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

Solution code:
n = int(input())
if n == 3:
    print(2,5,63)
elif n == 4:
    print(2,5,20,63)
else:
    l = [2,4,3,9]
    x = n-4
    for i in range(1,min(5000,x//2)):
        l.append(6*i+2)
        l.append(6*i+4)
    
    if len(l) != n:
        x = n-len(l)
        if x > 5000:
            for j in range(x-5000):
                l.append(6*(j+1))
            x = 5000
        elif x%2:
            l.append(6)
            x -= 1
        for i in range(2,x+2):
            l.append(6*i+3)
    print(*l)

Submission status: Wrong Answer

Solution code:
n = int(input())
if n == 3:
    print(2,5,63)
elif n == 4:
    print(2,5,20,63)
else:
    l = [2,4,3,9]
    x = n-4
    for i in range(1,min(5000,x//2)):
        l.append(6*i+2)
        l.append(6*i+4)
    
    if len(l) != n:
        x = n-len(l)
        if x > 5000:
            for j in range(x-5000):
                l.append(6*(j+1))
            x = 5000
        elif x%2:
            l.append(6)
            x -= 1
        for i in range(x):
            l.append(6*i+3)
    print(*l)

Submission status: Wrong Answer

Solution code:
import math
n = int(input())
if n == 3:
    print(2,5,63)
elif n == 4:
    print(2,5,20,63)
else:
    l = set()
    x = (n-2)//3
    if x%2 == 1:
        for i in range(min(15000,(n-2)//3*3)):
            l.add((i+1)*2)
    else:
        for i in range(min(5000,(n-2)//3)*3-3):
            l.add((i+1)*2)
    
    x = n-len(l)

    if x%2 == 0:
        for i in range(3,30000,6):
            l.add(i)
            if len(l) == n:
                break
    else:
        for i in range(3,30000,6):
            if len(l) == n-1:
                break
            l.add(i)
    if len(l) != n:
        for i in range(6,30001,6):
            l.add(i)
            if len(l) == n:
                break
    if len(l) == n:
        print(*l)
        exit()
    l = set()
    for i in range(min(15000,(n-2)//3*3)):
        l.add((i+1)*2)
    x = n-len(l)
    if x%2 == 0:
        for i in range(3,30000,6):
            l.add(i)
            if len(l) == n:
                break
    else:
        for i in range(3,30000,6):
            if len(l) == n-1:
                break
            l.add(i)
 
    if len(l) != n:
        for i in range(6,30001,6):
            l.add(i)
            if len(l) == n:
                break
    print(*l)

Submission status: Wrong Answer

Solution code:
import math
n = int(input())
if n == 3:
    print(2,5,63)
elif n == 4:
    print(2,5,20,63)
else:
    l = set()
    for i in range(min(15000,(n-2)//3*3)):
        l.add((i+1)*2)
    x = n-len(l)
    if x%2 == 0:
        for i in range(3,30000,6):
            l.add(i)
            if len(l) == n:
                break
    else:
        for i in range(3,30000,6):
            if len(l) == n-1:
                break
            l.add(i)

    if len(l) != n:
        for i in range(6,30001,6):
            l.add(i)
            if len(l) == n:
                break
    print(*l)

Submission status: Wrong Answer

Solution code:
n = int(input())
if n == 3:
    print(2,5,63)
elif n == 4:
    print(2,5,20,63)
else:
    l = set()
    for i in range((n-2)//3*3):
        l.add((i+1)*2)
    x = n-len(l)
    if x%2 == 0:
        for i in range(3,30000,6):
            l.add(i)
            if len(l) == n:
                break
    else:
        for i in range(3,30000,6):
            if len(l) == n-1:
                break
            l.add(i)

    if len(l) != n:
        for i in range(6,30001,6):
            l.add(i)
            if len(l) == n:
                break
    print(*l)

Submission status: Wrong Answer

Solution code:
n = int(input())
if n == 3:
    print(2,5,63)
elif n == 4:
    print(2,5,20,63)
else:
    l = set()
    for i in range((n-2)//3*3):
        l.add((i+1)*2)
    x = n-len(l)
    for i in range(3,30000,6):
        l.add(i)
        x -= 1
        if x == 0:
            break
    if x != 0:
        for i in range(6,30001,6):
            l.add(i)
            x -= 1
            if x == 0:
                break
    print(*l)

Submission status: Wrong Answer

Solution code:
N=int(input())
if N<=15000:
  L=list(range(2,2*(N-1),2))
  if N<=10000:
    if (N-1)%2==0:
      k=N-2
    else:
      k=N-1
    L.append(k)
    L.append(k*3)
    R=list()
  else:
    if (N-1)%2==0:
      k=N-1
    else:
      k=N-2
    while k%2==0:
      k//=2
    L.append(k)
    L.append(k*3)
    R=list()
else:
  if N%2==0:
    L=list(range(2,30002,2))
    N-=15000
    R=list(range(3,3+6*N,6))
  else:
    L=list(range(2,30000,2))
    N-=15000
    R=list(range(3,3+6*(N+1),6))
s=L+R
print(" ".join(list(map(str,s))))

Submission status: Wrong Answer

Solution code:
def slv(n):
    if n==3:return [2,5,63]
    ary=[2,3]
    sumb=2
    for i in range(4,30001,2):
        ary.append(i)
        sumb+=i
        if len(ary)==n-1:
            if sumb%3==0:break
            sumb-=ary.pop()
    sumb+=3
    for i in range(6,30001,3):
        if i%2!=0:
            ary.append(i)
            sumb+=i
        if len(ary)==n:
            if sumb%2==0:break
            sumb-=ary.pop()
    #print(sum(ary),len(ary))
    return ary

n=int(input())
#slv(n)
print(*slv(n),sep=' ')

Submission status: Wrong Answer

Solution code:
n=int(input())
ary=[2,3]
sumb=2
for i in range(4,30001,2):
    ary.append(i)
    sumb+=i
    if len(ary)==n-1:
        if sumb%3==0:break
        sumb-=ary.pop()
sumb+=3
for i in range(6,30001,3):
    if i%2!=0:
        ary.append(i)
        sumb+=i
    if len(ary)==n:
        if sumb%2==0:break
        sumb-=ary.pop()

print(*ary,sep=' ')
#print(sum(ary),sumb)
#print(len(ary),i)

Submission status: Wrong Answer

Solution code:
n=int(input())
ary=[]
sumb=0
for i in range(1,30001):
    if i%2==0 or i%3==0:
        ary.append(i)
        sumb+=i
    if len(ary)==n:
        if sumb%6==0:break
        sumb-=ary.pop()
print(*ary,sep=' ')

Submission status: Wrong Answer

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
    if n == 3:
        print("2 3 25")
        exit()
    elif n == 4:
        print("2 5 20 63")
        exit()
    tn = (n//8)*8
    sm = 0
    nm = 0
    ans = []
    la = 0
    for i in range(1,30001):
        if i%2 == 0 or i%3 == 0:
            ans.append(i)
            sm += i
            nm += 1
        if nm == tn:
            if ans:
                la = ans[-1]
            break

    if n%8 == 0:
        pass
    elif n%8 == 1:
        ans.append(la+6)
    elif n%8 == 2:
        ans.append(la+2)
        ans.append(la+4)
    elif n%8 == 3:
        ans.append(la+2)
        ans.append(la+4)
        ans.append(la+6)
    elif n%8 == 4:
        ans.append(la+2)
        ans.append(la+4)
        ans.append(la+6)
        ans.append(la+12)
    elif n%8 == 5:
        ans.append(la+2)
        ans.append(la+3)
        ans.append(la+4)
        ans.append(la+6)
        ans.append(la+9)
    elif n%8 == 6:
        ans.append(la+2)
        ans.append(la+3)
        ans.append(la+4)
        ans.append(la+6)
        ans.append(la+8)
        ans.append(la+10)
    elif n%8 == 7:
        ans.append(la+2)
        ans.append(la+3)
        ans.append(la+4)
        ans.append(la+6)
        ans.append(la+8)
        ans.append(la+10)
        ans.append(la+12)


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


    return None

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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
    if n == 3:
        print("2 3 25")
        exit()
    tn = (n//4)*4
    sm = 0
    nm = 0
    ans = []
    la = 0
    for i in range(1,30001):
        if i%2 == 0 or i%3 == 0:
            ans.append(i)
            sm += i
            nm += 1
        if nm == tn:
            if ans:
                la = ans[-1]
            break

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

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


    return None

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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
    sm = 0
    nm = 0
    ans = []
    for i in range(1,30001):
        if i%2 == 0 or i%3 == 0 or i%5 == 0:
            ans.append(i)
            sm += i
            nm += 1
        if nm == n-1:
            break

    for i in range(ans[-1]+1,30001):
        if (i+sm)%30 == 0 and math.gcd(i,sm) != 1:
            ans.append(i)
            break

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


    return None

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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
    sm = 0
    nm = 0
    ans = []
    for i in range(1,30001):
        if i%2 == 0 or i%3 == 0 or i%5 == 0:
            ans.append(i)
            sm += i
            nm += 1
        if nm == n-1:
            break

    for i in range(ans[-1]+2,30001):
        if (i+sm)%30 == 0:
            ans.append(i)
            break

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


    return None

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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())
    sm = 0
    ans = []
    for i in range(1,30001):
        if i%2 == 0 or i%3 == 0 or i%5 == 0:
            ans.append(i)
            sm += i
        if len(ans) == n-1:
            break

    sm %= 30
    for i in range(ans[-1]+1,30001):
        if (i+sm)%30 == 0:
            ans.append(i)
            break

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

    return None

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
n = int(input())
ANS = []
even = [2, 10, 3, 9, 4, 8, 6, 12]
odd = [12, 2, 10, 3, 9, 4, 8, 6]
if n == 3:
    print(2, 3, 10)
else:
    if n % 2 == 0:
        tmp = even
    else:
        tmp = odd
    ANS += [x for x in tmp[:(n % 8)]]
    ANS += [12 * i + x for x in tmp for i in range(1, (n // 8) + 1)]
    print(*ANS)

Submission status: Wrong Answer

Solution code:
n = int(input())
ANS = [2, 3, 10, 9, 6, 12, 4, 8]
even = [2, 10, 3, 9, 4, 8, 6, 12]
odd = [12, 2, 10, 3, 9, 4, 8, 6]
if n == 7:
    ANS = [2, 3, 10, 9, 6, 4, 8]
    print(*ANS)
elif n <= 8:
    print(*ANS[:n])
else:
    n -= 6
    p = n // 8
    r = n % 8
    for i in range(2, p + 2):
        ANS += [6 * i + x for x in even]
    if r % 2 == 0:
        ANS += [6 * (p + 2) + x for x in even[:r]]
    else:
        ANS += [6 * (p + 2) + x for x in odd[:r]]
    print(*ANS)

Submission status: Wrong Answer

Solution code:
n = int(input())
ANS = [2, 3, 10, 9, 6, 12]
even = [2, 10, 3, 9, 4, 8, 6, 12]
odd = [12, 2, 10, 3, 9, 4, 8, 6]
if n <= 6:
    print(*ANS[:n])
else:
    n -= 6
    p = n // 8
    r = n % 8
    for i in range(2, p + 2):
        ANS += [6 * i + x for x in even]
    if r % 2 == 0:
        ANS += [6 * (p + 2) + x for x in even[:r]]
    else:
        ANS += [6 * (p + 2) + x for x in odd[:r]]
    print(*ANS)

Submission status: Wrong Answer

Solution code:
# 奇数は偶数個->偶数を除いたときに偶数なら公約数が２になる
import math
N = int(input())
# for N in range(3, 20001):
ans = [2, 3, 25]
if N <= 1003:
    ans += [i for i in range(30, (N-3)*30+1, 30)]
    # print(*ans)
else:
    D = N - len(ans)
    for i in range(12, min(30000, (D//10)*20) + 1, 30):
        ans.append(i)
        ans.append(i+2)
        ans.append(i+4)
        ans.append(i+6)
        ans.append(i+8)
        ans.append(i+10)
        ans.append(i+12)
        ans.append(i+14)
        ans.append(i+16)
        ans.append(i+18)
    for i in range(32, min(30000, (D//5)*10) + 1, 30):
        ans.append(i)
        ans.append(i+2)
        ans.append(i+4)
        ans.append(i+6)
        ans.append(i+8)
    d = N - len(ans)
    # if d == 0:
    for i in range(33, min(30000, (d//4)*30 + 30)+1, 30):
        ans.append(i)
        ans.append(i+6)
        ans.append(i+18)
        ans.append(i+24)
    d = N - len(ans)
    for i in range(15, min(30000, (d//2)*60)+1, 60):
        ans.append(i)
        ans.append(i+30)
    d = N - len(ans)
    # for i in range(125, min(1325, (d//2)*400)+1, 400):
    #     ans.append(i)
    #     ans.append(i+200)
    d = N - len(ans)
    for i in range(min(1000, d)):
        ans.append(30*i + 30)

print(*sorted(ans[:N]))
# S = sum(ans[:N])
# s = S
# t = 0
# while(S > 0):
#     t += S % 10
#     S //= 10
# if t % 3 != 0 or s % 10 != 0 or len(ans) < N:
#     print(ans[:N])
#     print(t, s, len(ans), N)
#     break
# else:
#     print(N)

Submission status: Wrong Answer

Solution code:
N = int(input())
ans = [2, 3, 25]
if N == 4:
    print(2, 3, 25, 30)
else:
    for i in range(125, min(30000, ((N-3)//2)*400)+1, 400):
        ans.append(i)
        ans.append(i+200)
    D = N - len(ans)
    for i in range(12, min(30000, (D//5)*10 - 10) + 1, 2):
        ans.append(i)
    d = N - len(ans)
    # if d == 0:
    for i in range(33, min(30000, (d//4)*30 + 30)+1, 30):
        ans.append(i)
        ans.append(i+6)
        ans.append(i+18)
        ans.append(i+24)
    d = N - len(ans)
    for i in range(15, min(30000, (d//2)*60 + 60)+1, 60):
        ans.append(i)
        ans.append(i+30)

    print(*sorted(ans[:N]))

Submission status: Wrong Answer

Solution code:
import math

def _print(S):
  print(S)
  return
  S = list(map(int, S.split()))
  print(len(S))
  for s in S:
    if math.gcd(s, sum(S)-s) == 1:
      print("FAIL!!")
      
  

def main():
  N = int(input())
  # 2, 3, 5, 7, 11, ...
  # 2, p-2, p
  # sum 2 * (p-2) * p: 2pp-4p
  # 2, p-2, p, = 2p, rest = 2pp - 6p
  
  # 2, 3, 4, 6, 8, 9, 10, 12,     14, 15, 16, 18, 20, 21, 22, 24,     ...

  # 12, 4+8, 6 ,  18, 14+16,   24  
  if N >= 8:
    n = N % 8
    t = (8 - n)%8
    S = {2, 3, 4, 6, 8, 9, 10, 12, 14, 15, 16, 18, 20, 21, 22, 24}
    if t >= 4:
      S -= {4, 8, 14, 16}
      t -= 4
    elif t >= 2:
      S -= {4, 8}
      t -= 2
    while t:
      S -= {6*t}
      t -= 1
    #print(len(S), S)
    i = 2
    
    while N > len(S):
      S.update({i*12+j for j in [2,3,4,6,8,9,10,12]})
      i += 1
      #print(i, S)
    _print(' '.join(f'{s}' for s in S))
    
   # for s in S:
    #  print(math.gcd(s, sum(S)-s))
  elif N == 7:
    _print('2 3 4 8 9 10 12')
  elif N == 6:
    _print('2 3 4 8 9 10')
  elif N == 5:
    _print('2 3 9 10 12')
  elif N == 4:
    _print('2 5 20 63')
  elif N == 3:
    _print('2 5 63')
  
  
main()

Submission status: Wrong Answer

Solution code:
import math

def _print(S):
  print(S)
  #S = map(int, S.split())
  #for s in S:
  #  if math.gcd(s, sum(S)-s) == 1:
  #    print("FAIL!!")
      
  

def main():
  N = int(input())
  # 2, 3, 5, 7, 11, ...
  # 2, p-2, p
  # sum 2 * (p-2) * p: 2pp-4p
  # 2, p-2, p, = 2p, rest = 2pp - 6p
  
  # 2, 3, 4, 6, 8, 9, 10, 12,     14, 15, 16, 18, 20, 21, 22, 24,     ...

  # 12, 4+8, 6 ,  18, 14+16,   24  
  if N >= 8:
    n = N % 8
    t = (8 - n)%8
    S = {2, 3, 4, 6, 8, 9, 10, 12, 14, 15, 16, 18, 20, 21, 22, 24}
    if t >= 4:
      S -= {4, 8, 14, 16}
      t -= 4
    elif t >= 2:
      S -= {4, 8}
      t -= 2
    while t:
      S -= {6*t}
      t -= 1
    i = 3
    
    while N > len(S):
      S.update({i*8+j for j in [2,3,4,6,8,9,10,12]})
      i += 1
    _print(' '.join(f'{s}' for s in S))
    
   # for s in S:
    #  print(math.gcd(s, sum(S)-s))
  elif N == 7:
    _print('2 3 4 8 9 10 12')
  elif N == 6:
    _print('2 3 4 8 9 10')
  elif N == 5:
    _print('2 3 9 10 12')
  elif N == 4:
    _print('2 5 20 63')
  elif N == 3:
    _print('2 5 63')
  
  
main()

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

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

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

Submission status: Wrong Answer

Solution code:
import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")


n = int(input())
if n==3:
    ans = [2,3,25]
elif n==4:
    ans = [2,3,4,9]
else:
#     n -= 1
    ans = []
    for i in range(2, 30001):
        if i%2==0 or i%3==0:
            ans.append(i)
        if len(ans)>=(n//4)*4:
            if n%4==1:
                ans.append(i+3)
            elif n%4==2:
                ans.append(i+3)
                ans.append(i+6)
            elif n%4==3:
                ans.append(i+2)
                ans.append(i+3)
                ans.append(i+4)
            break
#     s = sum(ans)
#     for i in range(30000, 1, -1):
#         if i%2==0 or i%3==0:
#             if i%6==(6 - s%6)%6 and i not in ans:
#                 ans.append(i)
#                 break

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

Submission status: Wrong Answer

Solution code:
import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")


n = int(input())
if n==3:
    ans = [2,3,25]
elif n==4:
    ans = [2,3,4,9]
else:
    n -= 1
    ans = []
    for i in range(2, 30001):
        if i%2==0 or i%3==0:
            ans.append(i)
        if len(ans)>=(n//4)*4:
            if n%4==1:
                ans.append(i+3)
            elif n%4==2:
                ans.append(i+3)
                ans.append(i+6)
            elif n%4==3:
                ans.append(i+2)
                ans.append(i+3)
                ans.append(i+4)
            break
    s = sum(ans)
    for i in range(30000, 1, -1):
        if i%2==0 or i%3==0:
            if i%6==(6 - s%6)%6:
                ans.append(i)
                break

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

Submission status: Wrong Answer

Solution code:
import bisect
import copy
import heapq
import math
import sys
from collections import *
from functools import lru_cache
from itertools import accumulate, combinations, permutations, product
def input():
    return sys.stdin.readline()[:-1]
def ruiseki(lst):
    return [0]+list(accumulate(lst))
sys.setrecursionlimit(500000)
mod=pow(10,9)+7
al=[chr(ord('a') + i) for i in range(26)]
direction=[[1,0],[0,1],[-1,0],[0,-1]]

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:
    anslst=[]
    for i in range(n):
        if i%4==0:
            anslst.append(i//4*6+2)
        elif i%4==1:
            anslst.append(i//4*6+3)
        elif i%4==2:
            anslst.append(i//4*6+4)
        elif i%4==3:
            anslst.append(i//4*6+6)
    if sum(anslst)%6==0:
        pass
    elif sum(anslst)%6==3:
        anslst.remove(9)
        if anslst[-1]%6==0:
            anslst.append(anslst[-1]+6)
        else:
            anslst.append(anslst[-1]+3)
    elif sum(anslst)%6==2:
        anslst.remove(8)
        anslst.append(i//4*6+6)
    elif sum(anslst)%6==5:
        anslst.remove(9)
        anslst.append(i//4*6+4)
    print(*anslst)

Submission status: Wrong Answer

Solution code:
import bisect
import copy
import heapq
import math
import sys
from collections import *
from functools import lru_cache
from itertools import accumulate, combinations, permutations, product
def input():
    return sys.stdin.readline()[:-1]
def ruiseki(lst):
    return [0]+list(accumulate(lst))
sys.setrecursionlimit(500000)
mod=pow(10,9)+7
al=[chr(ord('a') + i) for i in range(26)]
direction=[[1,0],[0,1],[-1,0],[0,-1]]

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:
    anslst=[]
    for i in range(n):
        if i%4==0:
            anslst.append(i//4*6+2)
        elif i%4==1:
            anslst.append(i//4*6+3)
        elif i%4==2:
            anslst.append(i//4*6+4)
        elif i%4==3:
            anslst.append(i//4*6+6)
    if sum(anslst)%6==0:
        pass
    elif sum(anslst)%6==3:
        anslst.remove(9)
        if anslst[-1]%6==0:
            anslst.append(anslst[-1]+6)
        else:
            anslst.append(anslst[-1]+3)
    elif sum(anslst)%6==2:
        anslst.remove(8)
        anslst.append(i//4*6+6)
    elif sum(anslst)%6==4:
        anslst.remove(9)
        anslst.append(i//4*6+4)
    print(*anslst)

Submission status: Wrong Answer

Solution code:
import sys
stdin = sys.stdin
sys.setrecursionlimit(10**6)
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
nn = lambda: list(stdin.readline().split())
ns = lambda: stdin.readline().rstrip()

n = ni()
import math

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

a = [2,3,5]
now = 30000

for i in range(n-3):
    if i == n-4:
        total = sum(a)
        m = now
        while True:
            if (total+now)%30 == 0 and math.gcd(total,now) > 1:
                a.append(now)
                break
            if now < 6:
                if a[-1]%2==0:
                    a[-1]-=2
                elif a[-1]%3==0:
                    a[-1]-=3
                elif a[-1]%5==0:
                    a[-1]-=5
                total = sum(a)
                now = m+1
            now-=1
    else:
        while True:
            if now%2 == 0 or now%3 == 0 or now%5 == 0:
                a.append(now)
                now-=1
                break
            now-=1

print(*a)

Submission status: Wrong Answer

Solution code:
import sys
stdin = sys.stdin
sys.setrecursionlimit(10**6)
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
nn = lambda: list(stdin.readline().split())
ns = lambda: stdin.readline().rstrip()

n = ni()
import math

if n==3:
    print(2,3,65)

a = [2,3,5]
now = 30000

for i in range(n-3):
    if i == n-4:
        total = sum(a)
        while True:
            if (total+now)%30 == 0 and math.gcd(total,now) > 1:
                a.append(now)
                break
            now-=1
    else:
        while True:
            if now%2 == 0 or now%3 == 0 or now%5 == 0:
                a.append(now)
                now-=1
                break
            now-=1

print(*a)

Submission status: Wrong Answer

Solution code:
import sys
stdin = sys.stdin
sys.setrecursionlimit(10**6)
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
nn = lambda: list(stdin.readline().split())
ns = lambda: stdin.readline().rstrip()

n = ni()
import math

a = [2,3]
now = 30000

for i in range(n-2):
    if i == n-3:
        total = sum(a)
        while True:
            if (total+now)%6 == 0 and math.gcd(total,now) > 1:
                a.append(now)
                break
            now-=1
    else:
        while True:
            if now%2 == 0 or now%3 == 0:
                a.append(now)
                now-=1
                break
            now-=1

print(*a)

Submission status: Wrong Answer

Solution code:
import sys
stdin = sys.stdin
sys.setrecursionlimit(10**6)
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
nn = lambda: list(stdin.readline().split())
ns = lambda: stdin.readline().rstrip()

n = ni()
import math

a = [2,3]
now = 30000

for i in range(n-2):
    if i == n-3:
        total = sum(a)
        while True:
            if (total+now)%6 == 0 and math.gcd(total,now) > 1:
                a.append(now)
                break
            now-=1
    else:
        while True:
            if now%2 == 0 or now%3 == 0:
                a.append(now)
                break
            now-=1

print(*a)

Submission status: Wrong Answer

Solution code:
n=int(input())
vec=[]
if n==3:
    vec=[2,5,63]
elif n==4:
    vec=[2,3,4,9]
elif n==5:
    vec=[2,3,4,6,9]
elif n==6:
    vec=[2,3,4,6,9,12]
elif n==7:
    vec=[2,3,4,6,8,9,10]
else:
    for i in range(1,30001):
        if (i%2)*(i%3)==0:
            vec.append(i)
            if len(vec)==n//8*8:
                break
    mx=vec[-1]
    print(mx,len(vec),n)
    n%=8
    if n==0:
        vec2=[]
    elif n==1:
        vec2=[6]
    elif n==2:
        vec2=[2,4]
    elif n==3:
        vec2=[2,4,6]
    elif n==4:
        vec2=[2,3,4,9]
    elif n==5:
        vec2=[2,3,4,6,9]
    elif n==6:
        vec2=[2,3,4,6,9,12]
    elif n==7:
        vec2=[2,3,4,6,8,9,10]
    for i in vec2:
        vec.append(i+mx)
print(*vec)

Submission status: Wrong Answer

Solution code:
n=int(input())
vec=[]
if n==3:
    vec=[2,5,63]
elif n==4:
    vec=[2,3,4,9]
elif n==5:
    vec=[2,3,4,6,9]
elif n==6:
    vec=[2,3,4,6,9,12]
elif n==7:
    vec=[2,3,4,6,8,9,10]
else:
    for i in range(1,30001):
        if (i%2)*(i%3)==0:
            vec.append(i)
            if len(vec)==n//8*8:
                break
    mx=vec[-1]
    n%=8
    if n==0:
        vec2=[]
    elif n==1:
        vec2=[6]
    elif n==2:
        vec2=[2,4]
    elif n==3:
        vec2=[2,4,6]
    elif n==4:
        vec2=[2,3,4,9]
    elif n==5:
        vec2=[2,3,4,6,9]
    elif n==6:
        vec2=[2,3,4,6,9,12]
    elif n==7:
        vec2=[2,3,4,6,8,9,12]
    for i in vec2:
        vec.append(i+mx)
print(*vec)

Submission status: Wrong Answer

Solution code:
n=int(input())
vec=[]
for i in range(1,30001):
  if (i%2)*(i%3)==0:
    vec.append(i)
    if len(vec)==n-1:
      break
while sum(vec)%6==1 or sum(vec)%6==5:
  vec[-1]+=1
for i in range(vec[-1],30001):
    if (i%2)*(i%3)==0 and (sum(vec)+i)%6==0:
      vec.append(i)
      break
if n==3:
  vec=[2,5,63]
print(*vec)

Submission status: Wrong Answer

Solution code:
N = int(input())
N -= 3
ans = [2, 3, 4]
odd = []; pair = []; even = []
for i in range(6, 30001):
  if i % 6 == 0:
    even.append(i)
  elif i % 3 == 0:
    odd.append(i)
  elif i % 2 == 0:
    pair.append(i)

pair = pair[::-1]
while N:
  if N >= 4:
    N -= 4
    ans.append(odd.pop())
    ans.append(even.pop())
    ans.append(pair.pop()); ans.append(pair.pop())
  elif N >= 2:
    N -= 2
    if len(pair) >= 2:
      ans.append(pair.pop()); ans.append(pair.pop())
    else:
      ans.append(odd.pop())
      ans.append(even.pop())
  else:
    N -= 1
    if odd:
      ans.append(odd.pop())
    else:
      ans.append(even.pop())

print(*ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
x3 = N//2
x2 = N - x3

f = lambda x:x*(x+1)//2
s = set([3*i for i in range(1, x3)])
v = x3*3
while 1:
    if (f(x3-1)+v)%2==0:
        s.add(v)
        break
    v += 3

v = 2
cnt = 0
s2 = 0
while cnt<x2-1:
    if not v in s:
        s2 += v
        s.add(v)
        cnt += 1
    v += 2

v = 2
while 1:
    if (v+s2)%3==0 and v not in s:
        s.add(v)
        break
    v += 2

print(*s)

Submission status: Wrong Answer

Solution code:
n=int(input())
# Disadvantages of not reading qn properly in the beginning, all of them must be distinct
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:
    ans=[]
    k=0
    while len(ans)<n:
        ans.append(6*k+2)
        ans.append(6*k+3)
        ans.append(6*k+4)
        ans.append(6*k+6)
        k+=1
    # print(ans)
    ans=sorted(ans)[:n]
    # print(ans)
    nxt=6*(ans[-1]//6)
    if sum(ans)%6==2:
        ans.remove(8)
        ans.append(nxt)
    elif sum(ans)%6==3:
        ans.remove(9)
        ans.append(nxt)
    elif sum(ans)%6==5:
        ans.remove(9)
        ans.append(nxt+4)
    print(" ".join(list(map(str,ans))))