Problem:


Score : 300 points

Problem Statement

You are given N positive integers a_1, a_2, ..., a_N.

For a non-negative integer m, let f(m) = (m\ mod\ a_1) + (m\ mod\ a_2) + ... + (m\ mod\ a_N).

Here, X\ mod\ Y denotes the remainder of the division of X by Y.

Find the maximum value of f.

Constraints

All values in input are integers.

2 \leq N \leq 3000

2 \leq a_i \leq 10^5

Input

Input is given from Standard Input in the following format:

N
a_1 a_2 ... a_N

Output

Print the maximum value of f.

Sample Input 1

3
3 4 6

Sample Output 1

10

f(11) = (11\ mod\ 3) + (11\ mod\ 4) + (11\ mod\ 6) = 10 is the maximum value of f.

Sample Input 2

5
7 46 11 20 11

Sample Output 2

90

Sample Input 3

7
994 518 941 851 647 2 581

Sample Output 3

4527



Sample input:
3
3 4 6


Sample output:
10

Submission status: Runtime Error

Solution code:
import math
from functools import reduce

n = int(input())
a = [int(i) for i in input().split()]

ans1 = ans2 = 0
li_ans = []


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


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


lcm = lcm_list(a)

for num in a:
    ans1 += (lcm - 1) % num
    ans2 += (lcm + 1) % num

print(max(ans1, ans2))

Submission status: Runtime Error

Solution code:
def gcd(x,y):
    x,y = max(x,y),min(x,y)
    while(y>0):
        x,y = y,x%y
    return(x)
    
def lcm(a,b):
    return(int(a*b/gcd(a,b)))

n = int(input())
a = list(map(int,input().split()))
least_common_multiple = 1
for i in range(n):
    least_common_multiple = lcm(least_common_multiple,a[i])
ans = 0
for i in range(n):
    ans += (least_common_multiple-1)%a[i]
print(ans)

Submission status: Runtime Error

Solution code:
def gcd(x,y):
    x,y = max(x,y),min(x,y)
    while(y>0):
        x,y = y,x%y
    print(x)
def lcm(a,b):
    return(int(a*b/gcd(a,b)))

n = int(input())
a = list(map(int,input().split()))
least_common_multiple = 1
for i in range(n):
    least_common_multiple = lcm(least_common_multiple,a[i])
ans = 0
for i in range(n):
    ans += (least_common_multiple-1)%a[i]
print(ans)

Submission status: Runtime Error

Solution code:
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_list(li):
    if len(li) == 1:
        return li[0]

    elif len(li) == 2:
        return lcm(li[0], li[1])
        
    else:
        li = [lcm(li[0], li[1])] + li[2:]
        return  lcm_list(li)

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


i = lcm_list(a) -1
print(sum([i%j for j in a]))

Submission status: Runtime Error

Solution code:
import math
from functools import reduce

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

def lcm_list(a):
    return reduce(lcm_base, a)
if __name__ == '__main__':
	N = int(input())
	a = list(map(int, input().split()))
	ans = 0
	num = lcm_list(a) - 1
	print(num)
	for i in range(len(a)):
		ans += num % a[i]
	print(ans)

Submission status: Runtime Error

Solution code:
import math
import functools


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

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

def lcm_list(*numbers):
    return functools.reduce(lcm_base, numbers, 1)

def main() :
    n = int(input())
    a = list(map(int, input().split()))
    lcm = lcm_list(*a)

    ans = 0
    for aa in a :
        ans += (lcm-1) % aa

    print(ans)

main()

Submission status: Runtime Error

Solution code:
import math

input()
ip = input().split()
data = []
for i in ip:
    data.append(int(i))


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

def lcm(num):
    buf = num[0]
    for i in range(1, len(num)):
        buf = lcmbase(num[i], buf)
    return buf

usedata = int(lcm(data) - 1)

suming = 0
for i in data:
    suming += usedata % i

print(suming)

Submission status: Runtime Error

Solution code:
import math
from functools import reduce

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

