Codeforces Round 953 (Div. 2)


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

Examples
Input
5
2
1 1
4
2 3 3 1
5
2 2 3 2 2
2
10 3
3
1 2 3
Output
2
4
5
13
5
----------------------------------------------------------------------------------------------------
B. New Bakery
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
7
4 4 5
5 5 9
10 10 5
5 5 11
1000000000 1000000000 1000000000
1000000000 1000000000 1
1000 1 1000
Output
17
35
100
45
1000000000000000000
1000000000000000000
500500
----------------------------------------------------------------------------------------------------
C. Manhattan Permutations
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
8
3 4
4 5
7 0
1 1000000000000
8 14
112 777
5 12
5 2
Output
Yes
3 1 2
No
Yes
1 2 3 4 5 6 7
No
Yes
8 2 3 4 5 6 1 7
No
Yes
5 4 3 1 2
Yes
2 1 3 4 5
----------------------------------------------------------------------------------------------------
D. Elections
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
5
3 1
2 0 3
2 3
0 10
5 3
5 4 3 2 1
4 5
3 10 7 1
6 0
2 2 2 3 3 3
Output
0 1 2
1 0
0 1 2 3 4
1 0 2 3
1 1 2 0 4 5
----------------------------------------------------------------------------------------------------
E. Computing Machine
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
3
4
1111
0000
2
1 2
2 4
4
1010
1101
2
1 3
1 4
6
010101
011010
5
2 3
1 6
2 5
4 4
3 6
Output
2
3
2
3
1
4
3
1
2
----------------------------------------------------------------------------------------------------
F. Large Graph
time limit per test: 4 seconds
memory limit per test: 512 megabytes
input: standard input
output: standard output

Examples
Input
6
3 3
3 4 5
3 3
3 4 9
3 2
3 4 9
2 2
2 8
5 3
8 27 5 4 3
4 10
2 2 2 2
Output
3
2
3
1
4
1
----------------------------------------------------------------------------------------------------
