Codeforces Round 791 (Div. 2)


A. AvtoBus
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
4
4
7
24
998244353998244352
Output
1 1
-1
4 6
166374058999707392 249561088499561088
----------------------------------------------------------------------------------------------------
B. Stone Age Problem
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
5 5
1 2 3 4 5
1 1 5
2 10
1 5 11
1 4 1
2 1
Output
19
50
51
42
5
----------------------------------------------------------------------------------------------------
C. Rooks Defenders
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
8 10
1 2 4
3 6 2 7 2
1 3 2
3 6 2 7 2
1 4 3
3 2 6 4 8
2 4 3
3 2 6 4 8
1 4 8
3 2 6 4 8
Output
No
Yes
Yes
No
Yes
----------------------------------------------------------------------------------------------------
D. Toss a Coin to Your Graph...
time limit per test: 3 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
6 7 4
1 10 2 3 4 5
1 2
1 3
3 4
4 5
5 6
6 2
2 5
Output
4
Input
6 7 100
1 10 2 3 4 5
1 2
1 3
3 4
4 5
5 6
6 2
2 5
Output
10
Input
2 1 5
1 1
1 2
Output
-1
Input
1 0 1
1000000000
Output
1000000000
----------------------------------------------------------------------------------------------------
E. Typical Party in Dorm
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
7
ab??aba
8
a
b
ab
abc
abcd
abcde
abcdef
abcdefg
Output
14
13
55
105
171
253
351
465
Input
11
???????????
6
abcdefghijklmnopq
ecpnkhbmlidgfjao
olehfan
codef
glhf
q
Output
900057460
712815817
839861037
756843750
70840320
66
----------------------------------------------------------------------------------------------------
F. Formalism for Formalism
time limit per test: 3 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
1
0
Output
10
Input
2
1
0 1
Output
99
Input
2
9
0 1
1 2
2 3
3 4
4 5
5 6
6 7
7 8
8 9
Output
91
----------------------------------------------------------------------------------------------------
