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

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

c = 0
d = a + b -n
if (a > b):
    c = b
else:
    c = a

if (d < 0):
    d = 0
    
print(str(c) + " " + str(d))

Buggy submission (verdict: Runtime Error):
if __name__ == '__main__':
    n = int(input())
    c = []
    d = []
    e = []
    
    for i in range(0, n):
        a, b = map(int, input().split())
        c.append(a)
        d.append(b)
        e.append(a + b)
    
    li1, li2 = sorted(e), sorted(range(len(e)), key=lambda k: e[k])
    
    turn = 0
    happy = 0

    for i in range(n - 1, -1, -1):
        now = li1[i]
        if (turn == 0):
            max = 0
            maxKey = 0
            for j in range(i, -1, -1):
                if (now == li1[j] and max < c[li2[j]]):
                    max = c[li2[j]]
                    maxKey = j
                else:
                    li2[i], li2[maxKey] = li2[maxKey], li2[i]
                    break
            happy += c[li2[i]]
        else:

            max = 0
            maxKey = 0
            for j in range(i, -1, -1):
                if (now == li1[j] and max < d[li2[j]]):
                    max = d[li2[j]]
                    maxKey = j
                else:
                    li2[i], li2[maxKey] = li2[maxKey], li2[i]
                    break

            happy -= d[li2[i]]
        turn = (turn + 1) % 2
    print(happy)

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

c = 0
d = a + b -n
if (a > b):
    c = b
else:
    c = a

if (d < 0):
    d = 0
    
print(str(c) + " " + str(d))
Problem p03640 (python)

Fixed submission:
# -*- coding: utf-8 -*-
"""
Created on Fri Jun  5 09:50:00 2020

@author: NEC-PCuser
"""

H, W = map(int, input().split())
N = int(input())
a = list(map(int, input().split()))

gazo = [[0] * W  for i in range(H)]

count = 0
start_H = 0
start_W = 0
direction = 0
for i in range(len(a)):
    for j in range(a[i]):
        gazo[start_H][start_W] = i + 1
        if (start_W < W - 1 and direction == 0):
            start_W += 1
        elif (start_W == W - 1 and direction == 0):
            start_H += 1
            direction = 1
        elif (start_W > 0 and direction == 1):
            start_W -= 1
        elif (start_W == 0 and direction == 1):
            start_H += 1
            direction = 0
    
for i in range(len(gazo)):
    print(' '.join(map(str, gazo[i])))

Buggy submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-
"""
Created on Fri Jun  5 09:50:00 2020

@author: NEC-PCuser
"""

H, W = map(int, input().split())
N = int(input())
a = list(map(int, input().split()))

gazo = [[0] * W  for i in range(H)]

count = 0
start_H = 0
start_W = 0
direction = 0
for i in range(len(a)):
    for j in range(a[i]):
        gazo[start_H][start_W] = i + 1
        if (start_W < W - 1 and direction == 0):
            start_W += 1
        elif (start_W == W - 1 and direction == 0):
            start_H += 1
            direction = 1
        elif (start_W > 0 and direction == 1):
            start_W -= 1
        elif (start_W == 0 and direction == 1):
            start_H += 1
            direction = 1

for i in range(len(gazo)):
    print(' '.join(map(str, gazo[i])))
Problem p02553 (python)

Fixed submission:
li=list(map(int,input().split()))
ans=[]
a=li[0]*li[2]
b=li[0]*li[3]
c=li[1]*li[2]
d=li[1]*li[3]
ans.append(a)
ans.append(b)
ans.append(c)
ans.append(d)

print(max(ans))

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

if (li[0] or li[1])>0:
  if (li[2] or li[3])>0:
    x=min(li[0],li[1]+1)
    y=max(li[2],li[3]+1)
    print(x*y)
  else:
    x=max(li[0],li[1]+1)
    y=max(li[2],li[3]+1)
    print(x*y)
else:
  if (li[2] or li[3])>0:
    x=mix(li[0],li[1]+1)
    y=man(li[2],li[3]+1)
    print(x*y)
  else:
    x=min(li[0],li[1]+1)
    y=min(li[2],li[3]+1)
    print(x*y)
