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


R = []
B = []
G = []
p = 0
for i in S:
    if(i == "R"):
        R.append(p)
    elif(i == "B"):
        B.append(p)
    elif(i == "G"):
        G.append(p)
    p += 1
sum = len(R) * len(B) * len(G)
for r in R:
    for b in B:
        up = max(r, b)
        dw = min(r, b)
        d = up-dw
        if up + d in G:
            sum -= 1
        if dw - d in G:
            sum -= 1
        if (r+b)/2 in G:
            sum -= 1

print(sum)


            

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


R = []
B = []
G = []
p = 0
for i in S:
    if(i == "R"):
        R.append(p)
    elif(i == "B"):
        B.append(p)
    elif(i == "G"):
        G.append(p)
    p += 1
R = set(R)
B = set(B)
G = set(G)
sum = len(R) * len(B) * len(G)
for r in R:
    for b in B:
        up = max(r, b)
        dw = min(r, b)
        d = up-dw
        if up + d in G:
            sum -= 1
        if dw - d in G:
            sum -= 1
        if (r+b)/2 in G:
            sum -= 1

print(sum)

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

R = []
B = []
G = []
p = 0
for i in S:
    if(i == "R"):
        R.append(p)
    elif(i == "B"):
        B.append(p)
    elif(i == "G"):
        G.append(p)
    p += 1
for r in R:
    for b in B:
        rb = abs(r - b)
        for g in G:
            rg = abs(r - g)
            bg = abs(b - g)
            if(rb==rg or rg==bg or bg==rb):
                continue
            else:
                sum += 1

print(sum)

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


R = []
B = []
G = []
p = 0
for i in S:
    if(i == "R"):
        R.append(p)
    elif(i == "B"):
        B.append(p)
    elif(i == "G"):
        G.append(p)
    p += 1
R = set(R)
B = set(B)
G = set(G)
sum = len(R) * len(B) * len(G)
for r in R:
    for b in B:
        up = max(r, b)
        dw = min(r, b)
        d = up-dw
        if up + d in G:
            sum -= 1
        if dw - d in G:
            sum -= 1
        if (r+b)/2 in G:
            sum -= 1

print(sum)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
S = input()
sum = 0
for i in range(N):
    for j in range(i):
        if(S[i] == S[j]):
            continue
        for k in range(j):
            if(k - j == j - i):
                continue
            if(S[j] == S[k]):
                continue
            elif(S[i] == S[k]):
                continue
            sum += 1
            
print(sum)

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


R = []
B = []
G = []
p = 0
for i in S:
    if(i == "R"):
        R.append(p)
    elif(i == "B"):
        B.append(p)
    elif(i == "G"):
        G.append(p)
    p += 1
R = set(R)
B = set(B)
G = set(G)
sum = len(R) * len(B) * len(G)
for r in R:
    for b in B:
        up = max(r, b)
        dw = min(r, b)
        d = up-dw
        if up + d in G:
            sum -= 1
        if dw - d in G:
            sum -= 1
        if (r+b)/2 in G:
            sum -= 1

print(sum)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
S = input()
sum = 0
for i in range(N):
    for j in range(i):
        for k in range(j):
            if(k - j == j - i):
                continue
            if(S[i] == S[j]):
                continue
            elif(S[j] == S[k]):
                continue
            elif(S[i] == S[k]):
                continue
            sum += 1
            
print(sum)

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


R = []
B = []
G = []
p = 0
for i in S:
    if(i == "R"):
        R.append(p)
    elif(i == "B"):
        B.append(p)
    elif(i == "G"):
        G.append(p)
    p += 1
R = set(R)
B = set(B)
G = set(G)
sum = len(R) * len(B) * len(G)
for r in R:
    for b in B:
        up = max(r, b)
        dw = min(r, b)
        d = up-dw
        if up + d in G:
            sum -= 1
        if dw - d in G:
            sum -= 1
        if (r+b)/2 in G:
            sum -= 1

print(sum)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
S = input()
sum = 0
for i in range(N):
    for j in range(i):
        for k in range(j):
            if(k - j == j - i):
                continue
            elif(i == j):
                continue
            elif(j == k):
                continue
            elif(k == i):
                continue
            if(S[i] == S[j]):
                continue
            elif(S[j] == S[k]):
                continue
            elif(S[i] == S[k]):
                continue
            sum += 1
            
print(sum)

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


R = []
B = []
G = []
p = 0
for i in S:
    if(i == "R"):
        R.append(p)
    elif(i == "B"):
        B.append(p)
    elif(i == "G"):
        G.append(p)
    p += 1
R = set(R)
B = set(B)
G = set(G)
sum = len(R) * len(B) * len(G)
for r in R:
    for b in B:
        up = max(r, b)
        dw = min(r, b)
        d = up-dw
        if up + d in G:
            sum -= 1
        if dw - d in G:
            sum -= 1
        if (r+b)/2 in G:
            sum -= 1

print(sum)