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 = sorted([int(i) for i in input().split()])
B = [int(i) for i in input().split()]
C = sorted([int(i)-1 for i in input().split()])

def bis(x,y):
    low = 0
    high = N
    while low < high:
        mid = (low + high) // 2
        if x[mid] < y:
            low = mid + 1
        else:
            high = mid
    return low

total = 0
for b in B:
    total += bis(A,b) * (N - bis(C,b))

print(total)

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

total = 0

for i in range(N):
    low1 = 0
    high = N
    while low1 < high:
        mid = (low1 + high) // 2
        if A[mid] < B[i]:
            low1 = mid + 1
        else:
            high = mid
    low2 = 0
    high = N
    while low2 < high:
        mid = (low2 + high) // 2
        if C[mid] <= B[i]:
            low2 = mid + 1
        else:
            high = mid
    total += low1 * (N - low2)

print(total)

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

total = 0

for i in range(N):
    low = 0
    high = N 
    while low < high:
        mid1 = (low + high) // 2
        if A[mid1] < B[i]:
            low = mid1 + 1
        else:
            high = mid1
    mid1 = low
    low = 0
    high = N
    while low < high:
        mid2 = (low + high) // 2
        if C[mid2] > B[i]:
            high = mid2
        else:
            low = mid2 + 1
    mid2 = low
    total = total + mid1 * (N - mid2)

print(total)

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:
    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()
C.sort()
sum = 0
for i in B:
    a = bisect.bisect_left(A,i)
    c = len(B)-bisect.bisect_right(C,i)
    sum += a*c

print(sum)

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()
A = [-float('inf')] + A + [float('inf')]
B.sort()
C.sort()
C = [-float('inf')] + C + [float('inf')]

total = 0

for i in range(N):
    low = 0
    high = N + 1
    while low + 1 < high:
        mid1 = (low + high) // 2
        if A[mid1] < B[i]:
            low = mid1
        else:
            high = mid1
    mid1 = low
    low = 0
    high = N + 1
    while low + 1 < high:
        mid2 = (low + high) // 2
        if C[mid2] <= B[i]:
            low = mid2
        else:
            high = mid2
    mid2 = high
    total = total + mid1 * (N + 1 - mid2)

print(total)

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()
A = [-float('inf')] + A + [float('inf')]
B.sort()
C.sort()
C = [-float('inf')] + C + [float('inf')]

total = 0

for i in range(N):
    low = 0
    high = N + 1
    while high - low > 1:
        mid1 = (low + high) // 2
        if A[mid1] < B[i]:
            low = mid1
        else:
            high = mid1
    mid1 = low
    low = 0
    high = N + 1
    while high - low > 1:
        mid2 = (low + high) // 2
        if C[mid2] <= B[i]:
            low = mid2
        else:
            high = mid2
    mid2 = high
    total += mid1 * (N + 1 - mid2)

print(total)

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()
A = [-float('inf')] + A + [float('inf')]
B.sort()
C.sort()
C = [-float('inf')] + C + [float('inf')]

total = 0

for i in range(N):
    low = 0
    high = N + 1
    while high - low > 1:
        mid1 = (low + high) // 2
        if A[mid1] < B[i]:
            low = mid1
        else:
            high = mid1
    mid1 = low
    low = 0
    high = N + 1
    while high - low > 1:
        mid2 = (low + high) // 2
        if C[mid2] <= B[i]:
            low = mid2
        else:
            high = mid2
    mid2 = high
    total += mid1 * (N + 1 - mid2)

print(total)

Solution (Python):
import bisect
N=int(input())
A=sorted(list(map(int,input().split())))
B=sorted(list(map(int,input().split())))
C=sorted(list(map(int,input().split())))
print(sum(bisect.bisect_left(A,b)*(N-bisect.bisect_right(C,b)) for b in B))

Solution (Python):
import bisect

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

ans = 0

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

print(ans)

