CodeEff/ECCO huggingface dataset:
# Original solution
# this is a good problem !

import sys
si = sys.stdin.readline

d = ['R', 'G', 'B']
ld = [[], [], []]  # letter distribution


def main():
    count = 0
    n = int(si())
    l = list(si())
    l.pop()
    dc = d[:]

    for i in range(n-1, -1, -1):
        if i == n-1:
            if l[i] == 'R':
                ld[0].append(1)
                ld[1].append(0)
                ld[2].append(0)
            elif l[i] == 'G':
                ld[0].append(0)
                ld[1].append(1)
                ld[2].append(0)
            else:
                ld[0].append(0)
                ld[1].append(0)
                ld[2].append(1)
        else:
            if l[i] == 'R':
                ld[0] = [ld[0][0]+1]+ld[0]
                ld[1] = [ld[1][0]+0]+ld[1]
                ld[2] = [ld[2][0]+0]+ld[2]
            elif l[i] == 'G':
                ld[0] = [ld[0][0]+0]+ld[0]
                ld[1] = [ld[1][0]+1]+ld[1]
                ld[2] = [ld[2][0]+0]+ld[2]
            else:
                ld[0] = [ld[0][0]+0]+ld[0]
                ld[1] = [ld[1][0]+0]+ld[1]
                ld[2] = [ld[2][0]+1]+ld[2]

    for i in range(n-2):
        r1 = l[i]
        dc.remove(r1)
        for j in range(i+1, n-1):
            if l[j] in dc:
                r2 = l[j]
                dc.remove(r2)
                count += ld[d.index(dc[0])][j+1]
                if (j+j-i) < n and l[j+j-i] in dc:
                    count -= 1
                dc += [r2]
        dc += [r1]
    print(count)


if __name__ == '__main__':
    main()


# Optimized solution
import sys
si = sys.stdin.readline
so = sys.stdout.write


def main():
    n = int(si())
    s = si()[:-1]
    cnt = s.count('R')*s.count('G')*s.count('B')

    for i in range(n-2):
        for j in range(i+1, n-1):
            k = j+j-i
            if k < n and s[i] != s[j] and s[j] != s[k] and s[k] != s[i]:
                cnt -= 1

    print(cnt)


if __name__ == '__main__':
    main()
# Original solution
import math
import sys
import os
from operator import mul
import bisect

sys.setrecursionlimit(10**7)

def _S(): return sys.stdin.readline().rstrip()
def I(): return int(_S())
def LS(): return list(_S().split())
def LI(): return list(map(int,LS()))

if os.getenv("LOCAL"):
    inputFile = basename_without_ext = os.path.splitext(os.path.basename(__file__))[0]+'.txt'
    sys.stdin = open(inputFile, "r")
INF = float("inf")

N = I()
S = list(_S())
ans = 0

r = []
g = []
b = []

for i,s in enumerate(S):
    if s == 'R':
        r.append(i)
    if s == 'G':
        g.append(i)
    if s == 'B':
        b.append(i)

# j = bisect.bisect_right(<list>,<value>)
# print(r)
# print(g)
# print(b)

for i in r:
    for j in g:
        for k in b:
            tmp = sorted([i,j,k])
            if not tmp[1]-tmp[0]==tmp[2]-tmp[1]:
                ans += 1

# for i in range(N):
#     for j in range(i,N):
#         for k in range(j,N):
#             if S[i]==S[j]:
#                 continue
#             if S[i]==S[k] or S[j]==S[k]:
#                 continue
#             if (j-i) == (k-j):
#                 continue
#             ans += 1

print(ans)

# R G B
# R B G
# G B R
# G R B
# B G R
# B R G

# i   j   k
#  - != -

# RBRBGRBGGB
# 1122233333
# 0000111233
# 0112223334

# B*3
# G*4

# GB系: (2,4), (4,5)
# RB系: (1,3),

# Optimized solution
import math
import sys
import os
from operator import mul
import bisect

sys.setrecursionlimit(10**7)

def _S(): return sys.stdin.readline().rstrip()
def I(): return int(_S())
def LS(): return list(_S().split())
def LI(): return list(map(int,LS()))

if os.getenv("LOCAL"):
    inputFile = basename_without_ext = os.path.splitext(os.path.basename(__file__))[0]+'.txt'
    sys.stdin = open(inputFile, "r")
INF = float("inf")

