Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
from math import factorial
def cmb(m,r):
  return factorial(m)//(factorial(r)*factorial(m-r))
n=int(input())
s=[input() for i in range(n)]
s.sort()
cnt=0
ans=0
for i in range(1,n):
  if s[i]==s[i-1]:
    cnt+=1
  else:
    ans+=cmb(cnt+1,2)
    cnt=0
print(ans)


Fixed submission:
from math import factorial
def comb(n,k):
  if n<0 or k<0 or n<k:return 0
  if n==0 and k==0:return 1
  a=factorial(n)
  b=factorial(k)
  c=factorial(n-k)
  return a//(b*c)
n=int(input())
s=[sorted(list(input())) for i in range(n)]
s.sort()
cnt=1
ans=0
for i in range(1,n):
  if s[i]==s[i-1]:
    cnt+=1
  else:
    ans+=comb(cnt,2)
    cnt=1
if cnt>=2:
  ans+=comb(cnt,2)
print(ans)

Buggy python submission (verdict: Runtime Error):
from math import factorial
def cmb(n,r):
  return factorial(n)//(factorial(r)*factorial(n-r))
n=int(input())
s=[input() for i in range(n)]
s.sort()
cnt=0
ans=0
for i in range(1,n):
  if s[i]==s[i-1]:
    cnt+=1
  else:
    ans+=cmb(cnt+1,2)
    cnt=0
print(ans)

Fixed submission:
from math import factorial
def comb(n,k):
  if n<0 or k<0 or n<k:return 0
  if n==0 and k==0:return 1
  a=factorial(n)
  b=factorial(k)
  c=factorial(n-k)
  return a//(b*c)
n=int(input())
s=[sorted(list(input())) for i in range(n)]
s.sort()
cnt=1
ans=0
for i in range(1,n):
  if s[i]==s[i-1]:
    cnt+=1
  else:
    ans+=comb(cnt,2)
    cnt=1
if cnt>=2:
  ans+=comb(cnt,2)
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
n,m=map(int,input().split())
ab=[list(map(int,input().split())) for i in range(n)]
ab.sort(key=lambda x:x[0])
ans=0
l=[]
e=0
for i in range(1,m+1):
  while e<n and ab[e][0]==i:
    l.append(ab[e][1])
    e+=1
  if len(l)>0: 
    ans+=max(l)
    l.remove(max(l))
print(ans)

Fixed submission:
import heapq
n,m=map(int,input().split())
ab=[list(map(int,input().split())) for i in range(n)]
ab.sort(key=lambda x:x[0])
ans=0
q=[]
heapq.heapify(q)
e=0
for i in range(1,m+1):
  while e<n and ab[e][0]==i:
    heapq.heappush(q,-ab[e][1])
    e+=1
  if len(q)>0: 
    ans-=heapq.heappop(q)
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
s=input()
n=len(s)
mod=10**9+7
dp=[[0]*13 for i in range(n+1)] # dp[i][j]:i番目までで j mod 13.
dp[0][0]=1
for i in range(1,n+1):
  for j in range(13):
    if s[i-1]=='?':
      for k in range(10):
        dp[i][(j*10+k)%13]+=dp[i-1][j]
        dp[i][(j*10+k)%13]%=mod
    else:
      dp[i][(j*10+int(s[i-1]))%13]+=dp[i-1][j]
      dp[i][(j*10+int(s[i-1]))%13]%=mod
print(dp[n][5])

Fixed submission:
s=input()
n=len(s)
mod=10**9+7
dp=[[0]*13 for i in range(n+1)] # dp[i][j]:i番目までで j mod 13.
dp[0][0]=1
for i in range(1,n+1):
  for j in range(13):
    if s[i-1]=='?':
      for k in range(10):
        dp[i][(j*10+k)%13]+=dp[i-1][j]
        dp[i][(j*10+k)%13]%=mod
    else:
      dp[i][(j*10+int(s[i-1]))%13]+=dp[i-1][j]
      dp[i][(j*10+int(s[i-1]))%13]%=mod
print(dp[n][5])
Buggy python submission (verdict: Runtime Error):
n=int(input())
a=list(map(int,input().split()))
a.sort()
for i in range(n):
  if a[i]==a[-1]:
    print(a[-2])
  else:
    print(a[-1])

