For this Question: You are given a tree rooted at 1 (root is at level 1). The entire tree can be created in the following fashion:-
<li> Nodes at odd level have 2 children. So node 1 has two children, nodes 2 and 3.
<li> Nodes at even level have 4 children. So node 2 has 4 children, nodes 4, 5, 6, and 7. Similarly node 3 has 4 children, nodes 8, 9, 10, and 11.
<li> This process goes on infinitely. Node 4 has 2 children, nodes 12 and 13, node 5 has 2 children, nodes 14 and 15,... , and so on.

Now you are given an integer N, you need to report the path from the root to the node.The first and the only line of input contains an integer N.

Constraints
1 <= N <= 10<sup>16</sup>Output the path from the root to the node N in the form of space separated integers.Sample Input
14

Sample Output
1 2 5 14

Explanation: The path to node 14  from root is 1 -> 2 -> 5 -> 14 (Explained in problem text)

Sample Input
999

Sample Output
1 2 6 16 44 125 353 999 
, I have written this Solution Code: import java.io.*;
import java.util.*;

public class Main {
    InputStream is;
    PrintWriter out;
    String INPUT = "";

    void solve(int TC) throws Exception {
    	ArrayList<Long> al = new ArrayList<>();
    	ArrayList<Long> al2 = new ArrayList<>();
    	long last = 1L, lastP = 1L;
    	al.add(1L);
    	al2.add(1L);
    	for(int i=0;i<40;i++) {
    		if(i%2==0) {
    			last *= 2L;
    			al.add(last);
    			al2.add(last + al2.get(al2.size() - 1));
    		}else{
    			last *= 4L;
    			al.add(last);
    			al2.add(last + al2.get(al2.size() - 1));
    		}
    	}


    	long n = nl();
    	ArrayList<Long> ans = new ArrayList<>();
    	ans.add(n);
    	long cur = n;
    	while(cur > 1) {
    		int pos = 0;
    		while(al2.get(pos) < cur) {
    			++pos;
    		}

    		if(pos == 0) {
    			ans.add(1L);
    			break;
    		}
    		else if(pos == 1) {
    			if(cur>=8 && cur<=11) ans.add(3L);
    			else if(cur>=4 && cur<=7) ans.add(2L);
    			ans.add(1L);
    			break;
    		}
    		if(pos%2 == 1) {
    			cur = al2.get(pos - 2) + ((cur - al2.get(pos - 1) + 1) / 2);
    			ans.add(cur);
    		}else{
    			cur = al2.get(pos - 2) + (cur - al2.get(pos - 1) + 3) / 4;
    			ans.add(cur);
    		}

    	}
    	int pp = ans.size()-1;
    	while(pp >= 0) {
    		p(ans.get(pp) + " ");
    		--pp;
    	}
    	pn("");
    }

    boolean TestCases = false;
    public static void main(String[] args) throws Exception { new Main().run(); }

    void hold(boolean b)throws Exception{if(!b)throw new Exception("Hold right there, Sparky!");}
    static void dbg(Object... o){System.err.println(Arrays.deepToString(o));}

    void run() throws Exception {
        is = INPUT.isEmpty() ? System.in : new ByteArrayInputStream(INPUT.getBytes());
        out = new PrintWriter(System.out);
        long s = System.currentTimeMillis();
        int T = TestCases ? ni() : 1;
        for(int t=1;t<=T;t++) solve(t);
        out.flush();
        if(!INPUT.isEmpty())tr(System.currentTimeMillis()-s+"ms");
    }

    void p(Object o) { out.print(o); }
    void pn(Object o) { out.println(o); }
    void pni(Object o) { out.println(o);out.flush(); }

    int ni() {
        int num = 0, b;
        boolean minus = false;
        while((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'));
        if(b == '-') {
            minus = true;
            b = readByte();
        }
        while(true) {
            if(b >= '0' && b <= '9'){
                num = num * 10 + (b - '0');
            } else {
                return minus ? -num : num;
            }
            b = readByte();
        }
    }

    long nl() {
        long num = 0;
        int b;
        boolean minus = false;
        while((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'));
        if(b == '-') {
            minus = true;
            b = readByte();
        }
        while(true) {
            if(b >= '0' && b <= '9') {
                num = num * 10 + (b - '0');
            } else {
                return minus ? -num : num;
            }
            b = readByte();
        }
    }

    double nd() { return Double.parseDouble(ns()); }
    char nc() { return (char)skip(); }

    int BUF_SIZE = 1024 * 8;
    byte[] inbuf = new byte[BUF_SIZE];
    int lenbuf = 0, ptrbuf = 0;

    int readByte() {
        if(lenbuf == -1)throw new InputMismatchException();
        if(ptrbuf >= lenbuf){
            ptrbuf = 0;
            try { lenbuf = is.read(inbuf); } catch (IOException e) { throw new InputMismatchException(); }
            if(lenbuf <= 0)return -1;
        } return inbuf[ptrbuf++];
    }

    boolean isSpaceChar(int c) { return !(c >= 33 && c <= 126); }
    int skip() { int b; while((b = readByte()) != -1 && isSpaceChar(b)); return b; }

    String ns() {
        int b = skip();
        StringBuilder sb = new StringBuilder();
        while(!(isSpaceChar(b))) {
            sb.appendCodePoint(b); b = readByte();
        } return sb.toString();
    }

    char[] ns(int n) {
        char[] buf = new char[n];
        int b = skip(), p = 0;
        while(p < n && !(isSpaceChar(b))){
            buf[p++] = (char)b;
            b = readByte();
        } return n == p ? buf : Arrays.copyOf(buf, p);
    }

    void tr(Object... o) { if(INPUT.length() > 0)System.out.println(Arrays.deepToString(o)); }
}, In this Programming Language: Java, Now tell me if this Code is compilable or not?