#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;
template <class F, class S>
std::istream &operator>>(std::istream &in, std::pair<F, S> &a) {
  in >> a.first >> a.second;
  return in;
}
template <class F, class S>
std::ostream &operator<<(std::ostream &out, std::pair<F, S> &a) {
  out << a.first << " " << a.second;
  return out;
}
template <class T>
std::istream &operator>>(std::istream &in, std::vector<T> &a) {
  for (auto &i : a) in >> i;
  return in;
}
template <class T>
std::ostream &operator<<(std::ostream &out, std::vector<T> &a) {
  for (auto &i : a) out << i << " ";
  return out;
}
inline void Start() {}
template <class T>
T gcd(T a, T b) {
  return a ? gcd(b % a, a) : b;
}
int spec_stack_func(int a, int b) { return std::min(a, b); }
struct spec_stack {
 private:
  std::stack<std::pair<int, int>> st;

 public:
  bool empty() const { return st.empty(); }
  void pop() {
    if (!st.empty()) st.pop();
  }
  int func() const { return st.top().second; }
  int top() const { return st.top().first; }
  void push(int val) {
    st.emplace(val, spec_stack_func(val, (empty() ? val : func())));
  }
};
struct spec_queue {
 private:
  spec_stack tail, head;

 public:
  void push(int val) { tail.push(val); }
  void pop() {
    if (head.empty()) {
      while (!tail.empty()) {
        head.push(tail.top());
        tail.pop();
      }
    }
    head.pop();
  }
  int func() const {
    if (head.empty()) return tail.func();
    if (tail.empty()) return head.func();
    return spec_stack_func(head.func(), tail.func());
  }
  int front() {
    if (head.empty()) {
      while (!tail.empty()) {
        head.push(tail.top());
        tail.pop();
      }
    }
    return head.top();
  }
};
signed main() {
  Start();
  int n, m, w, h;
  std::cin >> n >> m >> w >> h;
  int g0, x, y, z;
  cin >> g0 >> x >> y >> z;
  vector<long long> g(n * m);
  g[0] = g0;
  for (int i = 1; i < n * m; ++i) g[i] = (g[i - 1] * x + y) % z;
  std::vector<std::vector<int>> a(n, std::vector<int>(m));
  for (int i = 0; i < n; ++i)
    for (int j = 0; j < m; ++j) a[i][j] = g[i * m + j];
  long long ans = 0;
  std::vector<spec_queue> queues(n);
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < h; ++j) {
      queues[i].push(a[i][j]);
    }
  }
  spec_queue q0;
  for (int i = 0; i < w; ++i) {
    q0.push(queues[i].func());
  }
  ans += q0.func();
  for (int i = w; i < n; ++i) {
    q0.pop();
    q0.push(queues[i].func());
    ans += q0.func();
  }
  for (int i = h; i < m; ++i) {
    for (int j = 0; j < n; ++j) {
      queues[j].pop();
      queues[j].push(a[j][i]);
    }
    spec_queue q;
    for (int j = 0; j < w; ++j) q.push(queues[j].func());
    ans += q.func();
    for (int j = w; j < n; ++j) {
      q.pop();
      q.push(queues[j].func());
      ans += q.func();
    }
  }
  cout << ans;
  return 0;
}
