func_code_string: #include <bits/stdc++.h>   using namespace std;   inline int read() {     char ch = getchar();     int res = 0, flag = 1;     while (ch <  0  || ch >  9 ) {       if (ch ==  - ) flag = -1;       ch = getchar();     }     while (ch >=  0  && ch <=  9 ) {       res = res * 10 + ch -  0 ;       ch = getchar();     }     return res * flag;   }   int r, c, n, k, p[3005][3005], x, y, cnt[3005], nxt[3005], lst[3005], tmp[3005];   long long ans;   int main() {     r = read();     c = read();     n = read();     k = read();     for (register int i = 1; i <= n; ++i) {       x = read();       y = read();       p[x][++p[x][0]] = y;     }     for (register int i = 1; i <= r; ++i) sort(p[i] + 1, p[i] + p[i][0] + 1);     for (register int i = r; i; --i) {       int h = 1, t = 0, s = 0;       long long now = 0;       for (register int j = 1; j <= p[i][0]; ++j) ++cnt[p[i][j]];       while (1) {         while (t < c && s < k) {           ++t;           s += cnt[t];         }         if (s < k) break;         while (h <= t && s >= k) {           s -= cnt[h];           ++h;           now += c - t + 1;         }       }       nxt[0] = 1;       lst[c + 1] = c;       for (register int j = 1; j <= c; ++j) {         nxt[j] = j + 1;         lst[j] = j - 1;       }       for (register int j = 1; j <= c; ++j)         if (!cnt[j]) {           nxt[lst[j]] = nxt[j];           lst[nxt[j]] = lst[j];         }       memcpy(tmp, cnt, sizeof(cnt));       for (register int j = r; j >= i; --j) {         ans += now;         for (register int u = 1; u <= p[j][0]; ++u) {           h = t = p[j][u];           int s1 = tmp[h], s2 = 0;           while (nxt[t] <= c && s1 + s2 + tmp[nxt[t]] <= k) {             t = nxt[t];             s2 += tmp[t];           }           while (1) {             if (s1 + s2 == k) now -= (h - lst[h]) * (nxt[t] - t);             h = lst[h];             s1 += tmp[h];             if (!h || s1 > k) break;             while (s1 + s2 > k) {               s2 -= tmp[t];               t = lst[t];             }           }           --tmp[p[j][u]];           if (!tmp[p[j][u]]) {             nxt[lst[p[j][u]]] = nxt[p[j][u]];             lst[nxt[p[j][u]]] = lst[p[j][u]];           }         }       }     }     printf( %lld n , ans);     return 0;   }   