import sys from itertools import combinations from math import gcd from functools import reduce def all_coprime(numbers): """ 与えられた数字のリストが互いに素であるかをチェックする """ return all(gcd(numbers[i], numbers[j]) == 1 for i in range(len(numbers)) for j in range(i + 1, len(numbers))) def max_sum_coprime(numbers): """ 互いに素な数字の組み合わせの中で最大の合計を見つける """ n = len(numbers) max_sum = 0 # すべての部分集合を考慮する for i in range(1, 1 << n): subset = [numbers[j] for j in range(n) if i & (1 << j)] if all_coprime(subset): max_sum = max(max_sum, sum(subset)) return max_sum def main(): input = sys.stdin.read data = input().split() K = int(data[0]) numbers = list(map(int, data[1:K+1])) print(max_sum_coprime(numbers)) if __name__ == "__main__": main()