Problem:
 Score : 300 points    Problem Statement The season for Snuke Festival has come again this year. First of all, Ringo will perform a ritual to summon Snuke. For the ritual, he needs an altar, which consists of three parts, one in each of the three categories: upper, middle and lower.  He has N parts for each of the three categories. The size of the i -th upper part is A_i , the size of the i -th middle part is B_i , and the size of the i -th lower part is C_i .  To build an altar, the size of the middle part must be strictly greater than that of the upper part, and the size of the lower part must be strictly greater than that of the middle part. On the other hand, any three parts that satisfy these conditions can be combined to form an altar.  How many different altars can Ringo build? Here, two altars are considered different when at least one of the three parts used is different.      Constraints  1 \leq N \leq 10^5  1 \leq A_i \leq 10^9(1\leq i\leq N)  1 \leq B_i \leq 10^9(1\leq i\leq N)  1 \leq C_i \leq 10^9(1\leq i\leq N)  All input values are integers.         Input Input is given from Standard Input in the following format:  N  A_1  ...  A_N  B_1  ...  B_N  C_1  ...  C_N       Output Print the number of different altars that Ringo can build.        Sample Input 1 2
1 5
2 4
3 6      Sample Output 1 3  The following three altars can be built:   Upper: 1 -st part, Middle: 1 -st part, Lower: 1 -st part  Upper: 1 -st part, Middle: 1 -st part, Lower: 2 -nd part  Upper: 1 -st part, Middle: 2 -nd part, Lower: 2 -nd part        Sample Input 2 3
1 1 1
2 2 2
3 3 3      Sample Output 2 27       Sample Input 3 6
3 14 159 2 6 53
58 9 79 323 84 6
2643 383 2 79 50 288      Sample Output 3 87

Solution (Python):
import sys
stdin = sys.stdin
 
sys.setrecursionlimit(10**5) 
 
def li(): return map(int, stdin.readline().split())
def li_(): return map(lambda x: int(x)-1, stdin.readline().split())
def lf(): return map(float, stdin.readline().split())
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())

from bisect import bisect_left, bisect_right

n = ni()
a = sorted(list(li()))
b = sorted(list(li()))
c = sorted(list(li()))

ans = 0
for bi in b:
    ans += bisect_left(a,bi)*(n-bisect_right(c,bi))
    
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:
    ai = bisect.bisect_left(A, b)
    ci = bisect.bisect_right(C, b)
    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:
    i_a = bisect.bisect_left(A, b)
    i_c = bisect.bisect_right(C, b)
    ans += i_a * (N-i_c)
print(ans)

Solution (Python):


INF = float('inf')


def inpl(): return list(map(int, input().split()))


N = int(input())
A = sorted(inpl())
B = sorted(inpl())
C = sorted(inpl())

ans = 0
i_a = 0
i_c = 0
for i_b in range(N):
    while i_a < N and A[i_a] < B[i_b]:
        i_a += 1
    while i_c < N and C[i_c] <= B[i_b]:
        i_c += 1

    ans += i_a * (N - i_c)

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()
    answer = 0
    for b in B :
        i = bisect.bisect_left(A,b)
        j = bisect.bisect_right(C,b)
        if i > 0 and j != len(C) :
            answer += i * (N-j)
    print(answer)
main()

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

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

Solution (Python):

def main():
    import bisect
    N = int(input())
    As = sorted(list(map(int, input().split())))
    Bs = sorted(list(map(int, input().split())))
    Cs = sorted(list(map(int, input().split())))

    c_under_b = [0]*N 
    a_on_b = [0]*N 

    for i in range(len(Bs)):
        c_under_b[i] = N - bisect.bisect_right(Cs, Bs[i])

    for i in range(len(Bs)):
        a_on_b[i] = bisect.bisect_left(As, Bs[i])

    count = 0
    for i in range(len(Bs)):
        count += c_under_b[i] * a_on_b[i]
    print(count)

