Codeforces Global Round 7


A. Bad Ugly Numbers
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
4
1
2
3
4
Output
-1
57
239
6789
----------------------------------------------------------------------------------------------------
B. Maximums
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
5
0 1 1 -2 1
Output
0 1 2 0 3 
Input
3
1000 999999000 -1000000000
Output
1000 1000000000 0 
Input
5
2 1 2 2 3
Output
2 3 5 7 10 
----------------------------------------------------------------------------------------------------
C. Permutation Partitions
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
3 2
2 1 3
Output
5 2
Input
5 5
2 1 5 3 4
Output
15 1
Input
7 3
2 7 3 1 5 4 6
Output
18 6
----------------------------------------------------------------------------------------------------
D1. Prefix-Suffix Palindrome (Easy version)
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
5
a
abcdfdcecba
abbaxyzyx
codeforces
acbba
Output
a
abcdfdcba
xyzyx
c
abba
----------------------------------------------------------------------------------------------------
D2. Prefix-Suffix Palindrome (Hard version)
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
5
a
abcdfdcecba
abbaxyzyx
codeforces
acbba
Output
a
abcdfdcba
xyzyx
c
abba
----------------------------------------------------------------------------------------------------
E. Bombs
time limit per test: 3 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
3
3 2 1
1 2 3
Output
3 2 1 
Input
6
2 3 6 1 5 4
5 2 1 4 6 3
Output
6 5 5 5 4 1 
----------------------------------------------------------------------------------------------------
F1. Wise Men (Easy Version)
time limit per test: 2 seconds
memory limit per test: 512 megabytes
input: standard input
output: standard output

Examples
Input
3
011
101
110
Output
0 0 0 6 
Input
4
0101
1000
0001
1010
Output
2 2 6 2 2 6 2 2 
----------------------------------------------------------------------------------------------------
F2. Wise Men (Hard Version)
time limit per test: 4 seconds
memory limit per test: 512 megabytes
input: standard input
output: standard output

Examples
Input
3
011
101
110
Output
0 0 0 6 
Input
4
0101
1000
0001
1010
Output
2 2 6 2 2 6 2 2 
----------------------------------------------------------------------------------------------------
G. Spiderweb Trees
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
4
0 0
0 1
-1 -1
1 -1
1 2
1 3
1 4
Output
5
Input
5
3 2
0 -3
-5 -3
5 -5
4 5
4 2
4 1
5 2
2 3
Output
8
Input
6
4 -5
0 1
-2 8
3 -10
0 -1
-4 -5
2 5
3 2
1 2
4 6
4 2
Output
13
Input
8
0 0
-1 2
-2 5
-5 1
1 3
0 3
2 4
-1 -4
1 2
3 2
5 6
4 2
1 5
5 7
5 8
Output
36
----------------------------------------------------------------------------------------------------
