Codeforces Round 167 (Div. 2)


A. Dima and Friends
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
1
1
Output
3
Input
1
2
Output
2
Input
2
3 5
Output
3
----------------------------------------------------------------------------------------------------
B. Dima and Sequence
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

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

Examples
Input
5
1 2 3 6 6
4
1 1
3 1
1 1
4 3
Output
1
3
4
6
Input
3
1 2 3
2
1 1
3 1
Output
1
3
Input
1
1
5
1 2
1 10
1 10
1 10
1 10
Output
1
3
13
23
33
----------------------------------------------------------------------------------------------------
D. Dima and Two Sequences
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
1
1
2
7
Output
1
Input
2
1 2
2 3
11
Output
2
----------------------------------------------------------------------------------------------------
E. Dima and Horses
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
3 3
1 2
3 2
3 1
Output
100
Input
2 1
2 1
Output
00
Input
10 6
1 2
1 3
1 4
2 3
2 4
3 4
Output
0110000000
----------------------------------------------------------------------------------------------------
