Codeforces Round 862 (Div. 2)


A. We Need the Zero
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
5
3
1 2 5
3
1 2 3
4
0 1 2 3
4
1 2 2 3
1
1
Output
6
0
3
-1
1
----------------------------------------------------------------------------------------------------
B. The String Has a Target
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
4
3
cba
4
acac
5
abbcb
4
aaba
Output
acb
aacc
abbcb
aaab
----------------------------------------------------------------------------------------------------
C. Place for a Selfie
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
5
1 2
1
1 -1 2
1 -1 3
2 2
1
4
1 2 1
2 5 1
1 1
0
1 0 0
1 1
100000000
100000000 100000000 100000000
2 3
0
2
2 2 1
1 -2 1
1 -2 -1
Output
YES
1
YES
1
YES
1
YES
4
NO
YES
100000000
YES
0
NO
NO
----------------------------------------------------------------------------------------------------
D. A Wide, Wide Graph
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
6
1 2
1 3
2 4
2 5
3 6
Output
1 1 2 4 6 6 
Input
5
1 2
2 3
3 4
3 5
Output
1 1 3 5 5 
----------------------------------------------------------------------------------------------------
E. There Should Be a Lot of Maximums
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
5
1 2
2 3
2 4
1 5
2 1 3 2 1
Output
0
2
1
2
Input
6
1 2
1 3
1 4
4 5
4 6
1 2 3 1 4 5
Output
1
1
0
1
1
----------------------------------------------------------------------------------------------------
F1. Survival of the Weakest (easy version)
time limit per test: 3 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
5
1 2 4 5 6
Output
34
Input
9
1 1 1 7 7 7 9 9 9
Output
256
Input
7
1 7 9 2 0 0 9
Output
20
Input
3
1000000000 1000000000 777
Output
1540
----------------------------------------------------------------------------------------------------
F2. Survival of the Weakest (hard version)
time limit per test: 3 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
5
1 2 4 5 6
Output
34
Input
9
1 1 1 7 7 7 9 9 9
Output
256
Input
7
1 7 9 2 0 0 9
Output
20
Input
3
1000000000 1000000000 777
Output
1540
----------------------------------------------------------------------------------------------------
