func_code_string: #include <bits/stdc++.h>   using namespace std;   struct ele {     long long next, prev, delta, y;   };   long long r, c, k, n, curcnt = 0, ans = 0;   vector<ele> a;   vector<long long> deltaleft, deltaright;   vector<vector<long long> > X, id;   vector<pair<long long, long long> > tmp;   void init() {     X.clear();     X.resize(r + 1);     id.resize(r + 1);   }   void remove(long long id) {     long long cur = id;     deltaleft.clear();     deltaright.clear();     for (long long i = 0; i <= k; i++) {       if (cur == -1 || a[cur].delta == -1) break;       deltaleft.push_back(a[cur].delta);       cur = a[cur].prev;     }     cur = a[id].next;     for (long long i = 0; i <= k; i++) {       if (cur == -1 || a[cur].delta == -1) break;       deltaright.push_back(a[cur].delta);       cur = a[cur].next;     }     curcnt -= deltaright[0] * deltaleft[0];     curcnt -= deltaright[0] * (deltaright[0] - 1) / 2 +               deltaleft[0] * (deltaleft[0] - 1) / 2;     curcnt +=         (deltaright[0] + deltaleft[0]) * (deltaright[0] + deltaleft[0] - 1) / 2;     for (long long i = 0; i <= k; i++) {       if (i < deltaleft.size() && k - i < deltaright.size())         curcnt += deltaleft[i] * deltaright[k - i];     }     a[a[id].prev].next = a[id].next;     a[a[id].next].prev = a[id].prev;     a[a[id].next].delta += a[id].delta;   }   long long cmp(pair<long long, long long> a, pair<long long, long long> b) {     return X[a.first][a.second] < X[b.first][b.second];   }   void solve(long long r1) {     tmp.clear();     for (long long i = r1; i <= r; i++) {       for (long long j = 0; j < X[i].size(); j++) {         tmp.push_back({i, j});       }     }     sort(tmp.begin(), tmp.end(), cmp);     a.resize(tmp.size() + 2);     a[0].prev = -1;     a[0].next = 1;     a[0].y = 0;     a[tmp.size() + 1].prev = (long long)tmp.size();     a[tmp.size() + 1].next = -1;     a[tmp.size() + 1].y = c + 1;     for (long long i = 0; i < tmp.size(); i++) {       id[tmp[i].first][tmp[i].second] = i + 1;       a[i + 1].y = X[tmp[i].first][tmp[i].second];       a[i + 1].prev = i;       a[i + 1].next = i + 2;     }     a[0].delta = -1;     for (long long i = 1; i < a.size(); i++) {       a[i].delta = a[i].y - a[i - 1].y;     }     curcnt = 0;     for (long long i = 1; i < a.size(); i++) {       curcnt += (a[i].delta - 1) * a[i].delta / 2;       for (long long j = 1; j <= k; j++) {         if (i - j <= 0) break;         curcnt += a[i].delta * a[i - j].delta;       }     }     for (long long i = r; i >= r1; i--) {       ans += curcnt;       for (long long j = 0; j < X[i].size(); j++) {         remove(id[i][j]);       }     }   }   signed main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cin >> r >> c >> n >> k;     k--;     init();     for (long long i = 1; i <= n; i++) {       long long u, v;       cin >> u >> v;       X[u].push_back(v);     }     for (long long i = 1; i <= r; i++) {       id[i].resize(X[i].size());     }     for (long long i = 1; i <= r; i++) {       solve(i);     }     ans = (r + 1) * r / 2 * (c + 1) * c / 2 - ans;     cout << ans << endl;     return 0;   }   