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: Runtime Error)

#include <stdio.h>
#define CONST (1000000007)
int main(){
  int n;
  long res,d[9][98];
  scanf("%d",&n);
  d[0][0]=26;
  d[1][0]=8;
  d[2][0]=4;
  d[3][0]=10;
  d[4][0]=3;
  d[5][0]=3;
  d[6][0]=3;
  d[7][0]=1;
  d[8][0]=1;
  d[9][0]=1;
  d[10][0]=1;
  for (int i=0;i<n-3;i++){
    d[0][i+1]=(2*d[0][i]+d[1][i]+d[2][i]+2*d[3][i]+2*d[5][i]
              +d[6][i]+d[7][i]+d[8][i]+d[9][i]+d[10][i])%CONST;
    d[1][i+1]=(d[0][i]+d[5][i]+d[8][i])%CONST;
    d[2][i+1]=(d[1][i]+d[2][i]+d[6][i]+d[9][i])%CONST;
    d[3][i+1]=(d[0][i]+d[3][i]+d[7][i]+d[8][i])%CONST;
    d[4][i+1]=(d[1][i]+d[6][i]+d[9][i])%CONST;
    d[5][i+1]=(d[1][i]+d[2][i])%CONST;
    d[6][i+1]=(d[3][i]+d[7][i])%CONST;
    d[7][i+1]=(d[4][i]+d[10][i])%CONST;
    d[8][i+1]=(d[4][i])%CONST;
    d[9][i+1]=(d[4][i]+d[10][i])%CONST;
    d[10][i+1]=(d[2][i])%CONST;
  }
  res=(d[0][n-3]+d[1][n-3]+d[2][n-3]+d[3][n-3]+d[4][n-3]+d[5][n-3]
       +d[6][n-3]+d[7][n-3]+d[8][n-3]+d[9][n-3]+d[10][n-3])%CONST;
  printf("%ld\n",res);
  return 0;
}