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 = list(str(input()))
z = 0
lnr = [i for i, x in enumerate(s) if x == 'R']
lng = [i for i, x in enumerate(s) if x == 'G']
lnb = [i for i, x in enumerate(s) if x == 'B']     
for i in lnr:
    for j in lng:
        ln = sorted([i, j])
        if ln[0] + ln[0] - ln[1] in lnb:
            z += 1
        if (ln[0] - ln[1]) % 2 == 0 and ln[1] + ((ln[0] - ln[1])//2) in lnb:
            z += 1
        if ln[1] - (ln[0] - ln[1]) in lnb:
            z += 1
print(len(lnr) * len(lng) * len(lnb) - z)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
s = input()
ans = 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):
                rgb = s[i] + s[j]+ s[k]
                if "R" in rgb and "G" in rgb and "B" in rgb :
                    if abs(j-i) != abs(k-j) :
                        ans += 1

print(ans)

Submission status: Time Limit Exceeded

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

res = 0

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

print(res)

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
S = input()
ans = 0
for i in range(N):
    for j in range(i,N):
        x,y=S[i],S[j]
        if not x==y:
            for k in range(j,N):
                z=S[k]
                if not x==z:
                    if not y==z:
                        if not 2*j==i+k:
                            ans+=1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
S = input()
com=[]
count = 0
for i in range(N+1):
    for j in range(i+1, N):
        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]):
                    count += 1
print(count)

Submission status: Time Limit Exceeded

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

print(count)

Submission status: Time Limit Exceeded

Solution code:
def main():
    n = int(input())
    s = input()
    r = 0
    s = [ord(l) for l in s]
    for k in range(1, n):
        sk = s[k]
        for j in range(1, k):
            sj = s[j]
            kj = k - j
            if sj != sk:
                for i in range(j):
                    si = s[i]
                    if j - i != kj and si != sk and si != sj:
                        r += 1
    print(r)


main()

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
s = input()
pair = []
b_num = []
ans = 0
for i in range(n - 1):
    if s[i] == "B":
        b_num.append(i)
        continue
    for j in range(i + 1, n):
        if s[j] == "B" or s[j] == s[i]: continue
        pair.append((i, j))
if s[-1] == "B":
    b_num.append(n - 1)

for i, j in pair:
    cnt = 0
    if 2 * i - j in b_num:
        cnt += 1
    if (j - i) % 2 == 0 and (i + j) // 2 in b_num:
        cnt += 1
    if 2 * j - i in b_num:
        cnt += 1
    ans += len(b_num) - cnt
print(ans)

Submission status: Time Limit Exceeded

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

count = 0

for i in range(n-3):
    for j in range(i+1, n-1):
        if s[i] == s[j]:
            continue
        for k in range(j+1, n):
            if s[i] == s[k] or s[j] == s[k]:
                continue
            else:
                if j - i == k - j:
                    continue
                else:
                    count += 1

print(count)

Submission status: Time Limit Exceeded

Solution code:
def main():
    N = int(input())
    S = list(input())

    su = 0
    for i, si in enumerate(S):
        for j, sj in enumerate(S[i+1:]):
            if si == sj:
                continue
            for k, sk in enumerate(S[i+j+2:]):
                # print(si, sj, sk)
                # print(i+1, j+i+2, k+j+i+2)
                if j == k:
                    pass
                elif sj != sk and si != sk:
                    su += 1
                    # print('gets')
    print(su)


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
s=list(input())
count=0
for k in range(1,n+1):
    for j in range(1,n):
        if k<=j:
            break
        elif s[k-1]==s[j-1]:
            continue
        for i in range(1,n-1):
            if j<=i:
                break
            elif s[k-1]==s[i-1] or s[j-1]==s[i-1] or j-i==k-j:
                continue
            count+=1
print(count)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
ans=0
n=int(input())
k=str(input())
r=k.count("R")
b=k.count("B")
g=k.count("G")
ans+=r*b*g
    
for i in range(n-2):
  ii=k[i]
  for j in range(i+1,n-1):
    jj=k[j]
    l=j+(j-i)
    #print(l)
    if jj!=ii and l<n:
      #print(i,j)
      ll=k[l]
      if ii!=ll and jj!=ll:
        ans-=1
          #print(i,j,l)
print(ans)

