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=sorted(list(map(int,input().split())))
b=sorted(list(map(int,input().split())))
c=sorted(list(map(int,input().split())))

import bisect

ans=0
for i in range(n):
    num_a=bisect.bisect_left(a,b[i])
    idx_c=bisect.bisect_right(c,b[i])
    num_c=n-idx_c
    ans+=num_a*num_c
print(ans)

Solution (Python):
from bisect import *
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()
res = 0
for i in b:
    temp_a = bisect_left(a, i)
    temp_c = n - bisect_right(c, i)
    res += temp_a*temp_c
print(res)

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

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

A.append(10**10)
B.append(10**10)
C.append(10**10)

btab=[0 for i in range(n)]

idx=0
for i in range(n):
    while A[idx] < B[i]:
        idx+=1
    btab[i]=idx

idx=0
sow=0
ans=0
for i in range(n):
    while B[idx] < C[i]:
        sow+=btab[idx]
        idx+=1
    ans+=sow

print(ans)

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

sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline
f_inf = float('inf')
mod = 10 ** 9 + 7


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

    res = 0
    for i in range(n):
        u = bisect_left(A, B[i])
        d = bisect_right(C, B[i])
        res += u * (n - d)
    print(res)


if __name__ == '__main__':
    resolve()

Solution (Python):
from bisect import bisect_left, 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
for b in B:
    a_upperbound = bisect_left(A, b)
    c_lowerbound = bisect_right(C, b)
    ans += a_upperbound * (N - c_lowerbound)
print(ans)

Solution (Python):
from bisect import bisect_right as br

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
Bc=[]
for i in range(N):
    Bc.append(N-br(C,B[i]))

S=[sum(Bc)]
for j in range(N):
    S.append(S[j]-Bc[j])

for a in A:
    b=br(B,a)
    ans+=S[b]
print(ans)

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()
ab = [0 for i in range(n)]
ans = 0

for i in range(n):
  ab[i] = ab[i-1] + bisect.bisect_left(a, b[i])
for i in range(n):
  tmp = bisect.bisect_left(b, c[i])
  if tmp != 0:
  	ans += ab[tmp-1] 

print(ans)

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()
ab = [0 for i in range(n)]
ans = 0

for i in range(n):
  ab[i] = ab[i-1] + bisect.bisect_left(a, b[i])
for i in range(n):
  tmp = bisect.bisect_left(b, c[i])
  if tmp != 0:
  	ans += ab[tmp-1] 

print(ans)

Solution (Python):
def check(arr, mid, maxV):
    if arr[mid] < maxV:
        return True
    else:
        return False


def binSearch(arr, maxV):
    ok = -1
    ng = len(arr)
    while abs(ok - ng) > 1:
        mid = (ok + ng) // 2
        if check(arr, mid, maxV):
            ok = mid
        else:
            ng = mid
    return ok


def resolve():
    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()])
    BoverA = [0 for _ in range(N)]
    sumA = 0
    for i in range(N):
        a = binSearch(A, B[i])
        sumA += (a + 1)
        BoverA[i] = sumA
    sumA = 0
    for i in range(N):
        b = binSearch(B, C[i])
        if b >= 0:
            sumA += 1 * 1 * BoverA[b]
    print(sumA)


resolve()

Solution (Python):
import bisect

N= int(input())
a = map(int, input().split(" "))
b = map(int, input().split(" "))
c = map(int, input().split(" "))

a = sorted(a)
b = sorted(b)
c = sorted(c)

result = 0
for i in b:
    ta = bisect.bisect_left(a,i)
    tc = bisect.bisect_right(c,i)
    result += ta*(N-tc)
print(result)

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())))
ans=0
for i in b:
    x=bisect.bisect_left(a,i)
    y=bisect.bisect_right(c,i)
    ans+=x*(n-y)
print(ans)

