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

Submission status: Time Limit Exceeded

Solution code:
from collections import defaultdict
from bisect import bisect_left
n = int(input())
s = input()
c = 0
f = defaultdict(list)
for i in range(n):
	f[s[i]].append(i)
for i in f:
	f[i].sort()
for i in range(n):
	for j in range(i+1, n):
		if  s[i] != s[j]:
			for k in f:
				if k != s[i] and k != s[j]:
					t = bisect_left(f[k], j+1)
					t1 = bisect_left(f[k][t:], 2*j - i)
					try:
						if f[k][t:][t1] == 2*j - i:
							c += len(f[k][t:]) - 1	
						else:
							c += len(f[k][t:])
					except:
						c += len(f[k][t:])
print(c)

Submission status: Time Limit Exceeded

Solution code:
from collections import defaultdict
from bisect import bisect_left
n = int(input())
s = input()
c = 0
f = defaultdict(list)
for i in range(n):
	f[s[i]].append(i)
for i in f:
	f[i].sort()
for i in range(n):
	for j in range(i+1, n):
		if  s[i] != s[j]:
			for k in f:
				if k != s[i] and k != s[j]:
					t = bisect_left(f[k], j+1)
					if(2*j - i) in f[k][t:]:
						c += len(f[k][t:]) - 1
					else:
						c += len(f[k][t:])
print(c)

Submission status: Time Limit Exceeded

Solution code:
from collections import defaultdict
n = int(input())
s = input()
c = 0
f = defaultdict(list)
for i in range(n):
	f[s[i]].append(i)
for i in range(n):
	for j in range(i+1, n):
		if  s[i] != s[j]:
			for k in f:
				if k != s[i] and k != s[j]:
					for m in f[k]:
						if m > j and 2*j - i != m:
							c += 1
print(c)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
S = input()
arr = list(S)
now = 0
count = 0
for first in range(N-2):
  for second in range(first+1,N-1):
    if arr[first] != arr[second]:
      for third in range(second+1,N):
        if arr[second] != arr[third] and arr[third] != arr[first] and second - first != third - second:
          count += 1
print(count)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
def main():
    from itertools import product

    n, s = int(input()), tuple(input())
    m = {'R', 'G', 'B'} 
    ans = 0

    for i in range(n - 2):
        for j in range(i + 1, n - 1):
            if s[i] == s[j]:
                continue
            t = m - {s[i], s[j]}
            t = t.pop()
            d = j - i
            ans += s[j + 1:].count(t)
            if j + d < n and s[j + d] == t:
                ans -= 1

    print(ans)


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
def main():
    from itertools import product

    n, s = int(input()), input()
    ans = 0

    for i in range(n - 2):
        for j in range(i + 1, n - 1):
            if s[i] == s[j]:
                continue
            t = {'R', 'G', 'B'} - {s[i], s[j]}
            t = t.pop()
            d = j - i
            ans += s[j + 1:].count(t)
            if j + d < n and s[j + d] == t:
                ans -= 1

    print(ans)


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
def main():
    from itertools import product

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


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
def main():
    from itertools import product

    n, s = int(input()), input()
    r, g, b = [], [], []
    for i, j in enumerate(s):
        if j == 'R':
            r.append(i)
        if j == 'G':
            g.append(i)
        if j == 'B':
            b.append(i)
    ans = 0
    for t in product(r, g, b):
        l = list(t)
        l.sort()
        if l[2] - l[1] != l[1] - l[0]:
            ans += 1

    print(ans)


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
s=input()
sum=0
box=['RGB','RBG','GRB','GBR','BRG','BGR']
for k in range(n):
    for j in range(k):
        for i in range(j):
            if j-i!=k-j:
                word=s[k]+s[j]+s[i]
                if word in box:
                    sum=sum+1
