Codeforces Round 551 (Div. 2)


A. Serval and Bus
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
2 2
6 4
9 5
Output
1
Input
5 5
3 3
2 5
5 6
4 9
6 1
Output
3
Input
3 7
2 2
2 3
2 4
Output
1
----------------------------------------------------------------------------------------------------
B. Serval and Toy Bricks
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
3 7 3
2 3 0 0 2 0 1
2 1 3
1 0 0 0 1 0 0
0 0 0 0 0 0 1
1 1 0 0 0 0 0
Output
1 0 0 0 2 0 0
0 0 0 0 0 0 1
2 3 0 0 0 0 0
Input
4 5 5
3 5 2 0 4
4 2 5 4
0 0 0 0 1
1 0 1 0 0
0 1 0 0 0
1 1 1 0 0
Output
0 0 0 0 4
1 0 2 0 0
0 5 0 0 0
3 4 1 0 0
----------------------------------------------------------------------------------------------------
C. Serval and Parenthesis Sequence
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
6
(?????
Output
(()())
Input
10
(???(???(?
Output
:(
----------------------------------------------------------------------------------------------------
D. Serval and Rooted Tree
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
6
1 0 1 1 0 1
1 2 2 2 2
Output
1
Input
5
1 0 1 0 1
1 1 1 1
Output
4
Input
8
1 0 0 1 0 1 1 0
1 1 2 2 3 3 3
Output
4
Input
9
1 1 0 0 1 0 1 0 1
1 1 2 2 3 3 4 4
Output
5
----------------------------------------------------------------------------------------------------
E. Serval and Snake
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
2
1
0
0
Output
? 1 1 1 1
? 1 2 1 2
? 2 2 2 2
! 1 1 2 1
Input
3
2
0
Output
? 2 2 2 2
? 2 1 2 3
! 2 1 2 3
----------------------------------------------------------------------------------------------------
F. Serval and Bonus Problem
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
1 1 1
Output
332748118
Input
6 2 1
Output
760234711
Input
7 5 3
Output
223383352
Input
97 31 9984524
Output
267137618
----------------------------------------------------------------------------------------------------
