<p>Given an integer <code>n</code>, your task is to count how many strings of length <code>n</code> can be formed under the following rules:</p>

<ul>
	<li>Each character is a lower case vowel&nbsp;(<code>&#39;a&#39;</code>, <code>&#39;e&#39;</code>, <code>&#39;i&#39;</code>, <code>&#39;o&#39;</code>, <code>&#39;u&#39;</code>)</li>
	<li>Each vowel&nbsp;<code>&#39;a&#39;</code> may only be followed by an <code>&#39;e&#39;</code>.</li>
	<li>Each vowel&nbsp;<code>&#39;e&#39;</code> may only be followed by an <code>&#39;a&#39;</code>&nbsp;or an <code>&#39;i&#39;</code>.</li>
	<li>Each vowel&nbsp;<code>&#39;i&#39;</code> <strong>may not</strong> be followed by another <code>&#39;i&#39;</code>.</li>
	<li>Each vowel&nbsp;<code>&#39;o&#39;</code> may only be followed by an <code>&#39;i&#39;</code> or a&nbsp;<code>&#39;u&#39;</code>.</li>
	<li>Each vowel&nbsp;<code>&#39;u&#39;</code> may only be followed by an <code>&#39;a&#39;</code>.</li>
</ul>

<p>Since the answer&nbsp;may be too large,&nbsp;return it modulo&nbsp;<code>10^9 + 7</code>.</p>

<p>&nbsp;</p>
<p><strong class="example">Example 1:</strong></p>

<pre>
<strong>Input:</strong> n = 1
<strong>Output:</strong> 5
<strong>Explanation:</strong> All possible strings are: &quot;a&quot;, &quot;e&quot;, &quot;i&quot; , &quot;o&quot; and &quot;u&quot;.
</pre>

<p><strong class="example">Example 2:</strong></p>

<pre>
<strong>Input:</strong> n = 2
<strong>Output:</strong> 10
<strong>Explanation:</strong> All possible strings are: &quot;ae&quot;, &quot;ea&quot;, &quot;ei&quot;, &quot;ia&quot;, &quot;ie&quot;, &quot;io&quot;, &quot;iu&quot;, &quot;oi&quot;, &quot;ou&quot; and &quot;ua&quot;.
</pre>

<p><strong class="example">Example 3:&nbsp;</strong></p>

<pre>
<strong>Input:</strong> n = 5
<strong>Output:</strong> 68</pre>

<p>&nbsp;</p>
<p><strong>Constraints:</strong></p>

<ul>
	<li><code>1 &lt;= n &lt;= 2 * 10^4</code></li>
</ul>

class Solution1 {
public:
    int countVowelPermutation(int n) {
        vector<vector<long>> dp(n, vector<long>(5,0));
        const int MOD7 = 1e9+7;

        for(int i = 0; i < n; i++)
        {
            if (i == 0)
            {
                for(int j = 0; j < 5; j++)
                    dp[i][j] = 1;
            }
            else
            {
                /*dp[i][0] = (dp[i-1][1] + dp[i-1][2] + dp[i-1][4])%MOD7;
                dp[i][1] = (dp[i-1][0] + dp[i-1][2])%MOD7; 
                dp[i][2] = (dp[i-1][1] + dp[i-1][3])%MOD7;
                dp[i][3] = (dp[i-1][2])%MOD7;    
                dp[i][4] = (dp[i-1][3] + dp[i-1][2])%MOD7;*/
                dp[i][0] = (dp[i-1][1])%MOD7;
                dp[i][1] = (dp[i-1][0] + dp[i-1][2])%MOD7; 
                dp[i][2] = (dp[i-1][0] + dp[i-1][1] + dp[i-1][3] + dp[i-1][4])%MOD7;
                dp[i][3] = (dp[i-1][2] + dp[i-1][4])%MOD7;    
                dp[i][4] = (dp[i-1][0])%MOD7;

            }
        }
 
        int ans = 0;
        
        for(int x : dp[n-1]) ans = (ans+x)%MOD7;
        
        return ans;
    }
};

class Solution {
public:
    int countVowelPermutation(int n) {
        vector<int> dp(5, 1);
        const int MOD7 = 1e9+7;
        
        unordered_map<int, vector<int>> mp;
        mp[0].push_back(1);//e (a) 
        mp[0].push_back(2);//i (a)
        mp[0].push_back(4);//u (a)
        mp[1].push_back(0);//a (e)
        mp[1].push_back(2);//i (e)
        mp[2].push_back(1);//e (i) 
        mp[2].push_back(3);//o (i)
        mp[3].push_back(2);//i (o)
        mp[4].push_back(2);//u (i)
        mp[4].push_back(3);//u (o)
        
        int idx = 1;
        while(idx < n)
        {
            vector<int> dp2(5, 0);
            for(int i = 0; i < 5; i++)
            {
                vector<int> neigh = mp[i];
                for(int j = 0; j < neigh.size(); j++)
                {
                    int v = neigh[j];
                    dp2[i] = (dp2[i] + dp[v])%MOD7;
                }
            }
            dp = dp2;
            idx++;
        }
        
        int ans = 0;
        for(int x : dp)
        {
            ans = (ans + x)%MOD7;
        }
        
        return ans;
    }
};

105813