Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
# cadidates of no shortest paths
n, m = map(int, input().split())

d = [[float("inf") for i in range(n + 1)] for i in range(n + 1)]
edge_data=[]
connect={i:[] for i in range(1,n+1)}
for i in range(m):
    x, y, z = map(int, input().split())
    # 有向グラフか無向グラフかによってここで場合わけが生じる
    d[x][y] = z
    d[y][x] = z
    connect[x].append(y)
    connect[y].append(x)    
    edge_data.append((x,y,z))
for i in range(n + 1):
    d[i][i] = 0  # 自身のところに行くコストは０


def warshall_floyd(d):
    # d[i][j]=i番目の頂点からj番目の頂点までの最短距離
    for k in range(1, n + 1):
        for i in range(1, n + 1):
            for j in range(1, n + 1):
                d[i][j] = min(d[i][j], d[i][k] + d[k][j])
    return d

warshall_floyd(d)

#最短距離を求めた
cnt=0
for some in edge_data:
    x,y,zsome[0],some[1],some[2]
    if d[x][y]<z:
        cnt+=1
print(cnt)


Fixed submission:
# cadidates of no shortest paths
n, m = map(int, input().split())

d = [[float("inf") for i in range(n + 1)] for i in range(n + 1)]
edge_data=[]
connect={i:[] for i in range(1,n+1)}
for i in range(m):
    x, y, z = map(int, input().split())
    # 有向グラフか無向グラフかによってここで場合わけが生じる
    d[x][y] = z
    d[y][x] = z
    connect[x].append(y)
    connect[y].append(x)    
    edge_data.append((x,y,z))
for i in range(n + 1):
    d[i][i] = 0  # 自身のところに行くコストは０


def warshall_floyd(d):
    # d[i][j]=i番目の頂点からj番目の頂点までの最短距離
    for k in range(1, n + 1):
        for i in range(1, n + 1):
            for j in range(1, n + 1):
                d[i][j] = min(d[i][j], d[i][k] + d[k][j])
    return d

warshall_floyd(d)

#最短距離を求めた
cnt=0
for some in edge_data:
    x,y,z=some[0],some[1],some[2]
    if d[x][y]<z:
        cnt+=1
print(cnt)
Buggy python submission (verdict: Time Limit Exceeded):
# Cosmic rays
import math
import heapq

xs, ys, xt, yt = map(int, input().split())
N = int(input())

d = [((xs, ys), 0, 0)]
# node,radius

for _ in range(N):
    x, y, r = map(int, input().split())
    d.append(((x, y), _+1, r))

graph = {i: [] for i in range(N+2)}

d.append(((xt, yt), N+1, 0))
for i in range(N+2):
    for j in range(i+1, N+2):
        p, point, rad = d[i]
        q, point2, rad2 = d[j]
        D = math.hypot(p[0]-q[0], p[1]-q[1])
        if D > (rad+rad2):
            graph[i].append((D-rad-rad2, j))
            graph[j].append((D-rad-rad2, i))
        else:
            graph[i].append((0, j))
            graph[j].append((0, i))


def dijkstra(s, graph):
    n = len(graph)
    dist = [float("inf") for i in range(n+1)]
    dist[s] = 0
    pq = []
    heapq.heapify(pq)
    heapq.heappush(pq, (0, s))
    while pq:
        mini_dis, node = heapq.heappop(pq)
        if dist[node] < mini_dis:
            continue
        for w, point in graph[node]:
            if dist[point] < w:
                continue
            newlen = dist[node]+w
            if newlen < dist[point]:
                heapq.heappush(pq, (newlen, point))
                dist[point] = newlen
    return dist

K=dijkstra(0,graph)[N+1]
print(K)


Fixed submission:
# Cosmic rays
import math
import heapq

xs, ys, xt, yt = map(int, input().split())
N = int(input())

d = [((xs, ys), 0, 0)]
# node,radius

for _ in range(N):
    x, y, r = map(int, input().split())
    d.append(((x, y), _+1, r))

graph = {i: [] for i in range(N+2)}

d.append(((xt, yt), N+1, 0))
for i in range(N+2):
    for j in range(i+1, N+2):
        p, point, rad = d[i]
        q, point2, rad2 = d[j]
        D = math.hypot(p[0]-q[0], p[1]-q[1])
        if D > (rad+rad2):
            graph[i].append((D-rad-rad2, j))
            graph[j].append((D-rad-rad2, i))
        else:
            graph[i].append((0, j))
            graph[j].append((0, i))


