#!/bin/python3 def longestSequence(a): # Return the length of the longest possible sequence of moves. max_stick_len = max(a) max_moves = [0] * (max_stick_len + 1) max_moves[1] = 1 # Fill max_lengths array all the way up to max_stick_len current_idx = 2 while current_idx < len(max_moves): max_possible_moves = 0 # SPEED UP HERE; This can be made faster for i in range(2, current_idx + 1): if current_idx % i == 0: # Figure out the max moves if we divide into i pieces piece_size = current_idx // i # Num moves is equal to 1 (for the break) + (# of pieces into # which the current piece is broken * max num moves for that piece size) num_moves = 1 + (i * max_moves[piece_size]) if num_moves > max_possible_moves: max_possible_moves = num_moves max_moves[current_idx] = max_possible_moves current_idx += 1 current_total_moves = 0 for num in a: current_total_moves += max_moves[num] return current_total_moves if __name__ == "__main__": n = int(input().strip()) a = list(map(int, input().strip().split(' '))) result = longestSequence(a) print(result)