#include <bits/stdc++.h>
using namespace std;
const long long maxn = 3e3 + 7;
long long maze[maxn][maxn];
long long min_maze[maxn][maxn];
long long q[maxn];
int main() {
  long long n, m, a, b;
  long long g, x, y, z;
  long long ans = 0;
  scanf("%lld%lld%lld%lld", &n, &m, &a, &b);
  scanf("%lld%lld%lld%lld", &g, &x, &y, &z);
  long long head = 0, tail = 0;
  for (long long i = 1; i <= n; i++) {
    head = 0;
    tail = 0;
    for (long long j = 1; j <= m; j++) {
      maze[i][j] = g;
      g = (g * x + y) % z;
      while (head < tail && j - q[head + 1] >= b) {
        head++;
      }
      while (head < tail && maze[i][q[tail]] >= maze[i][j]) {
        tail--;
      }
      q[++tail] = j;
      min_maze[i][j] = maze[i][q[head + 1]];
    }
  }
  for (long long j = b; j <= m; j++) {
    head = 0;
    tail = 0;
    for (long long i = 1; i <= n; i++) {
      while (head < tail && i - q[head + 1] >= a) {
        head++;
      }
      while (head < tail && min_maze[q[tail]][j] >= min_maze[i][j]) {
        tail--;
      }
      q[++tail] = i;
      if (i >= a) ans += min_maze[q[head + 1]][j];
    }
  }
  printf("%lld\n", ans);
  return 0;
}
