#include <bits/stdc++.h>
using namespace std;
long long ds1, ds2, hs[505], ls[505], goal, n, i, j, x, sx, sy;
long long read() {
  long long n = 0, f = 1;
  char c = getchar();
  while (c < '0' || c > '9') {
    if (c == '-') f = -1;
    c = getchar();
  }
  while (c >= '0' && c <= '9') {
    n = n * 10 + c - '0';
    c = getchar();
  }
  return n * f;
}
int main() {
  n = read();
  for (i = 1; i <= n; i++)
    for (j = 1; j <= n; j++) {
      x = read();
      if (!x) {
        sx = i;
        sy = j;
      }
      hs[i] += x;
      ls[j] += x;
      if (i == j) ds1 += x;
      if (i + j == n + 1) ds2 += x;
    }
  for (i = 1; i <= n; i++)
    if (i != sx)
      if (goal) {
        if (hs[i] != goal) {
          printf("-1");
          return 0;
        }
      } else
        goal = hs[i];
  for (j = 1; j <= n; j++)
    if (j != sy)
      if (goal) {
        if (ls[j] != goal) {
          printf("-1");
          return 0;
        }
      } else
        goal = ls[j];
  if (sx != sy)
    if (goal) {
      if (ds1 != goal) {
        printf("-1");
        return 0;
      }
    } else
      goal = ds1;
  if (sx + sy != n + 1)
    if (goal) {
      if (ds2 != goal) {
        printf("-1");
        return 0;
      }
    } else
      goal = ds2;
  if (hs[sx] != ls[sy]) {
    printf("-1");
    return 0;
  }
  if (sx == sy)
    if (hs[sx] != ds1) {
      printf("-1");
      return 0;
    }
  if (sx + sy == n + 1)
    if (ls[sy] != ds2) {
      printf("-1");
      return 0;
    }
  if (!goal) goal = 1;
  if (hs[sx] >= goal) {
    printf("-1");
    return 0;
  }
  cout << goal - hs[sx];
}
