#include <bits/stdc++.h>
using namespace std;
const double eps = 1e-10;
const double pi = acos(-1.0);
const int inf = 0x3f3f3f3f;
const int M = 3000;
const int N = 3000;
struct edge {
  int next, v;
} e[M];
int head[N], tot, ans;
int have[N];
void init() {
  memset(head, 0, sizeof(head));
  tot = 1;
  memset(have, 0, sizeof(have));
  ans = 0;
}
void add(int u, int v) {
  e[tot].v = v;
  e[tot].next = head[u];
  head[u] = tot++;
}
int n;
int ra[N], rb[N];
int zzz;
int dff(int x, int fa) {
  int i, j, t = 1;
  int r1 = 0, r2 = 0;
  for (i = head[x]; i; i = e[i].next) {
    int tp = e[i].v;
    if (tp != fa) {
      int tmp = 1 + dff(tp, x);
      if (tmp > r1) {
        swap(r1, tmp);
      }
      if (tmp > r2) {
        swap(r2, tmp);
      }
    }
  }
  zzz = max(zzz, r1 + r2);
  return max(r1, r2);
}
int main() {
  int a, b, i, j, t;
  scanf("%d", &n);
  init();
  for (i = 0; i < n - 1; i++) {
    scanf("%d%d", &a, &b);
    ra[i] = a;
    rb[i] = b;
    add(a, b);
    add(b, a);
  }
  ans = 0;
  for (i = 0; i < n - 1; i++) {
    zzz = 0;
    int x4, x5;
    dff(ra[i], rb[i]);
    x4 = zzz;
    zzz = 0;
    dff(rb[i], ra[i]);
    x5 = zzz;
    ans = max(ans, x4 * x5);
  }
  printf("%d\n", ans);
}
