qyliang/CodeNanoFix huggingface dataset:
Buggy code:
n = int(input())
a = [list(map(int,input().split())) for _ in range(n)]
dp = [[0, 0, 0] for _ in range(n+1)]
for i in range(n):
    for j in range(3):
        for k in range(3):
            if j != k:
                dp[i+1][j] = max(dp[i+1][j], dp[i][j]+a[i][k])
print(max(dp[n]))

Fixed code:
n = int(input())
a = [list(map(int,input().split())) for _ in range(n)]
dp = [[0, 0, 0] for _ in range(n+1)]
for i in range(n):
    for j in range(3):
        for k in range(3):
            if j != k:
                dp[i+1][k] = max(dp[i+1][k], dp[i][j]+a[i][k])
print(max(dp[n]))
Buggy code:
import sys
def input():
    return sys.stdin.readline()[:-1]
n=int(input())
abc=[list(map(int,input().split())) for i in range(n)]
happy=[[0,0,0] for i in range(n)]
happy[0]=abc[0]
print(happy)
for i in range(n-1):
    for j in range(3):
        for k in range(3):
            if j==k:
                continue
            happy[i+1][k]=max(happy[i+1][k],happy[i][j]+abc[i+1][k])
    # print(happy)
print(max(happy[-1]))

Fixed code:
import sys
def input():
    return sys.stdin.readline()[:-1]
n=int(input())
abc=[list(map(int,input().split())) for i in range(n)]
happy=[[0,0,0] for i in range(n)]
happy[0]=abc[0]
# print(happy)
for i in range(n-1):
    for j in range(3):
        for k in range(3):
            if j==k:
                continue
            happy[i+1][k]=max(happy[i+1][k],happy[i][j]+abc[i+1][k])
    # print(happy)
print(max(happy[-1]))
Buggy code:
num = int(input())
actions = []
for i in range(num):
    actions.append(list(map(int, input().split())))

dp = [[0 if j != 0 else actions[i][j] for i in range(3)] for j in range(num)]
for i in range(num):
    dp[i][0] = max(dp[i-1][1], dp[i-1][2]) + actions[i][0]
    dp[i][1] = max(dp[i-1][0], dp[i-1][2]) + actions[i][1]
    dp[i][2] = max(dp[i-1][0], dp[i-1][1]) + actions[i][2]

print(max( dp[num-1][0], dp[num-1][1] ,dp[num-1][2] ))

Fixed code:
num = int(input())
actions = []
for i in range(num):
    actions.append(list(map(int, input().split())))

dp = [[0 for i in range(3)] for j in range(num)]
for i in range(num):
    if i == 0:
        dp[i][0] = actions[i][0]
        dp[i][1] = actions[i][1]
        dp[i][2] = actions[i][2]
    else:
        dp[i][0] = max(dp[i-1][1] + actions[i][0], dp[i-1][2] + actions[i][0])
        dp[i][1] = max(dp[i-1][0] + actions[i][1], dp[i-1][2] + actions[i][1])
        dp[i][2] = max(dp[i-1][0] + actions[i][2], dp[i-1][1] + actions[i][2])

print(max( dp[num-1][0], dp[num-1][1] ,dp[num-1][2] ))
Buggy code:
n=int(input())
l=list()
for i in range(n):
  li=[int(i) for i in input().split()]
  l.append(li)
dp=[[0,0,0] for i in range(n)]
dp[0][0]=l[0][0]
dp[0][1]=l[0][1]
dp[0][2]=l[0][2]
for i in range(1,n):
  for j in range(3):
    for k in range(3):
      dp[i][j]=max(dp[i-1][k]+l[i][k],dp[i][j])
print(max(dp[-1]))

Fixed code:
n=int(input())
l=list()
for i in range(n):
  li=[int(i) for i in input().split()]
  l.append(li)
dp=[[0,0,0] for i in range(n)]
dp[0][0]=l[0][0]
dp[0][1]=l[0][1]
dp[0][2]=l[0][2]
for i in range(1,n):
  for j in range(3):
    for k in range(3):
        if j!=k:
            dp[i][j]=max(dp[i-1][k]+l[i][j],dp[i][j])
