Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
s = input()
 
ans = s.count("R") * s.count("G") * s.count("B")
for i in range(n-2):
    for j in range(i+1,n-1):
        for k in range(j+1,n):
            if s[k] != s[i] and s[k] != s[j] and s[i] != s[j]:
                if j-i == k-j:
                    ans -= 1
                    
print(ans)

Fixed submission:
n = int(input())
s = input()
 
ans = s.count("R") * s.count("G") * s.count("B")
for i in range(n-2):
    for j in range(i+1,n-1):
        k = 2*j-i
        if k < n:
            if s[k] != s[i] and s[k] != s[j] and s[i] != s[j]:
                    ans -= 1
                    
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
s = input()
 
ans = s.count("R") * s.count("G") * s.count("B")
for i in range(n-2):
    for j in range(i+1,n-1):
        for k in range(j+1,n):
            if s[k] != s[i] and s[k] != s[j] and s[i] != s[j]:
                if j-i == k-j:
                    ans -= 1
                    
print(ans)

Fixed submission:
n = int(input())
s = input()
 
ans = s.count("R") * s.count("G") * s.count("B")
for i in range(n-2):
    for j in range(i+1,n-1):
        k = 2*j-i
        if k < n:
            if s[k] != s[i] and s[k] != s[j] and s[i] != s[j]:
                    ans -= 1
                    
print(ans)

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

ans = 0
for i in range(n-2):
    one = s[i]
    for j in range(i+1,n-1):
        if one == s[j]:
            continue
        two = s[j]
        l = j-i
        for k in range(j+1,n):
            if s[k] != one and s[k] != two:
                if k-j != l:
                    ans += 1

print(ans)

Fixed submission:
n = int(input())
s = input()
 
ans = s.count("R") * s.count("G") * s.count("B")
for i in range(n-2):
    for j in range(i+1,n-1):
        k = 2*j-i
        if k < n:
            if s[k] != s[i] and s[k] != s[j] and s[i] != s[j]:
                    ans -= 1
                    
print(ans)

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

ans = 0
for i in range(n-2):
    one = s[i]
    for j in range(i+1,n-1):
        if one == s[j]:
            continue
        two = s[j]
        l = j-i
        for k in range(j+1,n):
            if s[k] != one and s[k] != two:
                if k-j != l:
                    ans += 1

print(ans)



Fixed submission:
n = int(input())
s = input()
 
ans = s.count("R") * s.count("G") * s.count("B")
for i in range(n-2):
    for j in range(i+1,n-1):
        k = 2*j-i
        if k < n:
            if s[k] != s[i] and s[k] != s[j] and s[i] != s[j]:
                    ans -= 1
                    
print(ans)

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

ans = 0
for i in range(n-2):
    for j in range(i+1,n-1):
        if s[i] == s[j]:
            continue
        l = j-i
        for k in range(j+1,n):
            if s[k] != s[i] and s[k] != s[j]:
                if k-j != l:
                    ans += 1

print(ans)



Fixed submission:
n = int(input())
s = input()
 
ans = s.count("R") * s.count("G") * s.count("B")
for i in range(n-2):
    for j in range(i+1,n-1):
        k = 2*j-i
        if k < n:
            if s[k] != s[i] and s[k] != s[j] and s[i] != s[j]:
                    ans -= 1
                    
print(ans)

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

ans = 0
for i in range(n-2):
    for j in range(i+1,n-1):
        if s[i] == s[j]:
            continue
        l = j-i
        for k in range(j+1,n):
            if s[k] != s[i] and s[k] != s[j]:
                if k-j != l:
                    ans += 1

print(ans)

Fixed submission:
n = int(input())
s = input()
 
ans = s.count("R") * s.count("G") * s.count("B")
for i in range(n-2):
    for j in range(i+1,n-1):
        k = 2*j-i
        if k < n:
            if s[k] != s[i] and s[k] != s[j] and s[i] != s[j]:
                    ans -= 1
                    
print(ans)