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;
ostream& operator<<(ostream& os, vector<long long>& x) {
  for (long long i = 0; i < x.size(); i++) os << x[i] << ' ';
  return os;
}
ostream& operator<<(ostream& os, pair<long long, long long> x) {
  cout << x.first << ' ' << x.second << ' ';
  return os;
}
ostream& operator<<(ostream& os, vector<pair<long long, long long> >& x) {
  for (long long i = 0; i < x.size(); i++) os << x[i] << '\n';
  return os;
}
struct data {
  long long u, v, del;
  data(long long _u, long long _v, long long _del) : u(_u), v(_v), del(_del){};
};
ostream& operator<<(ostream& os, data x) {
  cout << x.u << ' ' << x.v << ' ' << x.del << '\n';
  return os;
}
ostream& operator<<(ostream& os, vector<data>& x) {
  for (long long i = 0; i < x.size(); i++) os << x[i];
  return os;
}
long long n;
vector<vector<long long> > a(200005);
pair<long long, long long> hLo[200005];
pair<long long, long long> hHi[200005];
long long depth[200005];
pair<long long, long long> dualRoot;
long long ans = 0;
vector<data> order;
bool mark[200005];
void pdfs(long long u, long long p) {
  hLo[u] = make_pair(0, u);
  hHi[u] = make_pair(0, u);
  for (auto v : a[u]) {
    if (v == p) continue;
    depth[v] = depth[u] + 1;
    pdfs(v, u);
    hLo[u] = max(hLo[u], make_pair(hLo[v].first + 1, hLo[v].second));
    hHi[u] = max(hHi[u], make_pair(hHi[v].first + 1, v));
  }
}
void dfs2(long long u, long long p, pair<long long, long long> upLen,
          long long downLen) {
  if (u == 1) {
    upLen = make_pair(0, 1);
    for (auto v : a[u]) {
      if (v == p || mark[v]) continue;
      upLen = max(upLen, make_pair(hLo[v].first + 1, hLo[v].second));
    }
    downLen = depth[dualRoot.second];
    dfs2(hHi[1].second, 1, make_pair(upLen.first + 1, upLen.second),
         downLen - 1);
    return;
  }
  pair<long long, long long> mx = upLen;
  for (auto v : a[u]) {
    if (v == p) continue;
    if (mark[v]) continue;
    mx = max(mx, make_pair(hLo[v].first + 1, hLo[v].second));
  }
  for (auto v : a[u]) {
    if (v == p) continue;
    if (!mark[v]) continue;
    dfs2(v, u, make_pair(mx.first + 1, mx.second),
         downLen + (mark[v] ? -1 : +1));
  }
  for (auto v : a[u]) {
    if (v == p) continue;
    if (mark[v]) continue;
    dfs2(v, u, make_pair(upLen.first + 1, upLen.second),
         downLen + (mark[v] ? -1 : +1));
  }
  if (!mark[u]) {
    if (upLen.first > downLen) {
      ans += upLen.first;
      order.push_back(data(upLen.second, u, u));
    } else {
      ans += downLen;
      order.push_back(data(dualRoot.second, u, u));
    }
  }
}
void dfs1(long long u, long long p) {
  for (auto v : a[u]) {
    if (v == p) continue;
    if (u == 1 && v == hHi[1].second) continue;
    dfs1(v, u);
  }
  if (u != 1) {
    ans += depth[u] + depth[dualRoot.second];
    order.push_back(data(u, dualRoot.second, u));
  }
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> n;
  for (long long i = 1; i <= n - 1; i++) {
    long long u, v;
    cin >> u >> v;
    a[u].push_back(v);
    a[v].push_back(u);
  }
  pdfs(1, 1);
  dualRoot.first = 1;
  long long curVer = 1, curH = hHi[1].first;
  while (curH > 0) {
    mark[curVer] = 1;
    curH--;
    curVer = hHi[curVer].second;
    mark[curVer] = 1;
  }
  dualRoot.second = curVer;
  dfs2(1, 1, make_pair(0, 0), 0);
  dfs1(1, 1);
  curVer = 1, curH = hHi[1].first;
  while (curH > 0) {
    order.push_back(data(curVer, dualRoot.second, curVer));
    ans += curH;
    curH--;
    curVer = hHi[curVer].second;
  }
  cout << ans << '\n';
  cout << order << '\n';
}