TWOPATHS - Two Paths

In Flatland there are N cities, connected by N-1 two-way roads. The cities are numbered from 1 to N. You can get from one city to another moving along the roads.

The "Two Paths" company, has won a tender to repair two paths in Flatland. A path is a sequence of different cities, connected sequentially by roads. The company is allowed to choose by itself the paths to repair. The only condition they have to meet is that the two paths shouldn't cross (i.e. shouldn't have common cities).

It is known that the profit, the "Two Paths" company will get, equals the product of the lengths of the two paths. Let's consider the length of each road equals 1, and the length of a path equals the amount of roads in it. Find the maximum possible profit for the company.

Input

The first line contains an integer N (2 ≤ N ≤ 100000), where N is the amount of cities in the country. The following N-1 lines contain the information about the roads. Each line contains a pair of numbers of the cities, connected by the road a and b (1 ≤ a, b ≤ N)

Output

Output the maximum possible profit.

Example

Input:
4
1 2
2 3
3 4

Output:
1

Added by:Oleg
Date:2010-05-31
Time limit:0.100s
Source limit:50000B
Memory limit:1536MB
Cluster: Cube (Intel G860)
Languages:All except: NODEJS OBJC PERL6 SQLITE VB.NET
Resource:Codeforces round 14 with larger limits

hide comments
2023-09-28 22:55:07
same question is asked on codeforces but there is relaxation on constraints:

problem Link: https://codeforces.com/contest/14/problem/D

My code: <snip>

[Simes]: no thanks

Last edit: 2023-09-28 23:15:21
2019-08-29 13:49:45 enigmus
I would just emphasize that you can reach any city from any other city, directly or indirectly(via route going through other cities). I don't think that is clear from the text of the problem
2018-10-19 06:16:25
why time limit is so strict :(((((
2016-06-28 21:06:23 ANSH KHANNA
strict time limit :/
2011-03-10 11:21:05 Almaz
9
1 2
1 7
1 8
2 3
2 4
2 5
5 6
8 9
answer = 9
2011-01-29 06:23:58 ajeet kumar
do anyone can give another test case
2010-06-09 14:14:15 [Rampage] Blue.Mary
If another sample is provided I won't have the 1st WA...
© Spoj.com. All Rights Reserved. Spoj uses Sphere Engine™ © by Sphere Research Labs.