Submission status: Time Limit Exceeded

Solution code:
from collections import deque
from heapq import heapify,heappop,heappush,heappushpop
from copy import copy,deepcopy
from itertools import permutations,combinations
from collections import Counter
from pprint import pprint

def myinput():
    return map(int,input().split())

def mycol(data,col):
    return [ row[col] for row in data ]

def mysort(data,col):
    data.sort(key=lambda x:x[col],reverse=False)
    return data

def mymax(data):
    M = -1*float("inf")
    for i in range(len(data)):
        m = max(data[i])
        M = max(M,m)
    return M

def mymin(data):
    m = float("inf")
    for i in range(len(data)):
        M = min(data[i])
        m = min(m,M)
    return m

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)
    elif s[i]=="B":
        b.append(i)
    else:
        pass
# print(r,g,b)
count = 0
for i in r:
    for j in g:
        # print(i,j)
        if i<j:
            x = i
            y = j
        else:
            x = j
            y = i
        k1 = y + (y - x)
        if k1 in b:    
            count += 1
        k2 = x - (y - x)
        if k2 in b:
            count += 1
        k3 = (x+y)/2
        if k3 in b:
            count += 1
# print(len(r) * len(g) * len(b))
# print(count)
ans = len(r) * len(g) * len(b) - count
print(ans)

Submission status: Time Limit Exceeded

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

r = [i for i, x in enumerate(s) if x == 'R']
g = [i for i, x in enumerate(s) if x == 'G']
b = [i for i, x in enumerate(s) if x == 'B']
ans = 0

for x in r:
    n = [i for i in g if i>x]
    for y in n:
        m = [i for i in b if i>y]
        for z in m:
            if y-x != z-y:
                ans += 1
    n = [i for i in b if i>x]
    for y in n:
        m = [i for i in g if i>y]
        for z in m:
            if y-x != z-y:
                ans += 1

for x in b:
    n = [i for i in r if i>x]
    for y in n:
        m = [i for i in g if i>y]
        for z in m:
            if y-x != z-y:
                ans += 1
    n = [i for i in g if i>x]
    for y in n:
        m = [i for i in r if i>y]
        for z in m:
            if y-x != z-y:
                ans += 1           
                
for x in g:
    n = [i for i in r if i>x]
    for y in n:
        m = [i for i in b if i>y]
        for z in m:
            if y-x != z-y:
                ans += 1              
    n = [i for i in b if i>x]
    for y in n:
        m = [i for i in r if i>y]
        for z in m:
            if y-x != z-y:
                ans += 1

print(ans)

Submission status: Time Limit Exceeded

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

r = 0
r_l = []
g = 0
g_l = []
b = 0
b_l = []

for i in range(n):
    if s[i] == "R":
        r += 1
        r_l.append(i+1)
    if s[i] == "G":
        g += 1
        g_l.append(i+1)
    if s[i] == "B":
        b += 1
        b_l.append(i+1)
        
ans = r*g*b

for i in r_l:
    for j in g_l:
        for k in b_l:
            one = max(i,max(k,j))
            three = min(i,min(k,j))
            if i != one and i != three:
                two = i
            if j != one and j != three:
                two = j
            if k != one and k != three:
                two = k 
            if two - one == three - two:
                ans -= 1

print(ans)

Submission status: Time Limit Exceeded

Solution code:
n= int(input())
s = input()
ans = 0
li_r = []
li_g = []
li_b = []
for i in range(n):
  if s[i] == "R":
    li_r.append(i+1)
  elif s[i] == "G":
    li_g.append(i+1)
  elif s[i] == "B":
    li_b.append(i+1)
