Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
S=input()
dictR=[]
dictG=[]
dictB=[]
r=0
g=0
b=0
r=S.count("R")
g=S.count("G")
b=S.count("B")
sum=r*g*b
for i in range(n):
    for j in range(i+1,n):
        for k in range(j+1,n):
            si=S[i]
            sj=S[j]
            sk=S[k]
            if k-j!=j-i or (si==sj or sj==sk or si==sk):
                sum+=1



print(sum-(n*(n-1)*(n-2)//6))

Fixed submission:
n=int(input())
S=input()
R={}
G={}
B={}
r=0
g=0
b=0
for i in range(n):
    if S[i] == 'R':
        R[i] = None
    elif S[i] == 'G':
        G[i] = None
    else:
        B[i] = None
cnt=len(R)*len(G)*len(B)
for b in B:
    for g in G:
        if (b+g)/2 in R:
            cnt-=1
for b in B:
    for r in R:
        if (b+r)/2 in G:
            cnt-=1
for r in R:
    for g in G:
        if (r+g)/2 in B:
            cnt-=1
print(cnt)

Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
S=input()
dictR=[]
dictG=[]
dictB=[]
r=0
g=0
b=0
r=S.count("R")
g=S.count("G")
b=S.count("B")
sum=r*g*b
for i in range(n):
    for j in range(i+1,n):
        for k in range(j+1,n):
            si=S[i]
            sj=S[j]
            sk=S[k]
            if k-j==j-i and(si!=sj and sj!=sk and si!=sk):
                sum-=1



print(sum)

Fixed submission:
n=int(input())
S=input()
R={}
G={}
B={}
r=0
g=0
b=0
for i in range(n):
    if S[i] == 'R':
        R[i] = None
    elif S[i] == 'G':
        G[i] = None
    else:
        B[i] = None
cnt=len(R)*len(G)*len(B)
for b in B:
    for g in G:
        if (b+g)/2 in R:
            cnt-=1
for b in B:
    for r in R:
        if (b+r)/2 in G:
            cnt-=1
for r in R:
    for g in G:
        if (r+g)/2 in B:
            cnt-=1
print(cnt)

Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
S=input()
dictR=[]
dictG=[]
dictB=[]
r=0
g=0
b=0
r=S.count("R")
g=S.count("G")
b=S.count("B")
sum=r*g*b
for i in range(n):
    for j in range(i+1,n):
        for k in range(j+1,n):
            if k-j==j-i and(S[i]!=S[j] and S[j]!=S[k] and S[i]!=S[k]):
                sum-=1



print(sum)

Fixed submission:
n=int(input())
S=input()
R={}
G={}
B={}
r=0
g=0
b=0
for i in range(n):
    if S[i] == 'R':
        R[i] = None
    elif S[i] == 'G':
        G[i] = None
    else:
        B[i] = None
cnt=len(R)*len(G)*len(B)
for b in B:
    for g in G:
        if (b+g)/2 in R:
            cnt-=1
for b in B:
    for r in R:
        if (b+r)/2 in G:
            cnt-=1
for r in R:
    for g in G:
        if (r+g)/2 in B:
            cnt-=1
print(cnt)

Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
S=input()
dictR=[]
dictG=[]
dictB=[]
r=0
g=0
b=0
for i in range(len(S)):
    if S[i]=="R":
        dictR.append(i)
        r+=1
    elif S[i]=="G":
        dictG.append(i)
        g+=1
    else:
        dictB.append(i)
        b+=1
sum=r*g*b
if sum!=0:
    for i in dictR:
        for j in dictG:
            for k in dictB:
                maxi=max(i,max(j,k))
                mini=min(i,min(j,k))
                medi=i+j+k-maxi-mini
                if maxi-medi==medi-mini:
                    sum-=1

print(sum)

Fixed submission:
n=int(input())
S=input()
R={}
G={}
B={}
r=0
g=0
b=0
for i in range(n):
    if S[i] == 'R':
        R[i] = None
    elif S[i] == 'G':
        G[i] = None
    else:
        B[i] = None
cnt=len(R)*len(G)*len(B)
for b in B:
    for g in G:
        if (b+g)/2 in R:
            cnt-=1
for b in B:
    for r in R:
        if (b+r)/2 in G:
            cnt-=1
for r in R:
    for g in G:
        if (r+g)/2 in B:
            cnt-=1
print(cnt)

Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
S=input()
dictR=[]
dictG=[]
dictB=[]
r=0
g=0
b=0
for i in range(len(S)):
    if S[i]=="R":
        dictR.append(i)
        r+=1
    elif S[i]=="G":
        dictG.append(i)
        g+=1
    else:
        dictB.append(i)
        b+=1
sum=r*g*b
if sum!=0:
    for i in dictR:
        for j in dictG:
            for k in dictB:
                maxi=max(i,max(j,k))
                mini=min(i,min(j,k))
                medi=i+j+k-maxi-mini
                if maxi-medi==medi-mini:
                    sum-=1

print(sum)

Fixed submission:
n=int(input())
S=input()
R={}
G={}
B={}
r=0
g=0
b=0
for i in range(n):
    if S[i] == 'R':
        R[i] = None
    elif S[i] == 'G':
        G[i] = None
    else:
        B[i] = None
cnt=len(R)*len(G)*len(B)
for b in B:
    for g in G:
        if (b+g)/2 in R:
            cnt-=1
for b in B:
    for r in R:
        if (b+r)/2 in G:
            cnt-=1
for r in R:
    for g in G:
        if (r+g)/2 in B:
            cnt-=1
print(cnt)

Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
S=input()
dictR=[]
dictG=[]
dictB=[]
for i in range(len(S)):
    if S[i]=="R":
        dictR.append(i)
    elif S[i]=="G":
        dictG.append(i)
    else:
        dictB.append(i)
sum=len(dictR)*len(dictG)*len(dictB)
if sum!=0:
    for i in dictR:
        for j in dictG:
            for k in dictB:
                maxi=max(i,max(j,k))
                mini=min(i,min(j,k))
                medi=i+j+k-maxi-mini
                if maxi-medi==medi-mini:
                    sum-=1

print(sum)

Fixed submission:
n=int(input())
S=input()
R={}
G={}
B={}
r=0
g=0
b=0
for i in range(n):
    if S[i] == 'R':
        R[i] = None
    elif S[i] == 'G':
        G[i] = None
    else:
        B[i] = None
cnt=len(R)*len(G)*len(B)
for b in B:
    for g in G:
        if (b+g)/2 in R:
            cnt-=1
for b in B:
    for r in R:
        if (b+r)/2 in G:
            cnt-=1
for r in R:
    for g in G:
        if (r+g)/2 in B:
            cnt-=1
print(cnt)

Buggy python submission (verdict: Time Limit Exceeded):
def numS(S):
    x=len(S)
    if x<4:
        return 0
    T=S[1:]
   # print(T)
    l=x-1
    sum=0
    now=S[0]
    for i in range(l):
        now2=T[i]
    #    print(now2)
        if now2!=now:
            for j in range(i+1,l):
                now3=T[j]
     #           print(now,now2,now3)
                if now3!=now2 and now3!=now:
      #              print(i,j)
                    sum+=1
                    if 2*i+1==j:
                        sum-=1
    return numS(T)+sum
n=int(input())
S=input()
print(numS(S))

Fixed submission:
n=int(input())
S=input()
R={}
G={}
B={}
r=0
g=0
b=0
for i in range(n):
    if S[i] == 'R':
        R[i] = None
    elif S[i] == 'G':
        G[i] = None
    else:
        B[i] = None
cnt=len(R)*len(G)*len(B)
for b in B:
    for g in G:
        if (b+g)/2 in R:
            cnt-=1
for b in B:
    for r in R:
        if (b+r)/2 in G:
            cnt-=1
for r in R:
    for g in G:
        if (r+g)/2 in B:
            cnt-=1
print(cnt)

Buggy python submission (verdict: Runtime Error):
def numS(S):
    x=len(S)
    if x<4:
        return 0
    T=S[1:]
   # print(T)
   l=x-1
    sum=0
    now=S[0]
    for i in range(l):
        now2=T[i]
    #    print(now2)
        if now2!=now:
            for j in range(i+1,l):
                now3=T[j]
     #           print(now,now2,now3)
                if now3!=now2 and now3!=now:
      #              print(i,j)
                    sum+=1
                    if 2*i+1==j:
                        sum-=1
    return numS(T)+sum
n=int(input())
S=input()
print(numS(S))

Fixed submission:
n=int(input())
S=input()
R={}
G={}
B={}
r=0
g=0
b=0
for i in range(n):
    if S[i] == 'R':
        R[i] = None
    elif S[i] == 'G':
        G[i] = None
    else:
        B[i] = None
cnt=len(R)*len(G)*len(B)
for b in B:
    for g in G:
        if (b+g)/2 in R:
            cnt-=1
for b in B:
    for r in R:
        if (b+r)/2 in G:
            cnt-=1
for r in R:
    for g in G:
        if (r+g)/2 in B:
            cnt-=1
print(cnt)

Buggy python submission (verdict: Time Limit Exceeded):
def numS(S):
    if len(S)<4:
        return 0
    T=S[1:]
   # print(T)
    sum=0
    now=S[0]
    for i in range(len(T)):
        now2=T[i]
    #    print(now2)
        if now2!=now:
            for j in range(i+1,len(T)):
                now3=T[j]
     #           print(now,now2,now3)
                if now3!=now2 and now3!=now:
      #              print(i,j)
                    sum+=1
                    if 2*i+1==j:
                        sum-=1
    return numS(T)+sum
n=int(input())
S=input()
print(numS(S))

Fixed submission:
n=int(input())
S=input()
R={}
G={}
B={}
r=0
g=0
b=0
for i in range(n):
    if S[i] == 'R':
        R[i] = None
    elif S[i] == 'G':
        G[i] = None
    else:
        B[i] = None
cnt=len(R)*len(G)*len(B)
for b in B:
    for g in G:
        if (b+g)/2 in R:
            cnt-=1
for b in B:
    for r in R:
        if (b+r)/2 in G:
            cnt-=1
for r in R:
    for g in G:
        if (r+g)/2 in B:
            cnt-=1
print(cnt)

Buggy python submission (verdict: Time Limit Exceeded):
def numS(S):
    if len(S)<4:
        return 0
    T=S[1:]
   # print(T)
    sum=0
    now=S[0]
    for i in range(len(T)):
        now2=T[i]
    #    print(now2)
        if now2!=now:
            for j in range(i+1,len(T)):
                now3=T[j]
     #           print(now,now2,now3)
                if now3!=now2 and now3!=now:
      #              print(i,j)
                    sum+=1
                    if 2*i+1==j:
                        sum-=1
    return numS(T)+sum
n=int(input())
S=input()
print(numS(S))

Fixed submission:
n=int(input())
S=input()
R={}
G={}
B={}
r=0
g=0
b=0
for i in range(n):
    if S[i] == 'R':
        R[i] = None
    elif S[i] == 'G':
        G[i] = None
    else:
        B[i] = None
cnt=len(R)*len(G)*len(B)
for b in B:
    for g in G:
        if (b+g)/2 in R:
            cnt-=1
for b in B:
    for r in R:
        if (b+r)/2 in G:
            cnt-=1
for r in R:
    for g in G:
        if (r+g)/2 in B:
            cnt-=1
print(cnt)