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 sys
from bisect import bisect_right
from itertools import accumulate

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7

N = INT()
A = sorted(LIST())
B = sorted(LIST())
C = sorted(LIST())

dp1 = [1] * (N+1)
dp2 = [0] * (N+1)
dp3 = [0] * (N+1)

for i1, a in enumerate(A):
    i2 = bisect_right(B, a)
    dp2[i2] += dp1[i1]
dp2 = list(accumulate(dp2))
for i2, b in enumerate(B):
    i3 = bisect_right(C, b)
    dp3[i3] += dp2[i2]
dp3 = list(accumulate(dp3))
print(sum(dp3[:N]))

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

Bcount = [0 for i in range(n+1)]
for i in range(1,n+1):
    Bcount[i] = bisect.bisect_left(a, b[i-1]) + Bcount[i - 1]

for i in range(n):
    index = bisect.bisect_left(b,c[i])

    ans += Bcount[index]
print(ans)

Solution (Python):
import bisect
n = int(input())
list1 = [list(map(int,input().split())) for i in range(3) ]

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

count = 0

for i in range(n):
	a = bisect.bisect_left(list1[0],list1[1][i])
	c = bisect.bisect_right(list1[2],list1[1][i])
	count += a*(n-c)
print(count)

Solution (Python):
import sys
from functools import reduce
import copy
import math
from pprint import pprint
import collections
import bisect


sys.setrecursionlimit(4100000)


def inputs(num_of_input):
    ins = [input() for i in range(num_of_input)]
    return ins


def int_inputs(num_of_input):
    ins = [int(input()) for i in range(num_of_input)]
    return ins


def solve(inputs):
    N = int(inputs[0])
    A = string_to_int(inputs[1])
    B = string_to_int(inputs[2])
    C = string_to_int(inputs[3])
    A.sort()
    B.sort()
    C.sort()

    patterns = 0

    for b in B:
        ai = bisect.bisect_left(A, b)
        ci = bisect.bisect_right(C, b)
        patterns += ai * (N-ci)

    return patterns


def string_to_int(string):
    return list(map(int, string.split()))


if __name__ == "__main__":
    ret = solve(inputs(4))
    print(ret)

Solution (Python):
import bisect
n=int(input())
A=sorted(list(map(int,input().split())))
B=sorted(list(map(int,input().split())))
C=sorted(list(map(int,input().split())))
ans=0
for b in B:
    ans+=(bisect.bisect_left(A,b)*(n-bisect.bisect_right(C,b)))

print(ans)

Solution (Python):
import bisect as bis

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_e in b:
    n_top = bis.bisect_left(a, b_e)
    n_bottom = n - bis.bisect_right(c, b_e)
    ans += n_top * n_bottom

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


cnt = 0

for b in B:
    mid = bisect.bisect_left(A, b)
    bottom = n - bisect.bisect_right(C, b)
    cnt += mid*bottom

print(cnt)

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

A = [int(_) for _ in input().split()]
B = [int(_) for _ in input().split()]
C = [int(_) for _ in input().split()]

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

res = 0
for i in range(n):
    i1 = bisect.bisect_left(A,B[i])
    i2 = bisect.bisect_right(C,B[i])
    res += i1 * (n - i2)

print(res)

Solution (Python):

def input():
    import sys
    return sys.stdin.readline().rstrip()


def main():
    import math
    import collections
    import itertools

    n = int(input())
    
    as_ = [0] + sorted(list(map(int, input().split())))
    bs_ = [0] + sorted(list(map(int, input().split())))
    cs_ = [0] + sorted(list(map(int, input().split())))

    
    n_combs = [0] * 3
    is_ = [n] * 3
    while is_[0] >= 1:
        
        
        max_value = max((as_[is_[0]], 0, 0), (bs_[is_[1]], -1, 1), (cs_[is_[2]], -2, 2))
        posi = max_value[2]
        if posi == 2:
            n_combs[2] += 1
        else:
            n_combs[posi] += n_combs[posi + 1]
        is_[posi] -= 1
        
    print(n_combs[0])


if __name__ == '__main__':
    main()

