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:
import math
import string
import collections
from collections import Counter
from collections import deque
import sys
sys.setrecursionlimit(2*10**5)
INF = 2**60


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


def nCr(n, r):
    return math.factorial(n)//(math.factorial(n-r)*math.factorial(r))


def has_duplicates2(seq):
    seen = []
    for item in seq:
        if not(item in seen):
            seen.append(item)
    return len(seq) != len(seen)


def divisor(n):
    divisor = []
    for i in range(1, n+1):
        if n % i == 0:
            divisor.append(i)
    return divisor


# coordinates
dx = [-1, -1, -1, 0, 0, 1, 1, 1]
dy = [-1, 0, 1, -1, 1, -1, 0, 1]


N = int(input())
S = input()
r = []
g = []
b = []
for i in range(N):
    if S[i] == 'R':
        r.append(i+1)
    if S[i] == 'G':
        g.append(i+1)
    if S[i] == 'B':
        b.append(i+1)
# print(r)
# print(g)
# print(b)
c = [None]*N
for i in range(N):
    c[i] = [None]*N
cnt = 0
for i in range(len(r)):
    for j in range(len(g)):
        for k in range(len(b)):
            c[i][0] = r[i]
            c[i][1] = g[j]
            c[i][2] = b[k]
            #print(c[i][0], c[i][1], c[i][2])
            if c[i][1]-c[i][0] != c[i][2]-c[i][1]:
                cnt += 1

print(cnt)

Submission status: Wrong Answer

Solution code:
import bisect

def main():
    N = int(input())
    S = input()
    dict = {"R":[],"G":[],"B":[]}
    ans = 0
    for i in range(N):
        dict[S[i]].append(i)
    l = {"R" :len(dict["R"]),"G" :len(dict["G"]),"B" :len(dict["B"])}
    name = [["R","G","B"], ["R","B","G"], ["G","R","B"],["G","B","R"],["B","R","G"],["B","G","R"]]
    for n in name:
        a,b,c = n
        for i in dict[a]:
            p = bisect.bisect_left(dict[b],i+1)
            if p >= l[b]:
                continue
            for j in dict[b][p:]:
                q =  bisect.bisect_left(dict[c],j + 1)
                if bisect.bisect_left(dict[c],2 * j - i) + 2 == bisect.bisect_right(dict[c],2*j - i):
                    ans -= 1
                ans += len(dict[c][q:])

    print(ans-1)
if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
def chenge(x):
  if x == "R":
    return 0
  elif x == "G":
    return 1
  else:
    return 2

N = int(input())
S = list(map(chenge,input()))

ans = 0

for i in range(N-2):
  for j in range(i+1,N-1):
    if S[i] != S[j]:
      ans += S[j+1:].count(3-S[i]-S[j])

print(ans)

Submission status: Wrong Answer

Solution code:

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

count=0
for i in range(N):
    s_i = S[i]

    for j in range(i+1, N):
        s_j = S[j]

        for k in range(j+1, N):
            s_k = S[k]

            if s_i!=s_j and s_i!=s_k and j-i!=k-j:
                count+=1

print(count)

Submission status: Wrong Answer

Solution code:
n=int(input())
s=input()
r=[0]*n
b=[0]*n
g=[0]*n
cb=0
cg=0
cr=0
for i in range(n-1,-1,-1):
  if s[i]=='R':
    cr+=1
  elif s[i]=='G':
    cg+=1
  else:
    cb+=1
  r[i]=cr
  g[i]=cg
  b[i]=cb
  
fr=[0]*n
fb=[0]*n
fg=[0]*n
cb=0
cg=0
cr=0
for i in range(n):
  if s[i]=='R':
    cr+=1
  elif s[i]=='G':
    cg+=1
  else:
    cb+=1
  fr[i]=cr
  fg[i]=cg
  fb[i]=cb
  
