#include <bits/stdc++.h>
using namespace std;
const int N = 5e5 + 105;
const int mod = 1e9 + 7;
const double Pi = acos(-1.0);
const int INF = 0x3f3f3f3f;
const int G = 3, Gi = 332748118;
long long qpow(long long a, long long b) {
  long long res = 1;
  while (b) {
    if (b & 1) res = (res * a) % mod;
    a = (a * a) % mod;
    b >>= 1;
  }
  return res;
}
long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }
int n;
int head[N], cnt = 0;
int to[N << 1], nxt[N << 1];
int up[N], dep[N], val1[N], val2[N];
int res = 0;
struct node {
  int val, si;
};
bool cmp(node a, node b) { return a.val > b.val; }
void add(int u, int v) {
  to[cnt] = v, nxt[cnt] = head[u], head[u] = cnt++;
  to[cnt] = u, nxt[cnt] = head[v], head[v] = cnt++;
}
void dfs1(int u, int pre) {
  int max1 = 0, max2 = 0;
  for (int i = head[u]; i != -1; i = nxt[i]) {
    int v = to[i];
    if (v == pre) continue;
    dfs1(v, u);
    val2[u] = max(val2[u], val2[v]);
    if (dep[v] + 1 > max1) {
      max2 = max1;
      max1 = dep[v] + 1;
    } else if (dep[v] + 1 > max2) {
      max2 = dep[v] + 1;
    }
  }
  dep[u] = max1;
  val2[u] = max(val2[u], max1 + max2);
}
void dfs2(int u, int pre) {
  vector<node> sol;
  int dep1 = 0, dep2 = 0, tdep = 0;
  int max1 = val1[pre], max2 = 0, tp = 0;
  for (int i = head[u]; i != -1; i = nxt[i]) {
    int v = to[i];
    if (v == pre) continue;
    if (dep[v] + 1 > dep1) {
      dep2 = dep1;
      dep1 = dep[v] + 1;
      tdep = v;
    } else if (dep[v] + 1 > dep2) {
      dep2 = dep[v] + 1;
    }
    sol.push_back((node){dep[v] + 1, v});
    if (val2[v] > max1) {
      max2 = max1;
      max1 = val2[v];
      tp = v;
    } else if (val2[v] > max2) {
      max2 = val2[v];
    }
  }
  sol.push_back((node){up[u], u});
  sort(sol.begin(), sol.end(), cmp);
  int tt = sol.size();
  for (int i = head[u]; i != -1; i = nxt[i]) {
    int v = to[i];
    if (v == pre) continue;
    if (v == tdep) {
      up[v] = 1 + max(up[u], dep2);
    } else {
      up[v] = 1 + max(up[u], 1 + dep1);
    }
    if (tt > 2) {
      int tval = 0;
      if (v == sol[0].si) {
        tval = sol[1].val + sol[2].val;
      } else if (v == sol[1].si) {
        tval = sol[0].val + sol[2].val;
      } else
        tval = sol[0].val + sol[1].val;
      val1[u] = tval;
    } else
      val1[u] = up[u];
    if (v == tp) {
      val1[u] = max(val1[u], max2);
    } else {
      val1[u] = max(val1[u], max1);
    }
    res = max(res, val2[v] * val1[u]);
    dfs2(v, u);
  }
}
int main() {
  scanf("%d", &n);
  cnt = 0;
  for (int i = 0; i <= n; ++i) head[i] = -1;
  for (int i = 1; i < n; ++i) {
    int x, y;
    scanf("%d%d", &x, &y);
    add(x, y);
  }
  dfs1(1, 0);
  dfs2(1, 0);
  printf("%d\n", res);
  return 0;
}
