<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 {
public:
    const int mod=1000000007;
    int solver(int n, int A, int bool1, int bool2, vector<vector<vector<vector<int>>>> &dp){
        if(n==0) return 1;
        if(dp[n][A][bool1][bool2]!=-1) return dp[n][A][bool1][bool2];
        long long ans=0;
        if(A>0) ans=(ans+solver(n-1, A-1, false, false, dp))%mod; //marking A;
        ans=(ans+solver(n-1, A, false, false, dp))%mod; //marking P;
        if(!bool1 && !bool2) ans=(ans+solver(n-1, A, false, true, dp))%mod;
        if(!bool1 && bool2) ans=(ans+solver(n-1, A, true, true, dp))%mod;
        return dp[n][A][bool1][bool2]=ans;
    }
    int checkRecord(int n){
        vector<vector<vector<vector<int>>>> dp(n+1, vector<vector<vector<int>>>(2, vector<vector<int>>
                                                (2, vector<int>(2, -1))));
        return solver(n, 1, false, false, dp);
    }
};


// class Solution {
// public:
//     int checkRecord(int n) {
//         const int MOD = 1000000007;
//         vector<vector<int>> dp_last(2, vector<int>(3, 0)); // previous state
//         vector<vector<int>> dp_current(2, vector<int>(3, 0)); // current state

//         dp_last[0][0] = 1; // empty string

//         for (int i = 0; i < n; i++) {
//             for (int count_a = 0; count_a < 2; count_a++) {
//                 for (int count_l = 0; count_l < 3; count_l++) {
//                     // choose "P"
//                     dp_current[count_a][0] = (dp_current[count_a][0] + dp_last[count_a][count_l]) % MOD;
//                     // choose "A"
//                     if (count_a == 0) {
//                         dp_current[count_a + 1][0] = (dp_current[count_a + 1][0] + dp_last[count_a][count_l]) % MOD;
//                     }
//                     // Choose "L"
//                     if (count_l < 2) {
//                         dp_current[count_a][count_l + 1] = (dp_current[count_a][count_l + 1] + dp_last[count_a][count_l]) % MOD;
//                     }
//                 }
//             }
//             dp_last = dp_current; // Reference current to previous
//             dp_current = vector<vector<int>>(2, vector<int>(3, 0)); // make new current
//         }

//         // Sum up the counts for all combinations of length 'n' with different count_a and count_l.
//         int res = 0;
//         for (int count_a = 0; count_a < 2; count_a++) {
//             for (int count_l = 0; count_l < 3; count_l++) {
//                 res = (res + dp_last[count_a][count_l]) % MOD;
//             }
//         }
//         return res;
//     }
// };
520471