Koko Eating Bananas

Medium

Koko loves to eat bananas. There are n piles of bananas, and the i-th pile has piles[i] bananas. The guards have gone and will come back in h hours.

Koko picks an eating speed of k bananas per hour. Each hour, she chooses one pile and eats k bananas from it. If the pile has fewer than k bananas, she eats all of them and doesn't eat any more during that hour.

Koko likes to eat slowly but still wants to finish all the bananas before the guards return.

Return the minimum integer k such that she can eat all the bananas within h hours.

Examples

Example 1

Input:  piles = [3,6,7,11], h = 8
Output: 4

At speed 4 the piles take 1 + 2 + 2 + 3 = 8 hours, just in time. At speed 3 they'd take 1 + 2 + 3 + 4 = 10 hours, which is too slow.

Example 2

Input:  piles = [30,11,23,4,20], h = 5
Output: 30

Five piles in five hours means one whole pile per hour, so the speed has to be at least the biggest pile.

Example 3

Input:  piles = [30,11,23,4,20], h = 6
Output: 23

At speed 23 the piles take 2 + 1 + 1 + 1 + 1 = 6 hours. At 22, the 23-banana pile needs a second hour too: 2 + 1 + 2 + 1 + 1 = 7.

Example 4

Input:  piles = [1000000000], h = 2
Output: 500000000

One huge pile split evenly across two hours.

Example 5

Input:  piles = [312884470], h = 312884469
Output: 2

Speed 1 would take 312,884,470 hours, one more than she has.

Constraints

  • 1 <= piles.length <= 10^4
  • piles.length <= h <= 10^9
  • 1 <= piles[i] <= 10^9
