#include <bits/stdc++.h>
using namespace std;
typedef priority_queue<long long, vector<long long>, greater<long long>>
    minHeap;
const long long MD = 998244353;
inline long long mul(long long a, long long b) { return (a * b) % MD; }
inline long long po(long long a, long long b) {
  long long ans = 1;
  while (b > 0) {
    if (b & 1) ans = mul(ans, a);
    a = mul(a, a);
    b /= 2;
  }
  return ans;
}
long long INF = 1e17;
const int N = 5e5 + 22;
long long n, m, t, k;
long long arr[N];
string s;
int a, b;
long long g, x, y, z;
int tb[3100][3100];
int main() {
  ios::sync_with_stdio(false);
  cin >> n >> m >> a >> b;
  cin >> g >> x >> y >> z;
  vector<deque<int>> fi(m);
  long long cur = g;
  for (int i = 0; i < a - 1; i++) {
    for (int j = 0; j < m; j++) {
      while (!fi[j].empty() && fi[j].back() > cur) fi[j].pop_back();
      fi[j].push_back(cur);
      tb[i][j] = cur;
      cur = ((cur * x) % z + y) % z;
    }
  }
  long long ans = 0;
  for (int i = a - 1; i < n; i++) {
    for (int j = 0; j < m; j++) {
      while (!fi[j].empty() && fi[j].back() > cur) fi[j].pop_back();
      fi[j].push_back(cur);
      tb[i][j] = cur;
      cur = ((cur * x) % z + y) % z;
    }
    deque<int> se;
    queue<int> qu;
    for (int j = 0; j < b - 1; j++) {
      int fl = fi[j].front();
      while (!se.empty() && se.back() > fl) se.pop_back();
      se.push_back(fl);
      qu.push(fl);
    }
    for (int j = b - 1; j < m; j++) {
      int fl = fi[j].front();
      while (!se.empty() && se.back() > fl) se.pop_back();
      se.push_back(fl);
      qu.push(fl);
      ans += se.front();
      if (qu.front() == se.front()) se.pop_front();
      qu.pop();
    }
    for (int j = 0; j < m; j++) {
      if (fi[j].front() == tb[i - a + 1][j]) fi[j].pop_front();
    }
  }
  cout << ans;
  return 0;
}
