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;
struct ins {
  int ans;
  ins() { ans = 1; }
  void read() {}
  void read1(char &s) {
    char c = getchar();
    for (; !isprint(c) || c == ' ' || c == '\n' || c == '\t'; c = getchar())
      ;
    s = c;
    if (c == EOF) ans = 0;
  }
  void read1(string &s) {
    s = "";
    char c = getchar();
    for (; !isprint(c) || c == ' ' || c == '\n' || c == '\t'; c = getchar())
      ;
    for (; isprint(c) && c != ' ' && c != '\n' && c != '\t'; c = getchar())
      s += c;
    if (c == EOF) ans = 0;
  }
  void read1(char *s) {
    char c = getchar();
    int tt = 0;
    for (; !isprint(c) || c == ' ' || c == '\n' || c == '\t'; c = getchar())
      ;
    for (; isprint(c) && c != ' ' && c != '\n' && c != '\t'; c = getchar())
      s[tt++] = c;
    s[tt] = '\0';
    if (c == EOF) ans = 0;
  }
  template <typename T>
  void read1(T &n) {
    T x = 0;
    int f = 1;
    char c = getchar();
    for (; !isdigit(c); c = getchar()) {
      if (c == '-') f = -1;
      if (c == EOF) {
        ans = 0;
        return;
      }
    }
    for (; isdigit(c); c = getchar()) x = x * 10 + c - 48;
    n = x * f;
    if (c == EOF) ans = 0;
    if (c != '.') return;
    T l = 0.1;
    while ((c = getchar()) <= '9' && c >= '0') x = x + (c & 15) * l, l *= 0.1;
    n = x * f;
    if (c == EOF) ans = 0;
  }
  void write() {}
  void write1(string s) {
    int n = s.size();
    for (int i = 0; i < n; i++) putchar(s[i]);
  }
  void write1(const char *s) {
    int n = strlen(s);
    for (int i = 0; i < n; i++) putchar(s[i]);
  }
  void write1(char *s) {
    int n = strlen(s);
    for (int i = 0; i < n; i++) putchar(s[i]);
  }
  void write1(char s) { putchar(s); }
  void write1(float s, int x = 6) {
    char y[10001];
    sprintf(y, "%%.%df", x);
    printf(y, s);
  }
  void write1(double s, int x = 6) {
    char y[10001];
    sprintf(y, "%%.%dlf", x);
    printf(y, s);
  }
  void write1(long double s, int x = 6) {
    char y[10001];
    sprintf(y, "%%.%dLf", x);
    printf(y, s);
  }
  template <typename T>
  void write1(T n) {
    if (n < 0) n = -n, putchar('-');
    if (n > 9) write1(n / 10);
    putchar('0' + n % 10);
  }
  friend ins operator>>(ins x, char *n);
  template <typename T>
  friend ins operator>>(ins x, T &n);
  template <typename T>
  friend ins operator<<(ins x, T n);
  operator bool() { return ans; }
};
ins operator>>(ins x, char *n) {
  if (!x.ans) return x;
  x.read1(n);
  return x;
}
template <typename T>
ins operator>>(ins x, T &n) {
  if (!x.ans) return x;
  x.read1(n);
  return x;
}
template <typename T>
ins operator<<(ins x, T n) {
  x.write1(n);
  return x;
}
ins yin;
ins yout;
const int maxn = 1e6 + 10;
int son[maxn], dep[maxn];
vector<int> e[maxn];
void pre(int u, int fa) {
  for (auto v : e[u]) {
    if (v == fa) continue;
    pre(v, u);
    if (dep[v] > dep[son[u]]) son[u] = v;
  }
  dep[u] = dep[son[u]] + 1;
}
int buf[maxn];
int *opt[maxn], *now = buf;
int ans[maxn];
void dfs(int u, int fa) {
  opt[u][0] = 1;
  if (son[u]) {
    opt[son[u]] = opt[u] + 1;
    dfs(son[u], u);
    ans[u] = ans[son[u]] + 1;
  }
  for (auto v : e[u]) {
    if (v == fa || v == son[u]) continue;
    opt[v] = now;
    now += dep[v];
    dfs(v, u);
    for (int i = 1; i <= dep[v]; i++) {
      opt[u][i] += opt[v][i - 1];
      if (opt[u][i] > opt[u][ans[u]] ||
          (opt[u][i] == opt[u][ans[u]] && i < ans[u]))
        ans[u] = i;
    }
  }
  if (opt[u][ans[u]] == 1) ans[u] = 0;
}
void add(int u, int v) {
  e[u].push_back(v);
  e[v].push_back(u);
}
int n;
int main() {
  yin >> n;
  for (int i = 1; i < n; i++) {
    int u, v;
    yin >> u >> v;
    add(u, v);
  }
  pre(1, 0);
  opt[1] = now;
  now += dep[1];
  dfs(1, 0);
  for (int i = 1; i <= n; i++) yout << ans[i] << '\n';
  return 0;
}
