#include <bits/stdc++.h>
using namespace std;
int n;
long long arr2[200020], arr1[200020];
int main() {
  long long a, b;
  cin >> n;
  for (int i = n; i; i--) {
    long long c;
    cin >> c;
    arr1[i] = c;
  }
  for (int i = n - 1; i; i--) arr1[i] = min(arr1[i], arr1[i + 1]);
  arr1[0] = 1;
  for (int i = 1; i <= n; i++) {
    for (long long j = arr1[i], a, b = 0; j; j %= arr1[a]) {
      a = lower_bound(arr1 + 1, arr1 + n + 1, j) - arr1 - 1;
      arr2[i] =
          max(arr2[i], arr2[a] + (n - a) * (j - j % arr1[a] - arr1[a]) + b);
      b += (n - a) * (j - j % arr1[a]);
    }
  }
  cout << arr2[n];
  return 0;
}
