403Webshell
Server IP : 178.105.222.151  /  Your IP : 216.73.216.38
Web Server : nginx/1.28.3
System : Linux MNK 7.0.0-15-generic #15-Ubuntu SMP PREEMPT_DYNAMIC Wed Apr 22 16:06:43 UTC 2026 x86_64
User : www-data ( 33)
PHP Version : 8.5.4
Disable Function : NONE
MySQL : OFF  |  cURL : ON  |  WGET : ON  |  Perl : ON  |  Python : OFF  |  Sudo : ON  |  Pkexec : OFF
Directory :  /lib/python3/dist-packages/more_itertools/__pycache__/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ Back ]     

Current File : /lib/python3/dist-packages/more_itertools/__pycache__/recipes.cpython-314.pyc
+
�CiS���h�Rt^RIt^RIHtHt^RIHt^RIHt^RI	H
t
HtHt^RI
HtHt^RIHtHtHtHtHtHtHtHtHtHtHtHtHtHt^RIH t H!t!H"t"H#t#^R	I$H%t%H&t&H't'H(t(H)t)^R
IH*t*H+t+H,t,^RI-H.t..RNR
NRNRNRNRNRNRNRNRNRNRNRNRNRNRNRNRNRNRNR NR!NR"NR#NR$NR%NR&NR'NR(NR)NR*NR+NR,NR-NR.NR/NR0NR1NR2NR3NR4NR5NR6NR7NR8NR9NR:NR;NR<NR=Nt/]0!4t1]2!R>R?7]!]2R>R?7t3^R@IH5t6^RBI
H8t8H9t9R>t:RDt;R�RElt<RFt=R�RGlt>R�RHlt?R�RIlt@]A3RJltBRKtC]CtDRLtERMtFRNtGR�ROltHRPtI^RQIHJtKRRtJ]IP]Jn!RSRT]L4tMRUtNRVtOR�RWltPRXtQRYtRRZtSR�R[ltTR�R\ltUR�R]ltVR�R^ltWR�R_ltXR`^/RaltYR�RbltZRct[Rdt\Ret]Rft^Rgt_Rht`RitaRjtbRktcRltdRmteRntfR�RoltgRpthRqRC/Rrlti].Rs8�d ^RtIHjtkRqRC/Rultj]iP]jnM]itjRvtl]m]n33RwltoRxtpRytqRztrR{ts]t!]h!^�44tuR|tvR}twR~txRtyR�tz.R�Ot{]
R�4t|R�t}]P�!4PTtR�t�R�t�R�t�R�t�R�t�R�t�R�R/R�lt�R# ]4d]2t3EL�i;i ]7dRAt6EL�i;i ]7dRCt:EL�i;i ]7d]ItJELUi;i)�aImported 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)�bisect_left�insort)�deque��suppress)�	lru_cache�partial�reduce)�heappush�heappushpop)�
accumulate�chain�combinations�compress�count�cycle�groupby�islice�product�repeat�starmap�	takewhile�tee�zip_longest)�prod�comb�isqrt�gcd)�mul�not_�
itemgetter�getitem�index)�	randrange�sample�choice)�
hexversion�	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�running_median�sieve�sliding_window�	subslices�sum_of_squares�tabulate�tail�take�totient�	transpose�
triplewise�unique�unique_everseen�unique_justseenT��strict)�sumprodc��\W4#�N)r,)�x�ys&&�8/usr/lib/python3/dist-packages/more_itertools/recipes.py�<lambda>rals	��J�q�,�)�heappush_max�heappushpop_maxFc�*�\\W44#)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&&r`rRrRxs����x�#�$�$rbc�,�\V\V44#)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&&r`rPrP�s���x��u��&�&rbc��\V4p\V\^W ,
4R4# \d\	\YR74u#i;i)zsReturn an iterator over the last *n* items of *iterable*.

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

