#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;
const int LG = 50;
const int MX = 3e3 + 10;
int g[MX][MX];
int G[MX][MX];
int main() {
  long long n, m, a, b, x, y, z, now;
  cin >> n >> m >> a >> b >> now >> x >> y >> z;
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++) g[i][j] = now, now = (now * x + y) % z;
  for (int i = 1; i <= n; i++) {
    deque<int> q;
    for (int j = 1; j < b; j++) {
      while (!q.empty() && g[i][q.back()] >= g[i][j]) q.pop_back();
      q.push_back(j);
    }
    for (int j = b; j <= m; j++) {
      while (!q.empty() && q.front() <= j - b) q.pop_front();
      while (!q.empty() && g[i][q.back()] >= g[i][j]) q.pop_back();
      q.push_back(j);
      G[i][j] = g[i][q.front()];
    }
  }
  long long ans = 0;
  for (int i = b; i <= m; i++) {
    deque<int> q;
    for (int j = 1; j < a; j++) {
      while (!q.empty() && G[q.back()][i] >= G[j][i]) q.pop_back();
      q.push_back(j);
    }
    for (int j = a; j <= n; j++) {
      while (!q.empty() && q.front() <= j - a) q.pop_front();
      while (!q.empty() && G[q.back()][i] >= G[j][i]) q.pop_back();
      q.push_back(j);
      ans = ans + (long long)G[q.front()][i];
    }
  }
  cout << ans << '\n';
  return 0;
}
