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):
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(len(b)):
    index_a=bisect.bisect_left(a,b[i])
    index_c=bisect.bisect_right(c,b[i])
    ans+=(index_a*(len(c)-index_c))
print(ans)

Solution (Python):
import copy
import math
import time
import statistics
import math
import itertools
import bisect


def get_int():
    return int(input())

def get_string():
    return input()

def get_int_list():
    return [int(x) for x in input().split()]

def get_string_list():
    return input().split()

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

def get_string_char_list():
    return list(str(input()))




'''
while (idx < n) and ():

    idx += 1
'''

def main():
    start = time.time()
    n = get_int()

    a_list = get_int_list()
    b_list = get_int_list()
    c_list = get_int_list()

    a_list.sort()
    b_list.sort()
    c_list.sort()

    a_count = []
    b_count = []
    b_count2 = []

    idx = 0
    for a in a_list:
        idx = bisect.bisect_right(b_list, a, idx)
        a_count.append(idx)

    idx = 0
    for b in b_list:
        idx = bisect.bisect_right(c_list, b, idx)
        b_count.append(idx)

    ruikei = 0
    for i in range(n-1, -1, -1):
        ruikei += n - b_count[i]
        b_count2.append(ruikei)

    b_count2.sort(reverse=True)

    ans = 0
    for a in a_count:
        if a == n:
            continue
        ans += b_count2[a]

    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 = sorted(a)
b = sorted(b)
c = sorted(c)


def lower_bound(arr , x):
    l = 0
    r = len(c)
    for j in range(30):
        mid = (l + r) // 2
        
        if x <= arr[mid]:
            r = mid
        else:
            l = mid
    return r


count = 0
for i in range(n):
    a_count = lower_bound(a , b[i])
    c_count = len(c) - lower_bound(c , b[i] + 1)
    count += a_count * c_count

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 = sorted(a)
b = sorted(b)
c = sorted(c)


def lower_bound(arr , x):
    l = 0
    r = len(c)
    for j in range(30):
        mid = (l + r) // 2
        
        if x <= arr[mid]:
            r = mid
        else:
            l = mid
    return r


count = 0
for i in range(n):
    a_count = lower_bound(a , b[i])
    c_count = len(c) - lower_bound(c , b[i] + 1)
    count += a_count * c_count

print(count)

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)

count=0

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

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

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

from bisect import bisect_right

d=[]
for i in range(n):
    index = bisect_right(c,b[i])    

    d.append(n-index)

import numpy as np
s=sum(d)
cum=np.cumsum(d)

ans=0
for j in range(n):
    dex = bisect_right(b,a[j])
    if dex==0:
        ans+=s
    elif dex==n:
        continue
    else:
        ans+=s-cum[dex-1]

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()))
out=0
a.sort()
b.sort()
c.sort()
for i in b:
    na = bisect.bisect_left(a,i)
    nc = bisect.bisect(c,i)
    out += na * (len(c)-nc)
print(out)

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_count = bisect.bisect_left(A, b)
    c_count = N - bisect.bisect_right(C, b)
    ans += a_count * c_count
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()

pat = 0

for i in B:
    numA = bisect.bisect_left(A,i)
    numC = bisect.bisect(C,i)
    pat += numA * (len(C)-numC)

print(pat)

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 = sorted(A_list)
B_list = sorted(B_list)
C_list = sorted(C_list)
cnt = 0

def is_ok(arg): 
    return A_list[arg] < B_list[i]

def bisect(ng, ok):
    while (abs(ok - ng) > 1):
        mid = (ok + ng) // 2
        if is_ok(mid):
            ok = mid
        else:
            ng = mid
    return ok

def is_ok2(arg): 
    return C_list[arg] > B_list[i]

def bisect2(ng, ok):
    while (abs(ok - ng) > 1):
        mid = (ok + ng) // 2
        if is_ok2(mid):
            ok = mid
        else:
            ng = mid
    return ok

