#!/usr/bin/ python3.8 import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines from functools import reduce U = 10 ** 5 N, *A = map(int, read().split()) num_count = [0] * (U + 1) for x in A: num_count[x] += 1 save_cost = [0] * (U + 1) for d in range(2, U + 1): save_cost[d] = sum((n - n // d) * num_count[n] for n in range(d, U + 1, d)) def gcd(a, b): if a < b: a, b = b, a while b: LA = a.bit_length() LB = b.bit_length() a ^= b << (LA - LB) if a < b: a, b = b, a return a g = reduce(gcd, A) cand = [g] for i in range(1, 17): cand += [x ^ (g << i) for x in cand] max_save = 0 for d in cand: if 1 <= d <= U: x = save_cost[d] if max_save < x: max_save = x answer = sum(A) - max_save print(answer)