## coding: UTF-8
from decimal import *
from itertools import permutations, combinations,combinations_with_replacement,product
import math
from math import gcd

N = int(input())
S = input()

r_list = []
g_list = []
b_list = []

for i in range(N):
    if(S[i] == 'R'):
        r_list.append(i)
    elif(S[i] == 'G'):
        g_list.append(i)
    else:
        b_list.append(i)

#print('r:{}, g:{}, b:{}'.format(r_list, g_list, b_list))

R_count = len(r_list)
G_count = len(g_list)
B_count = len(b_list)
#print(R_count * G_count * B_count)

b_num_list = [0 for i in range(N)]
for i in range(B_count):
    b_num_list[b_list[i]] += 1
#print('b_num_list:{}'.format(b_num_list))
    

counter = R_count * G_count * B_count
NG_list = []
for i in range(R_count):
    for j in range(G_count):
        r = r_list[i]
        g = g_list[j]
        hit_count = 0
        #if( (g+g-r) in b_list):
        #print('g+g+r:{}'.format(g+g-r))
        if(g+g-r >= 0 and g+g-r <= N-1): #and b_num_list[g+g-r] == 1)
            #print('b_num_list[g+g-r]:{}'.format(b_num_list[g+g-r]))
            if(b_num_list[g+g-r] == 1):
                hit_count += 1
        #if( (g+r)%2 == 0 and ((g+r)/2) in b_list ):
        if( (g+r)%2 == 0 and b_num_list[int((g+r)/2)] == 1):
            hit_count+=1
        #if( (r-g+r) in b_list):
        if(r+r-g >= 0 and r+r-g <= N-1 ):#and b_num_list[r+r-g] == 1):
            if(b_num_list[r+r-g] == 1):
                hit_count+=1
        counter -= hit_count
print(counter)
   
