Buggy python submission (verdict: Runtime Error):
from numba import njit
from sys import stdin
def S(): return stdin.readline().rstrip()
def I(): return int(stdin.readline().rstrip())
 
@njit
def main():
    n = I()
    s = list(S())
    ans = 0
    for i in range(n-2):
        color = {s[i]}
        for j in range(i+1,n-1):
            if not s[j] in color:
                color.add(s[j])
                for k in range(j+1,n):
                    if not s[k] in color:
                        if k-j != j-i:
                            ans += 1
                color = {s[i]}
    
    print(ans)

if __name__ == '__main__':
    main()

Fixed submission:
from sys import stdin
def S(): return stdin.readline().rstrip()
def I(): return int(stdin.readline().rstrip())
 
n = I()
s = list(S())

r = s.count('R')
g = s.count('G')
b = s.count('B')
 
ans = r*g*b
for i in range(n-1):
    for j in range(1,n):
        if i-j<0 or n<=i+j:
            break
        else:
            if s[i-j]!=s[i] and s[i]!=s[i+j] and s[i-j]!=s[i+j]:
                ans-=1
 
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
from sys import stdin
def S(): return stdin.readline().rstrip()
def I(): return int(stdin.readline().rstrip())
 
def main():
    n = I()
    s = list(S())
    ans = 0
    for i in range(n-2):
        color = {s[i]}
        for j in range(i+1,n-1):
            if not s[j] in color:
                color.add(s[j])
                for k in range(j+1,n):
                    if not s[k] in color:
                        if k-j != j-i:
                            ans += 1
                color = {s[i]}
    
    print(ans)

if __name__ == '__main__':
    main()

Fixed submission:
from sys import stdin
def S(): return stdin.readline().rstrip()
def I(): return int(stdin.readline().rstrip())
 
n = I()
s = list(S())

r = s.count('R')
g = s.count('G')
b = s.count('B')
 
ans = r*g*b
for i in range(n-1):
    for j in range(1,n):
        if i-j<0 or n<=i+j:
            break
        else:
            if s[i-j]!=s[i] and s[i]!=s[i+j] and s[i-j]!=s[i+j]:
                ans-=1
 
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
from sys import stdin
def S(): return stdin.readline().rstrip()
def I(): return int(stdin.readline().rstrip())
 
n = I()
s = list(S())
 
ans = 0
for i in range(n-2):
    color = {s[i]}
    for j in range(i+1,n-1):
        if not s[j] in color:
            color.add(s[j])
            for k in range(j+1,n):
                if not s[k] in color:
                    if k-j != j-i:
                        ans += 1
            color = {s[i]}
 
print(ans)

Fixed submission:
from sys import stdin
def S(): return stdin.readline().rstrip()
def I(): return int(stdin.readline().rstrip())
 
n = I()
s = list(S())

r = s.count('R')
g = s.count('G')
b = s.count('B')
 
ans = r*g*b
for i in range(n-1):
    for j in range(1,n):
        if i-j<0 or n<=i+j:
            break
        else:
            if s[i-j]!=s[i] and s[i]!=s[i+j] and s[i-j]!=s[i+j]:
                ans-=1
 
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
from sys import stdin
def S(): return stdin.readline().rstrip()
def I(): return int(stdin.readline().rstrip())

n = I()
s = list(S())

ans = 0
for i in range(n-2):
    color = {s[i]}
    for j in range(i+1,n-1):
        if not s[j] in color:
            color.add(s[j])
            for k in range(j+1,n):
                if not s[k] in color:
                    if i+k-2*j:
                        ans += 1
            color = {s[i]}

print(ans)

Fixed submission:
from sys import stdin
def S(): return stdin.readline().rstrip()
def I(): return int(stdin.readline().rstrip())
 
n = I()
s = list(S())

r = s.count('R')
g = s.count('G')
b = s.count('B')
 
ans = r*g*b
for i in range(n-1):
    for j in range(1,n):
        if i-j<0 or n<=i+j:
            break
        else:
            if s[i-j]!=s[i] and s[i]!=s[i+j] and s[i-j]!=s[i+j]:
                ans-=1
 
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
from sys import stdin
def S(): return stdin.readline().rstrip()
def I(): return int(stdin.readline().rstrip())

n = I()
s = list(S())

ans = 0
for i in range(n-2):
    color = {s[i]}
    for j in range(i+1,n-1):
        if not s[j] in color:
            color.add(s[j])
            for k in range(j+1,n):
                if not s[k] in color:
                    if k-j != j-i:
                        ans += 1
            color = {s[i]}

