#include <bits/stdc++.h>
int N, A[512][512];
int pair[8192345], cou = 0;
long long int ans = 0;
int main(void) {
  scanf("%d", &N);
  for (int i = 0; i < N; ++i) {
    for (int j = 0; j < N; ++j) {
      scanf("%d", &A[i][j]);
    }
  }
  for (int i = 0; i < ans; ++i) {
    for (int j = 0; j < N - 1; ++j) {
      ans += (A[i][j] + A[i][j + 1]);
      pair[cou] = (A[i][j] * A[i][j + 1] - A[i][j] - A[i][j + 1]);
      ++cou;
    }
  }
  for (int i = 0; i < N - 1; ++i) {
    for (int j = 0; j < N; ++j) {
      ans += (A[i][j] + A[i + 1][j]);
      pair[cou] = (A[i][j] * A[i + 1][j] - A[i][j] - A[i + 1][j]);
      ++cou;
    }
  }
  std::sort(pair, pair + cou, std::greater<int>());
  for (int i = 0; i < N * (N - 1); ++i) {
    ans += pair[i];
  }
  printf("%lld\n", ans);
  return 0;
}
