+
    øCiS£  ã                   óh  € R t ^ RIt^ RIHtHt ^ RIHt ^ RIHt ^ RI	H
t
HtHt ^ RIHtHt ^ RIHtHtHtHtHtHtHtHtHtHtHtHtHtHt ^ RIH t H!t!H"t"H#t# ^ R	I$H%t%H&t&H't'H(t(H)t) ^ R
IH*t*H+t+H,t, ^ RI-H.t. . RNRNRNRNRNRNRNRNRNRNRNRNRNRNRNRNRNRNRNRNR NR!NR"NR#NR$NR%NR&NR'NR(NR)NR*NR+NR,NR-NR.NR/NR0NR1NR2NR3NR4NR5NR6NR7NR8NR9NR:NR;NR<NR=Nt/]0! 4       t1 ]2! R>R?7       ]! ]2R>R?7      t3 ^ R@IH5t6  ^ RBIH8t8H9t9 R>t:RD t;R‹RE lt<RF t=RŒRG lt>RŒRH lt?RŒRI lt@]A3RJ ltBRK tC]CtDRL tERM tFRN tGRŒRO ltHRP tI ^ RQIHJtK RR tJ]IP                   ]Jn          ! RS RT]L4      tMRU tNRV tOR�RW ltPRX tQRY tRRZ tSRŒR[ ltTRŒR\ ltURŽR] ltVRŒR^ ltWR�R_ ltXR`^/Ra ltYRŒRb ltZRc t[Rd t\Re t]Rf t^Rg t_Rh t`Ri taRj tbRk tcRl tdRm teRn tfR�Ro ltgRp thRqRC/Rr lti].Rs8¼  d    ^ RtIHjtk RqRC/Ru ltj]iP                   ]jn         M]itjRv tl]m]n33Rw ltoRx tpRy tqRz trR{ ts]t! ]h! ^Ó4      4      tuR| tvR} twR~ txR tyR€ tz. R‘Ot{]
R� 4       t|R‚ t}]Pü                  ! 4       PT                  tRƒ t€R„ t�R… t‚R† tƒR‡ t„Rˆ t…R‰R/RŠ lt†R#   ]4 d    ]2t3 EL‡i ; i  ]7 d    RA t6 EL‘i ; i  ]7 d    RCt: EL–i ; i  ]7 d    ]ItJ ELUi ; i)’a  Imported 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                 ó   € \        W4      # ©N)r,   )ÚxÚys   &&Ú8/usr/lib/python3/dist-packages/more_itertools/recipes.pyÚ<lambda>ra   l   s	   € œJ qÔ,ó    )Úheappush_maxÚheappushpop_maxFc                ó*   € \        \        W4      4      # )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`   rR   rR   x   s   € ô ”�xÓ#Ó$Ð$rb   c                ó,   € \        V \        V4      4      # )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`   rP   rP   ˆ   s   € ô ˆxœ˜u›Ó&Ð&rb   c                ó    €  \        V4      p\        V\        ^ W ,
          4      R4      #   \         d    \	        \        YR7      4      u # 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   )rg   rh   Úsizes   && r`   rQ   rQ   š   sK   € ð8Ü�8‹}ˆô �h¤ A t¥xÓ 0°$Ó7Ð7øô ô /Ü”E˜(Ô-Ó.Ò.ð/ús   ‚* ª AÁAc                óX   € Vf   \        V ^ R7       R# \        \        WV4      R4       R# )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   )Úiteratorrg   s   &&r`   r*   r*   ª   s'   € ð@ 	‚yäˆh˜q×!ô 	ŒV�H Ó# TÖ*rb   c                ó.   € \        \        WR4      V4      # )zmReturns the nth item or a default value.

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

