### BUGGY CODE ###

import math


def main():
    n = int(input())
    s = input()

    rs = []
    gs = []
    bs = []
    for i in range(n):
        if s[i] == "R":
            rs.append(i)
        elif s[i] == "G":
            gs.append(i)
        else:
            bs.append(i)

    cnt = 0
    for ri in rs:
        for gi in gs:
            for bi in bs:
                if ri < gi < bi:
                    if bi - gi != gi - ri:
                        cnt += 1
                elif ri < bi < gi:
                    if gi - bi != bi - ri:
                        cnt += 1
                elif bi < gi < ri:
                    if ri - gi != gi - bi:
                        cnt += 1
                elif bi < ri < gi:
                    if gi - ri != ri - bi:
                        cnt += 1
                elif gi < ri < bi:
                    if bi - ri != ri - gi:
                        cnt += 1
                else:
                    if ri - bi != bi - gi:
                        cnt += 1

    print(cnt)


main()


### FIXED CODE ###

import math


def main():
    n = int(input())
    s = input()

    rs = []
    gs = []
    bs = {}
    for i in range(n):
        if s[i] == "R":
            rs.append(i)
        elif s[i] == "G":
            gs.append(i)
        else:
            bs.setdefault(i, 1)

    cnt = 0

    for ri in rs:
        for gi in gs:
            df = abs(gi - ri)
            rr = max(gi,ri) + df
            ll = min(gi,ri) - df
            mm = -1
            if df % 2 == 0:
                mm = int((gi + ri)/2)

            if rr in bs:
                cnt +=1
            if mm in bs:
                cnt+=1
            if ll in bs:
                cnt+=1

            # if ri < gi:
            #     df = gi - ri
            #     rr = gi + df
            #     ll = ri - df
            #     mm = -1
            #     if df % 2 == 0:
            #         mm = ri + int(df / 2)
            #
            #     lim = rr if rr <= (n - 1) else max(mm, ll)
            #
            #     if lim < 0:
            #         continue
            #
            #     for bi in bs:
            #         if bi < ll:
            #             continue
            #         if lim < bi:
            #             break
            #
            #         if bi == ll:
            #             cnt += 1
            #         elif bi == mm:
            #             cnt += 1
            #         elif bi == rr:
            #             cnt += 1
            #
            # else:
            #     df = ri - gi
            #     rr = ri + df
            #     ll = gi - df
            #     mm = -1
            #     if df % 2 == 0:
            #         mm = gi + int(df / 2)
            #
            #     lim = rr if rr <= (n - 1) else max(mm, ll)
            #
            #     if lim < 0:
            #         continue
            #     for bi in bs:
            #         if bi < ll:
            #             continue
            #         if lim < bi:
            #             break
            #
            #         if bi == ll:
            #             cnt += 1
            #         elif bi == mm:
            #             cnt += 1
            #         elif bi == rr:
            #             cnt += 1
    all_cnt = len(rs) * len(gs) * len(bs)

    print(all_cnt - cnt)


main()