p=0
for i in range(1,n-1):
  if s[i]=='B':
    p+=fg[i-1]*b[i+1]+fb[i-1]*g[i+1]
    j=i-1
    k=i+1
    while (j>-1 and k<n):
      if (s[j]=='G' and s[k]=='R' or s[j]=='R' and s[k]=='G'):
        p-=1
      j-=1
      k+=1
      
  if s[i]=='G':
    p+=fb[i-1]*r[i+1]+fr[i-1]*b[i+1]
    j=i-1
    k=i+1
    while (j>-1 and k<n):
      if (s[j]=='B' and s[k]=='R' or s[j]=='R' and s[k]=='B'):
        p-=1
      j-=1
      k+=1
      
  if s[i]=='R':
    p+=fb[i-1]*g[i+1]+fg[i-1]*b[i+1]
    j=i-1
    k=i+1
    while (j>-1 and k<n):
      if (s[j]=='B' and s[k]=='G' or s[j]=='G' and s[k]=='B'):
        p-=1
      j-=1
      k+=1
  
print(p)

Submission status: Wrong Answer

Solution code:
N = int(input())
S = input()
from collections import Counter

d = Counter(S)
tmp = 1
for k in d.values():
    tmp*=k
for j in range(1, N//2+1):
    for i in range(N):
        if (i+(j*2))>=N:
            break
        if set((S[i], S[i+j], S[i+(j*2)])) == set('RGB'):
#             print(i, i+j, i+(j*2))
            tmp-=1
print(tmp)

Submission status: Wrong Answer

Solution code:
N = int(input())
S = list(map(str,list(input())))
c = 0

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

print(c)

Submission status: Wrong Answer

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

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

for i,s in enumerate(S):
    if s == "R":
        R.append(i)
    if s == "G":
        G.append(i)
    if s == "B":
        B.append(i)

ans = 0

print(R)
print(G)
print(B)

for i in R:
    for j in G:
        for k in B:
            if i < j < k and j-i != k-j:
                ans += 1

for i in R:
    for j in B:
        for k in G:
            if i < j < k and j-i != k-j:
                ans += 1

for i in G:
    for j in R:
        for k in B:
            if i < j < k and j-i != k-j:
                ans += 1


for i in G:
    for j in B:
        for k in R:
            if i < j < k and j-i != k-j:
                ans += 1

for i in B:
    for j in G:
        for k in R:
            if i < j < k and j-i != k-j:
                ans += 1

for i in B:
    for j in R:
        for k in G:
            if i < j < k and j-i != k-j:
                ans += 1

print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import math
n = int(input())
s = input()
r_cnt = 0
g_cnt = 0
b_cnt = 0
for i in s:
    if i == 'R':
        r_cnt += 1
    elif i == 'G':
        g_cnt += 1
    elif i == 'B':
        b_cnt += 1
        
total = r_cnt*g_cnt*b_cnt

if n < 4:
    print(total)

if n == 4:
    for j in range(2):
        tmp = s[j]+s[j+1]+s[j+2]
        if (tmp == 'RGB') or (tmp == 'RBG') or (tmp == 'GBR') or (tmp == 'GRB') or (tmp == 'BRG') or (tmp == 'BGR'):
            total -= 1
            
    print(total)
else:
    for i in range(1,math.floor((len(s)-2)/2)+100):
        for j in range(n-2*i):
            tmp = s[j]+s[j+i]+s[j+2*i]
            if (tmp == 'RGB') or (tmp == 'RBG') or (tmp == 'GBR') or (tmp == 'GRB') or (tmp == 'BRG') or (tmp == 'BGR'):
                total -= 1
    print(total)

Submission status: Wrong Answer

Solution code:
K= int(input())
N = input()
count = 0
list1, list2, list3 = [], [], []
for ids, item in enumerate(N):
    if item == "R":
       list1.append((item, ids))
    elif item == "G":
         list2.append((item, ids))
    else:
        list3.append((item, ids))
for x in list1:
    for y in list2:
        for z in list3:
            if (y[1] - x[1] > 1) != z[1] - y[1]:
                count += 1
print(count)

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
N = int(input())
S = input()

R = []
G = []
B = []
ans = 0

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

def calc(a, b, c):
  lis = sorted([a, b, c])
  if lis[1] * 2 != lis[0] + lis[2]:
    return 1
  else:
    return 0
        
lis = [calc(r, g, b) for r in R for g in G for b in B]
print(sum(lis))

Submission status: Wrong Answer

Solution code:
N = 39
S = "RBRBGRBGGBBRRGBBRRRBGGBRBGBRBGBRBBBGBBB"

count=0

for index1, val1 in enumerate(S):
  for index2, val2 in enumerate(S[index1+1:]):
    if val1 != val2:
      count += sum([1 for index3, val3 in enumerate(S[index1+index2+2:]) if val3 not in [val1, val2] and index2 != index3])
          
print(count)

Submission status: Wrong Answer

Solution code:
# from math import factorial,sqrt,ceil
from itertools import permutations as permus
# from fractions import gcd
from collections import deque,Counter
import re
# from decimal import Decimal, getcontext
# # getcontext().prec = 1000
# # eps = Decimal(10) ** (-100)

# import numpy as np
# from scipy.sparse.csgraph import shortest_path, dijkstra, floyd_warshall, bellman_ford, johnson
# from scipy.sparse import csr_matrix

# strlist = "abcdefghijklmnopqrstuvwxyz"
N = int(input())
S = input()

Sset = Counter(S)
iter = permus(list("RGB")) 

total = Sset["R"]*Sset["G"]*Sset["B"]

Slen = len(S)
hikukazu = 0
for i in range(Slen):
    for num in range(1,Slen//2):
        j = i+num
        k = i+num*2
        if k>Slen-1:
            break
        if S[i]!=S[j] and S[i]!=S[k] and S[k]!=S[j]:
            hikukazu += 1

ans = total - hikukazu
print(ans)
# print(*ans)   # unpackして出力。間にスペースが入る
# for row in board:
#     print(*row,sep="")    #unpackして間にスペース入れずに出力する
# print("{:.10f}".format(ans))
# print("{:0=10d}".format(ans))

Submission status: Wrong Answer

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

r_ary = []
g_ary = []
b_ary = []
index = 0
for i in (s):
    #print(i)
    if i == 'R':
        r_ary.append(index)
    elif i == 'G':
        g_ary.append(index)
    elif i == 'B':
        b_ary.append(index)
    index +=1
'''
print(r_ary)
print(g_ary)
print(b_ary)
print(len(r_ary))
print(len(g_ary))
print(len(b_ary))
'''
counta = 0
#exit()
for r in range(len(r_ary)):
    for g in range(len(g_ary)):
        if r_ary[r] < g_ary[g]:
            for b in range(len(b_ary)):
                if g_ary[g] < b_ary[b]:
                    #print(r_ary[r],g_ary[g],b_ary[b])
                    if g_ary[g] - r_ary[r] != b_ary[b] - g_ary[g]:
                        counta += 1
print(counta)
'''
8
RBGRBGRB
'''

Submission status: Wrong Answer

Solution code:
import re
a=int(input())
b=str(input())
sum=0
c=b
d=b
i=0
for s in b:
    if s=="R":
        if a>=i:

            for n in range(i,a):
                if c[n]=="G":
                    j=n-i
                    if a>=n:

                        for m in range(n,a):

                            if c[m]=="B":
                                k=m-n

                                if k!=j:

                                    sum+=1


    i+=1
print(sum)

Submission status: Wrong Answer

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 = 0


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

Submission status: Wrong Answer

Solution code:
N=input()
S={"R":[],"G":[],"B":[]}
for i,s in enumerate(input()):
	S[s].append(i)
print(len(S["R"])*len(S["G"])*len(S["B"])-1)

Submission status: Wrong Answer

Solution code:
import itertools
n=int(input())
num=[[i,j,k] for i,j,k in itertools.combinations(range(n),3) if (j-i)!=(k-j)]

s=input()
ans=0
for i,j,k in num:
    if s[i]!=s[j] and s[j]!=s[k]:
        ans+=1
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
S = input()
import itertools
from collections import Counter

C = itertools.combinations(S, 3)
d = Counter(S)
tmp = 1
for k in d.values():
    tmp*=k
for j in range(1, N//2+1):
    for i in range(N):
        if (i+(j*2))>=N:
            break
        if set((S[i], S[i+j], S[i+(j*2)])) == set('RGB'):
#             print(i, i+j, i+(j*2))
            tmp-=1
print(tmp)

Submission status: Wrong Answer

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

# N = 39
# S = 'RBRBGRBGGBBRRGBBRRRBGGBRBGBRBGBRBBBGBBB'

n_R = S.count('R')
n_G = S.count('G')
n_B = S.count('B')
ans = n_R * n_G * n_B

for a in range(N):
    # a = 2
    for b in range(1, N // 2):
        # b = 3
        i = a
        j = a + b
        k = a + 2 * b

        if k > N - 1:
            continue

        if S[i] != S[j] and S[j] != S[k] and S[k] != S[i]:
            ans -= 1
print(ans)

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)
        continue
    if S[i] == "G":
        G.append(i)
        continue
    B.append(i)

BN = len(B)

for i in R:
    for j in G:
        res += BN
        ii,jj = i,j
        if ii > jj:
            ii,jj = jj,ii
        if ii - (jj-ii) >= 0:
            if S[ii-(jj-ii)] == "B":
                res -= 1
        if (jj-ii) % 2 == 0:
            if S[(jj-ii) // 2] == "B":
                res -= 1
        if jj + (jj-ii) <= N-1:
            if S[jj+(jj-ii)] == "B":
                res -= 1
print(res)

Submission status: Wrong Answer

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

rc = s.count('R')
gc = s.count('G')
bc = s.count('B')

ans = rc*gc*bc

for i in range(n):
    if s[i] == 'R':
        for j in range(1,min(n-i-1, i-1)+1):
            if s[i-j] != s[i+j] and s[i-j] != 'R' and s[i+j] != 'R':
                ans -= 1
        for j in range(1,int((n-i-1)/2)+1):
            if s[i+2*j] != s[i+j] and s[i+2*j] != 'R' and s[i+j] != 'R':
                ans -= 1
        for j in range(1,int((i-1)/2)+1):
            if s[i-j] != s[i-2*j] and s[i-j] != 'R' and s[i-2*j] != 'R':
                ans -= 1

print(ans)

Submission status: Wrong Answer

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

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

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

main(R)

Submission status: Wrong Answer

Solution code:
from bisect import bisect_left
N = int(input())
S = list(input())
rix, gix, bix = [], [], []
lrc = [{} for _ in range(N)]
for i in range(N):
    c = S[i]
    lrc_d = lrc[i]
    if c == "R":
        rix.append(i)
        lrc_d["lg"] = 0
        lrc_d["rg"] = 0
        lrc_d["lb"] = 0
        lrc_d["rb"] = 0
    elif c == "G":
        gix.append(i)
        lrc_d["lr"] = 0
        lrc_d["rr"] = 0
        lrc_d["lb"] = 0
        lrc_d["rb"] = 0
    else:
        bix.append(i)
        lrc_d["lr"] = 0
        lrc_d["rr"] = 0
        lrc_d["lg"] = 0
        lrc_d["rg"] = 0
rl = len(rix)
gl = len(gix)
bl = len(bix)
# print(rix, gix, bix)
for ri in rix:
    lg = bisect_left(gix, ri)
    lb = bisect_left(bix, ri)
    lrc_d = lrc[ri]
    lrc_d["lg"] = lg
    lrc_d["rg"] = gl - lg
    lrc_d["lb"] = lb
    lrc_d["rb"] = bl - lb
for bi in bix:
    lr = bisect_left(rix, bi)
    lg = bisect_left(gix, bi)
    lrc_d = lrc[bi]
    lrc_d["lr"] = lr
    lrc_d["rr"] = rl - lr
    lrc_d["lg"] = lg
    lrc_d["rg"] = gl - lg
for gi in gix:
    lr = bisect_left(rix, gi)
    lb = bisect_left(bix, gi)
    lrc_d = lrc[gi]
    lrc_d["lr"] = lr
    lrc_d["rr"] = rl - lr
    lrc_d["lb"] = lb
    lrc_d["rb"] = bl - lb
# print(lrc)
ans = 0
mod = 10**9 + 7
for i in range(N):
    if S[i] == "R":
        lg = lrc[i]["lg"]
        rg = lrc[i]["rg"]
        lb = lrc[i]["lb"]
        rb = lrc[i]["rb"]
        lgs = set([i-gix[_] for _ in range(lg)])
        rgs = set([gix[lg+_]-i for _ in range(rg)])
        lbs = set([i-bix[_] for _ in range(lb)])
        rbs = set([bix[lb+_]-i for _ in range(rb)])
        ans += (lg*rb) - len(lgs&rbs)
        ans += (rg*lb) - len(rgs&lbs)
        ans %= mod
    if S[i] == "G":
        lr = lrc[i]["lr"]
        rr = lrc[i]["rr"]
        lb = lrc[i]["lb"]
        rb = lrc[i]["rb"]
        lrs = set([i-rix[_] for _ in range(lr)])
        rrs = set([rix[lr+_]-i for _ in range(rr)])
        lbs = set([i-bix[_] for _ in range(lb)])
        rbs = set([bix[lb+_]-i for _ in range(rb)])
        ans += (lr*rb) - len(lrs&rbs)
        ans += (rr*lb) - len(rrs&lbs)
        ans %= mod
        # print(lr, rr, lb, rb)
        # print(lrs, rrs, lbs, rbs)
    if S[i] == "B":
        lg = lrc[i]["lg"]
        rg = lrc[i]["rg"]
        lr = lrc[i]["lr"]
        rr = lrc[i]["rr"]
        lgs = set([i-gix[_] for _ in range(lg)])
        rgs = set([gix[lg+_]-i for _ in range(rg)])
        lrs = set([i-rix[_] for _ in range(lr)])
        rrs = set([rix[lr+_]-i for _ in range(rr)])
        ans += (lg*rr) - len(lgs&rrs)
        ans += (rg*lr) - len(rgs&lrs)
        ans %= mod
    # print(i, ans, S[i], lrc[i])
print(ans)

Submission status: Wrong Answer

Solution code:
from sys import stdin
import sys

# A, B, C = [int(x) for x in stdin.readline().rstrip().split()]
# A,B = [int(x) for x in stdin.readline().rstrip().split()]
# U = input().split()
# A, B = [str(x) for x in stdin.readline().rstrip().split()]
N = int(input())
S = list(input())
r = []
g = []
b = []
for i in range(N):
    if S[i] == 'R':
        r.append(i+1)
    elif S[i] == 'G':
        g.append(i+1)
    else:
        b.append(i+1)
# print(r)
# print(g)
# print(b)
cnt = 0
for i in range(len(r)):
    for j in range(len(g)):
        for k in range(len(b)):
            temp = [r[i], g[j], b[k]]
            temp.sort()

            if temp[1]*2 != temp[0]+temp[1]:
                cnt+=1
print(cnt)

Submission status: Wrong Answer

Solution code:
import math
n = int(input())
s = input()
r_cnt = 0
g_cnt = 0
b_cnt = 0
for i in s:
    if i == 'R':
        r_cnt += 1
    elif i == 'G':
        g_cnt += 1
    elif i == 'B':
        b_cnt += 1
        
total = r_cnt*g_cnt*b_cnt

if n < 4:
    print(total)

if n == 4:
    for j in range(2):
        tmp = s[j]+s[j+1]+s[j+2]
        if (tmp == 'RGB') or (tmp == 'RBG') or (tmp == 'GBR') or (tmp == 'GRB') or (tmp == 'BRG') or (tmp == 'BGR'):
            total -= 1
            
    print(total)
else:
    for i in range(1,math.floor((len(s)-2)/2)+1):
        for j in range(n-2*i):
            tmp = s[j]+s[j+i]+s[j+2*i]
            if (tmp == 'RGB') or (tmp == 'RBG') or (tmp == 'GBR') or (tmp == 'GRB') or (tmp == 'BRG') or (tmp == 'BGR'):
                total -= 1
    print(total)

Submission status: Wrong Answer

Solution code:
import math

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

r_count = s.count('R')
g_count = s.count('G')
b_count = s.count('B')

answer = r_count*g_count*b_count


for k in range(1, math.ceil(n/3)+6):
    for i in range(k):
        extracted = s[i::k]
        if len(extracted) >= 3:
            for l in range(len(extracted)-2):
                temp = extracted[l:l+3]
                if temp.count('R') == 1 and temp.count('G')==1 and temp.count('B'):
                    answer -= 1

print(answer)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(str(input()))
num=0
for k in range(N):
    for j in range(k):
        for i in range(j):
            if (A[i]==A[j]) or (A[j]==A[k]) or (A[i]==A[k]) or ((i+k)==2*j):
                num=num+1
num=N*(N*N-3*N+2)/6-num
print(num)

Submission status: Wrong Answer

Solution code:
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
x = min(r, g, b, key=len)
z = max(r, g, b, key=len)
for i in [r,g,b]:
	if x != i:
		if z != i:
			y = i
for i in x:
	for j in y:
		u = abs(i-j)
		if (max(i,j)+u) in z:
			count += 1
		if (min(i,j)-u) in z:
			count += 1
		if u%2 == 0:
			if (i+j)//2 in z:
				count += 1
print(len(r)*len(g)*len(b)-count)

Submission status: Wrong Answer

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


def run():
    n = int(input())
    s = input()[:n]

    r_list = [i for i, x in enumerate(s) if x == 'R']
    g_list = [i for i, x in enumerate(s) if x == 'G']
    b_list = [i for i, x in enumerate(s) if x == 'B']

    v = list(filter(
        lambda p: p[1] - p[0] != p[2] - p[1],
        itertools.product(
            r_list, g_list, b_list)
    ))

    print(len(v))


if __name__ == '__main__':
    run()

Submission status: Wrong Answer

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

def im(l, x):
    return [i for i, _x in enumerate(l) if _x == x]
R = im(s, "R")
G = im(s, "G")
B = im(s, "B")

ext = 0
if n >= 3:
    for i in range((n-3)//2):
        for j in range(n-(3+2*i)+1):
            if s[j] != s[j+i+1] and s[j] != s[j+2*(i+1)] and s[j+i+1] != s[j+2*(i+1)]:
                ext += 1

ans = len(R)*len(G)*len(B) - ext
print(ans)

Submission status: Wrong Answer

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

result = 0
if N <= 3:
    print(0)
else:
    for i in range(N-3):
        for j in range(i+1, N-1):
            if K[i] == K[j]:
                continue
            for k in range(j+1, N):
                if j - i == k - j:
                    continue
                if K[i] != K[j] and K[j] != K[k] and K[k] != K[i]:
                    result += 1

print(result)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
import sys
import math
from bisect import bisect_left
from bisect import bisect_right
import collections
import copy
import heapq
from collections import defaultdict
from heapq import heappop, heappush
import itertools
input = sys.stdin.readline
from collections import defaultdict
from heapq import heappop, heappush

from decimal import *

##### リストの 二分木検索 #####
# bisect_left(lists, 3)
# bisect_right(lists, 3)

##### プライオリティキュー #####
# heapq.heapify(a) #リストaのheap化
# heapq.heappush(a,x) #heap化されたリストaに要素xを追加
# heapq.heappop(a) #heap化されたリストaから最小値を削除＆その最小値を出力

# heapq.heappush(a, -x) #最大値を取り出す時は、pushする時にマイナスにして入れよう
# heapq.heappop(a) * (-1) #取り出す時は、-1を掛けて取り出すこと

##### タプルリストのソート #####
# sorted(ans) #(a, b) -> 1st : aの昇順, 2nd : bの昇順
# sorted(SP, key=lambda x:(x[0],-x[1])) #(a, b) -> 1st : aの昇順, 2nd : bの降順
# sorted(SP, key=lambda x:(-x[0],x[1])) #(a, b) -> 1st : aの降順, 2nd : bの昇順
# sorted(SP, key=lambda x:(-x[0],-x[1])) #(a, b) -> 1st : aの降順, 2nd : bの降順

# sorted(SP, key=lambda x:(x[1])) #(a, b) -> 1st : bの昇順
# sorted(SP, key=lambda x:(-x[1])) #(a, b) -> 1st : bの降順

##### 累乗 #####
# pow(x, y, z) -> x**y % z

def inputInt(): return int(input())
def inputMap(): return map(int, input().split())
def inputList(): return list(map(int, input().split()))

inf = float('inf')
mod = 1000000007

#-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
#-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-

def main():
	N = inputInt()
	S = input()
	S = S[:-1]

	R = []
	G = []
	B = []
	for i,val in enumerate(S):
		if val == "R":
			R.append(i)
		elif val == "G":
			G.append(i)
		else:
			B.append(i)

	ans = 0
	for i,val in enumerate(R):
		tmp = bisect_right(G, val)
		if len(G) == tmp:
			break

		for j in range(tmp,len(G)):
			tmptmp = bisect_right(B, G[j])
			if len(B) == tmptmp:
				break

			blacks = G[j] - val + G[j]
			lislis = B[tmptmp:]
			if blacks in lislis:
				ans += len(B)-tmptmp-1
			else:
				ans += len(B)-tmptmp

		tmp = bisect_right(B, val)
		if len(B) == tmp:
			break

		for j in range(tmp,len(B)):
			tmptmp = bisect_right(G, B[j])
			if len(G) == tmptmp:
				break

			blacks = B[j] - val + B[j]
			lislis = G[tmptmp:]
			if blacks in lislis:
				ans += len(G)-tmptmp-1
			else:
				ans += len(G)-tmptmp


	for i,val in enumerate(B):
		tmp = bisect_right(G, val)
		if len(G) == tmp:
			break

		for j in range(tmp,len(G)):
			tmptmp = bisect_right(R, G[j])
			if len(R) == tmptmp:
				break

			blacks = G[j] - val + G[j]
			lislis = R[tmptmp:]
			if blacks in lislis:
				ans += len(R)-tmptmp-1
			else:
				ans += len(R)-tmptmp

		tmp = bisect_right(R, val)
		if len(R) == tmp:
			break

		for j in range(tmp,len(R)):
			tmptmp = bisect_right(G, R[j])
			if len(G) == tmptmp:
				break

			blacks = R[j] - val + R[j]
			lislis = G[tmptmp:]
			if blacks in lislis:
				ans += len(G)-tmptmp-1
			else:
				ans += len(G)-tmptmp

	for i,val in enumerate(G):
		tmp = bisect_right(B, val)
		if len(B) == tmp:
			break

		for j in range(tmp,len(B)):
			tmptmp = bisect_right(R, B[j])
			if len(R) == tmptmp:
				break

			blacks = B[j] - val + B[j]
			lislis = R[tmptmp:]
			if blacks in lislis:
				ans += len(R)-tmptmp-1
			else:
				ans += len(R)-tmptmp



	print(ans)

#-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
#-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
# special thanks :
#  https://nagiss.hateblo.jp/entry/2019/07/01/185421
#-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
class Graph(object):
    """
    隣接リストによる有向グラフ
    """

    def __init__(self):
        self.graph = defaultdict(list)

    def __len__(self):
        return len(self.graph)

    def add_edge(self, src, dst, weight=1):
        self.graph[src].append((dst, weight))

    def get_nodes(self):
        return self.graph.keys()


class Dijkstra(object):
    """
    ダイクストラ法（二分ヒープ）による最短経路探索
    計算量: O((E+V)logV)
    """

    def __init__(self, graph, start):
        self.g = graph.graph

        # startノードからの最短距離
        # startノードは0, それ以外は無限大で初期化
        self.dist = defaultdict(lambda: float('inf'))
        self.dist[start] = 0

        # 最短経路での1つ前のノード
        self.prev = defaultdict(lambda: None)

        # startノードをキューに入れる
        self.Q = []
        heappush(self.Q, (self.dist[start], start))

        while self.Q:
            # 優先度（距離）が最小であるキューを取り出す
            dist_u, u = heappop(self.Q)
            if self.dist[u] < dist_u:
                continue
            for v, weight in self.g[u]:
                alt = dist_u + weight
                if self.dist[v] > alt:
                    self.dist[v] = alt
                    self.prev[v] = u
                    heappush(self.Q, (alt, v))

    def shortest_distance(self, goal):
        """
        startノードからgoalノードまでの最短距離
        """
        return self.dist[goal]

    def shortest_path(self, goal):
        """
        startノードからgoalノードまでの最短経路
        """
        path = []
        node = goal
        while node is not None:
            path.append(node)
            node = self.prev[node]
        return path[::-1]

def int_sqrt2(n):
    def f(prev):
        while True:
            m = (prev + n / prev) / 2
            if m >= prev:
                return prev
            prev = m

    return f(int(math.sqrt(n) * (1 + 1e-10)))

# nCr mod m
# rがn/2に近いと非常に重くなる
def combination(n, r, mod=10**9+7):
    r = min(r, n-r)
    res = 1
    for i in range(r):
        res = res * (n - i) * modinv(i+1, mod) % mod
    return res

# mを法とするaの乗法的逆元
def modinv(a, mod=10**9+7):
    return pow(a, mod-2, mod)

def egcd(a, b):
    if a == 0:
        return b, 0, 1
    else:
        g, y, x = egcd(b % a, a)
        return g, x - (b // a) * y, y

# nHr mod m
# 問題によって、combination()を切り替えること
def H(n, r, mod=10**9+7):
	# comb = Combination(n+r-1, mod)
	# return comb(n+r-1, r)
    return combination(n+r-1, r, mod)

class Combination:
    """
    O(n)の前計算を1回行うことで，O(1)でnCr mod mを求められる
    n_max = 10**6のとき前処理は約950ms (PyPyなら約340ms, 10**7で約1800ms)
    使用例：
    comb = Combination(1000000)
    print(comb(5, 3))  # 10
    """
    def __init__(self, n_max, mod=10**9+7):
        self.mod = mod
        self.modinv = self.make_modinv_list(n_max)
        self.fac, self.facinv = self.make_factorial_list(n_max)

    def __call__(self, n, r):
        return self.fac[n] * self.facinv[r] % self.mod * self.facinv[n-r] % self.mod

    def make_factorial_list(self, n):
        # 階乗のリストと階乗のmod逆元のリストを返す O(n)
        # self.make_modinv_list()が先に実行されている必要がある
        fac = [1]
        facinv = [1]
        for i in range(1, n+1):
            fac.append(fac[i-1] * i % self.mod)
            facinv.append(facinv[i-1] * self.modinv[i] % self.mod)
        return fac, facinv

    def make_modinv_list(self, n):
        # 0からnまでのmod逆元のリストを返す O(n)
        modinv = [0] * (n+1)
        modinv[1] = 1
        for i in range(2, n+1):
            modinv[i] = self.mod - self.mod//i * modinv[self.mod%i] % self.mod
        return modinv

if __name__ == "__main__":
	main()

Submission status: Wrong Answer

Solution code:
N = int(input())
S = input()+"00"

r_cnt = 0
g_cnt = 0
b_cnt = 0
rgb_cnt = 0

for i in range(N):

    if S[i] == "R":
        r_cnt += 1
    elif S[i] == "G":
        g_cnt += 1
    elif S[i] == "B":
        b_cnt += 1

    if "R" in S[i:i+3] and "G" in S[i:i+3] and "B" in S[i:i+3]:
        rgb_cnt += 1

print((r_cnt*g_cnt*b_cnt)-rgb_cnt)

Submission status: Wrong Answer

Solution code:
import sys
from collections import defaultdict, Counter, deque
from itertools import accumulate, permutations, combinations
from operator import itemgetter
from bisect import bisect_left, bisect_right, bisect
from heapq import heappop, heappush
from fractions import gcd
from math import ceil, floor, sqrt, cos, sin, pi
from copy import deepcopy

# If you use recursive call, uncomment this code
#sys.setrecursionlimit(10**6)

#def main():
#    N = int(input())
#    S = input()
#    ans = 0
#    memo = defaultdict(int)
#    if N % 2 == 0:
#        ridx = N // 2
#        lidx = ridx-1
#    else:
#        ridx = N//2+1
#        lidx = ridx-2

def main():
    N = int(input())
    S = input()
    ans = 0
    for i in range(N):
        for j in range(i+1,N):
            for k in range(2*j-i,N):
                if len(set([S[i],S[j],S[k]]))==3:
                    ans += 1
    print(ans)
        
if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

r_idxs = [i + 1 for i in range(N) if S[i] == "R"]
g_idxs = [i + 1 for i in range(N) if S[i] == "G"]
b_idxs = [i + 1 for  i in range(N) if S[i] == "B"]

rgb_idxs = [r_idxs, g_idxs, b_idxs]

def calc_same_diff(rgb_idxs):
    ans = 0
    idxs_1, idxs_2, idxs_3 = decide_idxs(rgb_idxs)
    for idx_1 in idxs_1:
        for idx_2 in idxs_2:
            diff = abs(idx_1 - idx_2)
            t1 = min(idx_1, idx_2) - diff
            t2 = max(idx_1, idx_2) + diff
            t3 = (idx_1 + idx_2) / 2
            for t in [t1, t2, t3]:
                if t in idxs_3:
                    ans +=1
                    continue
    return ans

def decide_idxs(rgb_idxs):
    rgb_idxs = [r_idxs, g_idxs, b_idxs]
    lengths = [len(w) for w in rgb_idxs]
    max_idx = lengths.index(max(lengths))
    min_idx = lengths.index(min(lengths))
    middle_idx = [i for i in range(3) if i != max_idx and i!=min_idx][0]
    min_idx, middle_idx, max_idx = rgb_idxs[min_idx], rgb_idxs[middle_idx], rgb_idxs[max_idx]
    return min_idx, middle_idx, max_idx

lengths = [len(w) for w in rgb_idxs]
all_num = lengths[0] * lengths[1] * lengths[2]
print(all_num - calc_same_diff(rgb_idxs))

Submission status: Wrong Answer

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

c = 0

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

print ( c )