#include <bits/stdc++.h>
using namespace std;
vector<vector<int> > g;
vector<pair<int, int> > e;
int n;
int bfs(int s, int& dist) {
  queue<int> q;
  q.push(s);
  vector<int> pr(n), d(n, 0);
  pr[s] = -1;
  while (!q.empty()) {
    int second = q.front(), to;
    q.pop();
    for (int i = 0; i < n; i++)
      if (g[second][i] == 1 && i != pr[second]) {
        to = i;
        q.push(to);
        d[to] = d[second] + 1;
        pr[to] = second;
      }
  }
  int second = s;
  for (int i = 0; i < n; i++)
    for (int i = 0; i < n; i++)
      if (d[i] > d[second]) second = i, dist = d[i];
  return second;
}
int main() {
  cin >> n;
  e.resize(n);
  g.assign(n, vector<int>(n, 0));
  for (int i = 0; i < n - 1; i++) {
    int first, second;
    cin >> first >> second;
    first--, second--;
    e[i] = pair<int, int>(first, second);
    g[first][second] = g[second][first] = 1;
  }
  int res = 0;
  for (int i = 0; i < n - 1; i++) {
    int d1 = 0, d2 = 0, first = e[i].first, second = e[i].second;
    g[first][second] = g[second][first] = 0;
    first = bfs(first, d1), second = bfs(second, d2);
    bfs(first, d1), bfs(second, d2);
    res = max(res, d1 * d2);
    g[e[i].first][e[i].second] = g[e[i].second][e[i].first] = 1;
  }
  cout << res;
  return 0;
}
