func_code_string: #include <bits/stdc++.h>   using namespace std;   vector<int> v[10005];   long long a[100005], dis[10005];   int b[100005], vis[10005];   bool cmp(const int &first, const int &second) { return a[first] < a[second]; }   priority_queue<pair<long long, int> > T, Q;   int main() {     long long h;     int n, m, p;     scanf( %I64d%d%d%d , &h, &n, &m, &p);     for (int i = 0; i < p; i++) dis[i] = h + 1;     dis[1] = 1;     for (int i = 1; i <= n; i++) {       scanf( %I64d%d , &a[i], &b[i]);       if (a[i] % p == 1 % p)         T.push(pair<long long, int>(b[i], -i));       else         v[a[i] % p].push_back(i);     }     for (int i = 0; i < p; i++) sort(v[i].begin(), v[i].end(), cmp);     for (int i = 1, ch; i <= m; i++) {       scanf( %d , &ch);       if (ch == 1) {         long long first;         scanf( %I64d , &first);         for (int j = 0; j < p; j++) Q.push(pair<long long, int>(-dis[j], j));         for (; !Q.empty();) {           pair<long long, int> t = Q.top();           Q.pop();           if (vis[t.second] == i) continue;           vis[t.second] = i;           int q = (t.second + first) % p;           if (first - t.first < dis[q])             dis[q] = first - t.first,             Q.push(pair<long long, int>(t.first - first, q));         }         for (int j = 0; j < p; j++)           while (!v[j].empty() && a[v[j][v[j].size() - 1]] >= dis[j])             T.push(pair<long long, int>(b[v[j][v[j].size() - 1]],                                         -v[j][v[j].size() - 1])),                 v[j].resize(v[j].size() - 1);       }       if (ch == 2) {         int first, second;         scanf( %d%d , &first, &second);         b[first] -= second;       }       if (ch == 3) {         pair<long long, int> t;       retry:         if (!T.empty())           t = T.top(), T.pop();         else           t = pair<long long, int>(0, -n - 1);         if (t.first != b[-t.second]) {           T.push(pair<long long, int>(b[-t.second], t.second));           goto retry;         }         b[-t.second] = 0;         printf( %d n , t.first);       }     }   }   