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

Fixed submission:
n,a=map(int,input().split())
x=list(map(lambda x:int(x)-a,input().split()))
m=0 if min(x)>0 else min(x)*n
M=1 if max(x)<0 else max(x)*n+1
dp=[[0]*(M-m) for _ in range(n)]
dp[0][x[0]]+=1
dp[0][0]+=1
for i in range(n-1):
    for j in range(m,M):
        if j+x[i+1] in range(m,M):dp[i+1][j+x[i+1]]+=dp[i][j]
        dp[i+1][j]+=dp[i][j]
print(dp[n-1][0]-1)

Buggy submission (verdict: Runtime Error):
n,a=map(int,input().split())
x=list(map(lambda x:int(x)-a,input().split()))
m=min(x)*n;M=max(x)*n+1
if max(x)<0 or min(x)>0:print(0);exit()
dp=[[0]*(M-m) for _ in range(n)]
dp[0][x[0]]+=1
dp[0][0]+=1
for i in range(n-1):
    for j in range(m,M):
        dp[i+1][j+x[i+1]]+=dp[i][j]
        dp[i+1][j]+=dp[i][j]
print(dp[n-1][0]-1)

Buggy submission (verdict: Runtime Error):
n,a=map(int,input().split())
x=list(map(lambda x:int(x)-a,input().split()))
m=min(x)*n;M=max(x)*n+1
if M<0 or m>0:print(0);exit()
dp=[[0]*(M-m) for _ in range(n)]
dp[0][x[0]]+=1
dp[0][0]+=1
for i in range(n-1):
    for j in range(m,M):
        dp[i+1][j+x[i+1]]+=dp[i][j]
        dp[i+1][j]+=dp[i][j]
print(dp[n-1][0]-1)

Buggy submission (verdict: Runtime Error):
n,a=map(int,input().split())
x=list(map(lambda x:int(x)-a,input().split()))
m=min(x)*n;M=max(x)*n+1
dp=[[0]*(M-m) for _ in range(n)]
dp[0][x[0]]+=1
dp[0][0]+=1
for i in range(n-1):
    for j in range(m,M):
        if dp[i][j]!=0:
            if j+x[i+1] in range(m,M):dp[i+1][j+x[i+1]]+=dp[i][j]
            dp[i+1][j]+=dp[i][j]
print(dp[n-1][0]-1)

Buggy submission (verdict: Runtime Error):
n,a=map(int,input().split())
x=list(map(lambda x:int(x)-a,input().split()))
m=min(x)*n;M=max(x)*n+1
dp=[[0]*(M-m) for _ in range(n)]
dp[0][x[0]]+=1
dp[0][0]+=1
for i in range(n-1):
    for j in range(m,M):
        if dp[i][j]!=0:
            dp[i+1][j+x[i+1]]+=dp[i][j]
            dp[i+1][j]+=dp[i][j]
print(dp[n-1][0]-1)
Problem p02848 (python)

Fixed submission:
import string

N = int(input())
S = input()

letters = string.ascii_uppercase + string.ascii_uppercase
letters = letters[N:N+26]
mapping = {s: letters[idx] for idx, s in enumerate(string.ascii_uppercase)}

ans = "".join(map(lambda s: mapping[s], S))
print(ans, flush=True)

Buggy submission (verdict: Runtime Error):
import string

N = int(input())
S = input()

letters = string.ascii_uppercase + string.ascii_uppercase
letters = letters[N:N+26]
mapping = {s: letters[idx] for idx, s in enumerate(S)}

ans = "".join(map(lambda s: mapping[s], S))
print(ans, flush=True)
Problem p02911 (python)

Fixed submission:
N, K, Q = map(int,input().split())
point_list = [0 for i in range(N+1)]
for i in range(Q):
    A = int(input())
    point_list[A]+=1
for i in range(1,N+1):
    if point_list[i]+K-Q<=0:
        print("No")
    else:
        print("Yes")

Buggy submission (verdict: Runtime Error):
import sys	

num1 = list(map(int, input().split()))
N = num1[0] #参加者数
K = num1[1] #初期ポイント
Q = num1[2] #出た正解の数
ans_list = []
for index1 in range(Q):
	ans_list.append(int(input()))
