def choose(n,r):
    """
    number of combinations of n things taken r at a time (order unimportant)
    """
    if (n < r):
        return 0
    if (n == r):
        return 1
    s = min(r, (n - r))
    t = n
    a = n-1
    b = 2
    while b <= s:
        t = (t*a)//b
        a -= 1
        b += 1
    return t