Problem:
Score : 700 points

Problem Statement

Given are positive integers N and K.

Determine if the 3N integers K, K+1, ..., K+3N-1 can be partitioned into N triples (a_1,b_1,c_1), ..., (a_N,b_N,c_N) so that the condition below is satisfied. Any of the integers K, K+1, ..., K+3N-1 must appear in exactly one of those triples.

For every integer i from 1 to N, a_i + b_i \leq c_i holds.

If the answer is yes, construct one such partition.

Constraints

1 \leq N \leq 10^5

1 \leq K \leq 10^9

Input

Input is given from Standard Input in the following format:

N K

Output

If it is impossible to partition the integers satisfying the condition, print -1. If it is possible, print N triples in the following format:

a_1 b_1 c_1
:
a_N b_N c_N

Sample Input 1

1 1

Sample Output 1

1 2 3

Sample Input 2

3 3

Sample Output 2

-1

Solution in C++14 (GCC 5.4.1) (judge verdict: Wrong Answer)

#include <algorithm>
#include <iostream>
#include <vector>
#include <math.h>
#include <set>
#include <map>
#include <string>
#include <stack>
#include <queue>
#include <iomanip>
#include <numeric>
#include <tuple>
#include <bitset>
#include <complex>
#include <unistd.h>
#include <cassert>
#include <cctype>
#include <random>
#include <time.h>
#define _USE_MATH_DEFINES
#define _GLIBCXX_DEBUG
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> plglg;
typedef pair<double, ll> pdlg;
typedef tuple<int, int, int> tiii;
typedef tuple<ll, ll, ll> tlglglg;
typedef tuple<double, double, double> tddd;
typedef complex<double> xy_t;
typedef vector<ll> vll;
typedef vector< vector<ll> > matrix;
#define REP(i, x, y) for(ll i = (ll)x; i < (ll)y; i++)
#define DREP(i, x, y, d) for(ll i = (ll)x; i < (ll)y; i += (ll)d)
#define PER(i, x, y) for(ll i = (ll)x; i > (ll)y; i--)
#define DPER(i, x, y, d) for(ll i = (ll)x; i > (ll)y; i -= (ll)d)
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
double pi = 3.141592653589793;
ll mod = 1000000007;
int intmax = 2147483647;
int intmin = -2147483648;
ll llmax = 9223372036854775807;
ll llmin = -9223372036854775807;
int iinf = intmax / 8;
ll inf = llmax / 8;
double eps = 1e-12;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N, K;
    cin >> N >> K;
    ll a = K;
    ll b = K + N;
    ll c = K + 2 * N;
    ll d = K + 3 * N;
    ll p = a + c - 1;
    if (a + b > c) {
        cout << -1 << endl;
        return 0;
    }
    if (p <= c) {
        REP(i, 0, N) {
            cout << a + i << " " << c - 1 - i << " " << c + i << endl;
        }
        return 0;
    }
    ll leftbtm = a;
    ll rightbtm = b;
    tlglglg ans[N];
    ll ansnum = 0;
    ll rnum = c - leftbtm;
    ansnum += rnum - rightbtm;
    ll lnum = c + 1 - rightbtm;
    ansnum += lnum - leftbtm;
    if (ansnum >= N) {
        ll fnum = c - (c - leftbtm);
        ll lmid = leftbtm + fnum;
        ll snum = N - fnum;
        ll rmid = c - leftbtm;
        REP(i, 0, min(fnum, snum) * 2) {
            if (i % 2 == 0) {
                ans[i] = tlglglg(leftbtm + i / 2, rmid + i / 2, c + i);
            } else {
                ans[i] = tlglglg(rightbtm + i / 2, lmid + i / 2, c + i);
            }
        }
        ll p = min(fnum, snum);
        REP(i, 0, max(fnum, snum) - min(fnum, snum)) {
            if (fnum > snum) {
                ans[p * 2 + i] = tlglglg(leftbtm + p + i, rmid + p + i, c + p + i);
            } else {
                ans[p * 2 + i] = tlglglg(rightbtm + p + i, lmid + p + i, c + p + i);
            }
        }
        REP(i, 0, N) {
            cout << a + i << " " << c - 1 - i << " " << c + i << endl;
        }
    } else {
        cout << -1 << endl;
    }
}