Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
S = input()
r = S.count('R')
g = S.count('G')
b = S.count('B')
count = r * g * b
for i in range(N):
    for j in range(i+1,N-1):
        if 2*j - i <= N-1:
            l = set([S[i],S[j],S[2*j-i]])
            if len(l) == 3:
                count -= 1
print(count)

Fixed submission:
N = int(input())
S = input()
r = S.count('R')
g = S.count('G')
b = S.count('B')
count = r * g * b
for i in range(N):
    for j in range(i+1,N-1):
        if 2*j - i <= N-1:
            l = set([S[i],S[j],S[2*j-i]])
            if len(l) == 3:
                count -= 1
print(count)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
S = input()
count = 0
def findlet(let,ind):
    add = st[ind:].count(let)
    if add > 0:
        if 2*ind < len(st):
            if st[2*ind] == let:
                add -= 1
        return add
    return 0
for i in range(N-2):
    if i == 0:
        st = S
    else:
        st = st[1:]
    if st[0] == "R":
        for j in [x for x, y in enumerate(st) if y == 'G']:
            count += findlet("B",j)
        for j in [x for x, y in enumerate(st) if y == 'B']:
            count += findlet("G",j)
    elif st[0] == "G":
        for j in [x for x, y in enumerate(st) if y == 'B']:
            count += findlet("R",j)
        for j in [x for x, y in enumerate(st) if y == 'R']:
            count += findlet("B",j)
    else:
        for j in [x for x, y in enumerate(st) if y == 'R']:
            count += findlet("G",j)
        for j in [x for x, y in enumerate(st) if y == 'G']:
            count += findlet("R",j)
print(count)

Fixed submission:
N = int(input())
S = input()
r = S.count('R')
g = S.count('G')
b = S.count('B')
count = r * g * b
for i in range(N):
    for j in range(i+1,N-1):
        if 2*j - i <= N-1:
            l = set([S[i],S[j],S[2*j-i]])
            if len(l) == 3:
                count -= 1
print(count)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
S = input()
count = 0
def findlet(let,ind):
    add = len([x for x in st[ind:] if x == let])
    if add > 0:
        if 2*ind < len(st):
            if st[2*ind] == let:
                add -= 1
        global count
        count += add
for i in range(N-2):
    if i == 0:
        st = S
    else:
        st = st[1:]
    if st[0] == "R":
        for j in [x for x, y in enumerate(st) if y == 'G']:
            findlet("B",j)
        for j in [x for x, y in enumerate(st) if y == 'B']:
            findlet("G",j)
    elif st[0] == "G":
        for j in [x for x, y in enumerate(st) if y == 'B']:
            findlet("R",j)
        for j in [x for x, y in enumerate(st) if y == 'R']:
            findlet("B",j)
    else:
        for j in [x for x, y in enumerate(st) if y == 'R']:
            findlet("G",j)
        for j in [x for x, y in enumerate(st) if y == 'G']:
            findlet("R",j)
print(count)

Fixed submission:
N = int(input())
S = input()
r = S.count('R')
g = S.count('G')
b = S.count('B')
count = r * g * b
for i in range(N):
    for j in range(i+1,N-1):
        if 2*j - i <= N-1:
            l = set([S[i],S[j],S[2*j-i]])
            if len(l) == 3:
                count -= 1
print(count)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
S = input()
count = 0
def findlet(let,ind):
    add = len([x for x in st[ind:] if x == let])
    if add > 0:
        if 2*ind < len(st):
            if st[2*ind] == let:
                add -= 1
        global count
        count += add
for i in range(N-2):
    if i == 0:
        st = S
    else:
        st = st[1:]
    if st[0] == "R":
        for j in [x for x, y in enumerate(st) if y == 'G']:
            findlet("B",j)
        for j in [x for x, y in enumerate(st) if y == 'B']:
            findlet("G",j)
    elif st[0] == "G":
        for j in [x for x, y in enumerate(st) if y == 'B']:
            findlet("R",j)
        for j in [x for x, y in enumerate(st) if y == 'R']:
            findlet("B",j)
    else:
        for j in [x for x, y in enumerate(st) if y == 'R']:
            findlet("G",j)
        for j in [x for x, y in enumerate(st) if y == 'G']:
            findlet("R",j)
