#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1005;
int N, a[MAXN][MAXN], vx, vy, l[MAXN][MAXN], r[MAXN][MAXN],
    arr[MAXN * MAXN * 2];
int arrlen;
void swapx() {
  for (int i = 1; i <= N - i + 1; ++i)
    for (int j = 1; j <= N; ++j) swap(a[i][j], a[N - i + 1][j]);
}
void swapy() {
  for (int i = 1; i <= N; ++i)
    for (int j = 1; j <= N - j + 1; ++j) swap(a[i][j], a[i][N - j + 1]);
}
void swapxy() {
  for (int i = 1; i <= N; ++i)
    for (int j = 1; j <= i; ++j) swap(a[i][j], a[j][i]);
}
int k(int x, int y) { return vx * y - vy * x; }
int tr[MAXN * MAXN * 2 * 4], tag[MAXN * MAXN * 2 * 4];
void pushup(int o) { tr[o] = min(tr[(o << 1)], tr[(o << 1 | 1)]); }
void cov(int o, int k) { tr[o] = max(tr[o], k), tag[o] = max(tag[o], k); }
void pushdown(int o) {
  if (tag[o]) cov((o << 1), tag[o]), cov((o << 1 | 1), tag[o]), tag[o] = 0;
}
void ins(int o, int l, int r, int L, int R, int K) {
  if (l == L && r == R)
    cov(o, K);
  else {
    pushdown(o);
    if (R <= ((l + r) >> 1))
      ins((o << 1), l, ((l + r) >> 1), L, R, K);
    else if (L > ((l + r) >> 1))
      ins((o << 1 | 1), ((l + r) >> 1) + 1, r, L, R, K);
    else
      ins((o << 1), l, ((l + r) >> 1), L, ((l + r) >> 1), K),
          ins((o << 1 | 1), ((l + r) >> 1) + 1, r, ((l + r) >> 1) + 1, R, K);
    pushup(o);
  }
}
int qry(int o, int l, int r, int L, int R) {
  if (l == L && r == R)
    return tr[o];
  else {
    pushdown(o);
    if (R <= ((l + r) >> 1))
      return qry((o << 1), l, ((l + r) >> 1), L, R);
    else if (L > ((l + r) >> 1))
      return qry((o << 1 | 1), ((l + r) >> 1) + 1, r, L, R);
    else
      return min(
          qry((o << 1), l, ((l + r) >> 1), L, ((l + r) >> 1)),
          qry((o << 1 | 1), ((l + r) >> 1) + 1, r, ((l + r) >> 1) + 1, R));
  }
}
long long ans;
int main() {
  scanf("%d%d%d", &N, &vx, &vy), vx = -vx, vy = -vy;
  for (int i = 1; i <= N; ++i)
    for (int j = 1; j <= N; ++j) scanf("%d", &a[i][j]);
  if (vx < 0) swapx(), vx = -vx;
  if (vy < 0) swapy(), vy = -vy;
  if (vx < vy) swapxy(), swap(vx, vy);
  if (vy) {
    for (int i = 1; i <= N; ++i)
      for (int j = 1; j <= N; ++j) {
        arr[++arrlen] = k(i, j - 1), arr[++arrlen] = k(i - 1, j);
      }
    sort(arr + 1, arr + arrlen + 1);
    arrlen = unique(arr + 1, arr + arrlen + 1) - (arr + 1);
    for (int i = 1; i <= N; ++i)
      for (int j = 1; j <= N; ++j) {
        l[i][j] = lower_bound(arr + 1, arr + arrlen + 1, k(i, j - 1)) - arr;
        r[i][j] = lower_bound(arr + 1, arr + arrlen + 1, k(i - 1, j)) - arr;
      }
    for (int t = 2 * N; t >= 2; --t) {
      for (int i = max(t - N, 1); i <= min(N, t - 1); ++i) {
        int j = t - i;
        ans += max(0, a[i][j] - qry(1, 1, arrlen - 1, l[i][j], r[i][j] - 1));
        ins(1, 1, arrlen - 1, l[i][j], r[i][j] - 1, a[i][j]);
      }
    }
    printf("%lld", ans);
  } else {
    for (int i = 1; i <= N; ++i) {
      int mx = 0;
      for (int j = N; j >= 1; --j) {
        ans += max(0, a[j][i] - mx);
        mx = max(mx, a[j][i]);
      }
    }
    printf("%lld", ans);
  }
  return 0;
}
