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

Solution (Python):
n=int(input())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
c=list(map(int,input().split()))
a.sort()
b.sort()
c.sort()
y=[]
import bisect
for i in range(n):
	y.append(bisect.bisect_left(a,b[i]))
ans=0
q=[]
for i in range(n):
	p=bisect.bisect_left(b,c[i])
	q.append(p)
k=sum(y[0:q[0]])
for i in range(n-1):
	ans+=k
	if q[i+1]!=q[i]:
		k+=sum(y[q[i]:q[i+1]])
ans+=k
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())))
t = 0
for i in b:
    t += (bisect.bisect_left(a, i) * (n - bisect.bisect_right(c, i)))
print(t)

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

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

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

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

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


X = [bisect_left(A ,B[i]) for i in range(N)]
Y = [N - bisect_right(C ,B[i]) for i in range(N)]

total = 0

for x,y in zip(X, Y):
    total += x * y

print(total)

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

print(ans)

Solution (Python):


from bisect import bisect_left,bisect_right

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

for i in range(n):
    bc=n-bisect_right(c,b[i])
    ba=bisect_left(a,b[i])
    ans+=bc*ba    

print(ans)

Solution (Python):
import bisect

a = int(input())
b = list(map(int, input().split()))
b.sort()
c = list(map(int, input().split()))
d = list(map(int, input().split()))
d.sort()
e = 0
for i in c:
    e += bisect.bisect_left(b, i) * (a - bisect.bisect_right(d, i))
print(e)

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
i = 0
j = 0
for b in B:
    while i < N and A[i] < b:
        i += 1
    while j < N and C[j] <= b:
        j += 1
    ans += i * (N-j)

print(ans)

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

Solution (Python):
import bisect
n = int(input())
a = sorted([int(i) for i in input().split()])
b = sorted([int(i) for i in input().split()])
c = sorted([int(i) for i in input().split()])
ans = 0
for i in b:
    ans += bisect.bisect_left(a, i) * (n - bisect.bisect(c, i))
print(ans)

Solution (Python):
from bisect import bisect_left, bisect
n=int(input())
la=sorted(list(map(int,input().split())))
lb=list(map(int,input().split()))
lc=sorted(list(map(int,input().split())))
ans=0
for i in lb:
    ans+=bisect_left(la,i)*(len(lc)-bisect(lc,i))
print(ans)

Solution (Python):
from bisect import bisect_left, bisect
n=int(input())
la=sorted(list(map(int,input().split())))
lb=list(map(int,input().split()))
lc=sorted(list(map(int,input().split())))
ans=0
for i in lb:
    ans+=bisect_left(la,i)*(len(lc)-bisect(lc,i))
print(ans)

Solution (Python):
from bisect import bisect

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

b_cost = [0]

for i,b in enumerate(bb):
  b_cost.append(N-bisect(cc, b)+b_cost[i])

ans = 0
for a in aa:
  idx = bisect(bb, a)
  ans += b_cost[-1]-b_cost[idx]
print(ans)

Solution (Python):

import bisect

n = int(input())
A = sorted([int(el) for el in input().split(' ')])
B = [int(el) for el in input().split(' ')]
C = sorted([int(el) for el in input().split(' ')])

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

Solution (Python):
n=int(input())
a=sorted([int(_) for _ in input().split()])
b=[int(_) for _ in input().split()]
c=sorted([int(_) for _ in input().split()])
x=0
for i in range(n):
    oa=-1
    na=n
    while na-oa>1:
        ma=(oa+na)//2
        if a[ma]<b[i]:oa=ma
        else:na=ma
    ob=n
    nb=-1
    while ob-nb>1:
        mb=(ob+nb)//2
        if c[mb]>b[i]:ob=mb
        else:nb=mb
    x+=(oa+1)*(n-ob)
print(x)

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) * (N - bisect.bisect_right(C, b))

print(ans)

Solution (Python):

import sys
input = sys.stdin.readline

from bisect import bisect_left, bisect_right

def main():
    n = int(input())
    A, B, C = [sorted(map(int, input().rstrip().split())) for _ in range(3)]
    l, ans = len(C), 0
    for i in B:
        ans += bisect_left(A, i) * (l - bisect_right(C, i))
    print(ans)


