Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np
n = int(input())
s = input()
R_ls = [0] * n
G_ls = [0] * n
B_ls = [0] * n
for i in range(n):
    if s[i] == 'R':
        R_ls[i] = 1
    elif s[i] == 'G':
        G_ls[i] = 1
    else:
        B_ls[i] = 1
R_csum = np.cumsum(R_ls)
G_csum = np.cumsum(G_ls)
B_csum = np.cumsum(B_ls)
ans = 0
for i in range(n-2):
    for j in range(i+1,n-1):
        if (s[i] == 'R' and s[j] == 'G') or (s[i] == 'G' and s[j] == 'R'):
            now = B_csum[-1] - B_csum[j]
            if j + (j-i) < n and s[2*j-i] == 'B':
                now -= 1
        elif (s[i] == 'R' and s[j] == 'B') or (s[i] == 'B' and s[j] == 'R'):
            now = G_csum[-1] - G_csum[j]
            if j + (j-i) < n and s[2*j-i] == 'G':
                now -= 1
        elif (s[i] == 'G' and s[j] == 'B') or (s[i] == 'B' and s[j] == 'G'):
            now = R_csum[-1] - R_csum[j]
            if j + (j-i) < n and s[2*j-i] == 'R':
                now -= 1
        else:
            now = 0
        ans += now
print(ans)




Fixed submission:
n = int(input())
s = input()
R_ls = [0] * n
G_ls = [0] * n
B_ls = [0] * n
R_csum = [0] * n
G_csum = [0] * n
B_csum = [0] * n
for i in range(n):
    if s[i] == 'R':
        R_ls[i] = 1
        R_csum[i] = R_csum[i-1] + 1
        G_csum[i] = G_csum[i-1]
        B_csum[i] = B_csum[i-1]
    elif s[i] == 'G':
        G_ls[i] = 1
        G_csum[i] = G_csum[i-1] + 1
        R_csum[i] = R_csum[i-1]
        B_csum[i] = B_csum[i-1]
    else:
        B_ls[i] = 1
        B_csum[i] = B_csum[i-1] + 1
        R_csum[i] = R_csum[i-1]
        G_csum[i] = G_csum[i-1]
ans = 0
for i in range(n-2):
    for j in range(i+1,n-1):
        if (s[i] == 'R' and s[j] == 'G') or (s[i] == 'G' and s[j] == 'R'):
            now = B_csum[-1] - B_csum[j]
            if j + (j-i) < n and s[2*j-i] == 'B':
                now -= 1
        elif (s[i] == 'R' and s[j] == 'B') or (s[i] == 'B' and s[j] == 'R'):
            now = G_csum[-1] - G_csum[j]
            if j + (j-i) < n and s[2*j-i] == 'G':
                now -= 1
        elif (s[i] == 'G' and s[j] == 'B') or (s[i] == 'B' and s[j] == 'G'):
            now = R_csum[-1] - R_csum[j]
            if j + (j-i) < n and s[2*j-i] == 'R':
                now -= 1
        else:
            now = 0
        ans += now
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
s = input()

R_inds = [0] * n
G_inds = [0] * n
B_inds = [0] * n

for i in range(n):
    if s[i] == 'R':
        R_inds[i] = i
    elif s[i] == 'G':
        G_inds[i] = i
    else:
        B_inds[i] = i
R_inds = list(set(R_inds))
G_inds = list(set(G_inds))
B_inds = list(set(B_inds))

if s[0] == 'R':
    G_inds.remove(0)
    B_inds.remove(0)
elif s[0] == 'G':
    R_inds.remove(0)
    B_inds.remove(0)
else:
    R_inds.remove(0)
    G_inds.remove(0)

G_len = len(G_inds)
B_len = len(B_inds)
R_len = len(R_inds)

if G_len >= B_len and G_len >= R_len:
    largest = G_inds
    a_inds = B_inds
    b_inds = R_inds
