Polynomial Round 2022 (Div. 1 + Div. 2, Rated, Prizes!)


A. Add Plus Minus Sign
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
3
2
11
5
01101
5
10001
Output
-
+-++
+++-
----------------------------------------------------------------------------------------------------
B. Coloring
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
2
12 6 2
1 1 1 1 1 7
12 6 2
2 2 2 2 2 2
Output
NO
YES
----------------------------------------------------------------------------------------------------
C. Ice and Fire
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
2
4
001
4
101
Output
1 1 3 
1 2 3 
----------------------------------------------------------------------------------------------------
D. Same Count One
time limit per test: 2 seconds
memory limit per test: 512 megabytes
input: standard input
output: standard output

Examples
Input
3
3 4
1 1 1 0
0 0 1 0
1 0 0 1
4 3
1 0 0
0 1 1
0 0 1
0 0 0
2 2
0 0
0 1
Output
1
2 1 1
1
4 2 2
-1
----------------------------------------------------------------------------------------------------
E. Two Chess Pieces
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
4 2
1 2
1 3
2 4
1 3
1 4
Output
6
Input
4 2
1 2
2 3
3 4
4 1 2 3 4
1 1
Output
8
----------------------------------------------------------------------------------------------------
F1. Magician and Pigs (Easy Version)
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
4
1 8
2 3
3
3
Output
2
Input
6
1 5
1 6
2 2
3
1 4
3
Output
5
Input
12
2 1
1 15
1 9
3
1 12
2 2
1 13
3
2 1
1 9
1 8
3
Output
17
----------------------------------------------------------------------------------------------------
F2. Magician and Pigs (Hard Version)
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
4
1 8
2 3
3
3
Output
2
Input
6
1 5
1 6
2 2
3
1 4
3
Output
5
Input
12
2 1
1 15
1 9
3
1 12
2 2
1 13
3
2 1
1 9
1 8
3
Output
17
----------------------------------------------------------------------------------------------------
G. Segment Covering
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

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

Examples
Input
2
5 4
8 4
Output
13
1 4 5 3 2
18
4 2 5 7 8 3 1 6
----------------------------------------------------------------------------------------------------
