func_code_string: #include <bits/stdc++.h>   #pragma GCC optimize( Ofast )   #pragma GCC optimization( unroll-loops )   std::pair<int, int> DR[] = {{-1, 0}, {0, 1},   {1, 0}, {0, -1},                               {-1, 1}, {-1, -1}, {1, 1}, {1, -1}};   using namespace std;   template <class c>   struct rge {     c b, e;   };   template <class c>   rge<c> range(c i, c j) {     return rge<c>{i, j};   }   template <class c>   auto dud(c* x) -> decltype(cerr << *x, 0);   template <class c>   char dud(...);   struct debug {     ~debug() { cerr << endl; }     template <class c>     typename enable_if<sizeof dud<c>(0) != 1, debug&>::type operator<<(c i) {       cerr << boolalpha << i;       return *this;     }     template <class c>     typename enable_if<sizeof dud<c>(0) == 1, debug&>::type operator<<(c i) {       return *this << range(begin(i), end(i));     }     template <class c, class b>     debug& operator<<(pair<b, c> d) {       return *this <<  (  << d.first <<  ,   << d.second <<  ) ;     }     template <class c>     debug& operator<<(rge<c> d) {       *this <<  [ ;       for (auto it = d.b; it != d.e; ++it) *this <<  ,   + 2 * (it == d.b) << *it;       return *this <<  ] ;     }   };   long long gcd(long long a, long long b) {     if (b) return gcd(b, a % b);     return a;   }   mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());   long long n, m, a, b, g[3005 * 3005], val[3005][3005], mn[3005][3005], x, y, z,       ans;   int32_t main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cerr.tie(0);     cout.tie(0);     cin >> n >> m >> a >> b;     cin >> g[0] >> x >> y >> z;     for (long long i = 1; i < n * m; i++) {       g[i] = (g[i - 1] * x + y) % z;     }     for (long long i = 0; i < n; i++) {       for (long long j = 0; j < m; j++) {         val[i][j] = g[i * m + j];       }     }     for (long long j = 0; j < m; j++) {       deque<long long> dq;       for (long long i = 0; i < a; i++) {         while ((long long)((dq).size()) && val[dq.back()][j] >= val[i][j])           dq.pop_back();         dq.push_back(i);       }       mn[0][j] = val[dq.front()][j];       for (long long i = 1; i <= n - a; i++) {         if (dq.front() == i - 1) dq.pop_front();         while ((long long)((dq).size()) && val[dq.back()][j] >= val[i + a - 1][j])           dq.pop_back();         dq.push_back(i + a - 1);         mn[i][j] = val[dq.front()][j];       }     }     for (long long i = 0; i <= n - a; i++) {       deque<long long> dq;       for (long long j = 0; j < b; j++) {         while ((long long)((dq).size()) && mn[i][dq.back()] >= mn[i][j])           dq.pop_back();         dq.push_back(j);       }       ans += mn[i][dq.front()];       for (long long j = 1; j <= m - b; j++) {         if (dq.front() == j - 1) dq.pop_front();         while ((long long)((dq).size()) && mn[i][dq.back()] >= mn[i][j + b - 1])           dq.pop_back();         dq.push_back(j + b - 1);         ans += mn[i][dq.front()];       }     }     return cout << ans, 0;     return 0;   }   