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:
import bisect

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

RGB = [[], [], []]
for i in range(n):
    if s[i] == 'R':
        RGB[0].append(i)
    elif s[i] == 'G':
        RGB[1].append(i)
    else:
        RGB[2].append(i)
total = len(RGB[0]) * len(RGB[1]) * len(RGB[2])
len_B=len(RGB[2])
for r in RGB[0]:
    for g in RGB[1]:
        dif = abs(r - g)
        up = max(r,g)+dif
        down = min(r,g)-dif
        up_posi=bisect.bisect_left(RGB[2],up)

        if up_posi < len_B:
            if RGB[2][up_posi]==up:
                total-=1
        down_posi=bisect.bisect_left(RGB[2],down)
        if down_posi < len_B:
            if RGB[2][down_posi]==down:
                total-=1
        if dif % 2 == 0:
            center = (r+g)/2
            center_posi=bisect.bisect_left(RGB[2], center)
            if center_posi < len_B:
                if RGB[2][center_posi]==center:
                    total-=1
print(total)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
S = input()
kv = {'R':[],'G':[],'B':[]}
for i in range(N):
    kv[S[i]].append(i)
a = sorted([[len(kv['R']),'R'],[len(kv['G']),'G'],[len(kv['B']),'B']], key=lambda x:-x[0])
a1, a2, a3 = a[0][1],a[1][1],a[2][1]

ans = 0

for one in kv[a2]:
    for t in kv[a3]:
        tmp = len(kv[a1])
        if 2*t-one in kv[a1]:
            tmp-=1
        if 2*one-t in kv[a1]:
            tmp-=1
        if (t+one)/2 in kv[a1]:
            tmp-=1
        ans+=tmp
print(ans)

Submission status: Time Limit Exceeded

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

def judge(i,j,k):
  if S[i] != S[j] and S[i] != S[k] and S[j] != S[k]:
    if j-i != k-j:
      # print(i,j,k, "True")
      return True
  # print(i,j,k, "False")
  return False

for i in range(N):
  for j in range(i,N):
    for k in range(j,N):
      if judge(i,j,k):
        R+=1

print(R)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
from itertools import combinations
N=int(input())
S=list(input())
Pattern=[x for x in combinations(range(N),3) if len(set(S[y] for y in x))==3]
print(sum([1 for x in Pattern  if x[2]-x[1] != x[1]-x[0]]))

Submission status: Time Limit Exceeded

Solution code:
import itertools
n = int(input())
s = input()
r = []
g = []
b = []

for i in range(0, len(s)):
    if s[i] == "R":
        r.append(i+1)
    elif s[i] == "G":
        g.append(i+1)
    elif s[i] == "B":
        b.append(i+1)

cnt = 0
# for i in r:
#     for j in g:
#         for k in b:

# forループのネスト
for i, j, k in itertools.product(r, g, b):
    if max(i, j, k) == k:
        if i < j:
            if k-j != j-i:
                cnt += 1
        else:
            if k-i != i-j:
                cnt += 1
    elif max(i, j, k) == j:
        if i < k:
            if j-k != k-i:
                cnt += 1
        else:
            if j-i != i-k:
                cnt += 1
    elif max(i, j, k) == i:
        if k < j:
            if i-j != j-k:
                cnt += 1
        else:
            if i-k != k-j:
                cnt += 1


print(cnt)

Submission status: Time Limit Exceeded

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

    ans = 0

    for i in range(N):
        for ii in range(i + 1, N):
            for iii in range(ii + 1, N):
                if ((ii - i) == (iii - ii)):
                    continue
                if (S[i] != S[ii] and S[ii] != S[iii] and S[i] != S[iii]):
                    ans += 1

    print(ans)


resolve()

Submission status: Time Limit Exceeded

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

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

print(count)

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
S=input()
count=0
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)
for r in R:
  for g in G:
    for b in B:
      if r<g and g<b and b-g!=g-r:
        count+=1
      if r<b and b<g and g-b!=b-r:
        count+=1
      if g<r and r<b and b-r!=r-g:
        count+=1
      if g<b and b<r and r-b!=b-g:
        count+=1
      if b<r and r<g and g-r!=r-b:
        count+=1
      if b<g and g<r and r-g!=g-b:
        count+=1