N = I()
S = list(_S())
ans = 0

r = []
g = []
b = []

for i,s in enumerate(S):
    if s == 'R':
        r.append(i)
    if s == 'G':
        g.append(i)
    if s == 'B':
        b.append(i)

# j = bisect.bisect_right(<list>,<value>)
# print(r)
# print(g)
# print(b)

# for i in r:
#     for j in g:
#         for k in b:
#             tmp = sorted([i,j,k])
#             if not tmp[1]-tmp[0]==tmp[2]-tmp[1]:
#                 ans += 1

ans = len(r)*len(g)*len(b)

for i in range(N):
    for j in range(i,N):
        k = j + (j-i)
        if k > N-1:
            break
        if S[i]==S[j]:
            continue
        if S[i]==S[k] or S[j]==S[k]:
            continue
        ans -= 1

print(ans)

# R G B
# R B G
# G B R
# G R B
# B G R
# B R G

# i   j   k
#  - != -

# RBRBGRBGGB
# 1122233333
# 0000111233
# 0112223334

# B*3
# G*4

# GB系: (2,4), (4,5)
# RB系: (1,3),
# Original solution
import sys
input = sys.stdin.readline

def linput():
    return [int(x) for x in input().split()]

n = int(eval(input()))
s = input().rstrip()

from collections import Counter

r = []
g = []
b = []



for i in range(n):
    if s[i] == "R":
        r.append(i)
    elif s[i] == "G":
        g.append(i)
    else:
        b.append(i)

cr = Counter(r)
cg = Counter(g)
cb = Counter(b)

import bisect
from copy import deepcopy
ans = 0
for i in range(n):
    for j in range(i + 1, n):
        if s[i] == s[j]:
            continue
        ng = j + (j - i)
        if s[i] == "R" and s[j] == "G":
            l = deepcopy(b)
            c = cb
        elif s[i] == "R" and s[j] == "B":
            l = deepcopy(g)
            c = cg
        elif s[i] == "G" and s[j] == "R":
            l = deepcopy(b)
            c = cb
        elif s[i] == "G" and s[j] == "B":
            l = deepcopy(r)
            c = cr
        elif s[i] == "B" and s[j] == "R":
            l = deepcopy(g)
            c = cg
        elif s[i] == "B" and s[j] == "G":
            l = deepcopy(r)
            c = cr
        ans += len(l) - bisect.bisect_right(l, j)
        ans -= c[j + (j - i)]

print(ans)






# Optimized solution
import sys
input = sys.stdin.readline

def linput():
    return [int(x) for x in input().split()]

n = int(eval(input()))
s = input().rstrip()

from collections import Counter

r = [0] * (n + 1)
g = [0] * (n + 1)
b = [0] * (n + 1)



for i in range(1, n + 1):
    if s[i - 1] == "R":
        r[i] = r[i - 1] + 1
    else:
        r[i] = r[i - 1]
    if s[i - 1] == "G":
        g[i] = g[i - 1] + 1
    else:
        g[i] = g[i - 1]
    if s[i - 1] == "B":
        b[i] = b[i - 1] + 1
    else:
        b[i] = b[i - 1]

ans = 0
for i in range(n):
    for j in range(i + 1, n - 1):
        if s[i] == s[j]:
            continue
        ng = j + (j - i) + 1
        if s[i] == "R" and s[j] == "G":
            l = b
        elif s[i] == "R" and s[j] == "B":
            l = g
            #c = cg
        elif s[i] == "G" and s[j] == "R":
            l = b
            #c = cb
        elif s[i] == "G" and s[j] == "B":
            l = r
            #c = cr
        elif s[i] == "B" and s[j] == "R":
            l = g
            #c = cg
        elif s[i] == "B" and s[j] == "G":
            l = r
            #c = cr
        ans += l[n] - l[j + 1]
        if ng < n + 1:
            ans -= l[ng] - l[ng - 1]
        #print(ans)

print(ans)
# Original solution
from itertools import accumulate, dropwhile
from sys import stdin


