Problem:
 Score : 300 points    Problem Statement The season for Snuke Festival has come again this year. First of all, Ringo will perform a ritual to summon Snuke. For the ritual, he needs an altar, which consists of three parts, one in each of the three categories: upper, middle and lower.  He has N parts for each of the three categories. The size of the i -th upper part is A_i , the size of the i -th middle part is B_i , and the size of the i -th lower part is C_i .  To build an altar, the size of the middle part must be strictly greater than that of the upper part, and the size of the lower part must be strictly greater than that of the middle part. On the other hand, any three parts that satisfy these conditions can be combined to form an altar.  How many different altars can Ringo build? Here, two altars are considered different when at least one of the three parts used is different.      Constraints  1 \leq N \leq 10^5  1 \leq A_i \leq 10^9(1\leq i\leq N)  1 \leq B_i \leq 10^9(1\leq i\leq N)  1 \leq C_i \leq 10^9(1\leq i\leq N)  All input values are integers.         Input Input is given from Standard Input in the following format:  N  A_1  ...  A_N  B_1  ...  B_N  C_1  ...  C_N       Output Print the number of different altars that Ringo can build.        Sample Input 1 2
1 5
2 4
3 6      Sample Output 1 3  The following three altars can be built:   Upper: 1 -st part, Middle: 1 -st part, Lower: 1 -st part  Upper: 1 -st part, Middle: 1 -st part, Lower: 2 -nd part  Upper: 1 -st part, Middle: 2 -nd part, Lower: 2 -nd part        Sample Input 2 3
1 1 1
2 2 2
3 3 3      Sample Output 2 27       Sample Input 3 6
3 14 159 2 6 53
58 9 79 323 84 6
2643 383 2 79 50 288      Sample Output 3 87

Solution (Python):
n=int(input())
a=list(map(int,input().split(' ')))
b=list(map(int,input().split(' ')))
c=list(map(int,input().split(' ')))
a=[0]+sorted(a)+[float('inf')]
c=[0]+sorted(c)+[float('inf')]


def meguru_a(bi):
    ng=n+1 ; ok=0
    while (abs(ok - ng) > 1): 
        mid = (ok + ng) // 2
        if a[mid] < bi :
            ok = mid
        else:
            ng = mid
    return ok

def meguru_c(bi):
    ng=-1 ; ok=n
    while (abs(ok - ng) > 1):
        mid = (ok + ng) // 2
        if bi < c[mid+1]:
            ok = mid
        else:
            ng = mid
    return ok

altar=0

for bi in b:
    s=meguru_a(bi)*(n - meguru_c(bi))
    altar+=s
print(altar)

Solution (Python):
import bisect
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()
ans = 0

for b in B:
    ok_a = bisect.bisect_left(A,b)
    ok_c = bisect.bisect_right(C,b)
    ans += ok_a*(N-ok_c)
print(ans)

Solution (Python):
import bisect

N = int(input())
A = [int(x) for x in input().split()]
B = [int(x) for x in input().split()]
C = [int(x) for x in input().split()]

A.sort()
B.sort()
C.sort()

ans = 0
for b in B:
    ans += bisect.bisect_left(A, b) * (N - bisect.bisect_right(C, b))
print(ans)

Solution (Python):
def n0():return int(input())
def n1():return [int(x) for x in input().split()]
def n2(n):return [int(input()) for _ in range(n)]
def n3(n):return [[int(x) for x in input().split()] for _ in range(n)]

n=n0()
a=n1()
b=n1()
c=n1()

a.sort()
b.sort()
c.sort()

from bisect import bisect_left,bisect_right
b2=[]
for i in b:
    b2.append(bisect_left(a,i))

import itertools
b3=list(itertools.accumulate(b2))
    
ans=0
for i in c:
    t=bisect_left(b,i)
    if t>0:
        ans+=b3[t-1]
    
print(ans)

Solution (Python):
def n0():return int(input())
def n1():return [int(x) for x in input().split()]
def n2(n):return [int(input()) for _ in range(n)]
def n3(n):return [[int(x) for x in input().split()] for _ in range(n)]

n=n0()
a=n1()
b=n1()
c=n1()

