#include <bits/stdc++.h>
using namespace std;
template <typename TH>
void _dbg(const char* sdbg, TH h) {
  cerr << sdbg << " = " << h << "\n";
}
template <typename TH, typename... TA>
void _dbg(const char* sdbg, TH h, TA... t) {
  while (*sdbg != ',') cerr << *sdbg++;
  cerr << " = " << h << ",";
  _dbg(sdbg + 1, t...);
}
const int N = 3e3 + 3;
int n, m, r, c, a[N][N], b[N][N];
void Build(int g0, int x, int y, int z) {
  int curG = g0;
  for (int i = (1), _b = (n); i <= _b; ++i) {
    for (int j = (1), _b = (m); j <= _b; ++j) {
      a[i][j] = curG;
      curG = ((int64_t)curG * x + y) % z;
    }
  }
}
void Solve() {
  for (int i = (1), _b = (n); i <= _b; ++i) {
    deque<int> dq;
    for (int j = (1), _b = (m); j <= _b; ++j) {
      while (int((dq).size()) && a[i][dq.back()] > a[i][j]) {
        dq.pop_back();
      }
      dq.push_back(j);
      if (j - c + 1 >= 1) {
        while (dq.front() < j - c + 1) {
          dq.pop_front();
        }
        b[i][j - c + 1] = a[i][dq.front()];
      }
    }
  }
  int64_t ans = 0;
  for (int j = (1), _b = (m - c + 1); j <= _b; ++j) {
    deque<int> dq;
    for (int i = (1), _b = (n); i <= _b; ++i) {
      while (int((dq).size()) && b[dq.back()][j] > b[i][j]) {
        dq.pop_back();
      }
      dq.push_back(i);
      if (i - r + 1 >= 1) {
        while (dq.front() < i - r + 1) {
          dq.pop_front();
        }
        ans += b[dq.front()][j];
      }
    }
  }
  cout << ans << '\n';
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cin >> n >> m >> r >> c;
  int g0, x, y, z;
  cin >> g0 >> x >> y >> z;
  Build(g0, x, y, z);
  Solve();
  return 0;
}
