Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
import sys
sys.setrecursionlimit(1000000)
def solve(n,l,pos):
    ans=0
    if(pos==n):
        return 0
    if(pos==n-1):
        return abs(l[-1]-l[-2])
    ans+=min(abs(l[pos-1]-l[pos])+solve(n,l,pos+1),abs(l[pos-1]-l[pos+1])+solve(n,l,pos+2))
    return ans
n=int(input())
l=list(map(int,input().split()))
print(solve(n,l,1))

Fixed submission:
import sys
sys.setrecursionlimit(1000000)
def solve(n,l,pos):
    if(pos==n):
        return 0
    if(pos==n-1):
        return abs(l[-1]-l[-2])
    if(t[pos]!=-1):
        return t[pos]
    t[pos]=min(abs(l[pos-1]-l[pos])+solve(n,l,pos+1),abs(l[pos-1]-l[pos+1])+solve(n,l,pos+2))
    return t[pos]
n=int(input())
l=list(map(int,input().split()))
global t
t=[-1]*(n+1)
print(solve(n,l,1))

Buggy python submission (verdict: Runtime Error):
def solve(n,l,pos):
    ans=0
    if(pos==n):
        return 0
    if(pos==n-1):
        return abs(l[-1]-l[-2])
    ans+=min(abs(l[pos-1]-l[pos])+solve(n,l,pos+1),abs(l[pos-1]-l[pos+1])+solve(n,l,pos+2))
    return ans
n=int(input())
l=list(map(int,input().split()))
print(solve(n,l,1))

Fixed submission:
import sys
sys.setrecursionlimit(1000000)
def solve(n,l,pos):
    if(pos==n):
        return 0
    if(pos==n-1):
        return abs(l[-1]-l[-2])
    if(t[pos]!=-1):
        return t[pos]
    t[pos]=min(abs(l[pos-1]-l[pos])+solve(n,l,pos+1),abs(l[pos-1]-l[pos+1])+solve(n,l,pos+2))
    return t[pos]
n=int(input())
l=list(map(int,input().split()))
global t
t=[-1]*(n+1)
print(solve(n,l,1))
Buggy python submission (verdict: Time Limit Exceeded):
import sys
N,k=map(int,input().split())
A=[int(i) for i in input().split()]
if N==1:
    print(0)
    sys.exit()
dp=[0]*N
dp[0]=0
for i in range(1,N):
    j=1
    ans=float('inf')
    while True:
        if j<=k and i-j>=0:
            ans=min(abs(A[i]-A[i-j])+dp[i-j],ans)
            j+=1
        else:
            break
    dp[i]=ans
##print(dp)
    
print(dp[-1])
    
    


Fixed submission:
import sys
N,k=map(int,input().split())
A=[int(i) for i in input().split()]
if N==1:
    print(0)
    sys.exit()
dp=[0]*N
dp[0]=0
for i in range(1,N):
    j=1
    ans=float('inf')
    while True:
        if j<=k and i-j>=0:
            ans=min(abs(A[i]-A[i-j])+dp[i-j],ans)
            j+=1
        else:
            break
    dp[i]=ans
##print(dp)
    
print(dp[-1])
Buggy python submission (verdict: Runtime Error):
n,k = [int(x) for x in input().split()]
h = [int(x) for x in input().split()]
dp = [float('inf')]*n
dp[-1] = 0
dp[-2] = abs(h[-1]-h[-2])

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


Fixed submission:
n = int(input())
h = [int(x) for x in input().split()]
dp = [0]*n
dp[n-2] = abs(h[n-1]-h[n-2])

for i in range(n-3,-1,-1):
  dp[i] = min(dp[i+1]+abs(h[i]-h[i+1]),dp[i+2]+abs(h[i]-h[i+2]))
  
print(dp[0])
Buggy python submission (verdict: Time Limit Exceeded):
n,k = [int(x) for x in input().split()]
h = [int(x) for x in input().split()]
dp = [float('inf')]*n
dp[-1] = 0
dp[-2] = abs(h[-1]-h[-2])

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


