Educational Codeforces Round 140 (Rated for Div. 2)


A. Cut the Triangle
time limit per test: 2 seconds
memory limit per test: 512 megabytes
input: standard input
output: standard output

Examples
Input
4
4 7
6 8
3 5
4 5
4 7
6 8
5 8
1 8
2 5
3 6
6 6
6 3
Output
YES
YES
YES
NO
----------------------------------------------------------------------------------------------------
B. Block Towers
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
4
3
1 2 3
3
1 2 2
2
1 1000000000
10
3 8 6 7 4 1 2 4 10 1
Output
3
2
500000001
9
----------------------------------------------------------------------------------------------------
C. Count Binary Strings
time limit per test: 2 seconds
memory limit per test: 512 megabytes
input: standard input
output: standard output

Examples
Input
3
1 0 2
1 0
1
Output
6
Input
3
1 1 2
1 0
1
Output
2
Input
3
1 2 1
1 0
1
Output
0
Input
3
2 0 2
0 1
1
Output
0
----------------------------------------------------------------------------------------------------
D. Playoff
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
3
101
Output
4 5 6 7 
Input
1
1
Output
2 
Input
2
01
Output
2 3 
----------------------------------------------------------------------------------------------------
E. Algebra Flash
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
5 3
1 3 2 3 1
1 10 100
Output
11
Input
5 3
1 3 2 3 1
1 200 20
Output
21
Input
4 2
2 2 1 1
5 5
Output
10
Input
10 10
3 8 6 2 10 5 2 3 7 3
9 7 4 2 1 8 2 6 2 2
Output
15
----------------------------------------------------------------------------------------------------
F. Two Subtrees
time limit per test: 9 seconds
memory limit per test: 1024 megabytes
input: standard input
output: standard output

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