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:
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, (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, (i + n * 3) // 2, k + i + n * 2)
            else:
                print(k + i // 2 + n // 2 + 1, i // 2 + n + k, k + i + n * 2)

Submission status: Wrong Answer

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, (i + n * 3) // 2, k + i + n * 2)
            else:
                print(k + i // 2 + n // 2, k + i // 2 + n, k + i + n * 2)
        print()
    else:
        for i in range(n):
            if i % 2 == 0:
                print(k + i // 2, (i + n * 3) // 2, k + i + n * 2)
            else:
                print(k + i // 2 + n // 2 + 1, i // 2 + n + k, k + i + n * 2)

Submission status: Wrong Answer

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(i // 2 + k, (i + n * 3) // 2, i + n * 2 + k, end=" ")
            else:
                print(i // 2 + n // 2 + k, i // 2 + n + k, i + n * 2 + k, end=" ")
    else:
        for i in range(n):
            if i % 2 == 0:
                print(i // 2 + k, (i + n * 3) // 2, i + n * 2 + k, end=" ")
            else:
                print(i // 2 + n // 2 + k + 1, i // 2 + n + k, i + n * 2 + k, end=" ")

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+i)

Submission status: Wrong Answer

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 - (n-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: Wrong Answer

Solution code:
N,K=map(int,input().split())
P=[]
X=K
S=set()
Y=K+3*N-1
for i in range(N):
  if X in S or Y in S or Y-X in S:
    print(-1)
    exit()
  if Y-X<K or Y-X>=K+3*N:
    print(-1)
    exit()
  S.add(X)
  S.add(Y)
  S.add(Y-X)
  P.append([X,Y-X,Y])
  Y-=1
  X+=1
for i in range(N):
  print(*P[i])

Submission status: Wrong Answer

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 + i
    for i in range(n - n // 2):
        a[i * 2] = k + n // 2 + i
    a.reverse()
    for i in range(n):
        print(a[i], b[i], c[i])
else:
    print(-1)

Submission status: Wrong Answer

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


main()

Submission status: Wrong Answer

Solution code:
print(-1)

Submission status: Wrong Answer

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

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:
      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:
      ans.append([a,b,cand.pop()])
  for a,b,c in ans:
    print(a,b,c)
else:
  print(-1)

Submission status: Wrong Answer

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:
  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]+=1
  ans=ans1+ans2
  for a,b,c in ans:
    print(a,b,c)
else:
  print(-1)

Submission status: Wrong Answer

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:
  ans1=[[k+i,k+2*n-2-i*2,2*k+2*n-i-2] for i in range(k-1)]
  ans2=[[k+k-1+i,k+2*n-1-i*2,3*k+2*n-i-2] for i in range(n-(k-1))]
  ans=ans1+ans2
  for a,b,c in ans:
    print(a,b,c)
else:
  print(-1)

Submission status: Wrong Answer

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
  for i in range(n):
    if checked[i+diff]==0:
      checked[i+diff]=1
      pair[i][0],pair[i+diff][0]=pair[i+diff][0],pair[i][0]
      diff-=1
      if diff==0:
        break
  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:
      ans.append([a,b,cand.pop()])
  for a,b,c in ans:
    print(a,b,c)
else:
  print(-1)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
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
#    print(d,loop)
    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):
            # 要素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が属するグループとを併合する
            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):
            # 要素x, yが同じグループに属するかどうかを返す
            return self.find(x) == self.find(y)

        def size(self, x):
            # 要素xが属するグループのサイズ（要素数）を返す
            x = self.find(x)
            return -self.parent[x]

        def is_root(self, x):
            # すべての根の要素をリストで返す
            return self.parent[x] < 0

        def members(self, x):
            # 要素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)
#    print(sorted_B); print(sorted_indices)
    d = defaultdict(int)
#    print(sortA,sortB)
    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)]  # (dist,vertex)
            while (Q):
                dist, v = heapq.heappop(Q)
                if self.dist[v] < dist: continue  # 候補として挙がったd,vだが、他に短いのがある
                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))
#    print(V)
    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]
        b = A2[N-1-2*i]
        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()

"""

"""

Submission status: Wrong Answer

Solution code:
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
#    print(d,loop)
    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):
            # 要素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が属するグループとを併合する
            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):
            # 要素x, yが同じグループに属するかどうかを返す
            return self.find(x) == self.find(y)

        def size(self, x):
            # 要素xが属するグループのサイズ（要素数）を返す
            x = self.find(x)
            return -self.parent[x]

        def is_root(self, x):
            # すべての根の要素をリストで返す
            return self.parent[x] < 0

        def members(self, x):
            # 要素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)
#    print(sorted_B); print(sorted_indices)
    d = defaultdict(int)
#    print(sortA,sortB)
    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)]  # (dist,vertex)
            while (Q):
                dist, v = heapq.heappop(Q)
                if self.dist[v] < dist: continue  # 候補として挙がったd,vだが、他に短いのがある
                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))
#    print(V)
    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)]
    A = [K+i for i in range(N*3)]
    if A[-1]<A[2*N-1]+A[2*N-2]:
        print(-1)
        return
    for i in range(N):
        ans[i] = [A[2*N-1-i*2],A[2*N-2-i*2],A[-i-1]]
    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()

