CodeEff/ECCO huggingface dataset:
# 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()

ans = 0
for i in range(N):
    up = A[i]
    middleIndex = bisect.bisect(B, up)
    if middleIndex < N:
        for j in range(middleIndex, N):
            middle = B[j]
            lowIndex = bisect.bisect(C, middle)
            if lowIndex < N:
                cnt = N - lowIndex
                ans += cnt

print(ans)


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

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

ans = 0
dp = [0] * N
for i in range(N):
    up = A[i]
    middleIndex = bisect.bisect(B, up)
    if middleIndex < N:
        if i == 0:
            for j in range(middleIndex, N):
                middle = B[j]
                lowIndex = bisect.bisect(C, middle)
                if lowIndex < N:
                    cnt = N - lowIndex
                    dp[j] = cnt
                    ans += cnt
                else:
                    dp[j] = 0
            dp = list(itertools.accumulate(dp[::-1]))
        else:
            ans += dp[-middleIndex-1]

print(ans)
# Original solution
N = int(eval(input()))
A = list(map(int, input().split()))
#A = [int(x) for x in input().split()]
B = list(map(int, input().split()))
C = list(map(int, input().split()))
A.sort()
A = [-float('inf')] + A + [float('inf')]
B.sort()
C.sort()
C = [-float('inf')] + C + [float('inf')]

total = 0

for i in range(N):
    low = 0
    high = N + 1
    while low + 1 < high:
        mid1 = (low + high) // 2
        if A[mid1] < B[i]:
            low = mid1
        else:
            high = mid1
    mid1 = low
    low = 0
    high = N + 1
    while low + 1 < high:
        mid2 = (low + high) // 2
        if C[mid2] <= B[i]:
            low = mid2
        else:
            high = mid2
    mid2 = high
    total = total + mid1 * (N + 1 - mid2)

print(total)

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

total = 0

for i in range(N):
    low1 = 0
    high = N
    while low1 < high:
        mid = (low1 + high) // 2
        if A[mid] < B[i]:
            low1 = mid + 1
        else:
            high = mid
    low2 = 0
    high = N
    while low2 < high:
        mid = (low2 + high) // 2
        if C[mid] <= B[i]:
            low2 = mid + 1
        else:
            high = mid
    total += low1 * (N - low2)

print(total)

# Optimized solution
N = int(eval(input()))
A = sorted([int(i) for i in input().split()])
B = [int(i) for i in input().split()]
C = sorted([int(i)-1 for i in input().split()])

def bis(x,y):
    low = 0
    high = N
    while low < high:
        mid = (low + high) // 2
        if x[mid] < y:
            low = mid + 1
        else:
            high = mid
    return low

total = 0
for b in B:
    total += bis(A,b) * (N - bis(C,b))

print(total)
# Original solution
import bisect
def find_ge(a, x):
    i = bisect.bisect_right(a,x)
    return i
    
def solve(n, a, b, c):

    b_count = [0]*len(b)
    for i, x in enumerate(b):
        b_count[i] = len(c) - find_ge(c, x)

    ans = 0
    for i in a:
        x = find_ge(b, i)
        ans += sum(b_count[x:])
        
    return ans

if __name__ == "__main__":
    n = int(eval(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()])
    print((solve(n, a, b, c)))


# Optimized solution
import bisect
import itertools
def find_ge(a, x):
    i = bisect.bisect_right(a,x)
    return i

def solve(n, a, b, c):

    tmp = len(c)
    b_count =list(itertools.accumulate([tmp - find_ge(c, x) for x in b]))
    ans = 0
    for i in a:
        min_index = find_ge(b, i)
        
        ans += b_count[-1] -(0 if min_index == 0 else b_count[min_index-1])
    
    return ans

if __name__ == "__main__":
    n = int(eval(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()])
    print((solve(n, a, b, c)))
# 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())))

BDP = [-1] * N
ans = 0
for a in A:
    b_idx = bisect.bisect_right(B, a)
    for i in range(b_idx,N):
        if BDP[i] == -1:
            c_idx = bisect.bisect_right(C, B[i])
            BDP[i] = N - c_idx
        ans += BDP[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())))

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

count = 0
for mid in b:
    upper_count = len(list([x for x in a if x<mid]))
    lower_count = len(list([x for x in c if x>mid]))
    count += upper_count * lower_count
print(count)