Fixed submission:
n,k = [int(x) for x in input().split()]
h = [int(x) for x in input().split()]
dp = [float('inf')]*n
dp[-1] = 0
dp[-2] = abs(h[-1]-h[-2])

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

Buggy python submission (verdict: Runtime Error):
n,k = [int(x) for x in input().split()]
h = [int(x) for x in input().split()]
dp = [float('inf')]*n
dp[-1] = 0
dp[-2] = abs(h[-1]-h[-2])

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

Fixed submission:
n,k = [int(x) for x in input().split()]
h = [int(x) for x in input().split()]
dp = [float('inf')]*n
dp[-1] = 0
dp[-2] = abs(h[-1]-h[-2])

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

Buggy python submission (verdict: Time Limit Exceeded):
from math import inf

n, k = map(int, input().split())
a = [int(i) for i in input().split()]
dp = [inf for _ in range(n)]
dp[0] = 0
for i in range(1, n):
    for j in range(1, k + 1):
        if i - j >= 0:
            dp[i] = min(dp[i], abs(a[i] - a[i - j]) + dp[i - j])

print(dp[-1])


Fixed submission:
from math import inf

n, k = map(int, input().split())
a = [int(i) for i in input().split()]
dp = [inf for _ in range(n)]
dp[0] = 0
for i in range(1, n):
    for j in range(1, k + 1):
        if i - j >= 0:
            dp[i] = min(dp[i], abs(a[i] - a[i - j]) + dp[i - j])
        else:
            break

print(dp[-1])
Buggy python submission (verdict: Time Limit Exceeded):
a = [int(x) for x in input().split()]
weight = a[1]
dp = [0] * weight + [0]
for x in range(a[0]):
    b = [int(x) for x in input().split()]
    for x in range(weight, b[0] - 1, -1):
        dp[x] = max(dp[x], dp[x - b[0]] + b[1])
print(dp[-1])


Fixed submission:
N, W = map(int, input().split())
import numpy as np
dp = np.zeros(W+1, dtype=int)
for i in range(N):
    w, v = map(int, input().split())
    np.maximum(dp[:-w] + v, dp[w:], out=dp[w:])
print(dp.max())

Buggy python submission (verdict: Runtime Error):
6 15
6 5
5 6
6 4
6 6
3 5
7 2


Fixed submission:
N, W = map(int, input().split())
import numpy as np
dp = np.zeros(W+1, dtype=int)
for i in range(N):
    w, v = map(int, input().split())
    np.maximum(dp[:-w] + v, dp[w:], out=dp[w:])
print(dp.max())

Buggy python submission (verdict: Runtime Error):
N, W = map(int, input().split())
import numpy as np
dp = np.zeros(W + 1, dtype=int)
for i in range(N):
    w, v = map(int, input().split())
    np.maximum(dp[:-w] + v, dp[w:], out=dp[w:])
print(dp.max())

Fixed submission:
N, W = map(int, input().split())
import numpy as np
dp = np.zeros(W+1, dtype=int)
for i in range(N):
    w, v = map(int, input().split())
    np.maximum(dp[:-w] + v, dp[w:], out=dp[w:])
print(dp.max())

Buggy python submission (verdict: Runtime Error):
N, W = map(int, input().split())
import numpy as np
dp = np.zeros(W, dtype=int)
for i in range(N):
    w, v = map(int, input().split())
    np.maximum(dp[:-w] + v, dp[w:], out=dp[w:])
print(dp.max())

Fixed submission:
N, W = map(int, input().split())
import numpy as np
dp = np.zeros(W+1, dtype=int)
for i in range(N):
    w, v = map(int, input().split())
    np.maximum(dp[:-w] + v, dp[w:], out=dp[w:])
print(dp.max())
Buggy python submission (verdict: Time Limit Exceeded):
from sys import stdin, stdout
n, w = list(map(int,stdin.readline().split()))
values = []
weights = []
for _ in range(n):
	v,a = list(map(int, stdin.readline().split()))
	values.append(a)
	weights.append(v)
