let rec tabulate n f = 
  let rec loop acc m =
    if m < n then loop (f m :: acc) (m + 1)
    else List.rev acc in
  loop [] 0

let () =
  let n, x = Scanf.scanf "%d %d\n" (fun n x -> n, x) in
  let as_ = Array.init n (fun _ -> Scanf.scanf "%d " (fun a -> a)) in
  tabulate n (fun i ->
    tabulate n (fun j -> as_.(j) + x * min ((n + i - j) mod n) ((n + j - i) mod n))
    |> List.fold_left min max_int)
  |> List.fold_left ( + ) 0
  |> Printf.printf "%d\n"