# Optimized solution
import bisect

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

count = 0
for mid in b:
    upper_count = bisect.bisect_left(a,mid)
    lower_count = len(c) - bisect.bisect_right(c,mid)
    count += upper_count * lower_count
print(count)
# 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()))
b.sort()
c.sort()
ans = 0
for i in range(n):
    pos = 0
    for j in range(bisect.bisect_right(b,a[i]),n):
        while (pos < n and c[pos] <= b[j]):
            pos += 1
        ans += n-pos
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):
    ans += bisect.bisect_left(a,b[i])*(n-bisect.bisect_right(c,b[i]))
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())))
ans = 0
for i in B:
    x, y = 0, 0
    for j in A:
        if j < i:
            x += 1
        else:
            break
    for j in reversed(C):
        if i < j:
            y += 1
        else:
            break
    ans += x * y
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()))
b.append(0)
c.append(0)
a.sort()
b.sort()
c.sort()

def isok(na , index , key):
    if na[index] >= key:
        return True
    else:
        return False
    
def bs(nar,key):
    left = -1
    right = len(nar)
    
    while (right - left) > 1:
        mid = left + (right - left) // 2
        
        if isok(nar , mid , key):
            right = mid
        else:
            left = mid
            
    return right

ans = 0
for i in a:
    q = bs(b,i+1)
    d = b[q:]
    
    for j in d:
        r = bs(c,j+1)
        f = c[r:]
        ans += len(f)
        
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 isok(na , index , key):
    if na[index] >= key:
        return True
    else:
        return False
    
def bs(nar,key):
    left = -1
    right = len(nar)
    
    while (right - left) > 1:
        mid = left + (right - left) // 2
        
        if isok(nar , mid , key):
            right = mid
        else:
            left = mid
            
    return right

ans = 0
for i in b:
    q = bs(a,i)
    r = bs(c,i+1)
    
    ans += q*(n-r)
print(ans)
# Original solution
import sys
def input(): return sys.stdin.readline().rstrip()

def main():
    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:
        sum_v = 1
        l = -1
        r = N
        while r - l > 1:
            m = (l + r) // 2
            if b > A[m]:
                l = m
            else:
                r = m
        sum_v *= l + 1

        l = -1
        r = N
        while r - l > 1:
            m = (l + r) // 2
            if b < C[m]:
                r = m
            else:
                l = m
        sum_v *= N - r
        ans += sum_v
    print(ans)

if __name__ == '__main__':
    main()


# Optimized solution
import sys
import bisect
def input(): return sys.stdin.readline().rstrip()

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

num = 0
for i in range(n):
    for j in range(n):
        for k in range(n):
            if a[i] < b[j] < c[k]:
                num += 1
print(num)

# 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())))
#print(a,b,c)
cnt = 0
for i in range(n):
    d = bisect.bisect_left(a,b[i])
    e = bisect.bisect_right(c,b[i])
    cnt += d*(n-e)
print(cnt)
# Original solution

import sys
import collections
# import math
# import string
# import bisect

def main():
    n, *parts = (int(x) for x in sys.stdin.read().split())
    uppers, middles, lowers = (parts[n*i:n*(i+1)] for i in range(3))

    count = 0
    for a, ca in list(collections.Counter(uppers).items()):
        for b, cb in list(collections.Counter((b for b in middles if b > a)).items()):
            count += ca * cb * len([c for c in lowers if c > b])

    print(count)

if __name__ == "__main__":
    main()


# Optimized solution

import sys
# import collections
# import math
# import string
import bisect

def main():
    n, *parts = (int(x) for x in sys.stdin.read().split())
    uppers, middles, lowers = (parts[n*i:n*(i+1)] for i in range(3))
    uppers.sort()
    lowers.sort()

    count = 0
    for j in middles:
        i = bisect.bisect_left(uppers, j)
        k = len(lowers) - bisect.bisect_right(lowers, j)
        count += i * k
        
    print(count)

if __name__ == "__main__":
    main()
# Original solution
import sys
from bisect import bisect_left as bi_l, bisect_right as bi_r

n = int(sys.stdin.readline().rstrip())
*a, = list(map(int, sys.stdin.readline().split()))
*b, = list(map(int, sys.stdin.readline().split()))
*c, = list(map(int, sys.stdin.readline().split()))

