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

Fixed submission:
from heapq  import heappush, heappop

N,M=map( int, raw_input().split() )
S="z"+raw_input()
num=[ [ 0 for i in range(2) ] for j in range(N+1) ] 

nl= [ [] for j in range(N+1) ] 

deleted=[ 0 for j in range(N+1) ] 

for i in range(M):
	a,b=map( int, raw_input().split() )
	if not b in nl[a]:
		nl[a].append(b)
		nl[b].append(a)
		if S[b]=="A":  num[a][0]+=1
		elif S[b]=="B":  num[a][1]+=1
		if S[a]=="A":  num[b][0]+=1
		elif S[a]=="B":  num[b][1]+=1

hq=[]

for i in range(1,N+1):
	if num[i][0]==0 or num[i][1]==0:
		heappush(hq,i)



while hq:
	x=heappop(hq)
	if deleted[x]==1: continue
	if num[x][0]==0 or num[x][1]==0:

		deleted[x]=1
		for u in nl[x]:
			if deleted[u]==0:
				if S[x]=="A": num[u][0]-=1						
				elif S[x]=="B": num[u][1]-=1
			
		#	print "x,u,num:::",x,u,num
			if ( num[u][0]==0 or num[u][1]==0 ) and deleted[u]==0:
				heappush(hq,u)
			#	print "x,u,hq:::",x,u,hq

				

	

#print "num:::",num
#print "deleted:::",deleted
#print "nl:::",nl

if sum(deleted[1:])==N:
	print "No"
else:
	print "Yes"

Buggy submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(1000000)
N,M=map( int, raw_input().split() )
S=raw_input()

C=[ [0 for i in range(2) ] for j in range(N+1)  ] 	#C[i][0] A no kazu , C[i][1] B no kazu
nl=[ set() for i in range(N+1) ]
D=[ 0 for i in range(N+1) ]		#Mukouka flag   1:delete

for i in range(M):
	a,b=map(int, raw_input().split() )
	nl[a].add(b)
	nl[b].add(a)

	if a==b:
		if S[a-1]=="A": 
			C[a][0]+=1			
		elif S[a-1]=="B":
			C[a][1]+=1			
	else:
		if S[a-1]=="A": 
			C[b][0]+=1
		elif S[a-1]=="B":
			C[b][1]+=1
		if S[b-1]=="A": 
			C[a][0]+=1
		elif S[b-1]=="B":
			C[a][1]+=1


def func(i):
	print "i,C::",i,C,nl
	if D[i]==1: return
	a_cnt=C[i][0]
	b_cnt=C[i][1]

	if a_cnt==0 or b_cnt==0:
		D[i]=1	#Mukouka flag wo on
		for x in nl[i]:
			if D[x]==1: continue

			if a_cnt>0: C[x][0]-=1;C[i][0]-=1
			elif b_cnt>0: C[x][1]-=1;C[i][1]-=1
			if C[x][0]==0 or C[x][1]==0:
				func(x)


for i in range(1,N+1):
	func(i)



for i,x in enumerate(D):
	if i==0:continue
	if x==0:
		for u in nl[i]:
			if D[u]==0:
				print "Yes"
				quit()
else:
	print "No"

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

C=[ [0 for i in range(2) ] for j in range(N+1)  ] 
nl=[ set() for i in range(N+1) ]
D=[ 0 for i in range(N+1) ]		#Mukouka flag   1:delete

for i in range(M):
	a,b=map(int, raw_input().split() )
	nl[a].add(b)
	nl[b].add(a)

	if a==b:
		if S[a-1]=="A": 
			C[a][0]+=1			
		elif S[a-1]=="B":
			C[a][1]+=1			
	else:
		if S[a-1]=="A": 
			C[b][0]+=1
		elif S[a-1]=="B":
			C[b][1]+=1
		if S[b-1]=="A": 
			C[a][0]+=1
		elif S[b-1]=="B":
			C[a][1]+=1


def func(i):
	if D[i]==1: return
	a_cnt=C[i][0]
	b_cnt=C[i][1]

	if a_cnt==0 or b_cnt==0:
		D[i]=1	#Mukouka flag wo on
		for x in nl[i]:
			if D[x]==1: continue

			if a_cnt>0: C[x][0]-=1;C[i][0]-=1
			elif b_cnt>0: C[x][1]-=1;C[i][1]-=1
			if C[x][0]==0 or C[x][1]==0:
				func(x)