for index1 in range(1,N+1):
	point = 0
	for index2 in ans_list:
		if index1==ans_list[index2]:
			point +=1

	fin=K+point-Q
	
	if fin <=0:
		print("No")
	else:
		print("Yes")

Buggy submission (verdict: Runtime Error):
import sys

def cal(x):
	point = 0
	for index2 in ans_list:
		if x==ans_list[index2]:
			point +=1
	score=K+point-Q
	return score	

num1 = list(map(int, input().split()))
N = num1[0] #参加者数
K = num1[1] #初期ポイント
Q = num1[2] #出た正解の数
ans_list = []
for index1 in range(Q):
	ans_list.append(int(input()))
for index1 in range(N):
	fin = cal(index1)
	if fin <=0:
		print("No")
	else:
		print("Yes")
Problem p02923 (python)

Fixed submission:
import sys

N = int(input())
H = list(map(int,input().split()))

count = 0
ans = 0

for i in range(N-1) :
	if H[i]>=H[i+1] :
		count+=1
	else :
		if ans<=count:
			ans= count
		count=0
	#print(ans)
	#print(count)
if ans<=count:
	ans= count
print(ans)

Buggy submission (verdict: Runtime Error):
import sys

N = int(input())
H = list(map(int,input().split()))

count = 0
ans =[]

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

print(max(ans))
Problem p02952 (python)

Fixed submission:
num = [i for i in range (1,int(input())+1)]
ans = 0

if num[-1]<=9 :
	ans = num[-1]
elif num[-1]<=99 :
	ans = 9
elif num[-1]<=999 :
	ans = num[-1]-90
elif num[-1]<=9999:
	ans = 909
elif num[-1]<=99999 :
	ans = num[-1]-9090
else :
	ans = 90909

print(ans)

Buggy submission (verdict: Runtime Error):
num = [i for i in range (1,int(input())+1)]
ans = 0

if num[-1]<=9 :
	ans = num[-1]
elif num[-1]<=99 :
	ans = 9
elif num[-1]<=999 :
	ans = 10+num[-1]%100
elif num[-1]<=9999:
	ans = 10+899
elif num[-1]<=99999 :
	ans = 910+num[-1]%10000
elif :
	ans = 90909

print(ans)

Buggy submission (verdict: Runtime Error):
#num = list(map(int,input().split()))
num = [i for i in range (1,int(input())+1)]
ans = 0
count = 0

for j in range(9,99):
	num[j]=0

for k in range(999,9999):
	num[k]=0

for l in range(len(num)-1):
	if not num[l]==0:
		count+=1

print(count)
Problem p02934 (python)

Fixed submission:
input_size = int(input())
inputs = input().split()
sum = 0
for i in range(input_size):
  sum += 1 / int(inputs[i])
print(1 / sum)

Buggy submission (verdict: Runtime Error):
input_size = int(input())
inputs = map(int, input().split())
sum = 0
for i in range(input_size):
  sum += 1 / inputs[i]
print(1 / sum)
Problem p02953 (python)

Fixed submission:
N = int(input())
a = input().split()
for l in range(N):
    a[l] = int(a[l])
for i in range(N):
  if i < N-1:
    if a[N-i-1] >= a[N-i-2]:
      continue
    elif a[N-i-1] + 1 == a[N-i-2]:
      a[N-i-2] -= 1
    else:
      print('No')
      break
  else:
    print('Yes')

Buggy submission (verdict: Runtime Error):
N = int(input())
a = input().split()
for l in range(N):
    a[l] = int(a[l])
for i in range(N):
  if i < N:
    if a[N-i-1] >= a[N-i-2]:
    elif a[N-i-1] + 1 == a[N-i-2]:
      a[N-i-2] -= 1
    else:
      print('No')
      break
  else:
    print('Yes')

Buggy submission (verdict: Runtime Error):
N = int(input())
a = []
for i in range(N):
  a.append(input())
for i in range(N):
  if i < N:
    if int(a[N-i-1]) >= int(a[N-i-2]):
      continue
    elif int(a[N-i-1]) + 1 == int(a[N-i-2]):
      int(a[N-i-2]) -= 1
      continue
    else:
      print('No')
      break
  else:
    print('Yes')
Problem p02957 (python)

Fixed submission:
inputs = input().split()
a = int(inputs[0])
b = int(inputs[1])
if (a - b) % 2 == 0:
  print( int((a + b) / 2 ))
