CodeEff/ECCO huggingface dataset:
# Original solution
n = eval(input())
top = list(map(int, input().split()))
top.sort()
middle = list(map(int, input().split()))
middle.sort()
under = list(map(int, input().split()))
under.sort()
cnt = 0
for i in top[::-1]:
    for j in middle[::-1]:
        if j <= i: break
        for k in under[::-1]:
            if k <= j: break
            cnt += 1
            # print '{} {} {}'.format(i,j,k)

print(cnt)

# Optimized solution
# coding:utf-8

INF = float('inf')


def inpl(): return list(map(int, input().split()))


N = int(eval(input()))
A = sorted(inpl())
B = sorted(inpl())
C = sorted(inpl())

ans = 0
i_a = 0
i_c = 0
for i_b in range(N):
    while i_a < N and A[i_a] < B[i_b]:
        i_a += 1
    while i_c < N and C[i_c] <= B[i_b]:
        i_c += 1

    ans += i_a * (N - i_c)

print(ans)
# Original solution
import bisect

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

ans = 0
for _c in c:
    i = bisect.bisect_left(b, _c)
    for j in range(i):
        ans += bisect.bisect_left(a, b[j])

print(ans)


# Optimized solution
import bisect

n = int(eval(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:
    aNum = bisect.bisect_left(a, _b)
    cNum = len(c) - bisect.bisect_right(c, _b)
    ans += aNum*cNum

print(ans)
# Original solution
import bisect

n = int(eval(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:
    aNum = bisect.bisect_left(a, _b)
    cNum = len(c) - bisect.bisect_right(c, _b)
    ans += aNum*cNum

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

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

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

ans = 0
for i in range(n):
    a = A[i]
    for b in B[bisect.bisect_right(B, a):]:
        ans += len(C[bisect.bisect_right(C, b):])
print(ans)

# Optimized solution
import bisect, itertools

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

c_num = [0]*n
for i in range(n):
    c_num[i] = n - bisect.bisect_right(C, B[i])
c_accum = [0] + list(itertools.accumulate(c_num))

ans = 0
for i in range(n):
    b_index = bisect.bisect_right(B, A[i])
    ans += (c_accum[-1] - c_accum[b_index])
print(ans)
# Original solution
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()

    cnt = 0
    for a in A:
        for b in B:
            if a >= b:
                continue
            for c in C:
                if b >= c:
                    continue
                cnt += 1
    print(cnt) 

if __name__ == '__main__':
    main()

# Optimized solution
#!/usr/bin/env python

import bisect

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

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

if __name__ == '__main__':
    main()
# Original solution
# ABC_077_C_Sunuke_Festival.py

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

# B[j]を固定してA[i]<=B[j]<=C[k]を満たす(i,j)の個数を求める
# ソートして二分探索すれば間に合う
A.sort()
# B.sort()
C.sort()
# print(A)
# print(B)
# print(C)


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)
    # print(cti, ctk)
    ans += cti*ctk
print(ans)


# Optimized solution
from bisect import bisect_right, bisect_left
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):
  s=b[i]
  k=bisect_left(a,s)*(N-bisect_right(c,s))
  ans+=k
print(ans)
# Original solution
import bisect
from itertools import accumulate
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
b_to_c = [0]*n
for i in range(n):
  b_to_c[i] = n - bisect.bisect_right(C, B[i])
Q = list(accumulate(b_to_c[::-1]))[::-1]
  
for i in A:
  t = bisect.bisect_right(B, i)
  if t < n:
    ans += Q[t]
print(ans)

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


#A2 = sorted(A)
#B2 = sorted(B)
#C2 = sorted(C)


def numadd(up, down):
    array = []
    count = 0
    last = 0
    for i in range(0,N):
        while down[i] > up[count]:
            count = count + 1
            if count == N:
                count = count - 1
                last = 1
                break
        array.append(count + last)
    return array

B3 = numadd(sorted(A),sorted(B))
C3 = numadd(sorted(B),sorted(C))

B4 = [B3[0]]
for i in range(0,N-1):
    B4.append(B4[i] + B3[i+1])

ans = 0
for i in range (0,N):
    if C3[i] > 0:
        ans = ans + B4[C3[i]-1]

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


A2 = sorted(A)
B2 = sorted(B)
C2 = sorted(C)

A2.append(2000000000)
B2.append(2000000000)

def numadd(up, down):
    array = []
    count = 0
    for i in range(0,N):
        while down[i] > up[count]:
            count = count + 1
            
        array.append(count) #+ last)
    return array

B3 = numadd(A2,B2)
C3 = numadd(B2,C2)

B4 = [B3[0]]
for i in range(0,N-1):
    B4.append(B4[i] + B3[i+1])

ans = 0
for i in range (0,N):
    if C3[i] > 0:
        ans = ans + B4[C3[i]-1]

print(ans)
# Original solution
import bisect
n = int(eval(input()))
a,b,c = [sorted(map(int,input().split())) for _ in "abc"]
print((sum([bisect.bisect_left(a,x)*(n-bisect.bisect_right(c,x)) for x in b])))

# Optimized solution
from bisect import *
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())))
print((sum(bisect_left(A,b)*(N-bisect_right(C,b)) for b in B)))
# Original solution
#-*-coding:utf-8-*-
import bisect

