Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
x=input()
ans=len(x)
while 1:
    x=x.replace("ST","")
    if len(x)==ans: break
    ans=len(x)
print(ans)


Fixed submission:
X=raw_input()
l=[0,0]
for i in X:
    if i=='S':
        l[0]+=1
    elif i=='T' and l[0]>0:
        l[0]-=1
    else:
        l[1]+=1
print sum(l)

Buggy python submission (verdict: Time Limit Exceeded):
X=raw_input()
while 1:
    if 'SSSSSSSSSSSSSSSSSSSSSSSSSTTTTTTTTTTTTTTTTTTTTTTTTT' in X:
       X=X.replace('SSSSSSSSSSSSSSSSSSSSSSSSSTTTTTTTTTTTTTTTTTTTTTTTTT','')
    elif 'SSSSSSSSSSSSSSSSSSSSTTTTTTTTTTTTTTTTTTTT' in X:
       X=X.replace('SSSSSSSSSSSSSSSSSSSSTTTTTTTTTTTTTTTTTTTT','')
    elif 'SSSSSSSSSSSSSSSTTTTTTTTTTTTTTT' in X:
       X=X.replace('SSSSSSSSSSSSSSSTTTTTTTTTTTTTTT','')
    elif 'SSSSSSSSSSTTTTTTTTTT' in X:
       X=X.replace('SSSSSSSSSSTTTTTTTTTT','')
    elif 'SSSSSSSTTTTTTT' in X:
       X=X.replace('SSSSSSSTTTTTTT','')
    elif 'SSSSSTTTTT' in X:
       X=X.replace('SSSSSTTTTT','')
    elif 'SSSTTT' in X:
       X=X.replace('SSSTTT','')
    elif 'ST' in X:
       X=X.replace('ST','')
    else:
        break
print len(X)

Fixed submission:
X=raw_input()
l=[0,0]
for i in X:
    if i=='S':
        l[0]+=1
    elif i=='T' and l[0]>0:
        l[0]-=1
    else:
        l[1]+=1
print sum(l)

Buggy python submission (verdict: Time Limit Exceeded):
X=raw_input()
while 1:
    if 'SSSSSSSSSSSSSSSTTTTTTTTTTTTTTT' in X:
       X=X.replace('SSSSSSSSSSSSSSSTTTTTTTTTTTTTTT','')
    elif 'SSSSSSSSSSTTTTTTTTTT' in X:
       X=X.replace('SSSSSSSSSSTTTTTTTTTT','')
    elif 'SSSSSSSTTTTTTT' in X:
       X=X.replace('SSSSSSSTTTTTTT','')
    elif 'SSSSSTTTTT' in X:
       X=X.replace('SSSSSTTTTT','')
    elif 'SSSTTT' in X:
       X=X.replace('SSSTTT','')
    elif 'ST' in X:
       X=X.replace('ST','')
    else:
        break
print len(X)

Fixed submission:
X=raw_input()
l=[0,0]
for i in X:
    if i=='S':
        l[0]+=1
    elif i=='T' and l[0]>0:
        l[0]-=1
    else:
        l[1]+=1
print sum(l)

Buggy python submission (verdict: Time Limit Exceeded):
X=raw_input()
while 1:
    if 'ST' in X:
       X=X.replace('ST','')
    else:
        break
print len(X)

Fixed submission:
X=raw_input()
l=[0,0]
for i in X:
    if i=='S':
        l[0]+=1
    elif i=='T' and l[0]>0:
        l[0]-=1
    else:
        l[1]+=1
print sum(l)
Buggy python submission (verdict: Runtime Error):
n,a=map(int,raw_input().split())
x=map(int,raw_input().split())
ans=0
for i in range(1<<n):
    chk=0
    t=bin(i)[2:]
    t='0'*(n-len(t))+t
    for j,p in enumerate(t):
        if p=='1':
            chk+=x[j]
    if chk!=0 and chk==a*t.count('1'):
        ans+=1
print ans


