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: Accepted

Solution code:
from fractions import gcd
N = int(input())
A = list(map(int,input().split()))
L = A[0]
for a in A:
    L = L*a//gcd(L,a)
res = 0
for a in A:
    res += (L-1)%a
print(res)

Submission status: Accepted

Solution code:
# INPUT
n = int(input())
a = list(map(int, input().split()))

# PROCESS
a_mul = 1
for a_item in a:
  a_mul = a_mul*a_item

answer = 0
for a_item in a:
  answer = answer + (a_mul-1) % a_item


# OUTPUT
print(answer)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import sys

input = sys.stdin.readline

def main():
    N = int(input())
    A = list(map(lambda x: int(x) - 1, input().split()))
    print(sum(A))

main()

Submission status: Accepted

Solution code:
N=int(input())
A=list(int(i) for i in input().split())
print(sum(A)-len(A))

Submission status: Accepted

Solution code:
input()
print(sum([int(a)-1 for a in input().split()]))

Submission status: Accepted

Solution code:
n=int(input())
a=list(map(int,input().split()))
l=[]
for i in range(n):
    l.append(a[i]-1)
print(sum(l))

Submission status: Accepted

Solution code:
n=int(input())
a=list(map(int,input().split()))
ans=0
for i in a:
    ans+= i-1
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())
A = [int(a) for a in input().split()]
ans = 0
for n in range(N):
  ans += A[n] - 1
print(ans)

Submission status: Accepted

Solution code:
import fractions
N = int(input())
a = list(map(int, input().split()))

lcm = a[0]
for item in a[1:]:
    lcm = (lcm * item) // fractions.gcd(lcm, item)
f = 0
for item in a:
    f += (lcm - 1) % item
print(f)

Submission status: Accepted

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


def GCD(a, b):
    if a < b:
        a, b = b, a
    if b == 0:
        return a
    else:
        return GCD(b, a % b)


def LCM(a, b):
    return a * b//GCD(a, b)


m = a[0]
for ni in range(1, n):
    m = LCM(m, a[ni])

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

print(ans)

Submission status: Accepted

Solution code:
N = int(input())
alist = list(map(int, input().split()))
alist = list(map(lambda x: x-1, alist))

print(sum(alist))

Submission status: Accepted

Solution code:
#証明してない
n = int(input())
a = list(map(int,input().split()))
print(sum(a)-n)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
import sys
import copy
import collections
from bisect import bisect_left
from bisect import bisect_right
from collections import defaultdict
from heapq import heappop, heappush
import numpy as np

def main():
	N = int(input())
	A = list(map(int, input().split(" ")))
	
	ans = A[0]
	for i, val in enumerate(A):
		if i == 0:
			continue
		ans = lcm(ans, val)
		
	ans -= 1
	tmp = 0
	for i, val in enumerate(A):
		tmp = tmp + (ans % val)
	
	print(tmp)
	
def gcd(a, b):
	if a > b:
		a, b = b, a
		
	while a > 0:
		a, b = b % a, a
	return b
	
def lcm(a, b):
	g = gcd(a, b)
	return a // g * b
	
if __name__ == "__main__":
	main()

Submission status: Accepted

Solution code:
_ = input()
ag = list(map(int, input().split()))
print(sum(ag)-len(ag))

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int, input().split()))
sum_a = 0

for i in range(N):
    sum_a += A[i] - 1

print(sum_a)

Submission status: Accepted

Solution code:
from functools import reduce


def gcd(x, y):
    if not x:
        return y
    return gcd(y % x, x)


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


n = int(input())
arr = list(map(int, input().split()))
lcm_arr = reduce(lcm, arr) - 1

print(sum([lcm_arr % x for x in arr]))

Submission status: Accepted

Solution code:
N = int(input())
A = map(int, input().split())

print(sum(A) - N)

Submission status: Accepted

Solution code:
N =int(input())
l = [int(i)-1 for i in input().split()]
print(sum(l))

Submission status: Accepted

Solution code:
from itertools import accumulate
from fractions import gcd
def lcm_(x,y):
    return x*y//gcd(x,y)
def lcm(numbers):
    return list(accumulate(numbers,lcm_))
n=int(input())
A=[int(i) for i in input().split()]
L=lcm(A)[-1]-1
f=0
for i in A:
    f+=L%i

print(f)

Submission status: Accepted

Solution code:
# 全ての積-1のとき
N = int(input())
A = [int(x) for x in input().split()]
answer = sum(A) - len(A)
print(answer)

