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():
    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 = sorted(A) + [float("inf")]
    B = sorted(B) + [float("inf")]
    C = sorted(C) + [float("inf")]
    
    b, c = 0, 0
    BC = []
    while b < N:
        if B[b] < C[c] or c == N:
            BC.append(N-c)
            b += 1
        else:
            c += 1
    for i in range(N-1):
        BC[N-2-i] += BC[N-1-i]
    
    a, b = 0, 0
    AB = []
    while a < N:
        if b == N:
            AB.append(N)
            a += 1
        elif A[a] < B[b]:
            AB.append(b)
            a += 1
        else:
            b += 1
            
    ans = 0
    BC += [0]
    for i in range(N):
        ans += BC[AB[i]]
    
    print(ans)

            
    
    
main()

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

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

Solution (Python):
import sys
import math
import bisect
from fractions import gcd





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

def combination_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

def permutations_count(n, r):
    return math.factorial(n) // math.factorial(n - r)

big_prime = 1000000007

"""


 = sys.stdin.readline().rstrip()
 = list(sys.stdin.readline().rstrip())


 = int(sys.stdin.readline())
 = map(int, sys.stdin.readline().split())
 = list(map(int, sys.stdin.readline().split()))
 = [list(map(int,list(sys.stdin.readline().split()))) for i in range(N)]
"""


N = int(sys.stdin.readline())
A = list(map(int, sys.stdin.readline().split()))
B = list(map(int, sys.stdin.readline().split()))
C = list(map(int, sys.stdin.readline().split()))

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

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


print(ans)

Solution (Python):
n = int(input())
a = 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 j in range(n):
    i = bisect.bisect_left(a, b[j])
    k = bisect.bisect_right(c, b[j])
    ans += i * (n - k)

print(ans)

Solution (Python):

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

a.sort()
b.sort()
c.sort()
a.append(10 ** 9 + 1)
b.append(10 ** 9 + 2)
c.append(10 ** 9 + 3)

ab = [0] * (n + 1)
j = 0
for i in range(n + 1):
    while b[j] <= a[i]:
        j += 1
    ab[i] = j

k = 0
bc = [0] * (n + 1)
for j in range(n + 1):
    while c[k] <= b[j]:
        k += 1
    bc[j] = k

bc_acc = [0] * (n + 1)
bc_acc[n] = 0
for j in range(n-1, -1, -1):
    bc_acc[j] = bc_acc[j+1] + n - bc[j]

ans = 0
for i in range(n):
    ans += bc_acc[ab[i]]

print(ans)

Solution (Python):
import bisect

N = int(input())

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

ans = 0
mem_idx_a = {}
for idx_b in range(N):
  idx_c = bisect.bisect_right(C,B[idx_b])
  idx_a = bisect.bisect_left(A,B[idx_b])
  ans += (N-idx_c)*idx_a
print(ans)

Solution (Python):
from bisect import bisect
N = int(input())
A = sorted(map(int, input().split()))
B = sorted(map(int, input().split()))
C = sorted(map(int, input().split()))
D = [0]*N
E = [0]*(N+1)
for i, b in enumerate(B) :
    D[i] = N - bisect(C, b)
for i, d in enumerate(D[::-1]) :
    E[N-i-1] = E[N-i] + d
c = 0
for a in A:
    c += E[bisect(B, a)]
print(c)

Solution (Python):

import sys
from bisect import bisect_right, bisect_left


def solve(N: int, A: "List[int]", B: "List[int]", C: "List[int]"):
    ans  = 0
    A.sort()
    B.sort()
    C.sort()
    for i in range(N):
        ai = bisect_left(A, B[i])
        ci = bisect_right(C, B[i])
        ans += (ai) * (N-ci)

    print(ans)

    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 math
from collections import defaultdict

sys.setrecursionlimit(10**7)
def input():
    return sys.stdin.readline()[:-1]

mod = 10**9 + 7

