n = int(input()) num = list(map(int, input().split())) left = 0 right = 2 * n - 1 ans = 0 for x in range(n): r = num[right] - num[right - 1] l = num[left] - num[left + 1] if l >= r: ans += l left += 2 else: ans += r right -= 2 print(ans)