def lcm_list(a):
    return reduce(lcm_base, a)

N = int(input())
a = list(map(int, input().split()))
ans = 0
num = lcm_list(a) - 1
print(num)
for i in range(len(a)):
	ans += num % a[i]
print(ans)

Submission status: Runtime Error

Solution code:
import math
import functools


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

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

def lcm_list(*numbers):
    return functools.reduce(lcm_base, numbers, 1)

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

ans = 0
for aa in a :
    ans += (lcm-1) % aa

print(ans)

Submission status: Runtime Error

Solution code:
import math
n = int(input())
a = list(map(int,input().split()))
least_common_multiple = 1
for i in range(n):
    least_common_multiple = int(least_common_multiple*a[i]/math.gcd(least_common_multiple,a[i]))
ans = 0
for i in range(n):
    ans += (least_common_multiple-1)%a[i]
print(ans)

Submission status: Runtime Error

Solution code:

def gcd(x, y):
	if y == 0:
		return x
	else:
		return gcd(y, x % y)

N = int(input())
A = list(map(int, input().split()))
#N = 7
#A = [994, 518, 941, 851, 647, 2, 581]
t = A[0]
for i in range(1,N):
	if (t % A[i] == 0):
		continue
	t = t * A[i] / gcd(t, A[i])
sum = 0
t -= 1
for i in range(N):
	sum += t % A[i]
print(int(sum))

Submission status: Runtime Error

Solution code:
def gcd(a, b):
  while b > 0:
    a, b = b, a%b
  return a

def lcm(a, b):
  return a*b/gcd(a, b)

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


lcm_num = lcm(a[0], a[1])

for i in range(2, n):
    lcm_num = lcm(lcm_num, a[i])

ans = 0
for i in range(n):
    ans += (lcm_num-1) % a[i]

print(int(ans))

Submission status: Runtime Error

Solution code:
def gcd(a, b):
	while b:
		a, b = b, a % b
	return a

def lcm(a, b):
    return int((a * b) / gcd(a,  b))

def lcm_list(li):
    if len(li) == 2:
        return lcm(li[0], li[1])
    else:
        li = [lcm(li[0], li[1])] + li[2:]
        return  lcm_list(li)

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


i = lcm_list(a) -1
print(sum([i%j for j in a]))

Submission status: Runtime Error

Solution code:
def find_lcm(num1, num2):
    if(num1>num2):
        num = num1
        den = num2
    else:
        num = num2
        den = num1
    rem = num % den
    while(rem != 0):
        num = den
        den = rem
        rem = num % den
    gcd = den
    lcm = int(int(num1 * num2)/int(gcd))
    return lcm
     
N=int(input())
A=list(map(int,input().split()))
N1 = A[0]
N2 = A[1]
lcm = find_lcm(N1,N2)
for i in range(2, N):
    lcm = find_lcm(lcm, A[i])
Ans=0
lcm-=1
for I in range(N):
	Ans+=(lcm%A[I])
print(Ans)

Submission status: Runtime Error

Solution code:
import math

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

N = int(input())
a = list(map(int,input().split()))
a.sort()
tlcm = lcm(a[0],a[1])

for i in range(2,len(a)):
	tlcm = lcm(a[i],tlcm)

tlcm = tlcm - 1
result = 0
for i in range(len(a)):
	result += tlcm % a[i]
print(result)

Submission status: Runtime Error

Solution code:
import math
import functools


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

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

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

ans = 0
for aa in a :
    ans += (lcm-1) % aa

print(ans)

Submission status: Runtime Error

Solution code:

def gcd(x, y):
	if y == 0:
		return x
	else:
		return gcd(y, x % y)

N = int(input())
A = list(map(int, input().split()))
#N = 7
#A = [994, 518, 941, 851, 647, 2, 581]
t = A[0]
for i in range(1,N):
	if (t % A[i])
		continue
	t = t * A[i] / gcd(t, A[i])
sum = 0
t -= 1
for i in range(N):
	sum += t % A[i]
