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):
from bisect import bisect_left, bisect_right

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


ans = 0
for i in range(N):
  la = bisect_left(A, B[i])
  rc = N - bisect_right(C, B[i])
  ans += la * rc
  
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()
b.sort()
c.sort()
num=[[0]*n for _ in range(3)]
from bisect import bisect_right as bl

for i in range(n):
    t=bl(b,a[i])
    if t==n:
        continue
    num[0][t]+=1

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

for i in range(n):
    t=bl(c,b[i])
    if t==n:
        continue
    num[1][t]+=num[0][i]


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

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

print(sum(num[1]))

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

B.sort()
C.sort()

BtoC = [0 for i in range(N)]

for i in range(N-1,-1,-1):
    x = bisect.bisect_right(C,B[i])
    if i == N-1:
        BtoC[i] = N-x
    else:
        BtoC[i] = BtoC[i+1]+N-x



ans = 0

for a in A:
    y = bisect.bisect_right(B,a)
    if y != N:
        ans += BtoC[y]

print(ans)

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

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

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

print(ans)

Solution (Python):

from bisect import bisect_left, bisect_right

N = int(input())
A = list(int(i) for i in input().split())  
B = list(int(i) for i in input().split())  
C = list(int(i) for i in input().split())


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

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

Solution (Python):
from bisect import bisect_left, bisect_right

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

ans = 0

for b in B:
  
  left = bisect_left(A, b)
  
  right = bisect_right(C, b)
  
  ans += left*(N-right)
  
print(ans)

Solution (Python):

from bisect import bisect_left
from bisect import bisect_right
from bisect import bisect

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

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

AtoB = []
for e in A:
    b_search = bisect_right(B,e)
    b_pattern = N-b_search
    AtoB.append(b_pattern)
BtoC = []
for e in B:
    c_search = bisect_right(C,e)
    c_pattern = N-c_search
    BtoC.append(c_pattern)
cs = [0]
for e in reversed(BtoC):
    cs.append(e+cs[-1])
cs = cs[1:]
for e in AtoB:
    if e == 0:
        continue
    ans += cs[e-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()

A_B = [0]*N
B_C = [0]*N

for i in range(N):
    index = bisect.bisect_left(A,B[i])
    A_B[i] = index 

for i in range(N):
    index = bisect.bisect_right(C,B[i])
    B_C[i] = len(C)-index

sum = 0
for i in range(N):
    sum = sum + B_C[i]*A_B[i]

print(sum)

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

import bisect
bbl = []
import bisect

for b in bl:
   idx = bisect.bisect_right(cl,b)
   bbl.append(n-idx)
aal = []
for a in al:
   idx = bisect.bisect_right(bl,a)
   aal.append(idx)
import itertools
bbl = list(itertools.accumulate(bbl[::-1]))[::-1]
bbl.append(0)
ans = 0
for a in aal:
   ans += bbl[a] 
print(ans)

Solution (Python):
from bisect import bisect_left, bisect_right


def solve():
    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):
        cnt_a = bisect_left(A, B[i])
        cnt_b = N - bisect_right(C, B[i])
        ans += cnt_a * cnt_b
    print(ans)


if __name__ == '__main__':
    solve()

Solution (Python):
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools
from collections import deque

sys.setrecursionlimit(10**7)
inf = 10**20
mod = 10**9 + 7

DR = [1, -1, 0, 0]
DC = [0, 0, 1, -1]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
     
def main():
    N = I()
    A = sorted(LI())
    B = sorted(LI())
    C = sorted(LI())
    cnt = 0
    B_lt_A = [0] * N
    C_lt_B = [0] * N

    b_ix = 0
    for a_ix, a in enumerate(A):
        while b_ix < N and a >= B[b_ix]:
            b_ix += 1
        B_lt_A[a_ix] = N - b_ix

    c_ix = 0
    for b_ix, b in enumerate(B):
        while c_ix < N and b >= C[c_ix]:
            c_ix += 1
        C_lt_B[b_ix] = N - c_ix
    cumsum = [0] * (N+1)
    for i in range(N):
        cumsum[i+1] = cumsum[i] + C_lt_B[i]

    for i in range(N):
        B_lt_A[i] = N - B_lt_A[i]
    for c_ix in B_lt_A:
        cnt += (cumsum[-1] - cumsum[c_ix])

    print(cnt)
