Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = [int(i) for i in input().split()]
B = [int(i) for i in input().split()]
C = [int(i) for i in input().split()]
A.sort();C.sort()
M = 0
for i in range(N):
    low = 0
    high = N - 1
    t = (low + high) // 2
    if A[N-1] < B[i]:
        t = N-1
    elif A[0] >= B[i]:
        t = -1
    else:
        while (low <= high):
            if A[t] < B[i] <= A[t+1]:
                break
            elif B[i] <= A[t]:
                high = t
            elif A[t+1] < B[i]:
                low = t+1
            t = (low + high) // 2
    low = 0
    high = N - 1
    s = (low + high) // 2
    if C[N-1] <= B[i]:
        s = N-1
    elif B[i] < C[0]:
        s = -1
    else:
        while (low <= high):
            if C[s] <= B[i] < C[s+1]:
                break
            elif B[i] < C[s]:
                high = s
            elif C[s+1] <= B[i]:
                low = s + 1
            s = (low + high) // 2
    M += (t+1)*(N-s-1)
print(M)


Fixed submission:
N = int(input())
A = [0 for i in range(N)]
B = [0 for i in range(N)]
C = [0 for i in range(N)]
st = input().split()
for i in range(N):
    A[i] = int(st[i])
st = input().split()
for i in range(N):
    B[i] = int(st[i])
st = input().split()
for i in range(N):
    C[i] = int(st[i])
A.sort();C.sort()
M = 0
for i in range(N):
    low = 0
    high = N - 1
    t = (low + high) // 2
    if A[N-1] < B[i]:
        t = N-1
    elif A[0] >= B[i]:
        t = -1
    else:
        while (low <= high):
            if A[t] < B[i] <= A[t+1]:
                break
            elif B[i] <= A[t]:
                high = t
            elif A[t+1] < B[i]:
                low = t+1
            t = (low + high) // 2
    low = 0
    high = N - 1
    s = (low + high) // 2
    if C[N-1] <= B[i]:
        s = N-1
    elif B[i] < C[0]:
        s = -1
    else:
        while (low <= high):
            if C[s] <= B[i] < C[s+1]:
                break
            elif B[i] < C[s]:
                high = s
            elif C[s+1] <= B[i]:
                low = s + 1
            s = (low + high) // 2
    M += (t+1)*(N-s-1)
print(M)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = [0 for i in range(N)]
B = [0 for i in range(N)]
C = [0 for i in range(N)]
st = input().split()
for i in range(N):
    A[i] = int(st[i])
st = input().split()
for i in range(N):
    B[i] = int(st[i])
st = input().split()
for i in range(N):
    C[i] = int(st[i])
A.sort();C.sort()
M = 0
for i in range(N):
    low = 0
    high = N - 1
    t = (low + high) // 2
    if A[N-1] < B[i]:
        t = N-1
    elif A[0] >= B[i]:
        t = -1
    else:
        while (low <= high):
            if A[t] < B[i] <= A[t+1]:
                break
            elif B[i] <= A[t]:
                high = t
            elif A[t+1] < B[i]:
                low = t+1
            t = (low + high) // 2
    low = 0
    high = N - 1
    s = (low + high) // 2
    if C[N-1] <= B[i]:
        s = N-1
    elif B[i] < C[0]:
        s = -1
    else:
        while (low <= high):
            if C[s] <= B[i] < C[s+1]:
                break
            elif B[i] < C[s]:
                high = s
            elif C[s+1] <= B[i]:
                low = s + 1
            s = (low + high) // 2
    M += (t+1)*(N-s-1)
print(M)

Fixed submission:
N = int(input())
A = [0 for i in range(N)]
B = [0 for i in range(N)]
C = [0 for i in range(N)]
st = input().split()
for i in range(N):
    A[i] = int(st[i])
st = input().split()
for i in range(N):
    B[i] = int(st[i])
st = input().split()
for i in range(N):
    C[i] = int(st[i])
A.sort();C.sort()
M = 0
for i in range(N):
    low = 0
    high = N - 1
    t = (low + high) // 2
    if A[N-1] < B[i]:
        t = N-1
    elif A[0] >= B[i]:
        t = -1
    else:
        while (low <= high):
            if A[t] < B[i] <= A[t+1]:
                break
            elif B[i] <= A[t]:
                high = t
            elif A[t+1] < B[i]:
                low = t+1
            t = (low + high) // 2
    low = 0
    high = N - 1
    s = (low + high) // 2
    if C[N-1] <= B[i]:
        s = N-1
    elif B[i] < C[0]:
        s = -1
    else:
        while (low <= high):
            if C[s] <= B[i] < C[s+1]:
                break
            elif B[i] < C[s]:
                high = s
            elif C[s+1] <= B[i]:
                low = s + 1
            s = (low + high) // 2
    M += (t+1)*(N-s-1)
print(M)