values = [0] + values
weights = [0] + weights

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

for i in range(n+1):
	for j in range(w+1):
		if i == 0 or j == 0:
			dp[i][j] = 0
		else:
			if weights[i] <= j:
				dp[i][j] = max(dp[i-1][j],
			   	dp[i-1][j-weights[i]] + values[i])
			else:
				dp[i][j] = dp[i-1][j]

print(str(dp[n][w]))


Fixed submission:
from sys import stdin, stdout
import numba as nb 

@nb.njit()
def solve(n,w,weights, values):
	dp = [[0 for _ in range(w+1)] for k in range(n+1)]
	for i in range(1,n+1):
		for j in range(1,w+1):
			if weights[i] <= j:
				dp[i][j] = max(dp[i-1][j],
			   	dp[i-1][j-weights[i]] + values[i])
			else:
				dp[i][j] = dp[i-1][j]
	return dp[n][w]

def main():
	n, w = map(int,stdin.readline().split())
	values = []
	weights = []

	for _ in range(n):
		v,a = map(int, stdin.readline().split())
		values.append(a)
		weights.append(v)

	values = [0] + values
	weights = [0] + weights
	print(solve(n,w,weights,values))

if __name__ == "__main__":
	main()

Buggy python submission (verdict: Time Limit Exceeded):
n, w = list(map(int,input().split()))
values = []
weights = []
for _ in range(n):
	v,a = list(map(int,input().split()))
	values.append(a)
	weights.append(v)
values = [0] + values
weights = [0] + weights

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

for i in range(n+1):
	for j in range(w+1):
		if i == 0 or j == 0:
			dp[i][j] = 0
		else:
			if weights[i] <= j:
				dp[i][j] = max(dp[i-1][j],
			   	dp[i-1][j-weights[i]] + values[i])
			else:
				dp[i][j] = dp[i-1][j]

print(dp[n][w])


Fixed submission:
from sys import stdin, stdout
import numba as nb 

@nb.njit()
def solve(n,w,weights, values):
	dp = [[0 for _ in range(w+1)] for k in range(n+1)]
	for i in range(1,n+1):
		for j in range(1,w+1):
			if weights[i] <= j:
				dp[i][j] = max(dp[i-1][j],
			   	dp[i-1][j-weights[i]] + values[i])
			else:
				dp[i][j] = dp[i-1][j]
	return dp[n][w]

def main():
	n, w = map(int,stdin.readline().split())
	values = []
	weights = []

	for _ in range(n):
		v,a = map(int, stdin.readline().split())
		values.append(a)
		weights.append(v)

	values = [0] + values
	weights = [0] + weights
	print(solve(n,w,weights,values))

if __name__ == "__main__":
	main()
Buggy python submission (verdict: Time Limit Exceeded):
from sys import stdin, stdout
import numba as nb 

@nb.njit()
def solve(n,w,weights, values):
	dp = [[0 for _ in range(w+1)] for k in range(n+1)]
	for i in range(1,n+1):
		for j in range(1,w+1):
			if weights[i] <= j:
				dp[i][j] = max(dp[i-1][j],
			   	dp[i-1][j-weights[i]] + values[i])
			else:
				dp[i][j] = dp[i-1][j]
	return dp[n][w]

def main():
	n, w = map(int, stdin.readline().split())
	values = []
	weights = []

	for _ in range(n):
		v,a = map(int, stdin.readline().split())
		values.append(a)
		weights.append(v)

	values = [0] + values
	weights = [0] + weights
	print(solve(n,w,weights,values))

if __name__ == "__main__":
	main()

Fixed submission:
import sys
 
import numba as nb
import numpy as np
 
input = sys.stdin.readline
 
 
@nb.njit("i8(i8,i8,i8[:],i8[:])")
def solve(N, W, w, v):
    dp = np.full(shape=(N + 1, np.sum(v) + 1), fill_value=(N * W), dtype=np.int64)
    dp[:, 0] = 0
    for i in range(N):
        np.minimum(w[i], dp[i][:v[i]], dp[i + 1][:v[i]])
        np.minimum(w[i] + dp[i][: - v[i]], dp[i][v[i]:], dp[i + 1][v[i]:])
    return np.where(dp[-1] <= W)[0][-1]
 
 
