Educational Codeforces Round 61 (Rated for Div. 2)


A. Regular Bracket Sequence
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
3
1
4
3
Output
1
Input
0
0
0
0
Output
1
Input
1
2
3
4
Output
0
----------------------------------------------------------------------------------------------------
B. Discounts
time limit per test: 2.5 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
7
7 1 3 1 4 10 8
2
3 4
Output
27
30
----------------------------------------------------------------------------------------------------
C. Painting the Fence
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

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

Examples
Input
2 4
3 2
4 2
Output
5
Input
1 5
4
2
Output
1
Input
1 6
4
2
Output
2
Input
2 2
2 10
3 15
Output
-1
----------------------------------------------------------------------------------------------------
E. Knapsack
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

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

Examples
Input
5
abaca
Output
3
Input
8
abcddcba
Output
4
----------------------------------------------------------------------------------------------------
G. Greedy Subsequences
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

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