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 bisect
N = int(input())  # N<= 4000 6*10^10なので、削減しないとだめ
S = list(input())


# Si Sj Skがどれも別のもの。ただしi<j<k
# また、j-i != k-j
# 1,2,3はだめ1,2,4はok
# 1,3,5もだめ
# この組の数を求める

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


indexes = {'R': [], "G": [], "B": []}
for i, char in enumerate(S):
    indexes[char].append(i + 1)
# print(permutation_hash)
count = 0
R_indexes_count = len(indexes['R'])
G_indexes_count = len(indexes['G'])
B_indexes_count = len(indexes['B'])
# 短いやつを使うとかする？
if R_indexes_count <= G_indexes_count and R_indexes_count <= B_indexes_count:
    min_type = 'R'
    if G_indexes_count <= B_indexes_count:
        second_min_type = 'G'
        last_type = 'B'
    else:
        second_min_type = 'B'
        last_type = 'G'
elif G_indexes_count <= R_indexes_count and G_indexes_count <= B_indexes_count:
    min_type = 'G'
    if R_indexes_count <= B_indexes_count:
        second_min_type = 'R'
        last_type = 'B'
    else:
        second_min_type = 'B'
        last_type = 'R'
else:
    min_type = 'B'
    if G_indexes_count <= R_indexes_count:
        second_min_type = 'G'
        last_type = 'R'
    else:
        second_min_type = 'R'
        last_type = 'G'


for R_index in indexes[min_type]:
    for G_index in indexes[second_min_type]:
        middle_index = (R_index + G_index) / 2
        remove_conut = 0
        if middle_index != R_index and middle_index != G_index:
            if middle_index in indexes[last_type]:
                remove_conut += 1
        div = abs(G_index - R_index)
        if G_index < R_index:
            if G_index - div in indexes[last_type]:
                remove_conut += 1
            if R_index + div in indexes[last_type]:
                remove_conut += 1
        else:
            if G_index + div in indexes[last_type]:
                remove_conut += 1
            if R_index - div in indexes[last_type]:
                remove_conut += 1
        count += (B_indexes_count - remove_conut)

print(count)

Submission status: Wrong Answer

Solution code:
N = int(input())
S = input()
R = [0]*N
G = [0]*N
B = [0]*N
ans = 0
for i in range(N):
    if S[i] == "R":
        R[i] = i+1
    elif S[i] == "G":
        G[i] = i+1
    else:
        B[i] = i+1
for i in range(N):
    if R[i] == 0:
        pass
    else:
        for j in range(N):
            if G[j] == 0:
                pass
            else:
                a = G[j]-R[i]
                for k in range(N):
                    g = G[j]
                    if B[k] == 0:
                        pass
                    else:
                        if a != B[k]-g:
                            ans += 1

print(ans)

Submission status: Wrong Answer

Solution code:
N,=map(int, input().split())  #複数数値入力　「A B」みたいなスペース空いた入力のとき
st,=map(str, input().split())  #複数数値入力　「A B」みたいなスペース空いた入力のとき
sum=0
st = list(st)
for k in range(1,N+1):
    for j in range(1,k+1):
        if (st[k-1]==st[j-1]):
            continue
        for i in range(1,j+1):
            if (st[i-1]!=st[j-1] and (j-i)!=(k-j)):
                sum+=1
print(sum)

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(1, N-1):
    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:
# ABC162_D
n=int(input())
s=input()
r=[0]*n
g=[0]*n
b=[0]*n
for i,ss in enumerate(s):
    if ss=="R":r[i]=1
    if ss=="G":g[i]=1
    if ss=="B":b[i]=1
from itertools import accumulate as acc
r=list(acc(r))
g=list(acc(g))
b=list(acc(b))

