#include <bits/stdc++.h>
const int MOD = 998244353;
const int INF = 1e9 + 7;
using namespace std;
const int N = 3e3 + 5;
vector<int> SlideWindow(vector<int> v, int w) {
  int n = v.size(), i;
  deque<int> dq;
  vector<int> res;
  for (i = 0; i < w; i++) {
    while (!dq.empty() && v[dq.back()] >= v[i]) dq.pop_back();
    dq.push_back(i);
  }
  res.push_back(v[dq.front()]);
  for (; i < n; i++) {
    if (dq.front() == i - w) dq.pop_front();
    while (!dq.empty() && v[dq.back()] >= v[i]) dq.pop_back();
    dq.push_back(i);
    res.push_back(v[dq.front()]);
  }
  return res;
}
int v[N][N];
int main() {
  int n, m, i, j, a, b;
  cin >> n >> m >> a >> b;
  long long int pre, x, y, z, now;
  cin >> pre >> x >> y >> z;
  for (i = 0; i < n * m; i++) {
    v[i / m][i % m] = pre;
    pre = (pre * x + y) % z;
  }
  vector<vector<int>> aux;
  vector<vector<int>> ans;
  for (i = 0; i < n; i++) {
    vector<int> row;
    for (j = 0; j < m; j++) row.push_back(v[i][j]);
    aux.push_back(SlideWindow(row, b));
  }
  long long int res = 0;
  for (j = 0; j <= m - b; j++) {
    vector<int> col;
    for (i = 0; i < n; i++) col.push_back(aux[i][j]);
    vector<int> now = SlideWindow(col, a);
    for (auto it : now) res += it;
  }
  cout << res << '\n';
  return 0;
}
