Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
N, M = map(int, input().split())
a = [0]*M
b = [0]*M
c = [0]*M
for i in range(M):
    a[i], b[i] = map(int, input().split())
    cc = list(map(int, input().split()))
    for ccc in cc:
        ccc -= 1
        c[i] += (1 << ccc)

INF = float('inf')
dp = [[INF]*5000 for _ in range(M+1)]
dp[0][0] = 0

for i in range(M):
    for j in range((1 << N)):
        dp[i+1][j] = min(dp[i+1][j], dp[i][j])
        nj = j | c[i]
        dp[i+1][nj] = min(dp[i+1][nj], dp[i][j] + a[i])
if dp[M][(1 << N)-1] == INF:
    print(-1)
else:
    print(dp[M][(1 << N)-1])


Fixed submission:
N, M = map(int, input().split())
a = [0]*M
b = [0]*M
c = [0]*M
for i in range(M):
    a[i], b[i] = map(int, input().split())
    cc = list(map(int, input().split()))
    for ccc in cc:
        ccc -= 1
        c[i] += (1 << ccc)

INF = float('inf')
dp = [[INF]*5000 for _ in range(M+1)]
dp[0][0] = 0

for i in range(M):
    for j in range((1 << N)):
        dp[i+1][j] = min(dp[i+1][j], dp[i][j])
        nj = j | c[i]
        dp[i+1][nj] = min(dp[i+1][nj], dp[i][j] + a[i])
if dp[M][(1 << N)-1] == INF:
    print(-1)
else:
    print(dp[M][(1 << N)-1])
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
S = input()
ans = 0
for d in range(n):
    cnt = 0
    for i in range(n-d):
        if S[i] == S[d+i]:
            cnt += 1
        else:
            cnt = 0
        ans = max(ans, min(cnt, d))
print(ans)


Fixed submission:
n = int(input())
S = input()
ans = 0
for d in range(n):
    cnt = 0
    for i in range(n-d):
        if S[i] == S[d+i]:
            cnt += 1
        else:
            cnt = 0
        ans = max(ans, min(cnt, d))
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
S = input()
ans = 0
cnt = 0
for d in range(n):
    for i in range(n-d):
        if S[i] == S[d+i]:
            cnt += 1
        else:
            cnt = 0
        ans = max(ans, min(cnt, d))
print(ans)


Fixed submission:
n = int(input())
S = input()
ans = 0
for d in range(n):
    cnt = 0
    for i in range(n-d):
        if S[i] == S[d+i]:
            cnt += 1
        else:
            cnt = 0
        ans = max(ans, min(cnt, d))
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
N,Q = map(int,input().split())
import sys
sys.setrecursionlimit(10**7)
tree = [[] for _ in range(N)]

for i in range(N-1):
    x,y = map(int,input().split())
    x -= 1
    y -= 1
    tree[y].append(x)
    tree[x].append(y)
ans = [0]*N
for i in range(Q):
    x,y = map(int,input().split())
    ans[x-1] += y


def dfs(cur,par):
    for chl in tree[cur]:
        if chl == par: #これで木の流れの逆行を防ぐ
            continue
        ans[chl] += ans[cur]
        dfs(chl,cur)

dfs(0,-1)
print(*ans)

Fixed submission:
n,q=map(int,input().split())
ab=[]
for i in range(n-1):
	x,y=map(int,input().split())
	ab.append([x,y])
ab.sort()
ans=[0]*n
cnt=[0]*n
for i in range(q):
	x,y=map(int,input().split())
	ans[x-1]+=y
for i in range(n-1):
	ans[ab[i][1]-1]+=ans[ab[i][0]-1]
print(*ans)

Buggy python submission (verdict: Runtime Error):
N,Q = map(int,input().split())

tree = [[0]*N for _ in range(N)]

for i in range(N-1):
    x,y = map(int,input().split())
    x -= 1
    y -= 1
    tree[y].append(x)
    tree[x].append(y)
ans = [0]*N
for i in range(Q):
    x,y = map(int,input().split())
    ans[x-1] += y
    