Fixed submission:
n,a=map(int,input().split())
l=[int(i) for i in input().split()]
ans=0
#dp=[[[0 for i in range(51)] for j in range(51)] for k in range(2501)]
dp=[[[0 for i in range(2501)] for j in range(51)] for k in range(51)]
dp[0][0][0]=1

for i in range(n):
    for j in range(50):
        for k in range(2501):
            if dp[i][j][k]:
                dp[i+1][j][k]+=dp[i][j][k]
                dp[i+1][j+1][k+l[i]]+=dp[i][j][k]
for i in range(1,n+1):
    ans+=dp[n][i][i*a]
print(ans)
Buggy python submission (verdict: Runtime Error):
s=list(raw_input())
s=set(s)
print 'Yes' if len(s)==4 or (len(s)==2 and 'S' in s and 'N' in s) or (len(2) and 'W' in s and 'E' in s) else 'No'

Fixed submission:
s=list(raw_input())
s=set(s)
print 'Yes' if len(s)==4 or (len(s)==2 and 'S' in s and 'N' in s) or (len(s)==2 and 'W' in s and 'E' in s) else 'No'
Buggy python submission (verdict: Runtime Error):
n=int(input())
l=[0]
if n<200: print(l[100])
ans=chk=0
for i in range(n):
    a=int(input())
    ans+=(a+chk)//2
    if a>0:
         chk=(a+chk)%2
    else:
        chk=0
print(ans)

Fixed submission:
n=int(input())
ans=chk=0
for i in range(n):
    a=int(input())
    ans+=(a+chk)//2
    if a>0:
         chk=(a+chk)%2
    else:
        chk=0
print(ans)
Buggy python submission (verdict: Runtime Error):
n, m = map(int, input().split())
par = [i for i in range(n)]

def find(x, par):
    if par[x] == x:
        return x
    else:
        return find(par[x], par)

def unite(x, y):
    x = find(x, par)
    y = find(y, par)
    if x != y:
        par[x] = y

for _ in range(m):
    a, b = map(int, input().split())
    unite(a-1, b-1)

groups= 0
for i in range(n):
    if i == par[i]:
        groups +=1
print(groups-1)

Fixed submission:
n, m = map(int, input().split())
par = [i for i in range(n)]
import sys
sys.setrecursionlimit(1000000)

def find(x, par):
    if par[x] == x:
        return x
    else:
        a = find(par[x], par)
        par[x] =a
        return a

def unite(x, y):
    x = find(x, par)
    y = find(y, par)
    if x != y:
        par[x] = y

for _ in range(m):
    a, b = map(int, input().split())
    unite(a-1, b-1)

groups= 0
for i in range(n):
    if i == par[i]:
        groups +=1
print(groups-1)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
def dividable(p):
    d_max = int(p**(1/2))
    yes=False
    if d_max*d_max==p:
        yes=True
    ret =0
    if yes:
        for i in range(1, d_max):
            if p % i == 0:
                ret += 1
        return ret*2+1
    else:
        for i in range(1, d_max+1):
            if p%i==0:
                ret+=1
        return ret*2
ls=[0]*(n+1)
for i in range(2, n+1):
    ls[i]= ls[i-1] + dividable(i-1)
print(ls[-1])

Fixed submission:
n = int(input())

N_1 = n - 1
ans = 0
i = 1
j = 1
while i <= N_1:
    while j <= N_1:
        if i * j <=  N_1:
            ans += 1
        else:
            j = N_1
        j = j + 1
    j = 1
    i = i + 1

print(ans)
Buggy python submission (verdict: Runtime Error):
import sys
stdin = sys.stdin

def main():
    n = int(stdin.readline().rstrip())
    ls = list(map(int, stdin.readline().split()))
    lsm = list(set(ls))
    m = len(lsm)
    ans = 0
    for i in range(n-1):
        for j in range(i+1, n):
            ans = (ans + lsm[i] * lsm[j]) % (10**9 + 7)
    print(ans)

if __name__ == '__main__':
    main()

Fixed submission:
import sys
stdin = sys.stdin

