Problem:


Score : 600 points

Problem Statement

Nagase is a top student in high school. One day, she's analyzing some properties of special sets of positive integers.  

She thinks that a set S = \{a_{1}, a_{2}, ..., a_{N}\} of distinct positive integers is called special if for all 1 \leq i \leq N, the gcd (greatest common divisor) of a_{i} and the sum of the remaining elements of S is not 1.

Nagase wants to find a special set of size N. However, this task is too easy, so she decided to ramp up the difficulty. Nagase challenges you to find a special set of size N such that the gcd of all elements are 1 and the elements of the set does not exceed 30000.

Constraints

3 \leq N \leq 20000

Input

Input is given from Standard Input in the following format:

N

Output

Output N space-separated integers, denoting the elements of the set S. S must satisfy the following conditions :

The elements must be distinct positive integers not exceeding 30000.

The gcd of all elements of S is 1, i.e. there does not exist an integer d > 1 that divides all elements of S.

S is a special set.

If there are multiple solutions, you may output any of them. The elements of S may be printed in any order. It is guaranteed that at least one solution exist under the given contraints.

Sample Input 1

3

Sample Output 1

2 5 63

\{2, 5, 63\} is special because gcd(2, 5 + 63) = 2, gcd(5, 2 + 63) = 5, gcd(63, 2 + 5) = 7. Also, gcd(2, 5, 63) = 1. Thus, this set satisfies all the criteria.

Note that \{2, 4, 6\} is not a valid solution because gcd(2, 4, 6) = 2 > 1.

Sample Input 2

4

Sample Output 2

2 5 20 63

\{2, 5, 20, 63\} is special because gcd(2, 5 + 20 + 63) = 2, gcd(5, 2 + 20 + 63) = 5, gcd(20, 2 + 5 + 63) = 10, gcd(63, 2 + 5 + 20) = 9. Also, gcd(2, 5, 20, 63) = 1. Thus, this set satisfies all the criteria.



Sample input:
3


Sample output:
2 5 63

Submission status: Accepted

Solution code:
def ans(N):
    if N % 2 == 0:
        if N == 4:
            return "2 4 3 9"
        ret = [2, 4, 3, 9]
        cnt = 4
        summand = 6
        while summand <= 30000 - 6:
            ret.append(summand)
            cnt += 1
            summand += 6
            ret.append(summand)
            if summand > 30000:
                return "over 30000"
            cnt += 1
            summand += 6
            if cnt == N:
                return " ".join(list(map(str, ret)))
        summand = 15
        while summand <= 30000 - 6:
            ret.append(summand)
            cnt += 1
            summand += 6
            ret.append(summand)
            if summand > 30000:
                return "over 30000"
            cnt += 1
            summand += 6
            if cnt == N:
                return " ".join(list(map(str, ret)))
        summand = 8
        while summand <= 30000 - 2:
            ret.append(summand)
            cnt += 1
            summand += 2
            ret.append(summand)
            if summand > 30000:
                return "over 30000"
            cnt += 1
            summand += 4
            if cnt == N:
                return " ".join(list(map(str, ret)))
    else:
        if N == 19999:
            if N == 3:
                return "2 5 63"
            ret = [2, 8, 14]
            cnt = 3
            summand = 3
            while summand < 30000:
                ret.append(summand)
                cnt += 1
                summand += 6
                ret.append(summand)
                # if summand > 30000:
                #     return "over 30000"
                cnt += 1
                summand += 6
                if cnt == N:
                    return " ".join(list(map(str, ret)))
            summand = 12
            while summand <= 30000 - 6:
                ret.append(summand)
                cnt += 1
                summand += 6
                ret.append(summand)
                # if summand > 30000:
                #     return "over 30000"
                cnt += 1
                summand += 6
                if cnt == N:
                    return " ".join(list(map(str, ret)))
            ret.append(30000)
            cnt += 1
            summand = 20
            while summand < 30000:
                ret.append(summand)
                cnt += 1
                summand += 2
                ret.append(summand)
                # if summand > 30000:
                #     return "over 30000"
                cnt += 1
                summand += 4
                if cnt == N:
                    return " ".join(list(map(str, ret)))
            ret.append(4)
            cnt += 1
            if cnt == N:
                return " ".join(list(map(str, ret)))
            ret.append(10)
            cnt += 1
            if cnt == N:
                return " ".join(list(map(str, ret)))
            ret.append(16)
            cnt += 1
            if cnt == N:
                return " ".join(list(map(str, ret)))
        if N == 3:
            return "2 5 63"
        ret = [2, 8, 14]
        cnt = 3
        summand = 3
        while summand < 30000:
            ret.append(summand)
            cnt += 1
            summand += 6
            ret.append(summand)
            # if summand > 30000:
            #     return "over 30000"
            cnt += 1
            summand += 6
            if cnt == N:
                return " ".join(list(map(str, ret)))
        summand = 6
        while summand < 30000:
            ret.append(summand)
            cnt += 1
            summand += 6
            ret.append(summand)
            # if summand > 30000:
            #     return "over 30000"
            cnt += 1
            summand += 6
            if cnt == N:
                return " ".join(list(map(str, ret)))
        summand = 20
        while summand < 30000:
            ret.append(summand)
            cnt += 1
            summand += 2
            ret.append(summand)
            # if summand > 30000:
            #     return "over 30000"
            cnt += 1
            summand += 4
            if cnt == N:
                return " ".join(list(map(str, ret)))
        ret.append(4)
        cnt += 1
        if cnt == N:
            return " ".join(list(map(str, ret)))
        ret.append(10)
        cnt += 1
        if cnt == N:
            return " ".join(list(map(str, ret)))
        ret.append(16)
        cnt += 1
        if cnt == N:
            return " ".join(list(map(str, ret)))
        ret.remove(6)
        cnt += 1
        if cnt == N:
            return " ".join(list(map(str, ret)))


