Codeforces Round 426 (Div. 1)


A. The Meaningless Game
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
6
2 4
75 45
8 8
16 16
247 994
1000000000 1000000
Output
Yes
Yes
Yes
No
No
Yes
----------------------------------------------------------------------------------------------------
B. The Bakery
time limit per test: 2.5 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
4 1
1 2 2 1
Output
2
Input
7 2
1 3 3 1 4 4 4
Output
5
Input
8 3
7 7 8 7 7 8 1 7
Output
6
----------------------------------------------------------------------------------------------------
C. Ever-Hungry Krakozyabra
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
1 10
Output
9
Input
40 57
Output
17
Input
157 165
Output
9
----------------------------------------------------------------------------------------------------
D. Red-Black Cobweb
time limit per test: 6 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
5
1 2 9 0
2 3 5 1
2 4 5 0
2 5 5 1
Output
1265625
Input
8
1 2 7 1
2 3 4 1
3 4 19 1
5 1 2 0
6 2 3 0
7 3 3 0
8 4 4 0
Output
452841614
----------------------------------------------------------------------------------------------------
E. Caramel Clouds
time limit per test: 3 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
3 5
1 7 1
1 6 2
1 7 1
3
7
2
5
Output
12
7
10
Input
3 15
1 4 17
2 8 6
4 8 9
2
5
1
Output
8
1
Input
2 10
3 7 9
10 90 10
2
10
100
Output
10
104
----------------------------------------------------------------------------------------------------
