+
    þÎjQµ  ã                   óT  € R t ^ RIt^ RIHtHt ^ RIHt ^ RIHt ^ RI	H
t
 ^ RI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 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.H/t/ ^ RIH0t0H1t1H2t2H3t3 ^ RI4H5t5 . 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R>NR?NR@NRANRBNRCNRDNt6]7! 4       t8 ^ REIH9t9H:t: RFt;RH t=R”RI lt>RJ t?R•RK lt@R•RL ltAR•RM ltB]C3RN ltDRO tE]EtFRP tGRQ tH ^ RRI#HItJ RS tKR•RT ltLRU tR–RV ltMRW tNRX tORY tPR•RZ ltQR•R[ ltRR—R\ ltSR•R] ltTR˜R^ ltUR_^/R` ltVR•Ra ltWRb tXRc tYRd tZRe t[Rf t\Rg t]Rh t^Ri t_Rj t`Rk taRl tbRm tcR™Rn ltdRo teRpRG/Rq ltf]5Rr8¼  d    ^ RsIHgth RpRG/Rt ltg]fP                   ]gn         M]ftgRu ti]j]k33Rv ltlRw tmRx tnRy toRz tp]q! ]e! ^Ó4      4      trR{ tsR| ttR} tuR~ tvR tw. RšOtx]R€ 4       tyR� tz]Pö                  ! 4       P`                  t|R‚ t}Rƒ t~R„ tR… t€R† t�R‡ t‚RˆR/R‰ ltƒRŠ t„RˆR/R‹ lt…RŒ t†RˆR/R� lt‡RŽ tˆRˆR/R� lt‰]
! RFRFR�7       ! R‘ R4      4       tŠRˆR/R’ lt‹R“ tŒR#   ]< d    RGt; EL�i ; i  ]< d    ]HtJ ELmi ; 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)Ú	dataclass)Ú	lru_cacheÚreduce)ÚheappushÚheappushpop)Ú
accumulateÚchainÚcombinationsÚcompressÚcountÚcycleÚfilterfalseÚgroupbyÚisliceÚpairwiseÚproductÚrepeatÚstarmapÚ	takewhileÚteeÚzip_longest)ÚprodÚcombÚisqrtÚgcd)ÚmulÚgetitemÚindexÚis_Ú
itemgetterÚtruediv)Ú	randrangeÚsampleÚchoiceÚshuffle)Ú
hexversionÚStatsÚ	all_equalÚbatchedÚbefore_and_afterÚconsumeÚconvolveÚ
dotproductÚfactorÚ
first_trueÚflattenÚgrouperÚis_primeÚiter_exceptÚ
iter_indexÚloopsÚmatmulÚmultinomialÚncyclesÚnthÚnth_combinationÚpad_noneÚpadnoner   Ú	partitionÚpolynomial_derivativeÚpolynomial_evalÚpolynomial_from_rootsÚpowersetÚprependÚquantifyÚrandom_combinationÚ#random_combination_with_replacementÚrandom_derangementÚrandom_permutationÚrandom_productÚ
repeatfuncÚreshapeÚ
roundrobinÚrunning_maxÚrunning_meanÚrunning_medianÚrunning_minÚrunning_statisticsÚsieveÚsliding_windowÚ	subslicesÚsum_of_squaresÚtabulateÚtailÚtakeÚtotientÚ	transposeÚ
triplewiseÚuniqueÚunique_everseenÚunique_justseen)Úheappush_maxÚheappushpop_maxTFc                ó*   € \        \        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   &&ÚL/opt/data/home/.local/lib/python3.14/site-packages/more_itertools/recipes.pyr[   r[   q   s   € ô ”�xÓ#Ó$Ð$ó    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   &&rh   rY   rY   �   s   € ô ˆxœ˜u›Ó&Ð&ri   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   )rf   rg   Úsizes   && rh   rZ   rZ   “   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

Nro   )r   Únextr   )Úiteratorrf   s   &&rh   r/   r/   £   s'   € ð@ 	‚yäˆh˜q×!ô 	ŒV�H Ó# TÖ*ri   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)rw   r   )rg   rf   Údefaults   &&&rh   r=   r=   Ë   s   € ô ”�x DÓ)¨7Ó3Ð3ri   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   )rg   Úkeyrx   ÚfirstÚseconds   &&   rh   r,   r,   Ø   s-   € ô$ �xÓ%€HÛˆÛˆFÛñ âñ ñ ri   c                ó*   € \        \        W4      4      # )zŽReturn the how many times the predicate is true.