def I(): return int(input())
def II(): return map(int, input().split())
def III(): return list(map(int, input().split()))
def Line(N):
    read_all = [tuple(map(int, input().split())) for _ in range(N)]
    return map(list,zip(*read_all))



from bisect import bisect_left

N = I()
A = III()
B = III()
C = III()

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

memo = [0]*N
for i in range(N):
    x = bisect_left(A,B[i])
    if i==0:
        memo[i] = x
    else:
        memo[i] = memo[i-1]+x

ans = 0
for i in range(N):
    y = bisect_left(B,C[i])
    if y==0:
        continue
    else:
        ans += memo[y-1]

print(ans)

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

Solution (Python):


import bisect

def main(N,A,B,C):
    A.sort()
    C.sort()
    ans = 0
    for i in B:
        cnt_small = bisect.bisect_left(A,i)
        cnt_large = N - bisect.bisect_right(C,i)
        ans += cnt_small*cnt_large
    print(ans)
        
if __name__ == '__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()]
    main(N,A,B,C)

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

cnt=0
for bb in b:
    aa=bisect_left(a,bb)
    cc=n-bisect_right(c,bb)
    cnt+=aa*cc
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()))
A.sort()
B.sort()
C.sort()


BtoC = [0]*N
for i in range(N):
    BtoC[i] = N - bisect.bisect_right(C,B[i])


s = [0]*N
for i in range(N):
    i = N-1-i
    if i == N-1:
        s[i] = BtoC[i]
        continue
    s[i] = s[i+1]+BtoC[i]
res = 0
for a in A:
    ind = bisect.bisect_right(B,a)
    res += s[ind] if ind <= N-1 else 0
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()
B.sort()
C.sort()

BtoC = [0]*N
for i in range(N):
    BtoC[i] = N - bisect.bisect_right(C,B[i])
s = [0]*N
for i in range(N):
    i = N-1-i
    if i == N-1:
        s[i] = BtoC[i]
        continue
    s[i] = s[i+1]+BtoC[i]
res = 0
for a in A:
    ind = bisect.bisect_right(B,a)
    res += s[ind] if ind <= N-1 else 0
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()
B.sort()
C.sort()

BtoC = [0]*N
for i in range(N):
    BtoC[i] = N - bisect.bisect_right(C,B[i])
s = [0]*N
for i in range(N):
    i = N-1-i
    if i == N-1:
        s[i] = BtoC[i]
        continue
    s[i] = s[i+1]+BtoC[i]
res = 0
for a in A:
    ind = bisect.bisect_right(B,a)
    if ind >= N:
        break
    res += s[ind]
print(res)

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())))
BB=[0]*(n+1)
for i in A:
  BB[bisect.bisect_right(B,i)]+=1
BB=BB[:-1]
for j in range(n-1):
  BB[j+1]+=BB[j]
ans=0
for k,l in zip(B,BB):
  ans+=l*(n-bisect.bisect_right(C,k))
print(ans)

Solution (Python):
n = int(input())
A = sorted([int(_) for _ in input().split()])
B = sorted([int(_) for _ in input().split()])
C = sorted([int(_) for _ in input().split()])


def f(_A, _B):
    bcnt = [0] * n
    j = 0
    for i in range(n):
        if i > 0: bcnt[i] = bcnt[i - 1]
        while j < n:
            if _B[i] > _A[j]:
                bcnt[i] += 1
                j += 1
            else:
                break
    return bcnt


spam = f(A, B)
for i in range(1, n):
    spam[i] += spam[i - 1]

ham = f(B, C)
ans = 0
for i in range(n):
    if ham[i] <= 0: continue
    ans += spam[ham[i] - 1]
print(ans)

Solution (Python):
import sys
import bisect
input = 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 i in range(N):
        tmp = bisect.bisect_right(a, b[i]-1)
        tmp *= N - bisect.bisect_left(c, b[i]+1)
        ans += tmp
    print(ans)

if __name__ == "__main__":
    main()

