Codeforces Global Round 9


A. Sign Flipping
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

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

Examples
Input
5
3 4
0 0 0 0
0 1 0 0
0 0 0 0
2 2
3 0
0 0
2 2
0 0
0 0
2 3
0 0 0
0 4 0
4 4
0 0 0 0
0 2 0 1
0 0 0 0
0 0 0 0
Output
YES
0 0 0 0
0 1 1 0
0 0 0 0
NO
YES
0 0
0 0
NO
YES
0 1 0 0
1 4 2 1
0 2 0 0
1 3 1 0
----------------------------------------------------------------------------------------------------
C. Element Extermination
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
4
3
1 2 3
4
3 1 2 4
3
2 3 1
6
2 4 6 1 3 5
Output
YES
YES
NO
YES
----------------------------------------------------------------------------------------------------
D. Replace by MEX
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

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

Examples
Input
3
3 1 2
Output
2
1 3
1 2
Input
4
1 8 1 6
Output
2
2 4
2 3
Input
5
1 1 1 2 2
Output
0
----------------------------------------------------------------------------------------------------
F. Integer Game
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
5 2 6
3
0
Output
First
2
3
----------------------------------------------------------------------------------------------------
G. Tree Modification
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
6
4 5
2 6
3 2
1 2
2 4
Output
1
Input
4
2 4
4 1
3 4
Output
0
----------------------------------------------------------------------------------------------------
H. Set Merging
time limit per test: 4 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
3 2
1 3 2
2 3
1 3
Output
6
3 2
1 3
5 2
4 6 
Input
2 4
2 1
1 2
1 2
1 2
1 1
Output
5
2 1
2 1
2 1
5 3 3 1
----------------------------------------------------------------------------------------------------
I. Cubic Lattice
time limit per test: 4 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
2
1 2 3
1 2 1
Output
1
1 0 0
0 1 0
0 0 1
Input
1
1 2 2
Output
9
2 -2 1
1 2 2
-2 -1 2
Input
1
2 5 5
Output
9
-1 2 2
2 -1 2
2 2 -1
----------------------------------------------------------------------------------------------------
