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

N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))
B.sort()
C.sort()
cnt = 0
for a in A:
  pos_b = bisect.bisect_right(B, a)
  for pb in range(pos_b, N):
    pos_c = bisect.bisect_right(C, B[pb])
    cnt += N-pos_c
    if pos_c == N-1:
      break
print(cnt)

Fixed submission:
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))

nums = []
for idx in range(N):
  nums.append((1, A[idx]))
  nums.append((2, B[idx]))
  nums.append((3, C[idx]))
nums.sort(key=lambda x:(x[1], -x[0]))
sum_a = 0
sum_b = 0
sum_c = 0
for idx in range(3*N):
  if nums[idx][0] == 1:
    sum_a += 1
  elif nums[idx][0] == 2:
    sum_b += sum_a
  elif nums[idx][0] == 3:
    sum_c += sum_b
print(sum_c)

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

N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))
A.sort()
B.sort()
C.sort()
cnt = 0
for a in A:
  pos_b = bisect.bisect_right(B, a)
  for pb in range(pos_b, N):
    pos_c = bisect.bisect_right(C, B[pb])
    cnt += N-pos_c
print(cnt)


Fixed submission:
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))

nums = []
for idx in range(N):
  nums.append((1, A[idx]))
  nums.append((2, B[idx]))
  nums.append((3, C[idx]))
nums.sort(key=lambda x:(x[1], -x[0]))
sum_a = 0
sum_b = 0
sum_c = 0
for idx in range(3*N):
  if nums[idx][0] == 1:
    sum_a += 1
  elif nums[idx][0] == 2:
    sum_b += sum_a
  elif nums[idx][0] == 3:
    sum_c += sum_b
print(sum_c)

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

N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))
A.sort()
B.sort()
C.sort()
cnt = 0
for a in A:
  pos_b = bisect.bisect_right(B, a)
  for pb in range(pos_b, N):
    pos_c = bisect.bisect_right(C, B[pb])
    cnt += N-pos_c
print(cnt)

Fixed submission:
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))

nums = []
for idx in range(N):
  nums.append((1, A[idx]))
  nums.append((2, B[idx]))
  nums.append((3, C[idx]))
nums.sort(key=lambda x:(x[1], -x[0]))
sum_a = 0
sum_b = 0
sum_c = 0
for idx in range(3*N):
  if nums[idx][0] == 1:
    sum_a += 1
  elif nums[idx][0] == 2:
    sum_b += sum_a
  elif nums[idx][0] == 3:
    sum_c += sum_b
print(sum_c)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))
A.sort()
B.sort()
C.sort()

b_ptn = [0] * (N)
for idx, b in enumerate(B):
  cnt = 0
  for a in A:
    if a < b:
      cnt += 1
    else:
      break
  b_ptn[idx] = cnt
ans = 0
for c in C:
  for idx, b in enumerate(B):
    if b >= c:
      break
    if idx == N-1:
      ans += b_ptn[idx]
      break
    ans += b_ptn[idx]
print(ans)


Fixed submission:
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))

nums = []
for idx in range(N):
  nums.append((1, A[idx]))
  nums.append((2, B[idx]))
  nums.append((3, C[idx]))
nums.sort(key=lambda x:(x[1], -x[0]))
sum_a = 0
sum_b = 0
sum_c = 0
for idx in range(3*N):
  if nums[idx][0] == 1:
    sum_a += 1
  elif nums[idx][0] == 2:
    sum_b += sum_a
  elif nums[idx][0] == 3:
    sum_c += sum_b
print(sum_c)