Problem:
Score : 400 points

Problem Statement

You are given an integer N. Find the number of strings of length N that satisfy the following conditions, modulo 10^9+7:

The string does not contain characters other than A, C, G and T.

The string does not contain AGC as a substring.

The condition above cannot be violated by swapping two adjacent characters once.

Notes

A substring of a string T is a string obtained by removing zero or more characters from the beginning and the end of T.

For example, the substrings of ATCODER include TCO, AT, CODER, ATCODER and (the empty string), but not AC.

Constraints

3 \leq N \leq 100

Input

Input is given from Standard Input in the following format:

N

Output

Print the number of strings of length N that satisfy the following conditions, modulo 10^9+7.

Sample Input 1

3

Sample Output 1

61

There are 4^3 = 64 strings of length 3 that do not contain characters other than A, C, G and T. Among them, only AGC, ACG and GAC violate the condition, so the answer is 64 - 3 = 61.

Sample Input 2

4

Sample Output 2

230

Sample Input 3

100

Sample Output 3

388130742

Be sure to print the number of strings modulo 10^9+7.

Solution in C (GCC 5.4.1) (judge verdict: Accepted)

#include <stdio.h>

#define MOD 1000000007;

int main() {
  int n;
  scanf("%d", &n);
  long dp[101][64];
  for (int i=0; i<101; i++) for (int j=0; j<64; j++) dp[i][j] = 0;
  for (int i=0; i<16; i++) dp[2][63-i] = 1;
  for (int i=3; i<n+1; i++) {
    for (int j=0; j<64; j++) {
      if (j == 6) continue;
      if (j == 18) continue;
      if (j == 9) continue;
      if (j%16 == 6) {
        for (int idx=1; idx<4; idx++) {
          dp[i][j] += dp[i-1][idx*16+j/4];
          dp[i][j] %= MOD;
        }
      }
      else if (j/16 == 1 && j%4 == 2) {
        for (int idx=1; idx<4; idx++) {
          dp[i][j] += dp[i-1][idx*16+j/4];
          dp[i][j] %= MOD;
        }
      }
      else {
        for (int idx=0; idx<4; idx++) {
          dp[i][j] += dp[i-1][idx*16+j/4];
          dp[i][j] %= MOD;
        }
      }
    }
  }
  long ans = 0;
  for (int i=0; i<64; i++) {
    ans += dp[n][i];
    ans %= MOD;
  }
  printf("%ld\n", ans);
  return 0;
}