Submission status: Accepted

Solution code:
N = int(input())
A = [int(i)-1 for i in input().split()]

print(sum(A))

Submission status: Accepted

Solution code:
from fractions import gcd

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

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

Submission status: Accepted

Solution code:
N = int(input())
a_s = list(map(int, input().split()))

print(sum(a_s)-len(a_s))

Submission status: Accepted

Solution code:
#!/usr/bin/env python
N = int(input())
A = [int(i) for i in input().split()]

ans = 0
for a in A:
    ans += a - 1
print(ans)

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int, input().split()))
ans = 0
for i in range(N):
    ans += A[i] - 1
print(ans)

Submission status: Accepted

Solution code:
def euc(x, y):
	if y == 0: return x
	return euc(y, x%y)

N = int(raw_input())
A = map(int, raw_input().split())
x = A[0]
for i in range(1, N):
	x = x * A[i] / euc(x, A[i])
sum = 0
for i in range(0, N):
	sum += (x-1) % A[i]
print sum

Submission status: Accepted

Solution code:
N = int(input())
As = list(map(int,input().split()))

amari = [a-1 for a in As]
print(sum(amari))

Submission status: Accepted

Solution code:
n = int(input())
a = [int(_) for _ in input().split()]
ans = 0
for i in range(n):
    ans += a[i] - 1
print(ans)

Submission status: Accepted

Solution code:
N, *a = map(int, open(0).read().split())
print(sum(a) - N)

Submission status: Accepted

Solution code:
print(-int(input())+sum(list(map(int, input().split()))))

Submission status: Accepted

Solution code:
# sys.stdin.readline()
import sys
input = sys.stdin.readline

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

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
import sys


def solve(N: int, A: "List[int]"):
    print(sum(A)-N)


# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    a = [ int(next(tokens)) for _ in range(N) ]  # type: "List[int]"
    solve(N, a)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
n=int(input())
da=list(map(int,input().split()))
ans=0
for i in da:
  ans+=i-1
print(ans)

Submission status: Accepted

Solution code:
n = int(input())
lst = list(map(int, input().rstrip().split()))
ans = 0
for i in lst:
    ans += i - 1
print(ans)

Submission status: Accepted

Solution code:
# ABC103C - Modulo Summation
from fractions import gcd


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


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

Submission status: Accepted

Solution code:
import sys, os

f = lambda:list(map(int,input().split()))
if 'local' in os.environ :
    sys.stdin = open('./input.txt', 'r')

def solve():
    n = f()[0]
    a = f()

    print(sum(a) - n)

solve()

Submission status: Accepted

Solution code:
N = int(input())
a = [int(t) for t in input().split()]

print(sum(a) - N)

Submission status: Accepted

Solution code:
from fractions import gcd
n = int(input())
a = list(map(int, input().split()))

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

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

Submission status: Accepted

Solution code:
n = input()
x = list(map(int , input().split()))

print(sum([xs-1 for xs in x]))

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
from fractions import gcd

N = int(input())
A = list(map(int, input().split()))
lcm = 1
for a in A:
  d = gcd(lcm, a)
  lcm = a * lcm // d
ans = 0
for a in A:
  ans += (lcm - 1) % a
print(ans)

Submission status: Accepted

Solution code:
from sys import stdin
import fractions

N = int(stdin.readline().rstrip())
A = [int(x) for x in stdin.readline().rstrip().split()]

lcm_a = A[0] * A[1] // fractions.gcd(A[0], A[1])

if len(A) > 2:
    for k in A[2:]:
        lcm_a = lcm_a * k // fractions.gcd(lcm_a, k)

modulo_sum = 0

for k in A:
    modulo_sum += (lcm_a - 1) % k

print(modulo_sum)

Submission status: Accepted

Solution code:
from sys import stdin
import fractions

N = int(stdin.readline().rstrip())
A = [int(x) for x in stdin.readline().rstrip().split()]

lcm_a = int(A[0] * A[1]) // fractions.gcd(A[0], A[1])

if len(A) > 2:
    for k in A[2:]:
        lcm_a = int(lcm_a * k) // fractions.gcd(lcm_a, k)

modulo_sum = 0

for k in A:
    modulo_sum += (lcm_a - 1) % k

print(modulo_sum)

Submission status: Accepted

Solution code:
from sys import stdin

N = int(stdin.readline().rstrip())
A = [int(x) for x in stdin.readline().rstrip().split()]

