Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
#create date: 2020-04-19 21:04

import sys
stdin = sys.stdin

def ns(): return stdin.readline().rstrip()
def ni(): return int(ns())
def na(): return list(map(int, stdin.readline().split()))

def main():
    n = ni()
    a = na()
    for i in range(1, n+1):
        print(a.count(i))

if __name__ == "__main__":
    main()


Fixed submission:
#create date: 2020-04-19 21:04

import sys
stdin = sys.stdin

def ns(): return stdin.readline().rstrip()
def ni(): return int(ns())
def na(): return list(map(int, stdin.readline().split()))

def main():
    n = ni()
    a = na()
    ans = [0] * n
    for ai in a:
        ans[ai-1] += 1
    for i in ans:
        print(i)

if __name__ == "__main__":
    main()

Buggy python submission (verdict: Time Limit Exceeded):
#create date: 2020-04-19 21:04

import sys
stdin = sys.stdin

def ns(): return stdin.readline().rstrip()
def ni(): return int(ns())
def na(): return list(map(int, stdin.readline().split()))

def main():
    n = ni()
    a = na()
    for i in range(1, n+1):
        print(a.count(i))

if __name__ == "__main__":
    main()

Fixed submission:
#create date: 2020-04-19 21:04

import sys
stdin = sys.stdin

def ns(): return stdin.readline().rstrip()
def ni(): return int(ns())
def na(): return list(map(int, stdin.readline().split()))

def main():
    n = ni()
    a = na()
    ans = [0] * n
    for ai in a:
        ans[ai-1] += 1
    for i in ans:
        print(i)

if __name__ == "__main__":
    main()
Buggy python submission (verdict: Time Limit Exceeded):
#create date: 2020-04-12 21:15

import sys
stdin = sys.stdin

def ns(): return stdin.readline().rstrip()
def ni(): return int(ns())
def na(): return list(map(int, stdin.readline().split()))

def main():
    n = ni()
    s = ns()
    r = s.count("R")
    g = s.count("G")
    b = s.count("B")
    ans = r*g*b
    for i in range(0, n-2):
        for j in range(1, (n-1)//+1):
            if i + 2*j < n:
                if len(set([s[i], s[i+j], s[i+2*j]]))==3:
                    ans -= 1
    print(ans)

if __name__ == "__main__":
    main()

Fixed submission:
#create date: 2020-04-12 21:15

import sys
stdin = sys.stdin

def ns(): return stdin.readline().rstrip()
def ni(): return int(ns())
def na(): return list(map(int, stdin.readline().split()))

def main():
    n = ni()
    s = ns()
    r = s.count("R")
    g = s.count("G")
    b = s.count("B")
    ans = r*g*b
    for i in range(0, n-2):
        for j in range(1, (n-1)//+1):
            if i + 2*j < n:
                if len(set([s[i], s[i+j], s[i+2*j]]))==3:
                    ans -= 1
    print(ans)

if __name__ == "__main__":
    main()
Buggy python submission (verdict: Runtime Error):
#create date: 2020-07-03 14:00

import sys
stdin = sys.stdin

def ns(): return stdin.readline().rstrip()
def ni(): return int(ns())
def na(): return list(map(int, stdin.readline().split()))

def main():
    def find(x):
        if par[x] < 0:
            return x
        else:
            par[x] = find(par[x])
            return par[x]

    def unite(x, y):
        x = find(x); y = find(y)
        if x == y:
            return False
        else:
            if par[x] > par[y]:
                x, y = y, x
            par[x] += par[y]
            par[y] = x
            return True
    def same(x, y):
        return find(x) == find(y)
    
    n, m, k = na()
    par = [-1] * n
    fb = [[0] * n for i in range(n)]
    for i in range(m):
        a, b = na()
        a -= 1; b -= 1
        unite(a, b)
        fb[a][b] = 1
        fb[b][a] = 1
    for i in range(k):
        c, d = na()
        c -= 1; d -= 1
        fb[c][d] = 1
        fb[d][c] = 1
    #print(par, fb)
    for i in range(n):
        ans = 0
        for j in range(n):
            if same(i, j) and fb[i][j]==0 and i != j:
                ans += 1
        print(ans, end=" ")
if __name__ == "__main__":
    main()

Fixed submission:
#create date: 2020-07-03 14:00

import sys
stdin = sys.stdin

def ns(): return stdin.readline().rstrip()
def ni(): return int(ns())
def na(): return list(map(int, stdin.readline().split()))

def main():
    def find(x):
        if par[x] < 0:
            return x
        else:
            par[x] = find(par[x])
            return par[x]

    def unite(x, y):
        x = find(x); y = find(y)
        if x == y:
            return False
        else:
            if par[x] > par[y]:
                x, y = y, x
            par[x] += par[y]
            par[y] = x
            return True
    def same(x, y):
        return find(x) == find(y)
    def size(x):
        return -par[find(x)]


    n, m, k = na()
    par = [-1] * n
    friend = [0] * n
    block = [list() for i in range(n)]
    for i in range(m):
        a, b = na()
        a -= 1; b -= 1
        unite(a, b)
        friend[a] += 1
        friend[b] += 1
    for i in range(k):
        c, d = na()
        c -= 1; d -= 1
        block[c].append(d)
        block[d].append(c)
    #print(par, fb)
    for i in range(n):
        ans = size(i) - friend[i] - 1
        for b in block[i]:
            if same(i, b):
                ans -= 1
        print(ans, end=" ")
if __name__ == "__main__":
    main()
Buggy python submission (verdict: Time Limit Exceeded):
import sys
stdin = sys.stdin
import math
from operator import mul
from functools import reduce

mod = 10**9 + 7

ns = lambda: stdin.readline().rstrip()
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))