N = int(input())
print(ans(N))

Submission status: Accepted

Solution code:
from fractions import gcd
from collections import deque
n = int(raw_input())
q = deque()
x = 2
s = 0
for i in xrange(n - 1):
    for j in xrange(x, 30001):
        if j % 2 == 0 or j % 3 == 0 or j % 5 == 0:
            q.append(j)
            x = j + 1
            s += j
            break
while 1:
    for j in xrange(x, 30001):
        if (s + j) % 30 == 0 and gcd(s, j) != 1:
            q.append(j)
            break
    else:
        for j in xrange(x, 30001):
            if j % 2 == 0 or j % 3 == 0 or j % 5 == 0:
                q.append(j)
                s -= q.popleft()
                x = j + 1
                s += j
                break
        continue
    break
while q:
    print q.popleft(),

Submission status: Accepted

Solution code:

# 素数生成器
def generate_primes():
  from collections import defaultdict
  from itertools import count
  D = defaultdict(list)

  q = 2
  for q in count(2):
    if q in D:
      for p in D[q]:
        D[p+q].append(p)
      del D[q]
    else:
      yield q
      D[q*q].append(q)


n = int(input())

L = []
m = 0
for i in range(2,30001):
  if i % 2 == 0 or i % 3 == 0:
    L.append(i)
    m += i
    m %= 6
    if len(L) == n-1:
      break

t = sum(L)
if t % 2 != 0 and t % 3 != 0:
  for p in generate_primes():
    s = 6*p
    if (t%s)%p == 0:
      L.append(s-(t%s))
      break


else:
  m = t % 6
  for j in range(L[-1]+1,30001):
    if (j % 2 == 0 or j % 3 == 0) and (m+j) % 6 == 0:
      L.append(j)
      break

print(' '.join(map(str,L)))

Submission status: Accepted

Solution code:
#!/usr/bin/env python3

import sys

n = int(input())

if n == 3:
    print("2 5 63"); sys.exit(0)

eight = [2, 3, 4, 6, 8, 9, 10, 12]
ct = [[],
      [6],
      [2, 4],
      [2, 4, 6],
      [2, 3, 4, 9],
      [2, 3, 4, 6, 9],
      [2, 3, 4, 8, 9, 10],
      [2, 3, 4, 6, 8, 9, 10]]

twelves = n // 8
mod = n % 8
res = []
for i in range(twelves):
    for j in range(8):
        res.append(i * 12 + eight[j])
for c in ct[mod]:
    res.append(twelves * 12 + c)

for i, r in enumerate(res):
    if i > 0:
        print(" ", end="")
    print(r, end="")

Submission status: Accepted

Solution code:
def solve(n):
    ans = [2, 3, 25]
    if n % 2 == 0:
        ans.append(30)
    dic1 = [4, 26, 6, 24, 8, 22, 9, 21, 10, 20, 12, 18, 14, 16]
    dic2 = [2, 28, 3, 27, 4, 26, 5, 25, 6, 24, 8, 22, 9, 21, 10, 20, 12, 18, 14, 16]

    remain = n - len(ans)
    if remain < len(dic1):
        ans.extend(dic1[:remain])
        return ans

    ans.extend(dic1)
    remain -= len(dic1)

    r, s = divmod(remain, len(dic2))
    for d in range(30, (r + 1) * 30, 30):
        ans.extend(d + c for c in dic2)
    # ans.extend((r + 1) * 30 + c for c in dic2[:s])
    ans.extend(range(60, s * 30 + 60, 30))
    return ans


