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

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

new = ""
for i in range(len(s) - 1):
  diff = (123 - ord(s[i])) % 26
  if diff <= K:
    K -= diff
    new += "a"
  else:
    new += s[i]

if K > 0:
  new_char = ord(s[-1]) + (K % 26)
  if new_char > 122:
    new_char = 96 + (new_char - 122)
  new += chr(new_char)
else:
  new += s[-1]

print(new)

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

new = ""
for i in range(len(s) - 1):
  diff = 26 - (ord(s[i]) - 97)
  if diff <= K:
    K -= diff
    new += "a"
  else:
    new += s[i]

if K > 0:
  new_char = ord(s[-1]) + K
  if new_char > 122:
    new_char = 96 + (new_char - 122)
  new += chr(new_char)
else:
  new += s[-1]

print(new)

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

new = ""
for i in range(len(s) - 1):
  diff = 123 - ord(s[i])
  if diff < K:
    K -= diff
    new += "a"
  else:
    new += s[i]

if K > 0:
  new_char = ord(s[-1]) + K
  if new_char > 122:
    new_char = 96 + (new_char - 122)
  new += chr(new_char)
else:
  new += s[-1]

print(new)
Problem p03029 (python)

Fixed submission:
x, y = [int(i) for i in input().split()]
print(int((x*3+y)/2))

Buggy submission (verdict: Runtime Error):
x = int(input())
y = int(input())
print(int((x*3+y)/2))
Problem p02719 (python)

Fixed submission:
N,K = map(int,input().split())
r = N%K
s = K-r
print(min([r,s]))

Buggy submission (verdict: Runtime Error):
N,K = map(int,input().split())
r = N%K
s = K-r
print(min[r,s])

Buggy submission (verdict: Runtime Error):
N,K = map(int,input().split())
r = N%K
s = s-r
print(min[r,s])
Problem p02801 (python)

Fixed submission:
x = input()
l = [chr(i) for i in range(97, 97+26)]

for i in range(26):
    if l[i]== x:
        k = i
        
print(l[k+1])

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

A = []

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

S = sum(A)
Score = M * N

n = Score - S

if n >=0 and n <= 100:
    print(n)
elif n > 100:
    print('-1')
else:
    print(0)

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

A = []

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

S = sum(A)
Score = M * N

n = Score - S

if n >=0 and n < 100:
    print(n)
elif n >= 100:
    print('-1')
else:
    print(0)
Problem p03029 (python)

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

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

Fixed submission:
str=input()
x=len(str)
if x==2:
   print(str)
else:
   print(str[::-1])

Buggy submission (verdict: Runtime Error):
str=input()
x=len(str)
if x=2:
  print(str)
else:
  print(str[::-1])
Problem p02658 (python)

Fixed submission:
def f(n, a):
  if 0 in a:
    return 0
  p = 1
  for x in a:
    p *= x
    if p > 10**18:
      return -1
  return p
 
n = int(input())
a = list(map(int, input().split()))
print(f(n, a))

Buggy submission (verdict: Runtime Error):
def f(n, a):
  if 0 in a:
    return 0
  p = 1
  for x in a:
    p *= x
    if p > 10**18:
      return -1
  return p

n = int(input())
a = list(int, input().split())
print(f(n, a))
Problem p02743 (python)

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

Buggy submission (verdict: Runtime Error):

if 4*a*b < (c-a-b) ** 2 and c-a-b > 0:
  print("Yes")
else:
  print("No")
Problem p02783 (python)

