#include <bits/stdc++.h>
using namespace std;
const int M = 3002;
int mi[M][M], ar[M][M];
int n, m, a, b;
long long g, x, y, z, ans;
void solve() {
  for (int j = b; j <= m; j++) {
    deque<pair<int, int> > dq;
    for (int i = 1; i <= n; i++) {
      if (dq.size() and i - dq.front().second >= a) dq.pop_front();
      while (dq.size() and dq.back().first >= mi[i][j]) dq.pop_back();
      dq.push_back(make_pair(mi[i][j], i));
      if (i >= a) ans += dq.front().first;
    }
  }
}
void build() {
  for (int i = 1; i <= n; i++) {
    deque<pair<int, int> > dq;
    for (int j = 1; j <= m; j++) {
      if (dq.size() and j - dq.front().second >= b) dq.pop_front();
      while (dq.size() and dq.back().first >= ar[i][j]) dq.pop_back();
      dq.push_back(make_pair(ar[i][j], j));
      mi[i][j] = dq.front().first;
    }
  }
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  cin >> n >> m >> a >> b >> g >> x >> y >> z;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      ar[i][j] = g;
      g = (g * x % z + y) % z;
    }
  }
  build();
  solve();
  cout << ans << '\n';
}
