input: Write a function to count the number of pairs with a given sum x from a list of numbers. The function should iterate through the list and check pairs of numbers to see if their sum equals x. If a pair is found, increment the count and move to the next pair. If the sum is less than x, move to the next number from the start of the list. If the sum is greater than x, move to the previous number from the end of the list. If the list is empty, return 0.
  
  def count_pairs(numbers, x):
      count = 0
      i, j = 0, len(numbers) - 1
      while i < j: 
          sum = numbers[i] + numbers[j]
          if sum == x: 
              count += 1
              i += 1
          elif sum < x: 
              i += 1 
          else: 
              j -= 1
      return count
  
  assert count_pairs([1, 2, 3, 4, 5], 7) == 2
  assert count_pairs([1, 2, 3, 4, 5], 5) == 2
  assert count_pairs([10, 20, 30, 40], 50) == 2
  assert count_pairs([1, 3, 5, 7], 10) == 1
  assert count_pairs([], 5) == 0
output: def count_pairs(numbers, x):
      count = 0
      i, j = 0, len(numbers) - 1
      while i < j: 
          sum = numbers[i] + numbers[j]
          if sum == x: 
              count += 1
              i += 1
          elif sum < x: 
              i += 1 
          else: 
              j -= 1
      return count