N)rv   r   )rh   rg   Údefaults   &&&r`   r8   r8   Ò   s   € ô ”�x DÓ)¨7Ó3Ð3rb   c                óF   € \        W4      pV F  pV F  p  R# 	   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Ûñ âñ ñ rb   c                ó*   € \        \        W4      4      # )zWReturn the how many times the predicate is true.

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

)Úsumrj   )rh   Úpreds   &&r`   rC   rC   ù   s   € ô Œs�4Ó"Ó#Ð#rb   c                ó,   € \        V \        R4      4      # )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   ©rh   s   &r`   r;   r;     s   € ô �œ6 $›<Ó(Ð(rb   c                óT   € \         P                  ! \        \        V 4      V4      4      # )zjReturns the sequence elements *n* times

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

)r   Úfrom_iterabler   Útuple©rh   rg   s   &&r`   r7   r7     s    € ô ×Òœv¤e¨H£o°qÓ9Ó:Ð:rb   c                ó4   € \        \        \        W4      4      # )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.
)r   rj   r   )Úvec1Úvec2s   &&r`   r,   r,     s   € ô Œs”3˜Ó#Ó$Ð$rb   c                ó.   € \         P                  ! V 4      # )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   € ô ×Ò˜{Ó+Ð+rb   c                ó^   € Vf   \        V \        V4      4      # \        V \        W!4      4      # )a  Call *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]

)r   r   )ÚfuncÚtimesÚargss   &&*r`   rI   rI   7  s,   € ð, ‚}Ü�tœV D›\Ó*Ð*Ü�4œ Ó,Ó-Ð-rb   c                óJ   € \        V 4      w  r\        VR4       \        W4      # )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©r   rv   Úzip)rh   ÚaÚbs   &  r`   Ú	_pairwiser•   R  s"   € ô ˆx‹=�D€AÜˆˆD„MÜˆq‹9Ðrb   )r<   c                 ó   € \        V 4      # r]   )Úitertools_pairwiser‚   s   &r`   r<   r<   f  s   € Ü! (Ó+Ð+rb   c                   ó6   a a€ ] tR tRt oRV 3R lltRtVtV ;t# )ÚUnequalIterablesErroril  c                ó`   <€ R pVe   VRP                   ! V!  ,          p\        SV `	  V4       R# )z Iterables have different lengthsNz/: index 0 has length {}; index {} has length {})ÚformatÚsuperÚ__init__)ÚselfÚdetailsÚmsgÚ	__class__s   && €r`   r�   ÚUnequalIterablesError.__init__m  s8   ø€ Ø0ˆØÒØÐE×MÒMØñõ ˆCô 	‰Ñ˜Örb   © r]   )Ú__name__Ú
__module__Ú__qualname__Ú__firstlineno__r�   Ú__static_attributes__Ú__classdictcell__Ú__classcell__)r¡   Ú__classdict__s   @@r`   r™   r™   l  s   ù‡ € ÷÷ rb   r™   c              #   ó|   "  € \        V R \        /  F$  pV F  pV\        J g   K  \        4       h	  Vx € K&  	  R# 5i)Ú	fillvalueN)r   Ú_markerr™   )Ú	iterablesÚcomboÚvals   &  r`   Ú_zip_equal_generatorr²   w  s:   é € Ü˜iÐ;´7Ô;ˆÛˆCØ”g�~Ü+Ó-Ð-ñ ð Œó	 <ùs   ‚<¦<c                  óè   €  \        V ^ ,          4      p\        V R,          ^4       F$  w  r#\        V4      pWA8w  g   K  \        WV3R7      h	  \        V !  #   \         d    \        T 4      u # i ; i)é    :é   NN)rŸ   )rp   Ú	enumerater™   r’   rr   r²   )r¯   Ú
first_sizeÚiÚitrt   s   *    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Á0A1c                ó¢   € \        V 4      .V,          pVR8X  d   \        VRV/ # VR8X  d
   \        V!  # VR8X  d
   \        V!  # \	        R4      h)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)rs   r   rº   r’   Ú