print(count)

Fixed submission:
N = int(input())
S = input()
r = S.count('R')
g = S.count('G')
b = S.count('B')
count = r * g * b
for i in range(N):
    for j in range(i+1,N-1):
        if 2*j - i <= N-1:
            l = set([S[i],S[j],S[2*j-i]])
            if len(l) == 3:
                count -= 1
print(count)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
S = input()
count = 0
def findlet(let,ind):
    add = st[ind:].count(let)
    if add > 0:
        if 2*ind < len(st):
            if st[2*ind] == let:
                add -= 1
        global count
        count += add
for i in range(N-2):
    if i == 0:
        st = S
    else:
        st = st[1:]
    if st[0] == "R":
        for j in [x for x, y in enumerate(st) if y == 'G']:
            findlet("B",j)
        for j in [x for x, y in enumerate(st) if y == 'B']:
            findlet("G",j)
    elif st[0] == "G":
        for j in [x for x, y in enumerate(st) if y == 'B']:
            findlet("R",j)
        for j in [x for x, y in enumerate(st) if y == 'R']:
            findlet("B",j)
    else:
        for j in [x for x, y in enumerate(st) if y == 'R']:
            findlet("G",j)
        for j in [x for x, y in enumerate(st) if y == 'G']:
            findlet("R",j)
print(count)

Fixed submission:
N = int(input())
S = input()
r = S.count('R')
g = S.count('G')
b = S.count('B')
count = r * g * b
for i in range(N):
    for j in range(i+1,N-1):
        if 2*j - i <= N-1:
            l = set([S[i],S[j],S[2*j-i]])
            if len(l) == 3:
                count -= 1
print(count)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
S = input()
count = 0
def findlet(let,ind):
    add = st[ind:].count(let)
    if add > 0:
        if 2*ind < len(st):
            if st[2*ind] == let:
                add -= 1
        global count
        count += add
for i in range(N-2):
    if i == 0:
        st = S
    else:
        st = st[1:]
    if st[0] == "R":
        for j in [x for x, y in enumerate(st) if y == 'G']:
            findlet("B",j)
        for j in [x for x, y in enumerate(st) if y == 'B']:
            findlet("G",j)
    elif st[0] == "G":
        for j in [x for x, y in enumerate(st) if y == 'B']:
            findlet("R",j)
        for j in [x for x, y in enumerate(st) if y == 'R']:
            findlet("B",j)
    else:
        for j in [x for x, y in enumerate(st) if y == 'R']:
            findlet("G",j)
        for j in [x for x, y in enumerate(st) if y == 'G']:
            findlet("R",j)
print(count)

Fixed submission:
N = int(input())
S = input()
r = S.count('R')
g = S.count('G')
b = S.count('B')
count = r * g * b
for i in range(N):
    for j in range(i+1,N-1):
        if 2*j - i <= N-1:
            l = set([S[i],S[j],S[2*j-i]])
            if len(l) == 3:
                count -= 1
print(count)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
S = input()
count = 0
def findlet(let,ind):
    add = st[ind:].count(let)
    if add > 0:
        if 2*ind < len(st):
            if st[2*ind] == let:
                add -= 1
        global count
        count += add
for i in range(N-2):
    st = S[i:]
    if st[0] == "R":
        for j in [x for x, y in enumerate(st) if y == 'G']:
            findlet("B",j)
        for j in [x for x, y in enumerate(st) if y == 'B']:
            findlet("G",j)
    elif st[0] == "G":
        for j in [x for x, y in enumerate(st) if y == 'B']:
            findlet("R",j)
        for j in [x for x, y in enumerate(st) if y == 'R']:
            findlet("B",j)
    else:
        for j in [x for x, y in enumerate(st) if y == 'R']:
            findlet("G",j)
        for j in [x for x, y in enumerate(st) if y == 'G']:
            findlet("R",j)
print(count)

Fixed submission:
N = int(input())
S = input()
r = S.count('R')
g = S.count('G')
b = S.count('B')
count = r * g * b
for i in range(N):
    for j in range(i+1,N-1):
        if 2*j - i <= N-1:
            l = set([S[i],S[j],S[2*j-i]])
            if len(l) == 3:
                count -= 1
