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 = 'class Node:\r\n    def __init__(self,x):\r\n        self.x=x\r\n        self.next=None\r\n        self.prev=None\r\n        self.flag=True\r\n\r\nfor t in range(1):\r\n    n=int(input())\r\n    arr=list(map(int,input().split()))\r\n    for i in range(n):\r\n        arr[i]=Node(arr[i])\r\n    for i in arr:\r\n        d=[i.x%3==0,i.x,i.x//3,i.x*2]\r\n        if d[0]:\r\n            for j in arr:\r\n                if j.x==d[2]:\r\n                    i.next=j\r\n                    j.prev=i\r\n                    break\r\n            else:\r\n                for j in arr:\r\n                    if j.x == d[3]:\r\n                        i.next = j\r\n                        j.prev = i\r\n                        break\r\n        else:\r\n            for j in arr:\r\n                if j.x==d[3]:\r\n                    i.next=j\r\n                    j.prev=i\r\n                    break\r\n    f,l=None,None\r\n    for i in arr:\r\n        if i.prev==None:\r\n            f=i\r\n        elif i.next==None:\r\n            l=i\r\n    while f!=l and l!=None:\r\n        print(f.x,end=" ")\r\n        f=f.next\r\n    print(f.x)'
_co = compile(_CODE, USER_FILENAME, "exec")
exec(_co, ns, ns)

```

Measured memory_bytes: 16423