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;
namespace io {
const int __SIZE = (1 << 21) + 1;
char ibuf[__SIZE], *iS, *iT, obuf[__SIZE], *oS = obuf, *oT = oS + __SIZE - 1,
                                           __c, qu[55];
int __f, qr, _eof;
inline void flush() { fwrite(obuf, 1, oS - obuf, stdout), oS = obuf; }
inline void gc(char &x) {
  x = (iS == iT ? (iT = (iS = ibuf) + fread(ibuf, 1, __SIZE, stdin),
                   (iS == iT ? EOF : *iS++))
                : *iS++);
}
inline void pc(char x) {
  *oS++ = x;
  if (oS == oT) flush();
}
inline void gstr(char *s) {
  for (__c = (iS == iT ? (iT = (iS = ibuf) + fread(ibuf, 1, __SIZE, stdin),
                         (iS == iT ? EOF : *iS++))
                       : *iS++);
       __c < 32 || __c > 126 || __c == ' ';)
    __c = (iS == iT ? (iT = (iS = ibuf) + fread(ibuf, 1, __SIZE, stdin),
                       (iS == iT ? EOF : *iS++))
                    : *iS++);
  for (; __c > 31 && __c < 127 && __c != ' ';
       ++s, __c = (iS == iT ? (iT = (iS = ibuf) + fread(ibuf, 1, __SIZE, stdin),
                              (iS == iT ? EOF : *iS++))
                            : *iS++))
    *s = __c;
  *s = 0;
}
inline int read() {
  int x;
  _eof = 0;
  for (__c = (iS == iT ? (iT = (iS = ibuf) + fread(ibuf, 1, __SIZE, stdin),
                         (iS == iT ? EOF : *iS++))
                       : *iS++);
       (__c < '0' || __c > '9') && !_eof;
       __c = (iS == iT ? (iT = (iS = ibuf) + fread(ibuf, 1, __SIZE, stdin),
                         (iS == iT ? EOF : *iS++))
                       : *iS++))
    _eof |= __c == EOF;
  for (x = 0; __c <= '9' && __c >= '0' && !_eof;
       __c = (iS == iT ? (iT = (iS = ibuf) + fread(ibuf, 1, __SIZE, stdin),
                         (iS == iT ? EOF : *iS++))
                       : *iS++))
    x = x * 10 + (__c & 15), _eof |= __c == EOF;
  return x;
}
inline void print(int x) {
  if (!x) pc('0');
  if (x < 0) pc('-'), x = -x;
  while (x) qu[++qr] = x % 10 + '0', x /= 10;
  while (qr) pc(qu[qr--]);
}
struct Flusher_ {
  ~Flusher_() { flush(); }
} io_flusher_;
}  // namespace io
using io::pc;
using io::print;
using io::read;
int n;
vector<int> e[1000006];
void add(int f, int t) { e[f].push_back(t), e[t].push_back(f); }
int fa[1000006], dep[1000006], h[1000006], sn[1000006];
void dfs(int u) {
  h[u] = 1, dep[u] = dep[fa[u]] + 1;
  for (int i = 0, v, en = e[u].size(); i < en; ++i)
    if ((v = e[u][i]) != fa[u]) {
      fa[v] = u, dfs(v), h[u] = max(h[u], h[v] + 1);
      h[v] == h[u] - 1 ? sn[u] = v : 0;
    }
}
int sum[1000006];
pair<int, int> res[1000006];
void update(int s, int u) {
  res[s] = max(res[s], (pair<int, int>){sum[u], n - (dep[u] - dep[s])});
}
void push(int s, int u, int v) {
  while (v) sum[u] += sum[v], update(s, u), u = sn[u], v = sn[v];
}
void work(int u) {
  if (!sn[u]) return res[u] = (pair<int, int>){sum[u] = 1, n}, void();
  work(sn[u]), res[u] = res[sn[u]], --res[u].second, ++sum[u], update(u, u);
  for (int i = 0, v, en = e[u].size(); i < en; ++i)
    if ((v = e[u][i]) != fa[u] && v != sn[u]) work(v), push(u, sn[u], v);
}
int main() {
  n = read();
  for (int i = 1; i < n; ++i) add(read(), read());
  dfs(1), work(1);
  for (int i = 1; i <= n; ++i) print(n - res[i].second), pc('\n');
  return 0;
}
