Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
def main():
  n=int(input())
  a=list(map(int,input().split()))
  mod=pow(10,9)+7
  dp=[0,0,0] # dp[j]:前から順番に見た時の帽子jの数
  ans=1
  for ai in a:
    ans*=dp.count(ai)
    ans%=mod
    dp[dp.index(ai)]+=1
  print(ans)

if __name__=='__main__':
  main()


Fixed submission:
def main():
  n=int(input())
  a=list(map(int,input().split()))
  mod=pow(10,9)+7
  dp=[0,0,0] # dp[j]:前から順番に見た時の帽子jの数
  ans=1
  for ai in a:
    if ai in dp:
      ans*=dp.count(ai)
      ans%=mod
      dp[dp.index(ai)]+=1
    else:
      print(0)
      exit()
  print(ans)
if __name__=='__main__':
  main()
Buggy python submission (verdict: Time Limit Exceeded):
t1,t2=map(int,input().split())
a1,a2=map(int,input().split())
b1,b2=map(int,input().split())
if t1*a1+t2*a2==t1*b1+t2*b2:
  print('infinity')
else:
  ans=0
  d=0 # a-b
  pre=0
  while True:
    if d!=0:
      if (d+(t1*a1-t1*b1))*d<=0:
        ans+=1
    d+=t1*a1-t1*b1
    if d!=0:
      if (d+(t2*a2-t2*b2))*d<=0:
        ans+=1
    d+=t2*a2-t2*b2
    if pre==ans:break
    pre=ans
  print(ans)


Fixed submission:
t1,t2=map(int,input().split())
a1,a2=map(int,input().split())
b1,b2=map(int,input().split())
c1,c2=a1-b1,a2-b2
if t1*c1+t2*c2==0:
  print('infinity')
