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



Sample input:
1 1


Sample output:
1 2 3

Submission status: Wrong Answer

Solution code:
from random import random


class TreapNode():
    def __init__(self, val):
        self.val = val
        self.priority = random()
        self.parent = None
        self.right = None
        self.left = None

        
class Treap():
    def __init__(self, is_multiset=False):
        self.root = None
        self.is_multiset = is_multiset

    def search(self, val: int) -> bool:
        ptr = self.root
        while ptr is not None:
            if ptr.val == val:
                return True
            if val < ptr.val:
                ptr = ptr.left
            else:
                ptr = ptr.right
        return False 

    def insert(self, val: int):
        if self.root is None:
            self.root = TreapNode(val)
            return

        ptr = self.root 
        while True:
            if val < ptr.val:
                if ptr.left is None:
                    ptr.left = TreapNode(val)
                    ptr.left.parent = ptr
                    ptr = ptr.left
                    break
                ptr = ptr.left
            else:
                if val == ptr.val and not self.is_multiset:
                    return
                if ptr.right is None:
                    ptr.right = TreapNode(val)
                    ptr.right.parent = ptr
                    ptr = ptr.right
                    break
                ptr = ptr.right

        while (ptr.parent is not None) and (ptr.parent.priority > ptr.priority):
            if ptr.parent.right == ptr:
                self.rotate_left(ptr.parent)
            else:
                self.rotate_right(ptr.parent)
        if ptr.parent is None:
            self.root = ptr 
       
    def delete(self, val: int):
        if self.root is None:
            return

        ptr = self.root         
        while True: 
            if ptr is None:
                return
            if ptr.val == val:
                break
            elif val < ptr.val:
                ptr = ptr.left
            else:
                ptr = ptr.right

        while (ptr.left is not None) or (ptr.right is not None):
            if ptr.left is None:
                self.rotate_left(ptr)
            elif ptr.right is None:
                self.rotate_right(ptr)
            elif ptr.left.priority < ptr.right.priority:
                self.rotate_right(ptr)
            else:
                self.rotate_left(ptr)
            if self.root == ptr:
                self.root = ptr.parent
       
        if ptr.left is None and ptr.right is None:
            if ptr == self.root:
                self.root = None
            elif ptr.parent.left == ptr:
                ptr.parent.left = None
            else:
                ptr.parent.right = None      

    def search_min(self, ptr):
        while True:
            if ptr.left is None:
                return ptr
            ptr = ptr.left
        return ptr

    def search_max(self):
        ptr = self.root
        while True:
            if ptr.right is None:
                return ptr.val
            ptr = ptr.right


    def rotate_left(self, ptr):
        w = ptr.right
        w.parent = ptr.parent
        if w.parent is not None:
            if w.parent.left == ptr:
                w.parent.left = w
            else:
                w.parent.right = w
        ptr.right = w.left
        if ptr.right is not None:
            ptr.right.parent = ptr
        ptr.parent = w
        w.left = ptr
        if ptr == self.root:
            self.root = w
            self.root.parent = None

    def rotate_right(self, ptr):
        w = ptr.left
        w.parent = ptr.parent
        if w.parent is not None:
            if w.parent.right == ptr:
                w.parent.right = w
            else:
                w.parent.left = w
        ptr.left = w.right
        if ptr.left is not None:
            ptr.left.parent = ptr
        ptr.parent = w
        w.right = ptr
        if ptr == self.root:
            self.root = w
            self.root.parent = None

    def search_less_than(self, val):
        if val == None:
            return None
        ptr = self.root
        ret = None
        while ptr is not None:
            if ptr.val == val:
                return ptr.val
            elif ptr.val < val:
                ret = ptr.val
                ptr = ptr.right
            else:
                ptr = ptr.left
        return ret


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

for i in range(2*n):
    tp.insert(k + i)

ans = []
for i in range(n)[::-1]:
    right = k + 2*n + i
    left1 = tp.search_max()
    tp.delete(left1)
    left2 = tp.search_less_than(right - left1)
    if left2 is None:
        print(-1)
        exit()
    tp.delete(left2)
    ans.append((left1, left2, right))
for i in ans:
    print(*i)

Submission status: Wrong Answer

