1223_G. Wooden Raft_36654
Suppose you are stuck on a desert island. The only way to save yourself is to craft a wooden raft and go to the sea. Fortunately, you have a hand-made saw and a forest nearby. Moreover, you've already cut several trees and prepared it to the point that now you have n logs and the i-th log has length a_i.

The wooden raft you'd like to build has the following structure: 2 logs of length x and x logs of length y. Such raft would have the area equal to x ⋅ y. Both x and y must be integers since it's the only way you can measure the lengths while being on a desert island. And both x and y must be at least 2 since the raft that is one log wide is unstable.

You can cut logs in pieces but you can't merge two logs in one. What is the maximum area of the raft you can craft?

Input

The first line contains the only integer n (1 ≤ n ≤ 5 ⋅ 10^5) — the number of logs you have.

The second line contains n integers a_1, a_2, ..., a_n (2 ≤ a_i ≤ 5 ⋅ 10^5) — the corresponding lengths of the logs.

It's guaranteed that you can always craft at least 2 × 2 raft.

Output

Print the only integer — the maximum area of the raft you can craft.

Examples

Input


1
9


Output


4


Input


9
9 10 9 18 9 9 9 28 9


Output


90

Note

In the first example, you can cut the log of the length 9 in 5 parts: 2 + 2 + 2 + 2 + 1. Now you can build 2 × 2 raft using 2 logs of length x = 2 and x = 2 logs of length y = 2.

In the second example, you can cut a_4 = 18 into two pieces 9 + 9 and a_8 = 28 in three pieces 10 + 9 + 9. Now you can make 10 × 9 raft using 2 logs of length 10 and 10 logs of length 9.
#include <bits/stdc++.h>
#pragma GCC optimize("-O3")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
using namespace std;
const int MAXN = 1123456;
const int N = 5e5;
const int inf = 1e9;
template <typename T>
void vout(T s) {
  cout << s << endl;
  exit(0);
}
int pref[MAXN], cnt[MAXN];
struct Set {
  int a = -inf, b = -inf;
  void insert(long long x) {
    if (b < x) b = x;
    if (a < b) swap(a, b);
  }
  bool empty() { return (a == -inf); }
  void clear() {
    a = -inf;
    b = -inf;
  }
  long long size() { return (a != -inf) + (b != -inf); }
};
Set st[MAXN], c, S;
int main() {
  ios_base ::sync_with_stdio(0);
  cin.tie(0);
  long long ans = 0;
  int n;
  cin >> n;
  vector<int> a(n + 1);
  int Mx = 0;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    Mx = max(Mx, a[i]);
    cnt[a[i]]++;
  }
  for (int i = 1; i <= N; i++) {
    pref[i] = pref[i - 1] + cnt[i];
    for (int j = 0; j < min(2, cnt[i]); j++) c.insert(i);
    st[i] = c;
  }
  int le, ri, val;
  long long kol = 0, X = 0;
  for (long long y = 2; y <= N; y++) {
    int l = 0, r = N;
    kol = 0;
    le = 0;
    while (le <= N) {
      ri = min(N, le + (int)y - 1);
      kol += (le / y) * (pref[ri] - (le ? pref[le - 1] : 0));
      le += y;
    }
    r = min((long long)N, kol);
    while (l < r) {
      int c = (l + r + 1) >> 1;
      if (c * 2 <= Mx) {
        kol = 0, X = 0;
        le = 0;
        while (le <= N) {
          ri = min(N, le + (int)y - 1);
          kol += (le / y) * (pref[ri] - (le ? pref[le - 1] : 0));
          if (!st[ri].empty()) {
            val = st[ri].a;
            if (val >= 2 * c) X = max(X, val % y);
          }
          le += y;
        }
        kol -= (2 * c) / y;
        if (X < (2 * c) % y) kol--;
        if (kol >= c) {
          l = c;
          continue;
        }
      }
      S.clear();
      kol = -2 * (c / y);
      le = 0;
      while (le <= N) {
        ri = min(N, le + (int)y - 1);
        kol += (le / y) * (pref[ri] - (le ? pref[le - 1] : 0));
        if (!st[ri].empty()) {
          val = st[ri].a;
          if (val >= c && val >= le) S.insert(val % y);
          if (st[ri].size() == 2) {
            val = st[ri].b;
            if (val >= c && val >= le) S.insert(val % y);
          }
        }
        le += y;
      }
      if (S.size() != 2) {
        r = c - 1;
        continue;
      }
      if (S.a < c % y) kol--;
      if (S.b < c % y) kol--;
      if (kol >= c) {
        l = c;
      } else
        r = c - 1;
    }
    if (l > 1) {
      ans = max(ans, y * l);
    }
  }
  cout << ans << "\n";
  return 0;
}