# print(r)
ans=0
for i in range(n):
    for j in range(i+1,n):
        # if s[i]==s[j]:continue
        h=j-i
        ok=False
        if s[i]=="R" and s[j]=="G" or s[j]=="R" and s[i]=="G":
            ans+=b[n-1]-b[j-1]
            ok=True
        elif s[i]=="R" and s[j]=="B" or s[j]=="R" and s[i]=="B":
            ans+=g[n-1]-g[j-1]
            ok=True
        elif s[i]=="B" and s[j]=="R" or s[j]=="B" and s[i]=="R":
            ans+=g[n-1]-g[j-1]
            ok=True
        elif s[i]=="B" and s[j]=="G" or s[j]=="B" and s[i]=="G":
            ans+=r[n-1]-r[j-1]
            ok=True
        elif s[i]=="G" and s[j]=="R" or s[j]=="G" and s[i]=="R":
            ans+=b[n-1]-b[j-1]
            ok=True
        elif s[i]=="G" and s[j]=="B" or s[j]=="G" and s[i]=="B":
            ans+=r[n-1]-r[j-1]
            ok=True
        if ok:
            ans-=((n-1)-j)//h
        # ans+=r[n-1]-r[j-1]
        # ans+=g[n-1]-g[j-1]
        # ans+=b[n-1]-b[j-1]
        # if s[i]==s[j]:
        #     if s[i]=="R":
        #         ans-=r[n-1]-r[j-1]
        #     elif s[i]=="G":
        #         ans-=g[n-1]-g[j-1]
        #     elif s[i]=="B":
        #         ans-=b[n-1]-b[j-1]
        # ans-=((n-1)-j)//h
print(ans)

Submission status: Wrong Answer

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

sum=0

R=[i for i, x in enumerate(S) if S[i] == 'R']
G=[i for i, x in enumerate(S) if S[i] == 'G']
B=[i for i, x in enumerate(S) if S[i] == 'B']

len_R=len(R)
len_G=len(G)
len_B=len(B)

for i in range(len_R):
  for j in range(len_G):
    for k in range(len_B):
      if(i-j!=k-j):
        sum=sum+1

print(int(sum))

Submission status: Wrong Answer

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

count = 0
char_candidates = "RGB"
for i in range(len(s)):
    i_char = s[i]

    indexes =  [a for a, ltr in enumerate(s[i+1:]) if ltr != i_char]
    for j in indexes:
        j_char = s[j]
        
        valid_k_char = char_candidates.replace(s[i], "").replace(s[j], "")

        target_chars = s[j+1:]
        match_count = target_chars.count(valid_k_char)

        if j + j - i < len(s) and s[j + j - i] == valid_k_char:
            match_count -= 1

        count += match_count

print(count)

Submission status: Wrong Answer

Solution code:
import math
if __name__ == "__main__":
    N = int(input())
    S = input()

    R_idx = [i for i in range(len(S)) if S[i] == "R"]
    G_idx = [i for i in range(len(S)) if S[i] == "G"]
    B_idx = [i for i in range(len(S)) if S[i] == "B"]
    #print(R_idx)
    #print(G_idx)
    #print(B_idx)
    ans = len(R_idx) * len(G_idx) * len(B_idx)
    for i in R_idx:
        for j in G_idx:
            m = min(i,j)
            M = max(i,j)
            d = M - m
            if m - d in B_idx:
                ans -= 1
            if M + d in B_idx:
                ans -= 1
    print(ans)

Submission status: Wrong Answer

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

print(cnt)

Submission status: Wrong Answer

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

R_list = [int(i) for i, x in enumerate(s_list) if x == 'R']
G_list = [int(i) for i, x in enumerate(s_list) if x == 'G']
B_list = [int(i) for i, x in enumerate(s_list) if x == 'B']

