#lang racket

(define (count-rgb N S)
  (let ([r 0] [g 0] [b 0])
    (define (iter s)
      (if (null? s)
          (* r g b)
          (begin
            (let ([item (car s)])
              (cond [(char=? item #\R) (set! r (+ r 1))]
                    [(char=? item #\G) (set! g (+ g 1))]
                    [(char=? item #\B) (set! b (+ b 1))])
            (iter (cdr s))))))
    (iter S)))

(define (solve N S)
  (let ([total (count-rgb N S)]
        [colors (list->vector S)])
    (define (nonnon i j)
      (let ([k (+ j (- j i))])
        (and (not (char=? (vector-ref colors i) (vector-ref colors j)))
             (not (char=? (vector-ref colors i) (vector-ref colors k)))
             (not (char=? (vector-ref colors j) (vector-ref colors k))))))
    (define (j-iter i j)
      (if (>= (+ j (- j i)) N)
          0
          (+ (if (nonnon i j) 1 0) (j-iter i (+ j 1)))))
    (define (i-iter i)
      (if (>= (+ i 2) N)
          0
          (+ (j-iter i (+ i 1)) (i-iter (+ i 1)))))
    (- total (i-iter 0))))

(let ([N (read)]
      [S (string->list (symbol->string (read)))])
  (display (solve N S)))
