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

result = 0

if n <= 2:
    print(0)
    
for i in range(n-2):
    if s[i] == "R":
        for j in range(i+1, n-1):
            if s[j] == "G":
                a = s[j+1:].count("B")
                if 2*j - i <= n-1:
                    if s[2*j-i] == "B":
                        a -= 1
                result += a
            elif s[j] == "B":
                a = s[j+1:].count("G")
                if 2*j - i <= n-1:
                    if s[2*j-i] == "G":
                        a -= 1
                result += a
    if s[i] == "G":
        for j in range(i+1, n-1):
            if s[j] == "R":
                a = s[j+1:].count("B")
                if 2*j - i <= n-1:
                    if s[2*j-i] == "B":
                        a -= 1
                result += a
            elif s[j] == "B":
                a = s[j+1:].count("R")
                if 2*j - i <= n-1:
                    if s[2*j-i] == "R":
                        a -= 1
                result += a
    if s[i] == "B":
        for j in range(i+1, n-1):
            if s[j] == "G":
                a = s[j+1:].count("R")
                if 2*j - i <= n-1:
                    if s[2*j-i] == "R":
                        a -= 1
                result += a
            elif s[j] == "R":
                a = s[j+1:].count("G")
                if 2*j - i <= n-1:
                    if s[2*j-i] == "G":
                        a -= 1
                result += a
print(result)

Fixed submission:
n = int(input())
s = input()
 
result = 0
 
if n <= 2:
    print(0)

