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

Fixed submission:
from collections import deque

n,m=map(int,input().split())

edges=[[] for _ in range(n)]#[[１番目の部屋からいける部屋],[２番目の部屋からいける部屋]...]

for _ in range(m):
    a,b=map(int,input().split())
    edges[a-1].append(b-1)
    edges[b-1].append(a-1)

todo=deque([[0,0]])
seen=[-1]*n
seen[0]=0

while todo:
    node,parent=todo.popleft()#現在探索している部屋、その親
    
    for to in edges[node]:
        if seen[to]!=-1:
            continue

        todo.append([to,node])
        seen[to]=node

print('Yes')

for parent in seen[1:]:
    print(parent+1)

Buggy submission (verdict: Runtime Error):
from collections import deque

n,m=map(int,input().split())

edges=[[] for _ in range(n)]#[[１番目の部屋からいける部屋],[２番目の部屋からいける部屋]...]

for _ in range(m):
    a,b=map(int,input().split())
    edges[a-1].append(b-1)
    edges[b-1].append(a-1)

todo=deque([0,0])
seen=[-1]*n
seen[0]=0

while todo:
    node,parent=todo.popleft()#現在探索している部屋、その親
    
    for to in edges[node]:
        if seen[to]!=-1:
            continue

        todo.append([to,node])
        seen[to]=node

print('Yes')

for parent in seen[1:]:
    print(parent+1)
Problem p02687 (python)

Fixed submission:
S=input()

if S=="ABC":
  print("ARC")
else:
  print("ABC")

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

if S=="ABC":
  print("ARC")
else:
  print("ABC")
Problem p02720 (python)

Fixed submission:
from collections import deque

K=int(input())

todo=deque(list(map(str,range(1,10))))

count=0

while todo:
    num=todo.popleft()
    count+=1

    if count==K:
        print(num)
        exit()
    
    base=int(num[-1])
    n1=base-1
    if n1!=-1:
        todo.append(num+str(n1))
    
    n2=base
    todo.append(num+str(n2))

    n3=base+1

    if n3!=10:
        todo.append(num+str(n3))

Buggy submission (verdict: Runtime Error):
from collections import deque

K=int(input())

todo=deque(list(map(str,range(1,10))))

count=0

while todo:
    num=todo.popleft()
    count+=1

    if count==k:
        print(num)
        exit()
    
    base=int(num[-1])
    n1=base-1
    if n1!=-1:
        todo.append(num+str(n1))
    
    n2=base
    todo.append(num+str(n2))

    n3=base+1

    if n3!=10:
        todo.append(num+str(n3))

Buggy submission (verdict: Runtime Error):
from collections import deque

K=int(input())
q=deque()
A=[]
q.append('0')
q.append('1')
q.append('2')
q.append('3')
q.append('4')
q.append('5')
q.append('6')
q.append('7')
q.append('8')
q.append('9')
q.append('10')
q.append('11')
q.append('12')

while len(A)<=K+10:
    snum=q.popleft()
    inum=int(snum)
    if snum[0]!='0':
        A.append(snum)
    
    if inum!=10 or inum!=11 or inum!=12: 
        if 1<=int(snum[0])<=8:
            q.append(str(int(snum[0])-1)+snum)
            q.append(str(int(snum[0])+1)+snum)

        elif int(snum[0])==0:
            q.append(str(int(snum[0])+1)+snum)
        
        elif int(snum[0])==9:
            q.append(str(int(snum[0])+1)+snum)
print(list(set(A))[K])
Problem p02761 (python)

Fixed submission:
N,M=map(int,input().split())
keta=[]
for i in range(N):
    keta.append('x')
ans=-1
for _ in range(M):
    si,ci=input().split()
    si=int(si)
    if keta[si-1]=='x':#sm
        keta[si-1]=ci
    else:
        if keta[si-1]!=ci:#sm
            break
