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: Time Limit Exceeded

Solution code:
n = int(input())
s = input()
cnt = 0
for i in range(n):
    for j in range(i + 1, n):
        if s[i] == s[j]:
            continue
        k = 2*j - i
        if j < k < n and len({s[i], s[j], s[k]}) == 3:
            cnt += 1
print(s.count('R') * s.count('G') * s.count('B') - cnt)

Submission status: Time Limit Exceeded

Solution code:
# coding: utf-8

# 標準入力 <int>
N = int(input())

# 標準入力<str>
S = input()

ans = 0

for i in range(N - 2):

  S2 = []
  for j in range(N - i - 2):
    rgb = "RGB"
    if S[i] == S[i + j + 1]:
      continue
    rgb = rgb.replace(S[i], "")
    rgb = rgb.replace(S[i + j + 1], "")
    if i + ((j + 1) * 2) < N:
      S2 = S[i + j + 2:i + (2 * j) + 2] + S[i + (2 * j) + 3:]
    else:
      S2 = S[i + j + 2:]
    ans += S2.count(rgb)

print(ans)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
s = input()
cnt = 0
for i in range(n):
    for j in range(i + 1, n):
        k = 2*j - i
        if j < k < n and s[i] != s[j] and s[i] != s[k] and s[j] != s[k]:
            cnt += 1
print(s.count('R') * s.count('G') * s.count('B') - cnt)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
s = input()
cnt = 0
for i in range(n):
    for j in range(i + 1, n):
        k = 2*j - i
        if j < k < n and len({s[i], s[j], s[k]}) == 3:
            cnt += 1
print(s.count('R') * s.count('G') * s.count('B') - cnt)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
S = input()
count = 0
def findlet(let,ind):
    add = len([x for x in st[ind:] if x == let])
    if add > 0:
        if 2*ind < len(st):
            if st[2*ind] == let:
                add -= 1
        global count
        count += add
for i in range(N-2):
    if i == 0:
        st = S
    else:
        st = st[1:]
    if st[0] == "R":
        for j in [x for x, y in enumerate(st) if y == 'G']:
            findlet("B",j)
        for j in [x for x, y in enumerate(st) if y == 'B']:
            findlet("G",j)
    elif st[0] == "G":
        for j in [x for x, y in enumerate(st) if y == 'B']:
            findlet("R",j)
        for j in [x for x, y in enumerate(st) if y == 'R']:
            findlet("B",j)
    else:
        for j in [x for x, y in enumerate(st) if y == 'R']:
            findlet("G",j)
        for j in [x for x, y in enumerate(st) if y == 'G']:
            findlet("R",j)
print(count)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
S = input()
R,G,B = [],[],[]
ans = 0

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

for r in R:
  for g in G:
    for b in B:
      a,b,c = sorted([r,g,b])
      if b-a != c-b:
        ans += 1
print(ans)

Submission status: Time Limit Exceeded

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

r_idx = []
g_idx = []
b_idx = []

for i, s in enumerate(S):
  if s == "R":
    r_idx.append(i)
  elif s == "G":
    g_idx.append(i)
  elif s == "B":
    b_idx.append(i)
    
count = 0
for r in r_idx:
  for g in g_idx:
    for b in b_idx:
      if b==2*g-r or g==2*r-b or r==2*b-g:
        continue
      else:
        count += 1
        
print(count)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
S = input()
count = 0
def findlet(let,ind):
    add = st[ind:].count(let)
    if add > 0:
        if 2*ind < len(st):
            if st[2*ind] == let:
                add -= 1
        global count
        count += add