1
9
 9
9 10 9 18 9 9 9 28 9
 5
12 12 16 16 16
 10
21 28 33 27 33 28 34 25 24 11
 9
3 4 3 5 3 3 10 6 4
 7
28 23 27 12 28 23 14
 10
3 8 15 14 7 15 8 9 5 15
 30
6 8 3 5 7 10 6 7 30 21 5 4 6 2 3 16 10 15 3 12 12 5 5 14 4 5 3 4 3 5
 10
28 22 16 35 32 23 22 35 26 35
 20
5 4 8 2 8 6 7 5 3 4 4 5 4 2 4 14 2 2 4 2
 10
2 3 3 3 2 2 3 3 10 10
 2
11 12
 30
11 18 20 15 4 4 2 7 8 2 22 23 18 27 11 21 47 7 19 10 8 4 32 4 20 22 29 8 5 4
 5
28 28 29 26 28
 10
2 2 2 4 3 2 2 5 5 4
 5
12 12 16 16 23
 10
21 28 33 27 47 28 34 25 24 11
 9
3 7 3 5 3 3 10 6 4
 7
28 23 27 20 28 23 14
 10
3 8 15 14 7 15 2 9 5 15
 30
6 8 3 5 7 10 6 7 30 21 5 4 6 2 3 16 10 15 2 12 12 5 5 14 4 5 3 4 3 5
 10
28 22 12 35 32 23 22 35 26 35
 20
5 4 8 2 8 6 13 5 3 4 4 5 4 2 4 14 2 2 4 2
 30
11 18 20 17 4 4 2 7 8 2 22 23 18 27 11 21 47 7 19 10 8 4 32 4 20 22 29 8 5 4
 10
2 2 2 4 3 2 2 5 8 4
 1
12
 9
9 10 14 18 9 9 9 28 9
 5
17 12 16 16 23
 7
28 23 27 20 53 23 14
 10
3 8 20 14 7 15 2 9 5 15
 30
12 8 3 5 7 10 6 7 30 21 5 4 6 2 3 16 10 15 2 12 12 5 5 14 4 5 3 4 3 5
 10
28 22 12 35 5 23 22 35 26 35
 30
11 18 20 17 4 4 2 7 8 2 22 23 18 27 11 21 47 7 19 10 8 4 32 4 30 22 29 8 5 4
 1
8
 9
9 10 14 18 9 7 9 28 9
 5
33 12 16 16 23
 10
21 28 57 27 47 28 24 25 24 11
 7
25 23 27 20 53 23 14
 10
28 22 12 35 5 23 22 35 14 35
 10
2 3 3 3 1 3 3 3 18 10
 30
11 18 20 17 4 4 2 7 8 2 22 23 18 27 11 21 47 7 19 10 8 4 32 4 30 22 58 8 5 4
 10
2 2 2 2 3 2 2 5 8 8
 9
9 10 14 18 9 7 1 28 9
 10
21 28 57 27 18 28 24 25 24 11
 10
16 22 12 35 5 23 22 35 14 35
 20
5 4 8 2 1 6 13 5 3 0 4 5 4 2 4 14 2 2 4 3
 5
45 19 16 16 23
 10
21 21 57 27 18 28 24 25 24 11
 9
2 7 3 5 3 3 10 17 2
 7
25 32 27 20 53 23 7
 30
4 8 3 5 7 10 2 7 30 21 5 4 6 2 3 16 10 15 0 12 12 5 5 14 4 5 3 4 3 5
 20
5 4 6 2 1 6 13 5 3 0 4 5 4 2 4 14 2 2 4 3
 7
25 32 27 20 101 23 7
 10
0 8 20 14 7 15 1 9 9 15
 20
5 4 6 2 1 6 9 5 3 0 4 5 4 2 4 14 2 2 4 3
 10
1 3 3 3 1 1 3 3 18 1
 30
11 18 20 17 8 0 2 7 8 2 22 23 18 27 11 21 47 7 19 10 8 4 32 4 30 22 58 8 5 4
 10
21 40 57 27 18 47 24 25 24 11
 7
25 32 27 20 001 23 7
 9
2 7 4 1 3 3 10 15 2
 7
25 32 27 21 001 23 7
 9
2 7 4 1 3 3 11 15 2
 10
0 8 20 2 7 15 1 1 9 8
 30
3 18 20 13 7 0 2 7 8 2 22 23 18 27 11 21 47 7 19 10 8 4 32 4 30 22 58 8 5 4
 9