>>> quantify([True, False, True])
2
>>> quantify(range(100, 200), pred=lambda x: x<120)
20

)Úsumrk   )rg   Úpreds   &&rh   rG   rG   ò   s   € ô Œs�4Ó"Ó#Ð#ri   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   ©rg   s   &rh   r?   r?   þ   s   € ô �œ6 $›<Ó(Ð(ri   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©rg   rf   s   &&rh   r<   r<     s    € ô ×Òœv¤e¨H£o°qÓ9Ó:Ð:ri   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€   rk   r    )Úvec1Úvec2s   &&rh   r1   r1     s   € ô Œs”3˜Ó#Ó$Ð$ri   )Úsumprodc                ó.   € \         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…   )Úlist_of_listss   &rh   r4   r4   -  s   € ô ×Ò˜}Ó-Ð-ri   c                ó^   € Vf   \        V \        V4      4      # \        V \        W!4      4      # )a  Call *function* 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   )rl   ÚtimesÚargss   &&*rh   rM   rM   9  s,   € ð, ‚}Ü�x¤¨£Ó.Ð.Ü�8œV DÓ0Ó1Ð1ri   c                ó   € \        V 4      # )zo
Wrapper for :func:`itertools.pairwise`.

.. deprecated:: 11.0.0
   Will be removed in a future major release.
)Úitertools_pairwiserƒ   s   &rh   r   r   T  s   € ô ˜hÓ'Ð'ri   c                ó¬   € \        V 4      .V,          pT;R8X  d    \        VRV/ # ;R8X  d    \        VRR/ # R8X  d
   \        V!  #  \        R4      h)aj  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 `ValueError` will be raised.

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

ÚfillÚ	fillvalueÚstrictTÚignorez Expected fill, strict, or ignore)rt   r   ÚzipÚ
ValueError)rg   rf   Ú
incompleter•   Ú	iteratorss   &&&& rh   r5   r5   ^  sZ   € ô: �h“Ð  1Õ$€IØ
ÞÝ 	Ð?°YÑ?Ð?ÞÝ˜	Ð/¨$Ñ/Ð/ÝÜ˜	‘?Ð"ØÜÐ?Ó@Ð@ri   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éÿÿÿÿ)rk   rt   Úrangerq   r   r   rw   )Ú	iterablesr›   Ú
num_actives   *  rh   rO   rO   ‡  sL   é € ô ”D˜)Ó$€IÜœC 	›N¨A¨rÖ2ˆ
Üœ& Ó7Ó8ˆ	Ü”t˜YÓ'×'Ò'ó 3á'ùs   ‚AA ÁAÁA c                óŽ   a aaa€ S f   \         o \        V4      o\        4       o\        4       oVVV V3R lpV! S4      V! S4      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, ' '])

c              3   ó¾   <"  € SP                   pSP                   p V '       d   V P                  4       x € K  S F  pS! V4      '       d   TMT! V4        K=  	  R# 5i)TN)ÚappendÚpopleft)ÚqueueÚappend_falseÚappend_trueÚvalueÚfalse_queuerx   r�   Ú
true_queues   &   €€€€rh   ÚgenÚpartition.<locals>.gen´  sU   øé € Ø"×)Ñ)ˆØ ×'Ñ'ˆØßØ—m‘m“oÔ%Û!�Ù $ U§¢‘°Ð=¸uÔEÚñ "ñ ùs
   ƒ!A¥8A)Úboolrt   r   )r�   rg   r«   r©   rx   rª   s   f& @@@rh   rA   rA   ™  sF   û€ ð( ‚|ÜˆÜ�H‹~€Hä“'€KÜ“€J÷
ð 
ñ ˆ{Ó™S ›_Ð,Ð,ri   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©N)r   )Ú.0ÚrÚss   & €rh   Ú	<genexpr>Úpowerset.<locals>.<genexpr>Õ  s   øé € ÐMÑ;L°aœ|¨A¨q×1Ð1Ó;Lùó   ƒ)re   r   r…   rž   rq   )rg   r³   s   &@rh   rE   rE   Ã  s2   ø€ ô" 	ˆX‹€AÜ×ÒÔM¼5ÄÀQÃÈ!ÅÔ;LÓMÓMÐMri   c              #  óî   "  € \        4       pVf5   \        VP                  V 4       F  pVP                  V4       Vx € K  	  R# V  F(  pV! V4      pWB9  g   K  VP                  V4       Vx € K*  	  R# 5i)aÛ  Yield unique elements, preserving order. Remember all elements ever seen.

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

