Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
s = str(input())
r = []
g = []
def right(r,g):
    return (max(r,g)+(abs(r-g)))
def left(r,g):
    return (min(r,g)-(abs(r-g)))
def half(r,g):
    return ((r+g)//2)
for i in range(n):
    if s[i] == "R":
        r.append(i)
    elif s[i] == "G":
        g.append(i)
ans = len(r)*len(g)*(n-(len(r)+len(g)))
for i in range(len(r)):
    for j in range(len(g)):
        t = left(r[i],g[j])
        f = right(r[i],g[j])
        h = half(r[i],g[j])
        if f < n:
            if s[f] == "B":
                ans -= 1
        if 0 <= t:
            if s[t] == "B":
                ans -= 1
        if abs(r[i]-g[j])%2 == 0:
            if s[h] == "B":
                ans -= 1
print(ans)

Fixed submission:
n = int(input())
s = str(input())
r = []
g = []
def right(r,g):
    return (max(r,g)+(abs(r-g)))
def left(r,g):
    return (min(r,g)-(abs(r-g)))
def half(r,g):
    return ((r+g)//2)
for i in range(n):
    if s[i] == "R":
        r.append(i)
    elif s[i] == "G":
        g.append(i)
ans = len(r)*len(g)*(n-(len(r)+len(g)))
for i in range(len(r)):
    for j in range(len(g)):
        t = left(r[i],g[j])
        f = right(r[i],g[j])
        h = half(r[i],g[j])
        if f < n:
            if s[f] == "B":
                ans -= 1
        if 0 <= t:
            if s[t] == "B":
                ans -= 1
        if abs(r[i]-g[j])%2 == 0:
            if s[h] == "B":
                ans -= 1
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
s = str(input())
r = []
g = []
for i in range(n):
    if s[i] == "R":
        r.append(i)
    elif s[i] == "G":
        g.append(i)
ans = len(r)*len(g)*(n-(len(r)+len(g)))
for i in range(len(r)):
    for j in range(len(g)):
        if max(r[i],g[j])+(abs(r[i]-g[j])) < n:
            if s[max(r[i],g[j])+(abs(r[i]-g[j]))] == "B":
                ans -= 1
        if 0 <= min(r[i],g[j])-(abs(r[i]-g[j])):
            if s[min(r[i],g[j])-(abs(r[i]-g[j]))] == "B":
                ans -= 1
        if abs(r[i]-g[j])%2 == 0:
            if s[(r[i]+g[j])//2] == "B":
                ans -= 1
print(ans)

Fixed submission:
n = int(input())
s = str(input())
r = []
g = []
def right(r,g):
    return (max(r,g)+(abs(r-g)))
def left(r,g):
    return (min(r,g)-(abs(r-g)))
def half(r,g):
    return ((r+g)//2)
for i in range(n):
    if s[i] == "R":
        r.append(i)
    elif s[i] == "G":
        g.append(i)
ans = len(r)*len(g)*(n-(len(r)+len(g)))
for i in range(len(r)):
    for j in range(len(g)):
        t = left(r[i],g[j])
        f = right(r[i],g[j])
        h = half(r[i],g[j])
        if f < n:
            if s[f] == "B":
                ans -= 1
        if 0 <= t:
            if s[t] == "B":
                ans -= 1
        if abs(r[i]-g[j])%2 == 0:
            if s[h] == "B":
                ans -= 1
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
s = str(input())
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 = len(r)*len(g)*len(b)
for i in range(len(r)):
    for j in range(len(g)):
        if max(r[i],g[j])+(abs(r[i]-g[j])) < n:
            if s[max(r[i],g[j])+(abs(r[i]-g[j]))] == "B":
                ans -= 1
        if 0 <= min(r[i],g[j])-(abs(r[i]-g[j])):
            if s[min(r[i],g[j])-(abs(r[i]-g[j]))] == "B":
                ans -= 1
        if abs(r[i]-g[j])%2 == 0:
            if s[(r[i]+g[j])//2] == "B":
                ans -= 1
print(ans)

Fixed submission:
n = int(input())
s = str(input())
r = []
g = []
def right(r,g):
    return (max(r,g)+(abs(r-g)))
def left(r,g):
    return (min(r,g)-(abs(r-g)))
def half(r,g):
    return ((r+g)//2)
for i in range(n):
    if s[i] == "R":
        r.append(i)
    elif s[i] == "G":
        g.append(i)
ans = len(r)*len(g)*(n-(len(r)+len(g)))
for i in range(len(r)):
    for j in range(len(g)):
        t = left(r[i],g[j])
        f = right(r[i],g[j])
        h = half(r[i],g[j])
        if f < n:
            if s[f] == "B":
                ans -= 1
        if 0 <= t:
            if s[t] == "B":
                ans -= 1
        if abs(r[i]-g[j])%2 == 0:
            if s[h] == "B":
                ans -= 1
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
s = str(input())
r = []
g = []
b = []
for i in range(n):
    if s[i] == "R":
        r.append(i+1)
    if s[i] == "G":
        g.append(i+1)
    if s[i] == "B":
        b.append(i+1)
ans = len(r)*len(g)*len(b)
for i in range(len(r)):
    for j in range(len(g)):
        if max(r[i],g[j])+(abs(r[i]-g[j])) in b:
            ans -= 1
        if min(r[i],g[j])-(abs(r[i]-g[j])) in b:
            ans -= 1
        if abs(r[i]-g[j])%2 == 0 and (r[i]+g[j])//2 in b:
            ans -= 1
print(ans)

Fixed submission:
n = int(input())
s = str(input())
r = []
g = []
def right(r,g):
    return (max(r,g)+(abs(r-g)))
def left(r,g):
    return (min(r,g)-(abs(r-g)))
def half(r,g):
    return ((r+g)//2)
for i in range(n):
    if s[i] == "R":
        r.append(i)
    elif s[i] == "G":
        g.append(i)
ans = len(r)*len(g)*(n-(len(r)+len(g)))
for i in range(len(r)):
    for j in range(len(g)):
        t = left(r[i],g[j])
        f = right(r[i],g[j])
        h = half(r[i],g[j])
        if f < n:
            if s[f] == "B":
                ans -= 1
        if 0 <= t:
            if s[t] == "B":
                ans -= 1
        if abs(r[i]-g[j])%2 == 0:
            if s[h] == "B":
                ans -= 1
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
s = str(input())
r = []
g = []
b = []
ans = 0
for i in range(n):
    if s[i] == "R":
        r.append(i+1)
    if s[i] == "G":
        g.append(i+1)
    if s[i] == "B":
        b.append(i+1)
for i in range(len(r)):
    for j in range(len(g)):
        ans += len(b)
        if max(r[i],g[j])+(abs(r[i]-g[j])) in b:
            ans -= 1
        if min(r[i],g[j])-(abs(r[i]-g[j])) in b:
            ans -= 1
        if abs(r[i]-g[j])%2 == 0 and (r[i]+g[j])//2 in b:
            ans -= 1
print(ans)

Fixed submission:
n = int(input())
s = str(input())
r = []
g = []
def right(r,g):
    return (max(r,g)+(abs(r-g)))
def left(r,g):
    return (min(r,g)-(abs(r-g)))
def half(r,g):
    return ((r+g)//2)
for i in range(n):
    if s[i] == "R":
        r.append(i)
    elif s[i] == "G":
        g.append(i)
ans = len(r)*len(g)*(n-(len(r)+len(g)))
for i in range(len(r)):
    for j in range(len(g)):
        t = left(r[i],g[j])
        f = right(r[i],g[j])
        h = half(r[i],g[j])
        if f < n:
            if s[f] == "B":
                ans -= 1
        if 0 <= t:
            if s[t] == "B":
                ans -= 1
        if abs(r[i]-g[j])%2 == 0:
            if s[h] == "B":
                ans -= 1
print(ans)