#include <bits/stdc++.h>
using namespace std;
long long n, a[505][505], sumc[505], sumr[505], marki, markj, d1, d2;
int main() {
  scanf("%I64d", &n);
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= n; j++) {
      scanf("%I64d", &a[i][j]);
      if (!a[i][j]) marki = i, markj = j;
    }
  if (n == 1) {
    puts("1");
    return 0;
  }
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= n; j++) {
      sumr[i] += a[i][j], sumc[j] += a[i][j];
      if (i == j) d1 += a[i][j];
      if (i + j - 1 == n) d2 += a[i][j];
    }
  bool pd = 1;
  long long tot = 0;
  if (marki == 1)
    tot = sumr[2];
  else
    tot = sumr[1];
  long long ans = tot - sumr[marki];
  sumr[marki] += ans;
  sumc[markj] += ans;
  if (marki == markj) d1 += ans;
  if (marki + markj - 1 == n) d2 += ans;
  for (int i = 1; i <= n; i++)
    if (sumr[i] != tot || sumc[i] != tot) pd = 0;
  if (d1 != tot) pd = 0;
  if (d2 != tot) pd = 0;
  if (ans <= 0) pd = 0;
  if (!pd)
    puts("-1");
  else
    printf("%I64d\n", ans);
  return 0;
}
