Codeforces Round 530 (Div. 1)


A. Sum in the tree
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
5
1 1 1 1
1 -1 -1 -1 -1
Output
1
Input
5
1 2 3 1
1 -1 2 -1 -1
Output
2
Input
3
1 2
2 -1 1
Output
-1
----------------------------------------------------------------------------------------------------
B. Nice table
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
2 2
AG
CT
Output
AG
CT
Input
3 5
AGCAG
AGCAG
AGCAG
Output
TGCAT
CATGC
TGCAT
----------------------------------------------------------------------------------------------------
C. Construct a tree
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
3 5
Output
Yes
1 1 
Input
4 42
Output
No
Input
6 15
Output
Yes
1 2 3 1 5 
----------------------------------------------------------------------------------------------------
D. Eels
time limit per test: 3 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
2
+ 1
- 1
Output
0
0
Input
4
+ 1
+ 3
+ 7
- 3
Output
0
0
1
0
Input
9
+ 2
+ 2
+ 12
- 2
- 2
+ 4
+ 1
+ 1
- 12
Output
0
1
1
0
0
0
0
3
2
----------------------------------------------------------------------------------------------------
E. Fedya the Potter
time limit per test: 2.5 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
2
6 3
Output
6
Input
2
8 8
Output
8
Input
5
19 16 2 12 15
Output
12
----------------------------------------------------------------------------------------------------
F. Ж-function
time limit per test: 6 seconds
memory limit per test: 512 megabytes
input: standard input
output: standard output

Examples
Input
abbd
4
2 3
1 3
3 3
1 4
Output
3
3
1
4
Input
bbaaa
5
2 4
1 5
1 5
3 3
1 2
Output
3
6
6
1
3
----------------------------------------------------------------------------------------------------
