Harryxun/GPT-100-sft-dataset huggingface dataset:
Problem p03160 (python)

Fixed submission:
n=int(input())

s=input().split(' ')

s=[int(i) for i in s]

dp = [10001]*100000

dp[0] = 0

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

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

print(dp[n-1])

Buggy submission (verdict: Runtime Error):
n,k=input().split()
n=int(n)
k=int(k)
s=[int(i) for i in input().split()]
dp=[]
for i in range(n):
    dp.append(10003)
dp[0] = 0
dp[1]=abs(s[0]-s[1])
for i in range(2,n):
    for j in range(1,k+1):
        if i-j >= 0:
            dp[i] = min(dp[i],(abs(s[i]-s[i-j])+dp[i-j]))
        else:
            break
print(dp[-1])

Buggy submission (verdict: Runtime Error):
n=int(input())
s=[int(x) for x in input().split(' ')]
#print(s)
t1=[]
t2=[]
for i in range(n-1):
    #t1.append(s[i+1]-s[i])
    if s[i+1] > s[i]:
        t1.append(s[i+1]-s[i])
    else:
        t1.append(s[i]-s[i+1])
    print(t1)
for i in range(n-2):
    #t2.append(s[i+2]-s[i])
    if s[i+2] > s[i]:
        t2.append(s[i+2]-s[i])
    else:
        t2.append(s[i]-s[i+2])
    print(t2)
p=max(len(t1),len(t2))
ct1,ct2=len(t1),len(t2)
sum1=0
for i in range(p):
    if ct1 == 0 or ct2 == 0:
        break
    if t1[i] > t2[i]:
        sum1+=t2[i]
    else:
        sum1+=t1[i]
    ct1-=1
    ct2-=1
print(sum1)
Problem p03160 (python)

Fixed submission:
## tasks https://atcoder.jp/contests/dp/tasks

def solution():
    # result array for calculation for optimal cost for every stone
    res = [None]*n
    res[0] = 0
    res[1] = abs(h[1]-h[0])
    for i in range(2, n):
        res[i] = min(res[i-1] + abs(h[i]-h[i-1]), res[i-2] + abs(h[i]-h[i-2]))

    return res[-1]

if __name__ == "__main__":
    n = int(input())

    # global scope actually
    h = list(map(int, input().split(" ")))

    print(solution())

Buggy submission (verdict: Runtime Error):
## tasks https://atcoder.jp/contests/dp/tasks

def solution():
    # result array for calculation for optimal cost for every stone
    res = [None]*n
    res[0] = 0
    res[1] = abs(h[1]-h[0])
    for i in range(2, n):
        res[i] = min(res[i-1] + abs(h[i]-h[i-1]), res[i-2] + abs(h[i]-h[i-2]))

    return res[-1]

if __name__ == "__main__":
    n = int(raw_input())

    # global scope actually
    h = list(map(int, raw_input().split(" ")))
    #print("h = {}".format(h))

    print(solution())

Buggy submission (verdict: Runtime Error):
def solution(k):
    #print("solution({}) = ?".format(k))
    if k == 0:
        return 0

    result = None
    if res[k]:
        result = res[k]
    elif k >= 2:
            result = min(solution(k-1) + abs(h[k]-h[k-1]), solution(k-2) + abs(h[k]-h[k-2]))
    else:
        # the case for k == 1 actually, only one of such
        result = solution(k-1) + abs(h[k]-h[k-1])
    res[k] = result

    #print("solution({}) = {}".format(k, result))
    return result

if __name__ == "__main__":
    n = int(raw_input())

    # global scope actually
    h = list(map(int, raw_input().split(" ")))
    #print("h = {}".format(h))

    # result array for calculation for optimal cost for every stone
    res = [None]*n

    solution(n-1)

    #last element
    print(res[-1])
Problem p03162 (python)

Fixed submission:
## tasks https://atcoder.jp/contests/dp/tasks
## TODO