if __name__ == "__main__":
    main()

Solution (Python):

from bisect import bisect_left, bisect_right

def main():
    n = int(input())
    A, B, C = [sorted(tuple(map(int, input().rstrip().split()))) for _ in range(3)]
    l, ans = len(C), 0
    for i in B:
        ans += bisect_left(A, i) * (l - bisect_right(C, i))
    print(ans)


if __name__ == "__main__":
    main()

Solution (Python):
n = int(input())
dat_a = list(map(int, input().split()))
dat_b = list(map(int, input().split()))
dat_c = list(map(int, input().split()))
dat_a.sort()
dat_b.sort()
dat_c.sort()

import bisect
res = 0
for i in range(n):
    x = bisect.bisect_left(dat_a, dat_b[i])
    y = bisect.bisect_right(dat_c, dat_b[i])
    res += x * (n - y)
print(res)

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

def func(x, y):
    i = 0
    j = 0
    cnt = 0
    s = [0 for i in range(n)]
    while j < n and i < n:
        if y[j] > x[i]:
            cnt += 1
            i += 1
        else:
            s[j] = cnt
            j += 1
    if i == n:
        for k in range(j,n):
            s[k] = cnt
    return s

s1 = func(a, b)
for i in range(1, n):
    s1[i] += s1[i-1]
s2 = func(b, c)
cnt = 0
for i in range(n):
    if s2[i] != 0:
        cnt += s1[s2[i]-1]

print(cnt)

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

Solution (Python):
n = int(input())
a = [int(x) for x in input().split()]
b = [int(x) for x in input().split()]
c = [int(x) for x in input().split()]


a.sort()
c.sort()

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

print(cnt)

Solution (Python):
from bisect import bisect_left, bisect_right

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

ans = 0
for b in B:
    ans += bisect_left(A, b) * (N-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())))
cnt = 0
for bb in b:
    anum = bisect.bisect_left(a, bb)
    cnum = n - bisect.bisect_right(c, bb)
    cnt += (anum * cnum)
print(cnt)

Solution (Python):
import bisect
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()))
cnt = 0
a.sort()
c.sort()
for i in range(n):
    cnt += (bisect.bisect_left(a, b[i])) * (n-bisect.bisect_right(c, b[i]))
print(cnt)

Solution (Python):
import bisect
from sys import stdin
N = int(stdin.readline().rstrip())
A = [int(_) for _ in stdin.readline().rstrip().split()]
B = [int(_) for _ in stdin.readline().rstrip().split()]
C = [int(_) for _ in stdin.readline().rstrip().split()]
A.sort()
C.sort()
ans = 0
for b in B:
  ans += bisect.bisect_left(A, b) * (N - bisect.bisect_right(C, b))
print(ans)

Solution (Python):
N = int(input())
A, B, C = [list(map(int, input().split())) for _ in range(3)]

for x in [A, B, C]:
	x.sort()

def bsr(a, v, lo=0, hi=None):
	if hi == None:
		hi = len(a) - 1
	while lo <= hi:
		mid = (lo + hi) // 2
		if v < a[mid]:
			hi = mid - 1
		else:
			lo = mid + 1
	return lo

bt = []
for b in B:
	bt += [max(0, (N - bsr(C, b)))]

for i in range(len(B) - 2, -1, -1):
	bt[i] += bt[i + 1]

r = 0
for ai, a in enumerate(A):
	bif = bsr(B, a)
	if bif < N:
		r += bt[bif]

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()))
ans=0
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())
a = sorted(list(map(int, input().split())))
b = sorted(list(map(int, input().split())))
c = sorted(list(map(int, input().split())))
cnt = 0
for bb in b:
    anum = bisect.bisect_left(a, bb)
    cnum = n - bisect.bisect_right(c, bb)
    cnt += (anum * cnum)
print(cnt)

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
j = 0
k = 0


for i in range(n):
    if j<n:
        while a[j]<b[i]:
            j+=1
            if j==n:
                break
    if k<n:
        while c[k]<=b[i]:
            k+=1
            if k==n:
                break

    ans += j*(n-k)


