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

def f(l, s, mn):
    ng = s - 1
    ok = len(l)
    while abs(ng - ok) > 1:
        i = (ok + ng) // 2
        x = l[i]
        if mn < x:
            ok = i
        else:
            ng = i
    return ok

ans = 0
bs = 0
for a in A:
    cs = 0
    bs = f(B, bs, a)
    for bi in range(bs, N):
        cs = f(C, cs, B[bi])
        ans += N - cs

print(ans)

Fixed submission:
from bisect import bisect_left, bisect_right
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))
A.sort()
C.sort()

ans = 0
for b in B:
    acnt = bisect_left(A, b)
    ccnt = N - bisect_right(C, b)
    ans += acnt * ccnt
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()))
B.sort()
C.sort()

def f(l, mn):
    ng = -1
    ok = len(l)
    while abs(ng - ok) > 1:
        i = (ok + ng) // 2
        x = l[i]
        if mn < x:
            ok = i
        else:
            ng = i
    return ok

ans = 0
for a in A:
    for bi in range(f(B, a), N):
        b = B[bi]
        ans += N - f(C, b)
print(ans)

Fixed submission:
from bisect import bisect_left, bisect_right
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))
A.sort()
C.sort()

ans = 0
for b in B:
    acnt = bisect_left(A, b)
    ccnt = N - bisect_right(C, b)
    ans += acnt * ccnt
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()))
B.sort()
C.sort()

def f(l, mn):
    ng = -1
    ok = len(l)
    while abs(ng - ok) > 1:
        i = (ok + ng) // 2
        x = l[i]
        if mn < x:
            ok = i
        else:
            ng = i
    return ok

ans = 0
for a in A:
    for bi in range(f(B, a), N):
        b = B[bi]
        ans += N - f(C, b)
print(ans)

Fixed submission:
from bisect import bisect_left, bisect_right
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))
A.sort()
C.sort()

ans = 0
for b in B:
    acnt = bisect_left(A, b)
    ccnt = N - bisect_right(C, b)
    ans += acnt * ccnt
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()

def f(l, mn):
    ng = -1
    ok = len(l)
    while abs(ng - ok) > 1:
        i = (ok + ng) // 2
        x = l[i]
        if mn < x:
            ok = i
        else:
            ng = i
    return l[ok:]

ans = 0
for a in A:
    for b in f(B, a):
        ans += len(f(C, b))
print(ans)

Fixed submission:
from bisect import bisect_left, bisect_right
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))
A.sort()
C.sort()

ans = 0
for b in B:
    acnt = bisect_left(A, b)
    ccnt = N - bisect_right(C, b)
    ans += acnt * ccnt
print(ans)