Solution (Python):
import bisect
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))

a = sorted(a)
b = sorted(b)
c = sorted(c)
ans = 0
for i in range(n):
    at = bisect.bisect_left(a, b[i])
    ct = max(len(c) - bisect.bisect_right(c, b[i]), 0)
    ans += at * ct
print(ans)

Solution (Python):
N = int(input())
AList = list(map(int,input().split()))
BList = list(map(int,input().split()))
CList = list(map(int,input().split()))
AList.sort()
BList.sort()
CList.sort()

Bx  = []

Bx2 = []

Cx = []

bnum = 0
for b in BList:
    while bnum < N and AList[bnum] < b:
        bnum += 1
    Bx.append(bnum)

for i in range(N):
    if i != 0:
        Bx2.append(Bx2[i-1]+Bx[i])
    else:
        Bx2.append(Bx[i])

cnum = 0
for c in CList:
    while cnum < N and BList[cnum] < c:
        cnum += 1
    Cx.append(cnum)

ans = 0
for sc in Cx:
    if sc > 0:
        ans += Bx2[sc-1]
print(ans)

Solution (Python):
import bisect

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

ans = 0
for mid in B:
    n_bottom = N - bisect.bisect_right(C,mid)
    n_top = bisect.bisect_left(A,mid)
    ans += n_bottom * n_top

print(ans)

Solution (Python):
import bisect
n=int(input())
a=[int(i) for i in input().split()]
b=[int(i) for i in input().split()]
c=[int(i) for i in input().split()]
a.sort()
b.sort()
c.sort()

ans=0
for i in range(n):
    ida=bisect.bisect_left(a,b[i])
    idc=bisect.bisect_right(c,b[i])
    ans+=(ida*(n-idc))
print(ans)

Solution (Python):
from bisect import bisect_right
        
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))
b_accum = [0 for _ in range(n)]
c_accum = [0 for _ in range(n)]
a.sort()
b.sort()
c.sort()
for i in range(n):
    index = bisect_right(b, a[i])
    try:
        b_accum[index] += 1
    except IndexError:
        pass
for i in range(1, n):
    b_accum[i] += b_accum[i-1]
for i in range(n):
    index = bisect_right(c, b[i])
    try:
        c_accum[index] += b_accum[i]
    except IndexError:
        pass
for i in range(1, n):
    c_accum[i] += c_accum[i-1]
for i in range(1, n):
    c_accum[i] += c_accum[i-1]
print(c_accum[n-1])

Solution (Python):
import bisect
cnt=0
n=int(input())
a= sorted(list(map(int, input().split())))
b= sorted(list(map(int, input().split())))
c= sorted(list(map(int, input().split())))
ab=[0]*n
bc=[0]*n
for i in range(n):
    bc[i]=bisect.bisect_left(b,c[i]-0.5)
for i in range(n):
    ab[i]=bisect.bisect_left(a,b[i]-0.5)
for i in range(1,n):
    ab[i]+=ab[i-1]
for i in range(n):
    if bc[i]!=0:
        cnt+=ab[bc[i]-1]
print(cnt)

Solution (Python):
import bisect
cnt=0
n=int(input())
a= sorted(list(map(int, input().split())))
b= sorted(list(map(int, input().split())))
c= sorted(list(map(int, input().split())))
ab=[0]*n
bc=[0]*n
for i in range(n):
    bc[i]=bisect.bisect_left(b,c[i]-0.5)
    ab[i]=bisect.bisect_left(a,b[i]-0.5)
for i in range(1,n):
    ab[i]+=ab[i-1]
for i in range(n):
    if bc[i]!=0:
        cnt+=ab[bc[i]-1]
print(cnt)

Solution (Python):
import bisect
cnt=0
n=int(input())
a= sorted(list(map(int, input().split())))
b= sorted(list(map(int, input().split())))
c= sorted(list(map(int, input().split())))
ab=[0]*n
bc=[0]*n
for i in range(n):
    bc[i]=bisect.bisect_left(b,c[i]-0.5)
for i in range(n):
    ab[i]=bisect.bisect_left(a,b[i]-0.5)
