Buggy python submission (verdict: Time Limit Exceeded):
def binary_search(list,target):

	result = -1
	left = 0
	right = len(list) - 1

	while left <= right:
		center = int((left + right)/2)
		if list[center] == target:
			result = center
			break
		elif list[center] < target:
			left = center + 1
		elif list[center] > target:
			right = center - 1

	if result == -1:
		return result
	else:
		return result


if __name__=="__main__":
    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)
    rlist=tuple(rlist)
    blist=tuple(blist)
    glist=tuple(glist)
    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 binary_search(rlist,2*i-j)!=-1:
                    ans-=1
                if binary_search(rlist,2*j-i)!=-1:
                    ans-=1
                if (i+j)/2 in rlist:
                    ans-=1
            else:
                if binary_search(rlist,2*i-j)!=-1:
                    ans-=1
                if binary_search(rlist,2*j-i)!=-1:
                    ans-=1
                if (i+j)/2 in rlist:
                    ans-=1

    print(ans)

Fixed submission:
def binary_search(list,target):

	result = -1
	left = 0
	right = len(list) - 1

	while left <= right:
		center = int((left + right)/2)
		if list[center] == target:
			result = center
			break
		elif list[center] < target:
			left = center + 1
		elif list[center] > target:
			right = center - 1

	if result == -1:
		return result
	else:
		return result


if __name__=="__main__":
    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 range(n-2):
        for j in range(i+1,n-1):
            k=2*j-i
            if s[i]==s[j]:
                continue
            elif k>len(s)-1:
                continue
            else:
                if s[k]!=s[i] and s[k]!=s[j]:
                    ans-=1

    print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
def binary_search(list,target):

	result = -1
	left = 0
	right = len(list) - 1

	while left <= right:
		center = int((left + right)/2)
		if list[center] == target:
			result = center
			break
		elif list[center] < target:
			left = center + 1
		elif list[center] > target:
			right = center - 1

	if result == -1:
		return result
	else:
		return result


if __name__=="__main__":
    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 binary_search(rlist,2*i-j)!=-1:
                    ans-=1
                if binary_search(rlist,2*j-i)!=-1:
                    ans-=1
                if (i+j)/2 in rlist:
                    ans-=1
            else:
                if binary_search(rlist,2*i-j)!=-1:
                    ans-=1
                if binary_search(rlist,2*j-i)!=-1:
                    ans-=1
                if (i+j)/2 in rlist:
                    ans-=1

    print(ans)

Fixed submission:
def binary_search(list,target):

	result = -1
	left = 0
	right = len(list) - 1

	while left <= right:
		center = int((left + right)/2)
		if list[center] == target:
			result = center
			break
		elif list[center] < target:
			left = center + 1
		elif list[center] > target:
			right = center - 1

	if result == -1:
		return result
	else:
		return result


if __name__=="__main__":
    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 range(n-2):
        for j in range(i+1,n-1):
            k=2*j-i
            if s[i]==s[j]:
                continue
            elif k>len(s)-1:
                continue
            else:
                if s[k]!=s[i] and s[k]!=s[j]:
                    ans-=1

    print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
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:
                ans-=1
            if 2*j-i in rlist:
                ans-=1
            if (i+j)/2 in rlist:
                ans-=1
        else:
            if 2*i-j in rlist:
                ans-=1
            if 2*j-i in rlist:
                ans-=1
            if (i+j)/2 in rlist:
                ans-=1

print(ans)

Fixed submission:
def binary_search(list,target):

	result = -1
	left = 0
	right = len(list) - 1

	while left <= right:
		center = int((left + right)/2)
		if list[center] == target:
			result = center
			break
		elif list[center] < target:
			left = center + 1
		elif list[center] > target:
			right = center - 1

	if result == -1:
		return result
	else:
		return result


if __name__=="__main__":
    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 range(n-2):
        for j in range(i+1,n-1):
            k=2*j-i
            if s[i]==s[j]:
                continue
            elif k>len(s)-1:
                continue
            else:
                if s[k]!=s[i] and s[k]!=s[j]:
                    ans-=1

    print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
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 rlist:
    for j in blist:
        if i>j :
            if 2*i-j in glist:
                ans-=1
        else:
            if 2*j-i in glist:
                ans-=1