Solution (Python):
from bisect import bisect_left,bisect_right
n = int(input())
a = sorted(list(int(i) for i in input().split()))
b = sorted(list(int(i) for i in input().split()))
c = sorted(list(int(i) for i in input().split()))
ans = 0

for j in range(n):
  a1 = bisect_left(a,b[j])
  a2 = bisect_right(c,b[j])
  ans += a1 *(n-a2)
print(ans)

Solution (Python):
import bisect

n = int(input())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
c = list(map(int,input().split()))
a.sort()
c.sort()
ans = 0
for i in range(n):
    a_num = bisect.bisect_left(a,b[i])
    c_num = n - bisect.bisect_right(c,b[i])

    ans += c_num * a_num
print(ans)

Solution (Python):
import bisect

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

ans = 0

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

Solution (Python):
def isOK(X, index, aim, mode):
    if mode==1:
        if X[index] < aim:
            return True
        else:
            return False
    else:
        if X[index] > aim:
            return True
        else:
            return False

def bs(X, aim, mode):
    left=-1
    right=len(X)

    while right-left>1:
        mid = left + int((right-left)/2)
        if mode == 1:
            if isOK(X, mid, aim, mode):
                left=mid
            else:
                right=mid
        else:
            if isOK(X, mid, aim, mode):
                right=mid
            else:
                left=mid
    if mode==1:
        return left
    else:
        return 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 j in range(N):
    piva=bs(A, B[j], 1)
    pivc=bs(C, B[j], 2)
    ans+=(piva+1)*(len(C)-pivc)
print(str(ans))

Solution (Python):
import bisect as bis

def main() :
	N = int(input())
	a = [int(i) for i in input().split()]
	b = [int(i) for i in input().split()]
	c = [int(i) for i in input().split()]

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

	count = 0
	for i in b :
		n = bis.bisect_left(a,i)
		m = len(c) - bis.bisect_right(c,i)
		count += n*m

	print(count)

main()

Solution (Python):
import bisect
n = int(input())
a = sorted(list(map(int,input().split())))
b = sorted(list(map(int,input().split())))
c = sorted(list(map(int,input().split())))
counta = 0
countc = 0
count = 0
for i in range(n):
    countc = n  - bisect.bisect_right(c,b[i])
    counta = bisect.bisect_left(a,b[i])
    count += countc*counta
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 = sorted(a)
b = sorted(b)
c = sorted(c)

import bisect
count = 0
for i in b:
    a_count = bisect.bisect_left(a, i)
    c_count = n - bisect.bisect_right(c, i)
    count += a_count * c_count
    
print(count)

Solution (Python):
from bisect import bisect_left, bisect_right


def main():
    n = int(input())
    aa = sorted(map(int, input().split()))
    bb = sorted(map(int, input().split()))
    cc = sorted(map(int, input().split()))
    res = 0
    for b in bb:
        i_a = bisect_left(aa, b)
        i_c = bisect_right(cc, b)
        res += i_a * (n - i_c)
    print(res)


if __name__ == '__main__':
    main()

Solution (Python):
from bisect import bisect_left, bisect_right
N = int(input())
A = [int(a) for a in input().split()]
B = [int(b) for b in input().split()]
C = [int(c) for c in input().split()]
A.sort()
C.sort()
ans = 0
for b in B:
    ltB = bisect_left(A, b)
    gtB = N - bisect_right(C, b)
    ans += ltB*gtB
print(ans)

Solution (Python):
from bisect import bisect_left, bisect_right
N = int(input())
A = [int(a) for a in input().split()]
B = [int(b) for b in input().split()]
C = [int(c) for c in input().split()]
A.sort()
B.sort()
C.sort()
ans = 0
for b in B:
    ltB = bisect_left(A, b)
    gtC = N - bisect_right(C, b)
    ans += ltB*gtC
print(ans)

Solution (Python):

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

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

import bisect
A2 = []
B2 = []
C2 = []







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





print(sum)

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 B:
  sml_B = bisect_left(A,i)
  
  big_B = len(C)-bisect_right(C,i)
  
  ans+=sml_B*big_B
