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

Solution (Python):
import bisect
N = int(input())
Alist = list(map(int,input().split()))
Blist = list(map(int,input().split()))
Clist = list(map(int,input().split()))
Alist.sort()
Clist.sort()
retnum = 0 
for i in Blist:
    Anum = bisect.bisect_left(Alist,i)
    Cnum =  N - bisect.bisect_right(Clist,i)
    retnum +=(Anum * Cnum)
print(retnum)

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

res = 0
for j in range(N):
	indA = bisect.bisect_left(A,B[j])
	ansA = indA
	indC = bisect.bisect_right(C,B[j])
	ansC = N - indC
	res += ansA * ansC

print(res)

Solution (Python):
import bisect

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

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

ans = 0

for e in b:
    i = bisect.bisect_left(a, e)
    j = bisect.bisect_right(c, e)
    if i > 0 and j != len(c):
            ans += i * (N - j)
            
print(ans)

Solution (Python):


import bisect

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

count = 0

for mid in B:
    lower_bound = bisect.bisect_left(A, mid)
    upper_bound = N - bisect.bisect_right(C, mid)
    count += lower_bound * upper_bound

print count

Solution (Python):
import bisect

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

A = list(A)
A.sort()
B = list(B)
B.sort()
C = list(C)
C.sort()

count = 0

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

print(count)

Solution (Python):
import bisect

num = int(input())
top = sorted([int(x) for x in input().split()])
middle = sorted([int(x) for x in input().split()])
bottom = sorted([int(x) for x in input().split()])



res = 0
for i in middle:
    index = bisect.bisect_left(top, i)
    index2 = len(bottom)-bisect.bisect_right(bottom, i)
    res += index*index2

print(res)

Solution (Python):
import bisect

n = int(input())
a = sorted(list(map(lambda x: int(x),input().split())))
b = sorted(list(map(lambda x: int(x),input().split())))
c = sorted(list(map(lambda x: int(x),input().split())))

count = 0
for mid in b:
    upper_count = bisect.bisect_left(a,mid)
    lower_count = len(c) - bisect.bisect_right(c,mid)
    count += upper_count * lower_count
print(count)

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

print(ans)

Solution (Python):
N = int(raw_input())
count = [0, 0, 0, 1]
for i in sorted([(int(i), 2) for i in raw_input().split(" ")] + [(int(i), 1) for i in raw_input().split(" ")] + [(int(i), 0) for i in raw_input().split(" ")]):
    count[i[1]] += count[i[1] + 1]
print count[0]

Solution (Python):

N = int(raw_input())
As = [(int(i), 2) for i in raw_input().split(" ")]
Bs = [(int(i), 1) for i in raw_input().split(" ")]
Cs = [(int(i), 0) for i in raw_input().split(" ")]

l = sorted(As + Bs + Cs)


count = [0, 0, 0, 1]
for i in l:
    count[i[1]] += count[i[1] + 1]
print count[0]

Solution (Python):


N = int(raw_input())
As = [(int(i), 2) for i in raw_input().split(" ")]
Bs = [(int(i), 1) for i in raw_input().split(" ")]
Cs = [(int(i), 0) for i in raw_input().split(" ")]

l = sorted(As + Bs + Cs)

ac = 0
bc = 0
cc = 0

for i in l:
    if i[1] == 2:
        ac += 1
    elif i[1] == 1:
        bc += ac
    elif i[1] == 0:
        cc += bc
print cc

Solution (Python):


N = int(raw_input())
As = [(int(i), 2) for i in raw_input().split(" ")]
Bs = [(int(i), 1) for i in raw_input().split(" ")]
Cs = [(int(i), 0) for i in raw_input().split(" ")]

l = sorted(As + Bs + Cs, key=lambda x: x[0] + x[1] * 0.1)

ac = 0
bc = 0
cc = 0

for i in l:
    if i[1] == 2:
        ac += 1
    elif i[1] == 1:
        bc += ac
    elif i[1] == 0:
        cc += bc
print cc

Solution (Python):


N = int(raw_input())
As = raw_input().split(" ")
Bs = raw_input().split(" ")
Cs = raw_input().split(" ")

As = [(int(i), 2) for i in As]
Bs = [(int(i), 1) for i in Bs]
Cs = [(int(i), 0) for i in Cs]

l = sorted(As + Bs + Cs, key=lambda x: x[0] + x[1] * 0.1)

ac = 0
bc = 0
cc = 0

