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()))
A.sort(reverse=True)
B.sort(reverse=True)
C.sort(reverse=True)
bidx = 0
cidx = 0
abnums = [0] * (N+1)
bcnums = [0] * (N+1)
idx = 0
for i, a in enumerate(A):
    abnums[i+1] = abnums[i]
    if abnums[i+1] == N:
        continue
    for j, b in enumerate(B[idx:]):
        if a < b:
            abnums[i+1] += 1
        else:
            idx = j + idx
            break

idx = 0
for i, b in enumerate(B):
    bcnums[i+1] = bcnums[i]
    if bcnums[i+1] == N:
        continue
    for j, c in enumerate(C[idx:]):
        if b < c:
            bcnums[i+1] += 1
        else:
            idx = j + idx
            break

for i in range(1, N+1):
    bcnums[i] += bcnums[i-1]

ans = 0
for n in abnums[1:]:
    ans += bcnums[n]
print(ans)

Fixed submission:
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))
A.sort()
B.sort()
C.sort()
idxa = 0
idxc = 0
ans = 0
for b in range(N):
    while idxa < N and A[idxa] < B[b]:
        idxa += 1
    while idxc < N and B[b] >= C[idxc]:
        idxc += 1
    ans += idxa * (N - idxc)
print(ans)

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()))
A.sort(reverse=True)
B.sort(reverse=True)
C.sort(reverse=True)
bidx = 0
cidx = 0
abnums = [0] * (N+1)
bcnums = [0] * (N+1)
idx = 0
for i, a in enumerate(A):
    abnums[i+1] = abnums[i]
    if abnums[i+1] == N:
        continue
    for j, b in enumerate(B[idx:]):
        if a < b:
            abnums[i+1] += 1
        else:
            idx = j + idx
            break

idx = 0
for i, b in enumerate(B):
    bcnums[i+1] = bcnums[i]
    if bcnums[i+1] == N:
        continue
    for j, c in enumerate(C[idx:]):
        if b < c:
            bcnums[i+1] += 1
        else:
            idx = j + idx
            break

ans = 0
for n in abnums[1:]:
    ans += sum(bcnums[1:n+1])
print(ans)

Fixed submission:
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))
A.sort()
B.sort()
C.sort()
idxa = 0
idxc = 0
ans = 0
for b in range(N):
    while idxa < N and A[idxa] < B[b]:
        idxa += 1
    while idxc < N and B[b] >= C[idxc]:
        idxc += 1
    ans += idxa * (N - idxc)
print(ans)

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

nums = []
for b in B:
    count = 0
    for c in C:
        if b < c:
            count += 1
    nums.append(count)

ans = 0
for a in A:
    for b, n in zip(B, nums):
        if a < b:
            ans += n
print(ans)


Fixed submission:
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))
A.sort()
B.sort()
C.sort()
idxa = 0
idxc = 0
ans = 0
for b in range(N):
    while idxa < N and A[idxa] < B[b]:
        idxa += 1
    while idxc < N and B[b] >= C[idxc]:
        idxc += 1
    ans += idxa * (N - idxc)
print(ans)