for i in range(n): 
    
    A_key = bisect(len(A_list), 0)
    if A_list[A_key] < B_list[i]:
        
        C_key = bisect2(-1, len(C_list)-1)
        if B_list[i] < C_list[C_key]:
            
            cnt += (n-C_key)*(A_key+1)

print(cnt)

Solution (Python):
import bisect

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

Solution (Python):


import math

import itertools
from collections import deque
from collections import Counter
import heapq


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()
b_res=[0]*n
c_res=[0]*n
j=0
cnt=0
for i in range(n):
    res=b[i]
    cnt=bisect.bisect_left(a,res)
    b_res[i]=cnt
    res=c[i]
    cnt=bisect.bisect_left(b,res)
    c_res[i]=cnt
cntb=[0]*n
cntb[0]=b_res[0]
for i in range(1,n):
    cntb[i]=cntb[i-1]+b_res[i]
ans=0
for i in range(n):
    cnt=c_res[i]
    if cnt==0:
        continue
    else:
        ans+=cntb[cnt-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.sort()
B.sort()
C.sort()

import bisect as bi
ans=0
for i in range(n):
    q=B[i]
    oka= bi.bisect_left(A,q)
    okb= n- bi.bisect_right(C,q)
    ans+=oka*okb
print(ans)

Solution (Python):
import bisect
from collections import defaultdict
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
bb = []
for b in B:
  idx = bisect.bisect_right(C, b)
  bb += [[b, len(C)-idx]]

for i in range(len(bb)-1, 0, -1):
  bb[i-1][1] += bb[i][1]

for a in A:
  idx = bisect.bisect_right(B, a)
  if idx > len(B)-1:
    continue
  ans += bb[idx][1]
print(ans)

Solution (Python):
from bisect import*
(n,), a, b, c = [sorted(map(int, o.split())) for o in open(0)]
print(sum(bisect_left(a, i) * (n - bisect(c, i)) for i in b))

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

C.sort()





def bisectsearch_left(L, a):
    i = bisect_left(L, a)
    return(i)


def bisectsearch_right(L, a):
    i = bisect_right(L, a)
    return(i)


ans = 0
for j in range(N):
    b = B[j]
    cti = bisectsearch_left(A, b)
    ctk = N-bisectsearch_right(C, b)
    
    ans += cti*ctk
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=sorted(a)
c=sorted(c)
ans=0
import bisect
for i in b:
  t=bisect.bisect_left(a, i)
  q=bisect.bisect_right(c, i)
  ans+=t*(n-q)
print(ans)

Solution (Python):
import sys
from bisect import bisect_left, bisect_right
def input(): return sys.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 = 0
    for b in B:
        idx_a = bisect_left(A, b)
        idx_c = bisect_right(C, b)
        ans += idx_a * (N - idx_c)
    print(ans)

if __name__ == "__main__":
    main()

Solution (Python):

import sys
import bisect
input = sys.stdin.readline
def RD(): return input().rstrip()
def I(): return int(input().rstrip())
def MI(): return map(int, input().split())
def MF(): return map(float,input().split())
def LI(): return list(map(int, input().split()))
def LF(): return list(map(float,input().split()))
def Init(H, W, num): return [[num for i in range(W)] for j in range(H)]

def main():
    N = I()
    A = LI()
    A.sort()
    B = LI()
    B.sort()
    B_len = len(B)
    C = LI()
    C.sort()
    C_len = len(C)
    result = 0
    A_init = A[0]
    index = 0
    next_i = index
    
    for i in B:
        tempA = bisect.bisect_left(A,i) 
        tempC = C_len - bisect.bisect_right(C,i)
        result += tempA*tempC
    print(result)

if __name__ == "__main__":
    main()

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=sorted(A)
b=sorted(B)
c=sorted(C)
ans=0
import bisect
from bisect import bisect_right
from bisect import bisect_left
for j in range(n):
  p=bisect.bisect_left(a,b[j])
  q=n-bisect.bisect_right(c,b[j])
  ans+=p*q
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()))
print(sum(bisect.bisect_left(A,b)*(N-bisect.bisect_right(C,b)) for b 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()
ab=[]
bc=[]
for i in range(n):
    ab.append([a[i],n])
    bc.append([b[i],n])
    ab.append([b[i],i])
    bc.append([c[i],i])
numa=1
numb=1
numc=1
la=[1]*n
lb=[1]*n
lc=[1]*n
for i in range(1,n):
    if a[i-1]!=a[i]:
        la[i]=i+1
        numa=i+1
    else:
        la[i]=numa
    if b[i-1]!=b[i]:
        lb[i]=i+1
        numb=i+1
    else:
        lb[i]=numb
    if c[i-1]!=c[i]:
        lc[i]=i+1
        numc=i+1
    else:
        lc[i]=numc
ab.sort(key=lambda x: x[0])
numab=1
lab=[1]*(n+1)
for i in range(1,n*2):
    if ab[i-1][0]!=ab[i][0]:
        lab[ab[i][1]]=i+1
        numab=i+1
    else:
        lab[ab[i][1]]=numab
ansb=[0]*n
numb=0
for i in range(n):
    numb+=lab[i]-lb[i]
    ansb[i]=numb
bc.sort(key=lambda x: x[0])
numbc=1
lbc=[1]*(n+1)
for i in range(1,n*2):
    if bc[i-1][0]!=bc[i][0]:
        lbc[bc[i][1]]=i+1
        numbc=i+1
    else:
        lbc[bc[i][1]]=numbc
ansc=[0]*n
for i in range(n):
    ansc[i]=lbc[i]-lc[i]
ans=0
for i in range(n):
    if ansc[i]!=0:
        ans+=ansb[ansc[i]-1]
print(ans)

Solution (Python):
import sys
from bisect import bisect_left, bisect_right
input = sys.stdin.readline
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()
  lc=len(C)
  ans=0
  for b in B:
    ma = bisect_left(A, b)
    mc = lc-bisect_right(C, b)
    ans += ma*mc
  print(ans)

if __name__ == "__main__":
    main()

Solution (Python):
import sys
from bisect import bisect_left, bisect_right
input = sys.stdin.readline
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())))
  lc=len(C)
  ans=0
  for b in B:
    ma = bisect_left(A, b)
    mc = lc-bisect_right(C, b)
    ans += ma*mc
  print(ans)

