#include <bits/stdc++.h>
using namespace std;
const int mo = 998244353;
int n, m, a, b, h[3000 + 5][3000 + 5];
long long g[3000 * 3000 + 5], x, y, z, ans;
int minn[3000 + 5][3000 + 5];
deque<int> q;
int main() {
  scanf("%d %d %d %d", &n, &m, &a, &b);
  scanf("%lld %lld %lld %lld", &g[0], &x, &y, &z);
  for (int i = 1; i <= 3000 * 3000; 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++) {
    while (!q.empty()) q.pop_back();
    for (int j = 1; j <= m; j++) {
      while (!q.empty() && q.front() <= j - b) q.pop_front();
      while (!q.empty() && h[i][q.back()] >= h[i][j]) q.pop_back();
      q.push_back(j);
      minn[i][j] = h[i][q.front()];
    }
  }
  while (!q.empty()) q.pop_back();
  for (int j = 1; j <= m; j++) {
    while (!q.empty()) q.pop_back();
    for (int i = 1; i <= n; i++) {
      while (!q.empty() && q.front() <= i - a) q.pop_front();
      while (!q.empty() && minn[q.back()][j] >= minn[i][j]) q.pop_back();
      q.push_back(i);
      if (i >= a && j >= b) ans += minn[q.front()][j];
    }
  }
  printf("%lld\n", ans);
  return 0;
}
