Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
N = int(input())
S = input()
S = list(S)


indices_black = list()
for i, c in enumerate(S):
    if c == '#':
        indices_black.append(i)

count_white = dict()
count = 0
for i, c in enumerate(S[::-1]):
    if c == '.':
        count += 1
    count_white[N - i - 1] = count


def get_answer(S):
    # most left
    if len(indices_black) == 0:
        return 0

    idx = indices_black.pop(0)
    if count_white[idx] == 0:
        return 0
    # count white: turn all white -> black
    ans_w = count_white[idx]

    # turn most left black -> white
    S[idx] = '.'
    ans_b = get_answer(S) + 1
    return min(ans_w, ans_b)


print(get_answer(S))

Fixed submission:
import sys
sys.setrecursionlimit(200000)


N = int(input())
S = input()
S = list(S)


indices_black = list()
for i, c in enumerate(S):
    if c == '#':
        indices_black.append(i)

count_white = dict()
count = 0
for i, c in enumerate(S[::-1]):
    if c == '.':
        count += 1
    count_white[N - i - 1] = count


def get_answer(S):
    # most left
    if len(indices_black) == 0:
        return 0

    idx = indices_black.pop(0)
    if count_white[idx] == 0:
        return 0
    # count white: turn all white -> black
    ans_w = count_white[idx]

    # turn most left black -> white
    S[idx] = '.'
    ans_b = get_answer(S) + 1
    return min(ans_w, ans_b)


print(get_answer(S))
Buggy python submission (verdict: Runtime Error):
N = int(input())
b = list(map(int, input().split()))


def naive():
    # (1), (1,2), ..., (1,...,N)
    import itertools
    candidates = itertools.product(*[range(1, i + 1) for i in range(1, N+1)])
    for candidate in candidates:
        a = list()
        for j in candidate:
            a.insert(j-1, j)

        if a == b:
            return candidate
    
    return -1


def fast():
    candidate = list()
    
    while len(b) != 0:
        for i in range(len(b))[::-1]:
            if b[i] == (i+1):
                value = b.pop(i)
                candidate.append(value)
                break
            
        else:
            return -1

    candidate.reverse()
    return candidate
 
# print(naive())
# print(fast())
ans_list = fast()
for ans in ans_list:
    print(ans)


Fixed submission:
N = int(input())
b = list(map(int, input().split()))


def fast():
    candidate = list()
    
    while len(b) != 0:
        for i in range(len(b))[::-1]:
            if b[i] == (i+1):
                value = b.pop(i)
                candidate.append(value)
                break
            
        else:
            return [-1]

    candidate.reverse()
    return candidate

ans_list = fast()
for ans in ans_list:
    print(ans)
Buggy python submission (verdict: Runtime Error):
import numpy as np


N, M = map(int, input().split())
A, B = list(), list()
for i in range(N):
    a, b = map(int, input().split())
    A.append(a)
    B.append(b)
A = np.array(A)
B = np.array(B)

n_bins = 0
cost = 0
indices = np.argsort(A)
for idx in indices:
    print(idx, B[idx], A[idx] * B[idx])
    # enough bins @idx
    if n_bins + B[idx] > M:
        cost += A[idx] * (M - n_bins)
        break
    # buy all bins
    else:
        n_bins += B[idx]
        cost += A[idx] * B[idx]
print(cost)

Fixed submission:
import numpy as np


H, W = map(int, input().split())
h, w = map(int, input().split())
board = np.ones((H, W), dtype=int)
board[0:h] = 0
board[:, 0:w] = 0
print(board.sum())
Buggy python submission (verdict: Runtime Error):
import numpy as np


N, M, C = map(int, input().split())
B = np.fromiter(map(int, input().split()), dtype=int)
As = list()
for i in range(N):
    a = np.fromiter(map(int, input().split()), dtype=int)
    As.append(a)
As = np.vstack(As)
print(int(np.sum(As @ B + C > 0)))



Fixed submission:
import numpy as np


N, M, C = map(int, input().split())
B = np.fromiter(map(int, input().split()), dtype=int)
As = list()
for i in range(N):
    a = np.fromiter(map(int, input().split()), dtype=int)
    As.append(a)
As = np.vstack(As)
print(int(np.sum(As.dot(B) + C > 0)))

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


N, M, C = map(int, input().split())
B = np.fromiter(map(int, input().split()), dtype=int)
As = list()
for i in range(N):
    a = np.fromiter(map(int, input().split()), dtype=int)
    As.append(a)