if __name__ == "__main__":
    main()

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

if __name__ == "__main__":
    main()

Solution (Python):
def main():
  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())))
  lc=len(C)
  ans=0
  for b in B:
    ma = bisect.bisect_left(A, b)
    mc = lc-bisect.bisect_right(C, b)
    ans += ma*mc
  print(ans)

if __name__ == "__main__":
    main()

Solution (Python):
def main():
  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())))
  lb,lc=len(B),len(C)
  ans=0
  for b in B:
    ma = bisect.bisect_left(A, b)
    mc = lc-bisect.bisect_right(C, b)
    ans += ma*mc
  print(ans)

if __name__ == "__main__":
    main()

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())))
lc=len(C)
ans=0
for b in B:
  ma = bisect.bisect_left(A, b)
  mc = lc-bisect.bisect_right(C, b)
  ans += ma*mc
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())))
lb,lc=len(B),len(C)
ans=0
for b in range(lb):
  ma = bisect.bisect_left(A, B[b])
  mc = lc-bisect.bisect_right(C, B[b])
  ans += ma*mc
print(ans)

Solution (Python):
n = int(raw_input())
ais = map(int, raw_input().split())
bis = map(int, raw_input().split())
cis = map(int, raw_input().split())


count = 0
ais.sort()
bis.sort()
cis.sort()

i,j = 0,0
for b in bis:
	while(i < len(ais) and ais[i] < b):
		i += 1
	while(j < len(cis) and cis[j] <= b):
		j += 1
	count += i * (n - j)
print count

Solution (Python):


