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: Wrong Answer

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

import numpy as np

def なんか(a,b,c):
    ans=0
    for i in a:
        tmp_b = b[b>i]
        for j in tmp_b:
            if j+j-i in c:
                ans+=len(c[(c>j)])-1
            else:
                ans+=len(c[(c>j)])
        tmp_c = c[c>i]
        for j in tmp_c:
            if j+j-i in b:
                ans+=len(b[(b>j)])-1
            else:
                ans+=len(b[(b>j)])
    return ans
  

r1=[]
b1=[]
g1=[]

for i, v in enumerate(s):
    if v=="R":
        r1+=[i]
    elif v=="B":
        b1+=[i]
    else:
        g1+=[i]
        
r1 = np.array(r1)
b1 = np.array(b1)
g1 = np.array(g1)

print(なんか(r1, g1, b1)+なんか(g1, b1, r1)+なんか(b1,r1,g1))

Submission status: Wrong Answer

Solution code:
from math import gcd
from functools import reduce

s = 0
n = int(input())
for i in range(1, n+1):
    for j in range(1, n+1):
        for k in range(1, n+1):
            s = s + int(reduce(gcd, (i, j, k)))
print(s)

Submission status: Wrong Answer

Solution code:
import math
import sys
import collections
def main():
    N=int(input())
    Tr=tuple(input())
    R=[]
    G=[]
    B=[]
    for i in range(N):
       if Tr[i]=="R":
           R.append(i)
       if Tr[i]=="G":
           G.append(i)
       if Tr[i]=="B":
           B.append(i)
    cnt=0
    if len(R)==max(len(R),len(G),len(B)):
        for i in B:
            for j in G:
                for k in R:
                    if max(i,j,k)-(i+j+k-max(i,j,k)-min(i,j,k))!=(i+j+k-max(i,j,k)-min(i,j,k))-min(i,j,k):
                        cnt+=1

        print(cnt)
    if len(G) == max(len(R), len(G), len(B)):
        for i in B:
            for j in R:
                for k in G:
                    if max(i, j, k) - (i + j + k - max(i, j, k) - min(i, j, k)) != (
                            i + j + k - max(i, j, k) - min(i, j, k)) - min(i, j, k):
                        cnt += 1

        print(cnt)
    if len(B) == max(len(R), len(G), len(B)):
        for i in R:
            for j in G:
                for k in B:
                    if max(i, j, k) - (i + j + k - max(i, j, k) - min(i, j, k)) != (
                            i + j + k - max(i, j, k) - min(i, j, k)) - min(i, j, k):
                        cnt += 1

        print(cnt)



if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import collections
N = int(input())
S = input()
temp_list = []
minus = 0
for i in range(0, N-2):
    for j in range(1, N-2):
        if i+j*2 >= N:
            break
        temp_list.append([i, i+j, i+j+j])


for temp in temp_list:
    if S[temp[0]] != S[temp[1]]:
        if S[temp[0]] != S[temp[2]]:
            if S[temp[1]] != S[temp[2]]:
                minus += 1

count_dict = collections.Counter(S)
print(count_dict["R"]*count_dict["G"]*count_dict["B"]-minus)

Submission status: Wrong Answer

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

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

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

counter = r_cnt * g_cnt * b_cnt

for i in range(n):
    for p in range(n):
        j = i + p
        k = j + p
        if k >= n:
            break
        if s[i] != s[j] and s[i] != s[j] and s[i] != s[j]:
            counter -= 1
print(counter)

Submission status: Wrong Answer

Solution code:
from collections import Counter

N = int(input())
S = input()
dum = []
mmm = []
d = 0
while 3 + d*2 < N:
    for i in range(N - 2*(d+1)):
        dum.append([S[i], S[i+d+1], S[i+2*(d+1)]])
        mmm.append([i, i+d+1, i+2*(d+1)])
    d += 1
dum_n = len([x for x in dum if len(set(x)) == 3])

RGB_Counter = Counter(S)
print(RGB_Counter['R'] * RGB_Counter['G'] * RGB_Counter['B'] -dum_n)

Submission status: Wrong Answer

Solution code:
import sys
import re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce


def input(): return sys.stdin.readline().strip()


def INT(): return int(input())


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


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


def ZIP(n): return zip(*(MAP() for _ in range(n)))


sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7


