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:
N = int(input())
S = input()

r_cnt = S.count('R')
g_cnt = S.count('G')
b_cnt = S.count('B')

ans = r_cnt * g_cnt * b_cnt

for i in range(1,N+1):
    for d in range(1, N+1):
        j = i+d
        k = j+d
        if k > N:
            break
        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 = input()
R = [] 
G = []
B = []
i = 1
while i < N+1:
  a = S[i-1]
  if a == 'R':
    R.append(i)
  elif a == 'G':
    G.append(i)
  else:
    B.append(i)
  i += 1
  

c = 0
d = len(R)*len(G)*len(B)


if d == 0:
    print(0)
else:
    for t in range(len(R)):
        for u in range(len(G)):
            k = (R[t] + G[u])/2
            if 2*R[t]- G[u] > 0:
              l = 2*R[t]-G[u]
              if l|set(B)==set(B):
                c += 1
            if 2*G[u] - R[t] > 0:
              
              m = 2*G[u]-R[t]
              if m|set(B)==set(B):
                c += 1
            if k|set(B)==set(B):
                c += 1

print(d-c)

Submission status: Runtime Error

Solution code:
ースコード 

Copy
Copy
N=int(input())
 
S=list(input())
m=0
 
a=S.count("R")
b=S.count("G")
c=S.count("B")
 
num=a*b*c
 
for i in range(N-2):
  for j in range(i+1,N-1):
    k=2*j-i #削る条件
    if k>N-1:
      break
    elif S[i]!=S[j] and S[j]!=S[k] and S[k]!=S[i]:
      m+=1
      
print(num-m)

Submission status: Runtime Error

Solution code:

from numba import jit

n = int(input())
s = list(input())
r = []
g = []
b = []

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


ans = 0


@jit
def aaa(n, s, r, g, b):
    ans=0
    for i in range(n):
        for j in range(i + 1, n):
            if s[i] == s[j]:
                continue
            if "R" not in [s[i], s[j]]:
                a = list(map(lambda x: x > j, r))
                ans += sum(a)
                if 2 * j - i in r:
                    ans -= 1
            elif "G" not in [s[i], s[j]]:
                a = list(map(lambda x: x > j, g))
                ans += sum(a)
                if 2 * j - i in g:
                    ans -= 1
            elif "B" not in [s[i], s[j]]:
                a = list(map(lambda x: x > j, b))
                ans += sum(a)
                if 2 * j - i in b:
                    ans -= 1
    return ans


ans = aaa(n, s, r, g, b)
print(ans)

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
# coding: utf-8

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

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

ans = 0

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

print(ans)

Submission status: Runtime Error

Solution code:
import sys
#import copy
#import numpy as np
#import itertools
import collections
#from collections import deque
#from scipy.sparse.csgraph import shortest_path, floyd_warshall, dijkstra, bellman_ford, johnson
#from scipy.sparse import csr_matrix

sys.setrecursionlimit(10**6)
readline = sys.stdin.readline
read = sys.stdin.read
count = collections.Counter

def main():
    N = int(readline())
    S = input()

    values = list(count(S).values())
    ans = values[0] * values[1] * values[2]

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

    print(ans)
    #print('end')


if __name__ == "__main__":
    main()

Submission status: Runtime Error

Solution code:
N=int(input())

S=list(input())
m=0

a=S.count("R")
b=S.count("G")
c=S.count("B")

num=a*b*c

for i in range(N-2):
  for j in range(i+1,N):
    k=2*j-i
    if k>=n-1:
      break
    elif S[i]!=S[j]!=S[k]:
      m+=1
      
print(num-m)

Submission status: Runtime Error

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

Rs = len([i for i, ch in enumerate(S) if ch == 'R'])
Gs = len([i for i, ch in enumerate(S) if ch == 'G'])
Bs = len([i for i, ch in enumerate(S) if ch == 'B'])

ans = Rs * Gs * Bs

if Rs == 0 or Gs == 0 or Bs == 0:
    print(0)
    exit(1)

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

Submission status: Runtime Error

Solution code:
#!/usr/bin/env python3
# -*- coding: utf-8 -*-


def main():
    N = int(input())
    S = input()

    R = 0
    G = 0
    B = 0

    for s in S:
        if s == 'R':
            R += 1
            continue
        elif s == 'G':
            G += 1
            continue
        elif s == 'B':
            B += 1
    

    total = 0

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

    print(N - total)


