Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
MOD = 1e9 + 7

n = int(input())
can = []
for _ in range(n):
    can.append([int(c) for c in input().split()])

dp = [0] * (2 ** n)
dp[0] = 1

for mask in range(2 ** n - 1):
    a = bin(mask).count('1')
    for b in range(n):
        if can[a][b] and not(mask & (1 << b)):
            m2 = mask ^ (1 << b)
            dp[m2] = dp[m2] + dp[mask]
            if dp[m2] > MOD:
                dp[m2] -= MOD


print(dp[(2**n) - 1])


Fixed submission:
MOD = int(1e9 + 7)

n = int(input())
can = []
for _ in range(n):
    can.append([int(c) for c in input().split()])

dp = [0] * (2 ** n)
dp[0] = 1

for mask in range(2 ** n - 1):
    a = bin(mask).count('1')
    for b in range(n):
        if can[a][b] and not(mask & (1 << b)):
            m2 = mask ^ (1 << b)
            dp[m2] = dp[m2] + dp[mask]
            if dp[m2] > MOD:
                dp[m2] -= MOD


print(dp[(2**n) - 1])
Buggy python submission (verdict: Runtime Error):
from collections import deque

line1 = input()
n, k = [int(num) for num in line1.split(" ")]
line2 = input()
h = [int(num) for num in line2.split(" ")]

d = deque([0], k)

for i in range(1, len(h)):
    min_cost = float("inf")
    for j,cost in enumerate(d):
        steps_taken = len(d)-j
        if i-steps_taken < 0: break
        step_cost = abs(h[i]-h[i-steps_taken])
        min_cost = min(min_cost, cost + abs(h[i]-h[i-steps_taken]))
        if step_cost == 0: break
    d.append(min_cost)

print(d[-1])

Fixed submission:
line1 = input()
line2 = input()
h = [int(num) for num in line2.split(" ")]

c1 = 0
c2 = abs(h[1] - h[0])

for i in range(2, len(h)):
    c1, c2 = c2, min(abs(h[i] - h[i-1]) + c2,
                    abs(h[i] - h[i-2]) + c1)

print(c2)
Buggy python submission (verdict: Time Limit Exceeded):
n, k = map(int, input().split())
arr = list(map(int, input().split()))
dp = [float("inf")] * len(arr)
dp[0] = 0
for j in range(1, len(arr)):
    for i in range(1, k + 1):
        if j >= i:
            dp[j] = min(dp[j], dp[j - i] + abs(arr[j] - arr[j - i]))
        else:
            break
print(dp[-1])


Fixed submission:
n, k = map(int, input().split())
arr = list(map(int, input().split()))
dp = [float("inf")] * len(arr)
dp[0] = 0
for j in range(1, len(arr)):
    for i in range(1, k + 1):
        if j >= i:
            dp[j] = min(dp[j], dp[j - i] + abs(arr[j] - arr[j - i]))
        else:
            break
print(dp[-1])
Buggy python submission (verdict: Runtime Error):
def dfs(cur, visited, dis):
    visited[cur] = 1
    if cur in adj_list:
        for item in adj_list[cur]:
            if not visited[item]:
                dfs(item, visited, dis)
            dis[cur] = max(dis[cur], 1+dis[item])


v, e = map(int, input().split())
adj_list = {}
for _ in range(e):
    x, y = map(int, input().split())
    adj_list.setdefault(x, []).append(y)
visited = [0] * (v + 1)
dis = [0] * (v + 1)
for i in range(v + 1):
    if not visited[i]:
        dfs(i, visited, dis)
print(max(dis))


Fixed submission:
import sys
sys.setrecursionlimit(10**5)

v, e = map(int, input().split())
adj_list = {}
for _ in range(e):
    x, y = map(int, input().split())
    adj_list.setdefault(x, []).append(y)
visited = [0] * (v + 1)
dis = [0] * (v + 1)


def dfs(cur):
    global visited
    global dis
    visited[cur] = 1
    if cur in adj_list:
        for item in adj_list[cur]:
            if not visited[item]:
                dfs(item)
            dis[cur] = max(dis[cur], 1+dis[item])


for i in range(v + 1):
    if not visited[i]:
        dfs(i)
print(max(dis))

