#include <bits/stdc++.h>
using namespace std;
const long long MOD = 998244353ll;
long long powmod(long long a, long long b) {
  long long res = 1;
  a %= MOD;
  assert(b >= 0);
  for (; b; b >>= 1) {
    if (b & 1) res = res * a % MOD;
    a = a * a % MOD;
  }
  return res;
}
template <typename t1, typename t2>
inline bool upmax(t1 &a, t2 b) {
  if (a < (t1)b) {
    a = (t1)b;
    return true;
  } else
    return false;
}
template <typename t1, typename t2>
inline bool upmin(t1 &a, t2 b) {
  if (a > (t1)b) {
    a = (t1)b;
    return true;
  } else
    return false;
}
template <typename T>
inline T gcd(T a, T b) {
  return b ? gcd(b, a % b) : a;
}
template <typename T>
inline T lcm(T a, T b) {
  return a * (b / gcd(a, b));
}
template <typename T>
inline T sqr(T a) {
  return a * a;
}
int dx[] = {1, 0, -1, 0, 1, 1, -1, -1};
int dy[] = {0, 1, 0, -1, 1, -1, 1, -1};
int dkx[] = {-1, -1, 1, 1, -2, -2, 2, 2};
int dky[] = {-2, 2, -2, 2, -1, 1, -1, 1};
const int INF = 1000000404;
const long long LINF = 1e18 * (1ll);
const long double PI = 3.14159265358979323846;
const long double EPS = 1e-9;
const int SQ = 318;
int timer = 0;
int h[3300][3300];
int ar[3300][3300];
template <typename T>
struct Qmin {
  int q_front = 0, q_back = 0;
  bool PRINT_QUEUE = false;
  deque<pair<T, int> > mins;
  deque<T> elements;
  void pop() {
    if (mins.front().second == q_front++) {
      mins.pop_front();
    }
    if (PRINT_QUEUE) elements.pop_front();
  }
  void push(T x) {
    while (!mins.empty() && mins.back().first >= x) {
      mins.pop_back();
    }
    mins.push_back({x, q_back++});
    if (PRINT_QUEUE) elements.push_back(x);
  }
  T getmin() { return mins.front().first; }
  void out() {
    cout << "\t In queue: \t";
    for (auto x : elements) {
      cout << x.second << ' ';
    }
    cout << endl;
  }
};
void solve() {
  int n, m;
  cin >> n >> m;
  int a, b;
  cin >> a >> b;
  int g, x, y, z;
  cin >> g >> x >> y >> z;
  for (int(i) = (1); (i) < (n + 1); (i)++) {
    for (int(j) = (1); (j) < (m + 1); (j)++) {
      h[i][j] = g;
      g = (1ll * g * x + y) % z;
    }
  }
  for (int(i) = (1); (i) < (n + 1); (i)++) {
    Qmin<int> q;
    for (int(j) = (1); (j) < (b + 1); (j)++) {
      q.push(h[i][j]);
    }
    for (int(j) = (b); (j) < (m + 1); (j)++) {
      ar[i][j] = q.getmin();
      q.push(h[i][j + 1]);
      q.pop();
    }
  }
  long long ans = 0;
  for (int(j) = (b); (j) < (m + 1); (j)++) {
    Qmin<int> q;
    for (int(i) = (1); (i) < (a + 1); (i)++) q.push(ar[i][j]);
    for (int(i) = (a); (i) < (n + 1); (i)++) {
      ans += q.getmin();
      q.push(ar[i + 1][j]);
      q.pop();
    }
  }
  cout << ans << endl;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int t = 1;
  for (int i = 1; i <= t; i++) {
    solve();
  }
  return 0;
}
