qyliang/CodeNanoFix huggingface dataset:
Buggy code:
n=int(input())
h=[int(x) for x in input().split()]
cost=[0]
cost.append(abs(h[0]-h[1]))
for p in range(2,n):
    cost.append(min(cost[p-1]+abs(h[p]-h[p-1]),abs(h[p]-h[p-2])+cost[p-2]))
print(cost)
print(cost[n-1])

Fixed code:
n=int(input())
h=[int(x) for x in input().split()]
cost=[0]
cost.append(abs(h[0]-h[1]))
for p in range(2,n):
    cost.append(min(cost[p-1]+abs(h[p]-h[p-1]),abs(h[p]-h[p-2])+cost[p-2]))
print(cost[n-1])
Buggy code:
n = int(input())
nums = list(map(int, input().split(" ")))
def frog(n, nums):
    if n == 0:
        return 0
    if n == 1:
        return nums[0]
    cost = [0, nums[0]]
    for i in range(2, len(nums)):
        cost.append(cost[i-2] + min(abs(nums[i-2] - nums[i]), abs(nums[i-1] - nums[i])))
    return cost[n - 1]
print(frog(n, nums))

Fixed code:
n = int(input())
nums = list(map(int, input().split(" ")))
def frog(n, nums):
    cost = [0, abs(nums[1] - nums[0])]
    for i in range(2, len(nums)):
        cost.append(min(cost[i-2] + abs(nums[i-2] - nums[i]), cost[i-1] + abs(nums[i-1] - nums[i])))
    return cost[n - 1]
print(frog(n, nums))
Buggy code:
N = int(input())
h = list(map(int, input().split()))

dp = [0] * (N+2)

for i in range(N):
    dp[i+1] = min(dp[i+1], dp[i]+abs(h[i]-h[i+1]))
    dp[i+2] = min(dp[i+2], dp[i]+abs(h[i]-h[i+2]))

print(dp[N-1])


Fixed code:
N = int(input())
h = list(map(int, input().split()))

dp = [0] * N
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[N-1])
Buggy code:
N = int(input())
h = list(map(int,input().split()))
A = [float('inf')] * (N)
A[0] = 0

for i in range(N-2):
    p = A[i] + abs(h[i+1] - h[i])
    q = A[i] + abs(h[i+2] - h[i])
    if  p < A[i+1]:
        A[i+1] = p
    if q < A[i+2]:
        A[i+2] = q
print(A[N-1])

Fixed code:
N = int(input())
h = list(map(int,input().split()))
A = [float('inf')] * (N)
A[0] = 0
A[1] = abs(h[1]-h[0])

if N > 2:
    for i in range(2,N):
        p = A[i-1] + abs(h[i-1] - h[i])
        q = A[i-2] + abs(h[i-2] - h[i])
        if  p < A[i]:
            A[i] = p
        if q < A[i]:
            A[i] = q
    print(A[N-1])

else:
    print(abs(h[1]-h[0]))
Buggy code:
N = int(input())
A = list(map(int, input().split()))
dp = [0 for _ in range(len(A))]
dp[0] = 0
for i in range(1,N):
 if i - 2>=0:
  dp[i] = min(dp[i-1] + abs(A[i] - A[i-1]),dp[i-2] + abs(A[i] - A[i-2]))
else:
 dp[i] =dp[i-1] + abs(A[i] - A[i-1])
print(dp)
print(dp[len(A)-1])
    


  

Fixed code:
N = int(input())
A = list(map(int, input().split()))
dp = [0 for _ in range(len(A))]
dp[0] = 0 
for i in range(1,N):
    if i - 2>=0:
        dp[i] = min(dp[i-1] + abs(A[i] - A[i-1]),dp[i-2] + abs(A[i] - A[i-2]))
    else:
        dp[i] =dp[i-1] + abs(A[i] - A[i-1])