Raises ``TypeError`` for unhashable items.

Some unhashable objects can be converted to hashable objects
using the *key* parameter:

* For ``list`` objects, try ``key=tuple``.
* For ``set`` objects, try ``key=frozenset``.
* For ``dict`` objects, try ``key=lambda x: frozenset(x.items())``
  or in Python 3.15 and later, set ``key=frozendict``.

Alternatively, consider the ``unique()`` itertool recipe.  It sorts
the data and then uses equality to eliminate duplicates.  Hashability
is not required.

N)Úsetr   Ú__contains__Úadd)rg   r|   ÚseenÚelementÚks   &&   rh   r`   r`   Ø  sf   é € ô. ‹5€DØ
‚{Ü" 4×#4Ñ#4°hÖ?ˆGØ�H‰H�WÔØŒMó @ó  ˆGÙ�G“ˆAØŽ}Ø—‘˜”Ø”ó	  ùs   ‚AA5ÁA5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']

)rk   r$   r   rw   )rg   r|   s   &&rh   ra   ra   ü  s<   € ð ‚{Ü”:˜a“=¤'¨(Ó"3Ó4Ð4äŒt”Sœ A›¬°Ó(>Ó?Ó@Ð@ri   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|   )Úsortedra   )rg   r|   rÀ   Ú	sequenceds   &&& rh   r_   r_     s   € ô  �x°'Ô:€IÜ˜9Ô.Ð.ri   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(function, sentinel)``, but uses an exception instead of a sentinel
to end the loop.

Examples:
    iter_except(functools.partial(heappop, h), IndexError)   # priority queue iterator
    iter_except(d.popitem, KeyError)                         # non-blocking dict iterator
    iter_except(d.popleft, IndexError)                       # non-blocking deque iterator
    iter_except(q.get_nowait, Queue.Empty)                   # loop over a producer Queue
    iter_except(s.pop, KeyError)                             # non-blocking set iterator

Multiple exceptions can be specified as a stopping condition, for example
``(IndexError, TypeError)``.

Nr   )rl   Ú	exceptionr}   s   &&&rh   r7   r7     s5   é € ô$ 
�)×	Õ	ØÒÙ“'ŠMØÙ“*Ô÷	 
×	Ð	ü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'

)rw   Úfilter)rg   rz   r�   s   &&&rh   r3   r3   8  s   € ô" ”�tÓ&¨Ó0Ð0ri   r   c                ót   € \        \        \         V4      4      V ,          p\        \        \        V4      4      # )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 is equivalent to taking a random selection from
``itertools.product(*args, repeat=repeat)``.

)r†   rk   r(   )r   rŸ   Úpoolss   $* rh   rL   rL   L  s,   € ô  ”#”e˜YÓ'Ó(¨6Õ1€EÜ””V˜UÓ#Ó$Ð$ri   c                ób   € \        V 4      pVf   \        V4      MTp\        \        W!4      4      # )aI  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 is equivalent to taking a random selection from
``itertools.permutations(iterable, r)``.

)r†   rq   r'   )rg   r²   Úpools   && rh   rK   rK   `  s+   € ô �‹?€DØ’YŒˆDŒ	 A€AÜ”˜“Ó!Ð!ri   c                ó¶   € \        V 4      p\        V4      p\        \        \	        V4      V4      4      p\        V Uu. uF  qRV,          NK  	  up4      # u upi )zîReturn a random *r* length subsequence of the elements in *iterable*.

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

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

)r†   rq   rÁ   r'   rž   )rg   r²   rÊ   rf   ÚindicesÚis   &&    rh   rH   rH   r  sL   € ô �‹?€DÜˆD‹	€AÜ”VœE !›H aÓ(Ó)€GÜ¡7Ó+¡7˜a�q—'�'¡7Ñ+Ó,Ð,ùÒ+s   ¾Ac                ó¸   a€ \        V 4      p\        V4      o\        V3R l\        V4       4       4      p\        V Uu. uF  qBV,          NK  	  up4      # u upi )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 is 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Í   rf   s   & €rh   r´   Ú6random_combination_with_replacement.<locals>.<genexpr>�  s   øé € Ð4©8 a”Y˜q—\�\«8ùs   ƒ)r†   rq   rÁ   rž   )rg   r²   rÊ   rÌ   rÍ   rf   s   &&   @rh   rI   rI   ‚  sL   ø€ ô �‹?€DÜˆD‹	€AÜÔ4¬5°¬8Ó4Ó4€GÜ¡7Ó+¡7˜a�q—'�'¡7Ñ+Ó,Ð,ùÒ+s   ¿Ac                ó¤  € \        V 4      p\        V4      p\        WA4      pV^ 8  d	   W%,          p^ Tu;8:  d   V8  g    \        h \        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.
``IndexError`` will be raised if the given *index* is invalid.
r�   )r†   rq   r   Ú
IndexErrorr£   )rg   r²   r"   rÊ   rf   ÚcÚresults   &&&    rh   r>   r>   “  sª   € ô �‹?€DÜˆD‹	€AÜˆQ‹
€Aàˆq„yØ�
ˆØ�Ž>˜�>ÜÐð ÜÐà€Fß
Ø•%˜1•*˜a !�e Q¨¥UˆaˆØŒjØ�JˆEØ˜A�•; !Õ# Q¨¥UŠqØ�‰�d˜2 �6•lÖ#ä�‹=Ðri   c                ó   € \        V .V4      # )a  Yield *value*, followed by the elements in *iterable*.

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

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

)r   )r¨   rg   s   &&rh   rF   rF   µ  s   € ô �%�˜(Ó#Ð#ri   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)uu  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 useful 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 input iterables are
evaluated differently by this function. *signal* is consumed lazily and can be
infinite. *kernel* is fully consumed before calculations begin.

Supports all numeric types: int, float, complex, Decimal, Fraction.
Note that empty input iterables will produce meaningless output.

References:

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

Nro   r�   )r†   rq   r   r   r   r£   Ú_sumprod)ÚsignalÚkernelrf   ÚwindowÚxs   &&   rh   r0   r0   Ä  si   é € ôH �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˜   )Ú	predicateÚitÚtruesÚafters   &&  rh   r.   r.   ð  s,   € ô �r“7�L€EÜ”Y˜yÓ0´#°e³*Ó=€EØˆ<Ðri   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')]