print(int(sum))

Submission status: Runtime Error

Solution code:
def gcd(a, b):
    if b == 0: return a
    return gcd(b, a % b)

def lcm(a, b):
    return int(a * b / gcd(a, b))

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

lcm_a = 0
for i in range(len(a_li)) :
    if i == 0 :
        lcm_a = a_li[i]
    else :
        lcm_a = lcm(lcm_a, a_li[i])

m = lcm_a - 1
f = 0
for i in range(len(a_li)) :
    f = f + m % a_li[i]

print(f)

Submission status: Runtime Error

Solution code:

def gcd(x, y):
	if y == 0:
		return x
	else:
		return gcd(y, x % y)

N = int(input())
A = list(map(int, input().split()))
#N = 7
#A = [994, 518, 941, 851, 647, 2, 581]
t = A[0]
for i in range(1,N):
	t = t * A[i] / gcd(t, A[i])
sum = 0
t -= 1
for i in range(N):
	sum += t % A[i]
print(int(sum))

Submission status: Runtime Error

Solution code:
import math
from fractions import Fraction
from functools import reduce

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


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

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


m =  lcm_list(A) -1

B = 0

for j in range(len(A)):
    B += m%A[j]

print(B)

Submission status: Runtime Error

Solution code:
def gcd(a, b):
    if b == 0: return a
    mod = a % b
    buf = gcd(b, mod)
    return buf

def lcm(a, b):
    buf = gcd(a, b)
    return int(a * b / buf)

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

lcm_a = 0
for i in range(len(a_li)) :
    if i == 0 :
        lcm_a = a_li[i]
    else :
        lcm_a = lcm(lcm_a, a_li[i])

m = lcm_a - 1
f = 0
for i in range(len(a_li)) :
    f = f + m % a_li[i]

print(f)

Submission status: Runtime Error

Solution code:
N = int(input())
a = list(map(int, input().split()))
ans = 0
import math
from functools import reduce
def lcm_base(x, y):
    return int((x * y) / math.gcd(x, y))
def lcm_list(numbers):
    ans = 0
    for i in range(1,len(numbers)):
        if(i == 1):
            ans = lcm_base(numbers[0], numbers[1])
        else:
            ans = lcm_base(ans, numbers[i])
    return ans

min_bin= lcm_list(a)

# ans = 0
for i in a:
    ans += (min_bin-1) % i
    # print(tmp)
print(ans)

Submission status: Runtime Error

Solution code:

def gcd(x, y):
	if y == 0:
		return x
	else:
		return gcd(y, x % y)

N = int(input())
A = list(map(int, input().split()))
#N = 3
#A = [3,4,6]

t = A[0]
for i in range(1,N):
	t = t * A[i] / gcd(t, A[i])
sum = 0
t -= 1
#print(t)
for i in range(N):
	sum += t % A[i]
print(sum)

Submission status: Runtime Error

Solution code:
import math

def lcm(lst):
    if len(lst) == 2:
        return (lst[0] * lst[1]) // math.gcd(lst[0], lst[1])
    l = lcm(lst[1:])
    return (lst[0] * l) // math.gcd(lst[0], l)

n = int(input())
inputs = list(map(int, input().split(' ')))
x = lcm(inputs) - 1
s = 0
for i in inputs:
    s += x % i
print(s)

Submission status: Runtime Error

Solution code:
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_list(li):
    if len(li) == 2:
        return lcm(li[0], li[1])
    else:
        li = [lcm(li[0], li[1])] + li[2:]
        return  lcm_list(li)

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


i = lcm_list(a) -1
print(sum([i%j for j in a]))

Submission status: Runtime Error

Solution code:
import math
from functools import reduce

def gcd_list(a):
	return reduce(math.gcd, a)

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

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

N = int(input())
a = list(map(int, input().split()))
ans = 0
num = lcm_list(a)- 1
for i in range(len(a)):
	ans += num % a[i]
print(ans)

Submission status: Runtime Error