def solution():
    # result array for calculation for optimal cost for every stone
    res = [[-1 for x in range(3)] for y in range(n)]
    res[0] = a[0]
    for i in range(1,n):
        # going through the all days
        for j in range(3):
            # calucaltion for every possible actions, but skipping the same activity
            # picked current activity is j, let us get options from non j and get max of them
            # it will be a cost for j
            # do it for every

            #searching for best previous happines
            bph = -1
            for o in range(3):
                #skipping the same activity
                if o==j:
                    continue
                bph = max(bph, res[i-1][o])
            #print("res = {} a = {}".format(res, a))
            #print("i={} j={}".format(i, j))
            res[i][j] = max(res[i][j], bph + a[i][j])

    return max(res[-1][0],res[-1][1],res[-1][2])


if __name__ == "__main__":
    n = int(input())

    a = [[None for x in range(3)] for y in range(n)]

    for i in range(n):
        row = list(map(int, input().split(" ")))
        for j in range(3):
            a[i][j] = row[j]

    #print("n = {} a = {}".format(n, a))
    if n == 1:
        print(max(a[0][0],a[0][1],a[0][2]))
    else:
        print(solution())

Buggy submission (verdict: Runtime Error):
## tasks https://atcoder.jp/contests/dp/tasks
## TODO

def solution():
    # result array for calculation for optimal cost for every stone
    res = [[-1 for x in range(3)] for y in range(n)]
    res[0] = a[0]
    for i in range(1,n):
        # going through the all days
        for j in range(3):
            # calucaltion for every possible actions, but skipping the same activity
            # picked current activity is j, let us get options from non j and get max of them
            # it will be a cost for j
            # do it for every

            #searching for best previous happines
            bph = -1
            for o in range(3):
                #skipping the same activity
                if o==j:
                    continue
                bph = max(bph, res[i-1][o])
            #print("res = {} a = {}".format(res, a))
            #print("i={} j={}".format(i, j))
            res[i][j] = max(res[i][j], bph + a[i][j])

    return max(res[-1][0],res[-1][1],res[-1][2])


if __name__ == "__main__":
    n = int(input())

    a = [[None for x in range(3)] for y in range(n)]

    for i in range(n):
        row = list(map(int, raw_input().split(" ")))
        for j in range(3):
            a[i][j] = row[j]

    #print("n = {} a = {}".format(n, a))
    if n == 1:
        print max(a[0][0],a[0][1],a[0][2])
    else:
        print(solution())
Problem p03160 (python)

Fixed submission:
import sys


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

  return res[n]


def main(N, H):
  res = [0] * N

  print jump(N-1, H, res)


if __name__ == '__main__':
  H, N = None, None
  for i, line_ in enumerate(sys.stdin):
    line = line_.strip()
    if line:
        if not i:
            N = int(line.strip())
        H_ = line.strip().split()
        H = [int(num) for num in H_]
  if N is not None and H is not None:
    main(N, H)

Buggy submission (verdict: Runtime Error):
import sys


def jump(k, h, res):
  if not k:
    return 0

  if res[k] == -1:
    res[k] = jump(k-1, h, res) + abs(h[k] - h[k-1])
    if k >= 2:
      res[k] = min(res[k], jump(k-2, h, res) + abs(h[k] - h[k-2]))

  return res[k]


def main(N, H):
  if len(H) != N:
      print 0
      return
  res = [-1] * N

  print jump(N-1, H, res)


if __name__ == '__main__':
  H, N = None, None
  for i, line_ in enumerate(sys.stdin):
    line = line_.strip()
    if line:
        if not i:
            N = int(line.strip())
        H_ = line.strip().split()
        H = [int(num) for num in H_]
  if N is not None and H is not None:
    main(N, H)

Buggy submission (verdict: Runtime Error):
import sys


def jump(k, h, res):
  if not k:
    return 0

  if res[k] == -1:
    res[k] = jump(k-1, h, res) + abs(h[k] - h[k-1])
    if k >= 2:
      res[k] = min(res[k], jump(k-2, h, res) + abs(h[k] - h[k-2]))

  return res[k]


