Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
N=int(input())
S=input()
r=[1 if S[0]=="R" else 0]
g=[1 if S[0]=="G" else 0]
b=[1 if S[0]=="B" else 0]

for i in range(1,N):
  if S[i]=="R":
    r.append(r[-1]+1)
    g.append(g[-1])
    b.append(b[-1])
  elif S[i]=="G":
    r.append(r[-1])
    g.append(g[-1]+1)
    b.append(b[-1])
  else:
    r.append(r[-1])
    g.append(g[-1])
    b.append(b[-1]+1)

#print(r)
#print(g)
#print(b)

st={"R","G","B"}

def calc(i,j):
  tmp={i,j}
  ans=st-tmp
  return ans.pop()

#print(calc("R","G"))
ans=0

for i in range(0,N-2):
  for j in range(i+1,N-1):
    if S[j]==S[i]:
      pass
    else:            
      tmp=calc(S[i],S[j])
      if tmp=="R":
        #print(i,j,tmp,r[-1],r[j])
        ans += r[-1]-r[j]
        if j+(j-i)<=N-1:
          if S[j+(j-i)]==tmp:
            ans -=1
      elif tmp=="G":
        #print(i,j,tmp,g[-1],g[j])
        ans += g[-1]-g[j]
        if j+(j-i)<=N-1:
          if S[j+(j-i)]==tmp:
            ans -=1
      else:
        #print(i,j,tmp,b[-1],b[j])
        ans += b[-1]-b[j]
        if j+(j-i)<=N-1:
          if S[j+(j-i)]==tmp:
            ans -=1

print(ans)

Fixed submission:
N=int(input())
S=input()
r=[1 if S[0]=="R" else 0]
g=[1 if S[0]=="G" else 0]
b=[1 if S[0]=="B" else 0]

for i in range(1,N):
  if S[i]=="R":
    r.append(r[-1]+1)
    g.append(g[-1])
    b.append(b[-1])
  elif S[i]=="G":
    r.append(r[-1])
    g.append(g[-1]+1)
    b.append(b[-1])
  else:
    r.append(r[-1])
    g.append(g[-1])
    b.append(b[-1]+1)

#print(r)
#print(g)
#print(b)

st={"R","G","B"}

def calc(i,j):
  tmp={i,j}
  ans=st-tmp
  return ans.pop()

#print(calc("R","G"))
ans=0

for i in range(0,N-2):
  for j in range(i+1,N-1):
    if S[j]==S[i]:
      pass
    else:            
      tmp=calc(S[i],S[j])
      if tmp=="R":
        #print(i,j,tmp,r[-1],r[j])
        ans += r[-1]-r[j]
        if j+(j-i)<=N-1:
          if S[j+(j-i)]==tmp:
            ans -=1
      elif tmp=="G":
        #print(i,j,tmp,g[-1],g[j])
        ans += g[-1]-g[j]
        if j+(j-i)<=N-1:
          if S[j+(j-i)]==tmp:
            ans -=1
      else:
        #print(i,j,tmp,b[-1],b[j])
        ans += b[-1]-b[j]
        if j+(j-i)<=N-1:
          if S[j+(j-i)]==tmp:
            ans -=1

print(ans)
Buggy python submission (verdict: Runtime Error):
K=int(input())
x=[[0] for _ in range(11)]
y=[ 0 for _ in range(11)]

x[1]=[1,2,3,4,5,6,7,8,9]
y[1]=9

for i in range(2,11):
  x[i].pop()
  for num in x[i-1]:
    last = num%10
    if last==0:
      x[i].append(10*num)
      x[i].append(10*num+1)
      y[i] +=2
    elif last==9:
      x[i].append(10*num+8)
      x[i].append(10*num+9)
      y[i] +=2
    else:
      x[i].append(10*num+(last-1))
      x[i].append(10*num+last)
      x[i].append(10*num+(last+1))
      y[i] +=3
      
#print(y)
#print(sum(y))

z=[0,y[1]]
for i in range(2,11):
 z.append(z[-1]+y[i])