def main():
    N, W = map(int, input().split())
 
    w = np.empty(shape=N, dtype=np.int64)
    v = np.empty(shape=N, dtype=np.int64)
    for i in range(N):
        w[i], v[i] = map(int, input().split())
 
    ans = solve(N, W, w, v)
    print(ans)
 
 
if __name__ == "__main__":
    main()
Buggy python submission (verdict: Time Limit Exceeded):
from sys import stdin, stdout, setrecursionlimit
setrecursionlimit = 1000000

input  = stdin.readline

n,m = list(map(int,input().split()))
par = [[] for _ in range(n+1)]
dis = [0]*(n+1)
vis = dis[:]

def dfs(n):
	sta = []
	sta.append(n)
	while(sta):
		n = sta.pop(-1)
		for i in par[n]:
			dis[i] = max(dis[i], dis[n]+1)
			sta.append(i)

for _ in range(m):
	x,y = map(int,input().split())
	par[x].append(y)

for i in range(1,n+1):
	if not vis[i]:
		dfs(i)

print(max(dis))


Fixed submission:
import collections
import sys
from functools import lru_cache
sys.setrecursionlimit(int(10**9))
n, m  = [int(i) for i in input().strip().split(' ')] 
edges = collections.defaultdict(list)
for i in range(m):
    s,d = [int(i) for i in input().strip().split(' ')]
    edges[s-1].append(d-1) 
# dp = [-1]*n
maxPath = 0 
@lru_cache(None)
def dfs(node): 
    ans = 0 
    for i in edges[node]:
        ans = max(ans,dfs(i)+1)
    return ans
 
for i in range(n):
    maxPath = max(dfs(i), maxPath) 
print(maxPath)

Buggy python submission (verdict: Runtime Error):
from sys import stdin, stdout, setrecursionlimit
setrecursionlimit = 1000000

input  = stdin.readline

n,m = list(map(int,input().split()))
par = [[] for _ in range(n+1)]
dis = [0]*(n+1)
vis = dis[:]

def dfs(n):
	for i in par[n]:
		dis[i] = max(dis[i], dis[n]+1)
		dfs(i)

for _ in range(m):
	x,y = map(int,input().split())
	par[x].append(y)

for i in range(1,n+1):
	if not vis[i]:
		dfs(i)

print(max(dis))


Fixed submission:
import collections
import sys
from functools import lru_cache
sys.setrecursionlimit(int(10**9))
n, m  = [int(i) for i in input().strip().split(' ')] 
edges = collections.defaultdict(list)
for i in range(m):
    s,d = [int(i) for i in input().strip().split(' ')]
    edges[s-1].append(d-1) 
# dp = [-1]*n
maxPath = 0 
@lru_cache(None)
def dfs(node): 
    ans = 0 
    for i in edges[node]:
        ans = max(ans,dfs(i)+1)
    return ans
 
for i in range(n):
    maxPath = max(dfs(i), maxPath) 
print(maxPath)
Buggy python submission (verdict: Time Limit Exceeded):
x,size=map(int,input().split())
weight=[]
value=[]
for i in range(x):
    a,b=map(int,input().split())
    weight.append(a)
    value.append(b)
dp=[[0 for i in range(size+1)] for j in range(len(weight))]
for i in range(len(weight)):
    dp[i][0]=0
for i in range(len(weight)):
    for j in range(1,size+1):
        if weight[i]>j:
            dp[i][j]=dp[i-1][j]
        else:
            dp[i][j]=max(dp[i-1][j],dp[i-1][j-weight[i]]+value[i])
print(dp[len(value)-1][size])
        
    

Fixed submission:
x,size=map(int,input().split())
weight=[]
value=[]
weight.append(0)
value.append(0)
for i in range(x):
    a,b=map(int,input().split())
    weight.append(a)
    value.append(b)
