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

Fixed submission:
n,m = map(int,input().split())
a=[0]*n
w=[0]*n
ac=0
wc=0
for _ in range(m):
    p,s=input().split()
    p=int(p)-1
    if a[p]==0:
        if s=="AC":
            a[p]=1
            ac+=1
            wc+=w[p]
        else:
            w[p]+=1
print(ac,wc)

Buggy submission (verdict: Runtime Error):
n,m = map(int,input().split())
a=[0]*n
w=[0]*n
ac=0
wa=0
for _ in range(m):
    p,s=input().split()
    p=int(p)-1
    if a[p]==0:
        if s=="AC":
            a[p]=1
            ac+=1
            wc+=w[p]
        else:
            w[p]+=1
print(ac,wc)
Problem p02888 (python)

Fixed submission:
import bisect
N = int(input())
L_list = list(map(int,input().split()))
L_list.sort()
ans = 0

for i in range(N-1):
  for j in range(i+1,N-1):
    x = bisect.bisect_left(L_list,L_list[i]+L_list[j])
    ans += x-j-1
print(ans)

Buggy submission (verdict: Runtime Error):
import bisect
N = input()
L_list = list(map(int,input().split()))
L_list.sort()
ans = 0

for i in range(N-1):
  for j in range(i+1,N-1):
    x = bisect.bisect_left(L_list,L_list[i]+L_list[j])
    ans += x-j-1
print(ans)

Buggy submission (verdict: Runtime Error):
import bisect
N = input()
L_list = list(map(int,input().split()))
ans = 0

for i in range(N-1):
  for j in range(i+1,N-1):
    x = bisect.bisect_left(L_list,L_list[i]+L_list[j])
    ans += x-j-1
print(ans)
Problem p02909 (python)

Fixed submission:
S = str(input())
L = ["Sunny","Cloudy","Rainy"]
print(L[(L.index(S)+1)%3])

Buggy submission (verdict: Runtime Error):
S = str(input())
dic_wet = {1:"Sunny",2:"Cloudy",3:"Rainy"}
for k , v in dic_wet.items():
    if v == S:
        print(dic_wet[(k+1) % 3])

Buggy submission (verdict: Runtime Error):
S = str(input())
dic_wet = {1:"Sunny",2:"Cloudy",3:"Rainy"}
for k , v in dic_wet.items():
    if v == S:
        print(dic_wet[(k+1) % 3])
Problem p02936 (python)

Fixed submission:
#「探索候補スタック」「探索済みリスト」「現在地点」の３点セットでとらえる
n,q=map(int,input().split())
mat=[set() for _ in range(n)]
for _ in range(n-1):
    a,b=map(int,input().split())
    mat[a-1].add(b-1)
    mat[b-1].add(a-1) # プラスした要素
count=[0]*n
for _ in range(q):
    p,score=map(int,input().split())
    count[p-1]+=score

stack=[[0,0,-1]]
while stack:
    # print(stack)
    num,cnt,pr=stack.pop()
    count[num]+=cnt
    for k in mat[num]:
        if k==pr:
            continue
        stack.append([k,count[num],num])
print(*count)

Buggy submission (verdict: Runtime Error):
n,q=map(int,input().split())
tree=[[] for _ in range(n)]
for _ in range(n-1):
    a,b=map(int,input().split())
    a-=1
    b-=1
    tree[a].append(b)
    tree[b].append(a)
cnt=[0]*n
for _ in range(q):
    p,x=map(int,input().split())
    cnt[p-1]+=x

def DFS(v,p_v):
    for next_v in tree[v]:
        if next_v==p_v:
            continue
        cnt[next_v]+=cnt[v]
        DFS(next_v,v)

DFS(0,-1)
print(*cnt)
Problem p02958 (python)

Fixed submission:
import sys

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

try:

    if sorted(p_list) == p_list:
        print("YES")
        sys.exit()

    sum = 0

    for i,j in zip(p_list,sorted(p_list)):
        if i != j:
            sum += 1

    if sum == 2:
        print("YES")
    else:
        print("NO")

except EOFError:
    pass

Buggy submission (verdict: Runtime Error):

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

