func_code_string: #include <bits/stdc++.h>   using namespace std;   int main() {     int n;     long long p;     cin >> n >> p;     vector<pair<long long, int> > ar;     vector<long long> ans(n);     for (int i = 0; i < n; i++) {       long long x;       cin >> x;       ar.push_back(make_pair(x, i));     }     sort(ar.begin(), ar.end());     set<int> waiting;     int q_smallest = n + 1;     queue<int> q;     long long time = 0;     int turn;     for (int i = 0; i < n || waiting.size() != 0 || q.size() != 0;) {       if (q.size() == 0 && waiting.size() == 0) {         q.push(ar[i].second);         q_smallest = ar[i].second;         time = ar[i++].first;       }       if (q.size() != 0) {         turn = q.front();         if (q_smallest == q.front()) q_smallest = n + 1;         q.pop();       } else if (waiting.size() != 0) {         turn = *(waiting.begin());         waiting.erase(waiting.begin());       }       time += p;       ans[turn] = time;       while (i < n && ar[i].first <= time) {         if ((q.size() == 0 || (q.size() > 0 && q_smallest > ar[i].second)) &&             turn > ar[i].second) {           q.push(ar[i].second);           q_smallest = ar[i].second;         } else {           waiting.insert(ar[i].second);         }         i++;       }     }     for (int i = 0; i < n; i++) cout << ans[i] <<    ;     return 0;   }   