if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
k=int(input())
d=0
for a in range(1,k+1) :
    for b in range(1,k+1):
        for c in range(1,k+1):
            d+=gcd(a,b,c)
print(d)

Submission status: Runtime Error

Solution code:
# coding: utf-8
# Your code here!

_ = int(input())
RGB= list(input())

count = 0
sub = 0

r_list = []
g_list = []
b_list = []
for val in range(0,len(List)):
    if "R" == List[val]:
        r_list.append(val)
    elif "G" == List[val]:
        g_list.append(val)
    elif "B" == List[val]:
        b_list.append(val)

for index, a in enumerate(RGB):
    if a == "R":
        del g_list[0:len([i for i in g_list if i < index])]
        del b_list[0:len([i for i in b_list if i < index])]
        for g in g_list:
            for b in b_list:
                if g-index == b-g or b-index == g-b:
                    sub +=1
        count = count + len(g_list)*len(b_list)
                    
    elif a == "G":
        del b_list[0:len([i for i in b_list if i < index])]
        del r_list[0:len([i for i in r_list if i < index])]
        for b in b_list:
            for r in r_list:
                if b-index == r-b or r-index == b-r:
                    sub +=1
        count = count + len(b_list)*len(r_list)
                
    elif a == "B":
        del r_list[0:len([i for i in r_list if i < index])]
        del g_list[0:len([i for i in g_list if i < index])]
        for r in r_list:
            for g in g_list:
                if r-index == g-r or g-index == r-g:
                    sub +=1
        count = count + len(g_list)*len(r_list) 
        
print(count-sub)

Submission status: Runtime Error

Solution code:
import sys
#import copy
import numpy as np
#import itertools
#import collections
#from collections import deque
#from scipy.sparse.csgraph import shortest_path, floyd_warshall, dijkstra, bellman_ford, johnson
#from scipy.sparse import csr_matrix

sys.setrecursionlimit(10**6)
readline = sys.stdin.readline
read = sys.stdin.buffer.read

def main():
    # input
    N = int(readline())
    #S = np.array(list(readline()))
    S = np.array(list(read().rstrip()), np.int8)
    #print(S)

    R = np.sum(S == ord('R'))
    G = np.sum(S == ord('G'))
    B = np.sum(S == ord('B'))

    ans = R*G*B

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

    print(ans)
    #print('end')


if __name__ == "__main__":
    main()

Submission status: Runtime Error

Solution code:
n=int(input())
s=list(map(ord,input().split()))
R=[0]
G=[0]
B=[0]
for i in s:
  R.append(R[-1])
  G.append(G[-1])
  B.append(B[-1])
  if i==82:R[-1]+=1
  elif i==71:G[-1]+=1
  else:B[-1]+=1
ans=0
for i in range(n-2):
  for j in range(i+1,n-1):
    if s[i]==s[j]:continue
    if 82 not in [s[i],s[j]]:
      ans+=R[-1]-R[j]
      if j+(j-i)<n:
        if s[j+(j-i)]==82:ans-=1
    elif 71 not in [s[i],s[j]]:
      ans+=G[-1]-G[j]
      if j+(j-i)<n:
        if s[j+(j-i)]==71:ans-=1
    else:
      ans+=B[-1]-B[j]
      if j+(j-i)<n:
        if s[j+(j-i)]==66:ans-=1
print(ans)

Submission status: Runtime Error

Solution code:
n=int(input())
s=list(map(ord,input().split()))
R=[0]
G=[0]
B=[0]
for i in s:
  R.append(R[-1])
  G.append(G[-1])
  B.append(B[-1])
  if i==82:R[-1]+=1
  elif i=="71":G[-1]+=1
  else:B[-1]+=1
ans=0
for i in range(n-2):
  for j in range(i+1,n-1):
    if s[i]==s[j]:continue
    if 82 not in [s[i],s[j]]:
      ans+=R[-1]-R[j]
      if j+(j-i)<n:
        if s[j+(j-i)]==82:ans-=1
    elif 71 not in [s[i],s[j]]:
      ans+=G[-1]-G[j]
      if j+(j-i)<n:
        if s[j+(j-i)]==71:ans-=1
    else:
      ans+=B[-1]-B[j]
      if j+(j-i)<n:
        if s[j+(j-i)]==66:ans-=1
print(ans)

Submission status: Runtime Error

