Codeforces Round 151 (Div. 2)


A. Buggy Sorting
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
1
Output
-1
----------------------------------------------------------------------------------------------------
B. Increase and Decrease
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
2
2 1
Output
1
Input
3
1 4 1
Output
3
----------------------------------------------------------------------------------------------------
C. Beauty Pageant
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
3 3
1 2 3
Output
1 1
1 2
2 3 2
Input
2 1
7 12
Output
1 12 
----------------------------------------------------------------------------------------------------
D. Colorful Graph
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
6 6
1 1 2 3 5 8
1 2
3 2
1 4
4 3
4 5
4 6
Output
3
Input
5 6
4 2 5 2 4
1 2
2 3
3 1
5 3
5 4
3 4
Output
2
----------------------------------------------------------------------------------------------------
E. Blood Cousins Return
time limit per test: 3 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
6
pasha 0
gerald 1
gerald 1
valera 2
igor 3
olesya 1
5
1 1
1 2
1 3
3 1
6 1
Output
2
2
0
1
0
Input
6
valera 0
valera 1
valera 1
gerald 0
valera 4
kolya 4
7
1 1
1 2
2 1
2 2
4 1
5 1
6 1
Output
1
0
0
0
2
0
0
----------------------------------------------------------------------------------------------------