max_value=sum(value)
dp=[[float('inf') for i in range(max_value+1)] for j in range(x+1)]
for i in range(x+1):
    dp[i][0]=0
for i in range(1,x+1):
    w=weight[i]
    v=value[i]
    for knap_v in range(1,max_value+1):
        if v<=knap_v:
            dp[i][knap_v]=min(dp[i-1][knap_v],w+dp[i-1][knap_v-v])
        else:
            dp[i][knap_v]=dp[i-1][knap_v]
ans=0
# print(dp)
for i in range(max_value+1):
    if dp[x][i]<=size:
        ans=i
print(ans)
Buggy python submission (verdict: Runtime Error):
n=int(input())
arr=list(map(int,input().split()))
one=two=three=0
for i in arr:
    if i==1:
        one+=1
    elif i==2:
        two+=1
    elif i==3:
        three+=1
max_one=one+two+three
max_two=two+three
max_three=three
dp=[[[0.0]*(n+1) for i in range(n)] for j in range(n+1)]
for k in range(max_three+1):
    for j in range(max_two+1-k):
        for i in range(max_one+1-j-k):
            if i+j+k==0:
                continue
            else:
                dp[i][j][k]=n/(i+j+k)
            if i>0:
                dp[i][j][k] += (dp[i-1][j][k]*i)/(i+j+k)
            if j>0:
                dp[i][j][k] += (dp[i+1][j-1][k]*j)/(i+j+k)
            if k>0:
                dp[i][j][k] += (dp[i][j+1][k-1]*k)/(i+j+k)
print(dp[i][j][k])
    
    

Fixed submission:
n=int(input())
arr=list(map(int,input().split()))
one=two=three=0
for i in arr:
    if i==1:
        one+=1
    elif i==2:
        two+=1
    elif i==3:
        three+=1
max_one=one+two+three
max_two=two+three
max_three=three
dp=[[[0.0]*(n+1) for i in range(n+1)] for j in range(n+1)]
for k in range(max_three+1):
    for j in range(max_two+1-k):
        for i in range(max_one+1-j-k):
            if i+j+k==0:
                continue
            else:
                dp[i][j][k]=n/(i+j+k)
            if i>0:
                dp[i][j][k] += (dp[i-1][j][k]*i)/(i+j+k)
            if j>0:
                dp[i][j][k] += (dp[i+1][j-1][k]*j)/(i+j+k)
            if k>0:
                dp[i][j][k] += (dp[i][j+1][k-1]*k)/(i+j+k)
print(dp[i][j][k])
Buggy python submission (verdict: Runtime Error):
def fun(a,k,n): ## k different steps can be taken
    if n==1:
        return 0
    dp = [0]*n
    dp[1]=dp[0]+abs(a[0]-a[1])
    for i in range(2,len(a)):
        t = 0
        min_ = float('inf')
        for j in range(i-1,-1,-1):
            if t==k:
                break
            else:
                t+=1
            if dp[j]+abs(a[i]-a[j]) < min_ :
                   min_ = dp[j]+abs(a[i]-a[j])
        dp[i]=min_
    return dp[-1]
from sys import stdin , stdout
n,k = map(int , stdin.readline().split())
a = list(map(int , stdin.readline().split()))
print(fun(a,k,n))

Fixed submission:
def fun(a):
    if len(a)==1:
        return 0
    dp = [0]*len(a)
    dp[0]=a[0]
    dp[1]=dp[0]+abs(a[0]-a[1])
    for i in range(2,len(a)):
        dp[i]=min(dp[i-1]+abs(a[i]-a[i-1]) ,dp[i-2]+abs(a[i]-a[i-2]))
    return dp[-1]-a[0]
  
n = int(input())
a = list(map(int , input().split()))
print(fun(a))
Buggy python submission (verdict: Runtime Error):
    n=int(input())
    h=list(map(int,input().split()))
    dp=[0]*(len(h))
    dp[1]+=abs(h[1]-h[0])
    for i in range(2,len(h)):
        dp[i] = min( 
                abs(h[i]-h[i-1])+dp[i-1],
                abs(h[i]-h[i-2])+dp[i-2]
                )
    print(dp[-1])


