Codeforces Global Round 2


A. Ilya and a Colorful Walk
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
5
1 2 3 2 3
Output
4
Input
3
1 2 1
Output
1
Input
7
1 1 3 1 1 1 1
Output
4
----------------------------------------------------------------------------------------------------
B. Alyona and a Narrow Fridge
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
5 7
2 3 5 4 1
Output
3
Input
10 10
9 1 1 1 1 1 1 1 1 1
Output
4
Input
5 10
3 1 4 2 4
Output
5
----------------------------------------------------------------------------------------------------
C. Ramesses and Corner Inversion
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
3 3
0 1 0
0 1 0
1 0 0
1 0 0
1 0 0
1 0 0
Output
Yes
Input
6 7
0 0 1 1 0 0 1
0 1 0 0 1 0 1
0 0 0 1 0 0 1
1 0 1 0 1 0 0
0 1 0 0 1 0 1
0 1 0 1 0 0 1
1 1 0 1 0 1 1
0 1 1 0 1 0 0
1 1 0 1 0 0 1
1 0 1 0 0 1 0
0 1 1 0 1 0 0
0 1 1 1 1 0 1
Output
Yes
Input
3 4
0 1 0 1
1 0 1 0
0 1 0 1
1 1 1 1
1 1 1 1
1 1 1 1
Output
No
----------------------------------------------------------------------------------------------------
D. Frets On Fire
time limit per test: 1.5 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
6
3 1 4 1 5 9
3
7 7
0 2
8 17
Output
5 10 18
Input
2
1 500000000000000000
2
1000000000000000000 1000000000000000000
0 1000000000000000000
Output
2 1500000000000000000
----------------------------------------------------------------------------------------------------
E. Pavel and Triangles
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
5
1 2 2 2 2
Output
3
Input
3
1 1 1
Output
0
Input
3
3 3 3
Output
3
----------------------------------------------------------------------------------------------------
F. Niyaz and Small Degrees
time limit per test: 3 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
5
1 2 1
1 3 2
1 4 3
1 5 4
Output
10 6 3 1 0 
Input
5
1 2 1
2 3 2
3 4 5
4 5 14
Output
22 6 0 0 0 
----------------------------------------------------------------------------------------------------
G. Get Ready for the Battle
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
13 7
6 4 3 7 2 1 5
Output
3
0 1 2 3 1 2 4
2 6 2 4 4 2 4
3 1 7 1 7 7 1
3 1 5 3 7 5 1
Input
6 5
3 3 3 3 3
Output
3
3 3 0 0 0
1 2 3 4 5
3 4 5 5 5
5 5 5 5 5
Input
7 4
1 5 9 2
Output
3
1 2 4 0
1 4 2 3
2 3 3 3
3 3 3 3
----------------------------------------------------------------------------------------------------
H. Triple
time limit per test: 1.5 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
1 1
1 2 3
1 0 1
Output
2 4 
Input
2 2
1 2 1
0 1 2
1 2 3
Output
4 2 4 6 
Input
4 3
1 2 3
1 3 7
0 2 5
1 0 6
3 3 2
Output
198 198 126 126 126 126 198 198 
----------------------------------------------------------------------------------------------------
