#include <bits/stdc++.h>
using namespace std;
template <typename T, typename U>
inline void smin(T &a, U b) {
  if (a > b) a = b;
}
template <typename T, typename U>
inline void smax(T &a, U b) {
  if (a < b) a = b;
}
template <class T>
inline void gn(T &first) {
  char c, sg = 0;
  while (c = getchar(), (c > '9' || c < '0') && c != '-')
    ;
  for ((c == '-' ? sg = 1, c = getchar() : 0), first = 0; c >= '0' && c <= '9';
       c = getchar())
    first = (first << 1) + (first << 3) + c - '0';
  if (sg) first = -first;
}
template <class T, class T1>
inline void gn(T &first, T1 &second) {
  gn(first);
  gn(second);
}
template <class T, class T1, class T2>
inline void gn(T &first, T1 &second, T2 &z) {
  gn(first);
  gn(second);
  gn(z);
}
template <class T>
inline void print(T first) {
  if (first < 0) {
    putchar('-');
    return print(-first);
  }
  if (first < 10) {
    putchar('0' + first);
    return;
  }
  print(first / 10);
  putchar(first % 10 + '0');
}
template <class T>
inline void printsp(T first) {
  print(first);
  putchar(' ');
}
template <class T>
inline void println(T first) {
  print(first);
  putchar('\n');
}
template <class T, class U>
inline void print(T first, U second) {
  printsp(first);
  println(second);
}
template <class T, class U, class V>
inline void print(T first, U second, V z) {
  printsp(first);
  printsp(second);
  println(z);
}
int power(int a, int b, int m, int ans = 1) {
  for (; b; b >>= 1, a = 1LL * a * a % m)
    if (b & 1) ans = 1LL * ans * a % m;
  return ans;
}
int mx[1000111 << 2];
int flag[1000111 << 2];
int n, first, second;
int arr[1000111 << 1];
int nn;
struct building {
  int st, ed, pos, h;
  building(int st = 0, int ed = 0, int pos = 0, int h = 0)
      : st(st), ed(ed), pos(pos), h(h) {}
} b[1000111];
bool cmp(building u, building v) { return u.pos < v.pos; }
void push_down(int u) {
  if (flag[u] == 0) return;
  smax(mx[(u << 1)], flag[u]);
  smax(mx[((u << 1) | 1)], flag[u]);
  smax(flag[(u << 1)], flag[u]);
  smax(flag[((u << 1) | 1)], flag[u]);
  flag[u] = 0;
}
void update(int u, int st, int ed, int l, int r, int h) {
  smax(l, st);
  smin(r, ed);
  if (l >= r) return;
  if (l == st and r == ed) {
    smax(mx[u], h);
    smax(flag[u], h);
    return;
  }
  push_down(u);
  update((u << 1), st, (st + ed >> 1), l, r, h);
  update(((u << 1) | 1), (st + ed >> 1), ed, l, r, h);
  mx[u] = min(mx[(u << 1)], mx[((u << 1) | 1)]);
}
int calc(int u, int st, int ed, int l, int r) {
  smax(l, st);
  smin(r, ed);
  if (l >= r) return 0x3f3f3f3f;
  if (l == st and r == ed) {
    return mx[u];
  }
  push_down(u);
  return min(calc((u << 1), st, (st + ed >> 1), l, r),
             calc(((u << 1) | 1), (st + ed >> 1), ed, l, r));
}
int main() {
  gn(n, first, second);
  int nb = 0, na = 0;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n; j++) {
      int u;
      gn(u);
      int st = 0x3f3f3f3f, ed = -0x3f3f3f3f, pos = 0x3f3f3f3f;
      for (int ii = 0; ii >= -1; ii--) {
        for (int jj = 0; jj >= -1; jj--) {
          int k = i + ii, p = j + jj;
          smin(pos, k * first + p * second);
          smax(ed, k * second - p * first);
          smin(st, k * second - p * first);
        }
      }
      b[nb++] = building(st, ed, pos, u);
      arr[na++] = st;
      arr[na++] = ed;
    }
  }
  long long ans = 0;
  sort(arr, arr + na);
  na = unique(arr, arr + na) - arr;
  sort(b, b + nb, cmp);
  for (int i = 0; i < nb; i++) {
    int l = lower_bound(arr, arr + na, b[i].st) - arr;
    int r = lower_bound(arr, arr + na, b[i].ed) - arr;
    int tmp = calc(1, 0, na, l, r);
    if (tmp < b[i].h) {
      ans += b[i].h - tmp;
      update(1, 0, na, l, r, b[i].h);
    }
  }
  println(ans);
  return 0;
}
