#include <bits/stdc++.h>
using namespace std;
long long m, n, a, b;
long long gn, x, y, z;
long long h[3004][3004];
long long g[3004 * 3004];
vector<vector<long long>> sol;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> m >> a >> b;
  cin >> gn >> x >> y >> z;
  g[0] = gn;
  for (long long i = 1; i < m * n; ++i) {
    g[i] = (g[i - 1] * x + y) % z;
  }
  for (long long i = 0; i < n; ++i) {
    for (long long j = 0; j <= m; ++j) {
      h[i][j] = g[(i)*m + j];
    }
  }
  deque<long long> d;
  for (long long i = 0; i < m; ++i) {
    sol.push_back(vector<long long>());
  }
  for (long long j = 0; j < m; ++j) {
    d.clear();
    long long i;
    for (i = 0; i < a; ++i) {
      while (!d.empty() && h[d.back()][j] > h[i][j]) {
        d.pop_back();
      }
      d.push_back(i);
    }
    sol[j].push_back(h[d.front()][j]);
    for (; i < n; ++i) {
      while (!d.empty() && ((i - d.front()) >= a)) {
        d.pop_front();
      }
      while (!d.empty() && h[d.back()][j] > h[i][j]) {
        d.pop_back();
      }
      d.push_back(i);
      sol[j].push_back(h[d.front()][j]);
    }
  }
  d.clear();
  long long sum = 0;
  for (long long i = 0; i < sol[0].size(); ++i) {
    d.clear();
    long long j;
    for (j = 0; j < b; ++j) {
      while (!d.empty() && sol[d.back()][i] > sol[j][i]) {
        d.pop_back();
      }
      d.push_back(j);
    }
    sum += sol[d.front()][i];
    for (; j < m; ++j) {
      while (!d.empty() && ((j - d.front()) >= b)) {
        d.pop_front();
      }
      while (!d.empty() && sol[d.back()][i] > sol[j][i]) {
        d.pop_back();
      }
      d.push_back(j);
      sum += sol[d.front()][i];
    }
  }
  cout << sum << '\n';
  return 0;
}
