#include <bits/stdc++.h>
using namespace std;
struct Data {
  pair<int, int> x, y;
  Data() {}
  Data(pair<int, int> a, pair<int, int> b) : x(a), y(b) {}
};
inline Data merge(Data x, Data y) {
  if (x.x < y.x) swap(x, y);
  return (x.x == y.x) ? Data(x.x, max(x.y, y.y)) : Data(x.x, max(x.y, y.x));
}
Data maxn[500005][20];
int bit[500005], cnt[500005];
void pre(int n) {
  for (int i = 1; (1 << i) <= n + 1; i++)
    for (int j = 0; j + (1 << i) - 1 <= n; j++)
      maxn[j][i] = merge(maxn[j][i - 1], maxn[j + (1 << (i - 1))][i - 1]);
  bit[0] = -1;
  for (int i = 1; i <= n + 1; i++) bit[i] = bit[i >> 1] + 1;
}
inline Data query(int l, int r) {
  int k = bit[r - l + 1];
  return merge(maxn[l][k], maxn[r - (1 << k) + 1][k]);
}
Data rmax[500005];
long long s;
bool check(int n, int m, int k) {
  if (k <= n) {
    int d = k / m;
    Data t = merge(query(k, min(n, (d + 1) * m - 1)), rmax[d + 1]);
    if (t.y.first != -1 &&
        s - 2 * d - ((k % m) > t.x.first) - ((k % m) > t.y.first) >= k)
      return 1;
  }
  if (2 * k <= n) {
    int d = 2 * k / m;
    Data t = merge(query(2 * k, min(n, (d + 1) * m - 1)), rmax[d + 1]);
    if (t.x.first != -1 && s - d - ((2 * k % m) > t.x.first) >= k) return 1;
  }
  return 0;
}
long long solve(int n, int m) {
  int d = 0;
  s = 0;
  for (int i = 0; m * i <= n; i++) {
    if (i) s += (long long)(cnt[min((i + 1) * m - 1, n)] - cnt[i * m - 1]) * i;
    rmax[d] = query(i * m, min((i + 1) * m - 1, n));
    if (rmax[d].x.first != -1) rmax[d].x.first %= m;
    if (rmax[d].y.first != -1) rmax[d].y.first %= m;
    d++;
  }
  rmax[d] = Data(pair<int, int>(-1, 0), pair<int, int>(-1, 0));
  for (int i = d - 1; i >= 0; i--) rmax[i] = merge(rmax[i], rmax[i + 1]);
  if (!check(n, m, 2)) return 0;
  int l = 2, r = n;
  while (l < r) {
    int mid = ((l + r) >> 1) + 1;
    if (check(n, m, mid))
      l = mid;
    else
      r = mid - 1;
  }
  return (long long)m * l;
}
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 0; i <= 5e5; i++)
    maxn[i][0] = Data(pair<int, int>(-1, 0), pair<int, int>(-1, 0));
  int r = 0;
  for (int i = 1; i <= n; i++) {
    int x;
    scanf("%d", &x);
    r = max(r, x);
    maxn[x][0] =
        merge(maxn[x][0], Data(pair<int, int>(x, i), pair<int, int>(-1, 0)));
    cnt[x]++;
  }
  for (int i = 1; i <= r; i++) cnt[i] += cnt[i - 1];
  pre(r);
  long long ans = 0;
  for (int i = 2; i <= r; i++) ans = max(ans, solve(r, i));
  printf("%lld\n", ans);
  return 0;
}
