Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
L = []
for i in range(k):
    y = x + i
    z = x - i
    if y > 1000000:
        y = x
    L.append(y)
    if z < -1000000:
        z = x
    L.append(z)
I = set(L)
for s in I:
    print(s,end = "")

Fixed submission:

# ABC138
# B One Clue
# K個連続黒、Xが黒、座標-1000000+1000000
k, x = map(int, input().split())
L = []
for i in range(k):
    y = x + i
    z = x - i
    if y > 1000000:
        y = x
    L.append(y)
    if z < -1000000:
        z = x
    L.append(z)
I = set(L)
L = list(sorted(I))
for s in L:
    print(s,end = " ")

Buggy python submission (verdict: Runtime Error):
k, x = map(int, input().split())
L = []
for i in range(k):
    y = x + i
    z = x - i
    if y > 1000000:
        y = x
    L.append(y)
    if z < -1000000:
        z = x
    L.append(z)
printset((L))


Fixed submission:

# ABC138
# B One Clue
# K個連続黒、Xが黒、座標-1000000+1000000
k, x = map(int, input().split())
L = []
for i in range(k):
    y = x + i
    z = x - i
    if y > 1000000:
        y = x
    L.append(y)
    if z < -1000000:
        z = x
    L.append(z)
I = set(L)
L = list(sorted(I))
for s in L:
    print(s,end = " ")
Buggy python submission (verdict: Runtime Error):
x, a = map(int, input())
if x < a:
    print(0)
else:
    print(10)


Fixed submission:
# A Rounding

x, a = map(int, input().split())
if x < a:
    print(0)
else:
    print(10)

Buggy python submission (verdict: Runtime Error):
# A Rounding
x, a = map(int, input())
if x < a:
    print(0)
else:
    print(1o)


Fixed submission:
# A Rounding

x, a = map(int, input().split())
if x < a:
    print(0)
else:
    print(10)