if sorted(p_list) == p_list:
    print("YES")
    sys.exit()

sum = 0
    
for i,j in zip(p_list,sorted(p_list)):
    if i != j:
        sum += 1

if sum == 2:
    print("YES")
else:
    print("NO")
Problem p02994 (python)

Fixed submission:
N,L = map(int,input().split())
l = list(map(lambda x : L+x-1 , range(1,N+1)))
print(sum(l)-min(l,key=abs))

Buggy submission (verdict: Runtime Error):
N,L = map(int,input().split())
l = list(map(lambda x : L+x+1 , range(1,N+1)))
print(sum(l)-min(l,key=min))

Buggy submission (verdict: Runtime Error):
N,L = map(int,input().split())
a_list = []
for i in range(N):
    diff = abs(((L-1)*(N-1)-i))
    a_list.append(diff)
    
print(sum(list(N+1))-((L-1)*(N-1) - min(a_list)))
Problem p02995 (python)

Fixed submission:
from fractions import gcd
a,b,c,d=map(int,input().split())

def lcm(x,y):
    return (x*y)//gcd(x,y)

def ans_cnt(i,y,z):
    return i - (i//y + i//z - i//lcm(y,z))

print(ans_cnt(b,c,d)-ans_cnt(a-1,c,d))

Buggy submission (verdict: Runtime Error):
from fractions import math
a,b,c,d=map(int,input().split())

def lcm(x,y):
    return (x*y)//gcd(x,y)

def ans_cnt(i,y,z):
    return i - (i//y + i//z - i//lcm(y,z))

print(ans_cnt(b,c,d)-ans_cnt(a-1,c,d))

Buggy submission (verdict: Runtime Error):
import math
try:
    a,b,c,d=map(int,input().split())
except EOFError:
    pass

def lcm(x,y):
    return (x*y)//math.gcd(x,y)

def ans_cnt(i,y,z):
    return i - (i//y + i//z - i//lcm(y,z))

print(ans_cnt(b,c,d)-ans_cnt(a-1,c,d))

Buggy submission (verdict: Runtime Error):
import math
try:
    a,b,c,d=map(int,input().split())

    def lcm(x,y):
        return (x*y)//math.gcd(x,y)

    def ans_cnt(i,y,z):
        return i - (i//y + i//z - i//lcm(y,z))
    
except EOFError:
    pass

print(ans_cnt(b,c,d)-ans_cnt(a-1,c,d))

Buggy submission (verdict: Runtime Error):
import math
try:
    a,b,c,d=map(int,input().split())

    def lcm(x,y):
        return (x*y)//math.gcd(x,y)

    def ans_cnt(i,y,z):
        return i - (i//y + i//z - i//lcm(y,z))

    print(ans_cnt(b,c,d)-ans_cnt(a-1,c,d))
except EOFError:
    break

Buggy submission (verdict: Runtime Error):
import math
try:
    a,b,c,d=map(int,input().split())

    def lcm(x,y):
        return (x*y)//math.gcd(x,y)

    def ans_cnt(i,y,z):
        return i - (i//y + i//z - i//lcm(y,z))

    print(ans_cnt(b,c,d)-ans_cnt(a-1,c,d))
except EOFError:
    pass

Buggy submission (verdict: Runtime Error):
import math
a,b,c,d=list(map(int,input().split()))

def lcm(x,y):
    return (x*y)//math.gcd(x,y)

def ans_cnt(i,y,z):
    return i - (i//y + i//z - i//lcm(y,z))

print(ans_cnt(b,c,d)-ans_cnt(a-1,c,d))

Buggy submission (verdict: Runtime Error):
import math
a,b,c,d=map(int,input().split())

def lcm(x,y):
    return (x*y)//math.gcd(x,y)

def ans_cnt(i,y,z):
    return i - (i//y + i//z - i//lcm(y,z))

print(ans_cnt(b,c,d)-ans_cnt(a-1,c,d))
Problem p03023 (python)

Fixed submission:
print(180*(int(input())-2))

Buggy submission (verdict: Runtime Error):
print(180*(int(input()-2))

Buggy submission (verdict: Runtime Error):
print(180*(n-2))
Problem p03037 (python)

Fixed submission:
n,m=map(int,input().split())
l=[list(map(int,input().split())) for _ in range(m)]
a=0
z=10**5
for i in range(m):
    a=max(a,l[i][0])
    z=min(z,l[i][1])
if a<=z:
    print(z-a+1)
else:
    print(0)

Buggy submission (verdict: Runtime Error):
n,m=map(int,input().split())
l=[list(map(int,input().split())) for _ in range(m)]
ans=0
for i in range(1,N+1):
    if all([i in range(l[k][0],l[k][1]+1) for k in range(m)]):
        ans+=1
print(ans)
Problem p03086 (python)

Fixed submission:
S = str(input())
ans = [0]
for i in range(len(S)):
    for k in range(i,len(S)):
        if all("ACGT".count(c)==1 for c in S[i:k+1]):
            ans.append(len(S[i:k+1]))
print(max(ans))

Buggy submission (verdict: Runtime Error):
S = str(input())
ans = []
for i in range(len(S)):
    for k in range(i,len(S)):
        if all("ACGT".count(c)==1 for c in S[i:k+1]):
            ans.append(len(S[i:k+1]))
print(max(ans))

Buggy submission (verdict: Runtime Error):
S = str(input())
ans = []
for i in range(len(S)):
    for k in range(i+1,len(S)):
        if all("ACGT".count(c)==1 for c in S[i:k]):
            ans.append(len(S[i:k]))
print(max(ans))
Problem p03126 (python)

Fixed submission:
n,m=map(int,input().split())
a=[0]*m
for _ in range(n):
    b=list(map(int,input().split()))
    for i in b[1:]:
        a[i-1]+=1
print(sum(x==n for x in a))

Buggy submission (verdict: Runtime Error):
n,m=map(int,input().split())
a=[0]*m
for _ in range(n):
    b=list(map(int,input().split()))
    for i in b[1:]:
        a[i]+=1
print(sum(x==n for x in a))
Problem p03239 (python)

Fixed submission:
n,t=map(int,input().split())
c_t=[list(map(int,input().split())) for _ in range(n)]
ans=[]
for i in range(n):
    if c_t[i][1]<=t:
        ans.append(c_t[i][0])
print(min(ans) if sum(ans)>0 else "TLE")

Buggy submission (verdict: Runtime Error):
n,t=map(int,input().split())
c_t=[list(map(int,input().split())) for _ in range(n)]
ans=[]
for i in range(n):
    if c_t[i][1]<=t:
        ans.append(c_t[i][0])
print(min(ans))
Problem p03262 (python)

Fixed submission:
n,x=map(int,input().split())
l=list(map(int,input().split()))
l=sorted([abs(i-x) for i in l],reverse=True)

def gcd(a,b):
    while b!=0:
        a,b=b,a%b
    return a

if n!=1:
    p=gcd(l[0],l[1])
    for i in l[2:]:
        q=gcd(i,p)
        p=q
else:
    p=l[0]
print(p)

Buggy submission (verdict: Runtime Error):
n,x=map(int,input().split())
l=list(map(int,input().split()))
l=sorted([abs(i-x) for i in l],reverse=True)

def gcd(a,b):
    while b!=0:
        a,b=b,a%b
    return a

p=gcd(l[0],l[1])
for i in l[2:]:
    q=gcd(i,p)
    p=q
print(p)
Problem p03371 (python)

Fixed submission:
a,b,c,x,y=map(int,input().split())
l=sorted([a,b,c*2])
if l[0]==c*2:
    print(max(x,y)*c*2)
elif l[1]==c*2:
    if l[0]==a:
        print(y*c*2+max((x-y),0)*a)
    else:
        print(x*c*2+max((y-x),0)*b)
else:
    if a+b>=c*2:
        if x>=y:
            print(y*2*c+(x-y)*a)
        else:
            print(x*2*c+(y-x)*b)
    else:
        print(x*a+y*b)

Buggy submission (verdict: Runtime Error):
a,b,c,x,y=map(int,input().split())
a_b_all=a*x+b*y
ab_all=(c*2)*max(x,y)
mix_a_all=(c*2)*x+b*(y-x)
mix_b_all=(c*2)*y+a*(x-y)
mix_all=max(mix_a_all,mix_b_all)
print(min(a_b_all,ab_all,mix_al))

Buggy submission (verdict: Runtime Error):
a,b,c,x,y=map(int,input().split())
a_b_all=a*x+b*y
ab_all=(c*2)*max(x,y)
mix_a_all=(c*2)*x+b*(y-x)
mix_b_all=(c*2)*y+a*(x-y)
mix_all=max(mix_a_all,mix_b_all)
print(min(a_b_all,ab_all,mix_al))

Buggy submission (verdict: Runtime Error):
a,b,c,x,y=map(int,input().split())
if x>=y:
    if c*2<=min(a,b):
        print(c*2*x)
    elif c*2<=max(a,b):
        if a>=b:
            print(c*2*x)
        else:
            print(c*2*y+a(x-y))
    elif c*2<=a+b:
        print(c*2*y+a*(x-y))
    else:
        print(a*x+b*y)
else:
    if c*2<=min(a,b):
        print(c*2*y)
    elif c*2<=max(a,b):
        if a<=b:
            print(c*2*y)
        else:
            print(c*2*y+b*(y-x))
    elif c*2<=a+b:
        print(c*2*x+b*(y-x))
    else:
        print(a*x+b*y)

Buggy submission (verdict: Runtime Error):
a,b,c,x,y=map(int,input().split())
if x>=y:
    if c*2<=min(a,b):
        print(c*2*x)
    elif c*2<=max(a,b):
        if a>=b:
            print(c*2*x)
        else:
            print(c*2*y+a(x-y))
    elif c*2<=a+b:
        print(c*2*y+a*(x-y))
    else:
        print(a*x+b*y)
else:
    if c*2<=min(a,b):
        print(c*2*y)
    elif c*2<=max(a,b):
        if a<=b:
            print(c*2*y)
        else:
            print(c*2*y+b(y-x))
    elif c*2<=a+b:
        print(c*2*x+b*(y-x))
    else:
        print(a*x+b*y)
Problem p03377 (python)

Fixed submission:
a,b,x=map(int,input().split())
print("YES" if a<=x<=a+b else "NO")

Buggy submission (verdict: Runtime Error):
a,b,x=map(int,input().split()
print("YES" if a+b>=x else "NO")
Problem p03386 (python)

Fixed submission:
a,b,k = map(int,input().split())
r = range(a,b+1)
for i in sorted (set(r[:k])|set(r[-k:])):
    print(i)

Buggy submission (verdict: Runtime Error):
a,b,k=map(int,input().split())
l=list(range(a,b+1))
ans=sorted(set(l[:k])|set(l[-k:]))
for i in ans:
    print(i)

Buggy submission (verdict: Runtime Error):
a,b,k=map(int,input().split())
l=list(range(a,b+1))
ans=sorted(list(set(l[:k]+l[-k:])))
for i in ans:
    print(i)

Buggy submission (verdict: Runtime Error):
a,b,k=map(int,input().split())
l=range(a,b+1)
ans=sorted(list(set(l[:k]+l[-k:])))
for i in ans:
print(i)

Buggy submission (verdict: Runtime Error):
a,b,k=map(int,input().split())
l=list(range(a,b+1))
ans=sorted(list(set(l[:k]+l[-k:])))
for i in ans:
    print(i)

Buggy submission (verdict: Runtime Error):
a,b,k=map(int,input().split())
l=list(range(a,b+1))
ans=sorted(list(set(l[:k]+l[-k:])))
for i in ans:
    print(i)
Problem p03478 (python)

Fixed submission:
N , A , B = map(int , input().split())
ans = 0
for n in range(1,N+1):
  sum_num = sum(list(map(int , str(n))))
  if A<=sum_num<=B:
    ans += n
print(ans)

Buggy submission (verdict: Runtime Error):
N , A , B = map(int , input().split())
ans = 0
for n in range(1,N+1):
  sum = sum(list(map(int , str(n))))
  if A<=sum<=B:
    ans += n
print(ans)
Problem p03680 (python)

Fixed submission:
n=int(input())
a=[int(input()) for _ in range(n)]
ans=-1
b=a[0]
if b==2:
    print(1)
else:
    for i in range(n):
        b=a[b-1]
        # print(f"b={b}")
        if b==2:
            ans=i+2
            break
    print(ans)

Buggy submission (verdict: Runtime Error):
n=int(input())
a=[int(input()) for _ in range(n)]
ans=-1
b=a[0]
if b==2:
    print(1)
    break
else:
    for i in range(n):
        b=a[b-1]
        # print(f"b={b}")
        if b==2:
            ans=i+2
            break
    print(ans)
Problem p04029 (python)

Fixed submission:
n=int(input())
ans=0
for i in range(1,n+1):
    ans+=i
print(ans)

Buggy submission (verdict: Runtime Error):
n,k,x,y=[int(input()) for _ in range(4)]
print(k*x+(n-k)*y if n>k else n*x)
Problem p02628 (python)

Fixed submission:
n,k = map(int,input().split(" "))
p = list(map(int,input().split(" ")))

p.sort()
#print(p)

ans = 0
for i in range(k):
    ans = ans + p[i]

print(ans)

Buggy submission (verdict: Runtime Error):
n,k = map(int,input().split(" "))
p = list(map(int,input().split(" "))).sort()
ans = 0

for i in range(k):
    ans = ans + p[i]

print(ans)
Problem p02645 (python)

Fixed submission:
import random


S = input()
n = len(S)
i = 0+int(random.random()*(n-3))
print(S[i]+S[i+1]+S[i+2])

Buggy submission (verdict: Runtime Error):
import random

S = input()
n = len(S)
i = 1+int(random.random()*(n-3))
print(S[i]+S[i+1]+S[i+2])

Buggy submission (verdict: Runtime Error):
import random

S = input()
n = len(S)

i = 1+int(random.random()*(n-3))

print(S[i]+S[i+1]+S[i+2])

Buggy submission (verdict: Runtime Error):
import random

S = input()
n = length(S)

i = 1+int(random.random()*(n-3))

print(S[i]+S[i+1]+S[i+2])
Problem p02646 (python)

Fixed submission:
A,V = map(int,input().split())
B,W = map(int,input().split())
T = int(input())

dis = abs(A-B)
v = V-W

if v > 0 and dis/v <= T:
  	print("YES")
else:
  print("NO")

Buggy submission (verdict: Runtime Error):
A,V = map(int,input().split())
B,W = map(int,input().split())
T = int(input())

dis = abs(A-B)
v = V-W

if v >= 0 and dis/v <= T:
  print("Yes")
else:
  print("No")

Buggy submission (verdict: Runtime Error):
A,V = map(int,input().split())
B,W = map(int,input().split())
T = int(input())

dis = abs(A-b)
v = V-W

if v >= 0 and dis/v <= T:
  print("Yes")
else:
  print("No")
Problem p02767 (python)

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

minimum = 10000000

for n in range(1,max(X)+1):
  kyori = 0
  for i in range(N):
    kyori += (X[i]-n)**2
  if kyori < minimum:
    minimum = kyori
print(minimum)

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

minimum = 10000000

for n in range(1,N+1):
  d = 0
  for i in range(N):
    d += (X[i]-n)**2
  print(d)
  if kyori < minimum:
    minimum = kyori
print(minimum)
Problem p03416 (python)

Fixed submission:
A,B = map(int,input().split())
count = 0
 
for i in range(A,B+1):
  i = str(i)
  if i[0] == i[4] and i[1] == i[3]:
    count += 1
    
print(count)

Buggy submission (verdict: Runtime Error):
A,B = map(int,input().split())
count = 0

for i in range(A,B+1):
  if i[0] == i[4] and i[1] == i[3]:
    count += 1
    
print(count)
Problem p03760 (python)

Fixed submission:
O = input()
E = input()
Ans = []

if len(O) - len(E) == 0:
  for i in range(len(O)):
  	Ans.append(O[i])
  	Ans.append(E[i])
else:
  for i in range(len(E)):
    Ans.append(O[i])
    Ans.append(E[i])
  Ans.append(O[len(O)-1])
  
print(''.join(Ans))

Buggy submission (verdict: Runtime Error):
O = input()
E = input()
Ans = []

for i in range(len(O)):
  Ans.append(O[i])
  Ans.append(E[i])
  
mojiretu = ''.join(Ans)
print(mojiretu)
Problem p02573 (python)

Fixed submission:
import sys
input = sys.stdin.readline
INF = 10**18
sys.setrecursionlimit(10**6)

def li():
    return [int(x) for x in input().split()]

class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if x == y:
            return
        if self.parents[x] > self.parents[y]:
            x, y = y, x
        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        root = self.find(x)
        return -self.parents[root]

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())

N, M = li()
uf = UnionFind(N)
for i in range(M):
    a, b = li()
    uf.union(a-1, b-1)

ans = max(uf.size(x) for x in range(N))
print(ans)

Buggy submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline
INF = 10**18
sys.setrecursionlimit(10**6)

def li():
    return [int(x) for x in input().split()]

N, M = li()
L = []
for i in range(M):
    a, b = sorted(li())
    L.append((a, b))

L = set(L)

cnts = [0] * (N+1)

for l in L:
    a, b = l
    cnts[a] += 1
    cnts[b] += 1
# print(cnts)
p = cnts.index(max(cnts))
# print(p)

others = []
for l in L:
    a, b = l
    if a == p:
        others.append(b)
    elif b == p:
        others.append(a)

anothers = []
for other in others:
    for l in L:
        a, b = l
        if a == other:
            anothers.append(b)
        elif b == other:
            anothers.append(a)
#
# print(others)
# print(anothers)

all = list(set(others + anothers))
all.remove(p)
ans = len(all) + 1
print(ans)
Problem p02579 (python)

Fixed submission:
from collections import deque
h,w=map(int,input().split())
ch,cw=map(int,input().split())
dh,dw=map(int,input().split())
s=[list(input()) for i in range(h)]
 
#幅優先で解く。
dx=[1,0,-1,0]
dy=[0,1,0,-1]
def bfs():
  maze=[[-1]*w for i in range(h)]
  maze[ch-1][cw-1]=0
  qu=deque([])
  qu.append((cw-1,ch-1))
  magic=0
  
  while qu:
    x,y=qu.popleft()
    for i in range(4):
      nx=dx[i]+x
      ny=dy[i]+y
      if 0<=nx<=w-1 and 0<=ny<=h-1 and s[ny][nx]=="." and (maze[ny][nx]==-1 or maze[ny][nx]>maze[y][x]):
        qu.appendleft((nx,ny))
        maze[ny][nx]=maze[y][x]
    for i in range(x-2,x+3):
      for j in range(y-2,y+3):
        nx=i
        ny=j
        if 0<=nx<=w-1 and 0<=ny<=h-1 and s[ny][nx]=="." and (maze[ny][nx]==-1 or maze[ny][nx]>maze[y][x]+1):
          qu.append((nx,ny))
          maze[ny][nx]=maze[y][x]+1
  return maze
    
maze = bfs()
print(maze[dh-1][dw-1])

Buggy submission (verdict: Runtime Error):
import sys

INF = 10 ** 18
sys.setrecursionlimit(10 ** 6)
from collections import defaultdict


def li():
    return [int(x) for x in input().split()]


from collections import deque

H, W = li()
Ch, Cw = li()
Dh, Dw = li()
S = [list(input()) for x in range(H)]

dx = [1, 0, -1, 0]
dy = [0, 1, 0, -1]


def bfs():
    costmap = [[-1] * W for i in range(H)]
    costmap[Ch - 1][Cw - 1] = 0
    que = deque([])
    que.append((Cw - 1, Ch - 1))

    while que:
        # print(que)
        # 左から取り出す
        x, y = que.popleft()
        # 通常移動パターン
        for i in range(4):
            nx = x + dx[i]
            ny = y + dy[i]
            # バリデーション
            if nx <= 0 or nx > W or ny <= 0 or ny > H:
                continue
            if S[ny][nx] != '.':
                continue
            # 初探索 or コストが下がる場合
            if costmap[ny][nx] == -1 or costmap[y][x] < costmap[ny][nx]:
                # コストゼロは左から
                que.appendleft((nx, ny))
                costmap[ny][nx] = costmap[y][x]
        # 特殊移動パターン
        for i in range(x - 2, x + 3):
            for j in range(y - 2, y + 3):
                nx, ny = i, j
                # バリデーション
                if nx <= 0 or nx > W or ny <= 0 or ny > H:
                    continue
                if S[ny][nx] != '.':
                    continue
                # 初探索 or コストが下がる場合
                if costmap[ny][nx] == -1 or costmap[y][x] + 1 < costmap[ny][nx]:
                    # コスト1は右から
                    que.append((nx, ny))
                    costmap[ny][nx] = costmap[y][x] + 1
    return costmap


costmap = bfs()
# print(costmap)
print(costmap[Dh - 1][Dw - 1])
Problem p02615 (python)

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

def li():
    return [int(x) for x in input().split()]

N = int(input())
A = li()

A.sort(reverse=True)

B = [A[i] for i in range(N) if i < N//2]

# 9 8 7 6 5
# 9 1 8 2 7 3 6 4 5
# 9 6 8 7
# 9+8+8+7+7+6+6+5

# 8 7 6 5
# 8 1 7 2 6 3 5 4
# 8+7+6+5+5+6+7

if N % 2 == 1:
    B = [A[i] for i in range(N) if i < N // 2 + 1]
    sm = B[0] + B[-1] + sum(B[i]*2 for i in range(N//2) if 0 < i)
    print(sm)
else:
    sm = B[0] + sum(B[i]*2 for i in range(N//2) if 0 < i)
    print(sm)

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

def li():
    return [int(x) for x in input().split()]

N = int(input())
A = li()

A.sort(reverse=True)

B = [A[i] for i in range(N) if i < N//2]

# 9 8 7 6 5
# 9 1 8 2 7 3 6 4 5
# 9 6 8 7
# 9+8+7+6+5+6+7+8

# 8 7 6 5
# 8 1 7 2 6 3 5 4
# 8+7+6+5+5+6+7

sm = B[0] + sum(B[i] * 2 for i in range(N/2) if 0 < i)
print(sm)
Problem p02641 (python)

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

def calc():
    x, n = [int(x) for x in input().split()]

    if n == 0:
        q = [x for x in range(102)]
    else:
        p = [int(x) for x in input().split()]
        q = [x for x in range(102) if x not in p]
    diffs = [abs(x - qk) for qk in q]
    mindiff = min(diffs)
    idx = diffs.index(mindiff)
    print(q[idx])

calc()

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

x, n = [int(x) for x in input().split()]
if n == 0:
    q = [x for x in range(1, 101)]
else:
    p = [int(x) for x in input().split()]
    q = [x for x in range(1, 101) if x not in p]

diffs = [abs(x-qk) for qk in q]
mindiff = min(diffs)
idx = diffs.index(mindiff)
print(q[idx])

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

x, n = [int(x) for x in input().split()]
p = [int(x) for x in input().split()]

q = [x for x in range(1, 101) if x not in p]
diffs = [abs(x-qk) for qk in q]
mindiff = min(diffs)
idx = diffs.index(mindiff)
print(q[idx])
Problem p02642 (python)

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

n = int(input())
a = [int(x) for x in input().split()]
maxval = 10 ** 6
factor_cnt = [0] * (maxval+1)
factor_cnt[0] = 2
for i in range(n):
    if factor_cnt[a[i]] > 1:
        continue
    for k in range(a[i], maxval+1, a[i]):
        factor_cnt[k] += 1

result = sum(factor_cnt[v] <= 1 for v in a)
print(result)

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

n = int(input())
a = [int(x) for x in input().split()]
maxval = 10 ** 6
has_prime_factor = [0] * (maxval+1)
has_prime_factor[0] = 2
has_prime_factor[1] = 2
for i in range(n+1):
    if a[i] == 1:
        continue
    if has_prime_factor[a[i]] > 1:
        continue
    for k in range(a[i], maxval+1, a[i]):
        has_prime_factor[k] += 1

result = sum(has_prime_factor[v] <= 1 for v in a)
print(result)