print(max(dp[-1]))
Buggy code:
n=int(input())
dp=[]
for i in range(n):
  l=list(map(int,input().split()))
  dp.append(l)
for i in range(1,n):
  for j in range(3):
  	dp[i][(j%3)]+=max(dp[i][(j+1)%3],dp[i][(j+2)%3]) 
print(max(dp[n-1]))
  

Fixed code:
n=int(input())
dp=[]
for i in range(n):
  l=list(map(int,input().split()))
  dp.append(l)
for i in range(1,n):
  for j in range(3):
  	dp[i][(j%3)]+=max(dp[i-1][(j+1)%3],dp[i-1][(j+2)%3]) 
print(max(dp[n-1]))
Buggy code:
from sys import stdin
#from collections import deque
#from math import sqrt, floor, ceil, log, log2, log10, pi, gcd, sin, cos, asin
def ii(): return int(stdin.readline())
def fi(): return float(stdin.readline())
def mi(): return map(int, stdin.readline().split())
def fmi(): return map(float, stdin.readline().split())
def li(): return list(mi())
def lsi():
    x=list(stdin.readline())
    x.pop()
    return x
def si(): return stdin.readline()
############# CODE STARTS HERE #############
n=ii()
a, b, c=mi()
for _ in range(n-1):
    x, y, z=mi()
    a+=max(y, z)
    b+=max(x, z)
    c+=max(y, z)
print(max(a, b, c))

Fixed code:
from sys import stdin
#from collections import deque
#from math import sqrt, floor, ceil, log, log2, log10, pi, gcd, sin, cos, asin
def ii(): return int(stdin.readline())
def fi(): return float(stdin.readline())
def mi(): return map(int, stdin.readline().split())
def fmi(): return map(float, stdin.readline().split())
def li(): return list(mi())
def lsi():
    x=list(stdin.readline())
    x.pop()
    return x
def si(): return stdin.readline()
############# CODE STARTS HERE #############
n=ii()
x, y, z=mi()
for _ in range(n-1):
    a, b, c=mi()
    a+=max(y, z)
    b+=max(x, z)
    c+=max(y, x)
    x, y, z=a, b, c
print(max(x, y, z))
Buggy code:
N=int(input())
A=[]
B=[]
C=[]
for i in range(N):
  a,b,c=map(int,input().split())
  A.append(a)
  B.append(b)
  C.append(c)
dp=[[0 for i in range(N)]for j 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]=[max(dp[i-1][1]+A[i],dp[i-1][2]+A[i]),max(dp[i-1][0]+B[i],dp[i-1][2]+B[i]),max(dp[i-1][0]+C[i],dp[i-1][1]+C[i])]
print(max(dp[N-1][0],dp[N-1][1],dp[N-1][2]))
  
                  

Fixed code:
N=int(input())
a,b,c=map(int,input().split())
dp=[[0 for i in range(3)]for j in range(N)]
dp[0]=[a,b,c]
for i in range(1,N):
  A,B,C=map(int,input().split())
  dp[i]=[max(dp[i-1][1]+A,dp[i-1][2]+A),max(dp[i-1][0]+B,dp[i-1][2]+B),max(dp[i-1][0]+C,dp[i-1][1]+C)]
print(max(dp[N-1][0],dp[N-1][1],dp[N-1][2]))
Buggy code:
from sys import stdin
n=int(stdin.readline())
dp=[0]*3
for i in range(n):
    before=[i for i in dp]
    l=list(map(int,stdin.readline().split()))
    for i in range(3):
        dp[i]=max(before[i]+l[(i+1)%3],before[i]+l[(i+2)%3])
print(max(dp))

Fixed code:
from sys import stdin
n=int(stdin.readline())
dp=[0]*3
for i in range(n):
    before=[0,0,0]
    l=list(map(int,stdin.readline().split()))
    for i in range(3):
        before[i]=max(dp[(i+1)%3],dp[(i+2)%3])+l[i]
    dp=before
print(max(dp))
Buggy code:
n=int(input())
l=[]
for i in range(n):
  a,b,c=map(int,input().split())
  l.append([a,b,c])

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

Fixed code:
n=int(input())
l=[]
for i in range(n):
  a,b,c=map(int,input().split())
  l.append([a,b,c])

