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

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

count = 0
r, g, b = 0, 0, 0

for i in s:
    if i == 'R':
        r += 1
    elif i == 'G':
        g += 1
    elif i == 'B':
        b += 1

count = r * g * b

for i in range(n-2):
    si = s[i]
    for j in range(i+1,n-1):
        sj = s[j]
        nk = 2 * j - i
        if not nk < n:
            continue
        snk = s[nk]
        if {si, sj, snk} == {'R','G','B'}:
            count -= 1

print("{}".format(count))

Fixed submission:
#coding:utf-8

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

count = 0
r, g, b = 0, 0, 0

for i in s:
    if i == 'R':
        r += 1
    elif i == 'G':
        g += 1
    elif i == 'B':
        b += 1

count = r * g * b

for i in range(n-2):
    si = s[i]
    for j in range(i+1,n-1):
        sj = s[j]
        nk = 2 * j - i
        if not nk < n:
            break
        snk = s[nk]
        if {si, sj, snk} == {'R','G','B'}:
            count -= 1

print("{}".format(count))

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

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

count = 0
r, g, b = 0, 0, 0

for i in s:
    if i == 'R':
        r += 1
    elif i == 'G':
        g += 1
    elif i == 'B':
        b += 1

count = r * g * b

for i in range(n-2):
    si = s[i]
    for j in range(i+1,n-1):
        sj = s[j]
        if si == sj:
            continue
        c_set = {'R','G','B'} - {si, sj}
        nk = 2 * j - i
        if not (2 * j - i) < n:
            continue
        if s[nk] in c_set:
            count -= 1

print("{}".format(count))

Fixed submission:
#coding:utf-8

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

count = 0
r, g, b = 0, 0, 0

for i in s:
    if i == 'R':
        r += 1
    elif i == 'G':
        g += 1
    elif i == 'B':
        b += 1

count = r * g * b

for i in range(n-2):
    si = s[i]
    for j in range(i+1,n-1):
        sj = s[j]
        nk = 2 * j - i
        if not nk < n:
            break
        snk = s[nk]
        if {si, sj, snk} == {'R','G','B'}:
            count -= 1

print("{}".format(count))

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

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

count = 0
r, g, b = 0, 0, 0

for i in s:
    if i == 'R':
        r += 1
    elif i == 'G':
        g += 1
    elif i == 'B':
        b += 1

count = r * g * b

for i in range(n-2):
    si = s[i]
    for j in range(i+1,n-1):
        sj = s[j]
        if si == sj:
            continue
        c_set = {'R','G','B'}
        c_set = c_set - {si,sj}
        nk = 2 * j - i
        if not nk < n:
            continue
        if not nk > j:
            continue
        if s[nk] in c_set:
            count -= 1

print("{}".format(count))

Fixed submission:
#coding:utf-8

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

count = 0
r, g, b = 0, 0, 0

for i in s:
    if i == 'R':
        r += 1
    elif i == 'G':
        g += 1
    elif i == 'B':
        b += 1

count = r * g * b

for i in range(n-2):
    si = s[i]
    for j in range(i+1,n-1):
        sj = s[j]
        nk = 2 * j - i
        if not nk < n:
            break
        snk = s[nk]
        if {si, sj, snk} == {'R','G','B'}:
            count -= 1

print("{}".format(count))

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

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

count = 0
r, g, b = 0, 0, 0

for k,i in enumerate(s):
    if i == 'R':
        r += 1
    elif i == 'G':
        g += 1
    elif i == 'B':
        b += 1

count = r * g * b

for i in range(n-2):
    si = s[i]
    for j in range(i+1,n-1):
        sj = s[j]
        if si == sj:
            continue
        c_set = {'R','G','B'}
        c_set = c_set - {si,sj}
        nk = 2 * j - i
        if not nk < n:
            continue
        if s[nk] in c_set:
            count -= 1

print("{}".format(count))

Fixed submission:
#coding:utf-8

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

count = 0
r, g, b = 0, 0, 0

for i in s:
    if i == 'R':
        r += 1
    elif i == 'G':
        g += 1
    elif i == 'B':
        b += 1

count = r * g * b

for i in range(n-2):
    si = s[i]
    for j in range(i+1,n-1):
        sj = s[j]
        nk = 2 * j - i
        if not nk < n:
            break
        snk = s[nk]
        if {si, sj, snk} == {'R','G','B'}:
            count -= 1

print("{}".format(count))

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

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

count = 0
r_list = []
g_list = []
b_list = []

for k,i in enumerate(s):
    if i == 'R':
        r_list.append(k)
    elif i == 'G':
        g_list.append(k)
    elif i == 'B':
        b_list.append(k)

count = len(r_list) * len(g_list) * len(b_list)

