#include <bits/stdc++.h>
using namespace std;
int n, m, a, b, h[3005][3005], Min[3005][3005], head, tail, que[3005 << 3];
long long x, y, z, g[9000010], ans;
int main() {
  scanf("%d%d%d%d%lld%lld%lld%lld", &n, &m, &a, &b, &g[0], &x, &y, &z);
  for (int i = 1; i <= 9000005; i++) g[i] = (g[i - 1] * x + 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];
  for (int i = 1; i <= n; i++) {
    head = 1;
    tail = 0;
    for (int j = 1; j <= m; j++) {
      while (head <= tail && que[head] <= j - b) head++;
      while (head <= tail && h[i][que[tail]] >= h[i][j]) tail--;
      que[++tail] = j;
      Min[i][j] = h[i][que[head]];
    }
  }
  for (int j = 1; j <= m; j++) {
    head = 1;
    tail = 0;
    for (int i = 1; i <= n; i++) {
      while (head <= tail && que[head] <= i - a) head++;
      while (head <= tail && Min[que[tail]][j] >= Min[i][j]) tail--;
      que[++tail] = i;
      if (i >= a && j >= b) ans += Min[que[head]][j];
    }
  }
  printf("%lld", ans);
}
