Codeforces Round 916 (Div. 3)


A. Problemsolving Log
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
3
6
ACBCBC
7
AAAAFPC
22
FEADBBDFFEDFFFDHHHADCC
Output
3
1
4
----------------------------------------------------------------------------------------------------
B. Preparing for the Contest
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

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

Examples
Input
4
4 7
4 3 1 2
1 1 1 1
3 2
1 2 5
3 1 8
5 5
3 2 4 1 4
2 3 1 4 7
6 4
1 4 5 4 5 10
1 5 1 2 5 1
Output
13
4
15
15
----------------------------------------------------------------------------------------------------
D. Three Activities
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
4
3
1 10 1
10 1 1
1 1 10
4
30 20 10 1
30 5 15 20
30 25 10 10
10
5 19 12 3 18 18 6 17 10 13
15 17 19 11 16 3 11 17 17 17
1 17 18 10 15 8 17 3 13 12
10
17 5 4 18 12 4 11 2 16 16
8 4 14 19 3 12 6 7 5 16
3 4 8 11 10 8 10 2 20 3
Output
30
75
55
56
----------------------------------------------------------------------------------------------------
E1. Game with Marbles (Easy Version)
time limit per test: 3.5 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
5
3
4 2 1
1 2 4
4
1 20 1 20
100 15 10 20
5
1000000000 1000000000 1000000000 1000000000 1000000000
1 1 1 1 1
3
5 6 5
2 1 7
6
3 2 4 2 5 5
9 4 7 9 2 5
Output
1
-9
2999999997
8
-6
----------------------------------------------------------------------------------------------------
E2. Game with Marbles (Hard Version)
time limit per test: 3.5 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
5
3
4 2 1
1 2 4
4
1 20 1 20
100 15 10 20
5
1000000000 1000000000 1000000000 1000000000 1000000000
1 1 1 1 1
3
5 6 5
2 1 7
6
3 2 4 2 5 5
9 4 7 9 2 5
Output
1
-9
2999999997
8
-6
----------------------------------------------------------------------------------------------------
F. Programming Competition
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
6
4
1 2 1
2
1
5
5 5 5 1
7
1 2 1 1 3 3
7
1 1 3 2 2 4
7
1 2 1 1 1 3
Output
1
0
1
3
3
3
----------------------------------------------------------------------------------------------------
G1. Light Bulbs (Easy Version)
time limit per test: 3 seconds
memory limit per test: 512 megabytes
input: standard input
output: standard output

Examples
Input
4
2
2 2 1 1
2
1 2 2 1
2
1 2 1 2
5
3 4 4 5 3 1 1 5 2 2
Output
2 4
1 2
1 4
2 8
----------------------------------------------------------------------------------------------------
G2. Light Bulbs (Hard Version)
time limit per test: 3 seconds
memory limit per test: 512 megabytes
input: standard input
output: standard output

Examples
Input
4
2
2 2 1 1
2
1 2 2 1
2
1 2 1 2
5
3 4 4 5 3 1 1 5 2 2
Output
2 4
1 2
1 4
2 8
----------------------------------------------------------------------------------------------------
