Scanf.scanf "%d %d" (fun n m -> let a = Array.init n (fun _ -> Scanf.scanf " %s" (fun a -> a)) in Array.fold_left (fun acc v -> let rec loop i acc = if i = m then acc else loop (i + 1) (if v.[i] = 'W' then acc + 1 else acc) in loop 0 acc ) 0 a |> Printf.printf "%d\n" )