Educational Codeforces Round 104 (Rated for Div. 2)


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

Examples
Input
3
3
3 2 2
2
5 5
4
1 3 3 7
Output
1
0
3
----------------------------------------------------------------------------------------------------
B. Cat Cycle
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
7
2 1
2 2
3 1
3 2
3 3
5 5
69 1337
Output
1
2
1
3
2
2
65
----------------------------------------------------------------------------------------------------
C. Minimum Ties
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
2
2
3
Output
0 
1 -1 1 
----------------------------------------------------------------------------------------------------
D. Pythagorean Triples
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
3
3
6
9
Output
0
1
1
----------------------------------------------------------------------------------------------------
E. Cheap Dinner
time limit per test: 4 seconds
memory limit per test: 512 megabytes
input: standard input
output: standard output

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

Examples
Input
24
Output
6
Input
102
Output
7
----------------------------------------------------------------------------------------------------
G. String Counting
time limit per test: 10 seconds
memory limit per test: 1024 megabytes
input: standard input
output: standard output

Examples
Input
4
2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2
Output
422500
Input
3
2 2 2 2 2 2 3 3 3 2 2 2 2 2 2 3 3 3 2 2 3 2 2 3 2 2
Output
16900
Input
400
348 322 247 158 209 134 151 267 268 176 214 379 372 291 388 135 147 304 169 149 193 351 380 368 181 340
Output
287489790
----------------------------------------------------------------------------------------------------