dp=l[0]
for i in range(1,n):
    dp=[max(dp[1],dp[2])+l[i][0],max(dp[0],dp[2])+l[i][1],max(dp[0],dp[1])+l[i][2]]
print(max(dp))
Buggy code:
# encoding: utf-8
N = int(input())
abc = [list(map(int, input().split())) for i in range(N)]


score = [[0] * N for i in range(3)] # N - 1 is used as -1
for i in range(N):
    for dst in range(3):
        tmp = abc[i][dst]
        for src in range(3):
            if dst == src: continue
            elif score[src][i - 1] + tmp > score[dst][i]:
                score[dst][i] = score[src][i - 1] + tmp

# print('#', score)
print(max((score[0][-1], score[1][-1], score[2][-1])))

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


score = [[0] * N for i in range(3)] # N - 1 is used as -1
for i in range(N):
    for dst in range(3):
        tmp = abc[i][dst]
        for src in range(3):
            if dst == src: continue
            elif score[src][i - 1] + tmp > score[dst][i]:
                score[dst][i] = score[src][i - 1] + tmp

# print('#', score)
if N == 1: print(max(abc[-1]))
else: print(max((score[0][-1], score[1][-1], score[2][-1])))
Buggy code:
n=int(input())
H=[list(map(int,input().split())) for i in range(n)]
dp=[[0 for i in range(3)] for i in range(n)]
for i in range(3):
    dp[0][i]=H[0][i]
for i in range(n-1):
    for j in range(3):
        if j==0:
            dp[i+1][0]=max(dp[i][1]+H[i+1][1],dp[i][2]+H[i+1][2])
        if j==1:
            dp[i+1][1]=max(dp[i][0]+H[i+1][0],dp[i][2]+H[i+1][2])
        if j==2:
            dp[i+1][2]=max(dp[i][0]+H[i+1][0],dp[i][1]+H[i+1][1])
print(max(dp[n-1][0],dp[n-1][1],dp[n-1][2]))

Fixed code:
n = int(input())
dp = [[0 for i in range(3)] for i in range(n)]
H = [list(map(int,input().split())) for i in range(n)]
for i in range(3):
    dp[0][i]=H[0][i]
for i in range(n-1):
    for j in range(3):
        if j==0:
            dp[i+1][0]=max(dp[i][1]+H[i+1][0],dp[i][2]+H[i+1][0])
        if j==1:
            dp[i+1][1]=max(dp[i][0]+H[i+1][1],dp[i][2]+H[i+1][1])
        if j==2:
            dp[i+1][2]=max(dp[i][0]+H[i+1][2],dp[i][1]+H[i+1][2])
print(max(dp[n-1][0],dp[n-1][1],dp[n-1][2]))
Buggy code:
n = int(input())


days = [] 
for _ in range(n):
  temp = list(map(int,input().split()))
  days.append(temp)
  
dp = [0]*n

for i in range(3):
  dp[i]= days[0][i]
#print(dp) 
for cur_day in range(1,n):
  m = [0]*n
  for i in range(3):
    for j in range(3):
      if i!=j:
        m[i] = max(m[i],dp[j]+days[cur_day][j])
  dp = m
#  print(dp)
  
print(max(dp))
  

Fixed code:
n = int(input())


days = [] 
for _ in range(n):
  temp = list(map(int,input().split()))
  days.append(temp)
  
dp = [0]*3

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

@lru_cache(maxsize=1000000)
def dp(i, a):
    if i == 0:
        return action[0][a]
    else:
        return max(dp(i-1, (a+1)%3), dp(i-1, (a+2)%3)) + action[i][a]

import sys
sys.setrecursionlimit(1000000)
print(max([dp(n-1,a) for a in range(3)]))


Fixed code:
from functools import lru_cache

n = int(input())
action = []
for i in range(n):
    action.append(list(map(int,input().split())))

@lru_cache(maxsize=None)
def dp(i, a):
    if i == 0:
        return action[0][a]
    else:
        return max(dp(i-1, (a+1)%3), dp(i-1, (a+2)%3)) + action[i][a]

