question
stringlengths
58
4.29k
label
class label
3 classes
let define split n nonincrease sequence positive integer sum n for example follow sequence split 8 4 4 3 3 2 2 2 1 1 1 1 5 2 1the follow sequence are not split 8 1 7 5 4 11 3 1 1 4 1 1the weight split number element split equal element for example weight split 1 1 1 1 1 5 weight split 5 5 3 3 3 2 weight split 9 equal 1for give n find number different weight split
2string
a chip place field coordinate system point 00every second chip move randomly if chip currently point xy second move point x1y probability p1 point xy1 probability p2 point x1y probability p3 point xy1 probability p4 its guarantee p1p2p3p41 the move independentfind expect time chip away origin distance great r ie satisfy
1graph
you give integer b moreover give sequence s_0 s_1 dot s_n all value s integer 1 1 its know sequence kperiodic k divide n1 in word k leq leq n satisfy s_i s_i kFind nonnegative remainder division sum limits_i0n s_i bi 109 9note modulo unusual
1graph
you give positive integer n write lead zeroes example number 04 incorrect in operation delete digit give integer result remain positive integer lead zerosDetermine minimum number operation need consistently apply give integ n square positive integer report impossibleAn integer x square positive integer xy2 positive integer y
2string
polycarp create training plan prepare programming contest he train n day day number 1 n begin firstOn ith day Polycarp necessarily solve a_i problem one evening Polycarp plan celebrate equator he celebrate evening day begin training day inclusive solve half problemsdetermine index day Polycarp celebrate equator
1graph
you give n point cartesian plane every point lattice point ie coordinate integer point distinctyou draw straight line necessarily distinct Is possible way point lie line
2string
your friend Mishka attend calculus lecture Lecture last n minute Lecturer tell ai theorem ith minuteMishka interested calculus hard stay awake time lecture you give array t Mishkas behavior if Mishka asleep ith minute lecture ti equal 0 equal 1 when Mishka awake write theorems tell ai ith minute otherwise write nothingyou know secret technique Mishka awake k minute straight however use you start begin minute 1 nk1 if use minute Mishka awake minute j write theorems lecturer tellsyou task calculate maximum number theorem Mishka able write use technique wake
1graph
Santa infinite number candy m flavour you give rooted tree n vertex the root tree vertex 1 each vertex contain exactly candy the ith vertex candy flavour f_iSometimes Santa fear candy flavour k melt he choose vertex x randomly send subtree x baker replacement in replacement candy flavour k replace new candy flavour the candy flavour k leave unchanged after replacement tree restoredthe actual cost replace candy flavour k c_k give k the Baker keep price fix order calculation simple every time subtree come replacement Baker charge C matter subtree flavour issuppose give flavour k probability Santa choose vertex replacement vertex you need find expect value error calculate cost replacement flavour k the error calculate cost define follow Error Ek actual cost Price charge Bakers 2note actual cost cost replacement candy flavour k multiplied number candy subtreealso Santa wish replace candy vertex x candy flavour pocketyou need handle type operation change flavour candy vertex x w Calculate expect value error calculate cost replacement give flavour k
1graph
a string consist number lowercase english letter he give friend B append number letter b end string since A b like character b sure point b exist stringB give stre C append number letter c end string however c good friend A b number letter c append equal number number b string it possible number letter c equal number letter number letter b timeyou string hand want check possible obtain string way if possible obtain string print yes print no quote
1graph
Mahmoud array consist n integer he ask Ehab find array b length b lexicographically greater equal bi2 b pairwise coprime 1ijn bi bj coprime ie GCDbibj1 GCDwz great common divisor w z Ehab wants choose special array want lexicographically minimal array variant can find itan array x lexicographically great array y exist index xiyi xjyj 1ji an array x equal array y xiyi 1 in
2string
Mahmoud want send message friend Ehab their language consist n word number 1 n some word mean k group word word group meaningMahmoud know ith word send cost ai for word message Mahmoud replace word mean leave can help Mahmoud determine minimum cost send messagethe cost send message sum cost send word
2string
Princess Heidi decide order K Rebel ship commander person unfortunately currently travel hyperspace leave N specific moment t1t2tn the meeting commander start stop time Namely commander board ship time ti disembark later time tj of course Heidi need meet commander meeting hold time two commander meet beginningsending hyperspace jump ships position coordinate enemy your task find minimum time Princess Heidi spend meeting schedule satisfy condition
1graph
the stardate 1977 science art detect Death Stars infancy Princess Heidi receive information star nearby solar system Rebel spy help identify exact location Death Star need know information correct two rebel spy provide map solar system each map NN grid cell occupy star to information correct Heidi need know maps solar system possibly spy actually empire double agent feed false informationunfortunately spy accidentally rotate map 90 180 270 degree flip vertical horizontal axis deliver Heidi if Heidi rotate flip map identical map solar system Otherwise traitor Rebel rank help Heidi find
1graph
you re give q query form LR for query find number x LxR exist integer number a0 p1 xap
1graph
let stre adorable letter realign way form consequent group equal symbol note different group contain different symbol for example ababa adorable transform aaabb letter form group group bs cccc possible consequent partition letter group coincideyoure give string s check split nonempty subsequence string form subsequence adorable here subsequence arbitrary set index string
1graph
Bob farmer he large pasture sheep recently lose wolf attack he decide place shepherd dog way sheep protectedThe pasture rectangle consist RC cell each cell contain sheep wolf dog Sheep dog stay place wolf roam freely pasture repeatedly move leave right neighboring cell when wolf enter cell sheep consume however wolf enter cell doginitially dog Place dog pasture way wolf reach sheep determine impossible note dog need minimize number
0array
you give sequence consist n integer you partition sequence sequence b c way element belong exactly sequence let b sum element belong b c sum element belong c sequences sum 0 what maximum possible value BC
2string
we ve get test case a big olympiad come but problemsetter number priority add problem round the diameter multiset point line large distance point set for example diameter multiset 1321 2diamet multiset consist point 0you give n point line what minimum number point remove diameter multiset remain point exceed d
1graph
Valya Tolya ideal pair quarrel recently Valya take offense boyfriend come tshirt letter differ letter pullover now do not want tolya seating room cry photo day longthis story sad fairy godmother Tolyas grandmother decide help restore relationship she secretly take Tolyas tshirt Valyas pullover want lettering in order unit mana buy spell change letter clothe your task calculate minimum mana Tolyas grandmother spend rescue love Tolya ValyaMore formally lettering Tolyas tshirt Valyas pullover string length n consist lowercase english letter use unit mana grandmother buy spell form c1c2 c1 c2 lowercase English letter arbitrary number time transform single letter c1 c2 viseversa Tolyas tshirt Valyas pullover you find minimum mana grandmother spend buy set spell lettering equal in addition output require set spell
1graph
as know male plane female plane however plane Earth like plane there n plane Earth number 1 n plane number like plane number fi 1fin fiiWe love triangle situation plane a like plane b plane b like plane c plane c like plane a find love triangle earth
2string
you give undirected connect graph weight edge the length path vertice bitwise xor weight edge belong path edge traverse include bitwise xor number time there type query process 1 x y d add edge connect vertex x vertex y weight d it guarantee edge connect x y query 2 x y remove edge connect vertex x vertex y it guarantee edge graph graph stay connect query 3 x y calculate length short path possibly nonsimple vertex x vertex y Print answer query type 3
1graph
let denote mfree matrix binary consist 1s 0s matrix square submatrix size mm matrix contain zero consider follow problemyou give integer n m you construct mfree square matrix size nn number 1s matrix maximum possible Print maximum possible number 1s matrixyou do not solve problem instead construct test ityou give t number x1 x2 xt for find integer ni mi nimi answer aforementione problem exactly xi set nni mmi
1graph
welcome task break code lock Explorers Whitfield Martin come unusual safe inside accord rumor untold rich find solution problem discrete logarithmOf course code lock instal safe the lock screen display stre n lowercase latin letter Initially screen display stre s Whitfield Martin find safe open string t display screenthe string screen change operation shift x in order apply operation explorer choose integer x 0 n inclusive after current string pαβ change βrα length β x length α nx in word suffix length x string p reverse move begin string for example operation shift 4 string abcacb change string bcacab αab βcacb βRbcacExplorers afraid apply operation shift lock lock forever they ask find way stre t screen 6100 operation
1graph
Ancient Egyptians know understand difficult concept mathematic the ancient egyptian mathematician Ahmes like write kind arithmetic expression papyrus paper call Ahmes arithmetic expressionan Ahmes arithmetic expression define d ahme arithmetic expression d onedigit positive integer E1opE2 ahme arithmetic expression E1 E2 valid Ahmes arithmetic expression space op plus minus for example 5 11 1235 valid Ahmes arithmetic expressionson trip Egypt Fafa find piece papyrus paper have Ahmes arithmetic expression write Being ancient papyrus piece wear as result operator erase keep number bracket since Fafa love mathematic decide challenge follow taskgiven number plus minus operator original expression find maximum possible value expression papyrus paper putting plus minus operator place original erase operator
2string
Fifa Fafa share flat Fifa love video game wants download new soccer game unfortunately Fafa heavily use internet consume quota Fifa access internet WiFi access point this access point access range r meter range choose Fifa position Fifa access point inside flat circular shape radius r Fifa want minimize area cover access point inside flat let Fafa outside flat access internetthe world represent infinite 2D plane the flat centered x1y1 radius R Fafas laptop locate x2y2 necessarily inside flat Find position radius choose Fifa access point minimize uncover area
1graph
Fafa own company work huge project there n employee Fafas company whenever company new project start work Fafa divide task project employeesFafa find time tiring so decide choose good l employee company team leader whenever new project Fafa divide task team leader team leader responsible positive number employee task to process fair team leader responsible number employee moreover employee team leader responsibility exactly team leader team leader responsible team leadergiven number employee n find way Fafa choose number team leader l way possible divide employee evenly
1graph
a dragon symbolize wisdom power wealth on Lunar New Years Day people model dragon bamboo strip clothe raise rod hold rod high low resemble fly dragonA performer hold rod low represent 1 hold high represent 2 thus line performer represent sequence a1a2anlittle Tommy he like choose interval lr 1lrn reverse alal1ar length long nondecrease subsequence new sequence maximumA nondecrease subsequence sequence index p1p2pk p1p2pk ap1ap2apk the length subsequence k
1graph
you team n people for particular task pick nonempty subset people the cost have x people task xk output sum cost nonempty subset people
2string
for permutation P1 N integer 1 n function f define follow let gi minimum positive integer j fiji we j existsFor give NAB find permutation p integer 1 n 1in gi equal a b
2string
Arkady Kirill visit exhibition rare coin the coin locate row enumerate leave right 1 k coin lay obverse reverse uparkady Kirill photo coin photo contain segment neighboring coin Akrady interested obverse photo coin obverse on contrary Kirill interested reverse photo coin reverse upthe photo lose Arkady Kirill remember bound segment coin photo contain give information compute remainder division 1097 number way choose upper coin way Arkadys photo coin obverse Kirills photo coin reverse
1graph
there time recall good old friend you ve come luckily social network store message history make easy know argue 10 year agomore formal message history sequence message order time send number 1 n n total number message chateach message contain link early message reply when open message x get link dialogue show way k previous message message x k message visible respect message x in case k message showndigge deep message history read visible message link current message x continue read mannerdetermine number message you ll read start message number t t 1 n Calculate number independently if start message x initial configuration x k previous k message message read multiple time consider
1graph
Arkady decide buy rose girlfriendA flower shop white orange red rose total n Arkady think red rose good white rose will not buy bouquet contain red white rose also Arkady will not buy bouquet rose color Arkady want buy exactly k rose for rose shop know beauty color beauty ith rise bi color ci W white rise o orange rise r red rise Compute maximum possible total beauty bouquet k rose satisfy constraint determine possible bouquet
1graph
a flower shop get n bouquet ith bouquet consist ai flower Vasya manager shop decide large bouquet bouquet Vasya think bouquet large initial bouquet constraint total number flower large bouquet odd each initial bouquet large bouquet if initial bouquet large bouquet flower include large bouquetdetermine maximum possible number large bouquet Vasya
1graph
olya want buy custom wardrobe it n box height a1a2an stack order in word represent box vertical segment length ai segment form single segment 0 overlapssome box important case bi1 bi0 Olya define convenience wardrobe number important box edge locate height l r inclusiveyou give information height box importance Compute maximum possible convenience wardrobe reorder box arbitrarily
1graph
apart plush toy imp huge fan little yellow bird to summon bird imp need strong magic there n tree row alley park nest tree in ith nest ci bird summon bird nest imp need stay tree cost costi point mana however bird summon Imp increase mana capacity b point imp summon bird summon number 0 ci bird ith nest Initially Imp stand tree W point mana mana capacity equal W he forward time move tree restore x point mana can not exceed current mana capacity move forward maximum number bird imp summon
0array
let denote Lxp infinite sequence integer y gcdpy1 yx gcd great common divisor integer number sort ascending order the element Lxp 1indexed example 9 13 15 second element l722 respectivelyYou process t query each query denote integer x p k answer query kth element Lxp
2string
let Dx number positive divisor positive integer x for example D22 2 divisible 1 2 d64 6 divisible 1 2 3 6you give array n integer you process type query REPLACE l r replace ai Dai SUM l r calculate Print answer SUM query
1graph
recently n student city S move city p attend programming campthey move train in evening student train decide want drink tea of course people use teapot simultaneously student form queue teaith student come end queue beginning lith second if multiple student come queue moment student great index come student less index Students queue behave follow queue student use teapot exactly second leave queue tea student wait people tea if begin rith second student tea queue leave queue get tea for student determine second use teapot tea actually get
1graph
suppose campus class day day as hurry classroom surprisingly find seat occupy Today friend go class find seat occupiedthe classroom contain n row seat m seat row then classroom represent n times m matrix the character represent seat mean seat occupy you need find k consecutive seat row column arrange seat friend your task find number way arrange seat two way consider different set place student occupy differ
2string
we supermarket buy fruit vegetable tag print price kilo but supermarket ask item clerk yuan b kilo you do not need care yuan ab yuan kilonow imagine you d like buy m kilos apple you ve ask n supermarket get price find minimum cost applesyou assume apple supermarket
1graph
will share psychic connection Upside Down Monster monster know will know suddenly start draw page page nonstop Joyce mom Chief Hopper drawing realize labeled tree a tree connect acyclic graph Wills tree n vertice Joyce Hopper do not know mean they re investigate tree similar tree for k 0kn1 they re go investigate label tree n vertex share exactly k edge will tree two label tree different there s pair vertex vu there s edge v u tree onehopper Joyce want know work ask tell number label tree n vertex share exactly k edge will tree k the answer large ask tell answer modulo 10000000071097
2string
as know Max good video game player friend her friend jealous create actual game prove she s good game the game play direct acyclic graph DAG n vertex m edge there s character write edge lowercase english letter Max Lucas playing game Max go Lucas Max each player marble initially locate vertex each player hisher turn hisher marble edge player marble vertex v vertex u there s outgoing edge v u if player move hisher marble vertex v vertex u character round character write edge v u there s additional rule ASCII code character round great equal ASCII code character round i1 i1 the round number player ie Max go odd number Lucas go number the player can not lose game the marble vertex timesince game Lucas Max focus find Dart do not time play so ask play optimally win gameyou determine winner game initial position marble
1graph
to surprise Jamie final boss EheheheJamie give tree n vertex number 1 n initially root tree vertex number 1 also vertex value itJamie give type query tree1 v change tree root vertex number v2 u v x for vertex subtree small size contain u v add x value3 v Find sum value vertice subtree vertex number vA subtree vertex v set vertex v lie short path vertex root tree pay attention subtree vertex change change tree rootshow strength programming Jamie perform query accurately
1graph
this year Alex finish school firstyear student Berland State University for total surprise study program attend physical education lesson the end term soon unfortunately Alex have not attend single lessonsince Alex do not want expel want know number work day leave end term attend physical education lesson day but BSU calculate number work day complicate matterThere n day leave end term number 1 n initially work day then university staff sequentially publish q order each order characterise number l r k if k1 day l r inclusive nonworking day if day work day previous order day nonworke day if k2 day l r inclusive working day if day nonworke day previous order day work day help Alex determine number work day leave order
1graph
Luba surf internet she currently n open tabs browser index 1 n leave right the mouse cursor currently locate posth tab Luba need use tab indice l r inclusive study want close tab do not belong segment fast possibleeach second Luba try move cursor leave right cursor currently tab tab maxi1a tab mini1b try close tab leave right cursor cursor currently tab close tab index segment ai1 segment i1b in aforementioned expression b denote minimum maximum index unclosed tab respectively for example 7 tab initially tab 1 2 7 close a3 b6what minimum number second Luba spend order leave tabs initial indice l r inclusive open
2string
Ember Storm play game First Ember pick label tree T n vertex degree vertex d then storm pick distinct vertex u v tree write label vertex path u v sequence a1a2 ak Finally Ember pick index 1ik array now perform follow operation exactly flip subrange i1k add ai after sequence a1 aiakaiak1ai ai1ai negate subrange i1k add ai ie array a1 aiai1aiai2aiakai Ember win array monotonically increase decrease Otherwise Storm winsthe game describe tuple Tuviop op flip negate depend action Ember choose turn Find number tuple occur Ember Storm play optimally when play optimally multiple move guarantee win play win move otherwise lose matter play play possible movesReport answer modulo m
2string
Edogawa Conan get tired solve case invite friend Professor Agasa they decide play game card Conan n card ith card number ai write itthey turn play start Conan in turn player choose card remove also remove card have number strictly less number choose card Formally player choose ith card remove card remove jth card j ajaiA player lose turn lose card leave Predict outcome game assume player play optimally
1graph
while Grisha celebrate New Year Ded Moroz Misha gift Sasha small rectangular pond size nm divide cell size 11 inhabit tiny evil fish fish cell they ll strifethe gift bundle include square scoop size rr design fishing if lowerleft corner scoopnet locate cell xy fish inside square xyxr1yr1 catch note scoopnet lie completely inside pond usedunfortunately Sasha skilled fishing throw scoop randomly in order frustrate Sasha Misha decide release k fishes pond way expect value number catch fish high possible help Misha in word k fishes pond distinct cell way scoopnet place random position nr1mr1 possible position average number catch fish high possible
1graph
you give unweighted tree n vertex then n1 follow operation apply tree a single operation consist follow step choose leave add length simple path answer remove choose leave tree initial answer apply operation 0 obviously n1 operation tree consist single vertex calculate maximal possible answer achieve construct sequence operation allow achieve answer
1graph
let suppose array stack s initially array b initially emptyyou perform follow operation s take element push s remove take element s append end array b remove s s you perform operation arbitrary orderif exist way perform operation array b sorted nondescending order end array call stacksortablefor example 312 stacksortable b sorted perform follow operation remove 3 push s remove 1 push s remove 1 s append end b remove 2 push s remove 2 s append end b remove 3 s append end b after operation b123 312 stacksortable 231 stacksortableyou give k element permutation p size n recall permutation size n array size n integer 1 n occur exactly you restore remain nk element permutation stacksortable if multiple answer choose answer p lexicographically maximal array q lexicographically great array p iff exist integer k ik qipi qkpk you swap change k element permutationprint lexicographically maximal permutation p obtainIf exist answer output 1
1graph
your friend hide direct graph n nodeslet fuv true direct path node u node v false for pair distinct node uv know statement true here and or XOR mean and or exclusive or operation respectivelyYou give n n matrix say statement hold pair vertex the entry uth row vth column single character if statement hold represented character a if second hold represent character o if hold represent character x the diagonal matrix contain character note possible pair node satisfy multiple statement case character give represent true statement pair this matrix guarantee symmetricyou like know direct graph consistent matrix if impossible print integer 1 otherwise print minimum number edge consistent information
1graph
Arseny like organize party invite people however friend come party friend friend friend friend friend that s arsenys guest unknown he decide fix issue follow procedureAt step select guest a pairwise introduce friend after action friend a friend this process run pair guest friendsarseny do not want spend time want finish process minimum number step help arseny
0array
Mishka get n box for 1 in ith box cube length aiMishka box box j follow condition meet ith box box jth box do not contain box box small box j aiaj Mishka box arbitrary number time he want minimize number visible box a box call visible iff boxhelp Mishka determine minimum possible number visible box
2string
you give connect undirected graph n vertex m edge the vertex enumerate 1 n you give n integer c1c2cn n n inclusive it guarantee parity cv equal parity degree vertex v the degree vertex number edge connect ityou write weight 2n2 2n2 inclusive edge way vertex v sum weight edge connect vertex equal cv determine impossible
1graph
Sasha take programming competition in problem check rooted tree isomorphic she see problem experience participant guess match tree sequence compare sequence instead tree Sasha want match tree sequence a0a1ah h height tree ai equal number vertex distance edge root unfortunately time Sashas intuition wrong tree match sequence to need write program give sequence ai build nonisomorphic root tree match sequence determine treetwo rooted tree isomorphic reenumerate vertex way index root equal index root second tree tree equalthe height root tree maximum number edge path root vertex
1graph
you give permutation p length n remove element permutation number record maximum possiblewe remind sequence number a1a2ak element ai record integer j 1ji follow hold ajai
2string
you fraction you need find occurrence digit c decimal notation fraction decimal point
1graph
there n shovel Polycarps shop the ith shovel cost burle shovel cost 1 burle second shovel cost 2 burle shovel cost 3 burle Polycarps want sell shovel pairsvisitor likely buy pair shovel total cost end 9s because Polycarp wants choose pair shovel sell way sum cost end maximum possible number nine for example choose shovel cost 12345 37454 total cost 49799 end ninesyou compute number pair shovel total cost end maximum possible number nine two pair consider different shovel present pair
1graph
Ann Borya n pile candy n number there ai candy pile number iAnn like number square integer Borya do not like number square integer during guy select pile candy add candy candy new do not belong pile remove candy candy pile find minimal number move require exactly n2 pile contain number candy square integer exactly n2 pile contain number candy square integer
2string
Vasya phone book record telephone number friend each friend phone numbersvasya decided organize information phone number friend you give n string entry Vasyas phone book each entry start friend then follow number phone number current entry phone number it possible identical phone record recordvasya believe phone number suffix phone number b number b end number write Vasya phone number person record city code take accountthe task print organize information phone number Vasyas friend it possible different people number if person number x y x suffix y y end x should not print number x if number friend Vasyas phone book record time format necessary account exactly onceread example understand statement format output well
1graph
Are go Scarborough FairParsley sage rosemary thymeremember live therehe true love mineWillem take girl high building island No28 know thereWillem ask friend Grick direction Grick help give taskAlthough girl want help Willem insist himselfGrick give Willem string length nWillem need m operation operation parameter lrc1c2 mean symbol c1 range lr lth rth include l r change c2 String 1indexedgrick wants know final string m operation
2string
Lakhesh love movie Nephren help run cinema we no 68 CinemaHowever day no 68 Cinema run change do not 50yuan note currently Nephren want start business Assume yuan kind currency Regulu EreThere type customer bring exactly 50yuan note bring 100yuan note Nephren need 50yuan note himher bring vip card do not need pay ticketnow n customer wait outside queue Nephren want know possible queue able run smoothly ie customer receive hisher change number 50yuan note sell ticket customer l r inclusive two queue consider different exist customer type different queue as number large output answer modulo p
1graph
this interactive problem Refer Interaction section well understandingIthea chtholly want play game order determine use kitchen tonightinitially ithea put n clear sheet paper line they number 1 n leave rightthis game m round in round Ithea chtholly integer 1 c chtholly need choose sheet write number number erase original replace new onechtholly win time sheet fill number n number nondecrease order looking leave right sheet 1 sheet n m round do not win lose gamechtholly want win game want cook Willem but do not know win game so chtholly find task write program receive number Ithea gives chtholly help decision sheet paper write number
1graph
Ralph go collect mushroom Mushroom Forest there m direct path connect n tree Mushroom Forest on path grow mushroom when Ralph pass path collect mushroom path the Mushroom Forest magical fertile ground mushroom grow fantastic speed new mushroom regrow soon Ralph finish mushroom collection path more specifically Ralph pass path ith time regrow mushroom pass that initially x mushroom path Ralph collect x mushroom time x1 mushroom second time x12 mushroom time however number mushroom 0for example let 9 mushroom path initially the number mushroom collect path 9 8 6 3 Ralph pass fourth time from fifth time later Ralph can not collect mushroom path pass itRalph decide start tree s how mushroom collect describe path
1graph
ralph magic field divide nm block that n row m column field Ralph integer block however magic field do not work properly it work product integer row column equal k k 1 1now Ralph want figure number way number block way magic field work properly two way consider different exist block number way second way different you ask output answer modulo 10000000071097note range number block prove answer infinity
2string
you give rooted tree consist n vertex each vertex number write number ai write vertex ilet denote dij distance vertice j tree number edge short path j also let denote kblocke subtree vertex x set vertex y condition meet x ancestor y vertex ancestor dxyk you give m query tree ith query represent number xi ki answer query minimum value aj vertex j j belong kiblocked subtree xiWrite program process query quicklynote query give modified way
2string
hand shed innocent bloodthere n guilty people line ith hold claw length Li the bell ring person kill people all people kill time Namely ith person kill jth person ji jiLiYou give length claws you need find total number alive people bell ring
1graph
a permutation p size n array integer 1 n occur exactly arraylet permutation identity permutation iff exist nk index 1 in piiyour task count number identity permutation give number n k
1graph
Mashas little brother draw point sheet paper after draw circle give sheet sister Masha return geometry lesson instantly notice interesting fact brother drawingAt line go point brother draw do not intersect touch circleAlso circle intersect touch pair circle circle locate inside anotherMoreover circle Masha draw square minimal area side parallel axis circle locate inside square notice square intersect touch pair square square locate inside othernow Masha want draw circle minimal possible radius go point brother draw do not intersect circle circle touch Mashas circle locate inside itits guarantee answer will not exceed 1012 it hold hack
1graph
there main kind event life topmodel fashion show photo shoot participate event affect rate appropriate topmodel after photo shoot model rating increase fashion decrease b designer experiment nowadays moreover topmodel participate talk show after participate talk model popular increase rating photo shoot c decrease rating fashion dIzabella want participate talk want way rate negative help find suitable moment participate talk Lets assume model career begin moment 0 at moment Izabellas rating equal start if talk happen moment t affect event model life interval time ttlen include t include tlen len duration influenceizabella want participate talk want way rate negative talk period influence talk Help find suitable moment participate talk
1graph
a onedimensional japanese crossword represent binary string length x an encode crossword array size n n number segment form completely 1s ai length ith segment no segment touch intersectfor example if x6 crossword 111011 encode array 32 if x8 crossword 01101010 encode array 211 if x5 crossword 11111 encode array 5 if x5 crossword 00000 encode array Mishka want create new onedimensional japanese crossword he pick length encoding crossword and need check exactly crossword length encoding equal length encoding pick help check
1graph
only t millisecond leave start wellknown online programming contest Codehorses Round 2017polycarp need download b compiler contest the size file f bytesPolycarps internet tariff allow download datum rate byte t0 millisecond this tariff prepay use incur expense Polycarp in addition internet service provider offer additional package download a1 byte rate byte t1 millisecond pay p1 burle package download a2 byte rate byte t2 millisecond pay p2 burle package Polycarp buy package time when buy package price p1 p2 prepaid usage once package buy replace regular tariff package datum limit completely after package consume Polycarp immediately buy new package switch regular tariff loose time while package use Polycarp can not buy package switch regular internet tarifffind minimum money Polycarp spend download f bytes file T millisecondsnote technical reason Polycarp download integer number byte regular tariff package ie download mode number download byte integer it mean Polycarp can not download byte partially regular tariff orand package
0array
recently tournament k kind sport begin Berland Vasya want money betsthe scheme tournament mysterious fully disclose Competitions hold involve sportsman leave tournament each match hold k kind sport Loser leave tournament the remain sportsman winner Apart scheme arbitrary disclose advancevasya know power sportsman kind sport he believe sportsman high power winsthe tournament hold year year new participant join in tournament sportsman participate second sportsman Vasya watch tournament n year help find number possible winner n tournament
2string
Slava play favorite game Peace Lightning now fly bomber specific mapformally map checker field size 1n cell number 1 n cell tank Slava do not know number tank position fly high drop bomb cell all tank cell damagedIf tank take damage time instantly move neighboring cell tank cell n cell n1 tank cell 1 cell 2 if tank take damage second time count destroy move the tank damage time themselvesHelp Slava destroy tank bomb possible
1graph
you give multiset n integer you select exactly k way difference divisible m tell impossiblenumber repeat original multiset multiset select number number occurrence number multiset select number exceed number occurrence original multiset
1graph
Petya Vasya got employ courier during work day deliver package n different point line accord company internal rule delivery package carry strictly certain order Initially Petya point coordinate s1 Vasya point coordinate s2 client point x1x2xn order require visitthe guy agree advance deliver package customer act follow when package ith client deliver deliver package i1st client send path person go point xi the friend busy deliver current package stand stillTo communicate guy get walkietalkie the walkietalkie work poorly great distance Petya Vasya want distribute order maximum distance day low possible help Petya Vasya minimize maximum distance observe delivery rule
2string
disclaimer lot untranslateable pun russian version statement reason learn Russian Rick Morty like ridge High Cry cry loudly extraordinary echo recently discover interesting acoustic characteristic ridge Rick Morty begin cry simultaneously different mountain cry hear mountain height equal bitwise or mountain they ve climb mountain Bitwise or binary operation determine follow way consider representation number x y binary numeric system probably lead zeroes xxk x1x0 yyk y1y0 then zxy define follow way zzk z1z0 zi1 xi1 yi1 zi0 in word digit bitwise or number equal zero digit correspond position number equal zero for example bitwise or number 1010102 910012 equal 1110112 in programming language CCJavaPython operation define Pascal orhelp Rick Morty calculate number way select mountain way start cry mountain cry hear mountain mountain more formally find number pair l r 1lrn bitwise or height mountain l r inclusive large height mountain interval
1graph
you give string s consist n lowercase latin letter some index string mark forbiddenyou want find string value afa maximum possible fa number occurence s occurence end nonforbidden index so example s aaaa aa index 3 forbid fa2 occurence s start index 1 2 3 start index 2 end forbid indexcalculate maximum possible value afa
1graph
Luba n chore today ith chore take ai unit time complete it guarantee condition aiai1 meet sequence sortedalso Luba work hard chore she choose k chore x unit time instead ai Luba responsible n chore want know minimum time need Luba chore simultaneously
2string
you give positive integer n Lets build graph vertex 12n way edge vertex u v Let duv short distance u v 0 path Compute sum value duv 1uvnthe gcd great common divisor positive integer maximum positive integer divide integer
1graph
you give array a1a2an consist n integer integer k you split array exactly k nonempty subsegment you ll compute minimum integer subsegment maximum integer k obtain minimum what maximum possible integer getDefinitions subsegment array splitting give note
2string
adieu lamiKoyomi help Oshino acquaintance care open space abandon Eikou Cram School building Oshinos makeshift residenceThe space represent rectangular grid nm cell arrange n row m column the cth cell rth row denote rcOshino place remove barrier rectangular area cell specifically action denote 1 r1 c1 r2 c2 mean Oshinos place barrier rectangle corner r1c1 r2c2 side parallel square side similarly 2 r1 c1 r2 c2 mean Oshinos remove barrier rectangle Oshino ensure barrier stay ground share common point intersect boundary nm areasometime Koyomi try walk cell carefully stride barrier order avoid damaging item grind 3 r1 c1 r2 c2 mean Koyomi try walk r1c1 r2c2 crossing barriersAnd you re tell Koyomi feasibility attempt
1graph
this playing duty ally justice Niichan Not ally justice OniichanWith hand join speed fast thought this time Fire Sisters Karen Tsukihi head they ve reach watersurrounded islandsthere cluster island conveniently colour red blue purple the cluster consist b c distinct island respectivelybridge build possibly island a bridge bidirectionally connect different island length 1 for island colour should not reach bridge short distance 3 apparently order prevent oddity spread quickly inside clusterthe Fire Sisters ready unknown they d like test courage and you re figure number different way build bridge constraint answer modulo 998244353 two way consider different pair island exist there s bridge
1graph
Snark Philip prepare problemset upcoming prequalification round semiquarterfinal they bank n problem want select nonempty subset problemsetk experience team participate contest some team know problem to contest interesting team know half select problemsdetermine Snark Philip interesting problemset
1graph
as know MemSQL american office San Francisco Seattle being manager company travel lot city planeyou prefer fly Seattle San Francisco direction warm San Francisco you busy do not remember number flight direction however n day know San Francisco office Seattle office you fly night office day give information determine fly time Seattle San Francisco n day
2string
the game Egg Roulette play player initially 2r raw egg 2C cook egg place randomly carton the shell leave way distinguish raw egg cook egg one time player select egg smash egg hisher forehead if egg cook happen egg raw mess this continue player break R raw egg point player declare loser player winsthe order player turns describe stre A b character ith character tell player choose ith egg Traditionally player turn go that follow order ABABAB this is not fair second player win We d like find well order player turn Lets define unfairness order absolute difference player win probability second player win probability Were interested ordering minimize unfairness we consider order valid contain number as BsYou give stre s length 2rc contain a b character an ordering say match S differ S position S contain of valid ordering minimize unfairness match S
2string
there n city Berland some pair connect m direct road one use road city there road connect city for pair city xy road x yA path city s city t sequence city p1 p2 pk p1s pkt road city pi city pi1 1 k1 the path pass multiple time city t it can not pass t oncea path p s t ideal lexicographically minimal path in word p ideal path s t path q s t piqi minimum integer piqithere tourist agency country offer q unusual excursion jth excursion start city sj end city tj for pair sj tj help agency study ideal path sj tj note possible ideal path sj tj this possible reason path sj tj path sj tj path p path q sj tj piqi minimum integer piqi the agency like know ideal path sj tj kjth city path way sj tjFor triple sj tj kj 1jq find ideal path sj tj print kjth city path
1graph
Vadim keen travel recently hear kayak activity near town excite join party kayakersNow party ready start journey firstly choose kayak there 2n people group include Vadim exactly n1 tandem kayak obviously carry people 2 single kayak ith person weight wi weight important matter kayak difference weight people sit tandem kayak large crash and course people want distribute seat kayak order minimize chance kayak crashformally instability single kayak 0 instability tandem kayak absolute difference weight people kayak Instability journey total instability kayakshelp party determine minimum possible total instability
1graph
Mahmoud Ehab stage adventure as know Dr Evil like set this time will not set large collection ask create new set replenish beautiful collection setsDr Evil favorite evil integer x he ask Mahmoud Ehab find set n distinct nonnegative integer bitwisexor sum integer exactly x Dr Evil do not like big number number set should not great 106
1graph
Mahmoud Ehab continue adventure as everybody evil land know Dr Evil like bipartite graph especially treesA tree connect acyclic graph a bipartite graph graph vertex partition 2 set way edge uv belong graph u v belong different set you find formal definition tree bipartite graph note section belowDr Evil give Mahmoud Ehab tree consist n node ask add edge way graph bipartite besides add edge graph simple do not contain loop multiple edge what maximum number edge addA loop edge connect node Graph do not contain multiple edge pair node edge a cycle loop are not
1graph
in build Polycarp live equal number flat floor unfortunately Polycarp do not remember flat floor remember flat number 1 low upper floor that flat floor flat second Polycarp do not remember total number flat building consider build infinitely high ie infinitely floor note floor number 1polycarp remember floor flat locate it guarantee information selfcontradictory it mean exist build equal number flat floor flat Polycarps memory floor Polycarp remembersgiven information possible restore exact floor flat n
1graph
Harry Ron Hermione figure Helga Hufflepuffs cup horcrux through encounter Bellatrix Lestrange Hermione come know cup present Bellatrixs family vault Gringotts Wizarding Bank the Wizarding bank form tree total n vault vault type denote number 1 m a tree undirecte connect graph cyclesthe vault high security type k vault type k high securityThere x vault high security also vault high security adjacent vault guarantee high security type guarantee kHarry want consider possibility easily find good path reach Bellatrixs vault so tell give tree structure Gringotts number possible way give vault type condition hold
0array
ilya sit wait area Metropolis airport bore look time table show plane delay so take sheet paper decide solve problemsFirst ilya draw grid size nn marked n square mark square share row column he call rectangle grid side parallel grid side beautiful exactly corner square mark there exactly nn12 beautiful rectanglesilya choose q query rectangle grid side parallel grid side necessarily beautiful one rectangle wants find beauty degree beauty degree rectangle number beautiful rectangle share square give onenow Ilya think time solve problem till departure flight you give description mark cell query rectangle help ilya find beauty degree query rectangle
2string
consider array A N element integer aDefine product transformation simultaneous update AiAiAi1 multiply element element right number an remain for example start array a a2 n4 product transformation A4 4 4 2 product transformation A16 16 8 2your simple task calculate array a M product transformation since number big output modulo Q
1graph
Bill famous mathematician BubbleLand thank revolutionary math discovery able money build beautiful house unfortunately pay property tax time court decide punish Bill making lose propertybill property observe convex regular 2nsided polygon a0 A1 A2n1 A2n a2n a0 side exactly 1 meter length Court rule remove property follow Split edge Ak ak1 k0 2n1 n equal part size 1n point p0p1pn1 on edge A2k A2k1 k0 n1 court choose point B2k Pi i0 n1 on edge a2k1a2k2 k0n1 Bill choose point B2k1 Pi i0 n1 Bill get property inside 2nsided polygon b0 b1 B2n1 Luckily Bill find B2k point court choose even great mathematician house big hard time calculate therefore ask help choose point maximize area property
1graph
Arpa take geometry exam here problem examyou give point abcfind point angle rotate page point angle new position old position b new position b old position cArpa doubt problem solution ie exist point angle satisfy condition help Arpa determine question solution
2string
Arpa research Mexican wavethere n spectator stadium label 1 n they start mexican wave time 0 at time 1 spectator stand at time 2 second spectator stand at time k kth spectator stand at time k1 k1th spectator stand spectator sit at time k2 k2th spectator stand second spectator sit at time n nth spectator stand nkth spectator sit at time n1 n1kth spectator sit at time nk nth spectator sit Arpa want know spectator stand time t
1graph
Mojtaba Arpa play game they list n number gameIn player turn choose number pk p prime number k positive integer pk divide number list for number list divisible pk x player delete x add list the player valid choice p k losesMojtaba starts game player alternatively move Determine player winner player play optimally
1graph
the Floral Clock stand Mirror Lake year though unable time remind people passage time good old daysOn rim Floral Clock 2n flower number 1 2n clockwise colour n possible one for colour exactly flower distance equal 2 equal n Additionally flower u v colour flower opposite u opposite v colour symmetry beautifulformally distance flower 1 plus number flower minor arc semicircle below possible arrangement n6 cover possibility the beauty arrangement define product length flower segment separate opposite flower colour in word order compute beauty remove circle flower colour flower opposite then beauty product length remain segment note include segment length 0 product if flower colour flower opposite beauty equal 0 for instance beauty arrangement equal 13139 segment 2 456 8 101112while keeping constraint satisfy lot different arrangement find sum beauty possible arrangement modulo 998244353 two arrangement consider different pair uv 1uv2n exist flower u v colour
2string
I will not feel lonely I sorrowful burieda string n bead leave message leave the bead number 1 n leave right having shape number integer 1 n inclusive some bead shapesThe memory shape x certain subsegment bead define difference position position shape x appear segment the memory subsegment sum memory shape occur itfrom time time shape bead change memory sometimes past secrete subsegment recall find memory
1graph