def main():
    n = int(stdin.readline().rstrip())
    ls = list(map(int, stdin.readline().split()))
    ans = 0
    m = 10**9 + 7
    sum1 = sum(ls)%m
    for i in range(n-1):
        sum1 = sum1-ls[i]
        ans = ((sum1 * ls[i])+ans) % m
    print(ans)

if __name__ == '__main__':
    main()
Buggy python submission (verdict: Runtime Error):
n, q = map(int, input().split())
cn = list(map(int, input().split()))
s = [-1]*(n+1)
t = [0]*n
for i in range(n):
    j = cn[i]
    if s[j] == -1:
        t[i] = -1
        s[j] = i
    else:
        t[i] = s[j]
        s[j] = i

ans = [0]*q
for i in range(q):
    count = 0
    l, r = map(int, input().split())
    for j in range(l-1,r):
        if t[j] >= l-1:
            count += 1
    ans[i] = r-l+1-count

for i in ans:
    print(i)

Fixed submission:
x = int(input())
if x >=30:
    print('Yes')
else:
    print('No')
Buggy python submission (verdict: Time Limit Exceeded):
k = int(input())

if k%2 ==0:
    print(-1)
    exit(0)

n = 0

for i in range(1, 10**6):
    n += 7 *(10**(i-1))
    if n%k == 0:
        print(i)
        exit(0)

print(-1)

Fixed submission:
k = int(input())

m = 0

for i in range(1, 10**7):
    n = m *10 +7
    m = n % k
    if m == 0:
        print(i)
        exit(0)

print(-1)

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

if k%2 ==0:
    print(-1)
    exit(0)

for i in range(1, 10**12):
    n = int(('7'*i))
    if n%k == 0:
        print(i)
        exit(0)

print(-1)

Fixed submission:
k = int(input())

m = 0

for i in range(1, 10**7):
    n = m *10 +7
    m = n % k
    if m == 0:
        print(i)
        exit(0)

print(-1)
Buggy python submission (verdict: Runtime Error):
n, k = map(int, input().split())
an = list(map(int, input().split()))

def judge(t):
    m = 0
    for i in an:
        m += i//t+1
    if m <= n+k:
        return True
    else:
        return False

mini = 0
maxi = max(an)

while mini != maxi:
    check = int((mini+maxi)/2)
    if judge(check):
        maxi = check
    else:
        mini = check+1

print(mini)

Fixed submission:
n, k = map(int, input().split())
an = list(map(int, input().split()))

maxi = max(an)
if k == 0:
    print(maxi)
    exit(0)


def judge(t):
    m = 0
    for i in an:
        if i%t == 0:
            m +=i//t
        else:
            m += i//t+1
    #print('judge', m, n+k)
    if m <= n+k:
        #print("true")
        return True
    else:
        #print("false")
        return False

mini = 0
#maxi = max(an)

while mini+1 != maxi:
    check = (mini+maxi)//2
    #print(check)
    if judge(check):
        maxi = check
        #print(mini, maxi)
    else:
        mini = check
        #print(mini, maxi)

print(maxi)
Buggy python submission (verdict: Runtime Error):
import sys
n = int(input())
an = list(map(int, sys.stdin.readline().rstrip().split()))
q = int(input())

import numpy as np

sum = np.sum(an)


for _ in range(q):
    b,c = map(int, input().split())
    for i in range(n):
        if b == an[i]:
            an[i]=c
            sum += c-b
    print(sum)

Fixed submission:
alpha = str(input())

if alpha in 'ABCDEFGHIJKLMNOPQRSTUVWXYZ':
    print('A')
else:
    print('a')
Buggy python submission (verdict: Time Limit Exceeded):
import sys
n = int(input())
an = list(map(int, sys.stdin.readline().rstrip().split()))
q = int(input())

import numpy as np
from collections import deque

sum = np.sum(an)
ans = deque()

for _ in range(q):
    b,c = map(int, input().split())
    for i in range(n):
        if b == an[i]:
            an[i]=c
            sum += c-b
    ans.append(sum)

while ans:
    print(ans.popleft())

Fixed submission:
N = int(input())
A = list(map(int, input().split()))
Q = int(input())
li = [0]*100001
for a in A:
    li[a] += 1
