Codeforces Round 187 (Div. 2)


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

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

Examples
Input
10 11
1 2 3 4 5 6 7 8 9 10
3 2
3 9
2 10
3 1
3 10
1 1 10
2 10
2 10
3 1
3 10
3 9
Output
2
9
11
20
30
40
39
----------------------------------------------------------------------------------------------------
C. Sereja and Contest
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
5 0
5 3 4 1 2
Output
2
3
4
Input
10 -10
5 5 1 7 5 1 2 4 9 2
Output
2
4
5
7
8
9
----------------------------------------------------------------------------------------------------
D. Sereja and Periods
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
10 3
abab
bab
Output
3
----------------------------------------------------------------------------------------------------
E. Sereja and Subsequences
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
1
42
Output
42
Input
3
1 2 2
Output
13
Input
5
1 2 3 4 5
Output
719
----------------------------------------------------------------------------------------------------
