func_code_string: #include <bits/stdc++.h>   #pragma comment(linker,  /STACK:256000000 )   using namespace std;   const int MAXN = 3005;   int r, c, n, k;   pair<int, int> v[MAXN];   int prv[MAXN], nxt[MAXN];   vector<int> y[MAXN], x[MAXN];   int pos[MAXN];   int num[MAXN];   int cnt;   long long ans;   int res;   bool cmp_x(int num1, int num2) { return v[num1].first < v[num2].first; }   bool cmp_y(int num1, int num2) { return v[num1].second < v[num2].second; }   int trivia(int x1, int x2) {     int cnt[MAXN];     memset(cnt, 0, sizeof(cnt));     for (int yy = 1; yy <= c; yy++) {       for (int i = 0; i < y[yy].size(); i++) {         if (x1 <= v[y[yy][i]].first && v[y[yy][i]].first <= x2) {           cnt[yy]++;         }       }     }     int res = 0;     for (int yy1 = 1; yy1 <= c; yy1++) {       int cur = 0;       for (int y2 = yy1; y2 <= c; y2++) {         cur += cnt[y2];         if (cur >= k) {           res++;         }       }     }     return res;   }   void solve() {     scanf( %d%d%d%d , &r, &c, &n, &k);     for (int i = 1; i <= n; i++) {       scanf( %d%d , &v[i].first, &v[i].second);       y[v[i].second].push_back(i);       x[v[i].first].push_back(i);     }     for (int i = 1; i <= r; i++) {       sort(x[i].begin(), x[i].end(), cmp_y);     }     for (int i = 1; i <= c; i++) {       sort(y[i].begin(), y[i].end(), cmp_x);     }     v[n + 1].second = c + 1;     for (int i = 1; i <= r; i++) {       cnt = 0;       res = 0;       for (int j = 1; j <= c; j++) {         for (int h = (int)y[j].size() - 1; h >= 0; h--) {           int curnum = y[j][h];           if (v[curnum].first < i) {             break;           }           pos[curnum] = ++cnt;           num[cnt] = curnum;           prv[cnt] = cnt - 1;           nxt[cnt - 1] = cnt;         }       }       nxt[cnt] = cnt + 1;       num[cnt + 1] = n + 1;       nxt[cnt + 1] = 0;       for (int j = k; j <= cnt; j++) {         res += (v[num[j + 1]].second - v[num[j]].second) *                (v[num[j - k + 1]].second);       }       for (int j = r; j >= i; j--) {         ans += res;         for (int h = 0; h < x[j].size(); h++) {           vector<int> all;           all.reserve(k << 1);           int back = 0;           int p = prv[pos[x[j][h]]];           while (p && all.size() < k - 1) {             all.push_back(p);             p = prv[p];           }           back = all.size();           reverse(all.begin(), all.end());           if (p) {             res +=                 (v[num[nxt[pos[x[j][h]]]]].second - v[num[pos[x[j][h]]]].second) *                 (v[num[p]].second);           }           p = pos[x[j][h]];           while (p && all.size() <= k + back) {             all.push_back(p);             p = nxt[p];           }           for (int l = max(k - 1, back); l + 1 < all.size(); l++) {             res -= (v[num[all[l + 1]]].second - v[num[all[l]]].second) *                    (v[num[all[l - k + 1]]].second);           }           for (int l = max(k, back + 1); l + 1 < all.size(); l++) {             res += (v[num[all[l + 1]]].second - v[num[all[l]]].second) *                    (v[num[all[l - k]]].second);           }           prv[nxt[pos[x[j][h]]]] = prv[pos[x[j][h]]];           nxt[prv[pos[x[j][h]]]] = nxt[pos[x[j][h]]];         }       }     }     printf( %I64d n , ans);   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     srand(1313);     solve();     return 0;   }   