elif B_len >= G_len and B_len >= R_len:
    largest = B_inds
    a_inds = G_inds
    b_inds = R_inds
else:
    largest = R_inds
    a_inds = G_inds
    b_inds = B_inds
    
ans = 0
for r in a_inds:
    for g in b_inds:
        big = max(r,g)
        small = min(r,g)
        bigger = big + (big - small)
        smaller = small - (big - small)
        if (big - small) % 2 == 0:
            middle = (big + small) // 2
        else:
            middle = -1
        
        subans = 0
        subans += len(largest)
        if smaller in largest:
            subans -= 1
        if bigger in largest:
            subans -= 1
        if middle in largest:
            subans -= 1
        if subans > 0:
            ans += subans

print(ans)


Fixed submission:
n = int(input())
s = input()
R_ls = [0] * n
G_ls = [0] * n
B_ls = [0] * n
R_csum = [0] * n
G_csum = [0] * n
B_csum = [0] * n
for i in range(n):
    if s[i] == 'R':
        R_ls[i] = 1
        R_csum[i] = R_csum[i-1] + 1
        G_csum[i] = G_csum[i-1]
        B_csum[i] = B_csum[i-1]
    elif s[i] == 'G':
        G_ls[i] = 1
        G_csum[i] = G_csum[i-1] + 1
        R_csum[i] = R_csum[i-1]
        B_csum[i] = B_csum[i-1]
    else:
        B_ls[i] = 1
        B_csum[i] = B_csum[i-1] + 1
        R_csum[i] = R_csum[i-1]
        G_csum[i] = G_csum[i-1]
ans = 0
for i in range(n-2):
    for j in range(i+1,n-1):
        if (s[i] == 'R' and s[j] == 'G') or (s[i] == 'G' and s[j] == 'R'):
            now = B_csum[-1] - B_csum[j]
            if j + (j-i) < n and s[2*j-i] == 'B':
                now -= 1
        elif (s[i] == 'R' and s[j] == 'B') or (s[i] == 'B' and s[j] == 'R'):
            now = G_csum[-1] - G_csum[j]
            if j + (j-i) < n and s[2*j-i] == 'G':
                now -= 1
        elif (s[i] == 'G' and s[j] == 'B') or (s[i] == 'B' and s[j] == 'G'):
            now = R_csum[-1] - R_csum[j]
            if j + (j-i) < n and s[2*j-i] == 'R':
                now -= 1
        else:
            now = 0
        ans += now
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
s = input()

R_inds = [0] * n
G_inds = [0] * n
B_inds = [0] * n

for i in range(n):
    if s[i] == 'R':
        R_inds[i] = i
    elif s[i] == 'G':
        G_inds[i] = i
    else:
        B_inds[i] = i
R_inds = list(set(R_inds))
G_inds = list(set(G_inds))
B_inds = list(set(B_inds))

if s[0] == 'R':
    G_inds.remove(0)
    B_inds.remove(0)
elif s[0] == 'G':
    R_inds.remove(0)
    B_inds.remove(0)
else:
    R_inds.remove(0)
    G_inds.remove(0)
    
ans = 0
for r in R_inds:
    for g in G_inds:
        big = max(r,g)
        small = min(r,g)
        bigger = big + (big - small)
        smaller = small - (big - small)
        if (big - small) % 2 == 0:
            middle = (big + small) // 2
        else:
            middle = -1
        
        subans = 0
        subans += len(B_inds)
        if smaller in B_inds:
            subans -= 1
        if bigger in B_inds:
            subans -= 1
        if middle in B_inds:
            subans -= 1
        if subans > 0:
            ans += subans

print(ans)