#print(z)

maxi=0
for r in range(11):
  if z[r]<=K:
    maxi=max(maxi,r)
    
keta=maxi+1
#print(K-y[maxi])
print(x[keta][K-y[maxi-1]])


Fixed submission:
K=int(input())
x=[[0] for _ in range(11)]
y=[ 0 for _ in range(11)]

x[1]=[1,2,3,4,5,6,7,8,9]
y[1]=9

for i in range(2,11):
  x[i].pop()
  for num in x[i-1]:
    last = num%10
    if last==0:
      x[i].append(10*num)
      x[i].append(10*num+1)
      y[i] +=2
    elif last==9:
      x[i].append(10*num+8)
      x[i].append(10*num+9)
      y[i] +=2
    else:
      x[i].append(10*num+(last-1))
      x[i].append(10*num+last)
      x[i].append(10*num+(last+1))
      y[i] +=3
      
#print(y)
#print(sum(y))

z=[0,y[1]]
for i in range(2,11):
 z.append(z[-1]+y[i])
#print(z)

keta=0
for i,num in enumerate(z):
  if num<=K:
    keta=i+1

s= K-z[keta-1]
#print(s)
print(x[keta][s-1])
Buggy python submission (verdict: Runtime Error):
def calc(P):
    #Pはリスト
    Q=[]
    for str in A:
        if str=="1":
            pass
        elif str=="2":
            Q.append("1")
        else:
            Q.append("2")
    return Q

def solve(P):
    #Pはリスト
    N=len(P)
    if N>1:
        Q=[]
        for i in range(N-1):
            if   abs( int(P[i])-int(P[i+1]) )==0:
                Q.append("0")
            elif abs( int(P[i])-int(P[i+1]) )==1:
                Q.append("1")
            else:
                Q.append("2")
        return solve(Q)
    elif N==0:
    	return(0)
    else:
        return P[0]

N=int(input())
A=input()
B=list(A)

#print(A)
#print(B) 
short=calc(B)
#print(short)

ans=solve(short)
print(ans)


Fixed submission:
H,W=map(int,input().split())
s=[0]*H
for i in range(H):
  s[i]= list(input())

dp= [[float("inf") for _ in range(W)] for _ in range(H)]
dp[0][0]= 1 if s[0][0]=="#" else 0

mv=[(-1,0),(0,-1)]
for i in range(H):
  for j in range(W):
    if i==0 and j==0: pass
    else:
      tmp=float("inf")
      for k in mv:
        a = i+k[0]
        b = j+k[1]
        if 0 <=a <= H-1 and 0 <=b <= W-1:
          if s[i][j]=="#" and s[a][b]==".":
            tmp= dp[a][b]+1
          else:
            tmp= dp[a][b]
        dp[i][j]=min(dp[i][j],tmp)
        
print(dp[-1][-1])
Buggy python submission (verdict: Runtime Error):
from math import sqrt
from decimal import Decimal
 
a,b,c = map(int,input().split())
s=c-a-b

if a*b< (S**2)/4:
  print("Yes")
else:
  print("No")

Fixed submission:
from math import sqrt
from decimal import Decimal
 
a,b,c = map(int,input().split())
s=c-a-b

if s>=0:
  if Decimal(4*a*b)< Decimal(s**2):
    print("Yes")
  else:
    print("No")
else:
  print("No")
Buggy python submission (verdict: Time Limit Exceeded):
N,K=map(int,input().split())
p=list(map(int,input().split()))

maxi=-1
sum=0

for i in range(0,N-K+1):
  sum=0
  for j in range(i,i+K):
    sum += (p[j]+1)/2
  maxi=max(maxi,sum)
  
print(maxi)

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

sum=[0]*N
sum_f=0

for j in range(K):
  sum_f += (p[j]+1)/2
sum[0]=sum_f
  
for i in range(1,N-K+1):
  sum[i]=sum[i-1] - (p[i-1]+1)/2 + (p[i+K-1]+1)/2
  
print(max(sum))

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

