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

Solution (Python):
n = int(input())
an = list(map(int, input().split(' ')))
bn = list(map(int, input().split(' ')))
cn = list(map(int, input().split(' ')))

an = sorted(an)
bn = sorted(bn)
cn = sorted(cn)

bcount = [0] * n
ccount = [0] * n

ai = 0
for bi in range(n):
    while ai < n and bn[bi] > an[ai]:
        bcount[bi] += 1
        ai += 1
    if bi < len(bn) - 1:
        bcount[bi + 1] = bcount[bi]

bi = 0
for ci in range(n):
    while bi < n and cn[ci] > bn[bi]:
        ccount[ci] += bcount[bi]
        bi += 1
    if ci < len(cn) - 1:
        ccount[ci + 1] = ccount[ci]
        
print(sum(ccount))

Solution (Python):


import numpy as np
N = int(input())
A = np.array(list(int(x) for x in input().split()))
B = np.array(list(int(x) for x in input().split()))
C = np.array(list(int(x) for x in input().split()))
A.sort()
C.sort()

ans = np.sum(np.searchsorted(A, B,'left') * (N - np.searchsorted(C, B,'right')))
print(ans)

Solution (Python):


import bisect

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

A.sort()
C.sort()

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

print(ans)

Solution (Python):


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

A.sort()
C.sort()

def binarySearchLeft(a, b):
    l = -1
    r = N
    while l+1<r:
        m = (l+r)//2
        if a[m]<b:
            l = m
        else:
            r = m
    return r

def binarySearchRight(a, b):
    l = -1
    r = N
    while l+1<r:
        m = (l+r)//2
        if a[m]<=b:
            l = m
        else:
            r = m
    return r

ans = 0
for j in range(N):
    ans += binarySearchLeft(A, B[j]) * (N - binarySearchRight(C, B[j]))

print(ans)

Solution (Python):


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

B.sort()
C.sort()

def binarySearch(a, b):
    l = -1
    r = N
    while l+1<r:
        m = (l+r)//2
        if a[m]<=b:
            l = m
        else:
            r = m
    return l+1

BC = []
for i in range(N):
    tmp = binarySearch(C, B[i])
    BC.append((N - tmp))

BC = BC[::-1]
BC2 = [0] * (N+1)
for i in range(N):
    BC2[i+1] = BC2[i] + BC[i]
BC2 = BC2[::-1]

ans = 0
for i in range(N):
    b = binarySearch(B, A[i])
    ans += BC2[b]

print(ans)

Solution (Python):
import sys
from bisect import bisect_left, bisect_right, insort_left, insort_right
from collections import defaultdict, deque, Counter
from copy import deepcopy
from fractions import gcd
from functools import lru_cache, reduce
from heapq import heappop, heappush
from itertools import accumulate, groupby, product, permutations, combinations, combinations_with_replacement
from math import ceil, floor, sqrt, cos, sin, pi
from operator import itemgetter
sys.setrecursionlimit(10**6)
rs = lambda: sys.stdin.readline().rstrip()
ri = lambda: int(rs())
rf = lambda: float(rs())
rs_ = lambda: [_ for _ in rs().split()]
ri_ = lambda: [int(_) for _ in rs().split()]
rf_ = lambda: [float(_) for _ in rs().split()]

N = ri()
A = sorted(ri_())
B = sorted(ri_())
C = sorted(ri_())
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(int(x) for x in input().split())
B = list(int(x) for x in input().split())
C = list(int(x) for x in input().split())

B.sort()
C.sort()

BC = []
for i in range(N):
    BC.append((N - bisect.bisect_right(C, B[i])))

BC = BC[::-1]
BC2 = [0] * (N+1)
for i in range(N):
    BC2[i+1] = BC2[i] + BC[i]
BC2 = BC2[::-1]

ans = 0
for i in range(N):
    b = bisect.bisect_right(B, A[i])
    ans += BC2[b]

print(ans)

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

    cnt = 0
    for i in range(N):
        a_cnt = binSearch(B[i],A)
        c_cnt = N - binSearch(B[i]+1, C)
        cnt += a_cnt * c_cnt
    
    print(cnt)

def binSearch(target,lst):
    left = -1
    right = len(lst)

    while right - left > 1:
        mid = (right+left) // 2
        if lst[mid] < target:
            left = mid
        else:
            right = mid
    
    return right

if __name__ == '__main__':
    solve()

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

Solution (Python):
import bisect

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

ans = 0
for bb in b:
    ai = bisect.bisect_left(a, bb)
    ci = bisect.bisect_right(c, bb)
    ans = ans + (ai * (n-ci))

