#include <bits/stdc++.h>
using namespace std;
const int inf = 0x3f3f3f3f;
const int N = 3010, K = 20, M = 1e6;
int A[N][N], Log[N], f[20][N];
int r1[N][N];
int ask(int x, int y) {
  int k = Log[y - x + 1];
  return min(f[k][x], f[k][y - (1 << k) + 1]);
}
int main() {
  std::ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  int n, m, a, b, g0, x, y, z;
  cin >> n >> m >> a >> b >> g0 >> x >> y >> z;
  A[1][1] = g0;
  for (int i = 2; i < N; i++) Log[i] = Log[i >> 1] + 1;
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++) {
      if (i == 1 && j == 1) continue;
      g0 = A[i][j] = (1LL * g0 * x % z + y) % z;
    }
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) f[0][j] = A[i][j];
    for (int j = 1; j < K; j++)
      for (int z = 1; z + (1 << j - 1) <= m; z++)
        f[j][z] = min(f[j - 1][z], f[j - 1][z + (1 << j - 1)]);
    for (int j = b; j <= m; j++) r1[i][j] = ask(j - b + 1, j);
  }
  long long ans = 0;
  for (int i = b; i <= m; i++) {
    for (int j = 1; j <= n; j++) f[0][j] = r1[j][i];
    for (int j = 1; j < K; j++)
      for (int z = 1; z + (1 << j - 1) <= n; z++)
        f[j][z] = min(f[j - 1][z], f[j - 1][z + (1 << j - 1)]);
    for (int j = a; j <= n; j++) ans += ask(j - a + 1, j);
  }
  cout << ans << '\n';
  return 0;
}
