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 Lua (5.3.2) (judge verdict: Wrong Answer)

local DBG = false
local function dbgpr(...)
    if DBG then
        io.write("[dbg]")
        print(...)
    end
end

local function dbgpr_t(tbl, use_pairs)
    if DBG then
        local enum = ipairs
        if use_pairs then
            enum = pairs
        end
        dbgpr(tbl)
        io.write("[dbg]")
        for i,v in enum(tbl) do
            io.write(i)
            io.write(":")
            io.write(tostring(v))
            io.write(" ")
        end
        print("")
    end
end

local function dbgpr_tp(tbl)
    dbgpr_t(tbl, true)
end
-----------------------------------------
local MOD = 1000000007

local function pow4(n)
    local a = 1
    for i=1,n do
        a = a * 4 % MOD
    end
    return a
end

local ng_a, ng_c, ng_g, ng_t, ng

local ng_a_tbl = {0,0,2}
ng_a = function(k)
    dbgpr("ng_a", k)
    if ng_a_tbl[k] ~= nil then
        return ng_a_tbl[k]
    end
    local x = (ng_a(k-1) + pow4(k-3) + ng_t(k-1) + pow4(k-3)) % MOD
    ng_a_tbl[k] = x
    return x
end

local ng_c_tbl = {0,0,0}
ng_c = function(k)
    dbgpr("ng_c", k)
    if ng_c_tbl[k] ~= nil then
        return ng_c_tbl[k]
    end
    local x = ng(k-1)
    ng_c_tbl[k] = x
    return x
end

local ng_t_tbl = {0,0,0}
ng_t = function(k)
    dbgpr("ng_t", k)
    if ng_t_tbl[k] ~= nil then
        return ng_t_tbl[k]
    end
    local x = ng(k-1)
    ng_t_tbl[k] = x
    return x
end

local ng_g_tbl = {0,0,1}
ng_g = function(k)
    dbgpr("ng_g", k)
    if ng_g_tbl[k] ~= nil then
        return ng_g_tbl[k]
    end
    local x = (ng_c(k-1) + ng_g(k-1) + ng_t(k-1) + pow4(k-3)) % MOD
    ng_g_tbl[k] = x
    return x
end

local ng_tbl = {0,0,3}
ng = function(k)
    dbgpr("ng", k)
    if ng_tbl[k] ~= nil then
        return ng_tbl[k]
    end
    local x = (ng_a(k) + ng_c(k) + ng_g(k) + ng_t(k)) % MOD
    ng_tbl[k] = x
    return x
end

local function ok(k)
    return (pow4(k) - ng(k) + MOD) % MOD
end

--for i=3,6 do
--    print(i, ok(i))
--end

local N = io.read("n")
print(ok(N))