Codeforces Round 140 (Div. 1)


A. Flying Saucer Segments
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
1 10
Output
2
Input
3 8
Output
2
----------------------------------------------------------------------------------------------------
B. Naughty Stone Piles
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

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

Examples
Input
10 1 8 2
Output
3
Input
10 1 8 3
Output
1
----------------------------------------------------------------------------------------------------
D. The table
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
4 1
-1
-1
-1
-1
Output
4 1 2 3 4 
0 
Input
2 4
-1 -1 -1 2
1 1 1 1
Output
1 1 
1 4 
----------------------------------------------------------------------------------------------------
E. Noble Knight's Path
time limit per test: 4 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

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