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 INF = 0x3f3f3f3f;
const long long INFF = 0x3f3f3f3f3f3f3f3fll;
const long long M = 1e9 + 7;
const long long maxn = 1e6 + 7;
const double eps = 0.00000001;
long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }
template <typename T>
inline T abs(T a) {
  return a > 0 ? a : -a;
}
template <typename T>
inline T powMM(T a, T b) {
  T ret = 1;
  for (; b; b >>= 1ll, a = 1ll * a * a % M)
    if (b & 1) ret = 1ll * ret * a % M;
  return ret;
}
int n, i, j, k;
vector<int> edge[maxn];
long long ans = 0;
int maxlen, node;
int f[maxn][20];
int dep[maxn];
void dfs(int x, int fa, int len) {
  f[x][0] = fa;
  int i;
  dep[x] = len;
  for (i = 1; i < 20; i++) f[x][i] = f[f[x][i - 1]][i - 1];
  if (len > maxlen) node = x, maxlen = len;
  for (int v : edge[x])
    if (v != fa) dfs(v, x, len + 1);
}
int lca(int x, int y) {
  int i;
  if (dep[x] < dep[y]) swap(x, y);
  for (i = 20 - 1; i >= 0; i--)
    if (dep[x] - dep[y] >= 1 << i) x = f[x][i];
  if (x == y) return x;
  for (i = 20 - 1; i >= 0; i--)
    if (f[x][i] != f[y][i]) x = f[x][i], y = f[y][i];
  return f[x][0];
}
int dis(int x, int y) { return dep[x] + dep[y] - 2 * dep[lca(x, y)]; }
queue<int> Q;
int d[maxn];
vector<pair<pair<int, int>, int> > ANS;
int main() {
  scanf("%d", &n);
  int u, v;
  for (i = 1; i <= n - 1; i++) {
    scanf("%d%d", &u, &v);
    edge[v].push_back(u);
    edge[u].push_back(v);
    d[u]++;
    d[v]++;
  }
  dfs(1, 0, 0);
  u = node;
  maxlen = 0;
  dfs(u, 0, 0);
  v = node;
  for (i = 1; i <= n; i++)
    if (d[i] == 1) Q.push(i);
  while (Q.size()) {
    int t = Q.front();
    Q.pop();
    if (t == u || t == v) continue;
    d[t] = -1;
    for (int x : edge[t]) {
      d[x]--;
      if (d[x] == 1) Q.push(x);
    }
    int disu = dis(u, t), disv = dis(v, t);
    if (disu < disv)
      ANS.push_back(make_pair(make_pair(v, t), t)), ans += disv;
    else
      ANS.push_back(make_pair(make_pair(u, t), t)), ans += disu;
  }
  Q.push(v);
  while (Q.size()) {
    int t = Q.front();
    Q.pop();
    for (int x : edge[t]) {
      d[x]--;
      if (d[x] == 1) Q.push(x);
    }
    ANS.push_back(make_pair(make_pair(u, t), t)), ans += dis(u, t);
  }
  printf("%I64d\n", ans);
  for (auto now : ANS)
    printf("%d %d %d\n", now.first.first, now.first.second, now.second);
}