Buggy python submission (verdict: Time Limit Exceeded):
import sys
def input():
    return sys.stdin.readline()[:-1]


def main():
    N = int(input())
    S = list(input())
    c = [[] for _ in range(3)] #c = [[]] * 3 とすると全ての要素にappendされてしまうのでNG
    for i in range(len(S)):
        if S[i] == 'R':
            c[0].append(i)
        elif S[i] == 'G':
            c[1].append(i)
        else : # 'B'のとき
            c[2].append(i)
    total = len(c[0]) * len(c[1]) * len(c[2])
    
    reigai = 0
    for i in c[0]:
        for j in c[1]:
            s = j - i # i < j と仮定して差を求める。逆の場合は負の値になるのでOK
            if j + s in c[2]:
                reigai += 1
            if i - s in c[2]:
                reigai += 1
            if (i + j) / 2 in c[2]:
                reigai += 1
    print(total - reigai)


if __name__ == "__main__":
    main()

Fixed submission:
import sys
def input():
    return sys.stdin.readline()[:-1]


def main():
    N = int(input())
    S = list(input())
 
    c = [[] for _ in range(3)] #c = [[]] * 3 とすると全ての要素にappendされてしまうのでNG
    for i in range(len(S)):
        if S[i] == 'R':
            c[0].append(i)
        elif S[i] == 'G':
            c[1].append(i)
        else : # 'B'のとき
            c[2].append(i)
    total = len(c[0]) * len(c[1]) * len(c[2])

    reigai = 0 #先に条件2を満たすものを考えてから、条件1に当てはまるかを判定
    for i in range(N - 2):
        for j in range(i + 1, N - 1):
            k = j + (j - i)
            if k >= N:
                break
            if S[i] != S[j] and S[i] != S[k] and S[j] != S[k]:
                reigai += 1
    print(total - reigai)


if __name__ == "__main__":
    main()

Buggy python submission (verdict: Time Limit Exceeded):
import sys
def input():
    return sys.stdin.readline()[:-1]


def main():
    N = int(input())
    S = list(input())
    c = [[] for _ in range(3)] #c = [[]] * 3 とすると全ての要素にappendされてしまうのでNG
    for i in range(len(S)):
        if S[i] == 'R':
            c[0].append(i)
        elif S[i] == 'G':
            c[1].append(i)
        else : # 'B'のとき
            c[2].append(i)
    total = len(c[0]) * len(c[1]) * len(c[2])
    
    reigai = 0
    for i in c[0]:
        for j in c[1]:
            s = j - i # i < j と仮定して差を求める。逆の場合は負の値になるのでOK
            if j + s in c[2]:
                reigai += 1
            if i - s in c[2]:
                reigai += 1
            if (i + j) / 2 in c[2]:
                reigai += 1
    print(total - reigai)


if __name__ == "__main__":
    main()

Fixed submission:
import sys
def input():
    return sys.stdin.readline()[:-1]


def main():
    N = int(input())
    S = list(input())
 
    c = [[] for _ in range(3)] #c = [[]] * 3 とすると全ての要素にappendされてしまうのでNG
    for i in range(len(S)):
        if S[i] == 'R':
            c[0].append(i)
        elif S[i] == 'G':
            c[1].append(i)
        else : # 'B'のとき
            c[2].append(i)
    total = len(c[0]) * len(c[1]) * len(c[2])

    reigai = 0 #先に条件2を満たすものを考えてから、条件1に当てはまるかを判定
    for i in range(N - 2):
        for j in range(i + 1, N - 1):
            k = j + (j - i)
            if k >= N:
                break
            if S[i] != S[j] and S[i] != S[k] and S[j] != S[k]:
                reigai += 1
    print(total - reigai)


if __name__ == "__main__":
    main()

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
S = list(input())

from itertools import combinations

lis = list(range(1, N+1))
s = [1 for v in combinations(lis, 3)
     if v[1] - v[0] != v[2] - v[1] and S[v[0]-1] != S[v[1]-1] and S[v[0]-1] != S[v[2]-1] and S[v[1]-1] != S[v[2]-1]]

print(len(s))


Fixed submission:
import sys
def input():
    return sys.stdin.readline()[:-1]