print(ans)

Solution (Python):
import bisect

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

ans = 0
A.sort()
C.sort()
for 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()))

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

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

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

Solution (Python):
from bisect 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()))
D = list(accumulate(N - bisect(C, b) for b in reversed(B))) + [0]
print(sum(D[N - bisect(B, a) - 1] for a in A))

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


def binary_upper(k, x):
    return len(k) - bisect.bisect_right(k, x)


def binary_lower(k, x):
    return bisect.bisect_left(k, x)


ans = 0

for middle in b:
    cnt_a = binary_lower(a, middle)
    cnt_c = binary_upper(c, middle)
    ans += cnt_a * cnt_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()
ct = 0
for j in B:
    a_max = bisect.bisect_left(A, j)
    c_min = bisect.bisect_right(C, j)
    ct += a_max * (n - c_min)
print(ct)

Solution (Python):
import numpy as np

N = int(input())
A = np.array(input().split(), np.int64)
B = np.array(input().split(), np.int64)
C = np.array(input().split(), np.int64)
A.sort()
B.sort()
C.sort()

x = np.searchsorted(B, A, 'right')
y = np.searchsorted(C, B, 'right')
Z = np.add.accumulate(N - y[::-1])
ans = sum(Z[k - 1] for k in N - x if k)
print(ans)

Solution (Python):
def bin_search(i, array):
    low = 0
    high = len(array) - 1

    while low <= high:
        mid = (low + high) // 2
        
        if array[mid] < i and (mid == len(array)-1 or array[mid+1] >= i ):
            
            return mid + 1
        
        elif array[mid] < i:
            
            low = mid + 1
        
        elif array[mid] >= i:
            
            high = mid - 1
    
    return 0


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

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





B_num = [0]*N
for i in range(N):
    b = B[i]
    B_num[i] = bin_search(b, A)

C_num = [0]*N
for i in range(N):
    c = C[i]
    C_num[i] = bin_search(c, B)

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




ans = 0
for i in range(N):
    if C_num[i] != 0:
        tmp = Cumulative_sum[C_num[i] - 1]
        
        ans += tmp
    
    

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

cnt = 0
cnt_b = []
for i_b in range(n):
    
    
    
    i_a = bisect.bisect_left(a, b[i_b]) - 1
    i_c = bisect.bisect_right(c, b[i_b])
    if i_a < 0 or n <= i_c:
        continue
    cnt += (i_a + 1) * (n - i_c)
    

print(cnt)

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

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

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

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

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

print(ans)

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

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 j in range(n):
    al=bisect.bisect_left(a,b[j])
    cl=n-bisect.bisect_right(c,b[j])
    ans+=al*cl
print(ans)

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

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 j in range(n):
    al=bisect.bisect_left(a,b[j])
    cl=n-bisect.bisect_right(c,b[j])
    ans+=al*cl
print(ans)

Solution (Python):
import bisect
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=sorted(a)
B=sorted(b)
C=sorted(c)
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):
from bisect import bisect_left as bil
from bisect import bisect_right as bir
from itertools import accumulate


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

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

t = [0]*(N+1)

for i, b in enumerate(B):
    j = bil(A, b)
    t[i+1] = j


t = list(accumulate(t))


ans = 0
for c in C:
    i = bil(B, c)
    ans += t[i]

print(ans)

Solution (Python):

import sys
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 7)

import bisect
N = int(readline())
A = sorted(list(map(int,readline().rstrip().split())))
B = list(map(int,readline().rstrip().split()))
C = sorted(list(map(int,readline().rstrip().split())))
cnt = 0
for i in range(N):
    j = bisect.bisect_left(A,B[i])
    k = bisect.bisect_right(C,B[i])
    cnt += j*(N-k)
print(cnt)

Solution (Python):

import sys
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 7)

import bisect
N = int(readline())
A = sorted(list(map(int,readline().rstrip().split())))
B = sorted(list(map(int,readline().rstrip().split())))
C = sorted(list(map(int,readline().rstrip().split())))
cnt = 0
for i in range(N):
    j = bisect.bisect_left(A,B[i])
    k = bisect.bisect_right(C,B[i])
    cnt += j*(N-k)
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()
cnt = 0

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

Solution (Python):
import bisect

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

ans = 0

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

Solution (Python):


