#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 1, MAX = 5e5;
int a[N], nt[N], sum[N], mx1[N], mx2[N];
pair<int, int> p[N];
signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(NULL);
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    int x;
    cin >> x;
    a[x]++;
  }
  for (int i = 1; i < N; i++) {
    nt[i] = (a[i] ? i : nt[i - 1]);
    sum[i] = sum[i - 1] + a[i];
  }
  long long ans = 0;
  for (int i = 2; i < N; i++) {
    long long s = 0;
    int z = 0, k = 0;
    for (int j = i - 1; j - i + 1 <= MAX; j += i) {
      if (nt[j] > j - i) {
        if (a[nt[j]] > 1)
          p[z++] = {nt[j], nt[j] - j + i};
        else if (nt[nt[j] - 1] > j - i) {
          p[z++] = {nt[nt[j] - 1], nt[nt[j] - 1] - j + i};
        }
        p[z++] = {nt[j], nt[j] - j + i};
      }
      s += (sum[j] - (k ? sum[j - i] : 0)) * (long long)k;
      k++;
    }
    int x = 0, y = 0, rx = 0, ry = 0;
    for (int j = z - 1; j >= 0; j--) {
      if (p[j].second > rx) {
        y = x;
        ry = rx;
        x = p[j].first;
        rx = p[j].second;
      } else if (p[j].second > ry) {
        y = p[j].first;
        rx = p[j].second;
      }
      mx1[j] = x;
      mx2[j] = y;
    }
    int l = 1, r = N;
    while (r - l > 1) {
      int m = (l + r) >> 1, x = upper_bound(p, p + z, make_pair(m, -1)) - p;
      if (x != z && mx1[x] + mx2[x] >= 2 * m) {
        int g = mx1[x] - m, h = mx2[x];
        if (g >= m && g % i >= h % i)
          g -= m;
        else
          h -= m;
        if (s - mx1[x] / i - mx2[x] / i + g / i + h / i >= m)
          l = m;
        else
          r = m;
      } else {
        r = m;
      }
    }
    if (l > 1) {
      ans = max(ans, l * (long long)i);
    }
  }
  cout << ans;
  return 0;
}
