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

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

MOD = 998244353

fact = [1]*4000
t = 1
for i in range(1,4000):
    t = (t*i)%MOD
    fact[i] = t

factinv = [1]*4000
for i in range(1,4000):
    factinv[i] = pow(fact[i], MOD-2, MOD)

def ncr(n,r):
    if n < 0 or r < 0 or n-r < 0:
        return 0
    return (fact[n] * factinv[r] * factinv[n-r]) % MOD

def nhr(n,r):
    if n == 0 and r == 0:
        return 1
    return ncr(n+r-1, r)

for i in range(2,2*K+1):
    t1,t2 = 0,0
    Ans = 0
    # p : 足して i になる整数の組の数
    np = i//2 - max(i-1-K,0)
    # p組からq組, 片方を使用する場合の数を足し合わせる
    # 偶奇で場合分け
    if i%2==0:
        # 偶数の場合 : 1組だけ同じ数の組があるため特別扱いする
        np -= 1
        for nq in range(np+1):
            # 同じ数の組の数字を全く含まない場合
            t1 = ncr(np,nq)*pow(2, nq, MOD)
            t1 %= MOD
            t2 = nhr(K-np*2+nq-1,N-nq)
            t2 %= MOD
            Ans = (Ans + t1*t2) % MOD
            # 同じ数の組の数字を1つ含む場合
            t2 = nhr(K-np*2+nq-1,N-nq-1)
            t2 %= MOD
            Ans = (Ans + t1*t2) % MOD
    else:
        # 奇数の場合 : p組全て互いに異なる数
        for nq in range(np+1):
            t1 = ncr(np,nq)*pow(2, nq, MOD)
            t1 %= MOD
            t2 = nhr(K-np*2+nq,N-nq)
            t2 %= MOD
            Ans = (Ans + t1*t2) % MOD
    print(Ans%MOD)

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

MOD = 998244353

fact = [1]*3000
t = 1
for i in range(1,3000):
    t = (t*i)%MOD
    fact[i] = t

def ncr(n,r):
    return (fact[n] * pow(fact[r],MOD-2,MOD) % MOD) * pow(fact[n-r],MOD-2,MOD) % MOD

for i in range(2,2*K+1):
    t1,t2 = 0,0
    Ans = 0
    # p : 足して i になる整数の組の数
    np = i//2 - max(i-1-K,0)
    # p組からq組, 片方を使用する場合の数を足し合わせる
    # 偶奇で場合分け
    if i%2==0:
        # 偶数の場合 : 1組だけ同じ数の組があるため特別扱いする
        np -= 1
        for nq in range(np+1):
            # 同じ数の組の数字を全く含まない場合
            t1 = ncr(np,nq)*(2**nq)
            t1 %= MOD
            nr = K - np*2 - 1
            t2 = ncr(N+nr-1,N-nq) if N+nr-1>=N-nq else 0
            t2 %= MOD
            Ans += t1*t2
            # 同じ数の組の数字を1つ含む場合
            t2 = ncr(N-1+nr-1,N-1-nq) if N-1+nr-1>=N-1-nq else 0
            t2 %= MOD
            Ans += t1*t2
    else:
        # 奇数の場合 : p組全て互いに異なる数
        for nq in range(np+1):
            t1 = ncr(np,nq)*(2**nq)
            t1 %= MOD
            nr = K - np*2
            t2 = ncr(N+nr-1,N-nq) if N-1+nr-1>=N-1-nq else 0
            t2 %= MOD
            Ans += t1*t2
    print(Ans%MOD)
Problem p03282 (python)

Fixed submission:
S = input()
K = int(input())

S2 = ""
for i in range(len(S)):
    if S[i]=="1":
        S2 += "1"
    else:
        S2 += S[i]*101
        break

if K<100:
    print(S2[K-1])
else:
    print(S2[100])

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

S2 = ""
for i in range(len(S)):
    if S[i]=="1":
        S2 += "1"
    else:
        S2 += S[i]*101
        break

if K<100:
    print(S2[K])
else:
    print(S2[100])
Problem p03311 (python)

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

for i in range(N):
    A[i] -= i

A.sort()

Ans = 0
mi = len(A)//2 # 中央値のindex
for i in range(N):
    Ans += abs(A[i]-A[mi])