for i in range(1,N+1):
	func(i)



for i,x in enumerate(D):
	if i==0:continue
	if x==0:
		for u in nl[i]:
			if D[u]==0:
				print "Yes"
				quit()
else:
	print "No"
Problem p03274 (python)

Fixed submission:
N,K=map(  int,raw_input().split() )
X=map(  int,raw_input().split() )

ans=float("inf")
t=float("inf")
for l in range(N-K+1):
	r=l+K-1
	if X[l]<0:
		if X[r]<0:	
			ans=min(ans, abs(X[l]) )
		else:	
			ans=min(ans, 2*abs(X[l])+abs(X[r]) , abs(X[l])+2*abs(X[r]) )
	elif X[l]>=0 and X[r]>=0:
		ans=min(ans, X[r] )


print ans

Buggy submission (verdict: Runtime Error):
import bisect
N,K=map(  int,raw_input().split() )
X=map(  int,raw_input().split() )
 
zero_idx=bisect.bisect_left(X,0)
 
t=float("inf")
ans=float("inf")
for i in range(zero_idx):
	if zero_idx-i>K:
		continue
	elif zero_idx-i==K:
		t=X[i]
	else:
		nokori_cnt=K-(zero_idx-i)
		t=2*abs(X[i])+X[zero_idx+nokori_cnt-1]
	ans=min(ans,t)	

for i in range(zero_idx,N):
	if i==zero_idx+K-1:
		t=X[i]
	elif i<zero_idx+K-1:
		nokori_cnt=K-(i-zero_idx)-1
		t=2*X[i]+abs(X[zero_idx-nokori_cnt])
	ans=min(ans,t)

print ans

Buggy submission (verdict: Runtime Error):
import bisect
N,K=map(  int,raw_input().split() )
X=map(  int,raw_input().split() )
 
zero_idx=bisect.bisect_left(X,0)
 
t=float("inf")
ans=float("inf")
for i in range(zero_idx):
	if zero_idx-i==K:
		t=X[i]
	else:
		nokori_cnt=K-(zero_idx-i)
		t=2*abs(X[i])+X[zero_idx+nokori_cnt-1]
	ans=min(ans,t)	

for i in range(zero_idx,N):
	if i==zero_idx+K-1:
		t=X[i]
	elif i<zero_idx+K-1:
		nokori_cnt=K-(i-zero_idx)-1
		t=2*X[i]+abs(X[zero_idx-nokori_cnt])
	ans=min(ans,t)

print ans

Buggy submission (verdict: Runtime Error):
import bisect
N,K=map(  int,raw_input().split() )
X=map(  int,raw_input().split() )

zero_idx=bisect.bisect_left(X,0)


ans=float("inf")
for i in range( max(0,zero_idx-K+1) , min(N,zero_idx+K) ):
	if i < zero_idx:
		if zero_idx-i==K:
			t=X[i]
		else:
			t=2*abs(X[i])+X[K-(zero_idx-i)-1+zero_idx]
	elif i>=zero_idx:
		if i-zero_idx==K-1:
			t=X[i]
		else:
			t=2*X[i]+ abs( X[zero_idx- ( K-(i-zero_idx+1) )] )
	ans=min(ans,t)

print ans

Buggy submission (verdict: Runtime Error):
import bisect
N,K=map(  int,raw_input().split() )
X=map(  int,raw_input().split() )

zero_idx=bisect.bisect_left(X,0)


ans=float("inf")
for i in range(zero_idx-K+1, min(N,zero_idx+K) ):
	if i < zero_idx:
		if zero_idx-i==K:
			t=X[i]
		else:
			t=2*abs(X[i])+X[K-(zero_idx-i)-1+zero_idx]
	elif i>=zero_idx:
		if i-zero_idx==K-1:
			t=X[i]
		else:
			t=2*X[i]+ abs( X[zero_idx- ( K-(i-zero_idx+1) )] )
	ans=min(ans,t)

print ans
Problem p03305 (python)

Fixed submission:
import heapq
 
N,M,S,T = map(int,input().split())
S,T = S-1,T-1
src = [tuple(map(int,input().split())) for i in range(M)]
 
es = [[] for i in range(N)]
for u,v,a,b in src:
    u,v = u-1,v-1
    es[u].append((v,a,b))
    es[v].append((u,a,b))
 
