Codeforces Round 813 (Div. 2)


A. Wonderful Permutation
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
4
3 1
2 3 1
3 3
1 2 3
4 2
3 4 1 2
1 1
1
Output
1
0
2
0
----------------------------------------------------------------------------------------------------
B. Woeful Permutation
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
2
1
2
Output
1 
2 1 
----------------------------------------------------------------------------------------------------
C. Sort Zero
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
5
3
3 3 2
4
1 3 1 3
5
4 1 5 3 2
4
2 4 1 2
1
1
Output
1
2
4
3
0
----------------------------------------------------------------------------------------------------
D. Empty Graph
time limit per test: 1.5 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
6
3 1
2 4 1
3 2
1 9 84
3 1
10 2 6
3 2
179 17 1000000000
2 1
5 9
2 2
4 2
Output
4
168
10
1000000000
9
1000000000
----------------------------------------------------------------------------------------------------
E1. LCM Sum (easy version)
time limit per test: 3.5 seconds
memory limit per test: 512 megabytes
input: standard input
output: standard output

Examples
Input
5
1 4
3 5
8 86
68 86
6 86868
Output
3
1
78975
969
109229059713337
----------------------------------------------------------------------------------------------------
E2. LCM Sum (hard version)
time limit per test: 3.5 seconds
memory limit per test: 512 megabytes
input: standard input
output: standard output

Examples
Input
5
1 4
3 5
8 86
68 86
6 86868
Output
3
1
78975
969
109229059713337
----------------------------------------------------------------------------------------------------
F. Triameter
time limit per test: 4.5 seconds
memory limit per test: 768 megabytes
input: standard input
output: standard output

Examples
Input
4
1 2 2
4
1 2 3 4
Output
1 2 2 2 
Input
7
1 2 3 4 2 1
7
2 1 3 7 5 6 4
Output
3 3 4 5 5 5 4 
Input
3
1 2
1
1
Output
1 
----------------------------------------------------------------------------------------------------
