CodeEff/ECCO huggingface dataset:
# Original solution
M = 1299710
isPrime = [1]*M
isPrime[0],isPrime[1] = 0,0
lp = [0]*M; p = []
b = 2
for i in range(2,M):
    if isPrime[i]:
        for j in range(i*i,M,i):
            isPrime[j] = 0
        p.append(i)
        b = i
    lp[i] = b
while 1:
    n = eval(input())
    if n==0: break
    print(p[p.index(lp[n])+1]-lp[n] if lp[n]!=n else "0")
    

# Optimized solution
M = 1299710
isPrime = [1]*M
isPrime[0],isPrime[1] = 0,0
for i in range(2,M):
    if isPrime[i]:
        for j in range(i*i,M,i):
            isPrime[j] = 0
while 1:
    n = eval(input())
    if n==0: break
    p = q = n
    if isPrime[n]:
        print(0)
    else:
        while isPrime[p]==0:p-=1
        while isPrime[q]==0:q+=1
        print(q-p)
# Original solution
a,b,c,d,e=[int(eval(input())) for _ in range(5)]
if a<0:
    print((-a*c+d+b*e))
else:
    print(((b-a)*e))

# Optimized solution
a,b,c,d,e=[int(eval(input())) for _ in range(5)]
print((-a*c+d+b*e if a<0 else (b-a)*e))
# Original solution
def count_bigger(a, b):
    i = j = 0
    c = []
    while i < len(a) and j < len(b):
        if a[i] >= b[j]:
            j += 1
            continue
        c.append(len(b) - j)
        i += 1
    if len(c) < len(a):
        c += [0] * (len(a) - len(c))
    for i in range(len(c) - 1, 0, -1):
        c[i - 1] += c[i]
    return c


def f(a, b, c):
    bc = count_bigger(b, c)
    i = j = ans = 0
    while i < len(a) and j < len(b):
        if a[i] >= b[j]:
            j += 1
            continue
        ans += bc[j] - len(set(c) & set(2 * _b - a[i] for _b in b[j:]))
        i += 1
    return ans


def solve(string):
    n, s = string.split()
    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)
    return str(f(r, g, b) + f(r, b, g) + f(b, r, g) + f(b, g, r) + f(g, r, b) + f(g, b, r))


if __name__ == '__main__':
    import sys
    print((solve(sys.stdin.read().strip())))


# Optimized solution
from itertools import product


def solve(string):
    n, s = string.split()
    r, g, b = [], [], []
    r2, g2, b2 = set([]), set([]), set([])
    for i, _s in enumerate(s):
        if _s == "R":
            r.append(i)
            r2.add(2 * i)
        if _s == "G":
            g.append(i)
            g2.add(2 * i)
        if _s == "B":
            b.append(i)
            b2.add(2 * i)
    ans = len(r) * len(g) * len(b)
    for i, j in product(r, g):
        ans -= 1 if i + j in b2 else 0
    for i, j in product(g, b):
        ans -= 1 if i + j in r2 else 0
    for i, j in product(b, r):
        ans -= 1 if i + j in g2 else 0
    return str(ans)


if __name__ == '__main__':
    import sys
    print((solve(sys.stdin.read().strip())))
# Original solution
from sys import stdin
n = int(eval(input()))
s = stdin.readline()
rind = []
gind = []
bind = []
ans = 0
for i in range(n):
    if s[i] == "R":
        rind.append(i+1)
    elif s[i] == "G":
        gind.append(i+1)
    else:
        bind.append(i+1)
for i in range(len(rind)):
    for j in range(len(gind)):
        for k in range(len(bind)):
            if (rind[i]+gind[j]!=2*bind[k])and(gind[j]+bind[k]!=2*rind[i])and(bind[k]+rind[i]!=2*gind[j]):
                ans += 1
print(ans)


# Optimized solution
from sys import stdin
n = int(eval(input()))
s = stdin.readline()
r = 0
g = 0 
b = 0
for i in range(n):
    if s[i] == "R":
        r += 1
    elif s[i] == "G":
        g += 1
    else:
        b += 1