for i in range(n-2):
    if s[i] == "R":
        a = s[i+1:].count("G")
        b = s[i+1:].count("B")
        result += a*b
        for j in range(1, (n+1-i)//2):
            if (s[i+j] == "G" and s[i+2*j] == "B") or (s[i+j] == "B" and s[i+2*j] == "G"):
                result -= 1
    elif s[i] == "G":
        a = s[i+1:].count("R")
        b = s[i+1:].count("B")
        result += a*b
        for j in range(1, (n+1-i)//2):
            if (s[i+j] == "R" and s[i+2*j] == "B") or (s[i+j] == "B" and s[i+2*j] == "R"):
                result -= 1
    elif s[i] == "B":
        a = s[i+1:].count("R")
        b = s[i+1:].count("G")
        result += a*b
        for j in range(1, (n+1-i)//2):
            if (s[i+j] == "R" and s[i+2*j] == "G") or (s[i+j] == "G" and s[i+2*j] == "R"):
                result -= 1
print(result)

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

result = 0

if n <= 2:
    print(0)
    
for i in range(n-2):
    if s[i] == "R":
        for j in range(i+1, n-1):
            if s[j] == "G":
                a = s[j+1:].count("B")
                if 2*j - i <= n-1:
                    if s[2*j-i] == "B":
                        a -= 1
                result += a
            elif s[j] == "B":
                a = s[j+1:].count("G")
                if 2*j - i <= n-1:
                    if s[2*j-i] == "G":
                        a -= 1
                result += a
    if s[i] == "G":
        for j in range(i+1, n-1):
            if s[j] == "R":
                a = s[j+1:].count("B")
                if 2*j - i <= n-1:
                    if s[2*j-i] == "B":
                        a -= 1
                result += a
            elif s[j] == "B":
                a = s[j+1:].count("R")
                if 2*j - i <= n-1:
                    if s[2*j-i] == "R":
                        a -= 1
                result += a
    if s[i] == "B":
        for j in range(i+1, n-1):
            if s[j] == "G":
                a = s[j+1:].count("R")
                if 2*j - i <= n-1:
                    if s[2*j-i] == "R":
                        a -= 1
                result += a
            elif s[j] == "R":
                a = s[j+1:].count("G")
                if 2*j - i <= n-1:
                    if s[2*j-i] == "G":
                        a -= 1
                result += a
print(result)

Fixed submission:
n = int(input())
s = input()
 
result = 0
 
if n <= 2:
    print(0)

for i in range(n-2):
    if s[i] == "R":
        a = s[i+1:].count("G")
        b = s[i+1:].count("B")
        result += a*b
        for j in range(1, (n+1-i)//2):
            if (s[i+j] == "G" and s[i+2*j] == "B") or (s[i+j] == "B" and s[i+2*j] == "G"):
                result -= 1
    elif s[i] == "G":
        a = s[i+1:].count("R")
        b = s[i+1:].count("B")
        result += a*b
        for j in range(1, (n+1-i)//2):
            if (s[i+j] == "R" and s[i+2*j] == "B") or (s[i+j] == "B" and s[i+2*j] == "R"):
                result -= 1
    elif s[i] == "B":
        a = s[i+1:].count("R")
        b = s[i+1:].count("G")
        result += a*b
        for j in range(1, (n+1-i)//2):
            if (s[i+j] == "R" and s[i+2*j] == "G") or (s[i+j] == "G" and s[i+2*j] == "R"):
                result -= 1
print(result)

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

result = 0

if n <= 2:
    print(0)
    
for i in range(n-2):
    if s[i] == "R":
        for j in range(i+1, n-1):
            if s[j] == "G":
                for k in range(j+1, n):
                    if s[k] == "B":
                        if j-i != k-j:
                            result += 1
            elif s[j] == "B":
                for k in range(j+1, n):
                    if s[k] == "G":
                        if j-i != k-j:
                            result += 1
    if s[i] == "G":
        for j in range(i+1, n-1):
            if s[j] == "R":
                for k in range(j+1, n):
                    if s[k] == "B":
                        if j-i != k-j:
                            result += 1
            elif s[j] == "B":
                for k in range(j+1, n):
                    if s[k] == "R":
                        if j-i != k-j:
                            result += 1
    if s[i] == "B":
        for j in range(i+1, n-1):
            if s[j] == "R":
                for k in range(j+1, n):
                    if s[k] == "G":
                        if j-i != k-j:
                            result += 1
            elif s[j] == "G":
                for k in range(j+1, n):
                    if s[k] == "R":
                        if j-i != k-j:
                            result += 1
print(result)

Fixed submission:
n = int(input())
s = input()
 
result = 0
 
if n <= 2:
    print(0)

for i in range(n-2):
    if s[i] == "R":
        a = s[i+1:].count("G")
        b = s[i+1:].count("B")
        result += a*b
        for j in range(1, (n+1-i)//2):
            if (s[i+j] == "G" and s[i+2*j] == "B") or (s[i+j] == "B" and s[i+2*j] == "G"):
                result -= 1
    elif s[i] == "G":
        a = s[i+1:].count("R")
        b = s[i+1:].count("B")
        result += a*b
        for j in range(1, (n+1-i)//2):
            if (s[i+j] == "R" and s[i+2*j] == "B") or (s[i+j] == "B" and s[i+2*j] == "R"):
                result -= 1
    elif s[i] == "B":
        a = s[i+1:].count("R")
        b = s[i+1:].count("G")
        result += a*b
        for j in range(1, (n+1-i)//2):
            if (s[i+j] == "R" and s[i+2*j] == "G") or (s[i+j] == "G" and s[i+2*j] == "R"):
                result -= 1
print(result)

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

result = 0

if n <= 2:
    print(0)
    
for i in range(n-2):
    for j in range(i+1, n-1):
        rgb = ["R", "G", "B"]
        rgb.remove(s[i])
        if s[j] in rgb:
            rgb.remove(s[j])
            for k in range(j+1, n):
                if s[k] in rgb:
                    if j-i != k-j:
                        result += 1
print(result)

Fixed submission:
n = int(input())
s = input()
 
result = 0
 
if n <= 2:
    print(0)

for i in range(n-2):
    if s[i] == "R":
        a = s[i+1:].count("G")
        b = s[i+1:].count("B")
        result += a*b
        for j in range(1, (n+1-i)//2):
            if (s[i+j] == "G" and s[i+2*j] == "B") or (s[i+j] == "B" and s[i+2*j] == "G"):
                result -= 1
    elif s[i] == "G":
        a = s[i+1:].count("R")
        b = s[i+1:].count("B")
        result += a*b
        for j in range(1, (n+1-i)//2):
            if (s[i+j] == "R" and s[i+2*j] == "B") or (s[i+j] == "B" and s[i+2*j] == "R"):
                result -= 1
    elif s[i] == "B":
        a = s[i+1:].count("R")
        b = s[i+1:].count("G")
        result += a*b
        for j in range(1, (n+1-i)//2):
            if (s[i+j] == "R" and s[i+2*j] == "G") or (s[i+j] == "G" and s[i+2*j] == "R"):
                result -= 1
print(result)

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

result = 0

if n <= 2:
    print(0)
else:
    for i in range(n-2):
        for j in range(i+1, n-1):
            for k in range(j+1, n):
                if s[i] != s[j] and s[i] != s[k] and s[j] != s[k]:
                    if j-i != k-j:
                        result +=1
print(result)

Fixed submission:
n = int(input())
s = input()
 
result = 0
 
if n <= 2:
    print(0)

for i in range(n-2):
    if s[i] == "R":
        a = s[i+1:].count("G")
        b = s[i+1:].count("B")
        result += a*b
        for j in range(1, (n+1-i)//2):
            if (s[i+j] == "G" and s[i+2*j] == "B") or (s[i+j] == "B" and s[i+2*j] == "G"):
                result -= 1
    elif s[i] == "G":
        a = s[i+1:].count("R")
        b = s[i+1:].count("B")
        result += a*b
        for j in range(1, (n+1-i)//2):
            if (s[i+j] == "R" and s[i+2*j] == "B") or (s[i+j] == "B" and s[i+2*j] == "R"):
                result -= 1
    elif s[i] == "B":
        a = s[i+1:].count("R")
        b = s[i+1:].count("G")
        result += a*b
        for j in range(1, (n+1-i)//2):
            if (s[i+j] == "R" and s[i+2*j] == "G") or (s[i+j] == "G" and s[i+2*j] == "R"):
                result -= 1
print(result)