Codeforces Round 627 (Div. 3)


A. Yet Another Tetris Problem
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
4
3
1 1 3
4
1 1 2 1
2
11 11
1
100
Output
YES
NO
YES
YES
----------------------------------------------------------------------------------------------------
B. Yet Another Palindrome Problem
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
5
3
1 2 1
5
1 2 2 3 2
3
1 1 2
4
1 2 2 1
10
1 1 2 2 3 3 4 4 5 5
Output
YES
YES
NO
YES
NO
----------------------------------------------------------------------------------------------------
C. Frog Jumps
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
6
LRLRRLL
L
LLR
RRRR
LLLLLL
R
Output
3
2
3
1
7
1
----------------------------------------------------------------------------------------------------
D. Pair of Topics
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
5
4 8 2 6 2
4 5 4 1 3
Output
7
Input
4
1 3 2 4
1 3 2 4
Output
0
----------------------------------------------------------------------------------------------------
E. Sleeping Schedule
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
7 24 21 23
16 17 14 20 20 11 22
Output
3
----------------------------------------------------------------------------------------------------
F. Maximum White Subtree
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
9
0 1 1 1 0 0 0 0 1
1 2
1 3
3 4
3 5
2 6
4 7
6 8
5 9
Output
2 2 2 2 2 1 1 0 2 
Input
4
0 0 1 0
1 2
1 3
1 4
Output
0 -1 1 -1 
----------------------------------------------------------------------------------------------------
