Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
import math

def lcm(x, y):
    return (x * y) // math.gcd(x, y)


def main():
    a,b,c,d = map(int,input().split())
    c_mul_count = b//c - (a-1)//c
    d_mul_count = b//d - (a-1)//d
    cd_lcm = lcm(c, d)
    lcm_mul_count = b//cd_lcm - (a-1)//cd_lcm
    s = b-a+1
    print(s-c_mul_count-d_mul_count+lcm_mul_count)



if __name__ == '__main__':
    main()


Fixed submission:
import fractions

def lcm(x, y):
    return (x * y) // fractions.gcd(x, y)


def main():
    a,b,c,d = map(int,input().split())
    c_mul_count = b//c - (a-1)//c
    d_mul_count = b//d - (a-1)//d
    cd_lcm = lcm(c, d)
    lcm_mul_count = b//cd_lcm - (a-1)//cd_lcm
    s = b-a+1
    print(s-c_mul_count-d_mul_count+lcm_mul_count)



if __name__ == '__main__':
    main()
Buggy python submission (verdict: Time Limit Exceeded):
def my_index(l, x, default=False):
    return l.index(x) if x in l else default


def main():
    n,m = map(int, input().split())
    PY = [list(map(int, input().split())) for _ in range(m)]
    P = [x[0] for x in PY]
    Y = [x[1] for x in PY]

    PY = sorted(PY, key=lambda x:(x[0],x[1]))
    P_sorted = [x[0] for x in PY]
    Y_sorted = [x[1] for x in PY]
    for i in range(m):
        x = my_index(Y_sorted, Y[i])+1 - my_index(P_sorted,P[i])
        print(str(P[i]).rjust(6,'0')+str(x).rjust(6,'0'))


if __name__ == '__main__':
    main()
    # test()


Fixed submission:
def main():
    n,m = map(int, input().split())
    PY = [list(map(int, input().split()+[i])) for i in range(m)]
    PY = sorted(PY, key=lambda x:(x[0],x[1]))

    tmp = 0
    for i in range(m):
        if tmp == PY[i][0]:
            count += 1
        else:
            count = 1
            tmp = PY[i][0]
        PY[i].append(count)

    PY = sorted(PY, key=lambda x:x[2])

    for i in range(m):
        print(str(PY[i][0]).rjust(6,'0')+str(PY[i][3]).rjust(6,'0'))


if __name__ == '__main__':
    main()
Buggy python submission (verdict: Time Limit Exceeded):
def main():
    S = input()
    T = input()

    for i in range(len(S)):
        tmp = S[i]
        S = S.replace(T[i],'_')
        S = S.replace(S[i],T[i])
        S = S.replace('_',tmp)
    if S == T:
        print('Yes')
    else:
        print('No')


if __name__ == '__main__':
    main()


Fixed submission:
def main():
    S = input()
    T = input()

    start = [-1]*26
    goal = [-1]*26
    for i in range(len(S)):
        a = ord(S[i])-ord('a')
        b = ord(T[i])-ord('a')
        if start[a]!=-1 or goal[b]!=-1:
            if start[a]!=b or goal[b]!=a:
                print('No')
                return
        else:
            start[a] = b
            goal[b] = a
    print('Yes')


if __name__ == '__main__':
    main()
Buggy python submission (verdict: Runtime Error):
def main():
    a,b = map(int,input().split())
    if a%2!=0 and b%2!=0:
        print('Yes')
        return
    print('No')


if __name __ == '__main__':
    main()


Fixed submission:
def main():
    a,b = map(int,input().split())
    if a%2!=0 and b%2!=0:
        print('Yes')
        return
    print('No')


if __name__ == '__main__':
    main()