main()

Solution (Python):
from sys import stdin
import bisect
n = int(stdin.readline().rstrip())
top = sorted(list(map(int, stdin.readline().rstrip().split())))
middle = sorted(list(map(int, stdin.readline().rstrip().split())))
bottom = sorted(list(map(int, stdin.readline().rstrip().split())))

res = 0

for j in middle:
    res += bisect.bisect_left(top, j) * (n - bisect.bisect_right(bottom, j))

print(res)

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

count = 0

for b in B:
    index_b = bisect.bisect_left(A, b)
    index_c = bisect.bisect_right(C, b)
    count += (N - index_c) * index_b

print(count)

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

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

def bisA(x,vec):
   left_index_OK=-1
   right_index_NG=len(vec)
   while(left_index_OK<right_index_NG-1):
      mid=int((left_index_OK+right_index_NG)/2)
      if x > vec[mid]:
         left_index_OK=mid
      else:
         right_index_NG=mid
   
   return left_index_OK

def bisC(x,vec):
   left_index_NG=-1
   right_index_OK=len(vec)
   while(left_index_NG<right_index_OK-1):
      mid=int((left_index_NG+right_index_OK)/2)
      if x < vec[mid]:
         right_index_OK=mid
      else:
         left_index_NG=mid
   
   return right_index_OK

alltypes=0
atypes=0
ctypes=0
for i in range(N):
   b=B[i]
   if b<=A[0]:
      continue
   else:
      atypes=bisA(b,A)+1
      ctypes=len(C)-bisC(b,C)
      alltypes+=atypes*ctypes

print(alltypes)

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()
AB=[0]*N
BC=[0]*N

i=0
j=0
while j<N:
  while i<N and A[i]<B[j]:
    i+=1
  AB[j]=i
  j+=1
  
ABs=[0]*(N+1)
for i in range(1, N+1):
  ABs[i]=ABs[i-1]+AB[i-1]
  
i=0
j=0
out=0
while j<N:
  while i<N and B[i]<C[j]:
    i+=1
  BC[j]=ABs[i]
  j+=1
  
print(sum(BC))

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

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

def main():
    a.sort()
    b.sort()
    c.sort()
    res = 0
    for i in b:
        cnt_a = bi_l(a, i)
        cnt_c = n - bi_r(c, i)
        res += cnt_a * cnt_c
 
    return res
    
if __name__ == '__main__':
    ans = main()
    print(ans)

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

ans = 0

def bisect(array, threshold, equal=False):
    OK = -1
    NG = N
    while NG - OK > 1:
        mid = (OK + NG) // 2
        if array[mid] < threshold:
            OK = mid
        elif equal == True and array[mid] == threshold:
            OK = mid
        else:
            NG = mid
    return OK + 1

for i in B:
    ans += bisect(A, i) * (N - bisect(C, i, True))

print(ans)

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

ans = 0

def bisect(array, threshold, equal=False):
    OK = -1
    NG = N
    while NG - OK > 1:
        mid = (OK + NG) // 2
        if array[mid] < threshold:
            OK = mid
        elif equal == True and array[mid] == threshold:
            OK = mid
        else:
            NG = mid
    return OK + 1

for i in B:
    ans += bisect(A, i) * (N - bisect(C, i, True))

print(ans)

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

ans = 0

for i in B:
    OK = -1
    NG = N
    while NG - OK > 1:
        mid = (OK + NG) // 2
        if A[mid] < i:
            OK = mid
        else:
            NG = mid
    countA = OK + 1
    
    OK = N
    NG = -1
    while OK - NG > 1:
        mid = (OK + NG) // 2
        if C[mid] > i:
            OK = mid
        else:
            NG = mid
    countC = N - NG - 1
    ans += countA * countC

print(ans)

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

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

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

Solution (Python):
import bisect

def main():
    N = int(input())

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

    

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

    def get_a(b):
        p = bisect.bisect_left(A, b)
        return p

    def get_c(b):
        """ bより大きい数がいくつあるか
        """
        p = bisect.bisect_right(C, b)
        return N - p

    cnt = 0
    for bi in B:
        x = get_a(bi) * get_c(bi)
        cnt += x

    print(cnt)


