#include <bits/stdc++.h>
using namespace std;
const long long N = 5e5 + 4;
long long sum[N], ar[N];
pair<long long, long long> max1[N];
long long ceil(long long x, long long y) { return (x + y - 1) / y; }
signed main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  long long n, i, j, k, l, A, ans = 4, maxx1, maxx2, num_y, x;
  cin >> n;
  A = 5e5;
  for (i = 1; i <= n; i++) {
    cin >> ar[i];
    sum[ar[i]]++;
  }
  for (i = 1; i <= A; i++) {
    max1[i] = max1[i - 1];
    if (sum[i] == 0) {
      sum[i] += sum[i - 1];
      continue;
    }
    if (sum[i] == 1) {
      max1[i] = {i, max1[i].first};
    } else {
      max1[i] = {i, i};
    }
    sum[i] += sum[i - 1];
  }
  for (i = 2; i <= A; i++) {
    maxx1 = -1;
    maxx2 = -1;
    num_y = 0;
    for (j = 0; j <= A / i; j++) {
      if (j) {
        num_y += (sum[min(A, i * (j + 1) - 1)] - sum[i * j - 1]) * j;
      }
    }
    for (j = ceil(A, i); j > 0; j--) {
      pair<long long, long long> lis = max1[min(A, i * j - 1)];
      if (lis.first >= (j - 1) * i && lis.second >= (j - 1) * i) {
        if (maxx1 <= lis.first % i) {
          maxx2 = maxx1;
          maxx1 = lis.first % i;
          if (maxx2 < lis.second % i) {
            maxx2 = lis.second % i;
          }
        } else {
          if (maxx2 < lis.first % i) {
            maxx2 = lis.first % i;
          }
        }
      } else {
        if (lis.first >= (j - 1) * i) {
          if (maxx1 <= lis.first % i) {
            maxx2 = maxx1;
            maxx1 = lis.first % i;
          } else {
            if (lis.first % i > maxx2) {
              maxx2 = lis.first % i;
            }
          }
        }
      }
      assert(maxx1 >= maxx2);
      assert(maxx1 < i);
      if (maxx1 != -1) {
        x = ((j - 1) * i + maxx1) / 2;
        if (min(x, num_y - j + 1) > 1) {
          ans = max(ans, i * min(x, num_y - (j - 1)));
        }
        x = (j - 1) * i + maxx1;
        if (x >= 1) {
          if (sum[A] - sum[x - 1] >= 2) {
            if (min(x, num_y - 2 * j + 1) > 1) {
              ans = max(ans, i * min(x, num_y - 2 * (j - 1) - 1));
            }
          }
        }
      }
      if (maxx2 != -1) {
        x = (j - 1) * i + maxx2;
        if (min(x, num_y - 2 * j + 2) > 1) {
          ans = max(ans, i * min(x, num_y - 2 * (j - 1)));
        }
      }
    }
  }
  cout << ans;
}