print(count)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
s = input()
ans = 0
for i in range(len(s)):
    if s[i] == "R":
        for j in range(i, len(s)):
            if s[j] == "G":
                for k in range(j, len(s)):
                    if s[k] == "B":
                        if j - i != k - j:
                            ans += 1


for i in range(len(s)):
    if s[i] == "R":
        for j in range(i, len(s)):
            if s[j] == "B":
                for k in range(j, len(s)):
                    if s[k] == "G":
                        if j - i != k - j:
                            ans += 1

for i in range(len(s)):
    if s[i] == "G":
        for j in range(i, len(s)):
            if s[j] == "R":
                for k in range(j, len(s)):
                    if s[k] == "B":
                        if j - i != k - j:
                            ans += 1

for i in range(len(s)):
    if s[i] == "G":
        for j in range(i, len(s)):
            if s[j] == "B":
                for k in range(j, len(s)):
                    if s[k] == "R":
                        if j - i != k - j:
                            ans += 1

for i in range(len(s)):
    if s[i] == "B":
        for j in range(i, len(s)):
            if s[j] == "R":
                for k in range(j, len(s)):
                    if s[k] == "G":
                        if j - i != k - j:
                            ans += 1

for i in range(len(s)):
    if s[i] == "B":
        for j in range(i, len(s)):
            if s[j] == "G":
                for k in range(j, len(s)):
                    if s[k] == "R":
                        if j - i != k - j:
                            ans += 1

print(ans)

Submission status: Time Limit Exceeded

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

def rgb(now,sec):
    if now=='R' and sec=='G':
        return 'B'
    if now == 'R' and sec == 'B':
        return 'G'
    if now == 'G' and sec == 'R':
        return 'B'
    if now == 'G' and sec == 'B':
        return 'R'
    if now == 'B' and sec == 'G':
        return 'R'
    if now == 'B' and sec == 'R':
        return 'G'

ans=0
for i in range(N-2):
    now = S[i]
    for j in range(i+1,N-1):
        if S[j] == now:
            continue
        else:
            sec = S[j]
            thi = rgb(now,sec)
            ans += S[j+1:].count(thi)
            if j+(j-i) < N and S[j+(j-i)]==thi:
                ans-=1
print(ans)

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

print(ans)

Submission status: Time Limit Exceeded

Solution code:
import sys
sys.setrecursionlimit(10 ** 6)  # 再帰関数の再帰の深さを設定
to_index = lambda x: int(x) - 1  # 入力した数字に1を引いたものを返す
print_list_in_2D = lambda x: print(*x, sep="\n")  # リストの要素を改行を挟んで表示する関数

# 入力を整数に変換して受け取る
def input_int():
    return int(input())

def map_int_input():
    return map(int, input())

MII = map_int_input

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

def MII_to_index():
    return map(to_index, input())

def MII_split_to_index():
    return map(to_index, input().split())

# 入力全てを整数に変換したものの配列を受け取る
def list_int_inputs():
    return list(map(int, input()))

LII = list_int_inputs

def LII_split():
    return list(map(int, input().split()))

# 2次元リスト化
def LII_2D(rows_number):
    return [LII() for _ in range(rows_number)]

def LII_split_2D(rows_number):
    return [LII_split() for _ in range(rows_number)]

N = input_int()
S = input()

if N < 3:
    print(0)
    exit()
count = 0
rs = []
gs = []
bs = []
for i in range(len(S)):
    if S[i] == 'R':
        rs.append(i)
    elif S[i] == 'G':
        gs.append(i)
    else:
        bs.append(i)
count = 0
for r in rs:
    for g in gs:
        for b in bs:
            rgb = [r, g, b]
            rgb.sort()
            if rgb[1]-rgb[0] != rgb[2]-rgb[1]:
                count += 1



# for i in range(N - 2):
#     for j in range(i + 1, N - 1):
#         if S[i] == S[j]:
#             continue
#
#         for k in range(j + 1, N):
#             if S[j] == S[k] or S[i] == S[k] or j - i == k - j:
#                 continue
#             else:
#                 count += 1
print(count)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
s = str(input())
res = 0

for i in range(n):
    for j in reversed(range(n)):
        if i > j:
            break
        for k in reversed(range(n)):
            if i < j and j < k:
                if s[i] != s[j] and s[i] != s[k] and s[j] != s[k]:
                    if j - i != k - j:
                        res += 1
            else:
                break
