AtCoder Beginner Contest 103 - Modulo Summation

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-----
3
3 4 6

-----Sample Output-----
10

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

Difficulty: EASY

Starter code:

Solutions:
lis = []
N = int(input())
a = list(map(int, input().split()))
print(sum(a) - N)


input()
print(sum([a - 1 for a in map(int, input().split())]))


import sys
input = sys.stdin.readline
n = int(input())
a = list(map(int, input().split()))
import math
r = 0
for ii in range(1, n):
	r = r * a[ii] // math.gcd(r, a[ii])

def func(x):
	y = 0
	for aa in a:
		y += x % aa
	return y
print(func(r - 1))


N = int(input())
A = [int(c) for c in input().split()]
print(sum(A) - N)


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


input()
print(sum(map(lambda e: int(e) - 1, input().split())))


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


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 lcm_list(numbers):
	return reduce(lcm_base, numbers, 1)
import sys
input = sys.stdin.readline
N = int(input())
a = list(map(int, input().split()))
saisyo_koubaisu = lcm_list(a)
ans = 0
for aa in a:
	ans += (saisyo_koubaisu - 1) % aa
print(ans)


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


(N, *A) = map(int, open(0).read().split())
print(sum((a - 1 for a in A)))


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


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


n = int(input())
l = list(map(lambda x: int(x) - 1, input().split()))
print(sum(l))


n = int(input())
print(sum([int(a) - 1 for a in input().split()]))


n = input()
print(sum([int(x) - 1 for x in input().split()]))


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


from math import gcd
from functools import reduce

def lcm(x, y):
	return x * y // gcd(x, y)
(N, *A) = list(map(int, open(0).read().split()))
l = reduce(lcm, A) - 1
print(sum((l % a for a in A)))


def main():
	n = int(input())
	a_lst = list(map(int, input().split()))
	maximum = sum(a_lst) - n
	print(maximum)

def __starting_point():
	main()
__starting_point()


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


N = int(input())
lis = map(int, input().split())
print(sum(lis) - N)


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

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

def lcm(x, y):
	return x * y // gcd(x, y)
m = a[0]
for i in range(n):
	m = lcm(m, a[i])
m -= 1
ans = 0
for i in range(n):
	ans += m % a[i]
print(ans)


import math
from functools import reduce

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

def lcm_list(numbers):
	return reduce(lcm, numbers, 1)
N = int(input())
A = list(map(int, input().split()))
MOD = lcm_list(A) - 1
ans = 0
for a in A:
	ans += MOD % a
print(ans)


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


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


N = int(input())
A = [int(zz) for zz in input().split()]
print(sum(A) - N)


import math
N = int(input())
a = list(map(int, input().split()))
ans = a[0]
for i in range(1, N):
	ans = ans * a[i] // math.gcd(ans, a[i])
tmp = ans - 1
mod = 0
f = 0
for i in range(N):
	mod = tmp % a[i]
	f += mod
print(f)


import sys
input = sys.stdin.readline
import numpy as np

def main():
	numbers = []
	n = int(input())
	numbers = np.array(list(map(int, input().split())))
	print((numbers - 1).sum())

def __starting_point():
	main()
__starting_point()


x = int(input())
y = list(map(int, input().split()))
print(sum(y) - x)


N = input()
a = list(map(int, input().split()))
ans = []
for ai in a:
	ans.append(ai - 1)
print(sum(ans))


N = int(input())
A = map(int, input().split())
print(sum(A) - N)


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


input()
print(sum((int(i) - 1 for i in input().split())))


n = int(input())
a = [int(x) for x in input().split()]
print(sum(a) - n)


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


n = int(input())
res = sum([int(i) - 1 for i in input().split()])
print(res)


n = input()
a = [int(b) for b in input().split()]
print(sum(a) - len(a))


import fractions
N = int(input())
a = list(map(int, input().split()))
ans = sum(a) - N
print(ans)


n = int(input())
L = list(map(int, input().split()))
from math import gcd
from functools import reduce

def lcm(x, y):
	return x * y // gcd(x, y)
