ABBYY Cup 2.0 - Hard


A1. Educational Game
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
4
1 0 1 2
Output
1
1
3
Input
8
1 2 3 4 5 6 7 8
Output
1
3
6
10
16
24
40
----------------------------------------------------------------------------------------------------
A2. Educational Game
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
4
1 0 1 2
Output
1
1
3
Input
8
1 2 3 4 5 6 7 8
Output
1
3
6
10
16
24
40
----------------------------------------------------------------------------------------------------
A3. Educational Game
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
4
1 0 1 2
Output
1
1
3
Input
8
1 2 3 4 5 6 7 8
Output
1
3
6
10
16
24
40
----------------------------------------------------------------------------------------------------
B1. Greedy Merchants
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
7 8
1 2
2 3
3 4
4 5
5 6
5 7
3 5
4 7
4
1 5
2 4
2 6
4 7
Output
2
1
2
0
----------------------------------------------------------------------------------------------------
B2. Greedy Merchants
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
7 8
1 2
2 3
3 4
4 5
5 6
5 7
3 5
4 7
4
1 5
2 4
2 6
4 7
Output
2
1
2
0
----------------------------------------------------------------------------------------------------
B3. Greedy Merchants
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
7 8
1 2
2 3
3 4
4 5
5 6
5 7
3 5
4 7
4
1 5
2 4
2 6
4 7
Output
2
1
2
0
----------------------------------------------------------------------------------------------------
C1. Smart Beaver and Resolving Collisions
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
10 2 7
+ 11 0
+ 22 2
+ 33 6
+ 44 0
+ 55 0
- 22
+ 66 0
Output
7
Input
5 1 6
+ 123 0
+ 234 1
+ 345 2
- 234
+ 456 0
+ 567 0
Output
4
----------------------------------------------------------------------------------------------------
C2. Smart Beaver and Resolving Collisions
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
10 2 7
+ 11 0
+ 22 2
+ 33 6
+ 44 0
+ 55 0
- 22
+ 66 0
Output
7
Input
5 1 6
+ 123 0
+ 234 1
+ 345 2
- 234
+ 456 0
+ 567 0
Output
4
----------------------------------------------------------------------------------------------------
C3. Smart Beaver and Resolving Collisions
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
10 2 7
+ 11 0
+ 22 2
+ 33 6
+ 44 0
+ 55 0
- 22
+ 66 0
Output
7
Input
5 1 6
+ 123 0
+ 234 1
+ 345 2
- 234
+ 456 0
+ 567 0
Output
4
----------------------------------------------------------------------------------------------------
D1. Magic Squares
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
3
1 2 3 4 5 6 7 8 9
Output
15
2 7 6
9 5 1
4 3 8
Input
3
1 0 -1 0 2 -1 -2 0 1
Output
0
1 0 -1
-2 0 2
1 0 -1
Input
2
5 5 5 5
Output
10
5 5
5 5
----------------------------------------------------------------------------------------------------
D2. Magic Squares
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
3
1 2 3 4 5 6 7 8 9
Output
15
2 7 6
9 5 1
4 3 8
Input
3
1 0 -1 0 2 -1 -2 0 1
Output
0
1 0 -1
-2 0 2
1 0 -1
Input
2
5 5 5 5
Output
10
5 5
5 5
----------------------------------------------------------------------------------------------------
D3. Magic Squares
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
3
1 2 3 4 5 6 7 8 9
Output
15
2 7 6
9 5 1
4 3 8
Input
3
1 0 -1 0 2 -1 -2 0 1
Output
0
1 0 -1
-2 0 2
1 0 -1
Input
2
5 5 5 5
Output
10
5 5
5 5
----------------------------------------------------------------------------------------------------
E1. The Beaver's Problem - 2
time limit per test: 5 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

No test samples are available for this problem
----------------------------------------------------------------------------------------------------
E2. The Beaver's Problem - 2
time limit per test: 5 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

No test samples are available for this problem
----------------------------------------------------------------------------------------------------
E3. The Beaver's Problem - 2
time limit per test: 5 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

No test samples are available for this problem
----------------------------------------------------------------------------------------------------
F1. Representative Sampling
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
3 2
aba
bzd
abq
Output
2
Input
4 3
eee
rrr
ttt
qqq
Output
0
Input
4 3
aaa
abba
abbc
abbd
Output
9
----------------------------------------------------------------------------------------------------
F2. Representative Sampling
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
3 2
aba
bzd
abq
Output
2
Input
4 3
eee
rrr
ttt
qqq
Output
0
Input
4 3
aaa
abba
abbc
abbd
Output
9
----------------------------------------------------------------------------------------------------
F3. Representative Sampling
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
3 2
aba
bzd
abq
Output
2
Input
4 3
eee
rrr
ttt
qqq
Output
0
Input
4 3
aaa
abba
abbc
abbd
Output
9
----------------------------------------------------------------------------------------------------
