Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
S = input()
A = [[],[],[]]
ans = 0
for i in range(N):
    if S[i] == 'R':
        A[0].append(i)
    elif S[i] == 'G':
        A[1].append(i)
    else:
        A[2].append(i)

for i in A[0]:
    for j in A[1]:
        for k in A[2]:
            if  (i < j and j < k) or (k < j and j < i):
                if abs(i-j) != abs(j-k):
                    ans += 1
            elif (i < k and k < j) or (j < k and k < i):
                if abs(i-k) != abs(k-j):
                    ans += 1
            elif (j < i and i < k) or (k < i and i < j):
                if abs(j-i) != abs(k-i):
                    ans += 1

print(ans)

Fixed submission:
N = int(input())
S = input()
A = [[],[],[]]

for i in range(N):
    if S[i] == 'R':
        A[0].append(i)
    elif S[i] == 'G':
        A[1].append(i)
    else:
        A[2].append(i)
ans = len(A[0])*len(A[1])*len(A[2])
p = 0
for i in range(N):
  for j in range(N):
    if i+j+j <= N-1:
      if S[i] != S[i+j] and S[i] != S[i+j+j] and S[i+j] != S[i+j+j]:
        p += 1

print(ans-p)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
S = input()
A = [[],[],[]]
ans = 0
for i in range(N):
    if S[i] == 'R':
        A[0].append(i)
    elif S[i] == 'G':
        A[1].append(i)
    else:
        A[2].append(i)

for i in A[0]:
    for j in A[1]:
        for k in A[2]:
            if  (i < j and j < k) or (k < j and j < i):
                if abs(i-j) != abs(j-k):
                    ans += 1
            elif (i < k and k < j) or (j < k and k < i):
                if abs(i-k) != abs(k-j):
                    ans += 1
            elif (j < i and i < k) or (k < i and i < j):
                if abs(j-i) != abs(k-i):
                    ans += 1

print(ans)

Fixed submission:
N = int(input())
S = input()
A = [[],[],[]]

for i in range(N):
    if S[i] == 'R':
        A[0].append(i)
    elif S[i] == 'G':
        A[1].append(i)
    else:
        A[2].append(i)
ans = len(A[0])*len(A[1])*len(A[2])
p = 0
for i in range(N):
  for j in range(N):
    if i+j+j <= N-1:
      if S[i] != S[i+j] and S[i] != S[i+j+j] and S[i+j] != S[i+j+j]:
        p += 1

print(ans-p)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
S = input()
ans = 0
for i in range(N-3):
    for j in range(i+1,N-1):
        for k in range(j+1,N):
            if j-i != k-j:
                if S[i] != S[j] and S[j] != S[k] and S[k] != S[i]:
                    ans += 1
print(ans)

Fixed submission:
N = int(input())
S = input()
A = [[],[],[]]

for i in range(N):
    if S[i] == 'R':
        A[0].append(i)
    elif S[i] == 'G':
        A[1].append(i)
    else:
        A[2].append(i)
ans = len(A[0])*len(A[1])*len(A[2])
p = 0
for i in range(N):
  for j in range(N):
    if i+j+j <= N-1:
      if S[i] != S[i+j] and S[i] != S[i+j+j] and S[i+j] != S[i+j+j]:
        p += 1

print(ans-p)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
S = input()
ans = 0
for i in range(N-3):
    for j in range(i+1,N-1):
        for k in range(j+1,N):
            if j-i != k-j:
                if S[i] != S[j] and S[j] != S[k] and S[k] != S[i]:
                    ans += 1
print(ans)

Fixed submission:
N = int(input())
S = input()
A = [[],[],[]]

for i in range(N):
    if S[i] == 'R':
        A[0].append(i)
    elif S[i] == 'G':
        A[1].append(i)
    else:
        A[2].append(i)
ans = len(A[0])*len(A[1])*len(A[2])
p = 0
for i in range(N):
  for j in range(N):
    if i+j+j <= N-1:
      if S[i] != S[i+j] and S[i] != S[i+j+j] and S[i+j] != S[i+j+j]:
        p += 1

print(ans-p)