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
/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 *
 * @author dipankar12
 */
import java.io.*;
import java.util.*;
public class r14d {
    private LinkedList<Integer> adj[];
    static int max;
    
    public r14d(int n)
    {
        adj=new LinkedList[n+1];
        for(int i=0;i<=n;i++)
            adj[i]=new LinkedList<Integer>();
    }
    void setEdge(int u,int v)
    {
        adj[u].add(v);
    }
    void removeEdge(int u,int v)
    {
        Integer x=u;
        Integer y=v;
        adj[u].remove(y);
        adj[v].remove(x);
    }
    void dfs1(int src,boolean visited[],int depth[])
    {
        visited[src]=true;
        Iterator<Integer> it=adj[src].iterator();
        while(it.hasNext())
        {
            int x=it.next();
            if(!visited[x])
            {
                depth[x]=depth[src]+1;
                dfs1(x,visited,depth);
            }
        }
    }
    void dfs2(int src,boolean visited[],int count)
    {
        //System.out.println("src "+src+" max "+max+" "+count);
        visited[src]=true;
        Iterator<Integer> it=adj[src].iterator();
        while(it.hasNext())
        {
            int x=it.next();
            if(!visited[x])
            {
                max=Math.max(max, count+1);
                dfs2(x,visited,count+1);
            }
        }
    }
    public static void main(String args[])
    {
        fastio in=new fastio(System.in);
        PrintWriter pw=new PrintWriter(System.out);

        int n=in.nextInt();
        r14d ob=new r14d(n);
        int edges[][]=new int[n-1][2];
        for(int i=0;i<n-1;i++)
        {
            int u=in.nextInt();
            int v=in.nextInt();
            edges[i][0]=u;
            edges[i][1]=v;
            ob.setEdge(u, v);
            ob.setEdge(v, u);
        }
        
        int max=0;
        for(int i=0;i<n-1;i++)
        {
            int u=edges[i][0];
            int v=edges[i][1];
            
            //pw.println("u "+u+" v "+v);
            
            ob.removeEdge(u, v);
            ob.removeEdge(v, u);
            
            boolean visited[]=new boolean[n+1];
            int depth[]=new int[n+1];
            ob.dfs1(u, visited, depth);
            
            int maxd=0,maxp=u;
            for(int j=0;j<=n;j++)
            {
                if(maxd<depth[j])
                {
                    maxd=depth[j];
                    maxp=j;
                }
            }
            
            //pw.println("maxp"+maxp);
            Arrays.fill(visited, false);
            ob.dfs2(maxp, visited, 0);
            int len1=ob.max;
            ob.max=0;
            
            Arrays.fill(depth, 0);
            Arrays.fill(visited, false);
            ob.dfs1(v, visited, depth);
            maxd=0;
            maxp=v;
            for(int j=0;j<=n;j++)
                if(maxd<depth[j])
                {
                    maxd=depth[j];
                    maxp=j;
                }
            
            Arrays.fill(visited, false);
            ob.dfs2(maxp, visited, 0);
            int len2=ob.max;
            ob.max=0;
            
            //pw.println("maxp "+maxp);
            //pw.println(len1+" "+len2);
            max=Math.max(max, len1*len2);
            ob.setEdge(u, v);
            ob.setEdge(v, u);
        }
        
        pw.println(max);
        pw.close();
    }

    static class fastio {
     
            private final InputStream stream;
            private final byte[] buf = new byte[8192];
            private int cchar, snchar;
            private SpaceCharFilter filter;
     
            public fastio(InputStream stream) {
                this.stream = stream;
            }
     
            public int nxt() {
                if (snchar == -1)
                    throw new InputMismatchException();
                if (cchar >= snchar) {
                    cchar = 0;
                    try {
                        snchar = stream.read(buf);
                    } catch (IOException e) {
                        throw new InputMismatchException();
                    }
                    if (snchar <= 0)
                        return -1;
                }
                return buf[cchar++];
            }
     
            public int nextInt() {
                int c = nxt();
                while (isSpaceChar(c)) {
                    c = nxt();
                }
                int sgn = 1;
                if (c == '-') {
                    sgn = -1;
                    c = nxt();
                }
                int res = 0;
                do {
                    if (c < '0' || c > '9')
                        throw new InputMismatchException();
                    res *= 10;
                    res += c - '0';
                    c = nxt();
                } while (!isSpaceChar(c));
                return res * sgn;
            }
     
            public long nextLong() {
                int c = nxt();
                while (isSpaceChar(c)) {
                    c = nxt();
                }
                int sgn = 1;
                if (c == '-') {
                    sgn = -1;
                    c = nxt();
                }
                long res = 0;
                do {
                    if (c < '0' || c > '9')
                        throw new InputMismatchException();
                    res *= 10;
                    res += c - '0';
                    c = nxt();
                } while (!isSpaceChar(c));
                return res * sgn;
            }
     
            public int[] nextIntArray(int n) {
                int a[] = new int[n];
                for (int i = 0; i < n; i++) {
                    a[i] = nextInt();
                }
                return a;
            }
     
            public String readString() {
                int c = nxt();
                while (isSpaceChar(c)) {
                    c = nxt();
                }
                StringBuilder res = new StringBuilder();
                do {
                    res.appendCodePoint(c);
                    c = nxt();
                } while (!isSpaceChar(c));
                return res.toString();
            }
     
            public String nextLine() {
                int c = nxt();
                while (isSpaceChar(c))
                    c = nxt();
                StringBuilder res = new StringBuilder();
                do {
                    res.appendCodePoint(c);
                    c = nxt();
                } while (!isEndOfLine(c));
                return res.toString();
            }
     
            public boolean isSpaceChar(int c) {
                if (filter != null)
                    return filter.isSpaceChar(c);
                return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
            }
     
            private boolean isEndOfLine(int c) {
                return c == '\n' || c == '\r' || c == -1;
            }
     
            public interface SpaceCharFilter {
                public boolean isSpaceChar(int ch);
            }
        }
    

}
