### BUGGY CODE ###

N = int(input())
S = input()

R = []
G = []
B = []
result = 0

for i in range(N):
    if S[i] == 'R':
        R.append(1)
        G.append(0)
        B.append(0)
    elif S[i] == 'G':
        R.append(0)
        G.append(1)
        B.append(0)
    if S[i] == 'B':
        R.append(0)
        G.append(0)
        B.append(1)
for i in range(N):
    R.append(0)
    G.append(0)
    B.append(0)
R_total = sum(R)
G_total = sum(G)
B_total = sum(B)
R_count = []
G_count = []
B_count = []
for i in range(N):
    if S[i] == 'R':
        R_total -= 1
        R_count.append(R_total)
        G_count.append(G_total)
        B_count.append(B_total)
    elif S[i] == 'G':
        G_total -= 1
        R_count.append(R_total)
        G_count.append(G_total)
        B_count.append(B_total)
    if S[i] == 'B':
        B_total -= 1
        R_count.append(R_total)
        G_count.append(G_total)
        B_count.append(B_total)

for i in range(N - 2):
    for j in range(i + 1, N - 1):
        if S[i] == 'R':
            if S[j] == 'G':
                result += B_count[j]
                if B[j * 2 - i] == 1:
                    result -= 1
            if S[j] == 'B':
                result += G_count[j]
                if G[j * 2 - i] == 1:
                    result -= 1
        elif S[i] == 'G':
            if S[j] == 'R':
                result += B_count[j]
                if B[j * 2 - i] == 1:
                    result -= 1
            if S[j] == 'B':
                result += R_count[j]
                if R[j * 2 - i] == 1:
                    result -= 1
        elif S[i] == 'B':
            if S[j] == 'R':
                result += G_count[j]
                if G[j * 2 - i] == 1:
                    result -= 1
            if S[j] == 'G':
                result += R_count[j]
                if R[j * 2 - i] == 1:
                    result -= 1
print(result)

### FIXED CODE ###

N = int(input())
S = input()

R = []
G = []
B = []
result = 0

for i in range(N):
    if S[i] == 'R':
        R.append(1)
        G.append(0)
        B.append(0)
    elif S[i] == 'G':
        R.append(0)
        G.append(1)
        B.append(0)
    if S[i] == 'B':
        R.append(0)
        G.append(0)
        B.append(1)
for i in range(N):
    R.append(0)
    G.append(0)
    B.append(0)
R_total = sum(R)
G_total = sum(G)
B_total = sum(B)
R_count = []
G_count = []
B_count = []
for i in range(N):
    if S[i] == 'R':
        R_total -= 1
        R_count.append(R_total)
        G_count.append(G_total)
        B_count.append(B_total)
    elif S[i] == 'G':
        G_total -= 1
        R_count.append(R_total)
        G_count.append(G_total)
        B_count.append(B_total)
    if S[i] == 'B':
        B_total -= 1
        R_count.append(R_total)
        G_count.append(G_total)
        B_count.append(B_total)

for i in range(N - 2):
    for j in range(i + 1, N - 1):
        if S[i] == 'R':
            if S[j] == 'G':
                result += B_count[j]
                if B[j * 2 - i] == 1:
                    result -= 1
            if S[j] == 'B':
                result += G_count[j]
                if G[j * 2 - i] == 1:
                    result -= 1
        elif S[i] == 'G':
            if S[j] == 'R':
                result += B_count[j]
                if B[j * 2 - i] == 1:
                    result -= 1
            if S[j] == 'B':
                result += R_count[j]
                if R[j * 2 - i] == 1:
                    result -= 1
        elif S[i] == 'B':
            if S[j] == 'R':
                result += G_count[j]
                if G[j * 2 - i] == 1:
                    result -= 1
            if S[j] == 'G':
                result += R_count[j]
                if R[j * 2 - i] == 1:
                    result -= 1
print(result)