Problem:
 Score : 300 points    Problem Statement The season for Snuke Festival has come again this year. First of all, Ringo will perform a ritual to summon Snuke. For the ritual, he needs an altar, which consists of three parts, one in each of the three categories: upper, middle and lower.  He has N parts for each of the three categories. The size of the i -th upper part is A_i , the size of the i -th middle part is B_i , and the size of the i -th lower part is C_i .  To build an altar, the size of the middle part must be strictly greater than that of the upper part, and the size of the lower part must be strictly greater than that of the middle part. On the other hand, any three parts that satisfy these conditions can be combined to form an altar.  How many different altars can Ringo build? Here, two altars are considered different when at least one of the three parts used is different.      Constraints  1 \leq N \leq 10^5  1 \leq A_i \leq 10^9(1\leq i\leq N)  1 \leq B_i \leq 10^9(1\leq i\leq N)  1 \leq C_i \leq 10^9(1\leq i\leq N)  All input values are integers.         Input Input is given from Standard Input in the following format:  N  A_1  ...  A_N  B_1  ...  B_N  C_1  ...  C_N       Output Print the number of different altars that Ringo can build.        Sample Input 1 2
1 5
2 4
3 6      Sample Output 1 3  The following three altars can be built:   Upper: 1 -st part, Middle: 1 -st part, Lower: 1 -st part  Upper: 1 -st part, Middle: 1 -st part, Lower: 2 -nd part  Upper: 1 -st part, Middle: 2 -nd part, Lower: 2 -nd part        Sample Input 2 3
1 1 1
2 2 2
3 3 3      Sample Output 2 27       Sample Input 3 6
3 14 159 2 6 53
58 9 79 323 84 6
2643 383 2 79 50 288      Sample Output 3 87

Solution (Python):
import bisect
N = int(input())
A = 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)

Solution (Python):
import bisect
import itertools

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()
bc = []
ans = 0
count = 0


for i in b:
  indc = bisect.bisect_right(c,i)
  bc.append((n - indc))
  count += 1

BC = [0] + list(itertools.accumulate(bc))

for i in a:
  indb = bisect.bisect_right(b,i)
  ans += BC[-1] - BC[indb]
   
print(ans)

Solution (Python):
import bisect
n = int(input())
al = list(map(int,input().split()))
bl = list(map(int,input().split()))
cl = list(map(int,input().split()))

al.sort()
bl.sort()
cl.sort()

ans = 0
for b in bl:
    a_num = bisect.bisect_left(al,b)
    c_num = n - bisect.bisect_right(cl,b)
    ans += a_num*c_num

print(ans)

Solution (Python):
import bisect


def main():
    n = int(input())
    a = list(map(int, input().split()))
    b = list(map(int, input().split()))
    c = list(map(int, input().split()))

    a = sorted(a)
    c = sorted(c)

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

    print(res)


if __name__ == '__main__':
    main()

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()
c.sort()
cnt = 0
for i in b:
    a_i = bisect.bisect_left(a,i)
    c_i = bisect.bisect_right(c,i)
    cnt += a_i * (n - c_i)
print(cnt)

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()
c.sort()
cnt = 0
for i in b:
    a_i = bisect.bisect_left(a,i)
    c_i = bisect.bisect_right(c,i)
    cnt += a_i * (n - c_i)
print(cnt)

Solution (Python):
from itertools import accumulate

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

num_fixed_b = [-1] * N
c_idx = 0
for b_idx, b in enumerate(B):
  while c_idx < N and C[c_idx] <= b:
    c_idx += 1
  num_fixed_b[b_idx] = N - c_idx

num_fixed_b = list(accumulate(num_fixed_b[::-1]))[::-1]
b_idx = 0
ans = 0
for a_idx, a in enumerate(A):
  while b_idx < N and B[b_idx] <= a:
    b_idx += 1
  if b_idx == N:
    print(ans)
    quit()
  ans += num_fixed_b[b_idx]

print(ans)