def main():

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

    cnt = 0
    
    for i in range(n):
        for j in range(n):
            if a_list[i] < b_list[j]:
                position = bisect.bisect_right(c_list, b_list[j])
                cnt += n - position
    
    print(cnt)
    

if __name__ == '__main__':
    main()

# Optimized solution
#-*-coding:utf-8-*-
import bisect

def main():

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

    cnt = 0
    
    for b in b_list:
        i = bisect.bisect_left(a_list, b)
        j = n - bisect.bisect_right(c_list, b)
        cnt += i * j
    
    print(cnt)
    
if __name__ == '__main__':
    main()
# Original 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 b in B:
    ai = bisect.bisect_left(A,b)
    ci = bisect.bisect(C,b)
    ans += ai*(N-ci)
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 b in B:
    ai = bisect.bisect_left(A, b)
    ci = bisect.bisect_right(C, b)
    ans += ai * (N-ci)
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())))
a_n = [0] * n
b_n = [0] * n
for i in range(n):
    a_n[i] = bisect.bisect_right(b, a[i])
for i in range(n):
    b_n[i] = n - bisect.bisect_right(c, b[i])
ans = 0
for i in a_n:
    ans += sum(b_n[i:])
print(ans)

# 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())))
a_n = [0] * n
b_n = [0] * n
for i in range(n):
    a_n[i] = bisect.bisect_right(b, a[i])
for i in range(n):
    b_n[i] = n - bisect.bisect_right(c, b[i])
ans = 0
b_n_t = [0]
for i in range(n):
    b_n_t.append(b_n[i] + b_n_t[i])
for i in a_n:
    ans += b_n_t[-1] - b_n_t[i]
print(ans)
# Original solution
# -*- coding: utf-8 -*-
"""
https://beta.atcoder.jp/contests/abc077/tasks/arc084_a

"""
import sys
from sys import stdin
from bisect import bisect_left, bisect_right
from functools import lru_cache
input = stdin.readline


@lru_cache(maxsize=None)
def calc(i):
    ans = 0
    for b in B[i:]:
        j = lut_B[b]
        if j == N:
            break
        ans += (N - j)
    return ans


lut_B = {}
B = []
N = 0
def main(args):
    global lut_B
    global B
    global N
    N = int(eval(input()))
    A = [int(x) for x in input().split()]
    B = [int(x) for x in input().split()]
    C = [int(x) for x in input().split()]
    A.sort()
    B.sort()
    C.sort()

    lut_A = {a:bisect_right(B, a) for a in A}
    lut_B = {b:bisect_right(C, b) for b in B}

    ans = 0
    for a in A:
        i = lut_A[a]
        if i == N:
            break
        ans += calc(i)

    print(ans)


