n = int(input())
a = map(int, [input() for i in range(n)])

x = 0
while True:
  data = map(lambda a: a + x, a)
  data1 = data.sort()
  if len(data1) == len(set(data1)):
    break:
  else:
    x += 1

print(x * n)