Buggy python submission (verdict: Runtime Error):
def dfs(cur, visited, dis):
    visited[cur] = 1
    if cur in adj_list:
        for item in adj_list[cur]:
            if not visited[item]:
                dfs(item, visited, dis)
            dis[cur] = max(dis[cur], 1+dis[item])


v, e = map(int, input().split())
adj_list = {}
for _ in range(e):
    x, y = map(int, input().split())
    adj_list.setdefault(x, []).append(y)
visited = [0] * (v + 1)
dis = [0] * (v + 1)
for i in range(v + 1):
    if not visited[i]:
        dfs(i, visited, dis)
print(max(dis))


Fixed submission:
import sys
sys.setrecursionlimit(10**5)

v, e = map(int, input().split())
adj_list = {}
for _ in range(e):
    x, y = map(int, input().split())
    adj_list.setdefault(x, []).append(y)
visited = [0] * (v + 1)
dis = [0] * (v + 1)


def dfs(cur):
    global visited
    global dis
    visited[cur] = 1
    if cur in adj_list:
        for item in adj_list[cur]:
            if not visited[item]:
                dfs(item)
            dis[cur] = max(dis[cur], 1+dis[item])


for i in range(v + 1):
    if not visited[i]:
        dfs(i)
print(max(dis))
Buggy python submission (verdict: Runtime Error):
n,k= (map(int,input().split()))
a = input().split()
cost = [0]*n
c1 = 0
c2 =0
for i in range(n):
    a[i] = int(a[i])
    if(i==0):
        cost[i] =0
    elif(k>i):
        
        mini = 10**5
        change = 0
        for j in range(i):
            change = abs(a[i] - a[j]) + cost[j]
            # print(change)
            if(mini > change):
                mini = change

        cost[i] = mini
    else:
       
        mini = 10**5
        change = 0
        for j in range(1,k+1):
            change = abs(a[i] - a[i-j]) + cost[i-j]
            if(mini > change):
                mini = change
            # print(change)
        cost[i] = mini


# print(a)
# print(cost)
print(cost[n-1])

Fixed submission:
n= int(input())
a = input().split()
cost = [0]*n
c1 = 0
c2 =0
for i in range(n):
    a[i] = int(a[i])
i = 0
for i in range(1,n):
    if(i==1):
        cost[i] = abs(a[i] - a[i-1])
    else:
        c1 = abs(a[i] - a[i-1]) + cost[i-1]
        c2 = abs(a[i] - a[i-2]) + cost[i-2]
        cost[i] = min(c1,c2)

print(cost[n-1])

Buggy python submission (verdict: Runtime Error):
n,k= map(int,input().split())
a = input().split()
cost = [0]*n
c1 = 0
c2 =0
for i in range(n):
    a[i] = int(a[i])
    if(i==0):
        cost[i] =0
    elif(k>i):
        
        mini = 10**5
        change = 0
        for j in range(i):
            change = abs(a[i] - a[j]) + cost[j]
            # print(change)
            if(mini > change):
                mini = change

        cost[i] = mini
    else:
       
        mini = 10**5
        change = 0
        for j in range(1,k+1):
            change = abs(a[i] - a[i-j]) + cost[i-j]
            if(mini > change):
                mini = change
            # print(change)
        cost[i] = mini


# print(a)
# print(cost)
print(cost[n-1])

Fixed submission:
n= int(input())
a = input().split()
cost = [0]*n
c1 = 0
c2 =0
for i in range(n):
    a[i] = int(a[i])
i = 0
for i in range(1,n):
    if(i==1):
        cost[i] = abs(a[i] - a[i-1])
    else:
        c1 = abs(a[i] - a[i-1]) + cost[i-1]
        c2 = abs(a[i] - a[i-2]) + cost[i-2]
        cost[i] = min(c1,c2)

print(cost[n-1])

Buggy python submission (verdict: Runtime Error):
n = int(input())
a = [*map(int,input().split())]
mini = 0
change1 = 0
change2 = 0
index = n-1
while  not(index <=0 ):
    if(index == 1):
        change1 = abs(a[index] - a[index-1])
        change2 = 0
        index -=1
        mini += change1
    else:
        change1 = abs(a[index] - a[index-1])
        change2 = abs(a[index] - a[index-2])
        if(change1 > change2):
            index -=2
            mini += change2
        else:
            index -=1
            mini += change1
    
print(mini)

