def count_slope_inversions(ys):
  """Count how many times the slope changes sign."""
  num_inversions = 0
  for a, b, c in zip(ys[:-2], ys[1:-1], ys[2:]):
    if (b - a) * (c - b) < 0:
      num_inversions += 1
  return num_inversions