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

positions = {}
positions['R'] = [i for i in range(n) if s[i]=='R']
positions['G'] = [i for i in range(n) if s[i]=='G']
positions['B'] = [i for i in range(n) if s[i]=='B']
positions['RG'] = sorted(positions['R']+positions['G'])
positions['RB'] = sorted(positions['R']+positions['B'])
positions['GB'] = sorted(positions['G']+positions['B'])

for p1 in range(n-3):
    if s[p1] == 'R':
        pos2 = [p for p in positions['GB'] if p > p1]
    elif s[p1] == 'G':
        pos2 = [p for p in positions['RB'] if p > p1]
    else:
        pos2 = [p for p in positions['RG'] if p > p1]

    for p2 in pos2:
        if s[p1] == 'R' and s[p2] == 'G':
            pos3 = [p for p in positions['B'] if p > p2]
        elif s[p1] == 'R' and s[p2] == 'B':
            pos3 = [p for p in positions['G'] if p > p2]
        elif s[p1] == 'G' and s[p2] == 'B':
            pos3 = [p for p in positions['R'] if p > p2]
        elif s[p1] == 'G' and s[p2] == 'R':
            pos3 = [p for p in positions['B'] if p > p2]
        elif s[p1] == 'B' and s[p2] == 'R':
            pos3 = [p for p in positions['G'] if p > p2]
        elif s[p1] == 'B' and s[p2] == 'G':
            pos3 = [p for p in positions['R'] if p > p2]
        
        for p3 in pos3:             
            if (p1-p2 != p2-p3):
                ans += 1
print(ans)

Fixed submission:
n = int(input())
s = input()
dup = 0
r = s.count('R')
g = s.count('G')
b = s.count('B')

for i in range(n):
    for j in range(i+1, n):
        k = 2*j - i
        if k < n:
            #print(i,j,k)
            if (s[i] != s[j]) and (s[j] != s[k]) and (s[i] != s[k]):
                #print(s[i], s[j], s[k])
                dup += 1
print(r*g*b - dup)

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

positions = {}
positions['R'] = [i for i in range(n) if s[i]=='R']
positions['G'] = [i for i in range(n) if s[i]=='G']
positions['B'] = [i for i in range(n) if s[i]=='B']
positions['RG'] = sorted(positions['R']+positions['G'])
positions['RB'] = sorted(positions['R']+positions['B'])
positions['GB'] = sorted(positions['G']+positions['B'])

for p1 in range(n-3):
    if s[p1] == 'R':
        pos2 = positions['GB']
    elif s[p1] == 'G':
        pos2 = positions['RB']
    else:
        pos2 = positions['RG']

    for p2 in pos2:
        if p2 > p1:
            if s[p1] == 'R' and s[p2] == 'G':
                pos3 = positions['B']
            elif s[p1] == 'R' and s[p2] == 'B':
                pos3 = positions['G']
            elif s[p1] == 'G' and s[p2] == 'B':
                pos3 = positions['R']
            elif s[p1] == 'G' and s[p2] == 'R':
                pos3 = positions['B']
            elif s[p1] == 'B' and s[p2] == 'R':
                pos3 = positions['G']
            elif s[p1] == 'B' and s[p2] == 'G':
                pos3 = positions['R']
            
            for p3 in pos3:
                if p3 > p2:                
                    if (p1-p2 != p2-p3):
                        ans += 1
print(ans)

Fixed submission:
n = int(input())
s = input()
dup = 0
r = s.count('R')
g = s.count('G')
b = s.count('B')

for i in range(n):
    for j in range(i+1, n):
        k = 2*j - i
        if k < n:
            #print(i,j,k)
            if (s[i] != s[j]) and (s[j] != s[k]) and (s[i] != s[k]):
                #print(s[i], s[j], s[k])
                dup += 1
print(r*g*b - dup)

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

positions = {}
positions['R'] = [i for i in range(n) if s[i]=='R']
positions['G'] = [i for i in range(n) if s[i]=='G']
positions['B'] = [i for i in range(n) if s[i]=='B']
positions['RG'] = sorted(positions['R']+positions['G'])
positions['RB'] = sorted(positions['R']+positions['B'])
positions['GB'] = sorted(positions['G']+positions['B'])

for p1 in range(n-3):
    if s[p1] == 'R':
        pos2 = positions['GB']
    elif s[p1] == 'G':
        pos2 = positions['RB']
    else:
        pos2 = positions['RG']

    for p2 in pos2:
        if p2 > p1:
            for p3 in pos2:
                if p3 > p2:                
                    #print(s[p1], s[p2], s[p3])
                    if (s[p1] != s[p2]) and (s[p1] != s[p3]) and (s[p2] != s[p3]) and (p1-p2 != p2-p3):
                        ans += 1
print(ans)

Fixed submission:
n = int(input())
s = input()
dup = 0
r = s.count('R')
g = s.count('G')
b = s.count('B')

for i in range(n):
    for j in range(i+1, n):
        k = 2*j - i
        if k < n:
            #print(i,j,k)
            if (s[i] != s[j]) and (s[j] != s[k]) and (s[i] != s[k]):
                #print(s[i], s[j], s[k])
                dup += 1
print(r*g*b - dup)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
s = input()
ans = 0
for p1 in range(n-3):
    for p2 in range(p1+1, n-1):
        for p3 in range(p2+1, n):
            #print(s[p1], s[p2], s[p3])
            if (s[p1] != s[p2]) and (s[p1] != s[p3]) and (s[p2] != s[p3]) and (p1-p2 != p2-p3):
                ans += 1
print(ans)

Fixed submission:
n = int(input())
s = input()
dup = 0
r = s.count('R')
g = s.count('G')
b = s.count('B')

for i in range(n):
    for j in range(i+1, n):
        k = 2*j - i
        if k < n:
            #print(i,j,k)
            if (s[i] != s[j]) and (s[j] != s[k]) and (s[i] != s[k]):
                #print(s[i], s[j], s[k])
                dup += 1
print(r*g*b - dup)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
s = input()
ans = 0
for p1 in range(n-3):
    for p2 in range(p1+1, n-1):
        for p3 in range(p2+1, n):
            #print(s[p1], s[p2], s[p3])
            if (s[p1] != s[p2]) and (s[p1] != s[p3]) and (s[p2] != s[p3]) and (p1-p2 != p2-p3):
                ans += 1
print(ans)

Fixed submission:
n = int(input())
s = input()
dup = 0
r = s.count('R')
g = s.count('G')
b = s.count('B')

for i in range(n):
    for j in range(i+1, n):
        k = 2*j - i
        if k < n:
            #print(i,j,k)
            if (s[i] != s[j]) and (s[j] != s[k]) and (s[i] != s[k]):
                #print(s[i], s[j], s[k])
                dup += 1
print(r*g*b - dup)