#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;
const long long MAXN = 3111;
vector<long long> lg;
vector<vector<long long> > ST;
void res(vector<long long>& a, long long k) {
  long long n = a.size();
  for (long long i = 0; i < n; i++) ST[i][0] = a[i];
  for (long long i = 1; i <= lg[n]; i++) {
    for (long long j = 0; j + (1 << i) <= n; j++)
      ST[j][i] = min(ST[j][i - 1], ST[j + (1 << (i - 1))][i - 1]);
  }
  auto get = [&](long long i, long long j) {
    long long ij = lg[j - i + 1];
    return min(ST[i][ij], ST[j - (1 << ij) + 1][ij]);
  };
  for (long long i = 0; i <= n - k; i++) a[i] = get(i, i + k - 1);
}
signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  long long n, m, a, b, g0, x, y, z;
  cin >> n >> m >> a >> b >> g0 >> x >> y >> z;
  vector<vector<long long> > mn(m, vector<long long>(n));
  vector<vector<long long> > mat(n, vector<long long>(m));
  lg.resize(MAXN);
  for (long long i = 0; i < n; i++) {
    for (long long j = 0; j < m; j++) {
      mat[i][j] = g0;
      g0 = (g0 * x + y) % z;
    }
  }
  lg[1] = 0;
  for (long long i = 2; i < MAXN; i++) lg[i] = lg[i / 2] + 1;
  ST.resize(max(n, m), vector<long long>(lg[MAXN - 1] + 1));
  for (long long j = 0; j < m; j++) {
    vector<long long> cur(n);
    for (long long i = 0; i < n; i++) cur[i] = mat[i][j];
    res(cur, a);
    mn[j] = cur;
  }
  long long ans = 0;
  for (long long i = 0; i <= n - a; i++) {
    vector<long long> cur(m);
    for (long long j = 0; j < m; j++) cur[j] = mn[j][i];
    res(cur, b);
    for (long long j = 0; j <= m - b; j++) ans += cur[j];
  }
  cout << ans << '\n';
  return 0;
}
