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

Fixed submission:
import collections
import heapq
n=int(input())
A=[int(i) for i in input().split()]
Ans=[0]*n
M=[0]
for i in range(n):
  M.append(max(M[-1],A[i]))
D=collections.defaultdict(int)
H=[]
for i in range(n):
  j=n-1-i
  if A[j]<=M[j]:
    heapq.heappush(H,-A[j])
  else:
    Ans[j]=(A[j]-M[j])*(D[A[j]]+1)
    D[M[j]]+=D[A[j]]+1
    ct=0
    while H:
      a=heapq.heappop(H)
      a=-a
      if a<=M[j]:
        heapq.heappush(H,-a)
        break
      else:
        Ans[j]+=a-M[j]
        D[M[j]]+=1

for a in Ans:
  print(a)

Buggy submission (verdict: Runtime Error):
import collections
import heapq
n=int(input())
A=[int(i) for i in input().split()]
Ans=[0]*n
M=[0]#自分より前の最大値をメモ。これ以下だと現れない
for i in range(n):
  M.append(max(M[-1],A[i]))
D=collections.defaultdict(int)
H=[]
for i in range(n):
  j=n-1-i
  if A[j]<=M[j]:
    heapq.heappush(H,-A[j])#出現しないインデックスの数を管理。大きいほうから取り出す。
  else:
    Ans[j]=(A[j]-M[j])*(D[A[j]]+1)#自分より前の最大値と自分の差かける自分自身と同じ数のこれまでの出現回数
    D[M[j]]+=D[A[j]]+1#自分自身より後ろの自分と同じ数全てを自分より前の最大値まで減らすことで増える分
    ct=0
    while H:#自分より後ろで自分より小さいが、自分の前の最大値より大きいものを全て見る
      a=heapq.heappop(H)
      a=-a
      if a<=M[j]:
        heapq.heappush(H,-a)
        break
      else:
        Ans[j]+=a-M[j]
        D[M[j]]+=1

for a in Ans:
  print(Ans)
Problem p03840 (python)