n = int(input())
print(*solve(n))

Submission status: Accepted

Solution code:
N=int(input())

if N==3:
    print('3 5 22')
else:
    c = 0
    a=2
    S=0
    while(c <= N-3):
        if a%2==0 or a%3==0 or a%5==0:
            print(str(a)+' ',end='')
            c+=1
            S+=a
        a+=1
     

    if S%2==0:
        if a%2!=0:
            a+=1
        print(str(a)+' ',end='')
        S+=a
        a+=1
        while((S+a)%30!=0):
            a+=1
        print(str(a))
    else:
        a=a-(a%6)+9
        print(str(a)+' ',end='')
        S+=a
        a+=1
        while((S+a)%30!=0):
            a+=1
        print(str(a))

Submission status: Accepted

Solution code:
N = int(input())
def gener():
    i = 2
    while True:
        if i%2==0 or i%3==0 or i%5==0:
            yield i
        i+=1
gen = gener()
ans = []
for j in range(N-2):
    ans.append(gen.__next__())
S = sum(ans)
while True:
    g = gen.__next__()
    p = S + g
    if p%2==0 or p%3==0 or p%5==0:
        ans.append(g)
        break
while True:
    g = gen.__next__()
    p2 = p + g
    if p2%30==0:
        ans.append(g)
        break
print(*ans)

Submission status: Accepted

Solution code:
import fractions

def check(S):
  g = S[0]
  for s in S:
    g = fractions.gcd(g, s)
  if g>1:
    return False
  for s in S:
    if fractions.gcd(s, sum(S)-s)==1:
      return False
  return True

import sys
sys.setrecursionlimit(100000)

N = input()
P = [2,3,5,7]
def BT(S, s):
  for a in xrange(S[-1]+1, 30001):
    ok = False
    for p in P:
      if a%p==0:
        ok = True
        break
    if ok:
      S.append(a)
      s += a
      if len(S)==N:
        if s%210==0:
          print " ".join(map(str, S))
          #print check(S)
          exit(0)
      else:
        BT(S, s)
      S.pop()
      s -= a
BT([2], 2)

Submission status: Accepted

Solution code:
n = input()

ans = [2,5,20,63]

if n == 3:
    print 2,5,63
    exit(0)

p = 90
while (n - len(ans))%44 != 0:
    ans.append(p)
    p += 30

while len(ans) < n:
    if p % 2 == 0 or p % 5 == 0 or p % 3 == 0:
        ans.append(p)
    p += 1

def gcd(a,b):
    if a == 0:return b
    return gcd(b % a, a)

s = sum(ans)
    
for x in ans:
    print x,
print ""

Submission status: Runtime Error

Solution code:
import sys
from math import gcd, log
sys.setrecursionlimit(10 ** 7)

def calc(arr, lim, pows, idx):
    if idx == -1:
        tmp = [arr[i]**pows[i] for i in range(len(arr))]
        sum_tmp = sum(tmp)
        f = True
        for i in range(len(tmp)):
            x = sum_tmp - tmp[i]
            if gcd(tmp[i], x) == 1:
                f = False
                break
        return f
    for i in range(1, lim[idx]):
        pows[idx] = i
        if calc(arr, lim, pows, idx-1):
            return True
    return False

def main():
    n = int(input())
    arr = [0]*n
    prime = [-1]*30000
    x = 3
    for i in range(n):
        while prime[x] != -1:
            x += 2
        arr[i] = x
        for j in range(x, 30000, x):
            prime[j] = 0
    pow_lim = [int(log(30000, arr[i]))+1 for i in range(n)]
    pows = [1]*n
    _ = calc(arr, pow_lim, pows, n-1)
    ans = [arr[i]**pows[i] for i in range(n)]
    for v in ans:
        print(v, end=" ")

if __name__ == "__main__":
    main()

Submission status: Runtime Error

Solution code:
import sys
from math import gcd, log
sys.setrecursionlimit(10 ** 7)

def calc(arr, lim, pows, idx):
    if idx == -1:
        tmp = [arr[i]**pows[i] for i in range(len(arr))]
        sum_tmp = sum(tmp)
        f = True
        for i in range(len(tmp)):
            x = sum_tmp - tmp[i]
            if gcd(tmp[i], x) == 1:
                f = False
                break
        return f
    for i in range(1, lim[idx]):
        pows[idx] = i
        if calc(arr, lim, pows, idx-1):
            return True
    return False

