#include <bits/stdc++.h>
using namespace std;
const int MOD = 1000000007;
struct Sync_stdio {
  Sync_stdio() {
    cin.tie(NULL);
    ios_base::sync_with_stdio(false);
  }
} _sync_stdio;
struct FAIL {
  FAIL() {
    cout << "CHANGE!!!"
         << "\n";
  }
};
vector<vector<int>> g;
vector<int> used1;
vector<int> used2;
vector<int> used3;
int maxc = 0;
int maxi = -1;
int res = 0;
int n;
void dfs3(int x, int h = 0) {
  used3[x] = 1;
  if (h >= maxc) {
    maxc = h;
    maxi = x;
  }
  for (auto i : g[x]) {
    if (used3[i]) {
      continue;
    }
    dfs3(i, h + 1);
  }
}
void dfs2(int x, int h = 0) {
  used2[x] = 1;
  used3[x] = 1;
  auto t = used3;
  vector<int> last(n, -1);
  for (int i = (0); i < (n); ++i) {
    if (!used3[i]) {
      maxc = -1;
      dfs3(i);
      last[i] = maxi;
    }
  }
  used3 = t;
  for (int i = (0); i < (n); ++i) {
    if (last[i] != -1) {
      maxc = -1;
      dfs3(last[i]);
      res = max(res, h * maxc);
    }
  }
  used3 = t;
  for (auto i : g[x]) {
    if (used2[i]) {
      continue;
    }
    dfs2(i, h + 1);
  }
  used3[x] = 0;
}
void dfs1(int x) {
  used1[x] = 1;
  used2.assign(n, 0);
  dfs2(x);
  for (auto i : g[x]) {
    if (used1[i]) {
      continue;
    }
    dfs1(i);
  }
}
int main() {
  cin >> n;
  g.resize(n);
  used1.resize(n);
  used2.resize(n);
  used3.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);
  }
  dfs1(0);
  cout << res;
}