Solution (Python):
from bisect import bisect_left, bisect_right
N = int(input())
*A, = map(int, input().split())
*B, = map(int, input().split())
*C, = map(int, input().split())
A.sort()
B.sort()
C.sort()
ans = 0
for b in B:
    a = bisect_left(A, b)
    c = bisect_right(C, b)
    ans += a * (N-c)
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())))
sm=0
for j in B:
  sm+=bisect.bisect_left(A,j)*(n-bisect.bisect_right(C,j))
print(sm)

Solution (Python):
import sys, os, math, bisect, itertools, collections, heapq, queue
from scipy.sparse.csgraph import csgraph_from_dense, floyd_warshall
from decimal import Decimal
from collections import defaultdict



sys.setrecursionlimit(10000000)

ii = lambda: int(sys.stdin.buffer.readline().rstrip())
il = lambda: list(map(int, sys.stdin.buffer.readline().split()))
fl = lambda: list(map(float, sys.stdin.buffer.readline().split()))
iln = lambda n: [int(sys.stdin.buffer.readline().rstrip()) for _ in range(n)]

iss = lambda: sys.stdin.buffer.readline().decode().rstrip()
sl = lambda: list(map(str, sys.stdin.buffer.readline().decode().split()))
isn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)]

lcm = lambda x, y: (x * y) // math.gcd(x, y)


MOD = 10 ** 9 + 7
MAX = float('inf')


def main():
    if os.getenv("LOCAL"):
        sys.stdin = open("input.txt", "r")

    N = ii()
    A, B, C = sorted(il()), sorted(il()), sorted(il())

    ret = 0
    for b in B:
        a = bisect.bisect_left(A, b)
        c = bisect.bisect_left(C, b+1)
        ret += a * (len(C) - c)
    print(ret)


if __name__ == '__main__':
    main()

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

ans = 0
for j in b:
    
    left = -1
    right = n 
    while(right - left > 1):
        center = (right + left)//2
        if a[center]  < j:
            left = center
        else:
            right = center
    
    l = -1
    r = n 
    while(r - l > 1):
        ce = (r+l)//2
        if c[ce] <= j:
            l = ce
        else:
            r = ce
    ans += right * (n - r)

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

print(ans)

Solution (Python):
import bisect
import itertools

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

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

res = 0
for b in B:
  pairA = bisect.bisect_left(A, b)
  pairC = bisect.bisect_right(C, b)
  res += pairA * (N-pairC)

print(res)

Solution (Python):



import bisect
import itertools

