#include <bits/stdc++.h>
using namespace std;
const double pi = 3.1415926535897932384626433832795;
vector<vector<int> > g;
vector<int> visited;
int n;
void dfs1(int k, int from) {
  visited[k] = true;
  for (int i = 0; i < (((int)(g[k]).size())); i++)
    if (g[k][i] != from) dfs1(g[k][i], k);
}
int dfs2(int k, int from, int doNot) {
  int ma = 0;
  for (int i = 0; i < (((int)(g[k]).size())); i++)
    if (g[k][i] != from && g[k][i] != doNot)
      ma = max(ma, dfs2(g[k][i], k, doNot));
  return ma + 1;
}
int getLongest(int k, int from) {
  visited.assign(n, false);
  dfs1(k, from);
  int ma = 0;
  for (int i = 0; i < (n); i++)
    if (visited[i]) ma = max(ma, dfs2(i, -1, from));
  return ma - 1;
}
int main() {
  cin >> n;
  g.resize(n);
  for (int i = 0; i < (n - 1); i++) {
    int x, y;
    cin >> x >> y;
    x--, y--;
    g[x].push_back(y);
    g[y].push_back(x);
  }
  int ma = 0;
  for (int i = 0; i < (n); i++)
    for (int j = 0; j < (((int)(g[i]).size())); j++) {
      int a = getLongest(g[i][j], i);
      int b = getLongest(i, g[i][j]);
      ma = max(ma, a * b);
    }
  cout << ma;
}