ans = 0
for i in range(len(R_list)):
    for j in range(len(G_list)):
        for k in range(len(B_list)):
            if abs(R_list[i] - G_list[j])+G_list[j] == B_list[k]:
                ans += 1
            elif abs(R_list[i] - G_list[j])+R_list[i] == B_list[k]:
                ans += 1
            elif G_list[j] - abs(R_list[i] - G_list[j]) == B_list[k]:
                ans += 1
            elif R_list[i] - abs(R_list[i] - G_list[j]) == B_list[k]:
                ans += 1
            elif 0.5*abs(R_list[i] - G_list[j])+G_list[j] == B_list[k]:
                ans += 1
            elif 0.5*abs(R_list[i] - G_list[j])+R_list[i] == B_list[k]:
                ans += 1
print(len(R_list)*len(G_list)*len(B_list)-ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
S = input()
R_index = [n for n, v in enumerate(S) if v == 'R']
G_index = [n for n, v in enumerate(S) if v == 'G']
B_index = [n for n, v in enumerate(S) if v == 'B']
ans = len(R_index) *len(G_index) *len(B_index)

for r in R_index:
    for g in G_index:
        diff = max(r,g) -min(r,g)
        mid = diff //2
        if max(r,g)+diff in B_index:
            ans -= 1
        if mid in B_index:
            ans -= 1
        # for b in B_index:
        #     l = [r,g,b]
        #     l.sort()
        #     if l[1] - l[0] == l[2] -l[1]:
        #         ans -= 1
print(ans)

Submission status: Wrong Answer

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

R = []
G = []
B = []
ans = 0
for i in range(len(S)):    
    if S[i] == "R":
        R.append(i)
    if S[i] == "G":
        G.append(i)
    if S[i] == "B":
        B.append(i)
# r, g, b = 0, 0, 0
# while (r < len(R) and g < len(G) and b < len(B)):
#     target = min(R[r], g, b)
#     if (abs(R[r] - g) != abs(g - b) and abs(R[r] - g) != abs(R[r] - b) and abs(g - b) != abs(R[r] - b)):
#         ans += 1
#     if target == R[r]:
#         r += 1
#     if target == g:
#         g += 1
#     if target == b:
#         b += 1
rem = 0 
for r in R:
    for g in G:
        # for b in B:
        #     if (abs(r - g) != abs(g - b) and abs(r - g) != abs(r - b) and abs(g - b) != abs(r - b)):
        #         ans += 1
        if g - abs(r - g) in B or r - abs(g - r) in B or  g + abs( r- g) in B or r +abs( g- r) in B:
            rem += 1
        if (r >= g):
            if (g + r) / 2 in B :
                rem += 1
        if (g >= r):
            if (g + r) / 2 in B :
                rem += 1
            
print(len(R)*len(G)*len(B) - rem )

Submission status: Wrong Answer

Solution code:
n=int(input())
s=input()
r=[0]*(n+2)
g=[0]*(n+2)
b=[0]*(n+2)
cntr=0
cntg=0
cntb=0
for i in range(n):
    if s[i]=="R":
        cntr+=1
    r[i+1]=cntr
    if s[i]=="G":
        cntg+=1
    g[i+1]=cntg
    if s[i]=="B":
        cntb+=1
    b[i+1]=cntb

ans=0
for j in range(0,n):
    tmp=0
    de=0
    if s[j]=="R":
        tmp+=(g[j]*b[j+2]+b[j]*g[j+2])

        for dist in range(1,n-j):
            if s[j - dist] == "G" and s[j + dist] == "B":
                de += 1
            elif s[j - dist] == "B" and s[j + dist] == "G":
                de += 1
        tmp-=de

    elif s[j]=="G":
        tmp+=(r[j]*b[j+2]+b[j]*r[j+2])
        for dist in range(1,n-j):
            if s[j-dist]=="R" and s[j+dist]=="B":
                de+=1
            elif s[j-dist]=="B" and s[j+dist]=="R":
                de+=1
        tmp-=de

    elif s[j]=="B":
        tmp+=(r[j]*g[j+2]+g[j]*r[j+2])

        for dist in range(1,n-j):
            if s[j - dist] == "R" and s[j + dist] == "G":
                de += 1
            elif s[j - dist] == "G" and s[j + dist] == "R":
                de += 1
        tmp-=de
    ans+=tmp

print(ans)

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)

