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.
  
      """
      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: from collections import deque
  from itertools import chain, combinations, count, cycle, groupby, islice, repeat, starmap, tee
  import operator
  from random import randrange, sample, choice
  from six import PY2
  from six.moves import filter, filterfalse, map, range, zip, zip_longest
label_desc: Use image node_id 27 for calling a global function with example usage: nth_combination(iterable, r, index) and returns: tuple