lcm_a = A[0] * A[1]

if len(A) > 2:
    for k in A[2:]:
        lcm_a = lcm_a * k

modulo_sum = 0

for k in A:
    modulo_sum += (lcm_a - 1) % k

print(modulo_sum)

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int,input().split(' ')))
print(sum(A) - len(A))

Submission status: Accepted

Solution code:
N = int(input())
a = list(map(int, input().split()))
for i in range(N):
	a[i] -= 1
print(sum(a))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
import sys


def solve(N: int, a: "List[int]"):
    ret = sum(a) - N
    print(ret)
    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    a = [ int(next(tokens)) for _ in range(N) ]  # type: "List[int]"
    solve(N, a)

if __name__ == '__main__':
    main()

Submission status: Accepted

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

ans = 0
for x in a:
  ans += x -1
  
print(ans)

Submission status: Accepted

Solution code:
input()
r = sum(map(lambda x: x-1, map(int, input().split())))
print(r)

Submission status: Accepted

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

p = sum(A) - N
print(p)

Submission status: Accepted

Solution code:
n = int(input())

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

Submission status: Accepted

Solution code:
###############################################################################

from sys import stdout
from bisect import bisect_left as binl
from copy import copy, deepcopy
from collections import defaultdict


mod = 1


def intin():
    input_tuple = input().split()
    if len(input_tuple) <= 1:
        return int(input_tuple[0])
    return tuple(map(int, input_tuple))


def intina():
    return [int(i) for i in input().split()]


def intinl(count):
    return [intin() for _ in range(count)]


def modadd(x, y):
    global mod
    return (x + y) % mod


def modmlt(x, y):
    global mod
    return (x * y) % mod


def lcm(x, y):
    while y != 0:
        z = x % y
        x = y
        y = z
    return x


def combination(x, y):
    assert(x >= y)

    if y > x // 2:
        y = x - y

    ret = 1

    for i in range(0, y):
        j = x - i
        i = i + 1

        ret = ret * j
        ret = ret // i

    return ret


def get_divisors(x):
    retlist = []
    for i in range(1, int(x**0.5) + 3):
        if x % i == 0:
            retlist.append(i)
            retlist.append(x // i)
    return retlist


def get_factors(x):
    retlist = []
    for i in range(2, int(x**0.5) + 3):
        while x % i == 0:
            retlist.append(i)
            x = x // i
    retlist.append(x)
    return retlist


def make_linklist(xylist):
    linklist = {}
    for a, b in xylist:
        linklist.setdefault(a, [])
        linklist.setdefault(b, [])
        linklist[a].append(b)
        linklist[b].append(a)
    return linklist


def calc_longest_distance(linklist, v=1):
    distance_list = {}
    distance_count = 0
    distance = 0
    vlist_previous = []
    vlist = [v]
    nodecount = len(linklist)

    while distance_count < nodecount:
        vlist_next = []
        for v in vlist:
            distance_list[v] = distance
            distance_count += 1
            vlist_next.extend(linklist[v])
        distance += 1
        vlist_to_del = vlist_previous
        vlist_previous = vlist
        vlist = list(set(vlist_next) - set(vlist_to_del))

    max_distance = -1
    max_v = None
    for v, distance in distance_list.items():
        if distance > max_distance:
            max_distance = distance
            max_v = v

    return (max_distance, max_v)


def calc_tree_diameter(linklist, v=1):
    _, u = calc_longest_distance(linklist, v)
    distance, _ = calc_longest_distance(linklist, u)
    return distance


###############################################################################


def main():
    n = intin()
    alist = intina()

    ans = 0
    for a in alist:
        ans += (a - 1)
    print(ans)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
n=int(input())
a_list=list(map(int,input().split()))
Sum=0
for i in a_list:
    Sum=Sum+i-1
print(Sum)

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int, input().split()))
print(sum(i-1 for i in A))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())
lst = list(map(int, input().split()))

print (sum(lst)-N)

Submission status: Accepted

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

Submission status: Accepted

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

print(sum(A)-N)

Submission status: Accepted

