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


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



def isok_A(index, key, arr):
    if arr[index] >= key:
        return True
    else:
        return False
 
def Binary_search_A(key, arr):
    
    ng = -1
    ok = len(arr)
    while ok - ng > 1:
        mid = (ok + ng) // 2
        if isok_A(mid, key, arr) is True:
            ok = mid
        else:
            ng = mid
    
    return ng, ok

def isok_B(index, key, arr):
    if arr[index] > key:
        return True
    else:
        return False

def Binary_search_B(key, arr):
    
    ng = -1
    ok = len(arr)
    while ok - ng > 1:
        mid = (ok + ng) // 2
        if isok_B(mid, key, arr) is True:
            ok = mid
        else:
            ng = mid
    
    return ng, ok

cnt = 0
for i in B:
    ng_a, ok_b = Binary_search_A(i, A)
    ng_c, ok_c = Binary_search_B(i, C)
    cnt += (ng_a + 1) * (N - ok_c)
print(cnt)

Solution (Python):
import bisect

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

A,B,C = sorted(A),sorted(B),sorted(C)

for b in B:
  a = bisect.bisect_left(A,b)
  c = bisect.bisect_right(C,b)
  ans += a*(N-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())))
  ans=0
  for b in B:
    a=bisect.bisect_left(A,b)
    c=N-bisect.bisect_right(C,b)
    ans+=a*c
  print(ans)
  
if __name__=="__main__":
  main()

Solution (Python):
n=int(input())
a=list(map(int,input().split()))
a.sort()
b=list(map(int,input().split()))
b.sort()
c=list(map(int,input().split()))
c.sort()
ans=0
import bisect
for bb in b:
  ao=bisect.bisect(a,bb-1)
  cnta=ao
  cs=bisect.bisect(c,bb)
  cntc=n-cs
  ans+=cnta*cntc
print(ans)

Solution (Python):
n=int(input())
a=list(map(int,input().split()))
a.sort()
b=list(map(int,input().split()))
b.sort()
c=list(map(int,input().split()))
c.sort()
ans=0
import bisect
for i in range(n):
    x=bisect.bisect_left(a,b[i])
    y=bisect.bisect_right(c,b[i])
    ans+=x*(n-y)
print(ans)

Solution (Python):
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()
b.sort()
c.sort()
len_c = len(c)
total = 0
for num in b:
    idx_a = bisect_left(a, num)
    idx_c = bisect_right(c, num)
    cnt = idx_a * (len_c - idx_c)
    total += cnt
print(total)

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

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

    ans = 0
    for b in B:
        n_a = bisect_left(A, b)
        n_c = N - bisect_right(C, b)
        ans += n_a * n_c

    print(ans)


if __name__ == "__main__":
    main()

Solution (Python):
import sys

import numba as nb
import numpy as np

input = sys.stdin.readline


@nb.njit("i8(i8[:],i8)", cache=True)
def binary_search(a, key):
    """Meguru type binary search"""
    ng = -1
    ok = len(a)

    def is_ok(a, key, idx):
        if a[idx] > key:
            return True
        else:
            return False

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

    return ok


@nb.njit("i8(i8,i8[:],i8[:],i8[:])", cache=True)
def solve(N, A, B, C):
    A.sort()
    B.sort()
    C.sort()

    BC = np.zeros(shape=N + 1, dtype=np.int64)
    for i in range(N):
        BC[i] = N - binary_search(C, B[i])

    ans = 0
    for a in A:
        idx = binary_search(B, a)
        ans += np.sum(BC[idx:])

    return ans


def main():
    N = int(input())
    A = np.array(input().split(), dtype=np.int64)
    B = np.array(input().split(), dtype=np.int64)
    C = np.array(input().split(), dtype=np.int64)

    ans = solve(N, A, B, C)
    print(ans)


if __name__ == "__main__":
    main()

Solution (Python):













