Codeforces Round 905 (Div. 1)


A1. Dances (Easy version)
time limit per test: 3 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
4
2 1
1
3 2
4 1
5 1 5
3 8 3 3
8 1
4 3 3 2 2 1 1
1 1 1 1 3 3 3 3
9 1
9 2 8 3 7 4 6 5
1 2 3 2 1 4 5 6 5
Output
0
1
4
4
----------------------------------------------------------------------------------------------------
A2. Dances (Hard Version)
time limit per test: 3 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
4
2 4
1
3 2
4 7
5 1 5
3 8 3 3
8 4
4 3 3 2 2 1 1
1 1 1 1 3 3 3 3
9 1
9 2 8 3 7 4 6 5
1 2 3 2 1 4 5 6 5
Output
2
12
16
4
----------------------------------------------------------------------------------------------------
B. Time Travel
time limit per test: 2 seconds
memory limit per test: 512 megabytes
input: standard input
output: standard output

Examples
Input
5 2
4
1 2
2 3
3 4
4 5
2
2 3
3 5
6
2 1 2 1 2 1
Output
5
Input
5 2
3
1 2
3 1
4 3
2
2 1
4 5
5
1 2 1 1 1
Output
-1
----------------------------------------------------------------------------------------------------
C. Minimum Array
time limit per test: 3 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
2
4
1 2 3 4
2
1 4 0
1 3 -100
5
2 1 2 5 4
3
2 4 3
2 5 -2
1 3 1
Output
-99 -98 -97 4 
2 1 2 5 4 
----------------------------------------------------------------------------------------------------
D. Split
time limit per test: 3 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
5
3 2 1 4 5
5
1 5
1 3
1 4
1 2
2 5
Output
Yes
No
Yes
No
Yes
Input
6
1 6 2 4 3 5
3
3 5
2 6
4 6
Output
Yes
No
Yes
----------------------------------------------------------------------------------------------------
E. Good Colorings
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
2
3
1 2
1 3
2 1
2 3
3 1
3 2
1
OK
3
1 1
1 2
1 3
2 1
2 2
2 3
OK
Output
? 1 1
! 1 2 1 3
! 1 2 1 2
----------------------------------------------------------------------------------------------------
F. Minimum Segments
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
5
3
2 3 4
5
2 3 5 4 6
1
1
3
1 3 4
8
3 6 6 6 8 9 9 9
Output
Yes
1 2 1
No
Yes
1 
No
Yes
1 3 5 3 5 1 1 3
----------------------------------------------------------------------------------------------------
