#include <bits/stdc++.h>
using namespace std;
template <typename T, typename U>
inline void smin(T &a, const U &b) {
  if (a > b) a = b;
}
template <typename T, typename U>
inline void smax(T &a, const U &b) {
  if (a < b) a = b;
}
struct point {
  int first, second;
  point(int first = 0, int second = 0) : first(first), second(second) {}
  inline long long operator*(point a) {
    return (long long)first * a.first + (long long)second * a.second;
  }
  inline long long operator^(point a) {
    return (long long)first * a.second - (long long)second * a.first;
  }
  inline point operator*(int a) { return point(first * a, second * a); }
  inline point operator/(int a) { return point(first / a, second / a); }
  inline point operator+(point a) {
    return point(first + a.first, second + a.second);
  }
  inline point operator-(point a) {
    return point(first - a.first, second - a.second);
  }
  inline point conj() { return point(-second, first); }
  inline long long nor2() { return *this * *this; }
  inline double al() { return atan2(second, first); }
  inline double nor() { return sqrt(*this * *this); }
  inline bool pos() { return second > 0 || second == 0 && first >= 0; }
  inline bool operator<(const point &a) const {
    return first != a.first ? first < a.first : second < a.second;
  }
  inline bool operator>(const point &a) const {
    return first != a.first ? first > a.first : second > a.second;
  }
  inline bool operator==(const point &a) const {
    return first == a.first && second == a.second;
  }
  inline bool operator!=(const point &a) const {
    return first != a.first || second != a.second;
  }
  inline void input() { scanf("%d %d", &first, &second); }
  inline void print() { printf("%d %d\n", first, second); }
};
int a[1010][1010];
point x_dir, y_dir;
struct monamu {
  int xmn, xmx, ymn, ymx, h;
  monamu(int xmn = 0, int xmx = 0, int ymn = 0, int ymx = 0, int h = 0)
      : xmn(xmn), xmx(xmx), ymn(ymn), ymx(ymx), h(h) {}
};
vector<monamu> vec;
int xmn, xmx, ymn, ymx;
inline void Update(int first, int second) {
  int X = point(first, second) * x_dir;
  int Y = point(first, second) * y_dir;
  smin(xmn, X), smax(xmx, X);
  smin(ymn, Y), smax(ymx, Y);
}
inline void insert_monamu(int i, int j, int h) {
  xmn = 0x3f3f3f3f, xmx = -0x3f3f3f3f, ymn = 0x3f3f3f3f, ymx = -0x3f3f3f3f;
  for (int I = 2; I--;)
    for (int J = 2; J--;) Update(i - I, j - J);
  vec.push_back(monamu(xmn, xmx, ymn, ymx, h));
}
double arr[9200100];
int LL[9200100], RR[9200100], flag[9200100];
inline void build(int u, int L, int R) {
  LL[u] = L, RR[u] = R;
  if (L + 1 == R) return;
  int ls = u << 1, rs = ls | 1, mid = L + R >> 1;
  build(ls, L, mid);
  build(rs, mid, R);
}
int mn[9200100], l, r, X;
inline void replace(int u, int first) {
  smax(mn[u], first);
  smax(flag[u], first);
}
inline void push_down(int u, int ls, int rs) {
  if (flag[u]) {
    replace(ls, flag[u]);
    replace(rs, flag[u]);
    flag[u] = 0;
  }
}
inline void update(int u) {
  int L = LL[u], R = RR[u];
  if (r <= L || R <= l) return;
  if (l <= L && R <= r) {
    replace(u, X);
    return;
  }
  int ls = u << 1, rs = ls | 1;
  push_down(u, ls, rs);
  update(ls), update(rs);
  mn[u] = min(mn[ls], mn[rs]);
}
inline int calc(int u) {
  int L = LL[u], R = RR[u];
  if (r <= L || R <= l) return 0x3f3f3f3f;
  if (l <= L && R <= r) return mn[u];
  int ls = u << 1, rs = ls | 1;
  push_down(u, ls, rs);
  return min(calc(ls), calc(rs));
}
int main() {
  int n;
  scanf("%d", &n);
  x_dir.input();
  y_dir = x_dir.conj();
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n; j++) {
      scanf("%d", a[i] + j);
      insert_monamu(i, j, a[i][j]);
    }
  }
  sort(vec.begin(), vec.end(),
       [](monamu a, monamu b) { return a.xmn < b.xmn; });
  int nn = 0;
  for (monamu p : vec) {
    double xmn = p.xmn, xmx = p.xmx;
    double ymn = p.ymn, ymx = p.ymx;
    arr[nn++] = ymn + 1e-4;
    arr[nn++] = ymx - 1e-4;
  }
  sort(arr, arr + nn);
  nn = unique(arr, arr + nn) - arr;
  build(1, 0, nn + 1);
  long long ans = 0;
  for (monamu p : vec) {
    double xmn = p.xmn, xmx = p.xmx;
    double ymn = p.ymn, ymx = p.ymx;
    int h = p.h;
    l = upper_bound(arr, arr + nn, ymn) - arr;
    r = lower_bound(arr, arr + nn, ymx) - arr;
    int mn_h = calc(1);
    if (mn_h < h) ans += h - mn_h;
    X = h, update(1);
  }
  cout << ans << endl;
}
