Problem

A graph is given in which N vertices, each numbered from 1 to N, are connected by N-1 undirected edges. For each vertex, output the shortest number of steps to start from that vertex and visit all vertices.

However, one step is to follow one side from one vertex and move to another vertex.

Constraints

* 2 ≤ N ≤ 105
* 1 ≤ ui, vi ≤ N (1 ≤ i ≤ N-1)
* ui ≠ vi
* The graph given is concatenated

Input

The input is given in the following format.


N
u1 v1
..
..
..
uN−1 vN−1


The first line is given one integer N.
In the following N-1 line, the integers ui and vi representing the vertex numbers at both ends of the i-th side are given on the i-th line, separated by blanks.

Output

Output the shortest number of steps to visit all vertices starting from vertex i on the i-th line from vertex 1 to vertex N.

Examples

Input

2
1 2


Output

1
1


Input

6
1 2
1 3
3 4
3 5
5 6


Output

7
6
8
7
7
6
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define F first
#define S second
#define pii pair<int, int>
#define eb emplace_back
#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep3(i, l, n) for (int i = l; i < (n); ++i)
#define sz(v) (int)v.size()
const int inf = 1e9 + 7;
const ll INF = 1e18;
#define abs(x) (x >= 0 ? x : -(x))
#define lb(v, x) (int)(lower_bound(all(v), x) - v.begin())
#define ub(v, x) (int)(upper_bound(all(v), x) - v.begin())
template<typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { if (a > b) { a = b; return 1; } return 0; }
template<typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { if (a < b) { a = b; return 1; } return 0; }
template<typename T> T gcd(T a, T b) { if (b == 0) return a; return gcd(b, a % b); }
template<typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; }
template<typename T> T pow(T a, int b) { return b ? pow(a * a, b / 2) * (b % 2 ? a : 1) : 1; }
const int mod = 1000000007;
ll modpow(ll a, int b) { return b ? modpow(a * a % mod, b / 2) * (b % 2 ? a : 1) % mod : 1; }
template<class T> ostream& operator<<(ostream& os, const vector<T>& vec) { for (auto &vi: vec) os << vi << " "; return os; }
template<class T, class U> ostream& operator<<(ostream& os, const pair<T, U>& p) { os << p.F << " " << p.S; return os; }
template<class T> inline void add(T &a, int b) { a += b; if (a >= mod) a -= mod; }



void solve();

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    int T;
    // cin >> T;
    T = 1;

    while (T--) {
        solve();
    }
}


// https://ei1333.hateblo.jp/entry/2017/04/10/224413
struct edge { int to, cost; };

const int maxn = 100005;
vector<edge> G[maxn];
ll dist[maxn];
// i から i の (決めた頂点を根とする) 部分木内で一番遠い頂点までの距離
// 根を除く葉の dist は 0
void dfs(int v, int p) {
  for (edge& e : G[v]) {
    if (e.to == p) continue;
    dfs(e.to, v);
    // dfs から上がってきたタイミングで
    chmax(dist[v], dist[e.to] + e.cost);
  }
}

vector<int> ans(maxn);

// v を根とする答え
// Dpar : v の親方向の, v から一番遠い頂点と v の距離
void dfs2(int v, int Dpar, int p) {
  vector<pii> d_child;
  d_child.eb(0, -1); // 下で最大2つを取るが, 2つないとき用

  for (edge& e : G[v]) {
    // 親との距離と, 親方向の部分木で一番遠い頂点との距離の和
    if (e.to == p) d_child.eb(Dpar + e.cost, e.to);
    // 部分木の, ある頂点 j への距離と, j と j の部分木内での一番遠い頂点との距離の和
    else d_child.eb(e.cost + dist[e.to], e.to);
  }
  sort(d_child.rbegin(), d_child.rend());
  // sort 後, 最大 2 つ
  ans[v] = d_child[0].F ;

  // 同じ部分木内で木の直径が実現されることがある
  for (edge& e : G[v]) {
    if (e.to == p) continue;
    // v と一番遠い方向 f に行かない
    // 2 番手の方に行けば, f の距離を d_p にもつ
    dfs2(e.to, d_child[d_child[0].S == e.to].F, v);
  }
}

void solve() {
  int n;
  cin >> n;
  rep(i, n - 1) {
    int a, b;
    cin >> a >> b;
    a--; b--; // debuged
    G[a].eb(edge{b, 1});
    G[b].eb(edge{a, 1});
  }
  dfs(0, -1);
  dfs2(0, 0, -1);
  // 各辺 2 回通るが, 一番長いのだけ 1 回
  rep(i, n) cout << (n - 1) * 2 - ans[i] << endl;
}

