#include <bits/stdc++.h>
using namespace std;
const int inf = 0x3f3f3f3f;
const int maxn = 3000 + 3;
int n;
int m;
int a;
int b;
int x;
int y;
int z;
int g[maxn * maxn];
int h[maxn][maxn];
int s[maxn][maxn];
int ql;
int qr;
int que[maxn];
int main() {
  scanf("%d%d%d%d", &n, &m, &a, &b);
  scanf("%d%d%d%d", &g[0], &x, &y, &z);
  for (int i = 1; i < n * m; i++) g[i] = (1ll * g[i - 1] * x + 1ll * y) % z;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      h[i][j] = g[(i - 1) * m + j - 1];
    }
  }
  long long ans = 0;
  for (int i = 1; i <= n; i++) {
    ql = 1;
    qr = 0;
    for (int j = 1; j <= m; j++) {
      while ((que[ql] <= j - b) && ql <= qr) ql++;
      while (ql <= qr && (h[i][j] <= h[i][que[qr]])) qr--;
      que[++qr] = j;
      if (j >= b) s[i][j - b + 1] = h[i][que[ql]];
    }
  }
  for (int j = 1; j <= m - b + 1; j++) {
    ql = 1;
    qr = 0;
    for (int i = 1; i <= n; i++) {
      while ((que[ql] <= i - a) && ql <= qr) ql++;
      while (ql <= qr && (s[i][j] <= s[que[qr]][j])) qr--;
      que[++qr] = i;
      if (i >= a) ans += 1ll * s[que[ql]][j];
    }
  }
  printf("%I64d\n", ans);
  return 0;
}