maxi=-1
sum=0

for i in range(0,N-K+1):
  sum=0
  for j in range(i,i+K):
    sum += (p[j]+1)/2
    maxi=max(maxi,sum)
  
print(maxi)

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

sum=[0]*N
sum_f=0

for j in range(K):
  sum_f += (p[j]+1)/2
sum[0]=sum_f
  
for i in range(1,N-K+1):
  sum[i]=sum[i-1] - (p[i-1]+1)/2 + (p[i+K-1]+1)/2
  
print(max(sum))

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

maxi=-1
sum=0

for i in range(0,N-K+1):
  sum=0
  for j in range(i,i+K):
    sum += (p[j]+1)/2
    maxi=max(maxi,sum)
  
print(maxi)

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

sum=[0]*N
sum_f=0

for j in range(K):
  sum_f += (p[j]+1)/2
sum[0]=sum_f
  
for i in range(1,N-K+1):
  sum[i]=sum[i-1] - (p[i-1]+1)/2 + (p[i+K-1]+1)/2
  
print(max(sum))
Buggy python submission (verdict: Runtime Error):
N,M=map(int,input().split())
p=[0]*N
S=[0]*N
sei=[0]*N
pena=[0]*N
total=[0]*N

for i in range(M):
  p[i],S[i] = input().split()
  p[i]=int(p[i])

  if S[i]=="AC":
    if sei[p[i]]>=1:
      pass
    else:
      sei[p[i]] +=1
      
  else: # WAのとき
    if sei[p[i]]>=1:
      pass
    else: #0のとき
      pena[p[i]] +=1

for j in range(N):
  total[j]=sei[j]*pena[j]
  
print(sum(sei),sum(total))

Fixed submission:
N,M=map(int,input().split())
p=[0]*M
S=[0]*M
sei=[0]*N
pena=[0]*N
total=[0]*N

for i in range(M):
  p[i],S[i] = input().split()
  p[i]=int(p[i])

  if S[i]=="AC":
    if sei[p[i]-1]>=1:
      pass
    else:
      sei[p[i]-1] +=1
      
  else: # WAのとき
    if sei[p[i]-1]>=1:
      pass
    else: #0のとき
      pena[p[i]-1] +=1

for j in range(N):
  total[j]=sei[j]*pena[j]
  
print(sum(sei),sum(total))
Buggy python submission (verdict: Runtime Error):
N=int(input())
s=[0]*N
t=[0]*N
for i in range(N):
  s[i],t[i] = input().split()
  t[i]=int(t[i])
X=input()

j= s.index(X)
if X==s[-1]:
  ans=0
else:
  ans= t[j+1:]

print(sum(ans))

Fixed submission:
N=int(input())
s=[0]*N
t=[0]*N
for i in range(N):
  s[i],t[i] = input().split()
  t[i]=int(t[i])
X=input()

j= s.index(X)
if X==s[-1]:
  ans=0
else:
  ans= sum(t[j+1:])

print(ans)
Buggy python submission (verdict: Runtime Error):
N,A,B=map(int,input().split())
C=A+B

if C%2==0:
  print(C/2/)
