### BUGGY CODE ###

import sys
sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))
from collections import deque
def resolve():
    N = ir()
    S = [s for s in sr()]
    q = deque([])
    for i in range(N):
        q.append([S[i], S[i], i, -1])
    ans = 0
    while len(q) > 0:
        u, v, n, d = q.popleft()
        if d == -1:
            for i in range(n+1, N):
                if u != S[i]:
                    q.append([u, S[i], i, i-n])
        else:
            for i in range(n+1, N):
                if i == n+d:
                    continue
                if u != S[i] and v != S[i]:
                    ans += 1
    print(ans)
resolve()

### FIXED CODE ###

import sys
sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))
from bisect import bisect_left
def resolve():
    N = ir()
    S = sr()
    R = []
    G = []
    B = []
    for i in range(N):
        if S[i] == 'R':
            R.append(i+1)
        elif S[i] == 'G':
            G.append(i+1)
        else:
            B.append(i+1)
    ans = len(R)*len(G)*len(B)
    for r in R:
        for g in G:
            if abs(r+g)%2 == 0:
                if abs(r+g)//2 in B:
                    ans -= 1
    for r in B:
        for g in G:
            if abs(r+g)%2 == 0:
                if abs(r+g)//2 in R:
                    ans -= 1
    for r in R:
        for g in B:
            if abs(r+g)%2 == 0:
                if abs(r+g)//2 in G:
                    ans -= 1
            # for b in B:
            #     rg = abs(r-g)
            #     gb = abs(g-b)
            #     br = abs(b-r)
            #     if rg != gb and gb != br and br != rg:
            #         ans += 1
                # i = min(r, g, b)
                # k = max(r, g, b)
                # a = k-i
                # if a != 2*r and a != 2*g and a != 2*b:
                #     ans += 1
    # for n in R:
    #     # x = bisect_left(G, n)
    #     for i in G:
    #         a = max(n, i)
    #         b = min(n, i)
    #         x = bisect_left(B, a)
    #         ans += len(B[x:])
    #         if 2*a-b in B:
    #             ans -= 1
    # for n in R:
    #     # x = bisect_left(B, n)
    #     for i in B:
    #         a = max(n, i)
    #         b = min(n, i)
    #         x = bisect_left(G, a)
    #         ans += len(G[x:])
    #         if 2*a-b in G:
    #             ans -= 1
    # # for n in G:
    # #     x = bisect_left(R, n)
    # #     for i in R[x:]:
    # #         x = bisect_left(B, i)
    # #         ans += len(B[x:])
    # #         if 2*i-n in B:
    # #             ans -= 1
    # for n in G:
    #     # x = bisect_left(B, n)
    #     for i in B:
    #         a = max(n, i)
    #         b = min(n, i)
    #         x = bisect_left(R, a)
    #         ans += len(R[x:])
    #         if 2*a-b in R:
    #             ans -= 1
    # for n in B:
    #     x = bisect_left(R, n)
    #     for i in R[x:]:
    #         x = bisect_left(G, i)
    #         ans += len(G[x:])
    #         if 2*i-n in G:
    #             ans -= 1
    # for n in B:
    #     x = bisect_left(G, n)
    #     for i in G[x:]:
    #         x = bisect_left(R, i)
    #         ans += len(R[x:])
    #         if 2*i-n in R:
    #             ans -= 1
    print(ans)
resolve()