n, *rest = map(int, open(0).read().split()) a = rest[:n] a.sort() total = 0 for i in range(1, n): total += abs(a[i] - a[i-1]) print(total)