#include <bits/stdc++.h>
using namespace std;
template <typename T>
void __read(T &a) {
  cin >> a;
}
template <typename T, typename... Args>
void __read(T &a, Args &...args) {
  cin >> a;
  __read(args...);
}
constexpr long long M7 = 1000000007ll;
constexpr long long M9 = 1000000009ll;
constexpr long long MFFT = 998244353ll;
template <class T>
void outv(T &a) {
  for (auto &x : a) cout << x << ' ';
}
static mt19937 rnd(static_cast<unsigned>(
    chrono::steady_clock::now().time_since_epoch().count()));
template <class T>
static auto __super_speed__ = (ios_base::sync_with_stdio(0), cin.tie(0));
vector<vector<pair<long long, long long>>> g;
vector<long long> w;
const long long MAXK = 5000;
void add_edge(long long v, long long u, long long w) {
  g[u].emplace_back(v, w);
  g[v].emplace_back(u, w);
}
long long current = 0;
long long add_vertex() {
  g.emplace_back();
  w.emplace_back();
  return current++;
}
vector<long long> prime_divisors(long long num) {
  vector<long long> res;
  long long d = 2;
  while (d * d <= num) {
    while (num % d == 0) {
      res.push_back(d);
      num /= d;
    }
    d++;
  }
  if (num != 1) {
    res.push_back(num);
  }
  return res;
}
vector<long long> cc, res;
void dfs1(long long v, long long p) {
  cc[v] = w[v];
  for (auto &[u, w] : g[v]) {
    if (u != p) {
      dfs1(u, v);
      cc[v] += cc[u];
      res[v] += res[u] + cc[u] * w;
    }
  }
}
long long dfs2(long long v, long long p = -1, long long w_p = 0) {
  if (p != -1) {
    cc[v] += cc[p];
    res[v] += res[p] + cc[p] * w_p;
  }
  long long ans = res[v];
  if (ans < 0) {
    long long asdas = 0;
  }
  for (auto [u, w] : g[v]) {
    if (u != p) {
      res[v] -= res[u] + cc[u] * w;
      cc[v] -= cc[u];
      ans = min(ans, dfs2(u, v, w));
      cc[v] += cc[u];
      res[v] += res[u] + cc[u] * w;
    }
  }
  if (p != -1) {
    cc[v] -= cc[p];
    res[v] -= res[p] + cc[p] * w_p;
  }
  return ans;
}
int32_t main() {
  long long n;
  __read(n);
  vector<long long> cnt(MAXK + 1);
  for (long long i = 0; i < n; ++i) {
    long long q;
    __read(q);
    cnt[q]++;
  }
  current = 0;
  stack<tuple<long long, long long, long long>> st;
  long long st_w = 0;
  add_vertex();
  w[0] = cnt[0] + cnt[1];
  vector<long long> div(MAXK + 1);
  long long cnt_div = 0;
  for (long long i = 2; i <= MAXK; ++i) {
    vector<long long> d = prime_divisors(i);
    auto next_div = div;
    for (auto &q : d) {
      next_div[q]++;
    }
    long long sm = 0;
    for (long long j = MAXK; j >= 2; --j) {
      sm += div[j];
      if (div[j] != next_div[j]) {
        break;
      }
    }
    while (!st.empty() && st_w - get<0>(st.top()) >= sm) {
      auto [weight, v, u] = st.top();
      st_w -= weight;
      st.pop();
      add_edge(v, u, weight);
    }
    if (!st.empty() && st_w > sm) {
      auto [weight, v, u] = st.top();
      st.pop();
      long long m = add_vertex();
      long long lw = sm - st_w + weight, rw = st_w - sm;
      add_edge(m, u, rw);
      st.emplace(lw, v, m);
    }
    cnt_div += d.size();
    long long u = add_vertex();
    w[u] += cnt[i];
    long long v = st.empty() ? 0 : get<2>(st.top());
    st.emplace(cnt_div - sm, v, u);
    st_w = cnt_div;
    div = move(next_div);
  }
  while (!st.empty()) {
    auto [weight, v, u] = st.top();
    st.pop();
    add_edge(v, u, weight);
  }
  cc.assign(g.size(), 0);
  res.assign(g.size(), 0);
  dfs1(0, -1);
  cout << dfs2(0);
  return 0;
}
