let () = Scanf.scanf "%d\n%s" @@ fun n s ->
  let r, g, b =
    List.fold_left (fun (r, g, b) -> function
      | 'R' -> r + 1, g, b
      | 'G' -> r, g + 1, b
      | 'B' -> r, g, b + 1) (0, 0, 0) @@
    List.init (String.length s) @@ String.get s in
  let ignore =
    List.fold_left (List.fold_left ( + )) 0 @@
    List.init (String.length s / 2) @@ fun w ->
      List.init (String.length s - 2 * (w + 1)) @@ fun i ->
        if s.[i] = s.[i + w + 1] || s.[i + w + 1] = s.[i + 2 * (w + 1)] || s.[i] = s.[i + 2 * (w + 1)]
        then 0
        else 1 in
  Printf.printf "%d\n" @@ r * g * b - ignore