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

Fixed submission:
a,b,x = map(int,input().split())
import numpy as np
S = x/a
if S <= a*b/2:
    theta = np.rad2deg(np.arctan(b*b/(2*S)))
else:
    S = a*b-S
    theta = np.rad2deg(np.arctan(2*S/(a*a)))
print(theta)

Buggy submission (verdict: Runtime Error):
a,b,x = map(int,input().split())
S = x/a
if S <= a*b/2:
    theta = np.rad2deg(np.arctan(b*b/(2*S)))
else:
    S = a*b-S
    theta = np.rad2deg(np.arctan(2*S/(a*a)))
print(theta)
Problem p02924 (python)

Fixed submission:
N = int(input())
print(int(N*(N-1)//2))

Buggy submission (verdict: Runtime Error):
print(int(input())*(int(input())-1))
Problem p03161 (python)

Fixed submission:
N,K = map(int, input().split())
h = list(map(int, input().split()))

dp = [0] * N
for i in range(min(N,K)):
    dp[i] = abs(h[i]-h[0])

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

answer = dp[-1]
print(answer)

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

dp = [0] * N
for i in range(min(N,K)):
    dp[i] = abs(h[i]-h[0])

for i in range(K,N):
    dp[i] = dp[i-1] + abs(h[i]-h[i-1])
    dp[i] = min(dp[i-k] + abs(H[i]-H[i-k]) for k in range(1,K+1))

answer = dp[-1]
print(answer)
Problem p03164 (python)

Fixed submission:
#PythonだとTLE、PyPyだとAC
N,W = map(int, input().split())
w = [0]*N
v = [0]*N
for i in range(N):
    w[i],v[i] = map(int, input().split())

V = sum(v)
inf=float("inf")
dp = [[inf for i in range(V)] for j in range(N)]

for i in range(N):
    for j in range(v[i]):
        dp[i][j] = w[i]

for i in range(1,N):
    for j in range(V):
        if j >= v[i]:
            dp[i][j] = min(dp[i][j],dp[i-1][j],dp[i-1][j-v[i]]+w[i])
        else:
            dp[i][j] = min(dp[i][j],dp[i-1][j])

cnt = 0
for i in dp[-1]:
    if i <= W:
        cnt += 1
print(cnt)

Buggy submission (verdict: Runtime Error):
#PythonだとTLE、PyPyだとAC
N,W = map(int, input().split())
w = [0]*N
v = [0]*N
for i in range(N):
    w[i],v[i] = map(int, input().split())

V = sum(v)
inf=float("inf")
dp = [[inf for i in range(V)] for j in range(N)]

for i in range(N):
    for j in range(v[i]):
        dp[i][j] = w[i]

for i in range(1,N):
    for j in range(V):
        if j >= v[i]:
            dp[i][j] = min(dp[i][j],dp[i-1][j],dp[i-1][j-v[i]]+w[i])
        else:
            dp[i][j] = min(dp[i][j],dp[i-1][j])

print(dp[-1].index(W+1))
Problem p02687 (python)

Fixed submission:
S = input()
if S == 'ABC':
  print('ARC')
else:
  print('ABC')

Buggy submission (verdict: Runtime Error):
S = input()
if S == 'ABC':
  input('ARC')
else:
  print('ABC')
Problem p02761 (python)

Fixed submission:
N,M = map(int,input().split())
s = []
c = []
for i in range(M):
    s1,c1=[int(i) for i in input().split()]
    s.append(s1)
    c.append(c1)

ans = [10 for i in range(N)]
x = ''

for j in range(M):
  if ans[s[j]-1] == 10:
     ans[s[j]-1] = c[j]
  elif ans[s[j]-1] != 10 and  ans[s[j]-1] != c[j]:
    print('-1')
    exit()
  
for k in range(N):
  if k == 0 and ans[k] == 10 and N != 1:
    ans[k] = 1
  elif k == 0 and ans[k] == 10 and N == 1:
    ans[k] = 0
  elif ans[k] == 10:
     ans[k] = 0
if N == 1:
  print(ans[0])
  exit()
else:
  if ans[0] == 0 :
    print('-1')
  else :
    for l in range(N):
      x += str(ans[l])
    print(x)

Buggy submission (verdict: Runtime Error):
N,M = map(int,input().split())
s = []
c = []
for i in range(M):
    s1,c1=[int(i) for i in input().split()]
    s.append(s1)
    c.append(c1)

ans = [10 for i in range(N)]
x = ''

for j in range(M):
  if ans[s[j]-1] == 10:
     ans[s[j]-1] = c[j]
  elif ans[s[j]-1] != 10 and  ans[s[j]-1] != c[j]:
    print('-1')
    exit()
  
for k in range(N):
  if ans[k] == 10:
    ans[k] = 0
if N == 1:
  for l in range(N):
    x += str(ans[l])
  print(x)
  exit()
else:
  if ans[0] == 0 :
  print('-1')
  else :
  for l in range(N):
    x += str(ans[l])
  print(x)
Problem p02767 (python)

Fixed submission:
N = int(input())
X = [int(x) for x in input().split()]
hp = []
dis = 0

for i in range(min(X), max(X) + 1):
  hp.append(dis)
  dis = 0
  for j in X:
    dis += (i - j) ** 2
if len(hp) == 1:
  print(0)
else:
  hp.remove(0)
  print(min(hp))

Buggy submission (verdict: Runtime Error):
N = int(input())
X = [int(x) for x in input().split()]
hp = []
dis = 0
for i in range(min(X),max(X) + 1):
  hp.append(dis)
  dis = 0
  for j in X:
    dis += (i - j) ** 2
hp.remove(0)
print(min(hp))

Buggy submission (verdict: Runtime Error):
N = int(input())
X = [int(x) for x in input().split()]
hp = []
dis = 0
for i in range(X[0],X[N-1] + 1):
  hp.append(dis)
  dis = 0
  for j in X:
    dis += (i - j) ** 2
hp.remove(0)
print(min(hp))
Problem p02830 (python)

Fixed submission:
N = int(input())
S,T = map(str,input().split())
ans = ''
for i in range(N):
    ans = ans+S[i]+T[i]
print(ans)

Buggy submission (verdict: Runtime Error):
 = int(input())
S,T = map(str,input().split())
ans = ''
for i in range(N):
    ans = ans+S[i]+T[i]
print(ans)
Problem p02885 (python)

Fixed submission:
A, B = map(int,input().split())
cartain = B*2

if A<=cartain :
    print(0)
else :
    print(A-cartain)

Buggy submission (verdict: Runtime Error):
A, B = map(int,input().split())
cartain = B*2

if A<=cartain :
    input(0)
else :
    input(A-cartain)
Problem p03029 (python)

Fixed submission:
A,P = map(int,input().split())
print((A*3+P)//2)

Buggy submission (verdict: Runtime Error):
A,P = map(int,input().split())
print((A*3+B)//2)
Problem p02946 (python)

Fixed submission:
K, X = map(int, input().split())

left = X-(K-1)
right = X+(K-1)
ans = list(map(str,range(left,right+1)))
print(' '.join(ans))

Buggy submission (verdict: Runtime Error):
import numpy as np
K, X = map(int, input().split())

if min(-1000000, X-(K-1)) != X-(K-1) and max(1000000, X+(K-1)) != X+(K-1):
    left = X-(K-1)
    right = X+(K-1)
elif min(-1000000, X-(K-1)) == X-(K-1):
    left = -1000000
    right = X+(K-1)
elif max(1000000, X+(K-1)) == X+(K-1):
    left = X-(K-1)
    right = 1000000
else:
    left = -1000000
    right = 1000000

ans = list(map(str,range(left,right+1)))
print(' '.join(ans))
Problem p02947 (python)

Fixed submission:
import collections

N = int(input())

word_list = []
for i in range(N):
    S = list(input())
    c = collections.Counter(sorted(S))
    count = c.values()
    words = c.keys()
    word_list.append(''.join(words)+str(count))

ans_dict = collections.Counter(word_list)
ans_count = list(ans_dict.values())
temp = [i for i in ans_count if i>1]
ans = int(sum([t*(t-1)/2 for t in temp]))
print(ans)

Buggy submission (verdict: Runtime Error):
import numpy as np
N = int(input())

word_list = []
for i in range(N):
    S = list(input())
    words, count = np.unique(S, return_counts=True)
    word_list.append(''.join(words)+str(count))

S, ans_count = np.unique(word_list, return_counts=True)
temp = ans_count[ans_count>1]
ans = int(sum([t*(t-1)/2 for t in temp]))
print(ans)

Buggy submission (verdict: Runtime Error):
import numpy as np
N = int(input())

word_list = []
for i in range(N):
    S = list(input())
    words, count = np.unique(S, return_counts=True)
    word_list.append(''.join(words)+str(count))

S, ans_count = np.unique(word_list, return_counts=True)
temp = ans_count[ans_count>1]
ans = int(sum([t*(t-1)/2 for t in temp]))
print(ans)
Problem p03086 (python)

Fixed submission:
S = list(input())
acgt = ['A', 'C', 'G', 'T']

c=0
ans=0
for word in S:
    c = c+1 if word in acgt else 0
    ans = max(ans, c)
print(ans)

Buggy submission (verdict: Runtime Error):
S = list(input())
acgt = ['A', 'C', 'G', 'T']

wlist=[]
answer=[]
for word in S:
    if word in acgt:
        wlist.append(word)
    else:
        print(wlist)
        answer.append(len(wlist))
        wlist=[]

print(max(answer))

Buggy submission (verdict: Runtime Error):
S = list(input())
acgt = ['A', 'C', 'G', 'T']

list=[]
answer=[]
for word in S:
    if word in acgt:
        list.append(word)
    else:
        answer.append(len(list))
        list=[]

print(max(answer))
Problem p02554 (python)

Fixed submission:
n = int(input())
mod = 10**9 + 7
ans = (pow(10, n, mod) - ((2 * pow(9, n, mod)) % mod - pow(8, n, mod) + mod) % mod + mod) % mod
print(ans)

Buggy submission (verdict: Runtime Error):
n = input()
mod = 10**9 + 7
ans = (pow(10, n, mod) - ((2 * pow(9, n, mod)) % mod - pow(8, n, mod) + mod) % mod + mod) % mod
print(ans)
Problem p02628 (python)

Fixed submission:
N, K = input().split()
P = list(map(int,input().split()))

P.sort()
 
total=0

for i in range(int(K)):
    total=total+P[i]
 
print(total)

Buggy submission (verdict: Runtime Error):
N, K = input().split()
P = list(map(int,input().split()))

P.sort()
 
total=0

for i in range(int(K)+1):
  total=total+P[i]
 
print(total)

Buggy submission (verdict: Runtime Error):
N, K = input().split()
P = list(map(int,input().split()))

# N=5
# K=2
# P=[10, 20, 40, 2, 6]

P.sort()
 
total=0

for i in range(int(K)+1):
  total=total+P[i]
 
print(total)

Buggy submission (verdict: Runtime Error):
N, K = input().split()
P = list(map(int,input().split()))
 
P.sort()
 
total=0
for i in range(K+1):
  total=total+P[i]
 
print(total)

Buggy submission (verdict: Runtime Error):
N, K = input().split()
P = list(map(int,input().split()))

P.sort()

total=0
for i in range(K):
  total=total+P[i]
 
print(total)
Problem p02630 (python)

Fixed submission:
N=int(input())
A=list(map(int,input().split()))
Q=int(input())

NumList=[0]*(10**5+1)

AllSum=sum(A)

for a in A:
  NumList[a]+=1

for i in range(Q):
  B,C=map(int,input().split())
  AllSum=AllSum + (C-B)*NumList[B]
  NumList[C]+=NumList[B]
  NumList[B]=0
  
  print(AllSum)

Buggy submission (verdict: Runtime Error):
N=int(input())
A=list(map(int,input().split()))
Q=int(input())

NumList=[0]*(10**5)

AllSum=sum(A)

for a in A:
  NumList[a]+=1

for i in range(Q):
  B,C=map(int,input().split())
  AllSum=AllSum + (C-B)*NumList[B]
  NumList[C]+=NumList[B]
  NumList[B]=0
  
  print(AllSum)

Buggy submission (verdict: Runtime Error):
N=int(input())
A=list(map(int,input().split()))
Q=int(input())

NumList=[0]*(10**5)

AllSum=sum(A)

for a in A:
  NumList[a]+=1

for i in range(Q):
  B,C=map(int,input().split())
  AllSum=AllSum + (C-B)*NumList[B]
  NumList[C]+=NumList[B]
  NumList[B]=0
  print(AllSum)
Problem p02817 (python)

Fixed submission:
a=list(map(str, input().split()))

print('{}{}'.format(a[1],a[0]))

Buggy submission (verdict: Runtime Error):
S,T=input().split()S,T=input().split()
print(T+S)
Problem p02818 (python)

Fixed submission:
A,B,K=map(int,input().split())
 
if A-K>=0:
  print(A-K,B)
elif (A+B)<=K:
  print(0,0)
else:
  print(0,A+B-K)

Buggy submission (verdict: Runtime Error):
A,B,K=map(int,input().split())

if A-K=>0:
  print(A-K,B)
elif (A+B)<=K:
  print(0,0)
else:
  print(0,A+B-K)
Problem p03478 (python)

Fixed submission:
N,A,B=map(int,input().split())
 
Alltotal=0
for i in range(1,N+1):
  partTotal=0
  temp=i
  while temp!=0:
    partTotal+=temp%10
    temp=temp//10
    
  if A<=partTotal and partTotal<=B:
    Alltotal+=i
    #print(i)
print(Alltotal)

Buggy submission (verdict: Runtime Error):
N,A,B=map(int,input().split())

Alltotal=0
for i in range(1,N+1):
  partTotal=0
  while i!=0:
    partTotal+=i%10
    i=i//10
  if A<=partTotal and partTotal<=b:
    Alltotal+=partTotal
Problem p03632 (python)

Fixed submission:
a,b,c,d=map(int,input().split())
 
if b<=c or d<=a:
  print(0)
else:
  print(min(d,b)-max(a,c))

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

if b<=c or d<=a:
  print(0)
else:
  print(min(d,b)-max(a-c))
Problem p02641 (python)

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

ans = 300
for i in range(-200, 201):
    if i not in list:
        if abs(x-i) < abs(x-ans):
            ans = i

print(ans)

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

integers = [i for i in range(1, 101)]
for i in list:
    integers.remove(i)

ans = integers[0]
minabs = abs(integers[0] - x)
for i in integers:
    if abs(i - x) < minabs:
        minabs = abs(i - x)
        ans = i
        break

print(ans)

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

integers = [i for i in range(1, 101)]  # この中の整数をxと比較
for i in list:
    integers.remove(i)

ans = integers[0]
minabs = abs(integers[0] - x)
for i in integers:
    if abs(i - x) < minabs:
        minabs = abs(i - x)
        ans = i

print(ans)
Problem p02573 (python)

Fixed submission:
N,M = map(int,input().split())
f = [[] for i in range(N)]
for i in range(M):
    A,B = map(int,input().split())
    f[A-1].append(B-1)
    f[B-1].append(A-1)
from collections import deque
d = deque()
x = [-1]*N
for i in range(N):
    if x[i] == -1:
        x[i] = i
        d.append(f[i])
    while len(d) > 0:
        z = d.popleft()
        for j in z:
            if x[j] == -1:
                x[j] = i
                d.append(f[j])
import collections
ans = collections.Counter(x)
print(ans.most_common()[0][1])

Buggy submission (verdict: Runtime Error):
N,M = map(int,input().split())
f = []
for i in range(M):
    A,B = map(int,input().split())
    a = {A,B}
    for j in range(len(f)):
        if f[j] & a != set():
            f[j] = f[j] | a
            a = set()
    if a != set():
        f.append(a)
count = 1
while count > 0:
    count = 0
    for i in range(len(f)-1):
        for j in range(i+1,len(f)):
            if f[i] & f[j] != set():
                count += 1
                f[i] = f[i] | f[j]
                f.remove(f[j])
for i in range(len(f)):
    f[i] = len(f[i])
print(max(f))

Buggy submission (verdict: Runtime Error):
N,M = map(int,input().split())
f = []
for i in range(M):
    A,B = map(int,input().split())
    a = {A,B}
    for i in range(len(f)):
        if f[i] & a != set():
            f[i] = f[i] | a
            a = set()
    if a != set():
        f.append(a)
count = 1
while count > 0:
    count = 0
    for i in range(len(f)-1):
        for j in range(i+1,len(f)):
            if f[i] & f[j] != set():
                count += 1
                f[i] = f[i] | f[j]
                f.remove(f[j])
for i in range(len(f)):
    f[i] = len(f[i])
print(max(f))

Buggy submission (verdict: Runtime Error):
N,M = map(int,input().split())
f = []
for i in range(M):
    A,B = map(int,input().split())
    a = {A,B}
    for i in range(len(f)):
        if f[i] & a != set():
            f[i] = f[i] | a
            a = set()
    if a != set():
        f.append(a)
count = 1
while count > 0:
    count = 0
    for i in range(len(f)-1):
        for j in range(i+1,len(f)):
            if f[i] & f[j] != set():
                count += 1
                f[i] = f[i] | f[j]
                f.remove(f[j])
for i in range(len(f)):
    f[i] = len(f[i])
print(max(f))

Buggy submission (verdict: Runtime Error):
N,M = map(int,input().split())
f = []
for i in range(M):
    A,B = map(int,input().split())
    a = {A,B}
    for i in f:
        if i & a != set():
            a = i | a
            f.remove(i)
#            print(f,a,i)
    f.append(a)

#print(f)
print(len(max(f)))
Problem p02888 (python)

Fixed submission:
N = int(input())
l = list(map(int,input().split()))
l.sort()
ans = 0
max = l[N-1]
tc = N
st = [j+1 for j in range(N-1)]
for i in range(N-2):
    if l[i]+l[i+1] > max:
        k = N-i-1
        ans += ((k-1)*k*(k+1))//6
        break
    for j in range(i+1,N-1):
        if j == tc:
            ans += tp
            break
        s = l[i]+l[j]
        if s <= l[j+1]:
            continue
        if s > max:
            tc = j 
            tp = (N-j-1) * (N-j) //2 #これをiの中でできないか
            ans += tp
            break
        start = st[j]
        if s <= l[start]:
            ans += start-j-1
            continue
        end = N
        while start != end:
            center = (start + end)//2
            if s <= l[center]:
                end = center
            else:
                start = center + 1
        st[j] = end
        ans += end-j-1
print(ans)

Buggy submission (verdict: Runtime Error):
N = int(input())
l = list(map(int,input().split()))
l.sort()
ans = 0
max = l[N-1]
tc = N
st = [j+1 for j in range(N-1)]
for i in range(N-2):
    if l[i]+l[i+1] > max:
        k = N-i-1
        ans += ((k-1)*k*(k+1))//6
        break
    for j in range(i+1,N-1):
        if j == tc:
            ans += tp
            break
        s = l[i]+l[j]
        if s <= l[j+1]:
            continue
        if s > max:
            tc = j 
            tp = (N-j-1) * (N-j) //2 #これをiの中でできないか
            ans += tp
            break
        start = st[j]
        if s <= l[start+1]:
            ans += start-j-1
            continue
        end = N
        while start != end:
            center = (start + end)//2
            if s <= l[center]:
                end = center
            else:
                start = center + 1
        st[j] = end
        ans += end-j-1
print(ans)

Buggy submission (verdict: Runtime Error):
N = int(input())
l = list(map(int,input().split()))
l.sort()
ans = 0
max = l[N-1]
tp = N
for i in range(N-2):
    if l[i]+l[i+1] > max:
        k = N-i-1
        ans += ((k-1)*k*(k+1))//6
        break
    for j in range(i+1,N-1):
        if j == tc:
            ans += tp
            break
        s = l[i]+l[j]
        if s <= l[j+1]:
            continue
        if s > max:
            tc = j 
            tp = (N-j-1) * (N-j) //2 #これをiの中でできないか
            ans += tp
            break
        start = j+1
        end = N
        while start != end:
            center = (start + end)//2
            if s <= l[center]:
                end = center
            else:
                start = center + 1
        ans += end-j-1
print(ans)
Problem p03246 (python)

Fixed submission:
n = int(input())
v = list(map(int,input().split()))
v0 = v[0:n-1:2]
v1 = v[1:n:2]
from collections import Counter
V0 = Counter(v0)
V1 = Counter(v1)
if V0.most_common()[0][0] != V1.most_common()[0][0]:
    a = V0.most_common()[0][1]
    b = V1.most_common()[0][1]
else:
    if V0.most_common()[0][1] > V1.most_common()[0][1]:
        if len(V1) > 1:
            a = V0.most_common()[0][1]
            b = V1.most_common()[1][1]
        else:
            a = V0.most_common()[0][1]
            b = 0
    elif V0.most_common()[0][1] < V1.most_common()[0][1]:
        if len(V0) > 1:
            a = V1.most_common()[0][1]
            b = V0.most_common()[1][1]
        else:
            a = 0
            b = V1.most_common()[0][1]
    else:
        if len(V0) == 1 and len(V1) == 1:
            a = 0
            b = V0.most_common()[0][1]
        elif len(V0) == 1:
            a = V0.most_common()[0][1]
            b = V1.most_common()[1][1]
        elif len(V1) == 1:
            a = V0.most_common()[1][1]
            b = V1.most_common()[0][1]
        else:
            a = V0.most_common()[0][1]
            b = max(V0.most_common()[1][1],V1.most_common()[1][1])
print(n-a-b)

Buggy submission (verdict: Runtime Error):
n = int(input())
v = list(map(int,input().split()))
v0 = v[0:n-1:2]
v1 = v[1:n:2]
from collections import Counter
V0 = Counter(v0)
V1 = Counter(v1)
if V0.most_common()[0][0] != V1.most_common()[0][0]:
    a = V0.most_common()[0][1]
    b = V1.most_common()[0][1]
else:
    if V0.most_common()[0][1] > V1.most_common()[0][1]:
        if len(V1) > 1:
            a = V0.most_common()[0][1]
            b = V1.most_common()[1][1]
        else:
            a = V0.most_common()[0][1]
            b = 0
    elif V0.most_common()[0][1] < V1.most_common()[0][1]:
        if len(V0) > 1:
            a = V1.most_common()[0][1]
            b = V0.most_common()[1][1]
        else:
            a = 0
            b = V1.most_common()[0][1]
    else:
        if len(V0) == 1 and len(V1) == 1:
            a = 0
            b = V0.most_common()[1][1]
        elif len(V0) == 1:
            a = V0.most_common()[0][1]
            b = V1.most_common()[1][1]
        elif len(V1) == 1:
            a = V0.most_common()[1][1]
            b = V1.most_common()[0][1]
        else:
            a = V0.most_common()[0][1]
            b = max(V0.most_common()[1][1],V1.most_common()[1][1])
print(n-a-b)
Problem p03274 (python)

Fixed submission:
N,K = map(int,input().split())
x = list(map(int,input().split()))
xp = [i for i in x if i >= 0]
xn = [i for i in x if i < 0]
xn.reverse()
lp = len(xp)
ln = len(xn)
if lp == 0:
    print(-xn[K-1])
    exit()
if ln == 0:
    print(xp[K-1])
    exit()
pc = min(K,lp)
pp = xp[pc-1]
if K>lp:
    nc = K-lp
    np = -xn[nc-1]
else:
    nc = 0
    np = 0
ans = pp + np + min(pp,np)
for i in range(pc-1):
    if nc == ln:
        break
    pp = xp[pc-i-2]
    np = -xn[nc]
    nc += 1
    ans = min(ans,pp + np + min(pp,np))
print(ans)

Buggy submission (verdict: Runtime Error):
N,K = map(int,input().split())
x = list(map(int,input().split()))
xp = [i for i in x if i >= 0]
xn = [i for i in x if i < 0]
xn.reverse()
lp = len(xp)
ln = len(xn)
pc = min(K,lp)
pp = xp[pc-1]
if K>lp:
    nc = K-lp
    np = -xn[nc-1]
else:
    nc = 0
    np = 0
ans = pp + np + min(pp,np)
for i in range(pc-1):
    if nc == ln:
        break
    pp = xp[pc-i-2]
    np = -xn[nc]
    nc += 1
    ans = min(ans,pp + np + min(pp,np))
print(ans)

Buggy submission (verdict: Runtime Error):
N,K = map(int,input().split())
x = list(map(int,input().split()))
xp = [i for i in x if i >= 0]
xn = [i for i in x if i < 0]
xn.reverse()
lp = len(xp)
ln = len(xn)
pc = min(K,lp)
pp = xp[pc-1]
if K>lp:
    nc = K-lp
    np = -xn[nc-1]
else:
    nc = 0
    np = 0
ans = pp + np + min(pp,np)
for i in range(pc):
    if nc == ln:
        break
    pp = xp[pc-i-2]
    np = -xn[nc]
    nc += 1
    ans = min(ans,pp + np + min(pp,np))
print(ans)
Problem p03401 (python)

Fixed submission:
N = int(input())
A = list(map(int,input().split()))
j = abs(A[0]) + abs(A[N-1])
for i in range(N-1):
    j += abs(A[i]-A[i+1])
for i in range(N):
    if i == 0:
        ans = j-abs(A[0])-abs(A[0]-A[1])+abs(A[1])
    elif i == N-1:
        ans = j-abs(A[N-2]-A[N-1])-abs(A[N-1])+abs(A[N-2])
    else:
        ans = j - abs(A[i]-A[i-1]) - abs(A[i]-A[i+1]) + abs(A[i-1]-A[i+1])
    print(ans)

Buggy submission (verdict: Runtime Error):
 = int(input())
A = list(map(int,input().split()))
j = abs(A[0]) + abs(A[N-1])
for i in range(N-1):
    j += abs(A[i]-A[i+1])
for i in range(N):
    if i == 0:
        ans = j-abs(A[0])-abs(A[0]-A[1])+abs(A[1])
    elif i == N-1:
        ans = j-abs(A[N-2]-A[N-1])-abs(A[N-1])+abs(A[N-2])
    else:
        ans = j - abs(A[i]-A[i-1]) - abs(A[i]-A[i+1]) + abs(A[i-1]-A[i+1])
    print(ans)
Problem p03838 (python)

Fixed submission:
x,y = map(int,input().split())
ax = abs(x)
ay = abs(y)
if ax == ay and x != y:
    a = 1
elif x > y and 0 < y:
    a = ax - ay + 2
elif x > y and y == 0:
    a = ax - ay + 1
elif x > y and 0 > y:
    if ay > ax and x >= 0:
        a = ay - ax + 1
    elif ay > ax and x < 0:
        a = ay - ax + 2
    elif ax > ay:
        a = ax - ay + 1
elif y > x and x < 0 and ay > ax:
    a = ay - ax + 1
elif y > x and x < 0 and y > 0 and ax > ay:
    a = ax - ay + 1
else:
    a = y-x
print(a)

Buggy submission (verdict: Runtime Error):
x,y = map(int,input().split())
ax = abs(x)
ay = abs(y)
if ax == ay and x != y:
    a = 1
elif x > y and 0 < y:
    a = ax - ay + 2
elif x > y and y = 0:
    a = ax - ay + 1
elif x > y and 0 > y:
    if ay > ax and x >= 0:
        a = ay - ax + 1
    elif ay > ax and x < 0:
        a = ay - ax + 2
    elif ax > ay:
        a = ax - ay + 1
elif y > x and x < 0 and ay > ax:
    a = ay - ax + 1
elif y > x and x < 0 and y > 0 and ax > ay:
    a = ax - ay + 1
else:
    a = y-x
print(a)

Buggy submission (verdict: Runtime Error):
x,y = map(int,input().split())
ax = abs(x)
ay = abs(y)
if x > y and 0 < y:
    x = -x
    a = y - x + 1
    if  ay > ax and x >= 0:
        a = ay - x + 

elif x > y and 0 >= y:
    if ay > ax and x >= 0:
        a = ay - x + 1
    elif ay > ax and x < 0:
        a = ay + x + 2
    else:
        a = 1
elif y > x and x < 0:
    if ay > ax:
        a = ay - ax + 1
else:
    a = y-x
print(a)