Codeforces Round 304 (Div. 2)


A. Soldier and Bananas
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
3 17 4
Output
13
----------------------------------------------------------------------------------------------------
B. Soldier and Badges
time limit per test: 3 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
4
1 3 1 4
Output
1
Input
5
1 2 3 2 5
Output
2
----------------------------------------------------------------------------------------------------
C. Soldier and Cards
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
4
2 1 3
2 4 2
Output
6 2
Input
3
1 2
2 1 3
Output
-1
----------------------------------------------------------------------------------------------------
D. Soldier and Number Game
time limit per test: 3 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
2
3 1
6 3
Output
2
5
----------------------------------------------------------------------------------------------------
E. Soldier and Traveling
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
4 4
1 2 6 3
3 5 3 1
1 2
2 3
3 4
4 2
Output
YES
1 0 0 0 
2 0 0 0 
0 5 1 0 
0 0 2 1 
Input
2 0
1 2
2 1
Output
NO
----------------------------------------------------------------------------------------------------
