ELF>  @Xg@8@ÔUÔU P]P] P] x€ h]h] h] ððÈÈÈ$$PåtdPPPÔÔQåtdRåtdP]P] P] °°GNU6}µö1Ô<ØAgùM½¹»ºÄ B…ˆ@ €BEÕì»ã’|ÙqXïì—l Uð—¼Ï£ 0!ßo„, F"fÈa yÐa mÈa G à2 __gmon_start___ITM_deregisterTMCloneTable_ITM_registerTMCloneTable__cxa_finalizelibpthread.so.0libc.so.6PyUnicode_FromStringPyModule_AddObject_Py_DeallocPyObject_RichCompareBoolPyExc_RuntimeErrorPyErr_SetStringPyExc_IndexErrorPyList_SetSlice_PyArg_BadArgumentPyList_Append_Py_NoneStruct_PyArg_CheckPositionalPyInit__heapqPyModuleDef_Init_edata__bss_start_endGLIBC_2.2.5eui ~P] `1X]  1`] `] ` p1@` 83H`  X` @8`` ]3h` `x` `7€` u3ˆ` Ð"˜` à6 ` i3¨` p¸`  5À` Š3È`  2Ø` À4à` +3è` °1ø` €4a }3a p2a @4 a L3(a 08a à3ˆa ’3�a  8 a @` ¨a ` È_ Ð_ Ø_  à_  è_  ð_ ø_ p_ x_ €_ ˆ_ �_ ˜_  _  ¨_  °_ ¸_ À_ óúHƒìH‹ U H…ÀtÿÐHƒÄÃÿ5zT ÿ%|T @ÿ%zT héàÿÿÿÿ%rT héÐÿÿÿÿ%jT héÀÿÿÿÿ%bT hé°ÿÿÿÿ%ZT hé ÿÿÿÿ%RT hé�ÿÿÿÿ%JT hé€ÿÿÿÿ%BT hépÿÿÿÿ%:T hé`ÿÿÿÿ%2T h éPÿÿÿÿ%*T h é@ÿÿÿH‹…Àx HƒèH‰tƒÊÿéé%H‰ßèPÿÿÿƒÊÿéÙ%E‹MAƒÁtE‰M1ÒL‰îL‰÷èMÿÿÿI‹…Éx HƒéI‰„àM‹uE…öxIƒîM‰u„…ÀˆûƒðHÃI‹GM;g„ÛL‹-ŸS H�5h'I‹}èßþÿÿéËA‹6ƒÆtA‰6L‰ï1ÒL‰öèÒþÿÿI‹}…ÿxHƒïI‰}uL‰ï‰D$è”þÿÿ‹D$M‹E…ÀxIƒèM‰uL‰÷‰D$èsþÿÿ‹D$…ÀˆhM;gtL‹=S H�5ã&I‹?è[þÿÿéG…À„.éÿL‰÷‰D$è-þÿÿ‹D$é ÿÿÿH‹õR H�5&H‹:èþÿÿé L‹%ÚR H�5õ%I‹<$èþÿÿéîL‰ï‰D$èáýÿÿ‹D$éÖþÿÿM‹$E…Àx IƒèM‰$t+1íéÐ$H‰ñH�Á%H�5¿%1íH�=¿%èÏýÿÿé¬$L‰ç1íè�ýÿÿé�$L‹3I‹Vö‚«tZH‹sL‰÷è¯ýÿÿ…À…- I‹NL�iÿL9é>L‹%+R H�5F%I‹<$èSýÿÿé H‰ß‰D$ H‰ $è.ýÿÿH‹ $‹D$ éééI‹FJ�4èM…í�€é6‹UƒÂt‰U1ÒH‰îL‰÷èýÿÿM‹E…ÉxIƒéM‰uL‰÷‰D$èÑüÿÿ‹D$L‹uE…öxIƒîL‰uuH‰ï‰D$è®üÿÿ‹D$…Àˆÿ ƒðI‹WHÃM9g„. L‹GQ H�5%I‹:èˆüÿÿéÐ H‰Ö¹ºH�=›$èªüÿÿ…Àt1L‹;I‹Wö‚«…°L‰ùH�E$H�5b$H�=f$èUüÿÿHÇD$é£ ‹uƒÆt‰uL‰ç1ÒH‰îèüÿÿI‹<$…ÿxHƒïI‰<$uL‰ç‰D$èáûÿÿ‹D$H‹M…ÉxHƒéH‰MuH‰ï‰D$è¿ûÿÿ‹D$…Àˆ M9wthL‹=fP H�5/$I‹?è§ûÿÿéïIƒH‹ktOI‹WD‹ML‹L‰D$AƒÁtD‰MM‹gH‰*M…äMH‹-2P H�5M#H‹}èZûÿÿ颅À„Ééµ L‹ P H�5$#I‹9è2ûÿÿHÇD$é M‰âIÑúL‰T$„�é˜L‹5ÏO H�5ê"I‹>èøúÿÿé@L‰ç‰D$H‰t$èÒúÿÿH‹t$‹D$é H‹-•O H�5°"H‹}è½úÿÿéÎ H‹yO H�5”"H‹:è¢úÿÿé³ L‹E…Ûx IƒëL‰tb1íéG H‰Ö¹ºH�=®"è¬úÿÿ…ÀtÜL‹#I‹L$ö�«uèôøÿÿéH‹°M H�5Ë H‹:èÙøÿÿ1Àé[L‰÷‰D$ L‰$è²øÿÿL‹$‹D$ éH‹ vM H�5‘ H‹9èŸøÿÿ1Àé!L‰ç‰D$<è|øÿÿ‹D$<éL‹DM H�5_ I‹;èmøÿÿ1ÀéïL‹%'M H�5B I‹<$èOøÿÿ1ÀéÑH‰ñH�; H�59 H�=� èKøÿÿ1ÀZÀAWAVAUATUSHƒì(L‹gH‰t$L9æ�ÌùÿÿL‰àH‰õHÑøH‰D$H9Æ�ÉH‹GI‰ÿH�T-H�ZHƒÂL‹,ØL9â�­L‹4ÐA‹ƒÁ„`øÿÿA‰A‹uƒÆ„^øÿÿA‰uL‰÷1ÒL‰îè§÷ÿÿI‹>…ÿˆcøÿÿHƒïI‰>„6ùÿÿM‹EE…Àˆ`øÿÿIƒèM‰E„gùÿÿ…ÀˆMƒðHÃI‹GM;g…RøÿÿL�,ÝH�,èN�(H‹UM‹I‰L‰]H9\$~3H‰Ýé9ÿÿÿL�,ÝL�èJ�4(M‹H‹>L‰I‰8H;\$|Õ„M‹gI9ÜŽÊøÿÿN‹4(H9\$�´H�kÿHÑýL‹,èL�íL‰\$A‹EƒÀ„Õ÷ÿÿA‰EA‹ƒÂ„Ð÷ÿÿA‰L‰ö1ÒL‰ïèŸöÿÿM‹ME…Ɉâ÷ÿÿIƒéM‰M„Ä÷ÿÿI‹…Ɉê÷ÿÿHƒéI‰„Í÷ÿÿ…ÀxIM;g…Ý÷ÿÿ…Àt*I‹GL‹T$H�ØIÂL‹3M‹M‰2L‰H‰ëH9l$ŒLÿÿÿ1ÀHƒÄ([]A\A]A^A_ÃÈÿëìf.„AWAVAUATUSH‰óHƒìHƒú…ÆL‹6I‹Fö€«„ŽH‹vL‰÷èõõÿÿ…À…sI‹NL�iÿI9Í�BøÿÿI‹FJ�4èM…펻H‹M�eÿ‹;IÑüN�<åJ‹,àƒÇ„°‰;D‹EAƒÀ„®D‰E1ÒH‰îH‰ßH‰ $èeõÿÿL‹MH‹ $E…ɈÇIƒéL‰M„¡L‹E…Òx IƒêL‰„Ó÷ÿÿ…ÀˆÏI;N…¯…Àt+I‹FN�,èIÇI‹]I‹/I‰I‰mM‰åM…ä…NÿÿÿfDH‹™I HƒÄ[]A\A]A^A_ÃD‹]AƒÃtD‰]1ÒH‰îH‰ßH‰ $è»ôÿÿH‹UH‹ $…Òx"HƒêH‰UuH‰ï‰D$ H‰ $èuôÿÿ‹D$ H‹ $H‹3…öˆQÿÿÿHƒîH‰3…Dÿÿÿé÷ÿÿL‹5 I H�5ÒI‹>èJôÿÿ1ÀéjÿÿÿL‰ñH�6H�5SH�=CèFôÿÿ1ÀéFÿÿÿH‰Ö¹ºH�=#èFôÿÿ…Àt¸éböÿÿff.„f�AWAVAUATUSH‰óHƒì(Hƒú…R÷ÿÿL‹>I‹Gö€«„o÷ÿÿIƒH‹n„jøÿÿI‹W‹}H‹2H‰t$ƒÇ„øÿÿ‰}M‹gH‰*M…äŽøÿÿL‰áHÑùH‰L$„òE1íO�\-I�[IƒÃH‹,ÚM9ã�éN‹4ÚA‹ƒÀ„3öÿÿA‰‹uƒÆ„/öÿÿ‰uL‰÷1ÒH‰îè:óÿÿI‹>…ÿˆBöÿÿHƒïI‰>„%öÿÿH‹M…ɈLöÿÿHƒéH‰M„.öÿÿ…ÀxAƒðI‹WHÃM;g…BöÿÿH�,ÝN�,êL�*M‹EM‹M‰M‰]H9\$~{I‰Ýé@ÿÿÿL‹\$M‹E…ÀˆmöÿÿIƒèM‰…`öÿÿL‰ßè}òÿÿHÇD$H‹D$HƒÄ([]A\A]A^A_ÃH�,ÝJ�êH�4*H‹H‹>H‰H‰8H;\$|’ff.„f�M‹wL9ó�ÐM‹WI‹,*L�kÿIÑýN�$íL‰d$O‹$êE‹$AƒÃ„ÞõÿÿE‰$D‹EAƒÀ„×õÿÿD‰E1ÒH‰îL‰çèòñÿÿM‹ $E…ɈèõÿÿIƒéM‰ $„ÊõÿÿH‹U…ÒˆðõÿÿHƒêH‰U„Òõÿÿ…ÀˆòþÿÿM9w…Þõÿÿ…À„ÿÿÿM‹WJ�íI�ÚLÐH‹+L‹ H‰(L‰#L‰ëM…í…=ÿÿÿéßþÿÿéPöÿÿff.„AWAVAUATUSHƒì(L‹oL9î�}öÿÿM‰èI‰ÿH‰õH‹GIÑøL9Æ�œI‰öK�6H�ZHƒÂL� ÝN�M‹"L9ê�€H‹ ÐA‹$ƒÀ„°A‰$‹1ƒÆ„ª‰11ÒH‰ÎL‰çL‰D$H‰L$èÌðÿÿI‹<$H‹L$L‹D$…ÿˆÖHƒïI‰<$„ L‹ E…ɈìIƒéL‰ „¿…Àˆ�ƒðHÃI‹GM;o…�L� ÝN�$ðN�M‹4$M‹M‰2M‰$I9ØŽÝI‰Þéÿÿÿ‹ƒÂt‰H‰Î1ÒL‰çL‰D$H‰L$è$ðÿÿI‹4$H‹L$L‹D$…öx2HƒîI‰4$u(L‰ç‰D$H‰L$L‰D$èÒïÿÿ‹D$H‹L$L‹D$@H‹9…ÿx)HƒïH‰9u H‰Ï‰D$L‰D$èŸïÿÿ‹D$L‹D$fD…Àˆ®ƒðHÃI‹GM;o…¢L� ÝN�M‹"N�ðM‹3M‰2M‰#L9ÃŒ#ÿÿÿM‹oI9ÝŽ~ôÿÿIÁH9Ý�ÆM‹!H�SÿHÑúL‹4ÐA‹$H�4ÕH‰t$ƒÀ„¯A‰$A‹ƒÁ„«A‰L‰öL‰çH‰T$1Òè ïÿÿI‹>H‹t$…ÿˆÉHƒïI‰>„¡M‹ $E…ÉxIƒéM‰ $„Òóÿÿ…ÀˆÓM;o…³…Àt/I‹GL‹t$H�ØIÆL‹#I‹M‰&H‰ H‰óH9õŒDÿÿÿ€1ÀHƒÄ([]A\A]A^A_ÃE‹AƒÀtE‰H‰T$L‰ö1ÒL‰çèaîÿÿM‹H‹t$E…Òx$IƒêM‰uL‰÷‰D$H‰t$èîÿÿ‹D$H‹t$�M‹$E…ÛˆNÿÿÿIƒëM‰$…@ÿÿÿé óÿÿL‹=©B H�5rI‹?èêíÿÿƒÈÿédÿÿÿL‹-‹B H�5TI‹}èËíÿÿëßf„ATUSH‰óHƒìHƒú…&óÿÿL‹&I‹D$ö€«„?óÿÿIƒ|$H‹n„‹I‹T$H‹‹;ƒÇt‰;1ÒH‰îH‰ßèxíÿÿL‹E…Àx IƒèL‰„�…Àˆ¿òÿÿu‹UƒÂt‰UHƒÄH‰è[]A\ÃIƒ|$t>M‹L$D‹UI‹AƒÂtD‰UI‰)1öL‰çH‰Ýè´ûÿÿ…ÀtÂé^òÿÿD‹eAƒÄt³é¹òÿÿH‹­A H�5È1íH‹8èÔìÿÿë”H‰ß‰D$ è¶ìÿÿ‹D$ éjÿÿÿff.„f�AWAVAUATUSH‰óHƒì(Hƒú…ÓH‹.H‹Eö€«„”Hƒ}L‹F„aH‹EA‹H‹8H‰|$ƒÂ„ºA‰L‹eL‰M…äŽÉòÿÿL‰áHÑùH‰L$„E1íO�|-I�_IƒÇH�4ÝH�<0L‹7M9üŽ©N‹<øA‹ƒÀ„þA‰A‹?ƒÇ„úA‰?1ÒL‰þL‰÷èïëÿÿI‹…ÒˆHƒêI‰„ðM‹7E…öˆ+IƒîM‰7„ÿ…Àx\ƒðHÃH‹EL;e…H�4ÝN�,èH� 0M‹EL‹ L‰M‰MH9\$Ž I‰Ýé2ÿÿÿH‹-@ H�5×H‹}èNëÿÿL‹D$M‹E…ÒˆmIƒêM‰…`L‰ÇèëÿÿHÇD$H‹D$HƒÄ([]A\A]A^A_Ãff.„A‹7ƒÆtA‰71ÒL‰þL‰÷èøêÿÿM‹E…Òx IƒêM‰uL‰÷‰D$è»êÿÿ‹D$€M‹E…Ûx(IƒëM‰uL‰ÿ‰D$è“êÿÿ‹D$ff.„@…Àˆ:ÿÿÿƒðHÃH‹EL;e…úH�4ÝH�<0L‹7N�<èI‹H‰M‰7H9\$�àþÿÿL‹}L9û�áL‹MM‹$1L�kÿE‹$IÑýJ� íO‹4éH‰L$AƒÀ„¢E‰$E‹AƒÂ„œE‰1ÒL‰öL‰çèêÿÿM‹E…ÛˆµIƒëM‰„�I‹4$…öxHƒîI‰4$„/ðÿÿ…ÀˆlþÿÿL9}…Kþÿÿ…À„‰þÿÿL‹MN�4íI�ÙMÎL‹#I‹M‰&H‰ L‰ëM…í…EÿÿÿéYþÿÿ„A‹ƒÀtA‰L‰ç1ÒL‰öèhéÿÿI‹>…ÿx!HƒïI‰>uL‰÷‰D$è,éÿÿ‹D$„I‹$…ÒˆbÿÿÿHƒêI‰$…Tÿÿÿé~ïÿÿL‹Ò= H�5íI‹;èûèÿÿHÇD$éÎýÿÿH‰éH�àH�5ýH�=èðèÿÿHÇD$é£ýÿÿH‰Ö¹ºH�=÷èéèÿÿ…ÀtÕé­îÿÿL‹eL‰M…äŽïÿÿM‰ãIÑûL‰\$…Iüÿÿé[ýÿÿL‹ #= H�5ìI‹9èdèÿÿéýÿÿé§îÿÿf.„AWAVAUATUH‰õSHƒì(H‹Fö€«„ˆH‹^H…Û„¦H‹VL‹dÚøA‹ $ƒÁtA‰ $1ÉH�sÿH‰ÚH‰ïèÚçÿÿ…À…�îÿÿHƒû„8L‹MI‹1M‰!L‹eH‰t$M…äާîÿÿL‰çHÑÿH‰|$„E1íO�D-I�XIƒÀL�<ÝO�9M‹2M9ÄŽžO‹<ÁE‹AƒÁ„íE‰E‹AƒÂ„èE‰1ÒL‰þL‰÷èrçÿÿM‹E…ÛˆIƒëM‰„ÜM‹7E…öˆIƒîM‰7„ñ…ÀxXƒðL‹MHÃL;eu1L�<ÝO�,éK� 9I‹UH‹9H‰I‰}H9\$ŽI‰Ýé3ÿÿÿL‹%”; H�5]I‹<$èÔæÿÿH‹|$H‹…Òˆ|íÿÿHƒêH‰…oíÿÿè¢æÿÿHÇD$H‹D$HƒÄ([]A\A]A^A_ÃA‹ƒÀtA‰L‰þ1ÒL‰÷è�æÿÿI‹6…öx&HƒîI‰6uL‰÷‰D$èQæÿÿ‹D$ff.„f�M‹E…Àx(IƒèM‰uL‰ÿ‰D$è#æÿÿ‹D$ff.„@…ÀˆDÿÿÿƒðL‹MHÃL;e…ÿÿÿL�<ÝO�9M‹2O�éI‹ I‰ M‰3H9\$�êþÿÿL‹uL9ó�•O‹$9L�kÿA‹$IÑýJ�<íO‹<éH‰|$ƒÂ„–A‰$A‹ƒÀ„’A‰L‰þ1ÒL‰çè—åÿÿI‹7…öˆ¬HƒîI‰7„ˆM‹$E…ÀxIƒèM‰$„ìÿÿ…Àˆ|þÿÿL9u…ï…À„•þÿÿL‹MH‹|$I�ÙLÏL‹#H‹L‰'H‰ L‰ëM…í…JÿÿÿéhþÿÿE‹AƒÁtE‰1ÒL‰þL‰çèåÿÿM‹E…Òx IƒêM‰uL‰ÿ‰D$èËäÿÿ‹D$€M‹$E…ÛˆkÿÿÿIƒëM‰$…]ÿÿÿévëÿÿL‰d$éýýÿÿH‰ñH�™ H�5— H�=ã è©äÿÿHÇD$éÒýÿÿL‹<9 H�5W I‹8èeäÿÿHÇD$é®ýÿÿH‹-9 H�5É H‹}è@äÿÿégýÿÿé,ëÿÿfDAWI‰ÿAVAUATUSHƒìHH‹GH‰t$H‰ÇHÑÿH‰|$0H=Ä �ËH‹T$0H‰ÓHƒëˆoƒâ„ÔHƒú„¦Hƒú„ƒHƒútdHƒútDHƒút$Hƒú…LH‰ÞL‰ÿL‹d$AÿÔ…À…fHƒëH‰ÞL‰ÿL‹l$AÿÕ…À…LHƒëH‰ÞL‰ÿL‹t$AÿÖ…À…2HƒëH‰ÞL‰ÿH‹D$ÿÐ…À…HƒëH‰ÞL‰ÿH‹l$ÿÕ…À…HƒëH‰ÞL‰ÿL‹d$AÿÔ…À…æHƒëHƒûÿ„’L‹l$H‰ÞL‰ÿAÿÕ…À…ÂH�sÿL‰ÿAÿÕ…À…°H�sþL‰ÿAÿÕ…À…žH�sýL‰ÿAÿÕ…À…ŒH�süL‰ÿAÿÕ…Àu~H�sûL‰ÿAÿÕ…ÀupH�súL‰ÿAÿÕ…ÀubH�sùL‰ÿAÿÕ…ÀuTHƒëHƒûÿ…sÿÿÿH‹77 HƒÄH[]A\A]A^A_ÃH‰ÞL‰ÿH‹l$ÿÕ…ÀuHƒëéšþÿÿH‰ÞL‰ÿL‹t$AÿÖ…À„ÿ1Àë½H�w1ÉHÑþƒÁHƒþuôHÓæHÁøL�FÿL�NþL‰D$(L‰L$L9È�æHƒèH‰D$ €H‹\$L�”ðÿÿL9T$u�M‹_L9Û�MéÿÿL‰ßI‹GHÑÿH9û�„H‰<$H‰ÚM‰ýH‰\$I‰×L‰ÛO�?I�hIƒÀL�4íJ�40L‹&L9ÃŽON‹4ÀA‹$ƒÀ„�A‰$A‹6ƒÆ„˜A‰61ÒL‰öL‰çècáÿÿI‹ $…Ɉ·HƒéI‰ $„�M‹&E…äˆÍIƒìM‰&„¡…ÀˆàþÿÿƒðHÅI‹EI;]…/L�4íN�<øN� 0M‹M‹M‰M‰H9,$ŽÀI‰ïé.ÿÿÿA‹>ƒÇtA‰>1ÒL‰öL‰çèÎàÿÿI‹$…Òx&HƒêI‰$uL‰ç‰D$<è�àÿÿ‹D$ýÿÿL‹d$M;g…u…Àt&I‹GH�ØIÅL‹#I‹MM‰eH‰ H‰ëH9,$ŒOÿÿÿH‹$öÃ…PHƒl$L‹L$L;L$ …*ýÿÿH‹l$0HƒíH‰l$H9l$(�ƒüÿÿ�H‹\$L�-¤íÿÿL9l$…M‹gL9ã�íåÿÿM‰âI‹GIÑúL9Ó� I‰ÞO�6M�kIƒÃJ�4íH� 0H‹)M9Ü޽‹UJ‹<؃„ö‰UD‹AƒÀ„ïD‰H‰þ1ÒH‰<$H‰ïL‰T$èyÞÿÿH‹uL‹$L‹T$…öˆHƒîH‰u„äI‹…Ɉ+HƒéI‰„þ…ÀˆîûÿÿƒðIÅI‹GM;g…wJ�4íN�4ðH�,0M‹L‹]L‰MM‰M9êŽM‰îéÿÿÿH‰ÞL‰ÿL‹t$AÿÖ…À…•ûÿÿff.„f�öÃ…çHƒl$H‹\$H9\$(Ž¡þÿÿéûÿÿ‹ƒÀt‰1ÒH‰þH‰<$H‰ïL‰T$è�ÝÿÿH‹}L‹$L‹T$…ÿx,HƒïH‰}u"H‰ï‰D$ L‰D$L‰$è=Ýÿÿ‹D$ L‹D$L‹$I‹…Òx)HƒêI‰u L‰Ç‰D$L‰$èÝÿÿ‹D$L‹$„…ÀˆÐúÿÿƒðIÅI‹GM;g…YJ�4íH� 0H‹)N�ðM‹3L‰1I‰+M9ê�äþÿÿM‹gM9ìŽ\äÿÿHÆL9ë�öþÿÿL‹6M�MÿIÑùJ‹,ÈA‹J�<ÍH‰|$ƒÀ„.A‰D‹EAƒÀ„(D‰E1ÒH‰îL‰÷L‰ $èyÜÿÿH‹UL‹$…ÒˆIHƒêH‰U„M‹E…Òx IƒêM‰„dãÿÿ…ÀˆöùÿÿM;g…l…À„\þÿÿI‹GH‹|$N�,èHÇM‹uH‹/L‰7I‰mM‰ÝL9ÛŒ?ÿÿÿé-þÿÿff.„f�HÑûéíùÿÿ„HÑûéÍüÿÿA‹ƒÂtA‰1ÒL‰öL‰çèÀÛÿÿM‹E…Àx(IƒèM‰uL‰÷‰D$<èƒÛÿÿ‹D$ heap[0]: item = heapreplace(heap, item)heappop($module, heap, /) -- Pop the smallest item off the heap, maintaining the heap invariant.heappushpop($module, heap, item, /) -- Push item on the heap, then pop and return the smallest item from the heap. The combined action runs more efficiently than heappush() followed by a separate call to heappop().heappush($module, heap, item, /) -- Push item onto heap, maintaining the heap invariant.Heap queue algorithm (a.k.a. priority queue). Heaps are arrays for which a[k] <= a[2*k+1] and a[k] <= a[2*k+2] for all k, counting elements from 0. For the sake of comparison, non-existing elements are considered to be infinite. The interesting property of a heap is that a[0] is always its smallest element. Usage: heap = [] # creates an empty heap heappush(heap, item) # pushes a new item on the heap item = heappop(heap) # pops the smallest item from the heap item = heap[0] # smallest item on the heap without popping it heapify(x) # transforms list into a heap, in-place, in linear time item = heapreplace(heap, item) # pops and returns smallest item, and adds # new item; the heap size is unchanged Our API differs from textbook heap algorithms as follows: - We use 0-based indexing. This makes the relationship between the index for a node and the indexes for its children slightly less obvious, but is more suitable since Python uses 0-based indexing. - Our heappop() method returns the smallest item, not the largest. These two make it possible to view the heap as a regular Python list without surprises: heap[0] is the smallest item, and heap.sort() maintains the heap invariant! Heap queues [explanation by François Pinard] Heaps are arrays for which a[k] <= a[2*k+1] and a[k] <= a[2*k+2] for all k, counting elements from 0. For the sake of comparison, non-existing elements are considered to be infinite. The interesting property of a heap is that a[0] is always its smallest element. The strange invariant above is meant to be an efficient memory representation for a tournament. The numbers below are `k', not a[k]: 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 In the tree above, each cell `k' is topping `2*k+1' and `2*k+2'. In a usual binary tournament we see in sports, each cell is the winner over the two cells it tops, and we can trace the winner down the tree to see all opponents s/he had. However, in many computer applications of such tournaments, we do not need to trace the history of a winner. To be more memory efficient, when a winner is promoted, we try to replace it by something else at a lower level, and the rule becomes that a cell and the two cells it tops contain three different items, but the top cell "wins" over the two topped cells. If this heap invariant is protected at all time, index 0 is clearly the overall winner. The simplest algorithmic way to remove it and find the "next" winner is to move some loser (let's say cell 30 in the diagram above) into the 0 position, and then percolate this new 0 down the tree, exchanging values, until the invariant is re-established. This is clearly logarithmic on the total number of items in the tree. By iterating over all items, you get an O(n ln n) sort. A nice feature of this sort is that you can efficiently insert new items while the sort is going on, provided that the inserted items are not "better" than the last 0'th element you extracted. This is especially useful in simulation contexts, where the tree holds all incoming events, and the "win" condition means the smallest scheduled time. When an event schedule other events for execution, they are scheduled into the future, so they can easily go into the heap. So, a heap is a good structure for implementing schedulers (this is what I used for my MIDI sequencer :-). Various structures for implementing schedulers have been extensively studied, and heaps are good for this, as they are reasonably speedy, the speed is almost constant, and the worst case is not much different than the average case. However, there are other representations which are more efficient overall, yet the worst cases might be terrible. Heaps are also very useful in big disk sorts. You most probably all know that a big sort implies producing "runs" (which are pre-sorted sequences, which size is usually related to the amount of CPU memory), followed by a merging passes for these runs, which merging is often very cleverly organised[1]. It is very important that the initial sort produces the longest runs possible. Tournaments are a good way to that. If, using all the memory available to hold a tournament, you replace and percolate items that happen to fit the current run, you'll produce runs which are twice the size of the memory for random input, and much better for input fuzzily ordered. Moreover, if you output the 0'th item on disk and get an input which may not fit in the current tournament (because the value "wins" over the last output value), it cannot fit in the heap, so the size of the heap decreases. The freed memory could be cleverly reused immediately for progressively building a second heap, which grows at exactly the same rate the first heap is melting. When the first heap completely vanishes, you switch heaps and start a new run. Clever and quite effective! In a word, heaps are useful memory structures to know. I use them in a few applications, and I think it is good to keep a `heap' module around. :-) -------------------- [1] The disk balancing algorithms which are current, nowadays, are more annoying than clever, and this is a consequence of the seeking capabilities of the disks. On devices which cannot seek, like big tape drives, the story was quite different, and one had to be very clever to ensure (far in advance) that each tape movement will be the most effective possible (that is, will best participate at "progressing" the merge). Some tapes were even able to read backwards, and this was also used to avoid the rewinding time. Believe me, real good tape sorts were quite spectacular to watch! From all times, sorting has always been a Great Art! :-) ;Ôкÿÿð�»ÿÿ\¸»ÿÿà(½ÿÿDu½ÿÿÈú½ÿÿ(ÀÿÿˆsÀÿÿðÁÿÿP®Áÿÿ°!Âÿÿ<ÈÂÿÿ€ðÂÿÿpÅÿÿX ÇÿÿÜÀÉÿÿ<PÍÿÿœ`ÎÿÿÀÒÿÿdàÖÿÿÄ`áÿÿ áÿÿô`âÿÿP�âÿÿ”Ðâÿÿ¬zRx �$عÿÿÀFJ w€?;*3$"$D@àÿÿ7A†KƒA gAAzRx � ƒ† ,ºÿÿ(HœxÁÿÿB�BŽB �B(ŒA0†A8ƒD`ø 8A0A(B BBBA zRx �`ƒ†Œ�Ž�(йÿÿp, ¤ßÿÿ½BŒA†A ƒr ABA zRx � ƒ†Œ$ܺÿÿMH„°ÂÿÿB�BŽB �B(ŒA0†A8ƒGP 8A0A(B BBBA zRx �Pƒ†Œ�Ž�(¥ºÿÿ…H<Äÿÿ’B�BŽB �B(ŒA0†A8ƒG`d 8A0A(B BBBA pʺÿÿ#Hh|Æÿÿ‡B�BŽB �B(ŒA0†A8ƒD`È 8A0A(B BBBA Ð�¼ÿÿV0ȬÉÿÿBŒA†A ƒG0{  DABA zRx �0ƒ†Œ${¼ÿÿªH0TÊÿÿVB�BŽB �B(ŒA0†A8ƒG`‰ 8A0A(B BBBL ˜żÿÿ‘H�TÎÿÿB�BŽB �B(ŒA0†D8ƒD`Ÿ 8A0A(B BBBA øö¼ÿÿsLðÒÿÿ² B�EŽB �B(ŒA0†A8ƒD€¬ 8A0A(B BBBA $zRx �€ƒ†Œ�Ž�,ݼÿÿ§|Ýÿÿ"A\zRx �@½ÿÿ!`ÀôÜÿÿ>]`ØÝÿÿ `1 1`] Ue À ì2P] X] õþÿoð8( Š X_ ¸ ¨ ûÿÿoþÿÿoðÿÿÿoðÿÿoÂùÿÿo h] ö   & 6 F V f v † – p183 €@8]3`€`7u3Ð"à6i3p€ 5Š3 2À4+3°1€4}3p2@4L30€à3ÿÿÿÿ’3 8@` ` GA$3a1À ù2_heapq.cpython-312-x86_64-linux-gnu.so-3.12.13-3.el8_10.x86_64.debugtkU!ý7zXZæÖ´F!t/å£àgÒ]?‘E„h=‰¦ÚŠáƒ2NÙHFv ™ãþÂt¦'ŠŽGëLôù¢$�«Jõ²uøóÿ¥Æ#)HQªØïóÙÞæzàqþ�èË")ª2pßÀ­ : Ü¥²ØTßÝ’ ®¨Sfóe®Rõ¨¦Â/•�ú£�¨<„ çdg¿‹Ç­læ5éôÝ?€è¡$T÷à Í>ܲèTû‘Aw•†+´ ª;ÐõÒE ˆ€ºL^ÞÓ££utW�õÆü ¯ÚTÆ)Uy%íõ‚ñÓ2˜WS&ëì{Â< �UÂ&¡™™…Ñ *(±àr>°¸Òoø¾g0„à½AB±L§Eò.Îq½v‚†”æÌ§šÄR¯©´„y„GÁ˜V¡~µf3j^Äg7[Ø©”Õ&jÁuƒU…‰O¬Œ­ÛBJfl‰éj¦gY…_4b_¿0™x½dg\*ËP°Ûq�ñ ÌO”ëo[¢ÙÆ5Hý—4KY¡K¯FùVô¾·‹v�wèZÞaR7@�‰:íëÖ`÷´7I-.T+Í3Òn–i÷1k`"n„ö�< v½w»� 1“Iœ¿¨O±R$à/]k§F,ꛂ&™@Õz?,r‚ú(ŸKDÝÝê8xÚåFMˆtÕÒÚ…Ù‰®áu8êòt•ì° Ó¬öË«¡kæëƒÌü,Ú¢5©û¥˼Ž-ü~ý|éÈäa<3BXÅñЂxùPSVOZé[Ùü,­éè¾Þ(7k^ª;ºðk>9é¨Å4œ™ðœÈž•}eÙ¬Eñ’`�$,7U«5ý•/ëÈœù[`B™ÚÍ]1¸&!ÍzŒã¦S~ ¸flºæ¬+îè ]½v±ÄgûYZ.shstrtab.note.gnu.build-id.gnu.hash.dynsym.dynstr.gnu.version.gnu.version_r.rela.dyn.rela.plt.init.text.fini.rodata.eh_frame_hdr.eh_frame.init_array.fini_array.data.rel.ro.dynamic.got.data.bss.gnu.build.attributes.gnu_debuglink.gnu_debugdata ÈÈ$öÿÿoðð4( ((088Š8ÿÿÿoÂÂ,Eþÿÿoðð T¨^B¸ ¸ hÀ À cà à Àn    L'tì2ì2 z33 ‚PPÔ�èPèPìšP] P]¦X] X]²`] `]¿h] h]ðÈX_ X_¨Í` `È ÓÈa ÈaØÐa`Èa$îìaLý8bLf