Buggy python submission (verdict: Runtime Error):
a, b, c = map(input().split())
if a * c > b:
    print(b//a)
else:
    print(c)


Fixed submission:
a, b, c = map(int, input().split())
if a * c > b:
    print(b//a)
else:
    print(c)
Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
ans=0
from  itertools import product
l1=[i for i in range(1,n+1)]
l2=[i for i in range(1,n+1)]
l3=[i for i in range(1,n+1)]
p=product(l1,l2,l3)
for a,b,c in p:
    if a*b+c==n:
        ans+=1
print(ans)

Fixed submission:
n=int(input())
ans=0
for i in range(1,n):
    ans+=(n-1)//i
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
ans=0
for i in range(1,n+1):
    for j in range(1,n+1):
        for k in range(1,n+1):
            if i*j+k==n:
                ans+=1
print(ans)

Fixed submission:
n=int(input())
ans=0
for i in range(1,n):
    ans+=(n-1)//i
print(ans)
Buggy python submission (verdict: Runtime Error):
s=str(input())
t=str(input())
ans=0
f=[]
g=len(s)
h=len(t)
n=g-h
for i in range(n):
    for j in range(h):
        if s[i+j]!=t[j]:
            ans+=1
    f.append(ans)
    ans=0
    f.sort()
print(f[0])


Fixed submission:
S = input()
T = input()
n = len(S)
m = len(T)
x = int(1e9)
for i in range(n-m+1):
  cnt = 0
  for j in range(m):
    cnt += (S[i+j] != T[j])
  x = min(x, cnt)
print(x)

Buggy python submission (verdict: Runtime Error):
s=str(input())
t=str(input())
ans=0
f=[]
g=len(s)
h=len(t)
for i in range(g-h):
    for j in range(h):
        if s[i+j]!=t[j]:
            ans+=1
    f.append(ans)
    ans=0
    f.sort()
print(f[0])



Fixed submission:
S = input()
T = input()
n = len(S)
m = len(T)
x = int(1e9)
for i in range(n-m+1):
  cnt = 0
  for j in range(m):
    cnt += (S[i+j] != T[j])
  x = min(x, cnt)
print(x)

Buggy python submission (verdict: Runtime Error):
s=str(input())
t=str(input())
ans=0
f=[]
g=len(s)
h=len(t)
for i in range(g-h):
    for j in range(h):
        if s[i+j]!=t[j]:
            ans+=1
    f.append(ans)
    ans=0
f.sort()
print(int(f[0]))

Fixed submission:
S = input()
T = input()
n = len(S)
m = len(T)
x = int(1e9)
for i in range(n-m+1):
  cnt = 0
  for j in range(m):
    cnt += (S[i+j] != T[j])
  x = min(x, cnt)
print(x)

Buggy python submission (verdict: Runtime Error):
s=str(input())
t=str(input())
ans=0
f=[]
r=0
g=len(s)
h=len(t)
for i in range(g-h):
    for j in range(h):
        if s[i+j]!=t[j]:
            ans+=1
        else:
            r=+1
    f.append(ans)
    ans=0
f.sort()
print(f[0])



Fixed submission:
S = input()
T = input()
n = len(S)
m = len(T)
x = int(1e9)
for i in range(n-m+1):
  cnt = 0
  for j in range(m):
    cnt += (S[i+j] != T[j])
  x = min(x, cnt)
print(x)

Buggy python submission (verdict: Runtime Error):
s=str(input())
t=str(input())
ans=0
f=[]
g=len(s)
h=len(t)
for i in range(g-h):
    for j in range(h):
        if s[i+j]!=t[j]:
            ans+=1
    f.append(ans)
    ans=0
f.sort()
print(f[0])


Fixed submission:
S = input()
T = input()
n = len(S)
m = len(T)
x = int(1e9)
for i in range(n-m+1):
  cnt = 0
  for j in range(m):
    cnt += (S[i+j] != T[j])
  x = min(x, cnt)
print(x)

Buggy python submission (verdict: Runtime Error):
s=str(input())
t=str(input())
ans=0
f=[]
g=len(s)
h=len(t)
for i in range(g-h):
    for j in range(h):
        if s[i+j]!=t[j]:
            ans+=1
    f.append(ans)
    ans=0
f.sort()
print(f[0])


Fixed submission:
S = input()
T = input()
n = len(S)
m = len(T)
x = int(1e9)
for i in range(n-m+1):
  cnt = 0
  for j in range(m):
    cnt += (S[i+j] != T[j])
  x = min(x, cnt)
print(x)
Buggy python submission (verdict: Runtime Error):
from numpy import cumsum
n,k=map(int,input().split())
p=list(map(int,input().split()))
p.sort()
p=cumsum(p)
print((p[k-1]))

Fixed submission:
from numpy import cumsum
n,k=map(int,input().split())
p=list(map(int,input().split()))
p.sort()
p=cumsum(p)
print((p[k-1]))
Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
a=list(map(int,(input().split())))
l=1
for i in range(n):
    l*=a[i]
if l>10**18:
    print('-1')
else:
    print(l)


Fixed submission:
n=int(input())
a=list(map(int,(input().split())))
l=1
a=sorted(a)
for i in range(n):
    l*=a[i]
    if l>10**18:
        print('-1')
        exit()
print(l)
Buggy python submission (verdict: Runtime Error):
s=input()
s.upper()
week=['sun','mon','tue','wed','thu','fri','sat']
ans=week.index(s)
print(7-ans)

Fixed submission:
s=input()
s=s.lower()
week=['sun','mon','tue','wed','thu','fri','sat']
ans=week.index(s)
print(7-int(ans))
Buggy python submission (verdict: Runtime Error):
n,k=map(int,input().split())
s=input()
w=s[k+1]
w=w.lower()
ans=s[:k+1]+w+s[n:]
print(ans)

Fixed submission:
n,k=map(int,input().split())
s=list(input())
s[k-1]=str.lower(s[k-1])
print(''.join(s))
Buggy python submission (verdict: Runtime Error):
c=input()
print(chr(ord(c)+1))

Fixed submission:
n,k=map(int,input().split())
h=list(map(int,input().split()))
dp=[0] + [float('inf')]*(n-1)
for i in range(n):
    for j in range(max(0,i-k),i):
        dp[i]=min(dp[i],dp[j]+abs(h[i]-h[j]))
print(dp[-1])
Buggy python submission (verdict: Runtime Error):
i=(48-i)
print(input())

Fixed submission:
i=int(input())
print(48-i)

Buggy python submission (verdict: Runtime Error):
print(48-i)
i=int(input())

Fixed submission:
i=int(input())
print(48-i)
Buggy python submission (verdict: Time Limit Exceeded):
k,s = map(int,input().split())
ans = 0
for i in range(k+1):
    for j in range(k+1):
        for k in range(k+1):
            if i + j + k ==s:
                ans += 1
print(ans)

Fixed submission:
k,s = map(int,input().split())
ans = 0
for i in range(k+1):
    for j in range(k+1):
        z = s - i - j
        if 0 <= z <= k:
            ans += 1

print(ans)
Buggy python submission (verdict: Runtime Error):
import numpy as np
import math
k=int(input())
a,b=map(int,input().split())

#print((a%k*b%k))

if((b//k-a//k)>=1 or (b%k*a%k)==0):
  print("OK")
else:
  print("NG")

Fixed submission:
import numpy as np
import math
k=int(input())
a,b=map(int,input().split())

#print((a%k*b%k))

if((b//k-a//k)>=1 or (b%k*a%k)==0):
  print("OK")
else:
  print("NG")
Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
l=[]
index=1
l.append(input())

for i in range(n-1):
  tmp=input()
  flg=0
  for j in range(index):
    if(l[j]==tmp):
      flg=1
      break
  if(flg==0):
    l.append(tmp)
    index=index+1
  #print(i,index)

print(index)

Fixed submission:
n=int(input())
l={}

for i in range(n):
  l[input()]=1

print(len(l))
Buggy python submission (verdict: Runtime Error):
H,W=map(int,input().split())

a=[[0]*W for i in range(H)]
b=[[0]*W for i in range(H)]


for i in range(H):
	a[i]=input().split(",")

for j in range(1,W):
	b[0][j]=b[0][j-1]+int(not(a[0][j]==a[0][j-1]))

for i in range(1,H):
	b[i][0]=b[i-1][0]+int(not(a[i-1][0]==a[i][0]))
	for j in range(1,W):
		b[i][j]=min(b[i-1][j]+int(not(a[i-1][j]==a[i][j])),b[i][j-1]+int(not(a[i][j-1]==a[i][j])))
	
print(b[H-1][W-1])


Fixed submission:
H,W=map(int,input().split())

a=[[0]*W for i in range(H)]
b=[[0]*W for i in range(H)]

#print(b)

for i in range(H):
	a[i]=list(input())
#print(a)
    
for j in range(1,W):
	b[0][j]=b[0][j-1]+int(not(a[0][j]==a[0][j-1]))

for i in range(1,H):
	b[i][0]=b[i-1][0]+int(not(a[i-1][0]==a[i][0]))
	for j in range(1,W):
		b[i][j]=min(b[i-1][j]+int(not(a[i-1][j]==a[i][j])),b[i][j-1]+int(not(a[i][j-1]==a[i][j])))

if(a[0][0]=="." and a[H-1][W-1]=="."):
	print(int(b[H-1][W-1]/2))
elif(a[0][0]=="#" and a[H-1][W-1]=="#"):
  print(int(b[H-1][W-1]/2+1))
else:
  print(int((b[H-1][W-1]+1)/2))
#print(int(b[H-1][W-1]/2))
Buggy python submission (verdict: Runtime Error):
n,a,b=map(int,input().split())

tmp1,tmp2=divmod(n,a+b)

blue=tmp1*a
if(tmp2>a):
  blue=blue+a
else:
  blue=blue+tmp2
  
print(blue)

Fixed submission:
S=list(input())

if(S[0]==S[1] and S[1]==S[2]):
  print("No")
  
else:
  print("Yes")
Buggy python submission (verdict: Runtime Error):
n,a,b=input().split()

tmp1,tmp2=divmod(N,a+b)

blue=tmp1*a
if(tmp2>a):
  blue=blue+a
eles:
  blue=blue+tmp2
  
print("blue")

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

tmp1,tmp2=divmod(n,a+b)

blue=tmp1*a
if(tmp2>a):
  blue=blue+a
else:
  blue=blue+tmp2
  
print(blue)
Buggy python submission (verdict: Runtime Error):
N = int(input())
A = list(map(int,input().split()))
sumA = sum(A)%(1000000007)
sumA2 = (sumA * sumA)%(1000000007)
square = 0
for i in range(N):
    square +=  ( A[i]**2 ) % (1000000007)
    square = square % (1000000007)
buf = sumA2 - square
if buf < 0:
  buf = buf + (1000000007)
res = ( buf * ((1000000007+1)//2)) % 1000000007
print(round(res))

Fixed submission:
D,T,S = map(int,input().split())
duration = float(D)/float(S)
if duration > T:
  print("No")
else:
  print("Yes")
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = list(map(int,input().split()))
pro = []
for i in range(N-1):
    redi = 0
    for j in range(i+1,N):
        redi += (A[i] * A[j])%(1000000007)
    pro.append(redi)
red = sum(pro)
res = red%(1000000007)
print(res)

Fixed submission:
N = int(input())
A = list(map(int,input().split()))
sumA = sum(A)%(1000000007)
sumA2 = (sumA * sumA)%(1000000007)
square = 0
for i in range(N):
    square +=  ( A[i]**2 ) % (1000000007)
    square = square % (1000000007)
buf = sumA2 - square
if buf < 0:
  buf = buf + (1000000007)
res = ( buf * ((1000000007+1)//2)) % 1000000007
print(int(res))

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = list(map(int,input().split()))
pro = []
for i in range(N-1):
    redi = 0
    for j in range(i+1,N):
        redi += (A[i] * A[j])%(1000000007)
    pro.append(redi)
red = 0
for i in range(N-1):
    red += pro[i]%(1000000007)
    red = red%(1000000007)
print(red)

Fixed submission:
N = int(input())
A = list(map(int,input().split()))
sumA = sum(A)%(1000000007)
sumA2 = (sumA * sumA)%(1000000007)
square = 0
for i in range(N):
    square +=  ( A[i]**2 ) % (1000000007)
    square = square % (1000000007)
buf = sumA2 - square
if buf < 0:
  buf = buf + (1000000007)
res = ( buf * ((1000000007+1)//2)) % 1000000007
print(int(res))
Buggy python submission (verdict: Runtime Error):
def how(c):
    if float(c).is_integer() == True:
        return int(float(c)),0
    else:
        dot=0
        while c[dot]!=".":
            dot+=1
        c = list(c)
        del c[dot]
        c ="".join(c)
        return int(c),len(c)-dot

def lo2(n):
    count = 0
    while n%2==0:
        n=n//2
        count+=1
    return count

def lo5(n):
    count=0
    while n%5==0:
        n=n//5
        count+=1
    return count

N = int(input())

A = []

for i in range(N):
    A.append(how(input()))


ruiseki = [[0]*80 for i in range(80)]

motoseisuu=0
for i in range(N):
    ruiseki[A[i][1]-lo2(A[i][0])+60][A[i][1]-lo5(A[i][0])+60]+=1
    if A[i][1]==0:
        motoseisuu +=1

for i in range(1,80):
    for j in range(1,80):
        ruiseki[i][j]=ruiseki[i-1][j]+ruiseki[i][j-1]-ruiseki[i-1][j-1]+ruiseki[i][j]


ans = 0
for i in range(N):
    ans+=ruiseki[lo2(A[i][0])+60-A[i][1]][lo5(A[i][0])+60-A[i][1]]

print((ans-motoseisuu)//2)


Fixed submission:
def how(c):
    if float(c).is_integer() == True:
        return int(float(c)),0
    else:
        dot=0
        while c[dot]!=".":
            dot+=1
        c = list(c)
        del c[dot]
        c ="".join(c)
        return int(c),len(c)-dot

def lo2(n):
    count = 0
    while n%2==0:
        n=n//2
        count+=1
    return count

def lo5(n):
    count=0
    while n%5==0:
        n=n//5
        count+=1
    return count

N = int(input())

A = []

for i in range(N):
    A.append(how(input()))


ruiseki = [[0]*120 for i in range(120)]

motoseisuu=0
for i in range(N):
    ruiseki[A[i][1]-lo2(A[i][0])+60][A[i][1]-lo5(A[i][0])+60]+=1
    if A[i][1]==0:
        motoseisuu +=1

for i in range(1,120):
    for j in range(1,120):
        ruiseki[i][j]=ruiseki[i-1][j]+ruiseki[i][j-1]-ruiseki[i-1][j-1]+ruiseki[i][j]


ans = 0
for i in range(N):
    ans+=ruiseki[lo2(A[i][0])+60-A[i][1]][lo5(A[i][0])+60-A[i][1]]

print((ans-motoseisuu)//2)
Buggy python submission (verdict: Time Limit Exceeded):
K = int(input())

if K ==2 or K == 5 or K%2==0:
    print(-1)
    exit()

preamari = 7%K
ans = 1
while preamari != 0:
    preamari = (preamari*10 + 7%K)%K
    ans+=1

print(ans)

Fixed submission:
K = int(input())

if K ==2 or K%5==0 or K%2==0:
    print(-1)
    exit()

preamari = 7%K
ans = 1
while preamari != 0:
    preamari = (preamari*10 + 7%K)%K
    ans+=1

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
N,K = map(int,input().split())
A = list(map(int,input().split()))

pre = A
for i in range(0,K,1):
    now = [0]*N
    for j in range(0,N,1):
        for k in range(max(0,j-pre[j]),min(N,j+pre[j]+1),1):
            now[k]+=1
    owari = True
    for j in range(0,N,1):
        if now[j]!=N:
            owari = False
        pre[j]=now[j]
    if owari:
        break
print(" ".join(list(map(str,now))))

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

pre = A
for i in range(0,K,1):
    now = [0]*N

    kuiL = [0]*N
    kuiR = [0]*N
    for j in range(0,N,1):
        #for k in range(max(0,j-pre[j]),min(N,j+pre[j]+1),1):
        #    now[k]+=1
        kuiL[max(0,j-pre[j])]+=1
        kuiR[min(N-1,j+pre[j])]+=1
    tmp = 0
    for j in range(0,N,1):
        if j!=0:
            tmp = tmp + kuiL[j]-kuiR[j-1]
        else:
            tmp = tmp + kuiL[j]
        now[j]+=tmp

    owari = True
    for j in range(0,N,1):
        if now[j]!=N:
            owari = False
        pre[j]=now[j]
    if owari:
        break
print(" ".join(list(map(str,now))))
Buggy python submission (verdict: Time Limit Exceeded):
MOD = 998244353

N,M,K = map(int,input().split())

ans = 0
NCi = 1#nからi選ぶ組み合わせ
for i in range(0,K+1,1):
    ans = (ans + M * pow(M-1,N-1-i,MOD)*NCi)%MOD
    NCi = NCi*(N-1-i)*pow((i+1),MOD-2,MOD)

print(ans)

Fixed submission:
MOD = 998244353

N,M,K = map(int,input().split())

ans = 0
NCi = 1#nからi選ぶ組み合わせ
for i in range(0,K+1,1):
    ans = (ans + M * pow(M-1,N-1-i,MOD)*NCi)%MOD
    NCi = (NCi*(N-1-i) * pow((i+1),MOD-2,MOD))%MOD

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
import bisect

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

mem =[]
count =0

for i in range(N-1,-1,-1):
    count += bisect.bisect_right(mem,A[i]+i)-bisect.bisect_left(mem,A[i]+i)
    bisect.insort(mem,i-A[i])

print(count)

Fixed submission:
import bisect

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

mem =[0 for i in range(0,N +1,1)]
count =0

for i in range(N-1,-1,-1):
    if A[i]+i < N:
        count+=mem[A[i]+i]

    if i - A[i] > 0:
        mem[i - A[i]]+=1

print(count)
Buggy python submission (verdict: Runtime Error):
S=input()
mem_mod = [0 for i in range(0,2019,1)]
N = len(S)
counter = 0
S_num_tmp = list(S)
S_num = list(map(int, S_num_tmp))
tmp=10

for i in range(1,N,1):
    S_num[N-i-1] = S_num[N-i] + S_num[N-i-1]*pow(10,i,2019)

for i in range(0,N,1):
    X = S_num[N-i-1] % 2019
    if X==0:
        counter+=1
    counter += mem_mod[X]
    mem_mod[X] += 1
print(counter)

Fixed submission:
e = list(map(int,input().split(sep=" ")))
if e[0]<=e[1]:
    print("unsafe")
else:
    print("safe")

Buggy python submission (verdict: Runtime Error):
S=input()
mem_mod = [0 for i in range(0,2019,1)]
N = len(S)
counter = 0
S_num_tmp = list(S)
S_num = list(map(int, S_num_tmp))
tmp=10

Fixed submission:
e = list(map(int,input().split(sep=" ")))
if e[0]<=e[1]:
    print("unsafe")
else:
    print("safe")

Buggy python submission (verdict: Runtime Error):
S=input()
mem_mod = [0 for i in range(0,2019,1)]
N = len(S)
counter = 0
S_num_tmp = list(S)
S_num = list(map(int, S_num_tmp))
tmp=10

Fixed submission:
e = list(map(int,input().split(sep=" ")))
if e[0]<=e[1]:
    print("unsafe")
else:
    print("safe")
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = list(map(int,input().split(sep=" ")))
for i in range(1,N+1,1):
    print(A.count(i))

Fixed submission:
N = int(input())
A = list(map(int,input().split(sep=" ")))
Acounter = []
for i in range(0,N,1):
    Acounter.append(0)
for i in range(0,N-1,1):
    Acounter[A[i]-1]+=1
for i in range(0,N,1):
    print(Acounter[i])
Buggy python submission (verdict: Time Limit Exceeded):
import fractions
K = int(input())
sum = 0
for a in range(1,K+1,1):
    for b in range(1,K+1,1):
        tmp = fractions.gcd(a,b)
        for c in range(1,K+1,1):
            sum+=fractions.gcd(c,tmp)
print(sum)

Fixed submission:
import math
K = int(input())
sum = 0
for a in range(1,K+1,1):
    for b in range(1,K+1,1):
        tmp = math.gcd(a,b)
        for c in range(1,K+1,1):
            sum+=math.gcd(c,tmp)
print(sum)

Buggy python submission (verdict: Time Limit Exceeded):
import fractions
K = int(input())
sum = 0
for a in range(1,K+1,1):
    for b in range(1,K+1,1):
        for c in range(1,K+1,1):
            sum+=fractions.gcd(c,fractions.gcd(a,b))
print(sum)

Fixed submission:
import math
K = int(input())
sum = 0
for a in range(1,K+1,1):
    for b in range(1,K+1,1):
        tmp = math.gcd(a,b)
        for c in range(1,K+1,1):
            sum+=math.gcd(c,tmp)
print(sum)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
S = list(input())
R = []
G = []
B = []
Rsize =0
Gsize =0
Bsize =0
for i in range(0,N,1):
    if S[i] == "R":
        R.append(i)
        Rsize+=1
    elif S[i] == "G":
        G.append(i)
        Gsize+=1
    elif S[i] == "B":
        B.append(i)
        Bsize+=1
counter = 0
for i in range(0,Rsize,1):
    for j in range(0,Gsize,1):
        for k in range(0, Bsize, 1):
            tmp = sorted([R[i],G[j],B[k]])
            if tmp[1]-tmp[0] != tmp[2] - tmp[1]:
                counter+=1

print(counter)

Fixed submission:
N = int(input())
S = list(input())
R = []
G = []
B = []
Rsize =0
Gsize =0
Bsize =0
for i in range(0,N,1):
    if S[i] == "R":
        Rsize+=1
    elif S[i] == "G":
        Gsize+=1
    elif S[i] == "B":
        Bsize+=1
counter = Rsize*Gsize*Bsize
for i in range(0,N-1,1):
    for j in range(i+1,N,1):
        k = 2*j - i
        if k < N:
            if S[i]!=S[j] and S[j]!=S[k] and S[i]!=S[k]:
                counter -=1
print(counter)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
S = list(input())
R = []
G = []
B = []
Rsize =0
Gsize =0
Bsize =0
for i in range(0,N,1):
    if S[i] == "R":
        R.append(i)
        Rsize+=1
    elif S[i] == "G":
        G.append(i)
        Gsize+=1
    elif S[i] == "B":
        B.append(i)
        Bsize+=1
counter = 0
for i in range(0,Rsize,1):
    for j in range(0,Gsize,1):
        for k in range(0, Bsize, 1):
            tmp = sorted([R[i],G[j],B[k]])
            if tmp[1]-tmp[0] != tmp[2] - tmp[1]:
                counter+=1

print(counter)

Fixed submission:
N = int(input())
S = list(input())
R = []
G = []
B = []
Rsize =0
Gsize =0
Bsize =0
for i in range(0,N,1):
    if S[i] == "R":
        Rsize+=1
    elif S[i] == "G":
        Gsize+=1
    elif S[i] == "B":
        Bsize+=1
counter = Rsize*Gsize*Bsize
for i in range(0,N-1,1):
    for j in range(i+1,N,1):
        k = 2*j - i
        if k < N:
            if S[i]!=S[j] and S[j]!=S[k] and S[i]!=S[k]:
                counter -=1
print(counter)
Buggy python submission (verdict: Time Limit Exceeded):
N,X,Y = map(int,input().split(sep=" "))
root = []
X = X-1
Y = Y-1
for i in range(0,N,1):
    for j in range(i+1,N,1):
        if j - i < abs(i-X)+abs(j-Y)+1:
            root.append(j-i)
        else:
            root.append(abs(i-X)+abs(j-Y)+1)
for k in range(1,N,1):
    print(root.count(k))
    root.count(k)

Fixed submission:
N,X,Y = map(int,input().split(sep=" "))
root = []
X = X-1
Y = Y-1
sumRoot = [0 for i in range(0,N-1,1)]
for i in range(0,N,1):
    for j in range(i+1,N,1):
        if j - i < abs(i-X)+abs(j-Y)+1:
            sumRoot[j-i-1] += 1
        else:
            sumRoot[abs(i-X)+abs(j-Y)] += 1
for k in range(0,N-1,1):
    print(sumRoot[k])
Buggy python submission (verdict: Time Limit Exceeded):
S = input()
Q = int(input())

for i in range(0,Q,1):
    q = input()
    if q[0]=="1":
        S=S[::-1]

    elif q[0]=="2":
        num,F,C = q.split(sep=" ")
        if F=="1":
            S=C+S
        elif F=="2":
            S=S+C
print(S)

Fixed submission:
S = input()
Q = int(input())
q = [input() for i in range(Q)]
reverse = False
p =[]
f =[]
appP = p.append
appF = f.append

for i in range(0,Q,1):
    if q[i][0]=="1":
        reverse=not reverse

    elif q[i][0]=="2":
        num,F,C = q[i].split(sep=" ")
        if F=="1":
            if reverse == False:
                appP(C)
            else:
                appF(C)
        elif F=="2":
            if reverse == False:
                appF(C)
            else:
                appP(C)
if reverse:
    tmpP="".join(p)
    tmpF="".join(f[::-1])
    print(tmpF+S[::-1]+tmpP)
else:
    tmpF="".join(f)
    tmpP="".join(p[::-1])
    print(tmpP+S+tmpF)
Buggy python submission (verdict: Runtime Error):
N,P = map(int,input().split())
S=input()
mem_mod = [0 for i in range(0,2019,1)]
counter = 0
S_num = list(map(int, S))
tmp=10

for i in range(1,N,1):
    S_num[N-i-1] = S_num[N-i] + S_num[N-i-1]*pow(10,i,P)

for i in range(0,N,1):
    X = S_num[N-i-1] % P
    if X==0:
        counter+=1
    counter += mem_mod[X]
    mem_mod[X] += 1
print(counter)

Fixed submission:
import sys

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

ans = 0

if 10 % P == 0:
    for r in range(len(A)):
        if int(A[r]) % P == 0:
            ans += r + 1
    print(ans)
    sys.exit()


A = "0" + A[::-1]

S = [0] * len(A)
cnt = [0] * P
cnt[0] = 1

for i in range(len(A) - 1):
    S[i + 1] = (S[i] + int(A[i + 1]) * pow(10, i, P)) % P
    cnt[S[i + 1] % P] += 1
# print(S, cnt)

# ans = cnt[0] * (cnt[0] - 1) // 2
for c in cnt:
    ans += c * (c - 1) // 2
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
N,P = map(int,input().split(sep=" "))
S = input()
count=0
for i in range(0,N,1):
    for j in range(i,N,1):
        tmp = int(S[i:j+1])
        if tmp%P == 0:
            count += 1

print(count)


Fixed submission:
import sys

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

ans = 0

if 10 % P == 0:
    for r in range(len(A)):
        if int(A[r]) % P == 0:
            ans += r + 1
    print(ans)
    sys.exit()


A = "0" + A[::-1]

S = [0] * len(A)
cnt = [0] * P
cnt[0] = 1

for i in range(len(A) - 1):
    S[i + 1] = (S[i] + int(A[i + 1]) * pow(10, i, P)) % P
    cnt[S[i + 1] % P] += 1
# print(S, cnt)

# ans = cnt[0] * (cnt[0] - 1) // 2
for c in cnt:
    ans += c * (c - 1) // 2
print(ans)