print(ans)

Solution (Python):
import bisect
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_list:
    s = bisect.bisect_left(a_list, b)
    t = len(c_list) - bisect.bisect_right(c_list, b) 
    ans += s*t
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 i in range(n):
  x=bisect.bisect_left(a,b[i])
  y=len(c)-bisect.bisect(c,b[i])
  ct+=x*y
print(ct)

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())))
m = len(c)
ans = 0
for x in b:
    
    p = bisect.bisect_left(a, x)
    q = m - bisect.bisect_right(c, x)
    ans += p*q
print(ans)

Solution (Python):
N=int(input())
D = []
D += [[i,0]  for i in list(map(int,input().split()))]
D += [[i,1]  for i in list(map(int,input().split()))]
D += [[i,2]  for i in list(map(int,input().split()))]
D = sorted(D,key=lambda x: x[0])

up_count=0
up_buf = 0
down_count=N
down_buf= 0
middle_buf = 0
ans = 0
prev_val = D[0][0]
for d in D:
    if d[0]==prev_val:
        if d[1]==0:
            up_buf+=1
        if d[1]==1:
            middle_buf += 1
        if d[1]==2:
            down_buf+=1
    else:
        ans += middle_buf*(down_count-down_buf)*up_count
        up_count+=up_buf
        up_buf=0
        down_count-=down_buf
        down_buf=0
        middle_buf=0
        prev_val = d[0]
        if d[1]==0:
            up_buf+=1
        if d[1]==1:
            middle_buf += 1
        if d[1]==2:
            down_buf+=1        
print(ans)

Solution (Python):
import bisect

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

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

print(ans)

Solution (Python):
import math
import sys
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 = sorted(A)
B = sorted(B)
C = sorted(C)

BAcnt = [0] * N


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

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

ret = 0
for i in range(N):
    j = bisect.bisect_left(B, C[i]) - 1
    if len(BAruiseki) > j and j>=0:
        ret += BAruiseki[j]


print(ret)

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

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

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

Solution (Python):
import bisect

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

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

Solution (Python):
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()])
"""
a = [_a[0]]
for i in range(1, n):
    if _a[i] != _a[i-1]:
        a.append(_a[i])
b = [_b[0]]
for i in range(1, n):
    if _b[i] != _b[i-1]:
        b.append(_b[i])
c = [_c[0]]
for i in range(1, n):
    if _c[i] != _c[i-1]:
        c.append(_c[i])
"""
aCount = [0 for i in range(len(a))]
bCount = [0 for i in range(len(b))]




k = len(c) - 1
for j in reversed(range(len(b))):
    if j < len(b) - 1:
        bCount[j] = bCount[j+1]
    while k >= 0 and b[j] < c[k]:
        bCount[j] = len(b) - k
        
        k -= 1

k = len(b) - 1
for j in reversed(range(len(a))):
    if j < len(a) - 1:
        aCount[j] = aCount[j+1]
    while k >= 0 and a[j] < b[k]:
        
        aCount[j] += bCount[k]
        
        k -= 1
print(sum(aCount))

Solution (Python):

import sys

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




capacity_B = [0] * N
idx_A = 0
idx_B = 0
for i in range(2 * N):
    if idx_B == N: break
    elif idx_A == N:
        for i in range(idx_B, N): capacity_B[i] = N
        break 
    elif A[idx_A] >= B[idx_B]:
        capacity_B[idx_B] = idx_A
        idx_B += 1
    else:
        idx_A += 1
        



capacity_C = [0] * N
idx_B = 0
idx_C = 0
for i in range(2 * N):
    if idx_C == N: break
    elif idx_B == N:
        for i in range(idx_C, N): capacity_C[i] = N
        break 
    elif B[idx_B] >= C[idx_C]:
        capacity_C[idx_C] = idx_B
        idx_C += 1
    else:
        idx_B += 1




