#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef long double ld;
typedef vector<vector<int>> Graph;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
#define pi 3.14159265359
#define inf 2147483647
#define INF 9223372036854775807
#define mod 1000000007
#define mod2 998244353

int main() {
    int N; cin >> N;
    vector<ll> A(N);
    map<ll, ll> M;
    for(int i = 0; i < N; i++) {
        cin >> A[i];
        if(!M.count(A[i])) M[A[i]] = 1;
        else M[A[i]]++;
    }
    ll Max = 0, preMax = 0;
    for(auto p: M) {
        if(p.second >= 4) {
            if(p.first > Max) {
                preMax = p.first;
                Max = p.first;
            }
            else if(p.first > preMax) {
                preMax = p.first;
            }
        }
        else if(p.second >= 2) {
            if(p.first > Max) {
                preMax = Max;
                Max = p.first;
            }
            else if(p.first > preMax) {
                preMax = p.first;
            }
        }
    }
    ll ans = Max * preMax;
    cout << ans << endl;
    return 0;
}
#pragma GCC optimize(2)
#include<bits/stdc++.h>
#define ll long long
#define maxn 1000005
#define inf 1e18
#define pb push_back
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define per(i,a,b) for(int i=a;i>=b;i--)
using namespace std;

inline ll read()
{
	ll x=0,w=1; char c=getchar();
	while(c<'0'||c>'9') {if(c=='-') w=-1; c=getchar();}
	while(c<='9'&&c>='0') {x=(x<<1)+(x<<3)+c-'0'; c=getchar();}
	return w==1?x:-x;
}

ll a[maxn],dp[maxn][5],n,pre[maxn];

int main()
{
	n=read(); rep(i,1,n) a[i]=read();
	rep(i,1,n) rep(j,0,3) dp[i][j]=-inf;
	dp[1][0]=a[1]; dp[2][1]=a[2]; dp[3][2]=a[3];
	for(int i=3;i<=n;i++)
	{
		dp[i][0]=dp[i-2][0]+a[i];
		dp[i][1]=max(dp[i-2][1],dp[i-3][0])+a[i];
		if(i>=4) dp[i][2]=max(max(dp[i-2][2],dp[i-3][1]),dp[i-4][0])+a[i];
	}
	if(n%2==1) cout<<max(max(dp[n][2],dp[n-1][1]),dp[n-2][0])<<endl;
	else cout<<max(dp[n][1],dp[n-1][0])<<endl;
	return 0;
}