The chef likes to play with numbers. He takes some integer number x, writes it down on his iPad, and then performs with it n−1 operations of the two kinds:
- divide the number x by 3 (x must be divisible by 3);
- multiply the number x by 2.
After each iteration, Chef writes down the result on his iPad and replaces x with the result. So there will be n numbers on the iPad after all.
You are given a sequence of length n — the numbers that Chef wrote down. This sequence is given in the order of the sequence can mismatch the order of the numbers written on the iPad.
Your problem is to rearrange elements of this sequence in such a way that it can match a possible Chef's game in the order of the numbers written on the board. I.e. each next number will be exactly two times the previous number or exactly one-third of the previous number.
I can give a guarantee that the answer exists.

-----Input:-----
- The first line of the input contains an integer number N i.e the number of the elements in the sequence. 
- The second line of the input contains n integer numbers a1,a2,…, an i.e rearranged (reordered) sequence that Chef can write down on the iPad.

-----Output:-----
Print N integer numbers — rearranged (reordered) input sequence that can be the sequence that Chef could write down on the iPad.
It is guaranteed that the answer exists

-----Constraints-----
- $2 \leq N \leq 100$
- $1 \leq A[i] \leq  3* 10^{18} $

-----Sample Input:-----
6
4 8 6 3 12 9

-----Sample Output:-----
9 3 6 12 4 8 

-----EXPLANATION:-----
In the first example, the given sequence can be rearranged in the following way: [9,3,6,12,4,8]. It can match possible Polycarp's game which started with x=9.

```python

USER_FILENAME = "<user_code>"
import sys, json, builtins
import math, heapq, bisect, itertools, functools, collections, statistics, fractions, decimal, operator, array, random, re, string, os, pathlib
try:
    import resource as _res
except Exception:
    _res = None
from collections import Counter, defaultdict, deque, OrderedDict
from functools import lru_cache, reduce
from itertools import accumulate, permutations, combinations, product
from math import gcd, ceil, floor, sqrt
from decimal import Decimal
try:
    from typing import *
except Exception:
    pass
try:
    sys.setrecursionlimit(1_000_000)
except Exception:
    pass
try:
    import site as _site
    try:
        _sys_sites = _site.getsitepackages() if hasattr(_site, "getsitepackages") else []
        for _p in _sys_sites:
            if _p and _p not in sys.path:
                sys.path.append(_p)
    except Exception:
        pass
    try:
        _usp = _site.getusersitepackages()
        if isinstance(_usp, str):
            _usp = [_usp]
        for _p in _usp:
            if _p and _p not in sys.path:
                sys.path.append(_p)
    except Exception:
        pass
except Exception:
    pass

ns = {"__name__": "__main__"}
for _k, _v in list(globals().items()):
    if not _k.startswith("_"):
        ns[_k] = _v
_CODE = 'def abc(v):\r\n    for j in d[v]:\r\n        k.append(j)\r\n    if d[v]:\r\n        abc(d[v][-1])\r\nn=int(input())\r\nl=list(map(int,input().split()))\r\nl.sort()\r\nd={}\r\nk=[]\r\nfor i in l:\r\n    a=[]\r\n    b=[]\r\n    req=2*i\r\n    for j in l:\r\n        if j==req:\r\n            a.append(j)\r\n            req = 2*j\r\n    if not i%3:\r\n        req=i//3\r\n    else:\r\n        req=-1\r\n    for j in range(n-1,-1,-1):\r\n        if req==-1:\r\n            break\r\n        if l[j]==req:\r\n            b.append(l[j])\r\n            if not l[j]%3:\r\n                req=l[j]//3\r\n            else:\r\n                req=-1\r\n    if a and b:\r\n        d[i]=[]\r\n    elif a:\r\n        d[i]=a\r\n    elif b:\r\n        d[i]=b\r\n    else:\r\n        d[i]=a\r\nfor i in l:\r\n    k=[i]\r\n    try:\r\n        abc(i)\r\n    except:\r\n        pass\r\n    #print(i,k)\r\n    if len(k)==n:\r\n        print(*k)\r\n        break\r\n    k=[]\r\n    \r\n    \r\n        \r\n    \r\n    \r\n    \r\n    \r\n        \r\n    \r\n'
_co = compile(_CODE, USER_FILENAME, "exec")
exec(_co, ns, ns)

```

Measured memory_bytes: 13547