print(res)

Submission status: Time Limit Exceeded

Solution code:
# import sys
import math #sqrt,gcd
# import decimal
# import queue # queue
# import bisect
# import heapq # priolity-queue
# import time
from itertools import product,permutations,combinations,combinations_with_replacement #順列生成
# import collections # deque
from operator import itemgetter,mul
# from fractions import Fraction
# from functools import reduce

mod = int(1e9+7)
INF = 1<<29
lINF = 1<<35

def readInt():
    return list(map(int,input().split()))

def main():
    n = int(input())
    s = input()
    ans = 0
    for x in combinations(range(n),3):
        i,j,k = x
        if j-i==k-j: continue
        if s[i]!=s[j] and s[j]!=s[k] and s[i]!=s[k]:
            ans += 1
    print(ans)
    return

if __name__=='__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
import math
def main():
    N=input()
    S=input()
    N=int(N)
    ans=0
    ind=[]
    tmp={"R":0,"G":0,"B":0}
    for i in S:
        tmp[i]+=1
        ind.append(tmp.copy())
    for i in range(0,N-2):
        for j in range(i+1,N-1):
            if S[i]==S[j]:
                continue
            col=[k for k in ["R","G","B"] if k!=S[i] and k!=S[j]]
            col=col[-1]
            if 2*j-i <N and S[j+j-i]==col:
                ans-=1
            ans+=(ind[-1][col]-ind[j][col])
    print(ans)

main()

Submission status: Time Limit Exceeded

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

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

print(ans)

Submission status: Time Limit Exceeded

Solution code:
a=int(input())
s=input()
count=0
x=[]
y=[]
z=[]
for i in range(a):
    if s[i]=="R":
        x+=[i]
    elif s[i]=="B":
        y+=[i]
    else:
        z+=[i]
for i in x:
    for j in y:
        p=2*i-j
        q=2*j-i
        r=(i+j)/2
        t=0
        if p in z:
            t+=1
        if q in z:
            t+=1
        if r in z:
            t+=1
        count+=len(z)-t
print(count)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
s = input()
count = 0
for i in range(n):
  for j in range(i):
    if s[i] != s[j]:
      for k in range(j):
        if 2*j != i+k and s[j]!=s[k] and s[k]!=s[i]:
          count += 1

print(count)

Submission status: Time Limit Exceeded

Solution code:
import bisect
import sys
input=sys.stdin.readline
def main():
    N=int(input())
    S=input().rstrip()
    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)
    ans=0
    for i in range(N):
        for j in range(i):
            if(S[i]==S[j]):
                continue
            else:
                s=set([S[i],S[j]])
            if('B' not in s):
                lon=len(B)-bisect.bisect_left(B,i)
                mi=bisect.bisect_left(B,i+i-j)
                if(mi<len(B) and B[mi]==i+i-j):
                    lon-=1
            elif('R' not in s):
                lon=len(R)-bisect.bisect_left(R,i)
                mi=bisect.bisect_left(R,i+i-j)
                if(mi<len(R) and R[mi]==i+i-j):
                    lon-=1
            elif('G' not in s):
                lon=len(G)-bisect.bisect_left(G,i)
                mi=bisect.bisect_left(G,i+i-j)
                if(mi<len(G) and G[mi]==i+i-j):
                    lon-=1
            ans+=lon
        
    print(ans)
    
if __name__=='__main__':
    main()

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
# coding: utf-8
# Your code here!
#from sys import stdin
#import math
#from functools import reduce
    
#A, B, C = [int(x) for x in stdin.readline().rstrip().split()]
N = int(input())
S = input()
 
counter = 0
 
for k in range(N):
    for j in range(k):
        for i in range(j):
            if (j-i)==(k-j):
                continue
            si = S[i]
            sj = S[j]
            sk = S[k]
            if (si==sj):
                continue
            elif (si==sk):
                continue
            elif (sj==sk):
                continue
            counter = counter + 1
 
print(counter)

Submission status: Time Limit Exceeded

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

    if N <= 3 :
        print("0")
    else :
        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 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) :
                        count = count + 1
                        #print(i,S[i-1])
                        #print(j,S[j-1])
                        #print(k,S[k-1])
        #print("count")
        print(count)

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))

N = INT()
S = input()

ans = 0