if __name__ == "__main__":
    main()

Solution (Python):
import collections
n=int(input())
a=sorted(list(collections.Counter(map(int,input().split())).items()), key=lambda x: x[0])
b=sorted(list(collections.Counter(map(int,input().split())).items()), key=lambda x: x[0])
c=sorted(list(collections.Counter(map(int,input().split())).items()), key=lambda x: x[0])
la=len(a)
lb=len(b)
lc=len(c)
bc=[0]*lb
j=0
tmp=sum(i[1] for i in c)
for i,x in enumerate(b):
  while j<lc and x[0]>=c[j][0]:
    tmp-=c[j][1]
    j+=1
  bc[i]=tmp

abc=[0]*la
j=0
tmp=sum(i[1]*j for i,j in zip(b,bc))
for i,x in enumerate(a):
  while j<lb and x[0]>=b[j][0]:
    tmp-=b[j][1]*bc[j]
    j+=1
  abc[i]=tmp
ans=sum(i[1]*j for i,j in zip(a,abc))

print(ans)

Solution (Python):
import bisect

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

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

Solution (Python):

import sys, math, itertools, heapq, collections, bisect, string
input = lambda: sys.stdin.buffer.readline().rstrip().decode('utf-8')
inf = float('inf')
mod = 10**9+7
ans = 0 ;count = 0 ;

n=int(input())
pro = [0]*(n+1)
A=list(map(int,input().split()))
B=list(map(int,input().split()))
C=list(map(int,input().split()))
A.sort();B.sort()
for i,bi in enumerate(B):
    pro[i+1]=bisect.bisect_left(A,bi)
for i in range(n):
    pro[i+1]+=pro[i]
for i,ci in enumerate(C):
    ans+=pro[bisect.bisect_left(B,ci)]
print(ans)

Solution (Python):
from bisect import bisect_left, bisect_right

def main():
    N = int(input())
    A = list(map(int, input().split()))
    B = list(map(int, input().split()))
    C = list(map(int, input().split()))
    A, C = sorted(A), sorted(C)
    res = 0
    for b in B:
        ai = bisect_left(A, b)
        ci = bisect_right(C, b)
        if ci >= len(C):
            continue
        res += ai * (len(C) - ci)
    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()
C.sort()

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

print(ans)

Solution (Python):






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()]
lenC = len(C)





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





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

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

print(ans)

Solution (Python):
import sys
import bisect
import numpy as np

if sys.platform =='ios':
	sys.stdin=open('Untitled.txt')
input = sys.stdin.readline
def INT(): return int(input())
def MAP(): return [int(s) for s in input().split()]

N = INT()
A = MAP()
B = MAP()
C = MAP()

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

cand_a = [0] * N
for i,a in enumerate(A):
	cand_a[i] = N - bisect.bisect_right(B, a)


cand_b = [0] * N
for i,b in enumerate(B):
	cand_b[i] = N - bisect.bisect_right(C, b)
	
cand_b = list(np.cumsum(list(reversed(cand_b))))


ans = 0
for a in cand_a:
	if a: ans += cand_b[a-1]

print(ans)

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

n = int(input())
a_list = sorted(map(int, input().split()))
b_list = sorted(map(int, input().split()))
c_list = sorted(map(int, input().split()))

b_c_table_ = list(accumulate(reversed(tuple(n - bisect(c_list, b) for b in b_list))))
b_c_table_.reverse()
b_c_table_ += [0]

print(sum(b_c_table_[bisect(b_list, a)] for a in a_list))

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

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

print(r)

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

from bisect import bisect_left

mids = []
for b in B:
    ind = bisect_left(A, b)
    mids.append(ind)
cs = [0]
for i in range(N):
    cs.append(cs[i]+mids[i])
ans = 0
for c in C:
    ind = bisect_left(B, c)
    ans += cs[ind]
print(ans)

Solution (Python):
import bisect
N=int(input())
A=[int(s) for s in input().split()]
B=[int(s) for s in input().split()]
C=[int(s) for s in input().split()]
B.sort()
C.sort()
Bls=[0 for _ in range(N)]
for i in range(N):
  x=B[i]
  index = bisect.bisect_right(C,x)
  Bls[i]=N-index