Solution (Python):
import bisect
from itertools import accumulate
n = int(input())
A = sorted(map(int,input().split()))
B = sorted(map(int,input().split()))
C = sorted(map(int,input().split()))
D = [0]*(n+1)
for i in range(n):
    D[i+1] = n-bisect.bisect_right(C,B[i])
D = tuple(accumulate(D))
ans = 0
for i in range(n):
    j = bisect.bisect_right(B,A[i])
    ans += D[-1]-D[j]
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()))
lenc = len(c)
a.sort()
c.sort()
ans = 0
for i in b:
	atmp = bisect.bisect_left(a, i)
	ctmp = lenc - bisect.bisect_right(c, i)
	ans += atmp * ctmp
print(ans)

Solution (Python):
from bisect import bisect_right,bisect_left
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:ans+=bisect_left(a,i)*(n-bisect_right(c,i))
print(ans)

Solution (Python):
def Binary_Search(A,x):
    L=0
    R=len(A)
    while R-L>1:
        C=(R+L-1)//2
        
        if A[C]<=x:
            L=C+1
        else:
            R=C+1
    return L
        
N=int(input())
A=list(map(int,input().split()))
B=list(map(int,input().split()))
C=list(map(int,input().split()))

A.sort()
A.append(A[-1]+1)
B.sort()
C.sort()
C=[0]+C
C=[-c for c in C[::-1]]

S=0
for b in B:
    S+=Binary_Search(A,b-1)*Binary_Search(C,-(b+1))
print(S)

Solution (Python):
from bisect import bisect_right, bisect_left

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

A.sort()
C.sort()
ans = 0

for i in B:
    a = bisect_left(A, i)
    b = N-bisect_right(C, i)
    ans += (a*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()))

import bisect
a.sort()
b.sort()
c.sort(reverse=True)
c = [-x for x in c]

ans = 0
for x in b:
    ans += bisect.bisect_left(a, x) * (bisect.bisect_left(c, -x))

print(ans)

Solution (Python):
import bisect

n = int(input())
A = sorted(map(int, input().split()))
B = sorted(map(int, input().split()))
C = sorted(map(int, input().split()))
ans = 0
L = [0] * n
for i in range(n):
    a = bisect.bisect_left(A, B[i])
    L[i] = a
cum = [0] * (n + 1)
for i in range(n):
    cum[i+1] = cum[i] + L[i]
for i in range(n):
    b = bisect.bisect_left(B, C[i])
    ans += cum[b]
print(ans)

Solution (Python):
import bisect

def main():
    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 b in B:
        indexa = bisect.bisect_left(A, b)
        indexc = bisect.bisect_right(C, b)
        ans += indexa * (N - indexc)
    print(ans)

if __name__ == '__main__':
    main()

Solution (Python):
import bisect

def main():
    N = int(input())
    A = sorted(list(map(int, input().split())))
    B = sorted(list(map(int, input().split())))
    C = sorted(list(map(int, input().split())))
    
    
    
    
    B1 = [0]*N
    for i in range(N):
        b = B[i]
        B1[i] = N - bisect.bisect_right(C, b)
        if i != 0:
            B1[i] += B1[i - 1]
    A1 = [0]*N
    for i in range(N):
        a = A[i]
        index = bisect.bisect_right(B, a)
        if index == 0:
            A1[i] = B1[-1]
        elif index < N:
            A1[i] = B1[-1] - B1[index - 1]
    ans = sum(A1)
    
    print(ans)

if __name__ == '__main__':
    main()

Solution (Python):
import sys
from bisect import bisect_left

input = sys.stdin.buffer.readline
N = int(input())
A = sorted(list(map(int, input().split())))
B = sorted(list(map(int, input().split())))
C = sorted(list(map(int, input().split())))

cumsum = [0]
for i in range(len(B)):
    b = B[i]
    a_idx = bisect_left(A, b)
    cumsum.append(cumsum[i] + a_idx)


