Bayan 2015 Contest Warm Up


A. Bayan Bus
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
9
Output
+------------------------+
|O.O.O.#.#.#.#.#.#.#.#.|D|)
|O.O.O.#.#.#.#.#.#.#.#.|.|
|O.......................|
|O.O.#.#.#.#.#.#.#.#.#.|.|)
+------------------------+
Input
20
Output
+------------------------+
|O.O.O.O.O.O.O.#.#.#.#.|D|)
|O.O.O.O.O.O.#.#.#.#.#.|.|
|O.......................|
|O.O.O.O.O.O.#.#.#.#.#.|.|)
+------------------------+
----------------------------------------------------------------------------------------------------
B. Strongly Connected City
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
3 3
><>
v^v
Output
NO
Input
4 6
<><>
v^v^v^
Output
YES
----------------------------------------------------------------------------------------------------
C. Kamal-ol-molk's Painting
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
4 4
XX..
XX..
XXXX
XXXX
Output
4
Input
4 4
....
.XXX
.XXX
....
Output
2
Input
4 5
XXXX.
XXXX.
.XX..
.XX..
Output
-1
----------------------------------------------------------------------------------------------------
D. CGCDSSQ
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
3
2 6 3
5
1
2
3
4
6
Output
1
2
2
0
1
Input
7
10 20 3 15 1000 60 16
10
1
2
3
4
5
6
10
20
60
1000
Output
14
0
2
2
2
0
2
2
1
1
----------------------------------------------------------------------------------------------------
E. Strongly Connected City 2
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
5 4
1 2
1 3
1 4
1 5
Output
13
Input
4 5
1 2
2 3
3 4
4 1
1 3
Output
16
Input
2 1
1 2
Output
3
Input
6 7
1 2
2 3
1 3
1 4
4 5
5 6
6 4
Output
27
----------------------------------------------------------------------------------------------------
F. Meta-universe
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
5
0 0
0 2
2 0
2 1
2 2
Output
3
Input
8
0 0
1 0
0 2
0 3
3 0
3 1
2 3
3 3
Output
1
----------------------------------------------------------------------------------------------------
