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):
from sys import stdin
from bisect import bisect_right, bisect_left


def input():
    return stdin.readline().strip()


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()
    C.sort()

    ans = sum(bisect_left(A, b) * (N - bisect_right(C, b)) for b in B)
    print(ans)


if __name__ == "__main__":
    main()

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


def input():
    return stdin.readline().strip()


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 = sum(bisect_left(A, b) * (N - bisect_right(C, b)) for b in B)
    print(ans)


if __name__ == "__main__":
    main()

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


def input():
    return stdin.readline().strip()


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

    print(ans)


if __name__ == "__main__":
    main()

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


def input():
    return stdin.readline().strip()


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

    print(ans)


if __name__ == "__main__":
    main()

Solution (Python):
from sys import stdin
from bisect import bisect_left


def input():
    return stdin.readline().strip()


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

    nums = [0] * (N + 1)

    pos = 0
    for i, b in enumerate(B):
        pos = bisect_left(C, b + 1, pos)
        nums[i] = N - pos

    for i in range(N, 0, -1):
        nums[i - 1] += nums[i]

    ans = 0
    pos = 0
    for a in A:
        pos = bisect_left(B, a + 1, pos)
        ans += nums[pos]

    print(ans)


if __name__ == "__main__":
    main()

Solution (Python):
from sys import stdin
from bisect import bisect_left


def input():
    return stdin.readline().strip()


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

    nums = [0] * (N + 1)

    pos = 0
    for i, b in enumerate(B):
        pos = bisect_left(C, b + 1, pos)
        nums[i] = N - pos

    for i in range(N, 0, -1):
        nums[i - 1] += nums[i]

    ans = 0
    pos = 0
    for a in A:
        pos = bisect_left(B, a + 1, pos)
        ans += nums[pos]

    print(ans)


if __name__ == "__main__":
    main()

Solution (Python):
from sys import stdin


def input():
    return stdin.readline().strip()


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

    nums = [0] * (N + 1)

    ng = -1
    for i, b in enumerate(B):
        ok = N
        while abs(ok - ng) > 1:
            mid = (ok + ng) // 2
            if C[mid] > b:
                ok = mid
            else:
                ng = mid

        nums[i] = N - ok

    for i in range(N, 0, -1):
        nums[i - 1] += nums[i]

    ans = 0
    ng = -1
    for a in A:
        ok = N
        while abs(ok - ng) > 1:
            mid = (ok + ng) // 2
            if B[mid] > a:
                ok = mid
            else:
                ng = mid

        ans += nums[ok]

    print(ans)


if __name__ == "__main__":
    main()

Solution (Python):
from sys import stdin


def input():
    return stdin.readline().strip()


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

    nums = [0] * (N + 1)

    ng = -1
    for i, b in enumerate(B):
        ok = N
        while abs(ok - ng) > 1:
            mid = (ok + ng) // 2
            if C[mid] > b:
                ok = mid
            else:
                ng = mid

        nums[i] = N - ok

    for i in range(N, 0, -1):
        nums[i - 1] += nums[i]

    ans = 0
    ng = -1
    for a in A:
        ok = N
        while abs(ok - ng) > 1:
            mid = (ok + ng) // 2
            if B[mid] > a:
                ok = mid
            else:
                ng = mid

        ans += nums[ok]

    print(ans)


if __name__ == "__main__":
    main()

Solution (Python):
from sys import stdin


def input():
    return stdin.readline().strip()


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

    nums = [0] * (N + 1)

    for i, b in enumerate(B):
        ng = -1
        ok = N
        while abs(ok - ng) > 1:
            mid = (ok + ng) // 2
            if C[mid] > b:
                ok = mid
            else:
                ng = mid

        nums[i] = N - ok

    for i in range(N, 0, -1):
        nums[i - 1] += nums[i]

    ans = 0
    for a in A:
        ng = -1
        ok = N
        while abs(ok - ng) > 1:
            mid = (ok + ng) // 2
            if B[mid] > a:
                ok = mid
            else:
                ng = mid

        ans += nums[ok]

    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
