func_code_string: #include <bits/stdc++.h>   #pragma GCC optimize(2)   using namespace std;   void qread(int &x) {     int neg = 1;     x = 0;     char c = getchar();     while (c <  0  || c >  9 ) {       if (c ==  - ) neg = -1;       c = getchar();     }     while (c >=  0  && c <=  9 ) x = 10 * x + c -  0 , c = getchar();     x *= neg;   }   const int maxn = 3005;   int n, m, p, k;   vector<int> pt[maxn];   int cnt[maxn], prv[maxn], nxt[maxn], tmp[maxn];   long long ans, cans[maxn];   int main() {     scanf( %d%d%d%d , &n, &m, &p, &k);     for (int(i) = 1; (i) <= p; i++) {       int x, y;       scanf( %d%d , &x, &y);       pt[y].push_back(x);     }     long long ans = 0;     for (int(i) = 1; (i) <= m; i++) {       for (int j = i; j <= m; j++) {         for (int(p) = 0; (p) < pt[j].size(); p++) {           int x = pt[j][p];           cnt[x]++;         }       }       int l = 0;       for (int(j) = 1; (j) <= n; j++) {         prv[j] = l;         if (cnt[j]) l = j;       }       int r = n + 1;       for (int j = n; j >= 1; j--) {         nxt[j] = r;         if (cnt[j]) r = j;       }       int cc = 0;       for (int j = m; j >= i; j--) {         long long ccur = 0;         for (int(p) = 0; (p) < pt[j].size(); p++) {           int x = pt[j][p];           int cur = x;           int c = 0;           for (int(q) = 0; (q) < k; q++) {             if (!cur) break;             cur = prv[cur];             tmp[c++] = cur;           }           reverse(tmp, tmp + c);           int sz = c;           tmp[c++] = x;           cur = x;           for (int(q) = 0; (q) < k; q++) {             if (cur > n) break;             cur = nxt[cur];             tmp[c++] = cur;           }           int r = 0, sum = 0;           long long ttmp = 0;           for (int(l) = 0; (l) < sz + 1; l++) {             while (r < c && sum < k) sum += cnt[tmp[r]], r++;             if (l && sum == k && r > sz)               ccur += 1LL * (tmp[l] - tmp[l - 1]) * (tmp[r] - tmp[r - 1]);             sum -= cnt[tmp[l]];           }           cnt[x]--;           if (!cnt[x]) {             int l = prv[x], r = nxt[x];             nxt[l] = r;             prv[r] = l;           }         }         cans[cc++] = ccur;       }       long long tot = 0;       for (int(j) = 0; (j) < cc; j++) tot += cans[j];       for (int(j) = 0; (j) < cc; j++) {         ans += tot;         tot -= cans[j];       }     }     printf( %lld n , ans);     return 0;   }   