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<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define F first
#define S second
#define pii pair<int, int>
#define eb emplace_back
#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep3(i, l, n) for (int i = l; i < (n); ++i)
#define sz(v) (int)v.size()
#define inf (int)(1e9+7)
#define abs(x) (x >= 0 ? x : -(x))
#define ceil(a, b) a / b + !!(a % b)
template<typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { if (a > b) { a = b; return 1; } return 0; }
template<typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { if (a < b) { a = b; return 1; } return 0; }
template<typename T> T gcd(T a, T b) { if (b == 0) return a; return gcd(b, a % b); }



// youtube解説


int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    
    int n, k;
    cin >> n >> k;
    vector<pii> v(n);
    if (n % 2 == 0) {
        rep(i, n / 2) v[i * 2].F = i + 1;
        rep(i, n / 2) v[i * 2 + 1].F = n / 2 + i + 1;
        rep(i, n / 2) v[i * 2 + 1].S = n + i + 1;
        rep(i, n / 2) v[i * 2].S = n + n / 2 + i + 1;
        // rep(i, n) cout << v[i].F << " " << v[i].S << endl;
        vector<int> v2(n);
        rep(i, n) v2[i] = 2 * n + i + 1;
        rep(i, n) if (v[i].F + v[i].S > v2[i]) { cout << -1 << endl; return 0; }
        rep(i, n) { v[i].F += k - 1; v[i].S += k - 1; v2[i] += k - 1; }
        rep(i, n) cout << v[i].F << " " << v[i].S << " " << v2[i] << endl;
    } else {
        rep(i, n / 2 + 1) v[i * 2].F = i + 1;
        rep(i, n / 2) v[i * 2 + 1].F = n / 2 + i + 2;
        rep(i, n / 2) v[i * 2 + 1].S = n + i + 1;
        rep(i, n / 2 + 1) v[i * 2].S = n + n / 2 + i + 1;
        // rep(i, n) cout << v[i].F << " " << v[i].S << endl;
        vector<int> v2(n);
        rep(i, n) v2[i] = 2 * n + i + 1;
        rep(i, n) if (v[i].F + v[i].S > v2[i]) { cout << -1 << endl; return 0; }
        rep(i, n) { v[i].F += k - 1; v[i].S += k - 1; v2[i] += k - 1; }
        rep(i, n) cout << v[i].F << " " << v[i].S << " " << v2[i] << endl;
    }
}