def GetCost(term):
  """Calculate the cost of a term.

  Quota is charged based on how complex the rules are rather than simply
  limiting the number of rules.

  A firewall rule tuple is the unique combination of IP range, protocol, and
  port defined as a matching condition in a firewall rule. And the cost of a
  firewall rule tuple is the total number of elements within it.

  Args:
    term: A Term object.

  Returns:
    int: The cost of the term.
  """
  protocols = len(term.protocol) or 1
  ports = len(term.destination_port) or 1

  if term.destination_address:
    addresses = len(term.destination_address) or 1
  else:
    addresses = len(term.source_address) or 1

  return addresses * protocols * ports