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
// codeforces 14D with larger limits

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;

public class Main {

    private FastScanner in;
    private PrintWriter out;

    class Graph {

        class Node {

            //zero-based
            final int index;
            Node[] edges;
            int size;
            int capacity;
            Node parent;
            int height;
            int longestPath; // in subtree
            Node maxPathChild1 = null;
            Node maxPathChild2 = null;
            Node maxHeightChild1 = null;
            Node maxHeightChild2 = null;
            Node maxHeightChild3 = null;

            int maxLineUp;
            int maxPathUp;

            Node(int index) {
                this.index = index;
                capacity = 4;
                edges = new Node[capacity];
            }

            @Override
            public String toString() {
                return Integer.toString(index + 1);
            }

            void addEdge(Node node) {
                if (size == capacity) {
                    Node[] newArray = new Node[2 * capacity];
                    System.arraycopy(edges, 0, newArray, 0, capacity);
                    edges = newArray;
                    capacity *= 2;
                }
                edges[size++] = node;
            }

            void calculateHeightAndPath() {
                if (parent != null && edges.length == 1) {
                    height = 0;
                    longestPath = 0;
                    return;
                }

                for (Node node : edges) {
                    if (node == parent) {
                        continue;
                    }
                    node.calculateHeightAndPath();
                    if (maxHeightChild1 == null || node.height >= maxHeightChild1.height) {
                        maxHeightChild3 = maxHeightChild2;
                        maxHeightChild2 = maxHeightChild1;
                        maxHeightChild1 = node;
                    } else if (maxHeightChild2 == null || node.height >= maxHeightChild2.height) {
                        maxHeightChild3 = maxHeightChild2;
                        maxHeightChild2 = node;
                    } else if (maxHeightChild3 == null || node.height >= maxHeightChild3.height) {
                        maxHeightChild3 = node;
                    }
                    if (maxPathChild1 == null || node.longestPath >= maxPathChild1.longestPath) {
                        maxPathChild2 = maxPathChild1;
                        maxPathChild1 = node;
                    } else if (maxPathChild2 == null || node.longestPath >= maxPathChild2.longestPath) {
                        maxPathChild2 = node;
                    }
                }

                height = maxHeightChild1.height + 1;
                longestPath = maxPathChild1.longestPath;
                if (edges.length <= 2) {
                    //one child
                    if (1 + maxHeightChild1.height > longestPath) {
                        longestPath = 1 + maxHeightChild1.height;
                    }
                } else {
                    // 2 or more children
                    if (2 + maxHeightChild1.height + maxHeightChild2.height > longestPath) {
                        longestPath = 2 + maxHeightChild1.height + maxHeightChild2.height;
                    }
                }
            }

            void calculateUp() {
                if (parent == null) {
                    maxLineUp = 0;
                    maxPathUp = 0;
                } else {
                    maxLineUp = parent.maxLineUp + 1;
                    for (Node node : parent.edges) {
                        if (node == parent.parent || node == this) {
                            continue;
                        }
                        if (2 + node.height > maxLineUp) {
                            maxLineUp = 2 + node.height;
                        }
                    }
                    maxPathUp = parent.maxPathUp;
                    int parentMaxHeightChild = parent.maxHeightChild1.height + 1;
                    if (parent.maxHeightChild1 == this) {
                        if (parent.maxHeightChild2 != null) {
                            parentMaxHeightChild = parent.maxHeightChild2.height + 1;
                        } else {
                            parentMaxHeightChild = 0;
                        }
                    }
                    if (parent.maxLineUp + parentMaxHeightChild > maxPathUp) {
                        maxPathUp = parent.maxLineUp + parentMaxHeightChild;
                    }
                    int parentMaxPathChild = parent.maxPathChild1.longestPath;
                    if (parent.maxPathChild1 == this) {
                        if (parent.maxPathChild2 != null) {
                            parentMaxPathChild = parent.maxPathChild2.longestPath;
                        } else {
                            parentMaxPathChild = 0;
                        }
                    }
                    if (parentMaxPathChild > maxPathUp) {
                        maxPathUp = parentMaxPathChild;
                    }
                    if ((parent.parent == null && parent.edges.length >= 3) ||
                            parent.edges.length >= 4) {
                        int parentTwoHeight = 2 + parent.maxHeightChild1.height +
                                parent.maxHeightChild2.height;
                        if (this == parent.maxHeightChild1 || this == parent.maxHeightChild2) {
                            parentTwoHeight = parentTwoHeight - height +
                                    parent.maxHeightChild3.height;
                        }
                        if (parentTwoHeight > maxPathUp) {
                            maxPathUp = parentTwoHeight;
                        }
                    }
                }

                for (Node node : edges) {
                    if (node == parent) {
                        continue;
                    }
                    node.calculateUp();
                }
            }

            long max() {
                long res = longestPath;
                res *= maxPathUp;

                for (Node node : edges) {
                    if (node == parent) {
                        continue;
                    }
                    long m = node.max();
                    if (m > res) {
                        res = m;
                    }
                }
                return res;
            }
        }

        final int n;
        final Node[] nodes;
        Node root;

        Graph(int n) {
            this.n = n;
            nodes = new Node[n];
            for (int i = 0; i < n; i++) {
                nodes[i] = new Node(i);
            }
        }

        // zero-based
        void addEdge(int a, int b) {
            nodes[a].addEdge(nodes[b]);
            nodes[b].addEdge(nodes[a]);
        }

        void toTree() {
            root = nodes[0];
            initParent(root, null);
        }

        void initParent(Node node, Node parent) {
            node.parent = parent;
            for (Node edge : node.edges) {
                if (edge != parent) {
                    initParent(edge, node);
                }
            }
        }

        void calculateHeightAndPath() {
            root.calculateHeightAndPath();
        }

        void calculateUp() {
            root.calculateUp();
        }

        long max() {
            return root.max();
        }

        void cutArrays() {
            for (int i = 0; i < n; i++) {
                Node[] newArray = new Node[nodes[i].size];
                System.arraycopy(nodes[i].edges, 0, newArray, 0, nodes[i].size);
                nodes[i].edges = newArray;
                nodes[i].capacity = nodes[i].size;
            }
        }
    }

    public void solve() throws IOException {
        int n = in.nextInt();
        Graph g = new Graph(n);
        for (int i = 0; i < n - 1; i++) {
            g.addEdge(in.nextInt() - 1, in.nextInt() - 1);
        }
        g.cutArrays();
        g.toTree();
        g.calculateHeightAndPath();
        g.calculateUp();
        out.println(g.max());
    }

    public void run() {
        try {
            in = new FastScanner(System.in);
            out = new PrintWriter(System.out);
            solve();
            out.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    class FastScanner {

        BufferedReader br;
        StringTokenizer st;

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

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

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

    public static void main(String[] arg) {
        new Main().run();
    }
}