Imagine you're a game designer creating a special dice game with magical rules! You have a fair 6-sided die and need to roll it n times to create a sequence. However, this isn't just any ordinary sequence - it must follow two mystical constraints:
๐ฏ Rule 1: Adjacent Harmony
Any two consecutive rolls must be coprime (their greatest common divisor equals 1). For example, rolling a 2 followed by a 3 is valid, but rolling a 2 followed by a 4 is not (since gcd(2,4) = 2).
๐ฏ Rule 2: Separation Distance
If you roll the same number twice, there must be at least 2 other rolls between them. So if you roll a 3 at position i, you cannot roll another 3 at positions i+1, i+2, or i+3.
Your task is to determine how many distinct valid sequences are possible. Since this number can be astronomically large, return the result modulo 109 + 7.
Two sequences are considered distinct if they differ in at least one position.
Input & Output
Constraints
- 1 โค n โค 104
- Dice values are always between 1 and 6 inclusive
- Result must be returned modulo 109 + 7