#include <bits/stdc++.h>
using namespace std;
int visited[505], dp[505];
int d, x, y, flag;
vector<int> vec[505];
vector<pair<int, int> > adj;
int var[505];
void dfs(int u, int dist) {
  visited[u] = 1;
  d = max(d, dist);
  for (int i = 0; i < vec[u].size(); i++) {
    if ((u == x && vec[u][i] == y) || (u == y && vec[u][i] == x)) continue;
    if (!visited[vec[u][i]]) {
      dfs(vec[u][i], dist + 1);
    }
  }
}
int main() {
  int n, ans = 0, fin = 0, temp;
  cin >> n;
  flag = 1;
  for (int i = 0; i < n - 1; i++) {
    scanf("%d %d", &x, &y);
    vec[x].push_back(y);
    vec[y].push_back(x);
    adj.push_back(make_pair(x, y));
  }
  for (int i = 0; i < adj.size(); i++) {
    x = adj[i].first, y = adj[i].second;
    ans = 0;
    memset(var, 0, sizeof(var));
    memset(visited, 0, sizeof(visited));
    d = 0;
    dfs(x, 0);
    for (int j = 1; j <= n; j++) {
      if (visited[j]) {
        var[j] = 1;
      }
    }
    for (int j = 1; j <= n; j++) {
      if (var[j]) {
        d = 0;
        memset(visited, 0, sizeof(visited));
        dfs(j, 0);
        ans = max(ans, d);
      }
    }
    memset(visited, 0, sizeof(visited));
    dfs(y, 0);
    memset(var, 0, sizeof(var));
    for (int j = 1; j <= n; j++) {
      if (visited[j]) {
        var[j] = 1;
      }
    }
    temp = 0;
    for (int j = 1; j <= n; j++) {
      if (var[j]) {
        d = 0;
        memset(visited, 0, sizeof(visited));
        dfs(j, 0);
        temp = max(temp, d);
      }
    }
    ans *= temp;
    fin = max(fin, ans);
  }
  cout << fin;
}
