Codeforces Round 539 (Div. 1)


A. Sasha and a Bit of Relax
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
5
1 2 3 4 5
Output
1
Input
6
3 2 2 3 7 6
Output
3
Input
3
42 4 2
Output
0
----------------------------------------------------------------------------------------------------
B. Sasha and One More Name
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
nolon
Output
2
Input
otto
Output
1
Input
qqqq
Output
Impossible
Input
kinnikkinnik
Output
1
----------------------------------------------------------------------------------------------------
C. Sasha and a Patient Friend
time limit per test: 1.5 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
6
1 2 1
1 4 -3
3 1 6 1
3 1 6 3
3 1 6 4
3 1 6 5
Output
5
5.666667
6
-1
Input
10
1 2 2
1 4 4
1 7 -10
3 2 4 1
3 5 6 0
3 1 15 1
2 4
3 1 15 1
1 8 1
3 1 15 1
Output
-1
5
8.7
8.1
-1
Input
5
1 1000 9999999
1 2000 -9999
3 1000 2000 0
2 1000
3 1000 2002 1
Output
1000
2000.0001
----------------------------------------------------------------------------------------------------
D. Sasha and Interesting Fact from Graph Theory
time limit per test: 2.5 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
3 2 1 3
Output
5
Input
3 1 1 2
Output
2
Input
5 15 1 5
Output
345444
----------------------------------------------------------------------------------------------------
E. Sasha and a Very Easy Test
time limit per test: 2.5 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
5 100
4 1 2 3 5
5
3 1 5
1 2 3 6
3 1 2
1 1 5 1
3 2 4
Output
15
10
21
Input
5 2
4 1 2 3 5
7
3 1 5
1 2 3 6
3 1 2
1 1 5 1
3 2 4
2 3 4
3 3 4
Output
1
0
1
0
Input
5 2100
1 2 3 4 5
10
1 1 3 12
1 1 5 10
2 5 50
3 2 4
1 4 4 28
2 4 7
3 1 2
3 3 4
2 3 3
3 1 5
Output
640
360
520
641
----------------------------------------------------------------------------------------------------
F. Sasha and Algorithm of Silence's Sounds
time limit per test: 1.5 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
1 5
1 2 3 4 5
Output
15
Input
2 3
1 2 3
4 5 6
Output
15
Input
4 4
4 3 2 16
1 13 14 15
5 7 8 12
6 11 9 10
Output
50
----------------------------------------------------------------------------------------------------
