Codeforces Round 207 (Div. 1)


A. Knight Tournament
time limit per test: 3 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
4 3
1 2 1
1 3 3
1 4 4
Output
3 1 4 0 
Input
8 4
3 5 4
3 7 6
2 8 8
1 8 1
Output
0 8 4 6 4 8 6 1 
----------------------------------------------------------------------------------------------------
B. Xenia and Hamming
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
100 10
a
aaaaaaaaaa
Output
0
Input
1 1
abacaba
abzczzz
Output
4
Input
2 3
rzr
az
Output
5
----------------------------------------------------------------------------------------------------
C. Compartments
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
5
1 2 2 4 3
Output
2
Input
3
4 1 1
Output
2
Input
4
0 3 0 4
Output
0
----------------------------------------------------------------------------------------------------
D. Bags and Coins
time limit per test: 2.5 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
3 3
1 3 1
Output
1 0
1 2 3 1
1 0
Input
3 3
1 3 1
Output
1 0
2 1 3
0 1 1
Input
1 2
1
Output
-1
Input
8 10
2 7 3 4 1 3 1 2
Output
2 0
1 2 1 4
0 2 7 8
0 2 5 6
1 0
3 0
1 0
2 0
----------------------------------------------------------------------------------------------------
E. Xenia and String Problem
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
zzz
Output
12
Input
aba
Output
12
Input
abacaba
Output
83
Input
aaaaaa
Output
15
----------------------------------------------------------------------------------------------------
