#include <bits/stdc++.h>
using namespace std;
inline int two(int n) { return 1 << n; }
inline int test(int n, int b) { return (n >> b) & 1; }
inline void set_bit(int& n, int b) { n |= two(b); }
inline void unset_bit(int& n, int b) { n &= ~two(b); }
inline int last_bit(int n) { return n & (-n); }
inline int ones(int n) {
  int res = 0;
  while (n && ++res) n -= n & (-n);
  return res;
}
vector<int> G[500];
int lx[500], rx[500];
int p = 0;
int dfs(int node, int par) {
  int max_1 = 0, max_2 = 0;
  for (int i = 0; i < G[node].size(); i++) {
    int curr = G[node][i];
    if (curr == par) continue;
    int tmp = dfs(curr, node) + 1;
    if (tmp > max_2) max_2 = tmp;
    if (max_1 < max_2) swap(max_1, max_2);
  }
  p = max(max_2 + max_1, p);
  return max_1;
}
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 0; i < n - 1; i++) {
    int x, y;
    scanf("%d", &x);
    scanf("%d", &y);
    x--, y--;
    lx[i] = x;
    rx[i] = y;
    G[x].push_back(y);
    G[y].push_back(x);
  }
  int ans = 0;
  for (int i = 0; i < n - 1; i++) {
    int x = 1;
    p = 0;
    dfs(lx[i], rx[i]);
    x *= p;
    p = 0;
    dfs(rx[i], lx[i]);
    x *= p;
    ans = max(ans, x);
  }
  cout << ans << endl;
  return 0;
}