def main():
    n = int(input())
    arr = [0]*n
    prime = [-1]*30000
    x = 3
    for i in range(n):
        while prime[x] != -1:
            x += 2
        arr[i] = x
        for j in range(x, 30000, x):
            prime[j] = x
    pow_lim = [int(log(30000, arr[i]))+1 for i in range(n)]
    pows = [1]*n
    _ = calc(arr, pow_lim, pows, n-1)
    ans = [arr[i]**pows[i] for i in range(n)]
    for v in ans:
        print(v, end=" ")

if __name__ == "__main__":
    main()

Submission status: Runtime Error

Solution code:
import sys
from math import gcd, log
sys.setrecursionlimit(10 ** 7)

def calc(arr, lim, pows, idx):
    if idx == -1:
        tmp = [arr[i]**pows[i] for i in range(len(arr))]
        sum_tmp = sum(tmp)
        f = True
        for i in range(len(tmp)):
            x = sum_tmp - tmp[i]
            if gcd(tmp[i], x) == 1:
                f = False
                break
        return f
    for i in range(1, lim[idx]):
        pows[idx] = i
        if calc(arr, lim, pows, idx-1):
            return True
    return False

def main():
    n = int(input())
    arr = [0]*n
    prime = [-1]*30000
    x = 2
    for i in range(n):
        while prime[x] != -1:
            x += 1
        arr[i] = x
        for j in range(x, 30000, x):
            prime[j] = x
    pow_lim = [int(log(30000, arr[i]))+1 for i in range(n)]
    pows = [1]*n
    _ = calc(arr, pow_lim, pows, n-1)
    ans = [arr[i]**pows[i] for i in range(n)]
    for v in ans:
        print(v, end=" ")

if __name__ == "__main__":
    main()

Submission status: Runtime Error

Solution code:
'''
自宅用PCでの解答
'''
import math
#import numpy as np
import itertools
import queue
import bisect
from collections import deque,defaultdict
import heapq as hpq
from sys import stdin,setrecursionlimit
#from scipy.sparse.csgraph import dijkstra
#from scipy.sparse import csr_matrix
ipt = stdin.readline
setrecursionlimit(10**7)
mod = 10**9+7
dir = [(-1,0),(0,-1),(1,0),(0,1)]
alp = "abcdefghijklmnopqrstuvwxyz"

def main():
    n = int(ipt())
