#include <bits/stdc++.h>
using namespace std;
const int di[] = {-1, 0, 1, 0};
const int dj[] = {0, 1, 0, -1};
const long long MOD = 1e9 + 7;
const long long INF = 1e9;
const double EPS = 1e-11;
vector<vector<int> > adj;
int length(int cur, int prnt) {
  int ret = 0;
  for (int i = 0; i < adj[cur].size(); ++i)
    if (adj[cur][i] != prnt) ret = max(ret, length(adj[cur][i], cur));
  if (adj[cur].size() == 1) return 0;
  return ret + 1;
}
int diameter(int cur, int forb) {
  vector<int> ch;
  for (int i = 0; i < adj[cur].size(); ++i)
    if (adj[cur][i] != forb) ch.push_back(length(adj[cur][i], cur) + 1);
  sort(ch.rbegin(), ch.rend());
  int ret = 0;
  for (int i = 0; i < 2 && i < ch.size(); ++i) ret += ch[i];
  return ret;
}
int dfs(int cur, int prnt) {
  int ret = diameter(cur, prnt);
  for (int i = 0; i < adj[cur].size(); ++i)
    if (adj[cur][i] != prnt) ret = max(ret, dfs(adj[cur][i], cur));
  return ret;
}
int main() {
  ios::sync_with_stdio(false), cin.tie(0);
  int n;
  cin >> n;
  adj.assign(n, vector<int>());
  vector<pair<int, int> > e(n - 1);
  for (int i = 0; i < n - 1; ++i) {
    int u, v;
    cin >> u >> v;
    u--, v--;
    adj[u].push_back(v);
    adj[v].push_back(u);
    e[i] = make_pair(u, v);
  }
  int r = 0;
  for (int i = 0; i < n - 1; ++i) {
    int u = e[i].first, v = e[i].second;
    int d1 = dfs(u, v), d2 = dfs(v, u);
    r = max(r, d1 * d2);
  }
  cout << r << endl;
}
