School Team Contest 3 (Winter Computer School 2010/11)


A. Codecraft III
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
November
3
Output
February
Input
May
24
Output
May
----------------------------------------------------------------------------------------------------
B. School
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

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

Examples
Input
4
BGBG
4 2 4 3
Output
2
3 4
1 2
Input
4
BBGG
4 6 1 5
Output
2
2 3
1 4
Input
4
BGBB
1 1 2 3
Output
1
1 2
----------------------------------------------------------------------------------------------------
D. Event Dates
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

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

Examples
Input
4
Ann
Anna
Sabrina
John
Petrov
Ivanova
Stoltz
Abacaba
Output
Ann Abacaba, Anna Ivanova, John Petrov, Sabrina Stoltz
Input
4
Aa
Ab
Ac
Ba
Ad
Ae
Bb
Bc
Output
Aa Ad, Ab Ae, Ac Bb, Ba Bc
----------------------------------------------------------------------------------------------------
F. Goats and Wolves
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
3 2
Output
11
Input
33 3
Output
-1
----------------------------------------------------------------------------------------------------
G. Prime Problem
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
8
Output
1 2 2 1 1 1 1 2
----------------------------------------------------------------------------------------------------
H. Road Problem
time limit per test: 3 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
4 3
1 2
2 3
3 4
Output
1
1 4
Input
4 4
1 2
2 3
2 4
3 4
Output
1
1 3
----------------------------------------------------------------------------------------------------
I. TCMCF+++
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
5
1 2 -3 3 3
Output
3 1 2 3 
Input
13
100 100 100 100 100 100 100 100 100 100 100 100 100
Output
100 100 100 100 100 100 100 100 100 100 100 100 100 
Input
4
-2 -2 -2 -2
Output
-2 -2 -2 -2 
----------------------------------------------------------------------------------------------------
J. Planting Trees
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
2 3
Output
3 6 2
5 1 4
Input
2 1
Output
-1
----------------------------------------------------------------------------------------------------
