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:
n = int(input())
s = input()
r = "R"
g = "G"
b = "B"

def find_r(start):
    offset = s[start:].find(r)
    return offset

def find_g(start):
    offset = s[start:].find(g)
    return offset

def find_b(start):
    offset = s[start:].find(b)
    return offset

sum = 0
for i in range(len(s)):
    if (s[i] == r):
        tmp1 = find_g(i+1)
        tmp2 = find_b(i+1)

        if ((tmp1 == 0) or (tmp2 == 0)):
            continue
        else:
            if (tmp1 < tmp2):
                tmp = find_b(tmp1+1)
                off1 = tmp1
                off2 = tmp - tmp1
            else:
                tmp = find_g(tmp2+1)
                off1 = tmp2
                off2 = tmp - tmp2

            if ((tmp == 0) or (off1 == off2)):
                continue
            else:
                sum += 1

    elif (s[i] == g):
        tmp1 = find_r(i+1)
        tmp2 = find_b(i+1)

        if ((tmp1 == 0) or (tmp2 == 0)):
            continue
        else:
            if (tmp1 < tmp2):
                tmp = find_r(tmp1+1)
                off1 = tmp1
                off2 = tmp - tmp1
            else:
                tmp = find_b(tmp2+1)
                off1 = tmp2
                off2 = tmp - tmp2

            if ((tmp == 0) or (off1 == off2)):
                continue
            else:
                sum += 1

    elif (s[i] == b):
        tmp1 = find_g(i+1)
        tmp2 = find_r(i+1)

        if ((tmp1 == 0) or (tmp2 == 0)):
            continue
        else:
            if (tmp1 < tmp2):
                tmp = find_g(tmp1+1)
                off1 = tmp1
                off2 = tmp - tmp1
            else:
                tmp = find_r(tmp2+1)
                off1 = tmp2
                off2 = tmp - tmp2

            if ((tmp == 0) or (off1 == off2)):
                continue
            else:
                sum += 1

print(sum)

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)

ng=0
for i in range(len(r)):
  for j in range(len(g)):
    k=g[j]+g[j]-r[i]
    l=r[i]-g[j]+r[i]
    if k in b or l in b:
      ng=ng+1

print(len(r)*len(g)*len(b)-ng)

Submission status: Wrong Answer

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

al = 0
for i in range(N):
    aaa = set()
    c1 = S[i]
    aaa.add(c1)
    for j in range(i+1,N):
        c2 = S[j]
        aaa.add(c2)
        if c1 == c2:
            continue
        if 'R' not in aaa:
            c3 = 'R'
        elif 'B' not in aaa:
            c3 = 'B'
        else :
            c3 = 'G'
        al += S[j+1:].count(c3)
        if N-1<2*j-i:
            continue
        tmp = S[2*j-i]
        if tmp != c1 and tmp != c2:
            al -= 1

ans = al
print(ans)

Submission status: Wrong Answer

Solution code:
N=int(input())
S=input()
c = 0
RGB = 'RGB'
for i in range(N-2):
  a = S[i]
  for j in range(i+1,N-1):
    if S[j] != a:
      S_ = S[j+1:]
      d = j - i
      S_ = S_[d: d+1]
      RGB = RGB.strip(a).strip(S[j])
      c += S_.count(RGB)
print(c)

Submission status: Wrong Answer

Solution code:
def get_number(n,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)
    return r, g, b

def find_ijk(x,y,z):
    count = 0
    for i in x:
        for j in y:
            for k in z:
                if j-i!=k-j:
                    count+=1
                
    return count
                    

if __name__ == "__main__":
    n = int(input())
    s = input()
    r, g, b = get_number(n,s)
    if n<=3:
        print(0)
    elif r is None or g is None or b is None:
        print(0)
    else:
        count = find_ijk(r,g,b)
        print(count)

Submission status: Wrong Answer

Solution code:
n=int(input())
s=input()
cnt=0
if n<=2:
    print(0)
    quit()
import itertools           
for i,j,k in itertools.combinations_with_replacement(range(0,n), 3):
    si,sj,sk=s[i],s[j],s[k]
    if 2j!=i+k and si!=sj and si!=sk and sj!=sk:
        cnt+=1
print(cnt)

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:
# -*- coding: utf-8 -*-
"""
Created on Sun Apr 12 22:06:39 2020

@author: H_hoshigi
"""
N = 4#int(input())
S = "RRGB"#input()