def main5():
    """ AC """
    import bisect
    N = int(input())
    As = sorted(list(map(int, input().split())))
    Bs = sorted(list(map(int, input().split())))
    Cs = sorted(list(map(int, input().split())))

    c_under_b = [] 
    a_on_b = [] 

    for b in Bs:
        i = bisect.bisect_right(Cs, b)
        c_under_b.append(N - i)

    for b in Bs:
        i = bisect.bisect_left(As, b)
        a_on_b.append(i)

    count = 0
    for i in range(len(Bs)):
        count += c_under_b[i] * a_on_b[i]
    print(count)

def main4():
    """ TLE """
    import bisect
    N = int(input())
    As = sorted(list(map(int, input().split())))
    Bs = sorted(list(map(int, input().split())))
    Cs = sorted(list(map(int, input().split())))

    c_under_b = [] 
    a_on_b = [] 

    for b in Bs:
        i = bisect.bisect_right(Cs, b)
        c_under_b.append(len(Cs[i:]))

    for b in Bs:
        i = bisect.bisect_left(As, b)
        a_on_b.append(len(As[:i]))

    count = 0
    for i in range(len(Bs)):
        count += c_under_b[i] * a_on_b[i]
    print(count)

def main3():
    """ TLE """
    import itertools
    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()
    count = 0
    for c in Cs:
        for b in Bs:
            if c <= b:
                break
            for a in As:
                if b <= a:
                    break
                if c > b > a:
                    count += 1
    print(count)

def main2():
    """ TLE """
    import itertools
    N = int(input())
    As = list(map(int, input().split()))
    Bs = list(map(int, input().split()))
    Cs = list(map(int, input().split()))

    count = 0
    for c in Cs:
        for b in Bs:
            for a in As:
                if a < b < c:
                    count += 1
    print(count)


if __name__ == '__main__':
    main()

Solution (Python):

def main():
    import bisect
    N = int(input())
    As = sorted(list(map(int, input().split())))
    Bs = sorted(list(map(int, input().split())))
    Cs = sorted(list(map(int, input().split())))

    c_under_b = [0]*N 
    a_on_b = [0]*N 

    for i in range(len(Bs)):
        c_under_b[i] = bisect.bisect_right(Cs, Bs[i])

    for i in range(len(Bs)):
        a_on_b[i] = bisect.bisect_left(As, Bs[i])

    count = 0
    for i in range(len(Bs)):
        count += c_under_b[i] * a_on_b[i]
    print(count)

def main5():
    import bisect
    N = int(input())
    As = sorted(list(map(int, input().split())))
    Bs = sorted(list(map(int, input().split())))
    Cs = sorted(list(map(int, input().split())))

    c_under_b = [] 
    a_on_b = [] 

    for b in Bs:
        i = bisect.bisect_right(Cs, b)
        c_under_b.append(N - i)

    for b in Bs:
        i = bisect.bisect_left(As, b)
        a_on_b.append(i)

    count = 0
    for i in range(len(Bs)):
        count += c_under_b[i] * a_on_b[i]
    print(count)

def main4():
    """ TLE """
    import bisect
    N = int(input())
    As = sorted(list(map(int, input().split())))
    Bs = sorted(list(map(int, input().split())))
    Cs = sorted(list(map(int, input().split())))

    c_under_b = [] 
    a_on_b = [] 

    for b in Bs:
        i = bisect.bisect_right(Cs, b)
        c_under_b.append(len(Cs[i:]))

    for b in Bs:
        i = bisect.bisect_left(As, b)
        a_on_b.append(len(As[:i]))

    count = 0
    for i in range(len(Bs)):
        count += c_under_b[i] * a_on_b[i]
    print(count)

def main3():
    """ TLE """
    import itertools
    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()
    count = 0
    for c in Cs:
        for b in Bs:
            if c <= b:
                break
            for a in As:
                if b <= a:
                    break
                if c > b > a:
                    count += 1
    print(count)

