#!/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()

#!/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):



        # RGBそれぞれの個数をカウント

        if S[i] == "R":

            r += 1

        elif S[i] == "G":

            g += 1

        else:

            b += 1

        

        # 条件2に一致しないケースをカウント

        for j in range(i + 1, N):

            if 2 * j - i >= N:

                break

            if S[i] != S[j] and S[j] != S[2 * j - i] and S[i] != S[2 * j - i]:

                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()

#!/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()

#!/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):
        # RGBそれぞれの個数をカウント
        if S[i] == "R":
            r += 1
        elif S[i] == "G":
            g += 1
        else:
            b += 1
        # 条件2に一致しないケースをカウント
        for j in range(i + 1, N):
            if 2 * j - i >= N:
                break
            if S[i] != S[j] and S[j] != S[2 * j - i] and S[i] != S[2 * j - i]:
                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()

+        # RGBそれぞれの個数をカウント -            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 -            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 -            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 +        # 条件2に一致しないケースをカウント +        for j in range(i + 1, N): +            if 2 * j - i >= N: +                break +            if S[i] != S[j] and S[j] != S[2 * j - i] and S[i] != S[2 * j - i]: +                sub += 1