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

Submission status: Wrong Answer

Solution code:
n, k = map(int, input().split())
if k != 1:
    print(-1)
else:
    ra = [i for i in range(k, k+3*n)]
    for i in range(n):
        print(" ".join(map(str, ra[i::n])))

Submission status: Wrong Answer

Solution code:
N,K = map(int,input().split())
if K != 1:
  print(-1)

Submission status: Wrong Answer

Solution code:
N,K = map(int,input().split())
if K > 1:
    print(-1)
    exit()

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 n+1>=2*k:
  a=n
  b=k+(2*n)-1
  c=k+(3*n)-1
  print(a,b,c)
else:
  print(-1)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

if k != 1:
    print(-1)
else:
    for i in range(1, n+1):
        print(i, i+n, i+n+n)

Submission status: Wrong Answer

Solution code:
import copy
def main():
    n,k = map(int,input().split()) 
    if 2*k-1>n:
        print(-1)
        return
    if k==1:
        for i in range(n):
            print(i+1,2*n+k-1-i,k+3*n-1-i)
    else:
        if k%2==0:
            print(k//2+n-1,k//2+n+1,k+2*n)
            print(k//2+n,k//2+n+2,k+3*n-1)
            for i in range(n-2):
                print(k+i,k+2*n-1-i,k+3*n-2-i)
        else:
            print((k+2*n-1)//2,(k+2*n+1)//2,k+2*n)
            print((k+2*n+1)//2+1,(k+2*n+1)//2+2,k+3*n-1)
            for i in range(n-2):
                print(k+i,k+2*n-1-i,k+3*n-2-i)
 
if __name__ == "__main__":
    main()

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
import bisect
import heapq
import math
import random
import sys
from collections import Counter, defaultdict, deque
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations
from operator import add, mul, sub

sys.setrecursionlimit(100000)
input = sys.stdin.readline
INF = 2**62-1

def read_int():
    return int(input())


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


def read_float():
    return float(input())


def read_float_n():
    return list(map(float, input().split()))


def read_str():
    return input().strip()


def read_str_n():
    return list(map(str, input().split()))


def error_print(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap


@mt
def slv(N, K):
    if K != 1:
        print(-1)
        return

    for i in range(N):
        print("%d %d %d" % (K + i,  K + 2*N - (i+1), K + 2*N + i))


def main():
    N, K = read_int_n()
    (slv(N, K))


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
N,K = map(int, input().split())
flg = True
for idx in range(N):
    if (idx > N - K):
        flg = False
        break
if (flg):
    for idx in range(N):
        print(str(K+idx) + " " + str(K+idx+N) + " " + str(K+idx+(N*2)))
else:
    print(-1)

Submission status: Wrong Answer

Solution code:
n, k = (int(i) for i in input().split())

if n%2==1:
    if k>(n+1)/2:
        print(-1)
    else:
        wlist=[]
        for i in range(n):
            if i<=n/2:
                wlist.append([k-i+2*n, k+i, 2*(n-i)])
            else:
                wlist.append([k+3*n-i, k+i, n+2*(n-i)])
        wlist=sorted(wlist)
        #print(wlist)
        for i in range(n):
            print(wlist[i][1], wlist[i][2], k+2*n+i)
else:
    if k<=2:
        wlist=[]
        for i in range(n):
            if i<n/2:
                wlist.append([k-i+2*n+1, k+i, 2*(n-i)])
            else:
                wlist.append([k+3*n-i+1, k+i, n+2*(n-i)+1])
        wlist=sorted(wlist)
        #print(wlist)
        for i in range(n):
            print(wlist[i][1], wlist[i][2], k+2*n+i)
    else:
        print(-1)

Submission status: Wrong Answer

Solution code:
N,K=map(int,input().split())
a=list(range(K,K+N*3))
if (a[-N-1]+a[0]<=a[-N]):
  for i in range(0,N):
    print(a[0+i],a[-N-1-i],a[-N+i])
else:
  print(-1)

Submission status: Wrong Answer

Solution code:
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):
    z.remove(a)
    if b in z:
        z.remove(b)
    else:
        a+=1
        continue
    print(a,b,c)
    c+=1
    a+=1
    b=c-a

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
import bisect
import heapq
import math
import random
import sys
from collections import Counter, defaultdict, deque
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations
from operator import add, mul, sub

sys.setrecursionlimit(100000)
input = sys.stdin.readline
INF = 2**62-1

def read_int():
    return int(input())


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


def read_float():
    return float(input())


def read_float_n():
    return list(map(float, input().split()))


def read_str():
    return input().strip()


def read_str_n():
    return list(map(str, input().split()))


def error_print(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap


@mt
def slv(N, K):
    if (K + N-1) + ( K + 2*N-1) > K+ 3*N - 1:
        print(-1)
        return
    for i in range(N):
        print("%d %d %d" % (K + i,  K + N + i, K + 2*N + i))
    # return 0


def main():
    N, K = read_int_n()
    (slv(N, K))


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import numpy as np
import sys
N,K = map(int,input().split())
A = np.zeros(3 * N, dtype="int64")
for i in range (0,3 * N):
  A[i] = K + i
for i in range (0,N):
  if (A[i] + A[2*N-i-1] > A[3*N-i-1]):
    print("-1")
    sys.exit()
  
for i in range (0,N):
  print("Yes")

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import numpy as np
import sys
N,K = map(int,input().split())
A = np.zeros(3 * N, dtype="int64")
for i in range (0,3 * N):
  A[i] = K + i
for i in range (0,N):
  if (A[i] + A[2*N-i-1] > A[3*N-i-1]):
    print("-1")
    sys.exit()

for i in range (0,N):
  print(A[i],A[2*N-i-1],A[3*N-i-1])

Submission status: Wrong Answer

Solution code:
N, K = map(int, input().split())
if K > 1:
  print(-1)
  exit()
for i in range(1, N+1):
  print(i, i+N, i+N+N)

Submission status: Wrong Answer

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

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
n, k = list(map(int, input().split()))
if n % 2 == 1:
    if k + n // 2 + k + 2 * n - 1 > k + 3 * n - 1:
        print(-1)
    else:
        small = list(range(k, k + n))
        large = list(range(k + n, k + 2 * n))
        large = large[n // 2:] + large[:n // 2]
        total = list(range(k + 2 * n, k + 3 * n))
        total = total[::2] + total[1::2]
        for a, b, c in zip(small, large, total):
            print(a, b, c)
else:
    if k + (n - 1) // 2 + k + 2 * n - 1 + 1 > k + 3 * n - 1:
        print(-1)
    else:
        small = list(range(k, k + n))
        large = list(range(k + n, k + 2 * n))
        total = list(range(k + 2 * n, k + 3 * n - 1))
        for a, b, c in zip(small[:n // 2], large[n // 2:], total[::2]):
            print(a, b, c)
        for a, b, c in zip(small[n // 2:], large[:n // 2], total[1::2]):
            print(a, b, c)

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline

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


if K+(K+2*N-1)<=K+2*N:
    for i in range(N):
        print(K+i,K+2*N-1-i,K+2*N+i)

else:
    print(-1)

Submission status: Wrong Answer

Solution code:
import sys
readline = sys.stdin.readline
from itertools import accumulate
from collections import Counter
from bisect import bisect as br, bisect_left as bl
class PMS:
    #1-indexed
    def __init__(self, A, B, issum = False):
        #Aに初期状態の要素をすべて入れる,Bは値域のリスト
        self.X, self.comp = self.compress(B)
        self.size = len(self.X)
        self.tree = [0] * (self.size + 1)
        self.p = 2**(self.size.bit_length() - 1)
        self.dep = self.size.bit_length()
        
        CA = Counter(A)
        S = [0] + list(accumulate([CA[self.X[i]] for i in range(self.size)]))
        for i in range(1, 1+self.size):
            self.tree[i] = S[i] - S[i - (i&-i)]
        if issum:
            self.sumtree = [0] * (self.size + 1)
            Ssum = [0] + list(accumulate([CA[self.X[i]]*self.X[i] for i in range(self.size)]))
            for i in range(1, 1+self.size):
                self.sumtree[i] = Ssum[i] - Ssum[i - (i&-i)]
    
    def compress(self, L):
        #座圧
        L2 = list(set(L))
        L2.sort()
        C = {v : k for k, v in enumerate(L2, 1)}
        # 1-indexed
        return L2, C
    
    def leng(self):
        #今入っている個数を取得
        return self.count(self.X[-1])
    
    def count(self, v):
        #v(Bの元)以下の個数を取得
        i = self.comp[v]
        s = 0
        while i > 0:
            s += self.tree[i]
            i -= i & -i
        return s
    
    def less(self, v):
        #v(Bの元である必要はない)未満の個数を取得
        i = bl(self.X, v)
        s = 0
        while i > 0:
            s += self.tree[i]
            i -= i & -i
        return s
    
    def leq(self, v):
        #v(Bの元である必要はない)以下の個数を取得
        i = br(self.X, v)
        s = 0
        while i > 0:
            s += self.tree[i]
            i -= i & -i
        return s
 
    def add(self, v, x):
        #vをx個入れる,負のxで取り出す,iの個数以上取り出すとエラーを出さずにバグる
        i = self.comp[v]
        while i <= self.size:
            self.tree[i] += x
            i += i & -i

    def get(self, i):
        # i番目の値を取得
        if i <= 0:
            return -1
        s = 0
        k = self.p
        for _ in range(self.dep):
            if s + k <= self.size and self.tree[s+k] < i:
                s += k
                i -= self.tree[s]
            k //= 2
        return self.X[s]
    
    def gets(self, v):
        #累積和がv以下となる最大のindexを返す
        v1 = v
        s = 0
        k = self.p
        for _ in range(self.dep):
            if s + k <= self.size and self.sumtree[s+k] < v:
                s += k
                v -= self.sumtree[s]
            k //= 2
        if s == self.size:
            return self.leng()
        return self.count(self.X[s]) + (v1 - self.countsum(self.X[s]))//self.X[s]
    
    def addsum(self, i, x):
        #sumを扱いたいときにaddの代わりに使う
        self.add(i, x)
        x *= i
        i = self.comp[i]
        while i <= self.size:
            self.sumtree[i] += x
            i += i & -i
    
    def countsum(self, v):
        #v(Bの元)以下のsumを取得
        i = self.comp[v]
        s = 0
        while i > 0:
            s += self.sumtree[i]
            i -= i & -i
        return s
    
    def getsum(self, i):
        #i番目までのsumを取得
        x = self.get(i)
        return self.countsum(x) - x*(self.count(x) - i)


N, K = map(int, readline().split())
C = list(range(K+2*N, K+3*N))
Ans = []

abl = list(range(K, K+2*N))
AB = PMS(abl, abl)

ans = -1
for i in range(N):
    c = C[N-1-i]
    bx = AB.get(2*N-2*i)
    AB.add(bx, -1)
    if c < bx:
        break
    bn = c - bx
    k = AB.leq(bn)
    if k == 0:
        break
    a = AB.get(k)
    b = bx
    AB.add(a, -1)
    Ans.append((a, b, c))
else:
    print('\n'.join('{} {} {}'.format(*a) for a in Ans))
    ans = 1
if ans == -1:
    print(ans)

Submission status: Wrong Answer

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

if N==K==1:
    print(1,2,3)
else:
    print(-1)

Submission status: Wrong Answer

Solution code:
n, k = list(map(int, input().split()))
if n % 2 == 1:
    if k + n // 2 + k + 2 * n - 1 > k + 3 * n - 1:
        print(-1)
    else:
        small = list(range(k, k + n))
        large = list(range(k + n, k + 2 * n))
        large = large[n // 2:] + large[:n // 2]
        for a, b in zip(small, large):
            print(a, b, a + b)
else:
    if k + (n - 1) // 2 + k + 2 * n - 1 + 1 > k + 3 * n - 1:
        print(-1)
    else:
        small = list(range(k, k + n))
        large = list(range(k + n, k + 2 * n))
        for a, b in zip(small[:n // 2], large[n // 2:]):
            print(a, b, a + b)
        for a, b in zip(small[n // 2:], large[:n // 2]):
            print(a, b, a + b + 1)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
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)
else:
    print(-1)

Submission status: Wrong Answer

Solution code:
n,k=map(int,input().split())
if k==1:
  for i in range(n):
    print(i+1,n+(n-i),2*n+i+1)
elif k>=3:
  print(-1)
elif k==2 and n==3:
  print(3,5,8)
  print(2,7,9)
  print(4,6,10)
else:
  print(-1)

Submission status: Wrong Answer

Solution code:
n,k=map(int,input().split())
a=k
b=k+1
c=k+3*n-1-(n-1)
d=c-(a+b)
a2=k
b2=c-1
c2=c
if d-(3*(n-1))>=0:
    for i in range(n):
        print(a,b,c)
        a+=2
        b+=2
        c+=1
elif a2+b2<=c2:
    for i in range(n):
        print(a2,b2,c2)
        a2+=1
        b2-=1
        c2+=1
else:
    print(-1)

Submission status: Wrong Answer

Solution code:
n,k=map(int,input().split())
a=k
b=k+1
c=k+3*n-1-(n-1)
d=c-(a+b)
if d-(3*(n-1))>=0:
    for i in range(n):
        print(a,b,c)
        a+=2
        b+=2
        c+=1
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:
        print(-1)
    else:
        for i in range(n):
            print(i+1,i+1+n,i+1+2*n)
    return

#Solve
if __name__ == "__main__":
    solve()

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
#設定
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 K != 1:
		print(-1)
	else:
		for i in range(N):
			a = i + 1
			b = K + 2 * N - 1 - i
			c = K + 2 * N + i
			ans = [a, b, c]
			print(" ".join(list(map(str, ans))))

if __name__ == '__main__':
	main()

Submission status: Wrong Answer

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

if(K!=1 or K > N):
    print(-1)
else:
    for i in range(N):
        list = [K+i, K+N+i, K+2*N+i]
        print(*list, sep=' ')

Submission status: Time Limit Exceeded

Solution code:
N,K=map(int,input().split())
[[0,0,K+(2*N)+i] for i in range(N)]
#K~K+2N-1  K+2N~K+3N-1
#（はじめ　終わり）/2*こすう
A=((2*K)+(2*N)-1)*N
B=(((2*K)+(5*N)-1)*N)//2
if A>B:
  print(-1)
  exit()
L=list(range(K+(2*N),K+(3*N)))
L=list(reversed(L))
R=list(range(K,K+(2*N)))
for i in range(N):
  for j in range(N):
    n=R[j]
    if L[i]-n in R:
      R.remove(n)
      R.remove(L[i]-n)
      print(n,L[i]-n,L[i])
      break

Submission status: Time Limit Exceeded

Solution code:
n, k = map(int, input().split())
if n*k+2*n*n-n>2*n*n+(n*(n-1)/2):
  print(-1)
else:
  a = 0
  while True:
    a+=1

Submission status: Time Limit Exceeded

Solution code:
N,K = map(int, input().split())
l1=list(range(K,K+N))
l2=list(range(K+N,K+2*N))
l3=list(range(K+2*N,K+3*N))
answer_list = [[0 for i in range(3)] for j in range(N)]
not_found_list = []
not_found_idx_list = []
flg = True
if 2*K-N-1 > 0:
    print(-1)
    exit()
for idx in reversed(range(N)):
    a3=l3[idx]
    innerFlg1 = False
    if (a3 % 2 == 0):
        for idy in reversed(range(N)):
            a2=l2[idy]
            if (a2==0):
                continue       
            if (len(l1) <= a3-a2-K):
                break
            if (l1[a3-a2-K] != 0):
                answer_list[idx] = [l1[a3-a2-K], a2, a3]
                l1[a3-a2-K]=0
                l2[idy]=0
                innerFlg1=True
                break
    else:
        for idy in reversed(range(N)):
            a1=l1[idy]
            if (a1==0):
                continue
            if (len(l2) <= a3-a1-K-N):
                break
            if (l2[a3-a1-K-N] != 0):
                answer_list[idx] = [a1, l2[a3-a1-K-N], a3]
                l1[idy]=0
                l2[a3-a1-K-N]=0
                innerFlg1=True
                break                
    if innerFlg1 == False:
        not_found_list.append(a3)
        not_found_idx_list.append(idx)

        
for idx in range(len(not_found_list)):
    a3=not_found_list[idx]
    for idy in reversed(range(N)):
        a2=l2[idy]
        if (a2==0):
            continue
        for idz in reversed(range(N)):
            a1=l1[idz]
            if (a1==0):
                continue
            if (a1 + a2 < a3):
                answer_list[not_found_idx_list[idx]] = [a1, a2, a3]
                l1[idz]=0
                l2[idy]=0
                innerFlg1=True
                break
        if innerFlg1==True:
            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: Time Limit Exceeded

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

if 2*K+1 > K+2*N:
    print(-1)
elif K + (K+2*N-1) > K+3*N-1:
    print(-1)

else:
    C = list(range(K+2*N,K+3*N))
    AB = list(range(K,K+2*N))
    submit = list()
    for i in range(N):
        c = C[::-1][i]
        a = AB.pop(AB.index(max(AB)))
        try:
            b = AB.pop(AB.index(max([x for x in AB if x <= c-a])))
        except:
            print(-1)
            break

        submit += [str(a) +" "+ str(b) + " " + str(c)] 

    if len(submit) == N:
        for s in submit:
            print(s)

Submission status: Time Limit Exceeded

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

if 2*K+1 > K+2*N:
    print(-1)
elif K + (K+2*N-1) > K+3*N-1:
    print(-1)

else:
    C = list(range(K+2*N,K+3*N))
    AB = list(range(K,K+2*N))
    submit = list()
    for i in range(N):
        c = C[::-1][i]
        a = max(AB)
        if not [x for x in AB if x <= c-a]:
            print(-1)
            break
        b = max([x for x in AB if x <= c-a])

        AB.remove(a)
        AB.remove(b)
        submit += [str(a) +" "+ str(b) + " " + str(c)] 

    if len(submit) == N:
        for s in submit:
            print(s)

Submission status: Time Limit Exceeded

Solution code:
N,K = map(int, input().split())
l=[1] * (3*N)
answer_list = [[0 for i in range(3)] for j in range(N)]
flg = True
for idx in range(N):
    innerFlg = False
    for idy in reversed(range(N)):
        if (l[N+idy] == 0):
            continue
        for idz in range(N):
            if (l[(2*N)+idz]==0):
                continue
            if (idx + idy <= N - K + idz):
                answer_list[idx] = [K+idx, K+N+idy, K+(2*N)+idz]
                l[N+idy] = 0
                l[(2*N)+idz]=0
                innerFlg=True
                break
    if innerFlg == 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: Time Limit Exceeded

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=bisect.bisect_right(list(z),b)
    if bi>0:
        print(a,list(z)[bi-1],c)     
    else:
        a+=1
        continue
    
    c+=1
    a+=1
    b=c-a

Submission status: Time Limit Exceeded

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=bisect.bisect_right(list(z),b)
    if bi>0:
        if list(z)[bi-1] in z:
            print(a,list(z)[bi-1],c)     
    else:
        a+=1
        continue
    
    c+=1
    a+=1
    b=c-a

Submission status: Time Limit Exceeded

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=bisect.bisect_right(list(z),b)
    if bi>0:
        if list(z)[bi-1] in z:
            print(a,list(z)[bi-1],c)
            z.remove(list(z)[bi-1])       
    else:
        a+=1
        continue
    
    c+=1
    a+=1
    b=c-a

Submission status: Time Limit Exceeded

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=bisect.bisect_right(list(z),b)
    if bi>0:
        print(a,list(z)[bi-1],c)
        z.remove(list(z)[bi-1])
        z.remove(a)            
    else:
        a+=1
        continue
    
    c+=1
    a+=1
    b=c-a

Submission status: Time Limit Exceeded

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=bisect.bisect_right(list(z),b)
    if bi>0:
        if list(z)[bi-1] in z:
            print(a,list(z)[bi-1],c)
            z.remove(list(z)[bi-1])
            z.remove(a)            
    else:
        a+=1
        continue
    
    c+=1
    a+=1
    b=c-a

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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) ))

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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

    #test=[]
    #for a,b,c in ans:
        #if a+b>c:
            #print("WA")
        #else:
            #test.append(a)
            #test.append(b)
            #test.append(c)

    #test.sort()
    #check=[i for i in range(K,K+3*N)]
    #if test==check:
        #print("AC")
    #else:
        #print("WA")

Submission status: Accepted

Solution code:
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])

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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)