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>
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;
const long long inf = numeric_limits<long long>::max() / 2;
const long double eps = 1e-9;
const long double pi = acos(-1);
template <typename T>
inline bool mineq(T& a, T b) {
  return (a > b) ? (a = b, 1) : 0;
}
template <typename T>
inline bool maxeq(T& a, T b) {
  return (a < b) ? (a = b, 1) : 0;
}
inline void solve(), read();
const string file = "";
int main() {
  if (file != "") {
    freopen((file + ".in").c_str(), "r", stdin);
    freopen((file + ".out").c_str(), "w", stdout);
  }
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  ;
  read();
  solve();
  return 0;
}
struct graph {
  long long n;
  vector<set<long long> > adj;
  graph() {}
  graph(long long n_) {
    n = n_;
    adj.resize(n);
  }
  void add(long long v, long long u) {
    adj[v].insert(u);
    adj[u].insert(v);
  }
};
const long long LOG = 20;
long long n, timer = 0;
graph g;
vector<long long> d, tin, tout;
vector<vector<long long> > up;
set<pair<long long, long long> > q;
vector<pair<long long, long long> > ans;
void dfs(long long v, long long p) {
  d[v] = d[p] + 1;
  up[v][0] = p;
  tin[v] = timer++;
  for (long long i = 1; i < LOG; i++) {
    up[v][i] = up[up[v][i - 1]][i - 1];
  }
  for (long long u : g.adj[v]) {
    if (u == p) {
      continue;
    }
    dfs(u, v);
  }
  tout[v] = timer++;
}
inline bool upper(long long a, long long b) {
  return tin[a] <= tin[b] && tout[a] >= tout[b];
}
long long lca(long long a, long long b) {
  if (upper(a, b)) {
    return a;
  }
  if (upper(b, a)) {
    return b;
  }
  for (long long i = LOG - 1; i >= 0; i--) {
    if (!upper(up[a][i], b)) {
      a = up[a][i];
    }
  }
  return up[a][0];
}
long long getd(long long a, long long b) {
  long long c = lca(a, b);
  return d[a] - d[c] + d[b] - d[c];
}
inline void solve() {
  d.assign(n, -1);
  tin.assign(n, 0), tout.assign(n, 0);
  up.assign(n, vector<long long>(LOG, 0));
  dfs(0, 0);
  long long l1 = max_element((d).begin(), (d).end()) - d.begin();
  d.assign(n, -1);
  tin.assign(n, 0), tout.assign(n, 0);
  up.assign(n, vector<long long>(LOG, 0));
  dfs(l1, l1);
  long long l2 = max_element((d).begin(), (d).end()) - d.begin();
  for (long long i = 0; i < n; i++) {
    if (i != l1 && i != l2) {
      q.insert({(long long)((g.adj[i]).size()), i});
    }
  }
  long long cur = 0;
  while (!q.empty()) {
    if (q.begin()->first != 1) {
      break;
    }
    long long v = q.begin()->second;
    long long u = *g.adj[v].begin();
    q.erase(*q.begin());
    if (u != l1 && u != l2) {
      q.erase({(long long)((g.adj[u]).size()), u});
      g.adj[u].erase(v);
      q.insert({(long long)((g.adj[u]).size()), u});
    }
    long long d1 = getd(v, l1);
    long long d2 = getd(v, l2);
    if (d1 > d2) {
      cur += d1;
      ans.push_back({v, l1});
    } else {
      cur += d2;
      ans.push_back({v, l2});
    }
  }
  long long k = (long long)((q).size()) + 2;
  while (l1 != l2) {
    cur += getd(l1, l2);
    ans.push_back({l2, l1});
    long long l = *g.adj[l2].begin();
    g.adj[l].erase(l2);
    l2 = l;
  }
  cout << cur << "\n";
  for (pair<long long, long long> p : ans) {
    cout << p.first + 1 << " " << p.second + 1 << " " << p.first + 1 << "\n";
  }
}
inline void read() {
  cin >> n;
  g = graph(n);
  for (long long i = 0; i < n - 1; i++) {
    long long v, u;
    cin >> v >> u;
    --v, --u;
    g.add(v, u);
  }
}