Fixed submission:
n = int(input())
s = input()
R_ls = [0] * n
G_ls = [0] * n
B_ls = [0] * n
R_csum = [0] * n
G_csum = [0] * n
B_csum = [0] * n
for i in range(n):
    if s[i] == 'R':
        R_ls[i] = 1
        R_csum[i] = R_csum[i-1] + 1
        G_csum[i] = G_csum[i-1]
        B_csum[i] = B_csum[i-1]
    elif s[i] == 'G':
        G_ls[i] = 1
        G_csum[i] = G_csum[i-1] + 1
        R_csum[i] = R_csum[i-1]
        B_csum[i] = B_csum[i-1]
    else:
        B_ls[i] = 1
        B_csum[i] = B_csum[i-1] + 1
        R_csum[i] = R_csum[i-1]
        G_csum[i] = G_csum[i-1]
ans = 0
for i in range(n-2):
    for j in range(i+1,n-1):
        if (s[i] == 'R' and s[j] == 'G') or (s[i] == 'G' and s[j] == 'R'):
            now = B_csum[-1] - B_csum[j]
            if j + (j-i) < n and s[2*j-i] == 'B':
                now -= 1
        elif (s[i] == 'R' and s[j] == 'B') or (s[i] == 'B' and s[j] == 'R'):
            now = G_csum[-1] - G_csum[j]
            if j + (j-i) < n and s[2*j-i] == 'G':
                now -= 1
        elif (s[i] == 'G' and s[j] == 'B') or (s[i] == 'B' and s[j] == 'G'):
            now = R_csum[-1] - R_csum[j]
            if j + (j-i) < n and s[2*j-i] == 'R':
                now -= 1
        else:
            now = 0
        ans += now
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
s = input()

R_inds = [0] * n
G_inds = [0] * n
B_inds = [0] * n

for i in range(n):
    if s[i] == 'R':
        R_inds[i] = i
    elif s[i] == 'G':
        G_inds[i] = i
    else:
        B_inds[i] = i
R_inds = list(set(R_inds))
G_inds = list(set(G_inds))
B_inds = list(set(B_inds))

if s[0] == 'R':
    G_inds.remove(0)
    B_inds.remove(0)
elif s[0] == 'G':
    R_inds.remove(0)
    B_inds.remove(0)
else:
    R_inds.remove(0)
    G_inds.remove(0)
    
ans = 0
for r in R_inds:
    for g in G_inds:
        big = max(r,g)
        small = min(r,g)
        bigger = big + (big - small)
        smaller = small - (big - small)
        if (big - small) % 2 == 0:
            middle = (big + small) // 2
        else:
            middle = -1
        
        subans = 0
        subans += len(B_inds)
        if smaller in B_inds:
            subans -= 1
        if bigger in B_inds:
            subans -= 1
        if middle in B_inds:
            subans -= 1
        if subans > 0:
            ans += subans

print(ans)

Fixed submission:
n = int(input())
s = input()
R_ls = [0] * n
G_ls = [0] * n
B_ls = [0] * n
R_csum = [0] * n
G_csum = [0] * n
B_csum = [0] * n
for i in range(n):
    if s[i] == 'R':
        R_ls[i] = 1
        R_csum[i] = R_csum[i-1] + 1
        G_csum[i] = G_csum[i-1]
        B_csum[i] = B_csum[i-1]
    elif s[i] == 'G':
        G_ls[i] = 1
        G_csum[i] = G_csum[i-1] + 1
        R_csum[i] = R_csum[i-1]
        B_csum[i] = B_csum[i-1]
    else:
        B_ls[i] = 1
        B_csum[i] = B_csum[i-1] + 1
        R_csum[i] = R_csum[i-1]
        G_csum[i] = G_csum[i-1]
ans = 0
for i in range(n-2):
    for j in range(i+1,n-1):
        if (s[i] == 'R' and s[j] == 'G') or (s[i] == 'G' and s[j] == 'R'):
            now = B_csum[-1] - B_csum[j]
            if j + (j-i) < n and s[2*j-i] == 'B':
                now -= 1
        elif (s[i] == 'R' and s[j] == 'B') or (s[i] == 'B' and s[j] == 'R'):
            now = G_csum[-1] - G_csum[j]
            if j + (j-i) < n and s[2*j-i] == 'G':
                now -= 1
        elif (s[i] == 'G' and s[j] == 'B') or (s[i] == 'B' and s[j] == 'G'):
            now = R_csum[-1] - R_csum[j]
            if j + (j-i) < n and s[2*j-i] == 'R':
                now -= 1
        else:
            now = 0
        ans += now
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
s = input()

