Codeforces Round 145 (Div. 1, ACM-ICPC Rules)


A. Cinema
time limit per test: 1 second
memory limit per test: 256 megabytes
input: input.txt
output: output.txt

Examples
Input
5 3
1 2 3
6
firstfilm
3
0 0 0
secondfilm
4
0 0 4 5
thirdfilm
1
2
fourthfilm
1
5
fifthfilm
1
4
sixthfilm
2
1 0
Output
2
2
1
1
1
2
Input
5 3
1 3 5
4
jumanji
3
0 0 0
theeagle
5
1 2 3 4 0
matrix
3
2 4 0
sourcecode
2
2 4
Output
2
0
1
1
----------------------------------------------------------------------------------------------------
B. Fence
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: input.txt
output: output.txt

Examples
Input
4
5 7
3 3 4 1
Output
3
Input
3
2 3
1 3 1
Output
2
Input
3
3 3
2 2 2
Output
-1
----------------------------------------------------------------------------------------------------
C. Practice
time limit per test: 1 second
memory limit per test: 256 megabytes
input: input.txt
output: output.txt

Examples
Input
2
Output
1
1 1
Input
3
Output
2
2 1 2
1 1
----------------------------------------------------------------------------------------------------
D. Merging Two Decks
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: input.txt
output: output.txt

Examples
Input
3
1 0 1
4
1 1 1 1
Output
1 4 5 6 7 2 3
3
5 6 7
Input
5
1 1 1 1 1
5
0 1 0 1 0
Output
6 1 2 3 4 5 7 8 9 10
4
1 7 8 9
----------------------------------------------------------------------------------------------------
E. Road Repairs
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: input.txt
output: output.txt

Examples
Input
3 2
1 3 0
3 2 1
Output
1
2
Input
4 4
2 3 0
3 4 0
4 1 0
4 2 1
Output
-1
Input
4 3
1 2 0
1 3 0
1 4 0
Output
0
----------------------------------------------------------------------------------------------------
F. TorCoder
time limit per test: 3 seconds
memory limit per test: 256 megabytes
input: input.txt
output: output.txt

Examples
Input
7 2
aabcbaa
1 3
5 7
Output
abacaba
Input
3 2
abc
1 2
2 3
Output
abc
----------------------------------------------------------------------------------------------------