"""

"""

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
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 k+K>2*N+i+K:
        print(-1)
        break
    print(j+K, k+K, 2*N+i+K)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

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

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

ans.sort(key=lambda x: x[0] + x[1])

for i in range(n):
    ans[i].append(k+2*n+i)
    print(*ans[i])

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(k+r)
    res.append(b)
    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:
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):
    print(k + 2*i, k + n + ((n+1) // 2) - 1 - i, k + 2 * n + i)
for i in range(n // 2):
    print(k + 1 + 2*i, k + n + ((n+1) // 2) + i, k + 2*n + ((n+1) // 2) + i)

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:
def gn(n,k):
    k -= 1
    r = k+2*n+n//2 - (1 + 2*k + 2*n)
    if r < 0:
        print(-1)
        return
    print(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)

Submission status: Wrong Answer

Solution code:
def gn(n,k):
    k -= 1
    r = k+2*n+n//2 - (1 + 2*k + 2*n)
    if r < 0:
        print(-1)
        return
    print(1, 2*n+k, 2*n+k+2)
    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)

Submission status: Wrong Answer

Solution code:
def gn(n,k):
    k -= 1
    r = k+2*n+n//2 - (1 + 2*k + 2*n)
    if r < 0:
        print(-1)
        return
    print(1, 2*n+k, 2*n+k+1)
    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)

Submission status: Wrong Answer

Solution code:
from heapq import heapify, heappop

N, K = map(int, input().split())
R = K + 3 * N - 1

V = []
for i in range(N):
    V.append((R - i - (K + i), K + i, R - i))

heapify(V)

ans = []
for m in range(K + N, R - N + 1)[:: -1]:
    _, s, b = heappop(V)
    if s + m > b:
        print('-1')
        exit()
    ans.append((s, m, b))

for a in ans:
    print(*a)

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

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

ab = []
ai = 0
bi = N - 1
ad = 2
for _ in range(N):
    ab.append((ai, bi))
    ai += ad
    bi -= 1
    if ai == N:
        ai -= 1
        ad *= -1
    if ai == N + 1:
        ai -= 3
        ad *= -1

first_c = max(K + 2 * N, ab[0][0] + ab[0][1] + 2 * K + N)
c = first_c
cd = 1
for ai, bi in ab:
    a = K + ai
    b = K + N + bi
    print(a, b, c)
    c += cd
    if c >= K + 3 * N:
        c = first_c - 1
        cd *= -1

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

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

ab = []
ai = 0
bi = N - 1
ad = 2
for _ in range(N):
    ab.append((ai, bi))
    ai += ad
    bi -= 1
    if ai == N:
        ai -= 1
        ad *= -1
    if ai == N + 1:
        ai -= 3
        ad *= -1

c = max(K + 2 * N, ab[0][0] + ab[0][1] + 2 * K + N)
for ai, bi in ab:
    a = K + ai
    b = K + N + bi
    print(a, b, c)
    c += 1
    if c >= K + 3 * N:
        c -= N

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

# 解説AC
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):
    ab.append((ai, bi))
    ai = (ai + 2) % N
    bi = (bi - 1) % N
    if ai == 0:
        # もう選んだ
        ai += 1
c = max(K + 2 * N, ab[0][0] + ab[0][1] + 2 * K + N)
for ai, bi in ab:
    a = K + ai
    b = K + N + bi
    print(a, b, c)
    c += 1
    if c >= K + 3 * N:
        c -= N

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

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

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

Submission status: Wrong Answer

Solution code:
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-N//2, K+2*N)]
    C = [c for c in range(K+2*N, K+3*N)]
    [print(*p) for p in list(map(list, zip(A, B, C)))]

Submission status: Wrong Answer

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

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 2 * K - 1 > N:
		print(-1)
	else:
		if N % 2 == 1:
			ans = [[0, 0, 0] for i in range(N)]
			print(ans)
			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()

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:
import sys

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

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


elif N > 2:
    ans = []
    na = K+2*N-1
    nb = K+N-2
    nc = K+3*N-1

    for i in range(N):

        if na + nb <= nc:
            ans.append([na,nb,nc])
        else:
            print (-1)
            sys.exit()

        if i % 2 == 0:
            na -= 2
            nb += 1

        else:
            na += 1
            nb -= 2

        nc -= 1

    for i in ans:

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

else:
    
    ans = []
    na = K+2*N-1
    nb = K
    nc = K+3*N-1

    for i in range(N):

        if na + nb <= nc:
            ans.append([na,nb,nc])
        else:
            print (-1)
            sys.exit()

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

    for i in ans:

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

Submission status: Wrong Answer

Solution code:
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 k + k+2*n-1 <= (k+2*n + k+3*n-1)/2:
  for i in range(n//2+n%2):
    a = s1 + i*2
    b = s4 - i
    c = (s5+s6+1)//2 + i
    print(a, b, c)
  for i in range(n//2-n%2):
    a = s1 + 1 + i*2
    b = (s3+s4-1)//2 - i
    c = s5 + i
    print(a, b, c)
else:
  print(-1)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

if __name__ =='__main__':
    main()

Submission status: Wrong Answer

Solution code:
import math
N, K = map(int,input().split())
if K != 1: #(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)