def dijkstra(s, graph):
    n = len(graph)
    dist = [float("inf") for i in range(n+1)]
    dist[s] = 0
    pq = []
    heapq.heapify(pq)
    heapq.heappush(pq, (0, s))
    while pq:
        mini_dis, node = heapq.heappop(pq)
        if dist[node] < mini_dis:
            continue
        for w, point in graph[node]:
            if dist[point] < w:
                continue
            newlen = dist[node]+w
            if newlen < dist[point]:
                heapq.heappush(pq, (newlen, point))
                dist[point] = newlen
    return dist

K=dijkstra(0,graph)[N+1]
print(K)
Buggy python submission (verdict: Runtime Error):
#greedy方法
import fractions
n=int(input())
lists=[]
for x in range(n):
    x,y=map(int,input().split())
    lists.append([x,y])
lists.append([1,1])
a=lists[0][0]
b=lists[0][1]
k=0
cnt=0
while cnt<n:
    k=max(fractions.ceil(a/lists[cnt+1][0]),fractions.ceil(b/lists[cnt+1][1]))
    a=lists[cnt+1][0]*k
    b=lists[cnt+1][1]*k   
    cnt+=1    
print(a+int(a*(min(lists[n-1][0],lists[n-1][1])/max(lists[n-1][0],lists[n-1][1])) ))

Fixed submission:
n=int(input())
lists=[]
import math
for i in range(n):
    a,t=map(int,input().split())
    lists.append([a,t])