for i in range(0, N-2):
    for k in range(i+2, N):
        for j in range(i+1, k):
            # 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:
                ans += 1

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, N - 1):
        if S[j] != S_i:
            S_j = S[j]
            for k in range(j, 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:
import sys
sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))
from collections import deque
def resolve():
    N = ir()
    nS = sr()
    q = deque([])
    S = []
    for i in range(N):
        if nS[i] == 'R':
            S.append(2)
        elif nS[i] == 'G':
            S.append(3)
        else:
            S.append(5)
        q.append([S[i], S[i], i, -1])
    ans = 0
    while len(q) > 0:
        u, v, n, d = q.popleft()
        if d == -1:
            for i in range(n+1, N):
                if u != S[i]:
                    q.append([u, S[i], i, i-n])
        else:
            for i in range(n+1, N):
                if i == n+d:
                    continue
                if u*v*S[i] == 30:
                    ans += 1
    print(ans)
resolve()

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
S = list(input())
ans=0

for i in range(0,N-2):
  I = S[i]
  for j in range(i+1,N-1):
    if S[j] != I:
      J = S[j]
      for k in range(j+1,N):
        if S[k] != I and S[k] != J:
          if 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(N):
    for j in range(i):
        for k in range(j):
            if(k - j == j - i):
                continue
            if(S[i] == S[j]):
                continue
            elif(S[j] == S[k]):
                continue
            elif(S[i] == S[k]):
                continue
            sum += 1
            
print(sum)

Submission status: Time Limit Exceeded

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

ri = [n+1 for n, v in enumerate(s) if v == 'R']
gi = [n+1 for n, v in enumerate(s) if v == 'G']
bi = [n+1 for n, v in enumerate(s) if v == 'B']

ans = 0

for r in ri:
    for g in gi:
        for b in bi:
            if r < g and g < b:
                if g - r != b - g:
                    ans += 1
            elif g < r and r < b:
                if r - g != b - r:
                    ans += 1
            elif r < b and b < g:
                if b - r != g - b:
                    ans += 1
            elif g < b and b < r:
                if b - g != r - b:
                    ans += 1
            elif b < r and r < g:
                if r - b != g - r:
                    ans += 1
            elif b < g and g < r:
                if g - b != r - g:
                    ans += 1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
s=list(input())
rlist=[]
glist=[]
blist=[]
ans=0
if len(s)<=3:
    print(0)
    exit()
for i in range(n):
    if s[i]=="R":
        rlist.append(i)
    elif s[i]=="G":
        glist.append(i)
    else:
        blist.append(i)
if len(rlist)==0 or len(glist)==0 or len(blist)==0:
    print(0)
    exit()
if rlist[0] < glist[0] and glist[0]< blist[0]:
    for i in rlist:
        for j in glist:
            for k in blist:
                tmp1=max(i,j,k)
                tmp2=min(i,j,k)
                tmp3=i+j+k-tmp1-tmp2
                if tmp2-tmp3 != tmp3-tmp1:
                    ans+=1
                else:
                    continue
elif glist[0] < rlist[0] and rlist[0]< blist[0]:
    for i in glist:
        for j in rlist:
            for k in blist:
                tmp1=max(i,j,k)
                tmp2=min(i,j,k)
                tmp3=i+j+k-tmp1-tmp2
                if tmp2-tmp3 != tmp3-tmp1:
                    ans+=1
                else:
                    continue
elif glist[0] < blist[0] and blist[0]< rlist[0]:
    for i in glist:
        for j in blist:
            for k in rlist:
                tmp1=max(i,j,k)
                tmp2=min(i,j,k)
                tmp3=i+j+k-tmp1-tmp2
                if tmp2-tmp3 != tmp3-tmp1:
                    ans+=1
                else:
                    continue
elif blist[0] < glist[0] and glist[0]< rlist[0]:
    for i in blist:
        for j in glist:
            for k in rlist:
                tmp1=max(i,j,k)
                tmp2=min(i,j,k)
                tmp3=i+j+k-tmp1-tmp2
                if tmp2-tmp3 != tmp3-tmp1:
                    ans+=1
                else:
                    continue
elif blist[0] < rlist[0] and rlist[0]< glist[0]:
    for i in blist:
        for j in rlist:
            for k in glist:
                tmp1=max(i,j,k)
                tmp2=min(i,j,k)
                tmp3=i+j+k-tmp1-tmp2
                if tmp2-tmp3 != tmp3-tmp1:
                    ans+=1
                else:
                    continue
