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.



Sample input:
3


Sample output:
61

Submission status: Wrong Answer

Solution code:
mod=10**9+7
n=int(input())
d=[[1,1,1,1] for i in range(100)]
d[1]=[4,4,4,4]
d[2]=[16,14,15,16]
for i in range(3,100):
    for j in range(4):
        t=d[i-1][0]+d[i-1][1]+d[i-1][2]+d[i-1][3]
        if j==0 or j==3:
            d[i][0]=t
            d[i][3]=t
        elif j==1:
            d[i][1]=t-(d[i-2][0]+d[i-2][2]+(d[i-3][0]*2))
        else:
            d[i][2]=t-d[i-2][0]
    for j in range(4):
        d[i][j]=abs(d[i][j])%mod
print((d[n-1][0]+d[n-1][1]+d[n-1][2]+d[n-1][3])%mod)

Submission status: Wrong Answer

Solution code:
mod=10**9+7
n=int(input())
d=[[1,1,1,1] for i in range(100)]
d[1]=[4,4,4,4]
for i in range(2,100):
    for j in range(4):
        t=d[i-1][0]+d[i-1][1]+d[i-1][2]+d[i-1][3]
        if j==0 or j==3:
            d[i][0]=t
            d[i][3]=t
        elif j==1:
            d[i][1]=t
            #if i>2:
                #d[i][1]-=(d[i-3][0]+d[i-3][2])
            #    d[i][1]-=d[i-3][2]
            d[i][1]-=(d[i-2][0]+d[i-2][2])
        else:
            d[i][2]=t
            if i>2:
                d[i][2]-=(d[i-3][0]+d[i-3][2])
            d[i][2]-=d[i-2][0]
    for j in range(4):
        d[i][j]=abs(d[i][j])%mod
print((d[n-1][0]+d[n-1][1]+d[n-1][2]+d[n-1][3])%mod)

Submission status: Wrong Answer

Solution code:
N = int(input())

ans = 4 ** N - ((N - 2) * (3 * (4 ** (N - 3))))

if N == 4:
    ans -= 2
if N == 5:
    ans -= 6
elif N == 6:
    ans -= 10
elif N >= 7:
    ans -= 4 * (N - 6) - 10

print(ans % (10**9 + 7))

Submission status: Wrong Answer

Solution code:
N = int(input())
mod = 10**9+7

def check(s):
    for i in range(4):
        l=list(s)
        if i>0:
            l[i-1],l[i]=l[i],l[i-1]
        if "".join(l).count("AGC"):
            return False
    else:
        return True

memo=[dict() for _ in range(N)]
def dfp(i,seq):
    if i==N:
        return 1
    if seq in memo[i]:
        return memo[i][seq]
    ret=0
    for s in ["A","G","C","T"]:
        if check(seq+s):
            ret=(ret+dfp(i+1,seq[1:]+s))%mod
    memo[i][seq] = ret
    return ret

dfp(0,"TTT")

Submission status: Wrong Answer

Solution code:
# abcde	s=input()	s='abcde'
# abcde	s=list(input())	s=['a', 'b', 'c', 'd', 'e']
# 5(1つだけ)	a=int(input())	a=5
# 1 2	| x,y = s_inpl()   |	x=1,y=2
# 1 2 3 4 5 ... n 　	li = input().split()	li=['1','2','3',...,'n']
# 1 2 3 4 5 ... n 　	li = inpl()	li=[1,2,3,4,5,...,n]
# FFFTFTTFF 　	li = input().split('T')	li=['FFF', 'F', '', 'FF']

# INPUT
# 3
# hoge
# foo
# bar
# ANSWER
# n=int(input())
# string_list=[input() for i in range(n)]

import math
import copy
from collections import defaultdict
from collections import Counter
from collections import deque
# 直積 A={a, b, c}, B={d, e}:のとき，A×B={(a,d),(a,e),(b,d),(b,e),(c,d),(c,e)}: product(A, B)
from itertools import product
# 階乗 P!: permutations(seq), 順列 {}_len(seq) P_n: permutations(seq, n)
from itertools import permutations
# 組み合わせ {}_len(seq) C_n: combinations(seq, n)
from itertools import combinations
from bisect import bisect_left, bisect_right
# import numpy as np

def inside(y, x, H, W):
    return 0 <= y < H and 0 <= x < W

# 四方向: 右, 下, 左, 上
dy = [0, -1, 0, 1]
dx = [1, 0, -1, 0]

def i_inpl(): return int(input())
def s_inpl(): return map(int,input().split())
def l_inpl(): return list(map(int, input().split()))
INF = float("inf")

############
############
############


N = int(input())
MOD = 10**9+7
print(MOD)
memo = [ {} for _ in range(N+1) ]

def ok(last4):
    for i in range(4):
        t = list(last4)
        if i >= 1:
            t[i-1], t[i] = t[i], t[i-1]
        if "".join(t).count("AGC") >= 1:
            return False
    return True