def main(N, H):
  res = [-1] * N

  print jump(N-1, H, res)


if __name__ == '__main__':
  H, N = None, None
  for i, line_ in enumerate(sys.stdin):
    line = line_.strip()
    if line:
        if not i:
            N = int(line.strip())
        H_ = line.strip().split()
        H = [int(num) for num in H_]
  if N and H:
    main(N, H)

Buggy submission (verdict: Runtime Error):
import sys


def jump(k, h, res):
  if not k:
    return 0

  if res[k] == -1:
    res[k] = jump(k-1, h, res) + abs(h[k] - h[k-1])
    if k >= 2:
      res[k] = min(res[k], jump(k-2, h, res) + abs(h[k] - h[k-2]))

  return res[k]


def main(N, H):
  res = [-1] * N

  print jump(N-1, H, res)


if __name__ == '__main__':
  for i, line_ in enumerate(sys.stdin):
    line = line_.strip()
    if line:
        if not i:
            N = int(line.strip())
        H_ = line.strip().split()
        H = [int(num) for num in H_]

  main(N, H)
Problem p03160 (python)

Fixed submission:
def helper(h, n):
    res = [0]*n
    res[0] = 0
    res[1] = abs(h[1]-h[0])
    for i in range(2, n):
        res[i] = min(res[i-1]+abs(h[i]-h[i-1]), res[i-2]+abs(h[i]-h[i-2]))
    return res[-1]

def main():
    n = int(input())
    h = list(map(int, input().split(" ")))
    print(helper(h, n))

if __name__ == "__main__":
    main()

Buggy submission (verdict: Runtime Error):
def helper(k, h, res):
    if k == 0:
        return 0
    if res[k] == -1:
        res[k] = helper(k-1, h, res)+abs(h[k]-h[k-1])
        if k >= 2:
            res[k] = min(helper(k, h, res), res[k-2]+abs(h[k]-h[k-2]))
    return res[k]

def main():
    n = int(input())
    h= list(map(int, input().split(" ")))
    res = [-1]*n
    print(helper(n-1, h, res))

if __name__ == "__main__":
    main()
Problem p03161 (python)

Fixed submission:
def calc_cost2(h, k):
    n = len(h)
    if (n == 0):
        return 0

    cost = n * [None]
    cost[0] = 0
    for i in range(1, len(h)):
        cost[i] = min([cost[s] + abs(h[i] - h[s]) for s in range(max(0, i-k), i)])
        #cost[i] = min(map(lambda s: cost[s] + abs(h[i] - h[s]), range(max(0, i-k), i)))

    return cost[n-1]


if __name__ == "__main__":
    n, k = list(map(int, input().split(" ")))
    h = list(map(int, input().split(" ")))
    res = calc_cost2(h, k)
    print(res)

Buggy submission (verdict: Runtime Error):
def calc_cost2(h, k):
    n = len(h)
    if (n == 0):
        return 0

    cost = n * [None]
    for i in range(1, len(h)):        
        tmp = cost[i-1] + abs(h[i] - h[i-1])
        for s in range(max(0, i-k), i):
            tmp = min(tmp, cost[s] + abs(h[i] - h[s]))

        cost[i] = tmp

    return cost[n-1]

if __name__ == "__main__":
    n, k = list(map(int, input().split(" ")))
    h = list(map(int, input().split(" ")))
    res = calc_cost2(h, k)
    print(res)

Buggy submission (verdict: Runtime Error):
def calc_cost2(h, k):
    n = len(h)
    if (n == 0):
        return 0

    cost = list()
    cost.append(0)
    for i in range(1, len(h)):        
        tmp = cost[i-1] + abs(h[i] - h[i-1])
        for s in range(max(0, i-k), i):
            tmp = min(tmp, cost[s] + abs(h[i] - h[s]))

        cost.append(tmp)

    return cost[n-1]

