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.

Solution (Python):
n=int(input())
ans=[0]*n
i=0
for k in range(1,30001):
    if k%2==0 or k%3==0:
        ans[i]=k
        i+=1
    if i==n-1:
        break
x=sum(ans)
def gcd(a,b):
    while b:
        a,b=b,a%b
    return a
for k in range(30000,0,-1):
    if (x+k)%6==0 and gcd(x,k)>1:
        ans[-1]=k
        break
print(*ans)

Solution (Python):
n = int(input())
def so(x):
    if x%2>0 and x%3>0 and x%5>0:
        return True
    else:
        return False



m = 30000
ANS = []
for i in range(1, m+1):
    if i%2==0 or i%3==0 or i%5==0:
        ANS.append(i)
        n -= 1
    if n == 1:
        k = ANS[-1]
        while k%30!=0:
            k += 1
        ANS.append(k+60-sum(ANS)%30)
        break
if so(ANS[-1]):
    for j in range(30):
        k = 30 - j
        if so(ANS[-1]+j) == False and so(ANS[-2]+k) == False:
            ANS[-1] += j
            ANS[-2] += k
            break
print(" ".join([str(i) for i in ANS]))

Solution (Python):
N=int(input())
if N==3:
    print(2,3,25)
elif N==4:
    print(2,3,25,30)
elif N==5:
    print(2,3,25,30,60)
else:
    ans=[]
    base=1
    while len(ans)+6<=N:
        for i in range(base,base+12):
            if (i%2==0)^(i%3==0):
                ans.append(i)
        base+=12
        if base>=30000:
            break
    base=6
    while len(ans)<N:
        ans.append(base)
        base+=6
    print(*ans)

Solution (Python):
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
while gcd(ans[-1],x)==1:
    ans[-1]-=6
print(*ans)

Solution (Python):
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=set()
  cnt=0
  e=0
  for i in range(2,30001):
    if i%2==0 or i%3==0:
      l.add(i)
      cnt+=1
      if cnt==n:
        m=sum(l)
        if m%6==2:
          l.discard(8)
          l.add((i//6+1)*6)
        elif m%6==3:
          l.discard(9)
          l.add((i//6+1)*6)
        elif m%6==5:
          l.discard(8)
          l.add((i+3)//6*6+3)
        break
  print(' '.join(map(str,l)))

Solution (Python):
def examA():
    S = SI()
    N = len(S)
    if N<26:
        d = defaultdict(bool)
        for s in S:
            d[s] = True
        for a in alphabet:
            if not d[a]:
                ans = S + a
                print(ans)
                return
    keep = []
    for i in range(N-1)[::-1]:
        keep.append(S[i+1])
        if S[i]<S[i+1]:
            break
    
    n = len(keep)
    c = "zz"
    for s in keep:
        if s>S[(N-n-1)]:
            c = min(c,s)
    if c=="zz":
        print(-1)
        return
    ans = S[:(N-n-1)] + c
    print(ans)
    return

def examB():
    N = I()
    if N==3:
        print("2 5 63")
        return
    if N%2==0:
        ans = [2, 4, 3, 9]
        now = 4
        cur = 10
    else:
        ans = [2, 4, 3, 9]
        now = 4
        cur = 10
    while(cur<=30000):
        if N-1<=now:
            break
        ans.append(cur)
        ans.append(cur-2)
        cur += 6; now += 2
    cur = 21
    while(cur<=30000):
        if N-1<=now:
            break
        ans.append(cur)
        ans.append(cur-6)
        cur += 12; now += 2
    for i in range(N-now):
        cur = (i+1)*6
        ans.append(cur)
    print(" ".join(map(str,ans)))
    return

def examC():
    ans = 0
    print(ans)
    return

def examD():
    ans = 0
    print(ans)
    return

def examE():
    ans = 0
    print(ans)
    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__':
    examB()

"""

"""

Solution (Python):
N = int(input())
def two(n):
    res = []
    if n%2 == 0:
        m = n//2
        for i in range(m):
            res.append(i*6+2)
            res.append(i*6+4)
        return res      
def three(n):
    res = []
    if n%2 == 0:
        m = n//2
        for i in range(m-1):
            res.append(i*6+3)
            res.append(i*6+6)
        if m%2 == 0:
            res.append(m*6-3)
            res.append(m*6)
        else:
            res.append(m*6)
            res.append(m*6+6)
    else:
        m = n//2
        if m%2 == 0:
            for i in range(m):
                res.append(i*6+3)
                res.append(i*6+6)
            res.append(m*6+6)
        else:
            for i in range(m):
                res.append(i*6+3)
                res.append(i*6+6)
            res.append(m*6+3)
    return res
import sys
if N == 3:
    ans = [22, 3, 5]
    print(*ans)
    sys.exit()
if N == 4:
    ans = [2, 4, 3, 9]
    print(*ans)
    sys.exit()
if N == 6:
    ans = [2, 4, 3, 6, 9, 12]
    print(*ans)
    sys.exit()
a = N//2
b = N-a
if a%2 != 0:
    if b%2 != 0:
        a+=1
        b-=1
    else:
        a, b = b, a
ans = two(a)
ans+=three(b)
print(*ans)

Solution (Python):
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(10,30001,2) if i%6!=0]
    div2.append(8)
    
    
    div3=[i for i in range(15,30001,6)]
    
    
    div6=[i for i in range(18,30001,6)]
    
    while count>=2 and len(div2)>=2:
        lst.append(div2.pop())
        lst.append(div2.pop())
        count-=2
    while count>=2 and len(div3)>=2:
        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))))

