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)

/*

0 1 2 3 4 5

0 5
1 3
2 4

01234567

0..2n-1
n(2n-1 + 2k)

2n..3n-1
n((5n-1)/2 + k)


k <= (n+1)/2

n=3
k=2

234 567 8910

n=5
k=3
3 4 5 6 7 8 9 10 11 12 / 13 14 15 16 17


17, 12 5
16, 9 7
15, 11 4
14, 8 6
13, 10 3
 
*/
// use std::cmp;
// use std::collections::HashMap;
// use std::collections::HashSet;
// use std::collections::VecDeque;
// use std::collections::BTreeSet;


// const INF: i64 = 1_000_000_000;
// const MOD: i64 = 998244353;

fn main() {
    let cin = stdin();
    let mut sc = Scanner::new(cin.lock());
    let n: i64 = sc.read();
    let k: i64 = sc.read();
    if 2 * k > n + 1 {
        println!("{}", -1);
    } else {
        for i in 0..n {
            let c = 2*n + i;
            let (a, b) = if i % 2 == 0 {
                (i/2, n + n/2 + i/2)
            } else {
                (n - n/2 + i/2, n + i/2)
            };
            println!("{} {} {}", k+a, k+b, k+c);
        }
    }
}

// thanks, ir5
use std::io::{stdin, Read, StdinLock};
use std::str::FromStr;

struct Scanner<'a> {
    cin: StdinLock<'a>,
}

impl<'a> Scanner<'a> {
    fn new(cin: StdinLock<'a>) -> Scanner<'a> {
        Scanner { cin: cin }
    }

    fn read1<T: FromStr>(&mut self) -> Option<T> {
        let token = self.cin
            .by_ref()
            .bytes()
            .map(|c| c.unwrap() as char)
            .skip_while(|c| c.is_whitespace())
            .take_while(|c| !c.is_whitespace())
            .collect::<String>();
        token.parse::<T>().ok()
    }

    fn read<T: FromStr>(&mut self) -> T {
        self.read1().unwrap()
    }
}