<|instruction|>
Solve the below problem. The solution should start with an abridged problem statement. Then key observations. Then full solution based on the observations. Then C++ and Python implementations with comments.

481. Hero of Our Time
Time limit per test: 0.5 second(s)
Memory limit: 65536 kilobytes
input: standard
output: standard

Saratov ACM ICPC teams have a tradition to come together on Halloween and recollect terrifying stories. And the most popular story among the newcomers is the story about the "Mescher Tree". A long time ago, when the famous Dmitry Mescheryakov aka Mescher was very young and he even didn't know how to write Dijkstra algorithm, he faced a difficult problem with a tree. Input file contained n — the number of vertices, and pairs of vertices, connected with an edge. Without thinking a lot (honestly, the exact reason of that mistake is unknown), he wrote the following code:

 read(n);
 for i := 1 to n do begin
 read(u, v);
 g[u, v] := true;
 g[v, u] := true;
 end; 
Mescher successfully compiled his code, got WA on sample test and started long debugging... This story has become a true legend. So it's no surprise that Saratov ACM ICPC teams use the following definition: connected undirected graph with n vertices and n edges is called Mescheryakov Tree or, less formally, Mescher Tree. The area of application of Mescher trees is not well-studied, so we suggest you to solve one of the problems connected with such trees: given n, find the number of distinct Mescher trees with n vertices. Trees are labeled, i.e. two trees are considered distinct if and only if their adjacency matrices differ.

Input
Input contains single integer number n (3 ≤ n ≤ 5000).

Output
Output the number of Mescher trees with n vertices without leading zeroes.

Example(s)
sample input
sample output
3

<|response|>
1. Abridged Problem Statement  
Given an integer n (3 ≤ n ≤ 5000), count how many labeled connected undirected graphs on n vertices have exactly n edges. Such graphs are precisely the connected unicyclic graphs (one cycle, with trees possibly attached). Output the exact count (as a big integer) with no leading zeros.

2. Key Observations  
- Any connected graph on n vertices with n edges has exactly one cycle.  
- You can build every such graph by choosing the cycle and then “hanging” the remaining vertices as trees on the cycle vertices.  
- Let k be the length of the unique cycle (3 ≤ k ≤ n).  
  • Choose which k vertices form the cycle: C(n, k) ways.  
  • Arrange them into an undirected cycle: each labeled cycle has (k – 1)!/2 distinct orderings.  
  ⇒ total ways to pick and form the cycle = C(n, k)·((k – 1)!/2).  
- The remaining n – k vertices must attach to the k cycle vertices in an acyclic, connected way. It is a known extension of Cayley’s formula that the number of forests on n labeled nodes with exactly k specified roots (each tree containing exactly one root) is k·n^(n–k–1).  
- Multiply the two counts and sum over k:  
  Tₙ = ∑_{k=3 to n} [C(n,k)·((k–1)!/2)]·[k·n^(n–k–1)].  

3. Full Solution Approach  
Step A. Simplify the summand algebraically.  
  • C(n,k)·(k–1)! = n! / ((n–k)!·k).  
  • Multiply by k/2 gives n! / (2·(n–k)!).  
  ⇒ For each k the term is [n!/(2·(n–k)!)]·n^(n–k–1).  
  Let j = n – k, so j runs 0…n–3. Then n–k–1 = j–1.  
  Tₙ = ∑_{j=0 to n–3} [n!/(2·j!)]·n^(j–1) = (n!/2)·∑_{j=0 to n–3} n^(j–1)/j!.  

Step B. Turn this into an O(n) recurrence for big integers.  
  Define f_j = term for index j = (n!/2)·n^(j–1)/j!.  
  Then  
    f₀ = (n!/2)·n^(–1)/0! = (n–1)!/2  
  and for j ≥ 1  
    f_j = f_{j–1} · n / j.  
  The answer is ans = ∑_{j=0 to n–3} f_j.  

Step C. Implementation details.  
  – Compute f = f₀ by building (n–1)! and dividing by 2.  
  – Initialize ans = f.  
  – For j from 1 to n–3:  
      f = f * n / j  
      ans = ans + f  
  – Print ans.  
All operations are on arbitrarily large integers; this runs in O(n) multiprecisions, fast for n up to 5000.

4. C++ Implementation with Detailed Comments  
```cpp
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>
using namespace std;
// We use boost::multiprecision::cpp_int for big integers.
using big = boost::multiprecision::cpp_int;

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

    int n;
    cin >> n;

    // Step A: compute f = f0 = (n-1)! / 2
    big f = 1;
    // compute (n-1)!
    for (int i = 2; i < n; ++i) {
        f *= i;
    }
    // divide by 2 to get (n-1)! / 2
    f /= 2;

    // This is the first term of the sum: ans = f0
    big ans = f;

    // Step B: iteratively compute f_j and add to ans
    // for j = 1 to n-3:
    //    f_j = f_{j-1} * n / j
    //    ans += f_j
    for (int j = 1; j <= n - 3; ++j) {
        // multiply by n (numerator)
        f *= n;
        // divide by j (denominator)
        f /= j;
        // add the new term
        ans += f;
    }

    // Output the final result, no leading zeros by default
    cout << ans << "\n";
    return 0;
}
```

5. Python Implementation with Detailed Comments  
```python
import sys

def main():
    n = int(sys.stdin.readline())
    # Step A: compute f = f0 = (n-1)! / 2
    f = 1
    for i in range(2, n):
        f *= i
    f //= 2           # now f = (n-1)! / 2

    # Initialize the running sum with f0
    ans = f

    # Step B: for j = 1 to n-3, update f and add to ans
    # f_j = f_{j-1} * n // j
    for j in range(1, n - 2):
        f = (f * n) // j
        ans += f

    # Print the final answer
    print(ans)

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