### 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
    lrs = len(_rs)
    lgs = len(_gs)
    lbs = len(_bs)
    rs = _rs
    gs = _gs
    bs = _bs

    if lrs < lgs < lbs:
        rs = _rs
        gs = _gs
        bs = _bs
    elif lrs < lbs < lgs:
        rs = _rs
        gs = _bs
        bs = _gs
    elif lgs < lrs < lbs:
        rs = _gs
        gs = _rs
        bs = _bs
    elif lgs < lbs < lrs:
        rs = _gs
        gs = _bs
        bs = _rs
    elif lbs < lrs < lgs:
        rs = _bs
        gs = _rs
        bs = _gs
    elif lbs < lgs < lrs:
        rs = _bs
        gs = _gs
        bs = _rs

    for ri in rs:
        for gi in gs:
            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()


### 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()