### BUGGY CODE ###

"""
import random
import functools
import copy
import bisect
import array
import re
import collections
import heapq
import fractions
import itertools
import string
import math
from operator import itemgetter as ig
from bisect import bisect_left, bisect_right, insort_left, insort_right
from itertools import permutations, combinations, product, accumulate, groupby
from heapq import heappush, heappop
from collections import deque, defaultdict, Counter
import sys
sys.setrecursionlimit(10 ** 7)
# import numpy as np

inf = 10 ** 20
INF = float("INF")
mod = 10 ** 9 + 7
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]
ddn = dd + [(-1, 1), (1, 1), (1, -1), (-1, -1)]
ddn9 = ddn + [(0, 0)]
'''for dx, dy in dd:
        nx = j + dx; ny = i + dy
            if 0 <= nx < w and 0 <= ny < h:'''
"""
from collections import Counter
import sys
sys.setrecursionlimit(10 ** 7)


def wi(): return list(map(int, sys.stdin.readline().split()))
# WideIntPoint


def wip(): return [int(x) - 1 for x in sys.stdin.readline().split()]


def ws(): return sys.stdin.readline().split()


def si(): return int(sys.stdin.readline())  # SingleInt


def ss(): return input()


def hi(n): return [si() for _ in range(n)]


def hs(n): return [ss() for _ in range(n)]  # HeightString


def s_list(): return list(input())


def mi(n): return [wi() for _ in range(n)]  # MatrixInt


def mip(n): return [wip() for _ in range(n)]


def ms(n): return [ws() for _ in range(n)]


def num_grid(n): return [[int(i) for i in sys.stdin.readline().split()[
    0]] for _ in range(n)]  # NumberGrid


def grid(n): return [s_list() for _ in range(n)]


def gcd(a, b):
    while b:
        a, b = b, a % b
    return a


def main():
    N = si()
    S = ss()
    ans = 0
    for i in range(N-2):
        for j in range(i+1, N-1):
            if S[i] == S[j]:
                continue
            else:
                s = S[j+1:N]
                clist = Counter(s)
                if S[i] == 'R' and S[j] == 'B':
                    ans += clist['G']
                    if j-i+j <= N-1:
                        if S[j-i+j] == 'G':
                            ans -= 1
                elif S[i] == 'R' and S[j] == 'G':
                    ans += clist['B']
                    if j-i+j <= N-1:
                        if S[j-i+j] == 'B':
                            ans -= 1
                elif S[i] == 'B' and S[j] == 'R':
                    ans += clist['G']
                    if j-i+j <= N-1:
                        if S[j-i+j] == 'G':
                            ans -= 1
                elif S[i] == 'B' and S[j] == 'G':
                    ans += clist['R']
                    if j-i+j <= N-1:
                        if S[j-i+j] == 'R':
                            ans -= 1
                elif S[i] == 'G' and S[j] == 'B':
                    ans += clist['R']
                    if j-i+j <= N-1:
                        if S[j-i+j] == 'R':
                            ans -= 1
                elif S[i] == 'G' and S[j] == 'R':
                    ans += clist['B']
                    if j-i+j <= N-1:
                        if S[j-i+j] == 'B':
                            ans -= 1
    print(ans)


if __name__ == '__main__':
    main()


### FIXED CODE ###

"""
import random
import functools
import copy
import bisect
import array
import re
import collections
import heapq
import fractions
import itertools
import string
import math
from operator import itemgetter as ig
from bisect import bisect_left, bisect_right, insort_left, insort_right
from itertools import permutations, combinations, product, accumulate, groupby
from heapq import heappush, heappop
from collections import deque, defaultdict, Counter
import sys
sys.setrecursionlimit(10 ** 7)
# import numpy as np

inf = 10 ** 20
INF = float("INF")
mod = 10 ** 9 + 7
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]
ddn = dd + [(-1, 1), (1, 1), (1, -1), (-1, -1)]
ddn9 = ddn + [(0, 0)]
'''for dx, dy in dd:
        nx = j + dx; ny = i + dy
            if 0 <= nx < w and 0 <= ny < h:'''
"""
from collections import Counter
import sys
sys.setrecursionlimit(10 ** 7)


def wi(): return list(map(int, sys.stdin.readline().split()))
# WideIntPoint


def wip(): return [int(x) - 1 for x in sys.stdin.readline().split()]


def ws(): return sys.stdin.readline().split()


def si(): return int(sys.stdin.readline())  # SingleInt


def ss(): return input()


def hi(n): return [si() for _ in range(n)]


def hs(n): return [ss() for _ in range(n)]  # HeightString


def s_list(): return list(input())


def mi(n): return [wi() for _ in range(n)]  # MatrixInt


def mip(n): return [wip() for _ in range(n)]


def ms(n): return [ws() for _ in range(n)]


def num_grid(n): return [[int(i) for i in sys.stdin.readline().split()[
    0]] for _ in range(n)]  # NumberGrid


def grid(n): return [s_list() for _ in range(n)]


def gcd(a, b):
    while b:
        a, b = b, a % b
    return a


def main():
    N = si()
    S = ss()
    rr = 0
    gg = 0
    bb = 0
    ans = 0
    for i in range(N):
        if S[i] == 'R':
            rr += 1
        elif S[i] == 'B':
            bb += 1
        elif S[i] == 'G':
            gg += 1
    ans = rr*gg*bb
    for i in range(N-2):
        for j in range(i+1, N-1):
            if S[i] != S[j] and 2*j-i < N and S[i] != S[2*j-i] and S[j] != S[2*j-i]:
                ans -= 1
    print(ans)


if __name__ == '__main__':
    main()