Codeforces Round 794 (Div. 1)


A. Circular Local MiniMax
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
4
3
1 1 2
4
1 9 8 4
4
2 0 2 2
6
1 1 1 11 111 1111
Output
NO
YES
1 8 4 9 
NO
YES
1 11 1 111 1 1111 
----------------------------------------------------------------------------------------------------
B. Linguistics
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
8
1 0 0 0
B
0 0 1 0
AB
1 1 0 1
ABAB
1 0 1 1
ABAAB
1 1 2 2
BAABBABBAA
1 1 2 3
ABABABBAABAB
2 3 5 4
AABAABBABAAABABBABBBABB
1 3 3 10
BBABABABABBBABABABABABABAABABA
Output
NO
YES
YES
YES
YES
YES
NO
YES
----------------------------------------------------------------------------------------------------
C. Bring Balance
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
3
2
(())
5
())((()))(
6
())((()))(()
Output
0
2
3 4
9 10
1
2 11
----------------------------------------------------------------------------------------------------
D1. Permutation Weight (Easy Version)
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
3
2
2 1
4
2 3 1 4
5
5 4 3 2 1
Output
1 2 
1 3 4 2 
1 4 2 3 5 
----------------------------------------------------------------------------------------------------
D2. Permutation Weight (Hard Version)
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
3
2
2 1
4
2 3 1 4
5
5 4 3 2 1
Output
1 2 
1 3 4 2 
1 3 4 2 5 
----------------------------------------------------------------------------------------------------
E. The Ultimate LIS Problem
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

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