for i in li_r:
  for j in li_g:
    if (j+i)%2 == 0:
      if 2*j -i in li_b and 2*i - j in li_b and (j+i)//2 in li_b:
        ans += len(li_b)-3
      elif 2*j -i not in li_b and 2*i - j in li_b and (j+i)//2 in li_b:
        ans += len(li_b) -2
      elif 2*j -i in li_b and 2*i - j not in li_b and (j+i)//2 in li_b:
        ans += len(li_b) -2
      elif 2*j -i in li_b and 2*i - j in li_b and (j+i)//2 not in li_b:
        ans += len(li_b) -2
      elif 2*j -i not in li_b and 2*i - j not in li_b and (j+i)//2 in li_b:
        ans += len(li_b) -1
      elif 2*j -i in li_b and 2*i - j not in li_b and (j+i)//2 not in li_b:
        ans += len(li_b) -1
      elif 2*j -i not in li_b and 2*i - j in li_b and (j+i)//2 not in li_b:
        ans += len(li_b) -1
      elif 2*j -i not in li_b and 2*i - j not in li_b and (j+i)//2 not in li_b:
        ans += len(li_b)
    else:
      if 2*j -i in li_b and 2*i - j in li_b:
        ans += len(li_b)-2
      elif 2*j -i not in li_b and 2*i - j in li_b:
        ans += len(li_b) -1
      elif 2*j -i in li_b and 2*i - j not in li_b:
        ans += len(li_b) -1
      elif 2*j -i not in li_b and 2*i - j not in li_b:
        ans += len(li_b)
print(ans)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())

S = input()

ans = 0

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

Submission status: Time Limit Exceeded

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

import bisect

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)
        
r, g, b = len(R), len(G), len(B)

ans = N * (N - 1) * (N - 2) // 6
for i in range(N):
  for j in range(i+1, N):
    if S[j] == S[i]:
      ans -= N - 2
    else:
      if 2 * j - i < N:
        if len(set([S[2*j-i], S[i], S[j]])) == 3:
          ans -= 1
ans += r * (r - 1) * (r - 2) // 3
ans += g * (g - 1) * (g - 2) // 3
ans += b * (b - 1) * (b - 2) // 3



print(ans)

Submission status: Time Limit Exceeded

Solution code:
a=int(input())

b=input()
c=a-1
d=0

for i in range(c):
  for j1 in range(c-i):
    j=j1+i+1

    if b[i]!=b[j]:
      for k1 in range(c-j):
        k=k1+j+1
        #print(i,j,k)

        if b[k]!=b[i] and b[k]!=b[j]:
          if j-i != k-j:
            d=d+1
print(d)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
s=input()
# 1<=i<j<k<=n
# j-i!=k-j
# si!=sj, sj!=sk, si!=sk
ans=0
cl=['R','G','B']
for i in range(n-2):
    c1=s[i]
    if c1=='R':
        c2='G'
        c3='B'
    if c1=='G':
        c2='R'
        c3='B'
    if c1=='B':
        c2='G'
        c3='R'
    # c2
    p=sum([x==c3 for x in s[i+1:]])
    pj=i+1
    for j in range(i+1,n-1):
        if s[j]!=c2:
            continue
        p-=sum([x==c3 for x in s[pj:j]])
        pj=j
        ans+=p
        if 2*j-i < n and s[2*j-i] != s[i] and s[2*j-i] != s[j]:
            ans-=1

    # c3
    p=sum([x==c2 for x in s[i+1:]])
    pj=i+1
    for j in range(i+1,n-1):
        if s[j]!=c3:
            continue
        p-=sum([x==c2 for x in s[pj:j]])
        pj=j
        ans+=p
        if 2*j-i < n and s[2*j-i] != s[i] and s[2*j-i] != s[j]:
            ans-=1

print(ans)

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-

import queue

def main():
     n = int(input())
     s = input()

     r_list = []
     g_list = []
     b_list = []

     ans = 0

     for i in range(n):
          if s[i] == 'R':
               r_list.append(i)
          elif s[i] == 'G':
               g_list.append(i)
          else:
               b_list.append(i)

     for i in range(n):
          if s[i] == 'R':
               spot = r_list.pop(0)
               ans += check(spot, g_list, b_list)

          if s[i] == 'G':
               spot = g_list.pop(0)
               ans += check(spot, r_list, b_list)

          if s[i] == 'B':
               spot = b_list.pop(0)
               ans += check(spot, r_list, g_list)

     print(ans)

def check(spot, first, second):
     ret = 0
     for f in first:
          ignore = f + (f - spot)
          limit_second = [s for s in second if s > f]

          ret += len(limit_second)
          if ignore in limit_second:
               ret += -1

     for s in second:
          ignore = s + (s - spot)
          limit_first = [f for f in first if f > s]

          ret += len(limit_first)
          if ignore in limit_first:
               ret += -1
     
     return ret

if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

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

