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

Fixed submission:
import sys
import numpy as np
sys.setrecursionlimit(1000000)
 
N,M = map(int,input().split())
a = [int(input()) for i in range(M)]

ans = 0

now = 0

dp = [0]*(N+1)
disable = [0]*(N+1)

for i in range(M):
    #print(i)
    disable[a[i]] = 1
    

waru = 10**9+7
dp[0] = 1

for i in range(1,N+1):
    if disable[i] == 1:
        dp[i] = 0
    else:
        dp[i] = ( dp[i-1] + dp[i-2] )  % waru

print(dp[N])

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

mod = 10**9+7

dp = [0] * (n+1)
dp[0] = 1
num = 0

for i in range(1,n+1):
    #print(i)
    if i == ai[num]:
        dp[i] = 0
        num += 1
        num = min(num,len(ai)-1)
    else:
        if i == 1:
            dp[i] = dp[i-1] % mod
        else:
            dp[i] = (dp[i-1] + dp[i-2])%mod
#    dp[i+1] = dp[i-1] + dp[i]
            
print(dp[n]%mod)

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

mod = 10**9+7

dp = [0] * (n+1)
dp[0] = 1
num = 0

for i in range(1,n+1):
    #print(i)
    if i == ai[num]:
        dp[i] = 0
        num += 1
        num = min(num,len(ai)-1)
    else:
        if i == 1:
            dp[i] = dp[i-1] % mod
        else:
            dp[i] = (dp[i-1] + dp[i-2])%mod
#    dp[i+1] = dp[i-1] + dp[i]
            
print(dp[n]%mod)
Problem p03038 (python)

Fixed submission:
import sys
sys.setrecursionlimit(1000000)
 
N,M = map(int,input().split())
A = list(map(int,input().split()))

BC =  [[int(i) for i in input().split()] for M in range(M)]



A.sort()
#BC.sort()
BC = sorted(BC, key=lambda x:x[1])
BC.reverse()

now = 0
end = 0

for i in range(M):
    for j in range(BC[i][0]):
        if now+j >= N:
            end = 1
            break
        if A[now+j] < BC[i][1]:
            A[now+j] = BC[i][1]
        else:
            end = 1
            break
    
    if end == 1:
        break
    now = now + BC[i][0]

print(sum(A))

Buggy submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(1000000)
 
N,M = map(int,input().split())
A = list(map(int,input().split()))

BC =  [[int(i) for i in input().split()] for M in range(M)]



A.sort()
#BC.sort()
BC = sorted(BC, key=lambda x:x[1])
BC.reverse()

now = 0
end = 0

for i in range(M):
    for j in range(BC[i][0]):
        if A[now+j] < BC[i][1]:
            A[now+j] = BC[i][1]
        else:
            end = 1
            break
    
    if end == 1:
        break
    now = now + BC[i][0]

print(sum(A))
Problem p03307 (python)

Fixed submission:
n = int(input())

if n % 2 == 0:
    print(n)
else:
    print(n*2)

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

val = []

for i in range(n):
    val.append(a[i]-i)

val.sort()
#print(val)

#idx = [(val[0],0)]
idx = []
cnt = 1
for i in range(n-1):
    if val[i] == val[i+1]:
        #cnt += 1
        if i == n-2:
            idx.append((val[i],i+2))
        continue
    else:
        idx.append((val[i],i+1))
        #cnt = 1
        
ans_val = 0

for i in range(len(idx)):
    if idx[i][1] >= (n) // 2:
        ans_val = idx[i-1][0]

#print(ans_val)
#exit()
     
ans = 0
ans2 = 0
ans3 = 0
for i in range(n):
    ans += abs(a[i]-ans_val-i)
    ans2 += abs(a[i]-ans_val-i+1)
    ans3 += abs(a[i]-ans_val-i-1)
    

print(min(ans,ans2,ans3))
Problem p03724 (python)

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