print(count)

Buggy python submission (verdict: Runtime Error):
N = int(input())
S = input()
count = 0
def findlet(let,ind):
    add = st[ind:].count(let)
    if add > 0:
        if 2*ind < len():
            if st[2*ind] == let:
                add -= 1
        global count
        count += add
for i in range(N-2):
    st = S[i:]
    if st[0] == "R":
        for j in [x for x, y in enumerate(st) if y == 'G']:
            findlet("B",j)
        for j in [x for x, y in enumerate(st) if y == 'B']:
            findlet("G",j)
    elif st[0] == "G":
        for j in [x for x, y in enumerate(st) if y == 'B']:
            findlet("R",j)
        for j in [x for x, y in enumerate(st) if y == 'R']:
            findlet("B",j)
    else:
        for j in [x for x, y in enumerate(st) if y == 'R']:
            findlet("G",j)
        for j in [x for x, y in enumerate(st) if y == 'G']:
            findlet("R",j)
print(count)

Fixed submission:
N = int(input())
S = input()
r = S.count('R')
g = S.count('G')
b = S.count('B')
count = r * g * b
for i in range(N):
    for j in range(i+1,N-1):
        if 2*j - i <= N-1:
            l = set([S[i],S[j],S[2*j-i]])
            if len(l) == 3:
                count -= 1
print(count)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
S = input()
count = 0
def findlet(let,ind,checker):
    add = S[ind:].count(let)
    if add > 0:
        if ind + checker < N:
            if S[ind+checker] == let:
                add -= 1
        global count
        count += add
for i in range(N-2):
    st = S[i:]
    if st[0] == "R":
        for j in [x for x, y in enumerate(st) if y == 'G']:
            findlet("B",i+j,j)
        for j in [x for x, y in enumerate(st) if y == 'B']:
            findlet("G",i+j,j)
    elif st[0] == "G":
        for j in [x for x, y in enumerate(st) if y == 'B']:
            findlet("R",i+j,j)
        for j in [x for x, y in enumerate(st) if y == 'R']:
            findlet("B",i+j,j)
    else:
        for j in [x for x, y in enumerate(st) if y == 'R']:
            findlet("G",i+j,j)
        for j in [x for x, y in enumerate(st) if y == 'G']:
            findlet("R",i+j,j)
print(count)

Fixed submission:
N = int(input())
S = input()
r = S.count('R')
g = S.count('G')
b = S.count('B')
count = r * g * b
for i in range(N):
    for j in range(i+1,N-1):
        if 2*j - i <= N-1:
            l = set([S[i],S[j],S[2*j-i]])
            if len(l) == 3:
                count -= 1
print(count)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
S = input()
count = 0
def findb(ind,checker):
    global count
    b = S[ind:].count("B")
    if b > 0:
        if ind + checker < N:
            if S[ind+checker] == "B":
                b -= 1
        count += b
def findg(ind,checker):
    global count
    g = S[ind:].count("G")
    if g > 0:
        if ind + checker < N:
            if S[ind+checker] == "G":
                g -= 1
        count += g
def findr(ind,checker):
    global count
    r = S[ind:].count("R")
    if r > 0:
        if ind + checker < N:
            if S[ind+checker] == "R":
                r -= 1
        count += r
for i in range(N-2):
    st = S[i:]
    if st[0] == "R":
        for j in [x for x, y in enumerate(st) if y == 'G']:
            findb(i+j,j)
        for j in [x for x, y in enumerate(st) if y == 'B']:
            findg(i+j,j)
    elif st[0] == "G":
        for j in [x for x, y in enumerate(st) if y == 'B']:
            findr(i+j,j)
        for j in [x for x, y in enumerate(st) if y == 'R']:
            findb(i+j,j)
    else:
        for j in [x for x, y in enumerate(st) if y == 'R']:
            findg(i+j,j)
        for j in [x for x, y in enumerate(st) if y == 'G']:
            findr(i+j,j)
print(count)

Fixed submission:
N = int(input())
S = input()
r = S.count('R')
g = S.count('G')
b = S.count('B')
count = r * g * b
for i in range(N):
    for j in range(i+1,N-1):
        if 2*j - i <= N-1:
            l = set([S[i],S[j],S[2*j-i]])
            if len(l) == 3:
                count -= 1