Solution code:
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])
            # print(1, 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])
            # print(2, a, b, c)
        return res
    else:
        m = (n // 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])
            # print(1, 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])
            # print(2, 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()

Submission status: Wrong Answer

Solution code:
N,K=map(int,input().split())
X=[]
for i in range(N):
    X.append((K+2*i,K+2*i+1,K+2*N+i))
for i in range(N):
    a,b,c=X[i]
    if a+b>c:
        print(-1)
        exit()
for i in range(N):
    a,b,c=X[i]
    print(a,b,c)

Submission status: Wrong Answer

Solution code:
N,K = map(int, input().split())
l=[1] * (2 * N)
answer_list = [[0 for i in range(3)] for j in range(N)]
flg = True
for idx in reversed(range(N)):
    innerFlg1 = False
    for idy in reversed(range(N)):
        if (l[idy + N]==0):
            continue
        for idz in reversed(range(N)):
            if (l[idz] == 0):
                continue
            if (K+idz + K + N + idy <= K + N * 2 + idx):
                answer_list[idx] = [K+idz, K+N+idy, K+(2*N)+idx]
                l[idx] = 0
                l[idy+N] = 0
                innerFlg1=True
                break
        if innerFlg1:
            break
    if innerFlg1 == False:
        flg=False
        break
if (flg):
    for idx in range(N):
        print(str(answer_list[idx][0]) + " " + str(answer_list[idx][1]) + " " + str(answer_list[idx][2]))
else:
    print(-1)

Submission status: Wrong Answer

Solution code:
N, K = map(int, input().split())
if (N*3+1)*3*N//2-N*(N*2+1)>=N*K:
    print('No')
else:
    print('Yes')

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
def main():
    N,K=map(int,input().split())
    if (2*K+2*N-1)*N>(2*K+5*N-1)*N//2:
        print(-1)
        return

    L1=list(range(K,K+N))
    L2=list(range(K+N,K+2*N))
    L3=list(range(K+2*N,K+3*N))

    output=[[a1,a2,a3] for a1,a2,a3 in zip(L1,reversed(L2),L3)]
    print(output)

    
    for i in range(len(output)):
        data=output[i]
        if data[0]+data[1]>data[2]:
            p=output[i][1]
            output[i][1]=output[i+data[0]+data[1]-data[2]][1]
            output[i+data[0]+data[1]-data[2]][1]=p

    for d in output:
        print(" ".join([str(x) for x in d]))

main()

Submission status: Wrong Answer

Solution code:
N,K=map(int,input().split())
if K+K+2*N-1<=K+2*N:
  for i in range(N):
    ls=[K+i,K+N*2-1-i,K+2*N+i]
    print(" ".join(map(str,ls)))
elif K+2*N-1+K+2*N-2<=K+3*N-1:
  for i in range(N):
    ls=[K+2*i,K+2*i+1,K+2*N+i]
    print(" ".join(map(str,ls)))
else:
  print(-1)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
N,K=map(int,input().split())
X=[]
for i in range(N):
    X.append((K+i,K+N+i,K+2*N+i))
for i in range(N):
    a,b,c=X[i]
    if a+b>c:
        print(-1)
        exit()
for i in range(N):
    a,b,c=X[i]
    print(a,b,c)

Submission status: Wrong Answer

Solution code:
N, K = map(int, input().split())
if N + 1 < 2*K:
    print(-1)
    exit()

A = list(range(K, K+N))
B = list(range(K+N, K+2*N))
C = list(range(K+2*N, K+3*N))

ans = []
for i in range(N):
    ans.append((A[i], B[(i*2-1)%N], C[(i*3 + (N//2))%N]))

for i in range(N):
    print(*ans[i])

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import sys
read = sys.stdin.buffer.read
input = sys.stdin.buffer.readline
inputs= sys.stdin.buffer.readlines
#rstrip().decode('utf-8')

#import math
#import numpy as np
#import operator
#import bisect
#from heapq import heapify,heappop,heappush
#from math import gcd
#from fractions import gcd
#from collections import deque
#from collections import defaultdict
#from collections import Counter
#from itertools import accumulate
#from itertools import groupby
#from itertools import permutations
#from itertools import combinations
#from scipy.sparse import csr_matrix
#from scipy.sparse.csgraph import floyd_warshall
#from scipy.sparse.csgraph import csgraph_from_dense
#from scipy.sparse.csgraph import dijkstra
#sys.setrecursionlimit(10**7)

#map(int,input().split())

def main():
	n,k=map(int,input().split())
	
	if k>=3:
		print("-1")
		exit(0)
	
	elif k==1:
		for i in range(1,n+1):
			print(i,2*n-i+1,2*n+i)

	
	else:
		if n<=2:
			print("-1")
			exit(0)
		else:
			print(2,2*n+1,2*n+3)
			print(3,2*n-1,2*n+2)
			print(4,2*n,2*n+4)
			for i in range(1,n-2):
				print(i+4,2*n-1-i,2*n+4+i)
	

if __name__ == '__main__':
	main()

Submission status: Wrong Answer

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


if N - 2*K + 1 < 0:
    print("-1")
else:
    for i in range(N):
        hoge = []
        half = N // 2
        kisu = (N % 2 == 1)
        if i * 2 < N-1:
            hoge = [str(K+N-1-i), str(K+N+2*i), str(K+3*N-half+i)]
        elif i < N-1 or kisu:
            hoge = [str(K+N-1-i), str(K+N+1-half+2*i), str(K+2*N-2//N+i-half+2*i)]
        elif i == N-1 and not kisu:
            hoge = [str(K), str(K+2*N), str(K+3*N-1)]
        print(" ".join(hoge))

Submission status: Wrong Answer

Solution code:



def solve(N,K):
    if K > (N-1)//2:
        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)

Submission status: Wrong Answer

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

ans = []
flag=True
for i in range(K,(K+3*N-1)-(K+2*N-1)+1):
    if i>= K+2*N:
        flag=False
        break
    ans.append((i,i+2*N-K,2*i + 2*N - K))
for i in range((K+3*N-1)-(K+2*N-1)+1,K+N):
    if i>= K+2*N:
        flag=False
        break
    ans.append((i,i + K + N - ((K+3*N-1)-(K+2*N-1)+1),2*i + K + N - ((K+3*N-1)-(K+2*N-1)+1)))

if flag:
    for a in ans:
        print(*a)
else:
    print(-1)

Submission status: Wrong Answer

Solution code:
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(k!=1):
        print(-1)
        return
    for i in range(n):
        print(i+1,2*n-i,2*n+i+1)
resolve()

Submission status: Wrong Answer

Solution code:
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) // 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 - 1 - 2 * i)
            res.append([a, b, c])
        for i in range(m - n):
            p = m + (m - n) // 2 
            a = k + n - 1 - m - i
            b = k + n + m + i + (p + p - i)
            c = k + 2 * n + m + (m - 2 * i)
            res.append([a, b, c])
        
        


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()

Submission status: Wrong Answer

Solution code:



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)

Submission status: Wrong Answer

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

ans = []

if N >= 0:
    for i in range(K,(K+3*N-1)-(K+2*N-1)+1):
        ans.append((i,i+2*N-K,2*i + 2*N - K))
    for i in range((K+3*N-1)-(K+2*N-1)+1,K+N):
        ans.append((i,i + K + N - ((K+3*N-1)-(K+2*N-1)+1),2*i + K + N - ((K+3*N-1)-(K+2*N-1)+1)))

    for a in ans:
        print(*a)
else:
    print(-1)

Submission status: Wrong Answer

Solution code:
#import sys
#read = sys.stdin.buffer.read
#input = sys.stdin.buffer.readline
#inputs= sys.stdin.buffer.readlines
#rstrip().decode('utf-8')

#import math
#import numpy as np
#import operator
#import bisect
#from heapq import heapify,heappop,heappush
#from math import gcd
#from fractions import gcd
#from collections import deque
#from collections import defaultdict
#from collections import Counter
#from itertools import accumulate
#from itertools import groupby
#from itertools import permutations
#from itertools import combinations
#from scipy.sparse import csr_matrix
#from scipy.sparse.csgraph import floyd_warshall
#from scipy.sparse.csgraph import csgraph_from_dense
#from scipy.sparse.csgraph import dijkstra
#sys.setrecursionlimit(10**7)

#map(int,input().split())

def main():
	n,k=map(int,input().split())
	
	if k>=3:
		print("-1")
		exit(0)
	
	elif k==1:
		for i in range(1,n+1):
			print(i,2*n-i+1,2*n+i)
		exit(0)
	
	else:
		if n<=2:
			print("-1")
			exit(0)
		else:
			print(3,2*n-1,2*n+2)
			print(2,2*n+1,2*n+3)
			print(4,2*n,2*n+4)
			for i in range(1,n-2):
				print(i+4,2*n-1-i,2*n+4+i)
			exit(0)
	

if __name__ == '__main__':
	main()

Submission status: Wrong Answer

Solution code:
inpl = lambda: list(map(int,input().split()))
N, K = inpl()
if (N,K) == (1,1):
    print(1,2,3)
else:
    print(-1)

Submission status: Wrong Answer

Solution code:
import bisect
N,K=[int(thing) for thing in input().split(" ")]
ll=[]
pool=list(range(K,K+2*N))
for i in range(0,N):
    c=K+3*N-1-i
    b=pool[-1]
    aa=c-b+1
    index=bisect.bisect_left(pool,aa)-1
    if index==len(pool):
        print(-1)
        exit()
    a=pool.pop(index)
    if a==b:
        print(-1)
        exit()

    ll=[[a,b,c]]+ll

print(ll)
for l in ll:
    print(l)
    print(" ".join([str(thing) for thing in l]))

Submission status: Wrong Answer

Solution code:
import sys
read = sys.stdin.buffer.read
input = sys.stdin.buffer.readline
inputs= sys.stdin.buffer.readlines
#rstrip().decode('utf-8')

#import math
#import numpy as np
#import operator
#import bisect
#from heapq import heapify,heappop,heappush
#from math import gcd
#from fractions import gcd
#from collections import deque
#from collections import defaultdict
#from collections import Counter
#from itertools import accumulate
#from itertools import groupby
#from itertools import permutations
#from itertools import combinations
#from scipy.sparse import csr_matrix
#from scipy.sparse.csgraph import floyd_warshall
#from scipy.sparse.csgraph import csgraph_from_dense
#from scipy.sparse.csgraph import dijkstra
#sys.setrecursionlimit(10**7)

#map(int,input().split())

def main():
	n,k=map(int,input().split())
	
	if k>=3:
		print("-2")
		exit(0)
	
	if k==1:
		for i in range(1,n+1):
			print(i,2*n-i+1,2*n+i)
	
	if k==2:
		if n<=2:
			print("-2")
			exit(0)
		else:
			print(3,2*n-1,2*n+2)
			print(2,2*n+1,2*n+3)
			print(4,2*n,2*n+4)
			for i in range(1,n-2):
				print(i+4,2*n-1-i,2*n+4+i)
	

if __name__ == '__main__':
	main()

Submission status: Wrong Answer

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

ans = []

if N >= 2*K-1:
    for i in range(K,(K+3*N-1)-(K+2*N-1)+1):
        ans.append((i,i+2*N-K,2*i + 2*N - K))
    for i in range((K+3*N-1)-(K+2*N-1)+1,K+N):
        ans.append((i,i + K + N - ((K+3*N-1)-(K+2*N-1)+1),2*i + K + N - ((K+3*N-1)-(K+2*N-1)+1)))

    for a in ans:
        print(*a)
else:
    print(-1)

Submission status: Wrong Answer

Solution code:
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(k!=1):
        print(-1)
resolve()

Submission status: Wrong Answer

Solution code:
import collections
import sys

def read_a_integer():
    return int(sys.stdin.readline())

def read_a_list(dtype):
    return list(map(dtype, sys.stdin.readline().split()))

def main():
    N, K = read_a_list(int)
    if K == 1:
        for i in range(N):
            print(1+i, 1+2*N-i-1, 1+i+2*N)
    else:
        print(-1)


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

used = set()
ans = []

mx = n = K+3*N-1
b = n//2 + 1
a = n-b

for i in range(N):
    if a < K: break
    ans.append((a,b,n))
    used.add(a)
    used.add(b)
    used.add(n)
    n -= 1
    a -= 2
    b += 1

notused = []
for i in range(K,K+3*N):
    if i in used: continue
    notused.append(i)

k = len(notused)//3
for a,b,c in zip(notused[:k], notused[k:2*k], notused[2*k:]):
    if a+b > c:
        print(-1)
        exit()
    ans.append((a,b,c))

for row in ans:
    print(*row)

Submission status: Wrong Answer

Solution code:
#!usr/bin/env python3
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)]
    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)
#Solve
if __name__ == "__main__":
    solve()

Submission status: Wrong Answer

Solution code:
N,K=[int(_) for _ in input().split()]
M1=K+3*N-1
M2=(M1+1)//2
if (M1-M2)==N:
    for i in range(M1,M2,-1):
        print((i+1)//2-1,(i+1)//2,i)
else:
    print(-1)

Submission status: Wrong Answer

Solution code:
#!usr/bin/env python3
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
    if n%2 == 0:
        print(-1)
        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)]
    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)
