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

    def is_ok1(mid, S, K):
        if K <= S[mid]:
            return True
        else:
            return False

    def is_ok2(mid, S, K):
        if K < S[mid]:
            return True
        else:
            return False

    def binary_search_meguru(S, K, is_ok):
        left = -1
        right = N
        while right - left > 1:
            mid = left + ((right - left) // 2)
            if is_ok(mid, S, K):
                right = mid
            else:
                left = mid
        return right

    ans = 0
    for b in B:
        a = binary_search_meguru(A, b, is_ok1)
        c = binary_search_meguru(C, b, is_ok2)
        ans += a * (N-c)
    print(ans)


if __name__ == '__main__':
    main()

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

ind0=0
LIST=[0]*N
for i in range(N):
    while ind0<N and B[i]<C[ind0]:
        ind0+=1
    LIST[i]=ind0
    
ind0=0
ALIST=[0]*N
for i in range(N):
    while ind0<N and A[i]<B[ind0]:
        ind0+=1
    ALIST[i]=ind0

from itertools import accumulate
S=[0]+list(accumulate(LIST))

ANS=0
for i in range(N):
    ANS+=S[ALIST[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 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= [int(_) for _ in input().split()]
B = [int(_) for _ in input().split()]
C = [int(_) for _ in input().split()]

A.sort()
B.sort()
C.sort(reverse=True)

ans = 0
ai = 0
ci = n-1

for b in B:
  while ai <n and  A[ai] <b:
    ai +=1
  while ci >=0 and C[ci] <=b:
    ci -= 1
  ans += ai *(ci +1)
print(ans)

Solution (Python):
import bisect
N = int(input())
A_arr = list(map(int,input().split()))
A_arr.sort()
B_arr = list(map(int,input().split()))
B_arr.sort()
C_arr = list(map(int,input().split()))
ans = 0
check_array = [0] * N
for i in range(N):
    check_array[i] = check_array[i-1]+bisect.bisect_left(A_arr,B_arr[i])
for i in C_arr:
    B_index = bisect.bisect_left(B_arr,i)
    if B_index == 0:
        continue
    ans += check_array[B_index-1]
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
A.sort()
C.sort()
for i in B:
    x = bisect.bisect_left(A,i)
    y = N-bisect.bisect_right(C,i)
    ans += x*y
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())))

A_B = []
B_C = []
total = 0

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

print(total)

Solution (Python):
import bisect

N=int(input())
As=sorted(list(map(int,input().split())))
Bs=sorted(list(map(int,input().split()))) 
Cs=sorted(list(map(int,input().split())))

Ans=0

for B in Bs:
    a=bisect.bisect_left(As, B)
    c=len(Cs)-bisect.bisect_right(Cs,B)
    Ans+=a*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()
c.sort()

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

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

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

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

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

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

Solution (Python):
from sys import stdin
import math
import bisect
import heapq
import numpy as np
from math import factorial

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

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

total = 0
for i in range(n):
    l = bisect.bisect(a,b[i]-1)
    r = n -bisect.bisect_left(c,b[i]+1)
    total += l*r

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

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

Solution (Python):
N = int(input())
As, Bs, Cs = [
  sorted(map(int, input().split()))
  for _ in range(3)
]

from bisect import *

def sums():
  for b in Bs:
  	yield bisect_left(As, b) * (N - bisect_right(Cs, b))

print(sum(sums()))

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

bi = [0 for i in range(N)]
for i in range(N):
    b = B[i]
    c = bisect.bisect_right(C,b)
    bi[i]+=(N-c)

S = sum(bi)
rui = [0]
for bii in bi:
    rui.append(rui[-1]+bii)

rui = rui[::-1]
ans = 0
for i in range(N):
    a = A[i]
    ind = bisect.bisect_right(B,a)
    
    ans+=(S-rui[N-ind])

    
    
print(ans)

Solution (Python):
def examC():
    N = I()
    A = LI(); B = LI(); C = LI()
    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)


