Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
s = input()
cnt = s.count('R')*s.count('G')*s.count('B')
for i in range(n-2):
    for j in range(i+1,n-1):
        if s[i] != s[j]:
            if 2*j-i <= n-1:
                if s[2*j-i] not in(s[i],s[j]):
                    cnt -= 1
print(cnt)

Fixed submission:
n = int(input())
s = input()
cnt = s.count('R')*s.count('G')*s.count('B')
for i in range(n-2):
    for j in range(i+1,n-1):
        if s[i] != s[j]:
            if 2*j-i > n-1:
                break
            if s[2*j-i] not in(s[i],s[j]):
                cnt -= 1
print(cnt)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
s = input()
cnt = 0
for i in range(n-2):
    for j in range(i+1,n-1):
        if s[i] != s[j]:
            if (s[i]+s[j]).count('R') == 0:
                cnt += s[j+1:n].count('R')
                if 2*j-i <= n-1:
                    if s[2*j-i] == 'R':
                       cnt -= 1
            elif (s[i]+s[j]).count('G') == 0:
                cnt += s[j+1:n].count('G')
                if 2*j-i <= n-1:
                    if s[2*j-i] == 'G':
                       cnt -= 1
            else:
                cnt += s[j+1:n].count('B')
                if 2*j-i <= n-1:
                    if s[2*j-i] == 'B':
                       cnt -= 1
print(cnt)

Fixed submission:
n = int(input())
s = input()
cnt = s.count('R')*s.count('G')*s.count('B')
for i in range(n-2):
    for j in range(i+1,n-1):
        if s[i] != s[j]:
            if 2*j-i > n-1:
                break
            if s[2*j-i] not in(s[i],s[j]):
                cnt -= 1
print(cnt)

Buggy python submission (verdict: Runtime Error):
n = int(input())
s = input()
cnt = 0
for i in range(n-2):
    for j in range(i+1,n-1):
        if s[i] != s[j]:
            if (s[i]+s[j]).count('R') == 0:
                cnt += s[j+1:n].count('R')
                if s[j+i] == 'R' and j-i > n-j:
                    cnt -= 1
            elif (s[i]+s[j]).count('G') == 0:
                cnt += s[j+1:n].count('G')
                if s[j+i] == 'G' and j-i > n-j:
                    cnt -= 1
            else:
                cnt += s[j+1:n].count('B')
                if s[j+i] == 'B' and j-i > n-j:
                    cnt -= 1
print(cnt)

Fixed submission:
n = int(input())
s = input()
cnt = s.count('R')*s.count('G')*s.count('B')
for i in range(n-2):
    for j in range(i+1,n-1):
        if s[i] != s[j]:
            if 2*j-i > n-1:
                break
            if s[2*j-i] not in(s[i],s[j]):
                cnt -= 1
print(cnt)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
s = input()
cnt = 0
for i in range(n-2):
    for j in range(i+1,n-1):
        if s[i] != s[j]:
            for k in range(j+1,n):
                if s[k] not in (s[i],s[j]):
                    if j-i != k-j:
                        cnt +=1
print(cnt)

Fixed submission:
n = int(input())
s = input()
cnt = s.count('R')*s.count('G')*s.count('B')
for i in range(n-2):
    for j in range(i+1,n-1):
        if s[i] != s[j]:
            if 2*j-i > n-1:
                break
            if s[2*j-i] not in(s[i],s[j]):
                cnt -= 1
print(cnt)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
s = input()
cnt = 0
for i in range(n-2):
    for j in range(i+1,n-1):
        if s[i] != s[j]:
            for k in range(j+1,n):
                if s[k] not in (s[i],s[j]) and j-i != k-j:
                    cnt +=1
print(cnt)

Fixed submission:
n = int(input())
s = input()
cnt = s.count('R')*s.count('G')*s.count('B')
for i in range(n-2):
    for j in range(i+1,n-1):
        if s[i] != s[j]:
            if 2*j-i > n-1:
                break
            if s[2*j-i] not in(s[i],s[j]):
                cnt -= 1
print(cnt)