ans = 0
for i in range(len(C)):
    c = C[i]
    b_idx = bisect_left(B, c)
    ans += cumsum[b_idx]
print(ans)

Solution (Python):
from bisect import bisect_left

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

AB = [0]*N
sAB = [0]*N
rlt = 0

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

for i in range(N):
  AB[i] = bisect_left(A, B[i])

sAB[0] = AB[0]
for i in range(N-1):
  sAB[i+1] = sAB[i] + AB[i+1]

for i in range(N):
  j = bisect_left(B, C[i])
  if j == 0:
    continue
  else:
    rlt += sAB[j-1]
  
print(rlt)

Solution (Python):
n=int(input())
from bisect import bisect_left as bl,bisect_right as br
a,b,c=[list(map(int,input().split())) for i in range(3)]
a.sort()
c.sort()
print(sum(bl(a,i)*(n-br(c,i))for i in b))

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()
from bisect import bisect_left
from bisect import bisect_right
count = 0
for bi in range(n):
  c_right = bisect_right(c, b[bi])
  a_left = bisect_left(a, b[bi])
  count += (n-c_right) * a_left
print(count)

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


Bnum=[]
a=0
for i in range(n):
    while a!=n and B[i]>A[a] :
        a+=1
    Bnum.append(a)

Cnum=[]
b=0
s=0
for i in range(n):
    while b!=n and C[i]>B[b]:
        s+=Bnum[b]
        b+=1
    Cnum.append(s)

print(sum(Cnum))

Solution (Python):
from bisect import bisect_right, bisect_left

N = int(input())

As = sorted(list(map(int, input().split())))
Bs = sorted(list(map(int, input().split())))
Cs = sorted(list(map(int, input().split())))

ans = 0

for B in Bs:
    A_idx = bisect_left(As, B)
    C_idx = bisect_right(Cs, B)
    ans += A_idx * (N - C_idx)

print(ans)

Solution (Python):
n = int(input())
a_list = list(map(int, input().split()))
b_list = list(map(int, input().split()))
c_list = list(map(int, input().split()))

a_list.sort()
b_list.sort()
c_list.sort()
n_b = []
current = 0
for i in range(n):
    a = a_list[i]
    while current <= n-1 and b_list[current] <= a:
        current += 1
    n_b.append(n-current)
n_c = []
current = 0
for i in range(n):
    b = b_list[i]
    while current <= n-1 and c_list[current] <= b:
        current += 1
    n_c.append(n-current)
cum_nc = [0]*n
cum_nc[0] = n_c[n-1]
for i in range(1, n):
    cum_nc[i] = cum_nc[i-1] + n_c[n-1-i]
ans = 0

for i in n_b:
    if i > 0:
        ans += cum_nc[i-1]
print(ans)

Solution (Python):
import bisect

n, *lst = map(int, open(0).read().split())
alst = sorted(lst[:n])
blst = lst[n:2*n]
clst = sorted(lst[2*n:])
res = 0
for i in blst:
  a = bisect.bisect_left(alst, i)
  c = n - bisect.bisect_right(clst, i)
  res += a * c
print(res)

Solution (Python):
import bisect

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

ans=0

for i in range(n):
    num1 = bisect.bisect_left(a,b[i])
    num2 = n - bisect.bisect(c,b[i])
    ans += num1*num2

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

li = []
i = 0
for bb in b:
    while i<n and a[i]<bb:
        i += 1
    li.append(i)
li2 = [0]
accu = 0
for i in li:
    accu += i
    li2.append(accu)
ans = 0
i = 0
for cc in c:
    while i<n and b[i]<cc:
        i += 1
    ans += li2[i]
print(ans)

Solution (Python):
import sys

def IS(): return sys.stdin.readline().rstrip()
def II(): return int(IS())
def MII(): return list(map(int, IS().split()))
from bisect import bisect_left, bisect_right