Solution (Python):
def f(n):
    if n==3:
        A = [2,3,25]
    elif n%3==1:
        k = n//3
        A = [2*i for i in range(1,3*(k-1)+3)]
        A += [3,9]
    elif n%3==2:
        k = n//3
        A = [2*i for i in range(1,3*k+1)]
        A += [3,9]
    else:
        k = n//3
        A = [2*i for i in range(1,3*k-3)]
        A += [3,9,15,21]
    return A
    
N = int(input())
if N<15003:
    A = f(N)
else:
    A = f(15002)
    A.pop()
    A.pop()
    n = N-15002
    if n%2==1:
        n = (n+1)//2
        B = [3+6*i for i in range(2*n+2)]
        A.pop()
        A += B
    else:
        n = n//2
        B = [3+6*i for i in range(2*n+2)]
        A += B
print(*A)

Solution (Python):
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 // 8
answer = np.array([])
for i in range(time):
    answer = np.append(answer, l + 12 * i)
remain = N % 8
if remain%2 == 0:
    answer = np.append(answer, l[:remain] + 12 * time)
else:
    answer = np.append(answer, l2[:remain] + 12 * time)

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

Solution (Python):
n=int(input())
if n==3:
    print("2 5 63")
elif n==6:
    print("3 4 6 8 9 12")
elif n==7:
    print("2 3 4 6 8 10 15")
else:
    res=[]
    count = 0
    for i in range(1,50000):
        if i % 2 == 0 or i % 3 == 0:
            res.append(i)
            count += 1
        if count == n-1:
            break

    s=sum(res)
    t=res[-1]
    f1 = s%2
    f2 = s%3
    if f1==0 and f2 == 0:
        flag = 0
    elif f1==0 and f2==1:
        flag = 2
    elif f1==0 and f2==2:
        flag = 4
    if f1==1 and f2 == 0:
        flag = 3
    elif f1==1 and f2==1:
        flag = 5
    elif f1==1 and f2==2:
        flag = 1

    if flag == 5 or flag ==1:
        res.pop(1)
        f=0
        for i in range(t+1,t+10):
            if i % 2==0:
                res.append(i)
                f+=1
            if f==2:
                break

    else:
        for i in range(t+1,t+10):
            if i % 6 == flag:
                res.append(i)
                break

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

Solution (Python):
import sys
printn = lambda x: sys.stdout.write(x)
inn = lambda : int(input())
inl   = lambda: list(map(int, input().split()))
inm   = lambda:      map(int, input().split())
DBG = True 