Solution (Python):
import bisect


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


if __name__ == "__main__":
    resolve()

Solution (Python):
import bisect, sys
from itertools import accumulate
input = sys.stdin.readline
n = int(input())
a = sorted(map(int,input().split()))
b = sorted(map(int,input().split()))
c = sorted(map(int,input().split()))

ans = 0
b_sect = [0]
for i in range(n)[::-1]:
    b_sect.append(n-bisect.bisect_right(c,b[i]))
acc = list(accumulate(b_sect))[::-1]

for i in a:
    t = bisect.bisect_right(b,i)
    ans += acc[t]
print(ans)

Solution (Python):
import bisect
from itertools import accumulate

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

ans = 0
b_sect = [0]
for i in range(n)[::-1]:
    b_sect.append(n-bisect.bisect_right(c,b[i]))
acc = list(accumulate(b_sect))[::-1]

for i in a:
    t = bisect.bisect_right(b,i)
    ans += acc[t]
print(ans)

Solution (Python):
from bisect import bisect_right

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

s = [0] * N
for i in range(N) :
    s[i] = N - bisect_right(C, B[i])
for i in range(N-2, -1, -1) :
    s[i] += s[i+1]

ret = 0
for i in range(N) :
    a = bisect_right(B, A[i])
    if a < N :
        ret += s[a]
print(ret)

Solution (Python):
import sys
from bisect import *
from collections import *
from heapq import *
from itertools import *
from operator import *

sys.setrecursionlimit(10**8)

input = sys.stdin.readline

def main():
    """ main """
    N = int(input())
    AS = list(map(int, input().split()))
    BS = list(map(int, input().split()))
    CS = list(map(int, input().split()))
    AS.sort()
    BS.sort()
    CS.sort()

    ans = 0
    for b in BS:
        a_idx = bisect_left(AS, b)
        c_idx = bisect_right(CS, b)
        if a_idx == 0 or c_idx == N: continue
        ans += a_idx*(N-c_idx)

    print(ans)

if __name__ == '__main__':
    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()
from bisect import bisect_left
from bisect import bisect_right
ans = 0
for j in range(n):
    key = b[j]
    i = bisect_left(a, key)
    k = n - bisect_right(c, key)
    ans += i * k
print(ans)

Solution (Python):
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)

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:
    num_a = bisect.bisect_left(A, b)
    num_c = N - bisect.bisect_right(C, b)

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

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

n=int(input())
a=[]
for i in range(3):
   a.append(list(map(int,input().split())))

for j in range(3):
    a[j].sort()
ans=0
for l in a[1]:
    aa=bisect.bisect_left(a[0],l)
    bb=(n-bisect.bisect_right(a[2],l))
    ans+=aa*bb
print(ans)

Solution (Python):


import bisect

N = int(input().split()[0])
a_list = sorted(list(map(int, input().split())))
b_list = sorted(list(map(int, input().split())))
c_list = sorted(list(map(int, input().split())))

comb_n = 0
comb_n_list = []


start_c_index = 0
start_a_index = 0

for i in range(N):  
    b = b_list[i]
    a_n = bisect.bisect_left(a_list, b)
    c_n = N - bisect.bisect_right(c_list, b)
    comb_n += a_n * c_n
ans = comb_n
print(ans)

Solution (Python):
import sys
import  math
import bisect
from statistics import *
from collections import *
from operator import itemgetter
"""
from fractions import gcd
def lcm(x, y):
    return (x * y) // gcd(x, y)
"""
stdin = sys.stdin
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline()

n = ni()
aaa = na()
bbb = na()
ccc = na()
aaa.sort()
ccc.sort()
l = 0
r = 0
ct = 0
ct = 0
for i in range(n):
    l = bisect.bisect_left(aaa, bbb[i])
    r = bisect.bisect_right(ccc, bbb[i])
    ct += l * (n - r)

print(ct)

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

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

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

Solution (Python):
import bisect
n = int(input())
bb = [0] * (n+1)
ans = 0
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()

