Codeforces Round 119 (Div. 1)


A. Permutations
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
3
3 2 1
1 2 3
Output
2
Input
5
1 2 3 4 5
1 5 2 3 4
Output
1
Input
5
1 5 2 3 4
1 2 3 4 5
Output
3
----------------------------------------------------------------------------------------------------
B. AlgoRace
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
4 2 3
0 1 5 6
2 0 3 6
1 3 0 1
6 6 7 0
0 3 5 6
2 0 1 6
1 3 0 2
6 6 7 0
1 4 2
1 4 1
1 4 3
Output
3
4
3
Input
4 2 3
0 7 3 3
8 0 10 5
1 1 0 4
8 9 2 0
0 3 3 9
7 0 4 9
3 8 0 4
4 8 9 0
2 3 3
2 1 3
1 2 2
Output
4
5
3
----------------------------------------------------------------------------------------------------
C. Weak Memory
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
6 6 3
1 3 6
1 2
2 3
4 2
5 6
4 5
3 4
1 6
Output
3
Input
6 5 3
1 5 6
1 2
2 3
3 4
4 5
6 3
1 5
Output
3
----------------------------------------------------------------------------------------------------
D. BRT Contract
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
1 3 2
5 2
5
1
2
3
4
5
Output
8
9
12
12
12
Input
5 3 7
10 1 1 8 900000005 1000000000
3
1
10
1000000000
Output
1900000040
1900000040
2900000030
----------------------------------------------------------------------------------------------------
E. Heaven Tour
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
5 2 2
0 10 11 21 22
Output
33
1 3 5 4
Input
4 3 1
0 1 2 3
Output
-1
Input
7 3 2
0 100 200 201 301 303 305
Output
409
1 3 4 7 6 5
----------------------------------------------------------------------------------------------------
