Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
s = input()
d = {'R':0,'G':0,'B':0}
for i in s:
    d[i] += 1
c = d['R'] * d['G'] * d['B']

for i in range(n):
    for j in range(i+1,n):
        k = 2 * j - i
        if(k <= j or k >= n):continue
        if(s[i] == s[j]):continue
        if(s[j] == s[k]):continue
        if(s[i] == s[k]):continue
        c -= 1

print(c)

Fixed submission:
n = int(input())
s = input()
d = [0,0,0]
for i in s:
    if(i == 'R'):d[0] += 1
    elif(i == 'G'):d[1] += 1
    elif(i == 'B'):d[2] += 1
c = d[0] * d[1] * d[2]

for i in range(n):
    for j in range(i+1,n):
        k = 2 * j - i
        if(k >= n):continue
        if(s[i] == s[j]):continue
        if(s[j] == s[k]):continue
        if(s[i] == s[k]):continue
        c -= 1

print(c)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
s = input()
d = {'R':0,'G':0,'B':0}
for i in s:
    d[i] += 1
c = d['R'] * d['G'] * d['B']

for i in range(n):
    for j in range(i+1,n):
        k = 2 * j - i
        if(k <= j or k >= n):continue
        if(s[i] != s[j] and s[j] != s[k] and s[i] != s[k]):c -= 1

print(c)

Fixed submission:
n = int(input())
s = input()
d = [0,0,0]
for i in s:
    if(i == 'R'):d[0] += 1
    elif(i == 'G'):d[1] += 1
    elif(i == 'B'):d[2] += 1
c = d[0] * d[1] * d[2]

for i in range(n):
    for j in range(i+1,n):
        k = 2 * j - i
        if(k >= n):continue
        if(s[i] == s[j]):continue
        if(s[j] == s[k]):continue
        if(s[i] == s[k]):continue
        c -= 1

print(c)

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

c = s.count('R') * s.count('G') * s.count('B')

for i in range(n):
    for j in range(i+1,n):
        k = 2 * j - i
        if(k <= j or k >= n):continue
        if(s[i] != s[j] and s[j] != s[k] and s[i] != s[k]):c -= 1

print(c)

Fixed submission:
n = int(input())
s = input()
d = [0,0,0]
for i in s:
    if(i == 'R'):d[0] += 1
    elif(i == 'G'):d[1] += 1
    elif(i == 'B'):d[2] += 1
c = d[0] * d[1] * d[2]

for i in range(n):
    for j in range(i+1,n):
        k = 2 * j - i
        if(k >= n):continue
        if(s[i] == s[j]):continue
        if(s[j] == s[k]):continue
        if(s[i] == s[k]):continue
        c -= 1

print(c)

Buggy python submission (verdict: Runtime Error):
n = int(input())
s = input()

r = [0] * n
g = [0] * n
b = [0] * n
dc = {'R':[0]*n,'G':[0]*n,'B':[0]*n}
for i in range(n-1)[::-1]:
    dc['R'][i] = dc['R'][i + 1]
    dc['G'][i] = dc['G'][i + 1]
    dc['B'][i] = dc['B'][i + 1]
    dc[s[i+1]][i] += 1
# print(dc['R'])
# print(dc['G'])
# print(dc['B'])
dcc = {('R','G'):'B',('R','B'):'G',('B','G'):'R',('G','R'):'B',('B','R'):'G',('G','B'):'R'}
if(n <= 3):print(0)
else:
    c = 0
    for i in range(n):
        for j in range(i+1,n):
            if(s[i] == s[j]):continue
            d = j - i
            c += dc[dcc[(s[i],s[j])]][j]
            k = j + d
            if(k < n):
                if(s[k] == dcc[(s[i],s[j])]):c -= 1
print(c)

Fixed submission:
n = int(input())
s = input()
d = [0,0,0]
for i in s:
    if(i == 'R'):d[0] += 1
    elif(i == 'G'):d[1] += 1
    elif(i == 'B'):d[2] += 1
c = d[0] * d[1] * d[2]

for i in range(n):
    for j in range(i+1,n):
        k = 2 * j - i
        if(k >= n):continue
        if(s[i] == s[j]):continue
        if(s[j] == s[k]):continue
        if(s[i] == s[k]):continue
        c -= 1

print(c)

Buggy python submission (verdict: Runtime Error):
n = int(input())
s = input()

r = [0] * n
g = [0] * n
b = [0] * n
dc = {'R':[0]*n,'G':[0]*n,'B':[0]*n}
for i in range(n-1):
    dc['R'][i] = dc['R'][i + 1]
    dc['G'][i] = dc['G'][i + 1]
    dc['B'][i] = dc['B'][i + 1]
    dc[s[i]] += 1
# print(r)
# print(g)
# print(b)
dcc = {('R','G'):'B',('R','B'):'G',('B','G'):'R',('G','R'):'B',('B','R'):'G',('G','B'):'R'}
if(n <= 3):print(0)
else:
    c = 0
    for i in range(n):
        for j in range(i+1,n):
            if(s[i] == s[j]):continue
            d = j - i
            c += dc[dcc[(s[i],s[j])]][j]
            k = j + d
            if(k < n):
                if(s[k] == dcc[(s[i],s[j])]):c -= 1
print(c)

Fixed submission:
n = int(input())
s = input()
d = [0,0,0]
for i in s:
    if(i == 'R'):d[0] += 1
    elif(i == 'G'):d[1] += 1
    elif(i == 'B'):d[2] += 1
c = d[0] * d[1] * d[2]

for i in range(n):
    for j in range(i+1,n):
        k = 2 * j - i
        if(k >= n):continue
        if(s[i] == s[j]):continue
        if(s[j] == s[k]):continue
        if(s[i] == s[k]):continue
        c -= 1

print(c)

Buggy python submission (verdict: Runtime Error):
n = int(input())
s = input()

r = [0] * n
g = [0] * n
b = [0] * n
dc = {'R':[0]*n,'G':[0]*n,'B':[0]*n}
for i in range(n):
    dc['R'][i] = s[i+1:].count('R')
    dc['G'][i] = s[i+1:].count('G')
    dc['B'][i] = s[i+1:].count('B')
# print(r)
# print(g)
# print(b)
dcc = {('R','G'):'B',('R','B'):'G',('B','G'):'R',('G','R'):'B',('B','R'):'G',('G','B'):'R'}
if(n <= 3):print(0)
else:
    c = 0
    for i in range(n):
        for j in range(i+1,n):
            if(s[i] == s[j]):continue
            d = j - i
            c += dc[dcc[(s[i],s[j])]][j]
            k = j + d
            if(k < n):
                if(s[k] == dcc[(s[i],s[j])]):c -= 1
print(c)

Fixed submission:
n = int(input())
s = input()
d = [0,0,0]
for i in s:
    if(i == 'R'):d[0] += 1
    elif(i == 'G'):d[1] += 1
    elif(i == 'B'):d[2] += 1
c = d[0] * d[1] * d[2]

for i in range(n):
    for j in range(i+1,n):
        k = 2 * j - i
        if(k >= n):continue
        if(s[i] == s[j]):continue
        if(s[j] == s[k]):continue
        if(s[i] == s[k]):continue
        c -= 1

print(c)