else:
  dist_a=A-1
  dist_b=N-B
  base=min(dist_a,dist_b)
  print(base+(B-A+1)//2)

Fixed submission:
N,A,B=map(int,input().split())
C=B-A

if C%2==0:
  print(C//2)
else:
  dist_a=A-1
  dist_b=N-B
  base=min(dist_a,dist_b)
  print(base+(B-A+1)//2)
Buggy python submission (verdict: Runtime Error):
X = int(input())
flag=False

if X>=2000:
  print(1)
else:
  for i in range(0,21):
    for j in range(0,21-i):
      for k in range(0,21-i-j):
        for l in range(0,21-i-j-k):
          for m in range(0,21-i-j-k-l):
            for n in range(0,21-i-j-k-l-m):
              if 100*i+101*j+102*k+103*l+104*m+105*n==X:
                if flag=False:
                  print(1)
                  flag=True
                  break
              
if flag==False:
  print(0)


Fixed submission:
X = int(input())
flag=False

if X>=2100:
  print(1)
  flag=True
else:
  for i in range(0,22):
    for j in range(0,22-i):
      for k in range(0,22-i-j):
        for l in range(0,22-i-j-k):
          for m in range(0,22-i-j-k-l):
            for n in range(0,22-i-j-k-l-m):
              if 100*i+101*j+102*k+103*l+104*m+105*n==X:
                if flag==False:
                  print(1)
                  flag=True
                  break
              
if flag==False:
  print(0)
Buggy python submission (verdict: Runtime Error):
N=int(input())
A=list(map(int,input().split()))
p=1000000007


R=[0]
G=[0]
B=[0]

#print(A)
ans=1
for i in range(N):
    if A[i]==R[-1]:
        tmp+=1
    if A[i]==G[-1]:
        tmp+=1
    if A[i]==B[-1]:
        tmp+=1
    ans = (ans*tmp)%p

    if A[i]==R[-1]:
        R.append(R[-1]+1)
        G.append(G[-1])
        B.append(B[-1])
    elif A[i]==G[-1]:
        R.append(R[-1])
        G.append(G[-1]+1)
        B.append(B[-1])
    else:
        R.append(R[-1])
        G.append(G[-1])
        B.append(B[-1]+1)
    tmp=0
    
#print(R)
#print(G)
#print(B)
print(ans)

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


R=[0]
G=[0]
B=[0]

#print(A)
ans=1
for i in range(N):
    tmp=0
    if A[i]==R[-1]:
        tmp+=1
    if A[i]==G[-1]:
        tmp+=1
    if A[i]==B[-1]:
        tmp+=1
    ans = (ans*tmp)%p

    if A[i]==R[-1]:
        R.append(R[-1]+1)
        G.append(G[-1])
        B.append(B[-1])
    elif A[i]==G[-1]:
        R.append(R[-1])
        G.append(G[-1]+1)
        B.append(B[-1])
    else:
        R.append(R[-1])
        G.append(G[-1])
        B.append(B[-1]+1)
    
#print(R)
#print(G)
#print(B)
print(ans)
Buggy python submission (verdict: Runtime Error):
X,Y=map(int,input().split())
awa=0

if X==3:
  awa += 100000
elif X==2:
  awa += 200000
else X==1:
  awa += 300000
  
if Y==3:
  awa += 100000
elif Y==2:
  awa += 200000
else Y==1:
  awa += 300000
  
if X==1 and Y==1:
  awa += 400000
  
print(awa)

Fixed submission:
X,Y=map(int,input().split())
awa=0

if X==3:
  awa += 100000
elif X==2:
  awa += 200000
elif X==1:
  awa += 300000
  
if Y==3:
  awa += 100000
elif Y==2:
  awa += 200000
elif Y==1:
  awa += 300000
  
if X==1 and Y==1:
  awa += 400000
  
print(awa)
Buggy python submission (verdict: Runtime Error):
N=int(input())

print(r**2)

Fixed submission:
r=int(input())

print(int(r**2))
Buggy python submission (verdict: Time Limit Exceeded):
import math

def comb(n,k,p):
  """power_funcを用いて(nCk) mod p を求める"""
  from math import factorial
  if n<0 or k<0 or n<k: return 0
  if n==0 or k==0: return 1
  a=factorial(n) %p
  b=factorial(k) %p
  c=factorial(n-k) %p
  return (a*power_func(b,p-2,p)*power_func(c,p-2,p))%p
def power_func(a,b,p):
  """a^b mod p を求める"""
  if b==0: return 1
  if b%2==0:
    d=power_func(a,b//2,p)
    return d*d %p
  if b%2==1:
    return (a*power_func(a,b-1,p ))%p


X,Y=map(int,input().split())

if (2*Y-X)%3!=0 and (2*X-Y)%3!=0:
  print(0)
else:
  P=(2*X-Y)//3
  Q=(2*Y-X)//3
  ans=comb((P+Q),P,(10**9+7))
  print(ans)

Fixed submission:
def framod(x,p=10**9+7):
  a=1
  for i in range(1,x+1):
    a = (a*i)%p
  return a
#############################################
X,Y=map(int,input().split())
p=10**9+7

if (X+Y)%3!=0:
  print(0)
else:
  a = (2*X-Y)//3
  b = (2*Y-X)//3
  t = a+b
  if a<0 or b<0:
    print(0)
  else:
    S=framod(t)
    T=pow(framod(a),p-2,p)
    U=pow(framod(b),p-2,p)
    print(((S*T)%p)*U%p)

Buggy python submission (verdict: Time Limit Exceeded):
import math
from scipy.misc import comb
#from scipy.special import comb

def comb(n,k,p):
  """power_funcを用いて(nCk) mod p を求める"""
  from math import factorial
  if n<0 or k<0 or n<k: return 0
  if n==0 or k==0: return 1
  a=factorial(n) %p
  b=factorial(k) %p
  c=factorial(n-k) %p
  return (a*power_func(b,p-2,p)*power_func(c,p-2,p))%p
def power_func(a,b,p):
  """a^b mod p を求める"""
  if b==0: return 1
  if b%2==0:
    d=power_func(a,b//2,p)
    return d*d %p
  if b%2==1:
    return (a*power_func(a,b-1,p ))%p


X,Y=map(int,input().split())

if (2*Y-X)%3!=0 and (2*X-Y)%3!=0:
  print(0)
else:
  P=(2*X-Y)//3
  Q=(2*Y-X)//3
  #maxi=
  ans=comb((P+Q),P,(10**9+7))
  #ans=combinations((P+Q),P)
  print(ans)

Fixed submission:
def framod(x,p=10**9+7):
  a=1
  for i in range(1,x+1):
    a = (a*i)%p
  return a
#############################################
X,Y=map(int,input().split())
p=10**9+7

if (X+Y)%3!=0:
  print(0)
else:
  a = (2*X-Y)//3
  b = (2*Y-X)//3
  t = a+b
  if a<0 or b<0:
    print(0)
  else:
    S=framod(t)
    T=pow(framod(a),p-2,p)
    U=pow(framod(b),p-2,p)
    print(((S*T)%p)*U%p)
Buggy python submission (verdict: Runtime Error):
from collections import Counter
N=int(input())
D=list(map(int, input().split() ))
d=dict(Counter(D))
p=998244353
#print(d)
maxi=max(d)

mini=float("inf")
ans=1
if D[0]!=0:
  print(0)
else:
  if d[0]!=1:
    print(0)
  else:
    for i in range(1,maxi+1):
      mini=min(mini,d[i])
      if i not in d:
        print(0)
        exit()
      else:
        s =  (d[i-1]**d[i])%p
        ans = (ans * s)%p
    print(ans)
    print(mini)

Fixed submission:
from collections import Counter
N=int(input())
D=list(map(int, input().split() ))
d=dict(Counter(D))
p=998244353
#print(d)
maxi=max(d)

ans=1
if D[0]!=0:
  print(0)
else:
  if d[0]!=1:
    print(0)
  else:
    for i in range(1,maxi+1):
      if i not in d:
        print(0)
        exit()
      else:
        s =  (d[i-1]**d[i])%p
        ans = (ans * s)%p
    print(ans)

Buggy python submission (verdict: Runtime Error):
from collections import Counter
N=int(input())
D=list(map(int, input().split() ))
d=dict(Counter(D))
p=998244353

#print(d)

ans=1
if 0 not in d:
  print(0)
else:
  if d[0]!=1:
    print(0)
  else:
    for num in d:
      if num==0:
        pass
      else:
        s= ((d[num-1])**d[num])%p
        ans = (ans * s)%p
    print(ans)

Fixed submission:
from collections import Counter
N=int(input())
D=list(map(int, input().split() ))
d=dict(Counter(D))
p=998244353
#print(d)
maxi=max(d)

ans=1
if D[0]!=0:
  print(0)
else:
  if d[0]!=1:
    print(0)
  else:
    for i in range(1,maxi+1):
      if i not in d:
        print(0)
        exit()
      else:
        s =  (d[i-1]**d[i])%p
        ans = (ans * s)%p
    print(ans)

Buggy python submission (verdict: Runtime Error):
def combi(n,r):
  s = fac[n]
  t = fac[r]
  u = fac[n-r]
  ans = (s*pow(t,p-2,p)*pow(u,p-2,p) )%p
  return ans
  
from collections import Counter
N=int(input())
D=list(map(int, input().split() ))
di=dict(Counter(D))
p=998244353

fac=[1]
for i in range(1,N):
  fac.append( (fac[-1]*i)%p )

ans=1
for i,num in enumerate(sorted(di)):
  if i==0:
    if di[num]!=1:
      ans=0
      break
  else:    
    ans = (ans * combi(di[i-1]+di[i]-1,di[i-1]-1))%p
    ans = (ans * fac[ di[i-1] ]) %p
    print(i,num,di[num],combi(di[i-1]+di[i]-1,di[i-1]-1),fac[ di[i-1] ],ans)
  
print(ans)

Fixed submission:
from collections import Counter
N=int(input())
D=list(map(int, input().split() ))
d=dict(Counter(D))
p=998244353
#print(d)
maxi=max(d)

ans=1
if D[0]!=0:
  print(0)
else:
  if d[0]!=1:
    print(0)
  else:
    for i in range(1,maxi+1):
      if i not in d:
        print(0)
        exit()
      else:
        s =  (d[i-1]**d[i])%p
        ans = (ans * s)%p
    print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
S=input()
N=len(S)+1
sum=0

for i in range(0,N) :
  l_cnt=0
  r_cnt=0
  for j in range(i-1,-1,-1):
    #print(j)
    if S[j]=="<":
      l_cnt +=1
    else:
      break
  for k in range(i,N-1):
    #print("k=",k,S[k])
    if S[k]==">":
      r_cnt +=1
    else:
      break
  #print(l_cnt,r_cnt)
  sum += max(l_cnt,r_cnt)
  
print(sum)

Fixed submission:
S=input()
N=len(S)+1
cnt=0

# 「<」 がここから左に何個連続しているか
small_left=[1 if S[0]=="<" else 0]
# 「>」 がここから右に何個連続しているか
large_right=[1 if S[-1]==">" else 0]

for i in range(1,len(S)):
  if S[i]=="<":
    small_left.append(small_left[-1]+1) 
  else:
    small_left.append(0) 
    
for i in range(len(S)-2,-1,-1):
  if S[i]==">":
    large_right.append(large_right[-1]+1) 
  else:
    large_right.append(0) 
large_right = large_right[::-1]
#print(large_right,small_left)

cnt += large_right[0]
for i in range(1,N-1):
  cnt += max(large_right[i], small_left[i-1])
cnt += small_left[-1]

print(cnt)

Buggy python submission (verdict: Time Limit Exceeded):
S=input()
N=len(S)+1
sum=0

for i in range(0,N) :
  l_cnt=0
  r_cnt=0
  for j in range(i-1,-1,-1):
    #print(j)
    if S[j]=="<":
      l_cnt +=1
    else:
      break
  for k in range(i,N-1):
    #print("k=",k,S[k])
    if S[k]==">":
      r_cnt +=1
    else:
      break
  #print(l_cnt,r_cnt)
  sum += max(l_cnt,r_cnt)
  
print(sum)

Fixed submission:
S=input()
N=len(S)+1
cnt=0

# 「<」 がここから左に何個連続しているか
small_left=[1 if S[0]=="<" else 0]
# 「>」 がここから右に何個連続しているか
large_right=[1 if S[-1]==">" else 0]

for i in range(1,len(S)):
  if S[i]=="<":
    small_left.append(small_left[-1]+1) 
  else:
    small_left.append(0) 
    
for i in range(len(S)-2,-1,-1):
  if S[i]==">":
    large_right.append(large_right[-1]+1) 
  else:
    large_right.append(0) 
large_right = large_right[::-1]
#print(large_right,small_left)

cnt += large_right[0]
for i in range(1,N-1):
  cnt += max(large_right[i], small_left[i-1])
cnt += small_left[-1]

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

N=int(input())
L=list(map(int, input().split()))
L.sort()

ans=0

for i in range(N-2):
  for j in range(i+1,N-1):
    small = bisect.bisect_left(L, L[j]-L[i])
    large = bisect.bisect_left(L, L[j]+L[i])
    
    #print(i,j,L[i],L[j],"  ",L[j]-L[i],L[j]+L[i],small,large)
    ans += max(large-j-1,0)    
print(ans)

Fixed submission:
import bisect

N=int(input())
L=list(map(int, input().split()))
L.sort()

ans=0
for i in range(N-2):
  for j in range(i+1,N-1):
    #small = bisect.bisect_left(L, L[j]-L[i])
    large = bisect.bisect_left(L, L[j]+L[i])    
    #print(i,j,L[i],L[j],"  ",L[j]-L[i],L[j]+L[i],small,large)
    ans += max(large-j-1,0)    

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
N=int(input())
L=list(map(int, input().split()))
L.sort()
cnt=0

for i in range(0,N-2):
  for j in range(i+1,N-1):
    for k in range(j+1,N):
      if L[k]<L[i]+L[j]:
        if L[i]<L[j]+L[k]:
          if L[j]<L[i]+L[k]:
            cnt+=1
      else:
        break

print(cnt)

Fixed submission:
import bisect

N=int(input())
L=list(map(int, input().split()))
L.sort()

ans=0
for i in range(N-2):
  for j in range(i+1,N-1):
    #small = bisect.bisect_left(L, L[j]-L[i])
    large = bisect.bisect_left(L, L[j]+L[i])    
    #print(i,j,L[i],L[j],"  ",L[j]-L[i],L[j]+L[i],small,large)
    ans += max(large-j-1,0)    

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
N=int(input())
L=list(map(int, input().split()))
L.sort()
cnt=0

for i in range(0,N-2):
  for j in range(i+1,N-1):
    for k in range(j+1,N):
      if L[i]<L[j]+L[k]:
        if L[j]<L[i]+L[k]:
          if L[k]<L[i]+L[j]:
            cnt+=1

print(cnt)

Fixed submission:
import bisect

N=int(input())
L=list(map(int, input().split()))
L.sort()

ans=0
for i in range(N-2):
  for j in range(i+1,N-1):
    #small = bisect.bisect_left(L, L[j]-L[i])
    large = bisect.bisect_left(L, L[j]+L[i])    
    #print(i,j,L[i],L[j],"  ",L[j]-L[i],L[j]+L[i],small,large)
    ans += max(large-j-1,0)    

print(ans)
Buggy python submission (verdict: Runtime Error):
A=int(input())
cnt=0
sum=0

for i in range(1,A+1):
  sum;=1
  if i%2==1:
    cnt+=1
    
print(cnt/sum)

Fixed submission:
A=int(input())
cnt=0
sum=0

for i in range(1,A+1):
  sum+=1
  if i%2==1:
    cnt+=1
    
print(cnt/sum)
Buggy python submission (verdict: Runtime Error):
H,W,A,B=map(int,input().split())
a=[ [-1 for _ in range(W)] for _ in range(H) ]

L=0
for i in range(H):
  R=min(L+A,W)
  for j in range(L,R):
    a[i][j]=0
  for j in range(R,W):
    a[i][j]=1
  if L+A>W:
    p =L+A
    for j in range(0,p):
      a[i][j]=1
    L=p
  else:
    for j in range(0,L):
      a[i][j]=1
    L =L+A

for j in range(W):
  cnt=0
  for i in range(H):
    cnt += a[i][j]
  if min(cnt,H-cnt)>B:
    ans="No"
    print(ans)
    exit()
else:
  for gyou in a:
    st = list( map(str,gyou) )
    print("".join(st))

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

for i in range(B):
  print("0" * A+ "1" * (W-A))
for i in range(B,H):
  print("1" * A+ "0" * (W-A))

Buggy python submission (verdict: Runtime Error):
H,W,A,B=map(int,input().split())
a=[ [-1 for _ in range(W)] for _ in range(H) ]

L=0
for i in range(H):
  R=min(L+A,W)
  for j in range(L,R):
    a[i][j]=0
  for j in range(R,W):
    a[i][j]=1
  if L+A>W:
    p =L+A
    for j in range(0,p):
      a[i][j]=1
    L=p
  else:
    for j in range(0,L):
      a[i][j]=1
    L =L+A

for j in range(W):
  cnt=0
  for i in range(H):
    cnt += a[i][j]
  if min(cnt,H-cnt)>B:
    ans="No"
    print(ans)
    break
else:
  for gyou in a:
    st = list( map(str,gyou) )
    print("".join(st))

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

for i in range(B):
  print("0" * A+ "1" * (W-A))
for i in range(B,H):
  print("1" * A+ "0" * (W-A))
Buggy python submission (verdict: Time Limit Exceeded):
N,K,Q=map(int, input().split())
m=max(N,Q)
A=[0]*m
for i in range(0,Q):
  A[i]=int(input())
S=[0]*m
T=[0]*m
for k in range(Q,m):
  A[k]=-1
  S[k]=-1
  T[k]=-1
  
for i in range(0,N):
  S[i]=A.count(i+1)
  T[i]=Q-S[i]
  if T[i]>=K:
    print("No")
  else:
    print("Yes")

Fixed submission:
N,K,Q=map(int, input().split())
A=[0]*Q
for i in range(0,Q):
  A[i]=int(input())

Score_list=[K]*N
Sum_list=[0]*N
for i in range(0,Q):
  Sum_list[A[i]-1]+=1
 
for i in range(0,N):
  if Q-Sum_list[i]>=K:
    print("No")    
  else:
    print("Yes")
Buggy python submission (verdict: Runtime Error):
a=int(input())
s=input()

If a>=3200:
  print(s)
else:
  print("red")

Fixed submission:
a=int(input())
s=input()

if a>=3200:
  print(s)
else:
  print("red")
Buggy python submission (verdict: Time Limit Exceeded):
N=int(input()) 
t=[[0]*10]*N
y=[[0]*10]*N

for i in range(N):
  s=input()
  for j in range(10):
    t[i][j]=s[j]
  y[i]=sorted(t[i])

y.sort()

count=0

for i in range(0,N-1):
  for j in range(i+1,N):
    #print(i,j,y[i],y[j])
    if y[j]==y[i]:
      count+=1
    else:
      break

print(count)

Fixed submission:
from collections import Counter

N=int(input())
s=[0]*N
t=[0]*N
d=dict()
cnt=0

for i in range(N):
  s[i]=input()
  t[i]=str(sorted(s[i]))
  if t[i] not in d:
    d[t[i]] =1
    #print(i,d)
  else:
    cnt += d[t[i]]
    d[t[i]] +=1
    #print(i,d)

print(cnt)

Buggy python submission (verdict: Time Limit Exceeded):
N=int(input()) 
t=[[0]*10]*N
y=[[0]*10]*N

for i in range(N):
  s=input()
  for j in range(10):
    t[i][j]=s[j]
  y[i]=sorted(t[i])
  
count=0

for i in range(0,N-1):
  for j in range(i+1,N):
    #print(i,t[i])
    #print(j,t[1])

    if y[i]==y[j]:
        count+=1

print(count)

Fixed submission:
from collections import Counter

N=int(input())
s=[0]*N
t=[0]*N
d=dict()
cnt=0

for i in range(N):
  s[i]=input()
  t[i]=str(sorted(s[i]))
  if t[i] not in d:
    d[t[i]] =1
    #print(i,d)
  else:
    cnt += d[t[i]]
    d[t[i]] +=1
    #print(i,d)

print(cnt)