Solution code:
from functools import reduce
from fractions import gcd
input()
aa=list(map(int,input().split()))
lcm=reduce((lambda a,b:a*b//gcd(a,b)),aa)
m=lcm-1
print(sum(m%a for a in aa))

Submission status: Accepted

Solution code:
N=int(input())
A=list(map(int, input().split()))
ans=sum(A)-N
print(ans)

Submission status: Accepted

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

def GCD(a,b):
    c = a%b
    if c == 0:
        return b
    else:
        return GCD(b,c)


def modsum(m):
    s = 0
    for a in A:
        s += m % a
    return s


tmp = 1
for i in range(N):
    tmp = tmp * A[i] // GCD(tmp,A[i])
    
ans = modsum(tmp-1)
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline

N = int(input())
L = [int(v) for v in input().split()]

m = 1
for v in L:
    m = m * v
m = m - 1
ans = sum([m % v for v in L])
print(ans)

Submission status: Accepted

Solution code:

def main():
    num = int(input())
    data = list(map(int, input().split()))
    ans = 0
    for ele in data:
        ans += (ele - 1)

    print(ans)




if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
N = int(input())
a = sum([int(i) for i in input().split()])
print(a - N)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())
a = list(map(int, input().split()))
num = 0
for i in a:
    num += i - 1

print(num)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# coding: utf-8
N = int(input())
a = list(map(int, input().split()))
ans = 0
for i in range(N):
	ans += a[i] - 1
print(ans)

Submission status: Accepted

Solution code:
from fractions import gcd
N = int(input())
A = list(map(int,input().split()))

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

l = A[0]
for i in range(1,N):
    l = lcm(l,A[i])
l -= 1

ans = 0
for a in A: ans += l % a
print(ans)

Submission status: Accepted

Solution code:
N = int(input())
l = list(map(int,input().split()))
ans = 0
for i in range(N):
    ans += l[i]-1
print(ans)

Submission status: Accepted

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


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


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


def f(m):
    global A
    return sum([m % x for x in A])


m = lcm_list(A) - 1


print(f(m))

Submission status: Accepted

Solution code:
import fractions
from functools import reduce

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

N = int(input())
A = list(map(int,input().split()))
M = lcm_list(A) - 1
ans = 0

for i in range(N):
    ans += M % A[i]

print(ans)

Submission status: Accepted

Solution code:
from fractions import gcd

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

N = int(input())
a = list(map(int, (input().split())))
l = (a[0] * a[1]) // gcd(a[0], a[1])

for i in a[2:]:
    l = lcm(l, i)

l -= 1

ans = sum(map(lambda x: l%x , a))
print(ans)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
import sys
from math import *
from itertools import *
from collections import *
from functools import *
import operator
try:
    from math import gcd
except Exception:
    from fractions import gcd


def solve(N: int, a: "List[int]"):
    m = reduce(operator.mul, a) - 1
    return sum([m % x for x in a])


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    a = [ int(next(tokens)) for _ in range(N) ]  # type: "List[int]"
    result = solve(N, a)
    print(result)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
n=int(input())
lista = [int(i) for i in input().split()]
#最小公倍数-1を取ればいい
print(sum(lista)-n)

Submission status: Accepted

Solution code:
N = int(input())
A = [int(c) for c in input().split()]

print(sum(A) - N)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
import numpy as np
import math
import re

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

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

Submission status: Accepted

Solution code:
N = int(input())
ai = [int(x) for x in input().split()]

print(sum(ai)-N)

Submission status: Accepted

Solution code:
n = int(input())
a = [int(i) for i in input().split()]
x = 0
for i in range(n):
    x += a[i] - 1

print(x)

Submission status: Accepted

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

print(sum(list(map(lambda ai: ai-1, A))))

Submission status: Accepted

Solution code:
n = int(input())
ans = 0

amari = list(map(int,input().split()))
    
for i in amari:
    ans += i-1
    
print(ans)

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int,input().split()))
sum = 0
for i in range(n):
    sum = sum + a[i] - 1
print(sum)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from functools import reduce


def gcd(a,b):
  x = max([a,b])
  y = min([a,b])
  while y:
    x, y = y, x % y
  return x

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

def lcm_list(nums):
  return reduce(lcm, nums)
n = int(input())

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




m = lcm_list(a) - 1


ans = 0
for i in range(n):
  ans += m % a[i]
  
  
print(ans)

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline

n = int(input())

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

print(sum(a) - len(a))

Submission status: Accepted

Solution code:
N = int(input())
s = list(map(int,input().split(" ")))
ans = sum(s) - N 
print(ans)

Submission status: Accepted

Solution code:
N = int(input())
a = list(map(int, input().split()))
s = 0
for i in range(N):
  s += a[i] - 1
print(s)

Submission status: Accepted

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

Submission status: Accepted

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