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

Fixed submission:
str=input()
K=int(input())
s=set()
for scope in range(1,K+1):
    for f in range(len(str)-scope+1):
        s.add(str[f:f+scope])
print(sorted([x for x in s])[K-1])

Buggy submission (verdict: Runtime Error):
s = input()
N = int(input())
l = len(s)
result=[]
for first in range(l):
  for scope in range(1,1+l-first):
    if not s[first:first+scope]:
      result.append(s[first:first+scope])
result.sort()
print(result[N-1])

Buggy submission (verdict: Runtime Error):
s = input()
N = int(input())
l = len(s)
li=list(set(s))
li.sort()
result=[]

if len(li)>5:
    a=5
else:
    a=l-1
for i in range(a):
    indexx=[f for f,x in enumerate(s) if x==s[i]]
    for index in indexx:
        for scope in range(1,l+1):
            if not s[index:index+scope] in result:
                result.append(s[index:index+scope])
                result.sort()


print(result)
print(result[N-1])

Buggy submission (verdict: Runtime Error):
s = input()
N = int(input())
l = len(s)
li=list(set(s))
li.sort()
result=[]
print(li)
if len(li)>5:
    a=5
else:
    a=l-1
for i in range(a):
    index=s.index(li[i])
    for scope in range(1,l+1):
        if not s[index:index+scope] in result:
            result.append(s[index:index+scope])
result.sort()
print(result)
print(result[N-1])

Buggy submission (verdict: Runtime Error):
s = input()
N = int(input())
l = len(s)
li=list(set(s))
li.sort()
result=[]
print(li)
if len(li)>5:
    a=5
else:
    a=l-1
for i in range(a):
    index=s.index(li[i])
    for scope in range(1,l+1):
        if not s[index:index+l-scope+1] in result:
            result.append(s[index:index+l-scope+1])
print(result)
result.sort()
print(result[N-1])

Buggy submission (verdict: Runtime Error):
s=input()
N=int(input())
l=len(s)
for scope in range(1,1+l):
  for first in range(1+l-scope):
    if not s[fist:first+scope] in li:
      li.append(s[first:first+scope])
    if len(li)==N:
      break
li.sort()   
print(li[N-1])

Buggy submission (verdict: Runtime Error):
s=input()
N=int(input())
l=len(s)
li=[]
for scope in range(1,l+1):
  for first in range(l-scope+1):
    if not s[first:first+scope]:
      li.append(s[first:first+scope])
li.sort()
print(li[N-1])

Buggy submission (verdict: Runtime Error):
s=input()
N=int(input())
l=len(s)
for scope in range(1,1+l):
  for first in range(1+l-scope):
    if not s[fist:first+scope] in li:
      li.append(s[first:first+scope])
li.sort()   
print(li[N-1])

Buggy submission (verdict: Runtime Error):
s=input()
N=int(input())
l=len(s)
for scope in range(1,1+l):
  for first in range(1+l-scope):
    if not s[fist:first+scope] in li:
      li.append(s[first:first+scope])
li.sort()   
print(li[N-1])

Buggy submission (verdict: Runtime Error):
s=input()
N=int(input())
l=len(s)
for scope in range(1,1+l):
  for first in range(1+l-scope):
    if not s[fist:first+scope] in li:
      li.append(s[first:first+scope])
li.sort()   
print(li[N])

Buggy submission (verdict: Runtime Error):
s=input()
l=len(s)
N=int(input())
for scope in range(1,1+l):
  for first in range(1+l-scope):
    if not s[fist:first+scope] in li:
      li.append(s[first:first+scope])
print(li[-N])
Problem p03359 (python)

Fixed submission:
a,b=map(int,input().split())
print(a if a<=b else a-1)

Buggy submission (verdict: Runtime Error):
a,b=map(int,input().split)
print(a if a<=b else a-1)

Buggy submission (verdict: Runtime Error):
a,b=map(int,input().split)
print(a-b if b<a else a-b+1)
Problem p02657 (python)

Fixed submission:
A, B = map(int,input().split())
print(A*B)