def dfs(current, last3):
    if last3 in memo[current]:
        return memo[current][last3]
    if current == N:
        return 1
    ret = 0
    for c in "ACGT":
        if ok(last3 + c):
            ret = (ret + dfs(current + 1, last3[1:] + c)) % MOD
    memo[current][last3] = ret
    return ret

print(int(dfs(0, "TTT") % MOD))

Submission status: Wrong Answer

Solution code:
# abcde	s=input()	s='abcde'
# abcde	s=list(input())	s=['a', 'b', 'c', 'd', 'e']
# 5(1つだけ)	a=int(input())	a=5
# 1 2	| x,y = s_inpl()   |	x=1,y=2
# 1 2 3 4 5 ... n 　	li = input().split()	li=['1','2','3',...,'n']
# 1 2 3 4 5 ... n 　	li = inpl()	li=[1,2,3,4,5,...,n]
# FFFTFTTFF 　	li = input().split('T')	li=['FFF', 'F', '', 'FF']

# INPUT
# 3
# hoge
# foo
# bar
# ANSWER
# n=int(input())
# string_list=[input() for i in range(n)]

import math
import copy
from collections import defaultdict
from collections import Counter
from collections import deque
# 直積 A={a, b, c}, B={d, e}:のとき，A×B={(a,d),(a,e),(b,d),(b,e),(c,d),(c,e)}: product(A, B)
from itertools import product
# 階乗 P!: permutations(seq), 順列 {}_len(seq) P_n: permutations(seq, n)
from itertools import permutations
# 組み合わせ {}_len(seq) C_n: combinations(seq, n)
from itertools import combinations
from bisect import bisect_left, bisect_right
# import numpy as np

def inside(y, x, H, W):
    return 0 <= y < H and 0 <= x < W

# 四方向: 右, 下, 左, 上
dy = [0, -1, 0, 1]
dx = [1, 0, -1, 0]

def i_inpl(): return int(input())
def s_inpl(): return map(int,input().split())
def l_inpl(): return list(map(int, input().split()))
INF = float("inf")

############
############
############


N = int(input())
MOD = 10e9+7
memo = [ {} for _ in range(N+1) ]

def ok(last4):
    for i in range(4):
        t = list(last4)
        if i >= 1:
            t[i-1], t[i] = t[i], t[i-1]
        if "".join(t).count("AGC") >= 1:
            return False
    return True

def dfs(current, last3):
    if last3 in memo[current]:
        return memo[current][last3]
    if current == N:
        return 1
    ret = 0
    for c in "ACGT":
        if ok(last3 + c):
            ret = (ret + dfs(current + 1, last3[1:] + c)) % MOD
    memo[current][last3] = ret
    return ret

print(int(dfs(0, "TTT")))

Submission status: Wrong Answer

Solution code:
ngs4 = ["ATGC", "AGTC","ACGC", "AGCC","AGGC", "AGGC"]
ngs3 = ["AGC", "ACG", "GAC"]
def is_valid(b):
    s = b[-4:]
    if s in ngs4:
        return False
    s = s[-3:]
    if s in ngs3:
        return False
    return True

N = int(input())
memo = [{} for i in range(N+1)]
acgt = ["A", "C", "G", "T"]
MOD = 10**9 + 7
def dp(i, last3):
    if last3 in memo[i]:
        return memo[i][last3]

    if i == N:
        return 1
    
    ret = 0
    for c in acgt:
        candi = last3 + c
        if is_valid(candi):
            ret = (ret + dp(i+1, last3[1:] +c)) % MOD
    memo[i][last3] = ret
    return ret

def sub():
    print(dp(0, "TTT"))

Submission status: Wrong Answer

Solution code:
N = int(input())
A = [0, 1, 4, 15]  #Gで終わる
B = [1, 3, 12, 46]  #Gで終わらない

M = 10 ** 9 + 7

while N > 3 and len(A) <= N:
    a = A[-1] + B[-1] - B[-3]
    while a < 0:
        a += M
    a = a % M

    b = 3 * (A[-1] + B[-1]) - 2 * (A[-3] + B[-3]) - 3 * (A[-4] + B[-4])
    while b < 0:
        b += M
    b = b % M

    A.append(a)
    B.append(b)
    # print(a,b)
print((A[N] + B[N]) % M)

Submission status: Wrong Answer

Solution code:
import numpy as np
    
N = int(input())
MOD=7+10**9

