Codeforces Round 445 (Div. 1, based on Technocup 2018 Elimination Round 3)


A. Petya and Catacombs
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
2
0 0
Output
2
Input
5
0 1 0 1 3
Output
3
----------------------------------------------------------------------------------------------------
B. Restoration of string
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
4
mail
ai
lru
cf
Output
cfmailru
Input
3
kek
preceq
cheburek
Output
NO
----------------------------------------------------------------------------------------------------
C. Maximum Element
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
5 2
Output
22
Input
5 3
Output
6
Input
6 3
Output
84
----------------------------------------------------------------------------------------------------
D. Symmetric Projections
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
3
1 2
2 1
3 3
Output
3
Input
2
4 3
1 2
Output
-1
----------------------------------------------------------------------------------------------------
E. Mod Mod Mod
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
2
10 5
Output
13
Input
5
5 4 3 2 1
Output
6
Input
4
5 10 5 10
Output
16
----------------------------------------------------------------------------------------------------
