Afrika paprika! – S.V.
After a tiring morning in the garden, Mr. Malnar decided to reward himself with dried hot peppers he grew himself.
He has peppers, connected with pieces of string, so that every two peppers are connected by some series of strings. Formally, they form a tree.
Mr. Malnar will partake in three lunches today. For that purpose, he will cut two strings to get three smaller components, one for each lunch.
It's bad to make any lunch too spicy, so he will choose the cuts in a way that minimizes the difference between the size of the largest and the smallest component. You need to determine the sought minimum difference.
Input
The first line contains an integer , the number of peppers. The peppers are labeled by integers from to .
Each of the following lines contains two integers and – labels of peppers that are directly connected by a piece of string.
Output
Print the minimum possible difference of component sizes.
Scoring
Subtask | Score | Constraints |
---|---|---|
Sample Input 1
4
1 2
2 3
3 4
Sample Output 1
1
Explanation for Sample Output 1
In the first example, each of the possible three ways of cutting the strings yields one component with two peppers and two components with one pepper each. Therefore the answer is .
Sample Input 2
6
1 2
1 3
3 4
3 5
5 6
Sample Output 2
0
Explanation for Sample Output 2
In the second example, it's possible to get three components of the same size by cutting the string that connects peppers and , and also and , so the answer is .
Sample Input 3
9
1 3
2 3
3 4
3 5
5 6
5 7
7 8
7 9
Sample Output 3
2
Explanation for Sample Output 3
Optimal cuts for the third example are shown on the figure in the statement. The sizes of the components are , and , and the answer is .
Comments