from sys import stdin
from operator import itemgetter
from collections import deque, Counter
import math
import pprint
from functools import reduce
import numpy as np
import random
import bisect



MOD = 1000000007
INF = float('inf')
alpha = ["a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"]

def keta(kazu): 
    kazu_str = str(kazu)
    kazu_list = [int(kazu_str[i]) for i in range(0, len(kazu_str))]
    return kazu_list

def gcd(*numbers): 
    return reduce(math.gcd, numbers)

def combination(m,n): 
    
    if n > m:
        return 'すまん'
    return math.factorial(m) // (math.factorial(m-n) * math.factorial(n))

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 fact(n): 
    arr = {}
    temp = n
    for i in range(2,int(n**0.5)+1):
        if temp % i == 0:
            cnt = 0
            while temp % i == 0:
                cnt += 1
                temp //= i
            arr[i] = cnt
    if temp != 1:
        arr[temp] = 1
    if arr == {}:
        arr[n] = 1
    return arr


    
def main():
    n = int(stdin.readline().rstrip())
    a_kari = list(map(int,[int(x) for x in stdin.readline().rstrip().split()]))
    a = sorted(a_kari)
    b_kari = list(map(int,[int(x) for x in stdin.readline().rstrip().split()]))
    b = sorted(b_kari)
    c_kari = list(map(int,[int(x) for x in stdin.readline().rstrip().split()]))
    c = sorted(c_kari)
    board_ab = [0] * n
    board_bc = [0] * n
    ans = 0
    
    for i in range(n):
        ab = bisect.bisect_left(a, b[i])
        bc = n - bisect.bisect_right(c, b[i])
        ans += ab * bc
        
    print(ans)
    
main()

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

Solution (Python):
import sys
import math
import itertools
import bisect
from copy import copy,deepcopy
from collections import deque,Counter
from decimal import Decimal
def s(): return input()
def i(): return int(input())
def S(): return input().split()
def I(): return map(int,input().split())
def L(): return list(map(int,input().split()))
def l(): return list(map(int,input().split()))
def lcm(a,b): return a*b//math.gcd(a,b)
sys.setrecursionlimit(10 ** 9)
INF = 10**9
mod = 10**9+7

N = i()
C = l()
B = l()
A = l()
B.sort()
C.sort()
l = []
for i in range(N):
    l.append(bisect.bisect_left(C,B[i]))
ruiseki = [0]+list(itertools.accumulate(l))
ans = 0
for i in range(N):
    num = bisect.bisect_left(B,A[i])
    ans += ruiseki[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())))
counter = 0
for i in range(len(B)):
    
    Ind_A = bisect.bisect_left(A,B[i])
    if A[Ind_A-1] == B[i]:
        Ind_A -= 1
    
    
    Ind_C = bisect.bisect_right(C,B[i])
    num_C = len(C)-Ind_C
    counter += round(Ind_A*num_C)
    
    
    
    
    
print(counter)

Solution (Python):
import sys

import time


def main():
        n = sys.stdin.readline()

        astr = sys.stdin.readline()
        bstr = sys.stdin.readline()
        cstr = sys.stdin.readline()

        a = list(map(int, astr.strip().split(' ')))
        b = list(map(int, bstr.strip().split(' ')))
        c = list(map(int, cstr.strip().split(' ')))

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

        cnt = 0

        bc = []
        sum = 0
        timesum = 0
        for bi in reversed(b):
                sum += len(c) - binary(bi,c)
                bc.append(sum)
        bc.reverse()

        cnt = 0
        for ai in a:
                bi = binary(ai, b)
                if(bi < len(bc)):
                    cnt += bc[bi]

        print(cnt)


def binary(x, li):
    upper = len(li)
    lower = -1
    index = int((upper + lower) / 2)

    while upper - lower > 1:
        if (x < li[index]):
            upper = index
        else:
            lower = index
        index = int((upper + lower)/2)
    
    return upper


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

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

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

