Buggy python submission (verdict: Time Limit Exceeded):
def main():
    N=int(input())
    S=input()
    ans=0
    for i in range(N-2):
        for j in range(i+1,N-1):
            if S[i]!=S[j]:
                for l in S[j+1:]:
                    if l!=S[i] and l!=S[j]:
                        ans+=1
            if j+(j-i)<N and S[i]!=S[j]:
                if S[j+(j-i)]!=S[i] and S[j+(j-i)]!=S[j]:
                    ans-=1
    print(ans)
main()

Fixed submission:
def main():
    N=int(input())
    S=input()
    k1=S.count("R")
    k2=S.count("B")
    ans=k1*k2*(len(S)-k1-k2)
    for i in range(N-2):
        for j in range(i+1,N-1):
            if j+(j-i)<N and S[i]!=S[j]:
                if S[j+(j-i)]!=S[i] and S[j+(j-i)]!=S[j]:
                    ans-=1
    print(ans)
main()

Buggy python submission (verdict: Runtime Error):
def main():
    N=int(input())
    S=input()
    ans=0
    for i in range(N-2):
        for j in range(i+1,N-1):
            lis=["R","G","B"]
            if S[i]!=S[j]:
                lis=["R","G","B"]
                lis.remove(S[i],S[j])
                k=S[j+1:].count(lis[0])
                ans=ans+k
            if j+(j-i)<N and S[i]!=S[j]:
                if S[j+(j-i)]!=S[i] and S[j+(j-i)]!=S[j]:
                    ans-=1
    print(ans)
main()

Fixed submission:
def main():
    N=int(input())
    S=input()
    k1=S.count("R")
    k2=S.count("B")
    ans=k1*k2*(len(S)-k1-k2)
    for i in range(N-2):
        for j in range(i+1,N-1):
            if j+(j-i)<N and S[i]!=S[j]:
                if S[j+(j-i)]!=S[i] and S[j+(j-i)]!=S[j]:
                    ans-=1
    print(ans)
main()

Buggy python submission (verdict: Time Limit Exceeded):
def main():
    N=int(input())
    S=input()
    ans=0
    for i in range(N-2):
        for j in range(i+1,N-1):
            lis=["R","G","B"]
            if S[i]!=S[j]:
                lis=["R","G","B"]
                lis.remove(S[i])
                lis.remove(S[j])
                k=S[j+1:].count(lis[0])
                ans=ans+k
            if j+(j-i)<N and S[i]!=S[j]:
                if S[j+(j-i)]!=S[i] and S[j+(j-i)]!=S[j]:
                    ans-=1
    print(ans)
main()

Fixed submission:
def main():
    N=int(input())
    S=input()
    k1=S.count("R")
    k2=S.count("B")
    ans=k1*k2*(len(S)-k1-k2)
    for i in range(N-2):
        for j in range(i+1,N-1):
            if j+(j-i)<N and S[i]!=S[j]:
                if S[j+(j-i)]!=S[i] and S[j+(j-i)]!=S[j]:
                    ans-=1
    print(ans)
main()

Buggy python submission (verdict: Time Limit Exceeded):
def main():
    N=int(input())
    S=input()
    ans=0
    for i in range(N-2):
        for j in range(i+1,N-1):
            lis=["R","G","B"]
            if S[i]!=S[j]:
                lis=["R","G","B"]
                lis.remove(S[i])
                lis.remove(S[j])
                k=S[j+1:].count(lis[0])
                ans=ans+k
            if j+(j-i)<N and S[i]!=S[j]:
                if S[j+(j-i)]!=S[i] and S[j+(j-i)]!=S[j]:
                    ans-=1
    print(ans)
main()

Fixed submission:
def main():
    N=int(input())
    S=input()
    k1=S.count("R")
    k2=S.count("B")
    ans=k1*k2*(len(S)-k1-k2)
    for i in range(N-2):
        for j in range(i+1,N-1):
            if j+(j-i)<N and S[i]!=S[j]:
                if S[j+(j-i)]!=S[i] and S[j+(j-i)]!=S[j]:
                    ans-=1
    print(ans)
main()

Buggy python submission (verdict: Time Limit Exceeded):
def main():
    N=int(input())
    S=input()
    ans=0
    for i in range(N-2):
        for j in range(i+1,N-1):
            lis=["R","G","B"]
            if S[i]!=S[j]:
                lis=["R","G","B"]
                lis.remove(S[i])
                lis.remove(S[j])
                k=S[j+1:].count(lis[0])
                ans=ans+k
            if j+(j-i)<N and S[i]!=S[j]:
                if S[j+(j-i)]!=S[i] and S[j+(j-i)]!=S[j]:
                    ans-=1
    print(ans)
 
main()


Fixed submission:
def main():
    N=int(input())
    S=input()
    k1=S.count("R")
    k2=S.count("B")
    ans=k1*k2*(len(S)-k1-k2)
    for i in range(N-2):
        for j in range(i+1,N-1):
            if j+(j-i)<N and S[i]!=S[j]:
                if S[j+(j-i)]!=S[i] and S[j+(j-i)]!=S[j]:
                    ans-=1
    print(ans)
main()

Buggy python submission (verdict: Time Limit Exceeded):
def main():
    N=int(input())
    S=input()
    ans=0
    for i in range(N-2):
        for j in range(i+1,N-1):
            if S[i]!=S[j]:
                k1=S[j+1:].count(S[i])
                k2=S[j+1:].count(S[j])
                ans=ans+len(S[j+1:])-k1-k2
            if j+(j-i)<N and S[i]!=S[j]:
                if S[j+(j-i)]!=S[i] and S[j+(j-i)]!=S[j]:
                    ans-=1
    print(ans)