def cmb(n,r):
    r = min(n-r,r)
    if r == 0: return 1
    over = reduce(mul, range(n, n - r, -1))
    under = reduce(mul, range(1,r + 1))
    return over // under

n, a, b = na()
ans = 2**n - 1 - cmb(n, a) - cmb(n, b)
print(ans % mod)

Fixed submission:
import sys
stdin = sys.stdin
from math import factorial

mod = 10**9 + 7

ns = lambda: stdin.readline().rstrip()
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))

n, a, b = na()

def pow(a,n,p=mod):
    bi=str(format(n,"b"))
    res=1
    for i in range(len(bi)):
        res=(res*res) %p
        if bi[i]=="1":
            res=(res*a) %p
    return res
def comb(a, b, p=mod):
    res = 1
    pres = 1
    for i in range(b):
        res = (res*(a-i))%p
        pres = (pres*(i+1))%p
    return res*pow(pres, p-2, p) % p
print((pow(2, n) - 1 - comb(n, a) - comb(n, b))%mod)
Buggy python submission (verdict: Runtime Error):
import sys
import math
import functools
stdin = sys.stdin
mod = 10**9 + 7

ns = lambda: stdin.readline().rstrip()
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
sa = lambda h: [list(map(int, stdin.readline().split())) for i in range(h)]

h, n = na()
a, b = [], []
for _ in range(n):
    ai, bi = na()
    a.append(ai)
    b.append(bi)
