Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
#!/usr/bin/env python3
import fractions

def lcm(x, y):
    return (x * y) // fractions.gcd(x, y)

N, M = map(int, input().split())
S = input()
T = input()
if S[0] != T[0]:
    print(-1)
    exit()

l = lcm(N, M)

Moji = ['']*l
Moji[0] = S[0]

for i in range(1, N):
    index = i * (l//N) + 1
    if Moji[index-1] == '':
        Moji[index-1] = S[i]

for i in range(1, M):
    index = i * (l//M) + 1
    if Moji[index-1] == '':
        Moji[index-1] = T[i]
    else:
        if Moji[index-1] != T[i]:
            print(-1)
            exit()

print(l)


Fixed submission:
#!/usr/bin/env python3
import fractions

def lcm(x, y):
    return (x * y) // fractions.gcd(x, y)

N, M = map(int, input().split())
S = input()
T = input()
if S[0] != T[0]:
    print(-1)
    exit()

l = lcm(N, M)

Moji = {}
Moji[0] = S[0]

for i in range(1, N):
    index = i * (l//N) + 1
    Moji[index-1] = S[i]

for i in range(1, M):
    index = i * (l//M) + 1
    if index-1 in Moji and Moji[index-1] != T[i]:
        print(-1)
        exit()

print(l)

Buggy python submission (verdict: Runtime Error):
#!/usr/bin/env python3
import fractions

def lcm(x, y):
    return (x * y) // fractions.gcd(x, y)

N, M = map(int, input().split())
S = input()
T = input()
if S[0] != T[0]:
    print(-1)
    exit()

l = lcm(N, M)

Moji = ['']*l
Moji[0] = S[0]

for i in range(1, N):
    index = i * (l//N) + 1
    if Moji[index-1] == '':
        Moji[index-1] = S[i]

for i in range(1, M):
    index = i * (l//M) + 1
    if Moji[index-1] == '':
        Moji[index-1] = T[i]
    else:
        if Moji[index-1] != T[i]:
            print(-1)
            exit()

print(l)


Fixed submission:
#!/usr/bin/env python3
import fractions

def lcm(x, y):
    return (x * y) // fractions.gcd(x, y)

N, M = map(int, input().split())
S = input()
T = input()
if S[0] != T[0]:
    print(-1)
    exit()

l = lcm(N, M)

Moji = {}
Moji[0] = S[0]

for i in range(1, N):
    index = i * (l//N) + 1
    Moji[index-1] = S[i]

for i in range(1, M):
    index = i * (l//M) + 1
    if index-1 in Moji and Moji[index-1] != T[i]:
        print(-1)
        exit()

print(l)
Buggy python submission (verdict: Runtime Error):
#!/usr/bin/env python3
import math


def lcm(x, y):
    return (x * y) // math.gcd(x, y)

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

g = A[0]
for i in range(1,N):
    g = lcm(g,A[i])
g -= 1

ans = 0
for a in A:
    ans += g % a
print(ans)


Fixed submission:
#!/usr/bin/env python3
#import math
import fractions

def lcm(x, y):
    return (x * y) // fractions.gcd(x, y)

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

g = A[0]
for i in range(1,N):
    g = lcm(g,A[i])
g -= 1

ans = 0
for a in A:
    ans += g % a
print(ans)
Buggy python submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-
h, w = map(int, raw_input().split())

matrix = []
matrix.append('.'*(w+2))

for i in range(w):
    matrix.append('.' + raw_input() + '.')

matrix.append('.'*(w+2))

for i in range(1, h+1):
    for j in range(1, w+1):
        if matrix[i][j] == '#':
            if matrix[i+1][j] == '#' or matrix[i-1][j] == '#' or matrix[i][j-1] == '#' or matrix[i][j+1] == '#':
                continue
            else:
                print 'No'
                exit()
print 'Yes'

Fixed submission:
#!/usr/bin/env python3
H, W = map(int, input().split())
M = [list(input()) for _ in range(H)]

# yoko
for i in range(H):
    for j in range(W-1):
        if (M[i][j] == '#' or M[i][j] == 'M') and (M[i][j+1] == '#' or M[i][j+1] == 'M'):
            M[i][j] = 'M'
            M[i][j+1] = 'M'

#tate
for j in range(W):
    for i in range(H-1):
        if (M[i][j] == '#' or M[i][j] == 'M') and (M[i+1][j] == '#' or M[i+1][j] == 'M'):
            M[i][j] = 'M'
            M[i+1][j] = 'M'

ret = 0
for m in M:
    ret += m.count('#')

if ret == 0: print('Yes')
else: print('No')

Buggy python submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-
h, w = map(int, raw_input().split())

matrix = []

matrix.append(list('.'*(w+2)))
for i in range(w):
    matrix.append(['.'] + list(raw_input()) + ['.'])
matrix.append(list('.'*(w+2)))

for i in range(1, h+1):
    for j in range(1, w+1):
        if matrix[i][j] == '#':
            if matrix[i+1][j] == '#' or matrix[i-1][j] == '#' or matrix[i][j-1] == '#' or matrix[i][j+1] == '#':
                continue
            else:
                print 'No'
                exit()
print 'Yes'


Fixed submission:
#!/usr/bin/env python3
H, W = map(int, input().split())
M = [list(input()) for _ in range(H)]

# yoko
for i in range(H):
    for j in range(W-1):
        if (M[i][j] == '#' or M[i][j] == 'M') and (M[i][j+1] == '#' or M[i][j+1] == 'M'):
            M[i][j] = 'M'
            M[i][j+1] = 'M'

#tate
for j in range(W):
    for i in range(H-1):
        if (M[i][j] == '#' or M[i][j] == 'M') and (M[i+1][j] == '#' or M[i+1][j] == 'M'):
            M[i][j] = 'M'
            M[i+1][j] = 'M'

ret = 0
for m in M:
    ret += m.count('#')

if ret == 0: print('Yes')
else: print('No')
Buggy python submission (verdict: Runtime Error):
#!/usr/bin/env python3

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

cnt = 0
for i in range(N):
    if i+1 == P[i]:
        p = P[i]
        P[i] = P[i+1]
        P[i+1] = p
        cnt += 1

print(cnt)



Fixed submission:
#!/usr/bin/env python3

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

cnt = 0
for i in range(N-1):
    if i+1 == P[i]:
        p = P[i]
        P[i] = P[i+1]
        P[i+1] = p
        cnt += 1

if P[N-1] == N:
    cnt += 1

print(cnt)
Buggy python submission (verdict: Runtime Error):
def main():
    INP = list(map(int, input().split()))
    list1 = [INP[0],INP[1]]
    list2 = [INP[2],INP[3]]
    if INP[0] < 0 and INP[1] > 0:
        list1.append([-1,0,1])
    if INP[2] < 0 and INP[3] > 0:
        list2.append([-1,0,1])
    ans = -(10**18)
    for item in list1:
        for item2 in list2:
            ans = max(ans,item*item2)
    print(ans)       


if __name__ == '__main__':
    main()

Fixed submission:
def main():
    INP = list(map(int, input().split()))
    list1 = [INP[0],INP[1]]
    list2 = [INP[2],INP[3]]
    if INP[0] < 0 and INP[1] > 0:
        list1.extend([-1,0,1])
    if INP[2] < 0 and INP[3] > 0:
        list2.extend([-1,0,1])
    ans = -(10**18)
    for item in list1:
        for item2 in list2:
            ans = max(ans,item*item2)
    print(ans)     


if __name__ == '__main__':
    main()
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input().split()[0])
a_list = list(map(int, input().split()))

mod = 10 ** 9 + 7
total = 0
for i, a in enumerate(a_list):
    for j in range(len(a_list) - (i + 1)):
        total += (a * a_list[i + 1 + j]) % mod
total = total % mod
ans = total
print(ans)

Fixed submission:
#!/usr/bin/env python3

N = int(input().split()[0])
a_list = list(map(int, input().split()))

mod = 10 ** 9 + 7
sum_a = sum(a_list)
total = 0
for i, a in enumerate(a_list):
    total += (a * (sum_a - a)) % mod
    sum_a -= a
total = total % mod
ans = total
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
#!/usr/bin/env python3

N = int(input().split()[0])
a_list = list(map(int, input().split()))


mod = 10 ** 9 + 7
total = 0
for i, a in enumerate(a_list):
    for j in range(len(a_list) - (i + 1)):
        total += (a * a_list[i + 1 + j]) % mod
total = total % mod
ans = total
print(ans)


Fixed submission:
#!/usr/bin/env python3

N = int(input().split()[0])
a_list = list(map(int, input().split()))

mod = 10 ** 9 + 7
sum_a = sum(a_list)
total = 0
for i, a in enumerate(a_list):
    total += (a * (sum_a - a)) % mod
    sum_a -= a
total = total % mod
ans = total
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
#!/usr/bin/env python3

X, Y, A, B, C = list(map(int, input().split()))
p_list = list(map(int, input().split()))  # 10 ** 5
q_list = list(map(int, input().split()))
r_list = list(map(int, input().split()))

p_list = sorted(p_list, reverse=True)
q_list = sorted(q_list, reverse=True)
r_list = sorted(r_list, reverse=True)

total = 0
for _ in range(X):
    if r_list and p_list:
        r = r_list[0]
        p = p_list[0]

        if p >= r:
            total += p_list.pop(0)
        else:
            total += r_list.pop(0)
    elif r_list:
        total += r_list.pop()
    elif p_list:
        total += p_list.pop()
    else:
        break

for _ in range(Y):
    if r_list and q_list:
        r = r_list[0]
        q = q_list[0]

        if q >= r:
            total += q_list.pop(0)
        else:
            total += r_list.pop(0)
    elif r_list:
        total += r_list.pop(0)
    elif q_list:
        total += q_list.pop(0)
    else:
        break
ans = total
print(ans)


Fixed submission:
#!/usr/bin/env python3

X, Y, A, B, C = list(map(int, input().split()))
p_list = list(map(int, input().split()))  # 10 ** 5
q_list = list(map(int, input().split()))
r_list = list(map(int, input().split()))

p_list = list(sorted(p_list, reverse=True))
q_list = list(sorted(q_list, reverse=True))
# r_list = sorted(r_list, reverse=True)

p_list = p_list[:X]
q_list = q_list[:Y]

all_list = p_list + q_list + r_list
all_list = list(sorted(all_list, reverse=True))
total = sum(all_list[: X + Y])


ans = total
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
H, N = list(map(int, input().split()))
ab_list = []
max_a = -float("inf")
for _ in range(N):
    a, b = list(map(int, input().split()))
    ab_list.append((a, b))
    max_a = max(max_a, a)

dp_table = [[0] + [float("inf")] * (H + max_a) for _ in range(N + 1)]

for i in range(1, N + 1):
    a, b = ab_list[i - 1]
    next_j = 0
    for j in range(H + max_a):
        # 攻撃jをしない場合
        before_best_cost = dp_table[i - 1][j]
        dp_table[i][j] = before_best_cost
        # 攻撃jをする場合
        if j - a < 0:
            continue
        cost = dp_table[i - 1][j - a] + b
        min_cost = min(before_best_cost, cost)

        cost = dp_table[i][j - a] + b
        min_cost = min(min_cost, cost)

        dp_table[i][j] = min_cost

        if j > H and min_cost != float("inf"):
            dp_table[i][H] = min(dp_table[i][H], min_cost)

ans = dp_table[-1][H]
print(ans)

Fixed submission:

H, N = list(map(int, input().split()))
ab_list = []
max_a = -float("inf")
for _ in range(N):
    a, b = list(map(int, input().split()))
    ab_list.append((a, b))
    max_a = max(max_a, a)

dp_table = [[0] + [float("inf")] * H for _ in range(N + 1)]

for i in range(1, N + 1):
    a, b = ab_list[i - 1]
    next_j = 0
    # for j in range(H + max_a):
    over_min_cost = float("inf")
    for j in range(H + 1):
        # 攻撃jをしない場合
        before_best_cost = dp_table[i - 1][j]
        dp_table[i][j] = min(dp_table[i][j], before_best_cost)
        # 攻撃jをする場合
        if j - a >= 0:
            cost = dp_table[i - 1][j - a] + b
            min_cost = min(before_best_cost, cost)

            cost = dp_table[i][j - a] + b
            min_cost = min(min_cost, cost)

            dp_table[i][j] = min(dp_table[i][j], min_cost)

        if j + a > H:
            cost = dp_table[i - 1][j] + b
            dp_table[i][H] = min(dp_table[i][H], cost)
            cost = dp_table[i][j] + b
            dp_table[i][H] = min(dp_table[i][H], cost)
            dp_table[i][H] = min(dp_table[i][H], dp_table[i - 1][H])

ans = dp_table[-1][H]
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
import fractions

N = int(input())
a_list = list(map(int, input().split()))
x = a_list[0]
for i in range(1, N):
    x = x * a_list[i] // fractions.gcd(x, a_list[i])
mod = 10 ** 9 + 7
t = 0
for a in a_list:
    b = x // a
    t += b % mod

ans = t % mod
print(ans)

Fixed submission:
#!/usr/bin/env python3
import fractions

N = int(input())
a_list = list(map(int, input().split()))
x = a_list[0]
for i in range(1, N):
    x = x * a_list[i] // fractions.gcd(x, a_list[i])
mod = 10 ** 9 + 7
t = 0
for a in a_list:
    b = x // a
    t += b

ans = t % mod
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
#!/usr/bin/env python3
import fractions

N = int(input())
a_list = list(map(int, input().split()))
x = a_list[0]
for i in range(1, N):
    x = x * a_list[i] // fractions.gcd(x, a_list[i])
mod = 10 ** 9 + 7
t = 0
for a in a_list:
    b = x // a
    t += b % mod

ans = t % mod
print(ans)


Fixed submission:
#!/usr/bin/env python3
import fractions

N = int(input())
a_list = list(map(int, input().split()))
x = a_list[0]
for i in range(1, N):
    x = x * a_list[i] // fractions.gcd(x, a_list[i])
mod = 10 ** 9 + 7
t = 0
for a in a_list:
    b = x // a
    t += b

ans = t % mod
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
#!/usr/bin/env python3
import itertools

N = int(input().split()[0])
S = input()

index_list = [i for i in range(N)]
p_list = []

for pattern in itertools.combinations(index_list, 3):
    a, b, c = list(sorted(list(pattern)))

    s = S[a] + S[b] + S[c]
    p_list.append(s)

ans = len(set(p_list))

print(ans)


Fixed submission:
import collections
import copy

N = int(input().split()[0])
S = input()

counter = collections.Counter(S)
total = 0
done_list = []

for i, ch in enumerate(S[::-1]):  # 3 * 10 ** 4
    if ch in done_list:
        counter[ch] = counter[ch] - 1
        if counter[ch] < 1:
            del counter[ch]
        continue
    sub_done_list = []
    counter[ch] = counter[ch] - 1
    if counter[ch] < 1:
        del counter[ch]
    sub_counter = copy.copy(counter)

    for ch_2 in S[N - (i + 1) - 1 :: -1]:  # 3 * 10 ** 4
        if ch_2 in sub_done_list:
            sub_counter[ch_2] = sub_counter[ch_2] - 1
            if sub_counter[ch_2] < 1:
                del sub_counter[ch_2]
            continue
        sub_done_list.append(ch_2)
        sub_counter[ch_2] = sub_counter[ch_2] - 1
        if sub_counter[ch_2] < 1:
            del sub_counter[ch_2]
        total += len(sub_counter.keys())

    done_list.append(ch)

ans = total

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
#!/usr/bin/env python3
import bisect


N = int(input().split()[0])
l_list = list(map(int, input().split()))
l_list = sorted(l_list)
p_list = []

for a_i, a in enumerate(l_list):
    for b_i, b in enumerate(l_list):
        if a_i == b_i:
            continue

        c_kouho = a + b
        c_i = bisect.bisect_left(l_list, c_kouho)
        p_list += [
            sorted([a, b, c])
            for c_i, c in enumerate(l_list[: c_i + 1])
            if c_i != a_i and c_i != b_i and abs(b - c) < a < b + c
        ]

p_list = ["{}_{}_{}".format(p[0], p[1], p[2]) for p in p_list]
ans = len(set(p_list))

print(ans)


Fixed submission:
#!/usr/bin/env python3
import bisect


N = int(input().split()[0])
l_list = list(map(int, input().split()))
l_list = sorted(l_list)
total = 0

for a_i, a in enumerate(l_list):
    # 一番長い辺を固定
    for b_i, b in enumerate(l_list[:a_i]):
        # 2番目に長い辺を固定
        c_i = bisect.bisect_right(l_list, abs(a - b))
        total += max(b_i - c_i, 0)

ans = total
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
#!/usr/bin/env python3
import bisect


N = int(input().split()[0])
l_list = list(map(int, input().split()))
l_list = sorted(l_list)
p_list = []

for a_i, a in enumerate(l_list):
    for b_i, b in enumerate(l_list):
        if a_i == b_i:
            continue

        c_kouho = a + b
        c_i = bisect.bisect_left(l_list, c_kouho)
        p_list += [
            sorted([a, b, c])
            for c_i, c in enumerate(l_list[: c_i + 1])
            if c_i != a_i and c_i != b_i and abs(b - c) < a < b + c
        ]

p_list = ["{}_{}_{}".format(p[0], p[1], p[2]) for p in p_list]
ans = len(set(p_list))

print(ans)


Fixed submission:
#!/usr/bin/env python3
import bisect


N = int(input().split()[0])
l_list = list(map(int, input().split()))
l_list = sorted(l_list)
total = 0

for a_i, a in enumerate(l_list):
    # 一番長い辺を固定
    for b_i, b in enumerate(l_list[:a_i]):
        # 2番目に長い辺を固定
        c_i = bisect.bisect_right(l_list, abs(a - b))
        total += max(b_i - c_i, 0)

ans = total
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
#!/usr/bin/env python3

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

for _ in range(M):
    a_list = sorted(a_list, reverse=True)
    a_list[0] = a_list[0] // 2

ans = sum(a_list)
print(ans)


Fixed submission:
#!/usr/bin/env python3
import heapq

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

# Pythonのheapqは最小値しかとれないので、負の値に変換して扱う
a_list = list(map(lambda x: x * (-1), a_list))
heapq.heapify(a_list)

for _ in range(M):
    max_value = -heapq.heappop(a_list)
    heapq.heappush(a_list, -(max_value // 2))

ans = -sum(a_list)
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
#!/usr/bin/env python3

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

for _ in range(M):
    max_diff = -float("inf")
    max_index = 0
    for i, a in enumerate(a_list):
        if a - (a // 2) > max_diff:
            max_diff = a - (a // 2)
            max_a = a // 2
            max_index = i
    a_list[max_index] = max_a

ans = sum(a_list)
print(ans)


Fixed submission:
#!/usr/bin/env python3
import heapq

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

# Pythonのheapqは最小値しかとれないので、負の値に変換して扱う
a_list = list(map(lambda x: x * (-1), a_list))
heapq.heapify(a_list)

for _ in range(M):
    max_value = -heapq.heappop(a_list)
    heapq.heappush(a_list, -(max_value // 2))

ans = -sum(a_list)
print(ans)
Buggy python submission (verdict: Runtime Error):
N = int(input().split()[0])
h_list = list(map(int, input().split()))

tentou_list = []

for i in range(N-1):
    if h_list[i] >= h_list[i+1]:
        t = 1
    else:
        t = 0
    tentou_list.append(t)

# 一番長い1はどれか
c = 0
c_list = []

for t in tentou_list:
    if t == 0:
        c_list.append(c)
        c = 0
    else:
        c += 1

if t == 1:
    c_list.append(c)

ans = max(c_list)
print(ans)


Fixed submission:
N = int(input().split()[0])
h_list = list(map(int, input().split()))

tentou_list = []

for i in range(N-1):
    if h_list[i] >= h_list[i+1]:
        t = 1
    else:
        t = 0
    tentou_list.append(t)

# 一番長い1はどれか
c = 0
c_list = []

for t in tentou_list:
    if t == 0:
        c_list.append(c)
        c = 0
    else:
        c += 1

if tentou_list:
    if t == 1:
        c_list.append(c)
    ans = max(c_list)
else:
    ans = 0

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
import math

N = int(input().split()[0])

n_list = [i for i in range(1, N+1)]
p_list = n_list[1:] + [1]

ans_1 = sum(n_list[:-1])
if (N - 1) % 2 == 0:
    ans = int(N * ((N - 1) / 2))
else:
    mean_v = math.floor((N - 1) / 2) + 1
    ans = int(N * math.floor((N - 1) / 2))
    ans += mean_v

print(ans)


Fixed submission:
import math

N = int(input().split()[0])

# if (N - 1) % 2 == 0:
#     ans = int(N * ((N - 1) / 2))
# else:
#     mean_v = math.floor((N - 1) / 2) + 1
#     ans = int(N * math.floor((N - 1) / 2))
#     ans += mean_v

ans = N * (N-1) // 2

print(ans)
Buggy python submission (verdict: Runtime Error):
A, B, C = list(map(int, input().split()))
  
print(max([A+B, A-B, A*B]))


Fixed submission:
A, B = list(map(int, input().split()))
  
print(max([A+B, A-B, A*B]))

Buggy python submission (verdict: Runtime Error):
A, B, C = list(map(int, input().split()))
  
print(max(A+B, A-B, A*B))


Fixed submission:
A, B = list(map(int, input().split()))
  
print(max([A+B, A-B, A*B]))
Buggy python submission (verdict: Time Limit Exceeded):
# https://atcoder.jp/contests/abc137/tasks/abc137_c
# C - Green Bin
import collections
import itertools

n = int(input().split()[0])
s_list = []
c_list = []

for _ in range(n):
    s = input().split()[0]
    s_list.append(s)
    c_list.append(collections.Counter(s))

p = itertools.combinations(c_list, 2)
ans = sum([1 if a == b else 0 for a, b in list(p)])
print(ans)


Fixed submission:
# https://atcoder.jp/contests/abc137/tasks/abc137_c
# C - Green Bin
import collections
import itertools
import math

n = int(input().split()[0])
s_list = []
c_list = []

for _ in range(n):
    s = input().split()[0]
    s_list.append(''.join(sorted(s)))

counter = collections.Counter(s_list)

def C(n, k):
    return math.factorial(n) / (math.factorial(k) * math.factorial(n-k))

p_list = [C(value, 2) for key, value in counter.items() if value > 1]
ans = int(sum(p_list))

print(ans)
Buggy python submission (verdict: Runtime Error):
nokori = a - b
ans = c - nokori
if ans < 0:
    ans = 0
print(ans)


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

nokori = a - b
ans = c - nokori
if ans < 0:
    ans = 0
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
import copy

n = int(input().split()[0])
a_list = []

for _ in range(n):
    a_list.append(int(input().split()[0]))

max_str = ''

for i, a in enumerate(a_list):
    kouho_list = copy.copy(a_list)
    kouho_list.pop(i)
    max_str += '{}\n'.format(max(kouho_list))

print(max_str[:-1])


Fixed submission:
import copy

n = int(input().split()[0])
a_list = []

for _ in range(n):
    a_list.append(int(input().split()[0]))

kouho_list = sorted(a_list)
max_n = max(kouho_list)
second_max_n = kouho_list[-2]

max_list = [str(max_n) if x != max_n else str(second_max_n) for x in a_list]
max_str = '\n'.join(max_list)

print(max_str)

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

n = int(input().split()[0])
a_list = []

for _ in range(n):
    a_list.append(int(input().split()[0]))

max_list = []

for i, a in enumerate(a_list):
    kouho_list = copy.copy(a_list)
    kouho_list.pop(i)
    max_list.append(max(kouho_list))

for x in max_list:
    print(x)


Fixed submission:
import copy

n = int(input().split()[0])
a_list = []

for _ in range(n):
    a_list.append(int(input().split()[0]))

kouho_list = sorted(a_list)
max_n = max(kouho_list)
second_max_n = kouho_list[-2]

max_list = [str(max_n) if x != max_n else str(second_max_n) for x in a_list]
max_str = '\n'.join(max_list)

print(max_str)
Buggy python submission (verdict: Runtime Error):
#!/usr/bin/env python3

N = int(input().split()[0])
a_list = list(map(int, input().split()))

# 最初が0から始まる場合
b_list = [0] * N
b_list[-1] = a_list[-1]

for i in range(N):
    # 大きい方から決めていく
    idx = N - (i + 1)
    total = 0
    for j in b_list[:: idx + 1]:
        # idx + 1の倍数のボールの個数を数える
        total += b_list[j]

    if total % (idx + 1) != a_list[idx]:
        b_list[idx] = 1

idx_list = [str(i + 1) for i, b in enumerate(b_list) if b == 1]
ans = sum(b_list)
print(ans)
print(" ".join(idx_list))


Fixed submission:
#!/usr/bin/env python3

N = int(input().split()[0])
a_list = list(map(int, input().split()))

# 最初が0から始まる場合
a_list = [0] + a_list
b_list = [0] * (N + 1)
# インデックスがずれるのがややこしいので、
# b_list[0]は欠番として1始まりで考えていく

for i in range(N):
    # 大きい方から決めていく
    idx = N - i
    total = sum(b_list[idx : N + 1 : idx])

    if total % 2 != a_list[idx]:
        b_list[idx] = 1

idx_list = [str(i) for i, b in enumerate(b_list) if b == 1]
ans = sum(b_list[1:])
print(ans)
if ans != 0:
    print(" ".join(idx_list))

Buggy python submission (verdict: Runtime Error):
#!/usr/bin/env python3

N = int(input().split()[0])
a_list = list(map(int, input().split()))

# 最初が0から始まる場合
b_list = [0] * N
b_list[-1] = a_list[-1]

for i in range(1, N + 1):
    # 大きい方から決めていく
    idx = N - i
    total = 0
    for j in b_list[:: idx + 1]:
        # idx + 1の倍数のボールの個数を数える
        total += b_list[j]

    if total % (idx + 1) != a_list[idx]:
        b_list[idx] = 1

idx_list = [str(i + 1) for i, b in enumerate(b_list) if b == 1]
ans = sum(b_list)
print(ans)
print(" ".join(idx_list))


Fixed submission:
#!/usr/bin/env python3

N = int(input().split()[0])
a_list = list(map(int, input().split()))

# 最初が0から始まる場合
a_list = [0] + a_list
b_list = [0] * (N + 1)
# インデックスがずれるのがややこしいので、
# b_list[0]は欠番として1始まりで考えていく

for i in range(N):
    # 大きい方から決めていく
    idx = N - i
    total = sum(b_list[idx : N + 1 : idx])

    if total % 2 != a_list[idx]:
        b_list[idx] = 1

idx_list = [str(i) for i, b in enumerate(b_list) if b == 1]
ans = sum(b_list[1:])
print(ans)
if ans != 0:
    print(" ".join(idx_list))