qyliang/CodeNanoFix huggingface dataset:
# Buggy code:
#!/usr/bin/env python3

import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(2147483647)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9+7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

n = I()
a = LI()
if n == 3:
    print(max(a))
    quit()
dp1 = [-inf]*(n+1) 
dp2 = [-inf]*(n+1)
dp3 = [-inf]*(n+1)
dp1[0] = 0
dp2[0] = 0
dp3[0] = 0
dp1[1] = a[0]
dp2[2] = a[1]
for i in range(3,n+1):
    dp1[i] = dp1[i-2] + a[i-1]
    dp2[i] = max(dp2[i-2],dp1[i-3]) + a[i-1]
    dp3[i] = max(dp3[i-2],dp2[i-3],dp1[i-4]) + a[i-1]
if n % 2:
    print(max(dp1[n-2], dp2[n]))
else:
    print(max(dp1[n-1],dp2[n]))



# Fixed code:
#!/usr/bin/env python3

import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(2147483647)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9+7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

n = I()
a = LI()
if n == 3:
    print(max(a))
    quit()
dp1 = [-inf]*(n+1) 
dp2 = [-inf]*(n+1)
dp3 = [-inf]*(n+1)
dp1[0] = 0
dp2[0] = 0
dp3[0] = 0
dp1[1] = a[0]
dp2[2] = a[1]
for i in range(3,n+1):
    dp1[i] = dp1[i-2] + a[i-1]
    dp2[i] = max(dp2[i-2],dp1[i-3]) + a[i-1]
    dp3[i] = max(dp3[i-2],dp2[i-3],dp1[i-4]) + a[i-1]
if n % 2:
    print(max(dp1[n-2], dp2[n], dp3[n]))
else:
    print(max(dp1[n-1],dp2[n]))
# Buggy code:
N=int(input())
alist=list(map(int,input().split()))

if N%2==0:
  dp=[]
  for i in range(2):
    array=[0]*N
    dp.append(array)
    
  #init
  dp[0][0]=alist[0]
  dp[0][1]=alist[0]
  dp[1][1]=alist[1]
  for i in range(2,N):
    dp[0][i]=dp[0][i-2]+alist[i]
    dp[1][i]=max(dp[1][i-2]+alist[i],dp[0][i-3])
    
  print(max(dp[0][-1],dp[1][-1]))
else:
  dp=[]
  for i in range(3):
    array=[0]*N
    dp.append(array)

  #init
  dp[0][0]=alist[0]
  dp[0][1]=alist[0]
  dp[0][2]=alist[0]+alist[2]
  dp[1][1]=alist[1]
  dp[1][2]=alist[1]
  dp[2][2]=alist[2]
  for i in range(3,N):
    dp[0][i]=dp[0][i-2]+alist[i]
    dp[1][i]=max(dp[1][i-2]+alist[i],dp[0][i-3])
    dp[2][i]=max(dp[2][i-2]+alist[i],dp[1][i-3],dp[0][i-4])
    
  print(max(dp[0][-1],dp[1][-1],dp[2][-1]))

# Fixed code:
N=int(input())
alist=list(map(int,input().split()))

if N%2==0:
  dp=[]
  for i in range(2):
    array=[0]*N
    dp.append(array)
    
  #init
  dp[0][0]=alist[0]
  dp[1][1]=alist[1]
  for i in range(2,N):
    dp[0][i]=dp[0][i-2]+alist[i]
    dp[1][i]=max(dp[1][i-2]+alist[i],dp[0][i-3]+alist[i])
    
  print(max(dp[0][-2],dp[1][-1]))
else:
  dp=[]
  for i in range(3):
    array=[0]*N
    dp.append(array)

  #init
  dp[0][0]=alist[0]
  dp[0][2]=alist[0]+alist[2]
  dp[1][1]=alist[1]
  dp[2][2]=alist[2]
  for i in range(3,N):
    dp[0][i]=dp[0][i-2]+alist[i]
    dp[1][i]=max(dp[1][i-2]+alist[i],dp[0][i-3]+alist[i])
    dp[2][i]=max(dp[2][i-2]+alist[i],dp[1][i-3]+alist[i],dp[0][i-4]+alist[i])

  #dp[0][-1] is NG
  print(max(dp[0][-3],dp[1][-2],dp[2][-1]))