def dfs(cur,par):
    for chl in tree[cur]:
        if chl == par: #これで木の流れの逆行を防ぐ
            continue
        ans[chl] += ans[cur]
        dfs(chl,cur)
    
dfs(0,-111111)
print(*ans)

Fixed submission:
n,q=map(int,input().split())
ab=[]
for i in range(n-1):
	x,y=map(int,input().split())
	ab.append([x,y])
ab.sort()
ans=[0]*n
cnt=[0]*n
for i in range(q):
	x,y=map(int,input().split())
	ans[x-1]+=y
for i in range(n-1):
	ans[ab[i][1]-1]+=ans[ab[i][0]-1]
print(*ans)

Buggy python submission (verdict: Runtime Error):
N,Q = map(int,input().split())
ab = []
for i in range(n-1):
    x,y = map(int,input().split())
    ab.append([x,y])
ab.sort()
ans = [0]*N
for i in range(Q):
    x,y = map(int,input().split())
    ans[x-1] += y
for i in range(N-1):
    ans[ab[i][1]-1] += ans[ab[i][1] - 1]
print(*ans)

Fixed submission:
n,q=map(int,input().split())
ab=[]
for i in range(n-1):
	x,y=map(int,input().split())
	ab.append([x,y])
ab.sort()
ans=[0]*n
cnt=[0]*n
for i in range(q):
	x,y=map(int,input().split())
	ans[x-1]+=y
for i in range(n-1):
	ans[ab[i][1]-1]+=ans[ab[i][0]-1]
print(*ans)

Buggy python submission (verdict: Runtime Error):
N,Q = map(int,input().split())
adjacent_list = [[] for _ in range(N+1)]
for _ in range(N-1):
    a,b = map(int,input().split())
    adjacent_list[a].append(b)
cnt = [0]*(N+1)
def dfs(v,x):
    cnt[v] += x
    for nv in adjacent_list[v]:
        dfs(nv,x)

for q in range(Q):
    p,x = map(int,input().split())
    dfs(p,x)
print(*cnt[1:])

Fixed submission:
n,q=map(int,input().split())
ab=[]
for i in range(n-1):
	x,y=map(int,input().split())
	ab.append([x,y])
ab.sort()
ans=[0]*n
cnt=[0]*n
for i in range(q):
	x,y=map(int,input().split())
	ans[x-1]+=y
for i in range(n-1):
	ans[ab[i][1]-1]+=ans[ab[i][0]-1]
print(*ans)
Buggy python submission (verdict: Time Limit Exceeded):

def verify_anagrams(w1, w2):
    f = lambda y: "".join(sorted(map(lambda x: x.replace(' ', '').lower(), y)))
    return f(w1) == f(w2)
#print(verify_anagrams(s,s2))
N = int(input())
ans = 0
words = [input() for _ in range(N)]
for i in range(N):
    for j in range(i+1,N):
        if verify_anagrams(words[i],words[j]):
            ans += 1
print(ans)

Fixed submission:

def verify_anagrams(w1, w2):
    f = lambda y: "".join(sorted(map(lambda x: x.replace(' ', '').lower(), y)))
    return f(w1) == f(w2)
#print(verify_anagrams(s,s2))
N = int(input())
ans = 0
unmatch_words = []
words = {}
for i in range(N):
    s = input()
    sorted_s = "".join(sorted(s))
    #print(sorted_s)
    if sorted_s in words:
        ans += words[sorted_s]
        words[sorted_s] += 1
    else:
        words[sorted_s] = 1


print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
s = input()
l = len(s)
MOD = 10**9+7
dp = [[0]*13 for _ in range(100005)]
dp[0][0] = 1
for i in range(l):

    c = -1 if s[i] == '?' else int(s[i])
    for j in range(10):
        if c != -1 and c != j:
            continue
        for r in range(13):
            dp[i+1][(10*r+j)%13] += dp[i][r]
    for k in range(13):
        dp[i+1][k] %= MOD
print(dp[l][5])

Fixed submission:
s = input()
l = len(s)
MOD = 10**9+7
dp = [[0]*13 for _ in range(100005)]
dp[0][0] = 1
for i in range(l):

    c = -1 if s[i] == '?' else int(s[i])
    for j in range(10):
        if c != -1 and c != j:
            continue
        for r in range(13):
            dp[i+1][(10*r+j)%13] += dp[i][r]
    for k in range(13):
        dp[i+1][k] %= MOD
