#include <bits/stdc++.h>
using namespace std;
inline void smin(int &a, const int &b) {
  if (b < a) a = b;
}
inline void smax(int &a, const int &b) {
  if (b > a) a = b;
}
inline long long scalar(int ax, int ay, int bx, int by) {
  return (long long)ax * bx + (long long)ay * by;
}
struct data {
  int mn, mx, val, dst;
  inline data(int mn = 0, int mx = 0, int val = 0, int dst = 0)
      : mn(mn), mx(mx), val(val), dst(dst) {}
};
data p[1010101];
int dst[1010][1010], l, r, x, nn;
long long mul[1010][1010], arr[1010101];
int mn[4040404], flag[4040404];
inline void update(int u, int x) { smax(mn[u], x), smax(flag[u], x); }
inline void push_down(int u, int L, int R) {
  if (flag[u]) {
    update((u << 1), flag[u]), update(((u << 1) | 1), flag[u]);
    flag[u] = 0;
  }
}
void update(int u, int L, int R) {
  if (r <= L || R <= l) return;
  if (l <= L && R <= r)
    update(u, x);
  else {
    push_down(u, L, R);
    update((u << 1), L, (L + R >> 1)), update(((u << 1) | 1), (L + R >> 1), R);
    mn[u] = min(mn[(u << 1)], mn[((u << 1) | 1)]);
  }
}
inline int calc_min(int u, int L, int R) {
  if (r <= L || R <= l) return 0x3f3f3f3f;
  if (l <= L && R <= r) return mn[u];
  push_down(u, L, R);
  return min(calc_min((u << 1), L, (L + R >> 1)),
             calc_min(((u << 1) | 1), (L + R >> 1), R));
}
int main() {
  int n, vx, vy;
  scanf("%d %d %d", &n, &vx, &vy);
  for (int i = 0; i <= n; i++) {
    for (int j = 0; j <= n; j++) {
      mul[i][j] = arr[nn++] = scalar(i, j, vx, vy);
    }
  }
  sort(arr, arr + nn), nn = unique(arr, arr + nn) - arr;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n; j++) {
      for (int I = 2; I--;) {
        for (int J = 2; J--;) {
          smax(dst[i][j], upper_bound(arr, arr + nn, mul[i - I][j - J]) - arr);
        }
      }
    }
  }
  swap(vx, vy), vx = -vx, nn = 0;
  for (int i = 0; i <= n; i++) {
    for (int j = 0; j <= n; j++) {
      mul[i][j] = arr[nn++] = scalar(i, j, vx, vy);
    }
  }
  sort(arr, arr + nn), nn = unique(arr, arr + nn) - arr;
  int N = 0;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n; j++) {
      int mn = nn, mx = 1;
      for (int I = 2; I--;) {
        for (int J = 2; J--;) {
          x = upper_bound(arr, arr + nn, mul[i - I][j - J]) - arr;
          smin(mn, x), smax(mx, x);
        }
      }
      scanf("%d", &x);
      p[N++] = data(mn, mx, x, dst[i][j]);
    }
  }
  sort(p, p + N, [](data a, data b) { return a.dst > b.dst; });
  long long ans = 0;
  for (int i = N; i--;) {
    l = p[i].mn, r = p[i].mx, x = p[i].val;
    int mn = calc_min(1, 1, nn);
    if (x > mn) ans += x - mn, update(1, 1, nn);
  }
  printf("%I64d", ans);
}
