Codeforces Global Round 23


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

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

Examples
Input
4
8
0 0 1 1 1 1 1 1
5
1 0 0 1 1
2
1 0
11
1 1 0 0 1 0 0 1 1 1 0
Output
0
1
1
3
----------------------------------------------------------------------------------------------------
C. Permutation Operations
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
4
4
1 2 3 4
5
1 3 2 4 5
3
2 3 1
1
1
Output
1 1 1 1
1 4 3 2 1
1 3 3
1
----------------------------------------------------------------------------------------------------
D. Paths on the Tree
time limit per test: 3 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
2
5 4
1 2 1 3
6 2 1 5 7
5 3
1 2 1 3
6 6 1 4 10
Output
54
56
----------------------------------------------------------------------------------------------------
E1. Joking (Easy Version)
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
6
NO
:(
NO
:)
Output
? 5 1 2 5 4 3
! 6
? 4 1 2 3 4
! 5
----------------------------------------------------------------------------------------------------
E2. Joking (Hard Version)
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
6
NO
:(
NO
:)
Output
? 5 1 2 5 4 3
! 6
? 4 1 2 3 4
! 5
----------------------------------------------------------------------------------------------------
F. Kazaee
time limit per test: 3 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
10 8
1234 2 3 3 2 1 1 2 3 4
2 1 6 2
1 1 1
2 1 6 2
2 1 9 2
1 10 5
2 1 9 3
1 3 5
2 3 10 2
Output
NO
YES
NO
YES
YES
----------------------------------------------------------------------------------------------------
G. Olympiad Training
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
4
4 1 1 0
1 2 1
1 1 1
0 1 2
1 2 2
3 1 1 1
1 1 2
7 2 1
9 3 2
4 2 1 0
100 2 1
5 2 3
7 1 2
5 1 2
5 1 1 1
10 3 1
9 2 3
20 1 1
16 1 4
1 3 4
Output
2
-1
17
35
----------------------------------------------------------------------------------------------------