im_b = [0]*(n)

for i in range(m):
    im_b[ab[i][0]-1] += 1
    im_b[ab[i][1]-1] -= 1

if im_b[0] % 2 == 1:
    print('NO')
    exit()

#im_a = [0]*(n)
#im_a[0] = im_b[0]

for i in range(n-1):
    #print(i)
    if im_b[i] % 2 == 1:
        print('NO')
        exit()

print('YES')

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

im_b = [0]*(n)

for i in range(n):
    im_b[ab[i][0]-1] += 1
    im_b[ab[i][1]-1] -= 1

if im_b[0] % 2 == 1:
    print('NO')
    exit()

#im_a = [0]*(n)
#im_a[0] = im_b[0]

for i in range(n-1):
    #print(i)
    if im_b[i] % 2 == 1:
        print('NO')
        exit()

print('YES')
Problem p02777 (python)

Fixed submission:
S,T = input ().split ()
A,B = map (int, input ().split ())
U = input ()
if U == S:
  print (A-1,B)
else:
  print (A,B-1)

Buggy submission (verdict: Runtime Error):
S,T = input (),split ()
A,B = map (int, input (),split ())
U = input ()
if U == S:
  print (A-1,B)
else:
  print (A,B-1)

Buggy submission (verdict: Runtime Error):
S,T = input (),split ()
A,B = map (int, input ().split ())
U = input ()
if U == S:
  print (A-1,B)
else:
  print (A,B-1)
Problem p02570 (python)

Fixed submission:
d,t,s=list(map(int,input().split()))

if t*s>=d:
    print("Yes")
else:
    print("No")

Buggy submission (verdict: Runtime Error):
n,m=list(map(int,input().split()))
par=[i for i in range(n)]
ro=dict(int)
for i in range(n):
    ro[i]=1
def root(i):
    if par[i]==i:
        return i
    else:
        return root(par[i])

def unite(x,y):
    rx=root(x)
    ry=root(y)
    if rx!=ry:
        par[rx]=ry
        ro[ry]+=ro[rx]
        ro[rx]=0

for i in range(m):
    a,b=list(map(int,input().split()))
    a-=1
    b-=1
    unite(a,b)


# for i in range(n):
#     ro[root(i)]+=1

print(max(ro.values()))
Problem p02781 (python)

Fixed submission:
from math import factorial as fac

def comb(n,r):
    if ( r<0 or r>n ):
        return 0
    return fac(n)/(fac(r)*fac(n-r))


n=int(input())
k=int(input())

nn=str(n)
keta=len(nn)

ans=0

if keta<k:
    print(0)
    exit()

zero=0

# for i in range(keta):
#     if int(nn[i])==0:zero+=1
#     ans+=comb(keta-i-1,k-i+zero)*9**(k-i)
#     if int(nn[i])-1>=0:
#         ans+=(int(nn[i])-1)*comb(keta-i-1,k-i-1+zero)*9**(k-i-1+zero)
#
# if keta-zero==k:ans+=1

def search(n,k):
    if k<=0:return
    global ans
    nn = str(n)
    keta = len(nn)
    ans += comb(keta - 1, k ) * 9 ** k
    if int(nn[0])-1>0:
        ans+=(int(nn[0])-1)*comb(keta-1,k-1)*9**(k-1)
    ne=n-int(nn[0])*10**(keta-1)
    search(ne,k-1)


search(n,k)
for i in range(keta):
    if nn[i]=="0":zero+=1
if keta-zero>=k:ans+=1
print(int(ans))

Buggy submission (verdict: Runtime Error):
from math import factorial as fac

def comb(n,r):
    if ( r<0 or r>n ):
        return 0
    return fac(n)/(fac(r)*fac(n-r))


n=int(input())
k=int(input())

nn=str(n)
keta=len(nn)

ans=0


