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

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

n = int(input())

path = [[] for i in range(n)]

for _ in range(n-1):
    u,v,w = list(map(int,input().split()))
    path[u-1].append((v-1, w))
    path[v-1].append((u-1, w))

global dist
dist = [-1 for i in range(n)]
dist[0] = 0

def dfs(now):
    for v,w in path[now]:
        if dist[v] == -1:
            dist[v] = w + dist[now]
            dfs(v)
    
dfs(0)

for i in dist:
    print(i%2)

Buggy submission (verdict: Runtime Error):
n = int(input())

path = [[] for i in range(n)]

for _ in range(n-1):
    u,v,w = list(map(int,input().split()))
    path[u-1].append((v-1, w%2))
    path[v-1].append((u-1, w%2))

global dist
dist = [-1 for i in range(n)]
dist[0] = 0

def dfs(now):
    for v,w in path[now]:
        if dist[v] == -1:
            dist[v] = w + dist[now]
            dfs(v)
    
dfs(0)

for i in dist:
    print(i%2)

Buggy submission (verdict: Runtime Error):
n = int(input())

path = [[] for i in range(n)]

for _ in range(n-1):
    u,v,w = list(map(int,input().split()))
    path[u-1].append((v-1, w))
    path[v-1].append((u-1, w))

global dist
dist = [-1 for i in range(n)]
dist[0] = 0

def dfs(now):
    for v,w in path[now]:
        if dist[v] == -1:
            dist[v] = w + dist[now]
            dfs(v)
    
dfs(0)

for i in dist:
    print(i%2)

Buggy submission (verdict: Runtime Error):
n = int(input())

path = [[] for i in range(n)]

for _ in range(n-1):
    u,v,w = list(map(int,input().split()))
    path[u-1].append((v-1, w))
    path[v-1].append((u-1, w))

global dist
dist = [-1 for i in range(n)]
dist[0] = 0

def dfs(now):
    for v,w in path[now]:
        if dist[v] == -1:
            dist[v] = w + dist[now]
            dfs(v)
    
dfs(0)

for i in dist:
    print(i%2)
Problem p03061 (python)

Fixed submission:
import fractions
n = int(input())

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

front_gcd = []

a_init = al[0]
for a in al:
    a_init = fractions.gcd(a, a_init)
    front_gcd.append(a_init)
    
back_gcd = []

b_init = al[-1]
for b in al[::-1]:
    b_init = fractions.gcd(b, b_init)
    back_gcd.append(b_init)
    
back_gcd = back_gcd[::-1]

ans = 1
for i in range(n):
    if i == 0:
        x = back_gcd[1]
    elif i == n-1:
        x = front_gcd[-2]
    else:
        x = fractions.gcd(front_gcd[i-1], back_gcd[i+1])
    if x > ans:
        ans = x

print(ans)

Buggy submission (verdict: Runtime Error):
import fractions
n = int(input())

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

front_gcd = []

a_init = al[0]
for a in al:
    a_init = fractions.gcd(a, a_init)
    front_gcd.append(a_init)
    
back_gcd = []

b_init = al[-1]
for b in al[::-1]:
    b_init = fractions.gcd(b, b_init)
    back_gcd.append(b_init)
    
back_gcd = back_gcd[::-1]

ans = 1
for i in range(n):
    if i == 0:
        x = back_gcd[1]
    elif i == n-1:
        x = front_gcd[-2]
    else:
        x = fractions.gcd(front_gcd[i-1], back_gcd[i+1])
    if gcd > ans:
        ans = x

print(ans)

Buggy submission (verdict: Runtime Error):
from fractions import gcd
n = int(input())

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

front_gcd = []

a_init = al[0]
for a in al:
    a_init = gcd(a, a_init)
    front_gcd.append(a_init)
    
back_gcd = []

b_init = al[-1]
for b in al[::-1]:
    b_init = gcd(b, b_init)
    back_gcd.append(b_init)
    
back_gcd = back_gcd[::-1]

