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: Wrong Answer)

#![allow(non_snake_case, unused)]
use std::collections::*;

////////// missing functions in 1.15.1 //////////
macro_rules! eprint {
	($($t:tt)*) => {{
		use ::std::io::Write;
		let _ = write!(::std::io::stderr(), $($t)*);
	}};
}
macro_rules! eprintln {
	() => { eprintln!(""); };
	($($t:tt)*) => {{
		use ::std::io::Write;
		let _ = writeln!(::std::io::stderr(), $($t)*);
	}};
}
macro_rules! dbg {
	($v:expr) => {{
		let val = $v;
		eprintln!("[{}:{}] {} = {:?}", file!(), line!(), stringify!($v), val);
		val
	}}
}
/////////////////////////////////////////////////
pub trait SetMinMax {
	fn setmin(&mut self, v: Self) -> bool;
	fn setmax(&mut self, v: Self) -> bool;
}
impl<T> SetMinMax for T where T: PartialOrd {
	fn setmin(&mut self, v: T) -> bool {
		*self > v && { *self = v; true }
	}
	fn setmax(&mut self, v: T) -> bool {
		*self < v && { *self = v; true }
	}
}

macro_rules! mat {
	($($e:expr),*) => { Vec::from(vec![$($e),*]) };
	($($e:expr,)*) => { Vec::from(vec![$($e),*]) };
	($e:expr; $d:expr) => { Vec::from(vec![$e; $d]) };
	($e:expr; $d:expr $(; $ds:expr)+) => { Vec::from(vec![mat![$e $(; $ds)*]; $d]) };
}

macro_rules! ok {
	($a:ident$([$i:expr])*.$f:ident()$(@$t:ident)*) => {
		$a$([$i])*.$f($($t),*)
	};
	($a:ident$([$i:expr])*.$f:ident($e:expr$(,$es:expr)*)$(@$t:ident)*) => { {
		let t = $e;
		ok!($a$([$i])*.$f($($es),*)$(@$t)*@t)
	} };
}

pub fn readln() -> String {
	let mut line = String::new();
	::std::io::stdin().read_line(&mut line).unwrap_or_else(|e| panic!("{}", e));
	line
}

macro_rules! read {
	($($t:tt),*; $n:expr) => {{
		let stdin = ::std::io::stdin();
		let ret = ::std::io::BufRead::lines(stdin.lock()).take($n).map(|line| {
			let line = line.unwrap();
			let mut it = line.split_whitespace();
			_read!(it; $($t),*)
		}).collect::<Vec<_>>();
		ret
	}};
	($($t:tt),*) => {{
		let line = readln();
		let mut it = line.split_whitespace();
		_read!(it; $($t),*)
	}};
}

macro_rules! _read {
	($it:ident; [char]) => {
		_read!($it; String).chars().collect::<Vec<_>>()
	};
	($it:ident; [u8]) => {
		Vec::from(_read!($it; String).into_bytes())
	};
	($it:ident; usize1) => {
		$it.next().unwrap_or_else(|| panic!("input mismatch")).parse::<usize>().unwrap_or_else(|e| panic!("{}", e)) - 1
	};
	($it:ident; [usize1]) => {
		$it.map(|s| s.parse::<usize>().unwrap_or_else(|e| panic!("{}", e)) - 1).collect::<Vec<_>>()
	};
	($it:ident; [$t:ty]) => {
		$it.map(|s| s.parse::<$t>().unwrap_or_else(|e| panic!("{}", e))).collect::<Vec<_>>()
	};
	($it:ident; $t:ty) => {
		$it.next().unwrap_or_else(|| panic!("input mismatch")).parse::<$t>().unwrap_or_else(|e| panic!("{}", e))
	};
	($it:ident; $($t:tt),+) => {
		($(_read!($it; $t)),*)
	};
}

pub fn main() {
	let _ = ::std::thread::Builder::new().name("run".to_string()).stack_size(32 * 1024 * 1024).spawn(run).unwrap().join();
}

use std::ops::*;

#[derive(Clone, Debug)]
pub struct BIT<T> {
	vs: Vec<T>
}

impl<T> BIT<T> where T: Clone + Default + AddAssign {
	pub fn new(n: usize) -> BIT<T> {
		BIT { vs: vec![T::default(); n + 1] }
	}
	/// v[k] += a
	pub fn add(&mut self, k: usize, a: T) {
		let mut i = k + 1;
		while i < self.vs.len() {
			self.vs[i] += a.clone();
			i += i & i.wrapping_neg();
		}
	}
	/// v[0]+v[1]+...+v[t-1]
	pub fn sum(&self, t: usize) -> T {
		let mut res = T::default();
		let mut i = t;
		while i > 0 {
			res += self.vs[i].clone();
			i -= i & i.wrapping_neg();
		}
		res
	}
}

impl<T> BIT<T> where T: Clone + SubAssign + PartialOrd {
	/// argmin_i v[0]+...+v[i]>a, v[i] must be non-negative
	pub fn get(&self, mut a: T) -> usize {
		let mut p = self.vs.len().next_power_of_two() >> 1;
		let mut q = p;
		while q > 0 {
			if p >= self.vs.len() || a < self.vs[p] { p ^= q; }
			else { a -= self.vs[p].clone(); }
			q >>= 1;
			p |= q;
		}
		p
	}
}

fn run() {
	let (N, K) = read!(usize, usize);
	let mut bit = BIT::new(2 * N);
	for i in 0..2 * N {
		bit.add(i, 1);
	}
	let mut ret = vec![];
	for i in (2 * N..3 * N).rev() {
		let h = bit.get(bit.sum(2 * N) - 1);
		if K + h > i {
			println!("-1");
			return;
		}
		bit.add(h, -1);
		let mut a = i - K - h;
		a.setmin(2 * N - 1);
		let b = bit.sum(a + 1);
		if b == 0 {
			println!("-1");
			return;
		}
		let j = bit.get(b - 1);
		bit.add(j, -1);
		ret.push((K + j, K + h, K + i));
	}
	for (a, b, c) in ret {
		println!("{} {} {}", a, b, c);
	}
}