Codeforces Round 876 (Div. 2)


A. The Good Array
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
7
3 2
5 2
9 3
7 1
10 4
9 5
8 8
Output
2
3
4
7
4
3
2
----------------------------------------------------------------------------------------------------
B. Lamps
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
4
4
2 2
1 6
1 10
1 13
5
3 4
3 1
2 5
3 2
3 3
6
1 2
3 4
1 4
3 4
3 5
2 3
1
1 1
Output
15
14
20
1
----------------------------------------------------------------------------------------------------
C. Insert Zero and Invert Prefix
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
4
5
1 1 0 0 0
1
1
3
0 1 1
6
1 0 0 1 1 0
Output
YES
0 0 2 1 3
NO
NO
YES
0 1 0 2 4 2
----------------------------------------------------------------------------------------------------
D. Ball Sorting
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
3
6
2 3 1 4 6 5
3
1 2 3
11
7 3 4 6 8 9 10 2 5 11 1
Output
3 2 2 2 2 2 
0 0 0 
10 5 4 4 4 4 4 4 4 4 4 
----------------------------------------------------------------------------------------------------
E. Decreasing Game
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
4
10 4 6 3
3
1
0
Output
First
1
2
4
Input
6
4 5 5 11 3 2
2
5
4
6
1
0
Output
Second 
4
4
3
1
3
----------------------------------------------------------------------------------------------------
