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

Solution code:

from collections import defaultdict,deque
import sys,heapq,bisect,math,itertools,string,queue,copy,time
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
eps = 10**-7
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpl_str(): return list(sys.stdin.readline().split())

N,K = inpl()


sab = [[i,i,0] for i in range(N)]

cnt = N
for i in range(N//2, N):
    sab[i][2] = cnt
    sab[i][0] += cnt
    cnt += 1

for i in range(N//2):
    sab[i][2] = cnt
    sab[i][0] += cnt
    cnt += 1

sab.sort()

C = N*2
ans = []
for s,a,b in sab:
    if s+K <= C:
        tmpl = [a+K,b+K,C+K]
        ans.append(' '.join(map(str,tmpl)))
    else:
        print(-1)
        sys.exit()
    C += 1

print('\n'.join(ans))

Submission status: Accepted

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

Solution code:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

import numpy as np

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

def solve_even(N,K):
    L = N//2
    x = np.arange(K,K+N)
    y = np.concatenate([np.arange(K+L+N,K+L+N+L),np.arange(K+N,K+L+N)])
    add = N-(K+L)
    z = x + y + add
    z[L:] += 1
    answer = np.vstack([x,y,z]).T
    print('\n'.join(' '.join(row) for row in answer.astype(str)))

def solve_odd(N,K):
    L = N//2
    x = np.arange(K,K+N)
    y = np.concatenate([np.arange(K+L+N,K+L+N+L+1),np.arange(K+N,K+L+N)])
    add = N-(K+L)
    z = x + y + add
    answer = np.vstack([x,y,z]).T
    print('\n'.join(' '.join(row) for row in answer.astype(str)))

def solve(N,K):
    if K+K > N+1:
        print(-1)
        return
    if N&1:
        solve_odd(N,K)
    else:
        solve_even(N,K)

solve(N,K)

Submission status: Runtime Error

Solution code:
// #define _GLIBCXX_DEBUG // for STL debug (optional)
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
using namespace std;
using ll = long long int;
using int64 = long long int;
 
template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}
 
int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
const int INF = 1LL << 29;
const ll LONGINF = 1LL << 60;
const ll MOD = 1000000007LL;
 
int main() {
    ll N, K; scanf("%lld%lld", &N, &K);
    vector<int> A(N), B(N), C(N);
    for(int i=0; i<N; i++) {
        A[i] = K + i;
        B[i] = K + N + i;
        C[i] = K + 2*N + i;
    }

    int ptr = N-1;
    while(ptr >= 0 and A[N-1] + B[ptr] > C[N-1]) ptr--;

    if(ptr < 0) {
        cout << -1 << endl;
        return 0;
    }

    vector< pair<ll, ll> > ans;
    for(int i=0; i<N; i++) {
        ans.emplace_back(A[N-1-i], B[ptr]);
        ptr--;
        if(ptr < 0) ptr = N-1;
    }

    sort(ans.begin(), ans.end(), [](auto a, auto b) {
            return a.first + a.second < b.first + b.second;
        });

    bool ok = true;
    for(int i=0; i<N; i++) {
        ok &= (ans[i].first + ans[i].second <= C[i]);
    }

    if(ok) {
        for(int i=0; i<N; i++) {
            ll a, b, c; tie(a, b) = ans[i], c = C[i];
            printf("%lld %lld %lld\n", a, b, c);
        }
    }
    else {
        cout << -1 << endl;
    }
    return 0;
}

Submission status: Runtime Error

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

if 2 * k - 1 > n:
  print(-1)
else:
  d = (n + 1) // 2
  flag_a = False
  for i in range(n):
    a = k + i // 2
    b = k + n + i // 2
    c = k + 2 * n + i
    if flag_a:
      a += d
    else:
      b += d
    print(a, b, c)
    flag = not flag

Submission status: Runtime Error

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: Runtime Error

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 (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 (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[idy]
            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==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: Runtime Error

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: Runtime Error

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,data in enumerate(output())
        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(d))

main()

Submission status: Runtime Error

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(1, 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: Runtime Error

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*i+K+2*1+11<=K+2*N+i:
  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: Runtime Error

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+3N-half+i)]
        elif i < N-1 or kisu:
            hoge = [str(K+N-1-i), str(K+N+1-half+2*i), str(K+2N-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: Runtime Error

Solution code:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

n, k = map(int,readline().split())
if k + n//2 > n:
    print(-1)

a = range(k, k+n)
b = range(k+n, k+2*n)
c = range(k+2*n, k+3*n)

if n % 2 == 0:
    for i in range(n//2):
        print(a[2*i], b[n//2-i], c[i])
    print(a[-1], b[0], c[n//2])
    for i in range(n//2-1):
        print(a[2*i+1], b[n-i], c[n//2+1+i])
        
if n % 2 == 0:
    for i in range(n//2+1):
        print(a[2*i], b[n//2-i], c[i])
    for i in range(n//2):
        print(a[2*i+1], b[n-i], c[n//2+1+i])

Submission status: Runtime Error

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(1, N):
    ans.append((A[i], B[(i*2-1)%N], C[(i*3-3)%N]))

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

Submission status: Runtime Error

Solution code:
N, K =map(int, input().split())
Mylist = []
ANSlist = []
for i in range(N*3-1):
    Mylist.append(N+i)
listlen = len(Mylist)
for a in range(listlen):
    for b in range(listlen):
        for c in range(listlen):
            if Mylist[a] + Mylist[b] <= Mylist[c]:
                ANSlist.append([Mylist[a],Mylist[b],Mylist[c]])

ANSlist = set(ANSlist)
ANSlist = list(ANSlist)

if len(ANSlist) != N:
    print(-1)
else:
    for i in range(N):
        for j in range(3):
            print("{} {} {}".format(ANSlist[i][j],ANSlist[i][j],ANSlist[i][j]))

Submission status: Runtime Error

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

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

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

Submission status: Runtime Error

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))
A = list(range(K, K+N))
B = list(range(K+N, K+2*N))
Ans = []
ans = 1

BB = PMS(B, B)
if sum(A) + sum(B) > sum(C):
    ans = -1
else:
    Ao = [A[i] for i in range(N) if A[i]%2]
    Ae = [A[i] for i in range(N) if not A[i]%2]
    if len(Ao) < len(Ae):
        AA = Ae + Ao
    else:
        AA = Ao + Ae
    
    for a, c in zip(AA, C):
        bx = c - a
        k = BB.leq(bx)
        if k == 0:
            ans = -1
            break
        b = BB.get(k)
        Ans.append((a, b, c))
        BB.add(b, -1)

if ans != -1:
    print('\n'.join('{} {} {}'.format(*an) for an in Ans))
else:
    print(ans)
for _ in range(test_case):
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))
A = list(range(K, K+N))
B = list(range(K+N, K+2*N))
Ans = []
ans = 1

BB = PMS(B, B)
if sum(A) + sum(B) > sum(C):
    ans = -1
else:
    Ao = [A[i] for i in range(N) if A[i]%2]
    Ae = [A[i] for i in range(N) if not A[i]%2]
    if len(Ao) < len(Ae):
        AA = Ae + Ao
    else:
        AA = Ao + Ae
    
    for a, c in zip(AA, C):
        bx = c - a
        k = BB.leq(bx)
        if k == 0:
            ans = -1
            break
        b = BB.get(k)
        Ans.append((a, b, c))
        BB.add(b, -1)

if ans != -1:
    print('\n'.join('{} {} {}'.format(*an) for an in Ans))
else:
    print(ans)

Submission status: Runtime Error

Solution code:
for _ in range(test_case):
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))
A = list(range(K, K+N))
B = list(range(K+N, K+2*N))
Ans = []
ans = 1

BB = PMS(B, B)
if sum(A) + sum(B) > sum(C):
    ans = -1
else:
    Ao = [A[i] for i in range(N) if A[i]%2]
    Ae = [A[i] for i in range(N) if not A[i]%2]
    if len(Ao) < len(Ae):
        AA = Ae + Ao
    else:
        AA = Ao + Ae
    
    for a, c in zip(AA, C):
        bx = c - a
        k = BB.leq(bx)
        if k == 0:
            ans = -1
            break
        b = BB.get(k)
        Ans.append((a, b, c))
        BB.add(b, -1)

if ans != -1:
    print('\n'.join('{} {} {}'.format(*an) for an in Ans))
else:
    print(ans)

Submission status: Runtime Error

Solution code:
import numpy as np
n, m = map(int, input().split())
ro = [[0 for i in range(n)] for i in range(n)]
lis = np.array([[int(i) for i in input().split(" ")] for i in range(m)])
lis = lis[lis[:,0].argsort(), :]
for i in lis:
    l, r, c = i
    for j in range(i[0]-1, i[1]-1):
        for k in range(i[0], i[1]):
            if ro[j][k] == 0:
                ro[j][k] = i[2]
                ro[k][j] = i[2]
            else:
                if ro[j][k] > i[2]:
                    ro[j][k] = i[2]
                    ro[k][j] = i[2]
             


route_list = ro

node_num = len(route_list) #ノードの数

unsearched_nodes = list(range(node_num)) # 未探索ノード
distance = [float("inf")] * node_num # ノードごとの距離のリスト
previous_nodes = [-1] * node_num # 最短経路でそのノードのひとつ前に到達するノードのリスト
distance[0] = 0 # 初期のノードの距離は0とする

def get_target_min_index(min_index, distance, unsearched_nodes):
    start = 0
    while True:
        index = distance.index(min_index, start)
        found = index in unsearched_nodes
        if found:
            return index
        else:
            start = index + 1

while(len(unsearched_nodes) != 0): #未探索ノードがなくなるまで繰り返す
    # まず未探索ノードのうちdistanceが最小のものを選択する
    posible_min_distance = float("inf") # 最小のdistanceを見つけるための一時的なdistance。初期値は inf に設定。
    for node_index in unsearched_nodes: # 未探索のノードのループ
        if posible_min_distance > distance[node_index]: 
            posible_min_distance = distance[node_index] # より小さい値が見つかれば更新
    target_min_index = get_target_min_index(posible_min_distance, distance, unsearched_nodes) # 未探索ノードのうちで最小のindex番号を取得
    unsearched_nodes.remove(target_min_index) # ここで探索するので未探索リストから除去

    target_edge = route_list[target_min_index] # ターゲットになるノードからのびるエッジのリスト
    for index, route_dis in enumerate(target_edge):
        if route_dis != 0:
            if distance[index] > (distance[ target_min_index] + route_dis):
                distance[index] = distance[ target_min_index] + route_dis # 過去に設定されたdistanceよりも小さい場合はdistanceを更新
                previous_nodes[index] =  target_min_index #　ひとつ前に到達するノードのリストも更新

if distance[node_num - 1] == float("inf"):
    print(-1)
else:
    print(distance[node_num - 1])

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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