Scanf.scanf "%d" (fun n ->
    let a = Array.init n (fun _ -> Scanf.scanf " %d" (fun a -> a)) in
    let s = Array.fold_left (+) 0 a in

    let rec loop i dist df =
        if i = n then df else
            if abs (a.(i) * n - s) < dist then loop (i + 1) (abs (a.(i) * n - s)) i
                                          else loop (i + 1) dist df
    in
    loop 0 max_int 0 |> Printf.printf "%d\n"
)