#include <bits/stdc++.h>
using namespace std;
long long n;
long long wi[1000008], to[1000008][21 + 1];
long long lg2[1000008];
long long cnt[1000008], pre[1000008];
long long ask(long long l, long long r) {
  if (l > r) return 0;
  long long t = r - l + 1;
  t = lg2[t];
  return max(to[l][t], to[r - (1 << t) + 1][t]);
}
long long f1[1000008], f2[1000008];
long long suffix(long long x) { return pre[1000008 - 1] - pre[x - 1]; }
signed main() {
  long long p = 2;
  for (long long i = 1; i < 1000008; i++)
    if (i == p)
      lg2[i] = lg2[i - 1] + 1, p <<= 1;
    else
      lg2[i] = lg2[i - 1];
  long long mana = 0;
  scanf("%lld", &n);
  for (long long i = 1; i <= n; i++)
    scanf("%lld", &wi[i]), cnt[wi[i]]++, mana = max(mana, wi[i]);
  for (long long i = 1; i < 1000008; i++) pre[i] = pre[i - 1] + cnt[i];
  for (long long i = 0; i < 1000008; i++)
    if (cnt[i])
      to[i][0] = i;
    else
      to[i][0] = -1e9;
  for (long long j = 1; j < 21; j++)
    for (long long i = 0; i <= mana and i + (1 << j) < 1000008; i++)
      to[i][j] = max(to[i][j - 1], to[i + (1 << j - 1)][j - 1]);
  long long ans = 0;
  for (long long y = 2; y <= mana; y++) {
    long long cnty = 0;
    long long u = 0;
    for (long long i = 0;; i++) {
      if (i * y > mana) break;
      u = i;
      long long l = i * y, r = i * y + y - 1;
      if (l > 0)
        cnty += i * (pre[r] - pre[l - 1]);
      else
        cnty += i * (pre[r]);
    }
    f1[u + 1] = f2[u + 1] = -1e9;
    for (long long i = u; i >= 0; i--) {
      f1[i] = f1[i + 1], f2[i] = f2[i + 1];
      long long l = i * y, r = i * y + y - 1;
      r = min(r, mana);
      long long x = ask(l, r);
      if (x - l >= f1[i]) {
        if (cnt[x] > 1)
          f2[i] = x - l;
        else
          f2[i] = max(f1[i], ask(l, x - 1) - l);
        f1[i] = x - l;
      } else
        f2[i] = max(f2[i], x - l);
    }
    for (long long k = 0; k <= u; k++) {
      if (k * y > mana) break;
      if (2) {
        long long xi = min(cnty - k, (k * y + f1[k]) / 2);
        if (xi > 1) ans = max(ans, xi * y);
      }
      if (1) {
        long long xi = min(cnty - k - k, k * y + f2[k]);
        if (xi > 1) ans = max(ans, xi * y);
        xi = min(cnty - k - k - 1, k * y + f1[k]);
        if (xi > 1 and suffix(k * y + f1[k]) >= 2) ans = max(ans, xi * y);
      }
    }
  }
  printf("%lld\n", ans);
  return 0;
}
