input: Write a function to implement an algorithm that merges two sorted lists A and B. The algorithm should compare the first elements of both lists and add the smaller element to the result list. This process should continue until all elements from both lists are added to the result list. If the given lists are not sorted, the function should return None.
  
  def merge_sort(A, B):
   if not all(A[i] <= A[i+1] for i in range(len(A)-1)) or not all(B[i] <= B[i+1] for i in range(len(B)-1)):
   return None
   result = []
   i, j = 0, 0
   while i < len(A) and j < len(B):
   if A[i] < B[j]:
   result.append(A[i])
   i += 1
   else:
   result.append(B[j])
   j += 1
   result += A[i:]
   result += B[j:]
   return result
  
  assert merge_sort([3, 6, 8, 10, 11], [2, 5, 7, 12])==[2, 3, 5, 6, 7, 8, 10, 11, 12]
  assert merge_sort([1, 3, 5], [2, 4, 6])==[1, 2, 3, 4, 5, 6]
  assert merge_sort([5, 3, 1], [6, 4, 2])==None
  assert merge_sort([1, 2, 3], [])==[1, 2, 3]
  assert merge_sort([], [1, 2, 3])==[1, 2, 3]
output: def merge_sort(A, B):
      if not all(A[i] <= A[i+1] for i in range(len(A)-1)) or not all(B[i] <= B[i+1] for i in range(len(B)-1)):
          return None
      result = []
      i, j = 0, 0
      while i < len(A) and j < len(B):
          if A[i] < B[j]:
              result.append(A[i])
              i += 1
          else:
              result.append(B[j])
              j += 1
      result += A[i:]
      result += B[j:]
      return result