for i in glist:
    for j in blist:
        if i>j :
            if 2*i-j in rlist:
                ans-=1
        else:
            if 2*j-i in rlist:
                ans-=1
for i in rlist:
    for j in glist:
        if i>j :
            if 2*i-j in blist:
                ans-=1
        else:
            if 2*j-i in blist:
                ans-=1


print(ans)

Fixed submission:
def binary_search(list,target):

	result = -1
	left = 0
	right = len(list) - 1

	while left <= right:
		center = int((left + right)/2)
		if list[center] == target:
			result = center
			break
		elif list[center] < target:
			left = center + 1
		elif list[center] > target:
			right = center - 1

	if result == -1:
		return result
	else:
		return result


if __name__=="__main__":
    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 range(n-2):
        for j in range(i+1,n-1):
            k=2*j-i
            if s[i]==s[j]:
                continue
            elif k>len(s)-1:
                continue
            else:
                if s[k]!=s[i] and s[k]!=s[j]:
                    ans-=1

    print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
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()
for i in rlist:
    for j in glist:
        for k in blist:
            tmp1=max(i,j,k)
            tmp2=min(i,j,k)
            tmp3=i+j+k-tmp1-tmp2
            if tmp2-tmp3 != tmp3-tmp1:
                ans+=1
            else:
                continue
print(ans)

Fixed submission:
def binary_search(list,target):

	result = -1
	left = 0
	right = len(list) - 1

	while left <= right:
		center = int((left + right)/2)
		if list[center] == target:
			result = center
			break
		elif list[center] < target:
			left = center + 1
		elif list[center] > target:
			right = center - 1

	if result == -1:
		return result
	else:
		return result


if __name__=="__main__":
    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 range(n-2):
        for j in range(i+1,n-1):
            k=2*j-i
            if s[i]==s[j]:
                continue
            elif k>len(s)-1:
                continue
            else:
                if s[k]!=s[i] and s[k]!=s[j]:
                    ans-=1

    print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
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()
if rlist[0] < glist[0] and glist[0]< blist[0]:
    for i in rlist:
        for j in glist:
            for k in blist:
                tmp1=max(i,j,k)
                tmp2=min(i,j,k)
                tmp3=i+j+k-tmp1-tmp2
                if tmp2-tmp3 != tmp3-tmp1:
                    ans+=1
                else:
                    continue
elif glist[0] < rlist[0] and rlist[0]< blist[0]:
    for i in glist:
        for j in rlist:
            for k in blist:
                tmp1=max(i,j,k)
                tmp2=min(i,j,k)
                tmp3=i+j+k-tmp1-tmp2
                if tmp2-tmp3 != tmp3-tmp1:
                    ans+=1
                else:
                    continue
elif glist[0] < blist[0] and blist[0]< rlist[0]:
    for i in glist:
        for j in blist:
            for k in rlist:
                tmp1=max(i,j,k)
                tmp2=min(i,j,k)
                tmp3=i+j+k-tmp1-tmp2
                if tmp2-tmp3 != tmp3-tmp1:
                    ans+=1
                else:
                    continue
elif blist[0] < glist[0] and glist[0]< rlist[0]:
    for i in blist:
        for j in glist:
            for k in rlist:
                tmp1=max(i,j,k)
                tmp2=min(i,j,k)
                tmp3=i+j+k-tmp1-tmp2
                if tmp2-tmp3 != tmp3-tmp1:
                    ans+=1
                else:
                    continue
elif blist[0] < rlist[0] and rlist[0]< glist[0]:
    for i in blist:
        for j in rlist:
            for k in glist:
                tmp1=max(i,j,k)
                tmp2=min(i,j,k)
                tmp3=i+j+k-tmp1-tmp2
                if tmp2-tmp3 != tmp3-tmp1:
                    ans+=1
                else:
                    continue
