// https://yukicoder.me/problems/no/609 package main import ( "fmt" "sort" ) func diff(a, b int) int { if a > b { return a - b } return b - a } func main() { var n int fmt.Scan(&n) ys := make([]int, n) for i := 0; i < n; i++ { fmt.Scan(&ys[i]) } sort.Ints(ys) med := ys[n/2] sum := 0 for _, y := range ys { sum += diff(med, y) } fmt.Println(sum) }