R_sum_list = [0]
G_sum_list = [0]
B_sum_list = [0]
R_sum = 0
G_sum = 0
B_sum = 0
for i in range(N):
    if S[-(i+1)] == "R":
        R_sum += 1
    elif S[-(i+1)] == "G":
        G_sum += 1
    else:
        B_sum += 1
    R_sum_list.append(R_sum)
    G_sum_list.append(G_sum)
    B_sum_list.append(B_sum)
R_sum_list = R_sum_list[::-1]
G_sum_list = G_sum_list[::-1]
B_sum_list = B_sum_list[::-1]


alphabet_list_list = [["R", "G", "B"],
                      ["R", "B", "G"],
                      ["G", "R", "B"],
                      ["G", "B", "R"],
                      ["B", "R", "G"],
                      ["B", "G", "R"],
                      ]
answer = 0
for a in range(6):
    for i in range(N):
        if S[i] == alphabet_list_list[a][0]:
            for j in range(i+1, N):
                if S[j] == alphabet_list_list[1]:
                    kosuu = 0
                    if alphabet_list_list[a][2] == "R":
                        kosuu = R_sum_list[N-j-1]
                        if S[2*j - i] == "R":
                            kosuu -= 1
                    if alphabet_list_list[a][2] == "G":
                        kosuu = G_sum_list[N-j-1]
                        if S[2*j - i] == "G":
                            kosuu -= 1
                    if alphabet_list_list[a][2] == "B":
                        kosuu = B_sum_list[N-j-1]
                        if S[2*j - i] == "B":
                            kosuu -= 1
                    answer += kosuu
print(answer)

Submission status: Wrong Answer

Solution code:
N = int(input())
S = str(input())
count = 0

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

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

for i in range(len(Rlist)):
    for j in range(i, len(Blist)):
        for k in range(j, len(Glist)):
            if j - i != k - j:
                count += 1


print(count)

Submission status: Wrong Answer

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

sum = 0
R_list = []
G_list = []
B_list = []
for i in range(N):
	if S[i]=='R':
		R_list.append(i)
	elif S[i]=='G':
		G_list.append(i)
	else:
		B_list.append(i)

print(len(R_list)*len(G_list)*len(B_list)-min(len(R_list),len(G_list),len(B_list))*min(len(R_list),len(G_list),len(B_list)))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n = int(input())
s = input().split()[0]
s = list(s)
sum = 0
for i in range(1, n):
    for j in range(i, n):
        for k in range(j, n):
            if ((s[i-1]!=s[j-1])&(s[j-1]!=s[k-1])&(s[i-1]!=s[k-1]))&((j-i)!=(k-j)):
                sum+=1
print(sum)

Submission status: Wrong Answer

