# 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):
        if dp[m] != None:
            return dp[m]
        l = []
        for i in range(n+1):
            if p[i]&m:
                l.append(i)
                for j in range(i,n+1):
                    if not p[j]&m:
                        l.append(j-1)
                        break
                else:
                    l.append(n)
                break
        if not d%2:
            res = -float("inf")
            for i in l:
                res = max(res,a[i]+dfs(d+1,m^p[i]))
            dp[m] = res
            return dp[m]
        else:
            res = float("inf")
            for i in l:
                res = min(res,-a[i]+dfs(d+1,m^p[i]))
            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])))
    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):
        if dp[m] != None:
            return dp[m]
        l = [0,0]
        for i in range(n+1):
            if p[i]&m:
                l[0] = i
                l[1] = i+n-1-d
                break
        if not d%2:
            res = -float("inf")
            for i in l:
                res = max(res,a[i]+dfs(d+1,m^p[i]))
            dp[m] = res
            return dp[m]
        else:
            res = float("inf")
            for i in l:
                res = min(res,-a[i]+dfs(d+1,m^p[i]))
            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])))
    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()