for i in range(k):
    ans+=comb(keta-i-1,k-i)*9**(k-i)
    if int(nn[i])-1>=0:
        ans+=(int(nn[i])-1)*comb(keta-i-1,k-i-1)*9**(k-i-1)



print(int(ans)+1)
Problem p02793 (python)

Fixed submission:
import sys
sys.setrecursionlimit(2000000)

from fractions import gcd
def lcm(a):
    x = a[0]
    for i in range(1, len(a)):
        x = (x * a[i]) // gcd(x, a[i])
    return x


mod = 1000000007


def mul(a, b):
    return ((a % mod) * (b % mod)) % mod

def power(x, y):
    if   y == 0     : return 1
    elif y == 1     : return x % mod
    elif y % 2 == 0 : return power(x, y/2)**2 % mod
    else            : return power(x, y//2)**2 * x % mod

def div(a, b):
    return mul(a, power(b, mod-2))



n=int(input())
aa=[]
aa=list(map(int,input().split()))
# for i in range(n):
#     aa.append(randint(1,10**6))

bb=lcm(aa)
mod=10**9+7
ans=0
for i in range(n):
    ccc=div(bb,aa[i])
    ans=int((ccc%mod+ans%mod)%mod)
print(int(ans))

Buggy submission (verdict: Runtime Error):
from fractions import gcd
def lcm(a):
    x = a[0]
    for i in range(1, len(a)):
        x = (x * a[i]) // gcd(x, a[i])
    return x

n=int(input())
aa=[]*n
aa=list(map(int,input().split()))

bb=lcm(aa)
mod=10**9+7
ans=0
for i in range(n):
    ans=(bb/aa[i]+ans)%mod
print(int(ans))
Problem p02832 (python)

Fixed submission:
import sys
sys.setrecursionlimit(2000000)

n=int(input())
a=[]*n
a=list(map(int,input().split()))
num=1
bre=0
no=True
def search(pos):
    spos=pos
    global num,bre,no
    end=True
    while end:
        if spos >= n:
            break
        if a[spos]==num:
            no=False
            num+=1
            search(spos+1)
            end=False
        else:
            spos+=1
            bre+=1

search(0)
if no:
    bre=-1
print(bre)

Buggy submission (verdict: Runtime Error):
n=int(input())
a=[]*n
a=list(map(int,input().split()))
num=1
bre=0
no=True
def search(pos):
    spos=pos
    global num,bre,no
    end=True
    while end:
        if spos >= n:
            break
        if a[spos]==num:
            no=False
            num+=1
            search(spos+1)
            end=False
        else:
            spos+=1
            bre+=1

search(0)
if no:
    bre=-1
print(bre)

Buggy submission (verdict: Runtime Error):
n=int(input())
a=[]*n
a=list(map(int,input().split()))
num=1
bre=0
no=True
def search(pos,s):
    spos=pos
    global num,bre,no
    end=True
    while end:
        if spos >= n:
            break
        if a[spos]==s:
            no=False
            bre+=spos-pos
            num+=1
            search(spos+1,num)
            end=False
        else:spos+=1
search(0, num)
if no:
    bre=-1
print(bre)
Problem p02847 (python)

Fixed submission:
S=input()
if S=="SUN":print("7")
if S=="MON":print("6")
if S=="TUE":print("5")
if S=="WED":print("4")
if S=="THU":print("3")
if S=="FRI":print("2")
if S=="SAT":print("1")

Buggy submission (verdict: Runtime Error):
a,b,x=map(int,input().split())
def binary_search(start,end):
    if end-start<=1:return start
    else:
        i=(start+end)//2
        s = a * (i) + b * len(str(i))
        if s<=x:return binary_search(i,end)
        else:return binary_search(start,i)
print(binary_search(0,10**9+1))
Problem p02881 (python)

Fixed submission:
import math
n=int(input())
ans=n
i=1
while(i<=math.sqrt(n)):
    if n%i==0:
        d=i+n/i-2
        ans=min(ans,d)
    i+=1
print(int(ans))

Buggy submission (verdict: Runtime Error):
n=int(input())
ans=n
i=1
while(i<math.sqrt(n)):
    if n%i==0:
        d=i+n/i-2
        ans=min(ans,d)
    i+=1
print(int(ans))
Problem p02891 (python)

Fixed submission:
s=input()
k=int(input())
l=len(s)
now=1
seq=[]
re=False
all=False
for i in range(l):
    if s[i%l]==s[(i+1)%l]:
        if i==l-1:
            re=True
            if len(seq)==0:
                all=True
            else:
                first=seq[0]//2
                end=now//2
                seq[0]=(seq[0]+now)
        now+=1
    else:
        seq.append(now)
        now=1
if all:
    ans=len(s)*k//2
else:
    seq=[i//2 for i in seq]
    if re:
        ans=sum(seq)*k-seq[0]+first+end
    else:
        ans=sum(seq)*k

print(ans)

Buggy submission (verdict: Runtime Error):
S = input()
K = int(input())
cnt = 0
for i in range(len(S)):
    if (S[i]==S[i+1])&(S[i]!=S[i-1]):
        cnt += K
print(cnt)

Buggy submission (verdict: Runtime Error):
S = input()
K = int(input())
cnt = 0
for i in range(len(S)-1):
    if (S[i]==S[i+1])&&(S[i-1]!=S[i]):
        cnt += K
print(cnt)

Buggy submission (verdict: Runtime Error):
S = input()
K = int(input())
cnt = 0
for i in range(len(S)-1):
    if S[i]==S[i+1]&&S[i-1]!=S[i]:
        cnt += K
print(cnt)
Problem p02550 (python)

Fixed submission:
N,X,M=map(int,input().split())
dist=[0 for i in range(M)]
A=X
loopin=-1
loopout=-1
ans=[0]
for i in range(N+1):
    if dist[A]!=0:
        loopin=dist[A]
        loopout=i
        ans.append(ans[-1]+A)
        break
    else:
        dist[A]=i
        ans.append(ans[-1]+A)
        A=(A*A)%M
if loopin==-1:
    print(ans[N])
    exit()
#print(roopin,roopout)
#print(ans)
A=X
loop=loopout-loopin
def solve(l,r):
    assert 0<=l and l<=r
    if r<=loopout:
        return ans[r]-ans[l]
    if l<loopin:
        return ans[loopin]-ans[l]+solve(loopin,r)
    x=(l-loopin)//loop
    y=(r-loopin)//loop
    #x*loop+loopin<=l<(x+1)*loop+loopin
    #y*loop+loopin<=r<(y+1)*loop+loopin
    if x==y:
        return ans[r-y*loop]-ans[l-x*loop]
    #以降はx<y
    tmp1=ans[l-x*loop]-ans[loopin]
    tmp2=(ans[loopout]-ans[loopin])*(y-x)
    tmp3=ans[r-y*loop]-ans[loopin]
    #print(l,r,x,y,tmp1,tmp2,tmp3)
    return tmp1+tmp2+tmp3
print(solve(0,N))

Buggy submission (verdict: Runtime Error):
N,X,M=map(int,input().split())
dist=[0 for i in range(M)]
A=X
loopin=-1
loopout=-1
ans=[0]
for i in range(N+1):
    if dist[A]!=0:
        loopin=dist[A]
        loopout=i
        ans.append(ans[-1]+A)
        break
    else:
        dist[A]=i
        ans.append(ans[-1]+A)
        A=(A*A)%M
if loopin==-1:
    print(ans[N])
#print(roopin,roopout)
#print(ans)
A=X
loop=loopout-loopin
def solve(l,r):
    assert 0<=l and l<=r
    if r<=loopout:
        return ans[r]-ans[l]
    if l<loopin:
        return ans[loopin]-ans[l]+solve(loopin,r)
    x=(l-loopin)//loop
    y=(r-loopin)//loop
    #x*loop+loopin<=l<(x+1)*loop+loopin
    #y*loop+loopin<=r<(y+1)*loop+loopin
    if x==y:
        return ans[r-y*loop]-ans[l-x*loop]
    #以降はx<y
    tmp1=ans[l-x*loop]-ans[loopin]
    tmp2=(ans[loopout]-ans[loopin])*(y-x)
    tmp3=ans[r-y*loop]-ans[loopin]
    #print(l,r,x,y,tmp1,tmp2,tmp3)
    return tmp1+tmp2+tmp3
print(solve(0,N))
Problem p02590 (python)

Fixed submission:
#https://qiita.com/sage-git/items/90c342fd2127ec39b874
import numpy as np
M=int(input())
P=200003
a=[int(i) for i in input().split()]
b=[0 for i in range(P)]
for i in range(M):
    b[a[i]]+=1
c=[0 for i in range(P-1)]
tmp=1
for i in range(P-1):
    c[i]=b[tmp]
    tmp=tmp*2
    tmp%=P
N = P-1
n0 = 2**int(np.ceil(np.log2(2*N - 1)))

A = np.zeros(n0)
B = np.zeros(n0)
for i in range(N):
    A[i],B[i]=c[i],c[i]

C = np.fft.ifft( np.fft.fft(A)*np.fft.fft(B) )

ret = [int(ci) for ci in np.real(C[:2*N - 1] + 0.5)]
ans=0
for k in range(2*N-1):
    ans+=ret[k]*pow(2,k,P)
for i in range(M):
    ans-=(a[i]*a[i])%P
print(ans//2)

Buggy submission (verdict: Runtime Error):
#https://qiita.com/sage-git/items/90c342fd2127ec39b874
import numpy as np
M=int(input())
P=200003
a=[int(i) for i in input().split()]
b=[0 for i in range(P)]
for i in range(M):
    b[a[i]]+=1
c=[0 for i in range(P-1)]
tmp=1
for i in range(P-1):
    c[i]=b[tmp]
    tmp=tmp*2
    tmp%=P
N = P-1
n0 = 2**int(np.ceil(np.log2(2*N - 1)))

A = np.zeros(n0)
B = np.zeros(n0)
for i in range(N):
    A[i],B[i]=c[i],c[i]

C = np.fft.ifft( np.fft.fft(A)*np.fft.fft(B) )

ret = [int(ci) for ci in np.real(C[:2*N - 1] + 0.5)]
ans=0
for k in range(2*N-1):
    ans+=ret[k]*pow(2,k,P)
for i in range(M):
    ans-=(a[i]*a[i])%P
print(ans//2)
Problem p02736 (python)

Fixed submission:
N=int(input())
a=[int(i)-1 for i in list(input())]
def solve(seq):
    if {0}==set(seq):
        return 0
    res=0
    for k in range(N):
        tmp=0
        if ((N-1)&k)==k:
            tmp=1
        #print(tmp)
        res+=tmp*seq[k]
        res%=2
    #print("#"*30)
    if res%2==1:
        return 1
    if 1 in set(seq):
        return 0
    seq2=[seq[i]//2 for i in range(N)]
    return solve(seq2)*2
print(solve(a))

Buggy submission (verdict: Runtime Error):
N=int(input())
a=[int(i)-1 for i in list(input())]
def solve(seq):
    res=0
    for k in range(N):
        tmp=1
        if (N&k)==k:
            tmp=0
        res+=tmp*seq[k]
        res%=2
    if res%2==1:
        return 1
    if 1 in set(seq):
        return 0
    seq2=[seq[i]//2 for i in range(N)]
    return solve(seq2)*2
print(solve(a))
Problem p02815 (python)

Fixed submission:
#T=(0,0,...,0)
#に変換するためのコストの2^N倍
N=int(input())
c=sorted([int(i) for i in input().split()])
mod=10**9+7
if N==1:
    print((2*c[0])%mod)
    exit()
ans=0
for k in range(N):
    a1=pow(2,N-2,mod)
    a2=(N-k+1)
    tmp=(a1*a2)%mod
    ans+=(c[k]*tmp)%mod
    ans%=mod
    #print(k,tmp)
ans=ans*pow(2,N,mod)
ans%=mod
print(ans)

Buggy submission (verdict: Runtime Error):
#T=(0,0,...,0)
#に変換するためのコストの2^N倍
N=int(input())
c=sorted([int(i) for i in input().split()])
mod=10**9+7
ans=0
for k in range(N):
    a1=pow(2,N-2,mod)
    a2=(N-k+1)
    tmp=(a1*a2)%mod
    ans+=(c[k]*tmp)%mod
    ans%=mod
    #print(k,tmp)
ans=ans*pow(2,N,mod)
ans%=mod
print(ans)
Problem p02891 (python)

Fixed submission:
def count(st):
    n=len(st)
    tmp=1
    res=[]
    for i in range(n-1):
        if st[i]==st[i+1]:
            tmp+=1
        else:
            res.append(tmp)
            tmp=1
    res.append(tmp)
    return res
S=input()
K=int(input())
T=S*3
N=len(S)
if N==1:
    print(K//2)
    exit()
if K<=2:
    Y=count(S*K)
    ans=0
    for i in Y:
        ans+=i//2
    print(ans)
    exit()
if S.count(S[0])==N:
    print((N*K)//2)
    exit()
X=[]
if S[0]==S[-1]:
    for j in range(1,N):
        if S[j-1]!=S[j]:
            break
    tmp=1
    for i in range(j,j+N-1):
        if T[i]==T[i+1]:
            tmp+=1
        else:
            X.append(tmp)
            tmp=1
    X.append(tmp)
else:
    X=count(S)

cnt=0
for i in X:
    cnt+=i//2
Y=count(T)
cnt2=0
for i in Y:
    cnt2+=i//2
print(cnt*(K-3)+cnt2)

Buggy submission (verdict: Runtime Error):
def count(st):
    n=len(st)
    tmp=1
    res=[]
    for i in range(n-1):
        if st[i]==st[i+1]:
            tmp+=1
        else:
            res.append(tmp)
            tmp=1
    res.append(tmp)
    return res
S=input()
K=int(input())
T=S*3
N=len(S)

if K<=2:
    Y=count(S*K)
    ans=0
    for i in Y:
        ans+=i//2
    print(ans)
    exit()
X=[]
if S[0]==S[-1]:
    for j in range(1,N):
        if S[j-1]!=S[j]:
            break
    tmp=1
    for i in range(j,j+N-1):
        if T[i]==T[i+1]:
            tmp+=1
        else:
            X.append(tmp)
            tmp=1
    X.append(tmp)
else:
    X=count(S)

cnt=0
for i in X:
    cnt+=i//2
Y=count(T)
cnt2=0
for i in Y:
    cnt2+=i//2
print(cnt*(K-3)+cnt2)
Problem p03016 (python)

Fixed submission:
L,A,B,M=map(int,input().split())
K=19
gap=[-1 for k in range(K)]
for k in range(K):
    tmp=10**k-A
    if tmp%B==0:
        gap[k]=-1+tmp//B
    else:
        gap[k]=tmp//B
    gap[k]=min(L-1,gap[k])
    gap[k]=max(-1,gap[k])
num=[0 for k in range(K)]
for k in range(1,K):
    #k-1,k
    num[k]=-gap[k-1]+gap[k]
def matrix(d):
    return [[pow(10,d,M),1,0],[0,1,B],[0,0,1]]
def mattime(P,Q):
    R=[[0,0,0],[0,0,0],[0,0,0]]
    for i in range(3):
        for j in range(3):
            for k in range(3):
                R[i][j]+=P[i][k]*Q[k][j]
                R[i][j]%=M
    return R
def matexp(P,n):
    if n==0:
        return [[1,0,0],[0,1,0],[0,0,1]]
    elif n%2==0:
        return matexp(mattime(P,P),n//2)
    else:
        return mattime(P,matexp(mattime(P,P),n//2))
Mat=[[1,0,0],[0,1,0],[0,0,1]]
for d in range(1,K):
    Mat=mattime(matexp(matrix(d),num[d]),Mat)
print((A*Mat[0][1]+Mat[0][2])%M)

Buggy submission (verdict: Runtime Error):
L,A,B,M=map(int,input().split())
gap=[-1 for k in range(37)]
for k in range(37):
    tmp=10**k-A
    if tmp%B==0:
        gap[k]=-1+tmp//B
    else:
        gap[k]=tmp//B
    gap[k]=min(L-1,gap[k])
    gap[k]=max(-1,gap[k])
num=[0 for k in range(37)]
for k in range(1,37):
    #k-1,k
    num[k]=-gap[k-1]+gap[k]

def egcd(a, b):
    (x, lastx) = (0, 1)
    (y, lasty) = (1, 0)
    while b != 0:
        q = a // b
        (a, b) = (b, a % b)
        (x, lastx) = (lastx - q * x, x)
        (y, lasty) = (lasty - q * y, y)
    return (lastx, lasty, a)
def inv(x):
    return egcd(x,M)[0]
ans=0
geta=0
for k in range(36,-1,-1):
    n=num[k]
    P=A+B*gap[k-1]
    Q=B
    R=pow(10,num[k],M)
    tmp=R*(P*(R-1)*(pow(R,n,M)-1)+n*Q*pow(R,n+1,M)-(n+1)*Q*pow(R,n,M)+Q)
    tmp%=M
    tmp*=pow(10,geta,M)
    tmp*=inv((R-1)**2)
    tmp%=M
    ans+=tmp
    ans%=M
    geta+=k*gap[k]
print(ans)
Problem p03038 (python)

Fixed submission:
N,M=map(int,input().split())
A=[int(i) for i in input().split()]
B=[0 for i in range(M)]
C=[0 for i in range(M)]
X=[]
for i in range(M):
    B[i],C[i]=map(int,input().split())
    X.append((B[i],C[i]))
A.sort()
X.sort(key=lambda x:x[1],reverse=True)
index=0
flag=1
for i in range(M):
    tmp=0
    for j in range(index,index+X[i][0]):
        if not(0<=j<N):
            break
        if A[j]<X[i][1]:
            A[j]=X[i][1]
            tmp+=1
        else:
            flag=0
            break
    if flag==0:
        break
    index+=tmp
print(sum(A))

Buggy submission (verdict: Runtime Error):
N,M=map(int,input().split())
A=[int(i) for i in input().split()]
B=[0 for i in range(M)]
C=[0 for i in range(M)]
X=[]
for i in range(M):
    B[i],C[i]=map(int,input().split())
    X.append((B[i],C[i]))
A.sort()
X.sort(key=lambda x:x[1],reverse=True)
index=0
flag=1
for i in range(M):
    tmp=0
    for j in range(index,index+X[i][0]):
        if A[j]<X[i][1]:
            A[j]=X[i][1]
            tmp+=1
        else:
            flag=0
            break
    if flag==0:
        break
    index+=tmp
print(sum(A))
Problem p03107 (python)

Fixed submission:
S=input()
N=len(S)
X=0
Y=0
for i in S:
    if i=="0":
        X+=1
    else:
        Y+=1
print(N-abs(X-Y))

Buggy submission (verdict: Runtime Error):
S=input();print(2*min(S.count("0")-S.count("1")))
Problem p03108 (python)

Fixed submission:
class UnionFind():
    n=1
    par=[0]
    rnk=[0]
    def __init__(self,size):
        self.n=size
        self.par=[i for i in range(self.n)]
        self.rnk=[0 for i in range(self.n)]
    def find(self,vertex1):
        if self.par[vertex1]==vertex1:
            return vertex1
        else:
            self.par[vertex1]=self.find(self.par[vertex1])
            return self.par[vertex1]
    def unite(self,vertex1,vertex2):
        vertex1=self.find(vertex1)
        vertex2=self.find(vertex2)
        if vertex1==vertex2:
            return
        if (self.rnk[vertex1]<self.rnk[vertex2]):
            self.par[vertex1]=vertex2
        else:
            self.par[vertex2]=vertex1
            if(self.rnk[vertex1]==self.rnk[vertex2]):
                self.rnk[vertex1]+=1
    def same(self,vetrex1,vertex2):
        return self.find(vetrex1)==self.find(vertex2)

N,M=map(int,input().split())
A=[0 for i in range(M)]
B=[0 for i in range(M)]
for i in range(M):
    A[i],B[i]=map(int,input().split())
    A[i]-=1;B[i]-=1
G=UnionFind(N)
D=dict()
for i in range(N):
    D[i]=1
ans=[(N*(N-1))//2]
for i in range(M)[::-1]:
    #print([G.find(i) for i in range(N)],A[i],B[i],D,ans[-1])
    a=G.find(A[i])
    b=G.find(B[i])
    G.unite(A[i],B[i])
    x=G.find(A[i])
    if a!=b:
        ans.append(ans[-1]-D[a]*D[b])
        if x==a:
            D[a],D[b]=D[a]+D[b],0
        else:
            D[a],D[b]=0,D[a]+D[b]
    else:
        ans.append(ans[-1])
for line in ans[:-1][::-1]:
    print(line)

Buggy submission (verdict: Runtime Error):
class UnionFind():
    n=1
    rnk=[0]
    par=[0]
    sze=[1]
    def __init__(self,N):
        self.n=N
        self.rnk=[0 for i in range(self.n)]
        self.par=[i for i in range(self.n)]
        self.sze=[1 for i in range(self.n)]
    def find(self,x):
        if x==self.par[x]:
            return x
        else:
            self.par[x]=self.find(self.par[x])
            return self.par[x]
    def unite(self,x,y):
        x=self.find(x)
        y=self.find(y)
        self.par[x]=y
        self.rnk[x]=1
        self.sze[y]+=self.sze[x]
        self.sze[x]=0
    def same(self,x,y):
        return self.find(x)==self.find(y)
    def size(self,x):
        return self.sze[self.find(x)]
N,M=map(int,input().split())
G=UnionFind(N)
A=[0 for i in range(M)]
B=[0 for i in range(M)]
ans=[0 for i in range(M+1)]
for i in range(M):
    A[i],B[i]=map(int,input().split())
    A[i]-=1;B[i]-=1
ans[M]=(N*(N-1))//2
for i in range(M-1,-1,-1):
    if G.same(A[i],B[i]):
        ans[i]=ans[i+1]
    else:
        ans[i]=ans[i+1]-G.size(A[i])*G.size(B[i])
    G.unite(A[i],B[i])
for i in range(1,M+1):
    print(ans[i])
Problem p03127 (python)

Fixed submission:
def gcd(a,b):
    x,y=max(a,b),min(a,b)
    if x%y==0:
        return y
    else:
        return gcd(y,x%y)
N=int(input())
A=[int(i) for i in input().split()]
ans=A[0]
for i in range(1,N):
    ans=gcd(ans,A[i])
print(ans)

Buggy submission (verdict: Runtime Error):
def gcd(a,b):
    x,y=max(a,b),min(a,b)
    if x%y==0:
        return y
    else:
        return (y,x%y)

N=int(input())
A=[int(i) for i in input().split()]
ans=A[0]
for i in range(1,N):
    ans=gcd(ans,A[i])
print(ans)