#include <iostream>
#include <sstream>
#include <iomanip>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <algorithm>
#include <numeric>
#include <iterator>
#include <functional>
#include <complex>
#include <queue>
#include <stack>
#include <cmath>
#include <cassert>
#include <tuple>
using namespace std;
typedef long long LL;
typedef complex<double> CMP;
class RoomPairs { public:
vector <string> fix(vector<string> s) {
for (size_t y = 1; y < s.size(); y += 2)
s[y][0] = s[y][s[y].size() - 1] = '|';
for (size_t x = 1; x < s[0].size(); x += 2)
s[0][x] = s[s.size()-1][x] = '-';
for (size_t y = 0; y<s.size(); y += 2)
for (size_t x = 0; x < s[y].size(); x += 2) {
int dx[] = { -1, +1, 0, 0 };
int dy[] = { 0, 0, -1, +1 };
char c = ' ';
for (int d = 0; d < 4; ++d) {
int yy = y + dy[d];
int xx = x + dx[d];
if (0 <= yy && yy < s.size() && 0 <= xx && xx < s[0].size() && s[yy][xx] != ' ')
c = '+';
}
s[y][x] = c;
}
return s;
}
vector <string> construct(int R, int C, int N)
{
return fix(solve(R, C, N));
}
vector<string> solve(int R, int C, int N)
{
vector<string> ans(R * 2 + 1, string(C * 2 + 1, ' '));
if (N < C) {
for (int r=1; r < ans.size(); r+=2) {
for (int c = 0; c < N; ++c)
ans[r][c*2+2] = '|';
}
return ans;
}
for (int r = 2; r <= R; ++r)
if((r-1)*C+r*(C-1) >= N)
{
int cnt = (r - 2)*C + (r - 1)*(C - 1);
vector<bool> h(C-1, true);
vector<bool> v(C, false);
for(; cnt<N; ++cnt) {
if (h[0] == false)
h[0] = true;
else {
int r = v.size() - 1;
for (; r >= 0; --r)
if (v[r] == false)
break;
if (r > 1) {
v[r] = true;
h[0] = false;
}
else {
//..
}
}
}
for (int x = 0; x < h.size(); ++x) {
for (int y = 0; y < R; ++y)
if(y<r-1)
ans[1 + y * 2][2 + x * 2] = '|';
else
ans[1 + y * 2][2 + x * 2] = (h[x] ? '|' : ' ');
}
for (int x = 0; x < v.size(); ++x)
for (int y=0; y < R; ++y)
if(y < r)
ans[2 + y * 2][1 + x * 2] = '-';
else if(y==r)
ans[2 + y * 2][1 + x * 2] = (v[x] ? '-' : ' ');
return ans;
}
}
};
// BEGIN CUT HERE
#include <ctime>
double start_time; string timer()
{ ostringstream os; os << " (" << int((clock()-start_time)/CLOCKS_PER_SEC*1000) << " msec)"; return os.str(); }
template<typename T> ostream& operator<<(ostream& os, const vector<T>& v)
{ os << "{ \n";
for(typename vector<T>::const_iterator it=v.begin(); it!=v.end(); ++it)
os << '\"' << *it << '\"' << (it+1==v.end() ? "" : "\n"); os << " }"; return os; }
void verify_case(const vector <string>& Expected, const vector <string>& Received) {
bool ok = (Expected == Received);
if(ok) cerr << "PASSED" << timer() << endl; else { cerr << "FAILED" << timer() << endl;
cerr << "\to: " << Expected << endl << "\tx: " << Received << endl; } }
#define CASE(N) {cerr << "Test Case #" << N << "..." << flush; start_time=clock();
#define END verify_case(_, RoomPairs().construct(R, C, N));}
int main(){
CASE(0)
int R = 2;
int C = 4;
int N = 1;
string __[] = {"+-+-+-+-+", "| | | |", "+ + +-+ +", "| | |", "+-+-+-+-+" };
vector <string> _(__, __+sizeof(__)/sizeof(*__));
END
CASE(1)
int R = 3;
int C = 3;
int N = 4;
string __[] = {"+-+-+-+", "| | | |", "+-+ +-+", "| |", "+-+ +-+", "| | | |", "+-+-+-+" };
vector <string> _(__, __+sizeof(__)/sizeof(*__));
END
CASE(2)
int R = 3;
int C = 4;
int N = 3;
string __[] = {"+-+-+-+-+", "| |", "+ +-+-+ +", "| | | | |", "+ +-+-+ +", "| |", "+-+-+-+-+" };
vector <string> _(__, __+sizeof(__)/sizeof(*__));
END
CASE(3)
int R = 4;
int C = 5;
int N = 31;
string __[] = {"+-+-+-+-+-+", "| | | | | |", "+-+-+-+-+-+", "| | | | | |", "+-+-+-+-+-+", "| | | | | |", "+-+-+-+-+-+", "| | | | | |", "+-+-+-+-+-+" };
vector <string> _(__, __+sizeof(__)/sizeof(*__));
END
CASE(4)
int R = 1;
int C = 10;
int N = 4;
string __[] = { "!!" };
vector <string> _(__, __+sizeof(__)/sizeof(*__));
END
/*
CASE(5)
int R = ;
int C = ;
int N = ;
string __[] = { "!!" };
vector <string> _(__, __+sizeof(__)/sizeof(*__));
END
*/
}
// END CUT HERE