input: Write a function to calculate the maximum possible revenue from the items with given weights and values using the knapsack algorithm. The function should take in the list of weights, the list of values, and the number of items as inputs, and return the maximum revenue. If the inputs are invalid or empty, return 0.
  assert knapsack([2, 1, 3], [4, 2, 3], 3)==7
  assert knapsack([1, 2, 3], [4, 2, 3], 3)==5
  assert knapsack([], [], 0)==0
  assert knapsack([1, 2], [4, 2], 2)==6
  assert knapsack([1, 2, 3, 4], [2, 3, 4, 5], 4)==7
output: def knapsack(weights, values, n):
      if not weights or not values or n == 0:
          return 0
      capacity = sum(weights)
      dp = [0] * (capacity + 1)
      for i in range(n):
          for w in range(capacity, weights[i] - 1, -1):
              dp[w] = max(dp[w], dp[w - weights[i]] + values[i])
      return dp[capacity]