Codeforces Round 207 (Div. 2)


A. Group of Students
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
5
3 4 3 2 1
6 8
Output
3
Input
5
0 3 3 4 2
3 10
Output
4
Input
2
2 5
3 6
Output
0
----------------------------------------------------------------------------------------------------
B. Flag Day
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
7 3
1 2 3
1 4 5
4 6 7
Output
1 2 3 3 2 2 1 
Input
9 3
3 6 9
2 5 8
1 4 7
Output
1 1 1 2 2 2 3 3 3 
Input
5 2
4 1 5
3 1 2
Output
2 3 1 1 3 
----------------------------------------------------------------------------------------------------
C. 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 
----------------------------------------------------------------------------------------------------
D. 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
----------------------------------------------------------------------------------------------------
E. 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
----------------------------------------------------------------------------------------------------
