Canada Cup 2016


A. Jumping Ball
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
4
<<><
Output
2
Input
5
>>>>>
Output
5
Input
4
>><<
Output
0
----------------------------------------------------------------------------------------------------
B. Food on the Plane
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
1f
Output
1
Input
2d
Output
10
Input
4a
Output
11
Input
5e
Output
18
----------------------------------------------------------------------------------------------------
C. Hidden Word
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
ABCDEFGHIJKLMNOPQRSGTUVWXYZ
Output
YXWVUTGHIJKLM
ZABCDEFSRQPON
Input
BUVTYZFQSNRIWOXXGJLKACPEMDH
Output
Impossible
----------------------------------------------------------------------------------------------------
D. Contest Balloons
time limit per test: 3 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
8
20 1000
32 37
40 1000
45 50
16 16
16 16
14 1000
2 1000
Output
3
Input
7
4 4
4 4
4 4
4 4
4 4
4 4
5 5
Output
2
Input
7
14000000003 1000000000000000000
81000000000 88000000000
5000000000 7000000000
15000000000 39000000000
46000000000 51000000000
0 1000000000
0 0
Output
2
----------------------------------------------------------------------------------------------------
E. Too Much Money
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
12
3
5
3
4
Output
5
Input
50
8
1
2
4
8
16
37
37
37
Output
Greed is good
----------------------------------------------------------------------------------------------------
F. Family Photos
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
2
12 3 4 7
1 15 9 1
Output
1
Input
2
5 4 8 8
4 12 14 0
Output
4
Input
1
0 10 0 10
Output
-10
----------------------------------------------------------------------------------------------------
G. Messages on a Tree
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
6 3
0 1 2 3 2 5
4 6
6 9
5 11
Output
14 13 11 
Input
3 2
0 1 1
2 1
3 1
Output
5 3 
Input
8 3
0 1 1 2 3 3 4 5
6 1
8 2
4 5
Output
7 6 11 
----------------------------------------------------------------------------------------------------
