Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
import sys #追加
sys.setrecursionlimit(10*7)
 
def bit_fullsearch(target):
    n = len(target)
    ret = []
    for i in range(2**n):
        tmp = []
        for j in range(n):
            if (i>>j)&1:
                tmp.append(target[j])
        ret.append(tmp)
    return ret

n,m,x = map(int,input().split())
choice = [i for i in range(n)]
l = [list(map(int,input().split())) for _ in range(n)]
ans = float('inf')
for lst in bit_fullsearch(choice):
    tmp = 0
    A = [0 for _ in range(m)]
    if len(lst)==0:
        continue
    elif len(lst)==1:
        tmp = l[0]
        j = lst[0]
        for k in range(m):
            A[k] += l[j][1+k]
    else:
        for j in lst:
            tmp += l[j][0]
            for k in range(m):
                A[k] += l[j][1+k]
    if min(A) >= x:
        ans = min(ans, tmp)
print(ans if ans!=float('inf') else -1)

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

def bit_fullsearch(target):
    n = len(target)
    ret = []
    for i in range(2**n):
        tmp = []
        for j in range(n):
            if (i>>j)&1:
                tmp.append(target[j])
        ret.append(tmp)
    return ret

n,m,x = map(int,input().split())
lst = [list(map(int,input().split())) for _ in range(n)]
ans = float('inf')

for l in bit_fullsearch(lst):
    tmp = [0 for _ in range(m+1)]
    for k in l:
        for i in range(m+1):
            tmp[i] += k[i]
    if min(tmp[1:]) >= x:
        ans = min(ans, tmp[0])
print(ans if ans!=float('inf') else -1)

Buggy python submission (verdict: Runtime Error):
def bit_fullsearch(target):
    n = len(target)
    ret = []
    for i in range(2**n):
        tmp = []
        for j in range(n):
            if (i>>j)&1:
                tmp.append(target[j])
        ret.append(tmp)
    return ret

n,m,x = map(int,input().split())
choice = [i for i in range(n)]
l = [list(map(int,input().split())) for _ in range(n)]

ans = float('inf')
for lst in bit_fullsearch(choice):
    tmp = 0
    A = [0 for _ in range(m)]
    if len(lst)==0:
        continue
    elif len(lst)==1:
        tmp = l[0]
        j = lst[0]
        for k in range(m):
            A[k] += l[j][1+k]
    else:
        for j in lst:
            tmp += l[j][0]
            for k in range(m):
                A[k] += l[j][1+k]
    if min(A) >= x:
        ans = min(ans, tmp)
print(ans if ans!=float('inf') else -1)

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

def bit_fullsearch(target):
    n = len(target)
    ret = []
    for i in range(2**n):
        tmp = []
        for j in range(n):
            if (i>>j)&1:
                tmp.append(target[j])
        ret.append(tmp)
    return ret

n,m,x = map(int,input().split())
lst = [list(map(int,input().split())) for _ in range(n)]
ans = float('inf')

for l in bit_fullsearch(lst):
    tmp = [0 for _ in range(m+1)]
    for k in l:
        for i in range(m+1):
            tmp[i] += k[i]
    if min(tmp[1:]) >= x:
        ans = min(ans, tmp[0])
print(ans if ans!=float('inf') else -1)
Buggy python submission (verdict: Runtime Error):
n,k = map(int,input().split())
A = [0]+list(map(int,input().split()))
visited = [False for _ in range(n+1)]
pos = 1
x = []
flg = False
for i in range(k):
    if visited[pos] == False:
        x.append(pos)
        visited[pos] = True
        pos = A[pos]
    else:
        flg = True
        pre = x.index(pos)
        loop = x[pre:]
        break
print(loop[(k-pre)%len(loop)] if flg else x[k])

Fixed submission:
n,k = map(int,input().split())
A = [0]+list(map(int,input().split()))
visited = [False for _ in range(n+1)]
pos = 1
x = []
flg = False
for i in range(k):
    if visited[pos] == False:
        x.append(pos)
        visited[pos] = True
        pos = A[pos]
    else:
        flg = True
        pre = x.index(pos)
        loop = x[pre:]
        break