print(dp[l][5])
Buggy python submission (verdict: Time Limit Exceeded):
import sys
sys.setrecursionlimit(10**6)
input = sys.stdin.readline
MOD = 10**9+7
N,K = map(int,input().split())
edge = [[] for _ in range(N)]
for i in range(N-1):
    a,b = map(int,input().split())
    a -= 1
    b -= 1
    edge[a].append(b)
    edge[b].append(a)

ans = 1
def dfs(now, par,num):
    global ans
    ans = ans*num%MOD
    num = K-1
    if par != -1:
        num -= 1
    for ch in edge[now]:
        if ch != par:
            dfs(ch,now,num)
            num -= 1

dfs(0,-1,K)
print(ans)

Fixed submission:
import sys
sys.setrecursionlimit(10**6)
input = sys.stdin.readline
MOD = 10**9+7
N,K = map(int,input().split())
edge = [[] for _ in range(N)]
for i in range(N-1):
    a,b = map(int,input().split())
    a -= 1
    b -= 1
    edge[a].append(b)
    edge[b].append(a)

ans = 1
def dfs(now, par,num):
    global ans
    ans = ans*num%MOD
    num = K-1
    if par != -1:
        num -= 1
    for ch in edge[now]:
        if ch != par:
            dfs(ch,now,num)
            num -= 1

dfs(0,-1,K)
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import sys
sys.setrecursionlimit(10**6)
MOD = 10**9+7
N,K = map(int,input().split())
edge = [[] for _ in range(N)]
for i in range(N-1):
    a,b = map(int,input().split())
    a -= 1
    b -= 1
    edge[a].append(b)
    edge[b].append(a)

ans = 1
def dfs(now, par,num):
    global ans
    ans = ans*num%MOD
    num = K-1
    if par != -1:
        num -= 1
    for ch in edge[now]:
        if ch != par:
            dfs(ch,now,num)
            num -= 1

dfs(0,-1,K)
print(ans)

Fixed submission:
import sys
sys.setrecursionlimit(10**6)
input = sys.stdin.readline
MOD = 10**9+7
N,K = map(int,input().split())
edge = [[] for _ in range(N)]
for i in range(N-1):
    a,b = map(int,input().split())
    a -= 1
    b -= 1
    edge[a].append(b)
    edge[b].append(a)

ans = 1
def dfs(now, par,num):
    global ans
    ans = ans*num%MOD
    num = K-1
    if par != -1:
        num -= 1
    for ch in edge[now]:
        if ch != par:
            dfs(ch,now,num)
            num -= 1

dfs(0,-1,K)
print(ans)

Buggy python submission (verdict: Runtime Error):
MOD = 10**9+7
N,K = map(int,input().split())
edge = [[] for _ in range(N)]
for i in range(N-1):
    a,b = map(int,input().split())
    a -= 1
    b -= 1
    edge[a].append(b)
    edge[b].append(a)

ans = 1
def dfs(now, par,num):
    global ans
    ans = ans*num%MOD
    num = K-1
    if par != -1:
        num -= 1
    for ch in edge[now]:
        if ch != par:
            dfs(ch,now,num)
            num -= 1

dfs(0,-1,K)
print(ans)

Fixed submission:
import sys
sys.setrecursionlimit(10**6)
input = sys.stdin.readline
MOD = 10**9+7
N,K = map(int,input().split())
edge = [[] for _ in range(N)]
for i in range(N-1):
    a,b = map(int,input().split())
    a -= 1
    b -= 1
    edge[a].append(b)
    edge[b].append(a)

ans = 1
def dfs(now, par,num):
    global ans
    ans = ans*num%MOD
    num = K-1
    if par != -1:
        num -= 1
    for ch in edge[now]:
        if ch != par:
            dfs(ch,now,num)
            num -= 1

dfs(0,-1,K)
print(ans)
Buggy python submission (verdict: Runtime Error):
import math

