#include <bits/stdc++.h>
using namespace std;
long long h[3009][3009];
long long sck[3009], info[3009], top, front;
long long g[9000000];
int main() {
  std::ios::sync_with_stdio(0);
  std::cin.tie(0);
  long long n, m, a, b, g0, x, y, z;
  cin >> n >> m >> a >> b >> g0 >> x >> y >> z;
  g[0] = g0;
  for (int i = 1; i < m * n; i++) {
    g[i] = (x * g[i - 1] + y) % z;
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      h[i][j] = g[(i - 1) * m + j - 1];
    }
  }
  for (int i = 1; i <= n; i++) {
    top = 0, front = 0;
    sck[top] = h[i][1];
    info[top++] = 1;
    for (int j = 2; j <= b; j++) {
      while (top > front && h[i][j] <= sck[top - 1]) top--;
      sck[top] = h[i][j];
      info[top++] = j;
    }
    h[i][1] = sck[front];
    for (int j = 2; j + b - 1 <= m; j++) {
      while (front < top && info[front] < j) front++;
      while (top > front && h[i][j + b - 1] <= sck[top - 1]) top--;
      sck[top] = h[i][j + b - 1];
      info[top++] = j + b - 1;
      h[i][j] = sck[front];
    }
  }
  for (int j = 1; j + b - 1 <= m; j++) {
    top = 0, front = 0;
    sck[top] = h[1][j];
    info[top++] = 1;
    for (int i = 2; i <= a; i++) {
      while (top > front && h[i][j] <= sck[top - 1]) top--;
      sck[top] = h[i][j];
      info[top++] = i;
    }
    h[1][j] = sck[front];
    for (int i = 2; i + a - 1 <= n; i++) {
      while (front < top && info[front] < i) front++;
      while (top > front && h[i + a - 1][j] <= sck[top - 1]) top--;
      sck[top] = h[i + a - 1][j];
      info[top++] = i + a - 1;
      h[i][j] = sck[front];
    }
  }
  long long ans = 0;
  for (int j = 1; j + b - 1 <= m; j++) {
    for (int i = 1; i + a - 1 <= n; i++) {
      ans += h[i][j];
    }
  }
  cout << ans;
  return 0;
}
