Deltix Round, Summer 2021 (open for everyone, rated, Div. 1 + Div. 2)


A. A Variety of Operations
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
6
1 2
3 5
5 3
6 6
8 0
0 0
Output
-1
2
2
1
2
0
----------------------------------------------------------------------------------------------------
B. Take Your Places!
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
5
3
6 6 1
1
9
6
1 1 1 2 2 2
2
8 6
6
6 2 3 4 5 1
Output
1
0
3
-1
2
----------------------------------------------------------------------------------------------------
C. Compressed Bracket Sequence
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
5
4 1 2 3 1
Output
5
Input
6
1 3 2 1 2 4
Output
6
Input
6
1 1 1 1 2 2
Output
7
----------------------------------------------------------------------------------------------------
D. Take a Guess
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
7 6
2
7
Output
and 2 5
or 5 6
finish 5
----------------------------------------------------------------------------------------------------
E. Equilibrium
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
8 5
0 1 2 9 3 2 7 5
2 2 1 9 4 1 5 8
2 6
1 7
2 4
7 8
5 8
Output
1
3
1
-1
-1
----------------------------------------------------------------------------------------------------
F. Sports Betting
time limit per test: 4 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
2
1 2
Output
1
Input
5
1 5 2 11 14
Output
642377629
----------------------------------------------------------------------------------------------------
G. Gates to Another World
time limit per test: 4 seconds
memory limit per test: 1024 megabytes
input: standard input
output: standard output

Examples
Input
3 3
ask 0 7
block 3 6
ask 0 7
Output
1
0
Input
6 10
block 12 26
ask 44 63
block 32 46
ask 1 54
block 27 30
ask 10 31
ask 11 31
ask 49 31
block 31 31
ask 2 51
Output
1
1
0
0
1
0
----------------------------------------------------------------------------------------------------
H. DIY Tree
time limit per test: 6 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
10 5
5 3 4 2 1
29 49 33 12 55 15 32 62 37
61 26 15 58 15 22 8 58
37 16 9 39 20 14 58
10 15 40 3 19 55
53 13 37 44 52
23 59 58 4
69 80 29
89 28
48
Output
95
----------------------------------------------------------------------------------------------------
