#include #include using namespace std; ifstream in("block.in"); ofstream out("block.out"); int a[50][50]; pair ans[1000000]; int lins[100],cols[100],n,k; bool stick1() { for(int i=2;i<=n;i++) for(int j=2;j<=n;j++) if(a[i][j]+a[i-1][j-1]+a[i-1][j]+a[i][j-1]==0) { ans[++k]={i,j}; a[i][j]=a[i-1][j-1]=a[i-1][j]=a[i][j-1]=1; return true; } return false; } bool stick2() { for(int i=2;i<=n;i++) for(int j=1;j1;i--) for(int j=n;j>1;j--) if(a[i][j]+a[i-1][j]+a[i][j-1]==0) { ans[++k]={i,j}; a[i][j]=a[i-1][j]=a[i][j-1]=1; return true; } return false; } bool stick6() { for(int i=n;i>1;i--) for(int j=1;j1;j--) if(a[i][j]+a[i+1][j]+a[i][j-1]==0) { ans[++k]={i,j}; a[i][j]=a[i+1][j]=a[i][j-1]=1; return true; } return false; } bool stick9() { for(int i=n;i>1;i--) for(int j=n;j>2;j--) if(a[i][j]+a[i-1][j]+a[i][j-1]+a[i][j-2]==0) { ans[++k]={i,j}; a[i][j]=a[i-1][j]=a[i][j-1]=a[i][j-2]=1; return true; } return false; } bool stick10() { for(int i=n;i>2;i--) for(int j=1;j1;j--) if(a[i][j]+a[i+1][j]+a[i][j-1]+a[i+2][j]==0) { ans[++k]={i,j}; a[i][j]=a[i+1][j]=a[i][j-1]=a[i+2][j]=1; return true; } return false; } bool stick13() { for(int i=1;i<=n;i++) for(int j=4;j<=n;j++) if(a[i][j]+a[i][j-1]+a[i][j-2]+a[i][j-3]==0) { ans[++k]={i,j}; a[i][j]=a[i][j-1]=a[i][j-2]=a[i][j-3]=1; return true; } return false; } bool stick14() { for(int i=4;i<=n;i++) for(int j=1;j<=n;j++) if(a[i][j]+a[i-1][j]+a[i-2][j]+a[i-3][j]==0) { ans[++k]={i,j}; a[i][j]=a[i-1][j]=a[i-2][j]=a[i-3][j]=1; return true; } return false; } bool stick15() { for(int i=1;i<=n;i++) for(int j=1;j<=n-3;j++) if(a[i][j]+a[i][j+1]+a[i][j+2]+a[i][j+3]==0) { ans[++k]={i,j}; a[i][j]=a[i][j+1]=a[i][j+2]=a[i][j+3]=1; return true; } return false; } bool stick16() { for(int i=1;i<=n-3;i++) for(int j=1;j<=n;j++) if(a[i][j]+a[i+1][j]+a[i+2][j]+a[i+3][j]==0) { ans[++k]={i,j}; a[i][j]=a[i+1][j]=a[i+2][j]=a[i+3][j]=1; return true; } return false; } bool stick17() { for(int i=n;i>2;i--) for(int j=n;j>1;j--) if(a[i][j]+a[i-1][j]+a[i-2][j]+a[i-1][j-1]==0) { ans[++k]={i,j}; a[i][j]=a[i-1][j]=a[i-2][j]=a[i-1][j-1]=1; return true; } return false; } bool stick18() { for(int i=n;i>2;i--) for(int j=1;j2;j--) if(a[i][j]+a[i][j-1]+a[i][j-2]+a[i+1][j-1]==0) { ans[++k]={i,j}; a[i][j]=a[i][j-1]=a[i][j-2]=a[i+1][j-1]=1; return true; } return false; } int main() { long long aa,b,c,d,e,f; in>>n>>aa>>b>>c>>d>>e>>f; for(int i=0;i<=n+1;i++) a[i][0]=a[0][i]=a[i][n+1]=a[n+1][i]=1; while(true) { c=(c^aa)+b, f=(f^d)+e; int block=c%5, angle=f%4; bool ok=0; if(block==0&&angle==0) ok=stick1(); if(block==0&&angle==1) ok=stick2(); if(block==0&&angle==2) ok=stick3(); if(block==0&&angle==3) ok=stick4(); if(block==1&&angle==0) ok=stick5(); if(block==1&&angle==1) ok=stick6(); if(block==1&&angle==2) ok=stick7(); if(block==1&&angle==3) ok=stick8(); if(block==2&&angle==0) ok=stick9(); if(block==2&&angle==1) ok=stick10(); if(block==2&&angle==2) ok=stick11(); if(block==2&&angle==3) ok=stick12(); if(block==3&&angle==0) ok=stick13(); if(block==3&&angle==1) ok=stick14(); if(block==3&&angle==2) ok=stick15(); if(block==3&&angle==3) ok=stick16(); if(block==4&&angle==0) ok=stick17(); if(block==4&&angle==1) ok=stick18(); if(block==4&&angle==2) ok=stick19(); if(block==4&&angle==3) ok=stick20(); if(!ok) break; int p1=0,p2=0; for(int i=1;i<=n;i++) { bool ok1=1,ok2=1; for(int j=1;j<=n&&ok1;j++) ok1=a[i][j]; for(int j=1;j<=n&&ok2;j++) ok2=a[j][i]; if(ok1) lins[++p1]=i; if(ok2) cols[++p2]=i; } for(int i=1;i<=p1;i++) for(int j=1;j<=n;j++) a[lins[i]][j]=0; for(int i=1;i<=p2;i++) for(int j=1;j<=n;j++) a[j][cols[i]]=0; } out<