ai = 0
ci = 0

for b in B:
    while ai < n and A[ai] < b:
        ai += 1
    while ci < n and C[ci] <= b:
        ci += 1
    ans += ai * (n - ci)

print(ans)

Solution (Python):
import bisect

N = int(input())
lst_a = sorted([int(x) for x in input().split()])
lst_b = sorted([int(x) for x in input().split()])
lst_c = sorted([int(x) for x in input().split()])
ans = 0
for b in lst_b:
    i = bisect.bisect_left(lst_a, b)
    j = bisect.bisect_right(lst_c, b)
    ans += i * (N - j)

print(ans)

Solution (Python):
import bisect

N = int(input())
lst_a = sorted([int(x) for x in input().split()])
lst_b = sorted([int(x) for x in input().split()])
lst_c = sorted([int(x) for x in input().split()])
ans = 0
for b in lst_b:
    i = bisect.bisect_left(lst_a, b)
    j = bisect.bisect_right(lst_c, b)
    if i > 0 and j != len(lst_c):
        ans += i * (N - j)

print(ans)

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

n = int(input().strip())
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 elem in b:
    idx_c = bisect_right(c, elem)
    rep = (n - idx_c)
    idx_a = bisect_left(a, elem)
    ans += rep * idx_a
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())))

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=sorted(list(map(int,input().split())))
B=sorted(list(map(int,input().split())))
C=sorted(list(map(int,input().split())))
ans=0
for b in B:
    ans+=bisect.bisect_left(A,b)*(N-bisect.bisect_right(C,b))
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()
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)

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)

ans = 0

for b in B:
    aPtn = bisect.bisect_left(A, b)
    cPtn = len(C) - bisect.bisect_right(C, b)
    ans += aPtn * cPtn

print(ans)

Solution (Python):
from bisect import bisect, bisect_left
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:
    max_A = bisect(A, i-1)
    min_C = bisect_left(C, i+1)
    
    ans += (max_A)* (len(C) - min_C)
print(ans)

Solution (Python):
import sys, math
from itertools import permutations, combinations
from collections import defaultdict, Counter, deque
from math import factorial
from bisect import bisect_left,  bisect_right 
sys.setrecursionlimit(10**7)
enu = enumerate
MOD = 10**9+7
def input(): return sys.stdin.readline()[:-1]
def pri(x): print('\n'.join(map(str, x)))

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
lenC = len(C)
for b in B:
    uecnt = bisect_left(A, b)
    shitacnt = lenC - bisect_right(C, b)
    val = uecnt*shitacnt
    cnt += val

print(cnt)

Solution (Python):
from bisect import bisect_left
n = int(input())
listtop = sorted(list(map(int, input().split())))
listmiddle = sorted(list(map(int, input().split())))
listbottom = sorted(list(map(int, input().split())))
sum = 0



listmiddlesum = [0]
for i in range(n):
    
    ride = bisect_left(listtop, listmiddle[i])
    listmiddlesum.append(listmiddlesum[i] + ride)
for i in range(n):
    ridesum = bisect_left(listmiddle, listbottom[i])
    sum += listmiddlesum[ridesum]
print(sum)

Solution (Python):
from bisect import bisect_left,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()
b.sort()
c.sort()

jsum=0
for j in b:
    ai=bisect(a,j-1)
    ci=lenc-bisect_left(c,j+1)

    jsum+=ai*ci

print(jsum)

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)
ans = 0

for i in range(n):
    a_M = bisect.bisect_left(a, b[i])
    c_m = bisect.bisect_right(c, b[i])
    ans += a_M * (n - c_m)
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 i in b:
  d = bisect.bisect_left(a, i)
  e = bisect.bisect_right(c, i)
  if d > 0 and e < len(c):
    ans += d*(n-e)
print(ans)

Solution (Python):

'''
多分あとは、Bで重複がある場合は探索しないで個数かけていくとかにしないといけない。
'''
def is_okC(idx,key,target):

    if target[idx] > key:
        return True
    return False