for i in range(N-2):
    if i == 0:
        st = S
    else:
        st = st[1:]
    if st[0] == "R":
        for j in [x for x, y in enumerate(st) if y == 'G']:
            findlet("B",j)
        for j in [x for x, y in enumerate(st) if y == 'B']:
            findlet("G",j)
    elif st[0] == "G":
        for j in [x for x, y in enumerate(st) if y == 'B']:
            findlet("R",j)
        for j in [x for x, y in enumerate(st) if y == 'R']:
            findlet("B",j)
    else:
        for j in [x for x, y in enumerate(st) if y == 'R']:
            findlet("G",j)
        for j in [x for x, y in enumerate(st) if y == 'G']:
            findlet("R",j)
print(count)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
s = input()
r, g, b = s.count('R'), s.count('G'), s.count('B')
cnt = r * g * b
for i in range(n):
    for j in range(i + 1, n):
        k = 2*j - i
        if j < k < n and len({s[i], s[j], s[k]}) == 3:
            cnt -= 1
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
S = input()
count = 0
def findlet(let,ind):
    add = st[ind:].count(let)
    if add > 0:
        if 2*ind < len(st):
            if st[2*ind] == let:
                add -= 1
        global count
        count += add
for i in range(N-2):
    st = S[i:]
    if st[0] == "R":
        for j in [x for x, y in enumerate(st) if y == 'G']:
            findlet("B",j)
        for j in [x for x, y in enumerate(st) if y == 'B']:
            findlet("G",j)
    elif st[0] == "G":
        for j in [x for x, y in enumerate(st) if y == 'B']:
            findlet("R",j)
        for j in [x for x, y in enumerate(st) if y == 'R']:
            findlet("B",j)
    else:
        for j in [x for x, y in enumerate(st) if y == 'R']:
            findlet("G",j)
        for j in [x for x, y in enumerate(st) if y == 'G']:
            findlet("R",j)
print(count)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
s = input()
rgb = s.count('R') * s.count('G') * s.count('B')
cnt = 0
for i in range(n):
    for j in range(i + 1, n):
        k = 2*j - i
        if j < k < n and len({s[i], s[j], s[k]}) == 3:
            cnt += 1
print(rgb - cnt)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
S = input()
count = 0
def findlet(let,ind,checker):
    add = S[ind:].count(let)
    if add > 0:
        if ind + checker < N:
            if S[ind+checker] == let:
                add -= 1
        global count
        count += add
for i in range(N-2):
    st = S[i:]
    if st[0] == "R":
        for j in [x for x, y in enumerate(st) if y == 'G']:
            findlet("B",i+j,j)
        for j in [x for x, y in enumerate(st) if y == 'B']:
            findlet("G",i+j,j)
    elif st[0] == "G":
        for j in [x for x, y in enumerate(st) if y == 'B']:
            findlet("R",i+j,j)
        for j in [x for x, y in enumerate(st) if y == 'R']:
            findlet("B",i+j,j)
    else:
        for j in [x for x, y in enumerate(st) if y == 'R']:
            findlet("G",i+j,j)
        for j in [x for x, y in enumerate(st) if y == 'G']:
            findlet("R",i+j,j)
print(count)

Submission status: Time Limit Exceeded

Solution code:
# RGBの数列からから'R,G,B'を取り出す必要がある．
# RGBの組み合わせのなかから(r*g*b)の中から，例えば，Rを固定して，Rからの距離の絶対値が一致するようなものは
# iを固定して， j-i=k-j= l として j,kの位置で，i以外の２文字になっているかを確認する．
# i
from collections import deque
N=int(input())
S=input()
R=deque()
G=deque()
B=deque()
for i,s in enumerate(S):
    if s=='R':
        R.append(i)
    if s == 'G':
        G.append(i)
    if s == 'B':
        B.append(i)

rgb = len(R)*len(G)*len(B)
import bisect

for i in range(0,N):
    if i in R:
        lest1 = G
        lest2 = B
    elif i in G:
        lest1 = B
        lest2 = R
    else:
        lest1 = R
        lest2 = G
    max_j_width = int((N-1-i)/2)+1
    for j in range(1,max_j_width+1):
        if i+j in lest1 and i+2*j in lest2:
            rgb-=1
        elif i+2*j in lest1 and i+j in lest2:
            rgb-=1
