Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
import sys

sys.setrecursionlimit(50000)
N,K= [int(v) for v in input().split()]
P = [int(v) - 1 for v in input().split()]
C = [int(v) for v in input().split()]

visited = [True for _ in range(N)]
cycle = []


ans = -float('inf')
for sn in range (N):
    cost = []
    nn = sn
    while True:
        cost.append(C[nn])
        nn = P[nn]
        if sn == nn:
            break
    total = sum(cost)
    l = len(cost)

    t = 0
    for i in range(l):
        t += cost[i]
        if i+1 > K: break
        now = t
        if total > 0:
            e = (K-i-1)//l
            now += total * e
        ans = max(ans,now)


print(int(ans))


Fixed submission:
import sys

sys.setrecursionlimit(50000)
N,K= [int(v) for v in input().split()]
P = [int(v) - 1 for v in input().split()]
C = [int(v) for v in input().split()]

visited = [True for _ in range(N)]
cycle = []


ans = -float('inf')
for sn in range (N):
    cost = []
    nn = sn
    while True:
        cost.append(C[nn])
        nn = P[nn]
        if sn == nn:
            break
    total = sum(cost)
    l = len(cost)

    t = 0
    for i in range(l):
        t += cost[i]
        if i+1 > K: break
        now = t
        if total > 0:
            e = (K-i-1)//l
            now += total * e
        ans = max(ans,now)


print(int(ans))

Buggy python submission (verdict: Runtime Error):
N,K= [int(v) for v in input().split()]
P = [int(v) - 1 for v in input().split()]
C = [int(v) for v in input().split()]

visited = [True for _ in range(N)]

def dfs(node,total,state,m):
    if visited[node]:
        return total,state,m
    state.append(C[node])
    nextM = max(total,total+C[node])
    total += C[node]
    visited[node] = True
    return dfs(P[node],total,state,nextM)

ans = -float('inf')

def calc(node):
    global visited,ans
    visited = [False for _ in range(N)]
    total,state,ma = dfs(P[node],0,[],-float('inf'))
    ans = max(ma,ans)
    K_ = K
    count = K // len(state)

    tmp = total * count
    for v in state[:K%len(state)]:
        tmp += v
    ans = max(ans,tmp)

    if total > 0:
        tmp = total * (count-1)
        for v in state:
            tmp += v
            ans = max(ans,tmp)






for i in range (N):
    calc(i)

print(ans)


Fixed submission:
import sys

sys.setrecursionlimit(50000)
N,K= [int(v) for v in input().split()]
P = [int(v) - 1 for v in input().split()]
C = [int(v) for v in input().split()]

visited = [True for _ in range(N)]
cycle = []


ans = -float('inf')
for sn in range (N):
    cost = []
    nn = sn
    while True:
        cost.append(C[nn])
        nn = P[nn]
        if sn == nn:
            break
    total = sum(cost)
    l = len(cost)

    t = 0
    for i in range(l):
        t += cost[i]
        if i+1 > K: break
        now = t
        if total > 0:
            e = (K-i-1)//l
            now += total * e
        ans = max(ans,now)


print(int(ans))
Buggy python submission (verdict: Runtime Error):
import sys

sys.setrecursionlimit(10000000)
N,K = [int(v) for v in input().split()]
A = [int(v) for v in input().split()]
print(N,K)


loop = []

def dfs(now):
    loop.append(now)
    if A[now-1] == 1:
        return
    else:
        dfs(A[now-1])
dfs(1)

print(loop[K%len(loop)])


Fixed submission:
import sys

sys.setrecursionlimit(10000000)
N,K = [int(v) for v in input().split()]
A = [int(v) for v in input().split()]

loop = []
pre = []
visited = set()

def dfs(index,now):
    global pre
    global loop
    loop.append(now)
    if now in visited:
        for left in range(len(loop)):
            if now == loop[left]:
                break
        pre = loop[:left]
        loop = loop[left:index]
        return
    else:
        visited.add(now)
        dfs(index+1,A[now-1])
