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 long long MAXN = 2e5 + 10;
set<pair<long long, pair<long long, long long> > > s[MAXN];
vector<long long> vertex[MAXN];
vector<pair<long long, long long> > ans;
pair<pair<long long, long long>, pair<long long, long long> > f[MAXN];
long long d[MAXN];
long long in[MAXN];
bool check[MAXN];
void set_dfs(long long v) {
  check[v] = true;
  f[v] = make_pair(make_pair(0, v), make_pair(0, v));
  for (long long i = 0; i < vertex[v].size(); i++) {
    if (!check[vertex[v][i]]) {
      set_dfs(vertex[v][i]);
      pair<long long, long long> z = f[vertex[v][i]].first;
      z.first++;
      if (z > f[v].first) {
        swap(f[v].first, f[v].second);
        f[v].first = z;
      } else {
        f[v].second = max(f[v].second, z);
      }
    }
  }
}
void dfs(long long v, pair<long long, long long> t) {
  check[v] = true;
  if (t > f[v].first) {
    swap(f[v].first, f[v].second);
    f[v].first = t;
  } else {
    f[v].second = max(f[v].second, t);
  }
  pair<pair<long long, long long>, pair<long long, long long> > k =
      make_pair(t, t);
  for (long long i = 0; i < vertex[v].size(); i++) {
    if (!check[vertex[v][i]]) {
      pair<long long, long long> z = f[vertex[v][i]].first;
      z.first++;
      if (z > k.first) {
        swap(k.first, k.second);
        k.first = z;
      } else {
        k.second = max(k.second, z);
      }
    }
  }
  for (long long i = 0; i < vertex[v].size(); i++) {
    if (!check[vertex[v][i]]) {
      pair<long long, long long> z = f[vertex[v][i]].first;
      z.first++;
      if (k.first == z) {
        z = k.second;
        z.first++;
        dfs(vertex[v][i], z);
      } else {
        z = k.first;
        z.first++;
        dfs(vertex[v][i], z);
      }
    }
  }
}
int main() {
  ios_base ::sync_with_stdio(false);
  cin.tie(0);
  long long n, r, res = 0;
  cin >> n;
  for (long long i = 0; i < (n - 1); i++) {
    long long v, u;
    cin >> v >> u;
    vertex[v].push_back(u);
    vertex[u].push_back(v);
  }
  set_dfs(1);
  fill(check, check + MAXN, false);
  dfs(1, make_pair(-1, 1));
  for (long long i = 1; i <= n; i++) {
    if (f[f[i].first.second].first.second == i) {
      r = max(i, f[i].first.second);
    }
  }
  f[r].first = make_pair(0, r);
  for (long long i = 1; i <= n; i++) {
    d[i] = (long long)(vertex[i].size());
    if (d[i] == 1) {
      in[f[i].first.second]++;
    }
  }
  for (long long i = 1; i <= n; i++) {
    if (d[i] == 1) {
      s[in[i]].insert(
          make_pair(f[i].first.first, make_pair(i, f[i].first.second)));
    }
  }
  for (long long i = 0; i < (n - 1); i++) {
    pair<long long, pair<long long, long long> > k = (*s[0].begin());
    s[0].erase(s[0].begin());
    res += k.first;
    ans.push_back(make_pair(k.second.first, k.second.second));
    s[in[k.second.second]--].erase(
        make_pair(f[k.second.second].first.first,
                  make_pair(k.second.second, f[k.second.second].first.second)));
    s[in[k.second.second]].insert(
        make_pair(f[k.second.second].first.first,
                  make_pair(k.second.second, f[k.second.second].first.second)));
    for (long long j = 0; j < vertex[k.second.first].size(); j++) {
      d[vertex[k.second.first][j]]--;
      if (d[vertex[k.second.first][j]] == 1) {
        s[0].insert(make_pair(k.first - 1, make_pair(vertex[k.second.first][j],
                                                     k.second.second)));
        s[in[k.second.second]++].erase(make_pair(
            f[k.second.second].first.first,
            make_pair(k.second.second, f[k.second.second].first.second)));
        s[in[k.second.second]].insert(make_pair(
            f[k.second.second].first.first,
            make_pair(k.second.second, f[k.second.second].first.second)));
      }
    }
  }
  cout << res << endl;
  for (long long i = 0; i < ans.size(); i++) {
    cout << ans[i].first << " " << ans[i].second << " " << ans[i].first << endl;
  }
}