ValueError)rh   rg   Ú
incompleter­   Ú	iteratorss   &&&& r`   r0   r0   �  s^   € ô: �h“Ð  1Õ$€IØ�VÔÜ˜IÐ;°Ñ;Ð;Ø�XÔÜ˜9Ñ%Ð%Ø�XÔÜ�I‰ÐäÐ;Ó<Ð<rb   c               '  óÄ   "  € \        \        V 4      p\        \        V 4      ^ R4       F/  p\	        \        W4      4      p\        \        V4       Rj  x€L
  K1  	  R#  L
5i)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éÿÿÿÿ)rj   rs   Úrangerp   r   r   rv   )r¯   rÀ   Ú
num_actives   *  r`   rJ   rJ   ·  sL   é € ô ”D˜)Ó$€IÜœC 	›N¨A¨rÖ2ˆ
Üœ& Ó7Ó8ˆ	Ü”t˜YÓ'×'Ò'ó 3á'ùs   ‚AA ÁAÁA c                óª   € V f   \         p \        V^4      w  r#p\        \        W4      4      w  rV\        V\        \        V4      4      \        W64      3# )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, ' '])

)Úboolr   rj   r   r   )r€   rh   Út1Út2ÚpÚp1Úp2s   &&     r`   r=   r=   É  sK   € ð( ‚|Üˆä�H˜aÓ �I€BˆAÜ”�T“Ó�F€BÜ�RœœT 2›Ó'¬°"Ó)9Ð:Ð:rb   c                óŒ   a€ \        V 4      o\        P                  ! V3R l\        \	        S4      ^,           4       4       4      # )a  Yields 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`.
c              3   ó<   <"  € T F  p\        SV4      x € K  	  R # 5ir]   )r   )Ú.0ÚrÚss   & €r`   Ú	<genexpr>Úpowerset.<locals>.<genexpr>÷  s   øé € ÐMÑ;L°aœ|¨A¨q×1Ð1Ó;Lùó   ƒ)rf   r   r„   rÃ   rp   )rh   rÐ   s   &@r`   rA   rA   å  s2   ø€ ô" 	ˆX‹€AÜ×ÒÔM¼5ÄÀQÃÈ!ÅÔ;LÓMÓMÐMrb   c              #  ó  "  € \        4       pVP                  p. pVP                  pVRJpV  F*  pV'       d	   V! V4      MTp W‚9  d   V! V4       Vx € K*  K,  	  R#   \         d    Y„9  d   T! T4       Tx €  KP   KS  i ; i5i)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   )	rh   r{   ÚseensetÚseenset_addÚseenlistÚseenlist_addÚuse_keyÚelementÚks	   &&       r`   rW   rW   ú  sˆ   é € ô6 ‹e€GØ—+‘+€KØ€HØ—?‘?€LØ˜ˆo€Gãˆß#‰C�ŒL¨ˆð	ØÔÙ˜A”Ø”ñ  ó øô ô 	ØÔ Ù˜Q”Ø•ò !ð	üs*   ‚A BÁAÁBÁBÁ:BÂ BÂBc           
     óž   € Vf   \        \        ^ 4      \        V 4      4      # \        \        \        \        ^4      \        W4      4      4      # )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']

)rj   r    r   rv   )rh   r{   s   &&r`   rX   rX   '  s<   € ð ‚{Ü”:˜a“=¤'¨(Ó"3Ó4Ð4äŒt”Sœ A›¬°Ó(>Ó?Ó@Ð@rb   c                ó4   € \        WVR7      p\        W1R7      # )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   )rh   r{   rá   Ú	sequenceds   &&& r`   rV   rV   6  s   € ô  �x°'Ô:€IÜ˜9Ô.Ð.rb   c              #  óŒ   "  € \        V4      ;_uu_ 4        Ve
   V! 4       x €  V ! 4       x € K    + '       g   i     R# ; i5i)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`   r2   r2   J  s4   é € ô, 
�)×	Õ	ØÒÙ“'ŠMØÙ“&ŒL÷	 
×	Ð	üs   ‚A–0°A	»	Ac                ó,   € \        \        W 4      V4      # )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)rh   ry   r€   s   &&&r`   r-   r-   g  s   € ô" ”�tÓ&¨Ó0Ð0rb   r   c                ó¨   € V Uu. uF  p\        V4      NK  	  upV ,          p\         ;QJ d    . R V 4       F  NK  	  5# ! R V 4       4      # u upi )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)``.