Fixed submission:
import copy
n=int(input())
a=[int(input()) for i in range(n)]
b=copy.deepcopy(a)
b.sort()
for i in range(n):
  if a[i]==b[-1]:
    print(b[-2])
  else:
    print(b[-1])
Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
a=[int(input()) for i in range(n)]
ans=0
INF=-10**9
k=0
while max(a)>=0:
  de=[]
  f=a[k]
  de.append(k)
  if f<0:
    k+=1
    continue
  for i in range(k+1,n):
    if f<a[i]:
      de.append(i)
      f=a[i]
  for i in de:
    a[i]=INF
  ans+=1
  k+=1
print(ans)

Fixed submission:
import bisect
n=int(input())
a=[int(input()) for _ in range(n)][::-1]
lis=[a[0]]
for i in a[1:]:
  if i>=lis[-1]:
    lis.append(i)
  else:
    lis[bisect.bisect_right(lis,i)]=i
print(len(lis))
Buggy python submission (verdict: Runtime Error):
n=int(input())
a=list(map(int,input().split()))
ans=s[0]
for i in range(n):
  ans^=s[i]
if ans!=0:
  print('No')
else:
  print('Yes')

Fixed submission:
n=int(input())
s=list(map(int,input().split()))
ans=s[0]
for i in range(1,n):
  ans^=s[i]
if ans!=0:
  print('No')
else:
  print('Yes')
Buggy python submission (verdict: Runtime Error):
L,R=map(int,input().split())
l,r=L%2019,R%2019
x,y=L//2019,R//2019
if x<y:
  print(0)
else:
  ans=10**9
  for i in range(l,r):
    for j in range(i+1,r+1):
      ans=min(ans,(i*j)%2019)
print(ans)

Fixed submission:
L,R=map(int,input().split())
l,r=L%2019,R%2019
x,y=L//2019,R//2019
if x<y:
  print(0)
else:
  ans=10**9
  for i in range(l,r):
    for j in range(i+1,r+1):
      ans=min(ans,(i*j)%2019)
  print(ans)
Buggy python submission (verdict: Runtime Error):
n,k=map(int,input().split())
path=[[] for i in range(n)]
for i in range(n):
  a,b=map(int,input().split())
  path[a-1].append(b-1)
  path[b-1].append(a-1)
mod=10**9+7
stack=[0]
visited=[1]+[0]*(n-1)
ans=k
while stack:
  v=stack.pop(0)
  c=k-2 if v!=0 else k-1
  for d in path[v]:
    if visited[d]:
      continue
    visited[d]=1
    ans=(ans*c)%mod
    c-=1
    stack.append(d)
print(ans)

Fixed submission:
n,k=map(int,input().split())
path=[[] for i in range(n)]
for i in range(n-1):
  a,b=map(int,input().split())
  path[a-1].append(b-1)
  path[b-1].append(a-1)
mod=10**9+7
stack=[0]
visited=[1]+[0]*(n-1)
ans=k
while stack:
  v=stack.pop(0)
  c=k-2 if v!=0 else k-1
  for d in path[v]:
    if visited[d]:
      continue
    visited[d]=1
    ans=(ans*c)%mod
    c-=1
    stack.append(d)
print(ans)
Buggy python submission (verdict: Runtime Error):
w,h,x,y=map(int,input().split())
s=w*h/2
i=1 if x=w/2 and y=h/2 else 0
print(s,i)

Fixed submission:
w,h,x,y=map(int,input().split())
s=w*h/2
i=1 if x==w/2 and y==h/2 else 0
print(s,i)
Buggy python submission (verdict: Time Limit Exceeded):
n,m=map(int,input().split())
s=list(map(int,input().split()))
t=list(map(int,input().split()))
mod=10**9+7
dp=[[0]*(m+1) for i in range(n+1)]
for i in range(n+1):
  dp[i][0]=1
for i in range(m+1):
  dp[0][i]=1
for i in range(n):
  for j in range(m):
    if s[i]==t[j]:
      dp[i+1][j+1]=dp[i+1][j]+dp[i][j+1]
    else:
      dp[i+1][j+1]=dp[i+1][j]+dp[i][j+1]-dp[i][j]
    dp[i+1][j+1]%=mod
