code: def longest_monotonic_subseq_length(xs):
      '''Return the length of the longest monotonic subsequence of xs, second
      return value is the difference between increasing and decreasing lengths.
  
      >>> longest_monotonic_subseq_length((4, 5, 1, 2, 3))
      (3, 1)
      >>> longest_monotonic_subseq_length((1, 2, 3, 5, 4))
      (4, 2)
      >>> longest_monotonic_subseq_length((1, 2, 1))
      (2, 0)
      '''
      li = longest_increasing_subseq_length(xs)
      ld = longest_decreasing_subseq_length(xs)
      return max(li, ld), li - lf longest_monotonic_subseq_length(xs):
      '''Return the length of the longest monotonic subsequence of xs, second
      return value is the difference between increasing and decreasing lengths.
  
      >>> longest_monotonic_subseq_length((4, 5, 1, 2, 3))
      (3, 1)
      >>> longest_monotonic_subseq_length((1, 2, 3, 5, 4))
      (4, 2)
      >>> longest_monotonic_subseq_length((1, 2, 1))
      (2, 0)
      '''
      li = longest_increasing_subseq_length(xs)
      ld = longest_decreasing_subseq_length(xs)
      return max(li, ld), li - ld
docs: Return the length of the longest monotonic subsequence of xs, second
      return value is the difference between increasing and decreasing lengths.
  
      >>> longest_monotonic_subseq_length((4, 5, 1, 2, 3))
      (3, 1)
      >>> longest_monotonic_subseq_length((1, 2, 3, 5, 4))
      (4, 2)
      >>> longest_monotonic_subseq_length((1, 2, 1))
      (2, 0)