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

Fixed submission:
H,W=map(int,input().split())
s=[0]*H
for i in range(H):
  s[i]= list(input())

dp= [[float("inf") for _ in range(W)] for _ in range(H)]
dp[0][0]= 1 if s[0][0]=="#" else 0

mv=[(-1,0),(0,-1)]
for i in range(H):
  for j in range(W):
    if i==0 and j==0: pass
    else:
      tmp=float("inf")
      for k in mv:
        a = i+k[0]
        b = j+k[1]
        if 0 <=a <= H-1 and 0 <=b <= W-1:
          if s[i][j]=="#" and s[a][b]==".":
            tmp= dp[a][b]+1
          else:
            tmp= dp[a][b]
        dp[i][j]=min(dp[i][j],tmp)
        
print(dp[-1][-1])

Buggy submission (verdict: Runtime Error):
def calc(P):
    #Pはリスト
    Q=[]
    for str in A:
        if str=="1":
            pass
        elif str=="2":
            Q.append("1")
        else:
            Q.append("2")
    return Q

def solve(P):
    #Pはリスト
    N=len(P)
    if N>1:
        Q=[]
        for i in range(N-1):
            if   abs( int(P[i])-int(P[i+1]) )==0:
                Q.append("0")
            elif abs( int(P[i])-int(P[i+1]) )==1:
                Q.append("1")
            else:
                Q.append("2")
        return solve(Q)
    elif N==0:
    	return(0)
    else:
        return P[0]

N=int(input())
A=input()
B=list(A)

#print(A)
#print(B) 
short=calc(B)
#print(short)

ans=solve(short)
print(ans)
Problem p02859 (python)

Fixed submission:
r=int(input())

print(int(r**2))

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

print(r**2)
Problem p02897 (python)

Fixed submission:
A=int(input())
cnt=0
sum=0

for i in range(1,A+1):
  sum+=1
  if i%2==1:
    cnt+=1
    
print(cnt/sum)

Buggy submission (verdict: Runtime Error):
A=int(input())
cnt=0
sum=0

for i in range(1,A+1):
  sum;=1
  if i%2==1:
    cnt+=1
    
print(cnt/sum)
Problem p02933 (python)

Fixed submission:
a=int(input())
s=input()

if a>=3200:
  print(s)
else:
  print("red")

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

If a>=3200:
  print(s)
else:
  print("red")
Problem p02954 (python)

Fixed submission:
S=input()
N=len(S)
ans=[]

