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
sys.setrecursionlimit(4100000)
import math
import bisect
import itertools
INF = float('inf')
from heapq import heapify, heappop, heappush

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 = 0
    for b in B:
        a_num = bisect.bisect_left(A,b)
        c_num = bisect.bisect_right(C,b)
        ans += a_num*(len(C) - c_num)
    print(ans)


if __name__ == '__main__':
    main()

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:
  a_num = bisect.bisect_left(A,i)
  c_num = bisect.bisect(C,i)
  ans += a_num*(N-c_num)


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:
  a_num = bisect.bisect_left(A,i)
  c_num = bisect.bisect(C,i)
  ans += a_num*(N-c_num)


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:
  A=bisect.bisect_left(a,i)
  C=bisect.bisect(c,i)
  ans+=A*(n-C)
print(ans)

Solution (Python):
import itertools
from collections import deque,defaultdict,Counter
from itertools import accumulate
import bisect
from heapq import heappop,heappush,heapify
import math
from copy import deepcopy
import queue


Mod = 1000000007
fact = [1, 1]
factinv = [1, 1]
inv = [0, 1] 
for i in range(2, 10**5 + 1):
    fact.append((fact[-1] * i) % Mod)
    inv.append((-inv[Mod % i] * (Mod // i)) % Mod)
    factinv.append((factinv[-1] * inv[-1]) % Mod)
    
def cmb(n, r, p):
    if (r < 0) or (n < r):
        return 0
    r = min(r, n - r)
    return fact[n] * factinv[r] * factinv[n - r] % p
    
def sieve_of_eratosthenes(n):
    if not isinstance(n,int):
        raise TypeError("n is not int")
    if n<2:
        raise ValueError("n is not effective")
    prime = [1]*(n+1)
    for i in range(2,int(math.sqrt(n))+1):
        if prime[i] == 1:
            for j in range(2*i,n+1):
                if j%i == 0:
                    prime[j] = 0
    res = []
    for i in range(2,n+1):
        if prime[i] == 1:
            res.append(i)
    return res

 
class UnionFind:
    def __init__(self,n):
        self.parent = [i for i in range(n+1)]
        self.rank = [0 for i in range(n+1)]
    
    def findroot(self,x):
        if x == self.parent[x]:
            return x
        else:
            y = self.parent[x]
            y = self.findroot(self.parent[x])
            return y
    
    def union(self,x,y):
        px = self.findroot(x)
        py = self.findroot(y)
        if px < py:
            self.parent[y] = px
        else:
            self.parent[px] = py
 
    def same_group_or_no(self,x,y):
        return self.findroot(x) == self.findroot(y)
def pow_k(x, n):

    if n == 0:
        return 1

    K = 1
    while n > 1:
        if n % 2 != 0:
            K *= x
        x *= x
        n //= 2

    return K * x
def main():  
    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()
    ans = 0
    for i in range(n):
        a_left = bisect.bisect_left(a, b[i])
        c_right = bisect.bisect_right(c, b[i])
        ans += (a_left*(n-c_right))
    print(ans)
        
        
    
if __name__ == "__main__":
    main()

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

Solution (Python):
from bisect import bisect_left,bisect_right
n=int(input())
al=list(map(int,input().split()))
bl=list(map(int,input().split()))
cl=list(map(int,input().split()))
al.sort()
cl.sort()
s=0
for b in bl:
    a=bisect_left(al,b)
    c=n-bisect_right(cl,b)
    s+=a*c
print(s)

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 m in b:
    l_idx = bisect.bisect_left(a, m)
    u_idx = bisect.bisect_right(c, m)
    ans += l_idx * (n - u_idx)

print(ans)

Solution (Python):
import sys
read = sys.stdin.read
readline = sys.stdin.buffer.readline
from bisect import bisect_right, bisect_left
sys.setrecursionlimit(10 ** 8)
INF = float('inf')
MOD = 10 ** 9 + 7


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 = 0


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

    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()
ans = 0

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

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

a.sort()
c.sort()

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

Solution (Python):
from bisect import *
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_left(A,b)*(N-bisect_right(C,b)) for b in B))

Solution (Python):
import bisect
N = int(input())
A, B, C = [sorted(map(int, input().split())) for _ in range(3)]
print(sum( bisect.bisect_left(A, b)*(N-bisect.bisect_right(C, b)) for b in B))

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

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

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 b in B:
    l = -1
    r = N
    while (r-l) > 1:
        mid = (r+l)//2
        if A[mid] < b:
            l = mid
        else:
            r = mid
    top = l+1
    l = -1
    r = N
    while (r-l) > 1:
        mid = (r+l)//2
        if C[mid] <= b:
            l = mid
        else:
            r = mid
    bottom = N-r
    ans += top*bottom
print(ans)

Solution (Python):

import itertools
import math
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 bi in B:
    res += bisect.bisect_left(A, bi) * (N-bisect.bisect_right(C, bi))
print(res)

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

n = int(sys.stdin.buffer.readline())
a = list(map(int, sys.stdin.buffer.readline().split()))
b = list(map(int, sys.stdin.buffer.readline().split()))
c = list(map(int, sys.stdin.buffer.readline().split()))
a.sort()
b.sort()
c.sort()
ans = 0
for j in b:
    ans += (n - bisect_right(c, j))*bisect_left(a, j)
print(ans)

Solution (Python):
import math
import collections
import itertools
import heapq
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()))

    sA = sorted(A)
    sC = sorted(C)

    res = 0
    for b in B:
        a = bisect.bisect_left(sA, b)
        c = N - bisect.bisect_right(sC, b)
        res += a*c

    print(res)

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