dfs(0,1)

if len(pre) > K:
    print(pre[K])
else:
    K-=len(pre)
    print(loop[K%len(loop)])
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = [int(v) for v in input().split()]

ans = 0

for i in range(1,N+1):
    l = A[i-1]
    for j in range(l+i,N+1):
        r = A[j-1]
        if j - i == l + r: ans += 1
print(ans)


Fixed submission:
from collections import defaultdict

N = int(input())
A = [int(v) for v in input().split()]

ans = 0
dic = defaultdict(int)

for i,a in enumerate(A):
    dic[i-a] += 1

for i,a in enumerate(A):
    ans += dic[a+i]

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
def lcm(a,b):
    if a < b:
        a,b = b,a
    while a % b != 0:
        a,b = b,a%b
    return b

K = int(input())
ans = 0
for i in range(1,K+1):
    for j in range(1,K+1):
        for k in range(1,K+1):
            ans += lcm(lcm(i,j),k)
print(ans)


Fixed submission:
def lcm(a,b):
    if a < b:
        a,b = b,a
    while a % b != 0:
        a,b = b,a%b
    return b

K = int(input())
ans = 0
for i in range(1,K+1):
    for j in range(1,K+1):
        for k in range(1,K+1):
            ans += lcm(lcm(i,j),k)
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
S = input()
ans = 0

for i in range(N-2):
    for j in range(i+1,N-1):
        for k in range(j+1,N):
            if S[i] != S[j] and S[j] != S[k] and S[i] != S[k]:
                if k-j != j - i:
                    ans += 1
print(ans)


Fixed submission:
N = int(input())
S = input()
ans = S.count("R") * S.count("G") * S.count("B")


for i in range(N-2):
    for j in range(i+1,N-1):
        k = j + (j-i)
        if k < N and S[i] != S[j] and S[k] != S[j] and S[i] != S[k]:
            ans -= 1

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = [int(v) for v in input().split()]

field = {}
for v in a:
    if not v in field:
        field[v] = 1
    else:
        field[v] += 1

for i in a:
    if i in field:
        field[i] -= 1
    
    ans = 0
    for k,v in field.items():
        ans += ((v*(v-1))/2)

    print(int(ans))

    if i in field:
        field[i] += 1


Fixed submission:
n = int(input())
a = [int(v) for v in input().split()]

field = {}
for v in a:
    if not v in field:
        field[v] = 1
    else:
        field[v] += 1

all_ans = 0
for k,v in field.items():
    all_ans += ((v*(v-1))/2)


for i in a:
    ans = all_ans
    if i in field:
        n = field[i]
        ans -= (n*(n-1))/2
        n = n - 1
        ans += (n*(n-1))/2
    
    print(int(ans))
Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque

H,W  = [int(v) for v in input().split()]
S = ['#'+input()+'#' for _ in range(H)]
S.insert(0,"#"*(W+2))
S.append("#"*(W+2))

ans = 0

for y in range(1,H+1):
    for x in range(1,W+1):
        if S[y][x] == "#": continue
        queue = deque([[x,y,0]])
        visited = [[False for _ in range(W+2)] for _ in range(H+2)]
        visited[y][x] = True
        while queue:
            x,y,c = queue.pop()
            visited[y][x] = True
            for ny,nx in [[y+1,x],[y,x+1],[y-1,x],[y,x-1]]:
                if visited[ny][nx] or S[ny][nx] == '#': continue
                queue.appendleft([nx,ny,c+1])

            ans = max(ans,c)
print(ans)


Fixed submission:
from collections import deque

H,W  = [int(v) for v in input().split()]
S = ['#'+input()+'#' for _ in range(H)]
S.insert(0,"#"*(W+2))
S.append("#"*(W+2))

ans = 0

