def max_slice(array):
  """
  Returns the maximal sum of a slice of array (empty slices are also considered).
  """

  max_ending = max_slice = 0
  for a in array:
    max_ending = max(0, max_ending + a)
    max_slice = max(max_slice, max_ending)
  return max_slice