Codeforces Round 804 (Div. 2)


A. The Third Three Number Problem
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
5
4
1
12
2046
194723326
Output
3 3 1
-1
2 4 6
69 420 666
12345678 87654321 100000000
----------------------------------------------------------------------------------------------------
B. Almost Ternary Matrix
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
3
2 4
2 2
4 4
Output
1 0 0 1
0 1 1 0
1 0
0 1
1 0 1 0
0 0 1 1
1 1 0 0
0 1 0 1
----------------------------------------------------------------------------------------------------
C. The Third Problem
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
5
5
4 0 3 2 1
1
0
4
0 1 2 3
6
1 2 4 0 5 3
8
1 3 7 2 5 0 6 4
Output
2
1
1
4
72
----------------------------------------------------------------------------------------------------
D. Almost Triple Deletions
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
5
7
1 2 3 2 1 3 3
1
1
6
1 1 1 2 2 2
8
1 1 2 2 3 3 1 1
12
1 5 2 3 3 3 4 4 4 4 3 3
Output
3
1
0
4
2
----------------------------------------------------------------------------------------------------
E. Three Days Grace
time limit per test: 4 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
4
5 10
2 4 2 4 2
3 50
12 2 3
2 40
6 35
2 5
1 5
Output
0
1
2
4
----------------------------------------------------------------------------------------------------