print(count)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
S = input()
count = 0
def findb(ind,checker):
    global count
    b = S[ind:].count("B")
    if b > 0:
        if ind + checker < N:
            if S[ind+checker] == "B":
                b -= 1
        count += b
def findg(ind,checker):
    global count
    g = S[ind:].count("G")
    if g > 0:
        if ind + checker < N:
            if S[ind+checker] == "G":
                g -= 1
        count += g
def findr(ind,checker):
    global count
    r = S[ind:].count("R")
    if r > 0:
        if ind + checker < N:
            if S[ind+checker] == "R":
                r -= 1
        count += r
for i in range(N-2):
    st = S[i:]
    if st[0] == "R":
        for j in [x for x, y in enumerate(st) if y == 'G']:
            findb(i+j,j)
        for j in [x for x, y in enumerate(st) if y == 'B']:
            findg(i+j,j)
    elif st[0] == "G":
        for j in [x for x, y in enumerate(st) if y == 'B']:
            findr(i+j,j)
        for j in [x for x, y in enumerate(st) if y == 'R']:
            findb(i+j,j)
    else:
        for j in [x for x, y in enumerate(st) if y == 'R']:
            findg(i+j,j)
        for j in [x for x, y in enumerate(st) if y == 'G']:
            findr(i+j,j)
print(count)

Fixed submission:
N = int(input())
S = input()
r = S.count('R')
g = S.count('G')
b = S.count('B')
count = r * g * b
for i in range(N):
    for j in range(i+1,N-1):
        if 2*j - i <= N-1:
            l = set([S[i],S[j],S[2*j-i]])
            if len(l) == 3:
                count -= 1
print(count)

Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque 
N = int(input())
S = input()
s = deque(list(S))
count = 0
def findb(ind,checker):
    global count
    b = S[ind:].count("B")
    if b > 0:
        if ind + checker < N:
            if S[ind+checker] == "B":
                b -= 1
        count += b
def findg(ind,checker):
    global count
    g = S[ind:].count("G")
    if g > 0:
        if ind + checker < N:
            if S[ind+checker] == "G":
                g -= 1
        count += g
def findr(ind,checker):
    global count
    r = S[ind:].count("R")
    if r > 0:
        if ind + checker < N:
            if S[ind+checker] == "R":
                r -= 1
        count += r
for i in range(N-2):
    temp = s.popleft()
    st = S[i:]
    if temp == "R":
        for j in [x for x, y in enumerate(st) if y == 'G']:
            findb(i+j,j)
        for j in [x for x, y in enumerate(st) if y == 'B']:
            findg(i+j,j)
    elif temp == "G":
        for j in [x for x, y in enumerate(st) if y == 'B']:
            findr(i+j,j)
        for j in [x for x, y in enumerate(st) if y == 'R']:
            findb(i+j,j)
    else:
        for j in [x for x, y in enumerate(st) if y == 'R']:
            findg(i+j,j)
        for j in [x for x, y in enumerate(st) if y == 'G']:
            findr(i+j,j)
print(count)

Fixed submission:
N = int(input())
S = input()
r = S.count('R')
g = S.count('G')
b = S.count('B')
count = r * g * b
for i in range(N):
    for j in range(i+1,N-1):
        if 2*j - i <= N-1:
            l = set([S[i],S[j],S[2*j-i]])
            if len(l) == 3:
                count -= 1
print(count)

Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque 
N = int(input())
S = input()
s = deque(list(S))
count = 0
def findb(ind,checker):
    global count
    b = S[ind:].count("B")
    if b > 0:
        if ind + checker < N:
            if S[ind+checker] == "B":
                b -= 1
        count += b
def findg(ind,checker):
    global count
    g = S[ind:].count("G")
    if g > 0:
        if ind + checker < N:
            if S[ind+checker] == "G":
                g -= 1
        count += g
def findr(ind,checker):
    global count
    r = S[ind:].count("R")
    if r > 0:
        if ind + checker < N:
            if S[ind+checker] == "R":
                r -= 1
        count += r