TypeScript
Loading editor…
Test cases31
Case 1
piles = [3,6,7,11]
h = 8
Case 2
piles = [30,11,23,4,20]
h = 5
Case 3
piles = [30,11,23,4,20]
h = 6
Case 4
piles = [3,6,7,11]
h = 4
Case 5
piles = [1,1,1,1]
h = 4
Case 6
piles = [1]
h = 1
Case 7
piles = [1]
h = 1000000000
Case 8
piles = [5]
h = 1
Case 9
piles = [5]
h = 4
Case 10
piles = [5]
h = 5
Case 11
piles = [1000000000]
h = 2
Case 12
piles = [1000000000]
h = 1
Case 13
piles = [1000000000]
h = 1000000000
Case 14
piles = [312884470]
h = 312884469
Case 15
piles = [1000000000,1000000000]
h = 3
Case 16
piles = [1000000000,1000000000]
h = 4
Case 17
piles = [805306368,805306368,805306368]
h = 1000000000
Case 18
piles = [2,2]
h = 2
Case 19
piles = [2,2]
h = 3
Case 20
piles = [2,2]
h = 4
Case 21
piles = [9,9,9,9]
h = 5
Case 22
piles = [10,20,30]
h = 59
Case 23
piles = [10,20,30]
h = 7
Case 24
piles = [7,7,7,7,7,7,7]
h = 7
Case 25
piles = [1,2,3,4,5,6,7,8,9,10]
h = 20
Case 26
piles = [58,28,84,56,66,94,88,66,41,54]
h = 632
Case 27
piles = [1544,222,913,982,1785,1938,1335,1019,268,1087,1073,1993,369,219,253,1708,845,1160,36,1251,1152,1949,1116,594,1397,1364,539,1177,509,414,245,552,281,822,531,578,367,1199,901,1812,335,1451,1,1672,1239,710,1508,1597,882,1872]
h = 32539
Case 28
piles = [467872,731067,764366,211663,488,908281,519914,939432,752303,26911,658386,766875,325387,220220,955943,738386,631868,948881,776368,611851,502268,327778,476671,505594,544852,95955,33379,83343,407469,26545,15559,388112,371801,322657,765122,548898,159904,367406,550559,55867,398571,868350,459852,197697,254759,788990,867902,319623,446699,179754,656609,851076,274807,14867,998201,559669,112582,75054,352394,264096,912924,287280,980068,38294,781437,49500,925669,874861,882267,251379,74081,192386,301811,699166,323660,717327,706632,78549,126950,401114,43748,28523,951284,81014,96404,752722,968071,687640,819963,369502,677185,653948,754241,961916,845209,302358,927957,581830,489368,999604,581055,30915,799771,942476,146473,537312,643584,448041,5504,242359,729377,984624,97058,103616,294592,468971,305086,857299,890611,679533,218373,219610,421321,837328,691853,655917,601384,336674,462878,504715,558387,307920,354995,934472,943382,731654,205591,355393,210129,176703,537866,53262,312854,426900,247777,461087,981173,737748,762723,568826,503056,839075,439239,605217,508727,912779,469419,228409,432240,366507,363599,959075,255431,44405,855428,449004,695486,598417,255265,477140,658946,499508,85719,402837,681135,40613,849673,995611,556538,535534,225737,428298,6913,567986,687363,631177,164828,850925,497244,757502,404643,127388,480606,618686,953611,841465,296266,180778,641675,632710]
h = 14501990
Case 29
piles = [564021265,512207427,373764896,786428130,544489927,490044147,823798474,194736757,840182061,810012014,54872447,661929262,458765220,566965459,911674674,595643050,617399581,981500717,510635669,659376431,365949960,285367414,121380763,515800371,199294129,917529168,786799314,145411051,928421792,600629578,57937497,469054077,763066091,753222017,242461343,689571412,401234267,165818433,687194735,635456797,430976638,951574722,697840987,4797367,20226141,532155608,351419305,464770095,712777471,568494130,658530911,631034445,670065253,317263967,563474997,263513002,17974979,320511221,647804445,574018492,489568018,139319502,625902067,372727362,837073966,390553389,148379919,247535514,374303978,330566352,151719606,259444557,814788677,893189223,152483529,445898444,933476473,331726118,61114232,562456721,605556433,411459678,159367877,708324168,760387175,284898097,267078267,882056137,898434493,30524138,98163455,838923546,153121208,390707082,347879787,852477693,53107809,70722733,328495063,289936743,369886278,859764390,292878552,733063881,642271,781639770,117549659,13067783,578193273,275862554,807248673,543614756,604911602,995471976,616525160,67993369,851611716,765341256,336735679,667522878,3675155,950345078,573793712,270348901,455144257,283618685,925493638,310698845,439098749,743102966,33731949,9268327,869718435,793192565,270576985,910466717,771155442,635189731,603174642,132597329,451883821,2384047,628234264,186833374,539737829,443260080,268265821,846960634,112430811,170251240,93403735,881884644,728552269,242744715,520738259,822909154,693937789,656540748,941225620,879884538,128681969,219465693,745825558,800389193,175619359,696778586,715743891,800717066,539375739,946952212,255784530,886521779,153957619,229313037,659571396,363525467,127860267,368068295,305403931,911246343,202766381,309649531,725038002,408118823,303513790,385547107,85802894,539945577,413558519,939766238,386140894,577330311,243213028,58490610,990177637,36748213,307314530,52165030,581631320,103684829,115840379,854611266,351501290,810477224,582721225,87092949,717868121,728863057,509798132,973579517,52184399,429581210,528459958,941992215,297424664,159232266,109599477,590393339,847305849,642426497,591854408,873097691,244984045,657169041,645472584,615039608,141005642,541703841,76824723,527461636,221204178,704678074,717524072,626129995,746234829,849899563,932036749,948021379,247105087,62459466,466587790,483659124,776890598,534266938,239677046,757986582,72283361,345374198,525446271,420308160,571043095,650436086,957923649,77862724,995262294,39930806,728278059,523767057,929660719,431948625,396115980,726916825,457197052,50309253,871414115,400954694,715911810,532950531,502470529,291552396,458676184,340905623,635207817,373829618,570101031,21925002,130491529,153794782,273886139,450435643,38558720,292612627,5148148,224594387,983358016,592132127,152567725,386313826,712846099,998519022,356672349,969907363,761118581,418701559,119044770,756519541,126334658,873147428,285901664,628736780,710240826,748001643,339647301,306759987,436431545,171521330,185806461,563069252,616358406,308174996,854709153,295300315,873715461,739340883,204497953,534303608,876640931,272085677,642527109,789181364,24563371,762327489,667695843,515700826,978765206,741139591,174371582,160761066,126402706,468600508,591904190,814618398,617942273,364679597,645473557,72418268,535632235,367034769,319691410,490624547,694828340,354564527,489805101,997242016,671058903,927275548,519426431,517488779,770950107,170555291,118456353,31601297,432360386,226173709,170537854,88254526,103772266,749618842,203165572,260904862,596969954,321349996,944705657,492789023,529577112,283240322,701847333,53201722,631510069,22193977,512794426,506185271,62637631,601126078,205733450,111576896,680023132,851468944,412073243,282679514,571611895,705060718,360991820,346161865,712759872,481109794,35859017,878076782,338115243,900962701,728760557,91981263,168840392,68685983,73290095,472549717,443706580,779854029,585773437,962705213,996481674,97203488,314242179,396030119,886121257,186165213,993994957,248769778,936254898,741937030,477946361,4218334,138226588,293023004,576091891,533177973,53371156,397968455,305252016,597069815,582483794,819676670,571907575,304192037,707613250,319963046,328807761,265067510,796277807,515274104,885764198,635918326,609910300,832732195,229230015,369855361,656481065,629142299,891395406,456842417,247471801,667819464,948707483,125637491,368446146,499958569,249237836,458249774,462344492,635180920,530008633,616241692,933147230,517507585,468516865,593633200,523286288,556463697,899799849,148222743,423323457,217400032,833516325,520075603,666738621,454145090,276469742,746775449,410885665,897257834,784844339,434373510,737379941,16629254,377746883,10013906,662493672,645874702,692677735,610922899,189658597,101244908,960154971,397747369,603139838,9621804,435555014,253708178,467522968,381704772,451492826,403274019,277649019,914372798,417716382,463408872,182518339,387891064,272080171,473507751,988004141,715485568,162185513,997374686,789199866,103115299,525096325,126099920,355525488,439915801,858407722,446018254,18683201,872314766,140110342,944793959,627666918,376804150,270343785,919273760,534612439,15598171,616776981,374569131,886141986,896107507,645608540,264059878,605383725,766291395,440635223,891710438,424311863,978123476,635258218,605474886,290946403,881659872,160222956,404781792,56659821,564322823,180447182,691944088,413831259,138492384,975006321,648361316,389848452,338788507,563638728,555361875,802324132,129756264,65524350,614239599,880203162,274380828,742079804,257888412,324852185,181344104,147484086,907028192,625208084,191737678,380995995,864324221,737630220,785227133,265872096,876376823,908061250,406527272,2474835,401402209,878783086,809561935,125931210,483643828,482612211,279790576,229602371,354192154,344448840,773985640,699423856,186255986,428845206,121311039,145909487,247244575,170550455,917242413,179644692,685306118,155124041,942542456,636051553,473816389,292696781,181315781,835027639,939759625,985301857,868007052,626736962,568282872,626212699,848567146,805553823,671902344,643250930,337314551,293100804,99635601,8357698,848681281,411435925,239554148,293516696,743479524,425835430,742041883,330162764,381851938,730307251,301908409,443867942,7665410,147310054,68365413,883241956,736499921,150887068,610651679,788381984,941400186,176199922,463685873,481438720,558201725,271338120,894794730,892465489,662802573,844185238,50606698,813322562,427767071,182501879,282431967,912503129,718813183,650977725,671641748,682683811,639828137,282186719,861876037,923235710,93983459,490939644,58543249,833706403,966876015,464298324,840949165,147323421,279801445,963838103,384924962,866366570,292445194,870424055,888473001,223040437,802934540,439501828,856824953,979186685,707993268,854299206,215044514,66091402,94704781,77698119,147206344,836452288,758646427,857860209,825290137,859786403,18615834,477137162,141516588,106621510,644196926,359052256,814520156,140917317,637115811,328427629,734245306,43804673,747800195,417956611,729869430,958514868,431289951,619645085,489736223,738644580,695896485,34575721,951900271,537778307,387371438,956203472,88418055,265065811,635333972,671556487,587006734,244078214,451910866,11671717,417743313,812172653,619288952,377685607,468424231,782019630,388644289,584506604,571174371,169424878,714901113,391602960,623255934,756056530,169950827,162013479,790457891,901184003,443855268,457070735,680448717,435926874,77794753,799625494,296444061,284093808,340486766,441486793,756150132,285939267,237986456,14168460,262899293,186497610,890415926,408677550,281404034,463355753,99363237,498809975,655389175,900445393,719209055,862880311,357358922,974076465,867536960,962307021,733572468,505530865,494215249,647920464,276969136,735611610,686824459,115733691,396542071,721820425,597168534,389012820,669178873,698084924,271803985,672758490,632145718,903290975,192640119,20685561,413046054,227079709,160384810,198786068,104598883]
h = 124231480
Case 30
piles = [362391138,917644225,504716681,957864348,301459227,459888569,306072757,900553828,950689943,463463605,317508941,533943012,814094761,466573596,614937334,114010587,938531386,586415907,241210150,650934696,417393126,79209220,604458773,335297767,976822202,779288412,14129817,960199099,946947019,473290647,116691730,381909800,368750128,344447135,264379894,553592407,735813369,271610052,693391357,989245044,755894801,783028006,29406189,776526546,877312560,263612665,114787900,516905582,383385431,693820654,371274437,358988550,520476114,487727510,134232785,640483549,137962697,302665279,900078563,282013208,352161970,69245879,671994528,664977383,212242323,450649237,683882025,220765821,439314776,799784996,761875869,122148969,159644968,26304118,255844691,779521684,306306377,990930005,929195910,652930033,1505072,654139830,813775316,544795665,338937123,365719806,716703965,682974013,464354168,366778792,593056014,185500065,472681197,368260755,926547562,170636542,965175742,426407557,428692135,411491854,803862732,163931218,807139372,559220302,778914822,739927575,808440605,580732,788852933,659074374,615386663,146707768,295313176,525645542,923695867,137797049,996408752,985594621,504399627,52400909,554083075,942847407,656385905,151846274,387411569,52483220,477070213,401416004,141336905,572686854,894919952,822084478,437133576,880102874,174728247,813456013,911079272,267134334,37752407,223231998,977566771,532383451,360359745,944856568,282914842,140439297,212888312,944963877,682644365,674356763,363447843,993071784,351507103,313430932,796848433,443802297,396544956,353619554,979001565,737453498,367083207,277117450,429602263,432036934,795425119,232193761,449192878,878511824,180689386,908211832,416436586,367796679,943376777,885080034,523792885,935091749,397487832,522201666,505890977,900393438,508861489,401269721,405295639,774422990,911844180,484300743,287509100,29466247,15659980,509643219,629091483,835688525,793263710,701864034,946009508,573197750,408102628,905053238,847754519,962111702,192803049,611986227,84728132,856604376,980725246,816364427,758948667,139348747,368351558,963921371,122475846,360894281,138467387,728944033,359410433,671108119,555434263,644796183,905659101,539066781,207009908,918799541,431600509,672304596,277679744,272353358,161876493,935236422,390301141,199648365,499698889,945118341,947154438,517597861,798505322,753571674,385512746,6227127,691980441,510430744,887965447,51716046,121519458,272312180,457645653,538098002,940710861,161463801,567163746,395907422,380849903,950836803,358167390,961263448,276435292,765359724,62098021,889521120,278458347,49630797,930783227,579207658,733427705,762058732,363051142,149776693,574279960,162011874,310485677,682885426,161591837,732210808,818759159,980145554,93935233,670933074,596853512,293252868,157167431,949641503,783122643,142568853,505344853,723500180,151767700,171469788,292308905,100967758,544486352,208792409,236751965,833015035,597950968,751604676,410470559,882249392,550195278,704256944,526547911,881214769,509671432,134148254,108027055,540289992,142068818,520316522,694112009,256611293,220631143,342430019,571439702,457533094,198981736,946598259,182542175,640349025,783707854,611982063,520623471,435013558,174103321,842198010,389819057,886359589,704337131,816200335,767237273,423415507,329856854,989671677,765473800,261048517,855497838,827298224,115105578,528171310,192382652,808036241,811765238,509529199,926310795,380370653,371568748,100493374,369609177,667026804,676678721,132800677,618952892,357920779,358019542,294505152,714060664,964261214,95980762,332187367,560562698,989944049,567767518,67649834,874976445,60077931,590488156,62643315,97356438,376799644,680138732,270074078,191095705,241714484,350534782,399144547,291461464,985871837,537432399,637484230,335986001,468079974,175627272,1340575,512083906,102157986,365305929,557248748,407725743,912035682,456405120,882929234,637469181,807446293,265542278,795832659,745395850,838725489,708435772,579392124,994483356,980047550,809729631,855933800,180050322,639757894,173027951,333293782,436656201,487015159,22923570,688781298,33706969,505612645,686546512,419343905,560524578,95720927,224514988,206338144,358501924,215170462,982794646,948087478,619195952,935499432,965328526,344673918,406371474,151837553,251310165,742828255,464808283,869953765,216466212,203571193,37380341,466793474,517587608,975233840,600891759,630070917,540528095,770912057,348564862,476994779,87406477,736647192,365423359,33456705,750189912,542747753,139960288,973183818,43157549,313728506,882072848,194890882,683296702,652181182,85050530,436606763,909627651,45544735,124696689,139720936,853717644,673636547,775537462,474520861,98572387,166029505,108503765,613654903,158895907,406816993,607038773,123369162,30747724,471679265,17631504,437312440,942193965,352457455,531659425,143188525,41246404,781241285,14788794,348692288,757425020,579329144,345347994,170549641,240452872,270844231,216305205,683842576,180455369,883695692,664355520,588946129,612126357,981352563,212709265,861479342,118095079,633267245,968733651,827764415,670009948,301870884,896636444,12162979,482941607,726586530,697541591,520771795,557836769,789227808,579403088,199995789,520873463,27528368,904203244,86034367,917684226,391144593,253143828,983536779,284957558,691350193,281831880,140011822,14670489,556496288,442051769,40634476,983940013,542616030,313052534,73419385,745674649,492641420,541376147,107969742,838322056,632780967,689045514,669456515,912331993,963142246,196230739,384428515,797418098,751745310,940582211,781806693,945990497,683397798,951890674,962959191,846827398,572922473,248842530,15345168,400354179,576202531,7409258,700436348,159971912,723752803,787837822,909902466,459490835,609863073,474728627,40685122,894610492,756492072,46145235,917808202,934577107,899632032,611074542,410357066,134053236,749671371,820000397,526286831,566758963,945308395,830477954,133403585,200594138,433515075,839002048,764223598,963695899,737553975,596642163,87324355,977630250,143971732,973898528,777893741,422798329,623979349,878265591,413092105,717411246,909967714,381974169,708750998,569076613,567707141,107035883,221517342,390268284,912728723,549849388,881019422,285473302,951713909,810771742,558679413,213426166,676853328,84637774,656872834,994418834,56452502,382853375,956465948,160543861,324555529,100711934,916588684,922581965,106254775,967436588,200574503,573864282,5630525,989877811,115538946,98554612,371955717,403807350,810760647,263466997,668645665,616397676,722284646,493810031,395320497,644065113,274292055,678911199,265288363,461276342,346851141,325703759,712334574,491906509,343120515,436041494,201304093,247474148,852541976,631504088,946449452,14779540,727924651,907148628,983498197,527406173,116841246,67854151,467307427,44018403,504333665,824290045,728964421,650978341,879600289,565993587,719708715,630061567,764857321,800766714,901655295,191486674,439132364,825352562,927606587,78590307,106152776,794176697,497127405,109276883,790147960,67767792,849202672,816132899,318720889,687906934,944297090,859186450,943440293,151572253,299322117,429791798,854689083,916060040,599830490,346269077,976090043,508159181,129959440,807124942,47831377,61682994,1960220,405223001,48307658,829436948,46860805,370325616,984388587,564206694,367509817,93407961,363315041,10301215,628606027,482867202,973618734,379345898,999634525,554973735,377973657,673676692,433092188,701016631,265264899,846157915,671765407,81242053,688428759,157550260,46949008,114064157,778334261,110433934,38914457,902421791,263666034,922703360,291037848,589709011,123426305,598148057,865317835,988944756,96076020,273116659,346884713,294258113,679000906,874925434,989854155,806061727,727627363,939509790,384131416,471792599,694856604,314053387,43803562,187460442,17488797,403900421,91873559,349851714,674383011,598977489,305050799,326493610,674276321,759519729,396851732,468995695,84626171,856322957,851255779,964636639,967410525,388968140,22055593,613552058,577532456,754108256,984914899,470381669,516270685,786679660,763072509,869150905,87089657,441088312,853644214,205588078,156259830,29047419,873653100,727260148,226018397,909897331,796918369,515396657,319173675,205990369,341644506,808539039,725225382,793482329,879675261,460039985,721887457,497820563,659082349,974575931,223533033,469764999,35591362,934911410,552864658,837874192,295939219,744576719,659197399,20625020,655655233,778436224,644512550,294187365,158731712,385981806,585249763,543957198,8488055,704825213,882077462,641412065,23943965,846140380,907227248,309165480,445398707,241937030,71267748,489356963,83730161,19588264,863575579,963632883,10533850,172136231,827173425,70090956,203655157,799918041,302671360,841520410,136436377,782263559,715305970,781381791,500148578,710596097,958091535,170947716,179511018,506716792,571835460,2540297,797983099,77037232,564907879,206433268,485626555,360911507,22063112,594792131,900634758,34135763,912912066,546014548,210237715,375115945,338995515,928979571,432773173,750531190,314636166,252186240,137518387,884612724,177644382,733921576,301717976,578031815,216159273,117822256,574295623,368137477,259707329,353867988,649341763,23427191,735606065,638091168,340640107,304303183,493983336,582581662,867423132,75970477,302461019,297376498,69078365,437917976,901394580,587523906,672508048,274377569,907945023,515267112,928634732,380393759,708559613,497569685,340522787,792730857,471637074,593967619,967628587,129715775,640126207,295081187,317390463,352728220,428871477,233315726,730861271,737172153,180178995,597670533,91819055,227421572,131745437,926857299,57187162,659063859,675404351,806506872,181810307,926576083,13706194,944696473,325280925,442101227,510316301,855616166,739279784,303288646,21839659,568455931,615400348,105692133,457821496,586964055,578372731,822392569,95175043,538287856,97911435,242212135,109100226,396165710,635835570,987217832,813227963,198260291,842631611,922424501,609367975,231982846,796929858,565108516,138163953,308897428,315350181]
h = 97482056
Case 31
piles = [944330526,365892609,414346699,976633561,528399814,861141204,552398046,617788569,306817041,681152637,125304621,350560739,622054956,128820556,291054391,611151211,426943867,313704460,788714633,331412952,447925887,953120552,606653037,411928470,862322308,657283278,317061170,369358467,283375861,624910012,819091731,409601258,383133231,591708804,253569704,304429845,865823861,731892868,616765154,148962110,453882430,412940556,386449267,666212853,343169925,997719171,350739778,628468824,959759119,207702292,184059156,182801674,439174808,465680098,322920599,368215165,851127173,847899141,471295519,829126791,452162909,273481217,943785481,589534194,875865582,426583793,566781733,865687486,453506341,303544236,726391604,649114339,968493101,725584475,934426286,758332604,185857317,890906079,568898579,262522164,215161222,356451994,623290685,419753440,779771839,291915517,565578724,844663507,293242973,999743728,729307325,422618614,507346267,587697470,383998186,766478677,400493959,865051890,582086447,342895096,876485772,868830895,274442447,570364407,678915094,444740241,884221482,989322189,924347684,478860320,832403656,352677805,176268412,145599302,484126239,548688656,315003192,720594138,298753971,952870117,674506449,752873661,931664741,348243242,864578167,284357166,763686741,684985967,844418474,653401486,487532067,237515391,959479611,371320113,342654293,539126850,958379719,971916550,285485423,579419844,537865031,684028602,770434714,411065515,164838137,525558441,477048256,139540096,306604397,319107300,810500360,101752802,621365734,769700913,771669024,725854366,344419228,174815333,995318064,736742190,157127745,801661391,858573932,371476086,329778106,725837768,907342653,584294968,772238641,911231403,320461174,802326342,988438868,738036203,474767749,162166749,919813971,662484537,377112498,398451893,972549705,200730300,431476763,903030306,142906209,562367786,830217863,728770727,419083238,490562618,428808823,147308094,306466579,382004953,357367563,499943233,783370070,617884739,688904344,902431026,338761604,571591812,372258443,388396060,409148792,332370657,747001532,932595077,746146919,518815224,894533069,809354209,559645793,527010046,363512690,805213421,608714776,379181754,701765462,375953449,735640119,417798555,354671692,469588373,496144144,230295176,820472810,144554444,301333986,320634353,744878719,219730189,310169604,400412793,615606420,279711309,587252397,610355461,279883445,122101279,494823827,590174226,913554851,660097222,875380094,542020847,101283302,376043438,881457803,300694235,226757758,418771455,818861686,878727903,681857129,323628939,433491170,840508977,226823687,855218024,401565627,522122375,948989775,986840874,319701892,247331537,246898782,786978611,178179046,638059500,906264770,310338068,770580635,125754273,108092246,114343886,970425238,370786640,273061211,492056795,238706005,164535546,625117622,386395975,631560554,431677070,957084738,307842326,517528072,825154319,134639993,549819158,823659721,231089164,305043458,318002233,383933272,862563298,159162353,334520133]
h = 1000000000