Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
N = int(input())
A = list(map(int, input().split()))

A_sorted = sorted(A)
A_set = list(set(A))
A_cnt = dict()
for a in A:
    if not a in A_cnt.keys():
        A_cnt[a] = 1
    else:
        A_cnt[a] += 1

if A_cnt.get(0) == N:
    print("Yes")
    exit()

if len(A_set) > 3 or N%3 != 0:
    print("No")
    exit()

B = []
B.append(A_set[0])
B.append(A_set[1])
for _ in range(N-2):
    B.append(B[-1] ^ B[-2])

B_sorted = sorted(B)
if A_sorted == B_sorted:
    print("Yes")
else:
    print("No")

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

A_sorted = sorted(A)
A_set = list(set(A))
A_cnt = dict()
for a in A:
    if not a in A_cnt.keys():
        A_cnt[a] = 1
    else:
        A_cnt[a] += 1

if A_cnt.get(0) == N:
    print("Yes")
    exit()

if len(A_set) > 3 or len(A_set) == 1 or N%3 != 0:
    print("No")
    exit()

B = []
B.append(A_set[0])
B.append(A_set[1])
for _ in range(N-2):
    B.append(B[-1] ^ B[-2])

B_sorted = sorted(B)
if A_sorted == B_sorted:
    print("Yes")
else:
    print("No")
Buggy python submission (verdict: Runtime Error):
# N, K = map(int, input().split())

# X = list(map(int, input().split()))

with open("test.txt", 'r') as f:
    N, K = map(int, f.readline().split())
    X = list(map(int, f.readline().split()))

def calc_time(x_max, x_min):
    if x_max * x_min >= 0:
        if abs(x_max) > abs(x_min):
            return x_max
        else:
            return abs(x_min)
    else:
        return x_max - x_min + min(abs(x_max), abs(x_min))

def calc_start_and_goal_position(index):
    if index - K >= 0:
        start_index = index - K
    else:
        start_index = 0
    
    if N > index + K + 1:
        goal_index = index + 1
    else:
        goal_index = N - K + 1
    
    return start_index, goal_index

if __name__ == "__main__":
    index = -1
    for i, x in enumerate(X):
        if x >= 0:
            index = i 
            break
    if index == -1:
        index = i
    start_index, goal_index = calc_start_and_goal_position(index)

    time_min = float('inf')
    for i in range(start_index, goal_index):
        time = calc_time(X[i+K-1], X[i])
        if time < time_min:
            time_min = time
    print(time_min)

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

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

def calc_time(x_max, x_min):
    if x_max * x_min >= 0:
        if abs(x_max) > abs(x_min):
            return x_max
        else:
            return abs(x_min)
    else:
        return x_max - x_min + min(abs(x_max), abs(x_min))

def calc_start_and_goal_position(index):
    if index - K >= 0:
        start_index = index - K
    else:
        start_index = 0
    
    if N > index + K + 1:
        goal_index = index + 1
    else:
        goal_index = N - K + 1
    
    return start_index, goal_index

if __name__ == "__main__":
    index = -1
    for i, x in enumerate(X):
        if x >= 0:
            index = i 
            break
    if index == -1:
        index = i
    start_index, goal_index = calc_start_and_goal_position(index)

    time_min = float('inf')
    for i in range(start_index, goal_index):
        time = calc_time(X[i+K-1], X[i])
        if time < time_min:
            time_min = time
    print(time_min)
Buggy python submission (verdict: Time Limit Exceeded):
N, M, Q = map(int, input().split())
LR = [list(map(int, input().split())) for _ in range(M)]
pq = [list(map(int, input().split())) for _ in range(Q)]

XY = [[0 for _ in range(N)] for _ in range(N)]
for l, r in LR:
    XY[l - 1][r - 1] += 1

for i in range(N):
    for j in range(N - 1):
        XY[i][j + 1] += XY[i][j]

for p, q in pq:
    count = 0
    for i in range(p - 1, q):
        if p - 2 >= 0:
            count += XY[i][q - 1] - XY[i][p - 2]
        else:
            count += XY[i][q - 1] - 0
    print(count)


