#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  long long arr[502][502];
  long long row[501] = {0};
  long long col[501] = {0};
  int r, c;
  for (int i = 0; i < n; i++)
    for (int j = 0; j < n; j++) {
      cin >> arr[i][j];
      if (arr[i][j] == 0) {
        r = i;
        c = j;
      }
    }
  if (n == 1) {
    if (arr[0][0] == 0) {
      cout << 1 << endl;
      return 0;
    }
  }
  long long x;
  for (int i = 0; i < n; i++) {
    x = 0;
    for (int j = 0; j < n; j++) {
      x += arr[i][j];
    }
    row[i] = x;
  }
  for (int i = 0; i < n; i++) {
    x = 0;
    for (int j = 0; j < n; j++) {
      x += arr[j][i];
    }
    col[i] = x;
  }
  long long d1 = 0, d2 = 0;
  long long req;
  if (r != 0)
    req = row[0];
  else
    req = row[1];
  int f = 1;
  for (int i = 0; i < n; i++) {
    if (i != r) {
      if (row[i] != req) {
        f = 0;
        break;
      }
    }
  }
  if (f == 0) {
    cout << -1 << endl;
    return 0;
  }
  for (int i = 0; i < n; i++) {
    if (i != c) {
      if (col[i] != req) {
        f = 0;
        break;
      }
    }
  }
  if (f == 0) {
    cout << -1 << endl;
    return 0;
  } else {
    long long pp = req - row[r];
    long long qq = req - col[c];
    if (pp <= 0 || qq <= 0) {
      cout << -1 << endl;
      return 0;
    }
    if (pp != qq) {
      cout << -1 << endl;
      return 0;
    }
    arr[r][c] = pp;
    for (int i = 0; i < n; i++) {
      x = 0;
      for (int j = 0; j < n; j++) {
        x += arr[i][j];
      }
      if (x != req) {
        f = 0;
        break;
      }
    }
    for (int i = 0; i < n; i++) {
      x = 0;
      for (int j = 0; j < n; j++) {
        x += arr[j][i];
      }
      if (x != req) {
        f = 0;
        break;
      }
    }
    for (int i = 0; i < n; i++) {
      d1 += arr[i][i];
    }
    int t1 = 0, t2 = n - 1;
    for (; t1 < n; t1++) {
      d2 += arr[t1][n - 1 - t1];
    }
    if (f == 0) {
      cout << -1 << endl;
      return 0;
    }
    if (d1 != req || d2 != req) {
      cout << -1 << endl;
      return 0;
    }
    if (d1 != d2) {
      cout << -1 << endl;
      return 0;
    } else
      cout << pp << endl;
  }
  return 0;
}
