Dasha Code Championship - Novosibirsk Finals Round (only for onsite-finalists)


A. Dawid and Bags of Candies
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
1 7 11 5
Output
YES
Input
7 3 2 5
Output
NO
----------------------------------------------------------------------------------------------------
B. Ania and Minimizing
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
5 3
51528
Output
10028
Input
3 2
102
Output
100
Input
1 1
1
Output
0
----------------------------------------------------------------------------------------------------
C. Increasing Matrix
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
4 5
1 3 5 6 7
3 0 7 0 9
5 0 0 0 10
8 9 10 11 12
Output
144
Input
3 3
1 2 3
2 0 4
4 5 6
Output
30
Input
3 3
1 2 3
3 0 4
4 5 6
Output
-1
Input
3 3
1 2 3
2 3 4
3 4 2
Output
-1
----------------------------------------------------------------------------------------------------
D. Anadi and Domino
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
4 4
1 2
2 3
3 4
4 1
Output
4
Input
7 0
Output
0
Input
3 1
1 3
Output
1
Input
7 21
1 2
1 3
1 4
1 5
1 6
1 7
2 3
2 4
2 5
2 6
2 7
3 4
3 5
3 6
3 7
4 5
4 6
4 7
5 6
5 7
6 7
Output
16
----------------------------------------------------------------------------------------------------
E. Middle-Out
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
3
9
iredppipe
piedpiper
4
estt
test
4
tste
test
Output
2
1
2
Input
4
1
a
z
5
adhas
dasha
5
aashd
dasha
5
aahsd
dasha
Output
-1
2
2
3
----------------------------------------------------------------------------------------------------
F. Marcin and Training Camp
time limit per test: 3 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
4
3 2 3 6
2 8 5 10
Output
15
Input
3
1 2 3
1 2 3
Output
0
Input
1
0
1
Output
0
----------------------------------------------------------------------------------------------------
G. Kamil and Making a Stream
time limit per test: 4 seconds
memory limit per test: 768 megabytes
input: standard input
output: standard output

Examples
Input
5
4 5 6 0 8
1 2
1 3
1 4
4 5
Output
42
Input
7
0 2 3 0 0 0 0
1 2
1 3
2 4
2 5
3 6
3 7
Output
30
----------------------------------------------------------------------------------------------------