R_inds = []
G_inds = []
B_inds = []

for i in range(n):
    if s[i] == 'R':
        R_inds.append(i)
    elif s[i] == 'G':
        G_inds.append(i)
    else:
        B_inds.append(i)
    
ans = 0
for r in R_inds:
    for g in G_inds:
        big = max(r,g)
        small = min(r,g)
        bigger = big + (big - small)
        smaller = small - (big - small)
        if (big - small) % 2 == 0:
            middle = (big + small) // 2
        else:
            middle = -1
        
        subans = 0
        subans += len(B_inds)
        if smaller in B_inds:
            subans -= 1
        if bigger in B_inds:
            subans -= 1
        if middle in B_inds:
            subans -= 1
        if subans > 0:
            ans += subans

print(ans)


Fixed submission:
n = int(input())
s = input()
R_ls = [0] * n
G_ls = [0] * n
B_ls = [0] * n
R_csum = [0] * n
G_csum = [0] * n
B_csum = [0] * n
for i in range(n):
    if s[i] == 'R':
        R_ls[i] = 1
        R_csum[i] = R_csum[i-1] + 1
        G_csum[i] = G_csum[i-1]
        B_csum[i] = B_csum[i-1]
    elif s[i] == 'G':
        G_ls[i] = 1
        G_csum[i] = G_csum[i-1] + 1
        R_csum[i] = R_csum[i-1]
        B_csum[i] = B_csum[i-1]
    else:
        B_ls[i] = 1
        B_csum[i] = B_csum[i-1] + 1
        R_csum[i] = R_csum[i-1]
        G_csum[i] = G_csum[i-1]
ans = 0
for i in range(n-2):
    for j in range(i+1,n-1):
        if (s[i] == 'R' and s[j] == 'G') or (s[i] == 'G' and s[j] == 'R'):
            now = B_csum[-1] - B_csum[j]
            if j + (j-i) < n and s[2*j-i] == 'B':
                now -= 1
        elif (s[i] == 'R' and s[j] == 'B') or (s[i] == 'B' and s[j] == 'R'):
            now = G_csum[-1] - G_csum[j]
            if j + (j-i) < n and s[2*j-i] == 'G':
                now -= 1
        elif (s[i] == 'G' and s[j] == 'B') or (s[i] == 'B' and s[j] == 'G'):
            now = R_csum[-1] - R_csum[j]
            if j + (j-i) < n and s[2*j-i] == 'R':
                now -= 1
        else:
            now = 0
        ans += now
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
s = input()

R_inds = []
G_inds = []
B_inds = []

for i in range(n):
    if s[i] == 'R':
        R_inds.append(i)
    elif s[i] == 'G':
        G_inds.append(i)
    else:
        B_inds.append(i)
    
ans = 0
for r in R_inds:
    for g in G_inds:
        big = max(r,g)
        small = min(r,g)
        bigger = big + (big - small)
        smaller = small - (big - small)
        if (big - small) % 2 == 0:
            middle = (big + small) // 2
        else:
            middle = -1
        
        if not (bigger in B_inds or smaller in B_inds or middle in B_inds):
            ans += len(B_inds)
        elif (bigger in B_inds and smaller in B_inds and middle in B_inds):
            ans += max(0,len(B_inds) - 3)
        elif (bigger in B_inds and smaller in B_inds and not middle in B_inds) or (smaller in B_inds and middle in B_inds and not bigger in B_inds) or \
            (middle in B_inds and bigger in B_inds and not smaller in B_inds):
            ans += max(0, len(B_inds) - 2)
        else:
            ans += max(0, len(B_inds) - 1)

print(ans)