def meguru_bisectC(key,target):
    left = -1
    length = len(target)
    right = length
    while (abs(right - left) > 1):
        mid = left + (right - left) // 2
        if is_okC(mid,key,target):
            right = mid
        else:
            left = mid
    return length-right


def is_okA(idx,key,target):

    if target[idx] >= key:
        return True
    return False

def meguru_bisectA(key,target):
    left = -1
    length = len(target)
    right = length
    while (abs(right - left) > 1):
        mid = left + (right - left) // 2

        if is_okA(mid,key,target):
            right = mid
        else:
            left = mid
    return right

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()
a = 0
c = 0
ans = 0



for i in B:
    a = meguru_bisectA(i,A)


    c = meguru_bisectC(i,C)

    ans += a*c


print(ans)

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:
        ansA = bisect.bisect_left(A, b)
        ansC = N - bisect.bisect_right(C, b)
        ans += ansA * ansC

    print(ans)


if __name__ == "__main__":
    main()

Solution (Python):
import bisect
n = int(input())
aa = list(map(int, input().split()))
bb = list(map(int, input().split()))
cc = list(map(int, input().split()))

aa.sort()
cc.sort()

cnt = 0
cnt = sum([bisect.bisect_left(aa,b) * (n - bisect.bisect_right(cc,b)) for b in bb])
print(cnt)

Solution (Python):
import numpy as np
n = int(input())
aa = np.array(list(map(int, input().split())))
bb = list(map(int, input().split()))
cc = np.array(list(map(int, input().split())))

aa.sort()
cc.sort()

cnt = 0
for b in bb:
    na = np.searchsorted(aa,b, side='left')
    nc = n - np.searchsorted(cc,b, side='right')
    cnt += na*nc
print(cnt)

Solution (Python):
import numpy as np
import bisect
n = int(input())
aa = list(map(int, input().split()))
bb = list(map(int, input().split()))
cc = list(map(int, input().split()))

aa.sort()
cc.sort()

cnt = 0
for b in bb:
    na = bisect.bisect_left(aa,b)
    nc = n - bisect.bisect_right(cc,b)
    cnt += na*nc
print(cnt)

Solution (Python):
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()
Cs.sort()
pyout=0

for i in range(N):
    num1=bisect.bisect_left(As,Bs[i])
    num2=N-bisect.bisect_right(Cs,Bs[i])
    pyout+=num2*num1
print(pyout)

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()    
C.sort()

alow = []
for i in range(n):
    key = B[i]
    ok = -1
    ng = n
    while abs(ok-ng)>1:
        mid = (ok+ng)//2
        if A[mid] < key:
            ok = mid
        else:
            ng = mid
    alow.append(ok+1)
    
cup = []
for i in range(n):
    key = B[i]
    ok = n
    ng = -1
    while abs(ok-ng)>1:
        mid = (ok+ng)//2
        if C[mid] > key:
            ok = mid
        else:
            ng = mid
    cup.append(n-ok)

