Codeforces Round 167 (Div. 1)


A. 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
----------------------------------------------------------------------------------------------------
B. 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
----------------------------------------------------------------------------------------------------
C. 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
----------------------------------------------------------------------------------------------------
D. Dima and Figure
time limit per test: 3 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
2 2
Output
13
Input
3 4
Output
571
----------------------------------------------------------------------------------------------------
E. Dima and Game
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
2 2
Output
0
Input
4 4
Output
520
Input
100 1000
Output
269568947
----------------------------------------------------------------------------------------------------