Fixed submission:
N, M, Q = map(int, input().split())
LR = [list(map(int, input().split())) for _ in range(M)]
pq = [list(map(int, input().split())) for _ in range(Q)]

XY = [[0 for _ in range(N)] for _ in range(N)]
for l, r in LR:
    XY[l - 1][r - 1] += 1

for i in range(N):
    for j in range(N):
        if i == 0 and j == 0:
            pass
        elif i == 0:
            XY[i][j] += XY[i][j - 1]
        elif j == 0:
            XY[i][j] += XY[i - 1][j]
            pre_im1_j = XY[i - 1][j]
        else:
            if XY[i - 1][j] == pre_im1_j:
                XY[i][j] += XY[i][j - 1]
            else:
                XY[i][j] += XY[i][j - 1] + XY[i - 1][j] - pre_im1_j
                pre_im1_j = XY[i - 1][j]

for p, q in pq:
    if p != 1:
        print(XY[q - 1][q - 1] + XY[p - 2][p - 2] - XY[p - 2][q - 1] - XY[q - 1][p - 2])
    else:
        print(XY[q - 1][q - 1])
Buggy python submission (verdict: Time Limit Exceeded):
N, M = map(int, input().split())
A = list(map(int, input().split()))
S_mod = [0]
s = 0
for a in A:
    s += a
    S_mod.append(s % M)

count = 0
for r in range(1, N+1):
    if S_mod[r] == 0:
        count += 1
    count += S_mod[(r + 1):].count(S_mod[r])

print(count)


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

mod_dict = dict()
S_mod = [0]
s = 0
for a in A:
    s += a
    mod = s % M
    S_mod.append(mod)
    if not mod in mod_dict.keys():
        mod_dict[mod] = 1
    else:
        mod_dict[mod] += 1

if 0 in mod_dict.keys():
    count = mod_dict[0]
else:
    count = 0
for key in mod_dict.keys():
    count += (mod_dict[key] - 1) * mod_dict[key] / 2

print(int(count))

Buggy python submission (verdict: Time Limit Exceeded):
N, M = map(int, input().split())
A = list(map(int, input().split()))
S = [0]
s = 0
for a in A:
    s += a
    S.append(s)

count = 0
for r in range(1, N+1):
    for l in range(r,N+1):
        if not (S[l] - S[r-1]) % M:
            count += 1

print(count)


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

mod_dict = dict()
S_mod = [0]
s = 0
for a in A:
    s += a
    mod = s % M
    S_mod.append(mod)
    if not mod in mod_dict.keys():
        mod_dict[mod] = 1
    else:
        mod_dict[mod] += 1

if 0 in mod_dict.keys():
    count = mod_dict[0]
else:
    count = 0
for key in mod_dict.keys():
    count += (mod_dict[key] - 1) * mod_dict[key] / 2

print(int(count))
Buggy python submission (verdict: Time Limit Exceeded):
S = input()

MOD = 1000000007

As = []
Bs = []
Cs = []
S_length = len(S)
hatena_count = 0
for i, c in enumerate(S):
    # 'A':0, 'B':1, 'C':2
    if c == 'A':
        As.append([S_length - i, 3])
    elif c == 'B':
        Bs.append([S_length - i, 3])
    elif c == 'C':
        Cs.append([S_length - i, 3])
    elif c == '?':
        hatena_count += 1
        As.append([S_length - i, 1])
        Bs.append([S_length - i, 1])
        Cs.append([S_length - i, 1])

new_Bs = []
for b in Bs:
    new_Bs.append([b, sum([c[1] for c in Cs if b[0] > c[0]])])

count = 0
for a in As:
    count += 3**(hatena_count - 3) * a[1] * sum([b[0][1] * b[1] for b in new_Bs if a[0] > b[0][0]])

print(int(count % MOD))

Fixed submission:
S = input()

MOD = 1000000007

# a_b_c, a_b_hc, a_hb_c, a_hb_hc, ha_b_c, ha_b_hc, ha_hb_c, ha_hb_hc
count = [[0, 0, 0] for _ in range(8)]
hatena_count = 0

