Buggy python submission (verdict: Time Limit Exceeded):
def main():
    import bisect

    N = int(input())
    upper = list(map(int, input().split()))
    middle = list(map(int, input().split()))
    lower = list(map(int, input().split()))

    upper.sort()
    middle.sort()
    lower.sort()

    cnt = 0

    index_mid = 0
    index_low = 0

    for i in range(N):
        len_up = upper[i]
        index_mid = index_mid + bisect.bisect_right(middle[index_mid:], len_up)

        if (index_mid >= N):
            break

        index_low = index_low + bisect.bisect_right(lower[index_low:], middle[index_mid])

        tmp_mid = index_mid
        tmp_low = index_low        

        while (tmp_mid < N):
            len_mid = middle[tmp_mid]
            tmp_low = tmp_low + bisect.bisect_right(lower[tmp_low:], len_mid)

            if (tmp_low < N):
                cnt += N - tmp_low
                tmp_mid += 1

            else:
                break

    print(cnt)


if __name__ == '__main__':
    main()



Fixed submission:
def main():
    import bisect

    N = int(input())
    upper = list(map(int, input().split()))
    middle = list(map(int, input().split()))
    lower = list(map(int, input().split()))

    upper.sort()
    middle.sort()
    lower.sort()

    cnt = 0

    for i in range(N):
        mid = middle[i]
        index_up = bisect.bisect_left(upper, mid)
        index_low = bisect.bisect_right(lower, mid)
        
        cnt += index_up * (N - index_low)
    
    print(cnt)


if __name__ == '__main__':
    main()

Buggy python submission (verdict: Time Limit Exceeded):
def main():
    import bisect

    N = int(input())
    upper = list(map(int, input().split()))
    middle = list(map(int, input().split()))
    lower = list(map(int, input().split()))

    upper.sort()
    middle.sort()
    lower.sort()

    cnt = 0

    index_mid = 0
    index_low = 0

    for i in range(N):
        len_up = upper[i]
        index_mid = index_mid + bisect.bisect_right(middle[index_mid:], len_up)

        if (index_mid >= N):
            break

        index_low = index_low + bisect.bisect_right(lower[index_low:], middle[index_mid])

        tmp_mid = index_mid
        tmp_low = index_low        

        while (tmp_mid < N):
            len_mid = middle[tmp_mid]
            tmp_low = tmp_low + bisect.bisect_right(lower[tmp_low:], len_mid)

            if (tmp_low < N):
                cnt += N - tmp_low
                tmp_mid += 1

            else:
                break

    print(cnt)


if __name__ == '__main__':
    main()



Fixed submission:
def main():
    import bisect

    N = int(input())
    upper = list(map(int, input().split()))
    middle = list(map(int, input().split()))
    lower = list(map(int, input().split()))

    upper.sort()
    middle.sort()
    lower.sort()

    cnt = 0

    for i in range(N):
        mid = middle[i]
        index_up = bisect.bisect_left(upper, mid)
        index_low = bisect.bisect_right(lower, mid)
        
        cnt += index_up * (N - index_low)
    
    print(cnt)


if __name__ == '__main__':
    main()

Buggy python submission (verdict: Time Limit Exceeded):
def main():
    import bisect

    N = int(input())
    upper = list(map(int, input().split()))
    middle = list(map(int, input().split()))
    lower = list(map(int, input().split()))

    upper.sort()
    middle.sort()
    lower.sort()

    cnt = 0

    for i in range(N):
        len_up = upper[i]
        
        index_mid = bisect.bisect_right(middle, len_up)

        while (index_mid < N):
            len_mid = middle[index_mid]
            index_low = bisect.bisect_right(lower, len_mid)

            if (index_low < N):
                cnt += N - index_low
                index_mid += 1
            
            else:
                break

    print(cnt)


if __name__ == '__main__':
    main()


Fixed submission:
def main():
    import bisect

    N = int(input())
    upper = list(map(int, input().split()))
    middle = list(map(int, input().split()))
    lower = list(map(int, input().split()))

    upper.sort()
    middle.sort()
    lower.sort()

    cnt = 0

    for i in range(N):
        mid = middle[i]
        index_up = bisect.bisect_left(upper, mid)
        index_low = bisect.bisect_right(lower, mid)
        
        cnt += index_up * (N - index_low)
    
    print(cnt)


if __name__ == '__main__':
    main()