import sys

input = sys.stdin.readline



N = int(eval(input()))

S = eval(input())

CNTR = 0

CNTG = 0

CNTB = 0

for i in range(N):

    if S[i] == 'R':

        CNTR += 1

    if S[i] == 'G':

        CNTG += 1

    if S[i] == 'B':

        CNTB += 1

CONB = CNTR * CNTG * CNTB

CNT = 0

for i in range(N):

    for j in range(i,N):

        if S[j] != S[i]:

            k = j + (j-i)

            if k > N-1:

                continue

            if S[k] != S[i] and S[k] != S[j]:

                CNT += 1

print((CONB - CNT))
import sys

input = sys.stdin.readline



def main():

    N = int(eval(input()))

    S = eval(input())

    CNTR = 0

    CNTG = 0

    CNTB = 0

    for i in range(N):

        if S[i] == 'R':

            CNTR += 1

        if S[i] == 'G':

            CNTG += 1

        if S[i] == 'B':

            CNTB += 1

    CONB = CNTR * CNTG * CNTB

    CNT = 0

    for i in range(N):

        for j in range(i,N):

            if S[j] != S[i]:

                k = j + (j-i)

                if k > N-1:

                    continue

                if S[k] != S[i] and S[k] != S[j]:

                    CNT += 1

    print((CONB - CNT))





if __name__ == '__main__':

    main()
import sys

input = sys.stdin.readline
N = int(eval(input()))
S = eval(input())
CNTR = 0
CNTG = 0
CNTB = 0
for i in range(N):
    if S[i] == "R":
        CNTR += 1
    if S[i] == "G":
        CNTG += 1
    if S[i] == "B":
        CNTB += 1
CONB = CNTR * CNTG * CNTB
CNT = 0
for i in range(N):
    for j in range(i, N):
        if S[j] != S[i]:
            k = j + (j - i)
            if k > N - 1:
                continue
            if S[k] != S[i] and S[k] != S[j]:
                CNT += 1
print((CONB - CNT))

import sys

input = sys.stdin.readline


def main():
    N = int(eval(input()))
    S = eval(input())
    CNTR = 0
    CNTG = 0
    CNTB = 0
    for i in range(N):
        if S[i] == "R":
            CNTR += 1
        if S[i] == "G":
            CNTG += 1
        if S[i] == "B":
            CNTB += 1
    CONB = CNTR * CNTG * CNTB
    CNT = 0
    for i in range(N):
        for j in range(i, N):
            if S[j] != S[i]:
                k = j + (j - i)
                if k > N - 1:
                    continue
                if S[k] != S[i] and S[k] != S[j]:
                    CNT += 1
    print((CONB - CNT))


if __name__ == "__main__":
    main()

-N = int(eval(input())) -S = eval(input()) -CNTR = 0 -CNTG = 0 -CNTB = 0 -for i in range(N): -    if S[i] == "R": -        CNTR += 1 -    if S[i] == "G": -        CNTG += 1 -    if S[i] == "B": -        CNTB += 1 -CONB = CNTR * CNTG * CNTB -CNT = 0 -for i in range(N): -    for j in range(i, N): -        if S[j] != S[i]: -            k = j + (j - i) -            if k > N - 1: -                continue -            if S[k] != S[i] and S[k] != S[j]: -                CNT += 1 -print((CONB - CNT)) + + +def main(): +    N = int(eval(input())) +    S = eval(input()) +    CNTR = 0 +    CNTG = 0 +    CNTB = 0 +    for i in range(N): +        if S[i] == "R": +            CNTR += 1 +        if S[i] == "G": +            CNTG += 1 +        if S[i] == "B": +            CNTB += 1 +    CONB = CNTR * CNTG * CNTB +    CNT = 0 +    for i in range(N): +        for j in range(i, N): +            if S[j] != S[i]: +                k = j + (j - i) +                if k > N - 1: +                    continue +                if S[k] != S[i] and S[k] != S[j]: +                    CNT += 1 +    print((CONB - CNT)) + + +if __name__ == "__main__": +    main()