Danny, the local Math Maniac, is fascinated by circles, Omkar's most recent creation. Help him solve this circle problem!

You are given $n$ nonnegative integers $a_1, a_2, \dots, a_n$ arranged in a circle, where $n$ must be odd (ie. $n-1$ is divisible by $2$). Formally, for all $i$ such that $2 \leq i \leq n$, the elements $a_{i - 1}$ and $a_i$ are considered to be adjacent, and $a_n$ and $a_1$ are also considered to be adjacent. In one operation, you pick a number on the circle, replace it with the sum of the two elements adjacent to it, and then delete the two adjacent elements from the circle. This is repeated until only one number remains in the circle, which we call the circular value.

Help Danny find the maximum possible circular value after some sequences of operations. 


-----Input-----

The first line contains one odd integer $n$ ($1 \leq n < 2 \cdot 10^5$, $n$ is odd)  — the initial size of the circle.

The second line contains $n$ integers $a_{1},a_{2},\dots,a_{n}$ ($0 \leq a_{i} \leq 10^9$)  — the initial numbers in the circle.


-----Output-----

Output the maximum possible circular value after applying some sequence of operations to the given circle.


-----Examples-----
Input
3
7 10 2

Output
17

Input
1
4

Output
4



-----Note-----

For the first test case, here's how a circular value of $17$ is obtained:

Pick the number at index $3$. The sum of adjacent elements equals $17$. Delete $7$ and $10$ from the circle and replace $2$ with $17$.

Note that the answer may not fit in a $32$-bit integer.

Source: codeforces | Difficulty: HARD
Tags: Dynamic programming

Complete search

Game theory

Greedy algorithms


Solutions:
def solve(ls):
	n = len(ls)
	k = (n - 1) // 2
	s = 0
	for i in range(k + 1):
		s += ls[2 * i]
	s_max = s
	for i in range(n):
		s -= ls[2 * i % n]
		s += ls[(2 * i + 1) % n]
		s_max = max(s_max, s)
	return s_max

def main(istr, ostr):
	n = int(istr.readline())
	ls = list(map(int, istr.readline().split()))
	print(solve(ls), file=ostr)
import sys
main(sys.stdin, sys.stdout)


n = int(input())
a = list(map(int, input().split()))
b = []
for i in range(0, n, 2):
	b.append(a[i])
for i in range(1, n, 2):
	b.append(a[i])
