#include <bits/stdc++.h>
using namespace std;
struct SegmentTree {
  struct Op {
    int h;
  };
  int l;
  int r;
  int h;
  SegmentTree* c[2];
  bool lazy;
  Op op;
  SegmentTree(int ll, int rr) {
    lazy = false;
    l = ll;
    r = rr;
    h = 0;
    if (l == r) return;
    int m = (l + r) / 2;
    c[0] = new SegmentTree(l, m);
    c[1] = new SegmentTree(m + 1, r);
  }
  int query(int xl, int xr) {
    if (l == r) return h;
    if (xl <= l && r <= xr) return h;
    SegmentTree& lc = *c[0];
    SegmentTree& rc = *c[1];
    if (lazy) {
      lc.update(lc.l, lc.r, op.h);
      rc.update(rc.l, rc.r, op.h);
      lazy = false;
    }
    int ret = INT_MAX;
    if (xl <= lc.r) {
      int temp = lc.query(xl, xr);
      if (ret > temp) ret = temp;
    }
    if (rc.l <= xr) {
      int temp = rc.query(xl, xr);
      if (ret > temp) ret = temp;
    }
    return ret;
  }
  void update(int xl, int xr, int xh) {
    if (l == r) {
      if (h < xh) h = xh;
      return;
    }
    if (xl <= l && r <= xr) {
      if (h < xh) h = xh;
      if (lazy) {
        if (op.h < xh) op.h = xh;
      } else {
        op.h = xh;
        lazy = true;
      }
      return;
    }
    SegmentTree& lc = *c[0];
    SegmentTree& rc = *c[1];
    if (lazy) {
      lc.update(lc.l, lc.r, op.h);
      rc.update(rc.l, rc.r, op.h);
      lazy = false;
    }
    if (xl <= lc.r) lc.update(xl, xr, xh);
    if (rc.l <= xr) rc.update(xl, xr, xh);
    h = min(lc.h, rc.h);
  }
};
struct Hall {
  int h;
  int proj_index[2];
  int proj_x[2];
};
const int HH = 1002;
int n;
int vx;
int vy;
Hall hall[HH][HH];
long long ans;
double get_x(double x, double y) {
  if (vx == 0) return x;
  return x - y / vy * vx;
}
int init_project() {
  int xx[] = {0, 1};
  int yy[] = {1, 0};
  double EPS = 1e-7;
  struct Proj {
    int i;
    int j;
    double x;
    int k;
  };
  vector<Proj> projection(n * n * 2);
  for (int i = 0; i < n; i++)
    for (int j = 0; j < n; j++)
      for (int k = 0; k < 2; k++) {
        int idx = 2 * (i * n + j) + k;
        projection[idx].i = i;
        projection[idx].j = j;
        projection[idx].x = get_x(i + xx[k], j + yy[k]);
        projection[idx].k = k;
      }
  sort(begin(projection), end(projection),
       [](const Proj& a, const Proj& b) { return a.x < b.x; });
  int n_seg = 0;
  hall[projection[0].i][projection[0].j].proj_index[projection[0].k] = 0;
  for (int i = 1; i < projection.size(); i++) {
    if (abs(projection[i].x - projection[i - 1].x) > EPS) n_seg++;
    hall[projection[i].i][projection[i].j].proj_index[projection[i].k] = n_seg;
  }
  return n_seg;
}
void rotate() {
  if (vy < 0) {
    for (int i = 0; i < n; i++) {
      int l = 0;
      int r = n - 1;
      while (l < r) {
        swap(hall[i][l].h, hall[i][r].h);
        l++;
        r--;
      }
    }
    vy = -vy;
  }
  if (vx < 0 || vy == 0) {
    for (int i = 0; i < n; i++)
      for (int j = 0; j < i; j++) swap(hall[i][j].h, hall[j][i].h);
    swap(vx, vy);
  }
  if (vy < 0) {
    for (int i = 0; i < n; i++) {
      int l = 0;
      int r = n - 1;
      while (l < r) {
        swap(hall[i][l].h, hall[i][r].h);
        l++;
        r--;
      }
    }
    vy = -vy;
  }
}
int main() {
  scanf("%d %d %d", &n, &vx, &vy);
  for (int i = 0; i < n; i++)
    for (int j = 0; j < n; j++) scanf("%d", &hall[i][j].h);
  rotate();
  int len = init_project();
  SegmentTree st(0, len - 1);
  for (int j = 0; j < n; j++) {
    for (int i = 0; i < n; i++) {
      const Hall& h = hall[i][j];
      int min_height = st.query(h.proj_index[0], h.proj_index[1] - 1);
      ans += max(0, h.h - min_height);
      st.update(h.proj_index[0], h.proj_index[1] - 1, h.h);
    }
  }
  printf("%lld\n", ans);
}
