Codeforces Round 309 (Div. 1)


A. Kyoya and Colored Balls
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
3
2
2
1
Output
3
Input
4
1
2
3
4
Output
1680
----------------------------------------------------------------------------------------------------
B. Kyoya and Permutation
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
4 3
Output
1 3 2 4
Input
10 1
Output
1 2 3 4 5 6 7 8 9 10
----------------------------------------------------------------------------------------------------
C. Love Triangles
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
3 0
Output
4
Input
4 4
1 2 1
2 3 1
3 4 0
4 1 0
Output
1
Input
4 4
1 2 1
2 3 1
3 4 0
4 1 1
Output
0
----------------------------------------------------------------------------------------------------
D. Nudist Beach
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
9 8 4
3 9 6 8
1 2
1 3
1 4
1 5
2 6
2 7
2 8
2 9
Output
3
1 4 5
Input
10 8 2
2 9
1 3
2 9
4 5
5 6
6 7
7 8
8 10
10 4
Output
8
1 5 4 8 10 6 3 7
----------------------------------------------------------------------------------------------------
E. Kyoya and Train
time limit per test: 8 seconds
memory limit per test: 512 megabytes
input: standard input
output: standard output

Examples
Input
4 4 5 1
1 2 0
50000 0 50000 0 0
2 3 0
10000 0 0 0 90000
3 4 0
100000 0 0 0 0
2 4 0
0 0 0 50000 50000
Output
0.7000000000
Input
4 4 5 1
1 2 100
50000 0 50000 0 0
2 3 100
10000 0 0 0 90000
3 4 100
100000 0 0 0 0
2 4 100
0 0 0 50000 50000
Output
200.7500000000
----------------------------------------------------------------------------------------------------