if __name__ == "__main__":
    n, k = list(map(int, input().split(" ")))
    h = list(map(int, input().split(" ")))
    res = calc_cost2_FAST(h, k)
    print(res)
Problem p03160 (python)

Fixed submission:
n = int(input())
arr = [int(x) for x in input().split()]
dp = [float('inf') for x in arr]
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(arr[i] - arr[j]))
print(dp[-1])

Buggy submission (verdict: Runtime Error):
n, k = [int(x) for x in input().split()]
arr = [int(x) for x in input().split()]
dp = [float('inf') for x in arr]
dp[0] = 0
for i in range(1, n):
  dp[i] = min(dp[j] + abs(arr[i] - arr[j]) for j in range(max(i-k, 0), i))
print(dp[-1])

Buggy submission (verdict: Runtime Error):
n, k = map(int, input().split())
arr = [int(x) for x in input().split()]
dp = [float('inf') for x in arr]
dp[0] = 0
for i in range(1, n):
    dp[i] = min(dp[j] + abs(arr[i] - arr[j]) for j in range(max(i-k, 0), i))
print(dp[n-1])

Buggy submission (verdict: Runtime Error):
n, k = map(int, input().split())
arr = list(map(int, input().split()))
dp = [float('inf')] * n
dp[0] = 0
for i in range(1, n):
    dp[i] = min(dp[j] + abs(arr[i] - arr[j]) for j in range(max(i-k, 0), i))
print(dp[n-1])
Problem p03171 (python)

Fixed submission:
def deque(n, arr):
    dp = [[0] * n for _ in range(n)]
    for i in range(n):
        dp[i][i] = arr[i]

    for l in range(n-2, -1, -1):
        for r in range(l+1, n):
            L = arr[l] - dp[l+1][r]
            R = arr[r] - dp[l][r-1]
            dp[l][r] = L if L > R else R
    return dp[0][n-1]

n = int(input())
arr = [int(x) for x in input().split()]
print(deque(n, arr))

Buggy submission (verdict: Runtime Error):
n = int(input())
piles = [int(x) for x in input().split()]
dp = [[0] * n for _ in range(n)]
for l in range(n-1,-1,-1):
    for r in range(l, n):
        if l == r:
            dp[l][r] = piles[l]
        else:
            dp[l][r] = max(piles[l] - dp[l+1][r], piles[r] - dp[l][r-1])
return dp[0][n-1]
Problem p03163 (python)

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

dp = [0] * (W + 1)
weights2check = [0]
ans = 0
for _ in range(N):
    w, v = map(int, input().split())
    for k in range(W-w, -1, -1):
        dp[k + w] = max(dp[k + w], dp[k] + v)
        ans = max(ans, dp[k + w])


print(ans)

Buggy submission (verdict: Runtime Error):
#include <bits/stdc++.h>
using namespace std;

int main() {
    int N, W;
    cin >> N >> W;

    vector<int> dp = vector<int>(W + 1, 0);
    vector<int> idx = vector<int>(1, 0);
    int ans = 0;

    for (int i = 0; i < N; i++) {
        int w, v;
        cin >> w >> v;
        vector<int> new_idx = vector<int>(1, 0);
        for (const auto& k : idx) {
            if (k + w <= W) {
                dp[k + w] = max(dp[k + w], dp[k] + v);
                new_idx.push_back(k + w);
                ans = max(ans, dp[k + w]);
            }
        }
        idx.insert(idx.end(), new_idx.begin(), new_idx.end());
    }

    cout << ans << endl;
}
Problem p03167 (python)

Fixed submission:
def main():
    MOD = int(1e9 + 7)
    h, w = map(int, input().split())
    grid = [input() for _ in range(h)]

    dp = [[0] * w for _ in range(h)]

    for i in range(h):
        for j in range(w):
            if grid[i][j] != '#':
                if i == 0 and j == 0:
                    dp[i][j] = 1
                
                if i > 0:
                    dp[i][j] += dp[i-1][j]

                if j > 0:
                    dp[i][j] += dp[i][j-1]

                if dp[i][j] > MOD:
                    dp[i][j] -= MOD

    ans = dp[h-1][w-1]
    print(ans)



