Dasha Code Championship - SPb Finals Round (only for onsite-finalists)


A. Anadi and Domino
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
4 4
1 2
2 3
3 4
4 1
Output
4
Input
7 0
Output
0
Input
3 1
1 3
Output
1
Input
7 21
1 2
1 3
1 4
1 5
1 6
1 7
2 3
2 4
2 5
2 6
2 7
3 4
3 5
3 6
3 7
4 5
4 6
4 7
5 6
5 7
6 7
Output
16
----------------------------------------------------------------------------------------------------
B. 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
----------------------------------------------------------------------------------------------------
C. 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
----------------------------------------------------------------------------------------------------
D. 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
----------------------------------------------------------------------------------------------------
E. 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
----------------------------------------------------------------------------------------------------
F1. 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
----------------------------------------------------------------------------------------------------
F2. 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
----------------------------------------------------------------------------------------------------
G. 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
----------------------------------------------------------------------------------------------------