if not flg:
    print(pos)
else:
    print(loop[(k-pre)%len(loop)])

Buggy python submission (verdict: Runtime Error):
n,k = map(int,input().split())
A = list(map(int,input().split()))
visited = [False for _ in range(5)]
nx = A[0] - 1
x = []
p = -1
for e, i in enumerate(range(n)):
    if visited[nx] == False:
        visited[nx] = True
        x.append(nx)
        nx = A[nx] - 1
    else:
        p = x.index(nx)
        q = x[:p]
        r = x[p:]
        break
if p!=-1:
    k = (k-len(q))%len(r)
    print(r[k-1]+1)
else:
    print(x[k-1])

Fixed submission:
n,k = map(int,input().split())
A = [0]+list(map(int,input().split()))
visited = [False for _ in range(n+1)]
pos = 1
x = []
flg = False
for i in range(k):
    if visited[pos] == False:
        x.append(pos)
        visited[pos] = True
        pos = A[pos]
    else:
        flg = True
        pre = x.index(pos)
        loop = x[pre:]
        break
if not flg:
    print(pos)
else:
    print(loop[(k-pre)%len(loop)])
Buggy python submission (verdict: Time Limit Exceeded):
import math
def f(x,y,z):
    # x,y,z = A,x,B
    return math.floor(x*y/z) - x*math.floor(y/z)
a,b,n = map(int,input().split())
if n<b:
    print(math.floor(a*n/b))
else:
    k = n//b
    ret = f(a, b-1, b)
    for kk in range(1, k+1):
        ret = max(ret, f(a,b*kk-1,b))
    print(ret)

Fixed submission:
import math
def f(x,y,z):
    # x,y,z = A,x,B
    return math.floor(x*y/z) - x*math.floor(y/z)
a,b,n = map(int,input().split())
if n<b:
    print(math.floor(a*n/b))
else:
    print(f(a, b-1, b))

Buggy python submission (verdict: Runtime Error):
import math
def f(x,y,z):
    # x,y,z = A,x,B
    return math.floor(x*y/z) - x*math.floor(y/z)

a,b,n = map(int,input().split())
if n<b:
    print(math.floor(a*n/b))
else:
    k = n//b
    x = b*k-1
    print(f(a,x,b) - a*f(x,b))

Fixed submission:
import math
def f(x,y,z):
    # x,y,z = A,x,B
    return math.floor(x*y/z) - x*math.floor(y/z)
a,b,n = map(int,input().split())
if n<b:
    print(math.floor(a*n/b))
else:
    print(f(a, b-1, b))

Buggy python submission (verdict: Runtime Error):
import math
def f(x,y,z):
    # x,y,z = A,x,B
    return math.floor(x*y/z) - x*math.floor(y/z)

a,b,n = map(int,input().split())
if n<b:
    print(math.floor(a*n/b))
else:
    k = n//b
    x = b*k-1
    print(f(a,x,b) - a*f(x,b))

Fixed submission:
import math
def f(x,y,z):
    # x,y,z = A,x,B
    return math.floor(x*y/z) - x*math.floor(y/z)
a,b,n = map(int,input().split())
if n<b:
    print(math.floor(a*n/b))
else:
    print(f(a, b-1, b))

Buggy python submission (verdict: Time Limit Exceeded):
import math

def f(x,y,z):
    # x,y,z = A,x,B
    return math.floor(x*y/z) - x*math.floor(y/z)

a,b,n = map(int,input().split())
if n<b:
    print(math.floor(a*n/b))
else:
    k = n%b
    ret = f(a, b-1, b)
    for j in range(1, k+1):
        ret = max(ret, f(a, b*k-1, b))
    print(ret)

Fixed submission:
import math
def f(x,y,z):
    # x,y,z = A,x,B
    return math.floor(x*y/z) - x*math.floor(y/z)
a,b,n = map(int,input().split())
if n<b:
    print(math.floor(a*n/b))
