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

Fixed submission:
import sys
sys.setrecursionlimit(10 ** 6)

n, m = map(int, input().split())
e = [[] for _ in range(n)]

for _ in range(m):
    a, b = map(int, input().split())
    e[a-1].append(b-1)

c = [0] * n
ans = []
def search_path(p, temp):
    c[p] = 1
    for x in e[p]:
        if x in temp:
            print(-99999)
            exit()
        else:
            search_path(x, temp + [x])


t = 1
for i in range(n):
    if c[i] == 0:
        ans = search_path(i, [i])

print(-1)

Buggy submission (verdict: Runtime Error):
n, m = map(int, input().split())
e = [[] for _ in range(n)]

for _ in range(m):
    a, b = map(int, input().split())
    e[a-1].append(b-1)

c = [0] * n
ans = []
def search_path(p, temp):
    c[p] = 1
    for x in e[p]:
        if x in temp:
            print(-99999)
            exit()
        else:
            search_path(x, temp + [x])

t = 1
for i in range(n):
    if c[i] == 0:
        ans = search_path(i, [i])

print(-1)

Buggy submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(10 ** 6)

n, m = map(int, input().split())
e = [[] for _ in range(n)]

for _ in range(m):
    a, b = map(int, input().split())
    e[a-1].append(b-1)

c = [0] * n
ans = []
def search_path(p, temp):
    c[p] = 1
    for x in e[p]:
        if x in temp:
            return temp[temp.index(x):]
        else:
            ret = search_path(x, temp + [x])
            if len(ret) != 0:
                return ret
    return []

t = 1
for i in range(n):
    if c[i] == 0:
        ans = search_path(0, [0])
        if len(ans) != 0:
            break

if len(ans) == 0:
    print(-1)
    exit()

check = 1
while check == 1:
    check = 0
    for i in range(len(ans)-1):
        for x in e[ans[i]]:
            #print(x, ans[:i])
            if x in ans[:i]:
                ans = [] + ans[:i+1]
                check = 1
    for x in e[ans[-1]]:
        if x in ans[1:len(ans)]:
            ans = [] + ans[ans.index(x):]
            check = 1

print(len(ans))
for x in ans:
    print(x+1)

Buggy submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(10 ** 6)

n, m = map(int, input().split())
e = [[] for _ in range(n)]

for _ in range(m):
    a, b = map(int, input().split())
    e[a-1].append(b-1)

c = [0] * n
ans = []
def search_path(p, temp):
    c[p] = 1
    for x in e[p]:
        if x in temp:
            return temp[temp.index(x):]
        else:
            ret = search_path(x, temp + [x])
            if len(ret) != 0:
                return ret
    return []

t = 1
for i in range(n):
    if c[i] == 0:
        ans = search_path(0, [0])
        if len(ans) != 0:
            break

if len(ans) == 0:
    print(-1)
    exit()

check = 1
while check == 1:
    check = 0
    for i in range(len(ans)-1):
        for x in e[ans[i]]:
            #print(x, ans[:i])
            if x in ans[:i]:
                ans = [] + ans[:i+1]
                check = 1
    for x in e[ans[-1]]:
        if x in ans[1:len(ans)]:
            ans = [] + ans[ans.index(x):]
            check = 1

print(len(ans))
for x in ans:
    print(x+1)
Problem p02920 (python)

Fixed submission:
n = int(input())
s = [list(map(int, input().split()))]

s[0].sort(reverse=True)

t = [s[0].pop(0)]
s.append([0 for _ in range(2 ** n - 1)])
a = 0
b = 1
p = 1
q = 2 ** n - 1
for _ in range(n):
    #print(s)
    j = 0
    k = 0
    for i in range(p):
        if j >= q:
            print('No')
            exit()
        #print(i, t, s)
        while t[i] <= s[a][j]:
            s[b][k] = s[a][j]
            j += 1
            k += 1
            if j >= q:
                print('No')
                exit()
        t.append(s[a][j])
        j += 1
    t.sort(reverse=True)

    #print(i, j, q)
    while j < q:
        s[b][k] = s[a][j]
        k += 1
        j += 1
    a, b = b, a
    #print(s)
    q -= p
    p *= 2
print('Yes')