n = int(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_list.sort()
b_list.sort()
c_list.sort()

bc_list = []
for i in range(n):
    _b = b_list[i]
    _idx = bisect.bisect_right(c_list, _b)
    bc_list.append(n-_idx)

ab_list = []
for i in range(n):
    _a = a_list[i]
    _idx = bisect.bisect_right(b_list, _a)
    ab_list.append(n-_idx)

bc_list.sort()
cumsum = list(itertools.accumulate(bc_list))

ans = 0
for i in range(n):
    if ab_list[i] == 0:
        continue
    ans += cumsum[ab_list[i]-1]
print(ans)

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

low = 0
high = len(A) -1

def check(mid, parts,key):
    if parts[mid] > key:
        return True
    return False
cnt = 0

































    
    
    
    
    

    
    
    
    
    
    
    
    
    
    
    
    



for b in B:
    A_low = -1
    A_high = len(A)
    while A_high - A_low > 1:
        mid = (A_high + A_low) //2
        if A[mid] < b:
            A_low = mid
        else:
            A_high = mid

    a_cnt =  A_low + 1
    C_low = -1
    C_high = len(C)
    while C_high - C_low > 1:
        mid = (C_high + C_low) //2
        if C[mid] > b:
            C_high = mid
        else:
            C_low = mid
    c_cnt = len(C) - C_high

    cnt += a_cnt * c_cnt
print(cnt)

Solution (Python):
import sys
import math
import collections
import decimal
import itertools
from collections import deque
from functools import reduce
import heapq
import bisect
n = int(input())


a = list(map(int, sys.stdin.readline().split()))

b = list(map(int, sys.stdin.readline().split()))
c = list(map(int, sys.stdin.readline().split()))

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

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

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

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

Solution (Python):
import bisect

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

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

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

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

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

ans = 0
i = []
k = []
for j in range(n):
    left = n - 1
    right = 0
    a_mid = n // 2
    while left >= right:
        if a[a_mid] >= b[j]:
            left = a_mid - 1
        else:
            right = a_mid + 1
        a_mid = (left + right) // 2
    i.append(a_mid + 1)
    
for j in range(n):
    left = n - 1
    right = 0
    c_mid = n // 2
    while left >= right:
        if c[c_mid] > b[j]:
            left = c_mid - 1
        else:
            right = c_mid + 1
        c_mid = (left + right) // 2
    k.append(n - c_mid - 1)

ans = sum(x * y for x, y in zip(i, k))
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()

bc = [0]*n
bc[n-1]=n-bisect.bisect_right(c, b[n-1])

for i in range(0,n-1):
  bc[n-2-i]=bc[n-1-i] + n-bisect.bisect_right(c, b[n-2-i])

ans = 0
for i in range(n):
  temp = bisect.bisect_right(b, a[i])
  if temp != n:  
    ans += bc[temp]
  
print(ans)

Solution (Python):

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

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

def is_ok(arg, target, abc):
    if abc[arg] >= target:
        return True
    else:
        return False

def is_ok2(arg, target, abc):
    if abc[arg] > target:
        return True
    else:
        return False


def bict(left, right, target, abc, jug):

    while(right - left > 1):
        mid = (right + left)//2

        if jug(mid, target, abc):
            right = mid
        else:
            left = mid

    return right

cnt = 0
for b in B:
    a_min_index = bict(-1, N, b, A, is_ok)
    c_min_index = bict(-1, N, b, C, is_ok2)
    temp = (a_min_index - 1 + 1) * (N - c_min_index)
    cnt += temp

print(cnt)

Solution (Python):
import sys
import bisect
input = sys.stdin.readline

def slove():
    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):
        k = B[i]
        a = bisect.bisect_left(A,k)
        c = n-bisect.bisect_right(C,k)
        ans += a*c
        
    return ans


if __name__ == "__main__":
    print(slove())

Solution (Python):

def main():
    import sys, bisect
    N = int(sys.stdin.readline())
    A = list(map(int, sys.stdin.readline().split()))
    B = list(map(int, sys.stdin.readline().split()))
    C = list(map(int, sys.stdin.readline().split()))
    A.sort()
    B.sort()
    C.sort()
    
    
    
    ans = 0
    for b in B:
        a = bisect.bisect_left(A, b)
        b = N-bisect.bisect_right(C, b)
        ans +=a*b
    print(ans)
    
if __name__=='__main__':
    main()

Solution (Python):
def bisect(lst, isok, ok, ng):
    while(abs(ok-ng)>1):
        mid = (ok+ng)//2
        if isok(lst[mid]):
            ok = mid
        else:
            ng = mid
    return [ok, ng]

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 b:
    x = bisect(a, lambda x:x < i, -1, n)[0]
    y = bisect(c, lambda x:x > i, n, -1)[0]
    ans += (x+1)*(n-y)

print(ans)

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


if __name__ == '__main__':
    main()

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


total = 0
for i in b:
    a_number = bisect.bisect_left(a, i)
    c_number = n - bisect.bisect_right(c, i)
    total = total +  a_number * c_number
print(total)

Solution (Python):
import bisect

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

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

count = 0
for i in b:
  count += bisect.bisect_left(a, i) * (len(c) - bisect.bisect(c, i))
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()
count = 0
lenA = len(A)
lenB = len(B)
lenC = len(C)
for b in B:
  count += (bisect.bisect_left(A, b))*(lenC-bisect.bisect_right(C, b))
print(count)

Solution (Python):
import bisect
from itertools import accumulate
n, *ABC = map(int, open(0).read().split())
A, B, C = ABC[:n], ABC[n:2*n], ABC[2*n:3*n]
A.sort()
B.sort()
C.sort()
D = [bisect.bisect_left(A, b) for b in B]
E = [bisect.bisect_left(B, c) for c in C]
F = list(accumulate(D))
s = 0
for e in E:
    if e != 0:
        s += F[e-1]
