Solving
#include <bits/stdc++.h> using namespace std;
const int n=310;
const int p=1000000007;
int k,n,m;
int a[n][n],b[n][n],inv[n][n],c[n][n];
int f[n],cur,v[n],t[n];
vector<int>g[n];
int Abs (int x) {return x>0?x:-x;} int Pow (int x,int y) {int ans=1;
for (; y;y>>=1,x=1ll*x*x%p) if (y&1) ans=1ll*ans*x%p;
return Ans;
} void Get_inv () {for (int i=1;i<=n;i++) inv[i][i]=1;
for (int i=1;i<=n;i++) {int pos=i;
for (int j=i;j<=n;j++) if (Abs (A[j][i]) >abs (a[pos][i)) pos=j;
for (int j=1;j<=n;j++) swap (a[i][j],a[pos][j]), swap (inv[i][j],inv[pos][j]);
int T=pow (A[I][I],P-2);
for (int j=1;j<=n;j++) a[i][j]=1ll*a[i][j]*t%p,inv[i][j]=1ll*inv[i][j]*t%p;
for (int j=1;j<=n;j++) if (I!=j&&a[j][i]) {int x=a[j][i];
for (int k=1;k<=n;k++) {a[j][k]= (a[j][k]-1ll*x*a[i][k])%P; Inv[j][k]= (inv[j][k]-1ll*x*inV[I][K])%P;
BOOL Dfs (int x) {if (v[x]==cur) return 0;
V[x]=cur;
for (int i=0;i<g[x].size (); i++) {int v=g[x][i]; if (!f[v]| |
Dfs (F[v])) {f[v]=x;t[x]=v;
return 1;
} return 0;
BOOL Find (int x) {if (v[x]==cur) return 0;
V[x]=cur;
for (int i=0;i<g[x].size (); i++) {int v=g[x][i]; if (!f[v]| | (F[v]>cur&&find (F[v]))
{f[v]=x;t[x]=v;
return 1;
} return 0;
int main () {scanf ("%d", &n);
for (int i=1;i<=n;i++) for (int j=1;j<=n;j++) scanf ("%d", &a[i][j]);
for (int i=1;i<=n;i++) for (int j=1;j<=n;j++) scanf ("%d", &b[i][j]);
GET_INV (); for (int k=1;k<=n;k++) for (int i=1;i<=n;i++) for (int j=1;j<=n;j++) c[i][j]= (c[
I][J]+1LL*B[I][K]*INV[K][J])%P;
for (int i=1;i<=n;i++) for (int j=1;j<=n;j++) if (C[i][j]) g[j].push_back (i);
for (int i=1;i<=n;i++) {cur=i; if (!
Dfs (i)) {puts ("NIE");
return 0;
} memset (V,0,sizeof (v));
for (int i=1;i<=n;i++) cur=i,f[t[i]]=0,find (i);
Puts ("TAK");
for (int i=1;i<=n;i++) printf ("%d\n", T[i]);
return 0; }