Codeforces Round 523 (Div. 2)


A. Coins
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
5 11
Output
3
Input
6 16
Output
3
----------------------------------------------------------------------------------------------------
B. Views Matter
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
5 6
3 3 3 3 3
Output
10
Input
3 5
1 2 4
Output
3
Input
5 5
2 3 1 4 4
Output
9
Input
1 1000
548
Output
0
Input
3 3
3 1 1
Output
1
----------------------------------------------------------------------------------------------------
C. Multiplicity
time limit per test: 3 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
2
1 2
Output
3
Input
5
2 2 1 22 14
Output
13
----------------------------------------------------------------------------------------------------
D. TV Shows
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
5 4 3
1 2
4 10
2 4
10 11
5 9
Output
60
Input
6 3 2
8 20
6 22
4 15
20 28
17 25
20 27
Output
142
Input
2 1000000000 2
1 2
2 3
Output
999999997
----------------------------------------------------------------------------------------------------
E. Politics
time limit per test: 4 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
4 1 2
1 2 3 4
1 2
1 3
3 4
1 2
2 3
1 4
2
1 3
4 1
1
2 3
Output
9
Input
5 1 1
3 99 99 100 2
1 2
1 3
3 4
3 5
1 3
1 2
2 4
2 5
2
1 2
3 1
2
1 2
2 1
Output
198
Input
4 1 2
1 2 3 4
1 2
1 3
3 4
2 1
2 4
4 3
1
1 4
2
4 1
2 4
Output
-1
----------------------------------------------------------------------------------------------------
F. Lost Root
time limit per test: 3 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
3 2
No
Yes
Output
? 1 3 2
? 1 2 3
! 2
----------------------------------------------------------------------------------------------------