print(dp[-1][-1])

Fixed submission:
n,m=map(int,input().split())
s=list(map(int,input().split()))
t=list(map(int,input().split()))
mod=10**9+7
dp=[[0]*(m+1) for i in range(n+1)]
for i in range(n+1):
  dp[i][0]=1
for i in range(m+1):
  dp[0][i]=1
for i in range(n):
  for j in range(m):
    if s[i]==t[j]:
      dp[i+1][j+1]=dp[i+1][j]+dp[i][j+1]
    else:
      dp[i+1][j+1]=dp[i+1][j]+dp[i][j+1]-dp[i][j]
    dp[i+1][j+1]%=mod
print(dp[-1][-1])
Buggy python submission (verdict: Runtime Error):
from collections import Counter
n=int(input())
b=[tuple(map(int,input().split())) for _ in range(n)]
r=[(x[0]-y[0],x[1]-y[1]) for x in b for y in b if x!=y]
c=Counter(r).most_commom(1)
print(n-c[0][1] if c else n)

Fixed submission:
from collections import Counter
n=int(input())
b=[tuple(map(int,input().split())) for _ in range(n)]
r=[(x[0]-y[0],x[1]-y[1]) for x in b for y in b if x!=y]
c=Counter(r).most_common(1)
print(n-c[0][1] if c else n)
Buggy python submission (verdict: Runtime Error):
n=int(input())
a=list(map(int,input().split()))
a.sort()
ans=0
for i in range(n):
  ans+=abs(a[i])
if a[0]>0:
  print(sum(a)-2*a[0])
else:
  print(ans)
plus=list()
minus=list()
for i in range(n):
  if a[i]>=0:
    plus.append(a[i])
  else:
    minus.append(a[i])
if len(minus)>0:
  while len(plus)>=2:
    p=plus.pop(0)
    m=minus.pop(0)
    minus.append(m-p)
    print(str(m)+' '+str(p))
if len(plus)>=2 and len(minus)==0:
  plus.sort()
  p1=plus.pop(0)
  p2=plus.pop(-1)
  minus.append(p1-p2)
  print(str(p1)+' '+str(p2))
if len(plus)==0:
  minus.sort()
  m1=minus.pop(-1)
  m2=minus.pop(-2)
  plus.append(m1-m2)
  print(str(m1)+' '+str(m2))
while len(minus)>0:
  p=plus.pop(0)
  m=minus.pop(0)
  plus.append(p-m)
  print(str(p)+' '+str(m))


Fixed submission:
n=int(input())
a=list(map(int,input().split()))
a.sort()
xy=[]
for i in range(n-2,0,-1):
  y=a[i]
  if y>0:
    x=a[0]
    a[0]-=y
  else:
    x=a[n-1]
    a[n-1]-=y
  xy.append((x,y))
print(a[n-1]-a[0])
xy.append((a[n-1],a[0]))
print('\n'.join([' '.join(map(str,t)) for t in xy]))

Buggy python submission (verdict: Runtime Error):
n=int(input())
a=list(map(int,input().split()))
a.sort()
ans=0
for i in range(n):
  ans+=abs(a[i])
print(ans)
plus=list()
minus=list()
for i in range(n):
  if a[i]>=0:
    plus.append(a[i])
  else:
    minus.append(a[i])
while len(plus)>=2 :
  p=plus.pop(0)
  m=minus.pop(0)
  minus.append(m-p)
  print(str(m)+' '+str(p))
while len(minus)>0:
  p=plus.pop(0)
  m=minus.pop(0)
  plus.append(p-m)
  print(str(p)+' '+str(m))

Fixed submission:
n=int(input())
a=list(map(int,input().split()))
a.sort()
xy=[]
for i in range(n-2,0,-1):
  y=a[i]
  if y>0:
    x=a[0]
    a[0]-=y
  else:
    x=a[n-1]
    a[n-1]-=y
  xy.append((x,y))
print(a[n-1]-a[0])
xy.append((a[n-1],a[0]))
print('\n'.join([' '.join(map(str,t)) for t in xy]))
Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
a,b,c=map(int,input().split())
d,e,f=map(int,input().split())
s=[0]*(n+1)
for i in range(a,n+1):
  s[i]=max(s[i],s[i-a]+d-a)