import sys
sys.setrecursionlimit(1000000)
print(max([dp(n-1,a) for a in range(3)]))
Buggy code:
n = int(input())
action = []
for i in range(n):
    action.append(list(map(int,input().split())))

memo = []
for i in range(n):
    memo.append([-1]*3)
def dp(i, a):
    if i == 0:
        return action[0][a]
    elif memo[i][a] != -1:
        return memo[i][a]
    else:
        return memo[i][a] = max(dp(i-1, (a+1)%3), dp(i-1, (a+2)%3)) + action[i][a]

print(max([dp(n-1,a) for a in range(3)]))


Fixed code:
n = int(input())
action = []
for i in range(n):
    action.append(list(map(int,input().split())))

memo = []
for i in range(n):
    memo.append([-1]*3)

def dp(i, a):
    if i == 0:
        return action[0][a]
    elif memo[i][a] != -1:
        return memo[i][a]
    else:
        memo[i][a] = max(dp(i-1, (a+1)%3), dp(i-1, (a+2)%3)) + action[i][a]
        return memo[i][a]

import sys
sys.setrecursionlimit(1000000)
print(max([dp(n-1,a) for a in range(3)]))
Buggy code:

n = int(input())
x = [-1]*n
for i in range(n):
    x[i] = list(map(int, input().split()))

ans = [[0]*3 for i in range(n)]
ans[0] = x[0]

for k in range(1,n):
    for j in range(3):
        ans[k][j] = max(ans[k-1][(j+1)%3], ans[k-1][(j+2)%3]) + x[k][j]
    print(ans[i])

print(max(ans[n-1]))



Fixed code:

n = int(input())
x = [-1]*n
for i in range(n):
    x[i] = list(map(int, input().split()))

ans = [[0]*3 for i in range(n)]
ans[0] = x[0]

for k in range(1,n):
    for j in range(3):
        ans[k][j] = max(ans[k-1][(j+1)%3], ans[k-1][(j+2)%3]) + x[k][j]

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

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

import sys

intMaxValue = sys.maxsize


def problem():
    N = int(input.split())
    activityList = []
    for i in range(N):
      row = list(map(int, input().split()))
      activityList.append(row)

    print(algorithm(N,activityList))

def algorithm(N, activityList):
  dp = [[0, 0, 0] for i in range(N+ 1)]

  for index in range(1, N + 1):
    for j in range(3):
      for k in range(3):
        if j == k:
          continue
        if dp[index][j] < dp[index - 1][k] + activityList[index-1][j]:
          dp[index][j] = dp[index - 1][k] + activityList[index-1][j]
      
  return max(dp[N])


problem()

Fixed code:

import sys


def problem():
    N = int(input())
    activityList = []
    for i in range(N):
      row = list(map(int, input().split()))
      activityList.append(row)

    print(algorithm(N,activityList))

def algorithm(N, activityList):
  dp = [[0, 0, 0] for i in range(N+ 1)]

  for index in range(1, N + 1):
    for j in range(3):
      for k in range(3):
        if j == k:
          continue
        if dp[index][j] < dp[index - 1][k] + activityList[index-1][j]:
          dp[index][j] = dp[index - 1][k] + activityList[index-1][j]
      
  return max(dp[N])

problem()
Buggy code:
import numpy as np
N = int(input())
abc = []
for i in range(N):
  abc.append([int(i) for i in input().split()])
abc.append([0,0,0])
dp = np.zeros([N+1,3])
print(dp)

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

Fixed code:
import numpy as np
N = int(input())
abc = []
for i in range(N):
  abc.append([int(i) for i in input().split()])
abc.append([0,0,0])
dp = np.zeros([N+1,3])
#print(dp)

for i in range(1,N+1):
  dp[i][0],dp[i][1],dp[i][2] = max(dp[i-1][1]+abc[i-1][0], dp[i-1][2]+abc[i-1][0]), max(dp[i-1][0]+abc[i-1][1], dp[i-1][2]+abc[i-1][1]), max(dp[i-1][1]+abc[i-1][2], dp[i-1][0]+abc[i-1][2])
  #print(dp)
print(int(max(dp[N])))
Buggy code:
n=int(input())
dp=[0,0,0]
for i in range(n):
    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[n-1]))

