Codeforces Round 564 (Div. 1)


A. Nauuo and Cards
time limit per test: 1.5 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
3
0 2 0
3 0 1
Output
2
Input
3
0 2 0
1 0 3
Output
4
Input
11
0 0 0 5 0 0 0 4 0 0 11
9 2 6 0 8 1 7 0 3 0 10
Output
18
----------------------------------------------------------------------------------------------------
B. Nauuo and Circle
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
4
1 2
1 3
2 4
Output
16
Input
4
1 2
1 3
1 4
Output
24
----------------------------------------------------------------------------------------------------
C1. Nauuo and Pictures (easy version)
time limit per test: 4 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
2 1
0 1
2 1
Output
332748119
332748119
Input
1 2
1
1
Output
3
Input
3 3
0 1 1
4 3 5
Output
160955686
185138929
974061117
----------------------------------------------------------------------------------------------------
C2. Nauuo and Pictures (hard version)
time limit per test: 4 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
2 1
0 1
2 1
Output
332748119
332748119
Input
1 2
1
1
Output
3
Input
3 3
0 1 1
4 3 5
Output
160955686
185138929
974061117
----------------------------------------------------------------------------------------------------
D. Nauuo and Portals
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
3
1 3 2
3 1 2
Output
2
1 1 1 3
2 2 3 1
Input
5
3 1 5 4 2
4 2 1 3 5
Output
3
1 1 3 4
2 2 3 2
2 3 5 1
----------------------------------------------------------------------------------------------------
E. Nauuo and ODT
time limit per test: 7.5 seconds
memory limit per test: 512 megabytes
input: standard input
output: standard output

Examples
Input
5 3
1 2 1 2 3
1 2
1 3
3 4
3 5
3 3
4 1
4 3
Output
47
51
49
45
Input
6 1
1 1 1 1 1 1
1 2
2 3
3 4
4 5
5 6
1 2
Output
36
46
----------------------------------------------------------------------------------------------------
F. Nauuo and Bug
time limit per test: 4 seconds
memory limit per test: 1024 megabytes
input: standard input
output: standard output

Examples
Input
4 5 6
7 2 -3 17
2 3
1 3
1 2
2 4
4 4
Output
-1
0
3
10
11
----------------------------------------------------------------------------------------------------
