Codeforces Round 530 (Div. 2)


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

Examples
Input
4 3
1 1
1 2
Output
8
Input
4 3
9 2
0 1
Output
1
----------------------------------------------------------------------------------------------------
B. Squares and Segments
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
1
Output
2
Input
2
Output
3
Input
4
Output
4
----------------------------------------------------------------------------------------------------
C. Postcard
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
hw?ap*yn?eww*ye*ar
12
Output
happynewyear
Input
ab?a
2
Output
aa
Input
ab?a
3
Output
aba
Input
ababb
5
Output
ababb
Input
ab?a
1
Output
Impossible
----------------------------------------------------------------------------------------------------
D. Sum in the tree
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
5
1 1 1 1
1 -1 -1 -1 -1
Output
1
Input
5
1 2 3 1
1 -1 2 -1 -1
Output
2
Input
3
1 2
2 -1 1
Output
-1
----------------------------------------------------------------------------------------------------
E. Nice table
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
2 2
AG
CT
Output
AG
CT
Input
3 5
AGCAG
AGCAG
AGCAG
Output
TGCAT
CATGC
TGCAT
----------------------------------------------------------------------------------------------------
F. Cookies
time limit per test: 3 seconds
memory limit per test: 512 megabytes
input: standard input
output: standard output

Examples
Input
5 26
1 5 1 7 7
1 3 2 2 2
1 1
1 1
2 0
2 0
Output
11
Input
3 179
2 2 1
6 6 6
1 3
2 3
Output
4
----------------------------------------------------------------------------------------------------