count1 = r*g*b
count2 = 0
for i in range(0,n-2):
    for j in range(i+1,n-1):
        if 2*j-i<=n-1:
            if (s[i] != s[j])and(s[i] != s[2*j-i])and(s[j] != s[2*j-i]):
               count2 += 1
print((count1-count2))
# Original solution
from math import gcd

n=int(input().strip())
s=input().strip()

c = 0
for i in range(n-2):
    for j in range(i+1,n-1):
        if s[i] == s[j]:
            continue
        for k in range(j+1,n):
            if j - i == k - j:
                continue
            if s[i] == s[k]:
                continue
            if s[j] == s[k]:
                continue
            c += 1
print(c)


# Optimized solution
from math import gcd

n=int(input().strip())
s=input().strip()

r = 0
g = 0
for i in s:
    if i == 'R':
        r += 1
    elif i == 'G':
        g += 1
ans = r * g * (n - r - g)

for i in range(0, n-1):
    for d in range(1, (n - i + 1) // 2):
        if s[i] != s[i+d] and s[i] != s[i+d+d] and s[i+d] != s[i+d+d]:
            ans -= 1
print(ans)
# Original solution
# D - RGB Triplets
from collections import defaultdict


def main():
    _ = int(eval(input()))
    S = input().rstrip()
    indices = defaultdict(set)
    for i, c in enumerate(S):
        indices[c].add(i)
    cnt = len(indices["R"]) * len(indices["G"]) * len(indices["B"])
    for c1, c2, c3 in ["RGB", "GBR", "BRG"]:
        cnt -= sum(
            (i + j) % 2 == 0 and (i + j) // 2 in indices[c3]
            for i in indices[c1]
            for j in indices[c2]
        )
    print(cnt)


if __name__ == "__main__":
    main()


# Optimized solution
# D - RGB Triplets
from collections import defaultdict


def main():
    _ = int(eval(input()))
    S = input().rstrip()
    indices = defaultdict(set)
    for i, c in enumerate(S):
        indices[c].add(2 * i)
    cnt = len(indices["R"]) * len(indices["G"]) * len(indices["B"])
    for c1, c2, c3 in ["RGB", "GBR", "BRG"]:
        cnt -= sum(
            (i + j) // 2 in indices[c3] for i in indices[c1] for j in indices[c2]
        )
    print(cnt)


if __name__ == "__main__":
    main()
# Original solution
# D - RGB Triplets
from collections import defaultdict


def main():
    _, S = open(0).read().split()
    indices, doubled_indices = defaultdict(list), defaultdict(set)
    for i, c in enumerate(S):
        indices[c].append(i)
        doubled_indices[c].add(2 * i)
    cnt = S.count("R") * S.count("G") * S.count("B")
    for x, y, z in ["RGB", "GBR", "BRG"]:
        cnt -= sum(i + j in doubled_indices[z] for i in indices[x] for j in indices[y])
    print(cnt)


if __name__ == "__main__":
    main()


# Optimized solution
# D - RGB Triplets
from collections import defaultdict


def main():
    _, S = open(0).read().split()
    indices, doubled_indices = defaultdict(list), defaultdict(set)
    for i, c in enumerate(S):
        indices[c].append(i)
        doubled_indices[c].add(2 * i)

    cnt = len(indices["R"]) * len(indices["G"]) * len(indices["B"])
    for x, y, z in ("RGB", "RBG", "BGR"):
        cnt -= sum(i + j in doubled_indices[z] for i in indices[x] for j in indices[y])
    print(cnt)


if __name__ == "__main__":
    main()
# Original solution
from sys import stdin
import bisect
def main():
    #入力
    readline=stdin.readline
    N=int(readline())
    S=readline().strip()

    res=0

    R=[]
    G=[]
    B=[]
    flags=[""]*N
    for i in range(N):
        if S[i]=="R":
            R.append(i)
            flags[i]="R"
        elif S[i]=="G":
            G.append(i)
            flags[i]="G"
        else:
            B.append(i)
            flags[i]="B"
    
    #Bが最後
    for i in range(len(R)):
        for j in range(len(G)):
            n=max(R[i],G[j])
            k=bisect.bisect_left(B,n)
            res+=len(B)-k
            if n+n-min(R[i],G[j])<N:
                if flags[n+n-min(R[i],G[j])]=="B":
                    res-=1
    
    for i in range(len(R)):
        for j in range(len(B)):
            n=max(R[i],B[j])
            k=bisect.bisect_left(G,n)
            res+=len(G)-k
            if n+n-min(R[i],B[j])<N:
                if flags[n+n-min(R[i],B[j])]=="G":
                    res-=1

    for i in range(len(B)):
        for j in range(len(G)):
            n=max(B[i],G[j])
            k=bisect.bisect_left(R,n)
            res+=len(R)-k
            if n+n-min(B[i],G[j])<N:
                if flags[n+n-min(B[i],G[j])]=="R":
                    res-=1

    print(res)
if __name__=="__main__":
    main()

# Optimized solution
from sys import stdin
def main():
    #入力
    readline=stdin.readline
    n=int(readline())
    s=readline().strip()
    ans=s.count("R")*s.count("G")*s.count("B")

    for i in range(n):
        for j in range(i+1,n):
            k=2*j-i
            if k>=n: break
            x=s[i]
            y=s[j]
            z=s[k]
            if x!=y and y!=z and z!=x:
                ans-=1

    print(ans)

if __name__=="__main__":
    main()
# Original solution
n,s=open(0);n=int(n);c=s.count;print((c('R')*c('G')*c('B')-sum(len(set(s[i:j+1:j-i>>1]))>2for i in range(n)for j in range(i+2,n,2))))

# Optimized solution
n,s=open(0);n=int(n);c=s.count;print((c('R')*c('G')*c('B')-sum(s[i]!=s[j]!=s[i+j>>1]!=s[i]for i in range(n)for j in range(i+2,n,2))))
# Original solution
n,s=open(0);n=int(n);c=s.count;print((c('R')*c('G')*c('B')-sum(s[i]!=s[j]!=s[i+j>>1]!=s[i]for i in range(n)for j in range(i+2,n,2))))

# Optimized solution
n,s=open(0);n=int(n);c=s.count;print((c('R')*c('G')*c('B')-sum(s[i]!=s[i+j>>1]!=s[j]!=s[i]for i in range(n)for j in range(i+2,n,2))))
# Original solution
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
# from fractions import gcd
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from functools import reduce
from bisect import bisect_left, insort_left
from heapq import heapify, heappush, heappop

INPUT = lambda: sys.stdin.readline().rstrip()
INT = lambda: int(INPUT())
MAP = lambda: list(map(int, INPUT().split()))
S_MAP = lambda: list(map(str, INPUT().split()))
LIST = lambda: list(map(int, INPUT().split()))
S_LIST = lambda: list(map(str, INPUT().split()))

sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7


def main():
    N = INT()
    S = INPUT()

    cnt = 0
    for i, j, k in list(combinations(list(range(N)), 3)):
        if j - i == k - j: continue
        if S[i] == S[j] or S[j] == S[k] or S[k] == S[i]: continue
        cnt += 1

    print(cnt)


if __name__ == '__main__':
    main()


# Optimized solution
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
# from fractions import gcd
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from functools import reduce
from bisect import bisect_left, insort_left
from heapq import heapify, heappush, heappop

INPUT = lambda: sys.stdin.readline().rstrip()
INT = lambda: int(INPUT())
MAP = lambda: list(map(int, INPUT().split()))
S_MAP = lambda: list(map(str, INPUT().split()))
LIST = lambda: list(map(int, INPUT().split()))
S_LIST = lambda: list(map(str, INPUT().split()))

sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7


def main():
    N = INT()
    S = INPUT()

    R = []
    G = []
    B = []
    for i, s in enumerate(S):
        if s == 'R': R.append(i + 1)
        elif s == 'G': G.append(i + 1)
        else: B.append(i + 1)

    cnt = 0
    for r in R:
        for g in G:
            for b in B:
                i = min(r, g, b)
                k = max(r, g, b)
                for x in [r, g, b]:
                    if i < x < k: j = x
                if j - i != k - j: cnt += 1

    print(cnt)


if __name__ == '__main__':
    main()
# Original solution
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**6)

