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, bisect_left
readline = sys.stdin.buffer.readline
sys.setrecursionlimit(10 ** 8)
INF = float('inf')
MOD = 10 ** 9 + 7

def lcm_base(x, y):
    return (x * y) // gcd(x, y)

def lcm_list(numbers):
    return reduce(lcm_base, numbers, 1)

def main():
    N = int(readline())
    A = list(map(int, readline().split()))
    B = list(map(int, readline().split()))
    C = list(map(int, readline().split()))
    A.sort()
    B.sort()
    C.sort()
    ans = 0
    for i in range(N):
        top = bisect_left(A, B[i])
        bottom = bisect_right(C, B[i])
        if top>0 and bottom != N:
            ans += top*(N-bottom)
    print(ans)
if __name__ == '__main__':
    main()

Solution (Python):
N = int(input())
Lists = []
ans = 0
for _ in range(3):
    s = [int(e) for e in input().split()]
    s.sort()
    Lists.append(s)
def bin(i,j):
    global t,s
    right = N-1;left = 0
    while(right >= left):
        mid = int(left + (right-left)/2)
        if(j==0):
            if(i>Lists[j][mid]):
                left = mid + 1
            else:
                right = mid -1
        else:
            if(i>=Lists[j][mid]):
                left = mid + 1
            else:
                right = mid - 1
    if(j == 0):
        t = left
    else:
        s = N - left
for i in Lists[1]:
    bin(i,0)
    bin(i,2)
    ans += t*s
print(ans)

Solution (Python):
def resolve():
    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()

    import bisect
    cnt = 0
    for bi in B:
        a_ok = bisect.bisect_left(A, bi)
        c_ok = bisect.bisect_right(C, bi)
        cnt += a_ok * (n - c_ok)
    print(cnt)

resolve()

Solution (Python):
import bisect
n=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))*(len(c)-(bisect.bisect_right(c,B)))
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())),reverse=True)
ul=[0]*n
ll=[0]*n
u=0
l=0
ans=0
for i in range(n):
  if u!=n:
    while a[u]<b[i]:
      u+=1
      if u==n:
        break
  ul[i]=u
b=b[::-1]
for i in range(n):
  if l!=n:
    while c[l]>b[i]:
      l+=1
      if l==n:
        break
  ll[i]=l
ll=ll[::-1]
for i in range(n):
  ans+=ul[i]*ll[i]
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()


cnt = 0
for i in range(N):
    cnt_ab = bisect.bisect_left(al, bl[i])  
    cnt_bc = len(cl) - bisect.bisect(cl, bl[i])  
    
    cnt += cnt_ab * cnt_bc

print(cnt)

Solution (Python):
def getN():
    return int(input())
def getNM():
    return map(int, input().split())
def getList():
    return list(map(int, input().split()))
def getArray(intn):
    return [int(input()) for i in range(intn)]
def input():
    return sys.stdin.readline().rstrip()

from collections import defaultdict, deque, Counter
from sys import exit
import heapq
import math
from fractions import gcd
import copy
from itertools import permutations
from operator import mul
from functools import reduce
from bisect import bisect_left, bisect_right

import sys
sys.setrecursionlimit(1000000000)
mod = 10 ** 9 + 7

from itertools import permutations
from math import factorial, hypot





N = getN()
top = getList()
middle = getList()
bottom = getList()

top.sort()
middle.sort()
bottom.sort()


on_mid = [0]
for i in range(N):
    index_mid = bisect_left(top, middle[i])
    on_mid.append(on_mid[i] + index_mid)

ans = 0
for j in range(N):
    index_bot = bisect_left(middle, bottom[j])
    
    ans += on_mid[index_bot]
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())))

from bisect import bisect_left, bisect

ans = 0
for i in range(N):
    b = B[i]
    a = bisect_left(A,b)
    c = bisect(C,b)
    
    
    ans += a*(N-c)
print(ans)

Solution (Python):
import sys

input = sys.stdin.buffer.readline

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())))
num_a = 0
num_c = 0
res = 0
pre_b = -1


for b in B:
    if b == pre_b:
        res += num_a * num_c
        continue
    num_a = bisect_left(A, b) 
    pre_num_c = bisect_right(C, b)
    num_c = N - pre_num_c 
    res += num_a * num_c
    pre_b = b
