Buggy python submission (verdict: Time Limit Exceeded):
#%%

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

#%%

def isok(index, key, arr):
    if arr == A and arr[index] >= key:
        return True
    elif arr == C and arr[index] > key:
        return True
    else:
        return False
 
def Binary_search(key, arr):
    
    ng = -1
    ok = len(arr)
    while ok - ng > 1:
        mid = (ok + ng) // 2
        if isok(mid, key, arr) is True:
            ok = mid
        else:
            ng = mid
    
    return ng, ok

cnt = 0
for i in B:
    ng_a, ok_b = Binary_search(i, A)
    ng_c, ok_c = Binary_search(i, C)
    cnt += (ng_a + 1) * (N - ok_c)
print(cnt)


Fixed submission:
#%%

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

#%%

def isok_A(index, key, arr):
    if arr[index] >= key:
        return True
    else:
        return False
 
def Binary_search_A(key, arr):
    
    ng = -1
    ok = len(arr)
    while ok - ng > 1:
        mid = (ok + ng) // 2
        if isok_A(mid, key, arr) is True:
            ok = mid
        else:
            ng = mid
    
    return ng, ok

def isok_B(index, key, arr):
    if arr[index] > key:
        return True
    else:
        return False

def Binary_search_B(key, arr):
    
    ng = -1
    ok = len(arr)
    while ok - ng > 1:
        mid = (ok + ng) // 2
        if isok_B(mid, key, arr) is True:
            ok = mid
        else:
            ng = mid
    
    return ng, ok

cnt = 0
for i in B:
    ng_a, ok_b = Binary_search_A(i, A)
    ng_c, ok_c = Binary_search_B(i, C)
    cnt += (ng_a + 1) * (N - ok_c)
print(cnt)

Buggy python submission (verdict: Time Limit Exceeded):
#%%
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()])

#%%
def isok(index, key, arr):
    if arr[index] > key:
        return True
    else:
        return False

def Binary_search(key, arr):
    
    ng = -1
    ok = len(arr)
    while ok - ng > 1:
        mid = (ok + ng) // 2
        if isok(mid, key, arr) is True:
            ok = mid
        else:
            ng = mid
    
    return ng, ok

cnt = 0
for i in A:
    ng, ok = Binary_search(i, B)
    for j in B[ok:]:
        ng_C, ok_C = Binary_search(j, C)
        cnt += len(C[ok_C: ])

print(cnt)


Fixed submission:
#%%

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

#%%

def isok_A(index, key, arr):
    if arr[index] >= key:
        return True
    else:
        return False
 
def Binary_search_A(key, arr):
    
    ng = -1
    ok = len(arr)
    while ok - ng > 1:
        mid = (ok + ng) // 2
        if isok_A(mid, key, arr) is True:
            ok = mid
        else:
            ng = mid
    
    return ng, ok

def isok_B(index, key, arr):
    if arr[index] > key:
        return True
    else:
        return False

def Binary_search_B(key, arr):
    
    ng = -1
    ok = len(arr)
    while ok - ng > 1:
        mid = (ok + ng) // 2
        if isok_B(mid, key, arr) is True:
            ok = mid
        else:
            ng = mid
    
    return ng, ok

cnt = 0
for i in B:
    ng_a, ok_b = Binary_search_A(i, A)
    ng_c, ok_c = Binary_search_B(i, C)
    cnt += (ng_a + 1) * (N - ok_c)
print(cnt)