r = [i for i, x in enumerate(s) if x == 'R']
g = [i for i, x in enumerate(s) if x == 'G']
b = [i for i, x in enumerate(s) if x == 'B']
sum = 0

for i in r:
  for j in g:
    for k in b:
      d, e, f = sorted([i, j, k])
      if e-d != f-e:
        sum += 1
print(sum)

Submission status: Time Limit Exceeded

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

ans = 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[j] and S[i] != S[k] and S[j] != S[k]) and j - i != k - j:
                    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+1)
    elif S[i] == 'G':
        g.append(i+1)
    else:
        b.append(i+1)
x = 0
for i in r:
    for j in g:
        for k in b:
            l = sorted([i,j,k])
            if l[1] - l[0] != l[2] - l[1]:
                x += 1
print(x)

Submission status: Time Limit Exceeded

Solution code:

def main():
    N = int(input())
    S = input()
    count = 0
    RGB = ["R", "G", "B"]

    for i in range(1, N-1):
        for j in range(i+1, N):
            if S[i-1] == S[j-1]:
                continue
            RGB = ["R", "G", "B"]
            RGB.remove(S[i-1])
            RGB.remove(S[j-1])
            count += S.count(RGB[0], j, N)
            #print(S.count(RGB[0], j, N))
            if 2 * j - i > N:
                pass
            else:
                if S[2 * j - i - 1] == RGB[0]:
                    count -= 1

    print(count)

if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
def main():
    N = int(input())
    S = input()
    res = 0

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


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
import itertools


def main():
    input()
    t = input()
    dic = {'R': [], 'G': [], 'B': []}
    for i in range(len(t)):
        dic[t[i]].append(i)
    count = 0
    p = itertools.product(dic['R'], dic['G'], dic['B'])
    for i in p:
        tmp = sorted(list(i))
        if tmp[1] - tmp[0] != tmp[2] - tmp[1]:
            count += 1

    print(count)

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

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

count=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 S[i]!=S[k] and S[k]!=S[j] and j-i!=k-j:
                    count+=1
print(count)

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

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

ans = 0

r = []
if s[0] == "R":
    r.append(1)
else:
    r.append(0)

for i in range(1, len(s)):
    if s[i] == "R":
        r.append(r[-1] + 1)
    else:
        r.append(r[-1])

g = []
if s[0] == "G":
    g.append(1)
else:
    g.append(0)

for i in range(1, len(s)):
    if s[i] == "G":
        g.append(g[-1] + 1)
    else:
        g.append(g[-1])

b = []
if s[0] == "B":
    b.append(1)
else:
    b.append(0)

for i in range(1, len(s)):
    if s[i] == "B":
        b.append(b[-1] + 1)
    else:
        b.append(b[-1])

for i in range(n - 2):
    for j in range(i + 1, n):
        if s[i] != s[j]:
            tmp = [s[i]] + [s[j]]
            target_idx = j + (j - i)

            if "R" not in tmp:
                ans += r[-1] - r[j]
                if target_idx >= len(s):
                    continue
                if s[target_idx] == "R":
                    ans -= 1
            elif "G" not in tmp:
                ans += g[-1] - g[j]
                if target_idx >= len(s):
                    continue
                if s[target_idx] == "G":
                    ans -= 1
            else:
                ans += b[-1] - b[j]
                if target_idx >= len(s):
                    continue
                if s[target_idx] == "B":
                    ans -= 1

print(ans)

Submission status: Time Limit Exceeded

Solution code:
import sys
from itertools import combinations
int1 = lambda x: int(x) - 1
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(500000)

N = int(readline())
S = readline().decode().rstrip()

l = [i for i in range(N)]

cnt = 0
for i, j, k in combinations(l, 3):
    if j - i == k - j:
        continue
    if (S[i] != S[j]) & (S[i] != S[k]) & (S[j] != S[k]):
        cnt += 1

print(cnt)

Submission status: Time Limit Exceeded

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

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

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

print(ans)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
s = input()
r = []
g = []
b = []
for i in range(len(s)):
    if s[i]=="R":
        r.append(i)
    elif s[i]=="G":
        g.append(i)
    else:
        b.append(i)

# print(r)
# print(g)
# print(b)

ans = 0
for R in r:
    for G in g:
        for B in b:
            lst = [R,G,B]
            lst.sort()
            if lst[1]-lst[0]!=lst[2]-lst[1]:
                ans += 1
