Harryxun/GPT-100-sft-dataset huggingface dataset:
Problem p02717 (python)

Fixed submission:
A, B, C = [int(i) for i in input().split()]

A, B, C = B, A, C
A, B, C = C, B, A

print("%s %s %s" % (A, B, C))

Buggy submission (verdict: Runtime Error):
A, B, C = [int(i) for i in input().split()]

A, B, C = B, A, C
A, B, C = C, B, A

print(f"{A} {B} {C}")
Problem p02927 (python)

Fixed submission:
def takahashi_cal(m: int, d: int) -> int:
    res = 0
    for mm in range(1, m + 1):
        for dd in range(1, d + 1):
            d1 = dd % 10
            d10 = dd // 10
            if any([d1 < 2, d10 < 2]):
                continue
            if d1 * d10 == mm:
                res += 1
    return res
    
m, d = input().split(" ")
print(takahashi_cal(int(m), int(d)))

Buggy submission (verdict: Runtime Error):
def takahashi_cal(m: int, d: int) -> int:
    res = 0
    for mm in range(1, m + 1):
        for dd in range(1, d + 1):
            d1 = dd % 10
            d10 = dd // 10
            if any([d1 < 2, d10 < 2]):
                continue
            if d1 * d10 == mm:
                res += 1
    return res
  
  m, d = input().split(" ")
  print(takahashi_cal(m, d))
Problem p02600 (python)

Fixed submission:
X = int(input())

if X in range(400,600):
  print(8)
elif X in range(600,800):
  print(7)
elif X in range(800,1000):
  print(6)
elif X in range(1000,1200):
  print(5)
elif X in range(1200,1400):
  print(4)
elif X in range(1400,1600):
  print(3)
elif X in range(1600,1800):
  print(2)
else:
  print(1)

Buggy submission (verdict: Runtime Error):
X = int(input())

if X in range(400,600):
  print(8)
elif X in range(600,800)
  print(7)
elif X in range(800,1000)
  print(6)
elif X in range(1000,1200)
  print(5)
elif X in range(1200,1400)
  print(4)
elif X in range(1400,1600)
  print(3)
elif X in range(1600,1800)
  print(2)
elif X in range(1800,1900)
  print(1)
Problem p02612 (python)

Fixed submission:
print((1000-(int(input())%1000))%1000)

