Breaking news from zombie neurology! It turns out that – contrary to previous beliefs – every zombie is born with a single brain, and only later it evolves into a complicated brain structure. In fact, whenever a zombie consumes a brain, a new brain appears in its nervous system and gets immediately connected to one of the already existing brains using a single brain connector. Researchers are now interested in monitoring the brain latency of a zombie. Your task is to write a program which, given a history of evolution of a zombie's nervous system, computes its brain latency at every stage.

Input

The first line of the input contains one number n – the number of brains in the final nervous system (2 ≤ n ≤ 200000). In the second line a history of zombie's nervous system evolution is given. For convenience, we number all the brains by 1, 2, ..., n in the same order as they appear in the nervous system (the zombie is born with a single brain, number 1, and subsequently brains 2, 3, ..., n are added). The second line contains n - 1 space-separated numbers p2, p3, ..., pn, meaning that after a new brain k is added to the system, it gets connected to a parent-brain <image>.

Output

Output n - 1 space-separated numbers – the brain latencies after the brain number k is added, for k = 2, 3, ..., n.

Example

Input

6
1
2
2
1
5


Output

1 2 2 3 4 
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author @VanHanhPham_skyvn97
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskC3 solver = new TaskC3();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskC3 {
        private static final int LOG = 18;
        int[][] par;
        int[] high;
        int n;

        public void solve(int testNumber, InputReader in, PrintWriter out) {
            n = in.nextInt();
            par = new int[n + 1][LOG + 1];
            high = new int[n + 1];
            high[0] = -1;
            int bestX = 1;
            int bestY = 1;
            for (int i = 2; i <= n; i++) {
                int par = in.nextInt();
                createNode(i, par);
                int oldX = bestX;
                int oldY = bestY;
                if (dis(oldX, i) > dis(bestX, bestY)) {
                    bestX = oldX;
                    bestY = i;
                }
                if (dis(oldY, i) > dis(bestX, bestY)) {
                    bestX = oldY;
                    bestY = i;
                }
                out.print(dis(bestX, bestY) + " ");
            }
            out.println();
        }

        private void createNode(int child, int node) {
            high[child] = high[node] + 1;
            par[child][0] = node;
            for (int j = 1; j <= LOG; j++)
                par[child][j] = par[par[child][j - 1]][j - 1];
        }

        private int dis(int u, int v) {
            return high[u] + high[v] - 2 * high[LCA(u, v)];
        }

        private int LCA(int u, int v) {
            if (high[u] < high[v]) return (LCA(v, u));
            for (int i = LOG; i >= 0; i--) {
                if (high[par[u][i]] >= high[v]) {
                    u = par[u][i];
                }
            }
            if (u == v) return (u);
            for (int i = LOG; i >= 0; i--) {
                if (par[u][i] != par[v][i]) {
                    u = par[u][i];
                    v = par[v][i];
                }
            }
            return par[u][0];
        }

    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String nextString() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(nextString());
        }

    }
}