print(s)

Solution (Python):
import bisect
N =int(input())
lisA =list(map(int,input().split()))
lisB = list(map(int,input().split()))
lisC = list(map(int,input().split()))

lisA.sort()
lisB.sort()
lisC.sort()
cnt = 0

for b in lisB:
    cnt += bisect.bisect_left(lisA,b)*(N-bisect.bisect_right(lisC,b))

print(cnt)

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


ans = 0

for i in range(N):
    upper = bisect_left(A, B[i])
    lower = N - bisect_right(C, B[i])
    ans += upper * lower

print(ans)

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

a=sorted(a)
for i in range(n):
    c[i]=-c[i]
c=sorted(c)

ans=0
for i in range(n):
    tmp1=bisect.bisect_left(a,b[i])
    tmp2=bisect.bisect_left(c,-b[i])
    ans+=tmp1*tmp2

print(ans)

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

ans = 0

for i in blist:
    a = bisect.bisect_left(alist,i)
    b = len(clist) - bisect.bisect_right(clist,i)
    ans += a*b
print(ans)

Solution (Python):



from bisect import bisect_left, bisect_right

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

    ret = 0
    for b in B:
        ia = bisect_left(A,b)
        ic = bisect_right(C,b)
        ret += ia*(N-ic)
    print(ret)

if __name__ == '__main__':
    main()

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

import bisect

m=0
d=[0 for i in range(n)]
for i in range(n):
    y=bisect.bisect_right(c,b[n-1-i])
    m+=n-y
    d[n-1-i]=m

m=0
for i in a:
    x=bisect.bisect_right(b,i)
    try :
        m+=d[x]
    except IndexError:
        pass
    
print(m)

Solution (Python):
import sys
import bisect
import numpy
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
n = int(readline())
A = list(map(int, readline().split()))
B = list(map(int, readline().split()))
C = list(map(int, readline().split()))
A = sorted(A)
B = sorted(B)

ans = 0
ind_list = []
for b in B:
  index = bisect.bisect_left(A,b)
  ind_list.append(index)
  
res = numpy.cumsum(ind_list)
for c in C:
  index = bisect.bisect_left(B,c)
  if index == 0:
    continue
  ans += res[index-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 i in b:
    x=bisect.bisect_left(a,i)
    y=n-bisect.bisect_right(c,i)
    ans+=x*y
print(ans)

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())))
ans=0
for i in b:
    he=-1
    ta=n
    while ta-he>1:
        mid=(he+ta)//2
        if i>a[mid]:
            he=mid
        else:
            ta=mid
    x=he+1

    he_=-1
    ta_=n
    while ta_-he_>1:
        mid_=(he_+ta_)//2
        if i>=c[mid_]:
            he_=mid_
        else:
            ta_=mid_
    y=n-ta_
    ans+=x*y
print(ans)

Solution (Python):
import bisect
import sys


def input(): return sys.stdin.readline().strip()
def I(): return int(input())
def LI(): return list(map(int, input().split()))
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 S(): return input()
def LS(): return input().split()


def main():
    n = I()
    a = LI()
    b = LI()
    c = LI()
    a.sort()
    b.sort()
    c.sort()
    ans = 0
    for bi in b:
        num_a = bisect.bisect_left(a, bi)
        num_c = n - bisect.bisect_right(c, bi)
        ans += num_a * num_c
    print(ans)


main()

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

ans=0
for i in range(N):
    b=B[i]
    left=0
    right=N-1
    if A[-1]<b:
        a_comb=N
    elif A[0]>=b:
        a_comb=0
    elif A[0]<b and A[1]>=b:
        a_comb=1
    else:
        a_comb=0
        while left<=right:
            mid=(left+right)//2
            if A[mid]<b and A[mid+1]>=b:
                a_comb=mid+1
                break
            elif A[mid]<b and A[mid+1]<b:
                left=mid+1
            elif A[mid]>=b:
                right=mid-1

    left=0
    right=N-1
    if C[0]>b:
        c_comb=N
    elif C[-1]<=b:
        c_comb=0
    elif C[-1]>b and C[-2]<=b:
        c_comb=1
    else:
        c_comb=0
        while left<=right:
            mid=(left+right)//2
            if C[mid]>b and C[mid-1]<=b:
                c_comb=N-mid
                break
            elif C[mid]>b and C[mid-1]>b:
                right=mid-1
            elif C[mid]<=b:
                left=mid+1
    ans+=a_comb*c_comb
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()
memo = [0]*(n+1)
for i in range(n):
    memo[bisect.bisect_left(b,c[i])] += 1
