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

Fixed submission:
n, l=map(int,input().split())
lists = []
taste = 0
for i in range(1,n+1):
	taste += l+i-1
	lists.append(l+i-1)
print(taste-min(lists, key=abs))

Buggy submission (verdict: Runtime Error):
n, l=map(int,input())
lists = []
for i in range(1,n+1):
	taste += l+i-1
	lists.append(abs(l+i-1))
lists.sort()
print(taste-lists[0])
Problem p02995 (python)

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

def lcm(m,n):
	return (m*n)//gcd(m,n)

def divnumber(c):
	ans=lenth//c
	rem1=a%c
	if rem1==0:rem1+=c
	rem2=lenth%c-1
	if rem1+rem2>=c:
		ans+=1
	return ans

print(lenth-divnumber(c)-divnumber(d)+divnumber(lcm(c,d)))

Buggy submission (verdict: Runtime Error):
import math
a, b, c, d= list(map(int, input().split()))
m=0
x, y, z=[0,0,0]
def lcm(a, b):
	return int(a*b/math.gcd(a,b))
for i in range(a,b+1):
	if i%c==0:
		x=1+math.floor((b-i)/c)
		break
for i in range(a,b+1):
	if i%d==0:
		y=1+math.floor((b-i)/d)
		break
for i in range(a,b+1):
	if i%lcm(c,d)==0:
		z=1+math.floor((b-i)/lcm(c,d))
		break
print(b-a+1-x-y+z)
# print(x, y, z)
# print(lcm(c, d))
# print(math.gcd(c,d))

Buggy submission (verdict: Runtime Error):
import math
a, b, c, d= list(map(int, input().split()))
m=0
x, y, z=[0,0,0]
def lcm(a, b):
	return int(a*b/math.gcd(a,b))
for i in range(a,b+1):
	if i%c==0:
		x=1+math.floor((b-i)/c)
		break
for i in range(a,b+1):
	if i%d==0:
		y=1+math.floor((b-i)/d)
		break
for i in range(a,b+1):
	if i%lcm(c,d)==0:
		z=1+math.floor((b-i)/lcm(c,d))
		break
print(b-a+1-x-y+z)
# print(x, y, z)
# print(lcm(c, d))
# print(math.gcd(c,d))

Buggy submission (verdict: Runtime Error):
import math
a, b, c, d= list(map(int, input().split()))
m=0
for i in range(a,b+1):
	if i%c==0:
		x=1+math.floor((b-i)/c)
		break
for i in range(a,b+1):
	if i%d==0:
		y=1+math.floor((b-i)/d)
		break
for i in range(a,b+1):
	if i%(c*d)==0:
		z=1+math.floor((b-i)/(c*d))
		break
print(b-a+1-x-y+z)
# print(x, y, z)

Buggy submission (verdict: Runtime Error):
import math
a, b, c, d= list(map(int, input().split()))
m=0
for i in range(a,b+1):
	if i%c==0:
		x=1+math.floor((b-i)/c)
		break
for i in range(a,b+1):
	if i%d==0:
		y=1+math.floor((b-i)/d)
		break
for i in range(a,b+1):
	if i%(c*d)==0:
		z=1+math.floor((b-i)/(c*d))
		break
print(b-a+1-x-y+z)
print(x, y, z)
Problem p03032 (python)

Fixed submission:
#!/usr/bin/env python3
n, k = map(int, input().split())
v = list(map(int, input().split()))
r = min(n, k)
ans = -float('inf')
for i in range(r+1):
    a = v[:i]
    for j in range(r+1-i):
        candi = a[:]
        if j != 0:
            candi += v[-j:]
        candi.sort()
        for t in range(k-i-j):
            if not 0 <= t < len(candi):
                break
            if candi[t] < 0:
                candi[t] = 0
            else:
                break
        candi = sum(candi)
        ans = max(candi, ans)
print(ans)

Buggy submission (verdict: Runtime Error):
n, k = map(int, input().split())
v = list(map(int, input().split()))
r = min(n, k)
ans = -float('inf')
for i in range(r+1):
    a = v[:i]
    for j in range(r+1-i):
        candi=a[:]
        if j !=0 :candi += v[-j:]
        candi.sort()
        for t in range(k-i-j):
            if not 0<=t<len(candi):break
            if candi[t] < 0:
                candi[t] = 03023
            else:
                break
        candi = sum(candi)
        ans = max(candi, ans)