def main():
    n = II()
    aa = MII(); bb = MII(); cc = MII()
    aa.sort();  bb.sort();  cc.sort()
    cnt = 0
    for b in bb:
        a = bisect_left(aa, b)
        c = bisect_right(cc, b)
        cnt += (a)*(n-c)
    print(cnt)



if __name__ == '__main__':
    main()

Solution (Python):
import sys
import bisect

readline = sys.stdin.readline

def main():
    N = int(readline())
    A = list(map(int, readline().split()))
    B = list(map(int, readline().split()))
    C = list(map(int, readline().split()))

    A.sort()
    C.sort()

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


if __name__ == "__main__":
    main()

Solution (Python):

printn = lambda x: print(x,end='')
inn = lambda : int(input())
inl   = lambda: list(map(int, input().split()))
inm   = lambda:      map(int, input().split())
ins = lambda : input().strip()
DBG = True 
BIG = 10**18
R = 10**9 + 7

def ddprint(x):
  if DBG:
    print(x)

import bisect
n = inn()
a = inl()
a.sort()
a.append(10**9+1)
b = inl()
b.sort()
b.append(10**9+1)
c = inl()
c.sort()
c.append(10**9+1)
sm = 0
for i in range(n):
    p = bisect.bisect_left(a,b[i])
    q = bisect.bisect_right(c,b[i])
    sm += p*(n-q)
print(sm)

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())))
result = 0
for b in B:
    
    result += bisect.bisect_right(A, b - 1) * (N-bisect.bisect_left(C, b + 1))
print(result)

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

a = sorted(a)
c = sorted(c)

rec = 0
for i in range(n):
    temp = b[i]
    l = bisect_left(a, temp)
    r = bisect_right(c, temp)
    rec += l * (n - r)
print(rec)

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()))
B_ans = [0]*N
A.sort()
B.sort()
C.sort()
ans = 0

for i, b in enumerate(B):
    bi = bisect.bisect_left(A, b)
    B_ans[i] = B_ans[i-1] + bi
for j, c in enumerate(C):
    ci = bisect.bisect_left(B, c)
    if ci == 0:
        continue

    ans += B_ans[ci-1]
print(ans)

Solution (Python):
from bisect import bisect_right, bisect_left
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 b in B:
    a_id = bisect_left(A, b)
    c_id = bisect_right(C, b)
    ans += a_id * (len(C) - c_id)

print(ans)

Solution (Python):
import bisect


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

s = [0] * (N + 1)
for i, bi in enumerate(B):
    s[i + 1] = s[i] + N - bisect.bisect_right(C, bi)

print(sum(s[N] - s[bisect.bisect_right(B, ai)] for ai in A))

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

Solution (Python):
import sys

stdin = sys.stdin
inf = 1 << 60
mod = 1000000007

sys.setrecursionlimit(10 ** 7)

ni      = lambda: int(ns())
nin     = lambda y: [ni() for _ in range(y)]
na      = lambda: list(map(int, stdin.readline().split()))
nan     = lambda y: [na() for _ in range(y)]
nf      = lambda: float(ns())
nfn     = lambda y: [nf() for _ in range(y)]
nfa     = lambda: list(map(float, stdin.readline().split()))
nfan    = lambda y: [nfa() for _ in range(y)]
ns      = lambda: stdin.readline().rstrip()
nsn     = lambda y: [ns() for _ in range(y)]
ncl     = lambda y: [list(ns()) for _ in range(y)]
nas     = lambda: stdin.readline().split()

from bisect import *

n = ni()
a = na()
b = na()
c = na()
a.sort()
c.sort()

ans = 0
for j in range(n):
    ap = bisect_left(a, b[j])
    cp = bisect_right(c, b[j])
    ans += ap * (n - cp)

print(ans)

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

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

    
    
    res = [0]*(n)
    j = 0
    res2=[0]*(n)
    for i in range(n):
        res[i]=bisect.bisect_left(A, B[i])
        res2[i]=n-bisect.bisect_right(C, B[i])

    ans = 0

    for i in range(n):
        ans+=(res[i]*res2[i])
    return ans
