n = int(input()) A = list(map(int, input().split())) from collections import deque L = deque(A) h = 0 t = 0 for i in range(n): if i != n-1: l1 = L.popleft() l2 = L.popleft() r1 = L.pop() r2 = L.pop() if l1-l2 >= r1-r2: h += l1 t += l2 L.append(r2) L.append(r1) else: h += r1 t += r2 L.appendleft(l2) L.appendleft(l1) else: l = L.popleft() r = L.pop() if l >= r: h += l t += r else: h += r t += l print(h-t)