Fixed submission:
n= int(input())
a = input().split()
cost = [0]*n
c1 = 0
c2 =0
for i in range(n):
    a[i] = int(a[i])
i = 0
for i in range(1,n):
    if(i==1):
        cost[i] = abs(a[i] - a[i-1])
    else:
        c1 = abs(a[i] - a[i-1]) + cost[i-1]
        c2 = abs(a[i] - a[i-2]) + cost[i-2]
        cost[i] = min(c1,c2)

print(cost[n-1])
Buggy python submission (verdict: Time Limit Exceeded):
n, k = map(int, input().split())
h = list(map(int, input().split()))

dp = [1e9] * n
dp[0] = 0

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

print(dp[n - 1])

Fixed submission:
n, k = map(int, input().split())
a = list(map(int, input().split()))
dp = [0] * n

for i in range(1, n):
    dp[i] = min(dp[j] + abs(a[i] - a[j])
                for j in range(i - 1, max(i - k - 1, -1), -1))

print(dp[-1])
Buggy python submission (verdict: Runtime Error):
n = int(input())
dp = [[[0, -1]] * 3 for _ in range(n)]
abc = [list(map(int, input().split())) for _ in range(n)]
abc = [*zip(*abc)]
a = [*abc[0]]
b = [*abc[1]]
c = [*abc[2]]
dp[0] = [[a[0], 0], [b[0], 1], [c[0], 2]]

for i in range(1, n):
    for j in range(3):
        if dp[i - 1][j][1] == 0:
            for k in [1, 2]:
                t = (b[i] if k == 1 else c[i])
                if dp[i - 1][j][0] + t > dp[i][j][0]:
                    dp[i][j] = [dp[i - 1][j][0] + t, k]
        elif dp[i - 1][j][1] == 1:
            for k in [2, 0]:
                t = (c[i] if k == 2 else a[i])
                if dp[i - 1][j][0] + t > dp[i][j][0]:
                    dp[i][j] = [dp[i - 1][j][0] + t, k]
        else:
            for k in [0, 1]:
                t = (b[i] if k == 1 else a[i])
                if dp[i - 1][j][0] + t > dp[i][j][0]:
                    dp[i][j] = [dp[i - 1][j][0] + t, k]


print(max([i[0] for i in dp[-1]]))


Fixed submission:
n = int(input())
ans = [0] * 3

for i in range(n):
    t1 = list(map(int, input().split()))
    t2 = [0] * 3
    for i in range(3):
        for j in range(3):
            if i != j:
                t2[j] = max(t2[j], ans[i] + t1[j])
    ans = t2
print(max(ans))
Buggy python submission (verdict: Runtime Error):
n, m, x, y = map(int, input().split())
a = [*map(int, input().split())]
b = [*map(int, input().split())]
print('No War' if any(x < i <= y for i in \
	range(max(a) + 1, min(b) + 1)) else 'War')

Fixed submission:
n, m, x, y = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
print('No War' if any(x < i <= y for i in \
	range(max(a) + 1, min(b) + 1)) else 'War')
Buggy python submission (verdict: Runtime Error):
n, x = map(int, input().split())
a = sorted([*map(int, input().split())])
ans, i = 0, 0
while i < (n - 1):
    if x - a[i] >= 0:
        x -= a[i]
        ans += 1
    else:
        break
    i += 1
if x == a[i]:
	ans += 1
print(ans)


Fixed submission:
n, x = map(int, input().split())
a = sorted(list(map(int, input().split())))
ans, i = 0, 0
while i < (n - 1):
    if x - a[i] >= 0:
        x -= a[i]
        ans += 1
    else:
        break
    i += 1
if x == a[i]:
	ans += 1
print(ans)

Buggy python submission (verdict: Runtime Error):
n, x = map(int, input().split())
a = sorted([*map(int, input().split())])
ans = 0
for i in a:
	if i <= x:
		ans += 1
		x -= i
	else:
		break
if not x == 0 and ans > 0: ans -= 1
print(ans)

Fixed submission:
n, x = map(int, input().split())
a = sorted(list(map(int, input().split())))
ans, i = 0, 0
while i < (n - 1):
    if x - a[i] >= 0:
        x -= a[i]
        ans += 1
    else:
        break
    i += 1
if x == a[i]:
	ans += 1
print(ans)
Buggy python submission (verdict: Runtime Error):
import math

N = int(input())
heights = list(map(int, input().strip().split()))