else:
  print('IMPOSSIBLE')

Buggy submission (verdict: Runtime Error):
inputs = input().split()
a = int(inputs[0])
b = int(inputs[1])
if abs(a - b) % 2 = 0:
  print( (a + b) / 2 )
else:
  print('IMPOSSIBLE')

Buggy submission (verdict: Runtime Error):
inputs = input().split()
a = int(inputs[0])
b = int(inputs[1])
if (a - b) % 2 = 0:
  print( (a + b) / 2 )
else:
  print('IMPOSSIBLE')
Problem p02898 (python)

Fixed submission:
N,K = map(int, input().split())
S = sorted( list(map(int, input().split())) )
count=0

for i in S:
  if(i>=K):
    count += 1
print(count)

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

r_R = len(S)
r_L = 0
r_M = round( (r_R+r_L)/2 )

flag = 0

if(r_R == 1):
	flag = 1
elif(S[r_L]>=K):
  flag = 1
  r_M = r_R

while(flag==0):
  if( S[r_M] <= K < S[r_M + 1] ):
    flag = 1
  
  elif( K < S[r_M] ):
    r_L = r_M
    r_M = round( (r_R+r_L)/2 )
  
  elif( S[r_M + 1] <=K ):
    r_R = r_M
    r_M = round( (r_R+r_L)/2 )

print(r_M)
Problem p02909 (python)

Fixed submission:
tenki = input()

if tenki == "Sunny":
  print("Cloudy")
elif tenki == "Cloudy":
  print("Rainy")
else:
  print("Sunny")

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

if tenki == Sunny:
  print("Cloudy")
elif tenki == Rainy:
  print("Rainy")
else:
  print("Cloudy")
Problem p02918 (python)

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

if len(S) > 1:
    count = 0

    temp = S[1]

    for i in range(0, len(S)-1):
        if S[i] == S[i+1]:
            count += 1

    print( min(len(S)-1, count + 2*K) )
else:
    print(0)

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

count = 0
temp = S[1]

for i in range(0, len(S)-1):
    if S[i] == S[i+1]:
        count += 1
        
print( min(len(S)-1, count + 2*K) )

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

count = 0
temp = S[1]

for i in range(0, len(S)-1):
    if S[i] == S[i+1]:
        count += 1
        
print( min(len(S)-1, count + 2*K) )
Problem p02850 (python)

Fixed submission:
import sys
sys.setrecursionlimit(1000000)

N = int(input())
G = [[] for i in range(N)]
for i in range(N-1):
    a,b = map(int,input().split())
    a,b = a-1,b-1
    G[a].append([b, i])

ans = [None]*(N-1)
def rec(cur, color):
    cnt = 1
    for (to, j) in G[cur]:
        if cnt == color:
            cnt += 1
        ans[j] = cnt
        rec(to, cnt)
        cnt += 1

rec(0,0)
print(max(ans))
[print(a) for a in ans]

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

N = int(input())
G = [[] for i in range(N)]
for i in range(N-1):
    a,b = map(int,input().split())
    a,b = a-1,b-1
    G[a].append([b, i])

ans = [None]*(N-1)
def rec(cur, color):
    cnt = 1
    for (to, j) in G[cur]:
        if cnt == color:
            cnt += 1
        ans[j] = cnt
        rec(to, cnt)
        cnt += 1

rec(0,0)
print(max(ans))
[print(a) for a in ans]

Buggy submission (verdict: Runtime Error):
N = int(input())
G = [[] for i in range(N)]
for i in range(N-1):
    a,b = map(int,input().split())
    a,b = a-1,b-1
    G[a].append([b, i])

ans = [None]*(N-1)
def rec(cur, color):
    cnt = 1
    for (to, j) in G[cur]:
        if cnt == color:
            cnt += 1
        ans[j] = cnt
        rec(to, cnt)
        cnt += 1

rec(0,0)
print(max(ans))
[print(a) for a in ans]
Problem p02937 (python)

Fixed submission:
S, T = input(), input()

def func(S, T):

    merge_S = list(set(S))
    merge_T = list(set(T))
    for t in merge_T:
        if t not in merge_S:
            return -1

    S_2 = S+S
    len_s = len(S)

    ans = -1

    for t in T:
        ans += S_2[(ans+1)%len_s:].index(t) + 1

    return ans + 1

print(func(S,T))

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