for c in S:
    if c == 'A':
        nums = [0,1,2,3]
        for num in nums:
            count[num][0] += 1
    elif c == 'B':
        nums = [0,1,4,5]
        for num in nums:
            count[num][1] += count[num][0]
    elif c == 'C':
        nums = [0,2,4,6]
        for num in nums:
            count[num][2] += count[num][1]
    elif c == '?':
        # hc
        nums = [1,3,5,7]
        for num in nums:
            count[num][2] += count[num][1]
        
        # hb
        nums = [2,3,6,7]
        for num in nums:
            count[num][1] += count[num][0]

        # ha
        nums = [4,5,6,7]
        for num in nums:
            count[num][0] += 1
        
        hatena_count += 1

total = 0
coef = [0, 1, 1, 2, 1, 2, 2, 3]
for i in range(8):
    total += count[i][2] * 3**(hatena_count - coef[i])

print(int(total % MOD))
Buggy python submission (verdict: Runtime Error):
from functools import reduce
import math

N = int(input())
A = list(map(int, input().split()))

lcm = reduce(lambda x, y: (x * y) // math.gcd(x, y), A)

score = 0
for a in A:
    score += (lcm - 1) % a

print(score)

Fixed submission:
from functools import reduce

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

N = int(input())
A = list(map(int, input().split()))

lcm = reduce(lambda x, y: (x * y) // gcd(x, y), A)

score = 0
for a in A:
    score += (lcm - 1) % a

print(score)
Buggy python submission (verdict: Time Limit Exceeded):
N, M = map(int, input().split())
AB = list(list(map(int, input().split())) for _ in range(M))

AB_sorted = sorted(AB, key=lambda x : x[1])

removed_bridge = []
for ab in AB_sorted:
    for bridge in removed_bridge:
        if ab[0] < bridge < ab[1]:
            break
    else:
        removed_bridge.append(ab[1] - 0.5)

print(len(removed_bridge))

Fixed submission:
N, M = map(int, input().split())
AB = list(list(map(int, input().split())) for _ in range(M))

AB_sorted = sorted(AB, key=lambda x : x[1])

removed_bridge = []
for ab in AB_sorted:
    if removed_bridge:
        if ab[0] < removed_bridge[-1] < ab[1]:
            continue
    removed_bridge.append(ab[1] - 0.5)

print(len(removed_bridge))
Buggy python submission (verdict: Runtime Error):
N = int(input())
A = list(map(int, input()))

print(max(A) - min(A))

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

print(max(A) - min(A))
Buggy python submission (verdict: Time Limit Exceeded):
from statistics import mean

N = int(input())
A = list(map(int, input().split()))
A_star = [a - (i + 1) for i, a in enumerate(A)]

def calc_score(b):
    score = 0
    for a in A_star:
        score += abs(a - b)
    return score

def decide_direction(b):
    score0 = calc_score(b)
    score1 = calc_score(b + 1)
    if score0 > score1:
        return 1
    else:
        return -1

b = int(mean(A_star))
direction = decide_direction(b)
pre_score = calc_score(b)

while True:
    b += direction
    score = calc_score(b)
    if score > pre_score:
        print(pre_score)
        break
    else:
        pre_score = score






Fixed submission:
from statistics import median

N = int(input())
A = list(map(int, input().split()))

A_star = [a - (i + 1) for i, a in enumerate(A)]

def calc_score(b):
    score = 0
    for a in A_star:
        score += abs(a - b)
    return score

def decide_direction(b):
    score0 = calc_score(b)
    score1 = calc_score(b + 1)
    if score0 > score1:
        return 1
    else:
        return -1

b = int(median(A_star))
direction = decide_direction(b)
pre_score = calc_score(b)

while True:
    b += direction
    score = calc_score(b)
    if score >= pre_score:
        print(pre_score)
        break
    else:
        pre_score = score

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

N = int(input())
A = list(map(int, input().split()))

def calc_score(b):
    score = 0
    for i, a in enumerate(A):
        score += abs(a - (b + i + 1))
    return score


def decide_direction():
    score_b0 = calc_score(0)
    score_b1 = calc_score(1)
    
    if score_b0 > score_b1:
        return 1
    else:
        return -1


pre_score = calc_score(0)
b = 0
direction = decide_direction()

while True:
    b += direction
    score = calc_score(b)
    if score > pre_score:
        print(pre_score)
        break
    else:
        pre_score = score

Fixed submission:
from statistics import median

N = int(input())
A = list(map(int, input().split()))

A_star = [a - (i + 1) for i, a in enumerate(A)]

def calc_score(b):
    score = 0
    for a in A_star:
        score += abs(a - b)
    return score

def decide_direction(b):
    score0 = calc_score(b)
    score1 = calc_score(b + 1)
    if score0 > score1:
        return 1
    else:
        return -1

b = int(median(A_star))
direction = decide_direction(b)
pre_score = calc_score(b)

while True:
    b += direction
    score = calc_score(b)
    if score >= pre_score:
        print(pre_score)
        break
    else:
        pre_score = score
Buggy python submission (verdict: Time Limit Exceeded):
# import heapq
import itertools

N, M = map(int, input().split())

data = []
for _ in range(N):
    data.append(list(map(int, input().split())))

# scores = []
max_score = 0
for info in list(itertools.combinations(data, M)):
    beuty_score = 0
    taste_score = 0
    popular_score = 0
    for i in info:
        beuty_score += i[0]
        taste_score += i[1]
        popular_score += i[2]
    beuty_score = abs(beuty_score)
    taste_score = abs(taste_score)
    popular_score = abs(popular_score)
    if (beuty_score + taste_score + popular_score) > max_score:
        max_score = (beuty_score + taste_score + popular_score)
    # heapq.heappush(scores, -(beuty_score + taste_score + popular_score))

print(max_score)
# print(-heapq.heappop(scores))



Fixed submission:
import heapq

N, M = map(int, input().split())

data = []
for _ in range(N):
    data.append(list(map(int, input().split())))

score = [] 
scores = []
for i in range(-1, 2, 2):
    for j in range(-1, 2, 2):
        for k in range(-1, 2, 2):
            for info in data:
                heapq.heappush(score, -(i*info[0] + j*info[1] + k*info[2]))
            scores.append(-sum([heapq.heappop(score) for _ in range(M)]))
            score.clear()

print(max(scores))

Buggy python submission (verdict: Time Limit Exceeded):
import heapq
import itertools

N, M = map(int, input().split())

data = []
for _ in range(N):
    data.append(list(map(int, input().split())))

scores = []
for info in list(itertools.combinations(data, M)):
    beuty_score = 0
    taste_score = 0
    popular_score = 0
    for i in info:
        beuty_score += i[0]
        taste_score += i[1]
        popular_score += i[2]
    beuty_score = abs(beuty_score)
    taste_score = abs(taste_score)
    popular_score = abs(popular_score)
    heapq.heappush(scores, -(beuty_score + taste_score + popular_score))


print(-heapq.heappop(scores))



Fixed submission:
import heapq

N, M = map(int, input().split())

data = []
for _ in range(N):
    data.append(list(map(int, input().split())))

score = [] 
scores = []
for i in range(-1, 2, 2):
    for j in range(-1, 2, 2):
        for k in range(-1, 2, 2):
            for info in data:
                heapq.heappush(score, -(i*info[0] + j*info[1] + k*info[2]))
            scores.append(-sum([heapq.heappop(score) for _ in range(M)]))
            score.clear()

print(max(scores))
Buggy python submission (verdict: Runtime Error):
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())


n, m = list(map(int, input().split()))
uf = UnionFind(n)
for i in range(m):
    a, b = map(int, input().split())
    uf.union(a, b)
print(uf.group_count()-1)


Fixed submission:
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())


