Problem:


Score : 400 points

Problem Statement

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

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

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

j - i \neq k - j.

Constraints

1 \leq N \leq 4000

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

Input

Input is given from Standard Input in the following format:

N
S

Output

Print the number of triplets in question.

Sample Input 1

4
RRGB

Sample Output 1

1

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

Sample Input 2

39
RBRBGRBGGBBRRGBBRRRBGGBRBGBRBGBRBBBGBBB

Sample Output 2

1800



Sample input:
4
RRGB


Sample output:
1

Submission status: Runtime Error

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

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


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


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


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


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


def ss(): return input()


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


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


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


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


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


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


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


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


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

# a/b の切り上げ


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


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


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

Submission status: Runtime Error

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

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


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


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


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


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


def ss(): return input()


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


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


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


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


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


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


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


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


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

# a/b の切り上げ


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


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


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

Submission status: Runtime Error

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

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


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


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


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


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


def ss(): return input()


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


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


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


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


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


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


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


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


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

# a/b の切り上げ


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


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


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

Submission status: Runtime Error

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

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


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


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


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


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


def ss(): return input()


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


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


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


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


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


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


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


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


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

# a/b の切り上げ


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


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


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

Submission status: Runtime Error

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

r , g, b = S.count("R"), S.count("G"), S.count("B")
ans = r * g * b