print(sum)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
s=input()
r,g,b=[],[],[]
ans=0
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)
for i in range(len(r)):
  for j in range(len(g)):
    for k in range(len(b)):
      l=[r[i],g[j],b[k]]
      l.sort()
      if l[1]-l[0]!=l[2]-l[1]:
        ans+=1
print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
# this is a good problem !

import sys
si = sys.stdin.readline


def main():
    d, ld, count, n, s = ['R', 'G', 'B'], [[0], [0], [0]], 0, int(si()), si()
    dc = d[:]
    # letter distribution
    # s = si()[:-1]

    for i in range(n-1, -1, -1):
        for j in range(3):
            if s[i] == dc[j]:
                ld[j] = [1+ld[j][0]]+ld[j]
            else:
                ld[j] = [ld[j][0]]+ld[j]

    for i in range(n-2):
        rgb1 = s[i]
        dc.remove(rgb1)
        for j in range(i+1, n-1):
            if s[j] in dc:
                rgb2 = s[j]
                dc.remove(rgb2)
                count += ld[d.index(dc[0])][j+1]
                k = j+j-i
                if k < n and s[k] in dc:
                    count -= 1
                dc += [rgb2]
        dc += [rgb1]
    print(count)


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import sys
import numpy as np
import math
# for AtCoder
# import fractions
from collections import deque 
from functools import reduce

input = sys.stdin.readline

n = int(input())

s = input()

s_np = np.array(s)

R_idx = np.array([i for i, x in enumerate(s) if x == 'R'])
G_idx = np.array([i for i, x in enumerate(s) if x == 'G'])
B_idx = np.array([i for i, x in enumerate(s) if x == 'B'])

cnt = 0
for R_i in R_idx:
    for G_i in G_idx:
        R_G = abs(R_i - G_i)
        ng1 = np.where(abs(B_idx - R_i) == R_G, 1, 0)
        ng2 = np.where(abs(B_idx - G_i) == R_G, 1, 0)
        ng3 = np.where(abs(B_idx - R_i) == abs(B_idx - G_i), 1, 0)
        cnt += (B_idx.shape[0] - ng1.sum() - ng2.sum() - ng3.sum())
                
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
# this is a good problem !

import sys
si = sys.stdin.readline

d = ['R', 'G', 'B']
ld = [[0], [0], [0]]  # letter distribution


def main():
    count = 0
    n = int(si())
    s = si()[:-1]
    dc = d[:]

    for i in range(n-1, -1, -1):
        for j in range(3):
            if s[i] == dc[j]:
                ld[j] = [1+ld[j][0]]+ld[j]
            else:
                ld[j] = [ld[j][0]]+ld[j]

    for i in range(n-2):
        rgb1 = s[i]
        dc.remove(rgb1)
        for j in range(i+1, n-1):
            if s[j] in dc:
                rgb2 = s[j]
                dc.remove(rgb2)
                count += ld[d.index(dc[0])][j+1]
                k = j+j-i
                if k < n and s[k] in dc:
                    count -= 1
                dc += [rgb2]
        dc += [rgb1]
    print(count)


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
N = int(input());
S = input();
A = []; 

for i in range(len(S)):
  A.append(S[i]);

num = 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 A[i] != A[j] and A[j] != A[k] and A[k] != A[i]:
          num += 1;
        else:
          pass
      else:
        pass
      
print(num)

Submission status: Time Limit Exceeded

Solution code:
import sys
import numpy as np
import math
# for AtCoder
# import fractions
from collections import deque 
from functools import reduce

input = sys.stdin.readline

n = int(input())

s = input()

s_np = np.array(s)

R_idx = [i for i, x in enumerate(s) if x == 'R']
G_idx = [i for i, x in enumerate(s) if x == 'G']
B_idx = [i for i, x in enumerate(s) if x == 'B']

