#include <bits/stdc++.h>
using namespace std;
const int mod = (int)1e9 + 7;
void dbg() { cerr << "\n"; }
template <typename T, typename... T2>
void dbg(const T& fst, const T2&... rst) {
  cerr << fst << ": ";
  dbg(rst...);
}
bool prime[100500];
vector<int> pr;
void eratos(int n) {
  prime[2] = true;
  prime[0] = prime[1] = false;
  for (int i = 3; i <= n; i += 2) prime[i] = true, prime[i + 1] = false;
  int limit = (int)sqrt((double)n) + 1;
  for (int i = 3; i <= limit; i += 2) {
    if (!prime[i]) continue;
    for (int j = i * i, k = i * 2; j <= n; j += k) prime[j] = false;
  }
  for (int(i) = 0; (i) < (100050); (i)++)
    if (prime[i]) pr.push_back(i);
}
int main() {
  eratos(100050);
  int n;
  cin >> n;
  vector<int> a(n);
  for (int(i) = 0; (i) < (n); (i)++) cin >> a[i];
  sort((a).begin(), (a).end());
  long long ans = 0;
  long long bs = 1;
  for (int(i) = 0; (i) < ((int)(pr).size()); (i)++)
    for (int(j) = 0; (j) < (n); (j)++)
      if (a[j] % pr[i] == 0) {
        bs *= pr[i];
        break;
      }
  dbg("bs", bs);
  for (long long i = 2 * bs - 2; i <= 2 * bs + 1; i += 1) {
    long long sm = 0;
    for (int(j) = 0; (j) < (n); (j)++) sm += i % a[j];
    if (sm > ans) {
    }
    ans = max(ans, sm);
  }
  cout << ans << "\n";
  return 0;
}
