#include <bits/stdc++.h>
using namespace std;
long long mp[4010][4010], f[4010][4010];
int main() {
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);
  long long n, m, a, b, x, y, z;
  cin >> n >> m >> a >> b;
  cin >> mp[1][1] >> x >> y >> z;
  for (int i = 1; i <= n; i += 1) {
    if (i - 1) mp[i][1] = (mp[i - 1][m] * x + y) % z;
    for (int j = 2; j <= m; j += 1) {
      mp[i][j] = (mp[i][j - 1] * x + y) % z;
    }
  }
  for (int i = 1; i <= n; i += 1) {
    deque<pair<int, int>> d;
    for (int j = 1; j <= b; j += 1) {
      while (d.size() && d.back().second > mp[i][j]) d.pop_back();
      d.push_back(make_pair(j, mp[i][j]));
    }
    f[i][1] = d.front().second;
    for (int j = b + 1; j <= m; j += 1) {
      while (d.size() && d.back().second > mp[i][j]) d.pop_back();
      if (d.size() && d.front().first <= j - b) d.pop_front();
      d.push_back(make_pair(j, mp[i][j]));
      f[i][j - b + 1] = d.front().second;
    }
  }
  long long ans = 0;
  for (int j = 1; j <= m; j += 1) {
    deque<pair<int, int>> d;
    for (int i = 1; i <= a; i += 1) {
      while (d.size() && d.back().second > f[i][j]) d.pop_back();
      d.push_back(make_pair(i, f[i][j]));
    }
    ans += d.front().second;
    for (int i = a + 1; i <= n; i += 1) {
      while (d.size() && d.back().second > f[i][j]) d.pop_back();
      if (d.size() && d.front().first <= i - a) d.pop_front();
      d.push_back(make_pair(i, f[i][j]));
      ans += d.front().second;
    }
  }
  cout << ans << endl;
  return 0;
}