if __name__ == '__main__':
    print(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.sort()
B.sort()
C.sort()

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

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
tmp1 = [n]*n
tmp2 = [n]*n
for i in range(n):
    j = bisect.bisect_left(al, bl[i])
    tmp1[i] = j
for i in range(n):
    j = bisect.bisect_right(cl, bl[i])
    tmp2[i] = n-j
for i in range(n):
    ans += tmp1[i]*tmp2[i]
print(ans)

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

Solution (Python):
from bisect import bisect_left,bisect_right
n=int(input())
A=sorted(list(map(int,input().split())))
B=sorted(list(map(int,input().split())))
C=sorted(list(map(int,input().split())))

ans=0
for i in B:
    ans +=bisect_left(A,i)*(n-bisect_right(C,i))
print(ans)

Solution (Python):
from bisect import bisect_left,bisect_right
n=int(input())
A=sorted(list(map(int,input().split())))
B=sorted(list(map(int,input().split())))
C=sorted(list(map(int,input().split())))

ans=0
for i in B:
    ans +=bisect_left(A,i)*(n-bisect_right(C,i))
print(ans)

Solution (Python):
def main(n,a,b,c):
  import bisect
  ans=0
  for i in range(n):
    na=bisect.bisect_left(a,b[i])
    nc=n-bisect.bisect_right(c,b[i])
    ans+=na*nc
  print(ans)
if __name__=='__main__':
  n=int(input())
  a=sorted(list(map(int,input().split())))
  b=sorted(list(map(int,input().split())))
  c=sorted(list(map(int,input().split())))
  main(n,a,b,c)

Solution (Python):


import numpy as np



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


def main():
    a = np.array(sorted(A))
    b = np.array(sorted(B))
    c = np.array(sorted(C))
    
    w = [None] * N
    for i in range(N):
        w[i] = N - np.searchsorted(c, b[i], side="right")
    
    wsum = [0] * (N + 1)
    for i in range(N - 1, -1, -1):
        wsum[i] = w[i] + wsum[i + 1]
    
    ans = 0
    for i in range(N):
        ans += wsum[np.searchsorted(b, a[i], side="right")]
    print(ans)


if __name__ == "__main__":
    main()

Solution (Python):
import sys
import bisect

readline = sys.stdin.readline
bileft = bisect.bisect_left
biright = bisect.bisect_right

def main():
    N = int(readline())
    A = list(map(int, readline().split()))
    B = list(map(int, readline().split()))
    C = list(map(int, readline().split()))
    A.sort(); C.sort()
    minA = min(A); maxA = max(A)
    minC = min(C); maxC = max(C)
    ans = 0
    for b in B:
        L = minA; R = maxA + 1
        mid = (L + R) // 2
        if b >= R:
            L = R
        else:
            while L + 1 < R:
                if mid <= b:
                    L = mid
                else:
                    R = mid
                mid = (L + R) // 2
        
        a = bileft(A, L)
        

        L = minC; R = maxC + 1
        mid = (L + R) // 2
        if b <= L-1:
            L = L-1
        else:
            while L + 1 < R:
                if mid <= b:
                    L = mid
                else:
                    R = mid
                mid = (L + R) // 2   
        
        c = len(C) - biright(C, L)
        
        

        ans += a*c

    print(ans)

if __name__ == "__main__":
    main()

Solution (Python):
from bisect import *
N = int(input())
A = sorted(list(map(int,input().split())))
B = sorted(list(map(int,input().split())))
C = sorted(list(map(int,input().split())))

count = 0

for i in range(N):
  a = bisect_left(A, B[i])
  c = bisect(C, B[i])
  c = N - c
  count += (a*c)

print(count)

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())))
ma=0
cntb=[0]*n
for i in range(n):
    if i>0:
        cntb[i]=cntb[i-1]
    while ma<n:
        if a[ma]<b[i]:
            cntb[i]+=1
            ma+=1
        else:
            break
