Buggy python submission (verdict: Time Limit Exceeded):
def resolve():
        n = int(input())
        s = input()
        r = [0] * n
        g = [0] * n
        b = [0] * n
        for i in range(n):
            if s[i] == "R":
                r[i] = 1
            elif s[i] == "G":
                g[i] = 1
            else:
                b[i] = 1
        ans = 0
        a = [r, g, b]
        for i in range(n):
            if a[0][i] == 1:
                for j in range(i + 1, n):
                    if a[1][j] == 1:
                        ans += sum(a[2][j + 1:n])
        a = [r, b, g]
        for i in range(n):
            if a[0][i] == 1:
                for j in range(i + 1, n):
                    if a[1][j] == 1:
                        ans += sum(a[2][j + 1:n])
        a = [g, r, b]
        for i in range(n):
            if a[0][i] == 1:
                for j in range(i + 1, n):
                    if a[1][j] == 1:
                        ans += sum(a[2][j + 1:n])
        a = [g, b, r]
        for i in range(n):
            if a[0][i] == 1:
                for j in range(i + 1, n):
                    if a[1][j] == 1:
                        ans += sum(a[2][j + 1:n])

        a = [b, r, g]
        for i in range(n):
            if a[0][i] == 1:
                for j in range(i + 1, n):
                    if a[1][j] == 1:
                        ans += sum(a[2][j + 1:n])

        a = [b, g, r]
        for i in range(n):
            if a[0][i] == 1:
                for j in range(i + 1, n):
                    if a[1][j] == 1:
                        ans += sum(a[2][j + 1:n])

        for i in range(1, n // 2+1):
            j = 0
            while j + 2 * i <= n - 1:
                if {s[j], s[j + i], s[j + 2 * i]} == {"R", "G", "B"}:
                    ans -= 1
                j += 1
        print(ans)
resolve()


Fixed submission:
def resolve():
    n = int(input())
    s = input()
    r = [0] * n
    g = [0] * n
    b = [0] * n
    for i in range(n):
        if s[i] == "R":
            r[i] = 1
        elif s[i] == "G":
            g[i] = 1
        else:
            b[i] = 1
    ans = sum(r)*sum(g)*sum(b)

    for i in range(1, n // 2 + 1):
        j = 0
        while j + 2 * i <= n - 1:
            if {s[j], s[j + i], s[j + 2 * i]} == {"R", "G", "B"}:
                ans -= 1
            j += 1
    print(ans)
resolve()

Buggy python submission (verdict: Time Limit Exceeded):
def resolve():
    n=int(input())
    s=input()
    r=[0]*n
    g = [0] * n
    b = [0] * n
    for i in range(n):
        if s[i]=="R":
            r[i]=1
        elif s[i]=="G":
            g[i]=1
        else:
            b[i]=1
    ans=0
    a=[r,g,b]
    for i in range(n):
            if a[0][i]==1:
                for j in range(i+1,n):
                    if a[1][j]==1:
                        ans+=sum(a[2][j+1:n])
                        if 2*j-i<=n-1:
                            if a[2][2*j-i]==1:
                               ans-=1
    a=[r,b,g]
    for i in range(n):
            if a[0][i]==1:
                for j in range(i+1,n):
                    if a[1][j]==1:
                        ans+=sum(a[2][j+1:n])
                        if 2*j-i<=n-1:
                            if a[2][2*j-i]==1:
                               ans-=1
    a=[g,r,b]
    for i in range(n):
            if a[0][i]==1:
                for j in range(i+1,n):
                    if a[1][j]==1:
                        ans+=sum(a[2][j+1:n])
                        if 2*j-i<=n-1:
                            if a[2][2*j-i]==1:
                               ans-=1
    a=[g,b,r]
    for i in range(n):
            if a[0][i]==1:
                for j in range(i+1,n):
                    if a[1][j]==1:
                        ans+=sum(a[2][j+1:n])
                        if 2*j-i<=n-1:
                            if a[2][2*j-i]==1:
                               ans-=1
    a=[b,r,g]
    for i in range(n):
            if a[0][i]==1:
                for j in range(i+1,n):
                    if a[1][j]==1:
                        ans+=sum(a[2][j+1:n])
                        if 2*j-i<=n-1:
                            if a[2][2*j-i]==1:
                               ans-=1
    a=[b,g,r]
    for i in range(n):
            if a[0][i]==1:
                for j in range(i+1,n):
                    if a[1][j]==1:
                        ans+=sum(a[2][j+1:n])
                        if 2*j-i<=n-1:
                            if a[2][2*j-i]==1:
                               ans-=1
    print(ans)
resolve()

Fixed submission:
def resolve():
    n = int(input())
    s = input()
    r = [0] * n
    g = [0] * n
    b = [0] * n
    for i in range(n):
        if s[i] == "R":
            r[i] = 1
        elif s[i] == "G":
            g[i] = 1
        else:
            b[i] = 1
    ans = sum(r)*sum(g)*sum(b)

    for i in range(1, n // 2 + 1):
        j = 0
        while j + 2 * i <= n - 1:
            if {s[j], s[j + i], s[j + 2 * i]} == {"R", "G", "B"}:
                ans -= 1
            j += 1
    print(ans)
resolve()

Buggy python submission (verdict: Time Limit Exceeded):
def resolve():
    n=int(input())
    s=input()
    ans=0
    for i in range(n):
        for j in range(i,n):
            for k in range(j,n):
                if {s[i],s[j],s[k]}=={"R","G","B"} and j-i!=k-j:
                    ans+=1
    print(ans)
resolve()

Fixed submission:
def resolve():
    n = int(input())
    s = input()
    r = [0] * n
    g = [0] * n
    b = [0] * n
    for i in range(n):
        if s[i] == "R":
            r[i] = 1
        elif s[i] == "G":
            g[i] = 1
        else:
            b[i] = 1
    ans = sum(r)*sum(g)*sum(b)

    for i in range(1, n // 2 + 1):
        j = 0
        while j + 2 * i <= n - 1:
            if {s[j], s[j + i], s[j + 2 * i]} == {"R", "G", "B"}:
                ans -= 1
            j += 1
    print(ans)
resolve()