Buggy python submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline

def binary_search(xs,target,maxlen,low,high,reverse=True):
    middle = 0
    while(low <= high):
        middle = (low + high) // 2
        can = xs[middle]
        if can == target:
            if reverse == False:
                return middle
            else:
                return middle + 1
        if can > target:
            high = middle - 1
        elif can < target:
            low = middle + 1

    middle = (low + high) // 2 +1
    return middle

def snuke_festival(a,b,c):
    count = 0
    a_sorted = sorted(a)
    b_sorted = sorted(b)
    c_sorted = sorted(c)
    maxlen=len(b)
    high = maxlen - 1
    low = 0
    mid_a = low
    mid_b = high

    for target in b_sorted:
        mid_a = binary_search(a_sorted,target,maxlen,mid_a,high,False)
        mid_b = binary_search(c_sorted,target,maxlen,low,mid_b,True)
        count += mid_a * (maxlen - mid_b)
    return count

if __name__ == "__main__":
    n = int(input())
    a = list(map(int,input().split()))
    b = list(map(int,input().split()))
    c = list(map(int,input().split()))

    print(snuke_festival(a,b,c))


Fixed submission:
import sys
input = sys.stdin.readline
import bisect
    
def snuke_festival(a,b,c):
    count = 0
    a_sorted = sorted(a)
    b_sorted = sorted(b)
    c_sorted = sorted(c)
    maxlen=len(b)

    for target in b_sorted:
        #mid_a = binary_search_left(a_sorted,target)
        #mid_c = binary_search_right(c_sorted,target)
        mid_a = bisect.bisect_left(a_sorted,target)
        mid_c = bisect.bisect_right(c_sorted,target)
        count += mid_a * (maxlen - mid_c)
        #print("mid_a %d, mid_c %d, count %d" %(mid_a,maxlen - mid_c,count))
    return count

if __name__ == "__main__":
    n = int(input())
    a = list(map(int,input().split()))
    b = list(map(int,input().split()))
    c = list(map(int,input().split()))

    print(snuke_festival(a,b,c))

Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = sys.stdin.readline

def binary_search(ys,target,low,high,reverse=True):
    xs = sorted(ys)
    maxlen = len(xs)

    middle = 0
    #print("array => %s, target => %d" %(xs,target))
    while(low <= high):
        middle = (low + high) // 2
        #print("target %d, low %d, mid %d, high %d" %(target,low,middle,high))
        if xs[middle] == target:
             #print("find ",middle)
            if reverse == False:
                return middle
            else:
                return middle+1
        if xs[middle] > target:
            high = middle - 1
        elif xs[middle] < target:
            low = middle + 1

    middle = (low + high) // 2 +1
   # print("target %d, low %d, mid %d, high %d" %(target,low,middle,high))
    return middle
    


def snuke_festival(a,b,c):
    count = 0
    b_sorted = sorted(b)
    high = len(b)-1
    low = 0
    ab = 0
    bc = 0
    mid_a = 0
    mid_b = 0
    maxlen=len(b)
    for n in range(maxlen):
        mid_a = binary_search(a,b_sorted[n],mid_a,high,False)
        ab = mid_a
        mid_b = binary_search(c,b_sorted[n],low,mid_b,True)
        bc = maxlen - mid_b
        count += ab * bc
    return count

if __name__ == "__main__":
    n = int(input())
    a = list(map(int,input().split()))
    b = list(map(int,input().split()))
    c = list(map(int,input().split()))

    print(snuke_festival(a,b,c))


Fixed submission:
import sys
input = sys.stdin.readline
import bisect
    
def snuke_festival(a,b,c):
    count = 0
    a_sorted = sorted(a)
    b_sorted = sorted(b)
    c_sorted = sorted(c)
    maxlen=len(b)

    for target in b_sorted:
        #mid_a = binary_search_left(a_sorted,target)
        #mid_c = binary_search_right(c_sorted,target)
        mid_a = bisect.bisect_left(a_sorted,target)
        mid_c = bisect.bisect_right(c_sorted,target)
        count += mid_a * (maxlen - mid_c)
        #print("mid_a %d, mid_c %d, count %d" %(mid_a,maxlen - mid_c,count))
    return count

if __name__ == "__main__":
    n = int(input())
    a = list(map(int,input().split()))
    b = list(map(int,input().split()))
    c = list(map(int,input().split()))

    print(snuke_festival(a,b,c))

Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = sys.stdin.readline

def binary_search(ys,target,reverse=True):
    xs = sorted(ys)
    low = 0
    maxlen = len(xs)
    high = len(xs)-1
    middle = 0
    #print("array => %s, target => %d" %(xs,target))
    while(low <= high):
        middle = (low + high) // 2

        if xs[middle] == target:
            #print("find ",middle)
            if reverse == False:
                return middle
            else:
                return maxlen - middle - 1
        elif xs[middle] > target:
            high = middle - 1
        elif xs[middle] < target:
            low = middle + 1

    middle = (low + high) // 2
    if reverse == False:
        return middle + 1
    else:
        return maxlen - middle - 1


