Codeforces Round 527 (Div. 3)


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

Examples
Input
3
7 3
4 4
6 2
Output
cbcacab
abcd
baabab
----------------------------------------------------------------------------------------------------
B. Teams Forming
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
6
5 10 2 3 14 5
Output
5
Input
2
1 100
Output
99
----------------------------------------------------------------------------------------------------
C. Prefixes and Suffixes
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
5
ba
a
abab
a
aba
baba
ab
aba
Output
SPPSPSPS
Input
3
a
aa
aa
a
Output
PPSS
Input
2
a
c
Output
PS
----------------------------------------------------------------------------------------------------
D1. Great Vova Wall (Version 1)
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
5
2 1 1 2 5
Output
YES
Input
3
4 5 3
Output
YES
Input
2
10 10
Output
YES
Input
3
1 2 3
Output
NO
----------------------------------------------------------------------------------------------------
D2. Great Vova Wall (Version 2)
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
5
2 1 1 2 5
Output
YES
Input
3
4 5 3
Output
NO
Input
2
10 10
Output
YES
----------------------------------------------------------------------------------------------------
E. Minimal Diameter Forest
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
4 2
1 2
2 3
Output
2
4 2
Input
2 0
Output
1
1 2
Input
3 2
1 3
2 3
Output
2
----------------------------------------------------------------------------------------------------
F. Tree with Maximum Cost
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
8
9 4 1 7 10 1 6 5
1 2
2 3
1 4
1 5
5 6
5 7
5 8
Output
121
Input
1
1337
Output
0
----------------------------------------------------------------------------------------------------
