#include <bits/stdc++.h>
using namespace std;
const int inf = 0x3f3f3f3f;
int n, rtx, rty, i, j, dx, dy, pl[1005][1005], pr[1005][1005], px[1005][1005],
    mi[16000005], tag[16000005], x, a[1005][1005];
vector<int> allx, ally;
vector<pair<int, int> > v[1000005];
long long ans;
void upd(int x, int c) {
  mi[x] = max(mi[x], c);
  tag[x] = max(tag[x], c);
}
void pushdo(int x) {
  if (tag[x]) {
    upd(x + x, tag[x]);
    upd(x + x + 1, tag[x]);
    tag[x] = 0;
  }
}
void update(int x, int l, int r, int ql, int qr, int c) {
  if (ql <= l && r <= qr) {
    upd(x, c);
    return;
  }
  pushdo(x);
  int mid = (l + r) / 2;
  if (ql <= mid) update(x + x, l, mid, ql, qr, c);
  if (qr > mid) update(x + x + 1, mid + 1, r, ql, qr, c);
  mi[x] = min(mi[x + x], mi[x + x + 1]);
}
int query(int x, int l, int r, int ql, int qr) {
  if (ql <= l && r <= qr) {
    return mi[x];
  }
  pushdo(x);
  int mid = (l + r) / 2, ans = inf;
  if (ql <= mid) ans = min(ans, query(x + x, l, mid, ql, qr));
  if (qr > mid) ans = min(ans, query(x + x + 1, mid + 1, r, ql, qr));
  return ans;
}
int main() {
  scanf("%d%d%d", &n, &rtx, &rty);
  swap(rtx, rty);
  rtx *= -1;
  for ((i) = 1; (i) <= (n); (i)++)
    for ((j) = 1; (j) <= (n); (j)++) {
      scanf("%d", &a[i][j]);
      if (a[i][j]) {
        pl[i][j] = inf;
        pr[i][j] = -inf;
        px[i][j] = inf;
        for ((dx) = 0; (dx) < (2); (dx)++)
          for ((dy) = 0; (dy) < (2); (dy)++) {
            int tx = rty * (i + dx) - rtx * (j + dy),
                ty = rtx * (i + dx) + rty * (j + dy);
            px[i][j] = min(px[i][j], tx);
            pl[i][j] = min(pl[i][j], ty);
            pr[i][j] = max(pr[i][j], ty);
          }
        allx.push_back(px[i][j]);
        ally.push_back(pl[i][j]);
        ally.push_back(pr[i][j]);
      }
    }
  sort(allx.begin(), allx.end());
  allx.resize(unique(allx.begin(), allx.end()) - allx.begin());
  sort(ally.begin(), ally.end());
  ally.resize(unique(ally.begin(), ally.end()) - ally.begin());
  for ((i) = 1; (i) <= (n); (i)++)
    for ((j) = 1; (j) <= (n); (j)++)
      if (a[i][j]) {
        px[i][j] =
            upper_bound(allx.begin(), allx.end(), px[i][j]) - allx.begin();
        pl[i][j] =
            upper_bound(ally.begin(), ally.end(), pl[i][j]) - ally.begin();
        pr[i][j] =
            upper_bound(ally.begin(), ally.end(), pr[i][j] - 1) - ally.begin();
        v[px[i][j]].push_back(make_pair(i, j));
      }
  for ((i) = 1; (i) <= (allx.size()); (i)++) {
    for (__typeof((v[i]).begin()) it = (v[i]).begin(); it != (v[i]).end();
         it++) {
      int t = query(1, 1, ally.size(), pl[it->first][it->second],
                    pr[it->first][it->second]);
      ans += max(0, a[it->first][it->second] - t);
      update(1, 1, ally.size(), pl[it->first][it->second],
             pr[it->first][it->second], a[it->first][it->second]);
    }
  }
  cout << ans << endl;
  return 0;
}
