#include <bits/stdc++.h>
using namespace std;
long long int ans, dia, dia1;
vector<set<long long int>> adj((long long int)(2e5 + 5));
vector<long long int> dp((long long int)(2e5 + 5));
void dfs(long long int c, long long int pre) {
  long long int mx = -1;
  for (auto x : adj[c]) {
    if (x == pre) continue;
    dfs(x, c);
    dia = max(dia, dp[x] + mx + 2);
    mx = max(mx, dp[x]);
    dp[c] = max(dp[c], dp[x] + 1);
  }
}
void solve() {
  long long int n;
  cin >> n;
  vector<pair<long long int, long long int>> d(n - 1);
  for (long long int i = 1; i < n; i++) {
    long long int u, v;
    cin >> u >> v;
    adj[u].insert(v);
    adj[v].insert(u);
    d[i - 1] = {u, v};
  }
  for (long long int i = 0; i < n - 1; i++) {
    long long int a = d[i].first;
    long long int b = d[i].second;
    adj[a].erase(b);
    adj[b].erase(a);
    dfs(a, 0);
    swap(dia, dia1);
    dia = 0;
    dfs(b, 0);
    ans = max(ans, dia * dia1);
    dia = 0;
    dia1 = 0;
    adj[a].insert(b);
    adj[b].insert(a);
    fill(dp.begin(), dp.end(), 0);
  }
  cout << ans;
}
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long int t = 1;
  while (t--) solve();
  return 0;
}
