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

def solve():
    N = int(input())
    S = input()
    R = []
    G = []
    B = []

    # color separate
    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)

    # after color map
    lR = len(R)
    lG = len(G)
    lB = len(B)
    RGBmap = []
    for i in range(len(S)):
        if S[i] == 'R':
            lR -= 1
        elif S[i] == 'G':
            lG -= 1
        elif S[i] == 'B':
            lB -= 1
        RGBmap.append([lR, lG, lB])

    # calculate
    sum = 0
    for i in range(len(S)):
        if S[i] == 'R':
            a1 = G
            a2 = B
            b1 = 2
            b2 = 1
            c1 = 'B'
            c2 = 'G'
        elif S[i] == 'G':
            a1 = R
            a2 = B
            b1 = 2
            b2 = 0
            c1 = 'B'
            c2 = 'R'
        else:
            a1 = G
            a2 = R
            b1 = 0
            b2 = 2
            c1 = 'R'
            c2 = 'G'
        sumb = 0
        for a in a1:
            if i < a:
                sumb = RGBmap[a][b1]
            if sumb == 0:
                continue
            if a + (a - i) < len(S) and S[a + (a - i)] == c1:
                sumb -= 1
            sum += sumb
        for a in a2:
            if i < a:
                sumb = RGBmap[a][b2]
            if sumb == 0:
                continue
            if a + (a - i) < len(S) and S[a + (a - i)] == c2:
                sumb -= 1
            sum += sumb
    print(sum)
    # 
    # sum = 0
    # for i in range(len(S)):
    #     if S[i] == 'R':
    #         a1 = G
    #         b1 = 2
    #         c1 = 'B'
    #         sumb = 0
    #         for a in a1:
    #             if i < a:
    #                 sumb = RGBmap[a][b1]
    #             if sumb == 0:
    #                 continue
    #             if a + (a - i) < len(S) and S[a + (a - i)] == c1:
    #                 sumb -= 1
    #             sum += sumb
    # print(sum)
    # 
    # 
    # sum = 0
    # for i in range(len(S)):
    #     if S[i] == 'R':
    #         a1 = G
    #         a2 = B
    #         b1 = 2
    #         b2 = 1
    #         c1 = 'B'
    #         c2 = 'G'
    #         sumb = 0
    #         for a in a1:
    #             if i < a:
    #                 sumb = RGBmap[a][b1]
    #             if sumb == 0:
    #                 continue
    #             if a + (a - i) < len(S) and S[a + (a - i)] == c1:
    #                 sumb -= 1
    #             sum += sumb
    #         for a in a2:
    #             if i < a:
    #                 sumb = RGBmap[a][b2]
    #             if sumb == 0:
    #                 continue
    #             if a + (a - i) < len(S) and S[a + (a - i)] == c2:
    #                 sumb -= 1
    #             sum += sumb
    # print(sum)
    # 
    # 


if __name__ == '__main__':
    solve()

Submission status: Wrong Answer

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

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

cum_r = [0] * (n + 1)
cum_g = [0] * (n + 1)
cum_b = [0] * (n + 1)

for i in range(n):
    cum_r[i + 1] = cum_r[i]
    cum_g[i + 1] = cum_g[i]
    cum_b[i + 1] = cum_b[i]
    if s[i] == "R":
        cum_r[i + 1] += 1
    elif s[i] == "G":
        cum_g[i + 1] += 1
    else:  # s[i] == "b":
        cum_b[i + 1] += 1