def main2():
    """ TLE """
    import itertools
    N = int(input())
    As = list(map(int, input().split()))
    Bs = list(map(int, input().split()))
    Cs = list(map(int, input().split()))

    count = 0
    for c in Cs:
        for b in Bs:
            for a in As:
                if a < b < c:
                    count += 1
    print(count)


if __name__ == '__main__':
    main5()

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

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

A_on_B=[0]*N     
for i in range(N):
    A_on_B[i]=bisect.bisect_left(A,B[i])

ans=0
for i in range(N):
    ans+=C_under_B[i]*A_on_B[i]
print(ans)

Solution (Python):
from sys import stderr
from functools import reduce
from operator import add
import bisect
def f(): return [int(i) for i in input().split()]
def yes(n): print("Yes" if n else "No")
def debug(*x, sep=" ", end="\n"):
    for item in x:
        stderr.write(str(item))
        stderr.write(sep)
    stderr.write(end)

n = int(input())
a = sorted(f())
b = sorted(f())
c = sorted(f())
debug(a,b,c,sep='\n')
ans = 0


canRideOnB = [bisect.bisect_left(a, b[0])]
for middle in b[1:]:
    top = bisect.bisect_left(a, middle)
    canRideOnB.append(top+canRideOnB[-1])
debug(canRideOnB)


canRideOnC = []
for bottom in c:
    mid = bisect.bisect_left(b, bottom)
    canRideOnC.append(mid)
debug(canRideOnC)


for bot in canRideOnC:
    if bot == 0:
        pass
    else:
        ans += canRideOnB[bot-1]

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 = sorted(a)[::-1]
b = sorted(b)[::-1]
c = sorted(c)[::-1]

a_smaller_b = [0]*n
b_smaller_c = [0]*n
n_a, n_b = 0, 0
j, k = 0, 0
for i in range(n):
    a_tar = a[i]
    b_tar = b[i]
    while True:
        if j == n:
            a_smaller_b[i] = n_a
            break
        if b[j] > a_tar:
            n_a += 1
            j += 1
        else:
            a_smaller_b[i] = n_a
            break

    while True:
        if k == n:
            b_smaller_c[i] = n_b
            break
        if c[k] > b_tar:
            n_b += 1
            k += 1
        else:
            b_smaller_c[i] = n_b
            break



bsc_cumsum = [0]*(n+1)
for i in range(n):
    bsc_cumsum[i+1] = bsc_cumsum[i]+b_smaller_c[i]

ans = 0
for i in range(n):
    ans += bsc_cumsum[a_smaller_b[i]]
print(ans)

Solution (Python):
import bisect

n = int(input())
a = sorted([int(v) for v in input().split()])
b = sorted([int(v) for v in input().split()])
c = sorted([int(v) for v in input().split()])

on_b_nums = []
num = 0
for v in b:
    num += bisect.bisect_left(a, v)
    on_b_nums.append(num)

on_c_nums = []
for v in c:
    i = bisect.bisect_left(b, v)
    if i > 0:
        on_c_nums.append(on_b_nums[i-1])
    else:
        on_c_nums.append(0)

print(sum(on_c_nums))

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

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

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

T = []
for j, D in enumerate([C, B, A]):
    for Di in D:
        T.append(Di * 10 + j)

Ai = Ci = cnt = 0

for t in sorted(T):
    c = chr(ord('C') - (t % 10))
    if c == 'A':
        Ai += 1
    if c == 'C':
        Ci += 1
    if c == 'B':
        cnt += Ai * (N - Ci)

print(cnt)

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

count = 0

for b in B:
    a_num = bisect_left(A, b)
    c_num = n - bisect_right(C, b)
    count += a_num * c_num
print(count)