print(dp[len(A)-1])
Buggy code:
N = int(input())
H = list(map(int, input().split()))
C = [0 for i in range(N)]
for i in range(N):
  if i == 0:
    C[i] == 0
  elif i == 1:
    c[i] == abs(H[i-1]-H[i])
  else:
    c[i] == min(abs(H[i-1]-H[i]), abs(H[i-2]-H[i]))
print(c[i])

Fixed code:
N = int(input())
H = list(map(int, input().split()))
C = [0 for i in range(N)]
for i in range(N):
  if i == 0:
    C[i] = 0
  elif i == 1:
    C[i] = abs(H[i-1]-H[i])
  else:
    C[i] = min(C[i-1] + abs(H[i-1]-H[i]), C[i-2] + abs(H[i-2]-H[i]))
print(C[N-1])
Buggy code:
inf = 10**9+5
n = int(input())
h = list( map(int,input().split()))

dp = [inf]*n
dp[0] = 0
for i in range(n):
    for j in range(i+1,i+3):
        if j<n:
            dp[j] = min(dp[j],dp[i]+abs(h[i]-h[j]))
            print(dp)
print(dp[-1])


Fixed code:
inf = 10**9+5
n = int(input())
h = list( map(int,input().split()))

dp = [inf]*n
dp[0] = 0
for i in range(n):
    for j in range(i+1,i+3):
        if j<n:
            dp[j] = min(dp[j],dp[i]+abs(h[i]-h[j]))
print(dp[-1])
Buggy code:
N = int(input())
A = list(map(int,input().split()))
dp = [0 for i in range(N)]
dp[0] = 0
dp[1] = abs(A[1] - A[0])
for i in range(2,N):
  dp[i] = min( dp[i-1] + abs(A[i] - A[i-1]),dp[i-2] + abs(A[i] - A[i-2]))
  
print(dp[n-1])


Fixed code:
N = int(input())
A = list(map(int,input().split()))
dp = [0 for i in range(N)]
dp[0] = 0
dp[1] = abs(A[1] - A[0])
for i in range(2,N):
  dp[i] = min( dp[i-1] + abs(A[i] - A[i-1]),dp[i-2] + abs(A[i] - A[i-2]))
  
print(dp[N-1])
Buggy code:
def main():
    import sys
    input = sys.stdin.readline

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

    inf = float("inf")
    dp = [inf]*N

    dp[0] = 0

    for i in range(N-1):
        dp[i+1] = min(dp[i+1], dp[i] + abs(H[i+1]-H[i]))
        if i == N-3:
            dp[i+2] = min(dp[i+2], dp[i] + abs(H[i+2]-H[i]))
    print(dp[-1])


if __name__ == "__main__":
    main()


Fixed code:
def main():
    import sys
    input = sys.stdin.readline

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

    inf = float("inf")
    dp = [inf]*N

    dp[0] = 0

    for i in range(N-1):
        dp[i+1] = min(dp[i+1], dp[i] + abs(H[i+1]-H[i]))
        if i != N-2:
            dp[i+2] = min(dp[i+2], dp[i] + abs(H[i+2]-H[i]))
    print(dp[-1])


if __name__ == "__main__":
    main()
Buggy code:
n = int(input())
h = list(map(int, input().split()))
dp = [0]*n

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


Fixed code:
n = int(input())
h = list(map(int, input().split()))
dp = [0]*n

for i in range(n):
  if i == 0:
    dp[i] = 0
  elif i == 1:
    dp[i] = abs(h[i]-h[i-1])
  else:
    dp[i] = min(dp[i-1]+abs(h[i]-h[i-1]), dp[i-2]+abs(h[i]-h[i-2]))
print(dp[n-1])
Buggy code:
n = int(input())
a = list(map(int,input().split()))
dp = [0,a[1]-a[0]]
for i in range(2,n):
    dp.append(min(dp[i-1]+abs(a[i]-a[i-1]), dp[i-2]+abs(a[i]-a[i-2])))
