#include <bits/stdc++.h>
using namespace std;
long long n, m, A, B;
signed a[3005][3005], c[3005][3005];
long long g;
long long ans;
inline long long read() {
  register long long x = 0, ch = getchar();
  while (!isdigit(ch)) ch = getchar();
  while (isdigit(ch)) x = x * 10 + ch - '0', ch = getchar();
  return x;
}
struct dl {
  deque<long long> q, b;
  void ru(long long x, long long y) {
    while (!q.empty() && x < q.back()) {
      q.pop_back();
      b.pop_back();
    }
    q.push_back(x);
    b.push_back(y);
  }
  void chu(long long x) {
    while (!q.empty() && x >= b.front()) {
      b.pop_front();
      q.pop_front();
    }
  }
  void qing() {
    while (!q.empty()) {
      q.pop_front();
      b.pop_front();
    }
  }
} q;
void print(long long x) {
  if (x < 0) {
    putchar('-');
    x = -x;
  }
  if (x > 9) print(x / 10);
  putchar(x % 10 + '0');
}
void rd() {
  cin >> n >> m >> A >> B;
  long long x, y, z, g;
  cin >> g >> x >> y >> z;
  for (long long i = 1; i <= n; i++)
    for (long long j = 1; j <= m; j++) {
      a[i][j] = g;
      g = (g * x + y) % z;
    }
}
signed main() {
  rd();
  for (long long i = 1; i <= n; i++) {
    q.qing();
    for (long long j = 1; j <= m; j++) {
      q.ru(a[i][j], j);
      q.chu(j - B);
      if (j >= B) {
        c[i][j] = q.q.front();
      }
    }
  }
  for (long long j = B; j <= m; j++) {
    q.qing();
    for (long long i = 1; i <= n; i++) {
      q.ru(c[i][j], i);
      q.chu(i - A);
      if (i >= A) {
        ans += q.q.front();
      }
    }
  }
  cout << ans;
  return 0;
}
