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

/**
 *
 * @author sarthak
 */

import java.util.*;
import java.math.*;
import java.io.*;



public class rnd14_D {

    static class FastScanner {
        BufferedReader br;
        StringTokenizer st;

        public FastScanner(InputStream is) {
            br = new BufferedReader(new InputStreamReader(is));
        }

        public String next() {
            while (st == null || !st.hasMoreTokens()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        public String nextLine() {
            st = null;
            try {
                return br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
                return "";
            }
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

        public long nextLong() {
            return Long.parseLong(next());
        }

        public double nextDouble() {
            return Double.parseDouble(next());
        }
    }
    static class P implements Comparable{

        private int u, v;

        public P(int x, int y) {
            this.u = x;
            this.v = y;
        }

        public int hashCode() {
            return (u * 31) ^ v;
        }

        public boolean equals(Object o) {
            if (o instanceof P) {
                P other = (P) o;
                return (u == other.u && v == other.v);
            }
            return false;
        }
        public int compareTo(Object obj) {
		P l = (P) obj;
		if (this.u == l.u){
			if (this.v == l.v) return 0;
			return (this.v < l.v)? -1: 1;
		}
		return (this.u < l.u)? -1: 1;
	}
    }
    static ArrayList<Integer>[] G;
    
    static int[] vis,h;
    static int n;
    static P re;
    public static int m(int a,int b){
        return Math.min(a,b);
    }
    public static int M(int a,int b){
        return Math.max(a,b);
    }
    public static void dfs(int v){
        vis[v]=1;
   //     System.out.println(" visiting vertex  : " + v);
        for(int ad:G[v]){ 
            if(!(m(v,ad)==re.u && M(v,ad)==re.v)){ //removing edge
                if(vis[ad]==0){
                    h[ad]=h[v]+1;
                    dfs(ad);
                }
            }
        }
    }
    
    
    public static int diam(int v){
        vis=new int[n+1];
        h=new int[n+1];
        dfs(v);
        int h1=0,v1=v;
        for(int i=1;i<=n;i++){
            if(h[i]>h1){
                h1=h[i];
                v1=i;
            }
        }
  //      System.out.println(" max height found for vertex " + v1 +"  " + h1);
 //       System.out.println();
  //      System.out.println();
        
        Arrays.fill(vis,0);
        Arrays.fill(h,0);
        dfs(v1);
        h1=0;
        for(int i=1;i<=n;i++){
            if(h[i]>h1)
                h1=h[i];
        }
 //       System.out.println(" max height found for vertex " + v1 +"  " + h1);
 //       System.out.println();
 //       System.out.println();
        return h1;
    }
    
    

    public static void main(String[] args){
         
    FastScanner s = new FastScanner(System.in);
    StringBuilder op=new StringBuilder();
    ArrayList<P> ED=new ArrayList<>();
    n=s.nextInt();
    G=new ArrayList[n+1];
    for(int i=1;i<=n;i++)
        G[i]=new ArrayList<>();
    for(int i=1;i<=n-1;i++)
    {
        int u=s.nextInt();
        int v=s.nextInt();
        G[u].add(v);
        G[v].add(u);
        ED.add(new P(m(u,v),M(u,v)));
    }
    int an=0;
   // System.out.println();
    for(P e:ED){
        re=e;
     //   System.out.println(" removing edge   :  "   + re.u+"  " + re.v);
        
        int d1=diam(e.u);
        int d2=diam(e.v);
        an=M(an,(d1*d2));
       // System.out.println("______________________________________________");
    }
    System.out.println(an);
   
    }


}