print(dp[-1])


Fixed code:
n = int(input())
a = list(map(int,input().split()))
dp = [0,abs(a[1]-a[0])]
for i in range(2,n):
    dp.append(min(dp[i-1]+abs(a[i]-a[i-1]), dp[i-2]+abs(a[i]-a[i-2])))
print(dp[-1])
Buggy code:
n = int(input())
hs = [int(s) for s in input().split()]
dp = [0]*n
dp[0], dp[1] = 0, abs(hs[1]-hs[0])
for i in range(2, n):
  dp(i) = min(dp[i-1] + abs (hs[i] - hs[i-1]), dp[i-2] + abs(hs[i] - hs[i-2]))
print(dp[-1])

Fixed code:
n = int(input())
hs = [int(s) for s in input().split()]
dp = [0]*n
dp[0], dp[1] = 0, abs(hs[1]-hs[0])
for i in range(2, n):
  dp[i] = min(dp[i-1] + abs (hs[i] - hs[i-1]), dp[i-2] + abs(hs[i] - hs[i-2]))
print(dp[-1])
Buggy code:
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()


Fixed code:
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 code:
import sys
sys.setrecursionlimit(10000000000)

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

memo = [-1]*N 
def func(n,memo): 
  if n == 0: 
    memo[0] = 0 
    return memo[n] 
  elif n == 1: 
    memo[1] = abs(H[1]-H[0]) 
    return memo[n] 
  else: 
    if memo[n] != -1: 
      return memo[n] 
    else: 
      min_c = min(func(n-1,memo)+abs(H[n]-H[n-1]), func(n-2,memo)+abs(H[n]-H[n-2])) 
      memo[n] = min_c 
    return min_c 
  
print(func(N-1,memo)) 

Fixed code:
import sys
sys.setrecursionlimit(500*500)

N =int(input()) 
H = list(map(int, input().split())) 
  
memo = [-1]*N 
def func(n,memo): 
  if n == 0: 
    memo[0] = 0 
    return memo[n] 
  elif n == 1: 
    memo[1] = abs(H[1]-H[0]) 
    return memo[n] 
  else: 
    if memo[n] != -1: 
      return memo[n] 
    else: 
      min_c = min(func(n-1,memo)+abs(H[n]-H[n-1]), func(n-2,memo)+abs(H[n]-H[n-2])) 
      memo[n] = min_c 
    return min_c 
  
print(func(N-1,memo))
Buggy code:
def jump_cost(value1, value2):
  return abs(value1 - value2)

n = int(input())
stones = [int(i) for i in input().split()]
cost = [float("inf")] * n
cost[0] = 0

for index in range(len(stones) - 1):
  cost[index + 1] = min(cost[index + 1], cost[index] + jump_cost(stones[index], stones[index + 1]))
  if index + 2 < n:
    cost[index + 2] = min(cost[index + 2], cost[index] + jump_cost(stones[index], stones[index + 2]))

return cost[-1]

Fixed code:
def jump_cost(value1, value2):
  return abs(value1 - value2)

def stone_jump(n, stones):
  cost = [float("inf")] * n
  cost[0] = 0

  for index in range(len(stones) - 1):
    cost[index + 1] = min(cost[index + 1], cost[index] + jump_cost(stones[index], stones[index + 1]))
    if index + 2 < n:
      cost[index + 2] = min(cost[index + 2], cost[index] + jump_cost(stones[index], stones[index + 2]))

  print(cost[-1])
  return cost[-1]

n = int(input())
stones = [int(i) for i in input().split()]
stone_jump(n, stones)
Buggy code:
def findmin(arr,n):
  dp = [0]*n
  dp[1] = abs(arr[0]-arr[1])
  for i in range(2,n):
    dp[i] = min(dp[i-1]+abs(arr[i-1]-arr[i]), dp[i-2]+abs(arr[i-2]-arr[i]))
  return dp[-1]