INF = float('inf')
cy = [INF] * N
cy[S] = 0
hq = [(0,S)]
heapq.heapify(hq)
while hq:
    cost,v = heapq.heappop(hq)
    for to,a,b in es[v]:
        if cost + a >= cy[to]: continue
        cy[to] = cost + a
        heapq.heappush(hq, (cy[to],to))
 
cs = [INF] * N
cs[T] = 0
hq = [(0,T)]
heapq.heapify(hq)
while hq:
    cost,v = heapq.heappop(hq)
    for to,a,b in es[v]:
        if cost + b >= cs[to]: continue
        cs[to] = cost + b
        heapq.heappush(hq, (cs[to],to))
 
ans = [INF]
for i in reversed(range(N)):
    tmp = cs[i] + cy[i]
    ans.append(min(ans[-1],tmp))
 
for a in reversed(ans[1:]):
    print(10**15 - a)

Buggy submission (verdict: Runtime Error):
import  heapq

n,m,s,t=map(int,raw_input().split())

nl=[ [ ] for j in range(n+1) ] 

for i in range(m):
	u,v,a,b=map(int,raw_input().split())
	nl[u].append( (v,a,b) )
	nl[v].append( (u,a,b) )


def dij(v,type):
	d=[ float("inf") for i  in range(n+1)]
	d[v]=0

	Q=[]
	heapq.heappush(Q,v)

	while Q:
		u=heapq.heappop(Q)
		for i in nl[u]:
			v=i[0]
			yen=i[1]
			sunuku=i[2]
			if type=="y":alt=d[u]+yen
			elif type=="s":alt=d[u]+sunuku

			if d[v]> alt:
				d[v]=alt
				heapq.heappush(Q,v)
	return d

d_y=dij(s,"y")
d_s=dij(t,"s")

val=float("inf")

A=[]
for i in range(n,0,-1):
	tmp=d_y[i]+d_s[i]
	val=min(val, tmp)
	A.append(val)

for i in reversed(A):
	print 10**15-i
Problem p03380 (python)

Fixed submission:
import math
n=input()
a=map(int, raw_input().split())
a.sort()
a.reverse()


c=a[0]

b=[0 for i in range(n)]
for i in range(1,n):
	b[i]=abs(a[i]-c/2)

min_b=min(b[1:])

d=[]
for i in range(1,n):
	if b[i]==min_b:
		d.append(a[i])

d.sort()
d.reverse()

print c,d[0]

Buggy submission (verdict: Runtime Error):
import math
n=input()
a=map(int, raw_input().split())
a.sort()
a.reverse()

def comb(N,R):
	#return math.factorial(N)/( math.factorial(N-R)*math.factorial(R) )
	if N-R>=R: t=R
	else:	t=N-R

	bunbo=1
	bunshi=1
	for i in range(1,t+1):
		bunbo*=(N-i+1)
		bunshi*=i
	return bunbo/bunshi


l=1
r=n-1
c=a[0]
for i in range(20):
	if comb(c,a[(l*2+r)/3]) > comb(c,a[(l+r*2)/3]):
		r=(l+r*2)/3
	else:
		l=(l*2+r)/3


if comb(c,a[(l*2+r)/3]) > comb(c,a[(l+r*2)/3]):
	print c,a[(l*2+r)/3]
else:
	print c,a[(l+r*2)/3]
Problem p03386 (python)

Fixed submission:
A,B,K=map(int, raw_input().split())
c=set()
for i in range(A,min(B+1,A+K)):
	c.add(i)

for i in range(B,max(A-1,B-K),-1):
	c.add(i)


a=list(c)
a.sort()
for i in a:
	print i

Buggy submission (verdict: Runtime Error):
A,B,K=map(int, raw_input().split())
l=range(A,B+1)
d=len(l)

if d/2>=K:
	for i in l[:K]:
		print i
	for i in l[-1*K:]:
		print i
elif d/2<K and K<d:
	for i in l[:K]:
		print i
	for i in l[ K-d:]:
		print i
else:
	for i in l:
		print i

Buggy submission (verdict: Runtime Error):
A,B,K=map(int, raw_input().split())
l=range(A,B+1)

if len(l)/2>=K:
	for i in l[:K]:
		print i
	for i in l[-1*K:]:
		print i
elif len(l)/2<K and K<len(l):
	for i in l[:K]:
		print i
	for i in l[ K-len(l):]:
		print i
else:
	for i in l:
		print i

