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(eval(input()))





def S(): return eval(input())





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





def MS(): return list(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 eval(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()

n = int(eval(input()))

A = list(map(int, input().split()))

INF = 10**18

dp_use = [-INF] * 5

dp_not_use = [-INF] * 5

dp_not_use[0] = 0

 

for a in A:

    tmp_use = [-INF] * 5

    tmp_not_use = [-INF] * 5

    for current_dif in range(-3,2):

        if current_dif-1 >= -3:

            tmp_use[current_dif] = dp_not_use[current_dif - 1] + a

        if current_dif+1 < 2:

            tmp_not_use[current_dif] = max(dp_use[current_dif+1], dp_not_use[current_dif+1])

    dp_use = tmp_use

    dp_not_use = tmp_not_use

dif = n//2 - (n-n//2)

print((max(dp_use[dif], dp_not_use[dif])))
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(eval(input()))


def S():
    return eval(input())


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


def MS():
    return list(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 eval(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()

n = int(eval(input()))
A = list(map(int, input().split()))
INF = 10**18
dp_use = [-INF] * 5
dp_not_use = [-INF] * 5
dp_not_use[0] = 0
for a in A:
    tmp_use = [-INF] * 5
    tmp_not_use = [-INF] * 5
    for current_dif in range(-3, 2):
        if current_dif - 1 >= -3:
            tmp_use[current_dif] = dp_not_use[current_dif - 1] + a
        if current_dif + 1 < 2:
            tmp_not_use[current_dif] = max(
                dp_use[current_dif + 1], dp_not_use[current_dif + 1]
            )
    dp_use = tmp_use
    dp_not_use = tmp_not_use
dif = n // 2 - (n - n // 2)
print((max(dp_use[dif], dp_not_use[dif])))

-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(eval(input())) - - -def S(): -    return eval(input()) - - -def MI(): -    return list(map(int, input().split())) - - -def MS(): -    return list(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 eval(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() +n = int(eval(input())) +A = list(map(int, input().split())) +INF = 10**18 +dp_use = [-INF] * 5 +dp_not_use = [-INF] * 5 +dp_not_use[0] = 0 +for a in A: +    tmp_use = [-INF] * 5 +    tmp_not_use = [-INF] * 5 +    for current_dif in range(-3, 2): +        if current_dif - 1 >= -3: +            tmp_use[current_dif] = dp_not_use[current_dif - 1] + a +        if current_dif + 1 < 2: +            tmp_not_use[current_dif] = max( +                dp_use[current_dif + 1], dp_not_use[current_dif + 1] +            ) +    dp_use = tmp_use +    dp_not_use = tmp_not_use +dif = n // 2 - (n - n // 2) +print((max(dp_use[dif], dp_not_use[dif])))