if __name__ == "__main__":
    main()

Buggy submission (verdict: Runtime Error):
def main():
    MOD = int(1e9 + 7)
    h, w = map(int, input().split())
    grid = [input() for _ in range(h)]

    dp = [[0] * w for _ in range(h)]
    dp[i][j] = 1

    for i in range(h):
        for j in range(w):
            if grid[i][j] != '#':
                if i > 0:
                    dp[i][j] += dp[i-1][j]

                if j > 0:
                    dp[i][j] += dp[i][j-1]

                if dp[i][j] > MOD:
                    dp[i][j] -= MOD

    ans = dp[h-1][w-1]
    print(ans)



if __name__ == "__main__":
    main()
Problem p03160 (python)

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 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])
Problem p03162 (python)

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

memo = {}

def solve(i, last_option):
	global a, b, c
	if (i, last_option) not in memo:
		if i == len(a):
			result = 0
		elif i == 0:
			result = max(a[i] + solve(i + 1, 1), b[i] + solve(i + 1, 2), c[i] + solve(i + 1, 3))
		else:
			if last_option == 1:
				result = max(b[i] + solve(i + 1, 2), c[i] + solve(i + 1, 3))
			elif last_option == 2:
				result = max(a[i] + solve(i + 1, 1), c[i] + solve(i + 1, 3))
			else:
				result = max(a[i] + solve(i + 1, 1), b[i] + solve(i + 1, 2))
		memo[(i, last_option)] = result
		return result
	else:
		return memo[(i, last_option)]

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

Buggy submission (verdict: Runtime Error):
memo = {}

def solve(i, last_option):
	global a, b, c
	if (i, last_option) not in memo:
		if i == len(a):
			result = 0
		elif i == 0:
			result = max(a[i] + solve(i + 1, 1), b[i] + solve(i + 1, 2), c[i] + solve(i + 1, 3))
		else:
			if last_option == 1:
				result = max(b[i] + solve(i + 1, 2), c[i] + solve(i + 1, 3))
			elif last_option == 2:
				result = max(a[i] + solve(i + 1, 1), c[i] + solve(i + 1, 3))
			else:
				result = max(a[i] + solve(i + 1, 1), b[i] + solve(i + 1, 2))
		memo[(i, last_option)] = result
		return result
	else:
		return memo[(i, last_option)]

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

Buggy submission (verdict: Runtime Error):
memo = {}

def solve(a, b, c, i, last_option):
	if (i, last_option) not in memo:
		if i == len(a):
			result = 0
		elif i == 0:
			result = max(a[i] + solve(a, b, c, i + 1, 1), b[i] + solve(a, b, c, i + 1, 2), c[i] + solve(a, b, c, i + 1, 3))
		else:
			if last_option == 1:
				result = max(b[i] + solve(a, b, c, i + 1, 2), c[i] + solve(a, b, c, i + 1, 3))
			elif last_option == 2:
				result = max(a[i] + solve(a, b, c, i + 1, 1), c[i] + solve(a, b, c, i + 1, 3))
			else:
				result = max(a[i] + solve(a, b, c, i + 1, 1), b[i] + solve(a, b, c, i + 1, 2))
		memo[(i, last_option)] = result
		return result
	else:
		return memo[(i, last_option)]

n = int(input())
a = [None for i in range(n)]
b = [None for i in range(n)]
c = [None for i in range(n)]
for i in range(n):
	a[i], b[i], c[i] = map(int, input().split())
print(solve(a, b, c, 0, 4))
Problem p03166 (python)

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 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))

Buggy 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))
Problem p03160 (python)

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 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])

Buggy 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])

Buggy 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)
Problem p03162 (python)

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 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]]))
Problem p03251 (python)

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 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')