Educational Codeforces Round 6


A. Professor GukiZ's Robot
time limit per test: 0.5 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
0 0
4 5
Output
5
Input
3 4
6 1
Output
3
----------------------------------------------------------------------------------------------------
B. Grandfather Dovlet’s calculator
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
1 3
Output
12
Input
10 15
Output
39
----------------------------------------------------------------------------------------------------
C. Pearls in a Row
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
5
1 2 3 4 1
Output
1
1 5
Input
5
1 2 3 4 5
Output
-1
Input
7
1 2 1 3 1 2 1
Output
2
1 3
4 7
----------------------------------------------------------------------------------------------------
D. Professor GukiZ and Two Arrays
time limit per test: 3 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
5
5 4 3 2 1
4
1 1 1 1
Output
1
2
1 1
4 2
Input
5
1 2 3 4 5
1
15
Output
0
0
Input
5
1 2 3 4 5
4
1 2 3 4
Output
1
1
3 1
----------------------------------------------------------------------------------------------------
E. New Year Tree
time limit per test: 3 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
7 10
1 1 1 1 1 1 1
1 2
1 3
1 4
3 5
3 6
3 7
1 3 2
2 1
1 4 3
2 1
1 2 5
2 1
1 6 4
2 1
2 2
2 3
Output
2
3
4
5
1
2
Input
23 30
1 2 2 6 5 3 2 1 1 1 2 4 5 3 4 4 3 3 3 3 3 4 6
1 2
1 3
1 4
2 5
2 6
3 7
3 8
4 9
4 10
4 11
6 12
6 13
7 14
7 15
7 16
8 17
8 18
10 19
10 20
10 21
11 22
11 23
2 1
2 5
2 6
2 7
2 8
2 9
2 10
2 11
2 4
1 12 1
1 13 1
1 14 1
1 15 1
1 16 1
1 17 1
1 18 1
1 19 1
1 20 1
1 21 1
1 22 1
1 23 1
2 1
2 5
2 6
2 7
2 8
2 9
2 10
2 11
2 4
Output
6
1
3
3
2
1
2
3
5
5
1
2
2
1
1
1
2
3
----------------------------------------------------------------------------------------------------
F. Xors on Segments
time limit per test: 10 seconds
memory limit per test: 512 megabytes
input: standard input
output: standard output

Examples
Input
6 3
1 2 3 4 5 6
1 6
2 5
3 4
Output
7
7
7
Input
1 1
1
1 1
Output
1
Input
6 20
10 21312 2314 214 1 322
1 1
1 2
1 3
1 4
1 5
1 6
2 2
2 3
2 4
2 5
2 6
3 4
3 5
3 6
4 4
4 5
4 6
5 5
5 6
6 6
Output
10
21313
21313
21313
21313
21313
21312
21313
21313
21313
21313
2314
2315
2315
214
215
323
1
323
322
----------------------------------------------------------------------------------------------------