for i in l:
    if i[1] == 2:
        ac += 1
    elif i[1] == 1:
        bc += ac
    elif i[1] == 0:
        cc += bc
print cc

Solution (Python):
import bisect

n = int(input())
count = 0
a = [[0 for i in range(n)] for i in range(3)]

for i in range(3):
    a[i] = [int(x) for x in input().split()]
    a[i].sort()


for i in a[1]:
    index0_left = bisect.bisect_left(a[0], i)

    index2_right = bisect.bisect_right(a[2], i)

    count += (index0_left -1 + 1)*(n - index2_right)

print(count)

Solution (Python):
N = int(input())
size = [list(sorted(map(int, input().split()))) for i in range(3)]
dp = [[1] * (N + 1), [0] * (N + 1), [0] * (N + 1)]
dp[0][0] = 0
for i in range(1, 3):
	pos = 1
	for j in range(1, N + 1):
		dp[i][j] += dp[i][j - 1]
		for k in range(pos, N + 1):
			if size[i][j - 1] <= size[i - 1][k - 1]:
				break
			dp[i][j] += dp[i - 1][k]
			pos += 1
print(sum(dp[2]))

Solution (Python):
import bisect


N = int(input())
ue = (list(map(int, input().split())))
mid = (list(map(int, input().split())))
bot = (list(map(int, input().split())))
ue.sort()
mid.sort()
bot.sort()

ans = 0
for i in mid:
    ans += bisect.bisect_left(ue, i) * (len(bot) - bisect.bisect_right(bot, 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
ans = 0
while j < N:
  while i < N and a[i]<b[j] :
    i += 1
  while k < N and c[k]<=b[j]:
    k += 1
  ans += i * (N - k)
  j += 1

print(ans)

Solution (Python):
import bisect

n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))
a.sort()
b.sort()
c.sort()
A = 0
for x in b:
  i = bisect.bisect_left(a, x)
  j = bisect.bisect_right(c, x)
  if i > 0 and j != len(c):
    A += i * (n - j)
print(A)

Solution (Python):


import bisect

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

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

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

if __name__ == '__main__':
    main()

Solution (Python):
N = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))
a.sort()
b.sort()
c.sort()
m = [0] * N
p = N - 1
q = N - 1
while p >= 0:
    while q >= 0 and b[p] < c[q]:
        m[p] += 1
        q -= 1
    p -= 1
for i in range(N-2, -1, -1):
    m[i] = m[i] + m[i + 1]

p = N - 1
q = N - 1
h = [0] * N
while p >= 0:
    while q >= 0 and a[p] < b[q]:
        h[p] += m[q]
        q -= 1
    p -= 1
for i in range(N-2, -1, -1):
    h[i] = h[i] + h[i + 1]
print(sum(h))

Solution (Python):
n = int(input())
*A, = map(int, input().split())
*B, = map(int, input().split())
*C, = map(int, input().split())
A.sort(); B.sort(); C.sort()
INF = 10**10
A += INF,; B += INF,; C += INF,
a = b = c = i = j = k = 0
while min(i, j, k) < n:
    v = min(A[i], B[j], C[k])
    if v == C[k]:
        c += b
        k += 1
    elif v == B[j]:
        b += a
        j += 1
    else:
        a += 1
        i += 1
print(c)

Solution (Python):


n=int(raw_input())
a=sorted(map(int,raw_input().split()))
b=sorted(map(int,raw_input().split()))
c=sorted(map(int,raw_input().split()))
x=0
z=0
res=0
for y in b:
 while x<n and a[x]<y:
  x+=1
 while z<n and c[z]<=y:
  z+=1
 res+=x*(n-z)
print res

Solution (Python):
import bisect

n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))
a.sort()
b.sort()
c.sort()
ans = 0
for y in b:
  i = bisect.bisect_left(a, y)
  j = bisect.bisect_right(c, y)
  if i > 0 and j != len(c):
    ans += i * (n - j)
print(ans)

Solution (Python):
N = int(input())
A_list = [int(a) for a in input().split()]
B_list = [int(b) for b in input().split()]
C_list = [int(c) for c in input().split()]
A_list.sort()
B_list.sort()
C_list.sort()

i = j = N-1
count_B_gt_A = [0] * N
while i >= 0 and j >= 0:
    if B_list[i] > A_list[j]:
        count_B_gt_A[i] = j+1
        i -= 1
    else:
        j -= 1

i = j = 0
count_B_lt_C = [0] * N
while i < N and j < N:
    if B_list[i] < C_list[j]:
        count_B_lt_C[i] = N - j
        i += 1
    else:
        j += 1
    
