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>
using namespace std;
const int N = 200005;
const int inf = 1000 * 1000 * 1000;
const int mod = 1000 * 1000 * 1000 + 7;
int n;
vector<int> g[N];
int mx, gag, H;
int gag1, gag2;
bool used[N];
int parent[N];
void dfs(int v, int r, int p) {
  if (r > mx) {
    mx = r;
    gag = v;
  }
  for (int i = 0; i < (int)g[v].size(); i++) {
    int to = g[v][i];
    if (to == p) continue;
    parent[to] = v;
    dfs(to, r + 1, v);
  }
}
int dp[N][22];
int tin[N], tout[N], tm;
int deg[N];
vector<int> vertex[N];
void rec(int v, int r, int p) {
  if (used[v] == false) vertex[r].push_back(v);
  if (r > H) H = r;
  tin[v] = tm++;
  deg[v] = r;
  dp[v][0] = parent[v];
  for (int i = 1; i <= 20; i++) dp[v][i] = dp[dp[v][i - 1]][i - 1];
  for (int i = 0; i < (int)g[v].size(); i++) {
    int to = g[v][i];
    if (to == p) continue;
    parent[to] = v;
    rec(to, r + 1, v);
  }
  tout[v] = tm++;
}
bool check(int a, int b) { return (tin[a] <= tin[b] && tout[a] >= tout[b]); }
int lca(int a, int b) {
  if (check(a, b)) return a;
  if (check(b, a)) return b;
  for (int i = 20; i >= 0; i--) {
    if (check(dp[a][i], b) == false) {
      a = dp[a][i];
    }
  }
  return parent[a];
}
vector<int> answ[5];
long long sum = 0;
int dist(int a, int b) {
  if (a == b) return 0;
  int p = lca(a, b);
  return deg[a] + deg[b] - 2 * deg[p];
}
void upd(int v) {
  int d1 = dist(v, gag1);
  int d2 = dist(v, gag2);
  if (d1 > d2) {
    sum += 1ll * d1;
    answ[1].push_back(gag1);
  } else {
    sum += 1ll * d2;
    answ[1].push_back(gag2);
  }
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i < n; i++) {
    int a, b;
    scanf("%d%d", &a, &b);
    g[a].push_back(b);
    g[b].push_back(a);
  }
  dfs(1, 0, -1);
  mx = 0;
  gag1 = gag;
  dfs(gag, 0, -1);
  gag2 = gag;
  used[gag] = true;
  while (gag != gag1) {
    gag = parent[gag];
    used[gag] = true;
  }
  parent[gag1] = gag1;
  rec(gag1, 0, -1);
  for (int i = H; i >= 0; i--) {
    for (int j = 0; j < (int)vertex[i].size(); j++) {
      int v = vertex[i][j];
      answ[0].push_back(v);
      upd(v);
      answ[2].push_back(v);
      used[v] = true;
    }
  }
  gag = gag2;
  while (gag != gag1) {
    answ[0].push_back(gag);
    answ[1].push_back(gag1);
    answ[2].push_back(gag);
    sum += 1ll * mx;
    mx--;
    gag = parent[gag];
  }
  cout << sum << endl;
  for (int i = 0; i < n - 1; i++) {
    printf("%d %d %d\n", answ[0][i], answ[1][i], answ[2][i]);
  }
  return 0;
}