Codeforces Round 872 (Div. 1)


A. LuoTianyi and the Show
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
10
3 10
5 5 5
4 6
1 -2 -2 1
5 7
-1 -1 4 -2 -2
6 7
5 -2 -2 -2 -2 -2
6 6
-1 1 4 5 -1 4
6 8
-1 -1 -1 3 -1 -2
6 7
5 -1 -2 -2 -2 -2
3 1
-2 -2 1
2 5
5 -2
1 2
-1
Output
1
3
5
6
5
5
5
1
2
1
----------------------------------------------------------------------------------------------------
B1. LuoTianyi and the Floating Islands (Easy Version)
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
4 2
1 2
2 3
3 4
Output
666666674
Input
5 1
1 2
2 3
3 4
3 5
Output
1
----------------------------------------------------------------------------------------------------
B2. LuoTianyi and the Floating Islands (Hard Version)
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
4 2
1 2
2 3
3 4
Output
666666674
Input
5 5
1 2
2 3
3 4
3 5
Output
1
----------------------------------------------------------------------------------------------------
C. LuoTianyi and XOR-Tree
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
6
3 5 7 5 8 4
1 2
1 3
1 4
3 5
4 6
Output
3
Input
8
7 10 7 16 19 9 16 11
1 5
4 2
6 5
5 2
7 2
2 3
3 8
Output
3
Input
4
1 2 1 2
1 2
2 3
4 3
Output
0
Input
9
4 3 6 1 5 5 5 2 7
1 2
2 3
4 1
4 5
4 6
4 7
8 1
8 9
Output
2
----------------------------------------------------------------------------------------------------
D. LuoTianyi and the Function
time limit per test: 7 seconds
memory limit per test: 1024 megabytes
input: standard input
output: standard output

Examples
Input
6 4
1 2 2 1 3 4
1 1 4 5
2 3 3 3
3 6 1 2
6 6 6 6
Output
6
6
0
6
Input
10 5
10 2 8 10 9 8 2 1 1 8
1 1 10 10
2 2 3 3
6 6 6 6
1 1 4 5
4 8 4 8
Output
4
2
6
4
80
----------------------------------------------------------------------------------------------------
E. LuoTianyi and Cartridge
time limit per test: 3 seconds
memory limit per test: 1024 megabytes
input: standard input
output: standard output

Examples
Input
3
1 2 2
1 1 2
1 2 2 1
1 3 1 2
Output
8
Input
5
2 4 2 1 1
2 4 4 4 4
2 5 3 3
3 5 2 4
4 2 5 5
5 1 1 5
Output
35
Input
6
5 7 10 7 9 4
6 9 7 9 8 5
2 1 5 1
3 2 2 4
4 3 6 3
5 1 7 4
6 5 6 8
Output
216
Input
5
1000 1000 1 1000 1000
1000 1000 1 1000 1000
1 2 1 1
2 3 1000 1000
3 4 1000 1000
3 5 1000 1000
Output
7000000
----------------------------------------------------------------------------------------------------
