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.util.*;

public class Main {
    public static void main(String[] args) throws IOException {
        InputStream inputStream = System.in;
//        InputStream inputStream = new FileInputStream("sum.in");
        OutputStream outputStream = System.out;
//        OutputStream outputStream = new FileOutputStream("sum.out");


//        Path path = Paths.get(URI.create("file:///foo/bar/Main.java"));
//        System.out.print(path.getName(200));

//        Path p = Paths.get("/foo/bar/Main.java");
//        for (Path e : p) {
//            System.out.println(e);
//        }

        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        Answer solver = new Answer();
        solver.solve(in, out);
        out.close();
    }
}

class Answer {
    private final int INF = (int) (1e9 + 7);
    private final int MOD = (int) (1e9 + 7);
    private final int MOD1 = (int) (1e6 + 3);
    private final long INF_LONG = (long) (1e18 + 1);
    private final double EPS = 1e-9;

    private List<Integer>[] G;
    private boolean[] isList;
    private boolean[] visited;
    private int[] d;

    private class Edge {
        int a;
        int b;

        public Edge(int a, int b) {
            this.a = a;
            this.b = b;
        }
    }

    private void getListC(int u, Edge e, Set<Integer> listsC) {
        visited[u] = true;
        if (isList[u]) {
            listsC.add(u);
        }
        for (Integer v : G[u]) {
            if (e.a == u && e.b == v) {
                continue;
            }
            if (e.a == v && e.b == u) {
                continue;
            }

            if (!visited[v]) {
                getListC(v, e, listsC);
            }
        }
    }

    private void dfs(int u, Edge e) {
        visited[u] = true;
        for (Integer v : G[u]) {
            if (e.a == u && e.b == v) {
                continue;
            }
            if (e.a == v && e.b == u) {
                continue;
            }

            if (!visited[v]) {
                d[v] = d[u] + 1;
                dfs(v, e);
            }
        }
    }

    private int getMaxDest(Set<Integer> listsC, Edge e, int n) {
        int maxDest = 0;

        for (Integer list : listsC) {
            visited = new boolean[n + 1];
            d = new int[n + 1];
            dfs(list, e);

            for (int i = 1; i <= n; i++) {
                maxDest = Math.max(maxDest, d[i]);
            }
        }

        return maxDest;
    }

    public void solve(InputReader in, PrintWriter out) throws IOException {
        int n = in.nextInt();

        d = new int[n + 1];
        isList = new boolean[n + 1];
        G = new List[n + 1];
        for (int i = 1; i <= n; i++) {
            G[i] = new ArrayList<>();
        }

        List<Edge> edges = new ArrayList<>();

        for (int i = 0; i < n - 1; i++) {
            int a = in.nextInt();
            int b = in.nextInt();

            G[a].add(b);
            G[b].add(a);
            edges.add(new Edge(a, b));
        }

        for (int i = 1; i <= n; i++) {
            if (G[i].size() == 1) {
                isList[i] = true;
            }
        }

        int ans = 0;

        for (Edge edge : edges) {
//            out.println(edge.a + " " + edge.b);

            visited = new boolean[n + 1];

            Set<Integer> listsC1 = new HashSet<>();
            Set<Integer> listsC2 = new HashSet<>();

            getListC(1, edge, listsC1);

            for (int i = 1; i <= n; i++) {
                if (isList[i] && !visited[i]) {
                    getListC(i, edge, listsC2);
                }
            }

//            out.print("listC1: ");
//            for (Integer list : listsC1) {
//                out.print(list + " ");
//            }
//            out.println();
//            out.print("listC2: ");
//            for (Integer list : listsC2) {
//                out.print(list + " ");
//            }
//            out.println();


            int x = getMaxDest(listsC1, edge, n);
            int y = getMaxDest(listsC2, edge, n);
            ans = Math.max(ans, x * y);


//            out.println(x + " " + y);
//            out.println("---------------------------------");
        }

        out.print(ans);

    }
}

class InputReader {
    private BufferedReader reader;
    private StringTokenizer tokenizer;

    InputReader(InputStream stream) {
        reader = new BufferedReader(new InputStreamReader(stream), 32768);
        tokenizer = null;
    }

    public String next() {
        while (tokenizer == null || !tokenizer.hasMoreTokens()) {
            try {
                tokenizer = new StringTokenizer(reader.readLine());
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return tokenizer.nextToken();
    }

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

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

    public int[] nextArrayInt(int count) {
        int[] a = new int[count];
        for (int i = 0; i < count; i++) {
            a[i] = nextInt();
        }
        return a;
    }

    public long[] nextArrayLong(int count) {
        long[] a = new long[count];
        for (int i = 0; i < count; i++) {
            a[i] = nextLong();
        }
        return a;
    }
}