Bls_sum=[0 for _ in range(N)]
Bls_sum[N-1]=Bls[N-1]
for i in range(1,N):
  Bls_sum[N-i-1]=Bls_sum[N-i]+Bls[N-i-1]

Bls_sum.append(0)
ans=0
for i in range(N):
  y=A[i]
  index = bisect.bisect_right(B,y)
  ans+=Bls_sum[index]
print(ans)

Solution (Python):
import sys
input = sys.stdin.readline
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):
    atmp = bisect.bisect_right(a, b[i] - 1)
    ctmp = bisect.bisect_left(c, b[i] + 1)

    ans += atmp * (N - ctmp)

print(ans)

Solution (Python):
from collections import Counter
N =int(input())
A = Counter(list(map(int,input().split())))
B = Counter(list(map(int,input().split())))
C = Counter(list(map(int,input().split())))
A_sort = sorted(A.items())
B_sort = sorted(B.items())
C_sort = sorted(C.items())

BtoC = []
ans = 0
start_j = 0
start_k = 0
sum_val = N
for j in range(len(B_sort)):
    for k in range(start_k , len(C_sort)):
        if B_sort[j][0] >= C_sort[k][0]:
            sum_val -= C_sort[k][1]
            start_k = k + 1
        else:
            BtoC.append([B_sort[j][0] , sum_val * B_sort[j][1]])
            break

work = 0
for i in range(len(BtoC) - 2 , -1 , -1):
    BtoC[i][1] = BtoC[i+1][1] + BtoC[i][1]
    work = BtoC[i+1][1]

for i in range(len(A_sort)):
    for j in range(start_j , len(BtoC)):
        if A_sort[i][0] >= BtoC[j][0]:
            start_j = j + 1
        else:
            ans += A_sort[i][1] * BtoC[j][1]
            break
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()))

a1 = sorted(a)
c1 = sorted(c)
count = 0

for i in b:
    count += bisect.bisect_left(a1,i) * (n - bisect.bisect_right(c1,i))
    
print(count)

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

A.sort()
B.sort()
C.sort()
ans=0
for b in B:
  aidx=bisect.bisect_left(A,b)
  cidx=bisect.bisect_right(C,b)
  ans+=aidx*(len(C)-cidx)
print(ans)

Solution (Python):
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
from bisect import bisect_left, bisect
from heapq import heappush, heappop

def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N = INT()
A = LIST()
B = LIST()
C = LIST()

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

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

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

    ans = 0
    blist = [0] * N
    cidx = 0
    for bidx in range(N):
        while (cidx < N) and (B[bidx] >= C[cidx]):
            cidx += 1
        
        if cidx >= N:
            break
        blist[bidx] = N - cidx

    bTotal = [0] * N
    bTotal[N - 1] = blist[N - 1]
    for bidx in range(1, N):
        bTotal[N - bidx - 1] = bTotal[N - bidx] + blist[N - bidx - 1]


    bidx = 0
    for aidx in range(N):
        while (bidx < N) and (A[aidx] >= B[bidx]):
            bidx += 1
        if bidx >= N:
            break
        ans += bTotal[bidx]
    
    print(ans)


def main():
    ABC077C_SnukeFes()

if __name__ == "__main__":
    main()

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

    ans = 0
    blist = [0] * N
    cidx = 0
    for bidx in range(N):
        while (cidx < N) and (B[bidx] >= C[cidx]):
            cidx += 1
        
        if cidx >= N:
            break
        blist[bidx] = N - cidx

    bTotal = [0] * N
    bTotal[N - 1] = blist[N - 1]
    for bidx in range(1, N):
        bTotal[N - bidx - 1] = bTotal[N - bidx] + blist[N - bidx - 1]


    bidx = 0
    for aidx in range(N):
        while (bidx < N) and (A[aidx] >= B[bidx]):
            bidx += 1
        if bidx >= N:
            break
        ans += bTotal[bidx]
    
    print(ans)


def main():
    ABC077C_SnukeFes()

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

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

Solution (Python):
import bisect
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())))
ans = 0
b_to_c = [0]*n
for i in range(n):
  b_to_c[i] = n - bisect.bisect_right(C, B[i])
Q = list(accumulate(b_to_c[::-1]))[::-1]
  
