#include <bits/stdc++.h>
using namespace std;
const int nsz = 3000;
int n, m, r, c, x, y, z, g[nsz * nsz + 5], h[nsz + 5][nsz + 5];
long long ans;
struct monotonous_queue {
  int l = 0, r = -1;
  pair<int, int> q[nsz + 5];
  void inline clear() {
    l = 0;
    r = -1;
  }
  void inline push_back(int id, int val) {
    for (; l <= r && q[r].second >= val; --r)
      ;
    q[++r] = make_pair(id, val);
  }
  void inline pop_front(int t) {
    for (; l <= r && q[l].first < t; ++l)
      ;
  }
  int inline top() { return q[l].second; }
};
monotonous_queue q;
int main() {
  ios_base::sync_with_stdio(0);
  cin >> n >> m >> r >> c >> g[0] >> x >> y >> z;
  for (int i = 1; i <= n * m; ++i) {
    g[i] = ((long long)g[i - 1] * x + y) % z;
  }
  for (int i = 1; i <= n; ++i) {
    for (int j = 1; j <= m; ++j) {
      h[i][j] = g[(i - 1) * m + j - 1];
    }
  }
  for (int i = 1; i <= n; ++i) {
    for (int j = 1; j <= c; ++j) {
      q.push_back(j, h[i][j]);
    }
    for (int j = 1; j <= m - c + 1; ++j) {
      q.pop_front(j);
      h[i][j] = q.top();
      q.push_back(j + c, h[i][j + c]);
    }
    q.clear();
  }
  for (int j = 1; j <= m - c + 1; ++j) {
    for (int i = 1; i <= r; ++i) {
      q.push_back(i, h[i][j]);
    }
    for (int i = 1; i <= n - r + 1; ++i) {
      q.pop_front(i);
      ans += q.top();
      q.push_back(i + r, h[i + r][j]);
    }
    q.clear();
  }
  cout << ans << '\n';
}