else:
    print(f(a, b-1, b))
Buggy python submission (verdict: Runtime Error):
import copy
n,k,c = map(int,input().split())
dp = [0]*(n+c+2)
s = input()
idx = []
for i in range(n):
    if s[i]=='o':
        idx.append(i+1)
for i in idx:
    dp[i] += 1
    dp[i+c+1] -= 1
for i in range(1,len(dp)):
    dp[i] = dp[i]+dp[i-1]       

for i in idx:
    tmp = copy.deepcopy(dp)
    for j in range(i, i+c+1):
        tmp[j] -= 1
    cnt = 0
    flg = False
    for j in range(len(tmp[1:-1])):
        if tmp[1+j]!=0 and flg==False:
            flg = True
            cnt += 1
        if tmp[1+j]!=0 and flg:
            continue
        if tmp[1+j]==0:
            flg = False
    if cnt<k:
        print(i)

Fixed submission:
k = int(input())
ans = [str(i) for i in range(1, 10)]
tmp = [str(i) for i in range(1, 10)]
cnt = 10
if k<=9:
    print(k)
else:
    while cnt<=k:
        ap = []
        for t in tmp:
            if t[-1]=='0':
                ap.append(t+'0')
                ap.append(t+'1')
            elif t[-1]=='9':
                ap.append(t+'8')
                ap.append(t+'9')
            else:
                l = int(t[-1])
                ap.append(t+str(l-1))
                ap.append(t+str(l))
                ap.append(t+str(l+1))
        cnt += len(ap)
        tmp = ap
    print(tmp[k-cnt])
Buggy python submission (verdict: Runtime Error):
import numpy as np
import copy
n,k,c = map(int,input().split())
dp = [0]*(n+c+2)
s = input()
idx = []
for i in range(n):
    if s[i]=='o':
        idx.append(i+1)
for i in idx:
    dp[i] += 1
    dp[i+c+1] -= 1
dp = np.cumsum(dp).tolist()

for i in idx:
    tmp = copy.deepcopy(dp)
    for j in range(i, i+c+1):
        tmp[j] -= 1

    cnt = 0
    flg = False
    for j in range(len(tmp[1:-1])):
        if tmp[1+j]!=0 and flg==False:
            flg = True
            cnt += 1
        if tmp[1+j]!=0 and flg:
            continue
        if tmp[1+j]==0:
            flg = False
    if cnt<k:
        print(i)

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

lst = []
for i in range(n):
    if s[i]=='o':
        lst.append(i+1)

x,y = [],[]
for i in range(len(lst)):
    if i==0:
        x.append(lst[i])
    else:
        if lst[i]-x[-1]>c:
            x.append(lst[i])
    if len(x)==k:
        break

for i in range(len(lst))[::-1]:
    if i==len(lst)-1:
        y.append(lst[i])
    else:
        if y[-1]-lst[i]>c:
            y.append(lst[i])
    if len(y)==k:
        break

x.sort()
y.sort()

ans = []
for i in range(k):
    if x[i]==y[i]:
        ans.append(x[i])
for a in ans:
    print(a)

Buggy python submission (verdict: Time Limit Exceeded):
from itertools import combinations
n,k,c = map(int,input().split())
s = input()
idx = []
for i in range(n):
    if s[i]=='o':
        idx.append(i+1)
dic = {}
for i in idx:
    dic[i] = 0
cnt = 0
for l in combinations(idx, k):
    l = list(l)
    flg = True
    for j in range(1, len(l)):
        if l[j]-l[j-1]<=c:
            flg = False
    if flg:
        cnt += 1
        for x in l:
            dic[x] = dic[x] + 1

for k,v in dic.items():
    if v==cnt:
        print(k)

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

lst = []
for i in range(n):
    if s[i]=='o':
        lst.append(i+1)

x,y = [],[]
for i in range(len(lst)):
    if i==0:
        x.append(lst[i])
    else:
        if lst[i]-x[-1]>c:
            x.append(lst[i])
    if len(x)==k:
        break