for i in range(1,n):
    ab[i]+=ab[i-1]
for i in range(n):
    if bc[i]!=0:
        cnt+=ab[bc[i]-1]
print(cnt)

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())))
GB = [0 for _ in range(N)]
for i in range(N):
    ind = bisect.bisect_right(C,B[i])
    GB[i] = N-ind
SB = [0 for _ in range(N)]
SB[N-1] = GB[N-1]
for i in range(N-2,-1,-1):
    SB[i] = SB[i+1]+GB[i]
cnt = 0
for i in range(N):
    a = A[i]
    ind = bisect.bisect_right(B,a)
    if ind<N:
        cnt += SB[ind]
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()

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)

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

Solution (Python):
n = int(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
res_b = 0
cnt = 0
i, j = 0, 0
for c_ in c:
    while i <= n-1 and c_ > b[i]:
        while j <= n-1 and b[i] > a[j]:
            cnt += 1
            j += 1
        res_b += cnt
        i += 1
    res += res_b

print(res)

Solution (Python):
n = int(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()])

def func1(list_1, list_2):
    res = []
    cnt = 0
    i = 0
    for x in list_2:
        while i <= n-1 and list_1[i] < x:
            cnt += 1
            i += 1
        res.append((x, cnt))
    return res

def func2(list_res, list_3):
    res = 0
    cnt = 0
    i = 0
    for x in list_3:
        while i <= n-1 and list_res[i][0] < x:
            cnt += list_res[i][1]
            i += 1
        res += cnt
    return res

ans = func2(func1(a, b), c)

print(ans)

Solution (Python):
def lowerBound(arr, n):
    low, high = -1, len(arr)
    while high-low>1:
        mid = (low+high)//2
        if arr[mid]>=n: high = mid
        else: low = mid
    return high

def upperBound(arr, n):
    low, high = -1, len(arr)
    while high-low>1:
        mid = (low+high)//2
        if arr[mid]>n: high = mid
        else: low = mid
    return low+1

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

ans = 0
for i in b:
    cnt_a = lowerBound(a, i)
    cnt_b = n - upperBound(c,i)
    ans += cnt_a * cnt_b
print(ans)

Solution (Python):
import bisect

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

ans = 0
for i in range(N):
    upper = bisect.bisect_left(A, B[i])
    downer = bisect.bisect_right(C, B[i])
    ans += upper*(len(C)-downer)
print(ans)

Solution (Python):
import bisect
n = int(input())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
c = list(map(int,input().split()))

a.sort()
c.sort()

res = 0

for sb in b:
    resa = bisect.bisect_left(a,sb)
    resc = n - bisect.bisect_right(c,sb)
    res += resa*resc

print(res)

Solution (Python):
from  bisect import bisect_left, bisect_right

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

cnt = 0
for b in B:
    a_cnt = bisect_left(A, b)
    c_cnt = N - bisect_right(C, b)
    cnt += a_cnt * c_cnt
print(cnt)

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

Solution (Python):
from bisect import bisect_left, bisect_right

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

answer = 0
CL = len(C)
for b in B:
    ai = bisect_left(A, b)
    ci = bisect_right(C, b)
    answer += ai * (CL - ci)
print(answer)

Solution (Python):

import bisect
n = int(input())
al = map(int, input().split())
bl = map(int, input().split())
cl = 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)

Solution (Python):


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

ans=[]
count=0

def binary (l,num):
    high=len(l)-1
    low=0
    
    if num<=l[0]:
        return 0
    elif num>l[-1]:
        return len(l)
        
    while True:
        
        mid=int((high+low))//2
        if l[mid]<num:
            if l[mid+1]>=num:
                return mid+1
            else:
                
                low=mid
        elif l[mid]>=num:
            if l[mid-1]<num:
                return (mid-1)+1
            else:
                
                high=mid
                
for i in range(len(B)):
    if i==0:
        ans.append(binary(A,B[i]))
    else:
        ans.append(binary(A,B[i])+ans[i-1])

for item in C:
    z=binary(B,item)
    if z==0:
        continue
    else:
        count+=ans[binary(B,item)-1]