#Solve
if __name__ == "__main__":
    solve()

Submission status: Wrong Answer

Solution code:
N,K=map(int,input().split())
if K+2*N-1+K+2*N-2<=K+3*N-1:
  for i in range(N):
    ls=[K+i*2,K+i*2+1,K+2*N+i]
    print(" ".join(map(str,ls)))
else:
  print(-1)

Submission status: Wrong Answer

Solution code:
import sys
read = sys.stdin.buffer.read
input = sys.stdin.buffer.readline
inputs= sys.stdin.buffer.readlines
#rstrip().decode('utf-8')

#import math
#import numpy as np
#import operator
#import bisect
#from heapq import heapify,heappop,heappush
#from math import gcd
#from fractions import gcd
#from collections import deque
#from collections import defaultdict
#from collections import Counter
#from itertools import accumulate
#from itertools import groupby
#from itertools import permutations
#from itertools import combinations
#from scipy.sparse import csr_matrix
#from scipy.sparse.csgraph import floyd_warshall
#from scipy.sparse.csgraph import csgraph_from_dense
#from scipy.sparse.csgraph import dijkstra
#sys.setrecursionlimit(10**7)

#map(int,input().split())

def main():
	n,k=map(int,input().split())
	
	if k>=3:
		print("-1")
		exit(0)
	
	if k==1:
		for i in range(1,n+1):
			print(i,2*n-i+1,2*n+i)
	
	if k==2:
		if n<=2:
			print("-1")
			exit(0)
		else:
			print(3,2*n-1,2*n+2)
			print(2,2*n+1,2*n+3)
			print(4,2*n,2*n+4)
			for i in range(1,n-2):
				print(i+4,2*n-1-i,2*n+4+i)
	

