Buggy python submission (verdict: Time Limit Exceeded):
# -*- coding: utf-8 -*-

n = int(input())
s = input()


counter = 0

for p in range(n):
    for q in range(n - p):
        a = s[p]
        b = s[p + q]
        if a == b:
            continue
        nokori = s[p + q:]
        rgb_list = ['R', 'G', 'B']
        rgb_list.remove(a)
        for e in rgb_list:
            if e not in nokori:
                continue
        rgb_list.remove(b)
        c = rgb_list[0]
        counter += nokori.count(c)
        if q < len(nokori) and nokori[q] == c:
            counter -= 1
print(counter)

Fixed submission:
# -*- coding: utf-8 -*-

n = int(input())
s = input()

r_cnt = s.count('R')
g_cnt = s.count('G')
b_cnt = s.count('B')

counter = r_cnt * g_cnt * b_cnt

for i in range(n):
    for p in range(n):
        j = i + p
        k = j + p
        if k >= n:
            break
        if s[i] != s[j] and s[j] != s[k] and s[k] != s[i]:
            counter -= 1
print(counter)

Buggy python submission (verdict: Time Limit Exceeded):
# -*- coding: utf-8 -*-

n = int(input())
s = input()


counter = 0

for p in range(n):
    for q in range(n - p):
        a = s[p]
        b = s[p + q]
        if a == b:
            continue
        rgb_list = ['R', 'G', 'B']
        rgb_list.remove(a)
        rgb_list.remove(b)
        # current_list = [a, b]
        # diff_list = list(set(rgb_list) - set(current_list))
        c = rgb_list[0]
        nokori = s[p + q:]
        counter += nokori.count(c)
        if q < len(nokori) and nokori[q] == c:
            counter -= 1
print(counter)

Fixed submission:
# -*- coding: utf-8 -*-

n = int(input())
s = input()

r_cnt = s.count('R')
g_cnt = s.count('G')
b_cnt = s.count('B')

counter = r_cnt * g_cnt * b_cnt

for i in range(n):
    for p in range(n):
        j = i + p
        k = j + p
        if k >= n:
            break
        if s[i] != s[j] and s[j] != s[k] and s[k] != s[i]:
            counter -= 1
print(counter)

Buggy python submission (verdict: Time Limit Exceeded):
# -*- coding: utf-8 -*-

n = int(input())
s = input()


rgb_list = ['R', 'G', 'B']
counter = 0

for p in range(n):
    for q in range(n - p):
        a = s[p]
        b = s[p + q]
        if a == b:
            continue
        current_list = [a, b]
        diff_list = list(set(rgb_list) - set(current_list))
        c = diff_list[0]
        nokori = s[p + q:]
        counter += nokori.count(c)
        if q < len(nokori) and nokori[q] == c:
            counter -= 1

print(counter)

Fixed submission:
# -*- coding: utf-8 -*-

n = int(input())
s = input()

r_cnt = s.count('R')
g_cnt = s.count('G')
b_cnt = s.count('B')

counter = r_cnt * g_cnt * b_cnt

for i in range(n):
    for p in range(n):
        j = i + p
        k = j + p
        if k >= n:
            break
        if s[i] != s[j] and s[j] != s[k] and s[k] != s[i]:
            counter -= 1
print(counter)

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

counter = 0

for p in range(n):
    for q in range(n - p):
        a = s[p]
        b = s[p + q]
        if a == b:
            continue
        for r in range(n - p - q):
            c = s[p + q + r]
            if b != c and c != a and q != r:
                # print(a, b, c, p, q, r)
                counter += 1
print(counter)

Fixed submission:
# -*- coding: utf-8 -*-

n = int(input())
s = input()

r_cnt = s.count('R')
g_cnt = s.count('G')
b_cnt = s.count('B')

counter = r_cnt * g_cnt * b_cnt

for i in range(n):
    for p in range(n):
        j = i + p
        k = j + p
        if k >= n:
            break
        if s[i] != s[j] and s[j] != s[k] and s[k] != s[i]:
            counter -= 1
print(counter)

Buggy python submission (verdict: Time Limit Exceeded):
# -*- coding: utf-8 -*-

n = int(input())
s = input()

counter = 0

for p in range(n):
    for q in range(n - p):
        for r in range(n - p - q):
            a = s[p]
            b = s[p + q]
            c = s[p + q + r]
            if a != b and b != c and c != a and q != r:
                # print(a, b, c, p, q, r)
                counter += 1
print(counter)

Fixed submission:
# -*- coding: utf-8 -*-

n = int(input())
s = input()

r_cnt = s.count('R')
g_cnt = s.count('G')
b_cnt = s.count('B')

counter = r_cnt * g_cnt * b_cnt

for i in range(n):
    for p in range(n):
        j = i + p
        k = j + p
        if k >= n:
            break
        if s[i] != s[j] and s[j] != s[k] and s[k] != s[i]:
            counter -= 1
print(counter)

Buggy python submission (verdict: Time Limit Exceeded):
# -*- coding: utf-8 -*-

n = int(input())
s = input()

counter = 0
for p in range(n):
    for q in range(n):
        if p >= q:
            continue
        for r in range(n):
            if q >= r:
                continue
            a = s[p]
            b = s[q]
            c = s[r]
            if a != b and b != c and c != a and r - q != q - p:
                # print(a, b, c, p, q, r)
                counter += 1
print(counter)

Fixed submission:
# -*- coding: utf-8 -*-

n = int(input())
s = input()

r_cnt = s.count('R')
g_cnt = s.count('G')
b_cnt = s.count('B')

counter = r_cnt * g_cnt * b_cnt

for i in range(n):
    for p in range(n):
        j = i + p
        k = j + p
        if k >= n:
            break
        if s[i] != s[j] and s[j] != s[k] and s[k] != s[i]:
            counter -= 1
print(counter)

Buggy python submission (verdict: Time Limit Exceeded):
# -*- coding: utf-8 -*-

n = int(input())
s = input()

counter = 0
for p in range(n):
    for q in range(n):
        for r in range(n):
            if p >= q or q >= r:
                continue
            a = s[p]
            b = s[q]
            c = s[r]
            if a != b and b != c and c != a and r - q != q - p:
                # print(a, b, c, p, q, r)
                counter += 1
print(counter)

Fixed submission:
# -*- coding: utf-8 -*-

n = int(input())
s = input()

r_cnt = s.count('R')
g_cnt = s.count('G')
b_cnt = s.count('B')

counter = r_cnt * g_cnt * b_cnt

for i in range(n):
    for p in range(n):
        j = i + p
        k = j + p
        if k >= n:
            break
        if s[i] != s[j] and s[j] != s[k] and s[k] != s[i]:
            counter -= 1
print(counter)