Buggy submission (verdict: Runtime Error):
import numpy as np
N = int(input())
A = list(map(int,input().split()))
a = np.prod(A)
if a > 10**18:
  print(-1)
else:
  print(a)
Problem p02683 (python)

Fixed submission:
from collections import deque
import itertools

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

li = deque()

sum = -1
ans = 0
for i in range(n):
    li.append(list(map(int, input().split())))

for i in range(1,n+1):
    for v in itertools.combinations(li, i):
        ok = True
        for j in range(1,m+1):
            ans = 0
            for k in v:
                ans += k[j]
                if ans >= x:
                    break
            if ans < x:
                ok = False
                break

        if ok == True:
            s=0
            for j in range(i):
                s+=v[j][0]
            if sum > s or sum == -1:
                sum=s


print(sum)

Buggy submission (verdict: Runtime Error):
3 3 10
60 2 2 4
70 8 7 9
50 2 3 9
Problem p02801 (python)

Fixed submission:
list = ['a','b','c','d','e','f','g','h','i','j','k','m','n','o','p','q','r','s','t','u','v','w','x','y','z']

C = str(input())

print(list[(list.index(C)+1)%len(list)])

Buggy submission (verdict: Runtime Error):
list = [a,b,c,d,e,f,g,h,i,j,k,m,n,o,p,q,r,s,t,u,v,w,x,y,z]

C = str(input())

print(list[(list.index(C)+1)%len(list)])
Problem p02576 (python)

Fixed submission:
n, x, t = map(int, input().split())
a = n // x
if n % x == 0:
  print(a * t)
else:
  print((a + 1) * t)

Buggy submission (verdict: Runtime Error):
n, x, t = map(int, input().split())
a = n/x
if n % x == 0:
  print(a*t)
else:
  print((a + 1)*t

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

print((n//=x + 1) * t )
Problem p02582 (python)

Fixed submission:
a = input()
if a =='SSS':
  print(0)
elif a=='RRR':
  print(3)
elif a == 'RRS' or a== 'SRR':
  print(2)
else:
  print(1)

Buggy submission (verdict: Runtime Error):
a = input()
total = 0
for i in a[range(1,4)]:
  if i = 'R':
    total +=1
  else:
    total = 0

Buggy submission (verdict: Runtime Error):
a = input()
total = 0
for i in a[range(1,4)]:
  if i = R:
    total +=1
  else:
    total = 0
Problem p02741 (python)

Fixed submission:
a = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]
print(a[int(input())-1])

Buggy submission (verdict: Runtime Error):
a = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]
print a[int(input())-1]

Buggy submission (verdict: Runtime Error):
a = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]
print a[int(input)-1]
Problem p02786 (python)

Fixed submission:
import math

h = int(input())
atk = 0
for i in range(int(math.log2(h)) + 1):
    atk += 2 ** i

print(atk)

Buggy submission (verdict: Runtime Error):
2**log2(int(input().split()[0]))-1

Buggy submission (verdict: Runtime Error):
print(2**log2(int(input()))-1)
Problem p03471 (python)

Fixed submission:
osatsu, okane = map(int, input().split())

#1万円の枚数 : x
#5千円の枚数 : y
#千円の枚数  : z

x_max = okane // 10000

