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

r, g, b = [0] * n, [0] * n, [0] * n
for i in range(0, n):
    if i == 0:
        if s[i] == 'R':
            r[i] = 1
        elif s[i] == 'G':
            g[i] = 1        
        elif s[i] == 'B':
            b[i] = 1
    else:
        if s[i] == 'R':
            r[i] = r[i-1] + 1
            g[i] = g[i-1]
            b[i] = b[i-1]
        elif s[i] == 'G':
            r[i] = r[i-1]
            g[i] = g[i-1] + 1
            b[i] = b[i-1]
        elif s[i] == 'B':
            r[i] = r[i-1]
            g[i] = g[i-1]
            b[i] = b[i-1] + 1   

cnt = 0
for i in range(0, n-2):
    for j in range(n-1, i+1, -1):
        if s[i] != s[j]:
            if s[i] != 'B' and s[j] != 'B':
                cnt += b[j] - b[i]
                if (i+j) % 2 == 0 and s[(i+j)//2] == 'B':
                    cnt -= 1
            elif s[i] != 'G' and s[j] != 'G':
                cnt += g[j] - g[i]
                if (i+j) % 2 == 0 and s[(i+j)//2] == 'G':
                    cnt -= 1
            elif s[i] != 'R' and s[j] != 'R':
                cnt += r[j] - r[i]
                if (i+j) % 2 == 0 and s[(i+j)//2] == 'R':
                    cnt -= 1
print(cnt)

Fixed submission:
def main():
    n=int(input())
    s=input()
    r=[]
    g=[]
    b=[]
    rdict={}
    gdict={}
    bdict={}
    ans=0
    for i in range(n):
        if s[i]=='R':
            r.append(i)
            rdict[2*i]=2*i
        if s[i]=='G':
            g.append(i)
            gdict[2*i]=2*i
        if s[i]=='B':
            b.append(i)
            bdict[2*i]=2*i
    ans=len(r)*len(g)*len(b)
    for i in r:
        for j in g:
            if i+j in bdict:
                ans-=1
    for i in g:
        for j in b:
            if i+j in rdict:
                ans-=1
    for i in b:
        for j in r:
            if i+j in gdict:
                ans-=1
    print(ans)
    
if __name__ == '__main__':
    main()

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

r, g, b = [0] * n, [0] * n, [0] * n
for i in range(0, n):
    if i == 0:
        if s[i] == 'R':
            r[i] = 1
        elif s[i] == 'G':
            g[i] = 1        
        elif s[i] == 'B':
            b[i] = 1
    else:
        if s[i] == 'R':
            r[i] = r[i-1] + 1
            g[i] = g[i-1]
            b[i] = b[i-1]
        elif s[i] == 'G':
            r[i] = r[i-1]
            g[i] = g[i-1] + 1
            b[i] = b[i-1]
        elif s[i] == 'B':
            r[i] = r[i-1]
            g[i] = g[i-1]
            b[i] = b[i-1] + 1   

cnt = 0
for i in range(0, n-2):
    for j in range(n-1, i+1, -1):
        if s[i] == 'R' and s[j] == 'G':
            cnt += b[j] - b[i]
            if (i+j) % 2 == 0 and s[(i+j)//2] == 'B':
                cnt -= 1
        elif s[i] == 'G' and s[j] == 'R':
            cnt += b[j] - b[i]
            if (i+j) % 2 == 0 and s[(i+j)//2] == 'B':
                cnt -= 1
        elif s[i] == 'R' and s[j] == 'B':
            cnt += g[j] - g[i]
            if (i+j) % 2 == 0 and s[(i+j)//2] == 'G':
                cnt -= 1
        elif s[i] == 'B' and s[j] == 'R':
            cnt += g[j] - g[i]
            if (i+j) % 2 == 0 and s[(i+j)//2] == 'G':
                cnt -= 1
        elif s[i] == 'G' and s[j] == 'B':
            cnt += r[j] - r[i]
            if (i+j) % 2 == 0 and s[(i+j)//2] == 'R':
                cnt -= 1
        elif s[i] == 'B' and s[j] == 'G':
            cnt += r[j] - r[i]
            if (i+j) % 2 == 0 and s[(i+j)//2] == 'R':
                cnt -= 1
print(cnt)

Fixed submission:
def main():
    n=int(input())
    s=input()
    r=[]
    g=[]
    b=[]
    rdict={}
    gdict={}
    bdict={}
    ans=0
    for i in range(n):
        if s[i]=='R':
            r.append(i)
            rdict[2*i]=2*i
        if s[i]=='G':
            g.append(i)
            gdict[2*i]=2*i
        if s[i]=='B':
            b.append(i)
            bdict[2*i]=2*i
    ans=len(r)*len(g)*len(b)
    for i in r:
        for j in g:
            if i+j in bdict:
                ans-=1
    for i in g:
        for j in b:
            if i+j in rdict:
                ans-=1
    for i in b:
        for j in r:
            if i+j in gdict:
                ans-=1
    print(ans)
    
if __name__ == '__main__':
    main()

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

r = [i for i in range(0, n) if s[i] == 'R']
g = [i for i in range(0, n) if s[i] == 'G']
b = [i for i in range(0, n) if s[i] == 'B']

cnt = 0
for elem1 in r:
    for elem2 in g:
        for elem3 in b:
            lst = sorted([elem1, elem2, elem3])
            if (lst[1] - lst[0]) != (lst[2] - lst[1]):
                cnt += 1
print(cnt)

Fixed submission:
def main():
    n=int(input())
    s=input()
    r=[]
    g=[]
    b=[]
    rdict={}
    gdict={}
    bdict={}
    ans=0
    for i in range(n):
        if s[i]=='R':
            r.append(i)
            rdict[2*i]=2*i
        if s[i]=='G':
            g.append(i)
            gdict[2*i]=2*i
        if s[i]=='B':
            b.append(i)
            bdict[2*i]=2*i
    ans=len(r)*len(g)*len(b)
    for i in r:
        for j in g:
            if i+j in bdict:
                ans-=1
    for i in g:
        for j in b:
            if i+j in rdict:
                ans-=1
    for i in b:
        for j in r:
            if i+j in gdict:
                ans-=1
    print(ans)
    
if __name__ == '__main__':
    main()

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

cnt = 0
for i in range(0, n-2):
    for j in range(i+1, n-1):
        if s[i] != s[j]:
            for k in range(j+1, n):
                if (j - i) != (k - j):
                    if s[i] != s[k] and s[j] != s[k]:
                        cnt += 1
                    else:
                        pass
                else:
                    pass
print(cnt)

Fixed submission:
def main():
    n=int(input())
    s=input()
    r=[]
    g=[]
    b=[]
    rdict={}
    gdict={}
    bdict={}
    ans=0
    for i in range(n):
        if s[i]=='R':
            r.append(i)
            rdict[2*i]=2*i
        if s[i]=='G':
            g.append(i)
            gdict[2*i]=2*i
        if s[i]=='B':
            b.append(i)
            bdict[2*i]=2*i
    ans=len(r)*len(g)*len(b)
    for i in r:
        for j in g:
            if i+j in bdict:
                ans-=1
    for i in g:
        for j in b:
            if i+j in rdict:
                ans-=1
    for i in b:
        for j in r:
            if i+j in gdict:
                ans-=1
    print(ans)
    
if __name__ == '__main__':
    main()