Codeforces Round 305 (Div. 1)


A. Mike and Frog
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
5
4 2
1 1
0 1
2 3
Output
3
Input
1023
1 2
1 0
1 2
1 1
Output
-1
----------------------------------------------------------------------------------------------------
B. Mike and Feet
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
10
1 2 3 4 5 4 3 2 1 6
Output
6 4 4 3 3 2 2 1 1 1 
----------------------------------------------------------------------------------------------------
C. Mike and Foam
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
5 6
1 2 3 4 6
1
2
3
4
5
1
Output
0
1
3
5
6
2
----------------------------------------------------------------------------------------------------
D. Mike and Fish
time limit per test: 3 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
4
1 1
1 2
2 1
2 2
Output
brrb
Input
3
1 1
1 2
2 1
Output
brr
----------------------------------------------------------------------------------------------------
E. Mike and Friends
time limit per test: 3 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
5 5
a
ab
abab
ababab
b
1 5 1
3 5 1
1 5 2
1 5 3
1 4 5
Output
7
5
6
3
6
----------------------------------------------------------------------------------------------------
