#include <bits/stdc++.h>
using namespace std;
long long a[501][501];
int n;
bool check() {
  long long res = 0, tmp;
  for (int i = 0; i < n; ++i) res += a[0][i];
  for (int i = 0; i < n; ++i) {
    tmp = 0;
    for (int j = 0; j < n; ++j) tmp += a[i][j];
    if (res != tmp) return false;
    tmp = 0;
    for (int j = 0; j < n; ++j) tmp += a[j][i];
    if (res != tmp) return false;
  }
  tmp = 0;
  for (int i = 0; i < n; ++i) tmp += a[i][i];
  if (res != tmp) return false;
  tmp = 0;
  for (int i = 0; i < n; ++i) tmp += a[i][n - 1 - i];
  if (res != tmp) return false;
  return true;
}
int main() {
  int x, y;
  scanf("%d", &n);
  for (int i = 0; i < n; ++i)
    for (int j = 0; j < n; ++j) {
      scanf("%I64d", &a[i][j]);
      if (a[i][j] == 0) x = i, y = j;
    }
  if (n == 1)
    puts("1");
  else {
    int z = x - 1 >= 0 ? x - 1 : x + 1;
    long long sum = 0, tmp = 0;
    for (int j = 0; j < n; ++j) sum += a[z][j];
    for (int j = 0; j < n; ++j) sum -= a[x][j];
    a[x][y] = sum;
    if (check() && sum > 0)
      printf("%I64d\n", sum);
    else
      puts("-1");
  }
  return 0;
}