print(ans)

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

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())))
cnt=0
x=[]
i=0
b__=b.copy()
rev=0
while(b__):
     b_=b__.pop()
     while(1):
          try:
               c_=c.pop()
          except:
               rev+=cnt
               x.append(rev)
               cnt=0
               break
          if c_>b_:
               cnt+=1
          else:
               rev+=cnt
               x.append(rev)
               cnt=0
               c.append(c_)
               break
cnt=0
i=n-1
rev=0
ans=0
while(a):
     a_=a.pop()
     while(1):
          try:
               b_=b.pop()
          except:
               rev+=cnt
               ans+=rev
               cnt=0
               break
          if b_>a_:
               cnt+=x.pop(0)
          else:
               rev+=cnt
               ans+=rev
               cnt=0
               b.append(b_)
               break
print(ans)

Solution (Python):
import bisect
n = int(input())
a = [sorted(list(map(int, input().split())))for _ in range(3)]
ans = 0
for b in a[1]:
  ans += bisect.bisect_left(a[0], b) * (n - bisect.bisect_right(a[2], b))
print(ans)

Solution (Python):


from bisect import bisect_left, bisect_right

n = int(input())
A, B, C = [sorted(list(map(int, input().rstrip().split()))) for _ in range(3)]
lgth = len(C)
ans = 0
for i in B:
    ans += bisect_left(A, i) * (lgth - bisect_right(C, i))
print(ans)

Solution (Python):

from bisect import bisect_left, bisect_right

n = int(input())
lst_a = sorted(list(map(int, input().rstrip().split())))
lst_b = sorted(list(map(int, input().rstrip().split())))
lst_c = sorted(list(map(int, input().rstrip().split())))
lgth = len(lst_c)
ans = 0
for i in lst_b:
    ans += bisect_left(lst_a, i) * (lgth - bisect_right(lst_c, i))
print(ans)

Solution (Python):

from bisect import bisect_left, bisect_right

n = int(input())
lst_a = sorted(list(map(int, input().rstrip().split())))
lst_b = list(map(int, input().rstrip().split()))
lst_c = sorted(list(map(int, input().rstrip().split())))
lgth = len(lst_c)
ans = 0
for i in lst_b:
    ans += bisect_left(lst_a, i) * (lgth - bisect_right(lst_c, i))
print(ans)

Solution (Python):

from bisect import bisect_left, bisect_right