import sys,copy,bisect,itertools
from heapq import heappop,heappush,heapify
from collections import Counter,defaultdict,deque
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def S(): return sys.stdin.readline().strip()
mod = 10**9 + 7
inf = float('inf')

examC()

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

dp_b = [0] * n
j = 0
for i in range(n):
    while j < n:
        if B[i] >= C[j]:
            dp_b[i] = j
            break
        j += 1
    if j == n:
        dp_b[i] = n

for i in range(1, n):
    dp_b[i] = dp_b[i] + dp_b[i - 1]

ans = 0
j = 0
for i in range(n):
    while j < n:
        if A[i] >= B[j]:
            if j == 0:
                break
            else:
                ans += dp_b[j - 1]
                break
        j += 1
    if j == n:
        ans += dp_b[n - 1]

print(ans)

Solution (Python):
from bisect import bisect_left as bl, bisect_right as br
N = int(input())
A = sorted([int(a) for a in input().split()])
B = sorted([int(a) for a in input().split()])
C = sorted([int(a) for a in input().split()])

ans = 0
for i in range(N):
    ans += bl(A, B[i]) * (N - br(C, B[i]))
print(ans)

Solution (Python):
import bisect
N = int(input())
Alist = sorted(list(map(int, input().split())))
Blist = sorted(list(map(int, input().split())))
Clist = sorted(list(map(int, input().split())))

num = 0

for B in Blist:
    small = bisect.bisect_left(Alist, B)
    left = N - bisect.bisect_right(Clist, B)
    num += small * left
print(num)

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()))
ctr= [0 for _ in range(N)]

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

ans = 0

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

Solution (Python):
def main():
    n = int(input())
    A,B,C = [sorted(list(map(int,input().split()))) for i in range(3)]
    ans = 0
    for b in B:
        ans += low(A,b)*(n-high(C,b))
    print(ans)


def low(A,key):
    left,right = -1,len(A)
    while right - left > 1:
        mid = (left+right)//2
        if A[mid] >= key:
            right = mid
        else:
            left = mid
    return left+1


def high(C,key):
    left,right = -1,len(C)
    while right - left > 1:
        mid = (left+right)//2
        if C[mid] <= key:
            left = mid
        else:
            right = mid
    return right


if __name__ == "__main__":
    main()

Solution (Python):
import bisect

n = int(input())
al, bl, cl = list(sorted(map(int, input().split())) for i in range(3))
ans = 0

for key in bl:
    top = bisect.bisect_left(al, key)
    btm = len(cl) - bisect.bisect_right(cl, key)
    ans += top * btm

print(ans)

Solution (Python):

n = int(input())
al = sorted(list(int(i) for i in input().split()))
bl = sorted(list(int(i) for i in input().split()))
cl = sorted(list(int(i) for i in input().split()))
ans = 0

def low_left(a, key):
    left = -1
    right = len(a)
    while right - left > 1:
        center = (left + right) // 2
        if a[center] >= key:
            right = center
        else:
            left = center
    return left+1 
    
def high_right(a, key):
    left = -1
    right = len(a)
    while right - left > 1:
        center = (left + right) // 2
        if a[center] <= key:
            left = center
        else:
            right = center
    return n-right
    
for i in bl:
    ans += low_left(al, i) * high_right(cl, i)

print(ans)

Solution (Python):
import bisect
n=int(input())
la=sorted(map(int,input().split()))
lb=sorted(map(int,input().split()))
lc=sorted(map(int,input().split()))
ans=0
for i in range(n):
  index1=bisect.bisect_left(la,lb[i])
  index2=bisect.bisect_right(lc,lb[i])
  ans+=index1*(n-index2)
print(ans)

Solution (Python):
import bisect
n=int(input())
la=sorted(map(int,input().split()))
lb=sorted(map(int,input().split()))
lc=sorted(map(int,input().split()))
countb=[]
count1=0
for i in range(n):
  index=bisect.bisect_left(la,lb[i])
  countb.append(index)