if __name__ == '__main__':
	main()

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
N, K = map(int, input().split())
if K != 1:
    print(-1)
    exit()
res = []
for idx in range(3):
    res.append([str(x) for x in range(idx * N + 1, idx*N+N+1)])
for i in range(N):
    print(' '.join(res[j][i] for j in range(3)))

Submission status: Wrong Answer

Solution code:
import os
import sys

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

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

N, K = list(map(int, sys.stdin.readline().split()))

# # ちがう？
# if N == K == 1:
#     print(1, 2, 3)
# else:
#     print(-1)


# c はできるだけおっきいの使ったほうが良い
ans = []
a = K
b = K + 2 * N - 1
for c in range(K + 2 * N, K + 3 * N):
    if a + b <= c:
        ans.append((a, b, c))
    else:
        break
    a += 1
    b -= 1
if len(ans) == N:
    for a, b, c in ans:
        print(a, b, c)
else:
    print(-1)

Submission status: Wrong Answer

Solution code:
import sys
read = sys.stdin.buffer.read
input = sys.stdin.buffer.readline
inputs= sys.stdin.buffer.readlines
#rstrip().decode('utf-8')

import math
#import numpy as np
#import operator
#import bisect
#from heapq import heapify,heappop,heappush
#from math import gcd
#from fractions import gcd
#from collections import deque
#from collections import defaultdict
#from collections import Counter
#from itertools import accumulate
#from itertools import groupby
#from itertools import permutations
#from itertools import combinations
#from scipy.sparse import csr_matrix
#from scipy.sparse.csgraph import floyd_warshall
#from scipy.sparse.csgraph import csgraph_from_dense
#from scipy.sparse.csgraph import dijkstra
#sys.setrecursionlimit(10**7)

