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

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

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


def need(L):
    if L == [] or max(L) == 0:
        return 0
    if min(L) > 0:
        l = [L[i]-1 for i in range(len(L))]
        return need(l)+1
    else:
        i = L.index(0)
        l = L[:i]
        m = L[i+1:]
        return need(l)+need(m)


print(need(H))

Buggy submission (verdict: Runtime Error):
N=int(inpput())
H=list(map(int,input().split()))
ct=0
for i in range(N):
  t=H[i]
  for j in range(i+1,N):
    if H[j]==0:
      break
    H[j]=max(H[j]-t,0)
  ct+=t
print(ct)
Problem p03161 (python)

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

# 移動量が最大2から最大Kになっただけ
# でもちょっとめんどい
# K回比較, を適当に関数にしとくことでforで回せるようになるらしい

dp=[float("inf")]*N
dp[0]=0
for i in range(1,N):
    for j in range(K):
        if i>j:
            dp[i] = min(dp[i], dp[i-j-1] + abs(H[i] - H[i-j-1]))
        # print(dp[i])
    # print(dp)
print(dp[N-1])

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

# 移動量が最大2から最大Kになっただけ
# でもちょっとめんどい
# K回比較, を適当に関数にしとくことでforで回せるようになるらしい

dp=[float("inf")]*N
dp[0]=0
for i in range(1,N):
    for j in range(K):
        if i>j:
            dp[i] = min(dp[i], dp[i-j-1] + abs(H[i] - H[i-j-1]))
        # print(dp[i])
    print(dp)
print(dp[N-1])
Problem p03166 (python)

Fixed submission:
import sys
sys.setrecursionlimit(10**6)
N, M = list(map(int, input().split()))
P = [set() for _ in range(N)]
for i in range(M):
    x, y = list(map(int, input().split()))
    x -= 1
    y -= 1
    P[x].add(y)

dp = [-1]*N


def lpth(n):
    if dp[n] > -1:
        return dp[n]
    l = P[n]
    # print(l)
    if l:
        s = [lpth(k) for k in l]
        # print(s)
        a = max(s)+1
    else:
        a = 0
    dp[n] = a
    return a


for i in range(N):
    dp[i] = lpth(i)
print(max(dp))
# print(dp)

Buggy submission (verdict: Runtime Error):
N,M=list(map(int, input().split()))
P=[set() for _ in range(N)]
for i in range(M):
    x,y=list(map(int, input().split()))
    x-=1
    y-=1
    P[x].add(y)

dp=[-1]*N

def lpth(n):
    if dp[n]>-1:
        return dp[n]
    l=P[n]
    # print(l)
    if l:
        s=[lpth(k) for k in l]
        # print(s)
        a=max(s)+1
    else:
        a=0
    dp[n]=a
    return a

for i in range(N):
    dp[i]=lpth(i)
print(max(dp))
Problem p03169 (python)

Fixed submission:
from collections import Counter
import sys


def main():
    sys.setrecursionlimit(10**6)
    readline = sys.stdin.buffer.readline
    N = int(readline())
    A = list(map(int, readline().split()))
    C = Counter(A)

    l, m, n = C[3], C[2], C[1]
    dp = [[[-1]*(N+1) for _ in range(N+1)] for _ in range(N+1)]
    dp[0][0][0] = 0

    def exval(i, j, k):
        if dp[i][j][k]!=-1:
            return dp[i][j][k]
        s = N
        if i > 0:
            s += i*exval(i-1, j+1, k)
        if j > 0:
            s += j*exval(i, j-1, k+1)
        if k > 0:
            s += k*exval(i, j, k-1)
        dp[i][j][k] = s / (i+j+k)
        return dp[i][j][k]


    print(exval(l, m, n))
    
if __name__ == "__main__":
    main()

Buggy submission (verdict: Runtime Error):
from collections import Counter
from functools import lru_cache
N = int(input())
A = list(map(int, input().split()))
C = Counter(A)

