from collections import deque N = int(input()) A = list(map(int,input().split())) if N == 1: print(max(A)-min(A)) exit() B = [] for i in range(0,2*N-1,2): B.append(A[i]-A[i+1]) B = deque(B) ans = 0 while B: if B[0] > -B[-1]: ans += B.popleft() else: ans += -B.pop() print(ans)