count=0
for i in B :
    a=bisect.bisect_left(A,i)
    c=bisect.bisect_right(C,i)
    p=a*(N-c)
    count+=p

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()))
al=sorted(a)
bl=sorted(b)
cl=sorted(c)
 
abl=[0]*n
bcl=[0]*n
i=n-1
for j in range(n-1,-1,-1):
    if i==-1:
        abl[j]=0
        continue
    while al[i]>=bl[j]:
        i-=1
        if i==-1:
            break
    if i==-1:
        abl[j]=0
    else:
        abl[j]=i+1
k=0
for j in range(n):
    if k==n:
        bcl[j]=0
        continue
    while cl[k]<=bl[j]:
        k+=1
        if k==n:
            break
    if k==n:
        bcl[j]=0
    else:
        bcl[j]=(n-k)
ans=0
for s in range(n):
    ans+=abl[s]*bcl[s]
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()))
al=sorted(a)
bl=sorted(b)
cl=sorted(c)
 
abl=[0]*n
bcl=[0]*n
i=n-1
for j in range(n-1,-1,-1):
    if i==-1:
        abl[j]=0
        continue
    while al[i]>=bl[j]:
        i-=1
        if i==-1:
            break
    if i==-1:
        abl[j]=0
    else:
        abl[j]=i+1
j=0
bcl=[0]*n
k=0
for j in range(n):
    if k==n:
        bcl[j]=0
        continue
    while cl[k]<=bl[j]:
        k+=1
        if k==n:
            break
    if k==n:
        bcl[j]=0
    else:
        bcl[j]=(n-k)
ans=0
for s in range(n):
    ans+=abl[s]*bcl[s]
print(ans)

Solution (Python):
N=int(input())
A=list(map(int,input().split()))
B=list(map(int,input().split()))
C=list(map(int,input().split()))
A.sort()
C.sort()
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-(ng+1)
    ans+=A_num*C_num
print(ans)

Solution (Python):
from bisect import bisect_left, bisect_right
n=int(input())
a=sorted(map(int,input().split()))
b=sorted(map(int,input().split()))
c=sorted(map(int,input().split()))

ans=0
for i in range(n):
    s=b[i]
    upper=bisect_left(a,s)
    lower=n-bisect_right(c,s)
    ans+=(upper*lower)

print(ans)

Solution (Python):
import bisect
N=int(input())
A=list(map(int,input().split()))
B=list(map(int,input().split()))
C=list(map(int,input().split()))
A.sort()
B.sort()
C.sort()
ans=0
for i in range(N):
  a=bisect.bisect_left(A,B[i])
  b=N-bisect.bisect_right(C,B[i])
  if b==0:
    break
  ans+=a*b
print(ans)

Solution (Python):
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()
C.sort()
ans = 0

for i in range(N):
  def meguru_bisect_A(ng, ok):
    def is_ok(idx):
      return A[idx] < B[i]

    while (abs(ok - ng) > 1):
      mid = (ok + ng) // 2
      if is_ok(mid):
        ok = mid
      else:
        ng = mid
    return ok

  def meguru_bisect_C(ng, ok):
    def is_ok(idx):
      return B[i] < C[idx]

    while (abs(ok - ng) > 1):
      mid = (ok + ng) // 2
      if is_ok(mid):
        ok = mid
      else:
        ng = mid
    return ok
  
  ans += (meguru_bisect_A(N, -1)+1) * (N - meguru_bisect_C(-1, N))

print(ans)

Solution (Python):
import bisect

N=int(input())
A=list(map(int,input().split()))
A=sorted(A)
B=list(map(int,input().split()))
B=sorted(B)
C=list(map(int,input().split()))
C=sorted(C)
count=0
for num in (B):
    a=bisect.bisect_left(A,num)
    b=bisect.bisect_right(C,num)
    count+=a*(N-b)

