### BUGGY CODE ###

from time import time

def solve(N, S):
    answer = 0
    for i in range(N):
        Si = S[i]
        for k in range(i+2, N):
            Sk = S[k]
            if Si == Sk:
                continue
            for j in range(i+1, k):
                if j-i == k-j:
                    continue
                Sj = S[j]
                if Si == Sj or Sj == Sk:
                    continue
                answer += 1
    print(answer)

def main(N, S):
    import sys
    start = time()
    from itertools import combinations
    Cs = [[], [], []]
    for i in range(N):
        c = S[i]
        if c == 'R':
            Cs[0].append(i)
        elif c == 'G':
            Cs[1].append(i)
        elif c == 'B':
            Cs[2].append(i)
    answer = 0
    for C in Cs:
        a = 0
        print(C, len(C))
        for Ci in range(len(C)-1):
            i = C[Ci]
            for Cj in range(Ci+1, len(C)):
                j = C[Cj]
                print("*", i, j)
                print(i)           # i より前
                print(j - i - 1)   # i と j の間
                print(N - 1 - j)   # j より後
                print(Ci)
                print(Cj - Ci-1)
                print(len(C) - 1 - Cj)
                a += i           # i より前
                a += N - 1 - j   # j より後
                a += j - i - 1   # i と j の間
                a -= Ci
                a -= Cj - Ci-1
                a -= len(C) - 1 - Cj
        print(S[C[0]], "expect", sum(S[C[0]] in (i, j, k) and (i == j or j == k or i == k) for i,j,k in combinations(S, 3)))
        print(S[C[0]], "actual", a)
        answer += a
    print("expect", sum(i == j or j == k or i == k for i,j,k in combinations(S, 3)))
    print("actual", answer)

    print(answer, time() - start, file=sys.stderr)
    for i in range(N):
        for d in range(1, N-i):
            if i + 2*d < N and not(S[i] == S[i+d] or S[i] == S[i+2*d]):
                answer += 1
    total = N * (N-1)*(N-2) // 6
    print(total, answer, file=sys.stderr)
    print(total - answer)
    print(time() - start, file=sys.stderr)


N = int(input())
S = input()
solve(N, S)
#main(N, S)


### FIXED CODE ###

from time import time

def solve(N, S):
    answer = 0
    Cs = [[], [], []]
    for i in range(N):
        c = S[i]
        if c == 'R':
            Cs[0].append(i)
        elif c == 'G':
            Cs[1].append(i)
        elif c == 'B':
            Cs[2].append(i)
    answer = len(Cs[0]) * len(Cs[1]) * len(Cs[2])
    for i in range(N):
        for d in range(1, N-i):
            if i + 2*d < N and not(S[i] == S[i+d] or S[i] == S[i+2*d] or S[i+d*2] == S[i+d]):
                answer -= 1
    print(answer)


def main(N, S):
    import sys
    start = time()
    from itertools import combinations
    Cs = [[], [], []]
    for i in range(N):
        c = S[i]
        if c == 'R':
            Cs[0].append(i)
        elif c == 'G':
            Cs[1].append(i)
        elif c == 'B':
            Cs[2].append(i)
    answer = 0
    for C in Cs:
        a = 0
        print(C, len(C))
        for Ci in range(len(C)-1):
            i = C[Ci]
            for Cj in range(Ci+1, len(C)):
                j = C[Cj]
                print("*", i, j)
                print(i)           # i より前
                print(j - i - 1)   # i と j の間
                print(N - 1 - j)   # j より後
                print(Ci)
                print(Cj - Ci-1)
                print(len(C) - 1 - Cj)
                a += i           # i より前
                a += N - 1 - j   # j より後
                a += j - i - 1   # i と j の間
                a -= Ci
                a -= Cj - Ci-1
                a -= len(C) - 1 - Cj
        print(S[C[0]], "expect", sum(S[C[0]] in (i, j, k) and (i == j or j == k or i == k) for i,j,k in combinations(S, 3)))
        print(S[C[0]], "actual", a)
        answer += a
    print("expect", sum(i == j or j == k or i == k for i,j,k in combinations(S, 3)))
    print("actual", answer)

    print(answer, time() - start, file=sys.stderr)
    for i in range(N):
        for d in range(1, N-i):
            if i + 2*d < N and not(S[i] == S[i+d] or S[i] == S[i+2*d]):
                answer += 1
    total = N * (N-1)*(N-2) // 6
    print(total, answer, file=sys.stderr)
    print(total - answer)
    print(time() - start, file=sys.stderr)


N = int(input())
S = input()
solve(N, S)
#main(N, S)