Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
l = list(map(int, input().split()))
ans = 0
for i in range(n):
    for j in range(i + 1, n):
        for k in range(j + 1, n):
            if l[i] < l[j] + l[k] and l[j] < l[i] + l[k] and l[k] < l[j] + l[i]:
                ans += 1
print(ans)


Fixed submission:
from bisect import bisect_left
n = int(input())
l = list(map(int, input().split()))
l.sort()
ans = 0
for i in range(n - 2):
    for j in range(i + 1, n - 1):
        ans += bisect_left(l, l[i] + l[j]) - j - 1
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
l = list(map(int, input().split()))
L_num = [0] * (10 ** 3 + 1)
ans = 0
for i in l:
    L_num[i] += 1
for i in range(n):
    for j in range(i + 1, n):
        L_num[l[i]] -= 1
        L_num[l[j]] -= 1
        start = abs(l[i] - l[j]) + 1
        end = l[i] + l[j]
        ans += sum(L_num[start:end])
        L_num[l[i]] += 1
        L_num[l[j]] += 1
print(int(ans / 3))

Fixed submission:
from bisect import bisect_left
n = int(input())
l = list(map(int, input().split()))
l.sort()
ans = 0
for i in range(n - 2):
    for j in range(i + 1, n - 1):
        ans += bisect_left(l, l[i] + l[j]) - j - 1
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
def main():
    n, m = map(int, input().split())
    a = list(map(int, input().split()))
    a = sorted(a)
    for i in range(m):
        a[-1] //= 2
        a.sort()
    print(sum(a))


if __name__ == '__main__':
    main()

Fixed submission:
import heapq