main()


Fixed submission:
def main():
    N=int(input())
    S=input()
    k1=S.count("R")
    k2=S.count("B")
    ans=k1*k2*(len(S)-k1-k2)
    for i in range(N-2):
        for j in range(i+1,N-1):
            if j+(j-i)<N and S[i]!=S[j]:
                if S[j+(j-i)]!=S[i] and S[j+(j-i)]!=S[j]:
                    ans-=1
    print(ans)
main()

Buggy python submission (verdict: Time Limit Exceeded):
def main():
    N=int(input())
    S=input()
    ans=0
    for i in range(N-2):
        for j in range(i+1,N-1):
            lis=["R","G","B"]
            if S[i]!=S[j]:
                lis=["R","G","B"]
                lis.remove(S[i])
                lis.remove(S[j])
                k=S[j+1:].count(lis[0])
                ans=ans+k
            if j+(j-i)<N and S[i]!=S[j]:
                if S[j+(j-i)]!=S[i] and S[j+(j-i)]!=S[j]:
                    ans-=1
    print(ans)

main()


Fixed submission:
def main():
    N=int(input())
    S=input()
    k1=S.count("R")
    k2=S.count("B")
    ans=k1*k2*(len(S)-k1-k2)
    for i in range(N-2):
        for j in range(i+1,N-1):
            if j+(j-i)<N and S[i]!=S[j]:
                if S[j+(j-i)]!=S[i] and S[j+(j-i)]!=S[j]:
                    ans-=1
    print(ans)
main()

Buggy python submission (verdict: Time Limit Exceeded):
def main():
    N=int(input())
    S=input()
    ans=0
    for i in range(N-2):
        for j in range(i+1,N-1):
            lis=["R","G","B"]
            if S[i]!=S[j]:
                lis=["R","G","B"]
                lis.remove(S[i])
                lis.remove(S[j])
                k=S[j+1:].count(lis[0])
                ans=ans+k
            if j+(j-i)<N and S[i]!=S[j]:
                if S[j+(j-i)]!=S[i] and S[j+(j-i)]!=S[j]:
                    ans-=1
    print(ans)

main()

Fixed submission:
def main():
    N=int(input())
    S=input()
    k1=S.count("R")
    k2=S.count("B")
    ans=k1*k2*(len(S)-k1-k2)
    for i in range(N-2):
        for j in range(i+1,N-1):
            if j+(j-i)<N and S[i]!=S[j]:
                if S[j+(j-i)]!=S[i] and S[j+(j-i)]!=S[j]:
                    ans-=1
    print(ans)
main()

Buggy python submission (verdict: Time Limit Exceeded):
def main():
    N=int(input())
    S=input()
    ans=0
    for i in range(N-2):
        for j in range(i+1,N-1):
            lis=["R","G","B"]
            if S[i]!=S[j]:
                lis=["R","G","B"]
                lis.remove(S[i])
                lis.remove(S[j])
                k=S[j+1:].count(lis[0])
                ans=ans+k
            if j+(j-i)<N and S[i]!=S[j]:
                if S[j+(j-i)]!=S[i] and S[j+(j-i)]!=S[j]:
                    ans-=1
    print(ans)

main()

Fixed submission:
def main():
    N=int(input())
    S=input()
    k1=S.count("R")
    k2=S.count("B")
    ans=k1*k2*(len(S)-k1-k2)
    for i in range(N-2):
        for j in range(i+1,N-1):
            if j+(j-i)<N and S[i]!=S[j]:
                if S[j+(j-i)]!=S[i] and S[j+(j-i)]!=S[j]:
                    ans-=1
    print(ans)
main()

Buggy python submission (verdict: Time Limit Exceeded):
def main():
    N=int(input())
    S=input()
    ans=0
    for i in range(N-2):
        for j in range(i+1,N-1):
            if S[i]!=S[j]:
                k1=S[j+1:].count(S[i])
                k2=S[j+1:].count(S[j])
                ans=ans+len(S[j+1:])-k1-k2
            if j+(j-i)<N and S[i]!=S[j]:
                if S[j+(j-i)]!=S[i] and S[j+(j-i)]!=S[j]:
                    ans-=1
    print(ans)

main()

Fixed submission:
def main():
    N=int(input())
    S=input()
    k1=S.count("R")
    k2=S.count("B")
    ans=k1*k2*(len(S)-k1-k2)
    for i in range(N-2):
        for j in range(i+1,N-1):
            if j+(j-i)<N and S[i]!=S[j]:
                if S[j+(j-i)]!=S[i] and S[j+(j-i)]!=S[j]:
                    ans-=1
    print(ans)
main()

Buggy python submission (verdict: Time Limit Exceeded):
N=int(input())
S=input()
ans=0
for i in range(N-2):
    for j in range(i+1,N-1):
        if S[i]!=S[j]:
            k1=S[j+1:].count(S[i])
            k2=S[j+1:].count(S[j])
            ans=ans+len(S[j+1:])-k1-k2
        if j+(j-i)<N and S[i]!=S[j]:
            if S[j+(j-i)]!=S[i] and S[j+(j-i)]!=S[j]:
                ans-=1
            
print(ans)

Fixed submission:
def main():
    N=int(input())
    S=input()
    k1=S.count("R")
    k2=S.count("B")
    ans=k1*k2*(len(S)-k1-k2)
    for i in range(N-2):
        for j in range(i+1,N-1):
            if j+(j-i)<N and S[i]!=S[j]:
                if S[j+(j-i)]!=S[i] and S[j+(j-i)]!=S[j]:
                    ans-=1
    print(ans)
main()