#include <bits/stdc++.h>   using namespace std;   using namespace std;   vector<pair<int, int> > dp(101);   int cntr[101] = {0};   int getIndexes(int &a, int &b, int &c, int &i, int &m, int x, int &xc, int &k) {     int res1 = 0;     int res2 = 0;     int f1 = 0, f2 = 0, j;     if (cntr[x] == 0) {       for (j = xc - m / 2; j <= xc + m / 2 + m % 2 - 1; j++)         res1 = res1 + (j > xc ? j - xc : xc - j) + i;       a = x;       b = dp[x].first = xc - m / 2;       c = dp[x].second = xc + m / 2 + m % 2 - 1;       return res1;     } else {       if (dp[x].first <= m) {         f1 = 1;         res1 = (1000 * 1000 * 1000 + 5);       } else {         for (j = dp[x].first - 1; j >= dp[x].first - m && j >= 1; j--)           res1 = res1 + (j > xc ? j - xc : xc - j) + i;       }       if (k - dp[x].second < m) {         f2 = 1;         res2 = (1000 * 1000 * 1000 + 5);       } else {         for (j = dp[x].second + 1; j <= dp[x].second + m && j <= k; j++)           res2 = res2 + (j > xc ? j - xc : xc - j) + i;       }       if (f1 == 1 && f2 == 1) return (1000 * 1000 * 1000 + 5);       if (res1 <= res2) {         a = x;         b = dp[x].first - m;         c = dp[x].first - 1;         return res1;       } else {         a = x;         b = dp[x].second + 1;         c = dp[x].second + m;         return res2;       }     }   }   int main() {     int n, k;     cin >> n >> k;     int xc = k / 2 + 1;     int yc = xc;     cntr[xc] = 0;     while (n--) {       int m, i;       cin >> m;       if (m > k) {         cout <<  -1  << endl;       } else {         int x, yl, yr;         int mfv = (1000 * 1000 * 1000 + 5);         for (i = 0; i < xc; i++) {           int a, b, c;           int mfu = (1000 * 1000 * 1000 + 5);           int mfd = (1000 * 1000 * 1000 + 5);           mfu = getIndexes(a, b, c, i, m, xc - i, xc, k);           if (mfv >= mfu) {             mfv = mfu;             x = a;             yl = b;             yr = c;           }           mfd = getIndexes(a, b, c, i, m, xc + i, xc, k);           if (mfv > mfd) {             mfv = mfd;             x = a;             yl = b;             yr = c;           }           if (cntr[xc - i] == 0 || cntr[xc + i] == 0) break;         }         if (mfv < (1000 * 1000 * 1000 + 5)) {           if (dp[x].first > yl || dp[x].first == 0) dp[x].first = yl;           if (dp[x].second < yr || dp[x].second == 0) dp[x].second = yr;           if (cntr[x] != 1) cntr[x] = 1;           cout << x <<     << yl <<     << yr << endl;         } else           cout <<  -1  << endl;       }     }     return 0;   }   