a = reduce(lcm, L)
ans = 0
for i in range(n):
	ans += (a - 1) % L[i]
print(ans)


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


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


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


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


n = int(input())
print(sum([int(i) for i in input().split()]) - n)


_ = input()
As = list(map(int, input().split()))
print(sum(As) - len(As))


N = int(input())
print(sum([int(a) - 1 for a in input().split()]))


print(-int(input()) + eval(input().replace(' ', '+')))


N = int(input())
t = [int(i) for i in input().split()]
print(sum(t) - N)


def f(m):
	ans = 0
	for i in range(len(a)):
		ans += m % a[i]
	return ans
n = int(input())
a = list(map(int, input().split()))
print(sum(a) - n)


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


import math
N = int(input())
List = list(map(int, input().split()))
mid = List[0]
for i in range(1, N):
	mid = mid * List[i] // math.gcd(mid, List[i])
res = 0
for i in range(N):
	res += (mid - 1) % List[i]
print(res)


import numpy as np
input()
print(sum(np.array(list(map(int, input().split()))) - 1))


input()
print(sum(list(map(lambda x: int(x) - 1, input().split()))))


print(sum((i - 1 for i in list(map(int, open(0).read().split()))[1:])))


N = int(input())
A = [int(x) - 1 for x in input().split()]
print(sum(A))


N = int(input())
A = [int(a) for a in input().split()]
print(sum(A) - N)


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


N = int(input())
AN = map(int, input().split())
print(sum(AN) - N)


from fractions import gcd
N = int(input())
a = list(map(int, input().split()))

def lcm(A):
	x = A[0]
	for i in range(1, len(a)):
		x = x * A[i] // gcd(x, A[i])
	return x
n = lcm(a) - 1
ans = 0
for v in a:
	ans += n % v
print(ans)


N = int(input())
a = [int(n) for n in input().split()]
print(sum(a) - N)


N = int(input())
a = [int(t) for t in input().split()]
print(sum(a) - N)


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


input()
print(sum([i - 1 for i in list(map(int, input().split()))]))


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

def lcm(x, y):
	return x * y // math.gcd(x, y)
l = 1
for i in range(n):
	l = lcm(l, a[i])
ans = 0
for i in range(n):
	ans += (l - 1) % a[i]
print(ans)


N = int(input())
print(sum(map(lambda c: int(c) - 1, input().split())))


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


N = int(input())
A = list(map(int, input().split()))
print(str(sum(A) - N))


N = int(input())
S = list(map(int, input().split()))
print(sum(S) - len(S))


(*a,) = map(int, open(0).read().split())
print(sum(a[1:]) - a[0])


N = int(input())
print(sum(tuple(map(int, input().split(' ')))) - N)


N = int(input())
L = [int(i) for i in input().split()]
print(sum(L) - N)


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


def solve(N, a):
	print(sum([ai - 1 for ai in a]))

def __starting_point():
	N = int(input())
	a = [int(i) for i in input().split()]
	solve(N, a)
__starting_point()


def get_input() -> tuple:
	N = int(input())
	a = list(map(int, input().split()))
	return (N, a)

def main(N: int, a: list) -> None:
	ans = sum(a) - N
	print(ans)

def __starting_point():
	(N, a) = get_input()
	main(N, a)
__starting_point()


input()
lst = [int(x) - 1 for x in input().split()]
print(sum(lst))


(n, a) = open(0)
print(sum(map(int, a.split())) - int(n))


import fractions

def lcm(a, N):
	ans = a[0]
	for i in range(1, N):
		ans = ans * a[i] // fractions.gcd(ans, a[i])
	return ans

def main():
	N = int(input())
	A = list(map(int, input().split()))
	num = lcm(A, N) - 1
	answer = 0
	for i in A:
		answer += num % i
	print(answer)

def __starting_point():
	main()
__starting_point()


N = int(input())
print(sum([int(s) - 1 for s in input().split()]))


n = int(input())
a = map(int, input().split())
b = []
for i in a:
	b.append(i - 1)
print(sum(b))


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


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


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


[n] = [int(i) for i in input().split()]
li = [int(i) for i in input().split()]
ans = 0
for i in li:
	ans += i