ans = 1
for i in range(n):
    if i == 0:
        gcd = back_gcd[1]
    elif i == n-1:
        gcd = front_gcd[-2]
    else:
        gcd = gcd(front_gcd[i-1], back_gcd[i+1])
    if gcd > ans:
        ans = gcd

print(ans)

Buggy submission (verdict: Runtime Error):
import math
n = int(input())

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

front_gcd = []

a_init = al[0]
for a in al:
    a_init = math.gcd(a, a_init)
    front_gcd.append(a_init)
    
back_gcd = []

b_init = al[-1]
for b in al[::-1]:
    b_init = math.gcd(b, b_init)
    back_gcd.append(b_init)
    
back_gcd = back_gcd[::-1]

ans = 1
for i in range(n):
    if i == 0:
        gcd = back_gcd[1]
    elif i == n-1:
        gcd = front_gcd[-2]
    else:
        gcd = math.gcd(front_gcd[i-1], back_gcd[i+1])
    if gcd > ans:
        ans = gcd

print(ans)
Problem p03078 (python)

Fixed submission:
x,y,z,k = map(int,input().split())	

al = list(map(int,input().split()))
bl = list(map(int,input().split()))
cl = list(map(int,input().split()))

al = sorted(al)
bl = sorted(bl)
cl = sorted(cl)
rank = []
flag = False
for xx in range(x-1,-1,-1):
    tmp = al[xx]+bl[-1]+cl[-1]
    if flag and rank[-1] >= tmp:
        break
    for yy in range(y-1, -1, -1):
        tmp = al[xx]+bl[yy]+cl[-1]
        if flag and rank[-1] >= tmp:
            break
        for zz in range(z-1,-1,-1):
            if len(rank) < k:
                rank.append(al[xx]+bl[yy]+cl[zz])
                rank = sorted(rank, reverse=True)
            else:
                tmp = al[xx]+bl[yy]+cl[zz]
                if rank[-1] < tmp:
                    flag = True
                    rank.pop()
                    rank.append(tmp)
                    rank = sorted(rank, reverse=True)
                else:
                    break

for i in rank:
    print(i)

Buggy submission (verdict: Runtime Error):
x,y,z,k = map(int,input().split())	

al = list(map(int,input().split()))
bl = list(map(int,input().split()))
cl = list(map(int,input().split()))

al = sorted(al)
bl = sorted(bl)
cl = sorted(cl)
rank = []
for xx in range(x-1,-1,-1):
    tmp = al[xx]+bl[-1]+cl[-1]
    if rank[-1] >= tmp:
        break
    for yy in range(y-1, -1, -1):
        tmp = al[xx]+bl[yy]+cl[-1]
        if rank[-1] >= tmp:
            break
        for zz in range(z-1,-1,-1):
            if len(rank) < k:
                rank.append(al[xx]+bl[yy]+cl[zz])
                rank = sorted(rank, reverse=True)
            else:
                tmp = al[xx]+bl[yy]+cl[zz]
                if rank[-1] < tmp:
                    rank.pop()
                    rank.append(tmp)
                    rank = sorted(rank, reverse=True)
                else:
                    break

for i in rank:
    print(i)

Buggy submission (verdict: Runtime Error):
x,y,z,k = map(int,input().split())	

al = list(map(int,input().split()))
bl = list(map(int,input().split()))
cl = list(map(int,input().split()))

al = sorted(al)
bl = sorted(bl)
cl = sorted(cl)
rank = []
for xx in range(x-1,-1,-1):
    tmp = al[xx]+bl[-1]+cl[-1]
    if rank[-1] >= tmp:
        break
    for yy in range(y-1, -1, -1):
        tmp = al[xx]+bl[yy]+cl[-1]
        if rank[-1] >= tmp:
            break
        for zz in range(z-1,-1,-1):
            if len(rank) < k:
                rank.append(al[xx]+bl[yy]+cl[zz])
                rank = sorted(rank, reverse=True)
            else:
                tmp = al[xx]+bl[yy]+cl[zz]
                if rank[-1] < tmp:
                    rank.pop()
                    rank.append(tmp)
                    rank = sorted(rank, reverse=True)
                else:
                    break

for i in rank:
    print(i)
Problem p03160 (python)

