You are given a rooted undirected tree consisting of n vertices. Vertex 1 is the root.

Let's denote a depth array of vertex x as an infinite sequence [d_{x, 0}, d_{x, 1}, d_{x, 2}, ...], where d_{x, i} is the number of vertices y such that both conditions hold:

  * x is an ancestor of y; 
  * the simple path from x to y traverses exactly i edges. 



The dominant index of a depth array of vertex x (or, shortly, the dominant index of vertex x) is an index j such that:

  * for every k < j, d_{x, k} < d_{x, j}; 
  * for every k > j, d_{x, k} ≤ d_{x, j}. 



For every vertex in the tree calculate its dominant index.

Input

The first line contains one integer n (1 ≤ n ≤ 10^6) — the number of vertices in a tree.

Then n - 1 lines follow, each containing two integers x and y (1 ≤ x, y ≤ n, x ≠ y). This line denotes an edge of the tree.

It is guaranteed that these edges form a tree.

Output

Output n numbers. i-th number should be equal to the dominant index of vertex i.

Examples

Input

4
1 2
2 3
3 4


Output

0
0
0
0


Input

4
1 2
1 3
1 4


Output

1
0
0
0


Input

4
1 2
2 3
2 4


Output

2
1
0
0
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
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 kessido
 */
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);
        FDominantIndices solver = new FDominantIndices();
        solver.solve(1, in, out);
        out.close();
    }

    static class FDominantIndices {
        int[][] g;

        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int n = in.NextInt();
            g = GraphExtension.parseGraph_n_m_and_m_lines_of_u_v_noSelfLoops(n, n - 1, in, false, false);
            int[] par = new int[n];
            int[] queue = new int[n];
            int qLength = 1;
            for (int i = 0; i < n; i++) {
                int cur = queue[i];
                int par1 = par[i];
                for (int j : g[cur]) {
                    if (j == par1) continue;
                    queue[qLength] = j;
                    par[qLength++] = cur;
                }
            }
            int[] ans = new int[n];
            Result[] res = new Result[n];
            for (int i = n - 1; i >= 0; i--) {
                int cur = queue[i];
                int par1 = par[i];
                for (int j : g[cur]) {
                    if (j == par1) continue;
                    if (res[cur] == null) res[cur] = res[j];
                    else res[cur].add(res[j]);
                    res[j] = null;
                }
                if (res[cur] == null) res[cur] = new Result();
                res[cur].add(1);
                ans[cur] = res[cur].length - res[cur].bestValue - 1;
            }
            res = null;
            queue = null;
            par = null;
            for (int i = 0; i < n; i++) {
                out.println(ans[i]);
            }
        }

        class Result {
            int[] values = new int[4];
            int length = 0;
            int bestValue = 0;

            void add(int x) {
                if (values.length == length) {
                    values = Arrays.copyOf(values, values.length * 2);
                }
                values[length++] = x;
                if (x >= values[bestValue]) bestValue = length - 1;
            }

            void add(Result res1) {
                int[] a = values;
                int[] b = res1.values;
                int aLength = length;
                int bLength = res1.length;
                int best = bestValue;
                if (aLength < bLength) {
                    a = res1.values;
                    b = values;
                    aLength = res1.length;
                    bLength = length;
                    best = res1.bestValue;
                }
                values = a;
                length = aLength;
                while (--aLength >= 0 && --bLength >= 0) {
                    a[aLength] += b[bLength];
                    if (a[aLength] >= a[best]) {
                        if (a[aLength] > a[best] || aLength > best)
                            best = aLength;
                    }
                }
                bestValue = best;
            }

        }

    }

    static class GraphExtension {
        public static int[][] parseGraph_n_e_array_of_of_u_v_noSelfLoops(final int n, final int[][] e, final boolean directed) {
            int[] edgesCount = new int[n];
            for (int[] i : e) {
                edgesCount[i[0]]++;
                if (!directed)
                    edgesCount[i[1]]++;
            }
            int[][] graph = new int[n][];
            for (int i = 0; i < n; i++) {
                graph[i] = new int[edgesCount[i]];
            }
            for (int[] i : e) {
                graph[i[0]][--edgesCount[i[0]]] = i[1];
                if (!directed)
                    graph[i[1]][--edgesCount[i[1]]] = i[0];
            }
            return graph;
        }

        public static int[][] parseGraph_n_m_and_m_lines_of_u_v_noSelfLoops(final int n, final int m, final InputReader in, final boolean zeroBasedIndex, final boolean directed) {
            int[][] e = in.NextIntMatrix(m, 2, zeroBasedIndex ? 0 : -1);
            return parseGraph_n_e_array_of_of_u_v_noSelfLoops(n, e, directed);
        }

    }

    static class InputReader {
        BufferedReader reader;
        StringTokenizer tokenizer;

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

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine(), " \t\n\r\f,");
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public int NextInt() {
            return Integer.parseInt(next());
        }

        public int[][] NextIntMatrix(int n, int m, int offset) {
            int[][] a = new int[n][m];
            for (int i = 0; i < n; i++) {
                for (int j = 0; j < m; j++) {
                    a[i][j] = NextInt() + offset;
                }
            }
            return a;
        }

    }
}

