n = int(input()) a = [int(i) for i in input().split()] ans = 0 l,r = 0,2*n-1 for i in range(n): if a[l] - a[l+1] > a[r] - a[r-1]: ans += a[l]-a[l+1] a[l],a[l+1] = 0,10**10 l += 2 else: ans += a[r]-a[r-1] a[r],a[r-1] = 0,10**10 r -= 2 print(ans)