a.sort()
b.sort()
c.sort()

from bisect import bisect_left,bisect_right
b2=[]
for i in b:
    b2.append(bisect_left(a,i))

import itertools
b3=list(itertools.accumulate(b2))
    
ans=0
for i in c:
    t=bisect_left(b,i)
    if t>0:
        ans+=b3[t-1]
    
print(ans)

Solution (Python):
n=int(input())
a=list(map(int,input().split(' ')))
b=list(map(int,input().split(' ')))
c=list(map(int,input().split(' ')))
a=[0]+sorted(a)+[float('inf')]
c=[0]+sorted(c)+[float('inf')]


def bin_search_a(a,b):
    low=0
    high=len(a)-1
    while low<=high:
        mid=(low+high)//2
        if a[mid] < b <= a[mid+1]:
            return mid
        if a[mid] >= b:
            high=mid-1
        else:
            low=mid+1
    
def bin_search_c(c,b):
    low=0
    high=len(c)-1
    while low<=high:
        mid=(low+high)//2
        if c[mid] <= b < c[mid+1]:
            return mid
        if c[mid] > b:
            high=mid-1
        else:
            low=mid+1

altar=0

for bi in b:
    s=bin_search_a(a,bi)*(n-bin_search_c(c,bi))
    altar+=s
print(altar)

Solution (Python):
def binary_search_1(data,value):
  l=0
  r=len(data)
  while l < r:
    mid = (l+r) // 2
    if data[mid] < value:
      l = mid + 1
    else:
      r = mid
  return l  

def binary_search_2(data,value):
  l=0
  r=len(data)
  while l < r:
    mid = (l+r) // 2
    if value < data[mid]:
      r = mid 
    else:
      l = mid + 1
  return l  
  
n=int(input())

a=sorted(list(map(int,input().split())))
b=sorted(list(map(int,input().split())))
c=sorted(list(map(int,input().split())))
cnt=0

for i in b:
    cnt +=(binary_search_1(a,i)*(len(c)-binary_search_2(c,i)))

print(cnt)

Solution (Python):
import bisect

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()

count = 0
for j in range(n):
    i = bisect.bisect_left(A, B[j])
    k = bisect.bisect(C, B[j])
    count += (i * (n - k))

print(count)

Solution (Python):
import bisect

n = int(input())
a = sorted(list(map(int, input().split())))
b = list(map(int, input().split()))
c = sorted(list(map(int, input().split())))

ans = 0
for i in b:
    a_pos = bisect.bisect_left(a, i)
    c_pos = n - bisect.bisect_right(c, i)
    ans += a_pos * c_pos

print(ans)

Solution (Python):
import bisect
n=int(input())
al=list(map(int,input().split()))
bl=list(map(int,input().split()))
cl=list(map(int,input().split()))

al.sort()
bl.sort()
cl.sort()

ans=0
for b in bl:
    ac=bisect.bisect_right(al,b-1)
    cc=n-bisect.bisect_left(cl,b+1)
    ans+=ac*cc
print(ans)

Solution (Python):
import bisect
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()

cnt = 0
for i in b:
	x = bisect.bisect_left(a,i)
	y = bisect.bisect_right(c,i)
	cnt += x*(n-y)
print (cnt)

Solution (Python):
import bisect

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

ans=0
for i in range(N):
    a=bisect.bisect_right(A,B[i]-1)
    c=N-bisect.bisect_left(C,B[i]+1)
    ans+=a*c
print(ans)

Solution (Python):
def bs_left(list, target):
    low = 0
    high = len(list)

    while low < high:
        mid = (low + high) // 2
        if target > list[mid]:
            low = mid + 1
        else:
            high = mid
    return low

def bs_right(list, target):
    low = 0
    high = len(list)
    while low < high:
        mid = (low + high) // 2
        if target < list[mid]:
            high = mid
        else:
            low = mid + 1
    return low

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

ans = 0
for b in B:
    ans += (bs_left(A, b) * (n - bs_right(C, b)))
print(ans)

