#include<bits/stdc++.h>
using namespace std;
int n,b[510],p[250010],m[250010];
int a[510][510],ans[510][510];
void bfs(int start){
int i,h=0,t=1;
memset(b,0x3f,sizeof(b));
p[1]=start;
m[1]=0;
do{
h++;
for(i=1;i<=n;i++)
if(i!=p[h]&&a[p[h]][i]>=m[h]&&b[i]>a[p[h]][i]){
p[++t]=i;
m[t]=a[p[h]][i];
b[i]=a[p[h]][i];
ans[start][i]=min(ans[start][i],m[t]);
}
}while(h<t);
}
int main(){
freopen(".in","r",stdin);
freopen(".out","w",stdout);
int i,j;
scanf("%d",&n);
for(i=1;i<=n;i++)
for(j=1;j<=n;j++)
scanf("%d",&a[i][j]);
memset(ans,0x3f,sizeof(ans));
for(i=1;i<=n;i++)
bfs(i);
for(i=1;i<=n;i++){
for(j=1;j<=n;j++)
if(ans[i][j]!=0x3f3f3f3f&&i!=j)printf("%d ",ans[i][j]);
else printf("0 ");
printf("\n");
}
return 0;
}