print(ans - n)


print(-int(input()) + sum(map(int, input().split())))


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


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


import bisect, collections, copy, heapq, itertools, math, string, sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(10 ** 7)
INF = float('inf')

def I():
	return int(input())

def F():
	return float(input())

def SS():
	return input()

def LI():
	return [int(x) for x in input().split()]

def LI_():
	return [int(x) - 1 for x in input().split()]

def LF():
	return [float(x) for x in input().split()]

def LSS():
	return input().split()

def resolve():
	N = I()
	a = LI()
	ans = sum([i - 1 for i in a])
	print(ans)

def __starting_point():
	resolve()
__starting_point()


N = int(input())
A = list(map(int, input().split()))
all = sum(A)
print(all - N)


N = input()
print(sum([i - 1 for i in map(int, input().split())]))


input()
(*a,) = map(int, input().split())
print(sum(a) - len(a))


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


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 = list(map(int, input().split()))
lcm = lcm_list(l)
ans = 0
for i in l:
	ans += (lcm - 1) % i
print(ans)


(N, A) = open(0)
print(sum(map(int, A.split())) - int(N))


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

def __starting_point():
	main()
__starting_point()


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


import math
N = int(input())
a = list(map(int, input().split()))
prod = a[0]
lcm = a[0]
for i in range(1, N):
	x = math.gcd(lcm, a[i])
	lcm = lcm * a[i] // x
m = lcm - 1
ans = 0
for i in a:
	ans += m % i
print(ans)


N = int(input())
a = list(map(int, input().split()))
ans = 0
for x in a:
	ans += x - 1
print(ans)


N = int(input())
A = [int(_) for _ in input().split()]
print(sum(A) - N)


import math
from functools import reduce
n = int(input())
a_list = map(int, input().split())
result = 0
for a in a_list:
	result += a - 1
print(result)


N = int(input())
a = list(map(int, input().split()))
a.sort(reverse=True)
ans = 0
(val1, val2) = (a[0], a[1])
while 1:
	if val1 % val2 == 0:
		ans = a[0] * a[1] // val2
		break
	else:
		tmp = val2
		val2 = val1 % val2
		val1 = tmp
for i in range(2, N):
	(val1, val2) = (ans, a[i])
	while 1:
		if val1 % val2 == 0:
			ans *= a[i] // val2
			break
		else:
			tmp = val2
			val2 = val1 % val2
			val1 = tmp
f_ans = 0
for i in range(N):
	f_ans += (ans - 1) % a[i]
print(int(f_ans))


N = int(input())
list_a = map(int, input().split())
print(sum(list_a) - N)


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


a = int(input())
b = [int(i) for i in input().split()]
print(sum(b) - a)


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


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

def __starting_point():
	main()
__starting_point()


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
f = sum([m % item for item in a])
print(f)


(N, *A) = map(int, open(0).read().split())
m = 1
ans = 0
for a in A:
	ans += a - 1
print(ans)


import math

def lcm(a, b):
	return a * b // math.gcd(a, b)
n = int(input())
a = list(map(int, input().split()))
ans = lcm(a[0], a[1])
for i in range(1, n):
	ans = lcm(ans, a[i])
m = 0
for i in a:
	m += (ans - 1) % i
print(m)


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


import sys
pin = sys.stdin.readline

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

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

def main():
	N = int(pin())
	a = list(map(int, pin().split()))
	s = a[0]
	for i in range(N - 1):
		s = lcm(a[i + 1], s)
	ans = 0
	for i in a:
		ans += (s - 1) % i
	print(ans)
	return
main()


N = int(input())
S = sum(map(int, input().split()))
print(S - N)


input()
print(sum((int(_) - 1 for _ in input().split())))


N = int(input())
A = [int(i) - 1 for i in input().split()]
print(sum(A))


N = int(input())
A = list(map(int, input().split()))
t = 0
print(sum(A) - N)


import math
N = int(input())
A = list(map(int, input().split()))
A = list(map(lambda x: int(math.copysign(x - 1, x)), A))
print(sum(A))


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


