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

Fixed submission:
n = int(input())
l = list(input().split())
ll,lr = l[::2],l[1::2]
dl,dr = {},{}
for i in ll: dl[i] = dl.get(i,0)+1
for j in lr: dr[j] = dr.get(j,0)+1
ltl = sorted(dl.items(),key=lambda k:-k[1])
ltr = sorted(dr.items(),key=lambda k:-k[1])
if ltl[0][0] != ltr[0][0]:
  print(n-ltl[0][1]-ltr[0][1])
elif len(ltl)<2:
  print(n//2)
else:
  print(n-ltl[0][1]-max(ltl[1][1],ltr[1][1]))

Buggy submission (verdict: Runtime Error):
n = int(input())
l = list(input().split())
ll,lr = l[::2],l[1::2]
dl,dr = {},{}
for i in ll: dl[i] = dl.get(i,0)+1
for j in lr: dr[j] = dr.get(j,0)+1
ltl = sorted(dl.items(),key=lambda k:-k[1])
ltr = sorted(dr.items(),key=lambda k:-k[1])
if ltl[0][0] != ltr[0][0]:
  print(n-ltl[0][1]-ltr[0][1])
elif len(ltl)<2:
  print(n//2)
else:
  print(n-ltl[0][1]-max(lt1[1][1],ltr[1][1]))
Problem p03282 (python)

Fixed submission:
s = input()
if set(s[:int(input())])=={'1'}:
  print(1)
else:
  for i in s:
    if int(i) > 1:
      print(int(i))
      break

Buggy submission (verdict: Runtime Error):
s=input()[:int(input())].replace('1','')
print([s[0],1][s==''])

Buggy submission (verdict: Runtime Error):
print(input()[:int(input())].replace('1','')[0]or 1)
Problem p03407 (python)

Fixed submission:
a,b,c=map(int,input().split())
print('YNeos'[a+b<c::2])

Buggy submission (verdict: Runtime Error):
a,b,c=map(input().split())
print('YNeos'[a+b<c::2])
Problem p03425 (python)

Fixed submission:
n=int(input())
from collections import *
d=Counter()
for _ in range(n): d[input()[0]]+=1
import itertools as it
print(sum(d[s]*d[t]*d[r] for s,t,r in it.combinations('MARCH',3)))

Buggy submission (verdict: Runtime Error):
n=int(input())
d={'M':0,'A':0,'R':0,'C':0,'H':0}
for _ in range(n): d[input()[0]]+=1
import itertools as it
print(sum(d[s]*d[t]*d[r] for s,t,r in it.combinations('MARCH',3)))
Problem p03625 (python)

Fixed submission:
input()
from collections import *
c=Counter(map(int,input().split()))
a=0
r=sorted(-k for k,v in c.items() if v>1)
if len(r)>1: a=r[0]*r[1]
s=sorted(-k for k,v in c.items() if v>3)
if s: a=max(a,s[0]**2)
print(a)

Buggy submission (verdict: Runtime Error):
input()
from collections import *
c=Counter(map(int,input().split()))
a=sorted(-k for k,v in c.items() if v>3)
if a: s=a[0]**2
l=sorted(-k for k,v in c.items() if v>1)
print(0 if len(l)<2 else max(s,l[0]*l[1]))
Problem p03635 (python)

Fixed submission:
n,m = map(int,input().split())
print((n-1)*(m-1))

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

Fixed submission:
s = input()
print(s[0]+str((len(s)-2))+s[-1])

Buggy submission (verdict: Runtime Error):
s = input()
print(l[0]+str((len(l)-2))+l[-1])
Problem p03644 (python)

Fixed submission:
n = int(input())
ans = 1
while ans <= n//2:
  ans *= 2
print(ans)

Buggy submission (verdict: Runtime Error):
ans = 1
while ans <= int(input())//2:
  ans *= 2
print(ans)
Problem p03796 (python)

Fixed submission:
p = 1
for i in range(int(input())):
  p = p*(i+1)%(10**9+7)
print(p)

Buggy submission (verdict: Runtime Error):
p = 1
for i in range(n):
  p = p*(i+1)%(10**9+7)
print(p)
Problem p04045 (python)

Fixed submission:
n,k=map(int,input().split())
l=input().split()
while 1:
  for i in str(n):
    if i in l: n+=1; break
  else: print(n); break

Buggy submission (verdict: Runtime Error):
n,_=map(int,input().split())
s=set(input())
while s&set(str(n)): n+=1
print(n
Problem p02534 (python)

Fixed submission:
K = int(input())
ans = ''
for i in range(K):
  ans += 'ACL'
print(ans)

Buggy submission (verdict: Runtime Error):
A,B,C,D = map(int, input().split())
if B < C or D < A:
  print('No')
else:
  print('Yes')
Problem p02658 (python)

Fixed submission:
n = int(input())
lst = list(map(int, input().split()))
lst.sort()
ans = 1
for a in lst: 
    ans *= a
    if ans > 1e18:
        print(-1)
        break
else:
    print(ans)

Buggy submission (verdict: Runtime Error):
n = int(input())
lst = list(map(int, input().split()))
ans = 1
for a in lst: 
    ans *= a
	if ans > 1000000000000000000:
		print(-1)
		return
if(ans>1000000000000000000): 
    print(-1)
else:
    print(ans)

Buggy submission (verdict: Runtime Error):
n = int(input())
lst = list(map(int, input().split()))
ans = 1
for a in lst: 
    ans *= a
	if ans > 1000000000000000000:
		print(-1);
		return;
if(ans>1000000000000000000): 
    print(-1)
else:
    print(ans)
Problem p03605 (python)

Fixed submission:
n = input()
if "9" in n:
    print("Yes")
else:
    print("No")

Buggy submission (verdict: Runtime Error):
n = input()
if 9 in n:
    print("Yes")
else:
    print("No")
Problem p02562 (python)

Fixed submission:
import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")


n,k = list(map(int, input().split()))
a = [list(map(int, input().split())) for _ in range(n)]
import networkx as nx
ans = (-float("inf"), None)
f = n*k
g = nx.DiGraph()
for i in range(2*n):
    g.add_node(i)
g.add_node(2*n, demand=-f)
g.add_node(2*n+1, demand=f)
for i in range(n):
    g.add_edge(2*n, i, capacity=k, weight=0)
    g.add_edge(i+n, 2*n+1, capacity=k, weight=0)
g.add_edge(2*n, 2*n+1, capacity=f, weight=0)
for i in range(n):
    for j in range(n):
        g.add_edge(i, j+n, capacity=1, weight=-a[i][j])
val, d = nx.network_simplex(g)
vals = [["."]*n for _ in range(n)]
for i in range(n):
    for j in range(n):
        if d[i][j+n]==1:
            vals[i][j] = "X"
if -val>ans[0]:
    ans = (-val, vals)
print(ans[0])
print("\n".join("".join(ans[1][i]) for i in range(n)))

Buggy submission (verdict: Runtime Error):
import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")


n,k = list(map(int, input().split()))
a = [list(map(int, input().split())) for _ in range(n)]
import networkx as nx
ans = (-float("inf"), None)
for f in range(1,n*k+1):
    g = nx.DiGraph()
    for i in range(2*n):
        g.add_node(i)
    g.add_node(2*n, demand=-f)
    g.add_node(2*n+1, demand=f)
    for i in range(n):
        g.add_edge(2*n, i, capacity=k, weight=0)
        g.add_edge(i+n, 2*n+1, capacity=k, weight=0)

    for i in range(n):
        for j in range(n):
            g.add_edge(i, j+n, capacity=1, weight=-a[i][j])
    val, d = nx.network_simplex(g)
    vals = [["."]*n for _ in range(n)]
    for i in range(n):
        for j in range(n):
            if d[i][j+n]==1:
                vals[i][j] = "X"
    if -val>ans[0]:
        ans = (-val, vals)
print(ans[0])
print("\n".join("".join(ans[1][i]) for i in range(n)))
Problem p02609 (python)

Fixed submission:
import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")


n = int(input())
a = input()
d = {}
def sub(val):
    if val in d:
        return d[val]
    pc = 0
    for i in range(val.bit_length()):
        if val>>i&1:
            pc += 1
    if pc==0:
        ans = 0
    else:
        tmp = val % pc
        if tmp==0:
            ans = 1
        else:
            ans = sub(tmp) + 1
    d[val] = ans
    return ans

pc = sum(item=="1" for item in a)
val0 = 0 # pc-1
val1 = 0 # pc+1
for i in range(n):
    if a[i]=="1":
        if pc>1:
            val0 += pow(2,n-1-i,pc-1)
        val1 += pow(2,n-1-i,pc+1)
        
ans = [None]*n
# print(a)
for i in range(n):
    if a[i]=="1":
        if pc==1:
            val = 0
            ans[i] = 0
        else:
            val = (val0 - pow(2,n-1-i,pc-1))%(pc-1) #(1<<(n-1-i))
            ans[i] = sub(val) + 1
#         print(1, bin(val)[2:], pc-1)
    else:
        val = (val1 + pow(2,n-1-i,pc+1))%(pc+1) #(1<<(n-1-i))
        ans[i] = sub(val) + 1
#         print(0, bin(val)[2:], pc+1)
write("\n".join(map(str, ans)))

Buggy submission (verdict: Runtime Error):
import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")


n = int(input())
a = input()
d = {}
def sub(val):
    if val in d:
        return d[val]
    pc = 0
    for i in range(val.bit_length()):
        if val>>i&1:
            pc += 1
    if pc==0:
        ans = 0
    else:
        tmp = val % pc
        if tmp==0:
            ans = 1
        else:
            ans = sub(tmp) + 1
    d[val] = ans
    return ans
pc = sum(item=="1" for item in a)
val0 = 0 # pc-1
val1 = 0 # pc+1
for i in range(n):
    if a[i]=="1":
        val0 += pow(2,n-1-i,pc-1)
        val1 += pow(2,n-1-i,pc+1)
        
ans = [None]*n
# print(a)
for i in range(n):
    if a[i]=="1":
        val = (val0 - pow(2,n-1-i,pc-1))%(pc-1) #(1<<(n-1-i))
        ans[i] = sub(val) + 1
#         print(1, bin(val)[2:], pc-1)
    else:
        val = (val1 + pow(2,n-1-i,pc+1))%(pc+1) #(1<<(n-1-i))
        ans[i] = sub(val) + 1
#         print(0, bin(val)[2:], pc+1)
write("\n".join(map(str, ans)))
Problem p02641 (python)

Fixed submission:
x,n = map(int,input().split())
if n:
    p = list(map(int,input().split()))
else:
    p = []
p = set(p)
pp = set([item for item in range(0,105) if item not in p])
v = 3000
ans = -1
for item in pp:
    if v>abs(x-item):
        v = abs(x-item)
        ans = item
print(ans)

Buggy submission (verdict: Runtime Error):
import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")

x,n = map(int,input().split())
if n:
    p = list(map(int,input().split()))

p = set(p)
pp = set([item for item in range(0,101) if item not in p])
v = 3000
ans = -1
for item in pp:
    if v>abs(x-item):
        v = abs(x-item)
        ans = item
print(ans)
Problem p02702 (python)

Fixed submission:
import sys
input = lambda : sys.stdin.readline().rstrip()

import collections
s = [int(c) for c in input()]
tmp = 1
mod = 0
count = collections.defaultdict(int)
for i,num in enumerate(s[::-1]):
    mod = (tmp * num + mod) % 2019
    count[mod] += 1
    tmp *= 10
    tmp %= 2019
count[0] += 1
print(sum((item*(item-1)//2 for item in count.values())))

Buggy submission (verdict: Runtime Error):
import collections
s = [int(c) for c in input()]
tmp = 1
prev = mod
count = collections.defaultdict(int)
for i,num in enumerate(s[::-1]):
    mod = (tmp * num + mod) % 2019
    count[mod] += 1
    tmp *= 10
print(sum((item*(item-1)//2 for item in count.values())))
Problem p02714 (python)

Fixed submission:
n = int(input())
s = input()
r = []
g = []
b = []
for i, item in enumerate(s):
    if item=="R":
        r.append(i)
    elif item=="G":
        g.append(i)
    else:
        b.append(i)
if (not r) or (not g) or (not b):
    print(0)
else:
    count = 0
    for low,mid,high in [(r,g,b), (r,b,g), (g,r,b), (g,b,r), (b,r,g), (b,g,r)]:
        for m in mid:
            ind = len(high) - 1
            for l in low:
                if l >= m:
                    continue
                while (l+high[ind] > m*2) and (ind>0):
                    ind -= 1
                if m < high[ind]:
                    if l+high[ind] == m*2:
                        count += 1
    print(len(r)*len(g)*len(b) - count)

Buggy submission (verdict: Runtime Error):
n = int(input())
s = input()
r = []
g = []
b = []
for i, item in enumerate(s):
    if item=="R":
        r.append(i)
    elif item=="G":
        g.append(i)
    else:
        b.append(i)

count = 0
for low,mid,high in [(r,g,b), (r,b,g), (g,r,b), (g,b,r), (b,r,g), (b,g,r)]:
    for m in mid:
        ind = len(high) - 1
        for l in low:
            if l >= m:
                continue
            while (l+high[ind] > m*2) and (ind>0):
                ind -= 1
            if m < high[ind]:
                if l+high[ind] == m*2:
                    count += 1

#                 print(l, m, high[ind])
print(len(r)*len(g)*len(b) - count)
Problem p02715 (python)

Fixed submission:
def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])

    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])

    return arr

import numpy as np
M = int(10**9)+7
n,k = [int(c) for c in input().split()]
nums = [0]*(k+1)
nums = np.zeros((k+1), dtype=int)
for i in range(k, 0, -1):
    tmp = pow(k // i, n, M)
    tmp -= nums[(2*i)::i].sum()
    nums[i] += tmp
    
# print(sum((i)*nums[i]%M for i in range(len(nums)))%M)
print((np.arange(k+1) * nums).sum()%M)

Buggy submission (verdict: Runtime Error):
def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])

    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])

    return arr

import numpy as np
M = int(10**9)+7
n,k = [int(c) for c in input().split()]
nums = [0]*(k+1)
nums = np.zeros((k+1), dtype=int)
for i in range(k, 0, -1):
    tmp = (pow(k // i, n, M)
    tmp -= nums[(2*i)::i].sum()
    nums[i] += tmp
    
# print(sum((i)*nums[i]%M for i in range(len(nums)))%M)
print((np.arange(k+1) * nums).sum()%M)
Problem p02734 (python)

Fixed submission:


n, s = list(map(int, input().split()))
a = list(map(int, input().split()))
dp = [[None] * (s+1) for _ in range(n+1)]
M = 998244353


for j in range(s+1):
    dp[0][j] = 0
for i in range(n+1):
    dp[i][0] = i+1

for i in range(1,n+1):
    for j in range(1, s+1):
        dp[i][j] = dp[i-1][j]
        if j-a[i-1]>=0:
            dp[i][j] += dp[i-1][j-a[i-1]]
        dp[i][j] %= M
print(sum((dp[i][s] for i in range(n+1)))%M)

Buggy submission (verdict: Runtime Error):
import numba

@numba.jit
def main():
    n, s = list(map(int, input().split()))
    a = list(map(int, input().split()))
    dp = [[None] * (s+1) for _ in range(n+1)]
    M = 998244353


    for j in range(s+1):
        dp[0][j] = 0
    for i in range(n+1):
        dp[i][0] = i+1

    for i in range(1,n+1):
        for j in range(1, s+1):
            dp[i][j] = dp[i-1][j]
            if j-a[i-1]>=0:
                dp[i][j] += dp[i-1][j-a[i-1]]
            dp[i][j] %= M
    total = 0
    for i in range(n+1):
        total += dp[i][s]
    return total%M
if __name__=="__main__":
    print(main())

Buggy submission (verdict: Runtime Error):
import numpy as np
n,s = [int(c) for c in input().split()]
a = [int(c) for c in input().split()]
# t[i][j] : 0<=r<...,<l=iについて和がsになるようなf(r,l)の和
# t = [[0]*(s+1) for _ in range(n)]
t = np.zeros((n, s+1), dtype="int64")
if a[0]<=s:
    t[0,a[0]] = 1
for i in range(n):
    t[i,0] = i+2
for i in range(1,n):
    for j in range(1,s+1):
        tt = t[i-1,j]
        if j-a[i]>=0:
            tt += t[i-1,j-a[i]]
        t[i,j] = tt
print(t[:,s].sum()%998244353)
Problem p02744 (python)

Fixed submission:
# パナソニック2020D
from queue import deque
n = int(input())
q = deque([("a", "a")])
while True:
    s, m = q.pop()
    if len(s)==n:
        print(s)
    elif len(s)>=n+1:
        break
    for o in range(ord("a"), ord(m)+2):
        if ord(m)<o:
            m = chr(o)
        q.appendleft((s + chr(o), m))

Buggy submission (verdict: Runtime Error):
# パナソニック2020D
import sys
def write(x):
	sys.stdout.write(x)
    sys.stdout.write("\n")
    
from queue import deque
n = int(input())
q = deque([("a", "a")])
while True:
    s, m = q.pop()
    if len(s)==n:
        write(s)
    elif len(s)>=n+1:
        break
    for o in range(ord("a"), ord(m)+2):
        if ord(m)<o:
            m = chr(o)
        q.appendleft((s + chr(o), m))
Problem p02756 (python)

Fixed submission:

s = input()
q = int(input())
turn = 0
# ともにSに近い方から並べる
before = "" 
after = ""
for _ in range(q):
    tmp = input()
    if tmp=="1":
        turn += 1
    else:
        _,f,c = tmp.split()
        f = int(f)
        if (turn + f) % 2 == 1:
            before += c
        else:
            after += c
if turn%2==0:
    out = before[::-1] + s + after
else:
    out = after[::-1] + s[::-1] + before
print(out)

Buggy submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline
# lines = open("tmp_in").readlines()

# def _input():
#     for ss in lines:
#         yield ss.rstrip()
# input = _input().__next__

s = input()
q = int(input())
turn = 0
# ともにSに近い方から並べる
before = "" 
after = ""
for _ in range(q):
    tmp = input()
    if tmp=="1":
        turn += 1
    else:
        _,f,c = tmp.split()
        f = int(f)
        if (turn + f) % 2 == 1:
            before += c
        else:
            after += c
if turn%2==0:
    out = before[::-1] + s + after
else:
    out = after[::-1] + s[::-1] + before
print(out)
Problem p02775 (python)

Fixed submission:
# ABC155E

s = input()
d0 = [0,1,2,3,4,5,6,7,8,9]
d1 = [0,1,2,3,4,5,5,4,3,2] # 通常時

a0 = d1[int(s[0])]
a1 = d1[int(s[0]) + 1] if int(s[0])<=8 else 1

for c in s[1:]:
    c = int(c)
    b0 = min(a0 + c, a1 + (10 - c))
    b1 = min(a0 + c + 1, a1 + (9 - c)) if c <=8 else a1
    a0, a1 = b0, b1
    
print(a0)

Buggy submission (verdict: Runtime Error):
# ABC155E

s = input()
d0 = [0,1,2,3,4,5,6,7,8,9]
d1 = [0,1,2,3,4,5,5,4,3,2] # 通常時

a0 = d1[int(s[0])]
a1 = d1[int(s[0]) + 1]

for c in s[1:]:
    c = int(c)
    b0 = min(a0 + c, a1 + (10 - c))
    b1 = min(a0 + c + 1, a1 + (9 - c)) if c <=8 else a1
    a0, a1 = b0, b1
    
print(a0)
Problem p02782 (python)

Fixed submission:
import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")

M = 10**9+7 # 出力の制限
N = 2*10**6+4 # 必要なテーブルサイズ

g1 = [None] * (N+1) # 元テーブル
g2 = [None] * (N+1) #逆元テーブル
inverse = [None] * (N+1) #逆元テーブル計算用テーブル
g1[0] = g1[1] = g2[0] = g2[1] = 1
inverse[0], inverse[1] = [0, 1] 

for i in range( 2, N + 1 ):
    g1[i] = ( g1[i-1] * i ) % M 
    inverse[i] = ( -inverse[M % i] * (M//i) ) % M # ai+b==0 mod M <=> i==-b*a^(-1) <=> i^(-1)==-b^(-1)*aより
    g2[i] = (g2[i-1] * inverse[i]) % M 

def cmb(n, r, M):
    if ( r<0 or r>n ):
        return 0
    r = min(r, n-r)
    return (g1[n] * g2[r] * g2[n-r]) % M

ans = 0
r1,c1,r2,c2 = map(int, input().split())
for c in range(c1, c2+1):
    ans += cmb(r2+c, r2, M) - cmb(r1-1+c, r1-1, M)
for r in range(r1, r2+1):
    ans += cmb(c2+r, c2, M) - cmb(c1-1+r, c1-1, M)
    
# for r in range(r1+1, r2+1):
#     val = cmb(r+c1, r, M)
#     ans += val * (c2-c1) * (r2-r+1)
#     ans += val
#     ans %= M
# ans += cmb(r1+c1, r1, M)
# for c in range(c1+1, c2+1):
#     val = cmb(r1+c, c, M)
#     ans += val * (r2-r1) * (c2-c+1)
#     ans += val
#     ans %= M
print(ans%M)

Buggy submission (verdict: Runtime Error):
import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")


M = 10**9+7 # 出力の制限
N = 10**6+2 # 必要なテーブルサイズ

g1 = [None] * (N+1) # 元テーブル
g2 = [None] * (N+1) #逆元テーブル
inverse = [None] * (N+1) #逆元テーブル計算用テーブル
g1[0] = g1[1] = g2[0] = g2[1] = 1
inverse[0], inverse[1] = [0, 1] 

for i in range( 2, N + 1 ):
    g1[i] = ( g1[i-1] * i ) % M 
    inverse[i] = ( -inverse[M % i] * (M//i) ) % M # ai+b==0 mod M <=> i==-b*a^(-1) <=> i^(-1)==-b^(-1)*aより
    g2[i] = (g2[i-1] * inverse[i]) % M 

def cmb(n, r, M):
    if ( r<0 or r>n ):
        return 0
    r = min(r, n-r)
    return (g1[n] * g2[r] * g2[n-r]) % M

ans = 0
r1,c1,r2,c2 = map(int, input().split())
for c in range(c1, c2+1):
    ans += cmb(r2+c, r2, M) - cmb(r1-1+c, r1-1, M)
for r in range(r1, r2+1):
    ans += cmb(c2+r, c2, M) - cmb(c1-1+r, c1-1, M)
    
# for r in range(r1+1, r2+1):
#     val = cmb(r+c1, r, M)
#     ans += val * (c2-c1) * (r2-r+1)
#     ans += val
#     ans %= M
# ans += cmb(r1+c1, r1, M)
# for c in range(c1+1, c2+1):
#     val = cmb(r1+c, c, M)
#     ans += val * (r2-r1) * (c2-c+1)
#     ans += val
#     ans %= M
print(ans%M)
Problem p02814 (python)

Fixed submission:

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

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

def lcms(a):
    l = a[0]
    for num in a[1:]:
        l = lcm(l, num)
    return l

n, m = map(int, input().split())
a = list(map(int, input().split()))
# a2 = [num//2 for num in a]
acount = [None]*n # aを2で割れる回数
anum = [None]*n # 割ったあとの残り(=奇数)
for i,num in enumerate(a):
    c = 0
    while num%2==0 and num>1:
        num //=2
        c += 1
    acount[i] = c
    anum[i] = num
if all(item==acount[0] for item in acount):
    l = lcms(anum)
    num0 = l * (pow(2, (acount[0]-1)))
    span = num0*2
    if m<num0:
        print(0)
    else:
        print(int((m-num0)//span + 1))
else:
    print(0)

Buggy submission (verdict: Runtime Error):

def factorization(n):
    arr = {}
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr[i] = cnt

    if temp!=1:
        arr[temp] = 1

    if not arr:
        arr[n] = 1

    return arr

import math

n, m = map(int, input().split())
a = list(map(int, input().split()))
# a2 = [num//2 for num in a]
acount = [None]*n # aを2で割れる回数
anum = [None]*n # 割ったあとの残り(=奇数)
for i,num in enumerate(a):
    c = 0
    while num%2==0:
        num //=2
        c += 1
    acount[i] = c
    anum[i] = num
if all(item==acount[0] for item in acount):
    cc = {}
    lcm = anum[0]
    for num in anum[1:]:
        g = math.gcd(lcm, num)
        lcm = lcm * num / g
    num0 = lcm * (pow(2, (acount[0]-1)))
    span = num0*2
    if m<num0:
        print(0)
    else:
        print(int((m-num0)//span + 1))
else:
    print(0)