print(res)

Solution (Python):
import sys

input = sys.stdin.buffer.readline

import numpy as np

N = int(input())

A = np.array(input().split(), dtype=np.int32) 
B = np.array(input().split(), dtype=np.int32)
C = np.array(input().split(), dtype=np.int32)

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

num_a = np.searchsorted(A, B, side="left")
num_c = N - np.searchsorted(C, B, side="right")

res = np.dot(num_a, num_c)

print(res)

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())))
num_a = 0
num_c = 0
res = 0
pre_b = -1


for b in B:
    if b == pre_b:
        res += num_a * num_c
        continue
    num_a = bisect_left(A, b) 
    pre_num_c = bisect_right(C, b)
    num_c = N - pre_num_c 
    res += num_a * num_c
    pre_b = b
print(res)

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())))
num_a = 0
num_c = 0
res = 0
pre_b = -1


for b in B:
    if b == pre_b:
        res += num_a * num_c
        continue
    num_a = bisect_left(A, b) 
    pre_num_c = bisect_right(C, b)
    num_c = N - pre_num_c 
    res += num_a * num_c
    pre_b = b
print(res)

Solution (Python):
import sys
import itertools
sys.setrecursionlimit(1000000000)
from heapq import heapify,heappop,heappush,heappushpop
import math
import collections
import copy
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 = n - bisect.bisect_left(C,b+1)
    ans += a*c
print(ans)

Solution (Python):
from bisect import bisect_left
from collections import defaultdict

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_a = 0
num_c = 0
res = 0
pre_b = -1

dict_C = defaultdict(int)


for b in B:
    if b == pre_b:
        res += num_a * num_c
        continue
    num_a = bisect_left(A, b) 
    pre_num_c = bisect_left(C, b)
    num_c = N - pre_num_c 
    if pre_num_c != N and C[pre_num_c] == b:
        num_c = N - bisect_left(C, b+1)
    res += num_a * num_c
    pre_b = b
print(res)

Solution (Python):
import sys
sys.setrecursionlimit(10**8)
def ii(): return int(sys.stdin.readline())
def mi(): return map(int, sys.stdin.readline().split())
def li(): return list(map(int, sys.stdin.readline().split()))
def li2(N): return [list(map(int, sys.stdin.readline().split())) for _ in range(N)]
def dp2(ini, i, j): return [[ini]*i for _ in range(j)]
def dp3(ini, i, j, k): return [[[ini]*i for _ in range(j)] for _ in range(k)]
import bisect 

from itertools import accumulate 

N = ii()
S = [sorted(li()) for _ in range(3)]
rec = [[0]*N for i in range(3)]

for i in range(N):
    
    
    rec[1][i] = N - bisect.bisect_right(S[2], S[1][i])

acc = list(accumulate(rec[1]))


    

ans = 0
for i in range(N):
    
    ind = bisect.bisect_right(S[1], S[0][i])
    if ind == 0:
        ans += acc[-1]
    else:
        ans += acc[-1] - acc[ind-1]

print(ans)

Solution (Python):
def isOK(index, key, a):
    if a[index] >= key:
        return True
    else:
        return False

def binary_search(key, a, N):
    ng = -1
    ok = N

    while abs(ok - ng) > 1:
        mid = (ok + ng) // 2
        if isOK(mid, key, a):
            ok = mid
        else:
            ng = mid

    return ok

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 range(N):
    key = B[i]
    A_index = binary_search(key, A, N)
    C_index = binary_search(key + 1, C, N)
    
    
    

    count_A = A_index
    count_C = N - C_index
    
    ans += count_A * abs(N-C_index)


print(ans)

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

"""
前処理で、中部の祭壇でBi以下のサイズを選べるときの、中段と上段のパーツの組み合わせのパターン数を計算しておく。
"""
BPattern = []
for i in range(N):
    b = B[i]
    idx = bisect(A,b-1)
    if i == 0:
        BPattern.append(idx)
    else:
        BPattern.append(BPattern[-1]+idx)

ans = 0
for i in range(N):
    c = C[i]
    idx = bisect(B,c-1)
    if idx:
        ans+=BPattern[idx-1]