Solution code:
import math
from functools import reduce
input()
ip = input().split()
data = []
for i in ip:
    data.append(int(i))

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

def lcm(num):
    return reduce(lcmB,num)

print(int(lcm(data) - 1))

Submission status: Runtime Error

Solution code:
import math
from fractions import Fraction
from functools import reduce

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


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

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


m =  lcm_list(A) -1

B = 0

for j in range(len(A)):
    B += m%A[j]

print(B)

Submission status: Runtime Error

Solution code:
from functools import reduce
import math
n = int(input())
a = list(map(int, input().split()))

#最小公倍数−1
def lcm_base(x, y):
    return (x * y) // math.gcd(x, y)

def lcm(*numbers):
    return reduce(lcm_base, numbers, 1)

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

m = lcm_list(a)-1
sum = 0
for i in a:
    sum += m%i

print(sum)

Submission status: Runtime Error

Solution code:
# 3
import math

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

def f(m,a):
    ans=0
    for i in a:
        ans+=m%i
    return ans

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

def lcm_list(numbers):
    ans=numbers[0]
    for i in range(1,len(numbers)):
        ans=lcm_base(ans,numbers[i])
    return ans

m= lcm_list(a)-1
print(f(m,a))

Submission status: Runtime Error

Solution code:
import numpy as np
from math import gcd
from functools import reduce
def lcm_base(x, y):
    return (x * y) // gcd(x, y)

def lcm_list(numbers):
    return reduce(lcm_base, numbers, 1)
N = int(input())
a = list(map(int,input().split()))
a = np.array(a)
a = np.sort(a)[::-1]
MAX = lcm_list(a)
#print (MAX)
Flag = True
q = 0
add = a[0]
sum = 0
max = np.sum(a)-len(a)
#print (max)
n = a[0]*q+a[0]-1
while True:
    st = np.sum(n%a)
    if st == max:
        sum = st
        break
    if st > MAX:
        break
    ind = np.where(a - n%a == 1)[0]
    #print (ind)
    c = a[ind]
    n += np.prod(c)
    #print (sum)
print (sum)

Submission status: Runtime Error

Solution code:
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)

Submission status: Runtime Error

Solution code:
import math

#least multi
def lm(a,b):
    return a*b // math.gcd(a,b)

N =input()
list = input().split(" ")
int_li = [int(s) for s in list]

m = 1
for i in int_li:
    m = lm(m,i)
m-=1

ans = 0
for i in int_li:
    ans += m%i

print(ans);

Submission status: Runtime Error

Solution code:
import math
from functools import reduce

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


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

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


m =  lcm_list(A) -1

B = 0

for j in range(len(A)):
    B += m%A[j]

print(B)

Submission status: Runtime Error

Solution code:
length = int(input())

numbers = list(map(int, input().rstrip().rsplit(' ')))

r = numbers[0]
for num in numbers[1:]:
    r %= num
    while r != 0:
        a = num
        num = r
        r = a % num
    
    r = num

mul = 1
for num in numbers:
    mul *= num

rest = 0
for num in numbers:
    rest += int(mul / r - 1) % num
    
print(rest)

Submission status: Runtime Error

Solution code:
import math

def lcm(a, b):
    return (a * b) // math.gcd(a,  b)

def lcm_list(li):
    if len(li) == 2:
        return lcm(li[0], li[1])
    else:
        li = [lcm(li[0], li[1])] + li[2:]
        return  lcm_list(li)

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


i = lcm_list(a) -1
print(sum([i%j for j in a]))

Submission status: Runtime Error

Solution code:
from math import gcd
from functools import reduce
import sys

def lcm(p,q):
    return p*q//gcd(p,q)
sys.setrecursionlimit(3001)
N=int(input())
a=list(map(int,input().split(' ')))
m=reduce(lcm,a)-1
result=0
for i in a:
    result+=m%i
print(result)

Submission status: Runtime Error

Solution code:
from math import gcd
n = int(input())

