Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
S = input()

s_l = {}
for i in range(N-1):
    s_l[i] = S[i+1:]

s = 0
for a in range(N-2):
    s1 = S[a]
    for b in range(a+1, N-1):
        s2 = S[b]
        if s1 == s2:
            continue
        n = s_l[b]
        pat = ['R', 'G', 'B']
        pat.remove(s1)
        pat.remove(s2)
        count = n.count(pat[0])
        d = b - a
        if len(n) > d-1 and n[d-1] == pat[0]:
            count -= 1
        s += count

print(s)


Fixed submission:
N = int(input())
S = input()

s_l = {}
for i in range(N-1):
    t = {}
    s = S[i+1:]
    t['s'] = s
    t['R'] = s.count('R')
    t['G'] = s.count('G')
    t['B'] = s.count('B')
    s_l[i] = t

s = 0
for a in range(N-2):
    s1 = S[a]
    for b in range(a+1, N-1):
        s2 = S[b]
        if s1 == s2:
            continue
        n = s_l[b]['s']
        pat = ['R', 'G', 'B']
        pat.remove(s1)
        pat.remove(s2)
        count = s_l[b][pat[0]]
        d = b - a
        if len(n) > d-1 and n[d-1] == pat[0]:
            count -= 1
        s += count

print(s)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
S = input()

s = 0
for a in range(N):
    s1 = S[a]
    for b in range(a+1, N):
        s2 = S[b]
        if s1 == s2:
            continue
        n = S[b+1:]
        pat = ['R', 'G', 'B']
        pat.remove(s1)
        pat.remove(s2)
        count = n.count(pat[0])
        d = b - a
        if len(n) > d-1 and n[d-1] == pat[0]:
            count -= 1
        s += count

print(s)


Fixed submission:
N = int(input())
S = input()

s_l = {}
for i in range(N-1):
    t = {}
    s = S[i+1:]
    t['s'] = s
    t['R'] = s.count('R')
    t['G'] = s.count('G')
    t['B'] = s.count('B')
    s_l[i] = t

s = 0
for a in range(N-2):
    s1 = S[a]
    for b in range(a+1, N-1):
        s2 = S[b]
        if s1 == s2:
            continue
        n = s_l[b]['s']
        pat = ['R', 'G', 'B']
        pat.remove(s1)
        pat.remove(s2)
        count = s_l[b][pat[0]]
        d = b - a
        if len(n) > d-1 and n[d-1] == pat[0]:
            count -= 1
        s += count

print(s)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
S = input()

s = 0
for a in range(N):
    s1 = S[a]
    for b in range(a+1, N):
        s2 = S[b]
        if s1 == s2:
            continue
        n = S[b+1:]
        pat = ['R', 'G', 'B']
        pat.remove(s1)
        pat.remove(s2)
        count = n.count(pat[0])
        d = b - a
        if len(n) > d-1 and n[d-1] == pat[0]:
            count -= 1
        s += count

print(s)


Fixed submission:
N = int(input())
S = input()

s_l = {}
for i in range(N-1):
    t = {}
    s = S[i+1:]
    t['s'] = s
    t['R'] = s.count('R')
    t['G'] = s.count('G')
    t['B'] = s.count('B')
    s_l[i] = t

s = 0
for a in range(N-2):
    s1 = S[a]
    for b in range(a+1, N-1):
        s2 = S[b]
        if s1 == s2:
            continue
        n = s_l[b]['s']
        pat = ['R', 'G', 'B']
        pat.remove(s1)
        pat.remove(s2)
        count = s_l[b][pat[0]]
        d = b - a
        if len(n) > d-1 and n[d-1] == pat[0]:
            count -= 1
        s += count

print(s)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
S = input()

s = 0
for a in range(N):
    o = S[a]
    for b in range(a+1, N):
        p = S[b]
        if o == p:
            continue
        for c in range(b+1, N):
            q = S[c]
            if o != q and p != q:
                if b-a != c-b:
                    s += 1
print(s)


Fixed submission:
N = int(input())
S = input()

s_l = {}
for i in range(N-1):
    t = {}
    s = S[i+1:]
    t['s'] = s
    t['R'] = s.count('R')
    t['G'] = s.count('G')
    t['B'] = s.count('B')
    s_l[i] = t

s = 0
for a in range(N-2):
    s1 = S[a]
    for b in range(a+1, N-1):
        s2 = S[b]
        if s1 == s2:
            continue
        n = s_l[b]['s']
        pat = ['R', 'G', 'B']
        pat.remove(s1)
        pat.remove(s2)
        count = s_l[b][pat[0]]
        d = b - a
        if len(n) > d-1 and n[d-1] == pat[0]:
            count -= 1
        s += count

print(s)