def ddprint(x):
  if DBG:
    print(x)

n = inn()
if n<=8:
    a = [0,0,0, '2 5 63', '2 5 20 63',
        '2 3 4 6 9', '2 3 4 6 9 12', '2 3 4 6 8 9 10',
        '2 3 4 6 8 9 10 12']
    print(a[n])
    exit()
m = (n-1)//8
r = (n-1)%8
b = ['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 ',
        '2 3 4 6 8 9 10 12 ']
printn(b[r])
for i in range(1,m+1):
    p = 12*i
    printn('{} {} {} {} {} {} {} {} '.format
      (p+2,p+3,p+4,p+6,p+8,p+9,p+10,p+12))
print('')

Solution (Python):
from random import sample
n=int(input())
if n==3:a=[2,5,63]
else:
  l=[i for i in range(6,30001)if i%2==0 or i%3==0]
  while True:
    a=[2,3,4];a+=sample(l,n-3)
    if sum(a)%6==0:break
print(*a)

Solution (Python):
from random import sample
n=int(input())
if n==3:
  print("2 5 63"); exit()
l=[i for i in range(6,30001)if i%2==0 or i%3==0]
while True:
  ans=[2,3,4]
  ans+=sample(l,n-3)
  if sum(ans)%6==0:
    break
print(*ans)

Solution (Python):


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





A = [2, 4, 3, 9]

li1, li2, li3 = [], [], []
for a in range(5, 30001):
    
    if a == 9:
        continue
    
    if a % 3 == 0 and a % 2 == 1:
        li1.append(a)
    
    elif a % 6 == 0:
        li2.append(a)
    
    elif a % 3 != 0 and a % 2 == 0:
        li3.append(a)


while li1 and len(A) + 2 <= N:
    A.append(li1.pop())
    A.append(li1.pop())
while li3 and len(A) + 2 <= N:
    A.append(li3.pop())
    A.append(li3.pop())

while li2 and len(A) + 1 <= N:
    A.append(li2.pop())
print(*A)

Solution (Python):
A6 = []
A2 = []
A3 = []
for i in range(2, 30001)[::-1]:
    if i % 6 == 0:
        A6.append(i)
    elif i % 2 == 0:
        A2.append(i)
    elif i % 3 == 0:
        A3.append(i)

N = int(input())
if N <= 4:
    print(*[[2, 5, 63], [2, 5, 20, 63]][N-3])
else:
    S = []
    S.append(A2.pop())
    S.append(A2.pop())
    S.append(A3.pop())
    S.append(A3.pop())
    N -= 4
    while N >= 2:
        if len(A2) >= 2:
            S.append(A2.pop())
            S.append(A2.pop())
            N -= 2
        elif len(A3) >= 2:
            S.append(A3.pop())
            S.append(A3.pop())
            N -= 2
        else:
            break
    while N:
        S.append(A6.pop())
        N -= 1
    print(*S)

Solution (Python):
A6 = []
A2 = []
A3 = []
for i in range(2, 30001)[::-1]:
    if i % 6 == 0:
        A6.append(i)
    elif i % 2 == 0:
        A2.append(i)
    elif i % 3 == 0:
        A3.append(i)

N = int(input())
if N <= 4:
    print(*[[2, 5, 63], [2, 5, 20, 63]][N-3])
else:
    S = []
    S.append(A2.pop())
    S.append(A2.pop())
    S.append(A3.pop())
    S.append(A3.pop())
    N -= 4
    while N >= 2:
        if len(A2) >= 2:
            S.append(A2.pop())
            S.append(A2.pop())
            N -= 2
        elif len(A3) >= 2:
            S.append(A3.pop())
            S.append(A3.pop())
            N -= 2
        else:
            break
    while N:
        S.append(A6.pop())
        N -= 1
    print(*S)

Solution (Python):

"""
2,3の倍数で構成
すべての和が6の倍数ならok

2,3,4,6 = 15
8,9,10,12 で繰り返し
"""
import sys

N = int(input())
q = []