print(ans)
Problem p03044 (python)

Fixed submission:
#!/usr/bin/env python3
n=int(input())
uvw=[list(map(int,input().split())) for i in range(n-1)]
graph=[[] for i in range(n+1)]
color=[-1]*(n+1)
for u,v,w in uvw:
    graph[u].append((v,w))
    graph[v].append((u,w))

color[1]=1
ne=[1]
while ne:
    t=ne.pop()
    for v,w in graph[t]:
        if color[v]==-1:
            ne.append(v)
            color[v]=color[t] if w%2==0 else (color[t]+1)%2

for i in range(1,n+1):
    print(color[i])

Buggy submission (verdict: Runtime Error):
#!/usr/bin/env python3
import copy


class UnionFind:
    __slots__ = ['id', 'sz']

    def __init__(self, n):
        self.id = [-1] * n
        self.sz = n

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

    def find(self, x, y):
        return uf.root(x) == uf.root(y)

    def union(self, x, y):
        s1, s2 = self.root(x), self.root(y)
        if s1 != s2:
            if self.id[s1] <= self.id[s2]:
                self.id[s1] += self.id[s2]
                self.id[s2] = s1
            else:
                self.id[s2] += self.id[s1]
                self.id[s1] = s2
            self.sz -= 1
            return True
        return False


n = int(input())
uvw = [list(map(int, input().split())) for i in range(n-1)]
groop = [-1]*n
groop[0] = 1
l = [0, 1]
uf = UnionFind(n)
uvw.sort()
while uvw:

    nextlist = []
    for i in range(n-1):
        u, v, w = uvw[i]
        if groop[u-1] >= 0:
            if w % 2:
                groop[v-1] = l[l.index(groop[u-1])-1]
            else:
                groop[v-1] = groop[u-1]
        elif groop[v-1] >= 0:
            if w % 2:
                groop[u-1] = l[l.index(groop[v-1])-1]
            else:
                groop[u-1] = groop[v-1]
        else:
            nextlist.append((u, v, w))
    uvw = copy.deepcopy(nextlist)
for g in groop:
    print(1 if g else 0)
Problem p03061 (python)

Fixed submission:
#!/usr/bin/env python3
from fractions import gcd
n=int(input())
a=list(map(int,input().split()))
m=[0]*n
L,R=[0]*(n+1),[0]*(n+1)
for i in range(1,n+1):
    L[i]=gcd(L[i-1],a[i-1])
    R[n-i]=gcd(R[n-i+1],a[n-i])
for i in range(n):
    m[i]=gcd(L[i],R[i+1])
print(max(m))

Buggy submission (verdict: Runtime Error):
#!/usr/bin/env python3
from math import gcd
n=int(input())
a=list(map(int,input().split()))
m=[0]*n
L,R=[0]*(n+1),[0]*(n+1)
for i in range(1,n+1):
    L[i]=gcd(L[i-1],a[i-1])
    R[n-i]=gcd(R[n-i+1],a[n-i])
for i in range(n):
    m[i]=gcd(L[i],R[i+1])
print(max(m))
Problem p03081 (python)

Fixed submission:
#!/usr/bin/env python3
import sys
input = lambda: sys.stdin.readline()[:-1]
sys.setrecursionlimit(10**8)
inf = float('inf')
mod = 10**9+7

n,q=map(int,input().split())
s=input()
td=[]
for i in range(q):
    td.append(input().split())

#左に集まる中でもっとも右の点を探す
ok1=-1
left=0
right=n
while left<right:
    mid=(left+right)//2
    tmp=mid
    for t,d in td:
        if s[tmp]==t:
            tmp=tmp-1 if d=='L' else tmp+1
        if tmp==-1 or tmp==n:
            break
    if tmp==-1:
        left=mid+1
        ok1=max(ok1,mid)
    else:
        right=mid

#右に集まる中でもっとも左の点を探す

ok2=n
left=0
right=n
while left<right:
    mid=(left+right)//2
    tmp=mid
    for t,d in td:
        if s[tmp]==t:
            tmp=tmp-1 if d=='L' else tmp+1
        if tmp==n or tmp==-1:break
    if tmp == n:
        right=mid
        ok2=min(ok2,mid)
    else:
        left=mid+1

