ROOTPLOIT
Server: Apache
System: Linux info 3.0 #1337 SMP Tue Jan 01 00:00:00 CEST 2000 all GNU/Linux
User: ws67150586 (67150586)
PHP: 8.3.36
Disabled: NONE
Upload Files
File: //kunden/kunden/kunden/lib/python3/dist-packages/more_itertools/__pycache__/recipes.cpython-313.pyc
�

a`h�����SrSSKrSSKJr SSKJr SSKJr SSKJ	r	J
r
 SSKJrJ
r
JrJrJrJrJrJrJrJrJrJrJr SSKJrJrJrJr SS	KJrJ r J!r!J"r" SS
KJ#r#J$r$J%r% SSK&J'r' /SQr(\)"5r*\+"S
S9 \
"\+S
S9r,SSKJ.r/ Sr1STSjr2Sr3SUSjr4SUSjr5SUSjr6\74Sjr8Sr9\9r:Sr;Sr<Sr=SUSjr>Sr?SSKJ@rA Sr@\?R\@l"S S!\B5rCS"rDS#rESVS$jrFS%rGS&rHS'rISUS(jrJSUS)jrKSWS+jrLSUS,jrMSXS-jrNS.S/.S0jrOSUS1jrPS2rQS3rRS4rSS5rTS6rUS7rVS8rWS9rXS:rYS;rZS<r[S=r\SYS>jr]S?r^S*S.S@jr_\'SA:�aSSBKJ`ra S*S.SCjr`O\_r`\_R\`lSDrbSErcSFrdSGre\f"\^"SH55rgSIrhSJriSKrjSLrkSMrl/SNQrm\	SO5rnSPro\R�"5RFrqSQrrSRrsSSrtg!\-a \+r,GN^f=f!\0a Sr/GNgf=f!\0a \?r@GN%f=f)ZaImported from the recipes section of the itertools documentation.

All functions taken from the recipes section of the itertools library docs
[1]_.
Some backward-compatible usability improvements have been made.

.. [1] http://docs.python.org/library/itertools.html#recipes

�N)�deque��suppress)�Sized)�	lru_cache�partial)
�
accumulate�chain�combinations�compress�count�cycle�groupby�islice�product�repeat�starmap�tee�zip_longest)�prod�comb�isqrt�gcd)�mul�not_�
itemgetter�getitem)�	randrange�sample�choice)�
hexversion)1�	all_equal�batched�before_and_after�consume�convolve�
dotproduct�
first_true�factor�flatten�grouper�is_prime�iter_except�
iter_index�loops�matmul�multinomial�ncycles�nth�nth_combination�padnone�pad_none�pairwise�	partition�polynomial_eval�polynomial_from_roots�polynomial_derivative�powerset�prepend�quantify�reshape�#random_combination_with_replacement�random_combination�random_permutation�random_product�
repeatfunc�
roundrobin�sieve�sliding_window�	subslices�sum_of_squares�tabulate�tail�take�totient�	transpose�
triplewise�unique�unique_everseen�unique_justseenT��strict)�sumprodc��[X5$�N)r')�x�ys  �8/usr/lib/python3/dist-packages/more_itertools/recipes.py�<lambda>r[is	��J�q�,�c�*�[[X55$)z�Return first *n* items of the *iterable* as a list.

    >>> take(3, range(10))
    [0, 1, 2]

If there are fewer than *n* items in the iterable, all of them are
returned.

    >>> take(10, range(3))
    [0, 1, 2]

)�listr��n�iterables  rZrLrLls����x�#�$�$r\c�,�[U[U55$)a�Return an iterator over the results of ``func(start)``,
``func(start + 1)``, ``func(start + 2)``...

*func* should be a function that accepts one integer argument.

If *start* is not specified it defaults to 0. It will be incremented each
time the iterator is advanced.

    >>> square = lambda x: x ** 2
    >>> iterator = tabulate(square, -3)
    >>> take(4, iterator)
    [9, 4, 1, 0]

)�mapr
)�function�starts  rZrJrJ|s���x��u��&�&r\c	��[U[5(a#[U[S[	U5U-
5S5$[[
XS95$)zsReturn an iterator over the last *n* items of *iterable*.

>>> t = tail(3, 'ABCDEFG')
>>> list(t)
['E', 'F', 'G']

rN��maxlen)�
isinstancerr�max�len�iterrr_s  rZrKrK�s@���(�E�"�"��h��A�s�8�}�q�'8� 9�4�@�@��E�(�-�.�.r\c�L�Uc[USS9 g[[XU5S5 g)a�Advance *iterable* by *n* steps. If *n* is ``None``, consume it
entirely.

Efficiently exhausts an iterator without returning values. Defaults to
consuming the whole iterator, but an optional second argument may be
provided to limit consumption.

    >>> i = (x for x in range(10))
    >>> next(i)
    0
    >>> consume(i, 3)
    >>> next(i)
    4
    >>> consume(i)
    >>> next(i)
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
    StopIteration

If the iterator has fewer items remaining than the provided limit, the
whole iterator will be consumed.

    >>> i = (x for x in range(3))
    >>> consume(i, 5)
    >>> next(i)
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
    StopIteration

Nrrg)r�nextr)�iteratorr`s  rZr%r%�s'��@	�y�
�h�q�!�	
�V�H��
#�T�*r\c�.�[[XS5U5$)zmReturns the nth item or a default value.

