#include <bits/stdc++.h>
using namespace std;
vector<vector<long long>> grid, grid1;
int n, m, a, b;
void input() {
  cin >> n >> m >> a >> b;
  long long g0, x, y, z;
  cin >> g0 >> x >> y >> z;
  vector<long long> g(n * m + 1);
  grid.resize(n, vector<long long>(m));
  grid1.resize(n, vector<long long>(m));
  g[0] = g0;
  for (int i = 1; i <= n * m; i++) {
    g[i] = (g[i - 1] * x + y) % z;
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      grid[i][j] = g[i * m + j];
    }
  }
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  input();
  for (int i = 0; i < n; i++) {
    deque<int> q;
    for (int j = 0; j < m; j++) {
      if (!q.empty() && q.front() <= j - b) {
        q.pop_front();
      }
      while (!q.empty() && grid[i][q.back()] > grid[i][j]) {
        q.pop_back();
      }
      q.push_back(j);
      grid1[i][j] = grid[i][q.front()];
    }
  }
  long long sm = 0;
  for (int i = 0; i < m; i++) {
    deque<int> q;
    for (int j = 0; j < n; j++) {
      if (!q.empty() && q.front() <= j - a) q.pop_front();
      while (!q.empty() && grid1[q.back()][i] > grid1[j][i]) {
        q.pop_back();
      }
      q.push_back(j);
      if (i >= b - 1 && j >= a - 1) sm += grid1[q.front()][i];
    }
  }
  cout << sm << '\n';
}