N)r   rw   r˜   )rg   Út1Út2Út3s   &   rh   r^   r^     s;   € ô �X˜qÓ!�J€BˆBÜˆˆT„NÜˆˆT„NÜˆˆT„NÜˆr�r‹?Ðri   c                 ó~   € \        W4      p\        V4       F  w  r4\        \        WCV4      R 4       K  	  \	        V!  # r°   )r   Ú	enumeraterw   r   r˜   )rg   rf   r›   rÍ   rx   s   &&   rh   Ú_sliding_window_islicerè     s8   € ä�HÓ €IÜ  Ö+‰ˆÜŒV�H Ó# TÖ*ñ ,ä�	‰?Ðri   c              #   ó¬   "  € \        V 4      p\        \        W!^,
          4      VR7      pV F!  pVP                  V4       \	        V4      x € K#  	  R# 5i)é   ro   N)rt   r   r   r£   r†   )rg   rf   rx   rÛ   rÜ   s   &&   rh   Ú_sliding_window_dequerë     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   &&rh   rV   rV   $  s^   € ð 	ˆ2„vÜ$ XÓ1Ð1Ø	
ˆQŒÜ% hÓ2Ð2Ø	
ˆaŒÜ˜Ó!Ð!Ø	
ˆaŒÜ�8‹}ÐäÐ9¸!¸Ð=Ó>Ð>ri   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.
)	re   r   Úslicer   rž   rq   rk   r!   r   )rg   ÚseqÚslicess   &  rh   rW   rW   =  s@   € ô ˆx‹.€CÜ”UœL¬¬s°3«x¸!­|Ó)<¸aÓ@ÓA€FÜŒwœ˜s› VÓ,Ð,ri   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.
)re   r0   )ÚrootsÚpolyÚroots   &  rh   rD   rD   K  s1   € ð  ˆ3€DÛˆÜ”H˜T A¨ u :Ó.Ó/Šñ à€Kri   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)ax  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 *value* arguments 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]