ans = sum(A)
# print(dict_A)
for i in range(Q):
    b, c = map(int, input().split())
    ans += (c-b)*li[b]
    li[c] += li[b]
    li[b] = 0
    print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import sys
n = int(input())
an = list(map(int, sys.stdin.readline().rstrip().split()))
q = int(input())

import numpy as np

sum = np.sum(an)
ans=[]

for _ in range(q):
    b,c = map(int, input().split())
    for i in range(n):
        if b == an[i]:
            an[i]=c
            sum += c-b
    ans.append(sum)

for q in ans:
    print(q)

Fixed submission:
N = int(input())
A = list(map(int, input().split()))
Q = int(input())
li = [0]*100001
for a in A:
    li[a] += 1
ans = sum(A)
# print(dict_A)
for i in range(Q):
    b, c = map(int, input().split())
    ans += (c-b)*li[b]
    li[c] += li[b]
    li[b] = 0
    print(ans)
Buggy python submission (verdict: Runtime Error):
import sys

x, n = map(int, input().split())
pn = list(map(int, sys.stdin.readline().rstrip().split()))

qn = set([i for i in range(1,101)]) - set(pn)

qn = list(qn)


if x-qn[0]<0:
    print(qn[0])
    exit(0)
if x-qn[-1]>=0:
    print(qn[-1])
    exit(0)

for i in range(100-n):
    if qn[i]==x:
        print(x)
        exit(0)
    elif x-qn[i+1]<0:
        if x-qn[i] <= qn[i+1]-x:
            print(qn[i])
            exit(0)
        elif x-qn[i] > qn[i+1]-x:
            print(qn[i+1])
            exit(0)

Fixed submission:
import sys

x, n = map(int, input().split())
pn = list(map(int, sys.stdin.readline().rstrip().split()))

if x not in pn:
    print(x)
    exit(0)

for i in range(1,100):
    if x-i not in pn:
        print(x-i)
        exit(0)
    elif x+i not in pn:
        print(x + i)
        exit(0)
Buggy python submission (verdict: Runtime Error):
import sys
n, k = map(int, sys.stdin.readline().rstrip().split())
an = list(map(int, sys.stdin.readline().rstrip().split()))


import numpy as np


t= min(k, 45)
from numba.decorators import jit

@jit
def imos(a, n):
    bn = [0]*n
    for i in range(n):
        bn[max(i - a[i], 0)] += 1

        if i+ a[i]+1 <n:
            bn[i+a[i]+1] -=1
    return np.cumsum(bn)


for k in range(t):
    an = imos(an, n)


print(*an)

Fixed submission:
s= str(input())

print(s[:3])

Buggy python submission (verdict: Runtime Error):
n, k = map(int, input().split())
an = list(map(int, input().split()))

import numpy as np

t= min(k, 45)
bn = np.zeros((t,n), dtype=int)

for k in range(t):
    if k==0:
        for i in range(n):
            for j in range(max(i - an[i], 0), min(n, i + an[i] + 1)):
                bn[k][j] += 1
    else:
        for i in range(n):
            for j in range(max(i - bn[k - 1][i], 0), min(n, i + bn[k - 1][i] + 1)):
                bn[k][j] += 1


print(*bn[t-1])

Fixed submission:
s= str(input())

print(s[:3])
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = list(map(int, input().split()))

ans=1

for i in range(n):
    ans *= a[i]

if ans > 10**18:
    print(-1)
else:
    print(ans)

Fixed submission:
n = int(input())
a = list(map(int, input().split()))

b = sorted(a, reverse=True)


ans=1

if min(b) == 0:
    print(0)
    exit(0)

for i in range(n):
    ans *= b[i]
    if ans > 10 ** 18:
        print(-1)
        exit(0)



print(ans)
Buggy python submission (verdict: Runtime Error):
n= int(input())

a = list(map(int, input().split()))

#print(a)

if a[0] != 0:
    print(-1)
    exit(0)

if n == 0:
    print(-1)
    exit(0)

b=1
count=1
asum =sum(a)
alim = asum

