#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")
using namespace std;
using ll = long long;
using ld = long double;
const ll infll = 1ll * 1 << 30 * 1 << 30;
const long double PI =
    3.141592653589793238462643383279502884197169399375105820974944;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
ll max(ll a, ll b) { return (a > b ? a : b); }
ll min(ll a, ll b) { return (a > b ? b : a); }
ll gcd(ll a, ll b) { return (b == 0) ? a : gcd(b, a % b); }
ll gcd(ll a, ll b, ll& x, ll& y) {
  if (a == 0) {
    x = 0;
    y = 1;
    return b;
  }
  ll x1, y1;
  ll d = gcd(b % a, a, x1, y1);
  x = y1 - (b / a) * x1;
  y = x1;
  return d;
}
ll modinv(ll a, ll b) {
  ll x, y;
  gcd(a, b, x, y);
  return (x % b + b) % b;
}
ll ceiling(ll a, ll b) {
  if (a % b == 0)
    return a / b;
  else
    return a / b + 1;
}
ll bpow(ll a, ll b, ll m) {
  a %= m;
  ll res = 1;
  while (b > 0) {
    if (b & 1) res = (res * a) % m;
    b >>= 1;
    a = a * a % m;
  }
  return res;
}
vector<vector<ll> > mat_mul(vector<vector<ll> > mat1, vector<vector<ll> > mat2,
                            ll mod1) {
  vector<vector<ll> > res(ll((mat1).size()),
                          vector<ll>(ll((mat2[0]).size()), 0));
  for (ll i = 0; i <= ll((mat1).size()) - 1; i++) {
    for (ll j = 0; j <= ll((mat2[0]).size()) - 1; j++) {
      for (ll k = 0; k <= ll((mat1[0]).size()) - 1; k++) {
        res[i][j] = (res[i][j] + (mat1[i][k] * mat2[k][j]) % mod1) % mod1;
      }
    }
  }
  return res;
}
vector<vector<ll> > mat_exp(vector<vector<ll> > mat, ll p, ll mod1) {
  vector<vector<ll> > res(ll((mat).size()), vector<ll>(ll((mat[0]).size()), 0));
  for (ll i = 0; i <= ll((mat).size()) - 1; i++) res[i][i] = 1;
  while (p > 0) {
    if (p & 1) res = mat_mul(res, mat, mod1);
    mat = mat_mul(mat, mat, mod1);
    p >>= 1;
  }
  return res;
}
const int N = 100000 + 5;
ll n, m, t, q, k, x, y, z, w, ans, a, b;
ll mat[3005][3005];
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  cin >> n >> m >> a >> b;
  cin >> w >> x >> y >> z;
  for (ll i = 0; i <= (n - 1) * m + m - 1; i++) {
    mat[i / m][i % m] = w;
    w = ((w * x) % z + y) % z;
  }
  a--;
  b--;
  for (ll i = 0; i <= n - 1; i++) {
    priority_queue<pair<int, int> > ro;
    for (ll j = 0; j <= b - 1; j++) ro.push(make_pair(-mat[i][j], j));
    for (ll j = b; j <= m - 1; j++) {
      ro.push(make_pair(-mat[i][j], j));
      while (ro.top().second < j - b) ro.pop();
      mat[i][j] = -ro.top().first;
    }
  }
  for (ll i = b; i <= m - 1; i++) {
    priority_queue<pair<int, int> > co;
    for (ll j = 0; j <= a - 1; j++) co.push(make_pair(-mat[j][i], j));
    for (ll j = a; j <= n - 1; j++) {
      co.push(make_pair(-mat[j][i], j));
      while (co.top().second < j - a) co.pop();
      ans -= co.top().first;
    }
  }
  cout << ans << '\n';
}
