def farey(n):
    """
    Generates the Farey sequence of maximum denominator n.  Includes 0/1 & 1/1.
    Code shamelessly stolen from Wikipedia.
    Input: n -- a positive integer
    Output: Sequence of lists of the form [integer, integer]
    Examples:
    >>> list(farey(5))
    [(0, 1), (1, 5), (1, 4), (1, 3), (2, 5), (1, 2), (3, 5), (2, 3), (3, 4), (4, 5), (1, 1)]
    """
    a, b, c, d = 0, 1, 1, n
    yield a, b
    while c <= n:
        k = (n + b) // d
        a, b, c, d = c, d, k * c - a, k * d - b
        yield a, b
