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

Fixed submission:
def main(n):

    prime = []
    if n < 2:
        prime.append((1,0))
    for p in range(2,int(n**0.5)):
        cnt = 0
        if p*p > n:
            break
        while n%p == 0:
            n //= p
            cnt += 1
        prime.append((p,cnt))
    if n > 1:
        prime.append((n,1))
    return prime
                    
n = int(input())    
pf = main(n)

ans = 0
for p, f in pf:
    cnt = 1
    while f >= cnt:
        f -= cnt
        ans += 1
        cnt += 1

print(ans)

Buggy submission (verdict: Runtime Error):
def main(n):

    prime = []
    if n < 2:
        return 1
    for p in range(2,int(n**0.5)):
        cnt = 0
        if p*p > n:
            break
        while n%p == 0:
            n //= p
            cnt += 1
        prime.append((p,cnt))
    if n > 1:
        prime.append((n,1))
    return prime
                    
n = int(input())    
pf = main(n)

ans = 0
for p, f in pf:
    cnt = 1
    while f >= cnt:
        f -= cnt
        ans += 1
        cnt += 1

print(ans)
Problem p02664 (python)

Fixed submission:
s = input()

n = len(s)
ans = []
for i in range(n):
    if s[i] != '?':
        ans.append(s[i])
    else:
        ans.append('D')
            
print(*ans,sep = '')

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

n = len(s)
ans = []
for i in range(n):
    if s[i] != '?':
        ans.append(s[i])
    else:
        if s[i-1] == 'P' and i > 0:
            ans.append('D')
        elif s[i-1] == '?'and i > 0:
            ans.append('D')
        elif s[i+1] == '?' and i < n:
            ans.append('P')
        elif s[i+1] == 'D' and i < n:
            ans.append('P')
        else:
            ans.append('D')
            
print(*ans,sep = '')

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

n = len(s)
ans = []
for i in range(n):
    if s[i] != '?':
        ans.append(s[i])
    else:
        if s[i-1] == 'P' and i > 0:
            ans.append('D')
        elif s[i-1] == '?'and i > 0:
            ans.append('D')
        elif s[i+1] == '?':
            ans.append('P')
        elif s[i+1] == 'D':
            ans.append('P')
        else:
            ans.append('D')
            
print(*ans,sep = '')
Problem p02690 (python)

Fixed submission:
x = int(input())

def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
 
    return divisors


d = make_divisors(x)


for i in d:
    for b in range(-10000,10000):
        a = i + b
        if x // i == a**4 + (a**3)*b + (a**2)*(b**2) + a*(b**3) + b**4:
            ans = [str(a),str(b)]
            break
        
print(*ans)

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

def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
 
    return divisors


d = make_divisors(x)


for i in d:
    for b in range(-100,100):
        a = i + b
        if x // i == a**4 + (a**3)*b + (a**2)*(b**2) + a*(b**3) + b**4:
            ans = [a,b]
            break
        
print(ans)
Problem p02718 (python)

Fixed submission:
import bisect
n,m = [int(i) for i in input().split()]
al = sorted([int(i) for i in input().split()],reverse = True)
total = sum(al)

l = al[:m]

if l[-1] >= total/(4*m):
    print('Yes')
else:
    print('No')

Buggy submission (verdict: Runtime Error):
import bisect
n,m = [int(i) for i in input().split()]
al = sorted([int(i) for i in input().split()])
total = sum(al)

idx = bisect.bisect_left(al,total/(4*m))

if n - idx > m:
    print('Yes')
elif al[idx+1] == total/(4*m):
    print('No')
else:
    print('No')

Buggy submission (verdict: Runtime Error):
import bisect
n,m = [int(i) for i in input().split()]
al = sorted([int(i) for i in input().split()])
total = sum(al)

idx = bisect.bisect_left(al,total/(4*m))
idx = bisect.bisect_left(al,789)

if n - idx > m:
    print('Yes')
elif al[idx+1] == total/(4*m):
    print('No')
else:
    print('No')
Problem p02795 (python)

Fixed submission:
h = int(input())
w = int(input())
n = int(input())

use = h if h >= w else w