c              3   ó8   "  € T F  p\        V4      x € K  	  R # 5ir]   )r%   )rÎ   Úpools   & r`   rÑ   Ú!random_product.<locals>.<genexpr>Œ  s   é € Ð0©% $”˜—�«%ùs   ‚)r…   )r   r�   rê   Úpoolss   $*  r`   rH   rH   {  sH   € ñ  &*Ó*¡T˜TŒU�4Ž[¡TÑ*¨VÕ3€EßŒ5Ñ0©%Ó0�5Ð0ˆ5Ñ0©%Ó0Ó0Ð0ùò +s   …Ac                ób   € \        V 4      pVf   \        V4      MTp\        \        W!4      4      # )aF  Return 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…   rp   r$   )rh   rÏ   rê   s   && r`   rG   rG   �  s+   € ô �‹?€DØ’YŒˆDŒ	 A€AÜ”˜“Ó!Ð!rb   c                óÐ   a€ \        V 4      o\        S4      p\        \        \	        V4      V4      4      p\         ;QJ d    . V3R lV 4       F  NK  	  5# ! V3R lV 4       4      # )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)``.

c              3   ó6   <"  € T F  pSV,          x € K  	  R # 5ir]   r£   ©rÎ   r¸   rê   s   & €r`   rÑ   Ú%random_combination.<locals>.<genexpr>®  ó   øé € Ð*¡'˜Q��a—’£'ùó   ƒ)r…   rp   râ   r$   rÃ   )rh   rÏ   rg   Úindicesrê   s   &&  @r`   rF   rF   ¡  sN   ø€ ô �‹?€DÜˆD‹	€AÜ”VœE !›H aÓ(Ó)€GßŒ5Ô*¡'Ó*�5Ð*ˆ5Ô*¡'Ó*Ó*Ð*rb   c                óÒ   aa€ \        V 4      o\        S4      o\        V3R l\        V4       4       4      p\         ;QJ d    . V3R lV 4       F  NK  	  5# ! V3R lV 4       4      # )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)``.

c              3   ó:   <"  € T F  p\        S4      x € K  	  R # 5ir]   )r#   ©rÎ   r¸   rg   s   & €r`   rÑ   Ú6random_combination_with_replacement.<locals>.<genexpr>¾  s   øé € Ð4©8 a”Y˜q—\�\«8ùs   ƒc              3   ó6   <"  € T F  pSV,          x € K  	  R # 5ir]   r£   rð   s   & €r`   rÑ   rø   ¿  rò   ró   )r…   rp   râ   rÃ   )rh   rÏ   rô   rg   rê   s   && @@r`   rE   rE   ±  sM   ù€ ô �‹?€DÜˆD‹	€AÜÔ4¬5°¬8Ó4Ó4€GßŒ5Ô*¡'Ó*�5Ð*ˆ5Ô*¡'Ó*Ó*Ð*rb   c                ó6  € \        V 4      p\        V4      pV^ 8  g   W8”  d   \        h^p\        WV,
          4      p\	        ^V^,           4       F   pWTV,
          V,           ,          V,          pK"  	  V^ 8  d	   W%,          pV^ 8  g   W%8¼  d   \
        h. pV'       dp   WQ,          V,          V^,
          V^,
          rpW%8¼  d)   W%,          pWTV,
          ,          V,          V^,
          rEK.  VP                  VRV,
          ,          4       Kw  \        V4      # )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…   rp   r¾   ÚminrÃ   Ú
IndexErrorr×   )	rh   rÏ   r"   rê   rg   ÚcrÞ   r¸   Úresults	   &&&      r`   r9   r9   Â  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Ö#ä�‹=Ðrb   c                ó   € \        V .V4      # )a  Yield *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   )Úvaluerw   s   &&r`   rB   rB   ì  s   € ô �%�˜(Ó#Ð#rb   c              #  óü   "  € \        V4      RRR1,          p\        V4      p\        ^ .VR7      V,          p\        V \	        ^ V^,
          4      4       F!  pVP                  V4       \        W4      x € K#  	  R# 5i)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