For ``range`` objects (and other objects whose ``index`` method's behavior doesn't
match that of ``list``), wrap *iterable* with ``iter``:

>>> list(iter_index(iter(range(5)), 2))
[2]

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

r"   N)Úgetattrr   rç   rq   r   r™   )rg   r¨   rm   ÚstopÚ	seq_indexrx   rÍ   r¼   s   &&&&    rh   r8   r8   a  s‘   é € ô< ˜ '¨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ê   )Ú	bytearrayr8   r   Úbytesrq   rž   )rf   rm   ÚdataÚps   &   rh   rU   rU   �  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r–   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™   rt   r†   r   rq   )rg   rf   r–   rx   Úbatchs   &&$  rh   Ú_batchedr  ¤  s[   é € ð 	ˆ1„uÜÐ1Ó2Ð2Ü�H‹~€HÜœ Ó,Ó-Ð
-ˆ%Ö
-ß”c˜%“j A”oÜÐ:Ó;Ð;ØŒñ .ùs   ‚AA'Á#A'i¢ )r-   c                ó   € \        WVR 7      # ))r–   )Úitertools_batched)rg   rf   r–   s   &&$rh   r-   r-   »  s   € Ü  °VÔ<Ð<ri   c                ó   € \        V RR/ # )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.
r–   T)r˜   )Úmatrixs   &rh   r]   r]   Ã  s   € ô �Ð$˜tÑ$Ð$ri   c                óT   €  \        V 4       \        Y4      #   \         d     R# i ; i)z.Scalars are bytes, strings, and non-iterables.T)rt   rs   Ú
isinstance)r¨   Ú
stringlikes   &&rh   Ú
_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.)rt   rw   ÚStopIterationr   r	  r…   )Útensorrx   r¨   s   &  rh   Ú_flatten_tensorr  Ø  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…   r  r	   Úreversedr   )r  ÚshapeÚ	first_dimÚdimsÚscalar_streamÚreshapeds   &&    rh   rN   rN   æ  sY   € ôB �%œ×ÒÜ”u×*Ò*¨6Ó2°EÓ:Ð:ØÐ€IÜ# FÓ+€MÜ”gœx¨›~¨}Ó=€HÜ�(Ó&Ð&ri   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.
)rq   r-   r   rØ   r   r]   )Úm1Úm2rf   s   && rh   r:   r:     s0   € ô 	ˆBˆq�E‹
€AÜ”7œ8¤W¨R´¸2³Ó%?Ó@À!ÓDÐDri   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™   )rf   ÚbrÜ   ÚyÚds   &    rh   Ú_factor_pollardr    sy   € ô �1�aŽ[ˆØˆ	ˆØˆØ�1ŒfØ•˜•˜a•ˆAØ•˜•˜a•ˆAØ•˜•˜a•ˆAÜ�A•E˜1“ŠAØŽ6ØŠHñ ô Ð'Ó
(Ð(ri   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_211r6   r£   r  rÁ   )rf   ÚprimeÚprimesÚtodoÚfacts   &    rh   r2   r2   1  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.
)rq   Útyperk   Úpowr   r  rž   rØ   )ÚcoefficientsrÜ   rf   Úpowerss   &&  rh   rC   rC   R  sI   € ô  	ˆLÓ€AØˆA„vÜ�AŒw�q‹zÐÜ””f˜Q“i¤¬%°«(Ó!3Ó4€FÜ�LÓ)Ð)ri   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   &rh   rX   rX   i  s   € ô ”S˜“]Ñ#Ð#ri   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.
)rq   r  rž   re   rk   r    )r'  rf   r(  s   &  rh   rB   rB   t  s0   € ô 	ˆLÓ€AÜ”e˜A˜q“kÓ"€FÜ””C˜Ó.Ó/Ð/ri   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¸   r2   )rf   r   s   & rh   r\   r\   ‡  s&   € ô& ”V˜A“Y–ˆØ	�%�Z�Šñ  à€Hri   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)rf   r³   r  s   &  rh   Ú_shift_to_oddr.  ¯  sQ   € ð ˆa�%�1�× Ñ Ó" QÕ&€AØ	�€AØ��F�a�<˜1Ô  Q§¤¨1°¬6Ð1Ð1Øˆ4€Kri   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)r.  r&  rž   )rf   Úbaser³   r  rÜ   Ú_s   &&    rh   Ú_strong_probable_primer3  ¸  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•Ž:Úñ ñ
 ri   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)r0  N)Ú_private_randrangerÐ   s   & €rh   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°   )r3  )r±   r1  rf   s   & €rh   r´   r7  û  s   øé € ÐA¹5°4Ô% a¨×.Ð.»5ùr¶   T>   r0  é   é   é   é   é   )Ú_perfect_testsrž   Úall)rf   ÚlimitÚbasess   f  rh   r6   r6   Î  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ÐAri   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   )rf   s   &rh   r9   r9   þ  s   € ô �$˜‹?Ðri   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   rk   r   r   )Úcountss   *rh   r;   r;     s   € ôT ””Dœ* VÓ,¨fÓ5Ó6Ð6ri   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  rb   r   r
   rc   ©rx   ÚreadÚloÚhis   &   rh   Ú#_running_median_minheap_and_maxheaprK  9  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)rF  r   r  r
   r   rG  s   &   rh   Ú_running_median_minheap_onlyrM  I  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   rq   r   r¤   )rx   rp   rÛ   ÚorderedrÜ   rÍ   rf   Úms   &&      rh   Ú_running_median_windowedrQ  Y  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rp   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().