for i in range(1,n+1):
    bb[i] = bisect.bisect_left(a,b[i-1]) + bb[i-1]

for i in range(n):
    ans += bb[bisect.bisect_left(b,c[i])]
print(ans)

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

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

Solution (Python):
import sys
import heapq
from operator import itemgetter
from collections import deque, defaultdict, Counter
from bisect import bisect_left, bisect_right
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)
MOD = 10**9 + 7
INF = float('inf')

def sol():
    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:
        a = bisect_left(A, b)
        c = bisect_right(C, b)
        ans += a * (N - c)

    print(ans)

sol()

Solution (Python):
N = int(input())
a = []
for i in range(3):
    a.append(list(map(int, input().split())))

for i in range(3):
    a[i].sort()

dataa = []
datab = []
memo = 0

for i in range(N):
    flag = 0
    for j in range(memo, N):
        
        if a[0][i] < a[1][j]:
            memo = j
            dataa.append(N - j)
            flag = 1
            break
    if flag == 0:
        for j in range(N - i):
            dataa.append(0)
        break
memo = 0
for i in range(N):
    flag = 0
    for j in range(memo, N):
        if a[1][i] < a[2][j]:
            memo = j
            datab.append(N - j)
            flag = 1
            break
    if flag == 0:
        for j in range(N - i):
            datab.append(0)
        break
ruiseki = []
count = 0
for i in range(len(datab)-1, -1, -1):
    count += datab[i]
    ruiseki.append(count)
count2 = 0
for i in range(len(dataa)):
    if dataa[i] != 0:
        count2 += ruiseki[dataa[i] - 1]



print(count2)

Solution (Python):
import bisect

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

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

Solution (Python):

N = int(input())

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

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

A.append(10 ** 9 + 2)

ap = 0

Bnum = []

ans = 0

for i in range(N):

    b = B[i]

    while True:

        if A[ap] < b:

            ap += 1

        else:

            break

    if i == 0:
        Bnum.append(ap)

    else:
        Bnum.append(ap + Bnum[-1])

bp = 0
B.append(10 ** 9 + 2)

for i in range(N):

    c = C[i]

    while True:

        if B[bp] < c:

            bp += 1

        else:

            break

    if bp != 0:
        ans += Bnum[bp-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_num = [0 for _ in range(n)]
for b_i in range(n):
    c_i = bisect.bisect_right(c, b[b_i])
    b_num[b_i] = n - c_i

for i in range(1, len(b_num)):
    b_num[len(b_num) - 1 - i] += b_num[len(b_num) - i]

ans = 0
for a_i in range(len(a)):
    b_i = bisect.bisect_right(b, a[a_i])
    if b_i >= n:
        continue
    ans += b_num[b_i]
print(ans)

Solution (Python):
import bisect
N = int(input())
As = list(map(int, input().split()))
Bs = list(map(int, input().split()))
Cs = list(map(int, input().split()))
As.sort()
Bs.sort()
Cs.sort()



NsB = []
for i in range(N):
  B = Bs[i]
  j = bisect.bisect_left(Cs, B+1)
  NsB.append(N-j)

CSNsB = []
r = 0
for i in reversed(range(N)):
  r += NsB[i]
  CSNsB.append(r)
CSNsB.reverse()

r = 0
for i in range(N):
  A = As[i]
  j = bisect.bisect_left(Bs, A+1)
  if j < N:
    r += CSNsB[j]
print(r)

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

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

a_list = []
b_list = []

tmp = n-1
num = 0

for i in range(n):
    while tmp >= 0 and a[n-i-1] < b[tmp]:
        tmp -= 1
        num += 1
    a_list.append(num)
    

tmp = n-1
num = 0

for i in range(n):
    while tmp >= 0 and b[n-i-1] < c[tmp]:
        tmp -= 1
        num += 1
    b_list.append(num)
    

b_rui = []
tmp = 0

for i in range(n):
    tmp += b_list[i]
    b_rui.append(tmp)

ans = 0

for i in range(n):
    if a_list[i] == 0:
        continue
    ans += b_rui[a_list[i]-1]
    
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())))


