Codeforces Round 441 (Div. 1, by Moscow Team Olympiad)


A. Classroom Watch
time limit per test: 1 second
memory limit per test: 512 megabytes
input: standard input
output: standard output

Examples
Input
21
Output
1
15
Input
20
Output
0
----------------------------------------------------------------------------------------------------
B. Sorting the Coins
time limit per test: 1 second
memory limit per test: 512 megabytes
input: standard input
output: standard output

Examples
Input
4
1 3 4 2
Output
1 2 3 2 1
Input
8
6 8 3 4 7 2 1 5
Output
1 2 2 3 4 3 4 5 1
----------------------------------------------------------------------------------------------------
C. National Property
time limit per test: 1 second
memory limit per test: 512 megabytes
input: standard input
output: standard output

Examples
Input
4 3
1 2
1 1
3 1 3 2
2 1 1
Output
Yes
2
2 3 
Input
6 5
2 1 2
2 1 2
3 1 2 3
2 1 5
2 4 4
2 4 4
Output
Yes
0
Input
4 3
4 3 2 2 1
3 1 1 3
3 2 3 3
2 3 1
Output
No
----------------------------------------------------------------------------------------------------
D. High Cry
time limit per test: 1 second
memory limit per test: 512 megabytes
input: standard input
output: standard output

Examples
Input
5
3 2 1 6 5
Output
8
Input
4
3 3 3 3
Output
0
----------------------------------------------------------------------------------------------------
E. Delivery Club
time limit per test: 2 seconds
memory limit per test: 512 megabytes
input: standard input
output: standard output

Examples
Input
2 0 10
5 6
Output
10
Input
3 2 1
3 4 5
Output
1
Input
1 4 5
2
Output
2
----------------------------------------------------------------------------------------------------
F. Royal Questions
time limit per test: 1.5 seconds
memory limit per test: 512 megabytes
input: standard input
output: standard output

Examples
Input
2 3
1 2 5
1 2 1
2 1 10
Output
15
Input
3 2
1 2 10
3 2 20
Output
30
----------------------------------------------------------------------------------------------------