Fixed submission:
h,a = tuple(map(int,input().rstrip().split()))
print((h+a-1)//a)

Buggy submission (verdict: Runtime Error):
h,a = tuple(map(int,input().rstrip().sprit()))
print((h+a-1)//a)

Buggy submission (verdict: Runtime Error):
h,a = tuple(map(int,input().rstrip().sprit()))
print((h+a-1)//a)
Problem p02787 (python)

Fixed submission:
def dp(H, N, ab):
  max_a = max([ab[i][0] for i in range(N)])
  d = [INF for _ in range(H + max_a)]
  d[0] = 0
  for h in range(1, H + max_a):
    d[h] = min(d[h - a] + b for a, b in ab)
  return min(d[H:])
INF = 10 ** 10
H, N = map(int, input().split())
ab = [tuple(map(int, input().split())) for _ in range(N)]
print(dp(H, N, ab))

Buggy submission (verdict: Runtime Error):
def mincost(h, m, i):
  if i == len(m) - 1:
    return (1 + (h - 1) // m[i][0]) * m[i][1]
  return min((1 + (h - 1) // m[i][0]) * m[i][1],
            mincost(h % m[i][0], m, i+1))

h, n = list(map(int, input().rstrip().split()))
m = [tuple(map(int, input().rstrip().split())) for _ in range(n)]

m.sort(key = lambda x: x[0])
m.sort(key = lambda x: x[0] / x[1], reversed = True)

print(mincost(h, m, 0))
Problem p02848 (python)

Fixed submission:
arphs = list("ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZ")
n = int(input())
s = list(input())
i = []
for x in s:
  i.append(arphs[arphs.index(x) + n])
print("".join(i))

Buggy submission (verdict: Runtime Error):
arphs = list(ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZ)
n = int(input())
s = list(input())
i = []
for x in s:
  i.append(arphs.index(x) + n)
print("".join(i))
Problem p02741 (python)

Fixed submission:
arr = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]
k = int(input())
print(arr[k-1])

Buggy submission (verdict: Runtime Error):
arr = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]
k = int(input())
print(arr[k+1])
Problem p03086 (python)

Fixed submission:
def change(c):
  if c in atcg:
    return "1"
  else:
    return "0"
  
s = input()
atcg = "ATCG"
s = "".join([change(i) for i in s])
print(max([len(i) for i in s.split("0")]))

Buggy submission (verdict: Runtime Error):
s = input()
atcg = ["A", "T", "C", "G"]
index = []
for i in range(len(s)-1):
  if s[i] not in atcg:
    index.append(i)

max = index[0]
for i in range(1, len(index), 1):
  if index[i] - index[i-1] - 1> max:
    max = index[i] - index[i-1] - 1 
print(max)

Buggy submission (verdict: Runtime Error):
s = input()
atcg = ["A", "T", "C", "G"]

max = 0
for i in range(len(s)-1):
  j = i
  while s[j] in atcg:
    if max <= j - i + 1:
      max = j - i + 1
    j += 1
      
print(max)
Problem p03106 (python)

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

l = [1]
for i in range(2, min(a, b) + 1, 1):
  if a % i == 0 and b % i == 0:
    l.append(i)

print(l[-k])

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

l = [1]
for i in range(2, min(a, b), 1):
  if a % i == 0 and b % i == 0:
    l.append(i)

print(l[k-1])
Problem p03160 (python)

Fixed submission:
n = int(input())
h = [int(i) for i in input().split(" ")]

dp = [0] * n
dp[1] = abs(h[1] - h[0])

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

print(dp[n-1])

Buggy submission (verdict: Runtime Error):
def culc(i, dp, h, n):
  if i == n - 1 :
    return dp[n - 1]
  
  cost1 = abs(h[i - 1] - h[i + 1])
  cost2 = abs(h[i] - h[i + 1])
  
  dp.append(dp[i - 1] + cost1 if cost1 <= cost2 else dp[i] + cost2)
  return culc(i + 1, dp, h, n)
    

n = int(input())
h = [int(i) for i in input().split(" ")]

dp = [0, abs(h[0] - h[1])]
print(culc(1, dp, h, n))

Buggy submission (verdict: Runtime Error):
def culc(i, dp, h, n):
  if i == n - 1 :
    return dp[n - 1]
  
  cost1 = abs(h[i - 1] - h[i + 1])
  cost2 = abs(h[i] - h[i + 1])
  
  dp.append(dp[i - 1] + cost1 if cost1 <= cost2 else dp[i] + cost2)
  return culc(i + 1, dp, h, n)
    

n = int(input())
h = [int(i) for i in input().split(" ")]

dp = [0, abs(h[0] - h[1])]
print(culc(1, dp, h, n))
Problem p02642 (python)

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

mx=max(A)
f=[True]*(mx+1)
chk=[0]*(mx+1)

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

for a in A:
    cnt=2
    while a*cnt<=mx:
        f[a*cnt]=False
        cnt+=1
ans=0
for a in A:
    if f[a]==True and chk[a]<=1:
        ans+=1
print(ans)

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

A=list(set(A))

L=len(A)

if L==1:
    print(0)
    exit()

mx=max(A)

f=[1]*L

A.sort()

for i in range(N):
    if A[i]*2>mx:break
    for j in range(i+1,N):
        if A[j]%A[i]==0:
            f[j]=0

print(sum(f))
Problem p02727 (python)

Fixed submission:
X,Y,A,B,C=map(int,input().split())

RO=list(map(int,input().split()))
GO=list(map(int,input().split()))
TO=list(map(int,input().split()))

RO.sort()
GO.sort()

R=RO[A-X:A]
G=GO[B-Y:B]

TO.extend(R)
TO.extend(G)

TO.sort(reverse=True)

T=TO[0:X+Y]

print(sum(T))

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

RO=list(map(int,input().split()))
GO=list(map(int,input().split()))
TO=list(map(int,input().split()))

RO.sort()
GO.sort()
TO.sort(reverse=True)

R=RO[A-X:A]
G=GO[B-Y:B]
ans=sum(R)+sum(G)

idxR=0
idxG=0
for i in range(C):
    t=TO[i]
    if idxR<A and idxG<B:
        mi=min(R[idxR],G[idxG],t)
        if mi==t:break
        elif mi==R[idxR]:
            ans=ans-R[idxR]+t
            idxR+=1
        elif mi==G[idxG]:
            ans=ans-G[idxG]+t
            idxG+=1
    elif idxR>=A and idxG<B:
        mi=min(G[idxG],t)
        if mi==t:break
        else:
            ans=ans-G[idxG]+t
            idxG+=1
    elif idxR<A and idxG>=B:
        mi=min(R[idxR],t)
        if mi==t:break
        else:
            ans=ans-R[idxR]+t
            idxR+=1
    elif idxR>=A and idxG>=B:break
print(ans)

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

RO=list(map(int,input().split()))
GO=list(map(int,input().split()))
TO=list(map(int,input().split()))

RO.sort()
GO.sort()
TO.sort(reverse=True)

R=RO[A-X:A]
G=GO[B-Y:B]
ans=sum(R)+sum(G)

idxR=0
idxG=0
for t in TO:
    if idxR<A and idxG<B:
        mi=min(R[idxR],G[idxG],t)
        if mi==t:break
        elif mi==R[idxR]:
            ans=ans-R[idxR]+t
            idxR+=1
        elif mi==G[idxG]:
            ans=ans-G[idxG]+t
            idxG+=1
    elif idxR>=A and idxG<B:
        mi=min(G[idxG],t)
        if mi==t:break
        else:
            ans=ans-G[idxG]+t
            idxG+=1
    elif idxR<A and idxG>=B:
        mi=min(R[idxR],t)
        if mi==t:break
        else:
            ans=ans-R[idxR]+t
            idxR+=1
    elif idxR>=A and idxG>=B:break
print(ans)
Problem p02787 (python)

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

A=[]
B=[]

for i in range(N):
    a,b=map(int,input().split())
    A.append(a)
    B.append(b)

DP=[[1000000000]*(H+max(A)+1) for i in range(N+1)]


for i in range(N):
    DP[i+1][A[i]]=B[i]


for i in range(N):
    for h in range(H+max(A)+1):
        DP[i+1][h]=min(DP[i+1][h],DP[i][h])
        if h-A[i]>=0:
            DP[i+1][h]=min(DP[i+1][h-A[i]]+B[i],DP[i+1][h])

print(min(DP[N][H:]))

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

A=[]
B=[]
DP=[10000000000]*(H+1)
DP[0]=0
for i in range(N):
    a,b=map(int,input().split())
    A.append(a)
    B.append(b)
    DP[a]=b



minA=A[A.index(min(A))]
minB=B[B.index(min(B))]

for i in range(1,A.index(min(A))):
    DP[i]=minB

for i in range(A.index(min(A)),H+1):
    temp=[]
    for j in range(i+1):
        temp.append(DP[j]+DP[i-j])
    DP[i]=min(temp)

print(DP[H])

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

A=[]
B=[]
DP=[10000000000]*(H+1)
DP[0]=0
for i in range(N):
    a,b=map(int,input().split())
    A.append(a)
    B.append(b)
    DP[a]=b



minA=A[A.index(min(A))]
minB=B[B.index(min(B))]

for i in range(1,A.index(min(A))):
    DP[i]=minB

for i in range(A.index(min(A)),H+1):
    temp=[]
    for j in range(i//2+1):
        temp.append(DP[j]+DP[i-j])
    DP[i]=min(temp)

print(DP[H])
Problem p02817 (python)

Fixed submission:
S,T=map(str,input().split())
print(T+S)

Buggy submission (verdict: Runtime Error):
S=input()
T=input()
print(T+S)
Problem p02843 (python)

Fixed submission:
X=int(input())

t=X//100

if 100*t<=X<=105*t:
    print(1)
else:
    print(0)

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

DP=[False]*(X+1)

for i in range(100,106):
    DP[i]=True

for i in range(106,X+1):
    if DP[i-100] or DP[i-101] or DP[i-102] or DP[i-103] or DP[i-104] or DP[i-105]:
        DP[i]=True

if DP[X]==True:
    print(1)
elif DP[X]==False:
    print(0)
Problem p02900 (python)

Fixed submission:
def div(N):
    ans = []
    for i in range(1, int(N ** 0.5) + 1):
        if N % i == 0:
            ans.append(i)
            if N // i != i:
                ans.append(N // i)
    ans.sort()
    return ans
import fractions

A,B=map(int,input().split())

g=fractions.gcd(A,B)

if g==1:
    print(1)
    exit()
cnt=0
di=div(g)

for i in di:
    f=True
    for j in range(2,int(i**0.5)+1):
        if i%j==0:
            f=False
            break
    if f:
        cnt+=1
print(cnt)

Buggy submission (verdict: Runtime Error):
def div(N):
    ans = []
    for i in range(1, int(N ** 0.5) + 1):
        if N % i == 0:
            ans.append(i)
            if N // i != i:
                ans.append(N // i)
    ans.sort()
    return ans
import math

A,B=map(int,input().split())

g=math.gcd(A,B)

if g==1:
    print(1)
    exit()
cnt=0
for i in range(2,g+1):
    if g%i==0:
        cnt+=1
        g=g//i
        while g%i==0:
            g=g//i
print(cnt+1)

Buggy submission (verdict: Runtime Error):
def PrimeNumber(N):
    if N==2:
        ans=[2]
        return ans
    ans = list(range(2, N + 1))
    i = 0
    while ans[i] < N ** 0.5 + 1:
        j = 2
        temp = ans[i]
        while temp * j <= ans[-1]:
            if temp * j in ans:
                ans.remove(temp * j)
            j += 1
        i += 1
    return ans

def div(N):
    ans = []
    for i in range(1, int(N ** 0.5) + 1):
        if N % i == 0:
            ans.append(i)
            if N // i != i:
                ans.append(N // i)
    ans.sort()
    return ans


import fractions

A,B=map(int,input().split())

g=fractions.gcd(A,B)

if g==1:
    print(1)
    exit()

d_list=[]
d_list=div(g)
PN=[1]
PN.extend(PrimeNumber(g))

cnt=0
for i in d_list:
    if i in PN:
        cnt+=1

print(cnt)
Problem p02903 (python)

Fixed submission:
H, W, A, B = map(int, input().split())

if A == 0 and B == 0:
    for i in range(H):
        ans = ["1"] * W
        print("".join(ans))
elif A == 0:
    for i in range(B):
        ans=[]
        temp = ["1"] * W
        ans.extend(temp)
        print("".join(ans))
    for i in range(H - B):
        ans=[]
        temp = ["0"] * W
        ans.extend(temp)
        print("".join(ans))
elif B == 0:
    for i in range(H):
        ans1=[]
        ans1 = ["1"] * A
        ans2 = ["0"] * (W - A)
        ans1.extend(ans2)
        print("".join(ans1))
else:
    for i in range(B):
        ans1 = ["1"]*A
        ans2=["0"]*(W-A)
        ans1.extend(ans2)
        print("".join(ans1))
    for i in range(H-B):
        ans1=["0"]*A
        ans2=["1"]*(W-A)
        ans1.extend(ans2)
        print("".join(ans1))

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

if A==0 and B==0:
    for i in range(H):
        ans=["1"]*W
        print("".join(ans))
        exit()
elif A==0:
    ans = ["1"] * W
    for i in range(B):
        print("".join(ans))
    ans=["0"]*W
    for i in range(H-B):
        print("".join(ans))
elif B==0:
    ans1 = ["1"] * A
    ans2 = ["0"] * (W - A)
    for i in range(H):
        ans1.extend(ans2)
        print("".join(ans1))
elif W%A==0 and H%B==0 and W//A==H//B:
    for j in range(H//B):
        ans=[]
        for i in range(W//A):
            if i==j:
                temp=["1"]*A
                ans.extend(temp)
            else:
                temp=["0"]*A
                ans.extend(temp)
        for k in range(B):
            print("".join(ans))
else:
    print("No")

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

if A==0 and B==0:
    for i in range(H):
        ans=["1"]*W
        print("".join(ans))
        exit()
elif A==0:
    ans = ["1"] * W
    for i in range(B):
        print("".join(ans))
    ans=["0"]*W
    for i in range(H-B):
        print("".join(ans))
elif B==0:
    ans1 = ["1"] * A
    ans2 = ["0"] * (W - A)
    for i in range(H):
        ans1.extend(ans2)
        print("".join(ans1))
elif W%A==0 and H%B==0:
    for j in range(H//B):
        ans=[]
        for i in range(W//A):
            if i==j:
                temp=["1"]*A
                ans.extend(temp)
            else:
                temp=["0"]*A
                ans.extend(temp)
        for k in range(B):
            print("".join(ans))
else:
    print("No")
Problem p02936 (python)

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

sys.setrecursionlimit(10**6)


N,Q=map(int,input().split())

A=[[] for i in range(N)]
c=[0]*N

for i in range(N-1):
    a,b=map(int,input().split())
    A[a-1].append(b-1)
    A[b-1].append(a-1)

for i in range(Q):
    p,x=map(int,input().split())
    c[p-1]+=x

def dfs(now,prev=-1):
    for next in A[now]:
        if next==prev:continue
        else:
            c[next]+=c[now]
            dfs(next,now)
dfs(0)
print(*c)

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

R=[[] for i in range(N)]
ans=[0]*N

for i in range(N-1):
    a,b=map(lambda x:int(x)-1,input().split())
    R[b].append(a)


c=[0]*N
for i in range(Q):
    p,x=map(int,input().split())
    c[p-1]+=x

ans=[0]*N

for i in range(N-1,-1,-1):
    tem=i
    while True:
        if tem==0:
            ans[tem]=c[0]
            break
        ans[i]+=c[R[tem][0]]
        tem=R[tem][0]


print(*ans)
Problem p02971 (python)

Fixed submission:
N = int(input())
A = [0]*N

for i in range(N):
    A[i] = int(input())

mx = max(A)
mxi = A.index(max(A))

for i in range(N):
    if i != mxi:
        print(mx)
    elif i == 0:
        print(max(A[1:N]))
    elif i == N-1:
        print(max(A[0:N-1]))
    else:
        print(max(max(A[0:i]),max(A[i+1:N])))

Buggy submission (verdict: Runtime Error):
 = int(input())
A = [0]*N

for i in range(N):
    A[i] = int(input())

mx = max(A)
mxi = A.index(max(A))

for i in range(N):
    
    if i != mxi:
        print(mx)
    elif i == 0:
        print(max(A[1:N]))
    elif i == N-1:
        print(max(A[mxi+1:N]))
    else:
        print(max(max(A[0:i]),max(A[i+1:N])))

Buggy submission (verdict: Runtime Error):
N = int(input())
A = [0]*N

for i in range(N):
    A[i] = int(input())

mx = max(A)
mxi = A.index(max(A))

for i in range(N):
    if i == 0:
        print(max(A[1:N]))
    elif i != mxi:
        print(mx)
    elif i == N-1:
        print(max(A[mxi+1:N]))
    else:
        print(max(max(A[0:i]),max(A[i+1:N])))
Problem p02972 (python)

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

b=[0]*(N+1)
M=0

for i in range(N,0,-1):
    cnt = 0

    for j in range(i+i,N+1,i):
        if b[j] == 1:
            cnt += 1

    if a[i-1]==1 and cnt%2==0:
        b[i]=1
        M+=1
    elif a[i-1]==0 and cnt%2==1:
        b[i]=1
        M+=1
        

print(M)
for i in range(1,N+1):
    if b[i]==1:
        print(i,end=" ")

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

b=[0]*(N+1)
PN=[2]
M=0

if a[0]==1:
    b[1]=1
    M+=1
if a[1]==1:
    b[2]=1
    M+=1
    b[4]=1
    M+=1

for i in range(3,N+1):
    if a[i-1]==1 and b[i]==0:
        b[i]=1
        M+=1
        for j in PN:
            if i%j==0:
                if i+j>N:
                    print(-1)
                    exit()
                else:
                    b[i+j]=1
                    M+=1
    if a[i-1]==0 and b[i]==1:
        if i+i>N:
            print(-1)
            exit()
        else:
            b[i+i]=1
        for j in PN:
            if i%j==0:
                if i+j>N:
                    print(-1)
                    exit()
                else:
                    b[i+j]=1
                    M+=1
    f=True
    for j in PN:
        if i%j==0:
            f=False
    if f==True:
        PN.append(i)

print(M)
for i in range(1,N+1):
    if b[i]==1:
        print(i,end=" ")
Problem p02995 (python)

Fixed submission:
import fractions

A, B, C, D = map(int, input().split())

x = fractions.gcd(C, D)
CD = x * (C // x) * (D // x)

Cm = B // C - (A - 1) // C
Dm = B // D - (A - 1) // D
CDm = B // CD - (A - 1) // CD

print(B + 1 - A - (Cm + Dm - CDm))

Buggy submission (verdict: Runtime Error):
import math

A, B, C, D = map(int, input().split())

x = math.gcd(C, D)
CD = x * (C // x) * (D // x)

Cm = B // C - (A - 1) // C
Dm = B // D - (A - 1) // D
CDm = B // CD - (A - 1) // CD

print(B + 1 - A - (Cm + Dm - CDm))
Problem p03006 (python)

Fixed submission:
N=int(input())

if N==1:
    print(1)
    exit()

P=[]
for i in range(N):
    P.append(list(map(int,input().split())))

c={}
for i in range(N):
    for j in range(N):
        if i!=j:
            p=P[j][0]-P[i][0]
            q=P[j][1]-P[i][1]
            temp=str(p)+"_"+str(q)
            if temp in c:
                c[temp]+=1
            else:
                c[temp]=1
c_num=[]
for j in c:
    c_num.append(c[j])

print(N-max(c_num))

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

P=[]
for i in range(N):
    P.append(list(map(int,input().split())))

c={}
for i in range(N):
    for j in range(N):
        if i!=j:
            p=P[j][0]-P[i][0]
            q=P[j][1]-P[i][1]
            temp=str(p)+"_"+str(q)
            if temp in c:
                c[temp]+=1
            else:
                c[temp]=1
c_num=[]
for j in c:
    c_num.append(c[j])

print(N-max(c_num))
Problem p03007 (python)

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

A.sort(reverse=True)
P=[]
M=[]

for i in A:
    if i<0:
        M.append(i)
    else:
        P.append(i)

ans=[]
if len(M)==0:
    if P[0]==0:
        print(0)
        for i in range(N-1):
            print(0,0)
        exit()
    else:
        x=P.pop()
        y=P.pop(0)
        ans.append([x,y])
        M.append(x-y)
if len(P)==0:
    x=M.pop(0)
    y=M.pop()
    ans.append([x,y])
    P.append(x-y)


for i in range(len(P)-1):
    y=P.pop()
    x=M.pop()
    ans.append([x,y])
    M.append(x-y)

for i in range(len(M)):
    y=M.pop()
    x=P.pop()
    ans.append([x,y])
    P.append(x-y)

print(P[0])

for x,y in ans:
    print(x,y)

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

A.sort(reverse=True)
P=[]
M=[]

for i in A:
    if i<0:
        M.append(i)
    else:
        P.append(i)
ans=[]
if len(M)==0:
    x=P.pop()
    y=P.pop()
    ans.append([x,y])
    M.append(x-y)
if len(P)==0:
    x=M.pop()
    y=M.pop()
    ans.append([x,y])
    P.append(x-y)


for i in range(len(P)-1):
    y=P.pop()
    x=M.pop()
    ans.append([x,y])
    M.append(x-y)

for i in range(len(M)):
    y=M.pop()
    x=P.pop()
    ans.append([x,y])
    P.append(x-y)

print(P[0])

for x,y in ans:
    print(x,y)