#include <bits/stdc++.h>
const double PI = acos(-1.0);
using namespace std;
int setb(int n, int pos) { return n = n | (1 << pos); }
int resb(int n, int pos) { return n = n & ~(1 << pos); }
bool checkb(int n, int pos) { return (bool)(n & (1 << pos)); }
inline long long bigmod(long long b, long long p, long long m) {
  long long ret = 1, cur = b % m;
  while (p) {
    if (p & 1) ret = (ret * cur) % m;
    cur = (cur * cur) % m;
    p = p >> 1;
  }
  return ret;
}
int n, m, a, b, ara[3002][3002], save[3002][3002];
struct info {
  int x, idx;
  info() {}
  info(int x, int idx) : x(x), idx(idx){};
};
void solve_vertical() {
  for (int j = 1; j <= m; j++) {
    deque<info> dq;
    for (int i = 1; i <= n; i++) {
      int x = ara[i][j];
      int bad = i - a;
      while (dq.size() > 0 && dq.back().idx <= bad) dq.pop_back();
      while (dq.size() > 0 && dq.front().x >= x) dq.pop_front();
      dq.push_front(info(x, i));
      if (i >= a) save[i - a + 1][j] = dq.back().x;
    }
  }
}
long long solve_horizontal() {
  long long ret = 0;
  for (int k = 1; k <= n - a + 1; k++) {
    deque<info> dq;
    for (int j = 1; j <= m; j++) {
      int x = save[k][j];
      int bad = j - b;
      while (dq.size() > 0 && dq.back().idx <= bad) dq.pop_back();
      while (dq.size() > 0 && dq.front().x >= x) dq.pop_front();
      dq.push_front(info(x, j));
      int now = dq.back().x;
      if (j >= b) ret += now;
    }
  }
  return ret;
}
long long solve() {
  solve_vertical();
  return solve_horizontal();
}
int main() {
  long long g, x, y, z;
  int i, j;
  scanf("%d %d", &n, &m);
  scanf("%d %d", &a, &b);
  scanf("%lld", &g);
  scanf("%lld %lld %lld", &x, &y, &z);
  for (i = 1; i <= n; i++) {
    for (j = 1; j <= m; j++) {
      ara[i][j] = g;
      g = (g * x + y) % z;
    }
  }
  long long ret = solve();
  printf("%lld\n", ret);
  return 0;
}
