#include <bits/stdc++.h>   using namespace std;   const long long inf = 1e16;   const int maxn = 1e5;   pair<long long, int> tree[4 * maxn + 11];   long long ans[maxn + 11];   long long minn[4 * maxn + 11], lazy[4 * maxn + 11];   set<pair<long long, int> > t;   void push_up(int rt) { tree[rt] = min(tree[rt << 1], tree[rt << 1 | 1]); }   void build(int rt, int l, int r) {     if (l == r) {       tree[rt] = make_pair(inf, l);       return;     }     int mid = (l + r) >> 1;     build(rt << 1, l, mid);     build(rt << 1 | 1, mid + 1, r);     push_up(rt);   }   void update(int rt, int l, int r, int pos, long long val) {     if (l > pos || r < pos) return;     if (l == r) {       tree[rt] = make_pair(val, l);       return;     }     int mid = (l + r) >> 1;     update(rt << 1, l, mid, pos, val);     update(rt << 1 | 1, mid + 1, r, pos, val);     push_up(rt);   }   void Push_up(int rt) { minn[rt] = min(minn[rt << 1], minn[rt << 1 | 1]); }   void push_down(int rt) {     if (minn[rt << 1] < inf) {       minn[rt << 1] -= lazy[rt];       lazy[rt << 1] += lazy[rt];     }     if (minn[rt << 1 | 1] < inf) {       minn[rt << 1 | 1] -= lazy[rt];       lazy[rt << 1 | 1] += lazy[rt];     }     lazy[rt] = 0;     minn[rt << 1] = max(minn[rt << 1], 0ll);     minn[rt << 1 | 1] = max(minn[rt << 1 | 1], 0ll);   }   void update(int rt, int l, int r, int al, int ar, long long val) {     if (l > ar || r < al) return;     if (l >= al && r <= ar) {       minn[rt] -= val;       minn[rt] = max(minn[rt], 0ll);       lazy[rt] += val;       return;     }     int mid = (l + r) >> 1;     if (lazy[rt]) push_down(rt);     update(rt << 1, l, mid, al, ar, val);     update(rt << 1 | 1, mid + 1, r, al, ar, val);     Push_up(rt);   }   pair<long long, int> query(int rt, int l, int r, int al, int ar) {     if (l > ar || r < al) return make_pair(inf, maxn + 1);     if (l >= al && r <= ar) return tree[rt];     int mid = (l + r) >> 1;     return min(query(rt << 1, l, mid, al, ar),                query(rt << 1 | 1, mid + 1, r, al, ar));   }   pair<long long, int> query(int rt, int l, int r) {     int mid = (l + r) >> 1;     if (l == r) return make_pair(minn[rt], l);     if (lazy[rt]) push_down(rt);     if (minn[rt << 1] <= minn[rt << 1 | 1]) return query(rt << 1, l, mid);     return query(rt << 1 | 1, mid + 1, r);   }   void upd(int rt, int l, int r, int pos, long long val) {     if (l > pos || r < pos) return;     if (l == r) {       minn[rt] = val;       return;     }     int mid = (l + r) >> 1;     if (lazy[rt]) push_down(rt);     upd(rt << 1, l, mid, pos, val);     upd(rt << 1 | 1, mid + 1, r, pos, val);     Push_up(rt);   }   int main() {     int n;     long long p;     cin >> n >> p;     build(1, 1, n);     for (int i = 1; i <= 4 * n; i++) minn[i] = inf, lazy[i] = 0;     for (int i = 1; i <= n; i++) {       long long x;       cin >> x;       update(1, 1, n, i, x);       upd(1, 1, n, i, x);     }     int out = 0;     queue<int> q;     set<int> s;     long long Pas = 0;     long long res = p;     while (out < n) {       if (q.empty()) {         pair<long long, int> pi = query(1, 1, n);         Pas += pi.first;         update(1, 1, n, 1, n, pi.first);         s.insert(pi.second);         q.push(pi.second);         upd(1, 1, n, pi.second, inf);       } else {         int lef = *s.begin();         if (lef == 1) {           Pas += p;           res = p;           update(1, 1, n, 1, n, p);           ans[q.front()] = Pas;           update(1, 1, n, q.front(), inf);           s.erase(q.front());           q.pop();           out++;         } else {           pair<long long, int> pi = query(1, 1, n, 1, lef - 1);           if (Pas + res > pi.first) {             res -= pi.first - Pas;             q.push(pi.second);             upd(1, 1, n, pi.second, inf);             s.insert(pi.second);           } else {             Pas += p;             res = p;             update(1, 1, n, 1, n, p);             ans[q.front()] = Pas;             update(1, 1, n, q.front(), inf);             s.erase(q.front());             q.pop();             out++;           }         }       }     }     for (int i = 1; i <= n; i++) cout << ans[i] <<    ;   }