if __name__ == '__main__':
    main(sys.argv[1:])


# Optimized solution
# -*- coding: utf-8 -*-
"""
https://beta.atcoder.jp/contests/abc077/tasks/arc084_a

"""
import sys
from sys import stdin
from bisect import bisect_left, bisect_right
input = stdin.readline


def main(args):
    N = int(eval(input()))
    A = [int(x) for x in input().split()]
    B = [int(x) for x in input().split()]
    C = [int(x) for x in input().split()]
    A.sort()
    B.sort()
    C.sort()

    lut_A = {}
    lut_C = {}
    for b in B:
        i = bisect_left(A, b)
        lut_A[b] = i
        j = bisect_right(C, b)
        lut_C[b] = N - j


    ans = 0
    for b in B:
        i = lut_A[b]
        j = lut_C[b]
        ans += i * j

    print(ans)


if __name__ == '__main__':
    main(sys.argv[1:])
# 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())))

cnt = 0


for b in B :
    a_cnt = len(A[:bisect.bisect_left(A,b)])
    c_cnt = len(C[bisect.bisect_right(C,b):])
    cnt += a_cnt * c_cnt
    
print(cnt)

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

cnt = 0


for j in range(n) :
    a = bisect.bisect_left(A,B[j])
    c = bisect.bisect_right(C,B[j])
    cnt += a * (n-c)
    
print(cnt)
# Original 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()
b.sort()
c.sort()


count = 0

for i in range(n):
    x = a[i] + 1
    index1 = bisect.bisect_left(b, x)
    if index1 >= n:
        break
    b_tmp = b[index1:]
    for j in b_tmp:
        y = j + 1
        index2 = bisect.bisect_left(c, y)
        if index2 >= n:
            break
        c_tmp = c[index2:]
        count += len(c_tmp)


print(count)



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

count = 0

for i in b:
    x = bisect.bisect_left(a, i)
    y = bisect.bisect_right(c, i)
    count += x * (len(c) - y)

print(count)
# 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())))

ans=0
for a in A:
    for i in range(len(B)):
        if a < B[i]:
            for j in range(len(C)):
                if B[i] < C[j]:
                    ans += len(C)-j
                    break    

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

print(ans)
# Original solution
N = int(eval(input()))
A = sorted(map(int, input().split()))
B = list(map(int, input().split()))
C = sorted(map(int, input().split()), reverse=True)

counts = 0
checked = {}
for _numB in B:
    if _numB in checked:
        counts += checked[_numB]
    else:
        countsA = 0
        for _numA in A:
            if (_numB > _numA):
                countsA += 1
            else:
                break
        countsC = 0
        for _numC in C:
            if (_numC > _numB):
                countsC += 1
            else:
                break
        checked[_numB] = countsA * countsC
        counts += countsA * countsC
print(counts)


# Optimized solution
import bisect

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

counts = 0
checked = {}
for _numB in B:
    if _numB not in checked:
        countsA = bisect.bisect_left(A, _numB)
        countsC = bisect.bisect_right(C, _numB)
        checked[_numB] = countsA * (N - countsC)
    counts += checked[_numB]
print(counts)
# Original solution
n=int(eval(input()))
lists1=sorted(list(map(int,input().split())))
lists2=sorted(list(map(int,input().split())))
lists3=sorted(list(map(int,input().split())),reverse=True)
lists_small=[]
lists_big=[]
for x in lists2:
    numbers=0
    for y in lists1:
        if y<x:
            numbers+=1
            if numbers==n:
                lists_small.append(numbers)
                break
            else:
                continue
        else:
            lists_small.append(numbers)
            break

for z in lists2:
    numbers=0
    for w in lists3:
        if w>z:
            numbers+=1
            if numbers==n:
                lists_big.append(numbers)
                break
            else:
                continue
        else:
            lists_big.append(numbers)
            break

