#include <bits/stdc++.h>
using namespace std;
int minn[8000000 + 5], sx, sy, n, h[5000 + 5][5000 + 5], num[8000000 + 5],
    k[5000 + 5][5000 + 5], cnt = 0;
long long ans = 0;
int update(int ll, int rr, int x, int l, int r, int p) {
  if (minn[p] > x) return minn[p];
  if (ll <= l && r <= rr) {
    int tmp = minn[p];
    minn[p] = max(minn[p], x);
    return tmp;
  }
  minn[((p) << 1)] = max(minn[((p) << 1)], minn[p]);
  minn[((p) << 1 | 1)] = max(minn[((p) << 1 | 1)], minn[p]);
  int mid = l + r >> 1, mi = 1e9;
  if (ll < mid) mi = min(mi, update(ll, rr, x, l, mid, ((p) << 1)));
  if (rr > mid) mi = min(mi, update(ll, rr, x, mid, r, ((p) << 1 | 1)));
  minn[p] = min(minn[((p) << 1)], minn[((p) << 1 | 1)]);
  return mi;
}
int main() {
  scanf("%d%d%d", &n, &sx, &sy);
  if (sy == 0) {
    swap(sx, sy);
    if (sy <= 0) {
      for (int j = n; j; j--)
        for (int i = 1; i <= n; i++) scanf("%d", h[i] + j);
      sy = -sy;
    } else
      for (int j = 1; j <= n; j++)
        for (int i = 1; i <= n; i++) scanf("%d", h[i] + j);
  } else if (sx >= 0 && sy >= 0) {
    for (int i = 1; i <= n; i++)
      for (int j = 1; j <= n; j++) scanf("%d", h[i] + j);
  } else if (sx < 0 && sy >= 0) {
    for (int i = n; i; i--)
      for (int j = 1; j <= n; j++) scanf("%d", h[i] + j);
    sx = -sx;
  } else if (sx < 0 && sy < 0) {
    for (int i = n; i; i--)
      for (int j = n; j; j--) scanf("%d", h[i] + j);
    sx = -sx, sy = -sy;
  } else if (sx >= 0 && sy < 0) {
    for (int i = 1; i <= n; i++)
      for (int j = n; j; j--) scanf("%d", h[i] + j);
    sy = -sy;
  }
  for (int i = 0; i <= n; i++)
    for (int j = 0; j <= n; j++)
      k[i][j] = j * sx - i * sy, num[++cnt] = k[i][j];
  sort(num + 1, num + 1 + cnt);
  cnt = unique(num + 1, num + 1 + cnt) - num - 1;
  for (int i = 0; i <= n; i++) {
    for (int j = 0; j <= n; j++) {
      k[i][j] = lower_bound(num + 1, num + 1 + cnt, k[i][j]) - num;
    }
  }
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= n; j++)
      ans += h[i][j] -
             min(update(k[i][j - 1], k[i - 1][j], h[i][j], 1, cnt, 1), h[i][j]);
  printf("%I64d\n", ans);
  return 0;
}
