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

Fixed submission:
L,R = map(int,input().split())

mod = 10**9+7
m = 64 +1
fac = [1]*m
ninv = [1]*m
finv = [1]*m
for i in range(2,m):
    fac[i] = fac[i-1]*i%mod
    ninv[i] = (-(mod//i)*ninv[mod%i])%mod
    finv[i] = finv[i-1]*ninv[i]%mod

def comb(n,k):
    return (fac[n]*finv[k]%mod)*finv[n-k]%mod

def f(N):
    if N==0:return 0
    S = bin(N)[2:]
    L = len(S)
    ret = pow(2,S.count("1")-1,mod)
    for i in range(L):
        if S[i] == "0" : continue
        c = S[:i].count("1")
        j = max(0,L-i-1)
        for k in range(j+1):
            if c+k == 0 : continue
            ret += pow(2,c+k-1,mod)*comb(j,k)
            ret %= mod
    return ret

def g(R,L):
    if L==0 : return 0
    Nr = len(bin(R))-2
    Nl = len(bin(L))-2
    if Nr!=Nl :
        R = int("1"*Nl,2)
        Nr = Nl
    ret = f(int("0"+"1"*(Nr-1),2))
    
    R = bin(R)[2:]
    L = bin(L)[2:]
    for i in range(Nr):
        if R[i] == "0": continue
        if i==0 : R2 = R
        else: R2 = R[:i] + "0" + "?"*(Nr-i-1)
        for j in range(Nl):
            if L[j] == "0" : continue
            if j==0 : L2 = L
            else: L2 = L[:j] + "0" + "?"*(Nl-j-1)
            tmp = 1
            for r,l in zip(R2,L2):
                if r==l=="?" : tmp *= 3
                if r=="?" and l=="0" : tmp *= 2
                if r=="1" and l=="?" : tmp *= 2
                if r=="0" and l=="1" : tmp *= 0
                tmp %= mod
            ret += tmp
    return ret

print((f(R)-g(R,L-1))%mod)

Buggy submission (verdict: Runtime Error):
L,R = map(int,input().split())

mod = 10**9+7
m = 64 +1
fac = [1]*m
ninv = [1]*m
finv = [1]*m
for i in range(2,m):
    fac[i] = fac[i-1]*i%mod
    ninv[i] = (-(mod//i)*ninv[mod%i])%mod
    finv[i] = finv[i-1]*ninv[i]%mod

def comb(n,k):
    return (fac[n]*finv[k]%mod)*finv[n-k]%mod

def f(N):
    S = bin(N)[2:]
    L = len(S)
    ret = pow(2,S.count("1")-1,mod)
    for i in range(L):
        if S[i] == "0" : continue
        c = S[:i].count("1")
        j = max(0,L-i-1)
        for k in range(j+1):
            if c+k == 0 : continue
            ret += pow(2,c+k-1,mod)*comb(j,k)
            ret %= mod
    return ret

ans = (f(R)-f(L-1))%mod
print(ans)
Problem p02949 (python)

Fixed submission:
def connect_dfs(N,E,start):
    connect = {start}
    q = [start]
    while q:
        i = q.pop()
        for j in E[i]:
            if j in connect:continue
            connect.add(j)
            q.append(j)
    return connect

def remove_Edge(N,Ef,Eb,start,goal):
    v = connect_dfs(N,Ef,start) & connect_dfs(N,Eb,goal)
    for i in range(N):
        if i in v:continue
        for j in Eb[i]:
            Ef[j].pop(i)

def Bellman_Ford(N,E,start,INFTY=10**18):
    def update(dist,N,E,start):
        done = [False]*N
        done[start] = True
        q = [start]
        d = dist[:]
        while q:
            i = q.pop()
            di = d[i]
            for j,c in E[i].items():
                d[j] = min(d[j],d[i]+c)
                if not done[j]:
                    q.append(j)
                    done[j] = True
        return d
    #
    d = [INFTY]*N
    d[start] = 0
    for _ in range(N-1):
        d = update(d,N,E,start)
    if d!=update(d,N,E,start): return None
    else: return d

N,M,P = map(int,input().split())
ABC = [list(map(int,input().split())) for _ in [0]*M]

Ef = [{} for _ in [0]*N]
Eb = [{} for _ in [0]*N]
INFTY = 10**18
for a,b,c in ABC:
    Ef[a-1][b-1] = min(P-c,Ef[a-1].get(b-1,INFTY))
    Eb[b-1][a-1] = min(P-c,Eb[b-1].get(a-1,INFTY))
    
remove_Edge(N,Ef,Eb,0,N-1)
d = Bellman_Ford(N,Ef,0)

if d==None:ans=-1
else:ans = max(0,-d[-1])
print(ans)

Buggy submission (verdict: Runtime Error):
N,M,P = map(int,input().split())
ABC = [list(map(int,input().split())) for _ in [0]*M]

Ef = [{} for _ in [0]*N]
Eb = [{} for _ in [0]*N]

for a,b,c in ABC:
    Ef[a-1][b-1] = P-c
    Eb[b-1][a-1] = P-c

#pre process

d = [-1]*N
d[0] = 0
q = [0]
while q:
    i = q.pop()
    di = d[i]
    for j in Ef[i]:
        if d[j] != -1 : continue
        d[j] = di + 1
        q.append(j)

for i in range(N):
    if d[i] != -1: continue
    for j in Ef[i]:
        Eb[j].pop(i)
    Ef[i] = {}

d = [-1]*N
d[N-1] = 0
q = [N-1]
while q:
    i = q.pop()
    di = d[i]
    for j in Eb[i]:
        if d[j] != -1 : continue
        d[j] = di + 1
        q.append(j)

for i in range(N):
    if d[i] != -1: continue
    for j in Eb[i]:
        Ef[j].pop(i)
    Eb[i] = {}

#main process
ans = 0
d = [None]*N
d[0] = 0
for _ in [0]*N:
    done = [False]*N
    q = [0]
    while q:
        i = q.pop()
        if done[i]: continue
        done[i] = True
        di = d[i]
        for j,c in Ef[i].items():
            if d[j] == None:
                d[j] = di + c
            else:
                d[j] = min(d[j],di+c)
            if done[j]:continue
            q.append(j)

ans = d[-1]
check = d[:]

#check
for _ in [0]:
    done = [False]*N
    q = [0]
    while q:
        i = q.pop()
        if done[i]: continue
        done[i] = True
        di = d[i]
        for j,c in Ef[i].items():
            if d[j] == None:
                d[j] = di + c
            else:
                d[j] = min(d[j],di+c)
            if done[j]:continue
            q.append(j)

if check!=d: ans = -1/0
else: ans = -min(0,ans)

print(ans)
Problem p02960 (python)

Fixed submission:
S = input()

mod = 10**9+7
N = len(S)
ans = 0

memo = {}
for i in range(1000):
    s = str(i).zfill(3)
    memo[s] = [0 for _ in [0]*13]
    memo[s][i%13] = 1

def rep_Q_count(s):
    memo[s] = [0 for _ in [0]*13]
    for q in range(10):
        s2 = s.replace("?",str(q),1)
        for i,n in enumerate(memo[s2]):
            memo[s][i] += n

for i in range(100):
    s = str(i).zfill(2)
    rep_Q_count(s+"?")
    rep_Q_count(s[0]+"?"+s[1])
    rep_Q_count("?"+s)
for i in range(10):
    s = str(i)
    rep_Q_count(s+"??")
    rep_Q_count("?"+s+"?")
    rep_Q_count("??"+s)
rep_Q_count("???")

s0 = S[max(0,N-3):N].zfill(3)
dp = memo[s0][:]
for i in range(1,(N-1)//3+1):
    s = S[max(0,N-(i+1)*3):N-i*3].zfill(3)
    j = i%2
    tmp = memo[s]
    dp2 = [0]*13
    for k,n in enumerate(tmp):
        for l,m in enumerate(dp):
            dp2[(l+k*((-1)**j))%13] += n*m
    dp = dp2
    for i in range(13):
        dp[i] %= mod
print(dp[5])

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

mod = 10**9+7
N = len(S)
ans = 0

memo = {}
for i in range(1000):
    s = str(i).zfill(3)
    memo[s] = [0 for _ in [0]*13]
    memo[s][i%13] = 1

def rep_Q_count(s):
    memo[s] = [0 for _ in [0]*13]
    for q in range(10):
        s2 = s.replace("?",str(q),1)
        for i,n in enumerate(memo[s2]):
            memo[s][i] += n

for i in range(100):
    s = str(i).zfill(2)
    rep_Q_count(s+"?")
    rep_Q_count(s[0]+"?"+s[1])
    rep_Q_count("?"+s)
for i in range(10):
    s = str(i)
    rep_Q_count(s+"??")
    rep_Q_count("?"+s+"?")
    rep_Q_count("??"+s)
rep_Q_count("???")

s0 = S[N-3:N]
dp = memo[s0][:]
for i in range(1,(N-1)//3+1):
    s = S[max(0,N-(i+1)*3):N-i*3].zfill(3)
    j = i%2
    tmp = memo[s]
    dp2 = [0]*13
    for k,n in enumerate(tmp):
        for l,m in enumerate(dp):
            dp2[(l+k*((-1)**j))%13] += n*m
    dp = dp2
    for i in range(13):
        dp[i] %= mod
print(dp[5])

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

mod = 10**9+7
N = len(S)
ans = 0

memo = {}
for i in range(1000):
    s = str(i).zfill(3)
    memo[s] = [0 for _ in [0]*13]
    memo[s][i%13] = 1

def rep_Q_count(s):
    memo[s] = [0 for _ in [0]*13]
    for q in range(10):
        s2 = s.replace("?",str(q),1)
        for i,n in enumerate(memo[s2]):
            memo[s][i] += n

for i in range(100):
    s = str(i).zfill(2)
    rep_Q_count(s+"?")
    rep_Q_count(s[0]+"?"+s[1])
    rep_Q_count("?"+s)
for i in range(10):
    s = str(i)
    rep_Q_count(s+"??")
    rep_Q_count("?"+s+"?")
    rep_Q_count("??"+s)
rep_Q_count("???")

s0 = S[N-3:N]
dp = memo[s0][:]
for i in range(1,(N-1)//3+1):
    s = S[max(0,N-(i+1)*3):N-i*3]
    j = i%2
    tmp = memo[s]
    dp2 = [0]*13
    for k,n in enumerate(tmp):
        for l,m in enumerate(dp):
            dp2[(l+k*((-1)**j))%13] += n*m
    dp = dp2
    for i in range(13):
        dp[i] %= mod
print(dp[5])
Problem p02972 (python)

Fixed submission:
N = int(input())
*A, = map(int,input().split())
D = [0]*(N+1)
ans = []
for i in range(N,0,-1):
    if D[i]%2 != A[i-1]:
        ans.append(i)
        for j in range(1,int(i**0.5)+1):
            if i%j==0:
                D[j] += 1
                if i//j != j:D[i//j] += 1
print(len(ans))
print(*ans)

Buggy submission (verdict: Runtime Error):
def get_divisor(n):
    if n==1:return [1]
    for i in range(1,int(n**0.5)+1):
        if n%i==0:
            a.append(i)
            b.append(n//i)
    if a[-1]==b[-1]:b.pop()
    a.extend(b[::-1])
    return a

N = int(input())
*A, = map(int,input().split())
D = [0]*(N+1)
ans = []
for i in range(N,0,-1):
    if D[i]%2 != A[i-1]:
        ans.append(i)
        for j in get_divisor(i):
            D[j]+=1
print(len(ans))
print(*ans)
Problem p03006 (python)

Fixed submission:
N=int(input())
xy=[list(map(int,input().split())) for _ in [0]*N]

pq = {0:0}
for i in range(N):
    for j in range(N):
        if i==j:continue
        p = xy[i][0] - xy[j][0]
        q = xy[i][1] - xy[j][1]
        pq[(p,q)] = pq.get((p,q),0)+1

print(N - max(pq.values()))

Buggy submission (verdict: Runtime Error):
N=int(input())
xy=[list(map(int,input().split())) for _ in [0]*N]

pq = dict()
for i in range(N):
    for j in range(N):
        if i==j:continue
        p = xy[i][0] - xy[j][0]
        q = xy[i][1] - xy[j][1]
        pq[(p,q)] = pq.get((p,q),0)+1

print(N - max(pq.values()))

Buggy submission (verdict: Runtime Error):
N=int(input())
xy=[list(map(int,input().split())) for _ in [0]*N]

dx = [[10**10]*N for _ in [0]*N]
dy = [[10**10]*N for _ in [0]*N]
ps = set()
qs = set()
for i in range(N):
    for j in range(N):
        if i==j:continue
        dx[i][j] = xy[i][0] - xy[j][0]
        dy[i][j] = xy[i][1] - xy[j][1]
        ps.add(dx[i][j])
        qs.add(dy[i][j])
for i in range(N):
    dx[i] = set(dx[i]) - set(10**10)
    dy[i] = set(dy[i]) - set(10**10)

ans = 0
for p in ps:
    for q in qs:
        cnt = 0
        for i in range(N):
            if (p in dx[i]) and (q in dy[i]):
                cnt += 1
        ans = max(ans,cnt)

print(N-ans)

Buggy submission (verdict: Runtime Error):
N=int(input())
xy=[list(map(int,input().split())) for _ in [0]*N]

dx = [[10**10]*N for _ in [0]*N]
dy = [[10**10]*N for _ in [0]*N]
ps = set()
qs = set()
for i in range(N):
    for j in range(N):
        if i==j:continue
        dx[i][j] = xy[i][0] - xy[j][0]
        dy[i][j] = xy[i][1] - xy[j][1]
        ps.add(dx[i][j])
        qs.add(dy[i][j])
for i in range(N):
    dx[i] = set(dx[i]) - set(10**10)
    dy[i] = set(dy[i]) - set(10**10)

ans = 0
for p in ps:
    for q in qs:
        cnt = 0
        for i in range(N):
            if (p in dx[i]) and (q in dy[i]):
                cnt += 1
        ans = max(ans,cnt)

print(N-ans)
Problem p03007 (python)

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

A.sort()

for i,a in enumerate(A):
    if a>=0:break
B = A[:i]
C = A[i:]

ans = []
if not B:
    x = C[0]
    for a in C[1:-1]:
        ans.append((x,a))
        x -= a
    ans.append((C[-1],x))
    x = C[-1] - x
elif not C:
    x = B[-1]
    for a in B[:-1]:
        ans.append((x,a))
        x -= a
else:
    x = B[0]
    for a in C[1:]:
        ans.append((x,a))
        x -= a
    ans.append((C[0],x))
    x = C[0]-x
    for a in B[1:]:
        ans.append((x,a))
        x -= a

print(x)
for out in ans:
    print(*out)

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

A.sort()

for i,a in enumerate(A):
    if a>=0:break
B = A[:i]
C = A[i:]

ans = []
if not B:
    x = C[0]
    for a in C[1:-1]:
        ans.append((x,a))
        x -= a
    ans.append((C[-1],x))
    x = C[-1] - x
elif not C:
    x = B[-1]
    for a in B[:-1]:
        ans.append((x,a))
        x -= a
else:
    x = B[0]
    for a in C[1:]:
        ans.append((x,a))
        x -= a
    ans.append((C[0],x))
    x = C[0]-x
    for a in B[1:]:
        ans.append(x,a)
        x -= a

print(x)
for out in ans:
    print(*out)

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

A.sort()

for i,a in enumerate(A):
    if a>=0:break
B = A[:i]
C = A[i:]

ans = []
if not B:
    x = C[0]
    for a in C[1:-1]:
        ans.append((x,a))
        x -= a
    ans.append((C[-1],x))
    x = C[-1] - x
else:
    x = B[0]
    for a in C[1:]:
        ans.append((x,a))
        x -= a
    ans.append((C[0],x))
    x = C[0]-x
    for a in B[1:]:
        ans.append(x,a)
        x -= a

print(x)
for out in ans:
    print(*out)

Buggy submission (verdict: Runtime Error):
N = int(input())
A = sorted(map(int,input().split()))[::-1]
B = A[:(N+1)//2]
i = (N+1)//2
if B[-1]<=0:
    for i in range(1,N+1//2):
        if B[i]<=0:
            B = B[:i]
            break
C = A[i:2*i][::-1]
D = A[2*i:]
ans = []
if (len(B)+len(C))%2:
    M = B.pop()
else:
    M = C.pop()
while B:
    if len(B)>len(C):
        p = B.pop()
    else:
        p = C.pop()
    ans.append((p,M))
    M = p - M
for d in D:
    ans.append((M,d))
    M = M - d
print(M)
for o in ans:
    print(*o)
Problem p03074 (python)

Fixed submission:
N,K = list(map(int,input().split()))
S = input()
n = []
p = S[0]
c = 1
for s in S[1:]:
    if s != p:
        n.append(c)
        p = s
        c = 0
    c+=1
n.append(c)
ans = max(n)
sum_n = [0]
for i in n:
    sum_n.append(i+sum_n[-1])
if S[0]=="0":
    for i in range(1,len(n)-2*K+1,2):
        ans = max(ans,sum_n[min(i+2*K+1,len(sum_n)-1)]-sum_n[i])
    sum_n.pop(1)
    n.pop(0)
    K -=1
for i in range(0,len(n)-2*K+1,2):
    ans = max(ans,sum_n[min(i+2*K+1,len(sum_n)-1)]-sum_n[i])
if (len(n)-2*K+1)<=0:
    ans = max(ans,sum_n[-1])
print(ans)

Buggy submission (verdict: Runtime Error):
N,K = list(map(int,input().split()))
S = input()
n = []
p = S[0]
c = 1
for s in S[1:]:
    if s != p:
        n.append(c)
        p = s
        c = 0
    c+=1
n.append(c)
ans = n[0]
if S[0]=="0":
    for i in range(1,len(n)-2*K+1,2):
        ans = max(ans,sum(n[i:i+2*K+1]))
    n[1]+=n[0]
    n.pop(0)
    K -=1
for i in range(0,len(n)-2*K,2):
    ans = max(ans,sum(n[i:i+2*K+1]))
print(ans)
Problem p03087 (python)

Fixed submission:
N,Q = list(map(int,input().split()))
S = (input())
lr = [list(map(int,input().split())) for _ in range(Q)]

cnt = [0]*N
tmp = 0
for i,c in enumerate(S):
    if tmp == 0 and c == "A":
        tmp =1
        cnt[i] = cnt[i-1]
    elif tmp == 1 and c == "C":
        tmp =0
        cnt[i] = cnt[i-1]+1
    else:
        tmp = int(c == "A")
        cnt[i] = cnt[i-1]

for l,r in lr:
    print(cnt[r-1]-cnt[l-1])

Buggy submission (verdict: Runtime Error):
N,Q = list(map(int,input().split()))
S = (input())
lr = [list(map(int,input().split())) for _ in range(Q)]

cnt = [0]*N
tmp = 0
for i,c in enumerate(S):
    if tmp == 0 and c == "A":
        tmp =1
        cnt[i] = cnt[i-1]
    elif tmp == 1 and c == "C":
        tmp =0
        cnt[i] = cnt[i-1]+1
    else:
        tmp = int(c == "A")
        cnt[i] = cnt[i-1]

for l,r in lr:
    print(cnt[r-1]-cnt[l-1] , " : " ,S[l-1:r])
Problem p03150 (python)

Fixed submission:
S = input()
N = len(S)

ans = False
for i in range(N):
  for j in range(i,N):
    if S[:i]+S[j:] == "keyence":
      print("YES")
      ans = True
      break
  if ans: break
else:
  print("NO")

Buggy submission (verdict: Runtime Error):
S = input()
N = len(S)

ans = false
for i in range(N):
  for j in range(i,N):
    if S[:i]+S[j:] == "keyence":
      print("YES")
      ans = True
      break
  if ans: break
else:
  print("NO")
Problem p03156 (python)

Fixed submission:
N = int(input())
A,B = map(int,input().split())
*P, = map(int,input().split())

a = len([p for p in P if p<=A])
a = min(a,
        len([p for p in P if A<p<=B]))
a = min(a,
        len([p for p in P if B<p]))
print(a)

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

a = len([p for p in P if p<=A])
a = min(a,
        len([p for p in P if A<p<=B])
a = min(a,
        len([p for p in P if B<p])
print(a)
Problem p03165 (python)

Fixed submission:
s = input()
t = input()

ls,lt = len(s),len(t)
dp = [[0]*(lt+1) for _ in [0]*(ls+1)]

for i,cs in enumerate(s,1):
    for j,ct in enumerate(t,1):
        if cs==ct:
            dp[i][j] = dp[i-1][j-1]+1
        else:
            dp[i][j] = max(dp[i-1][j],dp[i][j-1])

i = ls
j = lt
ans = ""
while i>0 and j>0:
    if s[i-1] == t[j-1]:
        ans += s[i-1]
        i -= 1
        j -= 1
    else:
        if dp[i-1][j] > dp[i][j-1]:
            i -=1
        else:
            j -=1
print(ans[::-1])

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

ls,lt = len(s),len(t)
if ls > lt:
    #短い方をsに固定
    s,t = t,s
    ls,lt = lt,ls
dp=[("",0,0)]
common_str_set = set([""])
max_len = 0
i_ans = 0
for i,c in enumerate(s):
    for common_str,j,l_dp in dp.copy():
        for k,ct in enumerate(t[j:],j):
            if c == ct and (common_str+c) not in common_str_set:
                dp.append((common_str+c,k+1,l_dp+1))
                common_str_set.add(common_str+c)
                if l_dp+1 > max_len:
                    max_len = l_dp+1
                    i_ans = len(dp)-1
print(dp[i_ans][0])
Problem p03166 (python)

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

N,M = list(map(int,input().split()))
xy = [list(map(int,input().split())) for _ in range(M)]

dp = [None] * (N+1)

def get_dp(i):
    if dp[i] != None:
        return dp[i]
    yListSub = yList[i]
    if yListSub == []:
        dp[i] = 0
        return 0
    else:
        dp[i] = 1+ max(map(get_dp,yListSub))
        return dp[i]

yList = [[] for _ in range(N+1)]
for x,y in xy:
    yList[x].append(y)

[get_dp(i) for i in range(0,N+1)]
print(max(dp))

Buggy submission (verdict: Runtime Error):
N,M = list(map(int,input().split()))
xy = [list(map(int,input().split())) for _ in range(M)]

dp = [None] * (N+1)

def get_dp(i):
    if dp[i] != None:
        return dp[i]
    yListSub = yList[i]
    if yListSub == []:
        dp[i] = 0
        return 0
    else:
        dp[i] = 1+ max(map(get_dp,yListSub))
        return dp[i]

yList = [[] for _ in range(N+1)]
for x,y in xy:
    yList[x].append(y)

[get_dp(i) for i in range(0,N+1)]
print(max(dp))
Problem p03213 (python)

Fixed submission:
N = int(input())

def get_soinsu(n):
    if n ==1:
        return
    for p in soinsu.keys():
        if n%p == 0:
            soinsu[p] += 1
            get_soinsu(n//p)
            break
    else:
        soinsu[n] = 1

soinsu = {}
for i in range(2,N+1):
    get_soinsu(i)

tmp3 = soinsu.values()
    
#素因数が(74)個の数の選び方
num_74 = len([tmp for tmp in tmp3 if tmp >= 74])

#素因数が(2,24)個の数の選び方
num_24_2 = len([tmp for tmp in tmp3 if tmp >= 24]) * (len([tmp for tmp in tmp3 if tmp >= 2])-1)

#素因数が(4,14)個の数の選び方
num_14_4 = len([tmp for tmp in tmp3 if tmp >= 14]) * (len([tmp for tmp in tmp3 if tmp >= 4])-1)

#素因数が(2,4,4)個の数の選び方
tmp2 = len([tmp for tmp in tmp3 if tmp >= 4])
num_4_4_2 = max(0,tmp2*(tmp2-1)*(len([tmp for tmp in tmp3 if tmp >= 2])-2)//2)

print(num_74 + num_24_2 + num_14_4 + num_4_4_2)

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

def factoring(M,n=2):
    for i in range(n,int(M**0.5)+1):
        if M%i==0:
            ret = factoring(M//i,i)
            ret[i] = ret.get(i,0)+1
            return ret
    return {M:1}

p = {}
for i in range(2,N+1):
    for k,v in factoring(i).items():
        p[k] = p.get(k,0)+v

c = [0]*4
for n in p.values():
    if n>=24:c[3]+=1
    elif n>=14:c[2]+=1
    elif n>=4:c[1]+=1
    elif n>=2:c[0]+=1

ans = 0
ans += p[2]>=74
ans += c[3]*(sum(c)-1)
c[2] += c[3]
ans += c[2]*(c[1]+c[2]-1)
c[1] +=c[2]
ans += c[0]*c[1]*(c[1]-1)//2
ans += c[1]*(c[1]-1)*(c[1]-2)//2
print(ans)
Problem p03216 (python)

Fixed submission:
N = int(input())
S = input()
Q = int(input())
*K, = map(int,input().split())

nD = S.count("D")
nC = S.count("C")
if nD < nC:
    S = S[::-1].replace("D","c").replace("C","d").upper()

D = [0]*(N+1)
cntM = [0]*(N+1)
sumM = [0]*(N+1)
ans = [0]*Q
for i,s in enumerate(S):
    D[i+1] = D[i]
    cntM[i+1] = cntM[i]
    sumM[i+1] = sumM[i]
    if s=="D":
        D[i+1] += 1
    elif s=="M":
        cntM[i+1] += 1
        sumM[i+1] += D[i]
    elif s=="C":
        for j,k in enumerate(K):
            ik = max(0,i-k+1)
            d = D[ik]
            ans[j] += (sumM[i]-sumM[ik]) - d*(cntM[i]-cntM[ik])
for out in ans:
    print(out)

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

import scipy as sp

N = int(input())
S = input()
Q = int(input())
*K, = map(int,input().split())

nD = S.count("D")
nC = S.count("C")
if nD < nC:
    S = S[::-1].replace("D","c").replace("C","d").upper()

S = "A" + S
cs = sp.cumsum
ans = sp.zeros(Q,int)
D = sp.zeros(N+1,int)
cntM = sp.zeros(N+1,int)
sumM = sp.zeros(N+1,int)
M = []
C = []
for i,s in enumerate(S):
    if s=="D":
        D[i] = 1
    elif s=="M":
        M.append(i)
    elif s=="C":
        C.append(i-1)
D = cs(D)
for i in M:
    cntM[i] = 1
    sumM[i] = D[i]
cntM = cs(cntM)
sumM = cs(sumM)

for i in C:
    sMi = sumM[i]
    cMi = cntM[i]
    for j,k in enumerate(K):
        ik = max(0,i-k+1)
        ans[j] += (sMi-sumM[ik]) - D[ik]*(cMi-cntM[ik])
for out in ans:
    print(out)
Problem p03227 (python)

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

Buggy submission (verdict: Runtime Error):
S=input()
if S.len()==2:print(S)
else:print(S[::-1])
Problem p03240 (python)

Fixed submission:
N = int(input())
data = [list(map(int,input().split())) for _ in range(N)]
data.sort(key=lambda x:-x[2])

def get_H(data,Cx,Cy):
    x,y,h = data
    return h+abs(x-Cx)+abs(y-Cy) , h==0
def estimate_H(data,Cx,Cy):
    H,_ = get_H(data[0],Cx,Cy)
    for cur_data in data[1:]:
        tmp,isZero = get_H(cur_data,Cx,Cy)
        if isZero and H <= tmp:
            continue
        if H != tmp:
            break
    else:
        return H
    return None

for Cx in range(101):
    for Cy in range(101):
        tmp = estimate_H(data,Cx,Cy)
        if tmp != None:
            print(Cx,Cy,tmp)
            break

Buggy submission (verdict: Runtime Error):
N = int(input())
data = [list(map(int,input().split())) for _ in range(N)]
sorted_data = sorted(data,key=lambda x: x[2])

def get_H(x,y,h,Cx,Cy):
    return max(0,h+abs(x-Cx)+abs(y-Cy))
def estimate_H(data,Cx,Cy):
    H = get_H(*data[0],Cx,Cy)
    for cur_data in data[1:]:
        tmp = get_H(*cur_data,Cx,Cy)
        if H != tmp:
            break
    else:
        return H
    return None

for Cx in range(101):
    for Cy in range(101):
        tmp = estimate_H(sorted_data,Cx,Cy)
        if tmp != None:
            print(Cx,Cy,tmp)
            break

Buggy submission (verdict: Runtime Error):
N = int(input())
data = [list(map(int,input().split())) for _ in range(N)]

sorted_data = sorted(data,key=lambda x: x[2])

def estimate_H(data,Cx,Cy):
    H = get_H(*data[0],Cx,Cy)
    for cur_data in data[1:]:
        tmp = get_H(*cur_data,Cx,Cy)
        if H != tmp:
            break
    else:
        return H
    return None
def get_H(x,y,h,Cx,Cy):
    return max(0,h+abs(x-Cx)+abs(y-Cy))

for Cx in range(101):
    for Cy in range(101):
        tmp = estimate_H(sorted_data,Cx,Cy)
        if tmp != None:
            print(Cx,Cy,tmp)
            break