countb2=[]
sum=0
for i in range(n):
  sum+=countb[i]
  countb2.append(sum)
ans=0
for i in range(n):
  index=bisect.bisect_left(lb,lc[i])
  if index==0:
    pass
  else:
    ans+=countb2[index-1]
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()
b_i = [0]*n
c_i = [0]*n
for i in range(n):
    b1 = bisect.bisect_left(a,b[i])
    if i==0:
        b_i[i]=b1
    else:
        b_i[i] = b_i[i-1]+b1
    c1 = bisect.bisect_left(b,c[i])
    c_i[i]= c1

ans = 0
for i in range(n):
    if c_i[i]<1:
        continue
    else:
        ans = ans + b_i[c_i[i]-1]
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()
b_i = [0]*n
c_i = [0]*n
for i in range(n):
    b1 = bisect.bisect_left(a,b[i])
    if i==0:
        b_i[i]=b1
    else:
        b_i[i] = b_i[i-1]+b1
    c1 = bisect.bisect_left(b,c[i])
    c_i[i]= c1

ans = 0
for i in range(n):
    if c_i[i]<1:
        continue
    else:
        ans = ans + b_i[c_i[i]-1]
print(ans)

Solution (Python):

from bisect import bisect_left, bisect_right

N = int(input())

A_list = list((int(e) for e in input().split()))
B_list = list((int(e) for e in input().split()))
C_list = list((int(e) for e in input().split()))

A_list.sort(reverse=False)
B_list.sort(reverse=False)
C_list.sort(reverse=False)

ans = 0











for i in range(N):
    middle_size = B_list[i]
    top_count = bisect_left(A_list, middle_size)
    lower_count = N - bisect_right(C_list, middle_size)
    
    
    
    ans += top_count * lower_count

print(ans)

Solution (Python):
import bisect as bi
 
n = int(input())
lia = list(map(int,input().split()))
lib = list(map(int,input().split()))
lic = list(map(int,input().split()))
lia = sorted(lia)
lib = sorted(lib)
lic = sorted(lic)
 
ans = 0
for i in range(n):
  tmpa = bi.bisect_left(lia,lib[i])
  tmpc = n - bi.bisect_right(lic,lib[i])
  ans += tmpa*tmpc
print(ans)

Solution (Python):
import bisect

n = int(input())
a = sorted(list(map(int, input().split())))
b = sorted(list(map(int, input().split())))
c = sorted(list(map(int, input().split())))
cnt = 0
info1 = []


for i in range(n):
    b_p = bisect.bisect_left(a, b[i])
    info1.append(b_p) 

info2 = [info1[0]]
for l in range(1, n):
    info2.append(info2[l-1] + info1[l])

for k in range(n):
    a_p = bisect.bisect_left(b, c[k])
    if a_p != 0:
        cnt += info2[a_p - 1]  
print(cnt)

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

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

def BinaryIndexSearch_floor(p, SL):
	"""
	search the minimum number among the larger numbers than the ginven nymber "n". 
	return the index of it under the list sorted.
	"""
	
	l = 0
	r = len(SL) - 1

	while True:
		if l == r:
			if SL[l] > p:
				return l
			else:
				return -1
		elif r-l == 1:
			if SL[l] > p:
				return l
			elif SL[r] > p:
				return r
			else:
				return -1

		center = l + ((r-l) // 2)

		if SL[center] <= p:
			l = center + 1
			continue

		else:
			r = center
			continue

def BinaryIndexSearch_ceil(p, SL):
	
	l = 0
	r = len(SL) - 1

	while True:
		if l == r:
			if SL[l] < p:
				return l
			else:
				return -1
		elif r-l == 1:
			if SL[r] < p:
				return r
			elif SL[l] < p:
				return l
			else:
				return -1
		center = l + ((r-l) // 2)

		if SL[center] < p:
			l = center 
			continue

		else:
			r = center - 1
			continue

min_A = A[0]
max_C = C[-1]
ans = 0
for b in B:
	if not (min_A < b < max_C):
		continue

	a = BinaryIndexSearch_ceil(b,A)
	c = BinaryIndexSearch_floor(b,C)

	ans += (a+1) * (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()))))

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