cnt = 0
for R_i in R_idx:
    for G_i in G_idx:
        for B_i in B_idx:
            if abs(R_i - G_i) == abs(G_i - B_i):
                continue
            if abs(R_i - B_i) == abs(G_i - B_i):
                continue
            if abs(R_i - G_i) == abs(R_i - B_i):
                continue
            cnt += 1
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
from collections import deque, Counter as cnt
from collections import defaultdict as dd
from operator import itemgetter as ig
from bisect import bisect_right as bsr
from math import factorial, ceil, floor
import sys
sys.setrecursionlimit(1000000)

# お約束
args = None
INF = float("inf")
MOD = int(1e9 + 7)


def input(*ps):
    if type(ps[0]) is list:
        return [input(*ps[0][:-1]) for _ in range(ps[0][-1])]
    elif len(ps) == 1:
        return ps[0](next(args))
    else:
        return [p(next(args)) for p in ps]


def nlist(n, v):
    if not n:
        return [] if type(v) is list else v
    return [nlist(n[1:], v) for _ in range(n[0])]


# エントリーポイント
PARA = {"R": (1, 0, 0), "G": (0, 1, 0), "B": (0, 0, 1)}
PARA2 = {"R": 0, "G": 1, "B": 2}


def main():
    N, S = input(int, str)
    count = [(0, 0, 0)]
    for s in reversed(S):
        left = count[-1]
        count.append(((left[0] + PARA[s][0]),
                      (left[1] + PARA[s][1]),
                      (left[2] + PARA[s][2])))
    count.reverse()
    ans = 0
    for i in range(N - 2):
        for j in range(i + 1, N - 1):
            if S[i] == S[j]:
                continue
            last = ({"R", "G", "B"} - {S[i], S[j]}).pop()
            ans += count[j + 1][PARA2[last]]
            if ((j * 2 - i < N) and S[j * 2 - i] == last):
                ans -= 1
    print(ans)

    return


if __name__ == '__main__':
    args = iter(sys.stdin.read().split())
    main()

Submission status: Time Limit Exceeded

Solution code:
import sys
import numpy as np
import math
# for AtCoder
# import fractions
from collections import deque 
from functools import reduce

input = sys.stdin.readline

n = int(input())

s = input()

s_np = np.array(s)

R_idx = [i for i, x in enumerate(s) if x == 'R']
G_idx = [i for i, x in enumerate(s) if x == 'G']
B_idx = [i for i, x in enumerate(s) if x == 'B']

cnt = 0
for i, R_i in enumerate(R_idx):
    for j, G_i in enumerate(G_idx):
        for k, B_i in enumerate(B_idx):
            if abs(R_i - G_i) == abs(G_i - B_i):
                continue
            if abs(R_i - B_i) == abs(G_i - B_i):
                continue
            if abs(R_i - G_i) == abs(R_i - B_i):
                continue
            else:
                cnt += 1
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
import sys
import numpy as np
import math
# for AtCoder
# import fractions
from collections import deque 
from functools import reduce

# input = sys.stdin.readline

n = int(input())

s = input()

s_np = np.array(s)

R_idx = [i for i, x in enumerate(s) if x == 'R']
G_idx = [i for i, x in enumerate(s) if x == 'G']
B_idx = [i for i, x in enumerate(s) if x == 'B']

cnt = 0
for i, R_i in enumerate(R_idx):
    for j, G_i in enumerate(G_idx):
        for k, B_i in enumerate(B_idx):
            if abs(R_i - G_i) == abs(G_i - B_i):
                continue
            if abs(R_i - B_i) == abs(G_i - B_i):
                continue
            if abs(R_i - G_i) == abs(R_i - B_i):
                continue
            else:
                cnt += 1
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
import sys
import numpy as np
import math
# for AtCoder
# import fractions
from collections import deque 
from functools import reduce

# input = sys.stdin.readline

n = int(input())

s = input()

s_np = np.array(s)

R_idx = [i for i, x in enumerate(s) if x == 'R']
G_idx = [i for i, x in enumerate(s) if x == 'G']
B_idx = [i for i, x in enumerate(s) if x == 'B']