inf = 10**9
dp = [[inf]* (10**4+1) for _ in range(n+1)]
for i in range(n):
    for j in range(1, 10**4+1):
        if j < a[i]:
            dp[i+1][j] = min(dp[i][j],((j-1)//a[i]+1)*b[i])
        else:
            dp[i+1][j] = min(dp[i][j],((j-1)//a[i]+1)*b[i], dp[i+1][j - a[i]] + b[i])
print(dp[n][h])



Fixed submission:
import sys
import math
import functools
stdin = sys.stdin
mod = 10**9 + 7

ns = lambda: stdin.readline().rstrip()
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
sa = lambda h: [list(map(int, stdin.readline().split())) for i in range(h)]


h, a = na()
print((h-1)//a+1)
Buggy python submission (verdict: Runtime Error):
import sys
import math
import functools
stdin = sys.stdin
mod = 10**9 + 7

ns = lambda: stdin.readline().rstrip()
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
sa = lambda h: [list(map(int, stdin.readline().split())) for i in range(h)]

def gcd(a, b):
    while b:
        a, b = b, a % b
    return a
def lcm(a, b):
    return a * b // gcd (a, b)
def lcm_n(nums):
    return functools.reduce(lcm, nums)

n = ni()
a = na()
a_lcm = lcm_n(a)
ans = 0
for ai in a:
    ans += a_lcm // ai
ans %= mod
print(ans)


Fixed submission:
import sys
import math
stdin = sys.stdin
mod = 10**9 + 7

ns = lambda: stdin.readline().rstrip()
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
sa = lambda h: [list(map(int, stdin.readline().split())) for i in range(h)]


n, m = na()
print("Yes" if n==m else "No")
Buggy python submission (verdict: Runtime Error):
import sys
import math
import bisect
stdin = sys.stdin
mod = 10**9 + 7

ns = lambda: stdin.readline().rstrip()
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
sa = lambda h: [list(map(int, stdin.readline().split())) for i in range(h)]


n = ni()
p = na()
q = na()
def check(pq):
    ans = factorial(n)
    a = list(range(1,n+1))
    for i in range(n):
        l = n - i
        pqi = pq[i]
        index = a.index(pqi)
        ans -= factorial(max(l-1, 0)) * max(l-index, 0)
        a.remove(pqi)
    return ans
print(abs(check(p) - check(q)))

Fixed submission:
import sys
import math
import bisect
stdin = sys.stdin
mod = 10**9 + 7

ns = lambda: stdin.readline().rstrip()
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
sa = lambda h: [list(map(int, stdin.readline().split())) for i in range(h)]

def factorial(n):
    if n == 1:
        return n
    elif n==0:
        return 0
    return n * factorial(n-1)

n = ni()

p = na()
q = na()
def check(pq):
    ans = factorial(n)
    a = list(range(1,n+1))
    for i in range(n):
        l = n - i
        pqi = pq[i]
        index = a.index(pqi)
        ans -= factorial(max(l-1, 0)) * max(l-index, 0)
        a.remove(pqi)
    return ans
print(abs(check(p) - check(q)))
Buggy python submission (verdict: Time Limit Exceeded):
import sys
import math
stdin = sys.stdin
mod = 10**9 + 7

ns = lambda: stdin.readline().rstrip()
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
sa = lambda h: [list(map(int, stdin.readline().split())) for i in range(h)]

n = ni()
l = na()
l.sort(reverse=True)
c = 0
for ll in range(n):
    for lm in range(ll+1, n):
        for lr in range(lm+1, n):
            if l[ll] < l[lm] + l[lr]:
                c += 1

print(c)


Fixed submission:
import sys
import math
import bisect
stdin = sys.stdin
mod = 10**9 + 7

ns = lambda: stdin.readline().rstrip()
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
sa = lambda h: [list(map(int, stdin.readline().split())) for i in range(h)]

n = ni()
l = na()
l.sort()


c = 0
for i_1 in range(n-2):
    for i_2 in range(i_1+1, n-1):
        m = l[i_1] + l[i_2]
        i_3max = bisect.bisect_left(l, m) - 1
        c += i_3max - i_2

print(c)

Buggy python submission (verdict: Time Limit Exceeded):
import sys
import math
stdin = sys.stdin
mod = 10**9 + 7

ns = lambda: stdin.readline().rstrip()
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
sa = lambda h: [list(map(int, stdin.readline().split())) for i in range(h)]

n = ni()
l = na()
l.sort(reverse=True)
c = 0
for ll in range(n):
    for lm in range(ll+1, n):
        for lr in range(lm+1, n):
            if l[ll] < l[lm] + l[lr]:
                c += 1

print(c)

Fixed submission:
import sys
import math
import bisect
stdin = sys.stdin
mod = 10**9 + 7

ns = lambda: stdin.readline().rstrip()
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
sa = lambda h: [list(map(int, stdin.readline().split())) for i in range(h)]

n = ni()
l = na()
l.sort()


c = 0
for i_1 in range(n-2):
    for i_2 in range(i_1+1, n-1):
        m = l[i_1] + l[i_2]
        i_3max = bisect.bisect_left(l, m) - 1
        c += i_3max - i_2

print(c)
Buggy python submission (verdict: Time Limit Exceeded):
import sys
stdin = sys.stdin
mod = 10**9 + 7

def ns(): return stdin.readline().rstrip()
def ni(): return int(ns())
def na(): return list(map(int, stdin.readline().split()))

N, K, Q = na()
A = [0 for _ in range(N)]
for _ in range(Q):
    a = ni()
    A[a-1] += 1
for i in range(N):
    if sum(A) - A[i] < K:
        print("Yes")
    else:
        print("No")

Fixed submission:
import sys
stdin = sys.stdin
mod = 10**9 + 7

def ns(): return stdin.readline().rstrip()
def ni(): return int(ns())
def na(): return list(map(int, stdin.readline().split()))

N, K, Q = na()
A = [0 for _ in range(N)]
for _ in range(Q):
    a = ni()
    A[a-1] += 1
sumA = sum(A)
for a in A:
    if sumA - a < K:
        print("Yes")
    else:
        print("No")
Buggy python submission (verdict: Runtime Error):
import sys
stdin = sys.stdin

ns = lambda: stdin.readline().rstrip()
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
s = lambda h: [list(map(int, stdin.readline().split())) for i in range(h)]

m, d = na()
if d < 22:
    print(0)
else:
    d10max = int(str(d)[0])
    d1max = int(str(d)[1])
    c = 0
    if d1max < 2:
        for d10 in range(2, int(str(d)[0])):
            for i in range(2, 9):
                if d10 * i <= m:
                    c += 1
    else:
        for d10 in range(2, int(str(d)[0])):
            for i in range(2, 9):
                if d10 * i <= m:
                    c += 1

        for i in range(2, d1max+ 1):
            if d10 * i <= m:
                c += 1
    print(c)




Fixed submission:
import sys
stdin = sys.stdin

ns = lambda: stdin.readline().rstrip()
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
s = lambda h: [list(map(int, stdin.readline().split())) for i in range(h)]

m, d = na()
if d < 22:
    print(0)
else:
    d10max = int(str(d)[0])
    d1max = int(str(d)[1])
    c = 0
    for d10 in range(2, d10max):
        for i in range(2, 10):
            if d10 * i <= m:
                c += 1

    for i in range(2, d1max+ 1):
        if d10max * i <= m:
            c += 1
    print(c)

Buggy python submission (verdict: Runtime Error):
import sys
stdin = sys.stdin

ns = lambda: stdin.readline().rstrip()
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
s = lambda h: [list(map(int, stdin.readline().split())) for i in range(h)]

m, d = na()
if d < 22:
    print(0)
else:
    d10max = int(str(d)[0])
    d1max = int(str(d)[1])
    c = 0
    for d10 in range(2, int(str(d)[0])):
        for i in range(2, 9):
            if d10 * i <= m:
                c += 1

    for i in range(2, d1max+ 1):
        if d10 * i <= m:
            c += 1
    print(c)




Fixed submission:
import sys
stdin = sys.stdin

ns = lambda: stdin.readline().rstrip()
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
s = lambda h: [list(map(int, stdin.readline().split())) for i in range(h)]

m, d = na()
if d < 22:
    print(0)
else:
    d10max = int(str(d)[0])
    d1max = int(str(d)[1])
    c = 0
    for d10 in range(2, d10max):
        for i in range(2, 10):
            if d10 * i <= m:
                c += 1

    for i in range(2, d1max+ 1):
        if d10max * i <= m:
            c += 1
    print(c)
Buggy python submission (verdict: Runtime Error):
import sys
import math
import functools
stdin = sys.stdin
mod = 10**9 + 7
from scipy.special import comb

ns = lambda: stdin.readline().rstrip()
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
sa = lambda h: [list(map(int, stdin.readline().split())) for i in range(h)]

n, k = na()
a = na()
cl = 0
cr = 0
for i in range(n-1):
    for j in range(i+1,n):
        if a[i] < a[j]:
            cl += 1
        if a[i] > a[j]:
            cr += 1
ans = (cr*k %mod + (cl+cr) * comb(k, 2, exact=True)) % mod
print(ans)

Fixed submission:
import sys
import math
import functools
stdin = sys.stdin
mod = 10**9 + 7

ns = lambda: stdin.readline().rstrip()
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
sa = lambda h: [list(map(int, stdin.readline().split())) for i in range(h)]

n, k = na()
a = na()
cl = 0
cr = 0
for i in range(n-1):
    for j in range(i+1,n):
        if a[i] < a[j]:
            cl += 1
        if a[i] > a[j]:
            cr += 1
ans = (cr*k %mod + (cl+cr) * k*(k-1)//2) % mod
print(ans)
Buggy python submission (verdict: Runtime Error):
import sys
stdin = sys.stdin
from itertools import accumulate

ns = lambda: stdin.readline().rstrip()
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))

n = ni()
h = na()
f = h[0]
b = False
for hi in h[1:]:
    if hi > f:
        f = hi
        b = False
    elif hi == f - 1 and not b:
        f = hi
        b = True
    elif hi == f:
        b = True
    else:
        print("No")
        quit()
print("Yes")

Fixed submission:
from itertools import accumulate, permutations, combinations, product, combinations_with_replacement, groupby
from math import floor, ceil, sqrt, factorial, log
from bisect import bisect_left, bisect_right
from collections import Counter, defaultdict
from heapq import heappop, heappush, heappushpop
from itertools import product
import sys
stdin = sys.stdin
mod = 10**9 + 7


def ns(): return stdin.readline().rstrip()


def ni(): return int(ns())


def na(): return list(map(int, stdin.readline().split()))


a, b, c = na()
print(max(b + c - a, 0))
Buggy python submission (verdict: Time Limit Exceeded):
#create date: 2020-07-25 09:13

import sys
stdin = sys.stdin
mod = 10**9+7

def ns(): return stdin.readline().rstrip()
def ni(): return int(ns())
def na(): return list(map(int, stdin.readline().split()))

def main():
    n, m = na()
    a = list()
    for i in range(m):
        a.append(ni())

    dp = [0] * (10**5+1)
    dp[0] = 1
    if not 1 in a: dp[1] = 1
    for i in range(2, n+1):
        if i in a:
            dp[i] = 0
        else:
            dp[i] = (dp[i-2] + dp[i-1]) % mod
    print(dp[n])

if __name__ == "__main__":
    main()

Fixed submission:
#create date: 2020-07-25 09:13

import sys
stdin = sys.stdin
mod = 10**9+7

def ns(): return stdin.readline().rstrip()
def ni(): return int(ns())
def na(): return list(map(int, stdin.readline().split()))

def main():
    n, m = na()
    a = [0] * (10**5+1)
    for i in range(m):
        st = ni()
        a[st] = 1

    dp = [0] * (10**5+1)
    dp[0] = 1
    if a[1] == 0: dp[1] = 1
    for i in range(2, n+1):
        if a[i] == 1:
            dp[i] = 0
        else:
            dp[i] = (dp[i-2] + dp[i-1]) % mod
    print(dp[n])

if __name__ == "__main__":
    main()

Buggy python submission (verdict: Time Limit Exceeded):
#create date: 2020-07-25 09:13

import sys
stdin = sys.stdin
mod = 10**9+7

def ns(): return stdin.readline().rstrip()
def ni(): return int(ns())
def na(): return list(map(int, stdin.readline().split()))

def main():
    n, m = na()
    a = list()
    for i in range(m):
        a.append(ni())

    dp = [0] * (10**5+1)
    dp[0] = 1
    if not 1 in a: dp[1] = 1
    for i in range(2, 10**5+1):
        if i in a:
            dp[i] = 0
        else:
            dp[i] = (dp[i-2] + dp[i-1]) % mod
    print(dp[n])

if __name__ == "__main__":
    main()

Fixed submission:
#create date: 2020-07-25 09:13

import sys
stdin = sys.stdin
mod = 10**9+7

def ns(): return stdin.readline().rstrip()
def ni(): return int(ns())
def na(): return list(map(int, stdin.readline().split()))

def main():
    n, m = na()
    a = [0] * (10**5+1)
    for i in range(m):
        st = ni()
        a[st] = 1

    dp = [0] * (10**5+1)
    dp[0] = 1
    if a[1] == 0: dp[1] = 1
    for i in range(2, n+1):
        if a[i] == 1:
            dp[i] = 0
        else:
            dp[i] = (dp[i-2] + dp[i-1]) % mod
    print(dp[n])

if __name__ == "__main__":
    main()
Buggy python submission (verdict: Runtime Error):
#create date: 2020-07-03 22:02

import sys
stdin = sys.stdin
from itertools import groupby, accumulate

def ns(): return stdin.readline().rstrip()
def ni(): return int(ns())
def na(): return list(map(int, stdin.readline().split()))

def main():
    n, k = na()
    s = ns()
    a = list()
    if s[0] == "0":
        a.append(0)
    gr = groupby(s)
    for key, group in gr:
        a.append(len(list(group)))
    if s[-1] == "0":
        a.append(0)
    acum = list(accumulate(a))
    m = len(acum)
    l = 2*k + 1
    if m == 1:
        print(acum[0])
        quit()
    ans = acum[l-1]
    for i in range(0, m-l+1, 2):
        ans = max(ans, acum[i+l-1] - acum[i-1])
    print(ans)

if __name__ == "__main__":
    main()

Fixed submission:
#create date: 2020-07-03 22:02

import sys
stdin = sys.stdin
from itertools import groupby, accumulate

def ns(): return stdin.readline().rstrip()
def ni(): return int(ns())
def na(): return list(map(int, stdin.readline().split()))

def main():
    n, k = na()
    s = ns()
    a = list()
    if s[0] == "0":
        a.append(0)
    gr = groupby(s)
    for key, group in gr:
        a.append(len(list(group)))
    if s[-1] == "0":
        a.append(0)
    acum = list(accumulate(a))
    m = len(acum)
    l = 2*k + 1
    if m == 1:
        print(acum[0])
        quit()
    if l > m:
        print(acum[-1])
        quit()
    ans = acum[l-1]
    for i in range(0, m-l+1, 2):
        ans = max(ans, acum[i+l-1] - acum[i-1])
    print(ans)

if __name__ == "__main__":
    main()
Buggy python submission (verdict: Runtime Error):
import sys
import math
stdin = sys.stdin
mod = 10**9 + 7

ns = lambda: stdin.readline().rstrip()
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
sa = lambda h: [list(map(int, stdin.readline().split())) for i in range(h)]

l = 9
ans = 0
for _ in range(5):
    num = ni()
    ans += -(-num//10) * 10
    if num % 10 != 0 and l > num % 10:
        l = num % 10
    elif num % 10 == 0:
        l = 10
if l != 0:
    ans += - 10 + l
print(ans)
```‘

Fixed submission:
import sys
import math
import numpy as np
stdin = sys.stdin
mod = 10**9 + 7

ns = lambda: stdin.readline().rstrip()
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
sa = lambda h: [list(map(int, stdin.readline().split())) for i in range(h)]

a = []
for _ in range(5):
    a.append(ni())
a = np.array(a)

m = np.min((a-1)%10+1)
d = (a - 1) // 10 + 1
print(sum(d)*10 + m - 10)
Buggy python submission (verdict: Runtime Error):
import sys
import math
import itertools
stdin = sys.stdin
mod = 10**9 + 7

ns = lambda: stdin.readline().rstrip()
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
sa = lambda h: [list(map(int, stdin.readline().split())) for i in range(h)]

n = ni()
a = na()

ans = a[0]

for ai in a[1:]:
    ans = math.gcd(ans, ai)
print(ans)

Fixed submission:
import sys
import math
import itertools
stdin = sys.stdin
mod = 10**9 + 7

ns = lambda: stdin.readline().rstrip()
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
sa = lambda h: [list(map(int, stdin.readline().split())) for i in range(h)]
#a,bの最大公約数
def gcd(a, b):
    while b:
        a, b = b, a % b
    return a


n = ni()
a = na()

ans = a[0]

for ai in a[1:]:
    ans = gcd(ans, ai)
print(ans)
Buggy python submission (verdict: Runtime Error):
import sys
import math
stdin = sys.stdin
mod = 10**9 + 7

ns = lambda: stdin.readline().rstrip()
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
sa = lambda h: [list(map(int, stdin.readline().split())) for i in range(h)]

n = ni()
h = na()

memo = [-1] * n
memo[1] = abs(h[1] - h[0])

def df(n):
    if n==0:
        return 0
    if n==1:
        return memo[1]
    elif memo[n] != -1:
        return memo[n]
    else:
        memo[n] = min(df(n-2) + abs(h[n] - h[n-2]), df(n-1) + abs(h[n] - h[n-1]))
        return memo[n]

print(df(n-1))

Fixed submission:
import sys
import math
import itertools
stdin = sys.stdin
mod = 10**9 + 7

ns = lambda: stdin.readline().rstrip()
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
sa = lambda h: [list(map(int, stdin.readline().split())) for i in range(h)]

n = ni()
h = na()
dp = [0] * n
dp[1] = abs(h[1] - h[0])
for i in range(2,n):
    op1 = dp[i-2] + abs(h[i-2] - h[i])
    op2 = dp[i-1] + abs(h[i-1] - h[i])
    dp[i] = min(op1, op2)

print(dp[-1])