def main():
    N = int(stdin.readline().rstrip())
    S = stdin.readline().rstrip()
    r_sum, g_sum, b_sum = [list(accumulate(1 if c == x else 0 for c in S)) for x in 'RGB']
    sums = {'R': r_sum, 'G': g_sum, 'B': b_sum}
    r_idx, g_idx, b_idx = [[i for i, c in enumerate(S) if c == x] for x in 'RGB']
    idxs = {'R': sorted(g_idx + b_idx), 'G': sorted(r_idx + b_idx), 'B': sorted(r_idx + g_idx)}

    ans = 0
    for i in range(N - 2):
        idxs[S[i]] = list(dropwhile(lambda x: i > x, idxs[S[i]]))
        for j in idxs[S[i]]:
            other = 'RGB'.replace(S[i], '').replace(S[j], '')
            ans += sums[other][-1] - sums[other][j]
            k = j + (j - i)
            if k < N and S[k] == other:
                ans -= 1
    print(ans)


if __name__ == '__main__':
    main()


# Optimized solution
from sys import stdin


def main():
    N = int(stdin.readline().rstrip())
    S = stdin.readline().rstrip()
    r_count, g_count, b_count = [S.count(x) for x in 'RGB']
    ans = r_count * g_count * b_count
    for i in range(N - 2):
        for j in range(i + 1, N - 1):
            k = j + (j - i)
            if k < N and (S[i] != S[j] and S[j] != S[k] and S[k] != S[i]):
                ans -= 1
    print(ans)


if __name__ == '__main__':
    main()
# Original solution
import sys

sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
printV = lambda x: print(*x, sep="\n")
printH = lambda x: print(" ".join(map(str,x)))
def IS(): return sys.stdin.readline()[:-1]
def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LI1(): return list(map(int1, sys.stdin.readline().split()))
def LII(rows_number): return [II() for _ in range(rows_number)]
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def LLI1(rows_number): return [LI1() for _ in range(rows_number)]

def main():
	n = II()
	s = IS()
	r,g,b=[],[],[]

	def binary_search(lst, K):
		l = 0; r = len(lst);
		while(l+1<r):
			mid = (l+r)//2
	    #下記の操作を書き換えることによって探索条件を変更可能
			if(lst[mid]>K): r=mid
			else: l=mid
		return l

	for i,ss in enumerate(s):
		if ss=='R':
			r.append(i)
		elif ss=='G':
			g.append(i)
		else:
			b.append(i)
	ans=len(r)*len(g)*len(b)
	for rr in r:
		for gg in g:
			a=max(rr,gg)+abs(rr-gg)
			if a in b:
				ans-=1
			a=min(rr,gg)-abs(rr-gg)
			if a in b:
				ans-=1
			if((rr+gg)%2==0):
				a=(rr+gg)//2
				if a in b:
					ans-=1
	print(ans)


if __name__ == '__main__':
	main()


# Optimized solution
import sys

sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
printV = lambda x: print(*x, sep="\n")
printH = lambda x: print(" ".join(map(str,x)))
def IS(): return sys.stdin.readline()[:-1]
def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LI1(): return list(map(int1, sys.stdin.readline().split()))
def LII(rows_number): return [II() for _ in range(rows_number)]
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def LLI1(rows_number): return [LI1() for _ in range(rows_number)]

def main():
	n = II()
	s = IS()
	r,g,b=[],[],[]

	def binary_search(lst, K):
		l = 0; r = len(lst);
		while(l+1<r):
			mid = (l+r)//2
	    #下記の操作を書き換えることによって探索条件を変更可能
			if(lst[mid]>K): r=mid
			else: l=mid
		return l

	for i,ss in enumerate(s):
		if ss=='R':
			r.append(i)
		elif ss=='G':
			g.append(i)
		else:
			b.append(i)
	ans=len(r)*len(g)*len(b)
	for rr in r:
		for gg in g:
			a=max(rr,gg)+abs(rr-gg)
			if(a<n):
				if(s[a]=="B"):
					ans-=1
			a=min(rr,gg)-abs(rr-gg)
			if(a<n and a>=0):
				if(s[a]=="B"):
					ans-=1
			if((rr+gg)%2==0):
				a=(rr+gg)//2
				if(a<n):
					if(s[a]=="B"):
						ans-=1
	print(ans)







if __name__ == '__main__':
	main()
# Original solution
from sys import stdin