ncnt = 0
scnt = 0
cnt = 0
for i, R_i in enumerate(R_idx):
    for j, G_i in enumerate(G_idx):
        for k, B_i in enumerate(B_idx):
            ncnt += 1
#             if (G_i > R_i) or (B_i > G_i):
#                 continue
            if abs(R_i - G_i) == abs(G_i - B_i):
                scnt += 1
#                 print("NG")
#                 print(i, j, k)
                continue
            if abs(R_i - B_i) == abs(G_i - B_i):
                scnt += 1
#                 print("NG")
#                 print(i, j, k)
                continue
            if abs(R_i - G_i) == abs(R_i - B_i):
                scnt += 1
#                 print("NG")
#                 print(i, j, k)
                continue
            else:
                cnt += 1
#             if (ncnt < 100):
#                 print("OK")
#                 print(R_i, G_i, B_i)
#                 print((R_i - G_i), (G_i - B_i))
#                 print(i, j, k)
#                 print(s[R_i], s[G_i], s[B_i])
print(cnt)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
#! /usr/bin/env python
# -*- coding: utf-8 -*-
import math

    
def main():
	num = int(input())
	moji = input()
	count = 0
	
	for i in range(num):
		point = i
		if moji[i] == 'R':
			while not moji.find('G',point+1) == -1:
				count += moji[moji.find('G',point+1):].count('B')
#				print (str(i)+" "+str(moji.find('G',point+1))+" "+str(moji[moji.find('G',point+1):].count('B')))
				if len(moji) > moji.find('G',point+1)+moji.find('G',point+1)-i:
					if moji[moji.find('G',point+1)+moji.find('G',point+1)-i] == 'B':
						count -= 1
#						print (-1)
				point = moji.find('G',point+1)
			point = i
			while not moji.find('B',point+1) == -1:
				count += moji[moji.find('B',point+1):].count('G')
				if len(moji) > moji.find('B',point+1)+moji.find('B',point+1)-i:
					if moji[moji.find('B',point+1)+moji.find('B',point+1)-i] == 'G':
						count -= 1
				point = moji.find('B',point+1)
		elif moji[i] == "G":
			while not moji.find('R',point+1) == -1:
				count += moji[moji.find('R',point+1):].count('B')
#				print (str(i)+" "+str(moji.find('R',point+1))+" "+str(moji[moji.find('R',point+1):].count('B')))
				if len(moji) > moji.find('R',point+1)+moji.find('R',point+1)-i:
					if moji[moji.find('R',point+1)+moji.find('R',point+1)-i] == 'B':
						count -= 1
#						print (-1)
				point = moji.find('R',point+1)
			point = i
			while not moji.find('B',point+1) == -1:
				count += moji[moji.find('B',point+1):].count('R')
#				print (str(i)+" "+str(moji.find('B',point+1))+" "+str(moji[moji.find('B',point+1):].count('R')))
				if len(moji) > moji.find('B',point+1)+moji.find('B',point+1)-i:
					if moji[moji.find('B',point+1)+moji.find('B',point+1)-i] == 'R':
						count -= 1
#						print (-1)
				point = moji.find('B',point+1)
		elif moji[i] == "B":
			while not moji.find('G',point+1) == -1:
				count += moji[moji.find('G',point+1):].count('R')
#				print (str(i)+" "+str(moji.find('G',point+1))+" "+str(moji[moji.find('G',point+1):].count('R')))
				if len(moji) > moji.find('G',point+1)+moji.find('G',point+1)-i:
					if moji[moji.find('G',point+1)+moji.find('G',point+1)-i] == 'R':
						count -= 1
#						print (-1)
				point = moji.find('G',point+1)
			point = i
			while not moji.find('R',point+1) == -1:
				count += moji[moji.find('R',point+1):].count('G')
