#include <bits/stdc++.h>
using namespace std;
vector<vector<int>> adj;
vector<pair<int, int>> edges;
vector<int> visited;
int far;
int dis = 0;
void dfs(int u, int val, int cur) {
  visited[u] = 1;
  if (dis <= cur) {
    dis = cur;
    far = u;
  }
  for (auto i : adj[u]) {
    if (!visited[i] && val != i) dfs(i, val, cur + 1);
  }
}
int discal(int u, int val) {
  visited[u] = 1;
  int ma = 0;
  for (auto i : adj[u]) {
    if (!visited[i] && val != i) {
      ma = max(ma, 1 + discal(i, val));
    }
  }
  return ma;
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  ;
  int n;
  cin >> n;
  adj = vector<vector<int>>(n + 1);
  for (int i = 0; i < n - 1; i++) {
    int x, y;
    cin >> x >> y;
    adj[x].push_back(y);
    adj[y].push_back(x);
    edges.push_back({x, y});
  }
  int ans = 0;
  for (auto i : edges) {
    int x, y;
    visited = vector<int>(n + 1);
    tie(x, y) = i;
    dfs(x, y, 0);
    dis = 0;
    visited = vector<int>(n + 1);
    int ans1 = discal(far, y);
    visited = vector<int>(n + 1);
    dfs(y, x, 0);
    dis = 0;
    visited = vector<int>(n + 1);
    int ans2 = discal(far, x);
    ans = max(ans, ans2 * ans1);
  }
  cout << ans << "\n";
  return 0;
}