Solution (Python):
n=int(input())
a=sorted(list(map(int,input().split())))
b=list(map(int,input().split()))
c=sorted(list(map(int,input().split())))
import bisect as bi
t=0
for i in b:
  x=n-bi.bisect_right(c,i)
  y=bi.bisect_left(a,i)
  t+=x*y
print(t)

Solution (Python):
N = int(input())
A = [int(a) for a in input().split()]
B = [int(b) for b in input().split()]
C = [int(c) for c in input().split()]

A.sort(reverse=True)
B.sort(reverse=True)
C.sort(reverse=True)

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

ans = 0
j = 0
for i in range(N):
    while j < N and B[j] > A[i]:
        j += 1
    if j > 0:
        ans += L[j-1]
    
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 bi in B:
    
    ai = bisect.bisect_left(A,bi)
    
    ci = len(C) - bisect.bisect_right(C,bi)

    ans += ai * ci

print(ans)

Solution (Python):
import bisect
n = int(input())
a,b,c = [sorted(map(int,input().split())) for _ in "abc"]
print(sum([bisect.bisect_left(a,x)*(n-bisect.bisect_right(c,x)) for x in b]))

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

print(ans)

Solution (Python):
import bisect as bi

n = int(input())
lia = list(map(int,input().split()))
lib = list(map(int,input().split()))
lic = list(map(int,input().split()))
lia = sorted(lia)
lib = sorted(lib)
lic = sorted(lic)

ans = 0
for i in range(n):
  tmpa = bi.bisect_left(lia,lib[i])
  tmpc = n - bi.bisect_right(lic,lib[i])
  ans += tmpa*tmpc
print(ans)

Solution (Python):

import sys



import bisect

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

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

if __name__ == "__main__":
    main()

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