print(max(0,ok2-ok1-1))
# print(ok2,ok1)

Buggy submission (verdict: Runtime Error):
#!/usr/bin/env python3
import sys
input = lambda: sys.stdin.readline()[:-1]
sys.setrecursionlimit(10**8)
inf = float('inf')
mod = 10**9+7

n,q=map(int,input().split())
s=input()
td=[]
for i in range(q):
    td.append(input().split())

#左に集まる中でもっとも右の点を探す
ok1=-1
left=0
right=n
while left<right:
    mid=(left+right)//2
    tmp=mid
    for t,d in td:
        if s[tmp]==t:
            tmp=tmp-1 if d=='L' else tmp+1
        if tmp==-1:
            break
    if tmp==-1:
        left=mid+1
        ok1=max(ok1,mid)
    else:
        right=mid

#右に集まる中でもっとも左の点を探す

ok2=n
left=0
right=n
while left<right:
    mid=(left+right)//2
    tmp=mid
    for t,d in td:
        if s[tmp]==t:
            tmp=tmp-1 if d=='L' else tmp+1
        if tmp==n:break
    if tmp == n:
        right=mid
        ok2=min(ok2,mid)
    else:
        left=mid+1

print(max(0,ok2-ok1-1))
# print(ok2,ok1)
Problem p03096 (python)

Fixed submission:
import sys, math, itertools, collections, bisect
input = lambda: sys.stdin.buffer.readline().rstrip().decode('utf-8')
inf = float('inf') ;mod = 10**9+7
mans = inf ;ans = 0 ;count = 0 ;pro = 1

n = int(input())
C = [int(input()) for i in range(n)]
pairs = [-1]*(n+1)
data = [-1]*(2*10**5+1)
for i,ci in enumerate(C):
  if data[ci] != -1 and abs(i-data[ci]) != 1:
    pairs[data[ci]] = i
  data[ci] = i
imos = [0] * (n+1)
for i in range(n-1,-1,-1):
  # ペアを持たないとき
  if pairs[i] == -1:
    imos[i] = imos[i+1]
    # print(i,imos[i],imos[i+1])
  else:
    j = pairs[i]
    imos[i] = imos[i+1] + imos[j] + 1
    imos[i] %= mod
  # ans += imos[i] + imos[j]
  # ans %= mod
  # imos[i-1] += imos[i]
print((imos[0]+1)%mod)
# print((ans+1)%mod)
# print(imos)

Buggy submission (verdict: Runtime Error):
import sys, math, itertools, collections, bisect
input = lambda: sys.stdin.buffer.readline().rstrip().decode('utf-8')
inf = float('inf') ;mod = 10**9+7
mans = inf ;ans = 0 ;count = 0 ;pro = 1
def solve_binary(mid,j):
    return pairs[mid][0] >= j
    pass

def binary_search(n,j):
    ok=n
    ng=0
    while abs(ok-ng)>1:
        mid=(ok+ng)//2
        if solve_binary(mid,j):
            ok=mid
        else:
            ng=mid
    return ok

n = int(input())
C = [int(input()) for i in range(n)]
pairs = []
data = [-1]*(n+1)
for i,ci in enumerate(C):
  if data[ci] != -1 and abs(i-data[ci]) != 1:
    pairs.append((data[ci],i))
  data[ci] = i
pairs.sort()
l = len(pairs)
for i,j in pairs:
  k = binary_search(l,j)
  # print(k,12345)
  ans += l-k+1
  ans %= mod
print(ans+1)
# print(pairs)
Problem p03140 (python)

Fixed submission:
#!/usr/bin/env python3
import sys, math, itertools, collections, bisect
input = lambda: sys.stdin.buffer.readline().rstrip().decode('utf-8')
inf = float('inf') ;mod = 10**9+7
mans = inf ;ans = 0 ;count = 0 ;pro = 1

n=int(input())
a=input()
b=input()
c=input()
def f(a,b,c):
  re=2
  if a==b:
    re-=1
  if c==b:
    re-=1
  if a==c:
    re-=1
  return max(0,re)
for i in range(n):
  count += f(a[i],b[i],c[i])
print(count)