result = sum([B_gt_A * B_lt_C for B_gt_A, B_lt_C in zip(count_B_gt_A, count_B_lt_C)])
print(result)

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()
    B.sort()
    C.sort()
    
    A_cand = [0 for i in range(N)]
    B_cand = [0 for i in range(N)]
    
    skip_loop = 0
    for i in range(N):
        cnt = skip_loop
        for j in range(N-skip_loop):
            if B[N-i-1] < C[N-skip_loop-j-1]:
                cnt += 1
            else:
                break
        B_cand[N-i-1] = cnt
        skip_loop = cnt
    
    skip_loop = 0
    ans = 0
    pre_loop_ans = 0
    for i in range(N):
        cnt = skip_loop
        ans += pre_loop_ans
        for j in range(N-skip_loop):
            if A[N-i-1] < B[N-skip_loop-j-1]:
                ans += B_cand[N-skip_loop-j-1]
                pre_loop_ans += B_cand[N-skip_loop-j-1]
                cnt += 1
            else:
                break
        A_cand[N-i-1] = cnt
        skip_loop = cnt
    print(ans)
    
 
solve()

Solution (Python):
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.sort()
B.sort()
C.sort()
sum = 0
for j in range(N):
    low = low2 = 0
    high = high2 = N
    b = B[j]
    mid = mid2 = 0
    
    while(high>low):
        mid = (high + low)//2
        if b > A[mid]:
            low = mid +1
        else:
            high = mid
    acount = low
    while (high2>low2):
        mid2 = (high2 + low2)//2
        if b < C[mid2]:
            high2 = mid2
        else:
            low2 = mid2 + 1
    ccount=N-low2
    sum += acount*ccount
print(sum)

Solution (Python):
import bisect

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

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

Solution (Python):
from bisect import bisect_left as bl, bisect_right as br
n = input()
a = sorted([int(x) for x in raw_input().split()])
b = sorted([int(x) for x in raw_input().split()])
c = sorted([int(x) for x in raw_input().split()])
ans = 0
for bi in b:
	ans += (bl(a, bi) * (n - br(c, bi)))
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, b, c = [sorted(x) for x in [a, b, c]]

ans = 0

for x in b:
    aa = bisect.bisect_left(a,x)
    bb = bisect.bisect_right(c,x)
    ans += aa * (len(b) - bb)

print(ans)

Solution (Python):
import bisect

def find_lt(a, x):
    i = bisect.bisect_left(a, x)
    if i:
        return i
    return 0

def find_l(a, x):
    i = bisect.bisect_right(a, x)
    if i == 0:
        return len(a)
    else:
        return len(a) - i

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

    partA = list(map(int, input().split()))
    partA.sort()
    partB = list(map(int, input().split()))
    partB.sort()
    partC = list(map(int, input().split()))
    partC.sort()
    cnt = 0


    for b in partB:
        A = find_lt(partA, b)
        
        B = find_l(partC, b)
        
        cnt += (A * B)

    print(cnt)

if __name__ == '__main__':
    main()