def get_result(data):
    # N = int(data[0][0])
    S = data[1][0]
    r_index = [i for i in range(len(S)) if S[i] == 'R']
    g_index = [i for i in range(len(S)) if S[i] == 'G']
    b_index = [i for i in range(len(S)) if S[i] == 'B']
    all_case = len(r_index) * len(g_index) * len(b_index)
    invalid_case = 0
    for i in r_index:
        for j in g_index:
            s_i, s_j = sorted([i, j])
            tmp_max_b = s_j + (s_j-s_i)
            if tmp_max_b in b_index:
                invalid_case += 1
            tmp_min_b = s_i - (s_j-s_i)
            if tmp_min_b in b_index:
                invalid_case += 1
            tmp_mid_b = (s_i + s_j) / 2
            if tmp_mid_b in b_index:
                invalid_case += 1
    return all_case - invalid_case


if __name__ == '__main__':
    raw_data = [val.rstrip() for val in stdin.readlines()]
    data = [list(map(str, val.split(' '))) for val in raw_data]
    result = get_result(data)
    print(result)


# Optimized solution
from sys import stdin


def get_result(data):
    # N = int(data[0][0])
    S = data[1][0]
    r_index = [i for i in range(len(S)) if S[i] == 'R']
    g_index = [i for i in range(len(S)) if S[i] == 'G']
    b_index = set([i for i in range(len(S)) if S[i] == 'B'])
    all_case = len(r_index) * len(g_index) * len(b_index)
    invalid_case = 0
    for i in r_index:
        for j in g_index:
            s_i, s_j = sorted([i, j])
            tmp_max_b = s_j + (s_j-s_i)
            if tmp_max_b in b_index:
                invalid_case += 1
            tmp_min_b = s_i - (s_j-s_i)
            if tmp_min_b in b_index:
                invalid_case += 1
            tmp_mid_b = (s_i + s_j) / 2
            if tmp_mid_b in b_index:
                invalid_case += 1
    return all_case - invalid_case


if __name__ == '__main__':
    raw_data = [val.rstrip() for val in stdin.readlines()]
    data = [list(map(str, val.split(' '))) for val in raw_data]
    result = get_result(data)
    print(result)
# Original solution
e=enumerate
_,s=open(0)
r,g,b=list(map(s.count,'RGB'))
print((r*g*b-sum(c!=d!=s[i-~j]!=c for i,c in e(s)for j,d in e(s[i+2:-1:2]))))

# Optimized solution
e=enumerate
_,s=open(0)
r,g,b=list(map(s.count,'RGB'))
print((r*g*b-sum(c!=d!=s[i+j]!=c for i,c in e(s)for j,d in e(s[i:-1:2]))))
# Original solution
import sys, math

n = int(sys.stdin.readline().strip())
s = sys.stdin.readline().strip()
res = 0

r = []
g = []
b = []
for i, c in enumerate(s):
    if c == "R":
        r.append(i)
    if c == "G":
        g.append(i)
    if c == "B":
        b.append(i)


res = len(r) * len(b) * len(g)

for i in r:
    for j in g:
        for k in b:
            x,y,z = sorted([i,j,k])
            if y-x ==z-y:
                res -= 1
print(res)

# Optimized solution
import sys, math

n = int(sys.stdin.readline().strip())
s = sys.stdin.readline().strip()
res = 0

r = []
g = []
b = []
for i, c in enumerate(s):
    if c == "R":
        r.append(i)
    if c == "G":
        g.append(i)
    if c == "B":
        b.append(i)


res = len(r) * len(b) * len(g)

def bin_find(tar):
    left = 0
    right = len(b)
    while left < right:
        mid = (left+right) // 2
        if b[mid] < tar:
            left = mid+1
        elif b[mid] > tar:
            right = mid
        else:
            return mid
    return -1

for i in r:
    for j in g:
        diff = i - j
        if diff < 0:
            diff = -diff
        if diff % 2 == 0:
            target = diff // 2 + min(i,j)
            if target < n and s[target] == 'B':
                res -= 1
        target = min(i,j) - diff
        if target >= 0 and s[target] == 'B':
            res -= 1
        target = max(i,j) + diff
        if target < n and s[target] == "B":
            res -= 1

print(res)
# Original solution
import sys
import collections