print(ans)

Fixed submission:
from sys import stdin
def S(): return stdin.readline().rstrip()
def I(): return int(stdin.readline().rstrip())
 
n = I()
s = list(S())

r = s.count('R')
g = s.count('G')
b = s.count('B')
 
ans = r*g*b
for i in range(n-1):
    for j in range(1,n):
        if i-j<0 or n<=i+j:
            break
        else:
            if s[i-j]!=s[i] and s[i]!=s[i+j] and s[i-j]!=s[i+j]:
                ans-=1
 
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
from sys import stdin
def S(): return stdin.readline().rstrip()
def I(): return int(stdin.readline().rstrip())

n = I()
s = list(S())

ans = 0
for i in range(len(s)-2):
    color = {s[i]}
    for j in range(i+1,len(s)-1):
        if not s[j] in color:
            color.add(s[j])
            for k in range(j+1,len(s)):
                if not s[k] in color:
                    if k-j != j-i:
                        ans += 1
            color = {s[i]}

print(ans)

Fixed submission:
from sys import stdin
def S(): return stdin.readline().rstrip()
def I(): return int(stdin.readline().rstrip())
 
n = I()
s = list(S())

r = s.count('R')
g = s.count('G')
b = s.count('B')
 
ans = r*g*b
for i in range(n-1):
    for j in range(1,n):
        if i-j<0 or n<=i+j:
            break
        else:
            if s[i-j]!=s[i] and s[i]!=s[i+j] and s[i-j]!=s[i+j]:
                ans-=1
 
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
from copy import deepcopy
from sys import stdin
def S(): return stdin.readline().rstrip()
def I(): return int(stdin.readline().rstrip())

n = I()
s = list(S())

ans = 0
for i in range(len(s)-2):
    color = set()
    color.add(s[i])
    for j in range(i+1,len(s)-1):
        if not s[j] in color:
            buff = deepcopy(color)
            buff.add(s[j])
            for k in range(j+1,len(s)):
                if not s[k] in buff:
                    if k-j != j-i:
                        ans += 1

print(ans)

Fixed submission:
from sys import stdin
def S(): return stdin.readline().rstrip()
def I(): return int(stdin.readline().rstrip())
 
n = I()
s = list(S())

r = s.count('R')
g = s.count('G')
b = s.count('B')
 
ans = r*g*b
for i in range(n-1):
    for j in range(1,n):
        if i-j<0 or n<=i+j:
            break
        else:
            if s[i-j]!=s[i] and s[i]!=s[i+j] and s[i-j]!=s[i+j]:
                ans-=1
 
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
from copy import deepcopy
from sys import stdin
def S(): return stdin.readline().rstrip()
def I(): return int(stdin.readline().rstrip())

n = I()
s = list(S())

s0 = {'R','G','B'}
s1 = deepcopy(s0)
ans = 0
for i in range(len(s)-2):
    s1.remove(s[i])
    for j in range(i+1,len(s)-1):
        s2 = deepcopy(s1)
        if s[j] in s2:
            s2.remove(s[j])
            for k in range(j+1,len(s)):
                if s[k] in s2:
                    if k-j != j-i:
                        ans += 1
    s1 = deepcopy(s0)

print(ans)

Fixed submission:
from sys import stdin
def S(): return stdin.readline().rstrip()
def I(): return int(stdin.readline().rstrip())
 
n = I()
s = list(S())

r = s.count('R')
g = s.count('G')
b = s.count('B')
 
ans = r*g*b
for i in range(n-1):
    for j in range(1,n):
        if i-j<0 or n<=i+j:
            break
        else:
            if s[i-j]!=s[i] and s[i]!=s[i+j] and s[i-j]!=s[i+j]:
                ans-=1
 
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
from sys import stdin
def S(): return stdin.readline().rstrip()
def I(): return int(stdin.readline().rstrip())

n = I()
s = list(S())
sj = s[1:]

c = 0
for i in s:
    sk = sj[1:]
    if len(sk) <= 0:
        break
    cj = 0
    for j in sj:
        cj += 1
        if len(sk) <= 0:
            break
        if i != j:
            ck = 0
            for k in sk:
                ck += 1
                if i!=k and j!=k and cj != ck:
                    c += 1
        sk.pop(0)
    sj.pop(0)

print(c)

Fixed submission:
from sys import stdin
def S(): return stdin.readline().rstrip()
def I(): return int(stdin.readline().rstrip())
 