for i in range(n-1):
    if a[i+1] > 2*b:
        print(-1)
        exit(0)
    else:
        alim = alim - a[i+1]
        b= min(2*b-a[i+1], alim)

        count += b



print(count+ asum)

Fixed submission:
h, m, i, n, k = map(int, input().split())

fun1 = 60 * h + m
fun2 = 60 * i + n

sa = fun2-fun1

if sa > k:
    ans = sa -k
else:
    ans = 0

print(ans)
Buggy python submission (verdict: Runtime Error):
n = input()
amari = n%10
p = ''
if amari ==2 or amari ==4 or amari ==5 or amari ==7 or amari ==9:
    p = 'hon'
elif amari ==1 or amari ==0 or amari ==6 or amari ==8 :
    p = 'pon'
else:
    p = 'bon'
print(p)

Fixed submission:
n = int(input())
amari = n%10
p = ''
if amari ==2 or amari ==4 or amari ==5 or amari ==7 or amari ==9:
    p = 'hon'
elif amari ==1 or amari ==0 or amari ==6 or amari ==8 :
    p = 'pon'
else:
    p = 'bon'
print(p)

Buggy python submission (verdict: Runtime Error):
n = input()
amari = n//10
p = ''
if amari ==2 or amari ==4 or amari ==5 or amari ==7 or amari ==9:
    p = 'hon'
elif amari ==1 or amari ==0 or amari ==6 or amari ==8 :
    p = 'pon'
else:
    p = 'bon'
print(p)

Fixed submission:
n = int(input())
amari = n%10
p = ''
if amari ==2 or amari ==4 or amari ==5 or amari ==7 or amari ==9:
    p = 'hon'
elif amari ==1 or amari ==0 or amari ==6 or amari ==8 :
    p = 'pon'
else:
    p = 'bon'
print(p)
Buggy python submission (verdict: Runtime Error):
s= str(input())
t= str(input())

r= int(t.replace(s, ''))
if r in range(10):
    print('Yes')
else:
    print('No')


Fixed submission:
s= str(input())
t= str(input())


if len(t)==1 + len(s) and t[0:len(s)]==s:
    print('Yes')
else:
    print('No')
Buggy python submission (verdict: Runtime Error):
if k <= a:
    print(k)
elif k <= a +b:
    print(a)

else:
    print(a -(k-a-b))

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

if k <= a:
    print(k)
elif k <= a +b:
    print(a)

else:
    print(a -(k-a-b))

Buggy python submission (verdict: Time Limit Exceeded):
a, b, c, k= map(int, input().split())

d = []

for _ in range(a):
    d.append(1)
for _ in range(b):
    d.append(0)
for _ in range(c):
    d.append(-1)
count=0
for i in range(k):
    count += d[i]


print(count)

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

if k <= a:
    print(k)
elif k <= a +b:
    print(a)

else:
    print(a -(k-a-b))
Buggy python submission (verdict: Runtime Error):
n, k  = map(int, input().split())
an = list(map(int, input().split()))
bn = [-1]*(n+1)

now=1
bn[1]=0
for i in range(1, k+1):
    print(bn)
    now = an[now-1]
    if bn[now] >0:
        rp =i-bn[now]
        p= (k-i)%rp
        for j in range(p):
            now = an[now-1]
        print(now)
        exit(0)
    bn[now]=i
print(now)

Fixed submission:
n, k  = map(int, input().split())
an = list(map(int, input().split()))
bn = [-1]*(n+1)

now=1
bn[1]=0
for i in range(1, k+1):
 #   print(bn)
    now = an[now-1]
    if bn[now] >0:
        rp =i-bn[now]
        p= (k-i)%rp
        for j in range(p):
            now = an[now-1]
        print(now)
        exit(0)
    bn[now]=i
print(now)
Buggy python submission (verdict: Time Limit Exceeded):
from itertools import chain

n, m = map(int, input().split())
H = list(map(int, input().split()))

ab = []
for i in range(m):
    ab.append(list(map(int, input().split())))

count = 0
skipset = []