for i in range(b,n+1):
  s[i]=max(s[i],s[i-b]+e-b)
for i in range(c,n+1):
  s[i]=max(s[i],s[i-c]+f-c)
n+=s[-1]
s=[0]*(n+1)
for i in range(d,n+1):
  s[i]=max(s[i],s[i-d]+a-d)
for i in range(e,n+1):
  s[i]=max(s[i],s[i-e]+b-e)
for i in range(f,n+1):
  s[i]=max(s[i],s[i-f]+c-f)
print(n+s[-1])


Fixed submission:
n=int(input())
a,b,c=map(int,input().split())
d,e,f=map(int,input().split())
s=[0]*(n+1)
for i in range(a,n+1):
  s[i]=max(s[i],s[i-a]+d-a)
for i in range(b,n+1):
  s[i]=max(s[i],s[i-b]+e-b)
for i in range(c,n+1):
  s[i]=max(s[i],s[i-c]+f-c)
n+=s[-1]
s=[0]*(n+1)
for i in range(d,n+1):
  s[i]=max(s[i],s[i-d]+a-d)
for i in range(e,n+1):
  s[i]=max(s[i],s[i-e]+b-e)
for i in range(f,n+1):
  s[i]=max(s[i],s[i-f]+c-f)
print(n+s[-1])

Buggy python submission (verdict: Runtime Error):
n=int(input())
a,b,c=map(int,input().split())
d,e,f=map(int,input().split())
s=[0]*(n+1)
for i in range(a,n+1):
  s[i]=max(s[i],s[i-a]+d-a)
for i in range(b,n+1):
  s[i]=max(s[i],s[i-b]+e-b)
for i in range(c,n+1):
  s[i]=max(s[i],s[i-b]+f-c)
n+=s[-1]
s=[0]*(n+1)
for i in range(d,n+1):
  s[i]=max(s[i],s[i-d]+a-d)
for i in range(e,n+1):
  s[i]=max(s[i],s[i-e]+b-e)
for i in range(f,n+1):
  s[i]=max(s[i],s[i-f]+c-f)
print(n+s[-1])

Fixed submission:
n=int(input())
a,b,c=map(int,input().split())
d,e,f=map(int,input().split())
s=[0]*(n+1)
for i in range(a,n+1):
  s[i]=max(s[i],s[i-a]+d-a)
for i in range(b,n+1):
  s[i]=max(s[i],s[i-b]+e-b)
for i in range(c,n+1):
  s[i]=max(s[i],s[i-c]+f-c)
n+=s[-1]
s=[0]*(n+1)
for i in range(d,n+1):
  s[i]=max(s[i],s[i-d]+a-d)
for i in range(e,n+1):
  s[i]=max(s[i],s[i-e]+b-e)
for i in range(f,n+1):
  s[i]=max(s[i],s[i-f]+c-f)
print(n+s[-1])
Buggy python submission (verdict: Time Limit Exceeded):
h,w=map(int,input().split())
grid=[list(input()) for _ in range(h)]
q=[]
for i in range(h):
  for j in range(w):
    if grid[i][j]=='#':
      q.append((i,j,0))
dx=[-1,0,1,0]
dy=[0,1,0,-1]
ans=0
while q:
  ny,nx,cnt=q.pop(0)
  for i in range(4):
    cy=ny+dy[i]
    cx=nx+dx[i]
    if 0<=cy<h and 0<=cx<w and grid[cy][cx]=='.':
      grid[cy][cx]='#'
      q.append((cy,cx,cnt+1))
      ans=max(ans,cnt+1)
print(ans)

Fixed submission:
import numpy as np
h,w=map(int,input().split())
a=[]
for i in range(h):
  a.append([0 if i=='#' else h+w for i in list(input())])
a=np.array(a)
for i in range(h-1):
  a[i+1,:]=np.minimum(a[i,:]+1,a[i+1,:])
for i in range(h-1,0,-1):
  a[i-1,:]=np.minimum(a[i,:]+1,a[i-1,:])
for i in range(w-1):
  a[:,i+1]=np.minimum(a[:,i]+1,a[:,i+1])
for i in range(w-1,0,-1):
  a[:,i-1]=np.minimum(a[:,i]+1,a[:,i-1])