def pattern_calc(num,i,j,k,l):
    #print(num,":",i,",",j,",",k,",",l,end="")
    
    #最終4文字がNGならパターン数0
    if calc_result[0,i,j,k,l]==0:
        #print("last 4 char is NG pattern.")
        sub_ans = 0
        
    else:
        if calc_flag[num,i,j,k,l] == True:
            sub_ans = calc_result[num,i,j,k,l]
            #print("…Calculated:",calc_result[num,i,j,k,l])
        else:
            #print("…Need  Calc :")

            for atot in range(4): 
                calc_result[num,i,j,k,l] = calc_result[num,i,j,k,l] + pattern_calc(num-1,atot,i,j,k)
                #print(pattern_calc(num-1,atot,i,j,k))
                #print(calc_result[num,i,j,k,l])
                
            calc_flag[num,i,j,k,l] = True
            sub_ans = calc_result[num,i,j,k,l]
            #print(num,":",i,",",j,",",k,",",l,"→",sub_ans)
    return sub_ans            

if N==3:
    print("61")
else:   
    calc_result = np.zeros((N-3,4,4,4,4),dtype=np.float64) #計算結果。[]の条件を満たせるのは何通りあるか?
    #ex
    #result_list[0,0,1,2,3]…最後4文字がA,G,C,TでAより前の文字数が0のパターンは満たせるか? → 0
    #result_list[1,0,1,2,3]…最後4文字がA,G,C,TでAより前の文字数が0のパターンは満たせるか? → 0


    #result_list[0,0,1,2,3]…0
    #result_list[0,1,1,2,3]…1
    #result_list[0,2,1,2,3]…1
    #result_list[0,3,1,2,3]…1

    #result_list[1,1,2,3,0]…最後4文字がG,C,T,AでGより前の文字数が1のパターンは満たせるか? → 3
    #result_list[2,2,3,0,1]…最後4文字がC,T,A,GでCより前の文字数が1のパターンは満たせるか? 
    #   →result_list[1,0,2,3,0],result_list[1,1,2,3,0],result_list[1,2,2,3,0],result_list[1,3,2,3,0]のSUM

    calc_flag = np.zeros((N-3,4,4,4,4), dtype=np.bool) #計算済みか
    #A→0,G→1,C→2,T→3として扱う。

    for i in range(4):
        for j in range(4):
            for k in range(4):
                for l in range(4):
                    calc_result[0,i,j,k,l] = 1
                    calc_flag[0,i,j,k,l] = True

    calc_result[0,0,0,1,2]=0
    calc_result[0,0,0,2,1]=0
    calc_result[0,0,1,1,2]=0
    calc_result[0,0,1,3,2]=0
    calc_result[0,0,1,2,0]=0
    calc_result[0,0,1,2,1]=0
    calc_result[0,0,1,2,2]=0
    calc_result[0,0,1,2,3]=0
    calc_result[0,0,1,0,2]=0
    calc_result[0,0,2,1,0]=0
    calc_result[0,0,2,1,1]=0
    calc_result[0,0,2,1,2]=0
    calc_result[0,0,2,1,3]=0
    calc_result[0,0,3,1,2]=0
    calc_result[0,1,0,1,2]=0
    calc_result[0,1,0,2,0]=0
    calc_result[0,1,0,2,1]=0
    calc_result[0,1,0,2,2]=0
    calc_result[0,1,0,2,3]=0
    calc_result[0,1,1,0,2]=0
    calc_result[0,2,0,2,1]=0
    calc_result[0,2,1,0,2]=0
    calc_result[0,2,0,1,2]=0
    calc_result[0,3,0,2,1]=0
    calc_result[0,3,1,0,2]=0
    calc_result[0,3,0,1,2]=0

    N = N - 4
    ans = 0
    
    for i in range(4):
        for j in range(4):
            for k in range(4):
                for l in range(4):
                    #print(N,",",i,",",j,",",k,",",l,":",int(pattern_calc(N,i,j,k,l)))
                    ans = (ans + pattern_calc(N,i,j,k,l))

    print(int(ans%MOD))

Submission status: Wrong Answer

Solution code:
N=int(input())
dp = [{} for _ in range(101)]

str = "ACGT"
mod = 10**9+7
for i in range(4):
  for j in range(4):
    for k in range(4):
      last3 = str[i] + str[j] + str[k]
      if last3 == "AGC" or last3 == "ACG" or last3 == "GAC":
        dp[3][last3] = 0
      else:
        dp[3][last3] = 1

for n in range(4,101):
  for last3 in dp[n-1]:
    for c in str:
      new_last3 = last3[1:]+c
      if new_last3 == "AGC" or new_last3 == "ACG" or new_last3 == "GAC":
        dp[n][new_last3] = 0
      else:
        if last3 == "AGC" or last3 == "ACG" or last3 == "GAC":
          if new_last3 not in dp[n]:
            dp[n][new_last3] = 0
        elif last3 == "AAG" or last3 == "AGA" or last3 == "AGG" or last3 == "AGT" or last3 == "ATG" or last3 == "CAG" or last3 == "CGA" or last3 == "GAG" or last3 == "GGA" or last3 == "TAG" or last3 == "TGA":
          if new_last3[2] != "C":
            if new_last3 not in dp[n]:
              dp[n][new_last3] = dp[n-1][last3]
            else:
              dp[n][new_last3] += dp[n-1][last3]
        elif last3 == "AAC" or last3 == "CAC" or last3 == "TAC":
          if new_last3[2] != "G":
            if new_last3 not in dp[n]:
              dp[n][new_last3] = dp[n-1][last3]
            else:
              dp[n][new_last3] += dp[n-1][last3]
        else:
          if new_last3 not in dp[n]:
            dp[n][new_last3] = dp[n-1][last3]
          else:
            dp[n][new_last3] += dp[n-1][last3]

