Buggy python submission (verdict: Time Limit Exceeded):
import bisect
N=int(input())
As=list(map(int,input().split()))
Bs=list(map(int,input().split()))
Cs=list(map(int,input().split()))
As.sort()
Bs.sort()
Cs.sort()
pyout=0
for i in range(N):
    num1=bisect.bisect_left(Bs,Cs[i])
    for j in range(num1):
        num2=bisect.bisect_left(As,Bs[j])
        pyout+=num2
print(pyout)

Fixed submission:
N=map(int,input().split())
A=sorted(list(map(int,input().split())))
B=list(map(int,input().split()))
C=sorted(list(map(int,input().split())))
 
def countA(target,L):
  ok=-1
  ng=len(L)
  while abs(ok-ng)>1:
    mid=(ok+ng)//2
    if L[mid]<target:
      ok=mid
    else:
      ng=mid
  return (ok+1)
 
def countC(target,L):
  ok=len(L)
  ng=-1
  while abs(ok-ng)>1:
    mid=(ok+ng)//2
    if L[mid]>target:
      ok=mid
    else:
      ng=mid
  return len(L)-ok
 
ans=0
for i in range(len(B)):
  data=B[i]
  ans+=(countA(data,A)*countC(data,C))
  
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
def nibu(list,item):

    high=len(list)-1

    low=0
    while low <= high:
        mid=(low+high)//2
        guess=list[mid]
        if guess==item:
            return mid+1
            break
        elif guess < item:
            low = mid +1
        elif guess > item:
            high = mid - 1
    if guess != item:
        return high+1



n=int(input())
A=list(map(int,input().split()))
B=list(map(int,input().split()))
C=list(map(int,input().split()))
A.sort()
B.sort()
C.sort()
Bs=[]
s=0
for i in range(n):
    Bs.append(n-nibu(C,B[i]))
for i in range(n):
    Bss=Bs[:]
    Bss=Bs[nibu(B,A[i]):]
    s+=sum(Bss)
print(s)


Fixed submission:
N=map(int,input().split())
A=sorted(list(map(int,input().split())))
B=list(map(int,input().split()))
C=sorted(list(map(int,input().split())))
 
def countA(target,L):
  ok=-1
  ng=len(L)
  while abs(ok-ng)>1:
    mid=(ok+ng)//2
    if L[mid]<target:
      ok=mid
    else:
      ng=mid
  return (ok+1)
 
def countC(target,L):
  ok=len(L)
  ng=-1
  while abs(ok-ng)>1:
    mid=(ok+ng)//2
    if L[mid]>target:
      ok=mid
    else:
      ng=mid
  return len(L)-ok
 
ans=0
for i in range(len(B)):
  data=B[i]
  ans+=(countA(data,A)*countC(data,C))
  
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
def nibu(list,item):

    high=len(list)-1

    low=0
    while low <= high:
        mid=(low+high)//2
        guess=list[mid]
        if guess==item:
            return mid+1
            break
        elif guess < item:
            low = mid +1
        elif guess > item:
            high = mid - 1
    if guess != item:
        return high+1


n=int(input())
A=list(map(int,input().split()))
B=list(map(int,input().split()))
C=list(map(int,input().split()))
A.sort()
B.sort()
C.sort()

sum=0

blist=[]
for i in range(n):

    kadan=nibu(C,B[i])
    u=n-kadan
    blist.append(u)
for i in range(n):
    tyudan=nibu(B,A[i])

    for i in range(tyudan,n):
        sum+=blist[i]

print(sum)


Fixed submission:
N=map(int,input().split())
A=sorted(list(map(int,input().split())))
B=list(map(int,input().split()))
C=sorted(list(map(int,input().split())))
 
def countA(target,L):
  ok=-1
  ng=len(L)
  while abs(ok-ng)>1:
    mid=(ok+ng)//2
    if L[mid]<target:
      ok=mid
    else:
      ng=mid
  return (ok+1)
 
def countC(target,L):
  ok=len(L)
  ng=-1
  while abs(ok-ng)>1:
    mid=(ok+ng)//2
    if L[mid]>target:
      ok=mid
    else:
      ng=mid
  return len(L)-ok
 
ans=0
for i in range(len(B)):
  data=B[i]
  ans+=(countA(data,A)*countC(data,C))
  
print(ans)