<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 md = 1000000007;
    using ll = long long;
    int checkRecord(int n) {
        if(n == 1) return 3;
        vector<vector<ll>> dp(n+4, vector<ll>(4,0));
        for(int i=0; i<4; i++)
        {
            dp[2][i] = 1;
            if(i == 0) dp[3][i] = 1;
            else dp[3][i] = 2;
        }
        for(int i=4; i<=n; i++)
        {
            dp[i][0] = (dp[i-2][2] + dp[i-2][3])%md;
            dp[i][1] = (dp[i-2][0] + dp[i-2][1] + dp[i-2][2] + dp[i-2][3])%md;
            dp[i][2] = (dp[i-2][1] + dp[i-2][2] + dp[i-2][3])%md;
            dp[i][3] = (dp[i-2][0] + dp[i-2][1] + dp[i-2][2] + dp[i-2][3])%md;
        }
        ll totalPossible = (dp[n][0] + dp[n][1] + dp[n][2] + dp[n][3])%md;
        for(int i=1; i<=n; i++)
        {
            int leftLength = i-1;
            int rightLength = n-i;
            ll leftWays = 0, rightWays = 0;
            if(leftLength == 0) leftWays = 1;
            else if(leftLength == 1) leftWays = 2;
            else leftWays = (dp[leftLength][0] + dp[leftLength][1] + dp[leftLength][2] + dp[leftLength][3])%md;
            if(rightLength == 0) rightWays = 1;
            else if(rightLength == 1) rightWays = 2;
            else rightWays = (dp[rightLength][0] + dp[rightLength][1] + dp[rightLength][2] + dp[rightLength][3])%md;
            totalPossible = (totalPossible + (leftWays*rightWays)%md)%md;
        }
        return totalPossible;
    }
};
171834