def func(S, T):

    S_2 = S+S
    len_s = len(S)
    merge_S = list(set(S))
    merge_T = list(set(T))
    alp2num = {t: merge_T.index(t) for t in merge_T}
    dis_S = [[-1]*len(merge_T) for _ in range(len_s)]
    pt = S.index(T[0])
    ans = pt+1

    for t in merge_T:
        if t not in merge_S:
            return -1

    for t in T[1:]:
        it = alp2num[t]
        if dis_S[pt][it] == -1:
            dis_S[pt][it] = S_2[pt+1:].index(t) + 1
        ans += dis_S[pt][it]
        pt = (pt + dis_S[pt][it]) % len_s

    return ans

print(func(S,T))
Problem p02910 (python)

Fixed submission:
s = input()
n = len(s)
a = 0
if n % 2 == 0:
  for i in range(0,n,2):
    if s[i] == "L":
      a = 1
      break
  for i in range(1,n,2):
    if s[i] == "R":
      a = 1
      break
else:
  for i in range(0,n,2):
    if s[i] == "L":
      a = 1
      break
  for i in range(1,n,2):
    if s[i] == "R":
      a = 1
      break
if a == 0:
  print("Yes")
if a == 1:
  print("No")

Buggy submission (verdict: Runtime Error):
s = input()
n = len(s)
a = 0
if n % 2 == 0:
  for i in range(0,n+1,2):
    if s[i] == "R":
      a = 1
      break
  for i in range(1,n,2):
    if s[i] == "L":
      a = 1
      break
if n % 2 == 1:
  for i in range(0,n,2):
    if s[i] == "R":
      a = 1
      break
  for i in range(1,n+1,2):
    if s[i] == "L":
      a = 1
      break
if a == 0:
  print("Yes")
if a == 1:
  print("No")

Buggy submission (verdict: Runtime Error):
s = input()
n = len(s)
a = 0
if n % 2 == 0:
  for i in range(0,n+1,2):
    if s[i] == "R":
      a = 1
      break
  for i in range(1,n,2):
    if s[i] == "L":
      a = 1
      break
if n % 2 == 1:
  for i in range(0,n,2):
    if s[i] == "R":
      a = 1
      break
  for i in range(1,n+1,2):
    if s[i] == "L":
      a = 1
      break
if a == 0:
  print("Yes")
if a == 1:
  print("No")
Problem p02934 (python)

Fixed submission:
N = int(input())
A = list(map(int,input().split()))
i = 0
B = 0
while i <= N-1:
  B += 1/A[i]
  i = i + 1
answer = 1 / B
print(answer)

Buggy submission (verdict: Runtime Error):
N = int(input())
A = list(map(int,input().split()))
i = 0
for i <= N-1:
  B[i] = 1/A[i]
S = sum(B)
answer = 1 / S
print(answer)
Problem p02988 (python)

Fixed submission:
n = int(input())
p = list(map(int,input().split()))
i = 1
ans = 0
while i <= n-2:
  if (p[i]-p[i-1])*(p[i]-p[i+1]) < 0:
    ans += 1
  if (p[i]-p[i-1])*(p[i]-p[i+1]) == 0:
    if p[i] < p[i-1] or p[i] < p[i+1]:
      ans += 1
  i += 1
print(ans)

Buggy submission (verdict: Runtime Error):
n = int(input())
p = list(map(int,input().split()))
i = 1
ans = 0
while i =< n-2:
  if (p[i]-p[i-1])*(p[i]-p[i+1]) < 0:
    ans += 1
  if (p[i]-p[i-1])*(p[i]-p[i+1]) = 0:
    if p[i] < p[i-1] or p[i] < p[i+1]:
      ans += 1
  i += 1
print("%d",ans)
Problem p03000 (python)

Fixed submission:
s = list(map(int,input().split()))
N = s[0]
X = s[1]
L = list(map(int,input().split()))
a = 0
d = 0
while d <= X:
  if a >= N:
    a = N+1
    break
  else:
    d += L[a]
    a += 1 

print(a)

Buggy submission (verdict: Runtime Error):
s = list(map(int,input().split()))
N = s[0]
X = s[1]
L = list(map(int,input().split()))
a = 0
d = 0
while d <= X:
  if a >= N+1:
    break
  else:
    d += L[a]
    a += 1 

print(a)

