func_code_string: #include <bits/stdc++.h>   using namespace std;   template <class X, class Y>   void amax(X& x, const Y& y) {     if (x < y) x = y;   }   template <class X, class Y>   void amin(X& x, const Y& y) {     if (x > y) x = y;   }   const int INF = 1e9 + 10;   const long long INFL = 1e18 + 10;   const int MAX = 1e6 + 10;   int n;   int a[MAX], prv[MAX], pos[MAX];   long long gt[MAX * 4], lazy[MAX * 4];   void update(int id, int l, int r, int u, int v) {     if (v < l || u > r) return;     if (u <= l && r <= v) {       lazy[id]++;       gt[id] += (r - l + 1);       return;     }     int mid = (l + r) / 2;     update(id * 2, l, mid, u, v);     update(id * 2 + 1, mid + 1, r, u, v);     gt[id] = gt[id * 2] + gt[id * 2 + 1] + lazy[id] * (r - l + 1);   }   long long query(int id, int l, int r, int u, int v) {     if (v < l || u > r) return 0;     if (u <= l && r <= v) return gt[id];     int mid = (l + r) / 2;     return query(id * 2, l, mid, u, v) + query(id * 2 + 1, mid + 1, r, u, v) +            lazy[id] * (min(r, v) - max(u, l) + 1);   }   void process() {     cin >> n;     for (int i = 1; i <= n; i++) cin >> a[i];     for (int i = 1; i <= n; i++) {       prv[i] = pos[a[i]];       pos[a[i]] = i;     }     long double sum = 0;     long double choose = (long long)n * n;     for (int i = 1; i <= n; i++) {       update(1, 1, n, prv[i] + 1, i);       sum = sum + (query(1, 1, n, 1, i) * 2 - 1) / choose;     }     cout << fixed << setprecision(10) << sum <<   n ;   }   int main() {     ios_base::sync_with_stdio(false);     process();   }   