n = int(input())
lst_a = sorted(list(map(int, input().rstrip().split())))
lst_b = list(map(int, input().rstrip().split()))
lst_c = sorted(list(map(int, input().rstrip().split())))
lgth = len(lst_c)
ans = 0
for i in lst_b:
    ans += bisect_left(lst_a, i) * (lgth - bisect_right(lst_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()

count = 0

for i in range(len(B)):
    a_b = bisect.bisect_left(A,B[i])
    c_b = bisect.bisect_right(C,B[i])
    count += a_b * (N - c_b)

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

sum = 0
for i in range(len(b)):
    ai = bisect.bisect_left(a, b[i])
    ci = bisect.bisect_right(c, b[i])
    sum += ai * (n - ci)

print(sum)

Solution (Python):
N = int(input())

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

cur_l = 0
cur_r = 0
p = 0
for cur_mid in B:
    while cur_l < len(A):
        if A[cur_l] >= cur_mid:
            break
        cur_l += 1
    while cur_r < len(C):
        if cur_mid < C[cur_r]:
            break
        cur_r += 1
    p += cur_l * (len(C) - cur_r)

print(p)

Solution (Python):
N = int(input())

L = []
L.extend(((int(x), 3)  for x in input().split()))
L.extend(((int(x), 2)  for x in input().split()))
L.extend(((int(x), 1)  for x in input().split()))

L = sorted(L, reverse=True)

cnt_C = 0
cnt_B = 0
cnt_A = 0
for x, i in L:
    if i == 1:
        cnt_C += 1
    elif i == 2:
        cnt_B += cnt_C
    elif i == 3:
        cnt_A += cnt_B

print(cnt_A)

Solution (Python):
N = int(input())

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

L = []
L.extend(((x, 3)  for x in A))
L.extend(((x, 2)  for x in B))
L.extend(((x, 1)  for x in C))

L = sorted(L, reverse=True)

cnt_C = 0
cnt_B = 0
cnt_A = 0
for x, i in L:
    if i == 1:
        cnt_C += 1
    elif i == 2:
        cnt_B += cnt_C
    elif i == 3:
        cnt_A += cnt_B

print(cnt_A)

Solution (Python):
N = int(input())

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

L = []
L.extend(((x, 3)  for x in A))
L.extend(((x, 2)  for x in B))
L.extend(((x, 1)  for x in C))

L = sorted(L, reverse=True)

cnt_C = 0
cnt_B = 0
cnt_A = 0
for x, i in L:
    if i == 1:
        cnt_C += 1
    elif i == 2:
        cnt_B += cnt_C
    elif i == 3:
        cnt_A += cnt_B

print(cnt_A)

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):
    tmp = 1
    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 = [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()

numpattern = 0

for i in range(N):
    numsmallerA = bisect.bisect_left(A,B[i])
    numbiggerC = N - bisect.bisect_right(C,B[i])
    numpattern += numsmallerA * numbiggerC

print(numpattern)

Solution (Python):
from bisect import bisect_left as bisect
from numpy import cumsum
N=int(input())
A,B,C=[sorted([int(_) for _ in input().split()]) for __ in range(3)]
ableAonB=[]
ableBonC=[]
ans=0
for b in B:
    ableAonB.append(bisect(A,b))
sumAonB=(cumsum(ableAonB))
for c in C:
    ableBonC.append(bisect(B,c))
for c in ableBonC:
    if c==0:continue
    ans+=sumAonB[c-1]
print(ans)

Solution (Python):


import math
import sys


MX = 10**9+1

N = int(sys.stdin.readline().rstrip())
An = list(map(int, sys.stdin.readline().rstrip().split()))
Bn = list(map(int, sys.stdin.readline().rstrip().split()))
Cn = list(map(int, sys.stdin.readline().rstrip().split()))

An = sorted(An)+[MX]
Bn = sorted(Bn)
Cn = sorted(Cn)+[MX]

ans,ia,ic = [0, 0, 0]
for b in Bn:
  while(An[ia] < b):
    ia += 1
  while(Cn[ic] <= b):
    ic += 1
  ans += ia * (N-ic)

print(ans)

Solution (Python):
n=int(input())
arr1=sorted(list(map(int,input().split())),reverse=True)
arr2=sorted(list(map(int,input().split())),reverse=True)
arr3=sorted(list(map(int,input().split())),reverse=True)
cnt=[0]*n
ans=0
pos=0
for i in range(n):
  for j in range(pos,n):
    if arr1[j]<arr2[i]:
      cnt[i]=n-pos
      break
    else:
      pos+=1
pos=0
for i in range(n):
  for j in range(pos,n):
    if arr2[i]<arr3[j]:
      pos+=1
    else:
      ans+=cnt[i]*pos
      break
  else:
    ans+=cnt[i]*pos
print(ans)

Solution (Python):
from functools import reduce
import math
import bisect
import collections 
def main():
    
    
    
    

    
    
    
    
    
    

    
    

    
    
    
    
    
    
    
    
    
    INF = float("inf")

    
    MOD = 10**9+7
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    

    
    
    
    
    N = int(input())
    A = list(int(_) for _ in input().split())
    B = list(int(_) for _ in input().split())
    C = list(int(_) for _ in input().split())
    A.sort()
    C.sort()
    ans = 0

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

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

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

ans = 0
for b in bs_:
  ans += bisect.bisect_left(as_, b) * (n-bisect.bisect_right(cs_, b))
print(ans)

Solution (Python):
from bisect import bisect_left, bisect_right

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

ans = 0

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

print(ans)

Solution (Python):
import sys, os
import bisect

f = lambda:list(map(int,input().split()))
if 'local' in os.environ :
    sys.stdin = open('./input.txt', 'r')

def solve():
    n = f()[0]
    a = f()
    b = f()
    c = f()

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

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


    

solve()

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

o = []
p = []

i = 0
k = 0
for j in range(N):
    while i < N and A[i] < B[j]:
        i = i + 1
    o.append(i)

    while k < N and B[j] >= C[k]:
        k = k + 1
    p.append(N-k)

sum = 0
for x in range(N):
    sum = sum + o[x] * p[x]

print(sum)

Solution (Python):
import bisect

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

print(ans)

Solution (Python):
from bisect import bisect,bisect_left

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:
    ca = bisect_left(A,b)
    cc = N - bisect(C,b)
    ans += ca*cc

print(ans)

Solution (Python):
import bisect
def MI(): return map(int, input().split())
def II(): return int(input())
def IS(): return input()
def LI(): return list(map(int, input().split()))

n = II()
a, b, c = sorted(LI()), LI(), sorted(LI())
ans = 0
for _b in b:
    a_index = bisect.bisect_left(a,_b)
    c_index = bisect.bisect_right(c,_b)
    ans += a_index * (n - c_index)
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 b:ans+=bisect.bisect_left(a,i)*(n-bisect.bisect_right(c,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()
i,j,k=0,0,0
m1=[]
while k<n and i<n:
  if b[i]>a[k]:
    j+=1
    k+=1
  else:
    m1.append(j)
    i+=1
for t in range(len(m1),len(b)):
  m1.append(j)
i,j,k=0,0,0
m2=[]
while k<n and i<n:
  if c[i]>b[k]:
    j+=m1[k]
    k+=1
  else:
    m2.append(j)
    i+=1
for t in range(len(m2),len(c)):
  m2.append(j)
print(sum(m2))

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()
c.sort()
s = 0
for b_ in b:
    t = bisect.bisect_right(a, b_-1)
    tt = len(c) - bisect.bisect_right(c, b_)
    d = tt * t
    s += d
print(s)

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

Solution (Python):
import math, string, itertools, fractions, heapq, collections, re,  array, bisect, sys, random, time, copy, functools
sys.setrecursionlimit(10**7)
inf = 10 ** 20
eps = 1.0 / 10**10
mod = 10**9+7
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]
ddn = [(-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1)]
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def pf(s): return print(s, flush=True)

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

BC = []
for b in B:
    idx = bisect.bisect_right(C, b)
    BC.append(len(B)-idx)

b_ac = [0]
for b in reversed(BC):
    b_ac.append(b+b_ac[-1])
b_ac.sort(reverse=True)

result = 0
for a in A:
    idx = bisect.bisect_right(B, a)
    result += b_ac[idx]
print(result)

Solution (Python):
import bisect
from collections import defaultdict

N = int(input())
As  = sorted(map(int, input().split()))
Bs  = sorted(map(int, input().split()))
Cs  = sorted(map(int, input().split()))

b_counts = []
for b in Bs[::-1]:
    count = len(Cs) - bisect.bisect(Cs, b)
    if len(b_counts) > 0:
        count += b_counts[-1]
    b_counts.append(count)
b_counts = b_counts[::-1]

total = 0
for a in As:
    i = bisect.bisect(Bs, a)
    if i >= len(Bs):
        continue
    total += b_counts[i]

print(total)

Solution (Python):
from bisect import bisect_left,bisect_right
n = int(input())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
C = list(map(int,input().split()))
A.sort()
B.sort()
C.sort()
ans = 0



for b in B:
    num1 = bisect_left(A,b)
    num2 = bisect_right(C,b)
    
    ans += num1*(n-num2)

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

for i in range(N):

    count_a = bisect.bisect_left(A,B[i])
    count_c = N -bisect.bisect_right(C,B[i])
    ans += count_a*count_c
    
print(ans)

Solution (Python):
N = int(input())
A = [[int(a),"A"] for a in input().split()]
B = [[int(b),"B"] for b in input().split()]
C = [[int(c),"C"] for c in input().split()]

parts = A+B+C
parts.sort(reverse = True,key = lambda x:x[0])

A_count = 0  
B_count = 0  
C_count = 0

for s,t in parts:
    if t=="C":      
        C_count += 1
    elif t=="B":
        B_count += C_count             
    elif t=="A":
        A_count += B_count
print(A_count)

Solution (Python):
N = int(input())
A = [[int(a),"A"] for a in input().split()]
B = [[int(b),"B"] for b in input().split()]
C = [[int(c),"C"] for c in input().split()]

parts = A+B+C
parts.sort(key = lambda x:x[1])
parts.sort(reverse = True,key = lambda x:x[0])

A_pat = [0]  
B_pat = [0]
C_count = 0

for s,t in parts:
    if t=="C":      
        C_count += 1
    elif t=="B":
        B_pat.append(C_count+B_pat[-1])
    elif t=="A":
        A_pat.append(B_pat[-1]+A_pat[-1])
print(A_pat[-1])

Solution (Python):
import bisect

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

A = sorted(A)
C = sorted(C)
ans = 0

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

print(ans)

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

A = sorted(A)
B = sorted(B)
C = sorted(C)
ans = 0
midnum = []
index = 0

for i in B:
    while True:
        if index == N or A[index] >= i:
            midnum.append(index)
            break
        else:
            index += 1

index = 0
midCnum = []
tmp = 0
for i in midnum:
    tmp += i
    midCnum.append(tmp)

for i in C:
    while True:
        if index == N:
            ans += midCnum[index-1]
            break
        elif i <= B[index]:
            if index != 0:
                ans += midCnum[index-1]
            break
        else:
            index += 1

print(ans)

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



ans=0
x=cumsum([n-bisect_right(c,s)for s in b][::-1])[::-1]
y=[bisect_right(b,t)for t in a]
for i in y:
    if i<n:
        ans+=x[i]
print(ans)

Solution (Python):
from collections import defaultdict
A = defaultdict(int)
B = defaultdict(int)
C = defaultdict(int)

N = int(input())
a = [k for k in map(int, input().split())]
b = [k for k in map(int, input().split())]
c = [k for k in map(int, input().split())]

for k in range(N):
  A[a[k]] += 1
  B[b[k]] += 1
  C[c[k]] += 1

Aset = sorted(set(a))
Bset = sorted(set(b))
Cset = sorted(set(c))

cnt = 0
index_a = 0
index_c = 0
a = 0
c = N

for b in Bset:
  flag_a = False
  flag_c = False
  if a < N:
    for k in range(index_a, len(Aset)):
      if Aset[k] < b:
        a += A[Aset[k]] 
      else:
        index_a = k
        flag_a = True
        break
  for k in range(index_c, len(Cset)):
    if Cset[k] <= b:
      c -= C[Cset[k]]
    else:
      index_c = k
      flag_c = True
      break
  if flag_a == False:
    a = N
  if flag_c == False:
    break
  cnt += a*c*B[b]
print(cnt)

Solution (Python):
import bisect

n = int(input())
alist = list(sorted(map(int, input().split())))
blist = list(map(int, input().split()))
clist = list(sorted(map(int, input().split())))

ans = 0
for b in blist:
  ai = bisect.bisect_left(alist, b)
  ci = bisect.bisect_right(clist, b)
  if ai == 0 or ci == len(clist):
    continue
  else:
    ans += ai * (len(clist) - ci)
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()))
x=[1 for _ in range(N)]
ans=0
for i in range(N):
        a=bisect.bisect_left(A,B[i]) 
        c=N-bisect.bisect_right(C,B[i])
        ans+=a*c
print(ans)

Solution (Python):
import sys
from collections import deque
import copy
import math
def get_read_func(fileobject):
    if fileobject == None :
        return raw_input
    else:
        return fileobject.readline

def main():
    if len(sys.argv) > 1:
        f = open(sys.argv[1])
    else:
        f = None
    read_func = get_read_func(f);
    input_raw = read_func().strip().split()
    [N] = [int(input_raw[0])]
    input_raw = read_func().strip().split()
    A = []
    for i in range(N):
        A.append(int(input_raw[i]))
    input_raw = read_func().strip().split()
    B = []
    for i in range(N):
        B.append(int(input_raw[i]))
    input_raw = read_func().strip().split()
    C = []
    for i in range(N):
        C.append(int(input_raw[i]))
    A.sort()
    B.sort()
    C.sort()

    A_backet = {}
    C_backet = {}
    A_ptr = 0L
    C_ptr = 0L
    count = 0L
    for i in range(N):
        while A_ptr < N and A[A_ptr] < B[i]:
            A_ptr += 1L
        while C_ptr < N and C[C_ptr] <= B[i]:
            C_ptr += 1L
        count += A_ptr * (N - C_ptr)
    print count




if __name__ == '__main__':
    main()