Codeforces Round 302 (Div. 1)


A. Writing Code
time limit per test: 3 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
3 3 3 100
1 1 1
Output
10
Input
3 6 5 1000000007
1 2 3
Output
0
Input
3 5 6 11
1 2 1
Output
0
----------------------------------------------------------------------------------------------------
B. Destroying Roads
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
5 4
1 2
2 3
3 4
4 5
1 3 2
3 5 2
Output
0
Input
5 4
1 2
2 3
3 4
4 5
1 3 2
2 4 2
Output
1
Input
5 4
1 2
2 3
3 4
4 5
1 3 2
3 5 1
Output
-1
----------------------------------------------------------------------------------------------------
C. Remembering Strings
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
4 5
abcde
abcde
abcde
abcde
1 1 1 1 1
1 1 1 1 1
1 1 1 1 1
1 1 1 1 1
Output
3
Input
4 3
abc
aba
adc
ada
10 10 10
10 1 10
10 10 10
10 1 10
Output
2
Input
3 3
abc
ada
ssa
1 1 1
1 1 1
1 1 1
Output
0
----------------------------------------------------------------------------------------------------
D. Road Improvement
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
3
1 1
Output
4 3 3
Input
5
1 2 3 4
Output
5 8 9 8 5
----------------------------------------------------------------------------------------------------
E. Listening to Music
time limit per test: 7 seconds
memory limit per test: 64 megabytes
input: standard input
output: standard output

Examples
Input
5 3
1 2 1 2 3
5
1 1 2
1 3 2
1 3 3
1 3 5
1 3 1
Output
2
0
2
3
1
----------------------------------------------------------------------------------------------------
