Codeforces Round 549 (Div. 2)


A. The Doors
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
5
0 0 1 0 0
Output
3
Input
4
1 0 0 1
Output
3
----------------------------------------------------------------------------------------------------
B. Nirvana
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
390
Output
216
Input
7
Output
7
Input
1000000000
Output
387420489
----------------------------------------------------------------------------------------------------
C. Queen
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
5
3 1
1 1
-1 0
2 1
3 0
Output
1 2 4 
Input
5
-1 0
1 1
1 1
2 0
3 0
Output
-1
Input
8
2 1
-1 0
1 0
1 1
1 1
4 0
5 1
7 0
Output
5 
----------------------------------------------------------------------------------------------------
D. The Beatles
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
2 3
1 1
Output
1 6
Input
3 2
0 0
Output
1 3
Input
1 10
5 3
Output
5 5
----------------------------------------------------------------------------------------------------
E. Lynyrd Skynyrd
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
3 6 3
2 1 3
1 2 3 1 2 3
1 5
2 6
3 5
Output
110
Input
2 4 3
2 1
1 1 2 2
1 2
2 3
3 4
Output
010
----------------------------------------------------------------------------------------------------
F. U2
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
3
-1 0
0 2
1 0
Output
2
Input
5
1 0
1 -1
0 -1
-1 0
-1 -1
Output
1
----------------------------------------------------------------------------------------------------
