[977D — Divide by three, multiply by two](http://codeforces.com/contest/977/problem/D)↵
--------------------------------------------------------------------------------------↵
1. We can see that all numbers in given sequence are distinct. since all numbers in sequence are of the form ${a_1}\dfrac{2^x}{3^y}$. Hence if $a_i = a_j$ then ${a_1}\dfrac{2^x}{3^y}$ = ${a_1}\dfrac{2^m}{3^n}$ $\implies$ $\dfrac{2^x}{3^y}$ = $\dfrac{2^m}{3^n}$ which is not possible because any power of 2 will be an even number and any power of 3 will be an odd number.↵
↵
2. if there exists $\dfrac{a_i}{3}$ in sequence then $2*a_i$ can not be in sequence and vice versa.↵
We can prove it using contradiction. Suppose there is a number $a_i$ such that both $\dfrac{a_i}{3}$ and $2*a_i$ exists in sequence. by little bit of tricks this $\implies$ ${3*a_1}\dfrac{2^x}{3^y}$ = ${a_1}\dfrac{2*2^m}{3^n}$, this again is not possible by same argument as above, we just have to change the order of exponents.↵
↵
3. Hence for each $a_i$ in sequence we see if $\dfrac{a_i}{3}$ or $2*a_i$ is present(remember that only one of them can be present). Now if there is any $a_i$ such that both $\dfrac{a_i}{3}$ and $2*a_i$ is not in sequence then this shoudld be $a_n$. if there is any such $a_i$ that for all $0\leq$ $j\leqn:$ $\dfrac{a_j}{3}$$\neq$ $a_i$ AND $2*a_i$ $\neq$ $a_i$, then this is $a_1$.↵
↵
4. Once you have got $a_1$, you keep on producing sequence just by doing binary search for $\dfrac{a_i}{3}$ and $2*a_i$ (remember only one of them is present so once you find it you print it).
--------------------------------------------------------------------------------------↵
1. We can see that all numbers in given sequence are distinct. since all numbers in sequence are of the form ${a_1}\dfrac{2^x}{3^y}$. Hence if $a_i = a_j$ then ${a_1}\dfrac{2^x}{3^y}$ = ${a_1}\dfrac{2^m}{3^n}$ $\implies$ $\dfrac{2^x}{3^y}$ = $\dfrac{2^m}{3^n}$ which is not possible because any power of 2 will be an even number and any power of 3 will be an odd number.↵
↵
2. if there exists $\dfrac{a_i}{3}$ in sequence then $2*a_i$ can not be in sequence and vice versa.↵
We can prove it using contradiction. Suppose there is a number $a_i$ such that both $\dfrac{a_i}{3}$ and $2*a_i$ exists in sequence. by little bit of tricks this $\implies$ ${3*a_1}\dfrac{2^x}{3^y}$ = ${a_1}\dfrac{2*2^m}{3^n}$, this again is not possible by same argument as above, we just have to change the order of exponents.↵
↵
3. Hence for each $a_i$ in sequence we see if $\dfrac{a_i}{3}$ or $2*a_i$ is present(remember that only one of them can be present). Now if there is any $a_i$ such that both $\dfrac{a_i}{3}$ and $2*a_i$ is not in sequence then this shou
↵
4. Once you have got $a_1$, you keep on producing sequence just by doing binary search for $\dfrac{a_i}{3}$ and $2*a_i$ (remember only one of them is present so once you find it you print it).