for i in range(n-1,-1,-1):
    memo[i] += memo[i+1]
for i in range(n-1,-1,-1):
    memo[i] += memo[i+1]
memo = memo[1:]+[0]
ans = 0

for i in range(n):
    ans += memo[bisect.bisect_right(b,a[i])]
print(ans)

Solution (Python):
import bisect

def solve(N, A, B, C):
     A.sort()
     B.sort()
     C.sort()
     ret = 0
     for j in range(N):
         i = bisect.bisect_right(A, B[j] - 1)
         k = bisect.bisect_left(C, B[j] + 1)
         ret += i * (N - k) if 0 <= i and 0 <= k < N else 0
     print(ret)

if __name__ == "__main__":
    N = int(input())
    A = list(map(int, input().split()))
    B = list(map(int, input().split()))
    C = list(map(int, input().split()))
    solve(N, A, B, C)

Solution (Python):
def binarySearchLeft(nums, target):
    low = 0
    high = len(nums) - 1
    while low <= high:
        mid = low + high >> 1
        if target == nums[mid]:
            if mid == 0 or target != nums[mid - 1]:
                return mid
            else:
                high = mid - 1
        elif target < nums[mid]:
            high = mid - 1
        else:
            low = mid + 1
    return low

def binarySearchRight(nums, target):
    low = 0
    high = len(nums) - 1
    while low <= high:
        mid = low + high >> 1
        if target == nums[mid]:
            if mid == len(nums) - 1 or target != nums[mid + 1]:
                return mid
            else:
                low = mid + 1
        elif target < nums[mid]:
            high = mid - 1
        else:
            low = mid + 1
    return high

def solve(N, A, B, C):
     A.sort()
     B.sort()
     C.sort()
     ret = 0
     for j in range(N):
         i = binarySearchRight(A, B[j] - 1)
         k = binarySearchLeft(C, B[j] + 1)
         ret += (i + 1) * (N - k) if 0 <= i < N and 0 <= k < N else 0
     print(ret)

if __name__ == "__main__":
    N = int(input())
    A = list(map(int, input().split()))
    B = list(map(int, input().split()))
    C = list(map(int, input().split()))
    solve(N, A, B, C)

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

ans = 0
for i in range(len(B)):
    selectA = bisect_left(A, B[i])
    selectB = len(C) - bisect_right(C, B[i])
    ans += selectA * selectB
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):
    b = B[i]
    a = bisect.bisect_left(A,b)
    c = bisect.bisect_right(C,b)
    ans+=(a*(len(C)-c))
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

for middle in b:
    
    tmp1 = bisect.bisect_left(a, middle)
    
    tmp2 = bisect.bisect_right(c, middle)
    ans += tmp1 * (n - tmp2)

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

Solution (Python):
import bisect
import numpy as np

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

small = []
big = []

for x in b:
    small.append(bisect.bisect_left(a, x))
    big.append(n-bisect.bisect(c, x))

small = np.array(small)
big = np.array(big)

print(np.sum(small*big))

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

BC = []
for b in B:
    BC.append(n - bisect.bisect_right(C, b))

cumsum = [BC[-1]]
for bc in BC[-2::-1]:
    cumsum.append(cumsum[-1] + bc)
cumsum = cumsum[::-1]

ans = 0
for a in A:
    idx = bisect.bisect_right(B, a)
    if idx < n: ans += cumsum[idx]
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
for i in range(n):
  temp1=bisect.bisect_left(a,b[i])
  temp2=bisect.bisect(c,b[i])
  ans=ans+temp1*(n-temp2)
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()
ans = 0
for i in B:
    x = bisect.bisect_left(A, i)
    y = bisect.bisect_right(C, i)
    y = N - y
    ans += x*y
