code: def nth_combination(iterable, r, index):
      """Equivalent to ``list(combinations(iterable, r))[index]``.
  
      The subsequences of *iterable* that are of length *r* can be ordered
      lexicographically. :func:`nth_combination` computes the subsequence at
      sort position *index* directly, without computing the previous
      subsequences.
  
          >>> nth_combination(range(5), 3, 5)
          (0, 3, 4)
  
      ``ValueError`` will be raised If *r* is negative or greater than the length
      of *iterable*.
      ``IndexError`` will be raised if the given *index* is invalid.
      """
      pool = tuple(iterable)
      n = len(pool)
      if (r < 0) or (r > n):
          raise ValueError
  
      c = 1
      k = min(r, n - r)
      for i in range(1, k + 1):
          c = c * (n - k + i) // i
  
      if index < 0:
          index += c
  
      if (index < 0) or (index >= c):
          raise IndexError
  
      result = []
      while r:
          c, n, r = c * r // n, n - 1, r - 1
          while index >= c:
              index -= c
              c, n = c * (n - r) // n, n - 1
          result.append(pool[-1 - n])
  
      return tuple(result)
  
imports: import math
  import operator
  from collections import deque
  from collections.abc import Sized
  from functools import partial, reduce
  from itertools import chain, combinations, compress, count, cycle, groupby, islice, product, repeat, starmap, tee, zip_longest
  from random import randrange, sample, choice
label_desc: Use image node_id 28 for calling a global function with example usage: nth_combination(iterable, r, index) and returns: tuple