mb=0
cntc=[0]*n
for i in range(n):
    if i>0:
        cntc[i]=cntc[i-1]
    while mb<n:
        if b[mb]<c[i]:
            cntc[i]+=cntb[mb]
            mb+=1
        else:
            break
print(sum(cntc))

Solution (Python):
import bisect

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

Solution (Python):
N = int(input())
A = [0]+list(map(int,input().split()))
A.sort()
B = [0]+list(map(int,input().split()))
B.sort()
C = [0]+list(map(int,input().split()))
C.sort()

bko = [0 for i in range(N+1)]
cnt = 1
for i in range(1,N+1):
  b = B[i]
  for j in range(cnt,N+1):
    if A[j] >= b:
      bko[i] = j-1
      cnt = j
      break
    if j == N:
      bko[i] = N
      cnt = N


for i in range(N):     
  bko[i+1] += bko[i]

cko = [0 for i in range(N+1)]
cnt = 1
for i in range(1,N+1):
  c = C[i]
  for j in range(cnt,N+1):
    if B[j] >= c:
      cko[i] = bko[j-1]
      cnt = j
      break
    if j == N:
      cko[i] = bko[N]
      cnt = N

print(sum(cko))

Solution (Python):
import sys
import math  
import bisect  
import queue  


def input():
    return sys.stdin.readline().rstrip()


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

    cntB = [0 for _ in range(N)]
    for i, b in enumerate(B):
        cntB[i] = N - bisect.bisect_right(C, b)

    cumsumB = [0 for _ in range(N)]
    cumsumB[-1] = cntB[-1]
    for i in range(N - 2, -1, -1):
        cumsumB[i] = cumsumB[i + 1] + cntB[i]

    res = 0
    for i, a in enumerate(A):
        idx = bisect.bisect_right(B, a)
        if idx < N:
            res += cumsumB[idx]

    print(res)


if __name__ == '__main__':
    main()

Solution (Python):
import sys
sys.setrecursionlimit(10**6)
from math import floor,ceil,sqrt,factorial,log
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict,deque
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from copy import deepcopy
from operator import itemgetter
from fractions import gcd
mod = 10 ** 9 + 7
inf = float('inf')
ninf = -float('inf')
 

def ii(): return int(sys.stdin.readline().rstrip()) 
def mii(): return map(int,sys.stdin.readline().rstrip().split())
def limii(): return list(mii()) 
def lin(n:int): return [ii() for _ in range(n)]
def llint(n: int): return [limii() for _ in range(n)]

def ss(): return sys.stdin.readline().rstrip() 
def mss(): return sys.stdin.readline().rstrip().split()
def limss(): return list(mss()) 
def lst(n:int): return [ss() for _ in range(n)]
def llstr(n: int): return [limss() for _ in range(n)]





n=ii()

aarr=sorted(limii())
barr=sorted(limii())
carr=sorted(limii())

ans=0

for i in range(n):
    temp1=bisect_left(aarr,barr[i])
    temp2=n-bisect_right(carr,barr[i])
    
    if temp1>0 and temp2>0:
        ans+=temp1*temp2
print(ans)

Solution (Python):
def main():
    N = int(input())
    *a, = map(int, input().split())
    *b, = map(int, input().split())
    *c, = map(int, input().split())

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

    ans = 0
    ai = 0  
    ci = 0  
    for mid in b:
        while ai < N and a[ai] < mid:
            ai += 1

        while ci < N and c[ci] <= mid:
            ci += 1

        ans += ai * (N - ci)

    print(ans)


if __name__ == '__main__':
    main()

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

cnt = 0
for j in range(n):
	idx_i = bisect_left(A, B[j])
	idx_k = bisect_right(C, B[j])
	cnt += idx_i * (n - idx_k)

