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 CPP):

Solution:
#include <bits/stdc++.h>
int check[200010];
std::vector<int> V[200010];
std::queue<int> Q;
void func(int k) {
  Q.push(k);
  check[k] = 0;
  while (!Q.empty()) {
    int t = Q.front();
    Q.pop();
    for (int i = 0; i < V[t].size(); i++) {
      if (check[V[t][i]] == 1234567890) {
        check[V[t][i]] = check[t] + 1;
        Q.push(V[t][i]);
      }
    }
  }
}
int s, t;
int dist1[200010], dist2[200010];
void func2(int k, int p) {
  for (int i = 0; i < V[k].size(); i++) {
    if (V[k][i] == p) continue;
    func2(V[k][i], k);
  }
  if (check[k] == 0) {
    if (dist1[k] > dist2[k])
      printf("%d %d %d\n", s, k, k);
    else
      printf("%d %d %d\n", t, k, k);
  }
}
int prev[200010], height[200010];
void init(int k, int p, int h) {
  prev[k] = p;
  height[k] = h;
  for (int i = 0; i < V[k].size(); i++) {
    if (V[k][i] == p) continue;
    init(V[k][i], k, h + 1);
  }
}
int main() {
  int a;
  scanf("%d", &a);
  for (int i = 1; i < a; i++) {
    int b, c;
    scanf("%d%d", &b, &c);
    V[b].push_back(c);
    V[c].push_back(b);
  }
  int max;
  for (int i = 1; i <= a; i++) check[i] = 1234567890;
  func(1);
  max = -1;
  for (int i = 1; i <= a; i++) {
    if (check[i] > max) {
      max = check[i];
      s = i;
    }
  }
  for (int i = 1; i <= a; i++) check[i] = 1234567890;
  func(s);
  max = -1;
  for (int i = 1; i <= a; i++) {
    if (check[i] > max) {
      max = check[i];
      t = i;
    }
  }
  for (int i = 1; i <= a; i++) dist1[i] = check[i];
  for (int i = 1; i <= a; i++) check[i] = 1234567890;
  func(t);
  for (int i = 1; i <= a; i++) dist2[i] = check[i];
  for (int i = 1; i <= a; i++) check[i] = 0;
  init(t, 0, 1);
  int s2 = s, t2 = t;
  check[s2] = check[t2] = 1;
  while (s2 != t2) {
    if (height[s2] > height[t2])
      s2 = prev[s2], check[s2] = 1;
    else
      t2 = prev[t2], check[t2] = 1;
  }
  long long int ans = 0;
  int count = 0;
  for (int i = 1; i <= a; i++) {
    if (check[i] == 0) {
      int S = dist1[i] > dist2[i] ? dist1[i] : dist2[i];
      ans += S;
    } else
      count++;
  }
  ans += (long long int)count * (count - 1) / 2;
  printf("%lld\n", ans);
  func2(t, 0);
  int pivot = s;
  while (s != t) {
    printf("%d %d %d\n", s, t, s);
    s = prev[s];
  }
}