print(ans)

Submission status: Time Limit Exceeded

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

rgb = set()
ans = 0

for i in range(N):
  rgb.add(S[i])
  for j in range(i+1, N):
    #print(i, j, ans)
    if S[j] in rgb:
      continue
    rgb.add(S[j])
    d1 = j - i
    rest = set(['R', 'G', 'B']) - rgb
    c = list(rest)[0]    
    tmp = S[j+1:j+d1].count(c)
    tmp += S[j+d1+1:N].count(c)
    ans += tmp    
    rgb.remove(S[j])
  rgb.remove(S[i])
      
print(ans)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
s = input()
ans = 0
i = 0
for a in s:
    for j in range(i+1,n):
        #a = s[i]
        b = s[j]
        if a != b:
            for k in range(j+1,n):
                c = s[k]
                if (a != c and b != c):
                    if (j-i != k-j):
                        ans +=1
    i += 1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
S = input()
ans = 0
num = -2
for i in range(0, N-3):
    for j in range(i, N-1):
        I = S[i]
        J = S[j]
        if I != J:
            color = ['R', 'G', 'B']
            color.remove(I)
            color.remove(J)
            r = color[0]
            if j > num:
                num = S[j+1:].find(r)
                su = S[j+1:].count(r)
                ans += su
            else:
                ans += su
            try:
                if S[j+(j-i)] == r:
                    ans -= 1
            except IndexError:
                pass
print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
S = input()
count=0

for i in range(1,N-1):
    for j in range(i+1,N):
        for k in range(j+1,N+1):
            if j-i == k-j:
                continue
            else:
                tmp = set([S[i-1],S[j-1],S[k-1]])
                if len(tmp)==3:
                    count += 1
print(count)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
S = list(input())
R =[]
G = []
B = []
lr = 0
lg = 0
lb = 0
for i in range(N):
    if S[i] == "R":
        R.append(i)
        lr+=1
    elif S[i] == "G":
        G.append(i)
        lg+=1
    else:
        B.append(i)
        lb+=1
ncount = 0
for r in R:
    for g in G:
        for b in B:
            s_li = sorted([r,g,b])
            if s_li[2]-s_li[1] == s_li[1]-s_li[0]:
                ncount+=1
print(lr*lg*lb - ncount)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
 
str = input()
sum = 0
two = []
three = []
for i in range(n-3):
  for j in range(i+1, n-1):
    for k in range(j+1, n):
      if str[i] == str[j]:
        break
      elif str[i] != str[k] and str[j] != str[k] and j - i != k - j:
        sum += 1
print(sum)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
s = str(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)
cnt = 0
for i in r:
    for j in g:
        if (i+j)%2==0 and (i + j) // 2 in b:
            cnt += 1
        if (2 * j) - i in b:
            cnt += 1
        if (2 * i) - j in b:
            cnt += 1
print((len(r) * len(g) * len(b))-cnt)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
S = input()
i,j,k = 1,2,3
res = 0

while True:
  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:
  	res += 1
  if not k == len(S):
    k += 1
  elif not j == len(S)-1:
    j += 1
    k = j+1
  elif not i == len(S)-2:
    i += 1
    j = i+1
    k = j+1
  else:
    break

print(res)

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)
	if s[i] == "G":
		g.append(i)
	if s[i] == "B":
		b.append(i)
count = len(r)*len(g)*len(b)
for i in r:
	for j in g:
		u = abs(i-j)
		if (max(i,j)+u) in b:
			count -= 1
		if (min(i,j)-u) in b:
			count -= 1
		if u%2 == 0:
			if (i+j)//2 in b:
				count -= 1
print(count)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
S=list(input())
ans=0
for i in range(n-2):
  for j in range(i,n-1):
    if S[i]==S[j]:
      continue
    for k in range(j,n):
      if S[j]==S[k] or S[i]==S[k]:
        continue
      if j-i != k-j:
        ans+=1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