print(count)

Solution (Python):
n = int(input())
a = sorted(list(map(int, input().split())))
b = sorted(list(map(int, input().split())))
c = sorted(list(map(int, input().split())))

bc = []
idx = 0
for i in range(n):
    while True:
        if b[i] >= c[-1]:
            bc.append(0)
            break
        elif c[idx] <= b[i]:
            idx += 1
        else:
            bc.append(n-idx)
            break

bc2 = bc[::-1]
ab2 = []
absum = 0
for i in range(n):
    absum += bc2[i]
    ab2.append(absum)
ab = ab2[::-1]

res = 0
idx = 0
for i in range(n):
    while True:
        if a[i] >= b[-1]:
            break
        elif b[idx] <= a[i]:
            idx += 1
        else:
            res += ab[idx]
            break
print(res)

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

for x in [A, B, C]:
    x.sort()

i = -1
j = 0
result = 0
for b in B:
    while i < N - 1 and A[i + 1] < b:
        i += 1
    while j < N and C[j] <= b:
        j += 1
    result += (i+1) * (N - j)
print(result)

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

for x in [A, B, C]:
    x.sort()

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

Solution (Python):

from bisect import bisect_right

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

for x in [A, B, C]:
    x.sort()

t = [0] * (N + 1)  
j = 0
for i in range(N):
    while j < N and C[j] <= B[i]:
        j += 1
    t[i] = N - j
for i in range(N - 1, -1, -1):
    t[i] += t[i + 1]

result = 0
i = 0
for a in A:
    while i < N and B[i] <= a:
        i += 1
    result += t[i]
print(result)

Solution (Python):

from bisect import bisect_right

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

for x in [A, B, C]:
    x.sort()

t = [0] * (N + 1)  
for i in range(N):
    t[i] = N - bisect_right(C, B[i])
for i in range(N - 1, -1, -1):
    t[i] += t[i + 1]

result = 0
for a in A:
    result += t[bisect_right(B, a)]
print(result)

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

Solution (Python):
import bisect
n=int(input())
A=sorted(map(int,input().split()))
B=list(map(int,input().split()))
C=sorted(map(int,input().split()))
r=0
for b in B:
    i=bisect.bisect_left(A,b)
    j=n-bisect.bisect_right(C,b)
    r+=i*j
print(r)

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()
c_len = len(C)

cnt = 0
for b in B:
    a_cnt = bisect.bisect_left(A,b)
    c_cnt = c_len - bisect.bisect_right(C,b)
    cnt +=  a_cnt * c_cnt

print(cnt)

Solution (Python):
from bisect import bisect_left
from bisect import bisect_right
n = int(input())
A = sorted(list(map(int, input().split())))
B = sorted(list(map(int, input().split())))
C = sorted(list(map(int, input().split())))

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

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

answer = 0
for b in B:
    ai = bisect.bisect_left(A, b)
    ci = bisect.bisect_right(C, b)
    answer += ai * (N - ci)

print(answer)

Solution (Python):
import sys
from bisect import bisect_left, bisect_right
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)


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

    cnt = 0
    for x in b:
        cnt += bisect_left(a, x)*(n-bisect_right(c, x))
    print(cnt)


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

import bisect
A.sort()
B.sort()
C.sort()





bc_val = [0] * N
for i in range(N):
    b = B[i]
    c_idx = bisect.bisect_right(C,b)
    bc_val[i] = (N-c_idx)
    
bc_ruiseki = [0] * N
tmp = bc_val[N-1]
bc_ruiseki[N-1] = tmp
for i in reversed(range(N-1)):
    tmp += bc_val[i]
    bc_ruiseki[i] = tmp
 

ans = 0
ib = 0
b = B[0]
flag = True
for ia in range(N):
    a = A[ia]
    while b <= a:
        if ib == N-1:
            flag = False
            break
        ib += 1
        b = B[ib]
    if flag:
        ans += bc_ruiseki[ib]
    else:
        break
    
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())))

bl = [bisect.bisect_left(A, b) for b in B]
for i in range(1, N):
    bl[i] += bl[i-1]
