Buggy python submission (verdict: Time Limit Exceeded):
import re

def main():
    NumString = int(input())
    String = input()
    
    total_ans = 0
    for i, i_string in enumerate(String[:-2]):
        RGB = 'RGB'
        for j, j_string in enumerate(String[i+1:-1], i+1):
            if i_string == j_string:
                continue

            k_RGB = RGB.replace(i_string, '').replace(j_string, '')
            total_ans += String.count(k_RGB, j+1)
            if (j + (j-i)) < NumString and String[j + (j-i)] == k_RGB:
                total_ans -= 1
    
    print(total_ans)

if __name__ == '__main__':
    main()

Fixed submission:
NumString = int(input())
String = input()

r_string_num, g_string_num, b_string_num = 0, 0, 0
for i_string in String:
    if i_string == 'R':
        r_string_num += 1
    elif i_string == 'G':
        g_string_num += 1
    else:
        b_string_num += 1
    
total_ans = r_string_num * g_string_num * b_string_num

exclude_num = 0
for i in range(NumString-2):
    for j in range(i+1, NumString-1):
        if (2*j - i) < NumString and String[i] != String[j] and \
            String[j] != String[2*j-i] and String[i] != String[2*j-i]:
            exclude_num += 1

total_ans -= exclude_num

print(total_ans)

Buggy python submission (verdict: Time Limit Exceeded):
import re

def main():
    NumString = int(input())
    String = input()
    
    total_ans = 0
    for i in range(NumString):
        RGB = 'RGB'
        for j in range(i+1, NumString):
            if String[i] == String[j]:
                continue

            k_RGB = RGB.replace(String[i], '').replace(String[j], '')
            total_ans += String.count(k_RGB, j+1)
            if (j + (j-i)) < NumString and String[j + (j-i)] == k_RGB:
                total_ans -= 1
    
    print(total_ans)

if __name__ == '__main__':
    main()

Fixed submission:
NumString = int(input())
String = input()

r_string_num, g_string_num, b_string_num = 0, 0, 0
for i_string in String:
    if i_string == 'R':
        r_string_num += 1
    elif i_string == 'G':
        g_string_num += 1
    else:
        b_string_num += 1
    
total_ans = r_string_num * g_string_num * b_string_num

exclude_num = 0
for i in range(NumString-2):
    for j in range(i+1, NumString-1):
        if (2*j - i) < NumString and String[i] != String[j] and \
            String[j] != String[2*j-i] and String[i] != String[2*j-i]:
            exclude_num += 1

total_ans -= exclude_num

print(total_ans)

Buggy python submission (verdict: Time Limit Exceeded):
import re

def main():
    NumString = int(input())
    String = input()
    
    total_ans = 0
    for i in range(NumString):
        i_RGB = 'RGB'
        for j in range(i+1, NumString):
            j_RGB = re.sub(String[i], '', i_RGB)
            if String[i] == String[j]:
                continue

            k_RGB = re.sub(String[j], '', j_RGB)
            total_ans += String.count(k_RGB, j+1)
            if (j + (j-i)) < NumString and String[j + (j-i)] == k_RGB:
                total_ans -= 1
    
    print(total_ans)

if __name__ == '__main__':
    main()

Fixed submission:
NumString = int(input())
String = input()

r_string_num, g_string_num, b_string_num = 0, 0, 0
for i_string in String:
    if i_string == 'R':
        r_string_num += 1
    elif i_string == 'G':
        g_string_num += 1
    else:
        b_string_num += 1
    
total_ans = r_string_num * g_string_num * b_string_num

exclude_num = 0
for i in range(NumString-2):
    for j in range(i+1, NumString-1):
        if (2*j - i) < NumString and String[i] != String[j] and \
            String[j] != String[2*j-i] and String[i] != String[2*j-i]:
            exclude_num += 1

total_ans -= exclude_num

print(total_ans)

Buggy python submission (verdict: Time Limit Exceeded):
def main():
    NumString = int(input())
    String = input()
    
    total_ans = 0
    for i in range(NumString):
        for j in range(i, NumString):
            for k in range(j, NumString):
                if String[i] != String[j] and String[j] != String[k] and \
                    String[i] != String[k] and j - i != k - j:
                    total_ans += 1
    
    print(total_ans)

if __name__ == '__main__':
    main()

Fixed submission:
NumString = int(input())
String = input()

r_string_num, g_string_num, b_string_num = 0, 0, 0
for i_string in String:
    if i_string == 'R':
        r_string_num += 1
    elif i_string == 'G':
        g_string_num += 1
    else:
        b_string_num += 1
    
total_ans = r_string_num * g_string_num * b_string_num

exclude_num = 0
for i in range(NumString-2):
    for j in range(i+1, NumString-1):
        if (2*j - i) < NumString and String[i] != String[j] and \
            String[j] != String[2*j-i] and String[i] != String[2*j-i]:
            exclude_num += 1

total_ans -= exclude_num

print(total_ans)

Buggy python submission (verdict: Time Limit Exceeded):
NumString = int(input())
String = input()

total_ans = 0
for i in range(NumString):
    for j in range(i, NumString):
        for k in range(j, NumString):
            if String[i] != String[j] and String[j] != String[k] and \
                String[i] != String[k] and j - i != k - j:
                total_ans += 1

print(total_ans)

Fixed submission:
NumString = int(input())
String = input()

r_string_num, g_string_num, b_string_num = 0, 0, 0
for i_string in String:
    if i_string == 'R':
        r_string_num += 1
    elif i_string == 'G':
        g_string_num += 1
    else:
        b_string_num += 1
    
total_ans = r_string_num * g_string_num * b_string_num

exclude_num = 0
for i in range(NumString-2):
    for j in range(i+1, NumString-1):
        if (2*j - i) < NumString and String[i] != String[j] and \
            String[j] != String[2*j-i] and String[i] != String[2*j-i]:
            exclude_num += 1

total_ans -= exclude_num

print(total_ans)