#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
const int maxn = 3e3 + 2;
const int mxn = maxn * maxn;
const int inf = 2e9;
const long long linf = 4e18;
int g[mxn];
int a[maxn][maxn];
void solve() {
  int n, m, c, b, x, y, z;
  cin >> n >> m >> c >> b >> g[0] >> x >> y >> z;
  for (int i = 1; i < n * m; i++) g[i] = (1LL * g[i - 1] * x + y) % z;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      a[i][j] = g[i * m - m + j - 1];
    }
  }
  for (int w = 1; w <= n; w++) {
    vector<int> tm;
    int i = 1, j = 1;
    deque<int> d;
    for (; j <= b; j++) {
      while (d.size() && a[w][d.back()] > a[w][j]) d.pop_back();
      d.push_back(j);
    }
    tm.push_back(d.front());
    for (i = 2; j <= m; i++, j++) {
      if (d.front() < i) d.pop_front();
      while (d.size() && a[w][d.back()] > a[w][j]) d.pop_back();
      d.push_back(j);
      tm.push_back(d.front());
    }
    for (int y = 0; y < tm.size(); y++) a[w][y + 1] = a[w][tm[y]];
  }
  long long ans = 0;
  for (int w = 1; w <= m - b + 1; w++) {
    deque<int> d;
    int i = 1, j = 1;
    for (; j <= c; j++) {
      while (d.size() && a[d.back()][w] > a[j][w]) d.pop_back();
      d.push_back(j);
    }
    ans += a[d.front()][w];
    for (int i = 2; j <= n; i++, j++) {
      if (d.front() < i) d.pop_front();
      while (d.size() && a[d.back()][w] > a[j][w]) d.pop_back();
      d.push_back(j);
      ans += a[d.front()][w];
    }
  }
  cout << ans;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cerr.tie(0);
  int tt = 1;
  while (tt--) solve();
  return 0;
}