Problem p02675 (python)

Fixed submission:
n=input()
l1=['2','4','5','7','9']
l2=['0','1','6','8']
l3=['3']
if (n[-1] in l1):
  print('hon')
elif (n[-1] in l2):
  print('pon')
else:
  print('bon')

Buggy submission (verdict: Runtime Error):
n=input()
l=[2,4,5,7,9]
l2=[0,1,6,8]
l3=[3]

if (n%10) in l:
  print('hon')
elif (n%10) in l2:
  print('pon')
else:
  print('bon')
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'):
  print('ARC')
else:
  prin('ABC')
Problem p02700 (python)

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

A=li[0]
B=li[1]
C=li[2]
D=li[3]

while ((A>0) and (C>0)) :
  C=C-B
  if C<=0:
    print('Yes')
    break
  A=A-D
  if A<=0:
    print('No')
    break

Buggy submission (verdict: Runtime Error):
li=[input() for i in range(4)]

while ((li[0]>0) and (li[2]>0)):
  li[2]=li[2]-li[1]
   if li[2]<=0:
      print('Yes')
  li[0]=li[0]-li[3]
   if li[0]<=0:
      print('No')

Buggy submission (verdict: Runtime Error):
li=[input() for i in range(4)]

while ((li[0]>0) and (li[2]>0)):
  li[2]=li[2]-li[1]
   if li[2]<=0:
      print('Yes')
  li[0]=li[0]-li[3]
   if li[0]<=0:
      print('No')
Problem p04044 (python)

Fixed submission:
n,l=map(int,input().split())
li=[input() for i in range(n)]

sortli=sorted(li)
print(''.join(sortli))

Buggy submission (verdict: Runtime Error):
n,l=map(int,input().split())
li=[input() for i in range(n)]

sortli=sorted(li)
print("{}{}{}".format(sortli[0],sortli[1],sortli[2]))
Problem p02630 (python)

Fixed submission:
import collections
N = int(input())
D = [0]*100001
A = list(map(int, input().split()))
a = sum(A)
for j in A:
    D[j] += 1
Q = int(input())
start = sum(A)
for i in range(Q):
    x,y=[int(i) for i in input().split()]
    a += D[x]*(y-x)
    print(a)
    D[y] +=D[x]
    D[x] = 0

Buggy submission (verdict: Runtime Error):
import collections
N = int(input())
D = [0]*100000
A = list(map(int, input().split()))
a = sum(A)
for j in A:
    D[j] += 1
Q = int(input())
start = sum(A)
for i in range(Q):
    x,y=[int(i) for i in input().split()]
    a += D[x]*(y-x)
    print(a)
    D[y] +=D[x]
    D[x] = 0
Problem p02690 (python)

Fixed submission:
X = int(input())
for i in range (240):
    for j in range (240):
        s = (i -120)**5 - (j -120)**5
        if s == X:
            A = i-120
            B = j -120
print(A,B)

Buggy submission (verdict: Runtime Error):
X = int(input())
A = 1
K = 1
while K < X:
    A += 1
    K = A ** 5
w = 0
while w != 1:
    P = S ** 5
    Q = P - X
    B = 0
    while (Q < B**5):
        B += 1
    if (Q == B**5):
        w += 1
    else:
        S += 1

        
print(S,B)
Problem p02696 (python)

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

if N>B:
    x = B -1
else:
    x = N
D = []

if N > 20:
    w = N % 15 + 5
elif N > 4:
    w = N-1
else:
    w = N
