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

Fixed submission:
A= (input().split())
if int(A[0]) % 3 == 0 or int(A[1]) % 3 == 0 or (int(A[0]) + int(A[1])) % 3 == 0:
    print("Possible")
else:
    print("Impossible")

Buggy submission (verdict: Runtime Error):
A= map(int, input().split())
if A[0] % 3 == 0 or A[1] % 3 == 0 or (A[0] + A[1]) % 3 == 0:
    print("Possible")
else:
    print("Impossible")

Buggy submission (verdict: Runtime Error):
A= int(input().split())
if A[0] % 3 == 0 or A[1] % 3 == 0 or (A[0] + A[1]) % 3 == 0:
    print("Possible")
else:
    print("Impossible")

Buggy submission (verdict: Runtime Error):
A = int(input())
B = int(input())
if A % 3 == 0 or B % 3 == 0 or (A + B) % 3 == 0:
  print("Possible")
else:
  print("Impossible")
Problem p03696 (python)

Fixed submission:
import numpy as np
n = int(input())
s = list(input())
j = []
now = 0
unclosen = 0
opened = 0
for i in s:
    if i == ")":
        now -= 1
        if opened:
            opened -= 1
        else:
            unclosen += 1
    else:
        now += 1
        opened += 1
j = np.array(j)
print("(" * unclosen + "".join(s) + ")" * opened)

Buggy submission (verdict: Runtime Error):
n = int(input())
s = list(input())
j = []
now = 0
unclosen = 0
opened = 0
for i in s:
    if i == ")":
        now -= 1
        if opened:
            opened -= 1
        else:
            unclosen += 1
    else:
        now += 1
        opened += 1
j = np.array(j)
print("(" * unclosen + "".join(s) + ")" * opened)
Problem p03854 (python)

Fixed submission:
s = input()


def solve(query):
    while 1:
        for frag in ("erase", "eraser", "dream", "dreamer"):
            if query.endswith(frag):
                query = query[:-len(frag)]
                break
        else:
            print("NO")
            break
        if not query:
            print("YES")
            break



solve(s)

Buggy submission (verdict: Runtime Error):
s = input()


def solve(query):
    if query == "":
        print("YES")
        exit()
    for frag in ("eraser", "erase", "dream", "dreamer"):
        if query.startswith(frag):
            solve(query[len(frag):])


solve(s)
print("NO")
Problem p02684 (python)

Fixed submission:
N,K = (int(i) for i in input().split()) 
A = [int(i) for i in input().split()] 
A_done = [0]*N
A_route = []
point = 1
end_point = 0
while A_done[point-1]==0:
  A_done[point-1] = 1
  A_route.append(point)
  point = A[point-1]
  if A_done[point-1]==1:
    end_point = point
cal = K%len(A_route)
roop = A_route.index(end_point)
f_len = len(A_route[:roop])
roop_len = len(A_route[roop:])
A_roop = A_route[roop:]
if K >= f_len + roop_len:
  cal = (K-f_len)%(len(A_roop))
  #print(cal)
  print(A_roop[cal])
else:
  print(A_route[K])

Buggy submission (verdict: Runtime Error):
N,K = (int(i) for i in input().split()) 
A = [int(i) for i in input().split()] 
A_done = [0]*N
A_route = []
point = 1
end_point = 0
while A_done[point-1]==0:
  A_done[point-1] = 1
  A_route.append(point)
  point = A[point-1]
  if A_done[point-1]==1:
    end_point = point
cal = K%len(A_route)
roop = A_route.index(end_point)
f_len = len(A_route[:roop])
roop_len = len(A_route[roop:])
A_roop = A_route[roop:]
if K >= f_len + roop_len:
  cal = (K-f_len)%(len(A_roop))
  #print(cal)
  print(A_roop[cal])
else:
  print(A_route(K))
Problem p02690 (python)

Fixed submission:
X = int(input())
for i in range(130):
  for j in range(-130,130):
    if i**5 - j**5 ==X:
      A = i
      B = j
      break

print(str(A)+str(" ")+str(B))

Buggy submission (verdict: Runtime Error):
X = int(input())
for i in range(130):
  for j in range(-66,66):
    if i**5 - j**5 ==X:
      A = i
      B = j
      break
print(str(A)+str(" ")+str(B))
Problem p02696 (python)