Solution (Python):
import bisect
N = int(input())
a_list = list(map(int, input().split()))
b_list = list(map(int, input().split()))
c_list = list(map(int, input().split()))

a_list.sort()
c_list.sort()
result = 0

for b in b_list:
    a_count = bisect.bisect_left(a_list, b)
    c_count = bisect.bisect_right(c_list, b)
    result += a_count*(len(c_list)-c_count)

print(result)

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

Solution (Python):
from collections import defaultdict, Counter
from itertools import product, groupby, count, permutations, combinations
from math import pi, sqrt
from collections import deque
from bisect import bisect, bisect_left, bisect_right
from string import ascii_lowercase
from functools import lru_cache
import sys
sys.setrecursionlimit(10000)
INF = float("inf")
YES, Yes, yes, NO, No, no = "YES", "Yes", "yes", "NO", "No", "no"
dy4, dx4 = [0, 1, 0, -1], [1, 0, -1, 0]


def inside(y, x, H, W):
    return 0 <= y < H and 0 <= x < W


def ceil(a, b):
    return (a + b - 1) // b


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

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

    print(ans)


if __name__ == '__main__':
    main()

Solution (Python):
from bisect import *;N,A,B,C=[sorted(map(int,input().split())) for _ in [0]*4];print(sum(bisect_left(A,x)*(N[0]-bisect_right(C,x)) for x in B))

Solution (Python):
from bisect import *;N=int(input());A,B,C=[sorted(map(int,input().split())) for _ in "ABC"];print(sum([bisect_left(A,i)*(N-bisect_right(C,i)) for i in B]))

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

Solution (Python):
import bisect;N=int(input());A,B,C=[sorted(list(map(int,input().split()))) for _ in "ABC"];print(sum([bisect.bisect_left(A,i)*(N-bisect.bisect_right(C,i)) for i in B]))

Solution (Python):
from bisect import bisect_left,bisect_right;N=int(input());A,B,C=[list(map(int,input().split())) for _ in "ABC"];A.sort();C.sort();print(sum([bisect_left(A,i)*(N-bisect_right(C,i)) for i in B]))

Solution (Python):
from bisect import bisect_left,bisect_right;N=int(input());A,B,C=[list(map(int,input().split())) for _ in "ABC"];A.sort();C.sort();print(sum([bisect_left(A,B[i])*(N-bisect_right(C,B[i])) for i in range(N)]))

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

Solution (Python):
from bisect import bisect_left,bisect_right;N=int(input());A=sorted([int(i) for i in input().split()]);B=[int(i) for i in input().split()];C=sorted([int(i) for i in 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_left,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()
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):
n = int(input())
A = sorted(list(map(int, input().split())))
B = sorted(list(map(int, input().split())))
C = sorted(list(map(int, input().split())))

import bisect

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

print(ans)

Solution (Python):
N = int(input())
A = sorted([int(x) for x in input().split()])
B = sorted([int(x) for x in input().split()])
C = sorted([int(x) for x in input().split()])
a = 0
c = 0
cnt = 0
for i in range(N):
  while a < N:
    if A[a] < B[i]:
      a += 1
    else:
      break
  while c < N:
    if C[c] <= B[i]:
      c += 1
    else:
      break
  cnt += a * (N - c)
print(cnt)

Solution (Python):
N = int(input())
A = sorted(-int(x) for x in input().split())
B = sorted(int(x) for x in input().split())
C = sorted(int(x) for x in input().split())

from bisect import *

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

A.sort()
C.sort()
count = 0
for Bi in B:
    a = bisect.bisect_left(A, Bi)
    c = bisect.bisect_right(C, Bi)
    count += a * (len(C) - c)
print(count)

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




res = 0
for b in B:
    res += bisect_left(A, b) * (N -bisect_right(C, b))
print(res)

Solution (Python):
"""
atcoder workspace
"""
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 = int()
for i in B:
    x = bisect_left(A, i)
    y = bisect_right(C, i)
    ans += x * (N-y)

"""
 A = [1,2,2,3,4]
 B = [1,1,2,4,5]
 C = [1,1,2,2,3]
 A < B < C
 when i+2(B = 2),
 x = 1, y = 3
 N_A = 1 (A=1), N_C = 1 (C=3)
"""

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):
    mid=b[i]
    ue=bisect.bisect_right(a,mid-1)
    sita=bisect.bisect_left(c,mid+1)
    ans+=ue*(n-sita)
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()))
import bisect
ans=0
a.sort()
b.sort()
c.sort()
for i in range(n):
    lift=bisect.bisect_left(a,b[i])
    right=bisect.bisect_right(c,b[i])
    right=n-right
    ans+=lift*right