def main():
    a.sort()
    b.sort()
    c.sort()
    res = 0
    for i in b:
        cnt_a = bi_l(a, i)
        cnt_c = n - bi_r(c, i)
        res += cnt_a * cnt_c
 
    return res
    
if __name__ == '__main__':
    ans = main()
    print(ans)

# Optimized solution
import sys
from bisect import bisect_left as bi_l, bisect_right as bi_r

n = int(sys.stdin.readline().rstrip())
a = sorted(map(int, sys.stdin.readline().split()))
b = sorted(map(int, sys.stdin.readline().split()))
c = sorted(map(int, sys.stdin.readline().split()))

def main():
    combs = 0
    for x in b:
        combs += bi_l(a, x) * (n - bi_r(c, x))
    print(combs)

if __name__ ==  '__main__':
    main()
# 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=[0]*N
E=[0]*N
for i in range(N):
    D[i]=N-bisect.bisect_right(C,B[i])
for i in range(N):
    E[i]=sum(D[bisect.bisect_right(B,A[i]):])
print((sum(E)))

# 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 range(N):
    ans+=(bisect.bisect_left(A,B[i]))*(N-bisect.bisect_right(C,B[i]))
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())))
second = []
third = []
ans = 0
for i in range(N):
  second.append(N - bisect.bisect_right(B,A[i]))
  third.append(N - bisect.bisect_right(C,B[i]))
for i in range(0,N):
  if second[i] == 0:
    continue
  ans += sum(third[-second[i]:])
print(ans)

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

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

bika=[0]
cika=[0]
j=0
k=0

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

for i in range(n):
  if j<n:
    while a[j]<b[i]:
      bika[i]+=1
      j+=1
      if j>=n:
        break
  if i!=n-1:
    bika.append(bika[i])

for i in range(n):
  if k<n:
    while b[k]<c[i]:
      cika[i]+=bika[k]
      k+=1
      if k>=n:
        break
  if i!=n-1:
    cika.append(cika[i])
print((sum(cika)))

# 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 b:
  x=bisect.bisect_left(a,i)
  y=n-bisect.bisect_right(c,i)
  ans+=x*y
print(ans)
# Original solution
import copy
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()
p = 0
c.sort()
q = 0
count = 0
x = 0
for i in range(n):
    p = 0
    q = 0
    while p<n:
        if (b[p] > a[i]):
            while q<n:
                if (c[q] > b[p]):
                    count += (n-q)
                    
                    p += 1
                    break
                else:
                    q += 1
        else:
            p += 1
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()
ans = 0
for i in range(n):
    x = bisect.bisect_left(a,b[i])
    y = bisect.bisect_right(c,b[i])
    ans += x*(n-y)
print(ans)
# Original 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()
C.sort()


ans = 0
#Bの中の数iに対して、Aの中でiより小さい数の個数と、Cの中でiより大きい数の個数の積を探索
for i in B:
    ans += bisect_right(A, i-0.1) * (N-bisect_left(C, i+0.1))
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()

# print (A, B ,C)
ans = 0
for i in B:
    # print (i)
    # print (bisect.bisect_left(A, i-0.1))
    ans += bisect.bisect_left(A, i-0.1) * (N-bisect.bisect_right(C, i+0.1))
print (ans)
# Original solution
N = int(eval(input()))


def binary_search(L, target):
    """
    >>> binary_search([1,3,5],2)
    2
    >>> binary_search([1,3,5],5)
    0
    >>> binary_search([1,3,5],9)
    0
    >>> binary_search([1,3,3,3,3,5],3)
    1
    >>> binary_search([1,3,3,3,3,5],4)
    1
    """
    if L[0] > target:
        return len(L)
    if L[-1] <= target:
        return 0
    right_i = len(L) - 1
    left_i = 0
    j = 0
    while left_i + 1 != right_i:
        med_i = (right_i + left_i) // 2
        if L[med_i] < target:
            left_i = med_i
        elif L[med_i] > target:
            right_i = med_i
        else:
            while L[med_i + 1] == target:
                med_i += 1
            return len(L) - med_i - 1
    return len(L) - right_i


D = []
for _ in range(3):
    D.append(list(map(int, input().split())))
A, B, C = D
A = [-a for a in A]
A.sort()
C.sort()
ans = 0

