###### Coderforces 711B Chris and Magic Square

#include<iostream>
#include<cstring>
#include<algorithm>
using namespace std;
const int maxn=500+10;
typedef long long LL;
LL map[maxn][maxn];
int n;
int x,y;
LL solve()
{
if(n==1) return 1;
LL sum=0;
if(x==1)
for(int i=1;i<=n;i++) sum+=map[2][i];
else
for(int i=1;i<=n;i++) sum+=map[1][i];
LL aim=sum;
for(int i=1;i<=n;i++)
aim-=map[x][i];
if(aim<=0) return -1;
map[x][y]=aim;
for(int i=1;i<=n;i++)
{
LL temp=0;
for(int j=1;j<=n;j++)
{
temp+=map[i][j];
}
if(temp!=sum) return -1;
}
for(int j=1;j<=n;j++)
{
LL temp=0;
for(int i=1;i<=n;i++)
{
temp+=map[i][j];
}
if(sum!=temp) return -1;
}
LL temp=0;
for(int i=1;i<=n;i++)
temp+=map[i][i];
if(temp!=sum) return -1;
temp=0;
for(int i=1;i<=n;i++)
temp+=map[i][n-i+1];
if(temp!=sum) return -1;
return aim;
}
int main()
{
while(scanf("%d",&n)!=EOF)
{
for(int i=1;i<=n;i++)
{
for(int j=1;j<=n;j++)
{
cin>>map[i][j];
if(map[i][j]==0) {x=i;y=j;}
}
}
cout<<solve()<<endl;
}
return 0;
}

#### Codeforces 711B Chris and Magic Square

2016-08-30 10:16:48

#### CodeForces - 711B Chris and Magic Square

2017-09-03 21:11:59

#### codeforces#369Div2(711B)Chris and Magic Square

2016-08-30 21:03:22

#### Chris and Magic Square(CodeForces - 711B)

2018-03-30 09:37:24

#### CodeForces 711B Chris and Magic Square

2017-10-14 19:28:25

#### 模拟-711B - Chris and Magic Square

2016-08-30 12:56:32

#### CodeForces 711B - Chris and Magic Square

2016-08-30 21:31:34

#### Chris and Magic Square CodeForces - 711B

2017-03-22 20:50:39

#### 【模拟】Codeforces 711B Chris and Magic Square

2016-08-30 14:51:23

#### C - Chris and Magic Square CodeForces - 711B

2017-10-15 10:57:50

## 不良信息举报

Coderforces 711B Chris and Magic Square