Solution (Python):
def main():
    import bisect
    n = int(input())
    a_lis = list(map(int, input().split()))
    b_lis = list(map(int, input().split()))
    c_lis = list(map(int, input().split()))
    a_lis.sort()
    b_lis.sort()
    c_lis.sort()
    cnt = 0

    for b in b_lis:
        a = bisect.bisect_left(a_lis, b)
        c = n - bisect.bisect_right(c_lis, b)
        cnt += a * c

    print(cnt)
        


    


if __name__ == "__main__":
    main()

Solution (Python):
n = int(input())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
c = list(map(int,input().split()))

import bisect
a.sort()
b.sort()
c.sort()
ans = 0
for i in range(len(b)):
    ab = bisect.bisect_right(a,b[i]-1) 
    bc = len(c) - bisect.bisect_left(c,b[i]+1) 
    ans += ab*bc
print(ans)

Solution (Python):
import bisect


def main():
    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()
    ans = 0
    for i in range(N):
        ans += bisect.bisect_left(A, B[i]) * (N - bisect.bisect_right(C, B[i]))
    print(ans)


if __name__ == '__main__':
    main()

Solution (Python):
import itertools
import bisect
n = int(input())
a=sorted(list(map(int, input().split())))
b=sorted(list(map(int, input().split())))
c=sorted(list(map(int, input().split())))
cnt=0

for i in range(0,len(b)):
    a_index = bisect.bisect_left(a,b[i])
    c_index = bisect.bisect_right(c,b[i])
    cnt+=a_index*(len(c)-c_index)
    
print(cnt)

Solution (Python):
import sys
def input(): return sys.stdin.readline().strip()

def resolve():
    import bisect
    n=int(input())
    la=list(map(int,input().split()))
    lb=list(map(int,input().split()))
    lc=list(map(int,input().split()))
    la.sort()
    lb.sort()
    lc.sort()
    ans=0
    for i in lb:
        ans1=bisect.bisect_left(la,i)
        ans2=len(lc)+-bisect.bisect_right(lc,i)
        ans+=ans1*ans2
    print(ans)
resolve()

Solution (Python):

import bisect
def main():
    n=int(input())
    a=list(map(int,input().split()))
    b=list(map(int,input().split()))
    c=list(map(int,input().split()))
    if n==1:
        if a<b and b<c:
            print(1)
        else:
            print(0)
    else:
        a.sort()
        b.sort()
        c.sort()
        aList=[0]*n
        bList=[0]*n
        bListSum=[0]*n
        for i in range(n):
            aList[i]=bisect.bisect_right(b,a[i])
            bList[i]=n-bisect.bisect_right(c,b[i])
        bListSum[n-1]=bList[n-1]
        for i in range(n-2,-1,-1):
            bListSum[i]=bListSum[i+1]+bList[i]
        ans=0
        for i in range(n):
            if aList[i]<n:
                ans+=bListSum[aList[i]]
        print(ans)
if __name__=="__main__":
    main()

Solution (Python):
import bisect
n = int(input())
al = list(map(int,input().split()))
bl = list(map(int,input().split()))
cl = list(map(int,input().split()))

al.sort()
bl.sort()
cl.sort()

cnt = 0
for b in bl:
    a_num = bisect.bisect_left(al,b)
    c_num = n - bisect.bisect_right(cl,b)
    cnt += a_num*c_num
    

print(cnt)

Solution (Python):
import bisect

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()
ans = 0
for b in B:
    a = bisect.bisect_left(A, b)
    c = len(C) - bisect.bisect_right(C, b)
    ans += a * c

print(ans)

Solution (Python):
from bisect import bisect_left, bisect_right

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()
total = 0
for num in b:
    a_pos = bisect_left(a, num)
    c_pos = bisect_right(c, num)
    total += a_pos * (len(c) - c_pos)
print(total)

Solution (Python):

import bisect

N = int(input())
A = sorted([int(j) for j in input().split()])
B = sorted([int(j) for j in input().split()])
C = sorted([int(j) for j in input().split()])
ans = 0
for b in B:
    a_cnt = bisect.bisect_left(A,b)
    c_cnt = N - bisect.bisect_right(C,b)
    ans += a_cnt * c_cnt