for i in range(N-2):
    temp = s.popleft()
    st = S[i:]
    if temp == "R":
        
        for j in [x for x, y in enumerate(st) if y == 'G']:
            findb(i+j,j)
        for j in [x for x, y in enumerate(st) if y == 'B']:
            findg(i+j,j)
    elif temp == "G":
        for j in [x for x, y in enumerate(st) if y == 'B']:
            findr(i+j,j)
        for j in [x for x, y in enumerate(st) if y == 'R']:
            findb(i+j,j)
    else:
        for j in [x for x, y in enumerate(st) if y == 'R']:
            findg(i+j,j)
        for j in [x for x, y in enumerate(st) if y == 'G']:
            findr(i+j,j)
print(count)

Fixed submission:
N = int(input())
S = input()
r = S.count('R')
g = S.count('G')
b = S.count('B')
count = r * g * b
for i in range(N):
    for j in range(i+1,N-1):
        if 2*j - i <= N-1:
            l = set([S[i],S[j],S[2*j-i]])
            if len(l) == 3:
                count -= 1
print(count)

Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque 
N = int(input())
S = input()
s = deque(list(S))
count = 0
def findb(ind,checker):
    global count
    st = S[ind:]
    if "B" in set(st):
        add = st.count("B")
        if add > 0:
            if ind + checker < N:
                if st[checker] == "B":
                    add -= 1
            count += add
def findg(ind,checker):
    global count
    st = S[ind:]
    if "G" in set(st):
        add = st.count("G")
        if add > 0:
            if ind + checker < N:
                if st[checker] == "G":
                    add -= 1
            count += add
def findr(ind,checker):
    global count
    st = S[ind:]
    if "R" in set(st):
        add = st.count("R")
        if add > 0:
            if ind + checker < N:
                if st[checker] == "R":
                    add -= 1
            count += add
for i in range(N-2):
    temp = s.popleft()
    if temp == "R":
        for j in [x for x, y in enumerate(S[i:]) if y == 'G']:
            findb(i+j,j)
        for j in [x for x, y in enumerate(S[i:]) if y == 'B']:
            findg(i+j,j)
    elif temp == "G":
        for j in [x for x, y in enumerate(S[i:]) if y == 'B']:
            findr(i+j,j)
        for j in [x for x, y in enumerate(S[i:]) if y == 'R']:
            findb(i+j,j)
    else:
        for j in [x for x, y in enumerate(S[i:]) if y == 'R']:
            findg(i+j,j)
        for j in [x for x, y in enumerate(S[i:]) if y == 'G']:
            findr(i+j,j)
print(count)

Fixed submission:
N = int(input())
S = input()
r = S.count('R')
g = S.count('G')
b = S.count('B')
count = r * g * b
for i in range(N):
    for j in range(i+1,N-1):
        if 2*j - i <= N-1:
            l = set([S[i],S[j],S[2*j-i]])
            if len(l) == 3:
                count -= 1
print(count)

Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque 
N = int(input())
S = input()
s = deque(list(S))
count = 0
def findb(ind,checker):
    global count
    b = S[ind:].count("B")
    if b > 0:
        if ind + checker < N:
            if S[ind+checker] == "B":
                b -= 1
        count += b
def findg(ind,checker):
    global count
    g = S[ind:].count("G")
    if g > 0:
        if ind + checker < N:
            if S[ind+checker] == "G":
                g -= 1
        count += g
def findr(ind,checker):
    global count
    r = S[ind:].count("R")
    if r > 0:
        if ind + checker < N:
            if S[ind+checker] == "R":
                r -= 1
        count += r
for i in range(N-2):
    temp = s.popleft()
    if temp == "R":
        for j in [x for x, y in enumerate(S[i:]) if y == 'G']:
            findb(i+j,j)
        for j in [x for x, y in enumerate(S[i:]) if y == 'B']:
            findg(i+j,j)
    elif temp == "G":
        for j in [x for x, y in enumerate(S[i:]) if y == 'B']:
            findr(i+j,j)
        for j in [x for x, y in enumerate(S[i:]) if y == 'R']:
            findb(i+j,j)
    else:
        for j in [x for x, y in enumerate(S[i:]) if y == 'R']:
            findg(i+j,j)
        for j in [x for x, y in enumerate(S[i:]) if y == 'G']:
            findr(i+j,j)
