n = int(input())
s = input()

INF = 1_000_000_000
colors = ['R', 'G', 'B']

def get_rest(si, sj):
    for c in colors:
        if not c in [si, sj]: return c

cnt = 0
for i in range(n):
    comb = 1
    for i, c in enumerate(colors):
        if c == s[i]: continue
        comb *= s[i+1:].count(c)
    cnt += comb

    w = 1
    while True:
        if i + 2*w >= n: break
        if s[i] != s[i+w] and s[i+w] != s[i+2*w] and s[i+2*w] != s[i]:
            cnt -= 1
        w += 1
print(cnt)
1a5b63f937ea918aba6a544f5a0325a43ae07bb3
<mask token>

<mask token>


def get_rest(si, sj):
    for c in colors:
        if not c in [si, sj]:
            return c


<mask token>

<mask token>


def get_rest(si, sj):
    for c in colors:
        if not c in [si, sj]:
            return c


<mask token>
for i in range(n):
    comb = 1
    for i, c in enumerate(colors):
        if c == s[i]:
            continue
        comb *= s[i + 1:].count(c)
    cnt += comb
    w = 1
    while True:
        if i + 2 * w >= n:
            break
        if s[i] != s[i + w] and s[i + w] != s[i + 2 * w] and s[i + 2 * w] != s[
            i]:
            cnt -= 1
        w += 1
print(cnt)

n = int(input())
s = input()
INF = 1000000000
colors = ['R', 'G', 'B']


def get_rest(si, sj):
    for c in colors:
        if not c in [si, sj]:
            return c


cnt = 0
for i in range(n):
    comb = 1
    for i, c in enumerate(colors):
        if c == s[i]:
            continue
        comb *= s[i + 1:].count(c)
    cnt += comb
    w = 1
    while True:
        if i + 2 * w >= n:
            break
        if s[i] != s[i + w] and s[i + w] != s[i + 2 * w] and s[i + 2 * w] != s[
            i]:
            cnt -= 1
        w += 1
print(cnt)

n = int(input())
s = input()

INF = 1_000_000_000
colors = ['R', 'G', 'B']

def get_rest(si, sj):
    for c in colors:
        if not c in [si, sj]: return c

cnt = 0
for i in range(n):
    comb = 1
    for i, c in enumerate(colors):
        if c == s[i]: continue
        comb *= s[i+1:].count(c)
    cnt += comb

    w = 1
    while True:
        if i + 2*w >= n: break
        if s[i] != s[i+w] and s[i+w] != s[i+2*w] and s[i+2*w] != s[i]:
            cnt -= 1
        w += 1
print(cnt)