n, m = list(map(int, input().split()))
uf = UnionFind(n)
for i in range(m):
    a, b = map(int, input().split())
    uf.union(a-1, b-1)
print(uf.group_count()-1)
Buggy python submission (verdict: Time Limit Exceeded):

from collections import defaultdict
from bisect import bisect
n, k = list(map(int, input().split()))
al = [0] * n
for i in range(n):
    al[i] = int(input())

d = defaultdict(lambda: 0)
d[al[0]] = 1
for a in al[1:]:
    m = 0
    for i in range(max(0, a-k), a+k+1):
        m = max(m, d[i])
    d[a] = m+1
print(max(d.values()))


Fixed submission:

from collections import defaultdict
from bisect import bisect

n, k = list(map(int, input().split()))
al = [0] * n
for i in range(n):
    al[i] = int(input())
max_al = max(al)
min_al = min(al)

# N: 処理する区間の長さ
N = max(al)+1
N0 = 2**(N-1).bit_length()
INF = 2**31-1
data = [INF]*(2*N0)
# a_k の値を x に更新


def update(k, x):
    k += N0-1
    data[k] = x
    while k >= 0:
        k = (k - 1) // 2
        data[k] = min(data[2*k+1], data[2*k+2])
# 区間[l, r)の最小値


def query(l, r):
    L = l + N0
    R = r + N0
    s = INF
    while L < R:
        if R & 1:
            R -= 1
            s = min(s, data[R-1])

        if L & 1:
            s = min(s, data[L-1])
            L += 1
        L >>= 1
        R >>= 1
    return s