Solution (Python):
import sys,collections
sys.setrecursionlimit(10**7)
def Is(): return [int(x) for x in sys.stdin.readline().split()]
def Ss(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def S(): return input()

N = I()
A,B,C = sorted(Is()),sorted(Is()),sorted(Is())

Bs = [0]*N
b,j = 0,0
for i in range(N):
    while j < N:
        if B[i] >= C[j]:
            b += 1
        else:
            Bs[i] = N - b
            break
        if j == N-1:
            Bs[i] = N - b
        j += 1

all = sum(Bs)
ans,sum,j = 0,0,0
for i in range(N):
    while j < N:
        if A[i] >= B[j]:
            sum += Bs[j]
        else:
            ans += all - sum
            break
        if j == N-1:
            ans += all - sum
        j += 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()

p1,p2 = 0,0

bnum = [0 for i in range(n)]
cnum = [0 for i in range(n)]
d = [0 for i in range(n)]

for i in range(n):
    while(b[i]>a[min(p1,n-1)] and p1<n):
        p1 += 1
    bnum[i] = p1
for i in range(n):
    while(c[i]>b[min(p2,n-1)] and p2<n):
        p2 += 1
    cnum[i] = p2

d[0] = sum(bnum[0:max(0,cnum[0])])
for i in range(n-1):
    d[i+1] = d[i]+sum(bnum[cnum[i]:cnum[i+1]])
print(sum(d))

Solution (Python):




n = int(input())
A, B, C = [list(sorted(map(int, input().split())))  for _ in range(3)]

cnt = 0

def bs_left(lis, target):
    
    
    
    low, high = 0, len(lis)
    while low<high:
        mid = (low+high)//2
        if lis[mid]<target:
            low = mid+1
        else:
            high = mid
    return low

def bs_right(lis, target):
    low, high = 0, len(lis)
    while low<high:
        mid = (low+high)//2
        if target<lis[mid]:
            high = mid
        else:
            low = mid+1
    return low

for b in B:
    
    cnt += (bs_left(A, b) * (n-bs_right(C, b)))
print(cnt)

Solution (Python):
from collections import defaultdict, Counter
from itertools import product, groupby, count, permutations, combinations
from math import pi, sqrt
from collections import deque
from bisect import bisect, bisect_left, bisect_right
INF = float("inf")
 
 
def find_lt(a, x):
    i = bisect_left(a, x)
    if i:
        return i
    return 0
 
 
def find_gt(a, x):
    i = bisect_right(a, x)
    if i != len(a):
        return i
    return len(a)
 
 
def main():
    N = int(input())
    A = list(sorted(list(map(int, input().split()))))
    B = list(sorted(list(map(int, input().split()))))
    C = list(sorted(list(map(int, input().split()))))
 
    ans = 0
    for b in B:
        a = find_lt(A, b)
        b = N - find_gt(C, b)
        ans += a * b
    print(ans)
 
 
if __name__ == '__main__':
    main()

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())))
bmul = [0]*(n+1)
ci = 0
for bi in range(n):
    while ci != n and c[ci] <= b[bi]:
        ci += 1
    bmul[bi] = n-ci
for i in range(n):
    bmul[n-i-1] += bmul[n-i]
bi = 0
ai = 0
ret = 0
for ai in range(n):
    while bi != n and b[bi] <= a[ai]:
        bi += 1
    ret += bmul[bi]
print(ret)

Solution (Python):
n = int(raw_input())
al = map(int, raw_input().split())
bl = map(int, raw_input().split())
cl = map(int, raw_input().split())
al.sort()
bl.sort()
cl.sort()
ap = 0
cp = 0
t = 0
for b in bl:
    while ap < n and al[ap] < b:
        ap += 1
    while cp < n and cl[cp] <= b:
        cp += 1
    t += ap * (n - cp)
print t

Solution (Python):
n = int(raw_input())
al = map(int, raw_input().split())
bl = map(int, raw_input().split())
cl = map(int, raw_input().split())
al.sort()
bl.sort()
cl.sort()
l = [(0,0) for _ in range(n)]
p = 0
for i, b in enumerate(bl):
    while p < n and cl[p] <= b:
        p += 1
    l[i] = (b, n-p)
p = n-1
s = 0
t = 0
for a in al[::-1]:
    while p >= 0 and l[p][0] > a:
        s += l[p][1]
        p -= 1
    t += s
print t

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

counter = 0

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

print(counter)

Solution (Python):
from bisect import bisect_left, bisect_right
br, bl = bisect_right, bisect_left
n = input()
a = sorted([int(x) for x in raw_input().split()])
b = sorted([int(x) for x in raw_input().split()])
c = sorted([int(x) for x in raw_input().split()])
ans = 0
for bi in b:
	ans += (bl(a, bi) * (n - br(c, bi)))
print ans

Solution (Python):

import operator

def snuke_fest(top_arr, middle_arr, bottom_arr):
    sorted_arrs = list(sorted(arr) for arr in (top_arr, middle_arr, bottom_arr))
    del top_arr
    del middle_arr
    del bottom_arr
    pointers = [0] * 3
    ended = [False] * 3
    min_posi = [None] * len(sorted_arrs[0]) * 3
    min_posi_pointer = 0
    try:
        while not all(ended):
            nums = [0] * 3
            mins = [10**9] * 3
            for i in range(3):
                if not ended[i]:
                    mins[-(i+1)] = sorted_arrs[i][pointers[i]]
            min_index, min_val = min(enumerate(mins), key = operator.itemgetter(1))
            min_index = 2 - min_index
            pointers[min_index] += 1
            min_posi[min_posi_pointer] = min_index
            min_posi_pointer += 1
            if pointers[min_index] == len(sorted_arrs[0]):
                ended[min_index] = True
    except Exception as e:
        return 0
    del sorted_arrs
    del pointers
    count = 0
    count_arr = [0, 0, 0]
    count_one_two = 0
    for i in range(len(min_posi)):
        count_arr[min_posi[-(i+1)]] += 1

        if min_posi[-(i+1)] == 1:
            count_one_two += count_arr[2]
        elif min_posi[-(i+1)] == 0:
            count += count_one_two
    return count


