#include <bits/stdc++.h>
using namespace std;
map<int, vector<int>> ma;
int fun(vector<bool>& v, int x, int& ans) {
  v[x] = true;
  priority_queue<int> q;
  q.push(0);
  q.push(0);
  int l = 0;
  for (int i = 0; i < (int)ma[x].size(); i++) {
    int h = ma[x][i];
    if (v[h]) continue;
    int k = 1 + fun(v, h, ans);
    q.push(k);
    l = max(l, k);
  }
  int a = q.top();
  q.pop();
  int b = q.top();
  q.pop();
  ans = max(ans, a + b);
  return l;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int n;
  cin >> n;
  vector<pair<int, int>> v;
  for (int i = 1; i < n; i++) {
    int x, y;
    cin >> x >> y;
    v.push_back({x, y});
    ma[x].push_back(y);
    ma[y].push_back(x);
  }
  int ans = 0;
  for (int i = 0; i < n - 1; i++) {
    vector<bool> vi1(n + 1, false), vi2(n + 1, false);
    vi1[v[i].first] = true;
    vi2[v[i].second] = true;
    int ans1 = 0, ans2 = 0;
    int l1 = fun(vi2, v[i].first, ans1);
    int l2 = fun(vi1, v[i].second, ans2);
    ans = max(ans, ans1 * ans2);
  }
  cout << ans << "\n";
}