Fixed submission:
a, b, n = map(int, input().split())
if n >= b - 1:
    print(int(a - a / b))
else:
    print(int(a * n / b) - a * int(n / b))

Buggy submission (verdict: Runtime Error):
A,B,N = (int(i) for i in input().split())
max_num = -10**100
tmp_num = 0
cnt = 1
flg = False
while flg  == False:
  tmp_num = math.floor(A*cnt/B) - A*math.floor(cnt/B)
  #print(tmp_num)
  if tmp_num > max_num :
    max_num = tmp_num
    cnt += 1
  else:
    flg = True
print(max_num)
Problem p02713 (python)

Fixed submission:
K = int(input())
import math
from functools import reduce
def gcd_list(numbers):
    return reduce(math.gcd, numbers)
tmp_sum = 0
for i in range(1,K+1):
  for j in range(i,K+1):
    for k in range(j,K+1):
      if i != j and j != k:
        tmp_list = [i,j,k]
        tmp_sum += gcd_list(tmp_list)*6
      elif i == j and j == k:
        tmp_list = [i,j,k]
        tmp_sum += gcd_list(tmp_list)
      else:
        tmp_list = [i,j,k]
        tmp_sum += gcd_list(tmp_list)*3
print(tmp_sum)

Buggy submission (verdict: Runtime Error):
import fractions
import math
from functools import reduce
def gcd_list(numbers):
    return reduce(math.gcd, numbers)
tmp_sum = 0
for i in range(1,K+1):
  for j in range(1,K+1):
    for k in range(1,K+1):
      tmp_list = [i,j,k]
      tmp_sum += gcd_list(tmp_list)
print(tmp_sum)
Problem p02791 (python)

Fixed submission:
N = int(input())
P = [int(i) for i in input().split()]
P_min = P.copy()
for i in range(1,N):
    P_min[i] = min(P_min[i-1],P[i])
cnt = 0
for i in range(N):
    if P_min[i] >= P[i]:
        cnt += 1
print(cnt)

Buggy submission (verdict: Runtime Error):
N = int(input())
P = [int(i) for i in input().split()]
P_min = P.copy()
for i in range(1,N):
    P_min[i] = min(P_min[i-1],P[i])
cnt = 0
for i in range(N):
    if P_min[i] >= P[i]:
        cnt += 1
print(cnt)
Problem p02657 (python)

Fixed submission:
a, b=map(int, input().split())
print(a*b)

