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
/*
　　　∫ ∫ ∫
　　　ノヽ
　　（＿　 ）
　（＿　　　 ）
（＿＿＿＿＿＿ ）
　ヽ(´･ω･)ﾉ　
　　 |　 /
　　 UU
*/
#pragma region macro
#include <bits/stdc++.h>
typedef long long int64;
using namespace std;
using P = pair<int64, int64>;
typedef vector<int> vi;
const int MOD = (int)1e9 + 7;
const int64 INF = 1LL << 62;
const int inf = 1<<30;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
#define REP(i, n) for (int i = 0; i < (n); i++)
#define FOR(i,s,n) for (int i = s; i < (n); i++)
#define ALL(obj) (obj).begin(), (obj).end() //コンテナじゃないと使えない!!
#define debug(x) cerr << #x << ": " << x << "\n";
#define mp make_pair
#define bn '\n'
template <typename T>
ostream& operator<<(ostream& os, const vector<T> &V){
    int N = V.size();
    REP(i,N){
        os << V[i];
        if (i!=N-1) os << " ";
    }
    os << "\n";
    return os;
}
template <typename T,typename S>
ostream& operator<<(ostream& os, pair<T,S> const&P){
    os << "(";
    os << P.first;
    os << " , ";
    os << P.second;
    os << ")";
    return os;
}
template <typename T>
ostream& operator<<(ostream& os, set<T> &S){
    auto it=S.begin();
    while(it!=S.end()){
        os << *it;
        os << " ";
        it++;
    }
    os << "\n";
    return os;
}
template <typename T>
ostream& operator<<(ostream& os, deque<T> &q){
    for(auto it=q.begin();it<q.end();it++){
        os<<*it;
        os<<" ";
    }
     os<<endl;
    return os;
}
vector<pair<int,int>> dxdy = {mp(0,1),mp(1,0),mp(-1,0),mp(0,-1)};
#pragma endregion
//fixed<<setprecision(10)<<ans<<endl;

int N;
vector<vector<int>> edge;
vector<int> DP;
vector<int> ans;
int dfs(int v, int pre){
    DP[v] = 0;
    for(auto to:edge[v]){
        if(to==pre) continue;
        chmax(DP[v], dfs(to,v) + 1);
    }
    return DP[v];
}
const int init_val = 0;
void dfs_with_rerooting(int v, int pre, int pre_val){
    //答えを得る
    for(auto to:edge[v]){
        if(to==pre){
            chmax(ans[v], pre_val + 1);
        }else{
            chmax(ans[v], DP[to] + 1);
        }
    }
    //左右から累積和
    int to;
    vector<int> left(edge[v].size(),init_val), right(edge[v].size(),init_val); 
    for(int i=0; i<edge[v].size(); i++){
        int j = edge[v].size() - i - 1;
        if(i) {
            left[i]  = left[i-1];
            right[j] = right[j+1];
        }
        to = edge[v][i];
        if(to == pre) {
            chmax(left[i], pre_val+1);
        }else{
            chmax(left[i], DP[to]+1);
        }
        to = edge[v][j];
        if(to == pre) {
            chmax(right[j], pre_val+1);
        }else{
            chmax(right[j], DP[to]+1);
        }
    }
    
    //根をくるくるする
    for(int i=0; i<edge[v].size(); i++){
        int to = edge[v][i];
        if(to!=pre){
            int val = init_val;
            if(i){
                chmax(val, left[i-1]);
            }
            if(i!=edge[v].size()-1){
                chmax(val, right[i+1]);
            }
            dfs_with_rerooting(to, v, val);
        }
    }
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> N;
    DP.assign(N,0);
    ans.assign(N,0);
    edge.assign(N,vector<int>());
    REP(i,N-1){
        int a,b;
        cin >> a >> b;

        edge[--a].emplace_back(--b);
        edge[b].emplace_back(a);
    }

    //一番遠い点へのパスに含まれる点は1度だけ通る
    //他の辺は2度通る
    

    dfs(0,-1);
    dfs_with_rerooting(0,-1,0);
    for(auto a:ans){
        cout << 2*(N-1)-a << bn;        
    }
}
