# Original solution
#!usr/bin/env python3
from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS():return list(map(list, sys.stdin.readline().split()))
def S(): return list(sys.stdin.readline())[:-1]
def IR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = I()
    return l
def LIR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = LI()
    return l
def SR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = S()
    return l
def LSR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = SR()
    return l
sys.setrecursionlimit(1000000)
mod = 1000000007


#A
def A():
    n,k = LI()
    a = LI()
    dp = [0 for i in range(k+1)]
    f = [0 for i in range(k+1)]
    for i in range(k+1):
        if not f[i]:
            for j in a:
                if i-j >= 0:
                    dp[i] = 1-dp[i-j]
                    if dp[i] == 0:
                        break
            else:
                dp[i] = 1
    print((["First","Second"][dp[k]]))
#B
def B():
    def dfs(d,m,k):
        if dp[m] != None:
            return dp[m]
        l = [k,k+n-1-d]
        if not d%2:
            res = -float("inf")
            res = max(res,a[l[0]]+dfs(d+1,m^p[l[0]],k+1))
            res = max(res,a[l[1]]+dfs(d+1,m^p[l[1]],k))
            dp[m] = res
            return dp[m]
        else:
            res = float("inf")
            for i in l:
                    res = min(res,-a[l[0]]+dfs(d+1,m^p[l[0]],k+1))
                    res = min(res,-a[l[1]]+dfs(d+1,m^p[l[1]],k))
            dp[m] = res
            return dp[m]
    n = I()
    a = LI()
    b = deque()
    p = [1 for i in range(n+1)]
    for i in range(n):
        p[i+1] = p[i]*2
    for i in range(1,n+1):
        b += [(p[i]-1) << j for j in range(n+1-i)]
    dp = [None for i in range(b[-1]+1)]
    dp[0] = 0
    print((dfs(0,b[-1],0)))
    return

#C
def C():
    return

#D
def D():
    return

#E
def E():
    return

#F
def F():
    return

#G
def G():
    return

#H
def H():
    return

#Solve
if __name__ == "__main__":
    B()


# Optimized solution
#!usr/bin/env python3
from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS():return list(map(list, sys.stdin.readline().split()))
def S(): return list(sys.stdin.readline())[:-1]
def IR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = I()
    return l
def LIR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = LI()
    return l
def SR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = S()
    return l
def LSR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = SR()
    return l
sys.setrecursionlimit(1000000)
mod = 1000000007


#A
def A():
    n,k = LI()
    a = LI()
    dp = [0 for i in range(k+1)]
    f = [0 for i in range(k+1)]
    for i in range(k+1):
        if not f[i]:
            for j in a:
                if i-j >= 0:
                    dp[i] = 1-dp[i-j]
                    if dp[i] == 0:
                        break
            else:
                dp[i] = 1
    print((["First","Second"][dp[k]]))
#B
def B():
    def dfs(d,m,k):
        if dp[m] != None:
            return dp[m]
        l = [k,k+n-1-d]
        if not d%2:
            res = -float("inf")
            res = max(res,a[l[0]]+dfs(d+1,m^p[l[0]],k+1))
            res = max(res,a[l[1]]+dfs(d+1,m^p[l[1]],k))
            dp[m] = res
            return dp[m]
        else:
            res = float("inf")
            for i in l:
                    res = min(res,-a[l[0]]+dfs(d+1,m^p[l[0]],k+1))
                    res = min(res,-a[l[1]]+dfs(d+1,m^p[l[1]],k))
            dp[m] = res
            return dp[m]
    n = I()
    a = LI()
    p = [1 for i in range(n+1)]
    for i in range(n):
        p[i+1] = p[i]*2
    dp = [None for i in range(p[-1])]
    dp[0] = 0
    print((dfs(0,p[-1]-1,0)))
    return

#C
def C():
    return

#D
def D():
    return

#E
def E():
    return

#F
def F():
    return

#G
def G():
    return

#H
def H():
    return

#Solve
if __name__ == "__main__":
    B()