func_code_string: #include <bits/stdc++.h>   using namespace std;   struct pt {     long long x, y;   } a[3005];   long long n, m, q, lim, las, pre[3005], suf[3005], rc[3005][3005], c, x, y, z,       v, ans;   long long cmp(pt x, pt y) { return x.y < y.y || (x.y == y.y && x.x < y.x); }   long long cb(long long x) { return (x + 1) * x >> 1; }   int main() {     scanf( %lld , &n), scanf( %lld , &m), scanf( %lld , &q), scanf( %lld , &lim);     for (long long i = 1; i <= q; i++)       scanf( %lld , &a[i].x), scanf( %lld , &a[i].y);     sort(a + 1, a + q + 1, cmp);     for (long long i = 1; i <= q; i++) rc[a[i].x][++rc[a[i].x][0]] = i;     a[q + 1].y = m + 1;     for (long long i = 1; i <= n; i++) {       memset(pre, 255, sizeof pre), memset(suf, 255, sizeof suf), las = 0;       for (long long j = 1; j <= q; j++)         if (a[j].x >= i) suf[pre[j] = las] = j, las = j;       suf[pre[q + 1] = las] = q + 1, v = cb(m), x = y = suf[0], c = 1;       while (suf[x] > -1) {         while (c + 1 < lim && suf[suf[y]] > -1) c++, y = suf[y];         if (c < lim) v -= (a[x].y - a[pre[x]].y) * (a[suf[y]].y - a[x].y);         x = suf[x], c--;       }       x = suf[0];       while (x) v -= cb(a[x].y - a[pre[x]].y - 1), x = suf[x];       for (long long j = n; j >= i; j--) {         ans += v;         if (!v) break;         if (j > i)           for (long long u = 1; u <= rc[j][0]; u++)             if (x = y = z = rc[j][u]) {               c = 1;               while (c < lim && pre[pre[x]] > -1) x = pre[x], c++;               while (pre[x] != z) {                 while (c < lim && suf[suf[y]] > -1) y = suf[y], c++;                 if (c == lim)                   v -= (a[x].y - a[pre[x]].y) * (a[suf[y]].y - a[y].y);                 if (c < lim) break;                 x = suf[x], c--;               }               x = pre[z], y = suf[z], suf[pre[y] = x] = y;             }       }     }     printf( %lld , ans);   }   