#include <bits/stdc++.h>
using namespace std;
bool endline = false;
template <class T>
istream& operator>>(istream& inp, vector<T>& v) {
  for (auto& it : v) inp >> it;
  return inp;
}
template <class T>
ostream& operator<<(ostream& out, vector<T>& v) {
  for (auto& it : v) out << it << (endline ? "\n" : " ");
  return out;
}
template <class T, class U>
istream& operator>>(istream& inp, pair<T, U>& v) {
  inp >> v.first >> v.second;
  return inp;
}
template <class T, class U>
ostream& operator<<(ostream& out, pair<T, U>& v) {
  out << v.first << ' ' << v.second;
  return out;
}
void debug() { cout << endl; }
template <typename H, typename... T>
void debug(H a, T... b) {
  cout << a << ' ';
  debug(b...);
}
void FAST_IO(string filein = "", string fileout = "", string fileerr = "") {
  if (fopen(filein.c_str(), "r")) {
    freopen(filein.c_str(), "r", stdin);
    freopen(fileout.c_str(), "w", stdout);
  }
  cin.tie(0), cout.tie(0)->sync_with_stdio(0);
}
void Hollwo_Pelw();
signed main() {
  FAST_IO(".inp", ".out");
  int testcases = 1;
  for (int test = 1; test <= testcases; test++) {
    Hollwo_Pelw();
  }
  return 0;
}
const int allmod[3] = {(int)1e9 + 7, 998244353, (int)1e9 + 9};
const int mod = allmod[0];
const int MAXN = 2e5 + 5;
const int inf = 2e9;
const long long linf = 1e18;
const long double eps = 1e-9;
long long n, depu[MAXN], depv[MAXN], par[MAXN];
vector<long long> adj[MAXN];
vector<tuple<long long, long long, long long>> res;
void dfs(long long u, long long p, long long* dep) {
  par[u] = p, dep[u] = p == u ? 0 : dep[p] + 1;
  for (auto v : adj[u])
    if (v != p) {
      dfs(v, u, dep);
    }
}
void Hollwo_Pelw() {
  cin >> n;
  for (long long i = 1, u, v; i < n; i++) {
    cin >> u >> v, adj[u].push_back(v), adj[v].push_back(u);
  }
  dfs(1, 1, depu);
  long long s = max_element(depu + 1, depu + n + 1) - depu;
  dfs(s, s, depu);
  long long e = max_element(depu + 1, depu + n + 1) - depu;
  dfs(e, e, depv);
  vector<long long> allv;
  set<long long> diameter;
  long long ans = 0, cur = s;
  diameter.insert(cur);
  while (cur != e) {
    cur = par[cur];
    diameter.insert(cur);
    res.push_back({s, cur, cur});
    ans += depu[cur];
  }
  for (long long i = 1; i <= n; i++)
    if (!diameter.count(i)) allv.push_back(i);
  sort(allv.begin(), allv.end(), [](const long long& a, const long long& b) {
    return max(depu[a], depv[a]) < max(depu[b], depv[b]);
  });
  for (auto v : allv) {
    if (depu[v] > depv[v]) {
      res.push_back({s, v, v});
      ans += depu[v];
    } else {
      res.push_back({e, v, v});
      ans += depv[v];
    }
  }
  reverse(res.begin(), res.end());
  cout << ans << endl;
  for (auto [u, v, w] : res) cout << u << ' ' << v << ' ' << w << endl;
}

### Prompt

Please create a solution in Cpp to the following 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

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
bool endline = false;
template <class T>
istream& operator>>(istream& inp, vector<T>& v) {
  for (auto& it : v) inp >> it;
  return inp;
}
template <class T>
ostream& operator<<(ostream& out, vector<T>& v) {
  for (auto& it : v) out << it << (endline ? "\n" : " ");
  return out;
}
template <class T, class U>
istream& operator>>(istream& inp, pair<T, U>& v) {
  inp >> v.first >> v.second;
  return inp;
}
template <class T, class U>
ostream& operator<<(ostream& out, pair<T, U>& v) {
  out << v.first << ' ' << v.second;
  return out;
}
void debug() { cout << endl; }
template <typename H, typename... T>
void debug(H a, T... b) {
  cout << a << ' ';
  debug(b...);
}
void FAST_IO(string filein = "", string fileout = "", string fileerr = "") {
  if (fopen(filein.c_str(), "r")) {
    freopen(filein.c_str(), "r", stdin);
    freopen(fileout.c_str(), "w", stdout);
  }
  cin.tie(0), cout.tie(0)->sync_with_stdio(0);
}
void Hollwo_Pelw();
signed main() {
  FAST_IO(".inp", ".out");
  int testcases = 1;
  for (int test = 1; test <= testcases; test++) {
    Hollwo_Pelw();
  }
  return 0;
}
const int allmod[3] = {(int)1e9 + 7, 998244353, (int)1e9 + 9};
const int mod = allmod[0];
const int MAXN = 2e5 + 5;
const int inf = 2e9;
const long long linf = 1e18;
const long double eps = 1e-9;
long long n, depu[MAXN], depv[MAXN], par[MAXN];
vector<long long> adj[MAXN];
vector<tuple<long long, long long, long long>> res;
void dfs(long long u, long long p, long long* dep) {
  par[u] = p, dep[u] = p == u ? 0 : dep[p] + 1;
  for (auto v : adj[u])
    if (v != p) {
      dfs(v, u, dep);
    }
}
void Hollwo_Pelw() {
  cin >> n;
  for (long long i = 1, u, v; i < n; i++) {
    cin >> u >> v, adj[u].push_back(v), adj[v].push_back(u);
  }
  dfs(1, 1, depu);
  long long s = max_element(depu + 1, depu + n + 1) - depu;
  dfs(s, s, depu);
  long long e = max_element(depu + 1, depu + n + 1) - depu;
  dfs(e, e, depv);
  vector<long long> allv;
  set<long long> diameter;
  long long ans = 0, cur = s;
  diameter.insert(cur);
  while (cur != e) {
    cur = par[cur];
    diameter.insert(cur);
    res.push_back({s, cur, cur});
    ans += depu[cur];
  }
  for (long long i = 1; i <= n; i++)
    if (!diameter.count(i)) allv.push_back(i);
  sort(allv.begin(), allv.end(), [](const long long& a, const long long& b) {
    return max(depu[a], depv[a]) < max(depu[b], depv[b]);
  });
  for (auto v : allv) {
    if (depu[v] > depv[v]) {
      res.push_back({s, v, v});
      ans += depu[v];
    } else {
      res.push_back({e, v, v});
      ans += depv[v];
    }
  }
  reverse(res.begin(), res.end());
  cout << ans << endl;
  for (auto [u, v, w] : res) cout << u << ' ' << v << ' ' << w << endl;
}

```