print(Ans)

Buggy submission (verdict: Runtime Error):
N = int(input())
A = list(map(int,input().split()))
from bisect import bisect_left

for i in range(N):
    A[i] = A[i]-i
A.sort()

S = [0]*(N+1)
for i in range(N):
    S[i+1] = S[i]+A[i]

sumA = sum(A)
maxA,minA = max(A),min(A)

Ans = 10**9
for i in range(3z00):
    l = bisect_left(A,minA)
    low  = abs(minA*l - S[l]) + abs(S[N]-S[l] - minA*(N-l))
    h = bisect_left(A,maxA)
    high  = abs(maxA*h - S[h]) + abs(S[N]-S[h] - maxA*(N-h))
    if low==high:
        minA += 1
    elif low < high:
        maxA = (maxA+minA)//2
    else:
        minA = (maxA+minA)//2
    #print(Ans,low,high,minA,maxA)
    Ans = min(Ans,low,high)

print(Ans)
Problem p03352 (python)

Fixed submission:
X = int(input())

s = [1]
for i in range(X+1):
    for j in range(2,X+1):
        if i**j <= X and i**j not in s:
            s.append(i**j)
        if i**j > X:
            break
print(max(s))

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

s = []
for i in range(X+1):
    for j in range(2,X+1):
        if i**j <= X and i**j not in s:
            s.append(i**j)
        if i**j > X:
            break
print(max(s))
Problem p03372 (python)

Fixed submission:
N,C = map(int,input().split())
X,V = [],[]
for i in range(N):
    x,v = map(int,input().split())
    X.append(x)
    V.append(v)
Ans = 0

# 右回り、左周りの原点基準の移動距離
xR = [0]+X
xL = [0]+list(map(lambda x: C-x,reversed(X)))

# 右回り,左周りで食べた時の累積カロリー
V2 = list(reversed(V))
calR,calL = [0],[0]
for i in range(N):
    calR.append(calR[i]+V[i])
    calL.append(calL[i]+V2[i])

# 移動距離を考慮した獲得カロリー
getR,getL = [],[]
for i in range(N+1):
    getR.append(calR[i]-xR[i])
    getL.append(calL[i]-xL[i])
# 単調増加になるように修正
for i in range(N):
    if getR[i+1] < getR[i]:
        getR[i+1] = getR[i]
    if getL[i+1] < getL[i]:
        getL[i+1] = getL[i]

for i in range(N+1):
    gr = getR[N-i]
    gl = getL[i]
    xr = xR[N-i]
    xl = xL[i]
    # 右回り → 左周り
    Ans = max(Ans, gr, gr-xr+gl)
    # 左周り → 右回り
    Ans = max(Ans, gl, gl-xl+gr)

print(Ans)

Buggy submission (verdict: Runtime Error):
N,C = map(int,input().split())
X,V = [],[]
for i in range(N):
    x,v = map(int,input().split())
    X.append(x)
    V.append(v)
Xa,Xb = [X[0]]+[0]*(N-1),[0]*(N-1)+[C-X[N-1]]
for i in range(1,N):
    Xa[i] = X[i] - X[i-1]
for i in range(N-1):
    Xb[N-2-i] = X[N-1-i] - X[N-2-i]

Point1,Point2 = [],[]
point = 0
for i in range(N):
    point = point - Xa[i] + V[i]
    Point1.append(point)
point = 0
for i in range(N):
    point = point - Xb[N-1-i] + V[N-1-i]
    Point2.append(point)

#順方向に食べ続けていく場合に、何個目で過去最高を更新するか
N1,N2 = [],[]
if Point1[0] > Point1[1]:
    N1.append(0)
for i in range(1,N-1):
    if Point1[i+1] < Point1[i] and Point1[i-1] < Point1[i]:
        N1.append(i)
if Point1[N-1] == max(Point1):
    N1.append(N-1)
#逆方向に食べ続けていく場合に、何個目で過去最高を更新するか
if Point2[0] > Point2[1]:
    N2.append(0)
for i in range(1,N-1):
    if Point2[i+1] < Point2[i] and Point2[i-1] < Point2[i]:
        N2.append(i)
if Point2[N-1] == max(Point2):
    N2.append(N-1)