Buggy submission (verdict: Runtime Error):
#!/usr/bin/env python3
import sys, math, itertools, collections, bisect
input = lambda: sys.stdin.buffer.readline().rstrip().decode('utf-8')
inf = float('inf') ;mod = 10**9+7
mans = inf ;ans = 0 ;count = 0 ;pro = 1

n=int(input())
a,b,c=[input() for i in range(3)]
for i in range(n):
  ans += len(set(a[i],b[i],c[i])) - 1
print(ans)
Problem p03169 (python)

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

S = [0] * 3
for a in A:
  S[a-1] += 1
I, J, K = S

dp = [[[0.0] * (N+1) for j in range(N+1)] for i in range(N+1)]

for k in range(S[2] + 1):
  for j in range(S[1] + S[2] - k + 1):
    for i in range(S[0] + S[1] + S[2] - j - k + 1):
      if i == j == k == 0: continue
      dp[i][j][k] = (i * (dp[i-1][j][k] if i > 0 else 0) + j * (dp[i+1][j-1][k] if j > 0 else 0) + k * (dp[i][j+1][k-1] if k > 0 else 0) + N) / (i + j + k)

print(dp[I][J][K])

Buggy submission (verdict: Runtime Error):
#!/usr/bin/env python3
import sys, math, itertools, collections, bisect
input = lambda: sys.stdin.buffer.readline().rstrip().decode('utf-8')
inf = float('inf') ;mod = 10**9+7
mans = inf ;ans = 0 ;count = 0 ;pro = 1

n=int(input())
L=list(map(int,input().split()))
A = L.count(1)
B = L.count(2)
C = L.count(3)
dp=[[[-1] * (301) for i in range(301)] for i in range(301)]

for a in range(n):
  for b in range(n):
    for c in range(n):
      result = n
      result += (dp[a-1][b][c] if a-1 >= 0 else 0)
      result += (dp[a+1][b-1][c] if b-1 >= 0 else 0)
      result += (dp[a][b+1][c-1] if c-1 >= 0 else 0)
      dp[a][b][c]=result / (a+b+c)

print(dp[A][B][C])

Buggy submission (verdict: Runtime Error):
#!/usr/bin/env python3
import sys, math, itertools, collections, bisect
input = lambda: sys.stdin.buffer.readline().rstrip().decode('utf-8')
inf = float('inf') ;mod = 10**9+7
mans = inf ;ans = 0 ;count = 0 ;pro = 1
# sys.setrecursionlimit(10**7)

n=int(input())
L=list(map(int,input().split()))
A = L.count(1)
B = L.count(2)
C = L.count(3)
dp=[[[-1] * (301) for i in range(301)] for i in range(301)]

for a in range(n):
  for b in range(n):
    for c in range(n):
      result = n
      result += dp[a-1][b][c] if a-1 >= 0 else 0
      result += dp[a+1][b-1][c] if b-1 >= 0 else 0
      result += dp[a][b+1][c-1] if c-1 >= 0 else 0
      dp[a][b][c]=result / (a+b+c)

print(dp[A][B][C])

Buggy submission (verdict: Runtime Error):
#!/usr/bin/env python3
import sys, math, itertools, collections, bisect
input = lambda: sys.stdin.buffer.readline().rstrip().decode('utf-8')
inf = float('inf') ;mod = 10**9+7
mans = inf ;ans = 0 ;count = 0 ;pro = 1
sys.setrecursionlimit(10**7)

n=int(input())
L=list(map(int,input().split()))
A = L.count(1)
B = L.count(2)
C = L.count(3)
dp=[[[-1] * (301) for i in range(301)] for i in range(301)]

for a in range(n):
  for b in range(n):
    for c in range(n):
      result = n
      result += dp[a-1][b][c] if a-1 >= 0 else 0
      result += dp[a+1][b-1][c] if b-1 >= 0 else 0
      result += dp[a][b+1][c-1] if c-1 >= 0 else 0
      dp[a][b][c]=result / (a+b+c)

print(dp[A][B][C])

# def rec (a,b,c):
#   if not (a >= 0 and b >= 0 and c >= 0):
#     return 0
#   if a == b == c == 0:
#     return 0
#   if dp[a][b][c] != -1:
#     return dp[a][b][c]
#   result = n
#   result += rec(a-1,b,c) * a
#   result += rec(a+1,b-1,c) * b
#   result += rec(a,b+1,c-1) * c
#   dp[a][b][c] = result / (a+b+c)
#   return dp[a][b][c]