def calc(R_count,L_count,ans):
  ans += [0]*(R_count-1)
  ans.append( (R_count+1)//2 + (L_count//2) )  
  ans.append( (L_count+1)//2 + (R_count//2) )
  ans += [0]*(L_count-1)
  return

R_count=0
L_count=0
i=0

while i<N:
  #print(i,S[i])
  if S[i]=="R":
    R_count += 1
    i += 1
  else:
    while i<N and S[i]=="L":
      #print(i,S[i])
      L_count +=1
      i += 1
    calc(R_count,L_count,ans)
    R_count=0
    L_count=0

#print(ans)
print(*ans)

Buggy submission (verdict: Runtime Error):
S=input()
N=len(S)
Letter=[]
list=[0]*N
for i in range(N):
  Letter.append(S[i])

R_sum=0
L_sum=0
Leftl=0

for i in range(Leftl,N-2):

  R_sum=0
  while S[i]=="R":
    R_sum=R_sum+1
    i=i+1
  else:
    L_sum=0
    if R_sum>=1:
      while S[i]=="L":
        L_sum=L_sum+1
        if i!=N-1:
          i=i+1
        else:
          break
      else:
        print(Leftl,R_sum,L_sum)

        if R_sum%2==1:
          list[Leftl+R_sum-1]=(R_sum+L_sum+1)//2
          list[Leftl+R_sum]=(R_sum+L_sum)//2          
        else:
          list[Leftl+R_sum-1]=(R_sum+L_sum)//2
          #print(Leftl,R_sum)
          list[Leftl+R_sum]=(R_sum+L_sum+1)//2          
        Leftl=i          
        
        
        
print(list)


  
#  if S[i]=="R" and S[i+1]=="L":
#    list.append(i)

#print(Letter)
#print(list)
#for j in list:
#  print(j)
Problem p03042 (python)

Fixed submission:
S=input()

left=int(S[:2])
right=int(S[2:])

YYMM=True
MMYY=True
AMBIGUOUS=True
NA=True


if left<=0 or left>12:
  MMYY=False
  AMBIGUOUS=False
else:
  NA=False
  
if right<=0 or right>12:
  YYMM=False
  AMBIGUOUS=False
else:
  NA=False


if YYMM==True:
  if MMYY==True:
    print("AMBIGUOUS")
  else:
    print("YYMM")
else:
  if MMYY==True:
    print("MMYY")
  else:
    print("NA")

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

left=int(S[:2])
right=int(S[2:])

YYMM=True
MMYY=True
AMBIGUOUS=True
NA=True


if leftL<=0 or left>12:
  MMYY=False
  AMBIGUOUS=False
else:
  NA=False
  
if right<=0 or right>12:
  YYMM=False
  AMBIGUOUS=False
else:
  NA=False

if YYMM==True:
  if MMYY==True:
    print("AMBIGOUS")
  else:
    print("YYMM")
else:
  if MMYY==True:
    print("MMYY")
  else:
    print("NA")
Problem p03250 (python)

Fixed submission:
def main():
	A, B, C = [int(_) for _ in input().split()]

	l_max=max(A,B,C)
	l_min=min(A,B,C)
	l_mid=(A+B+C)-(l_max+l_min)

	ans=10*l_max+l_mid+l_min
	print(ans)
    
main()

Buggy submission (verdict: Runtime Error):
def main():
	l = map(int, input().split())
	A=l[0]
	B=l[1]
	C=l[2]

	l_max=max(A,B,C)
	l_min=min(A,B,C)
	l_mid=(A+B+C)-(l_max+l_min)

	ans=10*l_max+l_mid+l_min
	print(ans)
    
main()
Problem p03426 (python)

Fixed submission:
# https://atcoder.jp/contests/abc089/tasks/abc089_d

def calc(x):
    if x<D+1:
        mv[x]=0
        return 0
    else:
        p = d[x][0]
        q = d[x][1]
        r = d[x-D][0]
        s = d[x-D][1]
        tmp = abs(p-r)+abs(q-s)
        ret= tmp+calc(x-D)
        mv[x]=ret
        return ret
####################################################################
import sys 
sys.setrecursionlimit(10**5)
H,W,D= map(int,input().split())
A = [list(map(int,input().split())) for _ in range(H)]
Q=int(input())

d=dict()
z=0
for a in A:
    for b in a:
        p = z//W
        q = z%W
        d[b]=(p,q)
        z+=1
        
mv=[0]*(H*W+1)
for i in range(D):
    calc(H*W-i)
    #print(H*W-i,calc(H*W-i))    
#print(mv)

L=[0]*Q
R=[0]*Q
for _ in range(Q):
    L,R=map(int,input().split())
    print(mv[R]-mv[L])

Buggy submission (verdict: Runtime Error):
# https://atcoder.jp/contests/abc089/tasks/abc089_d

def calc(x):
    if x<D+1:
        mv[x]=0
        return 0
    else:
        p = d[x][0]
        q = d[x][1]
        r = d[x-D][0]
        s = d[x-D][1]
        tmp = abs(p-r)+abs(q-s)
        ret= tmp+calc(x-D)
        mv[x]=ret
        return ret
    
H,W,D= map(int,input().split())
A = [list(map(int,input().split())) for _ in range(H)]
Q=int(input())

d=dict()
z=0
for a in A:
    for b in a:
        p = z//W
        q = z%W
        d[b]=(p,q)
        z+=1
        
mv=[0]*(H*W+1)
for i in range(D):
    calc(H*W-i)
    #print(H*W-i,calc(H*W-i))    
#print(mv)

L=[0]*Q
R=[0]*Q
for _ in range(Q):
    L,R=map(int,input().split())
    print(mv[R]-mv[L])
Problem p03634 (python)

Fixed submission:
from collections import deque

N=int(input())
a=[0]*(N-1)
b=[0]*(N-1)
c=[0]*(N-1)
L=[ [] for _ in range(N)]
for i in range(N-1):
  a[i],b[i],c[i]= map(int,input().split())
  L[a[i]-1].append((b[i]-1,c[i]))
  L[b[i]-1].append((a[i]-1,c[i]))
Q,K= map(int,input().split())
         
#Lの中のitemの0は接続先、1は距離

d=[ -1 for i in range(N)]

def BFS(x):
  v=deque([x])
  d[x]=0
  
  while len(v)>0:
    s=v.popleft() #sはint
    for item in L[s]:
      if d[item[0]]==-1:
        d[item[0]]=d[s]+item[1]
        v.append(item[0])
BFS(K-1)

x=[0]*Q
y=[0]*Q
for i in range(Q):
  x[i],y[i] = map(int,input().split())
  print(d[x[i]-1]+d[y[i]-1])

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

N=int(input())
a=[0]*(N-1)
b=[0]*(N-1)
c=[0]*(N-1)
L=[ [] for _ in range(N)]
for i in range(N-1):
  a[i],b[i],c[i]= map(int,input().split())
  L[a[i]-1].append((b[i]-1,c[i]))
  L[b[i]-1].append((a[i]-1,c[i]))
Q,K= map(int,input().split())
         
#Lの中のitemの0は接続先、1は距離

d=[ -1 for i in range(N)]

def BFS(x):
  v=deque([x])
  d[x]=0
  
  while len(v)>0:
    s=v.popleft() #sはint
    for item in L[s]:
      if d[item[0]]==-1:
        d[item[0]]=d[s]+item[1]
        v.append(item[0])
BFS(K-1)

x=[0]*Q
y=[0]*Q
for j in range(Q):
  x[i],y[i] = map(int,input().split())
  print(d[x[i]-1]+d[y[i]-1])

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

N=int(input())
a=[0]*(N-1)
b=[0]*(N-1)
c=[0]*(N-1)
L=[ [] for _ in range(N)]
for i in range(N-1):
  a[i],b[i],c[i]= map(int,input().split())
  L[a[i]-1].append((b[i]-1,c[i]))
  L[b[i]-1].append((a[i]-1,c[i]))
Q,K= map(int,input().split())
         
#Lの中のitemの0は接続先、1は距離

d=[ -1 for i in range(N)]

def BFS(x):
  v=deque([x])
  d[x]=0
  
  while len(v)>0:
    s=v.popleft() #sはint
    for item in L[s]:
      if d[item[0]]==-1:
        d[item[0]]=d[s]+item[1]
        v.append(item[0])
BFS(K-1)

x=[0]*N
y=[0]*N
for i in range(Q):
  x[i],y[i] = map(int,input().split())
  print(d[x[i]-1]+d[y[i]-1])
Problem p03767 (python)

Fixed submission:
N=int(input())
a=list(map(int,input().split()))
a.sort(reverse=True)

#print(a)
print(sum( a[1:2*N:2] ))

Buggy submission (verdict: Runtime Error):
N=int(input())
a=list(map(int,input().split()))
a.sort(reverse=True)

print(sum(N//3:2N//3))
Problem p03013 (python)

Fixed submission:
n,m=map(lambda x: int(x), input().split())
INF=10**12
dp=[INF]*n
for _ in range(m):
    dp[int(input())-1]=0
dp[0]=1 if dp[0]==INF else 0
if n>1:
    dp[1]=dp[0]+1 if dp[1]==INF else 0
if n>2:
    for i in range(2, n):
        if dp[i]==0:
            continue
        dp[i]=(dp[i-1]+dp[i-2])%(10**9+7)
print(dp[n-1])

Buggy submission (verdict: Runtime Error):
n,m=map(lambda x: int(x), input().split())
INF=10**12
dp=[INF]*n
for _ in range(m):
    dp[int(input())-1]=0
dp[0]=1 if dp[0]==INF else 0
dp[1]=dp[0]+1 if dp[1]==INF else 0
for i in range(2, n):
    if dp[i]==0:
        continue
    dp[i]=(dp[i-1]+dp[i-2])%(10**9+7)
print(dp[n-1])
Problem p02596 (python)

Fixed submission:
K = int(input())

powlis = [7*pow(10, i, K) for i in range(K)]
for i in range(K-1):
    powlis[i+1] = (powlis[i] + powlis[i+1]) % K
powlis[0] %= K


try:
    print(powlis.index(0) + 1)
except:
    print(-1)

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

powlis = [pow(10, i, K) for i in range(K)]
for i in range(K-1):
    powlis[i+1] = (powlis[i] + powlis[i+1]) % K
    
print(lis[0:10])
if 0 in lis:
    print(lis.index(0)+1)
else:
    print(-1)
Problem p02661 (python)

Fixed submission:
N = int(input())
X = [list(map(int,input().split())) for _ in range(N)]
A = sorted([X[i][0] for i in range(N)])
B = sorted([X[i][1] for i in range(N)])
if N%2==1:
    k = (N+1)//2
    a = A[k-1]
    b = B[k-1]
    print(b-a+1)
else:
    a2 = A[N//2-1]+A[N//2]
    b2 = B[N//2-1]+B[N//2]
    print(b2-a2+1)

Buggy submission (verdict: Runtime Error):
N = int(input())
A = [list(map(int,input().split())) for _ in range(N)]
C = {}
for i in range(N):
    a,b = A[i]
    if a not in C:
        C[a] = 0
    C[a] += 1
    if b not in C:
        C[b] = 0
    C[b] += 1
C = sorted(list(C.keys()))
if N%2==1:
    k = (N+1)//2
    a = C[k-2]
    b = C[-(k-1)]
    print(b-a+1)
else:
    k = N//2
    a = C[k-2]
    a1 = C[k-1]
    b = C[-(k-1)]
    b1 = C[-(k-1)-1]
    print(b+b1-a-a1+1)
Problem p02735 (python)

Fixed submission:
from collections import deque
H,W = map(int,input().split())
A = [input().strip() for _ in range(H)]
d = 0
if A[0][0]=="#":
    d += 1
que = deque([(0,0,d)])
hist = [[H*W for _ in range(W)] for _ in range(H)]
hist[0][0] = d
while que:
    i,j,d = que.popleft()
    if j+1<W and A[i][j+1]==A[i][j]:
        if hist[i][j+1]>d:
            hist[i][j+1] = d
            que.append((i,j+1,d))
    elif j+1<W and A[i][j+1]!=A[i][j]:
        if hist[i][j+1]>d+1:
            hist[i][j+1] = d+1
            que.append((i,j+1,d+1))
    if i+1<H and A[i+1][j]==A[i][j]:
        if hist[i+1][j]>d:
            hist[i+1][j] = d
            que.append((i+1,j,d))
    elif i+1<H and A[i+1][j]!=A[i][j]:
        if hist[i+1][j]>d+1:
            hist[i+1][j] = d+1
            que.append((i+1,j,d+1))
m = hist[H-1][W-1]
print((m+1)//2)

Buggy submission (verdict: Runtime Error):
INFTY = 10**3
def paint0(i,j):
    global cnt
    if j+1<W and C[i][j+1]<0 and A[i][j+1]==0:
        C[i][j+1]=cnt
        paint0(i,j+1)
    if i-1>=0 and C[i-1][j]<0 and A[i-1][j]==0:
        C[i-1][j]=cnt
        paint0(i-1,j)
    if j-1>=0 and C[i][j-1]<0 and A[i][j-1]==0:
        C[i][j-1]==cnt
        paint0(i,j-1)
    if i+1<H and C[i+1][j]<0 and A[i+1][j]==0:
        C[i+1][j]=cnt
        paint0(i+1,j)
def paint1(i,j):
    if j+1<W and A[i][j+1]==1:
        A[i][j+1]=0
        paint1(i,j+1)
    if i-1>=0 and A[i-1][j]==1:
        A[i-1][j]=0
        paint1(i-1,j)
    if j-1>=0 and A[i][j-1]==1:
        A[i][j-1]=0
        paint1(i,j-1)
    if i+1<H and A[i+1][j]==1:
        A[i+1][j]=0
        paint1(i+1,j)
def paint2(i,j):
    global ind
    if j+1<W and A[i][j+1]==1 and C[i][j+1]<0:
        C[i][j+1]=ind
        paint2(i,j+1)
    elif j+1<W and A[i][j+1]==0 and dist[C[i][j+1]]>=INFTY:
        dist[C[i][j+1]] = dist[ind]+1
    if i-1>=0 and A[i-1][j]==1 and C[i-1][j]<0:
        C[i-1][j]=ind
        paint2(i-1,j)
    elif i-1>=0 and A[i-1][j]==0 and dist[C[i-1][j]]>=INFTY:
        dist[C[i-1][j]]=dist[ind]+1
    if j-1>=0 and A[i][j-1]==1 and C[i][j-1]<0:
        C[i][j-1]=ind
        paint2(i,j-1)
    elif j-1>=0 and A[i][j-1]==0 and dist[C[i][j-1]]>=INFTY:
        dist[C[i][j-1]]=dist[ind]+1
    if i+1<H and A[i+1][j]==1 and C[i+1][j]<0:
        C[i+1][j]=ind
        paint2(i+1,j)
    elif i+1<H and A[i+1][j]==0 and dist[C[i+1][j]]>=INFTY:
        dist[C[i+1][j]]=dist[ind]+1
    
H,W = map(int,input().split())
S = [input() for _ in range(H)]
A = [[0 for _ in range(W)] for _ in range(H)]
for i in range(H):
    for j in range(W):
        if S[i][j]=="#":
            A[i][j] = 1
C = [[-1 for _ in range(W)] for _ in range(H)]
ans = 0
if A[0][0]==1:
    A[0][0]=0
    paint1(0,0)
    ans += 1
if A[H-1][W-1]==1:
    A[H-1][W-1]=0
    paint1(H-1,W-1)
    ans += 1
cnt = 0
for i in range(H):
    for j in range(W):
        if C[i][j]<0 and A[i][j]==0:
            C[i][j] = cnt
            paint0(i,j)
            cnt += 1
dist = [INFTY for _ in range(cnt)]
dist[0] = 0
for i in range(H):
    for j in range(W):
        if A[i][j]==0:
            ind = C[i][j]
            paint2(i,j)
x = C[H-1][W-1]
ans += dist[x]
print(ans)
Problem p02773 (python)

Fixed submission:
N = int(input())
C = {}
for _ in range(N):
    s = input().strip()
    if s not in C:
        C[s] = 0
    C[s] += 1
C = sorted(list(C.items()),key=lambda x:x[0])
C = sorted(C,key=lambda x:x[1],reverse=True)
k = C[0][1]
for i in range(len(C)):
    if C[i][1]==k:
        print(C[i][0])
    else:break

Buggy submission (verdict: Runtime Error):
N = int(input())
C = {}
for _ in range(N):
    s = input().strip()
    if s not in C:
        C[s] = 0
    C[s] += 1
C = sorted(list(C.items()),key=lambda x:x[0])
C = sorted(C,key=lambda x:x[1],reverse=True)
k = C[0][1]
for i in range(N):
    if C[i][1]==k:
        print(C[i][0])
    else:break
Problem p02781 (python)

Fixed submission:
N = input().strip()
n = len(N)
A = [0 for _ in range(n)]
A[0]=1
for i in range(1,n):
    if N[i]=="0":
        A[i] = A[i-1]
    else:
        A[i] = A[i-1]+1
K = int(input())
if K>n:
    print(0)
else:
    dp = [[[0 for _ in range(n+1)] for _ in range(2)] for _ in range(n+1)]
    dp[0][0][0] = 1
    for i in range(1,n+1):
        for k in range(n+1):
            if k==A[i-1]:
                dp[i][0][k] = 1
                break
    for i in range(1,n+1):
        for k in range(n+1):
            dp[i][1][k] = dp[i-1][1][k]
            if int(N[i-1])>0:
                dp[i][1][k] += dp[i-1][0][k]
            if k>=1:
                dp[i][1][k] += dp[i-1][1][k-1]*9
                if i==1 and k-1==0 and int(N[i-1])>=2:
                    dp[i][1][k] += dp[i-1][0][k-1]*(int(N[i-1])-1)
                elif i>=2 and k-1==A[i-2] and int(N[i-1])>=2:
                    dp[i][1][k] += dp[i-1][0][k-1]*(int(N[i-1])-1)
    print(dp[n][0][K]+dp[n][1][K])

Buggy submission (verdict: Runtime Error):
A = list(map(int,list(input())))
N = len(A)
K = int(input())
dp = [[[[0 for _ in range(100)]] for _ in range(2)] for _ in range(N+1)]
dp[1][0][1] = 1
for i in range(2,N+1):
    for j in range(100):
        dp[i][1][j] = dp[i-1][1][j-1]*9
        if A[i-1]==0:
            dp[i][0][j] = dp[i-1][0][j]
        else:
            dp[i][0][j] = dp[i-1][0][j-1]
            dp[i][1][j] += dp[i-1][0][j-1]*(A[i-1]-1)*(A[i-1]>1)+dp[i-1][0][j]*(A[i-1]==1)
print(dp[N][0][K]+dp[N][1][K])
Problem p02819 (python)

Fixed submission:
from bisect import bisect_left
INFTY = 10**5+10
P = [1 for _ in range(INFTY)]
P[0]=0
P[1]=0
for i in range(2,int(INFTY**0.5)+1):
    for j in range(i*i,INFTY,i):
        P[j] = 0
Q = []
for i in range(INFTY):
    if P[i]==1:
        Q.append(i)
X = int(input())
ind = bisect_left(Q,X)
print(Q[ind])

Buggy submission (verdict: Runtime Error):
from bisect import bisect_left
INFTY = 10**5
P = [1 for _ in range(INFTY)]
P[0]=0
P[1]=0
for i in range(2,int(INFTY**0.5)+1):
    for j in range(i*i,INFTY,i):
        P[j] = 0
Q = []
for i in range(INFTY):
    if P[i]==1:
        Q.append(i)
X = int(input())
ind = bisect_left(Q,X)
print(Q[ind])

Buggy submission (verdict: Runtime Error):
from bisect import bisect_right
INFTY = 10**5
P = [1 for _ in range(INFTY)]
P[0]=0
P[1]=0
for i in range(2,int(INFTY**0.5)+1):
    for j in range(i*i,INFTY,i):
        P[j] = 0
Q = []
for i in range(INFTY):
    if P[i]==1:
        Q.append(i)
X = int(input())
ind = bisect_right(Q,X)
print(Q[ind])

Buggy submission (verdict: Runtime Error):
from bisect import bisect_right
INFTY = 10**5
P = [1 for _ in range(INFTY)]
P[0]=0
P[1]=0
for i in range(2,int(INFTY**0.5)+1):
    for j in range(i*i,INFTY,i):
        P[j] = 0
Q = []
for i in range(INFTY):
    if P[i]==1:
        Q.append(i)
X = int(input())
ind = bisect_right(Q,X)
print(Q[ind])
Problem p02873 (python)

Fixed submission:
S = input().strip()
N = len(S)+1
A = [0 for _ in range(N)]
B = []
for i in range(N):
    if i==0 and S[i]=="<":
        B.append(0)
    elif i<N-2 and S[i]==">" and S[i+1]=="<":
        B.append(i+1)
    elif i==N-2 and S[i]==">":
        B.append(i+1)
for j in range(len(B)-1):
    ind0 = B[j]
    ind1 = B[j+1]
    c = ind0
    while S[c]=="<":
        A[c+1] = max(A[c+1],A[c]+1)
        c += 1
    c = ind1
    while S[c-1]==">":
        A[c-1] = max(A[c-1],A[c]+1)
        c -= 1
c = B[0]
if c>0:
    for i in range(c-1,-1,-1):
        A[i] = A[i+1]+1
c = B[-1]
if c<N-1:
    for i in range(c+1,N):
        A[i] = A[i-1]+1
print(sum(A))

Buggy submission (verdict: Runtime Error):
S = input().strip()
V = []
for i in range(len(S)-1):
    if S[i]==">" and S[i+1]=="<":
        V.append(i+1)
if S[-1]==">":
    V.append(len(S))
B = [0 for _ in range(len(S)+1)]
for i in range(len(S)):
    if S[i]==">":
        B[i+1] = B[i]-1
    else:
        B[i+1] = B[i]+1
for j in V:
    if B[j]<0:
        B[j] = 0
        cur = j-1
        while S[cur]==">":
            B[cur] = max(B[cur],B[cur+1]+1)
            cur -= 1
        cur = j
        while cur<len(S) and S[cur]=="<":
            B[cur+1]=B[cur]+1
            cur += 1
    elif B[j]>0:
        B[j] = 0
        cur = j-1
        while S[cur]==">":
            if cur-1>=0 and S[cur-1]==">":
                B[cur] = B[cur+1]+1
            cur -= 1
        cur = j
        while cur<len(S) and S[cur]=="<":
            B[cur+1] = B[cur]+1
            cur += 1
print(sum(B))
Problem p02892 (python)

Fixed submission:
from collections import deque
N = int(input())
G = {i:[] for i in range(N)}
for i in range(N):
    S = input().strip()
    for j in range(N):
        if S[j]=="1":
            G[i].append(j)
cmax = 0
for i in range(N):
    hist = [0 for _ in range(N)]
    hist[i]=1
    num = 0
    heap = deque([(i,1)])
    ind = 0
    while ind==0 and num<N:
        cur = heap.popleft()
        num += 1
        y = cur[0]
        g = cur[1]
        cmax = max(cmax,g)
        for x in G[y]:
            if hist[x]==0:
                heap.append((x,g+1))
                hist[x]=g+1
            elif hist[x]==hist[y]:
                ind = 1
                break
    if ind==1:break
if ind==1:
    print(-1)
else:
    print(cmax)

Buggy submission (verdict: Runtime Error):
from collections import deque
N = int(input())
S = [list(map(int,list(input))) for _ in range(N)]
G = {i:[] for i in range(N)}
for i in range(N):
    for j in range(N):
        if S[i][j]==1:
            G[i].append(j)
que = deque([(0,-1)])
hist = [0 for _ in range(N)]
hist[0]=1
flag = 0
A = [0]
while que:
    x,z = que.popleft()
    A.append(x)
    for y in G[x]:
        if y!=z:
            if hist[y]==1:
                flag = 1
                break
            hist[y]=1
            que.append((y,x))
    if flag==1:break
if flag==1:
    print(-1)
else:
    a = A[-1]
    que = deque((a,0))
    hist = [0 for _ in range(N)]
    hist[a]=1
    cnt = 0
    while que:
        x,d = que.popleft()
        for y in G[x]:
            if hist[y]==0:
                hist[y]=1
                que.append((y,d+1))
                cnt = d+1
    print(cnt)
Problem p03013 (python)

Fixed submission:
INFTY = 10**9+7
N,M = map(int,input().split())
A = []
for _ in range(M):
    A.append(int(input()))
dp = [0 for _ in range(N+1)]
dp[0] = 1
dp[1] = 1
cur = 0
if M>0 and A[0]==1:
    dp[1] = 0
    cur = 1
for i in range(2,N+1):
    if M>0 and cur<M and i==A[cur]:
        cur += 1
    else:
        dp[i] = (dp[i-1]+dp[i-2])%INFTY
print(dp[N])

Buggy submission (verdict: Runtime Error):
INFTY = 10**9+7
N,M = map(int,input().split())
A = []
for _ in range(M):
    A.append(int(input()))
dp = [0 for _ in range(N+1)]
dp[0] = 1
dp[1] = 1
cur = 0
if A[0]==1:
    dp[1] = 0
    cur = 1
for i in range(2,N+1):
    if cur<M and i==A[cur]:
        cur += 1
    else:
        dp[i] = (dp[i-1]+dp[i-2])%INFTY
print(dp[N])

Buggy submission (verdict: Runtime Error):
INFTY = 10**9+7
N,M = map(int,input().split())
A = [int(input()) for _ in range(M)]
dp = [0 for _ in range(N+1)]
dp[0] = 1
dp[1] = 1
cur = 0
if A[0]==1:
    dp[1] = 0
    cur = 1
for i in range(2,N+1):
    if cur<M and i==A[cur]:
        cur += 1
    else:
        dp[i] = (dp[i-1]+dp[i-2])%INFTY
print(dp[N])
Problem p03038 (python)

Fixed submission:
N,M = map(int,input().split())
A = list(map(int,input().split()))
A = sorted(A)
B = [list(map(int,input().split())) for _ in range(M)]
B = sorted(B,key=lambda x:x[1],reverse=True)
cur = 0
cnt = 0
for i in range(N):
    if cnt==B[cur][0]:
        cur +=1
        if cur==M:break
        cnt = 0
    if B[cur][1]<=A[i]:
        break
    A[i] = B[cur][1]
    cnt += 1
print(sum(A))

Buggy submission (verdict: Runtime Error):
N,M = map(int,input().split())
A = list(map(int,input().split()))
A = sorted(A)
B = [list(map(int,input().split())) for _ in range(M)]
B = sorted(B,key=lambda x:x[1],reverse=True)
cur = 0
cnt = 0
for i in range(N):
    if cnt==B[cur][0]:
        cur +=1
        cnt = 0
    if B[cur][1]<=A[i]:
        break
    A[i] = B[cur][1]
    cnt += 1
print(sum(A))
Problem p03201 (python)

Fixed submission:
from bisect import bisect_left
N = int(input())
A = sorted(list(map(int,input().split())))
A = [[A[i],0] for i in range(N)]
cnt = 0
for i in range(N-1,0,-1):
    if A[i][1]==0:
        a = A[i][0]
        A[i][1]=1
        k = 0
        while 2**k<=a:
            k += 1
        b = 2**k-a
        ind = bisect_left(A,[b,1])
        ind -= 1
        if ind<i and A[ind]==[b,0]:
            A[ind][1]=1
            cnt += 1
print(cnt)

Buggy submission (verdict: Runtime Error):
from bisect import bisect_left
N = int(input())
A = sorted(list(map(int,input().split())))
G = {}
for i in range(N-1,0,-1):
    a = A[i]
    kmin = 0
    while 2**kmin<=a:
        kmin += 1
    kmax = 0
    while 2**kmax<=2*a:
        kmax += 1
    for k in range(kmin,kmax):
        b = 2**k-a
        ind = bisect_left(A[:i],b)
        if A[ind]==b and ind<i:
            if 2**k not in G:
                G[2**k] = []
            G[2**k].append((i,ind))
            ind += 1
            while A[ind]==b:
                G[2**k].append((i,ind))
                ind += 1
C = sorted([[a,len(G[a])] for a in G],key=lambda x:x[1],reverse=True)
hist = [0 for _ in range(N)]
cnt = 0
for c in C:
    a,_ = c
    for x in G[a]:
        i,j = x
        if hist[i]==0 and hist[j]==0:
            cnt += 1
            hist[i] = 1
            hist[j] = 1
print(cnt)