print(ans)

Solution (Python):
from bisect import bisect,bisect_left
from collections import deque
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()
tmp=0
for i in b:
    dd=bisect_left(a,i)*(n-bisect(c,i))
    tmp+=dd
print(tmp)

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

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

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60


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

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

    ans = sum(bisect_left(A, b) * (N - bisect_right(C, b)) for b in B)

    print(ans)
    return


if __name__ == '__main__':
    main()

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

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60


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

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

    ans = sum(bisect_left(A, b) * (N - bisect_right(C, b)) for b in B)

    print(ans)
    return


if __name__ == '__main__':
    main()

Solution (Python):
from sys import stdin
from bisect import bisect_right, bisect_left


def input():
    return stdin.readline().strip()


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

    ans = sum(bisect_left(A, b) * (N - bisect_right(C, b)) for b in B)
    print(ans)


if __name__ == "__main__":
    main()

Solution (Python):
import sys

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60


def main():
    N, *ABC = map(int, read().split())
    A = sorted(ABC[:N])
    B = sorted(ABC[N : 2 * N])
    C = sorted(ABC[2 * N : 3 * N])

    ans = 0
    for b in B:
        ok = N
        ng = -1
        while ok - ng > 1:
            mid = (ok + ng) // 2
            if A[mid] >= b:
                ok = mid
            else:
                ng = mid
        a_num = ok

        ok = N
        ng = -1
        while ok - ng > 1:
            mid = (ok + ng) // 2
            if C[mid] > b:
                ok = mid
            else:
                ng = mid
        c_num = N - ok

        ans += a_num * c_num

    print(ans)
    return


if __name__ == '__main__':
    main()

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

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60


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

    A.sort()
    C.sort()

    ans = sum(bisect_left(A, b) * (N - bisect_right(C, b)) for b in B)

    print(ans)
    return


if __name__ == '__main__':
    main()

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

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60


def main():
    N, *ABC = map(int, read().split())
    A = sorted(ABC[:N])
    B = ABC[N : 2 * N]
    C = sorted(ABC[2 * N : 3 * N])

    ans = sum(bisect_left(A, b) * (N - bisect_right(C, b)) for b in B)

    print(ans)
    return


if __name__ == '__main__':
    main()

Solution (Python):
import sys

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60


def main():
    N, *ABC = map(int, read().split())
    A = sorted(ABC[:N])
    B = sorted(ABC[N : 2 * N])
    C = sorted(ABC[2 * N : 3 * N])

    ans = 0
    for b in B:
        ok = -1
        ng = N
        while ng - ok > 1:
            mid = (ok + ng) // 2
            if A[mid] < b:
                ok = mid
            else:
                ng = mid
        a_num = ok + 1

        ok = N
        ng = -1
        while ok - ng > 1:
            mid = (ok + ng) // 2
            if C[mid] > b:
                ok = mid
            else:
                ng = mid
        c_num = N - ok

        ans += a_num * c_num

    print(ans)
    return


if __name__ == '__main__':
    main()

Solution (Python):
N = int(input())
A = [0] + sorted([int(i) for i in input().split()]) + [10**9+1]
B = sorted([int(i) for i in input().split()])
C = [10**9+1] + sorted([int(i) for i in input().split()], reverse=True) + [0]

def A_count(n, ls):
    left = 0
    right = N + 1

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

        if n <= ls[mid]: right = mid
        if n > ls[mid]: left = mid

    return left

def C_count(n, ls):
    left = 0
    right = N + 1

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

        if n >= ls[mid]: right = mid
        if n < ls[mid]: left = mid

    return left

ans = 0
for i in range(N):
    n = B[i]
    ans += A_count(n, A) * C_count(n, C)

print(ans)

Solution (Python):






import sys
input = sys.stdin.readline

import math

import bisect
from collections import defaultdict
from collections import deque
from functools import lru_cache






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






def I(): return int(input().strip())
def S(): return input().strip()
def IL(): return list(map(int,input().split()))
def SL(): return list(map(str,input().split()))
def ILs(n): return list(int(input()) for _ in range(n))
def SLs(n): return list(input().strip() for _ in range(n))
def ILL(n): return [list(map(int, input().split())) for _ in range(n)]
def SLL(n): return [list(map(str, input().split())) for _ in range(n)]