print(cnt)

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

al = sorted(al)
bl = sorted(bl)
cl = sorted(cl)

import bisect
bl_ac = []
for b in bl:
    idx = bisect.bisect_right(cl, b)
    bl_ac.append(n-idx)
import itertools
bl_ac = [0] + list(itertools.accumulate(bl_ac[::-1]))
bl_ac = bl_ac
ans = 0
for a in al:
    idx = bisect.bisect_right(bl, a)
    ans += bl_ac[n-idx]

print(ans)

Solution (Python):
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush,heapify
import sys,bisect,math,itertools,fractions,pprint
sys.setrecursionlimit(10**8)
mod = 10**9+7
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))

n = inp()
a = inpl()
b = inpl()
c = inpl()
a.sort()
b.sort()
c.sort()
lb = [0] * n
res = 0
for i in range(n):
    tmp = bisect.bisect_right(b,a[i])
    if tmp == n: continue
    lb[tmp] += 1
llb = list(itertools.accumulate(lb))

rr = [0] * n
for i in range(n):
    tmp = bisect.bisect_right(c,b[i])
    if tmp == n: continue
    rr[tmp] += llb[i]
print(sum(list(itertools.accumulate(rr))))

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 = n ** 3
up = [0] * n
mid = [0] * n
bottom = [0] * n

p = 0
for i in range(n):
    while p < n and A[i] >= B[p]:
        p += 1
    mid[i] = p

p = 0
q = 0
for i in range(n):
    while p < n and B[i] >= C[p]:
        p += 1
    while q < n and B[i] > A[q]:
        q += 1
    bottom[i] = p
    up[i] = q

for m in mid:
    ans -= m * n

for u, b in zip(up, bottom):
    ans -= u * 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()
ans = 0
for j in range(n):
    bind = j
    top = n
    bot = -1
    while top-bot > 1:
        mid = (top+bot)//2
        if b[bind] > a[mid]:bot = mid
        else:top = mid
    
    aind = bot
    l = -1
    r = n
   
    while r-l> 1:
   
        cen = (l+r)//2
        if b[bind] < c[cen]:r = cen
        else:l = cen
    cind = r
    ans +=(aind+1)*(n-cind)
    
print(ans)

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

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

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

ba=0
bc=N
ans=0
for i in range(N):
    b=B[i]
    if ba!=N:
        while A[ba]<b:
            ba+=1
            if ba==N:
                break
    if bc!=0:
        while C[N-bc]<=b:
            bc-=1
            if bc==0:
                break
    ans+=ba*(bc)
    
print(ans)

Solution (Python):
import bisect
n = int(input())
a = [int(i) for i in input().split()]
a = sorted(a)
b = [int(i) for i in input().split()]
b = sorted(b)
c = [int(i) for i in input().split()]
c = sorted(c)
ans = 0
for i in range(n):
    B = b[i]
    a_nums = bisect.bisect_left(a,B)
    c_nums = n - bisect.bisect_right(c,B)
    ans += a_nums * c_nums
print(ans)

Solution (Python):
from bisect import bisect_right
from itertools import accumulate

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

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




Bcnt = [0] * N
for i,b in enumerate(B):
    r = bisect_right(C, b)
    Bcnt[i] = N - r
 
Bcnt = [0] + list(accumulate(Bcnt))
 
Acnt = [0] * N
for i,a in enumerate(A):
    r = bisect_right(B, a)
    Acnt[i] = Bcnt[N] - Bcnt[r]

print(sum(Acnt))

Solution (Python):
import bisect
N = int(input())
A = []
for _ in range(3):
  a = list(map(int, input().split()))
  a.sort()
  A.append(a)
  
ans = 0
for b in A[1]:
  a = bisect.bisect_left(A[0], b)
  c = bisect.bisect_right(A[2], b)
  ans += a * (N-c)
print(ans)