Fixed submission:
n=int(input())
h=list(map(int,input().split()))
dp=[0]*(len(h))
dp[1]+=abs(h[1]-h[0])
for i in range(2,len(h)):
    dp[i] = min( 
            abs(h[i]-h[i-1])+dp[i-1],
            abs(h[i]-h[i-2])+dp[i-2]
            )
print(dp[-1])

Buggy python submission (verdict: Runtime Error):
r,c=map(int,input().split())
mod=10**9+7
g=[]
for _ in range(r):
  g.append(input())
dp=[[0 for j in range(c)] for i in range(r)]
dp[0][0]=1
for i in range(r):
  for j in range(c):
    if g[i][j]=='.':
        if i>0:
            dp[i][j]+=dp[i-1][j]%mod
        if j>0:
            dp[i][j]+=dp[i][j-1]%mod


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


Fixed submission:
n=int(input())
h=list(map(int,input().split()))
res=[-1]*n
res[0]=0
res[1]=abs(h[0]-h[1])
for i in range(2,n):
  res[i]=min(abs(h[i-1]-h[i])+res[i-1],abs(h[i-2]-h[i])+res[i-2])

print(res[-1])
Buggy python submission (verdict: Time Limit Exceeded):
n,k=map(int,input().split())
h=list(map(int,input().split()))
res=[999999999]*n
res[0]=0
for i in range(1,n):
    mini=999999999
    for j in range(1,k+1):
        if i-j>=0:
            mini=min(abs(h[i-j]-h[i])+res[i-j],mini)
    res[i]=mini

print(res[-1])


Fixed submission:
import sys
n,k=map(int,input().split())
a=list(map(int,input().split()))
dp=[sys.maxsize]*n
dp[0]=0
for i in range(n):
    for j in range(i+1,i+k+1):
        if j<n:
            dp[j]=min(dp[j],dp[i]+abs(a[i]-a[j]))
print(dp[n-1])

Buggy python submission (verdict: Runtime Error):
n,k=map(int,input().split())
h=list(map(int,input().split()))
res=[-1]*n
res[0]=0
for i in range(1,k):
    
    res[i]=abs(h[i-1]-h[i])
for i in range(k,n):
    mini=999999999
    for j in range(1,k+1):
        mini=min(abs(h[i-j]-h[i])+res[i-j],mini)
    res[i]=mini

print(res[-1])


Fixed submission:
import sys
n,k=map(int,input().split())
a=list(map(int,input().split()))
dp=[sys.maxsize]*n
dp[0]=0
for i in range(n):
    for j in range(i+1,i+k+1):
        if j<n:
            dp[j]=min(dp[j],dp[i]+abs(a[i]-a[j]))
print(dp[n-1])

Buggy python submission (verdict: Time Limit Exceeded):
import sys
n,k=map(int,input().split())
a=list(map(int,input().split()))
dp=[sys.maxsize]*n
dp[0]=0
for i in range(n):
    for j in range(i+1,i+k+1):
        if j<n:
            dp[j]=min(dp[j],dp[i]+abs(a[i]-a[j]))
print(dp[n-1])


Fixed submission:
import sys
n,k=map(int,input().split())
a=list(map(int,input().split()))
dp=[sys.maxsize]*n
dp[0]=0
for i in range(n):
    for j in range(i+1,i+k+1):
        if j<n:
            dp[j]=min(dp[j],dp[i]+abs(a[i]-a[j]))
print(dp[n-1])
Buggy python submission (verdict: Runtime Error):
n=int(input())
a=[]
for _ in range(n):
    a.append(list(map(int,input().split())))
dp=[0]*n
for i in range(3):
  dp[i]=a[0][i]
for k 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]+a[k][i])
    dp=m
print(max(m))


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