Nrn   rÂ   )r…   rp   r   r   r   r×   Ú_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                ó^   € \        V4      w  r#\        \        W4      \        V4      4      pW#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.
)r   r   r   r’   )Ú	predicater¹   ÚtruesÚafters   &&  r`   r)   r)   &  s,   € ô �r“7�L€EÜ”Y˜yÓ0´#°e³*Ó=€EØˆ<Ðrb   c                ó€   € \        V ^4      w  rp\        VR4       \        VR4       \        VR4       \        WV4      # )z�Return overlapping triplets from *iterable*.

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

Nr‘   )rh   rÇ   rÈ   Út3s   &   r`   rU   rU   9  s;   € ô �X˜qÓ!�J€BˆBÜˆˆT„NÜˆˆT„NÜˆˆT„NÜˆr�r‹?Ðrb   c                 ó~   € \        W4      p\        V4       F  w  r4\        \        WCV4      R 4       K  	  \	        V!  # r]   )r   r¶   rv   r   r’   )rh   rg   rÀ   r¸   rw   s   &&   r`   Ú_sliding_window_islicer  I  s8   € ä�HÓ €IÜ  Ö+‰ˆÜŒV�H Ó# TÖ*ñ ,ä�	‰?Ðrb   c              #   ó¬   "  € \        V 4      p\        \        W!^,
          4      VR7      pV F!  pVP                  V4       \	        V4      x € K#  	  R# 5i)rµ   rn   N)rs   r   r   r×   r…   )rh   rg   rw   r  r^   s   &&   r`   Ú_sliding_window_dequer  Q  sC   é € ä�H‹~€HÜ”6˜(¨¥EÓ*°1Ô5€FÛˆØ�‰�aÔÜ�F‹mÔó ùs   ‚AAc                ó®   € V^8”  d   \        W4      # V^8”  d   \        W4      # V^8X  d   \        V 4      # V^8X  d   \        V 4      # \	        RV 24      h)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`.