print(ans)

Solution (Python):
import itertools

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)

ab = []
pivot_a = pivot_b = 0
while pivot_b<n:
    while pivot_a<n and a[pivot_a]<b[pivot_b]:
        pivot_a += 1
    ab.append(pivot_a)
    pivot_b += 1

ab_sum = list(itertools.accumulate(ab))

bc = []
pivot_a = pivot_b = 0
while pivot_b<n:
    while pivot_a<n and b[pivot_a]<c[pivot_b]:
        pivot_a += 1
    bc.append(pivot_a)
    pivot_b += 1


res = 0
for i in bc:
    if i!=0:
        res += ab_sum[i-1]
print(res)

Solution (Python):
from collections import defaultdict
import sys,heapq,bisect,math,itertools,string,queue,datetime
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
eps = 10**-7
def inpl(): return list(map(int, input().split()))
def inpl_s(): return list(input().split())

N = int(input())
aa = inpl()
bb = inpl()
cc = inpl()
aa.sort()
bb.sort()
cc.sort()
Sc = len(cc)

ans = 0
for b in bb:
	na = bisect.bisect_left(aa,b)
	nc = Sc - bisect.bisect_right(cc,b)
	ans += na*nc
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()

d = []
e = []

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

for i in range(n):
    k = bisect.bisect_right(c,b[i])
    e.append(n-k)
    



ass = 0
for i in range(n):
    ass += d[i]*e[i]

print(ass)

Solution (Python):
import bisect

n = int(input())
abc = [tuple(map(int, input().split(" "))) for i in range(3)]



a, b, c = [sorted(abc_i) for abc_i in abc]

print(sum(bisect.bisect_left(a, b_i) * (n-bisect.bisect_right(c, b_i)) for b_i in b))

Solution (Python):
import bisect

n = int(input())
abc = [tuple(map(int, input().split(" "))) for i in range(3)]



a, b, c = [sorted(abc_i) for abc_i in abc]

print(sum(bisect.bisect_left(a, b_i) * (n-bisect.bisect(c, b_i)) for b_i in b))

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_s, b_s, c_s = sorted(a), sorted(b), sorted(c)

a_idx, c_idx = 0, 0
small_at, big_at = [], []
small_cnt, big_cnt = 0, 0

for i in b_s :
    while a_idx < N and a_s[a_idx] < i :
        a_idx += 1
        small_cnt += 1
        
    while c_idx < N and c_s[c_idx] <= i :
        c_idx += 1
        big_cnt += 1
        
    small_at.append(small_cnt)
    big_at.append(big_cnt)
    
sum_comb = 0 
for i in range(N) :
    sum_comb += small_at[i] * (N - big_at[i])

print(sum_comb)

Solution (Python):
N = int(input())
A = sorted(int(x) for x in input().split())
B = sorted(int(x) for x in input().split())
C = sorted(int(x) for x in input().split())

import bisect
print(sum(bisect.bisect_left(A, b) * (N - bisect.bisect_right(C, b)) for b in B))

Solution (Python):

import bisect