print(rgb)

Submission status: Time Limit Exceeded

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

r = [i for i in range(n) if s[i] == 'R']
g = [i for i in range(n) if s[i] == 'G']
b = [i for i in range(n) if s[i] == 'B']
rgb = [sorted([ri, gi, bi]) for ri in r for gi in g for bi in b]

count = 0
for [i, j, k] in rgb:
    if j - i != k - j:
        count += 1
        
print(count)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
s = input()
cnt = s.count('R') * s.count('G') * s.count('B')
for i in range(n):
    for j in range(i + 1, n):
        k = 2*j - i
        if j < k < n and len({s[i], s[j], s[k]}) == 3:
            cnt -= 1
print(cnt)

Submission status: Time Limit Exceeded

Solution code:

# -*- coding: utf-8 -*-

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

count=0

rs, gs, bs=[], [], []
for i,s in enumerate(S):
    if s =='R':
        rs.append(i+1)
    elif s=='G':
        gs.append(i+1)
    else: bs.append(i+1)

n=len(bs)

for i in rs:
    for j in gs:
        co=0
        i1=min([i,j])
        i2=max([i,j])
        o1=2*i-j
        o2=2*j-i
        o3=0.5*(i+j)
        if  o1 in bs: co+=1
        if  o2 in bs: co+=1
        if  o3 in bs: co+=1
        count+=n-co

            
print(count)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
S = input()
count = 0
def findb(ind,checker):
    global count
    b = S[ind:].count("B")
    if b > 0:
        if ind + checker < N:
            if S[ind+checker] == "B":
                b -= 1
        count += b
def findg(ind,checker):
    global count
    g = S[ind:].count("G")
    if g > 0:
        if ind + checker < N:
            if S[ind+checker] == "G":
                g -= 1
        count += g
def findr(ind,checker):
    global count
    r = S[ind:].count("R")
    if r > 0:
        if ind + checker < N:
            if S[ind+checker] == "R":
                r -= 1
        count += r
for i in range(N-2):
    st = S[i:]
    if st[0] == "R":
        for j in [x for x, y in enumerate(st) if y == 'G']:
            findb(i+j,j)
        for j in [x for x, y in enumerate(st) if y == 'B']:
            findg(i+j,j)
    elif st[0] == "G":
        for j in [x for x, y in enumerate(st) if y == 'B']:
            findr(i+j,j)
        for j in [x for x, y in enumerate(st) if y == 'R']:
            findb(i+j,j)
    else:
        for j in [x for x, y in enumerate(st) if y == 'R']:
            findg(i+j,j)
        for j in [x for x, y in enumerate(st) if y == 'G']:
            findr(i+j,j)
print(count)

Submission status: Time Limit Exceeded

Solution code:
# 初期入力
N= int(input())
S =input()