for i in range(1, n+1):
    if i in skipset:
        continue
    f = {i}
    c= []
    e= []
    for j in ab:
        if i in j:
            c.append(j)
    d =set(chain.from_iterable(c)) -f
    #print(d)

    for k in d:
        e.append(H[k-1])



    if len(e)==0:
        count += 1
        #print('Yes')

        continue
    elif max(e) < H[i-1]:
        #print(i, H[i - 1], max(e))
        skipset.append(d)
        count += 1
        #print('Yes')
    else:

        pass

print(count)

Fixed submission:
N, M = map(int, input().split())
c_list = [[] for _ in range(N)]
e_list = list(map(int, input().split()))
for _ in range(M):
   a, b = map(lambda i: int(i) - 1, input().split())
   c_list[a].append(b)
   c_list[b].append(a)
ans = 0
for i, e in enumerate(e_list):
   for j in c_list[i]:
       if e <= e_list[j]:
           break
   else:
       ans += 1

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
from itertools import chain

n, m = map(int, input().split())
H = list(map(int, input().split()))

ab = []
for i in range(m):
    ab.append(list(map(int, input().split())))

count = 0

for i in range(1, n+1):
    f = {i}
    c= []
    e= []
    for j in ab:
        if i in j:
            c.append(j)
    d =set(chain.from_iterable(c)) -f
    #print(d)

    for k in d:
        e.append(H[k-1])



    if len(e)==0:
        count += 1
        #print('Yes')

        continue
    elif max(e) < H[i-1]:
        #print(i, H[i - 1], max(e))
        count += 1
        #print('Yes')
    else:
        pass

print(count)

Fixed submission:
N, M = map(int, input().split())
c_list = [[] for _ in range(N)]
e_list = list(map(int, input().split()))
for _ in range(M):
   a, b = map(lambda i: int(i) - 1, input().split())
   c_list[a].append(b)
   c_list[b].append(a)
ans = 0
for i, e in enumerate(e_list):
   for j in c_list[i]:
       if e <= e_list[j]:
           break
   else:
       ans += 1

print(ans)

Buggy python submission (verdict: Runtime Error):
from itertools import chain

n, m = map(int, input().split())
H = list(map(int, input().split()))

ab = []
for i in range(m):
    ab.append(list(map(int, input().split())))

count = 0

for i in range(1, n+1):

    c= []
    e= []
    for j in ab:
        if i in j:
            c.append(j)
    d =list(chain.from_iterable(c))

    for k in d:
        e.append(H[k-1])

    if len(e)==0:

        continue
    else max(e) == H[i-1]:
        count += 1

print(count)

Fixed submission:
N, M = map(int, input().split())
c_list = [[] for _ in range(N)]
e_list = list(map(int, input().split()))
for _ in range(M):
   a, b = map(lambda i: int(i) - 1, input().split())
   c_list[a].append(b)
   c_list[b].append(a)
ans = 0
for i, e in enumerate(e_list):
   for j in c_list[i]:
       if e <= e_list[j]:
           break
   else:
       ans += 1

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())

ans = 0
list = []

for _ in range(n):
    a = input()
    if a not in list:
        list.append(a)
        ans +=1

print(ans)

Fixed submission:
n = int(input())

import sys
S = set(sys.stdin.readlines())



print(len(S))
Buggy python submission (verdict: Time Limit Exceeded):
K = int(input())

ans = 0

import math

for i in range(1, K+1):
    for j in range(1, K+1):
        for k in range(1, K+1):
            ans += math.gcd(i, math.gcd(k,j))

print(ans)

Fixed submission:
K = int(input())

ans = 0

import math

for i in range(1, K+1):
    for j in range(1, K+1):
        s=math.gcd(i, j)
        for k in range(1, K+1):
            ans += math.gcd(k, s)

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = sys.stdin.readline
def main():
    n= int(input())
    s = str(input())
    ans = 0
    for i in range(n-2):
        for j in range(i+1, n-1):
            for k in range (j+1,n):
                t = {s[i], s[j], s[k]}
                if j-i != k-j and len(t) ==3:
                    ans +=1
    print(ans)
