CF765E Tree Folding

Description

Vanya wants to minimize a tree. He can perform the following operation multiple times: choose a vertex $ v $ , and two disjoint (except for $ v $ ) paths of equal length $ a_{0}=v $ , $ a_{1} $ , ..., $ a_{k} $ , and $ b_{0}=v $ , $ b_{1} $ , ..., $ b_{k} $ . Additionally, vertices $ a_{1} $ , ..., $ a_{k} $ , $ b_{1} $ , ..., $ b_{k} $ must not have any neighbours in the tree other than adjacent vertices of corresponding paths. After that, one of the paths may be merged into the other, that is, the vertices $ b_{1} $ , ..., $ b_{k} $ can be effectively erased: ![](https://cdn.luogu.com.cn/upload/vjudge_pic/CF765E/8a327dc5b22e7a12ad1fd6e8837e08cb4a661c45.png)Help Vanya determine if it possible to make the tree into a path via a sequence of described operations, and if the answer is positive, also determine the shortest length of such path.

Input Format

N/A

Output Format

N/A

Explanation/Hint

In the first sample case, a path of three edges is obtained after merging paths $ 2-1-6 $ and $ 2-4-5 $ . It is impossible to perform any operation in the second sample case. For example, it is impossible to merge paths $ 1-3-4 $ and $ 1-5-6 $ , since vertex 6 additionally has a neighbour 7 that is not present in the corresponding path.