Codeforces Round 298 (Div. 2)


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

Examples
Input
6
Output
6
1 5 3 6 2 4
Input
3
Output
2
1 3
----------------------------------------------------------------------------------------------------
B. Covered Path
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
5 6
4 2
Output
26
Input
10 10
10 0
Output
100
----------------------------------------------------------------------------------------------------
C. Polycarpus' Dice
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
2 8
4 4
Output
3 3 
Input
1 3
5
Output
4 
Input
2 3
2 3
Output
0 1 
----------------------------------------------------------------------------------------------------
D. Handshakes
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
5
2 1 3 0 1
Output
Possible
4 5 1 3 2 
Input
9
0 2 3 4 1 1 0 2 2
Output
Possible
7 5 2 1 6 8 3 4 9
Input
4
0 2 1 1
Output
Impossible
----------------------------------------------------------------------------------------------------
E. Berland Local Positioning System
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
6
2 3 5 7 11 13
5
3 4 5 5 6
Output
10
Input
6
2 3 5 7 11 13
9
1 2 2 3 3 4 5 5 6
Output
16
Input
3
10 200 300
4
1 2 2 3
Output
-1
Input
3
1 2 3
4
1 2 2 3
Output
3
----------------------------------------------------------------------------------------------------
F. Simplified Nonogram
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
3 5
2 3 2
1 0 1 2 1
Output
*.**.
*.*.*
*..**
Input
3 3
2 1 2
2 1 2
Output
*.*
.*.
*.*
Input
3 3
1 0 1
2 2 2
Output
***
...
***
----------------------------------------------------------------------------------------------------
