code: def ndependencies(
      dependencies: Mapping[Key, set[Key]],
      dependents: Mapping[Key, set[Key]],
  ) -> tuple[dict[Key, int], dict[Key, int]]:
      """Number of total data elements on which this key depends
  
      For each key we return the number of tasks that must be run for us to run
      this task.
  
      Examples
      --------
      >>> inc = lambda x: x + 1
      >>> dsk = {'a': 1, 'b': (inc, 'a'), 'c': (inc, 'b')}
      >>> dependencies, dependents = get_deps(dsk)
      >>> num_dependencies, total_dependencies = ndependencies(dependencies, dependents)
      >>> sorted(total_dependencies.items())
      [('a', 1), ('b', 2), ('c', 3)]
  
      Returns
      -------
      num_dependencies: Dict[key, int]
      total_dependencies: Dict[key, int]
      """
      num_needed = {}
      result = {}
      for k, v in dependencies.items():
          num_needed[k] = len(v)
          if not v:
              result[k] = 1
  
      num_dependencies = num_needed.copy()
      current: list[Key] = []
      current_pop = current.pop
      current_append = current.append
  
      for key in result:
          for parent in dependents[key]:
              num_needed[parent] -= 1
              if not num_needed[parent]:
                  current_append(parent)
      while current:
          key = current_pop()
          result[key] = 1 + sum(
              result[child] for child in dependencies[key]
          )
          for parent in dependents[key]:
              num_needed[parent] -= 1
              if not num_needed[parent]:
                  current_append(parent)
      return num_dependencies, result
  
file_path: dask/dask/order.py
imports: from __future__ import annotations
  import copy
  from collections import defaultdict, deque, namedtuple
  from collections.abc import Iterable, Mapping, MutableMapping
  from typing import Any, Callable, Literal, NamedTuple, overload
  from dask.core import get_dependencies, get_deps, getcycle, istask, reverse_dict
  from dask.typing import Key
label_desc: Use image node_id 5 for calling a global function with example usage: ndependencies(dependencies, dependents) and returns: num_dependencies,  result