// #include #include #include #include #include #include using namespace std; typedef long long ll; typedef pair pii; typedef pair pll; typedef vector vi; typedef vector vl; #define REP(i,n) for(ll i=0;i<(n);++i) #define REPR(i,n) for(ll i=1;i<(n);++i) #define FOR(i,a,b) for(ll i=(a);i<(b);++i) #define DEBUG(x) cout<<(#x)<<": "<<(x)<y&&yz&&x!=z); } bool check(int val){ if(val<=0 || val>=l)return false; int x = val; int y = l-x; int id = 0; REP(i,3)REP(j,3){ if(a[i][j]==0){ if(id==0)a[i][j] = x; else a[i][j] = y; id++; } } REP(i,3){ REP(j,3)c[j]=a[i][j]; if(!kado())return false; } REP(i,3){ REP(j,3)c[j]=a[j][i]; if(!kado())return false; } REP(i,3)c[i]=a[i][i]; if(!kado())return false; REP(i,3)c[i]=a[2-i][i]; if(!kado())return false; return true; } void solve(){ scanf("%d",&l); REP(i,3)REP(j,3)scanf("%d",&b[i][j]); set S; REP(i,3)REP(j,3)S.insert(b[i][j]); REP(i,3)REP(j,3)S.insert(l-b[i][j]); S.insert(l/2-1); S.insert(l/2); S.insert(l/2+1); set::iterator iter = S.begin(); int ans = 0; while(iter != S.end()){ int x = *iter; iter++; if(iter==S.end())break; int y = *iter; REP(i,3)REP(j,3)a[i][j]=b[i][j]; if(check(x)){ ans += 1; } REP(i,3)REP(j,3)a[i][j]=b[i][j]; if(x+1