def selectmax(a1,a2,a3,a4): left = a1 + a3 right = a2 + a4 edge = a1 + a4 max1 = max(left,right,edge) if max1 == right: return 'right' else: return 'left' n = int(input()) m = input().split() v = [0] sum = [] for num in range(n): v.append(int(m[num])) judge = True i = 1 num2 = n sum = 0 while judge: judge = False if num2 == 1: sum += v[i] elif num2 == 2: sum += max(v[i],v[i+1]) elif num2 == 3: sum += max(v[i]+v[i+2],v[i+1]) else: judge = True b1 = v[i] b2 = v[i+1] b3 = v[i+2] b4 = v[i+3] message = selectmax(b1,b2,b3,b4) if message is 'right': sum += b2 i += 3 num2 -= 3 else: sum += b1 i += 2 num2 -= 2 print(sum)