Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
seq = list(input())
# print(seq)

import itertools
combination = list(itertools.combinations(seq, 3))

print(len(set(combination)))

Fixed submission:
#三井住友信託銀行プログラミングコンテスト2019-D
N = int(input())
S = input()
ans = 0

possible_pass = [str(i).zfill(3) for i in range(1000)]

for password in possible_pass:
    try:
        first_num = S.index(password[0])
        S_second = S[first_num+1:]
        second_num = S_second.index(password[1])
        S_third = S_second[second_num+1:]
        third_num = S_third.index(password[2])
        ans += 1
    except:
        continue
    
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
seq = list(input())
# print(seq)

import itertools
combination = list(itertools.combinations(seq, 3))

print(len(set(combination)))

Fixed submission:
#三井住友信託銀行プログラミングコンテスト2019-D
N = int(input())
S = input()
ans = 0

possible_pass = [str(i).zfill(3) for i in range(1000)]

for password in possible_pass:
    try:
        first_num = S.index(password[0])
        S_second = S[first_num+1:]
        second_num = S_second.index(password[1])
        S_third = S_second[second_num+1:]
        third_num = S_third.index(password[2])
        ans += 1
    except:
        continue
    
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
ans = 0
for i in range(1, (N+1)//2):
    for j in range((N+1)//2, N+1):
        if (i + j) > N:
            break
        elif (i + j) == N:
            ans += 1
            break

print(ans)

Fixed submission:
N = int(input())
if N % 2 == 1:
    N += 1
ans = (N/2)-1
print(int(ans))

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
ans = 0
for i in range(1, (N+1)//2):
    for j in range((N+1)//2, N+1):
        if (i + j) == N:
            ans += 1

print(ans)

Fixed submission:
N = int(input())
if N % 2 == 1:
    N += 1
ans = (N/2)-1
print(int(ans))

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
ans = 0
for i in range(1, N+1):
#     print("i",i)
    for j in range(i+1, N+1):
#         print("j",j)
#         print((i + j) == N)
        if (i + j) == N:
            ans += 1

print(ans)

Fixed submission:
N = int(input())
if N % 2 == 1:
    N += 1
ans = (N/2)-1
print(int(ans))
Buggy python submission (verdict: Runtime Error):
#E https://atcoder.jp/contests/abc142/submissions/7853616
def main():
    n, m = map(int, input().split())
    inf = 10**9 #この10億は何に使う？->とにかくデカい数字。
    bit_dp = [inf for _ in range(2**(n))] #10億を2**n個並べる配列を作る。n=12 => 4096個
    bit_dp[0] = 0
    for i in range(m):
        a, b = map(int, input().split())
        c = list(map(int, input().split()))#鍵1個につきa,b,c1~cbを決める
        bit_n = 0
        for i in c:
            bit_n |= 1 << i - 1 #ここで何番目をあけられるのかをbit_nで定義する。1と3ならbit_n=(5)101、2と3なら110(6)
        for i in range(2**n):
            if bit_dp[i|bit_n] > bit_dp[i] + a:
                bit_dp[i|bit_n] = bit_dp[i] + a
    if bit_dp[-1] >= inf:
        print(-1)
    else:
        print(bit_dp[-1])
                
if __name__ == "__main__":
    main()

Fixed submission:
N = int(input())
if N % 2 == 0:
    print(1 / 2)
else:
    print((N - (((N + 1) / 2) -1)) / N)

Buggy python submission (verdict: Runtime Error):
A, B = map(int, input().split())
def gcd(x, y):
        while y != 0:
            x, y = y, x%y
        return x
    
def factorize(n):
    factor = []
    for num in range(2, n*n+1):
        while n % num == 0:
            n //= num
            factor.append(num)
    return factor
    
g = gcd(A, B)
f = factorize(g)
print(len(f)+1)

Fixed submission:
N = int(input())
if N % 2 == 0:
    print(1 / 2)
else:
    print((N - (((N + 1) / 2) -1)) / N)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = list(map(int, input().split()))
ans_list = []

for i in range(N):
    num = A.index(i+1)
    ans_list.append(str(num+1))
    
print(" ".join(ans_list))

Fixed submission:
N = int(input())
Ai_list = [number for number in map(int, input().split())]
Ai_And_i_list = {}
for i, Ai in enumerate(Ai_list):
    Ai_And_i_list[Ai] = i + 1
sorted_list = sorted(Ai_And_i_list.items())
for key, value in sorted_list:
    print(value)
Buggy python submission (verdict: Runtime Error):
def main():
    n, m = map(int, input().split())
    inf = 10**9 #この10億は何に使う？->とにかくデカい数字。
    bit_bp = [inf for _ in range(2**(n))] #10億を2**n個並べる配列を作る。n=12 => 4096個
    bit_dp[0] = 0

    for i in range(m):
        a, b = map(int, input().split())
        c = list(map(int, input().split()))#鍵1個につきa,b,c1~cbを決める
        bit_n = 0
        for i in c:
            bit_n |= 1 << i - 1 #ここで何番目をあけられるのかをbit_nで定義する。1と3ならbit_n=(5)101、2と3なら110(6)
        for i in range(2**n):
            if bit_dp[i|bit_n] > bit_dp[i] + a: #
                bit_dp[i|bit_n] = bit_dp[i] + a

    if bit_dp[-1] >= inf:
        print(-1)
    else:
        print(bit_dp[-1])
                
if __name__ == "__main__":
    main()

Fixed submission:
#E https://atcoder.jp/contests/abc142/submissions/7853616
def main():
    n, m = map(int, input().split())
    inf = 10**9 #この10億は何に使う？->とにかくデカい数字。
    bit_dp = [inf for _ in range(2**(n))] #10億を2**n個並べる配列を作る。n=12 => 4096個
    bit_dp[0] = 0
    for i in range(m):
        a, b = map(int, input().split())
        c = list(map(int, input().split()))#鍵1個につきa,b,c1~cbを決める
        bit_n = 0
        for i in c:
            bit_n |= 1 << i - 1 #ここで何番目をあけられるのかをbit_nで定義する。1と3ならbit_n=(5)101、2と3なら110(6)
        for i in range(2**n):
            if bit_dp[i|bit_n] > bit_dp[i] + a:
                bit_dp[i|bit_n] = bit_dp[i] + a
    if bit_dp[-1] >= inf:
        print(-1)
    else:
        print(bit_dp[-1])
                
if __name__ == "__main__":
    main()
Buggy python submission (verdict: Time Limit Exceeded):
# ABC-141-D
N, M = map(int, input().split())
A = list(map(int, input().split()))

for _ in range(M):
    A[A.index(max(A))] //= 2
    
print(sum(A))

Fixed submission:
# ABC-141-D
# https://qiita.com/ellio08/items/fe52a9eb9499b7060ed6
import heapq

N, M = map(int, input().split())
A = [i * (-1) for i in list(map(int, input().split()))]
heapq.heapify(A)

for _ in range(M):
    tmp = heapq.heappop(A) * (-1)
    heapq.heappush(A, (tmp//2)*-1)

# これだとTLEになる。
# for _ in range(M):
#     A[A.index(max(A))] //= 2

print(sum(A)*-1)
Buggy python submission (verdict: Time Limit Exceeded):
# ABC-139-D
N = int(input())

A = [i for i in range(1, N)]
print(sum(A))

Fixed submission:
# ABC-139-D
N = int(input())

# TLEになった
# A = [i for i in range(1, N)]
# print(sum(A))

#sum(N) = ((N+1)*N)/2なのでこちらで実施。
print((N * (N-1))//2)
Buggy python submission (verdict: Time Limit Exceeded):
#ABC-137-C
from collections import Counter
N = int(input())
S = []
for _ in range(N):
    si = Counter(input())
    S.append(si)

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

print(ans)

Fixed submission:
#ABC-137-C
N = int(input())
S = []
for _ in range(N):
    si = sorted(input())
    S.append("".join(si))

ans = 0
already_exist = {}

for i in range(N):
    if S[i] not in already_exist:
        already_exist[S[i]] = 0
    else:
        already_exist[S[i]] += 1
        ans += already_exist[S[i]]

# TLEになるので却下
# for i in range(N-1):
#     for j in range(i+1, N):
#         if S[i] == S[j]:
#             ans += 1

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
# ABC-137-D
import heapq
import bisect
N, M = map(int, input().split())
AB = []#Aでソートをかけて利用する。
BA = []#Bでソートをかけてheapqで利用する。
heapq.heapify(BA)

for _ in range(N):
    A, B = map(int, input().split())
    AB.append((A, B))    
AB = sorted(AB)

ans = 0
check_M = 1
while check_M <= M:
    r = bisect.bisect_right(AB, (check_M+1, 0))
    for A, B in AB[:r]:
        heapq.heappush(BA, (-1*B, A))
    try:
        max_B = heapq.heappop(BA)
    except:
        check_M += 1
        AB = AB[r:]
        continue
    ans += (-1) * max_B[0]
    check_M += 1
    AB = AB[r:]

print(ans)

Fixed submission:
# ABC-137-D
import heapq

N, M = map(int, input().split())
day_value = [[] for _ in range(M+1)]

for _ in range(N):
    A, B = map(int, input().split())
    if A <= M:
        day_value[A].append(B)

ans = 0
check_M = 1
BA = []
heapq.heapify(BA)

while check_M <= M:
    for item in day_value[check_M]:
        heapq.heappush(BA, -1*item)
    try:
        max_B = heapq.heappop(BA)
    except:
        check_M += 1
        continue
    ans += (-1) * max_B
    check_M += 1
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = [int(input()) for _ in range(N)]

for i in range(N):
    A_copy = A[:]
    removed_A = A_copy.pop(i)
    print(max(A_copy))


Fixed submission:
#ABC-134-C
N = int(input())
A = {}
for i in range(N):
    A[i] = int(input())

value_sorted = sorted(A.items(), key=lambda x:x[1])
max_value = 0

for i in range(N):
    max_value_tapple = value_sorted[-1]
    if max_value_tapple[0] == i:
        max_value_tapple = value_sorted[-2]
        max_value = max_value_tapple[1]
    else:
        max_value = max_value_tapple[1]
    print(max_value)
Buggy python submission (verdict: Runtime Error):
L, R = map(int, input().split())


if L == 0 or R-L >= 2019:
    ans = 0
else:
    flag = True
    for i in range(L, R+1):
        if i % 2019 == 0:
            ans = 0
            flag = False
            break
    if flag:
        raise
        ans = (L*(L+1))%2019

print(ans)


Fixed submission:
#ABC-133-C
#2019が素数ではなく3 * 673だから、2019の倍数が含まれてなければL*(L+1)%2019が答え。というアプローチで失敗だった。
L, R = map(int, input().split())
ans = 10 ** 10

for i in range(L, R+1):
    if ans == 0:
        break
    for j in range(i+1, R+1):
        ans = min(ans, (i * j) % 2019)
        if ans == 0:
            break

print(ans)
Buggy python submission (verdict: Runtime Error):
#ABC-131-C
import math
A, B, C, D = map(int, input().split())
lcm = C * D // math.gcd(C, D)
#1~A-1までの数字でCでもDでも割り切れないものの個数
A_divided_C = (A-1) // C
A_divided_D = (A-1) // D
A_divided_CD = (A-1) // (lcm)
one_to_A = (A-1) - A_divided_C - A_divided_D + A_divided_CD

#1~Bまでの数字でCでもDでも割り切れないものの個数
B_divided_C = B // C
B_divided_D = B // D
B_divided_CD = B // (lcm)
one_to_B = B - B_divided_C - B_divided_D + B_divided_CD

ans = one_to_B - one_to_A
print(ans)

Fixed submission:
#ABC-131-C
def gcd(a,b):
    while b!=0:
        a,b=b,a%b
    return a
    
A, B, C, D = map(int, input().split())
lcm = C * D // gcd(C, D)
#1~A-1までの数字でCでもDでも割り切れないものの個数
A_divided_C = (A-1) // C
A_divided_D = (A-1) // D
A_divided_CD = (A-1) // (lcm)
one_to_A = (A-1) - A_divided_C - A_divided_D + A_divided_CD

#1~Bまでの数字でCでもDでも割り切れないものの個数
B_divided_C = B // C
B_divided_D = B // D
B_divided_CD = B // (lcm)
one_to_B = B - B_divided_C - B_divided_D + B_divided_CD

ans = one_to_B - one_to_A
print(ans)
Buggy python submission (verdict: Runtime Error):
N = int(input())
W = list(map(int, input().split()))
ans = 10**9

for i in range(1, n):
    S1 = sum(W[:i])
    S2 = sum(W[i:])
    sa = abs(S1-S2)
    ans = min(ans, sa)
print(ans)

Fixed submission:
N = int(input())
W = list(map(int, input().split()))
ans = 10**9

for i in range(1, N):
    S1 = sum(W[:i])
    S2 = sum(W[i:])
    sa = abs(S1-S2)
    ans = min(ans, sa)
print(ans)

Buggy python submission (verdict: Runtime Error):
# ABC-129-B
N = int(input())
W = list(map(int, input().split()))
ans = 10**9

for i in range(1, n):
    S1 = sum(W[:i])
    S2 = sum(W[i:])
    sa = abs(S1-S2)
    ans = min(ans, sa)
print(ans)

Fixed submission:
N = int(input())
W = list(map(int, input().split()))
ans = 10**9

for i in range(1, N):
    S1 = sum(W[:i])
    S2 = sum(W[i:])
    sa = abs(S1-S2)
    ans = min(ans, sa)
print(ans)
Buggy python submission (verdict: Runtime Error):
N, M = map(int, input().split())
memo = [0]*(N+1)
memo[1] = 1
memo[2] = 2
mod = 10**9+7

for _ in range(M):
    ai = int(input())
    memo[ai] = None

if memo[1] == None:
    memo[2] = 1

for i in range(3, N+1):
    tmp = 0
    if memo[i] == None:
        continue
    if memo[i-1] != None:
        tmp += memo[i-1]
    if memo[i-2] != None:
        tmp += memo[i-2]
    memo[i] = tmp

print(memo[N]%mod)


Fixed submission:
#ABC-129-C
N, M = map(int, input().split())
# N, M = map(int, input().split())
a = [int(input()) for i in range(M)]

dp = [0] * (N+1)
#どうやってもスタート地点から始まるから、0に行く方法は1通りのみ
dp[0] = 1

#1が壊れていなければ1に行く方法は0->1の1通りのみ
if 1 not in a:
    dp[1] = 1
    not_broken_stairs = set(range(2, N+1)) - set(a)
else:
    not_broken_stairs = set(range(1, N+1)) - set(a)    

#i=2or3から始まる。
#１が壊れていなければ2に行く方法は(0->2の1通り)+(1->2の1通り)で2通り。
for i in not_broken_stairs:
    dp[i] = dp[i-2] + dp[i-1]
    
print(dp[-1] % (10 ** 9 + 7))

Buggy python submission (verdict: Runtime Error):
#ABC-129-C
N, M = map(int, input().split())
# N, M = map(int, input().split())
a = [int(input()) for i in range(M)]

dp = [0] * (N+1)
#どうやってもスタート地点から始まるから、0に行く方法は1通りのみ
dp[0] = 1

#1が壊れていなければ1に行く方法は0->1の1通りのみ
if a[0] != 1:
    dp[1] = 1
    not_broken_stairs = set(range(2, N+1)) - set(a)
else:
    not_broken_stairs = set(range(1, N+1)) - set(a)    

#i=2or3から始まる。
#１が壊れていなければ2に行く方法は(0->2の1通り)+(1->2の1通り)で2通り。
for i in not_broken_stairs:
    dp[i] = dp[i-2] + dp[i-1]
    
print(dp[-1] % (10 ** 9 + 7))

Fixed submission:
#ABC-129-C
N, M = map(int, input().split())
# N, M = map(int, input().split())
a = [int(input()) for i in range(M)]

dp = [0] * (N+1)
#どうやってもスタート地点から始まるから、0に行く方法は1通りのみ
dp[0] = 1

#1が壊れていなければ1に行く方法は0->1の1通りのみ
if 1 not in a:
    dp[1] = 1
    not_broken_stairs = set(range(2, N+1)) - set(a)
else:
    not_broken_stairs = set(range(1, N+1)) - set(a)    

#i=2or3から始まる。
#１が壊れていなければ2に行く方法は(0->2の1通り)+(1->2の1通り)で2通り。
for i in not_broken_stairs:
    dp[i] = dp[i-2] + dp[i-1]
    
print(dp[-1] % (10 ** 9 + 7))

Buggy python submission (verdict: Runtime Error):
#ABC-129-C
N, M = map(int, input().split())
# N, M = map(int, input().split())
a = [int(input()) for i in range(M)]

dp = [0] * (N+1)
#どうやってもスタート地点から始まるから、0に行く方法は1通りのみ
dp[0] = 1

#1が壊れていなければ1に行く方法は0->1の1通りのみ
if a[0] != 1:
    dp[1] = 1
    not_broken_stairs = set(range(2, N+1)) - set(a)
else:
    not_broken_stairs = set(range(1, N+1)) - set(a)    

#i=2or3から始まる。
#１が壊れていなければ2に行く方法は(0->2の1通り)+(1->2の1通り)で2通り。
for i in not_broken_stairs:
    dp[i] = dp[i-2] + dp[i-1]
    
print(dp[-1] % (10 ** 9 + 7))

Fixed submission:
#ABC-129-C
N, M = map(int, input().split())
# N, M = map(int, input().split())
a = [int(input()) for i in range(M)]

dp = [0] * (N+1)
#どうやってもスタート地点から始まるから、0に行く方法は1通りのみ
dp[0] = 1

#1が壊れていなければ1に行く方法は0->1の1通りのみ
if 1 not in a:
    dp[1] = 1
    not_broken_stairs = set(range(2, N+1)) - set(a)
else:
    not_broken_stairs = set(range(1, N+1)) - set(a)    

#i=2or3から始まる。
#１が壊れていなければ2に行く方法は(0->2の1通り)+(1->2の1通り)で2通り。
for i in not_broken_stairs:
    dp[i] = dp[i-2] + dp[i-1]
    
print(dp[-1] % (10 ** 9 + 7))
Buggy python submission (verdict: Runtime Error):
# ABC-128-B
# score_sorted = sorted(score.items(), key=lambda x:x[0])
r_list = []
ans_list = []
N = int(input())
for i in range(1, N+1):
    Si, Pi = input().split()
    r_list.append((Si, int(Pi), i))
    
name_sorted_list = sorted(r_list, key=lambda x:x[0])
while len(name_sorted_list) > 0:
    test_list = []
    list_index = [i for i, x in enumerate(name_sorted_list) if x  == name_sorted_list[1]]
    for i in list_index:
        test_list.append(name_sorted_list[i])
        del name_sorted_list[i]
    test_list = sorted(test_list, key=lambda x:x[1])
    for item in test_list:
        ans_list.append(item)

for item in ans_list:
    print(item[2])

Fixed submission:
r_list = []
ans_list = []
N = int(input())
for i in range(1, N+1):
    Si, Pi = input().split()
    r_list.append((Si, int(Pi), i))
    
name_sorted_list = sorted(r_list, key=lambda x:x[0])

while len(name_sorted_list) > 0:
    test_list = []
    list_index = [i for i, x in enumerate(name_sorted_list) if x[0]  == name_sorted_list[0][0]]
    for i in list_index:
        test_list.append(name_sorted_list[i])
    for i in reversed(list_index):
        del name_sorted_list[i]
    test_list = sorted(test_list, key=lambda x:x[1], reverse = True)
    for item in test_list:
        ans_list.append(item)
    
for item in ans_list:
    print(item[2])
Buggy python submission (verdict: Time Limit Exceeded):
#ABC-127-C
N, M = map(int, input().split())
LR  = []
for _ in range(M):
    Li, Ri = map(int, input().split())
    LR.append((Li, Ri))

possible_card_list = [i for i in range(LR[0][0], LR[0][1]+1)]

for Li, Ri in LR:
    for possible_card in possible_card_list[:]:
        if Li <= possible_card and possible_card <= Ri:
            #OK
            pass
        else:
            possible_card_list.remove(possible_card)
            
print(len(possible_card_list))
        

Fixed submission:
#ABC-127-C
N, M = map(int, input().split())
L_list  = []
R_list = []
for _ in range(M):
    Li, Ri = map(int, input().split())
    L_list.append(Li)
    R_list.append(Ri)

max_L = max(L_list)
min_R = min(R_list)

if max_L > min_R:
    print(0)
else:
    print(min_R-max_L+1)
Buggy python submission (verdict: Runtime Error):
from math import gcd

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

L = [-1] * (N-1)
L[0] = A[0]
R = [-1] * (N-1)
R[0] = A[-1]

for i in range(1, N-1):
    L[i] = gcd(L[i-1], A[i])
    R[i] = gcd(R[i-1], A[-i-1])

ans = 0
for i in range(1, N-1):
    tmp = gcd(L[i-1], R[N-i-2])
    ans = max(ans, tmp)

ans = max(ans, L[N-2])
ans = max(ans, R[N-2])
print(ans)


Fixed submission:
#ABC-125-C
N = int(input())
A = list(map(int, input().split())) #[0, 1, 2, ..., N-2, N-1]
L = [0] * N #L[0]とL[N-1]は0から変わらない。N=5なら実行終了時にL=[*0*,a,b,c,*0*]となる。
R = [0] * N #R[0]とR[N-1]は0から変わらない。N=5なら実行終了時にR=[*0*,f,e,d,A[4]]となる。

def gcd(x, y):
    while y:
        x, y = y, x%y
    return x

ans_gcd = -1

#Lから埋める
L[0] = A[0]
check_gcd = L[0]
for i in range(1, N-1): #N=5のときはi=1~3を実施して最終的にL=[0,a,b,c,0]となる。
    check_gcd = gcd(check_gcd, A[i])
    L[i] = check_gcd

#Rを埋める
R[-1] = A[-1]
check_gcd = R[-1]
for i in reversed(range(1, N-1)):#N=5のときはi=3~1を実施して最終的にR=[0,f,e,d,0]となる。
    check_gcd = gcd(check_gcd, A[i])
    R[i] = check_gcd

#端以外を書き換えの対象とした場合の最大公約数のMaxを探す。
for i in range(1, N-1):
    m = gcd(L[i-1], R[i+1])
    ans_gcd = max(ans_gcd, m)

#端と比べて最終的な答えを出す。N>2のときは数字が低い方を消すだけ。
if N > 2:
    ans_gcd = max(ans_gcd, gcd(A[-2], L[N-3]), gcd(A[1], R[2]))
else:
    ans_gcd = max(A)

print(ans_gcd)

Buggy python submission (verdict: Time Limit Exceeded):
#ABC-125-C
N = int(input())
A = list(map(int, input().split()))

def gcd(x, y):
    while y:
        x, y = y, x%y
    return x

ans_gcd = -1

for i in range(N):
    check_gcd = -1
    for j in range(N):
#         print("i, j", i, j)
        if i == j:
            continue
        elif check_gcd == -1:
            check_gcd = A[j]
#             print("check_gcd", check_gcd)
        else:
            check_gcd = gcd(check_gcd, A[j])
#     print("i", i, "ans", ans_gcd, "check", check_gcd)
    ans_gcd = max(ans_gcd, check_gcd)
    
print(ans_gcd)

Fixed submission:
#ABC-125-C
N = int(input())
A = list(map(int, input().split())) #[0, 1, 2, ..., N-2, N-1]
L = [0] * N #L[0]とL[N-1]は0から変わらない。N=5なら実行終了時にL=[*0*,a,b,c,*0*]となる。
R = [0] * N #R[0]とR[N-1]は0から変わらない。N=5なら実行終了時にR=[*0*,f,e,d,A[4]]となる。

def gcd(x, y):
    while y:
        x, y = y, x%y
    return x

ans_gcd = -1

#Lから埋める
L[0] = A[0]
check_gcd = L[0]
for i in range(1, N-1): #N=5のときはi=1~3を実施して最終的にL=[0,a,b,c,0]となる。
    check_gcd = gcd(check_gcd, A[i])
    L[i] = check_gcd

#Rを埋める
R[-1] = A[-1]
check_gcd = R[-1]
for i in reversed(range(1, N-1)):#N=5のときはi=3~1を実施して最終的にR=[0,f,e,d,0]となる。
    check_gcd = gcd(check_gcd, A[i])
    R[i] = check_gcd

#端以外を書き換えの対象とした場合の最大公約数のMaxを探す。
for i in range(1, N-1):
    m = gcd(L[i-1], R[i+1])
    ans_gcd = max(ans_gcd, m)

#端と比べて最終的な答えを出す。N>2のときは数字が低い方を消すだけ。
if N > 2:
    ans_gcd = max(ans_gcd, gcd(A[-2], L[N-3]), gcd(A[1], R[2]))
else:
    ans_gcd = max(A)

print(ans_gcd)
Buggy python submission (verdict: Time Limit Exceeded):
N, Q = map(int, input().split())
S = input()

for _ in range(Q):
    l, r = map(int, input().split())
    S_tmp = S[l-1:r]
    S_tmp = S_tmp.replace("AC", "@")
    print(S_tmp.count("@"))


Fixed submission:
N, Q = map(int, input().split())
S = input()
memo = [0]*N
tmp = 0
for i in range(1, len(S)):
    if S[i-1] == "A" and S[i] == "C":
        tmp += 1
        memo[i] = tmp
    else:
        memo[i] = tmp

for _ in range(Q):
    li, ri = map(int, input().split())
    ans = memo[ri-1] - memo[li-1]
    print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
N, Q = map(int, input().split())
S = input()

for _ in range(Q):
    li, ri = map(int, input().split())
    sliced_S = str(S[li-1:ri])
    sliced_S = sliced_S.replace("AC", "@")
    print(sliced_S.count("@"))


Fixed submission:
N, Q = map(int, input().split())
S = input()
memo = [0]*N
tmp = 0
for i in range(1, len(S)):
    if S[i-1] == "A" and S[i] == "C":
        tmp += 1
        memo[i] = tmp
    else:
        memo[i] = tmp

for _ in range(Q):
    li, ri = map(int, input().split())
    ans = memo[ri-1] - memo[li-1]
    print(ans)
Buggy python submission (verdict: Runtime Error):
N = int(input())
XYH = []

for _ in range(N):
    xi, yi, hi = map(int, input().split())
    XYH.append((xi, yi, hi))
    
assert False

Fixed submission:
def dist(a, b, x, y, h):
    return h + abs(a - x) + abs(b - y)

N = int(input())
P = []
for i in range(N):
    x, y, h = map(int, input().split())
    P.append([h, x, y])
P.sort(reverse = True)

for i in range(101):
    for j in range(101):
        H = dist(i, j, P[0][1], P[0][2], P[0][0])
        for p in P[1:]:
            if max(H - abs(p[1]-i)-abs(p[2]-j), 0) != p[0]:
                break
        else:
            print(i, j, H)
            break
Buggy python submission (verdict: Time Limit Exceeded):
S = input()
T = input()
N = len(S)
done_alphabets = []

for i in range(N):
    if S[i] in done_alphabets:
        continue
    if S[i] != T[i]:
        memo_char_num = []
        for j in range(i+1, N):
            if T[j] == T[i]:
                memo_char_num.append(j)
        for k in range(i+1, N):
            if k in memo_char_num:
                if S[i] != S[k]:
                    print("No")
                    quit()
            else:
                if S[i] == S[k]:
                    print("No")
                    quit()
        done_alphabets.append(S[i])
        done_alphabets.append(T[i])

print("Yes")


Fixed submission:
S = input()
T = input()
N = len(S)

memo_s = {"a":-1,"b":-1,"c":-1,"d":-1,"e":-1,"f":-1,"g":-1,"h":-1,"i":-1,"j":-1,"k":-1,"l":-1,"m":-1,"n":-1,"o":-1,"p":-1,"q":-1,"r":-1,"s":-1,"t":-1,"u":-1,"v":-1,"w":-1,"x":-1,"y":-1,"z":-1}
memo_t = {"a":-1,"b":-1,"c":-1,"d":-1,"e":-1,"f":-1,"g":-1,"h":-1,"i":-1,"j":-1,"k":-1,"l":-1,"m":-1,"n":-1,"o":-1,"p":-1,"q":-1,"r":-1,"s":-1,"t":-1,"u":-1,"v":-1,"w":-1,"x":-1,"y":-1,"z":-1}

for i in range(N):
    if memo_s[S[i]] == -1 and memo_t[T[i]] == -1:
        memo_s[S[i]] = T[i]
        memo_t[T[i]] = S[i]
    else:
        if memo_s[S[i]] != T[i] or memo_t[T[i]] != S[i]:
            print("No")
            quit()

print("Yes")
Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np
import collections

N = int(input())
A = list(map(int, input().split()))
ans = 10**18
dists_A2i = []

for i in range(1, N+1):
    dist_A2i = A[i-1] - i
    dists_A2i.append(dist_A2i)

c = collections.Counter(dists_A2i)

max_c_list = [key for key, value in c.items() if value == max(c.values())]

dists_A2i = np.array(dists_A2i)

for max_c in max_c_list:
    check_dists_A2i = abs(dists_A2i - max_c)
    ans = min(ans, sum(check_dists_A2i))

print(ans)

Fixed submission:
import numpy as np
import collections

N = int(input())
A = list(map(int, input().split()))
ans = 0
dists_A2i = []

for i in range(1, N+1):
    dist_A2i = A[i-1] - i
    dists_A2i.append(dist_A2i)

dists_A2i = np.array(dists_A2i)
dists_median = np.median(dists_A2i)
dists_A2i = abs(dists_A2i - dists_median)
ans = sum(dists_A2i)
print(int(ans))
Buggy python submission (verdict: Runtime Error):
S = input()
ans = 0

for char in S:
    if char = "+":
        ans += 1
    else:
        ans -= 1

print(ans)

Fixed submission:
S = input()
ans = 0

for char in S:
    if char == "+":
        ans += 1
    else:
        ans -= 1

print(ans)