# print(rec(A,B,C))
Problem p03239 (python)

Fixed submission:
N,T=map(int,input().split())
ct=[tuple(map(int,input().split())) for i in range(N)]
ans=10**9
for c,t in ct:
    if T<t:
        continue
    else:
        ans=min(ans,c)
print(ans if ans!=10**9 else 'TLE')

Buggy submission (verdict: Runtime Error):
N,T=map(int,input().split())
ct=[tuple(map(int,input().split())) for i in range(n)]
ans=10**9
for c,t in ct:
    if T<t:
        continue
    else:
        ans=min(ans,c)
print(ans if ans!=10**9 else 'TLE')
Problem p03319 (python)

Fixed submission:
#!/usr/bin/env python3
import sys, math, itertools, collections, bisect
input = lambda: sys.stdin.buffer.readline().rstrip().decode('utf-8')
inf = float('inf') ;mod = 10**9+7
mans = inf ;ans = 0 ;count = 0 ;pro = 1
def ceil(x,y):
  return (x-1)//y+1

n,k = map(int,input().split())
A = list(map(int,input().split()))
for i,ai in enumerate(A):
  if ai == 1:
    ind1 = i
print(ceil(n-1,k-1))

Buggy submission (verdict: Runtime Error):
#!/usr/bin/env python3
import sys, math, itertools, collections, bisect
input = lambda: sys.stdin.buffer.readline().rstrip().decode('utf-8')
inf = float('inf') ;mod = 10**9+7
mans = inf ;ans = 0 ;count = 0 ;pro = 1
def ceil(x,y):
  return (x-1)//y+1

n,k = map(int,input().split())
A = list(map(int,input().split()))
for i,ai in enumerate(A):
  if ai == 1:
    ind1 = i
print(ceil(n-1,k-1)))
Problem p03469 (python)

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

