Imagine a regular convex polygon with n vertices, where each vertex is labeled from 0 to n-1 in clockwise order. At each vertex sits exactly one monkey, creating a perfect circle of our primate friends!
The Challenge: All monkeys simultaneously decide to move to a neighboring vertex (either clockwise or counterclockwise). A collision occurs when:
- Two or more monkeys end up on the same vertex after moving
- Two monkeys cross paths while moving along the same edge
Your Mission: Calculate how many different ways the monkeys can move such that at least one collision happens. Since this number can be astronomically large, return the result modulo 109 + 7.
Key Insight: This is actually a clever math problem in disguise! Think about when collisions DON'T happen, then subtract from the total possibilities.
Input & Output
Constraints
- 3 โค n โค 109
- Large input range requires efficient O(log n) solution
- Result must be returned modulo 109 + 7