n = I()
s = list(S())

r = s.count('R')
g = s.count('G')
b = s.count('B')
 
ans = r*g*b
for i in range(n-1):
    for j in range(1,n):
        if i-j<0 or n<=i+j:
            break
        else:
            if s[i-j]!=s[i] and s[i]!=s[i+j] and s[i-j]!=s[i+j]:
                ans-=1
 
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
from copy import deepcopy
from sys import stdin
def S(): return stdin.readline().rstrip()
def I(): return int(stdin.readline().rstrip())

n = I()
s = list(S())
sj = deepcopy(s) 

c = 0
for i in s:
    sj.pop(0)
    sk = deepcopy(sj)
    if len(sk) <= 0:
        break
    cj = 0
    for j in sj:
        cj += 1
        sk.pop(0)
        if len(sk) <= 0:
            break
        if i != j:
            ck = 0
            for k in sk:
                ck += 1
                if i!=k and j!=k and cj != ck:
                    c += 1

print(c)

Fixed submission:
from sys import stdin
def S(): return stdin.readline().rstrip()
def I(): return int(stdin.readline().rstrip())
 
n = I()
s = list(S())

r = s.count('R')
g = s.count('G')
b = s.count('B')
 
ans = r*g*b
for i in range(n-1):
    for j in range(1,n):
        if i-j<0 or n<=i+j:
            break
        else:
            if s[i-j]!=s[i] and s[i]!=s[i+j] and s[i-j]!=s[i+j]:
                ans-=1
 
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
from copy import deepcopy
from sys import stdin
def S(): return stdin.readline().rstrip()
def I(): return int(stdin.readline().rstrip())

n = I()
s = list(S())
sj = deepcopy(s) 

c = 0
for i in s:
    sj.pop(0)
    sk = deepcopy(sj)
    if len(sk) <= 0:
        break
    cj = 0
    for j in sj:
        cj += 1
        sk.pop(0)
        if i != j:
            ck = 0
            for k in sk:
                ck += 1
                if i!=k and j!=k and cj != ck:
                    c += 1

print(c)

Fixed submission:
from sys import stdin
def S(): return stdin.readline().rstrip()
def I(): return int(stdin.readline().rstrip())
 
n = I()
s = list(S())

r = s.count('R')
g = s.count('G')
b = s.count('B')
 
ans = r*g*b
for i in range(n-1):
    for j in range(1,n):
        if i-j<0 or n<=i+j:
            break
        else:
            if s[i-j]!=s[i] and s[i]!=s[i+j] and s[i-j]!=s[i+j]:
                ans-=1
 
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
from copy import deepcopy
from sys import stdin

def S(): return stdin.readline().rstrip()
def I(): return int(stdin.readline().rstrip())
def LS(): return list(stdin.readline().rstrip().split())
def LI(): return list(map(int,stdin.readline().rstrip().split()))
def R(x):
    r = round(x)
    if r+0.5 <= x:
        r += 1
    return r

n = I()
s = S()

ans = 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] != s[i] and s[k] != s[j]:
                    if j-i != k-j:
                        ans += 1

print(ans)

Fixed submission:
from sys import stdin
def S(): return stdin.readline().rstrip()
def I(): return int(stdin.readline().rstrip())
 
n = I()
s = list(S())

r = s.count('R')
g = s.count('G')
b = s.count('B')
 
ans = r*g*b
for i in range(n-1):
    for j in range(1,n):
        if i-j<0 or n<=i+j:
            break
        else:
            if s[i-j]!=s[i] and s[i]!=s[i+j] and s[i-j]!=s[i+j]:
                ans-=1
 
print(ans)

Buggy python submission (verdict: Runtime Error):
def S(): return stdin.readline().rstrip()
def I(): return int(stdin.readline().rstrip())


n = I()
s = S()

ans = 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] != s[i] and s[k] != s[j]:
                    if j-i != k-j:
                        ans += 1

print(ans)

Fixed submission:
from sys import stdin
def S(): return stdin.readline().rstrip()
def I(): return int(stdin.readline().rstrip())
 
n = I()
s = list(S())

r = s.count('R')
g = s.count('G')
b = s.count('B')
 
ans = r*g*b
for i in range(n-1):
    for j in range(1,n):
        if i-j<0 or n<=i+j:
            break
        else:
            if s[i-j]!=s[i] and s[i]!=s[i+j] and s[i-j]!=s[i+j]:
                ans-=1
 
print(ans)