for b in B:
    ans += binary_search(A, -b) * binary_search(C, b)

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 hoge():
    count = 0
    Ai = -1
    Ci = -1
    for i in range(N):
        if Ai < N - 1:
            while A[Ai + 1] < B[i]:
                Ai += 1
                if Ai == N - 1:
                    break
        if Ci < N - 1:
            while C[Ci + 1] <= B[i]:
                Ci += 1
                if Ci == N - 1:
                    break
        count += (Ai + 1) * (N - (Ci + 1))
    return count


print((hoge()))
# Original solution
import sys
from bisect import bisect_left, bisect, bisect_right
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)


def main():
    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 x in a:
        i = bisect(b, x)
        for y in b[i:]:
            j = bisect(c, y)
            cnt += len(c[j:])

    print(cnt)


if __name__ == '__main__':
    main()


# Optimized solution
import sys
from bisect import bisect_left, bisect_right
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)


def main():
    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 x in b:
        cnt += bisect_left(a, x)*(n-bisect_right(c, x))
    print(cnt)


if __name__ == '__main__':
    main()
# Original solution
import itertools
N = int(eval(input()))
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))

L = list(itertools.product(A,B,C,repeat=1))
cnt = 0
for i,j,k in L:
    if i<j<k:
        cnt += 1
print(cnt)

# 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 x in B:
    # 小さい
    sm = bisect.bisect_left(A,x)
    # 大きい
    bi = len(C) - bisect.bisect_right(C,x)
    ans += sm*bi
print(ans)
# 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 a:
  for j in range(bisect.bisect(b, i), len(b)):
    count += len(b) - bisect.bisect(c, b[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()))

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

count = 0
for i in b:
  count += bisect.bisect_left(a, i) * (len(c) - bisect.bisect(c, i))
print(count)
# Original solution
n = int(eval(input()))
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))

cnt = 0

for a in A:
    for b in B:
        for c in C:
            if a < b < c:
                cnt += 1

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 b in B:
    mid = bisect.bisect_left(A, b)
    bottom = n - bisect.bisect_right(C, b)
    cnt += mid*bottom

print(cnt)
# Original solution
import bisect as bi
n = int(eval(input()))
kariA = list(map(int,input().split()))
kariB = list(map(int,input().split()))
kariC = list(map(int,input().split()))
A = sorted(kariA)
B = sorted(kariB)
C = sorted(kariC)
count = 0
for c in C:
    for b in B[:bi.bisect_left(B,c)]:
            count += bi.bisect_left(A,b)
    
print(count)

# Optimized solution
import bisect as bi
n = int(eval(input()))
kariA = list(map(int,input().split()))
kariB = list(map(int,input().split()))
kariC = list(map(int,input().split()))
A = sorted(kariA)
B = sorted(kariB)
C = sorted(kariC)
count = 0
Clength = len(C)
for b in B:
    count += bi.bisect_left(A,b)*(Clength - bi.bisect_right(C,b))
print(count)
# 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()
ans = 0
def func(array, value):
  ng = -1
  ok = len(array)
  #if value
  while ok - ng > 1:
    mid = (ok + ng)//2
    if array[mid] < value:
      ng = mid
    elif array[mid] >= value:
      ok = mid
  return ok
for a in A:
  b_idx = func(B, a + 1)
  if b_idx == len(B):
    break
  #print('a', a)
  #print('B[b_idx:]',B[b_idx:])
  for b in B[b_idx:]:
    c_idx = func(C, b + 1)
    #print('b',b)
    #print('C[c_idx:]',C[c_idx:])
    if c_idx == len(C):
      break
    #print(a, b_idx, c_idx)
    ans += len(C) - c_idx
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
def low_func(array, value):
  ng = -1
  ok = len(array)
  #if value
  while ok - ng > 1:
    mid = (ok + ng)//2
    if array[mid] < value:
      ng = mid
    elif array[mid] >= value:
      ok = mid
  return ok

def up_func(array, value):
  ok = -1
  ng = len(array)
  #if value
  while abs(ok - ng) > 1:
    mid = (ok + ng)//2
    if array[mid] <= value:
      ok = mid
    elif array[mid] > value:
      ng = mid
  return ok

for b in B:
  a_idx = up_func(A, b - 1)
  if a_idx == -1:
    continue
  c_idx = low_func(C, b + 1)
  if c_idx == len(C):
    break
  ans += (a_idx + 1)*(len(C) - c_idx)
print(ans)