#include <bits/stdc++.h>
using namespace std;
vector<vector<int> > precal(vector<vector<int> >& h, int n, int m, int a,
                            int b) {
  vector<vector<int> > tmp(n), mn(n);
  for (int i = 0; i < n; i++) {
    deque<int> dq;
    mn[i].resize(m), tmp[i].resize(m);
    for (int j = 0; j < m; j++) {
      for (; !dq.empty() and j - dq.front() + 1 > b; dq.pop_front())
        ;
      for (; !dq.empty() and h[i][dq.back()] > h[i][j]; dq.pop_back())
        ;
      dq.push_back(j);
      tmp[i][j] = h[i][dq.front()];
    }
  }
  for (int j = 0; j < m; j++) {
    deque<int> dq;
    for (int i = 0; i < n; i++) {
      for (; !dq.empty() and i - dq.front() + 1 > a; dq.pop_front())
        ;
      for (; !dq.empty() and tmp[dq.back()][j] > tmp[i][j]; dq.pop_back())
        ;
      dq.push_back(i);
      mn[i][j] = tmp[dq.front()][j];
    }
  }
  return mn;
}
int main() {
  ios_base ::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  int n, m, a, b, g0, x, y, z;
  cin >> n >> m >> a >> b >> g0 >> x >> y >> z;
  vector<vector<int> > h(n);
  for (int i = 0; i < n; i++) {
    h[i].resize(m);
    for (int j = 0; j < m; j++) {
      h[i][j] = g0;
      g0 = ((long long)g0 * x + y) % z;
    }
  }
  vector<vector<int> > mn = precal(h, n, m, a, b);
  long long res = 0LL;
  for (int i = a - 1; i < n; i++) {
    for (int j = b - 1; j < m; j++) {
      res += mn[i][j];
    }
  }
  cout << res << "\n";
  return 0;
}
