#include <bits/stdc++.h>
using namespace std;
vector<vector<long long>> A(3000, vector<long long>(3000, 0));
vector<deque<long long>> deqs(3000);
int main() {
  long long(n), (m);
  scanf("%lld%lld", &(n), &(m));
  ;
  long long(a), (b);
  scanf("%lld%lld", &(a), &(b));
  ;
  long long(g);
  scanf("%lld", &(g));
  ;
  long long(x), (y), (z);
  scanf("%lld%lld%lld", &(x), &(y), &(z));
  ;
  A[0][0] = g;
  long long prev = g, k = 0;
  for (long long k = 1; k < (m * n); k++) {
    A[k / m][k % m] = prev = (prev * x % z + y) % z;
  }
  long long res = 0;
  for (long long j = 0; j < (m); j++) {
    for (long long i = 0; i < (a); i++) {
      while (deqs[j].size() && deqs[j].back() > A[i][j]) {
        deqs[j].pop_back();
      }
      deqs[j].push_back(A[i][j]);
    }
  }
  for (long long i = a; i < (n + 1); i++) {
    deque<long long> d;
    for (long long j = 0; j < (b); j++) {
      while (d.size() && d.back() > deqs[j].front()) {
        d.pop_back();
      }
      d.push_back(deqs[j].front());
    }
    res += d.front();
    for (long long j = b; j < (m); j++) {
      if (deqs[j - b].front() == d.front()) d.pop_front();
      while (d.size() && d.back() > deqs[j].front()) {
        d.pop_back();
      }
      d.push_back(deqs[j].front());
      res += d.front();
    }
    if (i == n) break;
    for (long long j = 0; j < (m); j++) {
      if (A[i - a][j] == deqs[j].front()) deqs[j].pop_front();
      while (deqs[j].size() && deqs[j].back() > A[i][j]) {
        deqs[j].pop_back();
      }
      deqs[j].push_back(A[i][j]);
    }
  }
  printf("%lld\n", res);
  return 0;
}
