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

Fixed submission:
from collections import deque
n, m = map(int, input().split())
connect = [[] for _ in range(n)]
for _ in range(m):
    a, b = map(lambda x: int(x)-1, input().split())
    connect[a].append(b)
    connect[b].append(a)

color = [-1]*n
color[0] = 0
explored = {0}
next = deque([0])
exploring =deque()
Yes = True
explored.add(0)
while next:
    now = next.popleft()
    for a in connect[now]:
        if color[a] != -1:
            if color[a] != (color[now]+1)%2:
                Yes = False
            continue
        color[a] = (color[now]+1)%2
        next.append(a)
        
        
    '''
    exploring.extend(connect[now])
    while exploring:
        a = exploring.popleft()
        if color[a] == -1:
            color[a]=(color[now]+1)%2
        elif color[a] == (color[now]+1)%2:
            pass
        else:
            Yes = False
        if a not in explored:
            next.append(a)
        explored.add(a)
        '''
if Yes:
    s=sum(color)
    print(s*(n-s)-m)
else:
    print(n*(n-1)//2-m)

Buggy submission (verdict: Runtime Error):
from collections import deque
n, m = map(int, input().split())
connect = [[] for _ in range(n)]
for _ in range(m):
    a, b = map(lambda x: int(x)-1, input().split())
    connect[a].append(b)
    connect[b].append(a)

color = [-1]*n
color[0] = 0
explored = {0}
next = deque(connect[0])
exploring =deque()
Yes = True
explored.add(0)
while next:
    now = next.popleft()
    exploring.extend(connect[now])
    while exploring:
        a = exploring.popleft()
        if color[a] == -1:
            color[a]=(color[now]+1)%2
        elif color[a] == (color[now]+1)%2:
            pass
        else:
            Yes = False
        if a not in explored:
            next.append(a)
        explored.add(a)
if -1 in color and Yes:
    fjasodjasodg


if Yes:
    s=sum(color)
    print(s*(n-s)-m)
else:
    print(n*(n-1)//2-m)

Buggy submission (verdict: Runtime Error):
from collections import deque
n, m = map(int, input().split())
connect = [[] for _ in range(n)]
for _ in range(m):
    a, b = map(lambda x: int(x)-1, input().split())
    connect[a].append(b)
    connect[b].append(a)

color = [-1]*n
color[0] = 0
explored = {0}
next = deque(connect[0])
exploring =deque()
Yes = True
explored.add(0)
while next:
    now = next.popleft()
    exploring.extend(connect[now])
    while exploring:
        a = exploring.popleft()
        if color[a] == -1:
            color[a]=(color[now]+1)%2
        elif color[a] == (color[now]+1)%2:
            pass
        else:
            Yes = False
        if a not in explored:
            next.append(a)
        explored.add(a)
if -1 in color:
    fjasodjasodg


if Yes:
    s=sum(color)
    print(s*(n-s)-m)
else:
    print(n*(n-1)//2-m)
Problem p02640 (python)

Fixed submission:
x,y = map(int, input().split())
if y % 2 == 1:
    print("No")
elif 2 * x <= y <= 4 * x:
    print("Yes")
else:
    print("No")

Buggy submission (verdict: Runtime Error):
x,y = int(input().split())
if y % 2 == 1:
    print("No")
elif 2 * x <= y <= 4 * x:
    print("Yes")
else:
    print("No")
Problem p03469 (python)

Fixed submission:
print("2018" + input()[4:])

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

for i in range(y // 10000 + 1):
    for j in range(y // 5000 + 1):
        k = n - i - j
        if 0 <= k and 10000 * i + 5000 * j + 1000 * k == y:
            print(i,j,k,sep=" ")
            exit()
print("-1 " + "-1" + " -1")
Problem p03567 (python)

Fixed submission:
s = input()
flag = 0
for i in range(len(s) - 1):
    if s[i] == "A":
        if s[i + 1] == "C":
            flag = 1
if flag == 1:
    print("Yes")
else:
    print("No")

Buggy submission (verdict: Runtime Error):
s = input()
flag = 0
for i in range(len(s)):
    if s[i] == "A":
        if s[i + 1] == "C":
            flag = 1
if flag == 1:
    print("Yes")
else:
    print("No")
Problem p02601 (python)

Fixed submission:
import sys
import itertools
import copy
ORG=map(int, sys.stdin.readline().split())
K=int(sys.stdin.readline().strip())
L=list( itertools.product(range(3), repeat=K) )

for l in L:
    ABC=copy.deepcopy(ORG)
    for x in l:
        ABC[x]*=2
    if ABC[0]<ABC[1]<ABC[2]:
        print "Yes"
        quit()
else:
    print "No"

Buggy submission (verdict: Runtime Error):
import sys
import itertools
import copy
ORG=map(int, sys.stdin.readline().split())
K=int(sys.stdin.readline().strip())
L=list( itertools.product(range(3), repeat=K) )

for x in L:
    ABC=copy.deepcopy(ORG)
    ABC[x[0]]*=2
    ABC[x[1]]*=2
    ABC[x[2]]*=2
    if ABC[0]<ABC[1]<ABC[2]:
        print "Yes"
        quit()
else:
    print "No"
Problem p02609 (python)

Fixed submission:
# -*- coding: utf-8 -*-
import sys
N=int(sys.stdin.readline().strip())
X=sys.stdin.readline().strip()

cnt_of_one=0
for x in X:
    if x=="1": cnt_of_one+=1

cnt_of_one_plus_one=cnt_of_one+1
cnt_of_one_minus_one=cnt_of_one-1

amari_cnt_of_one_plus_one=0
amari_cnt_of_one_minus_one=0
for i,x in enumerate(X[::-1]):
    if x=="1":    #その桁の値が1の時だけ数を足す
        amari_cnt_of_one_plus_one+=pow(2,i,cnt_of_one_plus_one)
        amari_cnt_of_one_plus_one%=cnt_of_one_plus_one
        if cnt_of_one_minus_one==0: #2進数の全ての桁が0の場合は、0で除算はできないので場合分け
            amari_cnt_of_one_minus_one=0
        else:
            amari_cnt_of_one_minus_one+=pow(2,i,cnt_of_one_minus_one)
            amari_cnt_of_one_minus_one%=cnt_of_one_minus_one

def popcount(n):
    ret=0
    while 0<n:
        ret+=n%2
        n/=2
    return ret

def f(n):
    ret=0   #余りが0になるまでの割った回数
    while 0<n:
        n%=popcount(n)
        ret+=1
    return ret

for i,x in enumerate(X):
    keta=N-i-1
    if x=="0":
        syoki_amari=(amari_cnt_of_one_plus_one+pow(2,keta,cnt_of_one_plus_one))%cnt_of_one_plus_one
        if syoki_amari==0:
            print 1
        else:
            print 1+f(syoki_amari)
    elif x=="1":
        if cnt_of_one_minus_one==0: #2進数の全ての桁が0という意味だから
            print 0 #値が0になるまでの操作回数は0回
        else:
            syoki_amari=(amari_cnt_of_one_minus_one-pow(2,keta,cnt_of_one_minus_one))%cnt_of_one_minus_one
            if syoki_amari==0:
                print 1
            else:
                print 1+f(syoki_amari)

Buggy submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-
import sys
N=int(sys.stdin.readline().strip())
X=sys.stdin.readline().strip()

cnt_of_one=0
for x in X:
    if x=="1": cnt_of_one+=1

cnt_of_one_plus_one=cnt_of_one+1
cnt_of_one_minus_one=cnt_of_one-1

amari_cnt_of_one_plus_one=0
amari_cnt_of_one_minus_one=0
for i,x in enumerate(X[::-1]):
    if x=="1":    #その桁の値が1の時だけ数を足す
        amari_cnt_of_one_plus_one+=pow(2,i,cnt_of_one_plus_one)
        amari_cnt_of_one_plus_one%=cnt_of_one_plus_one
        amari_cnt_of_one_minus_one+=pow(2,i,cnt_of_one_minus_one)
        amari_cnt_of_one_minus_one%=cnt_of_one_minus_one

def popcount(n):
    ret=0
    while 0<n:
        ret+=n%2
        n/=2
    return ret

def f(n):
    ret=0   #余りが0になるまでの割った回数
    while 0<n:
        n%=popcount(n)
        ret+=1
    return ret

for i,x in enumerate(X):
    keta=N-i-1
    if x=="0":
        syoki_amari=(amari_cnt_of_one_plus_one+pow(2,keta,cnt_of_one_plus_one))%cnt_of_one_plus_one
        if syoki_amari==0:
            print 1
        else:
            print 1+f(syoki_amari)
    elif x=="1":
        syoki_amari=(amari_cnt_of_one_minus_one-pow(2,keta,cnt_of_one_minus_one))%cnt_of_one_minus_one
        if syoki_amari==0:
            print 1
        else:
            print 1+f(syoki_amari)
Problem p02788 (python)

Fixed submission:
# -*- coding: utf-8 -*-
import sys
from collections import deque

N,D,A=map(int, sys.stdin.readline().split())
XH=[ map(int, sys.stdin.readline().split()) for _ in range(N) ]
XH.sort()

q=deque()   #攻撃が無効となる座標、攻撃から差し引くポイント
ans=0
cnt=0

attack_point=0
for x,h in XH:
    while q:
        if x<q[0][0]:break
        end_x,end_point=q.popleft()
        attack_point-=end_point

    if h<=attack_point:
        pass
    else:
        if h%A==0:
            cnt=(h-attack_point)/A
        else:
            cnt=(h-attack_point)/A+1
        attack_point+=cnt*A
        q.append((x+2*D+1,cnt*A))
        ans+=cnt

print ans

Buggy submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-
import sys
from collections import deque

N,D,A=map(int, sys.stdin.readline().split())
XH=[ map(int, sys.stdin.readline().split()) for _ in range(N) ]
XH.sort()

q=deque()   #（攻撃が無効となる座標、攻撃によるポイント）
ans=0
cnt=0

attack_point=0
for x,h in XH:
    while q:
        if x<q[0][0]:break  #無効となる攻撃がない場合はwhileを終了
        end_x,end_point=q.popleft()
        attack_point-=end_point 　#攻撃が無効となる座標<=現在の座標があれば、その攻撃のポイントを引く

    if h<=attack_point: #モンスターの体力よりも攻撃で減らせるポイントの方が大きければ新規攻撃は不要
        pass
    else:   #新規攻撃が必要な場合
        if h%A==0:
            cnt=(h-attack_point)/A  #モンスターの大量をゼロ以下にするために何回攻撃が必要か
        else:
            cnt=(h-attack_point)/A+1
        attack_point+=cnt*A
        q.append((x+2*D+1,cnt*A))   #（攻撃が無効となる座標、攻撃によるポイント）をキューに入れる
        ans+=cnt

print ans
Problem p02803 (python)

Fixed submission:
# -*- coding: utf-8 -*-
import sys
from collections import deque
from collections import defaultdict
 
H,W=map(int, sys.stdin.readline().split())
S=[ sys.stdin.readline().strip() for _ in range(H) ]
 
D=[(1,0),(-1,0),(0,1),(0,-1)]
 
def bfs(start):
    Visit={}
    q=deque()
    q.append(start)
    L=defaultdict(lambda: float("inf")) 
    L[start]=0
 
    while q:
        fro_x,fro_y=q.popleft()
        for dx,dy in D:
            to_x=fro_x+dx
            to_y=fro_y+dy
            alt=L[(fro_x,fro_y)]+1
            if 0<=to_x<H and 0<=to_y<W:
                if S[to_x][to_y]=="." and alt<L[(to_x,to_y)]:
                    L[(to_x,to_y)]=alt
                    q.append((to_x,to_y))
    return max(L.values())
 
ans=0
for h in range(H):
    for w in range(W):
        if S[h][w]==".":
            ans=max(ans,bfs((h,w)))
print ans

Buggy submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-
import sys
from collections import deque
from collections import defaultdict

H,W=map(int, sys.stdin.readline().split())
S=[ sys.stdin.readline().strip() for _ in range(H) ]

D=[(1,0),(-1,0),(0,1),(0,-1)]

def bfs(start):
    Visit={}
    q=deque()
    q.append(start)
    Visit[start]=1
    L=defaultdict(lambda: 0)    #距離

    while q:
        fro_x,fro_y=q.popleft()
        for dx,dy in D:
            to_x=fro_x+dx
            to_y=fro_y+dy
            if 0<=to_x<H and 0<=to_y<W:
                if S[to_x][to_y]=="." and (to_x,to_y) not in Visit:
                    Visit[to_x,to_y]=1
                    L[(to_x,to_y)]=L[(fro_x,fro_y)]+1
                    q.append((to_x,to_y))

    return max(L.values())

ans=0
for h in range(H):
    for w in range(W):
        ans=max(ans,bfs((h,w)))

print ans
Problem p02843 (python)

Fixed submission:
# -*- coding: utf-8 -*-
import copy

X=input()

C={}    #n円を構成する品物の最小個数の集合

for n in range(100):
    org_n=copy.deepcopy(n)
    kosu=0     #n円を構成する品物の最小個数
    for i in range(5,0,-1):     
        kosu+=n/i
        n=n%i   #iで割った余りが残る
        if n==0:
            C[org_n]=kosu
            break

max_kosu=X/100
x=X%100

if max_kosu>=C[x]:
    print 1
else:
    print 0

Buggy submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-
import copy

X=input()

C={}    #n円を構成する品物の最小個数の集合

for n in range(1,100):
    org_n=copy.deepcopy(n)
    kosu=0     #n円を構成する品物の最小個数
    for i in range(5,0,-1):     
        kosu+=n/i
        n=n%i   #iで割った余りが残る
        if n==0:
            C[org_n]=kosu
            break


max_kosu=X/100
x=X%100

if max_kosu>=C[x]:
    print 1
else:
    print 0
Problem p02913 (python)

Fixed submission:
# -*- coding: utf-8 -*-
from collections import defaultdict
N=input()
s=raw_input()

str="abcdefghijklmnopqrstuvwxyz"
D={}
for i,str in enumerate(str):
	D[str]=i+1

base=27
mod=2**61-1
hash=[]

for i,x in enumerate(s):
	if i==0: hash.append(D[x]%mod)
	else: hash.append( (hash[-1]*base+D[x])%mod )

def get(l,r):
	if l==0: return hash[r-1]%mod
	else: return ( hash[r-1]-hash[l-1]*pow(base,(r-l),mod) )%mod

# 長さmを固定し、区間 [i, i + m) のハッシュ値を求めて、長さmの共通文字列があるかを判定
def check(m):
	C={}
	for i in range(N):
		if i+m<=N:
			hash_value=get(i,i+m)
			if hash_value in C:
				if m<=i-C[hash_value]:
					return True
			else:
				C[hash_value]=i
	else:
		return False

l=0
h=N

while 1<(h-l):
	m=(l+h)/2
	if check(m):
		l=m
	else:
		h=m

print l

Buggy submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-
import sys
from collections import defaultdict,deque
from heapq import heappush,heappop,heapify

N=input()
AL=defaultdict(lambda: set())
IN=defaultdict(lambda: 0)
BEGIN=set()

for i in range(N):
	A=map(int, sys.stdin.readline().split())
	for j in range(N-2):
		x=i+1
		x_next=i+1
		y=A[j]
		y_next=A[j+1]
		#print x,y,x_next,y_next
		if x>y: x,y=y,x
		if x_next>y_next: x_next,y_next=y_next,x_next
		IN[(x_next,y_next)]+=1
		AL[(x,y)].add((x_next,y_next))

		if j==0:
			BEGIN.add((x,y))

hq=[]

for x,y in BEGIN:
	if IN[(x,y)]==0:
		heappush(hq, (1,x,y))


DAY=defaultdict(lambda: 1)	#距離

ans=-1
while hq:
	cost,fro_x,fro_y=heappop(hq)
	fro=(fro_x,fro_y)
	for to in AL[fro]:
		IN[to]-=1
		alt=DAY[fro]+1
		if DAY[to]<alt and IN[to]==0:
			ans=max(ans,alt)
			DAY[to]=alt
			heappush(hq,(alt,to[0],to[1]))

print ans
Problem p02918 (python)

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

L=[]

now=None
for i,s in enumerate(S):
	if i==0:
		now=s
		cnt=1
	elif now==s:
		cnt+=1
	elif now!=s:
		L.append([now,cnt])
		cnt=1
		now=s
else:
	L.append([now,cnt])	

l=len(L)

for i in range(1,min(K*2,l),2):
	s=L[i][0]
	if s=="L": L[i][0]="R"
	elif s=="R": L[i][0]="L"


ans=0
prev=None
for t in L:
	s=t[0]
	cnt=t[1]
	if prev is None:
		prev=s
		lcnt=cnt
	else:
		if prev==s:
			lcnt+=cnt
		elif prev!=s:
			ans+=(lcnt-1)
			lcnt=cnt
		prev=s
else:
	ans+=(lcnt-1)
	
print ans

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

L=[]

now=None
for i,s in enumerate(S):
	if i==0:
		now=s
		cnt=1
	elif now==s:
		cnt+=1
	elif now!=s:
		L.append([now,cnt])
		cnt=1
		now=s
else:
	L.append([now,cnt])	

l=len(L)

ans=0
if l>2:
	for i in range(1,l-1):
		s=L[i][0]
		if s=="L":
			L[i][0]="R"
			K-=1
			if K==0:
				break

	lcnt=0
	now=None
	for i,t in enumerate(L):
		s=t[0]
		cnt=t[1]
		if i==0:
			now=s
			lcnt+=cnt
		else:
			if now==s:
				lcnt+=cnt
			elif now!=s:
				#print s,lcnt
				ans+=max(0,(lcnt-1))
				lcnt=cnt
				now=s
	else:
		ans+=(lcnt-1)

	print ans

else:
	if K<=1:
		print N-1
	else:
		for s,cnt in L:
			ans+=max(0,(lcnt-1))
		print ans

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

L=[]

now=None
for i,s in enumerate(S):
	if i==0:
		now=s
		cnt=1
	elif now==s:
		cnt+=1
	elif now!=s:
		L.append([now,cnt])
		cnt=1
		now=s
else:
	L.append([now,cnt])	

l=len(L)

ans=0
if l>2:
	for i in range(1,l-1):
		s=L[i][0]
		if s=="L":
			L[i][0]="R"
			K-=1
			if K==0:
				break
	lcnt=0
	for i,t in enumerate(L):
		s=t[0]
		cnt=t[1]
		if i==0:
			now=s
		else:
			if now==s:
				lcnt+=cnt
			elif now!=s:
				ans+=max(0,(lcnt-1))
				lcnt=cnt
				now=s
	else:
		ans+=(lcnt-1)

	print ans

else:
	if K<=1:
		print N-1
	else:
		for s,cnt in L:
			ans+=max(0,(lcnt-1))
		print ans
Problem p02921 (python)

Fixed submission:
S=raw_input()
T=raw_input()

ans=0
for s,t in zip(S,T):
	if s==t: ans+=1

print ans

Buggy submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-
import sys
import math
from numpy import arange

N=input()
A=[ map(int, sys.stdin.readline().split()) for _ in range(N) ]
L=[]

for x,y in A:
	if x==0 and y==0: continue
	si=float(y)/(x**2+y**2)**0.5
	L.append( (math.degrees(math.asin(si)),(x**2+y**2)**0.5) )


ans=0
for d_kouho in arange(0.0,360.1,0.01):
	ans_kouho=0
	for d,l in L:
		#print d,d-d_kouho,math.cos(math.radians(d-d_kouho)),l*math.cos(math.radians(d-d_kouho))
		ans_kouho+=l*math.cos(math.radians(d-d_kouho))
	ans=max(ans,ans_kouho)

print ans
Problem p02926 (python)

Fixed submission:
# -*- coding: utf-8 -*-
import sys
import math

N=input()
A=[ map(int, sys.stdin.readline().split()) for _ in range(N) ]
L=[]

for x,y in A:
	L.append( (math.atan2(y,x),x,y) )

L.sort()
L=L+L

ans=0
for start in range(N):
	for end in range(start,start+N):
		kyori=0
		X=0
		Y=0
		for i in range(start,end+1):
			x=L[i][1]
			y=L[i][2]
			X+=x
			Y+=y
		kyori=(X**2+Y**2)**0.5
		ans=max(ans,kyori)

print ans

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

N=input()
A=[ map(int, sys.stdin.readline().split()) for _ in range(N) ]
L=[]

for x,y in A:
	si=float(y)/(x**2+y**2)**0.5
	L.append( (math.degrees(math.asin(si)),x,y) )

N=len(L)
L.sort()
L=L+L

ans=0
for start in range(N):
	for end in range(start,start+N):
		kyori=0
		X=0
		Y=0
		for i in range(start,end+1):
			x=L[i][1]
			y=L[i][2]
			X+=x
			Y+=y
		kyori=(X**2+Y**2)**0.5
		ans=max(ans,kyori)

print ans

Buggy submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-
import sys
import math
from numpy import arange

N=input()
A=[ map(int, sys.stdin.readline().split()) for _ in range(N) ]
L=[]

for x,y in A:
	if x==0 and y==0: continue
	si=float(y)/(x**2+y**2)**0.5
	L.append( (math.degrees(math.asin(si)),(x**2+y**2)**0.5) )


ans=0
for d_kouho in arange(0.0,360.1,0.01):
	ans_kouho=0
	for d,l in L:
		#print d,d-d_kouho,math.cos(math.radians(d-d_kouho)),l*math.cos(math.radians(d-d_kouho))
		ans_kouho+=l*math.cos(math.radians(d-d_kouho))
	ans=max(ans,ans_kouho)

print ans

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

N=input()
A=[ map(int, sys.stdin.readline().split()) for _ in range(N) ]
L=[]

for x,y in A:
	si=float(y)/(x**2+y**2)**0.5
	L.append( (math.degrees(math.asin(si)),(x**2+y**2)**0.5) )


d_kouho=45	#角度の候補

ans=0
for d,l in L:
	#print d,d-d_kouho,math.cos(math.radians(d-d_kouho)),l*math.cos(math.radians(d-d_kouho))
	ans+=l*math.cos(math.radians(d-d_kouho))
print ans
Problem p02936 (python)

Fixed submission:
import sys
from collections import deque

N,Q=map(int, sys.stdin.readline().split())

 
al=[ [] for i in range(N+1) ]
 
for _ in range(N-1):
	a,b=map(int, sys.stdin.readline().split())
	al[a].append(b)
	al[b].append(a)

Visit=[ None for i in range(N+1) ] 
score=[ 0 for i in range(N+1) ] 

for _ in range(Q):
	p,x=map(int, sys.stdin.readline().split())
	score[p]+=x


q=deque()
q.append(1)

while q:
	fro=q.popleft()
	Visit[fro]=1
	for to in al[fro]:
		if Visit[to] is None:
			score[to]+=score[fro]
			q.append(to)


for i,ans in enumerate(score):
	if i==0:	continue
	print ans,

Buggy submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-
import sys
N,Q=map(int, sys.stdin.readline().split())

al=[ [] for _ in range(N+1) ]	#隣接リスト
for _ in range(N-1):
	u,v=map(int, sys.stdin.readline().split())
	al[u].append(v)
	al[v].append(u)

increment=[ 0 for _ in range(N+1) ]
for _ in range(Q):
    p,x=map(int, sys.stdin.readline().split())
    increment[p]+=x

socre=[ 0 for _ in range(N+1) ] #各頂点のカウンターの値を記録
visit=[ 0 for _ in range(N+1) ] #0なら未訪問、1なら訪問済み
point=0
def dfs(par,cur):
    visit[cur]=1
    global point
    point+=increment[cur]
    socre[cur]+=point       #各頂点のカウンターの値を記録
    old=point   #拡張点が子孫に遷移する前のカウンターの値を記録
    for to in al[cur]:
        if visit[to]==0:
            dfs(cur,to)
            point=old   #子孫に遷移し、増えたカウンターの値を自分の時の点数に戻す
dfs(-1,1)

for i in range(1,N+1):
    print socre[i],
Problem p02949 (python)

Fixed submission:
# -*- coding: utf-8 -*-
import sys
from collections import deque

N,M,P=map(int, sys.stdin.readline().split())

al=[ [] for i in range(N+1) ]		#隣接リスト
rev_al=[ [] for i in range(N+1) ]	#reverse隣接リスト
#辺のリスト
edge=[]

for i in range(M):
	a,b,c=map(int, sys.stdin.readline().split())
	al[a].append(b)
	rev_al[b].append(a)
	edge.append((a,b,c-P))


#ゴールからBFS
#訪問した頂点
Visit=[ 0 for _ in range(N+1) ]
q=deque()
q.append(N)
Visit[N]=1
while q:
	fro=q.popleft()
	for to in rev_al[fro]:
		if Visit[to]==0:
			Visit[to]=1
			q.append(to)
			
Visit1=Visit

#スタートからBFS
#訪問した頂点
Visit=[ 0 for _ in range(N+1) ]
q=deque()
q.append(1)
Visit[1]=1
while q:
	fro=q.popleft()
	for to in al[fro]:
		if Visit[to]==0:
			Visit[to]=1
			q.append(to)

Visit2=Visit

#1からもNからも到達可能な頂点の集合
V=[]
for v1,v2 in zip(Visit1,Visit2):
	V.append(v1&v2)

new_N=sum(V)

fedge=[]	#必要な要素だけをフィルターした辺集合
for a,b,c in edge:
	if V[a]==1 and V[b]==1:
		fedge.append((a,b,c))


D=[ float("-inf") ]*(N+1)	#頂点１からの距離 1-indexed
D[1]=0

#ベルマンフォード
for i in range(new_N):
	for a,b,c in fedge:
		if D[a]==float("-inf"): continue
		alt=D[a]+c
		if D[b]<alt:
			D[b]=alt
			if i==new_N-1:
				print -1
				quit()

print max(0,D[N])

Buggy submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-
import sys
from collections import deque

N,M,P=map(int, sys.stdin.readline().split())

al=[ [] for i in range(N+1) ]		#隣接リスト
rev_al=[ [] for i in range(N+1) ]	#reverse隣接リスト
#辺のリスト
edge=[]

for i in range(M):
	a,b,c=map(int, sys.stdin.readline().split())
	al[a].append(b)
	rev_al[b].append(a)
	edge.append((a,b,c-P))


#ゴールからBFS
q=deque()
q.append(N)
#訪問した頂点
Visit=[ 0 for _ in range(N+1) ]
while q:
	fro=q.popleft()
	Visit[fro]=1
	for to in rev_al[fro]:
		if Visit[to]==0:
			q.append(to)
			
Visit1=Visit

#スタートからBFS
q=deque()
q.append(1)
#訪問した頂点
Visit=[ 0 for _ in range(N+1) ]
while q:
	fro=q.popleft()
	Visit[fro]=1
	for to in al[fro]:
		if Visit[to]==0:
			q.append(to)

Visit2=Visit

#1からもNからも到達可能な頂点の集合
V=[]
for v1,v2 in zip(Visit1,Visit2):
	V.append(v1&v2)

new_N=sum(V)

fedge=[]	#必要な要素だけをフィルターした辺集合
for a,b,c in edge:
	if V[a]==1 and V[b]==1:
		fedge.append((a,b,c))


D=[ float("-inf") for _ in range(N+1) ]	#頂点１からの距離 1-indexed
D[1]=0

#ベルマンフォード
for i in range(new_N):
	for a,b,c in fedge:
		if D[a]==float("-inf"): continue
		alt=D[a]+c
		if D[b]<alt:
			D[b]=alt
			if i==new_N-1:
				print -1
				quit()

print (max(0,D[N]))
Problem p02971 (python)

Fixed submission:
import sys
N=input()
A=[ int(sys.stdin.readline().strip())  for _ in range(N) ]

L=[]
for i,a in enumerate(A):
	if i==0:
		L.append(a)
	else:
		L.append( max(L[-1], a) )

R=[]
for i,a in enumerate(A[::-1]):
	if i==0:
		R.append(a)
	else:
		R.append( max(R[-1], a) )

R=R[::-1]


for i in range(N):
	if i==0:
		print R[i+1]
	elif i==N-1:
		print L[i-1]
	else:
		print max( R[i+1], L[i-1])

Buggy submission (verdict: Runtime Error):
		L.append( max(L[-1], a) )

R=[]
for i,a in enumerate(A[::-1]):
	if i==0:
		R.append(a)
	else:
		R.append( max(R[-1], a) )

R=R[::-1]


for i in range(N):
	if i==0:
		print R[i+1]
	elif i==N-1:
		print L[i-1]
	else:
		print max( R[i+1], L[i-1])
Problem p02975 (python)

Fixed submission:
from collections import Counter

N=input()
A=map(int, raw_input().split())

for i,x in enumerate(A):
	if i==0:
		t=x
	else:
		t^=x

if t==0:
	print "Yes"
else:
	print "No"

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

N=input()
A=map(int, raw_input().split())

C=Counter(A)

if len(C)%3==0:
	a,b,c=C.keys()
	if N%3==0:
		if a^b==c:
			print "Yes"
		else:
			print "No"
else:
	if len(C)==1:
		if C.keys()==[0]:
			print "Yes"
		else:
			print "No"
	else:
		print "No"
Problem p02983 (python)

Fixed submission:
L,R=map(int, raw_input().split())
a=L%2019
b=R%2019

T=[]
ans=float("inf")
if a<b:
	T=range(a,b+1)
	if R-L>2018:
		print 0
		quit()
	else:
		l=len(T)
		for i in range(l):
			for j in range(i+1,l):
				ans=min(ans, (T[i]*T[j])%2019 )

		print ans
else:
	print 0
	quit()

Buggy submission (verdict: Runtime Error):
import sys
L,R=map(int, sys.stdin.readline().split())
sho1=L/2019
sho2=R/2019
if 1<=sho2-sho1:
    print 0
else:
    ans=float("inf")
    for i in range(L,R):
        for j in range(i+1,R+1):
            ans=min(ans,i*j%2019)

print ans