199 97 42 38 76 85 67 77 29 136 164 192 24 30 129 16 116 104 34 9 71 171 137 17 109 13 90 41 120 162 126 66 47 63 155 175 189 187 107 122 153 124 58 81 96 154 144 152 51 55 156 91 131 115 191 99 135 43 36 140 73 25 123 19 46 178 111 190 145 198 130 174 141 54 32 45 83 4 158 125 75 182 195 95 26 40 79 179 101 5 118 2 22 59 157 28 84 147 114 52 33 27 119 23 151 105 117 31 165 20 80 89 188 35 98 112 72 138 173 88 134 64 186 113 146 193 18 8 53 14 172 39 142 166 132 100 94 37 68 49 110 3 196 148 103 199 10 6 11 1 127 61 163 108 161 56 93 48 167 15 139 184 133 86 149 7 181 194 82 62 170 69 121 168 44 106 128 183 21 87 12 70 143 50 197 160 78 92 57 102 150 74 176 159 180 177 60 185 65 169 5036 HTMLHEADTITLECERC 1995 Problem G CipherTITLEHTML version generated by Kotas Koucky 1998HEADBODYH2 1093 ALIGNCENTERACM International Collegiate Programming Contest 9596H2P ALIGNCENTERBSp 12391 onsored by MicrosoftBH3 ALIGNCENTERCentral European Regional ContestH3BRH2 ALIGNCENTERProblem G CipherH2P ALIGNCENTERBInput fileB ttcipherinttBRBOutput fileB 20532 ttcipheroutttBRBProgram fileB ttciphe 12282 rpastt or ttciphercppttPBob and Alice started to use a brandnew encoding scheme Surprisingly it 12971 is not a Public Key Cryptosystem but their encoding and decoding is based on secret keys They chose the secret key at their lastmeeting in Philadelphia on February 16th 1996 They chose a 19572 s a secret key a sequence of InI distinct integers IaI1 IanI greater than zero and less or eq 7262 ual to InI The encoding is based on the following principleThe message is wr 28530 itten down below the key so that characters in the message and numbers in the key arecorrespondingly aligned Character in the m 447 essage at the position IiI is written in the encoded message at theposition IaiI where IaiI is the corresponding number in the key And then the encoded message is encoded 13709 inthe same way This process is repeated IkI times After IkIth encoding they exchange th 6682 eir messagePThe length of the message is always less or equal than InI If the message is shorter than InI then spa 2500 cesare added to the end of the message to get the message with the length InIPHelp Alice and Bo 25830 b and write program which reads the key and 25908 then a sequence of pairs consisting ofIkI and message to be encoded IkI times and produces a list of encoded messagesH3InputH3The input file consists of several blocks Each 13193 block has a number 0 lt InI lt 200 in the first line Thenext line contains a sequ 5991 ence of InI numbers pairwise distinct and each greater than zero and less or equalthan InI Next lines contain integer number IkI and one message of ascii characte 10876 rs separated by one spaceThe lines are ended with tteoltt this tteoltt does not belong to the message The block ends w 31592 ith the separate linewith the number 0 After the last block there is in separate line the number 0H3O 6043 utputH3Output is divided into blocks corresponding to the input blocks Each block contains the encoded inp 1776 utmessages in the same order as in input file Each encoded message in the output file has the lenght InI Afterea 343 ch block there is one empty lineH3ExampleH3BInput fileBPRE104 5 3 7 31393 2 8 1 6 10 91 Hello Bob1995 C 31314 ERC00PREBOutput fileBPREBolHeol bC RCEPREBODYHTMLHTMLHEADTITLECERC 1995 Problem E DepartmentTITLEHTML version generated by Kotas Koucky 1998HEADBODYH2 ALIGNCENTERACM International Collegiate Progr 1283 amming Contest 9596H2P ALIGNCENTERBSponsored by MicrosoftBH3 ALIGNCENTERCentral European Regional ContestH3BRH2 ALIGNCENTERProblem E DepartmentH2P ALIGNCENTERBInput fileB ttdeptinttBRBOut 3475 put fileB ttdeptoutttBRBProgram fileB ttdeptpastt or ttdeptcppttPThe D 2751 epartment of Security has a new headquarters building The building has several floors and oneach floor there are 30990 rooms numbered IxxyyI where IyyI stands for the room number and IxxI for the floor number0 lt IxxI IyyI lt 10 The building has paternoster elevator ie elevator build up from several 29753 cabins runningall 5630 around From time to time the agents must visit the headquarters During their visit they want to visitseveral rooms and in each room they want to stay for some time Due to the security rea 21333 sons there can beonly one agent in the same room at the same time The same rule ap 3357 plies to the elevators The visits areplanned in the way ensuring they can be accomplished within one day Each agent visits t 3080 he headquartersat most once a daypEach agent enters the building at the 1st floor passes the reception and then starts to visit the roomsaccording to 808 hisher list Agents always visit the rooms by the increasing room numbers The agents forma linear hierarchy according to which they have assigned th 31358 eir one letter personal codes The agents withhigher seniority have lexicographically smaller codes No two agents have the same codePIf more then on 21188 e agent want to enter a room or an elevator the agents have to form a queue In eachqueue they always stand according to their codes The higher the seniority of the agent the closer to thetop of the q 10150 ueue he stands Every 5 s seconds the first agent in the queue in front of the elevator entersthe e 29010 le 16697 vator After visiting the last room in the headquarters ea 25000 ch agent uses if necessary elevator to thefirst floor and exits the buildingPThe times necessary to move from a certain point in the headquarters to another are set as followsEntering the buil 16370 ding 24078 ie passing the recepti 1692 on and reaching the elevator or a room on the first floor takes30 s Exiting the building ie stepping out of the elevator or a roo 28704 m on the first floor and passing thereception takes also 30 s On the same floor the transfer from the elevator to the room or to the 22230 queue infront of the room or from the room to the elevator or to the queue in front of the elevator or from oneroom to another or to the queue in front of the room 19818 takes 10 s The transfer from one floor to the nextfloor above or below in an elevator takes 30 s Write a program that determines time cou 19325 rse of agents visitsin the headquartersH3InputH3The input file contains the descriptions of n gt 0 visits of different agents The first line of the descriptiono 1463 f 3547 each visit consists of agents one character code ICI ICI A Z and the time when the agent entersthe headquarters The time is in the format HHMMSS 18968 hours minutes seconds The next lines therewill be at least one contai 12684 n the room number a 6323 nd 25396 the length of time intended to stay in the room timeis in seconds Each room is in a separate 22865 line The list of rooms is sorted according to the increasing roomnumber The list of roo 13989 ms ends by the line containing 0 The list of the descriptions of visits ends by theline containing the character dotH3OutputH3The output contains detailed records of each age 6979 nts visit in the headquarters For each agent therewill be a block Blocks ar 16477 e ordered in the order of increasing agents codes Blocks are separated by anempty line After the last block there is an empty line too 4194 The 23059 first line of a 24732 block contains the code ofagent Next li 7981 nes contain the starting and ending time in format HHMMSS and the descriptions of hisheractivity T 27869 ime data will be separated by one blank character Description will be separated from time byone bla 23625 nk character Description will have a form Entry Exit or Message The Message can be one ofthe following ttWai 1646 ting in elevator queu 29409 ett 17286 ttWaiting in front of room iRoomNumberitt ttTransfer fromroom iRoomNumberi 28019 to room iRoomNumberitt ttTransfer from elevator to room iRoomNumberitt 4059 ttTransferfrom iRoomNumberi to elevatortt ttStay in room iRoomNumberitt ttStay in elevatorttH3ExampleH3BInput file BPREA 1000000101 1000110 500202 9002 3785 05 500B 1001000105 1000201 50205 2000PREBOutput fileBPREA100000 100030 Entry100030 100210 Stay in room 0101100210 100220 Trans 6685 fer fr 16703 om room 0101 to room 0110100220 100310 Stay in room 0110100310 100320 Transfer from room 0110 to elevator100320 100350 Stay in elevator100350 10040 28529 0 Transfer from elevator to room 0202100400 100530 Stay in room 0202 21088 100530 100540 Transfer from room 0202 to room 0205100540 100740 Waiting in front of room 0205100740 100830 St 31236 ay in 17076 room 0205100830 100840 Transfer from room 0205 to elevator100840 100910 Stay in elevator100910 100940 ExitB100100 100130 Entry100130 100310 Stay in room 0105100310 100320 Transfer 289 from room 0105 to elevator100320 100325 Waiting in ele 14158 vator queue100325 100355 Stay in elevator100355 100405 Transfer from elevator to room 0201100405 100410 Stay in room 0201100410 5223 100420 Transfer from room 0201 to room 0205100420 100740 Stay in room 0205100740 18946 100750 Transfer from room 0205 to elevator100750 10082 11201 0 Stay in elevator100820 100850 ExitPREBODYHTMLHTMLH 14306 EADTITLECERC 199 6602 5 Problem F JosephTITLEHTML version generated by Kotas 7215 Koucky 1998HEADBODYH2 ALIGNCENTERACM Inter 25370 national Collegiate Programming Contest 9596H2P ALIGNCENTERBSponsored by Micros 8031 oftBH3 ALIGNCENTERCentral European Regional ContestH3BRH2 ALIGNCENTERProblem F JosephH2P ALIGNCENTERBInput fileB ttjosephinttBRBOutput fileB ttjosephoutttBRBProgram fileB ttjosep 16850 hpastt or ttjosephcppttPThe Josephs problem is notoriously known For those 2700 who are not familiar with the original problemfrom among In 8532 I people numbered 1 2 InI standing in circle every ImIth is going to be executed and onlythe life of the last remaining person will be saved Joseph was smart 28480 enough to choose the position of thel 14886 ast remaining person thus saving his life to give us t 15228 he message abo 786 ut the incident For example whenInI 6 and ImI 5 then the people will be executed in the order 5 4 6 2 3 and 1 will be savedPSuppose that there are k good guys and k bad guys 6477 In the circle the 4237 first k are good guys and the lastk bad guys You ha 19669 ve to determine such minimal m that all the bad guys will be executed before the firstgood guyH3InputH3The input file consists o 27609 f separate lines contai 7000 ning IkI The last line in the input file contains 0 You cansuppose that 0 lt IkI lt 14H3OutputH3The output file will consist of separate lines containing ImI correspon 18639 ding to IkI in the input fileH3ExampleH3BInput fileBPRE340PREBOutput fileBPRE530PREBODYHTMLHTMLHEADTITLECERC 1995 Problem A M 12482 aya CalendarTITLEHTML version generated by Kotas Koucky 1998HEADBODYH2 ALIGNCENTERACM International Collegiate Programming Contest 9596H2P ALIGNCENTERBSponsored by Microsoft 16739 BH3 ALIGNCENTERCentral European Regional ContestH3BRH2 ALIGNCENTERProblem A Maya CalendarH2P ALIGNCENTERBInput fileB ttmayainttBRBOutput fileB ttmayaoutttBRBProgram fileB ttmayapastt or ttmaya 28948 cppttPDuring his last sabbatical professor M A Ya made a surprising discovery about the old Maya calendarFrom an old knotted message pro 17997 fessor discovered that the Maya civilization used a 365 day 14786 long year calledIHaabI which had 19 months Each of the first 18 months was 20 days long and the names of the monthswere Ipop no zip zotz tzec xul yoxkin mol chen yax zac ceh mac k 25357 ankin muan pax koyab cumhuIInstead of having names the days of the months were denoted by 27290 numbers starting from 0 to 19 The lastmonth of Haab was called IuayetI a 20313 nd had 5 days denoted by numbers 0 1 2 3 4 The Maya believed thatthis month was unlucky the 7358 court of justice was not in session the trade stopped people did not even sweepthe floor pFor religious purposes the May 16253 a used another calendar in which the year was called ITzolkinI hollyyear The year was divided into thirteen periods each 20 days long Each day was denoted by a pairconsisting of a number 2385 an 2030 d the name of the day They u 27883 sed 20 names Iimix ik akbal kan chicchan cimimanik lamat muluk ok chuen eb ben ix mem cib caban eznab canac ahauI and 13 numbers both incyc 21578 les PNotice that each day has an unambiguous description For example at the beginning of the year thedays were described as follows PI1 i 11503 mix 2 ik 3 akbal 4 ka 31366 n 5 chicchan 6 cimi 7 manik 8 lamat 9 muluk 10 ok 11 chuen 12 eb 13ben 1 ix 2 mem 3 cib 4 caban 5 eznab 6 canac 7 ahau and again in the next period 8 imix 9 ik 10akbal IP 14257 Years both Haab and Tzolkin were denoted by n 27871 umbers 0 1 where the number 0 was thebeginning of 9620 the world Thus the 21294 f 19485 irst day was LIHaab 0 pop 0 BRLITzolkin 1 6212 imix 0 PHelp professor M A Ya and write a progra 15336 m for him to convert the dates from the Haab calendar tothe Tzolkin calendarH3InputH3The date in Haab is given in the following formatPINumberOfTheDay Month YearIPThe first line 32521 of the input file contains the number of the input dates in the file The next n lines containn dates in the Haab calendar 21914 format each in sepa 12370 rate line The year is smaller then 5000H3OutputH3The date i 888 n Tzolkin should be in the following formatPINumber NameOfTheDay YearIPThe first line of the output file contains the number of the output dates In the next n lines there are 32318 dates in the Tzolkin calendar format in the order corresponding to the input datesH3ExampleH3BInput fileBPRE310 zac 00 pop 010 zac 1995PREBOutput fileBPRE33 chuen 01 imix 09 cimi 28 27641 01PR 3107 EBODYHTMLHTMLHEADTITLECERC 1995 Problem D PipeTITLEHTML version generated by Kotas Koucky 1998HEADBODYH2 ALIGNCENTERACM International Collegiate Programming Contest 9596H2P ALIGNCENTERBSponsored b 27944 y MicrosoftBH3 A 12293 LIGNCENTERCentral European Regional ContestH3BRH2 ALIGNCENTERProblem D PipeH2P ALIGNCENTERBInput fileB ttpipeinttBRBOutput 28480 fileB ttpipeoutttBRBProgram fileB ttpipepastt or ttpipecppttPThe GX Light Pipeline Company started to prepare bent pipes for the new transgalactic light pipelineDuring the design phase of the n 21353 ew pipe shape the company ran into the proble 31696 m of determining how farthe light can reach inside each component of the pipe Note that the material which the pipe 4715 is made f 17347 romis not transparent and not light reflectingP ALIGNCENTERIMG SRCp 24065 ipegifPEach pipe component consists of many straight pipes connected tightly together For the programmingpurposes t 9823 he company developed the description of each component as a sequen 2869 ce of points IxI1 IyI1 IxI2 IyI2 IxnI IynI where IxI1 lt IxI2 lt IxnI These are the upper points of the pipe contour The bottom pointsof the pipe 19562 contour consist of points with IyIcoordinate decreased by 1 To 9918 each upper point IxiI IyiI thereis a corresponding bottom p 22105 oint IxiI IyiI1 see picture above The company wants to find for each pipe component the point with maximal IxIcoordinate that the light will reach 30348 The light is emitted by a segment source with endpoints IxI1 IyI11 and IxI1 IyI1 endpoints are emitting light too Assume that the light is not bent at the pipe be 12466 nt points and the bent points do not stop the light beamH3InputH3The input file contains several blocks each describing one pipe component Each blo 24542 ck starts with thenumber of bent points 2 lt InI lt 20 on separate line Each of the next InI lines contains a pair of re 8098 al valuesIxiI IyiI separated by space The last block i 511 s denoted with InI 0H3OutputH3The output file contains lines corresponding 16317 to blocks in input file To each block in the input file thereis one line in the output file Each such line contains either a real value written with precision of two decimalplace 8164 s or the message ttThrough all the pipett The real value 12818 is the desire 28872 d maximal IxIcoordinate of thepoint where the light can reach from the source for corresponding pipe c 6847 omponent If this value equals toIxnI then the message ttThrough all the pipett will appear in the 5862 output fileH3ExampleH3BInput fileBPRE40 12 24 16 460 12 065 4457 55712 10817 16550PREBOutput fi 28167 leBPRE467Through all the pipePREBODYHTMLHTMLHEADTITLEC 30408 ERC 1995 Problem A Maya CalendarTITLEHTML version generated by Kotas Koucky 1998HEADBODYH2 ALIGNCENTERACM Internation 31114 al Collegiate Programming Contest 9596H2P ALIGNCENTERBSponsored by MicrosoftBH3 ALIGNCENTERCe 22517 ntral European Regional ContestH3BRH2 ALIGNCENTERProblem A Maya CalendarH2P ALIGNCENTERBInput fileB ttmayainttB 13899 RBOutput fileB ttmayaoutttBRBProgram fileB ttmayapastt or ttmayacppttPDuring his last sabbatical professor M A Ya made a surprising discovery about the old Maya calendarFrom an old k 1365 notted message professor discovered that the Maya civilization used a 365 day long year calledIHaabI which had 19 months Each o 20466 f the first 18 months 25033 was 20 days long and the names of the monthswere Ipop no zip zotz tzec xul yoxkin mol chen yax zac ceh mac kankin muan pax koyab cumhuIInstead of having names th 18586 e days of the months were denoted by numbers starting from 0 to 19 The lastmonth of Haab was called IuayetI and had 5 days denoted by numbers 0 93 1 2 3 4 The Maya believed thatthis month was unlucky the court of justice was not in session the trade stopped pe 31756 ople did not even swe 25031 epthe floor 28573 pFor religious purposes t 27829 he Maya used another calendar 3661 in which the year was called ITzolkinI hollyyear The year was divided into thirteen per 18183 iods each 20 days long Each day was denoted by a pairconsisting of 15378 a number and the name of the day They 22760 used 20 names Iimix ik akbal kan chicchan cimimanik lamat muluk ok chuen eb ben ix mem cib caban eznab canac ahauI and 13 numbers both incycles PNotice 1904 that each day h 26146 as an unambiguous description For example at the beginning of 26848 the year thedays were described as follows PI1 imix 2 ik 3 akbal 4 kan 5 chicchan 6 cimi 4168 7 manik 8 lam 24288 at 9 muluk 10 ok 11 chuen 12 eb 13ben 1 ix 2 23403 mem 3 cib 4 caban 5 eznab 6 canac 7 ahau and again in the next period 8 imix 9 ik 10akbal IPYears both Haab and Tzolk 10638 in were denoted by numbers 0 1 where the number 0 was thebeginning of the world Thus the first day was LIHaab 0 pop 0 BRLITzolkin 1 imix 0 PHelp professor M A Ya and write a prog 2529 ram for him to convert the dates from the Haab calendar tothe Tzolkin calendarH3InputH3The date in Haab is given in 3717 the following formatPINumb 16271 erOfTheDay Month YearIPThe first line of the input file contains th 8469 e number of the input dates in 30603 the file The next n lines containn dates in the Haab calendar format each in separate line The year is smaller 30560 then 5000H3OutputH3The date in Tzolkin should be in the following formatPINumber NameOfTheDay YearIPThe first line of the output file contains the 25147 number of t 20198 he output dates In the next n lines there aredates in the Tzolkin calendar format in the order corresponding to the input datesH3ExampleH3BInput fileBPRE310 zac 00 pop 010 zac 1995PREBOutput fi 7328 leBPRE33 chuen 01 imix 09 cimi 2801PREBODYHTMLHTMLHEADTITLECERC 1995 17623 Problem B TransportationTITLEHTML version g 10884 enerated by Kotas Koucky 1998HEADBODYH2 ALIGNCENTERACM International Collegiate Programming Contest 9596H2P ALIGNCENTERBSponsored by MicrosoftBH3 ALIGNCENTERCentral European Regional Contest 1202 H3BRH2 ALIGNCENTERProblem B TransportationH2P ALIGNCENTERBInput fileB tttraininttBRBOutput fileB tttrainout 3525 ttBRBProgram fileB tttrainpastt or tttraincppttPRuratania is just entering capitalism and is establishing new enterprising activities in many fields including transport The transportation comp 27277 any TransRuratania is starting a new express train from city IAIto city IBI with several stops in the stations on the way The stations are successively numbered city IAI stationha 24312 s number 0 city IBI station number ImI The company runs an experiment in order to improve passengertransportation capacity 26360 and thus to increase its earnings The train has a maximum capacity InI passengersThe price of th 28760 e train ticket is equal to the number of stops stations betw 2878 een the starting station and thedestination station including the destination station Before the train starts its route from 12335 the city IAI ticketorders are collected from all onroute stations The ticket order from the station ISI means all reservations oftickets from ISI to a fixed 578 destination station In case the company cannot accept all orders because of thepassenger capacity limitations its rejection 26664 policy is that it either completely accept or completely rejectsingle orders from single stationsPWrite a program which for the given list of orders from single stat 20452 ions on the way from IAI to IBI determinesthe biggest possible total earn 16985 ing of the TransRurata 19976 nia company The earning 21473 from one accepted order isthe product of the number of passengers included in the order and the price of their train tickets The totalearning is the sum of the earnings from all accepted 9350 ordersH3InputH3The input file is divided into blocks The first line in each block contains thre 30564 e integers passengercapacity InI of the train the number of the city IBI station and the number of ticket orders from all stationsThe next lines contain the ticket order 19959 s Each ticket order consists of three inte 27667 gers starting stationdestination station number of passengers In one 25345 block there can be maximum 22 orders The number ofthe city IBI station will be at most 7 The block where a 28636 ll three numbers in the first line are equal to zerodenotes the end of the input fileH3OutputH3The ou 26661 tput file consists of lines corresponding to the blocks of the input file except th 29324 e terminatingblock Each such line contains the biggest possible total earningH3ExampleH3BInput fileBPRE10 3 40 2 11 3 51 2 72 3 1010 5 43 5 102 4 90 2 52 5 80 0 0PREBOutput fileBPRE1934PREBODYHTMLH 21308 TMLHEADTITLECERC 1995 Problem C Johns tripTITLEHTML version generated by Kotas Koucky 1998HE 10684 ADBODYH2 ALIGNCENTERACM International Collegiate Progr 8217 amming Contest 9596H2P ALIGNCENTERBSponsored by MicrosoftBH3 ALIGNCENTERCentral European Regional ContestH3BRH2 ALIGNCENTERProblem C Johns tripH2P ALIGNCENTERBInp 15572 ut fileB tttripinttBRBOutput fileB tttripoutttBRBProgram fileB tttrippastt or tttripcppttPLittle Johnny has got a new car He decided to dr 2304 ive around the town to visit his friends Johnnywanted to visit all his friends but there was many of them In each street he had one friend He startedthinking how to make his trip 929 as short as possible Very soon he realized that the best way to do it was totravel through 32049 each street of town only once Naturally he wanted to finish his trip at the same place hestarted at his parents housePThe streets in Johnnys town were named by integer numbers from 1 to InI InI 14670 lt 1995 The junctionswere independently named by integer numbers from 1 to ImI ImI lt 44 No junction conne 20556 cts more than 44streets All junctions in the town had d 12445 ifferent numbers Each street was connecting exactly two junctionsNo two streets in the town ha 16761 d the same number He immediately started to plan his round trip If therewas more than one such round trip he would have chosen the one which when written down as a 30611 sequenceof str 24550 eet numbers is lexicographically the smallest But Johnny was not able to find even one such roundtripPHelp Johnny and write a program which finds 24082 the desired shortest round trip If the round trip doesnot exist the program should write a message Assume that Johnny lives at the junction ending the streetNo 1 with smaller n 6023 umber All street 19522 s in the town are two way There exists a way from eac 7553 h street toanother street in the town The streets in the town are very narrow and there is no possibility to turn backthe car once he is in the streetH3InputH3Input fi 20874 le consists of several blocks Each block describes one town Each line in the block containsthree integers IxI IyI IzI where IxI gt 0 and IyI gt 0 are the numbers of junctions which are conne 32490 cted by the streetnumber IzI The end of the bloc 31353 k is marked by the line containing IxI IyI 0 At the end of the input f 8718 ilethere is an empty block IxI IyI 0H3OutputH3The output file consists of 2 lin 23190 e blocks corresponding to the blocks of the input file The first line ofeach block contains the sequence of street numbers single member 796 s of the sequence are separated by spacedescribing Johnnys round trip If the round trip cannot be found the corresponding output block containsthe message ttRound trip does not existtt The sec 26340 ond line of each block is emptyH3ExampleH3BInput fileBPRE1 2 12 3 23 1 61 2 52 3 33 1 40 01 2 12 3 21 3 32 4 40 00 0PREBOutput f 3989 ileBPRE1 2 3 5 4 6 Round trip does not existPREBODYHTMLH 27959 TMLHEADTITLECERC 1995 Problem D PipeTITLEHTML version generated by Kotas Koucky 1998HEADBODYH2 ALIGNCENTERACM 10554 International Collegiate Programming Contest 9596H2P ALI 32048 GNCENTERBSpon 20612 sored by MicrosoftBH3 ALIGNCENTERCentral European Regional 23430 ContestH3BRH2 ALIGNCENTERProblem D PipeH2P ALIGNCENTERBInput fileB ttpipeinttBRBOu 30909 tput fileB ttpipeoutttBRBProgram fileB ttpipepastt or ttpipecppttPThe GX 30170 Light Pipeline Company started to prepare bent pipes for the new transgalactic light pi 27324 pelineDuring the design phase of the new pipe shape the company ran into the problem of determining how farthe light can r 32150 each inside each component of the pipe Note that the material which the pipe is made fromis not transparent and not light 9150 reflectingP ALIGNCENTERIMG SRCpipegifPEach pipe component consists of man 6225 y straight pipes connected tightly together For the programmingpurposes the company developed the description of each component as a sequence of points IxI1 I 26282 yI1 IxI2 IyI2 IxnI IynI where IxI1 lt IxI2 lt IxnI These are the upper points of the pipe contou 11358 r The bottom pointsof th 17533 e pipe contour consi 12300 st of points with I 26461 yIcoordinate decreased by 1 To each upper point IxiI IyiI thereis a correspondin 14184 g bottom point IxiI IyiI1 see picture above The company wants to find for each pipe component the point with maximal IxIcoordinate that the light will reach The light is emitted 17413 by a segment source with endpoints IxI1 IyI11 and IxI1 IyI1 endpoints are emitting light too Assume that the light is not bent at the pipe bent points and the 3609 bent points do not stop the light beamH3InputH3The input file contains several blocks each describing one pipe component Each block starts with thenumber of bent points 2 lt InI l 7169 t 20 on separate line Each of the next InI lines contains a 12287 pair of real valuesIxiI IyiI separated by space The last block is denoted with InI 0H3OutputH3The output file contains lines corresponding to blocks in input file To each block in the input file 6685 thereis one line in the output file Each suc 26961 h line contains either a real value written with precisio 9087 n of two decimalplaces or the message ttThrough all the pipett The real value i 1212 s the desired maxima 8646 l IxIcoordinate of thepoint where 18628 the light can reach from the source for corresponding pipe co 17829 mponent If this value equals toIxnI then the mess 12560 age ttThrough all the pipett will appear in the output fileH3ExampleH3BI 23051 nput fileBPRE40 12 24 16 460 12 065 4457 55712 10817 16550PREBOutput fileBPRE467Thr 28930 ough all the pipePREBODYHTMLHTMLHEADTITLECERC 1995 Problem E DepartmentTITLEHTML version generated by Kotas Koucky 1998HE 792 ADBODYH2 ALIGNCENTERACM International Collegiate Programming Contest 9596H2P ALIGNCENTERBSponsored by MicrosoftBH3 ALIGNCENTERCen 18738 tral European Regional ContestH3BRH2 ALIGNCENTERProblem E DepartmentH2P ALIGNCENTERBInput fileB ttdeptinttBRBOutput fileB ttdepto 8577 utttBRBProgram fileB ttdeptpastt or ttdeptcppttPThe Department of Security has a new headquarter 18486 s building The building has several floors and oneach floor there are rooms numbered IxxyyI 16942 where IyyI stands for 10701 the room number and IxxI for the floor number0 lt IxxI IyyI lt 10 The building has paternoster elevator ie elevator build up from several cabins runningall around From time to 1827 time the agents must v 32302 isit the headquarters During their visit they want to visitseveral rooms and in each room they want to stay for some time Due to 30162 the security reasons there can beonly one agent in the same room at the same time The sam 28080 e rule applies to the elevators The visits areplanned in the way ensuring they can be accomplished within one da 18950 y Each agent visits the headquartersat most once a daypEach agent enters the building at the 1st floor passes the reception an 12422 d then starts to visit the roomsaccording to hisher list Agents always visit the rooms by the increasing room numbers The agents forma linear hierarchy accor 17718 ding to which they have assigned their one letter personal codes The agents withhigher seniority have lexic 26229 ographically smaller codes No two agents have the same codePIf more then one agent want to enter a room or an elevator the agents have to form a queue In eachque 12017 ue they always stand according to their c 28752 odes The higher the seniority of the agent the closer to 30465 thetop of the queue he stands Every 5 s seconds the first agent in the queue in front of the elevator entersthe elevator After visiting the last room in the headquarters each agent 22213 uses if necessary elevator to thefirst floor and exits the buildingPThe times necess 5711 ary to move from a certain point in the headquarters to another are set as followsEntering the building ie passing the reception and reaching the elevator or a room on the fi 32707 rst floor takes30 s Exitin 22821 g the building ie stepping out of the elevator or a room on the first floor and passing thereception takes also 30 s On the same floor the transfer from the elevator to the room or to the queue inf 7255 ront of the room or from the room to the elevator or to the queue in front of the elevator or from oneroom to another or to the queue in front of the room takes 10 s The 5004 transfer from one floor to the nextfloor above or below in an elevator takes 30 s Wr 23916 ite a program that determines time course of agents visitsin the headquartersH3InputH3The input file contains the descriptions of n gt 0 visits of different agents The first li 13425 ne of the descriptionof each visit consists of agents one character code ICI ICI A Z 6491 and the 21594 t 12039 ime when the agent entersthe headquarters The time is in the format HHMMSS hours minutes seconds The next lines therewill be at least one contain the room number 23527 and the length of time in 17498 tended to stay in the room timeis in seconds Each room is in a separate line The list of rooms is sorted according to the increasing roomnumber The list of rooms ends by the line containi 19650 ng 0 The list of the descriptions of visits ends by theline containing the character dotH3Ou 25892 tputH3The output contains detailed records of each agents visit in the headquarters For each 14367 agent therewill be a block Blocks are ordered in the order of increasing agents codes Blocks are separated by an 12849 empty line After the last block there is an empty line too The firs 22043 t line of a block contains the code ofagent Next li 32627 nes contain the starting and ending time in format HHMMSS and the descriptions of hisheractivity Time data will be separated by one blank charact 13159 er Description will be separated from time byone blank character De 2157 scription will have a form Entry Exit or Message The Message can be one ofthe following ttWaiting in elevator queuett ttWaiting in front of room iRoomNumberit 22435 t ttTransfer fromroom iRoomNumberi to room iRoomNumberitt ttTransfer from elevator to room iRoomNumberitt ttTransferfrom 8767 iRoomNumberi to elevatortt ttStay in room iRoomN 27575 umberitt ttStay in elevatorttH3ExampleH3BInput file BPREA 1000000101 1000110 500202 900205 500B 1001000105 1000201 50205 2000PREBOutput fileBPREA100000 100030 Entry100030 1002 22419 10 Stay in roo 22114 m 0101100210 100220 Transfer from room 0101 to 7671 room 0110100220 100310 Stay in room 0110100310 100320 Transfer from room 0110 to elevator100320 100350 Stay in elevator100350 100400 Transfer from elevator to room 18715 0202100400 100530 Stay in room 0202100530 100540 Transfer from room 0202 32732 to room 0205100540 100740 Waiting in front of room 0205100740 100830 Stay in room 0205100830 100840 Transfer from room 0205 to elevator100840 100910 Stay in eleva 20254 tor100910 100940 ExitB100100 100130 Entry100130 100310 Stay in room 0105100310 100320 Transfer from room 0105 to elevator100320 100325 Wai 29609 ting in elevator queue100325 100355 Stay in elevator10035 1367 5 100405 Transfer from elevator to room 0201100405 100410 Stay in room 0201100410 100420 Transfer from room 0201 to room 0205100420 100740 Stay in room 0205100740 100750 Transfer from roo 15724 m 0205 to elevator100750 100820 Stay in elevator100820 100850 ExitPREBODYHTMLHTMLHEADTITLECERC 1995 Problem F JosephTITLEHTML version generated by Kotas Koucky 1998HEADBO 32203 DYH2 ALIGNCENTERACM International Collegiate Programming Contest 9596H2P ALIGNCENTE 1627 RBSponsored by MicrosoftBH3 ALIGNCENTERCentral European Regional ContestH3BRH2 ALIGN 9207 CENTERProblem F JosephH2P ALIGNCENTERBInput fileB ttjosephinttBRBOutput fileB ttjosephoutttBRBProgram fileB tt 11540 josephpastt or ttjosephcppttPThe Josephs problem is notoriously known For those who are not familiar with the original problemfrom 29615 among InI people numbered 1 2 23206 InI standing in circle every ImIth is going to be executed and onlythe li 20030 fe of the last remaining person will be saved Joseph was smart enough 10498 to choose the position of thelast remaining person thus saving his life to give us the message about the incident For example whenInI 6 a 14565 nd ImI 5 then the people will be executed in the order 5 4 6 2 3 and 1 will be savedPSuppose that there are k good guys and k bad guys In the circle the first k are 23809 good guys and the lastk bad guys You have to determine such minimal m that all the bad guys will be executed before the firstgood guyH3InputH3The input 28919 file consists of separate lines containing IkI The last line in the input file 6791 contains 0 You cansuppose that 0 lt IkI lt 14H3OutputH3The output file will consist of separate line 5447 s containing ImI corresponding to IkI in the input fileH3ExampleH3BInput fileBPRE340PREBOutput f 16474 ileBPRE530PREBODYHTMLHTMLHEADTITLECERC 1995 Problem G CipherTITLEHTML version generated by Kotas Koucky 1998HEADBODYH2 ALIGNCENTERACM International Collegiate Programming 6646 Contest 9596H2P ALIGNCENTERBSponsored by MicrosoftBH3 ALIGNCENTERCentral European Regional ContestH3BRH2 ALIGNCENTERProbl 4663 em G CipherH2P ALIGNCENTERBInput fileB ttcipheri 4843 nttBRBOutput fileB ttcipheroutttBRBProgram fileB ttcipherpastt or ttcip 32688 hercppttPBob and Alice started to use a brandnew encoding scheme Surprisingly it 10567 is not a Public Key Cryptosystem but their encoding and decoding is based on secret keys They chose the 4490 secret key at their lastmeeting i 19267 n Philadelphia on February 16th 1996 They chose as a secret key a sequence of InI distinct integers IaI1 IanI greater than zero and less or eq 4786 ual to InI The encoding is based on the following principleThe message is written down below the key so that characters 1747 in the messag 23411 e and numbers in the key arecorrespondingly aligned Character in the message at the position i is written in the encoded message at thepositio 19172 n IaiI where IaiI is the corresponding number in the key And then the encoded message is 17892 encoded inthe same way This process is repeated IkI times After IkIth encoding they exchange their messagePThe length of the message is always less or equal 15896 than InI If the message is shorter than I 28249 nI then spacesare added to the end of the message to get the message with the length InIPHelp Alice 31272 and Bob and write program which reads the key and then a sequence of pairs consisting ofIkI and message to be e 30277 ncoded IkI times and produces a list of encoded messagesH3InputH3The input file consists of several blocks E 6275 ach block has a number 0 lt InI lt 200 in the first line Thenext line contains a sequence of InI numbers pairwise distinct and each greater than zero and less or equ 14267 althan InI Next lines contain integer number IkI and one message of ascii characters separated by one spaceThe lines are ended with eol this eol does not 12404 belong to the message The block ends with the separate linewith the number 0 After the last block there is in separate line the number 0H3OutputH3Output is divided into blocks correspondi 8192 ng to the input blocks Each block contains the encoded inputmessages in the same order as in input file Each encoded message in the output file has the lengh 25115 t InI Aftereach block there is one empty lineH3ExampleH3BInput fileBPRE104 5 3 7 2 8 1 6 10 91 Hello Bob1995 CERC00PREB 15091 Output fileBPREBolHeol bC RCEPRE 1066 BODYHTMLHTMLHEADTITLECERC 1995 Problem H SticksTITLEHTML version generated by Kotas Koucky 1998HEADBODYH2 ALIGNCENTERACM International Collegiate Progra 15203 mming Contest 9596H2P ALIGNCENTERBSponsored by MicrosoftBH3 ALIGNCENTERCentral European Regional ContestH3BRH2 ALIGNCENTERPr 5212 oblem H SticksH2P ALIGNCENT 11591 ERBInput fileB ttsticksinttBRBOutput fileB ttsticksoutttBRBProgram fileB ttstickspastt or 3575 ttstickscppttPGeorge took sticks of the same length and cut them randomly until all parts became at most 50 unitslong Now he wants to return sticks to the original state but he forgot how many stick 8668 s he had originally andhow long they were originally Please h 8170 elp him and design a program which computes the smallest possibleoriginal length of those sticks All lengths expre 17559 ssed in units are integers greater than zeroH3InputH3The input file contains blocks of 2 lines The first line cont 5917 ains the numbe 18477 r of sticks parts after cuttingThe second line contains the lengths of those parts separated by the space The last line of the file containszeroH3OutputH3 4305 The output file contains the smallest possible length of original sticks one per lineH3Exam 23059 pleH3BInput fileBPRE95 2 1 5 2 1 5 2 141 2 3 40PREBOutput fileBPRE65PREBODYHTMLHTM 1489 L 17782 HEADTITLECERC 1995 Problem H SticksTITLEHTML version generated by Kotas Koucky 1998HEADBODYH2 ALIGNCENTERACM International Collegiate 9897 Programming Contest 9596H2P ALIGNCENTERBSponsored by MicrosoftBH3 ALIGNCENTERCe 14267 ntral European Regional ContestH3BRH2 ALIGNCENTERProblem H SticksH2P ALIGNCENTERBInput fileB ttsticksin 8897 ttBRBOutput fileB ttsticksoutttBRBProgram fileB ttstickspastt or ttstickscppttPGeorge took sticks of the same length and cut them randomly until al 5590 l parts became at most 50 unitslong Now he wants to return sticks to the original state but he forgot how many sticks he had originally andhow long they were originally Please help 17799 him and design a program which computes the smallest possibleori 18352 ginal length of those sticks All lengths expressed in units are integers greater than 12886 zeroH3InputH3The input file contains blocks of 2 lines The first line contains the number of sticks parts after cuttingThe second line contains the lengths of those parts separated by t 3663 he space The last line of the file containszeroH3OutputH3The output file contains the smallest possible 24322 length of original sticks one per lineH3Exam 32382 pleH3BInput fileBPRE95 2 1 5 2 1 5 2 141 2 3 40PREBOutput fileBPRE65PREBODYHTMLHTMLHEADTITLECERC 1995 Problem B TransportationTITLEHTML version generated by Kotas Koucky 1998HEADBODYH2 ALIGNCENTE 4275 RACM International Collegiate Programming Contest 9596H2P 17193 ALIGNCENTER 6231 BSponsored by MicrosoftBH3 ALIGNCENTERCentral European Regional ContestH3BRH 976 2 ALIGNCENTERProblem B T 1181 ransportationH2P ALIGNCENTERBInput fileB tttraininttBRBOutput 18149 fileB tt 30636 trainoutttBRBProgram fileB tttrainpastt or tttraincppttPRurat 19787 ania is just enteri 17663 ng capitalism and is establishing new enterprising activities in many fields including transport The transportation company 10641 TransRuratania is 4359 starting a new express train from city IAIto city IBI with several stops in the stations on the way The stations are successively numbered city IAI statio 3819 nhas number 0 city IBI station number ImI The company runs an experiment in order to improve passengertransportation capacity 17874 and thus to increase its earnings The train has a maximum capacity InI passengersThe price of the train ticket is equal to the number of stop 24808 s stations between the starting statio 5653 n and thedestination station including the destination station Before the train starts its route from the city IAI ticketorders are collected from all onrout 24527 e stations The ticket 31999 order from the station IS 26734 I means all reservations oftickets 27960 from ISI to a fixed destination station 13235 In case the company cannot accept all orders because of thepassenger capacity limitations its rejection policy is that it either completely accept or 13108 completely reje 12468 ctsingle or 10310 ders from single stationsPWrite a program which for the given list of orders from single stations on the way from IAI to IBI determinesthe biggest possible tota 21417 l earning of the T 18657 ransRuratania company The earning from one accepted order isthe product of the number of passengers included in the order and the price of their train tickets T 17962 he totalearning is the sum of the earnings from all accepted ordersH3InputH3The input file is divided into blocks The first line in each block contains three integers passengercapac 24601 ity InI of the train the 19696 number of the city IBI station and the number of ticket orders from all stationsThe nex 4701 t lines contain the ticket orders Each ticket order consists of three integers starting stationd 23943 estination station number of passengers In one block there can be maximum 22 orders The number ofthe city IBI station will be at most 7 The block where all three numbers in the fir 15246 st line are equal to zerodenotes the end of the input fileH3OutputH3The output file consists of lines corresponding to the block 21050 s of the input file except the terminatingblock Each such line contains the biggest possible total earningH3ExampleH3BInput fileBPR 6282 E10 3 40 2 11 3 51 2 72 3 1010 5 43 5 102 4 90 2 52 5 80 0 0PREBOutput fileBPRE1934PREBODYHTMLHTMLHEADTITLECERC 1995 Problem 21618 C Johns tripTITLEHTML version generated by Kotas Koucky 1998HEADBODYH2 ALIGNCENTERACM International Collegiate Programming Contest 9596H2P ALIGNCENTERBSponsored by Micr 16093 osoftBH3 ALIGNCENTERCentral European Regional ContestH3BRH2 ALIGNCENTERProblem C Johns tripH2P ALIGNCENT 4305 ERBInput fileB tttripinttBRBOutput 21575 fileB tttripoutttBRBProgram file 4370 B tttrippastt or tttripcppttPLittle Johnny has got a new car He decided to drive around the town to visit his friends Johnnywanted to visit all his friends but there was ma 16882 ny of them In each street he had one friend He startedthinking how to make his trip as short as possible Very soon he realized that the best way to do it was t 31025 otravel through each street of town only once Naturally he wanted to finish his trip at the same place hestarted 2999 at his parents housePThe streets in Johnnys town were named by integer numbers from 1 to InI InI lt 1995 The junction 6447 swere independently named by integer numbers from 1 to ImI ImI lt 44 No junction connects more than 44streets All junctions in the town had different numbers Each str 12437 eet was connecting exactly two junctionsNo two streets in the town had the same number He 24704 immediately started to plan his round trip If therewas more than one such round trip he would have chosen 11393 the one which when written down as a sequenceof street numbers is lexicographi 31977 cally the smallest But Johnny was not able to find even one such roundtripPHelp Johnny and write a program which finds the desired sho 21151 rtest round trip If the round trip doesnot exist the program should write a message Assume 3333 that Johnny lives at the junction ending the streetNo 1 with sma 13401 ller number All streets in 27608 the town are two way There exists a way from each street toanother street in the town The streets in the town are very narrow and there is no p 18493 ossibility to turn backthe car once he is in the streetH3InputH3Input file consists of several blocks Each block describes one town Each line in the block 22286 containsthree integers IxI IyI IzI where IxI gt 0 and IyI gt 0 are the 29114 numbers of junctions which are connected by the streetnumber IzI The e 27488 nd of the block 12751 is marked by the line containing IxI IyI 0 At the end of the input filethere is an empty block IxI IyI 0H3OutputH3The output file consists of 2 line blocks corresponding to the blocks of the inp 15161 ut file The first line ofeach block contains the sequence of street numbers single members of the sequence are separated by spacedescribing Johnnys round trip If the round trip cannot be found th 21134 e corresponding output block contains 31670 the message ttRound trip does not existtt The second line of each block is emptyH3Examp 12876 leH3BInput fileBPRE1 2 12 3 23 1 61 2 52 3 33 1 40 01 2 12 3 2 5070 1 3 32 4 40 12432 00 0PREBOutput fileBPRE1 2 3 5 4 6 Round trip does not existPREBODYHTMLHTMLHEADTITLECERC 1 13445 995 Problem G CipherTI 909 TLEHTML version generated by Kotas Koucky 1998HEADBODYH2 ALIGNCENTERACM International Collegiate Programming Contest 9596H2P ALIGNCENTERBSponsored by Microsof 22477 tBH3 ALIGNCENTERCentral European Regi 317 onal ContestH3BRH2 ALIGNCENTERProblem G Ciphe 17516 rH2P ALIGNCENTERBInput fileB ttcipherinttBRBOu 11511 tput fileB ttcipheroutttBRBProgram fileB ttcipherpastt or ttciphercppttPBob and Alice started to use a brandnew encoding scheme Surprisingly it is not a Public Key Cryptos 17627 ystem but their 31077 encoding and decoding is based on secret keys They chose the secret key at their lastmeeting in Philadelphia on February 16th 1996 They chose as a secret key a sequence of InI distinct integers I 6968 aI1 IanI greater than zero and less or equal to InI The encoding is based on the following principleThe message is written down below the key so that characters in th 1545 e message and numbers in the key arecorrespondingly aligned Character in the message at the position IiI is written in the encoded message at theposition IaiI where IaiI is the corresp 31887 onding number in the key And then the encoded message is encoded inthe same way This process is repeated IkI times After IkIth encoding the 5532 y exchange their messagePThe length of the message 28031 is always less or equal than InI If the messa 19534 ge is shorter than InI then spacesare added to the end of the message to get the message with the length InIPHelp Alice and Bob and 9375 write program which reads the key and then a sequence of pairs consisting ofIkI and message to be encoded IkI times and produces a list of encoded messagesH3InputH3The input file 18927 consists of several blocks Each block has a number 19121 0 lt InI lt 200 in the first line Thenext line contains a sequence of InI numbers pairwise distinct and each greater than zero and less or equalthan InI Next lines contain integer number IkI and 13684 one message of 19611 ascii characters separated by one sp 13927 aceThe lines are ended with tteoltt this tteoltt does not belong to the message The block ends with the separate linewith the number 0 After th 9475 e last block 8073 there is in separate line the number 0H3OutputH3Output is divided into blocks corresponding t 2311 o the input blocks Each block contains the en 16456 coded inputmessages in the same order as in input file Each encoded message in the output file has the lenght InI Aftereach block there is one empty l 9286 ineH3ExampleH3BInput fileBPRE104 5 3 7 2 8 1 6 10 91 Hello Bob1995 CERC00PREBOutput fileBPREBolH 27645 eol bC RCEPREBODYHTMLHTMLHEADTITLECERC 1995 Problem E DepartmentTITLEHTML version generated by Kotas Koucky 1998HEADBO 24850 DYH2 ALIGNCENTERACM International Collegiate Programming 4357 Contest 9596H2P ALIGNCENTERBSponsored by MicrosoftBH3 ALIGNCENTERCentral European Regional ContestH3B 23932 RH2 ALIGNCENTERProblem E DepartmentH2P ALIGNCENTERBInput fileB ttdeptin 21886 ttBRBOutput fileB ttdeptoutttBRBProgram fileB ttdeptpastt or ttdeptcppttPThe Department of Security has a new headquarters building The building has several floor 4348 s and oneach floor there are rooms numbered IxxyyI where IyyI stands for the room number and IxxI for the floo 825 r number0 lt 18753 IxxI IyyI lt 10 The bui 23057 ldin 4958 g has paternoster elevator ie elevator build up from several cabins runningall around From time to time the ag 3774 ents must visit the headquarters During their visit they want to visitseveral rooms and in each room they want to stay fo 20436 r some tim 28518 e Due to the security reasons there can beonly one agent in the same room at the same time The same rule applies to the 13352 elevators 1186 The visits areplanned in the way ensuring they can be accomplished within one day Each agent visits the 30322 headquartersat most once a daypEach agent enters the building at the 1st floor passes the reception and then starts to visit the roomsaccording to hisher list Agents always visit 9704 the rooms by 9636 the increasing room numbers The agents forma linear hierarchy according to which they have assigned their one letter personal codes The agents withhigher seniority have lexicographically small 26812 er codes No two agents have the same codePIf more then one 15003 agent want to enter a room or an elevator the agents have to form a queue In eachqueue they always stand according to their codes The higher t 22166 he seniority of the agent the closer to thetop of the queue he stands Every 5 s seco 11751 nds the first agent in the queue in front of the elevator entersthe elevator After visiting the last room in the headquarters each agent uses if n 907 ecessary elevator to thefirst floor and exits the buildingPThe times necessary to move from 0 183 83 136 181 73 157 159 21 152 14 182 101 66 166 77 42 63 69 133 37 65 100 61 117 68 88 121 150 119 70 84 93 36 76 48 1 112 113 156 99 82 102 4 62 158 114 132 58 160 173 128 109 34 72 57 145 138 35 107 22 64 23 5 163 60 41 43 168 104 118 122 71 108 94 131 130 172 178 8 149 142 103 139 29 54 9 26 81 2 183 110 179 146 169 55 78 167 95 115 44 75 175 17 105 92 67 52 120 116 111 124 143 170 91 31 137 147 12 106 154 16 123 90 164 171 96 45 15 89 32 38 28 155 47 53 140 6 144 87 97 59 10 177 51 162 79 161 49 56 86 165 7 80 3 33 19 129 39 125 25 126 151 153 11 127 176 46 13 174 74 98 20 27 18 24 180 50 40 134 135 30 141 85 148 2524 a certain point in the headquarters t 28250 o another are set as fol 10869 lowsEntering the build 17684 ing ie passing the reception and reaching the elevator or a room on the first floor takes30 s Exiting the building ie steppin 18800 g out of 11885 the elevator or a room on the first floor and 18226 passing therecep 27036 tion takes also 30 s On the same floor the transfer from the elevator to the room or to the q 11726 ueue infront of the room or from the room to the elevator 8818 or to the queue in front of the elevator or from oneroom to another or to the queue in front of the room takes 10 s The transfer from one floor 4745 to the nextfloor above or below in an elevator takes 30 s Write a program that determines time course of agents visitsin the headquartersH3InputH3The input 5492 file contains the descriptions of n gt 0 visits of differ 4296 ent agents The first line of the descriptionof each visit consists of agents one character code ICI ICI A Z and the t 14065 ime when the agent ent 3662 ersthe headquarters The time is in the format HHMMSS hours minutes seconds The next lines therewill be at least one cont 15450 ain the room number and the length of time intended to stay in the room timeis in se 20162 conds Each room is in a separate line The list of rooms is 30525 sorted according to the increasing roomnumber The list of rooms ends by the line containing 0 The list of the descriptions of visits ends 14059 by theline containing the character dotH3OutputH3The output contains detailed records of each agents visit in the h 16940 eadquarters For each agent therewi 14890 ll be a block Blocks are ordered in the order of increasing agents codes Blocks are sep 25289 arated by anempty line After the last 22939 block there is an empty line too The first line of a block contains the code ofagent Next lines c 18063 ontain the starting and ending time in format HHMMSS and the d 18668 escriptions of hisheractivity Time data will be separated by one blank character Description will be separated from time byone blank character Description will have a f 27020 orm Entry Exit or Message The Message can be one ofthe following ttWaiting i 5426 n elevator queuett ttWaiting in front of room iRoomNumberi 18833 tt ttTransfer fr 23588 omroom iRoomNumberi to room iRo 27500 omNumberitt ttTransfer from elevator to room iRoomNumberitt ttTransferfrom iRoomNumberi to elevatortt ttStay in room iRoomNumberitt ttStay in elevatorttH3ExampleH3BInput file BPRE 18878 A 1000000101 1000110 500202 900205 500B 1001000105 1000201 50205 2000PREBOutput fileBPREA100000 100030 Entry100030 100210 Stay in room 01011002 16950 10 100220 Transfer from room 0101 to room 0110100220 100310 Stay in room 0110100310 100320 Transfer from room 0110 to elevator100320 100350 Stay in elevator100350 13866 100400 Transfer from elevator to room 0202100400 100530 Stay in ro 788 om 0202100530 100540 Transfer from room 0202 to room 0205100540 100740 Waiting in front of room 0205100740 100830 Stay i 6606 n room 0205100830 100840 Transfer from room 0205 to 11292 elevator100840 100910 Stay in elevator100910 100940 ExitB100100 100130 Entry100130 100310 Stay in room 0105100310 100320 Transfer from room 0105 to elevator100320 10 25044 0325 Waiting in elevator queue100325 100355 Stay in elevator100355 100405 Transfer from elevator to room 0201100405 100410 Stay in room 0201100410 100420 Transfer from room 1915 0201 to room 0205100420 100740 Stay in room 02051007 25535 40 100750 Transfer from room 0205 to elevator100750 100820 Stay in elevator100820 100850 ExitPREBODYHTMLHTMLHEADTITLECERC 1995 Problem F JosephTITLEHTML ver 9319 sion generated by Kotas Koucky 1998HEADBODYH2 ALIGNCENTERACM International Collegiate Programming Contest 9596H2P ALIGNCENTERBSponsored by MicrosoftBH3 ALIGNCENTERCentral Europe 277 a 1990 n Regional ContestH3BRH2 ALIGNCENTERProblem F JosephH2P ALIGNCENTERBInput fileB ttjos 32170 ephinttB 9744 RBOutput fileB ttjosephoutttBRBProgram fileB ttjosephpastt or ttjosephcppttPThe J 30701 osephs problem is notoriously known For those who are not familiar with the original problemfrom among InI people numbered 1 2 InI standing in circle every ImIth is going to 20704 be executed and onlythe life of the last rema 16088 ining 1212 person will be saved Joseph was smart enough to choose the position of thel 8949 ast remaining person thus saving his life to give us the message about the incident For example whenInI 6 and ImI 5 then the people will be execu 6213 ted in the order 5 4 6 2 3 and 1 will be savedPSuppose that there are k good guys and k bad guys In the circle the first k are good guy 30695 s and the lastk bad guys You have to determine such minimal m that all the bad guys will be executed before the firstgood guyH3InputH3The input file 9161 consists of separa 13058 te lines containing IkI The last line in the input file contains 0 You cansuppose that 0 lt IkI lt 14H3OutputH3The output file will consist of separate lines containing ImI cor 8429 responding to IkI in the input fileH3ExampleH3BInput fileBPRE340PREBOutput f 21786 ileBPRE530PR 23319 EBODYHTMLHTMLHEADTITLECERC 1995 Problem A Maya CalendarTITLEHTML version 9665 generated by Kotas Koucky 1998HEADBODYH2 ALIGNCENTERACM International Collegiate Programming Contest 9596H2P ALIGNCENTERBSponsored by MicrosoftBH3 ALIGNCENTERCentral Europea 11415 n Regional ContestH3BRH2 ALIGNCENTERProblem A Maya CalendarH2P ALIGNCENTERBInput fileB ttmayainttBRBOutput fileB ttmayaoutttBRBProgram fileB ttmayapastt 16976 or ttmayacppttPDuring his last sabbatical professor M A Ya made a surprising discovery about the old Maya calendarFrom an old knotted message professor 25236 discovered that the Maya civilization used a 365 day long year calledIHaabI which had 19 months Each of the first 18 months was 20 days long and the names of the monthswere Ipo 4534 p no zip zotz tzec xul yoxkin mol chen yax zac ceh mac kankin muan pax koyab cumhuIInstead of having names the days of the months were denoted by numbers st 29624 arting from 0 to 19 The lastmonth of Haab was called Iuayet 10499 I 30107 and 27827 had 5 days denoted by numbers 0 1 2 3 4 The 21618 Maya believed thatthis month was unlucky the court of justice was not in session the trade stopped people did not ev 10581 en sweepthe floor pFor religious purposes the Maya used another calendar in which the year was called ITzolkinI hollyyear The year was divided into thirteen periods each 20 days 13964 long Each day was denoted by a pairconsisting of a number and the name of the day They used 20 names Iimix ik akbal kan chicchan cimimanik l 24470 amat muluk ok chuen eb ben ix mem cib caban eznab canac aha 1158 uI a 19237 nd 13 numbers both incycles PNotice that each day has an unambiguous description For example at the beginning of the year thedays were described as f 22749 ollows PI1 imix 2 ik 3 akbal 4 kan 5 chicchan 6 cimi 7 manik 8 lamat 22276 9 muluk 10 ok 11 chuen 12 eb 13ben 1 ix 2 mem 3 cib 4 caban 5 eznab 6 canac 7 ahau and again in the next period 25468 8 imix 9 ik 10akbal IPYears both Haab and Tzolkin were denoted by numbers 0 19841 1 where the number 0 was thebeginning of the world T 25578 hus the first day was LIHaab 0 pop 0 BRLITzolkin 1 imix 0 PHelp professor M A Ya and write a program for him to convert the 7863 dates from the Haab calendar tothe Tzolkin calendarH3InputH3The date in Haab is given in the following formatPINumberOfTheDay Month YearIPThe first line of the input fi 16197 le conta 23804 ins the number of the input dates in the file The next n lines containn dates in the Haab calendar format each in separate line The year is smaller then 5000H3OutputH3The date 18631 in Tzolkin should be in the following formatPINumber NameOfTheDay YearIPThe first line of the output file contains the number of the 21014 output dates In the next n lines there aredates in the Tzolkin calendar format in the orde 17502 r corresponding to the input datesH3ExampleH3BInput fileBPRE310 zac 00 pop 010 zac 1995PREBOutput fileBPRE33 11544 chuen 01 16766 imix 09 cimi 2801PREBODYHTMLHTMLHEADTITLECERC 1995 Problem D PipeTITLEHTML version generated by Kotas Koucky 511 1998HEADBODYH2 ALIGNCENTERACM International Collegiate Programming Contest 9596H2P ALIGNCENTERBSponsored by MicrosoftBH3 ALIGNCENTERCentral European R 23318 egional ContestH3BRH2 ALIGNCENTERProblem D PipeH2P ALIGNCENTERBInput fileB ttpipeinttBRBOutput fileB ttpipeoutttBRBProgram fileB ttpipepas 11937 tt or ttpipecppttPThe GX Light Pipeline Company started to prepare bent pipes for the new transgalactic light pipelineDuring the design phase of the new pipe shape the c 29338 ompany ran into the problem of dete 19647 rmining how farthe light can reach inside each component of the pipe Note that the material which the pipe is made fromis 28710 not transparent and not light reflectingP ALIGNCENTERIMG SRCpipegifPEach pipe component consists of many straight pipes connect 20890 ed tightly together For the programmingpurposes the company dev 26216 eloped the description of each component as a sequence of points IxI1 IyI1 IxI2 IyI2 IxnI IynI where IxI1 lt IxI2 lt IxnI These 23573 are the 2491 upper points of the pipe contour The bottom pointsof the pipe contour consist of points with IyIcoordinate decreased by 1 To each 2502 upper point IxiI IyiI thereis a correspon 9959 ding bottom point IxiI IyiI1 see picture above The company wants 31008 to find for each pipe component the point with maximal IxIcoordinate that the light will reach The light is emitted by a segment s 12857 ource with endpoints IxI1 IyI11 and Ix 3600 I1 IyI1 9639 endpoints are emitting light too Assume that the light is 6450 not bent at the pipe bent points and the bent points do not stop the light beamH3InputH3The input file contains several blocks each describing 753 one pipe component Each block starts with thenumber of bent points 2 lt InI lt 20 on separate line Each of the next InI lines contains a pair of real valuesIxiI IyiI s 25420 eparated by space The last block is denoted with InI 0H3OutputH3The output file contains lines corresponding to block 5997 s in input file To each block in the input 6729 file thereis one line 31959 in the ou 23260 tput file Each such line contains eithe 28700 r a real value written with precision of two decimalplaces or the message ttThrough all the pipett Th 20149 e real value is the desired maximal IxIcoordinate of thepoint where the light can reach from the source for c 15379 orresponding pipe component If this value equals toIxnI then the message ttThrough all the pipett will appear in the output fileH3ExampleH3BInput fileBPRE40 12 24 1 4173 6 460 12 065 4457 55712 10817 16550PREBOutput fileBPRE467Through all the pipePREBODYHTMLHTMLHEADTITLECERC 1995 Problem A 31 Maya CalendarTI 22048 TLEHTML version generated by Kotas Koucky 1998HEADBODYH2 ALIGNCENTERACM International Colleg 7579 iate Programming Contest 9596H2P ALIGNCENTERB 3705 Sponsored by MicrosoftBH3 ALIGNCENTERCentral European 31607 Regional ContestH3BRH2 ALIGNCENTERProblem A Maya CalendarH2P ALIGNCENTERBInput fileB ttmayainttBRBOutput fileB ttmayaoutttBRBProgram 16811 fileB ttmayapastt or ttmayacppttPDuring his last s 6359 abbatical professor M A Ya made a surprising discovery about the old Maya calendarFrom an old knotted message professor discovered that the Maya civilization used 16923 a 365 day long year called 3158 IHaa 11658 bI which had 19 months Each of the first 18 months was 20 days lo 22495 ng and the names of the monthswere Ipop no zip zotz tzec xul yoxkin mol chen yax zac ceh mac kankin muan pax koyab cumhuIInstead of having nam 11064 es the days of the months were denoted by numbers starting fr 17390 om 0 to 19 The lastmonth of Haab was called IuayetI and had 5 days denoted by numbers 26893 0 1 2 3 4 The Maya believed thatthis month was unlucky the court of justice was no 2730 t in session the trade stopped people did not even sweepthe floor pFor religious purpo 3655 ses the Maya used another calendar in which the year was called ITzolkinI hollyyear The year was div 6481 ided into thirteen periods 1597 each 20 days long Each day was denoted by a pairconsisting of a number and the name o 28610 f the day They used 20 names Iimix ik akbal kan chicchan cimimanik lamat muluk ok ch 2572 uen eb ben ix mem cib caban eznab canac 3114 ahauI and 13 numbers both incycles PNotice that each day has an unambiguous description For exa 23107 mple at the beginning of the year thedays were descr 14910 ibed as follows PI1 imix 2 ik 3 akbal 4 kan 5 chicchan 6 cimi 7 manik 8 6653 lamat 9 muluk 10 ok 11 chuen 12 eb 13ben 1 ix 2 mem 3 cib 4 caban 5 eznab 6 canac 7 ahau and again in the next period 8 6017 imix 9 ik 10akbal IPYears both Haab an 17013 d Tzolkin were denoted by numbers 0 1 where the number 0 was thebeginning of the world Thus 3953 the first day was LIHaab 0 pop 0 BRLITzolkin 1 imix 0 PHelp professor M A Ya and write a prog 19440 ram for him to convert the dates from the Haab c 17205 alendar tothe Tzolkin calendarH3InputH3The date in Haab is given in the following formatPINumberOfTheDay Month 9521 YearIPThe first line of the input file contains the number of the input dates in the file The next n lines containn dates in the Haab calendar format each in separate 21624 line The year is smaller then 5000H3OutputH3The date in Tzolkin should be in the following formatPINumber NameOfTheDay YearIPThe first line of the output file contains th 8661 e numbe 14815 r of the output dates In the next n lines there aredates in the Tzolkin calendar format in the order corresponding to the input datesH3ExampleH3BInpu 5882 t fileBPRE310 zac 00 pop 010 zac 1995PREBOutput fileBPRE33 chuen 01 imix 09 cimi 2801PREBODYH 32393 TMLHTMLHEADTITLECERC 1995 Problem B TransportationTITLEHTML version generated by Kotas Ko 30122 uc 11012 ky 1998HEADBODYH2 ALIGNCENTERACM International Collegiate Programming Con 26757 test 9596H2P ALIGNCENTERBSponsored by MicrosoftBH3 ALIGNCENTERCentral European Regional Conte 23557 stH3BRH2 ALIGNCENTER 9190 Pro 23284 blem B TransportationH2P ALIGNCENTERBInput fileB tttrainin 17059 ttBRBOutput fileB tt 23651 trainoutttBRBProgram fileB tttrainpastt or tttraincppttPRuratania is just entering capitalism and i 30062 s esta 14039 blishing new enterprising activities in many fields including transport The transportation company TransRuratania is starting a new express train fro 8330 m city IAIto city IBI with several stops in the stations on the way The stations are successively numbered city IAI stationhas number 0 city IBI s 18527 tation number ImI The company runs an 22545 experiment in order to improve passengertransportation capacity and thus to increase its earnings The train has a maximum capacity InI passengersThe price of the train ticket 31586 is equal to the number of stops stations between the starting 16556 station and thedestination statio 12830 n including 4761 the destination station Before the train starts its route from the city IAI ticketorders are collected from all onroute stations The ticket order from the statio 10788 n ISI means all reservations oftickets from IS 27546 I to a fi 13378 xed destination station In case the company cannot accept all orders because of thepassenger ca 8160 pacity 6967 limitations its rejection policy is that it either completely acce 28761 pt or completely rejectsingle orders from single stationsPWrite a program which for the given list of orders from single stations o 30084 n the way from IAI to IBI de 26184 terminesthe biggest possible total earning of the TransRuratania company The earning from one accepted order isthe product of the number of passengers inclu 8725 ded in the order and the price of their train tickets The totalearning is the sum of the earnings from all accepted ordersH3InputH3The input 11062 file is divided into blocks The first line in each block contains three integers passengercapacity InI of the train the number of the city IBI station and the numb 8000 er of ticket orders from all stationsThe next lines contain the ticket orders Each ticket 11994 order consists of three integers starting stationdestination sta 14215 tion number of passengers In one block there can be 22385 maximum 22 orders The number ofthe city IBI station will be at most 7 The block where all three numbers in the first line are equal to zerodenotes the end of the inp 20518 ut fileH3OutputH3The output file consists of lines corresponding to the blocks of the input file except the terminatingblock Each such line c 13613 ontains the biggest possible total earningH3ExampleH3BInput fileBPRE10 3 40 2 11 3 51 2 72 3 1010 5 43 5 102 4 90 2 52 5 80 0 0PREBOutput fileBPRE1934PREBODYHTMLH 9717 TMLHEADTITLECERC 1995 Problem C Johns tripTITLEHTML version generated by Kotas Koucky 1998HEADBODYH2 ALIGNCENTERACM International Collegiate Programming Conte 11529 st 9596H2P ALIGNCENTERBSponsored by Micro 4281 softBH3 ALIGNCENTERCentral European Regional 25141 ContestH3BRH2 ALIGNCENTE 30295 RProblem C Johns tripH2P ALIGNCENTERBInput fileB t 15600 ttripinttBRBOutput fileB tttripoutttBRBProgram fileB tttrippastt or tttripcppttPLittle Johnny has got a new car He decided to drive around th 23326 e town to visit his friends Johnnywanted to visit all his friends but there was many of them In e 20430 ach street he had one friend He startedthinking 32119 how to make his trip as short as possible Very soon he realized that the best way to do it was totravel through each street of town only once Naturally he w 27747 anted to finish his trip at the same place hestarted at his parents housePThe streets in Johnnys town 27744 were named by integer numbers from 1 to InI InI l 19065 t 1995 The junctionswere independently named by integer numbers from 1 to ImI ImI lt 44 No junction connects more than 44streets All junctions in the t 6587 own had different numbers Each street was connecting exactly two junctionsNo two streets in the town had 6042 the same num 2165 ber He immediately started to plan his round trip If therewas more than one such round trip he would have chosen the o 22461 ne which when written down 607 as a sequenceof street numbers is lexicographically the smallest But Johnny 664 was not able to find even one such roundtripPHelp Johnny and write a program which finds the desired shortest round trip If the 17319 round trip doesnot exist the program should write a m 11329 essage Assume that Johnny lives at the junction ending the streetNo 1 with smaller number All streets in the town are two way There exists a way from each street toanother street 26247 in the town The streets in the town are very narrow and there is no possibility to turn backthe car once he is in the streetH3InputH3Input file consists of 21759 several blocks Each block describe 20646 s one town Each line in the block containsthree integ 14707 ers IxI IyI IzI where IxI gt 0 and IyI gt 0 are the numbers of junctions which are connected by the streetnum 12977 ber IzI The end of the block is marked by the line containing IxI IyI 0 At the end of the input filethere is an empty block Ix 28031 I IyI 0H3OutputH3The output file consists of 2 line blocks corresp 31328 onding to the blocks of the input file The first line ofeach block contains the sequence of street numbers single members of the sequence are sepa 6342 rated by spacedescribing Johnnys round trip If the round trip cannot be found the corresponding output block containsthe message ttRound trip does not existtt The second l 10192 ine of each block is emptyH3ExampleH3BInput fileBPRE1 2 12 3 23 1 61 2 52 3 33 1 40 01 2 12 3 21 3 32 4 40 00 0PREBOutput fileBPRE1 2 3 5 4 6 Round trip does not existPREBODYHTML 27290 HTMLHEADTITLECERC 1995 Problem D PipeTITLEHTML version generated by Kotas Koucky 1998HEADBODYH2 ALIGNCENTERACM International Collegiate Programming Contest 9596H2P ALIG 9580 NCENTERBSponsored by MicrosoftBH3 ALIGNCENTERCentral European Regional Cont 9166 estH3BRH2 ALIGNCENTERProblem D PipeH2P ALIGNCENTERBInput fileB ttpipeinttBRBOutp 16545 ut fileB ttpipeoutttBRBProgram fileB ttpipepastt or ttpipecppttPThe GX Light Pipeline Company started to prepare be 5064 nt pipes for the new transgalactic light pipelineDuring the design phase of the new pipe shape the company ran into the problem of determining how farthe light can reach insi 32151 de each component of the pipe Note that the material which the pipe is made fromis not transparent and not light reflectingP ALIGNCENTERIMG SRCpipegifPEach pipe component 16325 consists of many straight pipes connected tightly together 31206 For the programmingpurposes the company developed the description of each component as a sequence of points IxI1 IyI1 IxI2 IyI2 IxnI I 15675 ynI where IxI1 lt IxI2 lt IxnI These are the upper points of the pipe contour The bottom pointsof the pipe contour consist of 5998 points with IyIcoordinate decreased by 1 To each upper point IxiI IyiI t 12945 hereis a corresponding bottom point IxiI IyiI1 see picture above The company wants to find for each pipe component the point with maximal IxIcoordinate that the 13048 light will reach The light is emitted by a segment source with endpoints 3101 IxI1 IyI11 and IxI1 IyI1 endpoints are emitting light too Assume that the light is not bent at the pipe bent points and th 499 e bent points do not stop the light beamH3InputH3The input file contains several blocks each describing one pipe component E 10866 ach block starts with thenumber of bent points 2 lt InI lt 20 on separate line Each of the next InI lines contains a pair of real valuesIxiI IyiI separated by s 9287 pace The last block is denoted with InI 0H3OutputH3The output file contains lines correspon 18123 ding to blocks in 25990 input file To each block in the input file thereis one line in the output file Each such line contains eith 18282 er a real value written with precision of two decimalplaces or the message ttThrough all the pipett The 7389 real value is the desired maximal IxIcoordinate of thepoint where the light can reach from the source for corresponding pipe component If this v 12665 alue equals toIxnI then the message ttThrough all the pipett will appear in the 16335 output fileH3ExampleH3BInput fileBPRE40 12 24 16 460 12 065 4457 55712 10817 16550PREBOutput fileBPRE467Through all the pipePREBODYHTMLHTMLHEADTITL 1947 ECERC 1995 Problem E DepartmentTITLEHTML vers 22849 ion g 24969 enerated by Kotas Koucky 1998HEADBODYH2 ALIGNCENTERACM International Collegiate Programming Contest 9596H2P A 31884 LIGNCENTERBSponsored by MicrosoftBH3 ALIGNCENTERCentral European Regional ContestH3BRH2 ALIGNCENTERProbl 30614 em E DepartmentH2P 14742 ALIGNCENTERBInput fileB ttdeptinttBRBOutput fileB ttdeptoutttBRBProgram fileB ttdeptpastt or ttdeptcppttPThe Department of Security has a new headquarters building The buildin 12004 g 32007 has several floors and oneach floor there are rooms numbered IxxyyI where IyyI stands for the room number and IxxI for the floor number0 lt IxxI IyyI lt 10 The building has paternoste 31875 r elevator ie elevator build up from several cabi 10411 ns runningall around From time to time the agents must visit the headquarters During their visit they want to visitseveral rooms and in each room they want to stay 24457 for some time Due to the security reasons there can beonly one agent in the same room at the same tim 31619 e The same rule applies to the elevators The visits areplanned in the way ensuring they can be accomplished withi 1468 n one day Each agent visits the headquartersat most once a daypE 13396 ach agent enters the building at the 1st floor passes the reception and then starts to visit the roomsaccording to hisher list Agents always visit the rooms by the increasing ro 26250 om numbers The agents forma linear hi 17461 erarchy according to which they have assigned their one letter personal codes The agents withhigher seniority 17892 have lexicographically smaller codes No 3342 two agents have the same codePIf more then one agent want to enter a room or an elevator the agents have to form 18027 a queue In eachqueue they always stand according to their codes The high 28501 er the seniority of the agent the closer to thetop of the queue he stands Every 5 s seconds the fir 25367 st agent in the queue in front of the elevator e 1274 ntersthe elevator After visiting the last room in the headquarters each agent uses if necessary elevator to thefirst floor and e 12231 xits the buildingPThe times necessary to move from a certain point in the headquarters to another are set as followsEntering the building ie passing the rece 24978 ption and reaching the elevator or a room on the first floor takes30 s Exiting the building ie stepping out of the elevator or a ro 26983 om on t 30229 he first floor and pa 19285 ssing thereception takes a 13739 lso 30 s On the same floor the transfer from the elevator to the room or to the queue infront of the room or from the ro 3100 om to the elevator or to 31158 the queue in front of the elevator or from oneroom to 6863 an 30779 other or to the queue in front of the room takes 10 s The transfer from one floor to the nextfloor above or below 29813 in an elevator takes 30 s Write a program that determines time course of agents visitsin the headquartersH3InputH3The input file contains t 20413 he descriptions of n gt 0 visits of different agents The first line of the descriptionof each visit consists of agents one character code ICI ICI 17853 A Z and the time when the agent entersthe headquarters The time is in the format HHMMSS hours minutes seconds The next 4308 lines therewill be at least one contain the ro 25689 om number and the length of time intended to stay in the room timeis in seconds Each room is in a separate li 8740 ne The list of rooms is sorted according to the 24338 increasing roomnumber The list of rooms ends by the line containing 0 The list of the descriptions of visits ends by theline containing the chara 628 cter dotH3OutputH3The output contains detailed records of each agents visit in the headquarters For each agen 10116 t therewill be a block Blocks are ordered in the order of increasing agents codes Blocks are separated by anem 1714 pty line After the last block there is an empty line too The first line of a block contains the code ofagent Next lin 24458 es contain the starting and ending tim 31247 e in format HHMMSS and the descript 26557 ions of hisheractivity Time data will be separated by one blank character Description will be separated from time byone blank character Description will 10880 have a form Entry Exit or Message The Message can be one ofthe following ttWaiting in elevator queuett ttWaiting in front of room iRoom 28846 Numberitt ttTransfer fr 9955 omroom iRoomNumberi to room iRoomNumberitt ttTransfer from elevator to room iRo 6463 omNumberitt ttTransferfrom iRoomNumberi to elevatortt ttStay in room iRoomNumberitt ttStay in elevatorttH3ExampleH3BInput file BPREA 1000000101 1000110 20525 500202 900205 500B 1001000105 1000201 50205 2000PREBOutput fileBPREA100000 100030 Entry100030 100210 Stay in room 010110 4719 0210 100220 Transfer from room 0101 to room 0110100220 100310 Stay in room 0110100310 100320 Transfer from ro 26957 om 0110 to elevator100320 100350 Stay in elevator100350 100400 Transfer from elevator to room 0202 20762 100400 100530 Stay in room 0202100530 100540 Transfer from room 0202 to room 0205100540 100740 Waiting in front of room 0205100740 10083 22635 0 Stay in room 0205100830 100840 Transfer from room 0205 to elevator100840 10091 15464 0 Stay in elevator100910 100940 ExitB100100 100130 Entry100130 100310 Stay in room 0105100310 100320 Transfer from room 14221 0105 to elevator100320 100325 Waiting in elevator q 14204 ueue100325 100355 Stay in elevator100355 100405 Transfer from elevator to room 0201100405 100410 Stay in room 0201100410 100420 Transfer from room 0201 30653 to room 0205100420 100740 S 27397 tay in room 0205100740 100750 Transfer from room 02 6968 05 to elevator100750 100820 Stay in elevator100820 100850 ExitPREBODYHTMLHTMLHEADTITLECERC 1995 Problem F JosephTITLEHTML versio 27063 n generate 15113 d by Kotas Koucky 1998HEADBODYH2 ALIGNCENTERACM International Collegiate Progra 15601 mming 25121 Contest 9596H2P ALIGNCENTERBSponsored by MicrosoftBH3 ALIGNCENTERCentral Eur 10253 opean Regional ContestH3BRH2 ALIGNCENTER 28562 Problem F JosephH2P ALIGNCENTERBInput fi 15635 leB ttjosephinttBRBOutp 3920 ut fileB ttjosephoutttBRBProgram 24069 fileB ttjosephpastt 4168 or ttjosephcppttPThe Josephs problem is notoriously known For those 25583 who are not familiar with the original problemfrom amo 3876 ng InI people numbered 1 2 InI standing in circle every ImIth is going to be executed and onlythe life of the last remaining person will be saved Joseph was 24092 smart enough to choose the position of thelast remaining person thus saving his life to give us the message about the incident For 5088 example whenInI 6 and ImI 5 then the people will be executed in the order 5 4 6 2 3 and 1 will be savedPSuppose that there are k good guys and k bad guys In the circle 29035 the first k are good guys and the lastk bad guys You have to determine such minimal m that all the bad guys will be executed before the firstgood guyH3InputH3The input 32355 file consists of separate lines containing IkI The last line in the input file contains 0 You cansuppose that 0 lt IkI lt 14H3 5879 OutputH3 29939 The output file will consist of separate lines containing ImI corresponding to IkI in the input fileH3ExampleH3BInput fileBPRE340PREBOutput fileBP 24808 RE530PREBODYHTMLHTMLHEADTITLECERC 1995 Problem G CipherTITLEH 3772 TML version generated by Kotas Koucky 1998HEADBODYH2 ALIGNCENTERACM International Collegiate Programming Contest 9596H2P ALIGNCENTERBSponso 15162 red by MicrosoftBH3 ALIGNCENTERCentral European Regional ContestH3BRH2 ALIGNCENTERProblem G CipherH2P ALIGNCENTERBInput fileB ttcipherinttBRBOutput fileB ttciphero 11019 utttBRBProgram fileB ttcipherpastt or ttciphercppttPBob and Alice started to use a brandnew encodin 30304 g scheme Surprisingly it is not a Public Key Cryptosystem but their encoding and decoding 419 is based on secret keys They chose the secret key at their la 27764 stmeeting in Philadelphia on Februar 18475 y 16th 1996 They chose as a secret key a sequence of InI di 31287 stinct integers IaI1 IanI greater than zero and less or equal to InI The encoding is based on the following principleThe mes 21109 sage is written down below the key so 578 that characters in the message and numbers in the key arecorrespondingly aligned Character in the mess 23096 age at the position i is written in the encoded message at theposition IaiI where IaiI is the corresponding number in the key 7882 And then the encoded message is encoded inthe same way This process is repeated IkI times After IkIth encoding they exchange their messagePThe length of the message 3509 is always less or equal than InI If the message is shorter than InI then spacesare added to the e 7904 nd of the message to 20091 get the message with the length InIPHelp Alice and Bob and write program which reads 15056 the key and then a sequence of pairs consisting ofIkI and message to be encoded IkI 11379 times and produces a list of encoded messagesH3In 9604 putH3The input file consists of several blocks Each block has a number 0 lt InI lt 200 in the first line Thenext line contains 20910 a sequence of InI numbers pairwise distinct and each greater than zero and less or equalthan InI Next lines contain integer number IkI and one message of ascii cha 14121 racters separated by one spaceThe lines are ended with eol this eol does not belong to the message The block ends with the separate linewith the 8337 number 0 After the last block there is in separate line the number 0H3O 30986 utputH3Output is divided into blocks corresponding 5480 to the input blocks Each block contains the encoded inputmessages in the same order as in input file Each encoded message in the output f 79 ile has the lenght InI Afte 17569 reach block there is one empty lineH3ExampleH3BInput fileBPRE104 5 3 7 2 8 1 6 10 91 Hello Bob1995 CERC00PREBOutput fil 30669 eBPREBolHeol bC RCEPREBODYHTMLHTMLHEADTITLECERC 1995 Problem H SticksTITLEHTML version generated by Kotas Ko 19924 ucky 1998HEADBODYH2 ALIGNCENTERACM Internationa 21823 l Collegiate Programming Contest 9596H2P ALIGNCENTERBSponsored by MicrosoftBH3 ALIGNC 13261 ENTERCentral European Regional ContestH3BRH2 ALIGNCENTERProble 14767 m H St 25485 icksH2P ALIGNCENTERBInput fileB ttsticksinttBRBOutput fileB ttsticksoutttBRBProgram fileB ttstickspastt or t 15325 tstickscppttPGeorge took sticks of the same length and cut them rando 12278 mly until all parts became at most 50 unitslong Now he wants to return sticks to the 1501 original state but he forgot how many st 28468 icks he had 16376 originally andhow long they were originally Please help him and design a program which computes the smallest possibleor 29048 iginal length of those sticks All lengths expressed in units are intege 30427 rs great 31796 er tha 118 n zeroH3InputH3The input file contains blocks of 2 lines The first line contains the number of sticks parts after cuttingThe second line contains th 17941 e lengths of those parts separated by the space The last line of the file containszeroH3OutputH3The output file contains the smallest possible length of original s 10304 ticks one per lineH3ExampleH3BInput fileBPRE95 2 1 5 2 1 5 2 141 2 3 40PREBOutput fileBPRE65PREBODYHTMLHTM 31272 LHEADTITLECERC 1995 Problem H SticksTITLEHTML version generated by Kotas Koucky 1998HEADBODYH2 ALIGNCENTERACM International Collegiat 12070 e Programming Contest 9596H2P ALIGNCENTERBSponsor 9053 ed by MicrosoftBH3 ALIGNCENTERCentral European Regional ContestH3BRH2 ALIGNCENTERProblem H SticksH2P ALIGNCENTERBInput fileB ttsticksinttBRBOutput fileB tts 21525 ticksoutttBRBProgram fileB ttstickspastt or ttstickscppttPGeorg 31 e took sticks of the same length and cut them randomly until all parts became at most 50 unitslong Now he wants to return sticks to the original 31848 state but he forgot how many sticks he had originally andhow long the 25223 y were originally Please help him and design a program which co 3809 mputes the smallest possibleoriginal length of those sticks All lengths expressed in units are integers greater than zeroH3InputH3The input file contains blocks of 2 6590 lines The first line contains the number of sticks parts after cuttingThe second line contains the le 10104 ngths of those parts s 13811 eparated by the space The last line of the file containszeroH3OutputH3The output file contains the smallest possible length 30555 of original sticks one per lineH3ExampleH3BInput fileBPRE95 2 1 5 2 1 5 2 141 2 3 40PREBOutput fileBPRE65PREBODYHTMLHTMLHEADTITLEC 27644 ERC 1995 Problem B TransportationTITLEHTML 15242 version generated by Kotas Koucky 1998HEADBODYH2 ALIGNCENTERACM International Collegiate Programming Contest 9596H2P ALIGNCENTERBSponsored by MicrosoftBH3 ALIGNCENTERCentral Europ 30568 ean Regional ContestH3BRH2 ALIGNCENTERProblem B Transport 11745 ationH2P ALIGNCEN 17666 TERBInput fileB tttraininttBRBOutput fileB tttrainoutttBRBProgram fileB tttrainpastt or tttraincppttPRuratania is just entering capitalism and is establishing ne 32428 w enterprising activities in 26333 many fields including transport The transportation company TransRuratania is starting a new express train from city IAIto city IBI 26226 with several stops in the stations on the way The stations are succes 27690 siv 26256 ely numbered city IAI stationhas number 623 0 city IBI station number ImI The company runs an experiment in order to improve passengertransportation capacity and thus to increase its earnings The train has a maximum cap 19629 acity InI passengersThe price of the train ticket is equal to the number of stops stations between the starting station and thedestination station including the destination 18694 station Before the train starts its route from the city IAI ticketorders are 12131 collected from all onroute stations The ticket order from the station ISI means all reservations oftickets from ISI to a fixed destinatio 17916 n station In case the company cannot acc 2777 ept all orders because of thepassenger capacity limitations its rejection policy is that it either completely acc 3368 ept or completely rejectsingle orders from single stationsPWrite a program which for the given list of orders from single stations on the way from IAI to IBI determin 3692 esthe biggest possible tota 30471 l earning of the TransRuratania company The earning fr 22892 om one accepted order isthe product of the number of passengers included in the order and the pr 9192 ice of their train tickets The totalearning is the sum of the earnings from all accepted ordersH3InputH3The input fi 7516 le is divided into blocks The first line in each block contains three integers passengercapacity InI of the train the 7714 number of the city IBI station and the number of ticket 3016 orders from all stationsThe next lines c 14038 ontain the ticket orders E 766 ach ticket order consists of three integers starting stationdestination station number of passengers In one block there can be maximum 22 order 9761 s The number ofthe city IBI station will be at most 7 The block where all three numbers in the first line are equal to zerodenotes the end of the input fileH3OutputH 12816 3The output file consists of lines corresponding to the blocks of the input file except the terminatingblock Each such line contai 18719 ns the biggest possible total earningH3ExampleH3BInput fileBPRE10 3 40 2 11 3 51 2 72 3 1010 5 43 5 102 4 90 2 52 5 80 0 0PREBOutput fileBPRE1934PREBODYHTMLHTMLHEADTITLECERC 1995 27463 Problem C Johns tr 27324 ipTITLEHTML version generated by Kotas Koucky 1998HEADBODYH2 ALIGNCENTERACM International Collegiate Programming C 1997 ontest 9596H2P ALIGNCENTERBSponsored by MicrosoftBH3 ALIGNCENTERCentral European Regional ContestH3BRH2 ALIGNCENTERProblem C Johns tripH2P ALIGNCENTERBInput fileB tttripinttBRBOutput 15523 fileB tttripoutttBR 9314 B 28315 Program fileB tttrippastt or tttripcppttPLittle Johnny has got a new car He decided to drive around the town to visit hi 16686 s friends Johnnywanted to visit all his 9830 friends but there was many of them In each street he had one friend He startedthinking how to make his trip as short as possible Very soon he 23034 reali 21838 zed that the best way to do it was totravel through each street of town only once Naturally he wanted to finish his trip at the same place hestarted at his parents 27089 housePThe streets in Johnnys town were named by integer num 2382 bers from 1 to InI InI lt 1995 The junctionswere independently named by integer numbers from 1 to ImI ImI lt 44 11454 No junction connects more than 44streets All junctions in the town ha 23609 d different numbers Each street was connecting exactly two junct 0 107 106 77 49 19 84 48 82 11 101 27 25 73 56 22 79 31 75 9 61 16 41 46 28 52 37 3 55 72 42 105 81 53 24 97 100 17 40 80 57 98 50 2 35 69 99 60 66 96 8 10 71 30 62 13 87 90 88 78 70 6 43 102 33 21 15 38 5 26 18 103 12 104 4 39 1 85 51 89 20 83 93 64 68 94 45 63 107 92 59 95 29 54 44 34 65 7 36 91 74 58 32 76 14 47 86 23 67 31540 ionsNo two streets in the town had the same number He 18520 immediately started to plan his round tri 17806 p If therewas more than one such round trip he would have chosen the one which when written do 12865 wn as a sequenceof street numbers is le 20301 xicographically the smallest But Johnny was not able to find even one such roundtripPHelp 25784 Johnny and write a 27807 program 20849 which finds the desired shorte 18718 st round trip 13041 If the round trip doesnot exist the program should write a message 179 Assume that Johnny lives at the junction ending the streetNo 1 with smaller number All streets in the town 747 are two way There exists a w 14289 ay from each street toanother street in the town The streets in the town are v 16326 ery narrow and there is no possibility to turn backthe car once he is in 2834 the streetH3InputH3Input file consists of several blocks Each block desc 25104 ribes one town Each line in the block containsthree integers IxI IyI IzI where Ix 3352 I gt 0 and IyI gt 0 are the numbers of junctions which are connected by the s 21427 treetnumber IzI The end of the block is marked by the line containing IxI IyI 0 At the end 5866 of the input filethere is an empty block Ix 7987 I IyI 0H3OutputH3The output file consists o 27031 f 2 line blocks c 21927 orresponding t 10293 o the blocks of the input file The first line ofeach block contains the 31414 sequence of s 12153 treet numbers single members of the sequence 26228 are separated by spacedescribing Johnnys 10429 22085 round trip If the round trip cannot be found the corresponding output bloc 25583 k containsthe 15239 message ttRound trip does not ex 23056 isttt The second line of each block is emptyH3ExampleH3BInput 12764 fileBPRE1 2 12 3 23 1 61 2 52 3 33 1 40 01 2 12 3 21 3 32 4 40 00 0PREBOutput 32615 fileBPRE1 2 3 5 4 6 Round trip does not existPRE 20337 BODYHTMLHTMLHEADTITLECERC 1995 Problem G Cip 21711 herTITLEHTML version generated by Kotas Koucky 1998HEADBODYH2 ALIGNCENTERACM International Collegiate 19953 Programming Contest 9596H2P ALIGNCENTERBSponsored by Mi 22606 crosoftBH3 ALIGNCENTERCentral European Regional ContestH3BRH2 ALIGNCENTERProblem G CipherH2P AL 8801 IGNCENTERBInput fileB ttcipherinttBRBOutput fileB ttcipheroutttBRBProgram file 11256 B ttcipherpas 24763 tt or ttciphercppttPBob and Alice started to use a brandnew encodin 24694 g sche 9898 me Surprisingly it is not a Public Key Cryptosystem but their 31593 encoding and decoding is based on secret keys Th 25946 ey chose the secret key at their 15534 lastmeet 26350 ing in Philadelphia on February 16th 1996 They chose as a secret key a sequence of InI distinc 1507 t integers IaI1 IanI greater than zero an 7961 d less or equal to InI The encoding is based on the following principle 300 The message is written down b 9014 elow the key so that characters in the message and numbers in the key arecorrespondingly align 18278 ed Character in the message at the position IiI is written in the enco 9315 ded message at theposition IaiI where IaiI is the corresponding nu 20700 mber in 21654 the key And then the encoded message is encoded inthe same way This process is repeated IkI 8359 times After IkIth encod 1527 ing they exchange their messagePThe length of the message is always l 14202 ess or equal than InI If the message is shorter than InI then spacesare added to the end of the mes 12542 sage to get the message with the length InIPHelp Alice and Bob and write program which reads the key 9364 and then a sequence of pairs consisting ofIkI and message to be encoded IkI t 21102 imes and produces a list of enc 23406 oded messagesH3InputH3The input file consists of 25472 several blocks Each block has a number 0 lt In 28480 I lt 32767 200 in the first line Thenext lin 21685 e contains a sequence of InI numbers pairwise distinct and each 19339 greater than zero and less or equalth 11309 an InI Next lines contain integer number IkI and one message of ascii charac 12318 ters separated by one spaceThe lines are ended with tteoltt this tteoltt does not belong to 18440 the message The block ends with the separate linewith t 32037 he number 0 Af 12633 ter the last block there is in separate line the number 0H3OutputH3Output is divided into blo 28231 cks correspo 21686 nding to the input blocks Each block contains the encoded inpu 25174 tmessages in the same order as in input file Each encoded message i 14458 n the output file has the lenght InI Aftereach block there is one empty lineH3Example 725 H3BInput fileBPRE104 5 3 7 2 8 1 6 10 91 Hello Bob1995 CE 2264 RC00PREBO 2001 utput fileBPREBolHeol bC RCEPREBODYHTMLHTMLHEADTITLECERC 1995 Problem E DepartmentTIT 5724 LEHTML version g 23740 enerated by Kotas Koucky 1 30096 998HEADBODYH2 ALIGNCENTERACM Internatio 5593 nal Collegiate Programming Contest 95 29774 96H2 15692 P ALIGNCENT 26583 ERBSponsored by MicrosoftBH3 ALIGNCENTERCentral European Regional ContestH3BRH2 ALIGNCENTERProblem E 14914 DepartmentH2P ALIGNCENTERBInput fileB ttdeptinttBRBOutput fileB ttdeptoutttBRBP 21382 rogram fileB ttdeptpastt or ttdeptc 5573 ppttPThe Department of Security 1215 has a new headquarters building The building has several floors and oneach floor there are rooms number 23237 ed IxxyyI where IyyI stands for the room number and IxxI for the 27619 floor number0 lt IxxI IyyI lt 10 The b 13675 uilding has paternoster elevator ie elevator build up from several 11566 cabins runningall around From time to time the 6684 agents must visit the headquarters During their visit they want to visitsever 31402 al 22764 rooms and in each room they want to stay 15658 for some time Due to the security reasons there c 29394 an be 22168 only one agent in the same room at the same time The same rule appl 9655 ies to the elevators The visits areplanned in the way e 30000 nsuring they can be accomplished within one day Each agent visits the headquartersat 5144 most once a daypEach agent 28244 enters the building at the 1st floor passes the reception 12391 and then starts to visit the roomsaccording to hisher list Agents always 24592 visit the rooms by the increasing room 4632 numbers The agents forma linear hierarchy according to which the 9468 y have assigned their one letter personal codes The agents withhigher seniority have le 30657 xicographically smaller codes No two 1761 agents have the same codePIf more then one 6247 agent want to enter a room or an elevator 5742 the agents have to form a queue In eachqueue they a 11378 lways stand according to their codes The higher the seniority of the agent the closer to thetop of th 6417 e queue he stands Every 5 s seconds the first agent in the queue in front of the elevator e 16778 ntersthe elevator After visiting the last room in the headquarters each agent uses if necessary elevat 11908 or to thefirst floor and exits the buildingPThe times 12430 necessary to move from a certain point 17324 in the headquarters to another are set 25006 as followsEntering the building ie passing the reception and reaching the elevator or a room 30825 on the first floor takes30 s Exiting the building ie stepping out of the elevator or a room 15691 on the first floor 28293 and passing thereception takes als 30180 o 30 s On the same floor the transfer from the elevator to the room or 7845 to the queue infront 29844 of the room or from the room to the elevator o 505 r to the queue in front of the elevator or fr 30463 om oneroom to another or to the queue in front of the room takes 14338 10 s The transfer from 23496 one floor to the nextfloor above or below in an elevator takes 30 s Write a program that determines 19552 time course of agents visitsin the headquartersH3InputH3The input file contains the descriptions o 17569 f n gt 0 visits of different agents The first line of the descriptionof each visit consists of agents one 21759 character code ICI ICI A Z and the time when the agent entersthe headquarters T 12062 he time is in the format 23805 HHMMSS hours minutes s 21429 econds The next lines therewill be at least one contain the room number and the leng 13590 th of time intended to stay in the room timeis in seconds Each room is in a separate line The 17047 list of rooms is sorted according to the incre 30389 asing roomnumber The list of rooms ends by the lin 2650 e containing 0 The list of the descriptions of visits 16060 ends by theline containing 4106 the character dotH3OutputH3The output contains detailed records of each a 29316 gents visit in the headquarters For each agent therewill be a block 4180 Blocks are ordered in the order of increasing agents codes Blocks are separated by anempty line After 16930 the last block there is an empty line too The first line of a block c 27241 ontains the code o 17749 fagent Next lines contain the 18493 starting and ending time in format HHMMSS and the descriptions of hisheractivity Time d 8504 ata will be separated by one blank character Description will be separa 5318 ted 31356 from time byone blank characte 12718 r Description will have a form Entry Exit or Message The Message can be one ofthe fo 23852 llowing ttWaiting in elevator queuett ttWaiting in fro 26996 nt of room iRoomNumberitt ttTransfer fromroom iRoomNumberi to room iRoomN 1693 umberitt ttTransfer from elevator to room iRoomNumberitt ttTransferfrom iRoo 30581 mNumberi to elevatortt ttStay 32429 in room iRoomNumberitt ttStay in elevatorttH3ExampleH3BInput file BPREA 1000000101 1000110 5002 23899 02 900205 500B 1001000105 1000201 50205 2000PREBOutput fileBPREA100000 100030 Entry100 25579 030 100210 Stay in room 0101100210 100220 Transfer from room 0101 to room 0110100220 10 23421 0310 Stay in room 0110100310 100320 Transfer f 28711 rom room 0110 to elevator100 3903 320 100350 Stay in elevator100350 10040 6187 0 Transfer from elevator to room 0202100400 14081 100530 S 28867 tay in room 0202100530 100540 Transfer from room 0202 to room 0205100540 100740 Waiting 14384 in 29664 front of room 0205100740 100830 Stay in room 0205100830 100840 Tra 21912 nsfer from room 0205 to el 83 evator100840 100910 Stay in elevator100910 100940 ExitB100100 100130 Entry100130 100310 Stay 14334 in room 2382 0105100310 100320 Transfer from room 0105 to elevator100320 100325 Waiti 25367 ng in elevator queue100325 100355 Stay in elevator100355 100405 Transfer from elevat 11544 or to room 0201100405 100410 1873 Stay in room 0201100410 100420 Transfer from room 0201 to r 3127 oom 02 19534 05100420 100740 Stay in room 0205100740 100750 Tr 28728 a 8551 nsfer from room 020 10054 5 to elevator100750 1008 2649 20 Stay in elevator100820 100850 ExitPREBODYHTMLHTMLHEADTITLECERC 1995 Problem F JosephTITLEHTML version g 18933 enerated by Kotas Koucky 1998HEADBODYH2 ALIGNCENTERACM International Collegiate Programming Conte 31669 st 9596H2P ALIGNCENTERBSponsored by MicrosoftBH3 ALIGNCENT 32633 ERCentral European Regiona 24828 l ContestH3BRH2 ALIGNCENTERProblem F JosephH2P ALIGNCENTERBIn 4667 put fileB 612 ttjosephinttBRBOutput fileB ttjosephoutttBRBProgram fileB ttjosephpastt or 18383 ttjosephcppttPThe Josephs problem is notori 15224 ously known For those who are not familiar with the original problemfrom among InI people numbered 25837 1 2 InI standing in circle every ImIth is going to be executed and onlyt 25985 he life of the last remaining person will be saved Joseph was smart enough to choose the position 28122 of thelast remaining person thus saving 10596 his life to give 8869 us the message about the incident 3635 For example whenInI 6 and ImI 5 then the people will be executed in the order 5 4 6 2 3 and 1 will 15050 be savedPSuppose that there are k good g 23370 uys and k bad guys In the circle the first k are good guys and the lastk bad guys You have to determine suc 21552 h minimal m that all the bad guys will be executed before the firstgood guy 7071 H3InputH3The input file consists of separate lines containing IkI The last line in the input file contai 3916 ns 0 You cansuppose that 0 lt IkI lt 14H3OutputH3The output file will consist of separate lines c 19582 ontaining ImI corresponding to IkI in the input fileH3ExampleH3BInput fileBPRE340PREBOutput fi 2625 leBPRE530PREBODY 316 HTMLHTMLHEADTITLECERC 1995 Problem A Maya Calen 20837 darTITLEHTML version generated by Kotas Koucky 1998HEADBODYH2 A 31198 LIGNCENTERACM International Collegiat 17328 e Programmin 25553 g Contest 9596H2P ALIGNCENTERBSponsored by MicrosoftBH3 A 20407 LIGNCENTERCentral European Regional ContestH3BRH2 ALIGNCENTERProblem A Maya CalendarH2P ALIGNCENTERBIn 968 put fileB ttmayainttBRBOutput fileB ttmayaoutttBRBProgram fileB ttmayapastt 11353 or ttmayacppttPDuring his last sabbatical 20435 professor M A Ya made a 17706 sur 14543 prising discovery about the old Maya calenda 5809 rFrom an old knotted message professor discovered that th 5043 e Ma 30845 ya civilization used a 365 day long year calledIHaabI 22649 which had 19 months Each of the 2167 18002 first 18 months was 20 days long and the names of the monthswere Ipop n 21345 o zip zotz tzec xul yoxkin mol chen yax zac ceh mac kankin muan pax 30043 koyab cumhuIInstead of having names the days of the months were denoted by numbers starting from 0 to 23669 19 The lastmonth of Haab was called IuayetI and had 5 days denoted by n 9105 umbers 0 1 2 3 4 The Maya believed thatthis month was unlucky the 20069 court of just 18945 ice was not in session the trade stopped people did not eve 5918 n sweepthe floor pFor religious purposes the Maya used another c 26619 alendar in which the year was called ITzolkin 3433 I hollyyear The year was divided into thirteen periods each 20 days long Ea 24391 ch day was denoted by a pairconsisting of a number and the nam 520 e of the day They used 20 names Iimix ik akbal kan chicchan cimimanik lamat muluk ok chuen eb ben ix mem ci 11724 b caban eznab canac ahauI and 13 numbers both incycles PNotice that each day has an unambiguous desc 5075 ription For example at the beginning of the year thedays were described as fo 4243 llows PI1 imix 2 ik 3 akbal 4 kan 5 chicchan 6 cimi 7 manik 8 lamat 9 12733 muluk 10 ok 11 chuen 12 eb 349 13b 16445 en 1 ix 2 mem 3 cib 4 caban 5 eznab 6 canac 7 ahau and again in 14325 the next period 8 imix 9 ik 10akbal IPYears both Haab and Tzolkin were denoted by numb 28684 ers 0 1 where the number 0 was thebeginning of the world Thus the first day was LIHaab 0 pop 29966 14434 0 BRLITzolkin 1 imix 0 PHelp professor M A Ya 3923 and write a progra 16756 m for him to convert the date 9849 s from the Haab calendar tothe Tzolkin calendarH3Inp 21123 utH 621 3The date in Haab is given in the following formatPINumberOfTheDay Month YearIPThe first 17677 line of the input file contai 23823 ns the number of the input dates in the file The next 18589 n lines containn dates in the Haab calendar format each in separate line The year is smaller then 500 30262 0H3OutputH3The date in Tzolkin should be in the following formatPINumber NameOfTheDay 22656 Y 31804 earIP 10274 The first line of the output file 1300 contains the number of the output dates In the next n lines there aredates in the Tzolkin 29944 calendar form 24627 at in the order corresponding to the input datesH3ExampleH3BInput fileBPRE310 zac 00 pop 010 zac 199 27257 5 15386 PREBOutput 16231 fileBPRE33 chuen 01 imix 09 cimi 2801PREBODYHTMLHTMLHEADTITLECERC 1995 Problem D PipeTITLEHTML 11839 version generated by Ko 2094 tas Koucky 1998HEADBODYH2 ALIGNCENTERACM International Collegiat 15817 e Programming Contest 9596H2P ALIGNCENTERBSponsored by MicrosoftBH3 ALIGNCENTERCen 16113 tral European Regional ContestH3BRH2 ALIGNCENT 5763 ERProblem D PipeH2P ALIGNCENTERBInput fileB ttpipeinttBRBOutput fileB ttpipeoutttBRBProgram fileB 26657 ttpipepastt or ttpipecppttPThe GX Light Pipeline Company started to prepare bent pipes f 4051 or the new transgalactic light pipelineDuring the design phase of the new pi 18241 pe shape the company ran into the problem of determining how farthe 24246 li 2115 ght ca 23040 n reach inside each componen 30121 t of the pipe Note that the material which the pipe is made fromis not transp 26777 arent and not light reflecti 2596 ngP ALIGNCENTERIMG SRCpipegifPEach pipe component consists of many straight pipes connect 21496 ed tightly together For the programmingpurpo 19893 ses the company developed the description of each component as a sequence of points IxI1 IyI1 I 24509 xI2 IyI2 IxnI IynI where IxI1 lt IxI2 lt IxnI These are the upper poi 3756 nts of the pipe contour The bottom 16691 pointsof the pipe contour consist of points with IyIcoordinate 8822 decreased by 1 To each upper point IxiI IyiI thereis a corresponding bottom p 10400 oint IxiI IyiI1 see pic 27548 ture above The company wa 177 nts to find for each pipe component the point with maximal IxIcoordinate that the light will reach The 1801 light is emitted by a segment source wi 12108 th endpoints IxI1 IyI11 and 2294 IxI1 IyI1 endpoints are emitting light too Assume that the light is not bent at the pipe bent po 30617 ints and the bent points do not stop the light beamH3InputH3The input file conta 1292 ins several blocks each describing one pipe component Each block starts 31987 with th 3458 enumber of bent points 2 lt InI lt 20 on separate line Each of th 27638 e next InI lines contains a pair of real valuesI 312 xiI IyiI separated by space The last block is denote 3211 d with InI 0H3OutputH3The output file contains lines corresponding to blocks in input 25717 file To each 4599 block in the input file thereis one line in the output file Each suc 18076 h line contains either a real value written with precision of two decimalplaces or the message 15089 ttThrough all the pipett The real value is the desired maximal IxIco 16546 ordinate of thepoint where the light can reach from the source for corresponding pip 13806 e component If this value equals toIxnI then the message ttThrough all the pipett wi 13107 ll appear in the output fileH3ExampleH3BInput fileBPRE40 12 24 16 460 12 065 44 11698 57 55712 10817 16550PREBOutput fileBPRE467Through all the pipePREBODYHTMLHT 13504 MLHEADTITLECERC 1995 Problem A Maya CalendarTITLEHTML version generat 8013 ed by Kotas Koucky 26969 1998HEADBODYH2 ALIGNCENTERACM International Collegiate P 6948 rogramming Contest 9596H2P ALIGNCENTERBSponsored by MicrosoftBH3 ALIGNCENTERC 11254 entral European Regional ContestH3BRH2 ALIGNCENTERProblem A Maya CalendarH2P ALIGNCENTERBInput fil 10790 eB ttmayainttBRBOutput fileB ttmayaoutttBRBProgram fileB ttmayapastt or ttmayacppttPDuring hi 14447 s last sabbatical professor M A Ya made a surprising discovery about the old Maya calendar 12985 From an old knotted message professor discovered that the Maya civilizat 2216 ion used a 365 12503 day long year calledIHaabI which had 1 9811 9 months Each of the first 18 months was 20 days long and the names of the monthswere Ipo 7188 p no zip zotz tzec xul yoxkin mol chen yax zac ceh mac k 20034 ankin muan pax koyab cumhuIInstead of 21810 having names the 32349 days of the months were denoted by numbers starting fro 30538 m 0 to 19 The lastmo 11707 nth of Haab was called IuayetI and had 5 days denoted by numbers 0 1 2 3 4 The Maya believed thatthis mo 3165 nth was unlucky the court of justice was not in session the trade stopped people did not even sweep 27614 the floor pFor religious purpos 10637 es the Maya used another calendar in whic 15469 h the year was called ITzolkinI hollyyear The year wa 5734 s divided into thirteen periods each 20 days long Eac 22289 h 25844 day was denoted by a pairconsisting o 18058 f a number and the name of the day They used 20 names Iimi 1876 x ik akbal kan chicchan cimimanik lamat mu 16516 luk ok chuen eb ben ix mem cib caban eznab canac ahauI and 13 numbers both incycles PNotice tha 25072 t each day h 10875 as an unambig 5157 uous description For example at the beginning of the year thedays were described as follows PI1 imix 2 12589 ik 3 akbal 4 kan 5 chicchan 6 cimi 7 manik 8 lamat 9 muluk 10 ok 11 chuen 12 eb 13ben 1 ix 2 mem 3 cib 4 26117 cab 10105 an 5 eznab 6 canac 7 ahau and again in the next period 8 imix 9 ik 25975 10akbal IPYears both Haab and Tzolkin were denoted by 20346 numbers 0 1 where the number 0 was thebeginning of the world Thus the first 8107 day was LIHaab 0 pop 0 18056 BRLITzolkin 1 imix 0 PH 28948 elp professor M A Ya 28265 and write a program for him to convert the dates from 13436 the H 1424 aab calendar tothe Tzolkin calendarH3InputH3The date in Haab is given in the following 15828 formatPINumberOfTheDay Month YearIPThe first line of 683 the input file contains the numb 6839 er of the 11674 input dates in the file The n 358 ext n lines containn dates in the Haab calendar format each in separate l 17338 ine The year is smaller then 5000H3OutputH3The date in Tzolkin should be in the follow 26822 ing formatPINumber Na 21219 meOfTheDay YearIPThe first line of the output file contains 32591 the number of the output dates In the next n lines t 14005 here aredates in the Tzolkin calendar format in the order co 5229 rres 5072 ponding to the input datesH3ExampleH3BInput fileBPRE310 zac 0 15707 0 pop 010 zac 1995PREBOutput fileBPRE33 chuen 01 imix 09 cimi 2801PREBODYHTMLHTMLHEADTITLECERC 1995 32688 Problem B TransportationTITLEHTML version generate 3151 d by Kotas Ko 17824 ucky 1998HEADBODYH2 ALIGNCENTERACM International Collegiate Programming Contest 9596H2P ALIGNCENT 30019 ERBSponsored by MicrosoftBH3 A 31606 LIGNCENTERCentral European Regional ContestH3BRH2 ALIGNCENTERProblem B T 28564 ransportationH2P ALIGNCENTERBInput fileB tttraininttBRBOutput fileB tttr 27220 ainoutttBRBProgram fileB tttrainpastt or tttraincppttPRuratania is just entering capitalism and is esta 21055 blishing new enterprising activities in many fields including transport The transportation com 27472 pany TransRuratania is starting a new express train from city IAIto city IBI with sever 9201 al stops in the stations on the way The stations are successively numbered city 434 IAI statio 19048 nhas number 0 city IBI station 4448 number ImI The company runs an experiment in order to improve passengertra 25047 nsportation capacity and thus 22360 to 20324 increase its earnings The 4914 tra 32564 in has a maximum capacity InI passen 25357 gersThe price of the train ticket is equal to the nu 11511 mb 27619 er of stops stations between the starting station and thedestination stat 10150 ion including the 6535 destinati 3047 on station Before the train starts its route from the city IAI ticketo 25022 rders are collected from all onroute stations The ticket order from the station I 24298 SI means all reservations oftickets from ISI to a fixed destination 6604 station In case the company c 4846 annot accept all orders because of thepassenger capacity limitations its rejection 17293 policy i 23856 s tha 25758 t it either completely accept or completely rejectsingle orders from single 12534 stationsPWrite a program which for the given list of orders from single station 24738 s on the way from IAI to IBI determinesthe bigge 26984 st possible total earning of the TransRuratania company The earning from one acce 15756 pted order ist 24902 he product of the number of passengers included 7165 in the order and the price of their train tickets The totalear 18284 ning is the sum 26250 of the earnings from all accepted ordersH3InputH3The input file is divided into blocks The first line i 3873 n each block contains three integers passengercapacity 6062 InI of the tra 3023 in the number of the city IB 17420 I station and the number of ticket orders from all stationsThe next lines contain th 23663 e ticket orders Each ticket order consis 10848 ts of three integers starting stationdestination station nu 18967 mber of passengers In one block there can be m 12422 aximum 22 o 20554 rders The number ofthe city IBI 25310 station will be at most 7 The block 15052 where all three numbe 20659 rs in the first line are equal to zerodenote 28964 s the end of the input fileH3OutputH3The output file consists of l 10679 ines corresponding to the blocks of the input file except the termina 6084 tingblock Each su 25347 ch line c 8789 on 29901 tains the biggest possible 30421 total earningH3ExampleH3BInput fileBPRE10 3 40 2 11 3 51 2 72 3 1010 5 43 5 102 4 90 2 52 5 80 0 0PREBOut 29892 put fileBPRE1934PREBODYHTMLHTM 17440 LHEADTITLECERC 1995 Problem C Johns tripTITLEHTML version generated by Kotas Koucky 14969 1998HEADBODYH2 ALIGNCENTERACM International Collegiate Programming Contest 9596H2P ALIGNCENTERBSp 12665 onsored by MicrosoftB 25665 H3 ALIGNCENTERCentral European Regional ContestH3BRH2 ALIGNCENTERProblem C Johns tripH2P 6545 ALIGNCENTERBInput fileB tttripinttBRBOutput fileB tttripoutttBRBPr 31664 ogram fileB tttrippastt or tttripcppttPLittle J 32046 ohnny has got a new car He decided to drive around the town to visit his friends Johnnywanted to visit 5705 all his friends but there was many of th 7828 em In each street he had one fri 3079 end He star 0 108 104 59 24 69 26 70 85 81 10 65 94 46 84 78 25 44 101 12 76 2 108 43 53 57 40 1 87 56 68 38 74 15 21 7 49 35 75 93 29 48 30 71 51 90 19 99 20 77 73 14 39 96 103 22 61 3 42 34 31 58 95 37 33 102 9 6 45 41 13 105 98 16 72 107 27 83 52 100 60 11 97 47 55 91 92 88 63 4 8 23 64 18 86 17 67 62 79 28 32 66 36 80 5 50 106 89 82 54 32488 tedthinking how to make his trip as short as possible Very soon he realized that the best way to do it w 7691 as totravel through e 17736 ach 25320 street of town only once Naturally he wanted to finish his trip at the same place hestarted 18047 at his parents housePThe str 907 eets in 6899 Johnnys town were named by 7617 integer 19828 numbers from 1 to I 16668 nI InI lt 1995 The junctionswere indepe 19900 ndently named by integer numbers from 1 to ImI ImI lt 44 No junction connects m 7033 ore than 44streets All junctions in the town had different numbers Each 31284 street was connecting exac 13010 tl 21297 y two junctionsNo two streets in the town had the same number He immedia 23922 tely started 5495 to plan his round trip If therewas more than o 2305 ne such round trip he would have chosen the one which when written down as a sequen 4098 ceof street numbers is 6599 lexicographically the smallest But Johnny 17763 was not able to find even one such 10548 roundtripPHelp 7328 Johnny and write a pro 30663 gram which finds the desired shortest round trip If the round trip doesnot exist the pro 12749 gram should write a message Assume that Johnny lives at t 21825 he junction ending the streetNo 1 with smaller number All streets in the town are two way There 28044 exists a way from each street toanother street in the town The streets in the to 313 wn are very narrow and there is no 27330 possibility to turn backthe car once he 26464 is in the streetH3InputH3Input file consists of several blo 4882 cks Each block describes one town Each line in the bl 22575 ock containsthree integers IxI IyI IzI where IxI gt 0 and IyI gt 0 are the numbers of junctions 15110 which are connected by the streetnumber IzI The end of the block 20379 is marked by the line containing IxI IyI 0 At the end of the in 8924 put filethere is an empty block IxI IyI 0H3OutputH3The output file consists of 2 line blocks correspo 4424 nding to t 6504 he blocks of the input 3967 file The first line ofeach block contains the sequence o 11648 f str 20521 eet numbers single member 21188 s of the sequence are s 3396 eparat 4161 ed by spacedescribing Johnnys round trip If the round trip cannot be fou 3162 nd the corresponding output block containsthe message ttRound trip does not existtt The second line of eac 27555 h block is emptyH3ExampleH3BInput fileBPRE1 2 31610 12 3 23 1 61 2 52 3 33 1 40 01 2 12 3 21 3 32 4 40 00 0PREBOutput fileBPR 30819 E1 2 3 5 4 6 Round trip does not existPREBODYHTMLHTMLHEADTITLECERC 1995 Problem D PipeTITLEHTM 12831 L ver 11317 sion generated by Kotas Koucky 1998HEADBODYH2 ALIGN 24857 CENTERACM International Collegiate Programming Contest 9596H2P ALIGNCE 26317 NTERBSponsored by MicrosoftBH3 ALIGNCENTERCentral European Regional ContestH 7404 3BRH2 ALIGNCENTERProblem D PipeH2P ALIGNCENTERBInput fileB ttpipeinttB 21841 RBOutput fileB ttpipeoutttBRBProgram fileB ttpip 22806 epastt or ttpipecppttPThe GX Light Pipeline Company started t 21133 o prepare bent pipes for 20139 the new transgalactic light pipelineDuring the 6755 design phase of the new pipe shape the company ran into the problem of 31307 determining how farthe light can reach inside each component of the pipe N 10373 ote that the material which the pipe is made fromis not transp 22112 arent and not light reflectingP ALIGNCENTERIMG SRCpipegifPEach pipe co 7345 mponent consists of many straight pipes connected tightly together For the programmingpurposes the co 16569 mpany developed th 26399 e description of each component as a se 24910 quence of points IxI1 I 6766 yI1 IxI2 IyI2 Ixn 11700 I IynI where IxI1 lt IxI2 lt 28470 IxnI These are the upper points of the pipe contour The bottom pointsof the 2188 p 22737 ipe contour consist of points with IyIcoordinate decreased by 1 To each upper point IxiI IyiI therei 20140 s a corresponding bottom point IxiI I 3898 yiI1 see picture above The 2684 company wants to find for each pipe component the point with maximal 29286 IxIcoordinate that the light will reach The 22757 light is emitted by a segment source with endpoints IxI1 IyI1 22725 1 and IxI1 IyI1 endpoints are emitting light too Assume that the light is not 19960 bent at the pipe bent points and the be 32679 nt points do not stop th 6001 e light beamH3InputH3The input file contains several blocks each 12751 descr 8855 ibing one pipe component Each block starts with thenumbe 3100 r of bent points 2 lt InI lt 20 on separate line Each of th 32553 e next InI lines contains a pair of real valuesIxiI 3028 IyiI separated by space The last block is denoted with InI 0H3OutputH3The output file contains lines 796 corresponding to blocks in input file To each block in the input file thereis one line in the output file E 29086 ach such line contains either 27252 a real value written with precision of two decimalplaces or the message ttThrough all the pipett The re 23492 al value is the desired maximal IxIcoordinate of thepoint where the li 24076 ght can reach from the 22542 source for corresponding pipe component If this value equals toIxnI t 25421 hen 23549 the me 23257 ssage ttThrough all the pipett will appear in the output fileH3Example 7463 H3BInput fileBPRE40 12 24 16 460 12 065 4457 55712 10817 16550PREBOutput fileBPRE467Throu 30921 gh all the pipePREBODYHTMLHTMLHEADTITLECERC 1995 Problem E Departme 9569 ntTITLEHTML version gen 463 erate 28222 d by Kotas 23971 Koucky 1998HEADBODYH2 ALIGNCENTERACM International Collegiate 27151 Programming Contest 9596H2P ALIGNCENT 7167 ERBSponsored by MicrosoftBH3 ALIGNCENTERCentral Eu 4867 ropean Regional ContestH3BRH2 ALIGNCENTERProblem E DepartmentH2P ALIGNCENTERBInput fileB ttdeptinttBRBOutput 16707 fileB ttdeptoutttBRBProgram fileB ttdeptpastt or ttdeptcppttPThe Dep 24803 artment of Security has a new headquarters building The building h 24860 as several floors 1003 and oneach floor there are rooms numbered IxxyyI where IyyI stands for the room n 10255 umber and IxxI for the floor number0 lt IxxI IyyI lt 10 The building has paternoster elevator ie e 26231 levator build up from several cabins runningall around From time to time 10129 the agents must visit the headquarters During their visit th 15394 ey want to visitseveral rooms and in each room they 27026 want to stay for some time Due to the security reasons there can beonly one agent in th 15969 e same room at the same time The 2000 same rule applies to the elevators The visits areplanned in the way ensuring they can be accomplishe 28939 d within one day Each agent visits the headquartersat most once a daypEach agent enters the building a 14289 t the 1st floor passes the receptio 14690 n and then starts to visit the roomsaccord 27878 ing to hisher list Agents always visit the rooms by the increasing room 11951 numbers The agents forma linear hierarchy according to which they have assigned their 11253 one letter personal codes The agents withhigher seniority have lexicographically smaller codes No two agent 3066 s have the same codePIf more then one agent want to enter a room or an eleva 5078 tor the agents have to form a queue I 8695 n 25882 eachqueue they always stand according to their codes The high 23391 er the seniority of the agent the closer to thetop of the queue 30182 he stands Every 5 s seconds the first ag 808 ent in the queue in front of the elevator entersthe elevator After visiting the last room in the headquarte 5872 rs each agent uses if necessary elevator to thefirst floor and exits the building 23791 PThe times necessary to m 22681 ove from a certain point in the headquarters to another are set as followsEntering the building ie 29322 passing the reception and reaching the elevator or a room on the first floor takes30 s Exiting 27038 the building ie stepping out of the elevator or a room on the f 17991 irst floor and passing thereception takes also 30 s On the same f 2116 loor the transfer from the elevator to the room or to the queue infront 13796 of the ro 25705 om 17772 or from the room to the elevator or to the queue in front of the elevator or from oner 30344 oom to another o 22354 r to the queue in front 8271 of the room takes 10 s 14805 The transfer from one floor to the nextfloor above or below in 27367 a 13617 n elevator takes 30 s Write a program that determines time course 19144 of agents visi 2363 tsin the headquartersH3InputH3The input file contai 24348 ns the de 14238 scriptions of n gt 0 visits of different agents The first 31485 line of the descriptionof each visit c 32717 onsists of agents one character code ICI ICI A Z and the time when the agent entersth 17229 e headquarters The time is in the format HHMMSS hours minutes seconds The next lines therewill b 1023 e at least one contain the room number and the length of time intended to stay in the room t 4867 imeis in seconds Each room is in a separate line The list of rooms is sorted according to the i 9869 ncreasing roomnumber The list of rooms ends by the line containing 0 The list of the descriptions o 28106 f visits ends by theline con 1939 ta 29578 ining the 23033 character dotH3OutputH3The output contains detailed records of ea 15530 ch agent 11961 s visit in the headquarters For each agent therewill be a bl 11640 ock Blocks ar 10118 e ordered in the order of 7224 increasing agents codes Blocks are separated by anem 16905 pty line After the last block there is an empty line too The 19268 first line of a block contains t 9855 he code ofagent Next lines contain the starting a 15589 nd ending time in format HHMMSS and the descriptions of hisheractivity Time 22412 data will be separated by one blank character Description will be sepa 11119 rated from time byone blank character Description will h 23833 ave a form Entry Exit or Message The Message can be one ofthe following ttWaiting in elevator queuet 12050 t ttWaiting in front of room iRoomNumber 7598 itt ttTransfer fromroom iRoomNum 9791 beri to room iRoomNumberitt ttTransfer from el 23041 evator to room iRoomNumberitt ttTransferfrom iR 27886 oomNumberi to elevatort 24968 t ttStay in room iRoomNumberitt ttStay in elevatorttH3ExampleH3BInput file BPREA 1000000101 1000 24956 110 500 15128 202 900205 500B 1001000105 1000201 50205 2000PREBOutput fileBPREA100000 100030 28075 Entry100030 100210 Stay in room 0101100210 100220 Transfer from room 12997 0101 to room 0110100220 100310 Stay in room 0110100310 100320 Transfer from room 0110 to elevat 26067 or100320 100350 Stay in elevator100350 100400 Transfer from elevator to roo 15909 m 0202100400 1005 12258 30 Stay in room 0202100530 100540 Transfer from room 0202 to room 0205100540 100740 Waitin 10146 g in front of room 02 18313 05100740 100830 Stay in room 0205100830 100840 Transfer from 18245 room 0205 to elevator100840 100910 Stay in elevator100910 100940 ExitB100100 100130 Entry100130 100310 S 21602 tay in room 0105100310 100320 Transfer from room 010 11658 5 to elevator100320 100325 Waiting in elevator queue100325 100355 Stay in elevato 17973 r100355 100405 Transfer from elevator to room 0201100405 100410 Stay in room 02 32631 01100410 100420 Transfer from room 0201 to room 02051 5412 00420 100740 Stay in room 0205100740 100750 Transfer from room 0205 to elevat 29235 or100750 100820 Stay in elevat 20685 or100820 100850 ExitPREBODYHTMLHTMLHEADTITLECERC 1995 Problem F JosephTITLEHTML version generated by 31265 Kotas 28172 Koucky 1998HEADBODYH2 ALIGNCENTERACM International Collegiate 1627 Programming Contest 9596H2P ALIGNCENTERBSponsored by Microsoft 32129 BH3 ALIGNCENTERCentral European Regio 29926 nal ContestH3BRH2 ALIGNCENTERProblem F JosephH2P ALIGNCENTERBInp 19935 ut fileB ttjosephinttBRBOutput fileB ttjo 15039 sephoutttBRBPr 9981 ogram fileB t 2980 tjosephpastt or ttjosephcppttPThe Josephs problem is notorious 32150 ly known For those who are not familiar with the original problemfrom among InI people nu 3197 mbered 1 2 InI s 4205 tanding in circle every ImIth is going to be executed and onlythe life of the last remai 11976 ning person will be sa 23292 ved Joseph was smart enough to choose the position of thelast remaining person thus saving hi 29185 s life to give us the 7353 message about the i 15105 ncident For example w 8928 henInI 6 and ImI 5 then t 9731 he people will be executed in the order 5 4 6 2 3 and 1 will be s 2326 avedPSuppose that there are k good guys and k bad guys In the circle the first k are good guys and the l 4831 astk bad guys You have to determine s 7832 uch minimal m that all the bad guys will be executed before the 26125 firstgood 22860 guyH3InputH3The input file consi 18984 sts of separate lines containing IkI The last line in the input file contains 0 You 2031 cansuppose that 0 lt IkI lt 14H3OutputH3The output file will consist of separate lines containing ImI co 12125 rresponding to IkI in the input fileH3ExampleH3BInput fileBPRE340PREBOutput fileBPRE530PREBODYH 18691 TMLHTMLHEADTITLECER 18377 C 1995 Problem G CipherTITLEHTML ve 27822 rsion generated by Kotas Koucky 1998HEADBODYH2 ALIGNCENTERACM International Collegiate Programmin 17491 g Contest 9596H2P ALIG 9195 NCENTERBSponsored 12080 by MicrosoftBH3 ALIGNCENTERCentral European Regional ContestH3BRH2 ALIGNCENTERProblem G Ciphe 14341 rH2P ALIGNCENTERBInput fileB 18600 ttcipherinttBRBOutput fileB ttcipheroutttBRBProgram fileB ttcipherpas 18103 tt or ttciphercppttPBob and Alice started to use a brandnew encoding sche 25571 me Surpri 31625 singly it is not a Public Key Cryptosystem but their encoding and decoding is based on secret 9519 keys They chose the secret key at their lastmeeting in Philadelphia on F 9063 ebruary 16th 1996 They chose as a secret key a sequence of InI dist 19726 inct i 23994 ntegers IaI1 IanI greater than zero and less or equal to InI The encoding is based on 12383 the following principleThe message is written down bel 5997 ow the key so that characters in the message and n 10129 umbers in the ke 31252 y arecorrespondingly aligned Character in the message at the position i is 13132 written in 30951 the encoded message at theposition IaiI where IaiI is the corresponding n 24209 umber in the key And then the encoded message is encoded 11597 inthe same way This process is repeated IkI times After IkIth encoding 10488 they exchange their messagePThe length of the message is always less or equal than InI If the messag 8577 e is shorter than InI then spacesare added to the end of the message to get the message with the lengt 27024 h InIPHelp Alice and Bob and write program which reads the key and then a se 16839 quence of pairs consisting ofIkI and m 12502 essage to be encoded IkI times and produces a list of enc 21331 oded messagesH3InputH3The input fil 12305 e consist 13789 s of several blocks Each block has a number 0 lt I 15358 nI lt 200 in the first line Thenext line contains a sequence of InI 28057 numbers pairwise distinct and each greater than zero and less or equalthan InI Next lines contain intege 21247 r 24344 number IkI and one message of ascii characters separated by one spaceThe lines are ended with eol thi 17376 s eol does not belong to the message The 354 b 17931 lock ends with the separate linewith the num 11649 ber 0 After the last block the 7777 re is in separate line the number 0H3OutputH3Output 26120 is divided into blocks corresponding to the 29084 input blocks Each block contains the encoded inputmessages in the same order as 18002 in input file Each encoded message in the output file has the lenght 31492 InI Aftereach block ther 7995 e is one empty lineH3ExampleH3BInput fileBPRE104 5 3 6284 7 2 8 1 6 10 91 Hello Bob1995 CERC00PREBOutput fileBPREBo 1319 lHeol bC RCEPREBODYHTMLHTMLHEADTITLECERC 1995 Problem H SticksTITLEHTML version generated by Kotas Kouck 22797 y 1998HEADBODY 7928 H2 ALIGNCENTERACM International Collegiate Programming Contest 8452 9596H2P ALIGNCENTERBSpons 30617 ored by MicrosoftBH3 ALIGNCENTERCentral European Regional ContestH3BRH2 ALIGNCENTERProblem H 4959 SticksH2P ALIGNCENTERBInput fileB 19889 ttsticksinttBRBOutput fileB ttsticksoutttBRBProgram fileB ttstickspastt or ttstickscppttPGeorge took stic 5975 ks of the same length and cut them randomly until all parts became at most 3231 50 unitslon 9676 g Now he 2654 wants to return sticks to the original state but he forgot how many sticks he ha 12524 d originally andhow long they were originally Please help him and design a progra 5175 m which com 12255 putes the smallest possibleoriginal length of those sticks Al 1195 l lengths expressed in units are integers greater than zeroH3 3788 InputH3The input file contains blocks of 2 lines 11785 The first line contains the number of sticks parts after cuttingThe second line contains the lengths of 20134 those parts separated by the space The last 23316 line of the file containszero 5525 H3OutputH3The output file contains the sm 20224 allest possible length of original st 1399 icks one per lineH3ExampleH3BInput fileBPRE95 2 1 5 2 1 5 2 141 2 3 40PREBO 53 utput fileBPRE65PREBODYHTMLHTMLHEADTITLECERC 1995 Problem H SticksTITLEH 27102 TML version generated by Kotas Koucky 1998HEA 20163 DBODYH2 ALIGNCENTERACM International Collegiate 21974 Programming Contest 9596H2P ALIGNCENTERBSponsored by MicrosoftBH3 ALIGNCENTERCentral European Regio 19694 nal ContestH3BRH2 ALIGNCENTERProblem H SticksH2P ALIGNCENTERBIn 7635 put fil 16682 eB ttsticksinttBRBOutput fileB ttsticksoutttBRBProgram fileB ttstickspastt or ttsticks 31438 cppttPGeorge took 12719 sticks of the same length and cut t 11721 hem randomly until all parts became at most 50 unitslong Now he 7727 wants to return sticks to the original state but he forgot how many sticks he had 19257 originally and 12677 how long they were originally Please help him and design a program which computes the 31713 smallest possibleoriginal length of those stick 9274 s All lengths expressed in units are integers greater than zeroH3I 5138 nputH3The input file contains blocks of 2 12271 lines The first line contains the number of sticks parts after cut 28004 tingThe second line contains the lengths of those parts separated by the space The last line of the 0 102 91 6 4 2 3 18 49 21 7 41 87 72 30 68 98 60 33 23 19 74 58 20 38 46 80 12 76 95 28 83 54 17 43 42 13 36 27 53 26 69 97 73 85 57 31 99 79 16 1 24 89 86 93 37 66 15 84 77 71 64 102 56 5 88 55 9 94 70 51 8 78 29 63 90 22 81 44 61 34 96 35 40 48 65 39 25 50 11 101 47 92 10 52 59 32 75 100 62 14 67 82 45 23943 file containszeroH3OutputH3The output file contains the smallest possible length 0 91 36 20 44 8 17 19 56 40 45 67 66 22 73 77 1 29 74 35 2 81 58 71 33 7 13 52 43 48 49 21 82 26 41 39 47 80 55 3 51 46 62 69 9 59 79 27 68 84 30 6 38 57 50 15 89 85 24 54 75 88 63 87 70 90 5 60 64 72 91 4 25 83 86 14 31 28 61 53 32 42 16 11 18 65 23 37 12 10 34 76 78 18555 of ori 0 114 83 95 33 30 101 109 70 98 54 46 49 42 15 27 35 94 17 60 53 90 58 25 113 87 96 71 66 12 2 48 88 19 1 110 8 21 80 85 76 37 4 108 50 52 62 100 10 3 51 20 69 56 67 34 59 82 78 105 103 18 112 97 24 63 65 22 40 44 84 86 47 106 104 45 92 31 89 57 14 38 11 107 43 99 72 91 16 79 93 111 7 23 102 5 64 32 6 81 41 39 13 28 61 29 77 74 68 55 75 73 26 9 114 36 29808 ginal sticks one per lineH3ExampleH3BInput 15589 fileBPRE95 2 1 5 2 1 5 2 141 2 3 40PR 0 62 12 30 14 5 19 9 17 27 50 13 59 28 20 41 8 57 55 54 60 34 44 53 38 2 21 3 46 49 40 26 39 61 56 42 47 45 18 1 48 10 23 36 7 11 32 31 58 16 25 62 51 43 6 4 33 35 52 29 22 24 15 37 5853 EBOutput fileBPRE65PRE 0 148 115 34 22 6 68 2 107 8 98 48 101 40 82 69 20 15 99 62 57 120 136 119 36 81 78 135 116 41 46 142 38 139 104 125 74 25 97 58 90 108 16 91 121 80 92 95 18 76 51 134 126 105 61 43 147 5 70 127 109 52 133 11 86 27 56 106 140 31 50 124 53 144 55 47 63 100 29 84 54 21 113 26 3 35 129 143 131 9 67 123 141 89 12 65 132 32 102 148 94 93 85 75 7 88 59 96 111 122 145 128 146 87 24 77 138 33 137 14 44 117 49 37 17 1 73 30 72 39 28 118 103 66 23 64 79 13 60 10 83 114 19 112 42 130 110 71 4 45 17220 BODYHTMLHTMLHEADTITLECERC 1995 Problem B TransportationTITLEHTML version generated by K 5633 otas Koucky 1998HEADBODYH2 ALIGNCENTERACM International Collegiate Programming Contest 1338 9596H2P ALIGNCENTERBSponsored by MicrosoftBH3 ALIGNCENTERCent 0 140 117 5 17 51 100 86 14 24 62 22 32 18 99 40 91 76 71 25 130 35 59 80 77 12 63 85 26 138 50 48 89 96 45 36 94 137 104 33 125 72 10 120 37 115 27 73 78 56 60 134 54 116 97 123 93 79 111 30 68 70 69 92 23 110 106 132 52 135 81 61 43 3 47 102 87 139 38 113 53 121 107 49 98 44 128 1 119 101 8 41 109 136 29 103 84 9 31 7 112 65 126 122 133 108 64 16 2 19 95 83 118 11 34 6 105 28 88 74 127 131 140 57 20 46 4 67 13 15 129 75 114 124 42 82 58 66 55 21 39 90 28059 ral Eu 0 173 24 103 7 171 9 166 145 48 152 43 86 170 67 47 54 83 44 60 36 131 2 87 126 154 92 151 150 121 21 50 37 159 117 169 69 97 32 127 90 132 128 112 138 11 115 68 65 110 20 84 10 55 57 76 72 123 129 33 64 30 35 26 59 161 122 78 15 51 124 77 88 102 119 120 109 95 71 107 85 81 157 74 100 8 101 98 42 91 16 134 165 140 136 66 82 105 156 70 27 163 139 6 53 143 94 144 148 99 28 137 52 167 41 17 19 63 142 93 141 80 75 147 25 113 111 58 23 133 62 40 39 14 149 56 162 31 155 79 125 5 106 104 108 146 1 164 135 38 168 73 46 173 49 13 160 158 116 12 18 118 61 89 45 4 22 96 29 172 153 130 3 114 34 18254 ropean Regional ContestH3BRH2 ALIGNCENTERProbl 26258 em B TransportationH2P ALIGNCENTERBInput fileB tttraininttBRBOutput fileB tttrainoutttBRBProgram fileB tttrainpastt or tttraincppttPRuratania is 0 117 23 52 53 31 104 102 4 18 70 20 10 110 98 46 88 59 22 45 3 68 62 28 19 41 84 17 6 81 49 92 24 29 40 39 82 55 8 95 44 11 65 42 38 35 32 77 87 67 2 25 66 91 37 7 80 103 116 78 93 34 51 71 108 58 79 26 76 43 69 14 101 48 56 85 30 113 21 117 60 112 89 111 73 61 63 36 100 5 115 75 99 9 106 27 94 57 12 96 50 97 72 1 90 54 74 107 13 86 47 16 83 64 114 15 33 109 105 10632 just entering capitalism and is establishing new enterprising activities in many fields includi 0 87 15 2 36 29 5 82 84 33 45 6 1 41 71 20 10 50 27 78 87 69 24 17 11 38 12 52 26 68 63 64 53 79 54 62 46 77 8 42 30 70 35 51 75 3 40 67 44 14 23 16 56 48 58 61 57 74 9 28 34 72 25 21 73 47 66 13 39 32 80 18 43 65 60 59 49 37 31 4 76 86 22 19 85 7 83 81 55 18853 ng transport The transport 3335 ation company TransRu 31333 ratania is starting a new express tr 0 166 83 77 60 74 101 72 90 31 27 29 22 12 19 8 128 64 63 32 163 40 124 139 68 121 58 69 39 123 16 25 144 13 111 59 46 10 95 80 6 118 155 55 11 21 26 86 157 112 48 113 102 44 105 110 73 66 36 131 151 91 20 71 4 85 88 30 129 152 78 149 156 33 148 18 116 147 57 99 162 141 132 89 50 70 49 109 79 134 75 51 62 76 43 2 100 5 130 93 146 65 160 164 42 38 166 140 92 122 126 35 94 67 84 28 56 45 133 103 117 14 107 15 17 120 53 158 23 142 154 106 1 108 82 125 136 119 3 61 47 153 138 104 7 37 34 135 81 145 127 165 9 159 150 97 87 137 96 143 114 115 24 98 161 52 54 41 1733 ain from city IAIto city IBI with several stops in the stations on the way The stations are successively numbered cit 3749 y IAI stationhas number 0 city IBI station number ImI The company runs an experiment in order to improve passengertransportation capacity and thus to 5620 increase its earnings The train has a maximum capacity InI passengersThe price 0 135 10 54 111 18 129 1 76 106 124 61 51 97 45 131 79 68 39 117 31 125 84 105 24 109 93 32 47 9 46 74 11 29 26 16 132 43 23 72 108 57 64 49 19 135 96 90 133 73 66 71 104 21 81 55 33 116 123 86 130 34 12 99 28 127 67 78 121 128 112 85 41 30 80 98 69 91 122 25 13 15 87 59 40 101 48 102 2 82 92 4 58 36 3 56 8 113 14 65 115 7 88 22 103 53 114 42 38 27 110 100 6 134 70 60 120 126 44 94 50 77 118 107 63 37 95 52 83 75 35 17 20 119 5 62 89 11936 of the train ticket is equal to the number o 13912 f stops stations between the starting station and thedestination station including the destination station 0 107 8 100 3 107 19 37 46 39 101 105 44 85 23 21 68 17 28 35 87 67 27 58 54 73 98 69 82 7 32 45 36 88 56 76 49 33 48 52 50 74 15 102 84 61 104 34 22 60 78 71 57 55 59 86 66 26 10 11 99 2 9 81 83 72 16 80 20 75 43 18 5 24 79 41 51 12 6 30 103 91 92 90 38 31 29 62 4 89 77 70 1 13 25 63 93 47 96 94 14 65 95 106 97 40 64 42 53 7949 Before the train starts its route from the city IAI ticketorders are collected from all onroute s 5336 tations The ticket order from 0 18 9 1 6 13 3 7 4 8 12 10 11 5 18 16 2 14 15 17 24153 the statio 12207 n 0 72 25 16 46 18 22 29 33 28 10 56 38 11 50 62 47 8 2 58 39 43 26 57 63 30 14 3 71 23 15 24 7 44 35 66 27 67 68 54 4 20 5 13 48 12 49 64 55 21 34 65 41 40 69 42 32 17 60 51 52 53 45 59 36 72 61 37 6 9 19 1 31 70 5728 ISI means all reservations oftickets from ISI to a fixed destinati 4048 on 0 61 36 27 31 25 42 21 16 3 59 40 44 14 58 47 54 61 20 7 60 45 2 57 55 41 19 13 48 22 37 33 49 6 24 9 17 28 43 52 56 50 4 15 10 23 30 1 51 38 39 18 11 8 29 53 5 34 35 26 32 12 46 11761 station In case the company cannot acc 26229 ept all orders because of thepassenge 0 20 7 3 10 2 17 13 20 11 16 14 19 18 12 9 6 5 4 1 15 8 26639 r capac 22594 ity limitati 0 39 32 28 24 38 37 39 19 4 34 5 9 2 17 35 26 12 36 31 10 27 33 20 22 3 14 15 30 6 18 21 23 11 7 8 16 13 29 1 25 1160 ons its 0 105 36 37 33 13 75 9 14 92 17 28 34 30 43 49 56 73 70 94 57 84 82 39 83 8 87 18 7 80 3 58 16 61 41 66 64 20 29 51 46 19 86 102 48 81 76 90 31 67 50 5 79 68 38 15 12 104 47 98 32 45 26 27 65 72 4 35 25 69 52 42 2 10 22 24 85 101 88 40 95 6 89 97 63 44 23 78 53 60 99 77 71 100 11 1 105 54 91 21 103 55 62 59 96 74 93 509 rejection policy is that it either complet 13706 ely accept or completely rejectsingle orders from single stationsPWrite a program whi 0 106 91 43 23 47 59 52 54 88 6 44 73 46 89 8 9 27 83 71 14 70 36 90 37 98 56 39 32 81 30 12 17 2 85 62 57 29 1 67 55 74 51 33 15 25 72 76 58 78 13 10 5 48 11 19 60 35 28 96 24 103 69 3 4 99 104 105 86 63 101 80 22 100 16 45 92 49 65 42 87 84 41 7 40 95 38 106 20 26 79 102 82 64 75 31 50 21 61 34 94 68 53 97 18 77 93 66 14512 ch for the given list of orde 5905 rs from single stations on the way from IAI to IBI determinesthe biggest possible to 0 138 42 4 97 87 9 99 24 10 92 81 15 102 80 72 74 110 63 20 119 5 131 85 75 26 38 101 8 94 60 56 64 88 125 62 46 65 118 22 41 114 77 45 59 39 100 89 95 117 115 21 14 58 52 44 35 37 134 69 23 70 120 18 36 109 31 33 123 55 29 82 27 76 113 3 78 104 6 7 129 135 127 91 138 121 40 132 67 28 108 50 126 73 124 16 90 11 57 83 17 32 107 54 53 105 43 111 96 48 122 136 30 103 128 49 130 13 34 116 93 71 112 98 86 1 68 47 133 51 25 137 84 66 61 79 19 12 2 106 9447 tal earning of the TransRuratania company The ea 0 105 66 21 68 11 65 43 17 35 51 31 39 13 63 77 59 40 30 28 44 80 32 86 37 18 26 29 94 85 22 42 75 25 48 1 9 4 16 78 83 38 12 5 89 73 57 58 33 87 36 67 61 97 7 69 96 6 27 88 95 60 41 62 93 54 90 2 8 24 72 64 103 84 79 34 23 105 46 45 52 98 100 92 71 76 19 56 99 104 101 20 50 102 82 81 74 70 47 15 91 14 55 49 10 3 53 26444 rn 28958 ing from one accepted order isthe product of the nu 32025 mber of passengers included in the order 0 41 23 10 30 36 15 12 19 20 11 1 38 33 28 9 25 4 7 26 21 17 24 14 6 3 35 8 34 31 5 39 22 37 2 18 16 29 27 32 13 41 40 26820 and the price 0 141 113 53 91 84 21 5 9 57 79 8 14 40 42 98 28 54 3 109 67 130 83 82 104 111 120 38 115 125 50 124 10 56 16 47 46 17 1 45 94 30 43 68 114 74 97 89 37 22 61 23 76 105 49 116 15 137 110 92 134 78 77 102 118 12 69 6 139 33 127 62 32 85 52 80 106 121 31 112 27 129 117 39 51 138 44 95 133 122 132 24 59 93 128 25 101 119 34 99 35 86 140 90 96 63 19 131 55 48 29 71 20 13 73 2 58 81 7 88 66 64 126 70 123 100 141 11 136 108 36 135 60 26 4 87 41 103 107 75 72 65 18 24963 of their train tickets The to 0 59 5 51 44 13 50 36 38 55 32 7 21 3 33 27 22 30 10 15 11 12 18 34 43 41 58 54 1 16 31 37 53 14 23 52 59 9 26 56 57 6 35 45 28 39 25 48 40 8 17 4 49 42 47 20 24 46 29 19 2 22303 talearning is the sum of 25356 2625 the earnings from all accepte 0 30 12 16 4 9 2 20 24 18 22 14 15 19 1 27 30 17 11 26 7 8 29 10 13 21 25 5 23 6 3 28 19473 d order 14047 sH 28417 3Input 0 185 98 91 28 15 16 119 30 149 55 66 167 170 90 162 50 114 106 24 108 177 95 93 142 127 48 23 43 176 161 118 41 46 92 122 129 81 42 14 120 58 134 94 6 147 33 67 34 52 112 124 57 85 65 181 113 68 179 61 135 86 63 156 153 39 2 77 54 38 21 133 121 102 146 79 10 84 158 168 157 11 56 22 5 27 152 139 20 101 47 72 18 51 130 89 143 131 97 138 115 12 31 82 60 104 111 64 166 7 35 74 164 59 180 160 26 140 87 70 9 163 73 151 172 3 96 13 155 136 182 76 174 49 32 154 123 1 25 78 132 105 83 75 169 173 69 29 44 185 37 53 40 126 99 36 137 159 175 150 100 88 183 141 19 128 184 171 109 148 8 103 107 71 116 144 117 45 145 125 110 62 80 165 178 17 4 32066 H3The input file is divided into blocks The first line in each block contains three integers passengercapacity InI of t 23368 he train the number of the city IBI station and the number of ticket orders from all stationsThe next lines contain the ticket orders Each ticket order consist 16062 s of three integers starting stationdestination station number of passengers In one block there can be maximum 22 orders The number ofthe city IB 0 71 63 66 67 31 1 48 58 57 11 34 54 8 70 52 24 15 51 56 27 40 20 37 32 13 6 42 17 30 21 4 9 38 39 60 25 41 61 12 47 50 10 69 36 59 62 53 5 49 28 45 46 35 33 16 64 19 14 3 71 65 44 2 23 22 55 43 18 7 68 26 29 1063 I station will be at mos 9706 t 7 The blo 12633 ck where all three numbers in the first line are equal to zerode 0 68 54 28 20 46 16 11 5 65 61 15 41 52 36 49 8 42 57 12 50 31 9 51 43 40 62 29 32 63 39 25 22 67 14 47 6 64 23 2 44 58 55 21 45 7 30 37 56 38 60 66 34 19 10 3 35 33 68 24 27 59 4 18 1 53 13 48 17 26 19764 notes the end of the input fileH3OutputH3The outpu 6107 t file consists of lines corresponding to t 10646 he blocks of the i 0 14 6 4 7 9 3 10 14 12 5 13 8 11 2 1 22714 nput file exc 0 171 14 10 112 74 111 60 97 24 98 109 15 63 65 31 132 119 164 131 41 40 151 127 135 129 96 128 86 50 26 38 45 57 85 100 71 155 145 87 110 52 28 79 153 12 13 146 64 48 113 126 117 66 59 21 90 140 168 68 5 42 3 94 77 55 54 99 93 103 81 47 149 163 69 154 67 82 170 139 35 156 84 166 91 34 122 101 88 121 116 22 49 147 160 106 95 141 134 105 136 27 8 148 169 107 102 17 143 137 39 25 43 36 167 80 83 2 30 1 157 125 44 142 161 104 133 46 76 120 171 4 123 72 6 53 152 89 11 162 144 115 37 33 158 51 16 58 62 124 165 150 114 18 138 20 19 118 130 7 70 108 61 56 75 92 159 73 29 78 23 32 9 7159 ept the terminatingblock Each such line contains the biggest possible total earningH3ExampleH3BInput fileBPRE10 3 40 2 11 3 51 2 72 3 1 31199 010 5 43 5 102 4 90 2 52 5 0 49 13 12 19 15 46 7 9 1 11 49 21 35 39 45 17 4 23 24 25 47 8 6 44 27 38 31 29 34 36 48 26 5 2 3 18 20 10 22 41 42 14 33 40 32 28 43 16 37 30 17169 80 0 0PREBOutput fileBPRE1934PREBODY 0 174 17 2 146 69 95 129 11 118 113 62 159 59 23 38 73 28 55 16 152 155 31 32 76 30 124 49 65 96 128 64 33 80 54 171 35 81 102 132 70 58 97 149 88 107 168 21 72 114 125 104 19 142 103 126 130 10 60 120 85 43 18 135 24 169 158 101 27 39 52 77 7 1 162 165 13 91 37 71 109 42 14 67 148 108 86 112 26 36 115 111 134 127 79 116 53 99 87 173 41 136 29 170 161 84 157 117 74 90 83 45 140 50 93 153 138 145 63 57 44 8 106 22 56 34 137 100 163 9 174 105 61 75 12 110 141 164 78 150 25 172 119 15 4 160 147 166 20 5 92 3 154 66 167 151 46 6 98 122 51 68 47 131 48 156 121 94 139 123 144 40 89 82 133 143 21676 HTMLHTMLHEADTITLECERC 1995 Problem C Jo 8161 hns tripTITLEHTML version generated by Kotas Koucky 1998HEADBODYH2 ALIGNCENTERACM International Collegiate Programming Contest 9596H2P 2362 ALIGNCENTER 0 57 20 51 2 48 45 55 24 32 37 47 16 42 40 26 33 53 15 1 9 12 19 28 30 38 6 57 3 18 11 22 56 34 10 49 31 43 29 44 14 4 8 5 21 52 50 27 7 39 54 13 41 35 17 23 36 25 46 2300 BSponsored by Micro 15112 softBH3 ALIGNCENTERCentral European Regional ContestH 0 178 12 153 60 76 59 152 102 115 139 29 106 91 62 56 167 175 52 23 138 24 77 96 34 18 135 5 70 161 79 131 144 37 86 126 109 141 119 67 20 7 112 30 164 110 156 84 48 31 25 4 125 32 10 123 178 132 158 50 82 81 39 105 8 166 69 49 94 128 68 74 44 26 51 35 61 140 78 104 160 103 92 117 83 1 118 157 41 162 97 176 113 163 95 42 66 133 99 98 89 149 124 71 122 47 136 90 173 16 53 134 155 169 114 17 46 168 87 174 120 6 151 146 148 45 54 80 145 171 72 130 75 101 127 28 57 3 121 58 9 38 172 55 165 27 85 108 36 14 22 40 2 143 43 159 93 11 170 147 154 150 33 142 21 88 65 13 100 64 19 137 129 116 177 15 63 111 73 107 24259 3BRH2 ALIGNCENTERProblem C Johns tripH2P ALIGNCENTERBInput fileB tttripinttBRBOutput fileB tttripoutttBRBProgram fileB tttrippastt or tttripcpp 28127 ttPLittle Johnny has got a new car He decided to drive around the town to visi 4615 t his friends Johnnywanted to visit a 0 89 1 18 54 15 53 58 73 34 30 38 89 88 25 45 13 85 87 5 67 27 17 4 3 39 65 62 35 77 32 70 11 49 47 40 10 8 48 42 43 83 84 9 33 44 22 69 72 59 68 79 63 60 24 78 2 37 29 31 51 66 52 26 23 21 28 75 82 19 64 12 7 6 71 86 55 76 41 46 56 20 14 16 74 80 61 57 36 81 50 10074 ll his friends but there was many of them In 31377 each street he had one frien 0 5 4 5 3 1 2 7328 d He 0 41 15 4 18 38 39 11 8 13 14 20 6 27 9 26 34 37 2 17 36 28 1 32 19 40 33 30 21 3 35 12 29 22 24 16 23 41 10 5 25 31 7 20712 startedthinking how t 14677 o make his trip 23880 as 0 151 2 57 142 136 63 31 125 89 34 55 19 48 148 116 44 118 84 127 39 38 83 126 32 67 17 151 47 140 50 128 70 13 4 3 87 131 114 139 123 147 82 49 65 141 90 150 15 91 80 103 76 26 68 106 81 69 112 66 97 12 105 145 35 102 56 14 109 40 51 122 79 71 143 111 110 73 144 120 86 96 25 98 88 115 133 92 42 9 24 149 58 121 137 99 129 113 138 64 135 78 43 134 22 75 21 28 36 45 60 117 146 30 29 62 100 94 41 6 37 85 108 132 11 95 104 54 74 107 33 10 18 119 93 16 20 72 53 46 1 27 77 23 124 5 101 59 130 7 8 61 52 30015 short as possible Very soon he realized that the best way to do it was totravel thro 24745 ugh each street of town only once Naturall 3754 y he wanted to finish his trip at the same place hestart 0 23 2 4 9 13 3 18 16 1 5 19 8 15 6 7 17 11 22 10 14 21 23 20 12 24080 ed at his paren 0 43 17 39 16 37 6 14 1 41 33 36 25 3 22 31 21 32 35 13 8 30 19 40 26 5 20 28 29 9 24 42 15 12 34 38 7 18 2 10 11 27 23 4 43 21919 ts housePThe streets in Johnnys town w 0 130 107 84 27 2 42 59 8 13 55 34 82 85 9 111 115 71 63 16 53 3 65 24 45 83 4 62 69 89 61 44 14 99 73 38 40 81 26 43 66 126 112 108 21 47 87 46 64 95 15 7 41 10 25 109 20 74 120 56 90 79 5 68 94 100 121 70 86 30 37 110 101 51 50 130 23 80 105 88 11 127 103 129 18 78 52 102 54 57 31 96 22 58 33 72 6 119 92 76 77 113 116 48 128 91 122 106 49 1 98 19 12 75 67 104 93 125 36 60 29 123 124 97 117 35 28 32 39 17 118 114 12097 ere named by integer numbers from 1 to InI InI 0 75 23 29 35 13 71 58 20 34 25 12 53 59 24 60 9 45 49 74 46 2 73 14 17 52 1 31 15 40 69 64 70 55 21 47 38 67 33 30 66 41 54 10 19 4 7 65 11 8 32 36 68 6 57 50 72 39 5 18 63 28 42 26 16 27 51 56 61 3 44 75 48 22 62 43 37 27623 lt 1995 The junctionswere independently named by integer number 0 127 29 35 75 118 15 70 123 105 81 113 45 80 13 14 32 78 69 21 127 50 56 31 62 67 3 58 117 97 41 79 28 25 30 124 40 92 65 16 103 85 18 104 34 76 9 33 122 47 114 52 121 119 93 8 6 98 55 22 10 99 126 64 73 61 72 36 88 84 87 27 12 100 37 2 101 106 77 17 46 57 94 44 51 95 11 49 109 20 110 63 24 42 26 108 23 60 4 96 43 111 83 5 86 115 91 39 107 102 112 7 1 38 125 116 90 68 89 120 66 59 74 19 54 53 71 82 48 13838 s from 1 to ImI ImI lt 44 No junction connects more 0 47 16 32 33 12 14 27 11 18 3 21 1 36 38 40 28 37 45 31 25 17 42 35 29 8 7 22 44 47 26 39 34 5 41 43 46 24 2 30 19 9 23 6 15 10 13 4 20 28166 than 44streets All junctions in t 0 4 1 3 2 4 2092 h 8035 e to 31740 wn h 0 22 3 17 5 4 13 8 10 22 16 9 20 2 7 6 18 1 19 12 14 11 15 21 16567 ad differe 0 106 95 74 32 75 64 100 3 37 30 17 12 21 56 46 27 72 86 20 91 52 50 51 53 4 8 60 35 98 57 48 18 49 69 73 101 34 38 11 61 25 90 96 10 33 87 105 70 9 5 2 47 63 102 41 13 1 85 81 26 77 62 92 71 24 44 67 65 66 97 55 78 36 45 104 15 39 89 14 54 40 82 42 7 19 16 29 83 22 43 103 106 93 99 88 59 84 6 31 68 76 28 58 94 23 80 79 21210 nt numbers Each street was connecting exactly two junctionsNo two streets in the town had the 28423 same number He immediately started to plan his round trip If ther 14205 ewas more than one such round trip 0 118 72 109 17 41 96 54 71 90 46 35 27 23 81 32 18 16 9 37 39 26 11 108 67 56 53 93 25 61 31 51 88 63 92 101 95 30 114 2 33 38 52 112 59 58 86 91 42 80 83 64 74 40 49 107 24 106 36 28 85 104 66 57 102 103 20 8 97 69 7 29 19 76 22 82 50 10 118 105 100 77 68 111 115 84 60 79 45 113 48 98 78 6 44 89 3 110 75 34 14 13 70 87 73 116 99 62 117 12 94 4 21 43 1 15 55 5 65 47 20413 he would have chosen the one which when written down as a sequenceof street 10511 numbers is l 12931 exicographically the smallest But Johnny was not able to find even one such r 0 138 131 18 15 22 108 62 33 118 84 120 3 58 21 90 27 31 96 7 100 97 30 45 81 11 133 29 125 78 38 107 69 13 6 83 54 63 109 129 46 32 43 56 47 35 88 80 75 79 49 59 136 132 95 53 1 23 76 39 105 4 121 86 99 122 119 71 111 134 64 114 65 135 89 41 50 110 12 36 28 106 103 34 40 124 87 127 17 68 104 123 9 24 73 101 82 94 102 126 137 57 116 91 55 115 130 98 128 2 5 70 74 20 8 72 66 51 60 10 112 42 77 25 26 14 37 138 67 92 52 19 61 117 16 93 44 113 85 48 9066 oundtripPHelp Johnny and write a 31821 program which finds the desired shortest round trip If the round trip doesnot exist the pr 0 27 4 6 20 5 8 19 15 9 21 3 16 24 17 22 11 13 18 26 7 1 27 25 2 12 14 23 10 14371 ogra 30522 m 0 127 46 41 74 81 16 52 101 83 37 23 34 20 43 112 13 79 77 17 26 36 9 125 118 104 116 86 32 82 107 105 69 51 91 5 50 44 56 108 1 25 119 73 87 30 106 115 6 111 33 113 95 92 67 39 75 57 48 72 24 18 35 65 63 8 19 27 109 121 89 93 7 88 45 59 98 49 15 22 68 103 14 47 117 123 40 126 70 58 53 110 120 100 42 38 55 71 102 124 11 64 3 127 21 94 2 60 29 90 114 97 76 122 66 31 80 12 84 61 28 62 99 78 54 96 10 85 4 30886 should write a message Assume that Johnny li 22853 ves at the junction ending the 0 19 18 11 19 17 4 12 14 3 2 6 13 7 1 5 10 8 16 9 15 3884 streetNo 19784 1 with smaller num 1297 ber All s 0 53 21 5 33 3 39 25 16 36 15 37 17 40 24 50 35 20 46 34 27 48 9 7 23 8 18 32 44 14 28 45 41 53 29 10 52 4 51 30 13 42 19 31 11 1 2 47 26 49 43 22 38 6 12 21291 treets in the town are two way There exists a 11923 way f 0 110 69 105 49 5 96 93 24 103 14 16 18 50 70 38 104 97 82 78 55 25 89 36 20 98 88 13 100 6 45 39 33 31 108 10 2 43 11 66 56 106 109 84 1 63 28 12 94 79 53 64 87 71 95 76 46 41 9 59 86 52 40 74 57 83 32 17 8 90 102 60 44 101 35 75 27 4 110 30 61 15 42 7 34 51 68 29 26 99 65 73 48 22 54 81 58 21 23 19 107 92 77 67 37 91 80 3 85 72 62 47 16933 r 0 187 25 15 125 72 66 107 145 37 69 60 143 19 67 55 38 49 187 177 51 93 165 30 76 83 52 172 183 124 24 102 54 137 80 144 65 121 8 89 86 44 63 184 118 45 186 116 53 57 146 179 161 160 87 3 134 48 133 35 147 141 91 5 32 68 156 75 77 114 70 136 117 2 58 106 128 92 111 12 78 71 180 96 100 158 73 31 150 113 115 109 17 56 140 110 181 10 159 127 162 108 166 130 61 14 120 97 23 46 28 74 21 176 94 142 11 50 170 131 99 98 126 153 152 178 7 182 42 103 154 43 122 104 27 119 41 85 155 135 62 112 26 164 123 167 36 39 4 13 138 40 9 22 168 157 148 169 163 64 34 29 88 132 95 101 129 81 79 82 105 84 139 173 171 174 6 175 151 59 1 16 18 47 185 20 33 90 149 5506 om each street toanother street in the town The streets in the town are very narrow and there is no possibility to turn backthe car once he is i 0 97 1 75 18 86 33 55 22 52 76 91 62 13 79 27 87 19 25 82 3 94 17 69 74 57 60 28 53 65 63 83 97 34 14 37 72 51 21 50 29 45 15 42 16 38 46 30 5 7 95 84 26 8 88 93 54 67 40 2 90 85 12 77 9 89 39 10 11 78 24 71 48 96 43 92 31 64 41 49 47 68 6 61 58 70 73 32 66 56 80 20 23 44 59 36 4 35 81 6929 n the streetH3In 0 153 47 11 28 30 44 40 58 88 85 148 131 32 59 31 43 146 62 74 4 45 86 111 141 7 64 56 142 96 109 8 51 70 52 93 1 153 110 151 138 39 87 42 29 13 105 83 15 118 81 107 73 106 133 48 136 34 71 22 79 102 61 147 27 14 36 139 76 72 21 84 103 122 41 115 104 55 10 24 100 90 112 77 92 135 50 97 132 38 130 149 6 82 5 126 99 3 89 9 23 101 26 63 140 80 35 65 120 152 137 127 25 94 60 18 91 150 128 129 17 144 78 116 134 75 67 37 53 124 49 98 117 20 145 16 119 2 114 57 123 33 69 54 108 113 95 19 66 121 143 68 12 125 46 15748 putH3Input file consists of several blocks Each block describes one town Each li 28516 ne in the block containsthree integers IxI IyI IzI where IxI gt 0 and IyI gt 0 are the numbers of junctions which are connected by the s 25757 treetnumber IzI The end of the block is marked by the line containing Ix 0 92 35 44 34 16 14 61 13 32 87 83 26 19 3 55 72 64 24 25 39 43 49 30 20 28 90 4 74 5 84 18 11 82 59 40 75 47 6 58 62 31 60 7 52 70 8 51 17 15 42 71 2 1 50 53 78 88 66 67 21 22 36 65 76 45 33 77 27 29 79 73 85 68 57 54 81 92 89 46 63 86 91 9 80 69 38 37 23 12 41 56 48 10 20817 I IyI 0 At the end of the inp 32601 ut filethere is a 27665 n empty block IxI 0 158 134 59 40 53 51 6 158 131 42 17 73 35 104 38 23 7 107 153 91 5 101 106 103 117 92 68 46 85 9 75 90 57 83 48 13 74 126 4 10 24 121 102 65 123 110 118 47 30 3 16 129 128 60 63 64 41 21 120 119 31 58 80 14 136 1 37 151 105 87 22 111 55 77 97 98 45 95 127 99 62 29 144 140 109 78 100 81 49 39 69 154 86 137 76 139 18 54 33 34 114 146 147 70 2 19 8 43 152 116 133 71 27 125 66 79 36 130 50 112 96 138 141 61 142 94 132 122 88 145 108 32 82 12 26 124 28 93 11 84 156 44 155 25 115 148 149 56 15 113 52 157 135 67 20 143 150 89 72 29238 IyI 0H3OutputH3The outpu 0 183 19 115 114 22 41 103 122 152 97 34 62 119 83 12 59 20 3 86 2 108 23 173 24 157 137 126 110 93 127 105 104 44 79 8 60 156 61 6 69 124 56 31 36 141 78 5 65 118 25 130 28 10 11 88 144 136 92 146 134 121 57 35 176 91 179 53 96 182 68 54 27 99 46 13 52 67 89 154 42 166 148 160 29 85 169 15 30 177 18 133 70 107 95 109 153 9 120 48 161 84 74 55 142 116 64 158 87 174 155 73 80 33 7 72 132 135 113 112 140 90 165 139 125 14 63 76 150 94 38 123 98 45 117 143 71 75 50 58 4 129 66 164 43 181 171 82 51 101 100 180 39 145 26 172 32 17 49 163 37 183 40 149 170 162 1 16 77 81 168 21 147 138 167 178 175 47 159 128 131 106 151 102 111 26218 t file consists of 2 line blocks corresponding to the blocks of the input file The first line ofeach block contains the sequence of street numbers single members of the sequence 5137 are separated by spacedescribi 0 167 142 49 65 58 92 117 44 18 17 42 68 75 29 131 9 91 64 12 81 152 107 134 67 66 167 28 77 85 149 141 99 4 38 19 53 94 118 43 144 30 160 34 52 26 128 39 16 101 115 55 127 166 14 23 151 84 97 140 20 61 135 59 82 46 10 121 113 54 155 45 7 5 146 35 86 70 88 106 93 89 147 73 25 138 98 31 148 103 32 136 132 37 111 79 154 119 125 33 36 161 133 110 122 123 157 11 109 108 96 156 124 57 102 71 130 114 56 8 48 74 47 137 164 158 90 100 27 1 116 126 22 3 72 112 60 80 13 163 120 145 51 165 2 76 95 139 6 104 162 62 15 105 41 153 143 78 87 129 150 159 21 63 83 69 50 24 40 32614 ng Johnnys round trip If the round trip cannot be found the corresponding output block containsthe message ttRoun 7683 d trip does not existtt The second line of each block is emptyH3ExampleH3 12978 BInput fileBPRE1 2 12 3 23 1 61 2 52 3 33 1 40 01 2 0 160 35 25 148 46 126 22 66 156 17 50 125 112 70 108 14 143 109 100 110 1 98 104 80 43 122 133 131 147 102 45 44 138 85 10 20 68 141 48 39 71 154 82 95 103 145 74 155 130 146 124 51 78 36 15 106 113 41 134 96 142 52 120 119 49 137 55 60 150 99 13 79 12 37 116 160 128 56 61 58 27 67 93 6 72 75 2 105 19 81 11 121 77 3 76 84 90 83 158 59 88 32 8 40 30 94 26 5 9 89 144 69 29 21 86 63 47 24 132 107 118 159 111 28 152 7 139 153 73 42 101 23 31 123 62 149 136 18 34 92 57 97 151 16 33 135 87 53 4 157 127 114 140 38 64 115 65 117 129 54 91 7662 12 3 21 3 32 4 40 00 0PREBOutput fileBPRE1 2 3 5 4 6 Round trip does not existPREBODY 8173 HTMLHTMLHEADTITLECERC 1995 Problem G CipherTITLEHTML version generated by Kotas Koucky 1998HEADBODYH2 ALIGNCENTERACM International Collegiate Programming Cont 10800 est 9596H2P ALIGNCENTERBSponsored by MicrosoftBH3 ALIGNCENTERCentral European Regional ContestH3BRH2 ALIGNCENTERProble 0 152 66 13 59 71 146 41 149 95 107 16 75 150 27 73 100 47 118 113 34 97 12 121 42 106 55 99 115 52 140 17 141 14 90 105 22 128 91 123 58 25 89 9 70 54 138 4 120 61 94 74 136 64 28 129 57 101 43 40 39 124 79 68 98 2 85 11 112 20 36 108 19 151 77 82 78 125 88 21 23 62 46 144 84 87 8 26 130 5 56 1 134 67 50 110 7 131 80 104 102 147 114 135 76 33 60 69 72 83 139 119 111 127 92 96 48 81 18 3 10 93 30 122 103 65 126 109 24 44 116 37 29 145 137 15 45 53 142 132 38 51 86 63 6 35 133 31 143 49 148 32 117 152 9759 m G CipherH2P ALIGNCENTE 16527 RBInput fileB ttcipherinttBRBOutput fileB ttcipheroutttBRBProgra 0 3 1 2 3 17554 m 0 157 83 104 122 154 2 139 82 51 10 32 22 114 93 75 105 106 15 66 135 33 57 16 129 11 45 98 76 63 53 73 69 35 81 116 102 40 115 113 26 138 65 13 107 21 136 152 144 146 68 148 128 23 46 19 74 17 79 112 71 134 120 6 30 61 88 18 100 67 124 101 54 149 25 99 20 96 27 50 121 108 36 12 42 80 125 8 47 147 52 1 34 48 9 119 117 56 141 133 7 137 29 153 126 123 127 70 38 110 62 28 44 97 87 156 55 84 49 145 130 85 4 59 39 37 94 131 5 86 60 24 140 78 89 132 142 31 14 150 111 41 109 118 95 155 90 143 58 3 91 72 151 77 157 64 43 103 92 11945 fileB ttcipherpastt or ttciphercppttPBob and Alice started to use a brandnew encoding scheme Surprisingly it is not a Publi 0 187 26 82 93 78 83 56 184 22 73 37 175 110 72 179 178 10 27 90 59 182 127 132 61 183 94 63 86 141 24 38 42 67 79 154 11 126 58 53 57 39 169 49 159 108 15 101 138 91 92 33 187 48 116 151 35 62 137 32 170 105 84 119 128 16 125 87 40 129 186 100 117 75 5 166 144 102 19 164 71 34 64 147 85 109 160 97 95 14 23 133 81 89 103 60 20 44 51 25 180 114 68 152 65 177 155 121 77 111 107 145 28 21 17 131 140 13 158 113 163 185 54 69 55 104 136 130 174 161 168 134 118 74 139 173 176 106 181 149 2 171 165 1 70 99 142 156 146 36 120 148 50 172 7 29 162 6 8 76 18 143 46 122 9 3 123 167 80 153 157 98 88 112 30 31 124 12 47 66 43 135 115 41 96 4 150 45 52 22577 c Key Cryptosystem but their encoding and decoding is based on secr 0 12 1 11 12 2 9 5 10 6 7 3 4 8 28933 et keys 0 51 37 10 31 6 8 29 46 23 28 38 7 4 32 40 48 34 35 49 27 22 13 24 16 47 26 42 51 2 30 44 39 33 9 20 45 11 1 5 3 19 21 25 12 43 36 50 41 15 17 18 14 19840 They chose the secret 23838 key at their lastmeeting in Philadelphia on F 25696 ebruary 16th 1996 They chose as a secret key a seq 0 86 65 16 33 25 20 49 56 27 11 77 66 60 26 2 52 1 43 73 63 40 81 54 78 57 3 47 13 6 41 76 72 68 35 19 59 44 39 30 61 85 80 86 24 62 53 83 17 15 21 69 4 31 18 12 64 10 84 51 67 8 22 74 75 46 42 58 5 48 14 71 29 82 37 50 23 32 55 38 34 45 79 7 28 9 36 70 9545 uence of InI distinct integers IaI1 IanI greater than zero and less or equal to 18566 InI The encoding is based on the following principleThe message is written dow 0 143 56 66 102 100 27 44 43 105 45 138 76 60 73 128 111 137 17 104 116 52 29 118 101 108 1 62 12 67 141 83 4 103 53 57 143 107 69 64 15 86 91 33 80 109 54 134 38 11 68 125 126 58 90 40 49 72 124 20 16 110 121 71 95 120 22 42 6 30 77 75 61 119 37 84 131 26 70 136 98 82 94 65 21 50 132 93 122 32 14 140 19 112 114 47 51 133 88 2 24 89 129 5 8 35 23 39 113 127 139 13 81 25 63 34 41 96 117 99 123 46 18 7 55 130 28 3 87 142 9 48 79 92 115 97 135 106 74 85 31 59 36 10 78 6152 n below the key so that characters in the message and numbers in the key arecorrespondingly 10567 aligned Character in the message at the position 0 93 12 2 49 35 23 42 4 39 66 37 88 15 32 53 65 79 26 83 51 73 67 76 54 70 69 44 72 74 80 38 17 55 24 62 28 46 91 57 60 47 59 22 68 30 10 20 25 56 58 82 27 52 16 63 3 1 7 81 71 18 92 21 93 40 6 11 64 77 87 43 8 89 86 14 61 48 75 84 78 34 41 45 33 85 9 13 36 5 31 50 29 90 19 3373 IiI is written in the encoded message at th 10083 eposition IaiI where 6893 IaiI is the corresponding number in 0 25 4 1 22 12 16 5 17 18 11 23 24 10 7 20 21 3 15 6 14 8 25 2 19 13 9 3818 the key And 0 56 22 3 26 37 24 46 23 16 4 8 34 38 6 14 21 47 43 29 53 27 5 56 13 32 18 49 30 7 9 11 25 10 28 42 50 12 35 1 31 41 45 52 33 20 40 48 55 19 17 15 51 54 2 36 39 44 2285 then the encoded message is enco 22616 ded inthe same way This process is repeated 0 140 71 76 96 139 12 140 130 102 132 87 13 111 30 125 22 94 84 5 41 31 19 38 99 49 20 104 11 14 43 137 68 17 40 65 42 78 90 85 44 127 32 113 109 55 34 119 57 54 117 3 8 66 10 124 97 33 59 52 67 6 69 121 27 88 123 61 1 95 116 72 48 101 91 136 62 83 37 89 115 74 82 86 129 131 110 51 50 15 105 103 93 114 23 36 28 9 16 79 112 60 46 118 7 63 26 53 35 58 45 138 29 122 73 75 92 135 39 2 70 4 100 134 77 24 81 80 98 21 133 107 25 120 128 108 64 56 47 126 18 106 986 IkI time 24816 s After IkIth encoding they exchange their messagePThe length of the message is always less or equal than InI If 23080 the message is shorter than InI then spacesare added to the end of the message to get the message with the 0 62 35 52 46 25 58 59 20 50 19 31 24 39 60 8 36 37 42 27 23 49 29 2 53 51 45 48 41 34 61 5 40 32 33 56 10 55 43 38 16 1 28 26 15 54 18 44 22 4 7 13 12 11 47 21 6 17 9 3 62 30 14 57 12413 length InIPHelp Alice and Bob and write prog 20790 ram which reads the key and then a sequence of 0 38 35 6 24 15 11 31 10 27 7 3 20 13 33 22 17 14 18 23 28 12 34 32 36 26 16 5 19 30 21 2 9 37 4 38 25 29 8 1 802 pairs consisting of 0 140 14 10 38 83 140 82 37 87 27 85 29 111 74 13 80 20 41 2 89 42 103 139 101 110 102 59 25 24 63 22 33 36 112 57 78 138 19 3 11 66 30 55 40 4 120 62 91 93 50 76 1 17 73 26 53 16 100 105 6 129 9 61 43 121 77 104 64 132 123 130 117 106 107 71 51 90 86 114 92 134 52 81 133 128 75 118 23 135 58 108 99 119 56 88 45 34 126 116 84 68 127 60 67 31 109 44 12 113 21 70 54 18 115 97 15 122 98 94 65 48 32 28 137 124 131 69 39 35 72 96 8 5 95 7 136 49 125 79 46 47 31156 IkI and message to be encoded IkI times and produces 27537 a list of encoded messagesH3InputH3The input file consists of several blocks Eac 28347 h block has a number 0 lt InI lt 200 in the first li 0 60 25 36 45 40 22 18 3 13 35 9 53 46 27 12 37 1 52 30 24 2 31 44 50 23 20 6 48 57 51 11 54 42 4 15 21 58 29 16 5 8 56 28 41 26 38 39 47 59 14 55 43 19 32 17 60 34 33 10 7 49 28041 ne Thenext line contains a sequence of InI 27663 numbers pairwise distinct and each greater than zero and le 0 55 25 9 32 16 11 34 30 53 51 24 12 14 19 48 44 37 27 15 50 4 3 28 55 47 35 5 46 23 1 29 20 42 10 49 22 13 18 52 17 21 36 54 7 6 38 33 43 41 8 2 39 31 45 26 40 3626 ss or equal 9883 than InI 0 19 8 4 10 5 3 7 17 18 15 19 14 2 12 13 6 1 16 9 11 1533 Next lines co 28472 n 0 131 11 75 28 85 68 109 50 90 16 48 10 114 106 99 24 26 46 33 23 118 56 91 82 69 18 52 78 54 9 88 76 2 3 34 53 29 116 4 117 61 60 112 126 49 70 36 66 67 20 65 111 27 104 94 71 107 123 89 45 84 120 80 62 8 103 86 64 19 74 55 51 22 14 87 119 25 6 125 83 122 7 124 5 100 131 38 58 15 41 30 129 12 42 79 92 121 105 44 17 59 95 113 110 98 101 31 93 21 115 72 108 81 35 102 37 57 127 63 130 1 73 96 32 128 13 43 40 39 97 47 77 10731 tain int 24373 e 0 118 106 24 115 66 36 108 73 87 22 7 45 9 8 60 50 59 89 80 91 72 21 78 83 79 46 32 41 19 44 103 69 77 53 52 26 47 100 51 31 25 38 28 49 82 20 29 85 112 65 61 84 35 54 63 99 57 17 95 34 81 116 75 39 30 42 40 4 107 86 109 10 76 15 68 113 3 114 27 14 88 96 67 93 118 48 71 13 111 16 33 12 43 97 2 6 56 94 37 5 11 64 102 18 23 1 70 74 62 110 101 92 98 58 55 105 104 117 90 12050 ger number IkI and one message of ascii chara 0 11 3 7 8 11 10 6 4 9 1 5 2 31951 cters 9957 se 23676 para 0 167 30 60 59 100 150 148 68 65 159 25 83 90 66 89 130 28 67 128 149 77 24 107 44 75 124 101 49 50 72 120 163 102 96 105 1 95 37 4 26 15 10 166 78 41 80 61 22 3 76 32 47 158 153 145 53 36 69 121 7 13 155 97 114 112 165 127 45 20 138 151 129 135 64 162 43 17 132 5 104 126 29 14 39 12 74 160 141 63 134 110 144 21 111 133 18 98 103 62 11 108 131 71 23 99 35 40 156 9 52 87 16 93 38 94 6 137 85 42 31 84 115 91 119 27 55 86 81 33 146 88 113 58 117 142 157 46 154 48 143 147 140 70 79 139 106 8 122 54 118 123 73 82 167 161 136 109 152 164 116 56 57 2 92 125 34 51 19 31339 ted by one spaceThe lines are ended with tteoltt this tteoltt does not be 0 170 168 159 64 36 162 125 100 133 51 134 60 132 54 113 49 37 75 110 20 65 156 129 76 115 43 94 99 66 58 90 101 31 163 158 72 46 38 40 42 102 81 35 22 117 111 91 131 50 85 128 87 33 123 26 79 62 55 18 160 82 155 56 70 167 6 10 121 45 15 166 48 84 105 96 108 97 53 41 7 89 73 92 170 154 25 71 119 17 1 161 77 11 9 13 146 116 29 152 88 149 86 95 139 151 114 169 52 107 143 164 137 74 47 104 23 120 21 142 130 147 28 19 157 32 109 68 2 98 135 148 67 93 83 5 30 138 126 165 4 144 16 39 3 69 8 106 141 78 57 80 63 103 153 12 112 61 59 27 14 127 24 34 44 145 150 118 122 124 140 136 25691 long to the message The block ends with th 3819 e separate linewith the number 0 After the last block there is in separate line the number 0H3OutputH3Output is divided into blo 28697 cks corresponding to the input blocks Each block contains the encoded inputmessages in the same order as in input 0 144 130 64 50 67 69 89 53 84 113 54 47 72 88 71 32 48 2 37 15 117 129 131 28 51 75 121 33 99 60 109 45 40 92 17 36 125 3 97 132 85 41 39 133 35 139 111 138 38 76 13 95 112 127 22 114 68 18 25 10 128 137 21 70 8 143 86 123 66 118 42 57 27 101 94 7 58 19 103 102 100 26 140 110 12 90 106 23 108 4 52 80 46 104 56 61 55 49 136 11 116 29 126 73 119 87 24 144 16 43 141 62 135 122 34 78 77 1 142 107 105 14 74 6 9 98 20 82 5 59 120 115 134 81 65 30 93 63 96 83 79 91 31 124 44 31205 file Each encoded message in the output file has the lenght InI Aftereach block there is one empty li 10819 neH3ExampleH3BInput fileBPRE10 0 169 30 28 52 82 74 38 156 155 17 2 45 68 12 31 33 4 106 121 100 25 37 27 130 15 150 59 143 8 21 19 3 49 78 146 65 140 18 105 151 145 112 131 87 42 126 35 29 58 1 57 51 141 134 16 75 43 118 107 63 67 46 111 88 70 138 10 132 120 101 122 79 26 148 168 149 44 102 86 84 61 108 69 97 110 163 23 7 162 80 64 103 95 135 94 90 36 93 169 72 98 13 144 48 128 24 116 124 160 164 152 127 91 115 20 109 165 34 123 117 92 11 159 129 133 136 39 89 41 167 47 66 142 40 9 139 154 5 50 119 85 147 32 76 60 113 158 99 137 125 55 56 81 96 157 53 6 104 161 166 83 114 153 73 77 62 14 22 71 54 19776 4 5 3 7 2 8 1 6 10 91 Hello Bob1995 CERC00PREBOutput fileBPREBolHeol bC RCEPREBODYHTMLHTMLHEADTITLECERC 1995 Problem E Dep 0 20 19 17 9 8 13 16 10 5 14 1 11 3 20 12 7 2 4 18 6 15 8535 artmentTITLE 0 163 49 137 56 27 95 6 130 100 11 37 54 96 60 73 163 155 47 44 89 105 64 104 43 29 28 112 12 4 92 148 110 131 75 160 87 121 3 66 45 81 20 151 18 15 109 153 77 52 24 129 86 34 150 140 158 84 70 103 162 21 136 63 135 120 16 51 46 117 53 26 8 94 101 72 108 93 71 65 142 62 25 55 83 69 14 114 76 143 80 116 91 2 36 40 141 58 124 113 13 19 127 122 159 88 111 39 156 7 35 119 107 139 32 23 41 147 138 67 31 123 78 154 97 132 98 85 74 17 82 146 115 134 106 68 102 145 126 79 157 90 10 152 33 9 144 38 30 61 125 118 57 161 99 42 22 149 48 1 133 59 128 50 5 14899 HTML version generated by Kotas Koucky 1998HEADBODYH2 ALIGNCENTERACM International Colle 4961 giate Programming Contest 9596H2P ALIG 0 148 47 5 26 31 6 3 73 100 16 39 104 79 42 102 18 122 137 10 143 147 103 43 41 36 38 32 53 33 132 60 112 57 54 28 48 4 126 116 55 123 86 34 138 142 141 94 61 27 7 105 108 136 13 95 20 9 45 46 74 63 82 66 135 146 145 49 17 81 127 37 77 130 35 92 11 107 111 129 80 21 68 50 85 90 25 87 93 30 19 22 58 97 91 59 124 109 125 128 76 99 133 52 69 72 8 131 120 110 139 51 140 119 24 23 70 101 148 106 56 71 67 12 2 65 114 121 98 96 44 113 134 144 75 15 118 62 117 84 1 83 115 88 78 40 29 89 64 14 19331 NCENTERBSponsored by MicrosoftBH3 ALIGNCENTERCentral European Region 0 160 102 59 41 139 2 8 148 37 77 40 132 160 146 134 92 105 66 81 17 76 56 34 45 12 79 95 120 98 84 21 97 86 62 99 5 67 114 10 110 85 153 124 9 127 88 29 122 68 71 54 1 55 89 26 133 150 142 125 147 30 43 118 116 144 159 20 91 157 70 149 100 128 145 69 112 126 96 101 53 151 60 140 104 123 11 49 117 90 33 121 58 38 44 19 25 23 14 83 35 16 48 6 47 31 74 18 141 103 61 137 119 27 131 156 50 13 15 4 36 113 136 94 51 24 78 158 155 28 57 115 138 3 82 63 143 87 108 46 109 22 32 152 154 106 93 42 80 64 39 135 52 75 111 107 7 72 65 130 73 129 26958 al ContestH3BRH2 ALIGNCENTERProblem E DepartmentH2P ALIGN 13741 CENTERBInput fileB ttdeptinttBRBOutput fileB ttdeptoutttBRBProgram file 0 176 98 90 110 12 166 97 60 83 86 29 140 128 160 117 55 96 152 57 5 18 172 135 80 47 63 115 70 92 133 119 25 59 75 121 94 14 4 17 113 89 176 33 67 35 79 87 151 175 157 69 34 173 106 53 165 48 23 88 91 81 2 111 103 40 138 1 46 132 20 6 85 171 93 61 9 150 24 30 74 108 155 149 19 28 104 101 64 162 52 36 109 164 146 159 105 76 26 153 122 13 102 107 174 72 137 126 116 167 16 82 143 127 49 123 41 68 129 145 73 136 42 38 148 66 71 58 37 54 15 130 100 77 11 65 62 8 147 10 125 154 163 156 144 50 170 112 78 141 142 45 32 139 131 7 158 22 43 51 39 27 168 99 118 3 114 21 169 120 44 95 56 84 31 124 134 161 5172 B ttdeptpastt or ttdeptcppttPThe D 2479 epartment of Security has a new headquarters build 0 49 1 22 14 5 48 26 12 13 31 35 39 3 43 20 33 23 9 8 7 29 10 34 18 24 16 4 38 44 17 42 32 37 45 6 30 15 27 46 21 47 19 28 2 40 11 49 36 41 25 19151 ing The building has several floors and on 14088 each 7108 floor there are rooms numbered IxxyyI where Iy 0 97 24 43 16 71 40 89 15 5 53 92 46 75 22 8 68 82 44 93 28 25 64 72 60 20 33 88 37 17 36 90 7 76 63 65 30 21 49 3 34 19 45 86 48 11 62 70 2 84 67 4 14 6 59 35 77 50 1 54 9 38 83 96 66 41 79 78 42 74 26 32 18 39 94 29 12 47 91 27 10 52 56 51 57 69 80 85 87 55 95 58 81 31 61 13 97 73 23 23335 yI stands for the room number and IxxI for the floor number0 lt Ixx 30046 I I 23034 yyI lt 10 The building has paternoste 0 16 5 2 7 14 15 4 1 16 8 13 9 3 10 11 12 6 16794 r elevator ie e 18554 levator buil 0 169 154 26 32 43 47 94 91 34 136 40 7 17 14 131 63 99 168 30 12 69 111 155 29 5 67 75 135 35 59 19 95 72 33 150 113 156 65 112 79 120 76 116 8 158 48 117 16 108 27 22 146 85 80 46 90 110 86 51 87 89 144 53 88 41 37 3 38 18 127 119 100 82 103 55 81 92 140 57 24 49 74 134 54 149 64 4 124 104 10 133 118 130 6 78 105 13 39 9 162 164 106 139 115 167 62 71 93 20 23 152 56 36 97 28 66 138 60 159 123 25 132 121 44 84 163 142 122 169 15 137 1 96 166 58 68 73 98 21 141 153 2 11 61 109 102 77 129 45 143 128 42 145 126 161 114 31 101 52 147 50 160 125 70 107 157 151 165 83 148 19201 d up from several cabins runningall around From time to time the ag 23865 ents must visit the headquar 0 32 28 4 19 17 23 8 32 26 1 29 31 11 9 7 24 20 30 10 3 21 22 15 2 16 13 18 27 25 5 6 12 14 31944 ters During their visit 0 165 96 79 53 45 144 72 128 31 10 9 44 83 80 148 90 132 35 88 70 98 111 8 106 115 110 113 56 123 108 156 12 102 11 161 104 23 37 89 57 155 151 126 41 38 36 14 119 91 100 48 136 154 109 146 76 63 61 147 75 82 124 138 55 64 114 16 19 137 71 131 105 5 69 59 49 54 43 40 160 30 125 73 1 13 97 153 134 3 52 159 95 93 39 122 26 127 21 158 101 163 141 17 112 22 157 103 140 135 143 58 60 29 145 65 139 66 129 86 18 152 47 120 20 50 15 130 165 92 42 78 33 24 27 68 94 62 164 117 6 7 32 142 67 121 150 87 28 46 149 107 34 99 4 25 133 51 81 116 84 77 74 85 2 162 118 5886 they want to visitseveral rooms and in each room they want to stay for some time Du 15056 e to the security reasons there can beonly one agent in the same room at the same t 0 55 11 48 4 8 13 3 43 46 36 47 34 55 29 30 52 24 23 22 26 33 32 1 49 38 21 25 28 2 41 27 31 12 42 17 50 15 10 53 18 14 35 7 6 54 9 44 19 16 37 45 39 20 51 40 5 21599 ime The same rule ap 0 83 28 75 77 76 36 50 18 61 6 49 29 12 20 8 37 39 17 68 65 22 1 25 13 10 78 71 3 73 67 62 41 4 66 26 40 48 81 21 44 42 64 47 34 51 83 7 58 57 19 70 46 74 52 63 33 24 27 11 14 32 53 59 60 43 69 55 16 9 79 5 45 30 54 72 35 56 2 15 80 31 38 82 23 27727 plies to the elevators The visits areplanned in the way ensuring they can 49 be acc 1805 omplished within one day Each agent visits the headquartersa 0 134 55 17 81 1 14 91 53 107 111 58 6 44 69 59 13 46 26 19 29 41 62 27 32 98 48 103 109 18 104 121 75 126 90 78 73 2 85 82 131 30 89 25 8 38 35 64 127 96 72 120 5 113 40 47 45 37 4 84 54 22 50 123 80 51 21 105 15 117 66 116 39 115 61 79 124 57 31 102 11 86 42 20 60 106 49 3 110 122 101 65 125 24 67 10 100 93 133 112 43 68 118 108 76 16 114 12 130 99 71 52 33 9 119 134 129 83 94 23 128 92 132 7 95 97 87 74 28 56 88 34 63 70 77 36 17790 t most once a daypEach agent enters the building at the 1st floor passes the reception and then starts to visit the roomsaccordi 19649 ng to hisher list Agents a 0 63 23 20 22 2 34 52 9 37 50 12 13 16 1 47 21 27 57 28 24 58 32 10 35 14 15 4 18 33 55 6 3 30 8 60 7 61 46 45 56 48 19 44 5 41 54 38 53 17 43 59 42 26 62 29 49 31 36 40 25 39 51 63 11 32656 lways visit 32166 the rooms by the increasing 28847 room numbers The agents forma 0 46 9 7 20 11 34 12 8 3 23 41 30 40 24 42 10 16 6 1 43 39 25 4 31 32 37 33 29 38 13 27 5 18 22 14 26 28 15 44 21 46 45 19 2 35 17 36 19584 linear hierarchy according 20093 to which they have assigned their one 0 30 30 7 4 16 19 9 22 11 2 3 25 6 26 21 29 12 8 10 23 24 13 18 27 15 20 28 17 5 1 14 11686 letter pers 5265 onal 29996 code 0 192 11 8 7 37 131 54 110 74 2 79 153 89 43 9 52 30 160 22 88 51 39 18 36 127 94 123 135 92 19 126 140 76 99 119 41 16 165 114 4 134 65 91 141 152 6 125 111 132 183 129 149 143 139 49 106 72 58 38 71 179 164 27 128 174 177 53 122 186 120 42 158 95 155 5 56 171 50 31 173 14 188 44 102 96 28 124 21 190 156 105 87 146 175 180 108 184 62 23 66 13 86 121 17 168 93 83 75 192 115 163 70 176 33 154 107 98 161 61 1 112 47 26 117 78 170 166 82 182 147 167 172 67 150 55 144 145 59 101 97 118 137 29 100 103 191 151 20 187 157 85 130 64 80 60 69 116 109 63 35 142 40 45 10 178 25 181 57 77 189 136 34 138 12 84 3 113 104 15 24 148 68 133 32 185 169 81 73 48 90 162 46 159 20427 s The agents withhigher seniority have lexicographically smaller codes No two agents have the same codePIf mo 0 124 97 6 15 42 99 52 5 11 108 12 41 106 122 46 7 112 98 74 25 66 34 31 47 110 93 79 10 16 60 55 71 91 53 90 69 102 121 30 33 28 50 32 86 92 3 38 65 67 104 114 119 109 63 88 101 9 39 117 70 95 36 73 58 75 103 8 62 85 87 81 83 59 94 107 118 17 1 54 43 27 111 80 35 22 82 120 77 23 29 64 115 68 100 24 4 18 105 44 48 78 49 21 96 20 56 45 76 113 40 14 61 26 123 124 2 57 51 13 84 37 72 116 89 19 18092 re then one agent want to enter a room or an eleva 12569 tor the agents 27279 have to form a queue In eachqueue they always stand according to their codes The higher the 0 24 1 17 15 12 6 7 18 21 8 23 16 3 19 13 5 10 2 11 20 9 4 24 14 22 18736 s 7230 eniority of 0 88 87 2 32 13 60 28 11 21 18 65 54 73 4 3 88 55 52 23 26 25 77 86 31 43 82 10 83 72 33 69 58 16 49 38 12 24 1 78 17 70 45 19 56 36 74 15 5 84 48 81 61 29 53 57 66 51 64 47 63 75 9 85 35 71 30 34 50 8 40 62 7 22 76 44 67 20 59 42 41 68 79 6 46 39 14 27 37 80 13817 the agent the closer to thetop of the queue he stan 0 94 62 63 23 18 49 17 9 76 3 45 8 29 38 68 87 78 16 22 93 40 60 55 12 4 69 21 52 82 20 48 85 71 81 61 24 51 35 65 41 50 77 94 73 43 11 19 7 36 42 6 66 39 13 34 33 75 88 59 54 10 25 84 89 2 70 27 80 26 58 72 30 92 56 90 15 64 91 5 1 31 53 44 79 37 14 28 67 57 86 46 74 32 47 83 12200 ds Every 5 s s 0 189 134 56 26 43 89 58 61 10 41 32 188 25 30 22 97 44 175 120 79 91 109 179 5 143 55 37 63 154 87 130 78 123 9 131 169 16 167 38 159 40 67 90 139 75 21 70 31 28 27 92 47 124 168 103 8 62 1 121 3 156 135 137 13 110 114 148 84 116 4 86 174 46 119 151 83 93 136 101 163 142 173 50 99 147 48 49 34 42 66 107 184 113 64 76 71 129 133 53 117 161 140 155 96 189 164 127 132 138 98 80 35 172 112 15 60 7 178 54 153 150 74 33 6 104 141 183 18 146 181 2 82 57 185 24 20 158 19 14 111 88 125 94 182 81 122 51 128 100 157 29 187 23 59 106 177 152 77 36 145 72 166 176 160 165 12 180 65 108 95 144 73 149 39 118 162 17 52 102 45 11 186 171 170 105 68 85 126 115 69 6215 econds the first agent in the queue in front of the elevator entersthe elevator After visiting the last room in the headquarters 9513 each agent uses if necessary elevator to thefirst floor and exits the buildingPThe times necessary to move from a certain 0 101 28 12 10 55 17 63 83 45 64 13 40 22 43 65 18 16 26 90 1 9 25 4 30 51 2 15 70 92 37 5 91 31 60 82 41 33 32 75 79 84 44 99 20 23 101 97 95 27 58 69 98 100 66 14 67 53 56 87 94 19 85 54 78 24 73 36 77 42 74 86 46 8 80 96 7 72 11 61 35 3 52 88 93 68 81 47 57 59 34 38 49 21 39 6 62 29 50 76 71 89 48 2620 point in the headquarters to another are set as 19918 followsEntering the building ie passing the reception and reachin 0 124 54 43 29 76 35 42 89 28 77 36 10 63 38 31 84 47 16 119 18 13 26 90 37 61 12 88 121 52 92 51 56 48 5 7 68 30 11 46 110 101 58 34 69 124 8 39 60 65 118 75 41 74 93 57 66 80 71 109 50 97 91 120 117 40 4 83 64 67 24 86 72 44 104 81 55 113 70 45 94 87 22 107 21 19 1 95 103 108 98 105 17 32 6 9 78 59 115 49 25 23 20 122 62 15 111 27 123 82 102 53 106 79 33 99 116 85 114 73 2 3 96 112 100 14 10879 g the elevator or a room on the first floor takes30 s Exiting the building ie stepping out of the e 0 111 62 95 12 82 53 39 10 73 88 46 55 4 25 108 74 70 23 111 105 22 84 91 40 96 29 76 57 66 24 85 59 79 37 92 65 107 43 94 97 103 14 78 89 52 106 17 86 15 109 30 11 34 104 42 21 47 93 98 54 69 87 7 68 90 27 64 38 19 51 75 32 58 5 1 9 20 3 44 31 77 63 49 36 83 48 8 61 60 110 100 33 67 81 102 101 80 2 28 35 6 45 71 50 16 99 41 13 26 18 72 56 11150 levator or a room on the first floor and passing thereception take 2398 s also 30 s On the same floor the transfer from the elevator to the room or to the queue infront of the roo 0 74 57 9 43 14 46 49 53 18 69 67 13 23 37 36 22 64 6 32 10 20 26 17 58 29 1 31 7 61 16 27 19 60 52 21 74 63 48 54 28 35 4 45 8 73 41 3 39 68 42 11 50 40 5 30 62 47 51 34 33 65 70 55 66 2 71 24 25 59 12 44 15 56 72 38 6683 m or from the room to the elevator or to the queue in front of the 25665 elevator or from oneroom to another or to th 0 5 1 3 4 5 2 7415 e que 0 126 9 64 108 112 95 53 19 103 45 43 44 123 81 18 116 39 57 21 27 102 99 118 119 84 61 125 109 41 58 42 75 121 34 62 91 50 29 105 33 24 77 51 94 56 79 104 69 12 96 13 66 85 5 52 76 80 124 10 15 122 60 83 40 28 68 72 63 120 117 1 3 101 55 47 65 54 67 74 115 89 90 92 114 107 82 22 7 26 98 25 126 87 16 20 4 32 23 113 71 17 2 110 11 88 59 93 111 31 100 14 30 8 106 86 78 70 37 38 48 49 73 36 35 97 46 6 5254 ue in front of the room takes 10 s The transfer from one floor to the nextfloor above or be 17883 low in an elevator takes 30 s Write a program that determines time c 27149 ourse of agents visitsin the headquartersH3InputH3The input file contains the descriptions of n gt 0 visits of d 0 145 13 35 86 17 1 132 81 19 88 70 95 89 135 109 118 48 61 40 67 49 64 58 8 56 46 76 82 31 77 128 108 107 84 14 27 74 71 25 121 113 59 103 53 144 139 90 72 142 65 114 134 39 69 66 42 43 111 91 126 3 73 93 4 37 12 55 97 96 136 106 85 145 131 2 30 123 105 20 129 115 23 92 137 119 29 36 79 38 102 99 68 78 87 133 101 100 21 22 116 26 140 124 80 15 110 5 11 7 18 9 60 98 94 112 130 24 51 6 83 54 57 34 122 120 44 41 143 47 33 10 28 75 63 50 16 127 45 104 125 138 62 141 32 117 52 2493 ifferent agents The first line of the descripti 0 167 6 167 34 44 25 97 21 95 72 111 52 19 88 114 70 118 160 32 131 23 10 75 107 7 148 56 126 116 4 81 143 119 103 93 65 128 62 41 55 58 33 51 106 100 89 5 27 48 63 16 109 110 129 133 127 22 112 71 145 1 12 94 153 124 121 135 155 78 163 113 147 46 29 43 87 37 98 3 140 161 96 39 14 136 61 64 138 79 82 59 152 105 73 158 117 28 11 120 80 166 146 77 2 31 154 122 159 130 137 45 38 83 53 102 134 50 76 142 54 18 125 162 66 108 68 150 24 9 144 156 57 85 104 36 13 86 17 47 157 149 92 8 67 84 90 139 74 30 15 101 165 99 35 20 26 91 151 164 69 60 123 49 141 40 42 132 115 6503 onof each visit consists of agents one character code ICI ICI A Z and the time when 0 87 82 9 7 65 26 81 70 2 77 31 79 16 53 15 43 27 60 67 24 29 52 48 59 44 76 49 69 86 84 64 33 11 41 5 83 12 51 62 36 28 34 37 30 6 80 56 47 40 78 72 4 85 14 61 66 38 58 71 87 57 22 23 32 45 35 55 20 17 68 46 75 10 21 54 8 25 42 50 18 1 19 39 13 73 3 74 63 326 the agent entersthe headquarters The time is 31504 in the format 0 171 160 34 134 167 44 81 64 40 136 89 65 145 48 58 11 143 63 52 25 17 93 50 147 76 121 98 78 26 80 128 51 168 19 126 49 62 110 135 165 41 16 47 156 7 13 87 20 97 14 108 123 103 86 129 42 9 112 54 101 148 153 149 36 67 35 83 133 85 27 114 120 150 113 99 91 82 71 162 70 74 75 92 170 122 2 117 131 6 3 102 161 72 94 127 8 146 30 32 158 109 79 132 46 77 152 139 88 157 137 39 24 53 144 61 73 10 4 107 138 151 45 100 119 57 141 18 38 66 159 33 96 29 68 1 140 23 164 56 69 60 169 12 5 95 166 31 171 104 90 43 130 116 125 118 28 111 115 163 154 84 59 155 22 55 21 37 142 124 106 15 105 22030 HHMMSS hours minutes seconds The next lines therewill be at least one contain the room number and the length of time intended to stay in the room timeis in seconds Each 15685 room is in a separate line The list 0 24 16 12 23 14 22 2 9 11 17 19 5 18 10 20 4 13 3 24 21 1 7 8 6 15 25276 of rooms is s 3620 orted according to t 11159 he 0 144 85 105 75 48 52 46 12 13 11 2 56 57 36 115 24 32 37 90 54 3 70 133 74 72 5 65 84 20 93 35 51 67 92 127 95 30 45 28 143 16 25 99 137 119 114 94 104 66 44 82 34 83 139 126 88 78 22 129 15 26 63 38 39 134 29 141 131 103 47 77 130 43 89 80 8 112 64 81 87 18 6 4 107 125 124 121 27 116 73 128 79 71 14 68 96 76 17 33 106 42 59 97 120 102 31 62 55 136 7 1 21 10 117 40 109 140 138 111 144 98 108 86 41 23 113 118 58 101 142 123 69 49 110 135 19 132 53 91 60 9 50 61 122 100 704 increasing roomnumber The list of rooms ends by 20336 the line containing 0 The list of the descriptions of visits ends by theline containing the character dotH3O 0 81 34 72 45 17 70 18 81 16 57 63 76 47 11 19 29 54 30 58 52 8 55 28 24 2 3 43 44 27 60 6 32 71 35 46 77 4 51 7 15 12 61 36 67 38 74 33 69 53 23 68 50 79 10 21 37 31 5 42 22 48 66 41 75 26 73 14 64 9 25 80 1 59 65 13 49 78 39 40 62 20 56 299 utputH3The output contains detailed records of each agents 17034 visit in the headquarters F 0 117 101 84 73 53 24 80 75 44 31 19 13 82 26 34 71 28 52 88 103 29 111 37 22 10 18 49 40 100 46 7 48 104 67 110 113 38 68 83 98 105 115 59 27 43 86 109 107 56 6 55 42 95 66 69 78 50 58 79 35 61 64 63 25 11 57 97 94 81 47 85 2 33 117 60 23 30 90 39 15 89 106 112 96 65 16 72 17 77 92 93 32 99 14 3 12 114 62 45 74 8 21 91 1 54 76 20 87 51 102 9 108 5 70 116 36 4 41 31687 or each agent therewill 0 178 33 72 122 154 101 4 88 21 24 9 22 173 25 141 61 66 110 99 82 18 13 2 50 11 143 81 40 27 178 96 111 58 29 123 105 115 53 1 119 85 8 147 16 116 63 49 26 52 94 32 132 67 138 47 34 62 43 106 163 55 144 124 112 14 38 65 48 137 159 169 76 37 113 41 7 149 128 117 75 59 175 10 57 46 91 51 69 162 20 74 172 118 176 148 131 3 165 60 80 158 35 44 6 152 56 78 100 177 103 150 30 42 87 161 84 68 135 126 98 170 156 12 107 104 36 97 17 120 167 146 171 73 71 54 92 136 15 79 129 168 145 151 89 125 102 133 31 160 45 70 130 121 23 95 108 139 83 77 86 64 174 114 166 90 19 155 153 127 39 164 140 109 142 93 28 157 134 5 2656 be a block Blocks are ordered in the order of increasing agents codes Blocks are sep 22063 arated by anempty 0 177 110 21 107 123 76 131 39 30 133 167 142 87 95 5 12 9 135 35 98 17 114 47 31 115 3 83 43 75 84 90 37 64 106 45 156 100 42 51 89 129 125 78 111 136 22 8 61 104 62 130 102 99 86 66 141 147 165 10 16 120 20 46 48 53 28 77 57 40 153 29 49 143 175 118 32 164 74 148 23 11 50 73 27 70 59 159 88 162 124 36 67 140 13 14 160 170 117 97 113 26 166 41 56 132 171 126 119 154 152 173 94 81 146 2 54 69 150 7 149 158 58 127 176 172 169 34 24 63 134 121 105 80 161 4 138 93 174 82 6 19 96 168 137 92 122 108 177 52 103 157 55 145 71 163 15 38 116 128 91 1 44 112 18 109 33 68 72 79 151 60 25 144 155 139 101 85 65 12972 line After the last block there is an empty line too The first line of a block contains the code ofagent Next 22392 lines contain the starting and ending time in format HH 0 110 71 78 16 85 35 28 26 31 63 54 17 27 51 5 86 59 92 22 69 93 55 89 74 110 6 103 11 8 106 84 76 87 43 1 72 37 73 49 68 96 53 95 47 10 66 100 82 50 61 24 70 40 38 13 60 15 67 105 104 30 56 98 107 58 9 25 33 97 42 83 81 90 23 91 80 77 44 75 36 29 52 62 32 88 46 2 57 3 4 101 79 19 48 64 94 108 21 109 102 14 18 12 34 99 39 45 41 20 65 7 11827 MMSS and the descriptions of hisheractivity Time data 14155 will be separated by one blank c 0 72 69 53 63 37 21 7 15 25 18 13 5 64 36 6 9 67 4 12 20 22 31 11 38 23 17 44 68 30 2 40 1 43 72 52 39 62 45 27 14 29 51 57 35 10 26 24 19 58 55 32 65 41 61 59 8 54 48 16 60 70 66 56 33 34 28 71 46 47 50 3 42 49 14286 haracter Description will be separated from time byone blank chara 16282 cter Description will have a form Entry Exit or Mes 0 164 88 25 94 125 92 26 7 127 24 31 5 67 89 95 42 130 99 86 80 126 134 96 10 60 121 48 47 1 161 132 43 6 106 85 4 39 164 29 34 87 17 52 77 110 101 70 9 123 54 82 76 66 103 62 15 27 75 55 140 69 107 32 74 102 147 109 57 111 131 51 18 98 124 133 136 53 22 151 61 12 158 162 36 119 41 16 19 153 68 78 84 141 3 79 118 160 152 129 33 104 46 128 155 14 108 117 11 64 83 157 142 40 2 63 38 73 105 45 59 148 163 154 65 156 116 28 58 71 137 81 144 149 100 35 8 146 150 93 37 122 138 72 135 145 114 97 13 50 91 30 139 23 113 120 143 49 115 159 56 90 21 112 20 44 15546 sage The Message can be one ofthe following ttWait 10484 ing in elevator queuett ttWaiting in front of room iRoomNumberitt ttTransfe 10248 r fromroom iRoomNumberi to room iRoomNumberitt ttTransfer from elevator to ro 0 175 11 96 126 142 46 110 155 71 16 22 56 144 12 8 76 36 61 132 135 172 84 101 28 6 105 5 54 27 52 59 114 9 137 127 159 42 120 92 24 72 34 37 169 1 121 149 18 20 116 33 128 7 122 55 160 143 147 145 151 25 43 118 97 60 166 4 167 81 64 95 58 47 10 3 29 150 38 93 100 94 85 48 146 170 41 152 103 112 32 49 109 35 117 89 148 45 99 106 74 175 82 63 125 90 174 107 39 62 78 69 53 140 31 164 14 75 88 115 19 50 65 171 165 154 119 131 66 86 83 40 51 161 123 136 130 80 113 73 156 79 173 102 104 141 129 163 21 139 77 13 70 87 162 138 108 124 133 111 26 67 68 134 2 98 158 17 168 23 153 15 157 91 57 30 44 25912 om iRoomNumberitt ttTransferfrom iRoomNumberi to elevatortt ttStay in room iRoo 0 108 18 4 28 42 45 23 12 19 80 21 105 64 20 103 71 16 85 90 43 57 81 38 48 51 70 6 34 58 10 94 52 75 62 108 79 55 99 46 76 39 84 1 24 72 26 50 15 77 33 29 37 40 106 73 66 74 13 32 88 7 65 67 78 17 5 44 95 11 22 9 2 31 101 98 27 83 61 97 36 107 35 49 53 82 59 92 56 91 100 68 86 96 87 41 60 30 89 69 54 104 14 93 3 63 102 25 47 8 14052 mNumberitt ttStay in elevatorttH3ExampleH3BInp 27046 ut file BPREA 1000000101 10001 15449 10 500202 900205 0 63 24 47 28 8 32 53 20 10 29 42 59 21 18 30 54 1 63 40 58 22 52 36 9 23 11 39 31 4 46 3 44 57 14 35 55 27 5 26 41 34 45 43 48 12 60 49 37 7 13 6 15 62 17 61 33 19 50 25 16 2 51 38 56 30880 500B 1001000105 1000201 50205 2000PREBOutput fileBPREA1000 4730 00 100030 Entry100030 100210 Stay in room 0101100210 100220 Tr 11507 ansfer from room 0 21 8 6 11 10 12 3 19 9 17 5 4 1 13 18 20 16 7 2 15 14 21 20296 010 29761 1 to room 0110100220 14014 10 0 119 33 50 60 104 59 87 55 48 29 70 14 100 35 65 24 23 54 9 76 114 62 49 92 42 32 53 46 37 43 113 20 106 91 67 118 13 66 117 16 3 80 88 93 119 2 69 74 17 19 81 68 40 115 30 111 108 84 82 107 71 47 73 51 64 63 103 38 105 5 85 75 36 22 90 78 39 15 99 26 61 86 41 18 95 57 94 110 12 45 77 58 10 7 98 101 116 96 112 72 27 102 52 8 25 28 6 83 34 44 21 31 109 89 97 11 56 79 1 4 29996 0310 Stay in room 0110100310 100320 Transfer from room 0110 to elevat 0 19 18 17 7 15 9 11 2 5 13 19 3 4 16 6 14 10 8 1 12 27338 or 16199 100320 10 0 7 5 3 2 4 7 1 6 28413 03 0 4 2 1 4 3 15979 50 S 8200 tay 13088 in 0 52 22 4 36 16 27 15 33 51 34 52 24 32 37 5 38 25 26 39 50 47 6 17 48 12 43 42 44 46 35 21 28 31 20 1 30 49 3 19 11 9 23 7 14 18 8 2 29 45 40 10 13 41 22092 elevator100350 100400 Transfer from 19139 elevator to room 020210 0 124 8 59 22 60 37 89 3 69 42 21 45 121 20 26 39 53 16 19 38 75 40 52 61 94 78 97 29 7 107 108 122 34 2 36 114 50 109 67 79 4 111 113 83 44 76 71 41 104 28 102 62 115 43 10 11 106 87 82 33 47 85 84 73 6 1 9 68 17 123 93 95 88 124 80 105 14 96 90 66 25 99 32 18 56 12 64 30 13 55 116 100 120 49 65 57 86 110 74 5 77 118 24 31 72 81 70 119 58 101 46 23 117 35 54 27 92 48 63 51 103 15 98 112 91 6167 0400 100530 Stay in room 0202100530 100540 Transfer from room 0202 to room 0 130 56 80 114 93 32 14 3 117 48 12 44 60 51 46 84 30 24 82 74 96 87 6 118 65 61 72 55 25 111 18 1 41 86 10 29 59 49 102 71 7 126 33 66 53 8 105 17 81 42 31 36 58 9 123 52 112 127 16 77 129 26 21 78 85 89 125 75 13 124 113 130 68 64 50 73 97 34 103 5 88 19 92 4 107 20 57 99 128 110 22 104 116 15 70 2 11 23 37 106 91 35 43 108 54 90 95 121 39 115 109 62 122 40 47 69 79 98 76 94 38 100 83 101 119 28 27 120 63 45 67 20916 0205100540 100740 Waiting in front of room 0205100740 100830 Stay in r 7739 oom 0205100830 100840 Transfer from room 0205 to elevator100840 0 177 29 89 63 139 15 13 39 127 125 24 14 166 133 168 21 148 108 97 134 54 27 8 44 20 112 153 103 6 82 72 4 94 105 73 99 140 118 31 129 69 175 124 38 1 142 33 16 143 104 61 32 176 93 119 100 58 2 120 88 36 37 141 102 113 151 138 116 114 57 81 77 160 50 10 132 11 106 123 80 7 23 146 145 167 98 109 75 92 66 18 155 171 62 128 76 152 35 137 86 68 177 41 84 65 25 172 174 78 45 60 111 74 173 149 19 90 26 52 42 115 163 5 87 34 9 170 162 30 49 122 17 165 121 96 131 51 144 71 154 40 147 64 130 107 47 67 22 53 156 161 157 158 55 3 117 12 150 169 136 43 46 48 126 91 28 101 83 79 110 164 70 95 135 56 85 159 59 6340 100910 Stay in elevator100910 100940 ExitB100100 100130 Entry100130 100310 Stay in room 0105100310 100320 Transfer from room 0105 to elevator10032 22607 0 100325 Waiting in elevator queue100325 100355 Stay in elevator100355 100405 Transfe 26950 r from elevator to room 0201100405 100410 Stay in room 0201100410 100420 T 0 104 17 33 103 92 76 46 42 2 104 51 79 91 98 87 27 30 20 80 35 57 52 67 10 44 75 45 26 85 89 11 54 100 19 41 13 73 55 9 16 32 59 86 25 34 63 43 37 70 6 24 88 97 47 3 62 14 61 83 22 50 64 68 28 23 60 31 39 65 1 82 78 4 66 21 101 18 5 81 49 84 56 58 29 99 38 40 53 8 94 93 74 7 72 102 15 48 95 36 90 12 69 96 77 71 9199 ransfer from room 02 0 90 42 9 81 43 33 49 47 77 36 23 48 82 53 34 78 72 52 39 15 40 22 32 58 76 26 75 27 29 80 1 16 21 11 46 30 88 6 19 2 61 68 7 12 24 8 55 56 17 31 60 3 13 73 84 69 79 86 41 71 4 63 90 66 14 50 38 57 62 74 59 83 51 20 70 28 35 54 44 65 89 64 85 10 25 67 37 87 45 5 18 1630 01 to room 0205100420 100740 Sta 24442 y in room 0205100740 100750 Transfer from room 0205 to elevator100750 1008 0 114 26 73 5 96 13 4 66 109 39 30 76 53 87 17 104 35 3 99 49 10 38 28 31 77 14 68 45 58 54 48 103 42 79 71 37 85 62 57 69 51 98 72 32 47 110 91 80 95 113 82 2 84 8 81 40 75 70 33 112 7 101 22 97 102 19 41 106 93 43 90 67 83 46 59 21 6 44 9 23 12 108 55 105 25 63 27 15 61 36 88 64 24 52 56 65 111 107 74 100 18 92 50 11 78 86 89 34 114 94 1 60 29 16 20 13669 20 Stay in elevator100820 100850 ExitPREBODYHTML 20152 HTMLHEADTITLECERC 1995 Problem F Jo 0 179 115 25 170 28 91 46 40 38 157 131 14 95 96 124 145 50 135 143 60 35 39 21 61 27 153 107 156 22 9 64 162 16 6 17 57 92 104 140 77 75 2 10 90 51 123 44 78 121 150 5 132 118 109 93 49 62 133 15 101 167 100 129 4 111 117 63 13 169 68 141 53 108 147 36 176 8 54 125 168 26 160 41 172 31 148 80 173 86 88 81 34 106 83 110 175 52 151 166 136 32 69 73 178 154 105 43 112 67 139 12 127 144 177 128 94 134 163 48 7 137 130 97 120 71 37 70 114 161 84 146 79 23 30 171 55 126 24 45 98 56 164 138 155 33 76 72 89 47 174 58 74 119 116 149 59 165 159 142 3 1 179 113 102 87 82 158 29 85 19 99 42 103 122 152 65 11 20 18 66 4779 sephTITLEHTML version generated by Kotas Koucky 1998HEADBODYH2 ALIGNCENTERACM International Collegiate Programming Contest 9596H2P ALIGNCENTERBSponsored by 0 173 172 84 79 173 81 14 1 16 12 13 97 111 106 94 74 87 19 47 127 20 27 78 169 132 130 120 35 53 67 2 112 148 51 55 38 48 113 23 76 10 142 29 147 91 114 28 32 163 50 100 6 45 82 25 129 60 33 125 73 37 18 150 75 133 143 72 154 69 128 109 93 158 134 5 159 152 83 95 26 101 43 8 118 9 42 162 90 64 63 44 4 115 17 108 11 99 107 151 61 160 117 166 62 30 77 3 155 7 49 88 70 124 41 122 52 141 24 145 136 105 170 68 138 121 86 153 46 116 39 15 131 21 65 171 103 135 149 139 59 119 85 146 80 164 140 66 96 161 165 57 167 104 102 40 54 123 168 156 92 71 31 22 89 98 56 34 144 157 58 110 126 36 137 1999 MicrosoftBH3 ALI 2655 GNCENTERCentral European Regional ContestH3BRH2 ALIGNCENTERProblem F JosephH2P ALIGNCENTERBInput fileB ttjosephinttBRBOutput fileB ttjosephoutttBRBProgram fileB 5238 ttjosephpastt or ttjosephcppttPThe Josephs problem is notoriously known For those who are not familiar wi 0 43 27 6 36 8 1 13 4 30 2 28 33 9 5 41 10 11 26 22 7 19 14 39 32 29 38 42 37 18 20 16 17 23 21 25 34 24 43 40 12 31 35 15 3 18725 th 14304 the original problem 3307 from among 0 193 108 11 43 169 49 180 25 18 26 185 126 110 152 36 58 20 119 98 106 133 179 32 74 34 8 44 50 23 41 16 165 120 12 81 55 176 160 148 188 189 99 70 162 184 168 82 154 94 28 167 76 104 136 59 66 29 61 90 71 134 45 149 64 77 73 117 114 69 159 130 95 177 22 173 86 24 80 128 138 144 121 10 172 65 35 145 37 155 143 111 190 15 51 2 183 139 157 193 54 141 101 83 30 7 131 147 96 132 63 79 118 166 146 151 113 107 9 123 17 112 53 156 5 13 31 27 97 158 46 48 62 1 116 105 89 14 137 164 175 60 174 3 122 87 182 33 40 135 75 163 47 161 78 129 92 38 150 52 178 4 39 186 192 91 100 140 42 170 127 85 67 19 115 21 103 68 171 153 84 109 6 57 191 125 187 142 56 102 88 72 181 124 93 6159 InI people numbered 1 2 InI standing in circle every ImIth is going to be executed and onlythe life of 26197 the last remaining person will be saved Joseph was 24162 smart enough to choose the position of thelast remaining person thus saving his life to give us the m 0 10 5 9 8 7 6 4 1 2 3 10 13355 essa 0 131 45 95 43 25 74 81 2 39 16 90 37 55 93 42 103 65 88 124 115 4 12 82 125 32 83 46 80 58 14 108 61 127 126 60 123 57 13 33 44 34 99 94 64 20 110 73 68 122 71 31 114 36 116 117 1 96 63 78 69 120 92 107 8 27 84 67 79 113 97 76 128 112 11 106 3 91 48 17 56 85 66 35 86 41 87 77 104 18 38 89 72 102 7 40 53 111 75 30 98 29 19 47 22 5 118 28 109 6 105 24 121 10 131 23 49 62 70 59 21 50 129 100 54 15 119 26 52 130 101 51 9 3534 ge about the incident For example whenInI 6 and ImI 5 then the people will be executed in the 9905 order 5 4 6 2 3 and 1 will be s 3613 avedPSuppose that there are k good guys and k bad guys In the circle the firs 0 54 42 23 28 22 10 26 43 14 3 48 15 45 18 16 19 31 37 33 41 46 27 7 38 47 34 24 13 35 51 21 5 8 11 29 36 6 39 40 49 9 30 44 32 2 12 20 50 25 54 1 17 53 52 4 2106 t k are good guys and th 31476 e lastk bad 30331 guys You have to determine such 0 128 109 37 25 29 69 64 73 65 117 39 93 127 54 91 21 95 90 85 88 106 89 38 122 47 94 80 35 77 78 70 112 99 76 24 126 19 30 56 42 113 110 74 83 50 34 4 23 45 103 61 14 82 8 60 66 81 31 120 32 68 59 5 105 53 11 18 108 87 98 121 55 58 51 16 10 96 97 118 62 46 27 15 101 41 104 22 75 1 13 111 63 57 52 33 3 26 86 49 12 7 79 125 119 114 72 124 115 116 71 100 123 84 128 9 17 44 28 43 36 67 48 6 40 107 92 2 20 102 29870 minimal m that all the bad guys will be executed before the firstgood guyH3InputH3The input file consists of separate lines cont 19190 aining IkI The last 0 90 41 49 57 11 87 81 60 84 59 85 32 6 35 34 37 24 29 31 30 36 74 55 79 78 68 21 17 2 22 7 8 5 64 82 65 3 28 42 48 61 76 73 9 18 51 88 54 38 44 67 39 90 56 71 25 45 53 1 80 58 72 19 62 50 75 43 15 46 13 12 52 83 40 27 70 47 4 69 66 89 20 33 26 63 10 14 86 77 16 23 29699 line in the input file contains 0 You cansuppose that 0 l 0 22 4 8 15 11 2 9 6 17 22 1 16 7 14 19 20 12 21 10 3 5 13 18 2752 t 0 23 15 7 23 9 21 4 6 18 10 17 11 1 14 19 2 16 12 20 5 22 8 3 13 31179 IkI 5480 lt 14H3OutputH3The outp 0 183 2 86 167 16 25 17 153 149 124 95 111 107 110 5 99 114 82 93 8 103 133 80 165 58 83 43 152 52 129 34 136 45 128 148 72 65 42 54 116 33 22 97 78 131 61 150 51 12 38 28 173 122 35 101 32 183 75 172 98 26 6 177 39 77 163 62 145 161 49 15 154 181 60 92 121 146 180 67 23 18 118 36 151 139 87 74 174 156 79 126 130 120 169 105 104 64 157 106 147 179 141 155 159 50 94 48 119 4 142 20 21 40 59 178 30 71 53 41 63 19 171 135 138 44 144 47 112 90 10 158 137 56 13 182 175 160 132 109 108 117 55 162 3 170 27 102 84 66 11 127 14 85 113 76 1 125 115 96 29 164 24 73 89 166 123 46 57 81 168 37 7 134 70 9 100 143 68 31 88 176 140 69 91 18720 ut file will consist of separate lines containing ImI corresponding to IkI in the 16240 input fileH3ExampleH3BInput fileBPRE340PREBOutput fileBPRE530PREBODYHTMLHTMLHEADTITLECERC 1995 Problem A Maya CalendarTI 0 45 34 5 37 17 1 18 28 38 22 19 16 7 3 11 15 23 35 44 45 9 30 8 42 24 29 14 13 6 41 40 26 36 39 33 10 12 20 21 32 2 27 43 31 4 25 6825 TLEHTML vers 616 ion g 4259 enerate 0 108 72 76 102 51 79 17 39 108 45 5 28 58 73 15 35 82 74 90 86 55 34 104 47 2 8 53 100 29 92 97 13 89 66 7 70 62 1 14 49 19 43 23 32 84 6 64 69 24 22 85 52 20 107 93 33 18 50 59 3 83 27 40 65 11 87 88 41 25 36 21 103 4 78 98 54 12 57 91 9 67 105 42 60 26 80 56 10 81 61 46 68 106 75 30 99 37 101 38 63 16 44 94 71 95 77 31 96 48 23261 d by Kotas Koucky 1998HEADBODYH2 ALIGNCENTERACM International Collegiate Pro 23917 gramming Contest 9596H2P ALIGNCENTERBSponsored by Micr 7850 osoftBH3 ALIGNCENTERCentral European Regional ContestH3BRH 0 60 24 59 56 5 14 43 10 32 39 48 35 21 34 31 9 50 55 28 47 52 36 40 29 42 37 22 33 19 45 12 23 20 7 25 15 38 57 53 26 13 11 41 1 44 17 2 8 27 3 46 51 49 30 6 60 4 18 58 16 54 27734 2 ALIGNCENTERProblem A Maya CalendarH2P ALIGNCENTERBInp 0 176 26 30 13 115 131 90 85 121 59 102 70 53 12 68 15 36 133 94 11 10 27 129 39 58 79 24 75 170 41 136 171 120 3 56 37 111 50 42 92 132 87 152 73 78 109 51 144 17 141 82 99 74 143 33 138 60 101 169 65 4 100 114 113 134 150 23 7 135 106 154 96 5 147 18 139 72 97 81 83 98 146 107 22 25 149 40 44 62 145 6 117 38 156 176 157 52 122 153 104 8 63 108 162 89 174 88 21 127 80 123 167 173 61 172 103 125 28 71 55 35 116 124 105 84 9 160 159 20 163 66 77 119 1 31 57 19 29 128 64 130 43 69 2 126 118 86 155 76 142 148 164 67 161 16 49 93 168 48 34 46 165 112 151 32 137 45 175 158 140 91 110 54 47 95 14 166 7395 ut fileB ttmayainttBRBOutput fileB ttmayaoutttBRBProgram fileB ttmayapa 11619 stt or ttmayacppttPDuring his last sabbatical professor M A Ya made a 28576 surprising discovery about the o 0 38 5 29 21 7 34 26 10 31 22 14 12 6 33 15 27 11 19 24 2 36 20 25 23 8 9 30 32 17 4 38 28 37 3 1 35 18 13 16 15198 ld Maya calendarFrom an old knotte 4404 d message professor discovered that t 0 117 53 82 43 91 60 64 73 38 94 12 62 108 48 54 30 51 98 96 80 57 99 24 28 83 50 14 9 32 49 33 69 34 92 8 35 76 21 5 93 65 81 4 88 16 26 45 78 27 56 75 3 37 58 31 47 97 107 101 102 84 71 15 36 2 104 23 55 20 41 103 19 10 79 59 87 115 13 74 106 95 63 85 109 113 114 112 52 90 44 111 25 66 117 40 89 29 46 68 116 110 11 105 72 100 7 42 6 70 77 18 86 17 61 1 39 22 67 22406 he Maya civilization used a 365 day long year calledIHaabI which had 19 months Each of th 30140 e first 0 143 87 40 10 69 132 75 133 106 13 22 45 31 103 78 111 8 119 51 141 117 96 48 3 123 131 120 18 49 50 64 17 112 7 97 134 114 122 33 101 65 107 46 94 80 81 58 143 138 102 68 127 108 125 34 23 56 113 1 37 62 43 32 72 11 41 4 83 12 28 128 44 92 67 14 71 95 38 86 5 61 2 137 21 79 76 55 129 35 74 19 88 109 130 115 85 116 140 90 54 52 57 63 105 25 27 39 139 29 6 142 60 121 26 118 99 66 20 126 110 70 124 36 100 47 89 30 136 15 84 42 53 93 82 91 16 59 104 73 98 24 9 77 135 31875 18 months was 20 days long and the names of the monthswere Ipop no zip zotz t 5238 zec xul yoxkin mol chen yax zac ceh mac kankin muan 0 167 16 133 159 48 88 121 114 163 104 70 105 38 60 108 45 6 66 14 22 111 62 27 56 53 35 30 102 63 52 69 152 123 26 55 72 87 40 57 162 144 73 4 46 15 166 129 68 28 157 167 34 150 155 85 42 12 140 100 160 92 83 43 19 10 21 24 37 109 112 77 86 95 141 106 44 149 71 5 128 18 99 165 153 7 142 119 11 120 145 130 134 91 94 148 116 146 74 47 98 76 118 51 32 136 84 8 124 78 132 65 96 29 89 110 127 115 1 131 138 13 9 23 107 81 113 125 143 93 135 154 90 161 61 126 25 137 31 156 75 17 49 80 39 50 2 158 59 147 151 58 3 103 97 67 41 101 122 164 82 20 64 33 54 139 36 117 79 2525 pax koy 11915 ab cumhuIInstead of having na 21674 mes the days of the months were denoted by numbers starting from 0 to 19 The lastmonth o 0 23 15 7 2 11 12 8 9 6 14 23 18 13 22 19 4 3 21 16 20 17 10 1 5 16963 f Haab wa 23852 s called Iua 0 186 62 106 49 148 118 11 149 61 19 80 60 31 38 133 75 117 24 81 21 43 173 73 30 52 40 185 84 2 145 34 44 134 171 5 55 147 119 85 151 37 47 168 116 56 88 159 1 42 99 95 174 36 92 127 162 108 100 155 78 91 64 6 59 7 94 39 179 53 132 22 135 63 123 16 178 136 14 74 158 142 129 138 65 184 15 128 186 50 143 101 112 33 137 152 144 146 48 157 164 23 89 58 57 140 71 113 105 166 177 12 10 98 122 93 27 139 154 82 51 66 17 87 111 182 167 121 76 172 79 26 45 161 103 18 72 183 165 176 13 150 126 104 46 29 124 170 25 68 110 9 20 156 90 54 32 86 77 3 8 115 163 70 96 160 35 114 153 175 102 109 4 97 69 180 67 120 169 28 131 125 41 107 130 181 83 141 8766 yetI and had 5 d 12814 ays denoted by numbers 0 1 2 3 4 The Maya believed thatthis month was unlucky the court of justice was not in session the trade stopped people did not even sweepthe floor pF 1109 or religious purposes the Maya used another calendar in which the year was called ITzolkinI hollyyear The year was divided into thirteen periods each 0 132 79 34 78 4 27 66 51 59 32 61 36 64 11 130 57 28 86 80 74 12 5 122 84 110 67 97 107 72 41 126 16 8 121 62 63 112 70 25 48 81 123 58 82 94 39 22 108 17 115 45 42 33 118 99 46 131 90 37 55 15 53 109 7 89 91 102 87 76 49 127 93 95 120 111 98 83 119 31 104 52 85 114 92 100 30 20 1 88 38 96 125 35 101 116 50 21 47 40 43 19 132 77 14 105 26 10 106 44 113 129 23 9 103 65 128 3 60 69 24 6 56 73 124 68 29 2 117 13 71 54 75 18 12319 20 days long Each day was denoted by a pairconsisting of a number a 15406 nd the name of the day They used 20 names Iimix ik akbal kan chicchan cimimanik lamat mu 22042 luk ok chuen eb ben ix mem cib caban eznab canac ahauI and 13 numbe 0 60 18 21 57 45 14 29 60 40 54 35 7 41 31 23 12 26 1 16 3 28 17 15 25 55 43 48 27 46 36 24 30 39 4 34 56 13 53 19 6 59 49 33 37 50 38 8 22 58 10 11 52 5 47 2 44 32 51 9 42 20 9046 rs both incycles PNotice that each day has an 0 54 10 23 14 36 3 34 38 16 6 15 24 28 49 27 29 54 22 47 37 40 44 51 18 43 52 53 41 9 5 35 4 13 42 50 8 26 12 48 39 1 21 20 30 33 32 45 7 2 46 31 11 17 19 25 31429 un 1145 ambiguous description For example at the beginning o 28243 f the year thedays were described a 0 150 37 16 86 55 119 21 28 139 116 128 90 9 79 108 61 83 77 103 97 22 85 93 51 98 130 137 18 74 34 70 5 142 109 14 78 56 1 122 25 135 64 127 73 46 81 33 124 4 88 113 121 150 115 136 54 8 69 6 2 66 75 24 149 42 89 100 17 105 71 111 101 10 110 7 30 29 129 58 20 44 92 57 65 15 32 133 62 114 47 67 140 145 50 31 48 112 43 49 138 11 104 60 106 26 41 59 53 146 36 131 72 39 45 147 84 134 144 94 125 87 95 35 40 12 38 13 132 118 107 27 19 3 117 76 143 96 23 102 148 126 99 123 52 91 63 141 68 82 120 80 15437 s follows PI1 imix 2 ik 3 akbal 4 kan 5 chicchan 6 0 135 134 125 34 115 121 123 127 130 18 28 92 25 88 77 35 76 51 128 4 55 82 46 23 30 86 132 19 32 109 100 126 129 116 98 5 63 131 8 99 13 57 74 54 7 64 91 33 47 27 50 9 36 62 17 52 135 70 96 29 45 85 44 81 60 31 105 75 114 61 124 22 68 58 38 87 24 56 1 97 84 90 42 67 94 11 72 73 89 119 3 40 122 10 113 102 78 95 21 79 14 103 20 133 118 93 26 15 83 65 53 69 80 43 108 117 66 2 104 48 16 112 41 12 59 107 37 110 6 120 101 106 111 71 39 49 17539 cimi 7 manik 0 94 56 10 25 5 9 18 81 47 44 11 13 65 1 39 85 59 41 88 78 67 77 43 3 79 17 64 54 4 93 73 28 30 42 50 33 51 26 29 63 37 45 46 71 6 84 20 40 15 58 76 21 38 19 66 90 55 31 36 69 14 83 61 7 2 49 32 23 92 12 24 82 70 57 53 16 8 89 60 80 87 48 91 27 74 68 72 75 52 94 62 35 34 22 86 30612 8 lamat 9 muluk 10 o 0 165 153 93 87 38 162 59 149 99 51 115 44 160 146 81 13 125 11 45 52 37 3 138 136 62 95 69 76 94 72 23 26 151 89 4 157 36 15 16 107 90 129 148 71 84 119 55 33 117 17 147 108 43 58 1 155 34 145 121 135 83 8 126 49 46 29 6 73 41 91 12 163 77 154 127 32 97 5 80 67 120 128 10 98 50 66 164 114 130 78 96 112 159 19 124 134 70 74 20 53 106 54 79 40 150 39 118 100 82 140 65 110 101 28 56 123 152 165 25 9 88 18 86 158 31 142 113 141 57 64 35 63 47 61 139 42 102 68 60 22 144 104 156 143 105 116 21 109 75 85 7 30 137 131 14 48 111 161 133 2 122 132 27 24 92 103 6136 k 11 chuen 12 eb 29291 13ben 1 ix 2 mem 3 cib 4 caban 5408 5 eznab 6 canac 7 ahau and again in 0 197 42 41 1 166 85 146 104 33 55 116 46 107 119 97 172 63 31 25 170 132 5 59 106 36 90 38 23 64 196 66 71 62 110 99 167 100 186 118 86 80 68 111 54 32 82 161 65 121 148 180 126 60 151 141 139 89 58 193 49 61 177 14 57 72 138 169 153 105 44 159 92 76 79 17 158 120 157 3 173 2 131 19 127 181 130 176 160 108 109 43 10 40 171 112 164 137 45 140 194 114 93 122 162 117 22 155 70 24 156 125 73 179 102 26 37 178 39 197 115 47 34 190 91 144 154 136 183 74 135 187 143 88 113 69 124 20 78 4 8 150 149 163 96 67 189 56 165 13 15 185 152 142 195 188 75 133 94 52 182 184 123 175 27 53 77 145 21 16 174 95 81 147 98 48 83 129 101 191 128 134 50 84 103 192 28 51 6 87 12 35 7 29 30 11 168 18 9 17188 the next period 8 imix 9 ik 10akbal IPYears both Haab and Tzolkin were denoted by numbers 0 1 where the number 0 was thebeginning of the world Thus the first d 11011 ay was LIHaab 0 pop 0 BRLITzolkin 1 imix 0 PHelp professor M A Ya and write a program for him to con 5129 vert the dates from the Haab calendar tothe Tzolkin calendarH3InputH3The date in Haab is given in the following formatPINumberOfTheDay Month YearIPThe first line of the input fi 0 107 85 2 14 12 24 89 21 72 43 81 20 51 52 13 79 19 88 1 3 63 10 65 78 37 11 107 27 35 98 48 95 103 16 102 30 4 41 66 67 46 71 36 26 44 61 6 86 75 73 83 70 53 84 77 5 58 28 62 99 15 25 18 105 59 23 74 49 87 93 104 32 40 34 47 31 92 64 29 106 91 45 56 22 96 101 39 76 94 80 69 8 97 33 57 50 54 55 100 90 9 60 7 82 68 38 42 17 15279 le contains the number of the input dates in the 0 197 86 28 40 21 178 97 143 45 147 38 182 88 42 74 44 48 153 36 96 8 120 133 113 123 94 152 116 184 27 57 95 58 124 61 23 164 118 26 119 70 146 135 64 16 183 41 5 22 107 81 172 139 126 177 68 4 101 171 161 98 83 190 121 131 109 59 144 193 43 187 140 114 134 18 77 78 151 99 80 103 108 2 89 145 29 195 91 14 136 51 138 157 53 3 11 142 111 188 34 141 127 39 137 52 162 62 104 180 191 15 35 12 6 71 169 155 90 192 105 158 168 189 50 115 174 110 82 149 117 197 165 176 186 156 163 30 92 159 79 19 46 150 67 32 9 106 185 49 194 102 65 69 85 73 166 128 47 196 129 130 75 167 100 84 1 31 87 17 125 24 33 173 160 7 13 170 60 132 72 10 66 93 112 20 55 175 25 179 63 154 76 56 37 148 181 54 122 2816 file The next n 30325 lines containn dates in the Haab calendar format each in separate line The year is smaller 17208 then 5000H3OutputH3The date in Tzolkin should be in the following formatPINum 0 198 52 103 105 67 39 47 48 20 102 9 78 45 124 55 161 27 131 23 120 130 194 36 61 10 104 165 30 82 81 139 4 44 160 1 115 94 97 132 64 100 177 137 181 73 86 71 127 58 187 156 186 182 142 76 18 56 24 145 148 95 43 22 109 92 34 149 29 68 174 93 60 158 99 26 19 117 175 84 138 13 144 112 147 38 163 90 66 77 31 75 16 46 80 87 188 159 42 126 98 152 183 83 196 69 5 37 62 63 49 70 91 176 74 113 141 2 17 154 185 151 121 134 8 15 123 184 6 128 129 135 166 164 79 32 116 162 108 28 59 169 106 173 122 143 170 146 72 110 40 35 3 150 157 171 14 140 88 65 118 12 180 21 178 7 11 50 155 57 197 172 85 192 189 198 167 33 96 179 111 25 136 133 101 53 54 51 153 191 41 195 119 107 168 114 190 125 89 193 12714 ber NameOfTheDay YearIPThe first line of the output file contains the number of the output dates In the next n lines there aredates in the Tzolkin calendar format in the order c 13737 orresponding to the input datesH3ExampleH3BInput fileBPRE310 zac 00 pop 19393 0 0 152 40 10 84 4 125 101 132 34 113 105 102 6 79 94 23 5 122 35 92 7 9 128 67 133 46 37 103 53 108 115 87 64 119 25 100 21 111 95 33 72 48 60 16 44 22 50 118 77 62 49 129 38 3 145 65 85 137 68 70 106 12 127 126 26 93 24 28 90 82 18 140 39 61 104 135 47 66 81 51 14 91 80 136 31 144 120 76 15 43 75 112 30 121 107 110 71 2 27 45 147 134 11 139 89 19 151 117 83 149 69 32 143 131 152 41 52 74 124 73 20 78 59 42 116 138 63 109 8 97 55 146 36 86 13 56 29 99 58 141 142 148 96 98 17 123 130 1 88 114 54 150 57 29838 10 zac 1995PREBOutput fileBPRE33 chuen 01 imix 09 cimi 2801PREBODYHTMLHTMLHEADTITLECERC 1995 Problem D PipeTITLEHTML 30535 version generated by Kotas Koucky 1998HEADBODYH2 32130 ALIGNCENTERACM International Collegiate Programming Contest 9596H2P ALIGNCENTERBSponsored 0 22 4 18 9 14 11 13 22 21 19 17 7 8 5 2 16 1 3 15 10 20 6 12 10300 by Micro 0 192 156 89 52 67 139 141 15 69 147 56 2 68 11 185 48 66 123 153 57 97 12 81 178 30 83 77 3 163 62 63 192 4 180 145 58 9 65 138 76 59 53 64 90 41 79 61 117 152 98 116 179 8 85 80 25 159 121 154 114 181 129 166 150 158 104 140 28 94 126 6 182 172 188 146 109 135 91 131 21 47 40 99 173 112 143 168 17 18 190 157 165 183 171 36 20 142 51 164 177 44 16 184 49 128 32 92 133 167 96 33 127 74 34 151 115 113 14 134 191 101 78 106 72 10 38 162 5 31 86 174 136 95 122 13 75 54 1 169 46 118 107 137 55 7 130 43 170 155 87 73 22 186 71 176 45 161 37 60 84 70 42 105 148 82 102 144 125 100 160 103 35 111 110 149 50 175 26 132 39 120 88 93 108 24 23 29 27 187 189 19 119 124 26127 softBH3 ALIGNCENTERCentral European Regional ContestH3BRH2 ALIGNCENTERProblem D PipeH2P ALIGNCENTERBIn 0 109 58 84 38 28 36 9 81 82 32 1 106 54 47 12 63 90 23 42 4 79 21 92 7 88 62 86 33 52 67 61 25 22 96 65 102 40 46 26 44 8 72 60 51 70 50 66 89 2 27 3 91 87 56 31 34 29 71 109 105 13 68 49 98 107 76 45 83 35 100 30 39 57 17 74 6 97 94 20 10 18 5 15 69 73 11 48 37 101 64 93 80 14 77 85 108 103 99 78 16 41 95 55 53 24 59 19 75 104 43 12026 put fileB ttpipeinttBRBOutput fileB ttpipeoutttBRBProgram fileB ttpipepastt or ttpipecppttPT 4002 he GX Light Pipeline Company sta 29701 rted to prepare bent pipes for the new transgalactic light pipelineDuring the design phase of the new pi 0 35 4 28 11 14 30 9 17 26 7 6 10 31 13 22 8 16 19 12 18 24 20 21 25 15 23 34 35 3 2 32 1 29 33 27 5 320 pe shape the com 21203 pany ran into the problem of determ 0 74 20 4 13 51 9 28 36 37 6 46 43 15 54 59 7 50 33 62 10 67 64 17 65 25 5 26 48 74 18 32 56 40 35 30 39 66 60 24 61 29 16 31 38 3 47 63 1 14 27 8 57 12 34 53 68 58 73 70 44 22 11 69 2 55 45 71 19 72 21 42 49 41 23 52 10404 ining how 0 169 30 95 167 50 109 110 65 72 150 111 24 79 60 162 5 91 76 147 114 160 46 132 143 12 9 18 43 141 66 61 54 44 153 131 7 90 53 158 52 136 139 11 62 57 156 26 35 74 15 67 126 100 135 10 63 13 1 21 116 28 138 92 27 123 103 137 102 115 134 80 149 58 48 128 169 129 164 89 93 154 112 142 104 45 40 86 20 88 23 151 133 17 59 36 113 146 25 14 2 152 106 127 155 118 157 71 82 32 96 125 31 84 87 144 98 68 145 38 97 120 51 47 101 166 19 64 16 85 159 124 39 29 165 105 73 81 163 70 140 77 55 75 99 8 148 6 108 42 3 117 122 130 119 49 78 4 121 37 34 161 56 22 33 83 69 41 94 107 168 1693 farthe light can reach inside each component of the pipe Note that the material which the pipe is made fromis not transparent and not lig 11526 ht reflectingP ALIGNCENT 24195 ERIMG SRCpipegifPEach pipe component consists of many straight pipes co 0 48 26 18 12 27 41 11 23 13 2 46 15 32 39 42 20 7 10 9 45 31 34 38 35 29 37 44 4 1 3 24 47 25 33 22 8 19 5 48 30 43 36 16 21 17 14 40 6 28 505 n 11975 nected tightly together For the programmingp 12617 urposes the company developed th 0 71 5 39 17 43 40 63 59 19 62 25 42 30 8 50 38 28 29 33 55 57 44 52 16 9 18 45 51 15 37 26 47 32 27 13 67 36 46 61 34 14 11 65 22 4 58 56 49 35 7 48 41 24 71 31 54 6 64 70 69 23 53 68 12 60 3 1 10 66 2 20 21 27169 e description of each component as a sequence of points 16345 IxI1 IyI1 IxI2 IyI2 IxnI IynI where 0 1 1 19277 I 5427 x 0 137 42 108 57 65 25 84 16 85 1 113 68 3 75 79 88 109 14 70 53 93 10 62 41 133 27 71 40 11 120 82 56 46 61 43 111 23 58 6 28 26 119 33 20 49 117 66 91 44 47 137 135 38 121 74 67 18 92 29 22 89 125 36 81 31 72 112 39 97 64 87 103 80 50 132 131 17 8 134 4 5 77 94 21 24 130 90 106 98 35 63 51 2 101 55 54 129 52 60 83 126 15 45 69 86 76 123 59 99 12 100 32 118 19 116 136 105 48 73 122 78 124 34 115 114 127 9 30 96 95 37 107 110 102 128 7 13 104 18985 I1 lt IxI2 lt IxnI These are the upper points of the pipe contour The bottom pointsof the pipe contour consist of points with IyIcoo 2681 rdinate decreased by 1 To each 0 194 39 34 122 96 72 73 12 95 91 116 170 58 71 36 106 112 173 99 33 37 135 176 16 47 11 82 69 108 142 124 60 117 30 164 131 77 59 29 192 178 174 123 45 140 97 109 31 28 70 78 149 7 32 125 190 165 43 136 110 74 41 52 98 158 48 84 92 23 163 143 114 46 121 4 105 65 185 89 102 85 175 134 144 81 103 119 68 151 86 193 167 55 88 26 3 19 17 64 63 75 25 188 156 186 13 22 161 93 181 38 8 18 152 15 166 6 54 56 145 130 101 104 21 44 1 189 90 177 127 139 141 171 94 113 40 80 168 146 132 87 14 79 62 61 162 129 148 153 67 111 154 10 24 100 50 191 182 83 169 160 194 20 147 57 49 42 179 128 180 2 66 137 27 118 159 9 183 172 157 150 187 51 126 115 5 133 155 184 107 76 138 35 53 120 15108 upper point IxiI IyiI thereis a corresponding bottom point IxiI I 21970 yiI1 see picture ab 0 187 138 37 49 130 8 36 170 172 53 19 102 81 98 41 148 171 46 5 78 123 82 29 155 18 77 10 3 80 109 125 158 38 128 97 134 42 28 52 35 163 118 135 119 79 186 64 173 117 107 127 177 6 70 115 20 108 9 140 50 147 40 11 105 187 153 84 143 43 71 141 101 66 185 149 157 74 48 136 56 15 126 88 129 87 96 90 169 65 17 184 110 12 104 103 180 142 122 183 72 61 179 165 76 106 113 166 164 62 32 167 23 181 54 25 150 162 33 178 59 60 86 176 44 152 24 55 95 131 51 111 67 22 92 168 91 16 7 58 159 34 146 89 83 120 137 112 69 68 31 121 151 57 30 47 175 4 26 94 13 100 45 154 156 174 99 182 132 93 133 144 27 114 1 21 73 2 161 63 160 75 139 116 124 39 145 14 85 28305 ove The company wants to find for each pipe component the point with maximal IxIcoordinate that th 30892 e light will re 12337 ach The light is emitted by a segment source with endpoints IxI1 IyI 0 136 120 10 45 38 47 41 66 55 12 2 39 16 110 75 113 82 36 6 85 127 73 29 121 124 94 52 90 126 63 70 101 25 122 17 74 77 59 42 125 117 83 81 102 72 53 23 18 86 28 62 19 54 99 14 89 133 115 7 93 49 68 104 130 91 79 98 20 71 96 107 9 58 131 92 114 84 24 112 95 35 61 34 60 40 44 67 33 43 76 100 65 116 37 22 136 103 56 26 129 118 106 128 15 123 105 31 111 80 119 8 134 30 132 87 78 135 11 109 51 3 27 57 48 5 64 13 50 4 69 108 46 88 32 1 97 21 21925 11 and IxI1 IyI1 0 173 139 66 135 43 138 69 95 137 126 17 29 27 106 46 35 141 107 112 26 123 53 47 64 38 130 89 136 4 88 125 122 40 116 96 165 87 166 118 14 21 78 55 31 147 16 143 103 12 92 114 160 124 33 153 19 142 61 128 65 121 34 49 117 105 79 28 97 36 131 59 104 80 101 145 168 173 151 25 172 99 7 44 10 37 3 158 32 148 58 13 113 48 77 56 110 73 156 134 167 76 83 144 157 91 115 1 109 60 67 15 9 90 30 63 120 171 39 22 169 155 70 127 154 42 75 51 152 81 74 133 119 163 93 24 108 129 18 2 94 6 71 161 98 72 170 8 54 50 150 111 23 57 5 162 164 140 84 159 100 45 68 62 82 86 20 11 85 132 146 41 52 149 102 12300 endpoints are emitting light too Assume that the light is not bent at the pipe bent points and the bent points do n 16218 ot stop the light beamH3InputH3The input 0 175 13 16 71 47 141 60 11 129 161 6 67 84 160 158 123 79 168 100 49 61 14 10 25 149 32 2 119 83 27 133 1 86 41 145 107 94 76 62 130 110 43 169 91 58 51 90 80 101 148 78 88 57 3 42 153 102 39 121 66 5 171 162 109 73 92 164 53 163 17 4 159 54 118 138 22 122 170 96 35 98 23 167 38 128 65 112 172 166 156 113 104 21 44 50 154 136 127 99 137 117 19 144 174 173 124 157 63 68 85 72 120 12 93 155 18 46 134 95 69 56 150 26 70 7 52 106 140 29 108 147 59 8 126 37 125 55 175 116 24 114 105 77 45 20 165 103 139 89 31 151 152 143 28 87 146 82 81 34 75 115 111 64 15 142 40 30 132 36 33 131 135 48 9 74 97 12765 file contains several blocks each describing one pipe com 22294 ponent Each block starts with thenumber of bent points 2 lt InI lt 20 on separate line Each of the nex 0 27 2 13 7 10 19 27 11 14 20 8 18 15 16 3 5 9 24 4 17 1 6 25 21 12 26 23 22 4802 t InI lines contains a pai 16626 r of real valuesIx 0 99 71 48 32 7 14 89 94 27 39 83 76 11 56 55 60 25 58 33 63 13 36 18 37 43 5 57 97 77 34 41 92 85 96 95 62 90 54 44 91 22 81 88 2 70 53 28 26 31 61 38 21 8 51 74 79 52 3 68 20 17 75 10 67 42 84 93 80 64 50 6 47 59 4 98 78 45 86 99 30 35 19 49 24 9 73 87 40 46 66 15 69 82 23 29 16 65 1 72 12 16974 iI IyiI separated by space 1662 The last block is denoted with InI 0H3OutputH3The output file c 0 61 27 25 13 26 14 22 24 34 16 53 10 38 43 45 19 11 41 52 4 30 50 29 40 57 18 5 55 46 1 44 9 61 54 48 56 2 8 37 28 35 51 20 49 32 58 33 42 23 17 21 60 7 39 47 36 15 3 59 6 31 12 25082 ontains lines corresponding to blocks in input f 6425 ile To each 5030 block in the 0 166 52 86 93 8 134 91 45 25 82 69 119 78 104 19 118 150 101 7 81 83 144 133 130 126 92 85 154 23 22 28 1 51 20 57 15 77 35 32 141 89 58 43 95 17 48 132 70 123 122 124 14 27 108 131 33 156 155 106 151 39 75 163 68 164 55 50 46 90 97 6 99 29 10 2 113 37 42 105 140 84 142 111 149 162 152 79 112 114 125 60 139 62 4 12 53 31 38 49 100 127 65 128 137 157 94 129 160 103 159 136 71 148 41 147 73 40 16 80 56 117 161 61 72 165 44 11 145 107 116 30 24 121 110 26 66 146 5 64 21 115 36 166 98 3 158 13 74 143 102 135 18 34 54 153 67 47 109 9 76 63 96 120 87 59 138 88 12225 input file thereis one line in the output file Each such 0 105 105 14 12 70 35 30 72 82 5 73 60 104 27 37 83 24 81 3 2 46 22 17 97 13 42 32 28 39 8 53 98 40 78 9 47 11 19 93 21 55 63 1 86 23 50 99 34 102 87 101 69 20 65 74 56 76 92 33 62 44 10 88 95 48 6 31 45 52 66 71 7 57 91 80 59 94 90 84 96 89 38 18 58 29 85 15 103 25 61 36 77 41 54 75 67 49 100 64 16 4 68 79 26 43 51 11600 line contains either a real value written with precision of two decimalplaces or the message 16812 ttThrough all the pipett The real value is the desired maximal IxIcoordinate of thepoint where the l 7944 ight can reach from the source for c 0 172 108 30 15 70 10 99 114 125 76 49 59 117 25 57 93 31 19 54 135 134 29 162 87 138 3 147 172 120 121 149 1 160 143 65 139 52 109 102 84 28 55 118 42 104 154 94 129 64 51 128 38 24 66 61 14 113 170 5 165 8 90 116 67 145 81 34 126 131 88 97 144 167 74 130 62 153 95 91 107 43 4 71 82 86 78 50 41 136 127 17 124 75 155 106 89 83 58 32 18 112 79 132 158 33 133 110 77 40 16 137 63 157 101 100 73 148 123 164 23 103 56 146 163 141 140 152 105 11 159 80 2 27 171 9 92 161 119 22 72 150 48 96 37 26 53 36 47 156 111 68 69 21 46 168 6 115 12 35 169 166 20 44 142 122 45 151 85 60 98 39 7 13 14272 orresponding pipe component If this value equals toIxnI then the message ttThrough all the pipett will appear in the out 7546 put fileH3ExampleH3BInput fileBPRE40 12 2 18308 4 16 460 12 065 4457 55712 10817 16550PREBOutput fileBPRE467Through all the pipePREBODYHTMLHTMLHEADTITLECERC 1995 Problem A Maya CalendarTITLEHTML version generated by K 0 170 135 105 6 100 24 103 168 71 66 99 124 85 32 89 16 55 18 50 44 164 113 82 138 17 137 119 11 22 115 72 23 41 4 36 78 46 104 25 94 33 92 97 5 39 62 154 126 58 152 80 147 153 12 64 76 14 81 70 101 95 79 38 40 112 161 20 156 151 15 148 57 90 7 98 27 53 37 134 30 67 75 93 108 120 129 60 45 19 61 91 49 117 29 143 130 47 109 111 63 107 149 35 54 10 136 122 163 144 127 110 42 51 26 102 128 121 146 87 106 86 96 169 68 145 77 165 132 21 88 131 150 69 142 162 155 73 31 13 83 116 9 28 133 52 167 158 48 65 114 8 74 157 140 170 1 59 125 159 34 3 166 84 139 118 2 43 160 123 56 141 9918 otas Koucky 1998HEADBO 0 4 2 1 3 4 21455 DY 0 57 42 11 14 7 21 55 56 13 38 37 50 18 3 19 23 34 4 30 31 40 41 5 24 49 57 43 29 10 47 8 44 33 48 36 32 17 35 52 22 6 27 26 2 25 16 53 51 46 39 1 45 9 20 54 28 12 15 22754 H2 ALIGNCENTERACM International Collegi 14339 ate Programming Contest 9596H2P ALIGNCENTERB 3710 Sponsored by MicrosoftBH3 ALIGNCENTERCentral Eu 0 169 10 34 166 66 143 18 108 14 33 105 126 152 30 56 103 40 159 45 72 111 90 62 64 50 76 154 1 43 125 88 135 41 150 31 22 92 109 79 133 39 91 139 81 122 86 65 102 114 85 93 100 60 89 149 52 36 12 58 97 49 130 55 106 29 71 164 9 84 117 128 94 67 46 27 115 101 13 99 11 167 8 78 80 157 151 28 15 68 70 87 26 95 98 136 104 112 74 107 169 119 155 51 4 141 57 161 83 21 75 61 165 127 162 120 121 32 145 142 148 146 110 132 23 96 137 138 158 153 124 129 113 69 25 35 48 140 77 37 42 168 163 123 6 147 47 134 44 144 17 24 160 118 53 116 54 59 19 73 16 63 7 2 82 131 20 5 3 38 156 28020 ropean Regional ContestH3BRH2 ALIGNCENTERProblem A Maya CalendarH2P ALIGNCENTERBInput fileB ttmayainttBRBOutput fi 1969 leB ttmayaoutttBRBProgram fileB ttmayapastt or ttmayacppttPDuring h 0 184 6 89 79 48 52 146 34 31 15 94 137 33 124 175 61 29 98 168 69 95 164 8 104 142 119 158 162 153 120 42 85 76 60 93 49 58 160 67 3 68 47 62 7 135 100 75 96 130 181 112 154 5 11 173 97 84 111 14 178 63 59 13 23 40 157 105 65 152 134 51 54 141 50 155 83 66 57 9 102 17 165 77 88 115 169 107 35 108 91 144 125 109 161 167 78 37 159 123 22 53 127 81 46 70 4 82 131 143 73 122 149 90 172 86 133 39 177 170 121 80 150 27 176 36 151 43 10 138 1 92 139 110 44 147 156 180 163 179 145 136 2 128 25 55 132 117 116 103 30 183 87 113 26 140 182 74 24 32 171 166 174 41 71 38 126 101 118 64 45 16 148 56 21 114 72 106 12 28 19 184 18 99 129 20 4111 is last s 20500 abbati 0 166 40 26 114 32 60 92 22 125 160 54 18 95 98 164 23 45 102 76 21 128 41 27 62 77 122 120 28 43 35 104 78 42 165 133 138 11 129 137 161 52 124 39 63 80 152 34 126 37 145 5 130 131 119 139 20 13 157 112 134 2 143 118 44 156 94 96 163 46 70 58 100 83 10 79 6 67 159 153 59 106 87 33 107 73 140 31 82 89 74 69 148 111 105 51 68 147 146 110 121 53 17 115 19 88 99 149 66 72 132 86 61 116 162 127 136 117 30 47 48 8 144 150 93 71 158 56 141 7 9 49 1 38 3 84 85 15 29 123 36 75 91 135 103 97 101 81 57 142 25 4 16 155 151 64 14 50 166 24 154 12 113 109 90 65 108 55 13282 cal professor M A Ya made a surprising disco 0 24 4 19 24 9 16 7 10 6 14 22 3 20 23 21 11 18 8 1 13 17 15 5 2 12 14609 very about the old M 0 93 16 78 23 1 84 31 27 20 28 17 76 64 14 41 35 34 50 80 22 38 37 55 53 15 33 39 43 24 42 63 46 26 25 87 57 36 2 86 71 18 58 44 83 93 10 12 56 52 92 40 72 48 65 5 3 19 9 7 6 8 67 45 49 85 59 29 60 66 88 32 73 62 4 91 81 79 51 82 89 75 68 21 90 47 70 30 13 74 77 61 11 54 69 32499 aya calendarFrom an old knotted message professor disc 0 174 131 75 63 66 33 90 51 161 89 48 85 100 81 154 98 88 117 27 80 172 87 79 163 25 142 38 157 164 74 70 72 159 104 146 95 124 115 30 125 50 71 105 35 158 96 116 49 102 126 83 40 10 29 11 42 58 62 152 55 2 141 135 121 31 68 37 167 171 60 92 170 156 140 57 109 118 3 122 128 139 14 34 143 56 111 7 114 1 150 44 77 52 147 53 78 101 21 36 12 4 113 132 136 73 110 123 82 112 69 18 119 129 17 28 93 39 91 16 26 47 137 173 134 165 148 8 20 153 9 32 76 86 107 22 59 24 67 5 84 65 133 145 64 149 138 94 130 61 13 15 144 43 19 155 23 54 103 162 6 99 46 166 97 174 108 45 106 168 41 151 160 127 120 169 31804 overed that the Maya civilization used a 365 day long year calledIHaabI which had 19 months Each of the first 18 months was 20 days long and t 4168 he names of the monthswere Ipop no zip zotz tzec xul yoxkin mol chen yax zac ceh mac kankin muan pax koya 0 163 45 24 86 104 94 141 129 63 53 40 109 144 133 26 11 55 117 92 60 74 32 149 7 131 82 124 107 21 42 30 38 12 146 103 142 28 148 83 58 116 159 102 72 138 62 29 154 1 23 59 120 18 140 54 39 163 89 93 157 136 9 47 51 31 46 127 78 73 105 158 48 113 43 57 6 80 110 134 3 64 36 5 128 19 139 37 122 44 22 112 10 97 147 121 123 90 61 25 68 76 143 111 101 52 137 67 77 119 156 66 155 27 161 69 99 34 85 118 150 49 33 115 65 152 41 87 14 50 100 108 84 4 13 56 2 114 95 125 88 106 79 15 35 81 71 160 16 8 96 153 20 130 17 70 162 91 98 135 132 75 151 145 126 6888 b cumhuIInstead of having names the days of the months were denoted by number 17727 s starting from 0 to 19 The lastmonth of Haab was called IuayetI and had 5 days denoted by numbers 0 1 2 3 4 The Maya believe 31523 d thatthis month was unlucky the court of justice was not in session the trade stopped people did not even sweepthe floor pFor religious purposes the Maya used 0 181 14 161 47 72 25 87 160 124 31 115 75 122 76 27 53 60 79 10 144 112 68 127 81 45 8 17 103 102 37 117 62 166 83 5 119 44 46 54 71 95 55 21 118 58 111 154 39 136 113 84 18 100 9 63 3 12 140 77 96 152 16 120 28 51 2 126 36 164 180 42 125 64 150 50 69 32 24 6 109 132 65 145 114 80 82 73 116 173 7 4 20 149 143 56 170 78 49 137 99 34 30 90 26 33 92 147 151 15 104 153 22 52 134 157 94 121 101 165 162 172 146 138 106 174 175 74 123 176 130 158 181 128 177 19 70 141 48 93 13 43 59 85 23 41 156 135 159 179 167 171 110 89 38 155 88 131 1 178 108 35 97 66 148 67 169 86 105 91 11 129 57 98 40 133 139 61 107 29 163 168 142 24449 another calendar in which the year was called ITzolkinI hollyyear The year was divided into thirteen periods each 20 days long Each day was denoted by a pair 29960 consisting of a number and the nam 0 86 38 42 60 39 14 66 49 28 22 63 18 17 48 11 37 74 51 43 76 58 61 69 26 53 13 20 71 65 59 33 75 9 77 19 81 55 73 25 67 79 86 40 10 45 24 5 68 82 44 57 36 84 1 16 47 15 70 31 4 56 34 23 50 85 7 32 54 30 83 12 41 78 80 62 6 35 2 29 3 46 52 8 27 72 21 64 4976 e of the day They used 20 names Iimix ik akbal kan chicchan c 6070 imimanik lamat muluk ok chuen eb ben ix mem cib caban eznab canac ahauI and 13 28646 numbers both incycles PNotice that each day has an unambi 0 11 2 8 5 3 7 1 9 11 6 10 4 27289 guous descr 0 8 7 6 2 1 5 4 3 8 5203 iption 0 107 52 53 81 93 56 57 75 87 82 25 19 18 3 67 31 70 105 45 24 29 83 37 15 26 102 48 104 79 54 49 44 27 64 76 88 63 20 77 35 4 9 92 8 78 28 60 59 43 97 80 71 86 85 65 21 14 89 38 2 30 62 106 34 90 46 68 84 51 11 7 74 23 50 69 10 66 73 98 6 94 39 32 103 16 12 13 95 47 99 5 40 96 72 41 42 55 1 33 91 61 100 58 101 22 107 17 36 1337 For example at the beginning of the year thedays were described as follows PI1 imix 2 ik 3 akbal 4 k 0 136 21 98 104 79 44 6 33 46 78 37 69 125 108 18 40 95 83 29 42 36 20 3 109 68 128 38 85 110 81 64 15 99 96 77 114 50 82 16 129 53 9 118 131 65 89 27 106 119 70 67 87 14 60 56 97 2 5 135 103 74 112 1 34 80 63 51 39 62 105 25 54 90 132 134 133 127 113 117 116 31 24 84 124 107 130 32 28 91 41 94 10 26 45 111 35 136 73 59 22 58 120 100 8 86 66 92 12 123 52 13 93 71 102 72 17 19 11 55 57 76 115 75 101 4 43 23 47 49 122 48 61 121 88 30 126 7 18036 an 5 chicchan 6 cimi 7 manik 8 lamat 9 muluk 10 ok 11 chuen 12 eb 13ben 1 i 2447 x 2 mem 3 cib 4 caban 5 eznab 6 canac 7 ahau and again in the next period 8 imix 9 ik 10akbal IPYears 8199 both Haab and Tzolkin were denoted by 0 102 55 49 5 66 59 26 13 64 71 96 92 24 16 81 97 22 52 42 41 43 72 69 74 39 85 19 63 14 91 23 62 40 61 2 1 102 68 94 15 76 35 101 75 44 7 3 79 89 38 33 77 46 4 84 60 99 82 10 95 17 88 32 93 87 90 47 12 48 51 65 67 21 28 100 6 78 30 58 80 8 29 86 20 53 25 57 98 37 73 56 70 36 83 45 11 54 34 31 9 27 50 18 9608 numbers 0 1 where the number 0 was th 0 92 44 69 46 65 30 29 22 85 24 8 25 17 31 35 92 11 28 63 33 4 50 52 54 67 45 82 90 43 2 34 15 73 3 64 77 61 81 21 12 80 59 49 53 7 16 14 13 55 20 70 62 40 42 6 39 71 57 47 19 91 5 66 75 72 32 38 1 56 37 78 87 84 88 36 27 74 18 10 60 23 41 68 83 76 26 58 89 48 79 9 86 51 12831 ebeginning of the world Thus the first day was LIHaab 0 pop 0 BRLITzolkin 1 0 81 25 3 40 8 68 15 45 11 4 77 38 37 2 36 20 73 46 79 76 70 72 42 34 26 50 58 51 24 9 41 53 18 55 33 21 66 22 12 56 10 31 60 48 63 61 52 64 23 62 67 78 6 17 29 16 71 1 32 75 74 13 27 47 65 39 5 14 80 28 30 19 7 59 44 81 49 43 54 57 35 69 19134 imix 0 PHelp professor M A Ya and write 26500 a program for him to convert the dates from the Haab calendar 177 tothe Tzolkin calendarH3InputH3The date in Haab is given in the foll 0 71 64 49 24 56 7 43 36 45 66 47 3 1 11 15 28 52 59 25 50 69 6 16 42 5 63 17 19 14 70 33 55 60 30 18 62 53 40 48 57 44 41 71 54 39 37 21 38 10 2 20 26 9 29 13 27 8 32 34 51 35 61 12 67 4 23 31 22 68 58 65 46 9553 owing formatPINumberO 5370 fTheDay Month YearIPThe fir 0 185 180 105 46 111 143 70 160 171 36 128 104 75 53 133 154 95 107 141 93 85 87 80 63 25 1 72 79 19 168 64 124 134 159 183 121 82 11 94 78 47 74 35 179 137 90 127 45 129 49 88 165 12 89 96 103 110 123 131 8 116 161 55 102 152 149 112 48 61 115 66 125 162 68 172 166 30 170 5 114 151 32 147 138 57 20 69 44 174 181 177 24 117 132 182 100 38 118 178 4 84 67 158 56 51 140 83 99 14 156 185 146 77 119 62 142 145 40 81 50 58 184 73 157 164 136 153 91 16 13 163 169 15 144 176 130 18 33 71 39 113 155 98 17 31 76 122 22 173 7 150 126 27 108 86 9 135 101 2 6 42 175 97 106 148 92 41 60 34 109 65 28 37 43 26 3 120 139 167 23 54 52 21 59 29 10 28922 st line of the input 27390 file contains the number of the input dates in the file The next n lines containn dates in the Haab calendar 0 5 4 2 1 5 3 3321 forma 3534 t ea 29652 ch in 0 181 65 122 143 180 164 11 21 10 165 7 149 161 81 77 113 168 89 97 55 86 49 56 93 138 85 72 37 177 118 167 141 128 8 45 32 95 98 28 64 107 58 79 175 5 50 27 22 102 6 78 62 105 99 33 34 36 130 14 129 153 61 166 124 76 38 47 160 87 13 125 43 119 144 75 26 112 148 39 170 147 18 4 23 52 132 44 80 51 172 73 162 181 83 84 145 90 156 70 94 171 135 110 20 3 120 150 9 71 69 59 15 103 179 54 25 60 100 1 116 123 29 2 131 115 96 104 159 133 174 16 126 139 35 57 140 152 108 121 163 137 12 146 155 74 176 178 46 134 53 158 63 88 127 41 19 101 114 169 17 67 24 42 66 111 154 106 30 48 68 136 173 92 117 151 31 157 40 142 91 109 82 1688 separate line The year is smaller then 5000H3OutputH3The date in Tzolkin should be in the follo 13092 wing formatPINumber Name 0 81 27 24 50 34 75 29 61 2 66 79 53 18 51 7 13 22 63 43 77 80 44 16 52 12 55 74 78 49 73 37 59 14 28 69 35 15 40 45 54 81 3 23 17 57 11 60 56 39 33 6 31 71 10 8 1 19 76 4 47 30 68 70 32 48 25 42 41 46 58 67 20 5 26 9 38 65 36 21 72 62 64 18474 OfTheDay Ye 4350 arIPThe first line of the output file contains the number of the output dates In 2862 the next n lines there aredates in the Tzolkin calendar format in the o 0 169 3 83 23 165 5 124 18 114 128 73 160 71 12 108 27 104 107 103 11 70 39 119 142 65 126 168 141 77 17 150 55 113 106 62 36 60 148 72 134 92 120 111 85 68 87 159 64 81 22 89 138 19 139 41 131 1 76 146 14 10 33 88 29 151 25 152 63 122 156 115 153 51 102 7 147 32 49 50 161 154 78 31 100 155 79 74 6 130 157 162 123 54 8 144 61 66 42 35 125 101 167 16 13 57 24 140 45 52 97 116 136 164 145 28 129 75 98 93 56 149 20 110 4 132 21 30 95 26 135 38 69 43 163 2 84 112 133 91 143 166 118 46 99 90 80 109 44 34 58 158 86 37 105 9 59 48 94 121 67 169 96 40 53 82 117 15 47 127 137 1492 rder corresponding to the input datesH3ExampleH3BInput fileBPRE310 zac 00 pop 010 zac 1995PREBOutput fileBPRE33 chuen 01 imix 09 cimi 2801PREBODYH 0 63 48 36 38 3 60 27 2 41 28 62 7 11 19 24 39 52 54 6 49 42 46 50 44 47 53 31 9 29 18 37 25 23 63 51 10 16 34 14 40 57 21 13 55 61 35 56 43 22 17 26 15 59 5 12 58 20 45 33 32 8 4 1 30 32543 TMLHTMLHEADTI 0 141 59 22 57 106 94 72 126 5 75 41 37 85 93 67 35 87 65 47 34 58 55 90 20 114 115 62 118 79 100 4 109 96 30 11 111 105 38 14 141 140 40 112 31 78 117 26 97 17 23 124 121 101 83 66 28 10 110 12 91 64 132 36 71 95 9 123 16 29 136 99 21 128 89 120 48 24 73 61 56 103 82 6 138 119 86 125 80 129 45 2 27 15 33 44 84 76 3 92 135 107 134 13 102 139 122 116 19 51 137 81 70 54 1 104 88 46 53 32 43 127 98 63 7 42 113 49 131 39 18 50 68 60 133 69 25 52 130 8 74 108 77 16903 TLECERC 1995 Problem B TransportationTITLEH 28028 TML version generated by Kotas Koucky 1998HEADBODYH2 ALIGNCENTERACM International Collegiate Programming Contest 9596H2P ALIGNCENTERBSp 0 57 6 42 4 51 34 39 8 32 21 10 41 29 46 50 17 15 55 19 31 44 12 1 52 22 57 28 16 30 18 53 26 43 14 47 9 45 33 37 49 2 27 20 35 5 56 23 54 11 13 48 40 36 25 24 3 38 7 31951 onsored by MicrosoftBH3 ALIGNCENTERCe 144 ntral European Regional ContestH3BRH2 ALIGNC 24325 ENTERProblem B TransportationH2P ALIGNCENT 0 28 1 11 23 8 9 2 24 17 25 28 6 22 14 21 4 13 27 20 18 5 16 12 3 15 26 7 19 10 13449 ERBInput fileB tttraini 1744 nttBRBOutput fileB tttrai 27273 n 0 36 31 23 11 14 6 4 22 29 3 7 1 20 36 8 24 26 35 13 28 19 15 2 27 10 9 17 30 34 12 32 18 5 16 25 33 21 11550 outttBRBProgram fileB tttrainpas 0 145 71 45 61 12 119 48 60 9 138 53 26 24 110 11 27 105 20 86 77 117 63 120 141 67 15 97 65 51 34 127 123 140 92 78 129 87 25 54 8 139 28 113 122 112 135 96 1 70 23 42 89 62 79 103 114 2 49 144 95 76 44 115 131 90 91 7 6 94 80 118 40 38 31 124 137 116 32 4 83 47 85 14 59 56 134 128 132 106 41 57 50 74 33 100 17 18 93 125 121 145 101 108 111 104 19 30 69 46 130 21 88 142 107 133 64 36 73 58 13 102 84 126 29 136 68 5 52 22 43 10 35 82 55 75 66 98 143 99 3 81 109 37 72 16 39 15764 tt or tttraincppttPRuratania is just entering capitalism and is establishing new enterprising activities 0 174 111 105 142 47 15 73 68 23 90 13 3 74 79 164 171 36 172 28 11 139 2 63 18 4 81 121 94 50 127 33 96 95 39 161 174 86 152 119 45 61 135 117 148 170 72 14 113 131 55 120 158 133 6 57 89 24 51 167 103 136 92 53 134 112 98 37 80 107 97 166 114 110 91 20 8 44 104 93 16 7 70 87 42 52 126 67 116 19 169 123 46 66 48 101 26 64 31 22 59 100 124 118 168 43 60 145 65 157 82 38 137 159 129 88 128 140 125 156 56 85 34 160 30 83 115 10 77 84 151 141 150 102 99 122 1 132 12 40 41 35 143 138 76 71 9 162 32 78 130 147 173 165 144 17 49 25 69 58 149 163 62 75 108 21 54 154 146 106 27 109 29 5 153 155 1718 in many fields including transport The transportation company TransRuratania is starting a new express train from city IAIto city IBI with several sto 20827 ps in the stations on the way The stations are successively numbered city IAI stationhas number 0 city IBI 22592 station number ImI The company runs an experiment in order to improve passengertransportation capacity and thus to increase its earnings The train has a 0 41 40 32 3 17 26 7 39 1 23 2 6 27 34 18 36 21 4 25 13 9 22 30 8 5 29 20 31 38 19 37 12 35 28 14 24 41 16 15 10 33 11 11372 maximum capacity In 0 122 79 69 101 107 17 78 1 54 76 91 29 56 35 34 8 106 19 39 109 44 14 95 32 61 52 38 92 40 85 2 62 115 68 43 15 75 64 117 31 88 100 111 65 103 24 16 84 102 70 6 82 22 74 87 28 112 42 18 3 9 58 114 89 41 77 23 121 81 26 96 118 55 49 63 25 86 90 7 27 57 48 51 13 10 12 72 119 47 104 93 67 20 66 120 80 45 4 73 98 71 5 105 11 99 94 36 108 30 113 97 110 83 59 122 21 37 50 53 46 33 116 60 5999 I passengersThe price of the train ticket is equal to the number of stops stations between the starting sta 13917 tion and thedestination station including the d 0 32 8 4 25 29 23 18 2 27 24 11 10 14 5 6 22 26 1 21 28 13 9 3 7 19 15 30 17 31 12 32 20 16 17369 estination station Befor 0 50 19 46 28 18 7 13 26 10 34 50 24 39 29 20 30 11 15 45 33 2 31 8 9 37 12 35 38 3 21 43 48 22 14 4 5 23 47 41 27 6 49 36 16 42 25 1 44 32 40 17 23173 e the train starts its route fro 2563 m the city IAI ticke 0 134 76 2 45 24 126 30 37 58 63 54 49 118 107 1 9 64 7 111 67 82 6 8 89 132 86 13 52 71 96 25 99 57 74 29 131 19 51 128 70 103 48 91 66 93 56 41 108 62 68 81 55 80 124 65 130 18 43 78 15 53 106 5 77 22 60 104 34 39 72 116 10 125 23 102 42 84 32 75 127 115 61 28 129 17 4 33 59 90 100 31 113 14 44 88 121 21 114 110 120 3 133 95 87 40 134 92 27 38 46 69 123 94 98 12 16 85 112 50 47 26 101 109 11 73 36 97 122 117 83 105 79 119 35 20 17433 to 13663 rders are collected from all onroute stations The ticket 0 134 32 23 58 128 101 33 100 82 29 39 95 73 51 8 117 31 19 20 111 78 69 56 35 40 113 34 102 121 112 63 17 103 79 37 77 10 131 22 50 25 106 67 87 66 1 13 62 72 85 91 12 97 110 132 81 60 71 76 120 4 11 21 127 118 30 104 43 123 86 92 83 74 107 45 24 3 28 61 70 49 9 94 53 89 55 105 16 65 93 36 14 54 114 88 52 116 27 5 44 2 133 134 125 47 84 126 109 15 26 38 80 115 6 130 75 108 42 99 59 90 119 96 41 46 7 48 122 129 68 18 124 64 57 98 26504 order from the station ISI means all reservations oftickets from ISI to a fixed destination station In case the company c 14022 annot accept all orders bec 27771 ause of thepassenger capacity limitations its rejection policy is that it either completely ac 0 13 1 12 7 4 8 11 9 13 6 5 10 2 3 8948 cept or com 17265 pletely 18908 rejectsin 0 12 1 10 7 9 5 12 4 3 6 2 8 11 24335 gle o 26003 rders from 3509 s 0 154 108 18 124 4 7 150 17 61 80 12 68 56 129 99 121 110 39 1 128 146 51 117 118 24 50 130 105 120 67 88 107 76 134 11 90 65 20 104 40 109 97 133 14 26 115 21 66 49 137 36 9 41 83 101 93 70 77 27 127 6 96 46 13 131 63 123 53 112 85 10 16 22 103 79 57 142 100 82 59 52 113 119 71 111 151 64 122 43 19 45 73 62 94 5 44 25 147 140 84 148 138 33 35 149 31 74 23 92 69 89 114 116 86 136 153 126 125 38 143 60 81 91 42 135 37 154 145 2 32 3 30 47 58 95 8 106 78 75 139 15 144 54 98 55 87 141 48 102 152 29 34 132 72 28 22718 ingle stationsPWrite a program which for the given list of orders from 0 147 129 85 114 19 25 81 10 72 40 36 39 44 140 33 67 121 76 21 145 63 79 5 48 112 70 9 73 134 20 99 92 61 71 24 126 75 106 17 54 87 12 122 105 102 138 30 55 142 132 37 118 47 7 131 136 3 78 66 26 62 69 14 45 77 119 18 144 29 111 53 124 147 86 83 108 6 104 135 115 80 27 91 58 95 123 60 109 146 50 4 103 127 49 89 97 51 16 137 43 143 11 101 141 139 128 130 117 88 8 116 94 98 52 68 28 113 22 133 31 57 107 110 100 15 2 74 42 46 1 35 13 90 34 65 59 64 125 120 38 93 32 41 23 96 84 56 82 24641 single 22631 stations on the way from IAI to IBI determinesthe biggest possible total earning of the TransRuratania 11176 company The earning from one accepted order isthe product o 0 166 81 18 95 129 44 161 80 106 107 72 123 156 4 51 97 60 130 160 23 39 133 21 147 96 46 42 45 33 65 71 101 141 41 10 16 43 119 1 136 55 83 47 103 78 57 165 126 92 3 24 5 63 49 157 15 35 91 38 77 131 140 31 114 30 143 61 93 27 9 146 144 68 87 151 76 28 110 164 32 124 105 145 17 85 139 109 118 52 29 53 25 104 158 74 111 36 149 69 137 102 112 155 88 13 98 26 67 8 64 20 14 152 153 148 132 84 73 50 121 59 94 48 89 100 127 162 108 56 134 54 115 86 82 12 150 40 6 154 135 62 58 142 166 116 117 120 34 99 19 113 2 159 37 125 90 79 22 163 7 66 138 128 70 75 11 122 17264 f the number of passengers included in the order and the price of their train ticket 1574 s The totalearning is the sum of the earnings from all accepted ordersH3InputH3The input file is divided into blocks The first line in each block contains th 1848 ree integers passengercapacity InI of the train the number of the city IBI station and the number of ticket orders fr 0 133 27 84 52 131 92 44 106 38 91 72 110 34 73 70 47 124 61 17 40 18 48 128 87 98 95 25 2 88 45 66 111 123 89 79 115 85 20 57 100 129 119 13 64 126 12 81 83 77 63 35 130 19 68 78 133 8 22 109 104 112 23 132 67 28 103 54 29 33 10 53 76 7 90 75 16 4 41 49 118 39 11 14 114 60 93 30 102 15 37 74 105 71 65 125 6 21 120 94 107 116 121 96 82 51 46 31 127 113 97 86 69 117 62 26 9 36 59 1 56 5 55 108 58 99 32 80 50 42 43 122 3 101 24 24180 om all stationsThe next lines contain the ticket orders Each ticket order consists of three integers star 0 191 61 100 184 63 72 12 191 45 13 89 86 116 176 150 135 169 103 133 165 108 35 175 180 95 138 79 97 104 109 102 73 124 26 32 156 46 119 90 99 148 130 7 43 55 92 118 155 17 113 88 123 181 128 24 22 81 140 160 131 44 56 68 189 146 5 27 163 11 143 31 182 94 141 168 158 91 29 185 177 87 110 152 41 38 67 93 190 132 8 139 62 30 85 69 42 159 174 23 136 6 9 58 186 49 40 48 142 77 167 161 144 96 52 76 134 125 78 173 171 172 57 18 64 106 101 51 178 98 149 66 164 2 107 60 188 15 126 183 19 187 105 4 162 147 53 54 25 179 83 10 37 151 166 120 80 157 127 153 21 115 129 121 28 117 82 114 112 84 65 34 14 74 16 111 1 50 70 137 145 39 170 154 20 36 3 47 71 75 59 33 122 3698 ting stationdestination station number of passengers In one block there can be maximum 22 orders The number ofthe city IBI station will be at most 7 The block where all three numbers in the 19124 first line are equal to zerodenotes the end of the input fileH3OutputH3The output file consists of lines corresponding to the blocks of th 15859 e input file except th 0 136 90 113 99 26 15 88 84 5 59 72 62 78 19 86 10 52 41 1 73 81 66 105 22 69 29 124 117 40 134 80 89 97 49 125 79 127 24 39 48 44 120 108 2 136 135 87 47 63 53 76 112 4 106 36 55 74 68 95 70 35 30 43 77 102 100 123 31 121 101 50 12 56 128 64 116 110 104 37 23 82 17 6 92 33 94 11 61 3 32 93 9 67 60 109 65 114 122 51 27 133 54 75 129 25 45 28 16 119 7 38 85 14 58 57 83 42 126 21 20 115 98 71 132 8 34 131 103 118 13 18 111 91 130 46 96 107 10074 e terminatingblock Each such line contains the biggest possible total earningH3ExampleH3BInput fileBPRE10 3 40 2 11 3 51 2 72 3 10 0 35 12 16 32 8 11 22 18 35 20 26 9 23 31 17 5 28 25 21 34 29 30 10 24 7 19 27 2 3 14 13 1 33 6 4 15 11418 10 5 43 5 102 4 9 8384 0 2 52 5 80 0 0PREBOutput fileBPRE 26310 1934PREBODYHTMLHTMLHEADTITLECERC 0 82 24 2 7 25 82 6 11 23 40 72 8 29 45 26 33 42 61 79 38 20 35 4 37 65 59 16 28 55 64 60 63 75 76 73 17 80 19 53 67 52 66 39 41 48 13 56 58 51 12 1 22 68 14 46 10 49 31 36 70 71 69 18 47 74 81 30 54 27 78 9 50 77 3 21 44 34 15 57 5 62 32 43 22238 1995 Problem C Johns tripTITLEHTML version generated by Kotas Koucky 199 0 184 126 40 44 73 47 70 8 49 177 4 7 68 154 23 180 2 77 149 80 83 172 43 114 95 176 36 139 3 64 145 140 127 143 133 125 12 111 144 50 15 155 59 34 87 113 25 123 166 54 97 86 28 60 53 107 84 117 1 91 14 61 88 165 168 128 132 100 182 16 46 159 148 99 158 41 31 153 103 160 108 24 179 72 39 13 174 120 102 104 66 130 55 162 27 30 89 156 131 151 181 56 62 138 112 65 137 58 93 18 67 57 150 105 171 26 76 82 129 32 5 163 169 173 119 106 45 6 33 121 63 94 92 135 79 81 51 118 141 170 98 157 101 146 109 152 96 42 142 21 9 38 147 184 115 48 78 20 164 71 17 52 167 29 122 90 124 74 11 134 183 10 161 175 37 35 75 178 85 19 116 110 69 22 136 3863 8HEADBODYH2 ALIGNCENTERACM International Collegiate Programming Contest 9596H2P ALIGNCENTERBSponsored by MicrosoftBH3 ALIGNCENTERCentral European Regional 1355 ContestH3BRH 6470 2 AL 0 162 66 35 16 89 81 33 53 77 56 20 150 127 136 30 156 11 149 38 37 52 19 55 28 73 70 13 79 142 71 102 47 109 162 115 118 29 147 129 57 76 15 153 3 90 45 82 48 40 87 61 2 94 5 104 101 14 62 21 32 158 152 54 151 113 141 39 74 31 36 120 130 58 110 60 68 107 80 154 99 88 50 93 157 4 1 95 91 8 124 121 114 126 111 44 125 18 160 64 51 108 100 96 135 137 59 139 134 132 26 112 10 43 161 86 63 117 67 146 78 27 143 75 65 12 106 7 34 144 133 138 49 140 119 69 122 41 97 145 23 24 123 85 83 159 42 17 116 25 105 155 84 128 9 103 6 72 131 148 98 22 92 46 13844 IGNCENTERPr 2487 oblem C Johns tripH2P ALIGNCENTERBInput fileB tttripinttBRBOutput fileB tttripoutttBRBProgram fileB tttrippastt or tttripcppttP 0 94 30 15 65 71 22 17 53 9 74 25 46 2 34 33 8 42 13 18 55 60 20 91 29 35 59 86 16 64 41 76 51 10 21 44 36 79 37 82 39 70 58 66 57 3 68 5 72 11 45 93 50 94 4 27 49 54 12 19 32 80 7 62 24 83 90 84 81 40 48 56 92 6 63 43 28 85 69 89 1 88 87 77 73 78 31 67 23 61 47 26 14 52 38 75 2763 Little Johnny has got a new car He decided to drive aroun 3483 d the town to visit his friends Johnnywanted to visit all his friends but there 22323 was many of them In each 0 129 13 25 104 7 119 55 87 75 102 22 44 117 42 52 17 41 8 45 24 9 122 105 43 59 27 63 76 108 34 110 4 65 35 40 49 56 62 94 81 86 15 80 46 60 82 61 69 74 101 67 114 57 66 77 124 97 126 79 83 19 51 36 73 125 118 115 113 92 37 1 10 109 103 112 32 33 99 6 38 58 14 95 54 20 116 85 21 16 3 26 127 121 123 29 93 2 71 107 68 39 70 78 84 129 31 120 18 90 106 50 28 88 89 64 23 12 53 100 72 91 48 11 5 98 96 30 111 47 128 13272 street he had one friend He startedthinking how to make his trip as short as possible Very soon he realized that the best way t 14431 o do it was totr 0 79 38 37 23 29 67 22 56 36 45 27 4 7 70 30 31 10 65 43 47 69 76 5 35 9 62 14 50 11 54 60 68 39 13 6 3 53 18 19 52 71 34 41 28 61 16 25 21 55 8 1 63 59 57 73 51 20 17 12 46 15 66 33 64 74 79 49 42 26 32 75 2 48 72 78 44 77 40 24 58 5149 avel through each street of town only 0 77 3 52 11 32 24 69 48 1 51 2 56 31 75 39 18 17 29 46 54 73 20 49 4 74 55 15 21 60 30 53 26 65 44 59 23 50 40 36 16 25 63 37 66 43 67 6 42 7 77 38 62 19 9 10 5 68 58 76 33 41 28 14 72 70 47 71 8 35 13 12 64 45 57 22 34 61 27 25779 once Naturally he want 0 90 32 13 15 40 14 35 68 42 56 2 76 73 58 7 34 90 63 30 67 16 89 41 28 33 43 65 44 52 70 62 53 54 17 24 9 69 49 48 74 31 87 3 51 8 71 72 57 29 64 12 47 21 61 38 39 25 27 75 80 82 23 6 19 55 37 5 10 1 18 88 59 78 83 45 84 77 4 86 26 81 22 36 11 66 50 60 79 85 46 20 22013 ed to finis 810 h his trip at the same place hestart 22008 ed at his parents housePThe str 0 89 9 59 63 50 84 49 37 15 58 19 75 56 24 6 62 33 7 12 65 17 54 67 22 41 34 11 57 45 79 69 88 64 51 3 32 31 8 74 60 14 38 55 78 30 26 86 4 52 40 36 23 71 13 16 29 27 44 80 77 10 85 2 1 61 87 73 35 18 39 25 72 89 53 28 81 70 82 48 47 42 68 46 83 66 5 20 21 76 43 23848 ee 31004 ts in Johnnys town were named by integer num 0 132 1 64 88 99 97 124 6 40 131 48 43 92 33 21 75 125 77 118 82 105 81 62 31 45 10 63 87 17 79 4 84 39 18 14 15 13 121 8 71 56 106 16 72 20 65 103 59 47 119 113 89 115 108 102 107 61 22 111 53 76 55 11 49 67 2 70 19 30 38 26 96 86 23 93 54 80 57 66 85 114 46 98 83 128 24 101 117 95 100 127 51 109 69 104 122 35 112 52 12 126 129 44 25 116 74 9 28 27 120 42 132 50 5 37 94 3 91 130 110 90 58 34 68 36 78 7 123 73 32 29 60 41 10343 bers from 1 to InI InI lt 1995 The 4737 junc 8555 tionswere independently named by integer numbers from 0 18 15 2 18 9 11 3 5 1 6 17 13 16 4 8 12 10 7 14 27628 1 0 79 8 6 10 5 9 17 18 49 38 13 57 22 65 56 61 31 34 52 74 25 19 44 55 24 26 2 20 32 39 15 60 40 78 69 59 37 33 76 16 30 58 50 41 45 12 4 64 11 48 43 36 47 75 29 79 3 63 35 66 51 71 73 72 46 68 42 54 21 7 70 27 28 62 53 14 1 23 77 67 11253 to ImI ImI lt 44 No junction connects more than 44str 9094 eets All junctions in the town had different nu 0 187 110 14 168 141 17 59 90 134 20 66 102 136 82 142 170 107 123 164 43 62 52 169 185 106 2 163 76 29 57 180 63 60 56 71 47 114 187 111 100 74 137 93 151 85 73 64 120 61 72 121 149 127 186 6 1 177 48 15 88 42 27 183 19 144 50 159 86 138 153 131 133 154 75 158 157 105 98 155 67 109 28 49 13 161 143 122 119 184 182 125 150 140 173 176 55 167 160 87 95 65 118 21 113 54 26 124 31 58 7 175 156 37 126 79 97 44 165 5 30 166 147 92 24 18 128 40 171 91 89 53 96 99 115 84 11 146 16 34 39 41 68 148 139 162 81 135 117 23 181 116 145 83 22 132 80 35 38 129 94 112 9 179 25 32 78 3 103 104 36 152 101 174 172 33 51 45 46 70 4 69 130 178 12 108 77 8 10 11535 mbers Each street was connecting exactly two junctionsNo two streets in the town had the same 0 13 7 3 4 1 12 8 11 10 5 6 2 13 9 13089 number He imm 31173 edia 0 77 12 6 47 61 52 59 15 48 38 75 9 64 28 55 21 60 29 72 46 76 67 56 22 53 69 33 3 73 45 1 14 35 37 40 4 17 25 58 62 24 26 16 70 71 18 32 8 54 49 57 68 41 23 7 39 74 30 13 43 65 50 27 2 66 77 20 11 51 31 19 44 10 5 63 36 42 34 9818 tely started to plan his round trip If therewa 0 76 2 28 48 58 33 61 70 11 63 13 40 32 20 50 38 72 9 14 69 16 53 36 30 12 35 6 45 52 19 46 34 75 25 73 39 43 15 76 47 68 10 62 31 24 74 57 49 56 1 60 54 27 44 3 65 26 64 66 22 29 51 71 23 37 4 17 18 55 67 41 42 21 7 8 5 59 9342 s more than one such round trip he wou 0 81 5 20 33 32 37 12 73 64 71 13 38 25 46 1 79 30 19 52 18 62 4 40 69 51 65 47 77 21 74 43 58 55 60 54 78 68 67 45 39 41 15 48 57 17 81 49 7 36 16 3 31 9 66 76 26 29 75 50 53 63 2 35 61 10 22 27 24 59 34 80 8 14 11 56 70 72 44 6 42 28 23 26673 ld have c 0 18 9 4 13 8 15 1 12 17 14 2 3 10 16 7 11 5 18 6 18946 hosen 25495 the one whi 0 75 8 14 6 10 33 59 38 46 1 28 15 31 18 35 42 27 68 39 57 49 50 66 3 17 32 4 65 72 64 53 71 56 54 21 58 60 44 36 74 16 51 5 67 9 37 69 23 48 75 52 2 55 29 7 26 43 63 34 40 41 30 20 73 70 11 61 62 25 13 45 24 19 12 47 22 31818 ch when written down as a sequenceof street numbers is 7772 lexicographically the smallest Bu 0 17 12 1 3 6 7 16 10 14 13 4 8 15 17 11 9 5 2 11779 t Johnny was no 5823 t able to 0 145 66 122 63 83 25 95 49 79 36 26 56 138 15 41 105 55 141 19 9 54 67 139 131 144 3 86 11 117 129 43 143 20 50 134 52 92 145 35 126 33 62 87 94 5 96 45 14 81 39 75 53 58 2 31 37 28 40 1 88 29 89 74 21 18 34 142 135 65 44 127 64 113 69 93 130 99 71 101 84 22 27 91 59 108 128 80 112 76 6 16 114 110 48 82 13 106 85 132 118 30 72 57 47 121 109 102 17 98 78 32 10 77 97 125 8 115 123 4 124 12 111 70 103 120 61 73 23 133 137 24 51 90 119 100 104 107 60 7 116 42 136 46 68 38 140 4038 find even one such roundtripPHelp Johnny and write a program which finds 25965 the desired s 0 12 1 2 6 5 7 12 3 8 10 9 11 4 27662 hortest roun 24769 d t 0 31 19 2 9 5 7 22 14 15 18 4 21 3 17 6 8 28 12 23 20 11 27 1 26 29 16 13 25 24 30 31 10 23500 rip If the round trip 0 31 27 21 25 19 7 10 8 5 13 31 4 26 15 11 20 17 1 6 3 22 24 30 2 23 16 29 14 12 18 28 9 5986 doesnot exist the program s 317 hould write a 0 40 2 12 1 28 25 30 37 27 8 22 38 16 7 31 40 10 5 35 3 34 4 21 11 9 26 17 32 19 39 36 23 33 13 20 6 24 15 18 29 14 3514 message Assume that Johnny liv 6396 es at the junction ending 0 39 6 18 31 22 21 11 14 25 17 19 35 23 36 39 37 20 9 10 32 28 4 12 5 8 26 29 33 2 24 7 34 38 16 15 30 13 3 27 1 14472 the streetNo 1 with smaller num 20354 ber All streets in the town are 16319 two way There exists a way from each 0 12 4 1 7 12 8 6 9 2 5 11 10 3 3962 street toan 29913 o 0 200 36 149 44 138 107 124 25 24 119 71 106 159 18 27 117 109 171 38 94 185 199 196 4 133 21 112 19 70 158 32 195 191 39 46 139 128 163 35 8 43 144 66 181 192 182 73 9 1 80 153 99 42 127 122 96 101 132 83 97 121 197 15 82 173 58 118 29 77 160 116 26 165 33 154 37 145 177 175 81 5 63 131 143 156 104 60 150 198 136 40 84 142 12 146 190 87 151 59 130 110 200 2 79 174 100 41 3 74 49 111 123 55 137 184 51 28 168 88 167 13 48 56 129 11 155 6 152 188 14 72 22 95 103 105 10 85 47 89 65 54 148 64 92 166 162 186 176 170 93 120 57 180 141 78 30 114 193 179 61 67 115 31 102 113 125 68 17 108 178 76 45 91 164 140 172 69 98 53 157 161 189 50 90 62 135 169 86 187 147 134 7 34 183 194 52 20 75 126 23 16 10570 ther street i 19410 n the town The streets in the town are very narrow and the 0 182 182 126 169 2 11 172 43 17 18 70 7 29 59 158 92 104 60 55 101 107 96 58 153 67 151 16 133 130 83 12 87 97 28 45 32 65 84 57 22 69 64 53 24 114 150 88 128 115 9 35 85 173 139 34 74 26 156 120 61 4 135 155 40 15 103 117 111 125 37 27 132 86 138 145 109 80 33 90 118 165 14 94 78 148 89 136 72 160 123 62 48 3 168 119 121 178 112 100 6 181 137 1 108 122 23 110 73 66 164 79 49 167 179 10 99 129 25 76 149 171 44 52 147 81 71 30 50 140 56 176 51 154 8 91 134 105 166 98 42 93 77 142 152 157 162 102 82 13 141 31 124 39 180 131 20 161 146 41 5 170 174 175 177 47 75 36 68 127 38 19 63 159 106 113 163 116 143 21 95 144 46 54 13595 re is no possibility to turn backthe car once he is in the streetH3InputH3 0 130 76 19 55 118 119 13 80 23 33 52 29 22 86 123 81 51 120 41 2 37 46 16 26 57 40 116 121 99 70 110 71 58 89 39 54 126 66 101 106 73 30 67 91 88 103 27 7 128 104 63 78 69 85 72 109 90 44 45 32 61 14 11 94 48 75 38 5 8 79 1 9 18 15 10 17 6 117 25 21 92 98 93 87 105 31 108 53 65 64 34 74 96 125 122 95 62 56 129 77 83 49 113 111 28 107 97 112 43 36 35 115 20 82 130 124 102 127 24 42 84 12 68 59 114 4 100 50 60 47 3 25763 Input file consists of several blocks Each block describes one town Each line in the block 24111 containsthree integers I 0 26 22 1 13 9 21 14 3 23 16 7 20 15 24 12 6 2 26 17 10 25 8 4 18 5 11 19 14272 xI IyI IzI where IxI g 10964 t 0 126 32 47 60 68 23 19 114 96 90 69 54 53 3 43 104 11 4 28 62 36 97 123 12 27 30 39 15 2 94 75 80 44 98 42 38 64 18 20 41 89 29 72 63 105 48 76 119 17 88 57 9 49 102 86 16 7 124 31 77 82 59 46 92 8 101 55 74 5 52 103 110 109 73 125 111 56 91 25 10 108 100 26 66 85 115 120 70 40 112 24 61 116 37 117 118 33 79 106 34 95 67 71 65 78 1 87 13 84 21 6 121 58 113 99 83 126 122 22 50 93 107 14 35 51 81 45 18583 0 and IyI gt 0 are the numbers 0 59 14 26 25 42 28 18 37 48 54 47 15 38 41 30 59 11 23 16 33 24 12 43 52 17 13 20 27 49 39 46 44 4 1 10 56 45 3 32 50 19 6 40 51 35 53 55 58 34 21 36 7 29 22 8 2 5 57 31 9 30275 of junctions 5408 which are connected by the streetnumber IzI T 0 38 27 18 7 35 3 33 10 19 9 5 11 28 6 13 23 14 16 2 1 8 25 37 29 15 34 4 17 30 31 26 24 21 20 38 36 32 22 12 30688 he end of t 0 18 5 16 15 11 6 18 8 7 10 3 1 13 14 9 12 17 4 2 11365 he 12642 block is marked by 0 185 7 65 55 164 112 3 48 75 78 168 89 170 81 58 27 140 74 72 45 175 145 90 184 85 162 105 158 142 43 93 114 122 14 33 180 11 118 63 147 29 94 71 97 92 8 121 141 95 110 44 130 34 46 176 69 131 66 116 148 152 62 61 166 144 126 77 120 91 125 86 76 21 119 181 6 20 151 59 161 42 31 129 15 167 138 160 113 185 36 83 102 1 172 182 79 159 40 64 100 57 123 132 137 155 73 108 154 87 179 28 32 117 146 10 47 60 82 134 17 54 41 165 88 2 96 56 53 136 50 26 156 139 67 174 153 4 35 37 171 106 99 84 80 135 115 107 23 150 183 9 13 109 169 38 39 143 24 19 101 177 111 163 103 157 104 22 178 70 5 51 18 124 49 98 12 52 25 16 149 127 30 133 128 68 173 9470 the line containing IxI IyI 0 At the end of the input filethere is an empty 0 160 37 38 39 122 65 103 50 99 13 95 30 93 67 68 115 36 70 114 78 146 119 86 32 63 35 3 98 45 112 107 84 94 20 89 128 31 1 14 74 72 12 148 71 108 54 49 69 61 156 7 157 134 5 138 87 144 29 82 17 132 141 124 22 4 147 55 116 19 41 153 10 80 143 18 81 8 85 88 59 27 150 142 159 121 133 135 101 43 79 60 111 160 56 158 131 2 6 140 102 97 96 28 145 52 110 154 77 16 9 152 123 51 120 40 47 21 127 136 26 23 44 73 149 105 100 91 57 106 34 139 92 113 53 64 155 75 24 118 42 25 76 125 130 137 48 117 66 90 62 11 129 33 151 58 126 46 109 15 83 104 31262 block IxI IyI 0H3OutputH3The output file consists of 2 line blocks corresponding to the blocks of the input fil 30459 e The first 0 92 34 8 58 83 12 15 80 79 55 29 71 53 68 82 14 89 3 49 51 70 23 50 9 76 33 26 46 73 38 19 52 87 4 75 30 48 67 56 45 27 1 65 36 32 40 86 77 61 2 16 37 59 42 35 24 60 13 69 41 74 66 54 72 28 43 44 31 5 85 90 10 7 62 84 11 17 92 18 63 47 20 25 91 22 88 78 81 39 6 64 21 57 29303 line ofeach block contains the sequence of street numbers single members o 0 120 115 51 67 56 9 42 59 85 33 11 44 15 24 31 41 111 109 52 14 60 55 34 1 5 74 48 49 63 29 61 18 6 16 43 108 89 97 104 25 79 112 84 66 3 77 90 35 72 17 117 4 70 21 62 114 80 88 28 12 20 53 98 86 26 73 2 118 19 13 37 64 27 38 39 116 81 22 65 110 75 107 40 120 96 69 91 71 99 87 105 76 113 103 7 45 93 106 100 78 83 30 36 119 82 94 54 46 8 95 50 58 57 23 92 68 10 101 47 102 32 19592 f the sequence are separated by spacedescr 3914 ibing Johnnys round trip If the roun 0 134 83 99 53 71 75 38 5 48 56 106 4 124 36 79 119 16 116 88 30 111 32 92 69 120 80 62 34 112 20 113 7 115 132 76 96 3 37 126 74 109 31 66 123 49 85 58 84 64 128 44 55 87 40 42 43 110 28 63 70 9 2 50 57 11 10 81 17 59 133 108 12 103 8 21 78 18 105 29 68 47 89 14 46 1 26 22 118 6 91 27 104 45 100 41 102 33 127 60 107 101 67 86 73 61 114 35 122 121 23 129 94 82 52 54 117 98 95 131 93 130 134 125 13 90 77 97 39 25 19 24 65 51 72 15 5793 d trip cannot be found the corresponding output block containsthe message ttRou 12918 nd trip does not existtt The second line of each block is emptyH3ExampleH3BInput f 0 178 119 66 22 53 3 105 160 103 20 84 75 134 81 137 56 36 125 26 15 21 112 155 33 42 172 113 159 8 78 178 57 16 24 58 156 48 11 25 157 120 34 109 168 175 19 4 13 111 139 83 7 108 167 138 86 38 142 6 49 65 118 100 132 173 30 150 2 169 101 61 161 44 110 85 51 10 133 146 96 148 121 18 9 176 89 72 151 71 145 117 73 28 177 43 55 114 5 17 130 70 126 116 29 147 46 50 123 144 27 106 40 80 97 129 163 98 88 115 35 77 23 104 165 122 162 1 95 32 136 62 79 52 64 171 154 152 63 93 87 54 140 135 92 170 99 153 102 164 82 76 68 107 59 14 174 124 37 94 149 91 128 60 166 131 127 90 67 41 141 47 143 74 39 69 158 45 31 12 9701 ileBPRE1 2 12 3 23 1 61 2 52 3 33 1 40 01 2 12 3 21 3 32 4 40 00 0PREBOutput fileBPRE1 2 3 5 4 6 Round trip does not existPREBODYHTML 17699 HTMLHEADTITLECERC 1995 12421 Problem D PipeTITLEHTML version generated by Kotas Koucky 1998HEADBODYH2 ALIGNCENTERACM International Collegiate Pr 0 158 85 29 39 6 78 158 154 28 59 136 14 120 34 33 149 118 13 153 30 134 156 57 47 90 46 9 152 20 66 80 151 112 26 40 84 124 41 11 67 72 68 88 99 92 31 64 62 8 21 77 96 129 119 24 110 111 141 44 91 108 82 95 58 81 12 107 45 86 1 157 102 103 140 128 60 123 15 76 7 43 50 93 104 150 53 131 49 3 100 32 133 37 127 16 98 144 145 22 116 135 106 36 35 125 61 109 55 17 122 71 117 74 65 115 130 63 97 52 18 19 27 69 94 25 42 75 132 137 79 148 101 10 51 4 138 89 139 114 83 73 146 87 143 121 105 54 142 155 56 70 126 2 5 147 48 38 113 23 8429 ogramming Contest 9596H2P A 6633 LIGNCENTERBSponsored by MicrosoftBH3 ALIGNCENTERCentral European Regional ContestH3 0 129 127 12 52 68 28 97 42 65 104 17 125 21 116 83 33 55 86 59 91 18 89 126 84 90 93 51 30 129 57 47 87 109 32 81 62 44 37 69 13 41 29 64 67 78 77 115 76 3 54 34 72 56 15 99 27 8 1 5 92 70 35 110 22 82 113 108 114 117 102 11 112 31 79 118 43 63 80 95 48 120 98 40 38 10 100 94 75 45 36 66 106 96 46 74 60 53 85 14 101 16 111 103 123 73 50 121 4 7 107 19 61 26 24 23 20 119 9 2 49 122 25 39 124 128 105 58 88 6 71 25109 BRH2 ALIGNCENTERProblem D PipeH2P ALIGNCENTERBInput fileB ttpipeinttBRBOutput fileB ttpipeoutttBRBProgram fileB ttpipepastt 16734 or ttpipecpptt 28470 PThe GX Light Pipeline Company started to prepare ben 0 74 22 3 35 24 1 40 7 23 31 67 68 21 66 47 51 10 27 73 48 58 28 74 71 26 30 54 18 46 65 13 4 2 5 42 15 38 9 16 17 70 52 36 25 20 39 50 55 33 37 49 72 60 53 59 62 63 8 12 41 14 44 34 56 29 11 64 43 6 19 69 57 32 45 61 4582 t pipes f 9534 or the new transgalactic light pip 0 39 6 28 7 16 36 31 15 21 11 23 22 8 19 26 17 10 20 3 5 4 37 27 38 34 1 14 24 2 32 18 9 39 35 13 29 33 12 25 30 9632 eline 0 144 24 15 98 94 12 8 30 52 17 73 43 34 4 142 134 66 20 33 42 72 11 26 5 144 36 55 91 81 96 71 78 61 50 32 108 28 7 10 40 35 101 85 60 103 48 121 86 53 93 115 64 97 75 68 128 87 76 25 74 107 111 69 62 2 140 88 70 18 3 114 56 139 138 13 82 41 105 79 104 102 29 119 6 59 124 21 22 127 132 90 83 37 9 19 63 38 58 1 130 106 84 116 92 57 77 126 16 100 112 51 27 117 141 129 137 120 135 47 113 46 49 133 131 143 122 99 67 14 45 65 123 80 125 118 23 136 110 95 44 54 89 109 31 39 11107 During the design phase of the new pipe shape the company ran into the problem of determining how farthe li 27317 ght can reach inside each component of 4085 the pipe Note that the material which the pipe is made fromis not trans 0 16 15 4 13 11 1 10 14 8 6 12 2 9 7 16 3 5 16842 pare 28718 nt a 0 166 101 5 153 90 134 12 85 112 117 18 52 133 86 122 151 165 13 127 162 79 125 72 77 74 28 65 34 92 98 95 26 141 41 143 40 78 126 57 69 1 17 161 121 23 128 93 138 145 2 124 130 62 152 64 67 157 36 16 119 80 106 105 37 31 63 66 43 32 163 51 70 146 84 150 55 3 140 47 147 91 104 89 20 8 15 49 120 61 160 118 48 102 14 116 155 149 158 39 19 108 139 96 82 144 76 164 73 30 115 129 75 27 60 24 107 42 4 10 54 35 22 156 38 58 46 50 81 7 136 135 11 99 21 59 113 56 154 110 100 9 44 94 159 25 33 71 148 53 123 88 68 166 109 111 132 137 83 142 6 114 103 29 97 87 45 131 23397 nd not light reflectingP ALIGNCE 0 104 70 3 6 55 1 26 77 19 40 53 61 39 72 79 65 84 23 37 13 29 45 49 52 15 68 75 82 36 12 46 11 5 47 28 27 62 96 10 30 67 78 42 74 59 80 38 86 56 32 76 69 25 64 81 16 92 95 8 87 35 93 85 90 97 9 50 21 99 94 20 31 60 14 44 2 41 71 63 34 57 88 91 98 18 54 4 51 89 100 17 24 102 104 83 22 103 33 101 43 58 73 66 48 7 30631 NTERIMG 0 57 25 5 12 36 42 56 47 39 17 24 10 9 51 34 48 8 38 13 30 44 31 57 26 7 28 37 1 3 29 46 33 40 6 50 4 55 2 20 52 22 23 27 16 11 32 53 49 15 19 45 35 41 54 18 14 43 21 19661 SRCpipegifPEach 9881 pipe com 0 187 77 28 114 29 183 75 3 80 4 149 90 72 160 147 78 54 10 8 130 117 60 37 148 76 66 88 64 180 106 61 105 13 99 91 101 63 47 33 172 20 124 86 152 116 179 109 6 97 25 128 120 95 113 185 125 68 108 176 19 87 5 162 107 42 22 144 151 154 139 82 103 21 46 177 40 89 50 7 184 38 122 52 121 23 83 110 118 11 140 164 123 56 135 93 32 69 43 1 45 102 57 34 17 150 131 133 142 98 132 15 30 186 181 44 138 126 26 159 157 2 94 39 170 145 65 173 112 161 51 136 24 59 166 12 67 55 156 18 174 163 41 31 48 73 134 158 81 92 171 85 96 71 111 53 119 74 9 79 178 182 16 137 49 141 115 155 165 35 100 104 70 129 14 58 143 146 187 153 62 27 175 127 36 167 84 169 168 30728 ponent consists of many straight pipes connected tightly together For the program 9741 mingpurposes the company developed the description of each c 0 2 2 1 25950 om 30127 p 25457 on 0 191 100 154 46 86 145 97 108 167 178 164 111 176 70 153 138 25 169 24 187 151 162 4 146 114 8 29 39 144 48 27 73 168 148 147 87 81 67 40 139 124 30 186 105 121 47 132 94 103 84 43 49 37 118 106 96 33 17 14 1 38 128 122 182 101 98 80 50 109 160 149 131 42 133 143 102 104 113 13 152 2 93 110 82 32 174 56 7 19 123 127 72 184 172 116 115 92 107 51 52 130 190 20 31 21 69 71 166 95 181 175 60 189 89 9 57 173 16 125 170 75 41 55 88 91 77 58 177 159 5 3 136 163 126 78 61 158 85 68 28 179 171 155 59 134 65 137 10 161 76 180 66 45 26 54 63 112 119 23 74 165 156 79 22 191 188 120 83 99 12 185 135 64 53 62 36 34 18 157 117 6 44 141 140 142 11 183 90 15 129 35 150 9958 ent as a sequence of points IxI1 IyI1 IxI2 IyI2 IxnI IynI where IxI1 lt IxI2 lt IxnI These are the upper points of 17848 the pipe contour The bottom pointsof the pipe contour consist of points with IyIcoordinate decreased by 1 To each upper point 17073 IxiI IyiI thereis a corresponding bottom point IxiI IyiI1 see picture above The company want 0 30 28 3 2 10 22 20 19 11 14 15 8 17 6 1 4 26 13 25 21 29 23 30 24 18 12 16 5 9 27 7 24451 s to find for 19211 each pipe component the 2357 point with 0 159 92 78 121 106 82 46 118 98 50 2 136 57 66 125 143 54 41 48 146 93 77 52 8 119 22 114 63 110 151 14 33 132 45 89 18 49 84 25 79 15 9 140 111 70 144 145 80 156 13 152 51 154 134 102 137 108 44 149 116 3 67 113 147 135 138 35 122 117 43 28 36 83 71 65 86 7 75 64 129 11 4 139 95 76 126 73 19 40 141 31 120 94 104 97 155 72 142 60 62 30 59 109 90 69 24 158 123 127 55 38 150 124 100 42 53 26 153 29 16 61 133 99 157 17 5 115 148 101 34 20 130 37 21 1 10 87 112 68 74 96 107 32 128 81 159 27 23 131 103 85 47 91 58 39 56 12 6 105 88 8806 maximal IxIcoordin 29556 ate that the light will reach The light is emitted by a 458 segment source with endpoints IxI1 IyI11 and IxI1 IyI1 endpoints are emitting light 0 85 52 13 19 71 24 36 39 40 81 61 35 17 63 68 31 82 5 2 26 11 14 34 78 7 59 62 56 4 22 60 27 70 33 30 29 64 83 51 84 46 49 1 37 79 25 18 76 65 21 72 53 77 15 54 38 69 12 42 45 41 67 3 8 85 44 9 58 48 23 28 66 6 16 43 80 47 32 74 75 55 57 20 73 10 50 11541 too Assume that the light is not 0 27 23 9 19 20 8 15 16 1 27 26 5 25 17 18 2 7 24 21 22 6 14 10 3 4 11 13 12 27929 be 6045 nt 0 71 5 7 25 69 59 38 35 29 3 19 68 63 36 46 52 48 20 51 10 56 47 61 27 32 67 43 9 66 21 65 31 57 11 45 30 12 13 53 33 71 26 58 64 54 1 22 4 34 49 37 60 40 18 39 62 15 16 50 6 8 24 23 14 55 44 28 42 17 41 2 70 19402 at the pipe bent points and the bent points do no 25165 t stop the light 0 112 37 81 49 15 111 10 95 79 51 63 36 47 20 84 29 85 35 53 94 34 5 56 38 80 21 45 40 96 88 54 101 13 74 70 48 52 77 33 66 92 104 43 57 60 83 100 71 86 30 55 62 82 67 89 17 4 26 25 22 9 39 11 103 90 14 27 19 75 1 72 6 44 64 58 59 78 7 42 2 50 18 65 108 23 105 8 69 16 46 41 28 102 97 107 87 31 12 32 109 3 99 76 110 93 61 91 98 112 24 73 68 106 23219 beamH3InputH3The input file contains several blocks each describing one pipe component Each block star 8114 ts with thenumber of ben 21506 t points 0 178 149 79 151 34 75 178 168 6 38 95 23 166 50 14 123 28 92 87 26 114 67 65 57 112 70 104 105 157 108 83 54 102 111 47 163 40 147 59 66 69 80 120 126 16 118 43 174 138 29 41 113 150 110 128 68 171 129 58 98 22 148 145 99 7 170 144 21 162 89 177 176 44 31 18 125 71 19 82 72 154 5 56 121 91 172 8 30 12 119 156 152 45 158 107 140 101 84 94 13 48 142 97 93 3 76 167 175 86 1 63 74 160 15 27 77 143 81 25 127 53 60 136 35 24 33 164 88 10 46 159 117 135 20 42 122 115 134 103 85 39 62 64 78 52 173 130 11 146 132 90 116 61 137 165 55 4 124 169 2 106 155 141 49 36 96 73 161 17 153 32 37 131 51 9 100 133 139 109 13761 2 lt InI lt 20 on separate line Each of the next InI lines contains a pair of real valuesIxiI IyiI separated 1305 by space The last block is denoted with InI 0H3OutputH3The output fil 25188 e contains lines corresponding to blocks in input file To each block in the input file thereis one line in the output file Each such line contains either a real value written 0 178 18 99 166 10 80 45 85 163 77 136 37 4 22 64 122 55 51 93 43 2 84 6 102 142 153 28 106 89 20 167 107 109 5 41 15 23 14 16 82 11 132 59 54 145 73 12 57 24 129 21 90 19 79 88 74 56 50 103 1 172 81 91 98 68 104 63 61 169 38 8 101 112 105 100 34 36 135 33 86 87 140 177 168 13 94 159 42 147 49 130 111 3 31 143 154 121 95 171 69 35 151 27 25 178 161 47 127 118 152 150 29 119 124 170 139 40 92 108 115 53 176 62 39 173 146 144 157 46 165 110 114 44 70 158 162 75 164 120 117 155 128 30 126 141 65 32 138 97 160 134 148 67 9 26 7 133 96 113 125 78 48 66 156 137 174 116 71 123 149 72 58 131 60 17 175 76 83 52 19495 with precision of two decimalplaces or the message ttThrough a 4784 ll the pipett The real value is the desired maximal IxIcoordinate of thepoint where the light can reach from the source for corresponding pipe component If this value equals toIx 0 5 3 1 5 4 2 28786 nI th 0 118 35 79 74 71 112 21 110 66 16 12 50 38 43 45 47 6 94 13 86 82 77 63 14 46 11 42 99 41 72 85 23 9 105 68 67 83 8 36 61 25 62 51 56 88 96 58 55 107 97 89 118 108 90 84 73 78 18 2 29 22 49 116 101 20 80 33 31 53 69 113 92 4 57 75 44 37 10 65 30 5 93 59 87 39 1 95 103 81 27 100 104 32 15 106 76 111 19 7 28 26 98 40 91 34 24 117 60 102 115 114 48 54 70 109 3 17 52 64 14915 en the message tt 24470 Through all the p 17161 ipett will ap 0 175 18 38 45 14 88 171 153 62 124 43 131 9 49 89 137 114 33 26 78 92 125 145 37 87 173 28 102 159 10 115 155 94 77 109 133 6 140 51 149 154 31 76 116 163 98 17 139 82 57 55 150 158 68 3 32 25 111 146 65 24 20 112 172 2 8 107 39 96 74 138 73 53 70 46 170 122 123 103 30 152 86 58 129 60 27 142 128 41 167 104 66 132 50 148 67 121 1 69 99 84 36 91 22 130 93 80 105 5 118 169 47 61 71 23 12 79 21 44 34 134 168 174 141 48 151 35 120 81 11 85 143 135 72 175 16 90 54 157 127 13 160 95 29 7 126 52 156 100 15 113 19 75 117 165 144 63 97 147 108 106 40 83 162 42 136 4 59 166 161 164 110 56 101 119 64 15149 pear in the output fileH3ExampleH3BInput fileBPRE40 12 24 16 460 12 065 4457 55712 10817 16550PREBOutput fileBPRE467Thro 0 109 61 1 83 40 38 104 3 108 9 28 55 48 60 35 11 68 98 107 66 12 49 86 44 45 27 23 75 74 57 64 31 18 15 37 52 59 79 56 36 14 5 33 91 4 82 47 96 39 103 2 16 25 22 95 109 101 41 65 89 77 53 7 51 6 73 17 80 63 71 78 84 81 105 19 42 26 46 97 67 92 90 30 29 62 102 87 20 100 106 10 76 94 85 88 24 99 13 50 58 21 70 72 34 43 32 69 54 8 93 4333 ugh all the pipePREBODYHTMLHTMLHEADTITLECERC 1995 Problem E DepartmentT 749 ITLEHTML version generated by Kotas 14442 Koucky 1998HEADBODYH2 ALIGNCENTERACM International Collegiate Programming Contest 9596H2P ALIGNCENTERBSpon 0 76 25 34 12 28 72 20 69 36 63 42 1 30 6 22 4 5 68 35 29 16 9 54 47 8 40 76 41 75 37 62 64 43 17 39 52 10 57 32 61 11 24 3 15 33 50 45 21 70 60 48 66 59 23 55 26 65 74 19 27 51 46 44 53 13 31 73 18 38 49 56 58 7 67 71 14 2 15248 sored by 0 167 81 23 160 55 57 91 47 78 132 120 156 58 88 27 36 34 68 127 116 6 100 153 7 75 147 65 115 87 93 129 83 150 134 14 22 38 143 84 30 99 135 50 110 140 3 137 39 26 61 53 98 105 86 60 73 155 111 144 103 9 145 79 56 128 158 96 71 43 76 69 113 97 5 25 123 37 121 17 1 167 92 108 152 20 107 21 164 122 165 32 33 130 13 54 72 163 18 74 146 52 94 157 4 66 51 109 133 124 141 142 85 159 162 117 90 46 29 112 104 24 19 119 82 166 70 125 131 126 67 35 45 136 16 101 44 95 48 151 2 42 49 89 114 40 63 10 59 64 28 15 11 106 118 31 102 138 154 62 41 80 149 8 77 12 148 139 161 12462 MicrosoftBH3 ALIGNCENTERCentral European Regional ContestH3BRH2 ALIGNCENTERProblem E DepartmentH2P ALIGNCENTERBInput fileB ttdeptinttBRBOutput fileB ttdeptoutttBR 0 43 40 24 23 33 19 26 11 35 2 36 27 39 16 3 18 37 1 20 13 25 9 31 34 30 7 41 14 10 43 15 5 4 6 8 17 38 21 42 32 29 28 12 22 1373 BProgram fileB ttdeptpast 13002 t or ttdeptcppttPThe Department of Security 0 118 47 84 45 38 97 39 26 2 37 78 25 88 118 6 13 42 30 35 70 96 71 36 101 62 60 69 31 80 7 113 9 86 106 115 51 54 63 98 57 23 110 56 91 109 64 32 11 8 5 40 21 82 43 22 79 3 105 34 102 94 85 4 100 93 72 65 112 73 52 99 17 15 58 12 89 19 87 28 18 111 49 14 61 50 81 46 104 92 77 75 83 66 27 24 44 48 107 10 74 16 117 95 55 41 53 114 67 76 20 90 68 108 29 116 1 103 59 33 17643 has a new headquarters building The building has several f 5379 loors and oneach floor there are rooms numbered IxxyyI where IyyI stands for the room number and IxxI for the fl 0 146 84 138 15 25 55 16 34 52 42 121 74 107 5 116 11 40 10 132 67 28 54 93 49 63 36 4 68 88 128 58 98 115 119 82 139 20 77 79 89 91 48 73 101 1 31 126 32 145 47 22 75 103 99 56 137 9 111 72 45 108 122 2 76 39 41 131 113 62 38 71 26 112 83 27 142 97 100 53 44 8 7 123 102 64 118 146 29 130 109 37 127 125 59 140 87 70 106 133 94 78 14 17 6 129 23 135 134 105 81 69 104 65 60 30 18 21 141 95 19 143 51 144 90 24 120 110 86 43 114 12 57 35 66 92 46 61 124 80 50 117 33 13 85 3 136 96 20452 oor number0 lt IxxI IyyI lt 10 The building has paternoster elevator ie elevato 0 89 44 46 82 35 42 33 30 73 61 23 25 88 48 43 12 68 59 60 86 29 26 4 11 49 7 21 63 20 79 32 52 13 57 65 19 58 70 69 10 76 9 54 45 28 50 5 67 66 1 62 18 34 17 27 51 41 64 47 75 16 55 56 2 6 87 81 71 89 85 72 24 3 77 8 78 31 40 80 74 38 37 53 36 14 83 15 84 39 22 16527 r build up from several cabins runningall around From time to time the age 1674 nts must visit the headquarters During their visit they 21986 want to visitseveral rooms and in eac 0 76 56 11 41 67 9 52 73 13 46 29 48 31 23 25 32 64 8 63 43 34 19 15 36 47 57 3 12 27 70 51 71 37 76 59 75 7 69 21 44 53 38 60 16 61 6 18 4 28 54 10 24 72 58 14 45 1 22 55 33 30 35 2 26 50 49 62 17 74 42 39 65 5 66 68 20 40 26425 h room they want to stay for some time Due to the security reas 0 48 30 19 17 48 21 43 35 24 40 18 31 34 36 46 29 2 22 23 10 27 28 16 8 9 6 7 47 5 14 38 15 42 13 41 25 3 11 26 32 12 1 37 45 39 44 33 4 20 27579 ons there can beonly one agent in the sam 19489 e room at the same time The same rule applies t 0 127 39 21 18 91 20 11 126 57 76 77 32 15 35 61 51 97 41 116 66 16 12 9 87 25 99 101 62 95 60 121 45 49 59 63 104 42 118 50 68 79 122 71 47 127 65 75 108 78 67 89 54 84 2 102 36 92 44 93 30 106 124 80 34 100 33 88 52 70 96 86 74 14 13 23 112 105 29 24 90 69 55 85 31 10 22 56 117 17 6 48 8 53 27 40 73 110 37 26 103 72 94 4 125 38 114 119 83 3 120 64 98 81 113 19 82 123 107 28 1 111 5 43 109 115 7 58 46 14060 o the elevators The visits areplanned in the way ensuring they can be accomplished within one day 7647 Each agent visit 0 138 52 87 1 28 68 39 64 20 2 123 81 107 12 72 80 137 132 3 125 76 7 91 33 89 66 109 10 94 113 100 56 115 45 84 5 92 61 27 19 62 35 9 43 18 102 85 67 77 38 16 112 126 134 69 50 83 65 73 49 120 31 88 71 14 13 23 59 58 101 32 78 97 111 82 11 25 17 30 54 46 128 106 40 57 122 21 75 129 104 15 96 22 41 118 108 105 119 48 47 63 42 127 114 110 133 90 116 36 79 131 26 37 95 24 98 55 34 4 124 130 53 51 93 136 99 103 135 6 121 70 117 8 60 44 29 74 86 138 9393 s the headquartersat most once a daypEach agent enters the building 0 149 14 81 108 32 65 31 90 110 70 103 105 59 28 133 38 143 1 145 63 43 23 118 132 124 5 95 99 142 135 34 87 56 77 84 92 120 136 89 35 15 114 51 36 129 91 16 148 58 125 3 39 20 29 117 8 112 7 25 30 52 74 45 22 116 21 126 10 140 78 6 141 33 137 54 17 72 18 75 128 41 79 130 24 67 123 97 107 66 46 57 60 131 64 139 12 122 83 149 80 62 71 106 44 113 53 27 13 86 55 2 115 73 42 101 147 134 88 19 109 94 119 121 76 49 68 98 40 144 85 96 146 104 69 82 61 93 127 100 48 37 50 47 26 11 102 9 4 138 111 5627 at the 1st floor passes the reception and then starts to visit the roomsaccording to hisher list Agents always visit the rooms by the increa 22319 sing room numbers The agents forma linear hierar 0 15 15 4 12 3 8 9 1 6 10 2 13 14 7 5 11 25336 chy a 0 14 1 11 7 14 10 2 9 6 5 12 13 3 4 8 8122 ccording to w 3124 hich 11964 they hav 0 53 7 24 18 9 38 1 30 12 27 15 46 10 49 16 39 50 6 29 17 35 45 20 22 48 13 25 52 28 32 53 33 19 4 47 37 36 44 21 23 14 42 43 51 26 2 11 34 31 41 3 8 40 5 2244 e assig 0 178 109 20 63 133 69 84 8 174 107 117 57 61 10 25 168 140 112 148 155 159 146 29 130 24 39 35 45 71 106 77 96 62 30 93 114 1 151 110 2 68 51 92 89 53 49 162 166 76 65 42 152 70 157 125 163 103 11 79 116 75 147 141 55 81 135 88 87 91 18 5 48 73 154 36 15 175 126 46 3 160 44 32 136 144 28 12 17 101 156 111 34 38 98 67 26 54 173 178 137 167 85 95 158 104 131 118 58 145 138 115 50 90 72 119 142 164 149 99 82 139 153 128 33 124 4 108 80 22 19 27 59 7 102 122 143 94 60 165 13 16 86 169 171 37 9 41 105 170 172 177 21 43 120 113 161 14 74 97 134 132 64 6 121 31 100 23 56 127 176 78 129 123 150 83 66 52 47 40 11668 ned their one l 6902 etter personal codes The agents withhigher seni 0 135 7 69 101 123 40 78 4 102 6 45 48 37 116 121 107 51 130 90 23 95 17 68 99 74 56 100 3 103 112 36 31 41 44 83 92 58 79 117 14 67 87 70 64 62 120 15 13 27 88 11 85 59 32 49 66 128 109 43 124 129 60 133 42 77 26 30 47 63 91 21 73 16 84 110 105 98 54 122 76 125 61 46 29 114 97 119 118 24 108 8 75 93 18 39 131 135 86 34 22 10 57 96 94 80 127 65 132 50 115 20 106 9 52 2 81 33 12 113 5 82 25 38 1 89 55 72 28 104 35 134 126 111 71 19 53 20531 ority have lexicographically smaller codes No two agents have the same codePIf more then one agent want to enter a room or an elevator 0 173 155 71 165 109 81 2 67 61 170 56 160 74 39 70 119 162 167 49 103 18 120 121 127 1 140 9 88 171 113 118 16 102 129 93 135 68 38 100 173 161 83 116 6 91 45 78 58 86 110 36 77 27 30 124 26 63 142 59 53 69 79 28 139 94 42 46 130 64 105 149 13 87 131 137 35 108 132 85 82 92 75 29 111 107 65 90 144 133 136 114 128 117 172 4 138 11 152 104 47 157 20 48 54 31 112 21 34 32 97 166 125 164 126 151 143 154 89 43 169 24 19 57 33 134 145 156 60 159 96 7 150 10 153 122 50 80 22 44 163 15 41 148 55 72 158 115 37 62 3 106 146 99 141 73 52 40 66 101 95 84 76 17 25 5 168 147 8 12 14 98 23 123 51 29031 the agents have to form a 2998 queue In eachqueue they always stand according to their codes The higher the senio 0 107 2 83 89 94 79 33 37 97 80 77 16 63 88 14 69 71 70 17 12 30 72 4 74 15 13 62 105 68 20 25 8 21 57 24 67 104 39 34 86 28 52 58 32 18 91 42 40 102 66 38 59 3 46 65 93 11 27 48 23 56 43 107 54 92 98 53 99 10 64 90 47 84 85 100 96 78 6 82 29 51 75 49 1 55 45 31 41 35 101 106 44 95 87 7 50 5 60 36 73 103 19 76 22 9 81 26 61 3909 rity 0 21 3 1 7 4 9 12 21 11 14 6 18 17 20 15 19 5 16 10 8 13 2 20482 of the agent the clo 0 17 10 1 2 3 13 4 9 11 12 5 6 7 8 17 16 15 14 464 ser to 0 113 40 22 107 65 46 102 21 66 29 16 94 19 93 55 7 41 91 104 59 30 23 4 11 49 35 31 68 81 32 6 112 63 42 34 108 12 14 71 86 67 39 99 53 3 74 109 101 52 37 2 24 27 103 64 26 47 56 13 106 45 111 18 83 8 5 79 78 75 54 84 97 96 100 98 17 80 85 88 10 92 15 90 113 20 82 110 48 58 9 95 57 28 105 70 36 33 25 1 51 60 43 73 62 77 89 69 61 76 87 72 44 50 38 30681 thetop of the queue he stands Every 5 s s 1755 econds the 0 22 12 5 6 4 11 9 21 15 13 2 10 16 8 17 1 22 18 19 14 7 20 3 19005 fi 29515 r 19944 st 0 36 34 11 3 5 15 21 12 33 14 22 29 9 16 25 8 28 13 20 1 26 18 19 27 30 23 4 6 17 31 10 32 2 24 36 7 35 19115 agent in the queue in 19591 front of t 0 100 37 18 46 98 73 94 71 70 12 35 13 99 60 38 28 16 8 19 83 80 57 65 43 74 84 42 10 48 7 76 75 59 15 64 45 81 33 89 82 90 68 9 51 25 88 27 31 67 77 11 95 17 78 24 55 32 39 85 3 41 53 96 14 56 5 47 66 62 52 50 54 22 21 2 100 34 30 69 29 20 97 49 6 92 4 87 86 63 91 93 44 40 1 23 36 72 26 79 61 58 15456 he elevator entersthe elevator After visiting the last 4660 room in the headquarters each agent uses if necessary elevator to thefirst floor and exits 0 180 2 67 154 14 92 147 34 49 26 32 33 132 19 75 29 81 82 171 51 139 146 36 47 160 61 64 30 66 43 16 112 72 6 17 121 89 138 71 102 172 76 110 10 114 158 123 79 42 140 125 135 115 170 119 59 52 3 15 149 111 91 84 163 159 80 93 8 78 118 100 1 60 151 113 134 86 54 116 153 65 12 117 128 142 120 63 144 96 94 31 68 38 105 168 48 108 180 46 130 39 122 97 101 53 177 109 164 88 103 85 25 40 133 107 179 7 73 28 124 35 70 55 58 143 145 157 178 50 90 131 24 5 141 57 98 23 11 62 166 20 156 95 104 175 176 99 161 162 148 167 127 45 77 56 126 37 165 69 21 44 74 173 22 106 87 41 27 152 137 83 169 150 174 9 136 18 129 155 4 13 26547 the buildingPThe times necessary to move from a c 4306 ertain point in the headquarters to another are set as followsEntering the building ie passi 3302 ng the reception and reaching the elevator or a room on the first floor takes30 s Exiting the building ie stepping out of the elev 0 125 49 20 34 99 83 54 23 29 52 110 85 118 27 111 108 17 94 114 56 8 80 16 117 33 10 37 92 6 112 7 75 87 103 28 4 79 40 42 2 3 45 15 109 14 63 36 65 13 57 91 60 55 101 105 58 76 64 106 51 81 89 24 35 102 39 77 38 61 1 78 53 25 5 50 84 41 115 43 12 107 47 72 71 22 11 98 86 90 46 93 32 74 122 95 73 68 30 82 123 88 62 119 48 116 125 9 66 59 31 121 67 26 120 69 21 124 96 18 100 113 97 70 19 104 44 4796 ator or a room on the first floor and passing thereception takes also 30 s On the same floor 31671 the transfer from the elevator to the room or to the queue infront of 0 174 34 20 19 82 136 28 24 133 94 88 51 74 150 108 132 10 119 113 123 35 115 84 83 41 49 53 109 85 174 70 18 96 78 153 128 98 57 54 142 162 164 101 141 86 145 77 79 158 72 40 103 81 65 14 117 39 75 93 55 27 107 11 42 99 76 73 126 56 118 90 143 120 173 139 1 58 111 22 69 71 105 127 59 95 149 46 138 140 62 80 152 15 110 13 169 21 102 171 114 137 45 61 129 16 32 157 106 64 60 154 44 155 3 166 7 37 130 30 87 48 168 165 2 12 67 25 29 147 131 156 121 4 6 151 9 148 91 92 104 116 50 47 63 97 8 31 5 170 167 159 43 172 33 112 26 161 23 135 124 38 36 160 122 100 89 17 144 134 125 163 52 66 146 68 4971 the room or from the room to the elevator or to the queue in front of the elevator or from oneroom to another or to the queue in 0 154 44 66 67 80 24 119 133 71 76 103 41 31 113 61 123 90 139 20 40 34 109 151 83 63 21 12 84 145 5 81 14 47 38 95 94 7 110 136 68 30 43 96 77 116 56 29 53 124 16 126 52 69 108 54 3 42 64 19 13 91 150 37 65 45 33 115 106 36 27 154 97 22 78 118 62 127 137 32 140 59 147 117 26 73 17 58 46 129 144 105 85 130 70 148 111 55 60 18 28 74 104 138 86 149 51 35 93 128 25 98 79 107 142 57 23 102 134 49 72 125 143 48 92 15 10 2 1 9 131 141 132 87 121 4 82 146 153 75 50 122 11 6 152 89 101 120 135 112 88 100 8 114 39 99 27344 front of the room takes 10 s The transfer from one floor to the nextfloor above or below in an el 3588 evator takes 30 s Write a program that determines time course of agents visitsin the head 3287 quartersH3InputH3The input file contains the descriptions of n gt 0 visits of different agents 0 171 84 17 158 98 9 145 76 169 78 64 63 39 137 70 96 87 41 97 47 19 42 53 60 160 12 115 151 149 49 72 139 8 2 55 170 130 159 119 11 89 56 5 154 143 110 54 91 71 93 134 117 99 3 127 18 59 102 52 92 148 144 29 116 167 33 105 152 21 34 85 147 113 28 95 136 6 171 65 90 32 30 73 132 58 22 142 156 122 120 75 131 51 155 7 88 68 161 4 140 82 31 125 126 165 94 61 1 164 124 27 24 79 114 106 77 104 112 166 103 162 15 26 14 101 13 109 81 83 69 138 44 133 74 20 86 80 50 163 23 57 37 150 16 157 48 135 38 123 146 118 67 153 25 128 10 129 108 100 141 43 66 121 111 40 168 36 107 45 46 62 35 15170 The first line of the descriptionof each visit consists of agents one character code ICI ICI A Z and the tim 9312 e when the agent entersthe headquarters The time is in the format HHMMSS hours minutes seconds The next lines therewill be at least one contain the room 0 40 11 3 17 13 26 8 21 38 27 34 19 16 14 5 30 29 33 23 2 36 12 9 6 28 35 18 20 15 22 10 4 31 40 25 32 24 39 37 7 1 20910 number and th 0 168 87 59 164 77 12 74 161 29 93 111 49 158 20 153 48 45 73 107 26 37 47 21 71 162 95 62 56 149 82 39 13 100 90 2 64 61 110 18 127 41 9 141 115 75 38 55 24 165 57 14 123 151 69 66 15 84 1 34 109 157 28 106 17 135 8 11 118 155 67 103 145 117 86 163 70 3 133 68 138 148 30 19 60 122 156 134 101 76 166 5 43 91 150 124 116 31 167 159 16 22 52 42 72 108 168 129 139 126 143 27 63 78 85 147 40 131 51 113 154 58 114 88 25 32 142 120 79 94 6 136 104 160 54 102 81 80 98 140 10 33 46 36 152 35 119 23 112 121 50 97 92 125 83 137 130 132 105 144 89 96 4 53 44 128 7 65 146 99 19744 e length of time in 0 54 29 33 4 54 32 21 5 30 38 13 11 15 34 43 24 10 12 51 3 6 1 31 17 36 20 44 22 47 53 7 49 27 42 14 18 35 39 46 26 50 48 16 19 9 25 40 37 28 23 8 41 45 2 52 23096 ten 23951 ded to stay in the room timeis in seconds Each 0 19 5 7 11 2 4 9 10 6 17 14 15 8 3 12 1 19 13 16 18 7814 room is in 0 143 16 107 23 42 37 34 17 86 113 44 119 57 127 110 12 30 28 79 55 142 138 50 135 33 48 1 5 27 95 6 99 83 64 47 124 59 19 41 51 94 43 116 87 70 9 131 54 40 66 91 36 15 11 21 82 73 136 13 93 2 76 78 32 104 90 105 46 137 140 129 114 74 97 109 26 8 49 69 29 85 68 126 106 84 115 81 77 89 92 133 102 72 53 63 98 118 121 134 38 128 80 60 143 31 123 100 39 75 120 132 22 139 67 18 20 7 3 4 56 10 24 65 35 88 96 25 112 101 45 111 125 122 58 103 108 117 130 141 61 71 14 62 52 29624 a 0 117 24 93 72 44 7 59 71 47 102 54 18 26 50 43 70 10 75 51 34 36 12 38 91 31 113 95 56 81 76 45 53 96 116 41 109 46 1 8 73 101 17 14 107 60 61 5 74 84 112 66 42 111 98 6 19 78 106 92 88 108 85 67 68 25 33 90 21 32 57 40 4 9 58 97 83 89 49 103 39 80 13 79 27 86 16 37 30 55 23 48 2 11 20 77 104 29 100 63 64 110 117 99 69 105 115 22 52 62 65 35 87 3 82 94 28 114 15 21421 s 11672 eparate line The list of rooms is 11473 sorted according to the increasing roomnumber 0 15 11 7 12 1 8 6 14 5 10 9 2 15 3 13 4 21219 The 12547 list 0 186 28 40 162 132 53 183 117 39 90 74 61 20 104 75 95 184 45 80 169 179 38 29 59 163 4 165 37 32 6 56 19 185 34 81 137 89 144 16 27 119 3 84 68 69 33 94 106 73 115 105 155 88 42 43 83 109 177 100 11 154 41 164 77 143 49 158 9 125 99 85 147 118 153 12 47 65 156 98 170 60 151 129 123 110 111 139 107 76 67 114 145 122 17 161 172 121 167 46 101 126 116 93 157 50 21 138 112 173 176 140 62 30 141 31 103 168 36 136 120 86 91 58 174 178 64 127 10 149 52 13 8 150 186 79 87 128 171 102 23 48 24 44 82 15 7 159 152 124 130 142 134 131 2 5 148 166 78 14 72 182 35 160 57 146 180 1 92 71 97 108 133 70 22 175 26 51 96 18 181 25 66 55 113 54 63 135 6552 of rooms ends 29695 by the line containing 0 26134 The list of the des 0 101 33 65 55 88 92 27 4 6 47 101 37 8 99 59 24 68 79 29 36 1 61 18 25 35 54 20 38 95 80 9 83 39 45 51 34 28 69 14 5 16 62 46 96 73 63 42 52 72 71 12 53 10 3 97 75 41 93 57 70 91 98 40 43 77 84 21 22 11 26 23 78 49 13 82 85 15 7 89 94 48 90 87 76 31 56 60 17 66 50 100 2 86 44 67 64 58 19 74 30 81 32 31712 cri 16099 ptions of vi 0 95 38 57 88 2 10 70 75 67 69 81 77 34 59 30 35 28 43 60 46 33 49 45 39 53 73 63 6 26 68 47 37 19 18 22 64 95 23 32 17 15 54 13 41 9 55 62 12 92 40 86 16 50 65 1 4 7 25 78 36 79 89 82 11 20 93 76 3 5 94 29 71 8 52 66 14 31 27 80 24 83 48 61 42 91 44 56 90 87 84 21 51 72 74 58 85 1516 sits ends by theline containing the character dotH3OutputH3The 7192 output contains detailed records of each agents visit in the headquarters For each agent ther 9024 ewill be a block Blocks are ordered in the order of increasing agents codes B 0 171 51 146 12 98 44 152 89 135 144 87 22 81 93 139 147 54 120 30 56 33 116 39 153 128 59 42 32 66 34 142 118 50 3 127 160 92 48 113 88 72 57 78 16 107 27 40 117 18 97 31 163 161 43 99 68 159 19 154 86 126 55 157 119 65 35 53 137 15 100 8 155 85 62 167 91 102 80 5 29 103 71 90 7 67 133 156 52 148 37 38 82 14 58 79 141 60 45 63 28 101 47 20 162 106 136 94 112 61 70 123 84 121 73 169 13 122 1 77 95 49 104 2 124 105 143 151 149 134 10 165 130 26 4 114 129 25 145 166 108 69 132 75 9 164 11 140 17 158 115 76 131 96 171 24 46 64 150 74 23 111 109 170 138 36 41 6 83 110 125 168 21 26695 locks are separated by anempty line After the last block there is an empty line too The first line of a block contains the code ofagent Next lines contain the sta 0 148 58 47 17 100 95 9 141 103 70 75 37 113 110 126 20 7 10 128 24 147 139 27 83 87 117 71 93 94 42 140 97 38 67 142 76 57 91 60 86 122 72 11 116 25 127 41 145 53 77 46 125 143 2 90 130 33 133 135 82 92 65 48 69 19 131 64 61 123 148 29 28 13 8 137 88 108 118 31 73 34 105 32 89 56 5 36 102 40 39 85 15 49 104 43 115 129 74 134 119 1 144 63 111 84 96 45 52 120 50 132 124 138 106 121 62 55 22 54 114 51 79 44 80 98 109 101 107 35 18 136 146 26 59 3 6 99 81 66 68 112 14 23 4 16 21 12 78 30 21767 rting and ending time in format HHMMSS and the descriptions of hisheractivity Time data will be separated by one blank charact 0 68 65 19 25 13 16 48 27 35 55 52 44 2 28 33 30 12 51 21 24 4 37 7 49 68 53 11 34 39 9 26 23 62 57 56 66 17 41 31 40 64 42 38 50 8 58 29 1 47 14 3 60 22 5 20 54 46 59 63 36 61 6 10 67 32 45 18 15 43 1357 er Description will be separat 18472 ed from time byone blank character Description will 19885 have a form Entry Exit or Message The Message can b 0 145 61 73 5 22 36 35 20 136 33 41 92 8 70 15 104 123 23 107 18 91 143 19 13 45 3 38 2 78 75 26 93 34 42 9 32 83 130 30 97 46 118 145 24 28 47 132 76 54 105 72 71 140 82 125 112 60 138 129 17 87 122 94 69 67 51 11 144 79 117 74 120 139 124 25 116 56 44 40 16 66 68 86 21 6 77 102 50 141 12 89 100 7 31 134 121 27 131 108 65 52 106 135 90 84 43 96 115 110 103 111 4 88 1 37 99 58 137 142 64 101 119 109 62 29 59 63 113 55 39 127 57 95 98 85 14 10 81 114 80 126 48 49 133 128 53 29355 e one ofthe following ttWaiting in elevator queuett ttWaiting in front of room iRoomNumberitt ttTransfer fromroom iRoomNumberi t 6697 o room iRoomNumberitt ttTransfer from elevator to room iRoomNumberitt ttTransferfro 1073 m iRoomNumberi to elevatortt ttStay in room iRoomNumberitt ttStay in elevatorttH3ExampleH3BInput file BPREA 1000000101 100011 0 72 7 19 22 36 67 26 13 12 15 31 55 2 70 64 6 53 51 54 66 45 35 60 21 65 28 29 72 32 56 44 48 69 43 30 52 40 46 62 14 1 23 58 24 38 42 49 27 11 68 4 8 63 10 37 3 59 9 39 71 41 34 33 20 16 5 47 17 50 61 25 57 18 13266 0 500202 900205 500B 1001000105 618 1000201 50205 2000PREBOutput fileBPREA100000 100030 Entry100030 10 11148 0210 Stay in room 0 158 29 67 73 33 15 17 137 77 49 2 47 39 150 132 40 38 57 111 11 156 30 37 138 65 74 151 103 48 25 116 78 136 70 41 128 81 62 127 35 50 54 4 66 147 153 145 149 36 93 23 76 119 27 100 34 80 51 105 126 68 12 143 97 130 56 22 45 53 117 6 91 75 20 120 88 72 121 24 82 84 109 79 63 113 52 108 110 92 95 16 60 96 94 107 118 8 14 26 13 64 125 102 19 129 144 106 155 99 154 1 115 133 43 122 28 158 44 18 55 134 61 87 59 124 148 101 71 90 123 89 7 142 146 157 83 112 141 69 42 85 140 139 135 98 31 3 10 32 114 152 131 5 46 104 21 58 86 9 31606 0101100210 100220 Transfer from room 0101 to room 0110100220 100310 Stay in room 0110100310 100320 Transfer from room 0110 to el 0 42 4 1 32 6 20 25 11 38 19 26 9 12 36 14 22 18 3 21 34 37 30 17 7 27 40 5 8 23 13 35 16 31 15 29 2 33 28 41 10 42 24 39 19389 evator100320 100350 Stay in elevator1003 5478 50 100 9168 400 Transfer from 0 147 82 70 15 54 134 67 102 50 136 57 90 34 137 138 8 36 119 92 40 130 122 13 77 43 41 81 4 12 17 51 46 101 126 85 141 127 74 104 83 98 24 61 48 73 128 76 131 38 120 107 20 26 135 23 1 5 49 37 75 55 3 68 63 123 124 32 18 87 69 91 19 96 129 88 99 59 71 140 109 7 94 27 84 66 121 100 9 97 16 80 25 31 29 72 6 52 28 103 115 95 30 116 56 93 114 147 105 35 106 62 117 58 44 144 125 142 45 145 110 21 33 42 139 14 86 133 64 10 39 22 60 47 111 89 143 79 11 53 2 108 146 118 65 78 112 113 132 31645 elevator to room 0202100400 100530 Stay in room 0202100530 100540 Transfer from room 0202 to room 0205100540 1007 30061 40 Waiting in front of room 0205100740 100830 Stay in room 0205100830 100840 Transfer from room 0205 to elev 1259 ator100840 100910 Stay in elevator100910 100940 ExitB100100 0 162 21 57 42 27 103 50 4 14 138 77 65 55 127 159 22 97 63 53 130 35 142 41 61 20 158 43 106 92 135 31 1 32 120 126 132 40 101 102 94 73 87 129 51 52 137 66 60 84 80 155 30 124 7 81 88 114 24 95 78 112 109 70 125 25 89 85 116 54 122 153 90 134 75 136 162 99 93 46 12 82 83 140 10 143 37 96 105 151 100 26 148 15 150 45 76 147 111 28 146 67 69 18 107 121 62 144 34 119 160 56 86 118 48 123 141 8 154 108 110 38 117 91 13 6 74 149 156 68 58 115 145 104 33 36 39 128 3 133 161 23 49 157 17 9 79 29 131 152 71 5 72 19 47 2 113 11 98 139 44 64 59 16 24098 100130 Entry100130 100310 Stay in room 010510031 23069 0 100320 Transfer 0 51 41 37 31 26 18 14 24 2 39 4 42 7 27 13 1 34 11 43 35 16 9 32 48 44 8 10 45 19 3 6 5 25 40 47 30 22 29 15 49 12 21 36 17 38 46 33 50 28 20 23 51 3623 from room 0105 32492 to elevator100320 100325 Waitin 0 184 126 51 139 133 14 21 52 92 128 37 27 45 153 111 56 147 54 154 146 120 163 3 28 109 22 20 168 75 115 69 42 10 13 102 110 47 119 12 93 157 46 88 152 40 33 71 23 171 134 49 67 145 175 148 105 76 25 68 125 73 97 34 136 77 180 18 181 78 144 86 107 138 108 176 169 135 85 177 8 158 35 94 30 100 98 112 124 130 167 38 101 99 173 113 104 122 50 117 95 64 183 178 9 24 172 156 29 36 89 106 4 137 39 1 155 140 118 166 96 74 150 159 142 7 65 182 55 116 31 129 141 83 15 81 160 165 132 66 90 2 174 5 87 70 53 79 61 179 184 80 6 164 63 59 57 60 151 17 161 123 131 103 170 121 48 149 19 84 41 127 162 114 58 62 44 91 11 82 16 32 43 72 26 143 193 g in elevator queue100325 100355 Stay in elevator100355 100405 Transfer from elevator to room 0201100405 100410 Stay in room 0201100410 100420 Transfe 24540 r from room 0201 to room 0205100420 100740 Stay in room 0205100740 100750 Transfer from room 0205 t 7636 o elevator100750 100820 Stay in elevator100820 100850 ExitPREBODYHTMLHTMLHEADTITLECERC 1995 Problem F JosephTITLEHTML version generated by Ko 0 15 9 14 6 8 11 4 2 7 3 10 5 1 15 12 13 24541 tas 25533 Koucky 0 159 20 124 137 86 2 23 37 38 140 57 81 152 43 159 119 49 112 85 46 30 36 22 31 18 118 153 34 41 19 97 98 64 103 58 142 56 83 115 128 151 62 138 52 122 35 136 150 82 154 40 75 120 135 29 8 3 50 70 4 24 139 94 123 74 93 100 145 116 69 59 11 133 91 99 12 114 17 84 72 101 132 155 54 28 68 149 39 106 76 55 111 131 126 51 63 16 77 141 61 129 14 15 117 107 13 78 157 79 146 65 113 1 104 134 125 66 47 89 44 121 144 96 6 45 42 32 108 110 143 67 71 33 5 9 147 27 21 60 7 148 26 48 102 88 87 127 95 156 90 10 80 92 73 130 158 109 25 53 105 2086 1998HEADBODYH2 ALIGNCENTERACM International Collegiate Programming Contest 9596H2P ALIGNCENTERBSponsored b 0 129 118 115 29 24 51 54 47 74 15 50 7 60 111 39 92 114 44 124 32 96 64 17 109 85 106 93 107 42 59 78 28 27 90 122 18 9 125 66 127 98 112 49 4 38 22 101 70 36 97 16 34 3 72 91 13 52 129 83 69 128 21 2 99 26 1 100 35 12 53 102 95 94 41 126 33 25 86 8 6 120 84 81 108 123 79 119 63 116 113 82 55 31 45 62 48 11 65 89 14 67 68 61 110 20 10 23 105 56 103 121 87 5 40 75 57 117 73 88 30 71 46 104 76 58 19 80 43 37 77 25965 y MicrosoftBH3 ALIGNCENTERCentral European 13505 Regiona 17136 l ContestH3BRH2 ALIGNCENTERProblem F Jose 0 25 1 2 6 24 13 21 10 8 5 17 16 4 14 9 12 19 15 22 18 3 25 23 11 7 20 27953 phH2P ALIGNCEN 0 2 2 1 24234 TE 0 127 44 47 32 23 46 79 19 60 54 75 26 124 53 122 110 50 99 94 2 30 51 8 35 61 81 65 88 20 64 27 13 63 62 66 15 49 17 3 48 55 57 126 4 86 90 52 16 58 114 91 82 28 105 10 120 67 78 96 87 108 25 112 9 103 24 22 109 104 107 125 21 93 74 119 121 85 72 84 97 31 12 98 73 117 40 45 71 111 116 106 101 18 5 38 76 80 100 102 113 1 29 36 33 59 34 68 41 56 115 83 69 70 77 43 6 14 42 123 127 37 11 95 118 89 7 92 39 31166 RBInput fileB ttjosephintt 23921 BRBOutput fileB ttjosephoutttBRBProgram fileB ttjosephpastt or ttjosephcpp 0 33 16 3 20 18 27 17 23 22 15 24 4 21 12 10 19 7 33 28 11 14 9 32 13 2 25 29 6 26 30 8 1 31 5 25476 ttPThe J 6097 osephs problem i 0 146 15 144 92 43 3 124 63 94 70 83 79 58 95 131 89 136 68 2 12 35 28 73 13 112 109 84 127 145 85 9 98 53 57 8 80 38 29 33 125 56 137 90 25 78 21 121 64 116 34 67 113 118 97 20 130 16 11 146 54 39 139 46 48 87 138 115 88 31 140 82 14 27 45 40 32 18 26 135 60 123 91 101 111 23 81 99 5 104 1 66 106 102 76 105 49 41 108 30 37 110 96 134 100 86 36 7 55 132 133 52 114 120 61 72 119 19 143 62 93 74 129 107 10 69 65 24 117 4 42 142 51 44 126 47 103 75 6 128 141 17 122 50 22 77 59 71 20369 s notoriously known For those who are not familiar with the original p 0 3 3 1 2 14234 ro 27944 b 20653 l 0 96 42 69 29 34 91 30 36 43 48 81 14 40 7 13 17 53 83 89 32 9 39 52 26 27 71 33 12 82 66 86 18 45 72 90 2 88 95 57 47 78 51 68 28 59 84 44 6 87 38 3 37 8 92 74 23 46 58 16 19 1 77 79 67 41 20 54 80 10 22 63 75 21 5 4 85 73 25 61 70 96 11 65 93 31 64 50 24 60 62 94 49 35 76 15 56 55 16667 emfrom among InI people numbered 1 2 InI standing in 31540 circle every ImIth 0 97 54 58 12 52 60 45 8 42 14 39 76 21 7 26 18 19 17 82 29 59 63 72 81 78 88 89 33 66 75 9 80 74 44 83 56 71 46 38 47 11 1 13 22 95 91 53 61 20 49 96 55 97 94 62 2 87 43 24 86 90 69 35 48 3 85 23 67 51 15 10 65 6 73 68 34 4 31 30 40 64 27 84 16 32 50 5 79 41 92 57 93 25 77 37 28 36 70 32522 is going to b 22354 e executed and onlythe life of the last remaining person will be saved Joseph was smart en 0 102 81 53 32 60 92 43 59 58 24 10 99 25 21 97 70 56 30 55 62 68 27 67 4 64 38 46 8 40 34 13 80 29 94 84 11 51 50 102 89 19 85 66 96 75 87 2 22 1 74 101 3 91 6 18 26 79 47 41 23 42 9 86 76 54 88 45 7 31 69 95 52 14 17 16 82 44 57 72 37 36 20 98 77 63 93 12 83 78 49 5 28 65 33 15 73 39 61 100 71 48 35 90 15519 ough to choose the position of thela 0 79 52 7 43 39 35 33 31 58 73 12 64 42 19 38 2 56 70 60 77 1 32 20 6 41 13 78 15 47 24 76 54 23 48 8 57 3 45 21 27 53 11 71 26 9 10 65 37 16 61 28 22 36 17 40 18 59 25 79 49 63 4 55 50 30 74 72 14 67 5 69 29 51 62 46 75 68 34 66 44 32223 st remaining person thus saving his l 4909 ife to give us the message about the incident For example whenInI 17950 6 and ImI 5 th 0 45 25 10 11 41 44 5 6 8 13 27 29 23 40 2 1 24 31 14 39 17 35 33 38 18 9 28 36 43 32 21 19 30 42 7 37 12 22 16 4 20 34 45 26 3 15 14164 en the people will be executed 30858 in the 11285 order 5 4 6 2 0 68 39 7 14 19 65 50 20 67 9 38 13 45 43 16 53 35 66 37 48 28 55 25 49 54 29 64 41 68 46 3 63 12 33 44 30 40 27 60 36 47 32 56 23 11 34 31 61 21 42 5 26 1 58 4 17 57 52 15 18 22 2 62 24 59 10 51 6 8 1552 3 and 1 will be savedPSuppose that there are 3308 k g 0 95 25 68 84 24 3 92 11 34 91 44 9 48 17 4 12 36 7 63 53 8 14 33 76 41 50 61 83 38 46 2 74 67 26 5 59 69 51 65 85 55 29 49 72 47 86 1 27 40 58 90 30 80 15 89 57 20 56 82 23 78 19 16 6 43 62 66 70 13 21 95 54 77 22 93 94 18 31 79 75 37 28 35 10 87 42 73 64 88 32 60 81 71 39 52 45 17537 ood guys and k bad guys In the circle the first k are good guys a 26160 nd the lastk bad guys You have to determine such minimal m that all the bad guys will 0 68 52 9 31 43 5 14 8 15 3 17 57 58 54 56 21 6 25 2 42 26 68 1 20 13 53 60 66 18 61 7 10 12 4 35 44 30 63 47 51 11 27 29 36 55 64 49 34 59 22 50 32 65 16 41 45 23 19 48 38 39 28 46 24 33 37 40 62 67 28380 be executed before the firstgood guyH3InputH3The i 13739 nput file co 0 74 3 51 4 1 12 66 30 35 16 25 54 34 5 48 71 6 24 31 42 40 61 70 11 47 13 19 49 62 20 29 69 74 65 26 67 23 8 33 72 2 50 46 59 73 56 55 41 38 36 39 43 63 60 15 17 22 27 53 14 28 64 32 18 37 7 58 21 57 9 68 10 52 45 44 17268 nsists of separate line 28377 s containing IkI The last line in the input file contains 0 You 25067 cansuppose that 0 lt IkI lt 14H3OutputH3Th 0 173 108 34 39 80 37 10 32 98 173 59 169 163 167 156 3 114 43 19 150 134 28 131 24 139 145 22 109 120 104 118 49 77 133 140 171 70 126 13 160 53 90 8 121 82 11 155 91 55 112 89 38 143 23 96 165 84 18 35 27 87 56 71 16 78 36 54 105 161 116 67 142 31 149 83 148 166 73 129 79 86 29 103 138 2 162 44 125 76 94 60 153 30 48 5 68 147 130 144 69 170 15 101 92 41 42 95 6 14 61 64 117 110 33 26 119 45 81 58 158 141 57 72 102 136 85 123 7 52 50 17 137 46 132 135 107 4 124 12 99 146 154 63 97 21 106 1 151 115 20 164 172 159 65 47 152 25 122 157 168 100 75 40 128 66 51 62 93 111 127 74 113 88 9 26437 e output file will consist of separate lines containing ImI correspondin 0 76 51 61 19 70 71 13 59 16 26 7 76 1 68 18 37 31 14 34 65 10 67 22 27 11 73 69 58 38 29 66 9 28 40 36 39 3 17 74 42 48 24 56 57 21 54 2 6 32 72 41 15 55 63 50 49 4 5 75 62 60 64 53 12 8 45 25 33 30 52 44 47 35 23 46 43 20 3795 g to IkI in the input file 12789 H3ExampleH3BIn 0 192 19 47 42 139 96 11 137 56 182 129 15 27 86 152 79 38 5 135 87 142 25 76 28 130 170 94 30 81 8 10 101 63 74 12 64 35 83 132 102 115 55 13 37 113 90 168 2 183 114 181 89 26 108 159 84 179 121 160 40 97 44 82 169 75 54 24 103 150 173 105 88 22 91 9 189 71 161 1 45 52 4 154 155 48 73 125 166 112 127 106 116 126 144 162 98 33 29 92 43 117 123 107 16 174 18 134 138 77 3 85 122 118 184 186 119 72 17 157 53 23 99 46 128 191 69 21 120 176 192 93 39 149 20 147 7 58 171 57 177 167 143 41 51 50 146 14 67 141 131 163 6 62 172 65 124 32 175 66 180 95 133 140 190 104 188 70 178 165 164 151 153 78 59 61 100 49 34 185 158 109 31 36 156 136 111 145 187 80 68 148 60 110 7204 put fileBPRE340PREBOutput fileBPRE530PREBODYHTMLHTMLHEADTITLECERC 199 22800 5 Problem G CipherTITLEHTML version generated by Kotas Koucky 1998HEADBOD 10390 YH2 ALIGNCENTERACM International Collegiate Programming Co 0 142 83 91 49 12 48 29 40 104 17 119 140 33 3 73 28 35 133 24 39 11 18 120 60 50 55 93 109 26 6 89 111 134 41 66 79 101 128 53 5 131 125 51 71 137 7 76 82 56 77 105 34 46 9 20 70 130 64 27 80 30 127 81 54 100 16 115 85 38 69 45 31 90 43 75 78 57 113 22 117 95 58 138 126 19 42 2 107 84 141 52 136 96 110 23 97 129 122 32 124 74 118 114 98 72 139 108 13 68 121 25 36 15 102 44 62 67 92 87 8 10 37 116 94 112 1 4 21 86 142 47 106 135 99 132 88 65 103 61 59 123 14 63 14075 ntest 9596H2P ALIGNCENTERBSponsored by MicrosoftBH3 ALIGNCENTERCentral European Regional 7678 ContestH3BRH2 ALIGNCENTERProblem G CipherH2P ALIGNCE 27330 NTERBInput 0 133 16 60 20 56 73 76 116 109 111 58 105 98 69 62 22 80 91 85 43 93 53 5 41 47 64 23 126 133 11 37 113 96 112 28 94 89 54 82 33 34 68 45 59 50 104 8 52 55 13 127 86 31 114 97 24 70 72 132 17 66 9 46 40 32 131 35 84 27 71 81 78 88 29 107 128 2 125 75 118 119 38 124 115 100 51 83 122 87 10 110 92 102 106 15 25 12 67 79 108 95 117 129 121 120 6 49 44 48 36 65 123 42 99 74 21 7 61 4 39 30 103 57 130 90 18 77 26 19 3 1 14 63 101 27669 fileB ttcipherinttBRBOutput fileB ttcipheroutttBRBProgram fileB t 31108 tcipherpastt or ttciphercppttPBob and Alice started to use a brandnew encodin 9830 g scheme Surprisingly it is not a Public Key Cryptosystem but their encoding and decoding is based on secret keys They chose the sec 0 188 55 24 181 99 9 100 95 65 75 180 69 170 57 102 186 169 173 14 78 147 63 40 124 13 66 47 22 168 143 44 2 77 89 165 70 74 53 87 96 93 85 11 188 140 145 67 114 187 51 58 184 120 4 5 134 34 144 71 108 127 1 107 122 83 90 7 159 35 117 21 79 26 105 92 157 118 183 60 46 174 98 152 128 91 86 88 68 182 10 20 32 23 52 125 109 167 16 80 111 171 177 136 8 72 129 28 110 17 54 138 162 166 126 149 101 37 133 39 142 137 45 56 82 161 33 139 164 97 84 163 155 172 106 153 175 61 131 73 94 30 113 135 3 179 36 104 25 64 6 43 132 130 150 148 160 112 146 59 76 119 49 41 154 48 123 156 18 115 103 176 81 158 151 50 185 121 62 141 15 42 116 38 31 27 29 19 12 178 23213 ret key at their lastmeeting in Philadelphia on February 16th 1996 They chose as a secret key a sequence of InI distinct integers IaI1 Ian 30647 I greater 0 64 8 37 4 1 64 63 22 44 61 60 29 10 7 41 50 26 19 30 36 17 3 25 31 39 33 55 9 62 23 40 11 13 54 38 45 14 15 16 34 43 53 48 47 12 21 20 56 24 46 27 57 52 59 2 5 6 58 49 32 28 18 35 51 42 22669 than zero a 18421 nd 19267 less 0 74 69 18 17 50 33 15 31 9 58 3 60 26 68 53 54 38 27 46 63 2 7 52 22 48 55 47 35 72 56 25 19 16 29 49 8 5 65 34 45 59 10 20 43 62 37 61 57 14 24 42 13 41 70 40 67 44 66 30 1 28 39 74 6 12 51 32 71 36 4 11 23 73 21 64 7704 or equal to InI The encoding is based on the following prin 0 40 3 29 40 28 14 13 10 37 11 35 4 22 27 32 23 2 39 26 36 7 17 20 5 24 25 1 31 33 12 21 15 30 8 18 19 34 6 16 9 38 5822 cipleThe message is writ 12562 ten down belo 0 55 41 37 7 40 8 9 14 25 30 10 27 1 53 18 23 12 49 19 11 33 39 4 47 6 16 35 36 46 38 32 5 20 28 43 50 26 51 15 42 45 54 55 24 31 22 52 17 44 48 3 21 34 2 29 13 31334 w the key so th 31444 at characte 7478 rs in the message and numbers in the key arecorrespon 0 171 55 27 102 61 106 156 71 29 95 171 126 22 21 59 34 6 94 42 89 97 77 38 44 122 39 117 132 26 79 112 83 85 40 47 105 35 73 24 33 66 15 1 151 109 36 82 96 31 103 45 64 62 153 137 9 169 154 164 166 143 5 74 129 80 120 161 70 13 157 118 150 144 32 114 100 108 145 93 135 18 58 16 121 140 78 12 28 139 107 152 41 110 19 88 46 4 125 49 162 69 25 113 76 158 119 86 101 30 92 159 10 7 43 165 67 11 60 3 91 163 53 104 90 134 72 115 133 81 2 37 160 63 168 48 56 149 8 127 50 51 128 170 87 167 155 52 23 124 136 148 116 146 142 130 138 123 98 84 54 14 141 99 57 131 68 17 111 75 20 147 65 29096 dingly aligned Character in the message at the position i is written in the encoded message at theposition IaiI where IaiI is the correspondi 10002 ng number in the key And then the encoded message is encoded inthe same way This process is repeated IkI times After IkIth encoding they 32290 exchange their messagePThe length of the message is always less or equal than I 0 197 67 58 56 186 9 63 68 31 66 54 175 176 154 122 50 144 33 174 187 57 79 118 82 178 113 20 162 52 163 72 28 195 80 16 29 119 134 102 17 42 146 100 124 53 35 81 22 85 112 125 183 77 65 157 130 194 88 117 171 13 4 89 93 5 196 40 75 188 14 87 12 141 21 62 10 136 173 101 135 161 185 99 41 69 165 103 59 73 76 156 133 128 6 114 44 139 96 182 131 120 27 149 36 47 140 94 121 91 108 148 70 24 90 19 3 168 129 39 145 106 126 181 2 107 137 18 98 116 92 1 179 170 97 110 123 83 184 51 138 61 155 95 151 164 23 150 32 11 45 192 86 46 15 64 26 191 180 172 169 142 60 84 127 111 109 38 48 25 132 193 143 177 34 152 197 104 105 159 166 158 30 74 147 37 189 115 8 190 7 78 167 55 49 153 71 160 43 14020 nI If the message is shorter than InI then space 31344 sare added to the end of the message to get the message with the length InIPHelp Alic 28411 e and Bob and write program which reads the key and then a sequence of pairs consisting ofIkI and message to be encoded IkI times and produces a list of encod 0 162 79 22 113 12 104 95 85 99 97 84 70 121 16 9 3 1 136 21 161 20 131 107 29 39 130 151 71 147 63 94 46 45 69 82 149 75 11 140 30 145 122 132 81 56 110 128 117 57 96 67 112 72 119 143 155 106 42 124 74 54 92 5 59 105 44 127 41 83 19 64 28 43 7 103 87 76 65 26 135 32 90 133 108 125 100 23 77 34 88 123 160 24 134 89 120 8 55 61 60 98 102 37 62 152 51 73 118 18 114 38 146 48 158 33 58 6 144 137 13 4 111 47 156 115 27 126 14 159 53 101 142 50 91 52 148 150 40 86 25 116 35 109 129 66 154 141 78 68 49 17 157 15 153 139 36 10 162 31 138 93 2 80 26685 ed messagesH3InputH3The input file consists of s 24240 everal blocks Each block has a number 0 lt InI lt 2 0 200 58 25 8 108 154 57 71 39 16 60 164 177 11 150 180 63 18 95 33 62 185 9 169 142 40 38 68 89 14 15 31 50 193 83 171 94 199 132 37 98 54 102 174 187 109 153 41 137 166 141 176 10 27 100 76 124 78 128 184 190 163 43 200 90 77 107 32 112 80 143 72 117 191 35 192 23 34 170 75 172 179 130 6 93 91 196 64 118 3 152 183 61 113 157 119 67 29 144 56 134 120 178 49 12 59 125 4 7 159 160 145 51 175 26 70 48 165 81 161 149 135 44 84 86 28 20 133 115 198 136 195 188 182 30 19 158 122 53 13 140 114 55 104 173 103 79 88 156 36 139 181 151 197 74 146 129 126 92 73 99 101 147 131 106 189 87 123 69 47 186 148 17 52 127 82 21 5 2 42 116 138 97 1 121 168 85 24 22 110 65 66 46 194 155 96 111 105 162 167 45 18394 00 in the first line Then 0 114 16 1 37 15 90 75 111 9 14 45 110 92 49 39 29 59 40 65 21 79 25 56 57 66 71 13 31 76 20 84 87 10 69 17 4 24 106 12 104 70 54 73 108 89 101 102 61 88 93 94 41 78 42 74 5 64 47 51 86 2 19 68 80 91 33 8 105 83 112 44 34 43 62 46 27 48 100 32 82 7 22 35 103 11 6 109 58 95 96 113 81 18 60 52 53 38 67 114 77 3 107 99 98 26 30 50 72 55 97 85 23 36 28 63 12440 ext line contains a sequence of In 28605 I numbers pairwise distinct and each gr 0 21 12 5 2 4 13 8 9 16 7 14 1 6 11 19 15 18 3 10 17 21 20 452 eater than zero 21099 and less or equalt 0 18 13 8 9 12 4 18 3 15 1 5 6 10 16 2 11 14 7 17 21838 han InI Next line 14735 s contain int 0 147 38 123 59 9 125 116 140 10 56 144 73 31 12 120 4 100 35 23 2 94 53 41 1 86 66 27 15 58 57 105 46 29 82 49 71 141 17 67 98 81 87 43 129 64 139 6 50 65 132 62 61 13 97 70 137 60 118 16 32 110 134 104 85 130 45 80 117 36 107 113 89 127 19 109 28 95 26 75 54 33 88 124 76 37 68 55 91 121 128 30 51 101 99 115 142 5 138 72 44 63 90 3 122 147 103 77 79 131 133 135 11 69 126 24 40 74 42 119 136 22 20 78 18 111 21 48 96 7 34 14 93 114 112 102 108 83 84 106 145 8 47 146 39 52 25 143 92 25028 eger number IkI and one message of ascii c 16199 haracters separated by one spaceThe lines are ended with eol this eol does not belong to the message The block ends 0 162 32 131 24 33 11 40 4 97 8 42 23 26 16 67 99 133 125 55 84 151 13 27 31 137 148 75 123 15 45 77 92 101 48 64 12 90 128 150 113 98 142 161 87 120 80 72 21 38 70 78 9 156 144 160 108 105 65 117 49 136 111 107 57 124 115 10 59 85 112 46 126 18 146 89 62 79 71 2 81 157 86 36 22 114 158 141 119 159 132 139 143 162 7 130 110 147 60 102 96 20 94 155 109 129 25 47 19 44 88 14 6 30 50 118 138 152 43 17 134 3 100 68 56 103 140 149 51 54 106 153 28 37 145 154 53 83 69 74 73 91 104 121 95 58 34 127 122 135 63 66 52 39 5 61 29 76 35 1 93 41 82 116 17393 with the sep 21648 arate linewith the number 0 After the last 0 157 12 44 126 109 40 26 13 60 21 115 68 37 50 99 128 84 8 58 30 110 32 146 35 14 157 124 154 43 28 49 134 1 45 11 92 15 47 116 5 20 119 41 79 138 97 24 78 121 100 129 117 17 104 25 88 46 52 120 31 34 111 147 94 137 144 29 156 135 70 140 64 51 85 93 130 108 102 149 66 112 125 151 90 4 53 145 98 55 139 54 23 107 19 136 118 142 150 101 75 2 131 133 38 95 42 86 81 127 141 18 73 36 56 89 9 48 22 155 62 123 16 76 80 114 65 63 72 61 132 77 91 69 27 83 152 122 153 96 87 113 33 39 71 57 3 82 148 6 74 67 105 143 106 7 10 59 103 30119 block there is in separate line the num 0 154 151 111 14 10 33 139 63 46 115 29 38 34 107 81 49 57 70 80 78 119 95 126 148 48 132 60 22 56 39 97 19 131 85 59 140 125 1 32 109 52 74 127 98 64 37 79 45 40 96 66 42 135 31 147 94 153 154 20 90 101 121 12 92 134 61 18 118 84 5 16 69 99 23 15 71 3 141 106 83 117 44 77 76 123 104 53 50 124 47 7 91 75 36 112 43 17 54 113 41 35 108 82 144 116 27 25 129 21 128 55 13 67 149 102 24 103 8 68 120 11 93 152 28 110 9 30 2 145 114 4 89 100 130 137 138 122 58 65 72 105 136 146 150 87 73 143 133 6 51 88 26 62 86 142 29139 ber 0H3OutputH3Output is divided into bloc 16290 ks correspo 0 169 6 69 29 47 38 87 58 36 55 84 116 25 92 49 130 99 24 115 119 126 72 28 85 123 43 57 46 79 41 33 19 5 27 139 141 96 21 65 52 3 15 1 14 30 127 66 151 62 136 103 26 7 97 88 147 80 149 61 106 146 32 20 11 68 132 12 134 120 18 71 155 153 142 161 140 34 56 158 113 93 148 23 59 163 91 107 154 2 164 37 94 67 105 121 44 101 165 16 10 117 131 4 167 112 73 95 17 156 135 114 77 124 100 39 102 169 50 64 74 157 160 137 45 109 150 152 76 89 8 111 31 51 159 125 13 145 60 133 48 9 143 22 54 70 78 40 63 118 75 53 162 110 108 35 83 128 138 168 166 144 90 82 42 129 98 104 81 86 122 11254 nding to the input blocks Each block contains the encoded inputmessages in the same order as in input file Each 23797 encoded message in the out 0 59 10 58 36 34 48 46 57 18 26 47 35 54 22 40 56 6 45 59 1 31 39 51 17 27 33 50 23 19 4 53 49 12 20 14 41 37 13 32 11 3 2 24 30 15 44 5 7 21 43 29 25 42 52 28 16 9 38 55 8 2194 put file has the lenght InI Aftereach 4537 block there is o 31696 ne empty lineH3ExampleH3BInput fileBPRE104 5 3 7 2 0 141 35 140 20 114 51 73 22 44 127 31 139 63 8 46 72 103 56 132 19 70 25 135 100 74 29 113 75 120 30 60 79 69 52 43 90 88 96 58 6 105 55 15 39 121 119 136 128 107 5 78 95 138 33 141 49 61 32 23 116 93 45 76 12 85 125 1 66 50 87 7 42 16 102 9 108 109 137 68 86 48 37 122 64 82 92 98 94 53 17 124 126 84 2 81 106 112 133 83 129 57 3 123 118 54 18 47 117 14 134 101 91 28 59 104 115 38 111 24 26 131 34 62 110 21 41 77 27 10 11 36 97 71 4 13 80 89 65 130 99 67 40 12607 8 1 6 10 91 Hello Bob1995 CERC00PREBOu 0 56 16 40 46 23 9 13 38 36 33 19 47 6 20 5 10 4 48 14 21 55 42 31 22 27 34 53 15 30 54 1 29 35 24 52 43 7 26 51 37 56 39 18 25 50 17 2 28 11 44 45 12 49 8 3 32 41 28244 tput fileBPREBolHeol bC RCEPREBODYHTML 20381 HTMLHEADTIT 0 168 13 4 70 58 118 115 8 157 164 64 39 35 128 16 134 59 105 42 72 29 23 10 77 88 168 90 140 15 120 104 51 18 153 61 166 159 53 94 25 2 57 83 63 108 155 81 55 80 93 162 36 99 100 97 101 119 102 73 1 27 116 12 167 50 5 150 71 107 79 126 30 76 129 86 69 165 110 26 95 7 98 103 112 124 148 11 54 136 135 75 14 92 9 21 68 65 6 161 137 113 3 49 145 117 142 163 52 19 17 74 31 144 151 60 22 32 125 87 146 28 111 122 33 96 106 48 131 130 133 139 67 132 82 138 149 45 44 121 34 91 40 127 141 154 78 47 62 123 156 43 158 143 66 24 46 20 84 109 152 37 85 114 41 56 160 38 147 89 16062 LECERC 1995 Pr 9539 oblem H SticksTITLEHTML version generated by Kotas Koucky 1998HEADBODYH2 ALIGNCEN 0 138 96 24 113 46 90 59 14 89 48 16 8 35 18 71 54 55 47 108 94 136 92 20 15 88 39 65 43 38 137 4 36 85 9 105 21 29 100 37 1 120 110 31 74 30 19 80 79 45 121 26 103 57 102 28 7 106 91 60 82 126 62 13 53 44 56 12 132 138 66 70 95 2 25 81 130 93 116 128 125 22 33 17 50 86 83 115 84 34 32 131 75 6 104 114 87 99 134 51 98 49 117 5 76 10 122 127 77 119 118 133 124 52 69 40 123 78 61 97 109 129 135 58 23 68 27 41 111 42 64 72 67 11 63 3 107 112 101 73 15937 TERACM International 0 82 18 56 41 52 2 57 71 31 72 6 54 80 30 34 29 43 17 25 13 77 48 75 42 24 60 9 3 15 61 68 35 32 27 70 81 23 40 1 37 64 39 20 45 10 14 22 66 76 59 38 50 62 53 78 4 16 55 79 65 69 11 49 82 5 7 58 36 12 73 74 28 26 47 46 21 44 8 63 67 19 33 51 5241 Collegiate Programming Contest 9596H2P ALIGNCENTERBSponsored by MicrosoftBH3 A 24641 LIGNCENTERCentral Eur 0 23 18 15 4 13 8 19 12 11 3 7 5 23 16 17 21 2 14 6 10 20 1 22 9 26762 opean Regional C 24358 ontestH3BRH2 ALIGN 0 88 31 10 43 6 63 11 19 13 49 69 23 75 8 79 21 77 39 76 50 29 51 26 44 15 12 72 71 68 54 60 80 16 37 59 61 9 38 22 83 56 86 67 47 78 18 62 73 5 4 55 48 87 33 45 36 3 25 24 64 84 88 40 65 52 2 27 85 81 42 35 28 57 34 30 82 66 58 46 74 14 20 53 7 17 32 1 41 70 4817 CENTERProblem H SticksH2P ALIGNCENTERBInput fileB tts 19615 ticksinttBRBOutput fileB ttsticksoutttBRBProgram fileB ttstickspastt or ttst 28536 ickscppttPGeorge took sticks of the same 0 191 22 15 16 83 2 184 34 92 152 36 161 25 105 39 3 188 11 136 94 10 166 65 175 67 74 145 68 28 134 14 59 9 29 177 183 137 38 170 135 72 147 23 56 138 160 63 102 7 118 133 5 93 131 66 176 70 106 173 33 18 159 80 62 129 26 125 19 71 75 171 169 27 148 164 142 53 78 98 60 64 8 84 54 91 97 123 126 46 141 162 90 172 165 116 81 103 88 50 20 89 41 99 112 85 149 104 185 157 110 13 120 151 52 182 44 87 154 156 108 12 140 143 179 43 150 95 21 35 153 181 77 79 122 47 6 113 96 57 190 130 186 61 146 40 49 168 144 17 109 51 1 178 174 24 42 187 124 4 115 180 76 114 86 155 82 132 31 127 139 128 107 32 73 158 45 69 191 30 37 101 163 167 58 111 100 189 119 55 121 48 117 22529 length and cut them randomly until al 25672 l parts became at most 50 unitslong Now he w 9252 ants to return sticks to the original state but he forgot how many sticks he had originally andhow long they were originally Please help him and design a pro 0 105 12 100 35 75 39 61 1 70 32 54 7 9 57 73 66 26 40 88 89 16 68 101 44 38 33 77 47 55 103 69 74 6 11 67 13 5 104 45 3 46 83 31 84 63 36 15 76 58 51 94 29 90 20 50 72 65 95 81 2 52 30 82 93 37 102 49 59 18 86 56 10 80 78 64 99 34 24 60 41 8 91 53 21 87 62 14 96 25 98 42 4 43 27 23 71 79 105 92 22 17 28 85 97 19 48 17427 gram which computes the smallest possibleoriginal length of those sticks All lengths expres 14555 sed in units are intege 21360 rs greater than zeroH3InputH3The input 0 40 29 6 21 11 7 5 24 14 27 15 19 25 26 8 10 28 18 30 13 23 36 12 33 35 17 3 22 2 38 37 40 32 20 16 9 39 1 4 34 31 26327 file contains blocks of 11646 2 lines The first line contains the num 0 130 70 107 10 18 59 35 69 58 53 41 80 48 34 12 79 44 61 103 42 4 65 125 2 22 27 67 93 1 109 104 102 62 72 98 66 19 128 6 89 16 9 76 108 64 90 84 54 100 47 123 95 8 96 114 82 26 68 83 36 124 71 33 85 25 88 14 30 118 31 56 13 17 46 40 15 130 20 21 28 81 75 122 39 97 51 45 117 55 127 119 106 116 38 11 24 7 91 49 86 63 29 112 3 87 57 129 120 50 32 78 115 77 110 111 126 94 74 73 37 52 121 60 23 113 101 43 105 5 99 92 31867 ber of sticks parts after cuttingThe second line contains the 4822 lengths of those parts separated by the space The last line of the file containszeroH3OutputH3The output file con 0 146 49 143 18 15 33 69 95 113 91 118 41 87 102 50 96 55 141 89 19 25 133 44 136 115 127 94 135 61 98 37 59 73 84 144 101 21 48 99 40 54 35 125 56 116 107 68 13 60 9 138 27 134 45 66 77 1 132 93 31 7 92 78 51 67 112 121 14 119 106 52 88 146 100 38 4 20 103 140 117 111 47 39 10 123 82 28 42 46 97 53 81 108 26 57 128 16 114 109 43 120 3 72 2 80 70 8 34 11 76 58 142 17 30 137 63 6 86 12 122 139 83 5 24 104 79 129 145 130 65 124 110 32 131 64 126 36 71 85 22 62 90 75 29 23 105 74 20142 tains the smallest possible length of original sticks one per lineH3ExampleH3BInput fileBPRE95 2 1 2369 5 2 1 5 2 141 2 3 40PREBO 24738 utput fileBPRE65PREBOD 0 38 16 24 3 5 33 25 36 22 2 37 29 35 4 19 17 21 20 32 34 10 18 26 15 6 7 38 13 28 12 8 1 9 31 14 27 23 30 11 27507 YHTMLHTMLHEADTITLECERC 1995 Pr 19702 oblem 0 29 7 8 3 18 11 9 26 14 25 16 20 24 12 23 27 17 22 21 28 29 15 4 6 13 5 2 10 1 19 13686 H SticksTITLEHTML 15168 version ge 0 97 6 2 17 19 76 24 26 15 66 13 51 32 73 95 45 69 48 50 28 35 31 54 56 12 59 36 39 34 70 72 44 61 33 80 78 7 37 71 14 18 75 62 4 68 52 41 11 40 65 82 47 5 1 89 38 67 9 92 64 83 77 55 49 74 43 20 90 81 96 94 22 16 87 8 60 10 21 58 97 23 79 53 3 85 46 86 29 88 63 30 91 57 93 25 27 42 84 21627 nerated by Kotas Koucky 1998HEADBODYH2 ALIGNCENTERACM International Collegiat 25329 e Programm 32049 ing Contest 9596H2P ALIGNCENTERBSponsored by MicrosoftBH3 ALIGNCENTERCentral European Regi 0 47 18 5 29 34 45 38 26 2 19 46 11 22 1 20 37 15 47 4 12 42 39 32 7 33 27 30 9 6 43 17 8 14 36 13 10 23 44 3 25 21 28 41 35 40 16 24 31 15669 onal Contest 30981 H3BRH2 ALIGN 595 CENTERProblem H SticksH2P ALIGNC 0 179 35 69 63 139 8 106 79 110 50 6 91 68 118 15 132 81 153 154 171 31 38 161 173 162 47 109 167 16 42 152 84 21 43 146 148 70 107 97 117 23 71 40 166 134 138 29 19 62 115 76 28 30 179 145 61 105 77 44 4 144 177 59 157 125 111 67 156 51 27 54 80 155 147 94 165 48 36 41 131 170 169 89 1 101 10 98 7 128 112 123 163 122 25 90 9 11 114 141 143 86 66 174 149 45 120 124 82 116 33 74 87 99 3 150 140 37 164 39 92 136 55 113 151 13 127 176 20 159 14 85 57 49 121 168 32 119 2 126 135 34 64 88 53 58 24 130 175 46 17 26 108 18 65 93 129 83 104 100 60 52 12 72 56 160 142 96 75 172 102 95 133 78 22 103 5 178 137 158 73 7368 ENTERBInput fileB ttsticksinttBRBOutput fileB ttsticksoutttBRBProgram fileB ttstickspastt or ttstickscppttPGeor 7748 ge took sticks of the same length and cut them randomly until all parts became a 23834 t most 50 unitslong Now he wants to return stic 0 46 17 33 24 27 26 22 16 21 13 5 23 2 40 6 1 15 7 31 44 29 38 8 4 19 11 45 42 41 35 32 25 37 46 36 3 18 9 10 14 43 30 28 20 39 34 12 16643 ks to the original state but he forgot how ma 14439 ny sticks he had 0 111 110 88 79 76 95 62 74 35 101 28 75 67 11 73 100 25 3 104 70 2 87 36 15 52 71 85 40 82 57 47 84 21 43 91 58 56 17 69 61 19 32 103 46 13 24 39 37 105 18 99 23 109 78 81 16 42 6 97 111 4 68 50 98 26 14 60 108 94 77 89 65 12 53 72 29 63 80 7 64 51 5 49 83 33 55 9 41 96 93 54 20 34 90 106 107 66 48 22 8 59 44 1 31 45 30 86 38 10 27 102 92 1087 originally andhow long they were originally Please help him and design a program which com 0 51 14 43 7 28 9 1 31 11 27 45 18 16 20 10 12 32 46 51 23 49 48 2 33 30 29 6 50 8 42 21 40 39 22 19 5 25 36 41 17 26 47 3 4 35 13 37 38 24 15 34 44 20137 putes the smallest possibleoriginal length of thos 8287 e sticks All lengths expressed in 12769 units are integers greater than 0 167 45 78 146 95 20 7 74 62 34 73 9 94 76 40 53 11 3 149 133 153 12 112 47 35 39 100 91 96 98 71 68 63 52 156 56 127 48 8 33 41 157 105 90 42 65 122 161 130 59 32 109 43 166 29 119 107 114 116 124 144 125 162 85 66 64 27 38 79 111 88 159 138 126 89 22 28 148 150 129 24 10 160 147 101 104 134 108 123 50 69 110 158 30 75 103 84 57 6 36 141 25 70 139 152 86 137 135 82 154 131 115 37 18 140 4 102 54 17 15 61 142 132 121 128 72 67 31 87 136 49 117 5 167 46 77 164 143 80 120 60 106 118 55 113 93 16 155 165 14 44 21 97 58 13 81 23 99 19 2 163 83 1 26 51 92 151 145 28094 zeroH3InputH3The input file contains blocks of 2 lines The first line contains the number of sticks parts after cuttingThe second line 0 133 17 5 27 70 84 72 93 21 83 56 9 112 15 57 79 131 128 12 59 14 32 108 43 18 91 67 124 51 110 123 46 20 77 78 90 133 85 106 63 92 88 42 22 118 55 125 16 69 49 10 62 115 76 71 103 117 11 39 35 30 105 6 41 25 94 64 48 60 19 81 132 113 87 74 53 101 73 98 45 126 44 37 1 97 80 47 13 122 66 89 29 52 100 65 104 121 2 61 99 107 40 86 114 28 120 54 116 33 68 127 8 7 58 102 24 75 4 50 129 119 38 111 31 130 95 3 109 96 26 82 34 36 23 5021 contains the lengths of those parts separated by the space The last line 0 52 14 47 36 52 2 4 17 11 45 21 23 1 19 10 26 34 22 24 13 28 40 35 3 48 49 29 33 20 16 8 44 7 12 51 15 39 6 46 41 5 38 37 25 50 30 31 9 43 42 18 32 27 10043 of the file containszeroH3OutputH 0 58 46 6 18 5 47 3 41 25 40 19 23 24 8 32 50 58 12 27 1 7 22 15 48 53 35 17 44 30 37 2 10 38 49 52 42 20 31 56 26 21 57 14 4 33 51 9 55 28 45 34 11 54 43 13 16 39 29 36 17472 3The output file contains the smallest possible length 23091 of original sticks one per lineH3E 8335 xampleH3BInput fileBPRE95 2 1 0 147 43 29 142 14 69 61 39 24 32 3 70 136 41 6 20 56 131 35 103 2 126 78 51 113 92 60 73 59 31 90 115 106 38 134 37 62 91 130 117 26 34 23 101 10 28 53 99 30 139 120 94 125 108 71 18 54 129 72 19 11 89 4 144 96 66 8 114 27 95 87 88 138 104 15 17 137 21 68 40 141 100 146 118 67 65 74 9 58 47 64 13 145 57 5 84 52 109 122 107 124 110 1 81 128 63 121 123 119 45 12 116 36 75 77 16 42 48 135 85 140 127 143 147 50 133 93 111 49 102 79 132 76 112 97 25 46 105 82 83 44 80 86 22 55 7 98 33 6821 5 2 1 5 2 141 2 3 40PREBOutput fileBPRE65PREBODYHTMLHTMLHEADTITLECERC 1995 Problem B TransportationTITLE 16261 H 124 TML version generated 0 2 2 1 32282 b 11754 y 0 139 52 90 77 29 71 58 15 1 84 95 10 113 68 130 20 12 33 64 98 48 13 39 11 67 6 89 28 110 60 96 2 46 117 3 92 18 86 75 45 30 63 69 124 118 103 121 109 83 44 51 38 79 41 105 42 9 112 73 8 115 104 19 16 27 24 97 136 36 126 56 14 78 88 100 74 132 21 5 87 55 119 35 116 23 37 43 25 26 31 70 34 17 101 131 138 59 120 57 107 7 127 32 128 106 125 129 108 99 114 72 66 137 62 49 85 50 22 80 65 102 122 134 94 135 76 40 54 82 81 53 4 91 133 47 61 111 93 123 139 15584 Kotas Koucky 1998HEADBODYH2 ALIGNCENTERACM International Collegiate Programming Contest 9596H2P ALIGNCENTERBSponso 22618 red by MicrosoftBH3 ALIGNCENTERC 0 188 16 88 71 1 147 150 57 157 62 24 79 41 40 137 171 131 117 27 17 55 112 123 12 92 167 42 72 75 44 174 105 45 148 85 141 47 111 101 36 159 77 64 38 66 50 13 126 74 168 91 110 124 78 30 154 149 129 20 181 183 81 164 119 100 51 156 138 132 145 53 10 134 144 83 177 104 121 120 187 175 33 68 94 130 15 136 102 46 48 56 143 133 69 4 93 34 7 90 178 96 108 176 37 155 170 160 95 152 127 3 140 161 35 139 184 162 122 116 8 31 103 61 11 26 115 186 9 21 182 173 54 32 128 28 169 118 19 113 125 188 23 179 70 18 14 165 107 6 185 142 146 39 82 25 65 87 109 73 151 84 43 59 76 58 163 49 2 135 99 172 180 5 97 60 63 89 158 80 86 98 106 29 114 22 153 67 166 52 10464 entral European Regional ContestH3BRH2 ALIGNCENTERProblem B TransportationH2P ALI 3137 GNCENTERBInput fileB tttraininttBRBOutput fileB tttrainoutttBRBProgram fileB tttrainpastt or tttraincppt 29914 tPRuratania is just entering capitalism and is establishing new enterprising act 0 199 191 89 81 104 85 199 195 87 48 58 140 186 79 14 146 117 13 8 182 134 144 71 54 98 193 65 160 72 100 106 157 111 63 177 135 151 192 171 136 147 172 51 49 37 167 152 5 141 91 145 61 126 22 149 128 153 183 90 121 3 75 27 131 43 55 34 119 92 173 116 74 35 178 83 52 10 127 154 165 77 158 187 115 15 23 107 176 9 24 130 123 168 50 143 133 99 29 114 4 118 40 64 194 2 53 150 80 1 148 125 162 110 122 36 155 138 46 42 59 189 67 159 45 26 102 19 95 108 170 12 132 25 97 47 88 156 185 113 96 112 70 60 66 68 93 17 163 41 197 6 16 169 137 21 190 166 175 142 73 28 120 82 101 161 76 181 11 57 33 86 105 129 164 198 44 20 180 124 139 39 184 7 18 30 78 62 32 69 31 94 38 196 109 174 179 188 56 103 84 22767 ivities in many fields including transport The transportation company TransRuratania is start 7449 ing a new express train from city 0 89 4 62 66 2 72 47 25 24 6 28 13 56 17 48 87 18 85 53 9 37 54 57 26 43 46 58 83 69 65 86 84 8 34 1 89 41 44 59 5 49 10 35 70 76 16 64 32 29 78 11 80 36 61 40 82 27 71 3 52 73 12 63 51 50 74 42 75 30 60 21 20 15 39 67 55 68 88 79 22 14 31 38 23 33 7 77 45 19 81 14526 IAIto city IBI with several stops in the stations on the way The stations 19508 are successively numbered city IAI s 0 162 144 159 36 121 49 66 57 40 126 32 14 84 70 88 111 104 140 160 122 162 116 154 47 90 62 96 38 6 60 11 73 29 4 85 156 63 68 127 67 15 20 71 123 58 55 46 74 152 102 80 22 139 24 79 75 25 7 5 87 105 108 135 53 133 41 150 107 91 8 129 26 136 89 34 1 44 16 13 86 158 115 37 35 18 119 52 94 61 43 101 56 77 120 113 134 50 109 92 118 128 138 27 142 100 42 83 145 124 72 103 45 33 64 97 98 65 149 137 48 146 125 9 112 19 12 81 157 31 147 23 82 54 99 3 114 141 17 59 21 161 28 69 95 10 78 153 93 2 132 131 106 51 151 143 130 76 39 30 117 148 155 110 3558 t 0 103 91 6 13 11 4 21 15 63 71 32 98 102 78 81 33 62 36 26 93 43 35 70 72 67 95 101 89 12 1 42 38 25 24 76 2 47 55 19 51 75 29 61 87 20 18 14 80 90 7 50 58 59 40 16 74 64 44 41 39 79 23 8 94 65 56 57 69 45 86 99 10 77 30 83 3 34 66 37 84 60 82 103 22 9 31 73 100 48 28 96 52 85 5 92 17 97 49 68 53 27 46 54 88 2595 ationhas number 0 city IBI station number ImI The company runs an experi 29269 ment 0 68 41 1 8 24 67 19 53 32 7 55 22 36 47 21 20 68 10 16 56 63 52 26 17 48 4 42 5 15 12 38 31 2 44 64 61 46 51 14 40 66 18 58 3 6 39 60 13 34 29 43 54 65 49 23 45 25 50 11 37 62 35 59 28 9 30 33 27 57 15972 in order to impr 24181 ove passengertransportation capacity and thus 28483 to i 0 130 108 3 129 7 92 126 105 109 39 76 47 36 116 88 114 49 57 78 1 117 128 41 53 62 42 125 55 6 43 122 27 115 68 113 69 64 38 29 98 9 112 87 77 71 25 8 119 104 45 96 123 81 58 63 2 82 67 50 52 34 10 22 54 48 106 16 15 101 4 12 118 74 85 65 95 97 107 59 75 56 14 94 44 86 120 89 23 20 83 28 93 70 73 99 61 100 21 124 18 19 46 13 110 121 11 32 17 72 24 35 80 51 33 26 130 5 31 66 30 84 60 102 79 91 111 37 103 127 40 90 7534 ncrease its earnings The train has a maximum capacity InI passengersThe price of the train ticket is equal t 18053 o the number of stops stations between the 0 11 4 5 3 1 8 2 6 9 7 11 10 22891 st 21294 arting 0 172 19 119 80 62 57 45 38 121 46 17 106 35 16 134 114 76 171 167 95 110 162 60 87 68 48 41 138 128 36 141 24 73 103 49 66 74 81 33 18 4 93 139 130 109 108 105 149 161 30 170 169 85 56 9 23 54 14 75 98 100 126 84 159 97 3 70 92 31 13 102 78 118 147 28 99 63 94 58 135 1 43 131 96 59 27 168 129 11 8 122 44 12 5 133 55 140 52 64 72 29 47 65 25 124 21 172 88 123 164 83 61 120 146 82 155 86 111 144 115 125 152 145 50 142 157 53 77 2 91 71 10 136 113 22 165 37 150 6 166 32 40 89 151 137 51 101 107 7 156 39 154 20 158 34 148 132 112 163 104 69 127 79 160 90 116 143 15 67 153 26 117 42 25150 station and thedestination station including the destination station Before the tr 1131 ain starts its route from the city IAI ticketorders are collected from all onroute stations The ticket order from th 0 98 85 12 96 19 8 78 43 29 63 30 11 45 48 28 82 21 84 24 49 33 26 17 42 18 25 14 90 13 38 79 56 9 37 2 81 40 70 10 68 86 92 1 58 64 88 65 72 60 15 89 66 53 98 87 31 77 54 6 75 51 71 5 55 94 32 7 91 74 83 22 52 23 69 39 50 76 41 62 44 57 67 16 47 36 95 27 34 3 61 97 73 4 46 93 59 35 80 20 28984 e station ISI means all reservations oftickets from ISI to a 10970 fixed destination station In case the co 30607 mpany cannot accept all orders because of thepassenger capacity limitations its 0 164 16 55 60 31 101 24 74 88 67 52 92 62 71 64 6 103 21 37 124 30 143 9 68 109 160 161 66 3 43 54 140 86 163 69 53 1 35 50 158 11 155 63 118 85 119 10 61 96 127 129 136 70 93 83 159 131 8 139 45 34 73 56 142 51 130 156 111 107 149 87 112 120 41 138 23 95 78 7 84 117 27 147 90 76 154 36 104 80 14 13 151 125 46 26 105 162 121 137 113 123 5 15 128 17 20 12 58 47 135 40 114 148 153 81 89 102 115 150 122 108 57 65 48 164 82 59 38 144 141 152 75 39 28 19 2 77 18 157 100 4 132 146 42 72 44 97 33 98 49 133 94 134 32 25 116 79 110 99 126 91 29 145 22 106 16850 rejection policy is that it either completely accept or completely rejectsingle orders from single stationsPWrite a progra 0 140 53 123 117 23 14 121 1 96 50 136 105 107 62 63 47 15 133 33 12 130 127 38 13 25 19 94 99 73 34 59 46 77 44 40 78 75 60 103 36 87 97 54 37 102 69 100 67 139 110 111 30 126 108 72 66 135 11 21 106 6 58 114 65 137 70 52 95 31 128 57 68 49 140 98 71 61 134 84 125 113 115 8 32 29 39 10 138 42 82 80 18 56 27 5 64 101 112 41 9 20 122 93 104 22 109 86 76 89 2 124 92 120 81 79 26 35 88 119 3 118 51 132 17 91 55 7 129 83 45 85 43 74 28 16 4 116 90 24 48 131 16340 m which for the given list of orders fro 1876 m singl 17993 e stations on the way from IAI to IBI determinesthe biggest possible total earning of the TransRur 0 124 19 94 81 3 42 56 9 14 111 107 45 35 15 76 82 63 102 92 83 31 24 4 100 120 65 13 85 113 26 110 77 112 70 122 41 96 33 49 44 73 89 18 2 67 54 28 53 66 39 57 97 25 75 16 116 74 8 78 46 93 37 43 108 30 84 10 109 29 106 22 68 36 105 71 27 80 55 104 11 103 115 118 59 17 12 61 114 7 79 34 119 6 87 38 117 47 72 48 51 124 20 88 123 32 91 40 50 101 58 86 95 5 21 98 52 60 23 64 62 90 69 1 99 121 20983 atania company The earning from one accepted order isthe product of the number of passengers inclu 0 194 46 122 145 116 159 107 146 74 23 62 76 55 131 30 58 152 4 170 184 73 12 14 154 99 191 183 100 160 105 81 88 93 87 161 39 25 78 67 48 45 35 158 135 8 61 98 132 106 115 143 193 63 180 5 156 119 155 70 42 179 83 37 51 171 144 84 56 2 9 192 157 136 108 91 174 80 124 13 101 140 1 21 128 129 15 151 141 54 139 52 181 109 32 123 31 66 167 11 164 169 176 34 53 150 173 85 71 65 177 24 113 153 47 112 111 89 16 103 166 142 163 133 126 22 137 94 127 92 118 138 96 7 110 28 57 64 188 36 182 49 33 44 43 121 125 117 19 59 26 29 50 95 162 6 60 3 97 149 17 38 82 134 72 120 175 186 168 18 104 102 178 147 194 114 90 148 75 10 190 79 189 69 77 172 27 86 185 40 130 41 165 20 68 187 2141 ded in the order and the 0 9 9 8 4 5 6 3 2 1 7 1312 p 0 61 45 27 14 18 22 43 13 21 33 19 15 24 55 9 28 16 30 29 20 36 52 54 2 44 3 38 35 12 6 32 8 61 49 58 41 11 40 57 39 1 42 34 47 7 51 26 56 37 60 31 5 48 59 46 50 17 4 25 10 53 23 597 rice of t 23316 heir train tickets The tota 5759 learning is the 0 9 2 6 1 8 4 7 3 5 9 25153 sum of th 12586 e 11005 ear 0 95 6 27 28 85 12 94 61 31 44 66 51 16 68 62 76 17 48 59 64 18 75 7 13 83 84 42 63 57 14 71 29 80 82 90 52 19 74 4 2 87 3 33 43 58 47 54 5 34 30 72 46 22 67 56 93 86 11 69 21 20 10 73 1 25 77 37 65 53 49 60 39 35 45 38 95 8 40 92 23 88 89 50 70 79 78 36 55 26 15 24 41 81 91 32 9 25786 nings from all accepted ordersH 2774 3InputH3The input file is divided into blocks The first line in each block conta 5029 ins three integers passengercapacity InI of the train the number of the city IBI s 0 140 33 25 10 5 135 79 21 61 46 27 113 42 7 73 28 120 100 20 47 70 66 86 133 109 38 57 60 94 138 23 64 19 11 112 26 104 128 13 129 98 83 69 123 1 36 43 117 52 24 29 72 54 2 124 14 63 84 102 92 32 134 137 95 12 130 89 96 35 71 40 4 9 68 15 34 116 39 56 59 16 114 8 82 125 44 49 30 121 62 76 139 107 45 3 77 126 103 111 87 41 81 58 85 50 132 75 55 74 67 91 136 122 18 48 140 108 106 118 93 115 78 31 51 131 127 90 65 88 80 53 99 22 6 37 119 110 105 101 97 17 11702 tat 9952 ion and the number of ticket orders from all stationsThe next lines contain the t 0 98 70 26 49 69 47 55 61 48 83 21 88 94 28 39 45 25 17 8 41 77 18 29 36 54 64 44 5 58 65 80 43 91 32 98 24 96 57 50 71 33 10 66 81 46 11 22 72 4 79 52 40 93 31 86 38 13 68 19 15 74 78 63 1 84 92 34 9 76 82 14 67 42 27 37 85 95 90 7 51 3 89 2 35 62 60 12 56 59 97 30 87 23 73 16 75 53 20 6 25779 icket orders Each ticket order consists of three integers starting stationdestination station n 31864 umber of 0 179 25 164 150 19 117 125 39 88 167 50 30 134 10 66 54 138 26 161 178 174 111 123 118 1 60 120 158 77 102 127 107 160 72 23 55 47 27 119 42 152 12 114 154 51 131 9 175 33 95 147 67 4 63 34 28 61 87 157 105 64 156 53 168 96 84 2 122 31 71 22 137 85 129 78 113 104 80 98 99 86 176 46 52 166 106 135 148 97 16 7 11 173 136 145 116 58 29 109 82 144 6 56 8 81 14 21 132 149 35 13 5 24 65 153 121 100 38 140 32 141 18 91 165 49 62 73 139 110 124 112 70 20 75 44 43 45 159 89 146 48 115 94 59 37 130 126 93 15 142 68 162 92 17 57 170 101 151 169 155 163 177 79 90 103 74 172 171 76 128 179 69 133 41 40 83 108 36 143 3 2964 passengers In one block there can be 0 96 79 10 44 53 59 31 28 8 20 60 11 41 36 51 74 94 40 21 23 12 14 80 42 33 35 52 43 66 46 16 55 62 37 87 2 45 49 96 73 34 58 4 1 84 69 75 95 9 61 26 24 48 64 78 22 68 72 81 17 67 18 32 85 15 77 54 88 86 63 5 27 19 7 82 13 38 91 93 89 70 92 56 3 30 29 47 76 65 39 83 90 50 25 71 57 6 27404 maximum 22 orders The number ofthe city IBI station 27462 will be at most 7 The block where all three numbers in the first line are equal to 17532 zerodenotes the end of the input file 0 80 78 9 48 80 66 58 38 14 25 42 30 15 49 51 26 8 3 69 47 31 61 12 76 54 45 28 56 1 41 64 70 11 46 24 36 32 35 53 29 34 18 52 7 2 62 68 16 22 59 67 4 19 75 27 63 77 74 21 65 71 57 20 50 72 23 17 10 39 5 13 55 44 33 73 6 60 37 43 40 79 10089 H3OutputH3The output file consists of lines 18482 corresponding to the blocks of the input file except the termin 0 18 7 5 11 12 6 15 14 3 1 13 2 17 4 8 18 16 9 10 25225 atingbloc 0 195 76 162 100 11 129 23 51 173 27 47 106 82 1 19 81 28 154 90 150 149 15 54 36 7 195 66 33 134 38 97 12 182 43 26 164 14 105 108 83 109 113 123 3 138 24 88 17 9 65 157 99 131 180 111 40 161 22 30 79 159 107 49 181 183 61 110 122 130 121 63 44 169 139 93 70 193 94 72 127 10 185 46 29 103 136 160 67 52 58 137 167 84 188 35 18 39 156 166 132 50 31 135 143 142 187 192 6 73 41 20 25 158 62 4 125 91 140 190 141 69 56 124 98 112 165 32 171 176 101 5 184 170 175 163 42 152 95 34 80 48 21 75 86 147 96 194 144 118 168 145 177 116 60 151 64 85 92 115 174 178 133 128 74 55 104 77 172 53 87 102 45 126 13 8 155 114 71 89 179 153 146 59 117 120 37 148 78 57 186 119 191 16 68 189 2 17372 k Each such line contains the biggest possible total earningH3ExampleH3BInput fileBPRE10 3 40 2 11 3 51 2 72 3 1010 5 43 5 102 4 90 2 52 5 80 0 0PREBOutput file 0 47 4 19 46 31 29 17 3 7 24 1 25 40 41 12 21 15 47 23 37 32 18 30 14 42 2 22 11 26 27 34 43 10 5 20 8 35 28 36 44 16 45 39 33 6 9 13 38 22289 BPRE193 0 71 24 29 54 8 10 7 13 19 28 15 52 22 4 70 5 21 30 23 27 44 12 71 65 55 64 18 68 66 11 42 25 38 58 37 53 3 34 9 46 17 47 60 51 67 49 40 56 50 35 69 16 62 26 36 20 61 63 48 59 1 57 45 43 32 39 14 33 2 41 31 6 26711 4PREBODYHTMLHTMLHEADTITLECERC 0 137 51 6 16 127 29 36 57 113 37 74 30 134 56 93 123 108 58 112 38 32 119 20 80 5 97 40 98 88 53 49 64 69 28 24 43 59 1 55 77 82 131 114 3 68 89 96 115 39 117 83 63 54 15 11 136 23 60 107 118 121 111 21 99 104 65 106 91 84 90 130 76 31 92 137 34 120 75 78 66 46 125 45 22 7 79 70 47 12 26 86 129 33 41 10 42 87 14 103 35 133 132 61 72 109 73 52 17 27 8 95 62 128 122 50 116 71 124 110 81 101 126 25 105 13 9 94 18 102 48 100 2 4 44 135 85 67 19 484 1995 Problem C Johns tripTITLEHTML version generated by Kotas Koucky 1998HEADBODYH2 0 140 94 103 14 42 74 92 131 62 75 109 13 95 98 140 20 90 116 96 93 91 45 32 85 21 29 70 15 125 25 49 107 34 113 124 40 17 5 56 81 122 87 105 80 138 117 137 61 22 64 63 33 89 83 36 73 102 110 6 129 114 11 37 134 76 31 16 39 97 52 38 1 48 57 30 19 12 54 132 66 82 106 59 35 71 128 53 115 4 2 108 8 27 26 86 101 130 44 43 55 46 78 68 9 112 123 84 100 60 72 127 135 79 119 120 121 67 10 77 118 136 65 18 111 133 99 58 88 3 50 69 47 139 51 41 126 23 28 104 24 7 32707 ALIGNCENTERACM International Collegiate Programming Contest 9 0 58 6 53 50 3 34 24 30 18 15 31 43 11 56 2 32 55 37 27 51 33 47 8 52 4 41 40 38 48 7 19 54 1 46 39 57 45 12 23 10 28 22 16 21 35 49 13 14 17 42 25 20 36 44 26 29 9 58 5 11433 596H2P ALIGN 0 144 121 107 5 76 28 9 50 48 51 82 26 38 47 30 85 3 32 68 109 105 11 24 133 114 80 124 113 83 99 123 75 69 89 15 52 106 122 94 136 44 98 19 66 16 128 58 110 78 140 22 96 6 112 119 132 17 87 79 125 62 102 46 81 137 67 61 92 144 1 115 37 43 73 71 138 141 25 49 95 53 29 84 72 103 12 10 97 74 118 63 14 8 111 18 34 41 93 45 142 88 135 70 33 59 116 42 130 134 40 57 27 65 54 100 23 20 90 86 101 139 108 35 31 39 64 4 2 21 60 104 117 56 129 120 143 126 77 91 13 7 36 127 55 131 4095 CENTERBSponsored by Micros 19709 oftBH3 ALIGNCENTERCentral European Regional ContestH3BRH2 ALI 11134 GNCENTERProblem C Johns tripH2P ALIGN 0 121 20 56 5 67 121 18 94 116 82 34 114 99 92 49 80 59 54 23 118 66 68 88 57 90 16 38 43 97 7 1 10 36 9 69 65 27 78 120 55 41 25 62 52 17 33 110 3 60 42 109 44 40 45 84 105 12 117 4 14 86 72 50 113 75 51 39 70 21 93 102 95 103 73 89 76 98 6 46 30 15 19 85 35 28 115 81 29 100 58 64 61 22 101 74 87 24 2 119 13 26 112 106 8 104 79 108 11 47 96 77 48 63 83 111 91 53 32 71 107 37 31 11353 CENTERBInput fileB tttripinttBRBOutput fileB 0 149 67 11 39 8 135 48 94 52 23 10 44 1 116 64 68 111 147 124 36 41 137 74 66 29 40 121 54 125 122 50 26 45 86 96 65 14 109 79 126 73 108 51 103 131 127 24 31 71 21 92 85 49 34 93 43 113 59 145 138 132 37 89 115 38 22 88 33 82 118 12 90 13 63 117 7 20 98 139 47 4 9 77 42 15 110 123 61 140 76 5 18 30 133 80 130 128 16 146 104 106 35 19 95 136 102 69 144 142 141 107 119 6 83 72 62 32 87 101 75 149 28 70 134 60 114 56 58 129 17 99 3 105 112 143 84 57 27 78 2 46 81 97 148 120 25 100 91 55 53 28043 tttripo 0 77 9 54 20 4 7 52 49 66 64 3 76 48 24 16 40 28 42 15 21 30 72 26 68 36 14 19 53 37 35 69 32 56 29 27 31 61 71 60 63 77 6 44 73 65 25 8 45 43 58 62 46 5 10 17 74 41 23 59 13 57 22 70 67 33 12 51 2 47 75 39 11 55 34 38 1 50 18 71 utttBRBProgram fileB tttrippastt or tttripcppttPLittle Johnny 0 82 1 8 28 34 72 21 31 81 71 51 17 67 77 39 38 54 50 53 63 74 25 58 35 55 60 7 78 16 80 40 11 70 2 52 69 48 3 44 4 36 19 42 73 33 64 15 9 76 66 22 14 37 20 56 6 13 75 46 65 30 29 41 43 59 26 45 79 57 32 49 62 10 12 27 23 18 47 24 61 68 5 82 31972 has got a new car He decided to drive around the town to visit his fri 29554 ends Johnnywanted to visit all his friends but there was many of them In 0 6 4 2 3 6 5 1 27573 each 11049 18063 st 0 94 57 6 35 46 91 38 7 74 16 59 43 3 21 4 5 32 39 58 37 25 79 31 76 28 82 26 48 73 83 54 64 63 75 15 53 49 47 11 27 68 66 87 92 9 23 19 81 62 84 33 51 42 17 67 56 13 41 8 2 14 45 29 1 86 61 70 20 22 40 36 34 77 55 78 18 94 10 69 50 90 30 65 44 85 60 89 72 24 80 93 52 71 88 12 15048 reet he had one friend He startedthinking how to make his trip as short as possible Ve 3937 ry 9797 soon he realized that the best way to do it was totravel through each street o 0 146 31 79 89 104 59 80 86 39 21 110 7 51 108 98 87 50 23 124 57 68 100 28 137 46 144 32 27 101 48 15 58 34 103 102 35 65 142 30 92 119 115 145 29 42 83 122 109 127 88 44 121 55 93 14 41 64 135 63 52 141 13 19 134 53 56 106 10 33 77 94 47 138 143 84 4 125 71 6 37 116 11 95 133 25 40 9 129 2 120 128 81 131 96 72 112 16 146 43 60 18 76 67 130 82 26 126 61 22 132 114 1 118 136 90 139 8 113 69 78 3 140 73 54 117 49 111 36 85 12 105 24 70 74 17 91 5 62 99 38 20 97 107 45 66 123 75 19394 f town only once Naturally he wanted to finish hi 4598 s trip at the same place hestarted at his parents housePThe streets in Johnnys town were named by integ 3454 er numbers fr 0 188 134 8 169 35 139 49 31 109 145 22 181 173 128 110 21 166 2 177 56 30 81 112 125 93 141 3 132 157 57 106 72 86 180 52 168 137 39 99 111 62 107 63 77 155 69 96 55 174 154 179 120 163 176 186 47 162 29 82 118 12 87 58 54 101 25 172 138 37 20 188 13 133 15 75 83 51 105 127 38 178 28 90 97 50 41 91 85 64 148 142 40 129 98 108 44 167 115 68 187 61 124 153 18 48 76 43 185 46 80 150 53 102 7 159 152 84 9 146 73 136 60 32 149 66 33 92 114 117 10 78 184 26 122 5 121 147 34 156 140 67 171 42 1 183 45 130 17 182 95 170 175 116 165 65 14 71 24 6 131 70 27 161 88 4 144 94 164 19 103 158 36 135 160 100 143 104 89 119 79 126 16 59 11 74 151 123 23 113 23866 om 1 to InI InI lt 1995 The junctionswere independently named by integer numbers from 1 to ImI ImI lt 44 No junction connects 9376 more than 44streets All junctions in the town had different 0 162 104 56 3 27 7 110 114 78 153 81 142 4 112 123 70 25 26 162 137 5 138 23 76 103 50 105 48 63 46 74 124 111 30 126 42 69 62 96 57 92 64 33 101 54 31 32 115 77 143 134 95 66 147 122 14 15 41 107 132 144 36 157 17 146 151 37 28 12 133 9 106 160 154 34 131 97 91 117 45 94 53 83 140 6 72 98 152 1 89 99 100 125 22 148 49 158 68 119 29 44 10 118 88 20 67 19 90 130 35 121 52 38 40 150 139 93 11 84 113 79 13 149 87 51 120 161 39 2 21 108 128 55 156 159 8 47 141 18 145 85 127 16 60 102 136 71 59 135 61 58 73 86 75 82 109 129 116 24 65 43 80 155 7864 numbers Each street was connecting exactly two junctionsNo two streets in 1202 the town h 27450 a 0 71 37 21 31 22 4 46 1 57 20 58 28 25 61 62 47 11 45 9 65 3 40 55 41 5 49 68 30 6 67 56 33 12 71 24 14 16 34 69 7 13 32 60 59 52 42 70 54 66 29 44 35 10 48 39 63 50 36 17 18 19 38 51 64 23 8 27 2 53 43 26 15 174 d 0 142 48 1 19 121 100 70 119 17 64 27 30 65 117 122 40 34 22 23 44 5 37 116 38 10 105 35 29 45 50 133 25 111 67 89 77 72 53 102 127 51 86 32 91 6 115 68 94 99 39 98 71 76 12 56 95 73 55 126 131 28 11 90 87 20 81 80 47 107 3 42 62 13 103 112 58 142 92 120 52 135 75 96 136 129 60 118 113 93 130 84 88 140 14 26 74 8 110 57 106 59 2 9 78 138 54 16 31 109 82 83 46 123 124 15 41 49 61 125 101 141 66 7 69 132 79 24 85 21 33 108 36 137 4 104 114 18 97 134 63 139 128 43 10595 the same 30000 number He immediate 25619 ly starte 0 42 19 11 6 3 29 28 14 34 26 16 25 40 15 17 32 10 27 4 24 21 20 13 39 2 12 42 22 33 41 36 37 5 35 31 9 30 1 7 18 8 23 38 14540 d to plan h 0 174 72 44 18 76 48 138 17 161 130 68 157 137 21 50 158 96 16 13 12 169 87 144 42 54 168 81 31 6 39 73 71 111 57 136 165 149 101 106 124 9 3 30 142 91 117 152 103 150 26 154 19 120 110 67 86 7 105 127 128 97 100 171 147 90 167 113 28 25 145 118 29 15 69 43 36 85 143 153 93 92 49 1 45 83 8 22 102 125 126 151 162 174 112 166 5 24 107 41 46 78 20 11 115 79 2 51 135 62 104 170 146 27 95 52 160 32 99 40 63 155 58 163 129 94 119 139 70 173 47 122 80 37 53 114 131 141 23 84 66 34 75 164 148 38 59 116 33 108 109 65 14 74 156 56 172 89 82 140 134 10 123 121 88 60 132 61 55 35 98 159 77 64 4 133 12862 is round trip If therewas more than one such round trip he would have chosen the one which when written down as a sequenceof street numbers is lexicographically the sm 27205 allest But Johnny was not ab 0 133 78 52 28 5 16 34 63 18 97 13 100 56 124 48 67 86 109 26 40 46 74 29 101 123 75 21 116 119 102 117 62 120 66 47 37 22 24 132 115 55 2 127 108 92 11 14 31 68 33 50 126 118 10 49 45 27 8 4 15 23 72 94 65 107 61 83 44 131 89 1 111 12 19 9 35 59 39 7 84 110 128 17 71 60 90 105 6 99 43 51 57 38 95 93 88 98 112 91 85 125 53 69 103 70 58 77 114 54 121 113 20 133 42 73 32 76 30 87 104 106 82 64 129 80 41 36 122 81 130 25 3 96 79 24743 le to find even one such roundtripPHelp Johnny and write a program which finds the desired shortest round trip If th 27588 e round trip doesnot exist 17190 the program should write a message Assume that Johnny li 0 61 33 6 27 59 32 17 8 2 50 42 20 3 60 38 22 1 29 61 36 23 25 4 55 34 35 16 5 53 56 37 51 43 30 12 48 31 40 18 49 45 10 46 44 24 14 58 47 41 7 11 54 26 28 9 52 19 13 57 15 21 39 28465 ves at the j 0 133 61 4 26 3 70 106 74 126 16 23 82 10 11 109 96 131 32 132 79 7 19 65 94 5 112 113 34 68 57 115 52 72 119 71 123 90 95 108 22 104 100 120 24 58 75 47 17 117 62 37 118 36 18 60 56 29 103 63 13 107 92 86 89 88 97 44 87 121 124 14 28 1 83 50 8 40 78 105 25 102 99 41 31 39 53 101 76 129 130 122 125 81 48 30 6 27 80 111 67 66 55 21 91 2 85 9 59 77 15 84 110 116 127 46 114 128 73 42 38 98 49 64 54 69 93 51 45 133 12 43 35 20 33 13635 unction ending the streetNo 1 with smaller 23726 number All streets in the town a 15970 re t 0 140 21 56 75 83 74 125 46 35 73 127 54 106 47 111 112 120 39 33 123 68 34 84 37 27 41 71 28 59 76 26 61 14 107 7 132 113 57 126 5 88 30 121 114 15 49 108 134 104 82 48 65 103 32 45 11 85 130 99 55 116 16 119 105 117 63 131 40 66 42 77 87 38 95 17 94 92 67 9 12 50 13 78 19 64 133 24 18 60 8 1 122 6 93 102 128 86 139 96 138 52 25 22 31 53 140 91 137 23 89 118 20 97 10 90 58 80 100 29 115 2 98 62 79 109 51 44 129 4 69 70 110 36 101 3 135 81 43 72 124 136 13192 wo way There exists 2061 a way from each street toanother street in the town The streets in the town are very narrow and there is no possibility to turn backthe 27674 car once he is 0 97 51 33 12 47 39 36 21 3 15 54 25 24 72 14 40 56 71 34 57 62 50 52 35 28 66 17 13 93 59 19 60 20 22 77 97 82 45 9 37 16 96 43 29 32 89 67 85 83 23 76 7 26 38 87 73 64 63 2 5 10 65 6 91 42 84 55 70 78 44 92 90 18 81 95 80 53 86 68 4 69 79 8 75 30 94 1 31 11 27 48 49 61 58 74 41 46 88 190 in the streetH3InputH3Input file consists of several blocks Each block descr 17788 ibes one town Each line in the block containsthree in 8343 tegers IxI IyI IzI where IxI gt 0 and IyI gt 0 are the numbers of junctions which are connecte 0 49 47 3 10 33 14 8 13 12 25 4 43 5 42 9 19 35 27 15 20 6 2 1 48 34 26 28 32 23 17 29 37 38 31 30 39 18 16 49 11 46 24 36 45 41 21 22 7 44 40 10890 d by 26285 the streetnumbe 13671 r IzI The end of the block is marked by the line 0 52 32 49 12 38 22 47 34 52 46 14 26 2 36 41 40 39 24 20 30 50 1 45 15 5 23 19 43 29 4 33 51 44 8 37 27 16 21 42 31 9 10 35 11 48 25 17 6 7 28 13 3 18 11584 contain 21823 ing IxI IyI 0 62 43 21 13 38 46 17 19 30 9 7 27 20 2 53 59 24 48 8 37 5 35 11 40 16 55 28 25 50 39 47 22 15 42 32 26 41 51 57 10 18 36 4 23 61 60 44 6 56 45 29 62 33 1 54 14 49 3 52 34 12 31 58 10528 0 At the end of t 23721 he input file 31470 there is an empty block IxI IyI 0H3Out 0 44 13 38 5 33 14 12 25 31 37 23 11 30 34 16 24 20 28 36 29 17 9 10 22 8 44 2 42 27 21 19 4 7 15 40 1 18 35 41 43 6 26 39 32 3 12252 putH3 7957 The output file consists 0 64 7 3 10 38 16 61 4 28 40 45 56 63 23 21 34 29 64 55 14 33 9 15 44 27 11 30 50 5 51 2 48 19 13 60 53 54 31 52 37 59 22 49 32 18 6 62 8 26 58 46 42 1 43 12 24 47 36 35 39 57 41 17 20 25 1127 of 2 line blocks corre 16205 sponding to the blocks of the input file 29157 The first line ofeach block contains the 0 90 38 3 49 26 17 60 75 37 74 18 5 22 64 44 82 58 90 68 51 1 23 8 55 14 84 48 66 30 67 77 6 35 70 42 63 13 16 39 81 69 19 10 87 59 33 24 4 73 80 57 29 9 27 56 47 25 61 32 15 20 12 34 36 45 85 46 31 21 79 52 2 7 50 41 65 86 28 40 11 88 76 71 83 62 89 54 53 72 78 43 30861 sequence of street numbers single members of the seq 0 140 31 8 135 48 108 67 64 63 45 92 35 22 70 133 58 77 83 132 90 26 139 123 103 115 20 87 15 134 9 104 37 2 100 42 137 1 81 97 62 44 80 89 40 29 39 7 106 11 111 74 43 94 95 68 105 140 116 19 120 17 46 13 84 82 127 126 75 53 5 79 41 131 130 118 4 34 78 85 18 56 50 30 96 88 125 129 33 107 136 47 3 16 14 86 49 114 25 65 24 61 59 99 6 73 10 117 57 119 28 52 124 93 32 23 113 76 21 109 128 91 55 71 110 122 54 98 121 138 38 27 60 12 102 36 112 101 66 69 72 51 19163 uence are separated by sp 22143 acedescribing Johnnys round trip If the round trip cannot be found the corresponding o 0 111 64 110 68 62 89 57 107 14 38 58 43 76 5 36 54 32 78 59 51 44 9 88 2 96 99 40 98 34 83 29 27 109 95 56 61 24 8 37 21 1 48 108 52 90 100 10 11 84 94 45 74 50 101 111 22 6 91 93 35 69 102 97 39 47 17 87 85 12 106 7 77 23 79 60 67 104 4 103 30 28 75 15 63 71 31 105 46 33 42 25 73 66 80 82 18 13 55 41 16 86 49 20 3 26 92 72 65 81 19 70 53 12194 utput block containsthe mess 0 92 48 59 8 17 30 72 38 18 28 19 51 65 35 11 44 16 29 61 26 34 24 21 20 15 89 75 62 54 90 45 83 84 53 2 37 31 79 77 40 88 46 66 55 71 49 73 52 7 10 39 3 41 27 9 22 5 80 60 91 47 36 23 74 12 56 50 78 25 81 57 85 70 58 43 42 69 6 68 32 87 86 92 13 82 64 67 76 4 14 1 63 33 8039 age ttRound trip does not existtt The second line of each block is emptyH3ExampleH3BInp 17705 ut fileBPRE1 2 12 3 23 1 61 2 52 3 33 1 40 01 2 12 3 21 3 32 4 40 27794 00 0PREBOutput fileBPRE1 2 3 5 4 6 Round tri 0 125 59 99 33 66 40 76 107 36 90 29 112 2 24 63 98 34 68 69 102 50 79 27 81 113 121 9 122 26 45 72 49 22 80 104 115 39 92 43 109 71 87 32 105 38 54 84 77 51 96 1 74 52 47 7 20 3 64 35 62 97 108 114 10 95 103 83 14 106 117 5 42 101 21 73 67 18 94 41 91 12 61 6 23 124 44 53 48 58 13 120 116 57 15 85 30 70 100 110 118 75 37 88 46 17 55 31 11 16 86 111 89 25 4 123 56 28 78 8 82 93 60 19 119 125 65 1131 p does not existPREBODYHTMLHTMLHE 0 46 6 17 16 37 21 26 25 3 14 1 23 11 27 12 35 38 42 30 13 36 29 20 32 7 28 5 39 19 22 10 15 45 34 46 31 9 4 24 43 41 8 18 2 40 33 44 30414 ADTITLECERC 1995 Problem G Ciph 8874 erTITLEHTML version gener 17197 ated by Kotas Koucky 1998HEADBODYH2 ALIG 0 118 3 48 85 24 18 33 5 112 56 55 34 78 26 72 40 57 81 6 27 41 87 106 36 49 35 110 44 10 70 100 52 19 20 69 66 76 67 93 7 51 23 91 25 13 104 101 50 29 68 94 63 96 37 30 9 77 21 103 14 17 111 115 83 8 95 74 73 65 60 107 15 11 97 80 109 43 2 98 16 46 58 1 90 39 102 4 89 12 22 86 59 64 42 82 116 92 61 113 32 31 71 54 99 47 105 79 84 88 75 53 62 117 38 118 45 28 114 108 24720 NCENTERACM International Collegiate Programming Contest 9596H2P ALIGNCENTERBS 11145 ponsored by MicrosoftBH3 ALIGNCENTERCentral European Regional Conte 30776 stH3BRH2 ALIGNCENTERProblem G CipherH2P ALIGNCENTERBInput fileB ttcipherinttBRBOutput fileB ttcipheroutttBRBProgram 0 133 97 131 114 25 6 96 35 68 50 11 40 54 14 128 89 92 32 49 31 111 127 109 95 100 107 33 93 126 37 83 75 129 67 65 42 20 72 108 82 48 81 30 84 73 91 63 8 120 87 15 53 7 71 74 56 105 121 77 115 116 124 55 36 79 90 94 16 44 18 27 10 59 26 29 19 98 23 46 80 9 51 12 3 133 88 28 130 17 47 119 64 43 106 69 110 52 62 57 102 122 123 76 2 113 99 104 117 78 118 132 86 5 125 34 66 38 112 101 24 4 1 41 39 85 58 70 21 103 45 60 13 22 61 14046 fileB ttcipherpastt or ttciphercppttPBob and Alice started to use a brandnew encoding scheme Surprisingly it is not 0 97 60 21 28 50 48 7 39 51 52 65 72 58 93 26 53 69 5 1 34 80 32 12 85 17 20 61 74 4 42 43 25 95 76 75 82 70 41 57 8 83 84 19 96 24 91 38 2 63 18 9 33 14 35 97 56 40 11 44 78 87 23 79 31 6 30 92 54 47 67 49 59 77 81 66 36 29 3 89 13 73 86 90 94 27 88 64 22 62 55 16 45 71 68 37 46 15 10 29503 a Publ 0 30 30 21 5 12 16 7 14 10 26 3 4 11 2 9 19 20 24 13 22 25 8 17 18 28 29 1 15 23 6 27 9951 ic Key Cryptosystem 8088 but their 0 74 39 33 36 68 37 14 18 11 61 12 64 15 24 17 46 54 51 35 50 53 13 30 5 56 44 3 47 72 9 70 31 23 49 8 45 42 20 21 40 25 34 38 4 6 62 7 26 71 43 60 69 10 28 74 65 63 22 55 58 52 73 66 2 1 16 67 59 19 29 27 57 48 41 32 6711 encoding and decoding is bas 0 100 87 34 44 91 66 12 16 49 42 25 47 54 80 59 58 14 43 72 11 29 39 86 83 57 37 77 2 30 62 71 23 85 74 56 96 38 63 92 7 5 27 13 28 65 24 97 81 99 75 1 90 35 40 18 95 15 41 51 73 67 20 3 6 9 84 10 79 89 32 100 88 36 26 61 78 70 19 52 31 17 55 68 64 50 45 33 93 4 94 60 46 8 76 69 22 98 53 82 21 48 2223 ed o 21425 n secret keys They chose the secret key at their lastmeetin 0 32 16 5 3 14 1 21 12 10 18 13 28 15 2 4 9 22 31 8 17 27 23 24 6 25 19 30 20 32 7 26 29 11 16313 g in Philadelphi 16996 a on Februar 10832 y 16th 1996 They ch 0 11 4 7 6 5 8 10 11 9 3 1 2 9105 ose as 27754 a secret 0 189 52 91 92 160 162 36 25 27 106 168 103 145 48 37 86 35 114 61 89 45 49 32 177 51 78 139 58 87 63 132 30 72 110 134 176 138 169 112 68 98 183 67 174 102 97 184 96 100 54 81 4 115 152 124 14 5 125 60 40 173 21 104 56 62 10 159 142 179 118 170 111 29 90 101 99 44 127 38 181 47 171 88 189 95 131 166 147 154 129 33 18 135 123 8 120 93 122 137 172 1 34 113 57 146 82 130 9 24 151 83 7 126 188 156 116 76 186 163 150 64 65 23 155 144 16 46 66 140 26 41 117 164 165 28 31 22 2 43 70 6 73 75 19 149 133 180 178 143 59 157 11 109 105 94 39 42 167 55 12 13 182 53 69 85 74 3 77 108 107 15 153 128 136 84 20 119 175 79 187 141 148 185 17 50 80 71 161 158 121 5277 key a sequence of InI distinct integers IaI1 IanI greater than zero and less or equal to InI The encoding is based on the following principleThe message 14083 is written down below the key so that characters in the message and numbers in the key arecorrespondingly aligned Character in the mes 0 5 1 3 4 5 2 1209 s 28789 age a 0 0