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
#include <bits/stdc++.h>
using namespace std;
template <class T>
void rd(T &x) {
  x = 0;
  char c;
  while (c = getchar(), c < 48)
    ;
  do x = x * 10 + (c ^ 48);
  while (c = getchar(), c > 47);
}
template <class T>
void rec_pt(T x) {
  if (!x) return;
  rec_pt(x / 10);
  putchar(x % 10 ^ 48);
}
template <class T>
void pt(T x) {
  if (!x)
    putchar('0');
  else
    rec_pt(x);
}
template <class T>
inline void ptn(T x) {
  pt(x), putchar('\n');
}
template <class T>
inline void Max(T &a, T b) {
  if (b > a) a = b;
}
template <class T>
inline void Min(T &a, T b) {
  if (b < a) a = b;
}
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
const int N = (int)1e6 + 5;
int tot_edge, lst[N], par[N], dep[N], depth[N], deep_son[N], tp[N];
pair<int, int> edge[N << 1];
int ans[N], memo[N], *allc = memo, *f[N];
void add_edge(int u, int v) {
  edge[tot_edge] = pair<int, int>(v, lst[u]);
  lst[u] = tot_edge++;
}
inline void add_edges(int u, int v) { add_edge(u, v), add_edge(v, u); }
void dfs(int u) {
  for (int i = lst[u]; ~i; i = edge[i].second) {
    int v = edge[i].first;
    if (v == par[u]) continue;
    par[v] = u;
    dep[v] = dep[u] + 1;
    dfs(v);
    if (!deep_son[u] || depth[v] > depth[deep_son[u]]) deep_son[u] = v;
  }
  if (deep_son[u]) depth[u] = depth[deep_son[u]] + 1;
}
void allc_dfs(int u) {
  if (deep_son[u]) {
    tp[deep_son[u]] = tp[u];
    allc_dfs(deep_son[u]);
    for (int i = lst[u]; ~i; i = edge[i].second) {
      int v = edge[i].first;
      if (v == par[u] || v == deep_son[u]) continue;
      allc_dfs(tp[v] = v);
    }
  } else {
    int sz = dep[u] - dep[tp[u]] + 1;
    f[u] = allc += sz;
  }
}
void DP(int u) {
  if (!deep_son[u]) {
    f[u][0] = 1;
    return;
  }
  for (int i = lst[u]; ~i; i = edge[i].second) {
    int v = edge[i].first;
    if (v == par[u]) continue;
    DP(v);
  }
  f[u] = f[deep_son[u]] - 1;
  f[u][0] = 1;
  if (f[deep_son[u]][ans[deep_son[u]]] > 1) ans[u] = ans[deep_son[u]] + 1;
  for (int i = lst[u]; ~i; i = edge[i].second) {
    int v = edge[i].first;
    if (v == par[u] || v == deep_son[u]) continue;
    for (int j = (1), _t = (depth[v] + 2); j < _t; ++j) {
      f[u][j] += f[v][j - 1];
      if (f[u][j] > f[u][ans[u]])
        ans[u] = j;
      else if (f[u][j] == f[u][ans[u]])
        Min(ans[u], j);
    }
  }
}
int main() {
  int n;
  rd(n);
  memset(lst, -1, n + 1 << 2);
  for (int i = 1, u, v; i < n; ++i) {
    rd(u), rd(v);
    add_edges(u, v);
  }
  dfs(1);
  allc_dfs(tp[1] = 1);
  DP(1);
  for (int i = (1), _t = (n + 1); i < _t; ++i) ptn(ans[i]);
  return 0;
}