dp = [math.inf for _ in range(N)]

dp[0] = 0
if len > 1:
    dp[1] = abs(heights[1] - heights[0])


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

print(dp[N - 1])


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

dp = [float("inf") for _ in range(N)]

dp[0] = 0
if N > 1:
    dp[1] = abs(heights[1] - heights[0])


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

print(dp[N - 1])

Buggy python submission (verdict: Runtime Error):
import math

N = int(input())
heights = list(map(int, input().strip().split()))

dp = [math.inf for _ in range(N)]

dp[0] = 0
dp[1] = abs(heights[1] - heights[0])


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

print(dp[N - 1])


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

dp = [float("inf") for _ in range(N)]

dp[0] = 0
if N > 1:
    dp[1] = abs(heights[1] - heights[0])


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

print(dp[N - 1])
Buggy python submission (verdict: Time Limit Exceeded):
n, k = [int(e) for e in input().split(' ')]
h_list = [int(e) for e in input().split(' ')]

dp_list = [0]

for i in range(1, n):
    dist_min = float("inf")
    for j in range(max(0, i - k), i):
        dist = abs(h_list[i] - h_list[j]) + dp_list[j]
        dist_min = min(dist_min, dist)
    dp_list.append(dist_min)

print(dp_list[-1])  # 出力


Fixed submission:
n, k = [int(e) for e in input().split(' ')]
h_list = [int(e) for e in input().split(' ')]

dp_list = [0]

for i in range(1, n):
    dist_min = float("inf")
    for j in range(max(0, i - k), i):
        dist = abs(h_list[i] - h_list[j]) + dp_list[j]
        dist_min = min(dist_min, dist)
    dp_list.append(dist_min)

print(dp_list[-1])  # 出力
Buggy python submission (verdict: Runtime Error):
b, c = map(int, input().split())
def caibun(b,c):
    count = 0
    for i in range(b, c+1, 1):
        a = str(i)
        if a == a[::-1]:
            count +=1
    print(count)
caibun(b,c)

Fixed submission:
ips = []
ips.append(input())
while True:
    try:
        ips.append(input())
    except (EOFError):
        break
abc = ips[0][0]+ips[1][1]+ips[2][2]
print(abc)
Buggy python submission (verdict: Runtime Error):
ips = []
ips.append(input())
while True:
    try:
        ips.append(input())
    except (EOFError):
        break
num = int(ips[0])
hina = ips[1]
v = []
for i in range(num):
    if hina[i] not in v:
        v.append(hina[i])
if len(v) == 3:
    print("three")
elif len(v) == 4:
    print("four")

Fixed submission:
a = int(input())
def more_than_three(a):
    if a < 3:
        return 0
    else:
        return a//3
print(more_than_three(a))
Buggy python submission (verdict: Runtime Error):
n = int(sin.readline())
stones = [int(i) for i in sin.readline().split()]
minCost = [float('inf') for i in range(n)]
minCost[0] = 0
minCost[1] = abs(stones[0] - stones[1])

for i in range(2, len(stones)):
    minCost[i] = min(minCost[i-1] + abs(stones[i-1] - stones[i]),
                     minCost[i-2] + abs(stones[i-2] - stones[i]))

print(minCost)
print(minCost[n-1])

Fixed submission:
import sys
import math
import functools
from collections import deque
sin = sys.stdin

n = int(sin.readline())
stones = [int(i) for i in sin.readline().split()]
minCost = [float('inf') for i in range(n)]
minCost[0] = 0
minCost[1] = abs(stones[0] - stones[1])

for i in range(2, len(stones)):
    minCost[i] = min(minCost[i-1] + abs(stones[i-1] - stones[i]),
                     minCost[i-2] + abs(stones[i-2] - stones[i]))

print(minCost[n-1])
Buggy python submission (verdict: Time Limit Exceeded):
import sys
import math
import functools
from collections import deque
sin = sys.stdin

nk = sin.readline().split()
n = int(nk[0])
k = int(nk[1])
heights = [int(i) for i in sin.readline().split()]
lowestCost = [0 for i in range(n)]

lowestCost[0] = 0
lowestCost[1] = abs(heights[1] - heights[0])

for i in range(2, n):
    m = float('inf')
    for j in range(i-k, i):
        if j >= 0:
            m = min(m, lowestCost[j] + abs(heights[j] - heights[i]))
    lowestCost[i] = m