Buggy submission (verdict: Runtime Error):
A,B,K=map(int, raw_input().split())
l=range(A,B+1)

if len(l)/2>=K:
	for i in l[:K]:
		print i
	for i in l[-K:]:
		print i
#elif len(l)/2<K and K<len(l):
#	for i in l[:K]:
#		print i
#	for i in l[ K-len(l):]:
#		print i
else:
	for i in l:
		print i

Buggy submission (verdict: Runtime Error):
A,B,K=map(int, raw_input().split())
l=range(A,B+1)

if len(l)/2>=K:
	for i in l[:K]:
		print i
	for i in l[-K:]:
		print i
elif len(l)/2<K and K<len(l):
	for i in l[:K]:
		print i
	for i in l[ K-len(l):]:
		print i
else:
	for i in l:
		print i

Buggy submission (verdict: Runtime Error):
A,B,K=map(int, raw_input().split())
l=range(A,B+1)

if len(l)/2>=K:
	for i in l[:K]:
		print i
	for i in l[-K:]:
		print i
elif len(l)/2<K and K<len(l):
	for i in l[:K]:
		print i
	for i in l[ ( K-(2*K-len(l)) )*-1:]:
		print i
else:
	for i in l:
		print i

Buggy submission (verdict: Runtime Error):
A,B,K=map(int, raw_input().split())
l=range(A,B+1)

if len(l)/2>=K:
	for i in l[:K]:
		print i
	for i in l[-K:]:
		print i
elif len(l)/2<K and K<len(l):
	for i in l[:K]:
		print i
	for i in l[ ( K-(2*K-len(l)) )*-1:]:
		print i
elif len(l)/2<K and K>=len(l):
	for i in l:
		print i
Problem p03394 (python)

Fixed submission:
N=input()

if N==3:
	print "2 5 63"
	quit()
elif N==4:
	print "2 5 20 63"
	quit()

#N>=5
#For 2 and 3
S=[2,3,4]
N-=3


x=N/4	# N=4x+b
b=N%4

for i in range(1,x+1):
	S.append(6*i)
	S.append(6*i+2)
	S.append(6*i+3)
	S.append(6*i+4)


if x%2==0:
	if b==0:
		S.remove(6*x+3)
		S.append(6*x+6)
	elif b==1:
		S.append(6*(x+1)+3)
	elif b==2:
		S.append(6*(x+1))
		S.append(6*(x+1)+3)
	elif b==3:
		S.append(6*(x+1))
		S.append(6*(x+1)+3)
		S.append(6*(x+1)+6)
else:
	if b==0:
		pass
	elif b==1:
		S.append(6*(x+1))
	elif b==2:
		S.append(6*(x+1)+2)
		S.append(6*(x+1)+4)
	elif b==3:
		S.append(6*(x+1))
		S.append(6*(x+1)+2)
		S.append(6*(x+1)+4)	

for i in S:
	print i,

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

if N==3:
	print "2 5 63"
	quit()
elif N==4:
	print "2 5 20 63"
	quit()

#N>=5
#For 2 and 3
S=[2,3,4]
N-=3


x=N/4	# N=4x+b
b=N%4

for i in range(1,x+1):
	S.append(6*i)
	S.append(6*i+2)
	S.append(6*i+3)
	S.append(6*i+4)

if x%2==0:
	if b==0:
		pass
	elif b==1:
		S.append(6*(x+1)+3)
	elif b==2:
		S.append(6*(x+1))
		S.append(6*(x+1)+3)
	elif b==3:
		S.append(6*(x+1))
		S.append(6*(x+1)+3)
		S.append(6*(x+1)+6)
else:
	if b==0:
		S.remove(6*x+3)
		S.remove(6*x+6)
	elif b==1:
		S.append(6*(x+1))
	elif b==2:
		S.append(6*(x+1)+2)
		S.append(6*(x+1)+4)
	elif b==3:
		S.append(6*(x+1))
		S.append(6*(x+1)+2)
		S.append(6*(x+1)+4)	

for i in S:
	print i,
Problem p03409 (python)

Fixed submission:
N=input()
a=[]
for i in range(2*N):
	x,y=map(int, raw_input().split())
	if i<N: a.append([x,y,"R"])
	else: a.append([x,y,"B"])

b=sorted(a, key=lambda x: x[0], reverse=True)


