N = $stdin.gets.to_i
S = []
CHAR = 0
COUNT = 1
INDEX = 2
prev = nil
$stdin.read(N).split(//).each_with_index do |s, i|
  if prev == s
    S[-1][COUNT] += 1
  else
    S.push([s, 1, i])
  end
end
SLen = S.length
#$stderr.puts S.to_s
def sub_count(pair1, pair2, pair3)
  sc = 0
  pair1[INDEX].upto(pair1[INDEX] + pair1[COUNT] - 1) do |i|
    pair2[INDEX].upto(pair2[INDEX] + pair2[COUNT] - 1) do |j|
      pair3[INDEX].upto(pair3[INDEX] + pair3[COUNT] - 1) do |k|
        if j - i != k - j
          #$stderr.puts [i, j, k].to_s
          sc += 1
        end
      end
    end
  end
  return sc
end
count = 0
0.upto(SLen - 3) do |pos1|
  pair1 = S[pos1]
  (pos1 + 1).upto(SLen - 2) do |pos2|
    pair2 = S[pos2]
    if pair1[CHAR] != pair2[CHAR]
      char3s = ['R', 'G', 'B']
      char3s.delete(pair1[CHAR])
      char3s.delete(pair2[CHAR])
      char3 = char3s[0]
      (pos2 + 1).upto(SLen - 1) do |pos3|
        pair3 = S[pos3]
        if pair3[CHAR] == char3
          count += sub_count(pair1, pair2, pair3)
        end
      end
    end
  end
end
puts count
