M. Task scheduler
time limit per test
1.5 seconds
memory limit per test
1024 megabytes
input
standard input
output
standard output
Example
Input
4
1
0
5
3
0 1 2
1 0 0
4
0 1 2 3
6 4 2 2
8
0 1 2 3 4 5 6 7
10 12 12 3 1 3 1 1
Output
0
1 2 0
2 3 1 0
4 6 7 3 5 0 1 2