#include <bits/stdc++.h>
using namespace std;
const int N = 3000;
int n, m, a, b, x, y, z;
int g[N * N];
int h[N][N];
int t[N][N];
long long ans = 0;
vector<int> mn[N];
void input() {
  cin >> n >> m >> a >> b;
  cin >> g[0] >> x >> y >> z;
  for (int i = 1; i < N * N; i++) g[i] = (1ll * g[i - 1] * x + y) % z;
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++) h[i - 1][j - 1] = g[1ll * (i - 1) * m + j - 1];
}
vector<int> shift(vector<int> row, int l) {
  vector<int> rtr;
  deque<int> q;
  for (int i = 0; i < row.size(); i++) {
    while (q.size() && row[q.back()] > row[i]) q.pop_back();
    q.push_back(i);
    if (q.front() == i - l) q.pop_front();
    if (i >= l - 1) rtr.push_back(row[q.front()]);
  }
  return rtr;
}
int main() {
  input();
  for (int i = 0; i < n; i++) mn[i] = shift(vector<int>(h[i], h[i] + m), b);
  for (int j = 0; j <= m - b; j++) {
    vector<int> column;
    for (int i = 0; i < n; i++) column.push_back(mn[i][j]);
    vector<int> tmp = shift(column, a);
    for (int j = 0; j < tmp.size(); j++) ans += tmp[j];
  }
  cout << ans << endl;
}
