#include <bits/stdc++.h>
using namespace std;
vector<vector<long long int> > arr(200001);
long long int visited[200001];
long long int level[3][200001];
long long int parent[200001];
long long int path[200001];
vector<pair<long long int, pair<long long int, long long int> > > ppp;
vector<long long int> leaf;
void dfs(long long int u, long long int index) {
  visited[u] = 1;
  long long int i;
  for (i = 0; i < arr[u].size(); i++) {
    long long int v = arr[u][i];
    if (visited[v] == 0) {
      visited[v] = 1;
      level[index][v] = 1 + level[index][u];
      dfs(v, index);
    }
  }
}
void dfs1(long long int u) {
  visited[u] = 1;
  long long int i;
  for (i = 0; i < arr[u].size(); i++) {
    long long int v = arr[u][i];
    if (visited[v] == 0) {
      visited[v] = 1;
      parent[v] = u;
      dfs1(v);
    }
  }
  leaf.push_back(u);
}
int main() {
  long long int n;
  cin >> n;
  long long int i;
  for (i = 1; i <= n - 1; i++) {
    long long int u, v;
    cin >> u >> v;
    arr[u].push_back(v);
    arr[v].push_back(u);
  }
  memset(visited, 0, sizeof(visited));
  level[0][1] = 0;
  dfs(1, 0);
  long long int u;
  long long int ma = -10000;
  for (i = 1; i <= n; i++) {
    if (level[0][i] > ma) {
      ma = level[0][i];
      u = i;
    }
  }
  memset(visited, 0, sizeof(visited));
  level[1][u] = 0;
  dfs(u, 1);
  ma = -10000;
  long long int v;
  for (i = 1; i <= n; i++) {
    if (level[1][i] > ma) {
      ma = level[1][i];
      v = i;
    }
  }
  memset(visited, 0, sizeof(visited));
  level[2][v] = 0;
  dfs(v, 2);
  long long int ans = 0;
  parent[u] = -1;
  memset(visited, 0, sizeof(visited));
  dfs1(u);
  long long int x = v;
  memset(path, 0, sizeof(path));
  while (parent[x] != -1) {
    path[x] = 1;
    x = parent[x];
  }
  path[u] = 1;
  for (i = 0; i < leaf.size(); i++) {
    long long int y = leaf[i];
    if (path[y] == 0) {
      if (level[1][y] > level[2][y]) {
        ppp.push_back(make_pair(u, make_pair(y, y)));
        ans = ans + level[1][y];
      } else {
        ppp.push_back(make_pair(v, make_pair(y, y)));
        ans = ans + level[2][y];
      }
    }
  }
  x = v;
  while (x != u) {
    ppp.push_back(make_pair(u, make_pair(x, x)));
    ans = ans + level[1][x];
    x = parent[x];
  }
  cout << ans << "\n";
  for (i = 0; i < ppp.size(); i++) {
    cout << ppp[i].first << " " << ppp[i].second.first << " "
         << ppp[i].second.second << "\n";
  }
  return 0;
}

### Prompt

Generate a CPP solution 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;
vector<vector<long long int> > arr(200001);
long long int visited[200001];
long long int level[3][200001];
long long int parent[200001];
long long int path[200001];
vector<pair<long long int, pair<long long int, long long int> > > ppp;
vector<long long int> leaf;
void dfs(long long int u, long long int index) {
  visited[u] = 1;
  long long int i;
  for (i = 0; i < arr[u].size(); i++) {
    long long int v = arr[u][i];
    if (visited[v] == 0) {
      visited[v] = 1;
      level[index][v] = 1 + level[index][u];
      dfs(v, index);
    }
  }
}
void dfs1(long long int u) {
  visited[u] = 1;
  long long int i;
  for (i = 0; i < arr[u].size(); i++) {
    long long int v = arr[u][i];
    if (visited[v] == 0) {
      visited[v] = 1;
      parent[v] = u;
      dfs1(v);
    }
  }
  leaf.push_back(u);
}
int main() {
  long long int n;
  cin >> n;
  long long int i;
  for (i = 1; i <= n - 1; i++) {
    long long int u, v;
    cin >> u >> v;
    arr[u].push_back(v);
    arr[v].push_back(u);
  }
  memset(visited, 0, sizeof(visited));
  level[0][1] = 0;
  dfs(1, 0);
  long long int u;
  long long int ma = -10000;
  for (i = 1; i <= n; i++) {
    if (level[0][i] > ma) {
      ma = level[0][i];
      u = i;
    }
  }
  memset(visited, 0, sizeof(visited));
  level[1][u] = 0;
  dfs(u, 1);
  ma = -10000;
  long long int v;
  for (i = 1; i <= n; i++) {
    if (level[1][i] > ma) {
      ma = level[1][i];
      v = i;
    }
  }
  memset(visited, 0, sizeof(visited));
  level[2][v] = 0;
  dfs(v, 2);
  long long int ans = 0;
  parent[u] = -1;
  memset(visited, 0, sizeof(visited));
  dfs1(u);
  long long int x = v;
  memset(path, 0, sizeof(path));
  while (parent[x] != -1) {
    path[x] = 1;
    x = parent[x];
  }
  path[u] = 1;
  for (i = 0; i < leaf.size(); i++) {
    long long int y = leaf[i];
    if (path[y] == 0) {
      if (level[1][y] > level[2][y]) {
        ppp.push_back(make_pair(u, make_pair(y, y)));
        ans = ans + level[1][y];
      } else {
        ppp.push_back(make_pair(v, make_pair(y, y)));
        ans = ans + level[2][y];
      }
    }
  }
  x = v;
  while (x != u) {
    ppp.push_back(make_pair(u, make_pair(x, x)));
    ans = ans + level[1][x];
    x = parent[x];
  }
  cout << ans << "\n";
  for (i = 0; i < ppp.size(); i++) {
    cout << ppp[i].first << " " << ppp[i].second.first << " "
         << ppp[i].second.second << "\n";
  }
  return 0;
}

```