Scanf.scanf "%d %s" (fun n s -> let rec loop_i i acc = let rec loop_j j acc = if j >= n then acc else let acc = if s.[j] = 'G' && s.[(i + j) / 2] = 'M' then acc + 1 else acc in loop_j (j + 2) acc in if i = n then acc else let acc = if s.[i] = 'U' then loop_j (i + 2) acc else acc in loop_i (i + 1) acc in loop_i 0 0 |> Printf.printf "%d\n" )