úWindow size should be positive)rt   Ú_indexr™   rQ  Ú_max_heap_availablerM  rK  ©rg   rp   rx   s   &$ rh   rR   rR   l  sV   € ô. �H‹~€HàÒÜ˜“ˆØ�QŒ;ÜÐ=Ó>Ð>Ü'¨Ó9Ð9çÓÜ+¨HÓ5Ð5ä.¨xÓ8Ð8ri   c              #   óÞ   "  € \        4       p^ pV  FV  pVP                  V4       W4,          p\        V4      V8”  d   W2P                  4       ,          pV\        V4      ,          x € KX  	  R# 5i©rú   N)r   r£   rq   r¤   )rx   rf   rÛ   Úrunning_sumr¨   s   &&   rh   Ú_windowed_running_meanrZ  ‘  sX   é € Ü‹W€FØ€KÛˆØ�‰�eÔØÕˆÜˆv‹;˜Œ?ØŸ>™>Ó+Õ+ˆKØœC ›KÕ'Ô'ó ùs   ‚A+A-c               ó¶   € \        V 4      pVf$   \        \        \        V4      \	        ^4      4      # \        V4      pV^ 8:  d   \        R4      h\        W!4      # )aƒ  Cumulative mean 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_mean([40, 30, 50, 46, 39, 44]))
    [40.0, 35.0, 40.0, 41.5, 41.0, 41.5]

    >>> list(running_mean([40, 30, 50, 46, 39, 44], maxlen=3))
    [40.0, 35.0, 40.0, 42.0, 45.0, 43.0]

Supports numeric types such as int, float, complex, Decimal, and Fraction.

No extra effort is made to reduce round-off errors for float inputs.
So the results may be slightly different from `statistics.mean`.