#map(int,input().split())

def main():
	n,k=map(int,input().split())
	
	if k>=3:
		print(-1)
		exit(0)
	
	if k==1:
		for i in range(1,n+1):
			print(i,2*n-i+1,2*n+i)
	
	if k==2:
		if n<=2:
			print(-1)
			exit(0)
		else:
			print(3,2*n-1,2*n+2)
			print(2,2*n+1,2*n+3)
			print(4,2*n,2*n+4)
			for i in range(1,n-2):
				print(i+4,2*n-1-i,2*n+4+i)
	

if __name__ == '__main__':
	main()

Submission status: Wrong Answer

Solution code:
n,k = map(int,input().split())
l = list()
for i in range(n):
  a = k + i*2
  b = k + i*2 + 1
  c = k + 2*n + i
  if a + b > c:
    print(-1)
    exit(0)
  l.append((a,b,c))
for x in l:
  print(*x)

Submission status: Wrong Answer

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

used = [True]*(2*n)

sma = 0

res = []
for b in range(k+2*n,k+3*n):
    q = b-2*k
    if sma*2+1 > q:
        print(-1)
        exit()
    used[sma] = False

    judge = True
    for i in range(q-sma,-1,-1):
        if used[i]:
            used[i] = False
            judge = False
            r = i
            break
    
    if judge:
        print(-1)
        exit()
    
    res.append(k+sma)
    res.append(b)
    res.append(k+r)
    if b != k+3*n-1:
        judge = True
        
        for i in range(sma+1,n):
            if used[i]:
                sma = i
                judge = False
                break

        if judge:
            print(-1)
            exit()