print(n//use + 1 if n%use else n//use)

Buggy submission (verdict: Runtime Error):
n,k,s = [int(i) for i in input().split()]
 
ans_list = []
for i in range(n):
  if i < k:
    ans_list.append(str(s))
  else:
    ans_list.append(str(s+1))
    
print(*ans_list)
Problem p02813 (python)

Fixed submission:
import itertools

n = int(input())
l = sorted(list(itertools.permutations([i for i in range(1,n+1)])))

al = tuple([int(i) for i in input().split()])
bl = tuple([int(i) for i in input().split()])


a,b = 0,0


if al == bl:
    print(0)
else:
    for idx,i in enumerate(l):
        if i == al:
            a = idx
        elif i == bl:
            b = idx
        else:
            pass
        
    print(abs(a-b))

Buggy submission (verdict: Runtime Error):
n = int(input())
l = sorted(list(itertools.permutations([i for i in range(1,n+1)])))

al = tuple([int(i) for i in input().split()])
bl = tuple([int(i) for i in input().split()])


a,b = 0,0


if al == bl:
    print(0)
else:
    for idx,i in enumerate(l):
        if i == al:
            a = idx
        elif i == bl:
            b = idx
        else:
            pass
        
    print(abs(a-b))
Problem p02844 (python)

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

l = [str(i).zfill(3) for i in range(0,1000)]

ct = 0
for i in l:
  n0 = s.find(i[0])
  if n0==-1:
    continue
  n1 = s.find(i[1], n0+1)
  if n1==-1:
    continue
  n2 = s.find(i[2], n1+1)
  if n2!=-1:
    ct += 1
   
print(ct)

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

l = [str(i).zfill(3) for i in range(0,1000)]

ct = 0
for i in l:
  n0 = s.find(a[0])
  if n0==-1:
    continue
  n1 = s.find(a[1], n0+1)
  if n1==-1:
    continue
  n2 = s.find(a[2], n1+1)
  if n2!=-1:
    c += 1
   
print(ct)
Problem p02853 (python)

Fixed submission:
prize = {1:300000,2:200000,3:100000}

a,b = [int(i) for i in input().split()]

if a == b == 1:
    print(1000000)
elif a < 4 and b < 4:
    print(prize[a] + prize[b])
elif a >= 4 and b < 4:
    print(prize[b])
elif b >= 4 and a < 4:
    print(prize[a])
else:
    print(0)

Buggy submission (verdict: Runtime Error):
prize = {1:300000,2:200000,3:100000}

a,b = [int(i) for i in input().split()]

if a == b == 1:
    print(1000000)
elif a < 4 and b < 4:
    print(prize[a] + prize[b])
elif a >= 4:
    print(prize[b])
elif b >= 4:
    print(prize[a])
else:
    print(0)
Problem p02882 (python)

Fixed submission:
import math
a,b,x = [int(i) for i in input().split()]

if x <= (a**2*b)/2:
    height = x/(a*b)*2
    #余弦定理
    c = b**2 + height**2 - 2*b*height*math.cos(math.radians(90))
    h2 = b*height / math.sqrt(c)
    theta = math.degrees(math.asin(h2/height))
    print(theta)
elif x < (a**2*b):
    square = a**2*b-(a**2*b - x)*2
    triangle = (a**2*b-x)
    ratio = square/triangle/2 + 1
    d = b/ratio
    height = triangle/(a*d)*2
    c = d**2 + height**2 - 2*d*height*math.cos(math.radians(90))
    h2 = d*height / math.sqrt(c)
    theta = math.degrees(math.asin(h2/height))
    print(theta)
else:
    print(0)

Buggy submission (verdict: Runtime Error):
import math
a,b,x = [int(i) for i in input().split()]

if x <= (a**2*b)/2:
    height = x/(a*b)*2
    #余弦定理
    c = b**2 + height**2 - 2*b*height*math.cos(math.radians(90))
    h2 = b*height / math.sqrt(c)
    theta = math.degrees(math.asin(h2/height))
    print(theta)
else:
    square = a**2*b-(a**2*b - x)*2
    triangle = (a**2*b-x)
    ratio = square/triangle/2 + 1
    d = b/ratio
    height = triangle/(a*d)*2
    c = d**2 + height**2 - 2*d*height*math.cos(math.radians(90))
    h2 = d*height / math.sqrt(c)
    theta = math.degrees(math.asin(h2/height))
    print(theta)
Problem p02888 (python)

Fixed submission:
import bisect
n = int(input())
l = sorted([int(i) for i in input().split()])

ans = 0
for i in range(n):
    for j in range(i+1,n):
        a = l[i]
        b = l[j]
        tri = bisect.bisect_left(l,a+b)
        ans += tri-j-1
        
print(ans)

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

l = np.array([int(i) for i in input().split()])
l.sort()

c = np.bincount(l,minlength = 2100)

cum = list(c.cumsum())

ans = 0
for i in range(n):
    for j in range(i+1, n):
        ans += cum[min(l[i]+l[j]-1, 1000)] - (j+1)
print(ans)

Buggy submission (verdict: Runtime Error):
import numpy as np
from numba import njit
 
@njit
def count(l,n):
  ct = 0
  for i in range(n):
    for j in range(i + 1, n):
      for k in range(j + 1, n):
        ct += (l[k] < l[i] + l[j])
  return ct

         
n = int(input())
l = np.int32(input().split())
l.sort()

ans = count(l,n)

print(ans)
Problem p02900 (python)

Fixed submission:
import fractions
import math
a,b = [int(i) for i in input().split()]

gcd = fractions.gcd(a,b)

def is_prime(n):
    if n == 1: return False

    for k in range(2, int(math.sqrt(n)) + 1):
        if n % k == 0:
            return False

    return True

def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)
 
    return divisors

