Buggy python submission (verdict: Time Limit Exceeded):
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(N, 0, -1):
    for j in range(N, 0, -1):
        #print(B[j-1],C[i-1],"BC")
        if B[j-1] < C[i-1]:
            for k in range(N, 0, -1):
                #print(A[k-1],B[j-1],"AB")
                if A[k-1] < B[j-1]:
                    ans = ans + k
                    break
else:
    print(ans)


Fixed submission:
n = int(input())
A = sorted(list(map(int,input().split())))
B = sorted(list(map(int,input().split())))
C = sorted(list(map(int,input().split())))
count = 0

A.insert(0,-1)
A.append(10e+10)
C.insert(0,-1)
C.append(10e+10)

for bi in B:
    left = 0
    right = n+1
    
    while right-left>1:
        middle = (left+right) //2
        if A[middle]>=bi:
            right = middle
        else:
            left = middle
    a_count = left

    left = 0
    right = n+1
    while right-left>1:
        middle = (left+right) //2
        if C[middle]>bi:
            right = middle
        else:
            left = middle
    c_count = n+1-right

    count += a_count*c_count

print(count)

Buggy python submission (verdict: Time Limit Exceeded):
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(N, 0, -1):
    for j in range(N, 0, -1):
        #print(B[j-1],C[i-1],"BC")
        if B[j-1] < C[i-1]:
            for k in range(N, 0, -1):
                #print(A[k-1],B[j-1],"AB")
                if A[k-1] < B[j-1]:
                    ans = ans + k
                    break
else:
    print(ans)

Fixed submission:
n = int(input())
A = sorted(list(map(int,input().split())))
B = sorted(list(map(int,input().split())))
C = sorted(list(map(int,input().split())))
count = 0

A.insert(0,-1)
A.append(10e+10)
C.insert(0,-1)
C.append(10e+10)

for bi in B:
    left = 0
    right = n+1
    
    while right-left>1:
        middle = (left+right) //2
        if A[middle]>=bi:
            right = middle
        else:
            left = middle
    a_count = left

    left = 0
    right = n+1
    while right-left>1:
        middle = (left+right) //2
        if C[middle]>bi:
            right = middle
        else:
            left = middle
    c_count = n+1-right

    count += a_count*c_count

print(count)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
C = list(map(int,input().split()))
ck = 0
for i in range(0, N):
    for j in range(0, N):
        for k in range(0, N):
            if A[i] < B[j] < C[k]:
                ck = ck + 1
else:
    print(ck)


Fixed submission:
n = int(input())
A = sorted(list(map(int,input().split())))
B = sorted(list(map(int,input().split())))
C = sorted(list(map(int,input().split())))
count = 0

A.insert(0,-1)
A.append(10e+10)
C.insert(0,-1)
C.append(10e+10)

for bi in B:
    left = 0
    right = n+1
    
    while right-left>1:
        middle = (left+right) //2
        if A[middle]>=bi:
            right = middle
        else:
            left = middle
    a_count = left

    left = 0
    right = n+1
    while right-left>1:
        middle = (left+right) //2
        if C[middle]>bi:
            right = middle
        else:
            left = middle
    c_count = n+1-right

    count += a_count*c_count

print(count)