sum=0
if len(r)*len(g)*len(b)==0:
    print(0)
else:
    for re in r:
        for gr in g:
            cnt=0
            re,gr=min(re,gr),max(re,gr)
            if (re+gr)%2==0:
                if (re+gr)//2 in b:
                    cnt-=1
            if 2*gr-re in b:
                cnt-=1
            if 2*re-gr in b:
                cnt-=1
            sum+=cnt+len(b)
    print(sum)

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
        for f in FF:
            if f - e > e-i:
                break
            if f-e == e-i:
                eq = 1
        if eq == 1:
            wa += len(FF)-1
        else:
            wa += len(FF)

    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:
l = [input() for _ in range(2)]
S = l[1]
N = int(l[0])
count = 0

indexR = []
indexG = []
indexB = []

i = 0
j = 0
k = 0

for a in range(N):
    character = S[a:a+1]

    if character == 'R':
        indexR.append(a+1)
    elif character == 'G':
        indexG.append(a+1)
    elif character == 'B':
        indexB.append(a+1)

maxi = 0
mini = 0

for r in indexR:
    maxi = r
    mini = r
    for g in indexG:
        if g < mini:
            mini = g
        if g > maxi:
            maxi = g
        for b in indexB:
            if b < mini:
                mini = b
            if b > maxi:
                maxi = b
            mean = (maxi + mini)/2
            if mean != r and mean != g and mean != b:
                count = count + 1
print(count)

Submission status: Wrong Answer

Solution code:
from copy import deepcopy

def main():
    n = int(input())
    s = list(input())
    sr = [0] * n
    sg = [0] * n
    sb = [0] * n
    for i1 in range(n):
        ts = s[i1]
        if ts == 'R':
            sr[i1] = 1
        elif ts == 'G':
            sg[i1] = 1
        else:
            sb[i1] = 1
    if n <= 3:
        print(0)
        exit()
    r = 0
    for ia in range(0,n-3):
        ta = s[ia]
        if ta == 'R':
            r += sum(sg[ia+1:]) * sum(sb[ia+1:])

        elif ta == 'G':
            r += sum(sr[ia+1:]) * sum(sb[ia+1:])
        else:
            r += sum(sg[ia + 1:]) * sum(sr[ia + 1:])
    print(r-1)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
from collections import Counter

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

    t = Counter(s)

    ans = t['R']*t['G']*t['B']

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

    print(ans)
if __name__ == "__main__":
    main()

Submission status: Wrong Answer

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

# R_id = [i for (i, x) in enumerate(S) if x == "R"]
# G_id = [i for (i, x) in enumerate(S) if x == "G"]
# B_id = [i for (i, x) in enumerate(S) if x == "B"]

acc_r = 0
acc_r_list = []
acc_b = 0
acc_b_list = []
acc_g = 0
acc_g_list = []
for c in S:
    if c == "R":
        acc_r += 1
    acc_r_list.append(acc_r)
    if c == "B":
        acc_b += 1
    acc_b_list.append(acc_b)
    if c == "G":
        acc_g += 1
    acc_g_list.append(acc_g)

summation = 0
for j, c in enumerate(S):
    if c == "G":
        for i, cc in enumerate(S[:j]):
            if cc == "R":
                diff = j - i
                if j + diff < N:
                    num_b = (acc_b_list[j + diff - 1] - acc_b_list[j])
                    if j + diff + 1 < N:
                        num_b += (acc_b_list[-1] - acc_b_list[j + diff + 1])
                else:
                    num_b = acc_b_list[-1] - acc_b_list[j]
                
                summation += num_b

for j, c in enumerate(S):
    if c == "R":
        for i, cc in enumerate(S[:j]):
            if cc == "G":
                diff = j - i
                if j + diff < N:
                    num_b = (acc_b_list[j + diff - 1] - acc_b_list[j])
                    if j + diff + 1 < N:
                        num_b += (acc_b_list[-1] - acc_b_list[j + diff + 1])
                else:
                    num_b = acc_b_list[-1] - acc_b_list[j]
                
                summation += num_b

