CodeEff/ECCO huggingface dataset:
# Original solution
N = int(eval(input()))
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))

counter = 0

for a in A:
    for b in B:
        if a < b:
            for c in C:
                if b < c:
                    counter = counter + 1
                else:
                    pass
        else:
            pass

print(counter)


# Optimized solution
import bisect

N = int(eval(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)

counter = 0

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

print(counter)
# Original solution
import bisect
n=int(eval(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()
b=b[::-1]
c.sort()
ans=tmp=0
for i in a:
    for j in b:
        if i>=j: break
        tmp=bisect.bisect_right(c, j)
        ans+=(n-tmp)
print(ans)

# Optimized solution
import bisect
n=int(eval(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()
b=b[::-1]
c.sort()
ans=tmp=0
for i in b:
    x=bisect.bisect_left(a,i)
    y=bisect.bisect_right(c, i)
    ans+=x*(n-y)
print(ans)
# Original solution
n=int(eval(input()))
a=list(map(int,input().split()))
b=list(map(int,input().split()))
c=list(map(int,input().split()))
al=sorted(a)
bl=sorted(b)
cl=sorted(c)
 
abl=[]
i=0
for j in range(n):
    i=n-1
    while al[i]>=bl[j]:
        i-=1
        if i==-1:
            break
    if i==-1:
        abl.append(0)
    else:
        abl.append(i+1)
bcl=[]
j=0
for j in range(n):
    k=0
    while cl[k]<=bl[j]:
        k+=1
        if k==n:
            break
    if k==n:
        bcl.append(0)
    else:
        bcl.append(n-k)
ans=0
for s in range(n):
    ans+=abl[s]*bcl[s]
print(ans)


# Optimized solution
n=int(eval(input()))
a=list(map(int,input().split()))
b=list(map(int,input().split()))
c=list(map(int,input().split()))
al=sorted(a)
bl=sorted(b)
cl=sorted(c)
 
abl=[0]*n
bcl=[0]*n
i=n-1
for j in range(n-1,-1,-1):
    if i==-1:
        abl[j]=0
        continue
    while al[i]>=bl[j]:
        i-=1
        if i==-1:
            break
    if i==-1:
        abl[j]=0
    else:
        abl[j]=i+1
j=0
bcl=[0]*n
k=0
for j in range(n):
    if k==n:
        bcl[j]=0
        continue
    while cl[k]<=bl[j]:
        k+=1
        if k==n:
            break
    if k==n:
        bcl[j]=0
    else:
        bcl[j]=(n-k)
ans=0
for s in range(n):
    ans+=abl[s]*bcl[s]
print(ans)
# Original solution
def main():
    from bisect import bisect_left
    n, *abc = list(map(int, open(0).read().split()))
    a, b, c = abc[:n], abc[n:2 * n], abc[2 * n:]
    a, b, c = sorted(a), sorted(b), sorted(c)
    ans = 0
    for i in c:
        j = bisect_left(b, i)
        for k in b[:j]:
            l = bisect_left(a, k)
            ans += l

    print(ans)


if __name__ == '__main__':
    main()


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

    print(ans)


if __name__ == '__main__':
    main()
# Original solution
n=int(eval(input()))
a=list(map(int,input().split()))
b=list(map(int,input().split()))
c=list(map(int,input().split()))
a.sort()
b.sort()
c.sort()
AtoB=[0 for i in range(n)]
BtoC=[0 for i in range(n+1)]
for i in range(n):
  top=a[i]
  h=n
  l=-1
  while h-l>1:
    mid=(h+l)//2
    if b[mid]>top:
      h=mid
    else:
      l=mid
  if h==0 and top>b[0]:
    h=-1
  AtoB[i]=h #smallestB-index
for i in range(n-1,-1,-1):
  top=b[i]
  h=n
  l=-1
  while h-l>1:
    mid=(h+l)//2
    if c[mid]>top:
      h=mid
    else:
      l=mid
  BtoC[i]+=BtoC[i+1]+n-h #according to B,C patten
ans=0
for i in range(n):
  ans+=BtoC[AtoB[i]]
print(ans)

# Optimized solution
n=int(eval(input()))
a=list(map(int,input().split()))
b=list(map(int,input().split()))
c=list(map(int,input().split()))
a.sort()
b.sort()
c.sort()
ans=0
for i in range(n):
  middle=b[i]
  h=n
  l=-1
  while h-l>1:
    m=(h+l)//2
    if a[m]<middle:
      l=m
    else:
      h=m
  ab=l+1
  h=n
  l=-1
  while h-l>1:
    m=(h+l)//2
    if c[m]>middle:
      h=m
    else:
      l=m
  bc=n-h
  ans+=ab*bc
print(ans)
# Original solution
N = int(eval(input()))
a = []
for i in range(3):
    a.append(list(map(int, input().split())))

for i in range(3):
    a[i].sort()

dataa = []
datab = []
memo = 0
for i in range(N):
    flag = 0
    for j in range(memo, N):
        if a[0][i] < a[1][j]:
            memo = j
            dataa.append(N - j)
            flag = 1
            break
    if flag == 0:
        dataa.append(0)
memo = 0
for i in range(N):
    flag = 0
    for j in range(memo, N):
        if a[1][i] < a[2][j]:
            memo = j
            datab.append(N - j)
            flag = 1
            break
    if flag == 0:
        datab.append(0)
ruiseki = []
count = 0
for i in range(len(datab)-1, -1, -1):
    count += datab[i]
    ruiseki.append(count)
count2 = 0
for i in range(len(dataa)):
    if dataa[i] != 0:
        count2 += ruiseki[dataa[i] - 1]



print(count2)


# Optimized solution
N = int(eval(input()))
a = []
for i in range(3):
    a.append(list(map(int, input().split())))

for i in range(3):
    a[i].sort()

dataa = []
datab = []
memo = 0
#print(a)
for i in range(N):
    flag = 0
    for j in range(memo, N):
        #print(a[0][i], a[1][j])
        if a[0][i] < a[1][j]:
            memo = j
            dataa.append(N - j)
            flag = 1
            break
    if flag == 0:
        for j in range(N - i):
            dataa.append(0)
        break
memo = 0
for i in range(N):
    flag = 0
    for j in range(memo, N):
        if a[1][i] < a[2][j]:
            memo = j
            datab.append(N - j)
            flag = 1
            break
    if flag == 0:
        for j in range(N - i):
            datab.append(0)
        break
ruiseki = []
count = 0
for i in range(len(datab)-1, -1, -1):
    count += datab[i]
    ruiseki.append(count)
count2 = 0
for i in range(len(dataa)):
    if dataa[i] != 0:
        count2 += ruiseki[dataa[i] - 1]



print(count2)
# Original solution
import bisect

num = int(eval(input()))
top = sorted([int(x) for x in input().split()])
middle = sorted([int(x) for x in input().split()])
bottom = sorted([int(x) for x in input().split()])


res = 0
for i in top:
    index = bisect.bisect_right(middle, i)
    if index != len(middle):
        for j in middle[index:]:
            index2 = bisect.bisect_right(bottom, j)
            if index2 != len(bottom):
                res += len(bottom) - index2
print(res)

# Optimized solution
import bisect

num = int(eval(input()))
top = sorted([int(x) for x in input().split()])
middle = sorted([int(x) for x in input().split()])
bottom = sorted([int(x) for x in input().split()])


# middleの配列でループを回したほうが早い(topとbottomを同時に処理できるため)
res = 0
for i in middle:
    index = bisect.bisect_left(top, i)
    index2 = len(bottom)-bisect.bisect_right(bottom, i)
    res += index*index2

print(res)
# Original solution
import bisect

n = int(eval(input()))

a = sorted([int(x) for x in input().split()])
b = sorted([int(x) for x in input().split()])
c = sorted([int(x) for x in input().split()])

res = 0
for cc in c:
    b_res = bisect.bisect_left(b, cc)
    for bb in b[:b_res]:
        res += (bisect.bisect_left(a, bb))

print(res)

# Optimized solution
import bisect

n = int(eval(input()))

a = sorted([int(x) for x in input().split()])
b = sorted([int(x) for x in input().split()])
c = sorted([int(x) for x in input().split()])

res = 0
for bb in b:
    b_res = bisect.bisect_left(a, bb)
    c_res = len(c) - bisect.bisect_right(c, bb)
    res += (b_res*c_res)

print(res)
# Original solution
# C - Snuke Festival

N = int(eval(input()))
A = list(int(x) for x in input().split())
B = list(int(x) for x in input().split())
C = list(int(x) for x in input().split())

B.sort()
C.sort()

def binarySearch(a, b):
    l = -1
    r = N
    while l+1<r:
        m = (l+r)//2
        if a[m]<=b:
            l = m
        else:
            r = m
    return l+1

BC = []
for i in range(N):
    tmp = binarySearch(C, B[i])
    BC.append((N - tmp))

BC = BC[::-1]
BC2 = [0] * (N+1)
for i in range(N):
    BC2[i+1] = BC2[i] + BC[i]
BC2 = BC2[::-1]

ans = 0
for i in range(N):
    b = binarySearch(B, A[i])
    ans += BC2[b]

print(ans)

# Optimized solution
# C - Snuke Festival

N = int(eval(input()))
A = list(int(x) for x in input().split())
B = list(int(x) for x in input().split())
C = list(int(x) for x in input().split())

A.sort()
C.sort()

def binarySearchLeft(a, b):
    l = -1
    r = N
    while l+1<r:
        m = (l+r)//2
        if a[m]<b:
            l = m
        else:
            r = m
    return r

def binarySearchRight(a, b):
    l = -1
    r = N
    while l+1<r:
        m = (l+r)//2
        if a[m]<=b:
            l = m
        else:
            r = m
    return r

ans = 0
for j in range(N):
    ans += binarySearchLeft(A, B[j]) * (N - binarySearchRight(C, B[j]))

print(ans)
# Original solution
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
from bisect import bisect_left


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

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

    result = 0
    for c in C:
        index_c_b = bisect_left(B, c)
        for b in B[:index_c_b]:
            result += bisect_left(A, b)

    print(result)


if __name__ == "__main__":
    main()


# Optimized solution
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
from bisect import bisect_left, bisect_right


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

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

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

    print(result)


if __name__ == "__main__":
    main()
# Original solution
n=int(eval(input()))
a=list(map(int,input().split()))
b=list(map(int,input().split()))
c=list(map(int,input().split()))
ans=[]
ans_2=[]
for i in range(n):
    cnt=0
    for j in range(n):
        if a[j]<b[i]:
            cnt+=1
    ans.append(cnt)
for i in range(n):
    cnt_2=0
    for j in range(n):
        if b[i]<c[j]:
            cnt_2+=1
    ans_2.append(cnt_2)
num=0
for i in range(n):
    num+=ans[i]*ans_2[i]
print(num)


# Optimized solution
n=int(eval(input()))
a=list(map(int,input().split()))
b=list(map(int,input().split()))
c=list(map(int,input().split()))
import bisect
a.sort()
c.sort()
cl=len(c)
cnt=0
for i in b:
    x=bisect.bisect_left(a,i)
    y=bisect.bisect_right(c,i)
    cnt+=x*(cl-y)
print(cnt)
# Original solution
n=int(eval(input()))
a=list(map(int,input().split()))
b=list(map(int,input().split()))
c=list(map(int,input().split()))
import bisect
a.sort()
c.sort()
cl=len(c)
cnt=0
for i in b:
    x=bisect.bisect_left(a,i)
    y=bisect.bisect_right(c,i)
    cnt+=x*(cl-y)
print(cnt)
    


# Optimized solution
n=int(eval(input()))
a=list(map(int,input().split()))
b=list(map(int,input().split()))
c=list(map(int,input().split()))
import bisect
a.sort()
b.sort()
c.sort()
ans=0
for i in range(n):
    ans+=bisect.bisect_left(a,b[i])*(n-bisect.bisect_right(c,b[i]))
print(ans)
# Original solution
n=int(eval(input()))
a=list(map(int,input().split()))
b=list(map(int,input().split()))
c=list(map(int,input().split()))
import bisect
a.sort()
b.sort()
c.sort()
ans=0
for i in range(n):
    ans+=bisect.bisect_left(a,b[i])*(n-bisect.bisect_right(c,b[i]))
print(ans)


# Optimized solution
n=int(eval(input()))
a=list(map(int,input().split()))
b=list(map(int,input().split()))
c=list(map(int,input().split()))
import bisect
ans=0
a.sort()
b.sort()
c.sort()
for i in range(n):
    lift=bisect.bisect_left(a,b[i])
    right=bisect.bisect_right(c,b[i])
    right=n-right
    ans+=lift*right
print(ans)
# Original solution
n = int(eval(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 a:
    comb = 1
    index = bisect.bisect_right(b,i)
    for j in b[index:]:
        ans += n-bisect.bisect_right(c,j)
print(ans)

# Optimized solution
n = int(eval(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)
# Original solution
N = int(eval(input()))
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))

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

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

i, j, k = 0, 0, 0
count = 0
total = []
result = 0

while i < N:
    while C[i] > B[j] and j < N:
        while B[j] > A[k] and k < N:
            count += 1
            k += 1
        total.append(count)
        j += 1
    result += sum(total)
    i += 1

print(result)

# Optimized solution
N = int(eval(input()))
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))

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

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

i, j, k = 0, 0, 0
count = 0
total = 0
result = 0

while i < N:
    while C[i] > B[j] and j < N:
        while B[j] > A[k] and k < N:
            count += 1
            k += 1
        total += count
        j += 1
    result += total
    i += 1

print(result)
# Original solution
N = int(eval(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()

def binsearch(threshold, lst):
    left, right = -1, len(lst)
    while right - left > 1:
        mid = (left + right) // 2
        if lst[mid] > threshold:
            right = mid
        else:
            left = mid
    return right

ans = 0
for a in A:
    b_min_index = binsearch(a, B)
    for i in range(b_min_index, N):
        c_min_index = binsearch(B[i], C)
        ans += N - c_min_index
        #print(a, B[b_min_index], C[c_min_index])
print(ans)


# Optimized solution
N = int(eval(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()

def binsearch(threshold, lst):
    left, right = -1, len(lst)
    while right - left > 1:
        mid = (left + right) // 2
        if lst[mid] > threshold:
            right = mid
        else:
            left = mid
    return right

ans = 0

BtoC = [None] * N
for i in range(0, N):
    BtoC[i] = N - binsearch(B[i], C)
#print(BtoC)

cumulative=[0]
for i in range(N):
    cumulative.append(cumulative[i] + BtoC[N-i-1])
#print(cumulative)
cumulative.reverse()
#print(cumulative)

for j in range(0, N):
    temp = binsearch(A[j], B)
    ans += cumulative[temp]

print(ans)
# Original solution
n = int(eval(input()))
a = list(map(int,input().split()))
b = list(map(int,input().split()))
c = list(map(int,input().split()))
t = 0
ans = 0
u =[0]*n
d =[0]*n
for i in range(n):
    for j in range(n):
        if b[i]>a[j]:
            t+=1
    u[i]=t
    t=0
for i in range(n):
    for j in range(n):
        if b[i]<c[j]:
            t+=1
    d[i]=t
    t=0
for i in range(n):
    ans+=u[i]*d[i]
print(ans)


# Optimized solution
n = int(eval(input()))
a = list(map(int,input().split()))
b = list(map(int,input().split()))
c = list(map(int,input().split()))
t = 0
ans = 0
u =[0]*n
d =[0]*n
a2 =[]
b2 =[]
c2 =[]

for i in range(n):
    a2.append([2,a[i]])
for i in range(n):
    b2.append([1,b[i]])
for i in range(n):
    c2.append([0,c[i]])
a2b2=a2+b2
b2c2=b2+c2

a2b2.sort(key = lambda x:(x[1],x[0]))
b2c2.sort(key = lambda x:(x[1],x[0]),reverse=True)

j=0
c=0
for i in range(2*n):
    if a2b2[i][0]==2:
        c+=1
    if a2b2[i][0]==1:
        u[j]=c
        j+=1
j=0
c=0
for i in range(2*n):
    if b2c2[i][0]==0:
        c+=1
    if b2c2[i][0]==1:
        d[j]=c
        j+=1
d.reverse()
for i in range(n):
    ans+=u[i]*d[i]
print(ans)
# Original solution
n = int(eval(input()))
a = list(map(int,input().split()))
b = list(map(int,input().split()))
c = list(map(int,input().split()))
t = 0
ans = 0
u =[0]*n
d =[0]*n
a2 =[]
b2 =[]
c2 =[]

for i in range(n):
    a2.append([2,a[i]])
for i in range(n):
    b2.append([1,b[i]])
for i in range(n):
    c2.append([0,c[i]])
a2b2=a2+b2
b2c2=b2+c2

a2b2.sort(key = lambda x:(x[1],x[0]))
b2c2.sort(key = lambda x:(x[1],x[0]),reverse=True)

j=0
c=0
for i in range(2*n):
    if a2b2[i][0]==2:
        c+=1
    if a2b2[i][0]==1:
        u[j]=c
        j+=1
j=0
c=0
for i in range(2*n):
    if b2c2[i][0]==0:
        c+=1
    if b2c2[i][0]==1:
        d[j]=c
        j+=1
d.reverse()
for i in range(n):
    ans+=u[i]*d[i]
print(ans)


# Optimized solution
n = int(eval(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()

def n_smaller_a(num):
    if num>a[n-1]:
        return n
    if num<=a[0]:
        return 0
    left=0
    right=n-1
    mid=(left+right)//2
    while right-left>1:
        if a[mid]>=num:
            right=mid
        else:
            left=mid
        mid=(left+right)//2

    if a[left]==num:
        return left
    else:
        return left+1

def n_bigger_c(num):
    if num >= c[n-1]:
        return 0
    if num < c[0]:
        return n
    left=0
    right=n-1
    mid=(left+right)//2
    while right-left>1:
        if c[mid]>num:
            right=mid
        else:
            left=mid
        mid=(left+right)//2
    if c[right]==num:
        return n-right-1
    else:
        return n-right

ans = 0

for i in range(n):
    ans+=n_bigger_c(b[i])*n_smaller_a(b[i])
print(ans)
# Original solution
n = int(eval(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)

total = 0
for alnum in al:
    truebl = [blnum for blnum in bl if blnum > alnum]
    for blnum in truebl:
        total += sum(clnum>blnum for clnum in cl)
print(total)

# Optimized solution
# C
import bisect
n = int(eval(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)

total = 0
for blnum in bl:
    alcnt = bisect.bisect_left(al, blnum)
    clcnt = n - bisect.bisect_right(cl, blnum)
    total += alcnt*clcnt
print(total)
# Original solution
from bisect import bisect_right,bisect_left
n=int(eval(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):
  na=bisect_left(a,b[i])
  nc=bisect_right(c,b[i])
  ans+=na*(n-nc)
print(ans)

# Optimized solution
from bisect import bisect_left,bisect_right
n=int(eval(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):
  indea=bisect_left(a,b[i])
  indec=bisect_right(c,b[i])
  ans+=indea*(n-indec)
print(ans)
# Original solution
import bisect
N = int(eval(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 a in A:
    b = bisect.bisect_left(B,a+1)
    if b == N:
        continue
    for i in range(b,N):
        c = bisect.bisect_left(C,B[i]+1)
        if c == N:
            continue
        count += N-c
print(count)

# Optimized solution
import bisect
N = int(eval(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 b in B:
    a = bisect.bisect_left(A,b)
    c = bisect.bisect_right(C,b)
    count += a*(N-c)
print(count)
# Original solution
import bisect as bi
def main():
  from builtins import input, int, map
  N = int(eval(input()))
  A = list(map(int,input().split()))
  B = list(map(int,input().split()))
  C = list(map(int,input().split()))
  A.sort()
  C.sort()

  ans = 0

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


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

  ans = 0

  for i in range(N):
    a = bi.bisect_left(A,B[i])
    c = N-bi.bisect_right(C,B[i])
    ans += a*c
  print(ans)
main()
# Original solution
def low_left(ls,key):
    left,right = -1,len(ls)
    while right - left > 1:
        mid = (right+left)//2
        if ls[mid] >= key:
            right = mid
        else:
            left = mid
    return len(ls[:(left+1)])


def high_right(ls,key):
    left,right = -1,len(ls)
    while right - left > 1:
        mid = (right+left)//2
        if ls[mid]<=key:
            left = mid
        else:
            right = mid
    return len(ls[right:])


def test():
    n = int(eval(input()))
    A,B,C = [list(sorted(map(int,input().split()))) for i in range(3)]
    ans = 0

    for b in B:
        ans += high_right(C,b)*low_left(A,b)
    print(ans)


if __name__ == "__main__":
    test()


# Optimized solution
def low_left(ls,key):
    left,right = -1,len(ls)
    while right - left > 1:
        mid = (right+left)//2
        if ls[mid] >= key:
            right = mid
        else:
            left = mid
    return left+1


def high_right(ls,key):
    left,right = -1,len(ls)
    while right - left > 1:
        mid = (right+left)//2
        if ls[mid]<=key:
            left = mid
        else:
            right = mid
    return right


def test():
    n = int(eval(input()))
    A,B,C = [list(sorted((list(map(int,input().split()))))) for i in range(3)]
    ans = 0

    for b in B:
        ans += (n-high_right(C,b))*low_left(A,b)
    print(ans)


if __name__ == "__main__":
    test()
# Original solution
from bisect import bisect_right

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

B.sort()
C.sort()
ans = 0
for a in A:
    b_index = bisect_right(B, a)
    if b_index == len(B):
        continue
    b_cnt = len(B)-b_index

    for b in B[b_index:]:
        c_index = bisect_right(C, b)
        if c_index == len(C):
            continue
        c_cnt = len(C)-c_index

        ans += c_cnt
print(ans)


# Optimized solution
import bisect

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

A.sort()
C.sort()
ans = 0
for i in range(N):
    a_cnt = bisect.bisect_left(A, B[i])
    c_cnt = N-bisect.bisect_right(C, B[i])
    ans += a_cnt*c_cnt
print(ans)
# Original solution
import bisect
import itertools
n = int(eval(input()))
a = list(map(int,input().split()))
b = list(map(int,input().split()))
c = list(map(int,input().split()))
count = 0
#for i in range(n):
  #for s in range(bisect.bisect_right(b, a[i]),n):
    #count += n-bisect.bisect_right(c, b[s])
for i in itertools.product(a, b, c):
  if i[0] < i[1] < i[2]:
    count += 1
print(count)

# Optimized solution
n=int(eval(input()))
a=list(map(int,input().split()))
b=list(map(int,input().split()))
c=list(map(int,input().split()))
a.sort()
b.sort()
c.sort()

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