def inp():
    return int(input())
def inps():
    return input().rstrip()
def inpl():
    return list(map(int, input().split()))
def _debug(obj):
    print(obj, file=sys.stderr)

# import decimal
# from decimal import Decimal
# decimal.getcontext().prec = 10

# from heapq import heappush, heappop, heapify
# import math
# from math import gcd
# import itertools as it
# import collections
# from collections import deque 

# ---------------------------------------

N = inp()
S = inps()

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

for i in range(N):
    if S[i] == "R":
        r.append(i)
    if S[i] == "G":
        g.append(i)
    if S[i] == "B":
        b.append(i)

ans = 0
for i in r:
    for j in g:
        for k in b:
            if abs(i - j) != abs (j - k) and abs(i - j) != abs (i - k) and abs(i - k) != abs (j - k):
                ans += 1
print(ans)


# Optimized solution
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**6)

def inp():
    return int(input())
def inps():
    return input().rstrip()
def inpl():
    return list(map(int, input().split()))
def _debug(obj):
    print(obj, file=sys.stderr)

# import decimal
# from decimal import Decimal
# decimal.getcontext().prec = 10

# from heapq import heappush, heappop, heapify
# import math
# from math import gcd
# import itertools as it
# import collections
# from collections import deque 

# ---------------------------------------

