CodeEff/ECCO huggingface dataset:
# Original solution
s=input()[::-1]
words=["dreamer","eraser","dream","erase"]
add=0
while add!=len(s):
    cnt=0
    for i in words:
        length=len(i)
        word=s[add:add+length][::-1]
        if word==i:
            add +=length
            break
        else:cnt +=1
    if cnt==4:print("NO");exit()
print("YES")

# Optimized solution
s=input()[::-1]
T=["dream","dreamer","erase","eraser"]
l,n=0,len(s)

while l!=n:
    flag=0
    for i in T:
        word=i[::-1]
        if s[l:l+len(word)]==word:
            l +=len(word)
            flag=1
            break
    if flag==0:print("NO");exit()
print("YES")
# Original solution
s=input()[::-1]
T=["dream","dreamer","erase","eraser"]
l,n=0,len(s)

while l!=n:
    flag=0
    for i in T:
        word=i[::-1]
        if s[l:l+len(word)]==word:
            l +=len(word)
            flag=1
            break
    if flag==0:print("NO");exit()
print("YES")

# Optimized solution
s=input()[::-1]
T=["dream","dreamer","erase","eraser"]
l,n=0,len(s)

while l!=n:
    flag=0
    for i in T:
        word=i[::-1]
        if s[l:l+len(word)]==word:
            l +=len(word)
            flag=1
    if flag==0:print("NO");exit()
print("YES")
# Original solution
def c_daydream(S):
    import re
    # Sを逆にしたものから該当する文字を除いていき、空文字列にできるか？
    s = S[::-1]
    dict = ['dream'[::-1], 'dreamer'[::-1], 'erase'[::-1], 'eraser'[::-1]]
    n = len(s)
    while n > 0:
        for d in dict:
            if s.startswith(d):
                s = re.sub('^' + d, '', s)
                break
        else:
            return 'NO'
        n = len(s)
    return 'YES'

S = input().strip()
print((c_daydream(S)))

# Optimized solution
def c_daydream(S):
    # Sを逆にしたものから文字列を除いていき、空文字にできるか？
    s = S[::-1]
    n = len(s)
    while True:
        if n == 0:
            return 'YES'
        elif n >= 5 and s[:5] == 'maerd':
            s = s[5:]
        elif n >= 7 and s[:7] == 'remaerd':
            s = s[7:]
        elif n >= 5 and s[:5] == 'esare':
            s = s[5:]
        elif n >= 6 and s[:6] == 'resare':
            s = s[6:]
        else:
            return 'NO'
        n = len(s)
    return None

S = input().strip()
print((c_daydream(S)))
# Original solution
s=input().replace("eraser","").replace("erase","").replace("dreamer","").replace("dream","")
if s:
    print("NO")
else:
    print("YES")

# Optimized solution
s = input().replace("eraser", "") .replace("erase", "").replace("dreamer", "").replace("dream", "")
print(("NO" if s else "YES"))
# Original solution
import bisect
import copy
import heapq
import sys
import itertools
import math
import queue
input = sys.stdin.readline
sys.setrecursionlimit(100000)
mod = 10 ** 9 + 7

def read_values(): return list(map(int, input().split()))
def read_index(): return [int(x) - 1 for x in input().split()]
def read_list(): return list(read_values())
def read_lists(N): return [read_list() for n in range(N)]


class V:
    def __init__(self, f, v=None):
        self.f = f
        self.v = v
 
    def __str__(self):
        return str(self.v)
 
    def ud(self, n):
        if n is None:
            return

        if self.v is None:
            self.v = n
            return
        self.v = self.f(self.v, n) 