ans=0
for _ in range(n):
    ans+=lists_small[_]*lists_big[_]
print(ans)
    

# Optimized solution
n=int(eval(input()))
lists1=sorted(list(map(int,input().split())))+[10**9+1]

lists2=sorted(list(map(int,input().split())))+[10**9+2]
lists3=sorted(list(map(int,input().split())))+[10**9+3]
lists_small=[0]*(n+1)
lists_big=[0]*(n+1)

numbers=0
for x in range(n):
    while lists1[numbers]<lists2[x]:
        numbers+=1
    lists_small[x]=numbers


numberss=0
for y in range(n):
    while lists3[numberss]<=lists2[y]:
        numberss+=1
    changes=n-numberss
    lists_big[y]=changes



ans=0
for xy in range(n):
    ans+=lists_big[xy]*lists_small[xy]
print(ans)
# Original solution
def lma():return list(map(int, input().split()))#x or y

a = int(eval(input()))
k=[]
s=[]
co=[0]*a*3
c=0
s= [lma()]
x2= lma()
x3 = lma()
s.append(x2)
s.append(x3)
res =0
for j in range(3):
    for i in range(a):
        k.append([j,s[j][i]])
k.sort(key=lambda x: x[1], reverse=True)
for i in range(a*3):
    if k[i][0] == 2:
       c+=1
    elif k[i][0] == 1:
       co[i] = c
    else:
       res+=sum(co[:i])
print(res)
       

# Optimized solution
def lma():return list(map(int, input().split()))#x or y
a = int(eval(input()))
k=[]
s=[]
c=0
s= [lma()]
x2= lma()
x3 = lma()
s.append(x2)
s.append(x3)
res =0
r =0
for j in range(3):
    for i in range(a):
        k.append([j,s[j][i]])
k.sort(key=lambda x: x[1], reverse=True)
for i in range(a*3):
    if k[i][0] == 2:
       c+=1
    elif k[i][0] == 1:
       r+=c 
    else:
       #res+=sum(co[:i])
        res+=r
print(res)
# Original solution

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


# Optimized solution
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()
# Original solution


N = int(input())
As = input().split(" ")
Bs = input().split(" ")
Cs = input().split(" ")

As = [(int(i), 2) for i in As]
Bs = [(int(i), 1) for i in Bs]
Cs = [(int(i), 0) for i in Cs]

l = sorted(As + Bs + Cs, key=lambda x: x[0] + x[1] * 0.1)

ac = 0
bc = 0
cc = 0

for i in l:
    if i[1] == 2:
        ac += 1
    elif i[1] == 1:
        bc += ac
    elif i[1] == 0:
        cc += bc
print(cc)

# Optimized solution


N = int(input())
As = [(int(i), 2) for i in input().split(" ")]
Bs = [(int(i), 1) for i in input().split(" ")]
Cs = [(int(i), 0) for i in input().split(" ")]

l = sorted(As + Bs + Cs, key=lambda x: x[0] + x[1] * 0.1)

ac = 0
bc = 0
cc = 0

for i in l:
    if i[1] == 2:
        ac += 1
    elif i[1] == 1:
        bc += ac
    elif i[1] == 0:
        cc += bc
print(cc)
# Original solution


N = int(input())
As = [(int(i), 2) for i in input().split(" ")]
Bs = [(int(i), 1) for i in input().split(" ")]
Cs = [(int(i), 0) for i in input().split(" ")]

l = sorted(As + Bs + Cs, key=lambda x: x[0] + x[1] * 0.1)

ac = 0
bc = 0
cc = 0

for i in l:
    if i[1] == 2:
        ac += 1
    elif i[1] == 1:
        bc += ac
    elif i[1] == 0:
        cc += bc
print(cc)

# Optimized solution


N = int(input())
As = [(int(i), 2) for i in input().split(" ")]
Bs = [(int(i), 1) for i in input().split(" ")]
Cs = [(int(i), 0) for i in input().split(" ")]

