def mirror_ins(itr, ins, index_based: bool = True):
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
if __name__ == "__main__":
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)