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# (Mono 4.6.2.0) (judge verdict: Wrong Answer)

using System;
using System.IO;
using System.Linq;
using System.Numerics;
using System.Collections.Generic;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using System.Diagnostics;
using static System.Math;
using MethodImplAttribute = System.Runtime.CompilerServices.MethodImplAttribute;
using MethodImplOptions = System.Runtime.CompilerServices.MethodImplOptions;

public static class P
{
    public static void Main()
    {
        var nk = Console.ReadLine().Split().Select(int.Parse).ToArray();
        int n = nk[0];
        long k = nk[1];
        var cands = Enumerable.Range((int)k, 3 * n).Select(x => (long)x).ToArray();
        var prevSum = cands.Take(n * 2).Sum();
        var afterSum = cands.Skip(n * 2).Sum();
        //2k <= n + 1であれば合法
        if (prevSum > afterSum)
        {
            Console.WriteLine(-1);
            return;
        }
        var mother = cands.Skip(n).Take(n).ToArray();
        var res = mother.Where(x => x % 2 == 1).Concat(mother.Where(x => x % 2 == 0))
            .Zip(cands.Skip(n * 2).Zip(cands.Take(n / 2).Reverse().Concat(cands.Take(n).Skip(n / 2).Reverse()), 
            (x, y) => new Tuple<long, long>(x, y)), (x, y) => new Tuple<long, long, long>(y.Item2, x, y.Item1)).ToArray();
        Console.WriteLine(string.Join("\n", res.Select(x => $"{x.Item1} {x.Item2} {x.Item3}")));
    }
}