question
stringlengths
58
4.29k
label
class label
3 classes
let number kgood contain digit exceed k 0k you ve get number k array contain n number find kgood number count number time occur array
1graph
John Doe offer sister Jane Doe find gcd set number aGcd positive integer g number set evenly divisible g is not g gg number set evenly divisible gUnfortunately Jane could not cope task John offer find ghd subset numbersGhd positive integer g half number set evenly divisible g is not g gg half number set evenly divisible gJane cope task hour please try
1graph
there fence Polycarpuss home the fence consist n plank width leave right the height ith plank hi meter distinct plank distinct height Fence n7 h1261171 Polycarpus buy posh piano thinking house in order carry plan need exactly k consecutive plank fence high plank harder tear fence Polycarpus wants find k consecutive plank sum height minimal possiblewrite program find index k consecutive plank minimal total height pay attention fence Polycarpuss home home word fence is not cyclic
1graph
you hear Foolland Geography lesson specifically know federal structure country centurie the country consist n city pair city connect bidirectional road road describe length liThe fool live land joyfully recent revolution change king now king Vasily Bear Vasily divide country city region city region path road city different region do not path then Vasily decide upgrade road network construct exactly p new road country construct road go like we choose pair distinct city u v connect new road possible road city we define length new road city u v belong distinct region length calculate min109S1 S total length road exist link region assume length equal 1000 we build road specify length choose city if new road connect distinct region construction road region combine new region Vasily want road construct process result country consist exactly q region your task come road construct plan Vasily meet requirement minimize total length build road
2string
little boy Petya love stair but bored simple going loves jump stair time as stand stair jump jump stair time but stair dirty Petya do not want step themnow petya stair staircase consist n stair he know number dirty stair staircase Help Petya find jump entire staircase reach stair number n touch dirty stair onceone note Petya step stair stair dirty Petya choose path clean step
2string
Levko love string length n consist lowercase english letter he string s for stre t length n Levko define beauty relative s number pair index j 1ijn substring tij lexicographically large substring sijthe boy wonder string t beauty relative s equal exactly k Help find remainder division number 1000000007 1097A substre sij string ss1s2 sn stre sisi1 sjstring xx1x2 xp lexicographically large string yy1y2 yp number r rp x1y1x2y2 xryr xr1yr1 the string character compare ascii code
1graph
Seryozha changeable character this time refuse leave room Dima girlfriend hame Inna way however lovebird find way communicate today write text message otherDima Inna secret code text message when Dima wants send Inna sentence write word insert heart word word a heart sequence character character digit 3 after apply code test message look like 3word13word23 wordn3encoding do not end then Dima insert random number small english character digit sign place messageInna know Dima perfectly know phrase Dima going send Inna get text message help find Dima encode message correctly in word find text message receive encoding manner describe
1graph
when child tell puzzle bag coin anyway here version a horse bag the bag coin second bag coin bag coin in total horse coin bag how possible the answer simple the bag contain coin bag this problem generalization childhood puzzle you n bag you know bag contain a1 coin second bag contain a2 coin nth bag contain coin in total s coin find way arrange bag coin match describe scenario state impossible
1graph
a team student city S send AllBerland Olympiad Informatics traditionally train all student buy ticket carriage consist n compartment compartment exactly people we know compartment contain student bore compartment contain student compartment fun entire tripthe student want swap people compartment student bore student to swap place person need convince necessary the student independently find necessary argument ask sympathetic conductor help the conductor use life experience persuade passenger switch place studenthowever conductor want waste time persuade wrong people want know minimum number people necessary persuade change place student your task find number after swap compartment student leave company student
1graph
Valera get n domino piece row each piece consist half upper lower each half contain number 1 6 Valera love integer want sum number upper half sum number low half evento Valera rotate dominoe 180 degree after rotation upper low half swap place this action take second help Valera find minimum time spend rotate domino wish come true
1graph
Valera want prepare Codesecrof round he s get problem want set time limit TL itValera write n correct solution for correct solution know run time second Valera write m wrong solution wrong solution know run time secondslet suppose Valera set v second TL problem then solution pass system testing run time v second we solution pass system test extra time run time second inequality 2av holdsAs result Valera decide set v second TL follow condition meet v positive integer correct solution pass system testing correct solution pass system test extra time wrong solution pass system testing value v minimum tl point 1 2 3 4 hold help Valera find suitable TL state TL do not exist
0array
one day n friend gather play Mafia during round game player supervisor n1 people game for person know round want player supervisor ith person want play ai round what minimum number round Mafia game need play let person play round want
2string
in mathematic subsequence sequence derive sequence delete element change order remain element for example sequence BDF subsequence ABCDEF a substre string continuous subsequence string for example BCD substre ABCDEFYou give string s1 s2 string call virus your task find long common subsequence s1 s2 do not contain virus substre
1graph
you read scientific research popularity famous superstition country want analyze datum more specifically want know superstition popular countriesThe datum give single file follow format country separate line follow list superstition popular entry line each entry list format asterisk follow single space superstition Entries unique country the line input represent country the input contain superstition country nonempty sequence word word consist english letter the word country separate input spacessuperstition nonempty sequence word word consist english letter digit the word superstition separate input spacesyou consider name equal corresponding sequence word equal you should not consider case letter compare wordsOutput list superstition observe great number country its guarantee country distinct name
1graph
judge previous problem Friday 13th do not treat start think minimize impact life you passionate participant programming contest competition important schedule naturally you d like spoil possibleA friendly admin leak list date contest hold year ahead check happen place Friday 13th month
2string
Triskaidekaphobia fear number 13 ordinary people suffer phobia feel uncomfortable number 13 130 513 etc programmer fear step for example consider number 7 its ok write decimal write base 4 13 dreadful numberthe think bad look Number 100 13 notation contain 13 and number 13 infinite number notation luckily math binary completely safe nasty number but want able estimate level nastiness number your task give integer n find number different integer basis b b2 n write base b contain 13 Assume digits number basis large 10 write letter decimal number 30 base 16 1E 114 simply 114 please note 13 present substre notation subsequence 123 do not contain 13
1graph
mad scientist Mike apply job his task manage system water pump stationsthe system consist n pump station number integer 1 n some pair station connect bidirectional pipe water flow direction time for pipe know bandwidth maximum number liter water flow hour each pumping station pump incoming water station station pipe provide hour total influx water station equal total outflux water stationIt Mikes responsibility pump water station from station station b pipe possibly station hour transmit certain number liter water accord rule describe during time water station flow station flow station b however water flow station station b if total x litre water flow station hour Mike get x bollar salaryTo pay Mike need work n1 day accord contract on day select station v1 v2 hour pump certain water v1 v2 Next ith day Mike choose station vi1 select pump certain water station vi station vi1 hour the quantity water pump ith day depend water pump i1th daymike need earn bollar project help Mike find permutation station number v1 v2 vn Mike able earn high possible salary
1graph
Xenia programmer tree consist n node we consider tree node index 1 n we consider node initially paint red node paint blueThe distance tree node v u number edge short path v uXenia need learn quickly execute query type paint specify blue node red calculate red node close give print short distance close red node your task write program execute describe query
2string
a girl name Xenia cupboard look like arc ahead the arc semicircle radius r cupboard wall height h cupboard side the cupboard depth r look like rectangle base r height hr side the figure show cupboard look like view leave view right Xenia get lot balloon birthday the girl hate mess want store balloon cupboard Luckily balloon sphere radius help Xenia calculate maximum number balloon cupboard you balloon cupboard can not balloon leave right view the balloon cupboard touch it allow squeeze balloon deform way you assume cupboard wall negligibly thin
1graph
Iahub like background story hell tell exactly problem ask foryou give matrix n row n column initially value matrix zero both row column 1based row number 1 2 n column number 1 2 n Lets denote element ith row jth column aijwe submatrix x0y0x1y1 element aij inequality hold x0ix1 y0jy1Write program perform follow operation Queryx0 y0 x1 y1 print xor sum element submatrix x0y0x1y1 Updatex0 y0 x1 y1 v element submatrix x0y0x1y1 get xore value v
2string
Iahub recently learn Bubble Sort algorithm sort permutation n element a1 a2 ascend order he bore simple algorithm invent graph the graph let G initially n vertex 0 edge during bubble Sort execution edge appear describe follow algorithm pseudocode procedure bubbleSortGraph build graph G n vertex 0 edge repeat swap false 1 n 1 inclusive ai ai 1 add undirected edge G ai ai 1 swap ai ai 1 swap true end end swap repeat algorithm long swap value true end procedurefor graph independent set set vertex graph adjacent edge vertice independent set a maximum independent set independent set maximum cardinality give permutation find size maximum independent set graph G use permutation premutation procedure bubblesortgraph
1graph
Iahub draw set n point cartesian plane call special point a quadrilateral simple polygon selfintersection side call edge vertex call corner please note quadrilateral do not convex a special quadrilateral vertex set special point give set special point calculate maximal area special quadrilateral
1graph
Manao solve problem follow statement he come solution produce correct answer slow you give pseudocode solution function getanswer calculate answer problemgetAnswera1n b1len h answer 0 1 nlen1 answer answer faiilen1 b h 1 return answerfs1len b1len h index index len1 return 1 1 len sindex bi h mem bi bi 0 re fs b h index 1 bi mem re 0 return 1 return 0your task help Manao optimize algorithm
1graph
Paladin Manao catch trail ancient Book Evil swampy area this area contain n settlement number 1 n move swamp difficult people tramp exactly n1 path each path connect pair settlement bidirectional moreover possible reach settlement traverse pathsThe distance settlement minimum number path cross settlement Manao know Book Evil get damage range d this mean Book Evil locate settlement damage example emergence ghost werewolf affect settlement distance d settlement Book residesManao hear m settlement affect Book Evil their number p1p2pm note Book affect settlement detect Manao want determine settlement contain Book Help difficult task
2string
Manao monitor the screen monitor horizontal vertical length ratio ab now go watch movie the movie frame horizontal vertical length ratio cd Manao adjust view way movie preserve original frame ratio occupy space screen possible fit completely thus zoom movie Manao change frame proportionally dimensionscalculate ratio screen screen occupy movie total screen size Print answer irreducible fraction pq
2string
Vasily bear favorite rectangle vertex point 00 opposite vertex point xy of course side Vasyas favorite rectangle parallel coordinate axis Vasya love triangle triangle vertex point B00 that s today ask find point ax1y1 Cx2y2 follow condition hold coordinate point x1 x2 y1 y2 integer besides follow inequation hold x1x2 triangle form point A b c rectangular isoscele right point favorite rectangle locate inside border triangle ABC area triangle ABC small possible help bear find require point it hard proof point unique
1graph
gerald friend Pollard Pollard interest lucky ticket ticket sequence digit at thought ticket lucky digit add arithmetic sign bracket result obtain arithmetic expression number 100 but quickly analyze ticket move general question now explore klucky ticketspollard sais ticket klucky add arithmetic operation sign digit leave right ie bracket obtain correct arithmetic expression value equal k for example ticket 224201016 1000lucky 2242010161000pollard carry away lucky ticket sign seminar lucky ticket far Gerald know Pollard attend daily 7 pm famous institute commute tram m day in tram ticket digit and Gerald want surprise Pollard day Pollard receive tram klucky ticket the conductor agree Pollard certain ticket m day want Gerald tell kind ticket in regard help Gerald pick exactly m distinct klucky ticket
1graph
a student life fraught complication some Berland University student know having study year contract strong antipathy chairperson department indeed person question was not kind lady begin prone reform group ban automatic pass mean deed at student decide can not away anymorethe student pull string high level learn University director meet go discuss n order chairperson accept exactly p there value assign order ai number chairperson hair turn grey obeys order bi displeasement director order is not obey the student director pass p order choose the student know chairperson obey exactly k p order she pick order obey way minimize director displeasement second number hair head turn greyThe student want choose p order way maximize number hair chairperson head turn grey if multiple way accept order student keen maximize director displeasement chairperson action help
1graph
reform continue enter Berland for example yesterday sit Berland Parliament approve n law law assign unique number 1 n today law table President Berland GW Boosch signedthis time mr Boosch plan sign 2k law he decide choose exactly nonintersecte segment integer 1 n length k sign law number fall segment more formally mr Boosch going choose integer b 1abnk1bak sign law number lie segment aak1 bbk1 border includedAs mr Boosch choose law sign course consider public opinion Allberland Public Opinion Study Centre APOSC conduct opinion poll citizen process result report give president the report contain absurdity value law public opinion as mr Boosch real patriot keen signing law maximum total absurdity help
1graph
a country n city Initially road country one day king decide construct road connect pair city road traverse way he want road construct way possible city city traverse road you give m pair city road construct pair citiesyour task construct minimum number road satisfy condition the constraint guarantee possible
1graph
Iahub Iahubina go date luxury restaurant everything go fine pay food instead money waiter want Iahub write hungry sequence consist n integer a sequence a1 a2 consist n integer hungry its element increase order that inequality aiaj hold index ij ij for index j ij aj divisible ai Iahub trouble ask help find hungry sequence n element
0array
you give permutation p q consist n element m query form l1r1l2r2 l1r1l2r2 the response query number integer 1 n position permutation segment l1r1 border include position second permutation segment l2r2 border include tooa permutation n element sequence n distinct integer 1 great nPosition number v 1vn permutation g1g2gn number giv
2string
Fox Ciel board n row n column integer cellIts know n odd number let introduce Fox Ciel follow operation time choose subboard size x row x column number multiply 1return maximal sum number board operation
1graph
Fox Ciel robot 2D plane initially locate 0 0 Fox Ciel code command the command represent string s each character s operation there operation U x y x y1 D x y x y1 L leave x y x1 y R right x y x1 y the robot operation s leave right repeat infinite time help Fox Ciel determine step robot locate ab
1graph
in problem moment set interval you interval ab set interval cd set cad cbd also path interval I1 set interval i2 set sequence successive move start I1 reach I2Your program handle query follow type 1 x y xy add new interval xy set interval the length new interval guarantee strictly great previous interval 2 b ab answer question path ath onebase add interval bth onebase add interval answer query note initially set interval
2string
a substre string contiguous subsequence string so stre bca substre string abcabc string cc nota repeat block string form concatenate string so stre abcabc repeat block string abcabd ababab notYouve get sequence latin character stre at step find short substring repeat block exist choose leftmost as substre form XX x string replace substre x word delete x substring substre you repeat process remains repeat block string how final string look like Look sample explanation understand statement precise
1graph
volodya like listen heavy metal occasionally read no wonder volodya especially interested text concern favourite music styleVolodya call stre powerful start heavy end metal find powerful substring substre Volodya mean subsequence consecutive character string give text make hero especially joyful recently feel enormous fit energy read certain text So Volodya decide count powerful substring text brag day long help difficult task two substring consider different appear different position textfor simplicity let assume Volodyas text represent single string
1graph
it note ant junction graphene integer lattice act follow fashion minute junction x y contain ant group ant form ant scatter neighbouring junction x1 y x1 y x y1 x y1 ant direction no ant movement happen ant interfere otherscientist colony n ant junction 0 0 wish know ant give junction movement ant stop
2string
Smart Beaver recently get interested new word game the point follow count number distinct good substring string s to determine stre good game use rule overall n rule each rule describe group plr p string l r lr integer well string t complie rule plr number occurrence string t string p lie l r inclusive for example string ab complies rule ab 1 2 aab 0 1 comply rule cd 1 2 abab 0 1A substring sl r 1lrs string ss1s2 ss s length s string slsl1 srconsider number occurrence string t string p number pair integer lr 1lrp pl rtwell string t good complie n rule Smart Beaver ask help write program calculate number distinct good substring string s two substring sx y sz w cosidere distinct iff sx ysz w
1graph
Smart Beaver interest drawing he draw sun however point Smart Beaver realize simply draw sun boring so decide design program process drawing you give picture draw beaver it color background sun image your task count number sun image count number raysSun arbitrarily rotate ellipse ray Ray segment connect point boundary ellipse point outside ellipse an image sun circle an image sun ellipse axis parallel coordinate axis an image sun rotate ellipsis it guarantee no sun common point the ray width 3 pixel the length ellipsis sun axis lie 40 200 pixel no ray intersect the length ray lie 10 30 pixel
2string
by age Smart Beaver master arithmetic operation get summer homework amazed teacheryou give sequence integer a1a2an your task perform m consecutive operation follow type for give number xi vi assign value vi element axi for give number li ri you ve get calculate sum f0f11 i2 fifi1fi2 for group number li ri di increase value ax di x lixri Smart Beaver plan tour great canadian lake ask help solve give problem
1graph
by age Smart Beaver master arithmetic operation get summer homework amazed teacheryou give sequence integer a1a2an your task perform m consecutive operation follow type for give number xi vi assign value vi element axi for give number li ri you ve get calculate sum f0f11 i2 fifi1fi2 for group number li ri di increase value ax di x lixri Smart Beaver plan tour great canadian lake ask help solve give problem
1graph
in rush modern life people forget beautiful world the time enjoy little stand queue room time clinic run queue anothercultural note stand huge disorganized queue hour native tradition Russia date soviet period Queues resemble crowd line not lose queue person follow strict survival technique approach queue ask person somebody answer join crowd now you re person queue till somebody show you eye chance destination I m sure people problem stranger ask person queue dare hint queue bolt away unknown destination these representative modern world ratio lack time great watch foreign toprate tv series such people create problem queue newcomer person queue take place virtual link chain wonder legendary figure leftthe Smart Beaver ill he s appointment therapist the doctor tell Beaver sad news nutshell necessary electrocardiogram the day Smart Beaver get early famous tv series download hour till download complete clenched tooth bravely go join queue electrocardiogram room notorious big queue clinichaving stand hour queue Smart Beaver realize beaver see suppose stand queue huge mess he come beaver ECG room queue ask queue if beaver know correct position queue turn ECG maybe wait long long timeAs you ve guess Smart Beaver hurry home give necessary information help determine number queue
1graph
Sereja get array consist n integer a1a2an Sereja active boy go complete m operation each operation form make vith array element equal xi in word perform assignment avixi Increase array element yi in word perform n assignment aiaiyi 1 in Take piece paper write qith array element that element aqi help Sereja complete operation
2string
Sereja paint n point plane point number 1 in coordinate i0 then Sereja mark point small large english letter Sereja do not like letter x do not use mark point Sereja think point mark beautifully follow condition hold point divide pair point belong exactly pair pair point less abscissa mark small english letter point large abscissa mark large english letter build square pair pair point square opposite point segment square diagonal result square will not intersect touch one Little Petya erase small large letter mark point now Sereja wonder way return remove letter point mark beautifully
2string
everything great Ilyas city road the thing ZooVille road represent n hole row we consider hole number 1 n leave rightilya help city so want fix k hole perharps fix single ZooVille road the city m build company ith company need ci money unit fix road segment contain hole number li ri the company ZooVille greedy fix segment contain fix hole decrease price fixing segment determine minimum money Ilya need fix k hole
1graph
information technology develop increasingly penetrate sphere human activity incredible modern technology farmingA large farm meadow grazing sheep Overall n sheep contain unique number 1 n sheep need distinguished need remember information alike the meadow consist infinite number region number 1 infinity its know sheep like region li riThere shepherd take care sheep First Second First wake early morning lead sheep graze lawn Second come evening collect sheepone morning First wake little later usual time lead sheep graze lawn so tie sheep region like First think well second work evening sheep will not scatter tie otherin evening Second come lawn gather sheep try line row but try sheep would not line second want second strength ability untie sheep leave condition want line sheep maximum distance tie sheep small possible the distance sheep number sheep rank twohelp second find right arrangement
1graph
Polycarpus love convex polygon especially angle side different Draw polygon give number vertex
1graph
Polycarpus sure life fit description white stripe black white so Polycarpus sure rule go fulfill n day Polycarpus know w good event b notsogood event at event go place day as day unequivocally characterize white black stripe day go event type ether good notsogoodwhat number distinct way scenario develop n day Polycarpus white stripe stripe good event stripe length 1 day black stripe stripe notsogood event stripe length 1 day white stripe stripe good event stripe length 1 day each n day belong stripe onlyNote event type distinct even event occur day order simultaneous eventsWrite code print number possible configuration sort event day see sample clarification scenario consider distinct Print answer modulo 1000000009 1099
1graph
Bike interested permutation a permutation length n integer sequence integer 0 n1 appear exactly for example 021 permutation length 3 022 123 nota permutation triple permutation length n abc call Lucky Permutation triple the sign ai denote ith element permutation the modular equality describe denote remainder divide aibi n divide ci n equalnow integer n wants find Lucky Permutation Triple could help
1graph
Vitaly array n distinct integer Vitaly want divide array nonempty set follow condition hold the product number set zero 0 the product number second set great zero 0 the product number set equal zero each number initial array occur exactly set Help Vitaly Divide give array
0array
polar bear like unique array array repeat element you get unique array s length n contain nonnegative integer since good friend Alice Bob decide split array precisely need construct array b length n follow condition 1 in aibi nonnegative integer siaibi ideally b unique array however life Arctic hard possible Fortunately Alice Bob happy array unique we define array length n unique turn unique array remove entriesFor example array 12132 unique remove entry 132 the array 121312 unique need remove 3 entry turn unique arraySo task split give unique array s unique array b
2string
Greg pad the pad screen nm rectangle cell black white well consider pad row number integer 1 n similarly pad column number integer 1 m leave rightgreg think pad screen display cave follow condition hold there segment lr 1lrn row ll1r exactly black cell row white cell there row number t ltr pair row number j lijt set column black cell row column black cell subset set column black cell row j column black cell similarly pair row number j tijr set column black cell row j column black cell subset set column black cell row column black cell Greg wonder way paint cave pad two way consider distinct cell distinct color pictureshelp Greg
1graph
Greg array aa1a2an m operation each operation look li ri di 1lirin to apply operation array mean increase array element number lili1ri value diGreg write k query piece paper each query follow form xi yi 1xiyim that mean apply operation number xixi1yi arrayNow Greg wonder array query execute help Greg
1graph
there n light align row these light number 1 n leave right Initially light switch Shaass want switch light at step switch light light switch moment there s adjacent light switch he know initial state light he s wonder different way exist switch light please find require number way modulo 10000000071097
2string
Shaass n book he want bookshelf book he want bookshelfs dimensions small possible the thickness ith book ti page width equal wi the thickness book 1 2 all book page height Shaass put book bookshelf follow way First select book vertically then put rest book horizontally vertical book the sum width horizontal book total thickness vertical book a sample arrangement book depict figure help Shaass find minimum total thickness vertical book achieve
1graph
Yaroslav Andrey Roman love playing cube sometimes play cube hour hour today get play cube Yaroslav take unit cube compose aaa cube Andrey bbb cube roman ccc cube after game finish guy leave but later Vitaly enter room he see cube want cube but size cube of course large cube length abc besides Vitaly decide decompose cube build Yaroslav Andrey Roman compose large cube however turn unit cube get destroy cube were not large cube we know Vitaly short exactly n cube Vitaly got upset demolish left as leave meet Petya tell cubes room need n unit cube large cubePetya enter room see messily scatter cube he want neat orderly but know cubes small unit cube Vitaly need n unit cube large help Petya understand way size b c restore Yaroslavs Andreys Romans cube
1graph
the problem use simplify TCPIP address model read statement carefullyAn IP address 32bit integer represent group decimal 8bit integer lead zero separate comma for example record 02551123 show correct IP address record 02561123 0255101 in give problem arbitrary group 8bit integer correct IP addressour hero Polycarpus work system administrator large corporation he like beautiful IP address to check IP address beautiful follow write line 8bit number IP address commas check result string palindrome let remind palindrome string read right leave leave rightfor example IP address 1210220121 0314130 beautiful string 1210220121 0314130 palindrome IP address 120201 100441 notPolycarpus want find beautiful IP address give set digit each digit set occur IP address IP address contain digit help cope difficult task
2string
some large corporation Polycarpus work short message service center smsc the center task send sort crucial information Polycarpus decide check efficiency smsc for ask statistic performance smsc period time in end Polycarpus get list n task go smsc corporation each task describe time receive smsc number text message send More formally ith task describe integer ti ci receive time second number text message correspondinglypolycarpus know SMSC send text message second the SMSC use queue organize work consider time moment x smsc work moment follow if time moment x queue SMSC send message queue smsc get message head queue Otherwise do not send message time moment x if time moment x SMSC receive task add queue message task SMSC add message tail queue note message task send time moment x that s decision send message point 1 add message queue give information n task Polycarpus want count value time text message send maximum size queue time Help count characteristic need evaluate efficiency SMSC
1graph
the problem describe property command line the description resemble usually real operating system however difference behavior please sure you ve read statement attentively use formal documentIn Pindows operating system string lexeme command line understand program run follow lexeme argument for example execute command runexe lexeme Pindows command line runexe more formally run command represent string s quote command line lexeme maximal inclusion substring string s contain spacesto send string space string command line lexeme use double quote the block character consider lexeme go inside quote embed quote prohibit occurrence character able clearly quote open closing for example run command runexe o ne lexemes Pindows command line runexe o string ne single spaceIt guarantee lexeme command line surround space side touch correspond command border one consequence open bracket character string space leave themyou string consist uppercase lowercase English letter digit character space it guarantee string correct os pindow command line string Print lexeme command line string consider character order denote single block character command line lexeme in particular consequence give string get number character
2string
petya unexperienced programming contestant recently come follow problemyou give nondirected graph consist n node m edge your task determine graph contain hamiltonian pathPetya write quick bugfree code believe solve problem after Petya decide problem April Fools Day contest unfortunately Petya mistake possible algorithm wrong but is not good excuse leave contest submit problem
1graph
little penguin Polo get tree nondirecte connected acyclic graph contain n node n1 edge we consider tree node number integer 1 nToday Polo wonder find number pair path do not common node more formally find number group integer abc d 1abn 1cdn there s node lie short path node node b node c node d the short path betweem node path short number edgeshelp Polo solve problem
1graph
little penguin Polo adore string but adore string length nOne day want find string meet follow condition the string consist n lowercase english letter string length equal n exactly k letter distinct no neighbouring letter string coincide represent string ss1s2 sn follow inequality hold sisi11 in among string meet point 1 2 require string lexicographically small help find string state string do not existstre xx1x2 xp lexicographically string yy1y2 yq pq x1y1x2y2 xpyp number r rprq x1y1x2y2 xryr xr1yr1 the character string compare ascii code
2string
in city Ultima Thule job applicant offer iq test the test follow person get piece square paper 44 square paint some square cell paint black paint white your task repaint cell color picture 22 square completely consist cell color if initial picture square person test complete your task write program determine possible pass test you pass test repaint cell action do not result 22 square consist cell color
2string
permutation p order set integer p1p2pn consist n distinct positive integer do not exceed n well denote ith element permutation p pi well number n size length permutation p1p2pnwell position 1 in permutation p1p2pn good pii1 Count number permutation size n exactly k good position print answer modulo 1000000007 1097
1graph
bessie cow play sequence need help they start sequence initially contain number 0 perform n operation each operation follow Add integer xi ai element sequence Append integer ki end sequence and size sequence increase 1 remove element sequence so size sequence decrease note operation element sequence after operation cow like know average number sequence help
1graph
the classic programming language Bitland bit this language peculiar complicatedthe language peculiar exactly variable call x also operation operation increase value variable x 1 operation decrease value variable x 1 a statement language bit sequence consist exactly operation variable x the statement write space contain character X executing statement mean apply operation containsa programme bit sequence statement need execute executing programme mean execute statement containsyoure give programme language Bit the initial value x 0 Execute programme find final value value variable programme execute
1graph
you give positive integer xyn your task find near fraction fraction denominator n formally find pair integer ab 1bn0a value minimal possibleif multiple near fraction choose minimum denominator if multiple near fraction minimum denominator choose minimum numerator
1graph
a root tree direct acyclic graph contain node root exactly path nodeA root tree binary node outgoing arcsWhen binary tree paint plane arc direct that arc go u v meet condition yuyvYouve give coordinate tree nod your task connect nod arcs binary root tree total length arc minimum all arc build tree direct
1graph
imagine nm grid block cell the left cell grid coordinate 11 right cell coordinate nm there k block cell grid you flash laser beam center cell xsys diagonal direction ie northeast northw southeast southwest if beam hit block cell border grid reflect the behavior beam reflection different situation depict figure after beam enter infinite cycle Count number cell beam go we consider beam go cell go center
0array
Dima come horse land there n horse live land each horse horse land enemy enmity symmetric relationship the horse land is not hostile number enemy horse 3right horse land go election campaign so horse trust Dima split part at horse want follow condition hold horse should not enemy partyhelp Dima split horse party note party turn
2string
you ve get string s consist small english letter some english letter good rest bada substre slr 1lrs string ss1s2ss s length string s string slsl1srthe substre slr good letter slsl1sr k bad one look sample explanation understand clearyour task find number distinct good substring give stre s two substring sxy spq consider distinct content different ie sxyspq
1graph
it like year 2013 come yesterday do know curious fact the year 2013 year old 1987 distinct digitsNow suggest solve follow problem give year number find minimum year number strictly large give distinct digit
1graph
Emuskald innovative musician try push boundary music production now come idea revolutionary musical instrument rectangular harpA rectangular harp rectangle nm consist n row m column the row number 1 n similarly column number 1 m leave right string pin space evenly unit thus n pin leave right side harp m pin the harp exactly nm different string string connect different pin different harpEmuskald order apprentice construct rectangular harp however do not mention string cross impossible play harp two string cross segment connect pin intersect to fix harp Emuskald perform operation type pick different column swap pin harp change pin connect string pick different row swap pin harp change pin connect string in follow example fix harp swap column help Emuskald complete creation find permutation row column harp need rearrange tell impossible he detach reattach string pin physical layout string do not matter
2string
Emuskald hire design artificial waterfall accord late trend landscape architecture a modern artificial waterfall consist multiple horizontal panel affix wide flat wall the water flow wall panel panel reach wallThe wall height t n panel wall each panel horizontal segment height hi begin li end ri the ith panel connect point lihi rihi plane the wall consider panel connect point 109 t 109 t similarly wall consider panel connect point 1090 1090 no panel share common pointEmuskald know waterfall aesthetically pleasing flow panel panel j follow condition hold maxliljminrirj horizontal projection panel overlap hjhi panel j panel panel k hjhkhi condition hold pair ik kj then flow equal minrirjmaxlilj length horizontal projection overlapEmuskald decide waterfall water flow single path if water flow panel wall water fall exactly low panel the total water flow waterfall define minimum horizontal projection overlap consecutive panel path waterfall Formally waterfall consist single path panel flow waterfall minimum flow path to truly great waterfall Emuskald maximize water flow panel have hard time planning creation below example waterfall Emuskald want help Emuskald maintain reputation find value maximum possible water flow
1graph
manaos friend send new song he listen right away instead compile playlist when feel mind open new music open playlist start listen songsOf course song Manao do not particuarly enjoy to pleasure receive song invent follow procedure listening playlist if listen song Manao realize like remember start listen unlistened song if listening song Manao realize like listen song like point begins listen unlistened song for example Manao song playlist a b c d correspond order go like song a C end order listening follow Manao listen a like remember Manao listen b like listen a Manao listen C like song remember Manao listen D enjoy relisten song a c that end Manao listen song a time song C twice song b D note Manao like song dislike subsequent listeningManao receive n song ith li seconds long Manao like probability pi percent the song Manaos playlist order Manao want know maximum expect value number second listening process possible permutation song playlist
1graph
Berland traffic different traffic country the capital Berland consist n junction m road each road connect pair junction there multiple road pair junction for road know capacity value ci maximum number car drive road direction unit time for road car drive direction that car can not simultaneously direction a road traffic number car go unit time for road aibi value negative traffic move bi ai a road traffic noninteger numberThe capital special junction entrance city junction 1 exit city junction n for junction true traffic lose that junction 1 n incoming traffic sum equal outgoing traffic sumtraffic unusual peculiarity capital Berland pair junction xy sum traffic path x y do not change depend choice path such sum include traffic road path possible minus sign traffic road direct direction road path x yyour task find large traffic pass trough city unit time correspond traffic road
2string
you ve get number as long large zero operation subtract less number large if equal substract number for example operation transform pair 417 pair 413 transform 55 05youve get number pair aibi how operation perform
1graph
during break schoolchildren boy girl form queue n people canteen Initially child stand order enter canteen however boy start feel awkward stand girl queue start let girl forward second Lets describe process precisely Lets position queue sequentially number integer 1 n person position number 1 serve then time x boy stand ith position girl stand i1th position time x1 ith position girl i1th position boy the time give secondsYouve get initial position child initial moment time determine way queue go look t second
2string
Squirrel Liss love nuts there n tree number 1 n west east street delicious nut tree the height tree hi Liss want eat nutsnow Liss root tree number 1 in second Liss perform follow action Walk unit tree eat nut current tree jump tree in action height Liss do not change more formally Liss height h tree 1in1 jump height h tree i1 this action can not perform hhi1 Compute minimal time second require eat nut
1graph
Squirrel Liss love nuts Liss ask plant nut treesThere n position number 1 n west east plant tree street tree grow meter month at beginning month process query the query follow type Plant tree height h position p Cut xth existent cut tree west x 1indexed when cut tree drop take available place position stand so tree plant position anymore after process query print length long increase subsequence a subset existent tree call increase subsequence height tree set strictly increase west east example westmost tree set shortest set the length increase subsequence number tree itnote Liss do not like tree height guarantee time tree exactly height
1graph
one day Vasya come blackboard write n distinct integer 1 n order circle then draw arcs join pair integers ab ab immediate neighbor circle number c с immediate neighbor b c immediate neighbor as easily deduce end Vasya draw 2n arcsfor example number write circle order 12345 clockwise direction arc join pair integer 12 23 34 45 51 13 24 35 41 52much time pass number wipe blackboard long ago recently Vasya find piece paper 2n write pair integer join arcs board Vasya ask find order number circle pair
1graph
Roma work company sell tv now prepare report yearRoma get list company income the list sequence consist n integer the total income company sum integer sequence Roma decide perform exactly k change sign number sequence he change sign number timesthe operation change number sign operation multiply number 1help Roma perform change total income company sum number result sequence maximum Note Roma perform exactly k change
2string
Maxim get calculator the calculator integer cell Initially cell contain number 1 second cell contain number 0 in perform follow operation Lets assume current time cell contain number second cell contain number b write second cell number b1 Lets assume current time cell contain number second cell contain number b Write cell number ab Maxim wonder integer x lxr write number x cell calculator having perform p move
2string
the board got paint tree graph consist n node let remind nondirected graph call tree connect do not contain cyclesEach node graph paint black white manner are not node color connect edge each edge contain value write nonnegative integerA bad boy Vasya come board write number sv near node v sum value edges incident node Then Vasya remove edge value boardYour task restore original tree node color number sv
1graph
the mfloor m1 office international corporation CodeForces advanced elevator control system establish it work followsall office floor sequentially number integer 1 m at time t0 elevator floor elevator wait elevator floor Next time ti ti0 people come elevator for simplicity assume person use elevator report interval for person know parameter time person come elevator floor person initially floor want goThe movement elevator floor follow at time t t0 t integer elevator floor first elevator release people elevator want current floor then let people wait elevator floor if person come elevator exactly time t time we assume action go elevator instantly after elevator decide way time t1 elevator gets select floorThe elevator select direction move follow algorithm if elevator current time wait elevator floor elevator remain current floor Otherwise let assume elevator floor number x 1xm then elevator calculate direction priority pup pdown pup sum number people wait elevator floor number great x number people elevator want floor number great x pdown sum number people wait elevator floor number x number people elevator want floor number x if puppdown elevator go floor current floor x floor x1 elevator go floor current floor x floor x1 your task simulate work elevator person tell time elevator floor person need please note elevator large accommodate people
1graph
little Maxim love interesting problem he decide share problem Initially array consist n zero the element array index start 1 then follow query change array each query characterize integer viti in answer query vith array element equal ti aviti1vinMaxim think pair integer xy good Maxim think array consist n integer lucky integer 1in1 pair integer aiai1 good Note order number pair important specifically 1221after query change array Maxim wants know way replace zeroes array integer result array zero lucky of course distinct zero replace distinct integersmaxim tell sequence query pair integer consider lucky help Maxim solve problem
1graph
there n people sit line table for person know tell truth lieslittle Serge ask tell truth each people table know honest person liar people table the honest people go correct answer liar go integer 1 n correct answer every liar choose answer regardless liar distinct liar distinct answerSerge know information people answer question he take piece paper write n integer a1a2an ai answer ith person row give sequence Serge determine exactly k people sit table apparently lieSerge wonder variant people answer sequence answer length n exactly k people sit table apparently lie as describe variant answer count remainder dividing number variant 777777777
1graph
one day Vasya physics practical perform task measure capacitance he follow teacher advice n measurement record result notebook after result teacher remember lesson teacher friend Petya redo experiment large small result differ time Vasya lazy want redo experiment he want task home play computer game so decide cheat Vasya show measurement teacher erase large small result remain measurement differ time in word remain measurement smallest result x large result y inequality y2x fulfill of course avoid teacher suspicion Vasya wants remove measurement result possible notesHelp Vasya find minimum number measurement result erase note large small remain result measurement differ time
1graph
an ipv6address 128bit number for convenience number record block 16 bit hexadecimal record block separate colon 8 block total block hexadecimal digit here example correct record ipv6 address 0124567890abcdef0124567890abcdef well format recording ipv6address fullbeside record ipv6 address short record format the record ipv6 address shorten remove lead zero begin block however block contain digit short format for example lead zero remove like a56f00d3000001240001f19a10000000 a56fd30012401f19a100000 there way shorten zeroes ipv6 addresssome ipv6 address contain long sequence zero Continuous sequence 16bit zero block shorten a sequence consist consecutive block 16 bit equal 0 you example zero block shortening a56f00d3000001240001000000000000 a56f00d3000001240001 a56f0000000001240001000012340ff0 a56f01240001000012340ff0 a56f0000000000000001000012340ff0 a56f000000000001000012340ff0 a56f00d3000001240001000000000000 a56f00d30000012400010000 00000000000000000000000000000000 it allow shorten zero block address this mean short record can not contain sequence character otherwise impossible determine number zero block represent double colonthe format record ipv6 address remove lead zero shortening zero block call shortYouve get short record ipv6 address Restore record
0array
Chilly Willy love play number he know prime number digit these number 2 3 5 7 but Willy grow bored number come game connect themChilly Willy wants find minimum number length n simultaneously divisible number Willy know 2 3 5 7 help thatA number length number digit decimal representation lead zero
2string
little boy Valera study algorithm sort integer array after study theory go practical task as result write program sort array n integer a1a2an nondecrease order the pseudocode program write Valera give the input program get number n array aloop integer variable 1 n1loop integer variable j n1if ajaj1 swap value element aj aj1but Valera mistake have not fully learn sort algorithm if Valera mistake program need counterexample make program work improperly example make program sort array nondecrease order if example give value n do not exist print 1
1graph
you ve get list program warning log each record log stream string format 2012mmdd HHMMSSMESSAGE quote String MESSAGE consist space uppercase lowercase english letter character String 2012MMDD determine correct date year 2012 String HHMMSS determine correct time 24 hour formatthe describe record log stream mean certain time record get program warning string MESSAGE contain warning descriptionyour task print moment time number warning n second m
1graph
two pirate Polycarpus Vasily play interesting game they n chest coin chest number integer 1 n chest number ai coin Polycarpus Vasily turn Polycarpus move during player allow choose positive integer x 2x1n coin chest number x 2x 2x1 it turn chest coin case player do not coin chest the game finish chest emptiedpolycarpus is not greedy scrooge Polycarpys lazy slob so wonder minimum number move game finish help Polycarpus determine minimum number move game finish Note Polycarpus count move count Vasilys move
2string
Vasya active internet user one day come internet resource like write address notebook we know address write resource format protocoldomainrucontext protocol equal http quote ftp quote domain nonempty string consist lowercase English letter context present if present context nonempty string consist lowercase english letter if string context is not present address additional character is not write thus address character one domain extra contextwhen boy come home find address write notebook punctuation mark Vasya lot hurry do not write character help Vasya restore possible address record internet resource
1graph
let consider nn square matrix consist digit zerowell consider matrix good meet follow condition row matrix one group that row matrix look like 000011110000 simply consist zero onesyou give matrix size nn consist zeroes one your task determine good matrix b rearrange column
1graph
you ve get array consist n integer a1a2an you allow perform operation array Calculate sum current array element segment lr count value alal1ar Apply xor operation give number x array element segment lr execute this operation change exactly rl1 array element expression mean apply bitwise xor operation number x y the give operation exist modern programming language example language C Java mark Pascal xorYouve get list m operation indicate type your task perform give operation sum query print result
2string
the black king stand chess field consist 109 row 109 column we consider row field number integer 1 109 the column similarly number integer 1 109 leave right we denote cell field locate ith row jth column ijYou know square give chess field allow all allow cell chess field give n segment each segment describe integer riaibi aibi denote cell column number ai number bi inclusive rith row allowedyour task find minimum number move king need square x0y0 square x1y1 provide move allow cell in word king locate allow cell waylet remind chess king neighboring cell two cell chess field consider neighboring share point
1graph
the Old City rectangular city represent mn grid block this city contain building straight twoway street junction each junction building exactly block all street width block vertical horizontal There junction side street we block adjacent share common no block different street adjacent junction adjacent there annual festival the Old Peykan follow special path city this path start block street continue junction end block street for street block know time take Old Peykan block adjacent block also Old Peykan junction adjacent street block minute of course Old Peykan can not build blocksWe know initial position Old Peykan sequence junction pass reach destination after pass junction reach destination stay forever your task find Old Peykan k minute start move consider the Old Peykan follow short path pass give sequence junction reach destinationnote Old Peykan visit block
2string
you sequence n distinct integer a1a2an 1ain you want remove integer way result sequence integer satisfie follow condition result sequence exclusive xor operation integer result sequence equal 0 write integer result sequence begin end row decimal numeral system space write number divisible p you give sequence n integer prime number p find way satisfy describe condition
1graph