Codeforces Round 171 (Div. 2)


A. Point on Spiral
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
0 0
Output
0
Input
1 0
Output
0
Input
0 1
Output
2
Input
-1 -1
Output
3
----------------------------------------------------------------------------------------------------
B. Books
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
4 5
3 1 2 1
Output
3
Input
3 3
2 2 3
Output
1
----------------------------------------------------------------------------------------------------
C. Ladder
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
8 6
1 2 1 3 3 5 2 1
1 3
2 3
2 4
8 8
1 4
5 8
Output
Yes
Yes
No
Yes
No
Yes
----------------------------------------------------------------------------------------------------
D. The Minimum Number of Variables
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
5
1 2 3 6 8
Output
2
Input
3
3 6 5
Output
-1
Input
6
2 4 8 6 10 18
Output
3
----------------------------------------------------------------------------------------------------
E. Beautiful Decomposition
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
10
Output
1
Input
111
Output
2
Input
1101101
Output
4
----------------------------------------------------------------------------------------------------