Ans = 0
#順方向に食べ、逆方向に最大限まで食べる
for i in N1:
    #順方向に食べて停止した時点のポイント
    point = Point1[i]
    Ans = max(Ans,point)
    #0まで戻るのに必要なポイント
    point -= X[i]
    #逆方向にどこまで食べられるか
    for j in N2:
        if j < N-1-i:
            point += Point2[j]
            Ans = max(Ans,point)

#逆方向に食べ、順方向に・・・
for i in N2:
    point = Point2[i]
    Ans = max(Ans,point)
    #0まで戻るのに必要なポイント
    point -= (C - X[N-1-i])
    for j in N1:
        #
        if j < N-1-i:
            point += Point1[j]
            Ans = max(Ans,point)

#出力
print(Ans)
Problem p03393 (python)

Fixed submission:
S = input()
chars = "abcdefghijklmnopqrstuvwxyz"
if len(S) < 26:
    for c in chars:
        if c not in S:
            Ans = S+c
            break
else:
    if S == chars[::-1]:
        Ans = -1
    else:
        for i in range(25):
            if S[25-i] > S[25-i-1]:
                break
        for j in range(25): # index out of rangeにならない？大丈夫？
            if chr(ord(S[25-i-1])+1+j) not in S[0:25-i-1]:
                break
        Ans = S[0:25-i-1]+chr(ord(S[25-i-1])+1+j)
print(Ans)

Buggy submission (verdict: Runtime Error):
S = input()
chars = "abcdefghijklmnopqrstuvwxyz"
if len(S) < 26:
    for c in chars:
        if c not in S:
            Ans = S+c
            break
else:
    if S == chars[::-1]:
        Ans = -1
    else:
        for i in range(26):
            if S[i] != chars[i]:
                Ans = S[0:i-1] + chars[i]
                break
print(Ans)

Buggy submission (verdict: Runtime Error):
S = input()
chars = "abcdefghijklmnopqrstuvwxyz"
if len(S) < 26:
    for c in chars:
        if c not in S:
            Ans = S+c
            break
else:
    if S == chars[::-1]:
        Ans = -1
    else:
        for i in range(26):
            if S[i] != chars[i]:
                Ans = S[0:i] + chars[i]
                break
print(Ans)
Problem p03424 (python)

Fixed submission:
N = int(input())
S = list(input().split())
print("Four" if "Y" in S else "Three")

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

Ans = "Three"
for s in S:
    if s=="Y":
        Ans = "Four"
        break

print(Ans)

Buggy submission (verdict: Runtime Error):
N = int(input())
S = list(map(int,input().split()))
print("Four" if "Y" in S else "Three")
Problem p03457 (python)

Fixed submission:
N = int(input())
S = "Yes"
A = [(0,0,0)]
for i in range(N):
    t,x,y = map(int,input().split())
    A.append((t,x,y))
A = sorted(A)
for i in range(N):
    t1,x1,y1 = A[i]
    t2,x2,y2 = A[i+1]
    if abs(x2-x1)+abs(y2-y1) > t2-t1  or   (abs(x2-x1)+abs(y2-y1))%2 != (t2-t1)%2:
        S = "No"
        break
print(S)

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

t0,x0,y0 = 0,0,0

for i in range(N):
    print(t0,x0,y0," ",t,x,y)
    if t-t0 >= abs(x-x0)+abs(y-y0) and (t-t0)%2 == abs(x-x0+y-y0)%2:
        t0,x0,y0 = t,x,y
        continue
    else:
        print("No")
        sys.exit()

print("Yes")
Problem p03496 (python)

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

maxA,minA = max(A),min(A)
maxAi,minAi = -1,-1
sign = ""
M = []

for i in range(N):
    if A[i] == maxA:
        maxAi = i
        break
for i in range(N):
    if A[i] == minA:
        minAi = i
        break

if abs(maxA) >= abs(minA):
    A = list(map(lambda x: x+maxA, A))
    sign = "+"
else:
    A = list(map(lambda x: x+minA, A))
    sign = "-"

if sign == "+":
    for i in range(N):
        if i != maxAi:
            M.append((maxAi,i))
    M.append((maxAi,maxAi))
    for i in range(N-1):
        M.append((i,i+1))
