#include <bits/stdc++.h>
using namespace std;
template <typename T>
inline void Read(T &x) {
  int f = 1;
  char t = getchar();
  while (t < '0' || t > '9') {
    if (t == '-') f = -1;
    t = getchar();
  }
  x = 0;
  while (t >= '0' && t <= '9') {
    x = x * 10 + t - '0';
    t = getchar();
  }
  x *= f;
}
template <typename T>
inline void Write(T x) {
  static int output[20];
  int top = 0;
  if (x < 0) putchar('-'), x = -x;
  do {
    output[++top] = x % 10;
    x /= 10;
  } while (x > 0);
  while (top > 0) putchar('0' + output[top--]);
  putchar('\n');
}
template <typename T>
inline void chkmin(T &x, T y) {
  if (x > y) x = y;
}
template <typename T>
inline void chkmax(T &x, T y) {
  if (x < y) x = y;
}
const int maxn = 1005;
const int maxs = 1000005;
const int inf = 0x3f3f3f3f;
const double eps = 1e-7;
int n;
int a[maxn][maxn];
double Vx;
double Vy;
int len;
pair<int, pair<int, int> > tmp[maxs];
double pos[maxs << 1];
int pn;
int lpp[maxn][maxn];
int rpp[maxn][maxn];
namespace SEG {
int mn[maxs << 3];
int tag[maxs << 3];
void init() {
  memset(mn, 0, sizeof(mn));
  memset(tag, -1, sizeof(tag));
}
void pushdown(int cn) {
  if (tag[cn] != -1) {
    chkmax(mn[cn << 1], tag[cn]);
    chkmax(mn[cn << 1 | 1], tag[cn]);
    chkmax(tag[cn << 1], tag[cn]);
    chkmax(tag[cn << 1 | 1], tag[cn]);
    tag[cn] = -1;
  }
}
void update(int cn) { mn[cn] = min(mn[cn << 1], mn[cn << 1 | 1]); }
void modify(int cn, int l, int r, int l0, int r0, int v) {
  if (l == l0 && r == r0) {
    chkmax(tag[cn], v);
    chkmax(mn[cn], v);
    return;
  }
  int mid = (l + r) >> 1;
  pushdown(cn);
  if (r0 <= mid)
    modify(cn << 1, l, mid, l0, r0, v);
  else if (l0 > mid)
    modify(cn << 1 | 1, mid + 1, r, l0, r0, v);
  else
    modify(cn << 1, l, mid, l0, mid, v),
        modify(cn << 1 | 1, mid + 1, r, mid + 1, r0, v);
  update(cn);
}
int query(int cn, int l, int r, int l0, int r0) {
  if (l == l0 && r == r0) return mn[cn];
  int mid = (l + r) >> 1;
  int ret;
  pushdown(cn);
  if (r0 <= mid)
    ret = query(cn << 1, l, mid, l0, r0);
  else if (l0 > mid)
    ret = query(cn << 1 | 1, mid + 1, r, l0, r0);
  else
    ret = min(query(cn << 1, l, mid, l0, mid),
              query(cn << 1 | 1, mid + 1, r, mid + 1, r0));
  return ret;
}
};  // namespace SEG
void input() {
  Read(n);
  Read(Vx);
  Read(Vy);
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n; j++) {
      Read(a[i][j]);
    }
  }
}
void standardize() {
  if (Vy == 0) {
    static int g[maxn][maxn];
    for (int i = 1; i <= n; i++) {
      for (int j = 1; j <= n; j++) {
        g[j][n - i + 1] = a[i][j];
      }
    }
    memcpy(a, g, sizeof(a));
    swap(Vx, Vy);
  }
  if (Vx > 0) {
    for (int l = 1, r = n; l < r; l++, r--) {
      for (int i = 1; i <= n; i++) {
        swap(a[l][i], a[r][i]);
      }
    }
    Vx = -Vx;
  }
  if (Vy < 0) {
    for (int i = 1; i <= n; i++) {
      reverse(a[i] + 1, a[i] + n + 1);
    }
    Vy = -Vy;
  }
  Vx /= Vy;
  Vy = 1.0;
}
int find(double x) {
  int l = 1;
  int r = pn;
  int mid;
  int ret = -1;
  while (l <= r) {
    mid = (l + r) >> 1;
    if (fabs(x - pos[mid]) < eps) {
      ret = mid;
      break;
    } else if (x < pos[mid]) {
      r = mid - 1;
    } else {
      l = mid + 1;
    }
  }
  return ret;
}
void prepare() {
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n; j++) {
      if (a[i][j] > 0) {
        tmp[++len] = make_pair(a[i][j], make_pair(i, j));
      }
    }
  }
  sort(tmp + 1, tmp + len + 1);
  for (int i = 0; i <= n; i++) {
    for (int j = 0; j <= n; j++) {
      pos[++pn] = i - Vx * j;
    }
  }
  sort(pos + 1, pos + pn + 1);
  int nn = 0;
  for (int i = 1, last = 1; i <= pn; i++) {
    if (fabs(pos[i] - pos[last]) > eps) {
      pos[++nn] = pos[last];
      last = i;
    }
    if (i == pn) {
      pos[++nn] = pos[last];
    }
  }
  pn = nn;
  double lp;
  double rp;
  for (int x = 1; x <= n; x++) {
    for (int y = 1; y <= n; y++) {
      lp = 1.0 * (x - 1) - Vx * (y - 1);
      rp = 1.0 * x - Vx * y;
      lpp[x][y] = find(lp);
      rpp[x][y] = find(rp) - 1;
    }
  }
  SEG::init();
}
void solve() {
  long long ans = 0;
  int L, R;
  int retmin;
  for (int y = 1; y <= n; y++) {
    for (int x = n; x >= 1; x--) {
      L = lpp[x][y];
      R = rpp[x][y];
      retmin = SEG::query(1, 1, pn, L, R);
      ans += max(0, a[x][y] - retmin);
      SEG::modify(1, 1, pn, L, R, a[x][y]);
    }
  }
  cout << ans << endl;
}
int main() {
  input();
  standardize();
  prepare();
  solve();
  return 0;
}