As = np.vstack(As)
print(np.sum(As @ B + C > 0))



Fixed submission:
import numpy as np


N, M, C = map(int, input().split())
B = np.fromiter(map(int, input().split()), dtype=int)
As = list()
for i in range(N):
    a = np.fromiter(map(int, input().split()), dtype=int)
    As.append(a)
As = np.vstack(As)
print(int(np.sum(As.dot(B) + C > 0)))
Buggy python submission (verdict: Runtime Error):
import collections
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))

A1 = collections.Counter(A)
B1 = collections.Counter(B)
A2 = A1.most_common()
B2 = B1.most_common()

for i in range(len(B2)):
  if A2[i][1] + B2[i][1] > N:
    print("No")
    quit()


B.reverse()    
s = 0
t = N - 1
for i in range(N):
  if A[i] == B[i]:
    if (A[s] != B[i]) and (A[i] != B[s]):
      x = B[s]
      B[s] = B[i]
      B[i] = x
      s += 1
    elif (A[t] != B[i]) and (A[i] != B[t]) :
      x = B[t]
      B[t] = B[i]
      B[i] = x
      t -= 1
    else:
      print("No")
      quit()
  
#print(B)  
print("Yes")  
for i in range(N):
  print(B[i], end = " ")
print("")

  
    


Fixed submission:
import collections
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))

A1 = collections.Counter(A)
B1 = collections.Counter(B)
A2 = A1.most_common()
B2 = B1.most_common()

if A2[0][0] == B2[0][0]:
  if min(A2[0][1], B2[0][1]) > int(N / 2):
    print("No")
    quit()

B.reverse()    
s = 0
t = N - 1
for i in range(N):
  if A[i] == B[i]:
    if (A[s] != B[i]) and (A[i] != B[s]):
      x = B[s]
      B[s] = B[i]
      B[i] = x
      s += 1
    elif (A[t] != B[i]) and (A[i] != B[t]) :
      x = B[t]
      B[t] = B[i]
      B[i] = x
      t -= 1
    else:
      print("No")
      quit()
  
#print(B)  
print("Yes")  
for i in range(N):
  print(B[i], end = " ")
print("")
Buggy python submission (verdict: Time Limit Exceeded):
N, K = map(int, input().split())
P = list(map(int, input().split()))
C = list(map(int, input().split()))

#if max(C) < 0:
#  print(min(C))
#  quit()
  
A = [0] * N

for i in range(N):#スタート地点
  q = [i + 1]
  now = i + 1
  score = []
  point = 0
  T = True
  while T:
    now = P[now - 1]
    point += C[now - 1]
    score.append(point)
    if now in q:
      T = False
    else:
      q.append(now)
  #print(q)#ループのルート
  #print(score)#ループ中のスコア
  if len(q) >= K:#一周未満
    score = score[:K]
    A[i] = max(score)
  else:#一周以上
    if score[-1] <= 0:#周回しない方がいいケース
      A[i] = max(score)
    else:#周回すべきケース
      ll = -float("inf")
      for j in range(len(q)):
        roop = int((K - (j + 1)) / len(q))
        ll = max(ll, roop * score[-1] + score[j])
        #print(i, ll, roop * score[-1] + score[j])
      A[i] = ll
      
      
#print(A)      
print(max(A))      
      
      
    
    
    


Fixed submission:
N, K = map(int, input().split())
P = list(map(int, input().split()))
C = list(map(int, input().split()))
  
already = [0] * N
A = [-float("inf")] * N

for i in range(N):#スタート地点
  if already[i] == 0:
    already[i] = 1
    q = [i + 1]
    now = i + 1
    score = []
    T = True
    while T:
      now = P[now - 1]
      score.append(C[now - 1])
      if now in q:
        T = False
      else:
        q.append(now)
        already[now - 1] = 1
    
    #A.append(q)
    #S.append(score)
    #print(q)#ループのルート
    #print(score)#ループ中のスコア
    roop = sum(score)
    if len(q) >= K:
      aa = -float("inf")
      for j in range(len(q)):
        time = 0
        bb = 0
        p = j
        while time != K:
          time += 1
          bb += score[p]
          aa = max(aa, bb)
          p += 1
          if p == len(q):
            p = 0
      A[i] = aa      
    else:  
      if roop <= 0:
        aa = -float("inf")
        for j in range(len(q)):
          time = 0
          bb = 0
          p = j
          while time != len(q):
            time += 1
            bb += score[p]
            aa = max(aa, bb)
            p += 1
            if p == len(q):
              p = 0
        A[i] = aa            
      else:
        ll = int(K / len(q)) 
        rr = K % len(q)
        aa = -float("inf")
        for j in range(len(q)):
          time = 0
          bb = ll * roop
          p = j
          while time != len(q):
            time += 1
            bb += score[p]
            if time == rr + 1:
              bb -= roop
            aa = max(aa, bb)
            p += 1
            if p == len(q):
              p = 0
        A[i] = aa           
        

