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 (Python):
import sys
def MI(): return map(int,sys.stdin.readline().rstrip().split())


N,K = MI()

if N-2*K+1 < 0:
    print(-1)
    exit()

ANS = [[0]*3 for _ in range(N)]
for i in range(K+2*N,K+3*N):
    ANS[i-(K+2*N)][2] = i

if N % 2 == 0:
    for i in range(N//2):
        ANS[2*i][0] = K+i
        ANS[2*i][1] = K+N+(N//2)+i
        ANS[2*i+1][0] = K+(N//2)+i
        ANS[2*i+1][1] = K+N+i

else:
    for i in range(N//2):
        ANS[2*i][0] = K+i
        ANS[2*i][1] = K+N+(N//2)+i
        ANS[2*i+1][0] = K+(N//2)+1+i
        ANS[2*i+1][1] = K+N+i
    ANS[-1][0] = K+(N//2)
    ANS[-1][1] = K+(2*N-1)

for i in range(N):
    a,b,c = ANS[i]
    print(a,b,c)

Solution (Python):
import sys

sys.setrecursionlimit(10**7)
def I(): return int(sys.stdin.readline().rstrip())
def MI(): return map(int,sys.stdin.readline().rstrip().split())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))  
def LI2(): return list(map(int,sys.stdin.readline().rstrip()))  
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())  
def LS2(): return list(sys.stdin.readline().rstrip())  


N,K = MI()

if N-2*K+1 < 0:
    print(-1)
    exit()

ANS = [[0]*3 for _ in range(N)]
for i in range(K+2*N,K+3*N):
    ANS[i-(K+2*N)][2] = i

if N % 2 == 0:
    for i in range(N//2):
        ANS[2*i][0] = K+i
        ANS[2*i][1] = K+N+(N//2)+i
        ANS[2*i+1][0] = K+(N//2)+i
        ANS[2*i+1][1] = K+N+i

else:
    for i in range(N//2):
        ANS[2 * i][0] = K + i
        ANS[2 * i][1] = K + N + (N // 2) + i
        ANS[2 * i + 1][0] = K + (N // 2) + 1 + i
        ANS[2 * i + 1][1] = K + N + i
    ANS[-1][0] = K+(N//2)
    ANS[-1][1] = K+(2*N-1)

for i in range(N):
    a,b,c = ANS[i]
    print(a,b,c)

Solution (Python):
n, k = map(int, input().split())
if 2 * k > n + 1:
    exit(print(-1))
else:
    if n % 2 == 0:
        for i in range(n):
            if i % 2 == 0:
                print(k + i // 2, k + (i + n * 3) // 2, k + i + n * 2)
            else:
                print(k + i // 2 + n // 2, k + i // 2 + n, k + i + n * 2)
    else:
        for i in range(n):
            if i % 2 == 0:
                print(k + i // 2, k + (i + n * 3) // 2, k + i + n * 2)
            else:
                print(k + i // 2 + n // 2 + 1, k + i // 2 + n, k + i + n * 2)

Solution (Python):
n,k = map(int,input().split())

ab = []
for i in range(1,n+1):
    a,b=0,0
    if(n%2==1):
        if(i%2==1):
            a,b = i, n + 1 + (n-i)//2
        else:
            a,b = i, 2*n - (i-2)//2
    elif(n%2==0):
        if(i%2==0):
            a,b = i, n + 1 + (n-i)//2
        else:
            a,b = i, 2*n - i//2
    a += k-1
    b += k-1
    ab.append((a+b,a,b))

ab.sort()

ans = []
for i in range(n):
    c = k+2*n+i
    tot,a,b = ab[i]
    if(tot > c):
        print(-1)
        exit()
    ans.append((a,b,c))

print('\n'.join(map(lambda x: ' '.join(map(str,x)), ans) ))

Solution (Python):
n, k = map(int, input().split())
s = 0
for i in range(k, k + 2 * n):
    s -= i
for i in range(k + 2 * n, k + 3 * n):
    s += i
if s >= 0:
    a = [0] * n
    b = list(range(k + n, k + 2 * n))
    c = [0] * n
    for i in range(n // 2):
        c[i * 2 + 1] = k + 2 * n + i
    for i in range(n - n // 2):
        c[i * 2] = k + 2 * n + n // 2 + i
    for i in range(n // 2):
        a[i * 2 + 1] = k + n // 2 - i - 1
    for i in range(n - n // 2):
        a[i * 2] = k + n - i - 1
    for i in range(n):
        print(a[i], b[i], c[i])
else:
    print(-1)

Solution (Python):
N,K=map(int,input().split())
if K>(N+1)//2:
    print(-1)
else:
    used={i:False for i in range(K+2*N,K+3*N)}
    ans=[]
    for i in range(K):
        print(K+i,2*N+i,2*N+K+2*i)
        ans.append((K+i,2*N+i,2*N+K+2*i))
        used[2*N+K+2*i]=True

    pos=2*N+K+1
    count=0
    while N-K>count:
        if not used[pos]:
            print(2*K+count,2*K+count+N-K,pos)
            ans.append((2*K+count,2*K+count+N-K,pos))
            used[pos]=True
            count+=1
            pos+=1
        else:
            pos+=1

Solution (Python):
n, k = map(int, input().split())

if 2*k-1 > n:
    print(-1)
    exit()

l = (n+1)//2

if n % 2 != 0:
    a = []
    b = []
    c = []
    for x in range(k, k+2*l-2+1,2):
        a.append(x)
    for x in range(k+1, k+2*l-2, 2):
        a.append(x)

    for x in range(k+3*l-2, k+2*l-2, -1):
        b.append(x)
    for x in range(k+4*l-3, k+3*l-2, -1):
        b.append(x)

    for x in range(k+4*l-2, k+6*l-3):
        c.append(x)
    for i in range(n):
        print(a[i], b[i], c[i])
else:
    a = []
    b = []
    c = []
    for x in range(k, k+2*l-2+1, 2):
        a.append(x)
    for x in range(k+1, k+2*l, 2):
        a.append(x)

    for x in range(k+3*l-1, k+2*l-1, -1):
        b.append(x)
    for x in range(k+4*l-1, k+3*l-1, -1):
        b.append(x)

    for x in range(k+4*l, k+6*l):
        c.append(x)
    for i in range(n):
        print(a[i], b[i], c[i])

Solution (Python):
n,k=map(int,input().split())
if n*(2*k+2*n-1)<=k*n+(5*n**2-n)//2 and k-1<=n//2:
  pair=[[k+i,k+2*n-1-i] for i in range(n)]
  checked=[0]*(n)
  diff=k-1
  cnt=0
  for i in range(n):
    if checked[i]==0 and checked[i+diff]==0:
      checked[i]=1
      checked[i+diff]=1
      pair[i][0],pair[i+diff][0]=pair[i+diff][0],pair[i][0]
      cnt+=1
      if cnt==k-1:
        break
      diff-=2
      if diff<=0:
        diff=k-2
  ans=[]
  cand=set(range(k+2*n,k+3*n))
  checked=[0]*(n)
  for i in range(n):
    a,b=pair[i]
    if a+b!=2*k+2*n-1:
      checked[i]=1
      ans.append([a,b,a+b])
      cand.discard(a+b)
  for i in range(n):
    if checked[i]==0:
      a,b=pair[i]
      ans.append([a,b,cand.pop()])
  for a,b,c in ans:
    print(a,b,c)
else:
  print(-1)

Solution (Python):
n,k=map(int,input().split())
sum1=sum(range(k,k+2*n))
sum2=sum(range(k+2*n,k+3*n))
if sum1<=sum2 and k-1<=n//2:
  arr1=set([k+i for i in range(n)])
  arr2=set([k+n+i for i in range(n)])
  ans1=[]
  for i in range(k-1):
    ans1.append([k+i,k+2*n-2-2*i,2*k+2*n-2-i])
    arr1.discard(k+i)
    arr2.discard(k+2*n-2-2*i)
  arr1=list(arr1)
  arr2=list(arr2)
  arr2=sorted(arr2,reverse=True)
  ans2=[]
  for i in range(n-(k-1)):
    ans2.append([arr1[i],arr2[i],arr1[i]+arr2[i]])
  ans2=sorted(ans2,key=lambda x:x[2])
  for i in range(1,n-(k-1)):
    if ans2[i][2]<=ans2[i-1][2]:
      ans2[i][2]=ans2[i-1][2]+1
  ans=ans1+ans2
  for a,b,c in ans:
    print(a,b,c)
else:
  print(-1)

Solution (Python):
n,k=map(int,input().split())
if 2*k-1>n:
  print(-1)
  exit()
for i in range(1,n+1):
  if i<=n//2:
    b=2*n+k-i*2
    c=2*n+k+n//2-i
  else:
    b=2*n+k+1-(i-n//2)*2
    c=k+3*n-(i-n//2)
  print(k+i-1,b,c)

Solution (Python):
def examA():
    N = I()
    ans = (N-1)//2
    print(ans)
    return

def examB():
    N = I()
    D = LI()
    d = Counter(D)
    loop = max(d.keys())
    if D[0]!=0 or d[0]!=1:
        print(0)
        return

    ans = 1; cur = 1
    for i in range(loop+1):
        if d[i]==0:
            print(0)
            return
        for _ in range(d[i]):
            ans *= cur
            ans %= mod2
        cur = d[i]
    print(ans)
    return

def examC():
    class UnionFind():
        def __init__(self, n):
            self.parent = [-1 for _ in range(n)]
            

        def find(self, x):
            
            if self.parent[x] < 0:
                return x
            else:
                self.parent[x] = self.find(self.parent[x])
                return self.parent[x]

        def unite(self, x, y):
            
            x, y = self.find(x), self.find(y)
            if x == y:
                return False
            else:
                if self.size(x) < self.size(y):
                    x, y = y, x
                self.parent[x] += self.parent[y]
                self.parent[y] = x

        def same(self, x, y):
            
            return self.find(x) == self.find(y)

        def size(self, x):
            
            x = self.find(x)
            return -self.parent[x]

        def is_root(self, x):
            
            return self.parent[x] < 0

        def members(self, x):
            
            root = self.find(x)
            return [i for i in range(self.n) if self.find(i) == root]

        def group_count(self):
            
            return len(self.roots())

        def all_group_members(self):
            
            return {r: self.members(r) for r in self.roots()}
    N = I()
    A = LI()
    B = LI()
    indices = [i for i in range(len(B))]
    sorted_indices = sorted(indices, key=lambda i: B[i])
    sorted_B = [B[i] for i in sorted_indices]
    sorted_A = sorted(A)

    d = defaultdict(int)

    for i in range(N):
        d[sorted_A[i]] = sorted_B[i]
        if sorted_A[i]>sorted_B[i]:
            print("No")
            return
    for i in range(N-1):
        if sorted_A[i+1]<=sorted_B[i]:
            print("Yes")
            return
    uf = UnionFind(N)
    indices_A = [i for i in range(len(A))]
    sorted_indices_A = sorted(indices_A, key=lambda i: A[i])
    for i in range(N):
        uf.unite(sorted_indices[i],sorted_indices_A[i])
    if uf.size(0)<N:
        print("Yes")
        return
    print("No")
    return

def examD():
    class Dijkstra(object):
        """
        construct: O(ElogV)
        """

        def __init__(self, edges, start=0):
            """
            :param list of list of list of int edges:
            :param int start=0:
            """
            self.__dist = [inf] * len(edges)
            self.__dist[start] = 0
            self.__calculate(edges, start)

        @property
        def dist(self):
            return self.__dist

        def __calculate(self, edges, start):
            Q = [(0, start)]  
            while (Q):
                dist, v = heapq.heappop(Q)
                if self.dist[v] < dist: continue  
                for u, cost in edges[v]:
                    if self.dist[u] > self.dist[v] + cost:
                        self.__dist[u] = self.dist[v] + cost
                        heapq.heappush(Q, (self.dist[u], u))
    N, M = LI()
    V = [[]for _ in range(N)]
    for _ in range(M):
        l, r, c = LI()
        l -=1; r -=1
        V[l].append((r,c))
    for i in range(N-1):
        V[i+1].append((i,0))

    D = Dijkstra(V)
    ans = D.dist[N-1]
    if ans==inf:
        ans = -1
    print(ans)
    return

def examE():
    N, K = LI()
    ans = [[]for _ in range(N)]
    A1 = [K+i for i in range(N)]
    A2 = [K+N+i for i in range(N)]
    A3 = [K+2*N+i for i in range(N)]
    for i in range(N):
        a = A1[-((N+1)//2)+i]
        if N%2==1 or i<N//2:
            b = A2[N-1-2*i]
        else:
            b = A2[N- 2 * i-2]
        c = A3[-1-i]
        if a+b>c:
            print(-1)
            return
        ans[i] = [a,b,c]
    for v in ans:
        print(" ".join(map(str,v)))
    return

def examF():
    ans = 0
    print(ans)
    return

import sys,copy,bisect,itertools,heapq,math
from heapq import heappop,heappush,heapify
from collections import Counter,defaultdict,deque
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
def LFI(): return list(map(float,sys.stdin.readline().split()))
def LSI(): return list(map(str,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def SI(): return sys.stdin.readline().strip()
global mod,mod2,inf,alphabet
mod = 10**9 + 7
mod2 = 998244353
inf = 10**18
alphabet = [chr(ord('a') + i) for i in range(26)]

if __name__ == '__main__':
    examE()

"""

"""

Solution (Python):
n, k = map(int, input().split())
if n < 2*k-1:
  print(-1)
else:
  A1 = [k+i for i in range(n)]
  A2 = [k+n+i for i in range(n)]
  A3 = [k+2*n+i for i in range(n)]
  l = (n+1)//2
  for i in range(l):
    print(A1[l-1-i], A2[i*2], A3[i])
  for i in range(n-l):
    print(A1[n-1-i], A2[i*2+1], A3[l+i])

Solution (Python):
N,K=map(int,input().split())
l=[0]*3*N
for i in range(3*N):
    z=(i//(2*N))*(3*((i%2)*(N//2-(i%N)//2-1)+(1-i%2)*(-(i%N)//2-N%2)))
    

    l[(i//N+3*(i%N)+(i//N)*3*((N+1)//2)+z)%(3*N)] = i+K
s=("{} "*3+"\n")*N
print(-1 if 2*K-1>N else s.format(*l))

Solution (Python):
N,K=map(int,input().split());print(-1 if 2*K-1>N else"\n".join("%d %d %d"%(((N+1)//2-k-1)%N+K,N+2*k%N+K+(2*k>=N)*(N+1)%2,2*N+k+K)for k in range(N)))

Solution (Python):
N, K = map(int, input().split())
for i in range(N):
    j = (N+(N+1)//2-i-1)%N
    k = N+(N+2*i)%N+(2*i>=N)*(N+1)%2
    if 2*K-1>N:
        print(-1)
        break
    print(j+K, k+K, 2*N+i+K)

Solution (Python):
N, K = map(int, input().split())
results = []
for i in range(N//2):
    results.append(((N+1)//2+i+1, 2*N-2*i-1, (N+1)//2+2*N-i))
for i in range((N+1)//2):
    results.append((i+1, 2*N-2*i, 2*N-i+1))
results = results[::-1]
for i, (x, y, z) in enumerate(results):
    if x+y+2*K-2 > 2*N+i+K:
        print(-1)
        break
    print(x + K - 1, y + K - 1, 2*N+i+K)

Solution (Python):
n, k = map(int, input().split())

if 2 * k - 1 > n:
  print(-1)
else:
  half_n = n // 2
  if n % 2 == 0:
    for i in range(half_n):
      a = k + i
      b = k + n + i + half_n
      c = k + 2 * n + 2 * i
      print(a, b, c)
      a += half_n
      b -= half_n
      c += 1
      print(a, b, c)
  else:
    for i in range(half_n):
      a = k + i
      b = k + n + i + half_n
      c = k + 2 * n + 2 * i
      print(a, b, c)
      a += half_n + 1
      b -= half_n
      c += 1
      print(a, b, c)
    a = k + half_n
    b = k + n + 2 * half_n
    c = k + 2 * n + 2 * half_n
    print(a, b, c)

Solution (Python):
n, k = map(int, input().split())

if 2 * k > n + 1:
    print(-1)
    exit(0)

ans = []
for i in range((n+1)//2):
    ans.append((k+i, k+n+i+n//2, k+2*n+2*i))
for i in range(n//2):
    ans.append((k+(n+1)//2+i, k+n+i, k+2*n+2*i+1))


for x in ans:
    print(*x)

Solution (Python):
n, k = map(int, input().split())
if 2*k > n+1:
	print(-1)
else:
	for i in range(n//2):
		print((2*k+n-2)//2 - i, k+n+1+2*i, k+2*n+i)
	for i in range(n-n//2):
		print(k+n-1-i, k+n+2*i, k+2*n+n//2+i)

Solution (Python):
import sys
input = sys.stdin.readline

n, k = [int(item) for item in input().split()]
if n - 2 * k + 1 < 0:
    print(-1)
    exit()
for i in range((n + 1) // 2):
    a = k + 2*i
    b = k + n + ((n+1) // 2) - 1 - i
    c = k + 2 * n + i
    print(a, b, c)
for i in range(n // 2):
    a = k + 1 + 2*i
    b = k + 2*n - 1 - i
    c = k + 2*n + ((n+1) // 2) + i
    print(a, b, c)

Solution (Python):
from operator import itemgetter


n, k = map(int, input().split())

li_a = [i+k for i in range(n)]
li_b = [i+k+n for i in range(n)]
li_c = [i+k+2*n for i in range(n)]
ans = []

for i in range(n):
   ans.append((li_a[n//2-i], li_b[n-1-i], li_a[n//2-i] + li_b[n-1-i]))
ans = sorted(ans, key = itemgetter(2))

res = []
for i in range(n):
    if ans[i][0] + ans[i][1] <= li_c[i]:
        res.append((ans[i][0], ans[i][1], li_c[i]))
    else:
        print(-1)
        break
else:
    for i in res:
        print(*i)

Solution (Python):
def gn(n,k):
    k -= 1
    r = k+2*n+n//2 - (1 + 2*k + 2*n)
    if r < 0:
        print(-1)
        return
    print(k+1, 2*n+k, 3*n+k)
    n-=1
    k+=1
    for i in range(1, n+1):
        x = i
        y = n+(i-((n+1)//2)+n)%n+1
        print(k+x, k+y, 2*k+x+y+r)
def kn(n,k):
    k -= 1
    r = k+2*n+(n+1)//2 - (1 + 2*k + 2*n)
    if r < 0:
        print(-1)
        return
    for i in range(1, n+1):
        x = i
        y = n+(i-((n+1)//2)+n)%n+1
        print(k+x, k+y, 2*k+x+y+r)

N, K = map(int, input().split())
if N%2:
    kn(N,K)
else:
    gn(N,K)

Solution (Python):
import os
import sys
from collections import deque

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(10 ** 9)
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7



N, K = list(map(int, sys.stdin.readline().split()))
if 2 * K > N + 1:
    print(-1)
    exit()

ab = []
ai = 0
bi = N - 1
for _ in range(N):
    a = K + ai
    b = K + N + bi
    ab.append((a + b, a, b))
    ai = (ai + 2) % N
    bi = (bi - 1) % N
    if ai == 0:
        
        ai += 1

ab.sort()
for c, (_, a, b) in zip(range(K + 2*N, K + 3*N), ab):
    print(a, b, c)

Solution (Python):
import sys
n,k=map(int,input().split())
if 2*k-1>n:
  print(-1)
  sys.exit()
a=[i for i in range(k,k+n)]
A=[]
for i in range(len(a)):
  if i%2==0:
    A.append(a[i])
for i in range(len(a)):
  if i%2==1:
    A.append(a[i])
b1=[i for i in range(k+n,k+n+(n+1)//2)]
b2=[i for i in range(k+n+(n+1)//2,k+2*n)]
b1.reverse()
b2.reverse()
B=b1+b2
C=[i for i in range(k+2*n,k+3*n)]
for i in range(n):
  print(A[i],B[i],C[i])

Solution (Python):
n,k=map(int,input().split())
if 2*k-1>n:
  print(-1)
else:
  a=[i for i in range(k,k+n)]
  A=[]
  for i in range(len(a)):
    if i%2==0:
      A.append(a[i])
  for i in range(len(a)):
    if i%2==1:
      A.append(a[i])
  b1=[i for i in range(k+n,k+n+(n+1)//2)]
  b2=[i for i in range(k+n+(n+1)//2,k+2*n)]
  b1.reverse()
  b2.reverse()
  B=b1+b2
  C=[i for i in range(k+2*n,k+3*n)]
  for i in range(n):
    print(A[i],B[i],C[i])

Solution (Python):
import sys

sys.setrecursionlimit(10 ** 6)
input = sys.stdin.readline
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")

def main():
    n, k = map(int, input().split())
    if 2 * k - n > 1:
        print(-1)
        exit()
    a = k + n // 2
    b = k + n
    c = k + 2 * n
    ab = []
    for i in range(n):
        ab.append([a, b])
        a, b = a + 1, b + 1
        if a == k + n: a = k
    ab.sort(key=lambda x: x[0] + x[1])
    for a, b in ab:
        print(a, b, c)
        c += 1

main()

Solution (Python):
import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
input=lambda :sys.stdin.readline().rstrip()
def resolve():
    n,k=map(int,input().split())
    if(2*k>n+1):
        print(-1)
        return
    
    h=(2*k+3*n-1)//2
    for i in range((n+1)//2):
        print(k+2*i,h-i,k+2*n+i)
    for i in range(n//2):
        print(k+1+i*2,k+2*n-1-i,k+2*n+((n-1)//2)+i+1)
resolve()

Solution (Python):
import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
input=lambda :sys.stdin.readline().rstrip()
def resolve():
    n,k=map(int,input().split())
    if(2*k>n+1):
        print(-1)
        return
    
    h=(2*k+3*n-1)//2
    for i in range(0,(n+1)//2):
        print(k+2*i,h-i,k+2*n+i)
    for i in range(0,n//2):
        print(k+1+i*2,k+2*n-1-i,k+2*n+((n-1)//2)+i+1)
resolve()

Solution (Python):
N,K = map(int,input().split())

ans = []
n = (N+1)//2
if N%2==1:
    for i in range(1,n+1):
        a = i
        b = 4*n-2*i
        c = a+b+n-1
        a += K-1
        b += K-1
        c += K-1
        ans.append([a,b,c])
    for i in range(1,n):
        a = n+i
        b = 4*n-1-2*i
        c = a+b+n-1
        a += K-1
        b += K-1
        c += K-1
        ans.append([a,b,c])
else:
    for i in range(1,n+1):
        a = i
        b = 4*n+2-2*i
        c = a+b+n-1
        a += K-1
        b += K-1
        c += K-1
        ans.append([a,b,c])
        a = n+i
        b = 4*n+1-2*i
        c = a+b+n
        a += K-1
        b += K-1
        c += K-1
        ans.append([a,b,c])

if K>n:
    print(-1)
else:
    for a,b,c in ans:
        print(a,b,c)

Solution (Python):
N, K = map(int, input().split())
if N < 2*K - 1:
    print(-1)
else:
    A = [a for a in range(K, K+N, 2)]
    A += [a for a in range(K+1, K+N, 2)]
    B = [b for b in range(K+2*N-N//2-1, K+N-1, -1)]
    B += [b for b in range(K+2*N-1, K+2*N-N//2-1, -1)]
    C = [c for c in range(K+2*N, K+3*N)]
    [print(*p) for p in list(map(list, zip(A, B, C)))]

Solution (Python):
n,k = map(int,input().split())
if n % 2 == 0:
  if 2*k > n:
    print(-1)
  else:
    for i in range(n//2):
      print(k+2*i, k+(3*n)//2-1-i, k+2*n+i)
    for i in range(n//2):
      print(k+1+2*i, k+2*n-1-i, k+(5*n)//2+i)
else:
  if 2*k-1 > n:
    print(-1)
  else:
    for i in range((n+1)//2):
      print(k+2*i, k+(3*n-1)//2-i, k+2*n+i)
    for i in range((n-1)//2):
      print(k+1+2*i, k+2*n-1-i, k+(5*n+1)//2+i)

Solution (Python):

import sys
input = sys.stdin.buffer.readline


from collections import defaultdict


def getlist():
	return list(map(int, input().split()))


def main():
	N, K = getlist()
	if 2 * K - 1 > N:
		print(-1)
	else:
		if N % 2 == 1:
			ans = [[0, 0, 0] for i in range(N)]
			for i in range(N):
				ans[i][2] = K + 2 * N + i
			for i in range(N):
				ans[(2 * i) % N][(2 * i) // N] = K + i
				ans[(2 * i + 1) % N][(2 * i + 1) // N] = K + N + i
		else:
			ans = [[0, 0, 0] for i in range(N)]
			for i in range(N):
				ans[i][2] = K + 2 * N + i
			n = N // 2
			for i in range(n):
				ans[2 * i][0] = K + i
				ans[2 * i + 1][0] = K + N + i
			for i in range(n, N):
				ans[2 * i - N][1] = K + N + i
				ans[2 * i + 1 - N][1] = K + i
		for i in range(N):
			print(" ".join(list(map(str, ans[i]))))

if __name__ == '__main__':
	main()

Solution (Python):
n,k=map(int,input().split())
if n%2==0:
    if (2+k-1)+(n//2*3+k-1)>2*n+1+k-1:
        print(-1)
    else:
        cc=3*n
        bb=3*n//2+1
        for aa in range(n-1,0,-2):
            print(aa+k-1,bb+k-1,cc+k-1)
            bb+=1
            cc-=1
        bb=n+1
        for aa in range(n,0,-2):
            print(aa+k-1,bb+k-1,cc+k-1)
            bb+=1
            cc-=1
else:
    if (2+k-1)+((n*3-1)//2+k-1)>2*n+1+k-1:
        print(-1)
    else:
        cc=3*n
        bb=(3*n+1)//2
        for aa in range(n,0,-2):
            print(aa+k-1,bb+k-1,cc+k-1)
            bb+=1
            cc-=1
        bb=n+1
        for aa in range(n-1,0,-2):
            print(aa+k-1,bb+k-1,cc+k-1)
            bb+=1
            cc-=1

Solution (Python):
import sys

N,K = map(int,input().split())

if 2*K-1 > N:
    print (-1)
    sys.exit()

ans = []

nc = K+2*N + (N+1) // 2
na = K+1
nb = K + 2*N -1

for i in range(N // 2):


    ans.append([na,nb,nc])
    
    na += 2
    nb -= 1
    nc += 1

na = K
nc = K + 2*N
for i in range((N+1) // 2):


    ans.append([na,nb,nc])


    na += 2
    nb -= 1
    nc += 1

for i in ans:

    print (i[0],i[1],i[2])

Solution (Python):
N,K = map(int,input().split())

ans = [[K+i] for i in range(N)]

m = (N+1)//2
n = K+N
for i in range(m,N):
    ans[i].append(n)
    n += 1
for i in range(m):
    ans[i].append(n)
    n += 1

ans.sort(key=lambda x: x[0]+x[1])
for i in range(N):
    if sum(ans[i]) > n:
        print(-1)
        exit()
    ans[i].append(n)
    n += 1

for row in ans:
    print(*row)

Solution (Python):
n, k = map(int, input().split())
s1, s2, s3, s4, s5, s6 = k, k+n-1, k+n, k+2*n-1, k+2*n, k+3*n-1
if s1 + s4 <= (s5 + s6)/2:
  for i in range(n//2+n%2):
    a = s1 + i*2
    b = s4 - i
    c = s5 + n//2 + i
    print(a, b, c)
  for i in range(n//2):
    a = s1 + 1 + i*2
    b = s4 - (n+1)//2 - i
    c = s5 + i
    print(a, b, c)
else:
  print(-1)

Solution (Python):
N, K = map(int, input().split())
A = []
B = []
C = [2*N+i+K for i in range(N)]
s = 2 * K + 3 * N // 2 + (1 if N % 2 == 0 else 0)
for i in range((N+1)//2):
    A.append(K+i*2)
    B.append(s-K-i-(2 if N % 2 == 0 else 0))
for i in range(N//2):
    A.append(K+1+i*2)
    B.append(s-K-i+N//2-(2 if N % 2 == 0 else 0))

for i in range(N):
    if A[i] + B[i] > C[i]:
        print(-1)
        break
else:
    for i in range(N):
        print(A[i], B[i], C[i])

Solution (Python):
def solve(n, k):
    s1 = n * (k + (k + 2 * n - 1))
    s2 = n * ((k + 2 * n) + (k + 3 * n - 1)) // 2
    res = []
    if s1 > s2:
        return None
    if n % 2 == 1:
        m = ((n + 1) // 4) * 2
        for i in range(m):
            a = k + n - 1 - i
            b = k + n + i + (m - 1 - 2 * i)
            c = k + 2 * n + (n - 1) // 2 + (m - 1 - 2 * i)
            res.append([a, b, c])
            
        for i in range(n - m):
            a = k + n - 1 - m - i
            b = k + 2 * n - 1 - i
            c = k + 2 * n + (n - 1) // 2 + 2 * ((n - m) // 2 - i)
            res.append([a, b, c])
            
        return res
    else:
        m = n // 2
        for i in range(m):
            a = k + n - 1 - i
            b = k + n + i + (m - 1 - 2 * i)
            c = k + 2 * n + m + (m - 2 - 2 * i)
            res.append([a, b, c])
            
        for i in range(n - m):
            a = k + n - 1 - m - i
            b = k + 2 * n - 1 - i
            c = k + 3 * n - 1 - 2 * i
            res.append([a, b, c])
            
        return res


def main():
    n, k = map(int, input().split())
    res = solve(n, k)
    if res is None:
        print(-1)
    else:
        for r in res:
            print(*r)


if __name__ == "__main__":
    main()

Solution (Python):



def solve(N,K):
    if 2*K > N+1:
        print(-1)
        return

    def it():

        for i in range((N+1)//2):
            yield (K+i, K+N+i+N//2, K+N*2+i*2)
        for i in range(N//2):
            yield (K+(N+1)//2 + i, K+N+i, K+N*2+i*2+1)

    for a,b,c in it():
        print(a,b,c)

N,K = map(int,input().split())
solve(N,K)

Solution (Python):

from collections import defaultdict,deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res
def IR(n):
    return [I() for i in range(n)]
def LIR(n):
    return [LI() for i in range(n)]
def SR(n):
    return [S() for i in range(n)]
def LSR(n):
    return [LS() for i in range(n)]

sys.setrecursionlimit(1000000)
mod = 1000000007

def solve():
    n,k = LI()
    if k == 1:
        for i in range(n):
            print(i+1,i+1+n,i+1+2*n)
        return
    a = [i+k for i in range(n)]
    b = [i+n+k for i in range(n)]
    c = [i+2*n+k for i in range(n)]
    if n%2 == 0:
        ans = [[a[i],b[(i+n-k)%n],c[2*i]] if 2*i < n else [a[i],b[(i+n-k)%n],c[(2*i+1)%n]] for i in range(n)]
    else:
        ans = [[a[i],b[(i+n-k)%n],c[(2*i)%n]] for i in range(n)]
    for a,b,c in ans:
        if a+b > c:
            print(-1)
            return
    for a in ans:
        print(*a)
    return
def test():
    def change(m):
        res = []
        for i in range(3*n):
            res.append(m%n)
            m //= n
        return res

    def check(a):
        return a[0]+a[1] <= a[2]
    n,k = LI()
    l = [k+i for i in range(3*n)]
    print(n**(3*n))
    f = [change(i) for i in range(n**(3*n))]
    for k in f[::-1]:
        if all([k.count(i) == n for i in range(n)]):
            a = [[l[i] for i in range(3*n) if k[i] == j] for j in range(n)]
            if all([check(i) for i in a]):
                print(a)

if __name__ == "__main__":
    solve()

Solution (Python):


import sys
sys.setrecursionlimit(10**6)
readline = sys.stdin.readline 

n,k = [int(i) for i in readline().split()]

if 2*k > n+1:
    print(-1)
else:
    if n%2:
        K = (n+1)//2
        S = K + 2*n
    else:
        K = (n)//2
        S = K + 2*n-2
        
    
    ans = []
    L = n-2
    num = n
    for i in range(2*K+n-1,K+n-1,-1):
        ans.append([i,S-i,S])
        S += 1
        num -= 1        
    
    if n%2==0:
        num -= 1
    for i in range(num):
        if n%2: P = K+2*n-1-i
        else: P = K+2*n-1-i-1
        ans.append([P,S-P,S])
        S += 1
    
    if n%2==0:
        ans.append([K+n-1,K+n-2,2*K+2*n-3+n//2])
        K-=1

    
    
    
    res = 0
    if n%2==0: res += 1
    
    for i in ans:
        a,b,c = i
        print(a-(K-k),b-(K-k),c-(K-k)+res)

Solution (Python):
import math
N, K = map(int,input().split())
if (2*N)*(K+ K+2*N-1) > N*(K+2*N + K+3*N-1):
    print(-1)
    exit()
flag = [1]*(2*N)
for i in range(math.floor(N/2),N):
    a = K + i
    b = K + 2*N -1 -(i-math.floor(N/2))*2
    c = K + 3*N -1 -(i-math.floor(N/2))
    print(a,b,c)
for i in range(math.floor(N/2)):
    a = K + i
    b = K + 2*N -2 -i*2
    c = K + 3*N -1 -i-math.ceil(N/2)
    print(a,b,c)

Solution (Python):
n,k=map(int,input().split())
a=[k+i for i in range(n)]
b=[n+i for i in a]
c=[n+i for i in b]
if sum(a)+sum(b)>sum(c):print(-1);exit()
i=n-1
j=b.index(2*n)
print(k+n-1,2*n,k+3*n-1)
bs={2*n}
for k in range(n-1-(n%2==0),0,-1):
  i-=2
  j+=1
  if i<0:i=n+i
  if j==n:j=0
  if i==n-1:
    i-=1
    j+=1
  bs.add(b[j])
  print(a[i],b[j],c[k-n%2])
if n%2==0:
  for i in b:
    if not i in bs:bb=i
  print(a[0],bb,c[0])

Solution (Python):
def swap(x):
    s = len(x)//2
    out = []
    if s>=1:
        for i in range(s):
            out.append([x[i][0],x[-1-i][1]])
            out.append([x[-1-i][0],x[i][1]])
        if len(x)%2==1:
            out.append([x[s][0],x[s][1]])
    else:
        out.append(x[0])
    return out

N, K = map(int, input().split())

if K == 1:
    for i in range(N):
        print(K+i,K+2*N-i-1,K+2*N+i)
elif K <= (N+1)/2:
    ans=[]
    for i in range(N):
        ans.append([K+i,K+2*N-i-1])
    if N%2 == 0:
        s=N//2
        ans_1 = ans[:s+1]
        ans_2 = ans[s+1:-1]
        ans_3 = ans[-1]
        ans_1_new = swap(ans_1)
        ans_2_new = swap(ans_2)
        ans_new = ans_1_new + ans_2_new + [ans_3]
    else:
        s=(N-1)//2
        ans_1 = ans[:s+1]
        ans_2 = ans[s+1:]
        ans_1_new = swap(ans_1)
        ans_2_new = swap(ans_2)
        ans_new = ans_1_new + ans_2_new
    ans = []
    for elem in ans_new:
        ans.append([elem[0],elem[1],elem[0]+elem[1]])
    ans = sorted(ans, key=lambda x: x[2])
    for i in range(N):
        ans[i][2] = K + 2*N + i
        print(ans[i][0],ans[i][1],ans[i][2])
else:
    print(-1)

Solution (Python):


def solve():
    N, K = map(int,input().split())
    if K > (N+1)/2:
        return '-1'

    L = [[K,K+N,K+2*N] for i in range(N)]
    for i in range(N):
        if N%2:
            j = (N-1-2*i)%N
            k = (2*i)%N
        else:
            j = (N-1-2*i)%N-i//(N//2)
            k = (1+2*i)%N-i//(N//2)
        L[i][0] += i
        L[j][1] += i
        L[k][2] += i
    res = '\n'.join(' '.join(map(str, l)) for l in L)
    return res

if __name__ == '__main__':
    print(solve())