<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 checkRecord(self, n: int) -> int:
        
        # dp = defaultdict(lambda: -1)
        dp = [ [[0 for a in range(2)] for l in range(3)] for _ in range(n+1) ]
        mod = 10**9 + 7
        
        prevDp = [[0 for a in range(2)] for l in range(3)]
        currDp = [[0 for a in range(2)] for l in range(3)]

        # n, l, a
        currDp[0][0] = 1
        currDp[0][1] = 1
        currDp[1][0] = 1
        currDp[1][1] = 0
        currDp[2][0] = 0
        currDp[2][1] = 0

        for i, row in enumerate(currDp):
            for j, val in enumerate(row):
                prevDp[i][j] = val

        for sz in range(2, n+1):
            currDp = [[0 for a in range(2)] for l in range(3)]
            for l in range(3):
                for a in range(2):

                    match (l, a):
                        case (0,0):
                            currDp[l][a] = prevDp[0][0] + prevDp[1][0] + prevDp[2][0] # P
                        case (1,0):
                            currDp[l][a] = prevDp[0][0] # L
                        case (2,0):
                            currDp[l][a] = prevDp[1][0] # L
                        case (0,1):
                            currDp[l][a] += prevDp[0][0] + prevDp[1][0] + prevDp[2][0] # A
                            currDp[l][a] += prevDp[0][1] + prevDp[1][1] + prevDp[2][1] # P
                        case (1,1):
                            currDp[l][a] = prevDp[0][1] # L
                        case (2,1):
                            currDp[l][a] = prevDp[1][1] # L
                    
                    currDp[l][a] = currDp[l][a] % mod

            for i, row in enumerate(currDp):
                for j, val in enumerate(row):
                    prevDp[i][j] = val
                    
        
        # print(dp[2])

        ans = 0
        for l in range(3):
            for a in range(2):
                ans += currDp[l][a]
                ans = ans % mod

        return ans % mod

    # def checkRecord(self, n: int) -> int:
        
    #     # dp = defaultdict(lambda: -1)
    #     dp = [ [[0 for a in range(2)] for l in range(3)] for _ in range(n+1) ]
    #     mod = 10**9 + 7

    #     # n, l, a
    #     dp[1][0][0] = 1
    #     dp[1][0][1] = 1
    #     dp[1][1][0] = 1
    #     dp[1][1][1] = 0
    #     dp[1][2][0] = 0
    #     dp[1][2][1] = 0

    #     for sz in range(2, n+1):
    #         for l in range(3):
    #             for a in range(2):

    #                 match (l, a):
    #                     case (0,0):
    #                         dp[sz][l][a] = dp[sz-1][0][0] + dp[sz-1][1][0] + dp[sz-1][2][0] # P
    #                     case (1,0):
    #                         dp[sz][l][a] = dp[sz-1][0][0] # L
    #                     case (2,0):
    #                         dp[sz][l][a] = dp[sz-1][1][0] # L
    #                     case (0,1):
    #                         dp[sz][l][a] += dp[sz-1][0][0] + dp[sz-1][1][0] + dp[sz-1][2][0] # A
    #                         dp[sz][l][a] += dp[sz-1][0][1] + dp[sz-1][1][1] + dp[sz-1][2][1] # P
    #                     case (1,1):
    #                         dp[sz][l][a] = dp[sz-1][0][1] # L
    #                     case (2,1):
    #                         dp[sz][l][a] = dp[sz-1][1][1] # L
                    
    #                 dp[sz][l][a] = dp[sz][l][a] % mod
        
    #     # print(dp[2])

    #     ans = 0
    #     for l in range(3):
    #         for a in range(2):
    #             ans += dp[n][l][a]
    #             ans = ans % mod

    #     return ans % mod


    # def checkRecord(self, n: int) -> int:
        
    #     dp = defaultdict(lambda: -1)
    #     mod = 10**9 + 7

    #     # fill the letter that this pos
    #     def count(pos, consL, totalA):
    #         if consL == 3 or totalA == 2: return 0
    #         if pos == n: return 1

    #         if dp[(pos, consL, totalA)] != -1: return dp[(pos, consL, totalA)]

    #         ways = 0

    #         ways += count(pos+1, 0, totalA) # add P
    #         ways += count(pos+1, consL+1, totalA) # add L
    #         ways += count(pos+1, 0, totalA+1) # add A
            
    #         dp[(pos, consL, totalA)] = ways % mod
    #         return dp[(pos, consL, totalA)]
        
    #     return count(0, 0, 0) % mod
        
51296