import sys
import math
import collections
import itertools
import bisect
INF = 10 ** 13
MOD = 10 ** 9 + 7
def input() : return sys.stdin.readline().strip()
def lcm(x, y) : return (x * y) // math.gcd(x, y)
def I() : return int(input())
def LI() : return [int(x) for x in input().split()]
def RI(N) : return [int(input()) for _ in range(N)]
def LRI(N) : return [[int(x) for x in input().split()] for _ in range(N)]
def LS() : return input().split()
def RS(N) : return [input() for _ in range(N)]
def LRS(N) : return [input().split() for _ in range(N)]
def PL(L) : print(*L, sep="\n")
def YesNo(B) : print("Yes" if B else "No")
def YESNO(B) : print("YES" if B else "NO")

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

A.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):
from bisect import bisect_left,bisect_right
import sys
input = sys.stdin.readline


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

sa = sorted(a)
sb = sorted(b)
sc = sorted(c)

ans = 0
for i in range(n):
    ab = bisect_left(sa,sb[i])
    bc = n - bisect_right(sc,sb[i])

    if ab == 0:
        continue
    ans += ab * bc

print(ans)

Solution (Python):
from bisect import bisect_right, bisect_left


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

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

    ans = 0
    for b in B:
        idx_a = bisect_left(A, b)
        cnt_a = idx_a

        idx_c = bisect_right(C, b)
        cnt_c = N - idx_c

        ans += cnt_a * cnt_c

    print(ans)


if __name__ == '__main__':
    main()

