Codeforces Round 572 (Div. 2)


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

Examples
Input
1
1
Output
1
1
Input
2
10
Output
2
1 0
Input
6
100011
Output
2
100 011
----------------------------------------------------------------------------------------------------
B. Number Circle
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
3
2 4 3
Output
YES
4 2 3 
Input
5
1 2 3 4 4
Output
YES
4 4 2 1 3
Input
3
13 8 5
Output
NO
Input
4
1 10 100 1000
Output
NO
----------------------------------------------------------------------------------------------------
C. Candies!
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
8
8 7 3 1 7 0 9 4
3
1 8
2 5
7 7
Output
3
1
0
Input
6
0 1 2 3 3 5
3
1 2
1 4
3 6
Output
0
0
1
----------------------------------------------------------------------------------------------------
D1. Add on a Tree
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
2
1 2
Output
YES
Input
3
1 2
2 3
Output
NO
Input
5
1 2
1 3
1 4
2 5
Output
NO
Input
6
1 2
1 3
1 4
2 5
2 6
Output
YES
----------------------------------------------------------------------------------------------------
D2. Add on a Tree: Revolution
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
5
1 2 2
2 3 4
3 4 10
3 5 18
Output
NO
Input
6
1 2 6
1 3 8
1 4 12
2 5 2
2 6 4
Output
YES
4
3 6 1
4 6 3
3 4 7
4 5 2
----------------------------------------------------------------------------------------------------
E. Count Pairs
time limit per test: 4 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
3 3 0
0 1 2
Output
1
Input
6 7 2
1 2 3 4 5 6
Output
3
----------------------------------------------------------------------------------------------------
F. Array Beauty
time limit per test: 5 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
4 3
1 7 3 5
Output
8
Input
5 5
1 10 100 1000 10000
Output
9
----------------------------------------------------------------------------------------------------