else:
    if keta[0]=='0' and N!=1:#先頭要素が０かつ2桁以上の数なら
        print(-1)
        exit()
    
    if keta[0]=='x' and N==1:
        print(0)
        exit()
    
    if keta[0]=='x' and N>=2:
        keta[0]='1'
    for i in range(1,N):
        if keta[i]=='x':
            keta[i]='0'

    ans=int(''.join(keta))

print(ans)

Buggy submission (verdict: Runtime Error):
N,M=map(int,input().split())
keta=[]
for i in range(N):
    keta.append('x')
ans=-1
for _ in range(M):
    si,ci=input().split()
    si=int(si)
    if keta[si-1]=='x':
        keta[si-1]=ci
    else:
        if keta[si-1]!=ci:
            break
else:
    if keta[0]=='0' and N!=1:#先頭要素が０かつ2桁以上の数なら
        print(-1)
        exit()
    
    if keta[0]=='x' and N==1:
        print(0)
        exit()
    
    if keta[0]=='x' and N>=2:
        keta[0]='1'
    for i in range(1,3):
        if keta[i]=='x':
            keta[i]='0'

    ans=int(''.join(keta))

print(ans)

Buggy submission (verdict: Runtime Error):
N,M=map(int,input().split())
keta=[]
for i in range(N):
    keta.append('x')
ans=-1
for _ in range(M):
    si,ci=input().split()
    si=int(si)
    if keta[si-1]=='x':
        keta[si-1]=ci
    else:
        if keta[si-1]!=ci:
            break
else:
    if keta[0]=='0' and N!=1:#先頭要素が０かつ2桁以上の数なら
        print(-1)
        exit()
    
    if keta[0]=='x' and N==1:
        print(0)
        exit()
    if keta[0]=='x' and N>=2:
        keta[0]=1
    for i in range(1,3):
        if keta[i]=='x':
            keta[i]='0'

    ans=int(''.join(keta))

print(ans)
Problem p02796 (python)

Fixed submission:
N=int(input())
A=[]
ans=1
for i in range(N):
    Xi,Li=map(int,input().split())
    A.append([Xi-Li,Xi+Li])
A.sort(key=lambda x:x[1])

def interf(A1,A2):
    if A1[1]>A2[0]:
        return 1
    else:
        return 0
    
pre=A[0]
for i in range(1,N):
    if interf(pre,A[i])==0:
        ans+=1
        pre=A[i]
print(ans)

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

X_t=[]
L_t=[]
ans=0

for _ in range(N):
    x,l=map(int,input().split())
    X_t.append(x)
    L_t.append(l)

tmp=zip(X_t,L_t)
XL=sorted(tmp)

X=[]
L=[]

for x,l in XL:
    X.append(x)
    L.append(l)
    

nls=[0]
for i in range(1,N-1):
    if (X[i]+L[i]>X[i+1]-L[i+1]) and (X[i]-L[i]<X[i-1]+L[i-1]):
        ans+=1
    else:
        nls.append(i)
nls.append(N-1)
        
for i in range(len(nls)-1):
    if nls==[]:
        break
    if len(nls)==1:
        break
    if (i-2)>len(nls):
        break
    
    if X[nls[i]]+L[nls[i]]>X[nls[i+1]]-L[nls[i+1]]:
        ans+=1

if X[-1]-L[-1]<X[-2]+L[-2]:
    ans+=1
print(N-ans)
Problem p02802 (python)

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

pn_num=0
WA_list=[0]*N
AC_list=[0]*N

for _ in range(M):
    pi,Si=input().split()
    pi=int(pi)
        
    if Si=='AC':
        if AC_list[pi-1]==0:
            pn_num+=WA_list[pi-1]
            AC_list[pi-1]=1
    
    else:
        WA_list[pi-1]+=1
    
print(sum(AC_list),pn_num)

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

pn_num=0
AC_list=[0]*N

for _ in range(M):
    pi,Si=input().split()
    pi=int(pi-1)
        
    if Si=='AC':
        AC_list[pi]=1
    
    else:
        if AC_list[pi]==0:
            pn_num+=1
    