print(ans)

Solution (Python):
import bisect

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()
ans = 0
for b in B:
    i = bisect.bisect_left(A, b)
    j = bisect.bisect_right(C, b)
    ans += i*(n-j)
print(ans)

Solution (Python):

import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
from collections import Counter, deque
from collections import defaultdict
from itertools import combinations, permutations, accumulate, groupby, product
from bisect import bisect_left,bisect_right
from heapq import heapify, heappop, heappush
from math import floor, ceil,pi
from operator import itemgetter
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def LI2(): return [int(input()) for i in range(n)]
def MXI(): return [[LI()]for i in range(n)]
def SI(): return input().rstrip()
def printns(x): print('\n'.join(x))
def printni(x): print('\n'.join(list(map(str,x))))
inf = 10**17
mod = 10**9 + 7

n=I()
A=sorted(LI())
B=sorted(LI())
C=sorted(LI())
ans=0
for i in range(n):
    ans+=bisect_left(A,B[i])*(n-bisect_right(C,B[i]))
    
    
print(ans)

Solution (Python):

import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
from collections import Counter, deque
from collections import defaultdict
from itertools import combinations, permutations, accumulate, groupby, product
from bisect import bisect_left,bisect_right
from heapq import heapify, heappop, heappush
from math import floor, ceil,pi
from operator import itemgetter
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def LI2(): return [int(input()) for i in range(n)]
def MXI(): return [[LI()]for i in range(n)]
def SI(): return input().rstrip()
def printns(x): print('\n'.join(x))
def printni(x): print('\n'.join(list(map(str,x))))
inf = 10**17
mod = 10**9 + 7

n=I()
A=sorted(LI())
B=sorted(LI())
C=sorted(LI())
ans=0
for i in range(n):
    ans+=bisect_left(A,B[i])*(n-bisect_right(C,B[i]))
    
    
print(ans)

Solution (Python):
from bisect import bisect_left
from bisect import bisect_right


N = int(input())
A = sorted(map(int, input().split()))
B = sorted(map(int, input().split()))
C = sorted(map(int, input().split()))

ans = 0
y_low = {}
i = 0
for y in B:
    x = bisect_left(A, y)
    z = bisect_right(C, y)
    ans += x * (N-z)
print(ans)

Solution (Python):

"""
Created on Sun May 10 19:10:47 2020

@author: Kanaru Sato
"""
import bisect

n = int(input())
_1 = list(map(int,input().split()))
_2 = list(map(int,input().split()))
_3 = list(map(int,input().split()))

a = sorted(_1)
b = sorted(_2)
c = sorted(_3)

count = 0
for i in range(n):
    smallernums = bisect.bisect_left(a,b[i])
    biggernums = len(c)-bisect.bisect_right(c,b[i])
    count += smallernums*biggernums

print(count)

Solution (Python):
import bisect
import itertools
def find_ge(a, x):
    i = bisect.bisect_right(a,x)
    return i

def solve(n, a, b, c):

    tmp = len(c)
    b_count =list(itertools.accumulate([tmp - find_ge(c, x) for x in b]))
    ans = 0
    for i in a:
        min_index = find_ge(b, i)
        
        ans += b_count[-1] -(0 if min_index == 0 else b_count[min_index-1])
    
    return ans

if __name__ == "__main__":
    n = int(input())
    a = sorted([int(i) for i in input().split()])
    b = sorted([int(i) for i in input().split()])
    c = sorted([int(i) for i in input().split()])
    print(solve(n, a, b, c))

Solution (Python):
import bisect
def I(): return int(input())
def LI(): return list(map(int,input().split()))
n=I()
a=sorted(LI())
b=sorted(LI())
c=sorted(LI())
ans=0
for bd in b:
    oka=bisect.bisect_left(a,bd)
    okc=bisect.bisect_right(c,bd)
    ans+=oka*(n-okc)
print(ans)

Solution (Python):
import bisect

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

cnt = 0


for j in range(n) :
    a = bisect.bisect_left(A,B[j])
    c = bisect.bisect_right(C,B[j])
    cnt += a * (n-c)
    
print(cnt)

