Divide by Zero 2018 and Codeforces Round 474 (Div. 1 + Div. 2, combined)


A. Check the string
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
aaabccc
Output
YES
Input
bbacc
Output
NO
Input
aabc
Output
YES
----------------------------------------------------------------------------------------------------
B. Minimize the error
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
2 0 0
1 2
2 3
Output
2
Input
2 1 0
1 2
2 2
Output
0
Input
2 5 7
3 4
14 4
Output
1
----------------------------------------------------------------------------------------------------
C. Subsequence Counting
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
10 5
Output
6
5 50 7 15 6 100
Input
4 2
Output
4
10 100 1000 10000
----------------------------------------------------------------------------------------------------
D. Full Binary Tree Queries
time limit per test: 4 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
5
3 12
1 2 1
3 12
2 4 -1
3 8
Output
12 6 3 1 
12 6 2 1 
8 4 2 1 
Input
5
3 14
1 5 -3
3 14
1 3 1
3 14
Output
14 7 3 1 
14 6 3 1 
14 6 2 1 
----------------------------------------------------------------------------------------------------
E. Alternating Tree
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
4
-4 1 5 -2
1 2
1 3
1 4
Output
40
Input
8
-2 6 -4 -4 -9 -3 -7 23
8 2
2 3
1 4
6 5
7 6
4 7
5 8
Output
4
----------------------------------------------------------------------------------------------------
F. Pathwalks
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
3 3
3 1 3
1 2 1
2 3 2
Output
2
Input
5 5
1 3 2
3 2 3
3 4 5
5 4 0
4 5 8
Output
3
----------------------------------------------------------------------------------------------------
G. Bandit Blues
time limit per test: 3.5 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
1 1 1
Output
1
Input
2 1 1
Output
0
Input
2 2 1
Output
1
Input
5 2 2
Output
22
----------------------------------------------------------------------------------------------------
H. Santa's Gift
time limit per test: 4 seconds
memory limit per test: 512 megabytes
input: standard input
output: standard output

Examples
Input
3 5 5 7
3 1 4
1 1
73 1 48 85 89
2 1
2 3
1 2 3
2 1
2 3
Output
2920.333333333333
593.000000000000
49.000000000000
3217.000000000000
----------------------------------------------------------------------------------------------------