print(lowestCost[n-1])


Fixed submission:
import sys
import math
import functools
from collections import deque
sin = sys.stdin

nk = sin.readline().split()
n = int(nk[0])
k = int(nk[1])
heights = [int(i) for i in sin.readline().split()]
lowestCost = [0 for i in range(n)]

lowestCost[0] = 0
lowestCost[1] = abs(heights[1] - heights[0])

for i in range(2, n):
    m = float('inf')
    for j in range(i-k, i):
        if j >= 0:
            m = min(m, lowestCost[j] + abs(heights[j] - heights[i]))
    lowestCost[i] = m

print(lowestCost[n-1])

Buggy python submission (verdict: Time Limit Exceeded):
import sys
import math
import functools
from collections import deque
sin = sys.stdin

nk = sin.readline().split()
n = int(nk[0])
k = int(nk[1])
heights = [int(i) for i in sin.readline().split()]

lowestCost = [0 for i in range(n)]

lowestCost[0] = 0
lowestCost[1] = abs(heights[1] - heights[0])

for i in range(2, n):
    m = float('inf')
    for j in range(i-k, i):
        if j >= 0:
            m = min(m, lowestCost[j] + abs(heights[j] - heights[i]))
    lowestCost[i] = m

print(lowestCost[n-1])


Fixed submission:
import sys
import math
import functools
from collections import deque
sin = sys.stdin

nk = sin.readline().split()
n = int(nk[0])
k = int(nk[1])
heights = [int(i) for i in sin.readline().split()]
lowestCost = [0 for i in range(n)]

lowestCost[0] = 0
lowestCost[1] = abs(heights[1] - heights[0])

for i in range(2, n):
    m = float('inf')
    for j in range(i-k, i):
        if j >= 0:
            m = min(m, lowestCost[j] + abs(heights[j] - heights[i]))
    lowestCost[i] = m

print(lowestCost[n-1])
Buggy python submission (verdict: Runtime Error):
inf = float('inf')
def main():
    n, k = map(int, raw_input().rstrip().split())
    h = list(map(int, raw_input().rstrip().split()))
    dp = [inf for i in range(n)]
    dp[0] = 0
    for i in range(n):
        for j in range(i+1, i+k+1):
            if j<n:
                cost = abs(h[i] - h[j])
                dp[j] = min(dp[j], dp[i] + cost)
    print(dp[n-1])

if __name__ == "__main__":
    main()


Fixed submission:
inf = float('inf')
def main():
    n = int(input().rstrip())
    h = list(map(int, input().rstrip().split()))
    dp = [inf for i in range(n)]
    dp[0]=0
    for i in range(n):
        for j in [i+1, i+2]:
            if j<n:
                dp[j] = min(dp[j], dp[i]+ abs(h[i] - h[j]))
    print(dp[n-1])

if __name__ == "__main__":
    main()

Buggy python submission (verdict: Runtime Error):
inf = float('inf')
def main():
    n, k = map(int, input().rstrip().split())
    h = list(map(int, input().rstrip().split()))
    dp = [inf for i in range(n)]
    dp[0] = 0
    for i in range(n):
        for j in range(i+1, i+k+1):
            if j<n:
                cost = abs(h[i] - h[j])
                dp[j] = min(dp[j], dp[i] + cost)
    print(dp[n-1])

if __name__ == "__main__":
    main()


Fixed submission:
inf = float('inf')
def main():
    n = int(input().rstrip())
    h = list(map(int, input().rstrip().split()))
    dp = [inf for i in range(n)]
    dp[0]=0
    for i in range(n):
        for j in [i+1, i+2]:
            if j<n:
                dp[j] = min(dp[j], dp[i]+ abs(h[i] - h[j]))
    print(dp[n-1])

if __name__ == "__main__":
    main()

Buggy python submission (verdict: Runtime Error):
import math
def main():
    n = int(input().rstrip())
    h = list(map(int, input().rstrip().split()))
    dp = [math.inf for i in range(n)]
    dp[0]=0
    for i in range(n):
        for j in [i+1, i+2]:
            if j<n:
                dp[j] = min(dp[j], dp[i]+ abs(h[i] - h[j]))
    print(dp[n-1])

if __name__ == "__main__":
    main()