else:
    for i in rlist:
        for j in blist:
            for k in glist:
                tmp1=max(i,j,k)
                tmp2=min(i,j,k)
                tmp3=i+j+k-tmp1-tmp2
                if tmp2-tmp3 != tmp3-tmp1:
                    ans+=1
                else:
                    continue
print(ans)

Submission status: Time Limit Exceeded

Solution code:
# =map(int,input().split())
n=int(input())
s=input()
import sys
cnt=0
if ('R' in s)and('B' in s)and('G' in s):
    for i in range(len(s)):
        first=s[i]
        for k in range(i+1,len(s)):
            if (s[k]!=first):
                second=s[k]
                for j in range(k+1,len(s)):
                    if (s[j]!=first)and(s[j]!=second)and((j-k)!=(k-i)):
                        cnt+=1
else:
    print(0)
    sys.exit()
print(cnt)

Submission status: Time Limit Exceeded

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

r = len(s.replace('G','').replace('B',''))
g = len(s.replace('R','').replace('B',''))
b = len(s.replace('G','').replace('R',''))

ans = r*g*b

for i in range(n):
  for j in range(n):
    if i+j+j+2 >= n:
      break
    
    if (not s[i] == s[i+j+1]) and (not s[i+j+1] == s[i+j+j+2]) and (not s[i+j+j+2] == s[i]):
      ans -= 1
      
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import sys

sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
printV = lambda x: print(*x, sep="\n")
printH = lambda x: print(" ".join(map(str,x)))
def IS(): return sys.stdin.readline()[:-1]
def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LI1(): return list(map(int1, sys.stdin.readline().split()))
def LII(rows_number): return [II() for _ in range(rows_number)]
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def LLI1(rows_number): return [LI1() for _ in range(rows_number)]

def main():
	n = II()
	s = IS()
	r,g,b=[],[],[]

	def binary_search(lst, K):
		l = 0; r = len(lst);
		while(l+1<r):
			mid = (l+r)//2
	    #下記の操作を書き換えることによって探索条件を変更可能
			if(lst[mid]>K): r=mid
			else: l=mid
		return l

	for i,ss in enumerate(s):
		if ss=='R':
			r.append(i)
		elif ss=='G':
			g.append(i)
		else:
			b.append(i)
	ans=len(r)*len(g)*len(b)
	for rr in r:
		for gg in g:
			a=max(rr,gg)+abs(rr-gg)
			if a in b:
				ans-=1
			a=min(rr,gg)-abs(rr-gg)
			if a in b:
				ans-=1
			if((rr+gg)%2==0):
				a=(rr+gg)//2
				if a in b:
					ans-=1
	print(ans)







if __name__ == '__main__':
	main()

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:
        for k in b:
            a = [i,j,k]
            a.sort()
            if (a[1]-a[0])!=(a[2]-a[1]):
                count += 1
print(count)

Submission status: Time Limit Exceeded

Solution code:
import itertools
n = int(input())
s = list(input())
ans = 0
idx = [i for i in range(n)]
p = []
for i in list(itertools.permutations(idx, 3)):
    if i[0] < i[1] < i[2]:
        p.append(i)
for a, b, c in p:
    if s[a] == s[b] or s[a] == s[c] or s[b] == s[c]:
        continue
    elif b-a == c-b:
        continue
    else:
        ans += 1
print(ans)

Submission status: Time Limit Exceeded

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

for i in range(len(S)):
  for j in range(len(S)):
    for k in range(len(S)):
      if (S[i] != S[j] and S[i] != S[k] and S[j] != S[k]) and abs(i-j) != abs(j-k) and i < j < k:
        ans += 1

print(ans)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
s = input()
sub=0
flg_r = 0
flg_g = 0
flg_b = 0#0だと見つかってない
for a in range(n-2):
    rgb = ("R","G","B")
    #print(a)
    for b in range(a+1,n-1):
        #print(a,b)
        rgb_kake = list(rgb)
        rgb_kake.remove(s[a])
        if s[a] != s[b]:
            #print(s[a],s[b],rgb, rgb_kake)
            rgb_kake.remove(s[b])
            for c in range(b+1,n):
                if s[c] == rgb_kake[0]:
                    #print(a,b,c)
                    if b-a != c-b:
                        sub+=1