l = sorted(As + Bs + Cs)

ac = 0
bc = 0
cc = 0

for i in l:
    if i[1] == 2:
        ac += 1
    elif i[1] == 1:
        bc += ac
    elif i[1] == 0:
        cc += bc
print(cc)
# 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())))
d = [-1] * n
ansum = 0
def stat(array,par):
    return bisect.bisect(array,par)

for i in range(n):
    indexC = stat(c,b[i])
    d[i] = max(0,n-indexC) 
for i in range(n-1):
    d[n-i-2] += d[n-i-1]
for A in a:
    index = stat(b,A)
    if index < n:
        ansum += d[index]
print(ansum)


# 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())))
ansum = 0
for B in b:
    index = bisect.bisect_left(a,B)
    index2= bisect.bisect_right(c,B)
    ansum += index*(n-index2)
print(ansum)
# Original 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()))

count = 0
a1 = sorted(a)
b1 = sorted(b)
c1 = sorted(c)
for i in c1:
    prior_c = bisect.bisect_left(b1,i)
    prior_c_list = b1[:prior_c]
    for j in prior_c_list:
        count += bisect.bisect_left(a1,j)

print(count)

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

a1 = sorted(a)
c1 = sorted(c)
count = 0

for i in b:
    count += bisect.bisect_left(a1,i) * (n - bisect.bisect_right(c1,i))
    
print(count)
# 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())))
ans = 0
import bisect
for i in A:
    a = bisect.bisect_right(B,i)
    for j in range(a,N):
        b = bisect.bisect_right(C,B[j])
        ans += N-b
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())))
ans = 0
import bisect
b = []
for i in B:
    x = bisect.bisect_right(C,i)
    b.append(N-x)
y = sum(b)
c = [y]
for i in range(1,N):
    y -= b[i-1]
    c.append(y)
c.append(0)
for i in A:
    a = bisect.bisect_right(B,i)
    ans += c[a]
print(ans)
# Original solution
import bisect
from sys import stdin

N = int(eval(input()))

lines = stdin.readlines

l = [[int(i) for i in line.split()] for line in lines()]

An = l[0]
Bn = l[1]
Cn = l[2]


def main():
    An.sort()
    Cn.sort()

    ans = 0

    for Bi in Bn:
        # 以上
        lx = bisect.bisect_left(An, Bi)

        # より大きい
        ux = bisect.bisect(Cn, Bi)

        ans += lx * (N - ux)

    print(ans)
    return


main()


# Optimized solution
import bisect

N = int(eval(input()))

An = list(map(int, input().split()))
Bn = list(map(int, input().split()))
Cn = list(map(int, input().split()))


def main():
    A = sorted(An)
    C = sorted(Cn)

    ans = 0

    for Bi in Bn:
        # 以上
        lx = bisect.bisect_left(A, Bi)

        # より大きい
        ux = bisect.bisect(C, Bi)

        ans += lx * (N - ux)

    print(ans)
    return


main()
# Original solution
def main():
    from bisect import bisect_left
    from bisect import bisect_right

    N = int(eval(input()))

    An = list(map(int, input().split()))
    Bn = list(map(int, input().split()))
    Cn = list(map(int, input().split()))

    A = sorted(An)
    C = sorted(Cn)

    print((sum(bisect_left(A, Bi) * (N - bisect_right(C, Bi)) for Bi in Bn)))
    return


main()


# Optimized solution
def main():
    from bisect import bisect_left
    from bisect import bisect_right

    N = int(eval(input()))

    An = list(map(int, input().split()))
    Bn = list(map(int, input().split()))
    Cn = list(map(int, input().split()))

    A = sorted(An)
    B = sorted(Bn)
    C = sorted(Cn)

    print((sum([bisect_left(A, Bi) * (N - bisect_right(C, Bi)) for Bi in B])))
    return


main()