for x in range(x_max + 1):
    z_max = (okane // 1000)
    tmp = z_max - osatsu - 9 * x
    if tmp % 4 != 0 or tmp < 0:
        continue
    y = tmp // 4
    z = osatsu - x - y
    if z < 0:
        continue

    print(x,y,z)
    break
else:
    print(-1, -1, -1)

Buggy submission (verdict: Runtime Error):
osatsu, okane = map(int, input().split())

#1万円の枚数 : x
#5千円の枚数 : y
#千円の枚数  : z

x_max = okane // 10_000

for x in range(x_max + 1):
    z_max = (okane // 1_000)
    tmp = z_max - osatsu - 9 * x
    if tmp % 4 != 0 or tmp < 0:
        continue
    y = tmp // 4
    z = osatsu - x - y
    if z < 0:
        continue

    print(x,y,z)
    break
else:
    print(-1, -1, -1)
Problem p02576 (python)

Fixed submission:
N,X,T=input().split()

print(((int(N)-1)//int(X)+1)*int(T))

Buggy submission (verdict: Runtime Error):
H,W,M=map(int,input().split())
MX=[0]*H
MY=[0]*W
MA=[0]*M

for i in range(M):
  x,y=map(int,input().split())
  x-=1
  y-=1
  MX[x]+=1
  MY[y]+=1
  MA[i]=(x,y)
xmax=max(MX)
ymax=max(MY)
ix=[x[0] for x in enumerate(MX) if x[1]==xmax]
iy=[x[0] for x in enumerate(MY) if x[1]==ymax]

i=0
j=0
for x,y in MA:
  if x in ix or y in iy:
    pass
  else:
    i+=1
  
  j+=1
  
  if len(ix)*len(iy)-j>M-i:
    print(xmax+ymax)
else:
  print(xmax+ymax-1)

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

H,W,M=input().split()
H=int(H)
W=int(W)
M=int(M)
MA=np.zeros((H,W),dtype=int64)
MX=[0]*H
MY=[0]*W
for i in range(M):
  x,y=input().split()
  MA[int(x)-1,int(y)-1]=1

MX=np.sum(MA,axis=1)
MY=np.sum(MA,axis=0)

xmax=max(MX)
ymax=max(MY)
ix=[x[0] for x in enumerate(MX) if x[1]==xmax]
iy=[x[0] for x in enumerate(MY) if x[1]==ymax]

ii=min([MA[x,y] for x in ix for y in iy])

print(xmax+ymax-ii)
Problem p02582 (python)

Fixed submission:
S=input()
for i in range(0,3):
    if S[0]=="R" and S[1]=="R" and S[2]=="R":
        x=3
    elif S[0]=="R" and S[1]=="R":
        x=2
    elif S[1]=="R" and S[2]=="R":
        x=2
    elif S[0]=="R" or S[1]=="R" or S[2]=="R":
        x=1
    else:
        x=0
print(x)

Buggy submission (verdict: Runtime Error):
X, K, D = map(int, input().split())
X=abs(X)
if D>=X and K%2==0:
    ans=X
elif D>=X and K%2==1:
    ans=D-X
elif D<X and K*D<X:
    ans=X-K*D
else:
    ans=X%D
    if (X-ans)%2==0:
        ans=D-ans
print(ans)
Problem p02584 (python)

Fixed submission:
X, K, D = map(int, input().split())
X=abs(X)
if D>=X and K%2==0:
    ans=X
elif D>=X and K%2==1:
    ans=D-X
elif D<X and K*D<X:
    ans=X-K*D
else:
    ans=X%D
    if (X-ans)%2!=K%2:
        ans=D-ans
print(ans)

Buggy submission (verdict: Runtime Error):
X, K, D = map(int, input().split())
X=abs(X)
if D>=X and K%2==0:
    ans=X
elif D>=X and K%2==1:
    ans=D-X
elif D<X and K*D<X:
    ans=X-K*D
else:
    if X<K*D-X:
        ans=X
        for i in range(0,K):
            ans=ans-D
            if ans<0 and (K-i)%2==0:
                ans=ans+D
                break
            elif ans<0 and (K-i)%2==1:
                ans=-ans
                break
    else:
        ans=K*D-X
        for i in range(0,K):
            ans=ans+D
        if ans>0 and (K-i)%2==0:
            ans=-ans+D
            break
        elif ans>0 and (K-i)%2==1:
            ans=ans
            break
print(ans)

Buggy submission (verdict: Runtime Error):
X, K, D = map(int, input().split())
X=abs(X)
if X==0 and K%2==0:
    ans=0
elif X==0 and K%2==1:
    ans=D
elif D>=X and K%2==0:
    ans=X
elif D>=X and K%2==1:
    ans=D-X
elif X>0 and D<X :
    if K*D<X:
        ans=X-K*D
    else:
        for i in range(0,K):
            if X-i*D<0:
                if (K-i)%2==0:
                    ans=X-(i-1)*D
                    break
                else:
                    ans=i*D-X
                    break
print(ans)

Buggy submission (verdict: Runtime Error):
X, K, D = map(int, input().split())
X=abs(X)
if X==0 and K%2==0:
    ans=0
elif X==0 and K%2==1:
    ans=D
elif D>=X and K%2==0:
    ans=X
elif D>=X and K%2==1:
    ans=D-X
elif X>0 and D<X :
    if K*D<X:
        ans=X-K*D
    else:
        for i in range(1,K):
            if X-i*D<0:
                if (K-i)%2==0:
                    ans=X-(i-1)*D
                    break
                else:
                    ans=i*D-X
                    break
print(ans)
Problem p02909 (python)

Fixed submission:
S=input()
if S=="Sunny":
    print("Cloudy")
elif S=="Cloudy":
    print("Rainy")
else:
    print("Sunny")

Buggy submission (verdict: Runtime Error):
X = list(map(int, input().split()))
A = []
B=[]
for _ in range(X[2]):
    A.append(int(input()))
for i in range(0,X[0]):
    count=0
    for j in range(0,X[2]):
        if j<X[2]-1 and A[j]!=i+1:
            count=count+1
        elif j==X[2]-1:
            if A[j]!=i+1:
                count=count+1
                if count < X[1]:
                    B.append("Yes")
                else:
                    B.append("No")
            else:
                if count < X[1]:
                    B.append("Yes")
                else:
                    B.append("No")
            
print(B)
Problem p02995 (python)

Fixed submission:
A,B,C,D = list(map(int, input().split()))
def gcd(a, b):
    while b:
        a, b = b, a % b
    return a
l=C*D//gcd(C,D)
print(B+1-A -B//C+(A-1)//C -B//D+(A-1)//D +B//l-(A-1)//l )

Buggy submission (verdict: Runtime Error):
A,B,C,D = list(map(int, input().split()))
import math
l=C*D//math.gcd(C,D)
print(B+1-A -B//C+(A-1)//C -B//D+(A-1)//D +B//l+(A-1)//l )
Problem p03006 (python)

Fixed submission:
N = list(map(int, input().split()))
d = {0:0}

pos=[]
for x in range(N[0]):
    a = list(map(int, input().split()))
    for y in pos:
        key = (a[0]-y[0])*(10**11)+(a[1]-y[1])
        if key<0:
            key=-key
        if key not in d.keys():
            d[key] = 0
        d[key] += 1
    pos.append(a)
    
print(N[0]-max(d.values()))

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

pos=[]
for x in range(N[0]):
    a = list(map(int, input().split()))
    for y in pos:
        key = (a[0]-y[0])*(10**11)+(a[1]-y[1])
        if key<0:
            key=-key
        if key not in d.keys():
            d[key] = 0
        d[key] += 1
    pos.append(a)
    
print(N[0]-max(d.values()))

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

pos=[]
for x in range(N[0]):
    a = list(map(int, input().split()))
    for y in pos:
        key = (a[0]-y[0])*(10**11)+(a[1]-y[1])
        if key<0:
            key=-key
    pos.append(a)
    
print(N[0]-max(d.values()))

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

pos=[]
for x in range(N[0]):
    a = list(map(int, input().split()))
    for y in pos:
        key = (a[0]-y[0])*(10**11)+(a[1]-y[1])
        if key<0:
            key=-key
        if key not in d:
            d[key] = 0
        d[key] += 1
    pos.append(a)
    
print(N[0]-max(d.values()))

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

pos=[]
for x in range(N[0]):
    a = list(map(int, input().split()))
    for y in pos:
        key = (a[0]-y[0])*(10**11)+(a[1]-y[1])
        if key not in d:
            d[key] = 0
        d[key] += 1
    pos.append(a)
    
print(N[0]-max(d.values()))
Problem p02632 (python)

Fixed submission:
def cmb(n, r, mod):
    if ( r<0 or r>n ):
        return 0
    r = min(r, n-r)
    return g1[n] * g2[r] * g2[n-r] % mod

mod = 10**9+7 #出力の制限
N = 2*(10**6)+5
g1 = [1, 1] # 元テーブル
g2 = [1, 1] #逆元テーブル
inverse = [0, 1] #逆元テーブル計算用テーブル

for i in range( 2, N + 1 ):
    g1.append( ( g1[-1] * i ) % mod )
    inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod )
    g2.append( (g2[-1] * inverse[-1]) % mod )
    
K=int(input())
s=input()
S=len(s)

ans=0
for i in range(K+1):
    ans+=(cmb(i+S-1,S-1,mod)*pow(25,i,mod)*pow(26,K-i,mod))%mod
    ans%=mod
print(ans)

Buggy submission (verdict: Runtime Error):
def cmb(n, r, mod):
    if ( r<0 or r>n ):
        return 0
    r = min(r, n-r)
    return g1[n] * g2[r] * g2[n-r] % mod

mod = 10**9+7 #出力の制限
N = 10**6+5
g1 = [1, 1] # 元テーブル
g2 = [1, 1] #逆元テーブル
inverse = [0, 1] #逆元テーブル計算用テーブル

for i in range( 2, N + 1 ):
    g1.append( ( g1[-1] * i ) % mod )
    inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod )
    g2.append( (g2[-1] * inverse[-1]) % mod )
    
K=int(input())
s=input()
S=len(s)

ans=0
for i in range(K+1):
    ans+=(cmb(i+S-1,S-1,mod)*pow(25,i,mod)*pow(26,K-i,mod))%mod
    ans%=mod
print(ans)
Problem p02716 (python)

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

DP=[[-10**16 for i in range(N)]for j in range(3)]

DP[1][0]=0
DP[2][0]=0
DP[2][1]=0
DP[0][0]=A[0]
DP[1][1]=A[1]
if N>=3:
    DP[2][2]=A[2]

for i in range(2,N):
    DP[0][i]=DP[0][i-2]+A[i]
    DP[1][i]=DP[1][i-2]+A[i]
    DP[2][i]=DP[2][i-2]+A[i]
    if i-3>=0:
        DP[1][i]=max(DP[1][i],DP[0][i-3]+A[i])
        DP[2][i]=max(DP[2][i],DP[1][i-3]+A[i])
    if i-4>=0:
        DP[2][i]=max(DP[2][i],DP[0][i-4]+A[i])

if N%2==0:
    print(max(DP[0][-2],DP[1][-1]))
else:
    print(max(DP[0][-3],DP[1][-2],DP[2][-1]))

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

DP=[[-10**16 for i in range(N)]for j in range(3)]

DP[1][0]=0
DP[2][0]=0
DP[2][1]=0
DP[0][0]=A[0]
DP[1][1]=A[1]
DP[2][2]=A[2]

for i in range(2,N):
    DP[0][i]=DP[0][i-2]+A[i]
    DP[1][i]=DP[1][i-2]+A[i]
    DP[2][i]=DP[2][i-2]+A[i]
    if i-3>=0:
        DP[1][i]=max(DP[1][i],DP[0][i-3]+A[i])
        DP[2][i]=max(DP[2][i],DP[1][i-3]+A[i])
    if i-4>=0:
        DP[2][i]=max(DP[2][i],DP[0][i-4]+A[i])

if N%2==0:
    print(max(DP[0][-2],DP[1][-1]))
else:
    print(max(DP[0][-3],DP[1][-2],DP[2][-1]))
Problem p02787 (python)

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

L=[]
for i in range(N):
    a,b=map(int,input().split())
    L.append([a,b])
L.sort()
import math
X=math.ceil(H/L[i][0]*L[i][1])
dp=[10**20 for i in range(10**4+100)]
dp[0]=0
for i in range(N):
    for j in range(len(dp)):
        if j%L[i][0]==0:
            Y=j//L[i][0]
        else:
            Y=j//L[i][0]+1
        if j-L[i][0]>=0:
            dp[j]=min(dp[j],Y*L[i][1],dp[j-L[i][0]]+L[i][1])
        else:
            dp[j]=min(dp[j],Y*L[i][1])
print(dp[H])

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

L=[]
for i in range(N):
    a,b=map(int,input().split())
    L.append([a,b])
L.sort()
import math
X=math.ceil(H/L[i][0]*L[i][1])
dp=[10**20 for i in range(10**4)]
dp[0]=0
for i in range(N):
    for j in range(len(dp)):
        if j%L[i][0]==0:
            Y=j//L[i][0]
        else:
            Y=j//L[i][0]+1
        if j-L[i][0]>=0:
            dp[j]=min(dp[j],Y*L[i][1],dp[j-L[i][0]]+L[i][1])
        else:
            dp[j]=min(dp[j],Y*L[i][1])
print(dp[H])
Problem p02788 (python)

Fixed submission:
import sys
input=sys.stdin.readline

N,D,A=map(int,input().split())
L=[]
for i in range(N):
    x,h=map(int,input().split())
    L.append([x,h])
L.sort()

import math

ans=0
S=0
P=0
RL=[0]
RC=[0]
cnt=0
for i in range(N):
    for j in range(P,len(RL)):
        if RL[P]<L[i][0]:
            cnt+=RC[P]
            P+=1
        else:
            break
    if L[i][1]-S+cnt>0:
        ans+=math.ceil((L[i][1]-S+cnt)/A)
        
        RL+=[L[i][0]+2*D]
        RC+=[math.ceil((L[i][1]-S+cnt)/A)*A]
        S+=math.ceil((L[i][1]-S+cnt)/A)*A
    #print(i,ans,P,RL,RC,S,cnt)
print(ans)

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

N,D,A=map(int,input().split())
L=[]
for i in range(N):
    x,h=map(int,input().split())
    L.append([x,h])
L.sort()

import math

ans=0
S=0
P=0
RL=[]
RC=[]
cnt=0
for i in range(N):
    while P<i and RL[P]<L[i][0]:
        cnt+=RC[P]
        P+=1
    if L[i][1]-S+cnt>0:
        ans+=math.ceil((L[i][1]-S+cnt)/A)
        RL=RL[:len(RL)-1]
        RC=RC[:len(RC)-1]
        RL+=[L[i][0]+2*D]
        RC+=[math.ceil((L[i][1]-S+cnt)/A)*A]
        S+=math.ceil((L[i][1]-S+cnt)/A)*A
    #print(i,ans,P)
print(ans)

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

N,D,A=map(int,input().split())
L=[]
for i in range(N):
    x,h=map(int,input().split())
    L.append([x,h])
L.sort()

import math

ans=0
S=0
P=0
RL=[0]
RC=[0]
cnt=0
for i in range(N):
    while RL[P]<L[i][0] and P<i:
        cnt+=RC[P]
        P+=1
    if L[i][1]-S+cnt>0:
        ans+=math.ceil((L[i][1]-S+cnt)/A)
        RL=RL[:len(RL)-1]
        RC=RC[:len(RC)-1]
        RL+=[L[i][0]+2*D]
        RC+=[math.ceil((L[i][1]-S+cnt)/A)*A]
        S+=math.ceil((L[i][1]-S+cnt)/A)*A
    #print(i,ans,P)
print(ans)
Problem p02845 (python)

Fixed submission:
N=int(input())
S=list(map(int,input().split()))
D={}
mod=((10**9)+7)
ans=1
for i in range(N):
    try:
        if S[i]==0:
            if 0 not in D:
                D[0]=1
                ans*=3
            elif D[0]==1:
                D[0]+=1
                ans*=2
            elif D[0]==2:
                D[0]=3
            else:
                ans=0
        elif S[i] not in D:
            ans*=D[S[i]-1]
            ans%mod
            D[S[i]]=1
        else:
            if D[S[i]]==1:
                ans*=(D[S[i]-1]-1)
                D[S[i]]+=1
                ans%=mod
            elif D[S[i]]==2:
                ans*=(D[S[i]-1]-2)
                D[S[i]]+=1
                ans%=mod
            else:
                ans=0
    except:
        ans=0
    #print(ans)
print(ans%mod)

Buggy submission (verdict: Runtime Error):
N=int(input())
S=list(map(int,input().split()))
D={}
mod=((10**9)+7)
ans=1
for i in range(N):
    if S[i]==0:
        if 0 not in D:
            D[0]=1
            ans*=3
        elif D[0]==1:
            D[0]+=1
            ans*=2
        else:
            D[0]=3
    elif S[i] not in D:
        ans*=D[S[i]-1]
        ans%mod
        D[S[i]]=1
    else:
        if D[S[i]]==1:
            ans*=(D[S[i]-1]-1)
            D[S[i]]+=1
            ans%=mod
        elif D[S[i]]==2:
            ans*=(D[S[i]-1]-2)
            D[S[i]]+=1
            ans%=mod
    #print(ans)
print(ans%mod)

Buggy submission (verdict: Runtime Error):
N=int(input())
S=list(map(int,input().split()))
D={}
mod=((10**9)+7)
ans=1
for i in range(N):
    if S[i]==0:
        if 0 not in D:
            D[0]=1
            ans*=3
        elif D[0]==1:
            D[0]+=1
            ans*=2
        else:
            D[0]=3
    elif S[i] not in D:
        ans*=D[S[i]-1]
        ans%mod
        D[S[i]]=1
    else:
        if D[S[i]]==1:
            ans*=(D[S[i]-1]-1)
            D[S[i]]+=1
            ans%=mod
        elif D[S[i]]==2:
            ans*=(D[S[i]-1]-2)
            D[S[i]]+=1
            ans%=mod
    #print(ans)
print(ans)
Problem p02850 (python)

Fixed submission:
import sys
input=sys.stdin.readline
N=int(input())
A=[]
L=[[]for i in range(N+1)]
for i in range(N-1):
    a,b=map(int,input().split())
    L[a].append(b)
    L[b].append(a)
    A.append((a,b))

P=[-1 for i in range(N+1)]
P[1]=0
Q=[]
for i in L[1]:
    Q.append([i,1])

for i in range(N):
    if len(Q)==i:
        break
    P[Q[i][0]]=Q[i][1]
    for j in L[Q[i][0]]:
        if P[j]==-1:
            Q.append([j,Q[i][0]])
#print(P)
#print(Q)
D={}
D[(0,1)]=0
cnt=1
p=0
for i in range(N-1):
    if p!=Q[i][1]:
        p=Q[i][1]
        cnt=1
        for j in range(cnt,10**6):
            if D[(min(Q[i][1],P[Q[i][1]]),max(Q[i][1],P[Q[i][1]]))] != j:
                D[(min(Q[i]),max(Q[i]))] = j
                cnt = j+1
                break
    else:
        for j in range(cnt,10**6):
            if D[(min(Q[i][1],P[Q[i][1]]),max(Q[i][1],P[Q[i][1]]))] != j:
                D[(min(Q[i]),max(Q[i]))] = j
                cnt = j+1
                break
print(max(D.values()))
for i in range(N-1):
    print(D[A[i][0],A[i][1]])

Buggy submission (verdict: Runtime Error):

L=[{}for i in range(N+1)]
ans=[]
for i in range(N-1):
    a,b=map(int,input().split())
    for j in range(1,N):
        if j not in L[a] and j not in L[b]:
            L[a][j]=1
            L[b][j]=1
            ans.append(j)
            break
print(max(ans))
for i in range(N-1):
    print(ans[i])
#print(L)
Problem p02852 (python)

Fixed submission:
N,M=map(int,input().split())
S=list(input())
S=S[::-1]
ans=[]
P=0
for i in range(1,N+1):
    if P==N:
        break
    for j in range(M+1):
        if P+(M-j)<=N and S[P+(M-j)]=="0":
            ans.append(M-j)
            P+=M-j
            if M-j==0:
                print(-1)
                exit()
            break
ans=ans[::-1]
if 0 in ans:
    print(-1)
else:
    print(*ans)

Buggy submission (verdict: Runtime Error):
N,M=map(int,input().split())
S=list(input())
S=S[::-1]
ans=[]
P=0
for i in range(1,N+1):
    if P==N:
        break
    for j in range(M+1):
        if P+(M-j)<=N and S[P+(M-j)]=="0":
            ans.append(M-j)
            P+=M-j
            if M-j==:
                print(-1)
                exit()
            break
ans=ans[::-1]
if 0 in ans:
    print(-1)
else:
    print(*ans)