Codeforces Round 732 (Div. 1)


A. AquaMoon and Strange Sort
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
3
4
4 3 2 5
4
3 3 2 2
5
1 2 3 5 4
Output
YES
YES
NO
----------------------------------------------------------------------------------------------------
B. AquaMoon and Chess
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
6
4
0110
6
011011
5
01010
20
10001111110110111000
20
00110110100110111101
20
11101111011000100010
Output
3
6
1
1287
1287
715
----------------------------------------------------------------------------------------------------
C. AquaMoon and Permutations
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
3
7
1 2 3 4 5 6 7
2 3 4 5 6 7 1
3 4 5 6 7 1 2
4 5 6 7 1 2 3
5 6 7 1 2 3 4
6 7 1 2 3 4 5
7 1 2 3 4 5 6
1 2 3 4 5 7 6
1 3 4 5 6 7 2
1 4 5 6 7 3 2
1 5 6 7 4 2 3
1 6 7 5 2 3 4
1 7 6 2 3 4 5
1 7 2 3 4 5 6
5
4 5 1 2 3
3 5 2 4 1
1 2 3 4 5
5 2 4 1 3
3 4 5 1 2
2 3 4 5 1
1 3 5 2 4
4 1 3 5 2
2 4 1 3 5
5 1 2 3 4
6
2 3 4 5 6 1
3 1 2 6 4 5
6 1 2 3 4 5
5 6 1 3 2 4
4 3 6 5 2 1
5 6 1 2 3 4
4 5 6 1 2 3
3 4 5 6 1 2
1 2 3 4 5 6
2 5 4 1 6 3
3 2 5 4 1 6
1 4 3 6 5 2
Output
1
1 2 3 4 5 6 7
2
1 3 5 6 10
4
1 3 6 7 8 9
----------------------------------------------------------------------------------------------------
D. AquaMoon and Wrong Coordinate
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
5 7
6 9 9 6 9
10 7 10 8 10
11 11 11 10 8
12 12 12 12 9
14 13 12 10 13
11 14 16 14 14
12 15 18 15 15
Output
4 13
----------------------------------------------------------------------------------------------------
E1. AquaMoon and Time Stop (easy version)
time limit per test: 3 seconds
memory limit per test: 1024 megabytes
input: standard input
output: standard output

Examples
Input
2
1
1 2 1 2
2 3 2 3
Output
2
Input
3
4
1 4 1 2
1 4 4 15
6 7 1 4
Output
8
Input
4
3
1 5 1 1
4 10 1 4
1 2 3 13
1 10 7 19
Output
14
Input
7
5
78 96 76 91
6 16 18 37
53 63 40 56
83 88 21 38
72 75 17 24
63 63 53 60
34 46 60 60
Output
20
----------------------------------------------------------------------------------------------------
E2. AquaMoon and Time Stop (hard version)
time limit per test: 7 seconds
memory limit per test: 1024 megabytes
input: standard input
output: standard output

Examples
Input
2
1
1 2 1 2
2 3 2 3
Output
2
Input
3
4
1 4 1 2
1 4 4 15
6 7 1 4
Output
8
Input
4
3
1 5 1 1
4 10 1 4
1 2 3 13
1 10 7 19
Output
14
Input
7
5
78 96 76 91
6 16 18 37
53 63 40 56
83 88 21 38
72 75 17 24
63 63 53 60
34 46 60 60
Output
20
----------------------------------------------------------------------------------------------------
F. AquaMoon and Potatoes
time limit per test: 7 seconds
memory limit per test: 512 megabytes
input: standard input
output: standard output

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