def main():
    n, m = map(int, input().split())
    a = list(map(lambda x: int(x)*(-1), input().split()))
    heapq.heapify(a)
    for i in range(m):
        item = heapq.heappop(a)
        heapq.heappush(a, (-1) * (-item // 2))
    print(-sum(a))


if __name__ == '__main__':
    main()
Buggy python submission (verdict: Runtime Error):
n, l = map(int, input().split())
t = list(map(lambda x: l + x, range(n)))
r = sum(t)
for i in range(n):
    tmp = sum(t[:i] + t[i + 1:])
    dif_t = abs(r - tmp)
    if i == 0:
        dif = dif_t
    if dif_t < dif:
        ans = tmp
        dif = dif_t
print(ans)


Fixed submission:
n, l = map(int, input().split())
t = list(map(lambda x: l + x, range(n)))
r = sum(t)
dif = 10 ** 100
for i in range(n):
    tmp = sum(t[:i] + t[i + 1:])
    dif_t = abs(r - tmp)
    if dif_t < dif:
        ans = tmp
        dif = dif_t
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
mod = 10 ** 9 + 7

n, m = map(int, input().split())
A = [int(input()) for _ in range(m)]
dp = [0] * (n + 1)
dp[0] = 1
for i in range(1, n + 1):
    if i not in A:
        if i == 1:
            dp[i] = dp[i - 1] % mod
        else:
            dp[i] = dp[i - 1] + dp[i - 2] % mod
print(dp[n] % mod)

Fixed submission:
mod = 10 ** 9 + 7

n, m = map(int, input().split())
A = [int(input()) for _ in range(m)]
not_wet = [True] * (n + 1)
for a in A:
    not_wet[a] = False
dp = [0] * (n + 1)
dp[0] = 1
for i in range(1, n + 1):
    if not_wet[i]:
        if i == 1:
            dp[i] = dp[i - 1] % mod
        else:
            dp[i] = dp[i - 1] + dp[i - 2] % mod
print(dp[n] % mod)
Buggy python submission (verdict: Time Limit Exceeded):
import sys


stdin = sys.stdin
def ns(): return stdin.readline().rstrip()
def ni(): return int(stdin.readline().rstrip())
def nm(): return map(int, stdin.readline().split())
def nl(): return list(map(int, stdin.readline().split()))


def main():
    n, q = nm()
    S = input()
    ans = []
    for i in range(q):
        l, r = nm()
        ans += [S[l - 1:r].count('AC')]
    print(*ans, sep='\n')


if __name__ == '__main__':
    main()


Fixed submission:
import sys
from bisect import bisect_left, bisect_right


stdin = sys.stdin
def ns(): return stdin.readline().rstrip()
def ni(): return int(stdin.readline().rstrip())
def nm(): return map(int, stdin.readline().split())
def nl(): return list(map(int, stdin.readline().split()))


def main():
    n, q = nm()
    S = input()
    ans = []
    A_pos = []
    C_pos = []
    for i in range(n - 1):
        if S[i] == 'A' and S[i + 1] == 'C':
            A_pos += [i + 1]
            C_pos += [i + 2]
    for i in range(q):
        l, r = nm()
        ans += [bisect_right(C_pos, r) - bisect_left(A_pos, l)]
    print(*ans, sep='\n')


if __name__ == '__main__':
    main()
Buggy python submission (verdict: Runtime Error):
import sys


stdin = sys.stdin
def ns(): return stdin.readline().rstrip()
def ni(): return int(stdin.readline().rstrip())
def nm(): return map(int, stdin.readline().split())
def nl(): return list(map(int, stdin.readline().split()))


def main():
    n = ni()
    Sn = sum(list(str(n)))
    print('Yes' if n % Sn == 0 else 'No')


if __name__ == '__main__':
    main()


Fixed submission:
import sys


stdin = sys.stdin
def ns(): return stdin.readline().rstrip()
def ni(): return int(stdin.readline().rstrip())
def nm(): return map(int, stdin.readline().split())
def nl(): return list(map(int, stdin.readline().split()))


def main():
    n = ni()
    Sn = sum(list(map(int, list(str(n)))))
    print('Yes' if n % Sn == 0 else 'No')


if __name__ == '__main__':
    main()
Buggy python submission (verdict: Runtime Error):
abc = list(map(int, input().split()))
k = int(input())
mx = abc.pop(max(abc))
print(mx * k + sum(abc))

Fixed submission:
abc = list(map(int, input().split()))
k = int(input())
mx = abc.pop(abc.index(max(abc)))
print(mx * pow(2, k) + sum(abc))
Buggy python submission (verdict: Runtime Error):
a, b, x = map(int, input().split())
print('YES' if a <= x <= a + b)

Fixed submission:
a, b, x = map(int, input().split())
print('YES' if a <= x <= a + b else 'NO')
Buggy python submission (verdict: Time Limit Exceeded):
import sys
import copy


stdin = sys.stdin
def ns(): return stdin.readline().rstrip()
def ni(): return int(stdin.readline().rstrip())
def nm(): return map(int, stdin.readline().split())
def nl(): return list(map(int, stdin.readline().split()))


def main():
    n = ni()
    X = nl()
    X_s = sorted(X)
    for i in range(n):
        X_s_c = copy.copy(X_s)
        X_s_c.remove(X[i])
        print(X_s_c[(n - 1) // 2])


if __name__ == '__main__':
    main()


Fixed submission:
import sys


stdin = sys.stdin
def ns(): return stdin.readline().rstrip()
def ni(): return int(stdin.readline().rstrip())
def nm(): return map(int, stdin.readline().split())
def nl(): return list(map(int, stdin.readline().split()))


def main():
    n = ni()
    X = nl()
    X_s = sorted(X)
    mid = X_s[n // 2]
    del_mid = (X_s[:n // 2] + X_s[n // 2 + 1:])[(n - 1) // 2]
    for x in X:
        if x < mid:
            print(mid)
        elif x > mid:
            print(X_s[n // 2 - 1])
        else:
            print(del_mid)


if __name__ == '__main__':
    main()

Buggy python submission (verdict: Time Limit Exceeded):
import sys


stdin = sys.stdin
def ns(): return stdin.readline().rstrip()
def ni(): return int(stdin.readline().rstrip())
def nm(): return map(int, stdin.readline().split())
def nl(): return list(map(int, stdin.readline().split()))


def main():
    n = ni()
    X = nl()
    for i in range(n):
        print(sorted((X[:i] + X[i + 1:]))[(n - 1) // 2])


if __name__ == '__main__':
    main()


Fixed submission:
import sys


stdin = sys.stdin
def ns(): return stdin.readline().rstrip()
def ni(): return int(stdin.readline().rstrip())
def nm(): return map(int, stdin.readline().split())
def nl(): return list(map(int, stdin.readline().split()))


def main():
    n = ni()
    X = nl()
    X_s = sorted(X)
    mid = X_s[n // 2]
    del_mid = (X_s[:n // 2] + X_s[n // 2 + 1:])[(n - 1) // 2]
    for x in X:
        if x < mid:
            print(mid)
        elif x > mid:
            print(X_s[n // 2 - 1])
        else:
            print(del_mid)


if __name__ == '__main__':
    main()
Buggy python submission (verdict: Time Limit Exceeded):
import sys


stdin = sys.stdin
def ns(): return stdin.readline().rstrip()
def ni(): return int(stdin.readline().rstrip())
def nm(): return map(int, stdin.readline().split())
def nl(): return list(map(int, stdin.readline().split()))


def main():
    n = ni()
    A = nl()
    for i in range(n):
        S = A[:i] + A[i + 1:]
        D = [abs(S[i + 1] - S[i]) for i in range(n - 2)]
        print(sum(D) + abs(S[0]) + abs(S[-1]))


if __name__ == '__main__':
    main()


Fixed submission:
import sys


stdin = sys.stdin
def ns(): return stdin.readline().rstrip()
def ni(): return int(stdin.readline().rstrip())
def nm(): return map(int, stdin.readline().split())
def nl(): return list(map(int, stdin.readline().split()))


def main():
    n = ni()
    A = nl()
    total = sum([abs(A[i + 1] - A[i]) for i in range(n - 1)])
    for i in range(n):
        if i == 0:
            start = abs(A[1])
            end = abs(A[-1])
            print(total - abs(A[1] - A[0]) + start + end)
        elif i == n - 1:
            start = abs(A[0])
            end = abs(A[-2])
            print(total - abs(A[-2] - A[-1]) + start + end)
        else:
            start = abs(A[0])
            end = abs(A[-1])
            print(total - abs(A[i - 1] - A[i]) -
                  abs(A[i] - A[i + 1]) + abs(A[i + 1] - A[i - 1])
                  + start + end)


if __name__ == '__main__':
    main()
Buggy python submission (verdict: Time Limit Exceeded):
k, s = map(int, input().split())
count = 0
for i in range(k + 1):
    for j in range(k + 1):
        for l in range(k + 1):
            x = i
            y = j
            z = l
            if i + j + l == s:
                count += 1
print(count)


Fixed submission:
k, s = map(int, input().split())
ans = 0
for x in range(k + 1):
    for y in range(k + 1):
            if 0 <= s - x - y <=k:
                ans += 1
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
k, s = map(int, input().split())
ans = 0
for x in range(k + 1):
    for y in range(k + 1):
        for z in range(k + 1):
            if x + y + z == s:
                ans += 1
print(ans)

Fixed submission:
k, s = map(int, input().split())
ans = 0
for x in range(k + 1):
    for y in range(k + 1):
            if 0 <= s - x - y <=k:
                ans += 1
print(ans)
Buggy python submission (verdict: Runtime Error):
n,m=map(int,input().split())
l=[set() for _ in range(n+1)]*(n+1)
mn=0
for i in range(m):
  a,b=map(int,input().split())
  l[a].add(b)
  l[b].add(a)

for i in range(n):
  aa=l[i]
  for k in l[i]:
    aa=aa|l[k]
  mn=max(mn,len(aa))
print(mn)
  

Fixed submission:
n,m=map(int,input().split())
l=[set() for _ in range(n+1)]

for i in range(m):
  a,b=map(int,input().split())
  l[a].add(b)
  l[b].add(a)

from collections import deque

vi=[0 for _ in range(n+1)]
st=deque([i,i] for i in range(1,n+1))

while st:
  c,d=st.popleft()

  if vi[c]==0 :
    vi[c]=d
    for m in l[c]:
      st.appendleft([m,d])
from collections import Counter
s=Counter(vi)
mx=0
for m in s.values():
  mx=max(mx,m)
print(mx)
Buggy python submission (verdict: Time Limit Exceeded):
import math
n=int(input())
a=list(map(int,input().split()))
g=a[0]
for m in a:
  g=math.gcd(g,m)
  if g==1:break
else:
  print("not coprime")
  exit()

j=2
l=[0]*2+[1]*(10**6-1)
while j<10*6+1:
  k=1
  if l[j]==1:
    while k*j<10**6:
      l[k*j]==0
      k+=1
  j+=1
d=[]
for i in range(len(l)):
  if l[i]==1: d.append(i)
              
e=set()
for i in range(n):
  z=a[i]
  for m in d:
    if z%m==0:
      if m in e:
        print("setwise coprime")
        exit()
      e.add(m)
print("pairwise coprime")
  
    


Fixed submission:
n=int(input())
a=list(map(int,input().split()))
l=[0]*(10**6+100)
x=0
for m in a:
  l[m]+=1

j=2
#print(l)


while j <10**6+1:
  c=0
  k=1
  while j*k<=10**6+1 :
    if l[j*k]>0:
      c+=l[j*k]
    k+=1

  if c==n:
    print("not coprime")
    exit()
  elif c>1:
    x=1
  j+=1 
  
if x==1:
  print("setwise coprime")
else:
  print("pairwise coprime")

Buggy python submission (verdict: Time Limit Exceeded):
import math
n=int(input())
a=list(map(int,input().split()))
g=a[0]
for m in a:
  g=math.gcd(g,m)
  if g==1:break
else:
  print("not coprime")
  exit()

j=2
l=[0]*2+[1]*(10**6-1)
while j<10*6+1:
  k=1
  if l[j]==1:
    while k*j<10**6:
      l[k*j]==0
      k+=1
  j+=1
d=[]
for i in range(len(l)):
  if l[i]==1: d.append(i)
              
e=set()
for i in range(n):
  z=a[i]
  for m in d:
    if z%m==0:
      if m in e:
        print("setwise coprime")
        exit()
      e.add(m)
print("pairwise coprime")
  
    


Fixed submission:
n=int(input())
a=list(map(int,input().split()))
l=[0]*(10**6+100)
x=0
for m in a:
  l[m]+=1

j=2
#print(l)


while j <10**6+1:
  c=0
  k=1
  while j*k<=10**6+1 :
    if l[j*k]>0:
      c+=l[j*k]
    k+=1

  if c==n:
    print("not coprime")
    exit()
  elif c>1:
    x=1
  j+=1 
  
if x==1:
  print("setwise coprime")
else:
  print("pairwise coprime")

Buggy python submission (verdict: Runtime Error):
n=int(input())
a=list(map(int,input().split()))
l=[0]*(10**6+1)
for m in a:
  l[m]=1
x=0
j=2
#print(l)
for i in range(n):
  c=0
  k=1
  while j*k<=10**6+1 :
    if l[j*k]==1:
      c+=1
      l[j*k]=0
    k+=1
  if c==n:
    print("not coprime")
    exit()
  elif c>1:
    x=1
  j+=1 
if x==1:
  print("setwise coprime")
else:
  print("pairwise coprime")
  
    


Fixed submission:
n=int(input())
a=list(map(int,input().split()))
l=[0]*(10**6+100)
x=0
for m in a:
  l[m]+=1

j=2
#print(l)


while j <10**6+1:
  c=0
  k=1
  while j*k<=10**6+1 :
    if l[j*k]>0:
      c+=l[j*k]
    k+=1

  if c==n:
    print("not coprime")
    exit()
  elif c>1:
    x=1
  j+=1 
  
if x==1:
  print("setwise coprime")
else:
  print("pairwise coprime")
Buggy python submission (verdict: Runtime Error):
h,w,m=map(int,input().split())
lh=[0]*h
lw=[0]*w
l=[[0 for _ in range(w)] for _ in range(h)]
for i in range(m):
  h1,w1=map(int,input().split())
  l[h1-1][w1-1]=1
  lh[h1-1]+=1
  lw[w1-1]+=1
hmax=max(lh)
wmax=max(lw)
lh2=[]
lw2=[]
for i in range(h):
  if lh[i]==hmax:
    lh2.append(i)
for i in range(w):
  if lw[i]==wmax:
    lw2.append(i)
 
s=1
for m in lh2:
  for m2 in lw2:
    if l[m][m2]==0:
      s=0
      
print(hmax+wmax-s)

Fixed submission:
n,x,t=map(int,input().split())
print(((n-1)//x+1)*t)
Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque
h,w=map(int,input().split())
ch,cw=map(int,input().split())
dh,dw=map(int,input().split())
s=[input() for _ in range(h)] #マップ
vi=[ [-1 for _ in range(w)] for _ in range(h)]#visit
st=deque()
st2=deque()
st.append([ch-1,cw-1])
vi[ch-1][cw-1]=1
c=0

d=[[0,1],[-1,0],[1,0],[0,-1]]
d2=[[-2,-2],[-2,-1],[-2,0],[-2,1],[-2,2],
    [-1,-2],[-1,-1],[-1,1],[1,2],[0,-2],[0,2],
    [1,-2],[1,-1],[1,1],[1,2],
    [2,-2],[2,-1],[2,0],[2,1],[2,2]]

while st or st2:
  while st:
    s2=0
    h1,w1=st.popleft()
    if dh-1==h1 and dw-1 ==w1:
      print(c)
      exit()
    for m in d:
      x=w1+m[1]
      y=h1+m[0]
      if 0<=y<h and 0<=x<w:
        if s[y][x]=="." and vi[y][x]==-1:
          st.append([y,x])
        elif s[y][x]=="#":s2=1
        vi[y][x]=1
    if s2==1: st2.append([h1,w1])

  while st2:
    h1,w1=st2.popleft()
    for m in d2:
      x=w1+m[1]
      y=h1+m[0]
      if 0<=y<h and 0<=x<w and vi[y][x]==-1 and s[y][x]==".":
        vi[y][x]=1
        st.append([y,x])
  c+=1
print(-1)

Fixed submission:
from collections import deque
h,w=map(int,input().split())
ch,cw=map(int,input().split())
dh,dw=map(int,input().split())
s=[input() for _ in range(h)] #マップ
vi=[ [-1 for _ in range(w)] for _ in range(h)]#visit
st=deque()
st2=deque()
st.append([ch-1,cw-1])
vi[ch-1][cw-1]=1
c=0

d=[[0,1],[-1,0],[1,0],[0,-1]]
d2=[[-2,-2],[-2,-1],[-2,0],[-2,1],[-2,2],
    [-1,-2],[-1,-1],[-1,1],[1,2],[0,-2],[0,2],
    [1,-2],[1,-1],[1,1],[1,2],
    [2,-2],[2,-1],[2,0],[2,1],[2,2]]

while st or st2:
  while st:
    s2=0
    h1,w1=st.popleft()
    if dh-1==h1 and dw-1 ==w1:
      print(c)
      exit()
    for m in d:
      x=w1+m[1]
      y=h1+m[0]
      if 0<=y<h and 0<=x<w:
        if s[y][x]=="." and vi[y][x]==-1:
          st.append([y,x])
        elif s[y][x]=="#":s2=1
        vi[y][x]=1
    if s2==1: st2.append([h1,w1])

  while st2:
    h1,w1=st2.popleft()
    for m in d2:
      x=w1+m[1]
      y=h1+m[0]
      if 0<=y<h and 0<=x<w and vi[y][x]==-1 and s[y][x]==".":
        vi[y][x]=1
        st.append([y,x])
  c+=1
print(-1)
Buggy python submission (verdict: Runtime Error):
import math
n=int(input())

l=[4 if i%2==0 else 2 for i in range(n+1)]
l[1]=1
l[2]=2
l[4]=3
for i in range(3,int(math.sqrt(n))+1):#振るい
  for j in range(i,n//i+1):
   # print(i,i*j)
    if i==j:
      l[i*j]+=1
    else:
      l[i*j]+=2
#print(l)

l2=[i*l[i] for i in range(n+1)]
print(sum(l2))


Fixed submission:
import math
n=int(input())

l=[4 if i%2==0 else 2 for i in range(max(5,n+1))]
l[1]=1
l[2]=2
l[4]=3
for i in range(3,int(math.sqrt(n))+1):#振るい
  for j in range(i,n//i+1):
   # print(i,i*j)
    if i==j:
      l[i*j]+=1
    else:
      l[i*j]+=2
#print(l)

l2=[i*l[i] for i in range(n+1)]
print(sum(l2))

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

l=[4 if i%2==0 else 2 for i in range(n+1)]
l[1]=1
l[2]=2
l[4]=3
for i in range(3,int(math.sqrt(n))+1):
  for j in range(i,n//i+1):
   # print(i,i*j)
    if i==j:
      l[i*j]+=1
    else:
      l[i*j]+=2
#print(l)

l2=[i*l[i] for i in range(n+1)]
print(sum(l2))


Fixed submission:
import math
n=int(input())

l=[4 if i%2==0 else 2 for i in range(max(5,n+1))]
l[1]=1
l[2]=2
l[4]=3
for i in range(3,int(math.sqrt(n))+1):#振るい
  for j in range(i,n//i+1):
   # print(i,i*j)
    if i==j:
      l[i*j]+=1
    else:
      l[i*j]+=2
#print(l)

l2=[i*l[i] for i in range(n+1)]
print(sum(l2))
Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
b=list(map(int,input().split()))
an=1
c=0
for m in b:
  an*=m
if(an>10**18):
  print("-1")
else:
  print(an)
  

Fixed submission:
n=int(input())
b=list(map(int,input().split()))
b.sort()
an=1
c=0

for m in b:
  an*=m
  if(an>10**18):
    print("-1")
    c=1
    break
if(c!=1):
  print(an)
Buggy python submission (verdict: Runtime Error):
a=int(input())
b=int(float(input())*100)
print(int(a*b)/100)

Fixed submission:
a,b=input().split()
b1=b[:-3]
b2=b[-2:]
print(int(a)*(int(b1)*100+int(b2))//100)
Buggy python submission (verdict: Time Limit Exceeded):
n,m=map(int,input().split())
l=[[0] for _ in range(n+1)]
vi=[-1 for _ in range(n+1)]
vi[0]=1
for i in range (m):
  a,b=map(int,input().split())
  l[a].append(b)
  l[b].append(a)
st=[[1,0]]

while st:
  x,i=st.pop(0)
  if vi[x]==-1:
    vi[x]=i
    for k in l[x]:
      if vi[k]==-1:
        st.append([k,x])


print("Yes")
for m in vi[2:]:
  print(m)
  
  

Fixed submission:
from collections import deque
n,m=map(int,input().split())
l=[[0] for _ in range(n+1)]
vi=[0 for _ in range(n+1)]
vi[1]=-1

for i in range (m):
  a,b=map(int,input().split())
  l[a].append(b)
  l[b].append(a)
st=deque([1])
e=set()
f=set()


while st:
    x=st.popleft()
    if x not in e:
      e.add(x)
      for k in l[x]:
        if k not in f:
          st.append(k)
          f.add(k)
          vi[k]=x   
  
print("Yes")
for m in vi[2:]:
  print(m)

Buggy python submission (verdict: Time Limit Exceeded):
n,m=map(int,input().split())
l=[[0] for _ in range(n+1)]
vi=[-1 for _ in range(n+1)]
vi[0]=1
for i in range (m):
  a,b=map(int,input().split())
  l[a].append(b)
  l[b].append(a)
st=[[1,0]]

def bfs(x,i):
  if vi[x]==-1:
    vi[x]=i
    for k in l[x]:
      if vi[k]==-1:
        st.append([k,x])
  return

while st:
  x,i=st.pop(0)
  bfs(x,i)

print("Yes")
for m in vi[2:]:
  print(m)
  
  

Fixed submission:
from collections import deque
n,m=map(int,input().split())
l=[[0] for _ in range(n+1)]
vi=[0 for _ in range(n+1)]
vi[1]=-1

for i in range (m):
  a,b=map(int,input().split())
  l[a].append(b)
  l[b].append(a)
st=deque([1])
e=set()
f=set()


while st:
    x=st.popleft()
    if x not in e:
      e.add(x)
      for k in l[x]:
        if k not in f:
          st.append(k)
          f.add(k)
          vi[k]=x   
  
print("Yes")
for m in vi[2:]:
  print(m)

Buggy python submission (verdict: Time Limit Exceeded):
n,m=map(int,input().split())
l=[[0] for _ in range(n+1)]
vi=[-1 for _ in range(n+1)]
vi[0]=1
for i in range (m):
  a,b=map(int,input().split())
  l[a].append(b)
  l[b].append(a)
st=[[1,0]]

def bfs(x,i):
  if vi[x]==-1:
    vi[x]=i
    for k in l[x]:
      if vi[k]==-1:
        st.append([k,x])
  return

while st:
  x,i=st.pop(0)
  bfs(x,i)

print("Yes")
for m in vi[2:]:
  print(m)
  
  

Fixed submission:
from collections import deque
n,m=map(int,input().split())
l=[[0] for _ in range(n+1)]
vi=[0 for _ in range(n+1)]
vi[1]=-1

for i in range (m):
  a,b=map(int,input().split())
  l[a].append(b)
  l[b].append(a)
st=deque([1])
e=set()
f=set()


while st:
    x=st.popleft()
    if x not in e:
      e.add(x)
      for k in l[x]:
        if k not in f:
          st.append(k)
          f.add(k)
          vi[k]=x   
  
print("Yes")
for m in vi[2:]:
  print(m)
Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
s=input()
r=[[0,0,0] for _ in range(n)]
c=0
l={"GB":0,"BG":0,"RB":1,"BR":1,"RG":2,"GR":2}
for i in range(n):
  if s[i] =="R":
    r[i][0]=r[i-1][0]+1
    r[i][1]=r[i-1][1]
    r[i][2]=r[i-1][2]
  elif s[i]=="G":
    r[i][1]=r[i-1][1]+1
    r[i][0]=r[i-1][0]
    r[i][2]=r[i-1][2]
  elif s[i]=="B":
    r[i][2]=r[i-1][2]+1
    r[i][0]=r[i-1][0]
    r[i][1]=r[i-1][1]

for i in range(n-2):
  for j in range(i+1,n-1):
    if s[i]==s[j]:
      continue
    else:
      c+=r[n-1][l[s[i]+s[j]]]-r[j][l[s[i]+s[j]]]
    
      
      if 2*j-i<n:
        if s[2*j-i]!= s[i] and s[2*j-i]!=s[j]:
          c-=1
   
  
print(c)
      

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

r=[[0,0,0] for _ in range(n)]
c=0
l={"GB":0,"BG":0,"RB":1,"BR":1,"RG":2,"GR":2}
for i in range(n):
  if s[i] =="R":
    r[i][0]=r[i-1][0]+1
    r[i][1]=r[i-1][1]
    r[i][2]=r[i-1][2]
  elif s[i]=="G":
    r[i][1]=r[i-1][1]+1
    r[i][0]=r[i-1][0]
    r[i][2]=r[i-1][2]
  elif s[i]=="B":
    r[i][2]=r[i-1][2]+1
    r[i][0]=r[i-1][0]
    r[i][1]=r[i-1][1]

for i in range(n-2):
  for j in range(i+1,n-1):
    if s[i]==s[j]:
      continue
    else:
      c+=r[n-1][l[s[i]+s[j]]]-r[j][l[s[i]+s[j]]]
     # print("p",i,j,c)
      
      if 2*j-i<n:
        if s[2*j-i]!= s[i] and s[2*j-i]!=s[j]:
          c-=1
      #   print("m",i,j,c)
  
print(c)
Buggy python submission (verdict: Runtime Error):
s=input()
if s[3]==s[4] and s[5]==s[6]:
  print("Yes")
else:
  print("No")

Fixed submission:
s=input()
if s[2]==s[3] and s[4]==s[5]:
  print("Yes")
else:
  print("No")
Buggy python submission (verdict: Runtime Error):
n,m=map(int,input())
print(n*(n-1)//2+m*(m-1)//2)

Fixed submission:
n,m=map(int,input().split())
print(n*(n-1)//2+m*(m-1)//2)
Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
from collections import defaultdict
import math
a=list(map(int,input().split()))
d=defaultdict(int)
for m in a:
  d[m]+=1
sm=0
for m in d:
  if d[m]>1:
    sm+=math.factorial(d[m])//math.factorial(d[m]-2)//2
for m in a:
  if d[m]>2:
    print(sm-math.factorial(d[m])//math.factorial(d[m]-2)//2+math.factorial(d[m]-1)//math.factorial(d[m]-3)//2)
  elif d[m]==2:
    print(sm-1)
  else:
    print(sm)

  



Fixed submission:
n=int(input())
from collections import defaultdict
import math
a=list(map(int,input().split()))
d=defaultdict(int)
for m in a:
  d[m]+=1
sm=0
for m in d:
  if d[m]>1:
    sm+=d[m]*(d[m]-1)//2
for m in a:
  if d[m]>2:
    print(sm-d[m]+1)
  elif d[m]==2:
    print(sm-1)
  else:
    print(sm)

Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
from collections import defaultdict
import math
a=list(map(int,input().split()))
d=defaultdict(int)
for m in a:
  d[m]+=1
sm=0
for m in d:
  if d[m]>1:
    sm+=math.factorial(d[m])//math.factorial(d[m]-2)//2
for m in a:
  if d[m]>2:
    print(sm-math.factorial(d[m])//math.factorial(d[m]-2)//2+math.factorial(d[m]-1)//math.factorial(d[m]-3)//2)
  elif d[m]==2:
    print(sm-1)
  else:
    print(sm)

  



Fixed submission:
n=int(input())
from collections import defaultdict
import math
a=list(map(int,input().split()))
d=defaultdict(int)
for m in a:
  d[m]+=1
sm=0
for m in d:
  if d[m]>1:
    sm+=d[m]*(d[m]-1)//2
for m in a:
  if d[m]>2:
    print(sm-d[m]+1)
  elif d[m]==2:
    print(sm-1)
  else:
    print(sm)
Buggy python submission (verdict: Runtime Error):
s=input()
print("No" if s=="AAA" or s="BBB" else "Yes")

Fixed submission:
s=input()
print("No" if s=="AAA" or s=="BBB" else "Yes")