from collections import defaultdict

def solve():
    n = int(input())
    e = defaultdict(int)
    r = defaultdict(list)
    for _ in range(n):
        x = int(input())
        e[x] += 1
    for x in e.items():
        if x[1] >= 3:
            r[3].append(x[0])
            continue
        r[x[1]].append(x[0])
    r[1].sort()
    r[2].sort()
    r[3].sort()
    answer = [0] * ((n+1)//2)
    for i in range(0, len(answer), 2):
        answer[i] = r[1].pop()
    x = 2
    for i in range(1, len(answer), 2):
        if x == 2:
            answer[i] = r[x].pop()
            x = 3
        else:
            answer[i] = r[x].pop()
            x = 2
    for i in range(len(answer)):
        print(answer[i], end=" ")

def main():
    t = 1
    while t > 0:
        solve()
        t -= 1

if __name__ == "__main__":
    main()