>>> l = range(10)
>>> nth(l, 3)
3
>>> nth(l, 20, "zebra")
'zebra'

N)rnr)rar`�defaults   rZr3r3�s����x�D�)�7�3�3r\c�@�[X5nUH
nUHn  g  g g)aw
Returns ``True`` if all the elements are equal to each other.

    >>> all_equal('aaaa')
    True
    >>> all_equal('aaab')
    False

A function that accepts a single argument and returns a transformed version
of each input item can be specified with *key*:

    >>> all_equal('AaaA', key=str.casefold)
    True
    >>> all_equal([1, 2, 3], key=lambda x: x < 10)
    True

FT)r)ra�keyro�first�seconds     rZr"r"�s-��$�x�%�H����F�����r\c�*�[[X55$)zWReturn the how many times the predicate is true.

>>> quantify([True, False, True])
2

)�sumrc)ra�preds  rZr>r>�s���s�4�"�#�#r\c�,�[U[S55$)z�Returns the sequence of elements and then returns ``None`` indefinitely.

    >>> take(5, pad_none(range(3)))
    [0, 1, 2, None, None]

Useful for emulating the behavior of the built-in :func:`map` function.

See also :func:`padded`.

N)r
r�ras rZr6r6�s����6�$�<�(�(r\c�T�[R"[[U5U55$)zjReturns the sequence elements *n* times

>>> list(ncycles(["a", "b"], 3))
['a', 'b', 'a', 'b', 'a', 'b']

)r
�
from_iterabler�tuple�rar`s  rZr2r2
s �����v�e�H�o�q�9�:�:r\c�4�[[[X55$)z�Returns the dot product of the two iterables.

>>> dotproduct([10, 15, 12], [0.65, 0.80, 1.25])
33.5
>>> 10 * 0.65 + 15 * 0.80 + 12 * 1.25
33.5

In Python 3.12 and later, use ``math.sumprod()`` instead.
)rwrcr)�vec1�vec2s  rZr'r's���s�3��#�$�$r\c�.�[R"U5$)z�Return an iterator flattening one level of nesting in a list of lists.

    >>> list(flatten([[0, 1], [2, 3]]))
    [0, 1, 2, 3]

See also :func:`collapse`, which can flatten multiple levels of nesting.

)r
r|)�listOfListss rZr*r*!s�����{�+�+r\c�\�Uc[U[U55$[U[X!55$)aCall *func* with *args* repeatedly, returning an iterable over the
results.

If *times* is specified, the iterable will terminate after that many
repetitions:

    >>> from operator import add
    >>> times = 4
    >>> args = 3, 5
    >>> list(repeatfunc(add, times, *args))
    [8, 8, 8, 8]

If *times* is ``None`` the iterable will not terminate:

    >>> from random import randrange
    >>> times = None
    >>> args = 1, 11
    >>> take(6, repeatfunc(randrange, times, *args))  # doctest:+SKIP
    [2, 4, 8, 1, 8, 4]

)rr)�func�times�argss   rZrDrD-s,��,
�}��t�V�D�\�*�*��4���,�-�-r\c�J�[U5up[US5 [X5$)z�Returns an iterator of paired items, overlapping, from the original

>>> take(4, pairwise(count()))
[(0, 1), (1, 2), (2, 3), (3, 4)]

On Python 3.10 and above, this is an alias for :func:`itertools.pairwise`.

N�rrn�zip)ra�a�bs   rZ�	_pairwiser�Hs"���x�=�D�A���D�M��q�9�r\)r7c��[U5$rW)�itertools_pairwiserzs rZr7r7\s
��!�(�+�+r\c�,^�\rSrSrSU4SjjrSrU=r$)�UnequalIterablesErroribc�R>�SnUbUSR"U6-
n[TU]	U5 g)Nz Iterables have different lengthsz/: index 0 has length {}; index {} has length {})�format�super�__init__)�self�details�msg�	__class__s   �rZr��UnequalIterablesError.__init__cs8���0�����E�M�M���
�C�	����r\�rW)�__name__�
__module__�__qualname__�__firstlineno__r��__static_attributes__�
__classcell__)r�s@rZr�r�bs
����r\r�c#�x# �[US[06H#nUHnU[LdM[5e Uv� M% g7f)N�	fillvalue)r�_markerr�)�	iterables�combo�vals   rZ�_zip_equal_generatorr�ms:����i�;�7�;���C��g�~�+�-�-����	<�s�:�:c���[US5n[USSS5H up#[U5nXA:wdM[XU4S9e [U6$![a [U5s$f=f)Nr�)r�)rk�	enumerater�r��	TypeErrorr�)r��
first_size�i�it�sizes     rZ�
_zip_equalr�usu��/���1��&�
��y���}�a�0�E�A��r�7�D��!�+�Z�D�4I�J�J�1�
�I�����/�#�I�.�.�/�s�0A�A�A#�"A#c��[U5/U-nUS:Xa[USU06$US:Xa[U6$US:Xa[U6$[	S5e)a�Group elements from *iterable* into fixed-length groups of length *n*.

>>> list(grouper('ABCDEF', 3))
[('A', 'B', 'C'), ('D', 'E', 'F')]

The keyword arguments *incomplete* and *fillvalue* control what happens for
iterables whose length is not a multiple of *n*.

