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()
b.sort()
c.sort()

ans = 0
dict_a = dict()
dict_b = dict()
for i in range(n):
    if a[i] in dict_a.keys():
        b_mid = dict_a[a[i]]
    else:
        left = n - 1
        right = 0
        b_mid = n // 2
        while left >= right:
            if b[b_mid] > a[i]:
                left = b_mid - 1
            else:
                right = b_mid + 1
            b_mid = (left + right) // 2
        b_mid += 1
        dict_a[a[i]] = b_mid

    for j in range(b_mid, n):
        if b[j] in dict_b.keys():
            c_mid = dict_b[b[j]]
        else:
            left = n - 1
            right = 0
            c_mid = n // 2
            while left >= right:
                if c[c_mid] > b[j]:
                    left = c_mid - 1
                else:
                    right = c_mid + 1
                c_mid = (left + right) // 2
            dict_b[b[j]] = c_mid
        ans += n - c_mid - 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()

ans = 0
i = []
k = []
for j in range(n):
    left = n - 1
    right = 0
    a_mid = n // 2
    while left >= right:
        if a[a_mid] >= b[j]:
            left = a_mid - 1
        else:
            right = a_mid + 1
        a_mid = (left + right) // 2
    i.append(a_mid + 1)
    
for j in range(n):
    left = n - 1
    right = 0
    c_mid = n // 2
    while left >= right:
        if c[c_mid] > b[j]:
            left = c_mid - 1
        else:
            right = c_mid + 1
        c_mid = (left + right) // 2
    k.append(n - c_mid - 1)

ans = sum(x * y for x, y in zip(i, k))
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()
b.sort()
c.sort()

ans = 0
for i in range(n):
    left = n - 1
    right = 0
    b_mid = n // 2
    while left >= right:
        if b[b_mid] > a[i]:
            left = b_mid - 1
        else:
            right = b_mid + 1
        b_mid = (left + right) // 2
    b_mid += 1

    for j in range(b_mid, n):
        left = n - 1
        right = 0
        c_mid = n // 2
        while left >= right:
            if c[c_mid] > b[j]:
                left = c_mid - 1
            else:
                right = c_mid + 1
            c_mid = (left + right) // 2
        ans += n - c_mid - 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()

ans = 0
i = []
k = []
for j in range(n):
    left = n - 1
    right = 0
    a_mid = n // 2
    while left >= right:
        if a[a_mid] >= b[j]:
            left = a_mid - 1
        else:
            right = a_mid + 1
        a_mid = (left + right) // 2
    i.append(a_mid + 1)
    
for j in range(n):
    left = n - 1
    right = 0
    c_mid = n // 2
    while left >= right:
        if c[c_mid] > b[j]:
            left = c_mid - 1
        else:
            right = c_mid + 1
        c_mid = (left + right) // 2
    k.append(n - c_mid - 1)

ans = sum(x * y for x, y in zip(i, k))
print(ans)