@lru_cache(maxsize=10*7)
def exval(l, m, n):
    if -1 in [l, m, n]:
        return 0
    if (l, m, n) == (0, 0, 0):
        return 0
    return (l*exval(l-1, m+1, n) + m*exval(l, m-1, n+1) +
            n*exval(l, m, n-1) + N) / (l+m+n)


l, m, n = C[3], C[2], C[1]
print(exval(l, m, n))

Buggy submission (verdict: Runtime Error):
from collections import Counter
from functools import lru_cache
N = int(input())
A = list(map(int, input().split()))
C = Counter(A)

@lru_cache(maxsize=10*7)
def exval(l, m, n):
    if -1 in [l, m, n]:
        return 0
    if (l, m, n) == (0, 0, 0):
        return 0
    return (l*exval(l-1, m+1, n) + m*exval(l, m-1, n+1) +
            n*exval(l, m, n-1) + N) / (l+m+n)


l, m, n = C[3], C[2], C[1]
print(exval(l, m, n))
Problem p03239 (python)

Fixed submission:
N,T=list(map(int, input().split()))
a=10**5
for _ in range(N):
  c,t=list(map(int, input().split()))
  if t<=T:
    a=min(c,a)
if a==10**5:
  print('TLE')
else:
  print(a)

Buggy submission (verdict: Runtime Error):
N,T=list(map(int, input().split()))
a=10**5
for _ in range(N):
  c,t=list(map(int, input().split()))
  if t<=T:
    a=min(c.a)
if a==10**5:
  print('TLE')
else:
  print(c)
Problem p03282 (python)

Fixed submission:
S=input()
K=int(input())
i=0
while S[i]=='1' and K>i+1 and i<len(S):
  i+=1
if i==len(S):
  i=0
print(S[i])

Buggy submission (verdict: Runtime Error):
S=input()
i=0
while S[i]!='1':
  i+=1
else:
  i=0
print(S[i])
Problem p03323 (python)

Fixed submission:
A,B=list(map(int, input().split()))
if A<=8 and B<=8:
  print('Yay!')
else:
  print(':(')

Buggy submission (verdict: Runtime Error):
A,B=list(map(int, input().split()))
if A<=8 and B<=8:
  print('Yay!')
else:
  peint(':(')
Problem p03385 (python)

Fixed submission:
S=input()
L=''.join(sorted(S))
if L=='abc':
  print('Yes')
else:
  print('No')

Buggy submission (verdict: Runtime Error):
S=input()
S.sort()
if S=='abc':
  print('Yes')
else:
  print('No')

Buggy submission (verdict: Runtime Error):
S-input()
S.sort()
if S=='abc':
  print('Yes')
else:
  print('No')
Problem p03469 (python)

Fixed submission:
date=str(input())
print(date.replace("2017","2018",1))

Buggy submission (verdict: Runtime Error):
date=str(input())
data.replace("2017","2018")
print(data)

Buggy submission (verdict: Runtime Error):
date=str(input())
data.replace("2017","2018")
Problem p03472 (python)

Fixed submission:
N, H = list(map(int, input().split()))
A = [0]*N
B = [0]*N
for i in range(N):
    a, b = list(map(int, input().split()))
    A[i], B[i] = a, b
a = max(A)
T = 0
ct = 0
B = reversed(sorted(B))
for b in B:
    if b > a:
        ct += 1
        T += b
    if T >= H:
        break
