Foxes and DFS#12287

Foxes and DFS

1 second
256 megabytes
Very hard

After successfully decorating the New Year tree, the foxes decided to compete in tree traversals.

Tree traversal is a traditional game in Rudolandy where foxes compete to see whose DFS traversal of the tree will be more beautiful. Each year, the criterion for the beauty of the tree changes. This year, the beauty of the tree will be defined as a function , the value of which numerically equals the length of the longest substring that appears in the number and consists only of and , where is the number formed by writing the vertex numbers in the order in which you traversed the tree.

This year, you are also allowed to join the game with them. The game will take place on a tree with vertices and n - 1 edges.

You became curious about what the maximum value of from all possible DFS traversals can be achieved.

By a DFS traversal of the tree starting from vertex , we mean the order of vertices determined by the following recursive algorithm: dfs(1); in the procedure dfs(v), vertex is added to the traversal order, after which in any order dfs(u) is recursively called for all unvisited neighbors of vertex .

Input

The first line contains a single integer (1 \le n \le 2 \cdot 10^5) — the number of vertices in the tree.

The next n - 1 lines contain two integers and (1 \le v, u \le n, u \neq v) — the edges between vertices and .

Output

Output a single integer — the maximum value of from all possible DFS traversals.

Examples

Example 1

Loading
Loading

Note

We have the following tree:

The most advantageous traversal will be: 1 -> 7 -> 10 -> 9 -> 6 -> 2 -> 3 -> 4 -> 5 -> 8

Then the number 17109623458.

Thus, the longest substring will be "171" with a length of 3.

Scoring

  1. Subtask ( points): (n \le 10)

  2. Subtask ( points): (Tree shaped like a bamboo)

  3. Subtask ( points): (Tree shaped like a star)

  4. Subtask ( points): (cntChild_{v} \le 2)

  5. Subtask ( points): (n \le 100)

  6. Subtask ( points): (n \le 5000)

  7. Subtask ( points): No additional constraints