numb = [0]*n
for i,c in enumerate(B):
    numb[i] = n-bisect.bisect_right(C,c)

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

ans = 0
for i in range(n):
    j = bisect.bisect_right(B,A[i])
    if j < n:
        ans += numb[j]
print(ans)

Solution (Python):
import bisect

N = int(input())
A = sorted(list(map(int,input().split())))
B = list(map(int,input().split()))
C = sorted(list(map(int,input().split())))
ans = 0
for x in B:
    ai = bisect.bisect_left(A,x)
    ci = bisect.bisect_right(C,x)
    ans += (ai*(N-ci))
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:
    ans += bisect.bisect_left(A, b) * (N - bisect.bisect_right(C, b))
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())))

bcount = [0] * (n+1)

bsum = 0
for i in range(n)[::-1]:
        bsum += n - bisect.bisect_right(c, b[i])
        bcount[i] = bsum

result = 0
for i in range(n):
        result += bcount[bisect.bisect_right(b, a[i])]

print(result)

Solution (Python):
def main():
    N = int(input())
    parts = [[int(a), 0] for a in input().split()]
    parts += [[int(b), 1] for b in input().split()]
    parts += [[int(c), 2] for c in input().split()]
    parts = sorted(parts, key = lambda x: x[0], reverse = True)
    countC = 0
    countBC = 0
    ans = 0
    for i in range(len(parts)):
        if parts[i][1] == 0:
            ans += countBC
        elif parts[i][1] == 1:
            countBC += countC
        else:
            countC += 1
    return ans 

if __name__ == '__main__':
    print(main())

Solution (Python):
N=int(input())
A=list(map(int,input().split()))
B=list(map(int,input().split()))
C=list(map(int,input().split()))
l=[]
for i in range(N):
    l.append([A[i],3])
    l.append([B[i],2])
    l.append([C[i],1])
l.sort()
a=0
c=N
s=0
for i in range(3*N):
    if l[i][1]==3:
        a+=1
    elif l[i][1]==2:
        s+=a*c
    else:
        c-=1
print(s)

Solution (Python):
N=int(input())
A=list(map(int,input().split()))
B=list(map(int,input().split()))
C=list(map(int,input().split()))
l=[]
for i in range(N):
    l.append([A[i],3])
    l.append([B[i],2])
    l.append([C[i],1])
l.sort()
a=0
c=N
s=0
for i in range(3*N):
    if l[i][1]==3:
        a+=1
    elif l[i][1]==2:
        s+=a*c
    else:
        c-=1
print(s)

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 second in B:
    ai = bisect.bisect_left(A, second)
    ci = bisect.bisect_right(C, second)

    ans += (ai*(N-ci))

print(ans)

Solution (Python):
import numpy as np

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

An = np.array(A)
Bn = np.array(B)
Cn = np.array(C)

An.sort()
Bn.sort()
Cn = -Cn
Cn.sort()

AB = np.searchsorted(An,Bn,side='left')
CB = np.searchsorted(Cn,-Bn,side='left')

print((AB*CB).sum())

Solution (Python):
import bisect

N=int(input())
A=list(map(int,input().split()))
B=list(map(int,input().split()))
C=list(map(int,input().split()))
A.sort()
B.sort()
C.sort()
total=0
for i in range(N):
    X=bisect.bisect_left(A, B[i])
    Y=len(C)-bisect.bisect_right(C, B[i])
    total+=X*Y
print(total)

Solution (Python):

import bisect



def cumsum(inlist):
    s = 0
    outlist = []
    for i in inlist:
        s += i
        outlist.append(s)
    return outlist