Fixed submission:
n = int(input())
hl = list(map(int,input().split()))

dp = [float("inf") for i in range(n)]

dp[0] = 0
for idx, h in enumerate(hl):
    if idx + 2 < n:
        dp[idx+2] = min(dp[idx] + abs(hl[idx] - hl[idx+2]), dp[idx+2])
    if idx+1 < n:
        dp[idx+1] = min(dp[idx] + abs(hl[idx] - hl[idx+1]), dp[idx+1])

print(dp[n-1])

Buggy submission (verdict: Runtime Error):
def Frog1():
    import numpy as np
    n = int(input())
    h = list(map(int, input().split()))
    ans = [np.inf for i in range(n)]
    ans[0] = 0
    def dp(ans, h, k):
        if n == k + 1:
            return
        if n != k + 2:
            ans[k + 2] = min(ans[k + 2], ans[k] + abs(h[k + 2] - h[k]))
        ans[k + 1] = min(ans[k + 1], ans[k] + abs(h[k + 1] - h[k]))
        dp(ans, h , k + 1)
    dp(ans, h, 0)
    print(ans[-1])
Frog1()

Buggy submission (verdict: Runtime Error):
    import numpy as np
    n = int(input())
    h = list(map(int, input().split()))
    ans = [np.inf for i in range(n)]
    ans[0] = 0
    def dp(ans, h, k):
        if n == k + 1:
            return
        if n != k + 2:
            ans[k + 2] = min(ans[k + 2], ans[k] + abs(h[k + 2] - h[k]))
        ans[k + 1] = min(ans[k + 1], ans[k] + abs(h[k + 1] - h[k]))
        dp(ans, h , k + 1)
    dp(ans, h, 0)
    print(ans[-1])
Problem p03165 (python)

Fixed submission:
s = input()
t = input()

def solve(S, T):
    L1 = len(S)
    L2 = len(T)
    dp = [[0]*(L2+1) for i in range(L1+1)]

    for i in range(L1-1, -1, -1):
        for j in range(L2-1, -1, -1):
            r = max(dp[i+1][j], dp[i][j+1])
            if S[i] == T[j]:
                r = max(r, dp[i+1][j+1] + 1)
            dp[i][j] = r

    # dp[0][0] が長さの解

    # ここからは復元処理
    res = []
    i = 0; j = 0
    while i < L1 and j < L2:
        if S[i] == T[j]:
            res.append(S[i])
            i += 1; j += 1
        elif dp[i][j] == dp[i+1][j]:
            i += 1
        elif dp[i][j] == dp[i][j+1]:
            j += 1
    return "".join(res)

print(solve(s,t))

Buggy submission (verdict: Runtime Error):
s = list(input())
t = list(input())


dp = [["" for _ in range(len(s)+2)] for _ in range(len(t)+2)]

for i in range(len(s)):
    for j in range(len(t)):
        if s[i] == t[j]:
            if len(dp[i][j]) + 1 > len(dp[i][j+1]) and len(dp[i][j]) + 1 > len(dp[i+1][j]):
                dp[i+1][j+1] = dp[i][j] + s[i]
            elif len(dp[i][j+1]) > len(dp[i][j]) + 1 and len(dp[i][j+1]) > len(dp[i+1][j]):
                dp[i+1][j+1] = dp[i][j+1]
            else:
                dp[i+1][j+1] = dp[i+1][j]
        else:
            if len(dp[i+1][j]) > len(dp[i][j+1]):
                dp[i+1][j+1] = dp[i+1][j]
            else:
                dp[i+1][j+1] = dp[i][j+1]

print(dp[len(s)][len(t)])
Problem p03216 (python)

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

def main():
    N = int(input())
    S = input()
    Q = int(input())
    x = tuple(map(int,input().split()))
    for k in x:
        d,m,dm,dmc = 0,0,0,0
        for i in range(N):
            if S[i] == "D":
                d += 1
            elif S[i] == "M":
                m += 1
                dm += d
            elif S[i] == "C":
                dmc += dm
            if i >= k-1:
                if S[i-k+1] == "D":
                    dm -= m
                    d -= 1
                elif S[i-k+1] == "M":
                    m -= 1
        print(dmc)
    
