Codeforces Round 588 (Div. 1)


A. Marcin and Training Camp
time limit per test: 3 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
4
3 2 3 6
2 8 5 10
Output
15
Input
3
1 2 3
1 2 3
Output
0
Input
1
0
1
Output
0
----------------------------------------------------------------------------------------------------
B. Kamil and Making a Stream
time limit per test: 4 seconds
memory limit per test: 768 megabytes
input: standard input
output: standard output

Examples
Input
5
4 5 6 0 8
1 2
1 3
1 4
4 5
Output
42
Input
7
0 2 3 0 0 0 0
1 2
1 3
2 4
2 5
3 6
3 7
Output
30
----------------------------------------------------------------------------------------------------
C. Konrad and Company Evaluation
time limit per test: 4 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
4 5
1 2
2 4
1 3
3 4
2 3
2
2
3
Output
4
3
2
Input
3 3
1 2
2 3
1 3
5
1
2
2
1
3
Output
1
1
1
1
1
1
----------------------------------------------------------------------------------------------------
D. Wojtek and Card Tricks
time limit per test: 3.5 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
3 3
2 1 3
3 1 2
1 3 2
Output
25
Input
2 4
4 1 3 2
4 3 1 2
Output
31
----------------------------------------------------------------------------------------------------
E1. Marek and Matching (easy version)
time limit per test: 7 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
2
50 50
50 50
Output
937500007
Input
3
3 1 4
1 5 9
2 6 5
Output
351284554
----------------------------------------------------------------------------------------------------
E2. Marek and Matching (hard version)
time limit per test: 15 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
2
50 50
50 50
Output
937500007
Input
3
3 1 4
1 5 9
2 6 5
Output
351284554
----------------------------------------------------------------------------------------------------
F. Mateusz and Escape Room
time limit per test: 7 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
5
0 2 3
1 2 3
4 3 3
4 3 3
4 3 3
Output
4
Input
3
0 1 2
3 0 3
1 0 0
Output
1
Input
4
1 0 2
3 3 3
4 0 4
5 3 5
Output
0
----------------------------------------------------------------------------------------------------