print(count)

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

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

Solution (Python):


def get_input() -> tuple:
    """
    標準入力を取得する.

    Returns:\n
        tuple: 標準入力
    """
    N = int(input())
    A = list(map(int, input().split()))
    B = list(map(int, input().split()))
    C = list(map(int, input().split()))

    return N, A, B, C


def get_lb(l: list, key: int) -> int:
    """
    l[index] > keyとなる最小のindexを求める.

    Args:\n
        l (list): リスト
        key (int): 整数

    Returns:\n
        int: l[index] > keyとなる最小のindex
    """
    low = -1
    high = len(l)
    while 1 < high - low:
        mid = (low + high) // 2
        guess = l[mid]
        if guess > key:
            high = mid
        else:
            low = mid
    return high


def get_ub(l: list, key: int) -> int:
    """
    l[index] < keyとなる最大のindexを求める.

    Args:\n
        l (list): リスト
        key (int): 整数

    Returns:\n
        int: l[index] < keyとなる最大のindex
    """
    low = -1
    high = len(l)
    while 1 < high - low:
        mid = (low + high) // 2
        guess = l[mid]
        if guess < key:
            low = mid
        else:
            high = mid
    return low


def main(N: int, A: list, B: list, C: list) -> None:
    """
    メイン処理.

    Args:\n
        N (int): パーツの数
        A (list): 上部のパーツのサイズ
        B (list): 中部のパーツのサイズ
        C (list): 下部のパーツのサイズ
    """
    
    A = sorted(A)
    B = sorted(B)
    C = sorted(C)

    
    ans = 0
    for i in range(N):
        B_i = B[i]
        ans += (get_ub(A, B_i) + 1) * (N - get_lb(C, B_i))

    
    print(ans)


if __name__ == "__main__":
    
    N, A, B, C = get_input()

    
    main(N, A, B, C)

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

Solution (Python):
def binary_search_low(ls, v):
    """
    ・基準(v)より小さい値が配列の中に何個あるか, 二分探索によって見つける.
    [input]
        ls: 二分探索するリスト(配列)
        v: 探索の基準となる値
    [output]
        return: 基準を満たす配列の要素数
    """
    ok = -1
    ng = n

    while (abs(ok - ng) > 1):
        mid = (ok + ng) // 2
        if ls[mid] < v: ok = mid
        else: ng = mid
        
    return ok+1
    
def binary_search_high(ls, v):
    """
    ・基準(v)より大きい値が配列の中に何個あるか, 二分探索によって見つける.
    [input]
        ls: 二分探索するリスト(配列)
        v: 探索の基準となる値
    [output]
        return: 基準を満たす配列の要素数
    """
    ng = -1
    ok = n

    while (abs(ok - ng) > 1):
        mid = (ok + ng) // 2
        if ls[mid] > v: ok = mid
        else: ng = mid
        
    return len(ls) - ok


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_count = binary_search_low(A,b)
    b_count = binary_search_high(C, b)
    ans += a_count*b_count

print(ans)

Solution (Python):
def binary_search_low(ls, v):
    """
    [input]
        ls: 二分探索するリスト(配列)
        v: 探索の基準となる値
    [output]
        ok: 基準を満たす最大index
        (ng: 基準を満たさない最小index)
    """
    ok = -1
    ng = n

    while (abs(ok - ng) > 1):
        mid = (ok + ng) // 2
        if ls[mid] < v: ok = mid
        else: ng = mid
        
    return ok  
    
def binary_search_high(ls, v):
    """
    [input]
        ls: 二分探索するリスト(配列)
        v: 探索の基準となる値
    [output]
        ok: 基準を満たす最大index
        (ng: 基準を満たさない最小index)
    """
    ng = -1
    ok = n

    while (abs(ok - ng) > 1):
        mid = (ok + ng) // 2
        if ls[mid] > v: ok = mid
        else: ng = mid
        
    return ok


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_count = binary_search_low(A,b) + 1
    b_count = n - binary_search_high(C, b)
    

    ans += a_count*b_count


