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.io.*;
import java.math.BigInteger;
import java.util.*;

public class D14 implements Runnable {
	private InputReader in;
	private PrintWriter out;
	
	public static void main(String[] args) {
		new D14().run();
	}

	public D14() {
		in = new InputReader(System.in);
		out = new PrintWriter(System.out);
	}
	
	private static final int INF = 1000000000;
	private static final int MAXN = 200+5;
	
	int NOCOLOR = 0;
	int YELLOW = 1;
	int GREEN = 2;
	int[] color = new int[MAXN];
	boolean[] visited = new boolean[MAXN];
	Deque<Integer> queue = new ArrayDeque<Integer>();
	void flood(int split) {
	    Arrays.fill(color, NOCOLOR);

	    
	    color[as[split]] = YELLOW;
	    color[bs[split]] = GREEN;
	    
	    queue.add(as[split]);
	    while (!queue.isEmpty()) {
	        int v = queue.pollFirst();
	        color[v] = YELLOW;
	        for (int v2 : edges[v])
	            if (color[v2] == NOCOLOR)
	                queue.add(v2);
	        
	    }
	    
	    queue.add(bs[split]);
	    while (!queue.isEmpty()) {
	        int v = queue.pollFirst();
	        color[v] = GREEN;
	        for (int v2 : edges[v])
	            if (color[v2] == NOCOLOR)
    	            queue.add(v2);
	    }
	    
	    //for (int i = 0; i < N; i++)
	    //    System.out.println(color[i]);
	}
	
	int N;
	int[] as = new int[MAXN];
	int[] bs = new int[MAXN];
	boolean[][] connect = new boolean[MAXN][MAXN];
	List<Integer>[] edges = new ArrayList[MAXN];
	int[][] dist = new int[MAXN][MAXN];
	public void run() {
        N = in.readInt();
        //System.out.println("A-2");
        for (int i = 0; i < N; i++) {
            edges[i] = new ArrayList<Integer>();
        }
        //System.out.println("A-1");
        // Read
        for (int i = 0; i < N-1; i++) {
            int p = in.readInt()-1;
            int q = in.readInt()-1;
            as[i] = p;
            bs[i] = q;
            connect[p][q] = true;
            connect[q][p] = true;
            edges[p].add(q);
            edges[q].add(p);
        }
        //System.out.println("A");
        // Ford
        for (int i = 0; i < N; i++)
            for (int j = 0; j < N; j++) {
                dist[i][j] = connect[i][j] ? 1 : INF;
                if (i == j) dist[i][j] = 0;
            }
        for (int k = 0; k < N; k++)
            for (int i = 0; i < N; i++)
                for (int j = 0; j < N; j++)
                    dist[i][j] = Math.min(dist[i][j], dist[i][k]+dist[k][j]);
        
        /*for (int i = 0; i < N; i++) {
            for (int j = 0; j < N; j++)
                System.out.print(dist[i][j]+" ");
            System.out.println();
        }*/
        //System.out.println("B");
        // Solve
        int best = 0;
        for (int i = 0; i < N-1; i++) {
            flood(i);
            int yellowbest = 0;
            int greenbest = 0;
            for (int j = 0; j < N; j++)
                for (int k = 0; k < N; k++) {
                    if (color[j] == color[k] && color[k] == YELLOW)
                        yellowbest = Math.max(yellowbest, dist[j][k]);
                    if (color[j] == color[k] && color[k] == GREEN)
                        greenbest = Math.max(greenbest, dist[j][k]);
                }
           //System.out.println(i+" "+yellowbest+" "+greenbest);
           best = Math.max(best, yellowbest*greenbest);
        }
        //out.println("C");
        out.println(best);
		out.close();
	}
	
	private static class InputReader {
		private InputStream stream;
		private byte[] buf = new byte[1000];
		private int curChar, numChars;

		public InputReader(InputStream stream) {
			this.stream = stream;
		}

		private int read() {
			if (numChars == -1)
				throw new InputMismatchException();
			if (curChar >= numChars) {
				curChar = 0;
				try {
					numChars = stream.read(buf);
				} catch (IOException e) {
					throw new InputMismatchException();
				}
				if (numChars <= 0)
					return -1;
			}
			return buf[curChar++];
		}

		public int readInt() {
			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 long readLong() {
			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 String readString() {
			int c = read();
			while (isSpaceChar(c))
				c = read();
			StringBuffer res = new StringBuffer();
			do {
				res.appendCodePoint(c);
				c = read();
			} while (!isSpaceChar(c));
			return res.toString();
		}

		private boolean isSpaceChar(int c) {
			return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
		}

		private String readLine0() {
			StringBuffer buf = new StringBuffer();
			int c = read();
			while (c != '\n' && c != -1) {
				buf.appendCodePoint(c);
				c = read();
			}
			return buf.toString();
		}

		public String readLine() {
			String s = readLine0();
			while (s.trim().length() == 0)
				s = readLine0();
			return s;
		}

		public String readLine(boolean ignoreEmptyLines) {
			if (ignoreEmptyLines)
				return readLine();
			else
				return readLine0();
		}

		public BigInteger readBigInteger() {
			try {
				return new BigInteger(readString());
			} catch (NumberFormatException e) {
				throw new InputMismatchException();
			}
		}

		public char readCharacter() {
			int c = read();
			while (isSpaceChar(c))
				c = read();
			return (char) c;
		}

		public double readDouble() {
			int c = read();
			while (isSpaceChar(c))
				c = read();
			int sgn = 1;
			if (c == '-') {
				sgn = -1;
				c = read();
			}
			double res = 0;
			while (!isSpaceChar(c) && c != '.') {
				if (c < '0' || c > '9')
					throw new InputMismatchException();
				res *= 10;
				res += c - '0';
				c = read();
			}
			if (c == '.') {
				c = read();
				double m = 1;
				while (!isSpaceChar(c)) {
					if (c < '0' || c > '9')
						throw new InputMismatchException();
					m /= 10;
					res += (c - '0') * m;
					c = read();
				}
			}
			return res * sgn;
		}
	}
}