Solution (Python):
import bisect

N = int(input())
A = [int(x) for x in input().split()]
B = [int(x) for x in input().split()]
C = [int(x) for x in input().split()]

A.sort()
B.sort()
C.sort()

ans = 0
for j in range(N):
    i = bisect.bisect_left(A, B[j])
    k = bisect.bisect_right(C, B[j])
    ans += i * (N - k)

print(ans)

Solution (Python):
from bisect import bisect_left,bisect_right

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()
ans = 0
cns = 0
for i in B:
    x = bisect_left(A,i)
    y = bisect_right(C,i)
    y = n - y
    ans += x*y
print(ans)

Solution (Python):
import bisect
N = int(input())
A = sorted(list(map(int, input().split()))) 
B = sorted(list(map(int, input().split()))) 
C = sorted(list(map(int, input().split()))) 
print(sum(bisect.bisect_left(A, b)*(N-bisect.bisect_right(C, b)) for b in B))

Solution (Python):
import sys
import bisect
input = sys.stdin.readline
n=int(input())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
c=list(map(int,input().split()))
a.sort()
c.sort()
ans=0
for i in b:
  x=bisect.bisect_left(a,i)
  y=n-bisect.bisect_right(c,i)
  ans+=x*y
print(ans)

Solution (Python):
N = int(input())
A = [int(x) for x in input().split()]
B = [int(x) for x in input().split()]
C = [int(x) for x in input().split()]

A.sort()
B.sort()
C.sort()
B += [10 ** 9 + 1] + [0]    
C += [10 ** 9 + 1] + [0]    





K = [0] * N

for j in range(N):
    ng = -1 
    ok = N  
    while ok - ng > 1:
        mid = (ok + ng) // 2
        if B[j] < C[mid]:
            ok = mid
        else:
            ng = mid
    K[j] = ok




f = [0] * (N - 1) + [N - K[N - 1]]
for j in range(N - 2, -1, -1):
    f[j] = f[j + 1] + N - K[j]

ans = 0
for i in range(N):
    
    ng = -1  
    ok = N   
    while ok - ng > 1:
        mid = (ok + ng) // 2
        if A[i] < B[mid]:
            ok = mid
        else:
            ng = mid
    if ok >= N: continue
    
    ans += f[ok]

print(ans)

Solution (Python):
N = int(input())

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

import bisect

count_B = {}
count_C = {}
count_sum = {}

count = 0
for idx, b in enumerate(reversed(B)):
    count_C[b] = N - bisect.bisect_right(C, b)
    count += count_C[b]
    count_sum[N-idx-1] = count

count = 0
for a in A:
    index = bisect.bisect_right(B, a)
    if index in count_sum:
        count += count_sum[bisect.bisect_right(B, a)]
        
print(count)

Solution (Python):
import bisect


def read_input():
    N = int(input())
    A = [int(x) for x in input().split(" ")]
    B = [int(x) for x in input().split(" ")]
    C = [int(x) for x in input().split(" ")]
    return N, A, B, C


def main():

    N, A, B, C = read_input()
    count = 0
    A.sort()

    C.sort()
    len_c = len(C)
    for b in B:
        l = bisect.bisect_left(A, b)
        r = len_c - bisect.bisect_right(C, b)
        count += l * r

    print(count)


if __name__ == "__main__":
    main()

Solution (Python):
import bisect
n=int(input())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
c=list(map(int,input().split()))
a=sorted(a)
b=sorted(b)
c=sorted(c)

sum=0
for i in range(n):
    bisect_a=bisect.bisect_left(a,b[i])
   
    
    bisect_c=bisect.bisect_right(c,b[i])
   

    sum+=bisect_a*(n-bisect_c)
print(sum)

Solution (Python):
import bisect

N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))
 
A.sort()
C.sort()
 
ans = 0
for i in range(N):
    a = bisect.bisect_left(A, B[i])
    c = bisect.bisect_right(C, B[i])
    ans += a*(N-c)
print(ans)

Solution (Python):
n = int(input())
a = list(sorted(list(map(int,input().split()))))
b = list(sorted(list(map(int,input().split()))))
c = list(sorted(list(map(int,input().split()))))
 