Buggy submission (verdict: Runtime Error):
s=input()
print("2018"+s[4:]
Problem p03471 (python)

Fixed submission:
n,y=map(int,input().split())
for i in range(n+1):
  for j in range(n+1-i):
    k=n-i-j
    if i*10000+j*5000+k*1000==y:
      print(i,j,k)
      exit()
print(-1,-1,-1)

Buggy submission (verdict: Runtime Error):
n,y=map(int,input())
for i in range(n):
  for j in range(i,n):
    k=n-i-j
    if i*10000+j*5000+k*1000==y:
      print(i,j,k)
      exit()
print(-1,-1,-1)
Problem p03478 (python)

Fixed submission:
#!/usr/bin/env python3
ans=0
n,a,b=map(int,input().split())
for i in range(1,n+1):
    count=0
    for j in str(i):
        count+=int(j)
    if a<=count<=b:
        ans+=i
print(ans)

Buggy submission (verdict: Runtime Error):
#!/usr/bin/env python3
ans=0
n,a,b=map(int,input().split())
for i in range(1,n):
    count=0
    for j in str(i):
        count+=j
    if a<=count<=b:
        ans+=1
print(ans)
Problem p03523 (python)

Fixed submission:
A="AKIHABARA"
data=[0,4,6,8]
AD=list(A)
S=set(); S.add(A)
for i in range(2):
    for j in range(2):
        for k in range(2):
            for l in range(2):
                tmp=AD.copy()
                # print(AD)
                # print(tmp)
                if i: tmp[0]=""
                if j: tmp[4]=""
                if k: tmp[6]=""
                if l: tmp[8]=""
                S.add(''.join(tmp))


s=input()
if s in S:
    print("YES")
else:
    print("NO")

Buggy submission (verdict: Runtime Error):
A="AKIHABARA"
s=input()
n=len(s)
na=len(A)
i=0
j=0
while i<n j<na-1:
  if s[i]==A[j]:
    i+=1; j+=1
  elif s[i]!=A[j] and A[j]=="A":
    j+=1
  else:
    break
if j==n-1:
  print("YES")
else:
  print("NO")

Buggy submission (verdict: Runtime Error):
A="AKIHABARA"
s=input()
n=len(s)
na=len(A)
i=0
j=0
while i<=n j<=na-1:
  if s[i]==A[j]:
    i+=1; j+=1
  elif s[i]!=A[j] and A[j]=="A":
    j+=1
  else:
    break
if j==n-1:
  print("YES")
else:
  print("NO")
Problem p03545 (python)

Fixed submission:
import sys
a,b,c,d=[x for x in input()]
op='+-'
for op1 in op:
  for op2 in op:
    for op3 in op:
      ans=a+op1+b+op2+c+op3+d
      if eval(ans)==7:
        print('{}=7'.format(ans))
        sys.exit()
      else:
        pass

Buggy submission (verdict: Runtime Error):
a,b,c,d=[x for x in input()]
op='+-'
for op1 in op:
  for op2 in op:
    for op3 in op:
      ans=A+op1+B+op2+C+op3+D
      if eval(ans)==7:
        print('{}=7'.format(ans))
        exit()
      else:
        pass

Buggy submission (verdict: Runtime Error):
a,b,c,d=[x for x in input()]
op='+-'
for op1 in op:
  for op2 in op:
    for op3 in op:
      ans=A+op1+B+op2+C+op3+D
      if eval(ans)==7:
        print('{}=7'.format(ans))
        sys.exit()
      else:
        pass
Problem p03697 (python)

Fixed submission:
a,b=map(int,input().split())
if a+b>=10:
  print('error')
else:
  print(a+b)

Buggy submission (verdict: Runtime Error):
a,b=map(int,input().split())
if a+b>=10:
  print('error')
else:
  print(a+b
Problem p03713 (python)

Fixed submission:
h,w=map(int,input().split())
candidate=[0]*4
if h*w%3==0:
	print(0)
	exit()

def solve(a,b,k):
	candidate[k]=a
	cnd=float('inf')
	for i in range(a+1):
		c1=b*i
		c2=(a-i)*(b//2)
		c3=(a-i)*(b-b//2)
		cnd=min(cnd,max(c1,c2,c3)-min(c1,c2,c3))
	candidate[k+1]=cnd

solve(h,w,0)
solve(w,h,2)
print(min(candidate))

Buggy submission (verdict: Runtime Error):
h,w=map(int,input().split())
candidate=[0]*4
if h*w%3==0:
	print(0)
	exit()
def solve(a,b,k):
	candidate[k]=a
	if b%2==0:
		cnd=float('inf')
		for i in range(a//2+1):
			cnd=min(abs(b-3*i),cnd)
		candidate[k+1]=(cnd*a//2,i)
	else:
		cnd=float('inf')
		for i in range(a//2+1):
			cnd=min(cnd,max(abs(a//2*(b-i)-a*i),abs(a//2*(b-i)-a*i+b-i),abs(b-i)))
			candidate[k+1]=(cnd,i)
solve(h,w,0)
solve(w,h,2)
print(min(candidate))
Problem p03714 (python)

Fixed submission:
#!/usr/bin/env python3
import sys, math, heapq,copy
input = lambda: sys.stdin.buffer.readline().rstrip().decode('utf-8')
sys.setrecursionlimit(10**8)
inf = float('inf')
ans=count=0


ans = -inf
n = int(input())
A = list(map(int, input().split()))
AL, AR = A[:n], A[2*n:]
al,ar=copy.copy(AL),copy.copy(AR)
AN = A[n:2*n]
LS, RS = sum(AL), sum(AR)
AR = list(map(lambda ddd: -ddd, AR))
heapq.heapify(AL)
heapq.heapify(AR)
tmp=LS
ANSR=[0]*n
ANSL=[0]*n

for i in range(n):
    if AN[i]-AL[0] >0:
        LS = LS-heapq.heappop(AL)+AN[i]
        heapq.heappush(AL,AN[i])
    ANSL[i] = LS

LS=tmp
for j in range(n-1,-1,-1):
    if 0 < -AR[0]-AN[j]:
        RS = RS+heapq.heappop(AR)+AN[j]
        heapq.heappush(AR,-AN[j])
    ANSR[j] = RS
ANSR=ANSR+[sum(ar)]
ANSL=[sum(al)]+ANSL
for i in range(n+1):
    ans=max(ans,ANSL[i]-ANSR[i])
print(ans)
# print(ANSL,ANSR)

Buggy submission (verdict: Runtime Error):
#!/usr/bin/env python3
import sys, math, heapq
input = lambda: sys.stdin.buffer.readline().rstrip().decode('utf-8')
sys.setrecursionlimit(10**8)
inf = float('inf')
ans=count=0


ans = -inf
n = int(input())
A = list(map(int, input().split()))
AL, AR = A[:n], A[2*n:]
al,ar=AL.copy(),AR.copy()
AN = A[n:2*n]
LS, RS = sum(AL), sum(AR)
AR = list(map(lambda ddd: -ddd, AR))
heapq.heapify(AL)
heapq.heapify(AR)
tmp=LS
ANSR=[0]*n
ANSL=[0]*n

for i in range(n):
    if AN[i]-AL[0] >0:
        LS = LS-heapq.heappop(AL)+AN[i]
        heapq.heappush(AL,AN[i])
    ANSL[i] = LS

LS=tmp
for j in range(n-1,-1,-1):
    if 0 < -AR[0]-AN[j]:
        RS = RS+heapq.heappop(AR)+AN[j]
        heapq.heappush(AR,-AN[j])
    ANSR[j] = RS
ANSR=ANSR+[sum(ar)]
ANSL=[sum(al)]+ANSL
for i in range(n+1):
    ans=max(ans,ANSL[i]-ANSR[i])
print(ans)
# print(ANSL,ANSR)
Problem p03731 (python)

Fixed submission:
n,t=map(int,input().split())
T=list(map(int,input().split()))
if n==1:
	print(t)
	exit()
count=0
if t>T[1]:
    count+=t-T[1]
pre=T[1]
for i in range(2,n):
    sa=T[i]-pre
    if t>sa:
        count+=t-sa
    pre=T[i]
print(n*t-count)

Buggy submission (verdict: Runtime Error):
n,t=map(int,input().split())
T=list(map(int,input().split()))
count=0
if t>T[1]:
    count+=t-T[1]
pre=T[1]
for i in range(2,n):
    sa=T[i]-pre
    if t>sa:
        count+=t-sa
    pre=T[i]
print(n*t-count)
Problem p03866 (python)

Fixed submission:
def dijkstra(s):
    #始点sから各頂点への最短距離
    #n:頂点数,　w:辺の数, cost[u][v] : 辺uvのコスト(存在しないときはinf)
    d = [float("inf")] * n
    used = [False] * n
    d[s] = 0
    
    while True:
        v = -1
        #まだ使われてない頂点の中から最小の距離のものを探す
        for i in range(n):
            if (not used[i]) and (v == -1):
               v = i
            elif (not used[i]) and d[i] < d[v]:
                v = i
        if v == -1:
               break
        used[v] = True
               
        for j in range(n):
               d[j] = min(d[j],d[v]+cost[v][j])
    return d

Xs,Ys,Xt,Yt = map(int,input().split())
n = int(input())
p = [(Xs,Ys,0),(Xt,Yt,0)]
for i in range(2,n+2):
    p.append(tuple(map(int,input().split())))
cost = [[0]*(n+2)for i in range(n+2)]

for i in range(n+2):
    for j in range(i,n+2):
        cost[i][j] = cost[j][i] =  max(((p[i][0]-p[j][0])**2+(p[i][1]-p[j][1])**2)**0.5 - p[i][2] - p[j][2],0)
cost = tuple(cost)
n += 2

res = dijkstra(0)
print(res[1])

Buggy submission (verdict: Runtime Error):
#!/usr/bin/env python3
from scipy.sparse.csgraph import csgraph_from_dense, floyd_warshall, dijkstra
# G = csgraph_from_dense(edge, null_value=10**9)
# f = floyd_warshall(G)
# d = dijkstra(G, indices=1)
import sys
input = lambda: sys.stdin.readline()[:-1]
sys.setrecursionlimit(10**8)

xs,ys,xt,yt=map(int,input().split())
n=int(input())
xyr=[(xs,ys,0),(xt,yt,0)]
data=[[0]*(n+2) for i in range(n+2)]
for i in range(n):
    xyr.append(tuple(map(int,input().split())))
for i in range(n+2):
    for j in range(n+2):
        x0=xyr[i][0];y0=xyr[i][1];r0=xyr[i][2]
        x1 = xyr[j][0];y1=xyr[j][1];r1=xyr[j][2]
        data[i][j]=max(((x0-x1)**2+(y0-y1)**2)**.5-r0-r1,0)
G = csgraph_from_dense(data, null_value=10**9)
d = dijkstra(G, indices=0)
print(d[1])