When *incomplete* is `'fill'`, the last group will contain instances of
*fillvalue*.

>>> list(grouper('ABCDEFG', 3, incomplete='fill', fillvalue='x'))
[('A', 'B', 'C'), ('D', 'E', 'F'), ('G', 'x', 'x')]

When *incomplete* is `'ignore'`, the last group will not be emitted.

>>> list(grouper('ABCDEFG', 3, incomplete='ignore', fillvalue='x'))
[('A', 'B', 'C'), ('D', 'E', 'F')]

When *incomplete* is `'strict'`, a subclass of `ValueError` will be raised.

>>> iterator = grouper('ABCDEFG', 3, incomplete='strict')
>>> list(iterator)  # doctest: +IGNORE_EXCEPTION_DETAIL
Traceback (most recent call last):
...
UnequalIterablesError

�fillr�rT�ignorez Expected fill, strict, or ignore)rlrr�r��
ValueError)rar`�
incompleter��	iteratorss     rZr+r+�s^��:�h�� �1�$�I��V���I�;��;�;��X���9�%�%��X���I����;�<�<r\c'��# �[[U5n[[U5SS5H/n[	[X55n[[U5Shv�N M1 gN	7f)a/Visit input iterables in a cycle until each is exhausted.

    >>> list(roundrobin('ABC', 'D', 'EF'))
    ['A', 'D', 'E', 'B', 'F', 'C']

This function produces the same output as :func:`interleave_longest`, but
may perform better for some inputs (in particular when the number of
iterables is small).

r���N)rcrl�rangerkrrrn)r�r��
num_actives   rZrErE�sL����D�)�$�I��C�	�N�A�r�2�
��&��7�8�	��t�Y�'�'�'�3�'�s�AA�A�
Ac��Uc[n[US5up#n[[X55upV[U[[U55[X654$)aw
Returns a 2-tuple of iterables derived from the input iterable.
The first yields the items that have ``pred(item) == False``.
The second yields the items that have ``pred(item) == True``.

    >>> is_odd = lambda x: x % 2 != 0
    >>> iterable = range(10)
    >>> even_items, odd_items = partition(is_odd, iterable)
    >>> list(even_items), list(odd_items)
    ([0, 2, 4, 6, 8], [1, 3, 5, 7, 9])

If *pred* is None, :func:`bool` is used.

    >>> iterable = [0, 1, False, True, '', ' ']
    >>> false_items, true_items = partition(None, iterable)
    >>> list(false_items), list(true_items)
    ([0, False, ''], [1, True, ' '])

�)�boolrrcrr)rxra�t1�t2�p�p1�p2s       rZr8r8�sK��(�|����H�a� �I�B�A�
��T��
�F�B��R��T�2��'��"�)9�:�:r\c�^�[U5m[R"U4Sj[[	T5S-555$)aYields all possible subsets of the iterable.

    >>> list(powerset([1, 2, 3]))
    [(), (1,), (2,), (3,), (1, 2), (1, 3), (2, 3), (1, 2, 3)]

:func:`powerset` will operate on iterables that aren't :class:`set`
instances, so repeated elements in the input will produce repeated elements
in the output.

    >>> seq = [1, 1, 0]
    >>> list(powerset(seq))
    [(), (1,), (1,), (0,), (1, 1), (1, 0), (1, 0), (1, 1, 0)]

For a variant that efficiently yields actual :class:`set` instances, see
:func:`powerset_of_sets`.
c3�<># �UHn[TU5v� M g7frW)r)�.0�r�ss  �rZ�	<genexpr>�powerset.<locals>.<genexpr>�s����M�;L�a�|�A�q�1�1�;L���r�)r^r
r|r�rk)rar�s @rZr<r<�s2���"	
�X��A����M�5��Q��!��;L�M�M�Mr\c#�# �[5nURn/nURnUSLnUH(nU(aU"U5OUnX�;aU"U5 Uv� M(M* g![a X�;aU"U5 Uv� MKMNf=f7f)aJ
Yield unique elements, preserving order.

    >>> list(unique_everseen('AAAABBBCCDAABBB'))
    ['A', 'B', 'C', 'D']
    >>> list(unique_everseen('ABBCcAD', str.lower))
    ['A', 'B', 'C', 'D']

Sequences with a mix of hashable and unhashable items can be used.
The function will be slower (i.e., `O(n^2)`) for unhashable items.

Remember that ``list`` objects are unhashable - you can use the *key*
parameter to transform the list to a tuple (which is hashable) to
avoid a slowdown.

    >>> iterable = ([1, 2], [2, 3], [1, 2])
    >>> list(unique_everseen(iterable))  # Slow
    [[1, 2], [2, 3]]
    >>> list(unique_everseen(iterable, key=tuple))  # Faster
    [[1, 2], [2, 3]]

Similarly, you may want to convert unhashable ``set`` objects with
``key=frozenset``. For ``dict`` objects,
``key=lambda x: frozenset(x.items())`` can be used.

N)�set�add�appendr�)	rars�seenset�seenset_add�seenlist�seenlist_add�use_key�element�ks	         rZrQrQ�s����6�e�G��+�+�K��H��?�?�L���o�G���#�C��L���	����A���
� ����	�� ��Q���
�!�	�s)�?A?�A�A?�A<�5A?�;A<�<A?c
��Uc[[S5[U55$[[[[S5[X555$)z�Yields elements in order, ignoring serial duplicates

>>> list(unique_justseen('AAAABBBCCDAABBB'))
['A', 'B', 'C', 'D', 'A', 'B']
>>> list(unique_justseen('ABBCcAD', str.lower))
['A', 'B', 'C', 'A', 'D']

rr�)rcrrrn)rarss  rZrRrRs<���{��:�a�=�'�(�"3�4�4��t�S��A����(>�?�@�@r\Fc�(�[XUS9n[X1S9$)a�Yields unique elements in sorted order.

>>> list(unique([[1, 2], [3, 4], [1, 2]]))
[[1, 2], [3, 4]]

*key* and *reverse* are passed to :func:`sorted`.

>>> list(unique('ABBcCAD', str.casefold))
['A', 'B', 'c', 'D']
>>> list(unique('ABBcCAD', str.casefold, reverse=True))
['D', 'c', 'B', 'A']

The elements in *iterable* need not be hashable, but they must be
comparable for sorting to work.
)rs�reverse)rs)�sortedrR)rarsr��	sequenceds    rZrPrP,s�� �x�'�:�I��9�.�.r\c#�t# �[U5 Ub	U"5v� U"5v� M!,(df   g=f7f)a�Yields results from a function repeatedly until an exception is raised.

Converts a call-until-exception interface to an iterator interface.
Like ``iter(func, sentinel)``, but uses an exception instead of a sentinel
to end the loop.

    >>> l = [0, 1, 2]
    >>> list(iter_except(l.pop, IndexError))
    [2, 1, 0]

Multiple exceptions can be specified as a stopping condition:

    >>> l = [1, 2, 3, '...', 4, 5, 6]
    >>> list(iter_except(lambda: 1 + l.pop(), (IndexError, TypeError)))
    [7, 6, 5]
    >>> list(iter_except(lambda: 1 + l.pop(), (IndexError, TypeError)))
    [4, 3, 2]
    >>> list(iter_except(lambda: 1 + l.pop(), (IndexError, TypeError)))
    []

Nr)r��	exceptionrts   rZr-r-@s3���,
�)�	����'�M���&�L��
�	�s�8�'�
5�8c�,�[[X 5U5$)ad
Returns the first true value in the iterable.

If no true value is found, returns *default*

If *pred* is not None, returns the first item for which
``pred(item) == True`` .

    >>> first_true(range(10))
    1
    >>> first_true(range(10), pred=lambda x: x > 5)
    6
    >>> first_true(range(10), default='missing', pred=lambda x: x > 9)
    'missing'

)rn�filter)rarqrxs   rZr(r(]s��"��t�&��0�0r\r��rc�n�UVs/sHn[U5PM snU-n[SU55$s snf)a�Draw an item at random from each of the input iterables.

    >>> random_product('abc', range(4), 'XYZ')  # doctest:+SKIP
    ('c', 3, 'Z')

If *repeat* is provided as a keyword argument, that many items will be
drawn from each iterable.

    >>> random_product('abcd', range(4), repeat=2)  # doctest:+SKIP
    ('a', 2, 'd', 3)

This equivalent to taking a random selection from
``itertools.product(*args, **kwarg)``.

c3�8# �UHn[U5v� M g7frW)r )r��pools  rZr��!random_product.<locals>.<genexpr>�s���0�%�$�����%�s�)r})rr�r��poolss    rZrCrCqs7�� &*�*�T�T�U�4�[�T�*�V�3�E��0�%�0�0�0��
+s�2c�`�[U5nUc[U5OUn[[X!55$)aFReturn a random *r* length permutation of the elements in *iterable*.

If *r* is not specified or is ``None``, then *r* defaults to the length of
*iterable*.

    >>> random_permutation(range(5))  # doctest:+SKIP
    (3, 4, 0, 1, 2)

This equivalent to taking a random selection from
``itertools.permutations(iterable, r)``.

)r}rkr)rar�r�s   rZrBrB�s+����?�D��Y��D�	�A�A�����!�!r\c�^�[U5m[T5n[[[	U5U55n[U4SjU55$)z�Return a random *r* length subsequence of the elements in *iterable*.

    >>> random_combination(range(5), 3)  # doctest:+SKIP
    (2, 3, 4)

This equivalent to taking a random selection from
``itertools.combinations(iterable, r)``.

c3�.># �UH
nTUv� M g7frWr��r�r�r�s  �rZr��%random_combination.<locals>.<genexpr>������*�'�Q��a��'���)r}rkr�rr�)rar�r`�indicesr�s    @rZrArA�s=�����?�D��D�	�A��V�E�!�H�a�(�)�G��*�'�*�*�*r\c�^^�[U5m[T5m[U4Sj[U555n[U4SjU55$)a;Return a random *r* length subsequence of elements in *iterable*,
allowing individual elements to be repeated.

    >>> random_combination_with_replacement(range(3), 5) # doctest:+SKIP
    (0, 0, 1, 2, 2)

This equivalent to taking a random selection from
``itertools.combinations_with_replacement(iterable, r)``.

c3�:># �UHn[T5v� M g7frW)r�r�r�r`s  �rZr��6random_combination_with_replacement.<locals>.<genexpr>�s����4�8�a�Y�q�\�\�8�s�c3�.># �UH
nTUv� M g7frWr�r�s  �rZr�r��r�r�)r}rkr�r�)rar�r�r`r�s   @@rZr@r@�s<�����?�D��D�	�A��4�5��8�4�4�G��*�'�*�*�*r\c��[U5n[U5nUS:dX:�a[eSn[XU-
5n[	SUS-5HnXTU-
U--U-nM US:aX%-
nUS:dX%:�a[
e/nU(aNXQ-U-US-
US-
pnX%:�aX%-nXTU-
-U-US-
pEX%:�aMUR
USU-
5 U(aMN[U5$)a�Equivalent to ``list(combinations(iterable, r))[index]``.

The subsequences of *iterable* that are of length *r* can be ordered
lexicographically. :func:`nth_combination` computes the subsequence at
sort position *index* directly, without computing the previous
subsequences.

    >>> nth_combination(range(5), 3, 5)
    (0, 3, 4)

``ValueError`` will be raised If *r* is negative or greater than the length
of *iterable*.
``IndexError`` will be raised if the given *index* is invalid.
rr�r�)r}rkr��minr��
IndexErrorr�)	rar��indexr�r`�cr�r��results	         rZr4r4�s�����?�D��D�	�A�	�A��1�5���	�A��A�1�u�
�A�
�1�a�!�e�_��
�Q����O�q� ���
�q�y�
�
��
��	�u�z���
�F�
��%�1�*�a�!�e�Q��U�a���j��J�E��A��;�!�#�Q��U�q��j�	�
�
�d�2��6�l�#��!���=�r\c��[U/U5$)aYield *value*, followed by the elements in *iterator*.

    >>> value = '0'
    >>> iterator = ['1', '2', '3']
    >>> list(prepend(value, iterator))
    ['0', '1', '2', '3']

