from collections import deque l, r = 0, 0 h, t = 0, 0 n = int(input()) A = deque(map(int, input().split())) while A: l = A[0]-A[1] r = A[-1]-A[-2] if l >= r: h += A.popleft() t += A.popleft() else: h += A.pop() t += A.pop() print(h-t)