#include <bits/stdc++.h>
using namespace std;
const int MaxN = 2e3 + 5;
const int INF = 1e9 + 2;
const long long Mod = 1e9 + 7;
int n, a, b, ans, d, ve;
bool u[MaxN];
vector<int> g[MaxN];
int len(int v, int nv, int p, int lv) {
  int d = lv;
  for (int i = 0; i < g[v].size(); ++i)
    if (g[v][i] != nv && g[v][i] != p) d = max(d, len(g[v][i], nv, v, lv + 1));
  return d;
}
int last(int v, int nv, int p = -1, int l = 0) {
  if (l > d) {
    d = l;
    ve = v;
  }
  for (int i = 0; i < g[v].size(); ++i)
    if (g[v][i] != p and g[v][i] != nv) last(g[v][i], nv, v, l + 1);
  return ve;
}
void dfs(int v) {
  u[v] = 1;
  for (int i = 0; i < g[v].size(); ++i) {
    if (!u[g[v][i]]) {
      d = ve = 0;
      int l1 = last(v, g[v][i]);
      d = ve = 0;
      int l2 = last(g[v][i], v);
      ans = max(ans, len(l1, g[v][i], -1, 0) * len(l2, v, -1, 0));
      dfs(g[v][i]);
    }
  }
}
int main() {
  scanf("%d", &n);
  ;
  for (int i = 1; i < n; ++i) {
    cin >> a >> b;
    g[a].push_back(b);
    g[b].push_back(a);
  }
  dfs(1);
  cout << ans;
  return 0;
}