Buggy submission (verdict: Runtime Error):
a=int(input())
b=int(input())
print(a*b
Problem p02885 (python)

Fixed submission:
a,b = map(int,input().split())
ans = max(a-2*b,0)
print(ans)

Buggy submission (verdict: Runtime Error):
a,b = map(int,intput().split())
ans = max(a-2*b,0)
print(ans)
Problem p03081 (python)

Fixed submission:
N,Q = map(int, input().split())
S = input()
TD = [ input().split() for _ in range(Q)]


N = len(S)
ans = 0

# N-1 falls from right edge ? 
nowpos = N-1
fall_f = False
for i in range(Q):
    t,d = TD[i]
    nowChar = S[nowpos]
    if t == nowChar:
        if d == "L":
            nowpos -= 1
            if nowpos == -1:
                break
        if d == "R":
            nowpos += 1
            if nowpos == N:
                fall_f = True
                break

if fall_f:
    ok = N-1
    ng = -1
    mid = (ok+ng)//2
    while abs(ok - ng) > 1:
        nowpos = mid
        fall_f = False

        for i in range(Q):
            t,d = TD[i]
            nowChar = S[nowpos]
            if t == nowChar:
                if d == "L":
                    nowpos -= 1
                    if nowpos == -1: break
                if d == "R":
                    nowpos += 1
                    if nowpos == N:
                        fall_f = True
                        break
        if fall_f :
            ok = mid
        else:
            ng = mid

        mid = (ok+ng)//2

    ans += N - ok 

    

    
# 0 fallse from left edge  ?
nowpos = 0
fall_f = False
for i in range(Q):
    t,d = TD[i]
    nowChar = S[nowpos]
    if t == nowChar:
        if d == "L":
            nowpos -= 1
            if nowpos == -1:
                fall_f = True
                break
        if d == "R":
            nowpos += 1
            if nowpos == N:
                break
if fall_f:

    ok = 0
    ng = N
    mid = (ok+ng)//2
    while abs(ok - ng) > 1:

        nowpos = mid
        fall_f = False

        for i in range(Q):
            t,d = TD[i]
            nowChar = S[nowpos]
            if t == nowChar:
                if d == "L":
                    nowpos -= 1
                    if nowpos == -1: 
                        fall_f = True
                        break
                if d == "R":
                    nowpos += 1
                    if nowpos == N:
                        break
        if fall_f :
            ok = mid
        else:
            ng = mid

        mid = (ok+ng)//2

    ans= min( ans +  ok + 1,  N)

print(N - ans)

Buggy submission (verdict: Runtime Error):
N,Q = map(int,input().split())
S = input()
QUE = [ input().split() for _ in range(Q)]

N = len(S)

l = 0
r = N-1

for i in range(Q-1, -1, -1):
    t,d = QUE[i]
    if d == "L" and t == S[l]:
        l += 1
    if d == "R" and t == S[r]:
        r -= 1

print(max(0, r-l+1))
Problem p03083 (python)

Fixed submission:
B,W = map(int, input().split())
N = B+W
mod = 10**9+7

factorial = [1]
for i in range(N+1):
    factorial.append( factorial[-1] * (i+1) % mod)
# print(factorial)



de_factorial = [0] * (N+1)
de_factorial[N] = pow(  factorial[N] , mod-2, mod  )

for i in range( N, 0, -1):
    de_factorial[i-1] = de_factorial[i] * i % mod
    
def comb(n,r):
    if n < r: return 0
    if n == r: return 1
    return (factorial[n] * de_factorial[r] * de_factorial[n-r]) % mod


p = [0] * (N+1) # Bを食べきった確率
q = [0] * (N+1) # Wを食べきった確率

de2 = de_factorial[2]
for i in range(1, N+1):
    p[i] = p[i-1] + comb(i-1 ,B-1) * de2 % mod 
    q[i] = q[i-1] + comb(i-1 ,W-1) * de2  % mod 
    de2 = de2 * de_factorial[2] % mod

    tmp = ( q[i-1] + 1-p[i-1] ) * de_factorial[2] % mod
    
    print(tmp)

Buggy submission (verdict: Runtime Error):
B,W = map(int, input().split())
N = B+W

factorial = [1]
for i in range(N+1):
    factorial.append( factorial[-1] * (i+1) % mod)
# print(factorial)

mod = 10**9+7

de_factorial = [0] * (N+1)
de_factorial[N] = pow(  factorial[N] , mod-2, mod  )

for i in range( N, 0, -1):
    de_factorial[i-1] = de_factorial[i] * i % mod
    
def comb(n,r):
    if n < r: return 0
    if n == r: return 1
    return (factorial[n] * de_factorial[r] * de_factorial[n-r]) % mod


p = [0] * (N+1) # Bを食べきった確率
q = [0] * (N+1) # Wを食べきった確率

de2 = de_factorial[2]
for i in range(1, N+1):
    p[i] = p[i-1] + comb(i-1 ,B-1) * de2 % mod 
    q[i] = q[i-1] + comb(i-1 ,W-1) * de2  % mod 
    de2 = de2 * de_factorial[2] % mod

    tmp = ( q[i-1] + 1-p[i-1] ) * de_factorial[2] % mod
    
    print(tmp)
Problem p03096 (python)

Fixed submission:
N=int(input()) 
clist=[-1]
mod=10**9+7

for i in range(N):
  t=int(input())
  if t==clist[-1]:
    continue
  clist.append(t)

del clist[0]
N = len(clist)

# print(clist)
colorlast=[-1]*(3*10**5)
poslp=[-1]*(N+1)

for e,c in enumerate(clist,1):
  if  colorlast[c]  !=  -1:
    poslp[e]=colorlast[c]
    colorlast[c]=e
  else:
    colorlast[c]=e


dp=[0]*(N+100)
dp[0]=1

for e,c in enumerate(clist,1):
  if poslp[e]==-1:
    dp[e]=(dp[e-1])%mod
  else:
    dp[e]=(dp[e-1]+dp[poslp[e]])%mod

# print(dp[:len(clist)+1])
print(dp[len(clist)]%mod)

Buggy submission (verdict: Runtime Error):
N=int(input()) 
clist=[-1]
mod=10**9+7
for i in range(N):
  t=int(input())
  if t==clist[-1]:
    continue
  clist.append(t)
  
colorlast=[-1]*(3*10**5)
poslp=[-1]*(N+2)

for e,c in enumerate(clist,1):
  if colorlast[c]!=-1:
    poslp[e]=colorlast[c]
    colorlast[c]=e
  else:
    colorlast[c]=e

dp=[0]*(N+1)
dp[0]=1
for e,c in enumerate(clist,1):
  if poslp[e]!=-1:
    dp[e]=(dp[e-1])%mod
  else:
    dp[e]=(dp[e-1]+dp[poslp[e]])%mod
print(dp[len(clist)]%mod)
Problem p03132 (python)

Fixed submission:
#!/mnt/c/Users/moiki/bash/env/bin/python
# N,M = map(int, input().split())
L = int(input())
A = [int(input()) for _ in  range(L)]


DP = [0] * 5
for i in range(L):
    r0 = A[i]
    r1 = (A[i] + 1) % 2

    if A[i] == 0:
        r2 = 2
    else:
        r2 = A[i] % 2

    for i,r in zip(range(4,-1,-1), [r0,r2,r1,r2,r0]):
        DP[i] = min(DP[:i+1]) + r
        # print(DP)

print(min(DP))

Buggy submission (verdict: Runtime Error):
#!/mnt/c/Users/moiki/bash/env/bin/python
# N,M = map(int, input().split())
L = int(input())
A = [int(input()) for _ in  range(L)]


# mode = A[0] % 2
# B = []
# for a in A:
#     if a == 0:
#         mode = -1
#     elif a % 2 == mode:
#     elif a % 2 != mode:


fromEnd = []

i = 0
while i < L:
    if A[i] != 0:
        start = i
        while i < L and A[i] != 0:
            i += 1
        end = i-1 if i != start else start
        fromEnd.append((start, end, sum(A[start:end+1])))
    i += 1

ans = float("inf")

# start forward
mode = 2 % 2
sum_forward = sum(A)
for i in range(start, L):
    sum_forward = min(sum_forward, ans)
    if   A[i] % 2 ==  1 and mode == A[i] % 2:
        sum_forward -= A[i]
    elif A[i] % 2 ==  1 and mode != A[i] % 2:
        mode = A[i] % 2
        sum_forward -= A[i]

    elif A[i] == 0:
        sum_forward += 1
        mode = -1

    elif A[i] % 2 == 0 and mode == A[i] % 2 :
        sum_forward -= A[i]

    elif A[i] % 2 == 0 and mode != A[i] % 2 :
        sum_forward -= A[i] - 1
        mode = A[i] % 2 
    
    if i == L-1 and A[i] %2 == 0 and mode != A[i] %2:
        sum_forward -= 1

# print("sum forward: ", sum_forward)
ans = sum_forward
mode = 2 % 2
sum_backward = sum(A)


for i in range(end, -1, -1):
    ans = min(sum_backward, ans)
    
    # ans = min(sum_backward, ans)
    if   A[i] % 2 ==  1 and mode == A[i] % 2:
        sum_backward -= A[i]
    elif A[i] % 2 ==  1 and mode != A[i] % 2:
        mode = A[i] % 2
        sum_backward -= A[i]

    elif A[i] == 0:
        sum_backward += 1
        mode = -1

    elif A[i] % 2 == 0 and mode == A[i] % 2 :
        sum_backward -= A[i]
    elif A[i] % 2 == 0 and mode != A[i] % 2 :
        sum_backward -= A[i] - 1
        mode = A[i] % 2 
    if i == 0 and A[i] %2 == 0 and mode != A[i] %2:
        sum_backward -= 1

ans = min(sum_backward, sum_forward)
print(ans)
Problem p03161 (python)

Fixed submission:
#!/mnt/c/Users/moiki/bash/env/bin/python
# N,K = list(map(int, input().split()))
# h = list(map(int, input().split()))

# (N,K), h = map(int, input().split()), list(map(int, input().split()))
N,K,*h = map(int, "\n".join([input(), input()]).split())

# suml = [1e9 for i in range(N)]
# suml[0] = 0


suml = [0]*N

# for i in range(1,N):
for i,e_h in enumerate(h):
    if i == 0:
        continue

    start = max(0, i-K)
    cost  = min(cst + abs( e_h - hgh) for cst, hgh in 
                   zip(suml[start:i], h[start:i]))
    # cost  = min(cst + abs( h[i] - hgh ) for cst, hgh in 
    #               zip(suml[start:i], h[start:i]))
    suml[i] = cost

print(suml[-1])

Buggy submission (verdict: Runtime Error):
#!/mnt/c/Users/moiki/bash/env/bin/python
# FROM : https://atcoder.jp/contests/dp/submissions/4017206
# N,M = map(int, input().split())
N = int(input())
from collections import Counter
a = Counter( map(int, input().split()))


#1,2,3
A,B,C = (a[i] for i in range(1,4))

# dpA,B,C

dp = [ [ [0] * (C+1) 
           for _ in range(B+C+1)
       ]
           for _ in range(A+B+C+1) 
     ]


for c in range(C+1):
    for b in range(B+C+1-c):
        for a in range(A+B+C+1-b-c):

            try: 
                dp[a][b][c] = (
                        ( a * ( dp[a-1][b][c]   if a else 0)  ) + 
                        ( b * ( dp[a+1][b-1][c] if b else 0)  ) +
                        ( c * ( dp[a][b+1][c-1] if c else 0)  ) + N 
                       ) / ( a+b+c ) 
            except:
                continue

print(dp[A][B][C])
Problem p03162 (python)

Fixed submission:
#!/mnt/c/Users/moiki/bash/env/bin/python
N = int(input())
# info = [ tuple(zip(tuple(map(int, input().split())), ("a","b","c"))) for i in range(N)]
info = [list(map(int, input().split())) for i in range(N)]
dp = [[0,0,0] for i in range(N+1)]
dp[1] = info[0]
for i in range(N):
    for j in range(3):
        for k in [x for x in range(3) if x != j]:
            if dp[i][k] + info[i][j] > dp[i+1][j]: # dp[i+1][j]?
                dp[i+1][j] = dp[i][k] + info[i][j]

# print(dp)
print(max(dp[N]))

Buggy submission (verdict: Runtime Error):
#!/mnt/c/Users/moiki/bash/env/bin/python
N = int(input())
ilist = [ tuple(zip(tuple(map(int, input().split())), ("a","b","c"))) for i in range(N)]

# print(ilist)
suml = [(0,"z")]
for i in range(1,N+1):
    l = (ilist[i-1])
    l = sorted(l, reverse=True)
    # print("list: ", l)
    if suml[i-1][1] != l[0][1]:
        # suml[i] = suml[i-1] + l[0][0]
        if (i+1)<=N and sorted(ilist[i+1], reverse=True)[0][1] == l[0][1]:
            # print("\tinside")
            l_n = sorted(ilist[i+1], reverse=True)# [0][1]
            if (l[0][0] + l_n[1][0]) < (l[1][0] + l_n[0][0]):

                suml.append(( suml[i-1][0]+l[1][0], l[1][1]  ))
            else:
                suml.append(( suml[i-1][0]+l[0][0], l[0][1]  ))
        else:
            suml.append(( suml[i-1][0]+l[0][0], l[0][1]  ))

        # // l[0][1] == sorted(ilist[i+1], reverse=True)[0][1]  \
        #  and l[0][0] + sorted(ilist[i+1], reverse=True)[0][1]
    else:
        # suml[i] = suml[i-1] + l[1][0]
        suml.append(( suml[i-1][0]+l[1][0], l[1][1]  ))

# print(suml)
print(suml[-1][0])
Problem p03168 (python)

Fixed submission:
#!/mnt/c/Users/moiki/bash/env/bin/python
N = int(input())
p = list(map(float, input().split()))

import numpy as np
dp = np.full(N+1, 0, dtype=np.float64)
dp[0] = 1
n_p = np.array(p)

for i in range(N):
    tmp      = np.zeros_like(dp)
    tmp[1:]  = dp[:-1] * n_p[i]
    tmp[:-1]+= dp[:-1] * (1-n_p[i])
    dp = tmp

ans = np.sum(dp[N//2+1:])
print(ans)

# for i in range(1, 1+N): # timestep
#     for j in range(0, 0+i): # pos
#         dp[j] = dp[
#     # kdp[:i] a

# suml = [[1 for x in range(round+1)] for round in range(N+1)]
# 
# for e,p in enumerate(P):
#     for (es, s),_ in zip(enumerate(suml[e]), range(e+1)):
# 
#         if (es == 0):
#             suml[e+1][es]   = suml[e][es] * (1-p)
#         else:
#             suml[e+1][es]   += suml[e][es] * (1-p)
# 
#         suml[e+1][es+1] = suml[e][es] * p
# 
# 
# sumA = suml[N][:len(suml[N])//2-1:-1]
# sumA = sum(sumA)
# print(sumA)

Buggy submission (verdict: Runtime Error):
#!/mnt/c/Users/moiki/bash/env/bin/python
N = int(input())
p = list(map(float, input().split()))

import numpy as np
dp = np.full(N+1, 0, dtype=np.float64)
dp[0] = 1
n_p = np.array(p)

for i in range(N):
    tmp      = np.zeros_like(dp)
    tmp[1:]  = dp[:-1] * n_p[i]
    tmp[:-1]+= dp[:-1] * (1-n_p[i])
    dp = tmp

ans = np.sum(dp[N//2+1:])
print(ans)

# for i in range(1, 1+N): # timestep
#     for j in range(0, 0+i): # pos
#         dp[j] = dp[
#     # kdp[:i] a

# suml = [[1 for x in range(round+1)] for round in range(N+1)]
# 
# for e,p in enumerate(P):
#     for (es, s),_ in zip(enumerate(suml[e]), range(e+1)):
# 
#         if (es == 0):
#             suml[e+1][es]   = suml[e][es] * (1-p)
#         else:
#             suml[e+1][es]   += suml[e][es] * (1-p)
# 
#         suml[e+1][es+1] = suml[e][es] * p
# 
# 
# sumA = suml[N][:len(suml[N])//2-1:-1]
# sumA = sum(sumA)
# print(sumA)
Problem p03173 (python)

Fixed submission:
N = int(input())
A = list(map(int, input().split()))
inf = float("inf")

from itertools import accumulate
Accum = list(accumulate([0] + A))

dp = [ [inf]*(N+1) for _ in range(N+1)]

def dfs(l,r):
    if dp[l][r] != inf:
        return dp[l][r]
    if l == r: 
        return 0
    if l+1 == r: 
        dp[l][r] = A[l]
        return A[l]

    local_ans = inf
    for i in range(l+1, r): # 0 to 4, 0-1, 1-4
        local_ans = min(local_ans, dfs(l,i) + dfs(i,r))
    dp[l][r] = local_ans + Accum[r] - Accum[l]
    return dp[l][r]
print (dfs(0,N)- sum(A))

Buggy submission (verdict: Runtime Error):
N = int(input())
# A = list(map(int, input()))
A = tuple(map(int, input().split()))

from collections import defaultdict, deque
dp = defaultdict(lambda : -1)

q = deque([])
q.append( (A, 0) )

inf = float("inf")

ans = inf
while q:
    t,cost = q.popleft()
    if len(t) == 0:
        ans = min(ans, cost)
        continue
    
    tpl = t
    for i in range(len(tpl)-1):
        q.append (   ( tpl[0:i] + ( tpl[i]+tpl[i+1], )  + tpl[i+2: ],   tpl[i] + tpl[i+1] ) ) 


print(ans - sum(A))
exit(0)[

def dfs(tpl):
    if dp[tpl] != -1:
        return dp[tpl]
    if len(tpl) == 0:
        return 0
    if len(tpl) == 1:
        dp[tpl] = tpl[0]
        return tpl[0]

    lst_candidates = []
    now_cost = []
    for i in range(len(tpl)-1):
        # print("i: ", i )
        lst_candidates.append (   tpl[0:i] + ( tpl[i]+tpl[i+1], )  + tpl[i+2: ]   )
        now_cost.append ( tpl[i] + tpl[i+1] ) 

    total_cost = []
    for i in range(len(now_cost)):
        total_cost.append ( now_cost [i] + dfs(lst_candidates[i]))

    # print("totla_cost: ", total_cost)
    # print("lst_candidates: ", lst_candidates)
    res = min(total_cost)
    dp[tpl] = res

    return res

# print(dfs(A) - sum(A))
Problem p03177 (python)

Fixed submission:
#!/mnt/c/Users/moiki/bash/env/bin/python
N,K = map(int, input().split())
A = [ [int(j) for j in input().split()] for i in range(N)]
# I = [ [j for j in range(1,N+1) if Ai[j]] for Ai in A]
MOD = 10**9 + 7

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

S = [[1]*N]
KDIG = [0]*70

for i in range(1,61):
    if K % (1<<i) :
        KDIG[i-1] = 1
        K -= K%(1<<i)


def prod(A,B,k,l,m):#A:k*l,B:l*m
 
    C=[[None for i in range(m)] for j in range(k)]
 
    for i in range(k):
        for j in range(m):
            ANS=0
            for pl in range(l):
                ANS=(ANS+A[i][pl]*B[pl][j])%MOD
 
            C[i][j]=ANS
 
    return C



for i in range(60):
    if KDIG[i] == 1:
        S = prod(S,A,1,N,N)

    A = prod(A,A,N,N,N)
print(sum(S[0])%MOD)

# for i in range(1,N+1):
#     for j in range(1,N+1):
#         # dp[i][j] = np.linalg.matrix_power(A, K)[i-1][j-1].item()
#         # ans += dp[i][j] % MOD
#         # ans += np.linalg.matrix_power(A, K)[i-1][j-1].item() % MOD
#         # ans += M[i-1,j-1].item() % MOD
#         ans += M[i-1][j-1] % MOD

# print(ans%MOD)

Buggy submission (verdict: Runtime Error):
#!/mnt/c/Users/moiki/bash/env/bin/python
N,K = map(int, input().split())
A = [ [int(j) for j in input().split()] for i in range(N)]
# I = [ [j for j in range(1,N+1) if Ai[j]] for Ai in A]
MOD = 10**9 + 7

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

import numpy as np
npA = np.array(A).astype(np.uint64)

def prod2(A,B):
    global N
    C = [ [0]*N for _ in range(N)]
    for i in range(N):
        for j in range(N):
            tmp = 0
            for k in range(N):
                tmp += A[i][k] * B[k][j]
            C[i][j] = tmp
    return C


def prod(A,n):
    if n == 0:
        C = [ [0]*(N) for _ in range(N)]
        for i in range(N):
                C[i][i] = 1
        return C

    elif n == 1:
        return A

    elif n % 2 == 1:
        return prod2( A , prod(A,n-1))

    elif n % 2 == 0:
        return prod2( prod(A,n//2), prod(A,n//2))
    
    

ans = 0
# M = np.linalg.matrix_power(A, K)
M = prod(A,K)
for i in range(1,N+1):
    for j in range(1,N+1):
        # dp[i][j] = np.linalg.matrix_power(A, K)[i-1][j-1].item()
        # ans += dp[i][j] % MOD
        # ans += np.linalg.matrix_power(A, K)[i-1][j-1].item() % MOD
        # ans += M[i-1,j-1].item() % MOD
        ans += M[i-1][j-1] % MOD

print(ans%MOD)
Problem p03231 (python)

Fixed submission:
N,M = map(int, input().split())
S = input()
T = input()
from fractions import gcd

# 15, 9
# 3$BJ8;z$:$D8+$F$$$/!"(B5$BJ8;z$:$D8+$F$$$/(B
LEN = N*M // gcd(N,M) # 45
p = LEN // N # 3
q = LEN // M # 5
lcm = p*q//gcd(p,q)

for i in range(0, LEN//lcm):
    if S[i*q] != T[i*p]:
        print(-1)
        exit()
print(LEN)

Buggy submission (verdict: Runtime Error):
N,M=map(int,input().split())
S=input()
T=input()
ans=["-1"]*()
def computeGCD(x, y): 
  if x > y: 
    small = y    
  else: 
    small = x
  for i in range(1, small+1): 
    if((x % i == 0) and (y % i == 0)): 
      gcd = i 
  return gcd 

lena=computeGCD(N,M)
glena=N*M//lena#45 , 15,9 , 3,5 
comm=computeGCD(glena//N, glena//M)
gcomm=(glena//N)*(glena//M)//comm
for i in range(glena//gcomm):
  if S[i*glena//M]!=T[i*glena//N]:
    print(-1)
    exit()
print(glena)