print(np.max(a))

Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque
h,w=map(int,input().split())
grid=[list(input()) for _ in range(h)]
q=deque()
for i in range(h):
  for j in range(w):
    if grid[i][j]=='#':
      q.append((i,j,0))
dx=[-1,0,1,0]
dy=[0,1,0,-1]
ans=0
while q:
  ny,nx,cnt=q.popleft()
  for i in range(4):
    cy=ny+dy[i]
    cx=nx+dx[i]
    if 0<=cy<h and 0<=cx<w and grid[cy][cx]=='.':
      grid[cy][cx]='#'
      q.append((cy,cx,cnt+1))
      ans=max(ans,cnt+1)
print(ans)

Fixed submission:
import numpy as np
h,w=map(int,input().split())
a=[]
for i in range(h):
  a.append([0 if i=='#' else h+w for i in list(input())])
a=np.array(a)
for i in range(h-1):
  a[i+1,:]=np.minimum(a[i,:]+1,a[i+1,:])
for i in range(h-1,0,-1):
  a[i-1,:]=np.minimum(a[i,:]+1,a[i-1,:])
for i in range(w-1):
  a[:,i+1]=np.minimum(a[:,i]+1,a[:,i+1])
for i in range(w-1,0,-1):
  a[:,i-1]=np.minimum(a[:,i]+1,a[:,i-1])
print(np.max(a))
Buggy python submission (verdict: Runtime Error):
s=list(input())
cnt=0
for i in range(1,n):
  if s[i]==s[i-1]=='1':
    cnt+=1
    s[i]='0'
  elif s[i]==s[i-1]=='0':
    cnt+=1
    s[i]='1'
print(cnt)

Fixed submission:
s=list(input())
cnt=0
for i in range(1,len(s)):
  if s[i]==s[i-1]=='1':
    cnt+=1
    s[i]='0'
  elif s[i]==s[i-1]=='0':
    cnt+=1
    s[i]='1'
print(cnt)
Buggy python submission (verdict: Time Limit Exceeded):
x,y,z,k=map(int,input().split())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
c=list(map(int,input().split()))
ab=sorted([x+y for x in a for y in b],reverse=True)[:k]
abc=sorted([x+y for x in ab for y in c],reverse=True)[:k]
for i in abc:
  print(i)

Fixed submission:
from heapq import nlargest
x,y,z,k=map(int,input().split())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
c=list(map(int,input().split()))
ab=nlargest(k,(x+y for x in a for y in b))
abc=nlargest(k,(xy+z for xy in ab for z in c))
for i in abc:
  print(i)

Buggy python submission (verdict: Runtime Error):
x,y,z,k=map(int,input().split())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
c=list(map(int,input().split()))
ab=[]
for i in range(x):
  for j in range(y):
    ab.append(a[i]+b[j])
ab.sort(reverse=True)
ab=ab[:k]
abc=[]
for i in range(k):
  for j in range(z):
    abc.append(ab[i]+c[j])
abc.sort(reverse=True)
for i in range(k):
  print(abc[i])

Fixed submission:
from heapq import nlargest
x,y,z,k=map(int,input().split())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
c=list(map(int,input().split()))
ab=nlargest(k,(x+y for x in a for y in b))
abc=nlargest(k,(xy+z for xy in ab for z in c))
for i in abc:
  print(i)
Buggy python submission (verdict: Runtime Error):
def Base_10_to_n(x,n):
  tmp=x
  out=''
  while tmp>0:
    out=str(tmp%n)+out
    tmp=int(tmp/n)
  return out
n,a,b,c=map(int,input().split())
l=[int(input()) for i in range(n)]
ans=10**18
for i in range(4**n):
  cost=0
  d=[[] for i in range(4)]
  s=Base_10_to_n(i,4).zfill(n)
  for j in range(n):
    k=int(s[j])
    d[k].append(l[j])
  if len(d[1])*len(d[2])*len(d[3])==0:
    continue
  for i in range(1,4):
    cost+=(len(d[k])-1)*10
  d1=sum(d[1])
  d2=sum(d[2])
  d3=sum(d[3])
  l=[abs(d1-a)+abs(d2-b)+abs(d3-c),abs(d1-a)+abs(d2-c)+abs(d3-b),abs(d1-b)+abs(d2-a)+abs(d3-c),abs(d1-b)+abs(d2-c)+abs(d3-a),abs(d1-c)+abs(d2-a)+abs(d3-b),abs(d1-c)+abs(d2-b)+abs(d3-a)]
  cost=min(l)
  ans=min(ans,cost)
