Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
s=input()
cnt=0
ans="No"
flag=True

while cnt<len(s):
  if len(s)==1:
    flag=False
    break
  if s[cnt]=="h" and s[cnt+1]=="i":
    cnt+=2
    continue
  else:
    flag=False
    break
if flag:
  ans="Yes"
print(ans)

Fixed submission:
s=input()
cnt=0
ans="No"
flag=True

while cnt<len(s):
  if len(s)==1 or len(s)%2==1:
    flag=False
    break
  if s[cnt]=="h" and s[cnt+1]=="i":
    cnt+=2
    continue
  else:
    flag=False
    break
if flag:
  ans="Yes"
print(ans)

Buggy python submission (verdict: Runtime Error):
s=input()
cnt=0
ans="No"
flag=True
while cnt<len(s):
  if s[cnt]=="h" and s[cnt+1]=="i":
    cnt+=2
    continue
  else:
    flag=False
    break
if flag:
  ans="Yes"
print(ans)

Fixed submission:
s=input()
cnt=0
ans="No"
flag=True

while cnt<len(s):
  if len(s)==1 or len(s)%2==1:
    flag=False
    break
  if s[cnt]=="h" and s[cnt+1]=="i":
    cnt+=2
    continue
  else:
    flag=False
    break
if flag:
  ans="Yes"
print(ans)
Buggy python submission (verdict: Runtime Error):
a,b,c=map(int,input().split())
if a==b:
  if b==c:
    ans="No"
  else:
    ans="Yes"
if b==c:
  if c==a:
    ans="No"
  else:
    ans="Yes"
if c==a:
  if a==b:
    ans="No"
  else:
    ans="Yes"
print(ans)    

Fixed submission:
a,b,c=map(int,input().split())
ans="No"
if a==b:
  if b==c:
    ans="No"
  else:
    ans="Yes"
if b==c:
  if c==a:
    ans="No"
  else:
    ans="Yes"
if c==a:
  if a==b:
    ans="No"
  else:
    ans="Yes"
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
n,k=map(int,input().split())
h=list(map(int,input().split()))
h.sort()
ans=0
h.reverse()
for i in range(k):
  if len(h)>=1:
    h.pop(0)
for i in h:
  if len(h)>=1:
    ans+=i
print(ans)

Fixed submission:
n,k=map(int,input().split())
h=list(map(int,input().split()))
h.sort()
ans=0
h.reverse()
if k<n:
  for i in range(k,n):
    ans+=h[i]
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n,k=map(int,input().split())
h=list(map(int,input().split()))
h.sort()
ans=0
h.reverse()
for i in range(k):
  if len(h)>=1:
    h.pop(0)
for i in h:
  if len(h)>=1:
    ans+=i
print(ans)

Fixed submission:
n,k=map(int,input().split())
h=list(map(int,input().split()))
h.sort()
ans=0
h.reverse()
if k<n:
  for i in range(k,n):
    ans+=h[i]
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
a=list(map(int,input().split()))
keta=[0 for i in range(61)]
ans=0
for i in range(n):
  b=a[i]
  cnt=0
  while(b>=1):
    if b%2==1:
      keta[cnt]+=1
    b=b//2
    cnt+=1
#print(keta)
for i in range(61):
  #print(keta[i])
  #print(keta[i]*(n-keta[i])*(2**i))
  ans+=(keta[i]*(n-keta[i])*(2**i))%(1000000007)
while(ans>1000000007):
  ans%=1000000007
print(ans)

Fixed submission:
n=int(input())
a=list(map(int,input().split()))
keta=[0 for i in range(61)]
ans=0
for i in range(n):
  b=a[i]
  cnt=0
  while(b>=1):
    if b%2==1:
      keta[cnt]+=1
    b=b//2
    cnt+=1
#print(keta)
for i in range(61):
  #print(keta[i])
  #print(keta[i]*(n-keta[i])*(2**i))
  ans+=(keta[i]*(n-keta[i])*(2**i))%(1000000007)
while(ans>1000000007):
  ans%=1000000007
print(ans)

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

Fixed submission:
n=int(input())
a=list(map(int,input().split()))
keta=[0 for i in range(61)]
ans=0
for i in range(n):
  b=a[i]
  cnt=0
  while(b>=1):
    if b%2==1:
      keta[cnt]+=1
    b=b//2
    cnt+=1
