#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 <cstring>
using namespace std;
typedef long long LL;
typedef complex<double> CMP;
LL s, N, K;
class PlaneFractal {
public:
vector <string> getPattern(int _s, int _N, int _K, int r1, int r2, int c1, int c2)
{
s = _s;
N = _N;
K = _K;
LL Ns=1; for(int i=0; i<s-1; ++i) Ns*=N;
vector<string> ans(r2-r1+1, string(c2-c1+1, '0'));
for(int r=r1; r<=r2; ++r)
for(int c=c1; c<=c2; ++c)
if( s>0 && black(r,c,Ns) )
ans[r-r1][c-c1] = '1';
return ans;
}
bool black(int y, int x, LL Ns) const
{
if( Ns == 0 )
return false;
int Y = y/Ns, X = x/Ns;
y%=Ns, x%=Ns;
if( (Y<(N-K)/2 || N-(N-K)/2<=Y) || (X<(N-K)/2 || N-(N-K)/2<=X) )
return black(y, x, Ns/N);
return true;
}
};
// 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> string print_array(const vector<T> &V) { ostringstream os; os << "{ "; for (typename vector<T>::const_iterator iter = V.begin(); iter != V.end(); ++iter) os << '\"' << *iter << "\","; os << " }"; return os.str(); }
int verify_case(const vector <string> &Expected, const vector <string> &Received) { if (Expected == Received) cerr << "PASSED" << timer() << endl; else { cerr << "FAILED" << timer() << endl; cerr << "\tExpected: " << print_array(Expected) << endl; cerr << "\tReceived: " << print_array(Received) << endl; } return 0;}
template<int N> struct Case_ { Case_(){start_time=clock();} };
char Test_(...);
int Test_(Case_<0>) {
int s = 1;
int N = 5;
int K = 3;
int r1 = 0;
int r2 = 4;
int c1 = 0;
int c2 = 4;
string RetVal_[] = {"00000", "01110", "01110", "01110", "00000" };
vector <string> RetVal(RetVal_, RetVal_+sizeof(RetVal_)/sizeof(*RetVal_));
return verify_case(RetVal, PlaneFractal().getPattern(s, N, K, r1, r2, c1, c2)); }
int Test_(Case_<1>) {
int s = 2;
int N = 3;
int K = 1;
int r1 = 0;
int r2 = 8;
int c1 = 0;
int c2 = 8;
string RetVal_[] = {"000000000", "010010010", "000000000", "000111000", "010111010", "000111000", "000000000", "010010010", "000000000" };
vector <string> RetVal(RetVal_, RetVal_+sizeof(RetVal_)/sizeof(*RetVal_));
return verify_case(RetVal, PlaneFractal().getPattern(s, N, K, r1, r2, c1, c2)); }
int Test_(Case_<2>) {
int s = 3;
int N = 3;
int K = 1;
int r1 = 4;
int r2 = 11;
int c1 = 5;
int c2 = 10;
string RetVal_[] = {"101001", "100000", "000000", "001001", "000000", "000011", "001011", "000011" };
vector <string> RetVal(RetVal_, RetVal_+sizeof(RetVal_)/sizeof(*RetVal_));
return verify_case(RetVal, PlaneFractal().getPattern(s, N, K, r1, r2, c1, c2)); }
int Test_(Case_<3>) {
int s = 2;
int N = 8;
int K = 4;
int r1 = 56;
int r2 = 61;
int c1 = 33;
int c2 = 56;
string RetVal_[] = {"000000000000000000000000", "000000000000000000000000", "011110000111100001111000", "011110000111100001111000", "011110000111100001111000", "011110000111100001111000" };
vector <string> RetVal(RetVal_, RetVal_+sizeof(RetVal_)/sizeof(*RetVal_));
return verify_case(RetVal, PlaneFractal().getPattern(s, N, K, r1, r2, c1, c2)); }
template<int N> void Run_() { cerr << "Test Case #" << N << "..." << flush; Test_(Case_<N>()); Run_<sizeof(Test_(Case_<N+1>()))==1 ? -1 : N+1>(); }
template<> void Run_<-1>() {}
int main() { Run_<0>(); }
// END CUT HERE