# import sys

# sys.setrecursionlimit(10 ** 6)

int1 = lambda x: int(x) - 1

def II(): return int(eval(input()))



def MI(): return list(map(int, input().split()))

def MI1(): return list(map(int1, input().split()))



def LI(): return list(map(int, input().split()))

def LLI(rows_number): return [LI() for _ in range(rows_number)]





def solve():

    n = II()

    S = list(eval(input()))



    R = []

    G = []

    B = []

    for i, s in enumerate(S):

        if s == 'R':

            R.append(i)

        elif s == 'G':

            G.append(i)

        else:

            B.append(i)



    cnt = 0

    for i in range(0, n):

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

            k = 2 * j - i

            if k >= n:

                continue

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

                # print(i, j, k)

                cnt = cnt + 1



    print((len(R) * len(G) * len(B) - cnt))



if __name__ == '__main__':

    solve()

import sys

sys.setrecursionlimit(10 ** 6)

# input = sys.stdin.readline    ####

int1 = lambda x: int(x) - 1

def II(): return int(eval(input()))



def MI(): return list(map(int, input().split()))

def MI1(): return list(map(int1, input().split()))



def LI(): return list(map(int, input().split()))

def LI1(): return list(map(int1, input().split()))

def LLI(rows_number): return [LI() for _ in range(rows_number)]



INF = float('inf')



def solve():

    n = II()

    S = list(eval(input()))

    # print(S)

    n = len(S)



    R = []

    G = []

    B = []

    rcnt = 0

    gcnt = 0

    bcnt = 0

    for idx, s in enumerate(S):

        if s == 'R':

            R.append(idx+1)

            rcnt += 1

        elif s == 'G':

            G.append(idx+1)

            gcnt += 1

        else:

            B.append(idx+1)

            bcnt += 1

    # print(R)

    # print(G)

    # print(B)

    ans = rcnt * gcnt * bcnt

    # print(ans)



    for i in range(n):

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

            k = 2 * j - i

            if k >= n:

                continue

            # print(i, j, k)

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

                ans -= 1

    print(ans)











if __name__ == '__main__':

    solve()

# import sys
# sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1


def II():
    return int(eval(input()))


def MI():
    return list(map(int, input().split()))


def MI1():
    return list(map(int1, input().split()))


def LI():
    return list(map(int, input().split()))


def LLI(rows_number):
    return [LI() for _ in range(rows_number)]


def solve():
    n = II()
    S = list(eval(input()))
    R = []
    G = []
    B = []
    for i, s in enumerate(S):
        if s == "R":
            R.append(i)
        elif s == "G":
            G.append(i)
        else:
            B.append(i)
    cnt = 0
    for i in range(0, n):
        for j in range(i + 1, n):
            k = 2 * j - i
            if k >= n:
                continue
            if S[i] != S[j] and S[j] != S[k] and S[k] != S[i]:
                # print(i, j, k)
                cnt = cnt + 1
    print((len(R) * len(G) * len(B) - cnt))


if __name__ == "__main__":
    solve()

import sys

sys.setrecursionlimit(10**6)
# input = sys.stdin.readline    ####
int1 = lambda x: int(x) - 1


def II():
    return int(eval(input()))


def MI():
    return list(map(int, input().split()))


def MI1():
    return list(map(int1, input().split()))


def LI():
    return list(map(int, input().split()))


def LI1():
    return list(map(int1, input().split()))


def LLI(rows_number):
    return [LI() for _ in range(rows_number)]


INF = float("inf")


def solve():
    n = II()
    S = list(eval(input()))
    # print(S)
    n = len(S)
    R = []
    G = []
    B = []
    rcnt = 0
    gcnt = 0
    bcnt = 0
    for idx, s in enumerate(S):
        if s == "R":
            R.append(idx + 1)
            rcnt += 1
        elif s == "G":
            G.append(idx + 1)
            gcnt += 1
        else:
            B.append(idx + 1)
            bcnt += 1
    # print(R)
    # print(G)
    # print(B)
    ans = rcnt * gcnt * bcnt
    # print(ans)
    for i in range(n):
        for j in range(i + 1, n):
            k = 2 * j - i
            if k >= n:
                continue
            # print(i, j, k)
            if S[i] != S[j] and S[j] != S[k] and S[k] != S[i]:
                ans -= 1
    print(ans)


if __name__ == "__main__":
    solve()

-# import sys -# sys.setrecursionlimit(10 ** 6) +import sys + +sys.setrecursionlimit(10**6) +# input = sys.stdin.readline    #### +def LI1(): +    return list(map(int1, input().split())) + + + + +INF = float("inf") +    # print(S) +    n = len(S) -    for i, s in enumerate(S): +    rcnt = 0 +    gcnt = 0 +    bcnt = 0 +    for idx, s in enumerate(S): -            R.append(i) +            R.append(idx + 1) +            rcnt += 1 -            G.append(i) +            G.append(idx + 1) +            gcnt += 1 -            B.append(i) -    cnt = 0 -    for i in range(0, n): +            B.append(idx + 1) +            bcnt += 1 +    # print(R) +    # print(G) +    # print(B) +    ans = rcnt * gcnt * bcnt +    # print(ans) +    for i in range(n): +            # print(i, j, k) -                # print(i, j, k) -                cnt = cnt + 1 -    print((len(R) * len(G) * len(B) - cnt)) +                ans -= 1 +    print(ans)