# Divide by three, multiply by two

time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

Polycarp likes to play with numbers. He takes some integer number

, writes it down on the board, and then performs with it

operations of the two kinds:

• divide the number

by ( must be divisible by

• );
• multiply the number

by

• .

After each operation, Polycarp writes down the result on the board and replaces

by the result. So there will be

numbers on the board after all.

You are given a sequence of length

— the numbers that Polycarp wrote down. This sequence is given in arbitrary order, i.e. the order of the sequence can mismatch the order of the numbers written on the board.

Your problem is to rearrange (reorder) elements of this sequence in such a way that it can match possible Polycarp’s game in the order of the numbers written on the board. I.e. each next number will be exactly two times of the previous number or exactly one third of previous number.

It is guaranteed that the answer exists.

Input

The first line of the input contatins an integer number

() — the number of the elements in the sequence. The second line of the input contains integer numbers (

) — rearranged (reordered) sequence that Polycarp can wrote down on the board.

Output

Print

integer numbers — rearranged (reordered) input sequence that can be the sequence that Polycarp could write down on the board.

It is guaranteed that the answer exists.

Examples

Input

Copy
6
4 8 6 3 12 9

Output

Copy
9 3 6 12 4 8

Input

Copy
4
42 28 84 126

Output

Copy
126 42 84 28

Input

Copy
2
1000000000000000000 3000000000000000000

Output

Copy
3000000000000000000 1000000000000000000
Note

In the first example the given sequence can be rearranged in the following way:

. It can match possible Polycarp’s game which started with .

#include <iostream>
#include <bits/stdc++.h>
using namespace std;
long long int h_3(long long int a)//3的个数
{
long long int cnt=0;
while(a%3==0)
{
cnt++;
a=a/3;
}
return cnt;
}
bool cmp(long long int a,long long int b)
{
long long aa,bb;
aa=h_3(a);
bb=h_3(b);
if(aa==bb)
{
return a<b;
}
else return aa>bb;
}
int main()
{
int n;
long long int a[110];
cin>>n;
for(int i=0;i<n;i++)
{
cin>>a[i];
}
sort(a,a+n,cmp);
for(int i=0;i<n;i++)
{
if(!i)cout<<a[i];
else
{
cout<<" "<<a[i];
}
}
cout<<endl;
return 0;
}


#include <iostream>
#include <bits/stdc++.h>
using namespace std;

int main()
{
long long int n,a[110],book[110];
cin>>n;
memset(book,0,sizeof(book));
for(int i=0;i<n;i++)
{
cin>>a[i];
}
long long int d,f;
for(int i=0;i<n;i++)
{
int f=0;
for(int j=0;j<n;j++)
{
if(j==i)continue;
if(a[j]*2==a[i])
{
f=1;
break;
}
if(a[j]%3==0)
{
if(a[j]/3==a[i])
{
f=1;
break;
}
}
}
if(f==0)
{
d=i;
break;
}
}
cout<<a[d];
book[d]=1;
for(int i=1;i<n;i++)
{
for(int j=0;j<n;j++)
{
if(book[j])continue;
if(a[d]*2==a[j]||(a[d]%3==0&&a[d]/3==a[j]))
{
book[j]=1;
d=j;
cout<<" "<<a[j];
break;
}
}
}
cout<<endl;
return 0;
}


#include<bits/stdc++.h>
using namespace std;
long long int a[105],vis[105],f[105],flag=0,top,n;
int j(long long int x,long long int y)
{
if(x*2==y)return 1;
else if(x%3==0&&x/3==y)return 1;
else return 0;
}
void dfs(int x)
{
if(top==n-1&&!flag)
{
flag=1;
for(int i=0;i<=n-1;i++)
{
if(i==n-1)cout<<f[i]<<endl;
else cout<<f[i]<<" ";
}
return;
}
for(int i=1;i<=n;i++)
{
if(!vis[i]&&j(a[x],a[i])==1)
{
top++;
f[top]=a[i];
vis[i]=1;
dfs(i);
top--;
vis[i]=0;
}
}
}
int main()
{
cin>>n;
for(int i=1;i<=n;i++)
{
cin>>a[i];
}
for(int i=1;i<=n;i++)
{
memset(vis,0,sizeof(vis));
vis[i]=1;
top=-1;
top++;
f[top]=a[i];
dfs(i);
if(flag)break;
}
return 0;
}