code: def _write(
      index_left: int,
      index_right: int,
      node: Node,
      key: int,
      value: Optional[V],
      op: Aggregator,
  ) -> Optional[V]:
      if index_right - index_left == 1:
          if node:
              ret = node[2]
          else:
              ret = None
          if value is None:
              del node[:]
          else:
              node[:] = None, None, value
      else:
          _expand(node)
          node_left, node_right, _ = node
          index_center = (index_left + index_right) // 2
          if key < index_center:
              ret = _write(
                  index_left, index_center, node_left, key, value, op
              )
          else:
              ret = _write(
                  index_center, index_right, node_right, key, value, op
              )
          _reduce(node, op)
      return ret
  
imports: import collections
  from typing import Any, Callable, Deque, Generic, List, Optional, Sequence, Tuple, TypeVar
  import numpy
  from pfrl.utils.random import sample_n_k
label_desc: Use image node_id 3 for calling a global function with example usage: _write(index_left, index_right, node, key, value, op) and returns: ret