for j, c in enumerate(S):
    if c == "B":
        for i, cc in enumerate(S[:j]):
            if cc == "G":
                diff = j - i
                if j + diff < N:
                    num_r = (acc_r_list[j + diff - 1] - acc_r_list[j])
                    if j + diff + 1 < N:
                        num_r += (acc_r_list[-1] - acc_r_list[j + diff + 1])
                else:
                    num_r = acc_r_list[-1] - acc_r_list[j]
                
                summation += num_r

for j, c in enumerate(S):
    if c == "G":
        for i, cc in enumerate(S[:j]):
            if cc == "B":
                diff = j - i
                if j + diff < N:
                    num_r = (acc_r_list[j + diff - 1] - acc_r_list[j])
                    if j + diff + 1 < N:
                        num_r += (acc_r_list[-1] - acc_r_list[j + diff + 1])
                else:
                    num_r = acc_r_list[-1] - acc_r_list[j]
                
                summation += num_r

for j, c in enumerate(S):
    if c == "B":
        for i, cc in enumerate(S[:j]):
            if cc == "R":
                diff = j - i
                if j + diff < N:
                    num_g = (acc_g_list[j + diff - 1] - acc_g_list[j])
                    if j + diff + 1 < N:
                        num_g += (acc_g_list[-1] - acc_g_list[j + diff + 1])
                else:
                    num_g = acc_g_list[-1] - acc_g_list[j]
                
                summation += num_g

for j, c in enumerate(S):
    if c == "R":
        for i, cc in enumerate(S[:j]):
            if cc == "B":
                diff = j - i
                if j + diff < N:
                    num_g = (acc_g_list[j + diff - 1] - acc_g_list[j])
                    if j + diff + 1 < N:
                        num_g += (acc_g_list[-1] - acc_g_list[j + diff + 1])
                else:
                    num_g = acc_g_list[-1] - acc_g_list[j]
                
                summation += num_g

print(summation)
# print(acc_b_list)

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)

ans = 0

for i in r:
  for j in g:
    for k in b:
      if j - i != k - j and i < j and j < k:
        ans += 1
print(ans)

Submission status: Wrong Answer

Solution code:
n=int(input())
s=input()
ans=0
r=[]
g=[]
b=[]
for i in range(n):
    tmp=s[i]
    if tmp=="R":
        r.append(i+1)
    elif tmp=="G":
        g.append(i+1)
    else:
        b.append(i+1)
for i in r:
    for j in g:
        for k in b:
            if (i<j and j<k and i<k) or (i<k and k<j and i<j):
                continue
            if j-i==k-j:
                continue
            else:
                ans+=1
print(ans)

Submission status: Wrong Answer

Solution code:
# coding: utf-8
 
N  = int(input())
S = input()

count = 0
count_red = S.count("R")
count_green = S.count("G")
count_blue = S.count("B")

count_DR = S.count("RR")
count_DG = S.count("GG")
count_DB = S.count("BB")

ans = (count_red*count_green*count_blue) - (count_DR*count_DG*count_DB)

print(ans)

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()
lst=list(s)
r=[]
g=[]
b=[]
for i,v in enumerate(lst):
    if v=="R":
        r.append(i)
    elif v=="G":
        g.append(i)
    elif v=="B":
        b.append(i)
