Hallway tiling
A hallway is L metres long. You cover it, end to end, with tiles 1 metre and 3 metres long. Every 3-metre tile must have a 1-metre tile right next to it (just before it or just after it). Count the different tile sequences, modulo 10^9 + 7. For L = 5 there are 4: [1, 1, 1, 1, 1], [1, 1, 3], [1, 3, 1] and [3, 1, 1].
Reported in: Infosys (SP / DSE · 29 Nov 2026) (memory-based)
Input
One line: L.
Output
The number of valid tile sequences modulo 10^9 + 7.
Constraints
1 ≤ L ≤ 10^6.
Example 1
Input:
4
Output:
3Example 2
Input:
5
Output:
4Example 3
Input:
7
Output:
7Hint: Build the row left to right and remember what the last tile is: a 1, a 3 that already has a 1 before it, or a 3 that still needs a 1 after it. A 3 may not follow a 3 that is still waiting for its 1, and the row may not end with one.