Buggy submission (verdict: Runtime Error):
s = list(map(int,input().split()))
N = s[0]
X = s[1]
L = list(map(int,input().split()))
a = 0
d = 0
while d <= X:
  if a == N+1:
    break
  else:
    d += L[a]
    a += 1 

print(a)

Buggy submission (verdict: Runtime Error):
s = list(map(int,input().split()))
N = s[0]
X = s[1]
L = list(map(int,input().split()))
a = 0
d = 0
while d <= X:
  while a <= N+1:
    d += L[a]
    a += 1 

print(a)

Buggy submission (verdict: Runtime Error):
s = list(map(int,input().split()))
N = s[0]
X = s[1]
L = list(map(int,input().split()))
a = 0
d = 0
while d <= X:
  if a >= N+1:
    a = N+1
    break
  d += L[a]
  a += 1 

print(a)

Buggy submission (verdict: Runtime Error):
s = list(map(int,input().split()))
N = s[0]
X = s[1]
L = list(map(int,input().split()))
a = 0
d = 0
while d <= X:
  if a >= N+1:
    a = N
    break
  d += L[a]
  a += 1 

print(a+1)

Buggy submission (verdict: Runtime Error):
s = list(map(int,input().split()))
N = s[0]
X = s[1]
L = list(map(int,input().split()))
a = 0
d = 0
while d <= X:
  if a >= N+1:
    a = N+1
    break
  d += L[a]
  a += 1 

print(a)

Buggy submission (verdict: Runtime Error):
s = list(map(int,input().split()))
N = s[0]
X = s[1]
L = list(map(int,input().split()))
a = 0
d = 0
while d <= X:
  d += L[a]
  a += 1 
  if a >= N+1:
    a = N+1
    break
print(a)

Buggy submission (verdict: Runtime Error):
s = list(map(int,input().split()))
N = s[0]
X = s[1]
L = list(map(int,input().split()))
a = 0
d = 0
while d =< X:
  d += L[a]
  a += 1 
print(a)
Problem p03001 (python)

Fixed submission:
a = list(map(float,input().split()))
answer = float(a[0] * a[1]/2)
print(answer)
if a[2] == a[0]/2:
  if a[3] == a[1]/2:
    print(1)
  else:
    print(0)
else:
  print(0)

Buggy submission (verdict: Runtime Error):
a = list(map(float,input().split(),9))
answer = float(a[0] * a[1])
print(answer)
if a[2] == a[0]/2:
  if a[3] == a[1]/2:
    print(1)
  else:
    print(0)
else:
  print(0)

Buggy submission (verdict: Runtime Error):
a = list(map(float,input().split(),9))
answer = float(a[0] * a[1],9)
print(answer)
if a[2] == a[0]/2:
  if a[3] == a[1]/2:
    print(1)
  else:
    print(0)
else:
  print(0)
Problem p02945 (python)

Fixed submission:
a,b = map(int, input().split())

print(max(a*b,a-b,a+b))

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

str_data = {}

for i in range(count):
  judge_str = ''.join(sorted(input()))
  if judge_str in str_data:
    str_data[judge_str] += 1
  else:
    str_data[judge_str] = 0