q=[]
ans=0
for i in b:
	x=i[1]
	type=i[2]
	if type=="B":
		q.append(x)
	elif type=="R" and len(q)>0:
		up=0
		tmp=[]
		for j in q:
			if x<=j:
				tmp.append(j)
				up=1
		ans+=up
		if len(tmp)>0:
			val=min(tmp)
			q.remove(val)

print ans

Buggy submission (verdict: Runtime Error):
N=input()
a=[]
for i in range(2*N):
	x,y=map(int, raw_input().split())
	if i<N: a.append([x,y,"R"])
	else: a.append([x,y,"B"])

b=sorted(a, key=lambda x: x[0], reverse=True)


q=[]
ans=0
for i in b:
	x=i[1]
	type=i[2]
	if type=="B":
		q.append(x)
	elif type=="R" and len(q)>0:
		up=0
		tmp=[]
		for j in q:
			if x<=j:
				tmp.append(j)
				up=1
		else:
			ans+=up
		val=min(tmp)
		q.remove(val)

print ans
Problem p03436 (python)

Fixed submission:
from collections import deque
H,W=map(int,raw_input().split())
c=[]
for i in range(H):
	s=list(raw_input())
	for j in s:
		if j=="#":
			c.append(1)
		else:
			c.append(0)


nl=[ [] for i in range(H*W)]

p0=[-1,1,W]
p1=[-W,1,W]
p2=[-W,-1,W]
p3=[-W,-1,1]
p4=[-W,-1,1,W]
for i in range(H*W):
	if c[i]==0:
		if i==0:
			if c[i+1]==0:nl[i].append(i+1)
			if c[i+W]==0:nl[i].append(i+W)
		elif i==W-1:
			if c[i-1]==0:nl[i].append(i-1)
			if c[i+W]==0:nl[i].append(i+W)
		elif i==W*(H-1):
			if c[i-W]==0:nl[i].append(i-W)
			if c[i+1]==0:nl[i].append(i+1)		
		elif i==W*H-1:
			if c[i-W]==0:nl[i].append(i-W)
			if c[i-1]==0:nl[i].append(i-1)
		elif i<W-1:
			for j in p0:
				if c[i+j]==0:nl[i].append(i+j)			
		elif i%W==0:
			for j in p1:
				if c[i+j]==0:nl[i].append(i+j)	
		elif i%W==W-1:
			for j in p2:
				if c[i+j]==0:nl[i].append(i+j)
		elif i>W*(H-1):
			for j in p3:
				if c[i+j]==0:nl[i].append(i+j)
		else:
			for j in p4:
				if c[i+j]==0:nl[i].append(i+j)


V=[ None for i in range(H*W)]
d=[ float("inf") for i in range(H*W) ]

def bfs(start):
	q = deque([]) 
	V[start]=1
	d[start]=0
	q.append(start)

	while len(q)!=0:
		v=q.popleft()
		for i in nl[v]:
			if V[i] is None:
				V[i]=1
				q.append(i)
				d[i]=d[v]+1

bfs(0)

if V[H*W-1] is None:
	print -1
else:
	print H*W-(d[H*W-1]+1)-sum(c)

Buggy submission (verdict: Runtime Error):
from collections import deque
H,W=map(int,raw_input().split())
c=[]
for i in range(H):
	s=list(raw_input())
	for j in s:
		if j=="#":
			c.append(1)
		else:
			c.append(0)


nl=[ [] for i in range(H*W)]

p0=[-1,1,3]
p1=[-3,1,3]
p2=[-3,-1,3]
p3=[-3,-1,1]
p4=[-3,-1,1,3]
for i in range(H*W):
	if c[i]==0:
		if i==0:
			if c[i+1]==0:nl[i].append(i+1)
			if c[i+W]==0:nl[i].append(i+W)
		elif i==W-1:
			if c[i-1]==0:nl[i].append(i-1)
			if c[i+W]==0:nl[i].append(i+W)
		elif i==W*(H-1):
			if c[i-W]==0:nl[i].append(i-W)
			if c[i+1]==0:nl[i].append(i+1)		
		elif i==W*H-1:
			if c[i-W]==0:nl[i].append(i-W)
			if c[i-1]==0:nl[i].append(i-1)
		elif i<W-1:
			for j in p0:
				if c[i+j]==0:nl[i].append(i+j)			
		elif i%W==0:
			for j in p1:
				if c[i+j]==0:nl[i].append(i+j)	
		elif i%W==W-1:
			for j in p2:
				if c[i+j]==0:nl[i].append(i+j)
		elif i>W*(H-1):
			for j in p3:
				if c[i+j]==0:nl[i].append(i+j)
		else:
			for j in p4:
				if c[i+j]==0:nl[i].append(i+j)
				