def P(arg): print(arg); return
def Y(): print("Yes"); return
def N(): print("No"); return
def E(): exit()
def PE(arg): print(arg); exit()
def YE(): print("Yes"); exit()
def NE(): print("No"); exit()


def DD(arg): return defaultdict(arg)



def inv(n): return pow(n, MOD-2, MOD)


kaijo_memo = []
def kaijo(n):
  if(len(kaijo_memo) > n):
    return kaijo_memo[n]
  if(len(kaijo_memo) == 0):
    kaijo_memo.append(1)
  while(len(kaijo_memo) <= n):
    kaijo_memo.append(kaijo_memo[-1] * len(kaijo_memo) % MOD)
  return kaijo_memo[n]

gyaku_kaijo_memo = []
def gyaku_kaijo(n):
  if(len(gyaku_kaijo_memo) > n):
    return gyaku_kaijo_memo[n]
  if(len(gyaku_kaijo_memo) == 0):
    gyaku_kaijo_memo.append(1)
  while(len(gyaku_kaijo_memo) <= n):
    gyaku_kaijo_memo.append(gyaku_kaijo_memo[-1] * pow(len(gyaku_kaijo_memo),MOD-2,MOD) % MOD)
  return gyaku_kaijo_memo[n]

def nCr(n,r):
  if(n == r):
    return 1
  if(n < r or r < 0):
    return 0
  ret = 1
  ret = ret * kaijo(n) % MOD
  ret = ret * gyaku_kaijo(r) % MOD
  ret = ret * gyaku_kaijo(n-r) % MOD
  return ret


