<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>

class Solution:
    def checkRecord(self, n: int) -> int:
        def eligible_combinations2(n, total_absences, consecutive_lates) -> int:
            # Do not generate further combinations if the combination is not eligible for the award.
            if total_absences >= 2 or consecutive_lates >= 3: return 0
            # We have created a combination of length 'n' which is eligible for the award, thus, include it in the count.
            if n == 0: return 1

            if (n, total_absences, consecutive_lates) in self.dp:
                return self.dp[(n, total_absences, consecutive_lates) ]

            # Choose a character for the current position and make further recursive calls.
            counts = eligible_combinations(n - 1, total_absences, 0) # Choose 'P'.
            counts += eligible_combinations(n - 1, total_absences + 1, 0) # Choose 'A'.
            counts += eligible_combinations(n - 1, total_absences, consecutive_lates + 1) # Choose 'L'.

            self.dp[(n, total_absences, consecutive_lates)] = counts % (10**9 + 7)
            return counts % (10**9 + 7)
        def eligible_combinations() -> int:
            dp = defaultdict(int)
            dp[(0,0,0)] = 1
            for index in range(1, n + 1):
                for ab in range(2):
                    for late in range(3):
                        count = 0
                        go_through = set()
                        if late != 0:
                            go_through.add((index - 1, ab, late - 1))
                        else:
                            for late2 in range(3):
                                go_through.add((index - 1, 0, late2))
                                if ab != 0:
                                    go_through.add((index - 1, 1, late2))

                        for val in go_through:
                            count += dp[val]
                        dp[(index, ab, late)] = count % (10**9 + 7)

            fin_count = 0
            for ab in range(2):
                for late in range(3):
                    fin_count += dp[(n, ab, late)]
            return fin_count


        self.dp = {}
        return eligible_combinations() % (10**9 + 7)
115981