#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;
}