N = inp()
S = inps()

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

for i in range(N):
    if S[i] == "R":
        r.append(i)
    if S[i] == "G":
        g.append(i)
    if S[i] == "B":
        b.append(i)

ans = 0
for i in r:
    for j in g:
        m = i
        n = j
        if m > n:
            m, n = n, m
        sa = abs(m - n)
        ans += len(b)
        if m - sa >= 0 and S[m - sa] == "B":
            ans -= 1
        if n + sa < N and S[n + sa] == "B":
            ans -= 1
        if sa % 2 == 0 and S[m + sa//2] == "B":
            ans -= 1
print(ans)
# Original solution
import sys
stdin = sys.stdin
sys.setrecursionlimit(10 ** 7)

i_i = lambda: int(i_s())
i_l = lambda: list(map(int, stdin.readline().split()))
i_s = lambda: stdin.readline().rstrip()

N = i_i()
S = i_s()

ans = 0
for i in range(N):
    for j in range(i, N):
        if S[i] != S[j]:
            if S[i] == 'R' and S[j] == 'G':
                tmp = 'B'
            elif S[i] == 'R' and S[j] == 'B':
                tmp = 'G'
            elif S[i] == 'G' and S[j] == 'R':
                tmp = 'B'
            elif S[i] == 'B' and S[j] == 'R':
                tmp = 'G'
            else:
                tmp = 'R'
            
            if tmp in S[j:]:
                for k in range(j, N):
                    if S[k] == tmp and k - j != j - i:
                        ans += 1

print(ans)

# Optimized solution
import sys
stdin = sys.stdin
sys.setrecursionlimit(10 ** 7)

i_i = lambda: int(i_s())
i_l = lambda: list(map(int, stdin.readline().split()))
i_s = lambda: stdin.readline().rstrip()

N = i_i()
S = i_s()

r = S.count('R')
g = S.count('G')
b = S.count('B')

cnt = 0
for i in range(N):
    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[i] != S[k]:
            cnt += 1

print(((r * g * b) - cnt))
# Original solution

def main():
    import sys
    input = sys.stdin.readline
    #n = int(input())
    #l = list(map(int, input().split()))
    '''
    A=[]
    B=[]
    for i in range():
        a, b = map(int, input().split())
        A.append(a)
        B.append(b)'''

    n=int(eval(input()))
    s=input().rstrip('\n')
    from collections import Counter
    a=Counter(s)
    #print(a)
    num=a["R"]*a["G"]*a["B"]
    #print(num)
    for i in range(n-2):
        for j in range(1,n//2+1):
            if i+2*j<n:
                #print([i,i+j,i+2*j,s[i], s[i+j], s[i+2*j]])
                if set([s[i],s[i+j],s[i+2*j]])==set(["R","G","B"]):
                    num-=1
    print(num)

if __name__ == "__main__":
    main()

# Optimized solution

def main():
    import sys
    input = sys.stdin.readline
    #n = int(input())
    #l = list(map(int, input().split()))
    '''
    A=[]
    B=[]
    for i in range():
        a, b = map(int, input().split())
        A.append(a)
        B.append(b)'''

    n=int(eval(input()))
    s=input().rstrip('\n')
    a=0
    b=0
    c=0
    for i in range(n):
        if s[i]=="R":
            a+=1
        elif s[i]=="G":
            b+=1
        elif s[i]=="B":
            c+=1
    num=a*b*c
    #print(num)
    for i in range(n-2):
        for j in range(1,n//2+1):
            if i+2*j<n:
                if s[i]!=s[i+j] and s[i+j]!=s[i+2*j] and s[i]!=s[i+2*j]:
                    num-=1
    print(num)

if __name__ == "__main__":
    main()
# Original solution
from itertools import permutations
inputs = open(0).readlines()
n = int(inputs[0])
S = inputs[1].strip()

R = [i for i, c in enumerate(S) if c == 'R']
G = [i for i, c in enumerate(S) if c == 'G']
B = [i for i, c in enumerate(S) if c == 'B']

def f(Z, i, x, y):
    for z in Z[i:]:
        if z == 2*y-x:
            return 1
        if z > 2*y-x:
            return 0
    return 0

ans = 0
for X, Y, Z in list(permutations([R, G, B])):
    for x in X:
        pi = 0
        for y in Y:
            if x < y:
                for i, z in enumerate(Z[pi:], pi):
                    if y < z:
                        ans += len(Z) - i - f(Z, i, x, y)
                        pi = i
                        break
print(ans)

# Optimized solution
n = int(eval(input()))
S = input().strip()
r, g, b = list(map(S.count, 'RGB'))
t = 0
for i in range(n-2):
    for w in range(1, (n-i+1) // 2):
        t += len({S[i], S[i+w], S[i+2*w]}) == 3
print((r*g*b - t))
# Original solution
from sys import stdin
N = list(map(int, (stdin.readline().strip().split())))[0]
S= list(stdin.readline().strip())
ans=0
for i in range(1,N+1):
    for j in range(i+1,N+1):
        for k in range(j+1,N+1):
            if j-i !=k-j:
                if S[i-1] != S[j-1] and S[j-1] !=S[k-1] and S[i-1] != S[k-1]:
                    ans+=1
print(ans)

# Optimized solution
from sys import stdin
N = list(map(int, (stdin.readline().strip().split())))[0]
S= list(stdin.readline().strip())
ans = S.count("R")*S.count("G")*S.count("B")
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[i] !=S[k]:
                ans-=1
print(ans)
# Original solution
# import numpy as np
# import math
# import copy
# from collections import deque
import sys
input = sys.stdin.readline
# sys.setrecursionlimit(10000)


def main():
    N = int(eval(input()))
    S = input().rstrip()

    all = {'R','G','B'}

    R = set([])
    G = set([])
    B = set([])

    for i in range(N):
        temp = S[i]
        if temp == 'R':
            R.add(i)
        elif temp == 'G':
            G.add(i)
        else:
            B.add(i)

    res = len(R) * len(G) * len(B)

    count = 0

    for r in R:
        for g in G:
            for b in B:
                l = [r,g,b]
                l.sort()
                if l[1]-l[0] == l[2]-l[1]:
                    count += 1

    res -= count
    print(res)




main()


# Optimized solution
# import numpy as np
# import math
# import copy
# from collections import deque
import sys
input = sys.stdin.readline
# sys.setrecursionlimit(10000)


def main():
    N = int(eval(input()))
    S = input().rstrip()

    R = set([])
    G = set([])
    B = set([])

    for i in range(N):
        temp = S[i]
        if temp == 'R':
            R.add(i)
        elif temp == 'G':
            G.add(i)
        else:
            B.add(i)

    all = [R,G,B]

    M = [len(R),len(G),len(B)]
    res = M[0] * M[1] * M[2]
    index = M.index(max(M))

    most = all.pop(index)
    first = all[0]
    second = all[1]

    count = 0

    for f in first:
        for s in second:
            temp1 = s * 2 - f
            temp2 = f * 2 - s
            temp3 = (f + s) // 2
            if (True) & (temp1 in most):
                count += 1
            if (True) & (temp2 in most):
                count += 1
            if (s + f) % 2 == 0:
                if temp3 in most:
                    count += 1

    res -= count
    print(res)




main()
# Original solution
from sys import stdin
n = int(stdin.readline().rstrip())
s = str(stdin.readline().rstrip())
#l = list(map(int, stdin.readline().rstrip().split()))
#A, B, C = map(int, stdin.readline().rstrip().split())
#S = [list(map(int, stdin.readline().rstrip().split())) for _ in range(h)]#hの定義を忘れずに

ans = 0

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

print(ans)


# Optimized solution
from sys import stdin
n = int(stdin.readline().rstrip())
s = str(stdin.readline().rstrip())
#l = list(map(int, stdin.readline().rstrip().split()))
#A, B, C = map(int, stdin.readline().rstrip().split())
#S = [list(map(int, stdin.readline().rstrip().split())) for _ in range(h)]#hの定義を忘れずに

rnum = s.count("R")
gnum = s.count("G")
bnum = s.count("B")

ans = rnum * gnum * bnum

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

print(ans)
# Original solution
import sys

n = int(sys.stdin.readline().rstrip())
s = sys.stdin.readline().rstrip()
r = []
b = []
g = []
for i, si in enumerate(s):
    if si == 'R':
        r.append(i + 1)
    elif si == 'G':
        g.append(i + 1)
    elif si == 'B':
        b.append(i + 1)
count = 0
gb = sorted(g + b)
br = sorted(b + r)
rg = sorted(r + g)
for i, si in enumerate(s):
    tmp = None
    if si == 'R':
        tmp = gb
    elif si == 'G':
        tmp = br
    else:
        tmp = rg
    for j in tmp:
        if j < i + 1:
            continue
        tmp2 = None
        # print(si, s[j-1])
        if (si == 'R' and s[j-1] == 'G') or (si == 'G' and s[j-1] == 'R'):
            tmp2 = b
        elif (si == 'R' and s[j-1] == 'B') or (si == 'B' and s[j-1] == 'R'):
            tmp2 = g
        elif (si == 'G' and s[j-1] == 'B') or (si == 'B' and s[j-1] == 'G'):
            tmp2 = r
        for k in tmp2:
            if k < j:
                continue
            if j - (i + 1) != k - j:
                # print(i + 1, j, k)
                count += 1
print(count)

# Optimized solution
import sys

n = int(sys.stdin.readline().rstrip())
s = sys.stdin.readline().rstrip()
r = []
b = []
g = []
for i, si in enumerate(s):
    if si == 'R':
        r.append(i + 1)
    elif si == 'G':
        g.append(i + 1)
    elif si == 'B':
        b.append(i + 1)
count = 0
for i in range(n):
    for j in range(i + 1, n):
        k = j + j - i
        if k < n and s[i] != s[j] and s[j] != s[k] and s[k] != s[i]:
            count += 1
print((len(r) * len(g) * len(b) - count))
# Original solution
n = int(eval(input()))
seq = input().strip()
ans = 0
r = []
g = []
b = []
for i in range(len(seq)):
    if seq[i] == 'R':
        r.append(i)
    elif seq[i] == 'G':
        g.append(i)
    else:
        b.append(i)

for i in r:
    for j in g:
        for k in b:
            z,x,c = sorted([i,j,k])
            if x-z != c - x:
                ans += 1
print(ans)

# Optimized solution
n = int(eval(input()))
seq = input().strip()
ans = 0
r = set()
g = set()
b = set()
for i in range(len(seq)):
    if seq[i] == 'R':
        r.add(i)
    elif seq[i] == 'G':
        g.add(i)
    else:
        b.add(i)

ans = len(r)*len(g)*len(b)
for i in r:
    for j in g:
        if (i+j) % 2 == 0 and ((i + j) //2) in b:
            ans -= 1
        if max(i,j) + (max(i,j) - min(i,j)) in b:
            ans -= 1
        if min(i,j) - (max(i,j) - min(i,j)) in b:
            ans -= 1
        
print(ans)