if N == 3:
    print ("2 5 63")
    sys.exit()

i = 1
while len(q) < (N // 8) * 8:

    if i % 2 == 0 or i % 3 == 0:
        q.append(i)

    i += 1

i -= 1
if N - len(q) >= 2:
    q.append(i+3)
    q.append(i+9)

if N - len(q) >= 2:
    q.append(i+2)
    q.append(i+4)

if N - len(q) >= 2:
    q.append(i+8)
    q.append(i+10)

if N - len(q) >= 1:
    q.append(i+6)

if N - len(q) >= 1:
    q.append(i+12)

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

Solution (Python):
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 a%2==0:
  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+4,6*a+6))
else:
  if b==0:
    del ans[-1]
    ans.append(6*a+3)
  if b==1:
    ans.append(6*a+3)
  if b==2:
    ans.extend((6*a+3,6*a+6))
  if b==3:
    ans.extend((6*a+2,6*a+3,6*a+4))
print(*ans)

Solution (Python):
n = int(input())
if n <= 15002:
  if n==3:
    print(2, 5, 63)
  else:
    if n%3:
      l = [2*(i+1) for i in range(n-2)]
      l += [3, 9]
      print(*l)
    else:
      l = [2*(i+1) for i in range(n-1) if i!=2]
      l += [3, 9]
      print(*l)
else:
  if n%2==0:
    l = [2*(i+1) for i in range(15000)]
    l += [3+6*i for i in range(n-15000)]
    print(*l)
  else:
    l = [2*(i+1) for i in range(15000) if i!=2]
    l += [3+6*i for i in range(n-14999)]
    print(*l)

Solution (Python):
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
while gcd(ans[-1],x)==1:
    ans[-1]-=6
print(*ans)

Solution (Python):
n=int(input())
a=[]
cnt=0
ans=""
s=0
if n>=6:
    for j in range(2,30001):
        if j%6==0 or j%6==2 or j%6==3 or j%6==4:
            a.append(j)
            cnt+=1
            s+=j
            if cnt==n:
                if s%6==0:
                    for i in range(n-1):
                        ans+=str(a[i])+" "
                    ans+=str(a[-1])
                    print(ans)
                elif s%6==2:
                    a[4]=30000
                    for i in range(n-1):
                        ans+=str(a[i])+" "
                    ans+=str(a[-1])
                    print(ans)
                elif s%6==3:
                    a[5]=30000
                    for i in range(n-1):
                        ans+=str(a[i])+" "
                    ans+=str(a[-1])
                    print(ans)
                else:
                    a[5]=29998
                    for i in range(n-1):
                        ans+=str(a[i])+" "
                    ans+=str(a[-1])
                    print(ans)
elif n==3:
    print(str(2)+" "+str(5)+" "+str(63))
elif n==4:
    print(str(2)+" "+str(5)+" "+str(20)+" "+str(63))
else:
    print(str(2)+" "+str(5)+" "+str(20)+" "+str(30)+" "+str(63))

Solution (Python):












n = int(input())
nn = n
if n == 3:
    print("2 5 63")
else:
    res = [2, 4, 3, 9]
    n -= 4
    for i in range(2, 5001):
        if n < 2:
            break
        else:
            n -= 2
            res.append(6 * i - 4)
            res.append(6 * i - 2)
    for i in range(3, 5000, 2):
        if n < 2:
            break
        else:
            n -= 2
            res.append(6 * i - 3)
            res.append(6 * i + 3)
    for i in range(1, 5001):
        if n == 0:
            break
        else:
            n -= 1
            res.append(6 * i)
    for i in range(len(res)):
        print(str(res[i]) + " ", end="")

Solution (Python):


N = int(input()) - 3

L = [2, 3, 25]
A = L[:]
i = 2
while N >= 2:
    if i not in L and any(i % l == 0 for l in L):
        A += (30000 - i, i)
        N -= 2
    i += 1

if N == 1:
    A.append(30000)

print(*A)

Solution (Python):
N = int(input())
ans = []
n = N//2
if N == 3:
    ans = [2,5,63]
