def binom(n, r):
    """
    Returns the binomial coefficient as a long integer.
    """
    if n < 0 or r < 0 or n < r:
        raise RuntimeError('bad binom() arguments')
    c = 1
    denom = 1
    for num, denom in zip(range(n, n - r, -1), range(1, r + 1, 1)):
        c = c * num // denom
    return c
