#include <bits/stdc++.h>
using namespace std;
const double EPS = 1e-9;
signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  long long n, m, a, b, g, x, y, z;
  cin >> n >> m >> a >> b >> g >> x >> y >> z;
  vector<vector<long long>> c(n, vector<long long>(m));
  c[0][0] = g;
  for (long long i = (0); i < (n); i++)
    for (long long j = (0); j < (m); j++) {
      if (i == 0 && j == 0) continue;
      g = (g * x + y) % z;
      c[i][j] = g;
    }
  vector<vector<long long>> d(n, vector<long long>(m - b + 1));
  for (long long i = (0); i < (n); i++) {
    deque<pair<long long, long long>> deq;
    long long id = 0;
    for (long long j = (0); j < (m); j++) {
      while (deq.size() && deq.back().first > c[i][j]) deq.pop_back();
      deq.push_back(pair<long long, long long>(c[i][j], j));
      if (j + 1 >= b) {
        d[i][id] = deq.front().first;
        while (deq.size() && deq.front().second <= id) deq.pop_front();
        id++;
      }
    }
  }
  long long ans = 0;
  for (long long j = (0); j < (m - b + 1); j++) {
    deque<pair<long long, long long>> deq;
    long long id = 0;
    for (long long i = (0); i < (n); i++) {
      while (deq.size() && deq.back().first > d[i][j]) deq.pop_back();
      deq.push_back(pair<long long, long long>(d[i][j], i));
      if (i + 1 >= a) {
        ans += deq.front().first;
        while (deq.size() && deq.front().second <= id) deq.pop_front();
        id++;
      }
    }
  }
  cout << ans << endl;
  return 0;
}