l = make_divisors(gcd)

print(len([i for i in l if is_prime(i)]) +1)

Buggy submission (verdict: Runtime Error):
import fractions
a,b = [int(i) for i in input().split()]

gcd = fractions.gcd(a,b)

def is_prime(n):
    if n == 1: return False

    for k in range(2, int(math.sqrt(n)) + 1):
        if n % k == 0:
            return False

    return True

def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)
 
    return divisors

l = make_divisors(gcd)

print(len([i for i in l if is_prime(i)]) +1)
Problem p02971 (python)

Fixed submission:
n = int(input())
l = [int(input()) for _ in range(n)]
max_num = max(l)
second_num = sorted(l)[-2]

for i in range(n):
   if l[i] == max_num:
       print(second_num)
   else:
       print(max_num)

Buggy submission (verdict: Runtime Error):
from collections import deque
n = int(input())
l = deque([int(input()) for _ in range(n)][::-1])
m = l.copy()

for i in range(len(l)):
    num = m.pop()
    print(max(m))
    m.appendleft(num)

Buggy submission (verdict: Runtime Error):
n = int(input())
l = [int(input()) for _ in range(n)]
m = l.copy()
m = m[::-1]

for i in range(len(l)):
    num = m.pop()
    print(max(m))
    m.insert(0, num)
Problem p03000 (python)

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

num = 0
ans = 1
for i in l:
    num += i
    if num > m:
        break
    else:
        ans +=1
    
print(ans)

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

num = 0
ct = 0
while num <= m and ct <= len(l):
    ct +=1
    num += l[ct-1]
    
print(ct)

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

num = 0
ct = 0
while num <= m:
    ct +=1
    num += l[ct-1]
    
print(ct)
Problem p03037 (python)

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

l = 0
r = n
for i in range(m):
    s,e = [int(i) for i in input().split()]
    l = max(l,s)
    r = min(r,e)
    
print(max(0,r-l + 1))

Buggy submission (verdict: Runtime Error):
n,m = [int(i) for i in input().split()]
if m == 1:
    print(1)
else:
    s1,e2  = {int(i) for i in input().split()}
    num_set = {i for i in range(s1,e2+1)}
    for i in range(m-1):
        s,e = [int(i) for i in input().split()]
        card_set = {i for i in range(s,e+1)}
        num_set = num_set & card_set
    
    print(len(num_set))
Problem p03211 (python)

Fixed submission:
n = input()
l = []
for i in range(len(n)-2):
    num = '{}{}{}'.format(n[i],n[i+1],n[i+2])
    l.append(int(num))  
print(min([abs(i - 753) for i in l]))

Buggy submission (verdict: Runtime Error):
n = input()
l = []
for i in range(len(n)-2):
    num = f'{n[i]}{n[i+1]}{n[i+2]}'
    l.append(int(num))
    
print(min([abs(i - 753) for i in l]))
Problem p03424 (python)

Fixed submission:
n = int(input())

s = set([i for i in input().split()])

print('Four' if len(s) == 4 else 'Three')

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

s = set([int(i) for i in input().split])

print(len(s))
Problem p03425 (python)

Fixed submission:
from collections import Counter
import itertools
n = int(input()) 
l = [input()[0] for _ in range(n)]
l = [i for i in l if i in {'M','A','R','C','H'}]

if len(l) < 3:
    print(0)