from collections import Counter
c = Counter(S)
count_all =c["R"] * c["G"] * c["B"]
count =0
#for i in range(N):
for i in range((N+1)//2):
    for j in range(1,i+1):
        if  0<=i-j and i+j <N: 
            if (S[i-j]=="R" and S[i] =="G" and S[i+j] =="B"):
                #print(i-j,i,i+j)
                count +=1
            elif S[i-j]=="R" and S[i] =="B" and S[i+j] =="G":
                #print(i-j,i,i+j)
                count +=1
            elif S[i-j]=="G" and S[i] =="R" and S[i+j] =="B":
                #print(i-j,i,i+j)
                count +=1
            elif S[i-j]=="G" and S[i] =="B" and S[i+j] =="R":
                #print(i-j,i,i+j)
                count +=1
            elif S[i-j]=="B" and S[i] =="G" and S[i+j] =="R":
                #print(i-j,i,i+j)
                count +=1
            elif S[i-j]=="B" and S[i] =="R" and S[i+j] =="G":
                count +=1
                #print(i-j,i,i+j)
N2=(N+1)//2           
for i in range(N2,N):
    for j in range(N-i,0,-1):
        if  0<=i-j and i+j <N: 
            if ((S[i-j]=="R" and S[i] =="G" and S[i+j] =="B")
                or( S[i-j]=="R" and S[i] =="B" and S[i+j] =="G")
                or( S[i-j]=="G" and S[i] =="R" and S[i+j] =="B")
                or( S[i-j]=="G" and S[i] =="B" and S[i+j] =="R")
                or( S[i-j]=="B" and S[i] =="G" and S[i+j] =="R")
                or( S[i-j]=="B" and S[i] =="R" and S[i+j] =="G")
            ):
                count +=1
                #print(i-j,i,i+j)

print(count_all - count)

Submission status: Time Limit Exceeded

Solution code:

# -*- coding: utf-8 -*-

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

count=0

rs, gs, bs=[], [], []
for i,s in enumerate(S):
    if s =='R':
        rs.append(i+1)
    elif s=='G':
        gs.append(i+1)
    else: bs.append(i+1)

for i in rs:
    for j in gs:
        for k in bs:
            lis=[i,j,k]
            i1=min([i,j,k])
            lis.remove(i1)
            i3=max(lis)
            lis.remove(i3)
            i2=lis[0]
            if i2-i1!=i3-i2:
                count+=1
print(count)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

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

S = S.replace("R", "1")
S = S.replace("G", "2")
S = S.replace("B", "3")
count = 0

if N < 3:
  print(count)
else:
  for i in range(2, N):
    #選択した部分より手前と後ろに分ける
    a, b = list(S[:i-1]), list(S[i:])
    #手前反転
    a.reverse()
    A = np.array([int(j) for j in a])
    C = np.reshape(A, (len(a), 1))
    B = np.array([int(k) for k in b])
    D = np.reshape(B, (1, len(b)))
    E = np.dot(C, D) * int(S[i-1])
    F = np.diag(E)
    count += np.count_nonzero(E == 6) - np.count_nonzero(F == 6)
  print(count)

Submission status: Time Limit Exceeded

Solution code:
from collections import deque 
N = int(input())
S = input()
s = deque(list(S))
count = 0
def findb(ind,checker):
    global count
    b = S[ind:].count("B")
    if b > 0:
        if ind + checker < N:
            if S[ind+checker] == "B":
                b -= 1
        count += b
def findg(ind,checker):
    global count
    g = S[ind:].count("G")
    if g > 0:
        if ind + checker < N:
            if S[ind+checker] == "G":
                g -= 1
        count += g
def findr(ind,checker):
    global count
    r = S[ind:].count("R")
    if r > 0:
        if ind + checker < N:
            if S[ind+checker] == "R":
                r -= 1
        count += r
for i in range(N-2):
    temp = s.popleft()
    st = S[i:]
    if temp == "R":
        for j in [x for x, y in enumerate(st) if y == 'G']:
            findb(i+j,j)
        for j in [x for x, y in enumerate(st) if y == 'B']:
            findg(i+j,j)
    elif temp == "G":
        for j in [x for x, y in enumerate(st) if y == 'B']:
            findr(i+j,j)
        for j in [x for x, y in enumerate(st) if y == 'R']:
            findb(i+j,j)
    else:
        for j in [x for x, y in enumerate(st) if y == 'R']:
            findg(i+j,j)
        for j in [x for x, y in enumerate(st) if y == 'G']:
            findr(i+j,j)
print(count)

Submission status: Time Limit Exceeded

Solution code:

# -*- coding: utf-8 -*-

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

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

Submission status: Time Limit Exceeded

Solution code:
from collections import deque 
N = int(input())
S = input()
s = deque(list(S))
count = 0
def findb(ind,checker):
    global count
    b = S[ind:].count("B")
    if b > 0:
        if ind + checker < N:
            if S[ind+checker] == "B":
                b -= 1
        count += b
def findg(ind,checker):
    global count
    g = S[ind:].count("G")
    if g > 0:
        if ind + checker < N:
            if S[ind+checker] == "G":
                g -= 1
        count += g
def findr(ind,checker):
    global count
    r = S[ind:].count("R")
    if r > 0:
        if ind + checker < N:
            if S[ind+checker] == "R":
                r -= 1
        count += r
for i in range(N-2):
    temp = s.popleft()
    st = S[i:]
    if temp == "R":
        
        for j in [x for x, y in enumerate(st) if y == 'G']:
            findb(i+j,j)
        for j in [x for x, y in enumerate(st) if y == 'B']:
            findg(i+j,j)
    elif temp == "G":
        for j in [x for x, y in enumerate(st) if y == 'B']:
            findr(i+j,j)
        for j in [x for x, y in enumerate(st) if y == 'R']:
            findb(i+j,j)
    else:
        for j in [x for x, y in enumerate(st) if y == 'R']:
            findg(i+j,j)
        for j in [x for x, y in enumerate(st) if y == 'G']:
            findr(i+j,j)
print(count)

Submission status: Time Limit Exceeded

Solution code:
# 初期入力
N= int(input())
S =input()

from collections import Counter
c = Counter(S)
count_all =c["R"] * c["G"] * c["B"]
count =0
#for i in range(N):
for i in range((N+1)//2):
    for j in range(1,i+1):
        if  0<=i-j and i+j <N: 
            if S[i-j]=="R" and S[i] =="G" and S[i+j] =="B":
                #print(i-j,i,i+j)
                count +=1
            elif S[i-j]=="R" and S[i] =="B" and S[i+j] =="G":
                #print(i-j,i,i+j)
                count +=1
            elif S[i-j]=="G" and S[i] =="R" and S[i+j] =="B":
                #print(i-j,i,i+j)
                count +=1
            elif S[i-j]=="G" and S[i] =="B" and S[i+j] =="R":
                #print(i-j,i,i+j)
                count +=1
            elif S[i-j]=="B" and S[i] =="G" and S[i+j] =="R":
                #print(i-j,i,i+j)
                count +=1
            elif S[i-j]=="B" and S[i] =="R" and S[i+j] =="G":
                count +=1
                #print(i-j,i,i+j)
N2=(N+1)//2           
for i in range(N2,N):
    for j in range(N-i,0,-1):
        if  0<=i-j and i+j <N: 
            if S[i-j]=="R" and S[i] =="G" and S[i+j] =="B":
                #print(i-j,i,i+j)
                count +=1
            elif S[i-j]=="R" and S[i] =="B" and S[i+j] =="G":
                #print(i-j,i,i+j)
                count +=1
            elif S[i-j]=="G" and S[i] =="R" and S[i+j] =="B":
                #print(i-j,i,i+j)
                count +=1
            elif S[i-j]=="G" and S[i] =="B" and S[i+j] =="R":
                #print(i-j,i,i+j)
                count +=1
            elif S[i-j]=="B" and S[i] =="G" and S[i+j] =="R":
                #print(i-j,i,i+j)
                count +=1
            elif S[i-j]=="B" and S[i] =="R" and S[i+j] =="G":
                count +=1
                #print(i-j,i,i+j)

print(count_all - count)

Submission status: Time Limit Exceeded

Solution code:
# RGBの数列からから'R,G,B'を取り出す必要がある．
# RGBの組み合わせのなかから(r*g*b)の中から，例えば，Rを固定して，Rからの距離の絶対値が一致するようなものは
# iを固定して， j-i=k-j= l として j,kの位置で，i以外の２文字になっているかを確認する．
# i
from collections import deque
N=int(input())
S=input()
R=deque()
G=deque()
B=deque()
for i,s in enumerate(S):
    if s=='R':
        R.append(i)
    if s == 'G':
        G.append(i)
    if s == 'B':
        B.append(i)

rgb = len(R)*len(G)*len(B)
for i in range(0,N):
    if i in R:
        lest1 = G
        lest2 = B
    elif i in G:
        lest1 = B
        lest2 = R
    else:
        lest1 = R
        lest2 = G
    max_j_width = int((N-1-i)/2)+1
    for j in range(1,max_j_width+1):
        if i+j in lest1 and i+2*j in lest2:
            rgb-=1
        if i+2*j in lest1 and i+j in lest2:
            rgb-=1
print(rgb)

Submission status: Time Limit Exceeded

Solution code:
from collections import deque 
N = int(input())
S = input()
s = deque(list(S))
count = 0
def findb(ind,checker):
    global count
    st = S[ind:]
    if "B" in set(st):
        add = st.count("B")
        if add > 0:
            if ind + checker < N:
                if st[checker] == "B":
                    add -= 1
            count += add
def findg(ind,checker):
    global count
    st = S[ind:]
    if "G" in set(st):
        add = st.count("G")
        if add > 0:
            if ind + checker < N:
                if st[checker] == "G":
                    add -= 1
            count += add
def findr(ind,checker):
    global count
    st = S[ind:]
    if "R" in set(st):
        add = st.count("R")
        if add > 0:
            if ind + checker < N:
                if st[checker] == "R":
                    add -= 1
            count += add
for i in range(N-2):
    temp = s.popleft()
    if temp == "R":
        for j in [x for x, y in enumerate(S[i:]) if y == 'G']:
            findb(i+j,j)
        for j in [x for x, y in enumerate(S[i:]) if y == 'B']:
            findg(i+j,j)
    elif temp == "G":
        for j in [x for x, y in enumerate(S[i:]) if y == 'B']:
            findr(i+j,j)
        for j in [x for x, y in enumerate(S[i:]) if y == 'R']:
            findb(i+j,j)
    else:
        for j in [x for x, y in enumerate(S[i:]) if y == 'R']:
            findg(i+j,j)
        for j in [x for x, y in enumerate(S[i:]) if y == 'G']:
            findr(i+j,j)
print(count)

Submission status: Time Limit Exceeded

Solution code:
from collections import deque 
N = int(input())
S = input()
s = deque(list(S))
count = 0
def findb(ind,checker):
    global count
    b = S[ind:].count("B")
    if b > 0:
        if ind + checker < N:
            if S[ind+checker] == "B":
                b -= 1
        count += b
def findg(ind,checker):
    global count
    g = S[ind:].count("G")
    if g > 0:
        if ind + checker < N:
            if S[ind+checker] == "G":
                g -= 1
        count += g
def findr(ind,checker):
    global count
    r = S[ind:].count("R")
    if r > 0:
        if ind + checker < N:
            if S[ind+checker] == "R":
                r -= 1
        count += r
for i in range(N-2):
    temp = s.popleft()
    if temp == "R":
        for j in [x for x, y in enumerate(S[i:]) if y == 'G']:
            findb(i+j,j)
        for j in [x for x, y in enumerate(S[i:]) if y == 'B']:
            findg(i+j,j)
    elif temp == "G":
        for j in [x for x, y in enumerate(S[i:]) if y == 'B']:
            findr(i+j,j)
        for j in [x for x, y in enumerate(S[i:]) if y == 'R']:
            findb(i+j,j)
    else:
        for j in [x for x, y in enumerate(S[i:]) if y == 'R']:
            findg(i+j,j)
        for j in [x for x, y in enumerate(S[i:]) if y == 'G']:
            findr(i+j,j)
print(count)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
arr = list(input())
a = 0
b = 0
c = 0
count = 0
for i in range(N - 2):
  for j in range(i + 1, N - 1):
    if arr[i] != arr[j]:
      for k in range(j + 1, N):
        if j - i != k - j:
          a = k
          b = j 
          c = i
          if arr[a] != arr[b] and arr[c] != arr[b] and arr[a] != arr[c]:
            count += 1
print(count)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
arr = list(input())
a = 0
b = 0
c = 0
count = 0
for i in range(N - 2):
  for j in range(i + 1, N - 1):
    if arr[i] != arr[j]:
      for k in range(j + 1, N):
        if j - i != k - j:
          a = k
          b = j 
          c = i
          if arr[a] == arr[b] or arr[c] == arr[b] or arr[a] == arr[c]:
            continue
          else:
            count += 1
print(count)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
arr = list(input())
a = 0
b = 0
c = 0
count = 0
for i in range(N - 2):
  for j in range(i + 1, N - 1):
    for k in range(j + 1, N):
      if k - j != j - i:
        a = k
        b = j 
        c = i
        if arr[a] == arr[b] or arr[c] == arr[b] or arr[a] == arr[c]:
          continue
        else:
          count += 1
print(count)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
arr = list(input())
a = 0
b = 0
c = 0
count = 0
for i in range(N - 2):
  for j in range(i + 1, N - 1):
    for k in range(j + 1, N):
      if k - j != j - i:
        a = k
        b = j 
        c = i
        count += 1
        
        if arr[a] == arr[b] or arr[c] == arr[b] or arr[a] == arr[c]:
          count -= 1
print(count)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
S = input()
count = 0
def findb(ind,checker):
    global count
    if ind + checker < N:
        add = S[ind:ind+checker].count("B") + S[ind+checker+1:].count("B")
    else:
        add = S[ind:].count("B")
    count += add
def findg(ind,checker):
    global count
    if ind + checker < N:
        add = S[ind:ind+checker].count("G") + S[ind+checker+1:].count("G")
    else:
        add = S[ind:].count("G")
    count += add
def findr(ind,checker):
    global count
    if ind + checker < N:
        add = S[ind:ind+checker].count("R") + S[ind+checker+1:].count("R")
    else:
        add = S[ind:].count("R")
    count += add
for i in range(N):
    if S[i] == "R":
        for j in [x for x, y in enumerate(S[i:]) if y == 'G']:
            findb(i+j,j)
        for j in [x for x, y in enumerate(S[i:]) if y == 'B']:
            findg(i+j,j)
    elif S[i] == "G":
        for j in [x for x, y in enumerate(S[i:]) if y == 'B']:
            findr(i+j,j)
        for j in [x for x, y in enumerate(S[i:]) if y == 'R']:
            findb(i+j,j)
    else:
        for j in [x for x, y in enumerate(S[i:]) if y == 'R']:
            findg(i+j,j)
        for j in [x for x, y in enumerate(S[i:]) if y == 'G']:
            findr(i+j,j)
print(count)

Submission status: Time Limit Exceeded

Solution code:
ans = 0
N = int(input())
S = input()
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[i-1] != S[k-1] and S[j-1] != S[k-1] and j-i != k-j:
        ans += 1
print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
# 初期入力
N= int(input())
S =input()

from collections import Counter
c = Counter(S)
count_all =c["R"] * c["G"] * c["B"]
count =0
for i,v in enumerate(S):
    for j in range(1,i+1):
        if  0<=i-j and i+j <N: 
            if S[i-j]=="R" and S[i] =="G" and S[i+j] =="B":
                #print(i-j,i,i+j)
                count +=1
            elif S[i-j]=="R" and S[i] =="B" and S[i+j] =="G":
                #print(i-j,i,i+j)
                count +=1
            elif S[i-j]=="G" and S[i] =="R" and S[i+j] =="B":
                #print(i-j,i,i+j)
                count +=1
            elif S[i-j]=="G" and S[i] =="B" and S[i+j] =="R":
                #print(i-j,i,i+j)
                count +=1
            elif S[i-j]=="B" and S[i] =="G" and S[i+j] =="R":
                #print(i-j,i,i+j)
                count +=1
            elif S[i-j]=="B" and S[i] =="R" and S[i+j] =="G":
                count +=1
                #print(i-j,i,i+j)

print(count_all - count)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
arr = list(input())
R = []
G = []
B = []
result = 0
for i in range(len(arr)):
  if arr[i] == "R":
    R.append(i)
  elif arr[i] == "G":
    G.append(i)
  elif arr[i] == "B":
    B.append(i)

for i in R:
  for j in G:
    for k in B:
      if abs(j - i) == abs(k - j) or abs(j - i) == abs(i - k) or abs(k - i) == abs(k - j):
        result += 1
print(len(R) * len(G) * len(B) - result)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
S = input()
count = 0
def findb(ind,checker):
    global count
    b = S[ind:].count("B")
    if b > 0:
        if ind + checker < N:
            if S[ind+checker] == "B":
                b -= 1
        count += b
def findg(ind,checker):
    global count
    g = S[ind:].count("G")
    if g > 0:
        if ind + checker < N:
            if S[ind+checker] == "G":
                g -= 1
        count += g
def findr(ind,checker):
    global count
    r = S[ind:].count("R")
    if r > 0:
        if ind + checker < N:
            if S[ind+checker] == "R":
                r -= 1
        count += r
for i in range(N):
    if S[i] == "R":
        for j in [x for x, y in enumerate(S[i:]) if y == 'G']:
            findb(i+j,j)
        for j in [x for x, y in enumerate(S[i:]) if y == 'B']:
            findg(i+j,j)
    elif S[i] == "G":
        for j in [x for x, y in enumerate(S[i:]) if y == 'B']:
            findr(i+j,j)
        for j in [x for x, y in enumerate(S[i:]) if y == 'R']:
            findb(i+j,j)
    else:
        for j in [x for x, y in enumerate(S[i:]) if y == 'R']:
            findg(i+j,j)
        for j in [x for x, y in enumerate(S[i:]) if y == 'G']:
            findr(i+j,j)
print(count)

Submission status: Time Limit Exceeded

Solution code:
# 初期入力
N= int(input())
S =input()

from collections import Counter
c = Counter(S)
count_all =c["R"] * c["G"] * c["B"]
count =0
for i,v in enumerate(S):
    for j in range(1,(N+1)//2):
        if  i+j*2 <N: 
            if S[i]=="R" and S[i+j] =="G" and S[i+j*2] =="B":
                #print(i-j,i,i+j)
                count +=1
            elif S[i]=="R" and S[i+j] =="B" and S[i+j*2] =="G":
                #print(i-j,i,i+j)
                count +=1
            elif S[i]=="G" and S[i+j] =="R" and S[i+j*2] =="B":
                #print(i-j,i,i+j)
                count +=1
            elif S[i]=="G" and S[i+j] =="B" and S[i+j*2] =="R":
                #print(i-j,i,i+j)
                count +=1
            elif S[i]=="B" and S[i+j] =="G" and S[i+j*2] =="R":
                #print(i-j,i,i+j)
                count +=1
            elif S[i]=="B" and S[i+j] =="R" and S[i+j*2] =="G":
                count +=1
                #print(i-j,i,i+j)

print(count_all - count)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
S = input()
a = 0
b = S.count("R")*S.count("B")*S.count("G")
for i in range(1,len(S)+1):
    for j in range(i,len(S)+1):

        k = 2*j-i
        if not k < len(S)+1:
            continue
        else:
            if not S[i-1] == S[k-1] and not S[k-1] == S[j-1] and not S[i-1] ==S[j-1]:
                b = b-1

print(b)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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)
ans = len(r)*len(g)*len(b)
def func(a,b,c):
    ans = 0
    for i in a:
        for k in [num1 for num1 in c if num1 > i+1]:
            if (k + i) / 2 in b:
                    ans -= 1
    return ans
print(ans + func(r,g,b) + func(r,b,g) + func(g,r,b) + func(g,b,r) + func(b,g,r) + func(b,r,g))