Codeforces Round 336 (Div. 1)


A. Chain Reaction
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
4
1 9
3 1
6 1
7 4
Output
1
Input
7
1 1
2 1
3 1
4 1
5 1
6 1
7 1
Output
3
----------------------------------------------------------------------------------------------------
B. Zuma
time limit per test: 2 seconds
memory limit per test: 512 megabytes
input: standard input
output: standard output

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

Examples
Input
7
NNESWW
SWSWSW
Output
YES
Input
3
NN
SS
Output
NO
----------------------------------------------------------------------------------------------------
D. Power Tree
time limit per test: 3.5 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
2 5
1 1 3
1 2 5
1 3 7
1 4 11
2 1
Output
344
Input
5 5
1 1 4
1 2 3
2 2
1 2 7
2 1
Output
14
94
----------------------------------------------------------------------------------------------------
E. Cross Sum
time limit per test: 7 seconds
memory limit per test: 512 megabytes
input: standard input
output: standard output

Examples
Input
4
1000 1000 3
1000 0
-1000 0
0 5000
0 -5000
Output
14.282170363
Input
2
-1000000 -1000000 1
1000000 -1000000
999999 1000000
Output
2000001000.999999500
Input
3
-1000 1000 3
1000 0
-1000 2000
2000 -1000
Output
6.000000000
Input
5
-303667 189976 10
-638 116487
-581 44337
1231 -756844
1427 -44097
8271 -838417
Output
12953.274911829
----------------------------------------------------------------------------------------------------
