#lang racket

(define (count-rgb S r g b)
  (if (null? S)
      (* r g b)
      (cond [(char=? (car S) #\R) (count-rgb (cdr S) (+ r 1) g b)]
            [(char=? (car S) #\G) (count-rgb (cdr S) r (+ g 1) b)]
            [(char=? (car S) #\B) (count-rgb (cdr S) r g (+ b 1))])))

(define (solve N S)
  (let ([total (count-rgb S 0 0 0)]
        [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 subs)
      (if (>= (+ j (- j i)) N)
          subs
          (j-iter i (+ j 1) (+ (if (nonnon i j) 1 0) subs))))
    (define (i-iter i subs)
      (if (>= (+ i 2) N)
          subs
          (+ (i-iter (+ i 1) (j-iter i (+ i 1) subs)))))
    (- total (i-iter 0 0))))

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