Problem: You are given an unweighted tree with n vertices. Then n - 1 following operations are applied to the tree. A single operation consists of the following steps: 

  1. choose two leaves; 
  2. add the length of the simple path between them to the answer; 
  3. remove one of the chosen leaves from the tree. 



Initial answer (before applying operations) is 0. Obviously after n - 1 such operations the tree will consist of a single vertex. 

Calculate the maximal possible answer you can achieve, and construct a sequence of operations that allows you to achieve this answer!

Input

The first line contains one integer number n (2 ≤ n ≤ 2·105) — the number of vertices in the tree. 

Next n - 1 lines describe the edges of the tree in form ai, bi (1 ≤ ai, bi ≤ n, ai ≠ bi). It is guaranteed that given graph is a tree.

Output

In the first line print one integer number — maximal possible answer. 

In the next n - 1 lines print the operations in order of their applying in format ai, bi, ci, where ai, bi — pair of the leaves that are chosen in the current operation (1 ≤ ai, bi ≤ n), ci (1 ≤ ci ≤ n, ci = ai or ci = bi) — choosen leaf that is removed from the tree in the current operation. 

See the examples for better understanding.

Examples

Input

3
1 2
1 3


Output

3
2 3 3
2 1 1


Input

5
1 2
1 3
2 4
2 5


Output

9
3 5 5
4 3 3
4 1 1
4 2 2

Solution (in JAVA):

Solution:
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.StringTokenizer;
import java.util.TreeSet;

public class Main {

	final static int mod = 1_000_000_007;

	public static void main(String[] args) throws Exception {

		STDIN scan = new STDIN();
		StringBuilder sb = new StringBuilder();
		
		int n = scan.nextInt();
		adj = new TreeSet[n];
		for(int i = 0; i < n; i++) adj[i] = new TreeSet<>();
		distA = new int[n]; distB = new int[n]; path = new boolean[n];
		for(int i = 1; i < n; i++) {
			int u = scan.nextInt()-1, v = scan.nextInt()-1;
			adj[u].add(v); adj[v].add(u);
		}
		a = farthest(new int[n], 1);
		b = farthest(distA, a);
		find(distB, b, -1);
		findPath(a, -1, b);
		TreeSet<Integer> t = new TreeSet<>(new Comp());
		for(int i = 0; i < n; i++)
			if(!path[i]) t.add(i);
		while(!t.isEmpty()) {
			int curr = t.pollFirst();
			if(distA[curr] > distB[curr]) {
				sb.append((curr+1) + " " + (a+1) + " " + (curr+1) + "\n");
				ans += distA[curr];
			}
			else {
				sb.append((curr+1) + " " + (b+1) + " " + (curr+1) + "\n");
				ans += distB[curr];
			}
			int next = adj[curr].pollFirst();
			t.remove(next);
			adj[next].remove(curr);
			if(!path[next]) t.add(next);
		}
		while(a != b) {
			sb.append((a+1) + " " + (b+1) + " " + (a+1) + "\n");
			ans += distB[a];
			int next = adj[a].pollFirst();
			adj[next].remove(a);
			a = next;
		}
		System.out.println(ans);
		System.out.println(sb);
	}
	
	static int a, b;
	static TreeSet<Integer> adj[];
	static int[] distA, distB;
	static boolean[] path;
	static long ans = 0;
	
	static class Comp implements Comparator<Integer>{
		@Override
		public int compare(Integer first, Integer second) {
			if(adj[first].size() == adj[second].size()) return first - second;
			return adj[first].size() - adj[second].size();
		}
	}
	
	static boolean findPath(int curr, int prev, int target) {
		if(curr == target) return path[curr] = true;
		for(int next : adj[curr])
			if(next != prev)
				path[curr] = path[curr] || findPath(next, curr, target);
		return path[curr];
	}
	
	static int farthest(int[] dist, int curr) {
		find(dist, curr, -1);
		int max = Integer.MIN_VALUE, ans = 0;
		for(int i = 0; i < dist.length; i++) {
			if(dist[i] > max) {
				max = dist[i];
				ans = i;
			}
		}
		return ans;
	}
		
	static void find(int[] dist, int curr, int prev) {
		if(prev == -1) dist[curr] = 0;
		else dist[curr] = dist[prev]+1;
		for(int next : adj[curr])
			if(next != prev)
				find(dist, next, curr);
	}
	
	static class STDIN {
		BufferedReader br;
		StringTokenizer st;

		public STDIN() {
			br = new BufferedReader(new InputStreamReader(System.in));
			st = null;
		}

		boolean hasNext() throws Exception {
			if (!st.hasMoreTokens())
				st = new StringTokenizer(br.readLine());
			return st.hasMoreTokens();
		}

		int nextInt() throws Exception {
			return Integer.parseInt(next());
		}

		long nextLong() throws Exception {
			return Long.parseLong(next());
		}

		double nextDouble() throws Exception {
			return Double.parseDouble(next());
		}

		String next() throws Exception {
			while (st == null || !st.hasMoreTokens())
				st = new StringTokenizer(br.readLine());
			return st.nextToken();
		}

		String nextLine() throws Exception {
			return br.readLine();
		}
	}
}