Buggy submission (verdict: Runtime Error):
n = int(input())
print(a=n//1000)
Problem p03067 (python)

Fixed submission:
def check_between(a,b,c):
    if  (b < c) and (c < a) :
        print('Yes')
    elif (a < c) and (c <b) :
        print('Yes')
    else:
        print('No')

a, b, c = map(int, input().split())
check_between(a,b,c)

Buggy submission (verdict: Runtime Error):
def remove_fwhite(S):
    fwhite = 0
    for fw in S:
        if fw == '.':
            fwhite += 1
        else:
            break
    return fwhite

def remove_fblack(S):
    fblack = 0
    for fb in S[::-1]:
        if fb == '#':
            fblack += 1
        else:
            break
    return fblack

def count_stone(S):
    black = 0
    white = 0
    for stone in S:
        if stone == '#':
            black += 1
        else:
            white += 1
    print(min(black,white))

N = int(input())
S = str(input())


fw = remove_fwhite(S)
fb = remove_fblack(S)
#print('fw:')
#print(fw)
#print('fb:')
#print(fb)
#print(S[fw:N-fb])
if fw == 0 or fb == 0:
    count_stone(S)
elif fw == N:
    print('0')
else:
    count_stone(S[fw:N-fb])
Problem p03071 (python)

Fixed submission:
def check_max_coin(a,b):
  max_coin = 0
  for i in range(1,3):
    if a < b :
      max_coin += b 
      b-=1 
    else:
      max_coin += a  
      a-=1    
  print(max_coin)
  
a, b = map(int, input().split())
check_max_coin(a,b)

Buggy submission (verdict: Runtime Error):
def check_max_coin(a,b):
  max_coin = 0
  for i in range(1:3):
    if a < b :
      max_coin += b 
    else:
      max_coin += a      
  print(max_coin)
  
a, b = map(int, input().split())
check_max_coin(a,b)
Problem p03210 (python)

Fixed submission:
def age_check(age):
  if age == 3 or age == 5 or age == 7:
    print('YES')
  else:
    print('NO')
 
age = int(input())
 
age_check(age)

Buggy submission (verdict: Runtime Error):
def age_check(age):
  if age ==3:
    print('YES')
  else age == 5:
    print('YES')
  else age == 7:
    print('YES')
  else:
    print('NO')

age = input()

age_check(age)

Buggy submission (verdict: Runtime Error):
def age_check(age):
    if age ==3:
        print('YES')
    else age == 5:
        print('YES')
    else age == 7:
        print('YES')
    else:
        print('NO')

age = input()

age_check(age)
Problem p02601 (python)

Fixed submission:
import itertools

a, b, c = map(int, input().split(" "))
k = int(input())
f = False
for conb in list(itertools.combinations_with_replacement([0, 1, 2], k)):
    a_i = conb.count(0)
    b_i = conb.count(1)
    c_i = conb.count(2)
    
    if (a * (2 ** a_i) < b * (2 **b_i)) and (b * (2 ** b_i) < c * (2 ** c_i)):
        f = True

if f:
    print("Yes")
else:
    print("No")

Buggy submission (verdict: Runtime Error):
a, b, c = map(int, input().split(" "))
k = int(input())
f = False
for conb in list(itertools.combinations_with_replacement([0, 1, 2], k)):
    a_i = conb.count(0)
    b_i = conb.count(1)
    c_i = conb.count(2)
    
    if (a * (2 ** a_i) < b * (2 **b_i)) and (b * (2 ** b_i) < c * (2 ** c_i)):
        f = True

if f:
    print("Yes")
else:
    print("No")
Problem p02612 (python)

Fixed submission:
pyment = int(input())
if pyment % 1000 == 0:
    print(0)
else:
    print(1000 - int(pyment % 1000))

Buggy submission (verdict: Runtime Error):
in = int(input())
print(int(in % 1000))
Problem p02830 (python)

Fixed submission:
n = input()
a, b = input().split(" ")
output = ""
for s, t in zip(a, b):
    output += s
    output += t
print(output)

Buggy submission (verdict: Runtime Error):
n = input()
a = input()
b = input()

output = ""

for s, t in zip(a, b):
    output += a
    output += b
print(output)
Problem p02639 (python)

Fixed submission:
l = list(map(int, input().split()))
     
for i in range(5):
  if l[i] == 0:
    print(i + 1)

Buggy submission (verdict: Runtime Error):
l = list(map(int, input().split()))

for i in range(5):
  if l[i] == 0
    print(i + 1)
Problem p02658 (python)

Fixed submission:
def product(list):
    num = 1

    if any([i == 0 for i in num_list]):
        print(0)
        return
     
    for i in num_list:
        num *= i
        if num > 1000000000000000000:
            num = -1
            break

    print(num)


N = int(input())

num_list = list(map(int, input().split()))

product(num_list)

Buggy submission (verdict: Runtime Error):
N = int(input())

num_list = list(map(int, input().split()))
     
num = 1
     
for i in num_list:
    num *= i
    
    if num == 0:
        break

if num > 1000000000000000000:
    num = -1
    break

print(num)
Problem p02681 (python)

Fixed submission:
S = input()
T = input()
     
if S == T[:-1]:
  print('Yes')
else:
  print('No')

Buggy submission (verdict: Runtime Error):
S = input()
T = input()
     
T.pop(-1)
     
if S == T:
  print('Yes')
else:
  print('No')

Buggy submission (verdict: Runtime Error):
S = input()
T = input()

T.pop(len(T) - 1)

if S == T:
  print('Yes')
else:
  print('No')
Problem p02887 (python)

Fixed submission:
def main():
    N = input_int()
    S = input()

    validitylist = [False] * N
    validitylist[0] = True

    for i in range(1, N):
        if S[i-1] != S[i]:
            validitylist[i] = True
    
    print(len([i for i in validitylist if i is True]))



def input_int():
    return int(input())


def input_int_tuple():
    return map(int, input().split())


def input_int_list():
    return list(map(int, input().split()))


main()

Buggy submission (verdict: Runtime Error):
def main():
    N = input_int()
    S = input()

    print(len(rec(S)))


def rec(s):
    if len(s) <= 1:
        return s

    i = 0

    while i + 1 in range(len(s)) and s[i] == s[i+1]:
        i += 1

    return s[0] + rec(s[i+1:])


def input_int():
    return int(input())


def input_int_tuple():
    return map(int, input().split())


def input_int_list():
    return list(map(int, input().split()))


main()

Buggy submission (verdict: Runtime Error):
def main():
    N = input_int()
    S = input()

    print(len(rec(S)))


def rec(s):
    if len(s) <= 1:
        return s

    i = 0

    while i + 1 in range(len(s)) and s[i] == s[i+1]:
        i += 1

    return s[0] + rec(s[i+1:])


def input_int():
    return int(input())


def input_int_tuple():
    return map(int, input().split())


def input_int_list():
    return list(map(int, input().split()))


main()

Buggy submission (verdict: Runtime Error):
def main():
    N = input_int()
    S = input()

    print(len(rec(S)))
    print(rec(S))


def rec(s):
    if len(s) <= 1:
        return s

    i = 0

    while i + 1 in range(len(s)) and s[i] == s[i+1]:
        i += 1

    return s[0] + rec(s[i+1:])


def input_int():
    return int(input())


def input_int_tuple():
    return map(int, input().split())


def input_int_list():
    return list(map(int, input().split()))


main()
Problem p03160 (python)

Fixed submission:
def main():
    N = input_int()
    h = input_int_list_in_line()

    DP = [0] * N

    DP[1] = abs(h[0] - h[1])

    for i in range(2, N):
        one_hop = abs(h[i] - h[i - 1])
        two_hop = abs(h[i] - h[i - 2])

        if DP[i - 1] + one_hop < DP[i - 2] + two_hop:
            DP[i] += DP[i - 1] + one_hop
        else:
            DP[i] += DP[i - 2] + two_hop

    print(DP[-1])


def input_int():
    return int(input())


def input_ints():
    return map(int, input().split())


def input_int_list_in_line():
    return list(map(int, input().split()))


def input_int_tuple_list(n: int, q: int):
    return [tuple(map(int, input().split())) for _ in range(n)]


main()

Buggy submission (verdict: Runtime Error):
def main():
    N = input_ints()
    h = input_int_list_in_line()

    DP = [0] * N

    DP[1] = abs(h[0] - h[1])

    for i in range(2, N):
        one_hop = abs(h[i] - h[i - 1])
        two_hop = abs(h[i] - h[i - 2])

        if DP[i - 1] + one_hop < DP[i - 2] + two_hop:
            DP[i] += DP[i - 1] + one_hop
        else:
            DP[i] += DP[i - 2] + two_hop

    print(DP[-1])


def input_int():
    return int(input())


def input_ints():
    return map(int, input().split())


def input_int_list_in_line():
    return list(map(int, input().split()))


def input_int_tuple_list(n: int, q: int):
    return [tuple(map(int, input().split())) for _ in range(n)]


main()
Problem p02697 (python)

Fixed submission:
N,M = list(map(int,input().strip().split()))

K = N//2
ans = []

if N == 3:
    ans = [(1,2)]
elif N == 4:
    ans = [(1,2)]
elif N == 5:
    ans = [(1,2),(3,5)]
else:
    left = 1
    right = K
    while left<right:
        ans += [(left,right)]
        left+=1
        right-=1

    left = K+1
    right = N
    if (right-left)%2 == (K-1)%2:
        right -= 1
    while left<right:
        ans += [(left,right)]
        left += 1
        right -= 1

for i in range(M):
    print(ans[i][0],ans[i][1])

Buggy submission (verdict: Runtime Error):
N,M = list(map(int,input().strip().split()))
K = N//2
ans = []
left = 1
right = K
while left<right:
    ans += [(left,right)]
    left+=1
    right-=1

left = K+1
right = N
if (right-left)%2 == (K-1)%2:
    right -= 1
while left<right:
    ans += [(lfet,right)]
    left += 1
    right -= 1

for i in range(M):
    print(ans[i][0],ans[i][1])
Problem p02716 (python)

Fixed submission:
def find(A):
    N = len(A)
    ans = [0]*N
    odd_sum = [0]*N
    even_sum = [0]*N
    for i in range(N):
        if i%2 == 0:
            if i-2>=0:
                even_sum[i] = even_sum[i-2] + A[i]
            else:
                even_sum[i] = A[i]
        else:
            if i-2>=0:
                odd_sum[i] = odd_sum[i-2] + A[i]
            else:
                odd_sum[i] = A[i]

#     print(odd_sum)
#     print(even_sum)
    for i in range(1,N):
        length = i+1
        if length%2==0:
            ans[i] = max(A[i] + ans[i-2],odd_sum[i-1]+even_sum[i-1] )
        else:
            ans[i] = max(A[i] + ans[i-2],ans[i-1])
            
    return ans[-1]
    
input()   
print(find(list(map(int,input().strip().split()))))

Buggy submission (verdict: Runtime Error):
def find(A):
    N = len(A)
    ans = [0]*N
    odd_sum = [0]*N
    even_sum = [0]*N
    for i in range(N):
        if i%2 == 0:
            if i-2>=0:
                even_sum[i] = even_sum[i-2] + A[i]
            else:
                even_sum[i] = A[i]
        else:
            if i-2>=0:
                odd_sum[i] = odd_sum[i-2] + A[i]
            else:
                odd_sum[i] = A[i]
    if N%2==0:
        return max(odd_sum[-1],even_sum[-2])
    
    def find_ans(M):
        if M==3:
            return max(A[0],A[1],A[2])
        elif M==2:
            return max(A[0],A[1])
        elif M==1:
            return 0
        
        if M%2==0:
            return max(even_sum[M-2],odd_sum[M-1])
        else:
            temp1 = A[M-1] + find_ans(M-2)
            temp2 = find_ans(M-1)
            return max(temp1,temp2)
    return find_ans(N)
input()
A = list(map(int,input().strip().split()))
print(find(A))
Problem p02939 (python)

Fixed submission:
import functools
def find(s):
    dp=[]
    for i in range(len(s)):
        if i==0:
            dp+=[1]
        elif i==1:
            if s[0]==s[1]:
                dp+=[1]
            else:
                dp+=[2]
        else:
            if s[i]==s[i-1]:
                if i-3>=0:
                    dp+=[dp[i-3]+2]
                else:
                    dp+=[2]
            else:
                dp+=[dp[-1]+1]
    return dp[-1]
print(find(input()))

Buggy submission (verdict: Runtime Error):
import functools
def find(s):
    
    A=[s]
    @functools.lru_cache()
    def findout(k):
        s=A[0]
        if k==1:
            return 1
        if k==2:
            if s[0]==s[1]:
                return 1
            else:
                return 2
        if s[k-1]==s[k-2]:
            return findout(k-3)+2
        else:
            return findout(k-1)+1
    return findout(len(s))
        
print(find(input()))
Problem p02969 (python)

Fixed submission:
r=int(input())
print(3*r**2)

Buggy submission (verdict: Runtime Error):
r=input()
print(3*r**2)
Problem p02975 (python)

Fixed submission:
def find(A):
    N=len(A)
    dic={}
    for i in range(len(A)):
        if A[i] in dic:
            dic[A[i]]+=1
        else:
            dic[A[i]]=1
            
    if len(dic)>3:
        return False
    
    if len(dic)==1:
        if 0 in dic:
            return True
        else:
            return False
    
    if len(dic)==2:
        if N%3!=0:
            return False
        temp=[]
        for x in dic:
            temp+=[dic[x]]
        n=N//3
        temp=sorted(temp)
        if (temp[0],temp[1])!=(n,2*n):
            return False
        
        if 0 not in dic:
            return False
        
        n1=dic[0]
        if n1==n:
            return True
        return False
    
    if len(dic)>3:
        return False
    
    if len(dic)==3 and N%3!=0:
        return False
    
    temp=[dic[x] for x in dic]
    if temp[0]!=temp[1] or temp[1]!=temp[2] or temp[2]!=temp[0]:
        return False
    
    a,b,c=[x for x in dic]
    if a^b==c or b^a==c or c^b==a:
        return True
    return False
    
input()
A=list(map(int,input().strip().split(' ')))
if find(A):
    print("Yes")
else:
    print("No")

Buggy submission (verdict: Runtime Error):
def find(A):
    dic={}
    for i in range(len(A)):
        if A[i] in dic:
            dic[A[i]]+=1
        else:
            dic[A[i]]=1
    if len(dic)==1:
        if 0 in dic:
            return True
        else:
            return False
    
    if len(dic)==2:
        if N%3!=0:
            return False
        temp=[]
        for x in dic:
            temp+=[dic[x]]
        n=N//3
        temp=sorted(temp)
        if (temp[0],temp[1])!=(n,2*n):
            return False
        
        if 0 not in dic:
            return False
        
        n1=dic[0]
        if n1==n:
            return True
        return False
    
    if len(dic)>3:
        return False
    
    if len(dic)==3 and N%3!=0:
        return False
    
    temp=[dic[x] for x in dic]
    if temp[0]!=temp[1] or temp[1]!=temp[2] or temp[2]!=temp[0]:
        return False
    
    a,b,c=[x for x in dic]
    if a^b==c or b^a==c or c^b==a:
        return True
    return False
    
input()
A=list(map(int,input().strip().split(' ')))
if find(A):
    print("Yes")
else:
    print("No")
Problem p03061 (python)

Fixed submission:
N=int(input())
A=list(map(int,input().strip().split(' ')))

def gcd(x, y): 
  
   while(y): 
       x, y = y, x % y 
  
   return x 
  

GG=[0]*N
GG[0]=A[0]
for i in range(1,N):
    GG[i]=gcd(GG[i-1],A[i])

GG2=[0]*N
GG2[-1]=A[-1]

for i in range(2,N+1):
    GG2[-i]=gcd(GG2[-(i-1)],A[-i])

ans=[0]*N

ans[0]=GG2[1]
ans[-1]=GG[N-2]
#print(GG)
#print(GG2)
#print(ans)


temp=ans[0]
for i in range(1,N-1):
    ans[i]=gcd(GG[i-1],GG2[i+1])
    if ans[i]>temp:
        temp=ans[i]
if ans[-1]>temp:
    temp=ans[-1]


print(temp)

Buggy submission (verdict: Runtime Error):
import math
N=int(input())
A=list(map(int,input().strip().split(' ')))



GG=[0]*N
GG[0]=A[0]
for i in range(1,N):
    GG[i]=math.gcd(GG[i-1],A[i])

GG2=[0]*N
GG2[-1]=A[-1]

for i in range(2,N+1):
    GG2[-i]=math.gcd(GG2[-(i-1)],A[-i])

ans=[0]*N

ans[0]=GG2[1]
ans[-1]=GG[N-2]
#print(GG)
#print(GG2)
#print(ans)


temp=ans[0]
for i in range(1,N-1):
    ans[i]=math.gcd(GG[i-1],GG2[i+1])
    if ans[i]>temp:
        temp=ans[i]
if ans[-1]>temp:
    temp=ans[-1]


print(temp)

Buggy submission (verdict: Runtime Error):
import math
N=int(input())
A=list(map(int,input().strip().split(' ')))
if N==1:
    print(A[0])
else:    




    GG=[0]*N
    GG[0]=A[0]
    for i in range(1,N):
        GG[i]=math.gcd(GG[i-1],A[i])

    GG2=[0]*N
    GG2[-1]=A[-1]

    for i in range(2,N+1):
        GG2[-i]=math.gcd(GG2[-(i-1)],A[-i])

    ans=[0]*N

    ans[0]=GG2[1]
    ans[-1]=GG[N-1]
    #print(GG)
    #print(GG2)

    for i in range(1,N-1):
        ans[i]=math.gcd(GG[i-1],GG2[i+1])
    #print(ans)  
    print(max(ans))

Buggy submission (verdict: Runtime Error):
import math
N=int(input())
A=list(map(int,input().strip().split(' ')))

GG=[0]*N
GG[0]=A[0]
for i in range(1,N):
    GG[i]=math.gcd(GG[i-1],A[i])

GG2=[0]*N
GG2[-1]=A[-1]

for i in range(2,N+1):
    GG2[-i]=math.gcd(GG2[-(i-1)],A[-i])

ans=[0]*N

ans[0]=GG2[1]
ans[-1]=GG[N-1]

for i in range(1,N-1):
    ans[i]=math.gcd(GG[i-1],GG2[i+1])
print(max(ans))
Problem p03160 (python)

Fixed submission:
# https://atcoder.jp/contests/dp/tasks/dp_a
# A - Frog 1

N=int(input())
H=list(map(int,input().strip().split(" ")))


def find(H):
    if len(H) == 1:
        return 0

    dp = [0] * len(H)
    dp[1] = abs(H[1] - H[0])
    for i in range(2, len(H)):
        dp[i] = min(dp[i - 1] + abs(H[i] - H[i - 1]), dp[i - 2] + abs(H[i] - H[i - 2]))
    return dp[-1]


#H = [10, 30, 40, 20]
print(find(H))

Buggy submission (verdict: Runtime Error):
a="0"+input()
b="1"+input()
dp=[[0]*len(b) for i in range(len(a))]
for i in range(len(a)):
    for j in range(len(b)):
        if a[i]==b[j]:
            if i>0 and j>0:
                dp[i][j]=dp[i-1][j-1]+1
            else:
                dp[i][j]=1
        else:
            if i>0 and j>0:
                dp[i][j]=max(dp[i-1][j],dp[i][j-1])
            elif i==0 and j>0:
                dp[i][j]=dp[i][j-1]
            elif i>0 and j==0:
                dp[i][j]=dp[i-1][j]
            else:
                dp[i][j]=0

ans = []
x,y=len(a)-1,len(b)-1
lcs = dp[x][y]
while x > 0 or y > 0:
    if x-1 >= 0 and dp[x-1][y] == lcs:
        x -= 1
    elif y-1 >= 0 and dp[x][y-1] == lcs:
        y -= 1
    else:
        ans.append(a[x])
        y -= 1
        x -= 1
        
        lcs -= 1
print("".join(ans[::-1]))

Buggy submission (verdict: Runtime Error):
#https://atcoder.jp/contests/dp/tasks/dp_a
#A - Frog 1

N=int(input())
H=list(map(int,input().strip().split(" ")))


def find(H):
    if len(H)==1:
        return 0

    dp=[0]*len(H)
    dp[1]=abs(H[1]-H[0])
    for i in range(2,len(H)):
        dp[i]=min(dp[i-1]+abs(H[i]-H[i-1]),dp[i-2]+abs(H[i]-H[i-2]))
    return dp[-1]    

pint(find(H))
Problem p03161 (python)

Fixed submission:
N,K=list(map(int,input().strip().split(" ")))
H=list(map(int,input().strip().split(" ")))
dp=[0]+[10**10]*(N-1)
for i in range(1,N):
    temp=0
    for j in range(i-K,i):
        if j>=0:
            dp[i]=min(dp[i],dp[j]+abs(H[i]-H[j]))
print(dp[-1])

Buggy submission (verdict: Runtime Error):
# https://atcoder.jp/contests/dp/tasks/dp_b
# B - Frog 2

N, K = list(map(int, input().strip().split(' ')))
H = list(map(int, input().strip().split(' ')))


dp = [0] * N

for i in range(1, N):
    MIN = None
    for j in range(1, K + 1):
        if i - j < 0:
            continue
        if Min == None:
            MIN = dp[i - j] + abs(H[i] - H[i - j])
        else:
            MIN=min(dp[i - j] + abs(H[i] - H[i - j]), MIN)
    dp[i]=MIN

print(dp[-1])

Buggy submission (verdict: Runtime Error):
#https://atcoder.jp/contests/dp/tasks/dp_b
#B - Frog 2

N=int(input())
H=list(map(int,input().strip().split(' ')))

dp=[0]*N

for i in range(1,N):
    MIN=10**9
    for j in range(1,K+1):
        if i-j<0:
            continue
        MIN=min(dp[i-j]+abs(H[i]-H[j]),MIN)
    dp[i]=MIN
print(dp[-1])
Problem p03177 (python)

Fixed submission:
N,K=list(map(int,input().strip().split(' ')))
A=[]
for _ in range(N):
    A+=[list(map(int,input().strip().split(' ')))]
dic={}
MOD=10**9+7
power=1
while 2**power<=K:
    power+=1

dp=[[[0 for j in range(N)] for i in range(N)] for p in range(power+1) ]
for p in range(0,power+1):
    
    if p==0:
        for i in range(N):
            for j in range(N):
                if A[i][j]==1:
                    dp[p][i][j]=1
    else:
        for i in range(N):
            for j in range(N):
                for k in range(N):
                    dp[p][i][j]+=(dp[p-1][i][k]*dp[p-1][k][j])%MOD
                    dp[p][i][j]%=MOD

    
rep=bin(K)[2:][::-1]
final_ans=[[0 for i in range(N)] for j in range(N)]
need=[]
for i in range(len(rep)):
    if rep[i]=="1":
        need+=[i]

final=[[dp[need[0]][i][j] for j in range(N)] for i in range(N)]
for i in range(1,len(need)):
    ##start*dp[need[i]]
    temp_ans=[[0 for i in range(N)] for j in range(N)]
    for x in range(N):
        for y in range(N):
            temp=0
            for z in range(N):
                temp+=final[x][z]*dp[need[i]][z][y]
                temp%=MOD
            temp_ans[x][y]=temp
    final=[[temp_ans[i][j] for j in range(N)] for i in range(N)]
            
ans=0
for i in range(N):
    for j in range(N):
        ans+=final[i][j]
        ans%=MOD
print(ans)

Buggy submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(10**9)
N,K=list(map(int,input().strip().split(' ')))
A=[]
for _ in range(N):
    A+=[list(map(int,input().strip().split(' ')))]
dic={}
MOD=10**9+7
def findout(i,j,k):
    
    if k==1:
        if A[i][j]==1:
            return 1
        else:
            return 0
    if (i,j,k) in dic:
        return dic[(i,j,k)]
    N=len(A)
    a1=k//2
    a2=k-a1
    
    ans=0
    for node in range(N):
        ans+=(findout(i,node,a1)*findout(node,j,a2))%MOD
    dic[(i,j,k)]=ans
    return ans
ans=0
for i in range(4):
    for j in range(4):
        ans+=findout(i,j,K)
        ans%=MOD
print(ans)

Buggy submission (verdict: Runtime Error):
N,K=list(map(int,input().strip().split(' ')))
A=[]
for _ in range(N):
    A+=[list(map(int,input().strip().split(' ')))]
dic={}
MOD=10**9+7
def findout(i,j,k):
    
    if k==1:
        if A[i][j]==1:
            return 1
        else:
            return 0
    if (i,j,k) in dic:
        return dic[(i,j,k)]
    N=len(A)
    a1=k//2
    a2=k-a1
    
    ans=0
    for node in range(N):
        ans+=(findout(i,node,a1)*findout(node,j,a2))%MOD
    dic[(i,j,k)]=ans
    return ans
ans=0
for i in range(4):
    for j in range(4):
        ans+=findout(i,j,K)
        ans%=MOD
print(ans)