for i in range(n):
    update(al[i], n)

for a in al:
    v = query(max(min_al, a-k), min(a+k, max_al)+1)
    update(a, n-((n-v)+1))
v = query(min_al, max_al+1)
print(n-v)
Buggy python submission (verdict: Time Limit Exceeded):
n, k = list(map(int, input().split()))
s = []
for i in range(k):
    a, b = list(map(int, input().split()))
    for j in range(a, b+1):
        s.append(j)
s = set(s)
dp = [0]*(n+1)
dp[1] = 1
mod = 998244353
for i in range(1, n+1):
    for ss in s:
        if i+ss <= n:
            dp[i+ss] += dp[i]
            dp[i+ss] %= mod
print(dp[-1])


Fixed submission:
n, k = list(map(int, input().split()))
s = []
for i in range(k):
    a, b = list(map(int, input().split()))
    s.append((a, b))
dp = [0]*(n+1)
v = 0
mod = 998244353
for i in range(1, n+1):
    if i == 1:
        for l, r in s:
            if i+l <= n:
                dp[i+l] += 1
            if i+r+1 <= n:
                dp[i+r+1] -= 1
    else:
        v += dp[i]
        v %= mod
        for l, r in s:
            if i+l <= n:
                dp[i+l] += v
            if i+r+1 <= n:
                dp[i+r+1] -= v


print(v % mod)
Buggy python submission (verdict: Runtime Error):
n = int(input())
mod = 10**9+7
dp = [1]*(n+1)
for i in range(3):
    dp[i] = 0

for j in range(3, 10):
    if j <= n:
        dp[j] = 1

for i in range(3, n+1):
    for j in range(3, n):
        if i+j <= n:
            dp[i+j] += dp[i]
            dp[i+j] %= mod
print(dp[-1])


Fixed submission:
n = int(input())
mod = 10**9+7
dp = [1]*(n+1)
if n <= 2:
    print(0)
    exit()
for i in range(3):
    dp[i] = 0

for j in range(3, 10):
    if j <= n:
        dp[j] = 1

for i in range(3, n+1):
    for j in range(3, n):
        if i+j <= n:
            dp[i+j] += dp[i]
            dp[i+j] %= mod
print(dp[-1])

Buggy python submission (verdict: Runtime Error):
n = int(input())
mod = 10**9+7
dp = [1]*(n+1)
for i in range(3):
    dp[i] = 0

for j in range(3, 10):
    if j <= n:
        dp[j] = 1

for i in range(3, n+1):
    for j in range(3, n):
        if i+j <= n:
            dp[i+j] += dp[i]
            dp[i+j] %= mod
print(dp[-1])


Fixed submission:
n = int(input())
mod = 10**9+7
dp = [1]*(n+1)
if n <= 2:
    print(0)
    exit()
