1 #include <iostream>
2 #include <cstring>
3 using namespace std;
4
5 void get_xxx(int x, int xxx[]);
6
7 int main()
8 {
9 int xxx[400005], a[505];
10 int n,i,check;
11 while(cin>>n && n>0) {
12 for(i=0; i<n; i++) cin>>a[i];
13 memset(xxx, 0, sizeof(xxx));
14 for(i=0; i<n; i++)
15 get_xxx(a[i],xxx);
16 check=1;
17 for(i=n-1; i>=0; i--)
18 if(xxx[a[i]] == 0) {
19 if(check==1) cout<<a[i];
20 else cout<<" "<<a[i];
21 check=0;
22 }
23 cout<<endl;
24 }
25 return 0;
26 }
27
28 void get_xxx(int x, int xxx[]) {
29 if(x==1) return ;
30 if(x%2==1)
31 x = (3*x+1)/2 ;
32 else
33 x/=2;
34 xxx[x]=1;
35 get_xxx(x, xxx);
36 }