CodeTON Round 8 (Div. 1 + Div. 2, Rated, Prizes!)


A. Farmer John's Challenge
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
3
2 2
3 1
3 2
Output
1 1
69420 69 420
-1
----------------------------------------------------------------------------------------------------
B. Bessie and MEX
time limit per test: 1.5 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
3
5
1 1 -2 1 2
5
1 1 1 1 1
3
-2 1 2
Output
0 1 4 2 3 
0 1 2 3 4 
2 0 1 
----------------------------------------------------------------------------------------------------
C1. Bessie's Birthday Cake (Easy Version)
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
3
8 4 0
1 6 2 5
8 8 0
1 3 2 5 4 6 7 8
4 2 0
1 3
Output
2
6
2
----------------------------------------------------------------------------------------------------
C2. Bessie's Birthday Cake (Hard Version)
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
3
8 4 2
1 6 2 5
7 3 1
6 4 3
4 2 2
1 3
Output
6
5
2
----------------------------------------------------------------------------------------------------
D. Learning to Paint
time limit per test: 4.5 seconds
memory limit per test: 512 megabytes
input: standard input
output: standard output

Examples
Input
4
1 2
-5
2 4
2 -3
-1
3 8
2 4 3
1 3
5
6 20
0 -6 -3 0 -6 -2
-7 -5 -2 -3 -4
7 0 -9 -4
2 -1 1
1 -2
-6
Output
0 -5 
2 0 -1 -3 
7 5 4 3 3 2 1 0 
8 8 7 7 5 5 2 2 1 1 1 1 1 1 0 0 0 0 0 -1 
----------------------------------------------------------------------------------------------------
E. Farm Game
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
3
2 1
3 1
420 69
Output
0
2
870279412
----------------------------------------------------------------------------------------------------
F. Farmer John's Favorite Function
time limit per test: 5 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
5 6
0 14 0 7 6
1 4
1 3
2 15
4 1
5 2
5 8
Output
3
2
3
2
1
3
Input
15 10
3364 1623 5435 7 6232 245 7903 3880 9738 577 4598 1868 1112 8066 199
14 4284
14 8066
6 92
6 245
2 925
2 1623
5 176
5 6232
3 1157
3 5435
Output
16
17
16
17
16
17
16
17
16
17
Input
2 2
386056082462833225 923951085408043421
1 386056082462833225
1 386056082462833224
Output
961223744
961223743
Input
13 10
31487697732100 446330174221392699 283918145228010533 619870471872432389 11918456891794188 247842810542459080 140542974216802552 698742782599365547 533363381213535498 92488084424940128 401887157851719898 128798321287952855 137376848358184069
3 283918145228010532
3 283918145228010533
1 2183728930312
13 1000000000000000000
10 1000000000000000000
9 1000000000000000000
8 1000000000000000000
7 1000000000000000000
6 1000000000000000000
5 1000000000000000000
Output
370643829
370643830
370643829
1000000000
1000000000
1000000000
1000000000
1000000000
1000000000
1000000000
----------------------------------------------------------------------------------------------------
G. Bessie and Cards
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
4
1 1 1
0 0 0
5 3 7
3366 1434 1234
Output
903173463
1
35118742
398952013
----------------------------------------------------------------------------------------------------
H. Farmer John's Favorite Intern
time limit per test: 6 seconds
memory limit per test: 512 megabytes
input: standard input
output: standard output

Examples
Input
2
8 8
1 1 1 4 3 6 6
5 6 2 9 8 4 1 3
1 3 14
1 4 17
1 2 7
2 2 1
1 6 1
2 1 1000000
1 4 999999
1 3 1
10 20
1 1 1 2 5 2 4 7 2
311353 270334 74853 385085 315501 183346 234819 417314 103862 429437
1 1 837541
1 10 933876
1 1 565958
1 4 791455
2 3 85054
2 3 440978
1 4 981040
1 5 68522
2 1 858305
2 4 184308
1 4 905081
2 8 519626
2 2 269090
1 1 43016
2 2 517644
1 5 355792
1 9 319241
2 10 125447
2 10 523890
1 10 241045
Output
NO
NO
YES
NO
YES
NO
NO
YES
NO
NO
NO
YES
YES
NO
NO
YES
YES
NO
YES
YES
NO
YES
NO
NO
YES
YES
NO
NO
----------------------------------------------------------------------------------------------------
