Educational Codeforces Round 55 (Rated for Div. 2)


A. Vasya and Book
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
3
10 4 5 2
5 1 3 4
20 4 19 3
Output
4
-1
5
----------------------------------------------------------------------------------------------------
B. Vova and Trophies
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
10
GGGSGGGSGG
Output
7
Input
4
GGGG
Output
4
Input
3
SSS
Output
0
----------------------------------------------------------------------------------------------------
C. Multi-Subject Competition
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
6 3
2 6
3 6
2 5
3 5
1 9
3 1
Output
22
Input
5 3
2 6
3 6
2 5
3 5
1 11
Output
23
Input
5 2
1 -1
1 -5
2 -1
2 -1
1 -10
Output
0
----------------------------------------------------------------------------------------------------
D. Maximum Diameter Graph
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
3
2 2 2
Output
YES 2
2
1 2
2 3
Input
5
1 4 1 1 1
Output
YES 2
4
1 2
3 2
4 2
5 2
Input
3
1 1 1
Output
NO
----------------------------------------------------------------------------------------------------
E. Increasing Frequency
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
6 9
9 9 9 9 9 9
Output
6
Input
3 2
6 2 6
Output
2
----------------------------------------------------------------------------------------------------
F. Speed Dial
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
3 1
0001 5
001 4
01 1
Output
14
Input
3 1
0001 5
001 6
01 1
Output
18
----------------------------------------------------------------------------------------------------
G. Petya and Graph
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
4 5
1 5 2 2
1 3 4
1 4 4
3 4 5
3 2 2
4 2 2
Output
8
Input
3 3
9 7 8
1 2 1
2 3 2
1 3 3
Output
0
----------------------------------------------------------------------------------------------------