#print(A)      
print(max(A))
Buggy python submission (verdict: Time Limit Exceeded):
import math
N, K = map(int, input().split())
A = list(map(int, input().split()))

#めぐる式二分探索
#indexが条件を満たすか判定
def isOK(mid, A):
  count = 0
  for i in range(N):
    if A[i] > mid:
      xx = A[i] / mid
      if xx % 1 != 0:
        xx += 1
      count += int(xx - 1)
      
  #print("c", count)
  if count > K:
    return False
  else:
    return True
  
#にぶたん
#A : 配列
def binary_search(A):
  N = 10 ** 9
  ng = -1
  ok = N
  while (abs(ok - ng) > 1):
    mid = int((ok + ng) / 2)
    if mid == 0:
      mid = 1
    #print(ng, ok, mid)
    if isOK(mid, A):
      ok = mid
    else:
      ng = mid
  return ok
  
#a = [1, 14, 32, 51, 51, 51, 243, 419, 750, 910]

print(binary_search(A))
  



Fixed submission:
import math
N, K = map(int, input().split())
A = list(map(int, input().split()))

#めぐる式二分探索
#indexが条件を満たすか判定
def isOK(mid, A):
  count = 0
  for i in range(N):
    if A[i] > mid:
      xx = A[i] / mid
      if xx % 1 != 0:
        xx += 1
      count += int(xx - 1)
      
  #print("c", count)
  if count > K:
    return False
  else:
    return True
  
#にぶたん
#A : 配列
def binary_search(A):
  N = 10 ** 9
  ng = -1
  ok = N
  while (abs(ok - ng) > 1):
    mid = int((ok + ng) / 2)
    if mid == 0:
      return 1
    #print(ng, ok, mid)
    if isOK(mid, A):
      ok = mid
    else:
      ng = mid
  return ok
  
#a = [1, 14, 32, 51, 51, 51, 243, 419, 750, 910]

print(binary_search(A))

Buggy python submission (verdict: Runtime Error):
import math
N, K = map(int, input().split())
A = list(map(int, input().split()))

#めぐる式二分探索
#indexが条件を満たすか判定
def isOK(mid, A):
  count = 0
  for i in range(N):
    if A[i] > mid:
      xx = A[i] / mid
      if xx % 1 != 0:
        xx += 1
      count += int(xx - 1)
      
  #print("c", count)
  if count > K:
    return False
  else:
    return True
  
#にぶたん
#A : 配列
def binary_search(A):
  N = 10 ** 9
  ng = -1
  ok = N
  while (abs(ok - ng) > 1):
    mid = int((ok + ng) / 2)
    #print(ng, ok, mid)
    if isOK(mid, A):
      ok = mid
    else:
      ng = mid
  return ok
  
#a = [1, 14, 32, 51, 51, 51, 243, 419, 750, 910]

print(binary_search(A))
  



Fixed submission:
import math
N, K = map(int, input().split())
A = list(map(int, input().split()))

#めぐる式二分探索
#indexが条件を満たすか判定
def isOK(mid, A):
  count = 0
  for i in range(N):
    if A[i] > mid:
      xx = A[i] / mid
      if xx % 1 != 0:
        xx += 1
      count += int(xx - 1)
      
  #print("c", count)
  if count > K:
    return False
  else:
    return True
  
#にぶたん
#A : 配列
def binary_search(A):
  N = 10 ** 9
  ng = -1
  ok = N
  while (abs(ok - ng) > 1):
    mid = int((ok + ng) / 2)
    if mid == 0:
      return 1
    #print(ng, ok, mid)
    if isOK(mid, A):
      ok = mid
    else:
      ng = mid
  return ok
  
#a = [1, 14, 32, 51, 51, 51, 243, 419, 750, 910]

print(binary_search(A))
Buggy python submission (verdict: Time Limit Exceeded):
#X = int(input())
#S = str(input())
N, K= map(int, input().split())
A = list(map(int, input().split()))

start = 1
for i in range(K):
  start *= A[i]
  
