#include <bits/stdc++.h>
using namespace std;
int n;
vector<int> adj[100000];
vector<int> h[100000];
vector<int> dim[100000];
vector<int> inv[100000];
void calc(int v, int i) {
  if (dim[v][i] >= 0) return;
  h[v][i] = 0;
  dim[v][i] = 0;
  int u = adj[v][i];
  for (int j = 0; j < (int)adj[u].size(); j++)
    if (adj[u][j] != v) {
      calc(u, j);
      if (h[u][j] + 1 > dim[v][i]) dim[v][i] = h[u][j] + 1;
      if (dim[v][i] > h[v][i]) {
        int t = dim[v][i];
        dim[v][i] = h[v][i];
        h[v][i] = t;
      }
    }
  dim[v][i] += h[v][i];
  for (int j = 0; j < (int)adj[u].size(); j++)
    if (adj[u][j] != v)
      if (dim[u][j] > dim[v][i]) dim[v][i] = dim[u][j];
}
int main() {
  cin >> n;
  for (int i = 0; i < n - 1; i++) {
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    inv[a].push_back(adj[b].size());
    inv[b].push_back(adj[a].size());
    adj[a].push_back(b);
    dim[a].push_back(-1);
    h[a].push_back(-1);
    adj[b].push_back(a);
    dim[b].push_back(-1);
    h[b].push_back(-1);
  }
  long long ans = 0;
  for (int i = 0; i < n; i++)
    for (int j = 0; j < (int)adj[i].size(); j++)
      if (i < adj[i][j]) {
        calc(i, j);
        calc(adj[i][j], inv[i][j]);
        long long x = dim[i][j] * dim[adj[i][j]][inv[i][j]];
        if (x > ans) ans = x;
      }
  cout << ans;
  return 0;
}