print(ans)

Solution (Python):
import bisect
N=int(input())
ue=list(map(int,input().split()))
naka=list(map(int,input().split()))
sita=list(map(int,input().split()))
sita.sort(),naka.sort(),ue.sort()
count2=[0]*N
count1=[0]*N
for i in range(N):
    m = naka[i]
    k=naka[i]
    small=bisect.bisect_left(ue,k)
    count1[i]=small
    big = bisect.bisect_right(sita, m)
    count2[i]=N-big
ans=0
for i in range(N):
    ans+=count1[i]*count2[i]
print(ans)

Solution (Python):
import bisect
N=int(input())
ue=list(map(int,input().split()))
naka=list(map(int,input().split()))
sita=list(map(int,input().split()))
sita.sort(),naka.sort(),ue.sort()
count2=[0]*N
count1=[0]*N
for i in range(N):
    m = naka[i]
    k=naka[i]
    small=bisect.bisect_left(ue,k)
    count1[i]=small
    big = bisect.bisect_right(sita, m)
    count2[i]=N-big
ans=0
for i in range(N):
    ans+=count1[i]*count2[i]
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):
    ans+=bisect.bisect_left(A,B[i])*(N-bisect.bisect_right(C,B[i]))
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())))

bC=[0 for i in range(N)]
for i in range(N):
    bC[i]=N-bisect.bisect(C,B[i])
    
bCS=[0]*(N+1)
for i in range(N):
    bCS[i+1] = bCS[i]+bC[i]
    
ans=0
for i in range(N):
    x=bisect.bisect(B,A[i])
    ans+=bCS[N]-bCS[x]
        
print(ans)

Solution (Python):
import bisect

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

list.sort(A), list.sort(B), list.sort(C)

ans = 0

for b in B:
    a = bisect.bisect_left(A, b)
    c = len(C) - bisect.bisect_right(C, b)
    ans += a * c

print(ans)

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

a.sort()
c.sort()

import bisect




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

print(ans)

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

res = 0

from bisect import bisect_left, bisect_right

for b in B:
    idx_a = bisect_left(A, b)
    idx_c = bisect_right(C, b)
    res += idx_a * (n - idx_c)

print(res)

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

ans = 0
for i in range(N):
  cand_num_a = bisect_left(A, B[i])
  cand_num_c = N - bisect_right(C, B[i])
  ans += cand_num_a * cand_num_c

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()))
ans = 0
tmp = 0
a.sort()
b.sort()
c.sort()
for i in range(n):
    tmp = bisect.bisect_left(a,b[i])
    tmp2 = n - bisect.bisect_left(c,b[i]+1)
    ans += tmp*tmp2
print(ans)

Solution (Python):
n= int(input())
al = list(map(int, input().split()))
bl = list(map(int, input().split()))
cl = list(map(int, input().split()))

lal = sorted(al)
lbl = sorted(bl)
lcl = sorted(cl)


from bisect import bisect_left, bisect_right
 

res = 0

for i in range(n):
    bx = lbl[i]
    ax = bisect_left(lal,bx)
    cx = n - bisect_right(lcl,bx)
    
    res += ax*cx

print(res)

Solution (Python):
import bisect
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())))
  b_c = [0]*N
  for i, b in enumerate(reversed(B)):
    b_c[-1-i]  = b_c[-i] +N-bisect.bisect_right(C, b)
  ans = 0
  for i in A:
    posi = bisect.bisect_right(B, i)
    if posi < N:
      ans += b_c[posi]
  print(ans)

if __name__ == "__main__":
  main()

Solution (Python):
import bisect
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())))
  b_c = [0]*N
  for i, b in enumerate(reversed(B)):
    b_c[-1-i]  = b_c[-i] +N-bisect.bisect_right(C, b)
  ans = 0
  for i in A:
    posi = bisect.bisect_right(B, i)
    if posi < N:
      ans += b_c[posi]
  print(ans)

if __name__ == "__main__":
  main()