#include <iostream>
using namespace std;
#define ll long long
int main()
{
int n;
cin >> n;
ll arr[n][n];
int i, j;
int row = 10000, col = 10000;
for(i = 0; i < n; i++) {
for(j = 0; j < n; j++) {
cin >> arr[i][j];
if(arr[i][j] == 0) {
row = i;
col = j;
}
}
}
ll sumR = 0, sumR2 = 0;
ll sumC = 0, sumC2 = 0;
ll sumD = 0, sumD2 = 0;
int flag = 0;
int exec = 0;
for(i = 0; i < n; i++) {
if(i != row) {
for(j = 0; j < n; j++)
sumR += arr[i][j];
if(exec != 0) {
if(sumR != sumR2) {
flag = 1;
break;
}
}
sumR2 = sumR;
sumR = 0;
exec++;
}
}
//cout << row << " " << col << endl;
exec = 0;
for(j = 0; j < n; j++) {
if(j != col) {
//cout << i << " " << j << endl;
for(i = 0; i < n; i++)
sumC += arr[i][j];
//cout << sumC << " " << sumC2 << endl;
if(exec != 0) {
if(sumC != sumC2) {
flag = 1;
break;
}
}
sumC2 = sumC;
sumC = 0;
exec++;
//cout << sumC << " " << sumC2 << endl;
}
}
int flag2 = 0;
for(i = 0, j = 0; i < n && j < n; i++, j++) {
if(i == row && j == col) {
sumD = 0;
flag2 = 1;
break;
} else {
sumD += arr[i][j];
}
//cout << sumD << " ";
}
for(i = 0, j = n-1; i < n && j >= 0; i++, j--) {
if(i == row && j == col) {
sumD2 = 0;
flag2 = 2;
break;
} else {
sumD2 += arr[i][j];
}
//cout << endl << sumD2 << " ";
}
//cout << endl;
ll ans = 0;
ll s = 0;
if(flag2 == 0) {
if(sumR2 == sumC2 && sumR2 == sumD && sumR2 == sumD2) {
//ll s = 0;
for(j = 0; j < n; j++)
s += arr[row][j];
ans = sumR2 - s;
}
//cout << ans << " " << s << endl;
} else if(flag2 == 1) {
if(sumR2 == sumC2 && sumR2 == sumD2) {
//ll s = 0;
for(j = 0; j < n; j++)
s += arr[row][j];
ans = sumR2 - s;
}
//cout << ans << " " << s << endl;
} else if(flag2 == 2) {
if(sumR2 == sumC2 && sumR2 == sumD) {
//ll s = 0;
for(j = 0; j < n; j++)
s += arr[row][j];
ans = sumR2 - s;
}
//cout << ans << " " << s << endl;
}
//cout << sumR2 << " " << sumC2 << " " << sumD << " " << sumD2 << " " << flag << " " << flag2 << " " << ans << " " << s << endl;
if(flag == 0 && ans > 0) {
cout << ans << endl;
} else
cout << "-1" << endl;
//cout << flag << ans;
return 0;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgp1c2luZyBuYW1lc3BhY2Ugc3RkOwojZGVmaW5lIGxsIGxvbmcgbG9uZwoKaW50IG1haW4oKQp7CiAgICBpbnQgbjsKICAgIGNpbiA+PiBuOwogICAgbGwgYXJyW25dW25dOwogICAgaW50IGksIGo7CiAgICBpbnQgcm93ID0gMTAwMDAsIGNvbCA9IDEwMDAwOwogICAgZm9yKGkgPSAwOyBpIDwgbjsgaSsrKSB7CiAgICAgICAgZm9yKGogPSAwOyBqIDwgbjsgaisrKSB7CiAgICAgICAgICAgIGNpbiA+PiBhcnJbaV1bal07CiAgICAgICAgICAgIGlmKGFycltpXVtqXSA9PSAwKSB7CiAgICAgICAgICAgICAgICByb3cgPSBpOwogICAgICAgICAgICAgICAgY29sID0gajsKICAgICAgICAgICAgfQogICAgICAgIH0KICAgIH0KICAgIGxsIHN1bVIgPSAwLCBzdW1SMiA9IDA7CiAgICBsbCBzdW1DID0gMCwgc3VtQzIgPSAwOwogICAgbGwgc3VtRCA9IDAsIHN1bUQyID0gMDsKICAgIGludCBmbGFnID0gMDsKICAgIGludCBleGVjID0gMDsKICAgIGZvcihpID0gMDsgaSA8IG47IGkrKykgewogICAgICAgIGlmKGkgIT0gcm93KSB7CiAgICAgICAgICAgIAogICAgICAgICAgICBmb3IoaiA9IDA7IGogPCBuOyBqKyspCiAgICAgICAgICAgICAgICBzdW1SICs9IGFycltpXVtqXTsKICAgICAgICAgICAgaWYoZXhlYyAhPSAwKSB7CiAgICAgICAgICAgICAgICBpZihzdW1SICE9IHN1bVIyKSB7CiAgICAgICAgICAgICAgICAgICAgZmxhZyA9IDE7CiAgICAgICAgICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgIH0KCiAgICAgICAgICAgICAgICBzdW1SMiA9IHN1bVI7CiAgICAgICAgICAgICAgICBzdW1SID0gMDsKICAgICAgICAgICAgCiAgICAgICAgICAgIGV4ZWMrKzsKICAgICAgICB9CiAgICB9CiAgICAvL2NvdXQgPDwgcm93IDw8ICIgIiA8PCBjb2wgPDwgZW5kbDsKICAgIGV4ZWMgPSAwOwogICAgZm9yKGogPSAwOyBqIDwgbjsgaisrKSB7CiAgICAgICAgaWYoaiAhPSBjb2wpIHsKICAgICAgICAgICAgLy9jb3V0IDw8IGkgPDwgIiAiIDw8IGogPDwgZW5kbDsKICAgICAgICAgICAgZm9yKGkgPSAwOyBpIDwgbjsgaSsrKQogICAgICAgICAgICAgICAgc3VtQyArPSBhcnJbaV1bal07CiAgICAgICAgICAgIC8vY291dCA8PCBzdW1DIDw8ICIgIiA8PCBzdW1DMiA8PCBlbmRsOwogICAgICAgICAgICBpZihleGVjICE9IDApIHsKICAgICAgICAgICAgICAgIGlmKHN1bUMgIT0gc3VtQzIpIHsKICAgICAgICAgICAgICAgICAgICBmbGFnID0gMTsKICAgICAgICAgICAgICAgICAgICBicmVhazsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgfSAKICAgICAgICAgICAgICAgIHN1bUMyID0gc3VtQzsKICAgICAgICAgICAgICAgIHN1bUMgPSAwOwogICAgICAgICAgICAKICAgICAgICAgICAgZXhlYysrOwogICAgICAgICAgICAvL2NvdXQgPDwgc3VtQyA8PCAiICIgPDwgc3VtQzIgPDwgZW5kbDsKICAgICAgICB9CiAgICB9CiAgICBpbnQgZmxhZzIgPSAwOwogICAgZm9yKGkgPSAwLCBqID0gMDsgaSA8IG4gJiYgaiA8IG47IGkrKywgaisrKSB7CiAgICAgICAgaWYoaSA9PSByb3cgJiYgaiA9PSBjb2wpIHsKICAgICAgICAgICAgc3VtRCA9IDA7CiAgICAgICAgICAgIGZsYWcyID0gMTsKICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgc3VtRCArPSBhcnJbaV1bal07CiAgICAgICAgfQogICAgICAgIC8vY291dCA8PCBzdW1EIDw8ICIgIjsKICAgIH0KICAgIGZvcihpID0gMCwgaiA9IG4tMTsgaSA8IG4gJiYgaiA+PSAwOyBpKyssIGotLSkgewogICAgICAgIGlmKGkgPT0gcm93ICYmIGogPT0gY29sKSB7CiAgICAgICAgICAgIHN1bUQyID0gMDsKICAgICAgICAgICAgZmxhZzIgPSAyOwogICAgICAgICAgICBicmVhazsKICAgICAgICB9IGVsc2UgewogICAgICAgICAgICBzdW1EMiArPSBhcnJbaV1bal07CiAgICAgICAgfQogICAgICAgIC8vY291dCA8PCBlbmRsIDw8IHN1bUQyIDw8ICIgIjsKICAgIH0KICAgIC8vY291dCA8PCBlbmRsOwogICAgbGwgYW5zID0gMDsKICAgIGxsIHMgPSAwOwogICAgaWYoZmxhZzIgPT0gMCkgewogICAgICAgIGlmKHN1bVIyID09IHN1bUMyICYmIHN1bVIyID09IHN1bUQgJiYgc3VtUjIgPT0gc3VtRDIpIHsKICAgICAgICAgICAgLy9sbCBzID0gMDsKICAgICAgICAgICAgZm9yKGogPSAwOyBqIDwgbjsgaisrKQogICAgICAgICAgICAgICAgcyArPSBhcnJbcm93XVtqXTsKICAgICAgICAgICAgYW5zID0gc3VtUjIgLSBzOwogICAgICAgICAgICAKICAgICAgICAgICAgCiAgICAgICAgfQogICAgICAgIC8vY291dCA8PCBhbnMgPDwgIiAiIDw8IHMgPDwgZW5kbDsKICAgIH0gZWxzZSBpZihmbGFnMiA9PSAxKSB7CiAgICAgICAgICBpZihzdW1SMiA9PSBzdW1DMiAmJiBzdW1SMiA9PSBzdW1EMikgewogICAgICAgICAgICAvL2xsIHMgPSAwOwogICAgICAgICAgICBmb3IoaiA9IDA7IGogPCBuOyBqKyspCiAgICAgICAgICAgICAgICBzICs9IGFycltyb3ddW2pdOwogICAgICAgICAgICBhbnMgPSBzdW1SMiAtIHM7ICAgICAgIAogICAgICAgIH0KICAgICAgICAvL2NvdXQgPDwgYW5zIDw8ICIgIiA8PCBzIDw8IGVuZGw7ICAgICAgCiAgICB9IGVsc2UgaWYoZmxhZzIgPT0gMikgewogICAgICAgICAgICBpZihzdW1SMiA9PSBzdW1DMiAmJiBzdW1SMiA9PSBzdW1EKSB7CiAgICAgICAgICAgIC8vbGwgcyA9IDA7CiAgICAgICAgICAgIGZvcihqID0gMDsgaiA8IG47IGorKykKICAgICAgICAgICAgICAgIHMgKz0gYXJyW3Jvd11bal07CiAgICAgICAgICAgIGFucyA9IHN1bVIyIC0gczsKICAgICAgICAgICAgCiAgICAgICAgICAgCiAgICAgICAgfQogICAgICAgIC8vY291dCA8PCBhbnMgPDwgIiAiIDw8IHMgPDwgZW5kbDsKICAgIH0KICAgIC8vY291dCA8PCBzdW1SMiA8PCAiICIgPDwgc3VtQzIgPDwgIiAiIDw8IHN1bUQgPDwgIiAiIDw8IHN1bUQyIDw8ICIgIiA8PCBmbGFnIDw8ICIgIiA8PCBmbGFnMiA8PCAiICIgPDwgYW5zIDw8ICIgIiA8PCBzIDw8IGVuZGw7CiAgICBpZihmbGFnID09IDAgICYmIGFucyA+IDApIHsKICAgICAgICBjb3V0IDw8IGFucyA8PCBlbmRsOwogICAgfSBlbHNlCiAgICAgICAgY291dCA8PCAiLTEiIDw8IGVuZGw7CiAgICAvL2NvdXQgPDwgZmxhZyA8PCBhbnM7CiAgICByZXR1cm4gMDsKfQ==