# Buggy code:
N = int(input())
A = list(map(int, input().split()))
INF = 10**18

dp0 = [-INF] * (N + 2)
dp1 = [-INF] * (N + 2)
dp2 = [-INF] * (N + 2)
dp0[0] = 0
dp0[1] = 0

for i, a in enumerate(A, start=2):
    dp0[i] = dp0[i - 2] + a
    dp1[i] = max(dp1[i - 2] + a, dp0[i - 1])
    dp2[i] = max(dp2[i - 2] + a, dp1[i - 1], dp0[i - 2])

if N % 2 == 1:
    print(dp2[-1])
else:
    print(max(dp1[-1], dp0[-2]))


# Fixed code:
N = int(input())
A = list(map(int, input().split()))
INF = 10**18

dp0 = [-INF] * (N + 2)
dp1 = [-INF] * (N + 2)
dp2 = [-INF] * (N + 2)
dp0[0] = 0
dp0[1] = 0
dp1[0] = 0
dp1[1] = 0

for i, a in enumerate(A, start=2):
    dp0[i] = dp0[i - 2] + a
    dp1[i] = max(dp1[i - 2] + a, dp0[i - 1])
    dp2[i] = max(dp2[i - 2] + a, dp1[i - 1], dp0[i - 2])

if N % 2 == 1:
    print(dp2[-1])
else:
    print(max(dp1[-1], dp0[-1]))
# Buggy code:


n = 0
a = []

def format_input(filename = None):
	global n
	global a
	if filename == None:
		n = int(input())
		a = list(map(int, input().split()))

	elif filename == '__random__':
		from random import randint as rng
		n = rng(2, 2 * 10**5)
		a = [rng(-1 * 10**9, 10**9) for i in range(n)]
		print(n)
		print(' '.join(list(map(str, a))))