print(ans)

Fixed submission:
def Base_10_to_n(x,n):
  tmp=x
  out=''
  while tmp>0:
    out=str(tmp%n)+out
    tmp=int(tmp/n)
  return out
n,a,b,c=map(int,input().split())
l=[int(input()) for i in range(n)]
ans=10**18
for i in range(4**n):
  cost=0
  d=[[] for j in range(4)]
  s=Base_10_to_n(i,4).zfill(n)
  for j in range(n):
    k=int(s[j])
    d[k].append(l[j])
  if len(d[1])*len(d[2])*len(d[3])==0:
    continue
  for j in range(1,4):
    cost+=(len(d[j])-1)*10
  d1=sum(d[1])
  d2=sum(d[2])
  d3=sum(d[3])
  L=[abs(d1-a)+abs(d2-b)+abs(d3-c),abs(d1-a)+abs(d2-c)+abs(d3-b),abs(d1-b)+abs(d2-a)+abs(d3-c),abs(d1-b)+abs(d2-c)+abs(d3-a),abs(d1-c)+abs(d2-a)+abs(d3-b),abs(d1-c)+abs(d2-b)+abs(d3-a)]
  cost+=min(L)
  ans=min(ans,cost)
print(ans)
Buggy python submission (verdict: Runtime Error):
n,k=map(int,input().split())
h=[int(input()) for i in range(n)]
h.sort()
ans=10**18
for i in range(k,n+1):
  ans=min(h[i-1]-h[i-k])
print(ans)

Fixed submission:
n,k=map(int,input().split())
h=[int(input()) for i in range(n)]
h.sort()
ans=10**18
for i in range(k,n+1):
  ans=min(ans,h[i-1]-h[i-k])
print(ans)
Buggy python submission (verdict: Runtime Error):
from collections import Counter
n=int(input())
v=list(map(int,input().split()))
s1,s2=[],[]
for i in range(n):
  if i%2==0:
    s1.append(v[i])
  else:
    s2.append(v[i])
c1=Counter(s1)
c2=Counter(s2)
d1=c1.most_common()
d2=c2.most_common()
if d1[0][0]!=d2[0][0]:
  print(n-d1[0][1]-d2[0][1])
else:
  print(min(n-d1[0][1]-d2[1][1],n-d1[1][1]-d2[0][1]))

Fixed submission:
from collections import Counter
n=int(input())
v=list(map(int,input().split()))
s1,s2=[],[]
for i in range(n):
  if i%2==0:
    s1.append(v[i])
  else:
    s2.append(v[i])
c1=Counter(s1)
c2=Counter(s2)
d1=c1.most_common()
d2=c2.most_common()
if d1[0][0]!=d2[0][0]:
  print(n-d1[0][1]-d2[0][1])