Buggy python submission (verdict: Runtime Error):
n=int(input())
a=[]
for _ in range(n):
    a.append(list(map(int,input().split()))) 
dp=[0]*n
for i in range(3):
  dp[i]=a[0][i]
for k in range(1,n):
    m=[0,0,0]
    for i in range(3):
        for j in range(3):
            if i!=j:
                m[i]=max(m[i],dp[j]+a[k][i])
    dp=m
print(max(m))


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

Buggy python submission (verdict: Runtime Error):
n=int(input())
a=[]
for _ in range(n):
    a.append(list(map(int,input().split())))
dp=a[0]

for k in range(1,n):
    m=[0,0,0]
    for i in range(3):
        for j in range(3):
            if i!=j:
                m[i]=max(m[i],dp[j]+a[k][i])
    dp=m
print(max(m))


Fixed submission:
n=int(input())
a=[]
for _ in range(n):
    a.append(list(map(int,input().split())))
for i in range(1,n):
    a[i][0]+=max(a[i-1][1],a[i-1][2])
    a[i][1]+=max(a[i-1][0],a[i-1][2])
    a[i][2]+=max(a[i-1][1],a[i-1][0])
print(max(a[n-1]))
Buggy python submission (verdict: Runtime Error):
a=input()
b=input()
dp=[[0 for i in range(len(a+1))] for j in range(len(b+1))]
for i in range(1,en(a+1)):
  for j in range(1,len(b+1)):
    if a[j-1]==b[i-1]:
      dp[i][j]=dp[i-1][j-1]
    else:
      dp[i][j]=max(dp[i-1][j],dp[i][j-1])+1
print(dp[-1][-1])
        
      


Fixed submission:
a=input()
b=input()
dp=[[0 for i in range(len(a)+1)] for j in range(len(b)+1)]
for i in range(1,len(b)+1):
  for j in range(1,len(a)+1):
    if a[j-1]==b[i-1]:
      dp[i][j]=dp[i-1][j-1]+1
    else:
      dp[i][j]=max(dp[i-1][j],dp[i][j-1])

res=''

j=len(a)
i=len(b)
while j>0 and i>0:
 
    if dp[i][j]==dp[i-1][j]:
        i-=1
  
    elif dp[i][j]==dp[i][j-1]:
        j-=1
    elif dp[i][j]==dp[i-1][j-1]+1:

        res+=a[j-1]
        i-=1
        j-=1
    
print(res[::-1])
Buggy python submission (verdict: Runtime Error):
return True

Fixed submission:
N = int(input())
jumps = [int(n) for n in input().split()]

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

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

print(dp[-1])
Buggy python submission (verdict: Runtime Error):
h,w=map(int,input().split())
graph=[]
for i in range(h):
  graph.append(list(input()))
#print(graph)
dp=[[0]*(w) for _ in range(h)]
dp[0][0]=1
for i in range(1,w):
  dp[0][i]=dp[0][i-1] if graph[0][i]=='.' else 0
for i in range(1,h):
  dp[i][0]=dp[i-1][0] if graph[0][i]=='.' else 0
for i in range(1,h):
  for j in range(1,w):
    #print(i-1,j-1)
    if(graph[i-1][j-1]=='#'):
      dp[i][j]=0
    else:
      dp[i][j]=(dp[i-1][j]+dp[i][j-1])%(1e9 + 7)

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

Fixed submission:
MOD = 1000000007
h,w=map(int,input().split())
graph=[]
for i in range(h):
  graph.append(list(input()))
#print(graph)
dp=[[0]*(w) for _ in range(h)]
dp[0][0]=1
for i in range(1,w):
  if graph[0][i]=='#':
    break
  dp[0][i]=1
for i in range(1,h):
  if graph[i][0]=='#':
    break
  dp[i][0]=1
for i in range(1,h):
  for j in range(1,w):
    #print(i-1,j-1)
    if(graph[i][j]=='#'):
      dp[i][j]=0
    else:
      dp[i][j]=(dp[i-1][j]+dp[i][j-1])%MOD

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