N = int(input())
A = sorted([int(x) for x in input().strip().split()])
B = sorted([int(x) for x in input().strip().split()])
C = sorted([int(x) for x in input().strip().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()

BC = [0] * n  
pairs = 0
for i in range(n-1, -1, -1):
    b = B[i]
    idx = bisect.bisect_right(C, b)
    pairs += n - idx
    BC[i] = pairs

ans = 0
for a in A:
    idx = bisect.bisect_right(B, a)
    if idx == n:
        continue
    ans += BC[idx]

print(ans)

Solution (Python):

from bisect import bisect_left, bisect_right
si = lambda: input()
ni = lambda: int(input())
nm = lambda: map(int, input().split())
nl = lambda: list(map(int, input().split()))

N = ni()
A = nl()
B = nl()
C = nl()

A.sort()
C.sort()

ans = 0

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

print(ans)

Solution (Python):
def nibu_A(list,item):
    high=len(list)
    low=-1
    while abs(high-low) > 1:
        mid=(high+low)//2

        if list[mid] < item:
            low= mid
        else:
            high=mid
    return (low+1)
def nibu_c(list,item):
    high= len(list)
    low=-1
    while abs(high-low)>1:
        mid=(high+low)//2
        if list[mid]>item:
             high = mid
        else:
            low=mid
    return len(list)-high


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

ans=0
for i in range(n):
    data=B[i]
    ans+=(nibu_A(A,data)*nibu_c(C,data))
print(ans)

Solution (Python):
N=map(int,input().split())
A=sorted(list(map(int,input().split())))
B=list(map(int,input().split()))
C=sorted(list(map(int,input().split())))
 
def countA(target,L):
  ok=-1
  ng=len(L)
  while abs(ok-ng)>1:
    mid=(ok+ng)//2
    if L[mid]<target:
      ok=mid
    else:
      ng=mid
  return (ok+1)
 
def countC(target,L):
  ok=len(L)
  ng=-1
  while abs(ok-ng)>1:
    mid=(ok+ng)//2
    if L[mid]>target:
      ok=mid
    else:
      ng=mid
  return len(L)-ok
 
ans=0
for i in range(len(B)):
  data=B[i]
  ans+=(countA(data,A)*countC(data,C))
  
print(ans)

Solution (Python):
def low_left(ls,key):
    left,right = -1,len(ls)
    while right - left > 1:
        mid = (right+left)//2
        if ls[mid] >= key:
            right = mid
        else:
            left = mid
    return left+1


def high_right(ls,key):
    left,right = -1,len(ls)
    while right - left > 1:
        mid = (right+left)//2
        if ls[mid]<=key:
            left = mid
        else:
            right = mid
    return right


def test():
    n = int(input())
    A,B,C = [list(sorted((map(int,input().split())))) for i in range(3)]
    ans = 0

    for b in B:
        ans += (n-high_right(C,b))*low_left(A,b)
    print(ans)


if __name__ == "__main__":
    test()

Solution (Python):
from bisect 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()
data=[0]*n
for i in range(n):
    l=bisect(c,b[i])
    data[i]=n-l
data+=[0]
for i in range(n):
    data[n-i-1]+=data[n-i]
ans=0
for i in range(n):
    l=bisect(b,a[i])
    ans+=data[l]
print(ans)

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

def countA(target,L):
  ok=-1
  ng=len(L)
  while abs(ok-ng)>1:
    mid=(ok+ng)//2
    if L[mid]<target:
      ok=mid
    else:
      ng=mid
  return (ok+1)

def countC(target,L):
  ok=len(L)
  ng=-1
  while abs(ok-ng)>1:
    mid=(ok+ng)//2
    if L[mid]>target:
      ok=mid
    else:
      ng=mid
  return len(L)-ok

ans=0
for i in range(len(B)):
  data=B[i]
  ans+=(countA(data,A)*countC(data,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()

count = 0

for i in b:
    x = bisect.bisect_left(a, i)
    y = bisect.bisect_right(c, i)
    count += x * (len(c) - y)

print(count)

Solution (Python):
import sys
import bisect
n = int(input())
a_ls = [int(i) for i in sys.stdin.readline().split()]
b_ls = [int(i) for i in sys.stdin.readline().split()]
c_ls = [int(i) for i in sys.stdin.readline().split()]
a_ls.sort()
b_ls.sort()
c_ls.sort()
comb_a = []
comb_b = []
len_b = len(b_ls)
len_c = len(c_ls)
for a in a_ls:
    ind = len_b - bisect.bisect_right(b_ls, a)
    comb_a.append(ind)

prod_b = []
res = 0
for b in b_ls[::-1]:
    ind = len_c - bisect.bisect_right(c_ls, b)
    comb_b.append(ind)
    res += ind
    prod_b.append(res)
comb_b = comb_b[::-1]
_sum = 0
for a in comb_a:
    if a <= 0:
        continue
    _sum += prod_b[a-1]
print(_sum)

Solution (Python):
def upper_bound(ar, val):
    low = 0
    high = len(ar)
    while low < high:
        mid = (low + high) >> 1
        if val >= ar[mid]:
            low = mid + 1
        else:
            high = mid
    return low


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] * n
greater_a = [0] * n
for i in range(n):
    greater_a[i] = upper_bound(b, a[i])
    count[i] = n - upper_bound(c, b[i])
prefix = [0] * n
prefix[n - 1] = count[n - 1]
for k in range(n - 2, -1, -1):
    prefix[k] = prefix[k + 1] + count[k]
total = 0
for k in range(n):
    if greater_a[k] < n:
        total += prefix[greater_a[k]]
print(total)

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()
len_c = len(list_c)
result = 0
for one_b in list_b:
  place_a = bisect.bisect_left(list_a, one_b)
  place_c = bisect.bisect_right(list_c, one_b)
  result += place_a * (len_c - place_c)
print(result)

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


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()
    C.sort()

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


if __name__ == '__main__':
    main()

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

    for b in B:
        ans += low_left(A,b) * (n-high_right(C,b))
    print(ans) 


def low_left(ls,t):
    low,high = 0,len(ls)
    while low<high:
        mid = (low+high)//2
        if ls[mid] < t:
            low = mid + 1
        else:
            high = mid
    return low


def high_right(ls,t):
    low,high = 0,len(ls)
    while low<high:
        mid = (low+high)//2
        if ls[mid] > t:
            high = mid
        else:
            low = mid + 1
    return low


if __name__ == "__main__":
    test()

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

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(' '))))
    c_len=len(c)
    ans = 0
    for i in b:
        ans_a=bisect.bisect_left(a,i)
        ans_c=c_len-bisect.bisect_right(c,i)
        ans += ans_a*ans_c
    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()

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