if __name__ == "__main__":
    
    _ = input()
    top_arr = [int(i) for i in input().split(" ")]
    middle_arr = [int(i) for i in input().split(" ")]
    bottom_arr = [int(i) for i in input().split(" ")]
    print(snuke_fest(top_arr, middle_arr, bottom_arr))

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
small=0
large=0
for i in range(N):
  for k in range(small,N):
    if A[k]>=B[i]:
      small=k
      break
  else: small=N
  for k in range(large,N):
    if C[k]>B[i]:
      large=k
      break
  else: large=N
  ans+=small*(N-large)
print(ans)

Solution (Python):
import bisect
N=input()

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

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

Solution (Python):
import bisect

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

counts = 0
checked = {}
for _numB in B:
    if _numB not in checked:
        countsA = bisect.bisect_left(A, _numB)
        countsC = bisect.bisect_right(C, _numB)
        checked[_numB] = countsA * (N - countsC)
    counts += checked[_numB]
print(counts)

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

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

ans = 0
for b in Bs:
    a = bisect.bisect_left(As, b)
    c = bisect.bisect_right(Cs, b)
    ans += a * (N-c)
print(ans)

Solution (Python):
import bisect


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

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

    print(ans)


def TLE(N, A, B, C):
    
    
    
    
    

    ans = 0
    for b in B:
        less_b_count = sum(1 for a in A if a < b)
        if less_b_count > 0:
            over_b_count = sum(1 for c in C if b < c)
            ans += less_b_count * over_b_count

    print(ans)

if __name__ == '__main__':
    main()

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

Solution (Python):
import bisect

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

    a = sorted(A)
    c = sorted(C)
    cnt = 0
    for i in B:
        x = bisect.bisect_left(a, i)
        y = bisect.bisect_right(c, i)
        cnt += x * (N - y)

    print(cnt)

main()

Solution (Python):
from bisect import bisect_left, bisect_right
br, bl = bisect_right, bisect_left
n = input()
a = sorted([int(x) for x in raw_input().split()])
b = sorted([int(x) for x in raw_input().split()])
c = sorted([int(x) for x in raw_input().split()])
ans = 0
for bi in b:
	ans += (bl(a, bi) * (n - br(c, bi)))
print ans

Solution (Python):
from collections import defaultdict, Counter
from itertools import product, groupby, count, permutations, combinations
from math import pi, sqrt
from collections import deque
from bisect import bisect, bisect_left, bisect_right
INF = float("inf")


def find_lt(a, x):
    i = bisect_left(a, x)
    if i:
        return i
    return 0


def find_gt(a, x):
    i = bisect_right(a, x)
    if i != len(a):
        return i
    return len(a)


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

    ans = 0
    for b in B:
        a = find_lt(A, b)
        b = N - find_gt(C, b)
        ans += a * b
    print(ans)


if __name__ == '__main__':
    main()

Solution (Python):


import sys
import os
import math
import itertools
import heapq
import numpy as np
from collections import OrderedDict, deque, Counter
from bisect import bisect_left, bisect_right, insort_left, insort_right
sys.setrecursionlimit(10000)

dx = [1, 0, -1, 0]
dy = [0, 1, 0, -1]


def solve():
    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 ele in B:
        cnt += bisect_left(A, ele) * (N - bisect_right(C, ele))

    print(cnt)


solve()

Solution (Python):
import bisect
from sys import stdin

def IL(): return list(map(int, stdin.readline().split()))
def SIL(): return sorted(list(map(int, stdin.readline().split())))

def main():
	n = int(input())
	A = SIL()
	B = IL()
	C = SIL()
	
	ans = 0
	for b in B:
	    smaller = bisect.bisect_left(A, b)
	    bigger = bisect.bisect_right(C, b)
	    ans += smaller*(n - bigger)

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

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

a_b = 0
b_c = 0
count = 0
for b_item in b:
    while a_b < N and a[a_b] < b_item:
        a_b += 1
    while b_c < N and c[b_c] <= b_item:
        b_c += 1
    count += (a_b * (N - b_c))

print(count)

Solution (Python):
from bisect import bisect_left, bisect_right 
N = int(input())
a = sorted(list(map(int, input().split()))) 
b = list(map(int, input().split()))
c = sorted(list(map(int, input().split()))) 

