#include <bits/stdc++.h>
using namespace std;
const long long MOD = 777777777;
const int INF = 2e9 + 1;
const long long INF64 = 1e18;
const double EPS = 1e-9;
const double PI = acos(-1);
const long long MD = 1551513443;
const long long T = 25923;
const int N = 2000110;
const int M = 1010;
int n;
int vx, vy, a[M][M], l[M][M], r[M][M], h[M][M], t[N * 4];
vector<int> p;
vector<pair<int, pair<int, int> > > b;
long long ans;
inline void push(int v, int tl, int tr) {
  if (tl != tr) {
    t[v * 2] = max(t[v * 2], t[v]);
    t[v * 2 + 1] = max(t[v * 2 + 1], t[v]);
  }
}
void update(int v, int tl, int tr, int l, int r, int val) {
  push(v, tl, tr);
  if (l > r) return;
  if (tl == l && tr == r)
    t[v] = max(t[v], val);
  else {
    int sdfjahlfasfh = (tl + tr) / 2;
    update(v * 2, tl, sdfjahlfasfh, l, min(r, sdfjahlfasfh), val);
    update(v * 2 + 1, sdfjahlfasfh + 1, tr, max(l, sdfjahlfasfh + 1), r, val);
    t[v] = min(t[v * 2], t[v * 2 + 1]);
  }
}
int get(int v, int tl, int tr, int l, int r) {
  push(v, tl, tr);
  if (l > r) return INF;
  if (tl == l && tr == r) return t[v];
  int sdfjahlfasfh = (tl + tr) / 2;
  return min(get(v * 2, tl, sdfjahlfasfh, l, min(r, sdfjahlfasfh)),
             get(v * 2 + 1, sdfjahlfasfh + 1, tr, max(l, sdfjahlfasfh + 1), r));
}
int main() {
  cin >> n >> vx >> vy;
  for (int first = 0; first < int(n); first++)
    for (int second = 0; second < int(n); second++) {
      scanf("%d", &a[first][second]);
      l[first][second] = INF;
      r[first][second] = -INF;
      h[first][second] = INF;
      for (int dx = 0; dx < int(2); dx++)
        for (int dy = 0; dy < int(2); dy++) {
          l[first][second] =
              min(l[first][second], (first + dx) * vy - (second + dy) * vx);
          r[first][second] =
              max(r[first][second], (first + dx) * vy - (second + dy) * vx);
          h[first][second] =
              min(h[first][second], (first + dx) * vx + (second + dy) * vy);
        }
      p.push_back(l[first][second]);
      p.push_back(r[first][second]);
      b.push_back(make_pair(h[first][second], make_pair(first, second)));
    }
  sort((p).begin(), (p).end());
  int z = int((p).size());
  p.erase(unique((p).begin(), (p).end()), p.end());
  sort((b).begin(), (b).end());
  int lf, rf, h;
  for (int i = 0; i < int(int((b).size())); i++) {
    int first = b[i].second.first, second = b[i].second.second;
    lf = int(lower_bound((p).begin(), (p).end(), l[first][second]) - p.begin());
    rf =
        int(lower_bound((p).begin(), (p).end(), r[first][second]) - p.begin()) -
        1;
    h = get(1, 0, z, lf, rf);
    if (h < a[first][second]) ans += a[first][second] - h;
    update(1, 0, z, lf, rf, a[first][second]);
  }
  cout << ans;
  return 0;
}
