#include <bits/stdc++.h>
using namespace std;
void load() {}
const int N = 1e5 + 12;
int f[N], g[N], dp[N], tmp[N], n, cnt, cs[N], mx[N], mn[N], r[N], l[N], r_1[N],
    l_1[N];
vector<int> ed[N];
long long res;
void dfs_1(int u, int p) {
  f[u] = 0;
  dp[u] = 0;
  for (int v : ed[u]) {
    if (v == p) continue;
    cs[v] = ++cnt;
    if (mn[u] == 0) mn[u] = cs[v];
    mx[u] = max(mx[u], cs[v]);
  }
  for (int v : ed[u]) {
    if (v == p) continue;
    dfs_1(v, u);
    dp[u] = max(dp[u], dp[v]);
    dp[u] = max(dp[u], f[u] + f[v] + 1);
    f[u] = max(f[u], f[v] + 1);
  }
  for (int i = 0; i < ed[u].size(); ++i) {
    int v = ed[u][i];
    if (v == p) continue;
    l[cs[v]] = l[cs[v] - 1];
    if (cs[v] == mn[u]) l[cs[v]] = f[v];
    l_1[cs[v]] = 0;
    if (cs[v] > mn[u])
      l_1[cs[v]] = max(l_1[cs[v] - 1], l[cs[v] - 1] + 2 + f[v]);
    l[cs[v]] = max(l[cs[v]], f[v]);
  }
  for (int i = ed[u].size() - 1; i >= 0; --i) {
    int v = ed[u][i];
    if (v == p) continue;
    r[cs[v]] = r[cs[v] + 1];
    if (cs[v] == mx[u]) r[cs[v]] = f[v];
    r_1[cs[v]] = 0;
    if (cs[v] < mx[u])
      r_1[cs[v]] = max(r_1[cs[v] + 1], r[cs[v] + 1] + f[v] + 2);
    r[cs[v]] = max(r[cs[v]], f[v]);
  }
  return;
}
void dfs_2(int u, int p, int typ) {
  tmp[u] = g[u];
  if (typ == 0) {
    for (int i = 0; i < ed[u].size(); ++i) {
      int v = ed[u][i];
      if (v == p) continue;
      g[v] = max(g[v], tmp[u] + 1);
      dfs_2(v, u, typ);
      tmp[u] = max(tmp[u], f[v] + 1);
    }
    return;
  }
  for (int i = ed[u].size() - 1; i >= 0; --i) {
    int v = ed[u][i];
    if (v == p) continue;
    g[v] = max(g[v], tmp[u] + 1);
    dfs_2(v, u, typ);
    tmp[u] = max(tmp[u], f[v] + 1);
  }
  return;
}
void calc(int u, int p, int val) {
  res = max(res, 1LL * dp[u] * val);
  for (int i = 0; i < ed[u].size(); ++i) {
    int v = ed[u][i];
    if (v == p) continue;
    int tg = max(val, g[u]);
    if (cs[v] > mn[u]) tg = max(tg, l[cs[v] - 1] + g[u] + 1);
    if (cs[v] < mx[u]) tg = max(tg, r[cs[v] + 1] + g[u] + 1);
    if (cs[v] > mn[u] && cs[v] < mx[u])
      tg = max(tg, r[cs[v] + 1] + l[cs[v] - 1] + 2);
    if (cs[v] - 1 > mn[u]) tg = max(tg, l_1[cs[v] - 1]);
    if (cs[v] + 1 < mx[u]) tg = max(tg, r_1[cs[v] + 1]);
    calc(v, u, tg);
  }
}
void trungtt() {
  int n;
  scanf("%d", &n);
  for (int i = 1; i < n; ++i) {
    int u, v;
    scanf("%d%d", &u, &v);
    ed[u].push_back(v);
    ed[v].push_back(u);
  }
  res = 0;
  cnt = 1;
  cs[1] = 1;
  dfs_1(1, 0);
  dfs_2(1, 0, 0);
  dfs_2(1, 0, 1);
  calc(1, 0, -1);
  printf("%lld", res);
}
int main() {
  load();
  trungtt();
  return 0;
}
