#include <bits/stdc++.h>
using namespace std;
inline int read() {
  int x = 0, c = getchar(), f = 0;
  for (; c > '9' || c < '0'; f = c == '-', c = getchar())
    ;
  for (; c >= '0' && c <= '9'; x = (x << 1) + (x << 3) + c - '0', c = getchar())
    ;
  return f ? -x : x;
}
inline void write(int x) {
  if (x < 0) putchar('-'), x = -x;
  if (x >= 10) write(x / 10);
  putchar(x % 10 + 48);
}
const int N = 1000 + 10, oo = 2e9, TN = N * N;
long long ans;
int a[N][N], T[TN], cnt[TN << 2], sum[TN << 2];
int ql, qr, tmp, n, i, j, x, y, t1, t2, t3, t4;
void Update(int k, int l, int r, int v) {
  if (ql <= l && r <= qr) {
    cnt[k] = max(cnt[k], v);
    sum[k] = max(sum[k], cnt[k]);
    return;
  }
  int mid = (l + r) >> 1;
  if (ql <= mid) Update(k << 1, l, mid, v);
  if (qr > mid) Update(k << 1 | 1, mid + 1, r, v);
  sum[k] = max(cnt[k], min(sum[k << 1], sum[k << 1 | 1]));
}
int Query(int k, int l, int r) {
  if (ql <= l && r <= qr) return sum[k];
  int mid = (l + r) >> 1, res = oo;
  if (ql <= mid) res = min(res, Query(k << 1, l, mid));
  if (qr > mid) res = min(res, Query(k << 1 | 1, mid + 1, r));
  return max(res, cnt[k]);
}
int cross(int x2, int y2) { return x * y2 - x2 * y; }
int find(int x) { return lower_bound(T + 1, T + *T + 1, x) - T; }
int main() {
  scanf("%d%d%d", &n, &x, &y);
  for (int i = (int)0; i <= n - 1; i++)
    for (int j = (int)0; j <= n - 1; j++) scanf("%d", &a[i][j]);
  if (y < 0)
    for (int i = (int)0; i <= n - 1; i++)
      for (int j = (int)0; j <= n - 1; j++)
        if (j < n / 2) swap(a[i][j], a[i][n - 1 - j]);
  if (x < 0)
    for (int i = (int)0; i <= n - 1; i++)
      for (int j = (int)0; j <= n - 1; j++)
        if (i < n / 2) swap(a[i][j], a[n - 1 - i][j]);
  x = abs(x);
  y = abs(y);
  for (int i = (int)0; i <= n; i++)
    for (int j = (int)0; j <= n; j++) T[++*T] = cross(i, j);
  sort(T + 1, T + *T + 1);
  *T = unique(T + 1, T + *T + 1) - (T + 1);
  for (int i = (int)0; i <= n - 1; i++)
    for (int j = (int)0; j <= n - 1; j++) {
      ql = find(cross(i + 1, j));
      qr = find(cross(i, j + 1)) - 1;
      int tmp = Query(1, 1, *T);
      if (tmp <= a[i][j]) ans += a[i][j] - tmp;
      Update(1, 1, *T, a[i][j]);
    }
  printf("%I64d\n", ans);
}
