Buggy python submission (verdict: Runtime Error):
import sys
#import copy
#import numpy as np
#import itertools
import collections
#from collections import deque
#from scipy.sparse.csgraph import shortest_path, floyd_warshall, dijkstra, bellman_ford, johnson
#from scipy.sparse import csr_matrix

sys.setrecursionlimit(10**6)
readline = sys.stdin.readline
read = sys.stdin.read
count = collections.Counter

def main():
    N = int(readline())
    S = input()

    values = list(count(S).values())
    ans = values[0] * values[1] * values[2]

    for i in range(N-2):
        for j in range(i+1, N-1):
            k = 2 * j - i
            if k >= N:
                break
            if S[i] != S[j] and S[i] != S[k] and S[j] != S[k]:
                ans -= 1

    print(ans)
    #print('end')


if __name__ == "__main__":
    main()


Fixed submission:
import sys
#import copy
#import numpy as np
#import itertools
import collections
#from collections import deque
#from scipy.sparse.csgraph import shortest_path, floyd_warshall, dijkstra, bellman_ford, johnson
#from scipy.sparse import csr_matrix

sys.setrecursionlimit(10**6)
readline = sys.stdin.readline
read = sys.stdin.read
count = collections.Counter

def main():
    N = int(readline())
    S = input()

    values = list(count(S).values())
    if len(values) < 3:
        print(0)
        return
    
    ans = values[0] * values[1] * values[2]

    for i in range(N-2):
        for j in range(i+1, N-1):
            k = 2 * j - i
            if k >= N:
                break
            if S[i] != S[j] and S[i] != S[k] and S[j] != S[k]:
                ans -= 1

    print(ans)
    #print('end')


if __name__ == "__main__":
    main()

Buggy python submission (verdict: Time Limit Exceeded):
import sys
#import copy
import numpy as np
#import itertools
#import collections
#from collections import deque
#from scipy.sparse.csgraph import shortest_path, floyd_warshall, dijkstra, bellman_ford, johnson
#from scipy.sparse import csr_matrix

sys.setrecursionlimit(10**6)
readline = sys.stdin.buffer.readline
read = sys.stdin.buffer.read

def main():
    N = int(readline())
    S = np.array(list(read().rstrip()), np.int8)

    #S = np.array(list(readline()))
    #print(S)

    R = np.sum(S == ord('R'))
    G = np.sum(S == ord('G'))
    B = np.sum(S == ord('B'))

    ans = R*G*B

    for i in range(N-2):
        for j in range(i+1, N-1):
            k = 2 * j - i
            if k >= N:
                break
            if S[i] != S[j] and S[i] != S[k] and S[j] != S[k]:
                ans -= 1

    print(ans)
    #print('end')


if __name__ == "__main__":
    main()


Fixed submission:
import sys
#import copy
#import numpy as np
#import itertools
import collections
#from collections import deque
#from scipy.sparse.csgraph import shortest_path, floyd_warshall, dijkstra, bellman_ford, johnson
#from scipy.sparse import csr_matrix

sys.setrecursionlimit(10**6)
readline = sys.stdin.readline
read = sys.stdin.read
count = collections.Counter

def main():
    N = int(readline())
    S = input()

    values = list(count(S).values())
    if len(values) < 3:
        print(0)
        return
    
    ans = values[0] * values[1] * values[2]

    for i in range(N-2):
        for j in range(i+1, N-1):
            k = 2 * j - i
            if k >= N:
                break
            if S[i] != S[j] and S[i] != S[k] and S[j] != S[k]:
                ans -= 1

    print(ans)
    #print('end')


if __name__ == "__main__":
    main()

Buggy python submission (verdict: Runtime Error):
import sys
#import copy
import numpy as np
#import itertools
#import collections
#from collections import deque
#from scipy.sparse.csgraph import shortest_path, floyd_warshall, dijkstra, bellman_ford, johnson
#from scipy.sparse import csr_matrix

sys.setrecursionlimit(10**6)
readline = sys.stdin.readline
read = sys.stdin.buffer.read

def main():
    # input
    N = int(readline())
    #S = np.array(list(readline()))
    S = np.array(list(read().rstrip()), np.int8)
    #print(S)

    R = np.sum(S == ord('R'))
    G = np.sum(S == ord('G'))
    B = np.sum(S == ord('B'))

    ans = R*G*B

    for i in range(N-2):
        for j in range(i+1, N-1):
            k = 2 * j - i
            if k >= N:
                break
            if S[i] != S[j] and S[i] != S[k] and S[j] != S[k]:
                ans -= 1

    print(ans)
    #print('end')


if __name__ == "__main__":
    main()


Fixed submission:
import sys
#import copy
#import numpy as np
#import itertools
import collections
#from collections import deque
#from scipy.sparse.csgraph import shortest_path, floyd_warshall, dijkstra, bellman_ford, johnson
#from scipy.sparse import csr_matrix

sys.setrecursionlimit(10**6)
readline = sys.stdin.readline
read = sys.stdin.read
count = collections.Counter

def main():
    N = int(readline())
    S = input()

    values = list(count(S).values())
    if len(values) < 3:
        print(0)
        return
    
    ans = values[0] * values[1] * values[2]

    for i in range(N-2):
        for j in range(i+1, N-1):
            k = 2 * j - i
            if k >= N:
                break
            if S[i] != S[j] and S[i] != S[k] and S[j] != S[k]:
                ans -= 1

    print(ans)
    #print('end')


if __name__ == "__main__":
    main()