for i in range(3):
    dp[i] = 0

for j in range(3, 10):
    if j <= n:
        dp[j] = 1

for i in range(3, n+1):
    for j in range(3, n):
        if i+j <= n:
            dp[i+j] += dp[i]
            dp[i+j] %= mod
print(dp[-1])
Buggy python submission (verdict: Time Limit Exceeded):
n, k = list(map(int, input().split()))
al = list(map(int, input().split()))
t = 1
for i in range(n):
    tt = t
    t *= al[i]

    if i < k:
        continue
    else:
        t //= al[i-k]
        if tt < t:
            print('Yes')
        else:
            print('No')


Fixed submission:
n, k = list(map(int, input().split()))
al = list(map(int, input().split()))
t = 1
for i in range(n):
    if i < k:
        continue
    else:
        t //= al[i-k]
        if al[i-k] < al[i]:
            print('Yes')
        else:
            print('No')
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
li = list(map(int, input().split()))
x = 1
if 0 in li:
    print(0)
else:
    for i in li:
        x = x * i
    if x > 10**18:
        print(-1)
    else:
        print(x)


Fixed submission:
n = int(input())
al = list(map(int, input().split()))
al.sort()
ans = 1
for a in al:
    ans *= a
    if ans > 10**18:
        print(-1)
        exit()
print(ans)

Buggy python submission (verdict: Runtime Error):
n = int(input())
li = input().split(" ")
x = 1
if 0 in li:
    print(0)
else:
    for i in li:
        x = x * i
        if x > 10**18:
            print(-1)
            exit()
    print(x)


Fixed submission:
n = int(input())
al = list(map(int, input().split()))
al.sort()
ans = 1
for a in al:
    ans *= a
    if ans > 10**18:
        print(-1)
        exit()
print(ans)

Buggy python submission (verdict: Runtime Error):
n = int(input())
list = input().split(" ")
x = 1
if 0 in list:
  print(0)
else:
  for i in list:
    x = x * i
    if x > 10**18:
      print(-1)
      exit()
  print(x)


Fixed submission:
n = int(input())
al = list(map(int, input().split()))
al.sort()
ans = 1
for a in al:
    ans *= a
    if ans > 10**18:
        print(-1)
        exit()
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
list = input().split(" ")
x = 1
for i in list:
  x = x * int(i)
if x <= 10**18:
  print(x)
else:
  print(-1)


Fixed submission:
n = int(input())
al = list(map(int, input().split()))
al.sort()
ans = 1
for a in al:
    ans *= a
    if ans > 10**18:
        print(-1)
        exit()
print(ans)
Buggy python submission (verdict: Runtime Error):
from collections import deque
n, m = list(map(int, input().split()))
al = [0] * n
bl = [0] * n
G = [[] for _ in range(n)]
for i in range(n):
    a, b = map(int, input().split())
    G[a-1].append(b-1)
    G[b-1].append(a-1)
N = n
# G[v]: 頂点vに隣接する頂点list
# N: 頂点数

dist = [-1]*N
tag = [-1]*N
que = deque([0])
dist[0] = 0
pre = 0
while que:
    v = que.popleft()
    d = dist[v]
    for w in G[v]:
        if dist[w] > -1:
            continue
        dist[w] = d + 1
        tag[w] = v + 1
        que.append(w)

print('Yes')
for t in tag[1:]:
    print(t)


Fixed submission:
from collections import deque
n, m = list(map(int, input().split()))
al = [0] * n
bl = [0] * n
G = [[] for _ in range(n)]
for i in range(m):
    a, b = map(int, input().split())
    G[a-1].append(b-1)
    G[b-1].append(a-1)
N = n
# G[v]: 頂点vに隣接する頂点list
# N: 頂点数

dist = [-1]*N
tag = [-1]*N
que = deque([0])
dist[0] = 0
pre = 0
while que:
    v = que.popleft()
    d = dist[v]
    for w in G[v]:
        if dist[w] > -1:
            continue
        dist[w] = d + 1
        tag[w] = v + 1
        que.append(w)

print('Yes')
for t in tag[1:]:
    print(t)