su = 0
for i in range((n + 1) // 2):
	su += b[i]
ans = su
for i in range((n + 1) // 2, n + (n + 1) // 2):
	su += b[i % n] - b[(i - (n + 1) // 2) % n]
	ans = max(su, ans)
print(ans)


import os
import heapq
import sys
import math
import operator
from collections import defaultdict
from io import BytesIO, IOBase

def inpt():
	return [int(k) for k in input().split()]

def main():
	n = int(input())
	ar = inpt()
	odd = []
	even = []
	for i in range(1, n + 1):
		if i % 2 == 0:
			even.append(ar[i - 1])
		else:
			odd.append(ar[i - 1])
	even = odd + even
	even += even
	sm = 0
	ans = 0
	for i in range((n + 1) // 2):
		sm += even[i]
	k = (n + 1) // 2
	ans = sm
	i = 0
	while k < 2 * n:
		sm -= even[i]
		sm += even[k]
		ans = max(ans, sm)
		k += 1
		i += 1
	print(ans)
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


def solve(n, arr):
	ans = m = sum(arr[:n:2])
	for i in range(0, n - 1, 2):
		m += arr[i + 1] - arr[i]
		ans = max(m, ans)
	m = arr[0] + sum(arr[1:n:2])
	ans = max(m, ans)
	for i in range(2, n - 1, 2):
		m += arr[i] - arr[i - 1]
		ans = max(m, ans)
	return ans
n = int(input())
arr = list(map(int, input().split()))
print(solve(n, arr))


n = int(input())
lst = list(map(int, input().split()))
lst1 = []
lst2 = []
for i in range(0, n, 2):
	lst1.append(lst[i])
for j in range(1, n, 2):
	lst2.append(lst[j])
lst = lst1 + lst2
k = (n + 1) // 2
sum_of_k_element = [0] * n
sum_of_k_element[0] = sum(lst[:k])
for i in range(1, n):
	sum_of_k_element[i] = sum_of_k_element[i - 1] - lst[i - 1] + lst[(i + k - 1) % n]
print(max(sum_of_k_element))


y = lambda x: print(x) or quit()
n = int(input())
p = list(map(int, input().split()))
if n < 2:
	y(p[0])
if n < 4:
	y(sum(p) - min(p))
s = [p[-1], p[-2]]
r = [p[0], p[1]]
for i in range(2, n):
	r.append(r[-2] + p[i])
	s.append(s[-2] + p[-i - 1])
s = s[::-1]
m = r[-1] + r[-2]
for i in range(n - 3):
	m = min(m, r[i] + s[i + 3])
m = min([m, r[n - 3], s[1], s[2]])
y(r[-1] + r[-2] - m)


import sys
input = sys.stdin.buffer.readline

def solution():
	n = int(input())
	l = list(map(int, input().split()))
	pre = [0] * (n + 1)
	suff = [0] * (n + 1)
	for i in range(n):
		pre[i] = l[i]
		if i >= 2:
			pre[i] += pre[i - 2]
	for i in range(n - 1, -1, -1):
		suff[i] = l[i]
		if i <= n - 3:
			suff[i] += suff[i + 2]
	ans = -1
	for i in range(n):
		ans = max(ans, suff[i] + pre[i - 1])
	print(ans)
solution()


import sys
input = sys.stdin.readline

def ceil(x):
	if x != int(x):
		x = int(x) + 1
	return x

def swaparr(arr, a, b):
	temp = arr[a]
	arr[a] = arr[b]
	arr[b] = temp

def gcd(a, b):
	if b == 0:
		return a
	return gcd(b, a % b)

def nCr(n, k):
	if k > n - k:
		k = n - k
	res = 1
	for i in range(k):
		res = res * (n - i)
		res = res / (i + 1)
	return int(res)

def upper_bound(a, x, lo=0, hi=None):
	if hi == None:
		hi = len(a)
	while lo < hi:
		mid = (lo + hi) // 2
		if a[mid] < x:
			lo = mid + 1
		else:
			hi = mid
	return lo

def primefs(n):
	primes = {}
	while n % 2 == 0 and n > 0:
		primes[2] = primes.get(2, 0) + 1
		n = n // 2
	for i in range(3, int(n ** 0.5) + 2, 2):
		while n % i == 0 and n > 0:
			primes[i] = primes.get(i, 0) + 1
			n = n // i
	if n > 2:
		primes[n] = primes.get(n, 0) + 1
	return primes

def power(x, y, p):
	res = 1
	x = x % p
	if x == 0:
		return 0
	while y > 0:
		if y & 1 == 1:
			res = res * x % p
		y = y >> 1
		x = x * x % p
	return res

def swap(a, b):
	temp = a
	a = b
	b = temp
	return (a, b)

def find(x, link):
	p = x
	while p != link[p]:
		p = link[p]
	while x != p:
		nex = link[x]
		link[x] = p
		x = nex
	return p

def union(x, y, link, size):
	x = find(x, link)
	y = find(y, link)
	if size[x] < size[y]:
		(x, y) = swap(x, y)
	if x != y:
		size[x] += size[y]
		link[y] = x

def sieve(n):
	prime = [True for i in range(n + 1)]
	p = 2
	while p * p <= n:
		if prime[p] == True:
			for i in range(p * p, n + 1, p):
				prime[i] = False
		p += 1
	return prime
MAXN = int(100000.0 + 5)

def spf_sieve():
	spf[1] = 1
	for i in range(2, MAXN):
		spf[i] = i
	for i in range(4, MAXN, 2):
		spf[i] = 2
	for i in range(3, ceil(MAXN ** 0.5), 2):
		if spf[i] == i:
			for j in range(i * i, MAXN, i):
				if spf[j] == j:
					spf[j] = i

def factoriazation(x):
	ret = {}
	while x != 1:
		ret[spf[x]] = ret.get(spf[x], 0) + 1
		x = x // spf[x]
	return ret

def int_array():
	return list(map(int, input().strip().split()))

def float_array():
	return list(map(float, input().strip().split()))

def str_array():
	return input().strip().split()
MOD = int(1000000000.0) + 7
CMOD = 998244353
INF = float('inf')
NINF = -float('inf')
n = int(input())
a = int_array()
odd_ = []
even_ = []
a += a
odd = even = 0
for i in range(2 * n):
	if i & 1:
		odd += a[i]
		odd_.append(odd)
	else:
		even += a[i]
		even_.append(even)
x = (n + 1) // 2
ans = 0
for i in range(x - 1, len(even_)):
	if i == x - 1:
		ans = max(ans, even_[i])
	else:
		ans = max(ans, even_[i] - even_[i - x])
for i in range(x - 1, len(odd_)):
	if i == x - 1:
		ans = max(ans, odd_[i])
	else:
		ans = max(ans, odd_[i] - odd_[i - x])
print(ans)


n = int(input().split()[0])
arr = list(map(int, input().split()))
if n == 1:
	print(arr[0])
else:
	dp = [[0] * n, [0] * n]
	dp[0][0] = arr[0]
	dp[1][0] = arr[0]
	dp[0][1] = arr[0] + arr[1]
	dp[1][1] = arr[1]
	for i in range(2, n):
		dp[0][i] = max(dp[1][i - 1] + arr[i], dp[0][i - 2] + arr[i])
		dp[1][i] = dp[1][i - 2] + arr[i]
	print(max(dp[1][n - 1], dp[0][n - 1], dp[0][n - 2], dp[1][n - 2]))


n = int(input())
a = list(map(int, input().split()))
s = sum(a)
c = 0
ans = 0
for i in range(0, n, 2):
	c += a[i]
for i in range(len(a)):
	ans = max(ans, c)
	c = s - c
	c += a[i]
print(ans)


n = int(input())
l1 = list(map(int, input().split()))
sum = 0
for i in range(0, n, 2):
	sum = sum + l1[i]
max = sum
if n > 1:
	for i in range(1, n, 2):
		sum = sum + l1[i] - l1[i - 1]
		if sum > max:
			max = sum
	sum = sum + l1[0] - l1[-1]
	if sum > max:
		max = sum
	for i in range(2, n, 2):
		sum = sum + l1[i] - l1[i - 1]
		if sum > max:
			max = sum
	print(max)
else:
	print(max)


import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')

def RL():
	return map(int, sys.stdin.readline().rstrip().split())

def RLL():
	return list(map(int, sys.stdin.readline().rstrip().split()))

def N():
	return int(input())

def comb(n, m):
	return factorial(n) / (factorial(m) * factorial(n - m)) if n >= m else 0

def perm(n, m):
	return factorial(n) // factorial(n - m) if n >= m else 0

def mdis(x1, y1, x2, y2):
	return abs(x1 - x2) + abs(y1 - y2)
mod = 998244353
INF = float('inf')
from math import factorial
from collections import Counter, defaultdict, deque
from heapq import heapify, heappop, heappush

def main():
	n = N()
	arr = RLL()
	sme = sum([arr[i] for i in range(0, n, 2)])
	smo = sum([arr[i] for i in range(1, n, 2)]) + arr[0]
	res = max(sme, smo)
	for i in range(n):
		if i % 2 == 0:
			sme -= arr[i] - arr[(i + 1) % n]
		else:
			smo -= arr[i] - arr[(i + 1) % n]
		res = max(res, sme, smo)
	print(res)
main()


n = int(input())
a = list(map(int, input().split()))
b = [a[i] for i in range(0, n, 2)] + [a[i] for i in range(1, n, 2)]
b = b + b
m = n // 2 + 1
total = sum(b[0:m])
ans = total
for i in range(0, n + n - m):
	total += b[i + m] - b[i]
	ans = max(ans, total)
print(ans)


def find_max_sub(arr, k):
	curr = sum(arr[:k])
	mx = curr
	for (i, a) in enumerate(arr[k:]):
		d = curr + a - arr[i]
		if d > mx:
			mx = d
		curr = d
	print(mx)
n = int(input())
arr = list(map(int, input().split(' ')))
a = arr[::2] + arr[1::2] + arr[::2]
find_max_sub(a, (n + 1) // 2)


n = int(input())
arr = list(map(int, input().split()))
total = sum(arr)
cur = 0
res = 0
for i in range(0, n, 2):
	cur += arr[i]
for i in range(n):
	res = max(res, cur)
	cur = total - cur
	cur += arr[i]
print(res)


import sys
import math
from collections import defaultdict, Counter
n = int(input())
a = list(map(int, input().split()))
a += a
ans = 0
c = 0
s = 0
p = 0
for i in range(0, 2 * n, 2):
	if c <= n // 2:
		s += a[i]
		c += 1
		ans = max(ans, s)
		if c > n // 2:
			c -= 1
			s -= a[p]
			p += 2
c = 0
s = 0
p = 1
for i in range(1, 2 * n, 2):
	if c <= n // 2:
		s += a[i]
		c += 1
		ans = max(ans, s)
		if c > n // 2:
			c -= 1
			s -= a[p]
			p += 2
print(ans)


import sys
input = sys.stdin.readline
n = int(input())
a = [int(item) for item in input().split()]
total = sum(a)
if n == 1:
	print(total)
	exit()
val = sum(a[::2])
a.append(a[0])
ans = 0
for (a0, a1) in zip(a, a[1:]):
	val = total - val + a0
	ans = max(ans, val)
print(ans)


n = int(input())
ar = list(map(int, input().split()))
a = [ar[i] for i in range(0, n, 2)]
b = [ar[i] for i in range(1, n, 2)]
fin = (a + b) * 2
s = 0
x = (n + 1) // 2
for i in range(x):
	s += fin[i]
mx = s
for i in range(x, 2 * n):
	s += fin[i] - fin[i - x]
	mx = max(mx, s)
print(mx)


import sys
INF = 10 ** 20
MOD = 10 ** 9 + 7
I = lambda : list(map(int, input().split()))
from math import gcd
from math import ceil
from collections import defaultdict as dd, Counter
from bisect import bisect_left as bl, bisect_right as br

def find(x):
	ans = []
	for i in range(1, int(x ** 0.5) + 1):
		if x % i:
			continue
		ans.append(i)
		ans.append(x // i)
	return ans

def solve():
	(n,) = I()
	a = I() * 2
	ans = sum(a) // 2
	mn = INF
	odd = even = 0
	for i in range(n - 1):
		if i % 2:
			odd += a[i]
		else:
			even += a[i]
	mn = min(odd, even)
	back = n - 1
	for i in range(n - 1, 2 * n):
		if i % 2:
			odd += a[i]
			odd -= a[i - back]
		else:
			even += a[i]
			even -= a[i - back]
		mn = min(mn, odd, even)
	print(ans - mn)
solve()


import sys
import math as mt
input = sys.stdin.readline
I = lambda : list(map(int, input().split()))
(n,) = I()
l = I()
ar = []
for i in range(0, n, 2):
	ar.append(l[i])
for i in range(1, n, 2):
	ar.append(l[i])
k = (n + 1) // 2
s = sum(ar[:k])
ans = s
ar += ar
for i in range(k, 2 * n):
	s -= ar[i - k]
	s += ar[i]
	ans = max(ans, s)
print(ans)


from sys import stdin, stdout
fi = stdin
fo = stdout

def solve():
	n = int(fi.readline())
	a = [int(v) for v in fi.readline().split()]

	def sum_odd(arr):
		f1 = [0] * (n + 2)
		f2 = [0] * (n + 2)
		for i in range(n):
			f1[i] = arr[i] + f1[i - 2]
		for i in reversed(range(n)):
			f2[i] = arr[i] + f2[i + 2]
		result = 0
		for i in range(0, n, 2):
			result = max(result, f1[i] + f2[i + 1])
		return result
	res = max(sum_odd(a), sum_odd(a[1:] + a[:1]))
	print(res)
solve()


n = int(input())
a = list(map(int, input().split()))
pref = [0] * (n + 1)
suff = [0] * (n + 1)
for i in range(1, n + 1):
	pref[i] = a[i - 1]
	if i >= 2:
		pref[i] += pref[i - 2]
for i in range(n, 0, -1):
	suff[i] = a[i - 1]
	if n - i >= 2:
		suff[i] += suff[i + 2]
ans = 0
for i in range(1, n + 1):
	ans = max(ans, suff[i] + pref[i - 1])
print(ans)


n = int(input())
f = int
ar = list(map(int, input().split()))
(se, so) = (0, 0)
bo = True
(po, pe) = ([], [])
for h in ar:
	if bo:
		se += h
		pe.append(se)
		bo = False
	else:
		so += h
		po.append(so)
		bo = True
if n == 1:
	print(ar[0])
	exit()
maxs = max(pe[-1], ar[0] + po[-1], ar[1] + pe[-1] - ar[0])
for i in range(2, n):
	x = f(i / 2)
	if i % 2 == 0:
		s = po[-1] - po[f(x - 1)] + pe[x]
		maxs = max(s, maxs)
	else:
		s = pe[-1] - pe[x] + po[x]
		maxs = max(maxs, s)
print(maxs)


n = int(input())
arr = list(map(int, input().rstrip().split()))
(odd, even) = ([], [])
if n == 1:
	print(arr[0])
else:
	for i in range(n):
		if i % 2 == 0:
			odd.append(arr[i])
		else:
			even.append(arr[i])
	odd.extend(even)
	odd.extend(odd)
	k = (n + 1) / 2
	(s, m, i, left) = (0, -1, 0, 0)
	while i < n + k:
		if i < k:
			s += odd[i]
		else:
			if m < s:
				m = s
			if i == n + k - 1:
				break
			s -= odd[left]
			s += odd[i]
			left += 1
		i += 1
	print(m)


import sys

def minp():
	return sys.stdin.readline().strip()

def mint():
	return int(minp())

def mints():
	return map(int, minp().split())

def solve1(a):
	n = len(a)

def solve():
	n = mint()
	a = list(mints())
	if n == 1:
		print(a[0])
		return
	a += a
	b = [0] * (2 * n)
	b[0] = a[0]
	b[1] = a[1]
	for i in range(2, len(b)):
		b[i] = b[i - 2] + a[i]
	r = min(b[n - 3], b[n - 3 + 1])
	for j in range(n - 3 + 2, len(b)):
		r = min(r, b[j] - b[j - (n - 3) - 2])
	print(sum(a) // 2 - r)
solve()


n = int(input())
ls = list(map(int, input().split()))
one_sum_ls = [0 for _ in range(n // 2 + 1)]
two_sum_ls = [0 for _ in range(n // 2)]
one_sum = 0
two_sum = 0
for i in range(n):
	if i % 2 == 0:
		one_sum += ls[i]
		one_sum_ls[i // 2] = one_sum
	else:
		two_sum += ls[i]
		two_sum_ls[i // 2] = two_sum
res = 0
for i in range(n):
	if i != n - 1:
		curr = 0
		if i % 2 == 0:
			curr += one_sum_ls[i // 2]
			curr += two_sum_ls[-1] - two_sum_ls[i // 2] + ls[i + 1]
		else:
			curr += two_sum_ls[i // 2]
			curr += one_sum_ls[-1] - one_sum_ls[i // 2]
	else:
		curr = one_sum_ls[-1]
	if curr > res:
		res = curr
print(res)


import sys
input = sys.stdin.readline
n = int(input())
a = [int(i) for i in input().split() if i != '\n']
prefev = [0]
prefod = [0]
for i in range(n):
	if not i & 1:
		prefod.append(prefod[-1] + a[i])
		prefev.append(prefev[-1])
	else:
		prefev.append(prefev[-1] + a[i])
		prefod.append(prefod[-1])
prefev = prefev[1:]
prefod = prefod[1:]
(best1, best2) = (0, 0)
for i in range(n):
	best1 = max(best1, prefev[i] + (prefod[-1] - prefod[i]))
	best2 = max(best2, prefod[i] + (prefev[-1] - prefev[i]))
print(max(best1, best2))


n = int(input())
m = (n + 1) // 2
a = list(map(int, input().split()))
curr = 0
for i in range(m):
	curr += a[2 * i]
answer = curr
for j in range(n - 1):
	curr -= a[2 * j % n]
	curr += a[2 * (j + m) % n]
	answer = max(answer, curr)
print(answer)


n = int(input())
a = list(map(int, input().split()))
if n == 1:
	print(a[0])
	exit()
s1 = a[0] + a[1]
for i in range(3, n, 2):
	s1 += a[i]
ans = s1
k = 1
for i in range(n // 2):
	s1 -= a[k]
	s1 += a[k + 1]
	k += 2
	if s1 > ans:
		ans = s1
s2 = a[1] + a[2]
for i in range(4, n, 2):
	s2 += a[i]
if s2 > ans:
	ans = s2
k = 2
for i in range(n // 2 - 1):
	s2 -= a[k]
	s2 += a[k + 1]
	k += 2
	if s2 > ans:
		ans = s2
print(ans)


import sys
input = sys.stdin.readline
n = int(input())
a = list(map(int, input().split()))
b = []
for i in range(0, n, 2):
	b.append(a[i])
for i in range(1, n, 2):
	b.append(a[i])
b = b + b
s = sum(b[:(n + 1) // 2])
ans = s
for i in range((n + 1) // 2, n + (n + 1) // 2):
	s += b[i] - b[i - (n + 1) // 2]
	ans = max(ans, s)
print(ans)


n = int(input())
a = list(map(int, input().split()))
if n == 1:
	print(a[0])
	exit()
b = [0]
ptr = 2 % n
while ptr:
	b.append(ptr)
	ptr = (ptr + 2) % n
b.extend(b)
sz = n // 2
tot = sum([a[pos] for pos in b[:sz]])
ans = tot + max(a[(b[sz - 1] + 1) % n], a[(b[sz - 1] + 2) % n])
for i in range(1, n):
	tot -= a[b[i - 1]]
	npos = b[i + sz - 1]
	tot += a[b[i + sz - 1]]
	ans = max(ans, tot + max(a[(npos + 1) % n], a[(npos + 2) % n]))
print(ans)


from sys import stdin
input = stdin.buffer.readline
n = int(input())
(*a,) = map(int, input().split())
s1 = sum((a[i] for i in range(0, n, 2)))
s2 = sum((a[i] for i in range(1, n, 2))) + a[0]
ans = max(s1, s2)
for i in range(0, n, 2):
	s1 -= a[i] - a[(i + 1) % n]
	ans = max(ans, s1)
for i in range(1, n, 2):
	s2 -= a[i] - a[(i + 1) % n]
	ans = max(ans, s2)
print(ans)


import sys
sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep='\n')

def II():
	return int(sys.stdin.readline())

def MI():
	return map(int, sys.stdin.readline().split())

def LI():
	return list(map(int, sys.stdin.readline().split()))

def LLI(rows_number):
	return [LI() for _ in range(rows_number)]

def SI():
	return sys.stdin.readline()[:-1]

def solve():
	if n == 1:
		return aa[0]
	dp = [[inf] * 2 for _ in range(n)]
	dp[0][0] = aa[0]
	dp[1][0] = aa[1]
	dp[2][1] = aa[2]
	for i in range(n - 2):
		for j in range(2):
			pre = dp[i][j]
			if pre == inf:
				continue
			dp[i + 2][j] = min(dp[i + 2][j], pre + aa[i + 2])
			if j == 0 and i + 3 < n:
				dp[i + 3][1] = min(dp[i + 3][1], pre + aa[i + 3])
	mn = min(dp[n - 3][0], dp[n - 2][0], dp[n - 2][1], dp[n - 1][1])
	return sum(aa) - mn
inf = 10 ** 16
n = II()
aa = LI()
print(solve())


def read_list():
	return list(map(int, input().split(' ')))

def print_list(l):
	print(' '.join(map(str, l)))
n = int(input())
nums = read_list()
if n == 3:
	print(sum(nums) - min(nums))
elif n == 1:
	print(nums[0])
else:
	dp = [0] * n
	dp[0] = nums[0]
	dp[3] = nums[0] + nums[3]
	for i in range(2, n - 1, 2):
		dp[i] = dp[i - 2] + nums[i]
	for i in range(5, n - 1, 2):
		dp[i] = min(dp[i - 2], dp[i - 3]) + nums[i]
	res = min(dp[n - 3], dp[n - 2])
	dp = [0] * n
	dp[1] = nums[1]
	dp[4] = nums[1] + nums[4]
	for i in range(3, n, 2):
		dp[i] = dp[i - 2] + nums[i]
	for i in range(6, n, 2):
		dp[i] = min(dp[i - 2], dp[i - 3]) + nums[i]
	res = min(dp[n - 1], dp[n - 2], res)
	res = min(res, sum(nums[2::2]))
	print(sum(nums) - res)


import sys
input = sys.stdin.readline
N = int(input())
A = list(map(int, input().split()))
ans = 0
dp = [[0, 0] for _ in range(N + 1)]
for (i, a) in enumerate(A):
	if i % 2 == 0:
		dp[i + 1][0] = dp[i][0]
		dp[i + 1][1] = dp[i][1] + a
	else:
		dp[i + 1][0] = dp[i][0] + a
		dp[i + 1][1] = dp[i][1]
for i in range(N):
	if i % 2 == 0:
		tmp = dp[i][0] + (dp[N][1] - dp[i][1])
	else:
		tmp = dp[i][1] + (dp[N][0] - dp[i][0])
	ans = max(ans, tmp)
print(ans)


from bisect import bisect_left, bisect_right
from sys import stdin, stdout
R = lambda : stdin.readline().strip()
RL = lambda f=None: list(map(f, R().split(' '))) if f else list(R().split(' '))
output = lambda x: stdout.write(str(x) + '\n')
output_list = lambda x: output(' '.join(map(str, x)))
n = int(R())
a = RL(int)
ass = []
for i in range(0, n, 2):
	ass.append(a[i])
for i in range(1, n, 2):
	ass.append(a[i])
ass += ass
k = (n + 1) // 2
sm = sum(ass[:k])
ans = sm
for i in range(k, len(ass)):
	sm += ass[i]
	sm -= ass[i - k]
	ans = max(sm, ans)
output(ans)


import sys, os, io

def rs():
	return sys.stdin.readline().rstrip()

def ri():
	return int(sys.stdin.readline())

def ria():
	return list(map(int, sys.stdin.readline().split()))

def ws(s):
	sys.stdout.write(s + '\n')

def wi(n):
	sys.stdout.write(str(n) + '\n')

def wia(a):
	sys.stdout.write(' '.join([str(x) for x in a]) + '\n')
import math, datetime, functools, itertools, operator
from collections import deque, defaultdict, OrderedDict
import collections

def main():
	starttime = datetime.datetime.now()
	if os.path.exists('input.txt'):
		sys.stdin = open('input.txt', 'r')
		sys.stdout = open('output.txt', 'w')
	zz = 0
	for _ in range(1):
		n = ri()
		a = ria()
		c = (n + 1) // 2
		z = a[::2] + a[1::2]
		z += z
		s = 0
		for i in range(c):
			s += z[i]
		m = 0
		for i in range(c, 2 * n):
			s -= z[i - c]
			s += z[i]
			m = max(m, s)
		wi(m)
	endtime = datetime.datetime.now()
	time = (endtime - starttime).total_seconds() * 1000
	if os.path.exists('input.txt'):
		print('Time:', time, 'ms')

class FastReader(io.IOBase):
	newlines = 0

	def __init__(self, fd, chunk_size=1024 * 8):
		self._fd = fd
		self._chunk_size = chunk_size
		self.buffer = io.BytesIO()

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, self._chunk_size))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self, size=-1):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, self._chunk_size if size == -1 else size))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

class FastWriter(io.IOBase):

	def __init__(self, fd):
		self._fd = fd
		self.buffer = io.BytesIO()
		self.write = self.buffer.write

	def flush(self):
		os.write(self._fd, self.buffer.getvalue())
		(self.buffer.truncate(0), self.buffer.seek(0))

class FastStdin(io.IOBase):

	def __init__(self, fd=0):
		self.buffer = FastReader(fd)
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')

class FastStdout(io.IOBase):

	def __init__(self, fd=1):
		self.buffer = FastWriter(fd)
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.flush = self.buffer.flush
sys.stdin = FastStdin()
sys.stdout = FastStdout()
main()


n = int(input())
array = list(map(int, input().split()))
prefix = [0 for i in range(n)]
suffix = [0 for i in range(n)]
i = 0
while i < n:
	if i < 2:
		prefix[i] = array[i]
	else:
		prefix[i] = prefix[i - 2] + array[i]
	i += 1
i = n - 1
while i >= 0:
	if i >= n - 2:
		suffix[i] = array[i]
	else:
		suffix[i] = suffix[i + 2] + array[i]
	i -= 1
maxi = 0
for i in range(n):
	if i == n - 1:
		maxi = max(prefix[i], maxi)
	else:
		maxi = max(maxi, prefix[i] + suffix[i + 1])
print(maxi)


def sums(i):
	if i != n - 1:
		if i % 2 == 0:
			return max(a[i], a[i + 1]) + psum[i][1] + psum[n - 1][0] - psum[i + 1][0]
		else:
			return max(a[i], a[i + 1]) + psum[i][0] + psum[n - 1][1] - psum[i + 1][1]
	else:
		return max(a[0], a[n - 1]) + psum[n - 1][1]
n = int(input())
a = list(map(int, input().split()))
if n == 1:
	print(a[0])
else:
	psum = []
	esum = [0, 0]
	for i in range(n):
		if i % 2 == 0:
			esum[0] += a[i]
		else:
			esum[1] += a[i]
		psum += [esum[:]]
	maxi = 0
	for i in range(n - 1):
		maxi = max(maxi, sums(i))
	print(maxi)


from sys import stdin
n = int(stdin.readline())
arr = list(map(int, stdin.readline().rstrip().split(' ')))
answer = 0
sumArr = []
prefixEven = [0]
prefixOdd = [0]
for i in range(n):
	if i % 2 == 0:
		prefixEven.append(prefixEven[-1] + arr[i])
	else:
		prefixOdd.append(prefixOdd[-1] + arr[i])
for i in range(n):
	if i % 2 == 0:
		sumArr.append(prefixEven[-1] - prefixEven[i // 2] + prefixOdd[i // 2])
	else:
		sumArr.append(prefixOdd[-1] - prefixOdd[(i - 1) // 2] + prefixEven[(i + 1) // 2])
print(max(sumArr))


import sys
input = sys.stdin.buffer.readline

def print(val):
	sys.stdout.write(str(val) + '\n')

def prog():
	n = int(input())
	a = list(map(int, input().split()))
	circle = []
	for i in range(0, n, 2):
		circle.append(a[i])
	for i in range(1, n - 1, 2):
		circle.append(a[i])
	circle.extend(circle)
	curr = 0
	for i in range((n + 1) // 2):
		curr += circle[i]
	mx_total = curr
	for i in range((n + 1) // 2, 2 * n):
		curr += circle[i] - circle[i - (n + 1) // 2]
		mx_total = max(mx_total, curr)
	print(mx_total)
prog()


n = int(input())
a = [int(x) for x in input().split()]
for i in range(n):
	a.append(a[i])
n *= 2
for i in range(n):
	if i > 1:
		a[i] += a[i - 2]
max1 = 0
m = int(n / 2)
for i in range(m, n):
	r = a[i]
	if i > m:
		r -= a[i - m - 1]
	max1 = max(max1, r)
print(max1)


n = int(input())
a = [int(i) for i in input().split()]
b = []
for i in range(0, n, 2):
	b.append(a[i])
else:
	ind = len(b)
for i in range(1, n, 2):
	b.append(a[i])
b.extend(b)
ans = sum(b[:ind])
lsum = ans
for i in range(ind, len(b)):
	lsum -= b[i - ind]
	lsum += b[i]
	ans = max(ans, lsum)
print(ans)


n = int(input())
b = list(map(int, input().split()))
preodd = [0]
preeven = [0]
curr1 = 0
curr2 = 0
for j in range(n):
	if j % 2 == 0:
		curr1 += b[j]
	else:
		curr2 += b[j]
	preeven.append(curr1)
	preodd.append(curr2)
ans = -1
for j in range(n):
	ans = max(ans, max(b[j] + preeven[j] + preodd[-1] - preodd[j + 1], b[j] + preodd[j] + preeven[-1] - preeven[j + 1]))
print(ans)


import sys
from itertools import accumulate

def input():
	return sys.stdin.readline().strip()

def list2d(a, b, c):
	return [[c] * b for i in range(a)]

def list3d(a, b, c, d):
	return [[[d] * c for j in range(b)] for i in range(a)]

def list4d(a, b, c, d, e):
	return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]

def ceil(x, y=1):
	return int(-(-x // y))

def INT():
	return int(input())

def MAP():
	return map(int, input().split())

def LIST(N=None):
	return list(MAP()) if N is None else [INT() for i in range(N)]

def Yes():
	print('Yes')

def No():
	print('No')

def YES():
	print('YES')

def NO():
	print('NO')
INF = 10 ** 19
MOD = 10 ** 9 + 7
N = INT()
A = LIST()
A2 = []
for (i, a) in enumerate(A):
	if i % 2 == 0:
		A2.append(a)
for (i, a) in enumerate(A):
	if i % 2 == 1:
		A2.append(a)
K = ceil(N, 2)
A2 += A2
acc = [0] + list(accumulate(A2))
ans = 0
for i in range(N):
	ans = max(ans, acc[i + K] - acc[i])
print(ans)


n = int(input())
A = list(map(int, input().split()))
B = A[::2] + A[1::2]
B *= 2
m = (n + 1) // 2
v = sum(B[:m])
best = v
for i in range(n):
	v -= B[i]
	v += B[i + m]
	best = max(best, v)
print(best)


n = int(input())
a = [int(x) for x in input().split()]
if n == 1:
	print(a[0])
	exit()
evens = [a[0]]
odds = [a[1]]
for i in range(2, n):
	if i % 2 == 0:
		evens.append(evens[-1] + a[i])
	else:
		odds.append(odds[-1] + a[i])
maxi = 0
for i in range(len(evens)):
	score = evens[i]
	if i == 0:
		score += odds[-1]
	else:
		score += odds[-1] - odds[i - 1]
	if score > maxi:
		maxi = score
for i in range(len(odds)):
	score = odds[i]
	score += evens[-1] - evens[i]
	if score > maxi:
		maxi = score
print(maxi)


import sys
n = int(input())
a = list(map(int, input().split()))
flag = 0
if len(a) == 1:
	print(a[0])
	flag = 1
if flag == 0:
	new_arr = []
	for i in range(1, len(a), 2):
		new_arr.append(a[i])
	for i in range(0, len(a), 2):
		new_arr.append(a[i])
	new_arr += new_arr
	k = (n + 1) // 2
	s = sum(new_arr[:k])
	ans = s
	for i in range(k, 2 * n):
		s -= new_arr[i - k]
		s += new_arr[i]
		ans = max(ans, s)
	print(ans)


n = int(input())
a = input().split()
totSum = 0
for i in range(n):
	totSum += int(a[i])
maxSum = 0
tempSum = 0
for i in range(n // 2 + 1):
	maxSum += int(a[2 * i])
	tempSum = maxSum
for i in range(0, n - 1):
	tempSum = totSum - tempSum + int(a[i])
	maxSum = max(maxSum, tempSum)
print(maxSum)


n = int(input())
a = list(map(int, input().split()))
if n == 1:
	print(a[0])
	exit(0)
a = [0] + a + a
pref = [0, a[1]]
for i in range(2, len(a)):
	pref.append(a[i] + pref[-2])
print(max([a[i] + a[i - 1] + pref[i - 3] - pref[i - n] for i in range(n + 1, 2 * n + 1)]))


n = int(input())
a = list(map(int, input().split()))
if n == 1:
	print(a[0])
elif n == 3:
	print(sum(a) - min(a))
else:
	start = list(range(n))
	end = [None] * n
	S = [0] * n
	L = n // 2
	(s0, s1) = (0, 1)
	(cur0, cur1) = (s0, s1)
	for i in range(L):
		cur0 = (s0 + i * 2) % n
		cur1 = (s1 + i * 2) % n
		S[s0] += a[cur0]
		S[s1] += a[cur1]
	end[s0] = cur0
	end[s1] = cur1
	for i in range(2, n):
		i_ = i - 2
		end_ = end[i_]
		end[i] = (end_ + 2) % n
		S[i] = S[i_] - a[i_] + a[end[i]]
	min_ = min(S)
	print(sum(a) - min_)


import sys
import bisect
import math as mt
input = sys.stdin.readline
t = 1
mod = 10 ** 9 + 7
for _ in range(t):
	n = int(input())
	l = list(map(int, input().split()))
	l1 = []
	for i in range(0, n, 2):
		l1.append(l[i])
	for j in range(1, n, 2):
		l1.append(l[j])
	(maxi, suma) = (0, 0)
	cnt = 1
	for i in range((n + 1) // 2):
		suma += l1[i]
	maxi = suma
	x = (n + 1) // 2
	i = x
	while cnt < n:
		suma -= l1[(i - x) % n]
		suma += l1[i % n]
		i += 1
		maxi = max(maxi, suma)
		cnt += 1
	print(maxi)


from collections import defaultdict
T = 1
for _ in range(T):
	n = int(input())
	l = [int(i) for i in input().split()]
	r = []
	for i in range(0, n, 2):
		r.append(l[i])
	for i in range(1, n, 2):
		r.append(l[i])
	f = [i for i in r]
	for i in range(len(r)):
		f.append(r[i])
	s = 0
	x = (n + 1) // 2
	for i in range(x):
		s += f[i]
	tmp = s
	i = 0
	j = x
	while j < len(f):
		tmp -= f[i]
		tmp += f[j]
		i += 1
		j += 1
		s = max(tmp, s)
	print(s)


n = int(input())
arr = list(map(int, input().split()))
tot = 0
for i in range(0, n, 2):
	tot += arr[i]
maxi = tot
for i in range(0, 2 * n - 2, 2):
	tot = tot - arr[i % n] + arr[(i + 1) % n]
	maxi = max(maxi, tot)
print(maxi)


import sys
import math
import bisect
from sys import stdin
from itertools import groupby
from heapq import heapify, heappop, heappush
from collections import deque, Counter, OrderedDict
input = iter(sys.stdin.buffer.read().decode().splitlines()).__next__

def neo():
	return map(int, input().split())

def Neo():
	return list(map(int, input().split()))
N = int(input())
t = (N + 1) // 2
A = Neo()
c = sum(A[0::2])
m = c
for i in range(0, 2 * N - 2, 2):
	c = c - A[i % N] + A[(i + 1) % N]
	m = max(c, m)
print(m)


n = int(input())
l = [int(x) for x in input().split()] * 2
for i in range(2, 2 * n):
	l[i] += l[i - 2]
s = 0
for i in range(n):
	if i >= 2:
		a = l[n + i - 1] - l[i - 2]
	else:
		a = l[n + i - 1]
	s = max(s, a)
print(s)


import sys
input = sys.stdin.readline
n = int(input())
a = [int(x) for x in input().split()]
for i in range(n):
	a.append(a[i])
n *= 2
for i in range(n):
	if i > 1:
		a[i] += a[i - 2]
max1 = 0
m = int(n / 2)
for i in range(m, n):
	r = a[i]
	if i > m:
		r -= a[i - m - 1]
	max1 = max(max1, r)
print(max1)


n = int(input())
A = list(map(int, input().split()))
L = list()
for _ in range(2):
	i = 0
	while i < n:
		L.append(A[i])
		i += 2
	i = 1
	while i < n:
		L.append(A[i])
		i += 2
size = (n + 1) // 2
window = 0
for i in range(size):
	window += L[i]
ans = window
i = 0
j = size - 1
while j < len(L) - 1:
	window += L[j + 1]
	window -= L[i]
	i += 1
	j += 1
	ans = max(ans, window)
print(ans)


n = int(input())
l = list(map(int, input().split()))
s = sum(l)
if n == 1:
	print(s)
	exit()
if n == 3:
	print(s - min(l))
	exit()
res = []
maxi = 0
if n // 2 % 2 == 1:
	r = l[0]
	for i in range(n // 2 // 2):
		r += l[i * 2 + 2]
	for i in range(n // 2 // 2):
		r += l[-1 * (i * 2 + 2)]
	res += [r]
	mini = r
	for i in range(1, n):
		res += [s - res[-1] - l[(i + 2 * (n // 2 // 2) + 1) % n]]
		mini = min(res[-1], mini)
else:
	r = 0
	for i in range(n // 2 // 2):
		r += l[i * 2 + 1]
	for i in range(n // 2 // 2):
		r += l[-1 * (i * 2 + 1)]
	res += [r]
	mini = r
	for i in range(1, n):
		res += [s - res[-1] - l[(i + 2 * (n // 2 // 2)) % n]]
		mini = min(res[-1], mini)
print(s - mini)


n = int(input())
a = list(map(int, input().split()))
if n == 1:
	print(a[0])
elif n == 2:
	print(max(a))
else:
	a = a[::2] + a[1::2]
	v = (n + 1) // 2
	mm = 0
	a1 = [0]
	for i in range(n):
		a1.append(a1[-1] + a[i])
	for i in range(v):
		a1.append(a1[-1] + a[i])
	output = max([a1[i + v] - a1[i] for i in range(n)])
	print(output)


import sys
input = sys.stdin.readline
n = int(input())
x = list(map(int, input().split()))
x = x + x
if len(x) == 2:
	print(x[0])
else:
	best = 0
	tmp = 0
	tmp += x[0]
	for i in range(1, n, 2):
		tmp += x[i]
	best = max(best, tmp)
	for i in range(0, n - 1, 2):
		tmp -= x[i]
		tmp -= x[i + 1]
		tmp += x[i + 2]
		tmp += x[n + i]
		best = max(best, tmp)
	x = [x[-1]] + x[:-1]
	tmp = 0
	tmp += x[0]
	for i in range(1, n, 2):
		tmp += x[i]
	best = max(best, tmp)
	for i in range(0, n - 1, 2):
		tmp -= x[i]
		tmp -= x[i + 1]
		tmp += x[i + 2]
		tmp += x[n + i]
		best = max(best, tmp)
	print(best)


import sys
input = sys.stdin.readline
n = int(input())
a = list(map(int, input().split()))
if n == 1:
	print(a[0])
	exit()
b = [0]
cnt = 0
idx = 0
while cnt <= 2 * n + 5:
	b.append(b[-1] + a[idx])
	cnt += 1
	idx += 2
	if idx >= n:
		idx -= n
res = b[-1]
for i in range(len(b)):
	if i + n // 2 >= len(b):
		break
	res = min(res, b[i + n // 2] - b[i])
print(sum(a) - res)


n = int(input())
arr = list(map(int, input().split()))
lis = []
for i in range(n + (n - 1) // 2):
	lis.append(arr[2 * i % n])
ans = sum(lis[:(n + 1) // 2])
temp = ans
for i in range(1, n):
	temp -= lis[i - 1]
	temp += lis[(n + 1) // 2 + i - 1]
	ans = max(ans, temp)
print(ans)


n = int(input())
a = list(map(int, input().split()))
if n != 1:
	maxCircle = 0
	maxCircleCand = a[0]
	for i in range(1, n, 2):
		maxCircleCand += a[i]
	maxCircle = maxCircleCand
	for i in range(1, n, 2):
		maxCircleCand -= a[i]
		maxCircleCand += a[i + 1]
		if maxCircle < maxCircleCand:
			maxCircle = maxCircleCand
	maxCircleCand = 0
	maxCircleCand += a[1]
	for i in range(2, n, 2):
		maxCircleCand += a[i]
	if maxCircle < maxCircleCand:
		maxCircle = maxCircleCand
	for i in range(2, n - 1, 2):
		maxCircleCand -= a[i]
		maxCircleCand += a[i + 1]
		if maxCircle < maxCircleCand:
			maxCircle = maxCircleCand
	print(maxCircle)
else:
	print(a[0])


n = int(input())
l = list(map(int, input().split()))
for i in range(2, n):
	l[i] = l[i] + l[i - 2]
s = l[-1]
for i in range(1, n):
	if i % 2 == 0:
		s = max(s, l[-1] - l[i - 2] + l[i - 1])
	elif i > 1:
		s = max(s, l[-2] - l[i - 2] + l[i - 1])
	else:
		s = max(s, l[-2] + l[i - 1])
print(s)


n = int(input())
A = input().split(' ')
for i in range(n):
	A[i] = int(A[i])
if n == 1:
	print(A[0])
else:
	s = 0
	k = int((n - 1) / 2)
	for i in range(k):
		s += A[2 * i]
	m = s
	for i in range(k):
		s = s + A[2 * k - 1 - 2 * i] - A[2 * k - 2 - 2 * i]
		m = min(m, s)
	for i in range(k):
		s = s + A[2 * k - 2 * i] - A[2 * k - 1 - 2 * i]
		m = min(m, s)
	print(sum(A) - m)


n = int(input())
a = list(map(lambda x: int(x), input().split()))
new_a = []
for i in range(0, len(a), 2):
	new_a.append(a[i])
for j in range(1, len(a), 2):
	new_a.append(a[j])
length = (n + 1) // 2
new_a = new_a + new_a[0:length - 1]
window = new_a[0:length]
prefix_sum = [new_a[0]]
for i in range(1, len(new_a)):
	prefix_sum.append(prefix_sum[i - 1] + new_a[i])
s = prefix_sum[length - 1]
answer = s
for i in range(length, len(new_a)):
	s = s - new_a[i - length] + new_a[i]
	answer = max(answer, s)
print(answer)


n = int(input())
a = [int(x) for x in input().split()]
o = [0] * n
e = [0] * n
for i in range(n):
	if i > 0:
		o[i] = o[i - 1]
		e[i] = e[i - 1]
	if i % 2 == 0:
		e[i] += a[i]
	else:
		o[i] += a[i]
ans = max(e[n - 1], o[n - 1])
if n % 2 == 1:
	for i in range(n):
		if i % 2 == 0:
			ans = max(ans, e[i] + o[n - 1] - o[i])
		else:
			ans = max(ans, o[i] + e[n - 1] - e[i])
print(ans)


n = int(input())
arr = list(map(int, input().split(' ')))
even_pos = arr[::2]
odd_pos = arr[1::2]
arr = even_pos + odd_pos + even_pos
m = (n + 1) // 2
s = sum(arr[:m])
s_max = s
for i in range(n):
	s -= arr[i]
	s += arr[m + i]
	s_max = max(s, s_max)
print(s_max)


n = int(input())
a = list(map(int, input().split()))
s = sum(a)
d = 0
an = 0
for i in range(0, n, 2):
	d += a[i]
for i in range(len(a)):
	an = max(an, d)
	d = s - d
	d += a[i]
print(an)


n = int(input())
a = list(map(int, input().split()))
a *= 2
acc1 = [0, a[0]]
acc2 = [0]
for i in range(1, 2 * n):
	if i % 2 == 0:
		acc1.append(acc1[-1] + a[i])
	else:
		acc2.append(acc2[-1] + a[i])
ans = 0
for i in range(n // 2 + 1, n + 1):
	ans = max(ans, acc2[i] - acc2[i - n // 2 - 1], acc1[i] - acc1[i - n // 2 - 1])
print(ans)


n = int(input())
a = list(map(int, input().split()))
l1 = [0]
l2 = [0]
r1 = [0]
r2 = [0]
for i in range(n):
	if i % 2 == 0:
		l1.append(l1[-1] + a[i])
		l2.append(l2[-1])
		r1.append(r1[-1])
		r2.append(r2[-1] + a[n - 1 - i])
	else:
		l1.append(l1[-1])
		l2.append(l2[-1] + a[i])
		r1.append(r1[-1] + a[n - 1 - i])
		r2.append(r2[-1])
ans = 0
for i in range(n + 1):
	ans = max(ans, l1[i] + r1[n - i], l2[i] + r2[n - i])
print(ans)


import sys
from functools import lru_cache, cmp_to_key
from heapq import merge, heapify, heappop, heappush, nsmallest
from math import ceil, floor, gcd, fabs, factorial, fmod, sqrt, inf
from collections import defaultdict as dd, deque, Counter as C
from itertools import combinations as comb, permutations as perm
from bisect import bisect_left as bl, bisect_right as br, bisect
from time import perf_counter
from fractions import Fraction
from decimal import Decimal
mod = pow(10, 9) + 7
mod2 = 998244353

def data():
	return sys.stdin.readline().strip()

def out(var):
	sys.stdout.write(str(var))

def outa(*var, end='\n'):
	sys.stdout.write(' '.join(map(str, var)) + end)

def l():
	return list(sp())

def sl():
	return list(ssp())

def sp():
	return map(int, data().split())

def ssp():
	return map(str, data().split())

def l1d(n, val=0):
	return [val for i in range(n)]

def l2d(n, m, val=0):
	return [l1d(n, val) for j in range(m)]
n = int(data())
arr = l()
new = [arr[i] for i in range(0, n, 2)] + [arr[i] for i in range(1, n, 2)]
new *= 2
half = (n + 1) // 2
s = sum(new[:half])
answer = s
window = deque(new[:])
for i in range(half, n * 2):
	s += new[i]
	s -= window.popleft()
	answer = max(answer, s)
out(answer)


import sys
import math
import heapq
from collections import defaultdict, deque
from decimal import *

def r():
	return int(input())

def rm():
	return map(int, input().split())

def rl():
	return list(map(int, input().split()))
n = r()
a = rl()
b = []
for i in range(1, n, 2):
	b.append(a[i])
for j in range(0, n, 2):
	b.append(a[j])
b = b + b
size = (n + 1) // 2
add = sum(b[:size])
sumi = sum(b[:size])
for i in range(size, len(b)):
	add += b[i] - b[i - size]
	sumi = max(sumi, add)
print(sumi)


n = int(input())
a = [int(x) for x in input().split()]
sumo = 0
for i in range(0, n, 2):
	sumo += a[i]
temo = sumo
for i in range(1, n, 2):
	temo += a[i] - a[i - 1]
	if temo > sumo:
		sumo = temo
for i in range(0, n, 2):
	temo += a[i] - a[i - 1]
	if temo > sumo:
		sumo = temo
print(sumo)


import math
import sys
input = sys.stdin.readline
t = 1
for cs in range(t):
	n = int(input())
	a = [int(_) for _ in input().split()]
	if n == 1:
		print(a[0])
		continue
	pre = [0] * n
	suf = [0] * n
	for i in range(n):
		if i >= 2:
			pre[i] = pre[i - 2] + a[i]
		else:
			pre[i] = a[i]
	for i in range(n - 1, -1, -1):
		if i + 2 < n:
			suf[i] = suf[i + 2] + a[i]
		else:
			suf[i] = a[i]
	ans = max(pre[0], pre[1])
	for i in range(n):
		if i > 0:
			ans = max(ans, pre[i - 1] + suf[i])
		if i >= 3:
			ans = max(ans, pre[i - 3] + suf[i])
	print(ans)


import os
import sys, math
from io import BytesIO, IOBase

def main():
	n = int(input())
	l = list(map(int, input().split()))
	if n == 1:
		print(l[0])
		return
	f = set()
	s = set()
	sf = 0
	ss = 0
	for i in range(2, n, 2):
		f.add(i)
		sf += l[i]
	for i in range(3, n, 2):
		s.add(i)
		ss += l[i]
	ans = -1
	for i in range(n):
		mx = max(l[i], l[(i + 1) % n])
		ans = max(ans, max(sf + mx, ss + mx))
		if i >= 0:
			if len(s) > len(f):
				s.remove((i + 2) % n)
				ss -= l[(i + 2) % n]
				f.add(i)
				sf += l[i]
			else:
				f.remove((i + 2) % n)
				sf -= l[(i + 2) % n]
				s.add(i)
				ss += l[i]
	print(ans)
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


from sys import stdin, stdout

def omkar_and_circle(n, a):
	if n == 1:
		return a[0]
	oea = [0] * (n + 1)
	oea[1] = a[0]
	oea[2] = a[1]
	for i in range(3, n + 1):
		oea[i] = a[i - 1] + oea[i - 2]
	res = 0
	for i in range(1, n + 1):
		sr = 0
		if i % 2 == 1:
			sr = oea[i] + oea[n - 1] - oea[i - 1]
		else:
			sr = oea[i] + oea[n] - oea[i - 1]
		res = max(res, sr)
	return res
n = int(stdin.readline())
a = list(map(int, stdin.readline().split()))
print(omkar_and_circle(n, a))


n = int(input())
a = list(map(int, input().split()))
a0 = [a[i] for i in range(n) if i % 2 == 0]
a1 = [a[i] for i in range(n) if i % 2 == 1]
a = a0 + a1
l = n // 2 + 1
ans = sum(a[:l])
ans_sub = sum(a[:l])
for i in range(n):
	ans_sub -= a[i]
	ans_sub += a[(i + l) % n]
	ans = max(ans, ans_sub)
print(ans)


x = int(input())
y = list(map(int, input().split(' ')))
bad = x // 2
s = 0
t = 0
y = y + y
for i in range(bad):
	s += y[2 * i]
	t += y[2 * i + 1]
mini = min(s, t)
for i in range(bad):
	s -= y[2 * i]
	s += y[2 * (bad + i)]
	t -= y[2 * i + 1]
	t += y[2 * (bad + i) + 1]
	mini = min(mini, min(s, t))
print(sum(y) // 2 - mini)


production = True
import sys, math, collections

def input(input_format=0, multi=0):
	if multi > 0:
		return [input(input_format) for i in range(multi)]
	else:
		next_line = sys.stdin.readline()[:-1]
		if input_format >= 10:
			use_list = False
			input_format = int(str(input_format)[-1])
		else:
			use_list = True
		if input_format == 0:
			formatted_input = [next_line]
		elif input_format == 1:
			formatted_input = list(map(int, next_line.split()))
		elif input_format == 2:
			formatted_input = list(map(float, next_line.split()))
		elif input_format == 3:
			formatted_input = list(next_line)
		elif input_format == 4:
			formatted_input = list(map(int, list(next_line)))
		elif input_format == 5:
			formatted_input = next_line.split()
		else:
			formatted_input = [next_line]
		return formatted_input if use_list else formatted_input[0]

def out(output_line, output_format=0, newline=True):
	formatted_output = ''
	if output_format == 0:
		formatted_output = str(output_line)
	elif output_format == 1:
		formatted_output = ' '.join(map(str, output_line))
	elif output_format == 2:
		formatted_output = '\n'.join(map(str, output_line))
	print(formatted_output, end='\n' if newline else '')

def log(*args):
	if not production:
		print('$$$', end='')
		print(*args)
enu = enumerate
ter = lambda a, b, c: b if a else c

def mapl(iterable, format=0):
	if format == 0:
		return list(map(int, iterable))
	elif format == 1:
		return list(map(str, iterable))
	elif format == 2:
		return list(map(list, iterable))

def solve():
	n = input(11)
	a = input(1)
	strip = a[::2] + a[1::2]
	strip += strip
	y = sum(strip[:n // 2 + 1])
	m1 = y
	l = 0
	r = n // 2 + 1
	log(r, strip[r], m1)
	while r < n * 2 - 1:
		y -= strip[l]
		y += strip[r]
		r += 1
		l += 1
		log(strip[l], strip[r], y)
		m1 = max(y, m1)
	log(m1)
	log(strip)
	m3 = ter(len(a) > 1, a[0] + a[-1], 0)
	log(m3)
	for (i, j) in zip(a, a[1:]):
		log(i, j)
		m3 = max(m3, i + j)
	out(max(m1, m3))
	return
solve()


import sys
input = sys.stdin.readline
n = int(input())
a = [int(x) for x in input().split()]
b = a + a
k = n // 2
now = 9223372036854775807
s = sum(a)
if n == 1:
	print(a[0])
	sys.exit()
(odd, even) = ([a[0]], [a[1]])
for x in range(2, 2 * n):
	if x % 2 == 0:
		odd.append(odd[-1] + b[x])
	else:
		even.append(even[-1] + b[x])
for x in range(n):
	if x + k >= n:
		break
	if odd[x + k] - odd[x] < now:
		now = odd[x + k] - odd[x]
	if even[x + k] - even[x] < now:
		now = even[x + k] - even[x]
print(s - now)


from sys import stdin, stdout
from math import gcd, ceil, sqrt
from collections import Counter
from bisect import bisect_left, bisect_right
ii1 = lambda : int(stdin.readline().strip())
is1 = lambda : stdin.readline().strip()
iia = lambda : list(map(int, stdin.readline().strip().split()))
isa = lambda : stdin.readline().strip().split()
mod = 1000000007
n = ii1()
arr = iia()
pre = [0] * n
post = pre[:]
for i in range(n):
	pre[i] = arr[i]
	if i >= 2:
		pre[i] += pre[i - 2]
for i in range(n)[::-1]:
	post[i] = arr[i]
	if i <= n - 3:
		post[i] += post[i + 2]
res = post[0]
for i in range(1, n):
	res = max(res, pre[i - 1] + post[i])
print(res)


import sys
input = sys.stdin.readline
for _ in range(1):
	n = int(input())
	a = list(map(int, input().split()))
	b = []
	for i in range(1, n, 2):
		b.append(a[i])
	for i in range(0, n, 2):
		b.append(a[i])
	b += b
	sz = (n + 1) // 2
	mx = cur = sum(b[:sz])
	for i in range(sz, len(b)):
		cur += b[i]
		cur -= b[i - sz]
		mx = max(mx, cur)
	print(mx)


from collections import deque
from collections import OrderedDict
import math
import sys
import os
import threading
import bisect
import operator
import heapq
from atexit import register
from io import BytesIO
import io
input = lambda : sys.stdin.readline().rstrip('\r\n')
n = int(input())
arr = list(map(int, input().split()))
cir = []
for i in range(0, n, 2):
	cir.append(arr[i])
for i in range(1, n, 2):
	cir.append(arr[i])
cir = [0] + cir + cir
pSum = [0] * (n * 2 + 5)
for i in range(1, len(cir)):
	pSum[i] = cir[i] + pSum[i - 1]
answer = 0
st = (n + 1) // 2
for i in range(1, len(cir) - st):
	val = pSum[i + st - 1] - pSum[i - 1]
	answer = max(answer, val)
print(answer)


import sys
input = sys.stdin.readline
from itertools import accumulate
n = int(input())
A = list(map(int, input().split()))
B = ([A[i] for i in range(n) if i % 2 == 0] + [A[i] for i in range(n) if i % 2 == 1]) * 2
SUM = [0] + list(accumulate(B))
MIN = 1 << 100
for i in range(n // 2, 2 * n + 1):
	MIN = min(MIN, SUM[i] - SUM[i - n // 2])
print(SUM[n] - MIN)


import io
import os
from collections import Counter, defaultdict, deque
import sys
sys.setrecursionlimit(10 ** 5)
inf = float('inf')

def solveBrute(N, A):
	if N == 1:
		return A[0]

	def getBest(i, j):
		if j - i == 1:
			return A[i]
		assert j - i > 1
		best = -inf
		for k in range(i + 1, j - 1):
			best = max(best, getBest(i, k) + getBest(k + 1, j))
		return best
	best = -inf
	A = deque(A)
	for i in range(N):
		A.rotate(1)
		best = max(best, getBest(0, N))
	return best

def solve(N, A):
	if N == 1:
		return A[0]
	evens = [0]
	odds = [0]
	for (i, x) in enumerate(A):
		if i % 2 == 0:
			evens.append(evens[-1] + x)
			odds.append(odds[-1] + 0)
		else:
			odds.append(odds[-1] + x)
			evens.append(evens[-1] + 0)
	best = evens[N]
	for i in range(1, N):
		if i % 2 == 1:
			best = max(best, evens[i] + odds[N] - odds[i])
		else:
			best = max(best, odds[i] + evens[N] - evens[i])
	return best
if False:
	import random
	random.seed(0)
	for j in range(1000):
		N = 5
		A = [random.randint(0, 10) for i in range(N)]
		ans1 = solveBrute(N, A)
		ans2 = solve(N, A)
		print('expected', A, ans1, ans2)
		assert ans1 == ans2
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
(N,) = [int(x) for x in input().split()]
A = [int(x) for x in input().split()]
ans = solve(N, A)
print(ans)


N = int(input())
A = list(map(int, input().split()))
cumev = [0]
cumod = [0]
for (i, a) in enumerate(A):
	cumev.append(cumev[-1] + (a if i % 2 == 0 else 0))
	cumod.append(cumod[-1] + (a if i % 2 else 0))
ans = cumev[-1]
for (i, (e, o)) in enumerate(zip(cumev, cumod)):
	if i % 2:
		tmp = e + cumod[-1] - o
	else:
		tmp = o + cumev[-1] - e
	ans = max(ans, tmp)
print(ans)


n = int(input())
arr = [0] + list(map(int, input().split()))
prefix = [0] * (n + 1)
suf = [0] * (n + 1)
for i in range(1, n + 1):
	prefix[i] = arr[i]
	if i >= 2:
		prefix[i] += prefix[i - 2]
for i in range(n, 0, -1):
	suf[i] = arr[i]
	if n - i >= 2:
		suf[i] += suf[i + 2]
ans = 0
for i in range(1, n + 1):
	ans = max(ans, prefix[i - 1] + suf[i])
print(ans)


for _ in range(1):
	n = int(input())
	a = list(map(int, input().split()))
	b = []
	for i in range(0, n, 2):
		b += [a[i]]
	for i in range(1, n, 2):
		b += [a[i]]
	b += b
	size = (n + 1) // 2
	ans = 0
	total = 0
	for i in range(size):
		total += b[i]
	ans = total
	for i in range(size, len(b)):
		total += b[i] - b[i - size]
		ans = max(ans, total)
	print(ans)


def getsum(a, b, pref):
	if b < a:
		b += n
	return pref[b] - pref[a]
for _ in range(1):
	n = int(input())
	arr = list(map(int, input().split()))
	pref0 = [0] * (len(arr) + 1)
	pref1 = [0] * (len(arr) + 1)
	for i in range(1, len(pref0)):
		pref0[i] = pref0[i - 1]
		pref1[i] = pref1[i - 1]
		if i % 2 == 1:
			pref0[i] += arr[i - 1]
		else:
			pref1[i] += arr[i - 1]
	mx = pref0[-1]
	s = sum(arr)
	for i in range(n - 1):
		if i % 2 == 0:
			x = pref0[i + 1] + (s - pref0[-1] - pref1[i + 1])
		else:
			x = pref1[i + 1] + (s - pref1[-1] - pref0[i + 1])
		mx = max(mx, x)
	print(mx)


n = int(input())
a = list(map(int, input().split()))
if n == 1:
	print(a[0])
	exit()
j = 0
odd = [a[1]]
even = [a[0]]
for i in range(3, n, 2):
	odd += [odd[-1] + a[i]]
for i in range(2, n, 2):
	even += [even[-1] + a[i]]
ans = -1
for i in range(n - 1):
	s = a[i] + a[i + 1]
	s1 = 0
	if i - 2 >= 0:
		if (i - 2) % 2 == 0:
			s1 = even[(i - 2) // 2]
		else:
			s1 = odd[(i - 2) // 2]
	s2 = 0
	if i + 3 <= n - 1:
		if (i + 1) % 2 == 0:
			s2 = even[-1] - even[(i + 1) // 2]
		else:
			s2 = odd[-1] - odd[(i + 1) // 2]
	ans = max(ans, s + s1 + s2)
s = 0
for i in range(n):
	if i % 2 == 0:
		s += a[i]
ans = max(ans, s)
print(ans)


n = int(input())
a = list(map(int, input().split()))
ans = 0
for i in range(n // 2):
	ans += a[2 * i]
ans += a[n - 1]
pointer = n - 1
pointer2 = 0
maxans = ans
for i in range(n):
	ans -= a[pointer2]
	pointer2 = (pointer2 + 2) % n
	ans += a[(pointer + 2) % n]
	pointer = (pointer + 2) % n
	maxans = max(ans, maxans)
print(maxans)


n = int(input())
a = list(map(int, input().split()))
even = [a[i] * (i % 2 == 0) for i in range(n)]
odd = [a[i] * (i % 2) for i in range(n)]
for i in range(1, n):
	even[i] += even[i - 1]
	odd[i] += odd[i - 1]
ans = even[-1]
for i in range(n - 1):
	temp = 0
	if i % 2 == 0:
		temp = even[i] + odd[-1] - odd[i]
	else:
		temp = odd[i] + even[-1] - even[i]
	ans = max(ans, temp)
print(ans)


import sys
import heapq, functools, collections
import math, random
from collections import Counter, defaultdict

def solve(lst):
	console('----- solving ------')
	arr = []
	arr.extend(lst[::2])
	arr.extend(lst[1::2])
	arr.extend(lst[::2])
	arr.extend(lst[1::2])
	psum = []
	ps = 0
	for i in arr:
		ps += i
		psum.append(ps)
	res = 0
	sub_length = (len(lst) + 1) // 2
	for i in range(len(lst)):
		res = max(res, psum[i + sub_length] - psum[i])
	return res

def console(*args):
	print('\x1b[36m', *args, '\x1b[0m', file=sys.stderr)
	return
_ = int(input())
lst = list(map(int, input().split()))
res = solve(lst)
print(res)


import math
LI = lambda : list(map(int, input().split()))
MI = lambda : map(int, input().split())
SI = lambda : input()
II = lambda : int(input())
n = II()
a = LI() * 2
for i in range(2, 2 * n):
	a[i] += a[i - 2]
m = 0
for i in range(n):
	if i >= 2:
		temp = a[n + i - 1] - a[i - 2]
	else:
		temp = a[n + i - 1]
	m = max(m, temp)
print(m)


import os, io
from sys import stdout
import collections
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
import sys

def primes(n):
	sieve = [True] * n
	for i in range(3, int(n ** 0.5) + 1, 2):
		if sieve[i]:
			sieve[i * i::2 * i] = [False] * ((n - i * i - 1) // (2 * i) + 1)
	return [2] + [i for i in range(3, n, 2) if sieve[i]]

def binomial_coefficient(n, k):
	if 0 <= k <= n:
		ntok = 1
		ktok = 1
		for t in range(1, min(k, n - k) + 1):
			ntok *= n
			ktok *= t
			n -= 1
		return ntok // ktok
	else:
		return 0

def powerOfK(k, max):
	if k == 1:
		return [1]
	if k == -1:
		return [-1, 1]
	result = []
	n = 1
	while n <= max:
		result.append(n)
		n *= k
	return result

def divisors(n):
	i = 1
	result = []
	while i * i <= n:
		if n % i == 0:
			if n / i == i:
				result.append(i)
			else:
				result.append(i)
				result.append(n / i)
		i += 1
	return result

def distance(xa, ya, xb, yb):
	return ((ya - yb) ** 2 + (xa - xb) ** 2) ** 0.5

def digitsSum(n):
	if n == 0:
		return 0
	r = 0
	while n > 0:
		r += n % 10
		n //= 10
	return r

def isValid(i, j, n, m):
	return i >= 0 and i < n and (j >= 0) and (j < m)

def print_grid(grid):
	for line in grid:
		print(' '.join(map(str, line)))

def kadane(a, size):
	max_so_far = 0
	max_ending_here = 0
	for i in range(0, size):
		max_ending_here = max_ending_here + a[i]
		if max_so_far < max_ending_here:
			max_so_far = max_ending_here
		if max_ending_here < 0:
			max_ending_here = 0
	return max_so_far

def prefixSum(arr):
	for i in range(1, len(arr)):
		arr[i] = arr[i] + arr[i - 1]
	return arr

def ceil(n, d):
	if n % d == 0:
		return n // d
	else:
		return n // d + 1

def _abs(a, b):
	return int(abs(a - b))

def evenodd(l):
	even = [e for e in l if e & 1 == 0]
	odd = [e for e in l if e & 1]
	return (even, odd)
n = int(input())
l = list(map(int, input().split()))
r = l[::2] + l[1::2]
r = r + r
s = n // 2 + 1
prev = sum(r[:s])
b = prev
(i, j) = (0, s)
while j < len(r):
	prev = prev + r[j] - r[i]
	b = max(b, prev)
	j += 1
	i += 1
print(b)


import sys, math
import io, os
from collections import defaultdict as dd, deque, Counter

def data():
	return sys.stdin.readline().strip()

def mdata():
	return list(map(int, data().split()))

def outl(var):
	sys.stdout.write(' '.join(map(str, var)) + '\n')

def out(var):
	sys.stdout.write(str(var) + '\n')
mod = int(1000000000.0) + 7
n = int(data())
a = mdata()
odd = [0]
even = [0]
for i in range(0, n - 1, 2):
	odd.append(odd[-1] + a[i])
	even.append(even[-1] + a[i + 1])
odd.append(odd[-1] + a[-1])
ans = odd[-1]
for i in range(1, n // 2 + 1):
	k = odd[i] + even[-1] - even[i - 1]
	ans = max(ans, k)
	k = odd[-1] - odd[n // 2 - i + 1] + even[n // 2 - i + 1]
	ans = max(ans, k)
out(ans)


n = int(input())
A = list(map(int, input().split()))
B = A[::2] + A[1::2]
B = B + B
m = (n + 1) // 2
window = sum(B[:m])
curSum = window
i = m
while i < len(B):
	curSum -= B[i - m]
	curSum += B[i]
	window = max(window, curSum)
	i += 1
print(window)


n = int(input())
a = list(map(int, input().rstrip().split()))
if n == 1:
	print(a[0])
else:
	b = a + a
	k = (n + 1) // 2
	s = 0
	for j in range(0, 2 * k, 2):
		s += b[j]
	M = s
	left = 0
	while left + 2 * k < 2 * n:
		s -= b[left]
		s += b[left + 2 * k]
		M = max(s, M)
		left += 2
	s = 0
	for j in range(1, 2 * k + 1, 2):
		s += b[j]
	M = max(s, M)
	left = 1
	while left + 2 * k < 2 * n:
		s -= b[left]
		s += b[left + 2 * k]
		M = max(s, M)
		left += 2
	print(M)


n = int(input())
L = list(map(int, input().split()))
odd_sum = 0
even_sum = 0
for (i, x) in enumerate(L):
	if i % 2 == 0:
		even_sum += x
	else:
		odd_sum += x
odd_sum += L[0]
current = max(even_sum, odd_sum)
for i in range(1, len(L)):
	if i % 2 == 0:
		odd_sum += L[i] - L[i - 1]
		current = max(current, odd_sum)
	else:
		even_sum += L[i] - L[i - 1]
		current = max(current, even_sum)
print(current)


import sys
from array import array
from typing import List, Tuple, TypeVar, Generic, Sequence, Union

def input():
	return sys.stdin.buffer.readline().decode('utf-8')

def main():
	n = int(input())
	a = list(map(int, input().split()))
	a = a[::2] + a[1::2]
	total = ans = sum(a[:n + 1 >> 1])
	for (l, r) in zip(range(n), range(n + 1 >> 1, (n + 1 >> 1) + n)):
		total += a[r % n] - a[l]
		ans = max(ans, total)
	print(ans)
main()


import os
import heapq
import sys
import math
import bisect
import operator
from collections import defaultdict
from io import BytesIO, IOBase

def prime_factors(n):
	i = 2
	factors = set()
	while i * i <= n:
		if n % i:
			i += 1
		else:
			factors.add(n // i)
			n = n // i
			factors.add(i)
	if n > 1:
		factors.add(n)
	return factors

def isPrime(n):
	if n == 2 or n == 3:
		return True
	if n % 2 == 0 or n < 2:
		return False
	for i in range(3, int(n ** 0.5) + 1, 2):
		if n % i == 0:
			return False
	return True

def inar():
	return [int(k) for k in input().split()]

def gcd(a, b):
	if b == 0:
		return a
	return gcd(b, a % b)

def lcmm(a, b):
	return a * b // gcd(a, b)

def main():
	n = int(input())
	arr = inar()
	if n == 1:
		print(arr[0])
	else:
		prefix = [arr[0], arr[1]]
		for i in range(2, n):
			prefix.append(prefix[i - 2] + arr[i])
		suffix = [0] * n
		for i in range(n - 1, -1, -1):
			if i + 2 > n - 1:
				suffix[i] = arr[i]
			else:
				suffix[i] = arr[i] + suffix[i + 2]
		ans = 0
		for i in range(n):
			if i - 1 == -1:
				ans = max(ans, suffix[i] + 0)
			else:
				ans = max(ans, suffix[i] + prefix[i - 1])
		print(ans)
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


import sys
import math
import heapq
import collections

def inputnum():
	return int(input())

def inputnums():
	return map(int, input().split())

def inputlist():
	return list(map(int, input().split()))

def inputstring():
	return [x for x in input()]

def inputmatrixchar(rows):
	arr2d = [[j for j in input().strip()] for i in range(rows)]
	return arr2d

def inputmatrixint(rows):
	arr2d = []
	for _ in range(rows):
		arr2d.append([int(i) for i in input().split()])
	return arr2d
n = inputnum()
a = inputlist()
sm = 0
for c in a:
	sm += c
vals = []
i = 0
while len(vals) < n + n // 2 - 1:
	vals.append(a[i])
	i += 2
	i %= n
mn = 0
cur = 0
for i in range(len(vals)):
	if i < n // 2:
		cur += vals[i]
		mn = cur
	else:
		cur -= vals[i - n // 2]
		cur += vals[i]
		mn = min(mn, cur)
print(sm - mn)


n = int(input())
a = [int(num) for num in input().split()]

def nex(x):
	if x == n - 1:
		return 0
	else:
		return x + 1
coun = (n - 1) // 2
if n > 3:
	i = 0
	sum = 0
	ind = 0
	while i < coun:
		sum += a[ind]
		ind += 2
		i += 1
	start = 0
	end = 2 * (coun - 1) + start
	lam = sum
	for i in range(n - 1):
		sum -= a[start]
		start = nex(nex(start))
		end = nex(nex(end))
		sum += a[end]
		lam = min(sum, lam)
	tot = 0
	for i in a:
		tot += i
	print(tot - lam)
elif n == 1:
	print(a[0])
else:
	print(a[0] + a[1] + a[2] - min(a[0], a[1], a[2]))


n = int(input())
a = list(map(int, input().split()))
ans = 0
cnt = 0
for i in range(0, n, 2):
	cnt += a[i]
ans = cnt
j = 0
for i in range(n):
	cnt -= a[j % n]
	cnt += a[(j + 1) % n]
	ans = max(cnt, ans)
	j += 2
print(ans)


n = int(input())
arr = [int(x) for x in input().split()]
arr1 = [[arr[0], 0]]
arr2 = []
sum1 = arr[0]
sum2 = 0
for i in range(n):
	if i % 2 == 0:
		arr2.append([arr[i], i])
		sum2 += arr[i]
	else:
		arr1.append([arr[i], i])
		sum1 += arr[i]
res = max(sum1, sum2)
(l, m) = (0, 1)
for i in range(n):
	if i % 2 == 0:
		index = arr2[l][1]
		sum2 -= arr2[l][0]
		arr2[l] = [arr[(index + 1) % n], (index + 1) % n]
		sum2 += arr2[l][0]
		l += 1
	else:
		index = arr1[m][1]
		sum1 -= arr1[m][0]
		arr1[m] = [arr[(index + 1) % n], (index + 1) % n]
		sum1 += arr1[m][0]
		m += 1
	res = max(res, sum1, sum2)
print(res)


from sys import stdin
import math
from collections import deque
from bisect import *
g = lambda : stdin.readline().strip()
gl = lambda : g().split()
gil = lambda : [int(var) for var in gl()]
gfl = lambda : [float(var) for var in gl()]
gcl = lambda : list(g())
gbs = lambda : [int(var) for var in g()]
mod = int(1000000000.0) + 7
inf = float('inf')
from collections import Counter
from heapq import *
t = 1
for _ in range(t):
	(n,) = gil()
	a = gil()
	a += a
	cs = []
	for i in range(2):
		cs.append([a[j] for j in range(i, 2 * n, 2)])
	w = n // 2 + 1
	(p1, p2) = (sum(cs[0][:w]), sum(cs[1][:w]))
	ans = max(p1, p2)
	for j in range(w, n):
		p1 += cs[0][j]
		p2 += cs[1][j]
		p1 -= cs[0][j - w]
		p2 -= cs[1][j - w]
		ans = max(p1, p2, ans)
	print(ans)


n = int(input())
arr = list(map(int, input().split()))
arr2 = arr[::2] + arr[1::2] + arr[::2] + arr[1::2]
length = n // 2 + 1
sum_now = sum(arr2[:length])
ans = sum_now
for i in range(length, n * 2):
	sum_now = sum_now + arr2[i] - arr2[i - length]
	ans = max(ans, sum_now)
print(ans)


n = int(input())
l = list(map(int, input().split()))
c = 0
for i in range(0, n, 2):
	c += l[i]
m = c
for i in range(0, 2 * n - 2, 2):
	c = c - l[i % n] + l[(i + 1) % n]
	if c > m:
		m = c
print(m)


import sys
from collections import defaultdict as dd
from collections import deque
from fractions import Fraction as f
from copy import *
from bisect import *
from heapq import *
from math import *
from itertools import permutations

def eprint(*args):
	print(*args, file=sys.stderr)
zz = 1
if zz:
	input = sys.stdin.readline
else:
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('all.txt', 'w')

def li():
	return [int(x) for x in input().split()]

def fli():
	return [float(x) for x in input().split()]

def gi():
	return [x for x in input().split()]

def fi():
	return int(input())

def swap(a, i, j):
	(a[i], a[j]) = (a[j], a[i])

def si():
	return list(input().rstrip())

def mi():
	return map(int, input().split())

def gh():
	sys.stdout.flush()

def graph(n, m):
	for i in range(m):
		(x, y) = mi()
		a[x].append(y)
		a[y].append(x)

def bo(i):
	return ord(i) - ord('a')
t = 1
while t > 0:
	t -= 1
	n = fi()
	a = li()
	o = [0]
	e = [0]
	for i in range(n):
		if i % 2:
			o.append(o[-1] + a[i])
			e.append(e[-1])
		else:
			e.append(e[-1] + a[i])
			o.append(o[-1])
	e.append(e[-1])
	o.append(o[-1])
	maxi = 0
	for i in range(1, n + 1):
		maxi = max([maxi, e[i - 1] + o[-1] - o[i] + a[i - 1], o[i - 1] + e[-1] - e[i] + a[i - 1]])
	print(maxi)


import io, os
from collections import deque
RL = lambda : list(map(int, input().split(' ')))

def smallestDivisor(n):
	if n % 2 == 0:
		return 2
	i = 3
	while i * i <= n:
		if n % i == 0:
			return i
		i += 2
	return n
n = int(input())
l = RL()
new = []
for i in range(0, n, 2):
	new.append(l[i])
for i in range(1, n, 2):
	new.append(l[i])
su = sum(new[0:(n + 1) // 2])
cur = su
for i in range(n):
	cur -= new[i]
	cur += new[((n + 1) // 2 + i) % n]
	su = max(su, cur)
print(su)


n = int(input())
a = list(map(int, input().split()))
pre = [0 for i in range(n)]
suff = [0 for i in range(n)]
for i in range(n):
	if i > 1:
		pre[i] = a[i] + pre[i - 2]
	else:
		pre[i] = a[i]
for i in range(n - 1, -1, -1):
	if i < n - 2:
		suff[i] = a[i] + suff[i + 2]
	else:
		suff[i] = a[i]
out = 0
out = max(out, suff[0])
for i in range(1, n):
	out = max(out, pre[i - 1] + suff[i])
print(out)


n = int(input())
m = n // 2
a = list(map(int, input().split()))
l = [0] * (n + 1)
for i in range(1, m + 2):
	l[i] = l[i - 1] + a[2 * i - 2]
for i in range(1, m + 1):
	l[m + i + 1] = l[m + i] + a[2 * i - 1]
mx = 0
for i in range(m + 1):
	mx = max(mx, l[m + 1 + i] - l[i])
for i in range(m, n + 1):
	mx = max(mx, l[-1] - l[i] + l[i - m])
print(mx)


import sys
inpy = [int(x) for x in sys.stdin.read().split()]
n = inpy[0]
nums = inpy[1:]
if n == 1:
	print(inpy[1])
	exit()
if n == 3:
	print(sum(inpy[1:]) - min(inpy[1:]))
	exit()
x = (n - 1) // 2
(odd, even) = (0, 0)
for i in range(1, n, 2):
	odd += nums[i]
for i in range(0, n, 2):
	even += nums[i]
res = even
(sodd, seven) = (0, 0)
for i in range(n):
	if i % 2 == 0:
		seven += nums[i]
		even -= nums[i]
		cur = seven + odd
	elif i % 2 == 1:
		sodd += nums[i]
		odd -= nums[i]
		cur = sodd + even
	res = max(res, cur)
print(res)


def solve():
	n = int(input())
	l = list(map(int, input().split()))
	l1 = [l[i] for i in range(n) if i % 2 == 0]
	l2 = [l[i] for i in range(n) if i % 2 == 1]
	l3 = l1 + l2 + l1 + l2
	lw = 0
	rw = (n + 1) // 2 - 1
	s = sum([l3[i] for i in range((n + 1) // 2)])
	mx = s
	while rw < 2 * n:
		s -= l3[lw]
		lw += 1
		rw += 1
		if rw >= 2 * n:
			break
		s += l3[rw]
		mx = max(mx, s)
	print(mx)
	return
t = 1
while t > 0:
	t -= 1
	solve()


import heapq

def solve(arr):
	even_indicies = arr[0:len(arr):2]
	odd_indicies = arr[1:len(arr):2]
	modified_arr = even_indicies + odd_indicies + even_indicies
	sum_len = (len(arr) + 1) // 2
	summation = sum(modified_arr[:sum_len])
	max_sum = summation
	for i in range(len(arr) - 1):
		summation = summation - modified_arr[i] + modified_arr[i + sum_len]
		max_sum = max(summation, max_sum)
	return max_sum
n = int(input())
arr = [int(i) for i in input().split(' ')]
print(solve(arr))


n = int(input())
list1 = list(map(int, input().strip().split()))
list1 = [0] + list1
if n == 1:
	print(list1[1])
else:
	ans1 = list1[1]
	temp1 = 0
	for i in range(2, n, 2):
		temp1 += list1[i]
	mid1 = temp1
	for i in range(2, n, 2):
		temp1 = temp1 - list1[i] + list1[i + 1]
		if temp1 > mid1:
			mid1 = temp1
	ans2 = list1[2] + list1[n]
	temp2 = 0
	for i in range(3, n, 2):
		temp2 += list1[i]
	mid2 = temp2
	for i in range(3, n, 2):
		temp2 = temp2 - list1[i] + list1[i + 1]
		if temp2 > mid2:
			mid2 = temp2
	print(max(ans1 + mid1, ans2 + mid2))


from math import *
from collections import *
from bisect import *
import sys
input = sys.stdin.readline
t = 1
while t:
	t -= 1
	n = int(input())
	a = list(map(int, input().split()))
	r = sum(a)
	a = a + a
	(e, o) = (0, 0)
	for i in range(n - 1):
		if i % 2:
			o += a[i]
		else:
			e += a[i]
	mi = min(e, o)
	for i in range(n - 1, 2 * n):
		if i % 2:
			o += a[i]
			o -= a[i - n + 1]
		else:
			e += a[i]
			e -= a[i - n + 1]
		mi = min(mi, e, o)
	print(r - mi)


from sys import stdin, stdout
int_in = lambda : int(stdin.readline())
arr_in = lambda : [int(x) for x in stdin.readline().split()]
mat_in = lambda rows: [arr_in() for _ in range(rows)]
str_in = lambda : stdin.readline().strip()
out = lambda o: stdout.write('{}\n'.format(o))
arr_out = lambda o: out(' '.join(map(str, o)))
bool_out = lambda o: out('YES' if o else 'NO')
tests = lambda : range(1, int_in() + 1)
case_out = lambda i, o: out('Case #{}: {}'.format(i, o))

def solve(n, a):
	if n == 1:
		return a[0]
	arr = []
	for i in range(0, len(a), 2):
		arr.append(a[i])
	for i in range(1, len(a), 2):
		arr.append(a[i])
	arr += arr
	need = (n + 1) // 2
	curr = 0
	for i in range(need):
		curr += arr[i]
	best = curr
	for i in range(1, len(arr) - need):
		curr -= arr[i - 1]
		curr += arr[need + i - 1]
		best = max(best, curr)
	return best
n = int_in()
a = arr_in()
out(solve(n, a))


n = int(input())
a = list(map(int, input().split()))
if n == 1:
	print(a[0])
	exit(0)
v = [sum((a[i] for i in range(j, n, 2))) for j in range(2, 4)]
u = [0, 0]
ans = 0
for i in range(n):
	w = u[(i - 2) % 2] + a[i] + a[(i + 1) % n] + v[(i + 3) % 2]
	ans = max(ans, w)
	u[i % 2] += a[i]
	v[(i + 2) % 2] -= a[(i + 2) % n]
print(ans)


n = int(input())
l = list(map(int, input().split()))
k = sum(l)
l += l[0:2 * (n // 2 - 1)]
l1 = l[0::2]
l2 = l[1::2]
arr = []
r = l1[0:n // 2]
st = 0
end = n // 2
q = sum(r)
arr.append(q)
for i in range(n // 2):
	q = q - l1[st] + l1[end]
	arr.append(q)
	st += 1
	end += 1
r = l2[0:n // 2]
st = 0
end = n // 2
q = sum(r)
arr.append(q)
for i in range(n // 2 - 1):
	q = q - l2[st] + l2[end]
	arr.append(q)
	st += 1
	end += 1
print(k - min(arr))


from sys import stdin, stdout
import collections, heapq, bisect, math
input = stdin.readline

def rint():
	return int(input())

def rstr():
	return input().strip()

def rlstr():
	return list(input().strip().split())

def rlint():
	return list(map(int, input().split()))

def main():
	n = rint()
	arr = rlint()
	arr = arr[::2] + arr[1::2] + arr[::2]
	l = (n + 1) // 2
	cur = maxval = sum(arr[:l])
	for i in range(l, len(arr)):
		cur += arr[i] - arr[i - l]
		maxval = max(maxval, cur)
	print(maxval)
main()


import os, sys
from io import BytesIO, IOBase

def main():
	n = int(input())
	arr = list(map(int, input().split()))
	if n == 1:
		print(arr[0])
		exit()
	(cul_eve, cul_odd) = ([arr[0]], [0, 0, 0])
	(x, y) = (arr[0], 0)
	for i in range(1, n):
		if i % 2:
			y += arr[i]
			cul_eve.append(0)
			cul_odd.append(y)
		else:
			x += arr[i]
			cul_eve.append(x)
			cul_odd.append(0)
	ans = 0
	val = arr[0]
	for i in range(1, n):
		if i % 2:
			ans = max(ans, val + cul_odd[-2] - cul_odd[i])
		else:
			val += arr[i]
	ans = max(ans, val)
	val = arr[1]
	for i in range(2, n):
		if i % 2:
			val += arr[i]
		else:
			ans = max(ans, val + cul_eve[-1] - cul_eve[i - 2])
	print(ans)
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


from collections import defaultdict as dd
from collections import deque
import bisect
import heapq

def ri():
	return int(input())

def rl():
	return list(map(int, input().split()))

def solve():
	n = ri()
	A = rl()
	odd_total = 0
	even_total = 0
	for i in range(n):
		if i % 2 == 0:
			even_total += A[i]
		else:
			odd_total += A[i]
	best = 0
	even_before = 0
	odd_before = 0
	even_after = even_total
	odd_after = odd_total
	for i in range(n):
		if i % 2 == 0:
			even_after -= A[i]
			even_before += A[i]
			candidate = even_before + odd_after
		else:
			odd_after -= A[i]
			odd_before += A[i]
			candidate = odd_before + even_after
		best = max(best, candidate)
	print(best)
mode = 's'
if mode == 'T':
	t = ri()
	for i in range(t):
		solve()
else:
	solve()


from sys import stdin, gettrace
from itertools import accumulate
if gettrace():
	inputi = input
else:

	def input():
		return next(stdin)[:-1]

	def inputi():
		return stdin.buffer.readline()

def main():
	n = int(inputi())
	aa = [int(a) for a in inputi().split()]
	aa = aa * 2
	es = list(accumulate([a for a in aa[::2]]))
	os = list(accumulate([a for a in aa[1::2]]))
	ev = [es[i + n // 2] - es[i] + aa[i * 2] for i in range(n // 2 + 1)]
	ov = [os[i + n // 2] - os[i] + aa[i * 2 + 1] for i in range(n // 2)]
	print(max(ev + ov))
main()


from __future__ import division, print_function
from fractions import Fraction
import sys, bisect, heapq, copyreg, copy, statistics, os
from math import *
from collections import Counter, defaultdict, deque, OrderedDict
from itertools import combinations, permutations, accumulate
from bisect import bisect_left, bisect_right, bisect
from statistics import mode
from functools import reduce
from io import BytesIO, IOBase
from decimal import *
if sys.version_info[0] < 3:
	from __builtin__ import xrange as range
	from future_builtins import ascii, filter, hex, map, oct, zip

def bfs(adj, v):
	visited = [False] * (v + 1)
	q = deque()
	while q:
		pass

def graph(vertex):
	return [[] for i in range(vertex + 1)]

def lcm(a, b):
	return a * b // gcd(a, b)

def most_frequent(List):
	return Counter(List).most_common(1)[0][0]

def most_common(List):
	return mode(List)

def chinese_remainder(a, p):
	prod = reduce(op.mul, p, 1)
	x = [prod // pi for pi in p]
	return sum((a[i] * pow(x[i], p[i] - 2, p[i]) * x[i] for i in range(len(a)))) % prod

def createMatrix(rowCount, colCount, dataList):
	mat = []
	for i in range(rowCount):
		rowList = []
		for j in range(colCount):
			if dataList[j] not in mat:
				rowList.append(dataList[j])
		mat.append(rowList)
	return mat

def readTree():
	v = int(inp())
	adj = [set() for i in range(v + 1)]
	for i in range(v - 1):
		(u1, u2) = In()
		adj[u1].add(u2)
		adj[u2].add(u1)
	return (adj, v)

def sieve():
	li = [True] * 1000001
	(li[0], li[1]) = (False, False)
	prime = []
	for i in range(2, len(li), 1):
		if li[i] == True:
			for j in range(i * i, len(li), i):
				li[j] = False
	for i in range(1000001):
		if li[i] == True:
			prime.append(i)
	return prime

def setBit(n):
	count = 0
	while n != 0:
		n = n & n - 1
		count += 1
	return count

def digitsSum(n):
	if n == 0:
		return 0
	r = 0
	while n > 0:
		r += n % 10
		n //= 10
	return r

def ncr(n, r):
	r = min(r, n - r)
	numer = reduce(op.mul, range(n, n - r, -1), 1)
	denom = reduce(op.mul, range(1, r + 1), 1)
	return numer // denom

def factors(n):
	return list(set(reduce(list.__add__, ([i, n // i] for i in range(1, int(n ** 0.5) + 1) if n % i == 0))))

def prime_factors(n):
	i = 2
	factors = []
	while i * i <= n:
		if n % i:
			i += 1
		else:
			n //= i
			factors.append(i)
	if n > 1:
		factors.append(n)
	return len(set(factors))

def prefixSum(arr):
	for i in range(1, len(arr)):
		arr[i] = arr[i] + arr[i - 1]
	return arr

def binomial_coefficient(n, k):
	if 0 <= k <= n:
		ntok = 1
		ktok = 1
		for t in range(1, min(k, n - k) + 1):
			ntok *= n
			ktok *= t
			n -= 1
		return ntok // ktok
	else:
		return 0

def powerOfK(k, max):
	if k == 1:
		return [1]
	if k == -1:
		return [-1, 1]
	result = []
	n = 1
	while n <= max:
		result.append(n)
		n *= k
	return result

def kadane(a, size):
	max_so_far = 0
	max_ending_here = 0
	for i in range(0, size):
		max_ending_here = max_ending_here + a[i]
		if max_so_far < max_ending_here:
			max_so_far = max_ending_here
		if max_ending_here < 0:
			max_ending_here = 0
	return max_so_far

def divisors(n):
	result = []
	for i in range(1, ceil(sqrt(n)) + 1):
		if n % i == 0:
			if n / i == i:
				result.append(i)
			else:
				result.append(i)
				result.append(n / i)
	return result

def sumyilln(n):
	return n * (n + 1) // 2

def isPrime(n):
	if n <= 1:
		return False
	if n <= 3:
		return True
	if n % 2 == 0 or n % 3 == 0:
		return False
	for i in range(5, ceil(sqrt(n)) + 1, 6):
		if n % i == 0 or n % (i + 2) == 0:
			return False
	return True

def isPowerOf2(n):
	while n % 2 == 0:
		n //= 2
	return True if n == 1 else False

def power2(n):
	k = 0
	while n % 2 == 0:
		k += 1
		n //= 2
	return k

def sqsum(n):
	return n * (n + 1) * (2 * n + 1) // 6

def cusum(n):
	return sumn(n) ** 2

def pa(a):
	for i in range(len(a)):
		print(a[i], end=' ')
	print()

def pm(a, rown, coln):
	for i in range(rown):
		for j in range(coln):
			print(a[i][j], end=' ')
		print()

def pmasstring(a, rown, coln):
	for i in range(rown):
		for j in range(coln):
			print(a[i][j], end='')
		print()

def isPerfectSquare(n):
	return pow(floor(sqrt(n)), 2) == n

def nC2(n, m):
	return n * (n - 1) // 2 % m

def modInverse(n, p):
	return pow(n, p - 2, p)

def ncrmodp(n, r, p):
	num = den = 1
	for i in range(r):
		num = num * (n - i) % p
		den = den * (i + 1) % p
	return num * pow(den, p - 2, p) % p

def reverse(string):
	return ''.join(reversed(string))

def listtostr(s):
	return ' '.join([str(elem) for elem in s])

def binarySearch(arr, l, r, x):
	while l <= r:
		mid = l + (r - l) // 2
		if arr[mid] == x:
			return mid
		elif arr[mid] < x:
			l = mid + 1
		else:
			r = mid - 1
	return -1

def isPalindrome(s):
	return s == s[::-1]

def gt(x, h, c, t):
	return (x * h + (x - 1) * c) / (2 * x - 1)

def CountFrequency(my_list):
	freq = {}
	for item in my_list:
		freq[item] = freq[item] + 1 if item in freq else 1
	return freq

def CountFrequencyasPair(my_list1, my_list2, freq):
	for item in my_list1:
		freq[item][0] = freq[item][0] + 1 if item in freq else 1
	for item in my_list2:
		freq[item][1] = freq[item][1] + 1 if item in freq else 1
	return freq

def binarySearchCount(arr, n, key):
	left = 0
	right = n
	mid = 0
	while left < right:
		mid = (right + left) // 2
		if arr[mid] == key:
			while mid + 1 < n and arr[mid + 1] == key:
				mid += 1
			break
		elif arr[mid] > key:
			right = mid
		else:
			left = mid + 1
	while mid > -1 and arr[mid] > key:
		mid -= 1
	return mid

def primes(n):
	(sieve, l) = ([True] * (n + 1), [])
	for p in range(2, n + 1):
		if sieve[p]:
			l.append(p)
			for i in range(p, n + 1, p):
				sieve[i] = False
	return l

def Next_Greater_Element_for_all_in_array(arr):
	(s, n, reta, retb) = (list(), len(arr), [], [])
	arr1 = [list([0, i]) for i in range(n)]
	for i in range(n - 1, -1, -1):
		while len(s) > 0 and s[-1][0] <= arr[i]:
			s.pop()
		if len(s) == 0:
			arr1[i][0] = -1
		else:
			arr1[i][0] = s[-1]
		s.append(list([arr[i], i]))
	for i in range(n):
		reta.append(list([arr[i], i]))
		retb.append(arr1[i][0])
	return (reta, retb)

class LRUCache:

	def __init__(self, capacity: int):
		self.cache = OrderedDict()
		self.capacity = capacity

	def get(self, key: int) -> int:
		if key not in self.cache:
			return -1
		else:
			self.cache.move_to_end(key)
			return self.cache[key]

	def put(self, key: int, value: int) -> None:
		self.cache[key] = value
		self.cache.move_to_end(key)
		if len(self.cache) > self.capacity:
			self.cache.popitem(last=False)
if os.path.exists('in.txt'):
	sys.stdin = open('in.txt', 'r')

def inp():
	return sys.stdin.readline().strip()

def out(var):
	sys.stdout.write(str(var))

def I():
	return inp()

def II():
	return int(inp())

def FI():
	return float(inp())

def SI():
	return list(str(inp()))

def MI():
	return map(int, inp().split())

def LI():
	return list(MI())

def MF():
	return map(float, inp().split())

def LF():
	return list(MF())
MOD = 10 ** 9 + 7
mod = 998244353
(n, l) = (II(), LI())
(count, m) = (0, 0)
for i in range(0, n, 2):
	count += l[i]
	m += l[i]
for i in range(0, 2 * n - 2, 2):
	count = count - l[i % n] + l[(i + 1) % n]
	if count > m:
		m = count
print(m)


import sys
input = sys.stdin.buffer.readline
n = int(input())
a = list(map(int, input().split()))
(psm, ssm) = ([0] * n, [0] * n)
for i in range(n):
	psm[i] = a[i] + (psm[i - 2] if i - 2 >= 0 else 0)
for i in range(n - 1, -1, -1):
	ssm[i] = a[i] + (ssm[i + 2] if i + 2 < n else 0)
(mx, total) = (0, sum(a))
for i in range(1, n):
	sm = (psm[i - 3] if i - 3 >= 0 else 0) + ssm[i]
	mx = max(mx, total - sm)
mx = max(mx, total - ssm[0] + a[-1])
print(mx)


import sys

def input():
	return sys.stdin.readline().rstrip()

def input_split():
	return [int(i) for i in input().split()]
n = int(input())
arr = input_split()
start = sum([arr[2 * i] for i in range(1, n // 2 + 1)])
mini = start
for i in range(n // 2 - 1):
	start += arr[2 * i + 1]
	start -= arr[2 * i + 2]
	mini = min(start, mini)
start = sum([arr[2 * i + 1] for i in range(1, n // 2)])
start += arr[0]
mini = min(start, mini)
for i in range(n // 2 - 1):
	start += arr[2 + 2 * i]
	start -= arr[3 + 2 * i]
	mini = min(start, mini)
other_poss = sum([arr[2 * i + 1] for i in range(n // 2)])
mini = min(other_poss, mini)
ans = sum(arr) - mini
print(ans)


n = int(input())
li2 = list(map(int, input().split(' ', n)[:n]))
if n > 3:
	li = []
	for i in range(0, n, 2):
		li.append(li2[i])
	for i in range(1, n, 2):
		li.append(li2[i])
	li += li
	ws = (n + 1) // 2
	mx = 0
	for i in range(ws):
		mx += li[i]
	cs = mx
	for i in range(ws, len(li)):
		cs -= li[i - ws]
		cs += li[i]
		if cs > mx:
			mx = cs
	print(mx)
elif n == 1:
	print(li2[0])
else:
	print(sum(li2) - min(li2))


n = int(input())
l = list(map(int, input().split(' ')))
t = [l[i] for i in range(0, len(l), 2)]
t = t + [l[i] for i in range(1, len(l), 2)]
t = t + t
k = int((n + 1) / 2)
s = 0
for i in range(k):
	s += t[i]
curr = s
for i in range(k, len(t)):
	curr = curr + t[i] - t[i - k]
	s = max(s, curr)
print(s)


import sys
import bisect
input = sys.stdin.readline
n = int(input())
l = input().split()
li = [int(i) for i in l]
sumi = sum(li)
if n == 1:
	print(sumi)
	quit()
ans = 0
z = (n - 1) // 2
suff = [0 for i in range(z)]
suff[-1] = li[n - 2]
for i in range(z - 2, -1, -1):
	suff[i] = suff[i + 1] + li[2 * i + 1]
curr = 0
for i in range(z):
	curr += li[2 * i]
	if i == z - 1:
		ans = max(ans, sumi - curr)
	else:
		ans = max(ans, sumi - curr - suff[i + 1])
ans = max(ans, sumi - suff[0])
ok = 0
for i in range(2, n, 2):
	ok += li[i]
ans = max(ans, sumi - ok)
suff = [0 for i in range(z)]
suff[-1] = li[2 * z]
for i in range(z - 2, -1, -1):
	suff[i] = suff[i + 1] + li[2 * (i + 1)]
ok = 0
for i in range(z):
	ok += li[2 * i + 1]
	if i == z - 1:
		ans = max(ans, sumi - ok)
	else:
		ans = max(ans, sumi - ok - suff[i + 1])
print(ans)


import sys

def rs():
	return sys.stdin.readline().rstrip()

def ri():
	return int(sys.stdin.readline())

def ria():
	return list(map(int, sys.stdin.readline().split()))

def ws(s):
	sys.stdout.write(s)
	sys.stdout.write('\n')

def wi(n):
	sys.stdout.write(str(n))
	sys.stdout.write('\n')

def wia(a, sep=' '):
	sys.stdout.write(sep.join([str(x) for x in a]))
	sys.stdout.write('\n')

def main():
	n = ri()
	a = ria()
	b = a[::2] + a[1::2]
	b += b
	k = (n + 1) // 2
	s = sum(b[:k])
	best = s
	for r in range(k, 2 * n):
		s += b[r] - b[r - k]
		best = max(best, s)
	wi(best)
main()


n = int(input())
a = [int(i) for i in input().split()]
out = []
for i in range(0, n, 2):
	out.append(a[i])
for i in range(1, n, 2):
	out.append(a[i])
out = out + out
size = (n + 1) // 2
summ = sum(out[:size])
curr = summ
for i in range(1, len(out) - size + 1):
	curr = curr - out[i - 1] + out[i + size - 1]
	summ = max(curr, summ)
print(summ)


n = int(input())
a = list(map(int, input().strip().split()))[:n]
if n == 1:
	print(a[0])
	exit(0)
prefix = [0] * n
suffix = [0] * n
prefix[0] = a[0]
prefix[1] = a[1]
suffix[-1] = a[-1]
suffix[-2] = a[-2]
for i in range(2, n):
	prefix[i] = a[i] + prefix[i - 2]
for i in range(n - 3, -1, -1):
	suffix[i] = a[i] + suffix[i + 2]
ans = 0
for i in range(0, n, 2):
	ans = ans + a[i]
for i in range(1, n):
	ans = max(ans, prefix[i - 1] + suffix[i])
print(ans)


T = 100

def main():
	N = int(input())
	A = list(map(int, input().split()))
	EPA = [0 for i in range(N)]
	OPA = [0 for i in range(N)]
	for i in range(N):
		if i % 2 == 0:
			EPA[i] = A[i]
		else:
			OPA[i] = OPA[i] + A[i]
	(os, es) = (sum(OPA), sum(EPA))
	for i in range(1, N):
		EPA[i] = EPA[i] + EPA[i - 1]
		OPA[i] = OPA[i] + OPA[i - 1]
	ans = es
	for i in range(N - 1):
		if i % 2 == 0:
			tp = EPA[i] - OPA[i + 1] + os + A[i + 1]
			if tp > ans:
				ans = tp
		else:
			tp = OPA[i] - EPA[i + 1] + es + A[i + 1]
			if tp > ans:
				ans = tp
	print(ans)
main()


n = int(input())
l = list(map(int, input().split()))
pref_odd = [0]
curr = 0
for i in range(n):
	if i % 2 == 1:
		curr += l[i]
	pref_odd.append(curr)
pref_even = [0]
curr = 0
for i in range(n):
	if i % 2 == 0:
		curr += l[i]
	pref_even.append(curr)
best = 0
for i in range(n):
	o1 = pref_even[i] + (pref_odd[-1] - pref_odd[i + 1])
	o2 = pref_odd[i] + (pref_even[-1] - pref_even[i + 1])
	best = max(best, max(o1, o2) + l[i])
print(best)


n = int(input())
l = list(map(int, input().split()))
s = sum(l)
x = 0
k = n // 2
for i in range(k):
	x += l[i * 2]
minx = x
for i in range(n - 1):
	x -= l[i * 2 % n]
	x += l[(k + i) * 2 % n]
	minx = min(minx, x)
print(s - minx)


import sys
input = sys.stdin.readline

def main():
	n = int(input())
	a = [int(x) for x in input().split()]
	a = a[0::2] + a[1::2] + a[0::2] + a[1::2]
	k = (n + 1) // 2
	s = sum(a[:k])
	ans = s
	for i in range(k, len(a)):
		s -= a[i - k]
		s += a[i]
		ans = max(ans, s)
	print(ans)
main()


n = int(input())
a = list(map(int, input().split()))
a = [a[i % n] for i in range(0, 2 * n, 2)]
s1 = sum(a[:(n + 1) // 2])
sx = s1
for i in range(1, n):
	s1 += a[(i + (n - 1) // 2) % n] - a[i - 1]
	sx = max(sx, s1)
print(sx)


def modinv(n, p):
	return pow(n, p - 2, p)

def main():
	n = int(input())
	initials = [int(x) for x in input().split()]
	alternate_prefix = []
	alternate_suffix = [0] * n
	for i in range(n):
		if i > 1:
			alternate_prefix.append(initials[i] + alternate_prefix[i - 2])
		else:
			alternate_prefix.append(initials[i])
	for i in range(n - 1, -1, -1):
		if i + 2 < n:
			alternate_suffix[i] = alternate_suffix[i + 2] + initials[i]
		else:
			alternate_suffix[i] = initials[i]
	ans = 0
	for i in range(n - 1):
		cur = initials[i] + initials[i + 1]
		if i > 1:
			cur += alternate_prefix[i - 2]
		if i + 3 < n:
			cur += alternate_suffix[i + 3]
		ans = max(ans, cur)
	cur = 0
	for i in range(0, n, 2):
		cur += initials[i]
	ans = max(cur, ans)
	print(ans)
py2 = round(0.5)
if py2:
	from future_builtins import ascii, filter, hex, map, oct, zip
	range = xrange
import os, sys
from io import IOBase, BytesIO
BUFSIZE = 8192

class FastIO(BytesIO):
	newlines = 0

	def __init__(self, file):
		self._file = file
		self._fd = file.fileno()
		self.writable = 'x' in file.mode or 'w' in file.mode
		self.write = super(FastIO, self).write if self.writable else None

	def _fill(self):
		s = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
		self.seek((self.tell(), self.seek(0, 2), super(FastIO, self).write(s))[0])
		return s

	def read(self):
		while self._fill():
			pass
		return super(FastIO, self).read()

	def readline(self):
		while self.newlines == 0:
			s = self._fill()
			self.newlines = s.count(b'\n') + (not s)
		self.newlines -= 1
		return super(FastIO, self).readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.getvalue())
			(self.truncate(0), self.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		if py2:
			self.write = self.buffer.write
			self.read = self.buffer.read
			self.readline = self.buffer.readline
		else:
			self.write = lambda s: self.buffer.write(s.encode('ascii'))
			self.read = lambda : self.buffer.read().decode('ascii')
			self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


def examA():
	T = I()
	ans = []
	for _ in range(T):
		N = I()
		cur = [1 for _ in range(N)]
		ans.append(cur)
	for v in ans:
		print(' '.join(map(str, v)))
	return

def examB():

	def factorization(n):
		arr = defaultdict(int)
		temp = n
		for i in range(2, int(-(-n ** 0.5 // 1)) + 1):
			if temp % i == 0:
				cnt = 0
				while temp % i == 0:
					cnt += 1
					temp //= i
				arr[i] = cnt
		if temp != 1:
			arr[temp] = 1
		if arr == []:
			arr[n] = 1
		return arr

	def make_divisors(n):
		divisors = []
		for i in range(1, int(n ** 0.5) + 1):
			if n % i == 0:
				divisors.append(i)
				if i != n // i:
					divisors.append(n // i)
		return divisors
	T = I()
	ans = []
	for _ in range(T):
		N = I()
		f = make_divisors(N)
		if len(f) <= 2:
			cur = [1, N - 1]
		else:
			cur = [N // f[2], N - N // f[2]]
		ans.append(cur)
	for v in ans:
		print(' '.join(map(str, v)))
	return

def examC():
	T = I()
	ans = []
	for _ in range(T):
		N = I()
		A = LI()
		flag = True
		for i in range(N - 1):
			if A[i] >= A[i + 1]:
				flag = False
				break
		if flag:
			ans.append(0)
			continue
		L = [[A[i], i] for i in range(N)]
		L.sort()
		flag = True
		cur = 1
		for i in range(N):
			if A[i] == i:
				flag = False
				break
		if flag:
			cur += 1
		ans.append(cur)
	for v in ans:
		print(v)
	return

def examD():
	N = I()
	A = LI()
	odd = [0] * (N + 1)
	even = [0] * (N + 1)
	for i in range(N):
		odd[i + 1] += odd[i]
		even[i + 1] += even[i]
		if i % 2 == 0:
			odd[i + 1] += A[i]
		else:
			even[i + 1] += A[i]
	ans = 0
	for i in range(N):
		cur1 = odd[i] + even[-1] - even[i]
		cur2 = even[i] + odd[-1] - odd[i]
		ans = max(ans, cur1, cur2)
	print(ans)
	return

def examE():
	ans = 0
	print(ans)
	return

def examF():
	ans = 0
	print(ans)
	return
from decimal import getcontext, Decimal as dec
import sys, bisect, heapq
from copy import deepcopy
from heapq import heappop, heappush, heapify
from collections import Counter, defaultdict, deque
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

def I():
	return int(input())

def LI():
	return list(map(int, sys.stdin.readline().split()))

def DI():
	return dec(input())

def LDI():
	return list(map(dec, sys.stdin.readline().split()))

def LSI():
	return list(map(str, sys.stdin.readline().split()))

def LS():
	return sys.stdin.readline().split()

def SI():
	return sys.stdin.readline().strip()
global mod, mod2, inf, alphabet, _ep
mod = 10 ** 9 + 7
mod2 = 998244353
inf = 10 ** 18
_ep = dec('0.000000000001')
alphabet = [chr(ord('a') + i) for i in range(26)]
alphabet_convert = {chr(ord('a') + i): i for i in range(26)}
getcontext().prec = 28
sys.setrecursionlimit(2 * 10 ** 5)
examD()


import sys
input = sys.stdin.readline
n = int(input())
a = list(map(int, input().split()))
eacc = [0]
oacc = [0]
for i in range(n):
	eacc.append(eacc[-1] + (a[i] if i % 2 == 0 else 0))
	oacc.append(oacc[-1] + (a[i] if i % 2 == 1 else 0))
ans = 0
for i in range(n):
	if i % 2 == 0:
		ans = max(ans, oacc[i] + eacc[n] - eacc[i])
	else:
		ans = max(ans, eacc[i] + oacc[n] - oacc[i])
print(ans)


import math
import random
import heapq, bisect
import sys
from collections import deque, defaultdict
from fractions import Fraction
import sys
from collections import defaultdict
mod = 10 ** 9 + 7
mod1 = 998244353
import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')

class TreeNode:

	def __init__(self, k, v):
		self.key = k
		self.value = v
		self.left = None
		self.right = None
		self.parent = None
		self.height = 1
		self.num_left = 1
		self.num_total = 1

class AvlTree:

	def __init__(self):
		self._tree = None

	def add(self, k, v):
		if not self._tree:
			self._tree = TreeNode(k, v)
			return
		node = self._add(k, v)
		if node:
			self._rebalance(node)

	def _add(self, k, v):
		node = self._tree
		while node:
			if k < node.key:
				if node.left:
					node = node.left
				else:
					node.left = TreeNode(k, v)
					node.left.parent = node
					return node.left
			elif node.key < k:
				if node.right:
					node = node.right
				else:
					node.right = TreeNode(k, v)
					node.right.parent = node
					return node.right
			else:
				node.value = v
				return

	@staticmethod
	def get_height(x):
		return x.height if x else 0

	@staticmethod
	def get_num_total(x):
		return x.num_total if x else 0

	def _rebalance(self, node):
		n = node
		while n:
			lh = self.get_height(n.left)
			rh = self.get_height(n.right)
			n.height = max(lh, rh) + 1
			balance_factor = lh - rh
			n.num_total = 1 + self.get_num_total(n.left) + self.get_num_total(n.right)
			n.num_left = 1 + self.get_num_total(n.left)
			if balance_factor > 1:
				if self.get_height(n.left.left) < self.get_height(n.left.right):
					self._rotate_left(n.left)
				self._rotate_right(n)
			elif balance_factor < -1:
				if self.get_height(n.right.right) < self.get_height(n.right.left):
					self._rotate_right(n.right)
				self._rotate_left(n)
			else:
				n = n.parent

	def _remove_one(self, node):
		replacement = node.left or node.right
		if node.parent:
			if AvlTree._is_left(node):
				node.parent.left = replacement
			else:
				node.parent.right = replacement
			replacement.parent = node.parent
			node.parent = None
		else:
			self._tree = replacement
			replacement.parent = None
		node.left = None
		node.right = None
		node.parent = None
		self._rebalance(replacement)

	def _remove_leaf(self, node):
		if node.parent:
			if AvlTree._is_left(node):
				node.parent.left = None
			else:
				node.parent.right = None
			self._rebalance(node.parent)
		else:
			self._tree = None
		node.parent = None
		node.left = None
		node.right = None

	def remove(self, k):
		node = self._get_node(k)
		if not node:
			return
		if AvlTree._is_leaf(node):
			self._remove_leaf(node)
			return
		if node.left and node.right:
			nxt = AvlTree._get_next(node)
			node.key = nxt.key
			node.value = nxt.value
			if self._is_leaf(nxt):
				self._remove_leaf(nxt)
			else:
				self._remove_one(nxt)
			self._rebalance(node)
		else:
			self._remove_one(node)

	def get(self, k):
		node = self._get_node(k)
		return node.value if node else -1

	def _get_node(self, k):
		if not self._tree:
			return None
		node = self._tree
		while node:
			if k < node.key:
				node = node.left
			elif node.key < k:
				node = node.right
			else:
				return node
		return None

	def get_at(self, pos):
		x = pos + 1
		node = self._tree
		while node:
			if x < node.num_left:
				node = node.left
			elif node.num_left < x:
				x -= node.num_left
				node = node.right
			else:
				return (node.key, node.value)
		raise IndexError('Out of ranges')

	@staticmethod
	def _is_left(node):
		return node.parent.left and node.parent.left == node

	@staticmethod
	def _is_leaf(node):
		return node.left is None and node.right is None

	def _rotate_right(self, node):
		if not node.parent:
			self._tree = node.left
			node.left.parent = None
		elif AvlTree._is_left(node):
			node.parent.left = node.left
			node.left.parent = node.parent
		else:
			node.parent.right = node.left
			node.left.parent = node.parent
		bk = node.left.right
		node.left.right = node
		node.parent = node.left
		node.left = bk
		if bk:
			bk.parent = node
		node.height = max(self.get_height(node.left), self.get_height(node.right)) + 1
		node.num_total = 1 + self.get_num_total(node.left) + self.get_num_total(node.right)
		node.num_left = 1 + self.get_num_total(node.left)

	def _rotate_left(self, node):
		if not node.parent:
			self._tree = node.right
			node.right.parent = None
		elif AvlTree._is_left(node):
			node.parent.left = node.right
			node.right.parent = node.parent
		else:
			node.parent.right = node.right
			node.right.parent = node.parent
		bk = node.right.left
		node.right.left = node
		node.parent = node.right
		node.right = bk
		if bk:
			bk.parent = node
		node.height = max(self.get_height(node.left), self.get_height(node.right)) + 1
		node.num_total = 1 + self.get_num_total(node.left) + self.get_num_total(node.right)
		node.num_left = 1 + self.get_num_total(node.left)

	@staticmethod
	def _get_next(node):
		if not node.right:
			return node.parent
		n = node.right
		while n.left:
			n = n.left
		return n

class SegmentTree1:

	def __init__(self, data, default=300006, func=lambda a, b: min(a, b)):
		self._default = default
		self._func = func
		self._len = len(data)
		self._size = _size = 1 << (self._len - 1).bit_length()
		self.data = [default] * (2 * _size)
		self.data[_size:_size + self._len] = data
		for i in reversed(range(_size)):
			self.data[i] = func(self.data[i + i], self.data[i + i + 1])

	def __delitem__(self, idx):
		self[idx] = self._default

	def __getitem__(self, idx):
		return self.data[idx + self._size]

	def __setitem__(self, idx, value):
		idx += self._size
		self.data[idx] = value
		idx >>= 1
		while idx:
			self.data[idx] = self._func(self.data[2 * idx], self.data[2 * idx + 1])
			idx >>= 1

	def __len__(self):
		return self._len

	def query(self, start, stop):
		if start == stop:
			return self.__getitem__(start)
		stop += 1
		start += self._size
		stop += self._size
		res = self._default
		while start < stop:
			if start & 1:
				res = self._func(res, self.data[start])
				start += 1
			if stop & 1:
				stop -= 1
				res = self._func(res, self.data[stop])
			start >>= 1
			stop >>= 1
		return res

	def __repr__(self):
		return 'SegmentTree({0})'.format(self.data)

class SegmentTree:

	def __init__(self, data, default=0, func=lambda a, b: a + b):
		self._default = default
		self._func = func
		self._len = len(data)
		self._size = _size = 1 << (self._len - 1).bit_length()
		self.data = [default] * (2 * _size)
		self.data[_size:_size + self._len] = data
		for i in reversed(range(_size)):
			self.data[i] = func(self.data[i + i], self.data[i + i + 1])

	def __delitem__(self, idx):
		self[idx] = self._default

	def __getitem__(self, idx):
		return self.data[idx + self._size]

	def __setitem__(self, idx, value):
		idx += self._size
		self.data[idx] = value
		idx >>= 1
		while idx:
			self.data[idx] = self._func(self.data[2 * idx], self.data[2 * idx + 1])
			idx >>= 1

	def __len__(self):
		return self._len

	def query(self, start, stop):
		if start == stop:
			return self.__getitem__(start)
		stop += 1
		start += self._size
		stop += self._size
		res = self._default
		while start < stop:
			if start & 1:
				res = self._func(res, self.data[start])
				start += 1
			if stop & 1:
				stop -= 1
				res = self._func(res, self.data[stop])
			start >>= 1
			stop >>= 1
		return res

	def __repr__(self):
		return 'SegmentTree({0})'.format(self.data)

class Factorial:

	def __init__(self, MOD):
		self.MOD = MOD
		self.factorials = [1, 1]
		self.invModulos = [0, 1]
		self.invFactorial_ = [1, 1]

	def calc(self, n):
		if n <= -1:
			print('Invalid argument to calculate n!')
			print('n must be non-negative value. But the argument was ' + str(n))
			exit()
		if n < len(self.factorials):
			return self.factorials[n]
		nextArr = [0] * (n + 1 - len(self.factorials))
		initialI = len(self.factorials)
		prev = self.factorials[-1]
		m = self.MOD
		for i in range(initialI, n + 1):
			prev = nextArr[i - initialI] = prev * i % m
		self.factorials += nextArr
		return self.factorials[n]

	def inv(self, n):
		if n <= -1:
			print('Invalid argument to calculate n^(-1)')
			print('n must be non-negative value. But the argument was ' + str(n))
			exit()
		p = self.MOD
		pi = n % p
		if pi < len(self.invModulos):
			return self.invModulos[pi]
		nextArr = [0] * (n + 1 - len(self.invModulos))
		initialI = len(self.invModulos)
		for i in range(initialI, min(p, n + 1)):
			next = -self.invModulos[p % i] * (p // i) % p
			self.invModulos.append(next)
		return self.invModulos[pi]

	def invFactorial(self, n):
		if n <= -1:
			print('Invalid argument to calculate (n^(-1))!')
			print('n must be non-negative value. But the argument was ' + str(n))
			exit()
		if n < len(self.invFactorial_):
			return self.invFactorial_[n]
		self.inv(n)
		nextArr = [0] * (n + 1 - len(self.invFactorial_))
		initialI = len(self.invFactorial_)
		prev = self.invFactorial_[-1]
		p = self.MOD
		for i in range(initialI, n + 1):
			prev = nextArr[i - initialI] = prev * self.invModulos[i % p] % p
		self.invFactorial_ += nextArr
		return self.invFactorial_[n]

class Combination:

	def __init__(self, MOD):
		self.MOD = MOD
		self.factorial = Factorial(MOD)

	def ncr(self, n, k):
		if k < 0 or n < k:
			return 0
		k = min(k, n - k)
		f = self.factorial
		return f.calc(n) * f.invFactorial(max(n - k, k)) * f.invFactorial(min(k, n - k)) % self.MOD

def powm(a, n, m):
	if a == 1 or n == 0:
		return 1
	if n % 2 == 0:
		s = powm(a, n // 2, m)
		return s * s % m
	else:
		return a * powm(a, n - 1, m) % m

def sort_list(list1, list2):
	zipped_pairs = zip(list2, list1)
	z = [x for (_, x) in sorted(zipped_pairs)]
	return z

def product(l):
	por = 1
	for i in range(len(l)):
		por *= l[i]
	return por

def binarySearchCount(arr, n, key):
	left = 0
	right = n - 1
	count = 0
	while left <= right:
		mid = int((right + left) / 2)
		if arr[mid] <= key:
			count = mid + 1
			left = mid + 1
		else:
			right = mid - 1
	return count

def countdig(n):
	c = 0
	while n > 0:
		n //= 10
		c += 1
	return c

def binary(x, length):
	y = bin(x)[2:]
	return y if len(y) >= length else '0' * (length - len(y)) + y

def countGreater(arr, n, k):
	l = 0
	r = n - 1
	leftGreater = n
	while l <= r:
		m = int(l + (r - l) / 2)
		if arr[m] >= k:
			leftGreater = m
			r = m - 1
		else:
			l = m + 1
	return n - leftGreater

class TrieNode:

	def __init__(self):
		self.children = [None] * 26
		self.isEndOfWord = False

class Trie:

	def __init__(self):
		self.root = self.getNode()

	def getNode(self):
		return TrieNode()

	def _charToIndex(self, ch):
		return ord(ch) - ord('a')

	def insert(self, key):
		pCrawl = self.root
		length = len(key)
		for level in range(length):
			index = self._charToIndex(key[level])
			if not pCrawl.children[index]:
				pCrawl.children[index] = self.getNode()
			pCrawl = pCrawl.children[index]
		pCrawl.isEndOfWord = True

	def search(self, key):
		pCrawl = self.root
		length = len(key)
		for level in range(length):
			index = self._charToIndex(key[level])
			if not pCrawl.children[index]:
				return False
			pCrawl = pCrawl.children[index]
		return pCrawl != None and pCrawl.isEndOfWord

class Node:

	def __init__(self, data):
		self.data = data
		self.height = 0
		self.left = None
		self.right = None

class BinaryTrie:

	def __init__(self):
		self.root = Node(0)

	def insert(self, pre_xor):
		self.temp = self.root
		for i in range(31, -1, -1):
			val = pre_xor & 1 << i
			if val == 0:
				if not self.temp.right:
					self.temp.right = Node(0)
				self.temp = self.temp.right
			elif val >= 1:
				if not self.temp.left:
					self.temp.left = Node(0)
				self.temp = self.temp.left

	def do(self, temp):
		if not temp:
			return 0
		ter = temp
		temp.height = self.do(ter.left) + self.do(ter.right)
		if temp.height == 0:
			temp.height += 1
		return temp.height

	def query(self, xor):
		self.temp = self.root
		cur = 0
		i = 31
		while i > -1:
			val = xor & 1 << i
			if not self.temp:
				return cur
			if val >= 1:
				self.opp = self.temp.right
				if self.temp.left:
					self.temp = self.temp.left
				else:
					return cur
			else:
				self.opp = self.temp.left
				if self.temp.right:
					self.temp = self.temp.right
				else:
					return cur
			if self.temp.height == pow(2, i):
				cur += 1 << i
				self.temp = self.opp
			i -= 1
		return cur
n = int(input())
l = list(map(int, input().split()))
e = []
e1 = []
for i in range(n):
	if i % 2 == 0:
		e.append(l[i])
	else:
		e1.append(l[i])
s = SegmentTree(e)
s1 = SegmentTree(e1)
ans = 0
for i in range(len(e)):
	ans = max(ans, s.query(0, i) + s1.query(i, n // 2 - 1))
for i in range(len(e1)):
	ans = max(ans, s1.query(0, i) + s.query(i + 1, n // 2))
print(ans)


from __future__ import division, print_function
from fractions import Fraction
import sys
import os
from io import BytesIO, IOBase
from itertools import *
import bisect
from heapq import *
from math import *
from collections import deque
from collections import Counter as counter
from itertools import combinations as comb
from itertools import permutations as permutate
from bisect import bisect_left as bl
from bisect import bisect_right as br
from bisect import bisect
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')

def print(*args, **kwargs):
	(sep, file) = (kwargs.pop('sep', ' '), kwargs.pop('file', sys.stdout))
	at_start = True
	for x in args:
		if not at_start:
			file.write(sep)
		file.write(str(x))
		at_start = False
	file.write(kwargs.pop('end', '\n'))
	if kwargs.pop('flush', False):
		file.flush()
if sys.version_info[0] < 3:
	(sys.stdin, sys.stdout) = (FastIO(sys.stdin), FastIO(sys.stdout))
else:
	(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
mod = 1000000007

def inp():
	return sys.stdin.readline().rstrip('\r\n')

def out(var):
	sys.stdout.write(str(var))

def lis():
	return list(map(int, inp().split()))

def stringlis():
	return list(map(str, inp().split()))

def sep():
	return map(int, inp().split())

def strsep():
	return map(str, inp().split())

def zerolist(n):
	return [0] * n

def nextline():
	out('\n')

def testcase(t):
	for p in range(t):
		solve()

def printlist(a):
	for p in range(0, len(a)):
		out(str(a[p]) + ' ')

def lcm(a, b):
	return a * b // gcd(a, b)

def power(a, b):
	ans = 1
	while b > 0:
		if b % 2 == 1:
			ans *= a
		a *= a
		b //= 2
	return ans

def ncr(n, r):
	return factorial(n) // (factorial(r) * factorial(max(n - r, 1)))

def isPrime(n):
	if n <= 1:
		return False
	if n <= 3:
		return True
	if n % 2 == 0 or n % 3 == 0:
		return False
	i = 5
	while i * i <= n:
		if n % i == 0 or n % (i + 2) == 0:
			return False
		i = i + 6
	return True

def solve():
	n = int(inp())
	a = lis()
	new = []
	for i in range(0, n, 2):
		new.append(a[i])
	for i in range(1, n, 2):
		new.append(a[i])
	new *= 2
	pre = [0]
	for i in range(0, len(new)):
		pre.append(new[i] + pre[i])
	ans = 10 ** 20
	for i in range(n // 2, len(pre)):
		ans = min(ans, pre[i] - pre[i - n // 2])
	print(pre[n] - ans)
testcase(1)


import sys
input = sys.stdin.readline
I = lambda : list(map(int, input().split()))
(n,) = I()
l = I()
su = sum(l)
e = [l[i] for i in range(n) if i % 2 == 0]
es = sum(e)
o = [l[i] for i in range(n) if i % 2]
an = min(es - l[0], es - l[n - 1], su - es)
os = su - es
for i in range(1, len(e)):
	e[i] += e[i - 1]
for i in range(1, len(o)):
	o[i] += o[i - 1]
for i in range((n - 1) // 2 - 1):
	y = (n - 1) // 2
	x = min(e[i] + o[-1] - o[i], o[i] + e[-1] - e[i + 1])
	an = min(an, x)
print(su - an)


import math, sys, bisect, heapq
from collections import defaultdict, Counter, deque
from itertools import groupby, accumulate
input = iter(sys.stdin.buffer.read().decode().splitlines()).__next__
ilele = lambda : map(int, input().split())
alele = lambda : list(map(int, input().split()))

def Y(c):
	print(['NO', 'YES'][c])

def y(c):
	print(['no', 'yes'][c])

def Yy(c):
	print(['No', 'Yes'][c])
N = int(input())
A = alele()
if N == 1:
	print(A[0])
else:
	odd = [0]
	even = [0]
	for i in range(N):
		if i % 2:
			odd.append(odd[-1] + A[i])
			even.append(even[-1])
		else:
			even.append(even[-1] + A[i])
			odd.append(odd[-1])
	maxi = 0
	for i in range(N):
		maxi = max(maxi, A[i] + max(odd[i] + even[-1] - even[i + 1], even[i] + odd[-1] - odd[i + 1]))
	print(maxi)


from bisect import *
from collections import *
from math import gcd, ceil, sqrt, floor, inf
from heapq import *
from itertools import *
from operator import add, mul, sub, xor, truediv, floordiv
from functools import *
import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')

def RL():
	return map(int, sys.stdin.readline().rstrip().split())

def RLL():
	return list(map(int, sys.stdin.readline().rstrip().split()))

def N():
	return int(input())
from types import GeneratorType

def bootstrap(f, stack=[]):

	def wrappedfunc(*args, **kwargs):
		if stack:
			return f(*args, **kwargs)
		else:
			to = f(*args, **kwargs)
			while True:
				if type(to) is GeneratorType:
					stack.append(to)
					to = next(to)
				else:
					stack.pop()
					if not stack:
						break
					to = stack[-1].send(to)
			return to
	return wrappedfunc
farr = [1]
ifa = []

def fact(x, mod=0):
	if mod:
		while x >= len(farr):
			farr.append(farr[-1] * len(farr) % mod)
	else:
		while x >= len(farr):
			farr.append(farr[-1] * len(farr))
	return farr[x]

def ifact(x, mod):
	global ifa
	ifa.append(pow(farr[-1], mod - 2, mod))
	for i in range(x, 0, -1):
		ifa.append(ifa[-1] * i % mod)
	ifa = ifa[::-1]

def per(i, j, mod=0):
	if i < j:
		return 0
	if not mod:
		return fact(i) // fact(i - j)
	return farr[i] * ifa[i - j] % mod

def com(i, j, mod=0):
	if i < j:
		return 0
	if not mod:
		return per(i, j) // fact(j)
	return per(i, j, mod) * ifa[j] % mod

def catalan(n):
	return com(2 * n, n) // (n + 1)

def linc(f, t, l, r):
	while l < r:
		mid = (l + r) // 2
		if t > f(mid):
			l = mid + 1
		else:
			r = mid
	return l

def rinc(f, t, l, r):
	while l < r:
		mid = (l + r + 1) // 2
		if t < f(mid):
			r = mid - 1
		else:
			l = mid
	return l

def ldec(f, t, l, r):
	while l < r:
		mid = (l + r) // 2
		if t < f(mid):
			l = mid + 1
		else:
			r = mid
	return l

def rdec(f, t, l, r):
	while l < r:
		mid = (l + r + 1) // 2
		if t > f(mid):
			r = mid - 1
		else:
			l = mid
	return l

def isprime(n):
	for i in range(2, int(n ** 0.5) + 1):
		if n % i == 0:
			return False
	return True

def binfun(x):
	c = 0
	for w in arr:
		c += ceil(w / x)
	return c

def lowbit(n):
	return n & -n

def inverse(a, m):
	a %= m
	if a <= 1:
		return a
	return (1 - inverse(m, a) * m) // a % m

class BIT:

	def __init__(self, arr):
		self.arr = arr
		self.n = len(arr) - 1

	def update(self, x, v):
		while x <= self.n:
			self.arr[x] += v
			x += x & -x

	def query(self, x):
		ans = 0
		while x:
			ans += self.arr[x]
			x &= x - 1
		return ans

class DSU:

	def __init__(self, n):
		self.c = [-1] * n

	def same(self, x, y):
		return self.find(x) == self.find(y)

	def find(self, x):
		if self.c[x] < 0:
			return x
		self.c[x] = self.find(self.c[x])
		return self.c[x]

	def union(self, u, v):
		(u, v) = (self.find(u), self.find(v))
		if u == v:
			return False
		if self.c[u] < self.c[v]:
			(u, v) = (v, u)
		self.c[u] += self.c[v]
		self.c[v] = u
		return True

	def size(self, x):
		return -self.c[self.find(x)]

class UFS:

	def __init__(self, n):
		self.parent = [i for i in range(n)]
		self.ranks = [0] * n

	def find(self, x):
		if x != self.parent[x]:
			self.parent[x] = self.find(self.parent[x])
		return self.parent[x]

	def union(self, u, v):
		(pu, pv) = (self.find(u), self.find(v))
		if pu == pv:
			return False
		if self.ranks[pu] >= self.ranks[pv]:
			self.parent[pv] = pu
			if self.ranks[pv] == self.ranks[pu]:
				self.ranks[pu] += 1
		else:
			self.parent[pu] = pv

def Prime(n):
	c = 0
	prime = []
	flag = [0] * (n + 1)
	for i in range(2, n + 1):
		if not flag[i]:
			prime.append(i)
			c += 1
		for j in range(c):
			if i * prime[j] > n:
				break
			flag[i * prime[j]] = prime[j]
			if i % prime[j] == 0:
				break
	return prime

def dij(s, graph):
	d = {}
	d[s] = 0
	heap = [(0, s)]
	seen = set()
	while heap:
		(dis, u) = heappop(heap)
		if u in seen:
			continue
		for v in graph[u]:
			if v not in d or d[v] > d[u] + graph[u][v]:
				d[v] = d[u] + graph[u][v]
				heappush(heap, (d[v], v))
	return d

def GP(it):
	return [(ch, len(list(g))) for (ch, g) in groupby(it)]

class DLN:

	def __init__(self, val):
		self.val = val
		self.pre = None
		self.next = None
t = 1
for i in range(t):
	n = N()
	a = RLL()
	pre = [0, a[0]]
	for i in range(1, n):
		pre.append(pre[i - 1] + a[i])
	ans = inf
	for i in range(n):
		if i < n - 3:
			tmp = pre[i + 1]
			if i & 1:
				tmp += pre[n] - pre[i + 2]
			else:
				tmp += pre[n - 1] - pre[i + 2]
		elif i < n - 1:
			tmp = pre[i + 1]
		else:
			tmp = pre[i + 1] - pre[i - n + 2]
		ans = min(ans, tmp)
	ans = sum(a) - ans
	print(ans)


import math

def answer(n, A):
	if n == 1:
		return A[0]
	dp = [0 for i in range(n)]
	dp[0] = A[0]
	dp[1] = A[1]
	for i in range(2, n):
		dp[i] = dp[i - 2] + A[i]
	maxi = 0
	for i in range(n):
		if i % 2 == 0:
			if i == 0:
				maxi = max(maxi, A[-1] + dp[-2])
			elif i == n - 1:
				maxi = max(maxi, dp[i] - A[i] + A[i - 1])
			else:
				k = A[i - 1] + dp[-2] - dp[i - 1] + dp[i] - A[i]
				maxi = max(maxi, k)
		else:
			k = A[i - 1] + dp[-1] - dp[i - 1] + dp[i] - A[i]
			maxi = max(maxi, k)
	return maxi
n = int(input())
arr = list(map(int, input().split()))
print(answer(n, arr))