Buggy python submission (verdict: Runtime Error):
def main():
    n,k = map(int, input().split())

    ans+= pow(N//K,3)
    if k%2 == 0:
        ans = pow((n-k//2)//k, 3)
    print(ans)


if __name__ == '__main__':
    main()

Fixed submission:
def main():
    n,k = map(int, input().split())

    ans = (n//k)**3
    if k%2 == 0:
        ans += ((n+k//2)//k)**3
    print(ans)


if __name__ == '__main__':
    main()
Buggy python submission (verdict: Runtime Error):
vdef main():
    n,i = map(int,input().split())

    print(n+1-i)

if __name__ == '__main__':
    main()


Fixed submission:
def main():
    n,i = map(int,input().split())

    print(n+1-i)

if __name__ == '__main__':
    main()
Buggy python submission (verdict: Runtime Error):
def main():
    h,w = map(int, input().split())

    A = []
    grid = []
    for i in range(h):
        A.append(input())
    gird = []

    for i in range(h):
        if A[i] != '.'*w:
            grid.append(A[i])

    A = grid.copy()
    w_tmp = len(A[0])
    h_tmp = len(A)
    grid = ['' for _ in range(h_tmp)]
    for i in range(w_tmp):
        tmp = 0
        for j in range(h_tmp):
            if A[j][i] == '.':
                tmp += 1
        if tmp != h_tmp:
            for j in range(h_tmp):
                grid[j] += A[j][i]
    for i in range(len(grid)):
        print(grid[i])


if __name__ == '__main__':
    main()


Fixed submission:
def main():
    h,w = map(int, input().split())

    A = []
    grid = []
    for i in range(h):
        A.append(input())
    gird = []

    for i in range(h):
        if A[i] != '.'*w:
            grid.append(A[i])

    A = grid.copy()
    w_tmp = len(A[0])
    h_tmp = len(A)
    grid = ['' for _ in range(h_tmp)]
    for i in range(w_tmp):
        tmp = 0
        for j in range(h_tmp):
            if A[j][i] == '.':
                tmp += 1
        if tmp != h_tmp:
            for j in range(h_tmp):
                grid[j] += A[j][i]
    for i in range(len(grid)):
        print(grid[i])


if __name__ == '__main__':
    main()

Buggy python submission (verdict: Runtime Error):
def main():
    h,w = map(int, input().split())

    A = []
    grid = []
    for i in range(h):
        A.append(input())
    gird = []

    for i in range(h):
        if A[i] != '.'*w:
            grid.append(A[i])

    A = grid.copy()
    w_tmp = len(A[0])
    h_tmp = len(A)
    grid = ['' for _ in range(h_tmp)]
    for i in range(w_tmp):
        tmp = 0
        for j in range(h_tmp):
            if A[j][i] == '.':
                tmp += 1
        if tmp != h_tmp:
            for j in range(h_tmp):
                grid[j] += A[j][i]
    for i in range(len(grid)):
        print(grid[i])


if __name__ == '__main__':
    main()


Fixed submission:
def main():
    h,w = map(int, input().split())

    A = []
    grid = []
    for i in range(h):
        A.append(input())
    gird = []

    for i in range(h):
        if A[i] != '.'*w:
            grid.append(A[i])

    A = grid.copy()
    w_tmp = len(A[0])
    h_tmp = len(A)
    grid = ['' for _ in range(h_tmp)]
    for i in range(w_tmp):
        tmp = 0
        for j in range(h_tmp):
            if A[j][i] == '.':
                tmp += 1
        if tmp != h_tmp:
            for j in range(h_tmp):
                grid[j] += A[j][i]
    for i in range(len(grid)):
        print(grid[i])


if __name__ == '__main__':
    main()
Buggy python submission (verdict: Runtime Error):
def main():
    n,k = map(int, input().split())
    X = list(map(int, input().split()))

    for i,x in enumerate(X):
        if max(X) < 0:
            array_m = X.copy()
            array_p = []
            break
        if x >= 0:
            array_m = X[:i]
            array_p = X[i:]
            break
    inf = 10**9
    array_m = [inf] + array_m
    array_p += [inf]
    array_m2 = [abs(2*x) for x in array_m]
    array_p2 = [abs(2*x) for x in array_p]
    count = 0
    array_m_tmp = []
    array_p_tmp = []
    for _ in range(k):
        if array_m2[-1] < array_p[0]:
            array_m_tmp.append(array_m2.pop(-1))
        else:
            array_p_tmp.append(array_p.pop(0))
    array_m_tmp.append(0)
    array_p_tmp.append(0)
    ans = max(array_m_tmp) + max(array_p_tmp)
    print(ans)


if __name__ == '__main__':
    main()


Fixed submission:
def main():
    n,k = map(int, input().split())
    X = list(map(int, input().split()))

    tmp = []
    for i in range(n-k+1):
        l = X[i]
        r = X[i+k-1]
        tmp.append(abs(l)+abs(r-l))
        tmp.append(abs(r)+abs(r-l))
    print(min(tmp))


if __name__ == '__main__':
    main()
Buggy python submission (verdict: Runtime Error):
import math

def main():
    n = int(input())
    print(int(2*n/math.gcd(2, n)))

if __name__ == '__main__':
    main()


Fixed submission:
import fractions

def main():
    n = int(input())
    print(int(2*n/fractions.gcd(2, n)))


if __name__ == '__main__':
    main()

Buggy python submission (verdict: Runtime Error):
import math

def main():
    n = int(input())
    print(int(2*n/math.gcd(2, n)))

if __name__ == '__main__':
    main()


Fixed submission:
import fractions

def main():
    n = int(input())
    print(int(2*n/fractions.gcd(2, n)))


if __name__ == '__main__':
    main()
Buggy python submission (verdict: Time Limit Exceeded):
def main():
    n = int(input())
    S = input()

    ans = 10**9
    for i in range(len(S)):
        ans = min(ans, S[:i].count('W')+S[i+1:].count('E'))
    print(ans)


if __name__ == '__main__':
    main()


Fixed submission:
def main():
    n = int(input())
    S = input()

    array = [0,S[1:].count('E')]
    ans = sum(array)

    for i in range(1,len(S)):
        if S[i-1]=='W':
            array[0]+=1
        if S[i]=='E':
            array[1]-=1
        ans = min(ans, sum(array))
    print(ans)


if __name__ == '__main__':
    main()
Buggy python submission (verdict: Runtime Error):
def main():
    S = input()
    k = int(input())

    array = []
    for i in range(len(S)):
        for j in range(i+1,len(S)+1):
            if j-i < k:
                array.append(S[i:j])
    array = list(set(array))
    array.sort()
    print(array[k-1])


if __name__ == '__main__':
    main()


Fixed submission:
def main():
    S = input()
    k = int(input())

    array = []
    for i in range(len(S)):
        for j in range(i+1,len(S)+1):
            if j-i <= k:
                array.append(S[i:j])
    array = list(set(array))
    array.sort()
    print(array[k-1])


if __name__ == '__main__':
    main()

Buggy python submission (verdict: Runtime Error):
def main():
    S = input()
    k = int(input())

    array = []
    for i in range(len(S)):
        for j in range(i+1,len(S)+1):
            if j-i < len(S):
                array.append(S[i:j])
    array = list(set(array))
    array.sort()
    print(array[k-1])


if __name__ == '__main__':
    main()


Fixed submission:
def main():
    S = input()
    k = int(input())

    array = []
    for i in range(len(S)):
        for j in range(i+1,len(S)+1):
            if j-i <= k:
                array.append(S[i:j])
    array = list(set(array))
    array.sort()
    print(array[k-1])


if __name__ == '__main__':
    main()

Buggy python submission (verdict: Runtime Error):
def main():
    S = input()
    k = int(input())

    array = []
    for i in range(len(S)):
        for j in range(i+1,len(S)+1):
            if j-i < len(S):
                array.append(S[i:j])
    array = list(set(array))
    array.sort()
    print(array[k-1])


if __name__ == '__main__':
    main()


Fixed submission:
def main():
    S = input()
    k = int(input())

    array = []
    for i in range(len(S)):
        for j in range(i+1,len(S)+1):
            if j-i <= k:
                array.append(S[i:j])
    array = list(set(array))
    array.sort()
    print(array[k-1])


if __name__ == '__main__':
    main()

Buggy python submission (verdict: Runtime Error):
def main():
    S = input()
    k = int(input())

    array = []
    for i in range(len(S)):
        for j in range(i+1,len(S)+1):
            array.append(S[i:j])
    array = list(set(array))
    array.sort()
    print(array[k-1])


if __name__ == '__main__':
    main()


Fixed submission:
def main():
    S = input()
    k = int(input())

    array = []
    for i in range(len(S)):
        for j in range(i+1,len(S)+1):
            if j-i <= k:
                array.append(S[i:j])
    array = list(set(array))
    array.sort()
    print(array[k-1])


if __name__ == '__main__':
    main()
Buggy python submission (verdict: Runtime Error):
def main():
    a,b,k = map(int, input().split())

    array = list(range(a,b+1))
    ans = list(set(array[:k]) | set(array[-k:]))
    ans.sort()
    for val in ans:
        print(val)


if __name__ == '__main__':
    main()


Fixed submission:
def main():
    a,b,k = map(int, input().split())

    array = range(a,b+1)
    ans = list(set(array[:k]) | set(array[-k:]))
    ans.sort()
    for val in ans:
        print(val)


if __name__ == '__main__':
    main()

Buggy python submission (verdict: Runtime Error):
def main():
    a,b,k = map(int, input().split())

    array = list(range(a,b+1))
    ans = list(set(array[:k]) | set(array[-k:]))
    ans.sort()
    for val in ans:
        print(val)


if __name__ == '__main__':
    main()


Fixed submission:
def main():
    a,b,k = map(int, input().split())

    array = range(a,b+1)
    ans = list(set(array[:k]) | set(array[-k:]))
    ans.sort()
    for val in ans:
        print(val)


if __name__ == '__main__':
    main()

Buggy python submission (verdict: Runtime Error):
def main():
    a,b,k = map(int, input().split())

    array = list(range(a,b+1))
    ans = list(set(array[:k]) | set(array[-k:]))
    ans.sort()
    for val in ans:
        print(val)


if __name__ == '__main__':
    main()


Fixed submission:
def main():
    a,b,k = map(int, input().split())

    array = range(a,b+1)
    ans = list(set(array[:k]) | set(array[-k:]))
    ans.sort()
    for val in ans:
        print(val)


if __name__ == '__main__':
    main()
Buggy python submission (verdict: Runtime Error):
def main():
    n = int(input())
    S = list(map(int,input().split()))

    if 'Y' in S:
        print('Four')
    else:
        print('Three')


if __name__ == '__main__':
    main()


Fixed submission:
def main():
    n = int(input())
    S = input()

    if 'Y' in S:
        print('Four')
    else:
        print('Three')


if __name__ == '__main__':
    main()
Buggy python submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(4100000)
import math
INF = 10**9

def main():
    a,b = map(str,input().split())

    if a*b%2 == 0:
        print('Even')
    else:
        print('Odd')


if __name__ == '__main__':
    main()


Fixed submission:
import sys
sys.setrecursionlimit(4100000)
import math
INF = 10**9

def main():
    a,b = map(int,input().split())

    if a*b%2 == 0:
        print('Even')
    else:
        print('Odd')


if __name__ == '__main__':
    main()
Buggy python submission (verdict: Runtime Error):
def main():
    n = input()

    array = [2,1]
    for i in range(100):
        array.append(array[i]+array[i+1])
    print(array[n])


if __name__ == '__main__':
    main()


Fixed submission:
def main():
    n = int(input())

    array = [2,1]
    for i in range(100):
        array.append(array[i]+array[i+1])
    print(array[n])


if __name__ == '__main__':
    main()
Buggy python submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(4100000)
import math
import itertools
INF = float('inf')
from heapq import heapify, heappop, heappush

def main():
    a = int(input())
    b = int(input())

    if b < a:
        prnit('GREATER')
    elif a == b:
        print('EQUAL')
    else:
        print('LESS')


if __name__ == '__main__':
    main()


Fixed submission:
import sys
sys.setrecursionlimit(4100000)
import math
import itertools
INF = float('inf')
from heapq import heapify, heappop, heappush

def main():
    a = int(input())
    b = int(input())

    if b < a:
        print('GREATER')
    elif a == b:
        print('EQUAL')
    else:
        print('LESS')


if __name__ == '__main__':
    main()

Buggy python submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(4100000)
import math
import itertools
INF = float('inf')
from heapq import heapify, heappop, heappush

def main():
    a,b = map(int, input().split())

    if b < a:
        prnit('GREATER')
    elif a == b:
        print('EQUAL')
    else:
        print('LESS')


if __name__ == '__main__':
    main()


Fixed submission:
import sys
sys.setrecursionlimit(4100000)
import math
import itertools
INF = float('inf')
from heapq import heapify, heappop, heappush

def main():
    a = int(input())
    b = int(input())

    if b < a:
        print('GREATER')
    elif a == b:
        print('EQUAL')
    else:
        print('LESS')


if __name__ == '__main__':
    main()
Buggy python submission (verdict: Time Limit Exceeded):
import sys
sys.setrecursionlimit(4100000)
import math
import itertools
INF = float('inf')
from heapq import heapify, heappop, heappush
import collections
import bisect

def main():
    n = int(input())
    mod = 10**9+7

    ans = 1
    for i in range(n):
        ans *= i+1
    print(ans%mod)


if __name__ == '__main__':
    main()


Fixed submission:
import sys
sys.setrecursionlimit(4100000)
import math
import itertools
INF = float('inf')
from heapq import heapify, heappop, heappush
import collections
import bisect

def main():
    n = int(input())
    mod = 10**9+7

    ans = 1
    for i in range(n):
        ans *= i+1
        ans %= mod
    print(ans)


if __name__ == '__main__':
    main()
Buggy python submission (verdict: Time Limit Exceeded):
#import numpy as np
import sys, math
from itertools import permutations, combinations
from collections import defaultdict, Counter, deque
from math import factorial#, gcd
from bisect import bisect_left, bisect_right #bisect_left(list, value)
sys.setrecursionlimit(10**7)
enu = enumerate
MOD = 10**9+7
def input(): return sys.stdin.readline()[:-1]
pl = lambda x: print(*x, sep='\n')

N, K = map(int, input().split())
A = list(map(int, input().split()))

B = [0]*(N-K+1)
val = 1
for a in A[:K]:
    val *= a
B[0] = val
for i in range(1, N-K+1):
    B[i] = B[i-1]
    B[i] //= A[i-1]
    B[i] *= A[i+K-1]

for bi, bip in zip(B[:-1], B[1:]):
    if bi < bip:
        print('Yes')
    else:
        print('No')



Fixed submission:
#import numpy as np
import sys, math
from itertools import permutations, combinations
from collections import defaultdict, Counter, deque
from math import factorial#, gcd
from bisect import bisect_left, bisect_right #bisect_left(list, value)
sys.setrecursionlimit(10**7)
enu = enumerate
MOD = 10**9+7
def input(): return sys.stdin.readline()[:-1]
pl = lambda x: print(*x, sep='\n')

N, K = map(int, input().split())
A = list(map(int, input().split()))

for i in range(N-K):
    if A[i] < A[i+K]:
        print('Yes')
    else:
        print('No')
Buggy python submission (verdict: Time Limit Exceeded):
#import numpy as np
import sys, math
from itertools import permutations, combinations
from collections import defaultdict, Counter, deque
from math import factorial#, gcd
from bisect import bisect_left #bisect_left(list, value)
sys.setrecursionlimit(10**7)
enu = enumerate
MOD = 10**9+7
def input(): return sys.stdin.readline()[:-1]
pl = lambda x: print(*x, sep='\n')

N, K = map(int, input().split())
A = list(map(int, input().split()))

def func(A):
    aA = [0]*(2*N+10)
    for i, a in enu(A):
        st = max(0, 2*i-2*a-1)
        en = min(2*N, 2*i+2*a+1)
        aA[st] += 1
        aA[en] -= 1

    for i in range(2*N):
        aA[i+1] += aA[i]

    res = [val for i, val in enu(aA) if i%2==0]
    res = res[:N]
    return res

for _ in range(K):
    A = func(A)

print(*A)

Fixed submission:
#import numpy as np
import sys, math
from itertools import permutations, combinations
from collections import defaultdict, Counter, deque
from math import factorial#, gcd
from bisect import bisect_left #bisect_left(list, value)
sys.setrecursionlimit(10**7)
enu = enumerate
MOD = 10**9+7
def input(): return sys.stdin.readline()[:-1]
pl = lambda x: print(*x, sep='\n')

N, K = map(int, input().split())
A = list(map(int, input().split()))
# print('A', A)

def func(A):
    # print('start')
    # print(A)
    all_N = True
    aA = [0]*(2*N+10)
    for i, a in enu(A):
        if a != N:
            all_N = False
        st = max(0, 2*i-2*a-1)
        en = min(2*N, 2*i+2*a+1)
        aA[st] += 1
        aA[en] -= 1

    # print(aA)
    for i in range(2*N):
        aA[i+1] += aA[i]

    # print(aA)

    res = [val for i, val in enu(aA) if i%2==0]
    res = res[:N]
    # print(res)
    return res, all_N

for _ in range(K):
    A, all_N = func(A)
    if all_N:
        break
    # print(*A)

print(*A)
Buggy python submission (verdict: Runtime Error):
from collections import defaultdict
enu = enumerate
def input(): return sys.stdin.readline()[:-1]

N = int(input())
A = list(map(int, input().split()))

cnt = 0
d = defaultdict(int)
for i, a in enu(A):
    l = (i+1) + a
    r = (i+1) - a
    cnt += d[r]
    d[l] += 1

print(cnt)

Fixed submission:
#import numpy as np
import sys, math
from itertools import permutations, combinations
from collections import defaultdict, Counter, deque
from math import factorial#, gcd
from bisect import bisect_left #bisect_left(list, value)
sys.setrecursionlimit(10**7)
enu = enumerate
MOD = 10**9+7
def input(): return sys.stdin.readline()[:-1]
def pri(x): print('\n'.join(map(str, x)))

N = int(input())
A = list(map(int, input().split()))

cnt = 0
d = defaultdict(int)
for i, a in enu(A):
    l = (i+1) + a
    r = (i+1) - a
    cnt += d[r]
    d[l] += 1
print(cnt)

Buggy python submission (verdict: Time Limit Exceeded):
#import numpy as np
import sys, math
from itertools import permutations, combinations
from collections import defaultdict, Counter, deque
from math import factorial#, gcd
from bisect import bisect_left #bisect_left(list, value)
sys.setrecursionlimit(10**7)
enu = enumerate
MOD = 10**9+7
def input(): return sys.stdin.readline()[:-1]
def pri(x): print('\n'.join(map(str, x)))

N = int(input())
A = list(map(int, input().split()))

cnt = 0
for i, a in enu(A):
    if i+a+1<=N-1:
        for j, b in enu(A[i+a+1:]):
            if abs(j+a+1) == a + b:
                cnt += 1
                # print(i, i+a+1+j)
print(cnt)

Fixed submission:
#import numpy as np
import sys, math
from itertools import permutations, combinations
from collections import defaultdict, Counter, deque
from math import factorial#, gcd
from bisect import bisect_left #bisect_left(list, value)
sys.setrecursionlimit(10**7)
enu = enumerate
MOD = 10**9+7
def input(): return sys.stdin.readline()[:-1]
def pri(x): print('\n'.join(map(str, x)))

N = int(input())
A = list(map(int, input().split()))

cnt = 0
d = defaultdict(int)
for i, a in enu(A):
    l = (i+1) + a
    r = (i+1) - a
    cnt += d[r]
    d[l] += 1
print(cnt)
Buggy python submission (verdict: Time Limit Exceeded):
import sys, math
from itertools import permutations, combinations
from collections import defaultdict, Counter, deque
from math import factorial#, gcd
from bisect import bisect_left #bisect_left(list, value)
sys.setrecursionlimit(10**7)
enu = enumerate
MOD = 10**9+7
def input(): return sys.stdin.readline()[:-1]
def pri(x): print('\n'.join(map(str, x)))

N = int(input())
S = input()

Rs = []
Gs = []
Bs = []
for index, s in enu(S):
    if s == 'R':
        Rs.append(index+1)
    elif s == 'G':
        Gs.append(index+1)
    elif s == 'B':
        Bs.append(index+1)
#print(Rs, Gs, Bs)

cnt = 0
for r in Rs:
    for g in Gs:
        for b in Bs:
            i, j, k = sorted([r, g, b])
            #print(' ', i, j, k)
            if j-i != k-j:
                cnt += 1
print(cnt)


Fixed submission:
import sys, math
from itertools import permutations, combinations
from collections import defaultdict, Counter, deque
from math import factorial#, gcd
from bisect import bisect_left #bisect_left(list, value)
sys.setrecursionlimit(10**7)
enu = enumerate
MOD = 10**9+7
def input(): return sys.stdin.readline()[:-1]
def pri(x): print('\n'.join(map(str, x)))

N = int(input())
S = input()

Rs = []
Gs = []
Bs = []
for index, s in enu(S):
    if s == 'R':
        Rs.append(index+1)
    elif s == 'G':
        Gs.append(index+1)
    elif s == 'B':
        Bs.append(index+1)
#print(Rs, Gs, Bs)

cnt = len(Rs) * len(Gs) * len(Bs)
sBs = set(Bs)

for rr in Rs:
    for gg in Gs:
        r, g = sorted([rr, gg])

        pt1 = g + (g-r)
        pt2 = -1
        if (g-r)%2==0:
            pt2 = r + (g-r)//2
        pt3 = r - (g-r)

        chks = [val for val in [pt1, pt2, pt3] if val > 0]
        for chk in chks:
            if chk in sBs:
                cnt -= 1

print(cnt)