Solution (Python):
import bisect
n=int(input())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
c=list(map(int,input().split()))
a.sort()
b.sort()
c.sort()
ans=0
for i in range(n):
  A=bisect.bisect_left(a,b[i])
  B=bisect.bisect_right(c,b[i])
  ans=ans+A*(n-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()
ans = 0
for b in B:
    a = bisect.bisect_left(A, b) 
    c = bisect.bisect_right(C, b) 
    ans += a * (len(C)-c)
print (ans)

Solution (Python):
import bisect
from sys import stdin

def get_result(data):
    N = data[0][0]
    A = sorted(data[1])
    B = sorted(data[2])
    C = sorted(data[3])
    ans = 0
    for mid_val in B:
      num_a = bisect.bisect_left(A, mid_val)
      num_c = N - bisect.bisect_right(C, mid_val)
      ans += num_a * num_c
    return ans


if __name__ == '__main__':
    raw_data = [val.rstrip() for val in stdin.readlines()]
    data = [list(map(int, val.split(' '))) for val in raw_data]
    result = get_result(data)
    print(result)

Solution (Python):
import bisect
def I(): return int(input())
def LI(): return list(map(int,input().split()))
N = I()
A = sorted(LI())
B = sorted(LI())
C = sorted(LI())
ans = 0
for b in B:
    ok_a = bisect.bisect_left(A,b)
    ok_c = bisect.bisect_right(C,b)
    ans += ok_a*(N-ok_c)
print(ans)

Solution (Python):
import bisect
def I(): return int(input())
def LI(): return list(map(int,input().split()))
N = I()
A = sorted(LI())
B = sorted(LI())
C = sorted(LI())
ans = 0
for b in B:
    ok_a = bisect.bisect_left(A,b)
    ok_c = bisect.bisect_right(C,b)
    if ok_a!=0 and ok_c!=N:
        ans += ok_a*(N-ok_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):
    p = bisect.bisect_left(a,b[i])
    q = bisect.bisect_right(c,b[i])
    ans += p * (n-q)

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()
anssum = 0
for i in B:
    moreB = N-bisect.bisect_right(C,i)
    lessB = bisect.bisect_left(A,i)
    anssum += moreB*lessB
print(anssum)

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()
from bisect import bisect_left
ans = 0
for i in range(N):
    b = B[i]
    inda = bisect_left(A,b)
    indc = bisect_left(C,b+1)
    ans += (N-indc)*inda
print(ans)

Solution (Python):
import numpy as np
import sys
input = sys.stdin.readline

n = int(input())
an = list(map(int, input().split()))
bn = list(map(int, input().split()))
cn = list(map(int, input().split()))

an.sort()
cn.sort()

a_pair = []
for i in bn:
    if i <= an[0]:
        a_pair.append(0)
        continue
    if i > an[-1]:
        a_pair.append(n)
        continue
    front = 0
    back = n-1
    while front != back:
        mid = (front+back)//2
        if an[mid] < i:
            front = mid + 1
        else:
            back = mid
    a_pair.append(front)

c_pair = []
for i in bn:
    if i >= cn[-1]:
        c_pair.append(0)
        continue
    if i < cn[0]:
        c_pair.append(n)
        continue
    front = 0
    back = n-1
    while front != back:
        mid = (front+back)//2
        if cn[mid] > i:
            back = mid
        else:
            front = mid + 1
    c_pair.append(n-back)

a_pair = np.array(a_pair)
c_pair = np.array(c_pair)
print(np.sum(a_pair*c_pair))

Solution (Python):
cin = open(0).read().strip().split('\n')
n = int(cin[0])
a = list(map(int, cin[1].split(' ')))
b = list(map(int, cin[2].split(' ')))
c = list(map(int, cin[3].split(' ')))

a = sorted(a)
b = sorted(b)
c = sorted(c)

from bisect import bisect_left, bisect

print(sum([bisect_left(a, bi)*(n-bisect(c, bi)) for bi in b]))

Solution (Python):


def solve():
    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()
    lenA, lenB, lenC = len(As), len(Bs), len(Cs)

    Bs_cases = [0 for _ in range(lenB)]  
    for bi in range(lenB-1, -1, -1):
        cidx = bisect.bisect_right(Cs, Bs[bi])
        if cidx == lenC:
            Bs_cases[bi] = 0
        else:
            Bs_cases[bi] = lenC-cidx

    Bs_cases_ruiseki = [0 for _ in range(lenB)]  
    Bs_cases_ruiseki[lenB-1] = Bs_cases[lenB-1]
    for bi in range(lenB-2, -1, -1):
        Bs_cases_ruiseki[bi] = Bs_cases_ruiseki[bi+1] + Bs_cases[bi]

    ans = 0
    for a in As:
        bidx = bisect.bisect_right(Bs, a)
        if bidx == lenB:
            continue
        ans += Bs_cases_ruiseki[bidx]

    print(ans)


if __name__ == "__main__":
    solve()

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

from bisect import bisect_left,bisect

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

print(ans)

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

for i in b:
    ans_a=bisect.bisect_left(a,i)
    ans_c=n-(bisect.bisect_right(c,i))
    ans+=ans_a*ans_c

print(ans)

Solution (Python):
import bisect

N = int(input())
Alist = sorted(list(map(int, input().split())))
Blist = sorted(list(map(int, input().split())))
Clist = sorted(list(map(int, input().split())))

ans = 0

for B in Blist:
    Aindex = bisect.bisect_left(Alist, B)
    Cindex = bisect.bisect_right(Clist, B)


    ans += Aindex * (N - Cindex)

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

Solution (Python):
import bisect
import sys

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


def input():
    return sys.stdin.readline().strip()


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

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

    print(ans)


if __name__ == "__main__":
    main()

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

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

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

    B2 = [bisect_left(A, b) for b in B]
    B3 = [B2[0]]
    pre = B3[0]
    for b in B2[1:]:
        pre += b
        B3.append(pre)
    C2 = [bisect_left(B, c) for c in C]
    B3.append(0)
    ans = sum([B3[c-1] for c in C2])
    print(ans)
    
if __name__ == '__main__':
    main()

Solution (Python):

import sys

stdin = sys.stdin
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip() 


def BinarySearch(num, nums):
    if len(nums) == 0:
        print("Erorr : list has no element")
        return
    left,right = 0,len(nums)
    while left < right:
        mid  = (left+right)//2
        if num < nums[mid]:
            right = mid
        else:
            left = mid + 1
    return right


def main():
    n = ni()
    a = sorted(na()) + [float('inf')]
    b = sorted(na())
    c = sorted(na()) + [float('inf')]
    ans = 0
    small = 0
    big = 0
    for mid in b:
        while a[small] < mid:
            small += 1
        while c[big] <= mid:
            big += 1
        ans += small * (n-big)
    print(ans)
    return


if __name__ == '__main__':
    main()

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

ans=0
for 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()))
t = 0
ans = 0
u =[0]*n
d =[0]*n
a2 =[]
b2 =[]
c2 =[]

for i in range(n):
    a2.append([2,a[i]])
for i in range(n):
    b2.append([1,b[i]])
for i in range(n):
    c2.append([0,c[i]])
a2b2=a2+b2
b2c2=b2+c2

a2b2.sort(key = lambda x:(x[1],x[0]))
b2c2.sort(key = lambda x:(x[1],x[0]),reverse=True)

j=0
c=0
for i in range(2*n):
    if a2b2[i][0]==2:
        c+=1
    if a2b2[i][0]==1:
        u[j]=c
        j+=1
j=0
c=0
for i in range(2*n):
    if b2c2[i][0]==0:
        c+=1
    if b2c2[i][0]==1:
        d[j]=c
        j+=1
d.reverse()
for i in range(n):
    ans+=u[i]*d[i]
print(ans)

Solution (Python):
import sys
import os
import math
import bisect