else:
    c = Counter(l)
    cl = list(itertools.combinations(c,3))
    ans = 0
    for i in cl:
        ans += c[i[0]] * c[i[1]] * c[i[2]]
    print(ans)

Buggy submission (verdict: Runtime Error):
from collections import Counter
import itertools
n = int(input()) 
l = [input()[0] for _ in range(n)]
l = [i for i in l if i in {'M','A','R','C','H'}]

if len(l) < 3:
    print(0)
else:
    c = Counter(l)
    cl = list(itertools.combinations(c,3))
    ans = 0
    for i in cl:
        ans += c[i[0]] * c[i[1]] * c[i[2]]

print(ans)
Problem p03471 (python)

Fixed submission:
x,y = [int(i) for i in input().split()]
ans =[]

for i in range(x+1):
    if not ans:
        for j in range(x-i+1):
            if 10000*i + j*5000 + (x-i-j)*1000 == y:
                ans = [i,j,x-i-j]
                break
    else:
        break

if ans:
    print(ans[0],ans[1],ans[2])
else:
    print('-1 -1 -1')

Buggy submission (verdict: Runtime Error):
n,m = [int(i) for i in input().split()]
l = sorted([[int(i) for i in input().split()] for _ in range(n)],key = lambda x: (x[1]))
l2 = sorted(l,key = lambda x :x[0])

min_atk = l2[n-1][0]
ct = 0
for i in range(len(l)-1,0,-1):
    if l[i][1] >= min_atk and m >= 0:
        m -= l[i][1]
        ct += 1
    else:
        break

if m < 0:
    print(ct)