if __name__ == '__main__':
    main()

Fixed submission:
import sys
input = sys.stdin.readline
def main():
    n= int(input())
    s = str(input().rstrip())
    r= s.count('R')
    g=s.count('G')
    b = s.count('B')
    ans = 0
    for i in range(n-2):
        for j in range(i+1, (n+i+1)//2):
            k = 2*j-i
            t = {s[i], s[j], s[k]}
            if len(t) ==3:
                ans +=1
    print(r*g*b-ans)
if __name__ == '__main__':
    main()

Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = sys.stdin.readline
n= int(input())
s = str(input())
ans = 0
for i in range(n-2):
    for j in range(i+1, n-1):
        for k in range (j+1,n):
            t = {s[i], s[j], s[k]}
            if j-i != k-j and len(t) ==3:
                ans +=1
print(ans)

Fixed submission:
import sys
input = sys.stdin.readline
def main():
    n= int(input())
    s = str(input().rstrip())
    r= s.count('R')
    g=s.count('G')
    b = s.count('B')
    ans = 0
    for i in range(n-2):
        for j in range(i+1, (n+i+1)//2):
            k = 2*j-i
            t = {s[i], s[j], s[k]}
            if len(t) ==3:
                ans +=1
    print(r*g*b-ans)
if __name__ == '__main__':
    main()

Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = sys.stdin.readline
n= int(input())
s = str(input())
ans = 0
for i in range(n-2):
    for j in range(i+1, n-1):
        for k in range (j+1,n):
            t = {s[i], s[j], s[k]}
            if j-i != k-j and len(t) ==3:
                ans +=1
print(ans)

Fixed submission:
import sys
input = sys.stdin.readline
def main():
    n= int(input())
    s = str(input().rstrip())
    r= s.count('R')
    g=s.count('G')
    b = s.count('B')
    ans = 0
    for i in range(n-2):
        for j in range(i+1, (n+i+1)//2):
            k = 2*j-i
            t = {s[i], s[j], s[k]}
            if len(t) ==3:
                ans +=1
    print(r*g*b-ans)
if __name__ == '__main__':
    main()
Buggy python submission (verdict: Time Limit Exceeded):
n, k = map(int, input().split())

if n <= k :
    print(min(n, k-n))
    exit(0)
if n>k:
    while n-k >=0:
        n -= k
    print(min(n, k-n))

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

if n <= k :
    print(min(n, k-n))
    exit(0)
if n>k:
    n = n%k
    print(min(n, k-n))
Buggy python submission (verdict: Time Limit Exceeded):
k = int(input())

count = 0
check = 1

def lun(n):
    if len(str(n)) ==1:
        return True
    else:
        m = str(check)
        keta = len(m)
        for i in range(1, keta):
            if int(m[i]) != int(m[i-1]) and int(m[i]) != int(m[i-1]) +1 and int(m[i]) != int(m[i-1]) -1:
                return False
        return True

while count < k:
    if lun(check):
        count +=1
    check += 1
print(check-1)

Fixed submission:
from collections import deque

k = int(input())

count = 1
d= deque([1,2,3,4,5,6,7,8,9])
#ls = []
while count <= k:
    v = d.popleft()
    count += 1
    last = str(v)[-1]
    if last == '0':
        d.append(int(str(v) + '0'))
        d.append(int(str(v)+'1'))
    elif last == '9':
        d.append(int(str(v) + '8'))
        d.append(int(str(v) + '9'))
    else:
        d.append(int(str(v) + str(int(last) - 1)))
        d.append(int(str(v) + str(int(last) )))
        d.append(int(str(v) + str(int(last) + 1)))
    #ls.append(v)

#print(ls)
print(v)
Buggy python submission (verdict: Runtime Error):
a, b = map(int, input().split())
x=10*b

import math
for i in range(10):
    if math.floor((x+i)*0.08)==a:
        print(x+i)
        exit(0)

print(-1)

Fixed submission:
s = input()
if s=='AAA' or s== 'BBB':
    print('No')
else:
    print('Yes')