ans = 0
idx_AB = 0
idx_BC = 0
sum_tmp = 0
for i in range(2 * N):
    if idx_BC == N: break
    elif idx_AB == N:
        for i in range(idx_BC, N): ans += sum_tmp
        break 
    elif idx_AB >= capacity_C[idx_BC]:
        ans += sum_tmp
        idx_BC += 1
    else:
        sum_tmp += capacity_B[idx_AB]
        idx_AB += 1



print(ans)

Solution (Python):
import bisect

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

ans = 0

for i in B:
    zyo = bisect.bisect_left(A, i)
    ge = bisect.bisect_right(C, i)
    ans += (N-ge)*zyo
    
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 = []
b = []
c = []
for i in range(n):
    a.append([])
    b.append([])
    c.append([])
for i in range(n):
    a[i].append(A[i])
    a[i].append(2)
    b[i].append(B[i])
    b[i].append(1)
    c[i].append(C[i])
    c[i].append(0)
d = a + b + c
d.sort(key=lambda x:(x[0], x[1]))
lenli = []
allli = []
count = 0
for i in range(len(d)):
    if d[i][1] == 2:
        if lenli == []:
            lenli.append(1)
        else:
            lenli[-1] += 1
    elif d[i][1] == 1:
        if allli == [] and lenli != []:
            allli.append(lenli[-1])
            allli.append(allli[-1])
            lenli.append(lenli[-1])
        elif allli == [] and lenli == []:
            pass
        else:
            allli[-1] += lenli[-1]
            allli.append(allli[-1])
            lenli.append(lenli[-1])
    elif d[i][1] == 0:
        if allli == []:
            count += 0
        else:
            count += allli[-2]

print(count)

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

ans=0
p=0
q=0

for i in b:
    while p<n and a[p]<i:
        p+=1
    while q<n and c[q]<=i:
        q+=1
    ans+=p*(n-q)

print(ans)

Solution (Python):
n=int(input())
s=[list(map(int,input().split()))for i in range(3)]
s[0].sort()
s[1].sort()
s[2].sort()
c,d,e=0,0,0
for i in range(n):
    while d<n and s[0][d]<s[1][i]:
        d+=1
    while e<n and s[2][e]<=s[1][i]:
        e+=1
    c+=d*(n-e)
print(c)

Solution (Python):
import sys
from operator import mul
def 解():
    input = sys.stdin.readline
    iN = int(input())
    aA = sorted([int(_) for _ in input().split()])
    aB = sorted([int(_) for _ in input().split()])
    aC = sorted([int(_) for _ in input().split()])

    aBA =[0]*iN
    aBC = [0]*iN

    iIndex = iN-1
    for i in range(iN-1,-1,-1):
        iB = aB[i]
        while aA[iIndex] >= iB:
            iIndex -= 1
            if iIndex < 0:
                break
        if iIndex >= 0 :
            aBA[i] = iIndex + 1
        else:
            break
    iBstart = 0
    if aC[0] > aB[0]:
        for iBstart in range(iN):
            if aB[iBstart] >= aC[0]:
                break
            else:
                aBC[iBstart] = iN
    iIndex = 0
    for i in range(iBstart,iN):
        iB = aB[i]
        while aC[iIndex] <= iB:
            iIndex += 1
            if iN <= iIndex :
                break
        if iIndex < iN  :
            aBC[i] = iN - iIndex
        else:
            break
    print(sum(map(mul,aBA,aBC)))
解()

Solution (Python):
import sys
def 解():
    input = sys.stdin.readline
    iN = int(input())
    aA = sorted([int(_) for _ in input().split()])
    aB = sorted([int(_) for _ in input().split()])
    aC = sorted([int(_) for _ in input().split()])

    aBA =[0]*iN
    iIndex = iN-1
    for i in range(iN-1,-1,-1):
        iB = aB[i]
        while aA[iIndex] >= iB:
            iIndex -= 1
            if iIndex < 0:
                break
        if iIndex >= 0 :
            aBA[i] = iIndex + 1
        else:
            break
    aAcBA=[0]*iN
    aAcBA[0]=aBA[0]
    for i in range(1,iN):
        aAcBA[i]=aAcBA[i-1]+aBA[i]
    iAns = 0
    iIndex = iN-1
    for i in range(iN-1,-1,-1):
        iC = aC[i]
        while aB[iIndex] >= iC:
            iIndex -= 1
            if iIndex < 0:
                break
        if iIndex >= 0 :
            iAns += aAcBA[iIndex]
        else:
            break
    print(iAns)