10 10 19 18 9 13 0 47 9
 10
21 40 36 27 18 47 24 27 32 11
 9
2 12 4 1 3 3 11 15 2
 7
25 25 27 21 001 15 7
 10
2 3 3 3 2 3 3 3 10 10
 10
21 28 33 27 47 28 24 25 24 11
 9
3 7 3 5 3 3 10 6 2
 20
5 4 8 2 8 6 13 5 3 4 4 5 4 2 4 14 2 2 4 3
 10
2 3 3 3 1 3 3 3 10 10
 10
2 2 2 2 3 2 2 5 8 4
 9
3 7 3 5 3 3 10 9 2
 10
2 8 20 14 7 15 2 9 5 15
 30
12 8 3 5 7 10 6 7 30 21 5 4 6 2 3 16 10 15 0 12 12 5 5 14 4 5 3 4 3 5
 20
5 4 8 2 8 6 13 5 3 0 4 5 4 2 4 14 2 2 4 3
 5
45 12 16 16 23
 9
3 7 3 5 3 3 10 17 2
 7
25 23 27 20 53 23 7
 10
2 8 20 14 7 15 1 9 5 15
 30
12 8 3 5 7 10 2 7 30 21 5 4 6 2 3 16 10 15 0 12 12 5 5 14 4 5 3 4 3 5
 10
2 3 3 3 1 3 3 3 18 1
 30
11 18 20 17 4 1 2 7 8 2 22 23 18 27 11 21 47 7 19 10 8 4 32 4 30 22 58 8 5 4
 10
2 2 2 2 3 1 2 5 8 8
 9
9 10 14 18 9 7 1 27 9
 10
0 8 20 14 7 15 1 9 5 15
 10
16 23 12 35 5 23 22 35 14 35
 10
1 3 3 3 1 3 3 3 18 1
 30
11 18 20 17 4 0 2 7 8 2 22 23 18 27 11 21 47 7 19 10 8 4 32 4 30 22 58 8 5 4
 10
2 2 2 2 3 1 2 5 10 8
 9
10 10 14 18 9 7 1 27 9
 5
58 19 16 16 23
 10
21 21 57 27 18 47 24 25 24 11
 9
2 7 3 5 3 3 10 15 2
 30
4 8 3 5 7 10 0 7 30 21 5 4 6 2 3 16 10 15 0 12 12 5 5 14 4 5 3 4 3 5
 10
16 23 12 35 5 23 22 41 14 35
 10
2 2 2 2 0 1 2 5 10 8
 9
10 10 19 18 9 7 1 27 9
 5
58 19 26 16 23
 9
2 7 3 1 3 3 10 15 2
 10
0 8 20 14 7 15 1 9 9 8
 30
4 8 3 5 7 10 0 7 30 21 5 4 6 2 3 16 10 15 0 12 12 5 5 14 4 5 3 4 1 5
 10
0 23 12 35 5 23 22 41 14 35
 20
5 4 6 2 1 6 9 5 0 0 4 5 4 2 4 14 2 2 4 3
 10
1 3 3 1 1 1 3 3 18 1
 30
11 18 20 17 7 0 2 7 8 2 22 23 18 27 11 21 47 7 19 10 8 4 32 4 30 22 58 8 5 4
 10
2 2 4 2 0 1 2 5 10 8
 9
10 10 19 18 9 13 1 27 9
 5
58 19 1 16 23
 10
21 40 57 27 18 47 24 27 24 11
 10
0 8 20 14 7 15 1 1 9 8
 30
4 8 3 5 7 10 0 7 30 21 5 4 6 2 3 16 10 15 0 12 12 7 5 14 4 5 3 4 1 5
 10
0 23 12 35 5 23 22 41 23 35

4
 90
 55
 198
 20
 120
 63
 114
 209
 35
 21
 18
 261
 115
 12
 60
 210
 21
 130
 56
 114
 209
 52
 261
 12
 8
 90
 64
 143
 63
 120
 187
 270
 4
 81
 80
 231
 140
 176
 27
 301
 16
 72
 198
 165
 44
 96
 190
 25
 144
 112
 40
 184
 70
 36
 18
 308
 220
 100
 24
 105
 28
 48
 294
 99
 216
 33
 84
 21
 210
 21
 52
 21
 12
 21
 63
 120
 52
 90
 27
 140
 63
 114
 21
 301
 16
 72
 63
 165
 21
 301
 16
 72
 112
 210
 25
 112
 176
 16
 81
 114
 21
 63
 112
 165
 36
 18
 308
 16
 90
 96
 220
 56
 112
 165