Buggy python submission (verdict: Time Limit Exceeded):
import sys
#import copy
import numpy as np
#import itertools
#import collections
#from collections import deque
#from scipy.sparse.csgraph import shortest_path, floyd_warshall, dijkstra, bellman_ford, johnson
#from scipy.sparse import csr_matrix

sys.setrecursionlimit(10**6)
readline = sys.stdin.readline
#read = sys.stdin.buffer.read

def main():
    # input
    N = int(readline())
    S = np.array(list(readline()))

    R = np.sum(S == 'R')
    G = np.sum(S == 'G')
    B = np.sum(S == 'B')

    ans = R*G*B

    for i in range(N-2):
        for j in range(i+1, N-1):
            k = 2 * j - i
            if k >= N:
                break
            if S[i] != S[j] and S[i] != S[k] and S[j] != S[k]:
                ans -= 1
    
    print(ans)
    #print('end')


if __name__ == "__main__":
    main()


Fixed submission:
import sys
#import copy
#import numpy as np
#import itertools
import collections
#from collections import deque
#from scipy.sparse.csgraph import shortest_path, floyd_warshall, dijkstra, bellman_ford, johnson
#from scipy.sparse import csr_matrix

sys.setrecursionlimit(10**6)
readline = sys.stdin.readline
read = sys.stdin.read
count = collections.Counter

def main():
    N = int(readline())
    S = input()

    values = list(count(S).values())
    if len(values) < 3:
        print(0)
        return
    
    ans = values[0] * values[1] * values[2]

    for i in range(N-2):
        for j in range(i+1, N-1):
            k = 2 * j - i
            if k >= N:
                break
            if S[i] != S[j] and S[i] != S[k] and S[j] != S[k]:
                ans -= 1

    print(ans)
    #print('end')


if __name__ == "__main__":
    main()

Buggy python submission (verdict: Time Limit Exceeded):
import sys
#import copy
#import numpy as np
#import itertools
#import collections
#from collections import deque
#from scipy.sparse.csgraph import shortest_path, floyd_warshall, dijkstra, bellman_ford, johnson
#from scipy.sparse import csr_matrix

sys.setrecursionlimit(10**6)
readline = sys.stdin.readline
#read = sys.stdin.buffer.read

def main():
    # input
    N = int(readline())
    S = input()

    ans = 0
    for i in range(N-2):
        menu = ['R', 'G', 'B']
        si = S[i]
        menu.remove(si)
        for j in range(i+1, N-1):
            if S[j] == si:
                continue
            tmpmenu = menu.copy()
            sj = S[j]
            tmpmenu.remove(sj)
            sk = tmpmenu[0]
            jk_list = [k + 1 for k, v in enumerate(S[j+1:]) if v == sk]
            ans += len([n for n in jk_list if n != j-i])

    print(ans)


if __name__ == "__main__":
    main()


Fixed submission:
import sys
#import copy
#import numpy as np
#import itertools
import collections
#from collections import deque
#from scipy.sparse.csgraph import shortest_path, floyd_warshall, dijkstra, bellman_ford, johnson
#from scipy.sparse import csr_matrix

sys.setrecursionlimit(10**6)
readline = sys.stdin.readline
read = sys.stdin.read
count = collections.Counter

def main():
    N = int(readline())
    S = input()

    values = list(count(S).values())
    if len(values) < 3:
        print(0)
        return
    
    ans = values[0] * values[1] * values[2]

    for i in range(N-2):
        for j in range(i+1, N-1):
            k = 2 * j - i
            if k >= N:
                break
            if S[i] != S[j] and S[i] != S[k] and S[j] != S[k]:
                ans -= 1

    print(ans)
    #print('end')


if __name__ == "__main__":
    main()

Buggy python submission (verdict: Time Limit Exceeded):
import sys
#import copy
#import numpy as np
#import itertools
#import collections
#from collections import deque
#from scipy.sparse.csgraph import shortest_path, floyd_warshall, dijkstra, bellman_ford, johnson
#from scipy.sparse import csr_matrix

sys.setrecursionlimit(10**6)
readline = sys.stdin.readline
#read = sys.stdin.buffer.read

def main():
    # input
    N = int(readline())
    S = input()

    ans = 0
    for i in range(N-2):
        menu = ['R', 'G', 'B']
        si = S[i]
        menu.remove(si)
        for j in range(i+1, N-1):
            if S[j] == si:
                continue
            tmpmenu = menu.copy()
            sj = S[j]
            tmpmenu.remove(sj)
            sk = tmpmenu[0]
            jk_list = [k + 1 for k, v in enumerate(S[j+1:]) if v == sk]
            ans += len([n for n in jk_list if n != j-i])

    print(ans)


if __name__ == "__main__":
    main()


Fixed submission:
import sys
#import copy
#import numpy as np
#import itertools
import collections
#from collections import deque
#from scipy.sparse.csgraph import shortest_path, floyd_warshall, dijkstra, bellman_ford, johnson
#from scipy.sparse import csr_matrix

sys.setrecursionlimit(10**6)
readline = sys.stdin.readline
read = sys.stdin.read
count = collections.Counter

def main():
    N = int(readline())
    S = input()

    values = list(count(S).values())
    if len(values) < 3:
        print(0)
        return
    
    ans = values[0] * values[1] * values[2]

    for i in range(N-2):
        for j in range(i+1, N-1):
            k = 2 * j - i
            if k >= N:
                break
            if S[i] != S[j] and S[i] != S[k] and S[j] != S[k]:
                ans -= 1

    print(ans)
    #print('end')


if __name__ == "__main__":
    main()