#include <bits/stdc++.h>
using namespace std;
long long a[3003][3003];
long long b[3003][3003];
int main() {
  int n, m, aa, bb;
  scanf("%d %d", &n, &m);
  scanf("%d %d", &aa, &bb);
  long long x, y, z;
  scanf("%lld", &a[1][1]);
  scanf("%lld %lld %lld", &x, &y, &z);
  long long pre = a[1][1];
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++) {
      if (i == 1 && j == 1) continue;
      a[i][j] = (pre * x + y) % z;
      pre = a[i][j];
    }
  for (int i = 1; i <= n; i++) {
    deque<pair<long long, int> > q;
    for (int j = 1; j <= bb; j++) {
      if (!q.size())
        q.push_back(make_pair(a[i][j], j));
      else {
        if (a[i][j] <= q.front().first) {
          q.push_front(make_pair(a[i][j], j));
        } else {
          while (q.back().first >= a[i][j]) {
            q.pop_back();
          }
          q.push_back(make_pair(a[i][j], j));
        }
      }
    }
    for (int j = 1; j + bb - 1 <= m; j++) {
      if (j == 1) {
        b[i][j] = q.front().first;
        continue;
      }
      int l = j;
      int r = j + bb - 1;
      while (q.size() && q.front().second < l) q.pop_front();
      while (q.size() && q.back().second < l) q.pop_back();
      if (!q.size() || a[i][r] <= q.front().first) {
        q.push_front(make_pair(a[i][r], r));
      } else {
        while (q.size() && q.back().first >= a[i][r]) {
          q.pop_back();
        }
        q.push_back(make_pair(a[i][r], r));
      }
      b[i][j] = q.front().first;
    }
  }
  long long ans = 0ll;
  for (int j = 1; j <= m; j++) {
    deque<pair<long long, int> > q;
    for (int i = 1; i <= aa; i++) {
      if (!q.size())
        q.push_back(make_pair(b[i][j], i));
      else {
        if (b[i][j] <= q.front().first) {
          q.push_front(make_pair(b[i][j], i));
        } else {
          while (q.back().first >= b[i][j]) {
            q.pop_back();
          }
          q.push_back(make_pair(b[i][j], i));
        }
      }
    }
    for (int i = 1; i + aa - 1 <= n; i++) {
      if (i == 1) {
        ans += q.front().first;
        continue;
      }
      int l = i;
      int r = i + aa - 1;
      while (q.size() && q.front().second < l) q.pop_front();
      while (q.size() && q.back().second < l) q.pop_back();
      if (!q.size() || b[r][j] <= q.front().first)
        q.push_front(make_pair(b[r][j], r));
      else {
        while (q.size() && q.back().first >= b[r][j]) {
          q.pop_back();
        }
        q.push_back(make_pair(b[r][j], r));
      }
      ans += q.front().first;
    }
  }
  printf("%lld\n", ans);
  ;
  return 0;
}
