package main import ( "bufio" "fmt" "math" "os" "strconv" ) func main() { var n int _, _ = fmt.Scan(&n) bi := bufio.NewScanner(os.Stdin) bi.Split(bufio.ScanWords) sum := 0 nums := make([]int, n) for i := range nums { bi.Scan() a, _ := strconv.Atoi(bi.Text()) sum += a nums[i] = a } c, f := int(math.Ceil(float64(sum)/float64(n))), int(math.Floor(math.Ceil(float64(sum)/float64(n)))) var cd, fd float64 for _, a := range nums { cd += math.Abs(float64(c - a)) fd += math.Abs(float64(f - a)) } fmt.Println(int(math.Min(cd, fd))) }