def main():
    N = int(input())
    S = list(input())
 
    c = [[] for _ in range(3)] #c = [[]] * 3 とすると全ての要素にappendされてしまうのでNG
    for i in range(len(S)):
        if S[i] == 'R':
            c[0].append(i)
        elif S[i] == 'G':
            c[1].append(i)
        else : # 'B'のとき
            c[2].append(i)
    total = len(c[0]) * len(c[1]) * len(c[2])

    reigai = 0 #先に条件2を満たすものを考えてから、条件1に当てはまるかを判定
    for i in range(N - 2):
        for j in range(i + 1, N - 1):
            k = j + (j - i)
            if k >= N:
                break
            if S[i] != S[j] and S[i] != S[k] and S[j] != S[k]:
                reigai += 1
    print(total - reigai)


if __name__ == "__main__":
    main()

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
S = list(input())

from itertools import combinations

lis = list(range(1, N+1))
s = [1 for v in combinations(lis, 3)
     if v[1] - v[0] != v[2] - v[1] and S[v[0]-1] != S[v[1]-1] and S[v[0]-1] != S[v[2]-1] and S[v[1]-1] != S[v[2]-1]]

print(len(s))


Fixed submission:
import sys
def input():
    return sys.stdin.readline()[:-1]


def main():
    N = int(input())
    S = list(input())
 
    c = [[] for _ in range(3)] #c = [[]] * 3 とすると全ての要素にappendされてしまうのでNG
    for i in range(len(S)):
        if S[i] == 'R':
            c[0].append(i)
        elif S[i] == 'G':
            c[1].append(i)
        else : # 'B'のとき
            c[2].append(i)
    total = len(c[0]) * len(c[1]) * len(c[2])

    reigai = 0 #先に条件2を満たすものを考えてから、条件1に当てはまるかを判定
    for i in range(N - 2):
        for j in range(i + 1, N - 1):
            k = j + (j - i)
            if k >= N:
                break
            if S[i] != S[j] and S[i] != S[k] and S[j] != S[k]:
                reigai += 1
    print(total - reigai)


if __name__ == "__main__":
    main()

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
S = list(input())

import itertools
lis = list(range(1, N+1))
c = 0

s = [1 for v in itertools.combinations(lis, 3)
     if v[1] - v[0] != v[2] - v[1] and S[v[0]-1] != S[v[1]-1] and S[v[0]-1] != S[v[2]-1] and S[v[1]-1] != S[v[2]-1]]

print(len(s))


Fixed submission:
import sys
def input():
    return sys.stdin.readline()[:-1]


def main():
    N = int(input())
    S = list(input())
 
    c = [[] for _ in range(3)] #c = [[]] * 3 とすると全ての要素にappendされてしまうのでNG
    for i in range(len(S)):
        if S[i] == 'R':
            c[0].append(i)
        elif S[i] == 'G':
            c[1].append(i)
        else : # 'B'のとき
            c[2].append(i)
    total = len(c[0]) * len(c[1]) * len(c[2])

    reigai = 0 #先に条件2を満たすものを考えてから、条件1に当てはまるかを判定
    for i in range(N - 2):
        for j in range(i + 1, N - 1):
            k = j + (j - i)
            if k >= N:
                break
            if S[i] != S[j] and S[i] != S[k] and S[j] != S[k]:
                reigai += 1
    print(total - reigai)


if __name__ == "__main__":
    main()

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
S = list(input())

import itertools
lis = list(range(1, N+1))
c = 0

s = [1 for v in itertools.combinations(lis, 3)
     if v[1] - v[0] != v[2] - v[1] and S[v[0]-1] != S[v[1]-1] and S[v[0]-1] != S[v[2]-1] and S[v[1]-1] != S[v[2]-1]]

print(len(s))


Fixed submission:
import sys
def input():
    return sys.stdin.readline()[:-1]


def main():
    N = int(input())
    S = list(input())
 
    c = [[] for _ in range(3)] #c = [[]] * 3 とすると全ての要素にappendされてしまうのでNG
    for i in range(len(S)):
        if S[i] == 'R':
            c[0].append(i)
        elif S[i] == 'G':
            c[1].append(i)
        else : # 'B'のとき
            c[2].append(i)
    total = len(c[0]) * len(c[1]) * len(c[2])

    reigai = 0 #先に条件2を満たすものを考えてから、条件1に当てはまるかを判定
    for i in range(N - 2):
        for j in range(i + 1, N - 1):
            k = j + (j - i)
            if k >= N:
                break
            if S[i] != S[j] and S[i] != S[k] and S[j] != S[k]:
                reigai += 1
    print(total - reigai)


if __name__ == "__main__":
    main()