#include <bits/stdc++.h>
using namespace std;
class Solution {
 public:
  long long solve(int n, int m, int a, int b, int g, long long x, long long y,
                  long long z) {
    vector<vector<long long>> mat(n, vector<long long>(m, 0));
    for (int i = 0; i < n; ++i) {
      for (int j = 0; j < m; ++j) {
        mat[i][j] = g;
        g = (g * x + y) % z;
      }
    }
    vector<vector<long long>> minMat(n, vector<long long>(m, 0));
    for (int j = 0; j < m; ++j) {
      deque<int> q;
      int i = 0;
      for (; i < a; ++i) {
        while (!q.empty() && q.back() > mat[i][j]) {
          q.pop_back();
        }
        q.push_back(mat[i][j]);
        minMat[i][j] = q.front();
      }
      for (; i < n; ++i) {
        if (mat[i - a][j] == q.front()) q.pop_front();
        while (!q.empty() && q.back() > mat[i][j]) {
          q.pop_back();
        }
        q.push_back(mat[i][j]);
        minMat[i][j] = q.front();
      }
    }
    long long cnt = 0ll;
    for (int i = a - 1; i < n; ++i) {
      deque<int> q;
      int j = 0;
      for (; j < b; ++j) {
        while (!q.empty() && q.back() > minMat[i][j]) {
          q.pop_back();
        }
        q.push_back(minMat[i][j]);
      }
      cnt += q.front();
      for (; j < m; ++j) {
        if (q.front() == minMat[i][j - b]) q.pop_front();
        while (!q.empty() && q.back() > minMat[i][j]) {
          q.pop_back();
        }
        q.push_back(minMat[i][j]);
        cnt += q.front();
      }
    }
    return cnt;
  }
};
int main() {
  Solution sol;
  int n, m, a, b;
  long long g, x, y, z;
  cin >> n >> m >> a >> b >> g >> x >> y >> z;
  cout << sol.solve(n, m, a, b, g, x, y, z) << endl;
  return 0;
}
