Buggy python submission (verdict: Runtime Error):
import sys


def main():
        n = sys.stdin.readline()

        astr = sys.stdin.readline()
        bstr = sys.stdin.readline()
        cstr = sys.stdin.readline()

        a = list(map(int, astr.strip().split(' ')))
        b = list(map(int, bstr.strip().split(' ')))
        c = list(map(int, cstr.strip().split(' ')))

        a.sort()
        b.sort()
        c.sort()

        cnt = 0

        bc = []
        sum = 0
        for bi in reversed(b):
                ct = c[binary(bi, c):]
                sum += len(ct)
                bc.append(sum)
        bc.reverse()

        cnt = 0
        for ai in a:
                bi = binary(ai, b)
                cnt += bc[bi]

        print(cnt)


def binary(x, li):
    upper = len(li)
    lower = -1
    index = int((upper + lower) / 2)


    while upper - lower > 1:
        if (x < li[index]):
            upper = index
        else:
            lower = index
        index = int((upper + lower)/2)
    
    return upper


main()

Fixed submission:
import sys

import time


def main():
        n = sys.stdin.readline()

        astr = sys.stdin.readline()
        bstr = sys.stdin.readline()
        cstr = sys.stdin.readline()

        a = list(map(int, astr.strip().split(' ')))
        b = list(map(int, bstr.strip().split(' ')))
        c = list(map(int, cstr.strip().split(' ')))

        a.sort()
        b.sort()
        c.sort()

        cnt = 0

        bc = []
        sum = 0
        timesum = 0
        for bi in reversed(b):
                sum += len(c) - binary(bi,c)
                bc.append(sum)
        bc.reverse()

        cnt = 0
        for ai in a:
                bi = binary(ai, b)
                if(bi < len(bc)):
                    cnt += bc[bi]

        print(cnt)


def binary(x, li):
    upper = len(li)
    lower = -1
    index = int((upper + lower) / 2)

    while upper - lower > 1:
        if (x < li[index]):
            upper = index
        else:
            lower = index
        index = int((upper + lower)/2)
    
    return upper


main()

Buggy python submission (verdict: Time Limit Exceeded):
import sys


def main():
        n = sys.stdin.readline()

        astr = sys.stdin.readline()
        bstr = sys.stdin.readline()
        cstr = sys.stdin.readline()

        a = map(int, astr.strip().split(' '))
        b = map(int, bstr.strip().split(' '))
        c = map(int, cstr.strip().split(' '))

        a.sort()
        b.sort()
        c.sort()

        cnt = 0

        for ai in a:
                bt = b[binary(ai, b):]
                for bi in bt:
                        ct = c[binary(bi, c):]
                        cnt = cnt + len(ct)

        print(cnt)


def binary(x, li):
    upper = len(li)
    lower = -1
    index = (upper + lower) / 2


    while upper - lower > 1:
        if (x < li[index]):
            upper = index
        else:
            lower = index
        index = (upper + lower)/2
    
    return upper


main()

Fixed submission:
import sys

import time


def main():
        n = sys.stdin.readline()

        astr = sys.stdin.readline()
        bstr = sys.stdin.readline()
        cstr = sys.stdin.readline()

        a = list(map(int, astr.strip().split(' ')))
        b = list(map(int, bstr.strip().split(' ')))
        c = list(map(int, cstr.strip().split(' ')))

        a.sort()
        b.sort()
        c.sort()

        cnt = 0

        bc = []
        sum = 0
        timesum = 0
        for bi in reversed(b):
                sum += len(c) - binary(bi,c)
                bc.append(sum)
        bc.reverse()

        cnt = 0
        for ai in a:
                bi = binary(ai, b)
                if(bi < len(bc)):
                    cnt += bc[bi]

        print(cnt)


def binary(x, li):
    upper = len(li)
    lower = -1
    index = int((upper + lower) / 2)

    while upper - lower > 1:
        if (x < li[index]):
            upper = index
        else:
            lower = index
        index = int((upper + lower)/2)
    
    return upper


main()

Buggy python submission (verdict: Time Limit Exceeded):
import sys

n = sys.stdin.readline()

astr = sys.stdin.readline()
bstr = sys.stdin.readline()
cstr = sys.stdin.readline()

a = map(int, astr.strip().split(' '))
b = map(int, bstr.strip().split(' '))
c = map(int, cstr.strip().split(' '))

a.sort()
b.sort()
c.sort()

cnt = 0

for ai in a:
        bt = filter(lambda x:x > ai, b)
        for bi in bt:
                ct = filter(lambda x:x > bi, c)
                cnt = cnt + len(ct)

print(cnt)

Fixed submission:
import sys

import time


def main():
        n = sys.stdin.readline()

        astr = sys.stdin.readline()
        bstr = sys.stdin.readline()
        cstr = sys.stdin.readline()

        a = list(map(int, astr.strip().split(' ')))
        b = list(map(int, bstr.strip().split(' ')))
        c = list(map(int, cstr.strip().split(' ')))

        a.sort()
        b.sort()
        c.sort()

        cnt = 0

        bc = []
        sum = 0
        timesum = 0
        for bi in reversed(b):
                sum += len(c) - binary(bi,c)
                bc.append(sum)
        bc.reverse()

        cnt = 0
        for ai in a:
                bi = binary(ai, b)
                if(bi < len(bc)):
                    cnt += bc[bi]

        print(cnt)


def binary(x, li):
    upper = len(li)
    lower = -1
    index = int((upper + lower) / 2)

    while upper - lower > 1:
        if (x < li[index]):
            upper = index
        else:
            lower = index
        index = int((upper + lower)/2)
    
    return upper


main()