#include <bits/stdc++.h>
using namespace std;
long long inf = 4e18, mod = 1e9 + 7;
void del(int idx, deque<pair<int, int>>& q) {
  if (!q.empty() && q.front().second == idx) q.pop_front();
}
void ins(int val, int idx, deque<pair<int, int>>& q) {
  while (!q.empty() && q.back().first > val) q.pop_back();
  q.push_back({val, idx});
}
void solve() {
  long long n, m, a, b;
  cin >> n >> m >> a >> b;
  long long g, x, y, z;
  cin >> g >> x >> y >> z;
  vector<long long> G(n * m, 0);
  G[0] = g;
  for (int i = 1; i < n * m; i++) {
    G[i] = (G[i - 1] * x) % z + y;
    G[i] %= z;
  }
  vector<vector<long long>> h(n + 1, vector<long long>(m + 1));
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      h[i][j] = G[(i - 1) * m + j - 1];
    }
  }
  vector<vector<long long>> minver(n + 1, vector<long long>(m + 1));
  for (int j = 1; j <= m; j++) {
    deque<pair<int, int>> q;
    for (int i = 1; i <= a; i++) {
      ins(h[i][j], i, q);
    }
    minver[1][j] = q.front().first;
    for (int i = a + 1; i <= n; i++) {
      del(i - a, q);
      ins(h[i][j], i, q);
      minver[i - a + 1][j] = q.front().first;
    }
  }
  long long ans = 0;
  for (int i = 1; i <= n - a + 1; i++) {
    deque<pair<int, int>> q;
    for (int j = 1; j <= b; j++) {
      ins(minver[i][j], j, q);
    }
    ans += q.front().first;
    for (int j = b + 1; j <= m; j++) {
      del(j - b, q);
      ins(minver[i][j], j, q);
      ans += q.front().first;
    }
  }
  cout << ans << endl;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int t = 1;
  while (t--) solve();
}