def get_answer():
	odd = [0]
	even = [0]
	for i in range(n // 2):
		odd.append(odd[-1] + a[2*i])
		even.append(even[-1] + a[2*i+1])
	if n % 2 == 1:
		odd.append(odd[-1] + a[-1])

	print(odd)
	print(even)
	answer = -1 * 10**9 * n
	if n % 2 == 0:
		for i in range(n // 2 + 1):
			answer = max(answer, odd[i] - even[i] + even[-1])
	else:
		for i in range(n // 2 + 2):
			if i < n // 2 + 1:
				for j in range(i+1):
					answer = max(answer, odd[j] - even[j] + even[i] - odd[i+1] + odd[-1])
			else:
				for j in range(i):
					answer = max(answer, odd[j] - even[j] + even[-1])
	return answer

if __name__ == '__main__':
	format_input()

	ans = get_answer()
	print(ans)


# Fixed code:


n = 0
a = []

def format_input(filename = None):
	global n
	global a
	if filename == None:
		n = int(input())
		a = list(map(int, input().split()))

	elif filename == '__random__':
		from random import randint as rng
		n = rng(2, 2 * 10**5)
		a = [rng(-1 * 10**9, 10**9) for i in range(n)]
		print(n)
		print(' '.join(list(map(str, a))))

def get_answer():
	odd = [0]
	even = [0]
	for i in range(n // 2):
		odd.append(odd[-1] + a[2*i])
		even.append(even[-1] + a[2*i+1])
	if n % 2 == 1:
		odd.append(odd[-1] + a[-1])

	answer = -1 * 10**9 * n
	if n % 2 == 0:
		for i in range(n // 2 + 1):
			answer = max(answer, odd[i] - even[i] + even[-1])
	else:
		even_range = [even[0] - odd[1]]
		for i in range(n // 2):
			add = a[2*i+1] - a[2*i+2]
			min = - a[2*i] + add
			even_range.append(max(even_range[-1] + add, min))
		answer = odd[-1] + max(even_range)
	return answer

if __name__ == '__main__':
	format_input()

	ans = get_answer()
	print(ans)
# Buggy code:
import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7 # 998244353
input=lambda:sys.stdin.readline().rstrip()
def resolve():
    n = int(input())
    A = list(map(int,input().split()))

    if n & 1 == 0:
        res = -INF
        score = sum(A[::2])
        for i in range(n-1,-1,-1):
            if i & 1:
                score += A[i]
            else:
                score -= A[i]
                res = max(res, score)
        print(res)
        return

    front_dp = [None] * n
    choose = -INF
    not_choose = 0
    for i in range(1, n, 2):
        choose, not_choose = max(choose+A[i],not_choose+A[i]), not_choose + A[i-1]
        front_dp[i] = max(choose, not_choose)

    back_dp = [None] * n
    choose = -INF
    not_choose = 0
    for i in range(n-2, -1, -2):
        choose, not_choose = max(choose+A[i],not_choose+A[i]), not_choose + A[i+1]
        back_dp[i] = max(choose, not_choose)

    res = -INF
    for i in range(1, n, 2):
        if i + 2 < n:
            res = max(res, front_dp[i] + back_dp[i])

    res = max(res, front_dp[-2])
    res = max(res, back_dp[1])
    print(res)
resolve()

# Fixed code:
import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7 # 998244353
input=lambda:sys.stdin.readline().rstrip()
def resolve():
    n = int(input())
    A = list(map(int,input().split()))

    if n & 1 == 0:
        res = -INF
        score = sum(A[::2])
        res = max(res, score)
        for i in range(n-1,-1,-1):
            if i & 1:
                score += A[i]
            else:
                score -= A[i]
                res = max(res, score)
        print(res)
        return

    front_dp = [None] * n
    choose = -INF
    not_choose = 0
    for i in range(1, n, 2):
        choose, not_choose = max(choose, not_choose) + A[i], not_choose + A[i-1]
        front_dp[i] = max(choose, not_choose)

    back_dp = [None] * n
    choose = -INF
    not_choose = 0
    for i in range(n-2, -1, -2):
        choose, not_choose = max(choose, not_choose) + A[i], not_choose + A[i+1]
        back_dp[i] = max(choose, not_choose)

    res = -INF
    for i in range(1, n, 2):
        if i + 2 < n:
            res = max(res, front_dp[i] + back_dp[i+2])

    res = max(res, front_dp[-2])
    res = max(res, back_dp[1])

    print(res)
resolve()
# Buggy code:
n = int(input())
a = [int(i) for i in input().split()]

    
b = a[:4]
e = [True]*4

for i in range(1, n // 2):
    c = [0] * 4
    f = [False]*4
    d = -10**24
    for j in range(4):
        if 2 * i + j >= n:
            continue
        if not e[j]:
            continue
        d = max(d, b[j])
        c[j] = d + a[2 * i + j]
        f[j] = True
    e = f.copy()
    b = c.copy()
ans = -10 ** 24
for i in range(4):
    if e[i]:
        ans = max(ans, b[i])
print(e)
print(ans)

# Fixed code:
n = int(input())
a = [int(i) for i in input().split()]

if n // 2 == 1:
    print(max(a))
    exit()
if n < 20:
    d = a.copy()
    
    for i in range(1, n // 2):
        b = [0] * n
        c = -10 ** 24
        ans = -10 ** 24
        for j in range(i * 2, n):
            c = max(c, a[j - 2])
            b[j] = c + d[j]
            ans = max(ans, c + d[j])

        a = b.copy()
    print(ans)
    exit()

b = a[:10]
e = [True]*10

for i in range(1, n // 2):
    c = [0] * 10
    f = [False]*10
    d = -10**24
    for j in range(10):
        if 2 * i + j >= n:
            continue
        if not e[j]:
            continue
        d = max(d, b[j])
        c[j] = d + a[2 * i + j]
        f[j] = True
    e = f.copy()
    b = c.copy()
ans = -10 ** 24
for i in range(10):
    if e[i]:
        ans = max(ans, b[i])
print(ans)
# Buggy code:
n = int(input())
nums = list(map(int,input().split()))
dp = [[0,0,0] for _ in range(n)]
dp[0][0] = nums[0]
dp[1][0],dp[1][1],dp[1][2] = nums[1],nums[0],-float("inf")
dp[2][0],dp[2][1],dp[2][2] = nums[2],nums[1],nums[0]
for i in range(3,n):
    if i%2 == 0:
        dp[i][0] = max(dp[i-2]) + nums[i]
        dp[i][1] = max(dp[i-3]) + nums[i-1]
        dp[i][2] = sum(nums[0:i-1:2])
    else:
        dp[i][0] = max(dp[i-2]) + nums[i]
        dp[i][1] = sum(nums[0:i-2:2]) + nums[i-1]
        dp[i][2] = -float("inf")
print(max(dp[n-1]))
print(dp)

# Fixed code:
n = int(input())
nums = list(map(int,input().split()))
if n == 2:
    print(max(nums[0],nums[1]))
else:
    temp =[0]
    for i in range(n):
        if i%2 == 0:
            temp += [temp[-1]+nums[i]]
    dp = [[0,0,0] for _ in range(n)]
    dp[0][0] = nums[0]
    dp[1][0],dp[1][1],dp[1][2] = nums[1],nums[0],-float("inf")
    dp[2][0],dp[2][1],dp[2][2] = nums[2],nums[1],nums[0]
    for i in range(3,n):
        if i%2 == 0:
            dp[i][0] = max(dp[i-2]) + nums[i]
            dp[i][1] = max(dp[i-3]) + nums[i-1]
            dp[i][2] = temp[i//2]
        else:
            dp[i][0] = max(dp[i-2]) + nums[i]
            dp[i][1] = temp[(i-1)//2] + nums[i-1]
            dp[i][2] = -float("inf")
    print(max(dp[n-1]))
# Buggy code:
def main():
    N=int(input())
    A=[int(_) for _ in input().split()]
    dp=[[0,0,0] for _ in range(N//2+1)]
    for i in range(N//2):
        dp[i+1][0]=dp[i][0]+A[i*2]
        dp[i+1][1]=max(dp[i][1],dp[i][0])+A[i*2+1]
        if N%2:
            dp[i+1][2]=max(dp[i][2],dp[i][1],dp[i][0])+A[i*2+2]
    for d in dp:
        print(d)
    if N%2:
        print(max(dp[-1]))
    else:
        print(max(dp[-1][:2]))

main()


# Fixed code:
def main():
    N=int(input())
    A=[int(_) for _ in input().split()]
    dp=[[0,0,0] for _ in range(N//2+1)]
    for i in range(N//2):
        dp[i+1][0]=dp[i][0]+A[i*2]
        dp[i+1][1]=max(dp[i][1],dp[i][0])+A[i*2+1]
        if N%2:
            dp[i+1][2]=max(dp[i][2],dp[i][1],dp[i][0])+A[i*2+2]
    if N%2:
        print(max(dp[-1]))
    else:
        print(max(dp[-1][:2]))

main()
# Buggy code:
n=int(input());l=list(map(int,input().split()));p=[0]*n;d=[0]*n
for i in range(n):p[i]=l[i]+p[i-2];d[i]=max(p[i-1]*(i&1)+d[i-1]*(i&1),l[i]+d[i-2])
print(d[-1])

# Fixed code:
n=int(input());l=list(map(int,input().split()));p=[0]*n;d=[0]*n
for i in range(n):p[i]=l[i]+p[i-2];d[i]=max(p[i-1]if i&1else d[i-1],l[i]+d[i-2])
print(d[-1])
# Buggy code:
n,*l=open(0);n=int(n);l=list(map(int,l.split()))
p=[0]*n;d=[0]*n
for i in range(n):p[i]=l[i]+p[i-2];d[i]=max(p[i-1]if(i&1)else d[i-1],l[i]+d[i-2])
print(d[-1])

# Fixed code:
n=int(input());l=list(map(int,input().split()));p=[0]*n;d=[0]*n;p[0]=l[0]
for i in range(1,n):p[i]=l[i]+p[i-2];d[i]=max(p[i-1]if(i&1)else d[i-1],l[i]+d[i-2])
print(d[-1])
# Buggy code:
N = int(input())
A = list(map(int,input().split()))
dp = [{} for _ in range(N+1)]
INF = -float('inf')
for i in range(1,N+1):
    mid = i//2
    dp[i][mid-2],dp[i][mid-1],dp[i][mid],dp[i][mid+1],dp[i][mid+2]=INF,INF,INF,INF,INF
dp[1][1] = A[0]
dp[2][1] = max(A[1],dp[1][1])

for i in range(2,N):
  a = A[i]
  ma = (i+2)//2
  mi = i//2
  dp[i+1][ma] = max(dp[i][ma],dp[i-1][ma-1]+a)
  dp[i+1][mi] = max(dp[i][mi],dp[i-1][mi-1]+a)

print(dp[-1][N//2])

# Fixed code:
N = int(input())
A = list(map(int,input().split()))
dp = [{} for _ in range(N+1)]
INF = -float('inf')
for i in range(1,N+1):
    mid = i//2
    dp[i][mid-2],dp[i][mid-1],dp[i][mid],dp[i][mid+1],dp[i][mid+2]=INF,INF,INF,INF,INF
dp[1][1] = A[0]
dp[2][1] = max(A[1],dp[1][1])
dp[1][0],dp[2][0]=0,0

for i in range(2,N):
  a = A[i]
  ma = (i+2)//2
  mi = i//2
  dp[i+1][ma] = max(dp[i][ma],dp[i-1][ma-1]+a)
  dp[i+1][mi] = max(dp[i][mi],dp[i-1][mi-1]+a)

print(dp[-1][N//2])
# Buggy code:
from heapq import heappush, heappop, heapify
from collections import deque, defaultdict, Counter
import itertools
from itertools import permutations, combinations, accumulate
import sys
import bisect
import string
import math
import time


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


def S(): return input()


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


def MS(): return map(str, input().split())


def LI(): return [int(i) for i in input().split()]


def LI_(): return [int(i)-1 for i in input().split()]


def StoI(): return [ord(i)-97 for i in input()]


def ItoS(nn): return chr(nn+97)


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


yn = {False: 'No', True: 'Yes'}
YN = {False: 'NO', True: 'YES'}
MOD = 10**9+7
inf = float('inf')
IINF = 10**10
l_alp = string.ascii_lowercase
u_alp = string.ascii_uppercase
ts = time.time()
sys.setrecursionlimit(10**6)
nums = ['1', '2', '3', '4', '5', '6', '7', '8', '9', '10']

show_flg = False
# show_flg = True


def main():
    N = I()
    a = LI()
    dp[1] = max(a[0],a[1])
    c = a[0]

    for i in range(2, n):
        if i % 2 == 0:
            c += a[i]
            dp[i] = max(dp[i-2] + a[i], dp[i-1])
        else:
            dp[i] = max(dp[i-2] + a[i], c)

    print(dp[-1])


if __name__ == '__main__':
    main()


# Fixed code:
from heapq import heappush, heappop, heapify
from collections import deque, defaultdict, Counter
import itertools
from itertools import permutations, combinations, accumulate
import sys
import bisect
import string
import math
import time


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


def S(): return input()


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


def MS(): return map(str, input().split())


def LI(): return [int(i) for i in input().split()]


def LI_(): return [int(i)-1 for i in input().split()]


def StoI(): return [ord(i)-97 for i in input()]


def ItoS(nn): return chr(nn+97)


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


yn = {False: 'No', True: 'Yes'}
YN = {False: 'NO', True: 'YES'}
MOD = 10**9+7
inf = float('inf')
IINF = 10**10
l_alp = string.ascii_lowercase
u_alp = string.ascii_uppercase
ts = time.time()
sys.setrecursionlimit(10**6)
nums = ['1', '2', '3', '4', '5', '6', '7', '8', '9', '10']

show_flg = False
# show_flg = True


def main():
    N = I()
    a = LI()
    dp = [0] * N
    dp[1] = max(a[0], a[1])
    c = a[0]

    for i in range(2, N):
        if i % 2 == 0:
            c += a[i]
            dp[i] = max(dp[i-2] + a[i], dp[i-1])
        else:
            dp[i] = max(dp[i-2] + a[i], c)

    print(dp[-1])


if __name__ == '__main__':
    main()
# Buggy code:
n = int(input())
a = list(map(int, input().split()))

le, lo, re, ro = [0], [0], [0], [0]

for i in range(n):
    if i % 2 == 0:
        le.append(le[-1] + a[i])
    else:
        lo.append(lo[-1] + a[i])

for i in range(n-1, -1, -1):
    if i % 2 == 0:
        re.append(re[-1] + a[i])
    else:
        ro.append(ro[-1] + a[i])

le_o = [0]
for i in range(len(lo)-1):
    le_o.append(max(0, le_o[-1] + a[2*i+1] - a[2*i]))

print(le)
print(lo)
print(re)
print(ro)
print(le_o)

if n % 2 == 0:
    n //= 2
    ans = 0
    for i in range(0, n + 1):
        ans = max(ans, le[i] + ro[n-i])

    print(ans)

else:
    n //= 2
    ans = 0
    for i in range(0, n+1):
        ans = max(ans, le[i] + ro[n-i])
        ans = max(ans, lo[i] + re[n-i])
        ans = max(ans, le[i] + re[n-i])
        if i != 0:
            ans = max(ans, le[i] + re[n-i] + le_o[i])

    print(ans)

# Fixed code:
n = int(input())
a = list(map(int, input().split()))

le, lo, re, ro = [0], [0], [0], [0]

for i in range(n):
    if i % 2 == 0:
        le.append(le[-1] + a[i])
    else:
        lo.append(lo[-1] + a[i])

for i in range(n-1, -1, -1):
    if i % 2 == 0:
        re.append(re[-1] + a[i])
    else:
        ro.append(ro[-1] + a[i])

le_o = [0]
for i in range(len(lo)-1):
    le_o.append(max(0, le_o[-1] + a[2*i+1] - a[2*i]))


if n % 2 == 0:
    n //= 2
    ans = lo[n]
    for i in range(0, n + 1):
        ans = max(ans, le[i] + ro[n-i])

    print(ans)

else:
    n //= 2
    ans = le[n]
    for i in range(0, n+1):
        ans = max(ans, le[i] + ro[n-i])
        ans = max(ans, lo[i] + re[n-i])
        ans = max(ans, le[i] + re[n-i] + le_o[i])

    print(ans)
# Buggy code:
from math import gcd
from functools import reduce
 
n=int(input())
ar=list(map(int,input().split(' ')))
 
if n%2==0:
	print(max(sum(ar[i] for i in range(0,n,2)),sum(ar[i] for i in range(1,n,2))))
	exit()
	
dp=[[-(10**20)]*5 for i in range(n+5)]
 
 
#1> 2 3> 4  6> 7 8> 9 10 11> 12> 14
def cn(z,j):
	return (z-j+1)//2
ans=-(10**20)
for i in range(n):
	idx=int(i)
	if idx<2:
		dp[idx][0]=0
	if idx-2>=0:
		dp[idx]=dp[idx-2].copy()
	for j in range(1,4):
			for k in range(j+1):
				if idx-k-1>=0:
					dp[idx][j]=max(dp[idx][j],dp[idx-k-2][j-k])
	for j in range(4):
		dp[i][j]+=ar[i]
		if cn(i+1,j)==n//2:
			ans=max(ans,dp[i][j])
print(ans)


# Fixed code:
from math import gcd
from functools import reduce
 
n=int(input())
ar=list(map(int,input().split(' ')))
 
dp=[[-(10**20)]*6 for i in range(n+5)]+[[0]+[-(10**20)]*8 for i in range(3)]
 
 
#1> 2 3> 4  6> 7 8> 9 10 11> 12> 14
def cn(z,j):
	return (z-j+1)//2
ans=-(10**20)
for i in range(n):
	idx=int(i)
	dp[idx]=dp[idx-2].copy()
	for j in range(0,5):
			for k in range(j+1):
					dp[idx][j]=max(dp[idx][j],dp[idx-k-2][j-k])
	for j in range(5):
		dp[i][j]+=ar[i]
		if cn(i+1,j)==n//2:
			ans=max(ans,dp[i][j])
print(ans)
# Buggy code:
n = int(input())
a = list(map(int, input().split()))

dp = [[0]*n for i in range(2)]

dp[1][0] = a[0]
dp[1][1] = max(a[0], a[1])

for i in range(2,n):
    dp[0][i] = max(dp[1][i-2], dp[1][i-1], dp[0][i-2] + a[i])
    
    if i % 2 == 0:
        dp[1][i] = dp[1][i-2] + a[i]
    else:
        dp[1][i] = max(dp[1][i-1], dp[1][i-2] + a[i])
print(dp[0][n-1])

# Fixed code:
n = int(input())
a = list(map(int, input().split()))

if n % 2 == 0:
  dp = a[:2]
  for i in range(1, n // 2):
    dp = dp[0] + a[2*i], max(dp) + a[2*i+1]
else:
  dp = a[:3]
  for i in range(1, n // 2):
    dp = dp[0] + a[2*i], max(dp[:2]) + a[2*i+1], max(dp) + a[2*i+2]

print(max(dp))
# Buggy code:
N = int(input())
*A, = map(int,input().split())

if N%2==0:
    1/0
    ans = max(sum(A[::2]),sum(A[1::2]))
    print(ans)
else:
    INF = 2* 10**9
    dp = [[-INF]*N for _ in [0]*3]
    dp[0][0] = A[0]
    dp[1][1] = A[1]
    dp[2][2] = A[2]
    for i in range(2,N,2):
        a = A[i]
        dp[0][i] = dp[0][i-2] + a
    for i in range(3,N):
        a = A[i]
        dp[1][i] = max(dp[1][i-2],dp[0][i-3]) + a
    for i in range(4,N,2):
        a = A[i]
        dp[2][i] = max(dp[2][i-2],dp[1][i-3],dp[0][i-4]) + a
    print(dp[2][-1])

# Fixed code:
N = int(input())
*A, = map(int,input().split())

if N%2==0:
    INF = 2* 10**9
    dp = [[-INF]*N for _ in [0]*2]
    dp[0][0] = A[0]
    dp[1][1] = A[1]
    for i in range(2,N,2):
        a = A[i]
        dp[0][i] = dp[0][i-2] + a
    for i in range(3,N):
        a = A[i]
        dp[1][i] = max(dp[1][i-2],dp[0][i-3]) + a
    print(max(dp[1][-1],dp[0][-2]))
else:
    INF = 2* 10**9
    dp = [[-INF]*N for _ in [0]*3]
    dp[0][0] = A[0]
    dp[1][1] = A[1]
    dp[2][2] = A[2]
    for i in range(2,N,2):
        a = A[i]
        dp[0][i] = dp[0][i-2] + a
    for i in range(3,N):
        a = A[i]
        dp[1][i] = max(dp[1][i-2],dp[0][i-3]) + a
    for i in range(4,N,2):
        a = A[i]
        dp[2][i] = max(dp[2][i-2],dp[1][i-3],dp[0][i-4]) + a
    print(max(dp[2][-1],dp[1][-2],dp[0][-3]))
# Buggy code:
def main():
    n = int(input())
    a = list(map(int, input().split()))
    dp = [[-10**15]*(3) for i in range(n+1)]
    dp[2][0] = a[0]
    dp[2][1] = a[1]
    dp[2][2] = max(a[0], a[1])
    dp[3][0] = max(a[0]+a[1], a[0]+a[2], a[1]+a[2])
    for i in range(4, n+1):
        if i%2:
            dp[i][0] = max(dp[i-1][2], dp[i-2][0]+a[i-1])
        else:
            dp[i][0] = dp[i-2][0]+a[i-2]
            dp[i][1] = dp[i-2][1]+a[i-1]
            dp[i][2] = max(dp[i][0], dp[i][1])
    if n%2:
        print(dp[n][0])
    else:
        print(dp[n][2])

if __name__ == "__main__":
    main()

# Fixed code:
def main():
    n = int(input())
    a = list(map(int, input().split()))
    dp = [-10**15]*(n+1)
    dp[2] = max(a[0], a[1])
    if n > 2:
        dp[3] = max(a[:3])
        aa = a[0]+a[2]
        for i in range(4, n+1):
            if i%2:
                aa += a[i-1]
                dp[i] = max(dp[i-1], dp[i-2]+a[i-1])
            else:
                dp[i] = max(aa, dp[i-2]+a[i-1])
    print(dp[n])

if __name__ == "__main__":
    main()
# Buggy code:
def main():
    N = int(input())
    A = list(map(int, input().split()))
    a0, a1, a2, b0, b1, b2 = 0, 0, 0, 0, 0, 0
    for i, a in enumerate(A):
        a0, a1, a2, b0, b1, b2 = (
                b0,
                max(b1, a0),
                max(b2, a1),
                a0 + a,
                a1 + a if i >= 1 else a1,
                a2 + a if i >= 2 else a2)
        print(a0, a1, a2, b0, b1, b2)

    if N & 1:
        return max(a2, b1)
    else:
        return max(a1, b0)


print(main())


# Fixed code:
def main():
    N = int(input())
    A = list(map(int, input().split()))
    a0, a1, a2, b0, b1, b2 = 0, 0, 0, 0, 0, 0
    for i, a in enumerate(A):
        a0, a1, a2, b0, b1, b2 = (
                b0,
                max(b1, a0),
                max(b2, a1),
                a0 + a,
                a1 + a if i >= 1 else a1,
                a2 + a if i >= 2 else a2)

    if N & 1:
        return max(b2, a1)
    else:
        return max(b1, a0)


print(main())
# Buggy code:
N=int(input())
A=[0]+list(map(int,input().split()))

dp=[[0]*(N+1) for i in range(3)]

dp[0][1]=-float("inf")
dp[2][1]=A[0]
dp[0][2]=0
dp[1][2]=max(A[0],A[1])
dp[2][2]=-float("inf")

for i in range(3,N+1):
    if i%2==1:
        for j in range(3):
            dp[j][i]=max(dp[j][i-2]+A[i],dp[j][i-1])
    else:
        for j in range(2):
            dp[j][i]=max(dp[j][i-2]+A[i],dp[j+1][i-1])
        dp[2][i]=dp[2][i-2]+A[i]

print(dp[1][N])

# Fixed code:
N=int(input())
A=[0]+list(map(int,input().split()))

dp=[[0]*(N+1) for i in range(3)]

dp[0][1]=-float("inf")
dp[2][1]=A[1]
dp[0][2]=0
dp[1][2]=max(A[1],A[2])
dp[2][2]=-float("inf")

for i in range(3,N+1):
    if i%2==1:
        for j in range(3):
            dp[j][i]=max(dp[j][i-2]+A[i],dp[j][i-1])
    else:
        for j in range(2):
            dp[j][i]=max(dp[j][i-2]+A[i],dp[j+1][i-1])
        dp[2][i]=dp[2][i-2]+A[i]

print(dp[1][N])