# Original solution
#!/usr/bin/env python3
import sys


def solve(N: int, S: str):
    count = 0
    for i in range(N):
        if S[i] == "R":
            for j in range(i + 1, N):
                if S[j] == "G":
                    for k in range(j + 1, N):
                        if S[k] == "B" and j - i != k - j:
                            count += 1
                elif S[j] == "B":
                    for k in range(j + 1, N):
                        if S[k] == "G" and j - i != k - j:
                            count += 1
        elif S[i] == "G":
            for j in range(i + 1, N):
                if S[j] == "R":
                    for k in range(j + 1, N):
                        if S[k] == "B" and j - i != k - j:
                            count += 1
                elif S[j] == "B":
                    for k in range(j + 1, N):
                        if S[k] == "R" and j - i != k - j:
                            count += 1
        else:
            for j in range(i + 1, N):
                if S[j] == "G":
                    for k in range(j + 1, N):
                        if S[k] == "R" and j - i != k - j:
                            count += 1
                elif S[j] == "R":
                    for k in range(j + 1, N):
                        if S[k] == "G" and j - i != k - j:
                            count += 1

    print(count)
    return


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    S = next(tokens)  # type: str
    solve(N, S)

if __name__ == '__main__':
    main()


# Optimized solution
#!/usr/bin/env python3
import sys


def solve(N: int, S: str):
    r = 0
    g = 0
    b = 0
    sub = 0
    for i in range(N):
        if S[i] == "R":
            r += 1
            for j in range(i + 1, N):
                if S[j] == "G":
                    if j * 2 - i < N and S[j * 2 - i] == "B":
                        sub += 1
                elif S[j] == "B":
                    if j * 2 - i < N and S[j * 2 - i] == "G":
                        sub += 1
        elif S[i] == "G":
            g += 1
            for j in range(i + 1, N):
                if S[j] == "R":
                    if j * 2 - i < N and S[j * 2 - i] == "B":
                        sub += 1
                elif S[j] == "B":
                    if j * 2 - i < N and S[j * 2 - i] == "R":
                        sub += 1
        else:
            b += 1
            for j in range(i + 1, N):
                if S[j] == "R":
                    if j * 2 - i < N and S[j * 2 - i] == "G":
                        sub += 1
                elif S[j] == "G":
                    if j * 2 - i < N and S[j * 2 - i] == "R":
                        sub += 1

    print((r * g * b - sub))
    return


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    S = next(tokens)  # type: str
    solve(N, S)

if __name__ == '__main__':
    main()