#include <bits/stdc++.h>
using namespace std;
const int MX = 1e5 + 10;
long long N;
int node, level;
vector<vector<int> > G(2000);
int par[2000];
void dfs_par(int u, int p) {
  par[u] = p;
  for (int i = 0; i < G[u].size(); i++) {
    int c = G[u][i];
    if (c != p) dfs_par(c, u);
  }
}
int dfs(int x, int p, int illg, int lev) {
  if (lev > level) {
    node = x;
    level = lev;
  }
  int l = 0;
  for (int i = 0; i < G[x].size(); i++) {
    int ch = G[x][i];
    if (ch == p || ch == illg) continue;
    l = max(l, 1 + dfs(ch, x, illg, lev + 1));
  }
  return l;
}
int main() {
  cin >> N;
  for (int i = 0; i < N - 1; i++) {
    int u, v;
    scanf("%d%d", &u, &v);
    G[u].push_back(v);
    G[v].push_back(u);
  }
  int ans = 0;
  dfs_par(1, -1);
  for (int i = 2; i <= N; i++) {
    level = 0;
    node = 0;
    int p1 = dfs(i, -1, par[i], 0);
    p1 = dfs(node, -1, par[i], 0);
    level = 0, node = 0;
    int p2 = dfs(1, -1, i, 0);
    p2 = dfs(node, -1, i, 0);
    ans = max(ans, p1 * p2);
  }
  cout << ans << "\n";
  return 0;
}
