#include <bits/stdc++.h>
using namespace std;
int matrix[3002][3002];
int ver[3002][3002] = {0};
void insertDeque(deque<long long> &q, long long x) {
  if (q.size() != 0)
    while (q.size() != 0 && q.back() > x) {
      q.pop_back();
    }
  q.push_back(x);
}
void deleteDeque(deque<long long> &q, long long x) {
  if (q.front() == x) {
    q.pop_front();
  }
}
void calculateHorAndVer(long long n, long long m, long long a, long long b) {
  deque<long long> q;
  long long i, j;
  for (j = 0; j < m; j++) {
    q.clear();
    for (i = 0; i < a; i++) {
      insertDeque(q, matrix[i][j]);
    }
    ver[0][j] = q.front();
    for (i = a; i < n; i++) {
      deleteDeque(q, matrix[i - a][j]);
      insertDeque(q, matrix[i][j]);
      ver[i - a + 1][j] = q.front();
    }
  }
}
long long ans = 0;
void solve(long long n, long long m, long long a, long long b) {
  long long i, j;
  deque<long long> q;
  for (i = 0; i <= n - a; i++) {
    q.clear();
    for (j = 0; j < b; j++) {
      insertDeque(q, ver[i][j]);
    }
    ans = ans + (long long)(q.front());
    for (j = b; j < m; j++) {
      insertDeque(q, ver[i][j]);
      deleteDeque(q, ver[i][j - b]);
      ans = ans + (long long)(q.front());
    }
  }
}
int main() {
  long long n, m, a, b;
  cin >> n >> m >> a >> b;
  long long g0, x, y, z;
  cin >> g0 >> x >> y >> z;
  long long i, j;
  for (i = 0; i < n; i++) {
    for (j = 0; j < m; j++) {
      matrix[i][j] = g0;
      g0 = (g0 * x + y) % z;
    }
  }
  calculateHorAndVer(n, m, a, b);
  solve(n, m, a, b);
  cout << ans << endl;
  return 0;
}