a = list(map(int,input().split()))
lcm = a[0]
for i in a[1:]:
  lcm = (lcm * i) // int(gcd(lcm, i)) 

lcm -= 1
ans = 0
for i in a:
	ans += lcm % i 
print(ans)

Submission status: Runtime Error

Solution code:
import math
def lcm(x, y):
    a = (x*y)//math.gcd(x, y)
    return a

N = int(input())
a = list(map(int, input().split()))
lcm2 = 1
for i in range(N):
    lcm2 = lcm(a[i], lcm2)
lcm2 -= 1
f = 0
for i in range(N):
    f += lcm2%a[i]
print(f)

Submission status: Runtime Error

Solution code:
N=int(input())
a=list(map(int, input().rstrip().split()))
work=int()
Multiple=int(1)
Output=int(0)
def gcd(x,y):
    while y>0:
        x, y=y, x%y
    return x
for i in range(N):
    Multiple=int((Multiple*a[i])/gcd(Multiple, a[i]))
for i in range(N):
    Output+=(Multiple-1)%a[i]
print(Output)

Submission status: Runtime Error

Solution code:
import math
def lcm(x, y):
    return (x*y)//math.gcd(x, y)

N = int(input())
a = list(map(int, input().split()))
lcm2 = 1
for i in range(N):
    lcm2 = lcm(a[i], lcm2)
lcm2 -= 1
f = 0
for i in range(N):
    f += lcm2%a[i]
print(f)

Submission status: Runtime Error

Solution code:
from math import gcd
from functools import reduce

def lcm(p,q):
    return p*q//gcd(p,q)

N=int(input())
a=list(map(int,input().split(' ')))
m=reduce(lcm,a)-1
result=0
for i in a:
    result+=m%i
print(result)

Submission status: Runtime Error

Solution code:
# 3
import math
from functools import reduce

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

def f(m,a):
    ans=0
    for i in a:
        ans+=m%i
    return ans

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

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

m= lcm_list(a)-1
# print(m)
print(f(m,a))

Submission status: Runtime Error

Solution code:
import math
from functools import reduce

def lcm(a, b):
    return (a * b) // math.gcd(a,  b)

def lcm_list(li):
    return reduce(lcm, li, 1)

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


i = lcm_list(a) -1
print(sum([i%j for j in a]))

Submission status: Runtime Error

Solution code:
import math

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

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

j=lcm(A[0],A[1])
for i in range(2,len(A)):
    j=lcm(j, A[i])

tmp=[]
for i in A:
    tmp.append((j-1)%i)
ans=sum(tmp)
print(ans)

Submission status: Runtime Error

Solution code:
import math
from functools import reduce

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