for i in A:
  t = bisect.bisect_right(B, i)
  if t < n:
    ans += Q[t]
print(ans)

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

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

answer = 0
for b_i in range(len(B)):
    value = B[b_i]
    """Aについて"""
    right = len(A)
    left = -1
    while right - left > 1:
        center = (right + left) // 2
        if A[center] >= value:
            right = center
        else:
            left = center
    a_num = left + 1
    
    """Cについて"""
    right = len(C)
    left = -1
    while right - left > 1:
        center = (right + left) // 2
        if C[center] <= value:
            left = center
        else:
            right = center
    c_num = len(C) - right

    answer += a_num*c_num

print(answer)

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

answer = 0
for b_i in range(len(B)):
    value = B[b_i]
    """Aについて"""
    right = len(A)
    left = -1
    while right - left > 1:
        center = (right + left) // 2
        if A[center] >= value:
            right = center
        else:
            left = center
    a_num = left + 1
    
    """Cについて"""
    right = len(C)
    left = -1
    while right - left > 1:
        center = (right + left) // 2
        if C[center] <= value:
            left = center
        else:
            right = center
    c_num = len(C) - right

    answer += a_num*c_num

print(answer)

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])
    c = N - bisect.bisect_right(C,B[i])
    ans += a*c
print(ans)

Solution (Python):
import sys

readline = sys.stdin.buffer.readline


def binary_search(A, n, p):
    if p == "+":
        n += 0.5
    else:
        n -= 0.5

    left = 0
    right = len(A) - 1

    if n < A[0]:
        return 0
    else:
        while left <= right:
            mid = (left + right) // 2
            if A[mid] < n:
                left = mid + 1
            else:
                right = mid - 1

        return left


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

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

    cnt = 0
    for b in B:
        ab = binary_search(A, b, "-")
        bc = N - binary_search(C, b, "+")
        cnt += ab * bc

    print(cnt)


main()

Solution (Python):
import sys

readline = sys.stdin.buffer.readline


def binary_search(A, n, p):
    if p == "+":
        n += 0.5
    else:
        n -= 0.5

    left = 0
    right = len(A) - 1

    if n < A[0]:
        return 0
    else:
        while left <= right:
            mid = (left + right) // 2
            if A[mid] < n:
                left = mid + 1
            else:
                right = mid - 1

        return left


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

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

    cnt = 0
    for i, b in enumerate(B):
        ab = binary_search(A, b, "-")
        bc = N - binary_search(C, b, "+")
        cnt += ab * bc

    print(cnt)


main()

Solution (Python):
import sys, re
from collections import deque, defaultdict, Counter
from math import floor, ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy,copy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
import bisect

def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

def main():
	n = INT()
	a = sorted(LIST())
	b = sorted(LIST())
	c = sorted(LIST())

	ans = 0

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

if  __name__=='__main__':
	main()

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

ary = [0]*len(B)

for i, b in enumerate(B):
    if A[0] >= b:
        continue
    left = 0
    right = len(A)
    while right-left > 1:
        middle = (left+right)//2
        if A[middle] >= b:
            right = middle
        else:
            left = middle
    ary[i] = left+1
    if i != 0:
        ary[i] += ary[i-1]
for i, c in enumerate(C):
    if B[0] >= c:
        continue
    left = 0
    right = len(B)
    while right-left > 1:
        middle = (left+right)//2
        if B[middle] >= c:
            right = middle
        else:
            left = middle
    ans += ary[left]

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

Solution (Python):
import bisect
n=int(input())
a,b,c=[sorted(map(int,input().split())) for i in range(3)]
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):
import bisect
n=int(input())
a,b,c=[sorted(map(int,input().split())) for i in range(3)]

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

Solution (Python):
from bisect import bisect_left as bl
import sys

sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]

def main():
    n=int(input())
    aa=LI()
    bb = LI()
    cc = LI()
    aa.sort()
    bb.sort()
    
    
    ans=0
    bi_to_a_cnt=[0]
    for b in bb:
        bi_to_a_cnt.append(bl(aa,b)+bi_to_a_cnt[-1])
    for c in cc:
        bi=bl(bb,c)
        ans+=bi_to_a_cnt[bi]
    print(ans)

main()