ii = lambda: int(sys.stdin.buffer.readline().rstrip())
il = lambda: list(map(int, sys.stdin.buffer.readline().split()))
fl = lambda: list(map(float, sys.stdin.buffer.readline().split()))
iln = lambda n: [int(sys.stdin.buffer.readline().rstrip()) for _ in range(n)]

iss = lambda: sys.stdin.buffer.readline().decode().rstrip()
sl = lambda: list(map(str, sys.stdin.buffer.readline().decode().split()))
isn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)]

lcm = lambda x, y: x * y / math.gcd(x, y)

MOD = 10 ** 9 + 7
MAX = float('inf')


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

    N = ii()
    A = sorted(il())
    B = sorted(il())
    C = sorted(il())

    ret = 0
    for b in B:
        al = bisect.bisect_right(A, b-1)
        cl = len(C) - bisect.bisect_left(C, b+1)
        ret += al*cl
    print(ret)


if __name__ == '__main__':
    main()

Solution (Python):
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

from bisect import bisect_left 
from bisect import bisect_right
def main():
    n = int(readline()) 
    a = [int(i) for i in readline().split()]
    b = [int(i) for i in readline().split()]
    c = [int(i) for i in readline().split()]
    a.sort()
    c.sort()
    ans = 0
    for v in b:
        i = bisect_left(a, v)
        j = bisect_right(c, v)
        ans += i*(n-j)
    print(ans)
if __name__ == '__main__':
    main()

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):
    a_cnt = bisect_left(a, b[i], 0, n)
    c_cnt = n - bisect_right(c, b[i], 0, n)
    
    ans += a_cnt * c_cnt

print(ans)

Solution (Python):
import numpy as np

N = int(input())
ts = list(map(int, input().split()))
ms = list(map(int, input().split()))
bs = list(map(int, input().split()))

ts = sorted(ts)
ms = sorted(ms)
bs = sorted(bs)

m_count = np.zeros(N, dtype=int)
i = 0
for j, m in enumerate(ms):
    while i < N and m >= bs[i]:
        i += 1
    m_count[j] = N-i
m_cumcount = np.cumsum(m_count[::-1])[::-1]


i = 0
ans = 0
for j, t in enumerate(ts):
    while i < N and t >= ms[i]:
        i += 1
    
    if i == N:
        break
    ans += m_cumcount[i] 
    
print(ans)

Solution (Python):
from itertools import accumulate
import bisect
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))
a.sort()
b.sort()
c.sort()
ans = 0
b_ = []
for bi in reversed(b):
    b_.append(n - bisect.bisect_right(c, bi))
b_ = list(accumulate(b_))[::-1]
for ai in a:
    idx_b = bisect.bisect_right(b, ai)
    if idx_b == n:
        break
    ans += b_[idx_b]
print(ans)

Solution (Python):
from bisect import bisect_right, bisect_left
from itertools import accumulate
n = int(input())
li_a = list(map(int, input().split()))
li_b = list(map(int, input().split()))
li_c = list(map(int, input().split()))
li_a.sort()
li_b.sort()
li_c.sort()
relation_bc = [] 
for i in range(n):
    i += 1
    j = li_b[(-1)*i]
    k = bisect_right(li_c, j)
    relation_bc.append(len(li_c)-k)
ans = 0
li = list(accumulate(relation_bc))
for i in li_a:
    p = bisect_right(li_b, i) 
    p = n - p
    if p >= 1:
        ans += li[p-1]
    else:
        continue
print(ans)

Solution (Python):
import bisect
N=int(input())
alist=list(map(int,input().split()))
blist=list(map(int,input().split()))
clist=list(map(int,input().split()))
alist.sort()
blist.sort()
clist.sort()

answer=0
ai,ci=0,0
for bi in range(N):
  while(ai<N and alist[ai]<blist[bi]):
    ai+=1
  while(ci<N and blist[bi]>=clist[ci]):
    ci+=1
  
  answer+=ai*(N-ci)

print(answer)

Solution (Python):
import bisect
N=int(input())
alist=list(map(int,input().split()))
blist=list(map(int,input().split()))
clist=list(map(int,input().split()))
alist.sort()
blist.sort()
clist.sort()

answer=0
for bi in range(N):
  ai=bisect.bisect_left(alist,blist[bi])  
  ci=bisect.bisect(clist,blist[bi])  
  
  answer+=ai*(N-ci)

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

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

print(sum)

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


def input():
    return stdin.readline().strip()


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

    A.sort()
    C.sort()

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

    print(ans)


if __name__ == "__main__":
    main()