Buggy python submission (verdict: Time Limit Exceeded):
# coding: utf-8
import math


def calc():
    n = int(input())
    
    tops = list(map(int, input().split()))
    middles = list(map(int, input().split()))
    lowers = list(map(int, input().split()))

    middles = sorted(middles, reverse=True)
    lowers = sorted(lowers, reverse=True)    

    d = {}
    counter = 0
    for top in tops:
        if top in d.keys():
            counter += d[top]
            continue

        c = 0
        for middle in middles:
            if middle <= top:
                break

            for lower in lowers:
                if lower <= middle:
                    break
                
                c += 1
                
        d[top] = c
        counter += c
    
    return counter

count = calc()
print(count)

Fixed submission:
# coding: utf-8
import math
import bisect

def calc():
    n = int(input())
    tops = list(map(int, input().split()))
    middles = list(map(int, input().split()))
    lowers = list(map(int, input().split()))
 
    tops = sorted(tops)
    lowers = sorted(lowers)
 
    counter = 0
 
    for i in range(n):
        # A < B
        top_num = bisect.bisect_left(tops, middles[i])
        
        # B < C
        lower_num = n - bisect.bisect_right(lowers, middles[i])
        
        counter += top_num * lower_num
    
    return counter
 
print(calc())

Buggy python submission (verdict: Time Limit Exceeded):
# coding: utf-8
import math
 
 
def calc():
    n = int(input())
 
    tops = list(map(int, input().split()))
    middles = list(map(int, input().split()))
    lowers = list(map(int, input().split()))
 
    lowers = sorted(lowers, reverse=True)
 
    max_lower = max(lowers)
    middles = sorted(list(filter(lambda x: x < max_lower, middles)), reverse=True)
 
    if middles == []:
        return 0
 
    max_middle = max(middles)
    tops = sorted(list(filter(lambda x: x < max_middle, tops)), reverse=True)
    
    if tops == []:
        return 0
 
    counter = 0
    for top in tops:
        for middle in middles:
            if middle <= top:
                break
 
            for lower in lowers:
                if lower <= middle:
                    break
                
                counter += 1
                
    return counter
 
count = calc()
print(count)

Fixed submission:
# coding: utf-8
import math
import bisect

def calc():
    n = int(input())
    tops = list(map(int, input().split()))
    middles = list(map(int, input().split()))
    lowers = list(map(int, input().split()))
 
    tops = sorted(tops)
    lowers = sorted(lowers)
 
    counter = 0
 
    for i in range(n):
        # A < B
        top_num = bisect.bisect_left(tops, middles[i])
        
        # B < C
        lower_num = n - bisect.bisect_right(lowers, middles[i])
        
        counter += top_num * lower_num
    
    return counter
 
print(calc())

Buggy python submission (verdict: Time Limit Exceeded):
# coding: utf-8
import math


def calc():
    n = int(input())

    tops = list(map(int, input().split()))
    middles = list(map(int, input().split()))
    lowers = list(map(int, input().split()))

    middles = sorted(middles, reverse=True)
    lowers = sorted(lowers, reverse=True)    

    counter = 0
    for top in tops:
        for middle in middles:
            if middle <= top:
                break

            for lower in lowers:
                if lower <= middle:
                    break
                
                counter += 1
                
    return counter

count = calc()
print(count)

Fixed submission:
# coding: utf-8
import math
import bisect

def calc():
    n = int(input())
    tops = list(map(int, input().split()))
    middles = list(map(int, input().split()))
    lowers = list(map(int, input().split()))
 
    tops = sorted(tops)
    lowers = sorted(lowers)
 
    counter = 0
 
    for i in range(n):
        # A < B
        top_num = bisect.bisect_left(tops, middles[i])
        
        # B < C
        lower_num = n - bisect.bisect_right(lowers, middles[i])
        
        counter += top_num * lower_num
    
    return counter
 
print(calc())

Buggy python submission (verdict: Time Limit Exceeded):
# coding: utf-8
import math


def calc():
    n = int(input())

    tops = list(map(int, input().split()))
    middles = list(map(int, input().split()))
    lowers = list(map(int, input().split()))

    lowers = sorted(lowers, reverse=True)

    max_lower = max(lowers)
    middles = sorted(list(filter(lambda x: x < max_lower, middles)), reverse=True)

    if middles == []:
        return 0

    max_middle = max(middles)
    tops = sorted(list(filter(lambda x: x < max_middle, tops)), reverse=True)
    
    if tops == []:
        return 0

    counter = 0
    for top in tops:
        for middle in middles:
            if middle <= top:
                break

            for lower in lowers:
                if lower <= middle:
                    break
                
                counter += 1
                
    return counter

count = calc()
print(count)

Fixed submission:
# coding: utf-8
import math
import bisect

def calc():
    n = int(input())
    tops = list(map(int, input().split()))
    middles = list(map(int, input().split()))
    lowers = list(map(int, input().split()))
 
    tops = sorted(tops)
    lowers = sorted(lowers)
 
    counter = 0
 
    for i in range(n):
        # A < B
        top_num = bisect.bisect_left(tops, middles[i])
        
        # B < C
        lower_num = n - bisect.bisect_right(lowers, middles[i])
        
        counter += top_num * lower_num
    
    return counter
 
print(calc())

Buggy python submission (verdict: Runtime Error):
# coding: utf-8
import math


n = int(input())

tops = list(map(int, input().split()))
middles = list(map(int, input().split()))
lowers = list(map(int, input().split()))

max_lower = max(lowers)
middles = list(filter(lambda x: x < max_lower, middles))

max_middle = max(middles)
tops = list(filter(lambda x: x < max_middle, tops))

counter = 0
for top in tops:
    for middle in middles:
        if middle <= top:
            continue

        for lower in lowers:
            if lower <= middle:
                continue
            
            counter += 1
            
            
print(counter)

Fixed submission:
# coding: utf-8
import math
import bisect

def calc():
    n = int(input())
    tops = list(map(int, input().split()))
    middles = list(map(int, input().split()))
    lowers = list(map(int, input().split()))
 
    tops = sorted(tops)
    lowers = sorted(lowers)
 
    counter = 0
 
    for i in range(n):
        # A < B
        top_num = bisect.bisect_left(tops, middles[i])
        
        # B < C
        lower_num = n - bisect.bisect_right(lowers, middles[i])
        
        counter += top_num * lower_num
    
    return counter
 
print(calc())