code: def max_sum(a):
      
  
      max_sum, max_start_index, max_end_index = -Infinity, 0, 0
      current_max_sum = 0
      current_start_index = 0
      for current_end_index, x in enumerate(a):
          current_max_sum += x
          if current_max_sum > max_sum:
              max_sum, max_start_index, max_end_index = current_max_sum, \
                  current_start_index, current_end_index
          if current_max_sum < 0:
              current_max_sum = 0
              current_start_index = current_end_index + 1
  
      return max_sum, max_start_index, max_end_index
docs: For an input array a, output the range that gives the largest sum
  
      >>> max_sum([4, 4, 9, -5, -6, -1, 5, -6, -8, 9])
      (17, 0, 2)
      >>> max_sum([8, -10, 10, -9, -6, 9, -7, -4, -10, -8])
      (10, 2, 2)
      >>> max_sum([10, 1, -10, -8, 6, 10, -10, 6, -3, 10])
      (19, 4, 9)