func_code_string: #include <bits/stdc++.h>   using namespace std;   inline int read() {     int s = 0, t = 1;     char ch = getchar();     while (ch <  0  || ch >  9 ) {       if (ch ==  - ) t = -1;       ch = getchar();     }     while (ch >=  0  && ch <=  9 )       s = (s << 3) + (s << 1) + (ch ^ 48), ch = getchar();     return s * t;   }   const int N = 3005;   int n, m, T, K, w[N], s[N], U[N], pr[N], su[N];   long long Sum, Ans;   vector<int> G[N];   int C(int n) { return n * (n + 1) / 2; }   void Add(int i, int t) {     Sum += (1ll * (i - U[i]) * (su[i] - i) + C(su[i] - i - 1)) * t;   }   int main() {     n = read(), m = read(), T = read(), K = read();     for (int i = 1; i <= T; i++) {       int x = read(), y = read();       G[y].push_back(x);     }     if (K == 0) return cout << 1ll * n * (n + 1) / 2 * m * (m + 1) / 2, 0;     for (int l = 1; l <= m; l++) {       memset(w, 0, sizeof(w)), Sum = 0;       for (int r = l; r <= m; r++)         for (auto x : G[r]) w[x]++;       for (int i = 1; i <= n; i++)         if (i == 1 || w[i]) {           U[i] = i, pr[i] = i - 1, su[i] = i + 1, s[i] = 0;           while (pr[i] && !w[pr[i]]) pr[i]--;           if (i > 1) pr[i] = max(pr[i], 1);           while (su[i] <= n && !w[su[i]]) su[i]++;           while (U[i] && s[i] + w[U[i]] < K) s[i] += w[U[i]], U[i] = pr[U[i]];           Add(i, +1);         }       for (int r = m; r >= l; r--) {         Ans += Sum;         for (auto x : G[r]) {           int t = x;           w[x]--;           if (x != 1 && !w[x]) {             t = su[x], pr[su[x]] = pr[x];             Add(x, -1), Add(pr[x], -1), su[pr[x]] = su[x], Add(pr[x], +1);           }           for (int j = 1, i = t; j <= K && i <= n; j++, i = su[i]) {             if (U[i] < x) s[i]--;             Add(i, -1);             while (U[i] && s[i] + w[U[i]] < K) s[i] += w[U[i]], U[i] = pr[U[i]];             Add(i, +1);           }         }       }     }     cout << 1ll * n * (n + 1) / 2 * m * (m + 1) / 2 - Ans;     return 0;   }   