Codeforces Round 279 (Div. 2)


A. Team Olympiad
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
7
1 3 1 3 2 1 2
Output
2
3 5 2
6 7 4
Input
4
2 1 1 2
Output
0
----------------------------------------------------------------------------------------------------
B. Queue
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
4
92 31
0 7
31 0
7 141
Output
92 7 31 141 
----------------------------------------------------------------------------------------------------
C. Hacking Cypher
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
116401024
97 1024
Output
YES
11640
1024
Input
284254589153928171911281811000
1009 1000
Output
YES
2842545891539
28171911281811000
Input
120
12 1
Output
NO
----------------------------------------------------------------------------------------------------
D. Chocolate
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
2 6
2 3
Output
1
1 6
2 3
Input
36 5
10 16
Output
3
16 5
5 16
Input
3 5
2 1
Output
-1
----------------------------------------------------------------------------------------------------
E. Restoring Increasing Sequence
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
3
?
18
1?
Output
YES
1
18
19
Input
2
??
?
Output
NO
Input
5
12224
12??5
12226
?0000
?00000
Output
YES
12224
12225
12226
20000
100000
----------------------------------------------------------------------------------------------------
F. Treeland Tour
time limit per test: 5 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

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