#include <bits/stdc++.h>
using namespace std;
int lab[4100000], Min[4100000], a[1100][1100], b[1100][1100], g[1100], n, vx,
    vy, top, m;
long long ans = 0;
double q[4100000];
int bin(double x) {
  int l = 1, r = m;
  while (l < r) {
    int mid = (l + r) / 2 + 1;
    if (x < q[mid] - 1e-9)
      r = mid - 1;
    else
      l = mid;
  }
  return l;
}
void down(int u, int l, int r) {
  if (lab[u] > Min[u]) Min[u] = lab[u];
  if (l != r) {
    lab[u * 2] = max(lab[u * 2], lab[u]);
    lab[u * 2 + 1] = max(lab[u * 2 + 1], lab[u]);
  }
  lab[u] = 0;
}
void updata(int u, int l, int r) { Min[u] = min(Min[u * 2], Min[u * 2 + 1]); }
void build(int u, int l, int r) {
  Min[u] = lab[u] = 0;
  if (l == r) return;
  int mid = (l + r) / 2;
  build(u * 2, l, mid);
  build(u * 2 + 1, mid + 1, r);
}
void add(int u, int l, int r, int x, int y, int z) {
  down(u, l, r);
  if (x > r || y < l) return;
  if (x <= l && y >= r) {
    lab[u] = z;
    down(u, l, r);
    return;
  }
  int mid = (l + r) / 2;
  add(u * 2, l, mid, x, y, z);
  add(u * 2 + 1, mid + 1, r, x, y, z);
  updata(u, l, r);
}
int query(int u, int l, int r, int x, int y) {
  down(u, l, r);
  if (x > r || y < l) return 1000000000;
  if (x <= l && y >= r) return Min[u];
  int mid = (l + r) / 2;
  return min(query(u * 2, l, mid, x, y), query(u * 2 + 1, mid + 1, r, x, y));
}
int main() {
  cin >> n >> vx >> vy;
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= n; j++) scanf("%d", &a[i][j]);
  if (vx == 0) {
    for (int i = 1; i <= n; i++)
      for (int j = 1; j <= n; j++) g[i] = max(g[i], a[i][j]);
    for (int i = 1; i <= n; i++) ans += g[i];
    cout << ans << endl;
    return 0;
  }
  if (vy == 0) {
    for (int i = 1; i <= n; i++)
      for (int j = 1; j <= n; j++) g[j] = max(g[j], a[i][j]);
    for (int i = 1; i <= n; i++) ans += g[i];
    cout << ans << endl;
    return 0;
  }
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= n; j++) {
      int tx = i, ty = j;
      if (vx < 0) tx = n - tx + 1;
      if (vy < 0) ty = n - ty + 1;
      b[i][j] = a[tx][ty];
    }
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= n; j++) a[i][j] = b[i][j];
  if (vx < 0) vx = -vx;
  if (vy < 0) vy = -vy;
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= n; j++) {
      int x = i - 1, y = j;
      q[++top] = x - (double)y / vy * vx;
      x = i, y = j - 1;
      q[++top] = x - (double)y / vy * vx;
    }
  sort(q + 1, q + top + 1);
  m = 1;
  for (int i = 2; i <= top; i++)
    if (fabs(q[i] - q[m]) > 1e-9) q[++m] = q[i];
  build(1, 1, m - 1);
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= n; j++) {
      int l = bin(i - 1 - (double)j / vy * vx),
          r = bin(i - (double)(j - 1) / vy * vx);
      r--;
      int t = query(1, 1, m - 1, l, r);
      if (t < a[i][j]) ans += a[i][j] - t;
      add(1, 1, m - 1, l, r, a[i][j]);
    }
  cout << ans << endl;
  return 0;
}