Solution code:
N = int(input())
S = list(input())
f=0
ijk = list()
for i in range(N):
    for j in range(N):
        for k in range(N):
            if(k>j and j>i):
                if(k == j+(j-i)):
                    pass
                elif(i == j-(j-k)):
                    pass
                else:
                    ijk.append([i+1,j+1,k+1])

for i in range(len(ijk)):
    if(S[ijk[i][0]]!= S[ijk[i][1]] and
       S[ijk[i][0]]!= S[ijk[i][2]] and
       S[ijk[i][1]]!= S[ijk[i][2]]):
       f+=1
print(f)

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
N = int(input())
S = list(input())
f=0
ijk = list()
for i in range(N):
    for j in range(N):
        for k in range(N):
            if(i<j<k):
                if(S[i]==S[j]):
                    pass
                elif(S[i]==S[k]):
                    pass
                elif(S[j]==S[k]):
                    pass
                else:
                    ijk.append([i+1,j+1,k+1])
# print(ijk)
for i in range(len(ijk)):
    if(ijk[i][1]-ijk[i][0] == ijk[i][2]-ijk[i][1]):
        pass:
    else:
        f += 1
print(f)

Submission status: Runtime Error

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)
    elif moji[i]=="B":
        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={len(r):r,len(g):g,len(b):b}
    tmp=sorted(min_len.keys())
    r=min_len[tmp[0]]
    g=min_len[tmp[1]]
    b=min_len[tmp[2]]
    for i in r:
        for j in g:
            if -abs(i-j)+min(i,j) in b:
                res-=1
            if abs(i-j)+max(i,j) in b:
                res-=1
            if abs(i-j)%2==0 and  int(abs(i-j)/2)+min(i,j) in b:
                res-=1
    print(res)

Submission status: Runtime Error

Solution code:
import collections
n = int(input())
s=input()
l=list(collections.Counter(s).values())
ans=l[0]*l[1]*l[2]
for i in range(n):
    for j in range(i+1,n):
        k = 2*j-i
        if n <= k:
            break
        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:
import numpy as np

def main():
    N = int(input())
    S = input()
    R,G,B = [],[],[]
    for i in range(N):
        if S[i]=="R":
            R.append(i)
        elif S[i] == "G":
            G.append(i)
        else:
            B.append(i)
    ans = len(R)*len(G)*len(B)
    rr,gg,bb = np.meshgrid(np.array(R),np.array(G),np.array(B))
  
    rgb = np.c_[rr.flatten(),gg.flatten(),bb.flatten()]
    a1,a2,a3 = np.hsplit(rgb,3)
    a1,a2,a3 = np.abs(a3-a2),np.abs(a2-a1),np.abs(a1-a3)
    a1,a2,a3 = a1==a2,a2==a3,a3==a1
    s = np.count_nonzero(a1) + np.count_nonzero(a2) + np.count_nonzero(a3)
    print(ans-s)

main()

Submission status: Runtime Error

Solution code:
import collections
n = int(input())
s=input()
l=list(collections.Counter(s).values())
ans=l[0]*l[1]*l[2]
for i in range(n):
    for j in range(i+1,n):
        k = 2*j-i
        if n<=k:
            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:
from collections import Counter

n=int(input())
s=input()
c=Counter(s)
ans=c['R']*c['G']c*['B']

for i in range(n-2):
    for j in range(i+1,n-1):
        w=j-i
        if j+w>=n:
            continue
        if s[i]!=s[j] and s[j+w]!=s[j] and s[j+w]!=s[i]:
            cnt-=1
print(ans)

Submission status: Runtime Error

Solution code:
import numpy as np
N = int(input())
S = input()
R_sum = np.zeros(N, dtype=np.int16)
G_sum = np.zeros(N, dtype=np.int16)
B_sum = np.zeros(N, dtype=np.int16)
rcnt = 0
gcnt = 0
bcnt = 0
cnt = 0
for c in S:
    if c == 'R':
        rcnt += 1
    elif c == 'G':
        gcnt += 1
    elif c == 'B':
        bcnt += 1
    R_sum[cnt] = rcnt
    G_sum[cnt] = gcnt
    B_sum[cnt] = bcnt
    cnt += 1

