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

Fixed submission:
n = int(input())
arr = [int(x) for x in input().split()]
d = {}
for x in arr:
  d[x] = d.get(x,0)+1

mxN = 10**6 + 1
rp = [True]*mxN

if 1 in d:
  if d[1] > 1:
    print(0)
    exit()
  else:
    print(1)
    exit()
for i in range(2,len(rp)):
  if i not in d or not rp[i]:continue
  for j in range(i+i,mxN,i):
    if j in d: rp[j] = False

#reason for tle



for k,v in d.items():
  if v > 1:rp[k] = False

ans = sum([(1 if rp[x] else 0) for x in arr])
print(ans)

Buggy submission (verdict: Runtime Error):
n = int(input())
arr = [int(x) for x in input().split()]
d = {}
for x in arr:
  d[x] = d.get(x,0)+1

mxN = 10**6 + 1
rp = [True]*mxN


for i in range(2,len(rp)):
  if i not in d or not rp[i]:continue
  for j in range(i+i,mxN,i):
    if j in d: rp[j] = False

#reason for tle



for k,v in d.items():
  if v > 1:rp[k] = False

ans = sum([(1 if rp[x] else 0) for x in cset])
print(ans)
Problem p02801 (python)

Fixed submission:
x = input()
y = chr(ord(x) + 1)
print(y)