if __name__ == "__main__":
    main()

Buggy submission (verdict: Runtime Error):
n = int(input())
sl = list(input())[:-1]

q = int(input())
kl = list(map(int,input().split()))

for k in kl:
    # i文字目までのdとmとdmの数
    d = 0
    m = 0
    dm = 0
    ans = 0
    for i in range(n):
        if i - k >= 0:
            if sl[i-k] == "D":
                d -= 1
                dm -= m
            if sl[i-k] == "M":
                m -= 1
        if sl[i] == "D":
            d += 1
        if sl[i] == "M":
            m += 1
            dm += d
        if sl[i] == "C":
            ans += dm

    print(ans)

Buggy submission (verdict: Runtime Error):
import sys

input = sys.stdin.readline
n = int(input())
sl = list(input())

q = int(input())
kl = list(map(int,input().split()))

for k in kl:
    # i文字目までのdとmとdmの数

    dp = [[0, 0, 0] for i in range(n+1)]
    ans = 0
    for i, s in enumerate(sl):
        if i - k >= 0:
            if sl[i-k] == "D":
                dp[i][0] -= 1
                dp[i][2] -= dp[i][1]
            if sl[i-k] == "M":
                dp[i][1] -= 1
        if s == "D":
            dp[i+1][0] = dp[i][0] + 1
        else:
            dp[i+1][0] = dp[i][0]
        if s == "M":
            dp[i+1][1] = dp[i][1] + 1
            dp[i+1][2] = dp[i][2] + dp[i][0]
        else:
            dp[i+1][1] = dp[i][1]
            dp[i + 1][2] = dp[i][2]
        if s == "C":
            ans += dp[i][2]

    print(ans)

Buggy submission (verdict: Runtime Error):
import sys

input = sys.stdin.readline
n = int(input())
sl = list(input())

q = int(input())
kl = list(map(int,input().split()))

for k in kl:
    # i文字目までのdとmとdmの数

    dp = [[0, 0, 0] for i in range(n+1)]
    ans = 0
    for i, s in enumerate(sl):
        if i - k >= 0:
            if sl[i-k] == "D":
                dp[i][0] -= 1
                dp[i][2] -= dp[i][1]
            if sl[i-k] == "M":
                dp[i][1] -= 1
        if s == "D":
            dp[i+1][0] = dp[i][0] + 1
        else:
            dp[i+1][0] = dp[i][0]
        if s == "M":
            dp[i+1][1] = dp[i][1] + 1
            dp[i+1][2] = dp[i][2] + dp[i][0]
        else:
            dp[i+1][1] = dp[i][1]
            dp[i + 1][2] = dp[i][2]
        if s == "C":
            ans += dp[i][2]

    print(ans)
Problem p03263 (python)

Fixed submission:
h,w = map(int,input().split())

al_l = []

for _ in range(h):
    al = list(map(int,input().split()))
    al_l.append(al)
    
ansl = []
get = False
for i in range(h):
    for j in range(w-1):
        if not get:
            if al_l[i][j] % 2 == 1:
                get = True
                al_l[i][j] -= 1
                al_l[i][j+1] += 1
                ansl.append(str(i+1)+" "+str(j+1)+" "+str(i+1)+" "+str(j+2))
        elif get:
            if al_l[i][j] % 2 == 0:
                get = False
            else:
                al_l[i][j] -= 1
                al_l[i][j+1] += 1
                ansl.append(str(i+1)+" "+str(j+1)+" "+str(i+1)+" "+str(j+2))
            
get = False  
for i in range(h-1):
    if not get:
        if al_l[i][-1] % 2 == 1:
            get = True
            al_l[i][-1] -= 1
            al_l[i+1][-1] += 1
            ansl.append(str(i+1)+" "+str(w)+" "+str(i+2)+" "+str(w))
    elif get:
        if al_l[i][-1] % 2 == 0:
            get = False
        else:
            al_l[i][-1] -= 1
            al_l[i+1][-1] += 1
            ansl.append(str(i+1)+" "+str(w)+" "+str(i+2)+" "+str(w))