V=[ None for i in range(H*W)]

def dfs(start):
	q = deque([]) 
	V[start]=1
	q.append(start)

	while len(q)!=0:
		v=q.pop()
		V[v]=1
		if H*W-1 in nl[v]:
			V[H*W-1]=1
			return

		for i in nl[v]:
			if V[i] is None:
				q.append(i)

dfs(0)
print len( filter(lambda x:x is None, V) ) - sum(c)
Problem p03480 (python)

Fixed submission:
S=raw_input()
N=len(S)
TS=N
for k in range(N-1):
	if S[k]!=S[k+1]:
		TS=min(TS, max(k+1, N-k-1))

print TS

Buggy submission (verdict: Runtime Error):
S=raw_input()
N=len(S)
n=len(S)/2
if N%2==1: c=n	# c:center

cnt=0
for i in range(1,n+1):
	if N%2==1:
		if S[c-i]==S[c+i]==S[c]:
			cnt=1+2*i
			pass
		else:
			if i==n:
				cnt+=1
			break
	else:	
		if S[n-i]==S[n+i]:
			cnt=2*n
		else:
			break
if N%2==1:
	print max(n+1,cnt)
else:
	print max(n, cnt)

Buggy submission (verdict: Runtime Error):
S=raw_input()
c=[]
cnt=0
for i in S:
	if i=="0":
		cnt+=1
	else:
		if cnt!=0:
			c.append(cnt)
			cnt=0
else:
	if cnt!=0:
		c.append(cnt)

if len(c)==1:
	print c[0]
else:
	print max(c)+1
Problem p03496 (python)

Fixed submission:
import sys
N=input()
#print N
a=[]
a=map(int,raw_input().split())
#print a

if max(a)==min(a):
	print 0
	sys.exit()
elif abs(max(a))>abs(min(a)):
	num=(max(a),a.index(max(a)))
else:
	num=(min(a),a.index(min(a)))
#print num

ans=[]
for i in range(N):
	a[i]+=num[0]
	ans.append((num[1]+1,i+1))

if num[0]>=0:
	for i in range(N-1):
		ans.append((i+1,i+2))
else:
	for i in range(N,1,-1):
		ans.append((i,i-1))

print len(ans)
for i,j in ans:
	print i,j

Buggy submission (verdict: Runtime Error):
import heapq
N=input()
#print N
a=[]
a=map(int,raw_input().split())
#print a

q1=[] #+
q2=[] #-
for ind,i in enumerate(a):
	if i>=0:
		heapq.heappush(q1, [-1*i,ind])
	else:
		heapq.heappush(q2, [i,ind])
#print "# q1"	
#print q1
#print "# q2"
#print q2

cnt=0
b=[]
for ind,i in enumerate(a):
	if ind==0:
		prev_i=i
		continue
	else:
		if prev_i<=i:
			prev_i=i
			continue
		else:
			#print ind,prev_i,i
			#while prev_i>i:
			if i<0 and prev_i<0:
				t_val=q2[0][0]
				#prev_i+=t_val
				cnt=cnt+(abs(i-prev_i)/t_val)+1
				#print (abs(i-prev_i)/t_val),cnt
				for i in range( (abs(i-prev_i)/t_val)+1 ):
					b.append((q2[0][1]+1,ind))
			else:
				t_val=q1[0][0]
				#i-=t_val
				cnt=cnt+(abs(i-prev_i)/t_val)+1
				#print cnt
				for i in range( (abs(i-prev_i)/t_val)+1 ):
					b.append((q1[0][1]+1,ind+1))

	

print cnt
#print b
for i,j in b:
	print i,j
Problem p03533 (python)

Fixed submission:
import sys
S=list(raw_input())
if len(S)>10:
	print "NO"
	sys.exit()

if "K" in S and "I" in S and "H" in S:
	pass
else:
	print "NO"
	sys.exit()
	
if S.index("K")+1!=S.index("I") or S.index("I")+1!=S.index("H"):
	print "NO"
	sys.exit()

for i in S:
	if i=="A":
		S.remove("A")


if ''.join(S)=="KIHBR":
	print "YES"