#				print (str(i)+" "+str(moji.find('R',point+1))+" "+str(moji[moji.find('R',point+1):].count('G')))
				if len(moji) > moji.find('R',point+1)+moji.find('R',point+1)-i:
					if moji[moji.find('R',point+1)+moji.find('R',point+1)-i] == 'G':
						count -= 1
#						print (-1)
				point = moji.find('R',point+1)
	
	print (count)

if __name__ == '__main__':
	main()

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
s = [1 if i=="R" else 2 if i=="G" else 4 for i in input()]
c = 0
for i in range(n-3):
    a = s[i]
    for j in range(i+1, n-1):
        if a == s[j]:
            continue
        else:
            b = a + s[j]
            c += sum([1 for k in range(j+1, n) if b+s[k]==7 and k-j!=j-i])
print(c)

Submission status: Time Limit Exceeded

Solution code:
c =0

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


for i in range(1,N+1):
    for j in range(1,N+1):
        for k in range(1,N+1):
            if j > k or i > j:
                continue
            elif S[i-1] == S[k-1] or S[j-1] == S[k-1] or S[i-1] == S[j-1]:
                continue
            elif j - i == k - j:
                continue
            else:
                c += 1
 
print(c)

Submission status: Time Limit Exceeded

Solution code:
c =0

N = int(input())+1
S = input()


for i in range(1,N):
    if i > N:
        continue
    for j in range(1,N):
        if j>N:
            continue
        for k in range(1,N):
            
            if j > k or i > j:
                continue
            elif k>N:
                continue
            elif S[i-1] == S[k-1] or S[j-1] == S[k-1] or S[i-1] == S[j-1]:
                continue
            elif j - i == k - j:
                continue
            else:
                c += 1

print(c)

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]: # 最初の2つの比較
            for k in range(j + 1, n):
                if s[j] != s[k] and s[k] != s[i]:
                    if j - i != k - j:
                        count = count + 1

print(count)

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):
        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 = count + 1

print(count)

Submission status: Time Limit Exceeded

Solution code:
c =0

N = int(input())+1
S = input()


for i in range(1,N):
    for j in range(1,N):
        for k in range(1,N):
            if j > k or i > j:
                continue
            elif S[i-1] == S[k-1] or S[j-1] == S[k-1] or S[i-1] == S[j-1]:
                continue
            elif j - i == k - j:
                continue
            else:
                c += 1

print(c)

Submission status: Time Limit Exceeded

Solution code:
from sys import stdin
import itertools

def main():
  N = int(stdin.readline())
  sentence = stdin.readline()
  
  ans = 0
  
  for (x, y, z) in itertools.combinations(range(N), 3):
    if x - y != y - z:
        if (sentence[x] != sentence[y]) & (sentence[y] != sentence[z]) & (sentence[x] != sentence[z]):
            ans += 1
      
  print(ans)
  
if __name__ == '__main__':
  main()

Submission status: Time Limit Exceeded

Solution code:
c =0

N = int(input())+1
S = tuple(input())


for i in range(1,N):
    for j in range(1,N):
        for k in range(1,N):
            if j > k or i > j:
                continue
            elif S[i-1] == S[k-1] or S[j-1] == S[k-1] or S[i-1] == S[j-1]:
                continue
            elif j - i == k - j:
                continue
            else:
                c += 1
print(c)

Submission status: Time Limit Exceeded

Solution code:
c =0

N = int(input())+1
S = tuple(input())


for i in range(1,N):
    for j in range(1,N):
        if i > j:
                continue
        for k in range(1,N):
            if j > k:
                continue
            elif S[i-1] == S[k-1] or S[j-1] == S[k-1] or S[i-1] == S[j-1]:
                continue
            elif j - i == k - j:
                continue
            else:
                c += 1
print(c)

Submission status: Time Limit Exceeded

Solution code:

c =0

N = int(input())+1
S = tuple(input())