import sys
stdin = sys.stdin
from bisect import bisect_left, bisect_right

def ns(): return stdin.readline().rstrip()
def ni(): return int(ns())
def na(): return list(map(int, stdin.readline().split()))

def main():
    n = ni()
    a = na()
    b = na()
    c = na()
    a.sort()
    b.sort()
    c.sort()
    cnt = 0
    
    for bi in b:
        i = bisect_left(a, bi)
        j = bisect_right(c, bi)
        cnt += i * (n-j)
        
    print(cnt)

if __name__ == "__main__":
    main()

Solution (Python):
n = int(input())
a_ls = list(map(int, input().split()))
b_ls = list(map(int, input().split()))
c_ls = list(map(int, input().split()))
for ls in [a_ls,b_ls,c_ls]:
    ls.sort()

def is_not_less_than(ls, ind, key):
    if ls[ind] >= key:
        return True
    else:
        return False

def return_min_ind_whose_value_not_less_than(ls,key):
    r = len(ls)
    l = -1
    while True:
        next_ind = (r+l) // 2
        if is_not_less_than(ls, next_ind, key):
            r = next_ind
        else:
            l = next_ind
        if r - l == 1:
            return r

def is_more_than(ls, ind, key):
    if ls[ind] > key:
        return True
    else:
        return False

def return_min_ind_whose_value_more_than(ls,key):
    r = len(ls)
    l = -1
    while True:
        next_ind = (r+l) // 2
        if is_more_than(ls, next_ind, key):
            r = next_ind
        else:
            l = next_ind
        if r - l == 1:
            return r

ans = 0
for i in range(n):
    b_c = n - return_min_ind_whose_value_more_than(c_ls, b_ls[i])
    a_b = return_min_ind_whose_value_not_less_than(a_ls, b_ls[i])
    ans += b_c*a_b
print(ans)

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

BtoA=[]
for b in B:
    BtoA.append(bisect(A,b))


sum_BtoA=[BtoA[0]]
for i in range(n-1):
    sum_BtoA.append(sum_BtoA[i]+BtoA[i+1])











ans=0
for c in C:
    index=bisect(B,c)
    if index>0:
        ans+=sum_BtoA[index-1]

print(ans)

Solution (Python):
import bisect
N = int(input())
A = sorted(int(T) for T in input().split())
B = sorted(int(T) for T in input().split())
C = sorted(int(T) for T in input().split())
Count = 0
for TB in B:
    SmallA = bisect.bisect_left(A,TB)
    BigC   = N-bisect.bisect_right(C,TB)
    Count += SmallA*BigC
print(Count)

Solution (Python):
import bisect 
from itertools import accumulate

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

bc = [0] * N 
for i in range(N):
    bc[i]= N - bisect.bisect_right(c, b[i])
bcA = [0] + list(accumulate(bc))               

cnt = 0
for i in range(N):
    x = bisect.bisect_right(b, a[i])            
    cnt += bcA[-1] - bcA[x]                    

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

ans = 0

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

B_cnt = [0]*N

for i in range(N):
    ok = bisect.bisect_right(C, B[i])
    B_cnt[i] = N-ok

B_cum = [0]*N
B_cum[-1] = B_cnt[-1]

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

B_cum.append(0)

