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 Ruby (2.3.3) (judge verdict: Accepted)

N = gets.to_i
MOD = 10 ** 9 + 7

# A: 0, G: 1, C: 2, T: 3
# NG: AGC, 1回入れ替えてAGC
# AGC, GAC, ACG, A?GC, AG?C
# 012, 102, 021, 0?12, 01?2

# dp: 文字数、最後から3,2,1文字目がいくつあるか
dp = Array.new(101) { Array.new(4) { Array.new(4) { Array.new(4, 0) } } }
dp[0][3][3][3] = 1 # ????

N.times do |i|
  4.times do |j| # 最後から1文字目の文字
    4.times do |k|
      4.times do |l|
        next if dp[i][j][k][l] == 0
        4.times do |c|
          next if c == 2 && j == 1 && k == 0
          next if c == 2 && j == 0 && k == 1
          next if c == 1 && j == 2 && k == 0
          next if c == 2 && j == 1 && l == 0
          next if c == 2 && k == 1 && l == 0
          dp[i + 1][c][j][k] += dp[i][j][k][l]
          dp[i + 1][c][j][k] %= MOD
        end
      end
    end
  end
end

ans = 0
4.times do |j|
  4.times do |k|
    4.times do |l|
      ans += dp[N][j][k][l]
      ans %= MOD
    end
  end
end

puts ans