Problem p03557 (python)

Fixed submission:
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()
C.sort()
d=0
for i in B:
 d+=bisect.bisect_right(A,i-0.1)*(N-bisect.bisect_left(C,i+0.1))
print(d)

Buggy submission (verdict: Runtime Error):
def quick_sort(arr):
 left = []
 right = []
 if len(arr) <= 1:
  return arr
 ref = arr[0]
 ref_count = 0
 for ele in arr:
  if ele < ref:
   left.append(ele)
  elif ele > ref:
   right.append(ele)
  else:
   ref_count += 1
 left = quick_sort(left)
 right = quick_sort(right)
 return left + [ref] * ref_count + right

def binary_search1(list,target):
 result = -1
 left = 0
 right = len(list) - 1
 while left <= right:
  center = (left + right)//2
  if list[center] >= target:
   if list[center-1] < target:
    result = center
    break
   else: right = center - 1
  elif list[center] < target:
   if center==N-1:
    result = N
    break
   else:
    left = center + 1
 if result == -1:
  return 0
 else:
  return str(result)

def binary_search2(list,target):
 result = -1
 left = 0
 right = len(list) - 1
 while left <= right:
  center = (left + right)//2
  if list[center] <= target:
   if list[center+1] > target:
    result = N-center-1
    break
   else:  left = center + 1
  elif list[center] > target:
   if center==0:
    result = N-center
    break
   else:
    right =center - 1
 if result == -1:
  return 0
 else:
  return str(result)

N=int(input())
A=list(map(int,input().split()))
B=list(map(int,input().split()))
C=list(map(int,input().split()))
A=quick_sort(A)
C=quick_sort(C)
K=0
for i in range(N):
 L=int(binary_search1(A,B[i]))
 M=int(binary_search2(C,B[i]))
 K+=L*M
print(K)

Buggy submission (verdict: Runtime Error):
def quick_sort(arr):
 left = []
 right = []
 if len(arr) <= 1:
  return arr
 ref = arr[0]
 ref_count = 0
 for ele in arr:
  if ele < ref:
   left.append(ele)
  elif ele > ref:
   right.append(ele)
  else:
   ref_count += 1
 left = quick_sort(left)
 right = quick_sort(right)
 return left + [ref] * ref_count + right

def binary_search1(list,target):
 result = -1
 left = 0
 right = len(list) - 1
 while left <= right:
  center = (left + right)//2
  if list[center] >= target:
   if list[center-1] < target:
    result = center
    break
   else: right = center - 1
  elif list[center] < target:
   if center==N-1:
    result = N
    break
   else:
    left = center + 1
 if result == -1:
  return 0
 else:
  return str(result)

def binary_search2(list,target):
 result = -1
 left = 0
 right = len(list) - 1
 while left <= right:
  center = (left + right)//2
  if list[center] <= target:
   if list[center+1] > target:
    result = N-center-1
    break
   else:  left = center + 1
  elif list[center] > target:
   if center==0:
    result = N-center
    break
   else:
    right =center - 1
 if result == -1:
  return 0
 else:
  return str(result)

N=int(input())
A=list(map(int,input().split()))
B=list(map(int,input().split()))
C=list(map(int,input().split()))
A=quick_sort(A)
C=quick_sort(C)
K=0
for i in range(N):
 L=int(binary_search1(A,B[i]))
 M=int(binary_search2(C,B[i]))
 K+=L*M
print(K)

Buggy submission (verdict: Runtime Error):
import os
import statistics

def quick_sort(arr):
 left = []
 right = []
 if len(arr) <= 1:
  return arr
 ref = arr[0]
 ref_count = 0
 for ele in arr:
  if ele < ref:
   left.append(ele)
  elif ele > ref:
   right.append(ele)
  else:
   ref_count += 1
 left = quick_sort(left)
 right = quick_sort(right)
 return left + [ref] * ref_count + right

def binary_search1(list,target):
 result = -1
 left = 0
 right = len(list) - 1
 while left <= right:
  center = (left + right)//2
  if list[center] >= target:
   if list[center-1] < target:
    result = center
    break
   else: right = center - 1
  elif list[center] < target:
   if center==N-1:
    result = N
    break
   else:
    left = center + 1
 if result == -1:
  return 0
 else:
  return str(result)

def binary_search2(list,target):
 result = -1
 left = 0
 right = len(list) - 1
 while left <= right:
  center = (left + right)//2
  if list[center] <= target:
   if list[center+1] > target:
    result = N-center-1
    break
   else:  left = center + 1
  elif list[center] > target:
   if center==0:
    result = N-center
    break
   else:
    right =center - 1
 if result == -1:
  return 0
 else:
  return str(result)

N=int(input())
A=list(map(int,input().split()))
B=list(map(int,input().split()))
C=list(map(int,input().split()))
A=quick_sort(A)
C=quick_sort(C)
K=0
for i in range(N):
 L=int(binary_search1(A,B[i]))
 M=int(binary_search2(C,B[i]))
 K+=L*M