print(count)

Fixed submission:
N = int(input())
S = input()
r = S.count('R')
g = S.count('G')
b = S.count('B')
count = r * g * b
for i in range(N):
    for j in range(i+1,N-1):
        if 2*j - i <= N-1:
            l = set([S[i],S[j],S[2*j-i]])
            if len(l) == 3:
                count -= 1
print(count)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
S = input()
count = 0
def findb(ind,checker):
    global count
    if ind + checker < N:
        add = S[ind:ind+checker].count("B") + S[ind+checker+1:].count("B")
    else:
        add = S[ind:].count("B")
    count += add
def findg(ind,checker):
    global count
    if ind + checker < N:
        add = S[ind:ind+checker].count("G") + S[ind+checker+1:].count("G")
    else:
        add = S[ind:].count("G")
    count += add
def findr(ind,checker):
    global count
    if ind + checker < N:
        add = S[ind:ind+checker].count("R") + S[ind+checker+1:].count("R")
    else:
        add = S[ind:].count("R")
    count += add
for i in range(N):
    if S[i] == "R":
        for j in [x for x, y in enumerate(S[i:]) if y == 'G']:
            findb(i+j,j)
        for j in [x for x, y in enumerate(S[i:]) if y == 'B']:
            findg(i+j,j)
    elif S[i] == "G":
        for j in [x for x, y in enumerate(S[i:]) if y == 'B']:
            findr(i+j,j)
        for j in [x for x, y in enumerate(S[i:]) if y == 'R']:
            findb(i+j,j)
    else:
        for j in [x for x, y in enumerate(S[i:]) if y == 'R']:
            findg(i+j,j)
        for j in [x for x, y in enumerate(S[i:]) if y == 'G']:
            findr(i+j,j)
print(count)

Fixed submission:
N = int(input())
S = input()
r = S.count('R')
g = S.count('G')
b = S.count('B')
count = r * g * b
for i in range(N):
    for j in range(i+1,N-1):
        if 2*j - i <= N-1:
            l = set([S[i],S[j],S[2*j-i]])
            if len(l) == 3:
                count -= 1
print(count)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
S = input()
count = 0
def findb(ind,checker):
    global count
    b = S[ind:].count("B")
    if b > 0:
        if ind + checker < N:
            if S[ind+checker] == "B":
                b -= 1
        count += b
def findg(ind,checker):
    global count
    g = S[ind:].count("G")
    if g > 0:
        if ind + checker < N:
            if S[ind+checker] == "G":
                g -= 1
        count += g
def findr(ind,checker):
    global count
    r = S[ind:].count("R")
    if r > 0:
        if ind + checker < N:
            if S[ind+checker] == "R":
                r -= 1
        count += r
for i in range(N):
    if S[i] == "R":
        for j in [x for x, y in enumerate(S[i:]) if y == 'G']:
            findb(i+j,j)
        for j in [x for x, y in enumerate(S[i:]) if y == 'B']:
            findg(i+j,j)
    elif S[i] == "G":
        for j in [x for x, y in enumerate(S[i:]) if y == 'B']:
            findr(i+j,j)
        for j in [x for x, y in enumerate(S[i:]) if y == 'R']:
            findb(i+j,j)
    else:
        for j in [x for x, y in enumerate(S[i:]) if y == 'R']:
            findg(i+j,j)
        for j in [x for x, y in enumerate(S[i:]) if y == 'G']:
            findr(i+j,j)
print(count)

Fixed submission:
N = int(input())
S = input()
r = S.count('R')
g = S.count('G')
b = S.count('B')
count = r * g * b
for i in range(N):
    for j in range(i+1,N-1):
        if 2*j - i <= N-1:
            l = set([S[i],S[j],S[2*j-i]])
            if len(l) == 3:
                count -= 1
print(count)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
S = input()
count = 0
def findb(ind,checker):
    global count
    b = S[ind:].count("B")
    if ind + checker < N:
        if S[ind+checker] == "B":
            b -= 1
    if b > 0:
        count += b
def findg(ind,checker):
    global count
    g = S[ind:].count("G")
    if ind + checker < N:
        if S[ind+checker] == "G":
            g -= 1
    if g > 0:
        count += g
