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)
    elif S[i] == 'G':
        G.append(i+1)
    else:
        B.append(i+1)
ans = 0
count = 0
for k in R:
    for j in G:
        for i in B:
            fr = 0
            ab = [k,j,i]
            ab.sort()
            if ab[2] - ab[1] == ab[1] - ab[0]:
                pass
            else:
                ans += 1
print(ans)

Fixed submission:
N = int(input())
N -= 1
S = str(input())
count = S.count('R') * S.count('G') * S.count('B')
for i in range(N):
    for j in range(i,N+1):
        k = 2*j - i
        if k > N:
            pass
        elif S[i] == S[j] or S[i] == S[k] or S[j] == S[k]:
            pass
        else:
            count -= 1
print(count)

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)
    elif S[i] == 'G':
        G.append(i+1)
    else:
        B.append(i+1)
ans = 0
count = 0
for k in R:
    for j in G:
        for i in B:
            fr = 0
            ab = [k,j,i]
            ab.sort()
            if ab[2] - ab[1] == ab[1] - ab[0]:
                fr += 1

            if fr == 0:
                ans += 1
print(ans)

Fixed submission:
N = int(input())
N -= 1
S = str(input())
count = S.count('R') * S.count('G') * S.count('B')
for i in range(N):
    for j in range(i,N+1):
        k = 2*j - i
        if k > N:
            pass
        elif S[i] == S[j] or S[i] == S[k] or S[j] == S[k]:
            pass
        else:
            count -= 1
print(count)

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)
    elif S[i] == 'G':
        G.append(i+1)
    else:
        B.append(i+1)
ans = 0
count = 0
for k in R:
    for j in G:
        for i in B:
            fr = 0
            ab = [k,j,i]
            ab.sort()
            if ab[2] - ab[1] == ab[1] - ab[0]:
                fr += 1

            if fr == 0:
                ans += 1
print(ans)

Fixed submission:
N = int(input())
N -= 1
S = str(input())
count = S.count('R') * S.count('G') * S.count('B')
for i in range(N):
    for j in range(i,N+1):
        k = 2*j - i
        if k > N:
            pass
        elif S[i] == S[j] or S[i] == S[k] or S[j] == S[k]:
            pass
        else:
            count -= 1
print(count)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
S = str(input())
All = [i for i in range(1,N+1)]
R = []
G = []
B = []
for i in range(N):
    if S[i] == 'R':
        R.append(i+1)
    elif S[i] == 'G':
        G.append(i+1)
    else:
        B.append(i+1)
ans = 0
count = 0
for k in R:
    for j in G:
        for i in B:
            fr = 0
            ab = [k,j,i]
            ab.sort()
            if ab[2] - ab[1] == ab[1] - ab[0]:
                fr += 1

            if fr == 0:
                ans += 1
print(ans)

Fixed submission:
N = int(input())
N -= 1
S = str(input())
count = S.count('R') * S.count('G') * S.count('B')
for i in range(N):
    for j in range(i,N+1):
        k = 2*j - i
        if k > N:
            pass
        elif S[i] == S[j] or S[i] == S[k] or S[j] == S[k]:
            pass
        else:
            count -= 1
print(count)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
S = str(input())
All = [i for i in range(1,N+1)]
R = []
G = []
B = []
for i in range(N):
    if S[i] == 'R':
        R.append(i+1)
    elif S[i] == 'G':
        G.append(i+1)
    else:
        B.append(i+1)
ans = 0
count = 0
for k in R:
    for j in G:
        for i in B:
            fr = 0
            if k < j:
                fr += 1
            if j < i:
                fr += 1
            if k - j - 1 == j - i - 1:
                fr += 1

            if fr == 0:
                ans += 1

for k in R:
    for j in B:
        for i in G:
            fr = 0
            if k < j:
                fr += 1
            if j < i:
                fr += 1
            if k - j == j - i:
                fr += 1

            if fr == 0:
                ans += 1

for k in G:
    for j in R:
        for i in B:
            fr = 0
            if k < j:
                fr += 1
            if j < i:
                fr += 1
            if k - j - 1 == j - i - 1:
                fr += 1

            if fr == 0:
                ans += 1

for k in G:
    for j in B:
        for i in R:
            fr = 0
            if k < j:
                fr += 1
            if j < i:
                fr += 1
            if k - j - 1 == j - i - 1:
                fr += 1

            if fr == 0:
                ans += 1

for k in B:
    for j in R:
        for i in G:
            fr = 0
            if k < j:
                fr += 1
            if j < i:
                fr += 1
            if k - j - 1 == j - i - 1:
                fr += 1

            if fr == 0:
                ans += 1

for k in B:
    for j in G:
        for i in R:
            fr = 0
            if k < j:
                fr += 1
            if j < i:
                fr += 1
            if k - j - 1 == j - i - 1:
                fr += 1

            if fr == 0:
                ans += 1

print(ans)

Fixed submission:
N = int(input())
N -= 1
S = str(input())
count = S.count('R') * S.count('G') * S.count('B')
for i in range(N):
    for j in range(i,N+1):
        k = 2*j - i
        if k > N:
            pass
        elif S[i] == S[j] or S[i] == S[k] or S[j] == S[k]:
            pass
        else:
            count -= 1
print(count)