for i in range(N-2):
    for d in range(N//2+1):
        j = i + d
        k = j + d
        if k < N:
        	if s[i] != s[j] and s[j] != s[k] and s[k] != s[i]:
            	ans -= 1
print(ans)

Submission status: Runtime Error

Solution code:
n=input()
s=input()
a=1;b=0
for i in s:#文字列を一個ずつ取り出す一つ目の文字用
	for i3 in range(n-a):#二つ目の文字を探す用ループ
		i3a=a+i3#二文字目のインデックス
		if i!=s[i3a]:#一つ目の文字と二つ目の文字が違う条件式
			j=s[i3a]
			for i2 in range(n-i3a):#三つ目を探すための回転数
				i2a=i3a+i2+1
				k=s[i2a]
				if i!=k and j!=k:#三文字目の条件式
					if (i3a+1)*2!=a+i2a+1:#j−i≠k−j である
						b+=1
			i2=0
	i3=0
	a+=1#二つ目の文字のインデックスの初期値	
print(b)

Submission status: Runtime Error

Solution code:
n = int(input())
s = input()
ans = s.count('B') * s.coufnt('G') * s.count('R')
for i in range(n):
  for j in range(i, n-1):
    k = 2*j - i
    if k >= n:
      continue
    if s[i] != s[j] and s[i] != s[k] and s[j] != s[k]:
      ans -= 1

print(ans)

Submission status: Runtime Error

Solution code:
mport sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
import numpy as np
from numba import njit
 
MOD = 10**9 + 7
 
N = int(readline())
S = np.array(list(read().rstrip()), np.int8)
 
R = np.sum(S == ord('R'))
B = np.sum(S == ord('B'))
G = np.sum(S == ord('G'))
 
@njit
def f(S):
    N = len(S)
    ret = 0
    for i in range(N):
        for j in range(i + 1, N):
            k = j + j - i
            if k >= N:
                break
            if S[i] != S[j] and S[i] != S[k] and S[j] != S[k]:
                ret += 1
    return ret
 
answer = R * B * G - f(S)
print(answer)

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
import sys
import collections


def main():
    input = sys.stdin.readline
    N = int(input())
    S = input()
    A = S.count('R')*S.count('G')*S.count('B')
    total = 0
    for j in range(1, N-1):
        for i in range(j):
            k = 2*j-i
            order += 1
            if k < len(S):
                if S[i] != S[j] and S[i] != S[k] and S[j] != S[k]:
                    total += 1
    print(A - total)


def main2():
    N = int(input())
    S = input()
    A = S.count('R')*S.count('G')*S.count('B')
    order = 0
    for i in range(N-2):
        for j in range(i+1, N-1):
            order += 1
            if 2*j-i < N:
                if S[i] != S[j] and S[i] != S[2*j-i] and S[j] != S[2*j-i]:
                    A -= 1
    print(A)
    print(order)


if __name__ == "__main__":
    main()

Submission status: Runtime Error

Solution code:
N = int(input())
A = list(input())
R = []
B = []
G = []
for i in range(N):
  if A[i] == "R":
    R.append(i)
  elif A[i] == "G":
    G.append(i)
  else:
    B.append(i)
ans = 0
for i in range(len(R)):
  for j in range(len(G)):
    for k in range(len(B)):
      if (max(R[i], G[j], B[k]) + min(R[i], G[j], B[k]))/2 != (R[i], G[j], B[k])/3:
        ans += 1
print(ans)

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:

from collections import Counter
n = int(input())
s = input()
d = Counter(s)
f = [d[i] for i in d]
c = f[0] * f[1] * f[2]
 


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

Submission status: Runtime Error

Solution code:
from collections import Counter
n = int(input())
s = input()
d = Counter(s)
f = [d[i] for i in d]
c = f[0] * f[1] * f[2]

for j in range(n):
	for i in range(n):
		if(j-i < 0 or j+i >= n):
			break
		elif(s[j-i] != s[j] and s[j+i] != s[j] and s[j+i] != s[j-i]):	c -= 1
 
print(c)

Submission status: Runtime Error

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

ri = [i for i, x in enumerate(s) if x=='R']
gi = [i for i, x in enumerate(s) if x=='G']
bi = [i for i, x in enumerate(s) if x=='B']

ans = len(ri) * len(gi) * len(bi)

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

print(ans)

Submission status: Runtime Error

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

r_i = [i for i, x in enumerate(s) if x=='R']
g_i = [i for i, x in enumerate(s) if x=='G']
b_i = [i for i, x in enumerate(s) if x=='B']

ans = 0

for i in len(r_i):
    for j in len(g_i):
        for k in len(b_i):
            if r_i[i]!=g_i[j] and g_i[j]!=b_i[k] and b_i[k]!=r_i[i]:
                ans += 1

print(ans)

Submission status: Runtime Error

Solution code:
def main():
    import collections
    import sys
    sys.setrecursionlimit(5000000)
    input = sys.stdin.readline
    N=int(input())
    S=input()
    if N<=3:
        print(0)
    else:
        str_list=list(S[:N])
        result=0
        c=collections.Counter(str_list)
        RGB_list=c.most_common()

        if len(c)<2:
            print(0)

        else:

            list1=[i for i, x in enumerate(str_list) if x == RGB_list[0][0]]
            list2=[i for i, x in enumerate(str_list) if x == RGB_list[1][0]]
            list3=[i for i, x in enumerate(str_list) if x == RGB_list[2][0]]
            list23=[]

        
            for i in list3:
                for j in list2:
                    list23+=[2*i-j,2*j-i,(i+j)/2]
            c1=collections.Counter(list23)
            for k in list1:
                for l in c1.keys():
                    if k==l:
                        result+=c1[l]
            print(int(RGB_list[0][1]*RGB_list[1][1]*RGB_list[2][1]-result))

if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
def main():
    import collections
    import sys
    sys.setrecursionlimit(50000)
    input = sys.stdin.readline
    N=int(input())
    S=input()
    if N<=3:
        print(0)
    else:
        str_list=list(S[:N])
        result=0
        c=collections.Counter(str_list)
        RGB_list=c.most_common()

        list1=[i for i, x in enumerate(str_list) if x == RGB_list[0][0]]
        list2=[i for i, x in enumerate(str_list) if x == RGB_list[1][0]]
        list3=[i for i, x in enumerate(str_list) if x == RGB_list[2][0]]
        list23=[]
        if RGB_list[2][0]==0 or RGB_list[1][0]==0:
            print(0)
        else:
            for i in list3:
                for j in list2:
                    list23+=[2*i-j,2*j-i,(i+j)/2]
            c1=collections.Counter(list23)
            for k in list1:
                for l in c1.keys():
                    if k==l:
                        result+=c1[l]
            print(int(RGB_list[0][1]*RGB_list[1][1]*RGB_list[2][1]-result))

if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
def main():
    import collections
    import sys
    sys.setrecursionlimit(50000)
    input = sys.stdin.readline
    N=int(input())
    S=input()
    if N<=3:
        print(0)
    else:
        str_list=list(S[:N])
        result=0
        c=collections.Counter(str_list)
        RGB_list=c.most_common()

        list1=[i for i, x in enumerate(str_list) if x == RGB_list[0][0]]
        list2=[i for i, x in enumerate(str_list) if x == RGB_list[1][0]]
        list3=[i for i, x in enumerate(str_list) if x == RGB_list[2][0]]
        list23=[]
        if RGB_list[2][0]==0 or RGB_list[1][0]==0:
            print(0)
        else:
            for i in list3:
                for j in list2:
                    list23+=[2*i-j,2*j-i,(i+j)/2]
            c1=collections.Counter(list23)
            for k in list1:
                for l in c1.keys():
                    if k==l:
                        result+=c1[l]
            print(int(RGB_list[0][1]*RGB_list[1][1]*RGB_list[2][1]-result))
            print(sys.getrecursionlimit())

if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
def main():
    import collections
    import sys
    sys.setrecursionlimit(500000)
    input = sys.stdin.readline
    N=int(input())
    S=input()
    if N<=3:
        print(0)
        sys.exit()
    else:
        str_list=list(S[:N])
        result=0
        c=collections.Counter(str_list)
        RGB_list=c.most_common()

        list1=[i for i, x in enumerate(str_list) if x == RGB_list[0][0]]
        list2=[i for i, x in enumerate(str_list) if x == RGB_list[1][0]]
        list3=[i for i, x in enumerate(str_list) if x == RGB_list[2][0]]
        list23=[]
        if RGB_list[2][0]==0 or RGB_list[1][0]==0:
            print(0)
            sys.exit()
        else:
            for i in list3:
                for j in list2:
                    list23+=[2*i-j,2*j-i,(i+j)/2]
            c1=collections.Counter(list23)
            for k in list1:
                for l in c1.keys():
                    if k==l:
                        result+=c1[l]
            print(int(RGB_list[0][1]*RGB_list[1][1]*RGB_list[2][1]-result))

if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
def main():
    import collections
    import sys
    sys.setrecursionlimit(500000)
    input = sys.stdin.readline
    N=int(input())
    S=input()
    if N<=3:
        print(0)
    else:
        str_list=list(S[:N])
        result=0
        c=collections.Counter(str_list)
        RGB_list=c.most_common()

        list1=[i for i, x in enumerate(str_list) if x == RGB_list[0][0]]
        list2=[i for i, x in enumerate(str_list) if x == RGB_list[1][0]]
        list3=[i for i, x in enumerate(str_list) if x == RGB_list[2][0]]
        list23=[]
        if RGB_list[2][0]==0 or RGB_list[1][0]==0:
            print(0)
        else:
            for i in list3:
                for j in list2:
                    list23+=[2*i-j,2*j-i,(i+j)/2]
            c1=collections.Counter(list23)
            for k in list1:
                for l in c1.keys():
                    if k==l:
                        result+=c1[l]
            print(int(RGB_list[0][1]*RGB_list[1][1]*RGB_list[2][1]-result))

if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
def main():
    import collections
    import sys
    input = sys.stdin.readline
    N=int(input())
    S=input()
    if N<=3:
        print(0)
    else:
        str_list=list(S[:N])
        result=0
        c=collections.Counter(str_list)
        RGB_list=c.most_common()

        list1=[i for i, x in enumerate(str_list) if x == RGB_list[0][0]]
        list2=[i for i, x in enumerate(str_list) if x == RGB_list[1][0]]
        list3=[i for i, x in enumerate(str_list) if x == RGB_list[2][0]]
        list23=[]
        if RGB_list[2][0]==0 or RGB_list[1][0]==0:
            print(0)
        else:
            for i in list3:
                for j in list2:
                    list23+=[2*i-j,2*j-i,(i+j)/2]
            c1=collections.Counter(list23)
            for k in list1:
                for l in c1.keys():
                    if k==l:
                        result+=c1[l]
            print(int(RGB_list[0][1]*RGB_list[1][1]*RGB_list[2][1]-result))

if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
def main():
    import collections
    import sys
    input = sys.stdin.readline
    N=int(input())
    S=input()
    if N<=3:
        print(0)
    else:
        str_list=tuple(S[:N])
        result=0
        c=collections.Counter(str_list)
        RGB_list=c.most_common()

        list1=[i for i, x in enumerate(str_list) if x == RGB_list[0][0]]
        list2=[i for i, x in enumerate(str_list) if x == RGB_list[1][0]]
        list3=[i for i, x in enumerate(str_list) if x == RGB_list[2][0]]
        list23=[]
        if RGB_list[2][0]==0 or RGB_list[1][0]==0:
            print(0)
        else:
            for i in list3:
                for j in list2:
                    list23+=[2*i-j,2*j-i,(i+j)/2]
            c1=collections.Counter(list23)
            for k in list1:
                for l in c1.keys():
                    if k==l:
                        result+=c1[l]
            print(int(RGB_list[0][1]*RGB_list[1][1]*RGB_list[2][1]-result))

if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
import collections
import sys
input = sys.stdin.readline
N=int(input())
S=input()
if N<=3:
    print(0)
else:
    str_list=tuple(S[:N])
    result=0
    c=collections.Counter(str_list)
    RGB_list=c.most_common()

    list1=[i for i, x in enumerate(str_list) if x == RGB_list[0][0]]
    list2=[i for i, x in enumerate(str_list) if x == RGB_list[1][0]]
    list3=[i for i, x in enumerate(str_list) if x == RGB_list[2][0]]
    list23=[]
    if RGB_list[2][0]==0 or RGB_list[1][0]==0:
        print(0)
    else:
        for i in list3:
            for j in list2:
                list23+=[2*i-j,2*j-i,(i+j)/2]
        c1=collections.Counter(list23)
        for k in list1:
            for l in c1.keys():
                if k==l:
                    result+=c1[l]
        print(int(RGB_list[0][1]*RGB_list[1][1]*RGB_li

Submission status: Runtime Error

Solution code:
import collections
import sys
input = sys.stdin.readline
N=int(input())
S=input()
str_list=tuple(S[:N])
result=0
c=collections.Counter(str_list)
RGB_list=c.most_common()

list1=[i for i, x in enumerate(str_list) if x == RGB_list[0][0]]
list2=[i for i, x in enumerate(str_list) if x == RGB_list[1][0]]
list3=[i for i, x in enumerate(str_list) if x == RGB_list[2][0]]
list23=[]
if RGB_list[2][0]==0 or RGB_list[1][0]==0:
    print(0)
else:
    for i in list3:
        for j in list2:
            list23+=[2*i-j,2*j-i,(i+j)/2]
    c1=collections.Counter(list23)
    for k in list1:
        for l in c1.keys():
            if k==l:
                result+=c1[l]
    print(int(RGB_list[0][1]*RGB_list[1][1]*RGB_list[2][1]-result))

Submission status: Runtime Error

Solution code:
import collections
N=int(input())
S=input()
str_list=tuple(S)
result=0
c=collections.Counter(str_list)
RGB_list=c.most_common()

list1=[i for i, x in enumerate(str_list) if x == RGB_list[0][0]]
list2=[i for i, x in enumerate(str_list) if x == RGB_list[1][0]]
list3=[i for i, x in enumerate(str_list) if x == RGB_list[2][0]]
list23=[]
l_append=list23.append
if RGB_list[2][0]==0 or RGB_list[1][0]==0:
    print(0)
else:
    for i in list3:
        for j in list2:
            l_append([i,j])
    for k in list1:
        for l in list23:
            if k==l[0]*2-l[1] or k==l[1]*2-l[0] or k==(l[0]+l[1])/2:
                result+=1
    print(int(RGB_list[0][1]*RGB_list[1][1]*RGB_list[2][1]-result))

Submission status: Runtime Error

Solution code:
import collections
N=int(input())
S=input()
str_list=tuple(S)
result=0
c=collections.Counter(str_list)
RGB_list=c.most_common()
def my_index_multi(A,x):
    return [i for i, _x in enumerate(A) if _x == x]

list1=my_index_multi(str_list,RGB_list[0][0])
list2=my_index_multi(str_list,RGB_list[1][0])
list3=my_index_multi(str_list,RGB_list[2][0])
list23=[]
l_append=list23.append
if RGB_list[2][0]==0 or RGB_list[1][0]==0:
    print(0)
else:
    for i in list3:
        for j in list2:
            l_append([i,j])
    for k in list1:
        for l in list23:
            if k==l[0]*2-l[1] or k==l[1]*2-l[0] or k==(l[0]+l[1])/2:
                result+=1
    print(int(RGB_list[0][1]*RGB_list[1][1]*RGB_list[2][1]-result))

Submission status: Runtime Error

Solution code:
import collections
N=int(input())
S=input()
str_list=list(S)
result=0
c=collections.Counter(str_list)
RGB_list=c.most_common()
def my_index_multi(A,x):
    return [i for i, _x in enumerate(A) if _x == x]

list1=my_index_multi(str_list,RGB_list[0][0])
list2=my_index_multi(str_list,RGB_list[1][0])
list3=my_index_multi(str_list,RGB_list[2][0])
list23=[]
for i in list3:
    for j in list2:
        list23.append([i,j])
for k in list1:
    for l in list23:
        if k==l[0]*2-l[1] or k==l[1]*2-l[0] or k==(l[0]+l[1])/2:
            result+=1
print(int(RGB_list[0][1]*RGB_list[1][1]*RGB_list[2][1]-result))

Submission status: Runtime Error

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


def convert_to_binary(character, string):
    array = []
    for c in string:
        if character == c:
            array.append(1)
        else:
            array.append(0)
    return array


def count_triple(S1, S2, S3):
    count = 0
    i = 1
    for Si in S1:
        if Si == 1:
            j = 1
            for Sj in S2:
                if Sj == 1:
                    k = 1
                    for Sk in S3:
                        if Sk == 1:
                            if (j - i) != (k - j):
                                count += 1
                        k += 1
                        if k > N:
                            break
                j += 1
                if j > N:
                    break
        i += 1
        if i > N:
            break
    return count


R = convert_to_binary('R', S)
G = convert_to_binary('G', S)
B = convert_to_binary('B', S)

found = 0

if R.index(1) < G.index(1) < B.index(1): found = count_triple(R, G, B)
if R.index(1) < B.index(1) < G.index(1): found = count_triple(R, B, G)
if G.index(1) < R.index(1) < B.index(1): found = count_triple(G, R, B)
if G.index(1) < B.index(1) < R.index(1): found = count_triple(G, B, R)
if B.index(1) < R.index(1) < G.index(1): found = count_triple(B, R, G)
if B.index(1) < G.index(1) < R.index(1): found = count_triple(B, G, R)

print(found)

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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


def convert_to_binary(character, string):
    array = []
    for c in string:
        if character == c:
            array.append(1)
        else:
            array.append(0)
    return array


def count_triple(S1, S2, S3):
    count = 0
    i = 0
    for Si in S1:
        if Si == 1:
            j = 0
            for Sj in S2:
                if Sj == 1:
                    k = 0
                    for Sk in S3:
                        if Sk == 1:
                            if (j - i) != (k - j):
                                count += 1
                        k += 1
                j += 1
        i += 1
    return count


R = convert_to_binary('R', S)
G = convert_to_binary('G', S)
B = convert_to_binary('B', S)

found = 0

if R.index(1) < G.index(1) < B.index(1): found = count_triple(R, G, B)
if R.index(1) < B.index(1) < G.index(1): found = count_triple(R, B, G)
if G.index(1) < R.index(1) < B.index(1): found = count_triple(G, R, B)
if G.index(1) < B.index(1) < R.index(1): found = count_triple(G, B, R)
if B.index(1) < R.index(1) < G.index(1): found = count_triple(B, R, G)
if B.index(1) < G.index(1) < R.index(1): found = count_triple(B, G, R)

print(found)

Submission status: Runtime Error

Solution code:
from collections import Counter

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

if N == 1 or N == 2:
    ans = 0
else:
    c = Counter(S)
    tmp = c.most_common()
    rgb = tmp[0][1] * tmp[1][1] * tmp[2][1]

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

print(ans)