Buggy submission (verdict: Runtime Error):
n = int(input())
s = list(map(int, input().split()))

dp = [[0 for _ in range(2 ** n)] for _ in range(18)]
dp[0] = [] + s

#for x in dp: print(x)

m = (n-1) ** 2
for a in range(n):
    #print(dp[a])
    for i in range(1 << (n-a-1)):
        #print(a, i)
        if dp[a][i*2] == dp[a][i*2+1]:
            print('No')
            exit()
        else:
            dp[a+1][i] = max(dp[a][i*2], dp[a][i*2+1])
    #m //= 2
    #print(dp[a+1])

print('Yes')
Problem p02961 (python)

Fixed submission:
import math

k = int(input())
x, y = map(int, input().split())

if k % 2 == 0 and (x + y) % 2 == 1:
    print(-1)
    exit()

a = 1
b = 1
d = 0
if x < 0:
    x *= -1
    a = -1
if y < 0:
    y *= -1
    b = -1
if x < y:
    d = 1
    x, y = y, x

def show_xy(tx, ty):
    if d == 1:
        print(ty * a, tx * b)
    else:
        print(tx * a, ty * b)

if x + y < k and (x + y) % 2 == 1:
    print(3)
    temp_x = x
    temp_y = x - k
    show_xy(temp_x, temp_y)
    temp_x = x + (k+x-y)//2
    temp_y += k - (k+x-y)//2
    show_xy(temp_x, temp_y)
    temp_x = x
    temp_y = y
    show_xy(temp_x, temp_y)
    exit()

c = (k - ((x + y) % k)) % k
if x + y < k:
    n = 2
else:
    n = math.ceil((x + y) / k) + (c % 2)

print(n)

ans = 0
temp_x = 0
temp_y = 0

temp = - (k * n - x - y) // 2
while 1:
    temp_y -= k
    if temp_y >=  temp:
        show_xy(temp_x, temp_y)
    else:
        temp_x = temp - temp_y
        temp_y = temp
        #print(temp_x * a, temp_y * b)
        break

while temp_x <= x:
    show_xy(temp_x, temp_y)
    temp_x += k

temp_y += temp_x - x
temp_x = x

while temp_y <= y:
    show_xy(temp_x, temp_y)
    temp_y += k

Buggy submission (verdict: Runtime Error):
k = int(input())
x, y = map(int, input().split())

if k % 2 == 0 and (x + y) % 2 == 1:
    print(-1)
    exit()

a = 1
b = 1
d = 0
if x < 0:
    x *= -1
    a = -1
if y < 0:
    y *= -1
    b = -1
if x < y:
    d = 1
    x, y = y, x

def show_xy(tx, ty):
    if d == 1:
        print(ty * a, tx * b)
    else:
        print(tx * a, ty * b)

if x + y < k and (x + y) % 2 == 1:
    f = [0,0]
    print(f[99])
    exit()
    temp_x = x
    temp_y = x - k
    show_xy(temp_x, temp_y)
    temp_x = x + (k+x-y)//2
    temp_y += k - (k+x-y)//2
    show_xy(temp_x, temp_y)
    temp_x = x
    temp_y = y
    show_xy(temp_x, temp_y)
    exit()

c = (k - (x + y) % k) % k
if x + y < k:
    n = 2
else:
    n = (x + y) // k + (c % 2)
    if (x + y) // k != 0:
        n += 1

print(n)

ans = 0
temp_x = 0
temp_y = 0

temp = - (k * n - x - y) // 2
while 1:
    temp_y -= k
    if temp_y >=  temp:
        show_xy(temp_x, temp_y)
    else:
        temp_x = temp - temp_y
        temp_y = temp
        #print(temp_x * a, temp_y * b)
        break

while temp_x <= x:
    show_xy(temp_x, temp_y)
    temp_x += k

temp_y += temp_x - x
temp_x = x

while temp_y <= y:
    show_xy(temp_x, temp_y)
    temp_y += k
Problem p02975 (python)

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

c = list(set(a))
c.sort()
if len(c) > 3:
    print('No')
    exit()

if len(c) == 1:
    if c[0] == 0:
        print('Yes')
    else:
        print('No')
elif len(c) == 2:
    if c[0] == 0 and a.count(0) * 2 == a.count(c[1]):
        print('Yes')
    else:
        print('No')