for i in range(n):
    print(res[3*i],res[3*i+1],res[3*i+2])

Submission status: Wrong Answer

Solution code:
n,k=map(int,input().split())
if (n+1)//2<k:print(-1);exit()
a=[k+i for i in range(n)]
b=[n+i for i in a]
c=[n+i for i in b]
from bisect import bisect_left as bl
i=n-1
j=bl(b,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])
if n%2==0:
  for i in b:
    if not i in bs:bb=i
  print(a[0],bb,c[0])

Submission status: Wrong Answer

Solution code:
n,k=map(int,input().split())
if (n+1)//2<k:print(-1);exit()
a=[k+i for i in range(n)]
b=[n+i for i in a]
c=[n+i for i in b]
from bisect import bisect_left as bl
i=n-1
j=bl(b,2*n)
print(k+n-1,2*n,k+3*n-1)
bs=set()
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])
if n%2==0:
  for i in b:
    if not i in bs:bb=i
  print(a[0],bb,c[0])

Submission status: Wrong Answer

Solution code:
#                         author:  kagemeka 
#                         created: 2019-11-09 21:20:16(JST)
### modules
## from standard library
import sys
# import collections
# import math
# import string
# import bisect
# import re
# import itertools
# import statistics
# import functools
# import operator
## from external libraries
# import scipy.special   
# import scipy.misc      
# import numpy as np 

def main():
    n, k = (int(x) for x in sys.stdin.readline().split())
    if n - 2 * k + 1 >= 0:
        # 存在する
        print(k, 2 * n, k + 2 * n)

        
    else:
        print(-1)



if __name__ == "__main__":
    # execute only if run as a script
    main()

Submission status: Wrong Answer

Solution code:
import bisect
n,k=map(int,input().split())
if n*(k-1)>n*(n-1)//2:
    print(-1)
    exit()
a=k
c=k+2*n
b=c-a
z=set(range(k,k+2*n))
ans=[]
f=0
for i in range(n):
    if b in z:
        print(a,b,c)
        z.remove(b)
        z.remove(a)            
    else:
        if f==0:
            a+=1
            f=1
        else:
            b-=1
            f=0
        continue
    
    c+=1
    a+=1
    b=c-a

Submission status: Wrong Answer

Solution code:
n,k = map(int,input().split())
m=list()
for i in range(3*n):
    m.append(k+i)
x=0
r=True
while (x<3*n):
    if (m[x]+m[x+1]>m[x+2]):
        r=False
    x=x+3
if (r):
    x=0
    while (x<3*n):
        print (m[x], m[x+1], m[x+2])
        x=x+3
else:
    print(-1)

Submission status: Wrong Answer

Solution code:
N,K = map(int,input().split())
if K == 1:
    for i in range(N):
        a = K + i
        b = K + 2*N - 1 - i
        c = K + 2*N + i
        print(a,b,c)
else:
    print(-1)

Submission status: Wrong Answer

Solution code:
k, n = map(int, input().split())
if k + n > 2:
  print(-1)
else:
  print('1 2 3')

Submission status: Wrong Answer

Solution code:
import bisect
n,k=map(int,input().split())
if n*(k-1)>n*(n-1)//2:
    print(-1)
    exit()
a=k
c=k+2*n
b=c-a
z=set(range(k,k+2*n))
ans=[]
for i in range(n):
    bi=b-1
    if bi>0:
        print(a,bi,c)     
    else:
        a+=1
        continue
    
    c+=1
    a+=1
    b=c-a

Submission status: Wrong Answer

Solution code:
import bisect
n,k=map(int,input().split())
if n*(k-1)>n*(n-1)//2:
    print(-1)
    exit()
a=k
c=k+2*n
b=c-a
z=set(range(k,k+2*n))
ans=[]
for i in range(n):
    bi=b-1
    if bi>0:
        print(a,list(z)[bi-1],c)     
    else:
        a+=1
        continue
    
    c+=1
    a+=1
    b=c-a