for i in range(len(lst))[::-1]:
    if i==len(lst)-1:
        y.append(lst[i])
    else:
        if y[-1]-lst[i]>c:
            y.append(lst[i])
    if len(y)==k:
        break

x.sort()
y.sort()

ans = []
for i in range(k):
    if x[i]==y[i]:
        ans.append(x[i])
for a in ans:
    print(a)
Buggy python submission (verdict: Runtime Error):
lst = [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]
print(lst[int(input()-1)])

Fixed submission:
lst = [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]
print(lst[int(input())-1])
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
s = input()
q = int(input())
for query in range(q):
    x,y,z = list(input().split())
    if x=='1':
        y = int(y)
        s = s[:y-1] + z + s[y:]
    else:
        y,z = int(y), int(z)
        print(len(set(list(s[y-1:z]))))

Fixed submission:
class BIT:
    def __init__(self, n):
        """
            data : BIT木データ
            el : 元配列
        """
        self.n = n
        self.data = [0]*(n+1)
        self.el = [0]*(n+1)
    
    """A1 ~ Aiまでの累積和"""
    def Sum(self, i):
        s = 0
        while i > 0:
            s += self.data[i]
            i -= i & (-i)   #LSB(Least Significant Bit)の獲得:i&(-i)
        return s
    
    """Ai += x"""
    def Add(self, i, x):
        self.el[i] += x
        while i <= self.n:
            self.data[i] += x
            i += i & -i
    
    """Ai ~ Ajまでの累積和"""
    def Get(self, i, j=None):
        if j is None:
            return self.el[i]
        return self.Sum(j) - self.Sum(i)

def ctoi(c):
    return ord(c) - 97

n = int(input())
s = list(input())
q = int(input())

bits = [BIT(n) for _ in range(26)]
ans = []
for i in range(n):
    bits[ctoi(s[i])].Add(i+1, 1)
for _ in range(q):
    line = list(input().split())
    if line[0] == '1':
        idx = int(line[1])
        bits[ctoi(s[idx-1])].Add(idx, -1)
        s[idx-1] = line[2]
        bits[ctoi(line[2])].Add(idx, 1) 
    else:
        l,r = int(line[1]), int(line[2])
        cnt = 0
        for i in range(26):
            if bits[i].Get(l-1,r)!=0:
                cnt += 1
        ans.append(cnt)
for a in ans:
    print(a)