ans = 0
for i in range(n):
    ans+=alow[i] * cup[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()    
C.sort()

alow = []
for i in range(n):
    key = B[i]
    ok = -1
    ng = n
    while abs(ok-ng)>1:
        mid = (ok+ng)//2
        if A[mid] < key:
            ok = mid
        else:
            ng = mid
    alow.append(ok+1)
    
cup = []
for i in range(n):
    key = B[i]
    ok = n
    ng = -1
    while abs(ok-ng)>1:
        mid = (ok+ng)//2
        if C[mid] > key:
            ok = mid
        else:
            ng = mid
    cup.append(n-ok)

ans = 0
for i in range(n):
    ans+=alow[i] * cup[i]
print(ans)

Solution (Python):
from bisect import bisect_left, bisect

n=int(input())
la=sorted(list(map(int,input().split())))
lb=list(map(int,input().split()))
lc=sorted(list(map(int,input().split())))
ans=0
for i in lb:
    ans+=bisect_left(la,i)*(len(lc)-bisect(lc,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(),c.sort()
x=len(c)
ans=0
for bi in b:
  xa=bisect.bisect_right(c,bi)
  xb=bisect.bisect_left(a,bi)
  ans+=xb*(x-xa)
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
ans = 0
cnt = []
for i in b:
    cnt.append(n-bisect.bisect_right(c,i))
cnt += [0]
for i in range(n-1,-1,-1):
    cnt[i] += cnt[i+1]
for i in a:
    ans += cnt[bisect.bisect_right(b,i)]
print(ans)

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

Solution (Python):
from bisect import bisect_left as bl,bisect_right as br
n=int(input())
a,b,c=[sorted(list(map(int,input().split()))) for i in range(3)]
ans=0
for v in b:
  if v<=a[0] or v>=c[-1]:continue
  ans+=bl(a,v)*(n-br(c,v))
print(ans)

Solution (Python):
import bisect

def snuke_festival(N,arr):
    n_pair = 0
    for item in arr[1]:
        up_pair = bisect.bisect_left(arr[0],item)
        down_pair = bisect.bisect_right(arr[2],item)
        n_pair += up_pair*(N-down_pair)
    return n_pair


if __name__ == "__main__":
    N  =int(input())
    arr = []
    for i in range(3):
        arr.append(list(map(int,input().split())))
    arr_sorted = []
    for j in range(3):
        arr_sorted.append(arr[j].sort())
    print(snuke_festival(N,arr))

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 num in b:
    i = bisect.bisect_left(a, num)
    j = bisect.bisect_right(c, num)
    cnt += i * (n - j)
print(cnt)

Solution (Python):
from collections import deque
from heapq import heapify,heappop,heappush,heappushpop
from copy import copy,deepcopy
from itertools import permutations,combinations
from collections import defaultdict,Counter
from bisect import bisect_left,bisect_right


from functools import reduce
from pprint import pprint

def myinput():
    return map(int,input().split())

def mylistinput(n):
    return [ list(myinput()) for _ in range(n) ]

def mycol(data,col):
    return [ row[col] for row in data ]

def mysort(data,col,reverse_flag):
    data.sort(key=lambda x:x[col],reverse=reverse_flag)
    return data

def mymax(data):
    M = -1*float("inf")
    for i in range(len(data)):
        m = max(data[i])
        M = max(M,m)
    return M

def mymin(data):
    m = float("inf")
    for i in range(len(data)):
        M = min(data[i])
        m = min(m,M)
    return m

def myoutput(ls,space=True):
    if space:
        if len(ls)==0:
            print(" ")
        elif type(ls[0])==str:
            print(" ".join(ls))
        elif type(ls[0])==int:
            print(" ".join(map(str,ls)))
        else:
            print("Output Error")
    else:
        if len(ls)==0:
            print("")
        elif type(ls[0])==str:
            print("".join(ls))
        elif type(ls[0])==int:
            print("".join(map(str,ls)))
        else:
            print("Output Error")

n = int(input())
a = list(myinput())
b = list(myinput())
c = list(myinput())

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






ls = [0]*n
for j in range(n):
    ind_a = bisect_left(a,b[j])
    ls[j] = ind_a


ls_sum = [0]*n
s = 0
for i in range(n):
    s += ls[i]
    ls_sum[i] = s

     
count = 0
for k in range(n):
    ind_b = bisect_left(b,c[k])
    
    if ind_b==0:
        count += 0
    elif ind_b==n:
        count += ls_sum[-1]
    else:
        count += ls_sum[ind_b-1]
    
print(count)

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

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

Solution (Python):
def binSearch(array, num):
    n = len(array)
    l = -1
    r = n

    while l + 1 < r:
        m = (l + r) // 2
        if num <= array[m]:
            r = m
        else:
            l = m

    return r


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(len(b)):
    a_idx = binSearch(a, b[i])
    c_idx = binSearch(c, b[i] + 1)
    ans += a_idx * (n - c_idx)
print(ans)

Solution (Python):
def is_ok_under(array, mid, target):
    return array[mid] < target


def is_ok_over(array, mid, target):
    return array[mid] > target



def bSearchUnder(array, ok, ng, target):
    while (abs(ok - ng) > 1):
        mid = (ok + ng) // 2
        if is_ok_under(array, mid, target):
            ok = mid
        else:
            ng = mid
    return ok



def bSearchOver(array, ok, ng, target):
    while (abs(ok - ng) > 1):
        mid = (ok + ng) // 2
        if is_ok_over(array, mid, target):
            ok = mid
        else:
            ng = mid
    return ok


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(len(b)):
    add = 1
    add *= bSearchUnder(a, -1, len(a), b[i]) + 1
    add *= len(c) - bSearchOver(c, len(c), -1, b[i])
    ans += add

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()
c.sort()

ans = 0
c_len = len(c)

for i in b:
    a_index = bisect.bisect_left(a , i)
    c_index = bisect.bisect_right(c , i)
    tmp = a_index * (c_len - c_index)
    ans += tmp
    
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 sys, copy, math, heapq, bisect
from itertools import accumulate
from collections import deque, defaultdict, Counter
input = sys.stdin.readline 
sys.setrecursionlimit(500000)
ans = 0
for i in range(N):
    a = bisect.bisect_left(A,B[i])
    c = bisect.bisect_right(C,B[i])

    ans += (N-c)*a
print(ans)

Solution (Python):
import bisect
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())))
    
    cnt = 0
    for b in B:
        i = bisect.bisect_left(A, b)
        k = bisect.bisect_right(C, b)
        cnt += i * (N-k)
    print(cnt)