s=str(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=0
for l in r:
  for m in g:
    for k in b:
      if l!=m and m!=k and k!=m and abs(m-l)!=abs(k-m) and abs(k-l)!=abs(k-m) and abs(k-l)!=abs(l-m):
        ans+=1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import itertools

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

lis = list(itertools.combinations(range(0, N), 3))

cnt=0
for i, j, k in lis:
    if S[i] != S[j] and S[i] != S[k] and S[j] != S[k]:
        if j-i != k-j:
            cnt+=1

print(cnt)

Submission status: Time Limit Exceeded

Solution code:
data = [input() for i in range(2)]
N = int(data[0])
S = list(data[1])
answer = 0
for i in range(N-2):
  I = i+1
  for j in range(N-1):
    J = j+1
    if J <= I:
      continue
    if S[i] == S[j]:
        continue
    for k in range(N):
      K = k+1
      if K <= J:
        continue
      if J-I == K-J:
        continue
      if S[i] == S[k]:
        continue
      if S[j] == S[k]:
        continue
      answer += 1
print(answer)

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
S=input()
ans=0
for i in range(0,N):
    for j in range(i,N):
        for k in range(j,N):
            if S[i]==S[j] or S[i]==S[k] or S[k]==S[j]:
                pass
            else:
                if j-i == k-j:
                    pass
                else:
                    ans+=1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import sys

N = int(sys.stdin.readline().rstrip())
S = sys.stdin.readline().rstrip()

if len(set(S)) == 1 or N < 3:
    print(0)
    sys.exit()

ans = 0
for i in range(N - 2):
    a = S[i]
    for j in range(i + 1, N - 1):
        b = S[j]
        if a == b:
            continue
        jtoi = j - i
        for k in range(j + 1, N):
            c = S[k]
            if a == c or b == c:
                continue
            ktoj = k - j
            if jtoi != ktoj:
                ans += 1

print(ans)

Submission status: Time Limit Exceeded

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

r = 0
r_l = []
g = 0
g_l = []
b = 0
b_l = []

for i in range(n):
    if s[i] == "R":
        r += 1
        r_l.append(i+1)
    if s[i] == "G":
        g += 1
        g_l.append(i+1)
    if s[i] == "B":
        b += 1
        b_l.append(i+1)
        
ans = r*g*b

for i in r_l:
    for j in g_l:
        for k in b_l:
            one = max(i,max(k,j))
            three = min(i,min(k,j))
            if i != one and i != three:
                two = i
            if j != one and j != three:
                two = j
            if k != one and k != three:
                two = k 
            if two - one == three - two:
                ans -= 1

print(ans)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
s = input()
s = list(s)
ans = 0

for i in range(0, 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]:
                    if s[j] != s[k]:
                        ans += 1

print(ans)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
s = input()
count = 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):
        #print(s[i],s[j],s[k])
        if s[i] != s[j] and s[j] != s[k] and s[k] != s[i] and j-i != k-j:
          #print(i,j,k)
          count += 1
          #print(s[i],s[j],s[k])
print(count)

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

Solution code:
import itertools
N = int(input())
S= input()
d = {}
for i in range(N):
  d[i] = S[i]

l = list(itertools.combinations(d, 3))
ans = 0
for x in l:
  if d[x[0]] == d[x[1]] or d[x[0]] == d[x[2]] or d[x[1]] == d[x[2]]:
    continue

  if (x[1] - x[0] != x[2] - x[1]):
    ans += 1
    
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import bisect
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 = 0
for i in r:
	for j in g:
		for k in b:
			a = [i,j,k]
			a.sort()
			ans += 1
			if a[2]-a[1] == a[1]-a[0]:
				ans -= 1
print (ans)

Submission status: Time Limit Exceeded

Solution code:
import sys
import math
from functools import reduce

# 入力を整数に変換して受け取る
def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def MI1(): return map(int1, sys.stdin.readline().split())
# 入力全てを整数に変換したものの配列を受け取る
def LI(): return list(map(int, sys.stdin.readline().split()))
# 入力全てを整数に変換して1引いたものの配列を受け取る
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def SR(): return sys.stdin.readline().rstrip()

ascii_lowercase = 'abcdefghijklmnopqrstuvwxyz'
ascii_uppercase = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
ascii_uppercase2 = 'ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZ'

# リストを改行区切りで出力する
p2D = lambda x: print(*x, sep="\n")
p2E = lambda x: print(''.join(x))
p2S = lambda x: print(*x, sep=" ")

def gcd_list(numbers):
    return reduce(math.gcd, numbers)

N = II()
S = input()

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