### BUGGY CODE ###

n = int(input())
s = list(input())

R = [0]*(n+10)
G = [0]*(n+10)
B = [0]*(n+10)


for i in range(n):
    if s[i] == "R":
        R[i] = 1
    elif s[i] == "G":
        G[i] = 1
    else:
        B[i] = 1

ans = 0

for i in range(n):
    if s[i] == "R":
        for j in range(i+1,n):
            if  s[j] == "G":
                ans += sum(B[j:])
                if j+j-i > n:
                    continue
                if B[j+j-i] == 1:
                    ans -= 1
            if s[j] == "B":
                ans += sum(G[j:])
                if j+j-i > n:
                    continue
                if G[j+j-i] == 1:
                    ans -= 1               

    if s[i] == "B":
        for j in range(i+1,n):
            if  s[j] == "R":
                ans += sum(G[j:])
                if j+j-i > n:
                    continue
                if G[j+j-i] == 1:
                    ans -= 1
            if s[j] == "G":
                ans += sum(R[j:])
                if j+j-i > n:
                    continue
                if R[j+j-i] == 1:
                    ans -= 1

    if s[i] == "G":
        for j in range(i+1,n):
            if  s[j] == "R":
                ans += sum(B[j:])
                if j+j-i > n:
                    continue
                if B[j+j-i] == 1:
                    ans -= 1
            if s[j] == "B":
                ans += sum(R[j:])
                if j+j-i > n:
                    continue
                if R[j+j-i] == 1:
                    ans -= 1
    
print(ans)

### FIXED CODE ###

n = int(input())
s = list(input())

R_count = [0]*n
G_count = [0]*n
B_count = [0]*n

Rc = 0
Gc = 0
Bc = 0

for i in range(1,n+1):
    if s[-i] == "R":
        Rc += 1
    elif s[-i] == "G":
        Gc += 1
    else:
        Bc += 1
        
    R_count[-i] = Rc
    G_count[-i] = Gc
    B_count[-i] = Bc

ans = 0

for i in range(n):
    if s[i] == "R":
        for j in range(i+1,n-1):
            if  s[j] == "G":
                ans += B_count[j+1]
                if j+j-i+1 > n:
                    continue
                if s[j+j-i] == "B":
                    ans -= 1
            if s[j] == "B":
                ans += G_count[j+1]
                if j+j-i+1 > n:
                    continue
                if s[j+j-i] == "G":
                    ans -= 1               

    if s[i] == "B":
        for j in range(i+1,n-1):
            if  s[j] == "R":
                ans += G_count[j+1]
                if j+j-i+1 > n:
                    continue
                if s[j+j-i] == "G":
                    ans -= 1
            if s[j] == "G":
                ans += R_count[j+1]
                if j+j-i+1 > n:
                    continue
                if s[j+j-i] == "R":
                    ans -= 1

    if s[i] == "G":
        for j in range(i+1,n-1):
            if  s[j] == "R":
                ans += B_count[j+1]
                if j+j-i+1 > n:
                    continue
                if s[j+j-i] == "B":
                    ans -= 1
            if s[j] == "B":
                ans += R_count[j+1]
                if j+j-i+1 > n:
                    continue
                if s[j+j-i] == "R":
                    ans -= 1
    
print(ans)