elif 4 <= N <= 15000:
    for i in range(1,n):
        ans.append(2*i)
        x = 30000 - 2*i
        ans.append(x)
    if N % 2 == 1:
        ans.append(30000)
    ans.append(3)
    ans.append(9)
else:
    for i in range(1,15000):
        ans.append(2*i)
    x = N - 14999
    for j in range(x-1):
        y = 6*j + 3
        ans.append(y)
    if x % 2 == 1:
        ans.append(30000)
    else:
        ans.append(6*x - 3)
print(*ans)

Solution (Python):


def main():
    N = int(input().strip())

    o = [6, 2, 10, 3, 9, 4, 8, 12]
    e = [2, 10, 3, 9, 4, 8, 6, 12]
    if N == 3:
        S = [2, 5, 63]
    else:
        l = o if N % 2 != 0 else e
        S = []
        for i in range(N):
            S.append(l[i % len(l)] + 12*(i//len(l)))

    return ' '.join(map(str, S))


if __name__ == '__main__':
    print(main())

Solution (Python):
import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
input=lambda:sys.stdin.readline().rstrip()
def resolve():
    n=int(input())
    if(n==3):
        print(2,5,63)
        return
    if(n==4):
        print(2,5,20,63)
        return

    q=n//8
    r=n%8
    ans=list(i for i in range(1,12*q+1) if(i%2==0 or i%3==0))
    x=12*q
    if(r==1):
        ans+=[x+6]
    elif(r==2):
        ans+=[x+2,x+4]
    elif(r==3):
        ans+=[x+2,x+4,x+6]
    elif(r==4):
        ans+=[x+2,x+4,x+6,x+12]
    elif(r==5):
        ans+=[x+2,x+3,x+4,x+6,x+9]
    elif(r==6):
        ans+=[x+2,x+3,x+4,x+6,x+9,x+12]
    elif(r==7):
        ans+=[x+2,x+3,x+4,x+6,x+8,x+9,x+10]
    print(*ans)
resolve()

Solution (Python):
n = int(input())
if n == 3:
	print(2, 3, 25)
	exit()
if n == 4:
	print(2, 3, 4, 9)
	exit()
ans = [2, 4, 6, 3, 9]
c = 5
M = 4
while c + 1 < n and M + 6 < 30000:
	c += 2
	ans += [M + 4, M + 6]
	M += 6
c = len(ans)
M = 9
while c + 1 < n and M + 6 < 30000:
	c += 2
	ans += [M + 6, M + 12]
	M += 12
ans += [x * 6 for x in range(2, n - c + 2)]
print(*ans)

Solution (Python):

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 = I()
    if n == 3:
        l = [2,5,63]
    elif n == 4:
        l = [2,5,20,63]
    elif n == 5:
        l = [2,3,4,6,9]
    else:
        l = []
        while len(l) < n:
            for k in range(30000):
                for i in [2,3,4,6]:
                    l.append(6*k+i)
                    if len(l) == n:
                        break
                else:
                    continue
                break
        s = sum(l)%6
        if s == 2:
            l[4] = 30000
        elif s == 3:
            l[5] = 30000
        elif s == 4:
            l[6] = 30000
        elif s == 5:
            l[5] = 29998
    s = sum(l)%6
    print(*l)
    return


if __name__ == "__main__":
    solve()

Solution (Python):
def main():
    n=int(input())
    if n==3:
        print(2,5,63)
        return 0
    ans=[2,3]
    cnt=0
    i=10
    while cnt<n-4:
        if i%2==0 or i%3==0:
            ans.append(i)
            cnt+=1
        i+=1
    a=sum(ans)
    if n==20000:
        ans.pop()
        ans.pop()
        ans.append(8)
        ans.append(9)
    elif n==19999:
        ans.pop()
        ans.append(8)
    if a%6==0:
        ans.append(4)
        ans.append(8)
    elif a%6==1:
        ans.append(8)
        ans.append(9)
    elif a%6==2:
        ans.append(4)
        ans.append(6)
    elif a%6==3:
        ans.append(6)
        ans.append(9)
    elif a%6==4:
        ans.append(8)
        ans.append(6)
    elif a%6==5:
        ans.append(9)
        ans.append(4)
    print(*ans)
main()

Solution (Python):
def main():
    from fractions import gcd
    n=int(input())
    ans=[]
    cnt=0
    i=2
    while cnt<n-1:
        if i%2==0 or i%3==0:
            ans.append(i)
            cnt+=1
        i+=1
    a=sum(ans)
    for j in range(30000,0,-1):
        if gcd(j,a)>1 and gcd(a+j,2)>1 and gcd(a+j,3)>1:
            print(*(ans+[j]))
            return 0
main()

Solution (Python):
N = int(input())

if N == 3 :
    print(2, 5, 63)
    
elif N == 4 :
    print(2, 5, 20, 63)
    
else :
    ret = [2, 4, 6]
    
    i = 3
    while N - len(ret) >= 2 and i + 6 <= 30000 :
        ret.append(i)
        ret.append(i + 6)
        i += 12

    i = 8
    while N - len(ret) >= 3 and i + 4 <= 30000 :
        ret.append(i)
        ret.append(i + 2)
        ret.append(i + 4)
        i += 6
        
    if N - len(ret) == 2 :
        ret.append(29996)
        ret.append(29998)
        
    elif N - len(ret) == 1 :
        ret.append(30000)
            
    print(*ret)

Solution (Python):
N = int(input())
if N == 3:
    print(2,5,63)
    exit()
if N == 4:
    print(2,5,20,63)
    exit()
if N == 6:
    print(2,4,6,3,9,24)
    exit()
if N == 19999:
    for i in range(1,30000):
        if i%2 == 0 or i % 3 == 0:
            print(i,end=" ")
    exit()
for a in range(3,15001,3):
    b = N-a
    if 1 < b <= 5000 and b%2 == 0:
        break
for i in range(a):
    print(2*i+2,end=" ")

for i in range(b):
    print(6*i+3,end=" ")

Solution (Python):
def get_input(inp):
    li = inp.split("\n")

    def inner():
        return li.pop(0)
    return inner

INPUT="""ABCBC"""
input = get_input(INPUT)

import sys
input = sys.stdin.readline
sys.setrecursionlimit(pow(10, 6))

def main():
    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:
        sz = 0
        ans = set()
        anss = 0
        i = 0
        while True:
            if sz < n:
                ans.add(6 * i + 2)
                anss += 6 * i + 2
                sz += 1
            else:
                break
            if sz < n:
                ans.add(6 * i + 3)
                anss += 6 * i + 3
                sz += 1
            else:
                break
            if sz < n:
                ans.add(6 * i + 4)
                anss += 6 * i + 4
                sz += 1
            else:
                break
            if sz < n:
                ans.add(6 * i + 6)
                anss += 6 * i + 6
                sz += 1
            else:
                break
            i += 1
        if anss % 6 == 2:
            ans.remove(8)
            ans.add(6 * i + 6)
        elif anss % 6 == 3:
            ans.remove(9)
            ans.add(6 * i + 6)
        elif anss % 6 == 5:
            ans.remove(9)
            ans.add(6 * i + 4)
        for s in ans:
            print(s)


if __name__ == '__main__':
    main()

Solution (Python):
import sys
input = sys.stdin.readline
N = int(input())
even = [2, 10, 3, 9, 4, 8, 6, 12]
odd = [6, 2, 10, 3, 9, 4, 8, 12]
if N == 3:
  print("2 5 63")
  exit(0)
res = []
for i in range(N):
  x = i % 8
  y = i // 8
  if N % 2:
    res.append(odd[x] + 12 * y)
  else:
    res.append(even[x] + 12 * y)
print(*res)

Solution (Python):
a=0
b=0
lists=[]
n=int(input())
lists2=[2*j for j in range(1,15001)]
lists3 =[3+6*k for k in range(0,5000)]
for q in range(1,2501):
    if (n-2*q)%3==0 and 1<=(n-2*q)<=15000:
        a=(n-2*q)
        b=q
if n>=7and n!=19999:
    lists=lists2[:a]+lists3[:2*b]
    print(*lists)
elif n==3:
    lists=[2,5,63]
    print(*lists)
elif n==4:
    lists=[2 ,5 ,20, 63]
    print(*lists)  
elif n==5:
    lists=[2,4,6,3,9]
    print(*lists)
elif n==6:
    lists=[2,5,20,63,70,140]
    print(*lists)
elif n==19999:
    lists=lists2[:14985]
    addlist2=[]
    count=0
    for i in lists3:
        if i%5!=0:
            addlist2.append(i)
            count+=1
        if count==3040:
            break
    addlist3=[]
    counter=0
    for i in range(5,30001,5):
        if i%2!=0 and i%3!=0:
            addlist3.append(i)
            counter+=1
        if counter==1974:
            break
    lists=lists+addlist2+addlist3
    print(*lists)

Solution (Python):
N = int(input())
a6 = []
a2 = []
a3 = []
for i in range(2, 30001):
    if i % 6 == 0:
        a6 += [i]
    elif i % 2 == 0:
        a2 += [i]
    elif i % 3 == 0:
        a3 += [i]
if N == 3:
    print(2, 5, 63)
    exit()
N -= 4
n2 = 2 * min(4999, N // 2)
N -= n2
n3 = 2 * min(2499, N // 2)
n6 = N - n3
n2 += 2
n3 += 2
print(*(a2[:n2] + a3[:n3] + a6[:n6]))

Solution (Python):
N=int(input())
if N==3:
    print(2,5,63)
    exit()
r=[]
s=14999
for i in range((N-2)//2*2):
    r.append(s*2)
    s-=1 if (s-1)%3 else 2
    if s<1:
        break
s=9999
for i in range((N-len(r))//2*2):
    r.append(s*3)
    s-=2
    if s<1:
        break
s=5000
for i in range(len(r),N):
    r.append(s*6)
    s-=1
print(*r)

Solution (Python):
n=int(input())
if n<4:
  print(2,5,63)
  exit()
a,b=[],[]
i=j=k=0
while i<n:
  if not b or a and a[-1]>b[-1]:
    b+=3*-~k,
    k+=1
    i+=1
  else:
    t=2*-~j
    if t%3:
      a+=t,
      i+=1
    j+=1
c=sum(a+b)
if c%6:
  if c%2:
    b[-1]+=3
    c+=3
  while c%6:
    a[-1]+=2
    c+=2
    if a[-1]%3<1and a[-1]==b[-1]:
      a[-1]+=2
      c+=2
print(*a+b)

Solution (Python):
n=int(input())
if n<4:
  print(2,5,63)
  exit()
a,b=[],[]
i=j=k=0
while i<n:
  if not b or a and a[-1]>b[-1]:
    b+=3*-~k,
    k+=1
    i+=1
  else:
    t=2*-~j
    if t%3:
      a+=t,
      i+=1
    j+=1
c=sum(a+b)
if c%6:
  if c%2:
    b[-1]+=3
    c+=3
  while c%6:
    a[-1]+=2
    c+=2
    if a[-1]%3<1and a[-1]==b[-1]:
      a[-1]+=2
      c+=2
print(*a+b)

Solution (Python):
N = int(input())

a, b = N//8, N%8

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

ans = []
for i in range(a):
    for r in rep:
        ans.append(12*i+r)

to = []
if b == 1:
    to = [6]
elif b == 2:
    to = [6, 12]
elif b == 3:
    to = [3, 6, 9]
elif b == 4:
    to = [2, 3, 4, 9]
elif b == 5:
    to = [2, 3, 4, 6, 9]
elif b == 6:
    to = [2, 3, 4, 8, 9, 10]
elif b == 7:
    to = [2, 3, 4, 6, 8, 9, 10]

for r in to:
    ans.append(12*a+r)

if N == 3:
    ans = [2, 5, 63]

for a in ans:
    print(a, end=' ')
print()

Solution (Python):
n = int(input())
if n == 3:
    ans = [2, 5, 63]
elif n == 4:
    ans = [2, 5, 20, 63]
elif n == 6:
    ans = [2, 4, 8, 10, 3, 9]
else:
    even = odd = None
    for i in range(1, 5001):
        a = n-3*i
        if a % 2 == 0 and 0 < a <= 5000:
            even = 3*i
            odd = a
            break
    if n == 19999:
        even = 14999
        odd = 5000
    assert(even+odd == n)
    assert(0 < even <= 15000)
    assert(0 < odd <= 5000)
    evens = [i for i in range(1, 30001) if i%2 == 0]
    odds = [i for i in range(1, 30001) if i%3 == 0 and i%2 == 1]
    ans = evens[:even] + odds[:odd]
print(*ans)

Solution (Python):
def f(x):
    return x%2==0 or x%3==0 or x%5==0

prd = list(filter(lambda x: f(x[0]) and f(x[1]), [(i, 30 - i) for i in range(1, 14)]))

pairs = []
for i in range(1, 1000):
    for j in prd:
        pairs += [i * 30 + j[0], i * 30 + j[1]]
for i in range(0, 500):
    pairs += [i * 30 + 15, (999 - i) * 30 + 15]
pairs += [4, 26, 6, 24, 8, 22, 9, 21, 10, 20, 12, 18, 14, 16]
N = int(input())
if N == 4:
    print(2, 3, 25, 30)
    exit(0)

a = [2, 3, 25]
aiv = [28, 27, 5]
if (N - len(a)) % 2 == 1: a += aiv

a += pairs
for i in range(1, 1001): a.append(i * 30)
print(" ".join(map(str, a[:N])))

Solution (Python):
N = int(input())

if N == 3:
	print(2, 5, 63)
elif N == 4:
	print(2, 5, 20, 63)
else:
	n = N // 8
	ans = []
	for i in range(n):
		ans.append(12 * i + 2)
		ans.append(12 * i + 3)
		ans.append(12 * i + 4)
		ans.append(12 * i + 6)
		ans.append(12 * i + 8)
		ans.append(12 * i + 9)
		ans.append(12 * i + 10)
		ans.append(12 * i + 12)
	j =  N % 8
	if j == 1:
		ans.append(12 * n + 6)
	elif j == 2:
		ans.append(12 * n + 3)
		ans.append(12 * n + 9)
	elif j == 3:
		ans.append(12 * n + 3)
		ans.append(12 * n + 9)
		ans.append(12 * n + 12)
	elif j == 4:
		ans.append(12 * n + 3)
		ans.append(12 * n + 9)
		ans.append(12 * n + 6)
		ans.append(12 * n + 12)
	elif j == 5:
		ans.append(12 * n + 2)
		ans.append(12 * n + 3)
		ans.append(12 * n + 4)
		ans.append(12 * n + 6)
		ans.append(12 * n + 9)
	elif j == 6:
		ans.append(12 * n + 2)
		ans.append(12 * n + 3)
		ans.append(12 * n + 4)
		ans.append(12 * n + 8)
		ans.append(12 * n + 9)
		ans.append(12 * n + 10)
	elif j == 7:
		ans.append(12 * n + 2)
		ans.append(12 * n + 3)
		ans.append(12 * n + 4)
		ans.append(12 * n + 6)
		ans.append(12 * n + 8)
		ans.append(12 * n + 9)
		ans.append(12 * n + 10)
	ans = list(map(str, ans))
	print(" ".join(ans))

Solution (Python):
N = int(input())

if N == 3:
    print('2 5 63')
else:
    A2 = [a for a in range(2, 30001, 2) if a % 6 != 0]
    A3 = [a for a in range(3, 30001, 6)]
    A6 = [a for a in range(6, 30001, 6)]

    a2 = min(10000, (N - 2) // 2 * 2)
    N -= a2
    a3 = min(5000, N // 2 * 2)
    a6 = N - a3

    ans = A2[: a2] + A3[: a3] + A6[: a6]
    print(*ans)