count = 0
for b_item in b:
    i = bisect_left(a, b_item) 
    j = N - bisect_right(c, b_item) 
    count += (i * j)
print(count)

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

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

ans = 0
ai = 0
ci = 0

for b in B:
    while ai < n and A[ai] < b:
        ai += 1
    while ci < n and C[ci] <= b:
        ci += 1
    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()))

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 math
import bisect

def calc():
    n = int(input())
    tops = list(map(int, input().split()))
    middles = list(map(int, input().split()))
    lowers = list(map(int, input().split()))
 
    tops = sorted(tops)
    lowers = sorted(lowers)
 
    counter = 0
 
    for i in range(n):
        
        top_num = bisect.bisect_left(tops, middles[i])
        
        
        lower_num = n - bisect.bisect_right(lowers, middles[i])
        
        counter += top_num * lower_num
    
    return counter
 
print(calc())

Solution (Python):
import bisect

def fun():
    a = sorted(list(map(int,input().split())))
    b = sorted(list(map(int,input().split())))
    c = sorted(list(map(int,input().split())))
    ans = 0
    for k in b:
        pos1 = bisect.bisect_left(a,k)
        pos2 = bisect.bisect_right(c,k)
        ans += (pos1*(n-pos2))
    print(ans)
if __name__ == "__main__":
    n = int(input())
    fun()

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 k in b:
    pos1 = bisect.bisect_left(a,k)
    pos2 = bisect.bisect_right(c,k)
    ans += (pos1*(n-pos2))
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 k in b:
    pos1 = bisect.bisect_left(a,k)
    pos2 = bisect.bisect_right(c,k)
    ans += (pos1*(n-pos2))
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()
C.reverse()
 
ans = 0
ai = 0
ci = N-1
for b in B:
    while ai < N and A[ai] < b:
        ai += 1
    while ci >= 0 and C[ci] <= b:
        ci -= 1
    ans += ai * (ci+1)
 
print(ans)

Solution (Python):



"""077-c"""

import sys
import pprint
import re
import itertools

import bisect

pp = pprint.PrettyPrinter(indent=2)

def main():
    """Main function."""
    N = int(input())

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

    count = 0
    for b in Bs:
        i = bisect.bisect_left(As, b)
        k = N - bisect.bisect_right(Cs, b)
        count += i * k

    print(count)

if __name__ == '__main__':
    sys.exit(main())

Solution (Python):
N = int(input())
A = sorted(map(int, input().split()))
B = map(int, input().split())
C = sorted(map(int, input().split()))
import bisect
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):

"""
https://beta.atcoder.jp/contests/abc077/tasks/arc084_a

"""
import sys
from sys import stdin
from bisect import bisect_left, bisect_right
input = stdin.readline


def main(args):
    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()








    lut_A = {b:bisect_left(A, b) for b in B}
    lut_C = {b:(N - bisect_right(C, b)) for b in B}

    ans = 0
    for b in B:
        i = lut_A[b]
        j = lut_C[b]
        ans += i * j

    print(ans)


if __name__ == '__main__':
    main(sys.argv[1:])

Solution (Python):
import sys
import numpy as np

def binary_search(array, num):
    
    if array[-1] <= num:
        return -1
    left = -1
    right = N-1
    while right - left > 1:
        mid = int((left + right)/2)
        if array[mid] <= num:
            left = mid
        else:
            right = mid
    return right

a_index = []
b_index = []

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

for a in A:
    a_index.append(binary_search(B, a))
    
for b in B:
    b_index.append(binary_search(C, b))


b_index = list(map(lambda x: N-x if (x != -1) else 0, b_index))

bb = []
tmp = np.sum(b_index)
for i in range(N):
    bb.append(tmp)
    tmp = tmp - b_index[i]

res = 0
for a_i in a_index:
    if a_i == -1:
        continue
    res += bb[a_i]
print(str(res))

Solution (Python):

"""
https://beta.atcoder.jp/contests/abc077/tasks/arc084_a

"""
import sys
from sys import stdin
from bisect import bisect_left, bisect_right
input = stdin.readline


def main(args):
    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()

    lut_A = {}
    lut_C = {}
    for b in B:
        i = bisect_left(A, b)
        lut_A[b] = i
        j = bisect_right(C, b)
        lut_C[b] = N - j


    ans = 0
    for b in B:
        i = lut_A[b]
        j = lut_C[b]
        ans += i * j

    print(ans)


if __name__ == '__main__':
    main(sys.argv[1:])