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 Rust (1.15.1) (judge verdict: Accepted)

use std::io::Write;

fn run() {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    let mut it = s.trim().split_whitespace();
    let n: usize = it.next().unwrap().parse().unwrap();
    let k: usize = it.next().unwrap().parse().unwrap();
    let mut l = 0;
    let mut r = 0;
    for i in 0..n {
        l += (k + i) + (k + n + i);
        r += k + 2 * n + i;
    }
    if l > r {
        println!("-1");
        return;
    }
    assert!(2 * k <= n + 1);
    let mut ans = vec![];
    let mut i = n / 2;
    let mut p = 3 * n - 1;
    let mut q = 2 * n - 1;
    while i < n {
        ans.push((k + i, k + q, k + p));
        p -= 1;
        q -= 2;
        i += 1;
    }
    let mut x = 0;
    let mut y = 2 * n - 2;
    while p >= 2 * n {
        ans.push((k + x, k + y, k + p));
        p -= 1;
        y -= 2;
        x += 1;
    }
    let out = std::io::stdout();
    let mut out = std::io::BufWriter::new(out.lock());
    for (a, b, c) in ans {
        writeln!(out, "{} {} {}", a, b, c).ok();
    }
}

fn main() {
    run();
}