for y in range(1,H+1):
    for x in range(1,W+1):
        if S[y][x] == "#": continue
        queue = deque([[x,y,0]])
        visited = [[False] * (W+2) for _ in range(H+2)]
        visited[y][x] = True

        while queue:
            x,y,c = queue.pop()
            for ny,nx in [[y+1,x],[y,x+1],[y-1,x],[y,x-1]]:
                if visited[ny][nx] or S[ny][nx] == '#': continue
                visited[ny][nx] = True
                queue.appendleft([nx,ny,c+1])
            ans = max(ans,c)
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque

H,W  = [int(v) for v in input().split()]
S = ['#'+input()+'#' for _ in range(H)]
S.insert(0,"#"*(W+2))
S.append("#"*(W+2))

ans = 0

for y in range(1,H+1):
    for x in range(1,W+1):
        if S[y][x] == "#": continue
        queue = deque([[x,y,0]])
        visited = [[False for _ in range(W+2)] for _ in range(H+2)]
        visited[y][x] = True
        while queue:
            x,y,c = queue.pop()
            visited[y][x] = True
            for ny,nx in [[y+1,x],[y,x+1],[y-1,x],[y,x-1]]:
                if visited[ny][nx] or S[ny][nx] == '#': continue
                queue.appendleft([nx,ny,c+1])

            ans = max(ans,c)
print(ans)


Fixed submission:
from collections import deque

H,W  = [int(v) for v in input().split()]
S = ['#'+input()+'#' for _ in range(H)]
S.insert(0,"#"*(W+2))
S.append("#"*(W+2))

ans = 0

for y in range(1,H+1):
    for x in range(1,W+1):
        if S[y][x] == "#": continue
        queue = deque([[x,y,0]])
        visited = [[False] * (W+2) for _ in range(H+2)]
        visited[y][x] = True

        while queue:
            x,y,c = queue.pop()
            for ny,nx in [[y+1,x],[y,x+1],[y-1,x],[y,x-1]]:
                if visited[ny][nx] or S[ny][nx] == '#': continue
                visited[ny][nx] = True
                queue.appendleft([nx,ny,c+1])
            ans = max(ans,c)
print(ans)
Buggy python submission (verdict: Runtime Error):
print(r*r)


Fixed submission:
print(int(input()) ** 2)
Buggy python submission (verdict: Time Limit Exceeded):
N,M = [int(v) for v in input().split()]
ad_list = [[] for _ in range (N+1)]
ad_num = [0 for _ in range(N)]
topo = []

for _ in range(N-1+M):
    l,r = [int(v) for v in input().split()]
    ad_list[l].append(r)
    ad_num[r-1] += 1

for i in range(1,N+1):
    if ad_num[i-1] == 0:
        topo.append(i)
queue = topo[:]
topo = [[0,topo[0]]]
while queue:
    n1 = queue.pop(0)
    for n2 in ad_list[n1]:
        ad_num[n2-1] -= 1
        if ad_num[n2-1] == 0:
            topo.append([n1,n2])
            queue.append(n2)
topo.sort(key=lambda x:x[1])
for i,v in topo:
    print(i)
#  visited = [False for _ in range(N)]

#  ans = 0
#  path_len = 0
#  def dfs(node,cnt=1):
    #  global ans
    #  if visited[node-1]: return 0
    #  visited[node-1] = True
    #  ans = max(ans,cnt)
    #  for n in ad_list[node]:
        #  dfs(n,cnt+1)

#  for n in range(1,N+1):
    #  dfs(n)
#  print(ans)


Fixed submission:
from collections import deque

N,M = [int(v) for v in input().split()]
ad_list = [[] for _ in range (N+1)]
ad_num = [0 for _ in range(N)]
topo = []

for _ in range(N-1+M):
    l,r = [int(v) for v in input().split()]
    ad_list[l].append(r)
    ad_num[r-1] += 1

for i in range(1,N+1):
    if ad_num[i-1] == 0:
        topo.append(i)
queue = deque(topo[:])
topo = [[0,topo[0]]]
while queue:
    n1 = queue.popleft()
    for n2 in ad_list[n1]:
        ad_num[n2-1] -= 1
        if ad_num[n2-1] == 0:
            topo.append([n1,n2])
            queue.append(n2)
