Codeforces Round 500 (Div. 1) [based on EJOI]


A. Photo of The Sky
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
4
4 1 3 2 3 2 1 3
Output
1
Input
3
5 8 5 5 7 5
Output
0
----------------------------------------------------------------------------------------------------
B. Chemical table
time limit per test: 1 second
memory limit per test: 512 megabytes
input: standard input
output: standard output

Examples
Input
2 2 3
1 2
2 2
2 1
Output
0
Input
1 5 3
1 3
1 1
1 5
Output
2
Input
4 3 6
1 2
1 3
2 2
2 3
3 1
3 3
Output
1
----------------------------------------------------------------------------------------------------
C. Hills
time limit per test: 1 second
memory limit per test: 512 megabytes
input: standard input
output: standard output

Examples
Input
5
1 1 1 1 1
Output
1 2 2 
Input
3
1 2 3
Output
0 2 
Input
5
1 2 3 2 2
Output
0 1 3 
----------------------------------------------------------------------------------------------------
D. AB-Strings
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
bab
bb
Output
2
1 0
1 3
Input
bbbb
aaa
Output
0
----------------------------------------------------------------------------------------------------
E. Cycle sort
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
5 5
3 2 3 1 1
Output
1
5
1 4 2 3 5 
Input
4 3
2 1 4 3
Output
-1
Input
2 0
2 2
Output
0
----------------------------------------------------------------------------------------------------
F. Passports
time limit per test: 2 seconds
memory limit per test: 512 megabytes
input: standard input
output: standard output

Examples
Input
2 1
3 1 1
6 1 1
Output
YES
1 1
1 4
Input
3 1
13 2 2
7 3 1
19 3 4
Output
YES
1 10
1 1
1 2
Input
7 2
15 1 1
14 1 1
18 1 1
21 1 1
9 4 6
22 2 5
5 4 3
Output
YES
2 13
1 1
1 16
1 19
1 2
2 16
2 1
Input
3 1
7 3 1
13 2 3
19 3 4
Output
NO
----------------------------------------------------------------------------------------------------