Fixed code:
n=int(input())
dp=[0,0,0]
for i in range(n):
    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())
lst=[]
for i in range(n):
  a,b,c=map(int,input().split())
  lst.append([a,b,c])
C=[[float('inf')]*3]*n
C[0][0]=lst[0][0]
C[0][1]=lst[0][1]
C[0][2]=lst[0][2]
D=[0,1,2]
d=D
for i in range(n-1):
  for j in d:
    D=d
    D.remove(j)
    C[i+1][j]=max(C[i][D[0]],C[i][D[1]])
print(max(C[n-1]))
      
    
  
  


Fixed code:
n=int(input())
lst=[]
for i in range(n):
  a,b,c=map(int,input().split())
  lst.append([a,b,c])
C=[]
for i in range(n):
    C.append([float('inf')]*3)
C[0][0]=lst[0][0]
C[0][1]=lst[0][1]
C[0][2]=lst[0][2]
D=[0,1,2]
for i in range(n-1):
  for j in [0,1,2]:
    del D[j]
    C[i+1][j]=max(C[i][D[0]]+lst[i+1][j],C[i][D[1]]+lst[i+1][j])
    D=[0,1,2]
print(max(C[n-1]))
Buggy code:
import sys
def input():
    return sys.stdin.readline()[:-1]

N = int(input())
ABC = [list(map(int,input().split())) for _ in range(N)]

inf = 10**9+7
dp = [[0] * 3 for _ in range(N+10)]
dp[0] = [ABC[0][0],ABC[0][1],ABC[0][2]]

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]+ABC[i+1][k])
        
    

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


Fixed code:
import sys
def input():
    return sys.stdin.readline()[:-1]

N = int(input())
ABC = [list(map(int,input().split())) for _ in range(N)]

inf = 10**9+7
dp = [[0] * 3 for _ in range(N+10)]
dp[0] = [ABC[0][0],ABC[0][1],ABC[0][2]]

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]+ABC[i+1][j])
        
    

print(max(dp[N-1][:]))
Buggy code:
N= int(input())

arr = [list(map(int,input().split())) for _ in range(N)]
dp = [ list([0,0,0]) for i in range(N)]
for i,l in enumerate(arr):
  if i == 0:
    dp[0] = l
    continue
  dp[i] = [max(dp[i-1][1:])+l[1], max(dp[i-1][0],dp[i-1][2])+l[1],max(dp[i-1][:2])+l[2]]
print(max(dp[-1]))
#print(dp)

Fixed code:
N= int(input())

arr = [list(map(int,input().split())) for _ in range(N)]
dp = [ list([0,0,0]) for i in range(N)]
for i,l in enumerate(arr):
  if i == 0:
    dp[0] = l
    continue
  dp[i] = [max(dp[i-1][1:])+l[0], max(dp[i-1][0],dp[i-1][2])+l[1],max(dp[i-1][:2])+l[2]]
print(max(dp[-1]))
#print(dp)
Buggy code:
n=int(input())
a,b,c=0,0,0
for i in range(n):
    x,y,z=map(int,input().split())
    a,b,c=max(b,c)+x,max(a,c)+y,max(a,b)+z
    print(a,b,c)
print(max(a,b,c))

Fixed code:
n=int(input())
a,b,c=0,0,0
for i in range(n):
    x,y,z=map(int,input().split())
    a,b,c=max(b,c)+x,max(a,c)+y,max(a,b)+z
print(max(a,b,c))
Buggy code:
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())
  a[i] += max(b[i-1],c[i-1])
  b[i] += max(a[i-1],c[i-1])
  c[i] += max(a[i-1],b[i-1])

print(max(a[-1],b[-1],c[-1]))

Fixed code:
N=int(input())
a=[0]*N
b=[0]*N
c=[0]*N
a[0],b[0],c[0]=map(int,input().split())
for i in range(1,N):
  a[i],b[i],c[i]=map(int,input().split())
  a[i] += max(b[i-1],c[i-1])
  b[i] += max(a[i-1],c[i-1])
  c[i] += max(a[i-1],b[i-1])