sum = 0
for i in range(n - 2):
    for k in range(n - 1, i + 2, -1):
        if s[i] == s[k]:
            continue

        # check "b"
        if (s[i] == "R" and s[k] == "G") or (s[i] == "G" and s[k] == "R"):
            sum += cum_b[k] - cum_b[i + 1]
            if (k + i) % 2 == 0 and s[(k + i) // 2] == "B":
                sum -= 1
        elif (s[i] == "R" and s[k] == "B") or (s[k] == "B" and s[k] == "R"):
            sum += cum_g[k] - cum_g[i + 1]
            if (k + i) % 2 == 0 and s[(k + i) // 2] == "G":
                sum -= 1
        else:
            sum += cum_r[k] - cum_r[i + 1]
            if (k + i) % 2 == 0 and s[(k + i) // 2] == "R":
                sum -= 1

print(sum)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
import sys
import numpy as np

def solve(N: int, S: str):
    r = []
    g = []
    b = []

    for i, x in enumerate(S):
        if x ==  "R":r.append(i)
        elif x =="G":g.append(i)
        elif x =="B":b.append(i)

    r = np.array(r)
    g = np.array(g)
    b = np.array(b)


    def rgb(r, g, b):
        sb = set(b)
        ans = 0
        for r_ in r:
            # brgb
            for g_ in g[g>r_]:
                if (g_ + (g_ - r_)) in sb:
                    ans -= 1
                ans += len(b[g_<b])
                if (r_ - (g_ - r_)) in sb:
                    ans -= 1                
                ans += len(b[b<r_])
            # bgrb
            for g_ in g[g>r_]:
                if (g_ + (g_ - r_)) in sb:
                    ans -= 1
                ans += len(b[g_<b])
                if (r_ - (g_ - r_)) in sb:
                    ans -= 1                
                ans += len(b[b<r_])
        return ans

    def rgb_s(r, g, b):
        sb = set(b)
        ans = 0
        for r_ in r:
            for g_ in g[g>r_]:
                if (g_ + g_ - r_) in sb:
                    ans -= 1
                ans += len(b[b>g_])
        return ans
 
    
    k = rgb(r,g,b) + rgb(b,g,r) +rgb_s(g,b,r)+rgb_s(g,r,b)

    print(k)


    return


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    S = next(tokens)  # type: str
    solve(N, S)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

# process
R = []
G = []
B = []
for i, s in enumerate(list(S)):
    if s == 'R':
        R.append(i)
    elif s == 'G':
        G.append(i)
    else:
        B.append(i)

ans = 0
for r in R:
    for g in G:
        if r > g:
            r, g = g, r
        
        for b in B:
            if g > b:
                g, b = b, g
            if r > g:
                r, g = g, r

            if b-g != g-r:
                ans += 1

# output
print(ans)

Submission status: Wrong Answer

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

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

    for i, si in enumerate(S):
        for j, sj in enumerate(S[i+1:]):
            if si == sj:
                continue
            for k, sk in enumerate(S[i+j+2:]):
                # print(si, sj, sk)
                # print(i+1, j+i+1, k+j+i+2)
                if j == k+1:
                    pass
                elif sj != sk and si != sk:
                    su += 1
                    # print('gets')
    print(su)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import collections
n=int(input())
s=str(input())
d=collections.defaultdict(list)
count=0
v=collections.defaultdict(int)
for i in range(n):
    d[s[i]].append(i)
for i in range(len(d["R"])):
    for j in range(i,len(d["G"])):
        for k in range(j,len(d["B"])):
            pass    
for i in range(len(d["R"])):
    for j in range(i,len(d["B"])):
        for k in range(j,len(d["G"])):
            pass
for i in range(len(d["G"])):
    for j in range(i,len(d["R"])):
        for k in range(j,len(d["B"])):
            pass
for i in range(len(d["G"])):
    for j in range(i,len(d["B"])):
        for k in range(j,len(d["R"])):
            pass
for i in range(len(d["B"])):
    for j in range(i,len(d["R"])):
        for k in range(j,len(d["G"])):
            pass
for i in range(len(d["B"])):
    for j in range(i,len(d["G"])):
        for k in range(j,len(d["R"])):
            pass
                #v[(i,j,k)]+=1
print(count)

#print(v)
#print(len(v))

Submission status: Wrong Answer

Solution code:
def main():
    N = int(input())
    S = list(str(input()))
    print()
    sum = 0
    for i in range(0, N-2):
        si = S[i]
        for j in range(i, N-1):
            sj = S[j]
            for k in range(j, N):
                sk = S[k]
                #if S[i] != S[j] and S[i] != S[k] and S[j] != S[k]:
                if si != sj and sj != sk and sj != sk:
                    if j - i != k -j:
                        sum += 1
    print(sum)



main()

Submission status: Wrong Answer

Solution code:
n=int(input())
s=input()
ss=list(range(n))
cnt=0
from itertools import combinations
for i in range(n):
    for j in range(i+1,n):
        if s[i]==s[j]:
            break
        for k in range(j+1,n):
            if j-i==k-j :
                continue
            if i<j and j<k:
                if s[i]!=s[j] and s[j]!=s[k] and s[i]!=s[k]:
                    cnt+=1

print(cnt)

Submission status: Wrong Answer

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

import random
from collections import Counter

res = 1
for i in Counter(s).values():
    res *= i

count = 0
for i in range(n):
    j = 1
    while i + 2 * j < n:
        if (s[i] != s[i+j]) and  (s[i+j] != s[i+2*j]) and (s[i] != s[i+2*j]):
            count += 1
        j += 1

print(res - count)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

for i in range(N-2) :
    for j in range(i+1,N-1) :
        for k in range(j+1,N) :
            print(i,j,k)
            if S[i] != S[j] and 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())

a = 0

for i in range(n):
  for j in range(n):
    for k in range(n):
      if i!=j and i!=k and j!=k and (j-i)!=(k-j):
        if s[i]=='R' and s[j]=='G' and s[k]=='B':
          a = a + 1
          
print(a)

Submission status: Wrong Answer

Solution code:
N = int(input())

S = input()


lS = len(S)

r = S.count("R")
g = S.count("G")
b = lS-r-g

result = r*g*b

for interval in range(1,lS//2):
    for i in range(1,lS-interval*2+1):
        Si = S[i-1]
        Sj = S[i+interval-1]
        if Si != Sj:
            Sk = S[i+interval*2-1]
            if Sk != Si and Sk != Sj:
                result -= 1

print(result)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
import sys
import numpy as np

def solve(N: int, S: str):
    r = []
    g = []
    b = []

    for i, x in enumerate(S):
        if x ==  "R":r.append(i)
        elif x =="G":g.append(i)
        elif x =="B":b.append(i)

    r = np.array(r)
    g = np.array(g)
    b = np.array(b)


    def rgb(r, g, b):
        sb = set(b)
        ans = 0
        for r_ in r:
            for g_ in g[g>r_]:
                if (g_ + (g_ - r_)) in sb:
                    ans -= 1
                ans += len(b[g_<b])
                if (r_ - (g_ - r_)) in sb:
                    ans -= 1                
                ans += len(b[b<r_])

            
        print(ans)
        return ans

    def rgb_s(r, g, b):
        sb = set(b)
        ans = 0
        for r_ in r:
            for g_ in g[g>r_]:
                if (g_ + g_ - r_) in sb:
                    ans -= 1
                ans += len(b[b>g_])
        return ans
 
    
    k = rgb(r,g,b) + rgb(b,g,r) +rgb_s(g,b,r)+rgb_s(g,r,b)

    print(k)


    return


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    S = next(tokens)  # type: str
    solve(N, S)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

r = 0
g = 0
b = 0
ans = 0
for s in S:
    if s == "R":
        r += 1
    elif s == "G":
        g += 1
    else:
        b += 1

print(r, g, b)

for i in range(len(S)-2):
    if S[i] == "R":
        # if not (S[i + 1] == "G" and S[i + 2] == "B") or (S[i + 1] == "B" and S[i + 2] == "G"):
            # ans -= 1
        ans += g * b
        r -= 1
    elif S[i] == "G":
        # if not(S[i+1] == "R" and S[i+2] == "B") or (S[i+1] == "B" and S[i+2] == "R"):
            # ans -= 1
        ans += r * b
        g -= 1
    else:
        # if not(S[i+1] == "G" and S[i+2] == "R") or (S[i+1] == "R" and S[i+2] == "G"):
        #     ans -= 1
        ans += r * g
        b -= 1

for i in range(len(S)):
    for j in range(len(S)):
        j += 1
        if i + j >= len(S) or i + j + j >= len(S):
            break
        if S[i] == "R":
            if S[i + j] == "G" and S[i + j + j] == "B" or S[i + j] == "B" and S[i + j + j] == "G":
                ans -= 1
        if S[i] == "G":
            if S[i + j] == "R" and S[i + j + j] == "B" or S[i + j] == "B" and S[i + j + j] == "R":
                ans -= 1
        if S[i] == "B":
            if S[i + j] == "G" and S[i + j + j] == "R" or S[i + j] == "R" and S[i + j + j] == "G":
                ans -= 1
print(ans)

Submission status: Wrong Answer

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

rList = []
gList = []
bList = []

for indx in range(N):
    if S[indx] == 'R':
        rList.append(indx)
    elif S[indx] == 'G':
        gList.append(indx)
    else:
        bList.append(indx)

NoSum = 0
fList = rList
sList = gList
remain = 'B'

for fItem in fList:
    for sItem in sList:
        if (max(fItem, sItem) + (max(fItem, sItem) - min(fItem, sItem)) <= N-1):
            if (S[max(fItem, sItem) + (max(fItem, sItem) - min(fItem, sItem))] == remain):
                NoSum += 1
        
        if (max(fItem, sItem) - min(fItem, sItem) % 2 == 0):
            if (S[int((max(fItem, sItem) - min(fItem, sItem))/2)] == remain):
                NoSum += 1
        
        if (min(fItem, sItem) - (max(fItem, sItem) - min(fItem, sItem)) >= 0):
            if  (S[min(fItem, sItem) - (max(fItem, sItem) - min(fItem, sItem))] == remain):
                NoSum += 1

print(len(rList) * len(gList) * len(bList) - NoSum)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

for I in i:
    for J in j:
        for K in k:
            total += 1 if J-I != K-J else 0
print(total)

Submission status: Wrong Answer

Solution code:
n = int(input())
s = input()
S = list(s[i] for i in range(n))
T = set(S)
x = 0
if len(T)<=2:
  print(0)
else:
  for i in range(n-2):
    for j in range(i+1, n-1):
      if s[i]==s[j]:
        continue
      else:
        for k in range(j+1, n):
          if {s[i], s[j], s[k]}=={"R", "G", "B"} and i+k != 2*j:
            x += 1
print(x)

Submission status: Wrong Answer

Solution code:
import numpy
import sys
import statistics

num=int(input())
txt=input()
count=0
arr=numpy.zeros(len(txt),dtype=">i4")
for i in range(len(txt)):
  if txt[i]=='G':
    arr[i]=1
  elif txt[i]=='B':
    arr[i]=2
if 0 not in arr or 1 not in arr or 2 not in arr:
  print(0)
  sys.exit()
ri=numpy.where(arr==0)[0]
gi=numpy.where(arr==1)[0]
bi=numpy.where(arr==2)[0]
for i in ri:
  for j in gi:
    for k in bi:
      mean=statistics.mean([i,j,k])
      med=statistics.median([i,j,k])
      if mean==med:
        continue
      count+=1
print(count)

Submission status: Wrong Answer

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

rs = []
gs = []
bs = []

for i in range(n):
  if s[i] == "R":
    rs.append(i)
  elif s[i] == "G":
    gs.append(i)
  elif s[i] == "B":
    bs.append(i)

def binary(lst, d):
    low = 0
    high = len(lst) - 1
    while low <= high:
        mid = (low + high) // 2
        if lst[mid] == d:
            return mid
        elif lst[mid] < d:
            low = mid + 1
        else:
            high = mid - 1
    return mid

ans = 0
for i in range(len(rs)):
  for j in range(len(gs)):
    for k in range(len(bs)):
      org_list = [rs[i], gs[j], bs[k]]
      new_list = sorted(org_list)
      if (new_list[2] - new_list[1] == new_list[1] - new_list[0]):
        print(i, j, k)
        continue
      ans += 1
print(rs, gs, bs)
print(ans)

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
p = [len(r),len(g),len(b)]
p.sort()
q = []
for i in p:
    if i == len(r):
        q.append(r)
    elif i == len(g):
        q.append(g)
    else:
        q.append(b)
for i in q[0]:
    for j in q[1]:
        for k in q[2]:
            a=[i,j,k]
            a.sort()
            if a[2]-a[1] != a[1]-a[0]:
                ans+=1
print(ans)

Submission status: Wrong Answer

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

ans = 0

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

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

Solution code:
import sys
input=sys.stdin.readline
#from collections import defaultdict
#d = defaultdict(int)
#import fractions
#import math
#import collections
#from collections import deque
#from bisect import bisect_left
N = int(input())
#A = list(map(int,input().split()))
S = list(input())
#S.remove("\n")
#N,M = map(int,input().split())
#S,T = map(str,input().split())
#A = [int(input()) for _ in range(N)]
#S = [input() for _ in range(N)]
#A = [list(map(int,input().split())) for _ in range(N)]
R = []
G = []
B = []
for i in range(N):
    a = S[i]
    if a == "R":
        R.append(i)
    elif a == "G":
        G.append(i)
    else:
        B.append(i)
s = len(R) * len(G) * len(B)
nr = len(R)
nb = len(B)
ng = len(G)
nn = max(nr,nb,ng)
def binary_search(S,key):  #昇順リストSからkeyを探す。
    n = len(S)             #存在したらindex,なかったら-1を返す
    left  = 0
    right = n
    while left < right:
        mid = (left+right) // 2
        if S[mid] == key:
            return mid
        elif S[mid] > key:
            right = mid
        else:
            left = mid + 1
    return -1
if nn == nb:
    for r in R:
        for g in G:
            Min = min(r,g)
            Max = max(r,g)
            if 2 * Min - Max > 0:
                c1 = 2 * Min - Max
            else:
                c1 = -1
            if (Min + Max ) % 2 == 0:
                c2 = (Min + Max) / 2
            else:
                c2 = -1
            if 2 * Max - Min < N:
                c3 = 2 * Max - Min
            else:
                c3 = -1
            if c1 != -1:
                if binary_search(B,c1) != -1:
                    s -= 1
            if c2 != -1:
                if binary_search(B,c2) != -1:
                    s -= 1
            if c3 != -1:
                if binary_search(B,c3) != -1:
                    s -= 1
elif nn == ng:
    for rr in R:
        for bb in B:
            Min = min(rr,bb)
            Max = max(rr,bb)
            if 2 * Min - Max > 0:
                c1 = 2 * Min - Max
            else:
                c1 = -1
            if (Min + Max ) % 2 == 0:
                c2 = (Min + Max) / 2
            else:
                c2 = -1
            if 2 * Max - Min < N:
                c3 = 2 * Max - Min
            else:
                c3 = -1
            if c1 != -1:
                if binary_search(G,c1) != -1:
                    s -= 1
            if c2 != -1:
                if binary_search(G,c2) != -1:
                    s -= 1
            if c3 != -1:
                if binary_search(G,c3) != -1:
                    s -= 1
else:
    for bbb in B:
        for ggg in G:
            Min = min(bbb,ggg)
            Max = max(bbb,ggg)
            if 2 * Min - Max > 0:
                c1 = 2 * Min - Max
            else:
                c1 = -1
            if (Min + Max ) % 2 == 0:
                c2 = (Min + Max) / 2
            else:
                c2 = -1
            if 2 * Max - Min < N:
                c3 = 2 * Max - Min
            else:
                c3 = -1
            if c1 != -1:
                if binary_search(R,c1) != -1:
                    s -= 1
            if c2 != -1:
                if binary_search(R,c2) != -1:
                    s -= 1
            if c3 != -1:
                if binary_search(R,c3) != -1:
                    s -= 1
print(s)

Submission status: Wrong Answer

Solution code:
from collections import Counter
N = int(input())
s = list(input())
a = dict(Counter(s))
value = 1
for i in a.values():
    value *= i
for i in range(N-2):
    for j in range(i,N-1):
        for k in range(j,N):
            if s[i]!=s[j] and s[j]!=s[k] and s[k]!=s[i]:
                if j-i==k-j:
                    value -= 1
print(value)

Submission status: Wrong Answer

Solution code:
n=int(input())
s=list(input())
rlist=[]
glist=[]
blist=[]
ans=0
if len(s)<=3:
    print(0)
    exit()
for i in range(n):
    if s[i]=="R":
        rlist.append(i)
    elif s[i]=="G":
        glist.append(i)
    else:
        blist.append(i)
if len(rlist)==0 or len(glist)==0 or len(blist)==0:
    print(0)
    exit()
ans+=len(rlist)*len(glist)*len(blist)
for i in glist:
    for j in blist:
        if i>j :
            if (2*i-j in rlist) or (2*j-i in rlist) or (int((i+j)/2) in rlist):
                ans-=1
        else:
            if (2*i-j in rlist) or (2*j-i in rlist) or (int((i+j)/2) in rlist):
                ans-=1


print(ans)

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)

else:
    for i in range(1,math.floor(len(s)-3/2)):
        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:
n = int(input())
s = input()
ans = 0

for i in range(n):
    si = s[i]
    for j in range(i+1, n):
        sj = s[j]
        if si == sj:
            continue
        else:
            for k in range(j+1, n):
                sk = s[k]
                if j - i != k - j and not (sj == sk == si):
                    ans += 1
print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
from math import gcd
N = int(input())
ans = 0
for a in range(1, N+1):
    for b in range(1, N+1):
        for c in range(1, N+1):
            ans += gcd(gcd(a, b), c)
print(ans)

Submission status: Wrong Answer

Solution code:
import itertools

input_line = input()
Line = list(input_line)

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

ans = 0

for i in range(len(Line)):
    if Line[i] == "R":
        R.append(i)
    if Line[i] == "G":
        G.append(i)
    if Line[i] == "B":
        B.append(i)

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

Submission status: Wrong Answer

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

if n == 1:
    print(0)
    exit(0)

r_count = 0
g_count = 0
b_count = 0
for idx, c in enumerate(s):
    if c == 'R':
        r_count += 1
    elif c == 'G':
        g_count += 1
    elif c == 'B':
        b_count += 1
# print(r_count, g_count, b_count)

i = 0
removed = 0
while True:
    i += 1
    if i >= n // 2:
        break
    for j in range(n):
        if j + i * 2 < n and s[j] != s[j + i] and s[j + i] != s[j + i * 2] and s[j] != s[j + i * 2]:
            # print(j, j + i, j + i * 2)
            removed += 1
    # print(i, removed)

print(r_count * g_count * b_count - removed)

Submission status: Wrong Answer

Solution code:
N=int(input())
S=input()
count=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)
for r in R:
  for g in G:
    for b in B:
      """
      if r<g and g<b:
        if b-g!=g-r:
          count+=1
      elif r<b and b<g:
        if g-b!=b-r:
          count+=1
      elif g<r and r<b:
        if b-r!=r-g:
          count+=1
      elif g<b and b<r:
        if r-b!=b-g:
          count+=1
      elif b<r and r<g:
        if g-r!=r-b:
          count+=1
      elif b<g and g<r:
        if r-g!=g-b:
          count+=1
      """
print(count)

Submission status: Wrong Answer

Solution code:
import sys

input = sys.stdin.readline

N = int(input())
S = input().strip()

dic = {}
ans = 0

for i in range(N-2):
    dic['R'] = S[i+1:].count('R')
    dic['G'] = S[i+1:].count('G')
    dic['B'] = S[i+1:].count('B')
    for j in range(i+1, N-1):
        dic[S[j]] -= 1
        arr = ['R', 'G', 'B']
        if S[i] != S[j]:
            arr.remove(S[i])
            arr.remove(S[j])
            ans += dic[arr[0]]
        if j+j-i <= N-1 and S[j+j-i] == arr[0]:
            ans -= 1

        #print(S[i], S[j], dic)

print(ans)

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)