sum = 0
for s in dp[N]:
  sum += dp[N][s] %mod

print(sum)

Submission status: Wrong Answer

Solution code:
from collections import defaultdict

N = int(input())
MOD = 10**9+7

ng = set()
for t in "AGCT":
    for n in ["?AGC", "AGC?", "A?GC", "AG?C", "GAC?", "?GAC", "ACG?", "?ACG"]:
        ng.add(n.replace('?', t))

dp = {"???": 1}
for i in range(1, N+1):
    ans = 0
    _dp = defaultdict(int)
    for k, v in dp.items():
        for t in "AGCT":
            s = k+t
            if s not in ng:
                _dp[s[1:]] += v
                ans = (ans+v) % MOD
    dp = _dp
    if i == N:
        print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())

dp = [[0] * 4 for _ in range(N)]

dp[0] = [1, 1, 1, 1]
dp[1] = [4, 4, 4, 4]
dp[2] = [16, 16, 15, 14]

if N > 3:
	for i in range(3, N):
		dp[i][0] = sum(dp[i-1])
		dp[i][1] = sum(dp[i-1])
		dp[i][2] = sum(dp[i-1]) - dp[i-3][0] - dp[i-3][1] - dp[i-3][3]
		dp[i][3] = sum(dp[i-1]) - dp[i-3][0]*5 - dp[i-3][1]*2 - dp[i-3][2]*2 - dp[i-3][3]*2

print(sum(dp[-1])%(10**9+7))

Submission status: Wrong Answer

Solution code:
N = int(input())

tot = 1 # total permutations 
for i in range(N):
  tot = tot*4 % (10**9 + 7) 
  
M = [{"AA":0,"AG":0,"AC":0,"AT":0,
     "GA":0,"GG":0,"GC":0,"GT":0,
     "CA":0,"CG":0,"CC":0,"CT":0,
     "TA":0,"TG":0,"TC":0,"TT":0} for i in range(N)]
for key in M[1]:
  M[1][key] = 1
# M[i] holds info for the last two letters for only the good ones with i+1 letters

bad = [0 for i in range(N)]
# bad[i] holds the number of bad ones with i+1 letters 

for i in range(2,N):
  # bad ones are bad no matter what the last letter is  
  bad[i] = bad[i-1] * 4
  # update Mi from Mi-1
  for keyaf in M[i]:
     for keybe in M[i-1]:
        if keybe[1] is keyaf[0]:
          M[i][keyaf] += M[i-1][keybe] 
  # subtract bad ones and add them to bad
  M[i]["GC"] -= M[i-1]["AG"]
  bad[i] += M[i-1]["AG"]
  M[i]["AC"] -= M[i-1]["GA"]
  bad[i] += M[i-1]["GA"]
  M[i]["CG"] -= M[i-1]["AC"]
  bad[i] += M[i-1]["AC"]

print(tot - bad[N-1]%(10**9+7))

Submission status: Wrong Answer

Solution code:
###AGC,GAC,ACG,A*GC,AG*Cが存在しない
###AGC,GAC,ACG,AGAC,AGGC,AGTC,ACGC,ATGC

###k-1個の組み合わせの前後に'AGCT'を付け足し、ダメな組み合わせを引いた数がk個の組み合わせ
###k-1がl個のとき、kはl*8-ダメな数

import sys

n = int(input())

if n <= 2:
  print(4**n)
  sys.exit()

end = {}
for i in ['A','G','C','T']:
  for j in ['A','G','C','T']:
    for k in ['A','G','C','T']:
      if i+j+k in ['AGC','GAC','ACG']:
        end[i+j+k] = 0
      else:
        end[i+j+k] = 1
        
num = 61
if n == 3:
  print(num)
  sys.exit()

###*AG+C
notend = ['AAG','GAG','CAG','TAG']
###*GA+C
notend += ['AGA','GGA','CGA','TGA']
###*AC+G
notend += ['AAC','CAC','TAC']
###AG*+C
notend += ['AGG','AGT']
###A*G+C
notend += ['ATG']

for i in range(4,n+1):
  
  num *= 4
  for j in end.keys():
    if j in notend:
      num -= end[j]
      end[j] = 0
      
  end_tmp = {}
  for j in end.keys():
    end_tmp[j] = 0
  
  for j in end.keys():
    for k in ['A','G','C','T']:
      end_tmp[j] += end[k+j[0:2]]
        
  end = end_tmp
  
#print(num)
print(num%(10**9+7))

Submission status: Wrong Answer