for i in range(1,N):
    for j in range(1,N):
        if i > j:
                continue
        elif S[i-1] == S[j-1]:
                continue
        for k in range(1,N):
            if j > k:
                continue
            elif S[i-1] == S[k-1] or S[j-1] == S[k-1]:
                continue
            elif j - i == k - j:
                continue
            else:
                c += 1
print(c)

Submission status: Time Limit Exceeded

Solution code:
c =0

N = int(input())+1
S = tuple(input())


for i in range(1,N):
    for j in range(1,N):
        if i > j:
                continue
        elif S[i-1] == S[j-1]:
                continue
        for k in range(1,N):
            if j > k:
                continue
            elif S[i-1] == S[k-1]:
                continue
            elif S[j-1] == S[k-1]:
                continue
            elif j - i == k - j:
                continue
            else:
                c += 1
print(c)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
s = input()
ans = 0
for i in range(n-3):
    i_ = s[i]
    for j in range(i+1, n-1):
        if s[j] == i_: continue
        else:
            k = 2 * j - i
            j_ = s[j]
            s_ = s[j+1:]
            ans += len(s_) - s_.count(i_) - s_.count(j_)
            if k >= n: continue
            if s[k] != i_ and s[k] != j_: ans -= 1
print(ans)

Submission status: Time Limit Exceeded

Solution code:

c =0

N = int(input())+1
S = tuple(input())
for i in range(1,N):
    for j in range(1,N):
        if i > j:
                continue
        for k in range(1,N):
            if j > k:
                continue
            elif S[i-1] == S[j-1]:
                continue
            elif S[i-1] == S[k-1]:
                continue
            elif S[j-1] == S[k-1]:
                continue
            elif j - i == k - j:
                continue
            else:
                c += 1
print(c)

Submission status: Time Limit Exceeded

Solution code:
c =0

N = int(input())+1
S = tuple(input())
for i in range(1,N):
    for j in range(1,N):
        for k in range(1,N):
            if i > j or j > k:
                continue
            elif S[i-1] == S[j-1]:
                continue
            elif S[i-1] == S[k-1]:
                continue
            elif S[j-1] == S[k-1]:
                continue
            elif j - i == k - j:
                continue
            else:
                c += 1
print(c)

Submission status: Time Limit Exceeded

Solution code:

c =0

N = int(input())
S = input()
for i in range(1,N+1):
    for j in range(1,N+1):
        for k in range(1,N+1):
            if i > j or j > k:
                continue
            elif S[i-1] == S[j-1]:
                continue
            elif S[i-1] == S[k-1]:
                continue
            elif S[j-1] == S[k-1]:
                continue
            elif j - i == k - j:
                continue
            else:
                c += 1
print(c)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
S = input()
ans = 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 k<=j:
        continue
      if N>k 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:
N = int(input())
S = input()
ans = S.count("R")*S.count("G")*S.count("B")

for i in range(N-2):
  for j in range(i+1,N-1):
      k = 2*j-i
      if k<=j:
        continue
      else:
        if N>k 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:
N = int(input())
S = input()
count = 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:
        continue
      else:
        if S[i] != S[j] and S[i] != S[k] and S[j] != S[k]:
          count+=1
          
print(count)

Submission status: Time Limit Exceeded

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

# 条件1だけを満たす組み合わせの数
ans = S.count('R') * S.count('G') * S.count('B')

# 条件2を満たさないものを、条件1でカウントしたものから減算
for l in range(N): # left
  for r in range(l+1, N): # right
    c = (r - l) // 2 + l # center
    if c - l == r - c: # 条件2を満たさない
      if len(set([S[l], S[c], S[r]])) == 3: # 条件1を満たす
        ans -= 1

print(ans)

Submission status: Time Limit Exceeded

Solution code:
from itertools import product

k = int(input())
s = input()

temp_dict = {
    "R": [],
    "G": [],
    "B": [],
}
for i, c in enumerate(s):
    temp_dict[c].append(i)