def findr(ind,checker):
    global count
    r = S[ind:].count("R")
    if ind + checker < N:
        if S[ind+checker] == "R":
            r -= 1
    if r > 0:
        count += r
for i in range(N):
    if S[i] == "R":
        for j in [x for x, y in enumerate(S[i:]) if y == 'G']:
            findb(i+j,j)
        for j in [x for x, y in enumerate(S[i:]) if y == 'B']:
            findg(i+j,j)
    elif S[i] == "G":
        for j in [x for x, y in enumerate(S[i:]) if y == 'B']:
            findr(i+j,j)
        for j in [x for x, y in enumerate(S[i:]) if y == 'R']:
            findb(i+j,j)
    else:
        for j in [x for x, y in enumerate(S[i:]) if y == 'R']:
            findg(i+j,j)
        for j in [x for x, y in enumerate(S[i:]) if y == 'G']:
            findr(i+j,j)
print(count)

Fixed submission:
N = int(input())
S = input()
r = S.count('R')
g = S.count('G')
b = S.count('B')
count = r * g * b
for i in range(N):
    for j in range(i+1,N-1):
        if 2*j - i <= N-1:
            l = set([S[i],S[j],S[2*j-i]])
            if len(l) == 3:
                count -= 1
print(count)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
S = input()
count = 0
def findb(ind,checker):
    global count
    b = S[ind:].count("B")
    if b > 0:
        if ind + checker < N:
            if S[ind+checker] == "B":
                count += b - 1
            else:
                count += b
        else:
            count += b
def findg(ind,checker):
    global count
    g = S[ind:].count("G")
    if g > 0:
        if ind + checker < N:
            if S[ind+checker] == "G":
                count += g - 1
            else:
                count += g
        else:
            count += g
def findr(ind,checker):
    global count
    r = S[ind:].count("R")
    if r > 0:
        if ind + checker < N:
            if S[ind+checker] == "R":
                count += r - 1
            else:
                count += r
        else:
            count += r
for i in range(N):
    if S[i] == "R":
        for j in [x for x, y in enumerate(S[i:]) if y == 'G']:
            findb(i+j,j)
        for j in [x for x, y in enumerate(S[i:]) if y == 'B']:
            findg(i+j,j)
    elif S[i] == "G":
        for j in [x for x, y in enumerate(S[i:]) if y == 'B']:
            findr(i+j,j)
        for j in [x for x, y in enumerate(S[i:]) if y == 'R']:
            findb(i+j,j)
    else:
        for j in [x for x, y in enumerate(S[i:]) if y == 'R']:
            findg(i+j,j)
        for j in [x for x, y in enumerate(S[i:]) if y == 'G']:
            findr(i+j,j)
print(count)

Fixed submission:
N = int(input())
S = input()
r = S.count('R')
g = S.count('G')
b = S.count('B')
count = r * g * b
for i in range(N):
    for j in range(i+1,N-1):
        if 2*j - i <= N-1:
            l = set([S[i],S[j],S[2*j-i]])
            if len(l) == 3:
                count -= 1
print(count)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
S = input()
count = 0
def findb(ind,checker):
    global count
    b = S[ind:].count("B")
    if b > 0:
        if ind + checker < N:
            if S[ind+checker] == "B":
                count += b - 1
            else:
                count += b
        else:
            count += b
def findg(ind,checker):
    global count
    g = S[ind:].count("G")
    if g > 0:
        if ind + checker < N:
            if S[ind+checker] == "G":
                count += g - 1
            else:
                count += g
        else:
            count += g
def findr(ind,checker):
    global count
    r = S[ind:].count("R")
    if r > 0:
        if ind + checker < N:
            if S[ind+checker] == "R":
                count += r - 1
            else:
                count += r
        else:
            count += r
for i in range(N):
    if S[i] == "R":
        for j in [x for x, y in enumerate(S[i:]) if y == 'G']:
            findb(i+j,j)
        for j in [x for x, y in enumerate(S[i:]) if y == 'B']:
            findg(i+j,j)
    elif S[i] == "G":
        for j in [x for x, y in enumerate(S[i:]) if y == 'B']:
            findr(i+j,j)
        for j in [x for x, y in enumerate(S[i:]) if y == 'R']:
            findb(i+j,j)
    else:
        for j in [x for x, y in enumerate(S[i:]) if y == 'R']:
            findg(i+j,j)
        for j in [x for x, y in enumerate(S[i:]) if y == 'G']:
            findr(i+j,j)
