### BUGGY CODE ###

n = int(input())
s = tuple(input())
if n <= 3:
    sum = 0
else:
    sum = 0
    for i in range(n-3):
        if s[i] == "R":
            j = i + 1
            while j <= n-2:
                if s[j] == "G":
                    sum += s[j:n].count("B")
                    if 2*j-i <= n-1 and s[2*j-i] == "B":
                        sum -= 1
                if s[j] == "B":
                    sum += s[j:n].count("G")
                    if 2*j-i <= n-1 and s[2*j-i] == "G":
                        sum -= 1
                j += 1
        if s[i] == "G":
            j = i + 1
            while j <= n-2:
                if s[j] == "R":
                    sum += s[j:n].count("B")
                    if 2*j-i <= n-1 and s[2*j-i] == "B":
                        sum -= 1
                if s[j] == "B":
                    sum += s[j:n].count("R")
                    if 2*j-i <= n-1 and s[2*j-i] == "R":
                        sum -= 1
                j += 1
        if s[i] == "B":
            j = i + 1
            while j <= n-2:
                if s[j] == "R":
                    sum += s[j:n].count("G")
                    if 2*j-i <= n-1 and s[2*j-i] == "G":
                        sum -= 1
                if s[j] == "G":
                    sum += s[j:n].count("R")
                    if 2*j-i <= n-1 and s[2*j-i] == "R":
                        sum -= 1
                j += 1
print(sum)
                    
    

### FIXED CODE ###

n = int(input())
s = input()
if n <= 3:
    sum = 0
else:
    sum = 0
    r = []
    g = []
    b = []
    if s[n-1] == "R":
        r.append(1)
        g.append(0)
        b.append(0)
    if s[n-1] == "G":
        r.append(0)
        g.append(1)
        b.append(0)
    if s[n-1] == "B":
        r.append(0)
        g.append(0)
        b.append(1)
    for i in range(1,n):
        if s[n-i-1] == "R":
            r.append(r[i-1]+1)
            g.append(g[i-1])
            b.append(b[i-1])
        if s[n-i-1] == "G":
            r.append(r[i-1])
            g.append(g[i-1]+1)
            b.append(b[i-1])
        if s[n-i-1] == "B":
            r.append(r[i-1])
            g.append(g[i-1])
            b.append(b[i-1]+1)
    for i in range(n-3):
        if s[i] == "R":
            j = i + 1
            while j <= n-2:
                if s[j] == "G":
                    sum += b[n-j-1]
                    if 2*j-i <= n-1 and s[2*j-i] == "B":
                        sum -= 1
                if s[j] == "B":
                    sum += g[n-j-1]
                    if 2*j-i <= n-1 and s[2*j-i] == "G":
                        sum -= 1
                j += 1
        if s[i] == "G":
            j = i + 1
            while j <= n-2:
                if s[j] == "R":
                    sum += b[n-j-1]
                    if 2*j-i <= n-1 and s[2*j-i] == "B":
                        sum -= 1
                if s[j] == "B":
                    sum += r[n-j-1]
                    if 2*j-i <= n-1 and s[2*j-i] == "R":
                        sum -= 1
                j += 1
        if s[i] == "B":
            j = i + 1
            while j <= n-2:
                if s[j] == "R":
                    sum += g[n-j-1]
                    if 2*j-i <= n-1 and s[2*j-i] == "G":
                        sum -= 1
                if s[j] == "G":
                    sum += r[n-j-1]
                    if 2*j-i <= n-1 and s[2*j-i] == "R":
                        sum -= 1
                j += 1
print(sum)