A,B,C,D = map(int,input().split())
lcm = C*D/math.gcd(C,D)
def c_in_a2b(c):
    return (math.ceil(B//c) - math.floor(A//c) + 1)
print(int((B-A+1)- c_in_a2b(C)-c_in_a2b(D)+c_in_a2b(lcm)))


Fixed submission:
import fractions

a, b, c, d = map(int, input().split())

lcm = c*d // fractions.gcd(c,d)


b_num = b - (b//c + b//d - b//lcm)
a_num = a-1 - (a-1)// c - (a-1)//d + (a-1) // lcm

ans = b_num - a_num
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
A,B,C,D = map(int,input().split())
cnt = 0
for num in range(A,B+1):
    if num%C != 0 and num%D != 0:
        cnt += 1
print(cnt)

Fixed submission:
import fractions

a, b, c, d = map(int, input().split())

lcm = c*d // fractions.gcd(c,d)


b_num = b - (b//c + b//d - b//lcm)
a_num = a-1 - (a-1)// c - (a-1)//d + (a-1) // lcm

ans = b_num - a_num
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
N, M = map(int, input().split())
S = list(map(int, input().split()))
T = list(map(int, input().split()))
MOD = 10**9 + 7
dp = [[0] * (M + 2) for _ in range(N + 2)]
sdp = [[0] * (M + 2) for _ in range(N + 2)]
dp[0][0] = 1
sdp[1][1] = 1
for i in range(N + 1):
    for j in range(M + 1):
        if i - 1 >= 0 and j - 1 >= 0 and S[i - 1] == T[j - 1]:
            dp[i][j] = sdp[i][j]
        sdp[i + 1][j + 1] = sdp[i + 1][j] + sdp[i][j + 1] - sdp[i][j] + dp[i][j]
        sdp[i + 1][j + 1] %= MOD
        sdp[i + 1][j + 1] %= MOD
print(sdp[N + 1][M + 1])


Fixed submission:
# dp[i][j] SとTの最後の文字を採用するような文字列の個数。これにより各DPテーブルの値が排反になる。元の文字列の最後を必ず採用するので
N, M = map(int, input().split())
S = list(map(int, input().split()))
T = list(map(int, input().split()))
MOD = 10**9 + 7
dp = [[0] * (M + 2) for _ in range(N + 2)]
sdp = [[0] * (M + 2) for _ in range(N + 2)]
dp[0][0] = 1
sdp[1][1] = 1
for i in range(N + 1):
    for j in range(M + 1):
        if i - 1 >= 0 and j - 1 >= 0 and S[i - 1] == T[j - 1]:
            dp[i][j] = sdp[i][j]
        sdp[i + 1][j + 1] = sdp[i + 1][j] + sdp[i][j + 1] - sdp[i][j] + dp[i][j]
        sdp[i + 1][j + 1] %= MOD
        sdp[i + 1][j + 1] %= MOD
print(sdp[N + 1][M + 1])
Buggy python submission (verdict: Runtime Error):
import numpy as np
BIG_NUM = 10**9+7
def stairs_n(n):
    if n <= 3:
        return n
    else:
        return stairs_n(n-1)+stairs_n(n-2)

#print(stairs_n(30))

n,m = map(int,input().split())

if m == 0:
    print(stairs_n(n)%BIG_NUM)
else:


    a_list = [int(input()) for _ in range(m)]
    a_list.append(n)
    a_list.insert(0,1)
    a_np = np.array(a_list)
    diff_a_np = np.diff(a_np)-1
    ans = 1
    # print(a_np)
    # print(diff_a_np)
    for num in diff_a_np:
        ans *= stairs_n(num)

    print(ans%BIG_NUM)

Fixed submission:
N, M = map(int,input().split())
dp = [0]*(N+1)
broke = [0]*(N+1)
dp[0] = 1
dp[1] = 1

for _ in range(M):
    a = int(input())
    broke[a] = -1

for i in range(N-1):
    if broke[i] != -1 and broke[i+1] != -1:
        dp[i+2] = dp[i+1] + dp[i]
    elif broke[i] == -1and broke[i+1] != -1:
        dp[i+2] = dp[i+1]
    elif broke[i+1] == -1and broke[i] != -1:
        dp[i+2] = dp[i]
    else:
        print(0)
        exit()
# print(broke)
# print(dp)
MOD = 10**9+7
print(dp[N]%MOD)

Buggy python submission (verdict: Runtime Error):
import numpy as np
BIG_NUM = 10**9+7
def stairs_n(n):
    if n <= 3:
        return n
    else:
        return stairs_n(n-1)+stairs_n(n-2)

#print(stairs_n(30))

n,m = map(int,input().split())

if m == 0:
    print(stairs_n(n)%BIG_NUM)
else:


    a_list = [int(input()) for _ in range(m)]
    a_list.append(n)
    a_np = np.array(a_list)
    diff_a_np = np.diff(a_np)-1
    ans = 1
    # print(a_np)
    # print(diff_a_np-1)
    ans *= (a_list[0])
    for num in diff_a_np:
        ans *= stairs_n(num)

    print(ans%BIG_NUM)

Fixed submission:
N, M = map(int,input().split())
dp = [0]*(N+1)
broke = [0]*(N+1)
dp[0] = 1
dp[1] = 1

for _ in range(M):
    a = int(input())
    broke[a] = -1

for i in range(N-1):
    if broke[i] != -1 and broke[i+1] != -1:
        dp[i+2] = dp[i+1] + dp[i]
    elif broke[i] == -1and broke[i+1] != -1:
        dp[i+2] = dp[i+1]
    elif broke[i+1] == -1and broke[i] != -1:
        dp[i+2] = dp[i]
    else:
        print(0)
        exit()
# print(broke)
# print(dp)
MOD = 10**9+7
print(dp[N]%MOD)
Buggy python submission (verdict: Runtime Error):
N, M = map(int,input().split())
connections=[]
for _ in range(M):
    connections.append(list(map(int,input().split())))
conditions = list(map(int,input.split()))

ans_cnt = 0
for i in range(2**N):
    condition_cnt = 0
    for j in range(M):

        cnt=0
        for k in connections[j][1:]:
            if (i >> k) & 1:
                cnt += 1
        if (cnt +conditions[j])%2 == 0:
            condition_cnt += 1
    if condition_cnt == M:
        ans_cnt += 1

print(ans_cnt)


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

conditions = [list(map(int,input().split())) for _ in range(M)]
p = list(map(int,input().split()))

ans = 0
for i in range(2**N):
    light_cnt = 0
    for condition_idx in range(M):


        switch_num = 0
        for j in range(N):
            if i >> j & 1 and j+1 in conditions[condition_idx][1:]: # つながっているスイッチの押してあるものを数える
                switch_num += 1
        if switch_num%2 == p[condition_idx]:
            light_cnt += 1
    if light_cnt == M:
        ans += 1
print(ans)

Buggy python submission (verdict: Runtime Error):
N, M = map(int,input().split())
connections=[]
for _ in range(M):
    connections.append(list(map(int,input().split())))
conditions = list(map(int,input.split()))

ans_cnt = 0
for i in range(2**N):
    condition_cnt = 0
    for j in range(M):

        cnt=0
        for k in connections[j][1:]:
            if (i >> k) & 1):
                cnt += 1
        if (cnt +conditions[j])%2 == 0:
            condition_cnt += 1
    if condition_cnt == M:
        ans_cnt += 1

print(ans_cnt)


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

conditions = [list(map(int,input().split())) for _ in range(M)]
p = list(map(int,input().split()))

ans = 0
for i in range(2**N):
    light_cnt = 0
    for condition_idx in range(M):


        switch_num = 0
        for j in range(N):
            if i >> j & 1 and j+1 in conditions[condition_idx][1:]: # つながっているスイッチの押してあるものを数える
                switch_num += 1
        if switch_num%2 == p[condition_idx]:
            light_cnt += 1
    if light_cnt == M:
        ans += 1
print(ans)
Buggy python submission (verdict: Runtime Error):
N,M = map(int,input().split())
A= list(map(int,input().split()))
BC=[list(map(int,input().split())) for _ in M]
A.sort()
BC.sort(key=lambda x:-x[1])
i = 0
for B,C in BC:
    for j in range(i,min(N,i+B)):
        if A[j]<C:A[j]=C
    i = i+B
print(sum(A))


Fixed submission:
a,b=map(int,input().split())
if a >= 13:
    print(b)
elif 6<=a<=12:
    print(int(b/2))
else:
    print("0")
Buggy python submission (verdict: Runtime Error):
N, K = map(int,input().split())
from math import ceil, log2
m_list = [ceil(log2(K/(n+1))) if n+1<K else 0 for n in range(N)]
#print(m_list) #各nに対し勝つのに必要な表の数

#
# m_list = []
# for n in range(N):
#     if n+1 >=

def calc_prob(x):
    return (1/2)**x

#prob_list = list(map(calc_prob,m_list))

# Kより大きいインデックスのところは1に書き換え
#print(prob_list)
print(sum(prob_list)/N)


Fixed submission:
N, K = map(int,input().split())
from math import ceil, log2
m_list = [ceil(log2(K/(n+1))) if n+1<K else 0 for n in range(N)]
#print(m_list) #各nに対し勝つのに必要な表の数

#
# m_list = []
# for n in range(N):
#     if n+1 >=

def calc_prob(x):
    return (1/2)**x

prob_list = list(map(calc_prob,m_list))

# Kより大きいインデックスのところは1に書き換え
#print(prob_list)
print(sum(prob_list)/N)
Buggy python submission (verdict: Runtime Error):
N = int(input())
adjacent_list = [[] for _ in range(N)]
for _ in range(N-1):
    u, v, w = map(int,input().split())
    u -= 1
    v -= 1
    adjacent_list[u].append([v, w])
    adjacent_list[v].append([u, w])


colors = [-1]*N


def dfs(v, color):
    if colors[v] != -1:
        return
    colors[v] = color
    for adjacent_v in adjacent_list[v]:
        if adjacent_v[1] % 2 == 0:
            dfs(adjacent_v[0], color)
        else:
            dfs(adjacent_v[0], 1-color)

dfs(0,0)

#print(*colors)
for i in range(N):
    print(colors[i])


Fixed submission:
import sys
sys.setrecursionlimit(10**9)
N = int(input())
adjacent_list = [[] for _ in range(N)]
for _ in range(N-1):
    u, v, w = map(int,input().split())
    u -= 1
    v -= 1
    adjacent_list[u].append([v, w])
    adjacent_list[v].append([u, w])


colors = [-1]*N


def dfs(v, color):
    if colors[v] != -1:
        return
    colors[v] = color
    for adjacent_v in adjacent_list[v]:
        if adjacent_v[1] % 2 == 0:
            dfs(adjacent_v[0], color)
        else:
            dfs(adjacent_v[0], 1-color)

dfs(0,0)

#print(*colors)
for i in range(N):
    print(colors[i])
Buggy python submission (verdict: Runtime Error):
N = int(input())
divisors = []
for i in range(1,int(N**0.5)+1):
    #print(i)
    if N%i == 0:
        divisors.append(i)
        divisors.append(N//i)
divisors.remove(1)
#print(divisors)
ds = set(divisors)
ans = 0
for div in ds:

    if N//(div-1) == N%(div-1):
        ans += div-1
print(ans)

Fixed submission:
N = int(input())
divisors = []
for i in range(1,int(N**0.5)+1):
    #print(i)
    if N%i == 0:
        divisors.append(i)
        divisors.append(N//i)
divisors.remove(1)
ds = set(divisors)
ans = 0
for div in ds:
    if div == 1:
        continue

    if N//(div-1) == N%(div-1):
        ans += div-1
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
import fractions
import copy

n = int(input())
a = list(map(int,input().split()))
nlist = []

def calc_gcd(list):
    ans = list[0]
    for i in range(1,n-1):
        ans = fractions.gcd(ans,list[i])
    return ans

#a = [1,2,3,4,5,6,7]

for j in range(n):
    b= copy.copy(a)
    b.pop(j)
    nlist.append(calc_gcd(b))

#print(nlist)
print(max(nlist))
#
# print(calc_gcd([16,100,4000]))

Fixed submission:
N = int(input())
A = list(map(int,input().split()))
lgcd = [0]*N
rgcd = [0]*N
from fractions import gcd
#def gcd(a,b):
#    if b == 0:return a
#    else:return gcd(b, a%b)

temp_lgcd = A[0]
for i in range(N):
    temp_lgcd = gcd(temp_lgcd,A[i])
    lgcd[i] = temp_lgcd

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

ans = 0
for i in range(N):
    if i == 0:
        calc_gcd = rgcd[1]
    elif i == N-1:
        calc_gcd = lgcd[-2]
    else:
        calc_gcd = gcd(lgcd[i-1],rgcd[i+1])
    ans = max(ans,calc_gcd)
print(ans)

Buggy python submission (verdict: Runtime Error):
import sympy as sp
import copy

n = int(input())
a = list(map(int,input().split()))
nlist = []

def calc_gcd(list):
    ans = list[0]
    for i in range(1,n-1):
        ans = sp.gcd(ans,list[i])
    return ans

#a = [1,2,3,4,5,6,7]

for j in range(n):
    b= copy.copy(a)
    b.pop(j)
    nlist.append(calc_gcd(b))

#print(nlist)
print(max(nlist))

Fixed submission:
N = int(input())
A = list(map(int,input().split()))
lgcd = [0]*N
rgcd = [0]*N
from fractions import gcd
#def gcd(a,b):
#    if b == 0:return a
#    else:return gcd(b, a%b)

temp_lgcd = A[0]
for i in range(N):
    temp_lgcd = gcd(temp_lgcd,A[i])
    lgcd[i] = temp_lgcd

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

ans = 0
for i in range(N):
    if i == 0:
        calc_gcd = rgcd[1]
    elif i == N-1:
        calc_gcd = lgcd[-2]
    else:
        calc_gcd = gcd(lgcd[i-1],rgcd[i+1])
    ans = max(ans,calc_gcd)
print(ans)
Buggy python submission (verdict: Runtime Error):
nlist = [int(input()) for i in range(5)]
#print(nlist)
total_time=0
tail=[]
for number in nlist:
    if number % 10 == 0:
        total_time += number
    else:
        total_time += (number+10-(number%10))
        tail.append(number%10)

total_time -= (10-min(tail))
print(total_time)


Fixed submission:
nlist = [int(input()) for i in range(5)]
#print(nlist)
total_time=0
tail=[]
for number in nlist:
    if number % 10 == 0:
        total_time += number
    else:
        total_time += (number+10-(number%10))
        tail.append(number%10)
if tail:
    total_time -= (10-min(tail))
print(total_time)
Buggy python submission (verdict: Runtime Error):
wlist = list(input())
wlength = 0

for w in wlist:
    if not w in ["A","T","G","C"]:
        tmp = 0
        continue

    else:
        tmp += 1
        if tmp >= wlength:
            wlength = tmp
print(wlength)




Fixed submission:
wlist = list(input())
wlength = 0
tmp = 0
for w in wlist:
    if not w in ["A","T","G","C"]:
        tmp = 0
        continue

    else:
        tmp += 1
        if tmp >= wlength:
            wlength = tmp
print(wlength)
Buggy python submission (verdict: Time Limit Exceeded):
n,q = map(int,input().split())
raw_list = list(input())
AC_pos = []
for idx,char in enumerate(raw_list):

    if raw_list[idx] =="A":
        if idx == len(raw_list)-1:
            break
        if raw_list[idx+1] == "C":
            AC_pos.append(idx)
#print(AC_pos)
for i in range(q):
    li, ri = map(int,input().split())
    print(sum(li-1<=x<=ri-2 for x in AC_pos))


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

ac_count = [0]*N
temp = 0
for i in range(1,N):
    if S[i] == 'C' and S[i-1] == 'A':
        temp += 1
        ac_count[i] = temp
    else:
        ac_count[i] = temp
#print(ac_count)
for _ in range(Q):
    l,r = map(int,input().split())
    if S[l-1] != 'C':
        print(ac_count[r-1]-ac_count[l-1])
    else:
        print(ac_count[r-1]-ac_count[l-1])