elif sign == "-":
    for i in range(N):
        if i != minAi:
            M.append((minAi,i))
    M.append((minAi,minAi))
    for i in range(N-1):
        M.append((N-i-1,N-i-2))

L = len(M)
print(L)
for i in range(L):
    x,y = M[i]
    print(x+1,y+1)

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

maxA,minA = max(A),min(A)
maxAi,minAi = -1,-1
sign = ""
M = []

for i in range(N):
    if A[i] == maxA:
        maxAi = i
        break
for i in range(N):
    if A[i] == minA:
        minAi = i
        break

if abs(maxA) >= abs(minA):
    A = list(map(lambda x: x+maxA, A))
    sign = "+"
else:
    A = list(map(lambda x: x+minA, A))
    sign = "-"

if sign == "+":
    for i in range(N):
        if i != maxAi:
            M.append((maxAi,i))
    M.append((maxAi,maxAi))
    for i in range(N-1):
        M.append((i,i+1))
elif sign == "-":
    for i in range(N):
        if i != minAi:
            M.append((minAi,i))
    M.append(minAi,minAi)
    for i in range(N-1):
        M.append((N-i,N-i-1))

L = len(M)
print(L)
for i in range(L):
    x,y = M[i]
    print(x,y)
Problem p03546 (python)

Fixed submission:
H,W = map(int,input().split())
c,A,s = [],[],0
for i in range(10):
    c.append(list(map(int,input().split())))
for i in range(H):
    A.append(list(map(int,input().split())))
for i in range(10):
    for j in range(10):
        for k in range(10):
            c[j][k] = min(c[j][k], c[j][i]+c[i][k])
for i in range(10):
    for j in range(H):
        s = s + A[j].count(i) * c[i][1]
print(s)

Buggy submission (verdict: Runtime Error):
H,W = map(int,input().split())
C = [0]*10
for i in range(10):
    C[i] = list(map(int,input().split()))
A = [0]*10
for i in range(H):
    A[i] = list(map(int,input().split()))
for k in range(10):
    for i in range(10):
        for j in range(10):
            C[i][j] = min(C[i][j],C[i][k]+C[k][j])
Ans = 0
for i in range(H):
    B = A[i]
    for b in B:
        if b > 1:
            Ans += C[b][1]
print(Ans)
Problem p03547 (python)

Fixed submission:
X,Y = input().split()
if X==Y:
    print("=")
elif(X>Y):
    print(">")
else:
    print("<")

Buggy submission (verdict: Runtime Error):
X,Y = input().split()
if X==Y:
    print("=")
elif(X>Y:
    print(">"))
else:
    print("<")
Problem p03600 (python)

Fixed submission:
N = int(input())
A,B,Ans = [],[],0
for i in range(N):
    x = list(map(int,input().split()))
    A.append(x[:])
    B.append(x[:])

for k in range(N):
    for i in range(N):
        for j in range(N):
            B[i][j] = min(B[i][j],B[i][k]+ B[k][j])

if A!=B:
    print(-1)
else:
    for i in range(N):
        for j in range(i+1,N):
            exists = True
            for k in range(N):
                if k not in (i,j) and B[i][j]==B[i][k]+B[k][j]:
                    exists = False                    
            if exists:
                Ans += B[i][j]
    print(Ans)

Buggy submission (verdict: Runtime Error):
N = int(input())
A,B,Ans = [],[],0
for i in range(N):
    x = list(map(int,input().split()))
    A.append(x.copy())
    B.append(x.copy())

for k in range(N):
    for i in range(N):
        for j in range(N):
            B[i][j] = min(B[i][j],B[i][k]+ B[k][j])

if A!=B:
    print(-1)
else:
    for i in range(N):
        for j in range(i+1,N):
            exists = True
            for k in range(N):
                if k not in (i,j) and B[i][j]==B[i][k]+B[k][j]:
                    exists = False                    
            if exists:
                Ans += B[i][j]
    print(Ans)
Problem p03611 (python)

Fixed submission:
from collections import Counter
N = int(input())
A = Counter(list(map(int,input().split())))
Ans = 0
for n,c in A.most_common():
    Ans = max(Ans,A[n]+A[n-1]+A[n+1])
print(Ans)

