func_code_string: #include <bits/stdc++.h>   using namespace std;   const int N = 3077;   int n, m, p, k, s[N], t[N], ls[N], nxt[N];   long long ans;   vector<int> P[N];   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);       P[x].push_back(y);     }     for (int u = n; u >= 1; u--) {       for (int i = 0; i < P[u].size(); i++) ++s[P[u][i]];       int l = 1, r = 0, yjy = 0;       long long aii = 0;       while (1) {         while (r + 1 <= m && yjy < k) yjy += s[++r];         if (yjy < k) break;         while (l <= r && yjy >= k) yjy -= s[l++], aii += m - r + 1;       }       for (int i = 1; i <= m; i++) t[i] = s[i];       for (int i = 0; i <= m + 1; i++) ls[i] = i - 1, nxt[i] = i + 1;       for (int i = 1; i <= m; i++)         if (!s[i]) ls[nxt[i]] = ls[i], nxt[ls[i]] = nxt[i];       for (int d = n; d >= u; d--) {         ans += aii;         for (int i = 0; i < P[d].size(); i++) {           int s = P[d][i], sl = t[s], sr = 0;           l = r = s;           while (nxt[r] <= m && sl + sr + t[nxt[r]] <= k) sr += t[r = nxt[r]];           while (1) {             if (sl + sr == k) aii -= (l - ls[l]) * (nxt[r] - r);             sl += t[l = ls[l]];             if (!l || sl > k) break;             while (sl + sr > k) sr -= t[r], r = ls[r];           }           --t[s];           if (!t[s]) ls[nxt[s]] = ls[s], nxt[ls[s]] = nxt[s];         }       }     }     printf( %lld , ans);   }   