zn should be at least one, not )r  r  r<   r’   r¾   r†   s   &&r`   rM   rM   Z  s^   € ð 	ˆ2„vÜ$ XÓ1Ð1Ø	
ˆQŒÜ% hÓ2Ð2Ø	
ˆaŒÜ˜Ó!Ð!Ø	
ˆaŒÜ�8‹}ÐäÐ9¸!¸Ð=Ó>Ð>rb   c           
     ó²   € \        V 4      p\        \        \        \	        \        V4      ^,           4      ^4      4      p\        \        \        V4      V4      # )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.
)	rf   r   Úslicer   rÃ   rp   rj   r!   r   )rh   ÚseqÚslicess   &  r`   rN   rN   s  s@   € ô ˆx‹.€CÜ”UœL¬¬s°3«x¸!­|Ó)<¸aÓ@ÓA€FÜŒwœ˜s› VÓ,Ð,rb   c                óN   € ^.pV  F  p\        \        V^V) 34      4      pK  	  V# )uS  Compute 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.
)rf   r+   )ÚrootsÚpolyÚroots   &  r`   r?   r?   �  s1   € ð  ˆ3€DÛˆÜ”H˜T A¨ u :Ó.Ó/Šñ à€Krb   c              #  óL  "  € \        V RR4      pVf4   \        WV4      p\        WR4       F  w  rgWqJ g	   Wq8X  g   K  Vx € K  	  R# Vf   \        V 4      MTpV^,
          p\	        \
        4      ;_uu_ 4         V! W^,           V4      ;px € K    + '       g   i     R# ; i5i)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)Úgetattrr   r¶   rp   r   r¾   )rh   r   rl   ÚstopÚ	seq_indexrw   r¸   rÝ   s   &&&&    r`   r3   r3   —  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$Á8BÂB!	Â	B$c              #  óš  "  € V ^8”  d   ^x € ^p\        R4      V ^,          ,          p\        V^V\        V 4      ^,           R7       Fd  p\        V^WV,          4       Rj  x€L
  \        \	        \        W3,          WV,           4      4      4      W#V,          WV,           1&   W3,          pKf  	  \        V^V4       Rj  x€L
  R#  Ld L5i)zYYield the primes less than n.

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

)r  N)r´   rµ   )Ú	bytearrayr3   r   Úbytesrp   rÃ   )rg   rl   ÚdatarÉ   s   &   r`   rL   rL   À  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Á#ACÃ C	ÃCÃ	CrZ   c             #  óÒ   "  € V^8  d   \        R4      h\        V 4      p\        \        W14      4      ;p'       d*   V'       d   \	        V4      V8w  d   \        R4      hVx € KE  R# 5i)ar  Batch 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`.
zn must be at least onezbatched(): incomplete batchN)r¾   rs   r…   r   rp   )rh   rg   rZ   rw   Úbatchs   &&$  r`   Ú_batchedr#  Õ  s[   é € ð 	ˆ1„uÜÐ1Ó2Ð2Ü�H‹~€HÜœ Ó,Ó-Ð
-ˆ%Ö
-ß”c˜%“j A”oÜÐ:Ó;Ð;ØŒñ .ùs   ‚AA'Á#A'i¢ )r(   c                ó   € \        WVR 7      # )rY   )Úitertools_batched)rh   rg   rZ   s   &&$r`   r(   r(   ì  s   € Ü  °VÔ<Ð<rb   c                ó   € \        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`   rT   rT   ô  s   € ô ˜ÑÐrb   c                óT   €  \        V 4       \        Y4      #   \         d     R# i ; i)z.Scalars are bytes, strings, and non-iterables.T)rs   rr   Ú
isinstance)r   Ú
stringlikes   &&r`   Ú
_is_scalarr,     s/   € ðÜˆUŒô �eÓ(Ð(øô ô Úðús   ‚ ˜'¦'c                óÈ   € \        V 4      p  \        V4      p\        T3T4      p\	        T4      '       d   T# \        P
                  ! T4      pKE    \         d    Tu # i ; i)z.Depth-first iterator over scalars in a tensor.)rs   rv   ÚStopIterationr   r,  r„   )Útensorrw   r   s   &  r`   Ú_flatten_tensorr0  	  sb   € ä�F‹|€HØ
ð	Ü˜“NˆEô ˜%˜ 8Ó,ˆÜ�e×ÒØˆOÜ×&Ò& xÓ0Šøô ô 	ØŠOð	ús   ŽA ÁA!Á A!c                óÔ   € \        V\        4      '       d!   \        \        P                  ! V 4      V4      # Vvr#\        V 4      p\        \        \        V4      V4      p\        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„   r0  r	   Úreversedr   )ÚmatrixÚshapeÚ	first_dimÚdimsÚscalar_streamÚreshapeds   &&    r`   rD   rD     sY   € ôB �%œ×ÒÜ”u×*Ò*¨6Ó2°EÓ:Ð:ØÐ€IÜ# FÓ+€MÜ”gœx¨›~¨}Ó=€HÜ�(Ó&Ð&rb   c                ó€   € \        V^ ,          4      p\        \        \        \	        V \        V4      4      4      V4      # )a  Multiply 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.
)rp   r(   r   r  r   rT   )Úm1Úm2rg   s   && r`   r5   r5   @  s0   € ô 	ˆBˆq�E‹
€AÜ”7œ8¤W¨R´¸2³Ó%?Ó@À!ÓDÐDrb   c                 ó  € \        ^V 4       Fo  p^;r#^pV^8X  dW   W",          V,           V ,          pW3,          V,           V ,          pW3,          V,           V ,          p\        W#,
          V 4      pK]  W@8w  g   Km  Vu # 	  \        R4      h)rµ   zprime or under 5)rÃ   r   r¾   )rg   r”   r^   r_   Úds   &    r`   Ú_factor_pollardr?  O  sy   € ô �1�aŽ[ˆØˆ	ˆØˆØ�1ŒfØ•˜•˜a•ˆAØ•˜•˜a•ˆAØ•˜•˜a•ˆAÜ�A•E˜1“ŠAØŽ6ØŠHñ ô Ð'Ó
(Ð(rb   c              #  óV  "  € V ^8  d   R# \          F  pW,          '       d   K  Vx € W,          p K  	  . pV ^8”  d   V .M. pV FI  p V R8  g   \        V 4      '       d   VP                  V 4       K.  \        V 4      pW4W,          3,          pKK  	  \	        V4       Rj  x€L
  R#  L5i)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_211r1   r×   r?  râ   )rg   ÚprimeÚprimesÚtodoÚfacts   &    r`   r.   r.   b  s“   é € ð 	ˆ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           	     ó¶   € \        V 4      pV^ 8X  d   \        V4      ! ^ 4      # \        \        \	        V4      \        \        V4      4      4      p\        W4      # )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   Úpowr   r3  rÃ   r  )Úcoefficientsr^   rg   Úpowerss   &&  r`   r>   r>   ƒ  sI   € ô  	ˆLÓ€AØˆA„vÜ�AŒw�q‹zÐÜ””f˜Q“i¤¬%°«(Ó!3Ó4€FÜ�LÓ)Ð)rb   c                ó&   € \        \        V 4      !  # )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  r   r(  s   &r`   rO   rO   š  s   € ô ”S˜“WÑÐrb   c                ót   € \        V 4      p\        \        ^V4      4      p\        \	        \
        W4      4      # )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.
)rp   r3  rÃ   rf   rj   r   )rI  rg   rJ  s   &  r`   r@   r@   ¥  s0   € ô 	ˆLÓ€AÜ”e˜A˜q“kÓ"€FÜ””C˜Ó.Ó/Ð/rb   c                óZ   € \        \        V 4      4       F  pW V,          ,          p K  	  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.   )rg   rB  s   & r`   rS   rS   ¸  s&   € ô& ”V˜A“Y–ˆØ	�%�Z�Šñ  à€Hrb   c                ó¼   € V ^,
          V ,          P                  4       ^,
          pW,	          p^V,          V,          V 8X  d   V^,          '       d   V^ 8¼  g   Q hW3# )z#Return s, d such that 2**s * d == n)Ú
bit_length)rg   rÐ   r>  s   &  r`   Ú_shift_to_oddrP  à  sQ   € ð ˆa�%�1�× Ñ Ó" QÕ&€AØ	�€AØ��F�a�<˜1Ô  Q§¤¨1°¬6Ð1Ð1Øˆ4€Krb   c                 ó6  € V ^8”  d"   V ^,          '       d   ^Tu;8:  d	   V 8  g   Q h Q h\        V ^,
          4      w  r#\        WV 4      pV^8X  g   W@^,
          8X  d   R# \        V^,
          4       F"  pWD,          V ,          pW@^,
          8X  g   K!   R# 	  R# )é   TF)rP  rH  rÃ   )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•Ž:Úñ ñ
 rb   c                ó¢  a € S ^8  d   S R9   # S ^,          '       dL   S ^,          '       d=   S ^,          '       d.   S ^,          '       d   S ^,          '       d   S ^,          '       g   R# \          F  w  rS V8  g   K   M	  V 3R l\        ^@4       4       p\        ;QJ d    V 3R lV 4       F  '       d   K   R# 	  R# ! V 3R lV 4       4      # )am  Return ``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.
Fc              3   óJ   <"  € T F  p\        ^S^,
          4      x € K  	  R# 5i)rR  N)Ú_private_randranger÷   s   & €r`   rÑ   Úis_prime.<locals>.<genexpr>*  s    øé € ÐA±y°!Ô# A q¨1¥u×-Ð-³yùs   ƒ #c              3   ó<   <"  € T F  p\        SV4      x € K  	  R # 5ir]   )rU  )rÎ   rS  rg   s   & €r`   rÑ   rY  ,  s   øé € ÐA¹5°4Ô% a¨×.Ð.»5ùrÓ   T>   rR  é   é   é   é   é   )Ú_perfect_testsrÃ   Úall)rg   ÚlimitÚbasess   f  r`   r1   r1   ÿ  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ÐArb   c                ó   € \        RV 4      # )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   )rg   s   &r`   r4   r4   /  s   € ô �$˜‹?Ðrb   c                 óH   € \        \        \        \        V 4      V 4      4      # )ue  Number 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

)r   rj   r   r   )Úcountss   *r`   r6   r6   =  s   € ôT ””Dœ* VÓ,¨fÓ5Ó6Ð6rb   c           
   #  óF  "  € V P                   p. p. p\        \        4      ;_uu_ 4         \        V\	        W1! 4       4      4       V^ ,          x € \        V\        W!! 4       4      4       V^ ,          V^ ,          ,           ^,          x € Kb    + '       g   i     R# ; i5i)z.Non-windowed running_median() for Python 3.14+N)Ú__next__r   r.  rc   r   r
   rd   ©rw   ÚreadÚloÚhis   &   r`   Ú#_running_median_minheap_and_maxheaprm  j  s{   é € ð ×Ñ€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  "  € V P                   p. p. p\        \        4      ;_uu_ 4         \        V\	        W1! 4       4      ) 4       V^ ,          ) x € \        V\	        W!! 4       ) 4      ) 4       V^ ,          V^ ,          ,
          ^,          x € Kf    + '       g   i     R# ; i5i)zDBackport of non-windowed running_median() for Python 3.13 and prior.N)rh  r   r.  r
   r   ri  s   &   r`   Ú_running_median_minheap_onlyro  z  s…   é € ð ×Ñ€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  "  € \        4       p. pV  Fš  pVP                  V4       \        W44       \        V4      V8”  d   \	        W2P                  4       4      pW5 \        V4      pV^,          pV^,          '       d	   W7,          M"W7^,
          ,          W7,          ,           ^,          x € Kœ  	  R# 5i)z+Yield median of values in a sliding window.N)r   r×   r   rp   r   Úpopleft)rw   ro   r  Ú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/B1ro   c               ó´   € \        V 4      pVe)   \        V4      pV^ 8:  d   \        R4      h\        W!4      # \        '       g   \        V4      # \        V4      # )a  Cumulative 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().
zWindow size should be positive)rs   r"   r¾   rt  Ú_max_heap_availablero  rm  )rh   ro   rw   s   &$ r`   rK   rK   �  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 )rR  r]  é=   )l   Áay)rR  r_  é   iS_ )l   ;n>Ô)rR  r[  r\  r]  r^  )l   ßp¤)rR  r[  r\  r]  r^  r_  )l            )rR  iE  iŸ$  in  i×à i=• iþ‘k)l   ý%!HÈn•fW )rR  r[  r\  r]  r^  r_  é   é   rz  é   rw  é%   é)   )‡Ú__doc__ÚrandomÚbisectr   r   Úcollectionsr   Ú
contextlibr   Ú	functoolsr   r   r	   Úheapqr
   r   Ú	itertoolsr   r   r   r   r   r   r   r   r   r   r   r   r   r   Úmathr   r   r   r   Úoperatorr   r   r    r!   r"   r#   r$   r%   Úsysr&   Ú__all__Úobjectr®   r’   r'  rr   r[   r  ÚImportErrorrc   rd   rv  rR   rP   rQ   r*   r8   r'   rÆ   rC   r;   r:   r7   r,   r/   rI   r•   r<   r—   r¾   r™   r²   rº   r0   rJ   r=   rA   rW   rX   rV   r2   r-   rH   rG   rF   rE   r9   rB   r+   r)   rU   r  r  rM   rN   r?   r3   rL   r#  r(   r%  rT   Ústrr  r,  r0  rD   r5   r?  r…   rA  r.   r>   rO   r@   rS   r`  rP  rU  ÚRandomrX  r1   r4   r6   rm  ro  rt  rK   r£   rb   r`   Ú<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ð@ ðA3ðB ðC3ðD ðE3ðF ðG3ðH ðI3ðJ ðK3ðL ðM3ðN ðO3ðP ðQ3ðR ðS3ðT ðU3ðV ðW3ðX ðY3ðZ ð[3ð\ ð]3ð^ ð_3ð` ða3ðb ðc3ðd ðe3€ñj ‹(€ð,ÙˆtÕñ ˜# dÔ+€Kð-Ý(ðß3ð Ðò%ô 'ò$8ô %+ôP
4ôð4 !ô $ò)ð €ò;ò
%ò	,ô.ò6ð	)Ý8ò
,ð !×(Ñ(€HÔô˜Jô òò/ô %=òP(ò$;ò8Nô**ô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 Ã9J Ä J ÅJ$ É3	J É?J Ê
JÊJÊ	J!Ê J!Ê$	J1Ê0J1