cl = [bisect.bisect_left(B, c) for c in C]

ans = 0
for c in cl:
    if c < 1:
        continue
    ans += bl[c-1]
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())))

bl = [bisect.bisect_left(A, b) for b in B]
for i in range(1, N):
    bl[i] += bl[i-1]
cl = [bisect.bisect_left(B, c) for c in C]

ans = 0
for c in cl:
    if c < 1:
        continue
    ans += bl[c-1]
print(ans)

Solution (Python):
import numpy as np

N = int(input())
A = np.array(list(map(int, input().split())))
B = np.array(list(map(int, input().split())))
C = -np.array(list(map(int, input().split())))

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

a = np.searchsorted(A, B, side='left')
c = np.searchsorted(C, -B, side='left')

print((a * c).sum())

Solution (Python):
import numpy as np

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

A.sort()
B.sort()

a = np.searchsorted(A, B, side='left')

B = sorted(B * (-1))
C = sorted(C * (-1))

c = np.searchsorted(C, B, side='left')
c = np.fliplr([c])[0]


print((a * c).sum())

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

sum=0
for bb in b:
    x=bisect.bisect_left(a,bb)
    y=bisect.bisect_right(c,bb)
    sum+=x*(n-y)
print(sum)

Solution (Python):
n = int(input())
a = sorted(list(map(int, input().split())))
b = sorted(list(map(int, input().split())))
c = sorted(list(map(int, input().split())))

k = 0
okb = [0 for i in range(n)]
for i in range(n):
    if k < n:
        while a[k] < b[i]:
            k += 1
            if k == n: break

    okb[i] = k

ans = 0
okc = 0

k = 0
for i in range(n):
    if k < n:
        while b[k] < c[i]:
            okc += okb[k]
            k += 1
            if k == n: break

    ans += okc
print(ans)

Solution (Python):
import bisect

n = int(input())
a = list(map(int, input().split( )))
b = list(map(int, input().split( )))
c =  list(map(int, input().split( )))
a.sort()
b.sort()
c.sort()


ans = 0

b_a = [0]
for i in range(n):
    bsct = bisect.bisect_left(a,b[i])
    b_a.append(bsct)
b_a_sum = [0]
sm = 0
for i in range(1,n+1):
    sm += b_a[i]
    b_a_sum.append(sm)
ans = 0
for i in range(n):
    mid =  bisect.bisect_left(b,c[i])
    ans += b_a_sum[mid] 
print(ans)

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

Solution (Python):
import sys
import heapq
from collections import deque

input = sys.stdin.readline

N = int(input())

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

A = [-i for i in A]
B = [-i for i in B]
C = [-i for i in C]
BD = [i for i in B]

heapq.heapify(A)
heapq.heapify(B)
heapq.heapify(C)
heapq.heapify(BD)

ai = [0]*N
bi = [0]*N
ci = [1]*N

def compete_cal(N, B, C, bi, ci):
    ciq = deque(ci)
    for i in range(N):
        b=-heapq.heappop(B)
        while len(C)>0:
          c=-heapq.heappop(C)
          if c>b:
              bi[i]+=ciq.popleft()
          else:
              heapq.heappush(C, -c)
              break

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

    return bi   

bi = compete_cal(N, B, C, bi, ci)

ai = compete_cal(N, A, BD, ai, bi)
    
print(sum(ai))

Solution (Python):
from bisect import bisect_right


def 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())))
    l = [0] * n
    for index, i in enumerate(b):
        l[index] = n - bisect_right(c, i)
    s = [l[-1]] * n
    for i in range(n - 2, -1, -1):
        s[i] = s[i + 1] + l[i]
    ans = 0
    for i in a:
        j = bisect_right(b, i)
        if j < n:
            ans += s[j]
    print(ans)


if __name__ == '__main__':
    main()

Solution (Python):
import sys
import heapq
from collections import deque

input = sys.stdin.readline

N = int(input())

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

A = [-i for i in A]
B = [-i for i in B]
C = [-i for i in C]
BD = [i for i in B]


heapq.heapify(A)
heapq.heapify(B)
heapq.heapify(C)
heapq.heapify(BD)