else:
    for i in range(1,math.floor(len(s)-3/2)):
        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:
N = int(input())
S = 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, G, B)
ans = 0
for r in R:
    for g in G:
        for b in B:
            i = min(r, g, b)
            k = max(r, g, b)
            j = r+g+b-i-k
            if j-i != k-j:
                ans += 1

print(ans)

Submission status: Wrong Answer

Solution code:
n=int(input())
s=input()
R,G,B=[],[],[]
ans,r,g,b=0,0,0,0
for i in range(n):
  if s[i]=="R":
    R.append(i)
    r+=1
    if G!=[] and B!=[]:
      for gg in G:
        if (gg+i)/2 in B:
          ans+=b-1
        else:
          ans+=b
      for bb in B:
        if (bb+i)/2 in G:
          ans+=g-1
        else:
          ans+=g
  elif s[i]=="G":
    G.append(i)
    g+=1
    if R!=[] and B!=[]:
      for rr in R:
        if (rr+i)/2 in B:
          ans+=b-1
        else:
          ans+=b
      for bb in B:
        if (bb+i)/2 in R:
          ans+=r-1
        else:
          ans+=r
  else:
    B.append(i)
    b+=1
    if G!=[] and R!=[]:
      for gg in G:
        if (gg+i)/2 in R:
          ans+=r-1
        else:
          ans+=r
      for rr in R:
        if (rr+i)/2 in G:
          ans+=g-1
        else:
          ans+=g
print(ans)

Submission status: Wrong Answer

Solution code:
word = str(input())
word_len = len(word)
R_list = []
G_list = []
B_list = []
for i in range(word_len):
    if word[i] == "R":
        R_list.append(i+1)
    if word[i] == "G":
        G_list.append(i+1)
    if word[i] == "B":
        B_list.append(i+1)
counter = 0
for r in R_list:
    for g in G_list:
        for b in B_list:
            v =  [r,g,b]
            v.sort()
            if (v[1]-v[0]) != (v[2]-v[1]):
                counter += 1
print(counter)