Solution code:
from collections import deque
n = int(input())
S = list(input())
q = deque(S)
ans = 0
for i in range(n-2):
  c = q.popleft()
  for j in range(n-i-2):
    s = list(q)
    if c == s[j]:
      continue
    a = i+j+1
    for k in range(j+1, n-i-1):
      b = k-j
      if a == b:
        continue
      elif s[k] != c and s[k] != s[j]:
        ans += 1
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 not l_useable or not 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:
import sys
input = sys.stdin.readline
def main():
  n=int(input())
  s=str(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 l in r:
    for m in g:
      for k in b:
        if l>m>k and l-m>m-k:
          ans+=1
        elif l>k>m and l-k>k-m:
          ans+=1
        elif k>l>m and k-l>l-m:
          ans+=1
        elif k>m>l and k-m>m-l:
          ans+=1
        elif m>k>l and m-k>k-l:
          ans+=1
        elif m>l>k and m-l>l-k:
          ans+=1
        else:
          pass
  print(ans)
main()

Submission status: Wrong Answer

Solution code:
N = int(input())
S = input()
cnt = 0
import re
for i in range(N-2):
    a = S[i]
    for j in range(i+1,N-1):
        b = S[j]
        if a==b:
            continue

        if a==('R'or'G'):
            c='B'
        elif a==('G'or'B'):
            c='R'
        else:
            c='G'
            
        no = [m.span() for m in re.finditer(c, S[j+1:])]
        
        for k in no:
            if (j-i)!=((k[0]+j+1)-j):
                
                cnt += 1

print(cnt)

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 = len(R)*len(G)*len(B)


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

Submission status: Wrong Answer

Solution code:
N = int(input())
S = str(input())
count = 0

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

print(count)

Submission status: Wrong Answer

Solution code:
from itertools import combinations
n = int(input())
s = input()
count = 0
list1 = []
list = []
list2= []
for i in range(1, len(s)+1):
    list.append(i)
for c in combinations(list, 3):
    list1.append(c)
for item in list1:
    if (item[1]-item[0]) != (item[2]-item[1]):
        list2.append(item)
        for k in list2:
            if s[k[0] - 1] != s[k[1] - 1] and s[k[0] - 1] != s[k[2] - 1] and s[k[1] - 1] != s[k[2] - 1]:
                count = count + 1
print(count)

Submission status: Wrong Answer

Solution code:
N=int(input())
S=list(input())
ans=0
if N==3:
    print("0")
else:
    for i in range(N-3):
        div=S[i+1:]
        A=S[i]
        for m in range((N-i-1)//2):
            if div[m] == div[2*m-1]:
                ans-=1
        for j in range(N-i-1):
            DIV=div[j+1:]
            if not div[j] == A:
                ans+=len([k for k in DIV if k != div[j] and k != A])
    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:
    return False
  else:
    if S[i] != S[j] and S[i] != S[k] and S[j] != S[k]:
      return True
    else:
      return False

listj = list(range(N))
for i in range(N):
  for j in listj:
    for k in listj:
      if judge(i,j,k):
        R+=1

print(R)

Submission status: Wrong Answer

Solution code:
from itertools import combinations as c

def cond1(a,b,c):
    return a != b and b != c and c != a

def cond2(i,j,k):
    return j-i != k - j

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

comb_N = list(c(range(N), 3))

C = [1 for i in range(len(comb_N)) if cond1(S[comb_N[i][0]], S[comb_N[i][1]], S[comb_N[i][2]]) and cond2(*comb_N[i])]
print(C)

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]:
            continue
        else:
            RGB = 'RGB'
            RGB = RGB.strip(S[i])
            RGB = RGB.strip(S[j])
            ans += S[j+1:].count(RGB)
            x = 2*j - i
            if x < N:
                if S[x] == RGB:
                    ans -= 1
print(ans)

Submission status: Wrong Answer

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

cnt=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]!=s[k]and j-i!=k-j:
                cnt+=1

print(cnt)

Submission status: Wrong Answer

Solution code:
S = list(input())
S_len = len(S)
ans = 0
i = 0
for _ in range(S_len):
  if S[0] == 'R':
    ans += S[1:].count('B') * S[1:].count('G')
    for j in range(int(len(S)/2+1)):
      try:
        if S[j+1] != S[j*2+2] and S[j*2+2] !='R' and S[j+1] !='R':
          ans-=1
      except:
        pass
  if S[0] == 'B':
    ans += S[1:].count('R') * S[1:].count('G')
    for j in range(int(len(S)/2+1)):
      try:
        if S[j+1] != S[j*2+2] and S[j*2+2] !='B' and S[j+1] !='B':
          ans-=1
      except:
        pass
  if S[0] == 'G':
    ans += S[1:].count('B') * S[1:].count('R')
    for j in range(int(len(S)/2+1)):
      try:
        if S[j+1] != S[j*2+2] and S[j*2+2] !='G' and S[j+1] !='G':
          ans-=1
      except:
        pass
  S  = S[1:]
print(ans)

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  :
        break
    for j in range(i,n):
        if j > k :
            break
        j = i + 1
        for k in range(j,n):
            if i >= j or j >= k or i >= k :
                break
            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())
s = str(input())

r = {}
b = {}
g = {}
for i in range(len(s)):
    if s[i] == 'R':
        r[i+1] = s[i]
    elif s[i] == 'B':
        b[i+1] = s[i]
    else:
        g[i+1] = s[i]

ans = len(r) * len(b) * len(g)