rS  )rt   rk   r%   r   r   rT  r™   rZ  rV  s   &$ rh   rQ   rQ   œ  sQ   € ô, �H‹~€Hà‚~Ü”7œJ xÓ0´%¸³(Ó;Ð;ä�F‹^€FØ�„{ÜÐ9Ó:Ð:ä! (Ó3Ð3ri   c              #   óT  "  € \        4       p\        V 4       FŠ  w  r4V'       d,   V^ ,          ^ ,          W1,
          8X  d   VP                  4        V'       d'   WBR,          ^,          8  d   VP                  4        K.  VP	                  W434       V^ ,          ^,          x € KŒ  	  R# 5i©rú   Nr�   ©r   rç   r¤   Úpopr£   ©rx   rp   r³   r"   r¨   s   &&   rh   Ú_windowed_running_minra  ¾  óp   é € ô 	‹€Aä! (Ö+‰ˆß��1•�a•˜E�NÔ*Ø�I‰IŒKß�E˜b�E !�HÔ$Ø�E‰EŽGØ	�‰�%�Ô Ø��d�1�gŒó ,ùó   ‚AB(ÁAB(c               ó’   € \        V 4      pVf   \        V\        R7      # \        V4      pV^ 8:  d   \	        R4      h\        W!4      # )a  Smallest 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_min([4, 3, 7, 0, 8, 1, 6, 2, 9, 5]))
    [4, 3, 3, 0, 0, 0, 0, 0, 0, 0]

    >>> list(running_min([4, 3, 7, 0, 8, 1, 6, 2, 9, 5], maxlen=3))
    [4, 3, 3, 0, 0, 0, 1, 1, 2, 2]

Supports numeric types such as int, float, Decimal, and Fraction,
but not complex numbers which are unorderable.
©ÚfuncrS  )rt   r   ÚminrT  r™   ra  rV  s   &$ rh   rS   rS   Í  óF   € ô& �H‹~€Hà‚~Ü˜(¬Ô-Ð-ä�F‹^€FØ�„{ÜÐ9Ó:Ð:ä  Ó2Ð2ri   c              #   óT  "  € \        4       p\        V 4       FŠ  w  r4V'       d,   V^ ,          ^ ,          W1,
          8X  d   VP                  4        V'       d'   WBR,          ^,          8”  d   VP                  4        K.  VP	                  W434       V^ ,          ^,          x € KŒ  	  R# 5ir]  r^  r`  s   &&   rh   Ú_windowed_running_maxrj  ì  rb  rc  c               ó’   € \        V 4      pVf   \        V\        R7      # \        V4      pV^ 8:  d   \	        R4      h\        W!4      # )a  Largest 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_max([4, 3, 7, 0, 8, 1, 6, 2, 9, 5]))
    [4, 4, 7, 7, 8, 8, 8, 8, 9, 9]

    >>> list(running_max([4, 3, 7, 0, 8, 1, 6, 2, 9, 5], maxlen=3))
    [4, 4, 7, 7, 8, 8, 8, 6, 9, 9]

Supports numeric types such as int, float, Decimal, and Fraction,
but not complex numbers which are unorderable.
re  rS  )rt   r   rr   rT  r™   rj  rV  s   &$ rh   rP   rP   û  rh  ri   )ÚfrozenÚslotsc                   ó,   a € ] tR tRt o V 3R ltRtV tR# )r+   i  c                óV   <€ V ^8„  d   Qh/ S[ ;R&   S[;R&   S[;R&   S[;R&   S[;R&   # )r0  ru   ÚminimumÚmedianÚmaximumÚmean)r  Úfloat)ÚformatÚ__classdict__s   "€rh   Ú__annotate__ÚStats.__annotate__  s?   ø‡ ‚ á
�Iñ ñ �Nñ ñ �Mñ	 ñ
 �Nñ ñ �Kò ri   © N)Ú__name__Ú
__module__Ú__qualname__Ú__firstlineno__Ú__annotate_func__Ú__static_attributes__Ú__classdictcell__)rv  s   @rh   r+   r+     s   ø‡ ‡ „ ri   c               ó  € Ve   \        V4      p\        V ^4      w  r#rE\        \        Vf   \	        ^4      M\        \        ^V4      \        V4      4      \        W!R7      \        W1R7      \        WAR7      \        WQR7      4      # )aã  Statistics for 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.

Yields instances of a ``Stats`` dataclass with fields for the dataset *size*,
*minimum* value, *median* value, *maximum* value, and the arithmetic *mean*.

Supports numeric types such as int, float, Decimal, and Fraction,
but not complex numbers which are unorderable.
ro   )rT  r   rk   r+   r   r   rž   r   rS   rR   rP   rQ   )rg   rp   Út0rã   rä   rå   s   &$    rh   rT   rT   #  st   € ð ÒÜ˜“ˆô ˜ 1Ó%�N€BˆBÜÜØ’NŒˆaŒ¬¬e°A°vÓ.>ÄÀvÃÓ(OÜ�BÔ&Ü�rÔ)Ü�BÔ&Ü�RÔ'óð ri   c                ó:  € \        V 4      p\        V4      ^8  d   \        V4      ^ 8X  d   R# \        R4      h\        \	        \        V4      4      4      p\        V4      p \        V4       \        \        \        W24      4      '       d   K-  \        V!  ! V4      # )zˆReturn a random derangement of elements in the iterable.

Equivalent to but much faster than ``choice(list(derangements(iterable)))``.