N��maxlen)�lenr�max�	TypeError�iterr)rgrh�sizes&& r`rQrQ�sK��8��8�}���h��A�t�x� 0�$�7�7���/��E�(�-�.�.�/�s�*� A
�A
c�X�Vf\V^R7R#\\WV4R4R#)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

Nrn)r�nextr)�iteratorrgs&&r`r*r*�s'��@	�y�
�h�q�!�	
�V�H��
#�T�*rbc�.�\\WR4V4#)zmReturns the nth item or a default value.

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

N)rvr)rhrg�defaults&&&r`r8r8�s����x�D�)�7�3�3rbc�F�\W4pVFpVFpR#	R#	R#)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)rh�keyrw�first�seconds&&   r`r'r'�s-��$�x�%�H����F�����rbc�*�\\W44#)zWReturn the how many times the predicate is true.

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

)�sumrj)rh�preds&&r`rCrC�s���s�4�"�#�#rbc�,�\V\R44#)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�rhs&r`r;r;s����6�$�<�(�(rbc�T�\P!\\V4V44#)zjReturns the sequence elements *n* times

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

)r
�
from_iterabler�tuple�rhrgs&&r`r7r7s �����v�e�H�o�q�9�:�:rbc�4�\\\W44#)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.
)rrjr)�vec1�vec2s&&r`r,r,s���s�3��#�$�$rbc�.�\P!V4#)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&r`r/r/+s�����{�+�+rbc�^�Vf\V\V44#\V\W!44#)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&&*r`rIrI7s,��,
�}��t�V�D�\�*�*��4���,�-�-rbc�J�\V4wr\VR4\W4#)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�rrv�zip)rh�a�bs&  r`�	_pairwiser�Rs"���x�=�D�A���D�M��q�9�rb)r<c��\V4#r])�itertools_pairwiser�s&r`r<r<fs
��!�(�+�+rbc�6aa�]tRtRtoRV3RlltRtVtV;t#)�UnequalIterablesErrorilc�`<�RpVeVRP!V!,
p\SV`	V4R#)z Iterables have different lengthsNz/: index 0 has length {}; index {} has length {})�format�super�__init__)�self�details�msg�	__class__s&& �r`r��UnequalIterablesError.__init__ms8���0�����E�M�M���
�C�	����rb�r])�__name__�
__module__�__qualname__�__firstlineno__r��__static_attributes__�__classdictcell__�
__classcell__)r��
__classdict__s@@r`r�r�ls�����rbr�c#�|"�\VR\/F$pVFpV\JgK\4h	Vx�K&	R#5i)�	fillvalueN)r�_markerr�)�	iterables�combo�vals&  r`�_zip_equal_generatorr�ws:����i�;�7�;���C��g�~�+�-�-����	<�s�<�<c���\V^,4p\VR,^4F$wr#\V4pWA8wgK\WV3R7h	\V!# \d\T4u#i;i)�:�NN)r�)rp�	enumerater�r�rrr�)r��
first_size�i�itrts*    r`�
_zip_equalr�ss��/���1��&�
��y��}�a�0�E�A��r�7�D��!�+�Z�D�4I�J�J�1�
�I�����/�#�I�.�.�/�s�8A�A�A1�0A1c��\V4.V,pVR8Xd\VRV/#VR8Xd
\V!#VR8Xd
\V!#\	R4h)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�rZ�ignorez Expected fill, strict, or ignore)rsrr�r��
ValueError)rhrg�
incompleter��	iteratorss&&&& r`r0r0�s^��:�h�� �1�$�I��V���I�;��;�;��X���9�%�%��X���I����;�<�<rbc'��"�\\V4p\\V4^R4F/p\	\W44p\\V4Rjx�L
K1	R#L
5i)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).