def bs_left(ls,target):
    low, high = 0, len(ls)
    while low < high:
        mid = (low+high) // 2
        if ls[mid] < target:
            low = mid + 1
        else:
            high = mid
    return low
 
def bs_right(ls,target):
    low, high = 0, len(ls)
    while low < high:
        mid = (low+high) // 2
        if target < ls[mid]:
            high = mid
        else:
            low = mid + 1
    return low
 
ans = 0
for i in b:
    ans += (bs_left(a,i)*(n-bs_right(c,i)))
 
print(ans)

Solution (Python):
import bisect

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()

ans = 0
for b in B:
    a = bisect.bisect_left(A, b)
    c = bisect.bisect_right(C, b)
    ans += a*(N-c)

print(ans)

Solution (Python):
import bisect
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()
BoverA = [0] * N
CoverB = [0] * N
for i in range(N):
    BoverA[i] = N - bisect.bisect_right(B, A[i])
    CoverB[i] = N - bisect.bisect_right(C, B[i])
cumBC = [0] * N
cumBC[N-1] = CoverB[N-1]
for i in range(N-2, -1, -1):
    cumBC[i] = cumBC[i+1] + CoverB[i]
ans = 0
for i in range(N):
    if N - BoverA[i] >= 0 and N - BoverA[i] < N:
        ans += cumBC[N - BoverA[i]]
print(ans)

Solution (Python):
from bisect import bisect_left,bisect_right
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()
ans=0
for i in range(n):
    A=bisect_left(a,b[i])
    C=n-bisect_right(c,b[i])
    ans+=A*C
print(ans)

Solution (Python):
n = int(input())
a = list(sorted(list(map(int,input().split()))))
b = list(sorted(list(map(int,input().split()))))
c = list(sorted(list(map(int,input().split()))))

def bs_left(ls,target):
    low, high = 0, len(ls)
    while low < high:
        mid = (low+high) // 2
        if ls[mid] < target:
            low = mid + 1
        else:
            high = mid
    return low

def bs_right(ls,target):
    low, high = 0, len(ls)
    while low < high:
        mid = (low+high) // 2
        if target < ls[mid]:
            high = mid
        else:
            low = mid + 1
    return low

ans = 0
for i in b:
    ans += (bs_left(a,i)*(n-bs_right(c,i)))

print(ans)

Solution (Python):
import bisect
n=int(input())
a=sorted(list(map(int,input().split())))
b=sorted(list(map(int,input().split())))
c=sorted(list(map(int,input().split())))
cnt=0
for i in range(n):
  A = bisect.bisect_left(a, b[i])
  C = n-bisect.bisect_right(c, b[i])
  cnt+=A*C
print(cnt)

Solution (Python):
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
import numpy as np

n = int(readline())
a = np.array(readline().split(), dtype=np.int32)
b = np.array(readline().split(), dtype=np.int32)
c = -np.array(readline().split(), dtype=np.int32)

a.sort()
b.sort()
c.sort()

cnt_a=np.searchsorted(a,b)
cnt_c=np.searchsorted(c,-b)
print((cnt_a*cnt_c).sum())

Solution (Python):
n=int(input())
a=sorted(list(map(int,input().split())))
b=sorted(list(map(int,input().split())))
c=sorted(list(map(int,input().split())))


 
  
  
  

cnt=0

