n guests came to a holiday party, each bringing one gift. The gifts go into a sack and are handed out again: every guest receives exactly one gift, but nobody may receive the one they brought.
In how many ways can the gifts be handed out? The answer can be huge, so return it modulo 10⁹ + 7.n=3 → 2
If guests 1, 2, 3 brought gifts 1, 2, 3, only the handouts (2, 3, 1) and (3, 1, 2) work.
n=1 → 0
A single guest can only get their own gift back.
n=4 → 9
n=3
2
Run checks the first 3 tests in your browser. Submit checks all 27 tests on the server, hidden ones included.