#!/bin/python3 import sys def longestSequence(a): # Return the length of the longest possible sequence of moves. def findme(x): curr_max = x+1 for j in range(2,(x//2)+1): remainder = x % j if remainder != 0: continue piece = x // j #if save[j] == -1: #if j >= 10001: if j not in save.keys(): save[j] = findme(j) #print(j) #print(save[j]) if 1 + save[j] * piece > curr_max: curr_max = 1 + save[j] * piece else: if 1 + save[j] * piece > curr_max: curr_max = 1 + save[j] * piece return curr_max save = {} #for i in range(0,10001): # save.append(-1) save[0] = 0 save[1] = 1 save[2] = 3 save[3] = 4 #for i in range(4,10001): # curr_max = i+1 # max_elem = 1 # for j in range(2,(i//2)+1): # if i % j == 0: #and j <= i//2: # piece = i // j # temp = 1 + save[j] * piece # if temp > curr_max: # curr_max = temp # max_elem = j # save[i] = curr_max total = 0 for elem in a: #if elem >= 10001: if elem not in save.keys(): save[elem] = findme(elem) #total += save[elem] #else: total += save[elem] return total if __name__ == "__main__": n = int(input().strip()) a = list(map(int, input().strip().split(' '))) result = longestSequence(a) print(result)