#include <bits/stdc++.h>
using namespace std;
const int maxn = 3e3 + 5;
int n, m, a, b;
int g0, x, y, z;
long long c[maxn][maxn];
long long d[maxn][maxn];
long long ans;
int q[maxn];
int head, tail;
int main() {
  scanf("%d%d%d%d", &n, &m, &a, &b);
  scanf("%d%d%d%d", &g0, &x, &y, &z);
  c[1][1] = g0;
  for (int i = 1; i <= n; i++) {
    if (i != 1) c[i][1] = ((long long)(c[i - 1][m] * x) + y) % z;
    for (int j = 2; j <= m; j++)
      c[i][j] = ((long long)(c[i][j - 1] * x) + y) % z;
  }
  for (int i = 1; i <= n; i++) {
    memset(q, 0, sizeof(q));
    head = tail = 1;
    c[i][0] = 0x3f3f3f3f;
    for (int j = 1; j <= m; j++) {
      if (j > b)
        while (head <= tail && q[head] <= j - b) head++;
      while (head <= tail && c[i][q[tail]] >= c[i][j]) tail--;
      q[++tail] = j;
      d[i][j] = c[i][q[head]];
    }
  }
  for (int j = b; j <= m; j++) {
    memset(q, 0, sizeof(q));
    head = tail = 1;
    d[0][j] = 0x3f3f3f3f;
    for (int i = 1; i <= n; i++) {
      if (i > a)
        while (head <= tail && q[head] <= i - a) head++;
      while (head <= tail && d[q[tail]][j] >= d[i][j]) tail--;
      q[++tail] = i;
      if (i >= a) ans += d[q[head]][j];
    }
  }
  printf("%lld\n", ans);
  return 0;
}