else:
    for i in rlist:
        for j in blist:
            for k in glist:
                tmp1=max(i,j,k)
                tmp2=min(i,j,k)
                tmp3=i+j+k-tmp1-tmp2
                if tmp2-tmp3 != tmp3-tmp1:
                    ans+=1
                else:
                    continue
print(ans)

Fixed submission:
def binary_search(list,target):

	result = -1
	left = 0
	right = len(list) - 1

	while left <= right:
		center = int((left + right)/2)
		if list[center] == target:
			result = center
			break
		elif list[center] < target:
			left = center + 1
		elif list[center] > target:
			right = center - 1

	if result == -1:
		return result
	else:
		return result


if __name__=="__main__":
    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 range(n-2):
        for j in range(i+1,n-1):
            k=2*j-i
            if s[i]==s[j]:
                continue
            elif k>len(s)-1:
                continue
            else:
                if s[k]!=s[i] and s[k]!=s[j]:
                    ans-=1

    print(ans)

Buggy python submission (verdict: Runtime Error):
n=int(input())
s=list(input())
rlist=[]
glist=[]
blist=[]
ans=0
for i in range(n):
    if s[i]=="R":
        rlist.append(i)
    elif s[i]=="G":
        glist.append(i)
    else:
        blist.append(i)
if rlist[0] < glist[0] and glist[0]< blist[0]:
    for i in rlist:
        for j in glist:
            for k in blist:
                tmp=[]
                tmp.append(i)
                tmp.append(j)
                tmp.append(k)
                tmp.sort()
                if tmp[1]-tmp[0] != tmp[2]-tmp[1]:
                    ans+=1
                else:
                    continue
elif glist[0] < rlist[0] and rlist[0]< blist[0]:
    for i in glist:
        for j in rlist:
            for k in blist:
                tmp=[]
                tmp.append(i)
                tmp.append(j)
                tmp.append(k)
                tmp.sort()
                if tmp[1]-tmp[0] != tmp[2]-tmp[1]:
                    ans+=1
                else:
                    continue
elif glist[0] < blist[0] and blist[0]< rlist[0]:
    for i in glist:
        for j in blist:
            for k in rlist:
                tmp=[]
                tmp.append(i)
                tmp.append(j)
                tmp.append(k)
                tmp.sort()
                if tmp[1]-tmp[0] != tmp[2]-tmp[1]:
                    ans+=1
                else:
                    continue
elif blist[0] < glist[0] and glist[0]< rlist[0]:
    for i in blist:
        for j in glist:
            for k in rlist:
                tmp=[]
                tmp.append(i)
                tmp.append(j)
                tmp.append(k)
                tmp.sort()
                if tmp[1]-tmp[0] != tmp[2]-tmp[1]:
                    ans+=1
                else:
                    continue
elif blist[0] < rlist[0] and rlist[0]< glist[0]:
    for i in blist:
        for j in rlist:
            for k in glist:
                tmp=[]
                tmp.append(i)
                tmp.append(j)
                tmp.append(k)
                tmp.sort()
                if tmp[1]-tmp[0] != tmp[2]-tmp[1]:
                    ans+=1
                else:
                    continue
else:
    for i in rlist:
        for j in blist:
            for k in glist:
                tmp=[]
                tmp.append(i)
                tmp.append(j)
                tmp.append(k)
                tmp.sort()
                if tmp[1]-tmp[0] != tmp[2]-tmp[1]:
                    ans+=1
                else:
                    continue
print(ans)

Fixed submission:
def binary_search(list,target):

	result = -1
	left = 0
	right = len(list) - 1

	while left <= right:
		center = int((left + right)/2)
		if list[center] == target:
			result = center
			break
		elif list[center] < target:
			left = center + 1
		elif list[center] > target:
			right = center - 1

	if result == -1:
		return result
	else:
		return result


if __name__=="__main__":
    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 range(n-2):
        for j in range(i+1,n-1):
            k=2*j-i
            if s[i]==s[j]:
                continue
            elif k>len(s)-1:
                continue
            else:
                if s[k]!=s[i] and s[k]!=s[j]:
                    ans-=1

    print(ans)