N���)rjrs�rangerprrrv)r�r��
num_actives*  r`rJrJ�sL����D�)�$�I��C�	�N�A�r�2�
��&��7�8�	��t�Y�'�'�'�3�'�s�AA �A�A c��Vf\p\V^4wr#p\\W44wrV\V\\V44\W643#)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, ' '])

)�boolrrjrr)r�rh�t1�t2�p�p1�p2s&&     r`r=r=�sK��(�|����H�a� �I�B�A�
��T��
�F�B��R��T�2��'��"�)9�:�:rbc�a�\V4o\P!V3Rl\\	S4^,444#)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�<<"�TFp\SV4x�K	R#5ir])r)�.0�r�ss& �r`�	<genexpr>�powerset.<locals>.<genexpr>�s����M�;L�a�|�A�q�1�1�;L���)rfr
r�r�rp)rhr�s&@r`rArA�s2���"	
�X��A����M�5��Q��!��;L�M�M�Mrbc#�"�\4pVPp.pVPpVRJpVF*pV'd	V!V4MTpW�9dV!V4Vx�K*K,	R# \dY�9dT!T4Tx�KPKSi;i5i)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�appendrr)	rhr{�seenset�seenset_add�seenlist�seenlist_add�use_key�element�ks	&&       r`rWrW�s����6�e�G��+�+�K��H��?�?�L���o�G���#�C��L���	����A���
� ����	�� ��Q���
�!�	�s*�AB�A�B�B�:B�B�Bc
��Vf\\^4\V44#\\\\^4\W444#)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']

)rjr rrv)rhr{s&&r`rXrX's<���{��:�a�=�'�(�"3�4�4��t�S��A����(>�?�@�@rbc�4�\WVR7p\W1R7#)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.
)r{�reverse)r{)�sortedrX)rhr{r��	sequenceds&&& r`rVrV6s�� �x�'�:�I��9�.�.rbc#�"�\V4;_uu_4Ve
V!4x�V!4x�K +'giR#;i5i)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��	exceptionr|s&&&r`r2r2Js4���,
�)�	�	����'�M���&�L�	
�	�	�s�A�0�A	�	Ac�,�\\W 4V4#)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'

)rv�filter)rhryr�s&&&r`r-r-gs��"��t�&��0�0rbrc��VUu.uFp\V4NK	upV,p\;QJd.RV4FNK	5#!RV44#uupi)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, repeat=repeat)``.

c3�8"�TFp\V4x�K	R#5ir])r%)r��pools& r`r��!random_product.<locals>.<genexpr>�s���0�%�$�����%�s�)r�)rr�r��poolss$*  r`rHrH{sH�� &*�*�T�T�U�4�[�T�*�V�3�E��5�0�%�0�5�0�5�0�%�0�0�0��
+s�Ac�b�\V4pVf\V4MTp\\W!44#)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�rpr$)rhr�r�s&& r`rGrG�s+����?�D��Y��D�	�A�A�����!�!rbc��a�\V4o\S4p\\\	V4V44p\;QJd.V3RlV4FNK	5#!V3RlV44#)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�6<"�TFpSV,x�K	R#5ir]r��r�r�r�s& �r`r��%random_combination.<locals>.<genexpr>������*�'�Q��a���'���)r�rpr�r$r�)rhr�rg�indicesr�s&&  @r`rFrF�sN�����?�D��D�	�A��V�E�!�H�a�(�)�G��5�*�'�*�5�*�5�*�'�*�*�*rbc��aa�\V4o\S4o\V3Rl\V444p\;QJd.V3RlV4FNK	5#!V3RlV44#)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�:<"�TFp\S4x�K	R#5ir])r#�r�r�rgs& �r`r��6random_combination_with_replacement.<locals>.<genexpr>�s����4�8�a�Y�q�\�\�8�s�c3�6<"�TFpSV,x�K	R#5ir]r�r�s& �r`r�r��r�r�)r�rpr�r�)rhr�r�rgr�s&& @@r`rErE�sM�����?�D��D�	�A��4�5��8�4�4�G��5�*�'�*�5�*�5�*�'�*�*�*rbc�6�\V4p\V4pV^8gW8�d\h^p\WV,
4p\	^V^,4F pWTV,
V,,V,pK"	V^8d	W%,
pV^8gW%8�d\
h.pV'dpWQ,V,V^,
V^,
rpW%8�d)W%,pWTV,
,V,V^,
rEK.VP
VRV,
,4Kw\V4#)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.
r�)r�rpr��minr��
IndexErrorr�)	rhr�r"r�rg�cr�r��results	&&&      r`r9r9�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��
�
�d�2��6�l�#���=�rbc��\V.V4#)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
)�valuerws&&r`rBrB�s���%��(�#�#rbc#�"�\V4RRR1,p\V4p\^.VR7V,p\V\	^V^,
44F!pVPV4\
W4x�K#	R#5i)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

Nrnr�)r�rprr
rr��_sumprod)�signal�kernelrg�windowr^s&&   r`r+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�^�\V4wr#\\W4\V44pW#3#)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.
)rrrr�)�	predicater��trues�afters&&  r`r)r)&s,���r�7�L�E��Y�y�0�#�e�*�=�E��<�rbc��\V^4wrp\VR4\VR4\VR4\WV4#)z�Return overlapping triplets from *iterable*.

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

Nr�)rhr�r��t3s&   r`rUrU9s;���X�q�!�J�B�B���T�N���T�N���T�N��r�r�?�rbc�~�\W4p\V4Fwr4\\WCV4R4K	\	V!#r])rr�rvrr�)rhrgr�r�rws&&   r`�_sliding_window_islicer
Is8���H� �I� ��+����V�H��
#�T�*�,��	�?�rbc#�"�\V4p\\W!^,
4VR7pVF!pVPV4\	V4x�K#	R#5i)r�rnN)rsrrr�r�)rhrgrwrr^s&&   r`�_sliding_window_dequerQsC����H�~�H�
�6�(��E�*�1�
5�F�
���
�
�a���F�m���s�AAc��V^8�d\W4#V^8�d\W4#V^8Xd\V4#V^8Xd\V4#\	RV24h)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`.
zn should be at least one, not )rr
r<r�r�r�s&&r`rMrMZs^��	�2�v�$�X�1�1�	
�Q��%�h�2�2�	
�a����!�!�	
�a���8�}���9�!��=�>�>rbc
��\V4p\\\\	\V4^,4^44p\
\\V4V4#)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.
)	rfr�slicerr�rprjr!r)rh�seq�slicess&  r`rNrNss@���x�.�C�
�U�L��s�3�x�!�|�)<�a�@�
A�F��w��s��V�,�,rbc�N�^.pVFp\\V^V)344pK	V#)uSCompute 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]

