#include <bits/stdc++.h>
#pragma optimization_level 3
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math")
using namespace std;
ifstream in("input.txt");
ofstream out("output.txt");
#pragma comment(linker, "/STACK:256000000")
const int INF = 2e9, N = 3000;
int n, m, a, b;
long long mins[N][N], ans = 0;
class min_stack {
  stack<long long> st;
  long long m = INF;

 public:
  void push(long long a) {
    if (a < m) {
      st.push(2 * a - m);
      m = a;
    } else
      st.push(a);
  }
  long long pop() {
    long long j = st.top();
    if (st.top() < m) {
      long long prevM = 2 * m - j;
      j = m;
      m = prevM;
    }
    st.pop();
    return j;
  }
  long long _min() { return m; }
  bool empty() { return st.empty(); }
};
class min_q {
  min_stack st1, st2;
  void move() {
    while (!st1.empty()) {
      st2.push(st1.pop());
    }
  }

 public:
  void push(long long a) { st1.push(a); }
  long long pop() {
    if (st2.empty()) move();
    return st2.pop();
  }
  long long _min() { return min(st1._min(), st2._min()); }
};
void input() {
  long long g, x, y, z, prev;
  cin >> n >> m >> a >> b >> g >> x >> y >> z;
  long long cur = g;
  for (int i = 0; i < n; i++) {
    min_q q;
    for (int r = 0, l = 0; r < m; r++) {
      q.push(cur);
      if (r - l + 1 > b) {
        q.pop();
        l++;
      }
      if (r - l + 1 == b) mins[i][l] = q._min();
      prev = cur;
      cur = (prev * x + y) % z;
    }
  }
}
void get_ans() {
  for (int j = 0; j + b - 1 < m; j++) {
    min_q q;
    for (int d = 0, u = 0; d < n; d++) {
      q.push(mins[d][j]);
      if (d - u + 1 > a) {
        q.pop();
        u++;
      }
      if (d - u + 1 == a) ans += q._min();
    }
  }
}
int main() {
  input();
  get_ans();
  cout << ans;
}