else:
    q,r = divmod(m,min_atk)
    ct += (m//min_atk) +( 1 if r > 0 else 0 )
    
print(ct)
Problem p03557 (python)

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

a = sorted([int(i) for i in input().split()])
b = sorted([int(i) for i in input().split()])
c = sorted([int(i) for i in input().split()])

ans = 0
for i in b:
    x = bisect.bisect(c,i)
    y = bisect.bisect_left(a,i)
    ans += (n-x) * y
    
print(ans)

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

a = sorted([int(i) for i in input().split()])
b = sorted([int(i) for i in input().split()])
c = sorted([int(i) for i in input().split()])

ans = 0
for i in b:
    x = bisect.bisect(c,i)
    y = bisect.bisect_left(a,i)
    ans += (n-x) * y
    
print(ans)
Problem p03665 (python)

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

l = [int(i) for i in input().split()]

l2 = [i for i in l if i %2 == 1]

if not l2 :
    print(2**a if b % 2 == 0 else 0)
else:
    print(2**(a-1))

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

l = [int(i) for i in input().split()]

l2 = [i for i in l if i %2 == 1]

if not l2 :
    print(2**n if b == 0 else 0)
else:
    print(2**(a-1))
Problem p03694 (python)

Fixed submission:
n = int(input())

l = sorted([int(i) for i in input().split()])

print(l[n-1] - l[0])

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

l = sorted(list({int(i) for i in input().split()}))

print(l[n-1] - l[0])
Problem p03721 (python)

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

temp = 0
l = sorted([[int(i) for i in input().split()] for _ in range(a)],key = lambda x: x[0])
for i in l:
    temp += i[1]
    if temp >= b:
        ans = i[0]
        break
print(ans)

Buggy submission (verdict: Runtime Error):
import numpy as np
n,m = [int(i) for i in input().split()]
l = [[int(i) for i in input().split()] for _ in range(n)]
ans = np.zeros(10**10+100,dtype = np.int64)
start = 0
end = 0
for i,j in l:
    end += j
    ans[start:end] = i
    start = end
    
print(ans[m-1])

Buggy submission (verdict: Runtime Error):
import numpy as np

n,m = [int(i) for i in input().split()]
l = [[int(i) for i in input().split()] for _ in range(n)]
ans = np.zeros(10**5+1,dtype = np.int64)
start = 0
end = 0
for i,j in l:
    end += j
    ans[start:end] = i
    start = end
    
print(ans[m-1])

Buggy submission (verdict: Runtime Error):
n,m = [int(i) for i in input().split()]
l = [[int(i) for i in input().split()] for _ in range(n)]
ans = np.zeros(10**5+1,dtype = np.int64)
start = 0
end = 0
for i,j in l:
    end += j
    ans[start:end] = i
    start = end
    
print(ans[m-1])
Problem p03777 (python)

Fixed submission:
a,b = [i for i in input().split()]
lies ={'H':'D','D':'H'}
print(b if a == 'H' else lies[b])

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

ct = 1
while ct*(ct+1)//2 < n:
    ct +=1
print(ct)
Problem p03815 (python)

Fixed submission:
n = int(input())

roll = n // 11 * 2

print(roll if n % 11  == 0 else roll + 1 if n % 11 < 7 else roll + 2 )

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

ans = x % 11
sample = 2 * n//11

print(sample if not ans else sample + ans//6 + 1)
Problem p03838 (python)

Fixed submission:
x,y = [int(i) for i in input().split()]
 
if x < y:
    if x*y < 0:
        print(1 + abs(abs(x) - y))
    else:
        print(y - x)
else:
    if x*y <= 0:
        print(1 + abs(x - abs(y)))
    else:
        print(2 + abs(x - y))

Buggy submission (verdict: Runtime Error):
import numpy as np
x,y = [int(i) for i in input().split()]

ans_array = np.array([],dtype = np.int64)

if y - x >= 0:
    ans_array = np.append(ans_array,y-x)
if y - abs(x) >= 0:
    ans_array = np.append(ans_array,y-abs(x)+1)
if abs(y) - x >= 0:
    ans_array = np.append(ans_array,abs(y)-x+1)
if abs(y) -abs(x) >= 0:
    ans_array = np.append(ans_array,abs(y)-abs(x) + 2)

print(ans_array.min())
Problem p03910 (python)

Fixed submission:
n = int(input())
def main(n):
    if n == 1:
        return 2,0
    
    if n == 3:
        return 3,0
    m = n //2 
    for i in range(1,m+1):
        if i * (i + 1) <= 2*n < (i+1)*(i+2):
           right  = i + 1
           break
       
    diff = right * (right+1) //2 - n
       
    return right+1,diff


right,diff = main(n)

for i in range(1,right):
    if i != diff:
        print(i)

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

if n == 1:
    print(1)
else:
    m = n //2 
    for i in range(1,m+1):
        if i * (i + 1) <= 2 *n < (i+1)*(i+2):
           right  = i + 1
           break
       
    diff = right * (right+1) //2 - n
       
    for i in range(1,right+1):
        if i != diff:
            print(i)
Problem p02705 (python)

Fixed submission:
from math import pi

print(int(input()) * 2 * pi)

Buggy submission (verdict: Runtime Error):
import math
print(int(input() * 2 * math.pi)
Problem p02721 (python)

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

R = []
p = 0
for _ in range(k):
    while s[p] == 'x':
        p += 1
    R.append(p)
    p += c + 1

L = []
p = n - 1
for _ in range(k):
    while s[p] == 'x':
        p -= 1
    L.append(p)
    p -= c + 1

L = list(reversed(L))

for i in range(k):
    if R[i] == L[i]:
        print(R[i] + 1)

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

R = []
p = 0
for _ in range(k):
    R.append(p)
    p += c
    while s[p] == 'x':
        p += 1

L = []
p = n - 1
for _ in range(k):
    L.append(p)
    p -= c
    while s[p] == 'x':
        p -= 1

L = list(reversed(L))

for i in range(k):
    if R[i] == L[i]:
        print(i+1)
Problem p02797 (python)

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

if s == 10 ** 9:
    ans = []
    for _ in range(k):
        ans.append(str(s))
    for _ in range(n-k):
        ans.append('1')
    print(' '.join(ans))
else:
    ans = []
    for _ in range(k):
        ans.append(str(s))
    for _ in range(n-k):
        ans.append(str(s+1))
    print(' '.join(ans))

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

if s == 10 ** 9:
    ans = []
    for _ in range(k):
        ans.append(str(s))
    for _ in range(n-k):
        ans.append('1')
    print(' '.join(ans))
else:
    ans = []
    for _ in range(k):
        ans.append(str(s))
    for _ in range(n-k):
        ans.appned(str(s+1))
    print(' '.join(ans))
Problem p02814 (python)

Fixed submission:
n, m = map(int, input().split())
a = list(map(lambda x:int(x) // 2, input().split()))

a = sorted(list(set(a)))

def gcd(a, b):
	while b:
		a, b = b, a % b
	return a

def lcm(a, b):
	return a * b // gcd (a, b)

if len(a) == 1:
    ans = m // a[0]
    print(ans - ans // 2)
    exit()

temp = lcm(a[0], a[1])
if (temp // a[0]) % 2 == 0 or (temp // a[1]) % 2 == 0:
    print(0)
    exit()

for y in a[2:]:
    temp = lcm(temp, y)
    if (temp // y) % 2 == 0 or temp > m:
        print(0)
        exit()

ans = m // temp
print(ans - ans // 2)

Buggy submission (verdict: Runtime Error):
n, m = map(int, input().split())
a = list(map(lambda x:int(x) // 2, input().split()))

def gcd(a, b):
	while b:
		a, b = b, a % b
	return a

def lcm(a, b):
	return a * b // gcd (a, b)

temp = lcm(a[0], a[1])
if (temp // a[0]) % 2 == 0 or (temp // a[1]) % 2 == 0:
    print(0)
    exit()

if n > 2:
    for y in a[2:]:
        temp = lcm(temp, y)
        if (temp // y) % 2 == 0 or temp > m:
            print(0)
            exit()

ans = m // temp
print(ans - ans // 2)

Buggy submission (verdict: Runtime Error):
n, m = map(int, input().split())
a = list(map(lambda x:int(x) // 2, input().split()))

def gcd(a, b):
	while b:
		a, b = b, a % b
	return a

def lcm(a, b):
	return a * b // gcd (a, b)

temp = lcm(a[0], a[1])
if (temp // a[0]) % 2 == 0 or (temp // a[1]) % 2 == 0:
    print(0)
    exit()

for y in a[2:]:
    temp = lcm(temp, y)
    if (temp // y) % 2 == 0 or temp > m:
        print(0)
        exit()

ans = m // temp
print(ans - ans // 2)

Buggy submission (verdict: Runtime Error):
n, m = map(int, input().split())
a = list(map(lambda x:int(x) // 2, input().split()))

def gcd(a, b):
	while b:
		a, b = b, a % b
	return a

def lcm(a, b):
	return a * b // gcd (a, b)

temp = lcm(a[0], a[1])
if (temp // a[0]) % 2 == 0 or (temp // a[1]) % 2 == 0:
    print(0)
    exit()

for y in a[2:]:
    temp = lcm(temp, y)
    if (temp // y) % 2 == 0 or temp > m:
        print(0)
        exit()

ans = m // temp
print(ans - ans // 2)
Problem p02874 (python)

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

n = int(input())
LR = [tuple(map(int, input().split())) for _ in range(n)]

def quicksort(x):
    if x==[]: return []

    smallerSorted = quicksort([a for a in x[1:] if a[0] < x[0][0] or (a[0] == x[0][0] and a[1] >= x[0][1])])
    biggerSorted = quicksort([a for a in x[1:] if a[0] > x[0][0] or (a[0] == x[0][0] and a[1] < x[0][1])])

    return(smallerSorted+[x[0]]+biggerSorted)

LR = quicksort(LR)

e = [[] for _ in range(n+2)]

ans = [0] * (n+1)
temp = 10 ** 9
i = 1
for L, R in LR:
    temp = min(temp, R)
    if L > temp:
        break
    ans[i] = temp - L + 1
    i += 1

temp = 10 ** 9
i = n - 1
L = LR[-1][0]
for x, R in reversed(LR):
    temp = min(temp, R)
    if L > temp:
        break
    ans[i] += temp - L + 1
    i -= 1

res = max(ans)
for L, R in LR:
    res = max(res, R - L + 1 + ans[0])

#print(LR)
#print(ans)
print(res)

Buggy submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(10 ** 9)

n = int(input())
LR = [tuple(map(int, input().split())) for _ in range(n)]

def quicksort(x):
    if x==[]: return []

    smallerSorted = quicksort([a for a in x[1:] if (a[0] < x[0][0] or (a[0] == x[0][0] and a[1] >= x[0][1])])
    biggerSorted = quicksort([a for a in x[1:] if (a[0] > x[0][0] or (a[0] == x[0][0] and a[1] < x[0][1]))])

    return(smallerSorted+[x[0]]+biggerSorted)

LR = quicksort(LR)

ans = [0] * (n+1)
temp = 10 ** 9
i = 1
for L, R in LR:
    temp = min(temp, R)
    if L > temp:
        break
    ans[i] = temp - L + 1
    i += 1
#print(ans)
temp = 10 ** 9
i = n - 1
L = LR[-1][0]
for x, R in reversed(LR):
    temp = min(temp, R)
    if L > temp:
        break
    ans[i] += temp - L + 1
    i -= 1

print(max(ans))