1. Abridged Problem Statement

Given \(n\) judges and a uniformly random derangement (permutation without fixed points) of size \(n\), each judge belongs to a cycle of length ≥ 2. In a "Highlander" chase game, each cycle of the permutation collapses to a single survivor who collects all cards in that cycle, and the winners are the survivors of the largest initial cycle(s). A judge has a theoretical chance to win if and only if he is in one of the largest cycles. Compute the expected total number of judges (i.e. sum of sizes of all maximum-length cycles) that have a chance to win.

2. Detailed Editorial

- **Reformulation**
  We choose a random derangement \(p\) of \(\{1,\dots,n\}\). Let the cycle-decomposition of \(p\) have cycle lengths \(c_1,c_2,\dots\), all \(\ge2\). Let
    - \(L=\max_i c_i\) be the largest cycle length.
    - \(m\) be the number of cycles of length \(L\).
  Every judge in those \(m\) largest cycles could end up as the survivor of that cycle and thus as an overall winner. So the quantity we seek is
  \[
    \mathbb{E}\bigl[m\times L\bigr],
  \]
  where the expectation is over all derangements of size \(n\).

- **DP State**
  Define
  \[
    \mathrm{dp}[\,\ell\,][\,M\,][\,k\,]
    = \Pr\bigl(\text{a (partial) derangement of size }\ell\text{ has no cycle }>{M},\text{ and exactly }k\text{ cycles of size }M\bigr).
  \]
  We build this up for all \(\ell=0..n\) and \(M=1..n\). (Cycles of size 1 are forbidden.)

- **Initialization**
  For every \(M\ge1\), a derangement of size 0 trivially has zero cycles:
  \(\mathrm{dp}[0][M][0]=1.\)

- **Transition**
  To form a derangement of size \(\ell>0\), look at which cycle contains element 1. Suppose that cycle has size \(s\) (with \(2\le s\le\min(M,\ell)\)). Then we choose its other \(s-1\) members among \(\ell-1\) in \(\binom{\ell-1}{s-1}\) ways, arrange them in a cycle in \((s-1)!\) ways, and interleave with a derangement of the remaining \(\ell-s\) elements. One can show that the total weight of "adding a cycle of size \(s\)" contributes exactly \(\tfrac1\ell\) to the transition probability. Thus:
  \[
    \mathrm{dp}[\ell][M][\,k\,]
    += \sum_{s=2}^{\min(M,\ell)}
       \mathrm{dp}[\ell-s][M][\,k - [s=M]\,]\;\times\;\frac1\ell.
  \]
  Here \([s=M]\) is 1 if \(s=M\), else 0.

- **Normalization**
  We have disallowed 1-cycles, so the total of \(\mathrm{dp}[n][M][k]\) over all \(M\ge2\), \(k\ge1\) is
  \[
    Z = \sum_{M=2}^{n}\sum_{k=1}^{\lfloor n/M\rfloor}\mathrm{dp}[n][M][k].
  \]
  This \(Z\) is the probability mass of *all* derangements (which is less than 1 if you allowed 1-cycles in an ordinary permutation). Divide by \(Z\) to renormalize to the uniform derangement distribution.

- **Answer**
  Finally
  \[
    \mathbb{E}[mL]
    = \frac1Z\;\sum_{M=2}^n\sum_{k=1}^{\lfloor n/M\rfloor}
      \mathrm{dp}[n][M][k]\;\times\;(k\times M).
  \]
  Compute with double precision, output with 9 decimal places.

3. C++ Solution