now = start    
for i in range(N - K):
  now *= A[K + i]
  now /= A[i]
  #print(start, now)
  if now > start:
    print("Yes")
  else:
    print("No")
  start = now
  
  

Fixed submission:
#X = int(input())
#S = str(input())
N, K= map(int, input().split())
A = list(map(int, input().split()))
  
for i in range(N - K):
  #print(start, now)
  if A[K + i] > A[i]:
    print("Yes")
  else:
    print("No")
Buggy python submission (verdict: Runtime Error):
#解説方針
#標準入力
n, m = map(int, input().split())
#逆元
def cmb(n, r, p):
    if (r < 0) or (n < r):
        return 0
    r = min(r, n - r)
    return fact[n] * factinv[r] * factinv[n-r] % p

def pmt(n, r, p):
    if (r < 0) or (n < r):
        return 0
    #r = min(r, n - r)
    return fact[n] * factinv[n - r] % p
  
p = 10 ** 9 + 7
N = n + 1
fact = [1, 1]  # fact[n] = (n! mod p)
factinv = [1, 1]  # factinv[n] = ((n!)^(-1) mod p)
inv = [0, 1]  # factinv 計算用
 
for i in range(2, N + 1):
    fact.append((fact[-1] * i) % p)
    inv.append((-inv[p % i] * (p // i)) % p)
    factinv.append((factinv[-1] * inv[-1]) % p)

#print(pmt(3, 2, p))
#(-1)**K * (NCK) * (MPK) * (M-KPN-K)**2をKについて足し合わせる
ans = 0
for i in range(n + 1):
  a = (-1) ** i
  b = cmb(n, i, p)
  c = pmt(m, i, p)
  d = pmt(m - i, n - i, p)
  #print(a, b, c, d)
  ans += a * b * c * (d ** 2)
  
print(ans)

  
  
  




Fixed submission:
#解説方針
#標準入力
n, m = map(int, input().split())
#逆元
def cmb(n, r, p):
    if (r < 0) or (n < r):
        return 0
    r = min(r, n - r)
    return fact[n] * factinv[r] * factinv[n-r] % p

def pmt(n, r, p):
    if (r < 0) or (n < r):
        return 0
    #r = min(r, n - r)
    return fact[n] * factinv[n - r] % p
  
p = 10 ** 9 + 7
N = m + 1
fact = [1, 1]  # fact[n] = (n! mod p)
factinv = [1, 1]  # factinv[n] = ((n!)^(-1) mod p)
inv = [0, 1]  # factinv 計算用
 
for i in range(2, N + 1):
    fact.append((fact[-1] * i) % p)
    inv.append((-inv[p % i] * (p // i)) % p)
    factinv.append((factinv[-1] * inv[-1]) % p)

#print(pmt(3, 2, p))
#(-1)**K * (NCK) * (MPK) * (M-KPN-K)**2をKについて足し合わせる
ans = 0
for i in range(n + 1):
  a = (-1) ** i
  b = cmb(n, i, p)
  c = pmt(m, i, p)
  d = pmt(m - i, n - i, p)
  #print(a, b, c, d)
  ans += (a * b * c * (d ** 2)) % p
  
print(ans % p)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = list(map(int, input().split()))
if A[0] == 1:
  print("-1")
  quit()

if N == 2:
  if A[0] < A[1]:
    print("-1")
    quit()
  elif (A[0] + A[1]) % 2 == 1:
    print("-1")
    quit()
  else:
    half = (A[0] + A[1]) // 2
    print(int(A[0] - half))
    quit()

now = 0
for i in range(N):
  now = now ^ A[i]

if now == 0:
  print("-1")
else:
  a = A[0] ^ A[1]
  b = a ^ now
  T = True
  i = 0
  while T:
    now2 = (A[0] - i) ^ (A[1] + i)
    #print(now2, A[0] - i, A[1] + i, b)
    if not (now2 ^ b):
      print(i)
      quit()
    
    i += 1
    if (A[0] - i) < 0:
      T = False
      print("-1")
    
    
 

Fixed submission:
#解説方針
import math
N = int(input())
A = list(map(int, input().split()))

all_xor = 0
for i in range(N):
  all_xor = all_xor ^ A[i]

fore = A[0] ^ A[1]#S
back = fore ^ all_xor #X
#a + b = (a xor b) + 2 * (a and b)
#a xor b = back, a + b = A[0] + A[1]

a_and_b = (A[0] + A[1] - back) / 2
#print(a_and_b, back)
#a_and_bは非負整数である必要がある
if (a_and_b % 1 != 0) or (a_and_b < 0):
  print(-1)
  quit()
a_and_b = int(a_and_b)

#print(a_and_b, back, a_and_b & back)
#a_and_bとbackには共通のbitがない
if (a_and_b & back) != 0:
  print(-1)
  quit()

ans = a_and_b
#print(math.log2(32))
if back == 0:
  if (ans == 0):
    print(-1)
  else:
    print(A[0] - ans)
  quit()
else:
  if ans > A[0]:
    print(-1)
    quit()
  nn = int(math.log2(back)) + 1
  #print(nn)
  #print(2 >> 1)
  #print(2 << 1)
  for i in range(nn + 1):
    #print(back, nn - i)
    if ((back >> (nn - i)) & 1):
      #print(ans, 2 << (nn - i))
      k = ans + (1 << (nn - i))
      #print("k", k, i)
      if k <= A[0]:
        ans = k 
  if (ans == 0):
    print(-1)
  else:
    print(A[0] - ans)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = list(map(int, input().split()))
A = sorted(A)
B = []
for i in range(N):
  if A.count(A[i]) != 1:
    continue
  else:
    p = 0
    for j in B:
      if A[i] % j == 0:
        p = 1
    if p == 0:
      B.append(A[i])
      
print(len(B))

Fixed submission:
N = int(input())
As = list(map(int,(input().split())))

As.sort()
# print(As)

all_nums = [0] * (As[-1] + 1)

for A in As:
    all_nums[A] += 1
#print(all_nums)
dup = 0

for i, num in enumerate(all_nums):
    if num == 0: #その数が一つもないなら無視
        continue
    if num > 1: #同じ数が複数ある場合はあとで除くためにカウント
        dup += num
    j = 2
    while i * j <= As[-1]:
        all_nums[i*j] = 0
        j += 1
    #print(all_nums)

print(sum(all_nums)-dup)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = list(map(int, input().split()))
A = sorted(A)
B = []
for i in range(N):
  if A.count(A[i]) != 1:
    continue
  else:
    p = 0
    for j in B:
      if A[i] % j == 0:
        p = 1
    if p == 0:
      B.append(A[i])
      
print(len(B))

Fixed submission:
N = int(input())
As = list(map(int,(input().split())))

As.sort()
# print(As)

all_nums = [0] * (As[-1] + 1)

for A in As:
    all_nums[A] += 1
#print(all_nums)
dup = 0

for i, num in enumerate(all_nums):
    if num == 0: #その数が一つもないなら無視
        continue
    if num > 1: #同じ数が複数ある場合はあとで除くためにカウント
        dup += num
    j = 2
    while i * j <= As[-1]:
        all_nums[i*j] = 0
        j += 1
    #print(all_nums)

print(sum(all_nums)-dup)
Buggy python submission (verdict: Time Limit Exceeded):
import math
N, K = map(int, input().split())
A = list(map(int, input().split()))

def lamp(A):
  B = [0] * N
  for i in range(N):
    l = max(0, i - A[i])
    r = min(N - 1, i + A[i])
    #print(l, r)
    B[l] += 1
    if r + 1 < N:
      B[r + 1] -= 1
  
  A[0] = B[0]
  for i in range(1, N):
    A[i] = A[i - 1] + B[i]
  return A

x = int(math.log(N, 2)) + 10
r = min(x, K)
for i in range(r):
  A = lamp(A)
  
for i in range(N):
  print(A[i], end = " ")
print("")


Fixed submission:
import math
N, K = map(int, input().split())
A = list(map(int, input().split()))

def lamp(A):
  B = [0] * N
  for i in range(N):
    l = max(0, i - A[i])
    r = min(N - 1, i + A[i])
    #print(l, r)
    B[l] += 1
    if r + 1 < N:
      B[r + 1] -= 1
  
  A[0] = B[0]
  for i in range(1, N):
    A[i] = A[i - 1] + B[i]
  return A

r = min(41, K)
for i in range(r):
  A = lamp(A)
  
for i in range(N):
  print(A[i], end = " ")
print("")
Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np
N, S = map(int, input().split())
A = list(map(int, input().split()))
MOD = 998244353

DP = np.zeros((N+1, S+1), dtype=np.int64)#[[0]*(S+1) for _ in range(N+1)]
DP[0][0] = 1
for i in range(N):
  for j in range(S + 1):
    if j >= A[i]:
      DP[i + 1][j] = (DP[i][j] * 2 + DP[i][j - A[i]]) % MOD
    else:
      DP[i + 1][j] = (DP[i][j] * 2) % MOD
print(DP[-1][-1] % MOD)






Fixed submission:
N, S = map(int, input().split())
A = list(map(int, input().split()))
MOD = 998244353

DP = [[0] * (S + 1) for i in range(N + 1)]
DP[0][0] = 1
for i in range(N):
  for j in range(S + 1):
    if j >= A[i]:
      DP[i + 1][j] = (DP[i][j] * 2 + DP[i][j - A[i]]) % MOD
    else:
      DP[i + 1][j] = (DP[i][j] * 2) % MOD

print(DP[-1][-1] % MOD)

Buggy python submission (verdict: Time Limit Exceeded):
N, S = map(int, input().split())
A = list(map(int, input().split()))
MOD = 998244353

DP = [[0] * (S + 1) for i in range(N + 1)]
DP[0][0] = 1
for i in range(N):
  for j in range(S + 1):
    if j >= A[i]:
      DP[i + 1][j] = (DP[i][j] * 2 + DP[i][j - A[i]]) % MOD
    else:
      DP[i + 1][j] = (DP[i][j] * 2) % MOD

print(DP[-1][-1] % MOD)






Fixed submission:
N, S = map(int, input().split())
A = list(map(int, input().split()))
MOD = 998244353

DP = [[0] * (S + 1) for i in range(N + 1)]
DP[0][0] = 1
for i in range(N):
  for j in range(S + 1):
    if j >= A[i]:
      DP[i + 1][j] = (DP[i][j] * 2 + DP[i][j - A[i]]) % MOD
    else:
      DP[i + 1][j] = (DP[i][j] * 2) % MOD

print(DP[-1][-1] % MOD)
Buggy python submission (verdict: Time Limit Exceeded):
def dijkstra(s,n,w,cost):
    #始点sから各頂点への最短距離
    #n:頂点数,　w:辺の数, cost[u][v] : 辺uvのコスト(存在しないときはinf)
    d = [float("inf")] * n
    used = [False] * n
    d[s] = 0
    before = [float("inf")] * n
    
    while True:
        v = -1
        #まだ使われてない頂点の中から最小の距離のものを探す
        for i in range(n):
            if (not used[i]) and (v == -1):
               v = i
            elif (not used[i]) and d[i] < d[v]:
                v = i
        if v == -1:
               break
        used[v] = True
               
        for j in range(n):
               d[j] = min(d[j],d[v]+cost[v][j])
               if d[j] == d[v] + cost[v][j]:
                 before[j] = v + 1
    return d, before

################################
n,w = map(int,input().split()) #n:頂点数　w:辺の数

cost = [[float("inf") for i in range(n)] for i in range(n)] 
#cost[u][v] : 辺uvのコスト(存在しないときはinf この場合は10**10)
for i in range(w):
    x,y = map(int,input().split())
    cost[x - 1][y - 1] = 1
    cost[y - 1][x - 1] = 1
#print(dijkstra(0,n,w,cost))
ans, ans2 = dijkstra(0,n,w,cost)

if "inf" in ans:
  print("No")
else:
  print("Yes")
  for i in range(1, n):
    print(ans2[i])

Fixed submission:
from collections import deque
n, m = map(int, input().split())
way = [[] for i in range(n + 1)]
ans = [-1 for i in range(n + 1)]
reached = [0 for i in range(n + 1)]

for i in range(m):
    a, b = map(int, input().split())
    way[a].append(b)
    way[b].append(a)
    
D = deque([1])
while D:
    go = D.popleft()
    for i in way[go]:
        if reached[i] == 0:
            D.append(i)
            reached[i] = 1
            ans[i] = go
print("Yes")
for i in range(2, n + 1):
    print(ans[i])
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = list(map(int, input().split()))

ans = 0
for i in range(2, N):
  for j in range(N - i):
    if A[j] + A[j + i] == i:
      ans += 1

print(ans)

Fixed submission:
import collections
N = int(input())
A = list(map(int, input().split()))

#i + Ai
plus = [0] * N
#i - Ai
minus = [0] * N

for i in range(N):
  plus[i] = i + 1 + A[i]
  minus[i] = i + 1 - A[i]
  
#print(plus, minus)  
plus = dict(collections.Counter(plus))
minus = dict(collections.Counter(minus))

#print(plus)
#print(minus)

ans = 0
for i in plus.keys():
  #print(i)
  if i in minus:
    #print(i)
    ans += plus[i] * minus[i]
    #print(ans)

print(ans)