You are given a tree (an undirected connected acyclic graph) consisting of n vertices. You are playing a game on this tree.

Initially all vertices are white. On the first turn of the game you choose one vertex and paint it black. Then on each turn you choose a white vertex adjacent (connected by an edge) to any black vertex and paint it black.

Each time when you choose a vertex (even during the first turn), you gain the number of points equal to the size of the connected component consisting only of white vertices that contains the chosen vertex. The game ends when all vertices are painted black.

Let's see the following example:

<image>

Vertices 1 and 4 are painted black already. If you choose the vertex 2, you will gain 4 points for the connected component consisting of vertices 2, 3, 5 and 6. If you choose the vertex 9, you will gain 3 points for the connected component consisting of vertices 7, 8 and 9.

Your task is to maximize the number of points you gain.

Input

The first line contains an integer n — the number of vertices in the tree (2 ≤ n ≤ 2 ⋅ 10^5).

Each of the next n - 1 lines describes an edge of the tree. Edge i is denoted by two integers u_i and v_i, the indices of vertices it connects (1 ≤ u_i, v_i ≤ n, u_i ≠ v_i).

It is guaranteed that the given edges form a tree.

Output

Print one integer — the maximum number of points you gain if you will play optimally.

Examples

Input


9
1 2
2 3
2 5
2 6
1 4
4 9
9 7
9 8


Output


36


Input


5
1 2
1 3
2 4
2 5


Output


14

Note

The first example tree is shown in the problem statement.
import java.io.*;
import java.util.*;
 
public class TreePainting {  
    static int n, e;
    static long ans;
    static long maxDist;
    static ArrayList<Integer>[] arr;  
    static long[] subtreeSize, dp;
    public static void main(String[] args) throws IOException{
        FastIO file = new FastIO();
        //BufferedReader file = new BufferedReader(new FileReader("file.in"));
        n = file.nextInt();
        arr = new ArrayList[n];
        for (int i=0; i<n; i++){
            arr[i] = new ArrayList<>();
        }
        for (int i=0; i<n-1; i++){
            int s = file.nextInt()-1;
            int e = file.nextInt()-1;
            arr[s].add(e);
            arr[e].add(s);
        }
        
        // Calculate subtree size
        subtreeSize = new long[n];
        calcsize(0, -1);

        // Calculate answer for the current root (0)
        dp = new long[n];
        calcans(0, -1);

        // Re-root to all other nodes
        ans = 0;
        reroot(0, -1);

        //System.out.println(ep1 + " " + ep2);
        //System.out.println(Math.max(solve(ep1, -1, ep1size), solve(ep2, -1, ep2size)));
        System.out.println(ans);
    }
    public static void reroot(int curr, int parent){
        ans = Math.max(ans, dp[curr]); // Curr is always the root
        // Returns the node with the longest distance from curr
        for (int i : arr[curr]){
            if (i != parent){
                // Re-rooting changes
                dp[curr] -= dp[i];
                dp[curr] -= subtreeSize[i];
                subtreeSize[curr] -= subtreeSize[i];
                dp[i] += dp[curr];
                dp[i] += subtreeSize[curr];
                subtreeSize[i] += subtreeSize[curr];
                // Ready to recurse with i being the root
                reroot(i, curr);

                // Revert the changes
                dp[i] -= dp[curr];
                dp[i] -= subtreeSize[curr];
                subtreeSize[i] -= subtreeSize[curr];
                dp[curr] += dp[i];
                dp[curr] += subtreeSize[i];
                subtreeSize[curr] += subtreeSize[i];
            }   
        }
    }
    public static void calcsize(int curr, int parent){
        subtreeSize[curr] = 1;
        // Returns the node with the longest distance from curr
        for (int i : arr[curr]){
            if (i != parent){
                calcsize(i, curr);
                subtreeSize[curr] += subtreeSize[i];
            }   
        }
    }

    public static void calcans(int curr, int parent){
        // Returns the node with the longest distance from curr
        dp[curr] = subtreeSize[curr];
        for (int i : arr[curr]){
            if (i != parent){
                calcans(i, curr);
                dp[curr] += dp[i];
            }   
        }
    }
    static class FastIO extends PrintWriter {
        private InputStream stream;
        private byte[] buf = new byte[1<<16];
        private int curChar, numChars;
    
        // standard input
        public FastIO() { this(System.in,System.out); }
        public FastIO(InputStream i, OutputStream o) {
            super(o);
            stream = i;
        }
        // file input
        public FastIO(String i, String o) throws IOException {
            super(new FileWriter(o));
            stream = new FileInputStream(i);
        }
    
        // throws InputMismatchException() if previously detected end of file
        private int nextByte() {
            if (numChars == -1) throw new InputMismatchException();
            if (curChar >= numChars) {
                curChar = 0;
                try {
                    numChars = stream.read(buf);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
                if (numChars == -1) return -1; // end of file
            }
            return buf[curChar++];
        }
    
        // to read in entire lines, replace c <= ' '
        // with a function that checks whether c is a line break
        public String next() {
            int c; do { c = nextByte(); } while (c <= ' ');
            StringBuilder res = new StringBuilder();
            do { res.appendCodePoint(c); c = nextByte(); } while (c > ' ');
            return res.toString();
        }
        public int nextInt() { // nextLong() would be implemented similarly
            int c; do { c = nextByte(); } while (c <= ' ');
            int sgn = 1; if (c == '-') { sgn = -1; c = nextByte(); }
            int res = 0;
            do {
                if (c < '0' || c > '9')
                    throw new InputMismatchException();
                res = 10*res+c-'0';
                c = nextByte();
            } while (c > ' ');
            return res * sgn;
        }
        public double nextDouble() { return Double.parseDouble(next()); }
    }
}