if '__main__' == __name__:
    resolve()

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

def input():
    return sys.stdin.readline()[:-1]
def inputi():
    return int(input())
def inputl():
    return list(map(int, input().split()))
def printl(li):
    print(*li, sep="\n")
def argsort(s):
    return sorted(range(len(s)), key=lambda k: s[k])



N = inputi()


A = inputl()
B = inputl()
C = inputl()


































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

Solution (Python):
import sys



import bisect

def input():
    return sys.stdin.readline()[:-1]
def inputi():
    return int(input())
def inputl():
    return list(map(int, input().split()))
def printl(li):
    print(*li, sep="\n")
def argsort(s):
    return sorted(range(len(s)), key=lambda k: s[k])



N = inputi()


A = inputl()
B = inputl()
C = inputl()


































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

Solution (Python):
import sys

readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


def main():
    n = int(input())
    a = list(map(int, readline().split()))
    b = list(map(int, readline().split()))
    c = list(map(int, readline().split()))
    a.sort()
    b.sort()
    c.sort()

    count_ab = [0] * n
    count_bc = [0] * n

    import bisect

    for bi, middle in enumerate(b):
        count_ab[bi] = bisect.bisect_left(a, middle)

    for ci, bottom in enumerate(c):
        count_bc[ci] = bisect.bisect_left(b, bottom)

    from itertools import accumulate

    cum_ab = [0] + list(accumulate(count_ab))
    ans = 0

    for i in range(n):
        num = count_bc[i]
        ans += cum_ab[num]

    print(ans)

if __name__ == '__main__':
    main()

Solution (Python):
import bisect
import io
import math
import string

data = 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()
C.sort()
counter = 0

for b in B:
    a_index = bisect.bisect_left(A,b)
    c_index = bisect.bisect_right(C,b)
    counter += a_index*(len(C)-c_index)

print(counter)

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

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

Solution (Python):
import copy
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()
l1n=[-1 for _ in range(N)]
l2n=[-1 for _ in range(N)]
idab=0
idbc=0
buf1=[]
flag1=0
buf2=[]
flag2=0
i=0



exc=0
mulsum=[0]*N
"""
while i<N:
    if (idab!=N)and(A[i]>=B[idab]):
        flag1=1
        idab=idab+1
    elif flag1==1:
        l1n[i]=idab-1
        i=i+1
    else:
        i=i+1
    
    

i=0
while i<N:
    if (idbc!=N)and(B[i]>=C[idbc]):
        flag2=1
        idbc=idbc+1
    elif flag2==1:
        l2n[i]=idbc-1
        i=i+1
    else:
        i=i+1
    
    


mulsum[0]=l2n[0]+1
for i in range(N-1):
    mulsum[i+1]=mulsum[i]+(l2n[i+1]+1)

for i in range(N):
    if l1n[i]!=-1:
        exc=exc+mulsum[l1n[i]]
        
print(pow(N,3)-(sum(l1n)+N)*N-(sum(l2n)+N)*N+exc)
"""
aok=0
cok=0