a_lcm = reduce(lambda x, y: (x * y) // math.gcd(x, y), a)
m = a_lcm - 1
a_mod = [m % ax for ax in a]

print(sum(a_mod))

Submission status: Runtime Error

Solution code:
import math

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

N = int(input())
a = list(map(int, input().split()))
lcm2 = 1
for i in range(len(a)):
    lcm2 = lcm(a[i], lcm2)
lcm2 -= 1
f = 0
for i in range(len(a)):
    f += lcm2%a[i]
print(f)

Submission status: Runtime Error

Solution code:
import math
from functools import reduce

# 最小公倍数を求める関数
def lcm_base(x, y):
    return (x * y) // math.gcd(x, y)

def lcm(*numbers):
    return reduce(lcm_base, numbers, 1)

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

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

lcm = lcm_list(a)

ans = 0
for i in range(n):
    ans += (lcm-1) % a[i]

print(ans)

Submission status: Runtime Error

Solution code:
import math

n=input()
a=[int(i) for i in input().split()]
ac=a[:]


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

while(len(ac)>1):
    x=ac.pop()
    y=ac.pop()
    ac.append(lcm(x, y))

g=ac[0]-1

ans=0
for i in a:
    ans+=g%i

print(ans)

Submission status: Runtime Error

Solution code:
import fraction
from functools import reduce


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

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


N = int(input())
A = list(map(int, input().split()))
L = lcm(A) - 1

result = 0

for a in A:
    result += (L % a)

print(result)

Submission status: Runtime Error

Solution code:
import statistics
import math
from functools import reduce

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

def lcm(*numbers):
    return reduce(lcm_base, numbers, 1)

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

n = int(input())
nums = list(map(int, input().split()))
lcm = lcm_list(nums)

# print(nums, lcm)
sum =0
for num in nums:
    sum += (lcm-1)%num
print(sum)

Submission status: Runtime Error

Solution code:
import math
from functools import reduce


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

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


N = int(input())
A = list(map(int, input().split()))
L = lcm(A) - 1

result = 0

for a in A:
    result += (L % a)

print(result)

Submission status: Runtime Error

Solution code:
n = int(input())
a = [int(x) for x in input().split()]
def gcd(a,b):
    while b>0:
        a,b = b, a%b
    return a
def lcm(a,b):
    return a/gcd(a,b) * b
lcm_sum=1
f=0
for i in a:
    lcm_sum = lcm(lcm_sum, i)
for i in a:
    f+=(lcm_sum-1) % i
print(int(f))

Submission status: Runtime Error

Solution code:
import math

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

def f(m, a):
    re = 0
    for i in a:
        re += m % i
    return re

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

def lcm(*numbers):
    return reduce(lcm_base, numbers, 1)

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

m = lcm_list(a) - 1
print(f(m, a))

Submission status: Runtime Error

Solution code:
import math

def lcm(a,b):
    return (a*b)//math.gcd(a,b)

n=int(input())
a=list(map(int,input().split()))
for i in range(n-1):    
    if(i==0):
        m=lcm(a[0],a[1])
    else:
        m=lcm(m,a[i+1])
m-=1
f=0
for i in range(n):
    f+=m%a[i]
print(f)

Submission status: Runtime Error

Solution code:
import functools

def gcd(a,b):
    while b > 0:
        a, b = b, a % b
    return a
    
def lcm(a, b):
    return a * b / gcd(a, b)

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

lcmVal = int(functools.reduce(lcm, a))
print(sum(map(lambda x: (lcmVal-1) % x, a)))

Submission status: Runtime Error

Solution code:
from math import gcd
from functools import reduce


def lcm_base(x, y):
    return (x * y) // gcd(x, y)
def lcm(numbers):
    return reduce(lcm_base, numbers, 1)


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

mod = []
for m in range(lcm(a)):
    k = [m % a[i] for i in range(N)]
    mod.append(sum(k))
print(max(mod))

Submission status: Runtime Error

Solution code:
import math
from functools import reduce

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

def f(m, a):
    re = 0
    for i in a:
        re += m % i
    return re

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

def lcm(*numbers):
    return reduce(lcm_base, numbers, 1)

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

m = lcm_list(a) - 1
print(f(m, a))

Submission status: Runtime Error

Solution code:
import sys
import os
import math
from functools import reduce
def lcm_base(x, y):
    return (x * y) // math.gcd(x, y)

def lcm(*numbers):
    return reduce(lcm_base, numbers, 1)

def lcm_list(numbers):
    return reduce(lcm_base, numbers, 1)
n=int(input())
m=list(map(int,input().split()))
k=lcm_list(m)
answer=0
for i in range(n):
    answer=answer+(m[i]%k)
print(answer-n)

Submission status: Runtime Error

Solution code:
import math
from functools import reduce

def lcm_base(x, y):
    return (x * y)//math.gcd(x, y)
def lcm(*numbers):
    return reduce(lcm_base, numbers, 1)

N = int(input())
a = list(map(int, input().split()))
lcm = lcm(*a)-1
f = 0
for i in range(len(a)):
    f += lcm%a[i]
print(f)

Submission status: Runtime Error

Solution code:
def gcd(a, b):
  while b > 0:
    a, b = b, a%b
  return a

def lcm(a, b):
  return a*b//gcd(a, b)

def lcm_lst(lst):
  if len(lst) == 1:
    return lst[0]
  return lcm(lst[0], lcm_lst(lst[1:]))


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

m = lcm_lst(a)-1
f = 0
for a_ in a:
    f += m % a_
print(f)

Submission status: Runtime Error

Solution code:
def gcd(a, b):
    a, b = max(a, b), min(a, b)
    if a % b == 0:
        return b
    else:
        return gcd(b, a%b)
def lcm(a, b):
    return int(a * b / gcd(a, b))

N = int(input())
a = [int(i) for i in input().split()]

LCM = lcm(a[0], a[1])
for i in range(1, N-1):
    LCM = lcm(LCM, a[i+1])
LCM -= 1

modTotal = 0
for i in range(N):
    modTotal += LCM % a[i]
print(modTotal)

Submission status: Runtime Error

Solution code:
import math
from functools import reduce

def lcm_base(x, y):
    return (x * y) // math.gcd(x, y)
def lcm(*numbers):
    return reduce(lcm_base, numbers, 1)

N = int(input())
a = list(map(int, input().split()))
lcm = lcm(*a)-1
f = 0
for i in range(len(a)):
    f += lcm%a[i]
print(f)

Submission status: Runtime Error

Solution code:
import math

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


def lcm(a, b):
    return int(a * b / math.gcd(a, b))

llcm=1
for i in range(n):
    llcm= lcm(llcm,l[i])

mmax=llcm
fmmax=0
    
for m in range(mmax):
    fm=0
    for i in l:
        fm += m%i
    if fm > fmmax:
        fmmax=fm
print(fmmax)

Submission status: Runtime Error

Solution code:
import math
from functools import reduce

n = int(input())
a = [int(i) for i in input().split()]

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

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

c = lcm_list(a) - 1

f = 0
for i in a:
    f += c % i

print(f)

Submission status: Runtime Error

Solution code:
from fraction import gcd
def lcm(a, b):return a * b // gcd(a,b)
N = int(input())
A = [int(i) for i in input().split()]
B = lcm(A[0],A[1])
ans = 0
for i in A:
    B = lcm(B,i)
for i in A:
    ans += (B-1)%i
print(ans)

Submission status: Runtime Error

Solution code:
import math
N = int(input())
ai = list(map(int, input().split()))
m = 1
ans = 0
for a in ai:
    m = (m * a) // math.gcd(m, a)
m -= 1
for a in ai:
    ans += m % a
    
print(ans)

Submission status: Runtime Error

Solution code:
n=input()
a=[int(i) for i in input().split()]

import math
from functools import reduce

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

def lcm(*numbers):
    return reduce(lcm_base, numbers, 1)

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

g=lcm(*a)-1

ans=0
for i in a:
    ans+=g%i

print(ans)

Submission status: Runtime Error

Solution code:
import functools

def gcd(a,b):
    while b > 0:
        a, b = b, a % b
    return a
    
def lcm(a, b):
    return a * b / gcd(a, b)

N = int(input())
a = list(map(int, input().split()))
assert(len(a) == N)

lcmVal = int(functools.reduce(lcm, a))
print(sum(map(lambda x: (lcmVal-1) % x, a)))

Submission status: Runtime Error

Solution code:
import math
from functools import reduce
def lcm_base(x, y):
    return (x * y) // math.gcd(x, y)
def lcm_list(numbers):
    return reduce(lcm_base, numbers, 1)

n = int(input())
l = [int(x) for x in input().split()]
m = lcm_list(l)
s = []
for i in range(m):
    c = 0
    for j in range(n):
        c += i % l[j]
    s.append(c)
print(max(s))

Submission status: Runtime Error

Solution code:
import math, string, fractions, heapq, re, array, bisect, sys, random, time, copy
import itertools as it
import collections as cl
import functools as ft


def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()


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

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


def calc_f(n, ms):
    sum = 0
    for m in ms:
        sum += n % m

    return sum


n = I()
a = LI()

print(calc_f(lcm_list(a)-1, a))

Submission status: Runtime Error

Solution code:
n=input()
print(sum([int(j) for j in input().split()])-n)

Submission status: Runtime Error

Solution code:
import functools

def gcd(a,b):
    while b > 0:
        a, b = b, a % b
    return a
    
def lcm(a, b):
    return a * b / gcd(a, b)

N = int(input())
a = list(map(int, input().split()))
assert(len(a) == N)

lcmVal = int(functools.reduce(lcm, a))
print(lcmVal)
print(sum(map(lambda x: (lcmVal-1) % x, a)))

Submission status: Runtime Error

Solution code:
def gcd(a, b):
    if b == 0:
        return a
    return gcd(b, a % b)


n = int(input())
arr = list(map(int, input().split()))
lcm = 1
for e in arr:
    lcm = int(lcm * e / gcd(lcm, e))
lcm -= 1
res = 0
for e in arr:
    res += lcm % e
print(res)

Submission status: Runtime Error

Solution code:
import math
from functools import reduce


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


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


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

lcm_num = lcm_list(a) - 1
ans = 0
for i in range(N):
    ans += lcm_num % a[i]
print(ans)

Submission status: Runtime Error

Solution code:
import math
from functools import reduce


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


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


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

lcm_num = lcm_list(a) - 1
ans = 0
for i in range(N):
    ans += lcm_num % a[i]
print(ans)

Submission status: Runtime Error

Solution code:
import math
from functools import reduce
N = int(input())
a = [int(ai) for ai in input().split()]

def f(m):
    answer = 0
    for ai in a:
        answer += m % ai
    return answer

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

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

m = lcm(a) - 1
print(f(m))

Submission status: Runtime Error

Solution code:
from functools import reduce
import fraction


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

def lcm(*numbers):
    return reduce(lcm_base, numbers, 1)

    
def main():
    n = int(input())
    a = [int(x) for x in input().split()]

    v = lcm(*a) -1
    ans = sum(v % x for x in a)
    print(ans)
    
        
if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
from functools import reduce
import math


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

def lcm(*numbers):
    return reduce(lcm_base, numbers, 1)

    
def main():
    n = int(input())
    a = [int(x) for x in input().split()]

    v = lcm(*a) -1
    ans = sum(v % x for x in a)
    print(ans)
    
        
if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
import math
from functools import reduce

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


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


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


lcm_num = lcm_list(a) - 1
ans = 0
for i in range(N):
    ans += lcm_num % a[i]
print(ans)

Submission status: Runtime Error

Solution code:
import math
def lcm(a,b):
    return(int(a*b/math.gcd(a,b)))

n = int(input())
a = list(map(int,input().split()))
least_common_multiple = 1
for i in range(n):
    least_common_multiple = lcm(least_common_multiple,a[i])
ans = 0
for i in range(n):
    ans += (least_common_multiple-1)%a[i]
print(ans)

Submission status: Runtime Error

Solution code:
n=int(input())
a=list(map(int, input().split()))
def gcd(x, y):
    while y:
        x, y = y, x % y
    return x
def lcm(x,y):
    return int(x*y/gcd(x,y))
k=1
for t in a:
    k=lcm(k,t)
k-=1
ans=0
for t in a:
    ans+=k%t
print(ans)

Submission status: Runtime Error

Solution code:
n=input()
a=list(map(int,input().split()))
print(sum(a)-n)

Submission status: Runtime Error

Solution code:
import math

n = int(input())
arr = list(map(int, input().split()))
lcm = 1
for e in arr:
    lcm = int(lcm * e / math.gcd(lcm, e))
lcm -= 1
res = 0
for e in arr:
    res += lcm % e
print(res)

Submission status: Runtime Error

Solution code:
import math
def lcm(x, y):
    return (x * y) // math.gcd(x, y)
n = int(input())
a = list(map(int,input().split()))
x = 1
for i in range(n-1):
    x *= lcm(a[i],a[i+1])
Sum = 0
for i in range(n):
    Sum += (x-1)%a[i]
print(Sum)