print(sub)

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);
    if s[i] == 'G' :
        g.append(i+1);
    if s[i] == 'B' :
        b.append(i+1);

ans = 0;
for i in r :
    for j in g :
        for k in b :
            l = [i,j,k];
            l.sort();
            if not(l[1]-l[0]-1 == l[2]-l[1]-1) :
                ans += 1;

print(ans);

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
S=input()
count=0
for i,s in enumerate(S):
  s1=s
  for j,ss in enumerate(S[i:]):
    if ss!=s1:
      s2=ss
      d=j
      for k,sss in enumerate(S[i+j:]):
        if sss !=s1 and sss!=s2 and k!=d:
          count+=1
print(count)

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

Solution code:
num=int(input())
txt=input()
count=0
for i in range(len(txt)-2):
  a=txt[i]
  for j in range(i+1,len(txt)-1):
    b=txt[j]
    if a==b:
      continue
    for k in range(j+1,len(txt)):
      c=txt[k]
      if c!=a and c!=b:
        if k-j != j-i:
          count+=1
        else:
          pass
print(count)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
S = input()
s = [S[i] for i in range(len(S))]
R_list = []
G_list = []
B_list = []
for i in range(N):
    if s[i] == "R":
        R_list.append(i+1)
    elif s[i] == "G":
        G_list.append(i+1)
    elif s[i] == "B":
        B_list.append(i+1)
ans = []
for i in R_list:
    for j in G_list:
        for k in B_list:
            list = [i,j,k]
            list.sort()
            if list[1] - list[0] != list[2] - list[1]:
                ans.append(0)
print(len(ans))

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
s = input()
sl = [s[i] for i in range(len(s))]

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

print(ans)

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):
        for k in range(j + 1, N):
            if (j - i) == (k - j):
                continue
            if S[i] == S[k]:
                continue
            if S[j] == S[k]:
                continue
            if S[i] == S[j]:
                continue
            ans += 1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
from collections import defaultdict, Counter
from heapq import heapify, heappop, heappush
from sys import stdin


def main():
    res = 0
    n = int(input())
    s = str(input())
    for i in range(n):
        for j in range(i+1, n):
            if s[i] == s[j]:
                continue
            else:
                for k in range(j+1, n):
                    if s[i] == s[k] or s[j] == s[k]:
                        continue
                    if j - i == k - j:
                        continue
                    res += 1
    print(res)


def input(): return stdin.readline().rstrip()


main()

Submission status: Time Limit Exceeded

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

if ('R' in S and 'G' in S and 'B' in S):
    for i in range(N):
        a = S[i]
        for j in range(i+1,N):
            b = S[j]
            if a==b:
                continue
            for k in range(j+1,N):
                c = S[k]
                if b==c:
                    continue
                if (a!=b)and(b!=c)and(a!=c)and((j-i)!=(k-j)):
                   
                    cnt += 1


print(cnt)

Submission status: Time Limit Exceeded

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

# def main(a=0, b=''):
def main():
    # 整数の入力
    a = int(input())
    # a = int(a)
    # スペース区切りの整数の入力
    # b, c = map(int, input().split())
    # b, c = map(int, input())

    # # 文字列の入力
    b = input()
    # 出力
    # print("{} {}".format(a+b+c, s))
    count = 0
    for i in range(a):
        for j in range(i, a):
            for k in range(j, a):
                if j - i == k - j:
                    continue
                if b[i]==b[j] or b[j]==b[k] or b[i]==b[k]:
                    continue
                count += 1
    print(count)


if __name__ == '__main__':
    # main(4, 'RRGB')
    # main(39, 'RBRBGRBGGBBRRGBBRRRBGGBRBGBRBGBRBBBGBBB')
    main()

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter
N = int(input())
S = list(input())
c = Counter(S)
# print('c', c)

if len(c) != 3:
    print(0)
    exit()

con1 = 1
for v in c.values():
    con1 *= v

not_con2 = 0
for d in range(3001):
    for i in range(3001):
        j = i + d
        k = j + d
        if N - 1 < k:
            continue
        # print('S', S[i], S[j], S[k], i, j, k)
        if S[i] != S[j] and S[j] != S[k] and S[k] != S[i]:
            not_con2 += 1

# print('not_con2', not_con2)
ans = con1 - not_con2
print(ans)