for i in range(n):
  B=b[i]
  if B<=a[0] or B>=c[-1]:
    continue
  
  i_small=0
  i_large=n-1
  while i_large-i_small>1:
    if a[(i_small+i_large)//2] <B:
      i_small=(i_small+i_large)//2
    else:
      i_large=(i_small+i_large)//2
 
  A=i_large
  if a[-1]<B:
    A+=1

  
  i_small=0
  i_large=n-1
  while i_large-i_small>1:
    if c[(i_small+i_large)//2] >B:
      i_large=(i_small+i_large)//2
    else:
      i_small=(i_small+i_large)//2
  C=n-i_large
  if c[0]>B:
    C+=1

  cnt+=A*C
if n>1:
  print(cnt)
else:
  if a[0]<b[0]<c[0]:
    print(1)
  else:
    print(0)

Solution (Python):
def main():
    from bisect import bisect_left, bisect_right
    n, *abc = map(int, open(0).read().split())
    a, b, c = abc[:n], abc[n:2 * n], abc[2 * n:]
    a, b, c = sorted(a), sorted(b), sorted(c)
    ans = 0
    for i in b:
        j = bisect_left(a, i)
        k = n - bisect_right(c, i)
        ans += j * k

    print(ans)


if __name__ == '__main__':
    main()

Solution (Python):
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()
ans=0
for i in range(n):
  middle=b[i]
  h=n
  l=-1
  while h-l>1:
    m=(h+l)//2
    if a[m]<middle:
      l=m
    else:
      h=m
  ab=l+1
  h=n
  l=-1
  while h-l>1:
    m=(h+l)//2
    if c[m]>middle:
      h=m
    else:
      l=m
  bc=n-h
  ans+=ab*bc
print(ans)

Solution (Python):
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()
AtoB=[0 for i in range(n)]
BtoC=[0 for i in range(n+1)]
for i in range(n):
  top=a[i]
  h=n
  l=-1
  while h-l>1:
    mid=(h+l)//2
    if b[mid]>top:
      h=mid
    else:
      l=mid
  if h==0 and top>b[0]:
    h=-1
  AtoB[i]=h 
for i in range(n-1,-1,-1):
  top=b[i]
  h=n
  l=-1
  while h-l>1:
    mid=(h+l)//2
    if c[mid]>top:
      h=mid
    else:
      l=mid
  BtoC[i]+=BtoC[i+1]+n-h 
ans=0
for i in range(n):
  ans+=BtoC[AtoB[i]]
print(ans)

Solution (Python):
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()
ans = 0
def low_func(array, value):
  ng = -1
  ok = len(array)
  
  while ok - ng > 1:
    mid = (ok + ng)//2
    if array[mid] < value:
      ng = mid
    elif array[mid] >= value:
      ok = mid
  return ok

def up_func(array, value):
  ok = -1
  ng = len(array)
  
  while abs(ok - ng) > 1:
    mid = (ok + ng)//2
    if array[mid] <= value:
      ok = mid
    elif array[mid] > value:
      ng = mid
  return ok

for b in B:
  a_idx = up_func(A, b - 1)
  if a_idx == -1:
    continue
  c_idx = low_func(C, b + 1)
  if c_idx == len(C):
    break
  ans += (a_idx + 1)*(len(C) - c_idx)
print(ans)

Solution (Python):
import numpy as np
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

n = int(readline())
a = np.array(readline().split(), dtype=np.int32)
b = np.array(readline().split(), dtype=np.int32)
c = - np.array(readline().split(), dtype=np.int32)

a.sort()
b.sort()
c.sort()

cnt_a = np.searchsorted(a, b, side='left')
cnt_c = np.searchsorted(c, -b, side='left')
 
answer = (cnt_a * cnt_c).sum()
print(answer)

Solution (Python):
import bisect
N=int(input())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
C = list(map(int,input().split()))
A.sort()
C.sort()
d=0
for i in B:
 d+=bisect.bisect_right(A,i-0.1)*(N-bisect.bisect_left(C,i+0.1))
print(d)

Solution (Python):
import bisect
N=int(input())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
C = list(map(int,input().split()))
A.sort()
C.sort()
d=0
for i in B:
 d+=bisect.bisect_right(A,i-0.1)*(N-bisect.bisect_left(C,i+0.1))
print(d)

Solution (Python):
import bisect

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()


result = 0
for i in range(n):
    b_bisect_in_a = bisect.bisect_left(a, b[i])
    b_bisect_in_c = bisect.bisect_right(c, b[i])
    result += b_bisect_in_a * (n - b_bisect_in_c)
        
        
print(result)

Solution (Python):
from bisect import bisect_right, bisect_left


n = int(input())
a = sorted(map(int, input().split()))
b = sorted(map(int, input().split()))
c = sorted(map(int, input().split()))
print(sum(bisect_left(a, i) * (n - bisect_right(c, i)) for i in b))

Solution (Python):
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
import numpy as np

def abc077_c():
    ''' maspyさんお手本 '''
    N = int(readline())
    A = np.array(readline().split(), dtype=np.int64)
    B = np.array(readline().split(), dtype=np.int64)
    C = np.array(readline().split(), dtype=np.int64)

    A.sort()
    B.sort()
    C.sort()

    
    cnt_A = np.searchsorted(A, B, side='left')
    
    cnt_C_not = np.searchsorted(C, B, side='right')
    
    cnt_C = N - cnt_C_not
    
    

    ans = np.multiply(cnt_A, cnt_C).sum()
    print(ans)

abc077_c()

Solution (Python):
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

def abc077_c():
    N = int(readline())
    A = list(map(int, readline().split()))
    B = list(map(int, readline().split()))
    C = list(map(int, readline().split()))
    A.sort()
    B.sort()
    C.sort()
    ans = 0

    from bisect import bisect_left

    
    B2C = [0] * N
    
    for j in range(N):
        B2C[j] = N - bisect_left(C, B[j]+1)
    
    accum = [0]
    for j in range(N):
        accum.append(accum[-1] + B2C[j])

    
    for i in range(N):
        jst = bisect_left(B, A[i]+1)
        if jst == N: continue
        
        ans += accum[N] - accum[jst]
    print(ans)

abc077_c()

Solution (Python):
import math
def main():
  from builtins import input, int, map
  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()
  n = int(math.log(N,2))+1

  ans = 0

  for i in range(N):
    if A[0] >= B[i]:
      continue
    if A[N-1] < B[i]:
      a = N
    else:
      left = 0
      right = N-1
      for _ in range(n):
        if right - left <= 1:
          break
        mid = (left + right) // 2
        if  B[i]> A[mid]:
          left = mid
        else:
          right = mid
      a = left + 1
    if C[N-1] <= B[i]:
      continue
    if C[0] > B[i]:
      c = N
    else:      
      left = 0
      right = N-1
      for _ in range(n):
        if right - left <= 1:
          break
        mid = (left + right) // 2
        if B[i]>= C[mid]:
          left = mid
        else:
          right = mid
      c = N - right
    ans += a*c
  print(ans)
main()

Solution (Python):
import bisect as bi
def main():
  from builtins import input, int, map
  N = int(input())
  A = list(map(int,input().split()))
  B = list(map(int,input().split()))
  C = list(map(int,input().split()))
  A.sort()
  C.sort()

  ans = 0

  for i in range(N):
    a = bi.bisect_left(A,B[i])
    c = N-bi.bisect_right(C,B[i])
    ans += a*c
  print(ans)
main()

Solution (Python):
import numpy as np
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

n = int(readline())
a = np.array(readline().split(), dtype=np.int32)
b = np.array(readline().split(), dtype=np.int32)
c = - np.array(readline().split(), dtype=np.int32)

a.sort()
b.sort()
c.sort()

cnt_a = np.searchsorted(a, b, side='left')
cnt_c = np.searchsorted(c, -b, side='left')
 
answer = (cnt_a * cnt_c).sum()
print(answer)

Solution (Python):
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()
i=0
k=0
ans=0
acnt=0
ccnt=n
for x in b:
    aok=True
    cng=True
    while aok:
        if acnt == n:
            break
        if a[i]<x:
            i+=1
            acnt+=1
        else:
            aok=False
    while cng:
        if ccnt == 0:
            break
        if c[k]<=x:
            k+=1
            ccnt-=1
        else:
            cng=False
    ans+=acnt*ccnt
    
print(ans)

Solution (Python):
import bisect
N = int(input())
A = sorted([int(i) for i in input().split()])
B = [int(i) for i in input().split()]
C = sorted([int(i) for i in input().split()])


ans = 0
for b in B:
    ans += bisect.bisect_left(A, b) * (N-bisect.bisect_right(C, b))
print(ans)

Solution (Python):
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()

import bisect
ans=0
for i in b:
    q=bisect.bisect_left(a,i)
    s=bisect.bisect_right(c,i)
    ans=ans+q*(n-s)
print(ans)