print(ans)

Solution (Python):
def main():
    _ = 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_accum = []
    ans = 0

    for b in B:
        num = binary_search(A, b) + 1
        B_.append((b, num))

    tmp_sum = 0
    for b_ in B_:
        tmp_sum += b_[1]
        B_accum.append(tmp_sum)

    for c in C:
        b_idx = binary_search_tuple(B_, c)
        if b_idx >= 0:
            ans += B_accum[b_idx]
    print(ans)


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


def binary_search_tuple(A, x):
    ok = -1
    ng = len(A)
    while abs(ok - ng) > 1:
        mid = (ok + ng) // 2
        if A[mid][0] < x:
            ok = mid
        else:
            ng = mid
    return ok


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

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

print(cnt)

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

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

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

print(ans)

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

A.sort()

C.sort()
countA = [0]*(N+1)
countC = [0]*(N+1)

ans = 0
for b in range(N):
    countA = bisect.bisect_left(A, B[b])
    countC = N - bisect.bisect_right(C, B[b])
    ans += countA*countC
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:
    n_lower_B = bisect.bisect_left(A, b)
    n_higher_B = N - bisect.bisect_right(C, b)
    ans += n_lower_B * n_higher_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
C = len(c)


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

ans = 0
C = len(c)


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

ans = 0
C = len(c)


for i in b:
    ans += (bisect.bisect_right(a,i-1))*(C-bisect.bisect_left(c,i+1))

print(ans)

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

Solution (Python):
from bisect import *
n = int(input())
A = [*map(int, input().split())]
B = [*map(int, input().split())]
C = [*map(int, input().split())]
A.sort()
C.sort()
ans = 0
for b in B:
    ia = bisect_left(A, b)
    ic = bisect_right(C, b)
    ans += ia * (n-ic)
print(ans)

Solution (Python):
from bisect import *
n = int(input())
A = [*map(int, input().split())]
B = [*map(int, input().split())]
C = [*map(int, input().split())]
A.sort()
C.sort()

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

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

Solution (Python):
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:
    if b <= A[0] or b >= C[N-1]:
        continue
    
    l, r = -1, N
    while abs(l - r) > 1:
        mid = (l + r) // 2
        if A[mid] < b:
            l = mid
        else:
            r = mid
    
    l2, r2 = -1, N
    while abs(l2 - r2) > 1:
        mid = (l2 + r2) // 2
        if C[mid] > b:
            r2 = mid
        else:
            l2 = mid
    ans += (l+1) * (N - r2)
print(ans)

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

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

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

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

print(ans)

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())))
ans = 0
for i in range(N):
    
    ok = -1
    ng = N
    while ng-ok>1:
        mid = (ok + ng)//2
        if A[mid]<B[i]:
            ok = mid
        else:
            ng = mid
    
    
    ok2 = N
    ng2 = -1
    while ok2-ng2>1:
        mid2 = (ok2+ng2)//2
        if C[mid2] > B[i]:
            ok2 = mid2
        else:
            ng2 = mid2
    
    ans += (ok+1)*(N-ok2)

print(ans)

Solution (Python):
import bisect

n = int(input())
aa = list(sorted(map(int, input().split())))
bb = list(sorted(map(int, input().split())))
cc = list(sorted(map(int, input().split())))

ans = 0
for b in bb:
    ax = bisect.bisect_left(aa, b)
    ci = bisect.bisect(cc, b)
    cx = len(cc) - ci
    ans += ax * cx
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()
B.sort()
C.sort()
ans = 0
for b in B:
    a = bisect_left(A, b)
    c = bisect_right(C, b)
    ans += a*(N-c)
print(ans)

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

