def main(): length = int(input()) numbers = [int(x) for x in input().split()] answer = 0 left_index = 0 right_index = 2 * length - 1 while length > 0: if numbers[left_index] - numbers[left_index + 1] < numbers[right_index] - numbers[right_index - 1]: answer += numbers[right_index] - numbers[right_index - 1] right_index -= 2 else: answer += numbers[left_index] - numbers[left_index + 1] left_index += 2 length -= 1 print(answer) if __name__ == '__main__': main()