question
stringlengths
58
4.29k
label
class label
3 classes
you give weight undirected connected graph consist n vertex m edge it guarantee selfloop multiple edge give graphLets define weight path consist k edge index e_1 e_2 dot e_k sumlimits_i1kw_e_i maxlimits_i1kw_e_i minlimits_i1kw_e_i w_i weight ith edge graphYour task find minimum weight path 1st vertex ith vertex 2 le le n
1graph
you give array length n integer x brand new robot what robot follow iterate element array let current element q if q divisible x robot add x copy integer fracqx end array move element Note newly add element process robot later otherwise q divisible x robot shut downplease determine sum value array end process
0array
Petya organize strange birthday party he invite n friend assign integer k_i ith now Petya like present in nearby shop m unique present available jth present cost c_j dollar 1 le c_1 le c_2 le ldots le c_m its allow buy single present onceFor ith friend Petya buy present j le k_i cost c_j dollar c_k_i dollar directlyhelp Petya determine minimum total cost host party
2string
a bracket sequence call regular possible obtain correct arithmetic expression insert character 1 sequence for example sequence regular Lets regular bracket sequence RBSYou give sequence s n character andor there exactly character exactly character sequenceyou replace character different character replace different bracket you reorder character remove insert character replaceddetermine possible obtain RBS replacement
1graph
suppose sequence k integer a a_1 a_2 dot a_k a_i geq 2 a sequence prime integer p p_1 p_2 dot p_k call suitable sequence a a_1 divisible p_1 a_2 divisible p_2 a sequence prime integer p call friendly unique integer sequence a sequence a call ideal sequence p suitable a friendly ie sequence p suitable a friendly for example sequence 2 4 16 ideal sequence 2 4 6 ideal exist sequence p 2 2 3 suitable a friendlyyou give n different integer x_1 x_2 x_n you choose exactly k way form ideal sequence report impossible note integer choose
1graph
you give integer n dx_1 dy_1 dx_2 dy_2 you select n distinct pair integer x_i y_i way possible pair integer x y exist exactly triple integer b meeting follow constraint begincase x x_i cdot dx_1 b cdot dx_2 y y_i cdot dy_1 b cdot dy_2 endcase
2string
let denote median sequence s odd length value middle s sort s nondecrease order for example let s 1 2 5 7 2 3 12 after sort sequence 1 2 2 underline3 5 7 12 median equal 3you sequence n integer 1 2 dot n odd integer kIn step choose k element sequence erase choose element median these element continuously gap allow themfor example sequence 1 2 3 4 5 6 7 ie n7 k 3 follow option step possible choose 1 underline2 3 2 median erase result sequence 2 4 5 6 7 choose 2 underline4 6 4 median erase result sequence 1 3 4 5 7 choose 1 underline6 7 6 median erase result sequence 2 3 4 5 6 you zero step can sequence b_1 b_2 b_m stepsyoull give t test case Solve test case independently
1graph
consider long corridor divide n square cell size 1 time 1 these cell number 1 n leave rightThere people corridor hooligan security guard initially hooligan ath cell guard bth cell ne b one possible situation the corridor consist 7 cell hooligan 3rd cell guard 6th n 7 3 b 6 there m firecracker hooligan pocket ith firecracker explode s_i second litthe following event happen second sequentially exactly follow order firstly hooligan move adjacent cell cell cell 1 cell 1 leave corridor stay cell currently if hooligan do not light firecracker drop the hooligan can not cell guard secondly firecracker drop explode Formally firecracker j drop Tth second explode T s_jth second example firecracker s_j 2 drop 4th second explode 6th second finally guard move cell close hooligan if guard moves cell hooligan hooligan catch obviously hooligan catch soon late corridor finite his goal maximum number firecracker explode catch act order maximize number firecracker explode caughtyour task calculate number firecracker hooligan act optimally
1graph
there n cell number 12dot n leave right you place robot cell initially the robot exactly k movesIn robot cell leave right provide do not bound in word robot cell cell i1 cell i1 long lie 1 n endpoint inclusive the cell order visit include cell robot place good patheach cell value a_i associate let c_0 c_1 dots c_k sequence cell good path order visit c_0 cell robot initially place c_1 cell robot formally c_i cell robot move then value path calculate a_c_0 a_c_1 dot a_c_kyour task calculate sum value possible good path since number large output modulo 109 7 two good path consider different start cell differ exist integer 1 k current cell robot exactly move different pathsyou process q update print update sum time each update change value exactly cell see input format sample inputoutput detail
2string
you give sequence n integer a_1 a_2 a_n let index j 2 le j le n1 hill a_j a_j1 a_j a_j1 let valley a_j a_j1 a_j a_j1Let define intimidation value sequence sum number hill number valley sequence you change exactly integer sequence number want let sequence remain unchanged what minimum intimidation value achieve
1graph
whoso ignorance draw near hear sirens voice nevermore returnshomer OdysseyIn time Jason Argonauts know siren use sound song lure sailor demise yet know time siren sailor weaken make vulnerable for purpose problem siren song name sailor represent string lowercase english letter the time sailor occur contiguous substring song great danger inJason find siren sing n1 song follow structure let s_i 0 leq leq n ith song t string length n n s_i1 s_i t_i s_i in word i1st song concatenation ith song ith letter 0indexed t ith song fortunately know s_0 t Jason wonder time sailor mention particular song Answer q query give sailor w index song output number occurrence w s_i substre as number large output remainder modulo 1097
2string
only know Pan Apollo were not battle title GOAT musician a millennium later challenge math fast calculation the task get solve followingLet x_1 x_2 ldot x_n sequence n nonnegative integer find value sum_i1n sum_j1n sum_k1n x_i x_j cdot x_j x_kHere denote bitwise denote bitwise orPan Apollo solve second can for convenience find answer modulo 109 7
1graph
after wife tragic death Eurydice Orpheus descend realm death Reaching gate uneasy passing prove challenge mostly Cerberus threeheade hound Hades Orpheus famous poet musician plan calm Cerberus poetry safely walk past he create peculiar poem Cerberus it consist lowercase english letter we poem substre palindrome read backwards forwards a string substre string b obtain b delete possibly zero character begin possibly zero character endunfortunately Cerberus dislike palindrome length great 1 for example poem abaa hound Hades would not like substring aba aaOrpheus calm Cerberus hound like poetry that s want change poem contain palindrome substring length great 1orpheus modify poem replace letter position lowercase english letter he use operation arbitrarily time possibly zero since palindrome poem correction but exactly give poem determine minimal number letter change poem contain palindrome length great 1
1graph
you robot number line at time moment 0 stand point 0you n command robot time t_i second command robot point x_i whenever robot receive command start move point x_i speed 1 unit second stop reach point however robot moving ignore command himFor example suppose commands robot time 1 point 5 time 3 point 0 time 6 point 4 then robot stand 0 time 1 start move 5 ignore second command reach 5 time 6 immediately start move 4 execute command at time 7 reach 4 stop thereyou command successful time moment range t_i t_i 1 ie command bound inclusive consider t_n 1 infty robot point x_i Count number successful command Note possible ignore command successful
1graph
Polycarp find n segment street a segment index describe integer l_i r_i coordinate begin end segment respectively Polycarp realize do not need segment want delete thempolycarp believe set k segment good segment l_i r_i 1 leq leq k set intersect segment set intersection point segment for example set 3 segment 1 4 2 3 3 6 good segment 2 3 intersect segment set Set 4 segment 1 2 2 3 3 5 4 5 goodpolycarp wonder minimum number segment delete remain segment form good set
2string
this easy version problem the difference easy hard version constraint k m version k2 m3 also version problem dont need output answer moduloyou give sequence length n consist integer 1 n the sequence contain duplicate ie element equalfind number tuple m 3 element maximum number tuple differ minimum k 2 formally need find number triple index j z thatmaxa_i a_j a_z mina_i a_j a_z le 2for example n4 a1243 triple i1 j2 z4 i2 j3 z4 if n4 a1111 possible triple suitable
2string
in recent year John successfully settle new job office but John do not like idly sit code compile immediately find interesting distraction the point distraction maintain water level water cooler zebra originally cooler contain exactly k liter water John decide water l liter water r liter John stay office exactly t day he know day exactly x liter water colleague at begin day add exactly y liter water cool point time water cooler range l rNow John wants find able maintain water level necessary level t day help answer question
1graph
there n glass table number 1 ldot n the glass hold a_i unit water currently contain b_i unit wateryou like choose k glass collect water possible to effect pour water glass time like however glass awkward shape totally unrelated natural clumsiness time try transfer water half spill floorformally suppose glass currently contain c_i unit water glass j contain c_j unit water suppose try transfer x unit glass glass j naturally x exceed c_i then x 2 unit spill floor after transfer glass contain c_i x unit glass j contain mina_j c_j x 2 unit excess water do not fit glass spilledeach time transfer water arbitrarlly choose glass glass j pour x transfer positive real numberFor k 1 ldot n determine large possible total water collect arbitrarily choose k glass transfer water glass zero time
1graph
you give different integer point p_1 p_2 p_3 p_4 mathitXY gridIn step choose point p_i direction in word choose point p_i x y x y 1 x y 1 x 1 y x 1 yYour goal point way form square side parallel mathitOX mathitOY axis square 0 allowedwhat minimum number step need square
1graph
you give sequence consist n integer a_1 a_2 dots a_n integer x your task sequence sort consider sorted condition a_1 le a_2 le a_3 le dots le a_n holdsto sequence sort perform follow operation number time want possibly zero choose integer 1 le le n a_i x swap value a_i xFor example 0 2 3 5 4 x 1 follow sequence operation possible choose 2 possible a_2 x 0 1 3 5 4 x 2 choose 3 possible a_3 x 0 1 2 5 4 x 3 choose 4 possible a_4 x 0 1 2 3 4 x 5 calculate minimum number operation perform sorted report impossible
1graph
Gildong interesting machine array n integer the machine support kind operation increase element suffix array 1 Decrease element suffix array 1 a suffix subsegment contiguous element array contain a_n in word a_i include subsegment a_js lt j le n include subsegmentGildong want element equal minimum number operation necessary to life easy Gildong start machine option change integer array integer you allow leave array unchanged you want minimize number operation Gildong perform with help minimum number operation Gildong performnote change integer array count operation Gildong perform
1graph
Utkarsh force play ashishs game the game progress turn turn usual Ashish move firstconsider 2d plane there token initially 00 in player increase x coordinate y coordinate token exactly k in player ensure token stay Euclidean distance d 00in word coordinate token pq p2 q2 leq d2 holdThe game end player unable it show game end finite number move if player play optimally determine win
0array
to help contestant struggle lot contest headquarters Codeforces planning introduce division 5 in new division tag problem announce prior round help contestantsThe contest consist n problem tag ith problem denote integer a_iYou want AK solve problem to solve problem order to contest funny create extra limitation you want solve problem consecutively tag bore also afraid big jump difficulty solve want minimize number time solve problem consecutively adjacent contest orderformally solve order describe permutation p length n the cost permutation define number index 1le p_i1p_i1 you requirement a_p_ine a_p_i1 1le nYou want know minimum possible cost permutation satisfie requirement if permutation meet requirement report
2string
a string b subsequence string b obtain deletion possibly zero character for example xy subsequence xzyw xy yxYou give stre your task reorder character trygub subsequence result stringin word find string b permutation symbol string trygub subsequence bWe truly marvelous proof string arrange contain trygub subsequence problem statement short contain
1graph
you give integer k n distinct point integer coordinate Euclidean plane ith point coordinate x_i y_iconsider list fracnn 12 pair point x_i y_i x_j y_j 1 le j le n for pair write distance line point origin 0 0your goal calculate kth small number distance
1graph
this easy version problem the difference version constraint array element you hack version problem solvedyou give array a_1 a_2 dot a_n your goal find length long subarray array frequent value unique in word look subarray frequent value occur f time subarray 2 different value occur exactly f timesan array c subarray array d c obtain d deletion possibly zero element begin possibly zero element end
2string
for give sequence distinct nonnegative integer b_1 b_2 dot b_k determine good follow way consider graph k node number b_1 b_k write for 1 k find j 1 le j le k jneq b_i oplus b_j small j oplus denote operation bitwise XOR httpsenwikipediaorgwikiBitwise_operationXOR next draw undirected edge vertex number b_i b_j graph we sequence good result graph form tree connect do not simple cycle it possible number b_i b_j try add edge twice nevertheless add edge onceyou find example picture correspond test case Sequence 0 1 5 2 6 good reach 1 5however sequence 0 1 5 2 good you give sequence a_1 a_2 dots a_n distinct nonnegative integer you like remove element possibly remain sequence good what minimum possible number removal require achieve goalIt show sequence remove number element leave 2 remain sequence good
1graph
you give array b consist n positive integer integer x please determine rearrange element b a_i b_i leq x hold 1 le le n
1graph
oleg favorite subject History Math favorite branch mathematic divisionTo improve division skill Oleg come t pair integer p_i q_i pair decide find great integer x_i p_i divisible x_i x_i divisible q_i Oleg good division manage find answer quickly
2string
petya prepare birthday he decide n different dish dinner table number 1 n since Petya do not like cook want order dish restaurantsunfortunately dish prepare different restaurant Petya need pick order n different place to speed process want order courier delivery restaurant thus dish option Petya dish deliver courier restaurant case courier arrive a_i minute Petya go restaurant pick dish spend b_i minute each restaurant courier start deliver order moment Petya leave house in word courier work parallel Petya visit restaurant choose delivery consistentlyfor example Petya want order n 4 dish 3 7 4 5 b 2 1 2 4 order delivery fourth restaurant second then courier restaurant bring order 3 minute courier fourth restaurant bring order 5 minute Petya pick remain dish 1 2 3 minute thus 5 minute dish Petyas housefind minimum time dish Petyas home
1graph
you give tree vertex colour white black grey you remove element tree select subset vertex single connect component remove adjacent edge graph the restriction allow select subset contain white black vertex oncewhat minimum number removal necessary remove vertex tree
2string
you give direct graph n vertex m edge Vertices number 1 n there token vertex 1the follow action allow Token movement to token vertex u vertex v edge u v graph this action take 1 second Graph transposition to transpose edge graph replace edge u v edge v u this action take increasingly time kth transposition take 2k1 second ie transposition take 1 second second take 2 second take 4 second the goal token vertex 1 vertex n short possible time Print time modulo 998244353
1graph
you give array n positive integersyou use follow operation time like select integer 1 le k le n thing decrement k element array decrement k element array for example n5 a32214 apply follow operation possible option list decrement element array after operation a2 1 2 1 4 decrement element array after operation a3 2 1 0 3 decrement element array after operation a2 1 1 0 3 determine possible element array equal zero apply certain number operation
1graph
this hard version problem the difference version number possible operation you hack solve version problemyou give binary table size n time m this table consist symbol 0 1you operation select 3 different cell belong 2 time 2 square change symbol cell change 0 1 1 0your task symbol table equal 0 you allow nm operation you do not need minimize number operationsIt prove possible
1graph
Yurii sure can solve task thoughhe array consist n positive integer Lets subarray alr good follow condition simultaneously satisfy l1 leq r1 ie subarray length 3 a_l oplus a_r a_l1a_l2ldotsa_r2a_r1 oplus denote bitwise XOR operation in word subarray good bitwise XOR border element equal sum rest element Yurii wants calculate total number good subarray what equal toan array c subarray array d c obtain d deletion possibly zero element begin possibly zero element end
2string
artem build new robot he matrix consist n row m column the cell locate ith row jth column leave value a_ij write if adjacent cell contain value robot break a matrix call good adjacent cell contain value cell call adjacent share Artem want increment value cell goodMore formally find good matrix b satisfie follow condition for valid ij b_ij a_ij b_ij a_ij1 for constraint problem show matrix b exist if table output please note minimize number increment
2string
monocarp tree consist n vertex root vertex 1 he decide study BFS Breadthfirst search run BFS tree start root BFS describe follow pseudocodea order vertice processedq Queueqput1 place root end queuewhile qempty k qpop retrieve vertex queue aappendk append k end sequence vertex visit y gk gk list child vertex k sorted ascending order qputyMonocarp fascinated BFS end lose tree fortunately sequence vertex order vertex visit BFS algorithm array pseudocode Monocarp know vertex visit exactly take queue exactly also know child vertex view ascending ordermonocarp know tree general case visit order do not hope restore tree Monocarp okay tree minimum heightthe height tree maximum depth tree vertex depth vertex number edge path root for example depth vertex 1 0 root depth root child 1help Monocarp find tree give visit order minimum height
1graph
you mayor Berlyatov there n district m twoway road the ith road connect district x_i y_i the cost travel road w_i there path pair district city connectedThere k delivery route Berlyatov the ith route go district a_i district b_i there courier route courier choose cheap minimum total cost path district a_i district b_i deliver productsthe route district courier route coincide count independentlyyou road cost zero ie choose road change cost 0let dx y cheap cost travel district x yyour task find minimum total courier route cost achieve optimally select road change cost 0 in word find minimum possible value sumlimits_i 1k da_i b_i apply operation describe optimally
1graph
there bookshelf fit n book the ith position bookshelf a_i 1 book position a_i 0 it guarantee book bookshelfIn choose contiguous segment l r consist book ie l r condition a_i 1 hold shift right 1 book index 1 l le le r this r1 le n book position r1 Shift leave 1 book index i1 l le le r this l1 ge 1 book position l1 your task find minimum number move require collect book shelf contiguous consecutive segment ie segment gapsfor example 0 0 1 0 1 gap book a_4 0 a_3 1 a_5 1 1 1 0 gap book 0 00 gap booksyou answer t independent test case
1graph
there build consist 10000 apartment number 1 10000 inclusiveCall apartment boring number consist digit Examples boring apartment 11 2 777 9999 onOur character troublemaker call intercom boring apartment till answer follow order First call apartment consist digit 1 increase order 1 11 111 1111 Next call apartment consist digit 2 increase order 2 22 222 2222 and the resident boring apartment x answer character stop call furtherour character wants know digit press total task help count total number keypressesfor example resident boring apartment 22 answer character call apartment number 1 11 111 1111 2 22 total number digit press 1 2 3 4 1 2 13you answer t independent test case
1graph
you string s consist n character each character 0 1you perform operation string each operation consist step select integer 1 length string s delete character s_i string length gets reduce 1 index character right delete reduce 1 string s delete maximum length prefix consist character indice remain character string length reduce length delete prefix Note step mandatory operation order changedFor example string s 111010 operation follow select 1 111010 rightarrow 11010 rightarrow 010 select 2 111010 rightarrow 11010 rightarrow 010 select 3 111010 rightarrow 11010 rightarrow 010 select 4 111010 rightarrow 11110 rightarrow 0 select 5 111010 rightarrow 11100 rightarrow 00 select 6 111010 rightarrow 11101 rightarrow 01 you finish perform operation string s what maximum number operation perform
1graph
wabbit try box contain food rest zoo coordinate plane point x_1y_1 point x_2y_2He rope use pull box he pull box stand exactly 1 unit away box direction coordinate axis he pull box standing move way direction 1 unit for example box point 12 wabbit standing point 22 pull box right 1 unit box end point 22 wabbit end point 32also wabbit 1 unit right leave pull box in case necessary exactly 1 unit away box if want pull box return point box also Wabbit can not point box locatedwabbit start point it take 1 second travel 1 unit right leave regardless pull box movingDetermine minimum time need box x_1y_1 x_2y_2 note point wabbit end matter
0array
you like play chess tournament onlineIn tournament play n game for sake problem chess game won lose draw when lose game 0 point when win 1 2 point win previous game 2 point 1 point if win game tournament 1 point previous gameThe outcome n game represent string s length n ith character s W win ith game L lose ith gameAfter tournament notice bug website allow change outcome k game mean k time change symbol L W W L since goal improve chess rating decide cheat use bugcompute maximum score cheat optimal way
2string
Masha n type tile size 2 time 2 each cell tile contain integer Masha infinite number tile typeMasha decide construct square size m time m consist give tile this square symmetric respect main diagonal matrix cell square cover exactly tile cell side tile parallel side square all place tile intersect also tile lie inside square see picture Notes section well understandingsymmetric respect main diagonal matrix square s pair j condition sij sji hold Ie true element write irow jth column equal element write jth row ith columnYour task determine Masha construct square size m time m symmetric matrix consist tile Masha use number tile type construct square Note rotate tile place orientation inputyou answer t independent test case
1graph
Chaneka hobby play animal toy every toy different fun value real number Chaneka box store toy specification the box store toy fun value range infty1 the second box store toy fun value range 1 0 the box store toy fun value range 0 1 the fourth box store toy fun value range 1 infty Chaneka A b c d toy second fourth box respectively one day decide want toy super toy so begin create super toy sewing toy haswhile number toy Chaneka 1 take different toy randomly sew create new toy the fun value new toy equal multiplication fun value sew toy she put new toy appropriate box she repeat process toy this toy super toy box stores toy special boxAs observer know number toys box initially know fun value you do not sequence Chanekas sewing Determine box special box Chaneka find super toy
1graph
Mr Chanek the Ninja day task mission handle mad snake attack site now Mr Chanek arrive hill destination right hill the mission area divide grid size 1000 time 1000 square there n mad snake site ith mad snake locate square x_i Y_i danger level b_imr Chanek going use Shadow Clone Jutsu Rasengan learn Lord Seventh complete mission his attack strategy follow Mr Chanek go M clone each clone choose mad snake attack target each clone pick different mad snake attack all clone jump hills attack respective choose target Rasengan radius r if mad snake square X Y attack direct Rasengan mad snake square X Y maxX X Y Y le R die the real Mr Chanek calculate score attack the score define square sum danger level kill snake now Mr Chanek curious sum score possible attack strategy because number huge Mr Chanek need output modulo 109 7
2string
Mr Chanek win national chess tournament get huge chessboard size n time M Bored play conventional chess Mr Chanek define function FX Y denote minimum number move knight square 1 1 square x Y it turn find FX Y simple Mr Chanek definesGX Y sum_ixn sum_jYM Fi jGiven X Y task find GX YA knight square b square b 0 b b 0 b b 3 of course knight leave chessboard
1graph
during space mission human find evidence previous life planet they lucky find book birth death year individual live planet what s interesting year range 1 109 therefore planet name LongliferIn order learn Longlifers previous population scientist need determine year maximum number individual alive number alive individual year your task help scientist solve problem
1graph
the Bubble Cup hypothesis stand unsolved 130 year who prove hypothesis regard great mathematician time a famous mathematician Jerry Mao manage reduce hypothesis problemgiven number m polynomial p coefficient set 01234567 p2mhelp Jerry Mao solve long standing problem
2string
in Bubbleland group special programming force get secret job calculate number potentially infect people new unknown virus the state population n people day new information new contact people the job special programming force calculate contact k day give person the new virus incubation period k day time people consider noninfectious because new virus extremely dangerous government mark suspicious everybody direct indirect contact k day independently order contactsthis virus strange people can not durable immunityyou need help special programming force calculate number suspicious people give person number people contact give personThere 3 give input beginning n n population q number query k virus incubation time day each query type x y person x person y meet day x neq y z return number people contact z counting the end current day move day
1graph
Mark crew sail sea Aeolus Greek mythology Aeolus keeper wind they map represent NxM matrix land sea field want port port consider sea field they hurry wind strong changeable food K days sea maximum carry ship John guy Marks crew know predict direction wind daily basis W day time reach port run food Mark ship direction north east south west field day stay place Wind blow direction north east south west blow day the wind strong sea Aeolus move ship field direction blow the ship result movement sum ship action wind day Mark careful order ship sea result movement end sea field 4connected path sea start field a 4connected path path cell share sidefor example follow image ship can not port 4connected path sea in image ship port 4connected path sea show red arrow Furthermore ship port follow happen wind blow east Mark move ship north wind blow north Mark move ship east in scenario ship end port Mark ship map do not know outside Lucky Mark crew t fish shop sea replenish food supply maximum shop work day that mean Mark crew shop position exact work day order replenish food supply help Mark find minimum day crew need reach port print 1 impossible food supply
2string
the pandemic world shortage important resource toilet paper as well prepare nation crisis BubbleLand promise help world nation valuable resource to country send airplane country carry toilet paperIn BubbleLand N toilet paper factory n airport because take build road course legal issue factory send paper airport airport toilet paper factoryAlso road can not build airportfactory pair legal issue every possible road number d give number day take build roadyour job choose N factoryairport pair country start build road time take day complete
1graph
Yura own ordinary boring array length n you think boring Vladik do not agreein order Yuras array bore Vladik make q bore query each query consist integer x y before answer query bound l r query calculate l x bmod n 1 r y bmod n 1 answer previous query zero initially bmod remainder operation whenever l r swappedAfter Vladik compute l r query compute common multiple lcm segment l r initial array modulo 109 7 lcm multiset integer smallest positive integer divisible element multiset the obtain lcm answer queryhelp Vladik compute answer query
1graph
Lindsey Buckingham tell Stevie Nicks Go way Nicks sad want away quickly possible life 2D hexagonal worldconsider hexagonal tiling plane picture Nicks wish cell mark 0 0 certain cell give coordinate she hexagon neighbor want cost associate the cost depend direction travel go 0 0 1 1 exact cost go 2 1 1 0 the cost give input order c_1 c_2 c_3 c_4 c_5 c_6 picture Print small cost path origin coordinate 0 0 give cell
1graph
in order celebrate twice 5th anniversary Tzuyu Sana decide play gameTzuyu give Sana integer b important questIn order complete quest Sana output small possible value oplus x b oplus x give x oplus denote bitwise XOR operation
2string
Ori Sein overcome difficult challenge they finally light Shrouded Lantern find Gumon Seal key Forlorn Ruins when try open door ruin happenedOri surprise Sein give explanation quickly clever Gumon decide additional defence doorThere n lamp Spirit Trees light Sein know time turn ith lamp l_i r_i respectively to open door choose k lamp way moment time turn onWhile Sein decide k lamp pick Ori interested way pick k lamp door open it happen Sein wrong k lamp the answer large print modulo 998244353
2string
an agent call Cypher decrypting message contain composite number n all divisor n great 1 place circle Cypher choose initial order number circleIn Cypher choose adjacent number circle insert common multiple he time neededA message decrypt adjacent number coprime note constraint possible decrypt messageFind minimal number move Cypher decrypt message initial order number circle
1graph
you give array consist n integerseach position 1 le le n array lock unlock you value unlocked position rearrange order place unlocked position you allow remove value add new one rearrange value lock position you allow leave value order werefor example let 1 1 underline3 2 underline2 1 4 underline0 underline position lock you obtain follow array 1 1 underline3 2 underline2 1 4 underline0 4 1 underline3 2 underline2 1 1 underline0 1 1 underline3 2 underline2 1 4 underline0 1 2 underline3 1 underline2 4 1 underline0 let p sequence prefix sum array rearrangement so p_1 a_1 p_2 a_1 a_2 p_3 a_1 a_2 a_3 dots p_n a_1 a_2 dots a_nlet k maximum j 1 le j le n p_j 0 if j p_j 0 k 0your goal rearrange value way k minimum possibleoutput array rearrangement value k minimum possible if multiple answer print
1graph
one day BThero decide play array come follow problemyou give array consist n positive integer the array numerate 1 n you execute follow procedure exactly you create new array b consist 2n positive integer 1 le le n condition b_2i1b_2i a_i hold for example array 6 8 2 create b 2 4 4 4 1 1 you merge consecutive equal number b for example b 2 4 4 4 1 1 b 2 4 1 find print minimum possible value b size b achieve end procedure it show give constraint way construct b
1graph
you give undirected graph consist n vertex m edge initially single integer write vertex vertex p_i write all p_i distinct integer 1 nyou process q query type 1 v vertex reachable vertex v edge graph include vertex v find vertex u large number p_u write print p_u replace p_u 0 2 delete ith edge graph Note query type possible vertex reachable v 0 write in case u explicitly define selection u affect choose vertex reachable v print value 0
1graph
all technique ninja world consist hand seal at moment Naruto learn new technique consist ncdot m different seal denote distinct number all write ntime m tablethe table lose Naruto manage remember element row leave right element column do not remember order row column please restore table consistent datum Naruto able learn new technique
1graph
we secret array you do not know array restore however know fact array the array consist n distinct positive great 0 integer the array contain element x y element know x y if sort array increase order a_1 a_2 ldot a_n difference adjacent consecutive element equal ie a_2 a_1 a_3 a_2 ldot a_n a_n1 it prove array exist constraint give belowamong possible array satisfy give condition ask restore minimum possible maximum element in word minimize maxa_1 a_2 dot a_nyou answer t independent test case
0array
you give m set integer a_1 a_2 ldot a_m element set integer 1 n inclusivethere array positive integer a_1 a_2 ldot a_m b_1 b_2 ldot b_n in operation delete element j set A_i pay a_i b_j coin thatyou maybe operation set emptyafter edgecolore undirected graph consist n vertex for set a_i add edge x y color x y A_i x y some pair vertice connect edge edge different colorsyou cycle i_1 e_1 i_2 e_2 ldot i_k e_k i_1 e_j edge connect vertex i_j i_j1 graph rainbow edge different colorsfind minimum number coin pay graph rainbow cycle
2string
there n beautiful skyscraper New York height ith h_i today villain set fire n 1 safety build nth skyscraperLets jump ith skyscraper jth j discrete skyscraper strictly lower high Formally jump discrete j follow condition satisfy 1 j maxh_i 1 ldot h_j 1 minh_i h_j maxh_i h_j minh_i 1 ldot h_j 1 at moment Vasya staying skyscraper want live little long goal reach nth skyscraper minimal count discrete jump help calcualte number
1graph
alexandra evenlength array consist 0s 1s the element array enumerate 1 n she want remove fracn2 element n length array way alternate sum array equal 0 ie a_1 a_2 a_3 a_4 dotsc 0 in word Alexandra want sum element odd position sum element position equal the element remove do not consecutivefor example 1 0 1 0 0 0 remove 2nd 4th element equal 1 1 0 0 alternate sum 1 1 0 0 0help
1graph
fishing Prince love tree especially love tree centroid the tree connect graph cyclesA vertex centroid tree cut vertex remove remove edge vertex size large connect component remain graph small possiblefor example centroid follow tree 2 cut size large connect component remain graph 2 can not small however tree centroid example both vertex 1 vertex 2 centroid size large connect component 3 cutting themnow fishing Prince tree he cut edge tree mean remove edge after add edge the result graph operation tree he add edge cuthe want centroid result tree unique help find possible way operation it prove way exist
2string
you give array integer a_1a_2ldotsa_n find maximum possible value a_ia_ja_ka_la_t indice j k l t ijklt
1graph
a brick define rectangle integer length width 1 height 1 bothThere ntime m grid cell color black white a tiling way place brick grid black cell cover exactly brick white cell cover brick in word brick place black cell cover black cell brick overlap an example tiling test case 5 brick it possible well 4 brick what minimum number brick require valid tiling
1graph
the mythic world Chess Land rectangular grid square r row c column r great equal c its row column number 1 r 1 c respectively the inhabitant Chess Land usually mention piece everyday language 5 specific type roam land pawn rooks bishop queen king contrary popular belief chivalry long dead Chess Land knight foundEach piece unique way move square square step pawn row forward ie row r r1 change column rook number column leftright change row or number row forwardbackward change column bishop square diagonal intersect currently occupy square queen square rook bishop position king 8 adjacent square in follow figure mark X square piece single step row number column leave right recently Chess Land dangerous place piece pass land capture unexpectedly unknown force simply disappear as consequence like reach destination fast ie move possible interested number different way possible reach minimal number step path available mean low chance getting capture two path consider different differ visit squarefor problem let assume piece enter Chess Land give column row 1 exit land give column row r your task answer Q question give type piece column enter row 1 column reach row r order exit compute minimal number move Chess Land number different way able
2string
once time Land Shamans live SkyHigh Beanstalk each shaman unique identify number 0 n1 altitude valueH_i represent high live ground level the distance altitude absolute value differenceAll shamans live peace steal formula worldfamous PotionofGreatPower to cover hisher track Thief Curse land inhabitant long trust otherDespite difficult circumstance order Good Investigators gain follow information Curse when Curse take effect stop trust the Curse unstable end day exactly midnight pair shaman start stop trust unfortunately shaman trust d give time they reconstruct log trust night know pair shaman startedstoppe trust otherthey believe thief whisper formula evil Shaman to avoid detection visit home respective trust friend during visit thief whisper formula evil Shaman window Note trust friend home time in fact possible visit house shaman weirdfortunately whisper travel short distance Order know trusted friend visit Thief Evil Shaman live close otherthey ask help investigation they like test suspicion Thief x evil Shaman y formula whisper day v what small distance whisper formula travel that minimum distance apartment shamans x y ie minleftleftH_x h_yrightright x trust friend x y trust friend y dayvthey share information ask number question you need answer question immediately receive
1graph
you give array length 2n you process q query each query follow 4 type Replacex k change a_x k Reversek reverse subarray i1 cdot 2k1 cdot 2k ge 1 Swapk swap subarray 2i2 cdot 2k1 2i1 cdot 2k 2i1 cdot 2k1 2i cdot 2k ge 1 Suml r print sum element subarray l r Write program quickly process give query
2string
you give tree consist n node you label n1 edge integer way satisfie follow condition integer great 0 product n1 number equal k number 1s n1 integer minimum possible Lets define fuv sum number simple path node u node v also let sumlimits_i1n1 sumlimits_ji1n fij distribution index treefind maximum possible distribution index since answer large print modulo 109 7In problem number k large result prime factorization k give instead
1graph
you give sequence a_1 a_2 dot a_n b_1 b_2 dot b_n each element sequence 0 1 2 the number element 0 1 2 sequence x_1 y_1 z_1 respectively number element 0 1 2 sequence b x_2 y_2 z_2 respectivelyyou rearrange element sequence b like after let define sequence c followsc_i begincase a_i b_i mboxif a_i b_i 0 mboxif a_i b_i a_i b_i mboxif a_i b_i endcasesyoud like sum_i1n c_i sum element sequence c large possible what maximum possible sum
1graph
you play RPG 2010s you planning raise smithe skill need resource possible so resource by steal courseyou decide rob town blacksmith follower you carry p unit follower f unitsIn blacksmith shop find cnt_s sword cnt_w war axis each sword weight s unit war axe w unit you do not care melt steel ingotwhat maximum number weapon sword war axis follower carry shop
1graph
easy hard version actually different problem advise read statement carefullyYou give weight rooted tree vertex 1 root tree also edge costA tree connect graph cycle a rooted tree special vertex call root a parent vertex v different v vertex path root vertex v Children vertex v vertex v parent a vertex leaf child the weight tree tree edge tree weightThe weight path sum edge weight path the weight path vertex 0you sequence zero move on select edge divide weight 2 round more formally choose edge divide weight 2 round w_i leftlfloorfracw_i2rightrfloorEach edge associated cost c_i 1 2 coin each edge cost c_i coinsyour task find minimum total cost sum weight path root leaf s in word wi j weight path vertex vertex j sumlimits_v leave wroot v le S leave list leavesyou answer t independent test case
2string
you give binary string s consist n zero onesYour task divide give stre minimum number subsequence way character string belong exactly subsequence subsequence look like 010101 101010 ie subsequence contain adjacent zero onesRecall subsequence sequence derive give sequence delete zero element change order remain element for example subsequence 1011101 0 1 11111 0111 101 1001 000 101010 11100you answer t independent test case
2string
polycarp play computer game in game fight monster magic spellsthere type spell fire spell power x deal x damage monster lightning spell power y deal y damage monster double damage spell Polycarp cast each spell cast battle Polycarp cast orderfor example suppose Polycarp know spell fire spell power 5 lightning spell power 1 lightning spell power 8 there 6 way choose order cast spell second this order deal 5 1 2 cdot 8 22 damage second this order deal 5 8 2 cdot 1 15 damage second this order deal 1 2 cdot 5 8 19 damage second this order deal 1 2 cdot 8 2 cdot 5 27 damage second this order deal 8 2 cdot 5 1 19 damage second this order deal 8 2 cdot 1 2 cdot 5 20 damage Initially Polycarp know 0 spell his spell set change n time time learn new spell forget know after change calculate maximum possible damage polycarp deal spell know
1graph
you give array n integersyou want element equal zero follow operation exactly time select segment number segment add multiple len len length segment add integer different it prove possible element equal zero
1graph
since Boboniu finish build Jianghu Kungfu mountain day Boboniu design map n mountain he use n1 road connect n mountain every pair mountain connect roadsFor ith mountain Boboniu estimate tiredness Kungfu t_i he estimate height mountain h_iA path sequence mountain M 1 le M exist road m_i m_i1 Boboniu regard path challenge 1le iM h_m_ile h_m_i1boboniu want divide n1 road challenge note road appear exactly challenge mountain appear challenge Boboniu want minimize total tiredness challenge the tiredness challenge M sum tiredness mountain ie sum_i1Mt_M_i he ask find minimum total tiredness as reward work you ll guardian Jianghu
1graph
Boboniu define bnstring string s character B NYou perform follow operation BNstring s Remove character s remove substre BN NB s add character B n end s add string BN NB end s note string substre string b obtain b deletion possibly zero character begin possibly zero character endboboniu think BNstrings s t similar st there exist permutation p_1 p_2 ldot p_s 1le ile s s_p_it_i Boboniu define textdistst distance s t minimum number operation make s similar tNow Boboniu give n nonempty BNstrings s_1s_2ldot s_n ask find nonempty BNstring t maximum distance string s minimized ie need minimize max_i1n textdists_it
1graph
Omkar play favorite pixelated video game Bed Wars in Bed Wars n player arrange circle j 2 leq j leq n player j 1 leave player j player j right player j 1 additionally player n leave player 1 player 1 right player nCurrently player attack player leave player right this mean player currently attack 0 1 2 player a key element Bed Wars strategy player attack exactly 1 player logically attack player response if instead player attack 0 2 player Bed Wars strategy say player logically attack adjacent playersunfortunately player game follow Bed Wars strategy correctly Omkar aware player currently attack talk n player game instead attack player e currently attack player leave Omkar convince instead attack player right currently attack player right Omkar convince instead attack player leave Omkar like player act logically calculate minimum player Omkar need talk player talk changed player attack player act logically accord Bed Wars strategy
1graph
you give list segment al_1 ar_1 al_2 ar_2 dot al_n ar_n bl_1 br_1 bl_2 br_2 dot bl_n br_ninitially segment al_i ar_i equal l_1 r_1 segment bl_i br_i equal l_2 r_2in step choose segment second list extend 1 in word suppose you ve choose segment x y transform x 1 y x y 1lets define total intersection I sum length intersection correspond pair segment ie sumlimits_i1ntextintersection_lengthal_i ar_i bl_i br_i empty intersection length 0 length segment x y equal y xWhat minimum number step need I greater equal k
0array
Captain Flint crew head savage shore Byteland month drink rum tell story in moment uncle Bogdan remember nephew Denis Today tell story Denis helped come interesting problem ask crew solve itIn beginning uncle Bogdan write board positive integer x consist n digit after wipe x write integer k instead concatenation binary representation digit x consist lead zero for example let x 729 k 111101001 7 111 2 10 9 1001after time uncle Bogdan understand do not know k ask Denis help Denis decide wipe n digits k name new number ras result Denis propose find integer x length n r number maximum possible if multiple valid x deni interested minimum oneall crew member include captain Flint easily solve task all cabin boy Kostya drunk think straight but younote task compare integer x k number despite representation write 729 1999 111 1000
2string
Joker return Gotham City execute evil plan in Gotham City N street junction number 1 N M street number 1 M each street connect distinct junction junction connect streetfor evil plan Joker need use odd number street form cycle that junction S positive integer k sequence junction S s_1 ldot s_k S street connect S s_1 b s_k s c s_i1 s_i 2 ldot kHowever police control street Gotham City on day monitor different subset street consecutive number j l_i leq j leq r_i these monitored street joker plan course unfortunately police Joker spy Gotham City Police Department tell street monitor day Now Joker wants find give number day execute evil plan on day cycle street consist odd number street monitor day
1graph
you give table size 2 time n ie row n column consist integer 1 nin choose column j 1 le j le n swap value a_1 j a_2 j each column choose onceyour task find minimum number move require obtain permutation size n second row table determine impossible thatyou answer t independent test casesrecall permutation size n array size n contain integer 1 n exactly order element do not matter
1graph
you give string s1 dot n consist lowercase latin letter it guarantee n 2k integer k ge 0The string s1 dot n call cgood follow condition satisfy the length s 1 consist character c ie s_1c the length s great 1 half string consist character c ie s_1s_2dotss_fracn2c second half string ie string s_fracn2 1s_fracn2 2 dot s_n c1good stre the length s great 1 second half string consist character c ie s_fracn2 1s_fracn2 2dotss_nc half stre ie string s_1s_2 dot s_fracn2 c1good string for example aabc agood ffgheeee egoodIn choose index 1 n replace s_i lowercase latin letter character zYour task find minimum number move require obtain agood string s ie cgood string c it guarantee answer existsyou answer t independent test casesanother example agood string follow consider string s cdbbaaaa it agood string second half string aaaa consist character half string cdbb bgood string second half string bb consist character b half string cd cgood string half string c consist character c second half string d dgood string
2string
you give array consist n integer you find length small short prefix element need erase good array Recall prefix array aa_1 a_2 dot a_n subarray consist element prefix array length k array a_1 a_2 dots a_k 0 le k le nThe array b length m call good obtain nondecrease array c c_1 le c_2 le dots le c_m repeat follow operation m time initially c select element b remove b append end array c for example 4 operation b_1 b_m b_m1 b_2 b b_3 b_4 dot b_m3 c b_1 b_m b_m1 b_2consider follow example b 1 2 3 4 4 2 1 this array good obtain nondecrease array c follow sequence operation element b b 2 3 4 4 2 1 c 1 element b b 2 3 4 4 2 c 1 1 element b b 2 3 4 4 c 1 1 2 element b b 3 4 4 c 1 1 2 2 element b b 4 4 c 1 1 2 2 3 element b b 4 c 1 1 2 2 3 4 element b b c 1 1 2 2 3 4 4 c nondecrease note array consist element goodPrint length short prefix delete erase good array note require length 0you answer t independent test case
1graph
the difference easy hard version constraint in version constraint low you hack version problem solvedKoa Koala beachThe beach consist leave right shore n1 meter sea island n1 meter shoreshe measure depth sea 1 2 dot n meter shore save array d d_i denote depth sea meter shore 1 le le nLike beach tide intensity tide measure parameter k affect depth begin time t0 follow way for total k second second tide increase depth 1 then total k second second tide decrease depth 1 this process repeat ie depth increase k second decrease k second Formally let define 0indexed array p 0 1 2 ldot k 2 k 1 k k 1 k 2 ldot 2 1 length 2k at time t 0 le t depth meter shore equal d_i pt bmod 2k t bmod 2k denote remainder division t 2k note change occur instantaneously second note well understanding at time t0 Koa standing shore want island suppose time t 0 le t x 0 le x le n meter shore in second Koa swim 1 meter shore x change x1 swim x stay case t change t1 as Koa bad swimmer depth sea point can not exceed l integer point time drown more formally Koa x 1 le x le n meter shore moment t integer tge 0 depth sea point d_x pt bmod 2k can not exceed l in word d_x pt bmod 2k le l hold once Koa reach island n1 meter shore stop restnote Koa swim tide do not effect ie can not drown swimming Note Koa choose stay shore long need shore island affect tide solid ground will not drown Koa wants know shore island help
1graph
note difference String Transformation 1 String Transformation 2 Koa in version letter y Koa select letter 20 lowercase letter english alphabet read statement well understand you hack problem independentlykoa Koala string A b length n ABn consist 20 lowercase english alphabet letter ie tin Koa select subset position p_1 p_2 ldot p_k k ge 1 1 le p_i le n p_i neq p_j neq j a a_p_1 a_p_2 ldots A_p_k x ie letter position equal letter x select letter y 20 lowercase letter english alphabet set letter position p_1 p_2 ldot p_k letter y more formally 1 le le k Koa set A_p_i y Note modify letter stre AKoa want know small number move string equal A b determine way equal help
2string
note difference String Transformation 1 String Transformation 2 Koa in version letter y Koa select strictly great alphabetically x read statement well understand you hack problem independentlykoa Koala string A b length n ABn consist 20 lowercase english alphabet letter ie tin Koa select subset position p_1 p_2 ldot p_k k ge 1 1 le p_i le n p_i neq p_j neq j a a_p_1 a_p_2 ldots A_p_k x ie letter position equal letter x select letter y 20 lowercase letter English alphabet yx ie letter y strictly great alphabetically x set letter position p_1 p_2 ldot p_k letter y more formally 1 le le k Koa set A_p_i y Note modify letter stre AKoa want know small number move string equal A b determine way equal help
1graph
there undirecte tree n vertex connect n1 bidirectional edge there snake stick inside tree its head vertex tail vertex b the snake body occupy vertex unique simple path bthe snake want know reverse head tail start tail head start unfortunately snake movement restrict tree structureIn operation snake head adjacent vertex currently occupy snake when tail move vertex close head length snake remain unchanged similarly snake tail adjacent vertex currently occupy snake when head move unit close tail Lets denote snake position ht h index vertex snake head t index vertex snake tail this snake reverse movement 47to 51to 42to 1 3to 72to 81to 74 Determine possible reverse snake sequence operation
2string
let b array length n m respectively element common we define new array mathrmmergeab length nm recursively follow if array result array that mathrmmergeemptysetbb mathrmmergeaemptyseta in particular mathrmmergeemptysetemptysetemptyset if array nonempty a_1b_1 mathrmmergeaba_1mathrmmergea_2ldotsa_nb that delete element a_1 merge remain array add a_1 begin result if array nonempty a_1b_1 mathrmmergeabb_1mathrmmergeab_2ldotsb_m that delete element b_1 b merge remain array add b_1 beginning result this algorithm nice property b sorted mathrmmergeab sort for example subroutine mergesort for problem consider procedure acting nonsorted array for example a31 b24 mathrmmergeab2314a permutation array consist n distinct integer 1 n arbitrary order for example 23154 permutation 122 permutation 2 appear twice array 134 permutation n3 4 arrayThere permutation p length 2n Determine exist array b length n element common pmathrmmergeab
1graph
this easy version problem the difference version constraint n require number operation you hack version problem solvedThere binary string b length n binary string string consist symbol 0 1 in operation select prefix simultaneously invert bits prefix 0 change 1 1 change 0 reverse order bit prefixfor example a001011 select prefix length 3 011011 then select entire string 001001your task transform string b 3n operation it prove possible
1graph
you give permutation p_1 p_2 dot p_n Recall sequence n integer call permutation contain integer 1 n exactly onceFind indice j k 1 le j k le n p_i p_j p_j p_k or index
1graph
Ivan fond genealogy currently study particular genealogical structure consist people in structure person parent specify Additionally person exactly child special person child the people structure conveniently number 1 n s_i denote child person s_i 0 exactly person childrenWe ancestor b b child ancestor b that ancestor s_a s_s_a etcWe person imbalance case person parent specify total number ancestor parent double Ivan count number imbalance people structure get k people total however sure compute correctly like check construction n people k imbalanced people total please help find construction determine exist
2string
vladimir like prepare present wife anniversary he decide buy exactly n flowersVladimir go flower shop amazed m type flower sell unlimited supply flower type Vladimir want choose flower maximize happiness wife he know receive flower ith type happiness wife increase a_i receive consecutive flower type happiness increase b_i that choose flower x_i 0 flower type wife get a_i x_i 1 cdot b_i additional happiness flower type get particular typeplease help Vladimir choose exactly n flower maximize total happiness wife
2string
this interactive problemAnton Harris playing game decide king problemsettingthere pile stone initially contain b c stone b c distinct positive integer on turn game follow sequence event take place the player choose positive integer y provide second player the second player add y stone pile condition choose pile consecutive turn the second player lose point pile contain number stone the player lose 1000 turn pass second player losingfeele confident skill Anton decide let Harris choose want second help Harris defeat Anton king problemsette
1graph
you give integer n in multiply n divide n 6 divisible 6 remainderyour task find minimum number move need obtain 1 n determine impossible thatyou answer t independent test case
1graph
you give array consist n integer index array start zero ie element a_0 second a_1 onyou reverse subarray continuous subsegment array Recall subarray border l r al r a_l a_l 1 dot a_ryour task reverse subarray sum element position result array maximize ie sum element a_0 a_2 dot a_2k integer k lfloorfracn12rfloor maximum possibleyou answer t independent test case
1graph
you give string s consist character you perform process stre this process describe follow pseudocode re 0for init 0 inf cur init ok true 1 s res re 1 si cur cur 1 cur cur 1 cur 0 ok false break ok breakNote inf denote infinity character string number 1 sYou calculate value res process end
1graph