#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
const long long INFLL = 0x3f3f3f3f3f3f3f3f;
const int MAXINT = 2147483647;
const int MAXN = 3005;
struct Node {
  long long p, v;
} q[MAXN * 2];
long long n, m, a, b, x, y, z, g[MAXN * MAXN], h[MAXN][MAXN], t, w,
    mini[MAXN][MAXN];
long long ans;
int main() {
  int i, j;
  scanf("%lld%lld%lld%lld%lld%lld%lld%lld", &n, &m, &a, &b, &g[0], &x, &y, &z);
  for (i = 1; i <= n * m; i++) {
    g[i] = (g[i - 1] * x + y) % z;
  }
  for (i = 1; i <= n; i++) {
    for (j = 1; j <= m; j++) {
      h[i][j] = g[(i - 1) * m + j - 1];
    }
  }
  for (i = 1; i <= n; i++) {
    t = 1;
    w = 1;
    q[1].p = 1;
    q[1].v = h[i][1];
    if (1 >= b) mini[i][1] = q[t].v;
    for (j = 2; j <= m; j++) {
      while (t <= w && q[t].p <= j - b) t++;
      while (t <= w && h[i][j] <= q[w].v) w--;
      q[++w].v = h[i][j];
      q[w].p = j;
      if (j >= b) mini[i][j] = q[t].v;
    }
  }
  for (j = b; j <= m; j++) {
    t = 1;
    w = 1;
    q[1].p = 1;
    q[1].v = mini[1][j];
    if (1 >= a) ans += 1ll * q[t].v;
    for (i = 2; i <= n; i++) {
      while (t <= w && q[t].p <= i - a) t++;
      while (t <= w && mini[i][j] <= q[w].v) w--;
      q[++w].v = mini[i][j];
      q[w].p = i;
      if (i >= a) ans += 1ll * q[t].v;
    }
  }
  printf("%lld", ans);
  return 0;
}
