bgodZddlZddlZddlmZddlmZddlmZm Z ddl m Z m Z m Z mZmZmZmZmZmZmZmZmZddlmZmZmZddlmZgd ZeZ e d ee d Z!n #e"$re Z!YnwxYwe#ed d Z$dZ%dHdZ&dZ'dIdZ(dIdZ)dIdZ*e+fdZ,dZ-e-Z.dZ/dZ0dZ1dIdZ2dZ3 ddl m4Z5dZ4e3je4_n #e6$re3Z4YnwxYwGdde7Z8dZ9d Z:dJd"Z;d#ZdId&Z?dId'Z@dKd)ZAdId*ZBdLd+ZCd,d-d.ZDdId/ZEd0ZFd1ZGd2ZHd3ZId4ZJd5ZKd6ZLd7ZMd8ZNd9ZOdMd:ZPd;ZQd(d d<ZRed=kr dd>l mSZTd(d d?ZSneRZSeRjeS_d@ZUdAZVdBZWdCZXdDZYdEZZdFZ[dGZ\dS)NaImported from the recipes section of the itertools documentation. All functions taken from the recipes section of the itertools library docs [1]_. Some backward-compatible usability improvements have been made. .. [1] http://docs.python.org/library/itertools.html#recipes N)deque)Sized)partialreduce) chain combinationscompresscountcyclegroupbyisliceproductrepeatstarmaptee zip_longest) randrangesamplechoice) hexversion). all_equalbatchedbefore_and_afterconsumeconvolve dotproduct first_truefactorflattengrouper iter_except iter_indexmatmulncyclesnthnth_combinationpadnonepad_nonepairwise partitionpolynomial_evalpolynomial_from_rootspolynomial_derivativepowersetprependquantifyreshape#random_combination_with_replacementrandom_combinationrandom_permutationrandom_product repeatfunc roundrobinsievesliding_window subslicessum_of_squarestabulatetailtaketotient transpose triplewiseuniqueunique_everseenunique_justseenTstrictsumprodc"t||SN)r)xys `/opt/cloudlinux/venv/lib64/python3.11/site-packages/setuptools/_vendor/more_itertools/recipes.pyrM_sAq1A1Ac<tt||S)zReturn 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 niterables rLr>r>bs x## $ $$rNc<t|t|S)aReturn 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 )functionstarts rLr<r<rs xu & &&rNc #Kt|tr7t|tdt ||z dEd{VdSt t ||Ed{VdS)zReturn an iterator over the last *n* items of *iterable*. >>> t = tail(3, 'ABCDEFG') >>> list(t) ['E', 'F', 'G'] rNmaxlen) isinstancerr maxleniterrrQs rLr=r=s(E""3(C3x==1+<$=$=tDDDDDDDDDDDhq11122222222222rNcn|t|ddStt|||ddS)aXAdvance *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 "", line 1, in 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 "", line 1, in StopIteration NrrY)rnextr )iteratorrRs rLrrsG@ y hq!!!!!! VHa # #T*****rNc@tt||d|S)zReturns the nth item or a default value. >>> l = range(10) >>> nth(l, 3) 3 >>> nth(l, 20, "zebra") 'zebra' N)r`r )rSrRdefaults rLr%r%s  xD))7 3 33rNc ztttt||ddkS)a 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 )r]rPr r rSkeys rLrrs3$ tF78S1115566 7 71 <>> quantify([True, False, True]) 2 )sumrU)rSpreds rLr0r0s s4"" # ##rNc<t|tdS)aReturns 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)rrrSs rLr(r(s 6$<< ( ((rNc`tjtt||S)zvReturns the sequence elements *n* times >>> list(ncycles(["a", "b"], 3)) ['a', 'b', 'a', 'b', 'a', 'b'] )r from_iterablertuple)rSrRs rLr$r$s%  veHooq99 : ::rNcRtttj||S)zcReturns the dot product of the two iterables. >>> dotproduct([10, 10], [20, 20]) 400 )rjrUoperatormul)vec1vec2s rLrrs  s8<t,, - --rNc*tj|S)zReturn 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. )rro) listOfListss rLrrs  { + ++rNc||t|t|St|t||S)aGCall *func* with *args* repeatedly, returning an iterable over the results. If *times* is specified, the iterable will terminate after that many repetitions: >>> from operator import add >>> times = 4 >>> args = 3, 5 >>> list(repeatfunc(add, times, *args)) [8, 8, 8, 8] If *times* is ``None`` the iterable will not terminate: >>> from random import randrange >>> times = None >>> args = 1, 11 >>> take(6, repeatfunc(randrange, times, *args)) # doctest:+SKIP [2, 4, 8, 1, 8, 4] )rr)functimesargss rLr6r6s9, }tVD\\*** 4e,, - --rNcft|\}}t|dt||S)zReturns 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)rr`zip)rSabs rL _pairwiser6s. x==DAqDMMM q!99rNr)c t|SrI)itertools_pairwiserms rLr)r)Js!(+++rNc eZdZdfd ZxZS)UnequalIterablesErrorNcld}| |dj|z }t|dS)Nz Iterables have different lengthsz/: index 0 has length {}; index {} has length {})formatsuper__init__)selfdetailsmsg __class__s rLrzUnequalIterablesError.__init__QsI0   MEM C rNrI)__name__ __module__ __qualname__r __classcell__)rs@rLrrPs=rNrc#rKt|dtiD]"}|D]}|turt|V#dS)N fillvalue)r_markerr) iterablescombovals rL_zip_equal_generatorr[s`i;7;; . .Cg~~+--- rNc  t|d}t|dddD]-\}}t|}||krt|||f.t|S#t$rt |cYSwxYw)Nrrf)r)r] enumeraterr} TypeErrorr)r first_sizeiitsizes rL _zip_equalrcs /1&& y}a00 K KEArr77Dz!!+ZD4IJJJJ"I ///#I...../sA#A&&BBfillct|g|z}|dkr t|d|iS|dkr t|S|dkr t|St d)aGroup 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. >>> it = grouper('ABCDEFG', 3, incomplete='strict') >>> list(it) # doctest: +IGNORE_EXCEPTION_DETAIL Traceback (most recent call last): ... UnequalIterablesError rrrFignorez Expected fill, strict, or ignore)r^rrr} ValueError)rSrR incompleterr{s rLr r sso: NN a DVD6I666X4  XDz;<<>> 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). rN)rUr^ranger]r r r`)r iterators num_actives rLr7r7s~D)$$IC NNAr22(( &J7788 tY''''''''''((rNc|t}t|d\}}}tt||\}}t|ttj|t||fS)a 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, ' ']) N)boolrrUr rrnot_)rkrSt1t2pp1p2s rLr*r*sg( |Ha  IBA T1  FB RX]B// 0 0(2r2B2B CCrNct|tjfdtt dzDS)a1Yields 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`. c38K|]}t|VdSrI)r).0rss rL zpowerset..s-MMa|Aq11MMMMMMrNrf)rPrrorr])rSrs @rLr.r.sH" XA  MMMM5Q!;L;LMMM M MMrNc#Kt}|j}g}|j}|du}|D]H}|r ||n|} ||vr|||V&#t$r||vr|||VYEwxYwdS)a 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)setaddappendr) rSrhseenset seenset_addseenlist seenlist_adduse_keyelementks rLrCrCs6eeG+KH?LoG  # 0CCLLL  A       Q    sA  A-,A-c |/ttjdt|Sttttjdt||S)zYields 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'] Nrrf)rUrr itemgetterr r`rgs rLrDrD s[ {8&q))78+<+<=== tS,Q//31G1GHH I IIrNFcDtt||||S)aYields 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. )rhreverse)rh)rDsorted)rSrhrs rLrBrBs& 6(WEEE3 O O OOrNc#XK | |V |V #|$rYdSwxYw)aYields 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))) [] N)ry exceptionfirsts rLr!r!-s[,  %''MMM $&&LLL       s  ))c>tt|||S)a 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' )r`filter)rSrcrks rLrrLs" tX&& 0 00rNrf)rcRd|D|z}td|DS)aDraw an item at random from each of the input iterables. >>> random_product('abc', range(4), 'XYZ') # doctest:+SKIP ('c', 3, 'Z') If *repeat* is provided as a keyword argument, that many items will be drawn from each iterable. >>> random_product('abcd', range(4), repeat=2) # doctest:+SKIP ('a', 2, 'd', 3) This equivalent to taking a random selection from ``itertools.product(*args, **kwarg)``. c,g|]}t|Srrprpools rL z"random_product..ps * * *TU4[[ * * *rNc34K|]}t|VdSrI)rrs rLrz!random_product..qs(00$000000rNr)rr{poolss rLr5r5`s9 + *T * * *V 3E 00%000 0 00rNct|}|t|n|}tt||S)abReturn 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)``. )rpr]r)rSrrs rLr4r4ts8 ??DYD AA a ! !!rNct|t}ttt ||}tfd|DS)zReturn a random *r* length subsequence of the elements in *iterable*. >>> random_combination(range(5), 3) # doctest:+SKIP (2, 3, 4) This equivalent to taking a random selection from ``itertools.combinations(iterable, r)``. c3(K|] }|V dSrIrrrrs rLrz%random_combination..'**Qa******rN)rpr]rrr)rSrrRindicesrs @rLr3r3s[ ??D D AVE!HHa(())G ****'*** * **rNct|ttfdt|D}tfd|DS)aSReturn 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)``. c36K|]}tVdSrI)r)rrrRs rLrz6random_combination_with_replacement..s)44aYq\\444444rNc3(K|] }|V dSrIrrs rLrz6random_combination_with_replacement..rrN)rpr]rr)rSrrrRrs @@rLr2r2sg ??D D A444458844444G ****'*** * **rNct|}t|}|dks||krtd}t|||z }t d|dzD]}|||z |zz|z}|dkr||z }|dks||krt g}|rS||z|z|dz |dz }}}||kr||z}|||z z|z|dz }}||k||d|z |St|S)aEquivalent 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. rrfr)rpr]rminr IndexErrorr) rSrindexrrRcrrresults rLr&r&s8 ??D D A A1q55 A Aq1u A 1a!e__!! QOq  qyy    uzz F $a%1*a!eQUa1qjj QJEA;!#QUqAqjj  d26l### $ ==rNc$t|g|S)aYield *value*, followed by the elements in *iterator*. >>> value = '0' >>> iterator = ['1', '2', '3'] >>> list(prepend(value, iterator)) ['0', '1', '2', '3'] To prepend multiple values, see :func:`itertools.chain` or :func:`value_chain`. )r)valueras rLr/r/s %( # ##rNc#Kt|ddd}t|}tdg||z}t|t d|dz D])}||t ||V*dS)aBConvolve the iterable *signal* with the iterable *kernel*. >>> signal = (1, 2, 3, 4, 5) >>> kernel = [3, 2, 1] >>> list(convolve(signal, kernel)) [3, 8, 14, 20, 26, 14, 5] Note: the input arguments are not interchangeable, as the *kernel* is immediately consumed and stored. NrrrYrf)rpr]rrrr_sumprod)signalkernelrRwindowrJs rLrrs6]]44R4 F F A A3q ! ! !A %F 66!QU++ , ,'' avv&&&&&&''rNcptgfd}t}||fS)aA 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. c3dKD])}|r|V|dSdSrI)r)elemr predicate transitions rL true_iteratorz'before_and_after..true_iteratorsV  Dy  !!$'''   rN)r^r)rrrremainder_iteratorrs`` @rLrrs^ bBJz2.. =??. ..rNc#hKtt|D]\\}}\}}|||fVdS)zReturn overlapping triplets from *iterable*. >>> list(triplewise('ABCDE')) [('A', 'B', 'C'), ('B', 'C', 'D'), ('C', 'D', 'E')] Nr)rSr~_rrs rLrArAsN#8H#5#566AAAg rNc#Kt|}tt||dz |}|D](}||t |V)dS)aYReturn 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`. rfrYN)r^rr rrp)rSrRrrrJs rLr9r9"ss hB 6"a!e$$Q / / /F  aFmmrNc t|}tttt t |dzd}t tjt||S)zReturn 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. rfre) rPrslicerrr]rUrrgetitemr)rSseqslicess rLr:r:6sU x..C ULs3xx!|)<)>> roots = [5, -4, 3] # (x - 5) * (x + 4) * (x - 3) >>> polynomial_from_roots(roots) # x^3 - 4 * x^2 - 17 * x + 60 [1, -4, -17, 60] rf)r}rrUrrnegrPrr)rootsfactorss rLr,r,DsA&))Su5566G x1#.. / //rNc#Kt|dd}|7t|||}t||D]\}}||us||kr|VdS|t|n|}|dz } |||dz|x}V#t$rYdSwxYw)aYield 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. rNrf)getattrr rr]r)rSrrWstop seq_indexrrrs rLr"r"Os2'400I HeT * *#B..  JAw%7e#3#3   !% s8}}}$ AI  ;%IeQUD999q::: ;    DD s&A<< B  B c #K|dkrdVd}td|dzz}tj|dz}t|d||D]_}t|d|||zEd{Vt t t ||z|||z|||z|||z<||z}`t|d|Ed{VdS)zdYield the primes less than n. >>> list(sieve(30)) [2, 3, 5, 7, 11, 13, 17, 19, 23, 29] rer)rrfrfN) bytearraymathisqrtr"bytesr]r)rRrWdatalimitrs rLr8r8zs  1uu E V  Q 'D JqMMA E a . .dAua!e444444444"'E!a%AE,B,B(C(C"D"DQUQQ A$5)))))))))))rNc#"K|dkrtdt|}tt||x}rI|r"t ||krtd|Vtt||x}GdSdS)aBatch 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`. rfzn must be at least onezbatched(): incomplete batchN)rr^rpr r])rSrRrFrbatchs rL_batchedrs 1uu1222 hBA'' '%  >> 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_strictrs rLr@r@s  rNcFttj||S)zReshape the 2-D input *matrix* to have a column count given by *cols*. >>> matrix = [(0, 1), (2, 3), (4, 5)] >>> cols = 3 >>> list(reshape(matrix, cols)) [(0, 1, 2), (3, 4, 5)] )rrro)matrixcolss rLr1r1s 5&v.. 5 55rNc t|d}tttt |t ||S)zMultiply 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. r)r]rrrrr@)m1m2rRs rLr#r#s= BqE A 78WR2%?%?@@! D DDrNc#Kttj|dzD]}||zs|V||z}|dkrdS||z|dkr|VdSdS)zTYield the prime factors of n. >>> list(factor(360)) [2, 2, 2, 3, 3, 5] rfN)r8rr)rRprimes rLrrs tz!}}q())e) KKK %KAAvv e)   1uu urNc t|}|dkr|dzSttt|t t |}t ||S)zEvaluate a polynomial at a specific value. Example: evaluating 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 r)r]rUpowrreversedrr) coefficientsrJrRpowerss rLr+r+sX LAAvv1u fQii%((!3!3 4 4F L& ) ))rNc.tt|S)zfReturn the sum of the squares of the input values. >>> sum_of_squares([10, 20, 30]) 1400 )rrrs rLr;r;s SWW rNct|}ttd|}tt t j||S)aCompute the first derivative of a polynomial. Example: evaluating the derivative of x^3 - 4 * x^2 - 17 * x + 60 >>> coefficients = [1, -4, -17, 60] >>> derivative_coefficients = polynomial_derivative(coefficients) >>> derivative_coefficients [3, -8, -17] rf)r]rrrPrUrrrs)rrRr s rLr-r-sB LA eAqkk " "F HL,77 8 88rNcZtt|D] }||z|dz z}|S)zReturn the count of natural numbers up to *n* that are coprime with *n*. >>> totient(9) 6 >>> totient(12) 4 rf)rr)rRrs rLr?r? s8^^ Fa!e  HrN)rrI)rN)NF)NN)rN)]__doc__rrr collectionsrcollections.abcr functoolsrr itertoolsrrr r r r r rrrrrrandomrrrsysr__all__objectrr}rrrrr>r<r=rr%rrr0r(r'r$rrr6rr)r ImportErrorrrrrr r7r*r.rCrDrBr!rr5r4r3r2r&r/rrrAr9r:r,r"r8rrrr@r1r#rr+r;r-r?rrNrLr.s !!!!!!%%%%%%%%                            -,,,,,,,,,/ / / b &((,Ct'#d+++KKKKK 74$A$A B B % % % ''''$333$%+%+%+%+P 4 4 4 4====*!$$$$ ) ) ) ;;;... , , ,....6    )888888 ,,,!(HHHHJ / / / %=%=%=%=P((($DDD8NNN*****Z J J J JPPPP&    >1111("#11111(""""$ + + + +++"'''T $ $ $''',///B( 6 6 6000((((V***$%*(666666',======G&GO   666 E E E    ***" 9 9 9      s$ A44A>=A>CC C