Harryxun/GPT-100-sft-dataset huggingface dataset:
Problem p02708 (python)

Fixed submission:
N, K = map(int, input().split())  # 0~NのN+1個の整数, K個以上選ぶ, 注意 ; 3, 5 と 1, 3, 4は別物になる。0と5, 2と3 を選んだパターンは同じになる

MOD = 10**9+7
ans = 0
for k in range(K, N+2):
    ans += k*(2*N-(k-1))//2 - k*(k-1)//2 + 1
    ans %= MOD
print(ans)

Buggy submission (verdict: Runtime Error):
N, K = map(int, input().split())  # 0~NのN+1個の数字, K個以上選んで出来上がる数
ans = 0
MOD = 10**9+7
# 出来上がる数字の幅を考える
for k in range(K, N+2):  # K~N+1までループを回す
  upper = k*(2N-(k-1))//2
  lower = k*(k-1)//2
  ans += upper - lower + 1
  ans %= MOD
print(ans)
Problem p02788 (python)

Fixed submission:
import math
from bisect import bisect_right
N, D, A = map(int, input().split())  # N体のモンスター, 爆弾の範囲D, 爆弾の威力A
XH = []
X = []
for _ in range(N):
    x, h = map(int, input().split())
    XH.append((x, math.ceil(h/A)))  # 座標と必要な爆弾の個数を格納する
    X.append(x)  # こっちは座標のみ, あとで座標を二分探索するときに使う
# 座標でソートする
XH.sort()
X.sort()
T = [0]*(N+1)
now = 0
ans = 0
for i in range(N):
    x, h = XH[i]
    now -= T[i]
    if now >= h:
        continue
    else:
        T[bisect_right(X, x+D*2)] += h - now
        ans += h - now
        now = h
print(ans)

Buggy submission (verdict: Runtime Error):
import math
from bisect import bisect_right
N, D, A = map(int, input().split())  # N体のモンスター, 爆弾の範囲D, 爆弾の威力A
XH = []
X = []
for _ in range(N):
    x, h = map(int, input().split())
    XH.append(x, math.ceil(x/A))  # 座標と必要な爆弾の個数を格納する
    X.append(x)  # こっちは座標のみ, あとで座標を二分探索するときに使う
# 座標でソートする
XH.sort()
X.sort()
T = [0]*(N+1)
j = 0
now = 0
ans = 0
for i in range(N):
    x, h = XH[i]
    now -= T[i]
    if now >= h:
        continue
    else:
        T[bisect_right(X, x+D*2)] += h - now
        ans += h - now
        now = h
print(ans)
Problem p02796 (python)

Fixed submission:
N = int(input())
robots = []
for _ in range(N):
    x, l = map(int, input().split())
    robots.append((x-l, x+l))

robots.sort(key=lambda x: x[1])  # 終端を昇順ソート
# print(robots)
cnt = 0
last = -10**18  # 最初、最右のものははるか左側にあると考える
for left, right in robots:
    if left >= last:  # 残せるのであれば
        cnt += 1
        last = right
print(cnt)

Buggy submission (verdict: Runtime Error):
N = int(input())
robots = []
for _ in range(N):
    x, l = map(int, input().split())
    robots.append((x, l))

robots = sorted(robots, key=lambda x: x[0])
rightest_point = robots[0][0] + robots[0][1] - 1
ans = 0
# 無理やり一体目を置いた時
for i in range(1, len(robots)):
    if robots[i][0]-robots[i][1] + 1 < rightest_point:
        ans += 1
        continue
    else:
        rightest_point = robots[i][0]+robots[i][1] - 1
first = N-ans

# 1体目を置かない場合
rightest_point = robots[1][0] + robots[1][1] - 1
ans = 0
for i in range(2, len(robots)):
    # print("rightest_point: ", rightest_point)
    if robots[i][0]-robots[i][1] + 1 < rightest_point:
        ans += 1
        continue
    else:
        rightest_point = robots[i][0]+robots[i][1] - 1
# print("rightest_point: ", rightest_point)
second = N-ans-1
print(max(first, second))

Buggy submission (verdict: Runtime Error):
N = int(input())
robots = []
for _ in range(N):
    x, l = map(int, input().split())
    robots.append((x, l))

robots = sorted(robots, key=lambda x: x[0])
# print(robots)
rightest_point = robots[0][0] + robots[0][1] - 1