Solution code:
###AGC,GAC,ACG,A*GC,AG*Cが存在しない
###AGC,GAC,ACG,AGAC,AGGC,AGTC,ACGC,ATGC

###k-1個の組み合わせの前後に'AGCT'を付け足し、ダメな組み合わせを引いた数がk個の組み合わせ
###k-1がl個のとき、kはl*8-ダメな数

import sys

n = int(input())

if n <= 2:
  print(4**n)
  sys.exit()

end = {}
for i in ['A','G','C','T']:
  for j in ['A','G','C','T']:
    for k in ['A','G','C','T']:
      if i+j+k in ['AGC','GAC','ACG']:
        end[i+j+k] = 0
      else:
        end[i+j+k] = 1
        
num = 61
if n == 3:
  print(num)
  sys.exit()

###*AG+C
notend = ['AAG','GAG','CAG','TAG']
###*GA+C
notend += ['AGA','GGA','CGA','TGA']
###*AC+G
notend += ['AAC','CAC','TAC']
###AG*+C
notend += ['AGG','AGT']
###A*G+C
notend += ['ATG']

for i in range(4,n+1):
  
  num *= 4
  for j in end.keys():
    if j in notend:
      num -= end[j]
      end[j] = 0
      
  end_tmp = {}
  for j in end.keys():
    end_tmp[j] = 0
  
  for j in end.keys():
    for k in ['A','G','C','T']:
      end_tmp[j] += end[k+j[0:2]]
        
  end = end_tmp
  
print(num)
print(num%(10**9+7))

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
import sys
import itertools

MOD = 1000000007  # type: int


def ok(s: str):
    ng = 'AGC'
    c = s.count(ng)
    for i in range(1, 4):
        s2 = s[:i-1] + s[i] + s[i-1] + s[i+1:]
        c += s2.count(ng)
    return c == 0
    

def solve(N: int):
    K = [''.join(t) for t in itertools.product('ACGT', repeat=3)]
    C = [{k: 0 for k in K} for i in range(N+2)] # C[-1 ~ N]
    C[0]['TTT'] = 1
    
    for i in range(1, N+1):
        for last3 in C[i-1].keys():
            for c in 'ACGT':
                if ok(last3 + c):
                    C[i][last3[1:] + c] = (C[i][last3[1:] + c] + C[i-1][last3]) % MOD
    print(sum([C[N][k] for k in K]))
    return


# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    solve(N)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
N = int(input())
MOD = 10**9+7
memo = [{} for _ in range(N+1)]

def ok(last4):
    for i in range(4):
        t = list(last4)
        if i >= 1:
            t[i-1],t[i] = t[i],t[i-1]
            if ''.join(t).count('AGC') >= 1:
                return False
        return True

def dfs(cur,last3):
    if last3 in memo[cur]:
        return memo[cur][last3]
    if cur == N:
        return 1
    ret = 0
    for c in 'AGCT':
        if ok(last3+c):
            ret = (ret + dfs(cur+1,last3[1:]+c)) % MOD
    memo[cur][last3] = ret
    return ret

print(dfs(0,'TTT'))

Submission status: Wrong Answer

Solution code:
n=int(input())
a1,a2,a3,a4,c1,c2,c3,c4,g1,g2,g3,g4,t1,t2,t3,t4=1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1
for i in range(n-2):
  a1,a2,a3,a4,c1,c2,c3,c4,g1,g2,g3,g4,t1,t2,t3,t4=a1+a2+a3+a4,c1+c2+c4,g1+g3+g4,t1+t2+t3+t4,a1+a2+a3+a4,c1+c2+c3+c4,g1+g2+g3+g4,t1+t2+t3+t4,a1+a3+a4,c1+c2+c3+c4,g1+g2+g3+g4,t1+t2+t3+t4,a1+a2+a3+a4,c1+c2+c3+c4,g1+g2+g3+g4,t1+t2+t3+t4
print((a1+a2+a3+a4+c1+c2+c3+c4+g1+g2+g3+g4+t1+t2+t3+t4)%(10**9+7))

Submission status: Wrong Answer

Solution code:
n=int(input())
a1,a2,a3,a4,c1,c2,c3,c4,g1,g2,g3,g4,t1,t2,t3,t4=1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1
for i in range(n-2):
  a1,a2,a3,a4,c1,c2,c3,c4,g1,g2,g3,g4,t1,t2,t3,t4=a1+a2+a3+a4,c1+c2+c4,g1+g3+g4,t1+t2+t3+t4,a1+a2+a4,c1+c2+c3+c4,g2+g3+g4,t1+t2+t3+t4,a1+a3+a4,c2+c3+c4,g1+g2+g3+g4,t1+t2+t3+t4,a1+a2+a3+a4,c1+c2+c3+c4,g1+g2+g3+g4,t1+t2+t3+t4
print((a1+a2+a3+a4+c1+c2+c3+c4+g1+g2+g3+g4+t1+t2+t3+t4)%(10**9+7))

