CodeTON Round 7 (Div. 1 + Div. 2, Rated, Prizes!)


A. Jagged Swaps
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

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

Examples
Input
3
2
AB
4
BBBA
4
AABB
Output
1
0
3
----------------------------------------------------------------------------------------------------
C. Matching Arrays
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
7
1 0
1
2
1 1
1
2
3 0
2 4 3
4 1 2
3 1
2 4 3
4 1 2
3 2
2 4 3
4 1 2
3 3
2 4 3
4 1 2
5 2
6 4 5 6 2
9 7 9 1 1
Output
YES
2
NO
NO
YES
2 4 1
YES
4 1 2
NO
YES
1 9 9 7 1
----------------------------------------------------------------------------------------------------
D. Ones and Twos
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
2
5 5
2 1 2 1 2
1 5
1 6
1 7
2 4 2
1 7
3 2
2 2 2
1 6
1 5
Output
YES
YES
NO
YES
YES
NO
----------------------------------------------------------------------------------------------------
E. Permutation Sorting
time limit per test: 4 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
2
5
3 2 4 1 5
6
2 1 4 6 5 3
Output
1 0 1 1 0 
2 1 2 1 0 1 
----------------------------------------------------------------------------------------------------
F. Bracket Xoring
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
4
1
01
2
0000
3
100111
4
01011100
Output
-1
2
()()
()()
1
(())()
2
(((())))
()()(())
----------------------------------------------------------------------------------------------------
G. Pepe Racing
time limit per test: 5 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
1
2
2
4
4
3
2
Output
? 1 2
? 3 4
? 2 4
? 2 3
? 2 1
! 4 3 2
----------------------------------------------------------------------------------------------------
H1. Cyclic Hamming (Easy Version)
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
1
0011
0101
Output
1
Input
1
0011
0110
Output
0
Input
1
0??1
01??
Output
2
Input
2
000?????
01010101
Output
3
Input
2
0???????
1???????
Output
68
Input
5
0101010101010101010101010101010101010101010101010101010101010101
????????????????????????????????????????????????????????????????
Output
935297567
----------------------------------------------------------------------------------------------------
H2. Cyclic Hamming (Hard Version)
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
1
0011
0101
Output
1
Input
1
0011
0110
Output
0
Input
1
0??1
01??
Output
2
Input
2
000?????
01010101
Output
3
Input
2
0???????
1???????
Output
68
Input
5
0101010101010101010101010101010101010101010101010101010101010101
????????????????????????????????????????????????????????????????
Output
935297567
----------------------------------------------------------------------------------------------------