#    n = 20000
    tn = (n//4)*4
    sm = 0
    nm = 0
    ans = []
    for i in range(1,30001):
        if i%2 == 0 or i%3 == 0:
            ans.append(i)
            sm += i
            nm += 1
        if nm == tn:
            break

    if n%4 == 0:
        pass
    elif n%4 == 1:
        ans.append(ans[-1]+6)
    elif n%4 == 2:
        ans.append(ans[-1]+2)
        ans.append(ans[-1]+2)
    else:
        ans.append(ans[-1]+2)
        ans.append(ans[-1]+2)
        ans.append(ans[-1]+2)

    print(" ".join(map(str,ans)))


    return None

if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
N = int(input())

if N==2:
    print(3,5)
    exit()
if N==3:
    print(2,5,63)
    exit()
if N==4:
    print(2,5,20,63)
    exit()

if N==5:
    print(2,5,20,30,63)

S=set()
i=2
while len(S)<N:
    if i%2==0 or i%3==0:
        S.add(i)
    i+=1

i+=1
r=sum(S)

if r%6==0:
    pass
elif r%6==2:
    S.remove(8)
    while len(S)<N:
        if i%6==0:
            S.add(i)
            break
        i+=1
elif r%6==3:
    S.remove(9)
    while len(S)<N:
        if i%6==0:
            S.add(i)
            break
        i+=1
elif r%6==5:
    S.remove(9)
    while len(S)<N:
        if i%6==4:
            S.add(i)
            break
        i+=1

assert len(S)==N,len(S)
print(" ".join(map(str,S)))

Submission status: Runtime Error

Solution code:
N = int(input())

if N==2:
    print(3,5)
    exit()
if N==3:
    print(2,5,63)
    exit()
if N==4:
    print(2,5,20,63)
    exit()

S=set()
i=2
while len(S)<N:
    if i%2==0 or i%3==0:
        S.add(i)
    i+=1

i+=1
r=sum(S)

if r%6==0:
    pass
elif r%6==2:
    S.remove(8)
    while len(S)<N:
        if i%6==0:
            S.add(i)
            break
        i+=1
elif r%6==3:
    S.remove(9)
    while len(S)<N:
        if i%6==0:
            S.add(i)
            break
        i+=1
elif r%6==5:
    S.remove(9)
    while len(S)<N:
        if i%6==4:
            S.add(i)
            break
        i+=1

assert len(S)==N,len(S)
print(" ".join(map(str,S)))

Submission status: Runtime Error

Solution code:
N = int(input())

S=set()
i=2
while len(S)<=N:
    if i%2==0 or i%3==0:
        S.add(i)
    i+=1

r=sum(S)%6

if r%6==0:
    pass
elif r%2==0:
    S.remove(8)
    while len(S)<=N:
        if i%6==0:
            S.add(i)
            break
        i+=1
elif r%3==0:
    S.remove(9)
    while len(S)<=N:
        if i%6==0:
            S.add(i)
            break
        i+=1
elif r%5==0:
    S.remove(9)
    while len(S)<=N:
        if i%6==4:
            S.add(i)
            break
        i+=1




print(" ".join(map(str,S)))

Submission status: Runtime Error

Solution code:
n = int(input())
if n == 3:
  print(2,5,63)
elif n == 4:
  print(2,5,20,63)
elif n == 6:
  print(2,4,6,12,3,9)
else:
  m = 1
  if n > 15001:
    m = (n-15000)//2
  for j in range(m,2501):
    if (n-2*j)/3 == int((n-2*j)/3) and 0 < (n-2*j)//3 <= 5000:
      x = j; y = (n-2*x)//3
      #print(x,y,2*x+3*y)
      break
  ans = []
  for i in range(2*x):
    ans.append(3+6*i)
  for j in range(3*y):
    ans.append(2+2*j)
    
  print(*ans)

Submission status: Runtime Error

Solution code:
n = int(input())
if n == 3:
  print(2,5,63)
elif n == 4:
  print(2,5,20,63)
elif n == 6:
  print(2,4,6,12,3,9)
else:
  m = 1
  if n > 15001:
    m = (n-15000)//2
  for j in range(m,2501):
    if (n-2*j)/3 == int((n-2*j)/3) and (n-2*j)//3 <= 5000:
      x = j; y = (n-2*x)//3
      #print(x,y,2*x+3*y)
      break
  ans = []
  for i in range(2*x):
    ans.append(3+6*i)
  for j in range(3*y):
    ans.append(2+2*j)
    
  print(*ans)

Submission status: Runtime Error

Solution code:
#
# 　　  ⋀_⋀　 
#　　  (･ω･)  
# .／ Ｕ ∽ Ｕ＼
#  │＊　合　＊│
#  │＊　格　＊│ 
#  │＊　祈　＊│ 
#  │＊　願　＊│ 
#  │＊　　　＊│ 
#      ￣
#
import sys
sys.setrecursionlimit(10**6)
input=sys.stdin.readline
from math import floor,sqrt,factorial,hypot,log #log2ないｙｐ
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict,deque
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from copy import deepcopy
from fractions import gcd
from random import randint
def ceil(a,b): return (a+b-1)//b
inf=float('inf')
mod = 10**9+7
def pprint(*A): 
    for a in A:     print(*a,sep='\n')
def INT_(n): return int(n)-1
def MI(): return map(int,input().split())
def MF(): return map(float, input().split())
def MI_(): return map(INT_,input().split())
def LI(): return list(MI())
def LI_(): return [int(x) - 1 for x in input().split()]
def LF(): return list(MF())
def LIN(n:int): return [I() for _ in range(n)]
def LLIN(n: int): return [LI() for _ in range(n)]
def LLIN_(n: int): return [LI_() for _ in range(n)]
def LLI(): return [list(map(int, l.split() )) for l in input()]
def I(): return int(input())
def F(): return float(input())
def ST(): return input().replace('\n', '')
def main():
    N=I()
    if(N==3):
        print(2,5,63)
    elif(N==4):
        print(2,5,20,63)
    elif(N==5):
        print(2,3,4,5,16)
    else:
        MAX = 30000
        ans = []
        for i in range(2,MAX+1):
            if(i%3==0 or i%2==0):
                ans.append(i)
                if(len(ans) == N):
                    break
        if(sum(ans) == 0):
            pass
        else:
            ans.remove(6 + (sum(ans)%6))
            v = ans[-1]
            while True:
                if(v%6==0):
                    ans.append(v)
                    break
                v+=1
            print(*ans)

if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
#include <bits/stdc++.h>
using namespace std;

#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define F0R(i,a) FOR(i,0,a)
#define ROF(i,a,b) for (int i = (b)-1; i >= (a); --i)
#define R0F(i,a) ROF(i,0,a)

using ll = long long;
using ld = long double;
ll INF = LLONG_MAX;

using vi = vector<int>;
using vll = vector<ll>;
using pii = pair<int, int>;

namespace output {
	void pr(int x) { cout << x; }
	void pr(long x) { cout << x; }
	void pr(ll x) { cout << x; }
	void pr(unsigned x) { cout << x; }
	void pr(unsigned long x) { cout << x; }
	void pr(unsigned long long x) { cout << x; }
	void pr(float x) { cout << x; }
	void pr(double x) { cout << x; }
	void pr(ld x) { cout << x; }
	void pr(char x) { cout << x; }
	void pr(const char* x) { cout << x; }
	void pr(const string& x) { cout << x; }
	void pr(bool x) { pr(x ? "true" : "false"); }
	template<class T> void pr(const complex<T>& x) { cout << x; }
	
	template<class T1, class T2> void pr(const pair<T1,T2>& x);
	template<class T> void pr(const T& x);
	
	template<class T, class... Ts> void pr(const T& t, const Ts&... ts) { 
		pr(t); pr(ts...); 
	}
	template<class T1, class T2> void pr(const pair<T1,T2>& x) { 
		pr("{",x.f,", ",x.s,"}"); 
	}
	template<class T> void pr(const T& x) { 
		pr("{"); // const iterator needed for vector<bool>
		bool fst = 1; for (const auto& a: x) pr(!fst?", ":"",a), fst = 0; 
		pr("}");
	}
	
	void print() { pr("\n"); } // print w/ spaces
	template<class T, class... Ts> void print(const T& t, const Ts&... ts) { 
		pr(t); if (sizeof...(ts)) pr(" "); print(ts...); 
	}
}

using namespace output;

int main() {
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	int N; cin >> N;
	int ceil = (N % 12 == 0) ? N : (N/12 + 1) * 12;
	vi arr;
	int i = 0;
	for (int i = 0; i < ceil; i += 2) {
		arr.push_back(3*(i/2)+2);
		arr.push_back(3*(i/2)+3);
	}
	
	while (ceil - N >= 2) {
		arr[1] += arr[arr.size() - 1];
		arr[0] += arr[arr.size() - 2];
		arr.pop_back(); arr.pop_back();
		--ceil; --ceil;
	}

	if (ceil - N == 1) {
		arr[1] += arr[arr.size() - 1];
		arr.pop_back();
	}
	
	for (int x : arr) {
		cout << x << " ";
	}
	cout << endl;
}

Submission status: Runtime Error

Solution code:
N = int(input())
if N == 3：
	print(1, 2, 3)
  	exit()
a = []
i = 2
while len(a) < N-N%2-2 and i + 2 <= 30000:
	a.append(i)
    a.append(i+2)
    i += 6
b = []
i = 3
while len(a) + len(b) < N-N%2 and i + 6 <= 30000:
  	b.append(i)
    b.append(i+6)
    i += 12
c = []
i = 6
while len(a) + len(b) + len(c) < N:
  	c.append(i)
    i += 6
print(' '.join(map(str, a+b+c)))

Submission status: Runtime Error

Solution code:
N = int(input())
if N ＝＝ 3：
	print(1, 2, 3)
  	exit()
a = []
i = 2
while len(a) < N-N%2-2 and i + 2 <= 30000:
	a.append(i)
    a.append(i+2)
    i += 6
b = []
i = 3
while len(a) + len(b) < N-N%2 and i + 6 <= 30000:
  	b.append(i)
    b.append(i+6)
    i += 12
c = []
i = 6
while len(a) + len(b) + len(c) < N:
  	c.append(i)
    i += 6
print(' '.join(map(str, a+b+c)))

Submission status: Runtime Error

Solution code:
n = int(input())
l = [{}, {}, {}, {2, 5, 63}, {2, 5, 20, 63}, {2, 3, 4, 6, 9}]
if n <= 5:
  print(*l[n])
l = [2, 3, 4, 6]
s = set()
for i in range(n):
  s.add(l[i%4] + 6*(i//4))
if sum(s) % 6 == 2:
  s.remove(8)
  s.add(30000)
if sum(s) % 6 == 3:
  s.remove(9)
  s.add(30000)
if sum(s) % 6 == 5:
  s.remove(9)
  s.add(29998)
print(*s)

Submission status: Runtime Error

Solution code:
N = int(input())

P2 = list(range(2,30001,2))
P3 = list(range(3,30001,6))
for i in range(1,N+1):
  if (N-i*3)%2==0 and 3*i<=15000 and 0<(N-3*i)<=5000:
    x = 3*i
    y = (N-i*3)
    break
if N==5 or N>6:
  ans = P2[:x]+P3[:y]
elif N==3:
  ans = [2,5,63]
elif N==4:
  ans = [2,5,20,63]
elif N==6:
  ans = [2,3,4,185,7,9]
print(*ans)

Submission status: Runtime Error

Solution code:
N = int(input())

P2 = list(range(2,30001,2))
P3 = list(range(3,30001,6))
for i in range(1,N+1):
  if (N-i*3)%2==0 and 3*i<=15000 and (N-3*i)<=5000:
    x = 3*i
    y = (N-i*3)
    break
if N==5 or N>6:
  ans = P2[:x]+P3[:y]
elif N==3:
  ans = [2,5,63]
elif N==4:
  ans = [2,5,20,63]
elif N==6:
  ans = [2,3,4,185,7,9]
print(*ans)

Submission status: Runtime Error

Solution code:
N = int(input())

P2 = list(range(2,30001,2))
P3 = list(range(3,30001,6))
for i in range(1,N+1):
  if (N-i*3)%2==0 and 3*i<=15000 and (N-3*i)<=5000:
    x = 3*i
    y = (N-i*3)
    break
if N==5 or N>6:
  ans = P2[:x]+P3[:y]
elif N==3:
  ans = [2,5,63]
elif N==4:
  ans = [2,5,20,63]
elif N==6:
  ans = [2,3,4,65,7,9]
print(*ans)

Submission status: Runtime Error

Solution code:
n=int(input())
if n==3:
  print(2,5,63)
elif n==4:
  print(2,5,20,63)
elif n==5:
  print(2,5,20,30,63)
else:
  l=[2,3]
  cnt=2
  last=0
  for i in range(4,30001):
    if i%6 in [0,2,3,4]:
      l.append(i)
      cnt+=1
      if cnt==n:
        last=i
        break
  m=sum(l)
  if m%6==1:
    l.remove(9)
    for i in range(6):
      if (last+i)%6==2:
        l.append(last+i)
        break
  elif m%6==2:
    l.remove(8)
    for i in range(6):
      if (last+i)%6==0:
        l.append(last+i)
        break
  elif m%6==3:
    l.remove(9)
    for i in range(6):
      if (last+i)%6==0:
        l.append(last+i)
        break
  elif m%6==4:
    l.remove(8)
    for i in range(6):
      if (last+i)%6==4:
        l.append(last+i)
        break
  elif m%6==5:
    l.remove(9)
    for i in range(6):
      if (last+i)%6==4:
        l.append(last+i)
        break
  print(*l)
  if len(s)!=n:
    while True:
      z=0

Submission status: Runtime Error

Solution code:
n=int(input())
if n==3:
  print(2,5,63)
elif n==4:
  print(2,5,20,63)
elif n==5:
  print(2,5,20,30,63)
else:
  l=[2,3]
  cnt=2
  last=0
  for i in range(6,30001):
    if i%6 in [0,2,3,4]:
      l.append(i)
      cnt+=1
      if cnt==n:
        last=i
        break
  m=sum(l)
  if m%6==2:
    l.remove(8)
    for i in range(6):
      if (last+i)%6==0:
        l.append(last+i)
        break
  elif m%6==3:
    l.remove(9)
    for i in range(6):
      if (last+i)%6==0:
        l.append(last+i)
        break
  elif m%6==5:
    l.remove(9)
    for i in range(6):
      if (last+i)%6==4:
        l.append(last+i)
        break
print(*l)

Submission status: Runtime Error

Solution code:
from bisect import *
from collections import *
from fractions import gcd
from math import factorial
from itertools import *

N=int(input())

if N==3:
    print(2,5,63)
elif N==4:
    print(2,5,20,63)
elif N==5:
    print(2,5,20,63,30)
else:
    lst=[2,3,4,6,9,12]
    count=N-6
    div2=[i for i in range(14,30001,2) if i%6!=0]
    if len(div2)%2==1:
        div2.pop()
    div3=[i for i in range(15,30001,6)]
    if len(div3)%2==1:
        div3.pop()
    div6=[i for i in range(18,30001,6)]

    while count>=2 and div2:
        lst.append(div2.pop())
        lst.append(div2.pop())
        count-=2
    while count>=2 and div3:
        lst.append(div3.pop())
        lst.append(div3.pop())
        count-=2
    while count>=1:
        lst.append(div6.pop())
        count-=1
    print(" ".join(list(map(str,lst))))

Submission status: Runtime Error

Solution code:
import sys
import numpy as np
sys.setrecursionlimit(10 ** 7)

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

N = ir()
if N == 3:
    print('2 5 63')
    exit()
l = np.array([3, 9, 2, 10, 4, 8, 6, 12]).astype('int32')
l2 = np.array([6, 3, 9, 2, 10, 4, 8,12]).astype('int32')
time = N // 12
answer = np.array([])
for i in range(time):
    answer = np.append(answer, l + 12 * i)
remain = N % 12
if remain%2 == 0:
    answer = np.append(answer, l[:remain] + 12 * time)
else:
    answer = np.appen(answer, l2[:remain] + 12 * time)

answer = [int(x) for x in answer]
print(*answer)
# 48

Submission status: Runtime Error

Solution code:
import sys
import numpy as np

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

N = ir()
if N == 3:
    print('2 5 63')
    exit()
l = np.array([3, 9, 2, 10, 4, 8, 6, 12]).astype('int32')
l2 = np.array([6, 3, 9, 2, 10, 4, 8,12]).astype('int32')
time = N // 12
answer = np.array([])
for i in range(time):
    answer = np.append(answer, l + 12 * i)
remain = N % 12
if remain%2 == 0:
    answer = np.append(answer, l[:remain] + 12 * time)
else:
    answer = np.appen(answer, l2[:remain] + 12 * time)

answer = [int(x) for x in answer]
print(*answer)
# 48

Submission status: Runtime Error

Solution code:
import sys
import numpy as np

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

N = ir()
if N == 3:
    print('2 5 63')
    exit()
l = np.array([3, 9, 2, 10, 4, 8, 6, 12]).astype('int32')
l2 = np.array([6, 3, 9, 2, 10, 4, 8,12]).astype('int32')
time = N // 12
answer = np.array([])
for i in range(1, time+1):
    answer = np.append(answer, l + 12 * i)
remain = N % 12
if remain%2 == 0:
    answer = np.append(answer, l[:remain])
else:
    answer = np.appen(answer, l2[:remain])

answer = [int(x) for x in answer]
print(*answer)
# 48

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-

import sys

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = 10 ** 18
MOD = 10 ** 9 + 7

N = INT()

# 例外処理
if N == 3:
    print(2, 5, 63)
    exit()

# ・全体のgcdが1になるように2と3を含める
# ・要素は全て2か3の倍数を使う
# ・全体の合計は6の倍数にする
# ・これでgcd(総和, 各要素)は常に2か3になる
A = [2, 4, 3, 9]

li1, li2, li3 = [], [], []
for a in range(5, 30001):
    # 9は既に使用済
    if a == 9:
        continue
    # 3の倍数で奇数(mod6で3)
    if a % 3 == 0 and a % 2 == 1:
        li1.append(a)
    # 3の倍数で偶数(mod6で0)
    elif a % 6 == 0:
        li2.append(a)
    # 3の倍数ではなくて偶数(mod6で2,4)
    elif a % 3 != 0 and a % 2 == 0:
        li3.append(a)

# リスト1,3はペアで使うとmod6で0にできる
while len(A) + 2 <= N:
    A.append(li1.pop())
    A.append(li1.pop())
while len(A) + 2 <= N:
    A.append(li3.pop())
    A.append(li3.pop())
# リスト2は元々mod6で0なので1つずつ使える
while len(A) + 1 <= N:
    A.append(li2.pop())
print(*A)

Submission status: Runtime Error

Solution code:
n=int(input())
if n==3:
  print(22,3,5)
  exit()
if n==4:
  print(2,3,4,9)
  exit()
if n==5:
  print(2,3,4,6,9)
  exit()
a=n//4
b=n%4
ans=[]
for i in range(a):
  ans.extend(6*i+2,6*i+3,6*i+4,6*i+6)
if b==1:
  ans.append(6*a+6)
if b==2:
  ans.extend(6*a+2,6*a+4)
if b==3:
  ans.extend(6*a+2,6*a+3,6*a+4)
print(*ans)

Submission status: Runtime Error

Solution code:
def gcd(a,b):
    while b!=0:
        a,b=b,a%b
    return a

n=int(input())
ans=[0]*n
k=0
i=2
while k<n-1:
    if i%2==0 or i%3==0:
        ans[k]=i
        k+=1
    i+=1
x=sum(ans)
ans[-1]=30000+x//6*6-x
if ans[-1]
while gcd(ans[-1],x)==1:
    ans[-1]-=6
print(*ans)