import sys

input = sys.stdin.readline

from itertools import *

from functools import *

from collections import *

from heapq import heapify, heappop, heappush, heappushpop

from numba import njit



INF = float('inf')

NIL = - 1





N = int(eval(input()))

S = input().rstrip()



r_count = S.count('R')

g_count = S.count('G')

b_count = S.count('B')



ret = 0

for i in range(N):

    for d in range(N):

        j = i + d

        k = j + d

        if k >= N:

            break

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

            ret += 1



ans = r_count * g_count * b_count - ret

print(ans)

import sys

input = sys.stdin.readline

from itertools import *

from functools import *

from collections import *

from heapq import heapify, heappop, heappush, heappushpop



INF = float('inf')

NIL = - 1





N = int(eval(input()))

S = input().rstrip()



r_count = S.count('R')

g_count = S.count('G')

b_count = S.count('B')



# ret = 0

# for i in range(N):

#     for d in range(N):

#         j = i + d

#         k = j + d

#         if k >= N:

#             break

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

#             ret += 1



ret = 0

for i in range(N):

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

        k = 2 * j - i

        if k >= N:

            break

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

            ret += 1





ans = r_count * g_count * b_count - ret

print(ans)

import sys

input = sys.stdin.readline
from itertools import *
from functools import *
from collections import *
from heapq import heapify, heappop, heappush, heappushpop
from numba import njit

INF = float("inf")
NIL = -1
N = int(eval(input()))
S = input().rstrip()
r_count = S.count("R")
g_count = S.count("G")
b_count = S.count("B")
ret = 0
for i in range(N):
    for d in range(N):
        j = i + d
        k = j + d
        if k >= N:
            break
        if S[i] != S[j] and S[j] != S[k] and S[k] != S[i]:
            ret += 1
ans = r_count * g_count * b_count - ret
print(ans)

import sys

input = sys.stdin.readline
from itertools import *
from functools import *
from collections import *
from heapq import heapify, heappop, heappush, heappushpop

INF = float("inf")
NIL = -1
N = int(eval(input()))
S = input().rstrip()
r_count = S.count("R")
g_count = S.count("G")
b_count = S.count("B")
# ret = 0
# for i in range(N):
#     for d in range(N):
#         j = i + d
#         k = j + d
#         if k >= N:
#             break
#         if S[i] != S[j] and S[j] != S[k] and S[k] != S[i]:
#             ret += 1
ret = 0
for i in range(N):
    for j in range(i + 1, N):
        k = 2 * j - i
        if k >= N:
            break
        if S[i] != S[j] and S[j] != S[k] and S[k] != S[i]:
            ret += 1
ans = r_count * g_count * b_count - ret
print(ans)

-from numba import njit +# ret = 0 +# for i in range(N): +#     for d in range(N): +#         j = i + d +#         k = j + d +#         if k >= N: +#             break +#         if S[i] != S[j] and S[j] != S[k] and S[k] != S[i]: +#             ret += 1 -    for d in range(N): -        j = i + d -        k = j + d +    for j in range(i + 1, N): +        k = 2 * j - i