print(sum(AC_list),pn_num)

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

pn_num=0
WA_list=[0]*N
AC_list=[0]*N

for _ in range(M):
    pi,Si=input().split()
    pi=int(pi-1)
        
    if Si=='AC':
        pn_num+=WA_list[pi-1]
    
    else:
        WA_list[pi-1]+=1
    
print(sum(AC_list),pn_num)

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

pn_num=0
AC_list=[0]*N

for _ in range(M):
    pi,Si=input().split()
    pi=int(pi-1)
        
    if Si=='AC':
        AC_list[pi]=1
    
    else:
        if AC_list[pi]==0:
            pn_num+=1
    
print(sum(AC_list),pn_num)
Problem p02807 (python)

Fixed submission:
MOD = 10 ** 9 + 7
N = int(input())
x = list(map(int, input().split()))
x.sort()
 
kaijo = [1]
for i in range(1, N):
    kaijo.append(kaijo[-1] * i % MOD)
 
ans = 0
for i in range(N - 1):
    ans = (ans * (i + 1) + (x[-1] - x[i]) * kaijo[i]) % MOD
 
print(ans)

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

N=int(input())
x=list(map(int,input().split()))
MOD=10**9+7


x_dist=[x[i+1]-x[i] for i in range(N-1)]

def Cn(n,Cn_1):
    return n*Cn_1+1

ans=0
Cn_list=[1]

for n in range(2,N):
    temp=Cn(n,Cn_list[n-2])
    Cn_list.append(temp)

for i in range(N-1):
    ans+=Cn_list[i]*x_dist[i]*factorial(N-1)/(i+1)

print((ans)%MOD)

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

N=int(input())
x=list(map(int,input().split()))
MOD=10**9+7


x_dist=[x[i+1]-x[i] for i in range(N-1)]

def Cn(n,Cn_1):
    return n*Cn_1+1

ans=0
Cn_list=[1]

for n in range(2,N):
    #fact=1
    #for i in range(1,N):
        #if i!=n:
    #    fact=fact*i
    
    temp=Cn(n,Cn_list[n-2])
    Cn_list.append(temp)

for i in range(N-1):
    ans+=Cn_list[i]*x_dist[i]*factorial(N-1)/(i+1)

print((ans)%MOD)

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

N=int(input())
x=list(map(int,input().split()))
MOD=10**9+7


x_dist=[x[i+1]-x[i] for i in range(N-1)]

def Cn(n,Cn_1):
    return Cn_1+1/n

ans=0
Cn_list=[1]

for n in range(2,N):
    temp=Cn(n,Cn_list[n-2])
    Cn_list.append(temp)

for i in range(N-1):
    ans+=Cn_list[i]*x_dist[i]

print(int((ans*factorial(N-1)))%MOD)

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

N=int(input())
x=list(map(int,input().split()))
MOD=10**9+7


x_dist=[x[i+1]-x[i] for i in range(N-1)]

def Cn(n,Cn_1):
    return Cn_1+1/n

ans=0
Cn_list=[1]

for n in range(2,N):
    temp=Cn(n,Cn_list[n-2])
    Cn_list.append(temp)

for i in range(N-1):
    ans+=Cn_list[i]*x_dist[i]

print((ans*factorial(N-1))%MOD)

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

N=int(input())
x=list(map(int,input().split()))
MOD=10**9+7


x_dist=[x[i+1]-x[i] for i in range(N-1)]

def Cn(n,Cn_1):
    return Cn_1+1/n

ans=0
Cn_list=[1]

for n in range(2,N):
    temp=Cn(n,Cn_list[n-2])
    Cn_list.append(temp)

for i in range(N-1):
    ans+=Cn_list[i]*x_dist[i]

print((ans*factorial(N-1))%MOD)

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

N=int(input())
x=list(map(int,input().split()))
MOD=10**9+7


x_dist=[x[i+1]-x[i] for i in range(N-1)]

def Cn(n,Cn_1):
    return Cn_1+1/n