else:
	print "NO"

Buggy submission (verdict: Runtime Error):
import sys
S=list(raw_input())
if len(S)>10:
	print "NO"
	sys.exit()

if S.index("K")+1!=S.index("I") or S.index("I")+1!=S.index("H"):
	print "NO"
	sys.exit()

for i in S:
	if i=="A":
		S.remove("A")


if ''.join(S)=="KIHBR":
	print "YES"
else:
	print "NO"
Problem p03547 (python)

Fixed submission:
X,Y=raw_input().split()
if X<Y:
	print "<"
elif X>Y:
	print ">"
elif X==Y:
	print "="

Buggy submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-
import sys
sys.setrecursionlimit(10000000)

N,X,Y=map(int, sys.stdin.readline().split())
A=map(int, sys.stdin.readline().split())

memo={}
def func(n,last,turn):  #n:カードの残り枚数、last:前の手番が最後に引いたスコア、turn: 0先手の番 1後手の番
    #print "func(",n,",",last,",",turn,")"
    if (n,turn) in memo:    #カードの残り枚数と、どちらの手番かで最終スコアはいつも同じ
        return memo[(n,turn)]
    if n==1:
        ret=abs(last-A[N-n])
    elif turn==0:
        ret=max( func(n-1,last,0) , func(n-1,A[N-n],1) ) #手番がXのまま  手番がYに移動
    elif turn==1:
        ret=min( func(n-1,last,1) , func(n-1,A[N-n],0) ) #手番がYのまま  手番がXに移動
    memo[(n,turn)]=ret
    return ret


print func(N,Y,0)
Problem p03565 (python)

Fixed submission:
import sys
S0=raw_input()
T=list(raw_input())

l=len(T)

if len(S0)<len(T):
	print "UNRESTORABLE"
	sys.exit()


ans=""
for i in range(len(S0)-l+1):
	S1=list(S0)
	#print S1
	for j in range(l):
		#print i+j,j,S1[i+j],T[j]
		if S1[i+j]!=T[j] and S1[i+j]!="?":
			#print "break"
			break
	else:
		#print "else"
		for j in range(l):
			S1[i+j]=T[j]
		S_tmp=(''.join(S1)).replace('?','a')
		#print ans
		#print S_tmp
		if ans=="":
			ans=S_tmp
		if S_tmp < ans:
			ans=S_tmp
			
	
if ans=="":
	print "UNRESTORABLE"
	sys.exit()
else:
	print ans

Buggy submission (verdict: Runtime Error):
import sys
S0=raw_input()
T=list(raw_input())

l=len(T)


ans=""
for i in range(len(S0)-l+1):
	S1=list(S0)
	for j in range(l):
		#print i+j,j,S1[i+j],T[j]
		if S1[i+j]!=T[j] and S1[i+j]!="?":
			#print "break"
			break
	else:
		#print "else"
		for j in range(l):
			S1[i+j]=T[j]
		S_tmp=(''.join(S1)).replace('?','a')
		#print ans
		#print S_tmp
		if ans=="":
			ans=S_tmp
		if S_tmp < ans:
			ans=S_tmp
			
	
if S0==''.join(S1) and S0.find("?")!=-1:
	print "UNRESTORABLE"
	sys.exit()
	

print ans

Buggy submission (verdict: Runtime Error):
import sys
S0=raw_input()
T=list(raw_input())

l=len(T)


ans=""
for i in range(len(S0)-l+1):
	S1=list(S0)
	for j in range(l):
		#print i+j,j,S1[i+j],T[j]
		if S1[i+j]!=T[j] and S1[i+j]!="?":
			#print "break"
			break
	else:
		#print "else"
		for j in range(l):
			S1[i+j]=T[j]
		S_tmp=(''.join(S1)).replace('?','a')
		#print ans
		#print S_tmp
		if ans=="":
			ans=S_tmp
		if S_tmp < ans:
			ans=S_tmp
			
	
if S0==''.join(S1):
	print "UNRESTORABLE"
	sys.exit()
	

print ans

Buggy submission (verdict: Runtime Error):
import sys
S0=raw_input()
S1=list(S0)
T=list(raw_input())
#print S1
#print T

l=len(T)

S=[]

for i in range(3):
	for j in range(l):
		#print i+j,j,S1[i+j],T[j]
		if S1[i+j]!=T[j] and S1[i+j]!="?":
			#print "break"
			break
	else:
		#print "else"
		for j in range(l):
			S1[i+j]=T[j]
	