Fixed submission:
n = int(input())
s = input()
R_ls = [0] * n
G_ls = [0] * n
B_ls = [0] * n
R_csum = [0] * n
G_csum = [0] * n
B_csum = [0] * n
for i in range(n):
    if s[i] == 'R':
        R_ls[i] = 1
        R_csum[i] = R_csum[i-1] + 1
        G_csum[i] = G_csum[i-1]
        B_csum[i] = B_csum[i-1]
    elif s[i] == 'G':
        G_ls[i] = 1
        G_csum[i] = G_csum[i-1] + 1
        R_csum[i] = R_csum[i-1]
        B_csum[i] = B_csum[i-1]
    else:
        B_ls[i] = 1
        B_csum[i] = B_csum[i-1] + 1
        R_csum[i] = R_csum[i-1]
        G_csum[i] = G_csum[i-1]
ans = 0
for i in range(n-2):
    for j in range(i+1,n-1):
        if (s[i] == 'R' and s[j] == 'G') or (s[i] == 'G' and s[j] == 'R'):
            now = B_csum[-1] - B_csum[j]
            if j + (j-i) < n and s[2*j-i] == 'B':
                now -= 1
        elif (s[i] == 'R' and s[j] == 'B') or (s[i] == 'B' and s[j] == 'R'):
            now = G_csum[-1] - G_csum[j]
            if j + (j-i) < n and s[2*j-i] == 'G':
                now -= 1
        elif (s[i] == 'G' and s[j] == 'B') or (s[i] == 'B' and s[j] == 'G'):
            now = R_csum[-1] - R_csum[j]
            if j + (j-i) < n and s[2*j-i] == 'R':
                now -= 1
        else:
            now = 0
        ans += now
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
s = input()

R_inds = []
G_inds = []
B_inds = []

for i in range(n):
    if s[i] == 'R':
        R_inds.append(i)
    elif s[i] == 'G':
        G_inds.append(i)
    else:
        B_inds.append(i)
    
ans = 0
for r in R_inds:
    for g in G_inds:
        for b in B_inds:
            ls = [r,g,b]
            ls.sort()
            if ls[2] - ls[1] != ls[1] - ls[0]:
                ans += 1

print(ans)

Fixed submission:
n = int(input())
s = input()
R_ls = [0] * n
G_ls = [0] * n
B_ls = [0] * n
R_csum = [0] * n
G_csum = [0] * n
B_csum = [0] * n
for i in range(n):
    if s[i] == 'R':
        R_ls[i] = 1
        R_csum[i] = R_csum[i-1] + 1
        G_csum[i] = G_csum[i-1]
        B_csum[i] = B_csum[i-1]
    elif s[i] == 'G':
        G_ls[i] = 1
        G_csum[i] = G_csum[i-1] + 1
        R_csum[i] = R_csum[i-1]
        B_csum[i] = B_csum[i-1]
    else:
        B_ls[i] = 1
        B_csum[i] = B_csum[i-1] + 1
        R_csum[i] = R_csum[i-1]
        G_csum[i] = G_csum[i-1]
ans = 0
for i in range(n-2):
    for j in range(i+1,n-1):
        if (s[i] == 'R' and s[j] == 'G') or (s[i] == 'G' and s[j] == 'R'):
            now = B_csum[-1] - B_csum[j]
            if j + (j-i) < n and s[2*j-i] == 'B':
                now -= 1
        elif (s[i] == 'R' and s[j] == 'B') or (s[i] == 'B' and s[j] == 'R'):
            now = G_csum[-1] - G_csum[j]
            if j + (j-i) < n and s[2*j-i] == 'G':
                now -= 1
        elif (s[i] == 'G' and s[j] == 'B') or (s[i] == 'B' and s[j] == 'G'):
            now = R_csum[-1] - R_csum[j]
            if j + (j-i) < n and s[2*j-i] == 'R':
                now -= 1
        else:
            now = 0
        ans += now
print(ans)