zNo derangments to choose fromry  )
r†   rq   rÓ   re   rž   r)   Úanyrk   r#   r$   )rg   rï   Úpermrm   s   &   rh   rJ   rJ   A  s{   € ô �‹/€CÜ
ˆ3ƒx�!„|Üˆs‹8�qŒ=ØˆIÜÐ8Ó9Ð9Ü””c˜#“h“Ó €DÜ�$‹K€EØ
Ü�ŒÜ”3”s˜EÓ(×)Ô)Ü˜tÒ$ SÓ)Ð)ri   )rú   r°   )r”   N)NF)NNrX  ))iÿ  )r0  )i�Š )é   éI   )l   ÅtT7 )r0  r;  é=   )l   Áay)r0  r=  é   iS_ )l   ;n>Ô)r0  r9  r:  r;  r<  )l   ßp¤)r0  r9  r:  r;  r<  r=  )l            )r0  iE  iŸ$  in  i×à i=• iþ‘k)l   ý%!HÈn•fW )r0  r9  r:  r;  r<  r=  é   é   r‰  é   r†  é%   é)   )�Ú__doc__ÚrandomÚbisectr   r   Úcollectionsr   Ú
contextlibr   Údataclassesr   Ú	functoolsr   r	   Úheapqr
   r   Ú	itertoolsr   r   r   r   r   r   r   r   r   r   r’   r   r   r   r   r   r   Úmathr   r   r   r   Úoperatorr    r!   r"   rT  r#   r$   r%   r&   r'   r(   r)   Úsysr*   Ú__all__ÚobjectÚ_markerrb   rc   rU  ÚImportErrorr[   rY   rZ   r/   r=   r,   r­   rG   r?   r@   r<   r1   r‹   rØ   r4   rM   r5   rO   rA   rE   r`   ra   r_   r7   r3   rL   rK   rH   rI   r>   rF   r0   r.   r^   rè   rë   rV   rW   rD   r8   rU   r  r-   r  r]   Ústrrü   r	  r  rN   r:   r  r†   r  r2   rC   rX   rB   r\   r>  r.  r3  ÚRandomr6  r6   r9   r;   rK  rM  rQ  rR   rZ  rQ   ra  rS   rj  rP   r+   rT   rJ   ry  ri   rh   Ú<module>r¡     s6  ðñó ç &Ý Ý Ý !ß 'ß '÷÷ ÷ ÷ ó ÷$ (Ó 'ß L× Lß 5Ó 5Ý ð9Øð9àð9ð ð9ð ð	9ð
 ð9ð ð9ð ð9ð ð9ð ð9ð ð9ð ð9ð ð9ð ð9ð ð9ð ð9ð  ð!9ð" ð#9ð$ ð%9ð& 
ð'9ð( ð)9ð* ð+9ð, ð-9ð. ð/9ð0 ð19ð2 ð39ð4 ð59ð6 ð79ð8 ð99ð: ð;9ð< ð=9ð> ð?9ð@ *ðA9ðB ðC9ðD ðE9ðF ðG9ðH ðI9ðJ ðK9ðL ðM9ðN ðO9ðP ðQ9ðR ðS9ðT ðU9ðV ðW9ðX ðY9ðZ ð[9ð\ ð]9ð^ ð_9ð` ða9ðb ðc9ðd ðe9ðf ðg9ðh ði9ðj ðk9ðl ðm9ðn ðo9ðp ðq9€ñv ‹(€ðß3ð Ðò%ô 'ò$8ô %+ôP
4ôð4 !ô 	$ò)ð €ò;ò
%ðÝ(ò
	.ô2ò6(ô&AòR(ò$'-òTNô*!ôHAô/ô(ô21ð(% aô %ô("ò$-ò -ò"òD$ò)'òXò&ò òò?ò2-òô,+;ò\*ð* Eô ð( �ÔÝ6ð= uô =ð ×&Ñ&€G…Oà€Gò	%ð #& u ô )ò1ò&'òREò)ñ  ™% ›*Ó%Ð òòB*ò.$ò0ò&ò2€ð ñó ðòð& —]’]“_×.Ñ.Ð ò-Bò`ò*7òZ&ò &ò Ið&"9 tô "9òJ(ð4 Tô 4òDð3 Dô 3ò>ð3 Dô 3ñ> �$˜dÔ#÷ð ó $ðð¨4ô ô<*øðm. ô  ØÓð ûð| ô ØƒHðús$   Ã=J
 Ä3J Ê
	JÊJÊ	J'Ê&J'