解()

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

cnt = 0

b_map = {}
c_index = 0
all = 0
for i in range(N):
    b = B[i]
    c = C[c_index]
    countable = True
    while(b >= c):
        if c_index == N-1:
            countable = False
            break
        c_index += 1
        c = C[c_index]
    if countable:
        b_map[i] = N-c_index
        all += b_map[i]
    else:
        b_map[i] = 0
m = {}
for i in range(N):
    if i > 0:
        m[i] = m[i-1] - b_map[i-1]
    else:
        m[i] = all

b_index = 0
for i in range(N):
    a = A[i]
    b = B[b_index]
    countable = True
    while(a >= b):
        if b_index == N-1:
            countable = False
            break
        b_index += 1
        b = B[b_index]
    if countable:
        cnt += m[b_index]

print(cnt)

Solution (Python):
n = int(input())
lis = list(map(int,input().split()))
li = list(map(int,input().split()))
l = list(map(int,input().split()))
cou = 0
co = 0
num = 0
nu = 0
ans = []
an = []
lis.sort(reverse = True)
li.sort(reverse = True)
for i in range(n):
  while True:
    if num == n:
      ans.append(0)
      break
    if lis[num] >= li[i]:
      num += 1
    else:
      ans.append(n-num)
      break
l.sort()
for i in range(n):
  while True:
    if nu == n:
      an.append(0)
      break
    if li[-1-i] >= l[nu]:
      nu += 1
    else:
      an.append(n-nu)
      break
for i in range(n):
  cou += ans[i]*an[-1-i]
print(cou)

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

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

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):
import sys
fin = sys.stdin.readline
from bisect import bisect, bisect_left
from collections import defaultdict


N = int(fin())
A_list = [int(elem) for elem in fin().split()]
B_list = sorted([int(elem) for elem in fin().split()])
C_list = sorted([int(elem) for elem in fin().split()])














cuml_combinations = [0] * N
current_combinations = 0
for i, B in enumerate(reversed(B_list)):
    idx = bisect(C_list, B)
    current_combinations += N - idx
    cuml_combinations[N - i - 1] = current_combinations

num_combinations = 0
for A in A_list:
    B_idx = bisect(B_list, A)
    try:
        num_combinations += cuml_combinations[B_idx]
    except IndexError:
        pass

print(num_combinations)

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

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

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=0
j=0
k=0
answer = 0
left = 0
right = N
for j in range(N):
    while i<N and a[i] < b[j]:
        left += 1
        i += 1
    while k<N and c[k] <= b[j]:
        right -= 1
        k += 1
    answer += left*right
print(answer)

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 bisect
import numpy as np

N = int(input())
_A = list(map(int, input().split()))
_B = list(map(int, input().split()))
_C = list(map(int, input().split()))


AI = sorted(_A)
BI = sorted(_B)
CI = sorted(_C)

BJ = []


for bi in BI:
    bj = bisect.bisect_left(AI,bi)
    BJ.append(bj)
    

BJ = np.cumsum(BJ)

ans = 0


