Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
S1 = input()
S = [(a, p) for p, a in enumerate(S1)]
 
count = 0
for i in range(N):
    for k in range(i+1,N):
        if S[i][0] != S[k][0]:
            RGB = ['R','G','B']
            RGB.remove(S[i][0])
            RGB.remove(S[k][0])
            count += S1.count(RGB[0],k+1,N)
            if 2*k-i < N:
                if S[2*k-i][0]!= S[i][0] and S[2*k-i][0]!=S[k][0]:
                    count -= 1 
print(count)   

Fixed submission:
N = int(input())
S = list(input())
count = S.count("R")*S.count("B")*S.count("G")
for i in range(N):
    for j in range(i+1,N):
        if 2*j-i < N:
            if S[i]!=S[j] and S[2*j-i]!=S[i] and S[2*j-i]!=S[j]:
                count-=1
print(count)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
S1 = input()
S = [(a, p) for p, a in enumerate(S1)]

count = 0
for i in range(N):
    for k in range(i+1,N):
        if S[i][0] != S[k][0]:
            RGB = ['R','G','B']
            RGB.remove(S[i][0])
            RGB.remove(S[k][0])
            count += S1.count(RGB[0],k+1,N)
            if 2*k-i < N:
                if S[2*k-i][0]!= S[i][0] and S[2*k-i][0]!=S[k][0]:
                    count -= 1 
print(count)      

Fixed submission:
N = int(input())
S = list(input())
count = S.count("R")*S.count("B")*S.count("G")
for i in range(N):
    for j in range(i+1,N):
        if 2*j-i < N:
            if S[i]!=S[j] and S[2*j-i]!=S[i] and S[2*j-i]!=S[j]:
                count-=1
print(count)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
S1 = input()
S = [(a, p) for p, a in enumerate(S1)]
count = 0
for i in range(N):
    for k in range(i+1,N):
        if S[i][0] != S[k][0]:
            count += (N-k-1)-S1.count(S[i][0],k+1,N)-S1.count(S[k][0],k+1,N)
            if 2*k-i < N:
                if S[2*k-i][0]!= S[i][0] and S[2*k-i][0]!=S[k][0]:
                    count -= 1 
print(count)    

Fixed submission:
N = int(input())
S = list(input())
count = S.count("R")*S.count("B")*S.count("G")
for i in range(N):
    for j in range(i+1,N):
        if 2*j-i < N:
            if S[i]!=S[j] and S[2*j-i]!=S[i] and S[2*j-i]!=S[j]:
                count-=1
print(count)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
S1 = input()
S = [(a, p) for p, a in enumerate(S1)]
count = 0
for i in range(N):
    for k in range(i+1,N):
        if S[i][0] != S[k][0]:
            count += (N-k-1)-S1.count(S[i][0],k+1,N)-S1.count(S[k][0],k+1,N)
            if 2*k-i < N:
                if S[2*k-i][0]!= S[i][0] and S[2*k-i][0]!=S[k][0]:
                    count -= 1 
print(count)    

Fixed submission:
N = int(input())
S = list(input())
count = S.count("R")*S.count("B")*S.count("G")
for i in range(N):
    for j in range(i+1,N):
        if 2*j-i < N:
            if S[i]!=S[j] and S[2*j-i]!=S[i] and S[2*j-i]!=S[j]:
                count-=1
print(count)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
S = input()
S = [(a, p) for p, a in enumerate(S)]
count = 0
for i in range(N):
    for j in range(i+1,N):
        if S[i][0] != S[j][0]:
            for k in range(j+1,N):
                if S[i][0] != S[k][0] and S[j][0] != S[k][0] and j-i != k-j:
                    count+=1
print(count)

Fixed submission:
N = int(input())
S = list(input())
count = S.count("R")*S.count("B")*S.count("G")
for i in range(N):
    for j in range(i+1,N):
        if 2*j-i < N:
            if S[i]!=S[j] and S[2*j-i]!=S[i] and S[2*j-i]!=S[j]:
                count-=1
print(count)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
S = input()
S = [(a, p) for p, a in enumerate(S)]
count = 0
for i in range(N):
    for j in range(i+1,N):
        if S[i][0] != S[j][0]:
            for k in range(j+1,N):
                if S[i][0] != S[k][0] and S[j][0] != S[k][0] and j-i != k-j:
                    count+=1
print(count) 

Fixed submission:
N = int(input())
S = list(input())
count = S.count("R")*S.count("B")*S.count("G")
for i in range(N):
    for j in range(i+1,N):
        if 2*j-i < N:
            if S[i]!=S[j] and S[2*j-i]!=S[i] and S[2*j-i]!=S[j]:
                count-=1
print(count)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
S = input()
S = [(a, p) for p, a in enumerate(S)]
count = 0
for i in range(N):
    for j in range(i+1,N):
        for k in range(j+1,N):
            if S[i][0] != S[j][0] and S[i][0] != S[k][0] and S[j][0] != S[k][0] and j-i != k-j:
                count+=1
print(count)    

Fixed submission:
N = int(input())
S = list(input())
count = S.count("R")*S.count("B")*S.count("G")
for i in range(N):
    for j in range(i+1,N):
        if 2*j-i < N:
            if S[i]!=S[j] and S[2*j-i]!=S[i] and S[2*j-i]!=S[j]:
                count-=1
print(count)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
S = input()
S = [(a, p) for p, a in enumerate(S)]
count = 0
for i in range(N):
    for j in range(i+1,N):
        for k in range(j+1,N):
            if S[i][0] != S[j][0] and S[i][0] != S[k][0] and S[j][0] != S[k][0] and j-i != k-j:
                count+=1
print(count)    

Fixed submission:
N = int(input())
S = list(input())
count = S.count("R")*S.count("B")*S.count("G")
for i in range(N):
    for j in range(i+1,N):
        if 2*j-i < N:
            if S[i]!=S[j] and S[2*j-i]!=S[i] and S[2*j-i]!=S[j]:
                count-=1
print(count)