Problem:


Score : 400 points

Problem Statement

We have a string S of length N consisting of R, G, and B.

Find the number of triples (i,~j,~k)~(1 \leq i < j < k \leq N) that satisfy both of the following conditions:

S_i \neq S_j, S_i \neq S_k, and S_j \neq S_k.

j - i \neq k - j.

Constraints

1 \leq N \leq 4000

S is a string of length N consisting of R, G, and B.

Input

Input is given from Standard Input in the following format:

N
S

Output

Print the number of triplets in question.

Sample Input 1

4
RRGB

Sample Output 1

1

Only the triplet (1,~3,~4) satisfies both conditions. The triplet (2,~3,~4) satisfies the first condition but not the second, so it does not count.

Sample Input 2

39
RBRBGRBGGBBRRGBBRRRBGGBRBGBRBGBRBBBGBBB

Sample Output 2

1800



Sample input:
4
RRGB


Sample output:
1

Submission status: Runtime Error

Solution code:
import sys
from collections import Counter


def input():
    return sys.stdin.readline().strip()


sys.setrecursionlimit(20000000)

MOD = 10 ** 9 + 7
INF = float("inf")


def main():
    N = int(input())
    S = input()
    C = Counter(S)
    r = C.get("R")
    g = C.get("G")
    b = C.get("B")
    answer = r * g * b
    for left in range(N):
        for mid in range(left + 1, N):
            right = mid * 2 - left
            if right < N:
                if S[right] != S[mid] and S[mid] != S[left] and S[right] != S[left]:
                    answer -= 1
    print(answer)


if __name__ == "__main__":
    main()

Submission status: Runtime Error

Solution code:
import sys
from collections import Counter


def input():
    return sys.stdin.readline().strip()


sys.setrecursionlimit(20000000)

MOD = 10 ** 9 + 7
INF = float("inf")


def main():
    N = int(input())
    S = input()
    C = Counter(S)
    r = C.get("R")
    g = C.get("G")
    b = C.get("B")
    answer = r * g * b
    for left in range(N):
        for mid in range(left + 1, N):
            right = mid * 2 - left
            if right < N:
                if S[right] != S[mid] and S[mid] != S[left] and S[right] != S[left]:
                    answer = -1
    print(answer)


if __name__ == "__main__":
    main()

Submission status: Runtime Error

Solution code:
N=int(input())
S=str(input())
S=list(S)
ans=S.count('R')*S.count('G')*S.count('B')

for i in range(0,N-2):
    for j in range(i+1,N-1):
        k=(j-i)+j-1
        if (S[i] != S[j]) and (S[j] != S[k]) and (S[k] != S[i]) :
            ans -= 1
print(ans)

Submission status: Runtime Error

Solution code:
from collections import Counter

n=int(input())
s=input()

l=list(Counter(s).values())
res=l[0]*l[1]*l[2]

dis=0
chk=0

while chk==0:
	dis+=1
	for i in range(n):
		if dis*2>n-1:
			chk=1
			break
		if i+dis*2>n-1:
			break
		j=i+dis
		k=i+dis*2
		if s[i]!=s[j] and s[j]!=s[k] and s[k]!=s[i]:
			res-=1
			
print(res)

Submission status: Runtime Error

Solution code:
n = int(input())
string = input()

r=g=b=0

for idx, s in enumerate(string):
    if s == 'R':
        r+=1
    elif s == 'B':
        b+=1
    elif s == 'G':
        g+=1

ans = r*g*b