topo.sort(key=lambda x:x[1])
for i,v in topo:
    print(i)
#  visited = [False for _ in range(N)]

#  ans = 0
#  path_len = 0
#  def dfs(node,cnt=1):
    #  global ans
    #  if visited[node-1]: return 0
    #  visited[node-1] = True
    #  ans = max(ans,cnt)
    #  for n in ad_list[node]:
        #  dfs(n,cnt+1)

#  for n in range(1,N+1):
    #  dfs(n)
#  print(ans)
Buggy python submission (verdict: Runtime Error):
n = int(input())
h = [int(v) for v in input().split()]

cost = [0 for _ in range(10001)]
for i in range(1,n):
  cost[i] = cost[i-1] + abs(h[i]-h[i-1])
  if i > 1:
    cost[i] = min(cost[i],cost[i-2]+abs(h[i] - h[i-2]))

print(cost[n-1])

Fixed submission:
n = int(input())
h = [int(v) for v in input().split()]
c = [0,abs(h[0]-h[1])]

for i in range(1,n-1):
  cost1 = c[i-1] + abs(h[i-1] - h[i+1])
  cost2 = c[i] + abs(h[i]-h[i+1])
  c.append(min(cost1,cost2))

print(c[-1])
Buggy python submission (verdict: Time Limit Exceeded):
N,W = [int(v) for v in input().split()]
items = [[int(v) for v in input().split()] for _ in range(N)]

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

for i in range(1,N+1):
    w,v = items[i-1]
    for cap in range(W+1):
        if cap - w >= 0:
            dp[i][cap] = max(dp[i][cap],dp[i-1][cap-w]+v)
        dp[i][cap] = max(dp[i][cap],dp[i-1][cap])

print(dp[-1][-1])


Fixed submission:
N,W = [int(v) for v in input().split()]
dp = [[0 for _ in range(W+1)] for _ in range(N+1)]

for i in range(1,N+1):
    w,v = [int(v) for v in input().split()]
    for cap in range(W+1):
        if cap - w >= 0:
            dp[i][cap] = max(dp[i][cap],dp[i-1][cap-w]+v)
        dp[i][cap] = max(dp[i][cap],dp[i-1][cap])

print(dp[-1][-1])

Buggy python submission (verdict: Time Limit Exceeded):
N,W = [int(v) for v in input().split()]
items = [[int(v) for v in input().split()] for _ in range(N)]

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

for i,(w,v) in enumerate(items,1):
    for cap in range(W+1):
        if cap - w >= 0:
            dp[i][cap] = max(dp[i][cap],dp[i-1][cap-w]+v)
        dp[i][cap] = max(dp[i][cap],dp[i-1][cap])

print(dp[-1][-1])


Fixed submission:
N,W = [int(v) for v in input().split()]
dp = [[0 for _ in range(W+1)] for _ in range(N+1)]

for i in range(1,N+1):
    w,v = [int(v) for v in input().split()]
    for cap in range(W+1):
        if cap - w >= 0:
            dp[i][cap] = max(dp[i][cap],dp[i-1][cap-w]+v)
        dp[i][cap] = max(dp[i][cap],dp[i-1][cap])

print(dp[-1][-1])
Buggy python submission (verdict: Runtime Error):
s = input()
t = input()
dp = [[0 for _ in range(len(s)+1)] for _ in range(len(t) + 1)]

for i,c1 in enumerate(s,1):
    for j,c2 in enumerate(t,1):
        if c1 == c2:
            dp[j][i] = dp[j-1][i-1] + 1
        else:
            dp[j][i] = max(dp[j-1][i],dp[j][i-1])

i1,i2 = len(s),len(t)

rev_ans = ""
while i1 != 0:
    lru = dp[i2-1][i1-1]
    now = dp[i2][i1]
    #  print(lru,now)
    if now - lru == 1:
        rev_ans += t[i2-1]
        i2 -= 1
        i1 -= 1
    elif now - dp[i2-1][i1] == 0:
        i2 -= 1
    else:
        i1 -= 1

