All problems

Problem 641

Count Vowels Permutation

Hard · 30 pts · Dynamic Programming

Problem

Count the strings of length N made only of the vowels a, e, i, o and u that follow these rules: a may only be followed by e; e only by a or i; i by anything except another i; o only by i or u; u only by a. Print the count modulo 1000000007. Keep, for each vowel, the number of valid strings ending with it, and update all five counts once per extra character. Keep the counts in a 64-bit integer type (long long in C++, long in Java) and take the remainder after every addition and multiplication: adding or multiplying two remainders can be larger than a 32-bit int can hold (Python needs nothing special).

Input

A single integer N.

Output

Print the number of valid strings modulo 1000000007.

Constraints

1 <= N <= 20000

Example input

2

Example output

10

Explanation

For N = 2 the valid strings are ae, ea, ei, ia, ie, io, iu, oi, ou and ua. That is 10 strings, so the answer is 10.

Every problem here can be used in a RelayTrixCode team match. Create a room.

Previous: Detonate the Maximum Bombs Next: Knight Dialer