Count the number of ways 2n people seated in a circle can shake hands without crossings.
There are 2n people seated around a circular table. Each person wants to shake hands with one other person, but no two handshakes can cross each other. Count the number of valid ways to form non-crossing handshakes.
This is equivalent to counting the number of ways to match 2n points on a circle with non-crossing chords.
Examples
Input:2
Output:1
Input:4
Output:2
Hints
This is the nth Catalan number: C_n = C(2n, n) / (n+1)
Use dynamic programming: dp[i] = sum of dp[j] * dp[i-1-j] for j in [0, i-1]
The answer grows quickly, consider using modulo if needed.