Pinely Round 1 (Div. 1 + Div. 2)


A. Two Permutations
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
4
1 1 1
2 1 2
3 1 1
4 1 1
Output
Yes
No
No
Yes
----------------------------------------------------------------------------------------------------
B. Elimination of a Ring
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
3
4
1 2 3 2
4
1 2 1 2
1
1
Output
4
3
1
----------------------------------------------------------------------------------------------------
C. Set Construction
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
2
4
0001
1001
0001
0000
3
011
001
000
Output
3 1 2 3
2 1 3
2 2 4
4 1 2 3 4
1 1
2 1 2
3 1 2 3
----------------------------------------------------------------------------------------------------
D. Carry Bit
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
3 1
Output
15
Input
3 0
Output
27
Input
998 244
Output
573035660
----------------------------------------------------------------------------------------------------
E. Make It Connected
time limit per test: 1 second
memory limit per test: 512 megabytes
input: standard input
output: standard output

Examples
Input
4
3
011
100
100
3
000
001
010
4
0100
1000
0001
0010
6
001100
000011
100100
101000
010001
010010
Output
0
1
1
2
3 4 
3
2 5 6 
----------------------------------------------------------------------------------------------------
F1. Anti-median (Easy Version)
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
5
2
-1 -1
3
-1 -1 -1
4
1 2 3 4
6
-1 -1 3 4 -1 -1
8
-1 -1 -1 -1 -1 -1 -1 -1
Output
2
4
0
1
316
----------------------------------------------------------------------------------------------------
F2. Anti-median (Hard Version)
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
5
2
-1 -1
3
-1 -1 -1
4
1 2 3 4
6
-1 -1 3 4 -1 -1
8
-1 -1 -1 -1 -1 -1 -1 -1
Output
2
4
0
1
316
----------------------------------------------------------------------------------------------------
G. Centroid Guess
time limit per test: 4 seconds
memory limit per test: 512 megabytes
input: standard input
output: standard output

Examples
Input
5
2
1
2
3
1
1
1
Output
? 1 2
? 1 3
? 1 4
? 1 5
? 2 3
? 3 4
? 4 5
! 3
----------------------------------------------------------------------------------------------------
