Scanf.scanf "%d %d %d" (fun p1 p2 n -> let res = Array.make 1000 0 in let rec loop i acc = if i = n then acc else let acc = Scanf.scanf " %d" (fun r -> res.(r) <- res.(r) + 1; if res.(r) > 1 then acc + p1 + p2 else acc ) in loop (i + 1) acc in loop 0 0 |> Printf.printf "%d\n" )