def duplicate(seq):
    """ Find first duplicate element.
    """
    seen = set()
    for n in seq:
        if n in seen:
            return n
        else:
            seen.add(n)
    raise ValueError('Not found')