else:
    if c[0] ^ c[1] == c[2] and a.count(c[0]) == a.count(c[1]) and a.count(c[1]) == a.count(c[2]):
        print('Yes')
    else:
        print('No')

Buggy submission (verdict: Runtime Error):
n = int(input())
a = list(map(int, input().split()))

c = set(a)
if len(c) > 3:
    print('No')
    exit()

c = list(c).sort()
if len(c) == 1:
    if c[0] == 0:
        print('Yes')
    else:
        print('No')
elif len(c) == 2:
    if c[0] == 0 and a.count(0) * 2 == a.count(c[1]):
        print('Yes')
    else:
        print('No')
else:
    if c[0] ^ c[1] == c[2] and a.count(c[0]) == a.count(c[1]) and a.count(c[1]) == a.count(c[2]):
        print('Yes')
    else:
        print('No')
Problem p02995 (python)

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

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

def lcm(n, m):
	return n * m // gcd (n, m)

if c == 1 or d == 1:
    print(0)
    exit()

if a == 1:
    div_a = 0
else:
    div_a = (a-1) // c + (a-1) // d - (a-1) // lcm(c, d)
div_b = b // c + b // d - b // lcm(c, d)

print(b - a + 1 - div_b + div_a)

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

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

def lcm(n, m):
	return n * m // gcd (n, m)

if c == 1 or d == 1:
    print(hoge)
    print(b - a + 1)
    exit()

if a == 1:
    div_a = 0
else:
    div_a = (a-1) // c + (a-1) // d - (a-1) // lcm(c, d)
div_b = b // c + b // d - b // lcm(c, d)

print(b - a + 1 - div_b + div_a)
Problem p02997 (python)

Fixed submission:
n, k = map(int, input().split())

if k > (n - 1) * (n - 2) // 2:
    print(-1)
    exit()

ans = [[0 for _ in range(n)] for _ in range(n)]

for i in range(1, n):
    ans[0][i] = 1

m = n-1

temp = (n-1) * (n-2) // 2 - k
for i in range(1, n):
    if temp == 0:
        break
    for j in range(i+1, n):
        ans[i][j] = 1
        m += 1
        temp -= 1
        if temp == 0:
            break

print(m)
for i in range(n):
    for j in range(n):
        if ans[i][j] == 1:
            print(i+1, j+1)

Buggy submission (verdict: Runtime Error):
n, k = map(int, input().split())

if k == 0:
    print(hoge)
    exit()

if k > (n - 1) * (n - 2) // 2:
    print(-1)
    exit()

ans = [[0 for _ in range(n)] for _ in range(n)]

for i in range(1, n):
    ans[0][i] = 1

m = n-1

temp = (n-1) * (n-2) // 2 - k
for i in range(1, n):
    for j in range(i+1, n):
        ans[i][j] = 1
        m += 1
        temp -= 1
        if temp == 0:
            break
    if temp == 0:
        break

print(m)
for i in range(n):
    for j in range(n):
        if ans[i][j] == 1:
            print(i+1, j+1)
Problem p03044 (python)

Fixed submission:
import sys
sys.setrecursionlimit(10 ** 5)

n = int(input())
uvw = [tuple(int(x) for x in input().split()) for _ in range(n-1)]

c = [-1] * n

r = [[] for _ in range(n)]

for u, v, w in uvw:
    r[u-1].append([v-1, w])
    r[v-1].append([u-1, w])

def f(p):
    count = 0
    for x, w in r[p]:
        if c[x] == -1:
            if w % 2 == 0:
                c[x] = c[p]
                f(x)
            else:
                c[x] = (c[p] + 1) % 2
                f(x)
            count += 1
    #print(count)

c[0] = 0
f(0)

for x in c:
    print(x)

Buggy submission (verdict: Runtime Error):
n = int(input())
uvw = [tuple(int(x) for x in input().split()) for _ in range(n-1)]

c = [-1] * n

r = [[] for _ in range(n)]

for u, v, w in uvw:
    r[u-1].append([v-1, w])
    r[v-1].append([u-1, w])

def f(p):
    count = 0
    for x, w in r[p]:
        if c[x] == -1:
            if w % 2 == 0:
                c[x] = c[p]
                f(x)
            else:
                c[x] = (c[p] + 1) % 2
                f(x)
            count += 1
    #print(count)

