#include <bits/stdc++.h>
using namespace std;
struct edge {
  int next, to, w, from;
} e[3005 << 1];
int head[3005], cnt, maxx = 0, st, ans1, ans2, ans;
inline void add(int x, int y) {
  e[++cnt].next = head[x];
  e[cnt].to = y;
  e[cnt].from = x;
  e[cnt].w = 1;
  head[x] = cnt;
}
bool vis[3005];
int dis[3005], n;
inline void bfs(int x) {
  queue<int> q;
  maxx = 0;
  st = x;
  memset(dis, 0, sizeof(dis));
  memset(vis, 0, sizeof(vis));
  q.push(x);
  vis[x] = 1;
  while (!q.empty()) {
    int u = q.front();
    q.pop();
    for (int i = head[u]; i; i = e[i].next) {
      int v = e[i].to;
      if (!vis[v] && e[i].w != 0) {
        dis[v] = dis[u] + e[i].w;
        vis[v] = 1;
        q.push(v);
      }
    }
  }
  for (int i = 1; i <= n; i++) {
    if (dis[i] > maxx) {
      maxx = dis[i];
      st = i;
    }
  }
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i < n; i++) {
    int u, v;
    scanf("%d%d", &u, &v);
    add(u, v);
    add(v, u);
  }
  for (int i = 1; i < cnt; i += 2) {
    e[i].w = 0;
    e[++i].w = 0;
    i--;
    maxx = 0;
    bfs(e[i].from);
    bfs(st);
    ans1 = maxx;
    bfs(e[i].to);
    bfs(st);
    ans2 = maxx;
    ans = max(ans, ans1 * ans2);
    e[i].w = 1;
    e[++i].w = 1;
    i--;
  }
  printf("%d", ans);
  return 0;
}
