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.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.io.BufferedWriter;
import java.io.Writer;
import java.io.OutputStreamWriter;
import java.util.InputMismatchException;
import java.io.IOException;
import java.util.ArrayList;
import java.io.InputStream;
/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        OutputWriter out = new OutputWriter(outputStream);
        TaskD solver = new TaskD();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskD {
        int INF = 1000 * 1000 * 1000;
        ArrayList<Integer>[] adj;

        public void solve(int testNumber, InputReader in, OutputWriter out) {
            int n = in.readInt();
            adj = new ArrayList[n];
            for (int i = 0; i < adj.length; i++) adj[i] = new ArrayList<>();
            for (int i = 0; i < n - 1; i++) {
                int a = in.readInt() - 1, b = in.readInt() - 1;
                adj[a].add(b);
                adj[b].add(a);
            }
            int res = 0;
            boolean[] onPath = new boolean[n], visited = new boolean[n];
            int[] queue = new int[n], fromA = new int[n];
            for (int a = 0; a < n; a++) {
                for (int b = a + 1; b < n; b++) {
                    if (adj[a].size() > 1 && adj[b].size() > 1) continue;
                    Arrays.fill(onPath, false);
                    Arrays.fill(visited, false);
                    int firstEdgeLength = dist(a, b, onPath, queue, fromA);
                    int secondEdgeLength = 0;
                    for (int start = 0; start < n; start++) {
                        if (!onPath[start] && !visited[start]) {
                            int furthestVertex = furthestVertex2(start, onPath, visited, queue, fromA);
                            if (furthestVertex == -1) continue;
                            secondEdgeLength = Math.max(secondEdgeLength, furthestDist(furthestVertex, -1, onPath));
                        }
                    }
                    res = Math.max(res, firstEdgeLength * secondEdgeLength);
                }
            }
            out.printLine(res);
        }

        int furthestVertex2(int start, boolean[] cant, boolean[] visited, int[] queue, int[] fromStart) {
            int queueSize = 0;
            Arrays.fill(fromStart, INF);
            fromStart[start] = 0;
            visited[start] = true;
            queue[queueSize++] = start;
            int maxDist = 0, res = -1;
            for (int frontPtr = 0; frontPtr < queueSize; frontPtr++) {
                int cur = queue[frontPtr];
                for (int nxt : adj[cur]) {
                    if (fromStart[nxt] == INF && !cant[nxt]) {
                        queue[queueSize++] = nxt;
                        visited[nxt] = true;
                        fromStart[nxt] = fromStart[cur] + 1;
                        if (fromStart[nxt] > maxDist) {
                            maxDist = fromStart[nxt];
                            res = nxt;
                        }
                    }
                }
            }
            return res;
        }

        int furthestDist(int cur, int prev, boolean[] cant) {
            int res = 0;
            for (int nxt : adj[cur]) {
                if (nxt != prev && !cant[nxt]) {
                    res = Math.max(res, 1 + furthestDist(nxt, cur, cant));
                }
            }
            return res;
        }

        private int dist(int a, int b, boolean[] onPath, int[] queue, int[] fromA) {
            int queueSize = 0;
            Arrays.fill(fromA, INF);
            fromA[a] = 0;
            queue[queueSize++] = a;
            for (int frontPtr = 0; frontPtr < queueSize; frontPtr++) {
                int cur = queue[frontPtr];
                for (int nxt : adj[cur]) {
                    if (fromA[nxt] == INF) {
                        queue[queueSize++] = nxt;
                        fromA[nxt] = fromA[cur] + 1;
                    }
                }
            }
            int dist = fromA[b];
            int cur = b;
            while (cur != a) {
                onPath[cur] = true;
                int n = -1;
                for (int nxt : adj[cur]) {
                    if (fromA[nxt] == dist - 1) {
                        n = nxt;
                        break;
                    }
                }
                dist--;
                cur = n;
            }
            onPath[a] = true;
            return fromA[b];
        }
    }
    static class OutputWriter {
        private final PrintWriter writer;

        public OutputWriter(OutputStream outputStream) {
            writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));
        }

        public OutputWriter(Writer writer) {
            this.writer = new PrintWriter(writer);
        }

        public void close() {
            writer.close();
        }

        public void printLine(int i) {
            writer.println(i);
        }
    }
    static class InputReader {
        private InputStream stream;
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;
        private InputReader.SpaceCharFilter filter;

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

        public 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 boolean isSpaceChar(int c) {
            if (filter != null) {
                return filter.isSpaceChar(c);
            }
            return isWhitespace(c);
        }

        public static boolean isWhitespace(int c) {
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

        public interface SpaceCharFilter {
            public boolean isSpaceChar(int ch);
        }
    }
}