Buggy python submission (verdict: Runtime Error):
class Cmb:
    def __init__(self, N=10**5, mod=10**9+7):
        self.fact = [1,1]
        self.fact_inv = [1,1]
        self.inv = [0,1]
        
        """ 階乗を保存する配列を作成 """
        for i in range(2, N+1):
            self.fact.append((self.fact[-1]*i) % mod)
            self.inv.append((-self.inv[mod%i] * (mod//i))%mod)
            self.fact_inv.append((self.fact_inv[-1]*self.inv[i])%mod)
    
    """ 関数として使えるように、callで定義 """
    def __call__(self, n, r, mod=10**9+7):
        if (r<0) or (n<r):
            return 0
        r = min(r, n-r)
        return self.fact[n] * self.fact_inv[r] * self.fact_inv[n-r] % mod

n,a,b = map(int,input().split())
c = Cmb()
mod = 10**9+7
print((pow(2,n,mod) - 1 - c(n,a) - c(n,b))%mod)



Fixed submission:
n,a,b = map(int,input().split())
mod = 10**9+7
ans = pow(2,n,mod)-1

comb1 = 1
for i in range(n-a+1, n+1):
    comb1 *= i
    comb1 %=  mod
for i in range(1, a+1):
    comb1 *= pow(i, mod-2, mod)
    comb1 %=  mod

comb2 = 1
for i in range(n-b+1, n+1):
    comb2 *= i
    comb2 %=  mod
for i in range(1, b+1):
    comb2 *= pow(i, mod-2, mod)
    comb2 %=  mod
ans -= (comb1 + comb2)
print(ans % mod)

Buggy python submission (verdict: Runtime Error):
n,a,b = map(int,input().split())
mod=10**9+7

def sig(n):
    #return 2**n
    if n==1:
        return 2
    elif n%2==0:
        return (sig(n//2)**2)%mod
    else:
        return (2*sig((n-1)//2)**2)%mod
    
s = sig(n) - 1

MAX = 10**5*3

facts = [1 for i in range(n)]
invs = [1 for i in range(n)]

def inv(x):
	return pow(x,mod-2,mod)
 
for i in range(1,MAX):
		facts[i] = (facts[i-1] * i)% mod
		invs[i] = inv(facts[i])

def nCr(n,r):
	return facts[n]*invs[r] * invs[n-r] % mod

x = nCr(n,a)%mod
y = nCr(n,b)%mod

if s-(x+y) < 0:
    print(s-(x+y)+mod)
else:
    print(s-(x+y)%mod)

Fixed submission:
n,a,b = map(int,input().split())
mod = 10**9+7
ans = pow(2,n,mod)-1

comb1 = 1
for i in range(n-a+1, n+1):
    comb1 *= i
    comb1 %=  mod
for i in range(1, a+1):
    comb1 *= pow(i, mod-2, mod)
    comb1 %=  mod

comb2 = 1
for i in range(n-b+1, n+1):
    comb2 *= i
    comb2 %=  mod
for i in range(1, b+1):
    comb2 *= pow(i, mod-2, mod)
    comb2 %=  mod
ans -= (comb1 + comb2)
print(ans % mod)
Buggy python submission (verdict: Time Limit Exceeded):
class Cmb:
    def __init__(self, N, mod=10**9+7):
        self.fact = [1,1]
        self.fact_inv = [1,1]
        self.inv = [0,1]
        
        """ 階乗を保存する配列を作成 """
        for i in range(2, N+1):
            self.fact.append((self.fact[-1]*i) % mod)
            self.inv.append((-self.inv[mod%i] * (mod//i))%mod)
            self.fact_inv.append((self.fact_inv[-1]*self.inv[i])%mod)
    
    """ 関数として使えるように、callで定義 """
    def __call__(self, n, r, mod=10**9+7):
        if (r<0) or (n<r):
            return 0
        r = min(r, n-r)
        return self.fact[n] * self.fact_inv[r] * self.fact_inv[n-r] % mod

n,k = map(int,input().split())
mod = 10**9+7
c = Cmb(N=n)
ans = 0
for l in range(k+1):
    tmp = c(n,l)*c(n-1, n-l-1)
    ans += tmp%mod
print(ans%mod)

Fixed submission:
class Cmb:
    def __init__(self, N, mod=10**9+7):
        self.fact = [1,1]
        self.fact_inv = [1,1]
        self.inv = [0,1]
        
        """ 階乗を保存する配列を作成 """
        for i in range(2, N+1):
            self.fact.append((self.fact[-1]*i) % mod)
            self.inv.append((-self.inv[mod%i] * (mod//i))%mod)
            self.fact_inv.append((self.fact_inv[-1]*self.inv[i])%mod)
    
    """ 関数として使えるように、callで定義 """
    def __call__(self, n, r, mod=10**9+7):
        if (r<0) or (n<r):
            return 0
        r = min(r, n-r)
        return self.fact[n] * self.fact_inv[r] * self.fact_inv[n-r] % mod

n,k = map(int,input().split())
mod = 10**9+7
c = Cmb(N=n)
ans = 0
for l in range(min(k+1, n)):
    tmp = c(n,l)*c(n-1, n-l-1)
    ans += tmp%mod
print(ans%mod)
Buggy python submission (verdict: Runtime Error):
def comb(x,y):
    if y==1:
        return x
    elif y==2:
        return max(x*(x-1)//2, 0)
    elif y==3:
        return max(x*(x-1)*(x-2)//6, 0)


n = int(input())
k = int(input())
digit = len(str(n))
ans1 = comb(digit-1, k) * (9**k)
lst = [int(i) for i in list(str(n))]
if k==1:
    ans2 = lst[0]
elif k==2:
    ans2 = 0
    ans2 += (lst[0]-1) * (digit-1) * 9
    ans2 += lst[1] + (digit-2)*9
elif k==3:
    ans2 = 0
    ans2 += (lst[0]-1) * comb(digit-1, 2) * (9*2)
    ans2 += lst[1]*(digit-2)*9 + comb(digit-2, 2)*(9**2)
print(ans1+ans2)

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

# dp[i桁まで][非0個数][未満フラグ]
dp = [[[0]*2 for _ in range(k+1)] for _ in range(len(n)+1)]
dp[0][0][0] = 1

for i in range(len(n)):
    x = int(n[i])
    for j in range(k):
        dp[i+1][j+1][1] += dp[i][j][1]*9
        dp[i+1][j][1] += dp[i][j][1]
        if x>0:
            dp[i+1][j][1] += dp[i][j][0]
            dp[i+1][j+1][1] += dp[i][j][0]*(x-1)
            dp[i+1][j+1][0] += dp[i][j][0]
        else:
            dp[i+1][j][0] += dp[i][j][0]
    dp[i+1][k][1] += dp[i][k][1]
    dp[i+1][k][x>0] += dp[i][k][0]

print(sum(dp[len(n)][k]))

Buggy python submission (verdict: Runtime Error):
def comb(x,y):
    if y==1:
        return x
    elif y==2:
        return max(x*(x-1)//2, 0)
    elif y==3:
        return max(x*(x-1)*(x-2)//6, 0)


n = int(input())
k = int(input())
digit = len(str(n))

ans1 = comb(digit-1, k) * (9**k)

lst = [int(i) for i in list(str(n))]
if k==1:
    ans2 = lst[0]
elif k==2:
    ans2 = 0
    ans2 += (lst[0]-1) * (digit-1) * 9
    ans2 += lst[1] + (digit-2)*9
elif k==3:
    ans2 = 0
    ans2 += (lst[0]-1) * comb(digit-1, 2) * (9**2)
    ans2 += lst[1]*(digit-2)*9 + comb(digit-2, 2)*(9**2)
    
print(ans1+ans2)

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

# dp[i桁まで][非0個数][未満フラグ]
dp = [[[0]*2 for _ in range(k+1)] for _ in range(len(n)+1)]
dp[0][0][0] = 1

for i in range(len(n)):
    x = int(n[i])
    for j in range(k):
        dp[i+1][j+1][1] += dp[i][j][1]*9
        dp[i+1][j][1] += dp[i][j][1]
        if x>0:
            dp[i+1][j][1] += dp[i][j][0]
            dp[i+1][j+1][1] += dp[i][j][0]*(x-1)
            dp[i+1][j+1][0] += dp[i][j][0]
        else:
            dp[i+1][j][0] += dp[i][j][0]
    dp[i+1][k][1] += dp[i][k][1]
    dp[i+1][k][x>0] += dp[i][k][0]

print(sum(dp[len(n)][k]))
Buggy python submission (verdict: Time Limit Exceeded):
h,n = map(int,input().split())
dg = 10**5

ba = []
for _ in [0]*n:
    a,b = map(int,input().split())
    if a >= h:
        a = h
    ba.append(b*dg + a)
ba.sort()

d = [10**9]*(h+1)
d[0] = 0

for i in range(1, h+1):
    for e in ba:
        a,b = e%dg, e//dg
        if i<=a:
            if d[i] > b:
                d[i] = b
        else:
            if d[i] > d[i-a]+b:
                d[i] = d[i-a]+b
print(d[-1])

Fixed submission:
h,n = map(int,input().split())
dg = 10**5

ba = []
for _ in [0]*n:
    a,b = map(int,input().split())
    if a >= h:
        a = h
    ba.append(b*dg + a)
ba.sort()

d = [10**9]*(h+1)
d[0] = 0

for i in range(1, h+1):
    for e in ba:
        a,b = e%dg, e//dg
        if i<=a:
            if d[i] > b:
                d[i] = b
        else:
            if d[i] > d[i-a]+b:
                d[i] = d[i-a]+b
print(d[-1])
Buggy python submission (verdict: Runtime Error):
import math

"""最小公倍数"""
def lcm(a,b):
    f = math.gcd(a,b)
    return a*b//f

n,m = map(int,input().split())
A = list(map(int,input().split()))
l = A[0]
for a in A[1:]:
    l = lcm(l, a)
flg = True
for a in A:
    if (l//a)%2==0:
        flg = False
if not flg:
    print(0)
else:
    minx = l//2
    if minx>m:
        print(0)
    else:
        print(1 + m//l)

Fixed submission:
import fractions
"""最小公倍数"""
def lcm(a,b):
    f = fractions.gcd(a,b)
    return a*b//f

n,m = map(int,input().split())
A = list(map(int,input().split()))
l = A[0]
for a in A[1:]:
    l = lcm(l, a)

if n==1:
    if l%2!=0:
        print(0)
    else:
        if l/2>m:
            print(0)
        else:
            print(1 + int((m-l//2)/l))

else:
    flg = True
    for a in A:
        if (l//a)%2==0:
            flg = False
    if not flg:
        print(0)
    else:
        minx = l//2
        if minx>m:
            print(0)
        else:
            print(1 + int((m-minx)//l))
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
lst = list(map(int,input().split()))
mod = 10**9+7

bit_lst = []
for i in range(n):
    bit_lst.append(format(lst[i], '060b'))
    
ans = 0
for i in range(60):
    tmp = []
    for j in range(n):
        tmp.append(bit_lst[j][i])
    
    cnt_one = tmp.count('1')
    cnt_zero = n - cnt_one
    
    tmp = cnt_one * cnt_zero
    for j in range(59 - i):
        tmp = (tmp * 2) % mod
    ans += tmp
print(ans%mod)

Fixed submission:
import numpy as np

n = int(input())
a = np.array(list(map(int,input().split())))

mod = 10**9 + 7
ans = 0

for j in range(60):
    li = (a >> j) & 1
    i = np.count_nonzero(li)
    o = n - i
    ans += i*o*2**j
    ans %= mod

print(ans % mod)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
lst = list(map(int,input().split()))
mod = 10**9+7

bit_lst = []
for i in range(n):
    bit_lst.append(format(lst[i], '060b'))
    
ans = 0
for i in range(60):
    tmp = []
    for j in range(n):
        tmp.append(bit_lst[j][i])
    
    cnt_one = tmp.count('1')
    cnt_zero = n - cnt_one
    
    tmp = cnt_one * cnt_zero
    for j in range(59 - i):
        tmp = (tmp * 2) % mod
    ans += tmp
print(ans%mod)

Fixed submission:
import numpy as np

n = int(input())
a = np.array(list(map(int,input().split())))

mod = 10**9 + 7
ans = 0

for j in range(60):
    li = (a >> j) & 1
    i = np.count_nonzero(li)
    o = n - i
    ans += i*o*2**j
    ans %= mod

print(ans % mod)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
s = input()
res = 0
for i in range(1000):
    tmp = str(i).rjust(3, '0')
    state = 0
    for j in range(n):
        if state == 3:
            continue
        elif s[j] == tmp[state]:
            state += 1
    else:
        if state==3:
            res += 1
print(res)

Fixed submission:

n = int(input())
s = input()

lst = [[] for i in range(10)]

for i in range(n):
    c = int(s[i])
    lst[c].append(i)

done = []
cnt = 0
for x in range(0,1000):
    tmp = str(x).rjust(3,'0')
    c1,c2,c3 = int(tmp[0]),int(tmp[1]),int(tmp[2])
    
    mi = -1
    mx = -1
    if len(lst[c1]) != 0:
        mi = lst[c1][0]
    if len(lst[c3]) != 0:
        mx = lst[c3][-1]
    
    if mi >= 0 and mx >= 0:
        for y in lst[c2]:
            if mi < y < mx:
                done.append(tmp)
    else:
        continue
        

print(len(set(done)))