Buggy submission (verdict: Runtime Error):
x = input()
print(chr(ord(x)+1)
Problem p03030 (python)

Fixed submission:
a = []
n = int(input())

for i in range(1,n+1):
  name,score =input().split()
  a.append([name,-int(score),i])
  
a.sort()
for n,s,idx in a:
  print(idx)

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

for i in range(1,n+1):
  name,score = map(int,input().split())
  a.append([name,-int(score),i])
  
a.sort()
for n,s,idx in a:
  print(idx)
Problem p03071 (python)

Fixed submission:
a,b = map(int,input().split())
print(max([a+a-1,b+b-1,a+b]))

Buggy submission (verdict: Runtime Error):
a,b = map(int,input())
print(max([a+a -1, b+b-1, a+b])
Problem p03106 (python)

Fixed submission:
# from math import gcd
def gcd(a,b):
    if b == 0:return a
    return gcd(b,a%b)

a,b,k = map(int,input().split())

g = gcd(a,b)

cnt = 0
for i in range(g,0,-1):
  if a%i == 0 and b%i == 0:
    # print('i is now ',i)
    cnt+=1
    if cnt == k:
      print(i)
      break

Buggy submission (verdict: Runtime Error):
from math import gcd

a,b,k = map(int,input().split())

g = gcd(a,b)

cnt = 0
for i in range(g,0,-1):
  if a%i == 0 and b%i == 0:
    # print('i is now ',i)
    cnt+=1
    if cnt == k:
      print(i)
      break
Problem p03110 (python)

Fixed submission:
n = int(input())
ans = 0
for _ in range(n):
    m,t = input().split()
    m = float(m)
    if t == 'JPY':ans+=m
    else:ans+= m*380000.0
print(ans)

Buggy submission (verdict: Runtime Error):
n = int(input())
ans = 0
for _ in n:
  m,t = input().split()
  m = float(m)
  if t == 'JPY':ans+=m
  else:ans+= m*380000.0
print(ans)
Problem p02628 (python)

Fixed submission:
n,k = map(int,input().split())
a = list(map(int,input().split()))
a.sort()
print(sum(a[:k]))

Buggy submission (verdict: Runtime Error):
n,k = map(int,input().split())
a = list(map(int,input().split()))
a.sort()
print(sum[:k])
Problem p02641 (python)

Fixed submission:
x,n = map(int,input().split())
a = []
if n != 0 : a = list(map(int,input().split()))
tmp = 114514
ret = -114514
for i in range(-10,110):
  if not i in a and abs(x-i) < tmp:
    ret = i
    tmp = abs(x-i)
print(ret)

Buggy submission (verdict: Runtime Error):
x,n = map(int,input().split())
a = []
if n != 0 : a = list(map(int,input().split()))
tmp = 114514
ret = -114514
for i in range(-10,110):
  if not i in a and abs(x-i) < tmp
  ret = i
  tmp = abs(x-i)
print(ret)
Problem p02658 (python)

Fixed submission:
from sys import stdin
input = stdin.readline
def main():
  n = int(input())
  a = list(map(int,input().split()))
  a.sort()
  if a[0] == 0:
    print(0)
    return
  ret = 1
  for i in a:
    ret *= i
    if ret > 10**18:
      print(-1)
      return
  print(ret)
main()

Buggy submission (verdict: Runtime Error):
from sys import stdin
input = stdin.readline
def main():
  n = int(input())
  a = list(map(int,input().split())).sort()
  if a[0] == 0:
    print(0)
    return
  ret = 1
  for i in a:
    ret *= i
    if ret > 10**18:
      print(-1)
      return
  print(ret)
main()
Problem p02731 (python)

Fixed submission:
f = int(input()) / 3.0
print("{:.9f}".format(f * f * f))

Buggy submission (verdict: Runtime Error):
f = int(input()) / 3.0
print("{.9f}".format(f * f * f))

Buggy submission (verdict: Runtime Error):
f = int(input()) / 3.0
return(f * f * f)
Problem p02780 (python)

Fixed submission:
n,k = map(int,input().split())
d = list(map(lambda x: (int(x) + 1) / 2, input().split()))
ret = sum(d[:k])
tmp = ret
for i in range(k,n):
  tmp = tmp + d[i] - d[i-k]
  ret = max(ret,tmp)
print(ret)

Buggy submission (verdict: Runtime Error):
n,k = map(int,input().split())
d = map(lambda x: (int(x) + 1) / 2, input().split())
ret = sum(d[:k])
tmp = ret
for i in range(k,n):
  tmp = tmp + d[i] - d[i-k]
  ret = max(ret,tmp)
print(ret)
Problem p03085 (python)

Fixed submission:
d = {"A":"T", "T":"A", "G":"C", "C":"G"}
print(d[input()])

Buggy submission (verdict: Runtime Error):
d = {"A":"T", "T":"A", "G":"C", "C","G"}
print(d[input()])
Problem p03145 (python)

Fixed submission:
a = list(map(int,input().split()))
a = sorted(a)
print(a[0]*a[1]//2)

Buggy submission (verdict: Runtime Error):
a = list(map(int,input().split()))
a = sort(a)
print(a[0]*a[1]//2)
Problem p03289 (python)

Fixed submission:
s = input()
flag = True
flag = flag and s[0] == 'A'
Ccount = 0
for i in range(1,len(s)):
  if ord('a') <= ord(s[i]) and ord(s[i]) <= ord('z'): continue
  if s[i] == 'C' and 2 <= i and i <= len(s)-2:
    Ccount += 1
  else:
    flag = False
print("AC" if flag and Ccount == 1 else "WA")

Buggy submission (verdict: Runtime Error):
s = input()
flag = True
flag = flag and s[0] == 'A'
Ccount = 0
for i in range(1,len(s)):
  if ord('a') <= ord(s[i]) and ord(s[i]) <= 'z': continue
  if s[i] == 'C' and 2 <= i and i <= len(s)-2:
    Ccount += 1
  else:
    flag = False
print("AC" if flag and Ccount == 1 else "WA")
Problem p03294 (python)

Fixed submission:
n = int(input())
l = list(map(int,input().split()))
print(sum(l)-n)

Buggy submission (verdict: Runtime Error):
n = input()
l = list(map(int,input().split()))
print(sum(l)-n)

Buggy submission (verdict: Runtime Error):
n = input()
l = list(map,input().split())
print(sum(l)-n)
Problem p03352 (python)

Fixed submission:
x = int(input())
ret = 0
for b in range(1,int(x**0.5)+2):
    for p in range(2,11):
        if b**p <= x and ret < b**p: ret = b**p
print(ret)

Buggy submission (verdict: Runtime Error):
x = int(input())
ret = 0
for b in range(1,int(sqrt(x))+2):
    for p in range(2,10):
        if b**p <= x and ret < b**p: ret = b**p
print(ret)
Problem p03436 (python)

Fixed submission:
h,w = map(int,input().split())
m = [list(map((lambda x: 0 if x == '#' else 1),list(input()))) for i in range(h)]
ret = sum(list(map(sum,m)))

q = [[0,0,0]]
m[0][0] = 0
while len(q)!=0:
    qtop = q.pop(0)
    x = qtop[0]
    y = qtop[1]
    d = qtop[2]
    if x == h-1 and y == w-1:
        print(ret-d-1)
        break
    if 0 < x and m[x-1][y] == 1:
        m[x-1][y] = 0
        q.append([x-1,y,d+1])
    if h-1 > x and m[x+1][y] == 1:
        m[x+1][y] = 0
        q.append([x+1,y,d+1])
    if 0 < y and m[x][y-1] == 1:
        m[x][y-1] = 0
        q.append([x,y-1,d+1])
    if w-1 > y and m[x][y+1] == 1:
        m[x][y+1] = 0
        q.append([x,y+1,d+1])
else:
    print(-1)

Buggy submission (verdict: Runtime Error):
h,w = map(int,input().split())
m = [map((lambda x: 0 if x == '#' else 1),list(input())) for i in range(h)]
white = sum(list(map(sum,m)))

q = [[0,0,0]]
m[0][0] = 0
while len(q)!=0:
    qtop = pop(0)
    x = qtop[0]
    y = qtop[1]
    d = qtop[2]
    if x == h-1 and y == w-1:
        print(ret-d)
        break
    if 0 < x and m[x-1][y] == 1:
        m[x-1][y] = 0
        q.append([x-1,y,d+1])
    if h-1 > x and m[x+1][y] == 1:
        m[x+1][y] = 0
        q.append([x+1,y,d+1])
    if 0 < y and m[x][y-1] == 1:
        m[x][y-1] = 0
        q.append([x,y-1,d+1])
    if w-1 > y and m[x][y+1] == 1:
        m[x][y+1] = 0
        q.append([x,y+1,d+1])
else:
    print(-1)
Problem p03472 (python)

Fixed submission:
from math import ceil
n,h = map(int,input().split())
a = [0]*n
b = [0]*n
for i in range(n):
    a[i] , b[i] = map(int,input().split())
bs = list(sorted(b,reverse=True))
ma = max(a)
ret = 0
while ret < n:
    if bs[0] > ma:
        h -= bs[0]
        bs.pop(0)
        ret += 1
        if h <= 0 : break
    else:
        break

if h > 0: ret += ceil(h/ma)
print(ret)

Buggy submission (verdict: Runtime Error):
from math import ceil
n,h = map(int,input().split())
a = [0]*n
b = [0]*n
for i in range(n):
    a[i] , b[i] = map(int,input().split())
bs = list(sorted(b,reverse=True))
ma = max(a)
ret = 0
while ret < n:
    if bs[0] => ma:
        h -= bs[0]
        bs.pop(0)
        ret += 1
        if h <= 0 : break
    else:
        break

if h > 0: ret += ceil(h/ma)
print(ret)
Problem p03480 (python)

Fixed submission:
s = input()
l = len(s)
limit = [max(i+1,l-i-1) for i in range(l-1) if s[i] != s[i+1]]
limit.append(l)
print(min(limit))

Buggy submission (verdict: Runtime Error):
s = input()
l = len(s)
limit = [max(i+1,l-i-1) for i in range(l-1) if s[i] != s[i+1]]
print(min(limit))
Problem p03544 (python)

Fixed submission:
luca = [2,1]
for i in range(2,100):
    luca.append(luca[i-2] + luca[i-1])
print(luca[int(input())])

Buggy submission (verdict: Runtime Error):
luca = [2,1]
for i in range(2,86):
    luca.append(luca[i-2] + luca[i-1])
print(luca[int(input())])
Problem p03564 (python)

Fixed submission:
n = int(input())
k = (int(input()))
a = [(1<<x)+k*(n-x) for x in range(n+1)]
print(min(a))

Buggy submission (verdict: Runtime Error):
n = int(input())
k = (int(input()))
a = [(1<<x)+k*(n-x) for x in range(1,n)]
print(min(a))
Problem p03569 (python)

Fixed submission:
def main():
    s = list(input())
    wox = [i for i in s if i != "x"]
    if len(wox) == 0: return 0
    wowr = list(reversed(wox))
    for i in range(len(wox)//2+1):
        if wox[i] != wowr[i]:
            return -1
    sr = list(reversed(s))
    si = ri = 0
    ret = 0
    while si < len(s) and ri < len(sr):
        if s[si] == sr[ri]:
            si += 1
            ri += 1
        elif s[si] == "x":
            si += 1
            ret += 1
        else:
            ri += 1
            ret += 1
    return (ret + len(s) - min(si,ri))//2
print(main())

Buggy submission (verdict: Runtime Error):
def main():
    s = list(input())
    wox = [i for i in s if i != "x"]
    wowr = list(reversed(wox))
    for i in range(len(wox)//2+1):
        if wox[i] != wowr[i]:
            return -1
    sr = list(reversed(s))
    si = ri = 0
    ret = 0
    while si < len(s) and ri < len(sr):
        if s[si] == sr[ri]:
            si += 1
            ri += 1
        elif s[si] == "x":
            si += 1
            ret += 1
        else:
            ri += 1
            ret += 1
    return (ret + len(s) - min(si,ri))//2
print(main())
Problem p03658 (python)

Fixed submission:
n,k = map(int,input().split())
print(sum(sorted(map(int,input().split()))[n-k:]))

Buggy submission (verdict: Runtime Error):
l,k = map(int,input().split())
print(sum(sorted(map(int,input().split())[:k]))
Problem p03993 (python)

Fixed submission:
n = int(input())
k = list(map(int,input().split()))
r = 0
for i in range(n):
  if k[k[i]-1] == i+1: r += 1
print(r//2)

Buggy submission (verdict: Runtime Error):
n = int(input())
k = list(map(int,input().split()))
r = 0
for i in range(n):
  if k[k[i]] == i: r += 1
print(r//2)
Problem p02802 (python)

Fixed submission:
n,m=map(int,input().split())
acf,waf=[0]*n,[0]*n
ac,wa=0,0
for i in range(m):
    x,y=input().split()
    x=int(x)
    if y=='AC':
        if acf[x-1]==0:
            ac+=1
            wa+=waf[x-1]
            acf[x-1]+=1
    else:
        waf[x-1]+=1
print(ac,wa)

Buggy submission (verdict: Runtime Error):
n,m=map(int,input().split())
acf,waf=[0]*n,[0]*n
ac,wa=0,0
for i in range(m):
    x,y=input().split()
    x=int(x)
    if y=='AC':
        if acf[x]==0:
            ac+=1
            wa+=waf[x-1]
            acf[x-1]+=1
    else:
        waf[x-1]+=1
print(ac,wa)
Problem p02838 (python)

Fixed submission:
n=int(input())
a=list(map(int,input().split()))
mod=10**9+7
import numpy as np
a=np.array(a)
md = len(bin(max(a)))
ans = 0
for d in range(md):
    cnt1 = np.count_nonzero((a>>d)&1)
    ans += cnt1 * (n-cnt1) * (1<<d)
    ans %= mod

print(ans%mod)

Buggy submission (verdict: Runtime Error):
a=int(input())
n=list(map(int,input().split()))
mod=10**9+7
import numpy as np
a=np.array(a)
md = len(bin(max(a)))
ans = 0
for d in range(md):
    cnt1 = np.count_nonzero((a>>d)&1)
    ans += cnt1 * (n-cnt1) * (1<<d)
    ans %= mod

print(ans%mod)
Problem p03131 (python)

Fixed submission:
import math
k,a,b=map(int,input().split())
s=1
if b-a<=2 or k-1<2:
    print(k+1)
else:
    ans=a
    k-=a-1
    if k%2==1:
        ans+=1
        k-=1
    ans+=(b-a)*(k//2)
    print(ans)

Buggy submission (verdict: Runtime Error):
import math
k,a,b=map(int,input().split())
s=1:
if b-a<=2 or k-1<2:
    print(k+1)
else:
    t=max(0,math.ceil((k−(a−1))/2))
    ans=a
    k-=a-1
    if k%2==1:
        ans+=1
        k-=1
    ans+=(b-a)*k
    print(ans)
Problem p03147 (python)

Fixed submission:
n=int(input())
h=list(map(int,input().split()))
f=[0]*n
cnt=0
while 1:
    flag=0
    for i in range(n):
        if h[i]!=f[i]:
            f[i]+=1
            flag=1
        elif h[i]==f[i] and flag==1:
            cnt+=1
            flag=0
    if flag==1:
        cnt+=1

    if h==f:
        break

print(cnt)

Buggy submission (verdict: Runtime Error):
n=int(input())
h=list(map(int,input().split()))
f=[0]*n
cnt=0
while 1:
    flag=0
    for i in range(n):
        if h[i]!=f[i]:
            f[i]+=1
            flag=1
        elif h[i]==f[i] and flag==1:
            cnt+=1
            flag=0
    if flag:==1
        cnt+=1

    if h == f:
        break

print(cnt)
Problem p03246 (python)

Fixed submission:
from collections import Counter

n=int(input())
s=list(map(int,input().split()))
e=Counter(s[0::2])
o=Counter(s[1::2])
e[0]=0
o[0]=0
e1,e2=e.most_common(2)
o1,o2=o.most_common(2)
if e1[0]!=o1[0]:
    print(n-(e1[1]+o1[1]))
else:
    print(n-max(e1[1]+o2[1],e2[1]+o1[1]))

Buggy submission (verdict: Runtime Error):
from collections import Counter

n=int(input())
s=list(map(int,input().split()))
e=Counter(s[0::2])
o=Counter(s[1::2])
e[0]=0
o[0]=0
e1,e2=e.most_common(2)
o1,o2=o.most_common(2)
if e1[0]!=o1[0]:
    print(n-(e1[1]+o1[1]))
else:
    print(n-max(e1[1]+o2[1],e2[1]+o1[1]))z
Problem p03379 (python)

Fixed submission:
n=int(input())
x=list(map(int,input().split()))
y=sorted(x)
l=y[n//2-1]
r=y[n//2]
for a in x:
  print(l if a >= r else r)

Buggy submission (verdict: Runtime Error):
n=int(input())
x=list(map(int,input().split()))
y=sorted(x)
l=y[n//2-1]
r=y[n//2]
for a in x:
  print(L if a >= R else R)
Problem p03477 (python)

Fixed submission:
a,b,c,d=list(map(int,input().split()))
x=a+b
y=c+d
if x>y:
  print("Left")
elif x<y:
  print("Right")
else:
  print("Balanced")

Buggy submission (verdict: Runtime Error):
a,b,c,d=list(map(int,input().split()))
x=a+b
y=c+d
if x>y:
  print("Left")
 elif x<y:
  print("Right")
 else:
  print("Balanced")

Buggy submission (verdict: Runtime Error):
a,b,c,d=map(int,input().split())
x=a+b
y=c+d
if x>y:
  print("Left")
 elif x<y:
  print("Right")
 else:
  print("Balanced")
Problem p03497 (python)

Fixed submission:
n,k=map(int,input().split())
a=list(map(int,input().split()))
s=[0 for i in range(n)]
z=set(a)
y=len(z)
for x in a:
    s[x-1]+=1
b=sorted(s)
f=0
ans=0
for x in b:
    if x!=0:
        f+=1
        ans+=x
    if f>=y-k:
      	break
print(ans)

Buggy submission (verdict: Runtime Error):
n,k=map(int,input().split())
a=list(map(int,input().split()))
s=[0 for i in range(n)]
z=set(a)
y=len(z)
for x in a:
    s[x]+=1
b=sorted(s)
f=0
ans=0
for x in b:
    if x!=0:
        f+=1
        ans+=x
    if f>=y-k:
      	break
print(ans)

Buggy submission (verdict: Runtime Error):
n,k=int(input()),int(input())
a=list(map(int,input().split()))
s=set(a)
if len(s)<=k:
    print(0)
else:
    print(len(s)-k)
Problem p03627 (python)

Fixed submission:
n=int(input())
a=map(int,input().split())
a=sorted(a)
a=list(reversed(a))
h,w=0,0
tmp=0
f=0
for x in a:
    if tmp==x:
        if w!=0:
            h=x
            break
        else:
            w=x
            tmp=0
            continue
    tmp=x
print(w*h)

Buggy submission (verdict: Runtime Error):
n=int(input())
m=map(int,input().split())
a=[0 for i in range(1000000)]
x=0
y=0
for i in m:
    a[i]+=1
for i in range(len(a)):
    if a[i]>=2:
        x=y
        y=i

ans=x*y
print(ans)

Buggy submission (verdict: Runtime Error):
n=int(input())
m=map(int,input().split())
a=[0 for i in range(100001)]
x=0
y=0
for i in m:
    a[i]+=1
for i in range(len(a)):
    if a[i]>=2:
        x=y
        y=i

ans=x*y
print(ans)

Buggy submission (verdict: Runtime Error):
n=int(input())
m=map(int,input().split())
a=[0 for i in range(100000)]
x=0
y=0
for i in m:
    a[i]+=1
for i in range(len(a)):
    if a[i]>=2:
        x=y
        y=i

ans=x*y
print(ans)
Problem p03695 (python)

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

cnt=[0]*8
count=0
for i in range(n):
    if a[i]>=1 and a[i]<=399:
        cnt[0]=1
    elif a[i]>=400 and a[i]<=799:
        cnt[1]=1
    elif a[i]>=800 and a[i]<=1199:
        cnt[2]=1
    elif a[i]>=1200 and a[i]<=1599:
        cnt[3]=1
    elif a[i]>=1600 and a[i]<=1999:
        cnt[4]=1
    elif a[i]>=2000 and a[i]<=2399:
        cnt[5]=1
    elif a[i]>=2400 and a[i]<=2799:
        cnt[6]=1
    elif a[i]>=2800 and a[i]<=3199:
        cnt[7]=1
    else:
        count+=1
min_ans=sum(cnt)

if count==0:
    min1=min_ans
elif min_ans==0:
    min1=1
else:
    min1=max(1,min_ans)
max1=min_ans+count
print(min1,max1)

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

cnt=[0]*8
count=0
for i in range(n):
    if a[i]>=1 and a[i]<=399:
        cnt[0]=1
    elif a[i]>=400 and a[i]<=799:
        cnt[1]=1
    elif a[i]>=800 and a[i]<=1199:
        cnt[2]=1
    elif a[i]>=1200 and a[i]<=1599:
        cnt[3]=1
    elif a[i]>=1600 and a[i]<=1999:
        cnt[4]=1
    elif a[i]>=2000 and a[i]<=2399:
        cnt[5]=1
    elif a[i]>=2400 and a[i]<=2799:
        cnt[6]=1
    elif a[i]>=2800 and a[i]<=3199:
        cnt[7]=1
    else:
        count+=1
min_ans=sum(cnt)
if min_ans==0 and count>=1:
    min_ans=1
    count-=1

print(str(min_ans)+' '+str(min_ans+count)
Problem p02995 (python)

Fixed submission:
from fractions import gcd
a,b,c,d = map(int,input().split())
n = (a-1)//c #1~a-1までのcで割り切れる数
m = b//c #1~bまでのcで割り切れる数
ck = m - n #a~bまでのcで割り切れる数

o = (a-1)//d #1~a-1までのdで割り切れる数
p = b//d #1~bまでのdで割り切れる数
dk = p - o #a~bまでのdで割り切れる数

#cでもdでも割り切れる場合
e = (c * d) // gcd(c, d) #cとdの最小公倍数
q = (a-1)//e #1~a-1までのeで割り切れる数
r = b//e #1~bまでのeで割り切れる数
ek = r - q #a~bまでのeで割り切れる数

#cまたはdで割り切れる数
cord = ck + dk - ek

ans = b - a + 1 - cord
print(ans)

Buggy submission (verdict: Runtime Error):
import math

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

num1 = B // C - (A-1) // C
num2 = B // D - (A-1) // D
gcdCD = C * D // math.gcd(C, D)
num3 = B // gcdCD - (A-1) // gcdCD

print(B - A - num1 - num2 + num3 + 1)

Buggy submission (verdict: Runtime Error):
import math
a,b,c,d = map(int,input().split())
n = (a-1)//c #1~a-1までのcで割り切れる数
m = b//c #1~bまでのcで割り切れる数
ck = m - n #a~bまでのcで割り切れる数

o = (a-1)//d #1~a-1までのdで割り切れる数
p = b//d #1~bまでのdで割り切れる数
dk = p - o #a~bまでのdで割り切れる数

#cでもdでも割り切れる場合
e = (c * d) // math.gcd(c, d) #cとdの最小公倍数
q = (a-1)//e #1~a-1までのeで割り切れる数
r = b//e #1~bまでのeで割り切れる数
ek = r - q #a~bまでのeで割り切れる数

#cまたはdで割り切れる数
cord = ck + dk - ek

ans = b - a + 1 - cord
print(ans)

Buggy submission (verdict: Runtime Error):
import math
a,b,c,d = map(int,input().split())
n = (a-1)//c #1~a-1までのcで割り切れる数
m = b//c #1~bまでのcで割り切れる数
ck = m - n #a~bまでのcで割り切れる数

o = (a-1)//d #1~a-1までのdで割り切れる数
p = b//d #1~bまでのdで割り切れる数
dk = p - o #a~bまでのdで割り切れる数

#cでもdでも割り切れる場合
e = (c * d) // math.gcd(c, d) #cとdの最小公倍数
q = (a-1)//e #1~a-1までのeで割り切れる数
r = b//e #1~bまでのeで割り切れる数
ek = r - q #a~bまでのeで割り切れる数

#cまたはdで割り切れる数
cord = ck + dk - ek

ans = b - a + 1 - cord
print(ans)
Problem p03846 (python)

Fixed submission:
n = int(input())
a = list(map(int, input().split()))
mod = 10**9 + 7
ans = 2**(n//2)%mod
if n % 2 == 0:
    l = n ** 2
else:
    l = (n - 1) * (n + 1)
if sum(a) == l // 2:
    print(ans)
else:
    print(0)

Buggy submission (verdict: Runtime Error):
import collections
n = int(input())
a = list(map(int,input().split()))
b = [0]*(n//2)
c = [0]
d = [0]*(n//2)
e = []
lot = 10**9 + 7
ans = 2**(n//2)%lot
for i in range(n):
    b[i] = n-(2*i+1)
    if b[i] == 1 or b[i] == 2:
        break
for i in range(n):
    d[i] = n-(2*i+1)
    if d[i] == 1 or b[i] == 2:
        break
if n%2 == 0:
    e = b + d
else:
    e = b + c + d

count1 = collections.Counter(a)
count2 = collections.Counter(e)

if count1 == count2:
    print(ans)
else:
    print(0)

Buggy submission (verdict: Runtime Error):
import collections
n = int(input())
a = list(map(int,input().split()))
b = [0]*(n//2)
c = [0]
d = [0]*(n//2)
e = []
for i in range(n):
    b[i] = n-(2*i+1)
    if b[i] == 1 or b[i] == 2:
        break
for i in range(n):
    d[i] = n-(2*i+1)
    if d[i] == 1 or b[i] == 2:
        break
if n%2 == 0:
    e = b + d
else:
    e = b + c + d

count1 = collections.Counter(a)
count2 = collections.Counter(e)

if count1 == count2:
    print(2**(n//2))
else:
    print(0)
Problem p02582 (python)

Fixed submission:

s = str(input())
r = 0
a = s.find("R")
if a==-1:
    print(r)
else:
    r+=1
    if a<2:
        while(s[a+1]=="R"):
            r+=1
            a+=1
            if a==2:
                break
    print(r)

Buggy submission (verdict: Runtime Error):

s = str(input())
r = 0
a = s.find("R")
if a==-1:
    print(r)
else:
    r+=1
    while(s[a+1]=="R"):
        r+=1
        a+=1
    print(r)
Problem p02641 (python)

Fixed submission:
x,n = map(int,input().split())
p = list(map(int,input().split()))
if x not in p:
    print(x)
    exit()
a,b = x,x
while True:
    a+=1
    b-=1
    if b not in p:
        print(b)
        break
    elif a not in p:
        print(a)
        break

Buggy submission (verdict: Runtime Error):
x,n = map(int,input().split())
p = list(map(int,input().split()))
if n==0:
    print(x)
    exit()
res = []
for num in range(1,101):
    if x!=num and num not in p:
        res.append(abs(x-num))
if x-min(res) not in p:
    print(x-min(res))
else:
    print(x+min(res))

Buggy submission (verdict: Runtime Error):
x,n = map(int,input().split())
p = list(map(int,input().split()))
if n==0:
    print(x)
    exit()
elif x==1:
    print(0)
    exit()
res = []
for num in range(1,101):
    if x!=num and num not in p:
        res.append(abs(x-num))
if x-min(res) not in p:
    print(x-min(res))
else:
    print(x+min(res))

Buggy submission (verdict: Runtime Error):
def forbidden(x,p):
    res = []
    if x==1:
        return 0
    for num in range(1,101):
        if x!=num and num not in p:
            res.append(abs(x-num))
    if x-min(res) not in p:
        return x-min(res)
    return x+min(res)

if __name__ == "__main__":
    x,n = map(int,input().split())
    p = list(map(int,input().split()))
    if n==0:
        print(x)
        exit()
    print(forbidden(x,p))

Buggy submission (verdict: Runtime Error):
def forbidden(x,p):
    res = []
    for num in range(1,101):
        if x!=num and num not in p:
            res.append(abs(x-num))
    if x-min(res) not in p:
        return x-min(res)
    return x+min(res)

if __name__ == "__main__":
    x,n = map(int,input().split())
    p = list(map(int,input().split()))
    if n==0:
        print(x)
        exit()
    elif x==1:
        print(0)
        exit()
    print(forbidden(x,p))

Buggy submission (verdict: Runtime Error):
def forbidden(x,p):
    res = []
    for num in range(1,101):
        if x!=num and num not in p:
            res.append(abs(x-num))
    if x-min(res) not in p and x-min(res)!=0:
        return x-min(res)
    return x+min(res)

if __name__ == "__main__":
    x,n = map(int,input().split())
    p = list(map(int,input().split()))
    if n==0:
        print(x)
        exit()
    print(forbidden(x,p))