print(max(a[-1],b[-1],c[-1]))
Buggy code:
import numpy as np
N = int(input())
total = []
dp = np.zeros((3,N), dtype = int)
for i in range(N):
  tmp = list(map(int,input().split()))
  if i == 0:
    dp[i][0] = tmp[0]
    dp[i][1] = tmp[1]
    dp[i][2] = tmp[2]
  else:
    dp[i][0] = max(dp[i-1][1], dp[i-1][2]) + tmp[0]
    dp[i][1] = max(dp[i-1][0], dp[i-1][2]) + tmp[1]
    dp[i][2] = max(dp[i-1][0], dp[i-1][1]) + tmp[2]
print(max(dp[N-1][0],dp[N-1][1],dp[N-1][2]))

Fixed code:
import numpy as np
N = int(input())
total = []
dp = np.zeros((N,3), dtype = int)
for i in range(N):
  tmp = list(map(int,input().split()))
  if i == 0:
    dp[i][0] = tmp[0]
    dp[i][1] = tmp[1]
    dp[i][2] = tmp[2]
  else:
    dp[i][0] = max(dp[i-1][1], dp[i-1][2]) + tmp[0]
    dp[i][1] = max(dp[i-1][0], dp[i-1][2]) + tmp[1]
    dp[i][2] = max(dp[i-1][0], dp[i-1][1]) + tmp[2]
print(max(dp[N-1][0],dp[N-1][1],dp[N-1][2]))
Buggy code:
import numpy as np
N = int(input())
h_list = []
for i in range(N):
    h_list.append([i for i in map(int,input().split())])

print(h_list)

dp = np.zeros((N,3))
dp[0] = h_list[0]
for i in range(1,N):
    dp[i,0] = max(dp[i-1,1], dp[i-1,2]) + h_list[i][0]
    dp[i,1] = max(dp[i-1,0], dp[i-1,2]) + h_list[i][1]
    dp[i,2] = max(dp[i-1,0], dp[i-1,1]) + h_list[i][2]

print(max(dp[-1]))

Fixed code:
import numpy as np
N = int(input())
h_list = []
for i in range(N):
    h_list.append([i for i in map(int,input().split())])

#print(h_list)

dp = np.zeros((N,3))
dp[0] = h_list[0]
for i in range(1,N):
    dp[i,0] = max(dp[i-1,1], dp[i-1,2]) + h_list[i][0]
    dp[i,1] = max(dp[i-1,0], dp[i-1,2]) + h_list[i][1]
    dp[i,2] = max(dp[i-1,0], dp[i-1,1]) + h_list[i][2]

print(int(max(dp[-1])))
Buggy code:
n=int(input())

ab = []
for _ in range(n):
    a, b, c = (int(x) for x in input().split())
    ab.append([a, b, c])

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:
                dp[i+1][k] = max([dp[i+1][k], dp[i][j]+ab[i][k]])

ptint(max(dp[n]))

Fixed code:
n=int(input())

ab = []
for _ in range(n):
    a, b, c = (int(x) for x in input().split())
    ab.append([a, b, c])

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:
                dp[i+1][k] = max([dp[i+1][k], dp[i][j]+ab[i][k]])

print(max(dp[n]))
Buggy code:
from sys import stdin


def main():
    input = lambda: stdin.readline()[:-1]
    N = int(input())
    ABC = [list(map(int, input().split())) for _ in [0] * N]

    dp = [[0, 0, 0] for _ in [0] * N]
    dp[0] = ABC[0][:]
    for i in range(1, N):
        dp[i][0] = max(dp[i-1][0] + ABC[i][1], dp[i-1][0] + ABC[i][2])
        dp[i][1] = max(dp[i-1][1] + ABC[i][0], dp[i-1][1] + ABC[i][2])
        dp[i][2] = max(dp[i-1][2] + ABC[i][0], dp[i-1][2] + ABC[i][1])
    print(max(dp[-1]))


main()


Fixed code:
from sys import stdin