for i in range(N):
    cnt += B_cum[bisect.bisect_right(B, A[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()
sm = 0
for i in b:
    target = i
    a_idx = bisect.bisect_left(a,target)
    c_idx = bisect.bisect_right(c,target)
    sm += a_idx * (n-c_idx)

print(sm)

Solution (Python):
n=int(input())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
c=list(map(int,input().split()))
d=[]
a.sort()
b.sort()
c.sort()
def binary_search1(list,item):
    low = 0
    high = len(list) - 1

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

def binary_search2(list,item):
    low = 0
    high = len(list) - 1

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

ans=0

for i in range(n):
    
    ans+=binary_search2(c,b[i])*binary_search1(a,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:
    ia = bisect.bisect_left(A, b)
    ic = len(C) - bisect.bisect(C, b)
    ans += ia * ic

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

  
print(ans)

Solution (Python):
import bisect

def I(): return int(input())
def LI(): return list(map(int,input().split()))
def MI(): return map(int,input().split())
def LLI(n): return [list(map(int, input().split())) for _ in range(n)]







n = I()
a_li = sorted(LI())
b_li = sorted(LI())
c_li= sorted(LI())
ans = 0
for i in range(n):
  B = b_li[i]
  k = n - bisect.bisect_right(c_li,B)
  l = bisect.bisect_left(a_li,B)
  ans += k*l
print(ans)

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

def isAok(a, b):
    return True if a < b else False

def isCok(b, c):
    return True if c > b else False


for b in B:
    left = -1
    right = N
    while right-left > 1:
        mid = left + (right-left)//2
        if isAok(A[mid], b):
            left = mid
        else:
            right = mid
    acnt = left + 1

    left = -1
    right = N
    while right-left > 1:
        mid = left
        mid = left + (right-left)//2
        if isCok(b, C[mid]):
            right = mid
        else:
            left = mid
    ccnt = N-right
    ans += acnt * ccnt
print(ans)

Solution (Python):
import sys
from bisect import bisect_right,bisect_left
read=sys.stdin.read
readline=sys.stdin.readline

def main():
    n=int(readline())
    a,b,c=(list(map(int,lst.split())) for lst in read().splitlines())
    a.sort()
    b.sort()
    c=[-x for x in c]
    c.sort()
    print(sum(bisect_left(a,x)*bisect_left(c,-x) for x in b))

if __name__=='__main__':
    main()

Solution (Python):

import sys
from heapq import heapify,heappop,heappush
from collections import defaultdict
read=sys.stdin.read
readline=sys.stdin.readline

def main():
    n=int(readline())
    a,b,c=(list(map(int,lst.split())) for lst in read().splitlines())
    a.sort()
    b.sort()
    c=[-x for x in c]
    c.sort()

    def bise(x,lst):
        left=0
        right=len(lst)
        while right-left>0:
            mid=(right+left)//2
            if lst[mid]>=x:
                right=mid
            else:
                left=mid+1
        return left
    print(sum(bise(x,a)*bise(-x,c) for x in b))

if __name__=='__main__':
    main()

Solution (Python):
import bisect as bs

n = int(input())

a_l = list(map(int, input().split()))
b_l = list(map(int, input().split()))
c_l = list(map(int, input().split()))

a_l.sort()
b_l.sort()
c_l.sort()

ans = 0
for b in b_l:
    ans += bs.bisect_left(a_l,b) * (n-bs.bisect_right(c_l,b))
print(ans)


'''
以下の方法だと、N*logN*logN
for i in range(n):
    index_1 = bs.bisect_right(b_l,a_l[i])
    for j in range(index_1,n):
        index_2 = bs.bisect_right(c_l,b_l[j])
        ans += (n-index_2)
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())))

comb = 0
mid_start = 0

while mid_start < N:
    mid_value = B[mid_start]
    mid_end = bisect.bisect_right(B,mid_value)
    mid_num = mid_end - mid_start
    top_end = bisect.bisect_left(A,mid_value)
    top_num = top_end
    bottom_start = bisect.bisect_right(C,mid_value)
    bottom_num = N - bottom_start
    comb += top_num * mid_num * bottom_num
    mid_start = mid_end

print(comb)

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

al = list(map(int, input().split()))
bl = list(map(int, input().split()))
cl = list(map(int, input().split()))
import bisect
al.sort();bl.sort();cl.sort()
ans=0
for bi in bl:
    c1 = bisect.bisect_right(al, bi-1)
    c2 = n-bisect.bisect_left(cl, bi+1)
    ans += c1*c2
print(ans)

Solution (Python):
def bs_left(lists, item):
    low, high = 0, len(lists)
    
    while (high >low ) :
        mid = (low + high)//2
        if lists[mid]  < item:
            low = mid +1
            
        else:
            high = mid
            
    return low

def bs_right(lists, item):
    low, high = 0, len(lists)
    
    while (high >low ):
        mid = (low + high)//2
        if lists[mid] > item:
            high = mid 
            
        else:
            low = mid+1
            
    return len(lists) - low
  
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()]

count = 0
A.sort(), B.sort(), C.sort()
for b in B:
    count += (bs_left(A, b) * bs_right(C, b))
    
print(count)

Solution (Python):
from bisect import bisect_left

N = int(input())

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

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

B_count = [0]*N
A_count = [0]*N

for i in range(N):
    B_count[i]=bisect_left(C,B[i])

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

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

print(sum(A_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()

total = 0
import bisect
for _b in b:
    n_a = bisect.bisect_left(a, _b)
    n_c = n - bisect.bisect_right(c, _b)
    total += n_a * n_c
print(total)

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()
a_pt=0;b_pt=0;c_pt=0
ci=0;bi=0;ai=0
while ci < len(c):
  cc=c[ci]
  while bi <len(b):
    bb=b[bi]
    if bb>=cc:
      break
    while ai<len(a):
      aa=a[ai]
      if aa>=bb:
        break
      a_pt+=1
      ai+=1
    b_pt+=a_pt
    bi+=1
  c_pt+=b_pt
  ci+=1

print(c_pt)

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 b in B:
    
    c_num = len(C)-bisect.bisect_left(C,b+1)
    a_num = bisect.bisect_right(A,b-1)
    count+=c_num*a_num

print(count)

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

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

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

lenc=len(C)

from bisect import *

cnt=0
for b in B:
    in_a = bisect_left(A, b)
    in_c = bisect_right(C, b)
    cnt+= in_a*(lenc-in_c)

print(cnt)

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

print(total)

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

Solution (Python):
from bisect import bisect_left

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

"""
前処理で中部に大きさb以下のパーツを使える場合の組み合わせの数を計算しておく。
"""

tmp1 = [0]
for b in B:
    a = bisect_left(A,b)
    tmp1.append(tmp1[-1]+a)

tmp2 = 0
for c in C:
    idx = bisect_left(B,c)
    tmp2 += tmp1[idx]
print(tmp2)

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 range(n):
    t = b[i]
    ci = bisect.bisect_right(c,t)
    ai = bisect.bisect_left(a,t)
    ans += ai*(n-ci)
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()

cnt = 0

for b_e in b:
    a_cases = bisect_left(a, b_e)
    c_cases = bisect_right(c, b_e)
    cnt += a_cases * (n - c_cases)
print(cnt)

Solution (Python):
from bisect import bisect_left, bisect_right

n = int(input())
an = list(map(int, input().split()))
bn = list(map(int, input().split()))
cn = list(map(int, input().split()))

an.sort()
bn.sort()
cn.sort()

cnt = 0

for b in bn:
    a = bisect_left(an,b)
    c = bisect_right(cn,b)
    cnt += a * (n-c)
print(cnt)

Solution (Python):
import bisect

ans =0

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

for i in b:
    s = bisect.bisect_right(c,i)
    s_num = n-s

    t = bisect.bisect_left(a,i)
    t_num = t

    ans += s_num * t_num

print(ans)

Solution (Python):
import sys
import itertools
sys.setrecursionlimit(1000000000)
from heapq import heapify,heappop,heappush,heappushpop
import math
import collections
import copy
import bisect
mod = 10**9+7

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

Solution (Python):
import bisect

n = int(input())
a_li = list(map(int, input().split()))
b_li = list(map(int, input().split()))
c_li = list(map(int, input().split()))

a_li.sort()
b_li.sort()
c_li.sort()

ans = 0

for i in b_li:
    s = bisect.bisect_right(c_li, i)
    s_num = n-s
    
    t = bisect.bisect_left(a_li, i)
    t_num = t
    
    ans += s_num * t_num

print(ans)