c[0] = 0
f(0)

for x in c:
    print(x)
Problem p03047 (python)

Fixed submission:
n, k = map(int, input().split())

print(n - k + 1)

Buggy submission (verdict: Runtime Error):
n = int(input())

ans = 0
x = 1

while x < n:
    if n % x == 0:
        m = n // x - 1
        if m <= x:
            break
        else:
            ans += m
    x += 1

print(ans)
Problem p03081 (python)

Fixed submission:
from collections import Counter

n, q = map(int, input().split())
s = list(input())
td = [list(input().split()) for _ in range(q)]

if n == 1:
    for t, d in td:
        if s[0] == t:
            print(0)
            exit()
    print(1)
    exit()

def vanish(x):
    for t, d in td:
        if s[x] == t:
            if d == 'L':
                x -= 1
                if x == -1:
                    return -1
            else:
                x += 1
                if x == n:
                    return n
    return x

L = 0
R = n
U = 0
ans = n

while R - L > 1:
    M = (L + R) // 2
    ret = vanish(M)
    if ret == -1:
        L = M
    else:
        R = M

ret = vanish(L)
if ret == -1:
    ans -= L + 1
else:
    ans -= L

L = 0
R = n

while R - L > 1:
    M = (L + R) // 2
    ret = vanish(M)
    if ret == n:
        R = M
    else:
        L = M

ret = vanish(L)
if ret == n:
    ans -= n - L
else:
    ans -= n - 1 - L

print(ans)

Buggy submission (verdict: Runtime Error):
from collections import Counter

n, q = map(int, input().split())
s = list(input())
td = [list(input().split()) for _ in range(q)]

if n == 1:
    for t, d in td:
        if s[0] == t:
            print(0)
            exit()
    print(1)
    exit()

def vanish(x):
    for t, d in td:
        if s[x] == t:
            if d == 'L':
                x -= 1
                if x == -1:
                    return -1
            else:
                x += 1
                if x == n:
                    return n
    return x

L = 0
R = n
U = 0
ans = n

while R - L > 1:
    M = (L + R) // 2
    ret = vanish(M)
    if ret == -1:
        L = M
    elif ret == n:
        R = M
        U = M
    else:
        R = M

ret = vanish(L)
if ret == -1:
    ans -= L + 1
    U = max(U, L + 1)
else:
    ans -= L

L = U
R = n

while R - L > 1:
    M = (L + R) // 2
    ret = vanish(M)
    if ret == n:
        R = M
    else:
        L = M

ret = vanish(L)
if ret == n:
    ans -= n - L
else:
    ans -= n - 1 - L

print(ans)
Problem p03145 (python)

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

a = sorted(a)