print(sum(str_data.values())

Buggy submission (verdict: Runtime Error):
a,b = input().split(' ')

print(max(a*b,a-b,a+b))
Problem p02947 (python)

Fixed submission:
count = int(input())
 
str_data = dict()
result = 0
for i in range(count):
    judge_str = ''.join(sorted(input()))
    if judge_str in str_data:
        str_data[judge_str] += 1
        result += str_data[judge_str]
    else:
        str_data[judge_str] = 0
    
print(result)

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

for i in range(count):
  judge_str = ''.join(sorted(input()))
  if judge_str in str_data:
    str_data[judge_str] += 1
  else:
    str_data[judge_str] = 0

print(sum(str_data.values()))

Buggy submission (verdict: Runtime Error):
count = int(input())
 
str_data = {}
 
for i in range(count):
  judge_str = ''.join(sorted(input()))
  if judge_str in str_data:
    str_data[judge_str] += 1
  else:
    str_data[judge_str] = 0
 
print(sum(str_data.values())
Problem p03325 (python)

Fixed submission:
import math
N=int(input().strip())
A=list(map(int,input().split()))
nns=[2**i for i in range(31)]
def func(n,x):
    return n%nns[x]==0
def binsearch_int(func, min_x, max_x):
    """func(x) == Trueとなる最大のxを返す
    """
    if func(max_x):
        return max_x
    if not func(min_x):
        return None
    left,right=min_x,max_x
    while left+1<right:
        mid=(left+right)//2
        if func(mid):
            left=mid
        else:
            right=mid
    return left
print(sum(binsearch_int(lambda x: func(i,x),0,int(math.log2(i))+1) for i in A))

Buggy submission (verdict: Runtime Error):
N=int(input().strip())
A=list(map(int,input().split()))
nns=[2**i for i in range(31)]
def func(n,x):
    return n%nns[x]==0
def binsearch_int(func, min_x, max_x):
    """func(x) == Trueとなる最大のxを返す
    """
    if func(max_x):
        return max_x
    if not func(min_x):
        return None
    left,right=min_x,max_x
    while left+1<right:
        mid=(left+right)//2
        if func(mid):
            left=mid
        else:
            right=mid
    return left
sum(binsearch_int(lambda x: func(i,x),0,int(math.log2(i))+1) for i in A)
Problem p03353 (python)

Fixed submission:
s=input().strip()
K=int(input())
sorteds=sorted(set(s))
ct=0
subsset=set()
for c in sorteds:
    ct+=1
    ixs=[]
    ss=s
    ix=0
    while len(ss):
        ii=ss.find(c)
        if ii==-1:break
        ixs.append(ix+ii)
        ix=ix+ii
        ss=ss[ii:]
        for i in range(min(len(ss),K)):
            subsset.add(ss[:1+i])
        ss=ss[1:]
    if len(subsset)>=K:
        break
print(sorted(list(subsset))[K-1])

Buggy submission (verdict: Runtime Error):
s=input().strip()
K=int(input())
st=set()
for i in range(len(s)-1):
    for k in range(i+1,min(len(s),i+K+1)):
        st.add(s[i:k])
print(sorted(st)[K-1])
Problem p03361 (python)

Fixed submission:
H,W = map(int,input().split())
ss=[]
for s in range(H):
    ss.append(input().strip())
flg=True
for i in range(H):
    for j in range(W):
        if ss[i][j]== "#":
            if not (j>0 and ss[i][j-1] == "#"or j<W-1 and ss[i][j+1] == "#" or i>0 and ss[i-1][j]=="#" or i< H-1 and ss[i+1][j]=="#"):
                flg=False
                break
    if not flg:
        break
print("No Yes".split()[int(flg)])

Buggy submission (verdict: Runtime Error):
H,W = sorted(map(int,input().split()))
ss=[]
for s in range(H):
    ss.append(input().strip())
flg=True
for i in range(H):
    for j in range(W):
        if ss[i][j]== "#":
            if not (j>0 and ss[i][j-1] == "#"or j<W-1 and ss[i][j+1] == "#" or i>0 and ss[i-1][j]=="#" or i< H-1 and ss[i+1][j]=="#"):
                flg=False
                break
    if not flg:
        break
print("No Yes".split()[int(flg)])
Problem p03450 (python)

Fixed submission:
import queue,sys
# 解説読んだ後
N,M=map(int,input().split())
# networkを作る
G={}
LRD=[]
for i in range(1,N+1):
    G[i]={}
for i in range(M):
    l,r,d=map(int,input().split())
    LRD.append((l,r,d))
    G[l][r]=d
    G[r][l]=-d
if M==0:
    print("Yes")
    sys.exit()
notvisit=set(range(1,N+1))
Q=queue.Queue()
x={}
while notvisit:
    current=notvisit.pop()
    Q.put(current)
    x[current]=0
    while Q.qsize():
        nex=Q.get()
        for k,v in G[nex].items():
            if k in x:
                if x[k]!= x[nex]+G[nex][k]:
                    print("No")
                    sys.exit()
            else:
                x[k]=x[nex]+G[nex][k]
                Q.put(k)
                notvisit.remove(k)
print("Yes")

Buggy submission (verdict: Runtime Error):
N,M=map(int,input().split())
LRD=[]
x={}
for i in range(M):
    l,r,d=map(int,input().split())
    LRD.append((l,r,d))
if LRD:
    x[LRD[0][0]]=0
flag=True
while LRD and flag:
    rmvlist=[]
    for i in range(len(LRD)):
        l,r,d=LRD[i]
        if l in x and r not in x:
            x[r] = x[l] +d
            rmvlist.append(i)
        elif r in x and l not in x:
            x[r] = x[l] +d
            rmvlist.append(i)
        elif l in x and r in x:
            if x[l] +d != x[r]:
                flag=False
                break
            else:
                rmvlist.append(i)
    if len(rmvlist)==0:
        x[LRD[0][0]]=0
    else:
        LRD=[LRD[i]for i in range(len(LRD)) if i not in rmvlist]

print("Yes No".split()[1-flag])

Buggy submission (verdict: Runtime Error):
N,M=map(int,input().split())
LRD=[]
x={}
for i in range(M):
    l,r,d=map(int,input().split())
    LRD.append((l,r,d))
if LRD:
    x[LRD[0][0]]=0
flag=True
while LRD and flag:
    ct=len(LRD)
    for i in range(len(LRD)):
        l,r,d=LRD[i]
        if l in x and r not in x:
            x[r] = x[l] +d
            LRD.pop(i)
            break
        elif r in x and l not in x:
            x[r] = x[l] +d
            LRD.pop(i)
            break
        elif l in x and r in x:
            if x[l] +d != x[r]:
                flag=False
                break
            else:
                LRD.pop(i)
                break
    if ct==len(LRD):
        break

print("Yes No".split()[1-flag])
Problem p03476 (python)

Fixed submission:
def eratosthenesAray(N):
    prime=[True]*(N+1)
    prime[0]=False
    prime[1]=False
    for i in range(2,N+1):
        if prime[i]:
            for j in range(i+i,N+1,i):
                prime[j]=False
    return prime

N=int(input().strip())
primes=eratosthenesAray(100000)
ruiseki=[0]*100001
for i in range(1,100001):
    ruiseki[i]=ruiseki[i-1]
    if primes[i] and primes[(i+1)//2]:
        ruiseki[i]+=1
for i in range(N):#N
    l,r=map(int,input().split())
    print(ruiseki[r]-ruiseki[l-1])

Buggy submission (verdict: Runtime Error):
N=int(input().strip())
primes=sorted(eratosthenes(int(1e5)))
p_set=set(primes)
primes2=[]
for p in primes:#MlogM
    if (p+1)//2 in p_set:
        primes2.append(p)
for i in range(N):#N
    l,r=map(int,input().split())
    li=binsearch_lb(primes2,l)#l以上のインデックス logM
    ri=binsearch_ub(primes2,r)#r以下のインデックス
    print(ri-li+1)
Problem p03488 (python)

Fixed submission:
import sys
sys.setrecursionlimit(100000)
s=input().strip()
x,y=map(int,input().split())
sl=[len(i) for i in s.split('T')]
x0,y0=sl[0],0
s_x = sl[::2]
s_y = sl[1::2]
s_y=[0]+s_y
dpx=[set() for i in s_x]
dpy=[set() for i in s_y]
dpx[0].add(s_x[0])
dpy[0].add(0)
for i,l in enumerate(s_x):
    if i==0:continue
    ll=dpx[i]
    for xx in dpx[i-1]:
        ll.add(xx-l)
        ll.add(xx+l)
for i,l in enumerate(s_y):
    if i==0:continue
    ll=dpy[i]
    for yy in dpy[i-1]:
        ll.add(yy-l)
        ll.add(yy+l)
print('Yes' if x in dpx[-1] and y in dpy[-1] else 'No')

Buggy submission (verdict: Runtime Error):
s=input().strip()
x,y=map(int,input().split())
sl=[len(i) for i in s.split('T')]
x0,y0=sl[0],0

answers={}
def search(xx,yy,k,isUD):
    if (xx,yy,k) in answers:
        return answers[(xx,yy,k)]
    if k == len(sl):
        ans=(xx,yy)==(x,y)
    else:
        lng=sl[k]
        # D or L
        llr=(lng if not isUD else 0)
        lud=(lng if isUD else 0)
        d_l = search(xx-llr,yy-lud,k+1, not isUD)
        u_r = search(xx+llr,yy+lud,k+1, not isUD)
        ans = d_l or u_r
    answers[(xx,yy,k)]=ans
    return ans
print('Yes' if search(x0,y0,1,True) else 'No')