print(K)

Buggy submission (verdict: Runtime Error):
import os
import statistics

def quickSort(arr):
  left = []
  right = []
  if len(arr) <= 1:
   return arr
  median = int(statistics.median(arr))
  medianFlg = 0
  for element in arr:
   if element < median:
    left.append(element)
   elif element > median:
    right.append(element)
   else:
    medianFlg += 1
  left = quickSort(left)
  right = quickSort(right)
  return left + [median] * medianFlg + right

def binary_search1(list,target):
 result = -1
 left = 0
 right = len(list) - 1
 while left <= right:
  center = (left + right)//2
  if list[center] >= target:
   if list[center-1] < target:
    result = center
    break
   else: right = center - 1
  elif list[center] < target:
   if center==N-1:
    result = N
    break
   else:
    left = center + 1
 if result == -1:
  return 0
 else:
  return str(result)

def binary_search2(list,target):
 result = -1
 left = 0
 right = len(list) - 1
 while left <= right:
  center = (left + right)//2
  if list[center] <= target:
   if list[center+1] > target:
    result = N-center-1
    break
   else:  left = center + 1
  elif list[center] > target:
   if center==0:
    result = N-center
    break
   else:
    right =center - 1
 if result == -1:
  return 0
 else:
  return str(result)

N=int(input())
A=list(map(int,input().split()))
B=list(map(int,input().split()))
C=list(map(int,input().split()))
A=quickSort(A)
C=quickSort(C)
K=0
for i in range(N):
 L=int(binary_search1(A,B[i]))
 M=int(binary_search2(C,B[i]))
 K+=L*M
print(K)

Buggy submission (verdict: Runtime Error):
import os
import statistics

def quickSort(arr):
  left = []
  right = []
  if len(arr) <= 1:
   return arr
  median = int(statistics.median(arr))
  medianFlg = 0
  for element in arr:
   if element < median:
    left.append(element)
   elif element > median:
    right.append(element)
   else:
    medianFlg += 1
  left = quickSort(left)
  right = quickSort(right)
  return left + [median] * medianFlg + right

def binary_search1(list,target):
 result = -1
 left = 0
 right = len(list) - 1
 while left <= right:
  center = (left + right)//2
  if list[center] >= target:
   if list[center-1] < target:
    result = center
    break
   else: right = center - 1
  elif list[center] < target:
   if center==N-1:
    result = N
    break
   else:
    left = center + 1
 if result == -1:
  return 0
 else:
  return str(result)

def binary_search2(list,target):
 result = -1
 left = 0
 right = len(list) - 1
 while left <= right:
  center = (left + right)//2
  if list[center] <= target:
   if list[center+1] > target:
    result = N-center-1
    break
   else:  left = center + 1
  elif list[center] > target:
   if center==0:
    result = N-center
    break
   else:
    right =center - 1
 if result == -1:
  return 0
 else:
  return str(result)

N=int(input())
A=list(map(int,input().split()))
B=list(map(int,input().split()))
C=list(map(int,input().split()))
A=quickSort(A)
C=quickSort(C)
K=0
for i in range(N):
 L=int(binary_search1(A,B[i]))
 M=int(binary_search2(C,B[i]))
 K+=L*M
print(K)

Buggy submission (verdict: Runtime Error):
import os
import statistics

def quickSort(arr):
  left = []
  right = []
  if len(arr) <= 1:
   return arr
  median = int(statistics.median(arr))
  medianFlg = 0
  for element in arr:
   if element < median:
    left.append(element)
   elif element > median:
    right.append(element)
   else:
    medianFlg += 1
  left = quickSort(left)
  right = quickSort(right)
  return left + [median] * medianFlg + right

def binary_search1(list,target):
 result = -1
 left = 0
 right = len(list) - 1
 while left <= right:
  center = (left + right)//2
  if list[center] >= target:
   if list[center-1] < target:
    result = center
    break
   else: right = center - 1
  elif list[center] < target:
   if center==N-1:
    result = N
    break
   else:
    left = center + 1
 if result == -1:
  return 0
 else:
  return str(result)

def binary_search2(list,target):
 result = -1
 left = 0
 right = len(list) - 1
 while left <= right:
  center = (left + right)//2
  if list[center] <= target:
   if list[center+1] > target:
    result = N-center-1
    break
   else:  left = center + 1
  elif list[center] > target:
   if center==0:
    result = N-center
    break
   else:
    right =center - 1
 if result == -1:
  return 0
 else:
  return str(result)

N=int(input())
A=list(map(int,input().split()))
B=list(map(int,input().split()))
C=list(map(int,input().split()))
A=quickSort(A)
C=quickSort(C)
K=0
for i in range(N):
 L=int(binary_search1(A,B[i]))
 M=int(binary_search2(C,B[i]))
 K+=L*M
print(K)