Buggy python submission (verdict: Time Limit Exceeded):
N=int(input())
S =input()
count =0

Bcount = S.count("B")
for i in range(0,N-1):
    for j in range(i+1,N):
        if (S[i] == "R" and S[j] == "G") or (S[i] == "G" and S[j] == "R") :
            count += Bcount
            if j+(j-i) <N  and S[j+(j-i)] == "B":
                count  -=1
            if i-(j-i) >=0 and S[i-(j-i)] =="B":
                count -=1
            if (i+j)%2 ==0 and S[int((i+j)/2)] == "B":
                count -=1
print(count)

Fixed submission:
N=int(input())
S =input()
count =0

Bcount = S.count("B")
for i in range(0,N-1):
    for j in range(i+1,N):
        if (S[i] == "R" and S[j] == "G") or (S[i] == "G" and S[j] == "R") :
            count += Bcount
            if j+(j-i) <N  and S[j+(j-i)] == "B":
                count  -=1
            if i-(j-i) >=0 and S[i-(j-i)] =="B":
                count -=1
            if (i+j)%2 ==0 and S[int((i+j)/2)] == "B":
                count -=1
print(count)

Buggy python submission (verdict: Time Limit Exceeded):
N=int(input())
S =input()
count =0
Bcount = S.count("B")
for i in range(0,N-1):
    for j in range(i+1,N):
        if (S[i] == "R" and S[j] == "G") or (S[i] == "G" and S[j] == "R") :
            count += Bcount
            if j+(j-i) <N  and S[j+(j-i)] == "B":
                count  -=1
            if i-(j-i) >=0 and S[i-(j-i)] =="B":
                count -=1
            if (i+j)%2 ==0 and S[int((i+j)/2)] == "B":
                count -=1
print(count)

Fixed submission:
N=int(input())
S =input()
count =0

Bcount = S.count("B")
for i in range(0,N-1):
    for j in range(i+1,N):
        if (S[i] == "R" and S[j] == "G") or (S[i] == "G" and S[j] == "R") :
            count += Bcount
            if j+(j-i) <N  and S[j+(j-i)] == "B":
                count  -=1
            if i-(j-i) >=0 and S[i-(j-i)] =="B":
                count -=1
            if (i+j)%2 ==0 and S[int((i+j)/2)] == "B":
                count -=1
print(count)

Buggy python submission (verdict: Time Limit Exceeded):
N=int(input())
S =input()
count =0
for i in range(0,N-2):
    stack =["R","G","B"]
    stack.remove(S[i])
    for j in range(i,N-1):
        dis = j -i
        if S[i] == S[j]:
            continue
        stack.remove(S[j])
        for k in range(j,N):
            if k -j == dis:
                continue
            if S[k] == stack[0]:
                count += 1
        stack.append(S[j])
print(count)

Fixed submission:
N=int(input())
S =input()
count =0

Bcount = S.count("B")
for i in range(0,N-1):
    for j in range(i+1,N):
        if (S[i] == "R" and S[j] == "G") or (S[i] == "G" and S[j] == "R") :
            count += Bcount
            if j+(j-i) <N  and S[j+(j-i)] == "B":
                count  -=1
            if i-(j-i) >=0 and S[i-(j-i)] =="B":
                count -=1
            if (i+j)%2 ==0 and S[int((i+j)/2)] == "B":
                count -=1
print(count)

Buggy python submission (verdict: Time Limit Exceeded):
N=int(input())
S =input()
count =0
for i in range(0,N-2):
    stack =["R","G","B"]
    stack.remove(S[i])
    for j in range(i,N-1):
        dis = j -i
        if S[i] == S[j]:
            continue
        stack.remove(S[j])
        for k in range(j,N):
            if k -j == dis:
                continue
            if S[k] == stack[0]:
                count += 1
        stack.append(S[j])
print(count)

Fixed submission:
N=int(input())
S =input()
count =0

Bcount = S.count("B")
for i in range(0,N-1):
    for j in range(i+1,N):
        if (S[i] == "R" and S[j] == "G") or (S[i] == "G" and S[j] == "R") :
            count += Bcount
            if j+(j-i) <N  and S[j+(j-i)] == "B":
                count  -=1
            if i-(j-i) >=0 and S[i-(j-i)] =="B":
                count -=1
            if (i+j)%2 ==0 and S[int((i+j)/2)] == "B":
                count -=1
print(count)