Educational Codeforces Round 56 (Rated for Div. 2)


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

Examples
Input
4
2
13
37
100
Output
1
3
8
27
----------------------------------------------------------------------------------------------------
B. Letters Rearranging
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
3
aa
abacaba
xdd
Output
-1
abaacba
xdd
----------------------------------------------------------------------------------------------------
C. Mishka and the Last Exam
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
4
5 6
Output
2 3 3 3
Input
6
2 1 2
Output
0 0 1 1 1 2 
----------------------------------------------------------------------------------------------------
D. Beautiful Graph
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
2
2 1
1 2
4 6
1 2
1 3
1 4
2 3
2 4
3 4
Output
4
0
----------------------------------------------------------------------------------------------------
E. Intersection of Permutations
time limit per test: 6 seconds
memory limit per test: 512 megabytes
input: standard input
output: standard output

Examples
Input
6 7
5 1 4 2 3 6
2 5 3 1 4 6
1 1 2 4 5
2 2 4
1 1 2 4 5
1 2 3 3 5
1 1 6 1 2
2 4 1
1 4 4 1 3
Output
1
1
1
2
0
----------------------------------------------------------------------------------------------------
F. Vasya and Array
time limit per test: 2 seconds
memory limit per test: 512 megabytes
input: standard input
output: standard output

Examples
Input
5 2 3
1 -1 1 -1 2
Output
2
Input
6 3 2
1 1 -1 -1 -1 -1
Output
0
Input
10 42 7
-1 -1 -1 -1 -1 -1 -1 -1 -1 -1
Output
645711643
----------------------------------------------------------------------------------------------------
G. Multidimensional Queries
time limit per test: 6 seconds
memory limit per test: 512 megabytes
input: standard input
output: standard output

Examples
Input
5 2
1 2
2 3
3 4
4 5
5 6
7
2 1 5
2 1 3
2 3 5
1 5 -1 -2
2 1 5
1 4 -1 -2
2 1 5
Output
8
4
4
12
10
----------------------------------------------------------------------------------------------------
