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.util.*;
import java.io.*; 
import java.text.DecimalFormat;

public class Main{
    final long mod = (int)998244353, IINF = (long)1e19;
    final int MAX = (int)2e5+1, MX = (int)1e7+1, INF = (int)1e9, root = 3;
    DecimalFormat df = new DecimalFormat("0.0000000000000");
    double eps = 1e-9, PI = 3.141592653589793238462643383279502884197169399375105820974944;
    static boolean multipleTC = false, memory = true;
    FastReader in;PrintWriter out;
    public static void main(String[] args) throws Exception{
        if(memory)new Thread(null, new Runnable() {public void run(){try{new Main().run();}catch(Exception e){e.printStackTrace();}}}, "1", 1 << 28).start();
        else new Main().run();
    }
    
    void run() throws Exception{
        in = new FastReader();
        out = new PrintWriter(System.out);
        for(int i = 1, T= (multipleTC)?ni():1; i<= T; i++)solve(i);
        out.flush();
        out.close();
    }
    
    void solve(int TC) throws Exception{
        int n = ni();
        int cnt[] = new int[n], edge[][] = new int[n-1][], g[][] = new int[n][];
        for(int i = 0; i< n-1; i++){
            edge[i] = new int[]{ni()-1, ni()-1};
            cnt[edge[i][0]]++;cnt[edge[i][1]]++;
        }
        for(int i = 0; i< n; i++)g[i]= new int[cnt[i]];
        for(int i = 0; i< n-1; i++){
            g[edge[i][0]][--cnt[edge[i][0]]] = edge[i][1];
            g[edge[i][1]][--cnt[edge[i][1]]] = edge[i][0];
        }
        int[] sz = new int[n], dep = new int[n],ans= new int[n];
        size(g,sz,dep,0,-1);
//        d = new int[n+1];
        d = new SegTree(n);
        big = new boolean[n];
        dfs(g,sz,dep,ans,0,-1, 0);
        for(int i:ans)pn(i);
    }
    SegTree d;
//    int[] d;
    int maxd = 0;
    boolean[] big;
    void size(int[][] g, int[] sz,int[] dep, int u, int p){
        sz[u] = 1;
        for(int v:g[u]){
            if(v==p)continue;
            dep[v] = dep[u]+1;
            maxd =  Math.max(maxd, dep[v]);
            size(g,sz,dep,v,u);
            sz[u]+=sz[v];
        }
    }
    
    void dfs(int[][] g, int[] sz,int[] dep, int[] ans, int u, int p, int keep){
        int bigC = -1;
        for(int v:g[u]){
            if(v==p)continue;
            if(bigC==-1 || sz[v]>sz[bigC])bigC = v;
        }
        for(int v:g[u])if(v!=p && v!=bigC)dfs(g,sz,dep,ans,v,u,0);
        if(bigC!=-1){
            dfs(g,sz,dep,ans,bigC,u,1);
            big[bigC] = true;
        }
        add(g,dep,u,p,1);
        ans[u] = maxd-dep[u]-d.query();
        if(bigC!=-1)big[bigC] = false;
        if(keep==0)add(g,dep,u,p,-1);
    }
    
    void add(int[][] g, int[] dep, int v, int p, int x){
        d.update(maxd-dep[v], x);
        for(int u: g[v])
            if(u != p && !big[u])
                add(g,dep,u, v, x);
    }
    
    class SegTree{
        int m = 1;
        int[] a;
        public SegTree(int n){
            while(m<n)m<<=1;
            a = new int[m<<1];
//            for(int i = 0; i< a.length; i++)a[i] = -1;
        }
        void update(int p, int x){
            p+=m;
            a[p]+=x;
            for(p>>=1;p>0;p>>=1)a[p] = Math.max(a[p<<1], a[p<<1|1]);
        }
        int query(){
            return query(0,m-1,1);
        }
        int query(int l, int r, int i){
            if(i>=m)return i-m;
            int mid = (l+r)>>1;
            if(a[i<<1|1]==a[1])return query(mid+1,r,i<<1|1);
            else return query(l,mid,i<<1);
        }
    }
    
    int[] sort(int[] a){
        if(a.length==1)return a;
        int mid = a.length/2;
        int[] b = sort(Arrays.copyOfRange(a,0,mid)), c = sort(Arrays.copyOfRange(a,mid,a.length));
        for(int i = 0, j = 0, k = 0; i< a.length; i++){
            if(j<b.length && k<c.length){
                if(b[j]<c[k])a[i] = b[j++];
                else a[i] = c[k++];
            }else if(j<b.length)a[i] = b[j++];
            else a[i] = c[k++];
        }
        return a;
    }

    long[] sort(long[] a){
        if(a.length==1)return a;
        int mid = a.length/2;
        long[] b = sort(Arrays.copyOfRange(a,0,mid)), c = sort(Arrays.copyOfRange(a,mid,a.length));
        for(int i = 0, j = 0, k = 0; i< a.length; i++){
            if(j<b.length && k<c.length){
                if(b[j]<c[k])a[i] = b[j++];
                else a[i] = c[k++];
            }else if(j<b.length)a[i] = b[j++];
            else a[i] = c[k++];
        }
        return a;
    }

    long gcd(long a, long b){return (b==0)?a:gcd(b,a%b);}
    int gcd(int a, int b){return (b==0)?a:gcd(b,a%b);}
    int bitcount(long n){return (n==0)?0:(1+bitcount(n&(n-1)));}
    void p(Object o){out.print(o);}
    void pn(Object o){out.println(o);}
    void pni(Object o){out.println(o);out.flush();}
    String n(){return in.next();}
    String nln(){return in.nextLine();}
    int ni(){return Integer.parseInt(in.next());}
    long nl(){return Long.parseLong(in.next());}
    double nd(){return Double.parseDouble(in.next());}

    class FastReader{
        BufferedReader br;
        StringTokenizer st;
        public FastReader(){
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        public FastReader(String s) throws Exception{
            br = new BufferedReader(new FileReader(s));
        }

        String next(){
            while (st == null || !st.hasMoreElements()){
                try{
                    st = new StringTokenizer(br.readLine());
                }catch (IOException  e){
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        String nextLine(){
            String str = "";
            try{    
                str = br.readLine();
            }catch (IOException e){
                e.printStackTrace();
            }   
            return str;
        }
    }
}   