Buggy python submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-
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()

# print(An)
# print(Bn)
# print(Cn)

# B
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]:
            A_cnt += B_cnt[j]
            break
        else:
            j += 1

# print(C_cnt)
# print(B_cnt)
print(A_cnt)


Fixed submission:
# -*- coding: utf-8 -*-
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()

# print(An)
# print(Bn)
# print(Cn)

# B
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(C_cnt)
# print(B_cnt)
print(A_cnt)

Buggy python submission (verdict: Time Limit Exceeded):
# -*- coding: utf-8 -*-
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()
#
# print(An)
# print(Bn)
# print(Cn)
#B
B_cnt = []
j = 0
for i in range(N):
    while j < N:
        if Bn[i] < Cn[j]:
            B_cnt.append(N - j)
            break
        else:
            j += 1
# print(B_cnt)

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

print(A_cnt)



Fixed submission:
# -*- coding: utf-8 -*-
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()

# print(An)
# print(Bn)
# print(Cn)

# B
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(C_cnt)
# print(B_cnt)
print(A_cnt)