Buggy submission (verdict: Runtime Error):
from collections import Counter
N = int(input())
A = Counter(list(map(int,input().split())))
Ans = 0
B = A.most_common()
for n,c in B:
    Ans = max(Ans,B[n]+B[n-1]+B[n+1])
print(Ans)
Problem p03625 (python)

Fixed submission:
from collections import Counter
N = int(input())
A = Counter(list(map(int,input().split()))).most_common()
fA = filter(lambda x: x[1] >= 2, A)
sA = sorted(fA,reverse=True)
if len(sA) < 2:
    print(0)
else:
    print(sA[0][0]**2 if sA[0][1]>=4 else sA[0][0]*sA[1][0])

Buggy submission (verdict: Runtime Error):
from collections import Counter
N = int(input())
A = list(map(int,input().split()))
C = sorted(Counter(A).most_common(),reverse=True)
D = []
F = []
for i in range(len(C)):
    x,y = C[i][0],C[i][1]
    if y >= 2:
        D.append(x)
    if y >= 4:
        F.append(x)
E = sorted(D,reverse=True)
G = sorted(F,reverse=True)
if len(E)>=2:
    if G[0]==E[0]:
        print(G[0]*G[0])
    else:
        print(E[0]*E[1])
else:
    print(0)
Problem p03633 (python)

Fixed submission:
from fractions import gcd

N = int(input())
T = []

for i in range(N):
    T.append(int(input()))

Ans = T[0]
for i in range(1,N):
    Ans = Ans*T[i]//gcd(Ans,T[i])

print(Ans)

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

N = int(input())
T = []

for i in range(N):
    T.append(int(input()))

Ans = T[0]
for i in range(1,N):
    Ans = Ans*T[i]//gcd(Ans,T[i])

print(Ans)
Problem p03674 (python)

Fixed submission:
from collections import Counter
N = int(input())
A = list(map(int,input().split()))
c = Counter(A).most_common(1)[0][0]
B = []
mod = 10**9+7

for i in range(N+1):
    if A[i]==c:
        B.append(i)

F,I = [1],[1]
for i in range(1,N+2):
    F.append(F[i-1]*i%mod)
    I.append(pow(F[i],mod-2,mod))

def C(n,r):
    if n<r or n==0 or r==0:
        return 0
    else:
        return F[n]*I[r]*I[n-r]%mod

r0 = B[0]+N-B[1]

for i in range(1,N+2):
    Ans = (C(N+1,i) - C(r0,i-1))%mod
    print(Ans if i>1 else Ans-1)

