Virtual contest is a way to take part in past contest, as close as possible to participation on time. It is supported only ICPC mode for virtual contests.
If you've seen these problems, a virtual contest is not for you - solve these problems in the archive.
If you just want to solve some problem from a contest, a virtual contest is not for you - solve this problem in the archive.
Never use someone else's code, read the tutorials or communicate with other person during a virtual contest.

No tag edit access

The problem statement has recently been changed. View the changes.

×
F. Tree Destruction

time limit per test

2 secondsmemory limit per test

256 megabytesinput

standard inputoutput

standard outputYou 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:

- choose two leaves;
- add the length of the simple path between them to the answer;
- 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·10^{5}) — the number of vertices in the tree.

Next *n* - 1 lines describe the edges of the tree in form *a*_{i}, *b*_{i} (1 ≤ *a*_{i}, *b*_{i} ≤ *n*, *a*_{i} ≠ *b*_{i}). 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 *a*_{i}, *b*_{i}, *c*_{i}, where *a*_{i}, *b*_{i} — pair of the leaves that are chosen in the current operation (1 ≤ *a*_{i}, *b*_{i} ≤ *n*), *c*_{i} (1 ≤ *c*_{i} ≤ *n*, *c*_{i} = *a*_{i} or *c*_{i} = *b*_{i}) — 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

Codeforces (c) Copyright 2010-2021 Mike Mirzayanov

The only programming contests Web 2.0 platform

Server time: May/07/2021 09:21:23 (j1).

Desktop version, switch to mobile version.

Supported by

User lists

Name |
---|