#include <bits/stdc++.h>
using namespace std;
long long n, m, a, b, x, y, z;
int g[3010][3010];
long long cnt;
int main() {
  int i, j, temp;
  cin >> n >> m >> a >> b;
  cin >> temp >> x >> y >> z;
  for (i = 0; i < n; i++) {
    for (j = 0; j < m; j++) {
      g[i][j] = temp;
      temp = (temp * x + y) % z;
    }
  }
  for (i = 0; i < n; i++) {
    priority_queue<pair<int, int>, vector<pair<int, int>>,
                   greater<pair<int, int>>>
        q;
    for (j = 0; j < m; j++) {
      q.emplace(g[i][j], j);
      while (q.top().second <= j - b) q.pop();
      g[i][j] = q.top().first;
    }
  }
  for (j = b - 1; j < m; j++) {
    priority_queue<pair<int, int>, vector<pair<int, int>>,
                   greater<pair<int, int>>>
        q;
    for (i = 0; i < n; i++) {
      q.emplace(g[i][j], i);
      while (q.top().second <= i - a) q.pop();
      if (i >= a - 1) cnt += q.top().first;
    }
  }
  cout << cnt << endl;
  return 0;
}