def factorization(n):
  arr = []
  temp = n
  for i in range(2, int(-(-n**0.5//1))+1):
    if temp%i==0:
      cnt=0
      while temp%i==0: 
        cnt+=1 
        temp //= i
      arr.append([i, cnt])
  if temp!=1:
    arr.append([temp, 1])
  if arr==[]:
    arr.append([n, 1])
  return arr


def make_divisors(n):
  divisors = []
  for i in range(1, int(n**0.5)+1):
    if n % i == 0:
      divisors.append(i)
      if i != n // i: 
        divisors.append(n//i)
  return divisors


def gcd(a, b):
    while b:
        a, b = b, a % b
    return a


def lcm(a, b):
    return a * b // gcd (a, b)


def count_bit(n):
  count = 0
  while n:
    n &= n -1
    count += 1
  return count


def base_10_to_n(X, n):
  if X//n:
    return base_10_to_n(X//n, n)+[X%n]
  return [X%n]

def base_n_to_10(X, n):
  return sum(int(str(X)[-i-1])*n**i for i in range(len(str(X))))


def int_log(n, a):
  count = 0
  while n>=a:
    n //= a
    count += 1
  return count





N = I()
A,B,C = ILL(3)
A.sort()
B.sort()
C.sort()

B2 = []

for b in B:
  p = bisect.bisect_left(A,b)
  if B2 == []:
    B2.append(p)
  else:
    B2.append(B2[-1]+p)

C2 = []
for i in range(N):
  c = C[i]
  p = bisect.bisect_left(B,c)
  if C2 == []:
    if p == 0:
      C2.append(0)
    else:
      C2.append(B2[p-1])
  else:
    if p == 0:
      C2.append(C2[-1])
    else:
      C2.append(C2[-1]+B2[p-1])
print(C2[-1])

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

def isOk(index, key, a):
    if a[index] >= key:
        return True
    else:
        return False

def binary_search(key, a):
    ng = -1
    ok = len(a)

    while abs(ok - ng) > 1:
        mid = (ok + ng) // 2
        if isOk(mid, key, a):
            ok = mid
        else:
            ng = mid

    return ok

ans = 0
a.sort()
c.sort()
for i in range(n):
    upper = binary_search(b[i], a)
    lower = n - binary_search(b[i] + 1, c)
    ans += upper * lower
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()
a.append(10**10)
c.append(10**10)
a = [-1] + a
c = [-1] + c
ans = 0
for i in range(len(b)):
    al = 0
    ar = n+1
    while True:
        am = (al+ar)//2
        if a[am] < b[i]:
            al = am
        else:
            ar = am
        an = al
        if al+1 == ar:
            break
    cl = 0
    cr = n+1
    while True:
        cm = (cl+cr)//2
        if c[cm] <= b[i]:
            cl = cm
        else:
            cr = cm
        cn = n - (cr-1)
        if cl+1 == cr:
            break
    ans += an*cn
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
for i in range(len(b)):
    al = 0
    ar = n-1
    while True:
        if a[-1] < b[i]:
            an = n
            break
        if a[0] >= b[i]:
            an = 0
            break
        am = (al+ar)//2
        if a[am] < b[i]:
            al = am
        else:
            ar = am
        an = al + 1
        if al+1 == ar:
            break
    cl = 0
    cr = n-1
    while True:
        if c[0] > b[i]:
            cn = n
            break
        if c[-1] <= b[i]:
            cn = 0
            break
        cm = (cl+cr)//2
        if c[cm] <= b[i]:
            cl = cm
        else:
            cr = cm
        cn = n - cr
        if cl+1 == cr:
            break
    ans += an*cn
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())))
count = 0

A.insert(0,-1)
A.append(10e+10)
C.insert(0,-1)
C.append(10e+10)

for bi in B:
    left = 0
    right = n+1
    
    while right-left>1:
        middle = (left+right) //2
        if A[middle]>=bi:
            right = middle
        else:
            left = middle
    a_count = left

    left = 0
    right = n+1
    while right-left>1:
        middle = (left+right) //2
        if C[middle]>bi:
            right = middle
        else:
            left = middle
    c_count = n+1-right

    count += a_count*c_count

print(count)

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

A.insert(0, -100000000000)
A.append(1000000000000)
C.insert(0, -100000000000)
C.append(1000000000000)


total= 0
for b in B:
    
    l = 0
    r = N + 1
    while r - l > 1:
        m = (l + r) // 2
        if A[m] < b:
            l = m
        else:
            r = m

    a_count = l

    
    l = 0
    r = N + 1
    while r - l > 1:
        m = (l + r) // 2
        if C[m] > b:
            r = m
        else:
            l = m

    c_count = N + 1 - r

    total += a_count * c_count

print(total)

Solution (Python):
import bisect

N = int(input())
A = sorted([int(s) for s in input().split()])
B = sorted([int(s) for s in input().split()])
C = sorted([int(s) for s in input().split()])

cnt = 0

for b in B:
    insert_index1 = bisect.bisect_left(A, b)
    insert_index2 = bisect.bisect_right(C, b)

    cnt += insert_index1 * (N - insert_index2)

print(cnt)

Solution (Python):
import bisect


def main():
    N = int(input())
    AArr = list(map(int, input().split()))
    BArr = list(map(int, input().split()))
    CArr = list(map(int, input().split()))

    AArr.sort()
    CArr.sort()
    ans = 0
    for i in range(N):
        a = bisect.bisect_left(AArr, BArr[i])
        c = bisect.bisect_right(CArr, BArr[i])
        c = N-c
        ans += a*c

    print(ans)


if __name__ == '__main__':
    main()

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 b in B:
    point_A = bisect.bisect_left(A, b)
    possible_A = point_A
    point_C = bisect.bisect_right(C, b)
    possible_C = N - point_C
    ans += possible_A * possible_C

print(ans)

Solution (Python):
from bisect import bisect_left, bisect_right
def calc_possible_alter(upper, middle, lower):
  cnt = 0
  for m in middle:
    
    
    cnt += bisect_left(upper, m) * (len(lower) - bisect_right(lower, m))
  return cnt


N = int(input())
upper_part = sorted(list(map(int, input().split())))
middle_part = sorted(list(map(int, input().split())))
lower_part = sorted(list(map(int, input().split())))

print(calc_possible_alter(upper_part, middle_part, lower_part))

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())))
print(sum(bisect.bisect_left(A,b)*(N-bisect.bisect_right(C,b)) for b in B))

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

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.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 *(N-c)
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())))

import bisect

ans = 0
for b in B:
  k = bisect.bisect_left(A, b)
  l = bisect.bisect_right(C, b)
  ans += k * (N -l)
