Codeforces Round 814 (Div. 1)


A1. Burenka and Traditions (easy version)
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
7
4
5 5 5 5
3
1 3 2
2
0 0
3
2 5 7
6
1 2 3 3 2 1
10
27 27 34 32 2 31 23 56 52 4
5
1822 1799 57 23 55
Output
2
2
0
2
4
7
4
----------------------------------------------------------------------------------------------------
A2. Burenka and Traditions (hard version)
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
7
4
5 5 5 5
3
1 3 2
2
0 0
3
2 5 7
6
1 2 3 3 2 1
10
27 27 34 32 2 31 23 56 52 4
5
1822 1799 57 23 55
Output
2
2
0
2
4
7
4
----------------------------------------------------------------------------------------------------
B. Fibonacci Strings
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
6
1
1
2
1 1
2
1 2
3
3 1 3
2
7 5
6
26 8 3 4 13 34
Output
YES
YES
NO
YES
NO
YES
----------------------------------------------------------------------------------------------------
C. Tonya and Burenka-179
time limit per test: 3 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
4
2 1
1 2
1 3
4 4
4 1 3 2
2 6
4 6
1 1
3 11
9 3
1 7 9 4 5 2 3 6 8
3 1
2 1
9 1
6 3
1 1 1 1 1 1
1 5
4 4
3 8
Output
3
5
14
16
24
24
24
57
54
36
36
6
18
27
28
----------------------------------------------------------------------------------------------------
D. Permutation for Burenka
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
4
4 3
1 4 3 2
5 0 7 0
6
9
1
4
5 3
1 2 5 4 3
0 5 10 0 0
3 9
1
8
11
5 2
1 4 3 2 5
0 0 0 0 0
7 9 1 5
6
100
4 2
4 1 3 2
0 5 3 0
2
4
6
Output
YES
NO
NO
YES
YES
NO
YES
YES
NO
NO
----------------------------------------------------------------------------------------------------
E. Impressionism
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
3 3
1 0 2
0 0 0
2 0 1
2 0 1
0 0 0
1 0 2
Output
1
1 1 3
Input
4 4
0 0 1 2
3 0 0 0
0 1 0 0
1 0 0 0
2 0 0 1
0 3 0 0
0 1 0 0
0 0 1 0
Output
4
1 3 4
2 3 4
2 2 3
2 1 2
Input
3 3
1 2 0
0 0 0
0 0 0
1 0 0
2 0 0
0 0 0
Output
-1
----------------------------------------------------------------------------------------------------
F. Burenka, an Array and Queries
time limit per test: 3 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

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