else:
  # t1+t2でどれだけ二人が離れるか。
  d=t1*c1+t2*c2
  if c2*d<0:
    print(0)
  elif abs(t2*c2)<abs(d):
    print(0)
  else:
    tmp=((t2*c2)//d)
    if (t2*c2)%d==0:
      print(2*tmp-2)
    else:
      print(2*tmp-1)
Buggy python submission (verdict: Time Limit Exceeded):
n,k=map(int,input().split())
a=list(map(lambda x:(int(x)-1)%k,input().split()))
a_=0
cs_a=[0]
for ai in a:
  a_+=ai
  a_%=k
  cs_a.append(a_)
jouyo=[[]for _ in range(k)]
for i,cs in enumerate(cs_a):
  jouyo[cs].append(i)
import bisect
def func(arg):
  if len(arg)<2:
    return 0
  ret=0
  for i in range(len(arg)):
    idx=bisect.bisect_right(arg,arg[i]+k-1)
    ret+=idx-i-1
  return ret
ans=0
for j in jouyo:
  ans+=func(j)
print(ans)


Fixed submission:
n,k=map(int,input().split())
a=list(map(lambda x:(int(x)-1)%k,input().split()))
a_=0
cs_a=[0]
for ai in a:
  a_+=ai
  a_%=k
  cs_a.append(a_)
ans=0
from collections import defaultdict
d=defaultdict(int)
for i in range(n+1):
  ans+=d[cs_a[i]]
  d[cs_a[i]]+=1
  if i>=k-1:
    d[cs_a[i-k+1]]-=1
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np
n,t=map(int,input().split())
ab=[list(map(int,input().split())) for _ in range(n)]
dp1=np.zeros((n+1,t),int)
dp2=np.zeros((n+2,t),int)
# dp1[i][j]:0<=i<=n:i個目までの料理で考えたとき（i個の料理）、時間j以内で食べられるおいしさの総和
# dp2[i][j]:1<=i<=n+1:i個目以降の料理で考えたとき（n-i+1個の料理）、時間j以内で食べられるおいしさの総和
for i in range(n):
  a,b=ab[i]
  dp1[i+1,:a]=dp1[i,:a]
  dp1[i+1,a:]=np.maximum(dp1[i,a:],dp1[i,:-a]+b)
  j=n-i
  a,b=ab[j-1]
  dp2[j,:a]=dp2[j+1,:a]
  dp2[j,a:]=np.maximum(dp2[j+1,a:],dp2[j+1,:-a]+b)
ans=0
for i in range(1,n+1):# i個目の料理を最後に食べるとするとき。
  ai=max([dp1[i-1][j]+dp2[i+1][t-1-j] for j in range(t)])
  ans=max(ans,ai+ab[i-1][1])
print(ans)



Fixed submission:
n,t=map(int,input().split())
ab=[list(map(int,input().split())) for _ in range(n)]
ab.sort(key=lambda x:x[0])
import numpy as np
ans=0
dp=np.zeros(t,np.int64)
# dp[i]:時間合計i以内に食べれる料理のおいしさ総和の最大
for i in range(n):
  a,b=ab[i]
  ans=max(ans,dp[-1]+b)
  dp[a:]=np.maximum(dp[a:],dp[:-a]+b)
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n,t=map(int,input().split())
ab=[list(map(int,input().split())) for _ in range(n)]
import numpy as np
def func(j):
  dp=np.zeros(3001,np.int64)
  # dp[i]:時間合計i以内に食べれる料理のおいしさ総和
  for i in range(n):
    if j==i:
      continue
    a,b=ab[i]
    dp[a:]=np.maximum(dp[a:],dp[:-a]+b)
  return dp[t-1]
ans=0
for i in range(n):
  ans=max(ans,func(i)+ab[i][1])
print(ans)


Fixed submission:
n,t=map(int,input().split())
ab=[list(map(int,input().split())) for _ in range(n)]
ab.sort(key=lambda x:x[0])
import numpy as np
ans=0
dp=np.zeros(t,np.int64)
# dp[i]:時間合計i以内に食べれる料理のおいしさ総和の最大
for i in range(n):
  a,b=ab[i]
  ans=max(ans,dp[-1]+b)
  dp[a:]=np.maximum(dp[a:],dp[:-a]+b)
print(ans)
Buggy python submission (verdict: Runtime Error):
from collections import defaultdict
n=int(input())
d=list(map(int,input().split()))
mod=998244353
if d[0]!=0:
      print(0)
      exit()
dd=defaultdict(lambda:0)
for di in d:
      dd[di]+=1
if dd[0]>1:
      print(0)
      exit()
ans=1
for i in dd.keys():
      if i==0:
            continue
      ans*=(dd[i-1]**dd[i])%mod
print(ans%mod)      

Fixed submission:
from collections import defaultdict
n=int(input())
d=list(map(int,input().split()))
mod=998244353
if d[0]!=0:
      print(0)
      exit()
dd=defaultdict(lambda:0)
for di in d:
      dd[di]+=1
if dd[0]>1:
      print(0)
      exit()
ans=1
for i in set(dd.keys()):
      if i==0:
            continue
      ans*=(dd[i-1]**dd[i])%mod
print(ans%mod)
Buggy python submission (verdict: Time Limit Exceeded):
s=input()
a=[0]*(len(s)+1)
for i in range(len(a)):
  j=i
  r=0
  l=0
  while j < len(s) and s[j] == '>':
    r+=1
    j+=1
  j=i
  while 0 < j and s[j-1] == '<':
    l+=1
    j-=1   
  a[i]=max(l,r)
print(sum(a))

Fixed submission:
s=input()
a=[0]*(len(s)+1)
r=0
l=0
for i in range(len(a)):
  j=i
  if r==0:
    while j < len(s) and s[j] == '>':
      r+=1
      j+=1
  else:
    r-=1
  if i !=0 and s[i-1] == '<':
    l+=1
  else:
    l=0
  a[i]=max(l,r)
print(sum(a))
Buggy python submission (verdict: Runtime Error):
n=int(input())
lr=[list(map(int,input().split())) for _ in range(n)]
lr.sort(key=lambda x:x[0])
# 右端がもっとも左にある問題
r0=0
tmpr=float('inf')
# 左端がもっとも右にある問題
l0=0
tmpl=0
for i,x in enumerate(lr):
  l,r=x
  if tmpl<l:
    l0=i
    tmpl=l
  if tmpr>r:
    r0=i
    tmpr=r
if l0==r0:
  ans=lr[r0][1]-lr[l0][0]+1
  tmp=0
  for i in range(n):
    if i==l0:continue
    l,r=lr[i]
    tmp=max(tmp,r-l+1)
  ans+=tmp
  print(ans)
  exit()
ans0=max(0,lr[r0][1]-lr[l0][0]+1)
tmp=0
for i in range(n):
  if i==l0 or i==r0:continue
  l,r=lr[i]
  tmp=max(tmp,r-l+1)
ans0+=tmp


import heapq
class pqheap:
  def __init__(self,key=None):
    self.p = list()
    self.q = list()
  def insert(self,x):
    heapq.heappush(self.p, x)
    return
  def erase(self,x):
    heapq.heappush(self.q, x)
    return
  def minimum(self):
    while self.q and self.p[0] == self.q[0]:
      heapq.heappop(self.p)
      heapq.heappop(self.q)
    return self.p[0] if len(self.p)>0 else None
pq=pqheap()

[pq.insert(x[1]) for i,x in enumerate(lr) if i!=l0 and i!=r0]
l1,r1=lr[r0]
l2,r2=lr[l0]
r2=min(r2,pq.minimum())
ans1=max(r1-l1+1,0)
ans1+=max(r2-l2+1,0)
for i,[l,r] in enumerate(lr):
  if i==l0 or i==r0:continue
  tmp=0
  l1=max(l1,l)
  pq.erase(r)
  tmp=max(r1-l1+1,0)
  if pq.minimum():
    r2=min(lr[l0][1],pq.minimum())
  else:
    l2,r2=lr[l0]
  tmp+=max(r2-l2+1,0)
  ans1=max(ans1,tmp)
print(max(ans1,ans0))


Fixed submission:
n=int(input())
lr=[list(map(int,input().split())) for _ in range(n)]
lr.sort(key=lambda x:x[0])
# 右端がもっとも左にある問題
r0=0
tmpr=float('inf')
# 左端がもっとも右にある問題
l0=0
tmpl=0
for i,x in enumerate(lr):
  l,r=x
  if tmpl<l:
    l0=i
    tmpl=l
  if tmpr>r:
    r0=i
    tmpr=r
if l0==r0:
  ans=lr[r0][1]-lr[l0][0]+1
  tmp=0
  for i in range(n):
    if i==l0:continue
    l,r=lr[i]
    tmp=max(tmp,r-l+1)
  ans+=tmp
  print(ans)
  exit()
ans0=max(0,lr[r0][1]-lr[l0][0]+1)
tmp=0
for i in range(n):
  if i==l0 or i==r0:continue
  l,r=lr[i]
  tmp=max(tmp,r-l+1)
ans0+=tmp


import heapq
class pqheap:
  def __init__(self,key=None):
    self.p = list()
    self.q = list()
  def insert(self,x):
    heapq.heappush(self.p, x)
    return
  def erase(self,x):
    heapq.heappush(self.q, x)
    return
  def minimum(self):
    while self.q and self.p[0] == self.q[0]:
      heapq.heappop(self.p)
      heapq.heappop(self.q)
    return self.p[0] if len(self.p)>0 else None
pq=pqheap()

[pq.insert(x[1]) for i,x in enumerate(lr) if i!=l0 and i!=r0]
l1,r1=lr[r0]
l2,r2=lr[l0]
if pq.minimum():r2=min(r2,pq.minimum())
ans1=max(r1-l1+1,0)
ans1+=max(r2-l2+1,0)
for i,[l,r] in enumerate(lr):
  if i==l0 or i==r0:continue
  tmp=0
  l1=max(l1,l)
  pq.erase(r)
  tmp=max(r1-l1+1,0)
  if pq.minimum():
    r2=min(lr[l0][1],pq.minimum())
  else:
    l2,r2=lr[l0]
  tmp+=max(r2-l2+1,0)
  ans1=max(ans1,tmp)
print(max(ans1,ans0))
Buggy python submission (verdict: Time Limit Exceeded):
import heapq
n,k=map(int,input().split())
a=sorted(list(map(int,input().split())))
f=sorted(list(map(int,input().split())),reverse=True)
d=[[-a[i]*f[i],f[i]] for i in range(n)]
d.sort(key=lambda x:x[0])
heapq.heapify(d)
for _ in range(k):
  i,j=heapq.heappop(d)
  i+=j
  heapq.heappush(d,[i,j])
ans,_=heapq.heappop(d)
print(max(ans*(-1),0))


Fixed submission:
n,k=map(int,input().split())
a=sorted(list(map(int,input().split())))
f=sorted(list(map(int,input().split())),reverse=True)
d=[[a[i]*f[i],f[i]] for i in range(n)]
r=max([di[0] for di in d])+1
l=0
x=(l+r)//2
while r-l>1:
  if r-l==2:
    cnt=0
    for di,fi in d:
      cnt+=max(0,(di-l+fi-1)//fi)
    if cnt<=k:
      x=l
    else:
      x=l+1
    break
  cnt=0
  for di,fi in d:
    cnt+=max(0,(di-x+fi-1)//fi)
  if cnt>k:
    l,r=x,r
  else:
    l,r=l,x+1
  x=(l+r)//2
if r-l==2:
  if cnt>k:
    x=l+1
  else:
    x=l

print(x)
Buggy python submission (verdict: Runtime Error):

def main(n,m,g,uv):
    # 1<=E<=n-1
    eary=[inf]*m
    vary=[inf]*n
    vary[-1]=0
    todo=[n-1]
    def dfs(v,x):
        if vary[v]<inf:return vary[v]
        ret=0
        cnt=0
        for i,nv in g[v]:
            if i==x:continue
            tmp=dfs(nv,x)+1
            eary[i]=tmp
            ret+=tmp
            cnt+=1
        if cnt==0:
            for i in range(n):
                vary[i]=inf
            return inf
        vary[v]=ret/cnt
        return ret/cnt
    e0=dfs(0,-1)
    ary=[-1]*m
    bary=[0]*n
    bary[0]=1
    for v in range(n):
        k=len(g[v])
        e=vary[v]
        for i,nv in g[v]:
            bary[nv]+=1/k*bary[v]
            if k>1 and bary[v]:
                ary[i]=max(0,e-(e*k-eary[i])/(k-1))
                ary[i]*=bary[v]
    #print(e0)
    #print(vary)
    #print(ary)
    #print(bary)
    return e0-max(0,max(ary))

n,m=map(int,input().split())
uv=[list(map(int,input().split())) for _ in range(m)]
g=[[] for _ in range(n)]
for i,(u,v) in enumerate(uv):
    u,v=u-1,v-1
    g[u].append((i,v))
print(main(n,m,g,uv))

Fixed submission:
import sys
sys.setrecursionlimit(10**7)
inf=float('inf')

def main(n,m,g,uv):
    # 1<=E<=n-1
    eary=[inf]*m
    vary=[inf]*n
    vary[-1]=0
    todo=[n-1]
    def dfs(v,x):
        if vary[v]<inf:return vary[v]
        ret=0
        cnt=0
        for i,nv in g[v]:
            if i==x:continue
            tmp=dfs(nv,x)+1
            eary[i]=tmp
            ret+=tmp
            cnt+=1
        if cnt==0:
            for i in range(n):
                vary[i]=inf
            return inf
        vary[v]=ret/cnt
        return ret/cnt
    e0=dfs(0,-1)
    ary=[-1]*m
    bary=[0]*n
    bary[0]=1
    for v in range(n):
        k=len(g[v])
        e=vary[v]
        for i,nv in g[v]:
            bary[nv]+=1/k*bary[v]
            if k>1 and bary[v]:
                ary[i]=max(0,e-(e*k-eary[i])/(k-1))
                ary[i]*=bary[v]
    return e0-max(0,max(ary))

n,m=map(int,input().split())
uv=[list(map(int,input().split())) for _ in range(m)]
g=[[] for _ in range(n)]
for i,(u,v) in enumerate(uv):
    u,v=u-1,v-1
    g[u].append((i,v))
print(main(n,m,g,uv))
Buggy python submission (verdict: Time Limit Exceeded):
def main():
  n=int(input())
  l=list(map(int,input().split()))
  l.sort()
  import bisect
  ans=0
  for i in range(n-2):
    for j in range(i+1,n-1):
      a=l[i]
      b=l[j]
      idxl=bisect.bisect_right(l[j+1:],abs(a-b))
      idxr=bisect.bisect_left(l[j+1:],abs(a+b))
      ans+=idxr-idxl
  print(ans)
if __name__=='__main__':
  main()


Fixed submission:
n=int(input())
l=sorted(list(map(int,input().split())))
import bisect
ans=0
for i in range(n):
  for j in range(i):
    index=bisect.bisect_right(l,l[i]-l[j])#このindexよりも右側のものでかつjより左のものが当てはまるもの
    ans += max(j - index,0)
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
l=list(map(int,input().split()))
l.sort()
import bisect
ans=0
for i in range(n-2):
  for j in range(i+1,n-1):
    a=l[i]
    b=l[j]
    idxl=bisect.bisect_right(l[j+1:],abs(a-b))
    idxr=bisect.bisect_left(l[j+1:],abs(a+b))
    ans+=idxr-idxl
print(ans)


Fixed submission:
n=int(input())
l=sorted(list(map(int,input().split())))
import bisect
ans=0
for i in range(n):
  for j in range(i):
    index=bisect.bisect_right(l,l[i]-l[j])#このindexよりも右側のものでかつjより左のものが当てはまるもの
    ans += max(j - index,0)
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
l=list(map(int,input().split()))
l.sort()
import bisect
ans=0
for i in range(n-2):
  for j in range(i+1,n-1):
    a=l[i]
    b=l[j]
    idxl=bisect.bisect_right(l[j+1:],abs(a-b))
    idxr=bisect.bisect_left(l[j+1:],abs(a+b))
    ans+=idxr-idxl
print(ans)


Fixed submission:
n=int(input())
l=sorted(list(map(int,input().split())))
import bisect
ans=0
for i in range(n):
  for j in range(i):
    index=bisect.bisect_right(l,l[i]-l[j])#このindexよりも右側のものでかつjより左のものが当てはまるもの
    ans += max(j - index,0)
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
l=list(map(int,input().split()))
d={}
for li in l:
  if li in d:
    d[li]+=1
  else:
    d[li]=1
l=list(set(l))
l.sort()
ans=0
for i in range(len(l)):
  for j in range(i+1):
    ls=[li for li in l[:j+1] if li>l[i]-l[j]]
    for lsi in ls:
      if l[i]==l[j] and l[j]==lsi:
        ans+=d[l[i]]*(d[l[i]]-1)*(d[l[i]]-2)//6
        #print(str(ans)+' '+str(l[i])+' '+str(l[j])+' '+str(lsi))
      elif l[i]==l[j]:
        ans+=d[l[i]]*(d[l[i]]-1)*d[lsi]//2
      elif l[j]==lsi:
        ans+=d[l[i]]*d[l[j]]*(d[l[j]]-1)//2
      else:
        ans+=d[l[i]]*d[l[j]]*d[lsi]
print(ans)


Fixed submission:
n=int(input())
l=sorted(list(map(int,input().split())))
import bisect
ans=0
for i in range(n):
  for j in range(i):
    index=bisect.bisect_right(l,l[i]-l[j])#このindexよりも右側のものでかつjより左のものが当てはまるもの
    ans += max(j - index,0)
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
n,m=map(int,input().split())
ab=[]
c=[]
for _ in range(m):
  ab.append(list(map(int,input().split())))
  c.append(list(map(int,input().split())))
dp={():0}
for i in range(m):
  a,b=ab[i]
  sc=set(c[i])
  dptmp={}
  for k,v in dp.items():
    s=set(k)
    s|=sc
    t=tuple(sorted(list(s)))
    dptmp[t]=min(v+a,dp[t] if t in dp else float('inf'),dptmp[t] if t in dptmp else float('inf'))
  dp.update(dptmp)

t=tuple(range(1,n+1))
if t in dp:
  print(dp[t])
else:
  print(-1)


Fixed submission:
n,m=map(int,input().split())
ab=[]
c=[]
for _ in range(m):
  ab.append(list(map(int,input().split())))
  c.append(list(map(int,input().split())))
dp={'0'*n:0}
for i in range(m):
  a,b=ab[i]
  ci=c[i]
  dptmp={}
  for k,v in dp.items():
    s=list(k)
    for cii in ci:
      s[cii-1]='1'
    t=''.join(s)
    dptmp[t]=min(v+a,dp[t] if t in dp else float('inf'),dptmp[t] if t in dptmp else float('inf'))
  dp.update(dptmp)

t='1'*n
if t in dp:
  print(dp[t])
else:
  print(-1)
#print(dp)

Buggy python submission (verdict: Time Limit Exceeded):
n,m=map(int,input().split())
ab=[]
c=[]
for _ in range(m):
  ab.append(list(map(int,input().split())))
  c.append(list(map(int,input().split())))
dp={():0}
for i in range(m):
  a,b=ab[i]
  sc=set(c[i])
  dptmp={}
  for k,v in dp.items():
    s=set(k)
    s|=sc
    t=tuple(sorted(list(s)))
    dptmp[t]=min(v+a,dp[t] if t in dp else float('inf'),dptmp[t] if t in dptmp else float('inf'))
  dp.update(dptmp)

t=tuple(range(1,n+1))
if t in dp:
  print(dp[t])
else:
  print(-1)


Fixed submission:
n,m=map(int,input().split())
ab=[]
c=[]
for _ in range(m):
  ab.append(list(map(int,input().split())))
  c.append(list(map(int,input().split())))
dp={'0'*n:0}
for i in range(m):
  a,b=ab[i]
  ci=c[i]
  dptmp={}
  for k,v in dp.items():
    s=list(k)
    for cii in ci:
      s[cii-1]='1'
    t=''.join(s)
    dptmp[t]=min(v+a,dp[t] if t in dp else float('inf'),dptmp[t] if t in dptmp else float('inf'))
  dp.update(dptmp)

t='1'*n
if t in dp:
  print(dp[t])
else:
  print(-1)
#print(dp)
Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
ss=input()

# Z-algorithm
# 文字列が与えられた時、各 i について「S と S[i:|S|-1] の最長共通接頭辞の長さ」を記録した配列 A を O(|S|) で構築するアルゴリズムです。
#s='aaabaaaab'
def func(s):
  a=[0]*len(s)
  a[0]=len(s)
  i,j=1,0
  while i<len(s):
    while i+j<len(s) and s[j]==s[i+j]:
      j+=1
    a[i]=j
    if j==0:
      i+=1
      continue
    k=1
    while i+k<len(s) and k+a[k]<j:
      a[i+k]=a[k]
      k+=1
    i+=k
    j-=k
  return a
ans=0
for i in range(n):
  a=func(ss[i:])
  for j in range(len(a)):
    ans=max(ans,min(a[j],j))
print(ans)


Fixed submission:
n=int(input())
ss=input()

# Z-algorithm
# 文字列が与えられた時、各 i について「S と S[i:|S|-1] の最長共通接頭辞の長さ」を記録した配列 A を O(|S|) で構築するアルゴリズムです。
#s='aaabaaaab'
def func(s):
  a=[0]*len(s)
  a[0]=len(s)
  i,j=1,0
  while i<len(s):
    while i+j<len(s) and s[j]==s[i+j]:
      j+=1
    a[i]=j
    if j==0:
      i+=1
      continue
    k=1
    while i+k<len(s) and k+a[k]<j:
      a[i+k]=a[k]
      k+=1
    i+=k
    j-=k
  return a
ans=0
for i in range(n):
  a=func(ss[i:])
  for j in range(len(a)):
    ans=max(ans,min(a[j],j))
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
print(sum(range(n)))

Fixed submission:
n=int(input())
print(n * (n-1) // 2)
Buggy python submission (verdict: Runtime Error):
n=int(input())
a=sorted(list(map(int,input().split())))
if n%3==0:
  d={}
  for ai in a:
    if ai not in d:
      d[ai]=a.count(ai)
  sa=list(set(a))
  if sa[0]^sa[1]==sa[2] and d[sa[0]]==d[sa[1]] and d[sa[0]]==d[sa[2]]:
    print('Yes')
    exit()
print('No')

Fixed submission:
n=int(input())
a=sorted(list(map(int,input().split())))
if n%3==0:
  d={}
  for ai in a:
    if ai not in d:
      d[ai]=a.count(ai)
      if len(d)==4:
        break
  sa=list(set(a))
  if len(sa)==3 and sa[0]^sa[1]==sa[2] and d[sa[0]]==d[sa[1]] and d[sa[0]]==d[sa[2]]:
    print('Yes')
    exit()
  if len(sa)==2 and 0 in d and 2*d[0]==max(d[sa[0]],d[sa[1]]):
    print('Yes')
    exit()

if n == a.count(0):
  print('Yes')
  exit()

print('No')

Buggy python submission (verdict: Runtime Error):
an=int(input())
a=sorted(list(map(int,input().split())))
if n%3==0:
  d={}
  for ai in a:
    if ai not in d:
      d[ai]=a.count(ai)
  sa=list(set(a))
  if sa[0]^sa[1]==sa[2] and d[sa[0]]==d[sa[1]] and d[sa[0]]==d[sa[2]]:
    print('Yes')
    exit()
print('No')

Fixed submission:
n=int(input())
a=sorted(list(map(int,input().split())))
if n%3==0:
  d={}
  for ai in a:
    if ai not in d:
      d[ai]=a.count(ai)
      if len(d)==4:
        break
  sa=list(set(a))
  if len(sa)==3 and sa[0]^sa[1]==sa[2] and d[sa[0]]==d[sa[1]] and d[sa[0]]==d[sa[2]]:
    print('Yes')
    exit()
  if len(sa)==2 and 0 in d and 2*d[0]==max(d[sa[0]],d[sa[1]]):
    print('Yes')
    exit()

if n == a.count(0):
  print('Yes')
  exit()

print('No')
Buggy python submission (verdict: Time Limit Exceeded):
n,m=map(int,input().split())
g=[[] for _ in range(n)]
for _ in range(m):
  a,b=map(int,input().split())
  a,b=a-1,b-1
  g[a].append(b)
s,t=map(int,input().split())
s,t=s-1,t-1
gg=[set(()) for _ in range(n)]
for i in range(n):
  for j in g[i]:
    for k in g[j]:
      for l in g[k]:
        if l!=i:
          gg[i].add(l)
from collections import deque
todo=deque([s])
seen=[-1]*n
seen[s]=0
while todo:
  v=todo.popleft()
  for l in gg[v]:
    if seen[l]==-1:
      todo.append(l)
      seen[l]=seen[v]+1
print(seen[t])

Fixed submission:
n,m=map(int,input().split())
g=[[] for _ in range(n)]
gg=[[] for _ in range(3*n)]
for _ in range(m):
  a,b=map(int,input().split())
  a,b=a-1,b-1
  gg[a].append(n+b)
  gg[n+a].append(2*n+b)
  gg[2*n+a].append(b)
s,t=map(int,input().split())
s,t=s-1,t-1
from collections import deque
todo=deque([s])
seen=[-1]*(3*n)
seen[s]=0
while todo:
  v=todo.popleft()
  for l in gg[v]:
    if seen[l]==-1:
      todo.append(l)
      seen[l]=seen[v]+1
      if l==t:
        print(seen[l]//3)
        exit()
if seen[t]>0:
  print(seen[t]//3)
else:
  print(-1)
Buggy python submission (verdict: Time Limit Exceeded):
def guchoku(n,k,mod):
    dp=[1]*(n+1)
    dp[0]=0
    for _ in range(k-1):
        ndp=[0]*(n+1)
        for i in range(1,n+1):
            ndp[i]+=sum([dp[j+1] for j in range(n//i)])
            ndp[i]%=mod
        dp=ndp.copy()
    return sum(dp)%mod
def main(n,k,mod):
    ary=[]
    tmp=0
    for i in range(1,int(n**0.5)+1):
        ary.append(n//i-n//(i+1))
        tmp+=ary[-1]
    tmp=n-tmp
    ary+=[1]*tmp
    ary.reverse()
    dp=[x for x in ary]
    m=len(ary)
    for i in range(m-1):
        dp[i+1]+=dp[i]
        dp[i+1]%=mod
    for _ in range(k-1):
        ndp=[0]*m
        for i in range(m):
            ndp[i]+=dp[-i-1]*ary[i]
            ndp[i]%=mod
            pass
        for i in range(m-1):
            ndp[i+1]+=ndp[i]
            ndp[i+1]%=mod
        dp=[x for x in ndp]
    return dp[-1]

n,k=map(int,input().split())
mod=10**9+7
#print(guchoku(n,k,mod))
print(main(n,k,mod))

Fixed submission:
def guchoku(n,k,mod):
    dp=[1]*(n+1)
    dp[0]=0
    for _ in range(k-1):
        ndp=[0]*(n+1)
        for i in range(1,n+1):
            ndp[i]+=sum([dp[j+1] for j in range(n//i)])
            ndp[i]%=mod
        dp=ndp.copy()
    return sum(dp)%mod
def main(n,k,mod):
    ary=[]
    tmp=0
    for i in range(1,int(n**0.5)+1):
        ary.append(n//i-n//(i+1))
        tmp+=ary[-1]
    tmp=n-tmp
    ary+=[1]*tmp
    ary.reverse()
    dp=[x for x in ary]
    m=len(ary)
    for i in range(m-1):
        dp[i+1]+=dp[i]
        dp[i+1]%=mod
    for _ in range(k-1):
        ndp=[0]*m
        for i in range(m):
            ndp[i]+=dp[-i-1]*ary[i]
            ndp[i]%=mod
            pass
        for i in range(m-1):
            ndp[i+1]+=ndp[i]
            ndp[i+1]%=mod
        dp=[x for x in ndp]
    return dp[-1]

n,k=map(int,input().split())
mod=10**9+7
#print(guchoku(n,k,mod))
print(main(n,k,mod))
Buggy python submission (verdict: Runtime Error):
import math
a,b,c,d=map(int,input().split())
base=b-a+1

n_c=math.floor(b/c)-math.ceil(a/c)+1
n_d=math.floor(b/d)-math.ceil(a/d)+1
cd=c*d/math.gcd(c,d)
n_cd=math.floor(b/cd)-math.ceil(a/cd)+1
print(base-n_c-n_d+n_cd)



Fixed submission:
import math
import fractions
a,b,c,d=map(int,input().split())
base=b-a+1
n_c=b//c-(a+c-1)//c+1
n_d=b//d-(a+d-1)//d+1
cd=c*d//fractions.gcd(c,d)
n_cd=b//cd-(a+cd-1)//cd+1
print(base-n_c-n_d+n_cd)
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()))
dp=[[0]*(m+1) for _ in range(n+1)]
for i in range(n+1):
  dp[i][0]=1
for i in range(m+1):
  dp[0][i]=1
mod=pow(10,9)+7
for i in range(n):
  for j in range(m):
    dp[i+1][j+1]=sum((dp[i][j+1],dp[i+1][j],-dp[i][j]))%mod
    if s[i]==t[j]:dp[i+1][j+1]+=dp[i][j]
    dp[i+1][j+1]%=mod
print(dp[-1][-1])
#print(dp)

Fixed submission:
n,m=map(int,input().split())
s=list(map(int,input().split()))
t=list(map(int,input().split()))
dp=[[0]*(m+1) for _ in range(n+1)]
for i in range(n+1):
  dp[i][0]=1
for i in range(m+1):
  dp[0][i]=1
mod=pow(10,9)+7
for i in range(n):
  for j in range(m):
    dp[i+1][j+1]=sum((dp[i][j+1],dp[i+1][j],-dp[i][j]))%mod
    if s[i]==t[j]:dp[i+1][j+1]+=dp[i][j]
    dp[i+1][j+1]%=mod
print(dp[-1][-1])
#print(dp)
Buggy python submission (verdict: Runtime Error):
from collections import defaultdict
n=int(input())
xy=[list(map(int,input().split())) for _ in range(n)]
d=defaultdict(lambda:0)
for i in range(n-1):
  for j in range(i+1,n):
    dx=xy[i][0]-xy[j][0]
    dy=xy[i][1]-xy[j][1]
    d[(dx,dy)]+=1
    d[(-dx,-dy)]+=1
print(n-max(d.values()))

Fixed submission:
from collections import defaultdict
n=int(input())
xy=[list(map(int,input().split())) for _ in range(n)]
if n==1:
  print(1)
  exit()
d=defaultdict(lambda:0)
for i in range(n-1):
  for j in range(i+1,n):
    dx=xy[i][0]-xy[j][0]
    dy=xy[i][1]-xy[j][1]
    d[(dx,dy)]+=1
    d[(-dx,-dy)]+=1
print(n-max(d.values()))
#for k,v in d.items():
#  print(k,v)