print(ct + max((H-T+a-1)//a, 0))

Buggy submission (verdict: Runtime Error):
N, H = list(map(int, input().split()))
A = [0]*N
B = [0]*N
for i in range(N):
    a, b = list(map(int, input().split()))
    A[i], B[i] = a, b
a = max(A)
T = 0
ct = 0
B.sort(reversed=True)
for b in B:
    if b > a:
        ct += 1
        T += b
    if T >= H:
        break
print(ct + max((H-T+a-1)//a, 0))
Problem p03493 (python)

Fixed submission:
#ABC_081_A_Placing_Marbles
a=input(str())
count=0
for i in range(0,3):
	if a[i]=='1':
		count+=1
print(count)

Buggy submission (verdict: Runtime Error):
from bisect import bisect_right

N,K=list(map(int, input().split()))
A=list(map(int, input().split()))
A.sort()
S=set(A)
S=list(S)
B=[]

def bisectsearch_right(L, a):
    i = bisect_right(L, a)
    return(i)

for i in S:
  a=A[0]
  j = bisect_right(A,a)
  B+=[j]
  del A[:j]
B.sort()
# print(B)
C=B[:len(S)-K]
print(sum(C))
Problem p03573 (python)

Fixed submission:
a,b,c=list(map(int,input().split()))
if a==b:
  print(c)
elif b==c:
  print(a)
else:
  print(b)

Buggy submission (verdict: Runtime Error):
a,b,c=list(map(int,input().split()))
if a==b:
  print(c)
elif b==c:
  print(a)
eles:
  print(b)
Problem p03777 (python)

Fixed submission:
a,b=list(input().split())
if a==b:
  print('H')
else:
  print('D')

Buggy submission (verdict: Runtime Error):
a,b=list(input())
if a==b:
  print('H')
else:
  print('D')
Problem p03779 (python)

Fixed submission:
X=int(input())
ct=1
sum=1
while X>sum:
  ct+=1
  sum+=ct
print(ct)

Buggy submission (verdict: Runtime Error):
X=abs(int(input()))
ct=1
sum=1
while X<=sum:
  ct+=1
  sub+=ct
print(ct)X=int(input())
ct=1
sum=1
while X>sum:
  ct+=1
  sum+=ct
print(ct)
Problem p03797 (python)

Fixed submission:
N,M=list(map(int, input().split()))
K=M-2*N
if K>=0:
  print(N+K//4)
else:
  print(min(N, M//2))

Buggy submission (verdict: Runtime Error):
N,M=list(map(int, input().split()))
K=N-2*M
  print(max(N+K//3,N))
Problem p02642 (python)

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

C=[1 for i in range(10**6+1)]
for i in range(N):
    if C[A[i]]==0:  #すでに割り切るものがあるとわかった場合
        continue
    if C[A[i]]==-1:  #同じ数字を2回目に通った時
        C[A[i]]=0
        continue
    C[A[i]]*=-1  #通ったの印
    j=2
    while A[i]*j<=10**6:  #それの倍数はすべてダメ
        C[A[i]*j]=0
        j+=1

print(C.count(-1))

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

C=[1 for i in range(220000)]
for i in range(N):
    if C[A[i]]==0:
        continue
    for j in range(2,220000//A[i]-1):
        C[A[i]*j]=0

ans=0
for i in range(N):
    if i!=N-1 and A[i]==A[i+1]:
        C[A[i]]=0
        continue
    if C[A[i]]==1:
        ans+=1
        C[A[i]]=0

print(ans)
Problem p02684 (python)

Fixed submission:
N,K=map(int,input().split())
A=list(map(int,input().split()))
visited=[0 for i in range(N)]
visited[0]=1
tour=[1]

while True:
    goto=A[tour[-1]-1]
    tour.append(goto)
    if visited[goto-1]:
        break
    visited[goto-1]=1

#print(tour)
    
before=0
shuuki=1
for i in range(len(tour)):
    if tour[i]==tour[-1]:
        before=i
        shuuki=len(tour)-i-1
        break

#print(before,shuuki)

if K<len(tour):
    print(tour[K])
else:
    K-=before
    K%=shuuki
    print(tour[before+K])

Buggy submission (verdict: Runtime Error):
N,K=map(int,input().split())
A=list(map(int,input().split()))
visited=[0 for i in range(N)]
visited[0]=1
tour=[1]

for i in range(1,min(K+1,100)):
    goto=A[tour[-1]-1]
    tour.append(goto)
    if visited[goto-1]:
        break
    visited[goto-1]=1

#print(tour)
    
before=0
shuuki=0
saigo=tour[-1]
for i in range(len(tour)):
    if tour[i]==tour[-1]:
        before=i
        shuuki=len(tour)-i-1
        break

#print(before,shuuki)

if K<=before:
    print(tour[K-1])
else:
    K-=before
    K%=shuuki
    print(tour[before+K])

Buggy submission (verdict: Runtime Error):
N,K=map(int,input().split())
A=list(map(int,input().split()))
visited=[0 for i in range(N)]
visited[0]=1
tour=[1]

for i in range(1,100):
    goto=A[tour[-1]-1]
    tour.append(goto)
    if visited[goto-1]:
        break
    visited[goto-1]=1

#print(tour)
    
before=0
shuuki=0
saigo=tour[-1]
for i in range(len(tour)):
    if tour[i]==tour[-1]:
        before=i
        shuuki=len(tour)-i-1
        break

#print(before,shuuki)

if K<=before:
    print(tour[K-1])
else:
    K-=before
    K%=shuuki
    print(tour[before+K])
Problem p02691 (python)

Fixed submission:
N=int(input())
A=list(map(int,input().split()))
L=[0 for i in range(200010)]
R=[0 for i in range(200010)]
for i in range(N):
    if A[i]+i<200010:
        L[A[i]+i]+=1
    if -A[i]+i>0:
        R[-A[i]+i]+=1
ans=0
for i in range(200010):
    ans+=L[i]*R[i]
print(ans)

Buggy submission (verdict: Runtime Error):
N=int(input())
A=list(map(int,input().split()))
L=[0 for i in range(100010)]
R=[0 for i in range(100010)]
for i in range(N):
    if A[i]+i<100010:
        L[A[i]+i]+=1
    if -A[i]+i>0:
        R[-A[i]+i]+=1
ans=0
for i in range(100010):
    ans+=L[i]*R[i]
print(ans)
Problem p02721 (python)

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

maekara=[]
i=1
cnt=0
while i<=N and cnt<K:
    if S[i-1]=='o':
        maekara.append(i)
        i+=C+1
        cnt+=1
    else: i+=1

usirokara=[]
j=N
cnt=0
while j>=1 and cnt<K:
    if S[j-1]=='o':
        usirokara.append(j)
        j-=C+1
        cnt+=1
    else: j-=1
usirokara=usirokara[::-1]

for i in range(K):
    if maekara[i]==usirokara[i]:
        print(maekara[i])

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

#まず一つ答えをつくる これはたぶん貪欲でいける
days=[]
T=S.copy()
for i in range(N):
    if T[i]=='o':
        days.append(i)
        if C!=0:
            for j in range(1,C+1):
                if i+j>=N:
                    break
                T[i+j]='x'
    if len(days)>=K:
        break

def check(plan):
    cnt=0
    qlan=plan.copy()
    for i in range(N):
        if qlan[i]=='o':
            cnt+=1
            if C!=0:
                for j in range(1,C+1):
                    if i+j>=N:
                        break
                    qlan[i+j]='x'
        if cnt>=K:
            return True  #これなしでも成立する
            break
    return False  #これなしでは成立しない

for i in days:
    p=S
    p[i]='x'
    if not check(p):
        print(i+1)
    p[i]='o'
Problem p02730 (python)

Fixed submission:
S=list(input())
SV=S[::-1]
N=len(S)

for i in range(N):
    F=1
    if S[i]!=SV[i]:
        F=0
        break

s=S[:N//2]
sv=s[::-1]
n=len(s)
#print(s)
for i in range(n):
    FF=1
#    print(s[i],s[-(i+1)])
    if s[i]!=sv[i]:
        FF=0
        break

if F and FF:
    print('Yes')
else:
    print('No')

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

for i in range(len(S)//2):
    F=1
#    print(S[i],S[-(i+1)])
    if S[i]!=S[-(i+1)]:
        F=0
        break

N=len(S)
s=S[:N//2]
#print(s)
for i in range(N//2//2):
    FF=1
#    print(s[i],s[-(i+1)])
    if s[i]!=s[-(i+1)]:
        FF=0
        break

if F and FF:
    print('Yes')
else:
    print('No')
Problem p02756 (python)

Fixed submission:
S=input()
QN=int(input())
front=''
rear=''
rev=False

for i in range(QN):
    op=input()
    if op[0]=='1':
        rev=not(rev)
    else:
        if op[2]=='1':
            if rev:
                rear+=op[4]
            else:
                front+=op[4]
        else:
            if rev:
                front+=op[4]
            else:
                rear+=op[4]

if rev:
    print(rear[::-1]+S[::-1]+front)
else:
    print(front[::-1]+S+rear)

Buggy submission (verdict: Runtime Error):
S=input()
QN=int(input())
front=''
rear=''
rev=False

for i in range(QN):
    op=input()
    if op[0]=='1':
        rev=not(rev)
    else:
        if op[2]=='1':
            if rev:
                rear+=[4]
            else:
                front+=op[4]
        else:
            if rev:
                front+=op[4]
            else:
                rear+=op[4]

if rev:
    print(rear[::-1]+S+front)
else:
    print(front[::-1]+S+rear)
Problem p02900 (python)

Fixed submission:
import collections

def gcd(a,b):
    while b!=0:
        a,b = b,a%b
    return a

def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a

A,B=map(int, input().split())
N=gcd(A,B)
c = collections.Counter(prime_factorize(N))
print(len(list(c.keys()))+1)

Buggy submission (verdict: Runtime Error):
import math
import numpy as np

A,B=map(int, input().split())

def gcd(a,b):
    while b!=0:
        a,b = b,a%b
    return a

def seachPrimeNum(N):
    max = int(np.sqrt(N))
    seachList = [i for i in range(2,N+1)]
    primeNum = []
    while seachList[0] <= max:
        primeNum.append(seachList[0])
        tmp = seachList[0]
        seachList = [i for i in seachList if i % tmp != 0]
    primeNum.extend(seachList)
    primeNum.append(1)
    return primeNum

def yakusuu(A):
    Y=[]
    for i in range(1,math.floor(math.sqrt(A+1))+1):
        if A%i==0:
            Y.append(i)
            Y.append(A//i)
    return(Y)

def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])

    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])

    return arr[-1][0]

N=gcd(A,B)

if N==1:
    print(1)
else:
    ms = factorization(N)
    pl = seachPrimeNum(ms)
    ya = yakusuu(N)
    count=0
#    print(N,ms,pl,ya)
    for i in range(len(pl)):
        if pl[i] in ya:
            count+=1
    print(count)
Problem p02983 (python)

Fixed submission:
l,r = map(int,input().split())
L = l%2019
R = r%2019  #2019 = 3*673
N = r-l+1

if N >= 2019 or L>R:
    print(0)
else:
    ans = l*(l+1)%2019
    for i in range(L,R):  #この時点でL<Rは決定済み
        for j in range(i+1,R+1):
            ans = min(ans,(j*i)%2019)
        if ans == 0:
            break
    print(ans)

Buggy submission (verdict: Runtime Error):
l,r = map(int,input().split())
L = l%2019
R = r%2019  #2019 = 3*673
N = r-l+1

if N >= 2019 or L>R:
    print(0)
else:
    ans = l*(l+1)%2019
    for i in range(L,R):  #この時点でL<Rは決定済み
        for j in range(i+1,R+1):
            ans = min(ans,(j*i)%2019)
        if ans == 0:
            break

print(ans)

Buggy submission (verdict: Runtime Error):
l,r = map(int,input().split())
L = l%2019
R = r%2019  #2019 = 3*673
N = r-l+1

if N >= 2019 or L>R:
    print(0)
else:
    ans = l*(l+1)%2019
    for i in range(L,R):  #この時点でL<Rは決定済み
        for j in range(i+1,R+1):
            if (i*j)%2019 < ans:
                ans = (i*j)%2019
                if ans == 0:
                    break
        if ans == 0:
            break

print(ans)

Buggy submission (verdict: Runtime Error):
l,r = map(int,input().split())
L = l%2019
R = r%2019  #2019 = 3*673
N = r-l+1

if N >= 2019 or L>R:
    print(0)
else:
    ans = l*(l+1)%2019
    for i in range(L,R):  #この時点でL<Rは決定済み
        for j in range(i+1,R+1):
            if (i*j)%2019 < ans:
                ans = (i*j)%2019
                if ans == 0:
                    break

print(ans)
Problem p02995 (python)

Fixed submission:
A,B,C,D=map(int, input().split())

def andiv(M,N):
    return((N//M) * (M-1) + N%M)

def gcd(a,b):
    while b!=0:
        a,b = b,a%b
    return a

def lcm(a,b):
    return(a*b // gcd(a,b))

E = andiv(C,B) + andiv(D,B) - andiv(lcm(C,D),B)
F = andiv(C,A-1) + andiv(D,A-1) - andiv(lcm(C,D),A-1)

print(int(E-F))

Buggy submission (verdict: Runtime Error):
import math

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

def andiv(M,N):
    return((N//M) * (M-1) + N%M)

def lcm(a,b):
    return(a*b // math.gcd(a,b))

E = andiv(C,B) + andiv(D,B) - andiv(lcm(C,D),B)
F = andiv(C,A-1) + andiv(D,A-1) - andiv(lcm(C,D),A-1)

print(int(E-F))

Buggy submission (verdict: Runtime Error):
import math

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

def andiv(M,N):  #N以下でMで割り切れないものの数
    return((N//M) * (M-1) + N%M)

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

E = andiv(C,B) + andiv(D,B) - andiv(lcm(C,D),B)
F = andiv(C,A-1) + andiv(D,A-1) - andiv(lcm(C,D),A-1)

print(E-F)

Buggy submission (verdict: Runtime Error):
import math

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

def andiv(M,N):
    return((N//M)*(M-1)+N%M)

def lcm(a,b):
    return(int((a*b / math.gcd(a,b))))

E = andiv(C,B) + andiv(D,B) - andiv(lcm(C,D),B)
F = andiv(C,A-1) + andiv(D,A-1) - andiv(lcm(C,D),A-1)

print(E-F)

Buggy submission (verdict: Runtime Error):
import math

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

def andiv(M,N): #N以下でMで割り切れないものの数
    return((N//M)*(M-1)+N%M)

def lcm(a,b): #最小公倍数
    return(int((a*b / math.gcd(a,b))))

E = andiv(C,B) + andiv(D,B) - andiv(lcm(C,D),B)
F = andiv(C,A-1) + andiv(D,A-1) - andiv(lcm(C,D),A-1)

print(E-F)

Buggy submission (verdict: Runtime Error):
import math

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

def andiv(A,N): #N以下でAで割り切れないものの数
    return((N//A)*(A-1)+N%A)

def lcm(a,b): #最小公倍数
    return(int((a*b / math.gcd(a,b))))

E = andiv(C,B) + andiv(D,B) - andiv(lcm(C,D),B)
F = andiv(C,A-1) + andiv(D,A-1) - andiv(lcm(C,D),A-1)

print(E-F)

Buggy submission (verdict: Runtime Error):
import math

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

def andiv(A,N): #N以下でAで割り切れないものの数
    return((N//A)*(A-1)+N%A)

def lcm(a,b): #最小公倍数
    return(int((a*b / math.gcd(a,b))))

E = andiv(C,B) + andiv(D,B) - andiv(lcm(C,D),B)
F = andiv(C,A-1) + andiv(D,A-1) - andiv(lcm(C,D),A-1)

print(E-F)

Buggy submission (verdict: Runtime Error):
import math

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

def andiv(A,N): #N以下でAで割り切れないものの数
    return((N//A)*(A-1)+N%A)

def lcm(a,b): #最小公倍数
    return(int((a*b / math.gcd(a,b))))

E = andiv(C,B) + andiv(D,B) - andiv(lcm(C,D),B)
F = andiv(C,A-1) + andiv(D,A-1) - andiv(lcm(C,D),A-1)

print(E-F)
Problem p03032 (python)

Fixed submission:
import heapq
N,K=map(int,input().split())
V=list(map(int,input().split()))

#a:左からとる b:右からとる K-a-b:捨てる
score=0
torikata=[]
for d in range(101):
    for a in range(101):
        for b in range(101):
            if d+a+b<=K and a+b<=N:
                torikata.append((a,b,d))

for i in range(len(torikata)):
    A,B,D=torikata[i][0],torikata[i][1],torikata[i][2]
    H=[]
    for i in range(A):
        H.append(V[i])
    for i in range(B):
        H.append(V[-(i+1)])
    heapq.heapify(H)
    for i in range(min(D,A+B)):
        heapq.heappop(H)
    score=max(score,sum(H))

print(score)

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

#a:左からとる b:右からとる K-a-b:捨てる
score=0
torikata=[]
for d in range(101):
    for a in range(101):
        for b in range(101):
            if d+a+b<=K:
                torikata.append((a,b,d))

for i in range(len(torikata)):
    A,B,D=torikata[i][0],torikata[i][1],torikata[i][2]
    H=[]
    for i in range(A):
        H.append(V[i])
    for i in range(B):
        H.append(V[-(i+1)])
    heapq.heapify(H)
    for i in range(min(D,A+B)):
        heapq.heappop(H)
    score=max(score,sum(H))

print(score)
Problem p03074 (python)

Fixed submission:
def ranlength(A):
    num = list(A)
    count = 1
    result = ''
    table = []
    for i in range(len(num)):
        try:
            if num[i] == num[i+1]:
               count = count + 1
            else:
                result += str(num[i]) + str(count)
                table.append(count)
                count = 1
        except:
            result += str(num[i]) + str(count)
            table.append(count)
    return(table)
    
N,K=map(int,input().split())
S=input()

RL=ranlength(S)
if S[0]=='0':
    RL=[0]+RL
if S[-1]=='0':
    RL.append(0)

#しゃくとり法
cnt=RL[0]
ans=RL[0]
for i in range(len(RL)):
    if i%2==0 and i>=2:
        cnt+=RL[i]
        cnt+=RL[i-1]
        if i>=K*2+2:
            cnt-=RL[i-(K*2+1)]
            cnt-=RL[i-(K*2+2)]
        ans=max(ans,cnt)
        #print(cnt)
print(ans)

Buggy submission (verdict: Runtime Error):
def ranlength(A):
    num = list(A)
    count = 1
    result = ''
    table = []
    for i in range(len(num)):
        try:
            if num[i] == num[i+1]:
               count = count + 1
            else:
                result += str(num[i]) + str(count)
                table.append(count)
                count = 1
        except:
            result += str(num[i]) + str(count)
            table.append(count)
    return(table)
    
N,K=map(int,input().split())
S=input()

RL=ranlength(S)
#print(RL)

#しゃくとり法
if int(S[0])==1:
    cnt1=RL[0]
    ans1=RL[0]
    for i in range(len(RL)):
        if i%2==0 and i>=2:
            cnt1+=RL[i]
            cnt1+=RL[i-1]
            if i>=K*2+2:
                cnt1-=RL[i-(K*2+1)]
                cnt1-=RL[i-(K*2+2)]
            ans1=max(ans1,cnt1)
            #print(cnt1)
    print(ans1)
elif int(S[0])==0:
    cnt2=RL[0]+RL[1]
    ans2=RL[0]+RL[1]
    for i in range(len(RL)):
        if i%2==1 and i>=3:
            cnt2+=RL[i]
            cnt2+=RL[i-1]
            if i>=K*2+1:
                cnt2-=RL[i-(K*2+1)]
                cnt2-=RL[i-(K*2)]
            ans2=max(ans2,cnt2)
            #print(cnt2)
    print(ans2)