<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:
    int checkRecord(int n) {

        //total status
        //0: 0A 0L
        //1: 0A 1L
        //2: 0A 2L
        //3: 1A 0L
        //4: 1A 1L
        //5: 1A 2L

        long int dp[6] = {1,0,0,0,0,0}; //at 0 day there is 0A0L
        long int tmp[6];
        const long long mod=1e9+7;

        for(int i = 0;i<n;i++){
            for(int j = 0;j<6;j++)tmp[j] = dp[j];

            //NOW STATE-|-------  NEXT STATE ---------|
            //0: 0A 0L => P: 0A0L    A: 1A0L   L: 0A1L
            //1: 0A 1L => P: 0A0L    A: 1A0L   L: 0A2L
            //2: 0A 2L => P: 0A0L    A: 1A0L   L: X
            //3: 1A 0L => P: 1A0L    A: X      L: 1A1L
            //4: 1A 1L => P: 1A0L    A: X      L: 1A2L
            //5: 1A 2L => P: 1A0L    A: X      L: X
            //    every turn
            //0A0L =0+1+2
            //0A1L =0
            //0A2L =1
            //1A0L =0+1+2+3+4+5
            //1A1L =3
            //1A2L =4

            dp[0] =(tmp[0]+tmp[1]+tmp[2])%mod;
            dp[1] =(tmp[0])%mod;
            dp[2] =(tmp[1])%mod;
            dp[3] = (tmp[0] + tmp[1] + tmp[2] + tmp[3] + tmp[4] +tmp[5])%mod;
            dp[4] =(tmp[3])%mod;
            dp[5] =(tmp[4])%mod;
        }
        
        return (dp[0]+dp[1]+dp[2]+dp[3]+dp[4]+dp[5])%mod;
        
    }

};
10428