// Author: Ivan Kazmenko (gassa@mail.ru)
module solution;
import std.algorithm;
import std.conv;
import std.range;
import std.stdio;
char [] [] initBoard (int r, int c)
{
auto res = new char [] [] (r, c);
foreach (ref line; res)
{
line[] = '.';
}
return res;
}
void placeCross (ref char [] [] board, int i, int j)
{
board[i + 0][j + 0] = '+';
board[i - 1][j + 0] = '|';
board[i + 1][j + 0] = '|';
board[i + 0][j - 1] = '-';
board[i + 0][j + 1] = '-';
}
char [] [] solveNotDivisible (int r, int c)
{
auto res = initBoard (r, c);
int start = r % 3 - 1;
int cur = 0;
int type = 1;
while (cur + 3 <= c)
{
for (int pos = start; pos + 3 <= r; pos += 3)
{
int row = pos + type;
if (pos == 1 && type == 1)
{
row = 0;
}
placeCross (res, row + 1, cur + 1);
}
if (c % 2 == 0 && cur == 2)
{
cur += 3;
}
else
{
cur += 2;
type ^= 1;
}
}
return res;
}
char [] [] solveDivisible (int r, int c)
{
auto res = initBoard (r, c);
for (int i = 1; i < r; i += 3)
{
for (int j = 1; j < c; j += 3)
{
placeCross (res, i, j);
}
}
return res;
}
char [] [] transposeBoard (char [] [] board, int r, int c)
{
auto res = new char [] [] (r, c);
foreach (i; 0..r)
{
foreach (j; 0..c)
{
res[i][j] = board[j][i];
if ("|-".canFind (res[i][j]))
{
res[i][j] = to !(char) ('|' + '-' - res[i][j]);
}
}
}
return res;
}
char [] [] solve (int r, int c)
{
if (r % 3 == 0 && c % 3 == 0)
{
return solveDivisible (r, c);
}
if (r % 3 == 0)
{
return transposeBoard (solve (c, r), r, c);
}
return solveNotDivisible (r, c);
}
void main ()
{
int r;
int c;
while (readf (" %s %s", &r, &c) > 0)
{
writefln ("%-(%s\n%)", solve (r, c));
}
}
Ly8gQXV0aG9yOiBJdmFuIEthem1lbmtvIChnYXNzYUBtYWlsLnJ1KQptb2R1bGUgc29sdXRpb247CmltcG9ydCBzdGQuYWxnb3JpdGhtOwppbXBvcnQgc3RkLmNvbnY7CmltcG9ydCBzdGQucmFuZ2U7Cmltc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