#include <bits/stdc++.h>
using namespace std;
int main(int argc, char const *argv[]) {
  int n, x, y;
  cin >> n;
  long long a[n][n];
  for (int i = 0; i < (n); ++i)
    for (int j = 0; j < (n); ++j) {
      cin >> a[i][j];
      if (!a[i][j]) x = i, y = j;
    }
  if (n == 1) {
    cout << "1\n";
    return 0;
  }
  long long sum = 0, r = 0;
  if (!x) r = 1;
  for (int j = 0; j < (n); ++j) sum += a[r][j];
  for (int row = 0; row < (n); ++row) {
    if (row == x) continue;
    long long sm = 0;
    for (int j = 0; j < (n); ++j) sm += a[row][j];
    if (sm != sum) {
      cout << "-1\n";
      return 0;
    }
  }
  for (int col = 0; col < (n); ++col) {
    if (col == y) continue;
    long long sm = 0;
    for (int i = 0; i < (n); ++i) sm += a[i][col];
    if (sm != sum) {
      cout << "-1\n";
      return 0;
    }
  }
  if (x != y) {
    long long sm = 0;
    for (int i = 0; i < (n); ++i) sm += a[i][i];
    if (sm != sum) {
      cout << "-1\n";
      return 0;
    }
  }
  if (x + y != n - 1) {
    long long sm = 0;
    for (int i = 0; i < (n); ++i) sm += a[i][n - 1 - i];
    if (sm != sum) {
      cout << "-1\n";
      return 0;
    }
  }
  long long temp = 0;
  for (int i = 0; i < (n); ++i) temp += a[i][y];
  long long temp1 = 0;
  for (int j = 0; j < (n); ++j) temp1 += a[x][j];
  if (temp1 != temp || temp >= sum) {
    cout << "-1\n";
    return 0;
  }
  if (x == y) {
    long long sm = 0;
    for (int i = 0; i < (n); ++i) sm += a[i][i];
    if (sm != temp) {
      cout << "-1\n";
      return 0;
    }
  }
  if (x + y == n - 1) {
    long long sm = 0;
    for (int i = 0; i < (n); ++i) sm += a[i][n - 1 - i];
    if (sm != temp) {
      cout << "-1\n";
      return 0;
    }
  }
  cout << sum - temp << endl;
  return 0;
}