if S0==''.join(S1):
	print "UNRESTORABLE"
	sys.exit()
	

S2=''.join(S1)
print S2.replace('?','a')
Problem p03599 (python)

Fixed submission:
# -*- coding: utf-8 -*-
A,B,C,D,E,F=map(int, raw_input().split())
#print A,B,C,D,E,F

sugar_list=[0]*(F+1)
i=0
while i <= F :
	for j in range(F):
		val=C*i+D*j
		if val > F:
			break
		elif val <= F:
			sugar_list[val]=1
	i+=1

#print "# Sugar"
#print sugar_list

#Water
water_list=[0]*(F/100+1)
#print water_list
loop_cnt=F/100+1

i=0
while i <= loop_cnt:
	for j in range(loop_cnt):
		val=A*i+B*j
		if val > F/100:
			break
		else:
			#print i,j,val
			water_list[val]=1
	i+=1

#print "# Water"
#print water_list

max_noudo=float(E)/(100+E)
#print max_noudo


hwm=0
water_ans=A*100
sugar_ans=0
for i in range(1,len(water_list)):
	for j in range(len(sugar_list)):
		if water_list[i]*sugar_list[j]==1 and i*100+j<=F and j<=i*E:
			if float(j)/(i*100+j)>hwm:
				hwm=float(j)/(i*100+j)
				water_ans=i*100
				sugar_ans=j
				

print water_ans+ sugar_ans, sugar_ans

Buggy submission (verdict: Runtime Error):
A,B,C,D,E,F=map(int, raw_input().split())
noudo=int(float(E)/(100+E)*100)

a=[]
for i in range(noudo):
	for j in range(noudo):
		#print i,j
		if i*C+D*j<=noudo:
			a.append(i*C+D*j)

b=[]
cnt=F/100
for i in range(cnt):
	for j in range(cnt):
		if i*100+j*100<=F and i*100+j*100!=0:
			b.append(i*100+j*100)


noudo=float(E)/(100+E)*100
max_noudo=0
for i in a:
	for j in b:
		t_noudo=float(i)/(i+j)*100
		if t_noudo>max_noudo:
			max_noudo=t_noudo
			ans=i,j

print ans[0]+ans[1],ans[0]

Buggy submission (verdict: Runtime Error):
A,B,C,D,E,F=map(int, raw_input().split())
noudo=int(float(E)/(100+E)*100)

a=[]
for i in range(noudo):
	for j in range(noudo):
		#print i,j
		if i*C+D*j<=noudo:
			a.append(i*C+D*j)

b=[]
cnt=F/100
for i in range(cnt):
	for j in range(cnt):
		if i*100+j*100<=F and i*100+j*100!=0:
			b.append(i*100+j*100)


noudo=float(E)/(100+E)*100
max_noudo=0
for i in a:
	for j in b:
		t_noudo=float(i)/(i+j)*100
		if t_noudo>max_noudo:
			max_noudo=t_noudo
			ans=i,j

print ans[0],ans[1]
Problem p03611 (python)

Fixed submission:
import sys

N=input()
a=map(int, raw_input().split())
#print a
#print max(a)

dict={}


for i in range(len(a)):
	if a[i] in dict:
		dict[ a[i] ]+=1 
	else:
		dict[ a[i] ]=1

#print dict

max_sum=0
for key,value in dict.items():
	#print key,value
	sum=dict[key]
	if key-1 in dict:
		sum+=dict[key-1]
	if key+1 in dict:
		sum+=dict[key+1]

	if max_sum<sum:
		max_sum=sum

print max_sum

Buggy submission (verdict: Runtime Error):
import sys

N=input()
a=map(int, raw_input().split())
#print a
#print max(a)

dict={}


for i in range(len(a)):
	if a[i] in dict:
		dict[ a[i] ]+=1 
	else:
		dict[ a[i] ]=1
		#print dict


for j in range(max(a)):
	if not j in dict:
		dict[j]=0

#print dict

max_sum=0
for key,value in dict.items():
	if key==0:
		sum=dict[key]+dict[key+1]
	elif key==max(a):
		sum=dict[key-1]+dict[key]
	else:
		sum=dict[key-1]+dict[key]+dict[key+1]
	#print key,sum

	if max_sum<sum:
		max_sum=sum

print max_sum