#include<iostream>
#include<algorithm>
#include<cstdio>
#define ll long long
using namespace std;
ll s1[550];
ll s2[550];
ll s3,s4;
ll v1,v2,v3;
int main(){
ll n,a[505][505];
cin>>n;
int v;
if(n==1){
ll t;
cin>>t;
cout<<"1"<<endl;
return 0;
}
ll x,y;
ll top=0;
for(int i=1;i<=n;i++){
for(int j=1;j<=n;j++){
cin>>a[i][j];
if(!a[i][j]){
x=i;
y=j;
}
}
}
ll sum=0;
ll sumpre=0;
for(int i=1;i<=n;i++)
{
sumpre+=a[x][i];
if(x>1)
sum+=a[1][i];
else if(x==1)
sum+=a[n][i];
}
a[x][y]=sum-sumpre;
for(int i=1;i<=n;i++){
for(int j=1;j<=n;j++){
s1[i]+=a[i][j];
if(i==1){
v1=s1[i];
}
}
if(i>1){
if(s1[i]!=s1[i-1]){
cout<<-1<<endl;
return 0;
}
}
}
for(int i=1;i<=n;i++){
for(int j=1;j<=n;j++){
s2[i]+=a[j][i];
if(i==1){
v2=s2[i];
}
}
if(i>1){
if(s2[i]!=s2[i-1]){
cout<<-1<<endl;
return 0;
}
}
}
for(int i=1;i<=n;i++){
s3+=a[i][i];
}
for(int i=1;i<=n;i++){
s4+=a[i][n-i+1];
}
if(s3!=s4){
cout<<-1<<endl;
return 0;
}else{
v3=s3;
}
if(a[x][y]<=0){
cout<<-1<<endl;
return 0;
}
if(v1==v2&&v2==v3)
cout<<a[x][y]<<endl;
else
cout<<-1<<endl;
return 0;
}