Submission status: Wrong Answer

Solution code:
N = int(input())
mod = 10 ** 9 + 7

memo = [{} for i in range(N+1)]


def ok(last4):
    for i in range(4):
        t = list(last4)
        if i >= 1:
            t[i-1], t[i] = t[i-1], t[i]
        if ''.join(t).count('AGC') >= 1:
            return False
    return True


def dfs(cur, last3):
    if last3 in memo[cur]:
        return memo[cur][last3]
    if cur == N:
        return 1
    ret = 0
    for c in 'ATCG':
        if ok(last3 + c):
            ret = (ret + dfs(cur + 1, last3[1:]+c)) % mod
    memo[cur][last3] = ret
    #print(memo, cur)
    return ret


print(dfs(0, 'TTT'))

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Sat Feb 16 20:52:46 2019

@author: Owner
"""


import collections
import scipy.misc
import sys
import numpy as np
import math
from operator import itemgetter
import itertools
import copy
import bisect

#素因数を並べる
def prime_decomposition(n):
  i = 2
  table = []
  while i * i <= n:
    while n % i == 0:
      n /= i
      table.append(int(i))
    i += 1
  if n > 1:
    table.append(int(n))
  return table   
# 桁数を吐く
def digit(i):
    if i > 0:
        return digit(i//10) + [i%10]
    else:
        return []
    
def getNearestValueIndex(list, num):
    """
    概要: リストからある値に最も近い値のインデックスを取得する関数
    @param list: データ配列
    @param num: 対象値
    @return 対象値に最も近い値
    """

    # リスト要素と対象値の差分を計算し最小値のインデックスを取得
    idx = np.abs(np.asarray(list) - num).argmin()
    return idx

def find_index(l, x, default=False):
    if x in l:
        return l.index(x)
    else:
        return default


"""
N, X = map(int, input().split())

x = [0]*N
x[:] = map(int, input().split())

P = [0]*N
Y = [0]*N
for n in range(N):
    P[n], Y[n] = map(int, input().split())

    
all(nstr.count(c) for c in '753')

# 複数配列を並び替え
ABT = zip(A, B, totAB)
result = 0
# itemgetterには何番目の配列をキーにしたいか渡します
sorted(ABT,key=itemgetter(2))
A, B, totAB = zip(*ABT)
A.sort(reverse=True)

# 2進数のbit判定
(x >> i) & 1

# dp最小化問題
dp = [np.inf]*N
for n in range(N):
    if n == 0:
        dp[n] = 0
    else:
        for k in range(1,K+1):
            if n-k >= 0:
                dp[n] = min(dp[n], dp[n-k] + abs(h[n]-h[n-k]))
            else:
                break

