def mirror_ins(itr, ins, index_based: bool = True):
    """Returns the morrored instance in a iterable.
example:
lst = ["a", "b", "c"]
morrired_instance(lst,  0)
the value 2 will be returned, which is the index of "c" in lst"""
    leng = len(itr)
    if leng % 2:
        # The length of iterable is odd
        middle = leng // 2
        if ins == middle:
            return middle if index_based else itr[middle]
        else:
            distance = abs(ins - middle)
            if ins > middle:
                mirror = ins - (distance * 2)
                return mirror if index_based else itr[mirror]
            else:
                mirror = ins + distance * 2
                return mirror if index_based else itr[mirror]
    else:
        # The length of iterable is even
        middles = ((leng // 2) - 1, leng // 2)
        if ins in middles:
            if ins == middles[0]:
                return middles[1] if index_based else itr[middles[1]]
            else:
                return middles[0] if index_based else itr[middles[0]]
            
        else:
            distance = abs(ins - middles[1])
            if ins > middles[1]:
                mirror = ins - (distance * 2 - 1)
                return mirror if index_based else itr[mirror]
            else:
                mirror = ins + (distance * 2 - 1)
                return mirror if index_based else itr[mirror]


def ask_input():
    n = int(input())
    pillars = list(map(int, input().split()))
    return pillars


pillars = ask_input()
min_shot = 0
for i in range(len(pillars) // 2):
    mirror = mirror_ins(pillars, i, False)
    if pillars[i] == mirror:
        continue
    min_shot += abs(pillars[i] - mirror)
else:
    del i, mirror
    print(min_shot)