for i in range(n):
    for k in range(i+1, n):
        if string[i] != string[k]:
            if (k+i)%2 == 0 and len(set(string[i], string[k], string[(k+i)//2])) ==3:
                ans -= 1

print(ans)

Submission status: Runtime Error

Solution code:
n = int(input())
string = input()

r=g=b=0

for idx, s in enumerate(string):
    if s == 'R':
        r+=1
    elif s == 'B':
        b+=1
    elif s == 'G':
        g+=1

ans = r*g*b

for i in range(n):
    for k in range(i+1, n):
        if string[i] != string[k]:
            if (k+i)%2 == 0 and len(set(string[i], string[k], string[(k+i)//2]) ==3:
                ans -= 1

print(ans)

Submission status: Runtime Error

Solution code:
import sys
input = sys.stdin.readline
n = int(input())
s = input()
s = s.replace('R','0')
s = s.replace('G','1')
s = s.replace('B','2')
s = tuple(map(int,s))
rgb = [[0 for _ in range(3)] for _ in range(n+1)]
for i in range(n):
    for j in range(3):
        rgb[i+1][j] = rgb[i][j]
    rgb[i+1][s[i]] = rgb[i][s[i]] +1
rgb = tuple(rgb)
ans = 0
for i in range(n):
    a = s[i]
    for j in range(i+1,n):
        b = s[j]
        if a != b:
            c = 3 -a- b
            ans += rgb[n][c] - rgb[j+1][c]
            if 2*j-i < n and s[2*j-i] == c:
                ans -= 1

print(ans)

Submission status: Runtime Error

Solution code:
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7
import numpy as np
 
N = INT()
S = list(input())
 
r = S.count("R")
g = S.count("G")
b = S.count("B")
 
 
A = list(range(len(S)))
cnt = 0
for x, y in combinations(A, 2):
	if (x+y)//2 == (x+y)/2:
		z = (x+y)//2
		if S[x] != S[y] and S[x] != S[z] and S[y] != S[z]:
			cnt += 1
 
print(r*g*b-cnt)

Submission status: Runtime Error

Solution code:
def numS(S):
    x=len(S)
    if x<4:
        return 0
    T=S[1:]
   # print(T)
   l=x-1
    sum=0
    now=S[0]
    for i in range(l):
        now2=T[i]
    #    print(now2)
        if now2!=now:
            for j in range(i+1,l):
                now3=T[j]
     #           print(now,now2,now3)
                if now3!=now2 and now3!=now:
      #              print(i,j)
                    sum+=1
                    if 2*i+1==j:
                        sum-=1
    return numS(T)+sum
n=int(input())
S=input()
print(numS(S))

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Wed May  6 02:13:01 2020

@author: shinba
"""

N = int(input())
S = input()

R = []
G = []
B = []

for i in range(N):
    if S[i] == "R":
        R.append(i+1)
    elif S[i] == "G":
        G.append(i+1)
    else:
        B.append(i+1)

ans = len(R)*len(G)*len(B)

m = min(B)
M = max(B)

for i in R:
    for j in G:
        a = 2*j - i 
        b = (i+j)//2 if (i+j)%2 == 0 else 0
        c = 2*i - j
        if m <= a <= M:
            if S[a-1] == "B":
                ans -= 1
        if b != 0 and S[b-1] == "B":
            ans -= 1
        if m <= c <= M:
            if S[c-1] == "B":
                ans -= 1
            
print(ans)

Submission status: Runtime Error

Solution code:
n = int(input())
S = input()

R = []
G = []
B = []

for i in range(n):
    if S[i] == 'R':
        R.append(i)
    elif S[i] == 'G':
        G.append(i)
    else:
        B.append(i)

#print(R, G, B)

cnt = 0
r = R[0]
g = G[0]
b = B[0]

iR = 0
iG = 0
iB = 0

def ccc(ia, ib, ic, BB, CC):
    cnt = 0
    #for aa in BB[:ib:-1]:
    for aa in BB[ib:]:
        if aa > ia:
            for aaa in CC[ic:]:
                if aaa > aa:
                    if (aa - ia) != (aaa - aa):
                        #print(ia, aa, aaa)
                        cnt += 1


    return cnt

for i in range(n):
    if S[i] == 'R':
        if iR < len(R) - 1:
            iR += 1

        cnt += ccc(i, iG, iB, G, B)
        cnt += ccc(i, iB, iG, B, G)

    elif S[i] == 'G':
        if iG < len(G) - 1:
            iG += 1

        cnt += ccc(i, iR, iB, R, B)
        cnt += ccc(i, iB, iR, B, R)

    else:
        if iB < len(B) - 1:
            iB += 1

        cnt += ccc(i, iG, iR, G, R)
        cnt += ccc(i, iR, iG, R, G)

    
print(cnt)

Submission status: Runtime Error

Solution code:
n = int(input())
S = input()

R = []
G = []
B = []

for i in range(n):
    if S[i] == 'R':
        R.append(i)
    elif S[i] == 'G':
        G.append(i)
    else:
        B.append(i)

#print(R, G, B)

cnt = 0
r = R[0]
g = G[0]
b = B[0]

iR = 0
iG = 0
iB = 0

def ccc(ia, ib, ic, BB, CC):
    cnt = 0
    for aa in BB[ib:]:
        if aa > ia:
            for aaa in CC[ic:]:
                if aaa > aa and (aa - ia) != (aaa - aa):
                        #print(ia, aa, aaa)
                        cnt += 1
    return cnt

for i in range(n):
    if S[i] == 'R':
        if iR < len(R):
            iR += 1
            cnt += ccc(i, iG, iB, G, B)
            cnt += ccc(i, iB, iG, B, G)
        # else:
        #     print(iR)
    elif S[i] == 'G':
        if iG < len(G):
            iG += 1
            cnt += ccc(i, iR, iB, R, B)
            cnt += ccc(i, iB, iR, B, R)
        # else:
        #     print(iG)
    else:
        if iB < len(B):
            iB += 1
            cnt += ccc(i, iG, iR, G, R)
            cnt += ccc(i, iR, iG, R, G)
        # else:
        #     print(iB)
    
print(cnt)

Submission status: Runtime Error

Solution code:
n = int(input())
S = input()

R = []
G = []
B = []

for i in range(n):
    if S[i] == 'R':
        R.append(i)
    elif S[i] == 'G':
        G.append(i)
    else:
        B.append(i)

#print(R, G, B)

cnt = 0
r = R[0]
g = G[0]
b = B[0]

iR = 0
iG = 0
iB = 0

def ccc(ia, ib, ic, BB, CC):
    cnt = 0
    for aa in BB[ib:]:
        if aa > ia:
            for aaa in CC[ic:]:
                if aaa > aa:
                    if (aa - ia) != (aaa - aa):
                        #print(ia, aa, aaa)
                        cnt += 1
    return cnt

for i in range(n):
    if S[i] == 'R':
        iR += 1
        cnt += ccc(i, iG, iB, G, B)
        cnt += ccc(i, iB, iG, B, G)
    elif S[i] == 'G':
        iG += 1
        cnt += ccc(i, iR, iB, R, B)
        cnt += ccc(i, iB, iR, B, R)      
    else:
        iB += 1
        cnt += ccc(i, iG, iR, G, R)
        cnt += ccc(i, iR, iG, R, G)
    
print(cnt)
# c = 0
# for i in range(n):
#     for j in range(i + 1, n):
#         if s[i] != s[j]:
#             for k in range(j + 1, n):
#                 if j - i == k - j:
#                     continue
#                 if s[i] != s[k] and s[j] != s[k]:
#                     c += 1
# print(c)

Submission status: Runtime Error

Solution code:
N=int(input())
S=input()
R=[]
G=[]
B=[]
ans=0
x=0
a=0
b=0
c=0
for i in S:
    if i=="R":
        R.append(x)
    if i=="G":
        G.append(x)
    if i=="B":
        B.append(x)
    x+=1
for j in R:
    for k in G:
        if 2*k-j in B:
            B.pop(B.index(2*k-j))
            a+=1
        if 2*j-k in B:
            B.pop(B.index(2*j-k))   
            b+=1
        if (j+k)/2 in B:
            B.pop(B.index((j+k)/2))
            c+=1
        count+=len(B)
        if a!=0:
            B.append(2*k-j)
            a=0
        if b!=0:
            B.append(2*j-k)
            b=0
        if c!=0:
            B.append((j+k)/2)
            c=0
print(ans)

Submission status: Runtime Error

Solution code:
import itertools
n=int(input)
s=str(input())
ans=0
for s in itertools.combinations((0,n),3):
    i,j,k=s
    if j-i!=k-i:
        if s[i]!=s[j] and s[i]!=s[k] and s[j]!=s[k]:
            ans+=1
print(ans)

Submission status: Runtime Error

Solution code:
n = int(input())
s = input()

r = [0] * n
g = [0] * n
b = [0] * n
dc = {'R':[0]*n,'G':[0]*n,'B':[0]*n}
for i in range(n-1)[::-1]:
    dc['R'][i] = dc['R'][i + 1]
    dc['G'][i] = dc['G'][i + 1]
    dc['B'][i] = dc['B'][i + 1]
    dc[s[i+1]][i] += 1
# print(dc['R'])
# print(dc['G'])
# print(dc['B'])
dcc = {('R','G'):'B',('R','B'):'G',('B','G'):'R',('G','R'):'B',('B','R'):'G',('G','B'):'R'}
if(n <= 3):print(0)
else:
    c = 0
    for i in range(n):
        for j in range(i+1,n):
            if(s[i] == s[j]):continue
            d = j - i
            c += dc[dcc[(s[i],s[j])]][j]
            k = j + d
            if(k < n):
                if(s[k] == dcc[(s[i],s[j])]):c -= 1
print(c)

Submission status: Runtime Error

Solution code:
n = int(input())
s = input()

r = [0] * n
g = [0] * n
b = [0] * n
dc = {'R':[0]*n,'G':[0]*n,'B':[0]*n}
for i in range(n-1):
    dc['R'][i] = dc['R'][i + 1]
    dc['G'][i] = dc['G'][i + 1]
    dc['B'][i] = dc['B'][i + 1]
    dc[s[i]] += 1
# print(r)
# print(g)
# print(b)
dcc = {('R','G'):'B',('R','B'):'G',('B','G'):'R',('G','R'):'B',('B','R'):'G',('G','B'):'R'}
if(n <= 3):print(0)
else:
    c = 0
    for i in range(n):
        for j in range(i+1,n):
            if(s[i] == s[j]):continue
            d = j - i
            c += dc[dcc[(s[i],s[j])]][j]
            k = j + d
            if(k < n):
                if(s[k] == dcc[(s[i],s[j])]):c -= 1
print(c)

Submission status: Runtime Error

Solution code:
n = int(input())
s = input()

r = [0] * n
g = [0] * n
b = [0] * n
dc = {'R':[0]*n,'G':[0]*n,'B':[0]*n}
for i in range(n):
    dc['R'][i] = s[i+1:].count('R')
    dc['G'][i] = s[i+1:].count('G')
    dc['B'][i] = s[i+1:].count('B')
# print(r)
# print(g)
# print(b)
dcc = {('R','G'):'B',('R','B'):'G',('B','G'):'R',('G','R'):'B',('B','R'):'G',('G','B'):'R'}
if(n <= 3):print(0)
else:
    c = 0
    for i in range(n):
        for j in range(i+1,n):
            if(s[i] == s[j]):continue
            d = j - i
            c += dc[dcc[(s[i],s[j])]][j]
            k = j + d
            if(k < n):
                if(s[k] == dcc[(s[i],s[j])]):c -= 1
print(c)

Submission status: Runtime Error

Solution code:
N=int(Input[0][0])
S=Input[1][0]
import math
count=0
counter={'R':0,'G':0,'B':0}
for i in S:
    counter[i]+=1
s=counter['R']*counter['G']*counter['B']
for i in range(1,N-1):
    for j in range(i+1,N):
        k=2*j-i
        if k<=N and (S[i-1]!=S[j-1] and S[i-1]!=S[k-1] and S[j-1]!=S[k-1]):
                count+=1
print(s-count)

Submission status: Runtime Error

Solution code:
import math
import queue
from collections import defaultdict
 
def readInt():
	return int(input())
def readInts():
	return list(map(int, input().split()))
def readChar():
	return input()
def readChars():
	return input().split()
def factorization(n):
	res = []
	if n%2==0:
		res.append(2)
	for i in range(3,math.floor(n//2)+1,2):
		if n%i==0:
			c = 0
			for j in res:
				if i%j==0:
					c=1
			if c==0:
				res.append(i)
	return res
def fact2(n):
	p = factorization(n)
	res = []
	for i in p:
		c=0
		z=n
		while 1:
			if z%i==0:
				c+=1
				z/=i
			else:
				break
		res.append([i,c])
	return res
def fact(n):#階乗
	ans = 1
	m=n
	for _i in range(n-1):
		ans*=m
		m-=1
	return ans
def comb(n,r):#コンビネーション
	l = min(r,n-r)
	m=n
	u=1
	for _i in range(l):
		u*=m
		m-=1
	return u//fact(l)
def printQueue(q):
	r=q
	ans=[0]*r.qsize()
	for i in range(r.qsize()-1,-1,-1):
		ans[i] = r.get()
	print(ans)
def binary_search(li,item):#二分探索
	left,right = 0, len(li)
	while left<=right:
		mid = (left+right)//2
		if li[mid]==item:
			return mid
		elif li[mid]<item:
			left = mid+1
		else:
			right = mid-1
	return -1

N = readInt()
S = readChar()
rgb = {"R":[],"G":[],"B":[]}
for i in range(N):
	rgb[S[i]].append(i)

c=s=0
c=len(rgb["R"])*len(rgb["G"])*len(rgb["B"])
for i in range(1,N):
	for j in range(i+1,N):
		k = 2*j-i
		if k<=N-1:
			continue
		if S[i]==S[j] and S[i]==S[k]:
			s+=1

ans=c-s
print(ans)

Submission status: Runtime Error

Solution code:
import math
import queue
from collections import defaultdict
 
def readInt():
	return int(input())
def readInts():
	return list(map(int, input().split()))
def readChar():
	return input()
def readChars():
	return input().split()
def factorization(n):
	res = []
	if n%2==0:
		res.append(2)
	for i in range(3,math.floor(n//2)+1,2):
		if n%i==0:
			c = 0
			for j in res:
				if i%j==0:
					c=1
			if c==0:
				res.append(i)
	return res
def fact2(n):
	p = factorization(n)
	res = []
	for i in p:
		c=0
		z=n
		while 1:
			if z%i==0:
				c+=1
				z/=i
			else:
				break
		res.append([i,c])
	return res
def fact(n):#階乗
	ans = 1
	m=n
	for _i in range(n-1):
		ans*=m
		m-=1
	return ans
def comb(n,r):#コンビネーション
	l = min(r,n-r)
	m=n
	u=1
	for _i in range(l):
		u*=m
		m-=1
	return u//fact(l)
def printQueue(q):
	r=q
	ans=[0]*r.qsize()
	for i in range(r.qsize()-1,-1,-1):
		ans[i] = r.get()
	print(ans)
def binary_search(li,item):#二分探索
	left,right = 0, len(li)
	while left<=right:
		mid = (left+right)//2
		if li[mid]==item:
			return mid
		elif li[mid]<item:
			left = mid+1
		else:
			right = mid-1
	return -1

N = readInt()
S = readChar()
rgb = {"R":[],"G":[],"B":[]}
for i in range(N):
	rgb[S[i]].append(i)

c=s=0
c=len(rgb["R"])*len(rgb["G"])*len(rgb["B"])
for i in range(1,N):
	for j in range(i+1,N):
		k = 2*j-i
		if S[i]==s[j] and s[i]==s[k]:
			s+=1

ans=c-s
print(ans)

Submission status: Runtime Error

Solution code:
N = int(input())
S = list(input())
ans = S.count('R')*S.count('G')*S.count('B') 
for i in range(N): 
    if S[i]=='R':
       S[i] =1
    elif S[i]=='G':
       S[i] =2
    elif S[i]=='B':
       S[i] =4
    for j in range(i+1,N):
        k=2*j-i
        if k>=N : 
           continue  
        if S[i]+S[j]+S[k]==7 : 
           ans-=1 
print(ans)

Submission status: Runtime Error

Solution code:
N = int(input())
S = list(input())
ans = S.count('R')*S.count('G')*S.count('B') 
for i in range(N): 
   if S[i]=='R':
       S[i]=1
   elif S[i]=='G':
       S[i]
   elif S[i]=='B':
       S[i]=4
for i in range(N): 
   for j in range(i+1,N):
     k=2*j-i
     if k>=N : 
       continue  
     if S[i]+S[j]+S[k]==7 : 
         ans-=1   
print(ans)

Submission status: Runtime Error

Solution code:
N = int(input())
S = list(input())
ans = S.count('R')*S.count('G')*S.count('B') 
for i in range(N): 
   if S[i]=='R':
       S[i]=1
   elif S[i]=='G':
       S[i]
   elif S[i]=='B':
       S[i]=4
for i in range(N): 
   for j in range(i+1,N):
     k=2*j-i
     if k>N : 
       continue  
     if S[i]+S[j]+S[k]==7 : 
         ans-=1   
print(ans)

Submission status: Runtime Error

Solution code:
N = int(input())
S = list(input())
ans = S.count('R')*S.count('G')*S.count('B') 
 #1番目の条件を満たすものの総数は(Rの個数)*(Gの個数)*(Bの個数)
for i in range(N): #判定を簡単にするためR:=1,G:=2,B:=4と置き換える
   if S[i]=='R':
       S[i]=1
   elif S[i]=='G':
       S[i]
   elif S[i]=='B':
       S[i]=4
for i in range(N): 
 #すべての(i,j)について(i,j,2*j-i)が1番目の条件を満たし、かつ2番目の条件を満たさないかを判定する
   for j in range(i+1,N):
     k=2*j-i
     if k>N : 
       continue  #考えなくて良いものはスキップ
     if S[i]+S[j]+S[k]==7 : 
         ans-=1   #1番目の条件を満たし、かつ2番目の条件を満たさないので、1を引く
print(ans)

Submission status: Runtime Error

Solution code:
def main():
  import sys
  input=sys.stdin.readline
  N=int(input())
  S=input()
  t=0
  for k in range(j,N+1):
    for j in range(i,N):
      for i in range(1,N-1):
        if S[i-1]!=S[j-1] and S[j-1]!=S[k-1] and S[k-1]!=S[i-1] and j-i!=k-j:
          t+=1
  print(t)
if __name__ == '__main__':
  main()

Submission status: Runtime Error

Solution code:
import sys
input=sys.stdin.readline
N=int(input())
S=[int(input()) for _ in range(N)]
t=0
for i in range(1,N-1):
  for j in range(i,N):
    for k in range(j,N+1):
      if S[i-1]!=S[j-1] and S[j-1]!=S[k-1] and S[k-1]!=S[i-1] and j-i!=k-j:
        t+=1
print(t)

Submission status: Runtime Error

Solution code:
from collections import Counter
from copy import copy

n = int(input())
s = input()

total_cnt = dict(Counter(s))
cnt = [total_cnt]
for i, c in enumerate(s):
    curr_cnt = copy(cnt[-1])
    curr_cnt[c] -= 1
    cnt.append(curr_cnt)

res = 0
for i, c1 in enumerate(s):
    for j in range(i + 1, n - 1):
        c2 = s[j]
        if c2 == c1:
            continue
        for c3 in "RGB":
            if c3 == c1 or c3 == c2:
                continue
            res += cnt[j + 1][c3]
            k = 2 * j - i
            if k >= n:
                continue
            if s[k] == c3:
                res -= 1
print(res)

Submission status: Runtime Error

Solution code:
N =input()
for i in range(1,N-1):
  for j in range(j,N):
    for k in range(k,N+1):
      if N[i] != N[j] != N[k] and j-i != k-j:
        count += 1
      else:
        pass
print(count)

Submission status: Runtime Error

Solution code:
N = int(input())
S = list(input())
r = S.count("R")
g = S.count("G")
b = S.count("B")
 
ans = r*g*b
for i in range(N-2):
  for j in range(i+1, N-1):
    k = 2*j-i
    if k <= N-1:
      if S[i] != S[j] and S[i] != S[k] and S[j] != S[k]:
        ans -= 1
 
print(ans

Submission status: Runtime Error

Solution code:
N = int(input())
S = list(input())
r = S.count("R")
g = S.count("G")
b = S.count("B")
 
ans = r*g*b
for i in range(N):
  for j in range(i+1, N):
    k = 2*j-i
    if k <= N-1:
      if S[i] != S[j] and S[i] != S[k] and S[j] != S[k]:
        ans -= 1
 
print(ans

Submission status: Runtime Error

Solution code:
N = int(input())
S = list(input())
r = S.count("R")
g = S.count("G")
b = S.count("B")

ans = r*g*b
for i in range(N):
  for j in range(N):
    k = 2*j-i
    if S[i] != S[j] and S[i] != S[k] and S[j] != S[k]:
      ans -= 1

print(ans)

Submission status: Runtime Error

Solution code:
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]:
    for k in range(j+1, n):
      if s[j] != s[k] and s[k]!= s[i]:
        if j-i != k-j:
          ans +=1
print(ans)

Submission status: Runtime Error

Solution code:
n = int(input())
raw = input()
rgb = {}
cnt = 1
sum = 0
for i in raw:
    if i not in rgb:
        rgb[i] = []
    rgb[i].append(cnt)
    cnt+=1

for i in rgb["R"]:
    for j in rgb["G"]:
        for k in rgb["B"]:
            li = [i,j,k]
            li.sort()
            tmo = li[1] - li[0]
            tmp = li[2] - li[1]
            if tmo != tmp:
                sum += 1
print(sum)

Submission status: Runtime Error

Solution code:
n = int(input())
raw = input()
rgb = {}
cnt = 1
sum = 0
for i in raw:
    if i not in rgb:
        rgb[i] = []
    rgb[i].append(cnt)
    cnt+=1

for i in rgb["R"]:
    for j in rgb["G"]:
        for k in rgb["B"]:
            li = [i,j,k]
            li.sort()
            print(li)
            tmo = li[1] - li[0]
            tmp = li[2] - li[1]
            if tmo != tmp:
                sum += 1
print(sum)

Submission status: Runtime Error

Solution code:
n = int(input())
raw = input()
rgb = {}
cnt = 1
sum = 0
for i in raw:
    if i not in rgb:
        rgb[i] = []
    rgb[i].append(cnt)
    cnt+=1

print(rgb)

for i in rgb["R"]:
    for j in rgb["G"]:
        for k in rgb["B"]:
            li = [i,j,k]
            li.sort()
            tmo = li[1] - li[0]
            tmp = li[2] - li[1]
            if tmo != tmp:
                sum += 1
print(sum)

Submission status: Runtime Error

Solution code:
cd ../n = int(input())
s = input()

r = []
g = []
b = []

for i, c in enumerate(s):
    if c == "R":
        r.append(i)
    elif c == "G":
        g.append(i)
    else:
        b.append(i)


ans = 0
for ri in r:
    for gi in g:
        for bi in b:
            arr = [ri, gi, bi]
            arr.sort()
            if arr[0] + arr[2] == 2 * arr[1]:
                pass
            else:
                ans += 1

print(ans)

Submission status: Runtime Error

Solution code:
r_cnt = S.count("R")
g_cnt  = S.count("G")
b_cnt = S.count("B")

ans = r_cnt * g_cnt * b_cnt

for i in range(N):
    for d in range(N):
        j = i + d
        k = j + d
        if k >= N:
            break
        if S[i] != S[j] and S[j] != S[k] and S[i] != S[k]:
            ans -= 1
print(ans)

Submission status: Runtime Error

Solution code:
n = int(input())
s = str(input())
rn = s.count("R")
gn = s.count("G")
bn = s.count("B")

ct=0
for i in range(n):
  for j in range(i+1,n):
    k = 2*j - i
    if k = n:
      break
    elif s[i]!=s[j] and s[j]!=s[k]and s[i]!=s[k]:
      ct += 1
 
print(rn*gn*bn-ct)

Submission status: Runtime Error

Solution code:
N=int(input())
S=input()
R=[]
G=[]
B=[]

def binary_search(A,n):
    find=False
    start=0
    end=len(A)
    if len(A)==1 and A[0]==n:
        find=True
    elif A[0]==n:
        find=True
    else:
        while find==False and start<end-1:
            middle=(start+end)//2
            if n>A[middle]:
                start=middle
            elif n<A[middle]:
                end=middle
            else:
                find=True
    return find

for n in range(N):
    if S[n]=="R":
        R.append(n)
    elif S[n]=="G":
        G.append(n)
    else:
        B.append(n)

EVERY=len(R)*len(G)*len(B)

REMOVE=0
for r in R:
    for g in G:
        if (r+g)%2==0:
            candidate=[2*r-g,(r+g)//2,2*g-r]
        else:
            candidate=[2*r-g,2*g-r]
        
        for e in candidate:
            if binary_search(B,e)==True:
                REMOVE+=1

print(EVERY-REMOVE)

Submission status: Runtime Error

Solution code:
import numpy as np
import sys

input = sys.stdin.readline


N = int(input())

S = input()

color =list("RGB")

#色がRGBの３色ないとき
for x in color:
    if x not in S:
        print(0)
        exit()

r = 0
g = 0
b = 0
for i in range(len(S)):
    if S[i] == color[0]:
        r+=1
    elif S[i] == color[1]:
        g+=1
    elif S[i] == color[2]:
        b+=1

all = r*g*b

sub = 0
for i in range(N):
    for j in range(i+1,N):
        k = 2*j - i
        #kがN以上の位置にある
        if k >= N:
            continue

        #同じ色がある
        if S[i] == S[j] or S[j] == S[k] or S[k] == S[i] :
            continue
        sub+=1

print(all - sub)

Submission status: Runtime Error

Solution code:
n,s = input().split()
s = list(s)

count = 0

for i in range(0,len(s)):
    for j in range(i,len(s)):
        for k in range(j,len(s)):
            if(j-i != k-j) and (s[i] != s[j] and s[i] != s[k] and s[j] != s[k]):
                count += 1


print(count)

Submission status: Runtime Error

Solution code:
"""
N = int(input())
S = input()

def main(N,S):
    count=0
    for i in range(1,N-2 +1):
        for j in range(i+1, N-1 +1):
            for k in range(j+1, N +1):
                if j-i != k-j and S[i-1]!=S[j-1]!=S[k-1]!=S[i-1]:
                    count += 1
    print(count)

if __name__=='__main__':
    main(N,S)
    
    """
import itertools
N = int(input())
S = input()
out = S.count('R') * S.count('G') * S.count('B')

RGBs = list(itertools.permutations(['R', 'G', 'B'], 3))

for i in range(1, N-1):
  for j in range(i+1,N):
      for k in range(j+1,N+1):
          if (S[i], S[j], S[k]) in RGBs:
              out -= 1
print(out)

Submission status: Runtime Error

Solution code:
Npt

Submission status: Runtime Error

Solution code:
"""
import random
import functools
import copy
import bisect
import array
import re
import collections
import heapq
import fractions
import itertools
import string
import math
from operator import itemgetter as ig
from bisect import bisect_left, bisect_right, insort_left, insort_right
from itertools import permutations, combinations, product, accumulate, groupby
from heapq import heappush, heappop
from collections import deque, defaultdict, Counter
import sys
sys.setrecursionlimit(10 ** 7)
# import numpy as np

inf = 10 ** 20
INF = float("INF")
mod = 10 ** 9 + 7
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]
ddn = dd + [(-1, 1), (1, 1), (1, -1), (-1, -1)]
ddn9 = ddn + [(0, 0)]
'''for dx, dy in dd:
        nx = j + dx; ny = i + dy
            if 0 <= nx < w and 0 <= ny < h:'''
"""
from collections import deque, defaultdict, Counter
import math
import sys
sys.setrecursionlimit(10 ** 7)


def wi(): return list(map(int, sys.stdin.readline().split()))
# WideIntPoint


def wip(): return [int(x) - 1 for x in sys.stdin.readline().split()]


def ws(): return sys.stdin.readline().split()


def si(): return int(sys.stdin.readline())  # SingleInt


def ss(): return input()


def hi(n): return [si() for _ in range(n)]


def hs(n): return [ss() for _ in range(n)]  # HeightString


def s_list(): return list(input())


def mi(n): return [wi() for _ in range(n)]  # MatrixInt


def mip(n): return [wip() for _ in range(n)]


def ms(n): return [ws() for _ in range(n)]


def num_grid(n): return [[int(i) for i in sys.stdin.readline().split()[
    0]] for _ in range(n)]  # NumberGrid


def grid(n): return [s_list() for _ in range(n)]


def gcd(a, b):
    while b:
        a, b = b, a % b
    return a

# a/b の切り上げ


def round_up(a, b):
    """ a/b の切り上げ """
    c = (a + b - 1) / b
    return c


def lcm(a, b):
    """a,bの最小公倍数"""
    return a * b // gcd(a, b)


def main():
    n = int(input())
    s = input()
    r = 0
    g = 0
    b = 0
    for i in range(n):
        if s[i] == 'R':
            r += 1
        elif s[i] == 'G':
            g += 1
        else:
            b += 1
    ans = r*g*b
    
    for i in range(n-2):
        for j in range(i, n-1):
            if s[i] != s[j] and 2*j-i <= n and s[j] != s[2*j-i] and s[i] != s[2*j-i]:
                ans -= 1
    print(ans)
            
if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
"""
import random
import functools
import copy
import bisect
import array
import re
import collections
import heapq
import fractions
import itertools
import string
import math
from operator import itemgetter as ig
from bisect import bisect_left, bisect_right, insort_left, insort_right
from itertools import permutations, combinations, product, accumulate, groupby
from heapq import heappush, heappop
from collections import deque, defaultdict, Counter
import sys
sys.setrecursionlimit(10 ** 7)
# import numpy as np

inf = 10 ** 20
INF = float("INF")
mod = 10 ** 9 + 7
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]
ddn = dd + [(-1, 1), (1, 1), (1, -1), (-1, -1)]
ddn9 = ddn + [(0, 0)]
'''for dx, dy in dd:
        nx = j + dx; ny = i + dy
            if 0 <= nx < w and 0 <= ny < h:'''
"""
from collections import deque, defaultdict, Counter
import math
import sys
sys.setrecursionlimit(10 ** 7)


def wi(): return list(map(int, sys.stdin.readline().split()))
# WideIntPoint


def wip(): return [int(x) - 1 for x in sys.stdin.readline().split()]


def ws(): return sys.stdin.readline().split()


def si(): return int(sys.stdin.readline())  # SingleInt


def ss(): return input()


def hi(n): return [si() for _ in range(n)]


def hs(n): return [ss() for _ in range(n)]  # HeightString


def s_list(): return list(input())


def mi(n): return [wi() for _ in range(n)]  # MatrixInt


def mip(n): return [wip() for _ in range(n)]


def ms(n): return [ws() for _ in range(n)]


def num_grid(n): return [[int(i) for i in sys.stdin.readline().split()[
    0]] for _ in range(n)]  # NumberGrid


def grid(n): return [s_list() for _ in range(n)]


def gcd(a, b):
    while b:
        a, b = b, a % b
    return a

# a/b の切り上げ


def round_up(a, b):
    """ a/b の切り上げ """
    c = (a + b - 1) / b
    return c


def lcm(a, b):
    """a,bの最小公倍数"""
    return a * b // gcd(a, b)


def main():
    n = int(input())
    s = input()
    r = 0
    g = 0
    b = 0
    for i in range(n):
        if s[i] == 'R':
            r += 1
        elif s[i] == 'G':
            g += 1
        else:
            b += 1
    ans = r*g*b
    
    for i in range(n-2):
        for j in range(i, n-1):
            if s[i] != s[j] and 2*j-i <= n and s[j] != s[2*j-i] and s[i] != s[2+j-i]:
                ans -= 1
    print(ans)
            
if __name__ == '__main__':
    main()