for i in g.keys():
    for j in b.keys():
        diff = abs(j-i)
        if max(i,j)+diff in r.keys() or min(i,j)-diff in r.keys() or ((i+j)%2 == 0 and (i+j)//2 in r.keys()):
#        for k in g.keys():
#            if abs(k -j) == abs(j -i) or abs(k-i) == abs(i-j) or abs(k-j) == abs(k-i) :
            #print(i,j)
            ans -= 1


print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
s = input()
r = s.count("R")
g = s.count("G")
b = s.count("B")
ans = 0
ans = r*g*b
for i in range(1,n-1):
    m = min(i,n-i-1)
    for j in range(1,m+1):
        A,B,C = s[i],s[i-j],s[i+j]
        if A != B and A != C and B != C:
            ans -= 1
if r == 0 or g == 0 or b == 0 or n<4:
    ans = 0
elif r == 1 or g == 1 or b == 1:
    ans = 1
print(ans)

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

Solution code:
N = int(input())
S = list(input())
index = 0
index_ = 0
sum = 0

for i in range(1,len(S)+1):
    if(("R" in S[-i:] and "G" in S[-i:]) or ("R" in S[-i:] and "B" in S[-i:]) or ("G" in S[-i:] and "B" in S[-i:])):
        index_ = len(S) - i
        break

for i in range(1,len(S)+1):
    if("R" in S[-i:] and "G" in S[-i:] and "B" in S[-i:]):
        index = len(S) - i
        break
else:
    print(0)
for i in range(0,index+1):
    for j in range(i+1,index_+1):
        for k in range(j+1,len(S)):
            if((S[i] != S[j] and S[j] != S[k] and S[i] != S[k]) and (j-i != k-j)):
                sum += 1
print(sum)

Submission status: Wrong Answer

Solution code:
N = int(input())
S = str(input())
count = 0

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

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

for i in range(len(Rlist)):
    for j in range(len(Blist)):
        for k in range(len(Glist)):
            if j - i != k - j:
                count += 1


print(count)

Submission status: Wrong Answer

Solution code:
n=int(input(''))
s=input('')
u=0
 
l=[]
for a in s:
    l.append(a)

k=0
while k==0:
    k=1
    for a in range(len(l)-3):
        if l[a]==l[a+1]==l[a+2]:
            l.pop(a)
            k=0
        break


for i in range(0,len(l)):
    for j in range(i+1,len(l)):
        if l[i]!=l[j]:
            for k in range(j+1,len(l)):
                if j-i!=k-j:
                    if l[j]!=l[k] and l[k]!=l[i]:
                        u=u+1

print(u)

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(d["R"][i],len(d["G"])):
        count+=max(len(d["B"])-d["G"][j],0)
        if 2*j-i in d["R"]:
            count-=1
for i in range(len(d["R"])):
    for j in range(d["R"][i],len(d["B"])):
        count+=max(len(d["G"])-d["B"][j],0)
        if 2*j-i in d["G"]:
            count-=1
            
for i in range(len(d["G"])):
    for j in range(d["G"][i],len(d["R"])):
        count+=max(len(d["B"])-d["R"][j],0)
        if 2*j-i in d["B"]:
            count-=1
for i in range(len(d["G"])):
    for j in range(d["G"][i],len(d["B"])):
        count+=max(len(d["R"])-d["B"][j],0)
        if 2*j-i in d["R"]:
            count-=1
for i in range(len(d["B"])):
    for j in range(d["B"][i],len(d["R"])):
        count+=max(len(d["G"])-d["R"][j],0)
        if 2*j-i in d["G"]:
            count-=1
for i in range(len(d["B"])):
    for j in range(i,len(d["G"])):
        count+=max(len(d["R"])-d["G"][j],0)
        if 2*j-i in d["R"]:
            count-=1
print(count)

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

Submission status: Wrong Answer

Solution code:
n = int(input())
s = input()
r = s.count("R")
g = s.count("G")
b = s.count("B")
ans = 0
ans = r*g*b
for i in range(1,n-1):
    m = min(i,n-i-1)
    for j in range(1,m+1):
        A,B,C = s[i],s[i-j],s[i+j]
        if A != B and A != C and B != C:
            ans -= 1
if r == 0 or g == 0 or b == 0 or n<3:
    ans = 0
elif r == 1 or g == 1 or b == 1:
    ans = 1
print(ans)

Submission status: Wrong Answer

Solution code:
n=int(input())
s=input()
counter=0
for i in range(1,n+1):
    for j in range(i+1,n+1):
        for k in range(j+1,n+1):
            if 2*j==i+k:
                break
            else:
                if s[i-1]!=s[j-1] and s[i-1]!=s[k-1] and s[j-1]!=s[k-1]:
                    counter+=1
print(counter)

Submission status: Wrong Answer

Solution code:
i = int(input())
l = str(input())
ll = len(l)

count = 0

m=0
mm = 0
mmm = 0
for k in l:
    m+=1
    for kk in l:
        mm +=1
        if k == kk:
            break
        if m <= mm:
            break
        for kkk in l:
            mmm += 1
            if kk != kkk and k != kkk and mm <= mmm and (mm-m) != (mmm - mm):
                count+=1
        mmm=0
    mm=0
print()

print(count)

Submission status: Wrong Answer

Solution code:
N=int(input())
S=str(input())
sum=0

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

Submission status: Wrong Answer

Solution code:
n = int(input())

rgb = input()

r = []
g = []
B = []

for i in range(n):
    if rgb[i] == "R":
        r.append(i + 1)
    elif rgb[i] == "G":
        g.append(i + 1)
    elif rgb[i] == "B":
        B.append(i + 1)

ans = 0

for a in r:
    for b in g:
        for c in B:
            if float(a + c) / 2.0  == b:continue
            ans += 1

print(ans)

Submission status: Wrong Answer

Solution code:
import re
n = int(input())
s = input()
result = s.count("R")*s.count("G")*s.count("B")
for i in range((n-3)//2+1):
    work = []
    work.append("R"+"."*i+"G"+"."*i+"B")
    work.append("R"+"."*i+"B"+"."*i+"G")
    work.append("G"+"."*i+"R"+"."*i+"B")
    work.append("G"+"."*i+"B"+"."*i+"R")
    work.append("B"+"."*i+"R"+"."*i+"G")
    work.append("B"+"."*i+"G"+"."*i+"R")
    for w in work:
        result -= len(re.findall(w, s))
print(result)

Submission status: Wrong Answer

Solution code:
N = (int)(input())
s = input()
ans = 0
r = []
g = []
b = []
for i in range(N):
    if(s[i] == "R"):
        r.append(i)
    elif(s[i] == "G"):
        g.append(i)
    elif(s[i] == "B"):
        b.append(i)
ans = len(r)*len(g)*len(b)
print(ans)
for i in range(len(r)):
    for j in range(len(g)):
        if(int((r[i] + g[j]))/2 in b) == True:
            ans -= 1
        if (int((2*r[i] -g[j])) in b) == True: 
            ans -= 1
        if (int((2*g[j] - r[i])) in b) == True:
            ans -= 1
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
s = list(input())
r = []
g = []
b = []
for _ in range(n):
    if s[_] == 'R':
        r.append(_)
    elif s[_] == 'G':
        g.append(_)
    else:
        b.append(_)

a = s.count('R') * s.count('G') * s.count('B')

for i in r:
    for j in g:
        i = min(i, j)
        j = max(i, j)
        lar = j * 2 - i
        sma = i * 2 - j
        if (i + j) % 2 == 0:
            med = int((i + j) / 2)
        else:
            med = n
        if 0 <= lar < n and s[lar] == 'B':
            a -= 1
        if 0 <= med < n and s[med] == 'B':
            a -= 1
        if 0 <= sma < n and s[sma] == 'B':
            a -= 1

print(a)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Sun Apr 12 22:06:39 2020

@author: H_hoshigi
"""
N = int(input())
S = input()

R_sum_list = [0]
G_sum_list = [0]
B_sum_list = [0]
R_sum = 0
G_sum = 0
B_sum = 0
for i in range(N):
    if S[-(i+1)] == "R":
        R_sum += 1
    elif S[-(i+1)] == "G":
        G_sum += 1
    else:
        B_sum += 1
    R_sum_list.append(R_sum)
    G_sum_list.append(G_sum)
    B_sum_list.append(B_sum)
R_sum_list = R_sum_list[::-1]
G_sum_list = G_sum_list[::-1]
B_sum_list = B_sum_list[::-1]


alphabet_list_list = [["R", "G", "B"],
                      ["R", "B", "G"],
                      ["G", "R", "B"],
                      ["G", "B", "R"],
                      ["B", "R", "G"],
                      ["B", "G", "R"],
                      ]
answer = 0
for a in range(6):
    for i in range(N):
        if S[i] == alphabet_list_list[0]:
            for j in range(i+1, N):
                if S[j] == alphabet_list_list[1]:
                    kosuu = 0
                    if alphabet_list_list[2] == "R":
                        kosuu = R_sum_list[N-j-1]
                        if S[2*j - i] == "R":
                            kosuu -= 1
                    if alphabet_list_list[2] == "G":
                        kosuu = G_sum_list[N-j-1]
                        if S[2*j - i] == "G":
                            kosuu -= 1
                    if alphabet_list_list[2] == "B":
                        kosuu = B_sum_list[N-j-1]
                        if S[2*j - i] == "B":
                            kosuu -= 1
                    answer += kosuu
print(answer)

Submission status: Wrong Answer

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

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

    print(d)


main

Submission status: Wrong Answer

Solution code:
N = int(input())
S = str(input())
count = 0

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

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

for i in range(len(Rlist)):
    for j in range(len(Blist)):
        for k in range(len(Glist)):
            if j - i != k - j:
                count += 1


print(count)

Submission status: Wrong Answer

Solution code:
N=int(input())
A=input()
c=0
B1B=0
B1R=0
B1G=0
if A[0]=="B":
 B1B+=1
elif A[0]=="R":
 B1R+=1
else:
 B1G+=1
for i in range(N-2):
 B2=A[i+1]
 for k in range(N-i-2):
  B3=A[i+2+k]
  if (B2=="B" and B3=="R")or (B2=="R" and B3=="B"):
   c+=B1G
   if (i+2+k)<=(i+1)*2:
    if A[(i+1)*2-(i+2+k)]=="G":
     c-=1
  if (B2=="G" and B3=="R")or (B2=="R" and B3=="G"):
   c+=B1B
   if (i+2+k)<=(i+1)*2:
    if A[(i+1)*2-(i+2+k)]=="B":
     c-=1
  if (B2=="B" and B3=="G")or (B2=="G" and B3=="B"):
   c+=B1R
   if (i+2+k)<=(i+1)*2:
    if A[(i+1)*2-(i+2+k)]=="R":
     c-=1
  if B2=="B":
   B1B+=1
  elif B2=="R":
   B1R+=1
  else:
   B1G+=1
print(c)

Submission status: Wrong Answer

Solution code:
N = int(input())
S = input()
cnt = 0
import re
for i in range(N-2):
    a = S[i]
    for j in range(i+1,N-1):
        b = S[j]
        if a==b:
            continue

        if a==('R'or'G'):
            c='B'
        elif a==('G'or'B'):
            c='R'
        else:
            c='G'
            
       
        no = [m.span() for m in re.finditer(c, S)]
        
        for k in no:
            if ((j-i)!=(k[0]-j))and(k[0]>j):
                
                cnt += 1

print(cnt)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Rcnt = 0
Gcnt = 0

excep = 0

for i in range(len(S)):
    if S[i] == 'R':
        Rcnt += 1
    elif S[i] == 'G':
        Gcnt += 1
    for j in range(1, (len(S)//2)):
        if i+j+j < len(S) and S[i] != S[i+j]:
            if S[i] != S[i+j+j] and S[i+j] != S[i+j+j]:
                excep += 1

RGBcalc = Rcnt * Gcnt * (N - Rcnt - Gcnt)

print(RGBcalc - excep)

Submission status: Wrong Answer

Solution code:
import collections

N = int(input())
S = input()
ans = 0

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

for i in r_index:
    for j in g_index:
        for k in b_index:
            if abs(j-i) == abs(k-j):
                continue
            else:
                ans += 1
print(ans)

Submission status: Wrong Answer

Solution code:
from collections import defaultdict

rind = set()
gind = set()
bind = set()

N = int(input())
S = input()
for i, ch in enumerate(S):
    if ch == 'R':
        rind.add(i)
    elif ch == 'G':
        gind.add(i)
    else:
        bind.add(i)

total = len(rind) * len(gind) * len(bind)
choices = set()
for r in rind:
    for g in gind:
        diff = abs(r - g)
        l, r = min([r, g]), max([r, g])
        if l - diff in bind:
            choices.add(tuple([l-diff, l, r]))
        if r + diff in bind:
            choices.add(tuple([l, r, r + diff]))
        if diff % 2 == 0 and (l + (diff // 2)) in bind:
            choices.add(tuple([l, l + diff // 2, r]))
print(total - len(choices) ** 2)

Submission status: Wrong Answer

Solution code:
N = (int)(input())
s = input()
ans = 0
r = []
g = []
b = []
for i in range(N):
    if(s[i] == "R"):
        r.append(i)
    elif(s[i] == "G"):
        g.append(i)
    elif(s[i] == "B"):
        b.append(i)
ans = len(r)*len(g)*len(b)
print(ans)
cta = 0
ctb = 0
ctc = 0
for i in range(len(r)):
    for j in range(len(g)):
        if(int((r[i] + g[j]))/2 in b) == True:
            ans -= 1
            cta += 1
        if (int((2*r[i] -g[j])) in b) == True: 
            ans -= 1
            ctb += 1
        if (int((2*g[j] - r[i])) in b) == True:
            ans -= 1
            ctc += 1
print(ans)