Fixed submission:
inf = float('inf')
def main():
    n = int(input().rstrip())
    h = list(map(int, input().rstrip().split()))
    dp = [inf for i in range(n)]
    dp[0]=0
    for i in range(n):
        for j in [i+1, i+2]:
            if j<n:
                dp[j] = min(dp[j], dp[i]+ abs(h[i] - h[j]))
    print(dp[n-1])

if __name__ == "__main__":
    main()
Buggy python submission (verdict: Runtime Error):
def holiday(n):
    old_dp = [0 for i in range(3)]
    for i in range(n):
        new_dp = [0 for i in range(n)]
        c = list(map(int, input().rstrip().split()))
        for i in range(3):
            for j in range(3):
                if i!=j:
                    new_dp[j] = max(new_dp[j], old_dp[i] + c[j])

        old_dp = new_dp
    return max(old_dp[0], old_dp[1], old_dp[2])

n = int(input().rstrip())

print(holiday(n))

Fixed submission:
def main():
    n = int(input().rstrip())
    old_dp = [0 for i in range(3)]
    for i in range(n):
        new_dp = [0 for i in range(3)]
        c = list(map(int, input().rstrip().split()))
        for i in range(3):
            for j in range(3):
                if i!=j:
                    new_dp[j] = max(new_dp[j], old_dp[i] + c[j])

        old_dp = new_dp
    print(max(old_dp[0], old_dp[1], old_dp[2]))

if __name__ == "__main__":
    main()
Buggy python submission (verdict: Runtime Error):
n,k = map(int,input().split())
h = list(map(int,input().split()))

dp=[float('inf')]*n
dp[0]=0

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


Fixed submission:
n = int(input())

h = list(map(int,input().split()))


dp=[float('inf')]*n
dp[0]=0


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

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

dp=[float('inf')]*n
dp[0]=0

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


Fixed submission:
n = int(input())

h = list(map(int,input().split()))


dp=[float('inf')]*n
dp[0]=0


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

Buggy python submission (verdict: Runtime Error):
def rec(h, place):
    if h[place] != -1:
        return h[place]

    h[place] = min(rec(h,place-1) + abs(l[place-1] - l[place]) 
    ,rec(h,place-2) + abs(l[place-2] - l[place]))

    return h[place]
n = int(input())

t_l = input().split()
l = []
for i in t_l:
    l.append(int(i))

h = [-1 for i in l]

h[0] = 0
h[1] = abs(l[0] - l[1])

rec(h,len(l)-1)

print(h[len(l)-1])





Fixed submission:
n = int(input())

t_l = input().split()
l = []
for i in t_l:
    l.append(int(i))

h = [-1 for i in l]

h[0] = 0
h[1] = abs(l[0] - l[1])

i = 2
while i < len(l):
    h[i] = min(h[i-1] + abs(l[i-1] - l[i]), 
    h[i-2] + abs(l[i-2] -l[i]))
    i+=1

print(h[len(l)-1])

Buggy python submission (verdict: Runtime Error):
N = int(input())
h_arr = list(map(int, input().split(" ")))
dp = [9999999 for _ in range(N)]
dp[0] = 0

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

print(dp[-1])

Fixed submission:
N = int(input())
h_arr = list(map(int, input().split(" ")))
dp = [9999999 for _ in range(N)]
dp[0] = 0
dp[1] = abs(h_arr[1]-h_arr[0])

for i in range(2, N):
	dp[i] = min(abs(h_arr[i]-h_arr[i-1]) + dp[i-1], abs(h_arr[i]-h_arr[i-2]) + dp[i-2])
		
print(dp[-1])
Buggy python submission (verdict: Time Limit Exceeded):
N, W = map(int, input().split())

dp = [0]*(W+1)
for i in range(N):
	w, v = map(int, input().split())
	for j in range(W, w-1, -1):
		dp[j] = max(dp[j], dp[j-w] + v)
print(dp[-1])

Fixed submission:
import numpy as np
N, W = map(int, input().split())

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

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

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

for i in range(1, N+1):
	for j in range(1, W+1):
		if j >= w[i-1][0]:
			dp[i][j] = max(dp[i-1][j-w[i-1][0]] + w[i-1][1], dp[i-1][j])
		else:
			dp[i][j] = dp[i-1][j]
print(dp[-1][-1])

Fixed submission:
import numpy as np
N, W = map(int, input().split())

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