cnt=0
for i in range(N):
    piv=B[i]
    aok=bisect.bisect_right(A,piv-1)
    cok=bisect.bisect_left(C,piv+1)
    cnt=cnt+aok*(N-cok)
    
print(cnt)

Solution (Python):
import copy
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()
l1n=[-1 for _ in range(N)]
l2n=[-1 for _ in range(N)]
idab=0
idbc=0
buf1=[]
flag1=0
buf2=[]
flag2=0
i=0



exc=0
mulsum=[0]*N
while i<N:
    if (idab!=N)and(A[i]>=B[idab]):
        flag1=1
        idab=idab+1
    elif flag1==1:
        l1n[i]=idab-1
        i=i+1
    else:
        i=i+1
    
    

i=0
while i<N:
    if (idbc!=N)and(B[i]>=C[idbc]):
        flag2=1
        idbc=idbc+1
    elif flag2==1:
        l2n[i]=idbc-1
        i=i+1
    else:
        i=i+1
    
    


mulsum[0]=l2n[0]+1
for i in range(N-1):
    mulsum[i+1]=mulsum[i]+(l2n[i+1]+1)

for i in range(N):
    if l1n[i]!=-1:
        exc=exc+mulsum[l1n[i]]
        
print(pow(N,3)-(sum(l1n)+N)*N-(sum(l2n)+N)*N+exc)

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

Solution (Python):
def isOK_under(array, index, key):
    if array[index] >= key:
        return True
    else:
        return False

def isOK_over(array, index, key):
    if array[index] > key:
        return True
    else:
        return False

def binary_serch_under(array, key):
    ng = -1
    ok = len(array)

    while (abs(ok - ng) > 1):
        mid = (ok + ng)//2

        if isOK_under(array, mid, key):
            ok = mid
        else:
            ng = mid
    return ok

def binary_serch_over(array, key):
    ng = -1
    ok = len(array)
    while (abs(ok - ng) > 1):
        mid = (ok + ng)//2
        if isOK_over(array, mid, key):
            ok = mid
        else:
            ng = mid
    return ok

n = int(input())
array1 = list(map(int,input().split()))
array2 = list(map(int,input().split()))
array3 = list(map(int,input().split()))

array1 = sorted(array1)
array2 = sorted(array2)
array3 = sorted(array3)


count=0









for index_array2 in range(n):
    a = binary_serch_under(array1, array2[index_array2])
    c = binary_serch_over(array3, array2[index_array2])
    count += a*abs(c-n)
print(count)

Solution (Python):




import sys
inf = 10**9+7
mod = 10**9+7
import bisect
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))
b.sort()
c.sort()
b_len = len(b)
c_len = len(c)
count = 0
b_list = [0 for i in range(b_len)]

for i,num in enumerate(b):
    ind_c = bisect.bisect_left(c, num)
    if c_len == ind_c:
        continue
    else:
        if c[ind_c] == num:
            ind_c = bisect.bisect_left(c, num+1)
            if c_len == ind_c:
                continue
            else:
                b_list[i] = c_len - ind_c
        else:
            b_list[i] = c_len-ind_c


a2 = [0]
for i in b_list:a2.append(a2[-1]+i)
def SumArea(l, r):
    return a2[r]-a2[l]


for num in a:
    ind_b = bisect.bisect_left(b, num)
    if b_len == ind_b:
        continue
    else:
        if b[ind_b] == num:
            ind_b = bisect.bisect_left(b, num+1)
            if b_len == ind_b:
                continue
            else:
                count += SumArea(ind_b, b_len)
        else:
            count += SumArea(ind_b, b_len)
print(count)

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