print(len(ansl))
for ans in ansl:
    print(ans)

Buggy submission (verdict: Runtime Error):
h,w = map(int,input().split())

al_l = []

for _ in range(h):
    al = list(map(int,input().split()))
    al_l.append(al)
    
ansl = []
get = False
for i in range(h):
    for j in range(w-1):
        if not get:
            if al_l[i][j] % 2 == 1:
                get = True
                al_l[i][j] -= 1
                al_l[i][j+1] += 1
                ansl.append(str(i+1)+" "+str(j+1)+" "+str(i+1)+" "+str(j+2))
        elif get:
            if al_l[i][j] % 2 == 0:
                get = False
            else:
                al_l[i][j] -= 1
                al_l[i][j+1] += 1
                ansl.append(str(i+1)+" "+str(j+1)+" "+str(i+1)+" "+str(j+2))
            
get = False  
for i in range(h-1):
    if not get:
        if al_l[i][-1] % 2 == 1:
            get = True
            al_l[i][-1] -= 1
            al_l[i+1][-1] += 1
            ansl.append(str(i+1)+" "+str(j+1)+" "+str(i+2)+" "+str(j+1))
    elif get:
        if al_l[i][-1] % 2 == 0:
            get = False
        else:
            al_l[i][-1] -= 1
            al_l[i+1][-1] += 1
            ansl.append(str(i+1)+" "+str(j+1)+" "+str(i+2)+" "+str(j+1))

print(len(ansl))
for ans in ansl:
    print(ans)
Problem p03266 (python)

Fixed submission:
n,k = map(int,input().split())