for ci in CI:
    cj = bisect.bisect_left(BI, ci)
    if cj != 0:
        ans += BJ[cj-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.sort()
b.sort()
c.sort()

anum = [1 for i in range(n)]
bnum = [0 for i in range(n)]
cnum = [0 for i in range(n)]
i = 0
j = 0
count = 0
while j < n:
    while i < n :
        if a[i] >= b[j]:
            break
        count += anum[i]
        i += 1
    bnum[j] = count
    j += 1
i = 0
j = 0
count = 0
while j < n:
    while i < n  :
        if b[i] >= c[j]:
            break
        count += bnum[i]
        i += 1
    cnum[j] = count
    j += 1
print(sum(cnum))

Solution (Python):
from bisect import *

n = int(input())
a,b,c = [sorted(map(int,input().split())) for i in range(3)]

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

Solution (Python):
def BvsA(i):
    min, max = 0, N
    while max-min>1:
        mid = (min+max)//2
        if B[i] > A[mid]:
            min = mid
        else:
            max = mid
    return min+1

def BvsC(i):
    min, max = -1, N-1
    while max-min>1:
        mid = (min+max)//2
        if B[i] < C[mid]:
            max = mid
        else:
            min = mid
    return N-max


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):
    if A[0] < B[i] < C[N-1]:
        Ans += BvsA(i) * BvsC(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())))
p = [0]*n
q = [0]*n
k = 0
for i in range(n):
  while k<n:
    if a[k]<b[i]:
      k += 1
    else:
      break
  p[i] = k
k = 0
s = 0
ans = 0
for i in range(n):
  while k<n:
    if b[k]<c[i]:
      s += p[k]
      k += 1
    else:
      break
  ans += s
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())))

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

num_b = [0 for _ in range(n)]
j = 0
for i in range(n):
    if j == n:
        num_b[i] = n
        continue
    while a[j] < b[i]:
        j += 1
        if j == n:
            break
    num_b[i] = j

ans = 0
j = 0
temp_sum = 0
for i in range(n):
    while b[j] < c[i]:
        temp_sum += num_b[j]
        j += 1
        if j == n:
            ans += (n - i) * sum(num_b)
            break
    if j == n:
        break
    ans += temp_sum

print(ans)

Solution (Python):

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

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

N = int(input())
An = list(map(int, input().split()))
Bn = list(map(int, input().split()))
Cn = list(map(int, input().split()))

An.sort()
Bn.sort()
Cn.sort()






C_cnt = []
C_sum = 0
j = 0
for i in range(N):
    while j < N:
        if Bn[i] < Cn[j]:
            C_cnt.append(N - j)
            C_sum += N - j
            break
        else:
            j += 1


B_cnt = []
temp_sum = 0
for cnt in C_cnt:
    B_cnt.append(C_sum - temp_sum)
    temp_sum += cnt

A_cnt = 0
j = 0
for i in range(N):
    while j < N:
        if An[i] < Bn[j]:
            if j < len(B_cnt):
                A_cnt += B_cnt[j]
            break
        else:
            j += 1



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

print(ans)

Solution (Python):

"""
Created on Sat Oct 20 10:21:00 2018
ABC077C
@author: maezawa
"""
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()

bcnt = [0]*n
for i, bi in enumerate(b):
    j = bisect.bisect_left(a, bi)
    if i == 0:
        bcnt[i] = j
    else:
        bcnt[i] = bcnt[i-1] + j
cnt = 0
for i, ci in enumerate(c):
    j = bisect.bisect_left(b, ci)
    if j == 0:
        continue
    else:
        cnt += bcnt[j-1]
    
    
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,B,C = sorted(A),sorted(B),sorted(C)

a_max = 0
c_min = 0
ans = 0

for j in range(N):
    b = B[j]

    a_max = bisect.bisect_left(A,b,a_max,N)
    c_min = bisect.bisect_right(C,b,c_min,N)
    ans += (a_max) * (N-c_min)

print(ans)

Solution (Python):



def main():
    from bisect import bisect_left
    from bisect import 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 bi in b:
        less = bisect_left(a, bi)
        greater = n - bisect_right(c, bi)
        ans += less * greater

    print(ans)


if __name__ == '__main__':
    main()

Solution (Python):



def main():
    from bisect import bisect_left
    from bisect import 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 bi in b:
        less = bisect_left(a, bi)
        greater = n - bisect_right(c, bi)
        ans += less * greater

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

print(ans)