To prepend multiple values, see :func:`itertools.chain`
or :func:`value_chain`.

)r
)�valueros  rZr=r=�s���%��(�#�#r\c#��# �[U5SSS2n[U5n[S/US9U-n[U[	SUS-
55H!nURU5 [
X5v� M# g7f)u-Discrete linear convolution of two iterables.
Equivalent to polynomial multiplication.

For example, multiplying ``(x² -x - 20)`` by ``(x - 3)``
gives ``(x³ -4x² -17x + 60)``.

    >>> list(convolve([1, -1, -20], [1, -3]))
    [1, -4, -17, 60]

Examples of popular kinds of kernels:

* The kernel ``[0.25, 0.25, 0.25, 0.25]`` computes a moving average.
  For image data, this blurs the image and reduces noise.
* The kernel ``[1/2, 0, -1/2]`` estimates the first derivative of
  a function evaluated at evenly spaced inputs.
* The kernel ``[1, -2, 1]`` estimates the second derivative of a
  function evaluated at evenly spaced inputs.

Convolutions are mathematically commutative; however, the inputs are
evaluated differently.  The signal is consumed lazily and can be
infinite. The kernel is fully consumed before the calculations begin.

Supports all numeric types: int, float, complex, Decimal, Fraction.

References:

* Article:  https://betterexplained.com/articles/intuitive-convolution/
* Video by 3Blue1Brown:  https://www.youtube.com/watch?v=KuXjwB4LzSA

Nr�rrgr�)r}rkrr
rr��_sumprod)�signal�kernelr`�windowrXs     rZr&r&�si���F�6�]�4�R�4�
 �F��F��A�
�A�3�q�
!�A�
%�F�
�6�6�!�Q��U�+�
,���
�
�a���v�&�&�-�s�A*A,c�\^^^�[T5m/mUUU4Sjn[TT5nU"5U4$)a�A variant of :func:`takewhile` that allows complete access to the
remainder of the iterator.

     >>> it = iter('ABCdEfGhI')
     >>> all_upper, remainder = before_and_after(str.isupper, it)
     >>> ''.join(all_upper)
     'ABC'
     >>> ''.join(remainder) # takewhile() would lose the 'd'
     'dEfGhI'

Note that the first iterator must be fully consumed before the second
iterator can generate valid results.
c3�h># �TH'nT"U5(aUv� MTRU5  g g7frW)r�)�elemr��	predicate�
transitions ���rZ�
true_iterator�'before_and_after.<locals>.true_iterator-s/�����D������
��!�!�$�'���s�/2)rlr
)rr�r�remainder_iteratorrs``  @rZr$r$s5���
�b��B��J���z�2�.���?�.�.�.r\c��[US5upn[US5 [US5 [US5 [XU5$)z�Return overlapping triplets from *iterable*.

>>> list(triplewise('ABCDE'))
[('A', 'B', 'C'), ('B', 'C', 'D'), ('C', 'D', 'E')]

r�Nr�)rar�r��t3s    rZrOrO=s;���X�q�!�J�B�B���T�N���T�N���T�N��r�r�?�r\c�|�[X5n[U5Hup4[[XCU5S5 M [	U6$rW)rr�rnrr�)rar`r�r�ros     rZ�_sliding_window_islicerMs8���H� �I� ��+����V�H��
#�T�*�,��	�?�r\c#�# �[U5n[[X!S-
5US9nUH!nURU5 [	U5v� M# g7f)Nr�rg)rlrrr�r})rar`ror�rXs     rZ�_sliding_window_dequer
UsC����H�~�H�
�6�(��E�*�1�
5�F�
���
�
�a���F�m���s�A
Ac��US:�a[X5$US:�a[X5$US:Xa[U5$US:Xa[U5$[	SU35e)a=Return a sliding window of width *n* over *iterable*.

    >>> list(sliding_window(range(6), 4))
    [(0, 1, 2, 3), (1, 2, 3, 4), (2, 3, 4, 5)]

If *iterable* has fewer than *n* items, then nothing is yielded:

    >>> list(sliding_window(range(3), 4))
    []

For a variant with more features, see :func:`windowed`.
��r�zn should be at least one, not )r
rr7r�r�r~s  rZrGrG^s^��	�2�v�$�X�1�1�	
�Q��%�h�2�2�	
�a����!�!�	
�a���8�}���9�!��=�>�>r\c
��[U5n[[[[	[U5S-5S55n[
[[U5U5$)z�Return all contiguous non-empty subslices of *iterable*.

    >>> list(subslices('ABC'))
    [['A'], ['A', 'B'], ['A', 'B', 'C'], ['B'], ['B', 'C'], ['C']]

This is similar to :func:`substrings`, but emits items in a different
order.
r�r)	r^r�slicerr�rkrcrr)ra�seq�slicess   rZrHrHws@���x�.�C�
�U�L��s�3�x�!�|�)<�a�@�
A�F��w��s��V�,�,r\c�N�S/nUHn[[USU*455nM U$)uCompute a polynomial's coefficients from its roots.

>>> roots = [5, -4, 3]            # (x - 5) * (x + 4) * (x - 3)
>>> polynomial_from_roots(roots)  # x³ - 4 x² - 17 x + 60
[1, -4, -17, 60]

Supports all numeric types: int, float, complex, Decimal, Fraction.
r�)r^r&)�roots�poly�roots   rZr:r:�s1��
�3�D����H�T�A��u�:�.�/����Kr\c#�# �[USS5nUc0[XU5n[XR5HupgXqLdXq:XdMUv� M gUc[U5OUnUS-
n[	[
5 U"XS-U5=nv� M!,(df   g=f7f)a�Yield the index of each place in *iterable* that *value* occurs,
beginning with index *start* and ending before index *stop*.


>>> list(iter_index('AABCADEAF', 'A'))
[0, 1, 4, 7]
>>> list(iter_index('AABCADEAF', 'A', 1))  # start index is inclusive
[1, 4, 7]
>>> list(iter_index('AABCADEAF', 'A', 1, 7))  # stop index is not inclusive
[1, 4]

The behavior for non-scalar *values* matches the built-in Python types.

>>> list(iter_index('ABCDABCD', 'AB'))
[0, 4]
>>> list(iter_index([0, 1, 2, 3, 0, 1, 2, 3], [0, 1]))
[]
>>> list(iter_index([[0, 1], [2, 3], [0, 1], [2, 3]], [0, 1]))
[0, 2]

See :func:`locate` for a more general means of finding the indexes
associated with particular values.

r�Nr�)�getattrrr�rkrr�)rar�re�stop�	seq_indexror�r�s        rZr.r.�s����2��'�4�0�I����(�4�0��#�H�4�J�A���7�#3���5�
!%��s�8�}�$���A�I��
�j�
!��%�e��U�D�9�9�q�:��"�
!�s�4B�-B�'A;�;
B	�Bc#�H# �US:�aSv� Sn[S5US--n[USU[U5S-S9HLn[USXU-5Shv�N [[	[X3-XU-555X#U-XU-2'X3-nMN [USU5Shv�N gNON7f)zYYield the primes less than n.

>>> list(sieve(30))
[2, 3, 5, 7, 11, 13, 17, 19, 23, 29]

rr�)rr�r�)rN)�	bytearrayr.r�bytesrkr�)r`re�datar�s    rZrFrF�s����	�1�u���
�E��V���Q��'�D�
��a��U�1�X��\�
:���d�A�u�!�e�4�4�4�"'��E�!�%���E�,B�(C�"D���U�Q�Q��
�����;��$��5�)�)�)�	5�*�s%�AB"�B�A	B"�B �B"� B"c#�# �US:a[S5e[U5n[[X155=n(aCU(a[	U5U:wa[S5eUv� [[X155=n(aMBgg7f)arBatch data into tuples of length *n*. If the number of items in
*iterable* is not divisible by *n*:
* The last batch will be shorter if *strict* is ``False``.
* :exc:`ValueError` will be raised if *strict* is ``True``.

>>> list(batched('ABCDEFG', 3))
[('A', 'B', 'C'), ('D', 'E', 'F'), ('G',)]

On Python 3.13 and above, this is an alias for :func:`itertools.batched`.
r�zn must be at least onezbatched(): incomplete batchN)r�rlr}rrk)rar`rTro�batchs     rZ�_batchedr#�sp���	�1�u��1�2�2��H�~�H����,�-�
-�%�
-��c�%�j�A�o��:�;�;������,�-�
-�%�
-�
-�s�A8A>�<A>i�
)r#c��[XUS9$)NrS)�itertools_batched)rar`rTs   rZr#r#�s�� ��V�<�<r\c��[U6$)z�Swap the rows and columns of the input matrix.

>>> list(transpose([(1, 2, 3), (11, 22, 33)]))
[(1, 11), (2, 22), (3, 33)]

The caller should ensure that the dimensions of the input are compatible.
If the input is empty, no output will be produced.
)�_zip_strict�r�s rZrNrN�s�����r\c�B�[[R"U5U5$)z�Reshape the 2-D input *matrix* to have a column count given by *cols*.

>>> matrix = [(0, 1), (2, 3), (4, 5)]
>>> cols = 3
>>> list(reshape(matrix, cols))
[(0, 1, 2), (3, 4, 5)]
)r#r
r|)�matrix�colss  rZr?r?s���5�&�&�v�.��5�5r\c�x�[US5n[[[[	U[U555U5$)aMultiply two matrices.

>>> list(matmul([(7, 5), (3, 5)], [(2, 5), (7, 9)]))
[(49, 80), (41, 60)]

The caller should ensure that the dimensions of the input matrices are
compatible with each other.

Supports all numeric types: int, float, complex, Decimal, Fraction.
r)rkr#rr�rrN)�m1�m2r`s   rZr0r0s0��	�B�q�E�
�A��7�8�W�R��2��%?�@�!�D�Dr\c���[SU5HKnS=p#SnUS:Xa4X"-U-U-nX3-U-U-nX3-U-U-n[X#-
U5nUS:XaM4X@:wdMIUs $ [S5e)Nr�rzprime or under 5)r�rr�)r`r�rXrY�ds     rZ�_factor_pollardr1s����1�a�[���	��
���1�f�����a��A�����a��A�����a��A��A�E�1�
�A�	�1�f�

�6��H���'�
(�(r\��c#�># �US:ag[H!nX-(aMUv� X-nX-(dMM# /nUS:�aU/O/nUH?nUS:d[U5(aURU5 M,[U5nX4X-4-
nMA [	U5Shv�N gN7f)z�Yield the prime factors of n.

>>> list(factor(360))
[2, 2, 2, 3, 3, 5]

Finds small factors with trial division.  Larger factors are
either verified as prime with ``is_prime`` or split into
smaller factors with Pollard's rho algorithm.
rNr�i�)�_primes_below_211r,r�r1r�)r`�prime�primes�todo�facts     rZr)r).s����	�1�u��#���)�)��K�
�K�A��)�)�#��F��a�%�A�3�R�D�
���v�:��!����M�M�!��"�1�%�D��1�9�%�%�D���f�~���s�B�B�A$B�B�Bc	��[U5nUS:Xa[U5"S5$[[[	U5[[
U555n[X5$)aDEvaluate a polynomial at a specific value.

Computes with better numeric stability than Horner's method.

Evaluate ``x^3 - 4 * x^2 - 17 * x + 60`` at ``x = 2.5``:

>>> coefficients = [1, -4, -17, 60]
>>> x = 2.5
>>> polynomial_eval(coefficients, x)
8.125

Supports all numeric types: int, float, complex, Decimal, Fraction.
r)rk�typerc�powr�reversedr�r�)�coefficientsrXr`�powerss    rZr9r9OsI��	�L��A��A�v��A�w�q�z��
��f�Q�i��%��(�!3�
4�F��L�)�)r\c�$�[[U56$)z�Return the sum of the squares of the input values.

>>> sum_of_squares([10, 20, 30])
1400

Supports all numeric types: int, float, complex, Decimal, Fraction.
)r�rr(s rZrIrIds���S��W��r\c�t�[U5n[[SU55n[[	[
X55$)u<Compute the first derivative of a polynomial.

Evaluate the derivative of ``x³ - 4 x² - 17 x + 60``:

>>> coefficients = [1, -4, -17, 60]
>>> derivative_coefficients = polynomial_derivative(coefficients)
>>> derivative_coefficients
[3, -8, -17]

Supports all numeric types: int, float, complex, Decimal, Fraction.
r�)rkr<r�r^rcr)r=r`r>s   rZr;r;os0��	�L��A�
�e�A�q�k�
"�F���C��.�/�/r\c�J�[[U55H
nXU--nM U$)u�Return the count of natural numbers up to *n* that are coprime with *n*.

Euler's totient function φ(n) gives the number of totatives.
Totative are integers k in the range 1 ≤ k ≤ n such that gcd(n, k) = 1.

>>> n = 9
>>> totient(n)
6

>>> totatives = [x for x in range(1, n) if gcd(n, x) == 1]
>>> totatives
[1, 2, 4, 5, 7, 8]
>>> len(totatives)
6

Reference:  https://en.wikipedia.org/wiki/Euler%27s_totient_function

)r�r))r`r5s  rZrMrM�s&��&�V�A�Y���	�%�Z��� ��Hr\))i�)r)i��)��I)l�tT7)r��=)l�ay)r�
�iS_)l;n>�)rr��rD�)l�p�)rr�rHrDrIrF)l)riEi�$ini��i=�i��k)l�%!H�n
�fW)
rr�rHrDrIrF��rG�rB�%�)c�~�US-
U-R5S-
nX-	nSU-U-U:XaUS-(aUS:�deX4$)z#Return s, d such that 2**s * d == nr�r)�
bit_length)r`r�r0s   rZ�
_shift_to_oddrQ�sO���a�%�1�� � �"�Q�&�A�	��A�
��F�a�<�1���Q��1��6�1�1��4�Kr\c���US:�aUS-(aSUs=::aU:de e[US-
5up#[XU5nUS:XdX@S-
:Xag[US-
5HnXD-U-nX@S-
:XdM g g)Nrr�TF)rQr;r�)r`�baser�r0rX�_s      rZ�_strong_probable_primerU�s���
��E��A��A��M��M�2�2�M�2�2���Q���D�A��D�Q��A��A�v��!�e���
�1�q�5�\��
�E�A�I���A��:���
r\c�^�TS:aTS;$TS-(a2TS-(a(TS-(aTS-(aTS-(a
TS-(dg	[H
upTU:dM
 O U4S
j[S55n[U4SjU55$)
amReturn ``True`` if *n* is prime and ``False`` otherwise.

Basic examples:

    >>> is_prime(37)
    True
    >>> is_prime(3 * 13)
    False
    >>> is_prime(18_446_744_073_709_551_557)
    True

Find the next prime over one billion:

    >>> next(filter(is_prime, count(10**9)))
    1000000007

Generate random primes up to 200 bits and up to 60 decimal digits:

    >>> from random import seed, randrange, getrandbits
    >>> seed(18675309)

    >>> next(filter(is_prime, map(getrandbits, repeat(200))))
    893303929355758292373272075469392561129886005037663238028407

    >>> next(filter(is_prime, map(randrange, repeat(10**60))))
    269638077304026462407872868003560484232362454342414618963649

This function is exact for values of *n* below 10**24.  For larger inputs,
the probabilistic Miller-Rabin primality test has a less than 1 in 2**128
chance of a false positive.
rJ>rr�rHrDrIrFr�r�rHrDrIrFFc3�B># �UHn[STS-
5v� M g7f)rr�N)�_private_randranger�s  �rZr��is_prime.<locals>.<genexpr>�s ����A�y�!�#�A�q�1�u�-�-�y�s��@c3�<># �UHn[TU5v� M g7frW)rU)r�rSr`s  �rZr�rY�s����A�5�4�%�a��.�.�5�r�)�_perfect_testsr��all)r`�limit�basess`  rZr,r,�sy���B	�2�v��(�(�(�
��E�a�!�e��A��!�a�%�A��F�q�2�v��&����u�9��'�B�u�R�y�A���A�5�A�A�Ar\c��[SU5$)z�Returns an iterable with *n* elements for efficient looping.
Like ``range(n)`` but doesn't create integers.

>>> i = 0
>>> for _ in loops(5):
...     i += 1
>>> i
5

Nr�)r`s rZr/r/�s���$��?�r\c�H�[[[[U5U55$)ulNumber of distinct arrangements of a multiset.

The expression ``multinomial(3, 4, 2)`` has several equivalent
interpretations:

* In the expansion of ``(a + b + c)⁹``, the coefficient of the
  ``a³b⁴c²`` term is 1260.

* There are 1260 distinct ways to arrange 9 balls consisting of 3 reds, 4
  greens, and 2 blues.

* There are 1260 unique ways to place 9 distinct objects into three bins
  with sizes 3, 4, and 2.

The :func:`multinomial` function computes the length of
:func:`distinct_permutations`.  For example, there are 83,160 distinct
anagrams of the word "abracadabra":

    >>> from more_itertools import distinct_permutations, ilen
    >>> ilen(distinct_permutations('abracadabra'))
    83160

This can be computed directly from the letter counts, 5a 2b 2r 1c 1d:

    >>> from collections import Counter
    >>> list(Counter('abracadabra').values())
    [5, 2, 2, 1, 1]
    >>> multinomial(5, 2, 1, 1, 2)
    83160

A binomial coefficient is a special case of multinomial where there are
only two categories.  For example, the number of ways to arrange 12 balls
with 5 reds and 7 blues is ``multinomial(5, 7)`` or ``math.comb(12, 5)``.

When the multiplicities are all just 1, :func:`multinomial`
is a special case of ``math.factorial`` so that
``multinomial(1, 1, 1, 1, 1, 1, 1) == math.factorial(7)``.

Reference:  https://en.wikipedia.org/wiki/Multinomial_theorem

)rrcrr	)�countss rZr1r1s��T��D�*�V�,�f�5�6�6r\)rrW)r�N)NF)NN)rN)u�__doc__�random�collectionsr�
contextlibr�collections.abcr�	functoolsrr�	itertoolsr	r
rrr
rrrrrrrr�mathrrrr�operatorrrrrrrr �sysr!�__all__�objectr�r�r'r�rUr��ImportErrorrLrJrKr%r3r"r�r>r6r5r2r'r*rDr�r7r�r�r�r�r�r+rEr8r<rQrRrPr-r(rCrBrAr@r4r=r&r$rOrr
rGrHr:r.rFr#r#r%rNr?r0r1r}r4r)r9rIr;rMr\rQrU�RandomrXr,r/r1r�r\rZ�<module>rqs������!�(�����(�'�3�3�,�,��2��h�(��,��t���#�d�+�K�-�(�

%� '�$/�$%+�P
4��4!�$�)���;�
%�	,�.�6�	)�8�
,�!�(�(�H���J���
/� %=�P(�$;�8N�**�ZA�/�(�:1�("#�1�("�$
+� +�"'�T$�('�V/�B
� ��?�2-��$&;�R*�*%*��(���6�',�=��G��&�&�G�O�	�6�E�
)� �%��*�%���B*�*�0�"
�2�������&�]�]�_�.�.��-B�`�*7��M%���K����-�,�H�-��`���H��s6�3G�G"�>G2�G�G�"	G/�.G/�2G>�=G>