def main():
    input = lambda: stdin.readline()[:-1]
    N = int(input())
    ABC = [list(map(int, input().split())) for _ in [0] * N]

    dp = [[0, 0, 0] for _ in [0] * N]
    dp[0] = ABC[0][:]
    for i in range(1, N):
        dp[i][0] = max(dp[i-1][1] + ABC[i][0], dp[i-1][2] + ABC[i][0])
        dp[i][1] = max(dp[i-1][0] + ABC[i][1], dp[i-1][2] + ABC[i][1])
        dp[i][2] = max(dp[i-1][0] + ABC[i][2], dp[i-1][1] + ABC[i][2])
    print(max(dp[-1]))


main()
Buggy code:
n = int(input())
dp = [map(int, input().split())]
for i in range(n-1):
    a, b, c = map(int, input().split())
    a0 = dp[0]
    b0 = dp[1]
    c0 = dp[2]
    
    dp[0] = max(b0, c0) + a
    dp[1] = max(c0, a0) + b
    dp[2] = max(a0, b0) + c
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())
    a0 = dp[0]
    b0 = dp[1]
    c0 = dp[2]
    
    dp[0] = max(b0, c0) + a
    dp[1] = max(c0, a0) + b
    dp[2] = max(a0, b0) + c
print(max(dp))
Buggy code:
import sys
input = sys.stdin.readline

n = int(input())

abc = [[int(i) for i in input().split()] for j in range(n)]

def happy(n, abc):
    da, db, dc = 0, 0, 0
    for a, b, c in abc:
        na = max(db, dc) + a
        nb = max(dc, da) + b
        nc = max(da, db) + c
    da, db, dc = na, nb, nc

    return max(da, db, dc)

print(happy(n, abc))


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

n = int(input())

abc = [[int(i) for i in input().split()] for j in range(n)]

def happy(n, abc):
    da, db, dc = 0, 0, 0
    for a, b, c in abc:
        na = max(db, dc) + a
        nb = max(dc, da) + b
        nc = max(da, db) + c
        da, db, dc = na, nb, nc

    return max(da, db, dc)

print(happy(n, abc))
Buggy code:
N = int(input())
T = [list(map(int, input().split())) for i in range(N)]
print(T)
dp = [[0 for i in range(3)] for j in range(N+1)]
print(dp)
dp[1] = T[0]
print(dp)
for i in range(2,N+1):
    dp[i][0] = max(dp[i-1][1]+T[i-1][0],dp[i-1][2]+T[i-1][0])
    dp[i][1] = max(dp[i-1][0]+T[i-1][1],dp[i-1][2]+T[i-1][1])
    dp[i][2] = max(dp[i-1][0]+T[i-1][2],dp[i-1][1]+T[i-1][2])
    print(dp)
print(max(dp[-1]))

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

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

for i, a in enumerate(a):
  dp_1 = dp[i-1]
  dp[i][0] = max(dp_1[1], dp_1[2]) + a[0]
  dp[i][1] = max(dp_1[0], dp_1[2]) + a[1]
  dp[i][2] = max(dp_1[0], dp_1[1]) + a[2]

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


Fixed code:
n = int(input())
a = ([list(map(int, input().split())) for _ in range(n)])
a.insert(0,[0,0,0])

dp = [[0,0,0] for _ in range(n+1)]

for i, a in enumerate(a):
  dp_1 = dp[i-1]
  dp[i][0] = max(dp_1[1], dp_1[2]) + a[0]
  dp[i][1] = max(dp_1[0], dp_1[2]) + a[1]
  dp[i][2] = max(dp_1[0], dp_1[1]) + a[2]

print(max(dp[n]))
Buggy code:
import numpy as np
n=int(input())
ABC=[list(map(int,input().split())) for _ in range(n)]

dp=np.zeros((n,3),int)
for i in range(n):
  for j in range(3):
    dp[i][j]=max(dp[i-1][(j+1)%3]+ABC[i][j], dp[i-1][(j+2)%3]+ABC[i][j])
print(max(dp[-1]))

Fixed code:
import numpy as np
n=int(input())
ABC=[list(map(int,input().split())) for _ in range(n)]

dp=np.zeros((n,3),int)
for i in range(n):
  for j in range(3):
    dp[i][j]=ABC[0][j] if i==0 else max(dp[i-1][(j+1)%3]+ABC[i][j], dp[i-1][(j+2)%3]+ABC[i][j])
  
print(max(dp[-1]))