#include using namespace std; struct Op{int k,r,c;}; int N; vector> a; bool useop[4][505][505]; Op tf(Op o,int fr,int fc,int sw){ if(sw) swap(o.r,o.c); if(fr) o.r=N-1-o.r; if(fc) o.c=N-1-o.c; return o; } int main(){ ios::sync_with_stdio(false); cin.tie(nullptr); cin>>N; vector s(N); for(auto &x:s) cin>>x; a.assign(N,vector(N)); for(int i=0;i> v; for(int d=-o.k;d<=o.k;d++){ v.push_back({o.r+d,o.c+d}); if(d) v.push_back({o.r+d,o.c-d}); } return v; }; // 小さい N は普通に GF(2) ガウス消去 if(N<=10){ constexpr int B=256; vector op; for(int k=1;2*k,100> bs{}; for(int i=0;i v; v[D+i]=1; for(auto [r,c]:cells(op[i])) v[r*N+c]=1; for(int p=0;p t; for(int r=0;r ans; for(int i=0;i& g,int fr=0,int fc=0,int sw=0){ for(auto o:g) put(tf(o,fr,fc,sw)); }; // 2層目の角付近用 const vector Q0={ {3,3,4},{1,1,6},{1,6,1} }; const vector Q1={ {3,4,3},{1,1,6},{1,6,1} }; // 最外周の角用 const vector C={ {1,1,3},{1,1,5},{1,2,2}, {1,3,1},{1,5,1},{3,3,3} }; // 上辺の (0,j),(0,j+2) 用、j=1,2,3 const vector P[3]={ { {1,1,4},{1,1,6},{1,2,1},{1,2,5}, {1,4,1},{1,5,2},{1,6,1},{3,3,4},{3,4,3} }, { {1,1,5},{1,1,7},{1,2,4},{3,3,5} }, { {1,1,2},{1,1,6},{1,3,2},{1,5,2},{3,3,4} } }; // 2層目の、角付近以外を直接消す for(int r=0;r=N-6){ int q=(j<=3?j:N-3-j); int mir=(j>=N-6); for(auto o:P[q-1]) put(tf(tf(o,0,mir,0),fr,fc,sw)); } else{ vector g={ {3,3,j+1}, {1,1,j-1}, {1,1,j+3} }; run(g,fr,fc,sw); } }; auto point=[&](int j,int side){ return tf({0,0,j},T[side][0],T[side][1],T[side][2]); }; // 最外周を各辺ごとに2マスずつ送って消す for(int side=0;side<4;side++){ for(int j=1;j<=N-4;j++){ Op p=point(j,side); if(a[p.r][p.c]) pairput(j,side); } } // 内部は5操作で1マスだけ反転 for(int r=2;r<=N-3;r++) for(int c=2;c<=N-3;c++){ if(!a[r][c]) continue; put({2,r,c}); put({1,r-1,c-1}); put({1,r-1,c+1}); put({1,r+1,c-1}); put({1,r+1,c+1}); } vector ans; for(int k=1;k<=3;k++) for(int r=0;r