question
stringlengths 58
4.29k
| label
class label 3
classes |
---|---|
this subtask problem F the difference second subtask constraint value m time limit you need solve subtask order hack onethere n1 distinct colour universe number 0 n there strip paper m centimetre long initially paint colour 0 Alice take brush paint strip following process for 1 n order pick integer 0 leq a_i b_i leq m segment a_i b_i currently paint single colour repaint colour Alice choose segment way centimetre paint colour 0 Formally segment i1 paint colour c_i c_i neq 0 every colour 0 visible stripcount number different pair sequence a_i_i1n b_i_i1n result configuration since number large output modulo 998244353 | 0array
|
let write positive integer number 1 delimiter ie single string it infinite sequence start 123456789101112131415161718192021222324252627282930313233343536your task print kth digit sequence | 2string
|
you give integer nYou perform follow operation number arbitrary possibly zero number time Replace n fracn2 n divisible 2 Replace n frac2n3 n divisible 3 Replace n frac4n5 n divisible 5 for example replace 30 15 operation 20 second operation 24 operationYour task find minimum number move require obtain 1 n impossible ityou answer q independent query | 1graph
|
you give n interval form l r number lineYou give m query form x y what minimal number interval point necessarily integer x y cover if can not choose interval point x y cover print 1 query | 1graph
|
you give function f write basic language the function accept integer value immediately write variable x x integer variable assign value 0 2321 the function contain type commands n loop end command n correspond end execute n time add add 1 x after execution command value x returnedEvery n match end function guarantee valid n immediately follow endadd command outside loopsNotice add command overflow value x it mean value x great 2321 add command now run f0 wonder result value x correct overflow incorrectIf overflow happen output overflow print result value x | 2string
|
you give integer n integer kIn step follow move decrease n 1 divide n k n divisible k for example n 27 k 3 follow step 27 rightarrow 26 rightarrow 25 rightarrow 24 rightarrow 8 rightarrow 7 rightarrow 6 rightarrow 2 rightarrow 1 rightarrow 0you ask calculate minimum number step reach 0 n | 1graph
|
you re give integer n for integer 2 n assign positive integer a_i follow condition hold for pair integer ij j coprime a_i neq a_j the maximal value a_i minimize small possible a pair integer call coprime great common divisor 1 | 1graph
|
nauuo girl love codingOne day solve problem require calculate sum number modulo pShe write follow code get verdict Wrong answerShe soon discover bug modadd function work number range 0p number problem range she curious wrong function want know result ithowever original code work slow ask help heryou give array a_1a_2ldotsa_n number p Nauuo m query query give l r calculate result Sumalrp you definition Sum function pseudocode aboveNote integer will not overflow code | 2string
|
nauuo girl love play game relate portalsone day playing game followsIn ntime n grid row number 1 n column number 1 n leave right we denote cell intersection rth row cth column rca portal pair door you travel change direction more formally walk cell door teleport cell door portal walk cell face original direction there door single cellThe cell near cell direction face for example face cell 25 35if walk cell door walk cell change direction if cell exist exit gridyou set possibly zero portal grid walk i1 face right eventually exit grid r_in walk 1 face exit grid nc_iIt guarantee r_1n c_1n permutation n element a permutation n element sequence number p_1p_2ldotsp_n integer 1 n appear exactly onceshe get confused playing game help find solution | 1graph
|
nauuo girl love play cardsone day playing card find card mix onesthere n card number 1 n mixed n card she pile 2n card draw n the n card Nauuos hand give the remain n card pile give order bottomin operation choose card hand play pile draw card pilenauuo want n number card pile increase order ith card pile card quickly possible can tell minimum number operation | 2string
|
you give sequence a_1 a_2 dot a_n you choose subset element reorder create sawthe sequence b_1 b_2 dots b_m call see element satisfy follow series inequalities b_1b_2b_3b_4dots b_1b_2b_3b_4dotsfind long saw obtain give arraynote give sequence require see b contain duplicate nonunique value | 1graph
|
polycarp n wheel car m slot wheel the initial pressure ith wheel a_ipolycarps goal exactly m wheel give n wheel equalize pressure wheel car use drive in minute decrease increase pressure single wheel 1 he increase pressure k time total hard pump wheelsHelp polycarp minimum number minute need spend equalize pressure m wheel give n wheel | 1graph
|
the circle line Roflanpolis subway n stationsthere parallel route subway the visit station order 1 2 ldot n 1 2 ldot stop station x equal x1 x n 1 the second route visit station order n n1 ldot 1 n n1 ldot stop station x equal x1 x1 n all train depart station simultaneously take exactly 1 minute arrive stationtwo toad live city name Daniel VladDaniel currently train route station exit subway train reach station xCoincidentally Vlad currently train second route station b exit subway train reach station ySurprisingly number axby distincttoad Ilya ask check Daniel Vlad station time journey in word check moment train stop station Note include moment Daniel Vlad enter leave subway | 1graph
|
Toad Pimple array integer a_1 a_2 ldot a_nWe y reachable x xy exist integer array p x p_1 p_2 ldot p_ky a_p_i a_p_i1 0 integer 1 leq kHere denote bitwise and operationyou give q pair index check reachability | 2string
|
Toad Zitz array integer integer 0 m1 inclusive the integer a_1 a_2 ldot a_nin operation Zitz choose integer k k index i_1 i_2 ldot i_k 1 leq i_1 i_2 ldot i_k leq n he change a_i_j a_i_j1 bmod m choose integer i_j the integer m fix operation indicesHere x bmod y denote remainder division x yZitz want array nondecrease minimum number operation find minimum number operation | 2string
|
this interactive problem remember flush output communicating testing program you use fflushstdout c systemoutflush Java stdoutflush Python flushoutput pascal flush output if use programming language consult documentation you refer guide interactive problem httpscodeforcescomblogentry45307the jury guess array consist 6 integer there 6 special number 4 8 15 16 23 42 number occur exactly permutation numbersyou do not know order allow ask 4 query in query choose index j 1 le j le 6 j necessarily distinct value a_i cdot a_j returnCan guess array aThe array fix test interaction program do not try adapt query | 1graph
|
we guess integer number x you give list divisor almost mean divisor 1 x listYour task find minimum possible integer x guess number input datum contradictory impossible find numberyou answer t independent query | 1graph
|
Kuro learn permutation excited create new permutation type he choose n distinct positive integer set S now define magical permutation a permutation integer 0 2x 1 x nonnegative integer the bitwise xor consecutive element permutation element SSince Kuro excite magical permutation wants create long magical permutation possible in word wants find large nonnegative integer x magical permutation integer 0 2x 1 since newbie subject want help find value x magical permutation x | 1graph
|
during normal walk forest Katie stumble mysterious code however mysterious code character unreadable she write code string c consist lowercase english character asterisk asterisks denote unreadable character excite discovery Katie decide recover unreadable character replace asterisk arbitrary lowercase english letter different asterisk replace different letterskatie favorite string s notsofavorite string t love recover mysterious code occurrence s possible little occurrence t possible Formally let denote fx y number occurrence y x example faababa ab 2 Katie want recover code c conform original c fc s fc t large possible However Katie good recover code general like help | 1graph
|
Vasya write permutation p_1 p_2 ldot p_n integer 1 n 1 leq leq n true 1 leq p_i leq n p_1 p_2 ldot p_n different after write n number next_1 next_2 ldot next_n the number next_i equal minimal index j leq n p_j p_i if j let let define next_i n 1in evening Vasya go home school rain notebook get wet now impossible read write number permutation value next_i completely lose if value next_i lose let next_i 1you give number next_1 next_2 ldot next_n maybe equal 1 help Vasya find permutation p_1 p_2 ldot p_n integer 1 n write notebook number next_i equal 1 correct | 1graph
|
you bag contain n card there number write card number ith card a_iYou play follow game during turn choose remove random card bag card leave inside bag choose equiprobably nothing happen turn turn remove card let number x compare card remove previous turn let number y possible outcome x y game end lose x y game end win x y game continue if card leave bag lose Cards return bag remove themyou calculate probability win game it show form fracpq p Q nonnegative integer Q neq 0 p le Q Output value p cdot Q1 mod 998244353 | 0array
|
Jury pick polynomial fx a_0 a_1 cdot x a_2 cdot x2 dot a_k cdot xk k le 10 a_i integer number 0 le a_i 106 3 its guarantee a_i 0now jury wants find integer x_0 fx_0 equiv 0 mod 106 3 report x_0you ask 50 query ask value x_q jury tell value fx_q mod 106 3Note print answer do not count query | 2string
|
there n shovel nearby shop the ith shovel cost a_i bourlesMisha buy exactly k shovel each shovel buy onceMisha buy shovel purchase during purchase choose subset remain nonbought shovel buy subsetthere m special offer shop the jth give pair x_j y_j mean Misha buy exactly x_j shovels purchase y_j cheap free ie pay y_j cheap shovel current purchaseMisha use offer possibly zero number time use offer purchase buy shovel offersyour task calculate minimum cost buy k shovel Misha buy optimally | 1graph
|
polycarp cat cat real gourmet Dependent day week eat certain type food Mondays Thursdays Sundays eat fish food Tuesdays Saturdays eat rabbit stew day week eat chicken stake Polycarp plan trip pack backpack his backpack contain daily ration fish food b daily ration rabbit stew c daily ration chicken stake Polycarp choose day week start trip cat eat additional food purchase long possible print maximum number day cat eat trip additional food purchase Polycarp choose day week start trip optimally | 1graph
|
get close close mathematician Serval university student math major Japari University on Calculus class teacher teach calculate expect length random subsegment give segment then leave bonus problem homework award garage kit IOI the bonus extend problem general case followsyou give segment length l we randomly choose n segment choose point maybe noninteg coordinate give segment equiprobably interval point form segment you give number random segment n integer k the 2n endpoint choose segment split segment 2n1 interval your task calculate expect total length interval cover k segment n random segmentsyou find answer modulo 998244353 | 2string
|
this interactive problemnow serval senior high school student Japari Middle School however way school pond dangerous snake the pond represent n time n grid the snake head tail different cell body series adjacent cell connect head tail selfintersecte if Serval hit head tail snake bite dieluckily special device answer follow question pick rectangle tell number time need cross border rectangle walk cell cell snake head tail the picture possible snake possible query answer 4 today Serval get late time 2019 query as good friend help find position head tailnote cell adjacent common edge grid snake body length 0 mean adjacent head tailalso note snake sleep will not serval device and what s obvious snake position depend query | 1graph
|
it rain heavily but day Serval 3 year old kindergarten unfortunately live far kindergarten father busy drive the choice poor little boy wait bus rainy day under circumstance poor boy use bus see matter go if bus come time choose randomlyserval bus station time t n bus route stop station for ith bus route bus arrive time s_i minutes bus route come d_i minute later previous oneas serval good friend wonder bus route if bus arrive time print | 1graph
|
Neko love divisor during late number theory lesson get interesting exercise math teacherneko integer b his goal find nonnegative integer k common multiple ak bk smallest possible if multiple optimal integer k need choose small onegiven mathematical talent Neko trouble get Wrong Answer problem can help solve | 2string
|
on random day Neko find n treasure chest m key the ith chest integer a_i write jth key integer b_j Neko know chest contain powerful mysterious green Grapes Neko want open treasure chest possiblethe jth key unlock ith chest sum key number chest number odd number formally a_i b_j equiv 1 pmod2 one key open chest chest open oncefind maximum number chest Neko open | 1graph
|
nazar student scientific lyceum Kingdom Kremland know outstanding mathematical ability today math teacher give difficult taskconsider infinite set number the set consist odd positive number 1 3 5 7 ldot second set consist positive number 2 4 6 8 ldot at stage teacher write number endless blackboard set second stage number second set stage number set fourth number second set in word stage start second write time number previous change set number write the write number 1 2 4 3 5 7 9 6 8 10 Lets number number write start onethe task find sum number number l r give integer l r the answer big need find remainder division 1000000007 1097nazar think problem long time do not come solution help solve problem | 2string
|
today scientific lyceum Kingdom Kremland biology lesson the topic lesson genome Lets genome string ACTGMaxim boring sit class teacher come task give string s consist uppercase letter length 4 need find minimum number operation need apply genome appear substre for operation replace letter string s previous alphabet for example letter D previous c e in problem assume letter a previous letter z b letter z previous letter Y letter AHelp Maxim solve problem teacher give himA string substre string b obtain b deletion possibly zero character begin possibly zero character end | 1graph
|
welcome Codeforces Stock Exchange Were pretty limited currently allow trading stock Codeforces Ltd we hope you ll able profit marketIn morning n opportunity buy share the ith allow buy share want price s_i bourlesIn evening m opportunity sell share the ith allow sell share want price b_i bourle you can not sell share haveits morning possess r bourle shareswhat maximum number bourle hold evening | 1graph
|
consider undirected graph g n vertex there value a_i vertextwo vertice j connected edge gcda_i a_j 1 gcdx y denote great common divisor GCD integer x yConsider set vertex Lets vertex set fair connect edge vertex setyou need find set k vertex k give integer 2 cdot k le n vertex fair vertex fair one set exist | 1graph
|
you give n pair integer a_1 b_1 a_2 b_2 ldot a_n b_n all integer pair distinct range 1 2 cdot n inclusivelet sequence integer x_1 x_2 ldot x_2k good x_1 x_2 x_3 ldot x_2k2 x_2k1 x_2k x_1 x_2 x_3 ldot x_2k2 x_2k1 x_2k you need choose subset distinct index i_1 i_2 ldot i_t order way write number pair single sequence sequence a_i_1 b_i_1 a_i_2 b_i_2 ldot a_i_t b_i_t sequence goodwhat large subset index choose you need construct correspond index sequence i_1 i_2 ldot i_t | 2string
|
Arkady buy air ticket city a city c unfortunately direct flight lot flight a city B B CThere n flight a b depart time moment a_1 a_2 a_3 a_n arrive B t_a moment laterthere m flight b c depart time moment b_1 b_2 b_3 b_m arrive C t_b moment laterthe connection time negligible use ith flight A B jth flight B C b_j ge a_i t_ayou cancel k flight if cancel flight Arkady use itArkady want C early possible want c late possible Find early time Arkady arrive C optimally cancel k flight if cancel k flight way possible reach C print 1 | 2string
|
Inaka disc circumference n unit the circumference equally divide n point number clockwise 1 n point 1 1 leq n adjacent point n 1There m straight segment disc endpoint aforementione n pointsInaka want know image rotationally symmetrical ie integ k 1 leq k n segment rotate clockwise center circle k unit new image original | 1graph
|
InputThe input consist single string uppercase letter AZ the length string 1 10 character inclusiveoutputoutput yes noexamplesinputneatoutputyesinputwordoutputnoinputcoderoutputnoinputaprilfooloutputnoinputaioutputyesinputjuroroutputyesinputyesoutputno | 1graph
|
Thanos sort supervillain sort algorithm work follow array sort snap finger remove second half item repeat processgiven input array size long sort array obtain Thanos sortinfinity Gauntlet require | 1graph
|
two integer sequence exist initially strictly increase strictly decreasingstrictly increase sequence sequence integer x_1 x_2 dot x_k and strictly decrease sequence sequence integer y_1 y_2 dot y_l note sequence sequence consist element consider increase decreasingelement increase sequence insert element decrease possibly element element change order for example sequence 1 3 4 10 4 2 produce follow result sequence 10 textbf1 textbf3 4 2 textbf4 textbf1 textbf3 textbf4 10 4 2 the follow sequence result insertion textbf1 10 textbf4 4 textbf3 2 order element increase sequence changedLet obtain sequence this sequence give input your task find suitable initial sequence one strictly increase strictly decrease note sequence sequence consist element consider increase decreasingif contradiction input impossible split give sequence increase sequence decrease sequence print NO | 1graph
|
recently Golden Circle Beetlovers find Byteland it circle route go n cdot k city the city numerate 1 n cdot k distance neighboring city exactly 1 kmSergey like beetle love burger fortunately n fast food restaurant circle locate 1st k 1st 2k 1st n1k 1st city ie distance neighboring city fast food restaurant k kmSergey begin journey city s travel circle make stop city l km l 0 stop s Sergey forgot number s l remember distance city s near fast food restaurant km distance city stop travel l km s near fast food restaurant b km Sergey travel direction circle calculate distance restaurant consider directionsnow Sergey interested integer the integer x minimum number stop exclude Sergey return s the second integer y maximum number stop exclude Sergey return s | 1graph
|
you give regular polygon n vertex label 1 n counterclockwise order the triangulation give polygon set triangle vertex triangle vertex initial polygon pair triangle intersection nonzero area total area triangle equal area give polygon the weight triangulation sum weigth triangle consist weight triagle denote product label verticescalculate minimum weight triangulation polygon | 0array
|
you give tree connect undirected graph cycle n vertex each n 1 edge tree color black redyou give integer k Consider sequence k vertex Lets sequence a_1 a_2 ldot a_k good satisfie follow criterion we walk path possibly visit edgevertex multiple time tree start a_1 end a_k Start a_1 a_2 short path a_1 a_2 a_3 similar way travel short path a_k1 a_k if walk black edge process sequence good consider tree picture if k3 follow sequence good 1 4 7 5 5 3 2 3 7 the follow sequence good 1 4 6 5 5 5 3 7 3there nk sequence vertex count good since number large print modulo 1097 | 2string
|
Vasya like travel train do not like car travel locate tail trainVasya get train station the train consist n car index 1 n count locomotive head train three type event occur train move some number car add head train some number car add tail train Vasya recalculate value convenience car read at moment time index car head train start 1 note add new car head train indexing old one shiftTo choose car Vasya use value A_i car car index calculate follow at beginning trip a_i0 new car time addition during recalculation Vasya choose positive integer b s add A_i value b 1 cdot s Vasya have not decide train train event type want know index car value A_i minimal since lot car Vasya ask write program answer question | 1graph
|
the new camp widelyknown country Spring Programming Camp go start soon hence team friendly curator teacher start compose camp schedule after continuous discussion come schedule s represent binary string ith symbol 1 student write contest ith day 0 day offat moment Gleb say camp productive run schedule t describe format schedule s since number day current different number day schedule t Gleb require camp schedule alter number occurrence t substre maximum possible at time number contest day day should not change order changecould rearrange schedule well possible way | 1graph
|
at big break Nastya come school dining room there n pupil school number 1 n unfortunately Nastya come pretty late pupil stand queue ie Nastya take place queue of course little bit sad Nastya go despond pupil queue agree change place pupilsformally pair u v pupil number u stand directly pupil number v Nastya ask change place Nastya ask find maximal number place queue forward | 2string
|
Nastya come informatics lesson teacher way little bit famous give follow tasktwo matrix a b give size n time m Nastya perform follow operation matrix a unlimited number time square square submatrix a transpose ie element submatrix ith row jth column submatrix jth row ith column transpose transpose submatrix place matrix a Nastyas task check possible transform matrix a matrix B Example operation as require lot operation ask answer question nastyaa square submatrix matrix M matrix consist element come row indece x x1 dot xk1 matrix M come column indece y y1 dot yk1 matrix M k size square submatrix in word square submatrix set element source matrix form solid square ie hole | 1graph
|
you give undirecte unweighted connected graph consist n vertex m edge it guarantee selfloop multiple edge give graphYour task find span tree graph maximum degree vertice maximum possible Recall degree vertex number edge incident | 1graph
|
polycarp go participate contest it start h_1m_1 end h_2m_2 it guarantee contest last number minute ie m_1 2 m_2 2 x y x modulo y it guarantee entire contest hold single day and finally guarantee contest last minutespolycarp want know time midpoint contest for example contest last 1000 1100 answer 1030 contest last 1110 1112 answer 1111 | 2string
|
you give stre s length n consist lowercase latin letter you apply operation string operation delete contiguous substre string letter substre delete equal for example delete substre bbbb string abbbbaccdd string aaccddcalculate minimum number operation delete string s | 1graph
|
you come local shop want buy chocolate bar there n bar shop ith cost a_i coin want buy themyou m different coupon allow buy chocolate bar ith coupon allow buy q_i chocolate bar pay q_i 1 expensive one cheap bar q_i bar freeyou use coupon use coupon choose q_i bar buy coupon buy remain n q_i bar discountsTo decide coupon choose want know minimum total money pay use coupon optimally | 2string
|
semyon participate prestigious competition world ocean title dangerous shark during competition shark compete different subject speed swimming masking map navigation now Semyon take destruction contestduring m domino place shark all domino line height domino vary the distance adjacent dominoe 1 moreover Domino cost value express integer the goal drop domino to shark push domino leave right begin fall direction if fall domino touch domino start fall direction original domino fall begin chain reaction result domino fall a fall domino touch distance strictly height fall domino domino necessarily adjacentof course shark easily drop domino way goal drop dominoe minimum cost the cost destruction sum cost dominoes shark need push dominoes fallSimon win previous subject smart win Help Semyon determine minimum total cost domino push domino fall | 1graph
|
roman Denis trip programming competition since trip long soon got bored decide come Roman invent pizza recipe Denis invent string multiplication according Denis result multiplication product string s length m t string t s_1 t s_2 ldot t s_m t s_i denote ith symbol string s denote string concatenation for example product string abc de string deadebdecde product string ab z string zazbz note unlike number multiplication product string s t necessarily equal product t sRoman jealous Denis invent cool operation decide invent stringrelated since roman beautylover decided define beauty string length long substre consist letter for example beauty string xayyaaabca equal 3 substring aaa beauty string qwerqwer equal 1 neighboring symbol differentIn order entertain Roman Denis write n string p_1 p_2 p_3 ldot p_n paper ask calculate beauty string ldot p_1 cdot p_2 cdot p_3 cdot ldot cdot p_n s cdot t denote multiplication string s t Roman have not fully realize Deniss multiplication work ask help Denis know roman impressionable guarantee beauty result string 109 | 1graph
|
you give array n integer a_1 a_2 ldot a_n your task find nonzero integer d 103 leq d leq 103 number array divide d number positive number present array greater equal half array size ie lceilfracn2rceil note positive number need integer eg 25 count positive number if multiple value d satisfy condition print in case d print single integer 0Recall lceil x rceil represent small integer x zero 0 positive negative | 1graph
|
in Morse code letter English alphabet represent string length 1 4 Moreover Morse code representation english letter contain dot dash in task represent dot 0 dash 1because 21222324 30 string length 1 4 contain 0 andor 1 correspond 26 english letter in particular string 0 andor 1 length 4 translate distinct english letter follow string correspond English alphabet 0011 0101 1110 1111you work string S initially for m time dot dash append S time your task find report modification stre s number nonempty sequence English letter represent substre S Morse codesince answer incredibly tremendous print modulo 109 7 | 2string
|
Alice receive set Toy Train Bob it consist train connected railway network n station enumerate 1 n the train occupy station time travel network station circular manner more precisely immediate station train visit station station i1 1 leq n station 1 n it take train 1 second travel station describedBob give Alice fun task leave deliver m candy initially station independent destination train the candy enumerate 1 m Candy 1 leq leq m station a_i deliver station b_i a_i neq b_i the blue number candy correspond b_i value the image correspond 1st example the train infinite capacity possible load number candy station however candy load station train leave station you choose candy station the time take candy negligiblenow Alice wonder time need train deliver candy your task find station minimum time train need deliver candy start | 2string
|
a positive integer give Baron Munchausen claim know positive integer n multiplie n sum digits decrease time in word San Sna Sx denote sum digits number x Find Baron tell true | 1graph
|
Alyona recently buy miniature fridge represent matrix h row 2 column initially shelf fridge Alyona install arbitrary number shelf inside fridge row a shelf cell wide occupy space separate inside fridge lower upper an example fridge h 7 shelf the shelf show black the picture correspond example Alyona n bottle milk want fridge the ith bottle a_i cell tall 1 cell wide she bottle shelf corresponding space shelf tall bottle she bottle bottle shelf two bottle share cellAlyona interested large integer k bottle 1 2 k fridge time Find large k | 1graph
|
the difference easy hard version constraintspolycarp write coursework the coursework consist m pagesPolycarp n cup coffee the coffee ith cup Polycarp a_i caffeine Polycarp drink cup coffee he drink cup order Polycarp drink cup instantly completely ie split cup dayssurely coursework write single day perfect world Berland leastlet consider day Polycarps work consider Polycarp drink k cups coffee day caffeine dosage cup Polycarp drink day a_i_1 a_i_2 dot a_i_k then cup drink give energy write a_i_1 page coursework second cup give energy write max0 a_i_2 1 page cup give energy write max0 a_i_3 2 page kth cup give energy write max0 a_i_k k 1 pagesif Polycarp do not drink coffee day write coursework daypolycarp finish coursework soon possible spend minimum number day your task find number day impossible | 1graph
|
the difference easy hard version constraintspolycarp write coursework the coursework consist m pagesPolycarp n cup coffee the coffee ith cup a_i caffeine Polycarp drink cup coffee he drink cup order Polycarp drink cup instantly completely ie split cup dayssurely coursework usually write single day perfect world Berland some require multiple day hard worklet consider day Polycarps work consider Polycarp drink k cups coffee day caffeine dosage cup Polycarp drink day a_i_1 a_i_2 dot a_i_k then cup drink give energy write a_i_1 page coursework second cup give energy write max0 a_i_2 1 page cup give energy write max0 a_i_3 2 page kth cup give energy write max0 a_i_k k 1 pagesif Polycarp do not drink coffee day write coursework daypolycarp finish coursework soon possible spend minimum number day your task find number day impossible | 1graph
|
implement unitary operation n qubit represent square matrix size 2N nonzero element main diagonal antidiagonal zero element elseFor example N 3 matrix operation follow shapeXXXXXXXXXXXXXXXXHere x denote nonzero element matrix complex number square absolute value greater equal 105 denote zero element matrix complex number square absolute value 105the row column index matrix follow little endian format significant bit index store qubit array thus column matrix give coefficient basis state you ll apply unitary 000rangle basis state second column 100rangle basis state etc you use DumpUnitary tool coefficient matrix unitary implement relative phase column correspond pattern Xs sYou implement operation take array n 2 le N le 5 qubit input apply unitary transformation matrix describe shape if multiple unitarie satisfy requirement implement the output operation pattern matrix coefficient implement testing harness UnitaryPatterns katayour code follow signaturenamespace Solution open MicrosoftQuantumPrimitive open MicrosoftQuantumCanon operation Solve qs Qubit Unit code you allow use measurement operation | 1graph
|
implement unitary operation N qubit represent antidiagonal matrix square matrix size 2N nonzero element diagonal run right corner leave corner zero element elseFor example n 2 matrix operation follow shapexxxxhere x denote nonzero element matrix complex number square absolute value greater equal 105 denote zero element matrix complex number square absolute value 105the row column index matrix follow little endian format significant bit index store qubit array thus column matrix give coefficient basis state you ll apply unitary 000rangle basis state second column 100rangle basis state etc you use DumpUnitary tool coefficient matrix unitary implement relative phase column correspond pattern Xs sYou implement operation take array n 2 le N le 5 qubit input apply unitary transformation matrix describe shape if multiple unitarie satisfy requirement implement the output operation pattern matrix coefficient implement testing harness UnitaryPatterns katayour code follow signaturenamespace Solution open MicrosoftQuantumPrimitive open MicrosoftQuantumCanon operation Solve qs Qubit Unit code | 0array
|
the number zero call love loeuf precise literally mean egg french example denote zero score game tennis aki fond number especially trail zero for example number 9200 trailing zero Aki think trail zero digit number pretty isHowever Aki believe number trail zero number static depend base radix represent thus consider scenario number basis and number bizarre ask help calculate beauty numbersgiven integer n b decimal notation task calculate number trail zero digit bary baseradix b representation n factorial n | 2string
|
there colony villain hole align row hole contain exactly villainEach colony arrangement express string length ith character string represent type villain ith hole Iron Man destroy colony colony arrangement villain certain type live half colony second half colonyHis assistant Jarvis special power it swap villain hole ie swap character stre operation number timesNow Iron Man ask Jarvis q question in question give Jarvis number x y Jarvis tell Iron Man number distinct colony arrangement create original power villain have type originally live xth hole yth hole live half Iron Man destroy colony arrangementtwo colony arrangement consider different exist hole different type villain present hole arrangement | 1graph
|
we know superhero transform certain superhero but Superheroes transform superhero a superhero s transform superhero t s equal t change vowel s vowel consonant s consonant multiple change madeIn problem consider letter e o u vowel letter consonantsGiven name superhero determine superhero s transform Superhero t | 1graph
|
let define eulerian traversal tree connect undirected graph cycle follow consider depthfirst search algorithm traverse vertex tree enumerate order visit visit vertex count this function start vertex number 1 recursively run vertex connect edge current vertex visit increase number order formally describe function follow pseudocodenext_id 1id array length n fill 1visited array length n fill falsefunction dfsv visitedv true idv next_id next_id 1 neighbor v increase order visitedto dfstoyou give weight tree vertex enumerate integer 1 n algorithm describe aboveA leaf vertex tree connect vertex in tree give vertex 1 leaf the distance vertex tree sum weight edge simple path themyou answer q query follow type give integer v l r find short distance vertex v leave indice l r inclusive | 2string
|
Grigory n magic stone conveniently number 1 n the charge ith stone equal c_isometime Grigory get bored select inner stone stone index 2 le le n 1 synchronize neighboring stone after choose stone lose charge acquire charge neighboring stone in word charge c_i change c_i c_i 1 c_i 1 c_iandrew grigorys friend n stone charge t_i Grigory curious exist sequence zero synchronization operation transform charge grigorys stone charge correspond Andrews stone change c_i t_i | 1graph
|
you give integer n n ge 0 represent k digits base radix b Son a_1 cdot bk1 a_2 cdot bk2 ldot a_k1 cdot b a_kFor example b17 k3 a11 15 7 n11cdot17215cdot177317925573441determine n odd | 1graph
|
read book Sashas passion once read book acquaint unusual character the character tell like many name country Mithrandir Elves Tharkûn dwarf Olórin I youth West forget South Incánus North Gandalf East I notand moment Sasha think character call East in East name palindrome a string palindrome read backward forward for example string kazak oo r palindrome string abb ij Sasha believe hero name god East as long could not equal name East people follow write original string piece paper cut paper minimum number time k get k1 piece paper substring initial string unite piece new string piece could not turn shuffledin way possible achive string abcdefg string fdeabcg 3 cut swap paper substring f abc the string cbadefg can not received cutsMore formally Sasha wants give palindrome s find minimum k cut string k 1 part unite way final string palindrome will not equal initial string s it answer print impossible quote | 2string
|
you give undirecte weight connect graph n vertex m edge loop multiple edgesthe ith edge e_i u_i v_i w_i distance vertex u_i v_i edge e_i w_i 1 le w_i the graph connect ie pair vertex path consist edge give grapha minimum span tree mst case positive weight subset edge connect weight undirected graph connect vertex minimum total cost subset total cost sum cost choose edgesyou modify give graph the operation perform follow increase weight edge 1 you increase weight edge multiple possibly zero timessuppose initial mst cost k your problem increase weight edge minimum possible number operation way cost MST obtain graph remain k MST unique mean way choose MST obtain graphyour problem calculate minimum number operation require | 1graph
|
you garland consist n lamp each lamp color red green blue the color ith lamp s_i r g b color lamp garlandyou recolor lamp garland recoloring lamp mean change initial color way obtain garland niceA garland call nice lamp color distance divisible Ie obtain garland t j t_i t_j satisfied ij mod 3 0 the value x mean absolute value x operation x mod y mean remainder x divide yFor example follow garland nice rgbrgbrg GB r grbgrbg brgbrgb the follow garland nice RR RGBGAmong way recolor initial garland nice choose minimum number recolore lamp if multiple optimal solution print | 2string
|
you give segment l_1 r_1 l_2 r_2 xaxis it guarantee l_1 r_1 l_2 r_2 segment intersect overlap coincide the example segment xaxis your problem find integer b l_1 le le r_1 l_2 le b le r_2 ne b in word choose distinct integer point way point belong segment l_1 r_1 second belong segment l_2 r_2it guarantee answer exist if multiple answer print themyou answer q independent query | 1graph
|
Vasya want buy nice new car unfortunately lack money currently exactly 0 burlesHowever local bank n credit offer each offer describe number a_i b_i k_i offer number 1 n if Vasya take ith offer bank give a_i burle begin month Vasya pay bank b_i burle end month k_i month include month activate offer Vasya offer order wantseach month Vasya credit offer also credit offer several credit active time it imply Vasya pay bank sum b_i active credit end monthVasya want buy car middle month he take money currently buy car exact pricevasya do not care hell pay bank buy car he go country car bank can not find anymorewhat maximum price car | 1graph
|
Lunar New Year approach Bob go receive red envelope countless money but collect money red envelope timeconsume process itselflet describe problem mathematical way consider timeline time 1 n the ith red envelope available time s_i t_i inclusive contain w_i coin if Bob choose collect coin ith red envelope integer point time s_i t_i inclusive can not collect envelope time d_i inclusive here s_i leq t_i leq d_i holdsBob greedy man collect coin greedily collect coin integer time x collect available red envelope maximum number coin if multiple envelope maximum number coin Bob choose parameter d large if multiple choice Bob choose randomlyhowever Alice daughter do not want father coin she disturb Bob m integer time moment if Alice decide disturb Bob time x time x resume usual strategy time x 1 inclusive lead miss red envelopescalculate minimum number coin Bob Alice disturb optimally | 1graph
|
Lunar New Year approach Bob planning famous restaurant AlicesThe restaurant alice serve n kind food the cost ith kind c_i initially restaurant ingredient serve exactly a_i dish ith kind in New Years Eve m customer visit Alices jth customer order d_j dish t_jth kind food the 1st customer come ith customer completely servedsuppose r_i dish ith kind remain initially r_i a_i when customer order 1 dish ith kind follow principle process if r_i 0 customer serve exactly 1 dish ith kind the cost dish c_i meanwhile r_i reduce 1 Otherwise customer serve 1 dish cheap available kind food if multiple cheap kind food small index cheap serve the cost cost dish serve remain correspond dish reduce 1 if dish customer leave angrily therefore matter dish serve previously cost customer 0if customer do not leave d_j dish serve cost customer sum cost d_j dishesplease determine total cost m customer | 2string
|
Hiasat register new account NeckoForces friend find ask use hiasat handleluckily Hiasat change handle point time also know exact moment friend visit profile page formally give sequence event type 1 Hiasat change handle 2 s friend s visit Hiasats profile the friend s happy time visit Hiasats profile handle sHiasat ask help find maximum possible number happy friend | 2string
|
Vasya favourite number n he want split nonzero digit it mean wants choose digit d_1 d_2 ldot d_k 1 leq d_i leq 9 d_1 d_2 ldot d_k nVasya like beauty wants find solution minimal possible number different digit d_1 d_2 ldot d_k help | 1graph
|
you give integer sequence 1 2 dot n you divide set a B way element belong exactly set suma sumB minimum possiblethe value x absolute value x sums sum element set S | 1graph
|
there n segment l_i r_i 1 le le n you divide segment nonempty group way pair segment different group common point impossible each segment belong exactly groupTo optimize testing process give multit | 1graph
|
an accordion string yes real world accordion musical instrument let forget represent concatenation open bracket ASCII code 091 colon ASCII code 058 possibly zero vertical line character ASCII code 124 colon closing bracket ASCII code 093 the length accordion number character itfor example accordion have length 4 6 7 accordion you give string s you want transform accordion remove possibly zero character note insert new character reorder exist one Is possible obtain accordion remove character s maximum possible length result | 1graph
|
Vasya big fish lover parent give aquarium New Year Vasya degree ichthyology think fill new aquarium eel good idea unfortunately eel predator Vasya decide find dangerous idea wasgetting aquarium eel fight exactly fish remain when eel fight big eat small weight equal eat namely let n eel initially aquarium ith weight x_i then n1 battle occur result eel survive in battle eel weight b le b eel weight eaten disappear aquarium eel weight b increase weight aba battle eel weight b le b consider dangerous b le 2 for give set eel danger define maximum number dangerous battle occur eel place aquariumNow Vasya planning eel want aquarium he set eel initially he make series operation set with operation add eel set remove eel set Vasya ask calculate danger current set eel operation | 1graph
|
all bus ticket Berland number a number consist n digit n only k decimal digit d_1 d_2 dot d_k form ticket number if 0 digits number lead zero for example n 4 digit 0 4 0000 4004 4440 valid ticket number 0002 00 44443 nota ticket lucky sum n 2 digit equal sum remain n 2 digits calculate number different lucky ticket Berland since answer big print modulo 998244353 | 0array
|
you give undirected graph consist n vertex a number write vertex number vertex a_i initially edge graphyou add edge graph pay the cost add edge vertex x y a_x a_y coin there m special offer denote number x y w mean add edge connect vertex x y pay w coin you do not use special offer pair vertex x y special offer associate connect vertex pay a_x a_y coin itwhat minimum number coin spend graph connect Recall graph connect possible vertex vertex edge belong graph | 2string
|
you give array n point kdimensional space let distance point a_x a_y sum limits_i 1k a_x a_y know Manhattan distanceYou process q query follow type 1 b_1 b_2 b_k set ith element point b_1 b_2 dots b_k 2 l r find maximum distance point a_i a_j l le j le r | 1graph
|
you give undirected unweighted graph consist n vertex m edgesyou write number vertex graph each number 1 2 3 the graph beautiful edge sum number vertice connect edge oddcalculate number possible way write number 1 2 3 vertex graph beautiful since number large print modulo 998244353note write exactly number vertexthe graph selfloop multiple edge | 1graph
|
Mishka got sixface dice it integer number 2 7 write face number face different usual dicemishka want exactly x point roll dice the number point sum number write topmost face dice roll Mishka makesmishka do not care number roll want know number roll able exactly x point Mishka lucky probability x point choose number roll nonzero able roll dice way your task print number it guarantee answer existsMishka curious different number point score answer t independent query | 2string
|
you give tree consist exactly n vertex Tree connect undirected graph n1 edge each vertex v tree value a_v assign itLet distx y distance vertex x y the distance vertex number edge simple path themlet define cost tree follow value firstly let fix vertex tree let v then cost tree sumlimits_i 1n disti v cdot a_iyour task calculate maximum possible cost tree choose v arbitrarily | 1graph
|
Ivan want play game he pick string s length n consist lowercase latin letter you do not know stre Ivan inform improper prefix suffix ie prefix suffix length 1 n1 do not tell string prefix suffixesIvan want guess give 2n2 string prefix give string suffix it impossible guess string Ivan pick multiple string set suffix prefix Ivan accept answer string consistent let game begin | 1graph
|
Bob duck he want alice nest duck duck ultimate animal image courtesy see Bang the journey represent straight line consist n segment Bob locate leave segment Alices nest right segment each segment length meter terrain type grass water lava Bob movement type swimming walk fly he switch change direction point time locate noninteger coordinate do not require extra time Bob swim water walk grass fly terrain flying meter take 1 second swimming meter take 3 second finally walk meter take 5 secondsBob finite energy call stamina Swimming walk relax gain 1 stamina meter walk swim on hand fly tiring spend 1 stamina meter fly stay place influence stamina of course stamina negative Initially stamina zerowhat short possible time reach Alices nest | 2string
|
let n integer consider permutation integer 1 n lexicographic order concatenate big sequence p for example n 3 p 1 2 3 1 3 2 2 1 3 2 3 1 3 1 2 3 2 1 the length sequence n cdot nLet 1 leq leq j leq n cdot n pair index we sequence p_i p_i1 dot p_j1 p_j subarray p its length define number element ie j 1 its sum sum element ie sum_kij p_k you give n find number subarray p length n have sum fracnn12 since number large output modulo 998244353 prime number | 1graph
|
there n house road Anya live paint k possible colorsAnya like walk road do not like adjacent house road color she want select long segment road adjacent house colorhelp Anya find long segment property | 2string
|
the kingdom Lazyland home n idler these idler incredibly lazy create problem ruler mighty King Lazyland Today k important job kingdom k le n perform every job person person job the King allow idle choose job want ith idler choose job a_i unfortunately job choose King persuade idler choose job the King know take b_i minute persuade ith idler he ask minister labour calculate minimum total time need spend persuade idler job can help | 2string
|
International Coding Procedures Company ICPC write code Jedi Script JS programming language JS compile deliver execution source form source contain comment extra whitespace include trail lead space nonessential feature large contribute semantic code process minification perform source file delivery execution compress source preserve semanticsyou hire ICPC write JS minifi ICPC fortunately ICPC adhere strict programming practice JS source restrict grammar they work integer algorithm use float point number string every JS source contain sequence line each line contain zero token separate space on line line start hash character code 35 include hash character treat comment ignore end lineeach line parse sequence token leave right repeatedly skip space find long possible token start current parse position transform source code sequence token all possible token list a reserve token kind operator separator literal reserve word library function preserve minification process Reserved token fix string nonspace ascii character contain hash character code 35 all reserve token give input minification process a number token consist sequence digits digit character zero 0 9 inclusive a word token consist sequence character follow set lowercase letter uppercase letter digit underscore _ code 95 dollar sign code 36 a word start digit Note parse long sequence character satisfie number word definition appear list reserve token consider reserve token insteaddure minification process word rename systematic fashion follow algorithm take list word consist lowercase letter order length lexicographically b z aa ab exclude reserve token consider word this target word list Rename word encounter input token sequence word target word list occurrence word input token sequence Rename second new word encounter input token sequence second word target word list the goal minification process convert give source short possible line counting space parse sequence token correspondingly rename word JS parse rule | 2string
|
petya collect beautiful matrixa matrix size n time n beautiful all element matrix integer 1 n for row matrix element row different for pair vertically adjacent element element different Today Petya buy beautiful matrix size n time n want determine raritythe rarity matrix index list beautiful matrix size n time n sort lexicographical order Matrix comparison row row the index lexicographically smallest matrix zerosince number beautiful matrix huge Petya want calculate rarity matrix modulo 998244353 | 1graph
|
Vasya like solve equation today want solve xmathrmdivk cdot x bmod k n mathrmdiv mathrmmod stand integer division modulo operation refer Notes exact definition in equation k n positive integer parameter x positive integer unknown if solution Vasya wants find smallest possible x can help | 1graph
|
polycarp love cipher he invent cipher call RightLeftRightLeft cipher string to encrypt string ss_1s_2 dot s_n Polycarp use follow algorithm write s_1 append current word s_2 ie write s_2 right current result prepend current word s_3 ie write s_3 leave current result append current word s_4 ie write s_4 right current result prepend current word s_5 ie write s_5 leave current result position end s for example stechno process t te cte cteh ncteh ncteho so encrypt stechno nctehogiven string t result encryption string s your task decrypt ie find string s | 1graph
|
a multisubject competition come the competition m different subject participant choose that s Alex coach form competition delegation student he n candidate for ith person know subject s_i candidate specialize r_i skill level specialization level negative the rule competition require delegation choose subset subject participate the restriction number student team participate choose subject sameAlex decide candidate participate subject specialize now Alex wonder choose maximize total sum skill level delegate skip competition year valid nonempty delegation negative sumOf course Alex do not spare money delegate choose participate competition | 1graph
|
sonya birthday recently she present matrix size ntime m consist lowercase latin letter we assume row number integer 1 n column number 1 m leave right Lets submatrix i_1 j_1 i_2 j_2 1leq i_1leq i_2leq n 1leq j_1leq j_2leq m element a_ij matrix i_1leq ileq i_2 j_1leq jleq j_2 Sonya state submatrix beautiful independently reorder character row column row column submatrix form palidrom Lets recall string call palindrome read leave right right leave for example string abacaba bcaacb palindrome string abca acbba ab notHelp Sonya find number beautiful submatrixe Submatrixes different element belong submatrix | 0array
|
the difference easy hard version constraintsVova like picture kitten the news feed social network use represent array n consecutive picture kitten course Vova like picture beautiful ith picture beauty a_iVova wants repost exactly x picture way segment news feed k consecutive picture picture reposte Vova sum beauty value reposte picture maximum possible for example k1 Vova repost picture news feed if k2 Vova skip picture pair consecutive picture Vova repost themYour task calculate maximum possible sum value reposte picture Vova follow condition describe way satisfy condition | 2string
|
consider follow game playersthere array b_1 b_2 b_k consist positive integer Initially chip place cell array b_1 decrease 1 Players turn each turn current player follow index cell chip currently place x choose index y x mink x m b_y 0 chip cell y decrease b_y 1 if impossible valid current player lose gameYour task follow give array consist n positive integer q query there type query 1 l r d l r increase a_i d 2 l r tell winner game play subarray index l index r inclusive Assume player choose optimal strategy | 1graph
|
you give undirecte connect weighted graph consist n vertex m edge Lets denote length short path vertex 1 vertex d_i you erase edge graph k edge remain Lets vertex good exist path 1 length d_i erase edgesyour goal erase edge way number good vertex maximize | 1graph
|