def main():

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

    a_list.sort()
    b_list.sort()
    c_list.sort()

    cnt = 0
    
    for b in b_list:
        i = bisect.bisect_left(a_list, b)
        j = n - bisect.bisect_right(c_list, b)
        cnt += i * j
    
    print(cnt)
    
if __name__ == '__main__':
    main()

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

A.sort()
C.sort()

count=0
i=0
for i in range(N):
    countA = bisect.bisect_left(A, B[i])
    

    countB = N - bisect.bisect_right(C, B[i])
    

    count += countA * countB

print(count)

Solution (Python):
import bisect, functools, sys
sys.setrecursionlimit(10**6)
N = int(input())
A = sorted(int(x) for x in input().split())
B = sorted(int(x) for x in input().split())
C = sorted(int(x) for x in input().split())

@functools.lru_cache(maxsize=None)
def a(n):
    return bisect.bisect_left(A, n)

b_cache = [0] * (N + 1)
b_cached = [False] * (N + 1)
def b_i(i):
    global b_cache, b_cached
    if i >= 1:
        if not b_cached[i - 1]: b_i(i - 1)
        t = b_cache[i - 1] + a(B[i - 1])
        b_cache[i] = t
        b_cached[i] = True
        return t
    return 0

@functools.lru_cache(maxsize=None)
def b(n):
    return b_i(min(N, bisect.bisect_left(B, n)))

def c():
    return sum(b(x) for x in C)

print(c())

Solution (Python):
from bisect import bisect_left, bisect_right

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 = sorted(A)
C = sorted(C)

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 = [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()
count = 0
for Bi in B:
    idx_A = bisect.bisect_left(A, Bi)
    idx_C = bisect.bisect_right(C, Bi)
    count += (idx_A) * (len(C) - idx_C)
print(count)

Solution (Python):
from collections import defaultdict
import sys,heapq,bisect,math,itertools,string
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
AtoZ = [chr(i) for i in range(65,65+26)]
atoz = [chr(i) for i in range(97,97+26)]


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

aa.sort()
bb.sort()
cc.sort()

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

print(ans)

Solution (Python):
'''
https://beta.atcoder.jp/contests/abc077/submissions/2532572
'''
from bisect import bisect_left, bisect_right

def inpl():
    return list(map(int, input().split()))

n = int(input())
a = sorted(inpl())
b = sorted(inpl())
c = sorted(inpl())

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

Solution (Python):
N = int(input())
a = sorted(list(map(int, input().split())))
b = sorted(list(map(int, input().split())))
c = sorted(list(map(int, input().split())))
bina = 0
binc = 0
count = 0
for b_tree in b:
    while bina < N and a[bina] < b_tree:
        bina += 1
    while binc < N and c[binc] <= b_tree:
        binc += 1
    count += bina * (N-binc)
print(count)

Solution (Python):


import bisect

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

ans = 0
for b in B:
    ans += bisect.bisect_left(A, b) * (n - bisect.bisect_right(C, b))
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()))
ans = 0
A.sort()
C.sort()
for b in B:
	a_cand = bisect_left(A, b)
	c_cand = N - bisect_right(C, b)
	ans += a_cand * c_cand
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()))
A2 = sorted(A)
B2 = sorted(B)
C2 = sorted(C)
A2.append(2000000000)
B2.append(2000000000)
def numadd(up, down):
    array = []
    count = 0
    for i in range(0,N):
        while down[i] > up[count]:
            count = count + 1
        array.append(count)
    return array

B3 = numadd(A2,B2)
C3 = numadd(B2,C2)
B4 = [B3[0]]
for i in range(0,N-1):
    B4.append(B4[i] + B3[i+1])
ans = 0
for i in range (0,N):
    if C3[i] > 0:
        ans = ans + B4[C3[i]-1]
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()))


A2 = sorted(A)
B2 = sorted(B)
C2 = sorted(C)

A2.append(2000000000)
B2.append(2000000000)

