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 + 7;
long long n;
vector<long long> g[MAXN];
void read() {
  cin >> n;
  for (long long i = 0; i < n - 1; ++i) {
    long long u, v;
    cin >> u >> v;
    --u;
    --v;
    g[u].push_back(v);
    g[v].push_back(u);
  }
}
pair<long long, long long> dfs(long long u, long long parent) {
  pair<long long, long long> ans = {0, u};
  for (long long v : g[u]) {
    if (v == parent) continue;
    auto t = dfs(v, u);
    ans = max(ans, {t.first + 1, t.second});
  }
  return ans;
}
vector<long long> st;
bool dfs1(long long u, long long parent, long long want) {
  st.push_back(u);
  if (u == want) return 1;
  for (long long v : g[u]) {
    if (v == parent) continue;
    if (dfs1(v, u, want)) return 1;
  }
  st.pop_back();
  return 0;
}
long long d1[MAXN], d2[MAXN];
void dfs2(long long u, long long parent, long long depth, long long *arr) {
  arr[u] = depth;
  for (long long v : g[u]) {
    if (v == parent) continue;
    dfs2(v, u, depth + 1, arr);
  }
}
struct KEK {
  long long a, b, c;
  KEK(long long a_, long long b_, long long c_) {
    a = a_;
    b = b_;
    c = c_;
  }
};
bool del[MAXN];
long long pw[MAXN];
signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  read();
  auto t = dfs(0, 0);
  long long a = t.second;
  t = dfs(a, a);
  long long b = t.second;
  dfs1(a, a, b);
  set<long long> ms;
  for (long long e : st) ms.insert(e);
  dfs2(a, a, 0, d1);
  dfs2(b, b, 0, d2);
  for (long long i = 0; i < n; ++i) {
    pw[i] = g[i].size();
  }
  long long ans = 0;
  vector<KEK> l;
  set<pair<long long, long long> > s;
  for (long long i = 0; i < n; ++i) {
    if (ms.find(i) == ms.end()) {
      s.insert({pw[i], i});
    }
  }
  while (s.size()) {
    long long u = s.begin()->second;
    if (s.begin()->first > 1) exit(1);
    s.erase(s.begin());
    if (d2[u] < d1[u]) {
      ans += d1[u];
      l.push_back(KEK(a + 1, u + 1, u + 1));
    } else {
      ans += d2[u];
      l.push_back(KEK(b + 1, u + 1, u + 1));
    }
    del[u] = 1;
    for (long long v : g[u]) {
      if (del[v]) continue;
      if (ms.find(v) != ms.end()) continue;
      s.erase({pw[v], v});
      --pw[v];
      s.insert({pw[v], v});
    }
  }
  for (long long i = 0; i < (long long)st.size() - 1; ++i) {
    ans += d2[st[i]];
    l.push_back(KEK(b + 1, st[i] + 1, st[i] + 1));
  }
  cout << ans << '\n';
  for (KEK e : l) cout << e.a << ' ' << e.b << ' ' << e.c << '\n';
  return 0;
}