Codeforces Round 568 (Div. 2)


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

Examples
Input
5 2 6 3
Output
2
Input
3 1 5 6
Output
8
Input
8 3 3 2
Output
2
Input
2 3 10 4
Output
3
----------------------------------------------------------------------------------------------------
B. Email from Polycarp
time limit per test: 3 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
4
hello
hello
hello
helloo
hello
hlllloo
hello
helo
Output
YES
YES
NO
NO
Input
5
aa
bb
codeforces
codeforce
polycarp
poolycarpp
aaaa
aaaab
abcdefghijklmnopqrstuvwxyz
zabcdefghijklmnopqrstuvwxyz
Output
NO
NO
YES
NO
NO
----------------------------------------------------------------------------------------------------
C1. Exam in BerSU (easy version)
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
7 15
1 2 3 4 5 6 7
Output
0 0 0 0 0 2 3 
Input
5 100
80 40 40 40 60
Output
0 1 1 2 3 
----------------------------------------------------------------------------------------------------
C2. Exam in BerSU (hard version)
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
7 15
1 2 3 4 5 6 7
Output
0 0 0 0 0 2 3 
Input
5 100
80 40 40 40 60
Output
0 1 1 2 3 
----------------------------------------------------------------------------------------------------
D. Extra Element
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
5
2 6 8 7 4
Output
4
Input
8
1 2 3 4 5 6 7 8
Output
1
Input
4
1 2 4 8
Output
-1
----------------------------------------------------------------------------------------------------
E. Polycarp and Snakes
time limit per test: 4 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
1
5 6
...a..
..bbb.
...a..
.cccc.
...a..
Output
YES
3
1 4 5 4
2 3 2 5
4 2 4 5
Input
3
3 3
...
...
...
4 4
..c.
adda
bbcb
....
3 5
..b..
aaaaa
..b..
Output
YES
0
YES
4
2 1 2 4
3 1 3 4
1 3 3 3
2 2 2 3
NO
Input
2
3 3
...
.a.
...
2 2
bb
cc
Output
YES
1
2 2 2 2
YES
3
1 1 1 2
1 1 1 2
2 1 2 2
----------------------------------------------------------------------------------------------------
F. Two Pizzas
time limit per test: 4 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
3 4
2 6 7
4 2 3 9 5
3 2 3 9
100 1 7
400 3 3 2 5
100 2 9 2
500 3 2 9 5
Output
2 3
Input
4 3
1 1
1 2
1 3
1 4
10 4 1 2 3 4
20 4 1 2 3 4
30 4 1 2 3 4
Output
1 2
Input
1 5
9 9 8 7 6 5 4 3 2 1
3 4 1 2 3 4
1 4 5 6 7 8
4 4 1 3 5 7
1 4 2 4 6 8
5 4 1 9 2 8
Output
2 4
----------------------------------------------------------------------------------------------------
G1. Playlist for Polycarp (easy version)
time limit per test: 5 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
3 3
1 1
1 2
1 3
Output
6
Input
3 3
1 1
1 1
1 3
Output
2
Input
4 10
5 3
2 1
3 2
5 1
Output
10
----------------------------------------------------------------------------------------------------
G2. Playlist for Polycarp (hard version)
time limit per test: 5 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
3 3
1 1
1 2
1 3
Output
6
Input
3 3
1 1
1 1
1 3
Output
2
Input
4 10
5 3
2 1
3 2
5 1
Output
10
----------------------------------------------------------------------------------------------------
