#include <bits/stdc++.h>
using namespace std;
int n, m, a, b;
int g, x, y, z;
int G[3010][3010];
int maxm[3010][3010];
int maxn[3010][3010];
struct position {
  int val, pos;
} q[3010];
long long ans;
int main() {
  scanf("%d%d%d%d", &n, &m, &a, &b);
  scanf("%d%d%d%d", &g, &x, &y, &z);
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      int now = (i - 1) * m + j - 1;
      if (now == 0)
        G[i][j] = g;
      else {
        g = (1LL * g * x + y) % z;
        G[i][j] = g;
      }
    }
  }
  for (int i = 1; i <= n; i++) {
    int l = 1, r = 0;
    for (int j = 1; j <= m; j++) {
      while (l <= r && q[l].pos + b <= j) ++l;
      while (l <= r && q[r].val >= G[i][j]) --r;
      q[++r].val = G[i][j], q[r].pos = j;
      maxm[i][j] = q[l].val;
    }
  }
  for (int j = 1; j <= m; j++) {
    int l = 1, r = 0;
    for (int i = 1; i <= n; i++) {
      while (l <= r && q[l].pos + a <= i) ++l;
      while (l <= r && q[r].val >= maxm[i][j]) --r;
      q[++r].val = maxm[i][j], q[r].pos = i;
      maxn[i][j] = q[l].val;
    }
  }
  for (int i = a; i <= n; i++) {
    for (int j = b; j <= m; j++) {
      ans += maxn[i][j];
    }
  }
  printf("%lld\n", ans);
}