def solve():
    readline = sys.stdin.buffer.readline
    mod = 10 ** 9 + 7
    n = int(readline())
    s = str(readline().rstrip().decode('utf-8'))
    c = collections.Counter(list(s))
    left = collections.defaultdict(int)
    cnt = 0
    for i in range(n - 2):
        left[s[i]] += 1
        mid = collections.defaultdict(int)
        for k, v in list(left.items()):
            mid[k] += v
        for j in range(i + 1, n - 1):
            mid[s[j]] += 1
            if s[i] != s[j]:
                if [s[i], s[j]].count("R") == 0:
                    cnt += c["R"] - mid["R"]
                    if j + j - i < n:
                        if s[j+j-i] == "R":
                            cnt -= 1
                elif [s[i], s[j]].count("G") == 0:
                    cnt += c["G"] - mid["G"]
                    if j + j - i < n:
                        if s[j+j-i] == "G":
                            cnt -= 1
                elif [s[i], s[j]].count("B") == 0:
                    cnt += c["B"] - mid["B"]
                    if j + j - i < n:
                        if s[j+j-i] == "B":
                            cnt -= 1
    print(cnt)


if __name__ == '__main__':
    solve()


# Optimized solution
import sys


def solve():
    readline = sys.stdin.buffer.readline
    mod = 10 ** 9 + 7
    n = int(readline())
    s = str(readline().rstrip().decode('utf-8'))
    r = s.count("R")
    g = s.count("G")
    b = s.count("B")
    cnt = r * g * b
    for i in range(n - 2):
        for j in range(i + 1, n - 1):
            k = j + j - i
            if k < n:
                if s[i] != s[j] and s[j] != s[k] and s[i] != s[k]:
                    cnt -= 1
    print(cnt)


if __name__ == '__main__':
    solve()
# Original solution
from sys import stdin, stdout
def main():
    N=int(stdin.readline())
    S=stdin.readline().rstrip()
    R, G, B = [], [], []
    for i, c in enumerate(S):
        if c == 'R':
            R.append(i)
        elif c == 'G':
            G.append(i)
        else:
            B.append(i)
    cnt = 0
    for ri in R:
        for gi in G:
            for bi in B:
                if abs(gi-ri) != abs(bi-gi) and abs(ri-bi) != abs(bi-gi) and abs(ri-bi) != abs(ri-gi):
                    cnt+=1

    stdout.write(str(cnt)+"\n")

main()


# Optimized solution
from sys import stdin, stdout
def main():
    N=int(stdin.readline())
    S=stdin.readline().rstrip()
    R, G, B = set(), set(), set()
    for i, c in enumerate(S):
        if c == 'R':
            R.add(i)
        elif c == 'G':
            G.add(i)
        else:
            B.add(i)
    cnt, total = 0, len(R) * len(G) * len(B)
    for ri in R:
        for gi in G:
            if abs(ri-gi)+gi in B:
                cnt += 1
            if abs(ri-gi)+ri in B:
                cnt += 1
    for ri in G:
        for gi in B:
            if abs(ri-gi)+gi in R:
                cnt += 1
            if abs(ri-gi)+ri in R:
                cnt += 1
    for ri in R:
        for gi in B:
            if abs(ri-gi)+gi in G:
                cnt += 1
            if abs(ri-gi)+ri in G:
                cnt += 1

    stdout.write(str(total-cnt)+"\n")

main()
# Original solution
import sys

N = int(sys.stdin.readline().rstrip())
S = sys.stdin.readline().rstrip()

if len(set(S)) == 1 or N < 3:
    print((0))
    sys.exit()

ans = []
for i in range(N - 2):
    a = S[i]
    for j in range(i + 1, N - 1):
        b = S[j]
        if a == b:
            continue
        jtoi = j - i
        for k in range(j + 1, N):
            c = S[k]
            if a == c or b == c:
                continue
            ktoj = k - j
            if jtoi != ktoj:
                ans.append(None)

print((len(ans)))

# Optimized solution
import sys

N = int(sys.stdin.readline().rstrip())
S = sys.stdin.readline().rstrip()

if len(set(S)) == 1 or N < 3:
    print((0))
    sys.exit()

Rs = S.count("R")
Gs = S.count("G")
Bs = S.count("B")
ans = Rs * Gs * Bs


for i in range(N - 1):
    for j in range(i + 1, N):
        k = j + (j - i)
        if k >= N: break
        if S[i] != S[j] and S[j] != S[k] and S[k] != S[i]:
            ans -= 1
print(ans)
# Original solution
#!/usr/bin/env pypy3
# n,m = map(int,sys.stdin.readline().split())
# a = list(map(int,sys.stdin.readline().split()))
# a = [sys.stdin.readline() for s in range(n)]
# s = sys.stdin.readline().rstrip()
# n = int(sys.stdin.readline())
# d = collections.defaultdict(list)
# import math
# from functools import reduce
import sys
sys.setrecursionlimit(15000)