n = int(input())
a_list = sorted([ int(v) for v in input().split() ])
b_list = sorted([ int(v) for v in input().split() ])
c_list = sorted([ int(v) for v in input().split() ])
a_b_list = [ bisect.bisect_right(a_list,i-1) for i in b_list]
b_c_list = [ bisect.bisect_right(b_list,i-1) for i in c_list]
a_b_cumsum_list = cumsum(a_b_list)
a_b_c_list = [ a_b_cumsum_list[i-1] for i in b_c_list if i != 0]
print(sum(a_b_c_list))

Solution (Python):
from bisect import bisect_left, bisect_right

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

Solution (Python):
from itertools import accumulate

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()]
A.sort()
B.sort()
C.sort()
cnt = [0] * (N + 1)
j = 0
for i, b in enumerate(B):
    while j < N and A[j] < b:
        j += 1
    cnt[i + 1] = j
cnt = list(accumulate(cnt))
ans = 0
j = 0
for i, c in enumerate(C):
    while j < N and B[j] < c:
        j += 1
    ans += cnt[j]
print(ans)

Solution (Python):
import bisect
import heapq
import itertools
import math
import operator
import os
import re
import string
import sys
from collections import Counter, deque, defaultdict
from copy import deepcopy
from decimal import Decimal
from fractions import gcd
from functools import lru_cache, reduce
from operator import itemgetter, mul, add, xor

import numpy as np

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(2147483647)
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7

N = int(sys.stdin.readline())
A = list(map(int, sys.stdin.readline().split()))
B = list(map(int, sys.stdin.readline().split()))
C = list(map(int, sys.stdin.readline().split()))

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

counts = []
a = 0
for b in range(N):
    while a < N and B[b] > A[a]:
        a += 1
    counts.append(a)

cs = list(itertools.accumulate(counts))
s = sum(counts)
ans = 0
b = 0
for c in range(N):
    while b < N and C[c] > B[b]:
        b += 1

    ans += cs[b - 1] if b - 1 >= 0 else 0
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, B, C = sorted(A), sorted(B), sorted(C)

ans = 0
for b in B:
    a = bisect.bisect_left(A, b)
    c = n - bisect.bisect_right(C, b)
    if a > 0 and c > 0:
        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()
B.sort()
C.sort()

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

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

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

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

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

AB = defaultdict(int)

for b in B:
    AB[b] = bisect_left(A, b)

sumAB = defaultdict(int)
sumAB[0] = 0
s = 0
for b in B:
    s += AB[b]
    sumAB[b] = s

B.insert(0, 0)
ans = 0
for c in C:
    r = bisect_left(B, c)
    ans += sumAB[B[r - 1]]

print(ans)

Solution (Python):
import bisect
N = int(input())
X = [sorted(list(map(int,input().split()))) for i in range(3)]
def nmb(i):
	left = bisect.bisect_left(X[0],i)
	right = bisect.bisect_right(X[2],i)
	return left*(len(X[2])-right)

ans = 0
for i in X[1]:
	ans += nmb(i)

print(ans)

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

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

ans = [0 for i in range(n)]
buf = [0 for i in range(n)]

a.reverse()
b.reverse()
c.reverse()






ind = 0
for i in range(n):
    buf[i]=buf[i-1]
    if ind > n - 1:
        continue
    while(True):
        if b[i] < c[ind]:
            buf[i] += 1
            ind += 1
            if ind > n-1:
                break
        else:
            break



ind = 0
for i in range(n):
    ans[i]=ans[i-1]
    if ind > n - 1:
        continue
    while True:
        if a[i] < b[ind]:
            ans[i] += buf[ind]
            ind += 1
            if ind > n-1:
                break
        else:
            break


print(sum(ans))

Solution (Python):

n = int(input())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
c = list(map(int,input().split()))
lenc = len(c)
a.sort()
c.sort()

from bisect import bisect_left,bisect_right
ret = 0
for i in b:
    ret += bisect_left(a,i) * (lenc - bisect_right(c,i))
print(ret)

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(C, b)) for b in B]))

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

print(ans)