#include<stdio.h>
int main()
{
	int n;
	scanf("%d", &n);
	int i, j;
	long long int a[200005];
	for (i = 0; i < n; i++)
		scanf("%lld", &a[i]);
	long long int dp[200005][3];
	long long int min = -100000000000000000;
	dp[0][0] = a[0];
	dp[0][1] = dp[0][2] = min;
	dp[1][1] = a[1];
	dp[1][0] = dp[1][2] = min;
	for (i = 2; i < n; i++)
	{
		for (j = 0; j < 3; j++)
		{
			if (dp[i - 2][j] > min)
				dp[i][j] = dp[i - 2][j] + a[i];
			else
				dp[i][j] = min;
		}
		if (i > 2)
		{
			for (j = 0; j < 2; j++)
				if (dp[i - 3][j] > min && dp[i][j + 1] < dp[i - 3][j] + a[i])
					dp[i][j + 1] = dp[i - 3][j] + a[i];
		}
		else
		{
			if (dp[i][2] < a[i])
				dp[i][2] = a[i];
		}
		if (i > 3)
		{
			if (dp[i - 4][0] > min && dp[i][2] < dp[i - 4][0] + a[i])
				dp[i][2] = dp[i - 4][0] + a[i];
		}
	}
	long long int ans;
	if (n % 2 > 0)
	{
		ans = dp[n - 3][0];
		if (ans < dp[n - 2][1])
			ans = dp[n - 2][1];
		if (ans < dp[n - 1][2])
			ans = dp[n - 1][2];
	}
	else
	{
		ans = dp[n - 2][0];
		if (ans < dp[n - 1][1])
			ans = dp[n - 1][1];
	}
	printf("%lld\n", ans);
	return 0;
}