i = int(input())
g = [int(i) for i in input().split()]
t = 0
y = 0
u = 0
for e in range(i):
if g[e] == 1:
t += 1
elif g[e] == 2:
y += 1
else:
u += 1
for q in range(t):
print("1",end=" ")
for q in range(y):
print("2",end=" ")
for q in range(u):
print("3",end=" ")
print()
Here where I fine it : https://steam.oxxostudio.tw/category/python/zerojudge/d587.html