def numadd(up, down):
    array = []
    count = 0
    for i in range(0,N):
        while down[i] > up[count]:
            count = count + 1
            
        array.append(count) 
    return array

B3 = numadd(A2,B2)
C3 = numadd(B2,C2)

B4 = [B3[0]]
for i in range(0,N-1):
    B4.append(B4[i] + B3[i+1])

ans = 0
for i in range (0,N):
    if C3[i] > 0:
        ans = ans + B4[C3[i]-1]

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







def numadd(up, down):
    array = []
    count = 0
    last = 0
    for i in range(0,N):
        while down[i] > up[count]:
            count = count + 1
            if count == N:
                count = count - 1
                last = 1
                break
        array.append(count + last)
    return array

B3 = numadd(sorted(A),sorted(B))
C3 = numadd(sorted(B),sorted(C))

B4 = [B3[0]]
for i in range(0,N-1):
    B4.append(B4[i] + B3[i+1])

ans = 0
for i in range (0,N):
    if C3[i] > 0:
        ans = ans + B4[C3[i]-1]

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


A2 = sorted(A)
B2 = sorted(B)
C2 = sorted(C)


def numadd(up, down):
    array = []
    count = 0
    last = 0
    for i in range(0,N):
        while down[i] > up[count]:
            count = count + 1
            if count == N:
                count = count - 1
                last = 1
                break
        array.append(count + last)
    return array

B3 = numadd(A2,B2)
C3 = numadd(B2,C2)

B4 = [B3[0]]
for i in range(0,N-1):
    B4.append(B4[i] + B3[i+1])

ans = 0
for i in range (0,N):
    if C3[i] > 0:
        ans = ans + B4[C3[i]-1]

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.sort()
b.sort()
b=b[::-1]
c.sort()
ans=tmp=0
for i in b:
    x=bisect.bisect_left(a,i)
    y=bisect.bisect_right(c, 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()

cnt = 0
for b in B:
    a_cand = bisect_left(A,b)
    c_cand = N - bisect_right(C,b)
    
    cnt += a_cand * c_cand
    
print(cnt)

Solution (Python):
import bisect
N=int(input())
s=[list(sorted(map(int,input().split()))) for i in range(3)]
t=[]
q=0
for i in s[1]:
    t.append(N-bisect.bisect_right(s[2],i))
for i in range(N):
    q+=bisect.bisect_left(s[0],s[1][i])*t[i]
print(q)

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)
z = [0] * N
ans = 0
for i in range(N-1,-1,-1):
  e = b[i]
  cin =  bisect.bisect_right(c,e)
  if i + 1 == N:
    z[i] = N-cin
  else:
    z[i] = z[i+1] + N-cin
for i in range(N):
  d = a[i]
  bind =  bisect.bisect_right(b,d)
  if bind == N:
    continue
  ans += z[bind]
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:
    ai = bisect.bisect_left(A,b)
    ci = bisect.bisect(C,b)
    ans += ai*(N-ci)
print(ans)

Solution (Python):
import bisect as bisect
N = int(input())
*A, = map(int, input().split())
*B, = map(int, input().split())
*C, = map(int, input().split())
A = sorted(A)
B = sorted(B)
C = sorted(C)
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 = 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 = []
for i in range(N):
    if i == 0:
        B_num.append(bisect.bisect_left(A, B[i]))
    else:
        B_num.append(bisect.bisect_left(A, B[i]) + B_num[i-1])

count = 0
for i in range(N):
    idx = bisect.bisect_left(B, C[i])
    if idx == 0:
        continue
    else:
        count += B_num[idx - 1]

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

ab=[0]*N
count=0

for i in range(N):
    while count<N and A[count]<B[i]:
        count+=1
    ab[i]=count

count=0
ans=0
bc=[0]*N

for i in range(N-1,-1,-1):
    while count<N and C[count]>B[i]:
        count+=1
    
    ans+=count*ab[i]

print(ans)