Fixed submission:
i,o,t,j,l,s,z=map(int,input().split())
ans=0
if i==0 or j==0 or l==0:
  ans+=o+(i//2)*2+(j//2)*2+(l//2)*2
else:
  ans+=o+(i//2)*2+(j//2)*2+(l//2)*2
  ans1=o+((i-1)//2)*2+((j-1)//2)*2+((l-1)//2)*2+3
  ans=max(ans,ans1)
print(ans)

Buggy submission (verdict: Runtime Error):
i,o,t,j,l,s,z=map(int,input().split())
ans=0
if i==0 or j==0 or l==0:
  ans+=o+(i//2)*2+min(j,l)*2
else:
  ans+=o+(i//2)*2+min(j,l)*2
  ans1=o+((i-1)//2)*2+max(0,min(j-1.l-1))*2
print(ans)
Problem p03855 (python)

Fixed submission:
import collections
import sys
input = sys.stdin.readline
n,k,l=map(int,input().split())

parD,parT=[-1]*n,[-1]*n
def findD(x):
  if parD[x]<0:
    return x
  else:
    parD[x]=findD(parD[x])
    return parD[x]
def uniteD(x,y):
  x=findD(x)
  y=findD(y)
  if x==y:
    return False
  else:
    if parD[x]>parD[y]:
      x,y=y,x
    parD[x]+=parD[y]
    parD[y]=x
    return True
def sameD(x,y):
  return findD(x)==findD(y)
def sizeD(x):
  return -parD[findD(x)]
def findT(x):
  if parT[x]<0:
    return x
  else:
    parT[x]=findT(parT[x])
    return parT[x]
def uniteT(x,y):
  x=findT(x)
  y=findT(y)
  if x==y:
    return False
  else:
    if parT[x]>parT[y]:
      x,y=y,x
    parT[x]+=parT[y]
    parT[y]=x
    return True
def sameT(x,y):
  return findT(x)==findT(y)
def sizeD(x):
  return -parT[findT(x)]


for i in range(k):
  p,q=map(int,input().split())
  uniteD(p-1,q-1)
for i in range(l):
  r,s=map(int,input().split())
  uniteT(r-1,s-1)
for i in range(n):
  findD(i)
  findT(i)
C=[]
for i in range(n):
  if parD[i]<0:
    parD[i]=i
  if parT[i]<0:
    parT[i]=i
Ans=[]
for i in range(n):
  Ans.append((parD[i],parT[i]))
ANS=collections.Counter(Ans)
for i in range(n):
  print(ANS[Ans[i]])

Buggy submission (verdict: Runtime Error):
input = sys.stdin.readline
n,k,l=map(int,input().split())

parD,parT=[-1]*n,[-1]*n
def findD(x):
  if parD[x]<0:
    return x
  else:
    parD[x]=findD(parD[x])
    return parD[x]
def uniteD(x,y):
  x=findD(x)
  y=findD(y)
  if x==y:
    return False
  else:
    if parD[x]>parD[y]:
      x,y=y,x
    parD[x]+=parD[y]
    parD[y]=x
    return True
def sameD(x,y):
  return findD(x)==findD(y)
def sizeD(x):
  return -parD[findD(x)]
def findT(x):
  if parT[x]<0:
    return x
  else:
    parT[x]=findT(parT[x])
    return parT[x]
def uniteT(x,y):
  x=findT(x)
  y=findT(y)
  if x==y:
    return False
  else:
    if parT[x]>parT[y]:
      x,y=y,x
    parT[x]+=parT[y]
    parT[y]=x
    return True
def sameT(x,y):
  return findT(x)==findT(y)
def sizeD(x):
  return -parT[findT(x)]


for i in range(k):
  p,q=map(int,input().split())
  uniteD(p-1,q-1)
for i in range(l):
  r,s=map(int,input().split())
  uniteT(r-1,s-1)
for i in range(n):
  findD(i)
  findT(i)
C=[]
for i in range(n):
  if parD[i]<0:
    parD[i]=i
  if parT[i]<0:
    parT[i]=i
Ans=[]
for i in range(n):
  Ans.append((parD[i],parT[i]))
ANS=collections.Counter(Ans)
for i in range(n):
  print(ANS[Ans[i]])
Problem p03910 (python)

Fixed submission:
n=int(input())
m=1
while m*(m+1)<2*n:
  m+=1
k=m*(m+1)//2-n
for i in range(m):
  if i+1==k:
    continue
  else:
    print(i+1)

Buggy submission (verdict: Runtime Error):
def f(n):
  for i in range(n):
    if i*(i+1)>=2*n:
      return(i)
      break
n=int(input())
Ans=[]
while n>1:
  Ans.append(f(n))
  n-=f(n)
Ans.append(1)
print(*Ans,sep="\n")
Problem p03971 (python)

Fixed submission:
n,a,b=map(int,input().split())
s=input()
pa,pb=0,0
for i in range(n):
  if s[i]=='a':
    if pa+pb<a+b:
      pa+=1
      print('Yes')
    else:
      print('No')
  elif s[i]=='b':
    if pa+pb<a+b and pb<b:
      pb+=1
      print('Yes')
    else:
      print('No')
  else:
    print('No')

Buggy submission (verdict: Runtime Error):
n,a,b=map(int,input().split())
s=input()
pa,pb=0,0
for i in range(n):
  if s[i]=='a':
    pa+=1
    if pa+prb<=a+b:
      print('Yes')
    else:
      print('No')
  elif s[i]=='b':
    pb+=1
    if pa+pb<=a+b and pb<=b:
      print('Yes')
    else:
      print('No')
  else:
    print('No')
Problem p03994 (python)

Fixed submission:
s=input()
k=int(input())
A={}
for i in range(26):
  A[chr(ord('a')+i)]=26-i
C=[]
for ss in s:
  C.append(A[ss])
ans=""
for i in range(len(s)):
  if i==len(s)-1:
    k%=26
    if ord(s[-1])+k>122:
      ans+=chr(ord(s[-1])+k-26)
    else:
      ans+=chr(ord(s[-1])+k)
  elif s[i]!="a" and k>=C[i]:
    ans+="a"
    k-=C[i]
  else:
    ans+=s[i]
print(ans)

Buggy submission (verdict: Runtime Error):
s=input()
k=int(input())
A={}
for i in range(26):
  A[chr(ord('a')+i)]=26-i
C=[]
for ss in s:
  C.append(A[ss])
ans=""
for i in range(len(s)):
  if i==len(s)-1:
    if ord(s[-1])+k>122:
      ans+=chr(ord(s[-1])+k-26)
    else:
      ans+=chr(ord(s[-1])+k)
  elif k>=C[i]:
    ans+="a"
    k-=C[i]
  else:
    ans+=s[i]
print(ans)

Buggy submission (verdict: Runtime Error):
s=input()
k=int(input())
A={}
for i in range(26):
  A[chr(ord('a') + i)]=26-i
C=[]
for ss in s:
  C.append(A[ss])
ans=""
for i in range(len(s)):
  if i==len(s)-1:
    ans+=chr(ord(s[-1])+k)
  elif k>=C[i]:
    ans+="a"
    k-=C[i]
  else:
    ans+=s[i]
print(ans)
Problem p04015 (python)

Fixed submission:
n,a=map(int,input().split())
X=[int(i) for i in input().split()]
DP=[[[0 for i in range(50*n+1)] for i in range(n+1)] for i in range(n+1)]
DP[0][0][0]=1
for i in range(1,n+1):
  for j in range(i+1):
    for s in range(50*j+1):
      DP[i][j][s]=DP[i-1][j][s]+DP[i-1][j-1][s-X[i-1]]
ans=0
for j in range(1,n+1):
  ans+=DP[n][j][j*a]
print(ans)

Buggy submission (verdict: Runtime Error):
import numpy as np
n,a=map(int,input().split())
X=[int(i) for i in input().split()]
tot,m=sum(X),max(X)
DP=np.zeros((n+1,n+1,tot+1),dtype=int)
DP[0][0][0]=1
for i in range(1,n+1):
  for j in range(i+1):
    lim=min(j*m,tot)+1
    for s in range(lim):
      DP[i][j][s]=DP[i-1][j][s]+DP[i-1][j-1][s-X[i-1]]
ans=0
for j in range(1,n+1):
  ans+=DP[n][j][j*a]
print(ans)

Buggy submission (verdict: Runtime Error):
import numpy as np
n,a=map(int,input().split())
X=[int(i) for i in input().split()]
DP=np.zeros((n+1,n+1,50*n+1),dtype=int)
DP[0][0][0]=1
for i in range(1,n+1):
  for j in range(i+1):
    for s in range(50*j+1):
      DP[i][j][s]=DP[i-1][j][s]+DP[i-1][j-1][s-X[i-1]]
ans=0
for j in range(1,n+1):
  ans+=DP[n][j][j*a]
print(ans)
Problem p02683 (python)

Fixed submission:
import itertools
import numpy as np

n,m,x=map(int,input().split())

book=[]

mincost=10**12

for i in range(n):
    l=list(map(int,input().split()))
    book.append(l)

nl=np.array(book)

for i in range(2**n):
    bag=np.array([0]*(m+1))
    for j in range(n):
        if((i>>j)&1):
            bag+=nl[j]
    flag=True
    for j in range(1,m+1):
        if bag[j]<x:
            flag=False
    if flag and bag[0]<mincost:
        mincost=bag[0]

if mincost==10**12:
    mincost=-1
    
print(mincost)

Buggy submission (verdict: Runtime Error):
import itertools
import numpy as np

n,m,x=map(int,input().split())

book=[]

mincost=10**12

for i in range(n):
    l=list(map(int,input().split()))
    book.append(l)

nl=np.array(book)

for i in range(2**n):
    bag=np.array([0]*(m+1))
    for j in range(n):
        if((i>>j)&1):
            bag+=nl[j]
    flag=True
    for j in range(1,m+1):
        if bag[j]<x:
            flag=False
    if flag and bag[0]<mincost:
        mincost=bag[0]

if mincost==10**12:
    mincost=-1
    
print(mincost)
Problem p02715 (python)

Fixed submission:
n,k=map(int,input().split())
mod=10**9+7
ans=0
l=[0]*(k+1)
 
for i in range(k,0,-1):
    l[i]=pow(k//i,n,mod)
    for j in range(2*i,k+1,i):
        l[i]-=l[j]
        l[i]%=mod
    ans+=l[i]*i
    ans%=mod
 
print(ans)

Buggy submission (verdict: Runtime Error):
import math
n,k=map(int,input().split())
mod=pow(10,9)+7
ans=0
l=[0]*(k+1)

for i in reversed(range(1,k+1)):
    l[i]=pow(math.floor(k/i),n)%mod
    a=2*i
    while a<=k:
        l[i]-=l[a]
        a+=i
    ans+=l[i]*i%mod

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

print(ans)
Problem p02747 (python)

Fixed submission:
import re
s=input()
if re.fullmatch(r'(hi)+',s):
    print("Yes")
else:
    print("No")

Buggy submission (verdict: Runtime Error):
import re
print("Yes")　if re.fullmatch(r'(hi)+',input())　else　print("No")
Problem p02755 (python)

Fixed submission:
import math

a,b=map(int,input().split())

emin=math.ceil(a/0.08)
emax=math.ceil((a+1)/0.08)-1
tmin=math.ceil(b/0.1)
tmax=math.ceil((b+1)/0.1)-1

if tmin<=emin<=tmax:
    print(emin)
elif emin<=tmin<=emax:
    print(tmin)
else:
    print(-1)

Buggy submission (verdict: Runtime Error):
n,a,b=map(int,input().split())
count=int(n/(a+b))*a
n=n%(a+b)
if(n<=b):
    count=count+n
else:
    count=count+b
print(count)
Problem p02756 (python)

Fixed submission:
s=input()
n=int(input())
rev=1
pre=''
suf=''

for i in range(n):
  q=input().split()
  if q[0]=='1':
    rev+=1
  elif (rev+int(q[1]))%2==0:
    pre=q[2]+pre
  else:
    suf=suf+q[2]
    
ans=pre+s+suf
  
if rev%2==0:
  print(ans[::-1])
else:
  print(ans)

Buggy submission (verdict: Runtime Error):
s=input()
n=int(input())
rev=1
pre=''
suf=''

for i in range(n):
  q=input().split()
  if q[0]=='1':
    rev+=1
  elif (rev+int(q[1]))%2==0:
    pre=q[2]+pre
  else:
    suf=suf+q[2]
    
ans=pre+s+suf
  
if rev%2==0:
  ans.reverse()

print(ans)

Buggy submission (verdict: Runtime Error):
s=input()
n=int(input())
rev=1

for i in range(n):
  q=input().split()
  if q[0]=='1':
    rev+=1
  elif (rev+int(q[1]))%2==0:
    s=q[2]+s
  else:
    s=s+q[2]
    
if rev%2==0:
  s.reverse()

print(s)

Buggy submission (verdict: Runtime Error):
s=input()
a=int(input())

for i in range(a):
    c=input()
    if c[0]=='1':
        s=''.join(list(reversed(s)))
    else:
        if c[2]=='1':
            s=c[4]+s
        else:
            s=s+c[4]
    
    print(s)
            
print(s)
Problem p02760 (python)

Fixed submission:
l=[list(map(int,input().split())) for i in range(3)]
n=int(input())
H=[0,0,0]
W=[0,0,0]
S=[0,0]

for i in range(n):
    b=int(input())
    for h in range(3):
        for w in range(3):
            if b==l[h][w]:
                H[h]+=1
                W[w]+=1
                if h==w:
                    S[0]+=1
                if h+w==2:
                    S[1]+=1

check=False
for h in H:
    if h==3:
        check=True
for w in W:
    if w==3:
        check=True
for s in S:
    if s==3:
        check=True

if check:
    print("Yes")
else:
    print("No")

Buggy submission (verdict: Runtime Error):
l=[list(map(int,input().split())) for i in range(3)]
n=int(input())
H=[0,0,0]
W=[0,0,0]
S=[0,0]
 
for i in range(n):
    b=int(input())
    for h in range(3):
        for w in range(3):
            if b==l[h][w]:
                H[h]+=1
                W[w]+=1
                if h==w:
                    S[0]+=1
                if h+w==4:
                    S[1]+=1
 
check=False
for h in H:
    if h==3:
        check=True
for w in W:
    if w==3:
        check=True
for s in S:
    if s==3:
        check=True
 
if check:
    print("Yes")
else:
    print("No")
l=[list(map(int,input().split())) for i in range(3)]
n=int(input())
H=[0,0,0]
W=[0,0,0]
S=[0,0]

for i in range(n):
    b=int(input())
    for h in range(3):
        for w in range(3):
            if b==l[h][w]:
                H[h]+=1
                W[w]+=1
                if h==w:
                    S[0]+=1
                if h+w==2:
                    S[1]+=1

check=False
for h in H:
    if h==3:
        check=True
for w in W:
    if w==3:
        check=True
for s in S:
    if s==3:
        check=True

if check:
    print("Yes")
else:
    print("No")
Problem p02768 (python)

Fixed submission:
mod=10**9+7

def modpow(a,n):
    if n==0:
        return 1
    elif n==1:
        return a%mod
    elif n%2==0:
        return (modpow(a,n/2)**2)%mod
    else:
        return (a*modpow(a,n-1))%mod

def modfact(l,r):
    fact=1
    for i in range(l-r+1):
        fact=fact*(r+i)%mod
    return fact

def comb(n,x):
    S=modfact(n,n-x+1)
    fact=modfact(x,1)
    T=modpow(fact,mod-2)
    return S*T%mod

n,a,b=map(int,input().split())
fact=modpow(2,n)
ans=fact-1-comb(n,a)-comb(n,b)
while ans<0:
    ans+=mod
print(ans)

Buggy submission (verdict: Runtime Error):
def modpow(a,n):
    if n==0:
        return 1
    elif n==1:
        return a%mod
    elif n%2==0:
        return (modpow(a,n/2)**2)%mod
    else:
        return (a*modpow(a,n-1))%mod

def modfact(l,r):
    fact=1
    for i in range(l-r+1):
        fact=fact*(r+i)%mod
    return fact

def comb(n,x):
    S=modfact(n,n-x+1)
    fact=modfact(x,1)
    T=modpow(fact,mod-2)
    print(S,fact,T,S*T%mod)
    return S*T%mod

n,a,b=map(int,input().split())
fact=modpow(2,n)
ans=fact-1-comb(n,a)-comb(n,b)
while ans<0:
    ans+=mod
print(ans)
Problem p02760 (python)

Fixed submission:
A = [list(map(int, input().split())) for _ in range(3)]
n = int(input())
B = [int(input()) for _ in range(n)]
ans = False

bingolist = []
for i in range(3):
  bingolist.append([A[i][0], A[i][1], A[i][2]])
  bingolist.append([A[0][i], A[1][i], A[2][i]])

bingolist.append([A[0][0], A[1][1], A[2][2]])
bingolist.append([A[2][0], A[1][1], A[0][2]])

for i in bingolist:
  if i[0] in B and i[1] in B and i[2] in B: ans = True
  
print("Yes" if ans else "No")

Buggy submission (verdict: Runtime Error):
A = [list(map(int, input().split())) for _ in range(3)]
n = input()
B = list(map(int, input().split()))
ans = False

bingolist = []
for i in range(3):
  bingolist.append([A[i][0], A[i][1], A[i][2]])
  bingolist.append([A[0][i], A[1][i], A[2][i]])

bingolist.append([A[0][0], A[1][1], A[2][2]])
bingolist.append([A[2][0], A[1][1], A[0][2]])

for i in bingolist:
  ans = True if (i[0] in B and i[1] in B and i[2] in B)
  
print(ans)
Problem p02761 (python)

Fixed submission:
n, m = map(int, input().split())
ctr = [-1 for _ in range(n)]
flag = True
for i in range(m):
  p, q = map(int, input().split())
  p -= 1
  if ctr[p] == -1:
    ctr[p] = q
  else:
    if(ctr[p] != q):
      flag = False
      break

if ctr[0] == 0 and n > 1:
  flag = False

if ctr[0] == -1:
  ctr[0] = 0 if n == 1 else 1
if flag:
  for i in ctr:
    print(0 if i == -1 else i, end="")
else:
  print(-1)

Buggy submission (verdict: Runtime Error):
n, m = map(int, input().split())
ctr = [-1 for _ in range(n)]
flag = True
for i in range(m):
  p, q = map(int, input().split())
  p -= 1
  if ctr[p] == -1:
    ctr[p] = q
  else:
    flag = False
    break

flag = False if ctr[0] = 0

if flag:
  for i in ctr:
    print(1 if i == -1 else i, end="")
else:
  print(-1)
Problem p02713 (python)

Fixed submission:
from functools import reduce
import math

k = int(input())

s = 0

def gcd(*numbers):
    return reduce(math.gcd, numbers)

for i in range(1,k+1):
    for j in range(1,k+1):
        for l in range(1,k+1):
            s += gcd(i,j,l)

print(s)

Buggy submission (verdict: Runtime Error):
import math

    k = int(input())
    ans = 0

    for h in range(1, k+1):
        for i in range(1, k+1):
            l = math.gcd(h, i)
            for j in range(1, k+1):
                ans += math.gcd(l, j)

    print(ans)
Problem p02909 (python)

Fixed submission:
s = input()

if s == 'Sunny':
    print('Cloudy')
elif s == 'Cloudy':
    print('Rainy')
else:
    print('Sunny')

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

if s == 'Sunny':
    print('Cloudy')
elif s == 'Cloudy':
    print(Rainy)
else:
    print('Sunny')
Problem p02983 (python)

Fixed submission:
l, r = map(int, input().split())

rem_l = l%2019
rem_r = r%2019

ans = -1

if r - l >= 2019:
    ans = 0

elif rem_l >= rem_r:
    ans = 0

else:
    ans = float('INF')
    for i in range(l, r+1):
        for j in range(i+1, r+1):
            temp = (i * j) % 2019
            if temp < ans:
                ans = temp

print(ans)

Buggy submission (verdict: Runtime Error):
l, r = map(int, input().split())

rem_l = l%2019
rem_r = r%2019

ans = -1

if r - l >= 2019:
    ans = 0

elif rem_l >= rem_r:
    ans = 0

else:
    ans = float('INF')
    for i in range(l, r):
        for j in raneg(i, r):
            temp = (i * j) % 2019
            if temp < ans:
                ans = temp

print(ans)
Problem p02612 (python)

Fixed submission:
n = int(input())

ans = []
for i in range(11):
    if 1000 * i - n >= 0:
        ans.append(1000*i - n)

print(min(ans))

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

ans = []
for i in range(1, 10):
    if 1000 * i - n >= 0:
        ans.append(1000*i - n)

print(min(ans))
Problem p02641 (python)

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

ans = 0
m = float("inf")
for i in range(-200, 200):
    if i not in p:
        if abs(i-x) < m:
            ans = i
            m = abs(i-x)

print(ans)

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

res = []
for i in range(1, 101):
    if i not in p:
        res.append([abs(i-x), i])

res.sort(key=lambda x:x[0])
print(res[0][1])
Problem p02691 (python)

Fixed submission:
from collections import defaultdict

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

memo = defaultdict(int)
ans = 0
for i, a in enumerate(A, 1):
    ans += memo[i - a]
    memo[a + i] += 1

print(ans)

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

ans = 0
cnt = defaultdict(int)
for i in range(n):
	ans += cnt[i - a[i]]
	cnt[i + a[i]] += 1

print(ans)
Problem p02732 (python)

Fixed submission:
from collections import Counter

def main():
    N = int(input())
    A = list(map(int, input().split()))
    count = Counter(A)
    sum_ = sum([v*(v-1)/2 for v in count.values()])

    for i in range(len(A)):
        took_count = count[A[i]]
        sub = took_count - 1
        print(int(sum_ - sub))

if __name__ == '__main__':
    main()

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

def cmb(n,r):
    if n < r:
        return 0
    else:
        math.factorial(n,r)

def main():
    N = int(input())
    A = list(map(int, input().split()))
    count = Counter(A)
    sum_ = sum([cmb(i,2) for i in count.values()])

    for i in range(len(A)):
        remain = A[:i] + A[i+1:]
        took_count = count[A[i]]
        sub = took_count - 1
        print(int(sum_ - sub))

if __name__ == '__main__':
    main()

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

def main():
    N = int(input())
    A = list(map(int, input().split()))
    count = Counter(A)
    sum_ = sum([math.factorial(i,2) for i in count.values()])

    for i in range(len(A)):
        remain = A[:i] + A[i+1:]
        took_count = count[A[i]]
        sub = took_count - 1
        print(int(sum_ - sub))

if __name__ == '__main__':
    main()
Problem p02780 (python)

Fixed submission:
def main():
    N, K = map(int, input().split())
    p = list(map(int, input().split()))

    p = [(p_i+1)/2 for p_i in p]
    ans = 0
    for i in range(N-K+1):
        if i == 0:
            sum_ = sum(p[i:i+K])
        else:
            sum_ = sum_ + p[i+K-1] - p[i-1]
        ans = max(ans, sum_)

    print(ans)

if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
def sigma(n):
    return sum([i for i in range(n+1)])

def main():
    N, K = map(int, input().split(' '))
    p = list(map(int, input().split(' ')))

    max_value = 0
    for i in range(N-K+1):
        sum_ = sum(p[i:i+K-1])
        if sum_ > max_value:
            max_value = sum_
            max_list = p[i:i+K]

    expected = 0
    for v in max_list:
        expected += sigma(v) / v

    print(expected)

if __name__ == '__main__':
    main()
Problem p02796 (python)

Fixed submission:
n = int(input())
xl = [list(map(int, input().split())) for _ in range(n)]
le = [[p[0]-p[1], p[0]+p[1]] for p in xl]
le.sort(key = lambda x : x[1])

ans = 0
right = -(10 ** 9) - 1
for i in range(n):
    if right <= le[i][0]:
        ans += 1
        right = le[i][1]

print(ans)

Buggy submission (verdict: Runtime Error):
n = int(input())
xl = [list(map(int, input().split())) for _ in range(n)]
le = [[p[0]-p[1], p[0]+p[1]] for p in xl]
le.sort(key = lambda x　: x[1])

ans = 0
right = -(10 ** 9) -　1
for i in range(n):
    if right <= le[i][0]:
        ans += 1
        right = le[i][1]

print(ans)
Problem p02803 (python)

Fixed submission:
from collections import deque

H, W = map(int, input().split())
c = [list(input()) for _ in range(H)]

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

def bfs(sx, sy):
    d = [[-1] * W for _ in range(H)]

    que = deque([])
    que.append((sx, sy))
    d[sy][sx] = 0

    res = 0
    while que:
        x, y = que.popleft()

        for k in range(4):
            nx = x + dx[k]
            ny = y + dy[k]

            if 0 <= nx < W and 0 <= ny < H and d[ny][nx] == -1 and c[ny][nx] == '.':
                que.append((nx, ny))
                tmp = d[y][x] + 1
                d[ny][nx] = tmp
                res = max(res, tmp)

    return res

ans = 0
for i in range(H):
    for j in range(W):
        if c[i][j] == '.':
            tmp = bfs(j, i)
            ans = max(ans, tmp)

print(ans)

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

H, W = map(int, input().split())
c = [list(input()) for _ in range(H)]

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

ans = 0
for i in range(H):
    for j in range(W):
        if c[i][j] == '.':
            sx, sy = (j, i)
            s = [[-1] * W for _ in range(H)]
            d = [[0] * W for _ in range(H)]

            que = deque([])
            que.append((sx, sy))
            s[sy][sx] = 1
            
            while que:
                x, y = que.popleft()
                s[y][x] = 1

                for k in range(4):
                    nx = x + dx[k]
                    ny = y + dy[k]

                    if 0 <= nx < W and 0 <= ny < H and s[ny][nx] != 1 and c[ny][nx] == '.':
                        que.append((nx, ny))
                        d[ny][nx] = d[y][x] + 1
        ans = max(ans, max([max(v) for v in d]))

print(ans)
Problem p02818 (python)

Fixed submission:
A, B, K = map(int, input().split())

if A > K:
    print(A-K, B)
else:
    print(0, max(0, B-(K-A)))

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

elif A > K:
    print(A-K, B)
else:
    print(0, max(0, B-(K-A)))
Problem p02856 (python)

Fixed submission:
M = int(input())

s = 0
dig = 0
for i in range(M):
    d, c = map(int, input().split())
    s += d * c
    dig += c

print(dig - 1 + (s - 1) // 9)

Buggy submission (verdict: Runtime Error):
M = int(input())
N = []

ans = 0
prev_d = 0
for i in range(M):
    d, c = map(int, input().split())
    N += [d] * c
    ans += c
    if prev_d + d > 9:
        ans += 1
    prev_d = d

print(ans-1)