#include <bits/stdc++.h>
using namespace std;
const int INF = (int)1e9 + 123;
const long long LINF = (long long)1e18 + 123;
const long double EPS = (long double)1e-8;
const long long MOD = (long long)1e9 + 7;
long long power(long long x, long long y, long long mod = MOD) {
  if (y == 0) {
    return 1;
  }
  if (y & 1) {
    return power(x, y - 1, mod) * x % mod;
  } else {
    long long tmp = power(x, y / 2, mod);
    return tmp * tmp % mod;
  }
}
inline void add(long long &x, long long y, long long mod = MOD) {
  x += y;
  if (x >= mod) x -= mod;
  if (x < 0) x += mod;
}
inline long long sum(long long x, long long y, long long mod = MOD) {
  add(x, y, mod);
  return x;
}
inline long long mult(long long x, long long y, long long mod = MOD) {
  return (x * y) % mod;
}
inline long long div(long long x, long long y, long long mod) {
  return x * power(y, mod - 2, mod);
}
template <typename A, typename B>
inline bool mini(A &x, const B &y) {
  if (y < x) {
    x = y;
    return true;
  }
  return false;
}
template <typename A, typename B>
inline bool maxi(A &x, const B &y) {
  if (y > x) {
    x = y;
    return true;
  }
  return false;
}
template <typename T>
inline void read(T first, T last) {
  while (first != last) {
    cin >> *(first++);
  }
}
template <typename T>
inline void print(T first, T last) {
  while (first != last) {
    cout << *(first++) << " ";
  }
  cout << "\n";
}
void run();
int main() {
  if (strlen("")) {
    freopen(
        ""
        ".in",
        "r", stdin);
    freopen(
        ""
        ".out",
        "w", stdout);
  }
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cout << fixed << setprecision(15);
  run();
  return 0;
}
const int N = (int)1e6 + 123;
int n;
int a[N];
vector<int> p[N];
long long f(long long k) { return k * (k + 1) / 2; }
void run() {
  cin >> n;
  for (auto i = 0; i < N; i++) p[i].push_back(0);
  for (auto i = 1; i < n + 1; i++) {
    cin >> a[i];
    p[a[i]].push_back(i);
  }
  for (auto i = 0; i < N; i++) p[i].push_back(n + 1);
  long double sum = -n;
  for (auto v = 0; v < N; v++) {
    if ((int)(p[v]).size() == 2) continue;
    sum += 2 * f(n);
    for (auto i = 0; i < (int)(p[v]).size() - 1; i++) {
      int l = p[v][i];
      int r = p[v][i + 1];
      int len = r - l - 1;
      sum -= 2 * f(len);
    }
  }
  cout << (sum / ((long double)n * n)) << "\n";
}
