def combinations(iterable, r):
    pool = tuple(iterable)
    n = len(pool)
    if (r > n):
        return
    indices = lrange(r)
    (yield tuple((pool[i] for i in indices)))
    while True:
        for i in reversed(lrange(r)):
            if (indices[i] != ((i + n) - r)):
                break
        else:
            return
        indices[i] += 1
        for j in range((i + 1), r):
            indices[j] = (indices[(j - 1)] + 1)
        (yield tuple((pool[i] for i in indices)))
def combinations(iterable, r):
    pool = tuple(iterable)
    n = len(pool)
    if (r > n):
        return
    indices = lrange(r)
    (yield tuple((pool[i] for i in indices)))
    while True:
        for i in reversed(lrange(r)):
            if (indices[i] != ((i + n) - r)):
                break
        else:
            return
        indices[i] += 1
        for j in range((i + 1), r):
            indices[j] = (indices[(j - 1)] + 1)
        (yield tuple((pool[i] for i in indices)))