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>
 
#define int long long
 
#define pii pair<int, int>
 
#define x1 x1228
#define y1 y1228
 
#define left left228
#define right right228
 
#define pb push_back
#define eb emplace_back
 
#define mp make_pair                                                                
                                                                                                                                        
#define ff first                                                                  
#define ss second   
 
#define matr vector<vector<int> > 
 
#define all(x) x.begin(), x.end()
 
 
using namespace std;
typedef long long ll; 
typedef long double ld; 
                                                                                                   
const int maxn = 3e5 + 7, mod = 998244353, MAXN = 1e6 + 7;
const double eps = 1e-9;
const ll inf = 1e18; 
mt19937 rnd(time(0));
int n, k; 
set<int> have; 
 
struct ANS {
    int a, b, c; 
    ANS(int a, int b, int c) : a(a), b(b), c(c) {}
    ANS() : a(0), b(0), c(0) {}
};
 
void solve() { 
    cin >> n >> k; 
    if (k > (n + 1) / 2) {
        cout << -1;
        return; 
    }
    int k1 = k;         
    k = (n + 1) / 2; 
    vector<int> ms;
    for (int i = 2 * n - k; i < 3 * n - k; ++i) {
        ms.pb(i); 
    }
    int cur = n; 
    set<int> kek; 
    for (int i = 0; i < n; ++i) {
        kek.insert(i); 
    }
    vector<ANS> ans;
    bool fl = true; 
    for (int i = 0; i < ms.size(); i += 2) {
        int add = ms[i] - cur;  
        auto t = kek.upper_bound(add);
        if (t == kek.begin()) {
            fl = false; 
            break; 
        }
        --t; 
        add = *t; 
        kek.erase(t);  
        ans.eb(add + k + (k1 - k), cur + k + (k1 - k), ms[i] + k + k + (k1 - k)); 
        ++cur; 
    }
    for (int i = 0; i < ms.size(); i += 2) {
        int add = ms[i] - cur;  
        auto t = kek.upper_bound(add);
        if (t == kek.begin()) {
            fl = false; 
            break; 
        }
        --t; 
        add = *t; 
        kek.erase(t);  
        ans.eb(add + k + (k1 - k), cur + k + (k1 - k), ms[i] + k + k + (k1 - k)); 
        ++cur; 
    }
    for (auto v : ans) cout << v.a << " " << v.b << " " << v.c << '\n';
/*    ans.clear();
    set<int> kek; 
    for (int i = 0; i < n; ++i) {
        kek.inert(i); 
    }
    cur = n; 
    for (int i = 1; i < ms.size(); i += 2) {
        int add = ms[i] - cur + k; 
        ans.eb(ms[i] - cur + k + (k1 - k), cur + k + (k1 - k), ms[i] + k + k + (k1 - k)); 
        ++cur; 
    }
    for (int i = 0; i < ms.size(); i += 2) {
        ans.eb(ms[i] - cur + k + (k1 - k), cur + k + (k1 - k), ms[i] + k + k + (k1 - k)); 
        ++cur;                         
    }
    for (auto v : ans) cout << v.a << " " << v.b << " " << v.c << '\n';*/
}   

signed main() {
#ifdef LOCAL
    freopen("TASK.in", "r", stdin);
    freopen("TASK.out", "w", stdout);
#else 
    
#endif // LOCAL
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.precision(20); 
    cout << fixed; 
    int t = 1; 
    for (int i = 0; i < t; ++i) {              
        solve();
    }
    return 0;
}