ans=0
Cn_list=[1]

for n in range(2,N):
    temp=Cn(n,Cn_list[n-2])
    Cn_list.append(temp)

for i in range(N-1):
    ans+=Cn_list[i]*x_dist[i]

print((ans*factorial(N-1))%MOD)

Buggy submission (verdict: Runtime Error):
N=int(input())
x=list(map(int,input().split()))
ans=0
MOD=10**9+7

import math


for i in range(2,N+1):#iは右端からの数
    #(x[-1]-x[-i])/i+(x[-2]-x[-i])/i......(x[-i+1]-x[-i])/i
    for j in range(i-1):
        ans+=(x[-j-1]-x[-i])/(i-1)
print(int((ans*math.factorial(N-1))%MOD))
Problem p02814 (python)

Fixed submission:
#ABC150_D

from fractions import gcd
N,M=map(int,input().split())
A=list(map(int,input().split()))
lcm=A[0]//2

for x in A:
    x//=2
    g=gcd(lcm,x)
    
    if (lcm//g)%2!=(x//g)%2:
        print(0)
        exit()
    
    lcm=lcm*x//g
print((M//lcm+1)//2)

Buggy submission (verdict: Runtime Error):
#ABC150_D

from fractions import gcd
N,M=map(int,input().split())
A=list(map(int,input().split()))
lcm=a[0]//2

for x in A:
    x//=2
    g=gcd(lcm,x)
    
    if (lcm//g)%2!=(x//g)%2:
        print(0)
        exit()
    
    lcm=lcm*x//g
print((M//lcm+1)//2)
Problem p02837 (python)

Fixed submission:
N = int(input())
A = [[] for _ in range(N)]
for i in range(N):
    for _ in range(int(input())):
        A[i].append([int(s) for s in input().split()])

ret = 0
for i in range(2 ** N):#2**Nだけ正解の候補がある
    bits = [i >> j & 1 for j in range(N)]#　N桁の２進数iについて、逆順に並べた配列が生成
    #print(bits)
    for i, a in enumerate(A):#i→人、a→人iの証言のリスト
        if bits[i] == 0:#人iが正直者じゃない場合、continueして次の人の証言に移行
            continue
        for x, y in a:
            # print(bits, bits[x - 1], y)
            if bits[x - 1] == y:#正解の候補と証言が一致する場合、その人の次の証言を参照
                continue
            break#そうでない場合、その人の証言を聞くのをやめて次の人の証言を聞く
        else:#breakでループを抜けなかったときにのみ、elseが実行
            continue#このcontinueは２つ上のfor文のcontinueつまり、間違った証言がある場合、一つ下のbreakが評価されて、次の正解候補にうつる
        break
    else:#breakでループを抜けなかったときにのみ、elseが実行
        ret = max(ret, sum(bits))
print(ret)

Buggy submission (verdict: Runtime Error):
N = int(input())
A = [[] for _ in range(N)]
for i in range(N):
    for _ in range(int(input())):
        A[i].append([int(s) for s in input().split()])

ret = 0
for i in range(2 ** N):#2**Nだけ正解の候補がある
    bits = [i >> j & 1 for j in range(N)]#　N桁の２進数iについて、逆順に並べた配列が生成
    #print(bits)
    for i, a in enumerate(A):#i→人、a→人iの証言のリスト
        if bits[i] == 0:#人iが正直者じゃない場合、continueして次の人の証言に移行
            continue
        for x, y in a:
            # print(bits, bits[x - 1], y)
            if bits[x - 1] == y:#正解の候補と証言が一致する場合、その人の次の証言を参照
                continue
            break　　　　　　　　　#そうでない場合、その人の証言を聞くのをやめて次の人の証言を聞く
        else:#breakでループを抜けなかったときにのみ、elseが実行
            continue#このcontinueは２つ上のfor文のcontinueつまり、間違った証言がある場合、一つ下のbreakが評価されて、次の正解候補にうつる
        break
    else:#breakでループを抜けなかったときにのみ、elseが実行
        ret = max(ret, sum(bits))
print(ret)
Problem p02838 (python)

Fixed submission:
#ABC147_D
#N個の数字から2個選ぶの全組み合わせのXORを足してmodする問題

import numpy as np

N = int(input())
arr = np.array([int(i) for i in input().split()])
ans = 0
mod=10**9+7


for i  in range(60):
    c1=np.count_nonzero(arr&1)#arrの最下位bitの論理和。arrの最下位bitが1の数をカウント
    c0=N-c1#arrの最下位bitが0の数
    ans+=2**i*c1*c0#c1個の中から1つ選ぶ組み合わせとc0個の中から1つ選ぶ組み合わせの掛け算が、該当bitがXOR＝１となる組み合わせの数
    arr>>=1#最下位bitを変更
print(ans%mod)

Buggy submission (verdict: Runtime Error):
#ABC147_D
#N個の数字から2個選ぶの全組み合わせのXORを足してmodする問題

import numpy as np

N = int(input())
arr = np.array([int(i) for i in input().split()])
ans = 0
mod=10**9+7


for i  in range(60):
    c1=np.count_nonzero(arr&1)#arrの最下位bitの論理和。arrの最下位bitが1の数をカウント
    c0=n-c1#arrの最下位bitが0の数
    ans+=2**i*c1*c0#c1個の中から1つ選ぶ組み合わせとc0個の中から1つ選ぶ組み合わせの掛け算が、該当bitがXOR＝１となる組み合わせの数
    arr>>=1#最下位bitを変更
print(s%mod)

Buggy submission (verdict: Runtime Error):
#ABC147_D
#N個の数字から2個選ぶの全組み合わせのXORを足してmodする問題

import numpy as np

N = int(input())
arr = np.array([int(i) for i in input().split()])
ans = 0
mod=10**9+7


for i  in range(60):
    c1=np.count_nonzero(arr&1)#arrの最下位bitの論理和。arrの最下位bitが1の数をカウント
    c0=n-c1#arrの最下位bitが0の数
    ans+=2**i*c1*c0#c1個の中から1つ選ぶ組み合わせとc0個の中から1つ選ぶ組み合わせの掛け算が、該当bitがXOR＝１となる組み合わせの数
    arr>>=1#最下位bitを変更
print(s%mod)

Buggy submission (verdict: Runtime Error):
#D
import numpy as np
N=int(input())
A=list(map(int,input().split()))
ans=0
for i in range(N-1):
    B=np.full(len(A)-i-1,A[i])
    C=np.bitwise_xor(A[i+1:],B)
    ans+=np.sum(C)
print(ans%(10**9+7))

Buggy submission (verdict: Runtime Error):
#D
import numpy as np
N=int(input())
A=list(map(int,input().split()))
ans=0
for i in range(N-1):
    B=np.full(len(A)-i-1,A[i])
    C=np.bitwise_xor(A[i+1:],B)
    ans+=np.sum(C)
print(ans%(10**9+7))
Problem p02861 (python)

Fixed submission:
import math
import itertools
 
N=int(input())
P=[]
all_dist=[]
 
def Len(X,Y):
    return math.sqrt((X[0]-Y[0])**2+(X[1]-Y[1])**2)

for _ in range(N):
    a,b=map(int,input().split())
    P.append([a,b])
#print('townmap_is',P)
 
route=list(itertools.permutations(P))
#print(route)
 
for k in range(math.factorial(N)):
    B=0
    A=list(route[k])
    for i in range(len(A)-1):
        B+=Len(A[i],A[i+1])
    all_dist.append(B)
ans=sum(all_dist)/len(all_dist)
 
print(str(ans))

Buggy submission (verdict: Runtime Error):
ソースコード 拡げる

Copy
Copy
import math
import itertools
 
N=int(input())
P=[]
all_dist=[]
 
 
def Len(X,Y):
    return math.sqrt((X[0]-Y[0])**2+(X[1]-Y[1])**2)
 
for _ in range(N):
    a,b=map(int,input().split())
    P.append([a,b])
#print('townmap_is',P)
 
route=list(itertools.permutations(P))
#print(route)
 
for k in range(math.factorial(N)):
    B=0
    A=list(route[k])
    for i in range(len(A)-1):
        B+=Len(A[i],A[i+1])
    all_dist.append(B)
ans=sum(all_dist)/len(all_dist)
 
print(str(ans))
Problem p02899 (python)

Fixed submission:
#ABC142_C
from operator import itemgetter
N=int(input())
A=list(map(int,input().split()))
ans=[i+1 for i,_ in sorted(enumerate(A),key=itemgetter(1))]

print(*ans)

Buggy submission (verdict: Runtime Error):
#ABC142_C
N=int(input())
A=list(map(int,input().split()))
ans=[i+1 for i,_ in sorted(enumerate(A),key=itemgetter(1))]

print(*ans)

Buggy submission (verdict: Runtime Error):
#ABC142_C
N=int(input())
A=list(map(int,input().split()))
ans=[i+1 for i,_ in sorted(enumerate(A),key=itemgetter(1))]
print(*ans)
Problem p02911 (python)

Fixed submission:
#ABC141_C
import numpy as np
N,K,Q=map(int,input().split())
ans=(K-Q)*np.ones((1,N),dtype='int32')

for _ in range(Q):
    idx=int(input())
    ans[0,idx-1]+=1
ans=ans.tolist()[0]
for i in range(len(ans)):
    if ans[i]>0:
        print('Yes')
    else:
        print('No')

Buggy submission (verdict: Runtime Error):
#ABC141_C
N,K,Q=map(int,input().split())
ans=[K-Q]*N
for _ in range(Q):
    ans[int(input())-1]+=1
for i in range(Q):
    if ans[i]>0:
        print('Yes')
    else:
        print('No')

Buggy submission (verdict: Runtime Error):
#ABC141_C
N,K,Q=map(int,input().split())
ans=(K-Q)*np.ones((1,N),dtype='int32')

for _ in range(Q):
    idx=int(input())
    ans[0,idx-1]+=1
ans=ans.tolist()[0]
for i in range(len(ans)):
    if ans[i]>0:
        print('Yes')
    else:
        print('No')

Buggy submission (verdict: Runtime Error):
#ABC141_C
N,K,Q=map(int,input().split())
ans=(K-Q)*np.ones((1,N),dtype='int32')
print(ans)
for _ in range(Q):
    idx=int(input())
    ans[0,idx-1]+=1
ans=ans.tolist()[0]
for i in range(len(ans)):
    if ans[i]>0:
        print('Yes')
    else:
        print('No')
Problem p02917 (python)

Fixed submission:
#ABC140_C
N=int(input())
A=[0]*N
B=[int(i) for i in input().split()]
A[0]=B[0]

for i in range(1,N-1):
    A[i]=min(B[i-1],B[i])
A[N-1]=B[N-2]

print(sum(A))

Buggy submission (verdict: Runtime Error):
#ABC140_C
N=int(input())
A=[0]*N
B=[int(i) for i in input().split()]
A[0]=B[0]

for i in range(1,N):
    A[i]=max(A[i-1],B[i-1],B[i])
print(*A)

Buggy submission (verdict: Runtime Error):
#ABC140_C
N=int(input())
A=[0]*N
B=[]
for _ in range(N-1):
    B.append(int(input()))
A[0]=B[0]

for i in range(1,N):
    A[i]=max(A[i-1],B[i-1],B[i])
print(*A)

Buggy submission (verdict: Runtime Error):
#ABC140_C
N=int(input())
A=[0]*N
for _ in range(N-1):
    B.append(int(input()))
A[0]=B[0]

for i in range(1,N):
    A[i]=max(A[i-1],B[i-1],B[i])
print(*A)
Problem p02947 (python)

Fixed submission:
#ABC137_C
from collections import Counter
N=int(input())
S=[input() for i in range(N)]

ctr=Counter()
ans=0

for s in S:
    a=''.join(sorted(list(s)))
    if a in ctr:
        ans+=ctr[a]
    ctr[a]+=1
print(ans)

Buggy submission (verdict: Runtime Error):
#ABC137_C
N=int(input())
ans=[]
cnt=0
for _ in range(N):
    str_list=input()
    dic={}
    for i in range(10):
        if str_list[i] in dic:
            dic[str_list[i]]+=1
        else:
            dic[str_list[i]]=1
    ans.append(dic)
while len(ans)>1: 
    cnt+=temp=ans.count(ans.pop(0))
print(cnt)
Problem p02995 (python)

Fixed submission:
#ABC_131_C
import fractions
A,B,C,D=list(map(int,input().split()))
#B以下の答え
CD_lcm=C*D//fractions.gcd(C,D)

underB=B-B//C-B//D+B//CD_lcm
underA_1=A-1-(A-1)//C-(A-1)//D+(A-1)//CD_lcm

print(underB-underA_1)

Buggy submission (verdict: Runtime Error):
#ABC_131_C
import math

A,B,C,D=list(map(int,input().split()))


def f(A,B,X):
    if A%X==0 or B%X==0:
        X_num=1+(B-A)//X
    else:
        X_num=(B-A)//X
    return X_num


C_num=f(A,B,C)
D_num=f(A,B,D)

CD_m=C*D//math.gcd(C,D)

CD_num=f(A,B,CD_m)

ans=(B-A+1)-C_num-D_num+CD_num
print(ans)
Problem p03061 (python)

Fixed submission:
#ABC125_C

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

def gcd(x,y):
    if x<y:
        x,y=y,x
    if y==0:
        return x
    return gcd(x%y,y)

LCD=[A[0]]
RCD=[A[-1]]
for i in range(1,N):
    LCD.append(gcd(LCD[-1],A[i]))
    RCD.append(gcd(RCD[-1],A[-i-1]))

ans=1

if RCD[N-2]>ans:
    ans=RCD[N-2]

for i in range(1,N-1):
    if gcd(LCD[i-1],RCD[N-i-2])>ans:
        ans=gcd(LCD[i-1],RCD[N-i-2])

if LCD[N-2]>ans:
    ans=LCD[N-2]
print(ans)

Buggy submission (verdict: Runtime Error):
#ABC125_C
import fractions
from functools import reduce
 
def gcd(nums):
    return reduce(fractions.gcd,nums)
 
N=int(input())
A=list(map(int,input().split()))
ans=1
       
for i in range(N):
    temp=A.copy()
    temp.reduce(temp[i])
    if gcd(temp) > ans:
        ans=gcd(temp)
print(ans)
Problem p03086 (python)

Fixed submission:
#ABC122B パターン2　カウントアップMAX方式

S=input()
N=len(S)

cnt=0
ans=0
for s in S:
    if s in "ACGT":
        cnt+=1
        ans=max(ans,cnt)
    else:
        cnt=0

print(ans)

Buggy submission (verdict: Runtime Error):
#ABC122B パターン１　部分文字列全探索
S=input()
N=len(S)

ans=0
'''
for i in range(N):
    if S[i] in "ACGT":
        ans=1

for l in range(N-1):
    for r in range(l+1,N):
        for s in S[l:r]:
            if not s in "ACGT":
                break
        else:
            ans=max(ans,len(S[l:r])) 
'''

for i in range(N):
    for j in range(i,N):
        if all("ACGT".count(c)==1 if for c in S[i:j+1]):
            ans=max(ans,j-i+1)

print(ans)
Problem p03111 (python)

Fixed submission:
N,A,B,C=map(int,input().split())
L=[int(input()) for _ in range(N)]
from itertools import product

ans=10**18

for pattern in product(range(4),repeat=N):
    MP=0
    take=[0]*3
    for index,length in zip(pattern,L):
        if index==3:
            continue
        if take[index]!=0:
            MP+=10
        take[index]+=length
    if take[0]!=0 and take[1]!=0 and take[2]!=0:
        MP+=abs(A-take[0])
        MP+=abs(B-take[1])
        MP+=abs(C-take[2])
        ans=min(MP,ans)
print(ans)

Buggy submission (verdict: Runtime Error):
N,A,B,C=map(int,input().split())
L=[int(input()) for _ in range(N)]

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

ans=10**18
def cost_calc(pp,TAKEs):
    if TAKEs==[]:
        return 10**8
    
    else:
        ans=0
        ans+=(len(TAKEs)-1)*10
        ans+=abs(pp-sum(TAKEs))
        return ans

assign=[]#[A,B,C,none]

for pattern in product([0,1,2,3],repeat=N):
    MP=0
    take=[0]*3
    for index,length in zip(pattern,l):
        if index==3:
            continue
        if take[index]!=0:
            MP+=10
        take[index]+=length
    if take[0]!=0 and take[1]!=0 and take[2]!=0:
        MP+=abs(A-take[0])
        MP+=abs(B-take[1])
        MP+=abs(C-take[2])
        ans=min(MP,ans)
print(ans)
Problem p03164 (python)

Fixed submission:
#dp[i][sum_v]:= i-1以下の品物の中から、価値をsum_v以上になる時の重さの最小値

N,W=map(int,input().split())

w,v=[0],[0]

for _ in range(N):
    wi,vi=map(int,input().split())
    w.append(wi)
    v.append(vi)

dp=[[10**12 for _ in range(N*max(v)+1)] for _ in range(N+1)]
dp[0][0]=0

for i in range(N):
    for sum_v in range(N*max(v)+1):
        if sum_v-v[i+1]>=0:
            dp[i+1][sum_v]=min(dp[i][sum_v-v[i+1]]+w[i+1],dp[i][sum_v])
        else:
            dp[i+1][sum_v]=dp[i][sum_v]

ans=0

for sum_v in range(N*max(v)+1):
    if dp[N][sum_v]<=W:
        ans=max(ans,sum_v)
print(ans)

Buggy submission (verdict: Runtime Error):
#dp[i][sum_v]:= i-1以下の品物の中から、価値をsum_v以上になる時の重さの最小値

N,W=map(int,input().split())

w,v=[0],[0]

for _ in range(N):
    wi,vi=map(int,input().split())
    w.append(wi)
    v.append(vi)

dp=[[10**12 for _ in range(N*max(v)+1)] for _ in range(N+1)]
dp[0][0]=0

for i in range(N):
    for sum_v in range(N*max(v)+1):
        if sum_v-v[i]>=0:
            dp[i+1][sum_v]=min(dp[i][sum_v-v[i+1]]+w[i+1],dp[i][sum_v])
        else:
            dp[i+1][sum_v]=dp[i][sum_v]

ans=0

for sum_v in range(N*max(v)+1):
    if dp[N+1][sum_v]<=W:
        ans=max(ans,sum_v)
print(ans)

Buggy submission (verdict: Runtime Error):
#dp[i][sum_v]:= i-1以下の品物の中から、価値をsum_v以上になる時の重さの最小値
import math
N,W=map(int,input().split())

w,v=[0],[0]

for _ in range(N):
    wi,vi=map(int,input().split())
    w.append(wi)
    v.append(vi)

dp=[[math.inf for _ in range(N*max(v)+1)] for _ in range(N+1)]
dp[0][0]=0

for i in range(N):
    for sum_v in range(N*max(v)+1):
        if sum_v-v[i]>=0:
            dp[i+1][sum_v]=min(dp[i][sum_v-v[i+1]]+w[i+1],dp[i][sum_v])
        else:
            dp[i+1][sum_v]=dp[i][sum_v]
#print(dp)

ans=0
for i in range(N+1):
    for sum_v in range(N*max(v)+1):
        if dp[i][sum_v]<=W:
            ans=max(ans,sum_v)
print(ans)