Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
s = input()
r_count = s.count('R')
g_count = s.count('G')
b_count = s.count('B')

count=0
for i in range(n):
    a = s[i]
    for j in range(i+1,n):
        if (2*j-i)>(n-1):
            continue
        b=s[j]
        c=s[2*j-i]
        if a!=b and b!=c and a!=c:
            count+=1
print(r_count*g_count*b_count-count)

Fixed submission:
n = int(input())
s = input()
r_count = s.count('R')
g_count = s.count('G')
b_count = s.count('B')

count=0
for i in range(n):
    a = s[i]
    for j in range(i+1,n):
        if (2*j-i)>(n-1):
            continue
        b=s[j]
        c=s[2*j-i]
        if a!=b and b!=c and a!=c:
            count+=1
print(r_count*g_count*b_count-count)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
s = input()
r_count = s.count('R')
g_count = s.count('G')
b_count = s.count('B')

count=0
for i in range(n):
    for j in range(i+1,n):
        if (2*j-i)>(n-1):
            continue
        if s[i]!=s[j]!=s[2*j-i] and s[j]!=s[2*j-i] and s[i]!=s[2*j-i]:
            count+=1
print(r_count*g_count*b_count-count)

Fixed submission:
n = int(input())
s = input()
r_count = s.count('R')
g_count = s.count('G')
b_count = s.count('B')

count=0
for i in range(n):
    a = s[i]
    for j in range(i+1,n):
        if (2*j-i)>(n-1):
            continue
        b=s[j]
        c=s[2*j-i]
        if a!=b and b!=c and a!=c:
            count+=1
print(r_count*g_count*b_count-count)

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

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

Fixed submission:
n = int(input())
s = input()
r_count = s.count('R')
g_count = s.count('G')
b_count = s.count('B')

count=0
for i in range(n):
    a = s[i]
    for j in range(i+1,n):
        if (2*j-i)>(n-1):
            continue
        b=s[j]
        c=s[2*j-i]
        if a!=b and b!=c and a!=c:
            count+=1
print(r_count*g_count*b_count-count)

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

print(sum((j-i)!=(k-j) and s[i]!=s[j] and s[i]!=s[k] and s[j]!=s[k] for i in range(n) for j in range(i,n) for k in range(j,n)))


Fixed submission:
n = int(input())
s = input()
r_count = s.count('R')
g_count = s.count('G')
b_count = s.count('B')

count=0
for i in range(n):
    a = s[i]
    for j in range(i+1,n):
        if (2*j-i)>(n-1):
            continue
        b=s[j]
        c=s[2*j-i]
        if a!=b and b!=c and a!=c:
            count+=1
print(r_count*g_count*b_count-count)

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

ans=0
for i in range(n):
    for j in range(i,n):
        for k in range(j,n):
            if (j-i)!=(k-j) and s[i]!=s[j] and s[i]!=s[k] and s[j]!=s[k]:
                ans +=1

print(ans)


Fixed submission:
n = int(input())
s = input()
r_count = s.count('R')
g_count = s.count('G')
b_count = s.count('B')

count=0
for i in range(n):
    a = s[i]
    for j in range(i+1,n):
        if (2*j-i)>(n-1):
            continue
        b=s[j]
        c=s[2*j-i]
        if a!=b and b!=c and a!=c:
            count+=1
print(r_count*g_count*b_count-count)