print(cnt)

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):
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(mid, array, n):  return array[mid] > n
 
def binary_search(left, right, array, n):
    while (abs(right - left) > 1):
        mid = (left + right) // 2
        if is_ok(mid, array, n):  right = mid
        else:  left = mid
    return right
 
ans = 0
BtoC = [N - binary_search(-1, N, C, B[i]) for i in range(N)]
for i in range(1, N):  BtoC[-i - 1] += BtoC[-i]
for i in range(N):  
    ret = binary_search(-1, N, B, A[i])
    if ret != N:  ans += BtoC[binary_search(-1, N, B, A[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 is_ok(mid, array, n):  return array[mid] > n

def binary_search(left, right, array, n):
    while (abs(right - left) > 1):
        mid = (left + right) // 2
        if is_ok(mid, array, n):  right = mid
        else:  left = mid
    return right

ans = 0
BtoC = []
for i in range(N):
    ret = binary_search(-1, N, C, B[i])
    if ret != N:
        BtoC.append(N - ret)
    else:
        BtoC.append(0)
for i in range(1, N):  BtoC[-i - 1] += BtoC[-i]
for i in range(N):  
    ret = binary_search(-1, N, B, A[i])
    if ret != N:  ans += BtoC[binary_search(-1, N, B, A[i])]
print(ans)

Solution (Python):
import bisect

N=int(input())
L1=list(map(int,input().split()))
L2=list(map(int,input().split()))
L3=list(map(int,input().split()))

L1.sort()
L2.sort()
L3.sort()

ans=0
for l2 in L2:
    l1_idx=bisect.bisect_left(L1,l2)
    l3_idx=bisect.bisect_right(L3,l2)
    
    ans+=l1_idx*(N-l3_idx)
print(ans)

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

cnt = [0] * n
for i in range(n):
    cnt[i] = n - bisect_right(c, b[i])

cnt = [0] + list(accumulate(cnt[::-1]))
cnt.reverse()

ans = 0
for i in range(n):
    ans += cnt[bisect_right(b, a[i])]

print(ans)

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

cnt = [0] * n
for i in range(n):
    cnt[i] = n - bisect_left(c, b[i] + 1)

cnt = [0] + list(accumulate(cnt[::-1]))
cnt.reverse()

ans = 0
for i in range(n):
    ans += cnt[bisect_left(b, a[i] + 1)]

print(ans)

Solution (Python):
import bisect
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:
    ai = bisect.bisect_left(A, b)
    ci = bisect.bisect_right(C, b)
    ans += (N - ci)*ai

print(ans)

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

print(ans)

Solution (Python):
import sys
sys.setrecursionlimit(10 ** 9)

def int1(x): return int(x) - 1
def II(): return int(input())
def MI(): return map(int, input().split())
def MI1(): return map(int1, input().split())
def LI(): return list(map(int, input().split()))
def LI1(): return list(map(int1, input().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def MS(): return input().split()
def LS(): return list(input())
def LLS(rows_number): return [LS() for _ in range(rows_number)]
def printlist(lst, k=' '): print(k.join(list(map(str, lst))))
INF = float('inf')





from bisect import bisect_left, bisect_right

def solve():
    N = II()
    A = sorted(LI())
    B = LI()
    C = sorted(LI())

    
    
    
    ans = 0
    for b in B:
        
        i = bisect_left(A, b)

        
        j = N - bisect_right(C, b)
        
        ans += i * j
    print(ans)

if __name__ == '__main__':
    solve()

Solution (Python):
import sys
import bisect

def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def S(): return sys.stdin.readline().rstrip()
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.bisect_left(A,b)
    ok_c = bisect.bisect_right(C,b)
    ans += ok_a*(N-ok_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:
    i = bisect.bisect_left(A, b)
    j = bisect.bisect(C, b)
    ans += i * (N - j)
print(ans)

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()
def rand_N(ran1, ran2):
    return random.randint(ran1, ran2)
def rand_List(ran1, ran2, rantime):
    return [random.randint(ran1, ran2) for i in range(rantime)]
def rand_ints_nodup(ran1, ran2, rantime):
  ns = []
  while len(ns) < rantime:
    n = random.randint(ran1, ran2)
    if not n in ns:
      ns.append(n)
  return sorted(ns)

def rand_query(ran1, ran2, rantime):
  r_query = []
  while len(r_query) < rantime:
    n_q = rand_ints_nodup(ran1, ran2, 2)
    if not n_q in r_query:
      r_query.append(n_q)
  return sorted(r_query)

from collections import defaultdict, deque, Counter
from sys import exit
from decimal import *
import heapq
import math
from fractions import gcd
import random
import string
import copy
from itertools import combinations, permutations, product
from operator import mul
from functools import reduce
from bisect import bisect_left, bisect_right

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





def less_than(array, x):
    
    
    index = bisect_left(array, x)
    if index == 0:
        less_than_int = -float('inf')
    else:
        less_than_int = array[index - 1]
    return [index, less_than_int]

N = getN()
up = getList()
up.sort()
mid = getList()
mid.sort()
low = getList()
low.sort()


mid_imos = [0] * N
for i in range(N):
    mid_imos[i] = less_than(up, mid[i])[0]

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

low_imos = [0] * N
for i in range(N):
    ind = less_than(mid, low[i])[0]
    if ind > 0:
        low_imos[i] = mid_imos[ind - 1]
print(sum(low_imos))

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

ans = 0
for b in B:
  a_ind = bisect.bisect_left(A, b)
  c_ind = bisect.bisect_right(C, b)
  ans += a_ind*(n-c_ind)
  
print(ans)

Solution (Python):
import sys
from bisect import bisect
from itertools import accumulate


def main():
    input = sys.stdin.buffer.readline
    n = int(input())
    a = sorted(map(int, input().split()))
    b = sorted(map(int, input().split()))
    c = sorted(map(int, input().split()))
    
    
    b_c_cnt = [0] * n
    past = 0
    for i in range(n):
        pos = bisect(c, b[i], lo=past)
        past = pos
        b_c_cnt[i] = n - pos

    
    acc = list(accumulate(b_c_cnt[::-1]))[::-1] + [0]
    ans = 0
    past = 0
    for i in range(n):
        pos = bisect(b, a[i], lo=past)
        ans += acc[pos]
        past = pos
    print(ans)


if __name__ == "__main__":
    main()

Solution (Python):
import sys
from bisect import bisect
from itertools import accumulate


def main():
    input = sys.stdin.buffer.readline
    n = int(input())
    a = sorted(map(int, input().split()))
    b = sorted(map(int, input().split()))
    c = sorted(map(int, input().split()))
    
    
    b_c_cnt = [0] * n
    past = 0
    for i in range(n):
        pos = bisect(c, b[i], lo=past)
        past = pos
        b_c_cnt[i] = n - pos

    
    acc = list(accumulate(b_c_cnt[::-1]))[::-1] + [0]
    ans = 0
    past = 0
    for i in range(n):
        pos = bisect(b, a[i], lo=past)
        ans += acc[pos]
        past = pos
    print(ans)


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

cnt = []
pos_c = 0
for pos_b in range(n):
    while pos_c < n and c[pos_c] <= b[pos_b]:
        pos_c += 1
    cnt.append(n - pos_c)

sum_cnt = [0] * (n+1)
sum_cnt[n-1] = cnt[n-1]
for i in range(n-2, -1, -1):
    sum_cnt[i] = sum_cnt[i+1] + cnt[i]

res = 0
pos_b = 0
for pos_a in range(n):
    while pos_b < n and b[pos_b] <= a[pos_a]:
        pos_b += 1
    res += sum_cnt[pos_b]

print(res)

Solution (Python):
import bisect
(n,),aa,bb,cc = [sorted(list(map(int, s.split()))) for s in open(0)]

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

print(ans)

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

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

Solution (Python):
import bisect
n = int(input())
list_A = list(map(int, input().split()))
list_B = list(map(int, input().split()))
list_C = list(map(int, input().split()))
list_A.sort()
list_B.sort()
list_C.sort()
ans = 0

for i in range(n):
    b = list_B[i]
    left = bisect.bisect_left(list_A, b)
    right = n - bisect.bisect_right(list_C, b)
    ans += left * right

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

sm=0

for i,y in enumerate(b):
    mn_x=-1
    mx_x=n
    while mx_x-mn_x>=2:
        mid=(mn_x+mx_x)//2
        if a[mid]<y:
            mn_x=mid
        else : mx_x=mid

    mn_z=-1
    mx_z=n
    while mx_z-mn_z>=2:
        mid=(mn_z+mx_z)//2
        if c[mid]>y:
            mx_z=mid
        else : mn_z=mid
    
    sm+=(mn_x+1)*(n-mx_z)

print(sm)

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

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

import bisect

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

Solution (Python):
import sys
input = sys.stdin.readline
N=int(input())
S=list(map(int,input().split()))
T=list(map(int,input().split()))
U=list(map(int,input().split()))
S.sort()
T.sort()
U.sort()





count=0
def is_ok(index,key):
    if key>S[index]:
        return True
    else:
        return False


def meguru_bisect(key):
    ng=N
    ok=-1
    
    while (abs(ok - ng) > 1):
        mid = (ok + ng) // 2
        if is_ok(mid,key):
            ok = mid
        else:
            ng = mid
    return ok

def is_ok2(index,key):
    if key<U[index]:
        return True
    else:
        return False


def meguru_bisect2(key):
    ng=-1
    ok=N
    
    while (abs(ok - ng) > 1):
        mid = (ok + ng) // 2
        if is_ok2(mid,key):
            ok = mid
        else:
            ng = mid
    return ok
ans=0
for i in range(N):
    ans+=(N-meguru_bisect2(T[i]))*(meguru_bisect(T[i])+1)
print(ans)

Solution (Python):
N=int(input())
S=list(map(int,input().split()))
T=list(map(int,input().split()))
U=list(map(int,input().split()))
S.sort()
T.sort()
U.sort()





count=0
def is_ok(index,key):
    if key>S[index]:
        return True
    else:
        return False


def meguru_bisect(key):
    ng=N
    ok=-1
    
    while (abs(ok - ng) > 1):
        mid = (ok + ng) // 2
        if is_ok(mid,key):
            ok = mid
        else:
            ng = mid
    return ok

def is_ok2(index,key):
    if key<U[index]:
        return True
    else:
        return False


def meguru_bisect2(key):
    ng=-1
    ok=N
    
    while (abs(ok - ng) > 1):
        mid = (ok + ng) // 2
        if is_ok2(mid,key):
            ok = mid
        else:
            ng = mid
    return ok
ans=0
for i in range(N):
    ans+=(N-meguru_bisect2(T[i]))*(meguru_bisect(T[i])+1)
print(ans)

Solution (Python):
import sys
import heapq
import re
from itertools import permutations
from bisect import bisect_left, bisect_right
from collections import Counter, deque
from math import factorial, sqrt, ceil, gcd
from functools import lru_cache, reduce
from decimal import Decimal
from operator import mul

INF = 1 << 60
MOD = 1000000007
sys.setrecursionlimit(10 ** 7)



class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())


def dijkstra_heap(s, edge, n):
    
    d = [10**20] * n
    used = [True] * n 
    d[s] = 0
    used[s] = False
    edgelist = []
    for a,b in edge[s]:
        heapq.heappush(edgelist,a*(10**6)+b)
    while len(edgelist):
        minedge = heapq.heappop(edgelist)
        
        if not used[minedge%(10**6)]:
            continue
        v = minedge%(10**6)
        d[v] = minedge//(10**6)
        used[v] = False
        for e in edge[v]:
            if used[e[1]]:
                heapq.heappush(edgelist,(e[0]+d[v])*(10**6)+e[1])
    return d


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 combinations_count(n, r):
    if n < r:
        return 0
    r = min(r, n - r)
    numer = reduce(mul, range(n, n - r, -1), 1)
    denom = reduce(mul, range(1, r + 1), 1)
    return numer // denom


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


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


def gcd_list(numbers):
    return reduce(gcd, numbers)


def is_prime(n):
    if n <= 1:
        return False
    p = 2
    while True:
        if p ** 2 > n:
            break
        if n % p == 0:
            return False
        p += 1
    return True



def eratosthenes(limit):
    A = [i for i in range(2, limit+1)]
    P = []

    while True:
        prime = min(A)
        
        if prime > sqrt(limit):
            break
            
        P.append(prime)
            
        i = 0
        while i < len(A):
            if A[i] % prime == 0:
                A.pop(i)
                continue
            i += 1
            
    for a in A:
        P.append(a)
            
    return P


def permutation_with_duplicates(L):

    if L == []:
        return [[]]

    else:
        ret = []

        
        S = sorted(set(L))

        for i in S:

            data = L[:]
            data.remove(i)

            for j in permutation_with_duplicates(data):
                ret.append([i] + j)

        return ret

def make_divisors(n):
    lower_divisors , upper_divisors = [], []
    i = 1
    while i*i <= n:
        if n % i == 0:
            lower_divisors.append(i)
            if i != n // i:
                upper_divisors.append(n//i)
        i += 1
    return lower_divisors + upper_divisors[::-1]




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

ans = 0
for i in range(n):
    ng = -1
    ok = n
    while abs(ok - ng) > 1:
        mid = (ok + ng) // 2
        if a[mid] < b[i]:
            ok = mid
        else:
            ng = mid
    
    ng2 = -1
    ok2 = n
    while abs(ok2 - ng2) > 1:
        mid2 = (ok2 + ng2) // 2
        if c[mid2] > b[i]:
            ok2 = mid2
        else:
            ng2 = mid2

    
    
    ans += (n - ok) * (n - ok2)

print(ans)

Solution (Python):
import bisect

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

if __name__ == '__main__':
    main()

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

Solution (Python):
N=int(input())
A,B,C=[list(sorted(map(int,input().split()))) for i in range(3)]

count=0

def bs_l(lis,x):
    low,high=0,len(lis)
    while low<high:
        mid=(low+high)//2
        if lis[mid]<x:
            low=mid+1
        else:
            high=mid
    return low        

def bs_r(lis,x):
    low,high=0,len(lis)
    while low<high:
        mid=(low+high)//2
        if lis[mid]>x:
            high=mid
        else:
            low=mid+1
    return low        

for i in B:
    count+=bs_l(A,i)*(N-bs_r(C,i))


print(count)

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,i)*(n-bisect.bisect_right(c,i)) for i in b))

Solution (Python):
n=int(input())
A=[0]+list(map(int,input().split()))
B=[0]+list(map(int,input().split()))
C=[0]+list(map(int,input().split()))

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

total = [0]*(n+1)
ans = [0]*(n+1)
for i in range(n+1):
    l1 = 0
    r1 = n+1
    while l1 != r1:
        mid1 = (l1 + r1)//2
        if B[i] > A[mid1]:
            l1 = mid1 + 1
            total[i]=max(total[i],mid1+total[i-1])
        else:
            r1 = mid1

for i in range(n+1):
    l2 = 0
    r2 = n+1
    while l2 != r2:
        mid2 = (l2 + r2)//2
        if C[i] > B[mid2]:
            l2 = mid2 + 1
            ans[i] = max(ans[i],total[mid2])
        else:
            r2 = mid2
print(sum(ans))