else:
  if len(d1)>1 and len(d2)>1:
    print(min(n-d1[0][1]-d2[1][1],n-d1[1][1]-d2[0][1]))
  elif len(d1)==1 and len(d2)==1:
    print(n//2)
  elif len(d1)==1:
    print(n//2-d2[0][1])
  else:
    print(n//2-d1[0][1])

Buggy python submission (verdict: Runtime Error):
import Counter
n=int(input())
v=list(map(int,input().split()))
s1,s2=[],[]
for i in range(n):
  if i%2==0:
    s1.append(v[i])
  else:
    s2.append(v[i])
c1=Counter(s1)
c2=Counter(s2)
d1=c1.most_common()
d2=c2.most_common()
if d1[0][0]!=d2[0][0]:
  print(n-d1[0][1]-d2[0][1])
else:
  print(min(n-d1[0][1]-d2[1][1],n-d1[1][1]-d2[0][1]))

Fixed submission:
from collections import Counter
n=int(input())
v=list(map(int,input().split()))
s1,s2=[],[]
for i in range(n):
  if i%2==0:
    s1.append(v[i])
  else:
    s2.append(v[i])
c1=Counter(s1)
c2=Counter(s2)
d1=c1.most_common()
d2=c2.most_common()
if d1[0][0]!=d2[0][0]:
  print(n-d1[0][1]-d2[0][1])
else:
  if len(d1)>1 and len(d2)>1:
    print(min(n-d1[0][1]-d2[1][1],n-d1[1][1]-d2[0][1]))
  elif len(d1)==1 and len(d2)==1:
    print(n//2)
  elif len(d1)==1:
    print(n//2-d2[0][1])
  else:
    print(n//2-d1[0][1])
Buggy python submission (verdict: Runtime Error):
from collections import Counter
s=input()
t=input()
c1=Counter(s)
c2=Counter(t)
c1.sort()
c2.sort()
print('Yes' if c1==c2 else 'No')

Fixed submission:
from collections import Counter
s=input()
t=input()
cntS=list(Counter(s).values())
cntT=list(Counter(t).values())
cntS.sort()
cntT.sort()
print('Yes' if cntS==cntT else 'No')
Buggy python submission (verdict: Time Limit Exceeded):
def comb(n,k,p):
  from math import factorial
  if n<0 or k<0 or n<k:return 0
  if n==0 and k==0:return 1
  a=factorial(n)%p
  b=factorial(k)%p
  c=factorial(n-k)%p
  return (a*power_func(b,p-2,p)*power_func(c,p-2,p))%p
def power_func(a,b,p):
  if b==0:
    return 1
  if b%2==0:
    d=power_func(a,b//2,p)
    return (d*d)%p
  else:
    return (a*power_func(a,b-1,p))%p
n,m=map(int,input().split())
mod=10**9+7
d=[]
for i in range(2,int(m**0.5)+1):
  if m%i==0:
    cnt=0
    while m%i==0:
      m//=i
      cnt+=1
    d.append(cnt)
if m>1:
  d.append(1)
ans=1
for k in d:
  ans=(ans*comb(k+n-1,k,mod))%mod
print(ans)

Fixed submission:
from math import sqrt, floor
from collections import defaultdict
def comb(n,m):
    if m == 0:
        return 1
    return comb(n-1,m-1)*n // m
def facts(n):
    dic = defaultdict(int)
    for i in range(2,floor(sqrt(n))+1):
        while n % i == 0:
            n //= i
            dic[i] += 1
        if n == 1:
            break
    if n != 1:
        dic[n] += 1
    return dic
N, M = map(int,input().split())
mod = 10**9+7
ans = 1
dic = facts(M)
for p in dic:
    ans = (ans*(comb(dic[p]+N-1, dic[p]) % mod)) % mod
print(ans)
Buggy python submission (verdict: Runtime Error):
N=10**6
def comb(n, r):
    if ( r<0 or r>n ):
        return 0
    r = min(r, n-r)
    return g1[n] * g2[r] * g2[n-r]
g1 = [1, 1] # 元テーブル
g2 = [1, 1] #逆元テーブル
inverse = [0, 1] #逆元テーブル計算用テーブル
for i in range( 2, N + 1 ):
    g1.append( ( g1[-1] * i ) % mod )
    inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod )
    g2.append( (g2[-1] * inverse[-1]) % mod )

n,k=map(int,input().split())
if k==2:
  print((comb(n//2,3)+comb(n-n//2,3))*6)
else:
  print(comb(n//k,3)*6)

Fixed submission:
n,k=map(int,input().split())
s=n//k
t=0
if k%2==0:
  t=(n+k//2)//k
print(s*s*s+t*t*t)
Buggy python submission (verdict: Time Limit Exceeded):
n,m,q=map(int,input().split())
line=[[0]*(n+1) for _ in range(n+1)]
for i in range(m):
  l,r=map(int,input().split())
  for j in range(0,l):
    for k in range(r-1,n):
      line[j][k]+=1
for _ in range(q):
  x,y=map(int,input().split())
  print(line[x-1][y-1])

Fixed submission:
n,m,q=map(int,input().split())
line=[[0]*(n+1) for _ in range(n+1)]
for i in range(m):
  l,r=map(int,input().split())
  line[l][r]+=1
for i in range(n+1):
  for j in range(n):
    line[i][j+1]+=line[i][j]
for i in range(n+1):
  for j in range(n):
    line[j+1][i]+=line[j][i]
for i in range(q):
  x,y=map(int,input().split())
  print(line[y][y]-line[x-1][y]-line[y][x-1]+line[x-1][x-1])
Buggy python submission (verdict: Runtime Error):
n,m=map(int,input().split())
a=list(map(int,input().split()))
b=[0]*(n+1)
cnt=[0]*m
s=set()
for i in range(1,n+1):
  b[i]=b[i-1]+a[i-1]
for i in range(n+1):
  cnt[b[i]%m]+=1
  s.add(b[i]%m)
ans=0
for i in s:
  ans+=cnt[i]*(cnt[i]-1)//2
print(ans)


Fixed submission:
from collections import Counter
import numpy as np
n,m=map(int,input().split())
a=[0]+list(map(int,input().split()))
d=Counter(np.cumsum(a)%m)
ans=0
for v in d.values():
  ans+=v*(v-1)//2
print(ans)

Buggy python submission (verdict: Runtime Error):
n,m=map(int,input().split())
a=list(map(int,input().split()))
b=[0]*(n+1)
cnt=[0]*m
for i in range(1,n+1):
  b[i]=b[i-1]+a[i-1]
for i in range(n+1):
  cnt[b[i]%m]+=1
ans=0
for i in range(m):
  ans+=cnt[i]*(cnt[i]-1)//2
print(ans)

Fixed submission:
from collections import Counter
import numpy as np
n,m=map(int,input().split())
a=[0]+list(map(int,input().split()))
d=Counter(np.cumsum(a)%m)
ans=0
for v in d.values():
  ans+=v*(v-1)//2
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
a=list(map(int,input().split()))
c=[a[i]-i-1 for i in range(n)]
cum_c=[0]*n
c.sort()
cum_c[0]=c[0]
for i in range(1,n):
  cum_c[i]=cum_c[i-1]+c[i]
ans=min(cum_c[n-1]-n*c[0],n*c[n-1]-cum_c[n-1])
for i in range(1,n):
  for b in range(c[i-1],c[i]+1):
    ans=min(ans,cum_c[n-1]-2*cum_c[i-1]+(2*i-n)*b)
print(ans)

Fixed submission:
n=int(input())
a=list(map(int,input().split()))
c=[a[i]-i-1 for i in range(n)]
cum_c=[0]*n
c.sort()
cum_c[0]=c[0]
for i in range(1,n):
  cum_c[i]=cum_c[i-1]+c[i]
ans=min(cum_c[n-1]-n*c[0],n*c[n-1]-cum_c[n-1])
for i in range(1,n):
  ans=min(ans,cum_c[n-1]-2*cum_c[i-1]+(2*i-n)*c[i-1])
  ans=min(ans,cum_c[n-1]-2*cum_c[i-1]+(2*i-n)*c[i])
print(ans)
Buggy python submission (verdict: Runtime Error):
k=input()
a=0
b=1
for i in range(k):
  a+=b
  print(a)
  if b<(a+b)/sum(map(int,str(a+b))):
    b*=10

Fixed submission:
k=int(input())
a=0
b=1
for i in range(k):
  a+=b
  print(a)
  if b<(a+b)/sum(map(int,str(a+b))):
    b*=10
Buggy python submission (verdict: Runtime Error):
n=int(input())
a=list(map(int,input().split()))
ans=0
s=0
r=0
for l in range(n):
  while r<n and s^a[r]==s+a[r]:
    sum+=a[r]
    r+=1
  ans+=r-l
  s-=a[l]
print(ans)

Fixed submission:
n=int(input())
a=list(map(int,input().split()))
ans=0
s=0
r=0
for l in range(n):
  while r<n and s^a[r]==s+a[r]:
    s+=a[r]
    r+=1
  ans+=r-l
  s-=a[l]
print(ans)
Buggy python submission (verdict: Runtime Error):
n=int(input())
p=[int(input()) for _ in range(n)]
dp=[0]*(n+10)
for i in p:
  dp[p]=dp[p-1]+1
print(n-max(dp))


Fixed submission:
n=int(input())
p=[int(input()) for _ in range(n)]
dp=[0]*(n+10)
for i in p:
  dp[i]=dp[i-1]+1
print(n-max(dp))