for i in range(w):
    F1 = (A*(x-i))//B
    F2 = A * ((x-i)//B)
    S = F1 - F2
    D.append(S)

ans = max(D)
print(ans)

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

if N>B:
    x = B -1
else:
    x = N
D = []

if N > 10:
    w = N % 10
else:
    w = N-1
for i in range(w):
    F1 = (A*(x-i))//B
    F2 = A * ((x-i)//B)
    S = F1 - F2
    D.append(S)

ans = max(D)
print(ans)

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

if N>B:
    x = B -1
else:
    x = N
D = []

for i in range(N//2):
    F1 = (A*(x-i))//B
    F2 = A * ((x-i)//B)
    S = F1 - F2
    D.append(S)

ans = max(D)
print(ans)
Problem p02732 (python)

Fixed submission:
import collections
N = int(input())
A = list(map(int , input().split()))
a = collections.Counter(A)
k = 0
def comb(n):
    return n * (n - 1) // 2
for j in a.values():
    k += comb(j)
    
for i in range(N):
    s = A[i]
    p = a[s]
    print(int(k - p + 1))

Buggy submission (verdict: Runtime Error):
import collections
N = int(input())
A = list(map(int , input().split()))
a = collections.Counter(A)
S = len(a)
k = 0
for j in range (S):
    b = a.most_common()[j][1]
    if b > 1:
        k += b * (b-1)/2
    

for i in range(N):
    s = A[i]
    p = a[s]
    print(int(k - q)

Buggy submission (verdict: Runtime Error):
import collections
N = int(input())
A = list(map(int , input().split()))
a = collections.Counter(A)
for i in range(N):
    K =[]
    K.extend(A)
    K.pop(i)
    a = collections.Counter(K)
    S = len(list(set(K)))
    k = 0
    for j in range (S):
        b =a.most_common()[j][1]
        k = b * (b-1)/2 + k
    print(int(k))
    K.clear()
    K.extend(A)
Problem p02743 (python)

Fixed submission:
a,b,c = list(map(int , input().split()))
x = c - a - b
X = x ** 2
Y = a * b * 4
Z = X - Y
if Z > 0 and x > 0:
    print("Yes")
else:
    print("No")

Buggy submission (verdict: Runtime Error):
import math
a,b,c = list(map(int , input().split()))
A = math.sqrt(a)
B = math.sqrt(b)
C = math.sqrt(C)
sahen = A + B
if sahen < C:
    print("Yes")
else:
    print("No")
Problem p02953 (python)

Fixed submission:
N = int(input())
A = list(map(int,input().split()))
ans = 0
for i in range(N-1):
  if ans > A[i+1]:
    print('No')
    exit()
  if A[i+1]-A[i] >= -1:
    ans = max(A[i+1]-1,A[i]-1,ans)
    if A[i+1] >= A[i] and A[i+1] > ans :
      A[i+1] -=1
  else:
    print('No')
    exit()
print('Yes')

Buggy submission (verdict: Runtime Error):
N = int(input())
A = list(map(int, input().split()))
A.reverse()
if N == 1:
    print("Yes")
else:
    k = 0
    for i in range (N-1):
        if A[i] < A[1+i]:
            if (A[1+i] - A[i]) == 1:
                A[i+1] -= 1
            else:
                break
if i != (N-2):
    print("No")
else:
    print("Yes")

Buggy submission (verdict: Runtime Error):
N = int(input())
A = list(map(int, input().split()))
if N == 1:
    print("Yes")
else:
    k = 0
    for i in range (N-1):
        if A[-(1 + i)] < A[-(2 + i)]:
            if (A[-(2 + i)] - A[-(1 + i)]) == 1:
                A[-(2 + i)] -= 1
            else:
                k = 114514
if k == 114514:
    print("No")
else:
    print("Yes")

Buggy submission (verdict: Runtime Error):
N = int(input())
A = list(map(int, input().split()))
if N == 1:
    print("Yes")
else:
    k = 0
    for i in range (N-1):
        if A[N-(1 + i)] < A[N-(2 + i)]:
            if (A[N-(2 + i)] - A[N-(1 + i)]) == 1:
                A[N-(2 + i)] -= 1
            else:
                k = 114514
if k == 114514:
    print("No")
else:
    print("Yes")

Buggy submission (verdict: Runtime Error):
N = int(input())
A = list(map(int, input().split()))
if N == 1:
    print("Yes")
else:
    k = 0
    for i in range (N-1):
        if A[N-(1 + i)] < A[N-(2 + i)]:
            if (A[N-(2 + i)] - A[N-(1 + i)]) == 1:
                A[N-(2 + i)] -= 1
            else:
                k = 114514
                break
if k == 114514:
    print("No")
else:
    print("Yes")

Buggy submission (verdict: Runtime Error):
N = int(input())
A = list(map(int, input().split()))
if N == 1:
    print("Yes")
else:
    k = 0
    for i in range (N-1):
        if A[N-1 -i] < A[N-2-i]:
            if (A[N-2-i] - A[N-1-i]) == 1:
                A[N-2-i] -= 1
            else:
                k = 114514
                break
if k == 114514:
    print("No")
else:
    print("Yes")
Problem p02958 (python)

Fixed submission:
N = int(input())
A = list(map(int, input().split()))
B = sorted(A)
k = 0
for i in range (N):
    if B[i] != A[i]:
        k += 1
if k >= 3:
    print("NO")
else:
    print("YES")

Buggy submission (verdict: Runtime Error):
N = int(input())
A = list(map(int, input().split()))
B = sorted(A)
for i in range (N):
    if B[i] != A[i]:
        k += 1
if k >= 3:
    print("NO")
else:
    print("YES")
Problem p03151 (python)

Fixed submission:
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
k = 0
s = 0
m = []
l = 0
if sum(B)<=sum(A):
    for i in range(N):
        if A[i] < B[i]:
            k += 1
            s += (B[i]- A[i])
        elif A[i] > B[i]+1:
            m.append(A[i]- B[i])
        elif A[i] == B[i]+1:
            l += (A[i]- B[i])
    if len(m)>1:
        n = sorted(m,reverse = True)
    else:
        n = m
    for j in range(len(m)):
        if s > 0:
            s -= n[j]
            k += 1
        if s <0:
            break
    if (s > 0) and(k > 0):
         k += s
else:
    k = -1
print(k)

Buggy submission (verdict: Runtime Error):
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
k = 0
s = 0
m = []
l = 0
if sum(B)<=sum(A):
    for i in range(N):
        if A[i] < B[i]:
            k += 1
            s += (B[i]- A[i])
        elif A[i] > B[i]+1:
            m.append(A[i]- B[i])
        elif A[i] == B[i]+1:
            l += (A[i]- B[i])
    if len(m)>1:
        n = sorted(m,reverse = True)
    for j in range(len(m)):
        if s > 0:
            s -= n[j]
            k += 1
        if s <0:
            break
    if (s > 0) and(k > 0):
         k += s
else:
    k = -1
print(k)

Buggy submission (verdict: Runtime Error):
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
k = 0
s = 0
m = []
l = 0
if sum(B)<=sum(A):
    for i in range(N):
        if A[i] < B[i]:
            k += 1
            s += (B[i]- A[i])
        elif A[i] > B[i]+1:
            m.append(A[i]- B[i])
        elif A[i] == B[i]+1:
            l += (A[i]- B[i])
    if len(m)>1:
        n = sorted(m,reverse = True)
    for j in range(len(m)):
        if s > 0:
            s -= n[j]
            k += 1
        if s <0:
            break
    if (s > 0) and(k > 0):
         k += s
else:
    print(-1)
print(k)

Buggy submission (verdict: Runtime Error):
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
k = 0
s = 0
m = []
l = 0
if sum(B)<=sum(A):
    for i in range(N):
        if A[i] < B[i]:
            k += 1
            s += (B[i]- A[i])
        elif A[i] > B[i]+1:
            m.append(A[i]- B[i])
        elif A[i] == B[i]+1:
            l += (A[i]- B[i])
    n = soeted(m,reverse = True)
    for j in range(len(m)):
        if s > 0:
            s -= n[j]
            k += 1
        if s <0:
            break
    if (s > 0) and(k > 0):
         k += s
else:
    print(-1)
print(k)
Problem p03945 (python)

Fixed submission:
S = list(input())
if len(list(set(S))) != 1:
    i =0
    count = 0
    while True:
        if S[i] != S[i+1]:
            count += 1
            S[i] = S[i + 1]
        i += 1
        if i == (len(S)-1):
            break
else:
    count = 0
print(count)

Buggy submission (verdict: Runtime Error):
S = list(input())
if len(list(set(S))) != 0:
    i =0
    count = 0
    while True:
        if S[i] != S[i+1]:
            count += 1
            S[i] = S[i + 1]
        i += 1
        if i == (len(S)-1):
            break
else:
    count = 0
print(count)

Buggy submission (verdict: Runtime Error):
S = list(input())
if len(list(set(S))) != 0:
    i =0
    count = 0
    while True:
        if S[i] != S[i+1]:
            count += 1
            S[i] = S[i + 1]
        i += 1
        if i == (len(S)-1):
            break
print(count)
Problem p03997 (python)

Fixed submission:
a = int(input())
b = int(input())
h = int(input())
k = (a + b)* h /2
print(round(k))

Buggy submission (verdict: Runtime Error):
a = int(input())
b = int(input())
h = int(input())
k = (a + b)* h /2
print(round(k)
Problem p02556 (python)

Fixed submission:
n = int(input())

z = []
w = []
for i in range(n):
    x, y = map(int, input().split())
    z.append(x + y)
    w.append(x - y)
z.sort()
w.sort()
print(max(z[-1]-z[0], w[-1]-w[0]))

Buggy submission (verdict: Runtime Error):
n = int(input())
w = []
for i in range(n):
    x, y = map(int, input().split())
    z.append(x + y)
    w.append(x - y)
z.sort()
w.sort()
print(max(z[-1]-z[0], w[-1]-w[0]))
Problem p02630 (python)

Fixed submission:
t=int(input())
import math
a=list(map(int,input().strip().split()))
q=int(input())
h=[0]*(1000000+1)
sumi=0
for i in range(len(a)):
    h[a[i]]+=1
    sumi+=a[i]
 
for i in range(q):
    b,c=map(int,input().strip().split())
    #print(h)
    sumi+=h[b]*(c-b)
    h[c]+=h[b]
    h[b]=0
    #print(h)
    print(sumi)
        
        
        
    #a=list(map(int,input().strip().split()))

Buggy submission (verdict: Runtime Error):
t=int(input())
for i in range(t):
  a=list(map(int,input().strip().split()))
  q=int(input())
  for i in range(q):
    m,n=map(int,input().strip().split())
    for i in range(len(a)):
      if a[i]==m:
        a[i]=n
    print(sum(a))
Problem p02791 (python)

Fixed submission:
n=int(input())
p=list(map(int, input().split()))
ans=0
m=p[0]
for i in p:
  if i<=m:
    m=i
    ans+=1
print(ans)

Buggy submission (verdict: Runtime Error):
n=int(input())
p=list(map(int, input().split()))
def chk(i, cnt, m):
  if p[i]==1:
    return cnt+1
  elif i==n-1: 
    return cnt
  else:
    if p[i]<=m:
      return chk(i+1, cnt+1, p[i])
    else:
      return chk(i+1, cnt, m)
if p[0]==1:
  print(1)
else:
  print(chk(1, 1, p[0]))

Buggy submission (verdict: Runtime Error):
n=int(input())
p=list(map(int, input().split()))
def chk(i, cnt, m):
  if p[i]==1:
    return cnt+1
  elif i==n-1: 
    return cnt
  else:
    if p[i]<m:
      return chk(i+1, cnt+1, p[i])
    else:
      return chk(i+1, cnt, m)
if p[0]==1:
  print(1)
else:
  print(chk(1, 1, p[0]))
Problem p02971 (python)

Fixed submission:
n=int(input())
l=[]
for _ in range(n):
  l.append(int(input()))
m=max(l)
mc=l.count(m)
tin=set(l)
if len(tin)==1:
  s=m
else:
  s=sorted(tin)[-2]
for i in l:
  if i==m:
    if mc>1:
      print(m)
    else:
      print(s)
  else:
    print(m)

Buggy submission (verdict: Runtime Error):
n=int(input())
l=[]
for _ in range(n):
  l.append(int(input()))
m=max(l)
mc=l.count(m)
s=sorted(set(l))[-2]
for i in l:
  if i==m:
    if mc>1:
      print(m)
    else:
      print(s)
  else:
    print(m)
Problem p03103 (python)

Fixed submission:
n, m=map(int, input().split())
l=[]
for i in range(n):
  l.append(list(map(int, input().split())))
l = sorted(l, reverse=False)  
#print(l)
drinks=0
ttl=0
add=0
for i in range(n):
  add=min(m-drinks, l[i][1])
  ttl=ttl+add*l[i][0]
  drinks+=add
  if drinks==m:
    print(ttl)
    exit()

Buggy submission (verdict: Runtime Error):
n, m=map(int, input().split())
l=[]
for i in range(n):
  l.append(list(map(int, input().split())))
l = sorted(l, reverse=False)  
print(l)
def fns(hon, n, mon):
  if hon==m:
    return mon
  elif hon>m:
    return mon-(hon-m)*l[n-1][0]
  else:
    return fns(hon+l[n][1], n+1, mon+l[n][1]*l[n][0])
print(fns(0, 0, 0))

Buggy submission (verdict: Runtime Error):
n, m=map(int, input().split())
#for i in range(n):
l=[]

for i in range(n):
  l.append(list(map(int, input().split())))
l = sorted(l, reverse=False)  
def fns(hon, n, mon):
  if hon==m:
    return mon
  elif hon>m:
    return mon-(hon-m)*l[n-1][0]
  else:
    return fns(hon+l[n][1], n+1, mon+l[n][1]*l[n][0])
print(fns(0, 0, 0))
Problem p03080 (python)

Fixed submission:
N = int(input())
S = input()

red = 0
blue = 0
for s in S:
    if s == 'R':
        red = red+1
    else:
        blue = blue+1

if red > blue:
    print('Yes')
else:
    print('No')

Buggy submission (verdict: Runtime Error):
N = int(input())
S = input()

red = 0
blue = 0
for s in S:
    if s == 'R':
        red++
    else:
        blue++

if red > blue:
    print('Yes')
else
    print('No')
Problem p03695 (python)

Fixed submission:
N = int(input())
a = list(map(int, input().split()))
colors = [0]*9
for i in a:
    idx = i//400
    if(idx > 8):
        idx = 8
    colors[idx] += 1
ans = 0
for i in colors[0:8]:
    if i != 0:
        ans += 1
if ans == 0:
    print(1, colors[8])
else:
    print(ans, ans+colors[8])

Buggy submission (verdict: Runtime Error):
N = int(input())
a = list(map(int, input().split()))
colors = [0]*9
for i in a:
    colors[i//400] += 1
ans = 0
for i in colors[0:8]:
    if i != 0:
        ans += 1
print(ans, ans+colors[8])
Problem p02556 (python)

Fixed submission:
n = int(input())
c = []
for _ in range(n):
    c.append(list(map(int,input().split())))

ans = 0
a = 100000000000000
m = 0
lm = 0
rm = 0
lt  = []
rt  = []
lb = []
rb = []

for l in c:
    m = max(m,l[0]+l[1])
    a = min(a,l[0]+l[1])
    if l[0] > l[1]:
        rm = max(rm,l[0]-l[1])
    if l[0] < l[1]:
        lm = max(lm,l[1]-l[0])

for l in c:
    if l[0] + l[1] == m:
        rt.append(l)
    if l[0] + l[1] == a:
        lb.append(l)
    if l[0] > l[1] and l[0] - l[1] == rm:
        rb.append(l)
    if l[0] < l[1] and l[1] - l[0] == lm:
        lt.append(l)


if len(lt)>0 and len(rb) > 0:
    i = lt[0]
    j = rb[0]
    ans = max(ans,abs(i[0]-j[0])+abs(i[1]-j[1]))

if len(rt)>0 and len(lb) > 0:
    i = rt[0]
    j = lb[0]
    ans = max(ans,abs(i[0]-j[0])+abs(i[1]-j[1]))
print(ans)

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

ans = 0
a = 100000000000000
m = 0
lm = 0
rm = 0
lt  = []
rt  = []
lb = []
rb = []

for l in c:
    m = max(m,l[0]+l[1])
    a = min(a,l[0]+l[1])
    if l[0] > l[1]:
        rm = max(rm,l[0]-l[1])
    if l[0] < l[1]:
        lm = max(lm,l[1]-l[0])

for l in c:
    if l[0] + l[1] == m:
        rt.append(l)
    if l[0] + l[1] == a:
        lb.append(l)
    if l[0] > l[1] and l[0] - l[1] == rm:
        rb.append(l)
    if l[0] < l[1] and l[1] - l[0] == lm:
        lt.append(l)


if lt is not None and rb is not None:
    i = lt[0]
    j = rb[0]
    ans = max(ans,abs(i[0]-j[0])+abs(i[1]-j[1]))

if rt is not None and lb is not None:
    i = rt[0]
    j = lb[0]
    ans = max(ans,abs(i[0]-j[0])+abs(i[1]-j[1]))
print(ans)
Problem p02584 (python)

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

c = x//d

a = x - x//d * d
b = d - abs(a)

if x//d%2 == 0:
    odd = a
    even = b
else:
    odd = b
    even = a

if abs(x//d) > k:
    ans = abs(abs(x) - abs(d*k))
else:
    if k%2 ==0:
        ans = odd
    else:
        ans = even

# print(odd,even)
print(abs(ans))

Buggy submission (verdict: Runtime Error):
x, k , d = map(int, input().split())
l = []

ans = 0

if x > 0:
    for i in range(x,-x,-d):
        l.append(i)
        if i < 0:
            break

else:
    for i in range(x,-x,d):
        l.append(i)
        if i > 0:
            break
    

if len(l)-1 > k:
    ans = l[k]
else:
    if len(l)%2 ==0:
        odd = l[len(l)-1]
        even = l[len(l)-2]
    else :
        odd = l[len(l)-2]
        even = l[len(l)-1]
    if k%2 == 0:
        ans = even
    else:
        ans = odd

print(abs(ans))
Problem p02642 (python)

Fixed submission:
n = int(input())
A = list(map(int,input().split()))
 
maxA = max(A)
ans = 0
flag = [0]*(maxA+1)
 
# print(flag)
for a in A:
    for ax in range(a,maxA+1,a):
        flag[ax] +=1
 
# print(flag)
for a in set(A):
    if flag[a] == 1:
        ans += 1
print(ans)

Buggy submission (verdict: Runtime Error):
n = int(input())
a = [int(i) for i in input().split()]


l = [0] * max(a)


for i in a:

    c = 2
    while True:
        if i*c-1 >= max(a):
            break
        l[i*c - 1] += 1
        c += 1



ans = 0

for i in set(a):
    if l[i] == 1:
        ans += 1

print(ans)

Buggy submission (verdict: Runtime Error):
n = int(input())
a = [int(i) for i in input().split()]


l = [0] * 1000000


for i in a:

    c = 2
    while True:
        l[i*c - 1] = 1
        c += 1
        if i*c-1 >= 1000000:
            break
sa = sorted(a)
ans = 0

for i in range(len(sa)):
    if l[sa[i]-1] == 0 and sa[i-1] != sa[i]:
        if i != 0:
            ans += 1
        else:
            if sa[i+1] != sa[i]: ans += 1 

print(ans)

Buggy submission (verdict: Runtime Error):
n = int(input())
a = [int(i) for i in input().split()]


l = [0] * 1000000


for i in a:

    c = 2
    while True:
        l[i*c - 1] = 1
        c += 1
        if i*c-1 >= 1000000:
            break
sa = sorted(a)
ans = 0

for i in range(len(sa)):
    if l[sa[i]-1] == 0 and sa[i-1] != sa[i]:
        if not(i == 0 and sa[i+1] == sa[i]):
            ans += 1


print(ans)