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 Java8 (OpenJDK 1.8.0) (judge verdict: Runtime Error)

import java.io.PrintWriter;
import java.util.Arrays;
import java.util.Scanner;
import java.util.TreeSet;

public class Main {

    static Scanner sc = new Scanner(System.in);

    public static void main(String[] args) {
        int N = sc.nextInt();
        int K = sc.nextInt();
        if (N + 1 < 2 * K) {
            System.out.println(-1);
            return;
        }
        PrintWriter writer = new PrintWriter(System.out);
//        int[] lo = new int[N];
//        int[] hi = new int[N];
//        for (int i = 0; i < N; i++) {
//            lo[i] = i;
//            hi[i] = N + i;
//        }
//        for (int i = 0; i < N / 2 / 2; i++) {
//            int tmp = lo[i];
//            lo[i] = lo[(N - 1) / 2 - i];
//            lo[(N - 1) / 2 - i] = tmp;
//            tmp = lo[N - 1 - i];
//            lo[N - 1 - i] = lo[(N + 1) / 2 + i];
//            lo[(N + 1) / 2 + i] = tmp;
//        }
//        for (int i = 0; i < N / 2; i++) {
//            int tmp = hi[i];
//            hi[i] = hi[N / 2 + i];
//            hi[N / 2 + i] = tmp;
//        }
//        for (int i = 0; i < N; i++) {
//            writer.printf("%d %d %d\n", lo[i] + K, hi[i] + K, 2 * N + K + i);
//        }

        TreeSet<Integer> min = new TreeSet<>();
        TreeSet<Integer> max = new TreeSet<>();
        for (int i = 0; i < N; i++) {
            min.add(K + i);
            max.add(N + K + i);
        }
        for (int i = 0; i < N; i++) {
            int sum = 2 * N + K + i;
            int lo = min.last();
            int hi = max.first();
//            System.err.println(max + " " + target + " " + mf);
            if (hi + lo > sum) {
                lo = min.lower(sum - hi + 1);
                min.remove(lo);
                hi = max.lower(sum - lo + 1);
                max.remove(hi);
                writer.printf("%d %d %d\n", lo, hi, sum);
            } else {
                hi = max.lower(sum - lo + 1);
                max.remove(hi);
                lo = min.lower(sum - hi + 1);
                min.remove(lo);
                writer.printf("%d %d %d\n", lo, hi, sum);
            }
        }
        writer.flush();
    }

}