def palindromic(arr):
    length = len(arr)
    middle = length // 2
    total_diff_sum = 0

    for i in range(middle):
        left_index = i
        right_index = length - 1 - i

        if arr[left_index] > arr[right_index]:
            total_diff_sum += arr[left_index] - arr[right_index]
            arr[left_index] = arr[right_index]
        else:
            total_diff_sum += arr[right_index] - arr[left_index]
            arr[right_index] = arr[left_index]

    return total_diff_sum, arr


def main():
    count = int(input())
    array_input = input()
    array = [int(num) for num in array_input.split()]

    total_diff_sum, palindrome_array = palindromic(array)
    print(total_diff_sum)


main()