print(a[0] * a[1] // 2)

Buggy submission (verdict: Runtime Error):
from operator import itemgetter

n, k = map(int, input().split())
td = [tuple(int(x) for x in input().split()) for _ in range(n)]

a = sorted(td, key=itemgetter(1), reverse=True)

ans = [0]
s = set()
t = []
for i in range(k):
    ans[0] += a[i][1]
    if a[i][0] not in s:
        s.add(a[i][0])
    else:
        t.append(a[i][1])

p = len(s)
q = len(t) - 1

if q < 0:
    print(ans[0] + k * k)
    exit()

v = []
for i in range(k, n):
    if a[i][0] not in s:
        s.add(a[i][0])
        v.append(a[i][1])

ans[0] += p * p
d = 0

for x in v:
    ans.append(ans[d] + x - t[q] + (p + 1) * (p + 1) - p * p)
    p += 1
    d += 1
    q -= 1
    if q < 0:
        break

print(max(ans))
Problem p03170 (python)

Fixed submission:
n, k = map(int, input().split())
a = list(map(int, input().split()))

t = min(a)

dp = [0] * (k+1)

for x in a:
    dp[x] = 1

for i in range(k+1):
    for x in a:
        if i >= x:
            if dp[i] + (dp[i-x] + 1) % 2 > 0:
                dp[i] = 1
            else:
                dp[i] = 0

print("First" if dp[i] == 1 else "Second")

Buggy submission (verdict: Runtime Error):
from collections import Counter

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

c = Counter(a)

dp = [[[0.0 for _ in range(n+1)] for _ in range(n+1)] for _ in range(n+1)]

for z in range(c[3] + 1):
    for y in range(c[2]+1 + c[3] - z):
        for x in range(n+1 - z - y):
            if x + y + z == 0:
                continue
            ret = 0.0
            if x > 0:
                ret += dp[x-1][y][z] * x
            if y > 0:
                ret += dp[x+1][y-1][z] * y
            if z > 0:
                ret += dp[x][y+1][z-1] * z
            dp[x][y][z] = (ret + n) / (x + y + z)

print(dp[c[1]][c[2]][c[3]])
Problem p03238 (python)

Fixed submission:
n = int(input())

if n == 1:
    print('Hello World')
else:
    a = int(input())
    b = int(input())
    print(a + b)

Buggy submission (verdict: Runtime Error):
import math
n, m = map(int, input().split())

def IsPrime(num):
    if num < 2:
        return False
    elif num == 2:
        return True
    elif num % 2 == 0:
        return False

    sqrtNum = math.sqrt(num)
    for i in (3, sqrtNum + 1, 2):
        if num % i == 0:
            return False

    return True

if IsPrime(m):
    print(1)
    exit()


ans = 0
for i in range(m // n, -1, -1):
    #print(i)
    if m % i == 0 and m // i >= n:
        ans = i
        break

print(ans)
Problem p03262 (python)

Fixed submission:
n, X = map(int, input().split())
x = list(map(int, input().split()))

d = [0 for _ in range(n)]
for i in range(n):
    d[i] = abs(x[i] - X)

d = sorted(list(set(d)))

if n == 1:
    print(d[0])
    exit()

def calc_gcd(a, b):
    if a < b:
        a, b = b, a
    if b == 0:
        return a
    c = a % b
    return calc_gcd(b, c)

ans = d[0]
for i in range(1, len(d)):
    ans = calc_gcd(ans, d[i])

print(ans)

Buggy submission (verdict: Runtime Error):
import math

n, X = map(int, input().split())
x = list(map(int, input().split()))

d = [0 for _ in range(n)]
for i in range(n):
    d[i] = abs(x[i] - X)

d = sorted(list(set(d)))

if n == 1:
    print(d[0])
    exit()

ans = d[0]
for i in range(1, len(d)):
    ans = math.gcd(ans, d[i])

print(ans)
Problem p03274 (python)

Fixed submission:
n, k = map(int, input().split())
x = list(map(int, input().split()))

for center in range(n):
    if x[center] >= 0:
        break

if center == n - 1:
    print(-1 * x[n - k])
    exit()
elif center == 0:
    print(x[k - 1])
    exit()

plus = [0] + x[center:]
minus = [0] + list(reversed(list(map(lambda i:i * -1, x[:center]))))

ans = 10 ** 10

for i in range(max(k - len(minus) + 1, 0), min(k + 1, len(plus))):
    ans = min(ans, plus[i] + minus[k - i] + min(plus[i], minus[k - i]))

print(ans)

Buggy submission (verdict: Runtime Error):
n, k = map(int, input().split())
x = list(map(int, input().split()))

for center in range(n):
    if x[center] >= 0:
        break

if center == n or (center == n - 1 and x[n - 1] == 0):
    print(-1 * x[n - k])
    exit()
elif center == 0:
    print(x[k - 1])
    exit()

plus = [0] + x[center:]
minus = [0] + list(reversed(list(map(lambda i:i * -1, x[:center]))))

ans = 10 ** 10

for i in range(max(k - len(minus) + 1, 0), min(k + 1, len(plus))):
    ans = min(ans, plus[i] + minus[k - i] + min(plus[i], minus[k - 1]))

print(ans)
Problem p03283 (python)

Fixed submission:
n, m, q = map(int, input().split())

temp = [ [0 for _ in range(n)] for _ in range(n)]
tables = [ [0 for _ in range(n)] for _ in range(n)]

if n == 1:
    print('1')
    exit()

for _ in range(m):
    l, r = map(int, input().split())
    temp[l - 1][r - 1] += 1

pq = [tuple(int(x) - 1 for x in input().split()) for _ in range(q)]

hoge = 0
for j in range(n):
    hoge += temp[0][j]
    tables[0][j] = hoge

for i in range(1, n):
    hoge = 0
    for j in range(n):
        hoge += temp[i][j]
        tables[i][j] = tables[i - 1][j] + hoge

for p, q in pq:
    if p == 0:
        print(tables[q][q])
    else:
        print(tables[q][q] - tables[p - 1][q] - tables[q][p - 1] + tables[p - 1][p - 1] )

Buggy submission (verdict: Runtime Error):
n, m, q = map(int, input().split())

temp = [ [0 for _ in range(n)] for _ in range(n)]
tables = [ [0 for _ in range(n)] for _ in range(n)]

for _ in range(m):
    l, r = map(int, input().split())
    temp[l - 1][r - 1] += 1

pq = [tuple(int(x) - 1 for x in input().split()) for _ in range(q)]

for i in range(m):
    hoge = 0
    for j in range(m):
        hoge += temp[i][j]
        tables[i][j] = hoge

for p, q in pq:
    ans = 0
    if p > 0:
        for i in range(p, q + 1):
            ans += tables[i][q] - tables[i][p - 1]
    else:
        for i in range(q + 1):
            ans += tables[i][q]
    print(ans)

Buggy submission (verdict: Runtime Error):
n, m, q = map(int, input().split())

temp = [ [0 for _ in range(n)] for _ in range(n)]
tables = [ [0 for _ in range(n)] for _ in range(n)]

for _ in range(m):
    l, r = map(int, input().split())
    temp[l - 1][r - 1] += 1

pq = [tuple(int(x) - 1 for x in input().split()) for _ in range(q)]

for i in range(m):
    hoge = 0
    for j in range(m):
        hoge += temp[i][j]
        tables[i][j] = hoge

for p, q in pq:
    ans = 0
    if p > 0:
        for i in range(p, q + 1):
            ans += tables[i][q] - tables[i][p - 1]
    else:
        for i in range(q + 1):
            ans += tables[i][q]
    print(ans)
Problem p03284 (python)

Fixed submission:
n, k = map(int, input().split())

if n % k == 0:
    print('0')
else:
    print('1')

Buggy submission (verdict: Runtime Error):
n = int(input())

a = []

if n > 0:
    while n > 0:
        a.append(n % 2)
        n //= 2

    a.append(0)
    a.append(0)
    for i in range(len(a) - 1):
        if i % 2 == 1:
            if a[i] == 1:
                a[i + 1] += 1
            elif a[i] == 2:
                a[i + 1] += 1
                a[i] = 0
        else:
            if a[i] == 2:
                a[i + 1] += 1
                a[i] = 0
        a[i] = str(a[i])

    for i in range(len(a) - 1, -1, -1):
        if a[i] == 0 or a[i] == '0':
            a[i] = ''
        else:
            break
    print(''.join(reversed(a)))
elif n == 0:
    print('0')
else:
    n = 0 - n
    while n > 0:
        a.append(n % 2)
        n //= 2

    a.append(0)
    a.append(0)
    for i in range(len(a) - 1):
        if i % 2 != 1:
            if a[i] == 1:
                a[i + 1] += 1
            elif a[i] == 2:
                a[i + 1] += 1
                a[i] = 0
        else:
            if a[i] == 2:
                a[i + 1] += 1
                a[i] = 0
        a[i] = str(a[i])

    for i in range(len(a) - 1, -1, -1):
        if a[i] == 0 or a[i] == '0':
            a[i] = ''
        else:
            break
    print(''.join(reversed(a)))

Buggy submission (verdict: Runtime Error):
if n % k == 0:
    print('0')
else:
    print('1')
Problem p03294 (python)

Fixed submission:
from fractions import gcd
from functools import reduce

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

a = sorted(a)

def lcm_base(x, y):
    return (x * y) // gcd(x, y)

def lcm_list(numbers):
    return reduce(lcm_base, numbers, 1)

temp = lcm_list(a) - 1

result = 0
for i in a:
    result += temp % i

print(result)

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

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

a = sorted(a)

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

def lcm_list(numbers):
    return reduce(lcm_base, numbers, 1)

temp = lcm_list(a) - 1

result = 0
for i in a:
    result += temp % i

print(result)