#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstring>
#include <math.h>
#define lli long long int
using namespace std;
int main(){
int n;
cin >> n;
lli a[n][n];
int i = 0;
int j = 0;
int x, y;
lli xsum = 0;
lli ysum = 0;
lli diag1 = 0;
lli diag2 = 0;
lli checksum = 0;
for(int i = 0; i < n; i++){
for(int j = 0; j < n; j++){
cin >> a[i][j];
if(a[i][j] == 0){
x = i;
y = j;
}
}
}
for(int j = 0; j < n; j++){
xsum += a[x][j];
checksum += a[x+1][j];
}
for(int j = 0; j < n; j++){
ysum += a[j][y];
}
int f = n-1;
int t = 0;
diag1 = a[0][0];
diag2 = a[n-1][0];
if(x == y){
for(int i = 0; i < n; i++){
for(int j = 1; j < n-1; j++){
diag1 += a[i+1][j];
}
}
if(diag1 == xsum && xsum == ysum){
cout << abs(xsum - checksum);
return 0;
}
else{
cout << -1;
return 0;
}
}
else if(abs(f-y) == abs(x-t)){
for(int i = n-1; i > 1; i--){
for(int j = 1; j < n-2; j++){
diag2 += a[i][j];
}
}
if(diag2 == xsum && xsum == ysum){
cout << abs(xsum - checksum);
return 0;
}
else{
cout << -1;
return 0;
}
}
else{
if(xsum == ysum){
cout << abs(checksum - xsum) << endl;
}
}
}
I2luY2x1ZGUgPHZlY3Rvcj4KI2luY2x1ZGUgPGxpc3Q+CiNpbmNsdWRlIDxtYXA+CiNpbmNsdWRlIDxzZXQ+CiNpbmNsdWRlIDxxdWV1ZT4KI2luY2x1ZGUgPGRlcXVlPgojaW5jbHVkZSA8c3RhY2s+CiNpbmNsdWRlIDxiaXRzZXQ+CiNpbmNsdWRlIDxhbGdvcml0aG0+CiNpbmNsdWRlIDxmdW5jdGlvbmFsPgojaW5jbHVkZSA8bnVtZXJpYz4KI2luY2x1ZGUgP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