code: def _yield_subset_of_sequences_with_fixed_number_of_items(
      sequences, n_items
  ):
      assert n_items > 0
      stack = list(reversed(sequences))
      while stack:
          subset = []
          count = 0
          while count < n_items:
              sequence = stack.pop()
              subset.append(sequence)
              count += len(sequence)
          if count > n_items:
              # Split last sequence
              sequence_to_split = subset[-1]
              n_exceeds = count - n_items
              assert n_exceeds > 0
              subset[-1] = sequence_to_split[:-n_exceeds]
              stack.append(sequence_to_split[-n_exceeds:])
          assert sum(len(seq) for seq in subset) == n_items
          yield subset
  
imports: import collections
  import itertools
  import random
  import chainer
  from chainer import cuda
  import chainer.functions
  import numpy
  from chainerrl import agent
  from chainerrl.misc.batch_states import batch_states
label_desc: Use image node_id 8 for calling a global function with example usage: _yield_subset_of_sequences_with_fixed_number_of_items(sequences, n_items) without return types