anssum = 0
for i in range(N):
    for j in range(i + 1, N):
        if S[i] == S[j]: continue
        clist = [S[i], S[j]]
        diff_idx = j - i

        if not ('R' in clist):
            anssum += (R_sum[N-1] - R_sum[j-1])
            if diff_idx + j < N:
                if S[diff_idx + j] == 'R':
                    anssum -= 1
        elif not ('G' in clist):
            anssum += (G_sum[N-1] - G_sum[j-1])
            if diff_idx + j < N:
                if S[diff_idx + j] == 'G':
                    anssum -= 1
        elif not ('B' in clist):
            anssum += (B_sum[N-1] - B_sum[j-1])
            if diff_idx + j < N:
                if S[diff_idx + j] == 'B':
                    anssum -= 1
print(anssum)

Submission status: Runtime Error

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>=n:
            break
        if s[i]!= s[j] and s[i]!=s[k] and s[i+j]!= s[k] :
            ans-=1
print(ans)

Submission status: Runtime Error

Solution code:
from bisect import bisect_right
N = int(input())
S = input().strip()
R = []
G = []
B = []
Ron = [0 for _ in range(len(S))]
Gon = [0 for _ in range(len(S))]
Bon = [0 for _ in range(len(S))]
for i in range(N):
    if S[i]=="R":
        R.append(i)
        Ron[i]=1
    elif S[i]=="G":
        G.append(i)
        Gon[i]=1
    else:
        B.append(i)
        Bon[i]=1
cnt = 0
for i in range(N):
    if Ron[i]==1:
        #RGB
        indr = i
        ind0 = bisect_right(G,indr)
        for j in range(ind0,len(G)):
            indg = G[j]
            ind1 = bisect_right(B,indg)
            if 2*indg-indr>B[-1] or Bon[2*indg-indr]==0 or Bon[2*indg-indr]==1 and 2*indg-indr<B[ind1]:
                cnt += len(B)-ind1
            else:
                cnt += len(B)-ind1-1
        #RBG
        ind0 = bisect_right(B,indr)
        for j in range(ind0,len(B)):
            indb = B[j]
            ind1 = bisect_right(G,indb)
            if 2*indb-indr>G[-1] or Gon[2*indb-indr]==0 or Gon[2*indb-indr]==1 and 2*indb-indr<G[ind1]:
                cnt += len(G)-ind1
            else:
                cnt += len(G)-ind1-1
    elif Gon[i]==1:
        #GBR
        indg = i
        ind0 = bisect_right(B,indg)
        for j in range(ind0,len(B)):
            indb = B[j]
            ind1 = bisect_right(R,indb)
            if 2*indb-indg>R[-1] or Ron[2*indb-indg]==0 or Ron[2*indb-indg]==1 and 2*indb-indg<R[ind1]:
                cnt += len(R)-ind1
            else:
                cnt += len(R)-ind1-1
        #GRB
        ind0 = bisect_right(R,indg)
        for j in range(ind0,len(R)):
            indr = R[j]
            ind1 = bisect_right(B,indr)
            if 2*indr-indg>B[-1] or Bon[2*indr-indg]==0 or Bon[2*indr-indg]==1 and 2*indr-indg<B[ind1]:
                cnt += len(B)-ind1
            else:
                cnt += len(B)-ind1-1
    elif Bon[i]==1:
        #BRG
        indb = i
        ind0 = bisect_right(R,indb)
        for j in range(ind0,len(R)):
            indr = R[j]
            ind1 = bisect_right(G,indr)
            if 2*indr-indb>G[-1] or Gon[2*indr-indb]==0 or Gon[2*indr-indb]==1 and 2*indr-indb<G[ind1]:
                cnt += len(G)-ind1
            else:
                cnt += len(G)-ind1-1
        #BGR
        ind0 = bisect_right(G,indb)
        for j in range(ind0,len(G)):
            indg = G[j]
            ind1 = bisect_right(R,indg)
            if 2*indg-indb>R[-1] or Ron[2*indg-indb]==0 or Ron[2*indg-indb]==1 and 2*indg-indb<R[ind1]:
                cnt += len(R)-ind1
            else:
                cnt += len(R)-ind1-1
print(cnt)

Submission status: Runtime Error

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

RN = S.count('R')
GN = S.sount('G')
BN = S.count('B')

ans = RN * GN * BN

for i in range(N):
    for d in range(N):
        j = i + d
        k = i + 2 * d
        if k >= N:
            break
        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:
