r"""
Python module for OEIS sequence number A126257.

Number of distinct new terms in row n of Pascal's triangle.

Examples of use.
-----------------------------------------------------------------------
>>> from a126257 import *
>>> print a126257_list(18)
[1, 0, 1, 1, 2, 2, 2, 3, 4, 4, 4, 5, 6, 6, 7, 5, 7, 8]
>>> print a126257_offset
0
>>> for x in a126257_list_pairs(6):
...     print x
...
(0, 1)
(1, 0)
(2, 1)
(3, 1)
(4, 2)
(5, 2)
>>> print a126257(7)
3
-----------------------------------------------------------------------
"""

from itertools import islice, izip, count

__all__ = ('a126257_offset', 'a126257_list', 'a126257_list_pairs', 'a126257', 'a126257_gen')
__author__ = 'Nick Hobson <nickh@qbyte.org>'

a126257_offset = offset = 0

def a126257_gen():
    """Generator function for OEIS sequence A126257."""
    s = set([1])
    yield len(s)
    for row in count(1):
        last = len(s)
        x = row
        s.add(x)
        for m in xrange(1, row//2 + 1):
            x = (x * (row - m)) / (m + 1)
            s.add(x)
        yield len(s) - last

def a126257_list(n):
    """Returns a list of the first n >= 0 terms."""
    if n < 0: raise ValueError, 'Input must be a non-negative integer'
    return list(islice(a126257_gen(), n))

def a126257_list_pairs(n):
    """Returns a list of tuples (n, a(n)) of the first n >= 0 terms."""
    if n < 0: raise ValueError, 'Input must be a non-negative integer'
    return list(izip(xrange(offset, n+offset), a126257_gen()))

def a126257(n):
    """Returns the term with index n >= 0; offset 0."""
    if n < offset: raise ValueError, 'Input must be an integer >= offset = ' + str(offset)
    return list(islice(a126257_gen(), n-offset, n-offset+1)).pop()