Buggy python submission (verdict: Time Limit Exceeded):
from collections import Counter
N =int(input())
A = Counter(list(map(int,input().split())))
B = Counter(list(map(int,input().split())))
C = Counter(list(map(int,input().split())))
A_sort = sorted(A.items())
B_sort = sorted(B.items())
C_sort = sorted(C.items())

BtoC = []
ans = 0
start_j = 0
start_k = 0
sum_val = N
for j in range(len(B_sort)):
    for k in range(start_k , len(C_sort)):
        if B_sort[j][0] >= C_sort[k][0]:
            sum_val -= C_sort[k][1]
            start_k = k + 1
        else:
            BtoC.append([B_sort[j][0] , sum_val * B_sort[j][1]])
            break

for i in range(len(A_sort)):
    for j in range(start_j , len(BtoC)):
        if A_sort[i][0] >= BtoC[j][0]:
            start_j = j + 1
            continue
        else:
            ans += A_sort[i][1] * BtoC[j][1]
print(ans)

Fixed submission:
from collections import Counter
N =int(input())
A = Counter(list(map(int,input().split())))
B = Counter(list(map(int,input().split())))
C = Counter(list(map(int,input().split())))
A_sort = sorted(A.items())
B_sort = sorted(B.items())
C_sort = sorted(C.items())

BtoC = []
ans = 0
start_j = 0
start_k = 0
sum_val = N
for j in range(len(B_sort)):
    for k in range(start_k , len(C_sort)):
        if B_sort[j][0] >= C_sort[k][0]:
            sum_val -= C_sort[k][1]
            start_k = k + 1
        else:
            BtoC.append([B_sort[j][0] , sum_val * B_sort[j][1]])
            break
#print(BtoC)
work = 0
for i in range(len(BtoC) - 2 , -1 , -1):
    BtoC[i][1] = BtoC[i+1][1] + BtoC[i][1]
    work = BtoC[i+1][1]
#print(BtoC)
for i in range(len(A_sort)):
    for j in range(start_j , len(BtoC)):
        if A_sort[i][0] >= BtoC[j][0]:
            start_j = j + 1
        else:
            ans += A_sort[i][1] * BtoC[j][1]
            break
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
from collections import Counter
N =int(input())
A = Counter(list(map(int,input().split())))
B = Counter(list(map(int,input().split())))
C = Counter(list(map(int,input().split())))
A_sort = sorted(A.items())
B_sort = sorted(B.items())
C_sort = sorted(C.items())

ans = 0
for i in range(len(A_sort)):
    sum_val = N
    now_k = 0
    now_j = 0
    for j in range(now_j , len(B_sort)):
        if A_sort[i][0] >= B_sort[j][0]:
            continue
        for k in range(now_k , len(C_sort)):
            if A_sort[i][0] < B_sort[j][0] < C_sort[k][0]:
                ans += (sum_val * B_sort[j][1] * A_sort[i][1])
                now_k = k
                now_j = j
                break
            else:
                sum_val -= C_sort[k][1]
print(ans)

Fixed submission:
from collections import Counter
N =int(input())
A = Counter(list(map(int,input().split())))
B = Counter(list(map(int,input().split())))
C = Counter(list(map(int,input().split())))
A_sort = sorted(A.items())
B_sort = sorted(B.items())
C_sort = sorted(C.items())

BtoC = []
ans = 0
start_j = 0
start_k = 0
sum_val = N
for j in range(len(B_sort)):
    for k in range(start_k , len(C_sort)):
        if B_sort[j][0] >= C_sort[k][0]:
            sum_val -= C_sort[k][1]
            start_k = k + 1
        else:
            BtoC.append([B_sort[j][0] , sum_val * B_sort[j][1]])
            break
#print(BtoC)
work = 0
for i in range(len(BtoC) - 2 , -1 , -1):
    BtoC[i][1] = BtoC[i+1][1] + BtoC[i][1]
    work = BtoC[i+1][1]
#print(BtoC)
for i in range(len(A_sort)):
    for j in range(start_j , len(BtoC)):
        if A_sort[i][0] >= BtoC[j][0]:
            start_j = j + 1
        else:
            ans += A_sort[i][1] * BtoC[j][1]
            break
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
from collections import Counter
N =int(input())
A = Counter(list(map(int,input().split())))
B = Counter(list(map(int,input().split())))
C = Counter(list(map(int,input().split())))
A_sort = sorted(A.items())
B_sort = sorted(B.items())
C_sort = sorted(C.items())

ans = 0
for i in range(len(A_sort)):
    sum_val = N
    now_k = 0
    now_j = 0
    for j in range(now_j , len(B_sort)):
        if A_sort[i][0] >= B_sort[j][0]:
            continue
        for k in range(now_k , len(C_sort)):
            if A_sort[i][0] < B_sort[j][0] < C_sort[k][0]:
                ans += (sum_val * B_sort[j][1] * A_sort[i][1])
                now_k = k
                now_j = j
                break
            else:
                sum_val -= C_sort[k][1]
print(ans)

Fixed submission:
from collections import Counter
N =int(input())
A = Counter(list(map(int,input().split())))
B = Counter(list(map(int,input().split())))
C = Counter(list(map(int,input().split())))
A_sort = sorted(A.items())
B_sort = sorted(B.items())
C_sort = sorted(C.items())

BtoC = []
ans = 0
start_j = 0
start_k = 0
sum_val = N
for j in range(len(B_sort)):
    for k in range(start_k , len(C_sort)):
        if B_sort[j][0] >= C_sort[k][0]:
            sum_val -= C_sort[k][1]
            start_k = k + 1
        else:
            BtoC.append([B_sort[j][0] , sum_val * B_sort[j][1]])
            break
#print(BtoC)
work = 0
for i in range(len(BtoC) - 2 , -1 , -1):
    BtoC[i][1] = BtoC[i+1][1] + BtoC[i][1]
    work = BtoC[i+1][1]
#print(BtoC)
for i in range(len(A_sort)):
    for j in range(start_j , len(BtoC)):
        if A_sort[i][0] >= BtoC[j][0]:
            start_j = j + 1
        else:
            ans += A_sort[i][1] * BtoC[j][1]
            break
print(ans)