print(ans)

Solution (Python):
n = int(input())
aaa = list(map(int, input().split()))
bbb = list(map(int, input().split()))
ccc = list(map(int, input().split()))

aaa.sort()
ccc.sort()

def is_ok_a(mid, b):
    if mid < 0:
        return True
    elif mid >= n:
        return False
    else:
        return aaa[mid] < b

def m_bisect_a(ng, ok, b):
    while abs(ng - ok) > 1:
        mid = (ng + ok) // 2
        if is_ok_a(mid, b):
            ok = mid
        else:
            ng = mid
    return ok

def is_ok_c(mid, b):
    if mid < 0:
        return False
    elif mid >= n:
        return True
    else:
        return ccc[mid] > b

def m_bisect_c(ng, ok, b):
    while abs(ng - ok) > 1:
        mid = (ng + ok) // 2
        if is_ok_c(mid, b):
            ok = mid
        else:
            ng = mid
    return ok

ans = 0
for i in range(n):
    b = bbb[i]
    ng, ok = n, -1
    cnt_a = m_bisect_a(ng, ok, b) + 1
    ng, ok = -1, n
    cnt_c = n - m_bisect_c(ng, ok, b)
    ans += (cnt_a * cnt_c)

print(ans)

Solution (Python):

import sys
from bisect import bisect_left, bisect_right


def S(): return sys.stdin.readline().rstrip()


def I(): return int(sys.stdin.readline().rstrip())


def LI(): return list(map(int, sys.stdin.readline().rstrip().split()))


def LS(): return list(sys.stdin.readline().rstrip().split())


N = I()
A = LI()
B = LI()
C = LI()
A.sort()
B.sort()
C.sort()
ans = 0
for b in B:
    ok_a = bisect_left(A, b)
    ok_c = bisect_right(C,b)
    ans += ok_a * (N-ok_c)
print(ans)

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

import bisect

count = 0
for b in B:
    
    la = bisect.bisect_left(A, b)
    
    rc = bisect.bisect_right(C, b)
    
    count += la*(n-rc)

print(count)

Solution (Python):
import sys
input = sys.stdin.readline
import bisect
    
def snuke_festival(a,b,c):
    count = 0
    a_sorted = sorted(a)
    b_sorted = sorted(b)
    c_sorted = sorted(c)
    maxlen=len(b)

    for target in b_sorted:
        
        
        mid_a = bisect.bisect_left(a_sorted,target)
        mid_c = bisect.bisect_right(c_sorted,target)
        count += mid_a * (maxlen - mid_c)
        
    return count

if __name__ == "__main__":
    n = int(input())
    a = list(map(int,input().split()))
    b = list(map(int,input().split()))
    c = list(map(int,input().split()))

    print(snuke_festival(a,b,c))

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

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

Solution (Python):
from bisect import bisect_right, bisect_left
import numpy as np

n = int(input())

top = map(int, input().split())
mid = map(int, input().split())
bot = map(int, input().split())
top = np.array(sorted(top))
mid = np.array(sorted(mid))
bot = np.array(sorted(bot))

ans = 0
for i in mid:
    top_num = len(top[:bisect_left(top,i)])
    bot_num = len(bot[bisect_right(bot,i):])
    ans += top_num * bot_num

print(ans)

Solution (Python):
from bisect import bisect_left
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の祭壇から大きさb以下のパーツを使うとき、Aの祭壇のパーツとの組み合わせはいくつあるか」というのを調べてメモしておく。
次に、Cの祭壇の大きさがcのとき、という風に場合わけして、選べるBの祭壇の大きさを絞って、A,B,Cの組み合わせの数を加算していく。
"""


tmpSum = 0
dicB = {}
for i in range(N):
    b = B[i]
    if b not in dicB:
        dicB[b] = tmpSum
    idx = bisect_left(A,b)
    dicB[b] += idx
    tmpSum += idx

ans = 0
for i in range(N):
    c = C[i]
    idx = bisect_left(B,c)
    if idx != 0:
        b = B[idx-1]
        ans += dicB[b]

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

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

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

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

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

ans = 0

for i in range(n):
    ans+=n_bigger_c(b[i])*n_smaller_a(b[i])
print(ans)