Buggy python submission (verdict: Time Limit Exceeded):
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)
    elif S[indx] == 'B':
        bList.append(indx)

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

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

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

Fixed submission:
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)
    elif S[indx] == 'B':
        bList.append(indx)

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

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

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

Buggy python submission (verdict: Time Limit Exceeded):
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)
    elif S[indx] == 'B':
        bList.append(indx)

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

for fItem in fList:
    for sItem in sList:
        if ((2 * max(fItem, sItem) - min(fItem, sItem)) <= N-1):
            if (S[(2 * 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 ((2 * min(fItem, sItem) - max(fItem, sItem)) >= 0):
            if  (S[(2 * min(fItem, sItem) - max(fItem, sItem))] == remain):
                NoSum += 1

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

Fixed submission:
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)
    elif S[indx] == 'B':
        bList.append(indx)

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

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

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

Buggy python submission (verdict: Time Limit Exceeded):
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)
    elif S[indx] == 'B':
        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)

Fixed submission:
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)
    elif S[indx] == 'B':
        bList.append(indx)

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

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

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

Buggy python submission (verdict: Time Limit Exceeded):
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

fList = gList
sList = bList
remain = 'R'

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

fList = bList
sList = rList
remain = 'G'

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


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

Fixed submission:
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)
    elif S[indx] == 'B':
        bList.append(indx)

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

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

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