func_code_string: #include <bits/stdc++.h>   using namespace std;   const int maxn = 3e3;   int r, c, n, k, tot, bound[maxn + 2], vis[maxn + 2], suc[maxn + 2],       pre[maxn + 2], rest[maxn + 2];   bool exist[maxn + 2][maxn + 2];   long long ans;   struct vertex {     int x, y;   } a[maxn + 1];   vector<int> t[maxn + 1];   int main() {     scanf( %d%d%d%d , &r, &c, &n, &k);     for (int i = 1; i <= n; ++i) {       scanf( %d%d , &a[i].x, &a[i].y);       exist[a[i].x][a[i].y] = true;     }     for (int i = 1; i <= r; ++i) {       memset(vis, 0, sizeof vis);       memset(suc, 0, sizeof suc);       memset(pre, 0, sizeof pre);       memset(rest, 0, sizeof rest);       tot = 0;       suc[c + 1] = c + 1;       for (int j = 1; j <= c + 1; ++j) bound[j] = c + 1;       for (int j = 1; j <= n; ++j)         if (a[j].x >= i) {           ++vis[a[j].y];           t[a[j].x].push_back(a[j].y);         }       for (int j = 1, l = 0, sum = 0; j <= c; ++j) {         while (l <= c && sum < k) sum += vis[++l];         if (l > c) break;         bound[j] = l;         rest[j] = sum;         sum -= vis[j];       }       for (int j = 1, last = 0; j <= c; ++j) {         if (vis[j]) {           suc[last] = j;           pre[j] = last;           last = j;         }         if (j == c) {           suc[last] = c + 1;           pre[c + 1] = last;         }       }       long long sum = 0;       for (int j = c + 1; j; j = pre[j])         sum += (long long)(c - bound[j] + 1) * (j - pre[j]);       for (int j = r; j >= i; --j) {         ans += sum;         for (int l = 0; l < t[j].size(); ++l) {           int lt = t[j][l];           --vis[lt];           for (int cnt = vis[lt], now = lt; now && bound[now] >= lt;                now = pre[now]) {             --rest[now];             if (rest[now] < k) {               sum -= (long long)(c - bound[now] + 1) * (now - pre[now]);               bound[now] = suc[bound[now]];               rest[now] += vis[bound[now]];               sum += (long long)(c - bound[now] + 1) * (now - pre[now]);             }           }           if (!vis[lt]) {             sum += (long long)(c - bound[suc[lt]] + 1) * (suc[lt] - pre[lt]) -                    (long long)(c - bound[lt] + 1) * (lt - pre[lt]) -                    (long long)(c - bound[suc[lt]] + 1) * (suc[lt] - lt);             pre[suc[lt]] = pre[lt];             suc[pre[lt]] = suc[lt];           }         }         t[j].clear();       }     }     printf( %lld , ans);     return 0;   }   