As you know, Bob's brother lives in Flatland. 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, where Bob's brother works, 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 ≤ 200), 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 ai, bi (1 ≤ ai, bi ≤ n).

Output

Output the maximum possible profit.

Examples

Input

4
1 2
2 3
3 4


Output

1


Input

7
1 2
1 3
1 4
1 5
1 6
1 7


Output

0


Input

6
1 2
2 3
2 4
5 4
6 4


Output

4
import java.util.*;
import java.io.*;
import java.math.*;
public class Main
{
    static class Reader 
    { 
        private InputStream mIs;private byte[] buf = new byte[1024];private int curChar,numChars;public Reader() { this(System.in); }public Reader(InputStream is) { mIs = is;} 
        public int read() {if (numChars == -1) throw new InputMismatchException();if (curChar >= numChars) {curChar = 0;try { numChars = mIs.read(buf);} catch (IOException e) { throw new InputMismatchException();}if (numChars <= 0) return -1; }return buf[curChar++];} 
        public String nextLine(){int c = read();while (isSpaceChar(c)) c = read();StringBuilder res = new StringBuilder();do {res.appendCodePoint(c);c = read();}while (!isEndOfLine(c));return res.toString() ;} 
        public String s(){int c = read();while (isSpaceChar(c)) c = read();StringBuilder res = new StringBuilder();do {res.appendCodePoint(c);c = read();}while (!isSpaceChar(c));return res.toString();} 
        public long l(){int c = read();while (isSpaceChar(c)) c = read();int sgn = 1;if (c == '-') { sgn = -1 ; c = read() ; }long res = 0; do{ if (c < '0' || c > '9') throw new InputMismatchException();res *= 10 ; res += c - '0' ; c = read();}while(!isSpaceChar(c));return res * sgn;} 
        public int i(){int c = read() ;while (isSpaceChar(c)) c = read();int sgn = 1;if (c == '-') { sgn = -1 ; c = read() ; }int res = 0;do{if (c < '0' || c > '9') throw new InputMismatchException();res *= 10 ; res += c - '0' ; c = read() ;}while(!isSpaceChar(c));return res * sgn;} 
        public double d() throws IOException {return Double.parseDouble(s()) ;}
        public boolean isSpaceChar(int c) { return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1; } 
        public boolean isEndOfLine(int c) { return c == '\n' || c == '\r' || c == -1; } 
        public int[] arr(int n){int[] ret = new int[n];for (int i = 0; i < n; i++) {ret[i] = i();}return ret;}
    }
    
    
    ///////////////////////////////////////////////////////////////////////////////////////////
    //    RRRRRRRRR            AAA             HHH     HHH     IIIIIIIIIIIII   LLL           //
    //    RR    RRR           AAAAA            HHH     HHH      IIIIIIIIIII    LLL           //
    //    RR   RRR           AAAAAAA           HHH     HHH          III        LLL           //
    //    RR  RRR           AAA   AAA          HHHHHHHHHHH          III        LLL           //
    //    RRRRRR           AAA     AAA         HHHHHHHHHHH          III        LLL           //
    //    RR  RRR         AAAAAAAAAAAAA        HHH     HHH          III        LLL           //
    //    RR    RRR      AAA         AAA       HHH     HHH      IIIIIIIIIII    LLLLLLLLLLLL  //
    //    RR     RRR    AAA           AAA      HHH     HHH     IIIIIIIIIIIII   LLLLLLLLLLLL  //
    ///////////////////////////////////////////////////////////////////////////////////////////
    static int n;
    static LinkedList<Integer> adj[];
    static int vis[];
    static int cache[];
    static int count=0;
    static int marker[];
    public static void dfs1(int j,int mark)
    {
        if(vis[j]!=0)
        return ;
        vis[j]=1;
        marker[j]=mark;
        for(int i:adj[j])
        dfs1(i,mark);
    }
    public static int dfs(int j)
    {
        if(vis[j]==1)
        return 0;
        if(cache[j]!=-1)
        return cache[j];
        vis[j]=1;
        int ans=0;
        for(int i:adj[j])
        if(vis[i]==0)
        ans=Math.max(ans,dfs(i)+1);
        return cache[j]=ans;
    }
    public static void main(String[] args)throws IOException
    {
        PrintWriter out= new PrintWriter(System.out);
        Reader sc=new Reader();
        n=sc.i();
        adj = new LinkedList[n];
        vis=new int[n];
        cache=new int[n];
        marker=new int[n];
        Arrays.fill(cache,-1);
        for (int i=0; i<n; ++i)
        adj[i] = new LinkedList();
        int arr[][]=new int[n-1][2];
        for(int i=0;i<n-1;i++)
        {
            int a=sc.i()-1;
            int b=sc.i()-1;
            arr[i][0]=a;
            arr[i][1]=b;
            adj[a].add(b);
            adj[b].add(a);
        }
        int max=0;
        for(int i=0;i<n-1;i++)
        {
            if(adj[arr[i][0]].size()!=1&&adj[arr[i][1]].size()!=1)
            {
                adj[arr[i][0]].remove(adj[arr[i][0]].indexOf(arr[i][1]));
                adj[arr[i][1]].remove(adj[arr[i][1]].indexOf(arr[i][0]));
                
                int count1=0;
                int count2=0;
                int mark=1;
                for(int j=0;j<n;j++)
                {
                    if(marker[j]==0&&mark==1)
                    {
                        dfs1(j,mark);
                        mark++;
                    }
                    else if(marker[j]==0&&mark==2)
                    {
                        dfs1(j,mark);
                        mark++;
                    }
                    if(mark==3)
                    break;
                }
                for(int j=0;j<n;j++)
                {
                    if(adj[j].size()==1)
                    {
                        //System.out.println(j+" "+dfs(j));
                        //System.out.println(j+" "+marker[j]);
                        if(marker[j]==1)
                        count1=Math.max(count1,dfs(j));
                        else
                        count2=Math.max(count2,dfs(j));
                        Arrays.fill(cache,-1);
                        Arrays.fill(vis,0);
                    }
                }
                max=Math.max(max,count1*count2);
                //System.out.println(i+" "+count1+" "+count2);
                Arrays.fill(vis,0);
                Arrays.fill(cache,-1);
                Arrays.fill(marker,0);
                adj[arr[i][0]].add(arr[i][1]);
                adj[arr[i][1]].add(arr[i][0]);
            }
        }
        out.println(max);
        out.flush();
    }
}