Note that polynomial coefficients are specified in descending power order.

Supports all numeric types: int, float, complex, Decimal, Fraction.
)rfr+)�roots�poly�roots&  r`r?r?�s1�� 
�3�D����H�T�A��u�:�.�/����Krbc#�L"�\VRR4pVf4\WV4p\WR4FwrgWqJg	Wq8XgKVx�K	R#Vf\V4MTpV^,
p\	\
4;_uu_4V!W^,V4;px�K +'giR#;i5i)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"N)�getattrrr�rprr�)rhrrl�stop�	seq_indexrwr�r�s&&&&    r`r3r3�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�6B$�;B$�8B�B!	�	B$c#�"�V^8�d^x�^p\R4V^,,p\V^V\V4^,R7Fdp\V^WV,4Rjx�L
\\	\W3,WV,444W#V,WV,1&W3,pKf	\V^V4Rjx�L
R#LdL5i)zYYield the primes less than n.

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

)rN)r�r�)�	bytearrayr3r�bytesrpr�)rgrl�datar�s&   r`rLrL�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 C�"C�#AC�C	�C�	CrZc#��"�V^8d\R4h\V4p\\W144;p'd*V'd\	V4V8wd\R4hVx�KER#5i)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`.
zn must be at least onezbatched(): incomplete batchN)r�rsr�rrp)rhrgrZrw�batchs&&$  r`�_batchedr#�s[���	�1�u��1�2�2��H�~�H����,�-�
-�%�
-��c�%�j�A�o��:�;�;���.�s�AA'�#A'i�
)r(c��\WVR7#)rY)�itertools_batched)rhrgrZs&&$r`r(r(�s�� ��V�<�<rbc��\V!#)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&r`rTrT�s�����rbc�T�\V4\Y4# \dR#i;i)z.Scalars are bytes, strings, and non-iterables.T)rsrr�
isinstance)r�
stringlikes&&r`�
_is_scalarr,s/����U���e�(�(������s��'�'c���\V4p\V4p\T3T4p\	T4'dT#\P
!T4pKE \dTu#i;i)z.Depth-first iterator over scalars in a tensor.)rsrv�
StopIterationr
r,r�)�tensorrwrs&  r`�_flatten_tensorr0	sb���F�|�H�
�	���N�E��%��8�,���e����O��&�&�x�0����	��O�	�s�A�
A!� A!c���\V\4'd!\\P!V4V4#Vvr#\V4p\
\\V4V4p\WR4#)a�Change the shape of a *matrix*.

If *shape* is an integer, the matrix must be two dimensional
and the shape is interpreted as the desired number of columns:

    >>> matrix = [(0, 1), (2, 3), (4, 5)]
    >>> cols = 3
    >>> list(reshape(matrix, cols))
    [(0, 1, 2), (3, 4, 5)]

If *shape* is a tuple (or other iterable), the input matrix can have
any number of dimensions. It will first be flattened and then rebuilt
to the desired shape which can also be multidimensional:

    >>> matrix = [(0, 1), (2, 3), (4, 5)]    # Start with a 3 x 2 matrix

    >>> list(reshape(matrix, (2, 3)))        # Make a 2 x 3 matrix
    [(0, 1, 2), (3, 4, 5)]

    >>> list(reshape(matrix, (6,)))          # Make a vector of length six
    [0, 1, 2, 3, 4, 5]

    >>> list(reshape(matrix, (2, 1, 3, 1)))  # Make 2 x 1 x 3 x 1 tensor
    [(((0,), (1,), (2,)),), (((3,), (4,), (5,)),)]

Each dimension is assumed to be uniform, either all arrays or all scalars.
Flattening stops when the first value in a dimension is a scalar.
Scalars are bytes, strings, and non-iterables.
The reshape iterator stops when the requested shape is complete
or when the input is exhausted, whichever comes first.

)	r*�intr(r
r�r0r	�reversedr)�matrix�shape�	first_dim�dims�
scalar_stream�reshapeds&&    r`rDrDsY��B�%�����u�*�*�6�2�E�:�:���I�#�F�+�M��g�x��~�}�=�H��(�&�&rbc��\V^,4p\\\\	V\V444V4#)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.
)rpr(rrrrT)�m1�m2rgs&& r`r5r5@s0��	�B�q�E�
�A��7�8�W�R��2��%?�@�!�D�Drbc��\^V4Fop^;r#^pV^8XdWW",V,V,pW3,V,V,pW3,V,V,p\W#,
V4pK]W@8wgKmVu#	\R4h)r�zprime or under 5)r�rr�)rgr�r^r_�ds&    r`�_factor_pollardr?Osy���1�a�[���	��
���1�f�����a��A�����a��A�����a��A��A�E�1�
�A��6��H���'�
(�(rbc#�V"�V^8dR#\FpW,'dKVx�W,pK	.pV^8�dV.M.pVFIpVR8g\V4'dVPV4K.\V4pW4W,3,
pKK	\	V4Rjx�L
R#L5i)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.
Ni�)�_primes_below_211r1r�r?r�)rg�prime�primes�todo�facts&    r`r.r.bs����	�1�u��#���)�)��K�
�K�A�#��F��a�%�A�3�R�D�
���v�:��!����M�M�!��"�1�%�D��1�9�%�%�D���f�~���s�B)�A;B)� B'�!B)c	��\V4pV^8Xd\V4!^4#\\\	V4\\
V444p\W4#)a�Evaluate 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

Note that polynomial coefficients are specified in descending power order.

Supports all numeric types: int, float, complex, Decimal, Fraction.
)rp�typerj�powrr3r�r)�coefficientsr^rg�powerss&&  r`r>r>�sI�� 	�L��A��A�v��A�w�q�z��
��f�Q�i��%��(�!3�
4�F��L�)�)rbc�&�\\V4!#)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.
)rrr(s&r`rOrO�s���S��W��rbc�t�\V4p\\^V44p\\	\
W44#)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]

Note that polynomial coefficients are specified in descending power order.

Supports all numeric types: int, float, complex, Decimal, Fraction.
)rpr3r�rfrjr)rIrgrJs&  r`r@r@�s0��	�L��A�
�e�A�q�k�
"�F���C��.�/�/rbc�Z�\\V44FpWV,,pK	V#)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.)rgrBs& r`rSrS�s&��&�V�A�Y���	�%�Z��� ��Hrbc��V^,
V,P4^,
pW,	p^V,V,V8XdV^,'dV^8�gQhW3#)z#Return s, d such that 2**s * d == n)�
bit_length)rgr�r>s&  r`�
_shift_to_oddrP�sQ���a�%�1�� � �"�Q�&�A�	��A�
��F�a�<�1���Q���1��6�1�1��4�Krbc�6�V^8�d"V^,'d^Tu;8:d	V8gQhQh\V^,
4wr#\WV4pV^8XgW@^,
8XdR#\V^,
4F"pWD,V,pW@^,
8XgK!R#	R#)�TF)rPrHr�)rg�baser�r>r^�_s&&    r`�_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��:���
rbc�a�S^8dSR9#S^,'dLS^,'d=S^,'d.S^,'dS^,'dS^
,'gR#\FwrSV8gKM	V3Rl\^@44p\;QJdV3RlV4F'dKR#	R#!V3RlV44#)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.
Fc3�J<"�TFp\^S^,
4x�K	R#5i)rRN)�_private_randranger�s& �r`r��is_prime.<locals>.<genexpr>*s ����A�y�!�#�A�q�1�u�-�-�y�s� #c3�<<"�TFp\SV4x�K	R#5ir])rU)r�rSrgs& �r`r�rY,s����A�5�4�%�a��.�.�5�r�T>rR�����
)�_perfect_testsr��all)rg�limit�basessf  r`r1r1�s����B	�2�v��(�(�(�
��E�E�a�!�e�e��A���!�a�%�%�A��F�F�q�2�v�v��&����u�9��'�B�u�R�y�A���3�A�5�A�3�3�A�3�A�3�A�5�A�A�Arbc��\RV4#)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

N)r)rgs&r`r4r4/s���$��?�rbc�H�\\\\V4V44#)ueNumber 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, 2, 1, 1)
    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)``.

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

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

)rrjrr)�countss*r`r6r6=s��T��D�*�V�,�f�5�6�6rbc
#�F"�VPp.p.p\\4;_uu_4\V\	W1!444V^,x�\V\
W!!444V^,V^,,^,x�Kb +'giR#;i5i)z.Non-windowed running_median() for Python 3.14+N)�__next__rr.rcrr
rd�rw�read�lo�his&   r`�#_running_median_minheap_and_maxheaprmjs{������D�	�B�	�B�	�-�	 �	 ����[��T�V�4�5��Q�%�K��R���T�V�4�5��a�5�2�a�5�=�A�%�%�

!�	 �	 �s�(B!�A#B
�
B	�	B!c
#�N"�VPp.p.p\\4;_uu_4\V\	W1!44)4V^,)x�\V\	W!!4)4)4V^,V^,,
^,x�Kf +'giR#;i5i)zDBackport of non-windowed running_median() for Python 3.13 and prior.N)rhrr.r
rris&   r`�_running_median_minheap_onlyrozs�������D�	�B�	�B�	�-�	 �	 ���R�+�b�$�&�1�1�2��a�5�&�L��R�+�b�4�6�'�2�2�3��a�5�2�a�5�=�A�%�%�

!�	 �	 �s�(B%�A'B�B"	�	B%c#�f"�\4p.pVF�pVPV4\W44\V4V8�d\	W2P44pW5\V4pV^,pV^,'d	W7,M"W7^,
,W7,,^,x�K�	R#5i)z+Yield median of values in a sliding window.N)rr�rrpr�popleft)rwror�orderedr^r�rg�ms&&      r`�_running_median_windowedrt�s�����W�F��G�
���
�
�a���w���w�<�&� ��G�^�^�%5�6�A��
���L��
��F����E�E�g�j��A�����(C�q�'H�H��s�B/B1roc��\V4pVe)\V4pV^8:d\R4h\W!4#\'g\V4#\
V4#)aCumulative median of values seen so far or values in a sliding window.

Set *maxlen* to a positive integer to specify the maximum size
of the sliding window.  The default of *None* is equivalent to
an unbounded window.

For example:

    >>> list(running_median([5.0, 9.0, 4.0, 12.0, 8.0, 9.0]))
    [5.0, 7.0, 5.0, 7.0, 8.0, 8.5]
    >>> list(running_median([5.0, 9.0, 4.0, 12.0, 8.0, 9.0], maxlen=3))
    [5.0, 7.0, 5.0, 9.0, 8.0, 9.0]

Supports numeric types such as int, float, Decimal, and Fraction,
but not complex numbers which are unorderable.

On version Python 3.13 and prior, max-heaps are simulated with
negative values. The negation causes Decimal inputs to apply context
rounding, making the results slightly different than that obtained
by statistics.median().
zWindow size should be positive)rsr"r�rt�_max_heap_availablerorm)rhrorws&$ r`rKrK�sV��.�H�~�H�
���v����Q�;��=�>�>�'��9�9���+�H�5�5�.�x�8�8rb)r�r])r�N)NF)NN)r�N))i�)rR)i��)��I)l�tT7)rRr]�=)l�ay)rRr_�iS_)l;n>�)rRr[r\r]r^)l�p�)rRr[r\r]r^r_)l)rRiEi�$ini��i=�i��k)l�%!H�n
�fW)
rRr[r\r]r^r_��rz�rw�%�))��__doc__�random�bisectrr�collectionsr�
contextlibr�	functoolsrrr	�heapqr
r�	itertoolsrr
rrrrrrrrrrrr�mathrrrr�operatorrrr r!r"r#r$r%�sysr&�__all__�objectr�r�r'rrr[r�ImportErrorrcrdrvrRrPrQr*r8r'r�rCr;r:r7r,r/rIr�r<r�r�r�r�r�r0rJr=rArWrXrVr2r-rHrGrFrEr9rBr+r)rUr
rrMrNr?r3rLr#r(r%rT�strrr,r0rDr5r?r�rAr.r>rOr@rSr`rPrU�RandomrXr1r4r6rmrortrKr�rbr`�<module>r�s�����&���0�0�'����� (�'�:�:�,�,��3��3�
�3��3��	3�
�3��
3��3�
�3��3��3��3��3��3��3�
�3� �!3�"�#3�$
�%3�&�'3�(�)3�*�+3�,�-3�.�/3�0�13�2�33�4�53�6�73�8�93�:�;3�<�=3�>*�?3�@�A3�B�C3�D�E3�F�G3�H�I3�J�K3�L�M3�N�O3�P�Q3�R�S3�T�U3�V�W3�X�Y3�Z�[3�\�]3�^�_3�`
�a3�b�c3�d�e3��j�(��,��t���#�d�+�K�-�(��3���
%� '�$
8� %+�P
4��4!�$�)���;�
%�	,�.�6�	)�8�
,�!�(�(�H���J���
/� %=�P(�$;�8N�**�ZA�/�(�:1�(1��1�("�$
+� +�"'�T$�('�V�&
� ��?�2-��,&;�R*�*�E��(���6�=�u�=��&�&�G�O��G�	�#&�u��)�1�&'�RE�
)� �%��*�%���B*�.�0�&
�2�������&�]�]�_�.�.��-B�`�*7�Z
&� 
&� I�&"9�t�"9��w)���K����-�,�H�-��� ��� ��`���H��sH�%	I3�9J�J�J$�3	J�?J�
J�J�	J!� J!�$	J1�0J1

Youez - 2016 - github.com/yon3zu
LinuXploit