def main():
    n = INT()
    s = list(input())

    if n < 4:
        print(0)
        exit()

    ans = 0

    rgb = ['R', 'G', 'B']

    for i in range(n-2):
        for k in range(i+2, n):
            if (i+k) % 2 != 0 and s[i] != s[k]:
                lis = s[i:k]
                lis_l = len(lis)
                temp = lis_l - lis.count(s[i]) - lis.count(s[k])
                ans += temp

    print(ans)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
n = int(input())
s = input()
c = [0, 0, 0]
col1 = []
col2 = []
col3 = []
res = 0

for i in range(n):
    if s[i] == "R":
        col1.append(i)
    elif s[i] == "G":
        col2.append(i)
    else:
        col3.append(i)

res = len(col1) * len(col2) * len(col3)

for i in range((n - 2) // 2):
    for j in range(n - (i + 1) * 2):
        x = s[j]
        y = s[j + i + 1]
        z = s[j + (i + 1) * 2]
        if x == y or y == z or x == z:
            continue
        else:
            res = res - 1

print(res)

Submission status: Wrong Answer

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

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

# リストを作成
for i in range(0,N):
  if S[i]=="R":
    R += [i]
  elif S[i]=="G":
    G += [i]
  else:
    B += [i]

def search(ind, col):
  n=0
  useable_col = ["R","G","B"]
  useable_col.remove(col)
  for i,j in [[0,1],[1,0]]:
    l_col=useable_col[i]
    r_col=useable_col[j]
    if l_col=="R":
      l_col=R
    elif l_col=="G":
      l_col=G
    else:
      l_col=B
    if r_col=="R":
      r_col=R
    elif r_col=="G":
      r_col=G
    else:
      r_col=B
    
    l_useable = [] 
    r_useable = [] 
    for ii in l_col:
      if ii<ind:
        l_useable += [ii]
      else:
        break
    if l_useable == []:
      continue
    for ii in r_col:
      if ii>ind:
        r_useable += [ii]
      else:
        break
    if r_useable == []:
      continue

    # print(l_useable)
    # print(r_useable)
    l = min(ind, N-1-ind)
    for m in range(1,l+1):
      if ind-m in l_useable and ind+m in r_useable:
        n -= 1
    n += len(l_useable) * len(r_useable)
    # print(len(l_useable))
    # print(len(r_useable))
  return n

n=0
for pivot in range(1,N-1):
  if S[pivot] =="R":
    n += search(pivot, "R")
  elif S[pivot] =="G":
    n += search(pivot, "G")
  else:
    n += search(pivot, "B")

print(n)

Submission status: Wrong Answer

Solution code:
import collections

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

dic = collections.Counter(S)

# RGBの選び方
cnt = 1
for k, v in dic.items():
    cnt *= v

if v == 0:
    print(0)
else:
    for j in range(1, N - 1):
        mm = min(j, N - j - 1)
        for d in range(1, mm + 1):
            if S[j - d] != S[j] and S[j] != S[j + d] and S[j - d] != S[j + d]:
                cnt -= 1

    print(cnt)

Submission status: Wrong Answer

Solution code:
# これは, u749194f さんの改造です。
# オリジナルではございません。
# https://atcoder.jp/contests/abc162/submissions/11825963
n = int(input())
s = input()
flag = True
if len(set(s))<=2:
    print(0)
    flag = False
if flag:
    r = [i+1 for i in range(n) if s[i]=='R']
    b = [i+1 for i in range(n) if s[i]=='B']
    g = [i+1 for i in range(n) if s[i]=='G']
    minus = 0
    def cnt_cmb(a, b, c):
        cnt = 0
        for i in a:
            for j in b:
                if (i+j)//2 in c:
                    cnt += 1
        return cnt
    minus += cnt_cmb(r, b, g)
    minus += cnt_cmb(b, g, r)
    minus += cnt_cmb(g, r, b)
    print(len(r)*len(b)*len(g)-minus)

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(10**6)
from math import floor,ceil,sqrt,factorial,log
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict,deque
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from copy import deepcopy
from operator import itemgetter
from fractions import gcd
mod = 10 ** 9 + 7
inf = float('inf')
ninf = -float('inf')
 
#整数input
def ii(): return int(sys.stdin.readline().rstrip()) #int(input())
def mii(): return map(int,sys.stdin.readline().rstrip().split())
def limii(): return list(mii()) #list(map(int,input().split()))
def lin(n:int): return [ii() for _ in range(n)]
def llint(n: int): return [limii() for _ in range(n)]
#文字列input
def ss(): return sys.stdin.readline().rstrip() #input()
def mss(): return sys.stdin.readline().rstrip().split()
def limss(): return list(mss()) #list(input().split())
def lst(n:int): return [ss() for _ in range(n)]
def llstr(n: int): return [limss() for _ in range(n)]

#本当に貪欲法か？ DP法では？？
#本当に貪欲法か？ DP法では？？
#本当に貪欲法か？ DP法では？？

n=ii()
s=list(ss())
rarr = []
garr=[]
barr=[]

for i in range(n):
    if s[i]=="R":
        rarr.append(i)
    elif s[i]=="G":
        garr.append(i)
    else:
        barr.append(i)

#組み合わせ全通り
ans=len(rarr)*len(barr)*len(garr)

#[0, 2, 5, 11, 12, 16, 17, 18, 23, 27, 31] 11
#[4, 7, 8, 13, 20, 21, 25, 29, 35] 9
#[1, 3, 6, 9, 10, 14, 15, 19, 22, 24, 26, 28, 30, 32, 33, 34, 36, 37, 38] 19

for r in rarr:
    for b in barr:
        #GRB
        if r-b >0 and (r + r-b in garr):
            ans-=1
        #GBR
        elif b-r >0 and (b + b-r in garr):
            ans-=1
        #RGB BGR
        elif r-b >0 and (r-b)%2==0 and b+((r-b)//2) in garr:
            ans-=1
        elif b-r >0 and (b-r)%2==0 and r+((b-r)//2) in garr:
            ans-=1
        #RBG
        elif r-b>0 and r-b in garr:
            ans-=1
        elif b-r>0 and b-r in garr:
            ans-=1
print(ans)

Submission status: Wrong Answer

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

RGBs = []
count = 0
RGBs.append({"value": S[0], "left_R": 0, "left_G": 0, "left_B": 0})

for i in range(1, N):
    new = S[i]
    for j in range(i):
        if (S[j] == 'G' and new == 'B') or (S[j] == 'B' and new == 'G'):
            count += RGBs[j]["left_R"] - int(S[j - (i - j)] == 'R')

        elif (S[j] == 'R' and new == 'B') or (S[j] == 'B' and new == 'R'):
            count += RGBs[j]["left_G"] - int(S[j - (i - j)] == 'G')

        elif (S[j] == 'R' and new == 'G') or (S[j] == 'G' and new == 'R'):
            count += RGBs[j]["left_B"] - int(S[j - (i - j)] == 'B')

    tmp_left_R = RGBs[i - 1]["left_R"]
    tmp_left_G = RGBs[i - 1]["left_G"]
    tmp_left_B = RGBs[i - 1]["left_B"]
    if S[i - 1] == 'R':
        tmp_left_R += 1
    elif S[i - 1] == 'G':
        tmp_left_G += 1
    elif S[i - 1] == 'B':
        tmp_left_B += 1
    RGBs.append({"value": S[i], "left_R": tmp_left_R, "left_G": tmp_left_G, "left_B": tmp_left_B})

print(count)

Submission status: Wrong Answer

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

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

# リストを作成
for i in range(0,N):
  if S[i]=="R":
    R += [i]
  elif S[i]=="G":
    G += [i]
  else:
    B += [i]

def search(ind, col):
  n=0
  useable_col = ["R","G","B"]
  useable_col.remove(col)
  for i,j in [[0,1],[1,0]]:
    l_col=useable_col[i]
    r_col=useable_col[j]
    if l_col=="R":
      l_col=R
    elif l_col=="G":
      l_col=G
    else:
      l_col=B
    if r_col=="R":
      r_col=R
    elif r_col=="G":
      r_col=G
    else:
      r_col=B
    
    l_useable = [] 
    r_useable = [] 
    for ii in range(len(l_col)):
      if ii<ind:
        l_useable += [ii]
      else:
        break
    if l_useable == []:
      continue
    for ii in range(len(r_col)):
      if ii>ind:
        r_useable += [ii]
      else:
        break
    if r_useable == []:
      continue

    # print(l_useable)
    # print(r_useable)
    l = min(ind, N-1-ind)
    for m in range(1,l+1):
      if ind-m in l_useable and ind+m in r_useable:
        n -= 1
    n += len(l_useable) * len(r_useable)
    # print(len(l_useable))
    # print(len(r_useable))
  return n

n=0
for pivot in range(1,N-1):
  if S[pivot] =="R":
    n += search(pivot, "R")
  elif S[pivot] =="G":
    n += search(pivot, "G")
  else:
    n += search(pivot, "B")

print(n)

Submission status: Wrong Answer

Solution code:
import collections

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

dic = collections.Counter(S)

# RGBの選び方
cnt = 1
for k, v in dic.items():
    cnt *= v

for j in range(1, N - 1):
    mm = min(j, N - j - 1)
    for d in range(1, mm + 1):
        if S[j - d] != S[j] and S[j] != S[j + d] and S[j - d] != S[j + d]:
            cnt -= 1

print(cnt)

Submission status: Wrong Answer

Solution code:
N = int(input())
S = input()
r = []
g = []
b = []
for idx, i in enumerate(S, 1):
    if i == 'R':
        r.append(idx)
    elif i == 'G':
        g.append(idx)
    else:
        b.append(idx)

b = set(b)
cnt = len(b) * len(r) * len(g)
if cnt == 0:
    print(0)
    exit()

for j in g:
    for i in r:
        if i > j:
            i, j = j, i
        d = j - i
        if j + d in b:
            cnt -= 1
        if i - d in b:
            cnt -= 1
        if d % 2 == 0 and (i + j) // 2 in b:
            cnt -= 1
print(cnt)

Submission status: Wrong Answer

Solution code:
n=int(input())
s=input()
r,g,b=0,0,0
for i in range(n):
    if s[i]=="R":
        r+=1
    elif s[i]=="G":
        g+=1
    else:
        b+=1
chohuku=0
double=0
for i in range(1,n-1):
    for j in range(1,min(i+1,n-i)):
        chohuku+=1
        k=j+i
        l=i-j
        if s[i]!=s[k] and s[i]!=s[l] and s[l]!=s[k]:
            double+=1
ans=r*g*b-double
print(r,g,b,ans)

Submission status: Wrong Answer

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]
            b = Blist[j]
            c = Glist[k]
            if a - b != b - c:
                count += 1


print(count)

Submission status: Wrong Answer

Solution code:
#200412D
N = int(input())
S = str(input())

Ans=0
for i in range(N-2):
    for j in range(N-i-2):
        for k in range(N-j-i-3):
            if i+j != i + i + j + k + 2:
                if S[i+1] != S[j+i+2]:
                    if S[i+1] != S[i+j+k+3]:
                        Ans += 1
print(int(Ans))

Submission status: Wrong Answer

Solution code:
n=int(input())
s=input()
r,g,b=0,0,0
for i in range(n):
    if s[i]=="R":
        r+=1
    elif s[i]=="G":
        g+=1
    else:
        b+=1
chohuku=0
double=0
for i in range(1,n-1):
    for j in range(1,min(i+1,n-1-i)):
        chohuku+=1
        k=j+i
        l=i-j
        if s[i]==s[k] or s[i]==s[l] or s[l]==s[k]:
            double+=1
ans=r*g*b-double
print(ans)

Submission status: Wrong Answer

Solution code:
print(0)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
N=int(input())
S=str(input())
S=list(S)
a=0
if 1<=N<=4000:
    if N<=3:
        print(0)
    else:
        i=0
        j=1
        k=2
        for k in range(2,N):
            for j in range(1,k):
                for i in range(0,j):
                    if (S[i]==S[j])or(S[j]==S[k]):
                        continue
                    else:
                        if j-i==k-j:
                            continue
                        else:
                            a+=1
                    i+=1
                j+=1
            k+=1
        print(a)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
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)
    
count = 0

for r in R:
  for g in G:
    for b in B:
      S = sorted([r,g,b])
      if S[0]+S[2]!=2*S[1]:
        count += 1

Submission status: Wrong Answer

Solution code:
# n = int(input())
# s = list(input())
# r_pos = []
# g_pos = []
# b_pos = []
# for i in range(n):
#     st = s[i]
#     if st == "R":
#         r_pos.append(i)

#     if st == "G":
#         g_pos.append(i)

#     if st == "B":
#         b_pos.append(i)

# r_num = len(r_pos)
# g_num = len(g_pos)
# b_num = len(b_pos)
# #print(r_pos, g_pos, b_pos)
# ans = r_num * g_num * b_num

# for r in r_pos:
#     for g in g_pos:
#         for b in b_pos:
#             color = [r, g, b]
#             color.sort()
#             x = color[0]
#             y = color[1]
#             z = color[2]
#             if z - y == y - x:
#                 ans -= 1
# print(ans)

# -----------------------------------------------------
n = int(input())
s = list(input())
r_pos = []
g_pos = []
b_pos = []

for i in range(n):
    st = s[i]
    if st == "R":
        r_pos.append(i)

    if st == "G":
        g_pos.append(i)

    if st == "B":
        b_pos.append(i)

r_num = len(r_pos)
g_num = len(g_pos)
b_num = len(b_pos)

print(r_pos, g_pos, b_pos, r_num, g_num, b_num)


ans = r_num * g_num * b_num
for r in r_pos:
    for g in g_pos:
        x, y = min(r, g), max(r, g)

        dif = y - x
        left_pos = x - dif
        right_pos = y + dif
        mid_pos = 4000
        if dif % 2 == 0:
            mid_pos = x + dif // 2

        left = 0
        right = 0
        mid = 0
        if left_pos in b_pos:
            left = 1
        if right_pos in b_pos:
            right = 1
        if mid_pos in b_pos:
            mid = 1

        ans -= left + right + mid

print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
s = input()
ans = 0
for i in range(n):
    if s[i]=='R':
        aa = s[:i].count('G')
        ab = s[i+1:].count('B')
        if aa>0 and ab>0:
            ans += aa*ab
        bb = s[:i].count('B')
        bc = s[i+1:].count('G')
        if bb>0 and bc>0:
            ans += bb*bc
        for j in range(min(i,n-i)):
            if s[i-j]=='G' and s[i+j]=='B':
                ans -= 1
            if s[i-j]=='B' and s[i+j]=='G':
                ans -= 1
    if s[i]=='G':
        aa = s[:i].count('R')
        ab = s[i+1:].count('B')
        if aa>0 and ab>0:
            ans += aa*ab
        bb = s[:i].count('B')
        bc = s[i+1:].count('R')
        if bb>0 and bc>0:
            ans += bb*bc
        for j in range(min(i,n-i)):
            if s[i-j]=='R' and s[i+j]=='B':
                ans -= 1
            if s[i-j]=='B' and s[i+j]=='R':
                ans -= 1
    if s[i]=='B':
        aa = s[:i].count('G')
        ab = s[i+1:].count('R')
        if aa>0 and ab>0:
            ans += aa*ab
        bb = s[:i].count('R')
        bc = s[i+1:].count('G')
        if bb>0 and bc>0:
            ans += bb*bc
        for j in range(min(i,n-i)):
            if s[i-j]=='G' and s[i+j]=='R':
                ans -= 1
            if s[i-j]=='R' and s[i+j]=='G':
                ans -= 1
print(ans)

Submission status: Wrong Answer

Solution code:
n= int(input())
s_list= list(input())
r_list=[]
g_list=[]
b_list=[]
count=0
for i in range(0,n):
    if s_list[i]=="R":
        r_list.append(i)
    elif s_list[i]=="G":
        g_list.append(i)
    else:
        b_list.append(i)
print(r_list)
print(b_list)
print(g_list)
for pp in r_list:
    for qq in g_list:
        count=count+len(b_list)
        if (pp+qq)/2 in b_list:
            count=count-1
        elif 2*pp-qq in b_list:
            count=count-1
        elif 2*qq-pp in b_list:
            count=count-1
print(count)

Submission status: Wrong Answer

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

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

count = 0
for s in S:
    if s == "R":
        R.append(count)
    elif s == "G":
        G.append(count)
    elif s == "B":
        B.append(count)
    count += 1

def checker(i,E,F):
    wa =0
    EE = [x for x in E if x > i]
    FF = [x for x in F if x > i]
    for e in EE:
        sa = e-i
        eq = 0
        minu = 0
        for f in FF:
            if e > f:
                minu += 1
            if f - e > e-i:
                break
            if f-e == e-i:
                eq = 1
        if eq == 1:
            wa += len(FF)-1 -minu
        else:
            wa += len(FF) - minu

    return(wa)

goukei = 0
for i in range(N):
    s = S[i]
    if s == "R":
        goukei += checker(i,G,B)
    elif s == "G":
        goukei += checker(i,R,B)
    elif s == "B":
        goukei += checker(i,R,G)

print(goukei)

Submission status: Wrong Answer

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

ret = 0
R = list()
G = list()
B = list()
for i in range(len(S)):
    if S[i] == 'R':
        R.append(i)
    elif S[i] == 'G':
        G.append(i)
    elif S[i] == 'B':
        B.append(i)
l = [R,G,B]

for r in range(len(R)):
    for g in range(len(G)):
        for b in range(len(B)):
            if abs(R[r] - G[g]) != abs(B[b] - G[g]) and abs(R[r] - B[b]) != abs(B[b] - G[g]):
                ret += 1
print(ret)

Submission status: Wrong Answer

Solution code:
n = int(input())
s = input()
r=0
g=0
b=0
for i in range(n):
    if s[i]=="R":
        r += 1
    if s[i]=="G":
        g += 1
    if s[i]=="B":
        b += 1
all = r*g*b
for k in range(1,(n-1)//2):
    for l in range(n-2*k):
        if s[l] == s[l+k]  or s[l+(2*k)] == s[l] or s[l+k]==s[l+(2*k)]:
            pass
        else:
            all -= 1
print(all)

Submission status: Wrong Answer

Solution code:
n = int(input())
s = input()
res = 0
r = []
g = []
b = []
for i in range(n):
    if s[i] == 'R':
        r.append(i)
    if s[i] == 'G':
        g.append(i)
    if s[i] == 'B':
        b.append(i)
res = len(r)*len(g)*len(b)
for i in range(1,n+1):
    for k in range(i+2,n-i+1):
        if (i+k)%2 == 0:
            if s[i-1] != s[k-1] != s[(i+k)//2-1]:
                res -= 1
print(res)

Submission status: Wrong Answer

Solution code:
n = int(input())
s = list(input())
r = []
g = []
b = []
for i,j in enumerate(s):
    if j == "R":
        r.append(i)
    elif j == "G":
        g.append(i)
    else:
        b.append(i)
ans = 0
ss = [len(r),len(g),len(b)]
if max(ss) == len(b):
    for i in r:
        for j in g:
            sa = abs(i-j)
            if sa%2==0:
                p = (i+j)//2
                if p in b:
                    ans-=1
                    ans += len(b)
            if i<j:
                if (i-sa) in b:
                    ans -= 1
                if (j+sa) in b:
                    ans -= 1
            if i>j:
                if (j-sa) in b:
                    ans -= 1
                if (i+sa) in b:
                    ans -= 1
if max(ss) == len(g):
    for i in r:
        for j in b:
            sa = abs(i-j)
            if sa%2==0:
                p = (i+j)//2
                if p in g:
                    ans-=1
                    ans += len(g)
            if i<j:
                if (i-sa) in g:
                    ans -= 1
                if (j+sa) in g:
                    ans -= 1
            if i>j:
                if (j-sa) in g:
                    ans -= 1
                if (i+sa) in g:
                    ans -= 1
if max(ss) == len(r):
    for i in b:
        for j in g:
            sa = abs(i-j)
            if sa%2==0:
                p = (i+j)//2
                if p in r:
                    ans-=1
                    ans += len(r)
            if i<j:
                if (i-sa) in r:
                    ans -= 1
                if (j+sa) in r:
                    ans -= 1
            if i>j:
                if (j-sa) in r:
                    ans -= 1
                if (i+sa) in r:
                    ans -= 1

print(ans)

Submission status: Wrong Answer

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

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

print(count)

Submission status: Wrong Answer

Solution code:
from collections import *
from bisect import *
n = int(input())
s = input()
r = deque()
g = deque()
b = deque()
ans = 0

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

def cnt(x, y, z):
    global ans
    for i in x:
        index1 = bisect_left(y, i)
        if index1 <= len(y) - 1:
            for j in range(index1, len(y)):
                index2 = bisect_left(z, y[j])
                if index2 <= len(z) - 1:
                    if z[index2] == y[j] + i:
                        ans += len(z) - index2
                    else:
                        ans += len(z) - index2
cnt(r, g, b)
cnt(r, b, g)
cnt(g, r, b)
cnt(g, b, r)
cnt(b, r, g)
cnt(b, g, r)
print(ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter

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

c=Counter(s)

ans1=c['B']*c['R']*c['G']

for i in range(1,n//2):
  for j in range(i,n-i):
    right=s[j-i]
    middle=s[j]
    left=s[j+i]
    if right==middle or middle==left or left==right:
      ans1-=1
print(ans1)

Submission status: Wrong Answer

Solution code:
import collections

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

dic = collections.Counter(S)

# RGBの選び方
cnt = 1
for k, v in dic.items():
    cnt *= v

b_cnt = 0
for j in range(1, N - 1):
    mm = min(j, N - j - 1)
    for d in range(1, mm + 1):
        if S[j - d] != S[j] != S[j + d]:
            b_cnt -= 1

print(cnt + b_cnt // 2)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n = int(input())
s = input()
ans = 0
for i in range(n):
    if s[i]=='R':
        aa = s[:i].count('G')
        ab = s[i+1:].count('B')
        if aa>0 and ab>0:
            ans += aa+ab
        bb = s[:i].count('B')
        bc = s[i+1:].count('G')
        if bb>0 and bc>0:
            ans += bb+bc
        for j in range(min(i,n-i)):
            if s[i-j]=='G' and s[i+j]=='B':
                ans -= 1
            if s[i-j]=='B' and s[i+j]=='G':
                ans -= 1
    if s[i]=='G':
        aa = s[:i].count('R')
        ab = s[i+1:].count('B')
        if aa>0 and ab>0:
            ans += aa+ab
        bb = s[:i].count('B')
        bc = s[i+1:].count('R')
        if bb>0 and bc>0:
            ans += bb+bc
        for j in range(min(i,n-i)):
            if s[i-j]=='R' and s[i+j]=='B':
                ans -= 1
            if s[i-j]=='B' and s[i+j]=='R':
                ans -= 1
    if s[i]=='B':
        aa = s[:i].count('G')
        ab = s[i+1:].count('R')
        if aa>0 and ab>0:
            ans += aa+ab
        bb = s[:i].count('R')
        bc = s[i+1:].count('G')
        if bb>0 and bc>0:
            ans += bb+bc
        for j in range(min(i,n-i)):
            if s[i-j]=='G' and s[i+j]=='R':
                ans -= 1
            if s[i-j]=='R' and s[i+j]=='G':
                ans -= 1
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
str = input()
i, j, k = [], [], []
total = 0
for n in range(1, N+1):
    if str[n-1]=='R':
        i.append(n)
    elif str[n-1]=='G':
        j.append(n)
    else:
        k.append(n)

for I in i:
    for J in j:
        total += len(k) if not ((J*2-I in k) or (I*2-J in k) or ((I+J)//2 in k)) else len(k)-1
print(total)

Submission status: Wrong Answer

Solution code:
from itertools import combinations 
N = int(input())
S = str(input())
lst = [i for i in range(1, N+1)]
def findTriplets(lst, N): 
    triplt = list(combinations(lst, 3))
    print(triplt)
    for item in triplt:
        if ((item[1] - item[0]) != (item[2] - item[1])) and ((S[0] != S[1]) and (S[0] != S[2]) and (S[2] != S[1])):
            print(item[0])
print(findTriplets(lst, N))

Submission status: Wrong Answer

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

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

# リストを作成
for i in range(0,N):
  if S[i]=="R":
    R += [i]
  elif S[i]=="G":
    G += [i]
  else:
    B += [i]

def search(ind, col):
  n=0
  useable_col = ["R","G","B"]
  useable_col.remove(col)
  for i,j in [[0,1],[1,0]]:
    l_col=useable_col[i]
    r_col=useable_col[j]
    if l_col=="R":
      l_col=R
    elif l_col=="G":
      l_col=G
    else:
      l_col=B
    if r_col=="R":
      r_col=R
    elif r_col=="G":
      r_col=G
    else:
      r_col=B
        
    l_useable = [ii for ii in l_col if ii<ind]
    r_useable = [ii for ii in r_col if ii>ind]
    # print(l_useable)
    if (l_useable == []) or (r_useable == []):
      return 0

    # print(l_useable)
    # print(r_useable)
    l = min(ind, N-1-ind)
    for m in range(1,l+1):
      if ind-m in l_useable and ind+m in r_useable:
        n -= 1
    n += len(l_useable) * len(r_useable)
  return n

n=0
for pivot in range(1,N-1):
  if S[pivot] =="R":
    n += search(pivot, "R")
  elif S[pivot] =="G":
    n += search(pivot, "G")
  else:
    n += search(pivot, "B")

print(n)

Submission status: Wrong Answer

Solution code:
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 + 1, N - 1):
        if S[i] != S[j]:
            x = j + j - i
            if x <= N - 1 and S[i] != S[x]:
                ans -= 1

print(ans)