package main
import (
"fmt"
"sort"
)
const N int = 100000
var s [N]int
func main() {
var n int
fmt.Scanf("%d", &n)
for i := 0; i < n; i++ {
fmt.Scanf("%d", &s[i])
}
sort.Ints(s[0:n])
res := 0
for i := 0; i < n; i++ {
num := (s[i] - s[n/2])
if num < 0 {
num = -1 * num
}
res += num
}
fmt.Printf("%d\n", res)
}