#include <bits/stdc++.h>
using namespace std;
const int maxn = 3000;
const int maxx = maxn * maxn;
int g[maxx], gg[maxn][maxn];
int main() {
  int n, m, a, b, x, y, z;
  cin >> n >> m >> a >> b >> g[0] >> x >> y >> z;
  int nm = n * m;
  for (int i = 1; i != nm; ++i) g[i] = (1LL * g[i - 1] * x + y) % z;
  for (int i = 0; i != n; ++i) {
    deque<int> que;
    int *arr = g + i * m;
    for (int j = 0; j != m; ++j) {
      while (!que.empty() && arr[que.back()] >= arr[j]) que.pop_back();
      while (!que.empty() && que.front() <= j - b) que.pop_front();
      que.emplace_back(j);
      gg[j][i] = arr[que.front()];
    }
  }
  int64_t res = 0;
  for (int i = b - 1; i != m; ++i) {
    deque<int> que;
    int *arr = gg[i];
    for (int j = 0; j != n; ++j) {
      while (!que.empty() && arr[que.back()] >= arr[j]) que.pop_back();
      while (!que.empty() && que.front() <= j - a) que.pop_front();
      que.emplace_back(j);
      if (j + 1 >= a) res += arr[que.front()];
    }
  }
  cout << res << endl;
}
