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

Fixed submission:
import bisect

N=int(input())
S=list(input())
Q=int(input())

alphabet="abcdefghijklmnopqrstuvwxyz"
bag={l:[] for l in alphabet}
for i in range(N):
    bag[S[i]].append(i+1)
#print(bag)

for i in range(Q):
    Type,a,b=input().split()
    if Type=='1':
        a=int(a)
        if S[a-1]!=b:
            bag[S[a-1]].remove(a)
            S[a-1]=b
            bisect.insort(bag[b],a)
    else:
        cnt=0
        a,b=int(a),int(b)
        for l in alphabet:
            bl=len(bag[l])
            if bl>0:
                left=bisect.bisect_left(bag[l],a)
                if left!=bl and bag[l][left]<=b:
                        cnt+=1
        print(cnt)

Buggy submission (verdict: Runtime Error):
import bisect

N=int(input())
S=list(input())
Q=int(input())

alphabet="abcdefghijklmnopqrstuvwxyz"
bag={l:[] for l in alphabet}
for i in range(N):
    bag[S[i]].append(i+1)
#print(bag)

for i in range(Q):
    Type,a,b=input().split()
    if Type=='1':
        if S[a-1]!=b:
            a=int(a)
            bag[S[a-1]].remove(a)
            S[a-1]=b
            bisect.insort(bag[b],a)
    else:
        cnt=0
        a,b=int(a),int(b)
        for l in alphabet:
            bl=len(bag[l])
            if bl>0:
                left=bisect.bisect_left(bag[l],a)
                if left!=bl and bag[l][left]<=b:
                        cnt+=1
        print(cnt)

Buggy submission (verdict: Runtime Error):
import bisect

N=int(input())
S=list(input())
Q=int(input())
L=[[] for i in range(150)]

for i in range(N):
    L[ord(S[i])].append(i)

#print(L)

for i in range(Q):
    
    Type,q1,q2=map(str,input().split())
    if Type=='1':
        q1=int(q1)-1
        L[ord(S[q1])].remove(q1)
        L[ord(q2)].append(q1)
        L[ord(q2)]=sorted(L[ord(q2)])
    else:
        q1,q2=int(q1)-1,int(q2)-1
        cnt=0
        for j in range(97,123):
            if len(L[j])!=0:
                L[j]=sorted(L[j])
                n=bisect.bisect_left(L[j],q1)
                #print(j,n)
                if n<len(L[j]) and L[j][n]<=q2:
                    cnt+=1
                    #print(str(j),'<')
        print(cnt)
Problem p02831 (python)

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

def lcm(a,b):
    return(int((a*b / gcd(a,b))))
    
A,B=map(int,input().split())
print(lcm(A,B))

Buggy submission (verdict: Runtime Error):
import math
def lcm(x, y):
    return (x * y) // math.gcd(x, y)
A,B=map(int,input().split())
print(lcm(A,B))
Problem p02862 (python)

Fixed submission:
import sys

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

def nCmMOD(A,B,Mod):
    num,den=1,1
    for i in range(B):
        num*=(A-i)
        den*=(i+1)
        num%=Mod
        den%=Mod
    return (num*pow(den,Mod-2,Mod))%Mod

if T%3!=0 or y/x<1/2 or y/x>2:
    print(0)
    sys.exit()
else:
    n=(2*y-x)//3
    m=(2*x-y)//3
    l=min(n,m)
    print(nCmMOD(n+m,l,MOD))

Buggy submission (verdict: Runtime Error):
x,y=map(int,input().split())
T=x+y
W=x-T//3
D=10**9
#print(T//3)

import sys
if T%3!=0 or y/x<1/2 or y/x>2:
    print(0)
    sys.exit()

if x==y==999999:
    print(151840682)
    sys.exit()

from functools import lru_cache
@lru_cache(maxsize=1000000)
def c(n,k): 
  return 1 if(k<=0 or n<=k) else (c(n-1, k-1) + c(n-1, k))%D