ai = [0]*N
bi = [0]*N
ci = [1]*N


for i in range(N):
    b=-heapq.heappop(B)
    cnt=False
    while not cnt:
        if len(C)==0:
            cnt=True
            break
        else:
            c=-heapq.heappop(C)
            if c>b:
                bi[i]+=1
            else:
                cnt=True
                heapq.heappush(C, -c)

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

bi = deque(bi)   
    
for i in range(N):
    a=-heapq.heappop(A)
    while len(BD)>0:
        b=-heapq.heappop(BD)
        if b>a:
            ai[i]+=bi.popleft()
        else:
            heapq.heappush(BD, -b)
            break
        
         
for i in range(1,N):
    ai[i]+=ai[i-1]
    
print(sum(ai))

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






pattern = 0
minA = min(A)
maxC = max(C)

for i in B:
        if minA < i and maxC > i:
                
                index = bisect.bisect_left(A, i)
                index2 = bisect.bisect_right(C, i)

                
                canA = index
                canC = N - index2

                pattern += canA * canC
        
print(pattern)

Solution (Python):
import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
input=lambda :sys.stdin.readline().rstrip()
def resolve():
    import bisect
    n=int(input())
    A=sorted(list(map(int,input().split())))
    B=sorted(list(map(int,input().split())))
    C=sorted(list(map(int,input().split())))
    ans=0
    for b in B:
        i=bisect.bisect_left(A,b)
        j=bisect.bisect_right(C,b)
        ans+=i*(n-j)
    print(ans)
resolve()

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

Solution (Python):
import bisect

N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))
A.sort()
C.sort()
cnt = 0
for b in B:
  pos_a = bisect.bisect_left(A, b)
  pos_c = bisect.bisect_right(C, b)
  cnt += pos_a * (N-pos_c)
print(cnt)

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

N = int(input())
A = sorted(list(map(int, input().split())), reverse=True)
B = sorted(list(map(int, input().split())))
C = sorted(list(map(int, input().split())))
j = bisect_left(C, B[0])
ansBC = [N - j] + [0] * (N-1)

for i in range(1, N):
    while j < N and B[i] >= C[j]:
        j += 1
    if j == N:
        break
    ansBC[i] = N - j

j = N-1
ans = 0
for i in range(N):
    while j >= 0 and A[i] < B[j]:
        ans += ansBC[j] * (N - i)
        j -= 1
    if j == -1:
        break
    
print(ans)

Solution (Python):
import bisect

n = int(input())
ls = [sorted(map(int, input().split())) for _ in range(3)]
res = 0
for i in range(n):
    b = ls[1][i]
    x = bisect.bisect_right(ls[0], b - 1)
    y = bisect.bisect_left(ls[2], b + 1)
    res += x * (n - y)
print(res)

Solution (Python):
from bisect import bisect_right, bisect_left
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()
s = 0
for j in range(N):
    s += bisect_left(A, B[j]) * (N - bisect_right(C, B[j]))
print(s)

Solution (Python):
from bisect import bisect_right, bisect_left
import sys
input = sys.stdin.readline
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 j in range(N):
    b = B[j]
    i = bisect_left(A, b)
    k = bisect_right(C, b)
    ans += i * (N - k)
print(ans)

Solution (Python):
from bisect import bisect_right, bisect_left
import sys
input = sys.stdin.readline
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 j in range(N):
    b = B[j]
    i = bisect_left(A, b)
    k = bisect_right(C, b)
    ans += i * (N - k)
print(ans)

Solution (Python):
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
import math
import bisect
import random
from itertools import permutations, accumulate, combinations
import sys
import string
from bisect import bisect_left, bisect_right
from math import factorial, ceil, floor
from functools import reduce


INF = float('inf')
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return sys.stdin.readline().strip()
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]
mod = 1000000007

n = I()



small = sorted(LI())
middle = sorted(LI())
big = sorted(LI())


ans = 0
for i in range(n):
    ans += bisect_left(small, middle[i]) * (n - bisect_right(big, middle[i]))



print(ans)

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

import bisect

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

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

print(cnt)