print(result)

Solution (Python):

import sys
import bisect

def solve(N: int, A: "List[int]", B: "List[int]", C: "List[int]"):
    A.sort()
    C.sort()
    answer = 0
    for i in range(N):
        A_index = bisect.bisect_left(A,B[i])
        C_index = bisect.bisect_left(C,B[i]+1) 
        answer += (N-C_index)*A_index
    print(answer)

    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  
    A = [int(next(tokens)) for _ in range(N)]  
    B = [int(next(tokens)) for _ in range(N)]  
    C = [int(next(tokens)) for _ in range(N)]  
    solve(N, A, B, C)

if __name__ == '__main__':
    main()

Solution (Python):

import sys
import bisect

def solve(N: int, A: "List[int]", B: "List[int]", C: "List[int]"):
    A.sort()
    B.sort()
    C.sort()
    answer = 0
    for i in range(N):
        A_index = bisect.bisect_left(A,B[i])
        C_index = bisect.bisect_left(C,B[i]+1) 
        answer += (N-C_index)*A_index
    print(answer)

    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  
    A = [int(next(tokens)) for _ in range(N)]  
    B = [int(next(tokens)) for _ in range(N)]  
    C = [int(next(tokens)) for _ in range(N)]  
    solve(N, A, B, C)

if __name__ == '__main__':
    main()

Solution (Python):
import bisect as bi

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 Bi in B:
    a=bi.bisect_left(A,Bi)
    c=N-bi.bisect_right(C,Bi)
    ans+=a*c

print(ans)

Solution (Python):
import sys
from itertools import accumulate
import bisect
N = int(input())
A = [int(x) for x in input().split()]
B = [int(x) for x in input().split()]
C = [int(x) for x in input().split()]
A.sort()
B.sort()
C.sort()
Bsum=[0]*(N+1)
for i in range(N):
  Bsum[i+1] = N-bisect.bisect_right(C,B[i])
Bsum=list(accumulate(Bsum))
ans = 0
for i in range(N):
  a = bisect.bisect_right(B,A[i])
  ans += Bsum[-1]-Bsum[a]
print(ans)

Solution (Python):
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 
from bisect import bisect_left as bl,bisect_right as br 
for i in b: 
    left=bl(a,i)
    right=n-br(c,i)
    ans+=left*right 
print(ans)

Solution (Python):
import sys
from bisect import bisect_left, bisect_right
inout = sys.stdin.readline

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())))
    
    ans = 0
    for Bi in B:
        Ai = bisect_left(A, Bi)
        Ci = N - bisect_right(C, Bi)
        ans += (Ai*Ci)

    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
b_li = [0 for i in range(n)]

for b in range(n):    
    index = bisect.bisect_left(C, B[b]+1)
    b_li[b] = n-index

for b in range(n-2,-1,-1):
    b_li[b] += b_li[b+1]
b_li.append(0)

for a in range(n):    
    index = bisect.bisect_left(B, A[a]+1)

    ans += b_li[index]
    
        
    

print(ans)

Solution (Python):
import sys
from bisect import bisect_left, bisect_right
inout = sys.stdin.readline

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())))
    
    ans = 0
    for Bi in B:
        Ai = bisect_left(A, Bi)
        Ci = N - bisect_right(C, Bi)
        ans += (Ai*Ci)

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

print(ans)