import itertools
N = int(input())
S = input()
C = np.array(list(itertools.combinations_with_replacement(range(1, N + 1), 3)))
count = 0
for i, j, k in C:
    if (i != 2 * j - k) and (S[i - 1] != S[j - 1] and S[i - 1] != S[k - 1] and S[j - 1] != S[k - 1]):
        count += 1
print(count)

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
 from collections import Counter
N = int(input())
S = input()
#c = Counter(S)
#print (c.most_common())
#ls = list(c.values())
ans = S.count('R') * S.count('G') * S.count('B')


for i in range(N):
    for j in range(1,N):
        a = i + j
        b = i + j + j
        if (b >= N):
            break
        else:
            l = S[i]
            m = S[a]
            r = S[b]
            if l!=m and m!=r and r!=l:
                ans -= 1
        # if (i-j<0 or i+j>=N):
        #     break
        # l = S[i-j]
        # m = S[i]
        # r = S[i+j]
        # if l!=m and m!=r and r!=l:
        #     ans -= 1
print (ans)

Submission status: Runtime Error

Solution code:
def main():
    N = int(input())
    S = input()
    r_ind = []
    g_ind = []
    d_ind = []
    for i,s in enumerate(S):
        if s == "R":
            r_ind.append
        if s == "G":
            g_ind.append
        if s == "B":
            b_ind.append 
    d = len(r_ind)*len(g_ind)*len(b_ind)

    temp = 0
    for i in r_ind:
        for j in g_ind:
            for k in b_ind:
                maxid = max(i,j,k)
                minid = min(i,j,k)
                if i+j+k == (maxid+minid)*3/2:
                    temp +=1
    ans = d-temp
    print(ans)

main()

Submission status: Runtime Error

Solution code:
def main():
    N = int(input())
    S = input()
    r_ind = []
    g_ind = []
    d_ind = []
    for i,s in enumerate(S):
        if s = "R":
            r_ind.append
        if s = "G":
            g_ind.append
        if s = "B":
            b_ind.append 
    d = len(r_ind)*len(g_ind)*len(b_ind)

    temp = 0
    for i in r_ind:
        for j in g_ind:
            for k in b_ind:
                maxid = max(i,j,k)
                minid = min(i,j,k)
                if i+j+k == (maxid+minid)*3/2:
                    temp +=1
    ans = d-temp
    print(ans)

main()

Submission status: Runtime Error

Solution code:
print(sum([x for x in range(a,int(input())+1) if (x%3!=0)and(x%5!=0)]))

Submission status: Runtime Error

Solution code:
import numpy as np

def main():
    N = int(input())
    S = input()
    R,G,B = [],[],[]
    for i in range(N):
        if S[i]=="R":
            R.append(i)
        elif S[i] == "G":
            G.append(i)
        else:
            B.append(i)
    ans = len(R)*len(G)*len(B)
    rr,gg,bb = np.meshgrid(np.array(R),np.array(G),np.array(B))
    rgb = np.c_[rr.flatten(),gg.flatten(),bb.flatten()]
    a1,a2,a3 = np.hsplit(rgb,3)
    b1,b2,b3 = np.abs(a3-a2),np.abs(a2-a1),np.abs(a1-a3)
    t1,t2,t3 = b1==b2,b2==b3,b3==b1
    s = np.count_nonzero(t1) + np.count_nonzero(t2) + np.count_nonzero(t3)
    print(ans-s)

main()

Submission status: Runtime Error