if k % 2 == 1:
    print((n//k) ** 3)
else:
    print((n//k) ** 3 + ((n-k//2)//k+1)**3)

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

k = k // 2
x = n // k
if x % 2 == 0:
    ans = 2 * (x / 2) ** 3
else:
    ans = ((x // 2) + 1) ** 3 + (x // 2) ** 3

print(ans)

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

k = k // 2
x = n // k
if x % 2 == 0:
    ans = 2 * (x / 2) ** 3
else:
    ans = ((x // 2) + 1) ** 3 + (x // 2) ** 3

print(int(ans))
Problem p03309 (python)

Fixed submission:
import numpy as np
n = int(input())
al = list(map(int,input().split()))

for i in range(n):
    al[i] -= i + 1

med = np.median(np.array(al))

ans = 0
for a in al:
    ans += abs(a-med)
print(int(ans))

Buggy submission (verdict: Runtime Error):
import numpy as np
n = int(input())
al = list(map(int,input().split()))

for i in range(n):
    al[i] -= i + 1

med = np.median(np.array(al))

ans = 0
for a in al:
    ans += abs(a-med)
print(int(ans))

Buggy submission (verdict: Runtime Error):
import statistics
n = int(input())
al = list(map(int,input().split()))

for i in range(n):
    al[i] -= i + 1

median = statistics.median(al)

ans = 0
for a in al:
    ans += abs(median - a)

print(int(ans))
Problem p03316 (python)

Fixed submission:
n = int(input())

s = n
b = []
while n:
    b.append(n%10)
    n = n // 10

if s % sum(b) == 0:
    print("Yes")
else:
    print("No")

Buggy submission (verdict: Runtime Error):
n = int(input())

s = n
b = []
while n:
    b.append(n%10)
    n = n // 10

if s % sum(b) == 0:
    print("Yes")
else:
Problem p03353 (python)

Fixed submission:
s = input()
k = int(input())



rank = []
for i in range(len(s)):
    for j in range(i+1, min(i+6,len(s)+1)):
        ss = s[i:j]
        rank.append(ss)

rank = sorted(list(set(rank)))
print(rank[k-1])

Buggy submission (verdict: Runtime Error):
s = input()
k = int(input())

if len(s) == 1:
    print(s)
    import sys
    sys.exit()

rank = []
for i in range(len(s)):
    for j in range(i+1, len(s)+1):
        ss = s[i:j]
        print(ss)
        if ss not in rank:
            if len(rank) < k:
                rank.append(ss)
            else:
                # print(ss)
                if ss <= rank[-1]:
                    rank.pop()
                    rank.append(ss)
                    rank = sorted(rank)
                    # print(rank)

print(rank[-1])
Problem p03372 (python)

Fixed submission:
n, c = map(int,input().split())

xvl = []
for _ in range(n):
    x,v = map(int,input().split())
    xvl.append((x,v))

get_l = []
sum_v = 0
for x, v in xvl:
    sum_v += v
    get_l.append(sum_v - x)

import itertools
get_l_ac = list(itertools.accumulate(get_l, max))
get_r = []
sum_v = 0
for x, v in xvl[::-1]:
    sum_v += v
    get_r.append(sum_v - (c - x))


ans = 0
x = 0
for i in range(n):
    tmp = 0
    if i > 0:
        x = c - xvl[-i][0]
        tmp += get_r[i-1]
    ans = max(tmp, tmp - x + get_l_ac[n - i - 1], ans)

get_r_ac = list(itertools.accumulate(get_r, max))
x = 0
for i in range(n):
    tmp = 0
    if i > 0:
        x = xvl[i-1][0]
        tmp += get_l[i-1]
    ans = max(tmp, tmp - x + get_r_ac[n - i - 1], ans)

print(ans)

Buggy submission (verdict: Runtime Error):
n, c = map(int,input().split())

xvl = []
for _ in range(n):
    x,v = map(int,input().split())
    xvl.append((x,v))

get_l = []
sum_v = 0
for x, v in xvl:
    sum_v += v
    get_l.append(sum_v - x)

import itertools
get_l_ac = list(itertools.accumulate(get_l, max))
get_r = []
sum_v = 0
for x, v in xvl[::-1]:
    sum_v += v
    get_r.append(sum_v - (c - x))


ans = 0
x = 0
for i in range(n):
    tmp = 0
    if i > 0:
        x = c - xvl[-i][0]
        tmp += get_r[i-1]
    ans = max(tmp, tmp - x + get_l_ac[n - i - 1], ans)

get_r_ac = list(itertools.accumulate(get_r, max))
x = 0
for i in range(n):
    tmp = 0
    if i > 0:
        x = xvl[i-1][0]
        tmp += get_l[i-1]
    ans = max(tmp, tmp - x + get_r_ac[n - i - 1], ans)

print(ans)
Problem p03393 (python)

Fixed submission:
S=input()
if S=='zyxwvutsrqponmlkjihgfedcba':
  print(-1)
  exit()
alp='abcdefghijklmnopqrstuvwxyz'
N=len(S)
if N<26:
  T=S+alp
  i=0
  while T.index(alp[i])<N:
    i+=1
  print(S+alp[i])
  exit()
  
i=-1
nums=[alp.index(S[i])]
while max(nums)==nums[-1]:
  i-=1
  nums.append(alp.index(S[i]))

out=S[:-len(nums)]
tmp=26
for i in nums[:-1]:
  if i>nums[-1] and tmp>i:
    tmp=i
    
print(out+alp[tmp])

Buggy submission (verdict: Runtime Error):
sl = list(input())
ascii_lowercase = 'abcdefghijklmnopqrstuvwxyz'
if len(sl) != 26:
    for s in ascii_lowercase:
        if s not in sl:
            sl.append(s)
            break
    print("".join(sl))
elif "".join(sl) == "zyxwvutsrqponmlkjihgfedcba":
    print("-1")
else:
    ansl = []
    for s, t in zip(sl, ascii_lowercase):
        if s != t:
            ansl[-1] = t
            print("".join(ansl))
            break
        ansl.append(t)

Buggy submission (verdict: Runtime Error):
sl = list(input())
ascii_lowercase = 'abcdefghijklmnopqrstuvwxyz'
if len(sl) != 26:
    for s in ascii_lowercase:
        if s not in sl:
            sl.append(s)
            break
    print("".join(sl))
elif "".join(sl) == "zyxwvutsrqponmlkjihgfedcba":
    print("zyxwvutsrqponmlkjihgfedcba")
else:
    ansl = []
    for s, t in zip(sl, ascii_lowercase):
        if s != t:
            ansl[-1] = t
            print("".join(ansl))
            break
        ansl.append(t)
Problem p03470 (python)

Fixed submission:
n = int(input())
dl = []
for _ in range(n):
    d = int(input())
    dl.append(d)

print(len(set(dl)))

Buggy submission (verdict: Runtime Error):
n = int(input())
dl = []
for _ in range(n):
    dl.append(d)

print(len(set(dl)))
Problem p03550 (python)

Fixed submission:
n,z,w = map(int,input().split())

al = list(map(int,input().split()))
if len(al) == 1:
    print(abs(al[-1] - w))
    exit()
ans1 = abs(al[-1] - al[-2])
ans2 = abs(al[-1] - w)

print(max(ans1, ans2))

Buggy submission (verdict: Runtime Error):
n,z,w = map(int,input().split())

al = list(map(int,input().split()))
if len(al) == 1:
    print(abs(al[-1] - w))
ans1 = abs(al[-1] - al[-2])
ans2 = abs(al[-1] - w)

print(max(ans1, ans2))

Buggy submission (verdict: Runtime Error):
n,z,w = map(int,input().split())

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

ans1 = abs(al[-1] - al[-2])
ans2 = abs(al[-1] - w)

print(max(ans1, ans2))
Problem p03576 (python)

Fixed submission:
N, K = list(map(int, input().split()))
P = sorted([tuple(map(int, input().split())) for _ in range(N)])

ans = 1e30
for lx in range(N):
    for rx in range(lx+K, N+1):
        Q = sorted(P[lx:rx], key=lambda x:x[1])
        for ly in range(len(Q)):
            R = Q[ly:ly+K]
            if len(R)>=K: ans = min(ans, (P[rx-1][0]-P[lx][0])*(R[-1][1]-R[0][1]))
print(ans)

Buggy submission (verdict: Runtime Error):
n,k = map(int,input().split())
xyl = []
for _ in range(n):
    x,y = map(int,input().split())
    xyl.append((x,y))

ans = float("inf")
for i in range(n):
    for j in range(i+1, n):
        for h in range(j+1, n):
            for g in range(h+1, n):
                x1 = min(xyl[i][0], xyl[j][0], xyl[h][0], xyl[g][0])
                x2 = max(xyl[i][0], xyl[j][0], xyl[h][0], xyl[g][0])
                y1 = min(xyl[i][1], xyl[j][1], xyl[h][1], xyl[g][1])
                y2 = max(xyl[i][1], xyl[j][1], xyl[h][1], xyl[g][1])
                cnt = 0
                for p in range(n):
                    if x1 <= xyl[p][0] <= x2 and  y1 <= xyl[p][1] <= y2:
                        cnt += 1
                if k <= cnt:
                    ans = min(ans, (x2-x1)*(y2-y1))

for i in range(n):
    for j in range(i+1, n):
        for h in range(j+1, n):
            x1 = min(xyl[i][0], xyl[j][0], xyl[h][0])
            x2 = max(xyl[i][0], xyl[j][0], xyl[h][0])
            y1 = min(xyl[i][1], xyl[j][1], xyl[h][1])
            y2 = max(xyl[i][1], xyl[j][1], xyl[h][1])
                cnt = 0
                for p in range(n):
                    if x1 <= xyl[p][0] <= x2 and  y1 <= xyl[p][1] <= y2:
                        cnt += 1
                if k <= cnt:
                    ans = min(ans, (x2-x1)*(y2-y1))

for i in range(n):
    for j in range(i+1, n):
        x1 = min(xyl[i][0], xyl[j][0])
        x2 = max(xyl[i][0], xyl[j][0])
        y1 = min(xyl[i][1], xyl[j][1])
        y2 = max(xyl[i][1], xyl[j][1])
            cnt = 0
            for p in range(n):
                if x1 <= xyl[p][0] <= x2 and  y1 <= xyl[p][1] <= y2:
                    cnt += 1
            if k <= cnt:
                ans = min(ans, (x2-x1)*(y2-y1))



print(ans)