def snuke_festival(a,b,c):
    count = 0
    b_sorted = sorted(b)
    for n in b_sorted:
        ab = 0
        bc = 0
        ab = binary_search(a,n,False)
        bc = binary_search(c,n,True)
        count += ab * bc
        #print("%d * %d = %d, count = %d" %(ab, bc,ab*bc,count))
        #print("")
    return count

if __name__ == "__main__":
    n = int(input())
    a = list(map(int,input().split()))
    b = list(map(int,input().split()))
    c = list(map(int,input().split()))

    print(snuke_festival(a,b,c))


Fixed submission:
import sys
input = sys.stdin.readline
import bisect
    
def snuke_festival(a,b,c):
    count = 0
    a_sorted = sorted(a)
    b_sorted = sorted(b)
    c_sorted = sorted(c)
    maxlen=len(b)

    for target in b_sorted:
        #mid_a = binary_search_left(a_sorted,target)
        #mid_c = binary_search_right(c_sorted,target)
        mid_a = bisect.bisect_left(a_sorted,target)
        mid_c = bisect.bisect_right(c_sorted,target)
        count += mid_a * (maxlen - mid_c)
        #print("mid_a %d, mid_c %d, count %d" %(mid_a,maxlen - mid_c,count))
    return count

if __name__ == "__main__":
    n = int(input())
    a = list(map(int,input().split()))
    b = list(map(int,input().split()))
    c = list(map(int,input().split()))

    print(snuke_festival(a,b,c))

Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = sys.stdin.readline

def snuke_festival(a,b,c):
    count = 0
    a_sorted = sorted(a)
    c_sorted = sorted(c)

    for n in b:
        ab = 0
        bc = 0
        for i in a_sorted:
            if n > i:
                ab += 1

        for i in c_sorted:
            if n < i:
                bc += 1

        count += ab * bc
    return count
        
if __name__ == "__main__":
    n = int(input())
    a = list(map(int,input().split()))
    b = list(map(int,input().split()))
    c = list(map(int,input().split()))

    print(snuke_festival(a,b,c))


Fixed submission:
import sys
input = sys.stdin.readline
import bisect
    
def snuke_festival(a,b,c):
    count = 0
    a_sorted = sorted(a)
    b_sorted = sorted(b)
    c_sorted = sorted(c)
    maxlen=len(b)

    for target in b_sorted:
        #mid_a = binary_search_left(a_sorted,target)
        #mid_c = binary_search_right(c_sorted,target)
        mid_a = bisect.bisect_left(a_sorted,target)
        mid_c = bisect.bisect_right(c_sorted,target)
        count += mid_a * (maxlen - mid_c)
        #print("mid_a %d, mid_c %d, count %d" %(mid_a,maxlen - mid_c,count))
    return count

if __name__ == "__main__":
    n = int(input())
    a = list(map(int,input().split()))
    b = list(map(int,input().split()))
    c = list(map(int,input().split()))

    print(snuke_festival(a,b,c))

Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = sys.stdin.readline
import itertools

def is_saidan(parts):
    tmp = 0
    for j in parts:
        if j > tmp:
            tmp = j
        else:
            break
    else:
        return True
    return False

def snuke_festival(a,b,c):
    comb = list(itertools.product(a,b,c))
    count = 0
    for i in comb:
        if is_saidan(i):
            count += 1
    return count
        
if __name__ == "__main__":
    n = int(input())
    a = list(map(int,input().split()))
    b = list(map(int,input().split()))
    c = list(map(int,input().split()))

    print(snuke_festival(a,b,c))


Fixed submission:
import sys
input = sys.stdin.readline
import bisect
    
def snuke_festival(a,b,c):
    count = 0
    a_sorted = sorted(a)
    b_sorted = sorted(b)
    c_sorted = sorted(c)
    maxlen=len(b)

    for target in b_sorted:
        #mid_a = binary_search_left(a_sorted,target)
        #mid_c = binary_search_right(c_sorted,target)
        mid_a = bisect.bisect_left(a_sorted,target)
        mid_c = bisect.bisect_right(c_sorted,target)
        count += mid_a * (maxlen - mid_c)
        #print("mid_a %d, mid_c %d, count %d" %(mid_a,maxlen - mid_c,count))
    return count

if __name__ == "__main__":
    n = int(input())
    a = list(map(int,input().split()))
    b = list(map(int,input().split()))
    c = list(map(int,input().split()))

    print(snuke_festival(a,b,c))