Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
Lists = []
ans = 0
for _ in range(3):
    s = [int(e) for e in input().split()]
    s.sort()
    Lists.append(s)
def bin(right,left,i,j):
    global ans
    while(right >= left):
        mid =int(left + (right-left) / 2)
        if(i>=Lists[j][mid]):
            left = mid + 1
        else:
            right = mid - 1
    if(j == 2 and left <= N-1):
        ans += N-left
    elif(left <= N-1):
        for k in range(left,N):
            bin(N-1,0,Lists[j][k],j+1)
for i in Lists[0]:
    bin(N-1,0,i,1)
print(ans)


Fixed submission:
N = int(input())
Lists = []
ans = 0
for _ in range(3):
    s = [int(e) for e in input().split()]
    s.sort()
    Lists.append(s)
def bin(i,j):
    global t,s
    right = N-1;left = 0
    while(right >= left):
        mid = int(left + (right-left)/2)
        if(j==0):
            if(i>Lists[j][mid]):
                left = mid + 1
            else:
                right = mid -1
        else:
            if(i>=Lists[j][mid]):
                left = mid + 1
            else:
                right = mid - 1
    if(j == 0):
        t = left
    else:
        s = N - left
for i in Lists[1]:
    bin(i,0)
    bin(i,2)
    ans += t*s
print(ans)

Buggy python submission (verdict: Runtime Error):
N = int(input())
Lists = []
ans = 0
for _ in range(3):
    s = [int(e) for e in input().split()]
    s.sort()
print(Lists)
def a(right,left,i,j):
    global ans
    while(right >= left):
        mid =int(left + (right-left) / 2)
        if(i>=Lists[j][mid]):
            left = mid + 1
        else:
            right = mid - 1
    if(j == 2 and left <= N-1):
        ans += N-left
    elif(left <= N-1):
        for k in range(left,N):
            a(N-1,0,Lists[j][k],j+1)
for i in Lists[0]:
    a(N-1,0,i,1)
print(ans)


Fixed submission:
N = int(input())
Lists = []
ans = 0
for _ in range(3):
    s = [int(e) for e in input().split()]
    s.sort()
    Lists.append(s)
def bin(i,j):
    global t,s
    right = N-1;left = 0
    while(right >= left):
        mid = int(left + (right-left)/2)
        if(j==0):
            if(i>Lists[j][mid]):
                left = mid + 1
            else:
                right = mid -1
        else:
            if(i>=Lists[j][mid]):
                left = mid + 1
            else:
                right = mid - 1
    if(j == 0):
        t = left
    else:
        s = N - left
for i in Lists[1]:
    bin(i,0)
    bin(i,2)
    ans += t*s
print(ans)

Buggy python submission (verdict: Runtime Error):
N = int(input())
Lists = []
ans = 0
for _ in range(3):
    s = [int(e) for e in input().split()]
    s.sort()
print(Lists)
def binary(right,left,i,j):
    global ans
    while(right >= left):
        mid =int(left + (right-left) / 2)
        if(i>=Lists[j][mid]):
            left = mid + 1
        else:
            right = mid - 1
    if(j == 2 and left <= N-1):
        ans += N-left
    elif(left <= N-1):
        for k in range(left,N):
            binary(N-1,0,Lists[j][k],j+1)
for i in Lists[0]:
    binary(N-1,0,i,1)
print(ans)

Fixed submission:
N = int(input())
Lists = []
ans = 0
for _ in range(3):
    s = [int(e) for e in input().split()]
    s.sort()
    Lists.append(s)
def bin(i,j):
    global t,s
    right = N-1;left = 0
    while(right >= left):
        mid = int(left + (right-left)/2)
        if(j==0):
            if(i>Lists[j][mid]):
                left = mid + 1
            else:
                right = mid -1
        else:
            if(i>=Lists[j][mid]):
                left = mid + 1
            else:
                right = mid - 1
    if(j == 0):
        t = left
    else:
        s = N - left
for i in Lists[1]:
    bin(i,0)
    bin(i,2)
    ans += t*s
print(ans)