#print(keta)
for i in range(61):
  #print(keta[i])
  #print(keta[i]*(n-keta[i])*(2**i))
  ans+=(keta[i]*(n-keta[i])*(2**i))%(1000000007)
while(ans>1000000007):
  ans%=1000000007
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
a=[i+1 for i in range(n)]
b=[i+1 for i in range(n)]
c=b[-1]
b.insert(0,c)
del b[-1]
ans=0
for i in range(n):
  ans+=b[i]%a[i]
print(ans)

Fixed submission:
n=int(input())
print((n-1)*n//2)

Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
a=[i+1 for i in range(n)]
b=[i+1 for i in range(n)]
c=b[-1]
b.insert(0,c)
del b[-1]
ans=0
for i in range(n):
  ans+=b[i]%a[i]
print(ans)

Fixed submission:
n=int(input())
print((n-1)*n//2)
Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque

n,q=map(int,input().split())
ab=[list(map(int,input().split())) for i in range(n-1)]
p=[0 for i in range(n+1)]
edge=[[] for i in range(n+1)]
que=deque([])
que.append(1)
visited=[False for i in range(n+1)]
visited[0]=True
for i,j in ab:
  edge[i].append(j)
  edge[j].append(i)
for i in range(q):
  a,b=map(int,input().split())
  p[a]+=b

while que:
  v=que.pop()
  visited[v]=True
  for nv in edge[v]:
    if visited[nv]==True:
      continue
    p[nv]+=p[v]
    que.append(nv)
p.pop(0)
print(*p)


Fixed submission:
from collections import deque

n,q=map(int,input().split())
ab=[list(map(int,input().split())) for i in range(n-1)]
p=[0 for i in range(n+1)]
edge=[[] for i in range(n+1)]
que=deque([])
que.append(1)
visited=[False for i in range(n+1)]
visited[0]=True
for i,j in ab:
  edge[i].append(j)
  edge[j].append(i)
for i in range(q):
  a,b=map(int,input().split())
  p[a]+=b

while que:
  v=que.pop()
  visited[v]=True
  for nv in edge[v]:
    if visited[nv]==True:
      continue
    p[nv]+=p[v]
    que.append(nv)
p.pop(0)
print(*p)
Buggy python submission (verdict: Runtime Error):
n=int(input())
a=[0]
r=list(map(int,input().split()))
for i in range(n):
  a.append(r[i])
b=[0 for i in range(n+1)]


for i in range((n//2+1),n+1):
  b[i]=a[i]
for i in range(n//2,0,-1):

  j=2
  b[i]=a[i]
  while(j*i=<n):
    b[i]^=a[j*i]
    j+=1

m=0
for i in range(n):
  m+=b[i]
print(m)
print(b)
for i in range(n):
  if b[i]==1:
    print(i)
    
  

Fixed submission:
n=int(input())
a=[0]
r=list(map(int,input().split()))
for i in range(n):
  a.append(r[i])
b=[0 for i in range(n+1)]


for i in range((n//2+1),n+1):
  b[i]=a[i]
for i in range(n//2,0,-1):
  j=2
  b[i]=a[i]
  while(j*i<=n):
    b[i]^=b[j*i]
    j+=1

m=0
for i in range(n+1):
  m+=b[i]
print(m)
for i in range(1,n+1):
  if b[i]==1:
    print(i)
Buggy python submission (verdict: Runtime Error):
n,x=map(int,input().split())
d=0
cnt=0
l=list(map(int,input().split()))
while(d<=x):
  cnt+=1
  d+=l[cnt-1]
  if cnt>n+1:
    cnt=n+1
    break
print(cnt)

Fixed submission:
n,x=map(int,input().split())
d=0
cnt=0
l=list(map(int,input().split()))
while(d<=x):
  cnt+=1
  if cnt==n+1:
    break
  d+=l[cnt-1]
print(cnt)

Buggy python submission (verdict: Runtime Error):
n,x=map(int,input().split())
d=0
cnt=0
l=list(map(int,input().split()))
while(d<=x):
  cnt+=1
  d+=l[cnt-1]
print(cnt)

Fixed submission:
n,x=map(int,input().split())
d=0
cnt=0
l=list(map(int,input().split()))
while(d<=x):
  cnt+=1
  if cnt==n+1:
    break
  d+=l[cnt-1]
print(cnt)
Buggy python submission (verdict: Runtime Error):
n,m=map(int,input().split())
a=list(map(int,input().split()))
b=[]
sum=0
res=0
for i in range(m):
  d,e=map(int,input().split())
  b.append([e,d])
a.sort()
b.sort()
b.reverse()
for i in range(1,m):
  b[i][1]+=b[i-1][1]
m=0
if b[0][1]>0 and b[0][0]>a[0]:
  a[0]=b[0][0]
if n>=2:
  for i in range(1,n):
    while i>b[m][1]-1:
      m+=1
    if b[m][0]>a[i]:
      a[i]=b[m][0]
    else:
      break
for i in range(n):
  res+=a[i]
print(res)


Fixed submission:
n,m=map(int,input().split())
a=list(map(int,input().split()))
b=[]
sum=0
res=0
for i in range(m):
  d,e=map(int,input().split())
  b.append([e,d])
a.sort()
b.sort()
b.reverse()

for i in range(1,m):
  b[i][1]+=b[i-1][1]

id=0
if b[0][1]>0 and b[0][0]>a[0]:
  a[0]=b[0][0]
if n>=2:
  for i in range(1,n):
    while i>b[id][1]-1:
      id+=1

      if id>m-1:
        break
    if id>m-1:
      break
    if b[id][0]>a[i]:
      a[i]=b[id][0]
    else:
      break
for i in range(n):
  res+=a[i]
print(res)
Buggy python submission (verdict: Runtime Error):
a=[]
ra=[]
for i in range(5):
  a.append(int(input()))

for i in range(5):
  ra.append(a[i]%10)

rmin=10
mi=10
for i in range(5):
  if ra[i]!=0 and ra[i]<rmin:
    rmin=ra[i]
    mi=i
    
mintime=0
for i in range(5):
  if ra[i]==0:
    mintime+=a[i]
  else:
    mintime+=a[i]+10-ra[i]
mintime-=10-ra[mi]
print(mintime)

Fixed submission:
a=[]
ra=[]
for i in range(5):
  a.append(int(input()))

for i in range(5):
  ra.append(a[i]%10)

tot=0
for i in range(5):
  if ra[i]==0:
    tot+=a[i]

  else:
    tot+=a[i]+10-ra[i]
    

ra.sort()
for i in range(5):
  if ra[i]==0:
    continue
  else:
    tot-=10-ra[i]
    break
print(tot)
Buggy python submission (verdict: Runtime Error):
def gcd(a,b):
  while b!=0:
    a,b=b,a%b
  return a

a,b,k=map(int,input().split())
l=[]
g=gcd(a,b)
q=g
i=1

if a==1 and b==1:
  print(1)
else:
  for i in range(1,int(g/2)+1):
   
    if q%i==0:
      if int(g/i)==i:
        l.append(i)
      else:
        l.append(int(g/i))
        l.append(i)
  l.sort()
  l=set(l)
  l=list(l)
  print(l[(-1)*k])


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

a,b,k=map(int,input().split())
l=[]
g=gcd(a,b)

if a==1 and b==1:
  print(1)
else:
  for i in range(1,g):
    if g%i==0:
      l.append(i)
  l.append(g)
  print(l[(-1)*k])

Buggy python submission (verdict: Runtime Error):
import math

a,b,k=map(int,input().split())
l=[]
g=math.gcd(a,b)
q=g
i=1

if a==1 and b==1:
  print(1)
else:
  for i in range(1,int(g/2)+1):
   
    if q%i==0:
      if int(g/i)==i:
        l.append(i)
      else:
        l.append(int(g/i))
        l.append(i)
  l.sort()
  l=set(l)
  l=list(l)
  print(l[(-1)*k])


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

a,b,k=map(int,input().split())
l=[]
g=gcd(a,b)

if a==1 and b==1:
  print(1)
else:
  for i in range(1,g):
    if g%i==0:
      l.append(i)
  l.append(g)
  print(l[(-1)*k])
Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
a=list(map(int,input().split()))
dp=[[0 for i in range(n+1)] for j in range(n+1)]

for len in range(1,n+1):
  for i in range(n+1):
    if i+len>n:
      break
    j=i+len
    if (n - len) % 2 == 0:
      dp[i][j] = max(dp[i + 1][j] + a[i], dp[i][j - 1] + a[j - 1])
      #print(len,dp)
    else:
      dp[i][j] = min(dp[i + 1][j] - a[i], dp[i][j - 1] - a[j - 1])
      #print(len,dp)
print(dp[0][n])

Fixed submission:
n=int(input())
a=list(map(int,input().split()))
dp=[[0 for i in range(n+1)] for j in range(n+1)]

for len in range(1,n+1):
  for i in range(n+1):
    if i+len>n:
      break
    j=i+len
    if (n - len) % 2 == 0:
      dp[i][j] = max(dp[i + 1][j] + a[i], dp[i][j - 1] + a[j - 1])
      #print(len,dp)
    else:
      dp[i][j] = min(dp[i + 1][j] - a[i], dp[i][j - 1] - a[j - 1])
      #print(len,dp)
print(dp[0][n])
Buggy python submission (verdict: Time Limit Exceeded):
a=input()
n=len(a)
s=[]
for i in range(n):
  s.append(a[i])
flag=1
cnt=0

while(flag==1):
  flag=0
  for i in range(n-1):
    if s[i]=="B" and s[i+1]=="W":
      s[i]="W"
      s[i+1]="B"
      i+=1
      flag=1
      cnt+=1
print(cnt)

Fixed submission:
a=input()
n=len(a)
s=[]
sb=0

for i in range(n):
  s.append(a[i])
b=s.count("B")
w=n-b
fb=int((2*n-b-1)*b/2)

for i in range(n):
  if s[i]=="B":
    sb+=i

print(fb-sb)
Buggy python submission (verdict: Runtime Error):
n=int(input())
t,a=map(int,input().split())

h=[int(input()) for i in range(n)]

min=1000
for i in range(n):
  temp=abs(t-0.006*h[i]-a)
  if min>temp:
    min=temp
    id=i
print(id+1)

Fixed submission:
n=int(input())
t,a=map(int,input().split())

h=list(map(int,input().split()))

min=1000
for i in range(n):
  temp=abs(a-t+0.006*h[i])
  if min>temp:
    min=temp
    id=i
print(id+1)

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

h=[int(input()) for i in range(n)]

min=1000
for i in range(n):
  temp=abs(t-0.006*h[i]-a)
  print(temp)
  if min>temp:
    min=temp
    id=i
print(i+1)

Fixed submission:
n=int(input())
t,a=map(int,input().split())

h=list(map(int,input().split()))

min=1000
for i in range(n):
  temp=abs(a-t+0.006*h[i])
  if min>temp:
    min=temp
    id=i
print(id+1)
Buggy python submission (verdict: Runtime Error):
import math
n,m=map(int,input().split())
s=input()
t=input()
cnt=1
i=0
flag=0

l=int(n*m/math.gcd(n,m))

r=l/m

while cnt<n:
  if s[int(i*l/m)]==t[int(i*l/n)]:
    flag=1
    cnt+=r
    i+=1
  else:
    flag=0
    break

if flag==1:
  print(l)
else:
  print(-1)


Fixed submission:
def gcd(a, b):
  while b:
	  a, b = b, a % b
  return a

n,m=map(int,input().split())
s=input()
t=input()
cnt=1
i=0
flag=0

l=int(n*m/gcd(n,m))

r=l/m

while cnt<n:
  if s[int(i*l/m)]==t[int(i*l/n)]:
    flag=1
    cnt+=r
    i+=1
  else:
    flag=0
    break

if flag==1:
  print(l)
else:
  print(-1)
Buggy python submission (verdict: Time Limit Exceeded):
n,m=map(int,input().split())

if n==1:
  print(m)
else:
  a=int(m**0.5)

  for i in range(int(m/n),0,-1):
    
    if m%i==0 and i*n<=m:
      print(i)
      break

Fixed submission:
n,m=map(int,input().split())

ans=0

if n==1:
  print(m)
else:
  a=int(m**0.5)

  for i in range(1,a):
    if m%i==0:
      if i*n<=m:
        ans=max(ans,i)
      if (m//i)*n<=m:
        ans=max(ans,m//i)
  print(ans)

Buggy python submission (verdict: Runtime Error):
vn,m=map(int,input().split())

if n==1:
  print(m)
else:
  a=int(m**0.5)

  for i in range(a+1,0,-1):
    if m%i==0 and i*n<=m:
      print(i)
      break

Fixed submission:
n,m=map(int,input().split())

ans=0

if n==1:
  print(m)
else:
  a=int(m**0.5)

  for i in range(1,a):
    if m%i==0:
      if i*n<=m:
        ans=max(ans,i)
      if (m//i)*n<=m:
        ans=max(ans,m//i)
  print(ans)
Buggy python submission (verdict: Runtime Error):
import math

n,x=map(int,input().split())
z=[]
y=[]
z=list(map(int, input().split()))

for i in range(n):
  y.append(abs(x-z[i]))

if n==1:
  print(y[0])
else:
  gcm=y[0]
  for i in range(n):
    gcm=math.gcd(gcm,y[i])
  print(gcm)


Fixed submission:
import fractions

n,x=map(int,input().split())
z=[]
y=[]
z=list(map(int, input().split()))

for i in range(n):
  y.append(abs(x-z[i]))

if n==1:
  print(y[0])
else:
  gcm=y[0]
  for i in range(n):
    gcm=fractions.gcd(gcm,y[i])
  print(gcm)

Buggy python submission (verdict: Runtime Error):
import math

n,x=map(int,input().split())
z=[]
y=[]
z=list(map(int, input().split()))

for i in range(n):
  y.append(abs(x-z[i]))

if n==1:
  print(y[0])
else:
  for i in range(n):
    if i<2:
      gcm=math.gcd(y[0],y[1])
    else:
      gcm=math.gcd(gcm,y[i])
  print(gcm)


Fixed submission:
import fractions

n,x=map(int,input().split())
z=[]
y=[]
z=list(map(int, input().split()))

for i in range(n):
  y.append(abs(x-z[i]))

if n==1:
  print(y[0])
else:
  gcm=y[0]
  for i in range(n):
    gcm=fractions.gcd(gcm,y[i])
  print(gcm)

Buggy python submission (verdict: Runtime Error):
import math

n,x=map(int,input().split())
z=[]
y=[]
z=list(map(int, input().split()))

for i in range(n):
  y.append(abs(x-z[i]))

if n==1:
  print(y[0])
else:
  gcm=math.gcd(y[0],y[1])
  for i in range(2,n):
    gcm=math.gcd(gcm,y[i])
  print(gcm)


Fixed submission:
import fractions

n,x=map(int,input().split())
z=[]
y=[]
z=list(map(int, input().split()))

for i in range(n):
  y.append(abs(x-z[i]))

if n==1:
  print(y[0])
else:
  gcm=y[0]
  for i in range(n):
    gcm=fractions.gcd(gcm,y[i])
  print(gcm)

Buggy python submission (verdict: Runtime Error):
import math

n,x=map(int,input().split())
z=[]

y=[]
z=list(map(int, input().split()))
z.append(x)
z.sort()

for i in range(n):
  y.append(z[i+1]-z[i])

if n==1:
  print(y[0])
else:
  gcm=math.gcd(y[0],y[1])
  for i in range(2,n):
    gcm=math.gcd(gcm,y[i])
  print(gcm)


Fixed submission:
import fractions

n,x=map(int,input().split())
z=[]
y=[]
z=list(map(int, input().split()))

for i in range(n):
  y.append(abs(x-z[i]))

if n==1:
  print(y[0])
else:
  gcm=y[0]
  for i in range(n):
    gcm=fractions.gcd(gcm,y[i])
  print(gcm)

Buggy python submission (verdict: Runtime Error):
import functools
import math

n,x=map(int,input().split())
z=[]

y=[]
z=list(map(int, input().split()))
z.append(x)

z.sort()
for i in range(n):
  y.append(z[i+1]-z[i])
  
gcd = functools.reduce(math.gcd, y)
print(gcd)


Fixed submission:
import fractions

n,x=map(int,input().split())
z=[]
y=[]
z=list(map(int, input().split()))

for i in range(n):
  y.append(abs(x-z[i]))

if n==1:
  print(y[0])
else:
  gcm=y[0]
  for i in range(n):
    gcm=fractions.gcd(gcm,y[i])
  print(gcm)
Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
i=0
b=[]
q=n
ans=""

while 1:
  r=q%(-2)
 
  if r==0:
    b.append(0)
    q=int(q/(-2))
  else:
    b.append(1)
    q=int(q/(-2)+0.5)
    if q==0:
      break
  i=i+1

b.reverse()
for j in range(i+1):
  ans=ans+str(b[j])
  
print(ans)


Fixed submission:
n=int(input())
i=0
b=[]
q=n
ans=""

while 1:
  r=q%(-2)
  if q==0:
    b.append(0)
    break
 
  if r==0:
    b.append(0)
    q=int(q/(-2))
  else:
    b.append(1)
    q=int(q/(-2)+0.5)
    if q==0:
      break
  i=i+1

b.reverse()
for j in range(i+1):
  ans=ans+str(b[j])
  
print(ans)
Buggy python submission (verdict: Runtime Error):
s=input()
num=0
for i in s:
  if i=="-":
    num-=1
  else
    num+=1
print(num)

Fixed submission:
s=input()
num=0
for i in s:
  if i=="-":
    num-=1
  else:
    num+=1
print(num)
Buggy python submission (verdict: Time Limit Exceeded):
q=int(input())

#prime table
prime=[0 for i in range(10**5+5)]
for i in range(2,10**5+5):
  j=1
  if not prime[i]:
    while j*i<=10**5+4:
      prime[j*i]=i
      j+=1

for i in range(q):
  l,r=map(int,input().split())
  cnt=0
  for j in range(l,r+1,2):
    if prime[j]==j and prime[(j+1)//2]==(j+1)//2:
      cnt+=1
  print(cnt)



Fixed submission:
q=int(input())

#prime table
prime=[0 for i in range(10**5+5)]
for i in range(2,10**5+5):
  j=1
  if not prime[i]:
    while j*i<=10**5+4:
      prime[j*i]=i
      j+=1

like2017=[0 for i in range(10**5+5)]
for i in range(3,10**5+5,2):
  j=(i+1)//2
  if i==prime[i] and j==prime[j]:
    like2017[i]=1

like2017sum=[0 for i in range(10**5+5)]
for i in range(10**5+4):
  like2017sum[i+1]=like2017sum[i]+like2017[i+1]
#print(like2017[0:54])
#print(like2017sum[0:80])
for i in range(q):
  l,r=map(int,input().split())
  if like2017[l]==1:
    alpha=1
  else:
    alpha=0
  print(like2017sum[r]-like2017sum[l]+alpha)
Buggy python submission (verdict: Time Limit Exceeded):
import heapq
from collections import deque

def bfs(i, c):
    color[i] = c
    cnt[c] += 1
    q = deque()
    q.append(i)
    while q:
        j = q.popleft()
        for k in G[j]:
            if color[k] == -1:
                color[k] = c
                cnt[c] += 1
                q.append(k)
    return

n = int(input())
xy = [list(map(int, input().split())) + [i] for i in range(n)]
xy.sort()
cnt = [0] * n
h = [[n + 1, n + 1]]
G = [[] for _ in range(n)]
for i in range(n):
    c = 0
    while h[0][0] < xy[i][1]:
        p = heapq.heappop(h)
        if c == 0:
            minv = p
        c = 1
        G[p[1]].append(xy[i][2])
        G[xy[i][2]].append(p[1])
    heapq.heappush(h, [xy[i][1], xy[i][2]])
    if c:
        heapq.heappush(h, minv)
color = [-1] * n
c = 0
for i in range(n):
    if color[i] == -1:
        bfs(i, c)
        c += 1
for i in range(n):
    ans = cnt[color[i]]
    print(ans)

Fixed submission:
import heapq
from collections import deque

def bfs(i, c):
    color[i] = c
    cnt[c] += 1
    q = deque()
    q.append(i)
    while q:
        j = q.popleft()
        for k in G[j]:
            if color[k] == -1:
                color[k] = c
                cnt[c] += 1
                q.append(k)
    return

n = int(input())
xy = []
for i in range(n):
    x, y = map(int, input().split())
    xy.append([x, y, i])
xy.sort()
cnt = [0] * n
h = [[n + 1, n + 1]]
G = []
for _ in range(n):
    G.append([])
for i in range(n):
    c = 0
    while h[0][0] < xy[i][1]:
        p = heapq.heappop(h)
        if c == 0:
            minv = p
        c = 1
        G[p[1]].append(xy[i][2])
        G[xy[i][2]].append(p[1])
    heapq.heappush(h, [xy[i][1], xy[i][2]])
    if c:
        heapq.heappush(h, minv)
color = [-1] * n
c = 0
for i in range(n):
    if color[i] == -1:
        bfs(i, c)
        c += 1
for i in range(n):
    ans = cnt[color[i]]
    print(ans)
Buggy python submission (verdict: Runtime Error):
def get_root(s):
    if s != root[s]:
        root[s] = get_root(root[s])
        return root[s]
    return s

def unite(s, t):
    root_s = get_root(s)
    root_t = get_root(t)
    if not root_s == root_t:
        if rank[s] == rank[t]:
            root[root_t] = root_s
            rank[root_s] += 1
        elif rank[s] > rank[t]:
            root[root_t] = root_s
        else:
            root[root_s] = root_t

def same(s, t):
    if get_root(s) == get_root(t):
        return True
    else:
        return False

n, m = map(int, input().split())
root = [i for i in range(n)]
rank = [1 for _ in range(n)]
size = [1 for _ in range(n)]
for _ in range(m):
    a, b = map(int, input().split())
    if not same(a - 1, b - 1):
        unite(a - 1, b - 1)
x = [0] * n
ans = 0
for i in range(n):
    j = get_root(i)
    x[j] += 1
    ans = max(ans, x[j])
print(ans)

Fixed submission:
"""
def get_root(s):
    if s != root[s]:
        root[s] = get_root(root[s])
        return root[s]
    return s

def unite(s, t):
    root_s = get_root(s)
    root_t = get_root(t)
    if not root_s == root_t:
        if rank[s] == rank[t]:
            root[root_t] = root_s
            rank[root_s] += 1
        elif rank[s] > rank[t]:
            root[root_t] = root_s
        else:
            root[root_s] = root_t

def same(s, t):
    if get_root(s) == get_root(t):
        return True
    else:
        return False

n, m = map(int, input().split())
root = [i for i in range(n)]
rank = [1 for _ in range(n)]
size = [1 for _ in range(n)]
for _ in range(m):
    a, b = map(int, input().split())
    if not same(a - 1, b - 1):
        unite(a - 1, b - 1)
x = [0] * n
ans = 0
for i in range(n):
    j = get_root(i)
    x[j] += 1
    ans = max(ans, x[j])
print(ans)
"""

from collections import deque

def bfs(s):
    q = deque()
    q.append(s)
    visit[s] = 1
    cnt = 1
    while q:
        p = q.popleft()
        for j in G[p]:
            if visit[j] == 0:
                q.append(j)
                visit[j] = 1
                cnt += 1
    global ans
    ans = max(ans, cnt)
    return

n, m = map(int, input().split())
G = [[] for _ in range(n + 1)]
for _ in range(m):
    a, b = map(int, input().split())
    G[a].append(b)
    G[b].append(a)
visit = [0] * (n + 1)
ans = 0
for i in range(1, n + 1):
    if visit[i] == 0:
        bfs(i)
print(ans)
Buggy python submission (verdict: Runtime Error):
def binary_search(c1, c2):
    m = (c1 + c2 + 1) // 2
    if abs(c1 - c2) <= 1:
        return m
    else:
        cnt = 0
        for i in a:
            cnt += i // m
        #print(cnt, m)
        if cnt <= k:
            c2 = m
        else:
            c1 = m
        return binary_search(c1, c2)

n, k = map(int, input().split())
a = list(map(int, input().split()))
x = binary_search(-1, 10 ** 9)
for i in range(x + 5, max(x - 5, 0), -1):
    cnt = 0
    for j in a:
        cnt += j // i
    if cnt <= k:
        ans = i
print(ans if not k == 0 else max(a))

Fixed submission:
def binary_search(c1, c2):
    m = (c1 + c2 + 1) // 2
    if abs(c1 - c2) <= 1:
        return m
    else:
        cnt = 0
        for i in a:
            cnt += (i - 1) // m
        #print(cnt, m)
        if cnt <= k:
            c2 = m
        else:
            c1 = m
        return binary_search(c1, c2)

n, k = map(int, input().split())
a = list(map(int, input().split()))
x = binary_search(0, 10 ** 9)
for i in range(x + 5, max(x - 5, 0), -1):
    cnt = 0
    for j in a:
        cnt += (j - 1) // i
    if cnt <= k:
        ans = i
print(ans if not k == 0 else max(a))