code: def distribute_subs_contraction(arg, subs):
      new_terms = tuple(
          Subs(
              v,
              tuple(
                  (name, sub) for name, sub in subs if name in v.inputs
              ),
          )
          if any(name in v.inputs for name, sub in subs)
          else v
          for v in arg.terms
      )
      return Contraction(
          arg.red_op, arg.bin_op, arg.reduced_vars, *new_terms
      )
  
imports: import functools
  import itertools
  from collections import Counter, OrderedDict, defaultdict
  from functools import reduce
  from typing import Tuple, Union
  import opt_einsum
  import funsor
  import funsor.ops
  from funsor.affine import affine_inputs
  from funsor.delta import Delta
  from funsor.domains import find_domain
  from funsor.gaussian import Gaussian
  from funsor.interpretations import eager, normalize, reflect
  from funsor.interpreter import children
  from funsor.ops import DISTRIBUTIVE_OPS, AssociativeOp, NullOp
  from funsor.tensor import Tensor
  from funsor.terms import _INFIX, Align, Binary, Funsor, Number, Reduce, Subs, Unary, Variable, to_funsor
  from funsor.typing import Variadic
  from funsor.util import broadcast_shape, get_backend, quote
label_desc: Use image node_id 23 for calling a global function with example usage: distribute_subs_contraction(arg, subs) and returns: Contraction