Buggy submission (verdict: Runtime Error):
def init_fact(n,mod):
    fact,finv,inv = [1]*n,[1]*n,[1]*n
    for i in range(2,n):
        fact[i] = (fact[i-1]*i) % mod
        inv[i]  = mod - inv[mod%i] * (mod//i)%mod
        finv[i] = finv[i-1] * inv[i] % mod
    return (fact,finv,inv)

def nCr(n,r,mod,fact,finv):
    if n<r:
        return 0
    else:
        return fact[n] * (finv[r] * finv[n-r] % mod) % mod

modulo = 10**9+7
fact,finv,inv = init_fact(200000,modulo)


from collections import Counter
N = int(input())
A = list(map(int,input().split()))

# 重複している数を調べる
C = Counter(A).most_common()
x = C[0][0]

# 重複している数のindexを調べる
xi = []
for i in range(N):
    if A[i]==x:
        xi.append(i)
h = xi[1]-xi[0]+1

for i in range(1,N+2):
    print(nCr(N+1,i,modulo,fact,finv) - nCr(N+1-h,i-1,modulo,fact,finv))
Problem p03699 (python)

Fixed submission:
N = int(input())
S = [int(input()) for _ in range(N)]
sumS = sum(S)
T = list(filter(lambda x : x%10!=0, S))
T.sort()
if len(T)==0:
    print(0)
else:
    for t in T:
        if sumS%10!=0:
            break
        else:
            sumS -= t
    print(sumS)

Buggy submission (verdict: Runtime Error):
N = int(input())
S = [int(input()) for _ in range(N)]

r = []
ans = 0
for i in range(N):
    ans += S[i]
    if S[i]%10!=0:
        r.append(S[i])

r.sort()
if ans%10==0:
    if len(rr)>0:
        ans -= r[0]
    else:
        ans = 0

print(ans)

Buggy submission (verdict: Runtime Error):
N = int(input())
S = [int(input()) for _ in range(N)]

rr = []
ans = 0
for i in range(N):
    ans += S[i]
    if S[i]%10!=0:
        rr.append(S[i])

rr.sort()
if ans%10==0:
    if len(rr)>0:
        ans -= r[0]
    else:
        ans = 0

print(ans)
Problem p03738 (python)

Fixed submission:
A = int(input())
B = int(input())
if A==B:
    print("EQUAL")
elif A>B:
    print("GREATER")
else:
    print("LESS")

Buggy submission (verdict: Runtime Error):
A,B = map(int,input().split())
if A==B:
    print("EQUAL")
elif A>B:
    print("GREATER")
else:
    print("LESS")
Problem p03801 (python)

Fixed submission:
from collections import Counter
N = int(input())
S = list(map(int,input().split()))
T = []
for i in range(N):
    T.append((i,S[i]))
U = sorted(T,key=lambda x:x[1], reverse=True)

Ans = [0]*N
c,v = 0,10**10

for i in range(N-1):
    c+=1
    v = min(v,U[i][0])
    if U[i][1]==U[i+1][1]:
        continue
    else:
        Ans[v] += (U[i][1] - U[i+1][1])*c
else:
    Ans[0] = 0
    Ans[0] = sum(S) - sum(Ans)

for i in range(N):
    print(Ans[i])

Buggy submission (verdict: Runtime Error):
from collections import Counter
N = int(input())
S = list(map(int,input().split()))
T = []
for i in range(N):
    T.append((i,S[i]))
U = sorted(T,key=lambda x:x[1], reverse=True)

Ans = [0]*N
c,v = 0,10**10

for i in range(N-1):
    c+=1
    v = min(v,U[i][0])
    if U[i][1]==U[i+1][1]:
        continue
    else:
        Ans[v] += (U[i][1] - U[i+1][1])*c
else:
    Ans[0] += U[i+1][1]

for i in range(N):
    print(Ans[i])
Problem p03846 (python)

Fixed submission:
from collections import Counter
N = int(input())
A = list(map(int,input().split()))

C = Counter(A).most_common()
p = 0
for k,v in C:
    if v==1 and k==0 and N%2==1:
        continue
    elif v==2:
        p += 1
        continue
    else:
        p = 0
        break
if N==1:
    print(1)
else:
    print(p if p==0 else (2**p)%(10**9+7))

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

# main
from collections import Counter
N = int(input())
A = list(map(int,input().split()))
mod = 10**9+7

C = dict(Counter(A))

ans = 1
if N%2==0:
    for i in range(N//2):
        if C[i*2+1] == 2:
            ans *= 2
            ans %= mod
        else:
            ans = 0
            break
else:
    if C[0] == 1:
        for i in range(N//2):
            if C[i*2+2] == 2:
                ans *= 2
                ans %= mod
            else:
                ans = 0
                break
    else:
        ans = 0

print(ans)
Problem p03943 (python)

Fixed submission:
A = sorted(map(int,input().split()))
print("Yes" if A[0]+A[1]==A[2] else "No")

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

# main
ABC = list(map(int,input().split()))

ABC.sort()

print("Yes" if A[0]+A[1]==A[2] else "No")
Problem p03962 (python)

Fixed submission:
from collections import Counter
A,B,C = map(int,input().split())
print(len(Counter([A,B,C]).most_common()))

Buggy submission (verdict: Runtime Error):
from math import ceil
N = int(input())
T,A = 1,1
for i in range(N):
    Ti,Ai = map(int,input().split())
    r = max(ceil(T/Ti),ceil(A/Ai))
    T,A = Ti*r,Ai*r
print(T+A)
Problem p04013 (python)

Fixed submission:
N,A = map(int,input().split())
X = [0]+list(map(int,input().split()))

dp = [[[0 for _ in range(2500+1)] for _ in range(N+1)] for _ in range(N+1)]
dp[0][0][0] = 1

for i in range(1,N+1):
    for j in range(0,i+1):
        for k in range(2500+1):
            if j==0 and k==0:
                dp[i][j][k] = 1
            elif k < X[i]:
                dp[i][j][k] = dp[i-1][j][k]
            elif j > 0 and k >= X[i]:
                dp[i][j][k] = dp[i-1][j][k] + dp[i-1][j-1][k-X[i]]

if max(X) < A:
    print(0)
else:
    Ans = 0
    for i in range(1,N+1):
        Ans += dp[N][i][A*i]
    print(Ans)

Buggy submission (verdict: Runtime Error):
N,A = map(int,input().split())
X = [0]+list(map(int,input().split()))

sumX = sum(X)
dp = [[[0 for _ in range(sumX+1)] for _ in range(N+1)] for _ in range(N+1)]
dp[0][0][0] = 1

for i in range(1,N+1):
    for j in range(0,i+1):
        for k in range(sum(X)+1):
            if j==0 and k==0:
                dp[i][j][k] = 1
            elif k < X[i]:
                dp[i][j][k] = dp[i-1][j][k]
            elif j > 0 and k >= X[i]:
                dp[i][j][k] = dp[i-1][j][k] + dp[i-1][j-1][k-X[i]]

if max(X) < A:
    print(0)
else:
    Ans = 0
    for i in range(1,N+1):
        Ans += dp[N][i][A*i]
    print(Ans)

Buggy submission (verdict: Runtime Error):
N,A = map(int,input().split())
X = [0]+list(map(int,input().split()))

maxX = max(X)
dp = [[[0 for _ in range(N*maxX+1)] for _ in range(N+1)] for _ in range(N+1)]
dp[0][0][0] = 1

for i in range(1,N+1):
    for j in range(0,i+1):
        for k in range(N*maxX+1):
            if j==0 and k==0:
                dp[i][j][k] = 1
            elif k < X[i]:
                dp[i][j][k] = dp[i-1][j][k]
            elif j > 0 and k >= X[i]:
                dp[i][j][k] = dp[i-1][j][k] + dp[i-1][j-1][k-X[i]]

Ans = 0
for i in range(1,N+1):
    Ans += dp[N][i][A*i]

print(Ans)
Problem p04014 (python)

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

def f(b,n):
    if n//b==0:
        return n
    else:
        return n%b + f(b,n//b)

ans = -1
if S==N:
    ans = N+1
else:
    for b in range(2,int(N**.5)+1):
        if f(b,N)==S:
            ans = b
            break

if ans == -1:
    for i in range(int(N**.5)+1,0,-1):
        b = (N-S)//i + 1
        if b>1:
            if f(b,N)==S:
                ans = b
                break

print(ans)

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

def f(b,n):
    if n//b==0:
        return n
    else:
        return n%b + f(b,n//b)

ans = -1
if S==N:
    ans = N+1
else:
    for b in range(2,int(N**.5)+1):
        if f(b,N)==S:
            ans = b
            break

if ans == -1:
    for i in range(int(N**.5)+1,0,-1):
        b = (N-S)//i + 1
        if b>0:
            if f(b,N)==S:
                ans = b
                break

print(ans)

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

def f(b,n):
    if n//b==0:
        return n
    else:
        return n%b + f(b,n//b)

ans = -1
if S==N:
    ans = N+1
else:
    for b in range(2,int(N**.5)+1):
        if f(b,N)==S:
            ans = b
            break
    for i in range(int(N**.5)+1,0,-1):
        b = (N-S)//i + 1
        if b>0:
            if f(b,N)==S:
                ans = b
                break

print(ans)

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

def f(b,n):
    if n//b==0:
        return n
    else:
        return n%b + f(b,n//b)

ans = -1
if S==N:
    ans = N+1
else:
    for b in range(2,int(N**.5)+1):
        if f(b,N)==S:
            ans = b
            break
    for i in range(int(N**.5)+1,0,-1):
        b = (N-S)//i + 1
        if f(b,N)==S:
            ans = b
            break

print(ans)
Problem p02640 (python)

Fixed submission:
X,Y=map(int,input().split())
a=(4*X-Y)/2
if X<=Y and a.is_integer() and a>=0 and a<=50:
  print("Yes")
else:
  print("No")

Buggy submission (verdict: Runtime Error):
X,Y=map(int,input().split())
a=(4*X-Y)//2
if a.is_integer() and a>=0 and a<=100:
  print("Yes")
else:
  print("No")