Solution (Python):
import numpy as np
import scipy.sparse as sps
import scipy.misc as spm
import collections as col
import functools as func
import itertools as ite
import fractions as frac
import math as ma
from math import cos,sin,tan,sqrt
import cmath as cma
import copy as cp
import sys
import re
import bisect as bs
sys.setrecursionlimit(10**7)
EPS = sys.float_info.epsilon
PI = np.pi; EXP = np.e; INF = np.inf
MOD = 10**9 + 7

def sinput(): return sys.stdin.readline().strip()
def iinput(): return int(sinput())
def imap(): return map(int, sinput().split())
def fmap(): return map(float, sinput().split())
def iarr(n=0):
    if n: return [0 for _ in range(n)]
    else: return list(imap())
def farr(): return list(fmap())
def sarr(n=0):
    if n: return ["" for _ in range(n)]
    else: return sinput().split()
def adj(n): return [[] for _ in range(n)]




n = iinput()
a = sorted(iarr())
b = sorted(iarr())
c = sorted(iarr())

cnt = 0
for bb in b:
    avar = bs.bisect_left(a,bb) 
    cvar = n - bs.bisect_right(c,bb) 
    cnt += avar * cvar
print(cnt)

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

ans = 0

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

print(ans)

Solution (Python):
from bisect import bisect_left

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

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





A_B = []

for i in range(n):
    A_B.append(bisect_left(A, B[i]))

ruisekiwa = [A_B[0]]
for i in range(1, n):
    ruisekiwa.append(ruisekiwa[-1] + A_B[i])




ans = 0

for i in range(n):
    idx = bisect_left(B, C[i])
    if idx:
        ans += ruisekiwa[idx-1]

print(ans)

Solution (Python):
import sys
import itertools

import time
import math
 
sys.setrecursionlimit(10 ** 7)
 
from collections import defaultdict
 
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

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

ans = 0
for i, b in enumerate(B):
    left = -1
    right = N
    while (right - left) > 1:
        mid = left + (right - left) // 2
        if C[mid] > b:
            right = mid
        else:
            left = mid
    Cs = N - right

    left = -1
    right = N
    while (right - left) > 1:
        mid = left + (right - left) // 2
        if A[mid] >= b:
            right = mid
        else:
            left = mid
    As = right
    ans += As * Cs
print(ans)

Solution (Python):
import sys
import itertools

import time
import math
 
sys.setrecursionlimit(10 ** 7)
 
from collections import defaultdict
 
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

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

base = [0] * N
for i, b in enumerate(B):
    left = -1
    right = N
    while (right - left) > 1:
        mid = left + (right - left) // 2
        if C[mid] > b:
            right = mid
        else:
            left = mid
    base[i] = N - right

acc = [0] * (N + 1)
for i in range(1, N + 1):
    acc[i] = acc[i - 1] + base[i - 1]

ans = 0
for i, a in enumerate(A):
    left = -1
    right = N
    while right - left > 1:
        mid = left + (right - left) // 2
        if B[mid] > a:
            right = mid
        else:
            left = mid
    ans += acc[N] - acc[right]
print(ans)

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

ans = 0
for b in bl:
    
    a_cnt = bisect_left(al,b)
    
    c_cnt = n - bisect_right(cl,b)
    ans += a_cnt*c_cnt

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

ans = 0
for b in bl:
    
    a_cnt = bisect_left(al,b)
    
    c_cnt = n - bisect_right(cl,b)
    ans += a_cnt*c_cnt

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()
lb = [0] * (len(B)+1)
lsum = [0] * (len(B)+1)
temp = 0
for i in range(len(B)):
    lb[i]= bisect.bisect_left(A,B[i])
    
for i in range(len(B)):
    lsum[i] = lb[i] +lsum[i-1]


ans = 0    
for i in range(len(C)):
    temp = bisect.bisect_left(B,C[i])
    ans +=lsum[temp-1]


print(ans)