Buggy python submission (verdict: Time Limit Exceeded):

import bisect

N = int(input())
A = sorted(map(int, input().split()))
B = sorted(map(int, input().split()))
C = sorted(map(int, input().split()))

ans = 0
for second in B:
    idx = bisect.bisect_left(A, second)
    first = len(A[:idx])

    idx = bisect.bisect_right(C, second)
    third = len(C[idx:])

    ans += (first*third)

print(ans)


Fixed submission:

import bisect

N = int(input())
A = sorted(map(int, input().split()))
B = map(int, input().split())
C = sorted(map(int, input().split()))

ans = 0
for second in B:
    ai = bisect.bisect_left(A, second)
    ci = bisect.bisect_right(C, second)

    ans += (ai*(N-ci))

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):

import bisect

N = int(input())
A = sorted(map(int, input().split()))
B = sorted(map(int, input().split()))
C = sorted(map(int, input().split()))

ans = 0
for second in B:
    idx = bisect.bisect_left(A, second)
    first = len(A[:idx])

    idx = bisect.bisect_right(C, second)
    third = len(C[idx:])

    ans += (first*third)

print(ans)


Fixed submission:

import bisect

N = int(input())
A = sorted(map(int, input().split()))
B = map(int, input().split())
C = sorted(map(int, input().split()))

ans = 0
for second in B:
    ai = bisect.bisect_left(A, second)
    ci = bisect.bisect_right(C, second)

    ans += (ai*(N-ci))

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):

import bisect

N = int(input())
A = sorted(map(int, input().split()))
B = sorted(map(int, input().split()))
C = sorted(map(int, input().split()))

count = 0
for first in A:
    idx = bisect.bisect_right(B, first)
    seconds = B[idx:]

    for second in seconds:
        idx = bisect.bisect_right(C, second)
        thirds = C[idx:]

        count += len(thirds)

print(count)

Fixed submission:

import bisect

N = int(input())
A = sorted(map(int, input().split()))
B = map(int, input().split())
C = sorted(map(int, input().split()))

ans = 0
for second in B:
    ai = bisect.bisect_left(A, second)
    ci = bisect.bisect_right(C, second)

    ans += (ai*(N-ci))

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):

import bisect

N = int(input())
A = sorted(map(int, input().split()))
B = sorted(map(int, input().split()))
C = sorted(map(int, input().split()))

count = 0
for first in A:
    idx = bisect.bisect_right(B, first)
    len_b = len(B)+1
    if idx == len_b and B[len_b-1] <= first:
        continue

    seconds = B[idx:]

    for second in seconds:
        idx = bisect.bisect_right(C, second)
        len_c = len(C)+1
        if idx == len_c and C[len_c-1] <= second:
            continue

        thirds = C[idx:]

        for third in thirds:
            count += 1


print(count)

Fixed submission:

import bisect

N = int(input())
A = sorted(map(int, input().split()))
B = map(int, input().split())
C = sorted(map(int, input().split()))

ans = 0
for second in B:
    ai = bisect.bisect_left(A, second)
    ci = bisect.bisect_right(C, second)

    ans += (ai*(N-ci))

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):

import bisect

N = int(input())
A = sorted(map(int, input().split()))
B = sorted(map(int, input().split()))
C = sorted(map(int, input().split()))

count = 0
for first in A:
    idx = bisect.bisect_left(B, first)
    seconds = B[idx:]

    for second in seconds:
        if first >= second:
            continue

        idx = bisect.bisect_left(C, second)
        thirds = C[idx:]

        for third in thirds:
            if second >= third:
                continue

            count += 1


print(count)

Fixed submission:

import bisect

N = int(input())
A = sorted(map(int, input().split()))
B = map(int, input().split())
C = sorted(map(int, input().split()))

ans = 0
for second in B:
    ai = bisect.bisect_left(A, second)
    ci = bisect.bisect_right(C, second)

    ans += (ai*(N-ci))

print(ans)