ans = 0
temp_list = list(product(temp_dict["R"], temp_dict["G"], temp_dict["B"]))
for temp in temp_list:
    temp = sorted(list(temp))
    if temp[0] - temp[1] != temp[1] - temp[2]:
        ans += 1

print(ans)

Submission status: Time Limit Exceeded

Solution code:
#import itertools
N = int(input())
S = input()
ans = 0
#cnt = 0

for i in range(0, N):
    for j in range(i+1, N-1):
        if S[i] == S[j]:
            continue
        for k in range(j+1, N):
            #cnt += 1
            if j - i == k - j:
                continue
            if S[i] == S[j] or S[i] == S[k] or S[j] == S[k]:
                continue
            ans += 1
            #print(f"i={i},j={j},k={k}")
#print(cnt)
print(ans)

Submission status: Time Limit Exceeded

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

for i in range(0, N):
    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[j] or S[i] == S[k] or S[j] == S[k]:
                continue
            ans += 1
            #print(f"i={i},j={j},k={k}")
print(ans)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
S = input()
R = S.count('R')
G = S.count('G')
B = S.count('B')
ans = R * G * B
for d in range(1, N):
  for i in range(N):
    j = i + d
    k = i + d + d
    if k < N 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:
a=int(input())
moji=input()
r=[]
g=[]
b=[]
for i in range(a):
    if moji[i]=="R":
        r.append(i)
    elif moji[i]=="G":
        g.append(i)
    else:
        b.append(i)
res=len(r)*len(g)*len(b)
if len(r)==0 or len(g)==0 or len(b)==0:
    print(0)
else:
    min_len={0:r,1:g,2:b}
    if len(min_len[0])>len(min_len[1]):
        tmp=min_len[0]
        min_len[0]=min_len[1]
        min_len[1]=tmp
    if len(min_len[1])>len(min_len[2]):
        tmp=min_len[1]
        min_len[1]=min_len[2]
        min_len[2]=tmp
    if len(min_len[0])>len(min_len[1]):
        tmp=min_len[0]
        min_len[0]=min_len[1]
        min_len[1]=tmp
    a1=[]
    for i in range(3):
        a1.append(min_len[i])
    I=a1[0]
    J=a1[1]
    K=a1[2]
    for i in I:
        for j in J:
            dif=abs(i-j)
            min_i_j=min(i,j)
            max_i_j=max(i,j)
            if -dif+min_i_j in K:
                res-=1
            if dif+max_i_j in K:
                res-=1
            if dif%2==0 and  int(dif/2)+min_i_j in K:
                res-=1
    print(res)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import time

import numpy as np 

# Input Stdin
## 1 <= N <= 4000
## S = R/G/B length(N)

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

num = 0

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

Submission status: Time Limit Exceeded

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

ans=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):
                continue
            elif S[i]!=S[j] and S[i]!=S[k] and S[k]!=S[j]:
                ans+=1

print(ans)

Submission status: Time Limit Exceeded

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

RGB = S.count("R") * S.count("G") * S.count("B")

for i in range(N - 2):
  for j in range(i + 1, N - 1):
    k = 2 * j - i
    if ( k >= N ):
      continue
    if (S[i] != S[j]) & (S[j] != S[k]) & (S[i] != S[k]):
      RGB -= 1


print(RGB)

Submission status: Time Limit Exceeded

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

#r=s.count('R')
#g=s.count('G')
#b=s.count('B')

r,g,b=0,0,0

for i in range(0,n):
  if s[i]=='R':
    r+=1
  elif s[i]=='G':
    g+=1
  else:
    b+=1

ng=0

all=r*g*b

#NGパターン数の洗い出し
for i in range(0,n-2):
  for j in range(i,n-1):
    if s[i]==s[j]:
      continue
    else:
      if j*2-i<=n-1:
#        print(i,j,j*2-i)
        if s[j]!=s[j*2-i] and s[j*2-i]!=s[i]:
          ng+=1
print(all-ng)