N = int(input())
X = input()
ans = 0
r=0
g=0
b=0
G = []
R = []
B = []
for i in range(0,N):
    if(X[i] == 'G'):
        G.append(i)
        g+=1
for k in range(0,N):
    if(X[k] == 'R'):
        R.append(k)
        r+=1
for j in range(0,N):
    if(X[j] == 'B'):
        B.append(j)
        b+=1
ans = r*b*g
for i in G:
    for k in R:
        for j in B:
            if(i<k):
                if(k<j):
                    if(j-k == k-i):
                        ans -=1
                else:
                    if(i<j):
                        if(k-j == j-i):
                            ans -=1
                    else:
                        if(k-i == i-j):
                            ans -= 1
            else:
                if(i<j):
                    if(j-i == i-k):
                        ans -=1
                else:
                    if(k<j):
                        if(i-j == j-k):
                            ans -= 1
                    else:
                        if(i-k == k-j):
                            ans -= 1
print(ans)