Tinkoff Internship Warmup Round 2018 and Codeforces Round 475 (Div. 2)


A. Splits
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
7
Output
4
Input
8
Output
5
Input
9
Output
5
----------------------------------------------------------------------------------------------------
B. Messages
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
4 5 5 3 5
1 5 5 4
Output
20
Input
5 3 1 1 3
2 2 2 1 1
Output
15
Input
5 5 3 4 5
1 2 3 4 5
Output
35
----------------------------------------------------------------------------------------------------
C. Alternating Sum
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
2 2 3 3
+-+
Output
7
Input
4 1 5 1
-
Output
999999228
----------------------------------------------------------------------------------------------------
D. Destruction of a Tree
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
5
0 1 2 1 2
Output
YES
1
2
3
5
4
Input
4
0 1 2 3
Output
NO
----------------------------------------------------------------------------------------------------
E. Cutting Rectangle
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
1
1 1 9
Output
3
Input
2
2 3 20
2 4 40
Output
6
Input
2
1 2 5
2 3 5
Output
0
----------------------------------------------------------------------------------------------------