n = int(sys.stdin.readline())
s = sys.stdin.readline().rstrip()
d = {"R":[],"G":[],"B":[]}
for i in range(n):
    d[s[i]].append(i)
s = 0
s = sum(1 for a in d["R"] for b in d["G"] for c in d["B"] if abs(a-b) != abs(b-c) and abs(a-c) != abs(c-b) and abs(b-a) != abs(a-c))
print(s)

# Optimized solution
#!/usr/bin/env pypy3
# n,m = map(int,sys.stdin.readline().split())
# a = list(map(int,sys.stdin.readline().split()))
# a = [sys.stdin.readline() for s in range(n)]
# s = sys.stdin.readline().rstrip()
# n = int(sys.stdin.readline())
# d = collections.defaultdict(list)
# import math
# from functools import reduce
import sys
sys.setrecursionlimit(15000)

n = int(sys.stdin.readline())
s = sys.stdin.readline().rstrip()
d = {"R":[],"G":[],"B":[]}
sb = set()
for i in range(n):
    d[s[i]].append(i)
    if s[i]=="B":
        sb.add(i)
s = 0
#s = sum(1 for a in d["R"] for b in d["G"] for c in d["B"] if abs(a-b) != abs(b-c) and abs(a-c) != abs(c-b) and abs(b-a) != abs(a-c))
#s = len(d["R"])*len(d["G"])*len(d["B"])-sum(1 for a in d["R"] for b in d["G"] for c in d["B"] if abs(a-b) == abs(b-c) or abs(a-c) == abs(c-b) or abs(b-a) == abs(a-c))
for a in d["R"]:
    for b in d["G"]:
        s += len(d["B"])
        if 2*b-a in sb:
            s -= 1
        if 2*a-b in sb:
            s -= 1
        if (a+b)%2 == 0 and (a+b)//2 in sb:
            s -= 1
print(s)
# Original solution
import sys
import math
from functools import reduce

# 入力を整数に変換して受け取る
def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def MI1(): return map(int1, sys.stdin.readline().split())
# 入力全てを整数に変換したものの配列を受け取る
def LI(): return list(map(int, sys.stdin.readline().split()))
# 入力全てを整数に変換して1引いたものの配列を受け取る
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def SR(): return sys.stdin.readline().rstrip()

ascii_lowercase = 'abcdefghijklmnopqrstuvwxyz'
ascii_uppercase = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
ascii_uppercase2 = 'ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZ'

# リストを改行区切りで出力する
p2D = lambda x: print(*x, sep="\n")
p2E = lambda x: print(''.join(x))
p2S = lambda x: print(*x, sep=" ")

def gcd_list(numbers):
    return reduce(math.gcd, numbers)

N = II()
S = input()

ans = 0
for i in range(1, N-2):
    for j in range(1+i, N):
        #if j <= i:
        #    continue
        for k in range(1+j, N+1):
            #if k <= j:
            #    continue
            if not(j-i == k-j or S[i-1] == S[j-1] or S[i-1] == S[k-1] or S[k-1] == S[j-1]):
                ans+=1
print(ans)


# Optimized solution
import sys
import math
from functools import reduce

# 入力を整数に変換して受け取る
def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def MI1(): return map(int1, sys.stdin.readline().split())
# 入力全てを整数に変換したものの配列を受け取る
def LI(): return list(map(int, sys.stdin.readline().split()))
# 入力全てを整数に変換して1引いたものの配列を受け取る
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def SR(): return sys.stdin.readline().rstrip()

ascii_lowercase = 'abcdefghijklmnopqrstuvwxyz'
ascii_uppercase = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
ascii_uppercase2 = 'ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZ'

# リストを改行区切りで出力する
p2D = lambda x: print(*x, sep="\n")
p2E = lambda x: print(''.join(x))
p2S = lambda x: print(*x, sep=" ")

def gcd_list(numbers):
    return reduce(math.gcd, numbers)

N = int(input())
S = input()
ans = S.count("R") * S.count("G") * S.count("B")
for i in range(N-2):
  for j in range(i+1,N-1):
    k=2*j-i
    if k>=N:
      continue
    if S[i]!=S[j] and S[j]!=S[k] and S[k]!=S[i]:
      ans-=1
print(ans)