for c in reversed(rev_ans):
    print(c,end='')


Fixed submission:
s = input()
t = input()
dp = [[0 for _ in range(len(s)+1)] for _ in range(len(t) + 1)]

for i,c1 in enumerate(s,1):
    for j,c2 in enumerate(t,1):
        if c1 == c2:
            dp[j][i] = dp[j-1][i-1] + 1
        else:
            dp[j][i] = max(dp[j-1][i],dp[j][i-1])

i1,i2 = len(s),len(t)
#  print(" " + s)
#  for i,row in enumerate(dp):
    #  if i == 0:
        #  print(" ",row)
    #  else:
        #  print(t[i-1],row)

rev_ans = ""
while i1 != 0:
    lru = dp[i2-1][i1-1]
    now = dp[i2][i1]
    dup = now - dp[i2-1][i1]
    dleft = now - dp[i2][i1-1]
    dupleft = now - lru
    #  print(i1,i2,dupleft,dup,dleft)
    if dupleft == 1 and dleft == 1 and dup == 1:
        rev_ans += t[i2-1]
        i2 -= 1
        i1 -= 1
    elif dleft == 1:
        i2 -= 1
    else:
        i1 -= 1

for c in reversed(rev_ans):
    print(c,end='')
Buggy python submission (verdict: Runtime Error):
N,M = map(int,input().split())
PY = [[int(py) for py in input().split()] for _ in range(M)]

for i in range(1,M+1):
    PY[i-1].append(i)

PY.sort(key=lambda x:x[1])

count = [1 for _ in range(M)]

ans = []

for cell in PY:
    row = '{0:06d}'.format(cell[0]) + '{0:06d}'.format(count[cell[0]-1])
    ans.append([row,cell[2]])
    count[cell[0]-1] += 1


ans.sort(key=lambda x:x[1])

for row in ans:
    print(row[0])

Fixed submission:
N,M = map(int,input().split())
PY = [[int(py) for py in input().split()] for _ in range(M)]

for i in range(1,M+1):
    PY[i-1].append(i)

PY.sort(key=lambda x:x[1])

count = [1 for _ in range(N)]

ans = []

for cell in PY:
    row = '{0:06d}'.format(cell[0]) + '{0:06d}'.format(count[cell[0]-1])
    ans.append([row,cell[2]])
    count[cell[0]-1] += 1


ans.sort(key=lambda x:x[1])

for row in ans:
    print(row[0])

Buggy python submission (verdict: Runtime Error):
N,M = map(int,input().split())
PY = [[int(py) for py in input().split()] for _ in range(M)]

for i in range(1,M+1):
    PY[i-1].append(i)

PY.sort(key=lambda x:x[1])

count = [1 for _ in range(M)]

ans = []

for cell in PY:
    row = '{0:06d}'.format(cell[0]) + '{0:06d}'.format(count[cell[0]])
    ans.append([row,cell[2]])
    count[cell[0]] += 1


ans.sort(key=lambda x:x[1])

for row in ans:
    print(row[0])

Fixed submission:
N,M = map(int,input().split())
PY = [[int(py) for py in input().split()] for _ in range(M)]

for i in range(1,M+1):
    PY[i-1].append(i)

PY.sort(key=lambda x:x[1])

count = [1 for _ in range(N)]

ans = []

for cell in PY:
    row = '{0:06d}'.format(cell[0]) + '{0:06d}'.format(count[cell[0]-1])
    ans.append([row,cell[2]])
    count[cell[0]-1] += 1


ans.sort(key=lambda x:x[1])

for row in ans:
    print(row[0])

Buggy python submission (verdict: Runtime Error):
N,M = map(int,input().split())
PY = [[int(py) for py in input().split()] for _ in range(M)]

for i in range(1,M+1):
    PY[i-1].append(i)

PY.sort(key=lambda x:x[1])

count = [1 for _ in range(M)]

ans = []

for cell in PY:
    row = '{0:06d}'.format(cell[0]) + '{0:06d}'.format(count[cell[0]])
    ans.append([row,cell[2]])
    count[cell[0]] += 1


