<p>An attendance record for a student can be represented as a string where each character signifies whether the student was absent, late, or present on that day. The record only contains the following three characters:</p>

<ul>
	<li><code>&#39;A&#39;</code>: Absent.</li>
	<li><code>&#39;L&#39;</code>: Late.</li>
	<li><code>&#39;P&#39;</code>: Present.</li>
</ul>

<p>Any student is eligible for an attendance award if they meet <strong>both</strong> of the following criteria:</p>

<ul>
	<li>The student was absent (<code>&#39;A&#39;</code>) for <strong>strictly</strong> fewer than 2 days <strong>total</strong>.</li>
	<li>The student was <strong>never</strong> late (<code>&#39;L&#39;</code>) for 3 or more <strong>consecutive</strong> days.</li>
</ul>

<p>Given an integer <code>n</code>, return <em>the <strong>number</strong> of possible attendance records of length</em> <code>n</code><em> that make a student eligible for an attendance award. The answer may be very large, so return it <strong>modulo</strong> </em><code>10<sup>9</sup> + 7</code>.</p>

<p>&nbsp;</p>
<p><strong class="example">Example 1:</strong></p>

<pre>
<strong>Input:</strong> n = 2
<strong>Output:</strong> 8
<strong>Explanation:</strong> There are 8 records with length 2 that are eligible for an award:
&quot;PP&quot;, &quot;AP&quot;, &quot;PA&quot;, &quot;LP&quot;, &quot;PL&quot;, &quot;AL&quot;, &quot;LA&quot;, &quot;LL&quot;
Only &quot;AA&quot; is not eligible because there are 2 absences (there need to be fewer than 2).
</pre>

<p><strong class="example">Example 2:</strong></p>

<pre>
<strong>Input:</strong> n = 1
<strong>Output:</strong> 3
</pre>

<p><strong class="example">Example 3:</strong></p>

<pre>
<strong>Input:</strong> n = 10101
<strong>Output:</strong> 183236316
</pre>

<p>&nbsp;</p>
<p><strong>Constraints:</strong></p>

<ul>
	<li><code>1 &lt;= n &lt;= 10<sup>5</sup></code></li>
</ul>

# In: int n
# Out: number of possible attendance records of length n for award (mod 10^9 + 7)
# Constraints: 1 <= n <= 10^5, "A", "L", "P" are possible records, max 1 "A", max 3 consecutive "L"
# Eg: Input: n = 2 => Output: 8
# Eg: Input: n = 1 => Output: 3
# Eg: Input: n = 10101 => Output: 183236316

# T: O()
# S: O()

# Approach:
# - seems like a dp problem
# - from each day, we can move forward but need to track the previous a_count and consecutive_l_count
# - could build this up recursively
# - are there any repeat subproblems?
# - seems like we are repeatedly solving a 3-length chain 

from collections import deque

class Solution:
    def checkRecord(self, n: int) -> int:
        # we could start with P, A, or L
        # next we add some remaining combo of n
        # keep going through the possibilities (P/A/L)
        mod = 10**9 + 7
        # create a memo
        memo = [[[-1] * 3 for _ in range(2)] for _ in range(n + 1)]

        def get_num_ways(num: int, a_count: int, l_count: int) -> int:
            # Base Case - invalid option
            if a_count >= 2 or l_count >= 3:
                return 0
            # Base Case - no days
            if num == 0:
                return 1
            # Recursive Case

            # use memo if possible
            if memo[num][a_count][l_count] != -1:
                return memo[num][a_count][l_count]

            # add on P/A/L to the smaller combo

            # P
            curr_num_ways = get_num_ways(num - 1, a_count, 0)
            # A
            curr_num_ways = (curr_num_ways + get_num_ways(num - 1, a_count + 1, 0))
            # L
            curr_num_ways = (curr_num_ways + get_num_ways(num - 1, a_count, l_count + 1))
            # record
            memo[num][a_count][l_count] = curr_num_ways
            return curr_num_ways % mod

        return get_num_ways(n, 0, 0) % mod
87443