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 Sum {
  pair<int, int> operator()(pair<int, int> a, pair<int, int> b) {
    return pair<int, int>(a.first + b.first, b.second);
  }
};
struct Max {
  pair<int, int> operator()(pair<int, int> a, pair<int, int> b) {
    if (a.first > b.first) {
      return a;
    } else if (a.first < b.first) {
      return b;
    } else if (a.second < b.second) {
      return a;
    } else {
      return b;
    }
  }
};
pair<int, int> def;
Max op;
Sum sub;
struct SegTree {
  int s;
  struct node {
    node(pair<int, int> v) : value(v) {}
    pair<int, int> value;
    int left = -1;
    int right = -1;
  };
  vector<node> tree;
  SegTree(int size, pair<int, int> d) {
    def = d;
    tree.push_back(node(def));
    s = size;
  }
  void add(int pos, pair<int, int> value) { add(pos, value, 0, s, 0); }
  void add(int pos, pair<int, int> value, int low, int hi, int i) {
    if (low + 1 == hi) {
      tree[i].value = sub(tree[i].value, value);
    } else if (low + 1 < hi) {
      int mid = (low + hi) / 2;
      int left = tree[i].left;
      int right = tree[i].right;
      if (pos < mid) {
        if (tree[i].left == -1) {
          left = tree[i].left = tree.size();
          tree.push_back(node(def));
        }
        add(pos, value, low, mid, tree[i].left);
        if (right != -1) {
          tree[i].value = op(tree[left].value, tree[right].value);
        } else {
          tree[i].value = tree[left].value;
        }
      } else {
        if (tree[i].right == -1) {
          right = tree[i].right = tree.size();
          tree.push_back(node(def));
        }
        add(pos, value, mid, hi, tree[i].right);
        if (left != -1) {
          tree[i].value = op(tree[left].value, tree[right].value);
        } else {
          tree[i].value = tree[right].value;
        }
      }
    }
  }
  pair<int, int> get(int a, int b) { return get(a, b, 0, s, 0); }
  pair<int, int> get(int a, int b, int low, int hi, int i) {
    if (i == -1 || hi <= a || b <= low || hi <= low) {
      return def;
    }
    if (a <= low && hi <= b) {
      return tree[i].value;
    }
    int mid = (low + hi) / 2;
    return op(get(a, b, low, mid, tree[i].left),
              get(a, b, mid, hi, tree[i].right));
  }
};
void merge(SegTree& a, SegTree& b, int low, int hi, int i) {
  if (i == -1) {
    return;
  }
  if (low + 1 == hi) {
    a.add(low, b.tree[i].value);
  } else {
    int mid = (low + hi) / 2;
    merge(a, b, low, mid, b.tree[i].left);
    merge(a, b, mid, hi, b.tree[i].right);
  }
}
void merge(SegTree& a, SegTree& b) {
  if (a.tree.size() < b.tree.size()) {
    a.tree.swap(b.tree);
  }
  return merge(a, b, 0, b.s, 0);
}
const int L = 1e6 + 1;
vector<int> edges[L];
int ret[L];
void dfs(SegTree& a, int r, int p, int d) {
  for (auto e : edges[r]) {
    if (e == p) continue;
    SegTree b(L, pair<int, int>(0, 0));
    dfs(b, e, r, d + 1);
    merge(a, b);
  }
  a.add(d, pair<int, int>(1, d));
  ret[r] = a.get(d, L).second - d;
}
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 1; i < n; i++) {
    int x, y;
    scanf("%d%d", &x, &y);
    edges[x].push_back(y);
    edges[y].push_back(x);
  }
  SegTree t(L, pair<int, int>(0, 0));
  dfs(t, 1, 0, 0);
  for (int i = 1; i <= n; i++) {
    printf("%d\n", ret[i]);
  }
  return 0;
}