ans.sort(key=lambda x:x[1])

for row in ans:
    print(row[0])

Fixed submission:
N,M = map(int,input().split())
PY = [[int(py) for py in input().split()] for _ in range(M)]

for i in range(1,M+1):
    PY[i-1].append(i)

PY.sort(key=lambda x:x[1])

count = [1 for _ in range(N)]

ans = []

for cell in PY:
    row = '{0:06d}'.format(cell[0]) + '{0:06d}'.format(count[cell[0]-1])
    ans.append([row,cell[2]])
    count[cell[0]-1] += 1


ans.sort(key=lambda x:x[1])

for row in ans:
    print(row[0])
Buggy python submission (verdict: Runtime Error):
n , x = map(int,input().split())

field = [int(i) for i in input().split()]

diff = list(map(lambda a:abs(a-x),field))

def gcd(x,y):

    if x < y:
        x,y = y,x

    if x % y == 0:
        return y
    else:
        gcd(y,x%y)

ans = diff[0]


for i in diff[1:]:
    ans = gcd(i,ans)

print(ans)

Fixed submission:
h,w = map(int,input().split())

a = [[int(i) for i in input().split()] for _ in range(h)]

total = 0

ans = []

for i,row in enumerate(a):
    for j,cell in enumerate(row):
        if(cell % 2 == 0):
            continue
        
        if(i == h - 1 and j == w -1):
            break
        
        if(j != w - 1):
            a[i][j+1] += 1
            ans.append([i+1,j+1,i+1,j+2])
            total += 1
        elif(i != h - 1):
            a[i+1][j] += 1
            ans.append([i+1,j+1,i+2,j+1])
            total += 1

        
print(total)

for a in ans:
    print(*a)
Buggy python submission (verdict: Time Limit Exceeded):
import math
n,k = map(int,input().split())
a = list(map(int,input().split()))

i_1 = a.index(1)

ans = 9999999999

# left = len(a[:i_1])
# right len(a[i_1+1:)

# if left < k or right <k:
#     c = math.ce

for i in range(1,k+1):
    count = 1
    left = i_1-(k-i)
    right = i_1+i

    if left < 0 or right < 0:
        continue


    l_l = len(a[:left])
    r_l = len(a[right:])

    count += math.ceil(l_l / (k-1)) + math.ceil(r_l / (k-1))
    ans = min(count,ans)

print(ans)

Fixed submission:
import math
n,k = map(int,input().split())
a = list(map(int,input().split()))

i_1 = a.index(1)

ans = 9999999999

left = len(a[:i_1])
right = len(a[i_1:])

for i in range(k):
    x = left  - i
    y = right - (k-i)
    
    if x < 0 or y < 0:
        continue
    
    count = 1 + math.ceil(x/(k - 1)) + math.ceil(y/(k - 1))
    ans = min(ans,count)

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
s = input()


total = 3 * 10 ** 5

for i in range(n):
    total = min(total,(s[:i].count("W")+s[i:].count("E")))

print(total)

Fixed submission:
n = int(input())
s = list(input())

total = s.count("E")

min_val = total

for char in s:
    if char == "E":
        total -= 1
    else:
        total += 1
    min_val = min(min_val, total)

print(min_val)
Buggy python submission (verdict: Runtime Error):
s = input()
k = int(input())

words = set()

l = len(s)

for i in range(1,k+1):
    for j in range(l-k):
        words.add(s[j:i+j])

sort_word = sorted(words)
print(sort_word[k-1])

Fixed submission:
s = input()
k = int(input())

words = set()

l = k+1 if len(s) > k else len(s) + 1

for i in range(1,l):
    for j in range(len(s)):

        words.add(s[j:i+j])

sort_word = sorted(words)

print(sort_word[k-1])
Buggy python submission (verdict: Runtime Error):
import math
n,x = tuple(map(int,input().split()))

m = []

for i in range(n):
    cost = int(input())
    x -= cost
    m.append(cost)


