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;
template <typename A, typename B>
bool cmin(A &a, const B &b) {
  return a > b ? (a = b, true) : false;
}
template <typename A, typename B>
bool cmax(A &a, const B &b) {
  return a < b ? (a = b, true) : false;
}
const double PI = acos(-1);
const double EPS = 1e-9;
long long inf = sizeof(long long) == sizeof(long long) ? 2e18 : 1e9 + 10;
struct edge {
  long long to, cost;
};
class DIA {
 public:
  vector<vector<edge> > G;
  vector<long long> d;
  vector<bool> vis;
  long long n;
  DIA(long long size) {
    n = size;
    G = vector<vector<edge> >(n);
    d = vector<long long>(n);
    vector<bool> vis(n);
  }
  void add_edge(long long a, long long b, long long c) {
    edge e = {b, c}, ee = {a, c};
    G[a].push_back(e);
    G[b].push_back(ee);
  }
  void bfs(long long s) {
    d = vector<long long>(n, inf);
    queue<long long> q;
    q.push(s);
    d[s] = 0;
    long long u;
    while (!q.empty()) {
      u = q.front();
      q.pop();
      for (long long i = 0; i < G[u].size(); i++) {
        edge e = G[u][i];
        if (d[e.to] == inf) {
          d[e.to] = d[u] + e.cost;
          q.push(e.to);
        }
      }
    }
  }
  vector<vector<long long> > data;
  pair<long long, long long> dia() {
    pair<long long, long long> t;
    bfs(0);
    long long maxv = 0, tgt = 0;
    for (long long i = 0; i < n; i++)
      if (d[i] != inf && maxv < d[i]) {
        maxv = d[i];
        tgt = i;
      }
    t.first = tgt;
    bfs(tgt);
    data.push_back(d);
    maxv = 0;
    for (long long i = 0; i < n; i++)
      if (d[i] != inf) maxv = max(maxv, d[i]);
    for (long long i = 0; i < n; i++)
      if (maxv == d[i]) t.second = i;
    bfs(t.second);
    data.push_back(d);
    return t;
  }
  void f(pair<long long, long long> p) {
    vector<long long> co(n);
    for (long long i = 0; i < n; i++)
      for (long long j = 0; j < G[i].size(); j++) co[i]++;
    queue<long long> que;
    for (long long i = 0; i < n; i++)
      if (i != p.first && i != p.second && co[i] == 1) que.push(i);
    long long out = 0;
    vector<vector<long long> > da;
    while (que.size()) {
      long long a = que.front();
      que.pop();
      co[a]--;
      if (data[0][a] > data[1][a]) {
        out += data[0][a];
        da.push_back({a + 1, p.first + 1, a + 1});
      } else {
        out += data[1][a];
        da.push_back({a + 1, p.second + 1, a + 1});
      }
      for (long long i = 0; i < G[a].size(); i++) {
        co[G[a][i].to]--;
        if (co[G[a][i].to] == 1) que.push(G[a][i].to);
      }
    }
    que.push(p.second);
    while (que.size()) {
      long long a = que.front();
      que.pop();
      co[a]--;
      out += data[0][a];
      da.push_back({a + 1, p.first + 1, a + 1});
      for (long long i = 0; i < G[a].size(); i++) {
        co[G[a][i].to]--;
        if (co[G[a][i].to] == 1) que.push(G[a][i].to);
      }
    }
    cout << out << endl;
    {
      for (long long __ = 0; __ < da.size(); __++) {
        for (long long _ = 0; _ < da[__].size(); _++) cout << " " << da[__][_];
        cout << endl;
      };
    };
  }
};
signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  long long n;
  cin >> n;
  DIA dia(n);
  for (long long i = 0; i < n - 1; i++) {
    long long s, t;
    cin >> s >> t;
    s--;
    t--;
    dia.add_edge(s, t, 1);
  }
  pair<long long, long long> p = dia.dia();
  dia.f(p);
}