N = int(input())
sum_a = sum(map(int, input().split()))
print(sum_a - N)


n = input()
print(sum([int(i) - 1 for i in list(input().split())]))


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


print((lambda a, b: sum(b) - int(a))(input(), list(map(int, input().split()))))


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


N = int(input())
l = [int(v) - 1 for v in input().split()]
print(sum(l))


input()
print(eval(input().replace(' ', '-1+')) - 1)


from math import gcd
n = int(input())
A = list(map(int, input().split()))
ans = 0
for a in A:
	ans += a - 1
print(ans)


import math
from math import gcd, pi, sqrt
INF = float('inf')
import sys
sys.setrecursionlimit(10 ** 6)
import itertools
from collections import Counter, deque

def i_input():
	return int(input())

def i_map():
	return list(map(int, input().split()))

def i_list():
	return list(i_map())

def i_row(N):
	return [i_input() for _ in range(N)]

def i_row_list(N):
	return [i_list() for _ in range(N)]

def s_input():
	return input()

def s_map():
	return input().split()

def s_list():
	return list(s_map())

def s_row(N):
	return [s_input for _ in range(N)]

def s_row_str(N):
	return [s_list() for _ in range(N)]

def s_row_list(N):
	return [list(s_input()) for _ in range(N)]

def main():
	n = i_input()
	a = i_list()
	ans = 0
	for i in a:
		ans += i - 1
	print(ans)

def __starting_point():
	main()
__starting_point()


S = input()
(*a,) = map(int, input().split())
print(sum(a) - int(S))


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


input()
print(sum((int(tok) - 1 for tok in input().split())))


import math
N = int(input())
a = list(map(int, input().split()))
lcm = 1
for i in range(N):
	lcm = lcm * a[i] // math.gcd(a[i], lcm)
print(sum(((lcm - 1) % a[i] for i in range(N))))


N = int(input())
a = [int(s) for s in input().split()]
print(sum(a) - N)


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


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


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


N = int(input())
a = [int(_) for _ in input().split()]
print(sum(a) - N)


import math
N = int(input())
lsa = list(map(int, input().split()))
lcm = lsa[0]
for i in range(1, N):
	lcm = lcm * lsa[i] // math.gcd(lcm, lsa[i])
m = lcm - 1
ans = 0
for i in range(N):
	ans += m % lsa[i]
print(ans)


N = int(input())
A = map(int, input().split())
print(sum([a - 1 for a in A]))


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


N = int(input())
H = [int(i) for i in input().split()]
print(sum(H) - N)


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


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


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(*numbers):
	return reduce(lcm_base, numbers, 1)
ans = 0
lcm = lcm(*A)
for a in A:
	ans += (lcm - 1) % a
print(ans)


(n, *a) = map(int, open(0).read().split())
print(sum([i - 1 for i in a]))


import sys
import math
from collections import defaultdict, deque, Counter
from copy import deepcopy
from bisect import bisect, bisect_right, bisect_left
from heapq import heapify, heappop, heappush
input = sys.stdin.readline

def RD():
	return input().rstrip()

def F():
	return float(input().rstrip())

def I():
	return int(input().rstrip())

def MI():
	return map(int, input().split())

def MF():
	return map(float, input().split())

def LI():
	return list(map(int, input().split()))

def TI():
	return tuple(map(int, input().split()))

def LF():
	return list(map(float, input().split()))

def Init(H, W, num):
	return [[num for i in range(W)] for j in range(H)]

def main():
	N = I()
	L = LI()
	ans = 0
	for i in L:
		ans += i - 1
	print(ans)

def __starting_point():
	main()
__starting_point()


import sys
sys.setrecursionlimit(10 ** 8)
ini = lambda : int(sys.stdin.readline())
inl = lambda : [int(x) for x in sys.stdin.readline().split()]
ins = lambda : sys.stdin.readline().rstrip()
debug = lambda *a, **kw: print('\x1b[33m', *a, '\x1b[0m', **dict(file=sys.stderr, **kw))

def solve():
	n = ini()
	a = inl()
	ans = 0
	for x in a:
		ans += x - 1
	return ans
print(solve())