"""

N = int(input())
dp = [[[[0]*4]*4]*4]*(N+1)
dp[0][3][3][3] = 1
mod = 10**9+7
for n in range(N):
    for i in range(4):
        for j in range(4):
            for k in range(4):
                for now in range(4):
                    if now == 0 and i == 1 and j == 2:
                        continue
                    if now == 0 and i == 2 and j == 1:
                        continue
                    if now == 1 and i == 0 and j == 2:
                        continue
                    if now == 0 and i == 3 and j == 1 and k==2:
                        continue
                    if now == 0 and i == 1 and j == 3 and k==2:
                        continue
                    dp[n+1][now][i][j] = dp[n][i][j][k]
                    dp[n+1][now][i][j] %= mod
res = 0
for i in range(4):
    for j in range(4):
        for k in range(4):
            res += dp[N][i][j][k]
            res %= mod
   

print(res)

Submission status: Wrong Answer

Solution code:
n = int(input())
dp = [{} for i in range(n + 1)]
s = "AGCT"

for j in range(n + 1):
  for c1 in s:
    for c2 in s:
      for c3 in s:
        dp[j][c1 + c2 + c3] = 0

dp[0]["TTT"] = 1

for l in range(n):
  for c1 in s:
    for c2 in s:
      for c3 in s:
        for p in s:
          if c2 == "A" and c3 == "G" and p == "C":
            continue
          if c1 == "A" and c3 == "G" and p == "C":
            continue
          if c1 == "A" and c2 == "G" and p == "C":
            continue
          if c2 == "G" and c3 == "A" and p == "C":
            continue
          if c2 == "A" and c3 == "C" and p == "G":
            continue
          dp[l + 1][c2 + c3 + p] += dp[l][c1 + c2 + c3]

ans = 0
for c1 in s:
  for c2 in s:
    for c3 in s:
      ans += dp[n][c1 + c2 + c3]
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
ng = ["agc", "aagc", "acgc", "aggc", "atgc", "agac", "agcc", "aggc", "agtc", "acg", "gac"]
x = {"a": 1, "g": 1, "c": 1, "t": 1}

for _ in range(1,N):
    y = dict()
    for let,num in x.items():
        for a in ["a", "g", "c", "t"]:
            if let + a in ng or (let + a)[-3:] in ng:
                continue
            else:
                if let[-3:] + a in y.keys():
                    y[let[-3:] + a] += num
                else:
                    y[let[-3:]+a] = num
    x = y

print(sum(x.values()) % (10**9+7))

Submission status: Wrong Answer

Solution code:
N=int(input())
MOD=10**9+7

dp={b:1 for b in "ACGT"}

for _ in range(N-1):
  dp_new={}
  for k in dp:
    for b in "ACGT":
      new=k[-3:]+b
      if new in ("AGC","GAC","ACG","AGGC","ATGC","ACGC","AGAC","AGTC","AGGC"):
        continue
      else:
        dp_new.setdefault(new,0)
        dp_new[new]+=dp[k]
  dp=dp_new

print(sum(dp.values())%MOD)

Submission status: Wrong Answer

Solution code:
N, MOD = int(input()), 10**9 + 7
memo = [{} for i in range(N+1)]

def ok(last4):
    for i in range(4):
        t = list(last4)
        if i >= 1:
            t[i-1], t[i] = t[i], t[i-1]
        if "".join(t).count("AGC") >= 1:
            return False
    return True

def dfs(cur, last3):
    if last3 in memo[cur]:
        return memo[cur][last3]
    if cur == N:
        return 1
    ret = 0
    for c in "ACGT":
        if ok(last3 + c):
            ret = (ret + dfs(cur + 1, last3[1:] + c)) % MOD
    memo[cur][last3] = ret
    return ret

print(dfs(0, "TTT"))
print(memo)

Submission status: Wrong Answer

Solution code:
n = int(input())

MOD = 1000000007

if n == 3:
    print(61)
    exit()

ans = 4 ** n - (4**(n-3) * (n-2) * 3) - (2 * 4**(n-4) * (n-3)) + (4**(n-5) * (n-4))
print(int(ans) % MOD)

Submission status: Wrong Answer

Solution code:
n = int(input())

MOD = 1000000007

if n == 3:
    print(230)
    exit()

ans = 4 ** n - (4**(n-3) * (n-2) * 3) - (2 * 4**(n-4) * (n-3)) + (4**(n-5) * (n-4))
print(int(ans) % MOD)

Submission status: Wrong Answer

Solution code:
n = int(input())

MOD = 1000000007


ans = 4 ** n - (4**(n-3) * (n-2) * 3) - (2 * 4**(n-4) * (n-3))
print(int(ans) % MOD)

Submission status: Wrong Answer

Solution code:
def ok (last4):
    t = list(last4)
    for i in range(4):
        if i >=1:
            t[i-1],t[i] = t[i],t[i-1]
        if "".join(t).count("AGC")>=1:
            return False
    return True
def dfs (cur,last3):
    if last3 in memo[cur]:
        return memo[cur][last3]
    if cur==N:
        return 1
    res =0
    for c in "AGCT":
        if ok(last3+c):
            res += dfs(cur+1,last3[1:]+c)%mod
    memo[cur][last3]=res
    return res
mod = 10**9+7
N = int(input())
memo=[{} for _ in range(N+1)]

print(dfs(0,"TTT"))

Submission status: Wrong Answer

Solution code:
N = int(input())

MOD = int(10e9+7)

tokens = ['A','C','G','T']

suffixes = []
for suffix_1 in tokens:
    for suffix_2 in tokens:
        for suffix_3 in tokens:
            suffixes.append(suffix_1+suffix_2+suffix_3)

dp = [[0 for _ in suffixes] for _ in range(N+1)]

reverse_index = {}
for i,s in enumerate(suffixes):
    reverse_index[s] = i

def pprint(dp):
    N = len(dp)
    M = len(dp[0])

    for i in dp:
        st = ""
        for j in i:
            st += str(j)
            st += " "
        print(st)

for i,s in enumerate(suffixes):
    if not s in ['AGC', 'ACG', 'GAC']:
        dp[3][i]  = 1

valid_str_4 = set()


        
def swap(s, i ,j):
    s_new = [c for c in s]
    s_new[i] = s[j]
    s_new[j] = s[i]
    return ''.join(s_new)

def valid(str4):
    if 'AGC' in str4:
        return False
    for i in range(len(str4)-1):
        s_new = swap(str4, i, i+1)
        if 'AGC' in s_new:
            return False
    return True

for s in suffixes:
    for c in tokens:
        ss = s+c
        if valid(ss):
            valid_str_4.add(ss)

for n in range(4, N+1):
    for s in suffixes:
        for c in tokens:
            ss = s+c
            if ss in valid_str_4:
                dp[n][reverse_index[ss[1:]]]+= dp[n-1][reverse_index[s]]
                dp[n][reverse_index[ss[1:]]] %= MOD

print(sum(dp[N]) % MOD)

Submission status: Wrong Answer

Solution code:
n = int(input())
memo = [{} for i in range(n+1)]
m = 10**9+7

def ppp(l):
    for i in range(4):
        t = list(l)
        if i >= 1:
            t[i-1],t[i] = t[i],t[i-1]
        if "".join(t).count("AGC") >= 1:
            return False
        return True
def dfs(c,l):
    if l in memo[c]:
        return memo[c][l]
    if c == n:
        return 1
    ret = 0
    for b in "AGCT":
        if ppp(l+b):
            ret = (ret + dfs(c + 1,l[1:] + b)) % m
    memo[c][l] = ret
    return ret
print(dfs(0,"TTT"))

Submission status: Wrong Answer

Solution code:
print(4**100%(10**9+7))

Submission status: Wrong Answer

Solution code:
N, MOD = int(input()), 10 ** 9 + 7
memo = [{} for i in range(N+1)]

def ok(last4):
	for i in range(4):
		t = list(last4)
	if i >= 1:
		t[i-1], t[i] = t[i], t[i-1]
	if ''.join(t).count('AGC') >= 1:
		return False
	return True
  
def dfs(cur, last3):
	if last3 in memo[cur]:
		return memo[cur][last3]
	if cur == N:
		return 1
	ret = 0
	for c in 'ACGT':
		if ok(last3 + c):
			ret = (ret + dfs(cur + 1, last3[1:] + c)) % MOD
	memo[cur][last3] = ret
	return ret

print(dfs(0, 'TTT'))

Submission status: Wrong Answer

Solution code:
#貰うDP
import itertools
N, MOD = int(input()), 10**9+7
memo = [{'AGC':0, 'ACG':0, 'GAC':0} for i in range(N + 1)]
C = list('ACGT')
for c in itertools.product(C, C, C):
    c = ''.join(c)
    if c in memo[3]:
        continue
    else:
        memo[3][c] = 1

def ok(last4):
    for i in range(4):
        t = list(last4)
        if i>= 1:
            t[i-1], t[i] = t[i], t[i-1]
            if ''.join(t).count('AGC') == 1:
                return False
    return True

def dfs(cur, last3):
    if last3 in memo[cur]:
        return memo[cur][last3]
    ret = 0
    for c in 'ACGT':
        if ok(c + last3):
            ret = (ret + dfs(cur - 1, c + last3[:-1])) % MOD
    memo[cur][last3] = ret
    return ret

def answer(n):
    ans = 0
    clist = list('ACGT')
    for c in itertools.product(clist, clist, clist):
        ch = ''.join(c)
        ans += dfs(n, ch)
    return ans

print(answer(N))

Submission status: Wrong Answer

Solution code:
n = int(input())
mem = [{} for i in range(n + 1)]

first3s = []
for c in 'ACGT':
	for c2 in 'ACGT':
		for c3 in 'ACGT':
			first3s.append(c + c2 + c3)

ans = 0
for three in first3s:
  mem[3][three] = 0 if three in ['AGC', 'ACG', 'GAC'] else 1
  ans += mem[3][three]

def check4(four):
  if 'AGC' in four:
    return False
  for i in range(3):
    if 'AGC' in four[:i] + four[i+1] + four[i] + four[i+2:]:
      return False
  return True

if n > 3:
  ans = 0
  for i in range(4, n + 1):
    for three in first3s:
      for c in 'ACGT':
        four = c + three
        if check4(four):
          ans = (ans + mem[i - 1][three]) % (10**9 + 7)
          mem[i][(c + three)[:3]] = (mem[i].get((c + three)[:3], 0) + mem[i - 1][three]) % (10**9 + 7)
print(ans)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-

N = int(input())

# A C G T を
# 0 1 2 3 と置く

dp = [[[[0 for i in range(4)] for j in range(4)] for k in range(4)] for l in range(101)]
dp[0][3][3][3] = 1

mod = 10**9+7

#文字列の文字数
for len in range(N):
    #最後から1文字目の文字
    for c1 in range(4):
        #最後から2文字目の文字
        for c2 in range(4):
            #最後から3文字目の文字
            for c3 in range(4):
                #新しく追加する文字
                for a in range(4):
                    if c2 == 0 and c1 == 1 and a == 2 :
                        continue #012
                    if c2 == 1 and c1 == 0 and a == 2 :
                        continue #102
                    if c2 == 0 and c1 == 2 and a == 1 :
                        continue #021
                    if c3 == 0 and c1 == 1 and a == 2 :
                        continue #0?12
                    if c3 == 0 and c2 == 1 and a == 2 :
                        continue #01?2
                    
                    dp[len + 1][c2][c1][a] += dp[len][c3][c2][c1]
                    dp[len + 1][c2][c1][a] %= mod
        
ans = 0

#最後から1文字目の文字
for c1 in range(4):
    #最後から2文字目の文字
    for c2 in range(4):
        #最後から3文字目の文字
        for c3 in range(4): 
            ans += dp[N][c3][c2][c1]

print(ans)