x=1
y=1
for i in range(n):
    j=max((x-1)//lists[i][0]+1,(y-1)//lists[i][1]+1)
    x=lists[i][0]*j
    y=lists[i][1]*j
print(x+y)
Buggy python submission (verdict: Runtime Error):
#D-atcoderくんと変なジャンケン
s=input()
import collections
S=dict(collections.Counter(s))
a=S["p"]
b=S["g"]
x=((a+b)//2)
print(x-a)

Fixed submission:
#D-atcoderくんと変なジャンケン
s=input()+"g"+"p"
import collections
S=dict(collections.Counter(s))
a=S["p"]-1
b=S["g"]-1
x=((a+b)//2)
print(x-a)
Buggy python submission (verdict: Time Limit Exceeded):
#すぬけくんの塗り絵
h,w,n=map(int,input().split())
dic={}
for  _ in range(n):
    a,b=map(int,input().split())
    for i in range(a-1,a+2):
        for j in range(b-1,b+2):
            if (i,j) in dic.keys():
                dic[(i,j)]+=1
            else:
                dic[(i,j)]=1
              
howmany=[0 for i in range(10)]
for some in dic.keys():
    a,b=some[0],some[1]
    if 2<=a<=h-1 and 2<=b<=w-1:
        howmany[dic[some]]+=1
J=(h-2)*(w-2)-sum(howmany)
print(J)
for i in range(1,10):
    print(howmany[i])

Fixed submission:
#すぬけくんの塗り絵
h,w,n=map(int,input().split())
dic={}
for  _ in range(n):
    a,b=map(int,input().split())
    for i in range(a-1,a+2):
        for j in range(b-1,b+2):
            if (i,j) in dic.keys():
                dic[(i,j)]+=1
            else:
                dic[(i,j)]=1
              
howmany=[0 for i in range(10)]
for some in dic.keys():
    a,b=some[0],some[1]
    if 2<=a<=h-1 and 2<=b<=w-1:
        howmany[dic[some]]+=1
J=(h-2)*(w-2)-sum(howmany)
print(J)
for i in range(1,10):
    print(howmany[i])
Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
A = [0]*(n)
for i in range(n):
    s=int(input())
    A[i]=s
    
lista=sorted(A)
cnt=0
for a in range(0,n,2):
    if A.index(lista[a])%2!=0:
        cnt+=1
print(cnt)

Fixed submission:
n=int(input())
A = [0]*(n)
for i in range(n):
    s=int(input())
    A[i]=[s,i]    
lista=sorted(A,key=lambda x:x[0])
cnt=0
for i in range(n):
    lista[i].append(i)
for i in range(n):
    if (lista[i][1]-lista[i][2])%2!=0:
        cnt+=1
print(cnt//2)
Buggy python submission (verdict: Runtime Error):
from math import gamma
cnt=0
h,w,a,b=map(int,input().split())
for k in range(0,h-a):
    cnt+= (int((gamma(b+k)*gamma(h+w-k-b-1))/(gamma(k+1)*gamma(b)*gamma(w-b)*gamma(h-k))))//(10^9+7)
print(cnt)

Fixed submission:
# D　イロハちゃんと升目
cnt=0
h,w,a,b=map(int,input().split())
def find_power(n):
    # 0!からn!までのびっくりを出してくれる関数
    powlist=[0]*(n+1)
    powlist[0]=1
    powlist[1]=1
    for i in range(2,n+1):
        powlist[i]=powlist[i-1]*i%(10**9+7)
    return powlist

def find_inv_power(n):
    #0!からn!までの逆元を10**9+7で割ったあまりリストを作る関数
    powlist=find_power(n)
    check=powlist[-1]
    first=1
    uselist=[0]*(n+1)
    secondlist=[0]*30
    secondlist[0]=check
    secondlist[1]=check**2
    for i in range(28):
        secondlist[i+2]=(secondlist[i+1]**2)%(10**9+7)
    a=format(10**9+5,"b")
    for j in range(30):
        if a[29-j]=="1":
            first=(first*secondlist[j])%(10**9+7)
    uselist[n]=first
    for i in range(n,0,-1):
        uselist[i-1]=(uselist[i]*i)%(10**9+7)
    return uselist

powlist=find_power(h+w+1)
invlist=find_inv_power(h+w+1)
def combi(n,r):
    a=powlist
    b=invlist
    if n<r:
        return 0
    elif n>=r:
        return (a[n]*b[r]*b[n-r])%(10**9+7)

for i in range(h-a):
    cnt+=(combi(b+i-1,i)*combi(w+h-2-b-i,h-1-i))%(10**9+7)
print(cnt%(10**9+7))
Buggy python submission (verdict: Runtime Error):
n, k = input().split(" ")
n = int(n)
k = int(k)
a = [int(x) for x in input().split(" ")]
a.sort()
ans = 0
for i in range(k):
 ans += int(a[i])
print(ans)


Fixed submission:
x = input()
print('A' if ord(x) < ord('a') else 'a')
Buggy python submission (verdict: Runtime Error):
n, k = input().split(" ")
n = int(n)
k = int(k)
a = input.split(" ")
a = sorted(a)
ans = 0
for i in range(k):
 ans += int(a[i])
print(ans)

Fixed submission:
n, k = input().split(" ")
n = int(n)
k = int(k)
a = [int(x) for x in input().split(" ")]
a.sort()
ans = 0
for i in range(k):
 ans += int(a[i])
print(ans)
Buggy python submission (verdict: Runtime Error):
r = 1
for i in range(input().split(' ')):
 r ^= int(i)
print(r)

Fixed submission:
r = 1
for i in input().split(' '):
 r ^= int(i)
print(r)
Buggy python submission (verdict: Runtime Error):
x, y = input().split(" ")
x = int(x)
 y = int(y)
print("Yes" if 2*x <= y and y <= 4*x and y%2 == 0 else "No")

Fixed submission:
x, y = input().split(" ")
x = int(x)
y = int(y)
print("Yes" if 2*x <= y and y <= 4*x and y%2 == 0 else "No")
Buggy python submission (verdict: Runtime Error):
a, b, c, k = [int(i) i in input().split(" ")]
print(min(a, k) - max(0, k-a-b))


Fixed submission:
a, b, c, k = [int(i) for i in input().split(" ")]
print(min(a, k) - max(0, k-a-b))

Buggy python submission (verdict: Runtime Error):
a, b, c, k = [int(i) in input().split(" ")]
print(min(a, k) - max(0, k-a-b))

Fixed submission:
a, b, c, k = [int(i) for i in input().split(" ")]
print(min(a, k) - max(0, k-a-b))
Buggy python submission (verdict: Runtime Error):
a = int(input())
a -= a%5
print(2*a - a%500)

Fixed submission:
s = input()
if s[2] == s[3] and s[4] == s[5]:
    print("Yes")
else:
    print("No")
Buggy python submission (verdict: Runtime Error):
print(int(input()-1)//2)


Fixed submission:
print((int(input())-1)//2)
Buggy python submission (verdict: Runtime Error):
n = int(input())
a = [int(i) for i in input().split()]
q = 0
for i in range(n):
 for j in range(i+1, n):
  t = a[i]
  a[i] = a[j]
  a[j] = t
  f = 1  
  lst = - 1100
  for k in a:
   f &= k > lst
   lst = k
  q |= f
  t = a[i]
  a[i] = a[j]
  a[j] = t
print("YES" if q else "NO")


Fixed submission:
a, b = [int(i) for i in input().split(" ")]
print("IMPOSSIBLE" if (a+b)%2 else (a+b)//2)
Buggy python submission (verdict: Runtime Error):
n = int(input())
a = [int(i) for in input().split()]
t = 0
for i in range(n):
 for j in range(i+1,n):
  t += a[i] > a[j]
print("YES" if t < 2 else "NO")

Fixed submission:
n = int(input())
a = [int(i) for i in input().split()]
q = 0
for i in range(n):
 for j in range(i, n):
  t = a[i]
  a[i] = a[j]
  a[j] = t
  f = 1  
  lst = - 1100
  for k in a:
   f &= k > lst
   lst = k
  q |= f
  t = a[i]
  a[i] = a[j]
  a[j] = t
print("YES" if q else "NO")
Buggy python submission (verdict: Runtime Error):
a, b, c = [int(i) for i in input().split()]
if a >= b and a >= c:
 print(c*b//2)
else if b >= c and b >= a:
 print(a*c//2)
else:
 print(a*b//2)


Fixed submission:
a, b, c = [int(i) for i in input().split()]
if a >= b and a >= c:
 print(c*b//2)
elif b >= c and b >= a:
 print(a*c//2)
else:
 print(a*b//2)

Buggy python submission (verdict: Runtime Error):
a, b, c = [int(i) for i in input().split()]
if a >= b and a >= c:
 print(c*b//2)
else if b >= c and b >= a:
 print(a*c//2)
else
 print(a*b//2)

Fixed submission:
a, b, c = [int(i) for i in input().split()]
if a >= b and a >= c:
 print(c*b//2)
elif b >= c and b >= a:
 print(a*c//2)
else:
 print(a*b//2)
Buggy python submission (verdict: Runtime Error):
p = -1
xp = -1
ans = 0
input()
for i in range(input().split(" ")):
  i = int(i)
  if i == p: continue
  if p != -1:
    x = p < i
    if xp != -1
      ans += x != xp
    xp = x
  p = i

Fixed submission:
p = -1
xp = -1
ans = 1
input()
for i in input().split(" "):
  i = int(i)
  if i == p: continue
  if p != -1:
    x = p < i
    if xp != -1:
      ans += x != xp
    if xp != -1 and x != xp:
      xp = -1
    else:
      xp = x
  p = i
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
import sys
sys.setrecursionlimit(1000000)


def main():
  N,Q = map(int,input().split())
  trees = [[] for _ in range(N+1)]
  values = [0 for _ in range(N+1)]
  
  for _ in range(N-1):
    parent,child = map(int,input().split())
    trees[parent].append(child)
    trees[child].append(parent)
  
  for _ in range(Q):
    node_num,value = map(int,input().split())
    values[node_num] += value
  
  def recursive_func(i,parent):
    for child in trees[i]:
      if child == parent:
        continue
      values[child] += values[i]
      recursive_func(child,i)
  
  recursive_func(1,-1)
  print(*values[1:])


if __name__ == "__main__":
  main()

Fixed submission:
import sys
input = sys.stdin.readline
sys.setrecursionlimit(1000000)
n, q = map(int, input().split())

trees = [ [] for i in range(n+1) ]
for i in range(n-1):
    a, b = map(int, input().split())
    trees[a].append(b)
    trees[b].append(a)

values = [ 0 for i in range(n+1) ]
for i in range(q):
    p, x = map(int, input().split())
    values[p] += x
#print(values)

def dfs2(i, parent):
    for j in trees[i]:
        if j == parent: continue
        values[j] += values[i]
        dfs2(j, i)

dfs2(1, -1)
print(*values[1:])

Buggy python submission (verdict: Time Limit Exceeded):

class Node(object):
  def __init__(self,name):
    self.name=name
    self.value = 0
    self.nodes_names = []
    self.nodes = []
  
  def set_nodes(self,all_Nodes_dic):
    for name,node in all_Nodes_dic.items():
      if name in self.nodes_names:
        self.nodes.append(node)
  
  def update_value(self,val):
    self.value += val
    for node in self.nodes:
      node.update_value(val)



def main():
  N,Q = map(int,input().split())
  all_Nodes = {}
  tasks=[]
  for _ in range(N-1):
    name,pname = map(int,input().split())
    if name not in all_Nodes.keys():
      node = Node(name)
      node.nodes_names.append(pname)
      all_Nodes.update({name:node})
    else:
      node = all_Nodes[name]
      node.nodes_names.append(pname)
    
    if pname not in all_Nodes.keys():
      node = Node(pname)
      all_Nodes.update({pname:node})
  
  for _ in range(Q):
    node_name,point = map(int,input().split())
    tasks.append((node_name,point))

  for node in all_Nodes.values():
    node.set_nodes(all_Nodes)
  
  for name,value in tasks:
    parent = all_Nodes[name]
    parent.update_value(value)
  
  sorted_lst = sorted(list(all_Nodes.values()), key=lambda x:x.name)

  print(" ".join([str(node.value) for node in sorted_lst]))
  return


if __name__ == "__main__":
  main()





Fixed submission:
import sys
input = sys.stdin.readline
sys.setrecursionlimit(1000000)
n, q = map(int, input().split())

trees = [ [] for i in range(n+1) ]
for i in range(n-1):
    a, b = map(int, input().split())
    trees[a].append(b)
    trees[b].append(a)

values = [ 0 for i in range(n+1) ]
for i in range(q):
    p, x = map(int, input().split())
    values[p] += x
#print(values)

def dfs2(i, parent):
    for j in trees[i]:
        if j == parent: continue
        values[j] += values[i]
        dfs2(j, i)

dfs2(1, -1)
print(*values[1:])
Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
a=list(map(int,input().split()))
for i in range(n):
    print(a.count(i+1))

Fixed submission:
n=int(input())
a=list(map(int,input().split()))
b=[]
for i in range(n):
    b.append(0)
for i in range(n-1):
    b[a[i]-1] +=1
for i in range(n):
    print(b[i])

Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
a=list(map(int,input().split()))
for i in range(n):
    print(a.count(i+1))

Fixed submission:
n=int(input())
a=list(map(int,input().split()))
b=[]
for i in range(n):
    b.append(0)
for i in range(n-1):
    b[a[i]-1] +=1
for i in range(n):
    print(b[i])
Buggy python submission (verdict: Runtime Error):
N = int(input())
mnstr = list(map(int, input().split()))
yusha = list(map(int, input().split()))
sum = 0
killed = 0

for i in range(N):
  killedtemp1 = min(mnstr[i], yusha[i])#iの勇者が倒したモンスターiの数
  yusha[i] = max(0, yusha[i]-mnstr[i])
  killedtemp2 = min(mnstr[i+1], yusha[i])#iの勇者が倒したモンスターi+1の数
  mnstr[i+1] = mnstr[i+1] - killedtemp2
  killed += killedtemp1 + killedtemp2
  
print(killed)
  

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

sum = a + b
if sum % 2 == 1:
  print("IMPOSSIBLE")
else:
  print(sum // 2)
Buggy python submission (verdict: Runtime Error):
L, R = map(int, input().split())

Lmod = L%2019
Rmod = R%2019

i = Lmod
j = i + 1

for k in range(L, R+1):
  if (k%2019) == 0:
    print(0)
    break
  elif k < R:
	continue
  else:
	print((i*j)%2019)

Fixed submission:
N, A, B = map(int, input().split())

print(min(A*N, B))

Buggy python submission (verdict: Runtime Error):
L, R = map(int, input().split())

Lmod = L%2019
Rmod = R%2019

i = Lmod
j = i + 1

for k in range(L, R+1):
  if (k%2019) == 0:
    print(0)
    break
  elif (k < R):
  	continue
  else:
    print((i*j)%2019)


Fixed submission:
N, A, B = map(int, input().split())

print(min(A*N, B))

Buggy python submission (verdict: Runtime Error):
L, R = map(int, input().split())

Lmod = L%2019
Rmod = R%2019

i = Lmod
j = i + 1

print((i*j)%2019)

Fixed submission:
N, A, B = map(int, input().split())

print(min(A*N, B))
Buggy python submission (verdict: Runtime Error):
S = list(input())
S.sort()
if (S[0] == S[1]) and (S[2] == S[3]):
  print(Yes)
else:
  print(No)

Fixed submission:
S = list(input())
S.sort()
if (S[0] == S[1]) and (S[2] == S[3]) and (S[1] != S[2]):
  print('Yes')
else:
  print('No')
Buggy python submission (verdict: Runtime Error):
N = int(input())
d = list(map(int, input().split()))

d.sort()

left = d[int(N/2)]
right = d[int(N/2) +1]

dif = right - left

print(dif)

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

d.sort()
left = d[int(N/2-1)]
right = d[int(N/2)]

dif = right - left

print(dif)

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

d.sort()

left = d[N//2]
right = d[N//2 +1]

dif = right - left

print(dif)

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

d.sort()
left = d[int(N/2-1)]
right = d[int(N/2)]

dif = right - left

print(dif)
Buggy python submission (verdict: Runtime Error):
X, A = map(int, input().split)

if X < A:
  print(0)
else:
  print(10)

Fixed submission:
X, A = map(int, input().split())

if X < A:
  print(0)
else:
  print(10)
Buggy python submission (verdict: Runtime Error):
x, y = map(int, input().split())

print(max(x, y) + max(max(x, y)-1, min(x,y))


Fixed submission:
x, y = map(int, input().split())

print(max(x, y) + max(max(x, y)-1, min(x,y)))

Buggy python submission (verdict: Runtime Error):
x, y = map(int, input().split())

print(max(x, y) + max(max(x, y)-1, min(x,y))

Fixed submission:
x, y = map(int, input().split())

print(max(x, y) + max(max(x, y)-1, min(x,y)))
Buggy python submission (verdict: Runtime Error):
n = int(input())
a = [0]*n
b = [0]*n
c = [0]*n
for i in range(n):
    a[i], b[i], c[i] = map(int, input().split())

dpa = [a[0]]+[0]*(n-1)
dpb = [b[0]]+[0]*(n-1)
dpc = [c[0]]+[0]*(n-1)
for i in range(1,n):
    dpa[i] = max( dpb[i-1]+a[i], dpc[i-1]+a[i])
    dpb[i] = max( dpc[i-1]+b[i], dpa[i-1]+b[i])
    dpa[i] = max( dpa[i-1]+c[i], dpb[i-1]+c[i])

print(max(dpa[-1], dpb[-1], dpc[-1]))

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

dp = [0]*n
dp[0] = 0
dp[1] = abs(h[1]-h[0])
for i in range(2,n):
    dp[i] = min(dp[i-1]+abs(h[i]-h[i-1]),dp[i-2]+abs(h[i]-h[i-2]))
print(dp[-1])

Buggy python submission (verdict: Runtime Error):
n = int(input())
a = [0]*n
b = [0]*n
c = [0]*n
for i in range(n):
    a[i], b[i], c[i] = map(int, input().split())

dpa = a[0]+[0]*(n-1)
dpb = b[0]+[0]*(n-1)
dpc = c[0]+[0]*(n-1)
for i in range(1,n):
    dpa[i] = max( dpb[i-1]+a[i], dpc[i-1]+a[i])
    dpb[i] = max( dpc[i-1]+b[i], dpa[i-1]+b[i])
    dpa[i] = max( dpa[i-1]+c[i], dpb[i-1]+c[i])

print(max(dpa[-1], dpb[-1], dpc[-1]))

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

dp = [0]*n
dp[0] = 0
dp[1] = abs(h[1]-h[0])
for i in range(2,n):
    dp[i] = min(dp[i-1]+abs(h[i]-h[i-1]),dp[i-2]+abs(h[i]-h[i-2]))
print(dp[-1])

Buggy python submission (verdict: Runtime Error):
n, k = map(int, input().split())
h = tuple(map(int, input().split()))

dp = [0] + [float("inf")]*(n-1)
dp[0] = 0
for i in range(1,n):
    for j in range(max(0,i-k), i):
        dp[i] = min( dp[i], dp[j]+abs(h[i]-h[j]) )
print(dp[-1])

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

dp = [0]*n
dp[0] = 0
dp[1] = abs(h[1]-h[0])
for i in range(2,n):
    dp[i] = min(dp[i-1]+abs(h[i]-h[i-1]),dp[i-2]+abs(h[i]-h[i-2]))
print(dp[-1])

Buggy python submission (verdict: Runtime Error):
import sys
input = sys.stdio.readline

n = int(input())
h = tuple(map(int, input().split()))

dp = [0]*n
dp[0] = 0
dp[1] = abs(h[1]-h[0])
for i in range(2,n):
    dp[i] = min(dp[i-1]+abs(h[i]-h[i-1]),dp[i-2]+abs(h[i]-h[i-2]))
print(dp[-1])

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

dp = [0]*n
dp[0] = 0
dp[1] = abs(h[1]-h[0])
for i in range(2,n):
    dp[i] = min(dp[i-1]+abs(h[i]-h[i-1]),dp[i-2]+abs(h[i]-h[i-2]))
print(dp[-1])

Buggy python submission (verdict: Runtime Error):
n = int(input)
h = tuple(map(int, input().split()))

dp = [0]*n
dp[0] = 0
dp[1] = abs(h[1]-h[0])
for i in range(2,n):
    dp[i] = min(dp[i-1]+abs(h[i]-h[i-1]),dp[i-2]+abs(h[i]-h[i-2]))
print(dp[-1])

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

dp = [0]*n
dp[0] = 0
dp[1] = abs(h[1]-h[0])
for i in range(2,n):
    dp[i] = min(dp[i-1]+abs(h[i]-h[i-1]),dp[i-2]+abs(h[i]-h[i-2]))
print(dp[-1])
Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = sys.stdin.readline

n, k = map(int, input().split())
h = tuple(map(int, input().split()))

dp = [0] + [float("inf")]*(n-1)
dp[0] = 0
for i in range(1,n):
    for j in range(max(0,i-k), i):
        dp[i] = min( dp[i], dp[j]+abs(h[i]-h[j]) )
print(dp[-1])

Fixed submission:
import sys
input = sys.stdin.readline

n, k = map(int, input().split())
h = tuple(map(int, input().split()))

dp = [0] + [float("inf")]*(n-1)
dp[0] = 0
for i in range(1,n):
    for j in range(max(0,i-k), i):
        dp[i] = min( dp[i], dp[j]+abs(h[i]-h[j]) )
print(dp[-1])

Buggy python submission (verdict: Time Limit Exceeded):
n, k = map(int, input().split())
h = tuple(map(int, input().split()))

dp = [0] + [float("inf")]*(n-1)
dp[0] = 0
for i in range(1,n):
    for j in range(max(0,i-k), i):
        dp[i] = min( dp[i], dp[j]+abs(h[i]-h[j]) )
print(dp[-1])

Fixed submission:
import sys
input = sys.stdin.readline

n, k = map(int, input().split())
h = tuple(map(int, input().split()))

dp = [0] + [float("inf")]*(n-1)
dp[0] = 0
for i in range(1,n):
    for j in range(max(0,i-k), i):
        dp[i] = min( dp[i], dp[j]+abs(h[i]-h[j]) )
print(dp[-1])
Buggy python submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline

n = int(input())
a = [0]*n
b = [0]*n
c = [0]*n
for i in range(n):
    a[i], b[i], c[i] = map(int, input().split())

dpa = a[0]+[0]*(n-1)
dpb = b[0]+[0]*(n-1)
dpc = c[0]+[0]*(n-1)
for i in range(1,n):
    dpa[i] = max( dpb[i-1]+a[i], dpc[i-1]+a[i])
    dpb[i] = max( dpc[i-1]+b[i], dpa[i-1]+b[i])
    dpa[i] = max( dpa[i-1]+c[i], dpb[i-1]+c[i])

print(max(dpa[-1], dpb[-1], dpc[-1]))

Fixed submission:
n = int(input())
a = [0]*n
b = [0]*n
c = [0]*n
for i in range(n):
    a[i], b[i], c[i] = map(int, input().split())

dpa = [a[0]]+[0]*(n-1)
dpb = [b[0]]+[0]*(n-1)
dpc = [c[0]]+[0]*(n-1)
for i in range(1,n):
    dpa[i] = max(dpb[i-1]+a[i],dpc[i-1]+a[i])
    dpb[i] = max(dpc[i-1]+b[i],dpa[i-1]+b[i])
    dpc[i] = max(dpa[i-1]+c[i],dpb[i-1]+c[i])

print(max(dpa[-1], dpb[-1], dpc[-1]))