An attendance record for a student can be represented as a string where each character says whether the student was absent, late or present on that day. The record contains only these three characters:
-
'A'
: absent
-
'L'
: late
-
'P'
: present
A student is eligible for an attendance award when both of these hold:
-
The student was absent (
'A'
) on strictly fewer than 2 days in total.
-
The student was never late (
'L'
) on 3 or more consecutive days.
Given an integer n, return the number of possible attendance records of length n that make a student eligible for the award. The answer can be very large, so return it modulo 10^9 + 7.
Function Signature
def count_eligible_records(n: int) -> int:
Rules
-
Count distinct strings. Two records are different when they differ on at least one day.
-
Return the count modulo
1_000_000_007
.
Constraints
Examples
Input: n = 2
Output: 8
There are 9 records of length 2, and only "AA" fails (two absences). The 8 eligible ones are "PP", "AP", "PA", "LP", "PL", "AL", "LA" and "LL".
Input: n = 1
Output: 3
"P", "A" and "L" are all eligible.
Input: n = 3
Output: 19
Without an 'A', 7 of the 8 strings over 'P' and 'L' qualify (only "LLL" fails). With exactly one 'A', there are 3 places for it and 4 ways to fill the other two days, which gives 12. The total is 7 + 12 = 19.