'Constructor for the Permutation object from a list or a
list of lists in which all elements of the permutation may
appear only once.
Examples
>>> from sympy.combinatorics.permutations import Permutation
>>> Permutation.print_cyclic = False
Permutations entered in array-form are left unaltered:
>>> Permutation([0, 2, 1])
Permutation([0, 2, 1])
Permutations entered in cyclic form are converted to array form;
singletons need not be entered, but can be entered to indicate the
largest element:
>>> Permutation([[4, 5, 6], [0, 1]])
Permutation([1, 0, 2, 3, 5, 6, 4])
>>> Permutation([[4, 5, 6], [0, 1], [19]])
Permutation([1, 0, 2, 3, 5, 6, 4], size=20)
All manipulation of permutations assumes that the smallest element
is 0 (in keeping with 0-based indexing in Python) so if the 0 is
missing when entering a permutation in array form, an error will be
raised:
>>> Permutation([2, 1])
Traceback (most recent call last):
ValueError: Integers 0 through 2 must be present.
If a permutation is entered in cyclic form, it can be entered without
singletons and the ``size`` specified so those values can be filled
in, otherwise the array form will only extend to the maximum value
in the cycles:
>>> Permutation([[1, 4], [3, 5, 2]], size=10)
Permutation([0, 4, 3, 5, 1, 2], size=10)
>>> _.array_form
[0, 4, 3, 5, 1, 2, 6, 7, 8, 9]'

def __new__(cls, *args, **kwargs):

    size = kwargs.pop('size', None)
    if (size is not None):
        size = int(size)
    ok = True
    if (not args):
        return cls._af_new(list(range((size or 0))))
    elif (len(args) > 1):
        return cls._af_new(Cycle(*args).list(size))
    if (len(args) == 1):
        a = args[0]
        if isinstance(a, cls):
            if ((size is None) or (size == a.size)):
                return a
            return cls(a.array_form, size=size)
        if isinstance(a, Cycle):
            return cls._af_new(a.list(size))
        if (not is_sequence(a)):
            return cls._af_new(list(range((a + 1))))
        if has_variety((is_sequence(ai) for ai in a)):
            ok = False
    else:
        ok = False
    if (not ok):
        raise ValueError('Permutation    argument    must    be    a    list    of    ints,    a    list    of    lists,    Permutation    or    Cycle.')
    args = list(args[0])
    is_cycle = (args and is_sequence(args[0]))
    if is_cycle:
        args = [[int(i) for i in c] for c in args]
    else:
        args = [int(i) for i in args]
    temp = flatten(args)
    if (has_dups(temp) and (not is_cycle)):
        raise ValueError('there    were    repeated    elements.')
    temp = set(temp)
    if ((not is_cycle) and any(((i not in temp) for i in range(len(temp))))):
        raise ValueError(('Integers    0    through    %s    must    be    present.' % max(temp)))
    if is_cycle:
        c = Cycle()
        for ci in args:
            c = c(*ci)
        aform = c.list()
    else:
        aform = list(args)
    if (size and (size > len(aform))):
        aform.extend(list(range(len(aform), size)))
    return cls._af_new(aform)