print(math.floor(x/min(m))+n)

Fixed submission:
s = input()
total = 700
for char in s:
    if char == "o":
        total += 100

print(total)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = [i for i in map(int, input().split())]


def money(arr):
    now_x = 0
    total_score = 0

    for i in arr:
        total_score += abs(i-now_x)
        now_x = i

    total_score += abs(now_x)
    return total_score


for i in range(n):
    tmp = [i for i in a]

    tmp.pop(i)
    tmp.append(0)

    print(money(tmp))


Fixed submission:
n = int(input())
a = [i for i in map(int, input().split())]
a.append(0)
a.insert(0, 0)


def money(arr):
    now_x = 0
    total_score = 0

    for i in arr:
        total_score += abs(i-now_x)
        now_x = i

    total_score += abs(now_x)
    return total_score


total = money(a)


for i in range(len(a)-2):
    now_point = a[i]
    break_point = a[i+1]
    next_point = a[i+2]

    break_distance = abs(next_point-now_point)
    normal_distance = abs(break_point-now_point) + \
        abs(next_point - break_point)

    if(break_distance == normal_distance):
        print(total)
    else:
        print(total - abs(break_distance-normal_distance))
Buggy python submission (verdict: Runtime Error):
import numpy as np
s = input().split("T")
x, y = ([int(i) for i in input().split()])

movex = []
movey = []

for i, t in enumerate(s):
    if i % 2 == 0:
        movex.append(len(t))
    else:
        movey.append(len(t))


def t_dfs(move, target, now):
    #print(move, target, now)
    if len(move) == 0:
        if target == now:
            return True
        else:
            return False

    return t_dfs(move[1:], target, now+move[0]) or t_dfs(move[1:], target, now-move[0])


if t_dfs(movex, x, 0) and t_dfs(movey, y, 0):
    print("YES")
else:
    print("No")


Fixed submission:
# T(ターン)で区切る
s = input().split("T")
x, y = ([int(i) for i in input().split()])

# x方向の移動量とy方向の移動量をまとめる
movex = []
movey = []

for i, t in enumerate(s):
    if i % 2 == 0:
        movex.append(len(t))
    else:
        movey.append(len(t))

# 最終目標地へ到達可能か調べる


def t_dfs(move, target, is_x):
    if is_x:
        target -= move.pop(0)

    move.sort(reverse=True)

    for dx in move:
        if target > 0:
            target -= dx
        else:
            target += dx

    return target == 0


if t_dfs(movex, x, True) and t_dfs(movey, y, False):
    print("Yes")
else:
    print("No")

Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np
s = list(input())
target = np.array([int(i) for i in input().split()])
# 右 : 0 下 : 1 左 : 2 上 :3
direction = np.array([[1, 0], [0, -1], [-1, 0], [0, 1]])


queue = [[np.array([0, 0]), 0, s]]
flag = False

while queue:
    state, now_d, s = queue.pop(0)

    if len(s) == 0:
        if np.allclose(target, state):
            flag = True
            break
        else:
            continue

    operation = s[0]

    if operation == "F":
        next_state = state + direction[now_d]
        queue.append([next_state, now_d, s[1:]])
    elif operation == "T":
        queue.append([state, (now_d+1) % 4, s[1:]])
        queue.append([state, (now_d-1) % 4, s[1:]])

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


Fixed submission:
# T(ターン)で区切る
s = input().split("T")
x, y = ([int(i) for i in input().split()])

# x方向の移動量とy方向の移動量をまとめる
movex = []
movey = []

for i, t in enumerate(s):
    if i % 2 == 0:
        movex.append(len(t))
    else:
        movey.append(len(t))

# 最終目標地へ到達可能か調べる


def t_dfs(move, target, is_x):
    if is_x:
        target -= move.pop(0)

    move.sort(reverse=True)

    for dx in move:
        if target > 0:
            target -= dx
        else:
            target += dx

    return target == 0


if t_dfs(movex, x, True) and t_dfs(movey, y, False):
    print("Yes")
else:
    print("No")