ans = 0
for i in range(1, N):
    # print("rightest_point: ", rightest_point)
    if robots[i][0]-robots[i][1] + 1 < rightest_point:
        ans += 1
        continue
    else:
        rightest_point = robots[i][0]+robots[i][1] - 1
# print("rightest_point: ", rightest_point)
first = N-ans
# 最初だけは例外

# ２体目から考える
rightest_point = robots[1][0] + robots[1][1] - 1

ans = 0
for i in range(2, N):
    # print("rightest_point: ", rightest_point)
    if robots[i][0]-robots[i][1] + 1 < rightest_point:
        ans += 1
        continue
    else:
        rightest_point = robots[i][0]+robots[i][1] - 1
second = N-ans
if robots[1][0] - robots[1][1] + 1 < robots[0][0] + robots[0][1] - 1:
    second -= 1

print(max(first, second))
Problem p02804 (python)

Fixed submission:
# 二項係数を"やるだけ"にしてくれるライブラリ
MAX = 510000
MOD = 1000000007
factrial = [0]*MAX
inverse = [0]*MAX
factrial_inverse = [0]*MAX


# テーブルを作る前処理
def COMinit():
    global factrial, inverse, factrial_inverse
    factrial[0] = 1
    factrial[1] = 1
    inverse[1] = 1
    factrial_inverse[0] = 1
    factrial_inverse[1] = 1
    for i in range(2, MAX):
        factrial[i] = factrial[i-1] * i % MOD
        inverse[i] = MOD - inverse[MOD % i] * (MOD//i) % MOD
        factrial_inverse[i] = factrial_inverse[i-1] * inverse[i] % MOD


# 二項係数計算
def COM(n, k):
    global factrial, inverse, factrial_inverse
    if n < k:
        return 0
    if n < 0 or k < 0:
        return 0
    return factrial[n] * (factrial_inverse[k] * factrial_inverse[n-k] % MOD) % MOD


# 前処理完了
COMinit()


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

# 最大値を固定してそのパターン数を数える
max_value_sum = 0
for i in range(N):
    max_value_sum += (A[i] * COM(i, K-1) + MOD) % MOD

# 最小値を固定してそのパターン数を数える
A.reverse()
min_value_sum = 0
for i in range(N):
    min_value_sum += (A[i] * COM(i, K-1) + MOD) % MOD

ans = max_value_sum - min_value_sum + MOD

print(ans % MOD)

Buggy submission (verdict: Runtime Error):
# 二項係数を"やるだけ"にしてくれるライブラリ
MAX = 10007
MOD = 1000000007
factrial = [0]*MAX
inverse = [0]*MAX
factrial_inverse = [0]*MAX


# テーブルを作る前処理
def COMinit():
    global factrial, inverse, factrial_inverse
    factrial[0] = 1
    factrial[1] = 1
    inverse[1] = 1
    factrial_inverse[0] = 1
    factrial_inverse[1] = 1
    for i in range(2, MAX):
        factrial[i] = factrial[i-1] * i % MOD
        inverse[i] = MOD - inverse[MOD % i] * (MOD//i) % MOD
        factrial_inverse[i] = factrial_inverse[i-1] * inverse[i] % MOD


# 二項係数計算
def COM(n, k):
    global factrial, inverse, factrial_inverse
    if n < k:
        return 0
    if n < 0 or k < 0:
        return 0
    return factrial[n] * (factrial_inverse[k] * factrial_inverse[n-k] % MOD) % MOD


# 前処理完了
COMinit()


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

# 最大値を固定してそのパターン数を数える
max_value_sum = 0
for i in range(N):
    max_value_sum += (A[i] * COM(i, K-1) + MOD) % MOD

A.reverse()
min_value_sum = 0
for i in range(N):
    min_value_sum += (A[i] * COM(i, K-1) + MOD) % MOD

ans = max_value_sum - min_value_sum + MOD

print(ans % MOD)
Problem p02807 (python)

Fixed submission:
# 二項係数を"やるだけ"にしてくれるライブラリ
MAX = 510000
MOD = 1000000007
factrial = [0]*MAX
inverse = [0]*MAX
factrial_inverse = [0]*MAX


# テーブルを作る前処理
def COMinit():
    global factrial, inverse, factrial_inverse
    factrial[0] = 1
    factrial[1] = 1
    inverse[1] = 1
    factrial_inverse[0] = 1
    factrial_inverse[1] = 1
    for i in range(2, MAX):
        factrial[i] = factrial[i-1] * i % MOD
        inverse[i] = MOD - inverse[MOD % i] * (MOD//i) % MOD
        factrial_inverse[i] = factrial_inverse[i-1] * inverse[i] % MOD


# 二項係数計算
def COM(n, k):
    global factrial, inverse, factrial_inverse
    if n < k:
        return 0
    if n < 0 or k < 0:
        return 0
    return factrial[n] * (factrial_inverse[k] * factrial_inverse[n-k] % MOD) % MOD


# 前処理完了
COMinit()

N = int(input())
X = list(map(int, input().split()))
# expected_value = [1]
# for i in range(2, N):
#     expected_value.append(expected_value[-1]+(1/i))
ans = 0
f = factrial[N-1]
c = 0
for i in range(1, N):
    c += f * inverse[i]
    c %= MOD
    ans += c * (X[i] - X[i-1])
    ans %= MOD

print(ans % MOD)

Buggy submission (verdict: Runtime Error):
# 二項係数を"やるだけ"にしてくれるライブラリ
MAX = 10005
MOD = 1000000007
factrial = [0]*MAX
inverse = [0]*MAX
factrial_inverse = [0]*MAX


# テーブルを作る前処理
def COMinit():
    global factrial, inverse, factrial_inverse
    factrial[0] = 1
    factrial[1] = 1
    inverse[1] = 1
    factrial_inverse[0] = 1
    factrial_inverse[1] = 1
    for i in range(2, MAX):
        factrial[i] = factrial[i-1] * i % MOD
        inverse[i] = MOD - inverse[MOD % i] * (MOD//i) % MOD
        factrial_inverse[i] = factrial_inverse[i-1] * inverse[i] % MOD


# 二項係数計算
def COM(n, k):
    global factrial, inverse, factrial_inverse
    if n < k:
        return 0
    if n < 0 or k < 0:
        return 0
    return factrial[n] * (factrial_inverse[k] * factrial_inverse[n-k] % MOD) % MOD


# 前処理完了
COMinit()

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

ans = 0
prepro = [1]
for i in range(2, N+1):
    prepro.append((prepro[-1]+inverse[i]) % MOD)

for i in range(N-1):
    ans += (X[i+1]-X[i]) * prepro[i] % MOD
    
ans *= factrial[N-1]  # 期待値の総和に(N-1)!をかける

print(ans % MOD)
Problem p02850 (python)

Fixed submission:
from collections import deque
N = int(input())
graph = [[] for _ in range(N)]
ans = {}
tmp = []
flag = [False] * N  # そのノードに到達済みか判定する
for _ in range(N-1):
    a, b = map(lambda x: int(x)-1, input().split())
    graph[a].append(b)
    graph[b].append(a)
    tmp.append((a, b))  # 最後に出力する時に使う
    ans[(a, b)] = -1
q = deque([0])  # 開始のノード
colors = [-1]*N
now_color = 0
while len(q):
    v = q.pop()
    flag[v] = True
    color = 1
    # vからeへの辺の色を塗る
    for e in graph[v]:

        if flag[e]:
            continue
        q.append(e)
        if color == colors[v]:
            color += 1
        ans[(v, e)] = color
        colors[e] = color
        color += 1
print(max(colors))
for a, b in tmp:
    print(ans[(a, b)])

Buggy submission (verdict: Runtime Error):
from collections import deque
N = int(input())
visited = [False]*N
tree = [[] for _ in range(N)]
tmp = []
for _ in range(N-1):
    a, b = map(lambda x: int(x)-1, input().split())
    tree[a].append(b)
    tree[b].append(a)
    tmp.append((a, b))  # 順番を保持するため

ans = {}  # 連想配列で保持する

q = deque([0])  # 開始のノード
colors = [-1]*N  # そのノードにささっている辺の色
while len(q):  # 幅優先探索を開始する
    v = q.pop()  # 部分木の親のノード
    color = 1
    for e in v:  # 子供に対して操作を行う
        if visited[e]:
            continue
        visited[e] = True
        if colors[v] == color:
            color += 1
        ans[(v, e)] = color
        colors[e] = color
        color += 1
        q.append(e)

print(max(colors))
for a, b in tmp:
    print(ans[(a, b)])

Buggy submission (verdict: Runtime Error):
from collections import deque
N = int(input())
visited = [False]*N
tree = [[] for _ in range(N)]
tmp = []
for _ in range(N-1):
    a, b = map(lambda x: int(x-1), input().split())
    tree[a].append(b)
    tree[b].append(a)
    tmp.append((a, b))  # 順番を保持するため

ans = {}  # 連想配列で保持する

q = deque([0])  # 開始のノード
colors = [-1]*N  # そのノードにささっている辺の色
while len(q):  # 幅優先探索を開始する
    v = q.pop()  # 部分木の親のノード
    color = 1
    for e in v:  # 子供に対して操作を行う
        if visited[e]:
            continue
        visited[e] = True
        if colors[v] == color:
            color += 1
        ans[(v, e)] = color
        colors[e] = color
        color += 1
        q.append(e)

print(max(colors))
for a, b in tmp:
    print(ans[(a, b)])
Problem p02882 (python)

Fixed submission:
from math import atan, degrees
a, b, x = map(int, input().split())

if 2*x >= a*a*b:
    h = 2*(a*a*b-x)/(a*a)
    print(degrees(atan(h/a)))
else:
    l = 2*(a*a*b-x)/(a*b) - a
    print(degrees(atan(b/(a-l))))

Buggy submission (verdict: Runtime Error):
import math
a, b, c = map(int, input().split())

# 容器に入っている水が半分以下の場合に困る
w = [2]
if a*a*b > 2 * c:
    print(w[4])
    h = (2*c)/(a*a)
    print(math.degrees(math.acos(h/a)))
else:
    h = 2*(a*a*b-c)/(a**2)
    print(math.degrees(math.atan(h/a)))

Buggy submission (verdict: Runtime Error):
import math
a, b, c = map(int, input().split())

# 容器に入っている水が半分以下の場合に困る
a = [2]
if a*a*b > 2 * c:
    print(a[4])
    h = (2*c)/(a*a)
    print(math.degrees(math.acos(h/a)))
else:
    h = 2*(a*a*b-c)/(a**2)
    print(math.degrees(math.atan(h/a)))

Buggy submission (verdict: Runtime Error):
import math
a, b, c = map(int, input().split())

# 容器に入っている水が半分以下の場合に困る
if a**2*b > 2 * c:
    h = (2*c)/(a**2)
    print(math.degrees(math.acos(h/a)))
else:
    h = 2*(a**2*b-c)/(a**2)
    print(math.degrees(math.atan(h/a)))
Problem p02889 (python)

Fixed submission:
from scipy.sparse.csgraph import floyd_warshall

# ダイクストラではなくワーシャルフロイドで解く
N, M, L = map(int, input().split())
# graph = [[] for _ in range(N)]
distant = [[float('inf')]*N for _ in range(N)]
for _ in range(M):
    a, b, c = map(int, input().split())
    a, b = a-1, b-1
    if c > L:
        continue
    distant[a][b] = c
    distant[b][a] = c

distant = floyd_warshall(distant)
another = [[float('inf')]*N for _ in range(N)]
for i in range(N):
    for j in range(N):
        if distant[i][j] <= L:  # 行けるところまでいくという印象
            another[i][j] = 1
another = floyd_warshall(another)
Q = int(input())
for _ in range(Q):
    s, t = map(lambda x: int(x)-1, input().split())
    if another[s][t] == float('inf'):
        print(-1)
        continue
    print(int(another[s][t])-1)
    # if distant[s][t] == float('inf'):
    #     print(-1)
    #     continue
    # print(int(distant[s][t])//L + min(1, int(distant[s][t]) % L) - 1)
# 燃料が4で
# 1 -> 4 -> 2
# のとき、距離は7だから一見すると補給回数は1で良さそうだけど、実は2回必要
# 今、２点間の最小距離を求めておいて、もう一つのグラフは「最短距離がL以下の2点に辺(重み1)を張る」

Buggy submission (verdict: Runtime Error):
from scipy.sparse.csgraph import floyd_warshall

# ダイクストラではなくワーシャルフロイドで解く
N, M, L = map(int, input().split())
# graph = [[] for _ in range(N)]
distant = [[float('inf')]*N for _ in range(N)]
for _ in range(M):
    a, b, c = map(int, input().split())
    a, b = a-1, b-1
    if c > L:
        continue
    distant[a][b] = c
    distant[b][a] = c

distant = floyd_warshall(distant)
another = [[float('inf')]*N for _ in range(N)]
for i in range(N):
    for j in range(N):
        if distant[i][j] <= L:  # 行けるところまでいくという印象
            another[i][j] = 1
another = floyd_warshall(another)
Q = int(input())
for _ in range(Q):
    s, t = map(lambda x: int(x)-1, input().split())
    if another[i][j] == float("inf"):
        print(-1)
        continue
    print(int(another[s][t])-1)
    # if distant[s][t] == float('inf'):
    #     print(-1)
    #     continue
    # print(int(distant[s][t])//L + min(1, int(distant[s][t]) % L) - 1)
# 燃料が4で
# 1 -> 4 -> 2
# のとき、距離は7だから一見すると補給回数は1で良さそうだけど、実は2回必要
# 今、２点間の最小距離を求めておいて、もう一つのグラフは「最短距離がL以下の2点に辺(重み1)を張る」
Problem p02991 (python)

Fixed submission:
from heapq import heappop, heappush

N, M = map(int, input().split())
graph = [[] for _ in range(N)]
for _ in range(M):
    a, b = map(lambda x: int(x)-1, input().split())
    graph[a].append(b)
S, T = map(lambda x: int(x)-1, input().split())

ans = -1
visited = set()
q = [(0, S)]
ans = -1
while q:
    c, v = heappop(q)  # cはカウント, vは頂点の番号
    key = (c % 3, v)
    if key in visited:
        continue
    visited.add(key)
    if v == T and c % 3 == 0:
        ans = c//3
        break
    c += 1
    d = c % 3
    for u in graph[v]:
        new_key = (d, u)
        if new_key in visited:
            continue
        heappush(q, (c, u))

print(ans)

Buggy submission (verdict: Runtime Error):
from heapq import heappush, heappop
N, M = map(int, input().split())  # N頂点, M辺
graph = [[] for _ in range(N)]

for _ in range(M):
    u, v = map(lambda x: int(x)-1, input().split())
    graph[u].append(v)

S, T = map(lambda x: int(x)-1, input().split())

dist = [[-1]*3 for _ in range(N)]
dist[S][0] = 0
q = []
heappush(q, (0, S))
while len(q):
    count, v = heappop(q)  # count, ノードのIndex
    for nv in graph[v]:  # nvは次のノードの番号
        np = (count + 1) % 3
        if dist[nv][np] == -1:  # 未到達なら
            dist[nv][np] = dist[v][count] + 1
            heappush(q, (nv, np))
if dist[T][0] == -1:
    print(-1)
else:
    print(dist[T][0]//3)
Problem p03031 (python)

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

# 繋がってるスイッチの情報
S = [list(map(int, input().split()))[1:] for _ in range(M)]
P = list(map(int, input().split()))

# print(S)
# print(P)

ans = 0

for i in range(1 << N):
    # print(i)
    for m in range(M):
        cnt = 0
        for s in S[m]:  # Sは繋がっているスイッチの情報
            if i & (1 << (s-1)) != 0:
                cnt += 1
        if cnt % 2 != P[m]:
            break
    else:
        ans += 1

print(ans)

Buggy submission (verdict: Runtime Error):
N, M = int(input().split())  # N個のスイッチ, M個の電球

# M個の電球がそれぞれどこのスイッチと繋がっているかを格納
SSS = [list(map(int, input().split()))[1:] for i in range(M)]
P = list(map(int, input().split()))

ans = 0

for i in range(1 << N):  # 2のN乗の値になる, bit全探索
    for mask in range(M):
        ans_2 = 0
        for s in SSS[mask]:
            if (1 << s-1) & i != 0:
                ans_2 += 1

        if ans_2 % 2 != P[mask]:
            break
    else:
        ans += 1

print(ans)

Buggy submission (verdict: Runtime Error):
N, M = int(input().split())  # N個のスイッチ, M個の電球

# M個の電球がそれぞれどこのスイッチと繋がっているかを格納
SSS = [list(map(int, input().split()))[1:] for i in range(M)]
P = list(map(int, input().split()))

ans = 0

for i in range(1 << N):  # 2のN乗の値になる, bit全探索
    for mask in range(M):
        ans_2 = 0
        for s in SSS[mask]:
            if (1 << s-1) & i != 0:
                ans_2 += 1

        if ans_2 % 2 != P[m]:
            break
    else:
        ans += 1

print(ans)
Problem p03044 (python)

Fixed submission:
import sys
sys.setrecursionlimit(10**7)
n=int(input())
a=[[] for i in range(n)]
for i in range(n-1):
    u,v,w=map(int,input().split())
    a[u-1].append((v-1,w))
    a[v-1].append((u-1,w))
b=[None for i in range(n)]
def k(v,dis):
    b[v]=dis
    for next_v,w in a[v]:
        if b[next_v]!=None:
            continue
        if w%2==0:
            k(next_v,dis)
        else:
            k(next_v,1-dis)
k(0,0)
for i in range(n):
    print(b[i])

Buggy submission (verdict: Runtime Error):
n=int(input())
a=[[] for i in range(n)]
for i in range(n-1):
    u,v,w=map(int,input().split())
    a[u-1].append((v-1,w))
    a[v-1].append((u-1,w))
b=[None for i in range(n)]
def k(v,dis):
    b[v]=dis
    for next_v,w in a[v]:
        if b[next_v]!=None:
            continue
        if w%2==0:
            k(next_v,dis)
        else:
            k(next_v,1-dis)
k(0,0)
for i in range(n):
    print(b[i])

Buggy submission (verdict: Runtime Error):
N = int(input())
graph = [[] for _ in range(N)]

for i in range(N-1):
    u, v, w = map(int, input().split())
    graph[u-1].append((v-1, w))
    graph[v-1].append((u-1, w))
# これによって木が定義できた
# print(graph)

flag = [None for _ in range(N)]  # まだどの頂点も探索していない


def k(v, distance):  # distanceは0or1
    flag[v] = distance  # 最初は0

    for next_v, w in graph[v]:
        if flag[next_v] == 1 or flag[next_v] == 0:  # 到達済み（親）であればcontinue
            continue
        if (w % 2) == 0:  # そのノードへの距離が偶数であればそのまま（最初は0なので）
            k(next_v, distance)
        else:
            k(next_v, 1-distance)


k(0, 0)  # 親を強制的に決めてよい, この場合は0のノードを親にしている
for i in range(N):
    print(int(flag[i]))

Buggy submission (verdict: Runtime Error):
def k(v, distance):  # distanceは0or1
    flag[v] = distance  # 最初は0

    for next_v, w in graph[v]:
        if flag[next_v] == 1 or flag[next_v] == 0:  # 到達済み（親）であればcontinue
            continue
        if w % 2 == 0:  # そのノードへの距離が偶数であればそのまま（最初は0なので）
            k(next_v, distance)
        else:
            k(next_v, 1-distance)


N = int(input())
graph = [[] for _ in range(N)]

for i in range(N-1):
    u, v, w = map(int, input().split())
    graph[u-1].append([v-1, w])
    graph[v-1].append([u-1, w])
# これによって木が定義できた
# print(graph)

flag = [None for _ in range(N)]  # まだどの頂点も探索していない

k(0, 0)  # 親を強制的に決めてよい, この場合は0のノードを親にしている
for i in range(N):
    print(int(flag[i]))
Problem p03061 (python)

Fixed submission:
def gcd(m, n):
    while n:
        m, n = n, m % n
    return m


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

left = [0]
right = [0]

for i in range(N):
    left.append(gcd(left[-1], A[i]))
    right.append(gcd(right[-1], A[(N-1)-i]))  # こっちのAは後ろからみる, iがN-1になった時はA[0]


right.reverse()  # indexが小さいほうが多くの数字を考慮した最大公約数になっている


gcd_list = [gcd(left[i], right[i+1]) for i in range(N)]

print(max(gcd_list))

Buggy submission (verdict: Runtime Error):
def gcd(m, n):
    while n:
        m, n = n, m % n
    return m


N = int(input())
A = list(map(int, input().split()))
# gcd_list = []
# hoge = gcd(A[0], A[1])
# for i in range(2, N):
#     gcd_list.append(gcd(hoge, A[i]))
# gcd_list.sort()
# print(gcd_list[len(gcd_list)-2])
A.sort()
max_A = max(A)
gcd_list = []
for i in range(int(N/2):
    tmp = A[i]
    A[i] = max_A
    hoge = gcd(A[0], A[1])
    for j in range(2, int(N/2):
        hoge = gcd(A[j], hoge)
    gcd_list.append(hoge)
    A[i] = tmp

print(max(gcd_list))
# 最大の値と変えてもいい

Buggy submission (verdict: Runtime Error):
N = int(input())
A = list(set(map(int, input().split())))


# ユークリッド互除法の関数の定義
def gcd(a, b):
    if b == 0:
        return a
    return gcd(b, a % b)


max_A = max(A)
gcd_list = []
if N == 1:
    print(A[0])
else:
    element = gcd(A[0], A[1])
    if N == 2:
        print(element)
        exit()
    else:
        for i in range(N):
            tmp = A[i]
            A[i] = max_A
            for j in range(2, N):
                element = gcd(element, A[i])
            gcd_list.append(element)
            A[i] = tmp
print(max(gcd_list))
# 最大の値と変えてもいい

Buggy submission (verdict: Runtime Error):
import math
from functools import reduce

N = int(input())

A = list(map(int, input().split()))
max_A = max(A)
gcd_list = []
for i in range(N):
    tmp = A[i]
    A[i] = max_A
    gcd = reduce(math.gcd, A)
    gcd_list.append(gcd)
    A[i] = tmp

print(max(gcd_list))
# 最大の値と変えてもいい

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

N = int(input())

A = list(map(int, input().split()))
max_A = max(A)
gcd_list = []
for i in range(N):
    tmp = A[i]
    A[i] = max_A
    gcd = functools.reduce(math.gcd, A)
    gcd_list.append(gcd)
    A[i] = tmp

print(max(gcd_list))
# 最大の値と変えてもいい
Problem p03069 (python)

Fixed submission:
N = int(input())
S = str(input())
# '.'の場合は白, '#'の場合は黒

if S[0] == '.':
    count_white = [1]
    count_black = [0]
else:
    count_white = [0]
    count_black = [1]


for i in range(1, N):
    if S[i] == '.':
        # 見ている石が白なら
        count_white.append(count_white[i-1]+1)
        count_black.append(count_black[i-1])
    else:
        # 見ている石が黒なら
        count_white.append(count_white[i-1])
        count_black.append(count_black[i-1]+1)

tmp = 9999999999
for i in range(1, N):
    min_sum = 0
    min_sum += count_black[i-1]
    min_sum += (count_white[N-1] - count_white[i])
    tmp = min(tmp, min_sum)

# print(tmp)

cnt = 0
target = S[0]
for i in range(1, N):
    if target == '#' and S[i] == '.':
        cnt += 1
        target = '#'  # 黒に変える
        continue

    if S[i] == '#':
        target = '#'
    else:
        target = '.'

cnt_2 = 0
aim = S[-1]
for i in range(N-1, -1, -1):
    if aim == '.' and S[i] == '#':
        cnt_2 += 1
        aim = '.'
        continue

    if S[i] == '#':
        aim = '#'
    else:
        aim = '.'


print(int(min(cnt, cnt_2, tmp)))

Buggy submission (verdict: Runtime Error):
N = int(input())
S = str(input())
# '.'の場合は白, '#'の場合は黒

if S[0] == '.':
    count_white = [1]
    count_black = [0]
else:
    count_white = [0]
    count_black = [1]


for i in range(1, N):
    if S[i] == '.':
        # 見ている石が白なら
        count_white.append(count_white[i-1]+1)
        count_black.append(count_black[i-1])
    else:
        # 見ている石が黒なら
        count_white.append(count_white[i-1])
        count_black.append(count_black[i-1]+1)

hoge = []
for i in range(1, N):
    min_sum = 0
    min_sum += count_black[i-1]
    min_sum += (count_white[N-1] - count_white[i])
    hoge.append(min_sum)

print(min(hoge))

Buggy submission (verdict: Runtime Error):
N = int(input())
S = str(input())
# '.'の場合は白, '#'の場合は黒

if S[0] == '.':
    count_white = [1]
    count_black = [0]
else:
    count_white = [0]
    count_black = [1]


for i in range(1, N):
    if S[i] == '.':
        # 見ている石が白なら
        count_white.append(count_white[i-1]+1)
        count_black.append(count_black[i-1])
    else:
        # 見ている石が黒なら
        count_white.append(count_white[i-1])
        count_black.append(count_black[i-1]+1)

# print(count_black)
# print(count_white)

# change_count = [x+y for x, y in zip(count_white, count_black)]
change_count = []
for i in range(1, N):
    change_count.append(count_black[i-1] + (count_white[N-1] - count_white[i]))

print(min(change_count))