def main():
    N = int(eval(input()))
    A = read_list()
    dp = [[[-10 ** 20 for _ in range(2)] for _ in range(N // 2 + 5)] for _ in range(N + 1)]

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

    print((max(dp[N][N // 2])))


if __name__ == "__main__":
    main()


# Optimized solution
import bisect
import copy
import heapq
import sys
import itertools
import math
import queue
input = sys.stdin.readline
sys.setrecursionlimit(100000)
mod = 10 ** 9 + 7

def read_values(): return list(map(int, input().split()))
def read_index(): return [int(x) - 1 for x in input().split()]
def read_list(): return list(read_values())
def read_lists(N): return [read_list() for n in range(N)]


class V:
    def __init__(self, f, v=None):
        self.f = f
        self.v = v
 
    def __str__(self):
        return str(self.v)
 
    def ud(self, n):
        if n is None:
            return

        if self.v is None:
            self.v = n
            return
        self.v = self.f(self.v, n) 


def main():
    N = int(eval(input()))
    A = read_list()
    dp = [[-10 ** 20 for _ in range(2)] for _ in range(N // 2 + 5)] 

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

    print((max(dp[N // 2])))


if __name__ == "__main__":
    main()
# Original solution
import sys

sys.setrecursionlimit(2*1000000)

N = int(eval(input()))
A = list(map(int, input().split(" ")))

dp_dict = {}

inf = -1*1000000000


def dp(i, j):
    if j == 1:
        return A[i]
    if i+2 >= N:
        return inf
    if N//2-j < i//2-1:
        return inf
    temp = max([dp(i+2, j-1)+A[i], dp(i+1, j)])
    dp_dict[(i, j)] = temp
    return temp


select = N//2
if select == 1:
    print((max(A)))
else:
    print((dp(0, select)))

# Optimized solution
N = int(eval(input()))
A = [0]+list(map(int, input().split(" ")))

dp_list = [{0, 0}, {0: 0, 1: A[1]}, {0: 0, 1: A[1] if A[1] > A[2] else A[2]}]

for i in range(3, N+1):
    b = (i-1)//2
    f = (i+1)//2
    dp_list.append({})
    for j in range(b, f+1):
        if j in dp_list[i-1]:
            dp_list[i][j] = dp_list[i-2][j-1]+A[i] if dp_list[i -
                                                              2][j-1]+A[i] > dp_list[i-1][j] else dp_list[i-1][j]
        else:
            dp_list[i][j] = dp_list[i-2][j-1]+A[i]

print((dp_list[-1][N//2]))
# Original solution
from collections import defaultdict
N = int(eval(input()))
A = list(map(int, input().split()))

# dp[(i, x, flg)] := i番目までみてx個選んでいる時の最大値。flgは最後の１つをとったかどうか。
dp = defaultdict(lambda: -float('inf'))
dp[(0, 0, 0)] = 0

for i, a in enumerate(A, start=1):
    j = i // 2
    for x in range(j - 1, j + 2):
        dp[(i, x, 0)] = max(dp[(i - 1, x, 0)], dp[(i - 1, x, 1)])
        dp[(i, x, 1)] = dp[(i - 1, x - 1, 0)] + a

print((max(dp[(N, N // 2, 0)], dp[(N, N // 2, 1)])))


# Optimized solution
from collections import defaultdict
N = int(eval(input()))
A = list(map(int, input().split()))

# dp[(i, x, flg)] := i番目までみてx個選んでいる時の最大値。flgは最後の１つをとったかどうか。
dp = defaultdict(lambda: -float('inf'))
dp[(0, 0, 0)] = 0

for i, a in enumerate(A, start=1):
    for x in range((i - 1) // 2, (i + 1) // 2 + 1):
        dp[(i, x, 0)] = max(dp[(i - 1, x, 0)], dp[(i - 1, x, 1)])
        dp[(i, x, 1)] = dp[(i - 1, x - 1, 0)] + a

print((max(dp[(N, N // 2, 0)], dp[(N, N // 2, 1)])))
# Original solution
import pprint
n = int(eval(input()))
ls = input().split()
lst = [int(e) for e in ls]
#print(lst)
m = n //2
d = n % 2
#print(m,d)

def ns ( l1, l2 ):
  res = 0
  for i in range(len(l1)):
    res += l1[i]*l2[i]
  return res

def mklst(no):
  ret = []
  if no % 2 == 0:
    m = no // 2
    for i in range(m+1):
      wk = [0]*no
      for j in range(m):
        if j < i :
          wk[j*2] = 1
        else:
          wk[j*2+1] = 1
      ret.append(wk)
  else:
    #wk = [0]*no
    if no == 1:
      ret.append([0])
      return ret
    if no == 3:
      ret.append([1,0,0])
      ret.append([0,1,0])
      ret.append([0,0,1])
      return ret

    for elst in mklst(no-1):
      ret.append([0]+elst)

    if no >= 5:
      for elst in mklst(no-3):
        ret.append([1,0]+elst+[0])

    if no >= 5:
      for elst in mklst(no-4):
        ret.append([1,0]+elst+[0,1])
      
  return ret    

mmm = lst[0]
for el in mklst(n):
  ans = ns(lst,el)
  if mmm < ans :
    mmm = ans

print(mmm)


# Optimized solution
import pprint
n = int(eval(input()))
ls = input().split()
lst = [int(e) for e in ls]
m = n //2
d = n % 2

def sum_lst(plst):
  no = len(plst)
  ret = []
  if no % 2 == 0:
    m = no // 2
    for i in range(m+1):
      sum = 0
      for j in range(m):
        if j < i :
          sum += plst[j*2]
        else:
          sum += plst[j*2+1]
      ret.append(sum)
  else:
    if no == 1:
      return [plst[0]]
    if no == 3:
      return [max(plst)]

    for elst in sum_lst(plst[1:no]):
      ret.append(elst)

    if no >= 5:
      for elst in sum_lst(plst[2:no-1]):
        ret.append(plst[0]+elst)

    if no >= 5:
      for elst in sum_lst(plst[2:no-2]):
        ret.append(plst[0]+elst+plst[no-1])
  return [max(ret)]    

mmm = sum_lst(lst)
print((mmm[0]))
# Original solution
# coding: utf-8

N=int(eval(input()))
A=list(map(int,input().split()))
INF=10**18

dp=[[-INF for i in range(N+1)] for i in range(N+1)]
dp[0][0]=0
dp[1][0]=0
dp[2][0]=0
dp[1][1]=A[0]
dp[2][1]=A[1]

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


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



# Optimized solution
# coding: utf-8

N=int(eval(input()))
A=list(map(int,input().split()))
INF=10**18

dp=[[-INF for i in range(2)] for j in range(N+1)]
dp[0][0]=0
dp[1][0]=0
dp[2][0]=0
dp[1][1]=A[0]
dp[2][1]=A[1]

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

if N%2==0:
    print((max(dp[N][1],dp[N-1][1])))
else:
    print((max(dp[N][0],dp[N-1][1],dp[N-2][1])))
# Original solution
import sys
sys.setrecursionlimit(10**6)

N = int(eval(input()))
A = [int(i) for i in input().split()]

def f(i,j):
  a = 0
  if not 2*j-1 <= i <= 2*j+1+(N-2*int(N/2)):
    a = 0
  elif i == 1 and j == 0:
    a = 0
  elif i == 1 and j == 1:
    a = A[0]
  elif i == 2 and j == 1:
    a = max(A[0],A[1])
  elif i == 2 and j == 0:
    a = 0
  else:
    a = max(f(i-2,j-1)+A[i-1],f(i-1,j))
  return a

print((f(N,int(N/2))))

# Optimized solution
import math

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

B = [{} for _ in range(N+1)]


for i in range(1,N+1):
  if i == 1:
    B[1][0] = 0
    B[1][1] = A[0]
  elif i == 2:
    B[2][1] = max(A[0],A[1])
    if N % 2 == 1:
      B[2][0] = 0
  else:
    if N % 2 == 0:
      for j in range(math.ceil((i-1)/2),(i+1)//2+1):
        m1 = B[i-2][j-1]+A[i-1] if j-1 in B[i-2] else -float('inf')
        m2 = B[i-1][j] if j in B[i-1] else -float('inf')
        B[i][j] = max(m1,m2)
    else:
      for j in range(math.ceil((i-2)/2),(i+1)//2+1):
        m1 = B[i-2][j-1]+A[i-1] if j-1 in B[i-2] else -float('inf')
        m2 = B[i-1][j] if j in B[i-1] else -float('inf')
        B[i][j] = max(m1,m2)
      

print((B[N][N//2]))
# Original solution
import sys
#import copy
#import numpy as np
#import itertools
#import collections
#from collections import deque
#from scipy.sparse.csgraph import shortest_path, floyd_warshall, dijkstra, bellman_ford, johnson
#from scipy.sparse import csr_matrix

sys.setrecursionlimit(10**6)
readline = sys.stdin.readline
#read = sys.stdin.buffer.read

inf = float('inf')

def main():
    # input
    N = int(readline())
    A = list(map(int, readline().split()))

    K = N//2
    DP = [[-inf] * (K)  for _ in range(N)]

    DP[0][0] = A[0]
    DP[1][0] = max(A[0], A[1])
    for i in range(2, N):
        i2 = i+1
        start = max(0, i2//2 - 1)
        end = min((i2 + 1)//2, K)
        for j in range(start, end):
            if j == 0:
                DP[i][j] = max(A[i], DP[i-1][j])
            else:
                DP[i][j] = max(DP[i-2][j-1] + A[i], DP[i-1][j])

    ans = DP[N-1][K-1]
    #print(DP)
    print(ans)


if __name__ == "__main__":
    main()


# Optimized solution
import sys
#import copy
#import numpy as np
#import itertools
#import collections
#from collections import deque
#from scipy.sparse.csgraph import shortest_path, floyd_warshall, dijkstra, bellman_ford, johnson
#from scipy.sparse import csr_matrix

sys.setrecursionlimit(10**6)
readline = sys.stdin.readline
#read = sys.stdin.buffer.read

inf = float('inf')
#inf = pow(10, 10)

def main():
    # input
    N = int(readline())
    A = list(map(int, readline().split()))

    K = N//2
    DP0 = [-inf] * N
    DP1 = [-inf] * N
    DP2 = [-inf] * N

    DP2[0] = A[0]
    DP2[1] = max(A[0], A[1])
    DP1[:2] = [0] * 2
    DP0[:4] = [0] * 4
    for i in range(2, N):
        if i%2 == 0:
            DP2[i] = DP2[i-2] + A[i]
            DP1[i] = max(DP2[i-1], DP1[i-2] + A[i])
            DP0[i] = max(DP1[i-1], DP0[i-2] + A[i])
        else:
            DP2[i] = max(DP2[i-2] + A[i], DP2[i-1])
            DP1[i] = max(DP1[i-1], DP1[i-2] + A[i])
            DP0[i] = max(DP0[i-1], DP0[i-2] + A[i])

    if N%2 == 0:
        ans = DP2[N-1]
    else:
        ans = DP1[N-1]

    #print(DP0)
    #print(DP1)
    #print(DP2)
    print(ans)


if __name__ == "__main__":
    main()
# Original solution
def calc():
  n=int(eval(input()))
  arr=list(map(int,input().split()))
  acum1=[0]
  acum2=[0]
  for i in range(n):
    if i%2==0:
      acum1.append(acum1[-1]+arr[i])
      acum2.append(acum2[-1]+0)
    else:
      acum1.append(acum1[-1]+0)
      acum2.append(acum2[-1]+arr[i])
  if n%2==0:
    ans=max(acum1[n-1],acum2[n])
    for i in range(1,n+1,2):
      if i+3>n:
        continue
      tmp=(acum1[i]-acum1[0])+(acum2[n]-acum2[i+2])
      ans=max(ans,tmp)
  else:
    ans=max(acum1[n-2]-acum1[0],acum2[n-1]-acum2[1],acum1[n]-acum1[2])
    for i in range(1,n+1,2):
      if i+3>n-1:
        continue
      tmp=(acum1[i]-acum1[0])+(acum2[n-1]-acum2[i+2])
      ans=max(ans,tmp)
    for i in range(2,n+1,2):
      if i+3>n:
        continue
      tmp=(acum2[i]-acum2[1])+(acum1[n]-acum1[i+2])
      ans=max(ans,tmp)
    for i in range(1,n+1,2):
      if i+4>n:
        continue
      tmp=(acum1[i]-acum1[0])+(acum1[n]-acum1[i+3])
      ans=max(ans,tmp)
    for i in range(1,n+1,2):
      for j in range(i+3,n+1,2):
        if j+3>n:
          continue
        tmp=(acum1[i]-acum1[0]-acum2[i+2])+(acum2[j]+acum1[n]-acum1[j+2])
        ans=max(ans,tmp)
  print(ans)
calc()

# Optimized solution
n=int(eval(input()))
arr=list(map(int,input().split()))
if n<=3:
  print((max(arr)))
  exit()
lim=n%2+2
dp=[[0]*lim for _ in range(n+1)]
for i in range(n):
  dp[i+1][0]=dp[i-1][0]+arr[i]
  dp[i+1][1]=max(dp[i-1][1]+arr[i],dp[i-2][0]+arr[i])
  if lim==3:
    dp[i+1][2]=max(dp[i-1][2]+arr[i],dp[i-2][1]+arr[i],dp[i-3][0]+arr[i])
print((max(dp[-1][:lim])))
# Original solution
import sys
input=sys.stdin.readline
n=int(eval(input()))
a=list(map(int,input().split()))
m=n//2
dp=[[-10**18]*n for _ in range(m)]
if n%2==0:
    dp[0][0]=a[0]
    dp[0][1]=a[1]
    for i in range(1,m):
        for j in range(2*i,2*(i+1)):
            for k in range(2*(i-1),2*i):
                if j-k>1:
                    dp[i][j]=max(dp[i][j],dp[i-1][k]+a[j])
else:
    dp[0][0]=a[0]
    dp[0][1]=a[1]
    dp[0][2]=a[2]
    for i in range(1,m):
        for j in range(2*i,2*(i+1)+1):
            for k in range(2*(i-1),2*i+1):
                if j-k>1:
                    #print(j)
                    dp[i][j]=max(dp[i][j],dp[i-1][k]+a[j])
print((max(dp[-1])))

# Optimized solution
import sys
input=sys.stdin.readline
n=int(eval(input()))
a=list(map(int,input().split()))
m=n//2
if n%2==0:
    dp=[[-10**18]*2 for _ in range(m)]
    dp[0][0]=a[0]
    dp[0][1]=a[1]
    for i in range(1,m):
        for j in range(2*i,2*(i+1)):
            for k in range(2*(i-1),2*i):
                if j-k>1:
                    dp[i][j%2]=max(dp[i][j%2],dp[i-1][k%2]+a[j])
else:
    dp=[[-10**18]*3 for _ in range(m)]
    dp[0][0]=a[0]
    dp[0][1]=a[1]
    dp[0][2]=a[2]
    for i in range(1,m):
        for j in range(2*i,2*(i+1)+1):
            for k in range(2*(i-1),2*i+1):
                if j-k>1:
                    dp[i][j-2*i]=max(dp[i][j-2*i],dp[i-1][k-2*(i-1)]+a[j])
print((max(dp[-1])))
# Original solution
N = int(eval(input()))
A = list(map(int,input().split()))
s = [0]*N
for i in range(N):
    s[i] = s[i-2]+A[i]

dp = [0]*N
dp[1] = max(A[0],A[1])
if N>=3:
    dp[2] = max(A[0],A[1],A[2])
for n in range(3,N):
    if n%2==1:
        dp[n] = max(A[n]+dp[n-2],s[n-1])
    else:
        dp[n] = max(A[n]+dp[n-2],A[n-1]+dp[n-3],s[n-2])

print((dp[-1]))

# Optimized solution
N = int(eval(input()))
A = list(map(int,input().split()))
s = [0]*N
for i in range(N):
    s[i] = s[i-2]+A[i]

dp = [0]*N
for n in range(N):
    if n%2==1:
        dp[n] = max(A[n]+dp[n-2],s[n-1])
    else:
        dp[n] = max(A[n]+dp[n-2],dp[n-1])

print((dp[-1]))
# Original solution
n = int(eval(input()))
A = list(map(int,input().split()))

def zenbu(m, B):
    dp = [-10**9]*m
    if dp[m-1] > -10**9:
        return dp[m-1]
    elif m == 1:
        dp[0] = B[0]
        return dp[0]
    elif m == 2:
        dp[1] = max(B[0],B[1])
        return dp[1]
    elif m == 3:
        dp[2] = max(B[0],B[1],B[2])
        return dp[2]
    elif m%2 == 0: #偶数の場合
        temp = 0
        for i in range(m//2-1):
            temp += B[i*2]
        dp[m-1] = max(temp+ max(B[m-2],B[m-1]), zenbu(m-2, B)+ B[m-1])
        return dp[m-1]
    else:#奇数の場合
        temp = 0
        for i in range((m-1)//2):
            temp += B[i*2]
        dp[m-1] = max(temp, zenbu(m-2,B)+ B[m-1], zenbu(m-3,B)+ max(B[m-2],B[m-1]))
        return dp[m-1]

ans = zenbu(n,A)

print(ans)

# Optimized solution
import sys
input = sys.stdin.readline
N = int(eval(input()))
A = list(map(int,input().split()))
if N%2 == 0:
  dp = [[0]*2 for _ in range(N)] #0index
  dp[0][0] = A[0]
  dp[1][1] = A[1]
  for i in range(2,N):
    dp[i][0] = dp[i-2][0]+A[i]
    if i-3>=0:
      dp[i][1] = max(dp[i-2][1],dp[i-3][0])+A[i]
    else:
      dp[i][1] = max(dp[i-2][1],0)+A[i]
  ans = max(dp[-2][0],dp[-1][1])
  print(ans)
#i個目を使ってj(0-2)回多く飛んでいる。
else: #N%2 == 1:
  dp = [[0]*3 for _ in range(N)] #0index
  dp[0][0] = A[0]
  dp[1][1] = A[1]
  dp[2][2] = A[2]
  dp[2][0] = A[0]+A[2]
  #print(dp)
  for i in range(3,N):
    dp[i][0] = dp[i-2][0]+A[i]
    if i-3 >= 0:
      dp[i][1] = max(dp[i-2][1],dp[i-3][0])+A[i]
    else:
      dp[i][1] = max(dp[i-2][1],0)+A[i]
    if i-4 >= 0:
      dp[i][2] = max(dp[i-2][2],dp[i-3][1],dp[i-4][0])+A[i]
    elif i-3 >= 0:
      dp[i][2] = max(dp[i-2][2],dp[i-3][1],0)+A[i]
  #else:
  #  dp[i][2] = max(dp[i-2][2],0,0)+A[i]
  #print(dp[-1],dp[-2],dp[-3])

  ans = max(dp[-3][0],dp[-2][1],dp[-1][2])
  print(ans)
  exit()
# Original solution
# -*- coding: utf-8 -*-
"""
Spyder Editor

This is a temporary script file.
"""

#f = open("C:/Users/naoki/Desktop/Atcoder/input.txt")
N = int(eval(input()))
A = list(map(int, input().split()))
A.insert(0, 0)

select_num = N//2

Dp_f = [[-9999]*(N+1) for _ in range(N+1)]
Dp_s = [[-9999]*(N+1) for _ in range(N+1)]

for i in range(1,N+1):
    Start = (i-1)//2
    End = (i+1)//2

    for j in range(Start,End+1):
        Dp_f[i][j] = max(Dp_s[i-1][j], Dp_f[i-1][j])   
        # [0] in 3rd dimension  not chosen at last num
        # must be transfered from [i-1]
    for j in range(Start,End+1):
        if Dp_f[i-1][j-1] == -9999 and j == 1:
            Dp_s[i][j] = 0 + A[i]
        else:
            Dp_s[i][j] = Dp_f[i-1][j-1]+A[i]

print((max(Dp_f[-1][select_num], Dp_s[-1][select_num])))


# Optimized solution

#f = open("C:/Users/naoki/Desktop/Atcoder/input.txt")
N = int(eval(input()))
A = list(map(int, input().split()))
A.insert(0, 0)

select_num = N//2
inf = -10e+100

Dp_f = [[inf] * (3) for _ in range(N+1)]
Dp_s = [[inf] * (3) for _ in range(N+1)]
# 3　次元はそれぞれStart~3つに該当

pre_margin = 0
for i in range(1,N+1):
    Start = (i-1)//2
    End = (i+1)//2
    
    cur_margin = Start
    
    for j in range(Start,End+1):
        Dp_f[i][j-cur_margin] = max(Dp_s[i-1][j-pre_margin], Dp_f[i-1][j-pre_margin])   
        # [0] in 3rd dimension  not chosen at last num
        # must be transfered from [i-1]
    for j in range(Start,End+1):
        if j-1 == 0:
            Dp_s[i][j-cur_margin] = 0 + A[i]
        else:
            Dp_s[i][j-cur_margin] = Dp_f[i-1][j-1-pre_margin]+A[i]
    
    pre_margin = cur_margin
print((max(Dp_f[-1][select_num - cur_margin], Dp_s[-1][select_num - cur_margin])))
# Original solution
# unfinished
INF = 1 << 64


def find_max(a):
    n = len(a)
    odd_a = [a[i] for i in range(n) if i % 2 == 0]
    even_a = [a[i] for i in range(n) if i % 2 == 1]

    cum_odd_a = [0]
    sum_odd_a = 0
    for odd_a_elem in odd_a:
        cum_odd_a.append(cum_odd_a[-1] + odd_a_elem)
        sum_odd_a += odd_a_elem

    cum_even_a = [0]
    sum_even_a = 0
    for even_a_elem in even_a:
        cum_even_a.append(cum_even_a[-1] + even_a_elem)
        sum_even_a += even_a_elem

    max_sum_half_a = -INF

    if n % 2 == 0:  # nが偶数である場合
        # 奇数と偶数の境目
        for i in range(n // 2 + 1):
            odd_part_sum = cum_odd_a[i]
            even_part_sum = sum_even_a - cum_even_a[i]
            sum_half_a = odd_part_sum + even_part_sum

            if sum_half_a > max_sum_half_a:
                max_sum_half_a = sum_half_a
    else:  # nが奇数である場合
        # 奇数と偶数の境目
        for i in range(n // 2 + 1):
            odd_part_sum_1 = cum_odd_a[i]

            # 偶数と奇数の境目
            for j in range(i, n // 2 + 1):
                even_part_sum = cum_even_a[j] - cum_even_a[i]
                odd_part_sum_2 = sum_odd_a - cum_odd_a[j + 1]

                sum_half_a = odd_part_sum_1 + even_part_sum + odd_part_sum_2

                if sum_half_a > max_sum_half_a:
                    max_sum_half_a = sum_half_a

    return max_sum_half_a


def main():
    _ = int(eval(input()))
    a = list(map(int, input().split()))

    print((find_max(a)))


main()


# Optimized solution
def find_max(a):
    n = len(a)

    if n <= 3:
        return max(a)

    dp = [[-(1 << 64)] * (2 + n % 2) for _ in range(n)]

    for i in range(2 + n % 2):
        dp[i][i] = a[i]
        dp[i + 1][i] = a[i]

    for i in range(2, n):
        for j in range(2 + n % 2):
            for extra_space in range(j + 1):
                curr_sum = dp[i - (2 + extra_space)][j - extra_space] + a[i]
                if curr_sum > dp[i][j]:
                    dp[i][j] = curr_sum

    return dp[-1][1 + n % 2]


def main():
    _ = int(eval(input()))
    a = list(map(int, input().split()))

    print((find_max(a)))


main()
# Original solution
n=int(eval(input()))
a=list(map(int,input().split()))
if n<=3:print((max(a)));exit()
if n&1:
  dp=[3*[-(10**20)]for _ in range(n)]
  dp[0][0]=a[0]
  for i in range(1,n):
    if i%2==0:
      dp[i][0]=dp[i-2][0]+a[i]
      if i>=3:dp[i][2]=max(dp[i-2][2]+a[i],dp[i-3][1]+a[i])
      else:dp[i][2]=a[i]
    else:
      if i>=3:dp[i][1]=max(dp[i-2][1]+a[i],dp[i-3][0]+a[i])
      else:dp[i][1]=a[i]
  print((max(dp[-1][2],dp[-2][1],dp[-3][0])))
else:
  b=[a[0]]
  c=[a[1]]
  for i in range(2,n):
    if i%2==0:b.append(b[-1]+a[i])
    else:c.append(c[-1]+a[i])
  ans=max(b[-1],c[-1])
  for i in range(n//2-1):
    ans=max(ans,b[i]+c[-1]-c[i])
  print(ans)


# Optimized solution
n=int(eval(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]if i>1else 0)
for i in range(1,n):
  d[i]=p[i-1]if(i&1)else d[i-1]
  d[i]=max(d[i],l[i]+(d[i-2]if i>1else 0))
print((d[-1]))
# Original solution
n=int(eval(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]if i>1else 0)
for i in range(1,n):
  d[i]=p[i-1]if(i&1)else d[i-1]
  d[i]=max(d[i],l[i]+(d[i-2]if i>1else 0))
print((d[-1]))

# Optimized solution
n=int(eval(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]if i>1else 0);d[i]=max(p[i-1]if(i&1)else d[i-1],l[i]+(d[i-2]if i>1else 0))
print((d[-1]))
# Original solution
n=int(eval(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]if i>1else 0);d[i]=max(p[i-1]if(i&1)else d[i-1],l[i]+(d[i-2]if i>1else 0))
print((d[-1]))

# Optimized solution
n=int(eval(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]if i>1else 0))
print((d[-1]))