#include <bits/stdc++.h>
using namespace std;
template <class C>
class seg_tree {
  vector<C> tree;
  C (*key)(C, C);
  const C def;
  int p = 1;

 public:
  seg_tree(vector<C> v, C func(C, C), C a) : def(a), key(func) {
    int n = (int)v.size();
    while (p < n) {
      p <<= 1;
    }
    tree.resize(2 * p, def);
    for (int i = 0; i < n; ++i) {
      tree[i + p] = v[i];
    }
    for (int i = p - 1; i > 0; --i) {
      tree[i] = key(tree[i << 1], tree[(i << 1) + 1]);
    }
  }
  C query(int l, int r) {
    C ans = def;
    for (l += p, r += p; l <= r; l >>= 1, r >>= 1) {
      if (l & 1) {
        ans = key(ans, tree[l++]);
      }
      if ((r & 1) == 0) {
        ans = key(ans, tree[r--]);
      }
    }
    return ans;
  }
};
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  auto _min = [](int a, int b) { return min(a, b); };
  int n, m, a, b, g, x, y, z;
  cin >> n >> m >> a >> b >> g >> x >> y >> z;
  vector<vector<int>> gg(n, vector<int>(m));
  vector<vector<int>> t(n);
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < m; ++j) {
      gg[i][j] = g;
      g = int(1ll * g * x % z + y) % z;
    }
    seg_tree<int> tree(gg[i], _min, 1e9);
    for (int j = 0; j < m - b + 1; ++j) {
      t[i].push_back(tree.query(j, j + b - 1));
    }
  }
  long long ans = 0;
  for (int j = 0; j < m - b + 1; ++j) {
    vector<int> col;
    for (int i = 0; i < n; ++i) {
      col.push_back(t[i][j]);
    }
    seg_tree<int> tree(col, _min, 1e9);
    for (int i = 0; i < n - a + 1; ++i) {
      ans += tree.query(i, i + a - 1);
    }
  }
  cout << ans;
  return 0;
}
