from collections import deque N = int(input()) A = tuple(map(int, input().split())) ans = 0 head = 0 tail = 2*N-1 while tail > head: x = A[head] - A[head+1] y = A[tail] - A[tail-1] if x > y: ans += x head += 2 else: ans += y tail -= 2 print(ans)