comb=len(r)*len(g)*len(b)
out=0
for i in r:
  for j in g:
      if ((2*j-i) in b) or ((i+j)//2 in b) or ((2*i-j) in b) or ((j-i*2) in b) or ((i-j*2) in b):
        out+=1
print(comb-out)

Submission status: Wrong Answer

Solution code:
n = int(input())
s = input()
ans = 0
ans_list = []

R_index = []
G_index = []
B_index = []

for i in range(n):
    if s[i] == 'R':
        R_index.append(i)
    elif s[i] == 'G':
        G_index.append(i)
    elif s[i] == 'B':
        B_index.append(i)

ans = len(R_index) * len(G_index) * len(B_index)

for j in range(1, n-1):
    for i in range(min(n-j-1,j)):
        if s[j-i] != s[j] and s[j] != s[j+i] and s[j-i] != s[j+i]:
            ans -= 1


print(ans)

Submission status: Wrong Answer

Solution code:
import itertools
import numpy as np

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

R = np.array([])
G = np.array([])
B = np.array([])
for i in range(len(S)):
    if S[i] == 'R':
        R = np.append(R, i)
    elif S[i] == 'G':
        G = np.append(G, i)
    else:
        B = np.append(B, i)

if len(R) == 0 or len(G) == 0 or len(B) == 0:
    print(0)
else:
    total = 0
    for r, g in itertools.product(R, G):
        x = np.min([r, g])
        y = np.max([r, g])

        bx = [x-b for b in B if b < x]
        if y-x in bx:
            total += len(bx) - 1
        else:
            total += len(bx)

        xy = [b for b in B if x < b and b < y]
        xb = xy - x
        by = y - xy
        l = list(np.concatenate([xb, by]))
        unique = [x for x in l if l.count(x) == 1]
        total += len(unique)

        yb = [b-y for b in B if y < b]
        if y-x in yb:
            total += len(yb) - 1
        else:
            total += len(yb)

    print(str(total))

Submission status: Wrong Answer

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
now_char = ''
change_idx = []
for c in S:
    if now_char != c:
        now_char = c
        change_idx.append(cnt)
    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(len(change_idx) - 1):
    for j in range(i + 1, len(change_idx)):
        if S[change_idx[i]] == S[change_idx[j]]: continue
        clist = [S[change_idx[i]], S[change_idx[j]]]
        diff_idx = j - i
        # cnt_val = 0
        # if S[change_idx[i]] == 'R':
        #     # print("R")
        #     # print(R_sum[j], R_sum[0])
        #     cnt_val = R_sum[j-1]
        # elif S[change_idx[i]] == 'G':
        #     # print("G")
        #     # print(G_sum[j], G_sum[0])
        #     cnt_val = G_sum[j-1]
        # elif S[change_idx[i]] == 'B':
        #     # print("B")
        #     # print(B_sum[j], B_sum[0])
        #     cnt_val = B_sum[j-1]
        # # print(f"cnt_val = {cnt_val}")

        if not ('R' in clist):
            # print("R")
            # print(R_sum[N-1], R_sum[j + 1])
            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):
            # print("G")
            # print(G_sum[N-1], G_sum[j + 1])
            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):
            # print("B")
            # print(B_sum[N-1], B_sum[j + 1])
            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: 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+1)

Submission status: Wrong Answer

Solution code:
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

n_min = min(n, n//3+10)
for k in range(1, n_min):
    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,=map(int, input().split())  #複数数値入力　「A B」みたいなスペース空いた入力のとき
st,=map(str, input().split())  #複数数値入力　「A B」みたいなスペース空いた入力のとき
sum=0
st = list(st)
for k in range(1,N+1):
    for j in range(1,k):
        if (st[k-1]==st[j-1]):
            continue
        for i in range(1,j):
            if (st[i-1]!=st[j-1] and (j-i)!=(k-j)):
                sum+=1
print(sum)

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
        if b-r >0 and (b + b-r in garr):
            ans-=1
        #RGB BGR
        if r-b >0 and (r-b)%2==0 and b+((r-b)//2) in garr:
            ans-=1
        if b-r >0 and (b-r)%2==0 and r+((b-r)//2) in garr:
            ans-=1
        #RBG
        if r-b>0 and r-b in garr:
            ans-=1
        if b-r>0 and b-r in garr:
            ans-=1
print(ans)