Solution code:
import collections
N=int(input())
S=input()
lis=list(S)
C= collections.Counter(lis)
count=list(C.values())
c=0
for i in range(N):
    for j in range(i,(N+i-1) // 2+1):
        if(lis[i]!=lis[j]):
            if(lis[j]!=lis[2*j-i]):
                if(lis[i]!=lis[2*j-i]):
                    c+=1
print(count[0]*count[1]*count[2]-c)

Submission status: Runtime Error

Solution code:
import collections
N=int(input())
S=input()
lis=list(S)
C= collections.Counter(lis)
count=list(C.values())
c=0
for i in range(N):
    print(i)
    for j in range(i,(N+i-1) // 2+1):
        if(lis[i]!=lis[j]):
            if(lis[j]!=lis[2*j-i]):
                if(lis[i]!=lis[2*j-i]):
                    c+=1
print(count[0]*count[1]*count[2]-c)

Submission status: Runtime Error

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

import itertools

counta = 0

R = []
G = []
B = []

for i, x in enumerate(S):
    if x == 'R':
        R.append(i)
    elif x == 'G':
        G.append(i)
    else:
        B.append(i)

print(len([0 for i in itertools.product(R, G, B) if sorted(i)[1] != ave(i)]))

Submission status: Runtime Error

Solution code:
N=int(input())
K=input()
dic = {}
for t in ts:
    p=[]
    for ir, r in enumerate(K):
        if r == t:
            p.append(ir)
    dic[t] = p
ans1 = len(dic['R']) * len(dic['G']) * len(dic['B'])

ans2 = 0

for i in range(N):
    for j in range(i):
        if (i + 2*(j-i) < N):
            if  K[i] != K[j] and K[i] != K[i + 2*(j-i)] and K[i+2*(j-i)] != K[j]:
                ans2 +=1

print(ans1 - ans2)

Submission status: Runtime Error

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

num_r, num_g = S.count('R'), S.count('G')
num_b = N - num_r - num_g
max_ans = num_r * num_g * num_b
count_not_ans = 0

for i in range(N-2):
    for j in range(i+1, N-1):
        k = 2 * j - i
        si, sj, sk = S[i], S[j], S[k]
        if (0 <= k <= N-1) and si != sj and sj != sk and sk != si:
            count_not_ans += 1

print(max_ans - count_not_ans)

Submission status: Runtime Error

Solution code:
N = int(input())
S = list(map(str, input()))
f=0
i_c = j_c = k_c =1
ijk = list()
for i in range(N):
    for j in range(N):
        for k in range(N):
            if(k_c>j_c and j_c>i_c):
                if(j_c-i_c!=k_c-j_c):
                    ijk.append([i,j,k])
            k_c+=1
        j_c+=1
        k_c = 1
    i_c+=1
    j_c = 1
S_i = ijk[i][0]
S_j = ijk[i][1]
S_k = ijk[i][2]
for i in range(len(ijk)):
    if(S[ijk[i][0]]!= S[ijk[i][1]] and
       S[ijk[i][0]]!= S[ijk[i][2]] and
       S[ijk[i][1]]!= S[ijk[i][2]]):
       f+=1
print(f)

Submission status: Runtime Error

Solution code:
n=int(input())
l=list(map(str,input()))
i=0
while 0<=i and i<=n-3:
    
    if l[i]=='R':
        j=i+1
        while i+1<=j and j<=n-2:
            if l[j]=='R':
                j+=1
            else:
                k=j+1
                while j+1<=k and k<=n-1 and k-j!=j-i:
                    if l[k]!=l[j]:
                        count+=1
                        k+=1
                    else:
                        k+=1
                j+=1
        i+=1
    if l[i]=='G':
        j=i+1
        while i+1<=j and j<=n-2:
            if l[j]=='G':
                j+=1
            else:
                k=j+1
                while j+1<=k and k<=n-1 and k-j!=j-i:
                    if l[k]!=l[j]:
                        count+=1
                        k+=1
                    else:
                        k+=1
                j+=1
        i+=1
    if l[i]=='B':
        j=i+1
        while i+1<=j and j<=n-2:
            if l[j]=='B':
                j+=1
            else:
                k=j+1
                while j+1<=k and k<=n-1 and k-j!=j-i:
                    if l[k]!=l[j]:
                        count+=1
                        k+=1
                    else:
                        k+=1
                j+=1
        i+=1
print(count)

Submission status: Runtime Error

Solution code:
n = int(input())
s = input()
a = s.count("R")
b = s.count("G")
c = s.count("B")
z = a*b*c
if z ==0:
  print(0)
else:
  R=[]
  G=[]
  B=[]
  for i in range(n):
    if s[i]=="R":
      R.append(i)
    elif s[i]=="G":
      G.append(i)
    else:
      B.append(i)
  x = 0
  for i in R:
    for j in G:
      if 0 <= 2*j-i <= n-1 and s[2*j-i]=="B":
        x+=1
      if 0 <= 2*i-j <= n-1 and s[2*i-j]=="B":
        x+=1
      if (i+j)%2==0 and s[(i+j)//2]=="B":
        x+=1
print(z-x)

Submission status: Runtime Error

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

count = 0

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

Submission status: Runtime Error

Solution code:
from collections import Counter

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

Submission status: Runtime Error

Solution code:
a=int(input())
b=str(input())
sum=0

riron_sum=b.count('R')*sum=b.count('G')*sum=b.count('B')
for i in range(1,a):
    for n in range(1,i):
        if i+n>N:
            j = i+d
            k = j+d
            if b[i]!=b[j] and b[j]!=b[k] and b[k]!=b[i]:
                riron_sum-=1

print(riron_sum)

Submission status: Runtime Error

Solution code:
import numpy as np
N = int(input())
S = input()
R,G,B = [],[],[]
for i in range(N):
    if S[i]=="R":
        R.append(i)
    elif S[i] == "G":
        G.append(i)
    else:
        B.append(i)
ans = len(R)*len(G)*len(B)
R = np.array(R)
G = np.array(G)
B = np.array(B)
rr,gg,bb = np.meshgrid(R,G,B)
rgb = np.c_[rr.flatten(),gg.flatten(),bb.flatten()]
a1,a2,a3 = np.hsplit(rgb,3)
t1 = np.abs(a3-a2) == np.abs(a2-a1)
t2 = np.abs(a3-a1) == np.abs(a2-a1)
t3 = np.abs(a3-a2) == np.abs(a3-a1)
s = np.count_nonzero(t1) + np.count_nonzero(t2) + np.count_nonzero(t3)
print(ans-s)

Submission status: Runtime Error

Solution code:
import itertools

counta = 0
i = 0

R = []
G = []
B = []

for i, x in enumerate(S):
    if x == 'R':
        R.append(i)
    elif x == 'G':
        G.append(i)
    else:
        B.append(i)

for i in itertools.product(R, G, B):
    j = sorted(list(i))
    if j[2] - j[1] != j[1] - j[0]:
        counta += 1
print(counta)

Submission status: Runtime Error

Solution code:
import numpy as np
np.set_printoptions(threshold=np.inf)
N = int(input())
S = input()
R,G,B = [],[],[]
for i in range(N):
    if S[i]=="R":
        R.append(i)
    elif S[i] == "G":
        G.append(i)
    else:
        B.append(i)
ans = len(R)*len(G)*len(B)
R = np.array(R)
G = np.array(G)
B = np.array(B)
rr,gg,bb = np.meshgrid(R,G,B)
rgb = np.c_[rr.flatten(),gg.flatten(),bb.flatten()]
a1,a2,a3 = np.hsplit(rgb,3)
t1 = np.abs(a3-a2) == np.abs(a2-a1)
t2 = np.abs(a3-a1) == np.abs(a2-a1)
t3 = np.abs(a3-a2) == np.abs(a3-a1)
s = np.count_nonzero(t1) + np.count_nonzero(t2) + np.count_nonzero(t3)
print(ans-s)

Submission status: Runtime Error

Solution code:
    N = int(input())
    S = input()
     
    R_list = []
    G_list = []
    B_list = []
    cnt = 0
     
    for i, s in enumerate(S):
        if s == "R":
            R_list.append(i)
        elif s == "G":
            G_list.append(i)
        else:
            B_list.append(i)
            
    for r in R_list:
        for g in G_list:
            for b in B_list:
                if (r + g + b) not in [3*r, 3*g, 3*b]:
                    cnt += 1
     
    print(str(cnt))

Submission status: Runtime Error

Solution code:
S = input()
count = 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[k] == S[i]) or ( S[k] == S[j]) or ( j-i == k-j):
                continue
            count+= 1
print(count)

Submission status: Runtime Error

Solution code:
N = int(input())
S = input()
d = dict()
for n in range(N):
    d.setdefault(S[n], []).append(n)
ans = len(d['R']) * len(d['G']) * len(d['B'])
q = (N - 3) // 2
for qq in range(q + 1):
    for i in range(N - (qq * 2 + 3) + 1):
        j = i + qq + 1
        k = j + qq + 1
        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:
N = int(input())
S = str(input())
count = 0

Rlist = list()
Blist = list()
Glist = list()

for i in range(1, len(S)):
    if S[i] == "R":
        Rlist.append(i + 1)
    elif S[i] == "G":
        Glist.append(i + 1)
    else:
        Blist.append(i + 1)

for i in range(len(Rlist)):
    for j in range(i, len(Blist)):
        for k in range(j, len(Glist)):
            a = [Rlist[i], Blist[j], Glist[k]].sort()
            if a[1] - a[0] != a[2] - a[1]:
                count += 1


print(count)