#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;
long long num[3005][3005], min_row[3005][3005], min_col[3005][3005];
int main() {
  long long i, j, n, m, a, b, g, x, y, z;
  scanf("%lld%lld%lld%lld%lld%lld%lld%lld", &n, &m, &a, &b, &g, &x, &y, &z);
  for (i = 0; i < n; i++)
    for (j = 0; j < m; j++) {
      num[i][j] = g;
      g = (g * x + y) % z;
    }
  for (i = 0; i < n; i++) {
    deque<long long> dq;
    for (j = 0; j < m; j++) {
      while (dq.size() && dq.front() < j - b + 1) dq.pop_front();
      while (dq.size() && num[i][j] <= num[i][dq.back()]) dq.pop_back();
      dq.push_back(j);
      if (j >= b - 1) min_row[i][j - b + 1] = num[i][dq.front()];
    }
  }
  long long ans = 0;
  for (i = 0; i < m; i++) {
    deque<long long> dq;
    for (j = 0; j < n; j++) {
      while (dq.size() && dq.front() < j - a + 1) dq.pop_front();
      while (dq.size() && min_row[j][i] <= min_row[dq.back()][i]) dq.pop_back();
      dq.push_back(j);
      if (j >= a - 1) {
        min_col[j - a + 1][i] = min_row[dq.front()][i];
        ans += min_col[j - a + 1][i];
      }
    }
  }
  printf("%lld\n", ans);
}