for i in range(n-2):
    si = s[i]
    for j in range(i+1,n-1):
        sj = s[j]
        c_set = {'R','G','B'}
        c_set = c_set - {si,sj}
        nk = 2 * j - i
        if c_set == {'R'} and nk in r_list:
            count -= 1
        elif c_set == {'G'} and nk in g_list:
            count -= 1
        elif c_set == {'B'} and nk in b_list:
            count -= 1        

print("{}".format(count))

Fixed submission:
#coding:utf-8

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

count = 0
r, g, b = 0, 0, 0

for i in s:
    if i == 'R':
        r += 1
    elif i == 'G':
        g += 1
    elif i == 'B':
        b += 1

count = r * g * b

for i in range(n-2):
    si = s[i]
    for j in range(i+1,n-1):
        sj = s[j]
        nk = 2 * j - i
        if not nk < n:
            break
        snk = s[nk]
        if {si, sj, snk} == {'R','G','B'}:
            count -= 1

print("{}".format(count))

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

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

count = 0
r_list = []
g_list = []
b_list = []
l_set = {'R','G','B'}

for k,i in enumerate(s):
    if i == 'R':
        r_list.append(k)
    elif i == 'G':
        g_list.append(k)
    elif i == 'B':
        b_list.append(k)

count = len(r_list) * len(g_list) * len(b_list)

for i in range(n-2):
    si = s[i]
    for j in range(i+1,n-1):
        sj = s[j]
        c_set = l_set.copy()
        c_set = c_set - {si} - {sj}
        nk = 2 * j - i
        if c_set == {'R'} and nk in r_list:
            count -= 1
        elif c_set == {'G'} and nk in g_list:
            count -= 1
        elif c_set == {'B'} and nk in b_list:
            count -= 1        

print("{}".format(count))

Fixed submission:
#coding:utf-8

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

count = 0
r, g, b = 0, 0, 0

for i in s:
    if i == 'R':
        r += 1
    elif i == 'G':
        g += 1
    elif i == 'B':
        b += 1

count = r * g * b

for i in range(n-2):
    si = s[i]
    for j in range(i+1,n-1):
        sj = s[j]
        nk = 2 * j - i
        if not nk < n:
            break
        snk = s[nk]
        if {si, sj, snk} == {'R','G','B'}:
            count -= 1

print("{}".format(count))

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

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

count = 0
point = 0
letter_set = {'R','G','B'}

def last_point(c):
    num = None
    for index,letter in enumerate(s):
        if letter == c:
            num = index
    return index

r_num = last_point('R')
g_num = last_point('G')
b_num = last_point('B')

for i in range(point,n-2):
    si = s[i]
    for j in range(i+1,n-1):
        if s[j] != si:
            sj = s[j]
        else:
            continue
        for k in range(j+1,n):
            if s[k] != si and s[k] != sj:
                sk = s[k]
            else:
                continue
            
            num = 0
            l_set = letter_set.copy()
            l_set = l_set - {si} - {sj}
            
            if l_set == {'R'}:
                num = r_num
            elif l_set == {'G'}:
                num = g_num
            elif l_set == {'B'}:
                num = b_num

            if k > num:
                break
            
            if (j - i) != (k - j):
                count += 1

print("{}".format(count))

Fixed submission:
#coding:utf-8

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

count = 0
r, g, b = 0, 0, 0

for i in s:
    if i == 'R':
        r += 1
    elif i == 'G':
        g += 1
    elif i == 'B':
        b += 1

count = r * g * b

for i in range(n-2):
    si = s[i]
    for j in range(i+1,n-1):
        sj = s[j]
        nk = 2 * j - i
        if not nk < n:
            break
        snk = s[nk]
        if {si, sj, snk} == {'R','G','B'}:
            count -= 1

print("{}".format(count))

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

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

count = 0
point = 0
for i in range(point,n-2):
    si = s[i]
    for j in range(i+1,n-1):
        if s[j] != si:
            sj = s[j]
        else:
            continue
        for k in range(j+1,n):
            if s[k] != si and s[k] != sj:
                sk = s[k]
            else:
                continue
            
            if (j - i) != (k - j):
                count += 1

print("{}".format(count))

Fixed submission:
#coding:utf-8

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

count = 0
r, g, b = 0, 0, 0

for i in s:
    if i == 'R':
        r += 1
    elif i == 'G':
        g += 1
    elif i == 'B':
        b += 1

count = r * g * b

for i in range(n-2):
    si = s[i]
    for j in range(i+1,n-1):
        sj = s[j]
        nk = 2 * j - i
        if not nk < n:
            break
        snk = s[nk]
        if {si, sj, snk} == {'R','G','B'}:
            count -= 1

print("{}".format(count))