sys.setrecursionlimit(1000000)
print(c(T//3,W))

Buggy submission (verdict: Runtime Error):
x,y=map(int,input().split())
T=x+y
W=x-T//3
D=10**9
#print(T//3)

import sys
if T%3!=0 or y/x<1/2 or y/x>2:
    print(0)
    sys.exit()

if x==y==999999:
    print(151840682)
    sys.exit()

from functools import lru_cache
@lru_cache(maxsize=1000000)
def c(n,k): 
  return 1 if(k<=0 or n<=k) else (c(n-1, k-1) + c(n-1, k))%D

sys.setrecursionlimit(10000)
print(c(T//3,W))

Buggy submission (verdict: Runtime Error):
x,y=map(int,input().split())
T=x+y
W=x-T//3
D=10**9
print(T//3)

import sys
if T%3!=0 or y/x<1/2 or y/x>2:
    print(0)
    sys.exit()

if x==y==999999:
    print(151840682)
    sys.exit()

from functools import lru_cache
@lru_cache(maxsize=1000000)
def c(n,k): 
  return 1 if(k<=0 or n<=k) else (c(n-1, k-1) + c(n-1, k))%D

sys.setrecursionlimit(10000)
print(c(T//3,W))
Problem p02897 (python)

Fixed submission:
N=int(input())
k=0
for i in range(N+1):
    if i%2==1:
        k+=1
print(k/N)

Buggy submission (verdict: Runtime Error):
import math

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

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

def primelist(n):
    P = [2]
    flag = 0
    for i in range(3,n+1,2):
        for j in range(len(P)):
            if math.sqrt(i) < P[j]:
                break
            else:
                if i%P[j] == 0:
                    flag += 1
                    break
        if flag == 0:
            P.append(i)
        flag = 0
    P.append(1)
    return(P)

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 = primelist(ms)
    ans=0
    for i in range(len(pl)):
        if N%pl[i]==0:
            ans+=1
    print(ans)
Problem p02912 (python)

Fixed submission:
import heapq
N, M = [int(_) for _ in input().split()]
A = [-int(_) for _ in input().split()]

heapq.heapify(A)

for _ in range(M):
    a = heapq.heappop(A)
    heapq.heappush(A, -(-a//2))

print(-sum(A))

Buggy submission (verdict: Runtime Error):
import heapq
N, M = [int(_) for _ in input().split()]
A = [-int(_) for _ in input().split()]

heapq.heapify(A)

for _ in range(M):
    a = heapq.heappop(A)
    heapq.heappush(A, -(-a//2))
    print(A)
    if sum(A) == 0:
        break
    
print(-sum(A))
Problem p02948 (python)

Fixed submission:
import heapq

N,M=map(int,input().split())
AB=[list(map(int,input().split())) for i in range(N)]
L=[[] for i in range(M+1)]

for i in range(N):
    if AB[i][0]<=M:
        L[AB[i][0]].append(-AB[i][1])

LL=[]
money=0

for i in range(1,M+1):
    for j in L[i]:
        heapq.heappush(LL,j)
    if len(LL)==0:
        continue
    money+=heapq.heappop(LL)

print(-money)

Buggy submission (verdict: Runtime Error):
import heapq

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

L=[]
for i in range(M+1):
    L.append([])

for i in range(N):
    if AB[i][0]<=M:
        L[AB[i][0]].append(AB[i][1])

for i in range(N):
    if len(L[i])!=0:
        L[i].sort(reverse=True)
        break

LL=[]
money=0

for i in range(1,M+1):
    LL+=[-k for k in L[i]]
    if len(LL)==0:
        continue
    money+=heapq.heappop(LL)

print(-money)
Problem p03075 (python)

Fixed submission:
ABCDE = []
for i in range(5):
    ABCDE.append(int(input()))
K = int(input())

out = 0
for i in range(5):
    for j in range(i+1,5):
        if ABCDE[j] - ABCDE[i] > K:
            out += 1
            break

if out == 0:
    print('Yay!')
else:
    print(':(')

Buggy submission (verdict: Runtime Error):
ABCDE = []
for i in range(5):
    ABCDE.append(int(input()))
K = int(input())

out = 0
for i in range(5):
    for j in range(i+1,5):
        if ABCDE[j] - ABCDE[i] > K:
            out += 1
            break

print(['Yay!',':('][out])
Problem p03127 (python)

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

def gcd_list(L):
    b=min(L)
    for i in L:
        while True:
            if i%b==0:
                break
            c=b
            b=i%b
            i=c
    return(b)

print(gcd_list(A))

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

import math
from functools import reduce
def gcd_list(numbers):
    return reduce(math.gcd, numbers)

print(gcd_list(A))
Problem p02624 (python)

Fixed submission:
n=int(input())

yakusu=[0]*(n+1)

for i in range(1,n+1):
    for j in range(1,n+1):
        if i*j<=n:
            yakusu[i*j]+=1
        else:
            break

ans=0
for i,v in enumerate(yakusu):
    ans+=i*v

print(ans)

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

import sympy

ans=0
for i in range(1,n+1):
    ans+=i*sympy.divisors(i)


print(ans)
Problem p02793 (python)

Fixed submission:
def main():
    from fractions import gcd
    import sys
    n=int(input())
    a = tuple(map(int, input().split()))
    ans = 1

    mmm=10**9+7
    for i in a:
        ans = ans *i // gcd(ans, i)

    result=0
    for item in a:
      result+=ans//item

    print(result%mmm)

if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
import sys

input = sys.stdin.readline
import fractions



def main():
    N=int(input())
    A = [int(x) for x in input().split()]
    MOD=10**9+7
    
    x = 1
    for a in A:
        x = (a *x )// fractions.gcd(a, x)

    ans=0
    for a in A:
      ans+=x//a

    print(ans%mod)

if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
def main():
    import fractions
    import sys
    input = sys.stdin.readline
    n=int(input())
    a = tuple(map(int, input().split()))
    ans = a[0]

    mmm=10**9+7
    for i in a[1:]:
        ans = 8ans *i )// fractions.gcd(ans, i)

    result=0
    for item in a:
      result+=ans//item

    print(result%mmm)

if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
def main():
    from fractions import gcd
    import sys
    n=int(input())
    a = tuple(map(int, input().split()))
    ans = a[0]

    #mmm=10**9+7
    for i in a[1:]:
        ans = ans *i // gcd(ans, i)

    result=0
    for item in a:
      resul+=ans//item

    print(result%(10**9+7))

if __name__ == '__main__':
    main()
Problem p02847 (python)

Fixed submission:
s=input()

days=["SUN","MON","TUE","WED","THU","FRI","SAT"]

print(7-days.index(s))

Buggy submission (verdict: Runtime Error):
#xが所持金
#a * n + b *nの桁数
a,b,x =map(int,input().split())

if a+b>x:
  print(0)
  exit()

if a*(10**9)+b*10<=x:
  print(10**9)
  exit()
  
  
for i in range(10):
  if (a*(10**i)+b*len(str(10**i))<=x and a*(10**(i+1))+b*len(str(10**(1+i))) >x) or i==9:
    kagen=10**i
    jougen=min(10**9,10**(i+1))
    
    atai=kagen+jougen//2
    
    while 1:
      #print(kagen,atai,jougen)
      if a*atai+b*len(str(atai))<=x and a*(atai+1)+b*len(str((1+atai))) >x:
        print(atai)
        exit()
      if a*atai+b*len(str(atai))<=x:
        kagen=atai
        atai=(atai+jougen)//2
      else:
        jougen=atai
        atai=(kagen+atai)//2
Problem p02862 (python)

Fixed submission:
import sys
sys.setrecursionlimit(2147483647)
INF=float('inf')
MOD=10**9+7
input=sys.stdin.readline

x,y=map(int,input().split())



if (x+y)%3!=0:
    print(0)
    exit()

if x==0 and y==0:
    print(0)
    exit()


n=(2*y-x)//3
m=(2*x-y)//3


if m<0 or n<0:
    print(0)
    exit()

if n==0 and m==1:
    print(1)
    exit()
if n==1 and m==0:
    print(1)
    exit()
    

#n+mCm
#(n+m)!/m!


def cmb(n, r, p):
    if (r < 0) or (n < r):
        return 0
    r = min(r, n - r)
    return fact[n] * factinv[r] * factinv[n-r] % p

p = 10 ** 9 + 7
N = 10 ** 6  # N は必要分だけ用意する
fact = [1, 1]  # fact[n] = (n! mod p)
factinv = [1, 1]  # factinv[n] = ((n!)^(-1) mod p)
inv = [0, 1]  # factinv 計算用

for i in range(2, N + 1):
    fact.append((fact[-1] * i) % p)
    inv.append((-inv[p % i] * (p // i)) % p)
    factinv.append((factinv[-1] * inv[-1]) % p)



print(cmb(n+m, m, 10**9+7))

Buggy submission (verdict: Runtime Error):
x,y=map(int,input().split())



if (x+y)%3!=0:
    print(0)
    exit()

if x==0 and y==0:
    print(0)
    exit()


n=(2*y-x)/3
m=(2*x-y)/3



if m<0 or n<0:
    print(0)
    exit()

if n==0 and m==1:
    print(1)
    exit()
if n==1 and m==0:
    print(1)
    exit()
    

#n+mCm
#(n+m)!/m!


def cmb(n, r, p):
    if (r < 0) or (n < r):
        return 0
    r = min(r, n - r)
    return fact[n] * factinv[r] * factinv[n-r] % p

p = 10 ** 9 + 7
N = 10 ** 6  # N は必要分だけ用意する
fact = [1, 1]  # fact[n] = (n! mod p)
factinv = [1, 1]  # factinv[n] = ((n!)^(-1) mod p)
inv = [0, 1]  # factinv 計算用
 
for i in range(2, N + 1):
    fact.append((fact[-1] * i) % p)
    inv.append((-inv[p % i] * (p // i)) % p)
    factinv.append((factinv[-1] * inv[-1]) % p)

#print(n+m,m)

print(cmb(n+m, m, 10**9+7))

Buggy submission (verdict: Runtime Error):
x,y=map(int,input().split())




mod=10**9+7

if (2*x-y)%3==0 and (2*y-x)%3==0:
  a=(2*x-y)/3
  b=(2*y-x)/3
  #print(a,b)

  result=0.0
  bunbo=1
  bunshi=1
  for i in range(int(a)):
    bunbo=bunbo*(a+b-i)
    bunshi=bunshi*(1+i)
    #print(bunbo,bunshi)
  result=bunbo/bunshi%mod
  print(int(result))
  

  
else:
  print(0)
Problem p02897 (python)

Fixed submission:
n=int(input())

if n%2==0:
  print(0.5)
else:
  print((n//2+1)/n)

Buggy submission (verdict: Runtime Error):
n,k=map(int,input().split())


cnt=0
for item in list(map(int,input().split())):
  if item>=k:cnt+=1
print(cnt)
Problem p02987 (python)

Fixed submission:
s=list(input())

for ss in s:
  if s.count(ss)!=2:
    print("No")
    exit()
    
print("Yes")

Buggy submission (verdict: Runtime Error):
s=list(int(input()))

for ss in s:
  if s.count(ss)!=2:
    print("No")
	exit()
    
print("Yes")
Problem p03045 (python)

Fixed submission:
import sys
sys.setrecursionlimit(1000000)

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

#初期値が0の辞書
from collections import defaultdict
xyz = defaultdict(lambda: set([]))
for _ in range(m):
    x,y,z=map(int,input().split())
    xyz[x].add(y)
    xyz[y].add(x)

no_checked=[0]*n

def DFS(x):
    global no_checked
    global xyz
    no_checked[x-1]=1
    for item in xyz[x]:
        if no_checked[item-1]==0:
            DFS(item)

cnt=0
for i in range(1,n+1):
    if no_checked[i-1]==0:
        cnt+=1
        DFS(i)

    #print(i,no_checked)
print(cnt)

Buggy submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(100000)

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

#初期値が0の辞書
from collections import defaultdict
xyz = defaultdict(lambda: set([]))
for _ in range(m):
    x,y,z=map(int,input().split())
    xyz[x].add(y)
    xyz[y].add(x)

no_checked=[0]*n

def DFS(x):
    global no_checked
    global xyz
    no_checked[x-1]=1
    for item in xyz[x]:
        if no_checked[item-1]==0:
            DFS(item)

cnt=0
for i in range(1,n+1):
    if no_checked[i-1]==0:
        cnt+=1
        DFS(i)

    #print(i,no_checked)
print(cnt)

Buggy submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(10000)

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

#初期値が0の辞書
from collections import defaultdict
xyz = defaultdict(lambda: set([]))
for _ in range(m):
    x,y,z=map(int,input().split())
    xyz[x].add(y)
    xyz[y].add(x)

no_checked=[0]*n

def DFS(x):
    global no_checked
    global xyz
    no_checked[x-1]=1
    for item in xyz[x]:
        if no_checked[item-1]==0:
            DFS(item)

cnt=0
for i in range(1,n+1):
    if no_checked[i-1]==0:
        cnt+=1
        DFS(i)

    #print(i,no_checked)
print(cnt)

Buggy submission (verdict: Runtime Error):
n,m=map(int,input().split())

#初期値が0の辞書
from collections import defaultdict
xyz = defaultdict(lambda: set([]))
for _ in range(m):
    x,y,z=map(int,input().split())
    xyz[x].add(y)
    xyz[y].add(x)

no_checked=[0]*n

def DFS(x):
    global no_checked
    global xyz
    no_checked[x-1]=1
    for item in xyz[x]:
        if no_checked[item-1]==0:
            DFS(item)

cnt=0
for i in range(1,n+1):
    if no_checked[i-1]==0:
        cnt+=1
        DFS(i)

    #print(i,no_checked)
print(cnt)
Problem p03208 (python)

Fixed submission:
n,k=map(int,input().split())
 
 
h=list(int(input()) for _ in range(n))
h.sort()
result=10**9
 
i=0
while i+k-1<n:
  result=min(result,h[i+k-1]-h[i])
  
  i+=1
  
print(result)

Buggy submission (verdict: Runtime Error):
n,k=map(int,input().split())


h=list(int(input()) for in range(n))
h.sort()
result=10**9

i=0
while i+k-1<n:
  result=min(result,h[i+k-1]-h[i])
  
  i+=1
  
print(result)
Problem p03295 (python)

Fixed submission:
n,m=map(int,input().split())

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

ab.sort()

ll=ab[0][0]
rr=ab[0][1]

cnt=1
#print(ab[0],ll,rr,cnt)
for item in ab[1:]:
    l=item[0]
    r=item[1]
    if l>=rr:
        cnt+=1
        ll=l
        rr=r
    else:
        if r<rr:
            rr=r
        if ll<l:
            ll=l
    #print(item,ll,rr,cnt)

print(cnt)

Buggy submission (verdict: Runtime Error):
n,m=map(int,input().split())

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

ab.sort((key=lambda x: x[1]))

cnt=0
border=0

for item in ab:
    if item[0]>=border:
        border=item[1]
        cnt+=1

print(cnt)
Problem p03326 (python)

Fixed submission:
n,m=map(int,input().split())

xyz=[tuple(map(int, input().split())) for _ in range(n)]
kk=[]
for i in [1,-1]:
    for j in [1,-1]:
        for k in [1,-1]:
            kk.append((i,j,k))

ans=[[] for _ in range(8)]

for (x,y,z) in xyz:
    for i,k in enumerate(kk):
        ans[i].append(x*k[0]+y*k[1]+z*k[2])

result=0

for i in range(8):
    ans[i].sort(reverse=True)
    #print(sum(ans[i][:m]))
    result=max(result,sum(ans[i][:m]))

print(result)

Buggy submission (verdict: Runtime Error):
n,m=map(int,input().split())


xyz=[tuple(map(int, input().split())) for _ in range(n)]

#m個食べる
#abs(sum(x))+abs(sum(y))+abs(sum(z))の最大化

#i個中m個食べた時の、最小のxyz
#dp[i][m][0]=(x,y,z)
#i個中m個食べた時の、最大のxyz
#dp[i][m][1]=(x,y,z)

dp=[[[(0,0,0)]*8 for _ in range(m+1)] for _ in range(n)]

for k in range(8):
    dp[0][1][k]=xyz[0]
    dp[0][1][k]=xyz[0]

#- + +
#- - +
#- - - 
#+ + +
#+ - +
#+ - -
#+ + -
#- + -  で最強を目指せば良い

kk=[]
for i in [1,-1]:
    for j in [1,-1]:
        for k in [1,-1]:
            kk.append((i,j,k))

for i in range(1,n):
    for j in range(1,m+1):
        for k in range(8):
            bk=0
            now=0
            for ind in range(3):
                #print(i,j,k,ind,dp)
                #print(kk)
                #print(i,j,k,ind)
                #print(dp[i-1][j][k])
                #print(dp[i-1][j][k][ind])
                #print("kk",kk[k][ind])
                bk+=dp[i-1][j][k][ind]*kk[k][ind]
                now+=dp[i-1][j-1][k][ind]*kk[k][ind]+xyz[i][ind]*kk[k][ind]
            if abs(bk)>abs(now):
                dp[i][j][k]=dp[i-1][j][k]
            else:
                x=dp[i-1][j-1][k][0]*kk[k][ind]+xyz[i][0]*kk[k][0]
                y=dp[i-1][j-1][k][1]*kk[k][ind]+xyz[i][1]*kk[k][1]
                z=dp[i-1][j-1][k][2]*kk[k][ind]+xyz[i][2]*kk[k][2]
                dp[i][j][k]=(x,y,z)

        """
        #最小値
        x=min(dp[i-1][j-1][0][0]+xyz[j][0],dp[i-1][j][0][0])
        y=min(dp[i-1][j-1][0][1]+xyz[j][1],dp[i-1][j][0][1])
        z=min(dp[i-1][j-1][0][2]+xyz[j][2],dp[i-1][j][0][2])
        dp[i][j][0]=(x,y,z)
        #最大値
        x=max(dp[i-1][j-1][1][0]+xyz[j][0],dp[i-1][j][1][0])
        y=max(dp[i-1][j-1][1][1]+xyz[j][1],dp[i-1][j][1][1])
        z=max(dp[i-1][j-1][1][2]+xyz[j][2],dp[i-1][j][1][2])
        dp[i][j][1]=(x,y,z)
        """

ans=0
for item in dp[-1][-1]:
    #print(item)
    ans=max(ans,abs(item[0])+abs(item[1])+abs(item[2]))

print(ans)
Problem p03329 (python)

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


n=int(input())

#dpで解く再帰

memo=[-1]*(n+1)
memo[0]=0

def fuck(x):
    #print(x)
    if memo[x]!=-1:
        return memo[x]
    else:
        tmp=10**9
        #6
        i=1
        while 6**i<=x:
            tmp=min(fuck(x-6**i),tmp)
            i+=1
        #9
        i=1
        while 9**i<=x:
            tmp=min(fuck(x-9**i),tmp)
            i+=1
        #1
        tmp=min(tmp,fuck(x-1))
        memo[x]=tmp+1
        #print(x,tmp+1,memo)
        return tmp+1
fuck(n)
#print(memo)
print(memo[-1])

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

#初期化
#コイン1円
dp=[i for i in range(n+1)]

#コイン6円
i=1
while 6**i<=n:
    dp[6**i]=1
    i+=1
#コイン6円
i=1
while 9**i<=n:
    dp[9**i]=1
    i+=1

for i in range(1,n+1):
    for j in range(i):
        dp[i]=min(dp[i],dp[j]+dp[i-j])
    if i%1000==0:
        #print(i)
print(dp[-1])
Problem p03618 (python)

Fixed submission:
a=list(input())

unko=[0]*(ord("z")+1-ord("a"))

for aa in a:
    unko[ord(aa)-ord("a")]+=1
tmp=0
for u in unko:
    tmp+=(u*(u-1))//2

print((len(a)*(len(a)-1))//2-tmp+1)

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

unko=[0]*(ord("z")+1-ord("a"))

for aa in a:
    unko[ord(aa)-ord("a")]+=1
tmp=0
for u in unko:
    tmp+=(u*(u-1))//2

print((n*(n-1))//2-tmp)
Problem p03634 (python)

Fixed submission:
import sys
sys.setrecursionlimit(2147483647)


n=int(input())

c={}
tree=[set([]) for _ in range(n)]

for _ in range(n-1):
    i,j,k=map(int,input().split())
    i-=1
    j-=1
    tree[i].add(j)
    tree[j].add(i)
    c[(min(i,j),max(i,j))]=k

result=[]
q,k=map(int,input().split())

memo=[-1]*n

def DEF(z,cnt):
    global memo,tree,c
    memo[z]=cnt
    for item in tree[z]:
        if memo[item]==-1:
            DEF(item,cnt+c[(min(item,z),max(item,z))])

DEF(k-1,0)
result=[]
for item in range(q):
    a,b=map(int,input().split())
    result.append(memo[a-1]+memo[b-1])

for item in result:
    print(item)

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

c={}
tree=[[] for _ in range(n)]

for _ in range(n-1):
    i,j,k=map(int,input().split())
    i-=1
    j-=1
    tree[i].append(j)
    tree[j].append(i)
    c[(i,j)]=k
    c[(j,i)]=k

result=[]
q,k=map(int,input().split())

#初期値が0の辞書
from collections import defaultdict
memo = defaultdict(lambda: -1) 

def DEF(z,cnt):
    global memo,tree,c
    memo[z]=cnt
    for item in tree[z]:
        if memo[item]==-1:
            DEF(item,cnt+c[(item,z)])

DEF(k-1,0)
result=[]
for item in range(q):
    a,b=map(int,input().split())
    result.append(memo[a-1]+memo[b-1])

for item in result:
    print(item)

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

c={}
tree=[[] for _ in range(n)]

for _ in range(n-1):
    i,j,k=map(int,input().split())
    i-=1
    j-=1
    tree[i].append(j)
    tree[j].append(i)
    c[(i,j)]=k
    c[(j,i)]=k

result=[]
q,k=map(int,input().split())

#初期値が0の辞書
from collections import defaultdict
memo = defaultdict(lambda: -1) 

def DEF(z,cnt):
    global memo,tree,c
    memo[z]=cnt
    for item in tree[z]:
        if memo[item]==-1:
            DEF(item,cnt+c[(item,z)])

DEF(k-1,0)
result=[]
for item in range(q):
    a,b=map(int,input().split())
    result.append(memo[a-1]+memo[b-1])

for item in result:
    print(item)
Problem p04021 (python)

Fixed submission:
n=int(input())

ans=0

a=[]
b=[]

for _ in range(n):
    x=int(input())
    a.append(x)
    b.append(x)
b.sort()

dic={}
for i,v in enumerate(b):
    dic[v]=i%2

cnt=0
for i,v in enumerate(a):
    if i%2 != dic[v]:
        cnt+=1
print(cnt//2)

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

ans=0

a=[]
b=[]

for _ in range():
    x=int(input())
    a.append(x)
    b.append(x)
b.sort()

cnt=0
for i,v in enumerate(a):
    if i%2 != (b.index(v))%2:
        cnt+=1
print(cnt//2)

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

ans=0

a=[int(input()) for _ in range(n)]

b=a.sorted()

cnt=0
for i,v in enumerate(a):
    if i%2 != (b.index(b))%2:
        cnt+=1
print(cnt//2)
Problem p02766 (python)

Fixed submission:
n,k = map(int,input().split())
cnt = 0
while n >= 1:
    n /= k
    cnt += 1
print(cnt)

Buggy submission (verdict: Runtime Error):
n,r = map(int,input().split())
cnt = 0
while n >= 1:
    n /= k
    cnt += 1
print(cnt)
Problem p02773 (python)

Fixed submission:
n = int(input())
s = [input() for i in range(n)]
from collections import Counter
s1 = Counter(s)
max_s = max(s1.values())
ans = []
for k,v in s1.items(): 
    if v == max_s:
        ans.append(k)
ans.sort()
for a in ans:
    print(a)

Buggy submission (verdict: Runtime Error):
n = int(input())
s = [input() for i in range(n)]
s.sort()
from collections import Counter
s1 = collections.Counter(s)
s2 = list(set(s))
s2.sort()
for i in range(len(s2)):
    if s1[s2[i]] == max(s1.values()):
        print(s2[i])
Problem p02831 (python)

Fixed submission:
import fractions
a,b = map(int,input().split())
c = fractions.gcd(a,b)
print(a*b//c)

Buggy submission (verdict: Runtime Error):
import math
a,b = map(int,input().split())
print(a*b//math.gcd(a,b))

Buggy submission (verdict: Runtime Error):
import math
a,b = map(int,input().split())
print(a*b//math.gcd(a,b))