print(count)

Fixed submission:
N = int(input())
S = input()
r = S.count('R')
g = S.count('G')
b = S.count('B')
count = r * g * b
for i in range(N):
    for j in range(i+1,N-1):
        if 2*j - i <= N-1:
            l = set([S[i],S[j],S[2*j-i]])
            if len(l) == 3:
                count -= 1
print(count)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
S = input()
count = 0
def findb(ind,checker):
    b = S[ind:].count("B")
    if b > 0:
        if ind + checker < N:
            if S[ind+checker] == "B":
                return b - 1
            else:
                return b
        else:
            return b
    return 0
def findg(ind,checker):
    g = S[ind:].count("G")
    if g > 0:
        if ind + checker < N:
            if S[ind+checker] == "G":
                return g - 1
            else:
                return g
        else:
            return g
    return 0
def findr(ind,checker):
    r = S[ind:].count("R")
    if r > 0:
        if ind + checker < N:
            if S[ind+checker] == "R":
                return r - 1
            else:
                return r
        else:
            return r
    return 0
for i in range(N):
    if S[i] == "R":
        for j in [x for x, y in enumerate(S[i:]) if y == 'G']:
            count += findb(i+j,j)
        for j in [x for x, y in enumerate(S[i:]) if y == 'B']:
            count += findg(i+j,j)
    elif S[i] == "G":
        for j in [x for x, y in enumerate(S[i:]) if y == 'B']:
            count += findr(i+j,j)
        for j in [x for x, y in enumerate(S[i:]) if y == 'R']:
            count += findb(i+j,j)
    else:
        for j in [x for x, y in enumerate(S[i:]) if y == 'R']:
            count += findg(i+j,j)
        for j in [x for x, y in enumerate(S[i:]) if y == 'G']:
            count += findr(i+j,j)
print(count)

Fixed submission:
N = int(input())
S = input()
r = S.count('R')
g = S.count('G')
b = S.count('B')
count = r * g * b
for i in range(N):
    for j in range(i+1,N-1):
        if 2*j - i <= N-1:
            l = set([S[i],S[j],S[2*j-i]])
            if len(l) == 3:
                count -= 1
print(count)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
S = input()
count = 0
def findb(ind,checker):
    b = S[ind:].count("B")
    if b > 0:
        if ind + checker < N:
            if S[ind+checker] == "B":
                return b - 1
            else:
                return b
        else:
            return b
    return 0
def findg(ind,checker):
    g = S[ind:].count("G")
    if g > 0:
        if ind + checker < N:
            if S[ind+checker] == "G":
                return g - 1
            else:
                return g
        else:
            return g
    return 0
def findr(ind,checker):
    r = S[ind:].count("R")
    if r > 0:
        if ind + checker < N:
            if S[ind+checker] == "R":
                return r - 1
            else:
                return r
        else:
            return r
    return 0
for i in range(N):
    if S[i] == "R":
        for j in [x for x, y in enumerate(S[i:]) if y == 'G']:
            count += findb(i+j,j)
        for j in [x for x, y in enumerate(S[i:]) if y == 'B']:
            count += findg(i+j,j)
    elif S[i] == "G":
        for j in [x for x, y in enumerate(S[i:]) if y == 'B']:
            count += findr(i+j,j)
        for j in [x for x, y in enumerate(S[i:]) if y == 'R']:
            count += findb(i+j,j)
    else:
        for j in [x for x, y in enumerate(S[i:]) if y == 'R']:
            count += findg(i+j,j)
        for j in [x for x, y in enumerate(S[i:]) if y == 'G']:
            count += findr(i+j,j)
print(count)

Fixed submission:
N = int(input())
S = input()
r = S.count('R')
g = S.count('G')
b = S.count('B')
count = r * g * b
for i in range(N):
    for j in range(i+1,N-1):
        if 2*j - i <= N-1:
            l = set([S[i],S[j],S[2*j-i]])
            if len(l) == 3:
                count -= 1
print(count)