Codeforces Round 589 (Div. 2)


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

Examples
Input
121 130
Output
123
Input
98766 100000
Output
-1
----------------------------------------------------------------------------------------------------
B. Filling the Grid
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
3 4
0 3 1
0 2 3 0
Output
2
Input
1 1
0
1
Output
0
Input
19 16
16 16 16 16 15 15 0 5 0 4 9 9 1 4 4 0 8 16 12
6 12 19 15 8 6 19 19 14 6 9 16 10 11 15 4
Output
797922655
----------------------------------------------------------------------------------------------------
C. Primes and Multiplication
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
10 2
Output
2
Input
20190929 1605
Output
363165664
Input
947 987654321987654321
Output
593574252
----------------------------------------------------------------------------------------------------
D. Complete Tripartite
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
6 11
1 2
1 3
1 4
1 5
1 6
2 4
2 5
2 6
3 4
3 5
3 6
Output
1 2 2 3 3 3 
Input
4 6
1 2
1 3
1 4
2 3
2 4
3 4
Output
-1
----------------------------------------------------------------------------------------------------
E. Another Filling the Grid
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
2 2
Output
7
Input
123 456789
Output
689974806
----------------------------------------------------------------------------------------------------
F. One Node is Gone
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
4
1 2
1 3
2 4
2 5
3 6
3 13
3 14
4 7
4 8
5 9
5 10
6 11
6 12
Output
1
3
Input
2
1 2
Output
2
1 2
Input
3
1 2
2 3
3 4
4 5
5 6
Output
0
----------------------------------------------------------------------------------------------------