```cpp
#include <bits/stdc++.h>

using namespace std;

template<typename T1, typename T2>
ostream& operator<<(ostream& out, const pair<T1, T2>& x) {
    return out << x.first << ' ' << x.second;
}

template<typename T1, typename T2>
istream& operator>>(istream& in, pair<T1, T2>& x) {
    return in >> x.first >> x.second;
}

template<typename T>
istream& operator>>(istream& in, vector<T>& a) {
    for(auto& x: a) {
        in >> x;
    }
    return in;
};

template<typename T>
ostream& operator<<(ostream& out, const vector<T>& a) {
    for(auto x: a) {
        out << x << ' ';
    }
    return out;
};

int n;

void read() { cin >> n; }

void solve() {
    // Let's consider judge i has card p[i], or in other words we have a
    // permutation p[1], ..., p[n]. We can notice that in the end of the game,
    // each cycles in this permutation will be compressed into a single judge.
    // Then a judge can win if and only if it's part of a largest cycle. In
    // other words we are looking for E[positions i which are part of a largest
    // cycle], over all permutations of length n. One important constraint is
    // that we can't have cycles of length 1 - this is because a person can't
    // start with its own card. We will do this by counting all permutations but
    // never allowing size of a cycle = 1, and then re-normalizing the
    // probabilities.
    //
    // To solve this we can try dp[length][max_cycle_length][cnt], representing
    // the probability to have a permutation of given length that has cnt cycles
    // of max_cycle_length, and no cycles larger than max_cycle_length. This is
    // O(n^2 log n) states, because cnt * max_cycle_length <= length and the
    // harmonic sequence. The trick to avoid over-counting is to always select
    // the cycle of p[1] in the transitions.
    //
    // The transitions are O(n), so the total complexity is O(n^3 log n) which
    // is fast enough for n <= 100.

    vector<vector<vector<double>>> dp(n + 1, vector<vector<double>>(n + 1));
    for(int length = 0; length <= n; length++) {
        for(int max_cycle_length = 1; max_cycle_length <= n;
            max_cycle_length++) {
            int max_cnt = length / max_cycle_length;
            dp[length][max_cycle_length].assign(max_cnt + 1, 0);
        }
    }

    for(int i = 1; i <= n; i++) {
        dp[0][i][0] = 1;
    }

    for(int length = 1; length <= n; length++) {
        for(int max_cycle_length = 1; max_cycle_length <= n;
            max_cycle_length++) {
            int max_cnt = length / max_cycle_length;
            for(int cnt = 0; cnt <= max_cnt; cnt++) {
                // Look at cycle of p[1], and select the size.
                // There are C(length - 1, size - 1) ways to select the other
                // nodes in this cycle, and then we have (size-1)! permutations
                // that are valid. There are also length! permutations but
                // 1/(length-size)! is already present in dp[length - size].
                //
                // Therefore the transition probability will be:
                //
                //     (size - 1)! * C(length - 1, size - 1) / (length! /
                //     (length-size)!)
                //  =
                //     (size - 1)! * (length - 1)! * (length - size)! / ( (size
                //     - 1)! * (length - 1 - size + 1)! * length!)
                //  =
                //     1 / length

                for(int size = 2; size <= min(max_cycle_length, length);
                    size++) {
                    int new_cnt = size == max_cycle_length ? cnt - 1 : cnt;

                    if(new_cnt >= 0 &&
                       new_cnt <
                           (int)dp[length - size][max_cycle_length].size()) {
                        dp[length][max_cycle_length][cnt] +=
                            dp[length - size][max_cycle_length][new_cnt] /
                            length;
                    }
                }
            }
        }
    }

    // We didn't allow cycle length equal to 1.0, so we need to renormalize.
    double Z = 0;
    for(int max_cycle_length = 2; max_cycle_length <= n; max_cycle_length++) {
        int max_cnt = n / max_cycle_length;
        for(int cnt = 1; cnt <= max_cnt; cnt++) {
            Z += dp[n][max_cycle_length][cnt];
        }
    }

    double ans = 0;
    for(int max_cycle_length = 2; max_cycle_length <= n; max_cycle_length++) {
        int max_cnt = n / max_cycle_length;
        for(int cnt = 1; cnt <= max_cnt; cnt++) {
            ans += dp[n][max_cycle_length][cnt] / Z * cnt * max_cycle_length;
        }
    }

    cout << setprecision(9) << fixed << ans << endl;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

    int T = 1;
    // cin >> T;
    for(int test = 1; test <= T; test++) {
        read();
        // cout << "Case #" << test << ": ";
        solve();
    }

    return 0;
}

/*
2 3 1 -> 3             -> 3 / 2
3 1 2 -> 3             -> 3 / 2

Total = 2.5
*/
```

4. Python Solution with Detailed Comments

```python
import sys
def main():
    data = sys.stdin.read().strip().split()
    n = int(data[0])

    # dp[l][M][k] = probability of a derangement of size l
    # with no cycle > M, and exactly k cycles of size M
    dp = [ [ [] for _ in range(n+1) ] for __ in range(n+1) ]
    # Pre-allocate inner lists by max possible k = floor(l/M)
    for l in range(n+1):
        for M in range(1, n+1):
            maxCnt = l // M
            dp[l][M] = [0.0] * (maxCnt+1)

    # Base case: empty set has 1 way, zero cycles
    for M in range(1, n+1):
        dp[0][M][0] = 1.0

    # Build DP for lengths 1..n
    for l in range(1, n+1):
        for M in range(1, n+1):
            maxCnt = l // M
            for k in range(maxCnt+1):
                # Choose the cycle size s containing '1'
                # must be in [2..min(M,l)]
                for s in range(2, min(M, l)+1):
                    prev_k = k - (1 if s == M else 0)
                    if prev_k < 0:
                        continue
                    # We add probability mass 1/l
                    dp[l][M][k] += dp[l-s][M][prev_k] / l

    # Sum up total mass of valid derangements Z
    Z = 0.0
    for M in range(2, n+1):
        for k in range(1, n//M + 1):
            Z += dp[n][M][k]

    # Compute expected total size of largest cycles: E[k * M]
    ans = 0.0
    for M in range(2, n+1):
        for k in range(1, n//M + 1):
            prob = dp[n][M][k] / Z
            ans += prob * (k * M)

    # Print with 9 decimal places
    print(f"{ans:.9f}")

if __name__ == "__main__":
    main()
```

5. Compressed Editorial

- We need the expected sum of sizes of all maximum-length cycles in a random derangement of size \(n\).
- Define \(\mathrm{dp}[l][M][k]\) = prob. that a derangement of \(l\) elements has no cycle > \(M\) and exactly \(k\) cycles of size \(M\). Disallow 1-cycles.
- Base: \(\mathrm{dp}[0][M][0]=1\). Transition by choosing the cycle through element 1 of size \(s\in[2,\min(M,l)]\), which contributes \(\tfrac1l\) to the transition.
- After filling dp up to \(l=n\), compute normalization \(Z=\sum_{M=2..n}\sum_{k\ge1}\mathrm{dp}[n][M][k]\).
- The answer is \(\frac1Z\sum_{M=2..n}\sum_{k\ge1}\mathrm{dp}[n][M][k]\times(k\times M)\), printed with 9 decimals.