n = int(input())
arr = list(map(int,input().split())
print(findmin(arr,n))

Fixed code:



def findmin(arr,n):
  dp = [0]*n
  dp[1] = abs(arr[0]-arr[1])
  for i in range(2,n):
    dp[i] = min(dp[i-1]+abs(arr[i-1]-arr[i]), dp[i-2]+abs(arr[i-2]-arr[i]))
  return dp[-1]

n = int(input())
arr = list(map(int,input().split()))
print(findmin(arr,n))
Buggy code:
import sys
sys.setrecursionlimit(200000)

n=int(input())
h=[int(i) for i in input().split()]
inf=10**10
dp=[inf]*n
def rec(i):
  if dp[i]<inf:
    return dp[i]
  elif i==0:
    return 0
  elif i==1:
    return h[1]-h[0]
  res=min(inf,rec(i-1)+abs(h[i]-h[i-1]),rec(i-2)+abs(h[i]-h[i-2]))
  dp[i]=res
  return res
print(rec(n-1))


Fixed code:
import sys
sys.setrecursionlimit(200000)
n=int(input())
h=[int(i) for i in input().split()]
inf=10**10
dp=[inf]*n
def rec(i):
  if dp[i]<inf:
    return dp[i]
  elif i==0:
    return 0
  res=inf
  res=min(inf,rec(i-1)+abs(h[i]-h[i-1]))
  if i>1:
    res=min(res,rec(i-2)+abs(h[i]-h[i-2]))
  dp[i]=res
  return res
print(rec(n-1))
Buggy code:
n=int(input())
h=[int(i) for i in input().split()]
li=[float('inf')]*(n)

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

print(li[-1])
    
    

Fixed code:
n=int(input())
h=[int(i) for i in input().split()]
li=[float('inf')]*(n)

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

print(li[-1])
Buggy code:
N = int(input())
li = [list(map(int,input().split())) for _ in range(N)]

dp = [0,0,0]*N
dp[0] = li[0]

for i in range(N-1):
  for j in range(3):
    for k in range(3):
      if j == k: continue
      dp[i+1][j] = dp[i][k] + li[i+1][j]
print(max(dp[-1]))

Fixed code:
N = int(input())
li = [list(map(int,input().split())) for _ in range(N)]

dp = [[0,0,0] for _ in range(N)]
dp[0] = li[0]

for i in range(N-1):
  for j in range(3):
    for k in range(3):
      if j == k: continue
      dp[i+1][j] = max(dp[i+1][j], dp[i][k] + li[i+1][j])
print(max(dp[-1]))
Buggy code:
# C
N = int(input())
abc = [list(map(int, input().split())) for i in range(N)]

da, db, dc = 0, 0, 0

for a, b, c in abc:
    na = max(db, dc) + a
    na = max(da, dc) + a
    na = max(da, db) + a
    
print(max(na, nb, nc))

Fixed code:
# C
N = int(input())
abc = [list(map(int, input().split())) for i in range(N)]

da, db, dc = 0, 0, 0

for a, b, c in abc:
    na = max(db, dc) + a
    nb = max(da, dc) + b
    nc = max(da, db) + c
    da = na
    db = nb
    dc = nc
    
print(max([na, nb, nc]))
Buggy code:
n=int(input())
a=[list(map(int, input().split())) for i in range(n)]
dp=[[0]*3 for i in range(n)]
dp[0]=a[0]
for i in range(1,n):
    for j in range(n):
        dp[i][j]=max(dp[i-1][(j+1)%3]+a[i][(j+1)%3],dp[i-1][(j+2)%3]+a[i][(j+2)%3])
print(max(dp[-1]))

Fixed code:
n=int(input())
x=[list(map(int, input().split())) for i in range(n)]
dp=[[0]*3 for i in range(n+1)]
for i in range(n):
    for j in range(3):
        dp[i+1][j]=max(dp[i][(j+1)%3],dp[i][(j+2)%3])+x[i][j]
print(max(dp[-1]))
Buggy code:
n=int(input())
dp=[[0]*3 for _ in range(n)]
for i in range(n):
  a,b,c=map(int,input().split())
  dp[i][0]=max(dp[i-1][1],dp[i-1][2])+a
  dp[i][1]=max(dp[i-1][0],dp[i-1][2])+b
  dp[i][2]=max(dp[i-1][0],dp[i-1][1])+c
print(max(dp[n-1]))

Fixed code:
n=int(input())
dp=[[0]*3 for _ in range(n)]
dp[0]=list(map(int,input().split()))
for i in range(1,n):
  a,b,c=map(int,input().split())
  dp[i][0]=max(dp[i-1][1],dp[i-1][2])+a
  dp[i][1]=max(dp[i-1][0],dp[i-1][2])+b
  dp[i][2]=max(dp[i-1][0],dp[i-1][1])+c
print(max(dp[-1]))
Buggy code:
import sys
input=sys.stdin.readline
def main():
    n=int(input())
    #H=[list(map(int,input().split())) for _ in range(n)]
    dp=[[-10**9]*3 for _ in range(n)]
    
    for i in range(n):
        a,b,c=map(int,input().split())
        t=[a,b,c]
        if i==0:
            dp[0][0],dp[0][1],dp[0][2]=a,b,c 
        else:
            for j in range(3):
                dp[i][j]=max(dp[i-1][j-1]+t[j-1],dp[i-2]+t[j-2])

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

Fixed code:
import sys
input=sys.stdin.readline
def main():
    n=int(input())
    #H=[list(map(int,input().split())) for _ in range(n)]
    dp=[[-10**9]*3 for _ in range(n)]
    
    for i in range(n):
        a,b,c=map(int,input().split())
        t=[a,b,c]
        if i==0:
            dp[0][0],dp[0][1],dp[0][2]=a,b,c 
        else:
            for j in range(3):
                dp[i][j]=max(dp[i-1][j-1]+t[j],dp[i-1][j-2]+t[j])
    #print(dp)

    print(max(dp[-1]))
main()
Buggy code:
N=int(input())
dp=[[0]*3 for i  in range(n+1)]
for i in range(n):
  a,b,c=map(int,input())
  dp[i+1][0]=max(dp[i][1],dp[i][2])+a
  dp[i+1][1]=max(dp[i][0],dp[i][2])+b
  dp[i+1][2]=max(dp[i][0],dp[i][1])+c
print(max(dp[-1]))

Fixed code:
n=int(input())
dp=[[0]*3 for i  in range(n+1)]
for i in range(n):
  a,b,c=map(int,input().split())
  dp[i+1][0]=max(dp[i][1],dp[i][2])+a
  dp[i+1][1]=max(dp[i][0],dp[i][2])+b
  dp[i+1][2]=max(dp[i][0],dp[i][1])+c
print(max(dp[-1]))
Buggy code:
N = int(input())
act = [tuple(map(int,input().split())) for _ in range(N)]
dp = [[0]*3 for _ in range(N+1)]

for i in range(1,N+1):
  dp[i+1][0] = max(dp[i][1], dp[i][2]) + act[i][0]
  dp[i+1][1] = max(dp[i][0], dp[i][2]) + act[i][1]
  dp[i+1][2] = max(dp[i][0], dp[i][1]) + act[i][2]
  
print(max(dp[N]))

Fixed code:
N = int(input())
act = [list(map(int,input().split())) for _ in range(N)]
dp = [[0]*3 for _ in range(N+1)]

for i in range(N):
  dp[i+1][0] = max(dp[i][1], dp[i][2]) + act[i][0]
  dp[i+1][1] = max(dp[i][0], dp[i][2]) + act[i][1]
  dp[i+1][2] = max(dp[i][0], dp[i][1]) + act[i][2]
  
print(max(dp[N]))
Buggy code:
N = int(input())
act = [list(map(int,input().split())) for _ in range(N)]
dp = [[0]*3 for _ in range(N+1)]

for i in range(1,N+1):
  dp[i+1][0] = max(dp[i][1], dp[i][2]) + act[i][0]
  dp[i+1][1] = max(dp[i][0], dp[i][2]) + act[i][1]
  dp[i+1][2] = max(dp[i][0], dp[i][1]) + act[i][2]
  
print(max(dp[N]))

Fixed code:
N = int(input())
abc = [list(map(int, input().split())) for i in range(N)]

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

for i in range(1, N + 1):
    dp[i][0] = max(dp[i][0], dp[i - 1][1] + abc[i - 1][1])
    dp[i][0] = max(dp[i][0], dp[i - 1][2] + abc[i - 1][2])
    dp[i][1] = max(dp[i][1], dp[i - 1][0] + abc[i - 1][0])
    dp[i][1] = max(dp[i][1], dp[i - 1][2] + abc[i - 1][2])
    dp[i][2] = max(dp[i][2], dp[i - 1][0] + abc[i - 1][0])
    dp[i][2] = max(dp[i][2], dp[i - 1][1] + abc[i - 1][1])

print(max(dp[N]))
Buggy code:
# -*- coding: utf-8 -*-
import numpy as np
def fnSolv():
  iNum = int(input())
  naABC = np.zeros((iNum, 3), dtype = int)
  naDP  = [0]*3
  #naDP  = [10**9, 10**9, 10**9]
  for iI in range(iNum):
    naABC[iI] = list(map(int, input().split()))
  for iA, iB, iC in naABC:
    naDPa = max([naDP[1] + iA, naDP[2] + iA])
    naDPb = max([naDP[2] + iB, naDP[0] + iB])
    naDPc = max([naDP[0] + iC, naDP[1] + iC])
    naDP = [naDPa, naDPb, naDPc]
    print(naDP)
  print(max(naDP))

if __name__ == '__main__':
  fnSolv()

Fixed code:
# -*- coding: utf-8 -*-
import numpy as np
def fnSolv():
  iNum = int(input())
  naABC = np.zeros((iNum, 3), dtype = int)
  naDP  = [0]*3
  #naDP  = [10**9, 10**9, 10**9]
  for iI in range(iNum):
    naABC[iI] = list(map(int, input().split()))
  for iA, iB, iC in naABC:
    naDPa = max([naDP[1] + iA, naDP[2] + iA])
    naDPb = max([naDP[2] + iB, naDP[0] + iB])
    naDPc = max([naDP[0] + iC, naDP[1] + iC])
    naDP = [naDPa, naDPb, naDPc]
    #print(naDP)
  print(max(naDP))

if __name__ == '__main__':
  fnSolv()
Buggy code:
x=int(input())
days=[]
for i in range(x):
    days.append(list(map(int,input().split())))
print(days)
dp=[0]*3
dp=days[0]
for cur in range(1,x):
    m=[0]*3
    for i in range(3):
        for j in range(3):
            if i!=j:
                m[i]=max(m[i],days[cur][i]+dp[j])
    dp=m
print(max(dp))
            

Fixed code:
x=int(input())
days=[]
for i in range(x):
    days.append(list(map(int,input().split())))
#print(days)
dp=[0]*3
dp=days[0]
for cur in range(1,x):
    m=[0]*3
    for i in range(3):
        for j in range(3):
            if i!=j:
                m[i]=max(m[i],days[cur][i]+dp[j])
    dp=m
print(max(dp))
Buggy code:
N = int(input())
a = [list(map(int, input().split())) for i in range(N)]
dp = [[0 for i in range(3)] for j in range(N)]
dp[0] = a[0]

for i in range(N - 1):
    for j in range(3):
        for k in range(3):
            if j == k:
                continue
            dp[i + 1][j] = max(dp[i + 1][j], dp[i][j] + a[i + 1][k])

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

Fixed code:
N = int(input())
a = [list(map(int, input().split())) for i in range(N)]

dp = [[0 for i in range(3)] for j in range(N + 1)]

for i in range(N):
    for j in range(3):
        for k in range(3):
            if j == k:
                continue
            dp[i + 1][k] = max(dp[i + 1][k], dp[i][j] + a[i][k])

print(max(dp[N]))
Buggy code:
N = int(input())
dp = [[0] * 3 for _ in range(N+1)]
A = [list(map(int,input().split())) for _ in range(N)]

for i in range(N):
    for j in range(3):
        for k in range(3):
            if j == k:
                continue
            dp[i+1][k] = max(dp[i+1][k], dp[i][k] + A[i][j])
            print(dp)
print(max(dp[N]))


Fixed code:
N = int(input())
dp = [[0] * 3 for _ in range(N+1)]
A = [list(map(int,input().split())) for _ in range(N)]

for i in range(N):
    for j in range(3):
        for k in range(3):
            if j == k:
                continue
            dp[i+1][k] = max(dp[i+1][k], dp[i][j] + A[i][k])
print(max(dp[N]))
Buggy code:
n = int(input())
dp = [[0] * 3 for _ in range(n)]

dp[0] = list(map(int, input().split()))
for i in range(1, n):
    a, b, c = map(int, input().split())
    dp[i][0] = a + max(dp[i - 1][1], dp[i - 1][2])
    dp[i][1] = b + max(dp[i - 1][0], dp[i - 1][2])
    dp[i][2] = c + max(dp[i - 1][1], dp[i - 1][1])
    
print(max(dp[-1]))

Fixed code:
n = int(input())
dp = [[0] * 3 for _ in range(n)]

dp[0] = list(map(int, input().split()))
for i in range(1, n):
    a, b, c = map(int, input().split())
    dp[i][0] = a + max(dp[i - 1][1], dp[i - 1][2])
    dp[i][1] = b + max(dp[i - 1][0], dp[i - 1][2])
    dp[i][2] = c + max(dp[i - 1][0], dp[i - 1][1])
    
print(max(dp[-1]))
Buggy code:
n = int(input())
dp = [int(i) for i in input().split()]

for i in range(n-1):
    a, b, c = map(int, input().split())
    dp[0] = max(b, c) + dp[0]
    dp[1] = max(a, c) + dp[1]
    dp[2] = max(a, b) + dp[2]
    
print(max(dp))

Fixed code:
n = int(input())
dp = [int(i) for i in input().split()]

for i in range(n-1):
    a, b, c = map(int, input().split())
    dp = [max(dp[1], dp[2]) + a, max(dp[0], dp[2]) + b, max(dp[0], dp[1]) + c]
    
print(max(dp))
Buggy code:
n = int(input())
A = [[int(i) for i in input().split()] for i in range(n)]
dp = [A[0][0], A[0][1], A[0][2]]

for i in range(1, n):
    dp = [dp[0] + max(A[i][1], A[i][2]), dp[1] + max(A[i][0], A[i][2]), dp[2] + max(A[i][0], A[i][1])]

print(max(dp))

Fixed code:
n = int(input())
dp = [0, 0, 0]

for i in range(n):
    A = [int(i) for i in input().split()]
    dp = [max(dp[1], dp[2]) + A[0], max(dp[0], dp[2]) + A[1], max(dp[0], dp[1]) + A[2]]
    
print(max(dp))
Buggy code:
N = int(input())

A = [map(int, input().split())]
B = [map(int, input().split())]
C = [map(int, input().split())]

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

dp[0][0] = A[0]
dp[0][1] = B[0]
dp[0][2] = C[0]

for i in range(1, N):
    
    dp[i][0] = max(dp[i - 1][1], dp[i - 1][2]) + A[i]
    dp[i][1] = max(dp[i - 1][2], dp[i - 1][0]) + B[i]
    dp[i][2] = max(dp[i - 1][0], dp[i - 1][1]) + C[i]

print(max(dp[-1]))

Fixed code:
N = int(input())

A = [0 for _ in range(N)]
B = [0 for _ in range(N)]
C = [0 for _ in range(N)]

for i in range(N):
    A[i], B[i], C[i] = map(int, input().split())

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

dp[0][0] = A[0]
dp[0][1] = B[0]
dp[0][2] = C[0]

for i in range(1, N):
    
    dp[i][0] = max(dp[i - 1][1], dp[i - 1][2]) + A[i]
    dp[i][1] = max(dp[i - 1][2], dp[i - 1][0]) + B[i]
    dp[i][2] = max(dp[i - 1][0], dp[i - 1][1]) + C[i]

print(max(dp[-1]))
Buggy code:
n = int(input())
import numpy as np
abc = np.array([[int(x) for x in input().split()] for y in range(n)],dtype=int)
dp = np.zeros((n,3),dtype=int)
dp[0] = abc[0]
for p in range(1,n):
    dp[p][0] = max(dp[p-1][1],dp[p-1][2]) + abc[p][0]
    dp[p][1] = max(dp[p-1][0],dp[p-1][2]) + abc[p][1]
    dp[p][2] = max(dp[p-1][0],dp[p-1][1]) + abc[p][2]
print(dp)
print(max(dp[n-1]))

Fixed code:
n = int(input())
import numpy as np
abc = np.array([[int(x) for x in input().split()] for y in range(n)],dtype=int)
dp = np.zeros((n,3),dtype=int)
dp[0] = abc[0]
for p in range(1,n):
    dp[p][0] = max(dp[p-1][1],dp[p-1][2]) + abc[p][0]
    dp[p][1] = max(dp[p-1][0],dp[p-1][2]) + abc[p][1]
    dp[p][2] = max(dp[p-1][0],dp[p-1][1]) + abc[p][2]
print(max(dp[n-1]))
Buggy code:
n = int(input())
a = [0] * n
for x in range(n):
    a[x] = list(map(int, input().split()))
print(a)
dp = [[0 for _ in range(3)] for _ in range(n+1)]
print(dp)
for i in range(n):
    for j in range(3):
        for k in range(3):
            if j == k:
                continue
            dp[i + 1][k] = max(dp[i + 1][k], dp[i][j] + a[i][k])
print(dp)
print(max(dp[n]))

Fixed code:
n = int(input())
a = [0] * n
for x in range(n):
    a[x] = list(map(int, input().split()))
# print(a)
dp = [[0 for _ in range(3)] for _ in range(n+1)]
# print(dp)
for i in range(n):
    for j in range(3):
        for k in range(3):
            if j == k:
                continue
            dp[i + 1][k] = max(dp[i + 1][k], dp[i][j] + a[i][k])
# print(dp)
print(max(dp[n]))
Buggy code:
N = int(input())
a = []
for i in range(N):
  a.append(list(map(int,input().split())))
A = [a[0][0]]
B = [a[0][1]]
C = [a[0][2]]
if N == 1:
  print(max(a))
else:
  for i in range(N-1):
    A.append(max(B[i],C[i])+a[i+1][0])
    B.append(max(A[i],C[i])+a[i+1][1])
    C.append(max(A[i],B[i])+a[i+1][2])
  print(max(A[N-1],B[N-1],C[N-1]))

Fixed code:
N = int(input())
a = []
for i in range(N):
  a.append(list(map(int,input().split())))
A = [a[0][0]]
B = [a[0][1]]
C = [a[0][2]]
if N == 1:
  print(max(A[0],B[0],C[0]))
else:
  for i in range(N-1):
    A.append(max(B[i],C[i])+a[i+1][0])
    B.append(max(A[i],C[i])+a[i+1][1])
    C.append(max(A[i],B[i])+a[i+1][2])
  print(max(A[N-1],B[N-1],C[N-1]))