contestId
int64 0
1.01k
| index
stringclasses 57
values | name
stringlengths 2
58
| type
stringclasses 2
values | rating
int64 0
3.5k
| tags
sequencelengths 0
11
| title
stringclasses 522
values | time-limit
stringclasses 8
values | memory-limit
stringclasses 8
values | problem-description
stringlengths 0
7.15k
| input-specification
stringlengths 0
2.05k
| output-specification
stringlengths 0
1.5k
| demo-input
sequencelengths 0
7
| demo-output
sequencelengths 0
7
| note
stringlengths 0
5.24k
| points
float64 0
425k
| test_cases
listlengths 0
402
| creationTimeSeconds
int64 1.37B
1.7B
| relativeTimeSeconds
int64 8
2.15B
| programmingLanguage
stringclasses 3
values | verdict
stringclasses 14
values | testset
stringclasses 12
values | passedTestCount
int64 0
1k
| timeConsumedMillis
int64 0
15k
| memoryConsumedBytes
int64 0
805M
| code
stringlengths 3
65.5k
| prompt
stringlengths 262
8.2k
| response
stringlengths 17
65.5k
| score
float64 -1
3.99
|
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
412 | A | Poster | PROGRAMMING | 900 | [
"greedy",
"implementation"
] | null | null | The R1 company has recently bought a high rise building in the centre of Moscow for its main office. It's time to decorate the new office, and the first thing to do is to write the company's slogan above the main entrance to the building.
The slogan of the company consists of *n* characters, so the decorators hung a large banner, *n* meters wide and 1 meter high, divided into *n* equal squares. The first character of the slogan must be in the first square (the leftmost) of the poster, the second character must be in the second square, and so on.
Of course, the R1 programmers want to write the slogan on the poster themselves. To do this, they have a large (and a very heavy) ladder which was put exactly opposite the *k*-th square of the poster. To draw the *i*-th character of the slogan on the poster, you need to climb the ladder, standing in front of the *i*-th square of the poster. This action (along with climbing up and down the ladder) takes one hour for a painter. The painter is not allowed to draw characters in the adjacent squares when the ladder is in front of the *i*-th square because the uncomfortable position of the ladder may make the characters untidy. Besides, the programmers can move the ladder. In one hour, they can move the ladder either a meter to the right or a meter to the left.
Drawing characters and moving the ladder is very tiring, so the programmers want to finish the job in as little time as possible. Develop for them an optimal poster painting plan! | The first line contains two integers, *n* and *k* (1<=≤<=*k*<=≤<=*n*<=≤<=100) — the number of characters in the slogan and the initial position of the ladder, correspondingly. The next line contains the slogan as *n* characters written without spaces. Each character of the slogan is either a large English letter, or digit, or one of the characters: '.', '!', ',', '?'. | In *t* lines, print the actions the programmers need to make. In the *i*-th line print:
- "LEFT" (without the quotes), if the *i*-th action was "move the ladder to the left"; - "RIGHT" (without the quotes), if the *i*-th action was "move the ladder to the right"; - "PRINT *x*" (without the quotes), if the *i*-th action was to "go up the ladder, paint character *x*, go down the ladder".
The painting time (variable *t*) must be minimum possible. If there are multiple optimal painting plans, you can print any of them. | [
"2 2\nR1\n",
"2 1\nR1\n",
"6 4\nGO?GO!\n"
] | [
"PRINT 1\nLEFT\nPRINT R\n",
"PRINT R\nRIGHT\nPRINT 1\n",
"RIGHT\nRIGHT\nPRINT !\nLEFT\nPRINT O\nLEFT\nPRINT G\nLEFT\nPRINT ?\nLEFT\nPRINT O\nLEFT\nPRINT G\n"
] | Note that the ladder cannot be shifted by less than one meter. The ladder can only stand in front of some square of the poster. For example, you cannot shift a ladder by half a meter and position it between two squares. Then go up and paint the first character and the second character. | 500 | [
{
"input": "2 2\nR1",
"output": "PRINT 1\nLEFT\nPRINT R"
},
{
"input": "2 1\nR1",
"output": "PRINT R\nRIGHT\nPRINT 1"
},
{
"input": "6 4\nGO?GO!",
"output": "RIGHT\nRIGHT\nPRINT !\nLEFT\nPRINT O\nLEFT\nPRINT G\nLEFT\nPRINT ?\nLEFT\nPRINT O\nLEFT\nPRINT G"
},
{
"input": "7 3\nME,YOU.",
"output": "LEFT\nLEFT\nPRINT M\nRIGHT\nPRINT E\nRIGHT\nPRINT ,\nRIGHT\nPRINT Y\nRIGHT\nPRINT O\nRIGHT\nPRINT U\nRIGHT\nPRINT ."
},
{
"input": "10 1\nEK5JQMS5QN",
"output": "PRINT E\nRIGHT\nPRINT K\nRIGHT\nPRINT 5\nRIGHT\nPRINT J\nRIGHT\nPRINT Q\nRIGHT\nPRINT M\nRIGHT\nPRINT S\nRIGHT\nPRINT 5\nRIGHT\nPRINT Q\nRIGHT\nPRINT N"
},
{
"input": "85 84\n73IW80UODC8B,UR7S8WMNATV0JSRF4W0B2VV8LCAX6SGCYY8?LHDKJEO29WXQWT9.WY1VY7408S1W04GNDZPK",
"output": "RIGHT\nPRINT K\nLEFT\nPRINT P\nLEFT\nPRINT Z\nLEFT\nPRINT D\nLEFT\nPRINT N\nLEFT\nPRINT G\nLEFT\nPRINT 4\nLEFT\nPRINT 0\nLEFT\nPRINT W\nLEFT\nPRINT 1\nLEFT\nPRINT S\nLEFT\nPRINT 8\nLEFT\nPRINT 0\nLEFT\nPRINT 4\nLEFT\nPRINT 7\nLEFT\nPRINT Y\nLEFT\nPRINT V\nLEFT\nPRINT 1\nLEFT\nPRINT Y\nLEFT\nPRINT W\nLEFT\nPRINT .\nLEFT\nPRINT 9\nLEFT\nPRINT T\nLEFT\nPRINT W\nLEFT\nPRINT Q\nLEFT\nPRINT X\nLEFT\nPRINT W\nLEFT\nPRINT 9\nLEFT\nPRINT 2\nLEFT\nPRINT O\nLEFT\nPRINT E\nLEFT\nPRINT J\nLEFT\nPRINT K\nLEFT\nPRINT D\n..."
},
{
"input": "59 53\n7NWD!9PC11C8S4TQABBTJO,?CO6YGOM!W0QR94CZJBD9U1YJY23YB354,8F",
"output": "RIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nPRINT F\nLEFT\nPRINT 8\nLEFT\nPRINT ,\nLEFT\nPRINT 4\nLEFT\nPRINT 5\nLEFT\nPRINT 3\nLEFT\nPRINT B\nLEFT\nPRINT Y\nLEFT\nPRINT 3\nLEFT\nPRINT 2\nLEFT\nPRINT Y\nLEFT\nPRINT J\nLEFT\nPRINT Y\nLEFT\nPRINT 1\nLEFT\nPRINT U\nLEFT\nPRINT 9\nLEFT\nPRINT D\nLEFT\nPRINT B\nLEFT\nPRINT J\nLEFT\nPRINT Z\nLEFT\nPRINT C\nLEFT\nPRINT 4\nLEFT\nPRINT 9\nLEFT\nPRINT R\nLEFT\nPRINT Q\nLEFT\nPRINT 0\nLEFT\nPRINT W\nLEFT\nPRINT !\nLEFT\nPRINT M\nLEFT\nPRINT O\nLEFT\nPRINT G\nLEFT\nPRIN..."
},
{
"input": "100 79\nF2.58O.L4A!QX!,.,YQUE.RZW.ENQCZKUFNG?.J6FT?L59BIHKFB?,44MAHSTD8?Z.UP3N!76YW6KVI?4AKWDPP0?3HPERM3PCUR",
"output": "RIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nPRINT R\nLEFT\nPRINT U\nLEFT\nPRINT C\nLEFT\nPRINT P\nLEFT\nPRINT 3\nLEFT\nPRINT M\nLEFT\nPRINT R\nLEFT\nPRINT E\nLEFT\nPRINT P\nLEFT\nPRINT H\nLEFT\nPRINT 3\nLEFT\nPRINT ?\nLEFT\nPRINT 0\nLEFT\nPRINT P\nLEFT\nPRINT P\nLEFT\nPRINT D\nLEFT\nPRINT W\nLEFT\nPRINT K\nLEFT\nPRINT A\nLEFT\nPRINT 4\nLEFT\nPRINT ?\nLEFT\nPRINT I\nLEFT\nPRINT V\nLEFT\nPRINT K\nLEFT\nPRIN..."
},
{
"input": "1 1\n!",
"output": "PRINT !"
},
{
"input": "34 20\n.C0QPPSWQKGBSH0,VGM!N,5SX.M9Q,D1DT",
"output": "RIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nPRINT T\nLEFT\nPRINT D\nLEFT\nPRINT 1\nLEFT\nPRINT D\nLEFT\nPRINT ,\nLEFT\nPRINT Q\nLEFT\nPRINT 9\nLEFT\nPRINT M\nLEFT\nPRINT .\nLEFT\nPRINT X\nLEFT\nPRINT S\nLEFT\nPRINT 5\nLEFT\nPRINT ,\nLEFT\nPRINT N\nLEFT\nPRINT !\nLEFT\nPRINT M\nLEFT\nPRINT G\nLEFT\nPRINT V\nLEFT\nPRINT ,\nLEFT\nPRINT 0\nLEFT\nPRINT H\nLEFT\nPRINT S\nLEFT\nPRINT B\nLEFT\nPRINT G\nLEFT\nPRINT K\nLEFT\nPRINT Q\nLEFT\nPRINT W\nLEFT\nPRINT S\n..."
},
{
"input": "99 98\nR8MZTEG240LNHY33H7.2CMWM73ZK,P5R,RGOA,KYKMIOG7CMPNHV3R2KM,N374IP8HN97XVMG.PSIPS8H3AXFGK0CJ76,EVKRZ9",
"output": "RIGHT\nPRINT 9\nLEFT\nPRINT Z\nLEFT\nPRINT R\nLEFT\nPRINT K\nLEFT\nPRINT V\nLEFT\nPRINT E\nLEFT\nPRINT ,\nLEFT\nPRINT 6\nLEFT\nPRINT 7\nLEFT\nPRINT J\nLEFT\nPRINT C\nLEFT\nPRINT 0\nLEFT\nPRINT K\nLEFT\nPRINT G\nLEFT\nPRINT F\nLEFT\nPRINT X\nLEFT\nPRINT A\nLEFT\nPRINT 3\nLEFT\nPRINT H\nLEFT\nPRINT 8\nLEFT\nPRINT S\nLEFT\nPRINT P\nLEFT\nPRINT I\nLEFT\nPRINT S\nLEFT\nPRINT P\nLEFT\nPRINT .\nLEFT\nPRINT G\nLEFT\nPRINT M\nLEFT\nPRINT V\nLEFT\nPRINT X\nLEFT\nPRINT 7\nLEFT\nPRINT 9\nLEFT\nPRINT N\nLEFT\nPRINT H\n..."
},
{
"input": "98 72\n.1?7CJ!EFZHO5WUKDZV,0EE92PTAGY078WKN!!41E,Q7381U60!9C,VONEZ6!SFFNDBI86MACX0?D?9!U2UV7S,977PNDSF0HY",
"output": "RIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nPRINT Y\nLEFT\nPRINT H\nLEFT\nPRINT 0\nLEFT\nPRINT F\nLEFT\nPRINT S\nLEFT\nPRINT D\nLEFT\nPRINT N\nLEFT\nPRINT P\nLEFT\nPRINT 7\nLEFT\nPRINT 7\nLEFT\nPRINT 9\nLEFT\nPRINT ,\nLEFT\nPRINT S\nLEFT\nPRINT 7\nLEFT\nPRINT V\nLEFT\nPRINT U\nLEFT\nPRINT 2\nLEFT\nPRINT U\nLEFT\nPRINT !\nLEFT\nPRINT 9\nLEFT\nPRINT ?\nLEFT\nPRINT D\nLEFT\n..."
},
{
"input": "97 41\nGQSPZGGRZ0KWUMI79GOXP7!RR9E?Z5YO?6WUL!I7GCXRS8T,PEFQM7CZOUG8HLC7198J1?C69JD00Q!QY1AK!27I?WB?UAUIG",
"output": "LEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nPRINT G\nRIGHT\nPRINT Q\nRIGHT\nPRINT S\nRIGHT\nPRINT P\nRIGHT\nPRINT Z\nRIGHT\nPRINT G\nRIGHT\nPRINT G\nRIGHT\nPRINT R\nRIGHT\nPRINT Z\nRIGHT\nPRINT 0\nRIGHT\nPRINT K\nRIGHT\nPRINT W\nRIGHT\nPRINT U\nRIGHT\nPRINT M\nRIGHT\nPRINT I\nRIGHT\nPRINT 7\nRIGHT\nPRINT 9\nRIGHT\n..."
},
{
"input": "96 28\nZCF!PLS27YGXHK8P46H,C.A7MW90ED,4BA!T0!XKIR2GE0HD..YZ0O20O8TA7E35G5YT3L4W5ESSYBHG8.TIQENS4I.R8WE,",
"output": "LEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nPRINT Z\nRIGHT\nPRINT C\nRIGHT\nPRINT F\nRIGHT\nPRINT !\nRIGHT\nPRINT P\nRIGHT\nPRINT L\nRIGHT\nPRINT S\nRIGHT\nPRINT 2\nRIGHT\nPRINT 7\nRIGHT\nPRINT Y\nRIGHT\nPRINT G\nRIGHT\nPRINT X\nRIGHT\nPRINT H\nRIGHT\nPRINT K\nRIGHT\nPRINT 8\nRIGHT\nPRINT P\nRIGHT\nPRINT 4\nRIGHT\nPRINT 6\nRIGHT\nPRINT H\nRIGHT\nPRINT ,\nRIGHT\nPRINT C\nRIGHT\nPRINT .\nRIGH..."
},
{
"input": "15 3\n!..!?!,!,..,?!.",
"output": "LEFT\nLEFT\nPRINT !\nRIGHT\nPRINT .\nRIGHT\nPRINT .\nRIGHT\nPRINT !\nRIGHT\nPRINT ?\nRIGHT\nPRINT !\nRIGHT\nPRINT ,\nRIGHT\nPRINT !\nRIGHT\nPRINT ,\nRIGHT\nPRINT .\nRIGHT\nPRINT .\nRIGHT\nPRINT ,\nRIGHT\nPRINT ?\nRIGHT\nPRINT !\nRIGHT\nPRINT ."
},
{
"input": "93 81\nGMIBVKYLURQLWHBGTFNJZZAZNUJJTPQKCPGDMGCDTTGXOANWKTDZSIYBUPFUXGQHCMVIEQCTINRTIUSPGMVZPGWBHPIXC",
"output": "RIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nPRINT C\nLEFT\nPRINT X\nLEFT\nPRINT I\nLEFT\nPRINT P\nLEFT\nPRINT H\nLEFT\nPRINT B\nLEFT\nPRINT W\nLEFT\nPRINT G\nLEFT\nPRINT P\nLEFT\nPRINT Z\nLEFT\nPRINT V\nLEFT\nPRINT M\nLEFT\nPRINT G\nLEFT\nPRINT P\nLEFT\nPRINT S\nLEFT\nPRINT U\nLEFT\nPRINT I\nLEFT\nPRINT T\nLEFT\nPRINT R\nLEFT\nPRINT N\nLEFT\nPRINT I\nLEFT\nPRINT T\nLEFT\nPRINT C\nLEFT\nPRINT Q\nLEFT\nPRINT E\nLEFT\nPRINT I\nLEFT\nPRINT V\nLEFT\nPRINT M\nLEFT\nPRINT C..."
},
{
"input": "88 30\n5847857685475132927321580125243001071762130696139249809763381765504146602574972381323476",
"output": "LEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nPRINT 5\nRIGHT\nPRINT 8\nRIGHT\nPRINT 4\nRIGHT\nPRINT 7\nRIGHT\nPRINT 8\nRIGHT\nPRINT 5\nRIGHT\nPRINT 7\nRIGHT\nPRINT 6\nRIGHT\nPRINT 8\nRIGHT\nPRINT 5\nRIGHT\nPRINT 4\nRIGHT\nPRINT 7\nRIGHT\nPRINT 5\nRIGHT\nPRINT 1\nRIGHT\nPRINT 3\nRIGHT\nPRINT 2\nRIGHT\nPRINT 9\nRIGHT\nPRINT 2\nRIGHT\nPRINT 7\nRIGHT\nPRINT 3\nRIGHT\nPRINT 2\nRIGHT\nP..."
},
{
"input": "100 50\n5B2N,CXCWOIWH71XV!HCFEUCN3U88JDRIFRO2VHY?!N.RGH.?W14X5S.Y00RIY6YA19BPD0T,WECXYI,O2RF1U4NX9,F5AVLPOYK",
"output": "LEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nPRINT 5\nRIGHT\nPRINT B\nRIGHT\nPRINT 2\nRIGHT\nPRINT N\nRIGHT\nPRINT ,\nRIGHT\nPRINT C\nRIGHT\nPRINT X\nRIGHT\nPRINT C\nRIGHT\nPRINT W\nRIGHT\nPRINT O\nRIGHT\nPRINT I\nRIGHT\nPRINT W\nRIGHT\nPRINT H\nRIGHT\nPRINT 7\n..."
},
{
"input": "100 51\n!X85PT!WJDNS9KA6D2SJBR,U,G7M914W07EK3EAJ4XG..UHA3KOOFYJ?M0MEFDC6KNCNGKS0A!S,C02H4TSZA1U7NDBTIY?,7XZ4",
"output": "RIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nPRINT 4\nLEFT\nPRINT Z\nLEFT\nPRINT X\nLEFT\nPRINT 7\nLEFT\nPRINT ,\nLEFT\nPRINT ?\nLEFT\nPRINT Y\nLEFT\nPRINT I\nLEFT\nPRINT T\nLEFT\nPRINT B\nLEFT\nPRINT D\nLEFT\nPRI..."
},
{
"input": "100 52\n!MLPE.0K72RW9XKHR60QE?69ILFSIKYSK5AG!TA5.02VG5OMY0967G2RI.62CNK9L8G!7IG9F0XNNCGSDOTFD?I,EBP31HRERZSX",
"output": "RIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nPRINT X\nLEFT\nPRINT S\nLEFT\nPRINT Z\nLEFT\nPRINT R\nLEFT\nPRINT E\nLEFT\nPRINT R\nLEFT\nPRINT H\nLEFT\nPRINT 1\nLEFT\nPRINT 3\nLEFT\nPRINT P\nLEFT\nPRINT B\nLEFT\nPRINT E\nL..."
},
{
"input": "100 49\n86C0NR7V,BE09,7,ER715OQ3GZ,P014H4BSQ5YS?OFNDD7YWI?S?UMKIWHSBDZ4398?SSDZLTDU1L?G4QVAB53HNDS!4PYW5C!VI",
"output": "LEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nPRINT 8\nRIGHT\nPRINT 6\nRIGHT\nPRINT C\nRIGHT\nPRINT 0\nRIGHT\nPRINT N\nRIGHT\nPRINT R\nRIGHT\nPRINT 7\nRIGHT\nPRINT V\nRIGHT\nPRINT ,\nRIGHT\nPRINT B\nRIGHT\nPRINT E\nRIGHT\nPRINT 0\nRIGHT\nPRINT 9\nRIGHT\nPRINT ,\nRIGHT\n..."
},
{
"input": "100 48\nFO,IYI4AAV?4?N5PWMZX1AINZLKAUJCKMDWU4CROT?.LYWYLYU5S80,15A6VGP!V0N,O.70CP?GEA52WG59UYWU1MMMU4BERVY.!",
"output": "LEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nPRINT F\nRIGHT\nPRINT O\nRIGHT\nPRINT ,\nRIGHT\nPRINT I\nRIGHT\nPRINT Y\nRIGHT\nPRINT I\nRIGHT\nPRINT 4\nRIGHT\nPRINT A\nRIGHT\nPRINT A\nRIGHT\nPRINT V\nRIGHT\nPRINT ?\nRIGHT\nPRINT 4\nRIGHT\nPRINT ?\nRIGHT\nPRINT N\nRIGHT\nPRINT..."
},
{
"input": "100 100\nE?F,W.,,O51!!G13ZWP?YHWRT69?RQPW7,V,EM3336F1YAIKJIME1M45?LJM42?45V7221?P.DIO9FK245LXKMR4ALKPDLA5YI2Y",
"output": "PRINT Y\nLEFT\nPRINT 2\nLEFT\nPRINT I\nLEFT\nPRINT Y\nLEFT\nPRINT 5\nLEFT\nPRINT A\nLEFT\nPRINT L\nLEFT\nPRINT D\nLEFT\nPRINT P\nLEFT\nPRINT K\nLEFT\nPRINT L\nLEFT\nPRINT A\nLEFT\nPRINT 4\nLEFT\nPRINT R\nLEFT\nPRINT M\nLEFT\nPRINT K\nLEFT\nPRINT X\nLEFT\nPRINT L\nLEFT\nPRINT 5\nLEFT\nPRINT 4\nLEFT\nPRINT 2\nLEFT\nPRINT K\nLEFT\nPRINT F\nLEFT\nPRINT 9\nLEFT\nPRINT O\nLEFT\nPRINT I\nLEFT\nPRINT D\nLEFT\nPRINT .\nLEFT\nPRINT P\nLEFT\nPRINT ?\nLEFT\nPRINT 1\nLEFT\nPRINT 2\nLEFT\nPRINT 2\nLEFT\nPRINT 7\nLEFT\nP..."
},
{
"input": "100 1\nJJ0ZOX4CY,SQ9L0K!2C9TM3C6K.6R21717I37VDSXGHBMR2!J820AI75D.O7NYMT6F.AGJ8R0RDETWOACK3P6UZAUYRKMKJ!G3WF",
"output": "PRINT J\nRIGHT\nPRINT J\nRIGHT\nPRINT 0\nRIGHT\nPRINT Z\nRIGHT\nPRINT O\nRIGHT\nPRINT X\nRIGHT\nPRINT 4\nRIGHT\nPRINT C\nRIGHT\nPRINT Y\nRIGHT\nPRINT ,\nRIGHT\nPRINT S\nRIGHT\nPRINT Q\nRIGHT\nPRINT 9\nRIGHT\nPRINT L\nRIGHT\nPRINT 0\nRIGHT\nPRINT K\nRIGHT\nPRINT !\nRIGHT\nPRINT 2\nRIGHT\nPRINT C\nRIGHT\nPRINT 9\nRIGHT\nPRINT T\nRIGHT\nPRINT M\nRIGHT\nPRINT 3\nRIGHT\nPRINT C\nRIGHT\nPRINT 6\nRIGHT\nPRINT K\nRIGHT\nPRINT .\nRIGHT\nPRINT 6\nRIGHT\nPRINT R\nRIGHT\nPRINT 2\nRIGHT\nPRINT 1\nRIGHT\nPRINT 7\nRIGHT\n..."
},
{
"input": "99 50\nLQJ!7GDFJ,SKQ8J2R?I4VA0K2.NDY.AZ?7K275NA81.YK!DO,PCQCJYL6BUU30XQ300FP0,LB!5TYTRSGOB4ELZ8IBKGVDNW8?B",
"output": "RIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nPRINT B\nLEFT\nPRINT ?\nLEFT\nPRINT 8\nLEFT\nPRINT W\nLEFT\nPRINT N\nLEFT\nPRINT D\nLEFT\nPRINT V\nLEFT\nPRINT G\nLEFT\nPRINT K\nLEFT\nPRINT B\nLEFT\nPRINT I\nLEFT\nPRI..."
},
{
"input": "99 51\nD9QHZXG46IWHHLTD2E,AZO0.M40R4B1WU6F,0QNZ37NQ0ACSU6!7Z?H02AD?0?9,5N5RG6PVOWIE6YA9QBCOHVNU??YT6,29SAC",
"output": "RIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nPRINT C\nLEFT\nPRINT A\nLEFT\nPRINT S\nLEFT\nPRINT 9\nLEFT\nPRINT 2\nLEFT\nPRINT ,\nLEFT\nPRINT 6\nLEFT\nPRINT T\nLEFT\nPRINT Y\nLEFT\nPRINT ?\nLEFT\nPRINT ?\nLEFT\nPRINT U\nL..."
},
{
"input": "99 49\nOLUBX0Q3VPNSH,QCAWFVSKZA3NUURJ9PXBS3?72PMJ,27QTA7Z1N?6Q2CSJE,W0YX8XWS.W6B?K?M!PYAD30BX?8.VJCC,P8QL9",
"output": "LEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nPRINT O\nRIGHT\nPRINT L\nRIGHT\nPRINT U\nRIGHT\nPRINT B\nRIGHT\nPRINT X\nRIGHT\nPRINT 0\nRIGHT\nPRINT Q\nRIGHT\nPRINT 3\nRIGHT\nPRINT V\nRIGHT\nPRINT P\nRIGHT\nPRINT N\nRIGHT\nPRINT S\nRIGHT\nPRINT H\nRIGHT\nPRINT ,\nRIGHT\n..."
},
{
"input": "99 48\nW0GU5MNE5!JVIOO2SR5OO7RWLHDFH.HLCCX89O21SLD9!CU0MFG3RFZUFT!R0LWNVNSS.W54.67N4VAN1Q2J9NMO9Q6.UE8U6B8",
"output": "LEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nPRINT W\nRIGHT\nPRINT 0\nRIGHT\nPRINT G\nRIGHT\nPRINT U\nRIGHT\nPRINT 5\nRIGHT\nPRINT M\nRIGHT\nPRINT N\nRIGHT\nPRINT E\nRIGHT\nPRINT 5\nRIGHT\nPRINT !\nRIGHT\nPRINT J\nRIGHT\nPRINT V\nRIGHT\nPRINT I\nRIGHT\nPRINT O\nRIGHT\nPRINT..."
},
{
"input": "2 1\nOA",
"output": "PRINT O\nRIGHT\nPRINT A"
},
{
"input": "2 2\nGW",
"output": "PRINT W\nLEFT\nPRINT G"
},
{
"input": "3 1\n.VP",
"output": "PRINT .\nRIGHT\nPRINT V\nRIGHT\nPRINT P"
},
{
"input": "3 2\nUD0",
"output": "RIGHT\nPRINT 0\nLEFT\nPRINT D\nLEFT\nPRINT U"
},
{
"input": "3 3\nMYE",
"output": "PRINT E\nLEFT\nPRINT Y\nLEFT\nPRINT M"
},
{
"input": "4 1\nC5EJ",
"output": "PRINT C\nRIGHT\nPRINT 5\nRIGHT\nPRINT E\nRIGHT\nPRINT J"
},
{
"input": "4 2\n5QSW",
"output": "LEFT\nPRINT 5\nRIGHT\nPRINT Q\nRIGHT\nPRINT S\nRIGHT\nPRINT W"
},
{
"input": "4 3\n!F3D",
"output": "RIGHT\nPRINT D\nLEFT\nPRINT 3\nLEFT\nPRINT F\nLEFT\nPRINT !"
},
{
"input": "4 4\nS!?Y",
"output": "PRINT Y\nLEFT\nPRINT ?\nLEFT\nPRINT !\nLEFT\nPRINT S"
},
{
"input": "5 1\nIP4!N",
"output": "PRINT I\nRIGHT\nPRINT P\nRIGHT\nPRINT 4\nRIGHT\nPRINT !\nRIGHT\nPRINT N"
},
{
"input": "5 2\nI7??5",
"output": "LEFT\nPRINT I\nRIGHT\nPRINT 7\nRIGHT\nPRINT ?\nRIGHT\nPRINT ?\nRIGHT\nPRINT 5"
},
{
"input": "5 3\nASNUW",
"output": "RIGHT\nRIGHT\nPRINT W\nLEFT\nPRINT U\nLEFT\nPRINT N\nLEFT\nPRINT S\nLEFT\nPRINT A"
},
{
"input": "5 4\n3?,4L",
"output": "RIGHT\nPRINT L\nLEFT\nPRINT 4\nLEFT\nPRINT ,\nLEFT\nPRINT ?\nLEFT\nPRINT 3"
},
{
"input": "5 5\n30COA",
"output": "PRINT A\nLEFT\nPRINT O\nLEFT\nPRINT C\nLEFT\nPRINT 0\nLEFT\nPRINT 3"
},
{
"input": "4 2\nABCD",
"output": "LEFT\nPRINT A\nRIGHT\nPRINT B\nRIGHT\nPRINT C\nRIGHT\nPRINT D"
}
] | 1,397,838,629 | 1,229 | Python 3 | OK | TESTS | 43 | 62 | 0 | n,k=map(int,input('').split())
lozung=list(input())
if n-k<k:
for i in range(k,n):
print('RIGHT')
for i in reversed(range(0,n)):
print ('PRINT ',lozung[i])
if i!=0:print('LEFT')
else:
# print('2')
for i in reversed(range(0,k-1)):
print('LEFT')
for i in range(n):
print ('PRINT ',lozung[i])
if i!=n-1:print('RIGHT')
| Title: Poster
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The R1 company has recently bought a high rise building in the centre of Moscow for its main office. It's time to decorate the new office, and the first thing to do is to write the company's slogan above the main entrance to the building.
The slogan of the company consists of *n* characters, so the decorators hung a large banner, *n* meters wide and 1 meter high, divided into *n* equal squares. The first character of the slogan must be in the first square (the leftmost) of the poster, the second character must be in the second square, and so on.
Of course, the R1 programmers want to write the slogan on the poster themselves. To do this, they have a large (and a very heavy) ladder which was put exactly opposite the *k*-th square of the poster. To draw the *i*-th character of the slogan on the poster, you need to climb the ladder, standing in front of the *i*-th square of the poster. This action (along with climbing up and down the ladder) takes one hour for a painter. The painter is not allowed to draw characters in the adjacent squares when the ladder is in front of the *i*-th square because the uncomfortable position of the ladder may make the characters untidy. Besides, the programmers can move the ladder. In one hour, they can move the ladder either a meter to the right or a meter to the left.
Drawing characters and moving the ladder is very tiring, so the programmers want to finish the job in as little time as possible. Develop for them an optimal poster painting plan!
Input Specification:
The first line contains two integers, *n* and *k* (1<=≤<=*k*<=≤<=*n*<=≤<=100) — the number of characters in the slogan and the initial position of the ladder, correspondingly. The next line contains the slogan as *n* characters written without spaces. Each character of the slogan is either a large English letter, or digit, or one of the characters: '.', '!', ',', '?'.
Output Specification:
In *t* lines, print the actions the programmers need to make. In the *i*-th line print:
- "LEFT" (without the quotes), if the *i*-th action was "move the ladder to the left"; - "RIGHT" (without the quotes), if the *i*-th action was "move the ladder to the right"; - "PRINT *x*" (without the quotes), if the *i*-th action was to "go up the ladder, paint character *x*, go down the ladder".
The painting time (variable *t*) must be minimum possible. If there are multiple optimal painting plans, you can print any of them.
Demo Input:
['2 2\nR1\n', '2 1\nR1\n', '6 4\nGO?GO!\n']
Demo Output:
['PRINT 1\nLEFT\nPRINT R\n', 'PRINT R\nRIGHT\nPRINT 1\n', 'RIGHT\nRIGHT\nPRINT !\nLEFT\nPRINT O\nLEFT\nPRINT G\nLEFT\nPRINT ?\nLEFT\nPRINT O\nLEFT\nPRINT G\n']
Note:
Note that the ladder cannot be shifted by less than one meter. The ladder can only stand in front of some square of the poster. For example, you cannot shift a ladder by half a meter and position it between two squares. Then go up and paint the first character and the second character. | ```python
n,k=map(int,input('').split())
lozung=list(input())
if n-k<k:
for i in range(k,n):
print('RIGHT')
for i in reversed(range(0,n)):
print ('PRINT ',lozung[i])
if i!=0:print('LEFT')
else:
# print('2')
for i in reversed(range(0,k-1)):
print('LEFT')
for i in range(n):
print ('PRINT ',lozung[i])
if i!=n-1:print('RIGHT')
``` | 3 |
|
690 | C1 | Brain Network (easy) | PROGRAMMING | 1,300 | [] | null | null | One particularly well-known fact about zombies is that they move and think terribly slowly. While we still don't know why their movements are so sluggish, the problem of laggy thinking has been recently resolved. It turns out that the reason is not (as previously suspected) any kind of brain defect – it's the opposite! Independent researchers confirmed that the nervous system of a zombie is highly complicated – it consists of *n* brains (much like a cow has several stomachs). They are interconnected by brain connectors, which are veins capable of transmitting thoughts between brains. There are two important properties such a brain network should have to function properly:
1. It should be possible to exchange thoughts between any two pairs of brains (perhaps indirectly, through other brains). 1. There should be no redundant brain connectors, that is, removing any brain connector would make property 1 false.
If both properties are satisfied, we say that the nervous system is valid. Unfortunately (?), if the system is not valid, the zombie stops thinking and becomes (even more) dead. Your task is to analyze a given nervous system of a zombie and find out whether it is valid. | The first line of the input contains two space-separated integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=1000) denoting the number of brains (which are conveniently numbered from 1 to *n*) and the number of brain connectors in the nervous system, respectively. In the next *m* lines, descriptions of brain connectors follow. Every connector is given as a pair of brains *a* *b* it connects (1<=≤<=*a*,<=*b*<=≤<=*n*, *a*<=≠<=*b*). | The output consists of one line, containing either yes or no depending on whether the nervous system is valid. | [
"4 4\n1 2\n2 3\n3 1\n4 1\n",
"6 5\n1 2\n2 3\n3 4\n4 5\n3 6\n"
] | [
"no\n",
"yes\n"
] | none | 0 | [
{
"input": "4 4\n1 2\n2 3\n3 1\n4 1",
"output": "no"
},
{
"input": "6 5\n1 2\n2 3\n3 4\n4 5\n3 6",
"output": "yes"
},
{
"input": "2 1\n1 2",
"output": "yes"
},
{
"input": "3 3\n2 1\n1 3\n3 2",
"output": "no"
},
{
"input": "3 2\n1 2\n2 3",
"output": "yes"
},
{
"input": "9 8\n1 2\n2 3\n3 4\n4 1\n5 6\n6 7\n7 8\n8 9",
"output": "no"
},
{
"input": "8 7\n6 2\n1 5\n4 8\n4 7\n6 7\n8 3\n8 1",
"output": "yes"
},
{
"input": "200 5\n93 101\n199 164\n14 94\n115 61\n106 156",
"output": "no"
},
{
"input": "10 9\n6 5\n9 2\n4 7\n2 3\n7 3\n3 4\n10 6\n1 2\n5 8",
"output": "no"
},
{
"input": "10 9\n2 3\n6 8\n10 1\n1 8\n6 7\n8 7\n10 5\n7 10\n2 5",
"output": "no"
},
{
"input": "10 9\n3 2\n4 1\n6 1\n7 1\n9 2\n6 9\n5 2\n7 9\n3 7",
"output": "no"
}
] | 1,573,560,299 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 5 | 109 | 0 | n,m=map(int,input().split())
L=[]
for k in range(n):
L.append(0)
for k in range(m):
a,b=map(int,input().split())
L[a-1]+=1
L[b-1]+=1
if n!=m+1 or 0 in L:
print("no")
else:
print("yes")
| Title: Brain Network (easy)
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
One particularly well-known fact about zombies is that they move and think terribly slowly. While we still don't know why their movements are so sluggish, the problem of laggy thinking has been recently resolved. It turns out that the reason is not (as previously suspected) any kind of brain defect – it's the opposite! Independent researchers confirmed that the nervous system of a zombie is highly complicated – it consists of *n* brains (much like a cow has several stomachs). They are interconnected by brain connectors, which are veins capable of transmitting thoughts between brains. There are two important properties such a brain network should have to function properly:
1. It should be possible to exchange thoughts between any two pairs of brains (perhaps indirectly, through other brains). 1. There should be no redundant brain connectors, that is, removing any brain connector would make property 1 false.
If both properties are satisfied, we say that the nervous system is valid. Unfortunately (?), if the system is not valid, the zombie stops thinking and becomes (even more) dead. Your task is to analyze a given nervous system of a zombie and find out whether it is valid.
Input Specification:
The first line of the input contains two space-separated integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=1000) denoting the number of brains (which are conveniently numbered from 1 to *n*) and the number of brain connectors in the nervous system, respectively. In the next *m* lines, descriptions of brain connectors follow. Every connector is given as a pair of brains *a* *b* it connects (1<=≤<=*a*,<=*b*<=≤<=*n*, *a*<=≠<=*b*).
Output Specification:
The output consists of one line, containing either yes or no depending on whether the nervous system is valid.
Demo Input:
['4 4\n1 2\n2 3\n3 1\n4 1\n', '6 5\n1 2\n2 3\n3 4\n4 5\n3 6\n']
Demo Output:
['no\n', 'yes\n']
Note:
none | ```python
n,m=map(int,input().split())
L=[]
for k in range(n):
L.append(0)
for k in range(m):
a,b=map(int,input().split())
L[a-1]+=1
L[b-1]+=1
if n!=m+1 or 0 in L:
print("no")
else:
print("yes")
``` | 0 |
|
461 | A | Appleman and Toastman | PROGRAMMING | 1,200 | [
"greedy",
"sortings"
] | null | null | Appleman and Toastman play a game. Initially Appleman gives one group of *n* numbers to the Toastman, then they start to complete the following tasks:
- Each time Toastman gets a group of numbers, he sums up all the numbers and adds this sum to the score. Then he gives the group to the Appleman. - Each time Appleman gets a group consisting of a single number, he throws this group out. Each time Appleman gets a group consisting of more than one number, he splits the group into two non-empty groups (he can do it in any way) and gives each of them to Toastman.
After guys complete all the tasks they look at the score value. What is the maximum possible value of score they can get? | The first line contains a single integer *n* (1<=≤<=*n*<=≤<=3·105). The second line contains *n* integers *a*1, *a*2, ..., *a**n* (1<=≤<=*a**i*<=≤<=106) — the initial group that is given to Toastman. | Print a single integer — the largest possible score. | [
"3\n3 1 5\n",
"1\n10\n"
] | [
"26\n",
"10\n"
] | Consider the following situation in the first example. Initially Toastman gets group [3, 1, 5] and adds 9 to the score, then he give the group to Appleman. Appleman splits group [3, 1, 5] into two groups: [3, 5] and [1]. Both of them should be given to Toastman. When Toastman receives group [1], he adds 1 to score and gives the group to Appleman (he will throw it out). When Toastman receives group [3, 5], he adds 8 to the score and gives the group to Appleman. Appleman splits [3, 5] in the only possible way: [5] and [3]. Then he gives both groups to Toastman. When Toastman receives [5], he adds 5 to the score and gives the group to Appleman (he will throws it out). When Toastman receives [3], he adds 3 to the score and gives the group to Appleman (he will throws it out). Finally Toastman have added 9 + 1 + 8 + 5 + 3 = 26 to the score. This is the optimal sequence of actions. | 500 | [
{
"input": "3\n3 1 5",
"output": "26"
},
{
"input": "1\n10",
"output": "10"
},
{
"input": "10\n8 10 2 5 6 2 4 7 2 1",
"output": "376"
},
{
"input": "10\n171308 397870 724672 431255 228496 892002 542924 718337 888642 161821",
"output": "40204082"
},
{
"input": "10\n1 2 2 2 4 5 6 7 8 10",
"output": "376"
},
{
"input": "10\n161821 171308 228496 397870 431255 542924 718337 724672 888642 892002",
"output": "40204082"
},
{
"input": "1\n397870",
"output": "397870"
},
{
"input": "1\n1000000",
"output": "1000000"
},
{
"input": "10\n10 8 7 6 5 4 2 2 2 1",
"output": "376"
},
{
"input": "10\n892002 888642 724672 718337 542924 431255 397870 228496 171308 161821",
"output": "40204082"
},
{
"input": "10\n5 2 6 10 10 10 10 2 2 5",
"output": "485"
},
{
"input": "10\n431255 724672 228496 397870 397870 397870 397870 724672 888642 431255",
"output": "36742665"
},
{
"input": "10\n2 2 2 5 5 6 10 10 10 10",
"output": "485"
},
{
"input": "10\n228496 397870 397870 397870 397870 431255 431255 724672 724672 888642",
"output": "36742665"
},
{
"input": "10\n10 10 10 10 6 5 5 2 2 2",
"output": "485"
},
{
"input": "10\n888642 724672 724672 431255 431255 397870 397870 397870 397870 228496",
"output": "36742665"
},
{
"input": "10\n10 10 10 10 10 10 10 10 10 10",
"output": "640"
},
{
"input": "10\n1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000",
"output": "64000000"
},
{
"input": "1\n397870",
"output": "397870"
},
{
"input": "2\n1 2",
"output": "6"
},
{
"input": "2\n2 3",
"output": "10"
},
{
"input": "2\n1 1",
"output": "4"
}
] | 1,512,552,313 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 1 | 46 | 5,529,600 | n=int(input())
list1=[int(i) for i in input().split()]
m=0
if n==1:
print(list1[0])
elif n==2:
print(sum(list1)*2)
else:
list1.sort()
list1.reverse()
for i in range(0,n,1):
m=m+list1[i]*(n-i+1)
print(m-list1[0]) | Title: Appleman and Toastman
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Appleman and Toastman play a game. Initially Appleman gives one group of *n* numbers to the Toastman, then they start to complete the following tasks:
- Each time Toastman gets a group of numbers, he sums up all the numbers and adds this sum to the score. Then he gives the group to the Appleman. - Each time Appleman gets a group consisting of a single number, he throws this group out. Each time Appleman gets a group consisting of more than one number, he splits the group into two non-empty groups (he can do it in any way) and gives each of them to Toastman.
After guys complete all the tasks they look at the score value. What is the maximum possible value of score they can get?
Input Specification:
The first line contains a single integer *n* (1<=≤<=*n*<=≤<=3·105). The second line contains *n* integers *a*1, *a*2, ..., *a**n* (1<=≤<=*a**i*<=≤<=106) — the initial group that is given to Toastman.
Output Specification:
Print a single integer — the largest possible score.
Demo Input:
['3\n3 1 5\n', '1\n10\n']
Demo Output:
['26\n', '10\n']
Note:
Consider the following situation in the first example. Initially Toastman gets group [3, 1, 5] and adds 9 to the score, then he give the group to Appleman. Appleman splits group [3, 1, 5] into two groups: [3, 5] and [1]. Both of them should be given to Toastman. When Toastman receives group [1], he adds 1 to score and gives the group to Appleman (he will throw it out). When Toastman receives group [3, 5], he adds 8 to the score and gives the group to Appleman. Appleman splits [3, 5] in the only possible way: [5] and [3]. Then he gives both groups to Toastman. When Toastman receives [5], he adds 5 to the score and gives the group to Appleman (he will throws it out). When Toastman receives [3], he adds 3 to the score and gives the group to Appleman (he will throws it out). Finally Toastman have added 9 + 1 + 8 + 5 + 3 = 26 to the score. This is the optimal sequence of actions. | ```python
n=int(input())
list1=[int(i) for i in input().split()]
m=0
if n==1:
print(list1[0])
elif n==2:
print(sum(list1)*2)
else:
list1.sort()
list1.reverse()
for i in range(0,n,1):
m=m+list1[i]*(n-i+1)
print(m-list1[0])
``` | 0 |
|
520 | A | Pangram | PROGRAMMING | 800 | [
"implementation",
"strings"
] | null | null | A word or a sentence in some language is called a pangram if all the characters of the alphabet of this language appear in it at least once. Pangrams are often used to demonstrate fonts in printing or test the output devices.
You are given a string consisting of lowercase and uppercase Latin letters. Check whether this string is a pangram. We say that the string contains a letter of the Latin alphabet if this letter occurs in the string in uppercase or lowercase. | The first line contains a single integer *n* (1<=≤<=*n*<=≤<=100) — the number of characters in the string.
The second line contains the string. The string consists only of uppercase and lowercase Latin letters. | Output "YES", if the string is a pangram and "NO" otherwise. | [
"12\ntoosmallword\n",
"35\nTheQuickBrownFoxJumpsOverTheLazyDog\n"
] | [
"NO\n",
"YES\n"
] | none | 500 | [
{
"input": "12\ntoosmallword",
"output": "NO"
},
{
"input": "35\nTheQuickBrownFoxJumpsOverTheLazyDog",
"output": "YES"
},
{
"input": "1\na",
"output": "NO"
},
{
"input": "26\nqwertyuiopasdfghjklzxcvbnm",
"output": "YES"
},
{
"input": "26\nABCDEFGHIJKLMNOPQRSTUVWXYZ",
"output": "YES"
},
{
"input": "48\nthereisasyetinsufficientdataforameaningfulanswer",
"output": "NO"
},
{
"input": "30\nToBeOrNotToBeThatIsTheQuestion",
"output": "NO"
},
{
"input": "30\njackdawslovemybigsphinxofquarz",
"output": "NO"
},
{
"input": "31\nTHEFIVEBOXINGWIZARDSJUMPQUICKLY",
"output": "YES"
},
{
"input": "26\naaaaaaaaaaaaaaaaaaaaaaaaaa",
"output": "NO"
},
{
"input": "26\nMGJYIZDKsbhpVeNFlquRTcWoAx",
"output": "YES"
},
{
"input": "26\nfWMOhAPsbIVtyUEZrGNQXDklCJ",
"output": "YES"
},
{
"input": "26\nngPMVFSThiRCwLEuyOAbKxQzDJ",
"output": "YES"
},
{
"input": "25\nnxYTzLFwzNolAumjgcAboyxAj",
"output": "NO"
},
{
"input": "26\npRWdodGdxUESvcScPGbUoooZsC",
"output": "NO"
},
{
"input": "66\nBovdMlDzTaqKllZILFVfxbLGsRnzmtVVTmqiIDTYrossLEPlmsPrkUYtWEsGHVOnFj",
"output": "NO"
},
{
"input": "100\nmKtsiDRJypUieHIkvJaMFkwaKxcCIbBszZQLIyPpCDCjhNpAnYFngLjRpnKWpKWtGnwoSteeZXuFHWQxxxOpFlNeYTwKocsXuCoa",
"output": "YES"
},
{
"input": "26\nEoqxUbsLjPytUHMiFnvcGWZdRK",
"output": "NO"
},
{
"input": "26\nvCUFRKElZOnjmXGylWQaHDiPst",
"output": "NO"
},
{
"input": "26\nWtrPuaHdXLKJMsnvQfgOiJZBEY",
"output": "NO"
},
{
"input": "26\npGiFluRteQwkaVoPszJyNBChxM",
"output": "NO"
},
{
"input": "26\ncTUpqjPmANrdbzSFhlWIoKxgVY",
"output": "NO"
},
{
"input": "26\nLndjgvAEuICHKxPwqYztosrmBN",
"output": "NO"
},
{
"input": "26\nMdaXJrCipnOZLykfqHWEStevbU",
"output": "NO"
},
{
"input": "26\nEjDWsVxfKTqGXRnUMOLYcIzPba",
"output": "NO"
},
{
"input": "26\nxKwzRMpunYaqsdfaBgJcVElTHo",
"output": "NO"
},
{
"input": "26\nnRYUQsTwCPLZkgshfEXvBdoiMa",
"output": "NO"
},
{
"input": "26\nHNCQPfJutyAlDGsvRxZWMEbIdO",
"output": "NO"
},
{
"input": "26\nDaHJIpvKznQcmUyWsTGObXRFDe",
"output": "NO"
},
{
"input": "26\nkqvAnFAiRhzlJbtyuWedXSPcOG",
"output": "NO"
},
{
"input": "26\nhlrvgdwsIOyjcmUZXtAKEqoBpF",
"output": "NO"
},
{
"input": "26\njLfXXiMhBTcAwQVReGnpKzdsYu",
"output": "NO"
},
{
"input": "26\nlNMcVuwItjxRBGAekjhyDsQOzf",
"output": "NO"
},
{
"input": "26\nRkSwbNoYldUGtAZvpFMcxhIJFE",
"output": "NO"
},
{
"input": "26\nDqspXZJTuONYieKgaHLMBwfVSC",
"output": "NO"
},
{
"input": "26\necOyUkqNljFHRVXtIpWabGMLDz",
"output": "NO"
},
{
"input": "26\nEKAvqZhBnPmVCDRlgWJfOusxYI",
"output": "NO"
},
{
"input": "26\naLbgqeYchKdMrsZxIPFvTOWNjA",
"output": "NO"
},
{
"input": "26\nxfpBLsndiqtacOCHGmeWUjRkYz",
"output": "NO"
},
{
"input": "26\nXsbRKtqleZPNIVCdfUhyagAomJ",
"output": "NO"
},
{
"input": "26\nAmVtbrwquEthZcjKPLiyDgSoNF",
"output": "NO"
},
{
"input": "26\nOhvXDcwqAUmSEPRZGnjFLiKtNB",
"output": "NO"
},
{
"input": "26\nEKWJqCFLRmstxVBdYuinpbhaOg",
"output": "NO"
},
{
"input": "26\nmnbvcxxlkjhgfdsapoiuytrewq",
"output": "NO"
},
{
"input": "26\naAbcdefghijklmnopqrstuvwxy",
"output": "NO"
},
{
"input": "30\nABCDEFGHTYRIOPLabcdefghtyriopl",
"output": "NO"
},
{
"input": "25\nabcdefghijklmnopqrstuvwxy",
"output": "NO"
},
{
"input": "26\nabcdefhijklmnopqrstVxyzABC",
"output": "NO"
},
{
"input": "25\nqwertyuiopasdfghjklxcvbnm",
"output": "NO"
},
{
"input": "34\nTheQuickBrownFoxJumpsOverTheLayDog",
"output": "NO"
},
{
"input": "26\nabcdefghigklmnopqrstuvwxyz",
"output": "NO"
},
{
"input": "26\nabcdefghijklmnopqrstuvwxyA",
"output": "NO"
},
{
"input": "50\nqazwsxedcrfvtgbyhnujmikolQWERTYUIOASDFGHJKLZXCVBNM",
"output": "NO"
},
{
"input": "35\nTheQuickBrownFoxJumpsOverTheLasyDog",
"output": "NO"
},
{
"input": "25\nbcdefghijklmnopqrstuvwxyz",
"output": "NO"
},
{
"input": "38\nAbCdEfGhIjKlMnOpQrStVwXyZzzzzzzaaaaaaa",
"output": "NO"
},
{
"input": "26\nabcdefghiklmnopqrstvxyzABC",
"output": "NO"
},
{
"input": "26\nabcdefghijklmnopqrstuvwxzZ",
"output": "NO"
},
{
"input": "50\nabcdefghijklmnopqrstuvwxyABCDEFGHIJKLMNOPQRSTUVWXY",
"output": "NO"
}
] | 1,697,015,876 | 2,147,483,647 | Python 3 | OK | TESTS | 59 | 46 | 0 | n=int(input())
ch=input()
m=0
letter='abcdefghijklmnopqrstuvwxyz'
for i in letter:
if i not in ch.lower():
m=1
if m==1:
print("No")
else:
print("Yes")
| Title: Pangram
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A word or a sentence in some language is called a pangram if all the characters of the alphabet of this language appear in it at least once. Pangrams are often used to demonstrate fonts in printing or test the output devices.
You are given a string consisting of lowercase and uppercase Latin letters. Check whether this string is a pangram. We say that the string contains a letter of the Latin alphabet if this letter occurs in the string in uppercase or lowercase.
Input Specification:
The first line contains a single integer *n* (1<=≤<=*n*<=≤<=100) — the number of characters in the string.
The second line contains the string. The string consists only of uppercase and lowercase Latin letters.
Output Specification:
Output "YES", if the string is a pangram and "NO" otherwise.
Demo Input:
['12\ntoosmallword\n', '35\nTheQuickBrownFoxJumpsOverTheLazyDog\n']
Demo Output:
['NO\n', 'YES\n']
Note:
none | ```python
n=int(input())
ch=input()
m=0
letter='abcdefghijklmnopqrstuvwxyz'
for i in letter:
if i not in ch.lower():
m=1
if m==1:
print("No")
else:
print("Yes")
``` | 3 |
|
231 | A | Team | PROGRAMMING | 800 | [
"brute force",
"greedy"
] | null | null | One day three best friends Petya, Vasya and Tonya decided to form a team and take part in programming contests. Participants are usually offered several problems during programming contests. Long before the start the friends decided that they will implement a problem if at least two of them are sure about the solution. Otherwise, the friends won't write the problem's solution.
This contest offers *n* problems to the participants. For each problem we know, which friend is sure about the solution. Help the friends find the number of problems for which they will write a solution. | The first input line contains a single integer *n* (1<=≤<=*n*<=≤<=1000) — the number of problems in the contest. Then *n* lines contain three integers each, each integer is either 0 or 1. If the first number in the line equals 1, then Petya is sure about the problem's solution, otherwise he isn't sure. The second number shows Vasya's view on the solution, the third number shows Tonya's view. The numbers on the lines are separated by spaces. | Print a single integer — the number of problems the friends will implement on the contest. | [
"3\n1 1 0\n1 1 1\n1 0 0\n",
"2\n1 0 0\n0 1 1\n"
] | [
"2\n",
"1\n"
] | In the first sample Petya and Vasya are sure that they know how to solve the first problem and all three of them know how to solve the second problem. That means that they will write solutions for these problems. Only Petya is sure about the solution for the third problem, but that isn't enough, so the friends won't take it.
In the second sample the friends will only implement the second problem, as Vasya and Tonya are sure about the solution. | 500 | [
{
"input": "3\n1 1 0\n1 1 1\n1 0 0",
"output": "2"
},
{
"input": "2\n1 0 0\n0 1 1",
"output": "1"
},
{
"input": "1\n1 0 0",
"output": "0"
},
{
"input": "2\n1 0 0\n1 1 1",
"output": "1"
},
{
"input": "5\n1 0 0\n0 1 0\n1 1 1\n0 0 1\n0 0 0",
"output": "1"
},
{
"input": "10\n0 1 0\n0 1 0\n1 1 0\n1 0 0\n0 0 1\n0 1 1\n1 1 1\n1 1 0\n0 0 0\n0 0 0",
"output": "4"
},
{
"input": "15\n0 1 0\n1 0 0\n1 1 0\n1 1 1\n0 1 0\n0 0 1\n1 0 1\n1 0 1\n1 0 1\n0 0 0\n1 1 1\n1 1 0\n0 1 1\n1 1 0\n1 1 1",
"output": "10"
},
{
"input": "50\n0 0 0\n0 1 1\n1 1 1\n0 1 0\n1 0 1\n1 1 1\n0 0 1\n1 0 0\n1 1 0\n1 0 1\n0 1 0\n0 0 1\n1 1 0\n0 1 0\n1 1 0\n0 0 0\n1 1 1\n1 0 1\n0 0 1\n1 1 0\n1 1 1\n0 1 1\n1 1 0\n0 0 0\n0 0 0\n1 1 1\n0 0 0\n1 1 1\n0 1 1\n0 0 1\n0 0 0\n0 0 0\n1 1 0\n1 1 0\n1 0 1\n1 0 0\n1 0 1\n1 0 1\n0 1 1\n1 1 0\n1 1 0\n0 1 0\n1 0 1\n0 0 0\n0 0 0\n0 0 0\n0 0 1\n1 1 1\n0 1 1\n1 0 1",
"output": "29"
},
{
"input": "1\n1 1 1",
"output": "1"
},
{
"input": "8\n0 0 0\n0 0 1\n0 0 0\n0 1 1\n1 0 0\n1 0 1\n1 1 0\n1 1 1",
"output": "4"
},
{
"input": "16\n1 1 1\n1 1 1\n1 1 1\n1 1 1\n1 1 1\n1 1 1\n1 1 1\n1 1 1\n1 1 1\n1 1 1\n1 1 1\n1 1 1\n1 1 1\n1 1 1\n1 1 1\n1 1 1",
"output": "16"
}
] | 1,696,038,581 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 62 | 0 | exit = 0
while (exit != 1):
problemInput = input()
if problemInput >= 1 and problemInput <= 1000:
n = 0
output = 0
while (n <= problemInput):
checkSolution = input()
splitCheck = int(checkSolution.split())
print(splitCheck)
posSolutions = 0
for solCheck in range(len(splitCheck)):
posSolutions += splitCheck[solCheck]
if posSolutions > 1 and posSolutions < 4:
output += 1
n += 1
print(output)
exit = 1
else:
print("Please input integer between 1 and 1000")
| Title: Team
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
One day three best friends Petya, Vasya and Tonya decided to form a team and take part in programming contests. Participants are usually offered several problems during programming contests. Long before the start the friends decided that they will implement a problem if at least two of them are sure about the solution. Otherwise, the friends won't write the problem's solution.
This contest offers *n* problems to the participants. For each problem we know, which friend is sure about the solution. Help the friends find the number of problems for which they will write a solution.
Input Specification:
The first input line contains a single integer *n* (1<=≤<=*n*<=≤<=1000) — the number of problems in the contest. Then *n* lines contain three integers each, each integer is either 0 or 1. If the first number in the line equals 1, then Petya is sure about the problem's solution, otherwise he isn't sure. The second number shows Vasya's view on the solution, the third number shows Tonya's view. The numbers on the lines are separated by spaces.
Output Specification:
Print a single integer — the number of problems the friends will implement on the contest.
Demo Input:
['3\n1 1 0\n1 1 1\n1 0 0\n', '2\n1 0 0\n0 1 1\n']
Demo Output:
['2\n', '1\n']
Note:
In the first sample Petya and Vasya are sure that they know how to solve the first problem and all three of them know how to solve the second problem. That means that they will write solutions for these problems. Only Petya is sure about the solution for the third problem, but that isn't enough, so the friends won't take it.
In the second sample the friends will only implement the second problem, as Vasya and Tonya are sure about the solution. | ```python
exit = 0
while (exit != 1):
problemInput = input()
if problemInput >= 1 and problemInput <= 1000:
n = 0
output = 0
while (n <= problemInput):
checkSolution = input()
splitCheck = int(checkSolution.split())
print(splitCheck)
posSolutions = 0
for solCheck in range(len(splitCheck)):
posSolutions += splitCheck[solCheck]
if posSolutions > 1 and posSolutions < 4:
output += 1
n += 1
print(output)
exit = 1
else:
print("Please input integer between 1 and 1000")
``` | -1 |
|
182 | B | Vasya's Calendar | PROGRAMMING | 1,000 | [
"implementation"
] | null | null | Vasya lives in a strange world. The year has *n* months and the *i*-th month has *a**i* days. Vasya got a New Year present — the clock that shows not only the time, but also the date.
The clock's face can display any number from 1 to *d*. It is guaranteed that *a**i*<=≤<=*d* for all *i* from 1 to *n*. The clock does not keep information about the current month, so when a new day comes, it simply increases the current day number by one. The clock cannot display number *d*<=+<=1, so after day number *d* it shows day 1 (the current day counter resets). The mechanism of the clock allows you to increase the day number by one manually. When you execute this operation, day *d* is also followed by day 1.
Vasya begins each day checking the day number on the clock. If the day number on the clock does not match the actual day number in the current month, then Vasya manually increases it by one. Vasya is persistent and repeats this operation until the day number on the clock matches the actual number of the current day in the current month.
A year passed and Vasya wonders how many times he manually increased the day number by one, from the first day of the first month to the last day of the *n*-th month inclusive, considering that on the first day of the first month the clock display showed day 1. | The first line contains the single number *d* — the maximum number of the day that Vasya's clock can show (1<=≤<=*d*<=≤<=106).
The second line contains a single integer *n* — the number of months in the year (1<=≤<=*n*<=≤<=2000).
The third line contains *n* space-separated integers: *a**i* (1<=≤<=*a**i*<=≤<=*d*) — the number of days in each month in the order in which they follow, starting from the first one. | Print a single number — the number of times Vasya manually increased the day number by one throughout the last year. | [
"4\n2\n2 2\n",
"5\n3\n3 4 3\n",
"31\n12\n31 28 31 30 31 30 31 31 30 31 30 31\n"
] | [
"2\n",
"3\n",
"7\n"
] | In the first sample the situation is like this:
- Day 1. Month 1. The clock shows 1. Vasya changes nothing. - Day 2. Month 1. The clock shows 2. Vasya changes nothing. - Day 1. Month 2. The clock shows 3. Vasya manually increases the day number by 1. After that the clock shows 4. Vasya increases the day number by 1 manually. After that the clock shows 1. - Day 2. Month 2. The clock shows 2. Vasya changes nothing. | 500 | [
{
"input": "4\n2\n2 2",
"output": "2"
},
{
"input": "5\n3\n3 4 3",
"output": "3"
},
{
"input": "31\n12\n31 28 31 30 31 30 31 31 30 31 30 31",
"output": "7"
},
{
"input": "1\n1\n1",
"output": "0"
},
{
"input": "1\n2\n1 1",
"output": "0"
},
{
"input": "2\n2\n1 1",
"output": "1"
},
{
"input": "10\n2\n10 2",
"output": "0"
},
{
"input": "10\n3\n6 3 6",
"output": "11"
},
{
"input": "10\n4\n8 7 1 5",
"output": "14"
},
{
"input": "10\n5\n2 7 8 4 4",
"output": "19"
},
{
"input": "10\n6\n8 3 4 9 6 1",
"output": "20"
},
{
"input": "10\n7\n10 5 3 1 1 9 1",
"output": "31"
},
{
"input": "10\n8\n6 5 10 6 8 1 3 2",
"output": "31"
},
{
"input": "10\n9\n6 2 7 5 5 4 8 6 2",
"output": "37"
},
{
"input": "10\n10\n1 10 1 10 1 1 7 8 6 7",
"output": "45"
},
{
"input": "100\n100\n85 50 17 89 65 89 5 20 86 26 16 21 85 14 44 31 87 31 6 2 48 67 8 80 79 1 48 36 97 1 5 30 79 50 78 12 2 55 76 100 54 40 26 81 97 96 68 56 87 14 51 17 54 37 52 33 69 62 38 63 74 15 62 78 9 19 67 2 60 58 93 60 18 96 55 48 34 7 79 82 32 58 90 67 20 50 27 15 7 89 98 10 11 15 99 49 4 51 77 52",
"output": "5099"
},
{
"input": "101\n100\n19 17 15 16 28 69 41 47 75 42 19 98 16 90 92 47 21 4 98 17 27 31 90 10 14 92 62 73 56 55 6 60 62 22 78 1 3 86 18 59 92 41 21 34 67 9 92 78 77 45 50 92 57 61 11 98 89 72 57 93 100 12 61 48 5 48 38 9 65 64 77 29 18 55 94 42 10 77 43 46 7 89 8 13 5 53 80 59 23 100 30 28 29 24 85 56 10 22 24 16",
"output": "5301"
},
{
"input": "102\n100\n31 22 59 16 11 56 81 4 19 31 8 72 4 92 18 7 13 12 62 40 34 67 40 23 96 4 90 28 3 18 54 49 10 71 73 79 69 7 41 75 59 13 2 78 72 6 95 33 52 97 7 86 57 94 12 93 19 94 59 28 5 96 46 102 2 101 57 85 53 69 72 39 14 75 8 16 10 57 26 4 85 18 89 84 48 93 54 21 78 6 67 35 11 78 91 91 97 15 8 32",
"output": "5447"
},
{
"input": "103\n100\n68 38 41 54 37 11 35 26 43 97 70 3 13 11 64 83 3 95 99 16 4 13 22 27 64 20 95 38 40 87 6 17 95 67 31 24 85 33 98 24 89 101 66 38 42 5 95 18 95 13 103 85 72 73 68 93 22 59 48 59 72 46 5 41 54 32 48 69 3 76 2 26 102 44 39 58 55 85 40 16 81 78 92 63 25 97 83 2 54 16 20 63 19 8 84 34 1 22 43 93",
"output": "5358"
},
{
"input": "104\n100\n65 74 94 71 98 38 88 67 71 84 45 79 55 86 55 51 27 89 14 66 29 63 8 103 98 94 87 81 58 68 24 96 60 36 48 95 28 72 95 42 87 7 14 23 99 77 34 14 90 31 8 99 29 30 9 88 42 1 77 61 55 85 17 98 62 78 27 1 58 69 82 62 62 81 56 104 66 8 17 23 7 61 59 70 79 64 78 16 32 11 59 4 24 73 55 2 95 39 62 13",
"output": "4773"
}
] | 1,576,850,029 | 2,147,483,647 | PyPy 3 | RUNTIME_ERROR | TESTS | 0 | 404 | 2,355,200 | #234B
with open('input.txt',"r") as file:
n , k = map(int, file.readline().split(" "))
a = list(map(int, file.readline().split(" ")))
b = a.copy()
b.sort(reverse=True)
b = b[:k]
ans = []
for i in b:
ans.append(a.index(i)+ 1)
with open('output.txt',"w") as writefile:
writefile.write(str(min(b)) +'\n')
writefile.write(" ".join(str(x) for x in ans))
| Title: Vasya's Calendar
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vasya lives in a strange world. The year has *n* months and the *i*-th month has *a**i* days. Vasya got a New Year present — the clock that shows not only the time, but also the date.
The clock's face can display any number from 1 to *d*. It is guaranteed that *a**i*<=≤<=*d* for all *i* from 1 to *n*. The clock does not keep information about the current month, so when a new day comes, it simply increases the current day number by one. The clock cannot display number *d*<=+<=1, so after day number *d* it shows day 1 (the current day counter resets). The mechanism of the clock allows you to increase the day number by one manually. When you execute this operation, day *d* is also followed by day 1.
Vasya begins each day checking the day number on the clock. If the day number on the clock does not match the actual day number in the current month, then Vasya manually increases it by one. Vasya is persistent and repeats this operation until the day number on the clock matches the actual number of the current day in the current month.
A year passed and Vasya wonders how many times he manually increased the day number by one, from the first day of the first month to the last day of the *n*-th month inclusive, considering that on the first day of the first month the clock display showed day 1.
Input Specification:
The first line contains the single number *d* — the maximum number of the day that Vasya's clock can show (1<=≤<=*d*<=≤<=106).
The second line contains a single integer *n* — the number of months in the year (1<=≤<=*n*<=≤<=2000).
The third line contains *n* space-separated integers: *a**i* (1<=≤<=*a**i*<=≤<=*d*) — the number of days in each month in the order in which they follow, starting from the first one.
Output Specification:
Print a single number — the number of times Vasya manually increased the day number by one throughout the last year.
Demo Input:
['4\n2\n2 2\n', '5\n3\n3 4 3\n', '31\n12\n31 28 31 30 31 30 31 31 30 31 30 31\n']
Demo Output:
['2\n', '3\n', '7\n']
Note:
In the first sample the situation is like this:
- Day 1. Month 1. The clock shows 1. Vasya changes nothing. - Day 2. Month 1. The clock shows 2. Vasya changes nothing. - Day 1. Month 2. The clock shows 3. Vasya manually increases the day number by 1. After that the clock shows 4. Vasya increases the day number by 1 manually. After that the clock shows 1. - Day 2. Month 2. The clock shows 2. Vasya changes nothing. | ```python
#234B
with open('input.txt',"r") as file:
n , k = map(int, file.readline().split(" "))
a = list(map(int, file.readline().split(" ")))
b = a.copy()
b.sort(reverse=True)
b = b[:k]
ans = []
for i in b:
ans.append(a.index(i)+ 1)
with open('output.txt',"w") as writefile:
writefile.write(str(min(b)) +'\n')
writefile.write(" ".join(str(x) for x in ans))
``` | -1 |
|
146 | A | Lucky Ticket | PROGRAMMING | 800 | [
"implementation"
] | null | null | Petya loves lucky numbers very much. Everybody knows that lucky numbers are positive integers whose decimal record contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not.
Petya loves tickets very much. As we know, each ticket has a number that is a positive integer. Its length equals *n* (*n* is always even). Petya calls a ticket lucky if the ticket's number is a lucky number and the sum of digits in the first half (the sum of the first *n*<=/<=2 digits) equals the sum of digits in the second half (the sum of the last *n*<=/<=2 digits). Check if the given ticket is lucky. | The first line contains an even integer *n* (2<=≤<=*n*<=≤<=50) — the length of the ticket number that needs to be checked. The second line contains an integer whose length equals exactly *n* — the ticket number. The number may contain leading zeros. | On the first line print "YES" if the given ticket number is lucky. Otherwise, print "NO" (without the quotes). | [
"2\n47\n",
"4\n4738\n",
"4\n4774\n"
] | [
"NO\n",
"NO\n",
"YES\n"
] | In the first sample the sum of digits in the first half does not equal the sum of digits in the second half (4 ≠ 7).
In the second sample the ticket number is not the lucky number. | 500 | [
{
"input": "2\n47",
"output": "NO"
},
{
"input": "4\n4738",
"output": "NO"
},
{
"input": "4\n4774",
"output": "YES"
},
{
"input": "4\n4570",
"output": "NO"
},
{
"input": "6\n477477",
"output": "YES"
},
{
"input": "6\n777777",
"output": "YES"
},
{
"input": "20\n44444444444444444444",
"output": "YES"
},
{
"input": "2\n44",
"output": "YES"
},
{
"input": "10\n4745474547",
"output": "NO"
},
{
"input": "14\n77770004444444",
"output": "NO"
},
{
"input": "10\n4747777744",
"output": "YES"
},
{
"input": "10\n1234567890",
"output": "NO"
},
{
"input": "50\n44444444444444444444444444444444444444444444444444",
"output": "YES"
},
{
"input": "50\n44444444444444444444444444444444444444444444444447",
"output": "NO"
},
{
"input": "50\n74444444444444444444444444444444444444444444444444",
"output": "NO"
},
{
"input": "50\n07777777777777777777777777777777777777777777777770",
"output": "NO"
},
{
"input": "50\n77777777777777777777777777777777777777777777777777",
"output": "YES"
},
{
"input": "50\n44747747774474747747747447777447774747447477444474",
"output": "YES"
},
{
"input": "48\n447474444777444474747747744774447444747474774474",
"output": "YES"
},
{
"input": "32\n74474474777444474444747774474774",
"output": "YES"
},
{
"input": "40\n4747777444447747777447447747447474774777",
"output": "YES"
},
{
"input": "10\n4477477444",
"output": "YES"
},
{
"input": "18\n447747474447744747",
"output": "YES"
},
{
"input": "26\n44747744444774744774474447",
"output": "YES"
},
{
"input": "50\n44707747774474747747747447777447774747447477444474",
"output": "NO"
},
{
"input": "40\n4747777444447737777447447747447474774777",
"output": "NO"
},
{
"input": "36\n764477744747444444447747747474744444",
"output": "NO"
},
{
"input": "22\n4477407474777477744447",
"output": "NO"
},
{
"input": "32\n74274474777444474444747774474774",
"output": "NO"
},
{
"input": "16\n4744447974444747",
"output": "NO"
},
{
"input": "2\n11",
"output": "NO"
},
{
"input": "2\n22",
"output": "NO"
},
{
"input": "2\n33",
"output": "NO"
},
{
"input": "2\n74",
"output": "NO"
},
{
"input": "2\n55",
"output": "NO"
},
{
"input": "2\n66",
"output": "NO"
},
{
"input": "2\n77",
"output": "YES"
},
{
"input": "2\n88",
"output": "NO"
},
{
"input": "2\n99",
"output": "NO"
},
{
"input": "4\n4004",
"output": "NO"
},
{
"input": "14\n00077774444444",
"output": "NO"
},
{
"input": "6\n004444",
"output": "NO"
},
{
"input": "4\n0044",
"output": "NO"
},
{
"input": "14\n77771114444444",
"output": "NO"
},
{
"input": "14\n44444447777000",
"output": "NO"
},
{
"input": "6\n004774",
"output": "NO"
}
] | 1,568,028,194 | 2,147,483,647 | Python 3 | OK | TESTS | 46 | 218 | 0 | import sys
n = int(input())
s = input()
i = 0
for ch in s:
if(ch != '4' and ch != '7'):
print('NO')
sys.exit(0)
n = int(n/2)
if(sum(map(int,s[:n])) == sum(map(int, s[-n:]))):
print("YES")
else:
print('NO')
| Title: Lucky Ticket
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Petya loves lucky numbers very much. Everybody knows that lucky numbers are positive integers whose decimal record contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not.
Petya loves tickets very much. As we know, each ticket has a number that is a positive integer. Its length equals *n* (*n* is always even). Petya calls a ticket lucky if the ticket's number is a lucky number and the sum of digits in the first half (the sum of the first *n*<=/<=2 digits) equals the sum of digits in the second half (the sum of the last *n*<=/<=2 digits). Check if the given ticket is lucky.
Input Specification:
The first line contains an even integer *n* (2<=≤<=*n*<=≤<=50) — the length of the ticket number that needs to be checked. The second line contains an integer whose length equals exactly *n* — the ticket number. The number may contain leading zeros.
Output Specification:
On the first line print "YES" if the given ticket number is lucky. Otherwise, print "NO" (without the quotes).
Demo Input:
['2\n47\n', '4\n4738\n', '4\n4774\n']
Demo Output:
['NO\n', 'NO\n', 'YES\n']
Note:
In the first sample the sum of digits in the first half does not equal the sum of digits in the second half (4 ≠ 7).
In the second sample the ticket number is not the lucky number. | ```python
import sys
n = int(input())
s = input()
i = 0
for ch in s:
if(ch != '4' and ch != '7'):
print('NO')
sys.exit(0)
n = int(n/2)
if(sum(map(int,s[:n])) == sum(map(int, s[-n:]))):
print("YES")
else:
print('NO')
``` | 3 |
|
275 | A | Lights Out | PROGRAMMING | 900 | [
"implementation"
] | null | null | Lenny is playing a game on a 3<=×<=3 grid of lights. In the beginning of the game all lights are switched on. Pressing any of the lights will toggle it and all side-adjacent lights. The goal of the game is to switch all the lights off. We consider the toggling as follows: if the light was switched on then it will be switched off, if it was switched off then it will be switched on.
Lenny has spent some time playing with the grid and by now he has pressed each light a certain number of times. Given the number of times each light is pressed, you have to print the current state of each light. | The input consists of three rows. Each row contains three integers each between 0 to 100 inclusive. The *j*-th number in the *i*-th row is the number of times the *j*-th light of the *i*-th row of the grid is pressed. | Print three lines, each containing three characters. The *j*-th character of the *i*-th line is "1" if and only if the corresponding light is switched on, otherwise it's "0". | [
"1 0 0\n0 0 0\n0 0 1\n",
"1 0 1\n8 8 8\n2 0 3\n"
] | [
"001\n010\n100\n",
"010\n011\n100\n"
] | none | 500 | [
{
"input": "1 0 0\n0 0 0\n0 0 1",
"output": "001\n010\n100"
},
{
"input": "1 0 1\n8 8 8\n2 0 3",
"output": "010\n011\n100"
},
{
"input": "13 85 77\n25 50 45\n65 79 9",
"output": "000\n010\n000"
},
{
"input": "96 95 5\n8 84 74\n67 31 61",
"output": "011\n011\n101"
},
{
"input": "24 54 37\n60 63 6\n1 84 26",
"output": "110\n101\n011"
},
{
"input": "23 10 40\n15 6 40\n92 80 77",
"output": "101\n100\n000"
},
{
"input": "62 74 80\n95 74 93\n2 47 95",
"output": "010\n001\n110"
},
{
"input": "80 83 48\n26 0 66\n47 76 37",
"output": "000\n000\n010"
},
{
"input": "32 15 65\n7 54 36\n5 51 3",
"output": "111\n101\n001"
},
{
"input": "22 97 12\n71 8 24\n100 21 64",
"output": "100\n001\n100"
},
{
"input": "46 37 13\n87 0 50\n90 8 55",
"output": "111\n011\n000"
},
{
"input": "57 43 58\n20 82 83\n66 16 52",
"output": "111\n010\n110"
},
{
"input": "45 56 93\n47 51 59\n18 51 63",
"output": "101\n011\n100"
},
{
"input": "47 66 67\n14 1 37\n27 81 69",
"output": "001\n001\n110"
},
{
"input": "26 69 69\n85 18 23\n14 22 74",
"output": "110\n001\n010"
},
{
"input": "10 70 65\n94 27 25\n74 66 30",
"output": "111\n010\n100"
},
{
"input": "97 1 74\n15 99 1\n88 68 86",
"output": "001\n011\n000"
},
{
"input": "36 48 42\n45 41 66\n26 64 1",
"output": "001\n111\n010"
},
{
"input": "52 81 97\n29 77 71\n66 11 2",
"output": "100\n100\n111"
},
{
"input": "18 66 33\n19 49 49\n48 46 26",
"output": "011\n100\n000"
},
{
"input": "68 79 52\n51 39 100\n29 14 26",
"output": "110\n000\n111"
},
{
"input": "91 69 77\n91 26 64\n91 88 57",
"output": "001\n011\n110"
},
{
"input": "16 69 64\n48 21 80\n81 51 51",
"output": "010\n101\n111"
},
{
"input": "96 14 2\n100 18 12\n65 34 89",
"output": "111\n010\n010"
},
{
"input": "93 95 90\n8 59 42\n53 13 19",
"output": "100\n001\n111"
},
{
"input": "71 84 18\n100 19 67\n9 76 15",
"output": "010\n010\n001"
},
{
"input": "38 93 85\n21 88 64\n4 96 25",
"output": "111\n011\n000"
},
{
"input": "75 20 20\n60 5 78\n77 4 69",
"output": "011\n001\n000"
},
{
"input": "65 70 96\n19 6 83\n33 37 82",
"output": "100\n000\n011"
},
{
"input": "11 13 60\n17 13 46\n42 21 39",
"output": "000\n011\n101"
},
{
"input": "0 0 0\n0 0 0\n0 0 0",
"output": "111\n111\n111"
},
{
"input": "0 0 0\n0 1 0\n0 0 0",
"output": "101\n000\n101"
},
{
"input": "0 0 0\n0 0 0\n0 0 1",
"output": "111\n110\n100"
}
] | 1,642,180,712 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 0 | 46 | 512,000 | a = []
res = []
for i in range(3):
b = list(map(int, input().split()))
a.append(b)
temp = [0]*3
res.append(temp)
for i in range(3):
for j in range(3):
number_of_times_toggled = 0
number_of_times_toggled += a[i][j]
if j>0:
number_of_times_toggled += a[i][j-1]
if j<2:
number_of_times_toggled += a[i][j+1]
if i > 0:
number_of_times_toggled += a[i-1][j]
if i < 2:
number_of_times_toggled += a[i+1][j]
if number_of_times_toggled%2 == 0:
res[i][j] = 1
else:
res[i][j] = 0
for arr in res:
print(*arr) | Title: Lights Out
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Lenny is playing a game on a 3<=×<=3 grid of lights. In the beginning of the game all lights are switched on. Pressing any of the lights will toggle it and all side-adjacent lights. The goal of the game is to switch all the lights off. We consider the toggling as follows: if the light was switched on then it will be switched off, if it was switched off then it will be switched on.
Lenny has spent some time playing with the grid and by now he has pressed each light a certain number of times. Given the number of times each light is pressed, you have to print the current state of each light.
Input Specification:
The input consists of three rows. Each row contains three integers each between 0 to 100 inclusive. The *j*-th number in the *i*-th row is the number of times the *j*-th light of the *i*-th row of the grid is pressed.
Output Specification:
Print three lines, each containing three characters. The *j*-th character of the *i*-th line is "1" if and only if the corresponding light is switched on, otherwise it's "0".
Demo Input:
['1 0 0\n0 0 0\n0 0 1\n', '1 0 1\n8 8 8\n2 0 3\n']
Demo Output:
['001\n010\n100\n', '010\n011\n100\n']
Note:
none | ```python
a = []
res = []
for i in range(3):
b = list(map(int, input().split()))
a.append(b)
temp = [0]*3
res.append(temp)
for i in range(3):
for j in range(3):
number_of_times_toggled = 0
number_of_times_toggled += a[i][j]
if j>0:
number_of_times_toggled += a[i][j-1]
if j<2:
number_of_times_toggled += a[i][j+1]
if i > 0:
number_of_times_toggled += a[i-1][j]
if i < 2:
number_of_times_toggled += a[i+1][j]
if number_of_times_toggled%2 == 0:
res[i][j] = 1
else:
res[i][j] = 0
for arr in res:
print(*arr)
``` | 0 |
|
266 | B | Queue at the School | PROGRAMMING | 800 | [
"constructive algorithms",
"graph matchings",
"implementation",
"shortest paths"
] | null | null | During the break the schoolchildren, boys and girls, formed a queue of *n* people in the canteen. Initially the children stood in the order they entered the canteen. However, after a while the boys started feeling awkward for standing in front of the girls in the queue and they started letting the girls move forward each second.
Let's describe the process more precisely. Let's say that the positions in the queue are sequentially numbered by integers from 1 to *n*, at that the person in the position number 1 is served first. Then, if at time *x* a boy stands on the *i*-th position and a girl stands on the (*i*<=+<=1)-th position, then at time *x*<=+<=1 the *i*-th position will have a girl and the (*i*<=+<=1)-th position will have a boy. The time is given in seconds.
You've got the initial position of the children, at the initial moment of time. Determine the way the queue is going to look after *t* seconds. | The first line contains two integers *n* and *t* (1<=≤<=*n*,<=*t*<=≤<=50), which represent the number of children in the queue and the time after which the queue will transform into the arrangement you need to find.
The next line contains string *s*, which represents the schoolchildren's initial arrangement. If the *i*-th position in the queue contains a boy, then the *i*-th character of string *s* equals "B", otherwise the *i*-th character equals "G". | Print string *a*, which describes the arrangement after *t* seconds. If the *i*-th position has a boy after the needed time, then the *i*-th character *a* must equal "B", otherwise it must equal "G". | [
"5 1\nBGGBG\n",
"5 2\nBGGBG\n",
"4 1\nGGGB\n"
] | [
"GBGGB\n",
"GGBGB\n",
"GGGB\n"
] | none | 500 | [
{
"input": "5 1\nBGGBG",
"output": "GBGGB"
},
{
"input": "5 2\nBGGBG",
"output": "GGBGB"
},
{
"input": "4 1\nGGGB",
"output": "GGGB"
},
{
"input": "2 1\nBB",
"output": "BB"
},
{
"input": "2 1\nBG",
"output": "GB"
},
{
"input": "6 2\nBBGBBG",
"output": "GBBGBB"
},
{
"input": "8 3\nBBGBGBGB",
"output": "GGBGBBBB"
},
{
"input": "10 3\nBBGBBBBBBG",
"output": "GBBBBBGBBB"
},
{
"input": "22 7\nGBGGBGGGGGBBBGGBGBGBBB",
"output": "GGGGGGGGBGGBGGBBBBBBBB"
},
{
"input": "50 4\nGBBGBBBGGGGGBBGGBBBBGGGBBBGBBBGGBGGBGBBBGGBGGBGGBG",
"output": "GGBGBGBGBGBGGGBBGBGBGBGBBBGBGBGBGBGBGBGBGBGBGGBGBB"
},
{
"input": "50 8\nGGGGBGGBGGGBGBBBGGGGGGGGBBGBGBGBBGGBGGBGGGGGGGGBBG",
"output": "GGGGGGGGGGGGBGGBGBGBGBGBGGGGGGBGBGBGBGBGBGGBGGBGBB"
},
{
"input": "50 30\nBGGGGGGBGGBGBGGGGBGBBGBBBGGBBBGBGBGGGGGBGBBGBGBGGG",
"output": "GGGGGGGGGGGGGGGGGGGGGGGGGGGGGGBBBBBBBBBBBBBBBBBBBB"
},
{
"input": "20 20\nBBGGBGGGGBBBGBBGGGBB",
"output": "GGGGGGGGGGBBBBBBBBBB"
},
{
"input": "27 6\nGBGBGBGGGGGGBGGBGGBBGBBBGBB",
"output": "GGGGGGGBGBGBGGGGGBGBBBBBBBB"
},
{
"input": "46 11\nBGGGGGBGBGGBGGGBBGBBGBBGGBBGBBGBGGGGGGGBGBGBGB",
"output": "GGGGGGGGGGGBGGGGGBBGBGBGBGBGBGBGBGBGBGBGBBBBBB"
},
{
"input": "50 6\nBGGBBBBGGBBBBBBGGBGBGBBBBGBBBBBBGBBBBBBBBBBBBBBBBB",
"output": "GGGGBBBBBGBGBGBGBBBGBBBBBBGBBBBBBBBBBBBBBBBBBBBBBB"
},
{
"input": "50 10\nBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB",
"output": "BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB"
},
{
"input": "50 8\nGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGG",
"output": "GGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGG"
},
{
"input": "50 10\nBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBGB",
"output": "BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBGBBBBBBBBBBB"
},
{
"input": "50 13\nGGGBGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGG",
"output": "GGGGGGGGGGGGGGGGBGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGG"
},
{
"input": "1 1\nB",
"output": "B"
},
{
"input": "1 1\nG",
"output": "G"
},
{
"input": "1 50\nB",
"output": "B"
},
{
"input": "1 50\nG",
"output": "G"
},
{
"input": "50 50\nBBBBBBBBGGBBBBBBGBBBBBBBBBBBGBBBBBBBBBBBBBBGBBBBBB",
"output": "GGGGGBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB"
},
{
"input": "50 50\nGGBBGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGBBGGGGGGBG",
"output": "GGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGBBBBB"
},
{
"input": "6 3\nGGBBBG",
"output": "GGGBBB"
},
{
"input": "26 3\nGBBGBBBBBGGGBGBGGGBGBGGBBG",
"output": "GGBBBBGBGBGBGGGBGBGGGBGBBB"
},
{
"input": "46 3\nGGBBGGGGBBGBGBBBBBGGGBGGGBBGGGBBBGGBGGBBBGBGBB",
"output": "GGGGBGBGGGBBBBBGBGBGBGGGBGGBGBGBGBGBGBGBGBBBBB"
},
{
"input": "44 8\nBGBBBBBBBBBGGBBGBGBGGBBBBBGBBGBBBBBBBBBGBBGB",
"output": "GBBGBGBGBGBGBGBBBBGBBGBBBBBBBBBGBBGBBBBBBBBB"
},
{
"input": "20 20\nBBGGBGGGGBBBGBBGGGBB",
"output": "GGGGGGGGGGBBBBBBBBBB"
},
{
"input": "30 25\nBGGBBGBGGBGBGBBGBGGGGBGBGGBBBB",
"output": "GGGGGGGGGGGGGGGBBBBBBBBBBBBBBB"
},
{
"input": "17 42\nBBGBGBGGGGGGBBGGG",
"output": "GGGGGGGGGGGBBBBBB"
},
{
"input": "30 50\nBGGBBGGGGGGGGBBGGGBBGGBBBGBBGG",
"output": "GGGGGGGGGGGGGGGGGGBBBBBBBBBBBB"
},
{
"input": "31 33\nBBGGBBGGBGBBBBGGBGBBBGBGGBBGBBB",
"output": "GGGGGGGGGGGGBBBBBBBBBBBBBBBBBBB"
},
{
"input": "2 2\nBG",
"output": "GB"
},
{
"input": "8 8\nGGGBGGBB",
"output": "GGGGGBBB"
},
{
"input": "34 34\nBGGBBBBGGBBGBGGGGGGBBGGGGGBGGBGGGB",
"output": "GGGGGGGGGGGGGGGGGGGGGBBBBBBBBBBBBB"
},
{
"input": "34 20\nBBBBGBGGGBGGGBGBGGBBBBGGBBGGGBGBBG",
"output": "GGGGGGGGGGGGGGGGGBBBBBBBBBBBBBBBBB"
},
{
"input": "50 50\nBBGBBBBBBBBBBBBGBBBGBBBBBBBGBBBBBBGBBBGBBGBBGBBBGG",
"output": "GGGGGGGGGGBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB"
},
{
"input": "10 10\nGGGGGGGGGG",
"output": "GGGGGGGGGG"
},
{
"input": "10 10\nBBBBBBBBBB",
"output": "BBBBBBBBBB"
},
{
"input": "10 10\nBGBGBGBGBG",
"output": "GGGGGBBBBB"
},
{
"input": "1 1\nB",
"output": "B"
}
] | 1,698,452,541 | 2,147,483,647 | Python 3 | OK | TESTS | 44 | 92 | 0 | q, r = map(int, input().split())
t1 = input()
t = []
for o in t1:
t.append(o)
for j in range(r):
i = 0
while i < len(t)-1:
if t[i] == 'B' and t[i + 1] == 'G':
t[i], t[i + 1] = t[i + 1], t[i]
i += 2
else:
i += 1
t1 = ''.join(t)
print(t1)
| Title: Queue at the School
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
During the break the schoolchildren, boys and girls, formed a queue of *n* people in the canteen. Initially the children stood in the order they entered the canteen. However, after a while the boys started feeling awkward for standing in front of the girls in the queue and they started letting the girls move forward each second.
Let's describe the process more precisely. Let's say that the positions in the queue are sequentially numbered by integers from 1 to *n*, at that the person in the position number 1 is served first. Then, if at time *x* a boy stands on the *i*-th position and a girl stands on the (*i*<=+<=1)-th position, then at time *x*<=+<=1 the *i*-th position will have a girl and the (*i*<=+<=1)-th position will have a boy. The time is given in seconds.
You've got the initial position of the children, at the initial moment of time. Determine the way the queue is going to look after *t* seconds.
Input Specification:
The first line contains two integers *n* and *t* (1<=≤<=*n*,<=*t*<=≤<=50), which represent the number of children in the queue and the time after which the queue will transform into the arrangement you need to find.
The next line contains string *s*, which represents the schoolchildren's initial arrangement. If the *i*-th position in the queue contains a boy, then the *i*-th character of string *s* equals "B", otherwise the *i*-th character equals "G".
Output Specification:
Print string *a*, which describes the arrangement after *t* seconds. If the *i*-th position has a boy after the needed time, then the *i*-th character *a* must equal "B", otherwise it must equal "G".
Demo Input:
['5 1\nBGGBG\n', '5 2\nBGGBG\n', '4 1\nGGGB\n']
Demo Output:
['GBGGB\n', 'GGBGB\n', 'GGGB\n']
Note:
none | ```python
q, r = map(int, input().split())
t1 = input()
t = []
for o in t1:
t.append(o)
for j in range(r):
i = 0
while i < len(t)-1:
if t[i] == 'B' and t[i + 1] == 'G':
t[i], t[i + 1] = t[i + 1], t[i]
i += 2
else:
i += 1
t1 = ''.join(t)
print(t1)
``` | 3 |
|
1 | B | Spreadsheet | PROGRAMMING | 1,600 | [
"implementation",
"math"
] | B. Spreadsheets | 10 | 64 | In the popular spreadsheets systems (for example, in Excel) the following numeration of columns is used. The first column has number A, the second — number B, etc. till column 26 that is marked by Z. Then there are two-letter numbers: column 27 has number AA, 28 — AB, column 52 is marked by AZ. After ZZ there follow three-letter numbers, etc.
The rows are marked by integer numbers starting with 1. The cell name is the concatenation of the column and the row numbers. For example, BC23 is the name for the cell that is in column 55, row 23.
Sometimes another numeration system is used: RXCY, where X and Y are integer numbers, showing the column and the row numbers respectfully. For instance, R23C55 is the cell from the previous example.
Your task is to write a program that reads the given sequence of cell coordinates and produce each item written according to the rules of another numeration system. | The first line of the input contains integer number *n* (1<=≤<=*n*<=≤<=105), the number of coordinates in the test. Then there follow *n* lines, each of them contains coordinates. All the coordinates are correct, there are no cells with the column and/or the row numbers larger than 106 . | Write *n* lines, each line should contain a cell coordinates in the other numeration system. | [
"2\nR23C55\nBC23\n"
] | [
"BC23\nR23C55\n"
] | none | 0 | [
{
"input": "2\nR23C55\nBC23",
"output": "BC23\nR23C55"
},
{
"input": "1\nA1",
"output": "R1C1"
},
{
"input": "5\nR8C3\nD1\nR7C2\nR8C9\nR8C9",
"output": "C8\nR1C4\nB7\nI8\nI8"
},
{
"input": "4\nR4C25\nR90C35\nAP55\nX83",
"output": "Y4\nAI90\nR55C42\nR83C24"
},
{
"input": "10\nR50C12\nR23C47\nY96\nR44C13\nR19C21\nR95C73\nBK12\nR51C74\nAY34\nR63C25",
"output": "L50\nAU23\nR96C25\nM44\nU19\nBU95\nR12C63\nBV51\nR34C51\nY63"
}
] | 1,682,847,065 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 5 | 92 | 0 | # Hydro submission #644e355674221a4e24c95e98@1682847063427
def transform_string1(s):
r = ''
c = ''
i = 1
while s[i].isdigit():
r += s[i]
i += 1
i += 1
while i < len(s) and s[i].isdigit():
c += s[i]
i += 1
c = int(c)
res = ''
stack = []
while c:
if c % 26:
stack.append(chr(c % 26 + 64))
elif c == 26:
stack.append('Z')
break
else:
stack.append('Z')
c //= 26
while stack:
res += stack.pop()
res += r
return res
def transform_string2(s):
stack = []
i = 0
while s[i].isdigit() is False:
stack.append(s[i])
i += 1
r = s[i:]
c = 0
for j in range(len(stack)):
c += (ord(stack[j]) - 64) * (26 ** (len(stack) - j - 1))
res = 'R' + r + 'C' + str(c)
return res
n = int(input())
stack = []
for i in range(n):
s = input()
if not s[1].isdigit():
print(transform_string2(s))
else:
sign = 1
i = 2
while sign and i < len(s):
if not s[i].isdigit():
sign -= 1
i += 1
if not sign:
print(transform_string1(s))
else:
print(transform_string2(s)) | Title: Spreadsheet
Time Limit: 10 seconds
Memory Limit: 64 megabytes
Problem Description:
In the popular spreadsheets systems (for example, in Excel) the following numeration of columns is used. The first column has number A, the second — number B, etc. till column 26 that is marked by Z. Then there are two-letter numbers: column 27 has number AA, 28 — AB, column 52 is marked by AZ. After ZZ there follow three-letter numbers, etc.
The rows are marked by integer numbers starting with 1. The cell name is the concatenation of the column and the row numbers. For example, BC23 is the name for the cell that is in column 55, row 23.
Sometimes another numeration system is used: RXCY, where X and Y are integer numbers, showing the column and the row numbers respectfully. For instance, R23C55 is the cell from the previous example.
Your task is to write a program that reads the given sequence of cell coordinates and produce each item written according to the rules of another numeration system.
Input Specification:
The first line of the input contains integer number *n* (1<=≤<=*n*<=≤<=105), the number of coordinates in the test. Then there follow *n* lines, each of them contains coordinates. All the coordinates are correct, there are no cells with the column and/or the row numbers larger than 106 .
Output Specification:
Write *n* lines, each line should contain a cell coordinates in the other numeration system.
Demo Input:
['2\nR23C55\nBC23\n']
Demo Output:
['BC23\nR23C55\n']
Note:
none | ```python
# Hydro submission #644e355674221a4e24c95e98@1682847063427
def transform_string1(s):
r = ''
c = ''
i = 1
while s[i].isdigit():
r += s[i]
i += 1
i += 1
while i < len(s) and s[i].isdigit():
c += s[i]
i += 1
c = int(c)
res = ''
stack = []
while c:
if c % 26:
stack.append(chr(c % 26 + 64))
elif c == 26:
stack.append('Z')
break
else:
stack.append('Z')
c //= 26
while stack:
res += stack.pop()
res += r
return res
def transform_string2(s):
stack = []
i = 0
while s[i].isdigit() is False:
stack.append(s[i])
i += 1
r = s[i:]
c = 0
for j in range(len(stack)):
c += (ord(stack[j]) - 64) * (26 ** (len(stack) - j - 1))
res = 'R' + r + 'C' + str(c)
return res
n = int(input())
stack = []
for i in range(n):
s = input()
if not s[1].isdigit():
print(transform_string2(s))
else:
sign = 1
i = 2
while sign and i < len(s):
if not s[i].isdigit():
sign -= 1
i += 1
if not sign:
print(transform_string1(s))
else:
print(transform_string2(s))
``` | 0 |
1 | A | Theatre Square | PROGRAMMING | 1,000 | [
"math"
] | A. Theatre Square | 1 | 256 | Theatre Square in the capital city of Berland has a rectangular shape with the size *n*<=×<=*m* meters. On the occasion of the city's anniversary, a decision was taken to pave the Square with square granite flagstones. Each flagstone is of the size *a*<=×<=*a*.
What is the least number of flagstones needed to pave the Square? It's allowed to cover the surface larger than the Theatre Square, but the Square has to be covered. It's not allowed to break the flagstones. The sides of flagstones should be parallel to the sides of the Square. | The input contains three positive integer numbers in the first line: *n*,<=<=*m* and *a* (1<=≤<=<=*n*,<=*m*,<=*a*<=≤<=109). | Write the needed number of flagstones. | [
"6 6 4\n"
] | [
"4\n"
] | none | 0 | [
{
"input": "6 6 4",
"output": "4"
},
{
"input": "1 1 1",
"output": "1"
},
{
"input": "2 1 1",
"output": "2"
},
{
"input": "1 2 1",
"output": "2"
},
{
"input": "2 2 1",
"output": "4"
},
{
"input": "2 1 2",
"output": "1"
},
{
"input": "1 1 3",
"output": "1"
},
{
"input": "2 3 4",
"output": "1"
},
{
"input": "1000000000 1000000000 1",
"output": "1000000000000000000"
},
{
"input": "12 13 4",
"output": "12"
},
{
"input": "222 332 5",
"output": "3015"
},
{
"input": "1000 1000 10",
"output": "10000"
},
{
"input": "1001 1000 10",
"output": "10100"
},
{
"input": "100 10001 1000000000",
"output": "1"
},
{
"input": "1000000000 1000000000 1000000000",
"output": "1"
},
{
"input": "1000000000 1000000000 999999999",
"output": "4"
},
{
"input": "1000000000 1000000000 192",
"output": "27126743055556"
},
{
"input": "1000000000 987654321 1",
"output": "987654321000000000"
},
{
"input": "456784567 1000000000 51",
"output": "175618850864484"
},
{
"input": "39916800 134217728 40320",
"output": "3295710"
}
] | 1,660,282,872 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 30 | 0 | numeros = input().split()
output = 0
lado = 0
cociente = 0
n = numeros[0]
m = numeros[1]
a = numeros[2]
if(n<m):
lado = n
else:
lado = m
cociente = int(lado/a)
output = (cociente + 2) * cociente + 1
print(output) | Title: Theatre Square
Time Limit: 1 seconds
Memory Limit: 256 megabytes
Problem Description:
Theatre Square in the capital city of Berland has a rectangular shape with the size *n*<=×<=*m* meters. On the occasion of the city's anniversary, a decision was taken to pave the Square with square granite flagstones. Each flagstone is of the size *a*<=×<=*a*.
What is the least number of flagstones needed to pave the Square? It's allowed to cover the surface larger than the Theatre Square, but the Square has to be covered. It's not allowed to break the flagstones. The sides of flagstones should be parallel to the sides of the Square.
Input Specification:
The input contains three positive integer numbers in the first line: *n*,<=<=*m* and *a* (1<=≤<=<=*n*,<=*m*,<=*a*<=≤<=109).
Output Specification:
Write the needed number of flagstones.
Demo Input:
['6 6 4\n']
Demo Output:
['4\n']
Note:
none | ```python
numeros = input().split()
output = 0
lado = 0
cociente = 0
n = numeros[0]
m = numeros[1]
a = numeros[2]
if(n<m):
lado = n
else:
lado = m
cociente = int(lado/a)
output = (cociente + 2) * cociente + 1
print(output)
``` | -1 |
912 | B | New Year's Eve | PROGRAMMING | 1,300 | [
"bitmasks",
"constructive algorithms",
"number theory"
] | null | null | Since Grisha behaved well last year, at New Year's Eve he was visited by Ded Moroz who brought an enormous bag of gifts with him! The bag contains *n* sweet candies from the good ol' bakery, each labeled from 1 to *n* corresponding to its tastiness. No two candies have the same tastiness.
The choice of candies has a direct effect on Grisha's happiness. One can assume that he should take the tastiest ones — but no, the holiday magic turns things upside down. It is the xor-sum of tastinesses that matters, not the ordinary sum!
A xor-sum of a sequence of integers *a*1,<=*a*2,<=...,<=*a**m* is defined as the bitwise XOR of all its elements: , here denotes the bitwise XOR operation; more about bitwise XOR can be found [here.](https://en.wikipedia.org/wiki/Bitwise_operation#XOR)
Ded Moroz warned Grisha he has more houses to visit, so Grisha can take no more than *k* candies from the bag. Help Grisha determine the largest xor-sum (largest xor-sum means maximum happiness!) he can obtain. | The sole string contains two integers *n* and *k* (1<=≤<=*k*<=≤<=*n*<=≤<=1018). | Output one number — the largest possible xor-sum. | [
"4 3\n",
"6 6\n"
] | [
"7\n",
"7\n"
] | In the first sample case, one optimal answer is 1, 2 and 4, giving the xor-sum of 7.
In the second sample case, one can, for example, take all six candies and obtain the xor-sum of 7. | 1,000 | [
{
"input": "4 3",
"output": "7"
},
{
"input": "6 6",
"output": "7"
},
{
"input": "2 2",
"output": "3"
},
{
"input": "1022 10",
"output": "1023"
},
{
"input": "415853337373441 52",
"output": "562949953421311"
},
{
"input": "75 12",
"output": "127"
},
{
"input": "1000000000000000000 1000000000000000000",
"output": "1152921504606846975"
},
{
"input": "1 1",
"output": "1"
},
{
"input": "1000000000000000000 2",
"output": "1152921504606846975"
},
{
"input": "49194939 22",
"output": "67108863"
},
{
"input": "228104606 17",
"output": "268435455"
},
{
"input": "817034381 7",
"output": "1073741823"
},
{
"input": "700976748 4",
"output": "1073741823"
},
{
"input": "879886415 9",
"output": "1073741823"
},
{
"input": "18007336 10353515",
"output": "33554431"
},
{
"input": "196917003 154783328",
"output": "268435455"
},
{
"input": "785846777 496205300",
"output": "1073741823"
},
{
"input": "964756444 503568330",
"output": "1073741823"
},
{
"input": "848698811 317703059",
"output": "1073741823"
},
{
"input": "676400020444788 1",
"output": "676400020444788"
},
{
"input": "502643198528213 1",
"output": "502643198528213"
},
{
"input": "815936580997298686 684083143940282566",
"output": "1152921504606846975"
},
{
"input": "816762824175382110 752185261508428780",
"output": "1152921504606846975"
},
{
"input": "327942415253132295 222598158321260499",
"output": "576460752303423487"
},
{
"input": "328768654136248423 284493129147496637",
"output": "576460752303423487"
},
{
"input": "329594893019364551 25055600080496801",
"output": "576460752303423487"
},
{
"input": "921874985256864012 297786684518764536",
"output": "1152921504606846975"
},
{
"input": "922701224139980141 573634416190460758",
"output": "1152921504606846975"
},
{
"input": "433880815217730325 45629641110945892",
"output": "576460752303423487"
},
{
"input": "434707058395813749 215729375494216481",
"output": "576460752303423487"
},
{
"input": "435533301573897173 34078453236225189",
"output": "576460752303423487"
},
{
"input": "436359544751980597 199220719961060641",
"output": "576460752303423487"
},
{
"input": "437185783635096725 370972992240105630",
"output": "576460752303423487"
},
{
"input": "438012026813180149 111323110116193830",
"output": "576460752303423487"
},
{
"input": "438838269991263573 295468957052046146",
"output": "576460752303423487"
},
{
"input": "439664513169346997 46560240538186155",
"output": "576460752303423487"
},
{
"input": "440490752052463125 216165966013438147",
"output": "576460752303423487"
},
{
"input": "441316995230546549 401964286420555423",
"output": "576460752303423487"
},
{
"input": "952496582013329437 673506882352402278",
"output": "1152921504606846975"
},
{
"input": "1000000000000000000 1",
"output": "1000000000000000000"
},
{
"input": "2147483647 1",
"output": "2147483647"
},
{
"input": "2147483647 2",
"output": "2147483647"
},
{
"input": "2147483647 31",
"output": "2147483647"
},
{
"input": "8 2",
"output": "15"
},
{
"input": "3 3",
"output": "3"
},
{
"input": "4 1",
"output": "4"
},
{
"input": "10 2",
"output": "15"
},
{
"input": "288230376151711743 2",
"output": "288230376151711743"
},
{
"input": "5 2",
"output": "7"
},
{
"input": "576460752303423487 2",
"output": "576460752303423487"
},
{
"input": "36028797018963967 123",
"output": "36028797018963967"
},
{
"input": "1125899906842623 2",
"output": "1125899906842623"
},
{
"input": "576460752303423489 5",
"output": "1152921504606846975"
},
{
"input": "288230376151711743 3",
"output": "288230376151711743"
},
{
"input": "36028797018963967 345",
"output": "36028797018963967"
},
{
"input": "18014398509481984 30",
"output": "36028797018963967"
},
{
"input": "8 8",
"output": "15"
},
{
"input": "8 1",
"output": "8"
}
] | 1,516,725,943 | 2,147,483,647 | Python 3 | OK | TESTS | 58 | 77 | 5,632,000 | n , k = map(int , input().split())
l = list(bin(n))[2:]
if k == 1: print(n)
else:
print ((1 << len(l)) -1)
| Title: New Year's Eve
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Since Grisha behaved well last year, at New Year's Eve he was visited by Ded Moroz who brought an enormous bag of gifts with him! The bag contains *n* sweet candies from the good ol' bakery, each labeled from 1 to *n* corresponding to its tastiness. No two candies have the same tastiness.
The choice of candies has a direct effect on Grisha's happiness. One can assume that he should take the tastiest ones — but no, the holiday magic turns things upside down. It is the xor-sum of tastinesses that matters, not the ordinary sum!
A xor-sum of a sequence of integers *a*1,<=*a*2,<=...,<=*a**m* is defined as the bitwise XOR of all its elements: , here denotes the bitwise XOR operation; more about bitwise XOR can be found [here.](https://en.wikipedia.org/wiki/Bitwise_operation#XOR)
Ded Moroz warned Grisha he has more houses to visit, so Grisha can take no more than *k* candies from the bag. Help Grisha determine the largest xor-sum (largest xor-sum means maximum happiness!) he can obtain.
Input Specification:
The sole string contains two integers *n* and *k* (1<=≤<=*k*<=≤<=*n*<=≤<=1018).
Output Specification:
Output one number — the largest possible xor-sum.
Demo Input:
['4 3\n', '6 6\n']
Demo Output:
['7\n', '7\n']
Note:
In the first sample case, one optimal answer is 1, 2 and 4, giving the xor-sum of 7.
In the second sample case, one can, for example, take all six candies and obtain the xor-sum of 7. | ```python
n , k = map(int , input().split())
l = list(bin(n))[2:]
if k == 1: print(n)
else:
print ((1 << len(l)) -1)
``` | 3 |
|
803 | A | Maximal Binary Matrix | PROGRAMMING | 1,400 | [
"constructive algorithms"
] | null | null | You are given matrix with *n* rows and *n* columns filled with zeroes. You should put *k* ones in it in such a way that the resulting matrix is symmetrical with respect to the main diagonal (the diagonal that goes from the top left to the bottom right corner) and is lexicographically maximal.
One matrix is lexicographically greater than the other if the first different number in the first different row from the top in the first matrix is greater than the corresponding number in the second one.
If there exists no such matrix then output -1. | The first line consists of two numbers *n* and *k* (1<=≤<=*n*<=≤<=100, 0<=≤<=*k*<=≤<=106). | If the answer exists then output resulting matrix. Otherwise output -1. | [
"2 1\n",
"3 2\n",
"2 5\n"
] | [
"1 0 \n0 0 \n",
"1 0 0 \n0 1 0 \n0 0 0 \n",
"-1\n"
] | none | 0 | [
{
"input": "2 1",
"output": "1 0 \n0 0 "
},
{
"input": "3 2",
"output": "1 0 0 \n0 1 0 \n0 0 0 "
},
{
"input": "2 5",
"output": "-1"
},
{
"input": "1 0",
"output": "0 "
},
{
"input": "1 1",
"output": "1 "
},
{
"input": "20 398",
"output": "1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 \n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 \n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 \n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 \n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 \n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 \n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 \n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 \n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 \n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 \n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 \n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 \n1 1 1 1..."
},
{
"input": "20 401",
"output": "-1"
},
{
"input": "100 3574",
"output": "1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 \n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 \n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1..."
},
{
"input": "100 10000",
"output": "1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 \n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 \n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1..."
},
{
"input": "100 10001",
"output": "-1"
},
{
"input": "2 3",
"output": "1 1 \n1 0 "
},
{
"input": "4 5",
"output": "1 1 1 0 \n1 0 0 0 \n1 0 0 0 \n0 0 0 0 "
},
{
"input": "5 6",
"output": "1 1 1 0 0 \n1 1 0 0 0 \n1 0 0 0 0 \n0 0 0 0 0 \n0 0 0 0 0 "
},
{
"input": "5 24",
"output": "1 1 1 1 1 \n1 1 1 1 1 \n1 1 1 1 1 \n1 1 1 1 1 \n1 1 1 1 0 "
},
{
"input": "2 0",
"output": "0 0 \n0 0 "
},
{
"input": "3 5",
"output": "1 1 1 \n1 0 0 \n1 0 0 "
},
{
"input": "3 3",
"output": "1 1 0 \n1 0 0 \n0 0 0 "
},
{
"input": "5 10",
"output": "1 1 1 1 1 \n1 1 0 0 0 \n1 0 0 0 0 \n1 0 0 0 0 \n1 0 0 0 0 "
},
{
"input": "3 4",
"output": "1 1 0 \n1 1 0 \n0 0 0 "
},
{
"input": "4 3",
"output": "1 1 0 0 \n1 0 0 0 \n0 0 0 0 \n0 0 0 0 "
},
{
"input": "1 1000000",
"output": "-1"
},
{
"input": "3 6",
"output": "1 1 1 \n1 1 0 \n1 0 0 "
},
{
"input": "1 2",
"output": "-1"
},
{
"input": "1 0",
"output": "0 "
},
{
"input": "1 1",
"output": "1 "
},
{
"input": "1 2",
"output": "-1"
},
{
"input": "1 3",
"output": "-1"
},
{
"input": "1 4",
"output": "-1"
},
{
"input": "1 5",
"output": "-1"
},
{
"input": "1 6",
"output": "-1"
},
{
"input": "1 7",
"output": "-1"
},
{
"input": "1 8",
"output": "-1"
},
{
"input": "1 9",
"output": "-1"
},
{
"input": "1 10",
"output": "-1"
},
{
"input": "1 11",
"output": "-1"
},
{
"input": "1 12",
"output": "-1"
},
{
"input": "1 13",
"output": "-1"
},
{
"input": "1 14",
"output": "-1"
},
{
"input": "1 15",
"output": "-1"
},
{
"input": "1 16",
"output": "-1"
},
{
"input": "1 17",
"output": "-1"
},
{
"input": "1 18",
"output": "-1"
},
{
"input": "1 19",
"output": "-1"
},
{
"input": "1 20",
"output": "-1"
},
{
"input": "1 21",
"output": "-1"
},
{
"input": "1 22",
"output": "-1"
},
{
"input": "1 23",
"output": "-1"
},
{
"input": "1 24",
"output": "-1"
},
{
"input": "1 25",
"output": "-1"
},
{
"input": "1 26",
"output": "-1"
},
{
"input": "2 0",
"output": "0 0 \n0 0 "
},
{
"input": "2 1",
"output": "1 0 \n0 0 "
},
{
"input": "2 2",
"output": "1 0 \n0 1 "
},
{
"input": "2 3",
"output": "1 1 \n1 0 "
},
{
"input": "2 4",
"output": "1 1 \n1 1 "
},
{
"input": "2 5",
"output": "-1"
},
{
"input": "2 6",
"output": "-1"
},
{
"input": "2 7",
"output": "-1"
},
{
"input": "2 8",
"output": "-1"
},
{
"input": "2 9",
"output": "-1"
},
{
"input": "2 10",
"output": "-1"
},
{
"input": "2 11",
"output": "-1"
},
{
"input": "2 12",
"output": "-1"
},
{
"input": "2 13",
"output": "-1"
},
{
"input": "2 14",
"output": "-1"
},
{
"input": "2 15",
"output": "-1"
},
{
"input": "2 16",
"output": "-1"
},
{
"input": "2 17",
"output": "-1"
},
{
"input": "2 18",
"output": "-1"
},
{
"input": "2 19",
"output": "-1"
},
{
"input": "2 20",
"output": "-1"
},
{
"input": "2 21",
"output": "-1"
},
{
"input": "2 22",
"output": "-1"
},
{
"input": "2 23",
"output": "-1"
},
{
"input": "2 24",
"output": "-1"
},
{
"input": "2 25",
"output": "-1"
},
{
"input": "2 26",
"output": "-1"
},
{
"input": "3 0",
"output": "0 0 0 \n0 0 0 \n0 0 0 "
},
{
"input": "3 1",
"output": "1 0 0 \n0 0 0 \n0 0 0 "
},
{
"input": "3 2",
"output": "1 0 0 \n0 1 0 \n0 0 0 "
},
{
"input": "3 3",
"output": "1 1 0 \n1 0 0 \n0 0 0 "
},
{
"input": "3 4",
"output": "1 1 0 \n1 1 0 \n0 0 0 "
},
{
"input": "3 5",
"output": "1 1 1 \n1 0 0 \n1 0 0 "
},
{
"input": "3 6",
"output": "1 1 1 \n1 1 0 \n1 0 0 "
},
{
"input": "3 7",
"output": "1 1 1 \n1 1 0 \n1 0 1 "
},
{
"input": "3 8",
"output": "1 1 1 \n1 1 1 \n1 1 0 "
},
{
"input": "3 9",
"output": "1 1 1 \n1 1 1 \n1 1 1 "
},
{
"input": "3 10",
"output": "-1"
},
{
"input": "3 11",
"output": "-1"
},
{
"input": "3 12",
"output": "-1"
},
{
"input": "3 13",
"output": "-1"
},
{
"input": "3 14",
"output": "-1"
},
{
"input": "3 15",
"output": "-1"
},
{
"input": "3 16",
"output": "-1"
},
{
"input": "3 17",
"output": "-1"
},
{
"input": "3 18",
"output": "-1"
},
{
"input": "3 19",
"output": "-1"
},
{
"input": "3 20",
"output": "-1"
},
{
"input": "3 21",
"output": "-1"
},
{
"input": "3 22",
"output": "-1"
},
{
"input": "3 23",
"output": "-1"
},
{
"input": "3 24",
"output": "-1"
},
{
"input": "3 25",
"output": "-1"
},
{
"input": "3 26",
"output": "-1"
},
{
"input": "4 0",
"output": "0 0 0 0 \n0 0 0 0 \n0 0 0 0 \n0 0 0 0 "
},
{
"input": "4 1",
"output": "1 0 0 0 \n0 0 0 0 \n0 0 0 0 \n0 0 0 0 "
},
{
"input": "4 2",
"output": "1 0 0 0 \n0 1 0 0 \n0 0 0 0 \n0 0 0 0 "
},
{
"input": "4 3",
"output": "1 1 0 0 \n1 0 0 0 \n0 0 0 0 \n0 0 0 0 "
},
{
"input": "4 4",
"output": "1 1 0 0 \n1 1 0 0 \n0 0 0 0 \n0 0 0 0 "
},
{
"input": "4 5",
"output": "1 1 1 0 \n1 0 0 0 \n1 0 0 0 \n0 0 0 0 "
},
{
"input": "4 6",
"output": "1 1 1 0 \n1 1 0 0 \n1 0 0 0 \n0 0 0 0 "
},
{
"input": "4 7",
"output": "1 1 1 1 \n1 0 0 0 \n1 0 0 0 \n1 0 0 0 "
},
{
"input": "4 8",
"output": "1 1 1 1 \n1 1 0 0 \n1 0 0 0 \n1 0 0 0 "
},
{
"input": "4 9",
"output": "1 1 1 1 \n1 1 0 0 \n1 0 1 0 \n1 0 0 0 "
},
{
"input": "4 10",
"output": "1 1 1 1 \n1 1 1 0 \n1 1 0 0 \n1 0 0 0 "
},
{
"input": "4 11",
"output": "1 1 1 1 \n1 1 1 0 \n1 1 1 0 \n1 0 0 0 "
},
{
"input": "4 12",
"output": "1 1 1 1 \n1 1 1 1 \n1 1 0 0 \n1 1 0 0 "
},
{
"input": "4 13",
"output": "1 1 1 1 \n1 1 1 1 \n1 1 1 0 \n1 1 0 0 "
},
{
"input": "4 14",
"output": "1 1 1 1 \n1 1 1 1 \n1 1 1 0 \n1 1 0 1 "
},
{
"input": "4 15",
"output": "1 1 1 1 \n1 1 1 1 \n1 1 1 1 \n1 1 1 0 "
},
{
"input": "4 16",
"output": "1 1 1 1 \n1 1 1 1 \n1 1 1 1 \n1 1 1 1 "
},
{
"input": "4 17",
"output": "-1"
},
{
"input": "4 18",
"output": "-1"
},
{
"input": "4 19",
"output": "-1"
},
{
"input": "4 20",
"output": "-1"
},
{
"input": "4 21",
"output": "-1"
},
{
"input": "4 22",
"output": "-1"
},
{
"input": "4 23",
"output": "-1"
},
{
"input": "4 24",
"output": "-1"
},
{
"input": "4 25",
"output": "-1"
},
{
"input": "4 26",
"output": "-1"
},
{
"input": "5 0",
"output": "0 0 0 0 0 \n0 0 0 0 0 \n0 0 0 0 0 \n0 0 0 0 0 \n0 0 0 0 0 "
},
{
"input": "5 1",
"output": "1 0 0 0 0 \n0 0 0 0 0 \n0 0 0 0 0 \n0 0 0 0 0 \n0 0 0 0 0 "
},
{
"input": "5 2",
"output": "1 0 0 0 0 \n0 1 0 0 0 \n0 0 0 0 0 \n0 0 0 0 0 \n0 0 0 0 0 "
},
{
"input": "5 3",
"output": "1 1 0 0 0 \n1 0 0 0 0 \n0 0 0 0 0 \n0 0 0 0 0 \n0 0 0 0 0 "
},
{
"input": "5 4",
"output": "1 1 0 0 0 \n1 1 0 0 0 \n0 0 0 0 0 \n0 0 0 0 0 \n0 0 0 0 0 "
},
{
"input": "5 5",
"output": "1 1 1 0 0 \n1 0 0 0 0 \n1 0 0 0 0 \n0 0 0 0 0 \n0 0 0 0 0 "
},
{
"input": "5 6",
"output": "1 1 1 0 0 \n1 1 0 0 0 \n1 0 0 0 0 \n0 0 0 0 0 \n0 0 0 0 0 "
},
{
"input": "5 7",
"output": "1 1 1 1 0 \n1 0 0 0 0 \n1 0 0 0 0 \n1 0 0 0 0 \n0 0 0 0 0 "
},
{
"input": "5 8",
"output": "1 1 1 1 0 \n1 1 0 0 0 \n1 0 0 0 0 \n1 0 0 0 0 \n0 0 0 0 0 "
},
{
"input": "5 9",
"output": "1 1 1 1 1 \n1 0 0 0 0 \n1 0 0 0 0 \n1 0 0 0 0 \n1 0 0 0 0 "
},
{
"input": "5 10",
"output": "1 1 1 1 1 \n1 1 0 0 0 \n1 0 0 0 0 \n1 0 0 0 0 \n1 0 0 0 0 "
},
{
"input": "5 11",
"output": "1 1 1 1 1 \n1 1 0 0 0 \n1 0 1 0 0 \n1 0 0 0 0 \n1 0 0 0 0 "
},
{
"input": "5 12",
"output": "1 1 1 1 1 \n1 1 1 0 0 \n1 1 0 0 0 \n1 0 0 0 0 \n1 0 0 0 0 "
},
{
"input": "5 13",
"output": "1 1 1 1 1 \n1 1 1 0 0 \n1 1 1 0 0 \n1 0 0 0 0 \n1 0 0 0 0 "
},
{
"input": "5 14",
"output": "1 1 1 1 1 \n1 1 1 1 0 \n1 1 0 0 0 \n1 1 0 0 0 \n1 0 0 0 0 "
},
{
"input": "5 15",
"output": "1 1 1 1 1 \n1 1 1 1 0 \n1 1 1 0 0 \n1 1 0 0 0 \n1 0 0 0 0 "
},
{
"input": "5 16",
"output": "1 1 1 1 1 \n1 1 1 1 1 \n1 1 0 0 0 \n1 1 0 0 0 \n1 1 0 0 0 "
},
{
"input": "5 17",
"output": "1 1 1 1 1 \n1 1 1 1 1 \n1 1 1 0 0 \n1 1 0 0 0 \n1 1 0 0 0 "
},
{
"input": "5 18",
"output": "1 1 1 1 1 \n1 1 1 1 1 \n1 1 1 0 0 \n1 1 0 1 0 \n1 1 0 0 0 "
},
{
"input": "5 19",
"output": "1 1 1 1 1 \n1 1 1 1 1 \n1 1 1 1 0 \n1 1 1 0 0 \n1 1 0 0 0 "
},
{
"input": "5 20",
"output": "1 1 1 1 1 \n1 1 1 1 1 \n1 1 1 1 0 \n1 1 1 1 0 \n1 1 0 0 0 "
},
{
"input": "5 21",
"output": "1 1 1 1 1 \n1 1 1 1 1 \n1 1 1 1 1 \n1 1 1 0 0 \n1 1 1 0 0 "
},
{
"input": "5 22",
"output": "1 1 1 1 1 \n1 1 1 1 1 \n1 1 1 1 1 \n1 1 1 1 0 \n1 1 1 0 0 "
},
{
"input": "5 23",
"output": "1 1 1 1 1 \n1 1 1 1 1 \n1 1 1 1 1 \n1 1 1 1 0 \n1 1 1 0 1 "
},
{
"input": "5 24",
"output": "1 1 1 1 1 \n1 1 1 1 1 \n1 1 1 1 1 \n1 1 1 1 1 \n1 1 1 1 0 "
},
{
"input": "5 25",
"output": "1 1 1 1 1 \n1 1 1 1 1 \n1 1 1 1 1 \n1 1 1 1 1 \n1 1 1 1 1 "
},
{
"input": "5 26",
"output": "-1"
},
{
"input": "100 0",
"output": "0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 \n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 \n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0..."
},
{
"input": "100 1",
"output": "1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 \n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 \n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0..."
},
{
"input": "100 2",
"output": "1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 \n0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 \n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0..."
},
{
"input": "100 3",
"output": "1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 \n1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 \n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0..."
},
{
"input": "100 99",
"output": "1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 \n1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 \n1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0..."
},
{
"input": "100 100",
"output": "1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 \n1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 \n1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0..."
},
{
"input": "100 101",
"output": "1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 \n1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 \n1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0..."
},
{
"input": "100 9999",
"output": "1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 \n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 \n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1..."
},
{
"input": "100 10000",
"output": "1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 \n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 \n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1..."
},
{
"input": "100 10001",
"output": "-1"
}
] | 1,698,547,208 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 12 | 46 | 1,843,200 | (n,k) = map(int,input().split())
matrix = [[0] * n for i in range(n)]
if k > n*n:
print(-1)
else:
i = n
while 2 * i - 1 < k:
for m in range(n-i,n):
matrix[m][n-i] = 1
matrix[n-i][m] = 1
k -= 2*i -1
i -= 1
if k == 2:
matrix[n-i][n-i] = 1
matrix[n-i+1][n-i+1] = 1
elif k == 1:
matrix[n-i][n-i] = 1
elif k > 2 and k % 2 == 0:
matrix[n-i+1][n-i+1] = 0
for l in range(n-i,n-i+ n//2):
matrix[l][n - i] = 1
matrix[n - i][l] = 1
else:
for l in range(n-i,n-i+(k+1)//2):
matrix[l][n - i] = 1
matrix[n - i][l] = 1
for row in matrix:
print(' '.join(map(str,row))) | Title: Maximal Binary Matrix
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given matrix with *n* rows and *n* columns filled with zeroes. You should put *k* ones in it in such a way that the resulting matrix is symmetrical with respect to the main diagonal (the diagonal that goes from the top left to the bottom right corner) and is lexicographically maximal.
One matrix is lexicographically greater than the other if the first different number in the first different row from the top in the first matrix is greater than the corresponding number in the second one.
If there exists no such matrix then output -1.
Input Specification:
The first line consists of two numbers *n* and *k* (1<=≤<=*n*<=≤<=100, 0<=≤<=*k*<=≤<=106).
Output Specification:
If the answer exists then output resulting matrix. Otherwise output -1.
Demo Input:
['2 1\n', '3 2\n', '2 5\n']
Demo Output:
['1 0 \n0 0 \n', '1 0 0 \n0 1 0 \n0 0 0 \n', '-1\n']
Note:
none | ```python
(n,k) = map(int,input().split())
matrix = [[0] * n for i in range(n)]
if k > n*n:
print(-1)
else:
i = n
while 2 * i - 1 < k:
for m in range(n-i,n):
matrix[m][n-i] = 1
matrix[n-i][m] = 1
k -= 2*i -1
i -= 1
if k == 2:
matrix[n-i][n-i] = 1
matrix[n-i+1][n-i+1] = 1
elif k == 1:
matrix[n-i][n-i] = 1
elif k > 2 and k % 2 == 0:
matrix[n-i+1][n-i+1] = 0
for l in range(n-i,n-i+ n//2):
matrix[l][n - i] = 1
matrix[n - i][l] = 1
else:
for l in range(n-i,n-i+(k+1)//2):
matrix[l][n - i] = 1
matrix[n - i][l] = 1
for row in matrix:
print(' '.join(map(str,row)))
``` | 0 |
|
139 | A | Petr and Book | PROGRAMMING | 1,000 | [
"implementation"
] | null | null | One Sunday Petr went to a bookshop and bought a new book on sports programming. The book had exactly *n* pages.
Petr decided to start reading it starting from the next day, that is, from Monday. Petr's got a very tight schedule and for each day of the week he knows how many pages he will be able to read on that day. Some days are so busy that Petr will have no time to read whatsoever. However, we know that he will be able to read at least one page a week.
Assuming that Petr will not skip days and will read as much as he can every day, determine on which day of the week he will read the last page of the book. | The first input line contains the single integer *n* (1<=≤<=*n*<=≤<=1000) — the number of pages in the book.
The second line contains seven non-negative space-separated integers that do not exceed 1000 — those integers represent how many pages Petr can read on Monday, Tuesday, Wednesday, Thursday, Friday, Saturday and Sunday correspondingly. It is guaranteed that at least one of those numbers is larger than zero. | Print a single number — the number of the day of the week, when Petr will finish reading the book. The days of the week are numbered starting with one in the natural order: Monday, Tuesday, Wednesday, Thursday, Friday, Saturday, Sunday. | [
"100\n15 20 20 15 10 30 45\n",
"2\n1 0 0 0 0 0 0\n"
] | [
"6\n",
"1\n"
] | Note to the first sample:
By the end of Monday and therefore, by the beginning of Tuesday Petr has 85 pages left. He has 65 pages left by Wednesday, 45 by Thursday, 30 by Friday, 20 by Saturday and on Saturday Petr finishes reading the book (and he also has time to read 10 pages of something else).
Note to the second sample:
On Monday of the first week Petr will read the first page. On Monday of the second week Petr will read the second page and will finish reading the book. | 500 | [
{
"input": "100\n15 20 20 15 10 30 45",
"output": "6"
},
{
"input": "2\n1 0 0 0 0 0 0",
"output": "1"
},
{
"input": "100\n100 200 100 200 300 400 500",
"output": "1"
},
{
"input": "3\n1 1 1 1 1 1 1",
"output": "3"
},
{
"input": "1\n1 1 1 1 1 1 1",
"output": "1"
},
{
"input": "20\n5 3 7 2 1 6 4",
"output": "6"
},
{
"input": "10\n5 1 1 1 1 1 5",
"output": "6"
},
{
"input": "50\n10 1 10 1 10 1 10",
"output": "1"
},
{
"input": "77\n11 11 11 11 11 11 10",
"output": "1"
},
{
"input": "1\n1000 1000 1000 1000 1000 1000 1000",
"output": "1"
},
{
"input": "1000\n100 100 100 100 100 100 100",
"output": "3"
},
{
"input": "999\n10 20 10 20 30 20 10",
"output": "3"
},
{
"input": "433\n109 58 77 10 39 125 15",
"output": "7"
},
{
"input": "1\n0 0 0 0 0 0 1",
"output": "7"
},
{
"input": "5\n1 0 1 0 1 0 1",
"output": "1"
},
{
"input": "997\n1 1 0 0 1 0 1",
"output": "1"
},
{
"input": "1000\n1 1 1 1 1 1 1",
"output": "6"
},
{
"input": "1000\n1000 1000 1000 1000 1000 1000 1000",
"output": "1"
},
{
"input": "1000\n1 0 0 0 0 0 0",
"output": "1"
},
{
"input": "1000\n0 0 0 0 0 0 1",
"output": "7"
},
{
"input": "1000\n1 0 0 1 0 0 1",
"output": "1"
},
{
"input": "509\n105 23 98 0 7 0 155",
"output": "2"
},
{
"input": "7\n1 1 1 1 1 1 1",
"output": "7"
},
{
"input": "2\n1 1 0 0 0 0 0",
"output": "2"
},
{
"input": "1\n0 0 0 0 0 1 0",
"output": "6"
},
{
"input": "10\n0 0 0 0 0 0 1",
"output": "7"
},
{
"input": "5\n0 0 0 0 0 6 0",
"output": "6"
},
{
"input": "3\n0 1 0 0 0 0 0",
"output": "2"
},
{
"input": "10\n0 0 0 0 0 0 10",
"output": "7"
},
{
"input": "28\n1 2 3 4 5 6 7",
"output": "7"
},
{
"input": "100\n5 5 5 5 5 5 5",
"output": "6"
},
{
"input": "4\n1 0 0 0 0 0 1",
"output": "7"
},
{
"input": "2\n0 0 0 0 0 0 1",
"output": "7"
},
{
"input": "7\n0 0 0 0 0 0 7",
"output": "7"
},
{
"input": "7\n2 1 1 1 1 1 0",
"output": "6"
},
{
"input": "2\n0 0 1 1 0 0 0",
"output": "4"
},
{
"input": "6\n1 1 1 1 1 1 0",
"output": "6"
},
{
"input": "5\n1 1 1 0 0 1 1",
"output": "7"
},
{
"input": "100\n10 20 30 10 10 10 10",
"output": "7"
},
{
"input": "1\n0 0 0 1 0 0 0",
"output": "4"
},
{
"input": "70\n10 10 10 10 10 10 10",
"output": "7"
},
{
"input": "22\n1 2 3 4 5 6 10",
"output": "7"
},
{
"input": "5\n0 0 0 1 0 0 0",
"output": "4"
},
{
"input": "2\n0 0 0 1 0 0 0",
"output": "4"
},
{
"input": "6\n1 0 0 0 0 0 2",
"output": "7"
},
{
"input": "10\n1 2 2 1 2 1 1",
"output": "7"
},
{
"input": "5\n0 0 0 0 0 0 10",
"output": "7"
},
{
"input": "4\n0 1 1 0 0 0 0",
"output": "3"
},
{
"input": "100\n0 0 0 0 0 1 0",
"output": "6"
}
] | 1,620,651,049 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 10 | 124 | 7,065,600 | import random
limit=0
n = int(input())
read=list(map(int,input().split()))
for i in range(len(read)):
limit+=read[i]
if limit >=n:
print(i+1)
break
else:
print(1)
| Title: Petr and Book
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
One Sunday Petr went to a bookshop and bought a new book on sports programming. The book had exactly *n* pages.
Petr decided to start reading it starting from the next day, that is, from Monday. Petr's got a very tight schedule and for each day of the week he knows how many pages he will be able to read on that day. Some days are so busy that Petr will have no time to read whatsoever. However, we know that he will be able to read at least one page a week.
Assuming that Petr will not skip days and will read as much as he can every day, determine on which day of the week he will read the last page of the book.
Input Specification:
The first input line contains the single integer *n* (1<=≤<=*n*<=≤<=1000) — the number of pages in the book.
The second line contains seven non-negative space-separated integers that do not exceed 1000 — those integers represent how many pages Petr can read on Monday, Tuesday, Wednesday, Thursday, Friday, Saturday and Sunday correspondingly. It is guaranteed that at least one of those numbers is larger than zero.
Output Specification:
Print a single number — the number of the day of the week, when Petr will finish reading the book. The days of the week are numbered starting with one in the natural order: Monday, Tuesday, Wednesday, Thursday, Friday, Saturday, Sunday.
Demo Input:
['100\n15 20 20 15 10 30 45\n', '2\n1 0 0 0 0 0 0\n']
Demo Output:
['6\n', '1\n']
Note:
Note to the first sample:
By the end of Monday and therefore, by the beginning of Tuesday Petr has 85 pages left. He has 65 pages left by Wednesday, 45 by Thursday, 30 by Friday, 20 by Saturday and on Saturday Petr finishes reading the book (and he also has time to read 10 pages of something else).
Note to the second sample:
On Monday of the first week Petr will read the first page. On Monday of the second week Petr will read the second page and will finish reading the book. | ```python
import random
limit=0
n = int(input())
read=list(map(int,input().split()))
for i in range(len(read)):
limit+=read[i]
if limit >=n:
print(i+1)
break
else:
print(1)
``` | 0 |
|
478 | B | Random Teams | PROGRAMMING | 1,300 | [
"combinatorics",
"constructive algorithms",
"greedy",
"math"
] | null | null | *n* participants of the competition were split into *m* teams in some manner so that each team has at least one participant. After the competition each pair of participants from the same team became friends.
Your task is to write a program that will find the minimum and the maximum number of pairs of friends that could have formed by the end of the competition. | The only line of input contains two integers *n* and *m*, separated by a single space (1<=≤<=*m*<=≤<=*n*<=≤<=109) — the number of participants and the number of teams respectively. | The only line of the output should contain two integers *k**min* and *k**max* — the minimum possible number of pairs of friends and the maximum possible number of pairs of friends respectively. | [
"5 1\n",
"3 2\n",
"6 3\n"
] | [
"10 10\n",
"1 1\n",
"3 6\n"
] | In the first sample all the participants get into one team, so there will be exactly ten pairs of friends.
In the second sample at any possible arrangement one team will always have two participants and the other team will always have one participant. Thus, the number of pairs of friends will always be equal to one.
In the third sample minimum number of newly formed friendships can be achieved if participants were split on teams consisting of 2 people, maximum number can be achieved if participants were split on teams of 1, 1 and 4 people. | 1,000 | [
{
"input": "5 1",
"output": "10 10"
},
{
"input": "3 2",
"output": "1 1"
},
{
"input": "6 3",
"output": "3 6"
},
{
"input": "5 3",
"output": "2 3"
},
{
"input": "10 2",
"output": "20 36"
},
{
"input": "10 6",
"output": "4 10"
},
{
"input": "1000000000 1",
"output": "499999999500000000 499999999500000000"
},
{
"input": "5000000 12",
"output": "1041664166668 12499942500066"
},
{
"input": "1833 195",
"output": "7722 1342341"
},
{
"input": "1000000000 1000000000",
"output": "0 0"
},
{
"input": "1000000000 1000000",
"output": "499500000000 499000500499500000"
},
{
"input": "1000000000 32170",
"output": "15541930838100 499967831017438365"
},
{
"input": "1000000 1000",
"output": "499500000 499000999500"
},
{
"input": "1234 1123",
"output": "111 6216"
},
{
"input": "599222887 298488",
"output": "601178656545 179355218158217800"
},
{
"input": "999999999 500000000",
"output": "499999999 124999999750000000"
},
{
"input": "1000000000 384842119",
"output": "845473643 189209609585784021"
},
{
"input": "1000000000 384842119",
"output": "845473643 189209609585784021"
},
{
"input": "1000000000 2",
"output": "249999999500000000 499999998500000001"
},
{
"input": "1000000000 999999999",
"output": "1 1"
},
{
"input": "38447 383",
"output": "1910550 724453080"
},
{
"input": "100000000 99999799",
"output": "201 20301"
},
{
"input": "1 1",
"output": "0 0"
},
{
"input": "2 1",
"output": "1 1"
},
{
"input": "2 2",
"output": "0 0"
},
{
"input": "10 10",
"output": "0 0"
}
] | 1,666,021,089 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 2 | 62 | 0 | items = input().split(" ")
n = int(items[0])
m = int(items[1])
def get_res(k):
return k * (k-1) // 2
if m == 1:
k_min = get_res(n)
k_max = get_res(n)
print(k_min, k_max)
else:
if n % m == 0:
k_min = get_res(n//m)
else:
k_min = get_res(n//m + 1)
k_max = get_res(n-(m-1))
print(k_min, k_max) | Title: Random Teams
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
*n* participants of the competition were split into *m* teams in some manner so that each team has at least one participant. After the competition each pair of participants from the same team became friends.
Your task is to write a program that will find the minimum and the maximum number of pairs of friends that could have formed by the end of the competition.
Input Specification:
The only line of input contains two integers *n* and *m*, separated by a single space (1<=≤<=*m*<=≤<=*n*<=≤<=109) — the number of participants and the number of teams respectively.
Output Specification:
The only line of the output should contain two integers *k**min* and *k**max* — the minimum possible number of pairs of friends and the maximum possible number of pairs of friends respectively.
Demo Input:
['5 1\n', '3 2\n', '6 3\n']
Demo Output:
['10 10\n', '1 1\n', '3 6\n']
Note:
In the first sample all the participants get into one team, so there will be exactly ten pairs of friends.
In the second sample at any possible arrangement one team will always have two participants and the other team will always have one participant. Thus, the number of pairs of friends will always be equal to one.
In the third sample minimum number of newly formed friendships can be achieved if participants were split on teams consisting of 2 people, maximum number can be achieved if participants were split on teams of 1, 1 and 4 people. | ```python
items = input().split(" ")
n = int(items[0])
m = int(items[1])
def get_res(k):
return k * (k-1) // 2
if m == 1:
k_min = get_res(n)
k_max = get_res(n)
print(k_min, k_max)
else:
if n % m == 0:
k_min = get_res(n//m)
else:
k_min = get_res(n//m + 1)
k_max = get_res(n-(m-1))
print(k_min, k_max)
``` | 0 |
|
427 | B | Prison Transfer | PROGRAMMING | 1,100 | [
"data structures",
"implementation"
] | null | null | The prison of your city has *n* prisoners. As the prison can't accommodate all of them, the city mayor has decided to transfer *c* of the prisoners to a prison located in another city.
For this reason, he made the *n* prisoners to stand in a line, with a number written on their chests. The number is the severity of the crime he/she has committed. The greater the number, the more severe his/her crime was.
Then, the mayor told you to choose the *c* prisoners, who will be transferred to the other prison. He also imposed two conditions. They are,
- The chosen *c* prisoners has to form a contiguous segment of prisoners. - Any of the chosen prisoner's crime level should not be greater then *t*. Because, that will make the prisoner a severe criminal and the mayor doesn't want to take the risk of his running away during the transfer.
Find the number of ways you can choose the *c* prisoners. | The first line of input will contain three space separated integers *n* (1<=≤<=*n*<=≤<=2·105), *t* (0<=≤<=*t*<=≤<=109) and *c* (1<=≤<=*c*<=≤<=*n*). The next line will contain *n* space separated integers, the *i**th* integer is the severity *i**th* prisoner's crime. The value of crime severities will be non-negative and will not exceed 109. | Print a single integer — the number of ways you can choose the *c* prisoners. | [
"4 3 3\n2 3 1 1\n",
"1 1 1\n2\n",
"11 4 2\n2 2 0 7 3 2 2 4 9 1 4\n"
] | [
"2\n",
"0\n",
"6\n"
] | none | 1,000 | [
{
"input": "4 3 3\n2 3 1 1",
"output": "2"
},
{
"input": "1 1 1\n2",
"output": "0"
},
{
"input": "11 4 2\n2 2 0 7 3 2 2 4 9 1 4",
"output": "6"
},
{
"input": "57 2 10\n7 5 2 7 4 1 0 5 2 9 2 9 8 6 6 5 9 6 8 1 0 1 0 3 2 6 5 2 8 8 8 8 0 9 4 3 6 6 2 4 5 1 2 0 1 7 1 1 5 4 5 0 7 5 1 9 6",
"output": "0"
},
{
"input": "2 228885628 1\n90897004 258427916",
"output": "1"
},
{
"input": "3 1 1\n1 2 1",
"output": "2"
},
{
"input": "3 3 3\n3 2 3",
"output": "1"
},
{
"input": "4 2 2\n1 3 3 2",
"output": "0"
},
{
"input": "1 228 1\n1",
"output": "1"
}
] | 1,685,812,159 | 2,147,483,647 | PyPy 3-64 | RUNTIME_ERROR | TESTS | 5 | 139 | 25,600,000 | n,t,c=map(int,input().strip().split())
li=list(map(int,input().strip().split()))
di={}
# i=0
# # fli=[]
# while i<n:
# ct=0
# si=i
# maxi=li[i]
# while ct<c and i<n:
# if li[i]>maxi:
# maxi=li[i]
# ct+=1
# i+=1
# # lii=[maxi]*c
# # fli=fli+lii
# for j in range(si,i):
# di[j]=maxi
# ans=0
# si=0
# print(di)
# for i in range(0,n-c+1):
# if di[i]<=t:
# ans+=1
# print(ans)
i=0
ct=0
si=i
maxi=li[i]
while ct<c and i<n:
if li[i]>maxi:
maxi=li[i]
ct+=1
i+=1
di[si]=maxi
for i in range(1,n-c+1):
if li[c-1+i]>maxi:
maxi=li[c+i]
di[i]=maxi
ans=0
si=0
# print(di)
for i in range(0,n-c+1):
if di[i]<=t:
ans+=1
print(ans)
| Title: Prison Transfer
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The prison of your city has *n* prisoners. As the prison can't accommodate all of them, the city mayor has decided to transfer *c* of the prisoners to a prison located in another city.
For this reason, he made the *n* prisoners to stand in a line, with a number written on their chests. The number is the severity of the crime he/she has committed. The greater the number, the more severe his/her crime was.
Then, the mayor told you to choose the *c* prisoners, who will be transferred to the other prison. He also imposed two conditions. They are,
- The chosen *c* prisoners has to form a contiguous segment of prisoners. - Any of the chosen prisoner's crime level should not be greater then *t*. Because, that will make the prisoner a severe criminal and the mayor doesn't want to take the risk of his running away during the transfer.
Find the number of ways you can choose the *c* prisoners.
Input Specification:
The first line of input will contain three space separated integers *n* (1<=≤<=*n*<=≤<=2·105), *t* (0<=≤<=*t*<=≤<=109) and *c* (1<=≤<=*c*<=≤<=*n*). The next line will contain *n* space separated integers, the *i**th* integer is the severity *i**th* prisoner's crime. The value of crime severities will be non-negative and will not exceed 109.
Output Specification:
Print a single integer — the number of ways you can choose the *c* prisoners.
Demo Input:
['4 3 3\n2 3 1 1\n', '1 1 1\n2\n', '11 4 2\n2 2 0 7 3 2 2 4 9 1 4\n']
Demo Output:
['2\n', '0\n', '6\n']
Note:
none | ```python
n,t,c=map(int,input().strip().split())
li=list(map(int,input().strip().split()))
di={}
# i=0
# # fli=[]
# while i<n:
# ct=0
# si=i
# maxi=li[i]
# while ct<c and i<n:
# if li[i]>maxi:
# maxi=li[i]
# ct+=1
# i+=1
# # lii=[maxi]*c
# # fli=fli+lii
# for j in range(si,i):
# di[j]=maxi
# ans=0
# si=0
# print(di)
# for i in range(0,n-c+1):
# if di[i]<=t:
# ans+=1
# print(ans)
i=0
ct=0
si=i
maxi=li[i]
while ct<c and i<n:
if li[i]>maxi:
maxi=li[i]
ct+=1
i+=1
di[si]=maxi
for i in range(1,n-c+1):
if li[c-1+i]>maxi:
maxi=li[c+i]
di[i]=maxi
ans=0
si=0
# print(di)
for i in range(0,n-c+1):
if di[i]<=t:
ans+=1
print(ans)
``` | -1 |
|
225 | C | Barcode | PROGRAMMING | 1,700 | [
"dp",
"matrices"
] | null | null | You've got an *n*<=×<=*m* pixel picture. Each pixel can be white or black. Your task is to change the colors of as few pixels as possible to obtain a barcode picture.
A picture is a barcode if the following conditions are fulfilled:
- All pixels in each column are of the same color. - The width of each monochrome vertical line is at least *x* and at most *y* pixels. In other words, if we group all neighbouring columns of the pixels with equal color, the size of each group can not be less than *x* or greater than *y*. | The first line contains four space-separated integers *n*, *m*, *x* and *y* (1<=≤<=*n*,<=*m*,<=*x*,<=*y*<=≤<=1000; *x*<=≤<=*y*).
Then follow *n* lines, describing the original image. Each of these lines contains exactly *m* characters. Character "." represents a white pixel and "#" represents a black pixel. The picture description doesn't have any other characters besides "." and "#". | In the first line print the minimum number of pixels to repaint. It is guaranteed that the answer exists. | [
"6 5 1 2\n##.#.\n.###.\n###..\n#...#\n.##.#\n###..\n",
"2 5 1 1\n#####\n.....\n"
] | [
"11\n",
"5\n"
] | In the first test sample the picture after changing some colors can looks as follows:
In the second test sample the picture after changing some colors can looks as follows: | 1,500 | [
{
"input": "6 5 1 2\n##.#.\n.###.\n###..\n#...#\n.##.#\n###..",
"output": "11"
},
{
"input": "10 5 3 7\n.####\n###..\n##.##\n#..#.\n.#...\n#.##.\n.##..\n.#.##\n#.#..\n.#..#",
"output": "24"
},
{
"input": "6 3 1 4\n##.\n#..\n#..\n..#\n.#.\n#.#",
"output": "6"
},
{
"input": "5 10 4 16\n.#####....\n##..#..##.\n.#..##.#..\n##..#####.\n...#.##..#",
"output": "21"
},
{
"input": "5 4 1 4\n####\n..##\n##..\n..#.\n#..#",
"output": "8"
},
{
"input": "1 1 1 2\n.",
"output": "0"
},
{
"input": "3 44 2 18\n####..###.#.##........##...###.####.#.....##\n...#....##.###.###.##.#####.#######.#..#..#.\n#...#.####.#.##.#.#.#.....##.##..###.#....##",
"output": "39"
},
{
"input": "69 1 1 2\n#\n.\n#\n#\n.\n#\n#\n.\n.\n#\n.\n.\n#\n.\n#\n#\n.\n#\n#\n#\n#\n#\n.\n#\n.\n.\n#\n#\n#\n.\n.\n.\n.\n#\n#\n.\n#\n#\n.\n#\n.\n.\n#\n.\n.\n.\n#\n.\n.\n#\n#\n.\n.\n#\n.\n.\n.\n#\n#\n#\n#\n#\n.\n#\n.\n#\n#\n#\n#",
"output": "31"
},
{
"input": "56 2 2 2\n##\n##\n##\n..\n..\n##\n.#\n#.\n..\n##\n##\n..\n..\n#.\n#.\n#.\n#.\n##\n..\n.#\n..\n##\n##\n.#\n#.\n.#\n..\n..\n#.\n..\n##\n..\n#.\n.#\n#.\n#.\n#.\n##\n#.\n##\n##\n.#\n#.\n##\n..\n.#\n#.\n#.\n##\n..\n..\n#.\n##\n..\n..\n##",
"output": "55"
}
] | 1,615,372,684 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 0 | 154 | 0 | from math import inf
n,m,x,y=map(int,input().split())
matx=[]
for i in range(n):
matx.append(list(input().strip()))
d=[[0,0]]
for i in range(m):
c=0
for j in range(n):
if matx[j][i]=='.':
c+=1
d.append([c,n-c])
print(d)
for i in range(1,m+1):
d[i][0]+=d[i-1][0]
d[i][1]+=d[i-1][1]
#dp[n][0,1][p]
dp=[[1000,1000]for j in range(m+1)]
dp[0]=[0,0]
dp[x]=[d[x][0],d[x][1]]
for i in range(x,m+1):
for j in range(x,min(y+1,i+1)):
dp[i][0]=min(dp[i-j][1]+d[i][0]-d[i-j][0],dp[i][0])
dp[i][1]=min(dp[i-j][0]+d[i][1]-d[i-j][1],dp[i][1])
#A&print(dp)
print(min(dp[-1]))
| Title: Barcode
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You've got an *n*<=×<=*m* pixel picture. Each pixel can be white or black. Your task is to change the colors of as few pixels as possible to obtain a barcode picture.
A picture is a barcode if the following conditions are fulfilled:
- All pixels in each column are of the same color. - The width of each monochrome vertical line is at least *x* and at most *y* pixels. In other words, if we group all neighbouring columns of the pixels with equal color, the size of each group can not be less than *x* or greater than *y*.
Input Specification:
The first line contains four space-separated integers *n*, *m*, *x* and *y* (1<=≤<=*n*,<=*m*,<=*x*,<=*y*<=≤<=1000; *x*<=≤<=*y*).
Then follow *n* lines, describing the original image. Each of these lines contains exactly *m* characters. Character "." represents a white pixel and "#" represents a black pixel. The picture description doesn't have any other characters besides "." and "#".
Output Specification:
In the first line print the minimum number of pixels to repaint. It is guaranteed that the answer exists.
Demo Input:
['6 5 1 2\n##.#.\n.###.\n###..\n#...#\n.##.#\n###..\n', '2 5 1 1\n#####\n.....\n']
Demo Output:
['11\n', '5\n']
Note:
In the first test sample the picture after changing some colors can looks as follows:
In the second test sample the picture after changing some colors can looks as follows: | ```python
from math import inf
n,m,x,y=map(int,input().split())
matx=[]
for i in range(n):
matx.append(list(input().strip()))
d=[[0,0]]
for i in range(m):
c=0
for j in range(n):
if matx[j][i]=='.':
c+=1
d.append([c,n-c])
print(d)
for i in range(1,m+1):
d[i][0]+=d[i-1][0]
d[i][1]+=d[i-1][1]
#dp[n][0,1][p]
dp=[[1000,1000]for j in range(m+1)]
dp[0]=[0,0]
dp[x]=[d[x][0],d[x][1]]
for i in range(x,m+1):
for j in range(x,min(y+1,i+1)):
dp[i][0]=min(dp[i-j][1]+d[i][0]-d[i-j][0],dp[i][0])
dp[i][1]=min(dp[i-j][0]+d[i][1]-d[i-j][1],dp[i][1])
#A&print(dp)
print(min(dp[-1]))
``` | 0 |
|
984 | B | Minesweeper | PROGRAMMING | 1,100 | [
"implementation"
] | null | null | One day Alex decided to remember childhood when computers were not too powerful and lots of people played only default games. Alex enjoyed playing Minesweeper that time. He imagined that he saved world from bombs planted by terrorists, but he rarely won.
Alex has grown up since then, so he easily wins the most difficult levels. This quickly bored him, and he thought: what if the computer gave him invalid fields in the childhood and Alex could not win because of it?
He needs your help to check it.
A Minesweeper field is a rectangle $n \times m$, where each cell is either empty, or contains a digit from $1$ to $8$, or a bomb. The field is valid if for each cell:
- if there is a digit $k$ in the cell, then exactly $k$ neighboring cells have bombs. - if the cell is empty, then all neighboring cells have no bombs.
Two cells are neighbors if they have a common side or a corner (i. e. a cell has at most $8$ neighboring cells). | The first line contains two integers $n$ and $m$ ($1 \le n, m \le 100$) — the sizes of the field.
The next $n$ lines contain the description of the field. Each line contains $m$ characters, each of them is "." (if this cell is empty), "*" (if there is bomb in this cell), or a digit from $1$ to $8$, inclusive. | Print "YES", if the field is valid and "NO" otherwise.
You can choose the case (lower or upper) for each letter arbitrarily. | [
"3 3\n111\n1*1\n111\n",
"2 4\n*.*.\n1211\n"
] | [
"YES",
"NO"
] | In the second example the answer is "NO" because, if the positions of the bombs are preserved, the first line of the field should be *2*1.
You can read more about Minesweeper in [Wikipedia's article](https://en.wikipedia.org/wiki/Minesweeper_(video_game)). | 1,000 | [
{
"input": "3 3\n111\n1*1\n111",
"output": "YES"
},
{
"input": "2 4\n*.*.\n1211",
"output": "NO"
},
{
"input": "1 10\n.....1*1..",
"output": "YES"
},
{
"input": "1 1\n4",
"output": "NO"
},
{
"input": "10 10\n..........\n...111111.\n..13*21*1.\n.12**2111.\n.1*542..11\n.13**1..1*\n..2*31..11\n..111..111\n.......1*1\n.......111",
"output": "YES"
},
{
"input": "10 17\n12*2*22123*31....\n2*333*3*4***3211.\n*22*213**4***3*1.\n11111.12224*6*21.\n221..111.14**4311\n**2233*212****2*1\n*55***4*13*544421\n2***54*322*21**31\n13*4*33*221114*4*\n.1122*22*1...2*31",
"output": "YES"
},
{
"input": "10 10\n**********\n**********\n**********\n**********\n**********\n******3***\n**********\n**********\n**********\n***3.5****",
"output": "NO"
},
{
"input": "21 10\n62637783*1\n23*51**531\n35*7*6.**.\n.*3***581*\n2.32*745**\n83*7*6*6*5\n*74.**6**3\n323*6**7*6\n3454*67.*1\n**63265*6*\n3725*4553*\n24****5**4\n23.34****4\n55257*1*4*\n4*3253*456\n**.3*45488\n*7318**4*5\n234.*4557*\n12..21*.*3\n286.225*4*\n834*11*.3*",
"output": "NO"
},
{
"input": "10 10\n**********\n*********6\n*********5\n**********\n**********\n**********\n**********\n**********\n**********\n**********",
"output": "NO"
},
{
"input": "100 1\n.\n.\n.\n.\n1\n*\n2\n*\n1\n.\n.\n.\n.\n.\n.\n1\n*\n1\n1\n*\n1\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n1\n*\n2\n*\n*\n*\n1\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n1\n*\n2\n*\n1\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.",
"output": "YES"
},
{
"input": "1 100\n*************5****5****************************************************4****************************",
"output": "NO"
},
{
"input": "1 100\n.....1*1........1*1................................1*1...1**11*1.......1*1....1.....1*1.....1*1...1*",
"output": "NO"
},
{
"input": "1 10\n881111882*",
"output": "NO"
},
{
"input": "5 5\n*2221\n24**2\n*3*5*\n3425*\n**12*",
"output": "NO"
},
{
"input": "5 5\n****2\n4***4\n3****\n3*563\n*22**",
"output": "NO"
},
{
"input": "5 5\n***2.\n5**31\n**6**\n***43\n**31*",
"output": "NO"
},
{
"input": "5 5\n*32**\n4*3*4\n**44*\n**45*\n*4***",
"output": "NO"
},
{
"input": "3 3\n***\n*2*\n***",
"output": "NO"
},
{
"input": "1 1\n*",
"output": "YES"
},
{
"input": "1 2\n*1",
"output": "YES"
},
{
"input": "1 2\n*2",
"output": "NO"
},
{
"input": "2 2\n32\n**",
"output": "NO"
},
{
"input": "3 3\n...\n232\n***",
"output": "YES"
},
{
"input": "3 2\n..\n11\n.*",
"output": "NO"
},
{
"input": "2 3\n1*2\n3*2",
"output": "NO"
},
{
"input": "1 3\n.*.",
"output": "NO"
},
{
"input": "3 1\n.\n*\n.",
"output": "NO"
},
{
"input": "3 1\n1\n*\n1",
"output": "YES"
},
{
"input": "3 1\n*\n1\n*",
"output": "NO"
},
{
"input": "1 3\n1**",
"output": "YES"
},
{
"input": "1 1\n8",
"output": "NO"
},
{
"input": "1 1\n.",
"output": "YES"
},
{
"input": "1 2\n2*",
"output": "NO"
},
{
"input": "2 1\n*\n2",
"output": "NO"
},
{
"input": "2 1\n*\n*",
"output": "YES"
},
{
"input": "2 1\n.\n1",
"output": "NO"
},
{
"input": "1 3\n..1",
"output": "NO"
},
{
"input": "3 3\n112\n1*1\n111",
"output": "NO"
},
{
"input": "3 3\n11.\n1*1\n111",
"output": "NO"
},
{
"input": "3 3\n151\n1*1\n111",
"output": "NO"
},
{
"input": "3 3\n1.1\n1*1\n111",
"output": "NO"
},
{
"input": "3 3\n611\n1*1\n111",
"output": "NO"
},
{
"input": "3 3\n.11\n1*1\n111",
"output": "NO"
},
{
"input": "3 3\n111\n2*1\n111",
"output": "NO"
},
{
"input": "3 3\n111\n**1\n111",
"output": "NO"
},
{
"input": "3 3\n111\n5*1\n111",
"output": "NO"
},
{
"input": "3 3\n111\n.*1\n111",
"output": "NO"
},
{
"input": "3 3\n111\n1*1\n411",
"output": "NO"
},
{
"input": "3 3\n111\n1*1\n.11",
"output": "NO"
},
{
"input": "3 3\n111\n1*1\n121",
"output": "NO"
},
{
"input": "3 3\n111\n1*1\n1.1",
"output": "NO"
},
{
"input": "3 3\n111\n1*1\n115",
"output": "NO"
},
{
"input": "3 3\n111\n1*1\n11.",
"output": "NO"
},
{
"input": "3 3\n111\n1*4\n111",
"output": "NO"
},
{
"input": "3 3\n111\n1*.\n111",
"output": "NO"
},
{
"input": "1 4\n*222",
"output": "NO"
},
{
"input": "1 1\n*",
"output": "YES"
},
{
"input": "2 2\n**\n**",
"output": "YES"
},
{
"input": "3 3\n***\n*.*\n***",
"output": "NO"
},
{
"input": "3 3\n***\n***\n***",
"output": "YES"
},
{
"input": "3 3\n***\n*4*\n***",
"output": "NO"
},
{
"input": "2 6\n....1.\n.....*",
"output": "NO"
},
{
"input": "5 5\n*****\n*****\n*****\n*****\n*****",
"output": "YES"
},
{
"input": "4 1\n.\n*\n.\n.",
"output": "NO"
},
{
"input": "2 2\n2*\n11",
"output": "NO"
},
{
"input": "3 3\n888\n888\n888",
"output": "NO"
},
{
"input": "1 4\n*22*",
"output": "NO"
}
] | 1,662,002,040 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 31 | 0 | import sys,os,io
input = sys.stdin.readlines
def inlt():
return(list(map(int,input().split())))
grid = input()[1:]
for i in range(len(grid)):
grid[i] = list(grid[i][:-1])
print(grid)
def check(grid,i,j):
count = 0
if 0 <= i - 1 < len(grid):
if 0 <= j + 1 < len(grid[i]):
if grid[i - 1][j + 1] == '*':
count += 1
if 0 <= j < len(grid[i]):
if grid[i - 1][j] == '*':
count += 1
if 0 <= j - 1 < len(grid[i]):
if grid[i - 1][j - 1] == '*':
count += 1
if 0 <= i + 1 < len(grid):
if 0 <= j + 1 < len(grid[i]):
if grid[i + 1][j + 1] == '*':
count += 1
if 0 <= j < len(grid[i]):
if grid[i + 1][j] == '*':
count += 1
if 0 <= j - 1 < len(grid[i]):
if grid[i + 1][j - 1] == '*':
count += 1
if 0 <= j - 1 < len(grid[i]):
if grid[i][j - 1] == '*':
count += 1
if 0 <= j + 1 < len(grid[i]):
if grid[i][j + 1] == '*':
count += 1
return count
flag = 0
for i in range(len(grid)):
for j in range(len(grid[i])):
if grid[i][j].isnumeric():
x = int(grid[i][j])
if x != check(grid,i,j):
flag = 1
break
if grid[i][j] == '.':
if check(grid,i,j) != 0:
flag = 1
break
print("YES") if flag == 0 else print("NO")
| Title: Minesweeper
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
One day Alex decided to remember childhood when computers were not too powerful and lots of people played only default games. Alex enjoyed playing Minesweeper that time. He imagined that he saved world from bombs planted by terrorists, but he rarely won.
Alex has grown up since then, so he easily wins the most difficult levels. This quickly bored him, and he thought: what if the computer gave him invalid fields in the childhood and Alex could not win because of it?
He needs your help to check it.
A Minesweeper field is a rectangle $n \times m$, where each cell is either empty, or contains a digit from $1$ to $8$, or a bomb. The field is valid if for each cell:
- if there is a digit $k$ in the cell, then exactly $k$ neighboring cells have bombs. - if the cell is empty, then all neighboring cells have no bombs.
Two cells are neighbors if they have a common side or a corner (i. e. a cell has at most $8$ neighboring cells).
Input Specification:
The first line contains two integers $n$ and $m$ ($1 \le n, m \le 100$) — the sizes of the field.
The next $n$ lines contain the description of the field. Each line contains $m$ characters, each of them is "." (if this cell is empty), "*" (if there is bomb in this cell), or a digit from $1$ to $8$, inclusive.
Output Specification:
Print "YES", if the field is valid and "NO" otherwise.
You can choose the case (lower or upper) for each letter arbitrarily.
Demo Input:
['3 3\n111\n1*1\n111\n', '2 4\n*.*.\n1211\n']
Demo Output:
['YES', 'NO']
Note:
In the second example the answer is "NO" because, if the positions of the bombs are preserved, the first line of the field should be *2*1.
You can read more about Minesweeper in [Wikipedia's article](https://en.wikipedia.org/wiki/Minesweeper_(video_game)). | ```python
import sys,os,io
input = sys.stdin.readlines
def inlt():
return(list(map(int,input().split())))
grid = input()[1:]
for i in range(len(grid)):
grid[i] = list(grid[i][:-1])
print(grid)
def check(grid,i,j):
count = 0
if 0 <= i - 1 < len(grid):
if 0 <= j + 1 < len(grid[i]):
if grid[i - 1][j + 1] == '*':
count += 1
if 0 <= j < len(grid[i]):
if grid[i - 1][j] == '*':
count += 1
if 0 <= j - 1 < len(grid[i]):
if grid[i - 1][j - 1] == '*':
count += 1
if 0 <= i + 1 < len(grid):
if 0 <= j + 1 < len(grid[i]):
if grid[i + 1][j + 1] == '*':
count += 1
if 0 <= j < len(grid[i]):
if grid[i + 1][j] == '*':
count += 1
if 0 <= j - 1 < len(grid[i]):
if grid[i + 1][j - 1] == '*':
count += 1
if 0 <= j - 1 < len(grid[i]):
if grid[i][j - 1] == '*':
count += 1
if 0 <= j + 1 < len(grid[i]):
if grid[i][j + 1] == '*':
count += 1
return count
flag = 0
for i in range(len(grid)):
for j in range(len(grid[i])):
if grid[i][j].isnumeric():
x = int(grid[i][j])
if x != check(grid,i,j):
flag = 1
break
if grid[i][j] == '.':
if check(grid,i,j) != 0:
flag = 1
break
print("YES") if flag == 0 else print("NO")
``` | 0 |
|
268 | A | Games | PROGRAMMING | 800 | [
"brute force"
] | null | null | Manao works on a sports TV. He's spent much time watching the football games of some country. After a while he began to notice different patterns. For example, each team has two sets of uniforms: home uniform and guest uniform. When a team plays a game at home, the players put on the home uniform. When a team plays as a guest on somebody else's stadium, the players put on the guest uniform. The only exception to that rule is: when the home uniform color of the host team matches the guests' uniform, the host team puts on its guest uniform as well. For each team the color of the home and guest uniform is different.
There are *n* teams taking part in the national championship. The championship consists of *n*·(*n*<=-<=1) games: each team invites each other team to its stadium. At this point Manao wondered: how many times during the championship is a host team going to put on the guest uniform? Note that the order of the games does not affect this number.
You know the colors of the home and guest uniform for each team. For simplicity, the colors are numbered by integers in such a way that no two distinct colors have the same number. Help Manao find the answer to his question. | The first line contains an integer *n* (2<=≤<=*n*<=≤<=30). Each of the following *n* lines contains a pair of distinct space-separated integers *h**i*, *a**i* (1<=≤<=*h**i*,<=*a**i*<=≤<=100) — the colors of the *i*-th team's home and guest uniforms, respectively. | In a single line print the number of games where the host team is going to play in the guest uniform. | [
"3\n1 2\n2 4\n3 4\n",
"4\n100 42\n42 100\n5 42\n100 5\n",
"2\n1 2\n1 2\n"
] | [
"1\n",
"5\n",
"0\n"
] | In the first test case the championship consists of 6 games. The only game with the event in question is the game between teams 2 and 1 on the stadium of team 2.
In the second test sample the host team will have to wear guest uniform in the games between teams: 1 and 2, 2 and 1, 2 and 3, 3 and 4, 4 and 2 (the host team is written first). | 500 | [
{
"input": "3\n1 2\n2 4\n3 4",
"output": "1"
},
{
"input": "4\n100 42\n42 100\n5 42\n100 5",
"output": "5"
},
{
"input": "2\n1 2\n1 2",
"output": "0"
},
{
"input": "7\n4 7\n52 55\n16 4\n55 4\n20 99\n3 4\n7 52",
"output": "6"
},
{
"input": "10\n68 42\n1 35\n25 70\n59 79\n65 63\n46 6\n28 82\n92 62\n43 96\n37 28",
"output": "1"
},
{
"input": "30\n10 39\n89 1\n78 58\n75 99\n36 13\n77 50\n6 97\n79 28\n27 52\n56 5\n93 96\n40 21\n33 74\n26 37\n53 59\n98 56\n61 65\n42 57\n9 7\n25 63\n74 34\n96 84\n95 47\n12 23\n34 21\n71 6\n27 13\n15 47\n64 14\n12 77",
"output": "6"
},
{
"input": "30\n46 100\n87 53\n34 84\n44 66\n23 20\n50 34\n90 66\n17 39\n13 22\n94 33\n92 46\n63 78\n26 48\n44 61\n3 19\n41 84\n62 31\n65 89\n23 28\n58 57\n19 85\n26 60\n75 66\n69 67\n76 15\n64 15\n36 72\n90 89\n42 69\n45 35",
"output": "4"
},
{
"input": "2\n46 6\n6 46",
"output": "2"
},
{
"input": "29\n8 18\n33 75\n69 22\n97 95\n1 97\n78 10\n88 18\n13 3\n19 64\n98 12\n79 92\n41 72\n69 15\n98 31\n57 74\n15 56\n36 37\n15 66\n63 100\n16 42\n47 56\n6 4\n73 15\n30 24\n27 71\n12 19\n88 69\n85 6\n50 11",
"output": "10"
},
{
"input": "23\n43 78\n31 28\n58 80\n66 63\n20 4\n51 95\n40 20\n50 14\n5 34\n36 39\n77 42\n64 97\n62 89\n16 56\n8 34\n58 16\n37 35\n37 66\n8 54\n50 36\n24 8\n68 48\n85 33",
"output": "6"
},
{
"input": "13\n76 58\n32 85\n99 79\n23 58\n96 59\n72 35\n53 43\n96 55\n41 78\n75 10\n28 11\n72 7\n52 73",
"output": "0"
},
{
"input": "18\n6 90\n70 79\n26 52\n67 81\n29 95\n41 32\n94 88\n18 58\n59 65\n51 56\n64 68\n34 2\n6 98\n95 82\n34 2\n40 98\n83 78\n29 2",
"output": "1"
},
{
"input": "18\n6 90\n100 79\n26 100\n67 100\n29 100\n100 32\n94 88\n18 58\n59 65\n51 56\n64 68\n34 2\n6 98\n95 82\n34 2\n40 98\n83 78\n29 100",
"output": "8"
},
{
"input": "30\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1",
"output": "450"
},
{
"input": "30\n100 99\n58 59\n56 57\n54 55\n52 53\n50 51\n48 49\n46 47\n44 45\n42 43\n40 41\n38 39\n36 37\n34 35\n32 33\n30 31\n28 29\n26 27\n24 25\n22 23\n20 21\n18 19\n16 17\n14 15\n12 13\n10 11\n8 9\n6 7\n4 5\n2 3",
"output": "0"
},
{
"input": "15\n9 3\n2 6\n7 6\n5 10\n9 5\n8 1\n10 5\n2 8\n4 5\n9 8\n5 3\n3 8\n9 8\n4 10\n8 5",
"output": "20"
},
{
"input": "15\n2 1\n1 2\n1 2\n1 2\n2 1\n2 1\n2 1\n1 2\n2 1\n2 1\n2 1\n1 2\n2 1\n2 1\n1 2",
"output": "108"
},
{
"input": "25\n2 1\n1 2\n1 2\n1 2\n2 1\n1 2\n1 2\n1 2\n2 1\n2 1\n2 1\n1 2\n1 2\n1 2\n2 1\n2 1\n2 1\n1 2\n2 1\n1 2\n2 1\n2 1\n2 1\n2 1\n1 2",
"output": "312"
},
{
"input": "25\n91 57\n2 73\n54 57\n2 57\n23 57\n2 6\n57 54\n57 23\n91 54\n91 23\n57 23\n91 57\n54 2\n6 91\n57 54\n2 57\n57 91\n73 91\n57 23\n91 57\n2 73\n91 2\n23 6\n2 73\n23 6",
"output": "96"
},
{
"input": "28\n31 66\n31 91\n91 31\n97 66\n31 66\n31 66\n66 91\n91 31\n97 31\n91 97\n97 31\n66 31\n66 97\n91 31\n31 66\n31 66\n66 31\n31 97\n66 97\n97 31\n31 91\n66 91\n91 66\n31 66\n91 66\n66 31\n66 31\n91 97",
"output": "210"
},
{
"input": "29\n78 27\n50 68\n24 26\n68 43\n38 78\n26 38\n78 28\n28 26\n27 24\n23 38\n24 26\n24 43\n61 50\n38 78\n27 23\n61 26\n27 28\n43 23\n28 78\n43 27\n43 78\n27 61\n28 38\n61 78\n50 26\n43 27\n26 78\n28 50\n43 78",
"output": "73"
},
{
"input": "29\n80 27\n69 80\n27 80\n69 80\n80 27\n80 27\n80 27\n80 69\n27 69\n80 69\n80 27\n27 69\n69 27\n80 69\n27 69\n69 80\n27 69\n80 69\n80 27\n69 27\n27 69\n27 80\n80 27\n69 80\n27 69\n80 69\n69 80\n69 80\n27 80",
"output": "277"
},
{
"input": "30\n19 71\n7 89\n89 71\n21 7\n19 21\n7 89\n19 71\n89 8\n89 21\n19 8\n21 7\n8 89\n19 89\n7 21\n19 8\n19 7\n7 19\n8 21\n71 21\n71 89\n7 19\n7 19\n21 7\n21 19\n21 19\n71 8\n21 8\n71 19\n19 71\n8 21",
"output": "154"
},
{
"input": "30\n44 17\n44 17\n44 17\n17 44\n44 17\n44 17\n17 44\n17 44\n17 44\n44 17\n44 17\n44 17\n44 17\n44 17\n17 44\n17 44\n17 44\n44 17\n44 17\n17 44\n44 17\n44 17\n44 17\n17 44\n17 44\n44 17\n17 44\n44 17\n44 17\n44 17",
"output": "418"
},
{
"input": "22\n78 92\n15 92\n92 78\n78 80\n92 16\n24 80\n92 16\n16 92\n78 16\n24 78\n80 78\n92 80\n16 80\n80 78\n15 78\n92 16\n24 15\n24 80\n80 16\n16 80\n92 80\n24 80",
"output": "74"
},
{
"input": "24\n9 83\n90 31\n83 3\n83 3\n21 31\n83 3\n32 31\n12 21\n31 21\n90 32\n32 21\n12 9\n12 31\n9 83\n83 12\n32 3\n32 83\n90 31\n9 32\n31 21\n83 90\n32 21\n21 3\n32 9",
"output": "59"
},
{
"input": "30\n67 21\n85 39\n85 87\n21 39\n66 85\n10 95\n10 21\n87 85\n82 21\n67 21\n95 10\n21 39\n82 21\n21 66\n66 39\n95 30\n67 85\n66 82\n85 82\n21 66\n10 39\n67 10\n21 85\n10 82\n85 95\n10 85\n21 39\n85 39\n39 10\n95 67",
"output": "100"
},
{
"input": "4\n8 7\n8 7\n7 8\n7 8",
"output": "8"
},
{
"input": "6\n1 2\n1 2\n1 2\n1 2\n1 2\n2 1",
"output": "10"
},
{
"input": "12\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1",
"output": "72"
},
{
"input": "4\n1 2\n1 2\n2 1\n2 1",
"output": "8"
}
] | 1,673,285,663 | 2,147,483,647 | Python 3 | OK | TESTS | 31 | 92 | 0 | teams = int(input())
homeKit = [None] * teams
guestKit = [None] * teams
for i in range(teams):
homeKit[i], guestKit[i] = map(int, input().split())
guestUni = 0
for i in range(teams):
for j in range(teams):
if i == j:
continue
if homeKit[i] == guestKit[j]:
guestUni += 1
print(guestUni)
| Title: Games
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Manao works on a sports TV. He's spent much time watching the football games of some country. After a while he began to notice different patterns. For example, each team has two sets of uniforms: home uniform and guest uniform. When a team plays a game at home, the players put on the home uniform. When a team plays as a guest on somebody else's stadium, the players put on the guest uniform. The only exception to that rule is: when the home uniform color of the host team matches the guests' uniform, the host team puts on its guest uniform as well. For each team the color of the home and guest uniform is different.
There are *n* teams taking part in the national championship. The championship consists of *n*·(*n*<=-<=1) games: each team invites each other team to its stadium. At this point Manao wondered: how many times during the championship is a host team going to put on the guest uniform? Note that the order of the games does not affect this number.
You know the colors of the home and guest uniform for each team. For simplicity, the colors are numbered by integers in such a way that no two distinct colors have the same number. Help Manao find the answer to his question.
Input Specification:
The first line contains an integer *n* (2<=≤<=*n*<=≤<=30). Each of the following *n* lines contains a pair of distinct space-separated integers *h**i*, *a**i* (1<=≤<=*h**i*,<=*a**i*<=≤<=100) — the colors of the *i*-th team's home and guest uniforms, respectively.
Output Specification:
In a single line print the number of games where the host team is going to play in the guest uniform.
Demo Input:
['3\n1 2\n2 4\n3 4\n', '4\n100 42\n42 100\n5 42\n100 5\n', '2\n1 2\n1 2\n']
Demo Output:
['1\n', '5\n', '0\n']
Note:
In the first test case the championship consists of 6 games. The only game with the event in question is the game between teams 2 and 1 on the stadium of team 2.
In the second test sample the host team will have to wear guest uniform in the games between teams: 1 and 2, 2 and 1, 2 and 3, 3 and 4, 4 and 2 (the host team is written first). | ```python
teams = int(input())
homeKit = [None] * teams
guestKit = [None] * teams
for i in range(teams):
homeKit[i], guestKit[i] = map(int, input().split())
guestUni = 0
for i in range(teams):
for j in range(teams):
if i == j:
continue
if homeKit[i] == guestKit[j]:
guestUni += 1
print(guestUni)
``` | 3 |
|
1,009 | A | Game Shopping | PROGRAMMING | 800 | [
"implementation"
] | null | null | Maxim wants to buy some games at the local game shop. There are $n$ games in the shop, the $i$-th game costs $c_i$.
Maxim has a wallet which can be represented as an array of integers. His wallet contains $m$ bills, the $j$-th bill has value $a_j$.
Games in the shop are ordered from left to right, Maxim tries to buy every game in that order.
When Maxim stands at the position $i$ in the shop, he takes the first bill from his wallet (if his wallet is empty then he proceeds to the next position immediately) and tries to buy the $i$-th game using this bill. After Maxim tried to buy the $n$-th game, he leaves the shop.
Maxim buys the $i$-th game if and only if the value of the first bill (which he takes) from his wallet is greater or equal to the cost of the $i$-th game. If he successfully buys the $i$-th game, the first bill from his wallet disappears and the next bill becomes first. Otherwise Maxim leaves the first bill in his wallet (this bill still remains the first one) and proceeds to the next game.
For example, for array $c = [2, 4, 5, 2, 4]$ and array $a = [5, 3, 4, 6]$ the following process takes place: Maxim buys the first game using the first bill (its value is $5$), the bill disappears, after that the second bill (with value $3$) becomes the first one in Maxim's wallet, then Maxim doesn't buy the second game because $c_2 > a_2$, the same with the third game, then he buys the fourth game using the bill of value $a_2$ (the third bill becomes the first one in Maxim's wallet) and buys the fifth game using the bill of value $a_3$.
Your task is to get the number of games Maxim will buy. | The first line of the input contains two integers $n$ and $m$ ($1 \le n, m \le 1000$) — the number of games and the number of bills in Maxim's wallet.
The second line of the input contains $n$ integers $c_1, c_2, \dots, c_n$ ($1 \le c_i \le 1000$), where $c_i$ is the cost of the $i$-th game.
The third line of the input contains $m$ integers $a_1, a_2, \dots, a_m$ ($1 \le a_j \le 1000$), where $a_j$ is the value of the $j$-th bill from the Maxim's wallet. | Print a single integer — the number of games Maxim will buy. | [
"5 4\n2 4 5 2 4\n5 3 4 6\n",
"5 2\n20 40 50 20 40\n19 20\n",
"6 4\n4 8 15 16 23 42\n1000 1000 1000 1000\n"
] | [
"3\n",
"0\n",
"4\n"
] | The first example is described in the problem statement.
In the second example Maxim cannot buy any game because the value of the first bill in his wallet is smaller than the cost of any game in the shop.
In the third example the values of the bills in Maxim's wallet are large enough to buy any game he encounter until he runs out of bills in his wallet. | 0 | [
{
"input": "5 4\n2 4 5 2 4\n5 3 4 6",
"output": "3"
},
{
"input": "5 2\n20 40 50 20 40\n19 20",
"output": "0"
},
{
"input": "6 4\n4 8 15 16 23 42\n1000 1000 1000 1000",
"output": "4"
},
{
"input": "5 1\n1 1 1 1 1\n5",
"output": "1"
},
{
"input": "5 1\n10 1 1 1 1\n1000",
"output": "1"
},
{
"input": "5 1\n100 100 100 100 100\n100",
"output": "1"
},
{
"input": "2 1\n2 1\n1",
"output": "1"
},
{
"input": "2 3\n3 1\n2 4 2",
"output": "1"
},
{
"input": "1 5\n4\n1 4 3 3 2",
"output": "0"
},
{
"input": "5 3\n4 2 3 1 1\n2 1 3",
"output": "3"
},
{
"input": "3 5\n5 2 5\n1 4 1 4 2",
"output": "0"
},
{
"input": "7 3\n9 7 10 2 1 1 1\n8 9 6",
"output": "3"
},
{
"input": "5 3\n2 5 3 3 2\n2 5 3",
"output": "3"
}
] | 1,555,662,827 | 2,147,483,647 | Python 3 | OK | TESTS | 19 | 124 | 307,200 | def main():
[n_games, n_bills] = [int(_) for _ in input().split()]
game_prices = [0] + [int(_) for _ in input().split()]
bills = [0] + [int(_) for _ in input().split()]
last_game = 0
last_bill = 0
count_games_bought = 0
while last_game < n_games and last_bill < n_bills:
last_bill += 1
bill = bills[last_bill]
try:
last_game = next(g for g in range(last_game + 1, n_games + 1) if game_prices[g] <= bill)
count_games_bought += 1
except StopIteration:
last_game = n_games
print(count_games_bought)
if __name__ == '__main__':
main()
| Title: Game Shopping
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Maxim wants to buy some games at the local game shop. There are $n$ games in the shop, the $i$-th game costs $c_i$.
Maxim has a wallet which can be represented as an array of integers. His wallet contains $m$ bills, the $j$-th bill has value $a_j$.
Games in the shop are ordered from left to right, Maxim tries to buy every game in that order.
When Maxim stands at the position $i$ in the shop, he takes the first bill from his wallet (if his wallet is empty then he proceeds to the next position immediately) and tries to buy the $i$-th game using this bill. After Maxim tried to buy the $n$-th game, he leaves the shop.
Maxim buys the $i$-th game if and only if the value of the first bill (which he takes) from his wallet is greater or equal to the cost of the $i$-th game. If he successfully buys the $i$-th game, the first bill from his wallet disappears and the next bill becomes first. Otherwise Maxim leaves the first bill in his wallet (this bill still remains the first one) and proceeds to the next game.
For example, for array $c = [2, 4, 5, 2, 4]$ and array $a = [5, 3, 4, 6]$ the following process takes place: Maxim buys the first game using the first bill (its value is $5$), the bill disappears, after that the second bill (with value $3$) becomes the first one in Maxim's wallet, then Maxim doesn't buy the second game because $c_2 > a_2$, the same with the third game, then he buys the fourth game using the bill of value $a_2$ (the third bill becomes the first one in Maxim's wallet) and buys the fifth game using the bill of value $a_3$.
Your task is to get the number of games Maxim will buy.
Input Specification:
The first line of the input contains two integers $n$ and $m$ ($1 \le n, m \le 1000$) — the number of games and the number of bills in Maxim's wallet.
The second line of the input contains $n$ integers $c_1, c_2, \dots, c_n$ ($1 \le c_i \le 1000$), where $c_i$ is the cost of the $i$-th game.
The third line of the input contains $m$ integers $a_1, a_2, \dots, a_m$ ($1 \le a_j \le 1000$), where $a_j$ is the value of the $j$-th bill from the Maxim's wallet.
Output Specification:
Print a single integer — the number of games Maxim will buy.
Demo Input:
['5 4\n2 4 5 2 4\n5 3 4 6\n', '5 2\n20 40 50 20 40\n19 20\n', '6 4\n4 8 15 16 23 42\n1000 1000 1000 1000\n']
Demo Output:
['3\n', '0\n', '4\n']
Note:
The first example is described in the problem statement.
In the second example Maxim cannot buy any game because the value of the first bill in his wallet is smaller than the cost of any game in the shop.
In the third example the values of the bills in Maxim's wallet are large enough to buy any game he encounter until he runs out of bills in his wallet. | ```python
def main():
[n_games, n_bills] = [int(_) for _ in input().split()]
game_prices = [0] + [int(_) for _ in input().split()]
bills = [0] + [int(_) for _ in input().split()]
last_game = 0
last_bill = 0
count_games_bought = 0
while last_game < n_games and last_bill < n_bills:
last_bill += 1
bill = bills[last_bill]
try:
last_game = next(g for g in range(last_game + 1, n_games + 1) if game_prices[g] <= bill)
count_games_bought += 1
except StopIteration:
last_game = n_games
print(count_games_bought)
if __name__ == '__main__':
main()
``` | 3 |
|
863 | B | Kayaking | PROGRAMMING | 1,500 | [
"brute force",
"greedy",
"sortings"
] | null | null | Vadim is really keen on travelling. Recently he heard about kayaking activity near his town and became very excited about it, so he joined a party of kayakers.
Now the party is ready to start its journey, but firstly they have to choose kayaks. There are 2·*n* people in the group (including Vadim), and they have exactly *n*<=-<=1 tandem kayaks (each of which, obviously, can carry two people) and 2 single kayaks. *i*-th person's weight is *w**i*, and weight is an important matter in kayaking — if the difference between the weights of two people that sit in the same tandem kayak is too large, then it can crash. And, of course, people want to distribute their seats in kayaks in order to minimize the chances that kayaks will crash.
Formally, the instability of a single kayak is always 0, and the instability of a tandem kayak is the absolute difference between weights of the people that are in this kayak. Instability of the whole journey is the total instability of all kayaks.
Help the party to determine minimum possible total instability! | The first line contains one number *n* (2<=≤<=*n*<=≤<=50).
The second line contains 2·*n* integer numbers *w*1, *w*2, ..., *w*2*n*, where *w**i* is weight of person *i* (1<=≤<=*w**i*<=≤<=1000). | Print minimum possible total instability. | [
"2\n1 2 3 4\n",
"4\n1 3 4 6 3 4 100 200\n"
] | [
"1\n",
"5\n"
] | none | 0 | [
{
"input": "2\n1 2 3 4",
"output": "1"
},
{
"input": "4\n1 3 4 6 3 4 100 200",
"output": "5"
},
{
"input": "3\n305 139 205 406 530 206",
"output": "102"
},
{
"input": "3\n610 750 778 6 361 407",
"output": "74"
},
{
"input": "5\n97 166 126 164 154 98 221 7 51 47",
"output": "35"
},
{
"input": "50\n1 1 2 2 1 3 2 2 1 1 1 1 2 3 3 1 2 1 3 3 2 1 2 3 1 1 2 1 3 1 3 1 3 3 3 1 1 1 3 3 2 2 2 2 3 2 2 2 2 3 1 3 3 3 3 1 3 3 1 3 3 3 3 2 3 1 3 3 1 1 1 3 1 2 2 2 1 1 1 3 1 2 3 2 1 3 3 2 2 1 3 1 3 1 2 2 1 2 3 2",
"output": "0"
},
{
"input": "50\n5 5 5 5 4 2 2 3 2 2 4 1 5 5 1 2 4 2 4 2 5 2 2 2 2 3 2 4 2 5 5 4 3 1 2 3 3 5 4 2 2 5 2 4 5 5 4 4 1 5 5 3 2 2 5 1 3 3 2 4 4 5 1 2 3 4 4 1 3 3 3 5 1 2 4 4 4 4 2 5 2 5 3 2 4 5 5 2 1 1 2 4 5 3 2 1 2 4 4 4",
"output": "1"
},
{
"input": "50\n499 780 837 984 481 526 944 482 862 136 265 605 5 631 974 967 574 293 969 467 573 845 102 224 17 873 648 120 694 996 244 313 404 129 899 583 541 314 525 496 443 857 297 78 575 2 430 137 387 319 382 651 594 411 845 746 18 232 6 289 889 81 174 175 805 1000 799 950 475 713 951 685 729 925 262 447 139 217 788 514 658 572 784 185 112 636 10 251 621 218 210 89 597 553 430 532 264 11 160 476",
"output": "368"
},
{
"input": "50\n873 838 288 87 889 364 720 410 565 651 577 356 740 99 549 592 994 385 777 435 486 118 887 440 749 533 356 790 413 681 267 496 475 317 88 660 374 186 61 437 729 860 880 538 277 301 667 180 60 393 955 540 896 241 362 146 74 680 734 767 851 337 751 860 542 735 444 793 340 259 495 903 743 961 964 966 87 275 22 776 368 701 835 732 810 735 267 988 352 647 924 183 1 924 217 944 322 252 758 597",
"output": "393"
},
{
"input": "50\n297 787 34 268 439 629 600 398 425 833 721 908 830 636 64 509 420 647 499 675 427 599 396 119 798 742 577 355 22 847 389 574 766 453 196 772 808 261 106 844 726 975 173 992 874 89 775 616 678 52 69 591 181 573 258 381 665 301 589 379 362 146 790 842 765 100 229 916 938 97 340 793 758 177 736 396 247 562 571 92 923 861 165 748 345 703 431 930 101 761 862 595 505 393 126 846 431 103 596 21",
"output": "387"
},
{
"input": "50\n721 631 587 746 692 406 583 90 388 16 161 948 921 70 387 426 39 398 517 724 879 377 906 502 359 950 798 408 846 718 911 845 57 886 9 668 537 632 344 762 19 193 658 447 870 173 98 156 592 519 183 539 274 393 962 615 551 626 148 183 769 763 829 120 796 761 14 744 537 231 696 284 581 688 611 826 703 145 224 600 965 613 791 275 984 375 402 281 851 580 992 8 816 454 35 532 347 250 242 637",
"output": "376"
},
{
"input": "50\n849 475 37 120 754 183 758 374 543 198 896 691 11 607 198 343 761 660 239 669 628 259 223 182 216 158 20 565 454 884 137 923 156 22 310 77 267 707 582 169 120 308 439 309 59 152 206 696 210 177 296 887 559 22 154 553 142 247 491 692 473 572 461 206 532 319 503 164 328 365 541 366 300 392 486 257 863 432 877 404 520 69 418 99 519 239 374 927 601 103 226 316 423 219 240 26 455 101 184 61",
"output": "351"
},
{
"input": "3\n1 2 10 11 100 100",
"output": "1"
},
{
"input": "17\n814 744 145 886 751 1000 272 914 270 529 467 164 410 369 123 424 991 12 702 582 561 858 746 950 598 393 606 498 648 686 455 873 728 858",
"output": "318"
},
{
"input": "45\n476 103 187 696 463 457 588 632 763 77 391 721 95 124 378 812 980 193 694 898 859 572 721 274 605 264 929 615 257 918 42 493 1 3 697 349 990 800 82 535 382 816 943 735 11 272 562 323 653 370 766 332 666 130 704 604 645 717 267 255 37 470 925 941 376 611 332 758 504 40 477 263 708 434 38 596 650 990 714 662 572 467 949 799 648 581 545 828 508 636",
"output": "355"
},
{
"input": "2\n55 5 25 51",
"output": "4"
},
{
"input": "25\n89 50 640 463 858 301 522 241 923 378 892 822 550 17 42 66 706 779 657 840 273 222 444 459 94 925 437 159 182 727 92 851 742 215 653 891 782 533 29 128 133 883 317 475 165 994 802 434 744 973",
"output": "348"
},
{
"input": "4\n35 48 71 44 78 79 57 48",
"output": "10"
},
{
"input": "3\n58 89 73 15 5 47",
"output": "21"
},
{
"input": "2\n1 20 99 100",
"output": "1"
}
] | 1,641,669,877 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 2 | 93 | 0 | n = int(input().strip())
weights = [int(i) for i in input().strip().split()]
weights.sort()
max_dif = 0
f, s = None, None
for i in range(n*2-1):
if weights[i+1] - weights[i] > max_dif:
max_dif = weights[i+1] - weights[i]
f = i+1
s = i
weights.pop(i+1)
weights.pop(i)
ans = 0
for i in range(n*2-3):
ans += weights[i+1] - weights[i]
print(ans) | Title: Kayaking
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vadim is really keen on travelling. Recently he heard about kayaking activity near his town and became very excited about it, so he joined a party of kayakers.
Now the party is ready to start its journey, but firstly they have to choose kayaks. There are 2·*n* people in the group (including Vadim), and they have exactly *n*<=-<=1 tandem kayaks (each of which, obviously, can carry two people) and 2 single kayaks. *i*-th person's weight is *w**i*, and weight is an important matter in kayaking — if the difference between the weights of two people that sit in the same tandem kayak is too large, then it can crash. And, of course, people want to distribute their seats in kayaks in order to minimize the chances that kayaks will crash.
Formally, the instability of a single kayak is always 0, and the instability of a tandem kayak is the absolute difference between weights of the people that are in this kayak. Instability of the whole journey is the total instability of all kayaks.
Help the party to determine minimum possible total instability!
Input Specification:
The first line contains one number *n* (2<=≤<=*n*<=≤<=50).
The second line contains 2·*n* integer numbers *w*1, *w*2, ..., *w*2*n*, where *w**i* is weight of person *i* (1<=≤<=*w**i*<=≤<=1000).
Output Specification:
Print minimum possible total instability.
Demo Input:
['2\n1 2 3 4\n', '4\n1 3 4 6 3 4 100 200\n']
Demo Output:
['1\n', '5\n']
Note:
none | ```python
n = int(input().strip())
weights = [int(i) for i in input().strip().split()]
weights.sort()
max_dif = 0
f, s = None, None
for i in range(n*2-1):
if weights[i+1] - weights[i] > max_dif:
max_dif = weights[i+1] - weights[i]
f = i+1
s = i
weights.pop(i+1)
weights.pop(i)
ans = 0
for i in range(n*2-3):
ans += weights[i+1] - weights[i]
print(ans)
``` | 0 |
|
837 | A | Text Volume | PROGRAMMING | 800 | [
"implementation"
] | null | null | You are given a text of single-space separated words, consisting of small and capital Latin letters.
Volume of the word is number of capital letters in the word. Volume of the text is maximum volume of all words in the text.
Calculate the volume of the given text. | The first line contains one integer number *n* (1<=≤<=*n*<=≤<=200) — length of the text.
The second line contains text of single-space separated words *s*1,<=*s*2,<=...,<=*s**i*, consisting only of small and capital Latin letters. | Print one integer number — volume of text. | [
"7\nNonZERO\n",
"24\nthis is zero answer text\n",
"24\nHarbour Space University\n"
] | [
"5\n",
"0\n",
"1\n"
] | In the first example there is only one word, there are 5 capital letters in it.
In the second example all of the words contain 0 capital letters. | 0 | [
{
"input": "7\nNonZERO",
"output": "5"
},
{
"input": "24\nthis is zero answer text",
"output": "0"
},
{
"input": "24\nHarbour Space University",
"output": "1"
},
{
"input": "2\nWM",
"output": "2"
},
{
"input": "200\nLBmJKQLCKUgtTxMoDsEerwvLOXsxASSydOqWyULsRcjMYDWdDCgaDvBfATIWPVSXlbcCLHPYahhxMEYUiaxoCebghJqvmRnaNHYTKLeOiaLDnATPZAOgSNfBzaxLymTGjfzvTegbXsAthTxyDTcmBUkqyGlVGZhoazQzVSoKbTFcCRvYsgSCwjGMxBfWEwMHuagTBxkz",
"output": "105"
},
{
"input": "199\no A r v H e J q k J k v w Q F p O R y R Z o a K R L Z E H t X y X N y y p b x B m r R S q i A x V S u i c L y M n N X c C W Z m S j e w C w T r I S X T D F l w o k f t X u n W w p Z r A k I Y E h s g",
"output": "1"
},
{
"input": "200\nhCyIdivIiISmmYIsCLbpKcTyHaOgTUQEwnQACXnrLdHAVFLtvliTEMlzBVzTesQbhXmcqvwPDeojglBMIjOXANfyQxCSjOJyO SIqOTnRzVzseGIDDYNtrwIusScWSuEhPyEmgQIVEzXofRptjeMzzhtUQxJgcUWILUhEaaRmYRBVsjoqgmyPIKwSajdlNPccOOtWrez",
"output": "50"
},
{
"input": "1\ne",
"output": "0"
},
{
"input": "1\nA",
"output": "1"
},
{
"input": "200\nABCDEFGHIJ ABCDEFGHIJ ABCDEFGHIJ ABCDEFGHIJ ABCDEFGHIJ ABCDEFGHIJ ABCDEFGHIJ ABCDEFGHIJ ABCDEFGHIJ ABCDEFGHIJ KLMNOPRSTU KLMNOPRSTU KLMNOPRSTU VWXYZABCDE KLMNOPRSTU KLMNOPRSTU KLMNOPRSTU KLMNOPRSTU KZ",
"output": "10"
},
{
"input": "200\nAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA",
"output": "200"
},
{
"input": "200\nffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff",
"output": "0"
},
{
"input": "24\nHarbour Space UniversitY",
"output": "2"
},
{
"input": "5\naA AA",
"output": "2"
},
{
"input": "10\nas AS ASDA",
"output": "4"
},
{
"input": "10\nas AS ASDZ",
"output": "4"
},
{
"input": "3\na A",
"output": "1"
},
{
"input": "24\nHarbour space UniversitY",
"output": "2"
},
{
"input": "10\nas AS ASAa",
"output": "3"
},
{
"input": "15\naAb ABCDFGRHTJS",
"output": "11"
},
{
"input": "53\nsdfAZEZR AZE dfdf dsdRFGSDF ZZDZSD dfsd ERBGF dsfsdfR",
"output": "6"
},
{
"input": "10\nABC ABc AB",
"output": "3"
},
{
"input": "10\nA c de CDE",
"output": "3"
},
{
"input": "4\nA AB",
"output": "2"
},
{
"input": "18\nHARbour Space UNIV",
"output": "4"
},
{
"input": "13\na b c d e f A",
"output": "1"
},
{
"input": "6\nA B CA",
"output": "2"
},
{
"input": "4\naa A",
"output": "1"
},
{
"input": "3\nA a",
"output": "1"
}
] | 1,538,606,067 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 108 | 0 | n=int(input())
ch=input()
i=0
l=[]
k=0
while((i<=n)):
if (ch[i].isupper()):
k+=1
if (ch[i]==' '):
l.append(k)
k=0
i+=1
l.append(k)
v=max(l)
| Title: Text Volume
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given a text of single-space separated words, consisting of small and capital Latin letters.
Volume of the word is number of capital letters in the word. Volume of the text is maximum volume of all words in the text.
Calculate the volume of the given text.
Input Specification:
The first line contains one integer number *n* (1<=≤<=*n*<=≤<=200) — length of the text.
The second line contains text of single-space separated words *s*1,<=*s*2,<=...,<=*s**i*, consisting only of small and capital Latin letters.
Output Specification:
Print one integer number — volume of text.
Demo Input:
['7\nNonZERO\n', '24\nthis is zero answer text\n', '24\nHarbour Space University\n']
Demo Output:
['5\n', '0\n', '1\n']
Note:
In the first example there is only one word, there are 5 capital letters in it.
In the second example all of the words contain 0 capital letters. | ```python
n=int(input())
ch=input()
i=0
l=[]
k=0
while((i<=n)):
if (ch[i].isupper()):
k+=1
if (ch[i]==' '):
l.append(k)
k=0
i+=1
l.append(k)
v=max(l)
``` | -1 |
|
272 | A | Dima and Friends | PROGRAMMING | 1,000 | [
"implementation",
"math"
] | null | null | Dima and his friends have been playing hide and seek at Dima's place all night. As a result, Dima's place got messy. In the morning they decided that they need to clean the place.
To decide who exactly would clean the apartment, the friends want to play a counting-out game. First, all the guys stand in a circle, and then each of them shows some number of fingers on one hand (one to five), and then the boys count in a circle, starting from Dima, the number of people, respective to the total number of fingers shown. The person on who the countdown stops will clean the apartment.
For example, if Dima and one of his friends played hide and seek, and 7 fingers were shown during the counting-out, then Dima would clean the place. If there were 2 or say, 8 fingers shown, then his friend would clean the place.
Dima knows how many fingers each of his friends will show during the counting-out. Now he is interested in the number of ways to show some number of fingers on one hand (one to five), so that he did not have to clean the place. Help Dima. | The first line contains integer *n* (1<=≤<=*n*<=≤<=100) — the number of Dima's friends. Dima himself isn't considered to be his own friend. The second line contains *n* positive integers, not exceeding 5, representing, how many fingers the Dima's friends will show.
The numbers in the lines are separated by a single space. | In a single line print the answer to the problem. | [
"1\n1\n",
"1\n2\n",
"2\n3 5\n"
] | [
"3\n",
"2\n",
"3\n"
] | In the first sample Dima can show 1, 3 or 5 fingers. If Dima shows 3 fingers, then the counting-out will go like that: Dima, his friend, Dima, his friend.
In the second sample Dima can show 2 or 4 fingers. | 500 | [
{
"input": "1\n1",
"output": "3"
},
{
"input": "1\n2",
"output": "2"
},
{
"input": "2\n3 5",
"output": "3"
},
{
"input": "2\n3 5",
"output": "3"
},
{
"input": "1\n5",
"output": "3"
},
{
"input": "5\n4 4 3 5 1",
"output": "4"
},
{
"input": "6\n2 3 2 2 1 3",
"output": "4"
},
{
"input": "8\n2 2 5 3 4 3 3 2",
"output": "4"
},
{
"input": "7\n4 1 3 2 2 4 5",
"output": "4"
},
{
"input": "3\n3 5 1",
"output": "4"
},
{
"input": "95\n4 2 3 4 4 5 2 2 4 4 3 5 3 3 3 5 4 2 5 4 2 1 1 3 4 2 1 3 5 4 2 1 1 5 1 1 2 2 4 4 5 4 5 5 2 1 2 2 2 4 5 5 2 4 3 4 4 3 5 2 4 1 5 4 5 1 3 2 4 2 2 1 5 3 1 5 3 4 3 3 2 1 2 2 1 3 1 5 2 3 1 1 2 5 2",
"output": "5"
},
{
"input": "31\n3 2 3 3 3 3 4 4 1 5 5 4 2 4 3 2 2 1 4 4 1 2 3 1 1 5 5 3 4 4 1",
"output": "4"
},
{
"input": "42\n3 1 2 2 5 1 2 2 4 5 4 5 2 5 4 5 4 4 1 4 3 3 4 4 4 4 3 2 1 3 4 5 5 2 1 2 1 5 5 2 4 4",
"output": "5"
},
{
"input": "25\n4 5 5 5 3 1 1 4 4 4 3 5 4 4 1 4 4 1 2 4 2 5 4 5 3",
"output": "5"
},
{
"input": "73\n3 4 3 4 5 1 3 4 2 1 4 2 2 3 5 3 1 4 2 3 2 1 4 5 3 5 2 2 4 3 2 2 5 3 2 3 5 1 3 1 1 4 5 2 4 2 5 1 4 3 1 3 1 4 2 3 3 3 3 5 5 2 5 2 5 4 3 1 1 5 5 2 3",
"output": "4"
},
{
"input": "46\n1 4 4 5 4 5 2 3 5 5 3 2 5 4 1 3 2 2 1 4 3 1 5 5 2 2 2 2 4 4 1 1 4 3 4 3 1 4 2 2 4 2 3 2 5 2",
"output": "4"
},
{
"input": "23\n5 2 1 1 4 2 5 5 3 5 4 5 5 1 1 5 2 4 5 3 4 4 3",
"output": "5"
},
{
"input": "6\n4 2 3 1 3 5",
"output": "4"
},
{
"input": "15\n5 5 5 3 5 4 1 3 3 4 3 4 1 4 4",
"output": "5"
},
{
"input": "93\n1 3 1 4 3 3 5 3 1 4 5 4 3 2 2 4 3 1 4 1 2 3 3 3 2 5 1 3 1 4 5 1 1 1 4 2 1 2 3 1 1 1 5 1 5 5 1 2 5 4 3 2 2 4 4 2 5 4 5 5 3 1 3 1 2 1 3 1 1 2 3 4 4 5 5 3 2 1 3 3 5 1 3 5 4 4 1 3 3 4 2 3 2",
"output": "5"
},
{
"input": "96\n1 5 1 3 2 1 2 2 2 2 3 4 1 1 5 4 4 1 2 3 5 1 4 4 4 1 3 3 1 4 5 4 1 3 5 3 4 4 3 2 1 1 4 4 5 1 1 2 5 1 2 3 1 4 1 2 2 2 3 2 3 3 2 5 2 2 3 3 3 3 2 1 2 4 5 5 1 5 3 2 1 4 3 5 5 5 3 3 5 3 4 3 4 2 1 3",
"output": "5"
},
{
"input": "49\n1 4 4 3 5 2 2 1 5 1 2 1 2 5 1 4 1 4 5 2 4 5 3 5 2 4 2 1 3 4 2 1 4 2 1 1 3 3 2 3 5 4 3 4 2 4 1 4 1",
"output": "5"
},
{
"input": "73\n4 1 3 3 3 1 5 2 1 4 1 1 3 5 1 1 4 5 2 1 5 4 1 5 3 1 5 2 4 5 1 4 3 3 5 2 2 3 3 2 5 1 4 5 2 3 1 4 4 3 5 2 3 5 1 4 3 5 1 2 4 1 3 3 5 4 2 4 2 4 1 2 5",
"output": "5"
},
{
"input": "41\n5 3 5 4 2 5 4 3 1 1 1 5 4 3 4 3 5 4 2 5 4 1 1 3 2 4 5 3 5 1 5 5 1 1 1 4 4 1 2 4 3",
"output": "5"
},
{
"input": "100\n3 3 1 4 2 4 4 3 1 5 1 1 4 4 3 4 4 3 5 4 5 2 4 3 4 1 2 4 5 4 2 1 5 4 1 1 4 3 2 4 1 2 1 4 4 5 5 4 4 5 3 2 5 1 4 2 2 1 1 2 5 2 5 1 5 3 1 4 3 2 4 3 2 2 4 5 5 1 2 3 1 4 1 2 2 2 5 5 2 3 2 4 3 1 1 2 1 2 1 2",
"output": "5"
},
{
"input": "100\n2 1 1 3 5 4 4 2 3 4 3 4 5 4 5 4 2 4 5 3 4 5 4 1 1 4 4 1 1 2 5 4 2 4 5 3 2 5 4 3 4 5 1 3 4 2 5 4 5 4 5 2 4 1 2 5 3 1 4 4 5 3 4 3 1 2 5 4 2 5 4 1 5 3 5 4 1 2 5 3 1 1 1 1 5 3 4 3 5 1 1 5 5 1 1 2 2 1 5 1",
"output": "5"
},
{
"input": "100\n4 4 3 3 2 5 4 4 2 1 4 4 4 5 4 1 2 1 5 2 4 3 4 1 4 1 2 5 1 4 5 4 2 1 2 5 3 4 5 5 2 1 2 2 2 2 2 3 2 5 1 2 2 3 2 5 5 1 3 4 5 2 1 3 4 2 2 4 4 3 3 3 2 3 2 1 5 5 5 2 1 4 2 3 5 1 4 4 2 3 2 5 5 4 3 5 1 3 5 5",
"output": "5"
},
{
"input": "100\n4 4 2 5 4 2 2 3 4 4 3 2 3 3 1 3 4 3 3 4 1 3 1 4 5 3 4 3 1 1 1 3 3 2 3 4 3 4 2 2 1 5 1 4 5 1 1 1 3 3 1 1 3 2 5 4 2 5 2 4 5 4 4 1 1 2 1 1 4 5 1 1 5 3 3 2 5 5 5 1 4 1 4 1 1 3 2 3 4 4 2 5 5 2 5 1 1 3 5 3",
"output": "5"
},
{
"input": "100\n4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4",
"output": "4"
},
{
"input": "100\n5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5",
"output": "5"
}
] | 1,631,557,116 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 0 | 184 | 20,172,800 | n = int(input())
l = list(map(int,input().split()))
s = sum(l)
a = ((sum(l)-2)//(n+1)) + 1
if a<=0:
print(a+4)
else:
print(a) | Title: Dima and Friends
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Dima and his friends have been playing hide and seek at Dima's place all night. As a result, Dima's place got messy. In the morning they decided that they need to clean the place.
To decide who exactly would clean the apartment, the friends want to play a counting-out game. First, all the guys stand in a circle, and then each of them shows some number of fingers on one hand (one to five), and then the boys count in a circle, starting from Dima, the number of people, respective to the total number of fingers shown. The person on who the countdown stops will clean the apartment.
For example, if Dima and one of his friends played hide and seek, and 7 fingers were shown during the counting-out, then Dima would clean the place. If there were 2 or say, 8 fingers shown, then his friend would clean the place.
Dima knows how many fingers each of his friends will show during the counting-out. Now he is interested in the number of ways to show some number of fingers on one hand (one to five), so that he did not have to clean the place. Help Dima.
Input Specification:
The first line contains integer *n* (1<=≤<=*n*<=≤<=100) — the number of Dima's friends. Dima himself isn't considered to be his own friend. The second line contains *n* positive integers, not exceeding 5, representing, how many fingers the Dima's friends will show.
The numbers in the lines are separated by a single space.
Output Specification:
In a single line print the answer to the problem.
Demo Input:
['1\n1\n', '1\n2\n', '2\n3 5\n']
Demo Output:
['3\n', '2\n', '3\n']
Note:
In the first sample Dima can show 1, 3 or 5 fingers. If Dima shows 3 fingers, then the counting-out will go like that: Dima, his friend, Dima, his friend.
In the second sample Dima can show 2 or 4 fingers. | ```python
n = int(input())
l = list(map(int,input().split()))
s = sum(l)
a = ((sum(l)-2)//(n+1)) + 1
if a<=0:
print(a+4)
else:
print(a)
``` | 0 |
|
979 | A | Pizza, Pizza, Pizza!!! | PROGRAMMING | 1,000 | [
"math"
] | null | null | Katie, Kuro and Shiro are best friends. They have known each other since kindergarten. That's why they often share everything with each other and work together on some very hard problems.
Today is Shiro's birthday. She really loves pizza so she wants to invite her friends to the pizza restaurant near her house to celebrate her birthday, including her best friends Katie and Kuro.
She has ordered a very big round pizza, in order to serve her many friends. Exactly $n$ of Shiro's friends are here. That's why she has to divide the pizza into $n + 1$ slices (Shiro also needs to eat). She wants the slices to be exactly the same size and shape. If not, some of her friends will get mad and go home early, and the party will be over.
Shiro is now hungry. She wants to cut the pizza with minimum of straight cuts. A cut is a straight segment, it might have ends inside or outside the pizza. But she is too lazy to pick up the calculator.
As usual, she will ask Katie and Kuro for help. But they haven't come yet. Could you help Shiro with this problem? | A single line contains one non-negative integer $n$ ($0 \le n \leq 10^{18}$) — the number of Shiro's friends. The circular pizza has to be sliced into $n + 1$ pieces. | A single integer — the number of straight cuts Shiro needs. | [
"3\n",
"4\n"
] | [
"2",
"5"
] | To cut the round pizza into quarters one has to make two cuts through the center with angle $90^{\circ}$ between them.
To cut the round pizza into five equal parts one has to make five cuts. | 500 | [
{
"input": "3",
"output": "2"
},
{
"input": "4",
"output": "5"
},
{
"input": "10",
"output": "11"
},
{
"input": "10000000000",
"output": "10000000001"
},
{
"input": "1234567891",
"output": "617283946"
},
{
"input": "7509213957",
"output": "3754606979"
},
{
"input": "99999999999999999",
"output": "50000000000000000"
},
{
"input": "21",
"output": "11"
},
{
"input": "712394453192",
"output": "712394453193"
},
{
"input": "172212168",
"output": "172212169"
},
{
"input": "822981260158260519",
"output": "411490630079130260"
},
{
"input": "28316250877914571",
"output": "14158125438957286"
},
{
"input": "779547116602436424",
"output": "779547116602436425"
},
{
"input": "578223540024979436",
"output": "578223540024979437"
},
{
"input": "335408917861648766",
"output": "335408917861648767"
},
{
"input": "74859962623690078",
"output": "74859962623690079"
},
{
"input": "252509054433933439",
"output": "126254527216966720"
},
{
"input": "760713016476190622",
"output": "760713016476190623"
},
{
"input": "919845426262703496",
"output": "919845426262703497"
},
{
"input": "585335723211047194",
"output": "585335723211047195"
},
{
"input": "522842184971407769",
"output": "261421092485703885"
},
{
"input": "148049062628894320",
"output": "148049062628894321"
},
{
"input": "84324828731963974",
"output": "84324828731963975"
},
{
"input": "354979173822804781",
"output": "177489586911402391"
},
{
"input": "1312150450968413",
"output": "656075225484207"
},
{
"input": "269587449430302150",
"output": "269587449430302151"
},
{
"input": "645762258982631926",
"output": "645762258982631927"
},
{
"input": "615812229161735895",
"output": "307906114580867948"
},
{
"input": "0",
"output": "0"
},
{
"input": "349993004923078531",
"output": "174996502461539266"
},
{
"input": "891351282707723851",
"output": "445675641353861926"
},
{
"input": "563324731189330734",
"output": "563324731189330735"
},
{
"input": "520974001910286909",
"output": "260487000955143455"
},
{
"input": "666729339802329204",
"output": "666729339802329205"
},
{
"input": "856674611404539671",
"output": "428337305702269836"
},
{
"input": "791809296303238499",
"output": "395904648151619250"
},
{
"input": "711066337317063338",
"output": "711066337317063339"
},
{
"input": "931356503492686566",
"output": "931356503492686567"
},
{
"input": "234122432773361866",
"output": "234122432773361867"
},
{
"input": "1000000000000000000",
"output": "1000000000000000001"
},
{
"input": "1",
"output": "1"
},
{
"input": "2",
"output": "3"
},
{
"input": "7",
"output": "4"
},
{
"input": "63",
"output": "32"
},
{
"input": "24",
"output": "25"
},
{
"input": "8",
"output": "9"
},
{
"input": "15",
"output": "8"
}
] | 1,558,537,146 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 10 | 108 | 0 | N = int(input()) + 1
if (N % 2 == 0):
print(int(N / 2))
else:
print(N)
| Title: Pizza, Pizza, Pizza!!!
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Katie, Kuro and Shiro are best friends. They have known each other since kindergarten. That's why they often share everything with each other and work together on some very hard problems.
Today is Shiro's birthday. She really loves pizza so she wants to invite her friends to the pizza restaurant near her house to celebrate her birthday, including her best friends Katie and Kuro.
She has ordered a very big round pizza, in order to serve her many friends. Exactly $n$ of Shiro's friends are here. That's why she has to divide the pizza into $n + 1$ slices (Shiro also needs to eat). She wants the slices to be exactly the same size and shape. If not, some of her friends will get mad and go home early, and the party will be over.
Shiro is now hungry. She wants to cut the pizza with minimum of straight cuts. A cut is a straight segment, it might have ends inside or outside the pizza. But she is too lazy to pick up the calculator.
As usual, she will ask Katie and Kuro for help. But they haven't come yet. Could you help Shiro with this problem?
Input Specification:
A single line contains one non-negative integer $n$ ($0 \le n \leq 10^{18}$) — the number of Shiro's friends. The circular pizza has to be sliced into $n + 1$ pieces.
Output Specification:
A single integer — the number of straight cuts Shiro needs.
Demo Input:
['3\n', '4\n']
Demo Output:
['2', '5']
Note:
To cut the round pizza into quarters one has to make two cuts through the center with angle $90^{\circ}$ between them.
To cut the round pizza into five equal parts one has to make five cuts. | ```python
N = int(input()) + 1
if (N % 2 == 0):
print(int(N / 2))
else:
print(N)
``` | 0 |
|
811 | B | Vladik and Complicated Book | PROGRAMMING | 1,200 | [
"implementation",
"sortings"
] | null | null | Vladik had started reading a complicated book about algorithms containing *n* pages. To improve understanding of what is written, his friends advised him to read pages in some order given by permutation *P*<==<=[*p*1,<=*p*2,<=...,<=*p**n*], where *p**i* denotes the number of page that should be read *i*-th in turn.
Sometimes Vladik’s mom sorted some subsegment of permutation *P* from position *l* to position *r* inclusive, because she loves the order. For every of such sorting Vladik knows number *x* — what index of page in permutation he should read. He is wondered if the page, which he will read after sorting, has changed. In other words, has *p**x* changed? After every sorting Vladik return permutation to initial state, so you can assume that each sorting is independent from each other. | First line contains two space-separated integers *n*, *m* (1<=≤<=*n*,<=*m*<=≤<=104) — length of permutation and number of times Vladik's mom sorted some subsegment of the book.
Second line contains *n* space-separated integers *p*1,<=*p*2,<=...,<=*p**n* (1<=≤<=*p**i*<=≤<=*n*) — permutation *P*. Note that elements in permutation are distinct.
Each of the next *m* lines contains three space-separated integers *l**i*, *r**i*, *x**i* (1<=≤<=*l**i*<=≤<=*x**i*<=≤<=*r**i*<=≤<=*n*) — left and right borders of sorted subsegment in *i*-th sorting and position that is interesting to Vladik. | For each mom’s sorting on it’s own line print "Yes", if page which is interesting to Vladik hasn't changed, or "No" otherwise. | [
"5 5\n5 4 3 2 1\n1 5 3\n1 3 1\n2 4 3\n4 4 4\n2 5 3\n",
"6 5\n1 4 3 2 5 6\n2 4 3\n1 6 2\n4 5 4\n1 3 3\n2 6 3\n"
] | [
"Yes\nNo\nYes\nYes\nNo\n",
"Yes\nNo\nYes\nNo\nYes\n"
] | Explanation of first test case:
1. [1, 2, 3, 4, 5] — permutation after sorting, 3-rd element hasn’t changed, so answer is "Yes". 1. [3, 4, 5, 2, 1] — permutation after sorting, 1-st element has changed, so answer is "No". 1. [5, 2, 3, 4, 1] — permutation after sorting, 3-rd element hasn’t changed, so answer is "Yes". 1. [5, 4, 3, 2, 1] — permutation after sorting, 4-th element hasn’t changed, so answer is "Yes". 1. [5, 1, 2, 3, 4] — permutation after sorting, 3-rd element has changed, so answer is "No". | 1,000 | [
{
"input": "5 5\n5 4 3 2 1\n1 5 3\n1 3 1\n2 4 3\n4 4 4\n2 5 3",
"output": "Yes\nNo\nYes\nYes\nNo"
},
{
"input": "6 5\n1 4 3 2 5 6\n2 4 3\n1 6 2\n4 5 4\n1 3 3\n2 6 3",
"output": "Yes\nNo\nYes\nNo\nYes"
},
{
"input": "10 10\n10 1 6 7 9 8 4 3 5 2\n1 1 1\n4 4 4\n7 7 7\n3 3 3\n1 6 5\n2 6 2\n6 8 7\n1 1 1\n7 9 9\n2 9 4",
"output": "Yes\nYes\nYes\nYes\nYes\nYes\nYes\nYes\nYes\nNo"
},
{
"input": "20 20\n18 17 2 3 16 15 1 9 12 8 20 11 13 14 4 5 19 7 10 6\n13 15 15\n1 1 1\n2 2 2\n11 14 13\n10 11 10\n2 8 6\n12 18 16\n4 8 8\n2 2 2\n5 11 11\n4 9 9\n5 6 6\n3 20 12\n8 8 8\n6 16 11\n9 18 18\n8 18 17\n1 1 1\n2 6 5\n1 4 3",
"output": "No\nYes\nYes\nNo\nYes\nYes\nNo\nNo\nYes\nYes\nNo\nNo\nNo\nYes\nNo\nNo\nYes\nYes\nYes\nNo"
},
{
"input": "5 10\n5 4 3 2 1\n1 5 3\n1 3 1\n2 4 3\n4 4 4\n2 5 3\n1 5 3\n1 3 1\n2 4 3\n4 4 4\n2 5 3",
"output": "Yes\nNo\nYes\nYes\nNo\nYes\nNo\nYes\nYes\nNo"
}
] | 1,570,469,959 | 2,147,483,647 | PyPy 3 | TIME_LIMIT_EXCEEDED | TESTS | 9 | 2,000 | 9,113,600 | n, m = map(int, input().split())
a = list(map(int, input().split()))
for i in range(m):
l, r, x = map(int, input().split())
b = a[l - 1: r]
b.sort()
if a[x - 1] == b[x - l]:
print("Yes")
else:
print("No")
| Title: Vladik and Complicated Book
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vladik had started reading a complicated book about algorithms containing *n* pages. To improve understanding of what is written, his friends advised him to read pages in some order given by permutation *P*<==<=[*p*1,<=*p*2,<=...,<=*p**n*], where *p**i* denotes the number of page that should be read *i*-th in turn.
Sometimes Vladik’s mom sorted some subsegment of permutation *P* from position *l* to position *r* inclusive, because she loves the order. For every of such sorting Vladik knows number *x* — what index of page in permutation he should read. He is wondered if the page, which he will read after sorting, has changed. In other words, has *p**x* changed? After every sorting Vladik return permutation to initial state, so you can assume that each sorting is independent from each other.
Input Specification:
First line contains two space-separated integers *n*, *m* (1<=≤<=*n*,<=*m*<=≤<=104) — length of permutation and number of times Vladik's mom sorted some subsegment of the book.
Second line contains *n* space-separated integers *p*1,<=*p*2,<=...,<=*p**n* (1<=≤<=*p**i*<=≤<=*n*) — permutation *P*. Note that elements in permutation are distinct.
Each of the next *m* lines contains three space-separated integers *l**i*, *r**i*, *x**i* (1<=≤<=*l**i*<=≤<=*x**i*<=≤<=*r**i*<=≤<=*n*) — left and right borders of sorted subsegment in *i*-th sorting and position that is interesting to Vladik.
Output Specification:
For each mom’s sorting on it’s own line print "Yes", if page which is interesting to Vladik hasn't changed, or "No" otherwise.
Demo Input:
['5 5\n5 4 3 2 1\n1 5 3\n1 3 1\n2 4 3\n4 4 4\n2 5 3\n', '6 5\n1 4 3 2 5 6\n2 4 3\n1 6 2\n4 5 4\n1 3 3\n2 6 3\n']
Demo Output:
['Yes\nNo\nYes\nYes\nNo\n', 'Yes\nNo\nYes\nNo\nYes\n']
Note:
Explanation of first test case:
1. [1, 2, 3, 4, 5] — permutation after sorting, 3-rd element hasn’t changed, so answer is "Yes". 1. [3, 4, 5, 2, 1] — permutation after sorting, 1-st element has changed, so answer is "No". 1. [5, 2, 3, 4, 1] — permutation after sorting, 3-rd element hasn’t changed, so answer is "Yes". 1. [5, 4, 3, 2, 1] — permutation after sorting, 4-th element hasn’t changed, so answer is "Yes". 1. [5, 1, 2, 3, 4] — permutation after sorting, 3-rd element has changed, so answer is "No". | ```python
n, m = map(int, input().split())
a = list(map(int, input().split()))
for i in range(m):
l, r, x = map(int, input().split())
b = a[l - 1: r]
b.sort()
if a[x - 1] == b[x - l]:
print("Yes")
else:
print("No")
``` | 0 |
|
25 | A | IQ test | PROGRAMMING | 1,300 | [
"brute force"
] | A. IQ test | 2 | 256 | Bob is preparing to pass IQ test. The most frequent task in this test is to find out which one of the given *n* numbers differs from the others. Bob observed that one number usually differs from the others in evenness. Help Bob — to check his answers, he needs a program that among the given *n* numbers finds one that is different in evenness. | The first line contains integer *n* (3<=≤<=*n*<=≤<=100) — amount of numbers in the task. The second line contains *n* space-separated natural numbers, not exceeding 100. It is guaranteed, that exactly one of these numbers differs from the others in evenness. | Output index of number that differs from the others in evenness. Numbers are numbered from 1 in the input order. | [
"5\n2 4 7 8 10\n",
"4\n1 2 1 1\n"
] | [
"3\n",
"2\n"
] | none | 0 | [
{
"input": "5\n2 4 7 8 10",
"output": "3"
},
{
"input": "4\n1 2 1 1",
"output": "2"
},
{
"input": "3\n1 2 2",
"output": "1"
},
{
"input": "3\n100 99 100",
"output": "2"
},
{
"input": "3\n5 3 2",
"output": "3"
},
{
"input": "4\n43 28 1 91",
"output": "2"
},
{
"input": "4\n75 13 94 77",
"output": "3"
},
{
"input": "4\n97 8 27 3",
"output": "2"
},
{
"input": "10\n95 51 12 91 85 3 1 31 25 7",
"output": "3"
},
{
"input": "20\n88 96 66 51 14 88 2 92 18 72 18 88 20 30 4 82 90 100 24 46",
"output": "4"
},
{
"input": "30\n20 94 56 50 10 98 52 32 14 22 24 60 4 8 98 46 34 68 82 82 98 90 50 20 78 49 52 94 64 36",
"output": "26"
},
{
"input": "50\n79 27 77 57 37 45 27 49 65 33 57 21 71 19 75 85 65 61 23 97 85 9 23 1 9 3 99 77 77 21 79 69 15 37 15 7 93 81 13 89 91 31 45 93 15 97 55 80 85 83",
"output": "48"
},
{
"input": "60\n46 11 73 65 3 69 3 53 43 53 97 47 55 93 31 75 35 3 9 73 23 31 3 81 91 79 61 21 15 11 11 11 81 7 83 75 39 87 83 59 89 55 93 27 49 67 67 29 1 93 11 17 9 19 35 21 63 31 31 25",
"output": "1"
},
{
"input": "70\n28 42 42 92 64 54 22 38 38 78 62 38 4 38 14 66 4 92 66 58 94 26 4 44 41 88 48 82 44 26 74 44 48 4 16 92 34 38 26 64 94 4 30 78 50 54 12 90 8 16 80 98 28 100 74 50 36 42 92 18 76 98 8 22 2 50 58 50 64 46",
"output": "25"
},
{
"input": "100\n43 35 79 53 13 91 91 45 65 83 57 9 42 39 85 45 71 51 61 59 31 13 63 39 25 21 79 39 91 67 21 61 97 75 93 83 29 79 59 97 11 37 63 51 39 55 91 23 21 17 47 23 35 75 49 5 69 99 5 7 41 17 25 89 15 79 21 63 53 81 43 91 59 91 69 99 85 15 91 51 49 37 65 7 89 81 21 93 61 63 97 93 45 17 13 69 57 25 75 73",
"output": "13"
},
{
"input": "100\n50 24 68 60 70 30 52 22 18 74 68 98 20 82 4 46 26 68 100 78 84 58 74 98 38 88 68 86 64 80 82 100 20 22 98 98 52 6 94 10 48 68 2 18 38 22 22 82 44 20 66 72 36 58 64 6 36 60 4 96 76 64 12 90 10 58 64 60 74 28 90 26 24 60 40 58 2 16 76 48 58 36 82 60 24 44 4 78 28 38 8 12 40 16 38 6 66 24 31 76",
"output": "99"
},
{
"input": "100\n47 48 94 48 14 18 94 36 96 22 12 30 94 20 48 98 40 58 2 94 8 36 98 18 98 68 2 60 76 38 18 100 8 72 100 68 2 86 92 72 58 16 48 14 6 58 72 76 6 88 80 66 20 28 74 62 86 68 90 86 2 56 34 38 56 90 4 8 76 44 32 86 12 98 38 34 54 92 70 94 10 24 82 66 90 58 62 2 32 58 100 22 58 72 2 22 68 72 42 14",
"output": "1"
},
{
"input": "99\n38 20 68 60 84 16 28 88 60 48 80 28 4 92 70 60 46 46 20 34 12 100 76 2 40 10 8 86 6 80 50 66 12 34 14 28 26 70 46 64 34 96 10 90 98 96 56 88 50 74 70 94 2 94 24 66 68 46 22 30 6 10 64 32 88 14 98 100 64 58 50 18 50 50 8 38 8 16 54 2 60 54 62 84 92 98 4 72 66 26 14 88 99 16 10 6 88 56 22",
"output": "93"
},
{
"input": "99\n50 83 43 89 53 47 69 1 5 37 63 87 95 15 55 95 75 89 33 53 89 75 93 75 11 85 49 29 11 97 49 67 87 11 25 37 97 73 67 49 87 43 53 97 43 29 53 33 45 91 37 73 39 49 59 5 21 43 87 35 5 63 89 57 63 47 29 99 19 85 13 13 3 13 43 19 5 9 61 51 51 57 15 89 13 97 41 13 99 79 13 27 97 95 73 33 99 27 23",
"output": "1"
},
{
"input": "98\n61 56 44 30 58 14 20 24 88 28 46 56 96 52 58 42 94 50 46 30 46 80 72 88 68 16 6 60 26 90 10 98 76 20 56 40 30 16 96 20 88 32 62 30 74 58 36 76 60 4 24 36 42 54 24 92 28 14 2 74 86 90 14 52 34 82 40 76 8 64 2 56 10 8 78 16 70 86 70 42 70 74 22 18 76 98 88 28 62 70 36 72 20 68 34 48 80 98",
"output": "1"
},
{
"input": "98\n66 26 46 42 78 32 76 42 26 82 8 12 4 10 24 26 64 44 100 46 94 64 30 18 88 28 8 66 30 82 82 28 74 52 62 80 80 60 94 86 64 32 44 88 92 20 12 74 94 28 34 58 4 22 16 10 94 76 82 58 40 66 22 6 30 32 92 54 16 76 74 98 18 48 48 30 92 2 16 42 84 74 30 60 64 52 50 26 16 86 58 96 79 60 20 62 82 94",
"output": "93"
},
{
"input": "95\n9 31 27 93 17 77 75 9 9 53 89 39 51 99 5 1 11 39 27 49 91 17 27 79 81 71 37 75 35 13 93 4 99 55 85 11 23 57 5 43 5 61 15 35 23 91 3 81 99 85 43 37 39 27 5 67 7 33 75 59 13 71 51 27 15 93 51 63 91 53 43 99 25 47 17 71 81 15 53 31 59 83 41 23 73 25 91 91 13 17 25 13 55 57 29",
"output": "32"
},
{
"input": "100\n91 89 81 45 53 1 41 3 77 93 55 97 55 97 87 27 69 95 73 41 93 21 75 35 53 56 5 51 87 59 91 67 33 3 99 45 83 17 97 47 75 97 7 89 17 99 23 23 81 25 55 97 27 35 69 5 77 35 93 19 55 59 37 21 31 37 49 41 91 53 73 69 7 37 37 39 17 71 7 97 55 17 47 23 15 73 31 39 57 37 9 5 61 41 65 57 77 79 35 47",
"output": "26"
},
{
"input": "99\n38 56 58 98 80 54 26 90 14 16 78 92 52 74 40 30 84 14 44 80 16 90 98 68 26 24 78 72 42 16 84 40 14 44 2 52 50 2 12 96 58 66 8 80 44 52 34 34 72 98 74 4 66 74 56 21 8 38 76 40 10 22 48 32 98 34 12 62 80 68 64 82 22 78 58 74 20 22 48 56 12 38 32 72 6 16 74 24 94 84 26 38 18 24 76 78 98 94 72",
"output": "56"
},
{
"input": "100\n44 40 6 40 56 90 98 8 36 64 76 86 98 76 36 92 6 30 98 70 24 98 96 60 24 82 88 68 86 96 34 42 58 10 40 26 56 10 88 58 70 32 24 28 14 82 52 12 62 36 70 60 52 34 74 30 78 76 10 16 42 94 66 90 70 38 52 12 58 22 98 96 14 68 24 70 4 30 84 98 8 50 14 52 66 34 100 10 28 100 56 48 38 12 38 14 91 80 70 86",
"output": "97"
},
{
"input": "100\n96 62 64 20 90 46 56 90 68 36 30 56 70 28 16 64 94 34 6 32 34 50 94 22 90 32 40 2 72 10 88 38 28 92 20 26 56 80 4 100 100 90 16 74 74 84 8 2 30 20 80 32 16 46 92 56 42 12 96 64 64 42 64 58 50 42 74 28 2 4 36 32 70 50 54 92 70 16 45 76 28 16 18 50 48 2 62 94 4 12 52 52 4 100 70 60 82 62 98 42",
"output": "79"
},
{
"input": "99\n14 26 34 68 90 58 50 36 8 16 18 6 2 74 54 20 36 84 32 50 52 2 26 24 3 64 20 10 54 26 66 44 28 72 4 96 78 90 96 86 68 28 94 4 12 46 100 32 22 36 84 32 44 94 76 94 4 52 12 30 74 4 34 64 58 72 44 16 70 56 54 8 14 74 8 6 58 62 98 54 14 40 80 20 36 72 28 98 20 58 40 52 90 64 22 48 54 70 52",
"output": "25"
},
{
"input": "95\n82 86 30 78 6 46 80 66 74 72 16 24 18 52 52 38 60 36 86 26 62 28 22 46 96 26 94 84 20 46 66 88 76 32 12 86 74 18 34 88 4 48 94 6 58 6 100 82 4 24 88 32 54 98 34 48 6 76 42 88 42 28 100 4 22 2 10 66 82 54 98 20 60 66 38 98 32 47 86 58 6 100 12 46 2 42 8 84 78 28 24 70 34 28 86",
"output": "78"
},
{
"input": "90\n40 50 8 42 76 24 58 42 26 68 20 48 54 12 34 84 14 36 32 88 6 50 96 56 20 92 48 16 40 34 96 46 20 84 30 50 20 98 8 44 96 42 8 76 70 38 84 30 40 88 84 72 2 22 52 58 16 62 100 66 80 40 50 32 14 62 88 72 22 99 76 50 84 82 8 82 98 46 26 40 2 98 18 78 30 72 70 18 34 68",
"output": "70"
},
{
"input": "80\n81 43 87 1 55 43 53 61 27 19 43 13 89 9 33 83 75 55 97 71 91 37 95 5 21 69 81 93 95 69 31 83 55 7 97 7 79 57 8 61 27 85 49 1 15 97 63 79 29 73 41 85 5 41 31 93 67 11 63 59 15 99 91 77 43 69 23 23 81 73 19 1 67 51 1 75 99 67 3 81",
"output": "39"
},
{
"input": "98\n13 83 61 27 35 1 85 95 97 73 95 65 73 45 5 43 27 83 91 19 11 3 85 59 9 39 69 23 45 7 51 85 5 71 5 95 1 51 75 3 43 57 3 11 33 71 21 99 47 41 87 39 71 87 31 85 91 49 83 5 49 85 47 91 55 99 33 23 31 23 23 73 29 77 55 31 25 5 81 49 91 15 15 39 87 5 9 40 69 47 29 33 11 21 49 79 51 83",
"output": "88"
},
{
"input": "3\n100 100 1",
"output": "3"
}
] | 1,610,520,845 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 92 | 204,800 | n = input()
s = input()
s1 = s.split()
odd = 0
even = 0
for i in range(int(n)):
if int(s1[i]) % 2 == 0:
even = even + 1
else:
odd = odd + 1
if odd > even:
for i in range(int(n)):
if int(s1[i]) % 2 == 0:
print(i)
elif even > odd:
for i in range(int(n)):
if int(s1[i]) % 2 != 0:
print(i) | Title: IQ test
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Bob is preparing to pass IQ test. The most frequent task in this test is to find out which one of the given *n* numbers differs from the others. Bob observed that one number usually differs from the others in evenness. Help Bob — to check his answers, he needs a program that among the given *n* numbers finds one that is different in evenness.
Input Specification:
The first line contains integer *n* (3<=≤<=*n*<=≤<=100) — amount of numbers in the task. The second line contains *n* space-separated natural numbers, not exceeding 100. It is guaranteed, that exactly one of these numbers differs from the others in evenness.
Output Specification:
Output index of number that differs from the others in evenness. Numbers are numbered from 1 in the input order.
Demo Input:
['5\n2 4 7 8 10\n', '4\n1 2 1 1\n']
Demo Output:
['3\n', '2\n']
Note:
none | ```python
n = input()
s = input()
s1 = s.split()
odd = 0
even = 0
for i in range(int(n)):
if int(s1[i]) % 2 == 0:
even = even + 1
else:
odd = odd + 1
if odd > even:
for i in range(int(n)):
if int(s1[i]) % 2 == 0:
print(i)
elif even > odd:
for i in range(int(n)):
if int(s1[i]) % 2 != 0:
print(i)
``` | 0 |
112 | A | Petya and Strings | PROGRAMMING | 800 | [
"implementation",
"strings"
] | A. Petya and Strings | 2 | 256 | Little Petya loves presents. His mum bought him two strings of the same size for his birthday. The strings consist of uppercase and lowercase Latin letters. Now Petya wants to compare those two strings lexicographically. The letters' case does not matter, that is an uppercase letter is considered equivalent to the corresponding lowercase letter. Help Petya perform the comparison. | Each of the first two lines contains a bought string. The strings' lengths range from 1 to 100 inclusive. It is guaranteed that the strings are of the same length and also consist of uppercase and lowercase Latin letters. | If the first string is less than the second one, print "-1". If the second string is less than the first one, print "1". If the strings are equal, print "0". Note that the letters' case is not taken into consideration when the strings are compared. | [
"aaaa\naaaA\n",
"abs\nAbz\n",
"abcdefg\nAbCdEfF\n"
] | [
"0\n",
"-1\n",
"1\n"
] | If you want more formal information about the lexicographical order (also known as the "dictionary order" or "alphabetical order"), you can visit the following site:
- http://en.wikipedia.org/wiki/Lexicographical_order | 500 | [
{
"input": "aaaa\naaaA",
"output": "0"
},
{
"input": "abs\nAbz",
"output": "-1"
},
{
"input": "abcdefg\nAbCdEfF",
"output": "1"
},
{
"input": "asadasdasd\nasdwasdawd",
"output": "-1"
},
{
"input": "aslkjlkasdd\nasdlkjdajwi",
"output": "1"
},
{
"input": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\naaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
"output": "0"
},
{
"input": "aAaaaAAaAaaAzZsssSsdDfeEaeqZlpP\nAaaaAaaAaaAaZzSSSSsDdFeeAeQZLpp",
"output": "0"
},
{
"input": "bwuEhEveouaTECagLZiqmUdxEmhRSOzMauJRWLQMppZOumxhAmwuGeDIkvkBLvMXwUoFmpAfDprBcFtEwOULcZWRQhcTbTbX\nHhoDWbcxwiMnCNexOsKsujLiSGcLllXOkRSbnOzThAjnnliLYFFmsYkOfpTxRNEfBsoUHfoLTiqAINRPxWRqrTJhgfkKcDOH",
"output": "-1"
},
{
"input": "kGWUuguKzcvxqKTNpxeDWXpXkrXDvGMFGoXKDfPBZvWSDUyIYBynbKOUonHvmZaKeirUhfmVRKtGhAdBfKMWXDUoqvbfpfHYcg\ncvOULleuIIiYVVxcLZmHVpNGXuEpzcWZZWyMOwIwbpkKPwCfkVbKkUuosvxYCKjqfVmHfJKbdrsAcatPYgrCABaFcoBuOmMfFt",
"output": "1"
},
{
"input": "nCeNVIzHqPceNhjHeHvJvgBsNFiXBATRrjSTXJzhLMDMxiJztphxBRlDlqwDFImWeEPkggZCXSRwelOdpNrYnTepiOqpvkr\nHJbjJFtlvNxIbkKlxQUwmZHJFVNMwPAPDRslIoXISBYHHfymyIaQHLgECPxAmqnOCizwXnIUBRmpYUBVPenoUKhCobKdOjL",
"output": "1"
},
{
"input": "ttXjenUAlfixytHEOrPkgXmkKTSGYuyVXGIHYmWWYGlBYpHkujueqBSgjLguSgiMGJWATIGEUjjAjKXdMiVbHozZUmqQtFrT\nJziDBFBDmDJCcGqFsQwDFBYdOidLxxhBCtScznnDgnsiStlWFnEXQrJxqTXKPxZyIGfLIToETKWZBPUIBmLeImrlSBWCkTNo",
"output": "1"
},
{
"input": "AjQhPqSVhwQQjcgCycjKorWBgFCRuQBwgdVuAPSMJAvTyxGVuFHjfJzkKfsmfhFbKqFrFIohSZBbpjgEHebezmVlGLTPSCTMf\nXhxWuSnMmKFrCUOwkTUmvKAfbTbHWzzOTzxJatLLCdlGnHVaBUnxDlsqpvjLHMThOPAFBggVKDyKBrZAmjnjrhHlrnSkyzBja",
"output": "-1"
},
{
"input": "HCIgYtnqcMyjVngziNflxKHtdTmcRJhzMAjFAsNdWXFJYEhiTzsQUtFNkAbdrFBRmvLirkuirqTDvIpEfyiIqkrwsjvpPWTEdI\nErqiiWKsmIjyZuzgTlTqxYZwlrpvRyaVhRTOYUqtPMVGGtWOkDCOOQRKrkkRzPftyQCkYkzKkzTPqqXmeZhvvEEiEhkdOmoMvy",
"output": "1"
},
{
"input": "mtBeJYILXcECGyEVSyzLFdQJbiVnnfkbsYYsdUJSIRmyzLfTTtFwIBmRLVnwcewIqcuydkcLpflHAFyDaToLiFMgeHvQorTVbI\nClLvyejznjbRfCDcrCzkLvqQaGzTjwmWONBdCctJAPJBcQrcYvHaSLQgPIJbmkFBhFzuQLBiRzAdNHulCjIAkBvZxxlkdzUWLR",
"output": "1"
},
{
"input": "tjucSbGESVmVridTBjTmpVBCwwdWKBPeBvmgdxgIVLwQxveETnSdxkTVJpXoperWSgdpPMKNmwDiGeHfxnuqaDissgXPlMuNZIr\nHfjOOJhomqNIKHvqSgfySjlsWJQBuWYwhLQhlZYlpZwboMpoLoluGsBmhhlYgeIouwdkPfiaAIrkYRlxtiFazOPOllPsNZHcIZd",
"output": "1"
},
{
"input": "AanbDfbZNlUodtBQlvPMyomStKNhgvSGhSbTdabxGFGGXCdpsJDimsAykKjfBDPMulkhBMsqLmVKLDoesHZsRAEEdEzqigueXInY\ncwfyjoppiJNrjrOLNZkqcGimrpTsiyFBVgMWEPXsMrxLJDDbtYzerXiFGuLBcQYitLdqhGHBpdjRnkUegmnwhGHAKXGyFtscWDSI",
"output": "-1"
},
{
"input": "HRfxniwuJCaHOcaOVgjOGHXKrwxrDQxJpppeGDXnTAowyKbCsCQPbchCKeTWOcKbySSYnoaTJDnmRcyGPbfXJyZoPcARHBu\nxkLXvwkvGIWSQaFTznLOctUXNuzzBBOlqvzmVfTSejekTAlwidRrsxkbZTsGGeEWxCXHzqWVuLGoCyrGjKkQoHqduXwYQKC",
"output": "-1"
},
{
"input": "OjYwwNuPESIazoyLFREpObIaMKhCaKAMWMfRGgucEuyNYRantwdwQkmflzfqbcFRaXBnZoIUGsFqXZHGKwlaBUXABBcQEWWPvkjW\nRxLqGcTTpBwHrHltCOllnTpRKLDofBUqqHxnOtVWPgvGaeHIevgUSOeeDOJubfqonFpVNGVbHFcAhjnyFvrrqnRgKhkYqQZmRfUl",
"output": "-1"
},
{
"input": "tatuhQPIzjptlzzJpCAPXSRTKZRlwgfoCIsFjJquRoIDyZZYRSPdFUTjjUPhLBBfeEIfLQpygKXRcyQFiQsEtRtLnZErBqW\ntkHUjllbafLUWhVCnvblKjgYIEoHhsjVmrDBmAWbvtkHxDbRFvsXAjHIrujaDbYwOZmacknhZPeCcorbRgHjjgAgoJdjvLo",
"output": "-1"
},
{
"input": "cymCPGqdXKUdADEWDdUaLEEMHiXHsdAZuDnJDMUvxvrLRBrPSDpXPAgMRoGplLtniFRTomDTAHXWAdgUveTxaqKVSvnOyhOwiRN\nuhmyEWzapiRNPFDisvHTbenXMfeZaHqOFlKjrfQjUBwdFktNpeiRoDWuBftZLcCZZAVfioOihZVNqiNCNDIsUdIhvbcaxpTRWoV",
"output": "-1"
},
{
"input": "sSvpcITJAwghVfJaLKBmyjOkhltTGjYJVLWCYMFUomiJaKQYhXTajvZVHIMHbyckYROGQZzjWyWCcnmDmrkvTKfHSSzCIhsXgEZa\nvhCXkCwAmErGVBPBAnkSYEYvseFKbWSktoqaHYXUmYkHfOkRwuEyBRoGoBrOXBKVxXycjZGStuvDarnXMbZLWrbjrisDoJBdSvWJ",
"output": "-1"
},
{
"input": "hJDANKUNBisOOINDsTixJmYgHNogtpwswwcvVMptfGwIjvqgwTYFcqTdyAqaqlnhOCMtsnWXQqtjFwQlEcBtMFAtSqnqthVb\nrNquIcjNWESjpPVWmzUJFrelpUZeGDmSvCurCqVmKHKVAAPkaHksniOlzjiKYIJtvbuQWZRufMebpTFPqyxIWWjfPaWYiNlK",
"output": "-1"
},
{
"input": "ycLoapxsfsDTHMSfAAPIUpiEhQKUIXUcXEiopMBuuZLHtfPpLmCHwNMNQUwsEXxCEmKHTBSnKhtQhGWUvppUFZUgSpbeChX\ndCZhgVXofkGousCzObxZSJwXcHIaqUDSCPKzXntcVmPxtNcXmVcjsetZYxedmgQzXTZHMvzjoaXCMKsncGciSDqQWIIRlys",
"output": "1"
},
{
"input": "nvUbnrywIePXcoukIhwTfUVcHUEgXcsMyNQhmMlTltZiCooyZiIKRIGVHMCnTKgzXXIuvoNDEZswKoACOBGSyVNqTNQqMhAG\nplxuGSsyyJjdvpddrSebOARSAYcZKEaKjqbCwvjhNykuaECoQVHTVFMKXwvrQXRaqXsHsBaGVhCxGRxNyGUbMlxOarMZNXxy",
"output": "-1"
},
{
"input": "EncmXtAblQzcVRzMQqdDqXfAhXbtJKQwZVWyHoWUckohnZqfoCmNJDzexFgFJYrwNHGgzCJTzQQFnxGlhmvQTpicTkEeVICKac\nNIUNZoMLFMyAjVgQLITELJSodIXcGSDWfhFypRoGYuogJpnqGTotWxVqpvBHjFOWcDRDtARsaHarHaOkeNWEHGTaGOFCOFEwvK",
"output": "-1"
},
{
"input": "UG\nak",
"output": "1"
},
{
"input": "JZR\nVae",
"output": "-1"
},
{
"input": "a\nZ",
"output": "-1"
},
{
"input": "rk\nkv",
"output": "1"
},
{
"input": "RvuT\nbJzE",
"output": "1"
},
{
"input": "PPS\nydq",
"output": "-1"
},
{
"input": "q\nq",
"output": "0"
},
{
"input": "peOw\nIgSJ",
"output": "1"
},
{
"input": "PyK\noKN",
"output": "1"
},
{
"input": "O\ni",
"output": "1"
},
{
"input": "NmGY\npDlP",
"output": "-1"
},
{
"input": "nG\nZf",
"output": "-1"
},
{
"input": "m\na",
"output": "1"
},
{
"input": "MWyB\nWZEV",
"output": "-1"
},
{
"input": "Gre\nfxc",
"output": "1"
},
{
"input": "Ooq\nwap",
"output": "-1"
},
{
"input": "XId\nlbB",
"output": "1"
},
{
"input": "lfFpECEqUMEOJhipvkZjDPcpDNJedOVXiSMgBvBZbtfzIKekcvpWPCazKAhJyHircRtgcBIJwwstpHaLAgxFOngAWUZRgCef\nLfFPEcequmeojHIpVkzjDPcpdNJEDOVXiSmGBVBZBtfZikEKcvPwpCAzKAHJyHIrCRTgCbIJWwSTphALagXfOnGAwUzRGcEF",
"output": "0"
},
{
"input": "DQBdtSEDtFGiNRUeJNbOIfDZnsryUlzJHGTXGFXnwsVyxNtLgmklmFvRCzYETBVdmkpJJIvIOkMDgCFHZOTODiYrkwXd\nDQbDtsEdTFginRUEJNBOIfdZnsryulZJHGtxGFxnwSvYxnTLgmKlmFVRCzyEtBVdmKpJjiVioKMDgCFhzoTODiYrKwXD",
"output": "0"
},
{
"input": "tYWRijFQSzHBpCjUzqBtNvBKyzZRnIdWEuyqnORBQTLyOQglIGfYJIRjuxnbLvkqZakNqPiGDvgpWYkfxYNXsdoKXZtRkSasfa\nTYwRiJfqsZHBPcJuZQBTnVbkyZZRnidwEuYQnorbQTLYOqGligFyjirJUxnblVKqZaknQpigDVGPwyKfxyNXSDoKxztRKSaSFA",
"output": "0"
},
{
"input": "KhScXYiErQIUtmVhNTCXSLAviefIeHIIdiGhsYnPkSBaDTvMkyanfMLBOvDWgRybLtDqvXVdVjccNunDyijhhZEAKBrdz\nkHsCXyiErqIuTMVHNTCxSLaViEFIEhIIDiGHsYNpKsBAdTvMKyANFMLBovdwGRYbLtdQVxvDVJCcNUndYiJHhzeakBrdZ",
"output": "0"
},
{
"input": "cpPQMpjRQJKQVXjWDYECXbagSmNcVfOuBWNZxihdERraVuiOpSVDCPgTGuSQALNoVjySceHcKXwOEpSzXrEqWwwrYeppNiWhDVg\nCPPqmPjRqJkQvxJwdyECXBAGsMNcVfOuBWNzxIhderRavUiOpSvDCpGTgusqAlNovjyScEhCKXwoePSZxrEQwWwryEPPniWHDvG",
"output": "0"
},
{
"input": "SajcCGMepaLjZIWLRBGFcrZRCRvvoCsIyKsQerbrwsIamxxpRmQSZSalasJLVFbCHCuXJlubciQAvLxXYBazLsMKLHLdDQ\nsaJcCgmEpaLJziWlrBgFcRzrCrVVOcSIykSQerBrwSIamxxPrMqSzSalASjLVFbChCUxjLUbCIQAVlxxybAZLsmkLhLDdQ",
"output": "0"
},
{
"input": "kigPrWNTOUNDBskAfefjhHYZNYdnfZWuXWzHiBxFQryBbAkPtenFwWvCSTYGpzOntUNzNUhxRWjKmicTwLwJAnbAxj\nkigpRWntOUNdBsKaFEFjhhYZnYDNfzWuXwZhibxFQRybbakPteNfwwvcStyGPzoNTunznuHXrWjKMIctWLWJANBAxJ",
"output": "0"
},
{
"input": "nTomZZuTTRTAAPoUsySVFGElrpQRNLjqvFmcYytiheQnjUhPLnqNBiYtQkljbcvmjuNAVKbvQOWpqqFlQhAhULIhquoCnjUI\nntOmzZuttrtAAPOUSySVFgeLRPQrNLjQvfmCyYTiHEQnjuHPlNQNbIYtqKLJBCVmjunavkbvQOWPQQFlqHaHULIHQuOcnJUi",
"output": "0"
},
{
"input": "abac\nadaa",
"output": "-1"
},
{
"input": "Bbc\nabc",
"output": "1"
},
{
"input": "aaaba\naaaab",
"output": "1"
}
] | 1,695,174,378 | 2,147,483,647 | Python 3 | OK | TESTS | 53 | 92 | 0 | a = input().lower()
b = input().lower()
abi = True
for i in range(len(a)):
if a[i] > b[i]:
print('1')
abi = False
break
elif a[i] < b[i]:
print('-1')
abi = False
break
if abi:
print('0')
| Title: Petya and Strings
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Little Petya loves presents. His mum bought him two strings of the same size for his birthday. The strings consist of uppercase and lowercase Latin letters. Now Petya wants to compare those two strings lexicographically. The letters' case does not matter, that is an uppercase letter is considered equivalent to the corresponding lowercase letter. Help Petya perform the comparison.
Input Specification:
Each of the first two lines contains a bought string. The strings' lengths range from 1 to 100 inclusive. It is guaranteed that the strings are of the same length and also consist of uppercase and lowercase Latin letters.
Output Specification:
If the first string is less than the second one, print "-1". If the second string is less than the first one, print "1". If the strings are equal, print "0". Note that the letters' case is not taken into consideration when the strings are compared.
Demo Input:
['aaaa\naaaA\n', 'abs\nAbz\n', 'abcdefg\nAbCdEfF\n']
Demo Output:
['0\n', '-1\n', '1\n']
Note:
If you want more formal information about the lexicographical order (also known as the "dictionary order" or "alphabetical order"), you can visit the following site:
- http://en.wikipedia.org/wiki/Lexicographical_order | ```python
a = input().lower()
b = input().lower()
abi = True
for i in range(len(a)):
if a[i] > b[i]:
print('1')
abi = False
break
elif a[i] < b[i]:
print('-1')
abi = False
break
if abi:
print('0')
``` | 3.977 |
847 | M | Weather Tomorrow | PROGRAMMING | 1,000 | [
"implementation",
"math"
] | null | null | Vasya came up with his own weather forecasting method. He knows the information about the average air temperature for each of the last *n* days. Assume that the average air temperature for each day is integral.
Vasya believes that if the average temperatures over the last *n* days form an arithmetic progression, where the first term equals to the average temperature on the first day, the second term equals to the average temperature on the second day and so on, then the average temperature of the next (*n*<=+<=1)-th day will be equal to the next term of the arithmetic progression. Otherwise, according to Vasya's method, the temperature of the (*n*<=+<=1)-th day will be equal to the temperature of the *n*-th day.
Your task is to help Vasya predict the average temperature for tomorrow, i. e. for the (*n*<=+<=1)-th day. | The first line contains a single integer *n* (2<=≤<=*n*<=≤<=100) — the number of days for which the average air temperature is known.
The second line contains a sequence of integers *t*1,<=*t*2,<=...,<=*t**n* (<=-<=1000<=≤<=*t**i*<=≤<=1000) — where *t**i* is the average temperature in the *i*-th day. | Print the average air temperature in the (*n*<=+<=1)-th day, which Vasya predicts according to his method. Note that the absolute value of the predicted temperature can exceed 1000. | [
"5\n10 5 0 -5 -10\n",
"4\n1 1 1 1\n",
"3\n5 1 -5\n",
"2\n900 1000\n"
] | [
"-15\n",
"1\n",
"-5\n",
"1100\n"
] | In the first example the sequence of the average temperatures is an arithmetic progression where the first term is 10 and each following terms decreases by 5. So the predicted average temperature for the sixth day is - 10 - 5 = - 15.
In the second example the sequence of the average temperatures is an arithmetic progression where the first term is 1 and each following terms equals to the previous one. So the predicted average temperature in the fifth day is 1.
In the third example the average temperatures do not form an arithmetic progression, so the average temperature of the fourth day equals to the temperature of the third day and equals to - 5.
In the fourth example the sequence of the average temperatures is an arithmetic progression where the first term is 900 and each the following terms increase by 100. So predicted average temperature in the third day is 1000 + 100 = 1100. | 0 | [
{
"input": "5\n10 5 0 -5 -10",
"output": "-15"
},
{
"input": "4\n1 1 1 1",
"output": "1"
},
{
"input": "3\n5 1 -5",
"output": "-5"
},
{
"input": "2\n900 1000",
"output": "1100"
},
{
"input": "2\n1 2",
"output": "3"
},
{
"input": "3\n2 5 8",
"output": "11"
},
{
"input": "4\n4 1 -2 -5",
"output": "-8"
},
{
"input": "10\n-1000 -995 -990 -985 -980 -975 -970 -965 -960 -955",
"output": "-950"
},
{
"input": "11\n-1000 -800 -600 -400 -200 0 200 400 600 800 1000",
"output": "1200"
},
{
"input": "31\n1000 978 956 934 912 890 868 846 824 802 780 758 736 714 692 670 648 626 604 582 560 538 516 494 472 450 428 406 384 362 340",
"output": "318"
},
{
"input": "5\n1000 544 88 -368 -824",
"output": "-1280"
},
{
"input": "100\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0",
"output": "0"
},
{
"input": "33\n456 411 366 321 276 231 186 141 96 51 6 -39 -84 -129 -174 -219 -264 -309 -354 -399 -444 -489 -534 -579 -624 -669 -714 -759 -804 -849 -894 -939 -984",
"output": "-1029"
},
{
"input": "77\n-765 -742 -719 -696 -673 -650 -627 -604 -581 -558 -535 -512 -489 -466 -443 -420 -397 -374 -351 -328 -305 -282 -259 -236 -213 -190 -167 -144 -121 -98 -75 -52 -29 -6 17 40 63 86 109 132 155 178 201 224 247 270 293 316 339 362 385 408 431 454 477 500 523 546 569 592 615 638 661 684 707 730 753 776 799 822 845 868 891 914 937 960 983",
"output": "1006"
},
{
"input": "3\n2 4 8",
"output": "8"
},
{
"input": "4\n4 1 -3 -5",
"output": "-5"
},
{
"input": "10\n-1000 -995 -990 -984 -980 -975 -970 -965 -960 -955",
"output": "-955"
},
{
"input": "11\n-999 -800 -600 -400 -200 0 200 400 600 800 1000",
"output": "1000"
},
{
"input": "51\n-9 10 30 50 70 90 110 130 150 170 190 210 230 250 270 290 310 330 350 370 390 410 430 450 470 490 510 530 550 570 590 610 630 650 670 690 710 730 750 770 790 810 830 850 870 890 910 930 950 970 990",
"output": "990"
},
{
"input": "100\n10 12 14 16 18 20 22 24 26 28 30 32 34 36 38 40 42 44 46 48 50 52 54 56 58 60 62 64 66 68 70 72 74 76 78 80 82 84 86 88 90 92 94 96 98 100 102 104 106 108 110 112 114 116 118 120 122 124 126 128 130 132 134 136 138 140 142 144 146 148 150 152 154 156 158 160 162 164 166 168 170 172 174 176 178 180 182 184 186 188 190 192 194 196 198 200 202 204 206 207",
"output": "207"
},
{
"input": "2\n1000 1000",
"output": "1000"
},
{
"input": "2\n-1000 1000",
"output": "3000"
},
{
"input": "2\n1000 -1000",
"output": "-3000"
},
{
"input": "2\n-1000 -1000",
"output": "-1000"
},
{
"input": "100\n-85 -80 -76 -72 -68 -64 -60 -56 -52 -48 -44 -40 -36 -32 -28 -24 -20 -16 -12 -8 -4 0 4 8 12 16 20 24 28 32 36 40 44 48 52 56 60 64 68 72 76 80 84 88 92 96 100 104 108 112 116 120 124 128 132 136 140 144 148 152 156 160 164 168 172 176 180 184 188 192 196 200 204 208 212 216 220 224 228 232 236 240 244 248 252 256 260 264 268 272 276 280 284 288 292 296 300 304 308 312",
"output": "312"
},
{
"input": "4\n1 2 4 5",
"output": "5"
}
] | 1,680,878,020 | 2,147,483,647 | Python 3 | OK | TESTS | 26 | 46 | 0 | n = int(input())
vals = list(map(int,(input().split())))
arith = True
diff = vals[0]-vals[1]
for i in range(n-1):
if vals[i]-vals[i+1]!=diff:
arith = False
break
if arith:
print(vals[-1]-diff)
else:
print(vals[-1]) | Title: Weather Tomorrow
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vasya came up with his own weather forecasting method. He knows the information about the average air temperature for each of the last *n* days. Assume that the average air temperature for each day is integral.
Vasya believes that if the average temperatures over the last *n* days form an arithmetic progression, where the first term equals to the average temperature on the first day, the second term equals to the average temperature on the second day and so on, then the average temperature of the next (*n*<=+<=1)-th day will be equal to the next term of the arithmetic progression. Otherwise, according to Vasya's method, the temperature of the (*n*<=+<=1)-th day will be equal to the temperature of the *n*-th day.
Your task is to help Vasya predict the average temperature for tomorrow, i. e. for the (*n*<=+<=1)-th day.
Input Specification:
The first line contains a single integer *n* (2<=≤<=*n*<=≤<=100) — the number of days for which the average air temperature is known.
The second line contains a sequence of integers *t*1,<=*t*2,<=...,<=*t**n* (<=-<=1000<=≤<=*t**i*<=≤<=1000) — where *t**i* is the average temperature in the *i*-th day.
Output Specification:
Print the average air temperature in the (*n*<=+<=1)-th day, which Vasya predicts according to his method. Note that the absolute value of the predicted temperature can exceed 1000.
Demo Input:
['5\n10 5 0 -5 -10\n', '4\n1 1 1 1\n', '3\n5 1 -5\n', '2\n900 1000\n']
Demo Output:
['-15\n', '1\n', '-5\n', '1100\n']
Note:
In the first example the sequence of the average temperatures is an arithmetic progression where the first term is 10 and each following terms decreases by 5. So the predicted average temperature for the sixth day is - 10 - 5 = - 15.
In the second example the sequence of the average temperatures is an arithmetic progression where the first term is 1 and each following terms equals to the previous one. So the predicted average temperature in the fifth day is 1.
In the third example the average temperatures do not form an arithmetic progression, so the average temperature of the fourth day equals to the temperature of the third day and equals to - 5.
In the fourth example the sequence of the average temperatures is an arithmetic progression where the first term is 900 and each the following terms increase by 100. So predicted average temperature in the third day is 1000 + 100 = 1100. | ```python
n = int(input())
vals = list(map(int,(input().split())))
arith = True
diff = vals[0]-vals[1]
for i in range(n-1):
if vals[i]-vals[i+1]!=diff:
arith = False
break
if arith:
print(vals[-1]-diff)
else:
print(vals[-1])
``` | 3 |
|
129 | A | Cookies | PROGRAMMING | 900 | [
"implementation"
] | null | null | Olga came to visit the twins Anna and Maria and saw that they have many cookies. The cookies are distributed into bags. As there are many cookies, Olga decided that it's no big deal if she steals a bag. However, she doesn't want the sisters to quarrel because of nothing when they divide the cookies. That's why Olga wants to steal a bag with cookies so that the number of cookies in the remaining bags was even, that is, so that Anna and Maria could evenly divide it into two (even 0 remaining cookies will do, just as any other even number). How many ways there are to steal exactly one cookie bag so that the total number of cookies in the remaining bags was even? | The first line contains the only integer *n* (1<=≤<=*n*<=≤<=100) — the number of cookie bags Anna and Maria have. The second line contains *n* integers *a**i* (1<=≤<=*a**i*<=≤<=100) — the number of cookies in the *i*-th bag. | Print in the only line the only number — the sought number of ways. If there are no such ways print 0. | [
"1\n1\n",
"10\n1 2 2 3 4 4 4 2 2 2\n",
"11\n2 2 2 2 2 2 2 2 2 2 99\n"
] | [
"1\n",
"8\n",
"1\n"
] | In the first sample Olga should take the only bag so that the twins ended up with the even number of cookies.
In the second sample Olga can take any of five bags with two cookies or any of three bags with four cookies — 5 + 3 = 8 ways in total.
In the third sample, no matter which bag with two cookies Olga chooses, the twins are left with 2 * 9 + 99 = 117 cookies. Thus, Olga has only one option: to take the bag with 99 cookies. | 500 | [
{
"input": "1\n1",
"output": "1"
},
{
"input": "10\n1 2 2 3 4 4 4 2 2 2",
"output": "8"
},
{
"input": "11\n2 2 2 2 2 2 2 2 2 2 99",
"output": "1"
},
{
"input": "2\n1 1",
"output": "0"
},
{
"input": "2\n2 2",
"output": "2"
},
{
"input": "2\n1 2",
"output": "1"
},
{
"input": "7\n7 7 7 7 7 7 7",
"output": "7"
},
{
"input": "8\n1 2 3 4 5 6 7 8",
"output": "4"
},
{
"input": "100\n1 1 1 1 1 2 2 2 2 2 1 1 1 1 1 2 2 2 2 2 1 1 1 1 1 2 2 2 2 2 1 1 1 1 1 2 2 2 2 2 1 1 1 1 1 2 2 2 2 2 1 1 1 1 1 2 2 2 2 2 1 1 1 1 1 2 2 2 2 2 1 1 1 1 1 2 2 2 2 2 1 1 1 1 1 2 2 2 2 2 1 1 1 1 1 2 2 2 2 2",
"output": "50"
},
{
"input": "99\n99 100 99 100 99 100 99 100 99 100 99 100 99 100 99 100 99 100 99 100 99 100 99 100 99 100 99 100 99 100 99 100 99 100 99 100 99 100 99 100 99 100 99 100 99 100 99 100 99 100 99 100 99 100 99 100 99 100 99 100 99 100 99 100 99 100 99 100 99 100 99 100 99 100 99 100 99 100 99 100 99 100 99 100 99 100 99 100 99 100 99 100 99 100 99 100 99 100 99",
"output": "49"
},
{
"input": "82\n43 44 96 33 23 42 33 66 53 87 8 90 43 91 40 88 51 18 48 62 59 10 22 20 54 6 13 63 2 56 31 52 98 42 54 32 26 77 9 24 33 91 16 30 39 34 78 82 73 90 12 15 67 76 30 18 44 86 84 98 65 54 100 79 28 34 40 56 11 43 72 35 86 59 89 40 30 33 7 19 44 15",
"output": "50"
},
{
"input": "17\n50 14 17 77 74 74 38 76 41 27 45 29 66 98 38 73 38",
"output": "7"
},
{
"input": "94\n81 19 90 99 26 11 86 44 78 36 80 59 99 90 78 72 71 20 94 56 42 40 71 84 10 85 10 70 52 27 39 55 90 16 48 25 7 79 99 100 38 10 99 56 3 4 78 9 16 57 14 40 52 54 57 70 30 86 56 84 97 60 59 69 49 66 23 92 90 46 86 73 53 47 1 83 14 20 24 66 13 45 41 14 86 75 55 88 48 95 82 24 47 87",
"output": "39"
},
{
"input": "88\n64 95 12 90 40 65 98 45 52 54 79 7 81 25 98 19 68 82 41 53 35 50 5 22 32 21 8 39 8 6 72 27 81 30 12 79 21 42 60 2 66 87 46 93 62 78 52 71 76 32 78 94 86 85 55 15 34 76 41 20 32 26 94 81 89 45 74 49 11 40 40 39 49 46 80 85 90 23 80 40 86 58 70 26 48 93 23 53",
"output": "37"
},
{
"input": "84\n95 9 43 43 13 84 60 90 1 8 97 99 54 34 59 83 33 15 51 26 40 12 66 65 19 30 29 78 92 60 25 13 19 84 71 73 12 24 54 49 16 41 11 40 57 59 34 40 39 9 71 83 1 77 79 53 94 47 78 55 77 85 29 52 80 90 53 77 97 97 27 79 28 23 83 25 26 22 49 86 63 56 3 32",
"output": "51"
},
{
"input": "47\n61 97 76 94 91 22 2 68 62 73 90 47 16 79 44 71 98 68 43 6 53 52 40 27 68 67 43 96 14 91 60 61 96 24 97 13 32 65 85 96 81 77 34 18 23 14 80",
"output": "21"
},
{
"input": "69\n71 1 78 74 58 89 30 6 100 90 22 61 11 59 14 74 27 25 78 61 45 19 25 33 37 4 52 43 53 38 9 100 56 67 69 38 76 91 63 60 93 52 28 61 9 98 8 14 57 63 89 64 98 51 36 66 36 86 13 82 50 91 52 64 86 78 78 83 81",
"output": "37"
},
{
"input": "52\n38 78 36 75 19 3 56 1 39 97 24 79 84 16 93 55 96 64 12 24 1 86 80 29 12 32 36 36 73 39 76 65 53 98 30 20 28 8 86 43 70 22 75 69 62 65 81 25 53 40 71 59",
"output": "28"
},
{
"input": "74\n81 31 67 97 26 75 69 81 11 13 13 74 77 88 52 20 52 64 66 75 72 28 41 54 26 75 41 91 75 15 18 36 13 83 63 61 14 48 53 63 19 67 35 48 23 65 73 100 44 55 92 88 99 17 73 25 83 7 31 89 12 80 98 39 42 75 14 29 81 35 77 87 33 94",
"output": "47"
},
{
"input": "44\n46 56 31 31 37 71 94 2 14 100 45 72 36 72 80 3 38 54 42 98 50 32 31 42 62 31 45 50 95 100 18 17 64 22 18 25 52 56 70 57 43 40 81 28",
"output": "15"
},
{
"input": "22\n28 57 40 74 51 4 45 84 99 12 95 14 92 60 47 81 84 51 31 91 59 42",
"output": "11"
},
{
"input": "59\n73 45 94 76 41 49 65 13 74 66 36 25 47 75 40 23 92 72 11 32 32 8 81 26 68 56 41 8 76 47 96 55 70 11 84 14 83 18 70 22 30 39 28 100 48 11 92 45 78 69 86 1 54 90 98 91 13 17 35",
"output": "33"
},
{
"input": "63\n20 18 44 94 68 57 16 43 74 55 68 24 21 95 76 84 50 50 47 86 86 12 58 55 28 72 86 18 34 45 81 88 3 72 41 9 60 90 81 93 12 6 9 6 2 41 1 7 9 29 81 14 64 80 20 36 67 54 7 5 35 81 22",
"output": "37"
},
{
"input": "28\n49 84 48 19 44 91 11 82 96 95 88 90 71 82 87 25 31 23 18 13 98 45 26 65 35 12 31 14",
"output": "15"
},
{
"input": "61\n34 18 28 64 28 45 9 77 77 20 63 92 79 16 16 100 86 2 91 91 57 15 31 95 10 88 84 5 82 83 53 98 59 17 97 80 76 80 81 3 91 81 87 93 61 46 10 49 6 22 21 75 63 89 21 81 30 19 67 38 77",
"output": "35"
},
{
"input": "90\n41 90 43 1 28 75 90 50 3 70 76 64 81 63 25 69 83 82 29 91 59 66 21 61 7 55 72 49 38 69 72 20 64 58 30 81 61 29 96 14 39 5 100 20 29 98 75 29 44 78 97 45 26 77 73 59 22 99 41 6 3 96 71 20 9 18 96 18 90 62 34 78 54 5 41 6 73 33 2 54 26 21 18 6 45 57 43 73 95 75",
"output": "42"
},
{
"input": "45\n93 69 4 27 20 14 71 48 79 3 32 26 49 30 57 88 13 56 49 61 37 32 47 41 41 70 45 68 82 18 8 6 25 20 15 13 71 99 28 6 52 34 19 59 26",
"output": "23"
},
{
"input": "33\n29 95 48 49 91 10 83 71 47 25 66 36 51 12 34 10 54 74 41 96 89 26 89 1 42 33 1 62 9 32 49 65 78",
"output": "15"
},
{
"input": "34\n98 24 42 36 41 82 28 58 89 34 77 70 76 44 74 54 66 100 13 79 4 88 21 1 11 45 91 29 87 100 29 54 82 78",
"output": "13"
},
{
"input": "29\n91 84 26 84 9 63 52 9 65 56 90 2 36 7 67 33 91 14 65 38 53 36 81 83 85 14 33 95 51",
"output": "17"
},
{
"input": "100\n2 88 92 82 87 100 78 28 84 43 78 32 43 33 97 19 15 52 29 84 57 72 54 13 99 28 82 79 40 70 34 92 91 53 9 88 27 43 14 92 72 37 26 37 20 95 19 34 49 64 33 37 34 27 80 79 9 54 99 68 25 4 68 73 46 66 24 78 3 87 26 52 50 84 4 95 23 83 39 58 86 36 33 16 98 2 84 19 53 12 69 60 10 11 78 17 79 92 77 59",
"output": "45"
},
{
"input": "100\n2 95 45 73 9 54 20 97 57 82 88 26 18 71 25 27 75 54 31 11 58 85 69 75 72 91 76 5 25 80 45 49 4 73 8 81 81 38 5 12 53 77 7 96 90 35 28 80 73 94 19 69 96 17 94 49 69 9 32 19 5 12 46 29 26 40 59 59 6 95 82 50 72 2 45 69 12 5 72 29 39 72 23 96 81 28 28 56 68 58 37 41 30 1 90 84 15 24 96 43",
"output": "53"
},
{
"input": "100\n27 72 35 91 13 10 35 45 24 55 83 84 63 96 29 79 34 67 63 92 48 83 18 77 28 27 49 66 29 88 55 15 6 58 14 67 94 36 77 7 7 64 61 52 71 18 36 99 76 6 50 67 16 13 41 7 89 73 61 51 78 22 78 32 76 100 3 31 89 71 63 53 15 85 77 54 89 33 68 74 3 23 57 5 43 89 75 35 9 86 90 11 31 46 48 37 74 17 77 8",
"output": "40"
},
{
"input": "100\n69 98 69 88 11 49 55 8 25 91 17 81 47 26 15 73 96 71 18 42 42 61 48 14 92 78 35 72 4 27 62 75 83 79 17 16 46 80 96 90 82 54 37 69 85 21 67 70 96 10 46 63 21 59 56 92 54 88 77 30 75 45 44 29 86 100 51 11 65 69 66 56 82 63 27 1 51 51 13 10 3 55 26 85 34 16 87 72 13 100 81 71 90 95 86 50 83 55 55 54",
"output": "53"
},
{
"input": "100\n34 35 99 64 2 66 78 93 20 48 12 79 19 10 87 7 42 92 60 79 5 2 24 89 57 48 63 92 74 4 16 51 7 12 90 48 87 17 18 73 51 58 97 97 25 38 15 97 96 73 67 91 6 75 14 13 87 79 75 3 15 55 35 95 71 45 10 13 20 37 82 26 2 22 13 83 97 84 39 79 43 100 54 59 98 8 61 34 7 65 75 44 24 77 73 88 34 95 44 77",
"output": "55"
},
{
"input": "100\n15 86 3 1 51 26 74 85 37 87 64 58 10 6 57 26 30 47 85 65 24 72 50 40 12 35 91 47 91 60 47 87 95 34 80 91 26 3 36 39 14 86 28 70 51 44 28 21 72 79 57 61 16 71 100 94 57 67 36 74 24 21 89 85 25 2 97 67 76 53 76 80 97 64 35 13 8 32 21 52 62 61 67 14 74 73 66 44 55 76 24 3 43 42 99 61 36 80 38 66",
"output": "52"
},
{
"input": "100\n45 16 54 54 80 94 74 93 75 85 58 95 79 30 81 2 84 4 57 23 92 64 78 1 50 36 13 27 56 54 10 77 87 1 5 38 85 74 94 82 30 45 72 83 82 30 81 82 82 3 69 82 7 92 39 60 94 42 41 5 3 17 67 21 79 44 79 96 28 3 53 68 79 89 63 83 1 44 4 31 84 15 73 77 19 66 54 6 73 1 67 24 91 11 86 45 96 82 20 89",
"output": "51"
},
{
"input": "100\n84 23 50 32 90 71 92 43 58 70 6 82 7 55 85 19 70 89 12 26 29 56 74 30 2 27 4 39 63 67 91 81 11 33 75 10 82 88 39 43 43 80 68 35 55 67 53 62 73 65 86 74 43 51 14 48 42 92 83 57 22 33 24 99 5 27 78 96 7 28 11 15 8 38 85 67 5 92 24 96 57 59 14 95 91 4 9 18 45 33 74 83 64 85 14 51 51 94 29 2",
"output": "53"
},
{
"input": "100\n77 56 56 45 73 55 32 37 39 50 30 95 79 21 44 34 51 43 86 91 39 30 85 15 35 93 100 14 57 31 80 79 38 40 88 4 91 54 7 95 76 26 62 84 17 33 67 47 6 82 69 51 17 2 59 24 11 12 31 90 12 11 55 38 72 49 30 50 42 46 5 97 9 9 30 45 86 23 19 82 40 42 5 40 35 98 35 32 60 60 5 28 84 35 21 49 68 53 68 23",
"output": "48"
},
{
"input": "100\n78 38 79 61 45 86 83 83 86 90 74 69 2 84 73 39 2 5 20 71 24 80 54 89 58 34 77 40 39 62 2 47 28 53 97 75 88 98 94 96 33 71 44 90 47 36 19 89 87 98 90 87 5 85 34 79 82 3 42 88 89 63 35 7 89 30 40 48 12 41 56 76 83 60 80 80 39 56 77 4 72 96 30 55 57 51 7 19 11 1 66 1 91 87 11 62 95 85 79 25",
"output": "48"
},
{
"input": "100\n5 34 23 20 76 75 19 51 17 82 60 13 83 6 65 16 20 43 66 54 87 10 87 73 50 24 16 98 33 28 80 52 54 82 26 92 14 13 84 92 94 29 61 21 60 20 48 94 24 20 75 70 58 27 68 45 86 89 29 8 67 38 83 48 18 100 11 22 46 84 52 97 70 19 50 75 3 7 52 53 72 41 18 31 1 38 49 53 11 64 99 76 9 87 48 12 100 32 44 71",
"output": "58"
},
{
"input": "100\n76 89 68 78 24 72 73 95 98 72 58 15 2 5 56 32 9 65 50 70 94 31 29 54 89 52 31 93 43 56 26 35 72 95 51 55 78 70 11 92 17 5 54 94 81 31 78 95 73 91 95 37 59 9 53 48 65 55 84 8 45 97 64 37 96 34 36 53 66 17 72 48 99 23 27 18 92 84 44 73 60 78 53 29 68 99 19 39 61 40 69 6 77 12 47 29 15 4 8 45",
"output": "53"
},
{
"input": "100\n82 40 31 53 8 50 85 93 3 84 54 17 96 59 51 42 18 19 35 84 79 31 17 46 54 82 72 49 35 73 26 89 61 73 3 50 12 29 25 77 88 21 58 24 22 89 96 54 82 29 96 56 77 16 1 68 90 93 20 23 57 22 31 18 92 90 51 14 50 72 31 54 12 50 66 62 2 34 17 45 68 50 87 97 23 71 1 72 17 82 42 15 20 78 4 49 66 59 10 17",
"output": "54"
},
{
"input": "100\n32 82 82 24 39 53 48 5 29 24 9 37 91 37 91 95 1 97 84 52 12 56 93 47 22 20 14 17 40 22 79 34 24 2 69 30 69 29 3 89 21 46 60 92 39 29 18 24 49 18 40 22 60 13 77 50 39 64 50 70 99 8 66 31 90 38 20 54 7 21 5 56 41 68 69 20 54 89 69 62 9 53 43 89 81 97 15 2 52 78 89 65 16 61 59 42 56 25 32 52",
"output": "49"
},
{
"input": "100\n72 54 23 24 97 14 99 87 15 25 7 23 17 87 72 31 71 87 34 82 51 77 74 85 62 38 24 7 84 48 98 21 29 71 70 84 25 58 67 92 18 44 32 9 81 15 53 29 63 18 86 16 7 31 38 99 70 32 89 16 23 11 66 96 69 82 97 59 6 9 49 80 85 19 6 9 52 51 85 74 53 46 73 55 31 63 78 61 34 80 77 65 87 77 92 52 89 8 52 31",
"output": "44"
},
{
"input": "100\n56 88 8 19 7 15 11 54 35 50 19 57 63 72 51 43 50 19 57 90 40 100 8 92 11 96 30 32 59 65 93 47 62 3 50 41 30 50 72 83 61 46 83 60 20 46 33 1 5 18 83 22 34 16 41 95 63 63 7 59 55 95 91 29 64 60 64 81 45 45 10 9 88 37 69 85 21 82 41 76 42 34 47 78 51 83 65 100 13 22 59 76 63 1 26 86 36 94 99 74",
"output": "46"
},
{
"input": "100\n27 89 67 60 62 80 43 50 28 88 72 5 94 11 63 91 18 78 99 3 71 26 12 97 74 62 23 24 22 3 100 72 98 7 94 32 12 75 61 88 42 48 10 14 45 9 48 56 73 76 70 70 79 90 35 39 96 37 81 11 19 65 99 39 23 79 34 61 35 74 90 37 73 23 46 21 94 84 73 58 11 89 13 9 10 85 42 78 73 32 53 39 49 90 43 5 28 31 97 75",
"output": "53"
},
{
"input": "100\n33 24 97 96 1 14 99 51 13 65 67 20 46 88 42 44 20 49 5 89 98 83 15 40 74 83 58 3 10 79 34 2 69 28 37 100 55 52 14 8 44 94 97 89 6 42 11 28 30 33 55 56 20 57 52 25 75 1 87 42 62 41 37 12 54 85 95 80 42 36 94 96 28 76 54 36 4 17 26 24 62 15 17 79 84 36 92 78 74 91 96 77 54 92 81 91 62 98 37 37",
"output": "43"
},
{
"input": "100\n86 24 61 15 11 85 1 31 47 36 23 36 59 34 3 27 16 29 82 28 58 52 52 66 71 61 98 39 60 20 67 41 67 90 73 29 92 17 70 95 58 98 58 32 21 73 46 56 87 72 80 75 40 27 94 31 59 92 93 37 14 99 96 21 97 23 81 91 52 52 96 94 92 28 38 29 52 16 57 27 17 24 91 21 79 55 96 98 95 94 23 78 79 12 77 35 32 75 100 82",
"output": "51"
},
{
"input": "100\n88 85 41 37 69 21 7 69 36 5 92 26 64 75 22 46 67 20 70 22 62 66 38 24 47 49 68 30 90 31 67 86 86 82 9 51 43 45 48 42 73 44 31 94 45 60 54 66 20 87 11 94 34 32 87 66 56 28 75 39 37 90 72 93 55 72 31 42 30 71 87 61 4 12 12 81 23 61 56 98 71 32 30 33 96 63 92 16 8 78 47 91 47 54 49 3 81 82 41 5",
"output": "47"
},
{
"input": "1\n2",
"output": "1"
},
{
"input": "5\n1 1 3 2 2",
"output": "3"
}
] | 1,638,820,906 | 2,147,483,647 | Python 3 | OK | TESTS | 52 | 122 | 0 | n=int(input())
l=list(map(int,input().split()))
Sum=sum(l)
if(Sum%2==0):
print(len([i for i in l if i%2==0]))
else:
print(len([i for i in l if(i%2==1)]))
| Title: Cookies
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Olga came to visit the twins Anna and Maria and saw that they have many cookies. The cookies are distributed into bags. As there are many cookies, Olga decided that it's no big deal if she steals a bag. However, she doesn't want the sisters to quarrel because of nothing when they divide the cookies. That's why Olga wants to steal a bag with cookies so that the number of cookies in the remaining bags was even, that is, so that Anna and Maria could evenly divide it into two (even 0 remaining cookies will do, just as any other even number). How many ways there are to steal exactly one cookie bag so that the total number of cookies in the remaining bags was even?
Input Specification:
The first line contains the only integer *n* (1<=≤<=*n*<=≤<=100) — the number of cookie bags Anna and Maria have. The second line contains *n* integers *a**i* (1<=≤<=*a**i*<=≤<=100) — the number of cookies in the *i*-th bag.
Output Specification:
Print in the only line the only number — the sought number of ways. If there are no such ways print 0.
Demo Input:
['1\n1\n', '10\n1 2 2 3 4 4 4 2 2 2\n', '11\n2 2 2 2 2 2 2 2 2 2 99\n']
Demo Output:
['1\n', '8\n', '1\n']
Note:
In the first sample Olga should take the only bag so that the twins ended up with the even number of cookies.
In the second sample Olga can take any of five bags with two cookies or any of three bags with four cookies — 5 + 3 = 8 ways in total.
In the third sample, no matter which bag with two cookies Olga chooses, the twins are left with 2 * 9 + 99 = 117 cookies. Thus, Olga has only one option: to take the bag with 99 cookies. | ```python
n=int(input())
l=list(map(int,input().split()))
Sum=sum(l)
if(Sum%2==0):
print(len([i for i in l if i%2==0]))
else:
print(len([i for i in l if(i%2==1)]))
``` | 3 |
|
0 | none | none | none | 0 | [
"none"
] | null | null | Asterix, Obelix and their temporary buddies Suffix and Prefix has finally found the Harmony temple. However, its doors were firmly locked and even Obelix had no luck opening them.
A little later they found a string *s*, carved on a rock below the temple's gates. Asterix supposed that that's the password that opens the temple and read the string aloud. However, nothing happened. Then Asterix supposed that a password is some substring *t* of the string *s*.
Prefix supposed that the substring *t* is the beginning of the string *s*; Suffix supposed that the substring *t* should be the end of the string *s*; and Obelix supposed that *t* should be located somewhere inside the string *s*, that is, *t* is neither its beginning, nor its end.
Asterix chose the substring *t* so as to please all his companions. Besides, from all acceptable variants Asterix chose the longest one (as Asterix loves long strings). When Asterix read the substring *t* aloud, the temple doors opened.
You know the string *s*. Find the substring *t* or determine that such substring does not exist and all that's been written above is just a nice legend. | You are given the string *s* whose length can vary from 1 to 106 (inclusive), consisting of small Latin letters. | Print the string *t*. If a suitable *t* string does not exist, then print "Just a legend" without the quotes. | [
"fixprefixsuffix\n",
"abcdabc\n"
] | [
"fix",
"Just a legend"
] | none | 0 | [
{
"input": "fixprefixsuffix",
"output": "fix"
},
{
"input": "abcdabc",
"output": "Just a legend"
},
{
"input": "qwertyqwertyqwerty",
"output": "qwerty"
},
{
"input": "papapapap",
"output": "papap"
},
{
"input": "aaaaaaaaaa",
"output": "aaaaaaaa"
},
{
"input": "ghbdtn",
"output": "Just a legend"
},
{
"input": "a",
"output": "Just a legend"
},
{
"input": "aa",
"output": "Just a legend"
},
{
"input": "ab",
"output": "Just a legend"
},
{
"input": "aaa",
"output": "a"
},
{
"input": "aba",
"output": "Just a legend"
},
{
"input": "aab",
"output": "Just a legend"
},
{
"input": "abb",
"output": "Just a legend"
},
{
"input": "abc",
"output": "Just a legend"
},
{
"input": "aaabaabaaaaab",
"output": "Just a legend"
},
{
"input": "aabaaabaaaaab",
"output": "aab"
},
{
"input": "aaabaaaabab",
"output": "Just a legend"
},
{
"input": "abcabcabcabcabc",
"output": "abcabcabc"
},
{
"input": "aaaaabaaaa",
"output": "aaaa"
},
{
"input": "aaaabaaaaaaa",
"output": "aaaa"
},
{
"input": "ghghghgxghghghg",
"output": "ghghg"
},
{
"input": "kincenvizh",
"output": "Just a legend"
},
{
"input": "amcksgurlgqzqizdauqminfzshiweejkevbazyzylrrghumnvqeqqdedyopgtvxakqwpvxntxgrkrcxabhrgoxngrwrxrvcguuyw",
"output": "Just a legend"
},
{
"input": "kwuaizneqxfflhmyruotjlkqksinoanvkyvqptkkntnpjdyzicceelgooajdgpkneuhyvhdtmasiglplajxolxovlhkwuaizneqx",
"output": "Just a legend"
},
{
"input": "nfbdzgdlbjhrlvfryyjbvtsmzacxglcvukmyexdgpuiwvqbnfbdzgdlbjhrlvfryyjbtuomcwbwvlhefnfbdzgdlbjhrlvfryyjb",
"output": "nfbdzgdlbjhrlvfryyjb"
},
{
"input": "btbdpnzdenxueteteytvkwnegodyhmdwhmrmbftrifytzudumzlacwytsuzefqfpjesdblxhpcsidgksisjdmhyxmmugrjmtfcgxmcgpmvbxbyszdugvmoyjeeqsywcvuqskcjotyhvdijyslgfvyujxthngnonasgnbzzygyikheelirdfsvuicbiazfdeqecbtbdpnzdenxueteteytvkwnegodyhmdwhmrmbftrifytzudumzlacwytsuzefqfpjesdblxhpcsidgksisjdmhyxmmugrjmtfcgxmcgpccdtdteohtjjuicfjfcbzpynlqhecyqqrjpmexgfqywnfmusldgzvgnzdmuuujtkdfnlytzgstquwqpuccxbtbdpnzdenxueteteytvkwnegodyhmdwhmrmbftrifytzudumzlacwytsuzefqfpjesdblxhpcsidgksisjdmhyxmmugrjmtfcgxmcgp",
"output": "btbdpnzdenxueteteytvkwnegodyhmdwhmrmbftrifytzudumzlacwytsuzefqfpjesdblxhpcsidgksisjdmhyxmmugrjmtfcgxmcgp"
},
{
"input": "abcazabca",
"output": "a"
}
] | 1,465,217,867 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 3 | 124 | 4,608,000 | s=input()
ins=s[1:-1]
ans="Just a legend"
for i in range(len(s)):
if s[:i]==s[-i:] and ins.find(s[:i])!=-1:
ans=s[:i]
break
print(ans)
| Title: none
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Asterix, Obelix and their temporary buddies Suffix and Prefix has finally found the Harmony temple. However, its doors were firmly locked and even Obelix had no luck opening them.
A little later they found a string *s*, carved on a rock below the temple's gates. Asterix supposed that that's the password that opens the temple and read the string aloud. However, nothing happened. Then Asterix supposed that a password is some substring *t* of the string *s*.
Prefix supposed that the substring *t* is the beginning of the string *s*; Suffix supposed that the substring *t* should be the end of the string *s*; and Obelix supposed that *t* should be located somewhere inside the string *s*, that is, *t* is neither its beginning, nor its end.
Asterix chose the substring *t* so as to please all his companions. Besides, from all acceptable variants Asterix chose the longest one (as Asterix loves long strings). When Asterix read the substring *t* aloud, the temple doors opened.
You know the string *s*. Find the substring *t* or determine that such substring does not exist and all that's been written above is just a nice legend.
Input Specification:
You are given the string *s* whose length can vary from 1 to 106 (inclusive), consisting of small Latin letters.
Output Specification:
Print the string *t*. If a suitable *t* string does not exist, then print "Just a legend" without the quotes.
Demo Input:
['fixprefixsuffix\n', 'abcdabc\n']
Demo Output:
['fix', 'Just a legend']
Note:
none | ```python
s=input()
ins=s[1:-1]
ans="Just a legend"
for i in range(len(s)):
if s[:i]==s[-i:] and ins.find(s[:i])!=-1:
ans=s[:i]
break
print(ans)
``` | 0 |
|
771 | A | Bear and Friendship Condition | PROGRAMMING | 1,500 | [
"dfs and similar",
"dsu",
"graphs"
] | null | null | Bear Limak examines a social network. Its main functionality is that two members can become friends (then they can talk with each other and share funny pictures).
There are *n* members, numbered 1 through *n*. *m* pairs of members are friends. Of course, a member can't be a friend with themselves.
Let A-B denote that members A and B are friends. Limak thinks that a network is reasonable if and only if the following condition is satisfied: For every three distinct members (X, Y, Z), if X-Y and Y-Z then also X-Z.
For example: if Alan and Bob are friends, and Bob and Ciri are friends, then Alan and Ciri should be friends as well.
Can you help Limak and check if the network is reasonable? Print "YES" or "NO" accordingly, without the quotes. | The first line of the input contain two integers *n* and *m* (3<=≤<=*n*<=≤<=150<=000, ) — the number of members and the number of pairs of members that are friends.
The *i*-th of the next *m* lines contains two distinct integers *a**i* and *b**i* (1<=≤<=*a**i*,<=*b**i*<=≤<=*n*,<=*a**i*<=≠<=*b**i*). Members *a**i* and *b**i* are friends with each other. No pair of members will appear more than once in the input. | If the given network is reasonable, print "YES" in a single line (without the quotes). Otherwise, print "NO" in a single line (without the quotes). | [
"4 3\n1 3\n3 4\n1 4\n",
"4 4\n3 1\n2 3\n3 4\n1 2\n",
"10 4\n4 3\n5 10\n8 9\n1 2\n",
"3 2\n1 2\n2 3\n"
] | [
"YES\n",
"NO\n",
"YES\n",
"NO\n"
] | The drawings below show the situation in the first sample (on the left) and in the second sample (on the right). Each edge represents two members that are friends. The answer is "NO" in the second sample because members (2, 3) are friends and members (3, 4) are friends, while members (2, 4) are not. | 250 | [
{
"input": "4 3\n1 3\n3 4\n1 4",
"output": "YES"
},
{
"input": "4 4\n3 1\n2 3\n3 4\n1 2",
"output": "NO"
},
{
"input": "10 4\n4 3\n5 10\n8 9\n1 2",
"output": "YES"
},
{
"input": "3 2\n1 2\n2 3",
"output": "NO"
},
{
"input": "3 0",
"output": "YES"
},
{
"input": "15 42\n8 1\n3 14\n7 14\n12 3\n7 9\n6 7\n6 12\n14 12\n3 10\n10 14\n6 3\n3 13\n13 10\n7 12\n7 2\n6 10\n11 4\n9 3\n8 4\n7 3\n2 3\n2 10\n9 13\n2 14\n6 14\n13 2\n1 4\n13 6\n7 10\n13 14\n12 10\n13 7\n12 2\n9 10\n13 12\n2 6\n9 14\n6 9\n12 9\n11 1\n2 9\n11 8",
"output": "YES"
},
{
"input": "20 80\n17 4\n10 1\n11 10\n17 7\n15 10\n14 15\n13 1\n18 13\n3 13\n12 7\n9 13\n10 12\n14 12\n18 11\n4 7\n10 13\n11 3\n19 8\n14 7\n10 17\n14 3\n7 11\n11 14\n19 5\n10 14\n15 17\n3 1\n9 10\n11 1\n4 1\n11 4\n9 1\n12 3\n13 7\n1 14\n11 12\n7 1\n9 12\n18 15\n17 3\n7 15\n4 10\n7 18\n7 9\n12 17\n14 18\n3 18\n18 17\n9 15\n14 4\n14 9\n9 18\n12 4\n7 10\n15 4\n4 18\n15 13\n1 12\n7 3\n13 11\n4 13\n5 8\n12 18\n12 15\n17 9\n11 15\n3 10\n18 10\n4 3\n15 3\n13 12\n9 4\n9 11\n14 17\n13 17\n3 9\n13 14\n1 17\n15 1\n17 11",
"output": "NO"
},
{
"input": "99 26\n64 17\n48 70\n71 50\n3 50\n9 60\n61 64\n53 50\n25 12\n3 71\n71 53\n3 53\n65 70\n9 25\n9 12\n59 56\n39 60\n64 69\n65 94\n70 94\n25 60\n60 12\n94 48\n17 69\n61 17\n65 48\n61 69",
"output": "NO"
},
{
"input": "3 1\n1 2",
"output": "YES"
},
{
"input": "3 2\n3 2\n1 3",
"output": "NO"
},
{
"input": "3 3\n2 3\n1 2\n1 3",
"output": "YES"
},
{
"input": "4 2\n4 1\n2 1",
"output": "NO"
},
{
"input": "4 3\n3 1\n2 1\n3 2",
"output": "YES"
},
{
"input": "5 9\n1 2\n5 1\n3 1\n1 4\n2 4\n5 3\n5 4\n2 3\n5 2",
"output": "NO"
},
{
"input": "10 5\n9 5\n1 2\n6 8\n6 3\n10 6",
"output": "NO"
},
{
"input": "10 8\n10 7\n9 7\n5 7\n6 8\n3 5\n8 10\n3 4\n7 8",
"output": "NO"
},
{
"input": "10 20\n8 2\n8 3\n1 8\n9 5\n2 4\n10 1\n10 5\n7 5\n7 8\n10 7\n6 5\n3 7\n1 9\n9 8\n7 2\n2 10\n2 1\n6 4\n9 7\n4 3",
"output": "NO"
},
{
"input": "150000 10\n62562 50190\n48849 60549\n139470 18456\n21436 25159\n66845 120884\n99972 114453\n11631 99153\n62951 134848\n78114 146050\n136760 131762",
"output": "YES"
},
{
"input": "150000 0",
"output": "YES"
},
{
"input": "4 4\n1 2\n2 3\n3 4\n1 4",
"output": "NO"
},
{
"input": "30 73\n25 2\n2 16\n20 12\n16 20\n7 18\n11 15\n13 11\n30 29\n16 12\n12 25\n2 1\n18 14\n9 8\n28 16\n2 9\n22 21\n1 25\n12 28\n14 7\n4 9\n26 7\n14 27\n12 2\n29 22\n1 9\n13 15\n3 10\n1 12\n8 20\n30 24\n25 20\n4 1\n4 12\n20 1\n8 4\n2 28\n25 16\n16 8\n20 4\n9 12\n21 30\n23 11\n19 6\n28 4\n29 21\n9 28\n30 10\n22 24\n25 8\n27 26\n25 4\n28 20\n9 25\n24 29\n20 9\n18 26\n1 28\n30 22\n23 15\n28 27\n8 2\n23 13\n12 8\n14 26\n16 4\n28 25\n8 1\n4 2\n9 16\n20 2\n18 27\n28 8\n27 7",
"output": "NO"
},
{
"input": "5 4\n1 2\n2 5\n3 4\n4 5",
"output": "NO"
},
{
"input": "4 4\n1 2\n2 3\n3 4\n4 1",
"output": "NO"
},
{
"input": "6 6\n1 2\n2 4\n4 3\n1 5\n5 6\n6 3",
"output": "NO"
},
{
"input": "3 2\n1 2\n1 3",
"output": "NO"
},
{
"input": "6 6\n1 2\n2 3\n3 4\n4 5\n5 6\n1 6",
"output": "NO"
},
{
"input": "4 4\n1 2\n1 3\n2 4\n3 4",
"output": "NO"
},
{
"input": "6 9\n1 4\n1 5\n1 6\n2 4\n2 5\n2 6\n3 4\n3 5\n3 6",
"output": "NO"
},
{
"input": "4 3\n1 2\n1 3\n3 4",
"output": "NO"
},
{
"input": "4 3\n1 2\n1 3\n2 4",
"output": "NO"
},
{
"input": "6 6\n1 2\n2 3\n3 4\n4 5\n5 6\n6 1",
"output": "NO"
},
{
"input": "4 3\n1 2\n1 3\n1 4",
"output": "NO"
},
{
"input": "150000 3\n150000 149999\n149998 149999\n149998 150000",
"output": "YES"
},
{
"input": "10 15\n1 2\n1 3\n2 4\n2 5\n3 4\n3 5\n4 5\n1 6\n6 7\n6 8\n7 9\n7 10\n8 9\n8 10\n9 10",
"output": "NO"
},
{
"input": "5 5\n1 2\n2 3\n3 4\n4 5\n5 1",
"output": "NO"
},
{
"input": "5 4\n1 2\n1 3\n1 4\n1 5",
"output": "NO"
},
{
"input": "9 9\n1 2\n2 3\n3 4\n4 5\n5 6\n6 7\n7 8\n8 9\n9 1",
"output": "NO"
},
{
"input": "4 5\n1 2\n1 3\n1 4\n2 3\n3 4",
"output": "NO"
},
{
"input": "4 4\n1 2\n1 3\n4 2\n4 3",
"output": "NO"
},
{
"input": "5 5\n1 4\n5 3\n5 1\n2 3\n4 5",
"output": "NO"
},
{
"input": "4 5\n1 2\n1 3\n2 3\n1 4\n2 4",
"output": "NO"
},
{
"input": "4 5\n1 2\n1 3\n1 4\n2 3\n2 4",
"output": "NO"
},
{
"input": "6 12\n1 2\n1 4\n1 5\n1 6\n2 3\n2 5\n2 6\n3 4\n3 5\n3 6\n4 5\n4 6",
"output": "NO"
},
{
"input": "1000 4\n100 132\n100 164\n196 132\n196 164",
"output": "NO"
}
] | 1,694,517,068 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 6 | 46 | 0 | mod = int(1e9+7)
def solve():
n,m = map(int,input().split())
adj = [[]for i in range(n)]
for i in range(m):
a,b = map(int,input().split())
adj[a-1].append(b-1)
adj[b-1].append(a-1)
def dfs(s,par,gpar):
visited[s] = True
strue = False
atrue = True
for i in adj[s]:
if not visited[i]:
atrue&=dfs(i,s,par)
if i==gpar:
strue = True
if atrue and (strue or par==-1 or gpar==-1):
return True
return False
visited = [False]*n
ttrue = True
for i in range(n):
if not visited[i]:
ttrue&=dfs(i,-1,-1)
if ttrue:
print("YES")
else:
print("NO")
# number of test cases
#t = int(input())
t = 1
for i in range(t):
solve()
| Title: Bear and Friendship Condition
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Bear Limak examines a social network. Its main functionality is that two members can become friends (then they can talk with each other and share funny pictures).
There are *n* members, numbered 1 through *n*. *m* pairs of members are friends. Of course, a member can't be a friend with themselves.
Let A-B denote that members A and B are friends. Limak thinks that a network is reasonable if and only if the following condition is satisfied: For every three distinct members (X, Y, Z), if X-Y and Y-Z then also X-Z.
For example: if Alan and Bob are friends, and Bob and Ciri are friends, then Alan and Ciri should be friends as well.
Can you help Limak and check if the network is reasonable? Print "YES" or "NO" accordingly, without the quotes.
Input Specification:
The first line of the input contain two integers *n* and *m* (3<=≤<=*n*<=≤<=150<=000, ) — the number of members and the number of pairs of members that are friends.
The *i*-th of the next *m* lines contains two distinct integers *a**i* and *b**i* (1<=≤<=*a**i*,<=*b**i*<=≤<=*n*,<=*a**i*<=≠<=*b**i*). Members *a**i* and *b**i* are friends with each other. No pair of members will appear more than once in the input.
Output Specification:
If the given network is reasonable, print "YES" in a single line (without the quotes). Otherwise, print "NO" in a single line (without the quotes).
Demo Input:
['4 3\n1 3\n3 4\n1 4\n', '4 4\n3 1\n2 3\n3 4\n1 2\n', '10 4\n4 3\n5 10\n8 9\n1 2\n', '3 2\n1 2\n2 3\n']
Demo Output:
['YES\n', 'NO\n', 'YES\n', 'NO\n']
Note:
The drawings below show the situation in the first sample (on the left) and in the second sample (on the right). Each edge represents two members that are friends. The answer is "NO" in the second sample because members (2, 3) are friends and members (3, 4) are friends, while members (2, 4) are not. | ```python
mod = int(1e9+7)
def solve():
n,m = map(int,input().split())
adj = [[]for i in range(n)]
for i in range(m):
a,b = map(int,input().split())
adj[a-1].append(b-1)
adj[b-1].append(a-1)
def dfs(s,par,gpar):
visited[s] = True
strue = False
atrue = True
for i in adj[s]:
if not visited[i]:
atrue&=dfs(i,s,par)
if i==gpar:
strue = True
if atrue and (strue or par==-1 or gpar==-1):
return True
return False
visited = [False]*n
ttrue = True
for i in range(n):
if not visited[i]:
ttrue&=dfs(i,-1,-1)
if ttrue:
print("YES")
else:
print("NO")
# number of test cases
#t = int(input())
t = 1
for i in range(t):
solve()
``` | 0 |
|
260 | B | Ancient Prophesy | PROGRAMMING | 1,600 | [
"brute force",
"implementation",
"strings"
] | null | null | A recently found Ancient Prophesy is believed to contain the exact Apocalypse date. The prophesy is a string that only consists of digits and characters "-".
We'll say that some date is mentioned in the Prophesy if there is a substring in the Prophesy that is the date's record in the format "dd-mm-yyyy". We'll say that the number of the date's occurrences is the number of such substrings in the Prophesy. For example, the Prophesy "0012-10-2012-10-2012" mentions date 12-10-2012 twice (first time as "0012-10-2012-10-2012", second time as "0012-10-2012-10-2012").
The date of the Apocalypse is such correct date that the number of times it is mentioned in the Prophesy is strictly larger than that of any other correct date.
A date is correct if the year lies in the range from 2013 to 2015, the month is from 1 to 12, and the number of the day is strictly more than a zero and doesn't exceed the number of days in the current month. Note that a date is written in the format "dd-mm-yyyy", that means that leading zeroes may be added to the numbers of the months or days if needed. In other words, date "1-1-2013" isn't recorded in the format "dd-mm-yyyy", and date "01-01-2013" is recorded in it.
Notice, that any year between 2013 and 2015 is not a leap year. | The first line contains the Prophesy: a non-empty string that only consists of digits and characters "-". The length of the Prophesy doesn't exceed 105 characters. | In a single line print the date of the Apocalypse. It is guaranteed that such date exists and is unique. | [
"777-444---21-12-2013-12-2013-12-2013---444-777\n"
] | [
"13-12-2013"
] | none | 1,000 | [
{
"input": "777-444---21-12-2013-12-2013-12-2013---444-777",
"output": "13-12-2013"
},
{
"input": "30-12-201429-15-208830-12-2014",
"output": "30-12-2014"
},
{
"input": "14-08-201314-08-201314-08-201381-16-20172406414-08-201314-08-201314-08-20134237014-08-201314-08-2013",
"output": "14-08-2013"
},
{
"input": "15-11-201413-02-20147-86-25-298813-02-201413-02-201434615-11-201415-11-201415-11-201415-11-2014",
"output": "15-11-2014"
},
{
"input": "19-07-201419-07-201424-06-201719-07-201419-07-201413-10-201419-07-201468-01-201619-07-20142",
"output": "19-07-2014"
},
{
"input": "01-04-201425-08-201386-04-201525-10-2014878-04-20102-06-201501-04-2014-08-20159533-45-00-1212",
"output": "01-04-2014"
},
{
"input": "23-11-201413-07-201412-06-2015124-03-20140-19-201323-11-201424-03-2014537523-11-20143575015-10-2014",
"output": "23-11-2014"
},
{
"input": "15-04-201413-08-201589-09-201013-08-20130-74-28-201620-8497-14-1063713-08-2013813-02-201513-08-2013",
"output": "13-08-2013"
},
{
"input": "13-05-201412-11-2013-12-11-201314-12-201329-05-201306-24-188814-07-201312-11-201312-04-2010",
"output": "12-11-2013"
},
{
"input": "14-01-201402-04-201514-01-201485-26-1443948-14-278314-01-2014615259-09-178413-06-201314-05-2014",
"output": "14-01-2014"
},
{
"input": "31-12-201331-11-201331-11-2013",
"output": "31-12-2013"
},
{
"input": "01-01-2014",
"output": "01-01-2014"
},
{
"input": "32-13-2100-32-13-2100-32-13-2100-12-12-2013",
"output": "12-12-2013"
},
{
"input": "15-1--201315-1--201301-01-2013",
"output": "01-01-2013"
},
{
"input": "00-12-2014-00-12-2014-00-12-2014-12-12-2014",
"output": "12-12-2014"
},
{
"input": "120110201311-10-20151201102013",
"output": "11-10-2015"
},
{
"input": "31-08-2013---31-08-2013---03-03-2013",
"output": "31-08-2013"
},
{
"input": "12-12-201312-12-201312-12-201313--12-201313--12-201313--12-201313--12-201313--12-201313--12-201313--12-201313--12-2013",
"output": "12-12-2013"
},
{
"input": "21-12-201221-12-201221-12-201221-12-201213-12-2013",
"output": "13-12-2013"
},
{
"input": "29-02-2013-02-2013-29-02-2013",
"output": "13-02-2013"
},
{
"input": "20-12-2012----20-12-2012-----01-01-2013",
"output": "01-01-2013"
},
{
"input": "01-2-02013---01-2-02013----13-02-2014",
"output": "13-02-2014"
},
{
"input": "11111111111111111111---21-12-2013",
"output": "21-12-2013"
},
{
"input": "29-02-2014--29-02-2014--28-02-2014",
"output": "28-02-2014"
},
{
"input": "29-02-201329-02-201321-12-2013",
"output": "21-12-2013"
},
{
"input": "01--01--2013-12-2013-01--01--2013",
"output": "13-12-2013"
},
{
"input": "10-10-2023-10-10-2023-10-10-2013",
"output": "10-10-2013"
}
] | 1,535,796,221 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 24 | 546 | 1,536,000 | import re
s = input()
a = []
days = [0,31,28,31,30,31,30,30,31,30,31,30,31];
regex = r'(0[1-9])?(1[0-9])?(2[0-9])?(3[0-1])?-(0[1-9])?(1[0-2])?[-]201[3-5]'
for i in range(0,len(s)-9):
if(s[i]!='-' and s[i+9]!='-'):
if(re.search(regex,s[i:i+10])!=None):
a.append(s[i:i+10])
st = set(a)
b = [[a.count(i),i] for i in st]
b.sort(reverse=True)
for i in range (0,len(b)):
d = int(b[i][1][:2])
mont = int(b[i][1][3:5])
if(d>0 and d<=days[mont]):
print(b[i][1])
break | Title: Ancient Prophesy
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A recently found Ancient Prophesy is believed to contain the exact Apocalypse date. The prophesy is a string that only consists of digits and characters "-".
We'll say that some date is mentioned in the Prophesy if there is a substring in the Prophesy that is the date's record in the format "dd-mm-yyyy". We'll say that the number of the date's occurrences is the number of such substrings in the Prophesy. For example, the Prophesy "0012-10-2012-10-2012" mentions date 12-10-2012 twice (first time as "0012-10-2012-10-2012", second time as "0012-10-2012-10-2012").
The date of the Apocalypse is such correct date that the number of times it is mentioned in the Prophesy is strictly larger than that of any other correct date.
A date is correct if the year lies in the range from 2013 to 2015, the month is from 1 to 12, and the number of the day is strictly more than a zero and doesn't exceed the number of days in the current month. Note that a date is written in the format "dd-mm-yyyy", that means that leading zeroes may be added to the numbers of the months or days if needed. In other words, date "1-1-2013" isn't recorded in the format "dd-mm-yyyy", and date "01-01-2013" is recorded in it.
Notice, that any year between 2013 and 2015 is not a leap year.
Input Specification:
The first line contains the Prophesy: a non-empty string that only consists of digits and characters "-". The length of the Prophesy doesn't exceed 105 characters.
Output Specification:
In a single line print the date of the Apocalypse. It is guaranteed that such date exists and is unique.
Demo Input:
['777-444---21-12-2013-12-2013-12-2013---444-777\n']
Demo Output:
['13-12-2013']
Note:
none | ```python
import re
s = input()
a = []
days = [0,31,28,31,30,31,30,30,31,30,31,30,31];
regex = r'(0[1-9])?(1[0-9])?(2[0-9])?(3[0-1])?-(0[1-9])?(1[0-2])?[-]201[3-5]'
for i in range(0,len(s)-9):
if(s[i]!='-' and s[i+9]!='-'):
if(re.search(regex,s[i:i+10])!=None):
a.append(s[i:i+10])
st = set(a)
b = [[a.count(i),i] for i in st]
b.sort(reverse=True)
for i in range (0,len(b)):
d = int(b[i][1][:2])
mont = int(b[i][1][3:5])
if(d>0 and d<=days[mont]):
print(b[i][1])
break
``` | -1 |
|
656 | A | Da Vinci Powers | PROGRAMMING | 1,900 | [
"*special"
] | null | null | The input contains a single integer *a* (0<=≤<=*a*<=≤<=35).
Output a single integer. | The input contains a single integer *a* (0<=≤<=*a*<=≤<=35). | Output a single integer. | [
"3\n",
"10\n"
] | [
"8\n",
"1024\n"
] | none | 0 | [
{
"input": "3",
"output": "8"
},
{
"input": "10",
"output": "1024"
},
{
"input": "35",
"output": "33940307968"
},
{
"input": "0",
"output": "1"
},
{
"input": "1",
"output": "2"
},
{
"input": "2",
"output": "4"
},
{
"input": "4",
"output": "16"
},
{
"input": "5",
"output": "32"
},
{
"input": "6",
"output": "64"
},
{
"input": "7",
"output": "128"
},
{
"input": "8",
"output": "256"
},
{
"input": "9",
"output": "512"
},
{
"input": "11",
"output": "2048"
},
{
"input": "12",
"output": "4096"
},
{
"input": "13",
"output": "8092"
},
{
"input": "14",
"output": "16184"
},
{
"input": "15",
"output": "32368"
},
{
"input": "16",
"output": "64736"
},
{
"input": "17",
"output": "129472"
},
{
"input": "18",
"output": "258944"
},
{
"input": "19",
"output": "517888"
},
{
"input": "20",
"output": "1035776"
},
{
"input": "21",
"output": "2071552"
},
{
"input": "22",
"output": "4143104"
},
{
"input": "23",
"output": "8286208"
},
{
"input": "24",
"output": "16572416"
},
{
"input": "25",
"output": "33144832"
},
{
"input": "26",
"output": "66289664"
},
{
"input": "27",
"output": "132579328"
},
{
"input": "28",
"output": "265158656"
},
{
"input": "29",
"output": "530317312"
},
{
"input": "30",
"output": "1060634624"
},
{
"input": "31",
"output": "2121269248"
},
{
"input": "32",
"output": "4242538496"
},
{
"input": "33",
"output": "8485076992"
},
{
"input": "34",
"output": "16970153984"
}
] | 1,496,787,250 | 2,147,483,647 | Python 3 | OK | TESTS | 36 | 62 | 0 | if __name__ == "__main__":
a = [1,
2,
4,
8,
16,
32,
64,
128,
256,
512,
1024,
2048,
4096,
8092,
16184,
32368,
64736,
129472,
258944,
517888,
1035776,
2071552,
4143104,
8286208,
16572416,
33144832,
66289664,
132579328,
265158656,
530317312,
1060634624,
2121269248,
4242538496,
8485076992,
16970153984,
33940307968]
print (a[int(input())])
| Title: Da Vinci Powers
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The input contains a single integer *a* (0<=≤<=*a*<=≤<=35).
Output a single integer.
Input Specification:
The input contains a single integer *a* (0<=≤<=*a*<=≤<=35).
Output Specification:
Output a single integer.
Demo Input:
['3\n', '10\n']
Demo Output:
['8\n', '1024\n']
Note:
none | ```python
if __name__ == "__main__":
a = [1,
2,
4,
8,
16,
32,
64,
128,
256,
512,
1024,
2048,
4096,
8092,
16184,
32368,
64736,
129472,
258944,
517888,
1035776,
2071552,
4143104,
8286208,
16572416,
33144832,
66289664,
132579328,
265158656,
530317312,
1060634624,
2121269248,
4242538496,
8485076992,
16970153984,
33940307968]
print (a[int(input())])
``` | 3 |
|
757 | A | Gotta Catch Em' All! | PROGRAMMING | 1,000 | [
"implementation"
] | null | null | Bash wants to become a Pokemon master one day. Although he liked a lot of Pokemon, he has always been fascinated by Bulbasaur the most. Soon, things started getting serious and his fascination turned into an obsession. Since he is too young to go out and catch Bulbasaur, he came up with his own way of catching a Bulbasaur.
Each day, he takes the front page of the newspaper. He cuts out the letters one at a time, from anywhere on the front page of the newspaper to form the word "Bulbasaur" (without quotes) and sticks it on his wall. Bash is very particular about case — the first letter of "Bulbasaur" must be upper case and the rest must be lower case. By doing this he thinks he has caught one Bulbasaur. He then repeats this step on the left over part of the newspaper. He keeps doing this until it is not possible to form the word "Bulbasaur" from the newspaper.
Given the text on the front page of the newspaper, can you tell how many Bulbasaurs he will catch today?
Note: uppercase and lowercase letters are considered different. | Input contains a single line containing a string *s* (1<=<=≤<=<=|*s*|<=<=≤<=<=105) — the text on the front page of the newspaper without spaces and punctuation marks. |*s*| is the length of the string *s*.
The string *s* contains lowercase and uppercase English letters, i.e. . | Output a single integer, the answer to the problem. | [
"Bulbbasaur\n",
"F\n",
"aBddulbasaurrgndgbualdBdsagaurrgndbb\n"
] | [
"1\n",
"0\n",
"2\n"
] | In the first case, you could pick: Bulbbasaur.
In the second case, there is no way to pick even a single Bulbasaur.
In the third case, you can rearrange the string to BulbasaurBulbasauraddrgndgddgargndbb to get two words "Bulbasaur". | 500 | [
{
"input": "Bulbbasaur",
"output": "1"
},
{
"input": "F",
"output": "0"
},
{
"input": "aBddulbasaurrgndgbualdBdsagaurrgndbb",
"output": "2"
},
{
"input": "BBBBBBBBBBbbbbbbbbbbuuuuuuuuuullllllllllssssssssssaaaaaaaaaarrrrrrrrrr",
"output": "5"
},
{
"input": "BBBBBBBBBBbbbbbbbbbbbbbbbbbbbbuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuussssssssssssssssssssaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
"output": "0"
},
{
"input": "BBBBBBBBBBssssssssssssssssssssaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaarrrrrrrrrr",
"output": "0"
},
{
"input": "BBBBBBBBBBbbbbbbbbbbbbbbbbbbbbuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuullllllllllllllllllllssssssssssssssssssssaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaarrrrrrrrrrrrrrrrrrrr",
"output": "10"
},
{
"input": "BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBbbbbbbbbbbbbbbbbbbbbuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuullllllllllllllllllllssssssssssssssssssssaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaarrrrrrrrrrrrrrrrrrrrrrrrrrrrrr",
"output": "20"
},
{
"input": "CeSlSwec",
"output": "0"
},
{
"input": "PnMrWPBGzVcmRcO",
"output": "0"
},
{
"input": "hHPWBQeEmCuhdCnzrqYtuFtwxokGhdGkFtsFICVqYfJeUrSBtSxEbzMCblOgqOvjXURhSKivPcseqgiNuUgIboEYMvVeRBbpzCGCfVydDvZNFGSFidwUtNbmPSfSYdMNmHgchIsiVswzFsGQewlMVEzicOagpWMdCWrCdPmexfnM",
"output": "0"
},
{
"input": "BBBBBBBBBBbbbbbbbbbbbbuuuuuuuuuuuullllllllllllssssssssssssaaaaaaaaaaaarrrrrrrrrrrrZBphUC",
"output": "6"
},
{
"input": "bulsar",
"output": "0"
},
{
"input": "Bblsar",
"output": "0"
},
{
"input": "Bbusar",
"output": "0"
},
{
"input": "Bbular",
"output": "0"
},
{
"input": "Bbulsr",
"output": "0"
},
{
"input": "Bbulsa",
"output": "0"
},
{
"input": "Bbulsar",
"output": "0"
},
{
"input": "Bbulsar",
"output": "0"
},
{
"input": "CaQprCjTiQACZjUJjSmMHVTDorSUugvTtksEjptVzNLhClWaVVWszIixBlqFkvjDmbRjarQoUWhXHoCgYNNjvEgRTgKpbdEMFsmqcTyvJzupKgYiYMtrZWXIAGVhmDURtddbBZIMgIgXqQUmXpssLSaVCDGZDHimNthwiAWabjtcraAQugMCpBPQZbBGZyqUZmzDVSvJZmDWfZEUHGJVtiJANAIbvjTxtvvTbjWRpNQZlxAqpLCLRVwYWqLaHOTvzgeNGdxiBwsAVKKsewXMTwZUUfxYwrwsiaRBwEdvDDoPsQUtinvajBoRzLBUuQekhjsfDAOQzIABSVPitRuhvvqeAahsSELTGbCPh",
"output": "2"
},
{
"input": "Bulbasaur",
"output": "1"
},
{
"input": "BulbasaurBulbasaur",
"output": "2"
},
{
"input": "Bulbbasar",
"output": "0"
},
{
"input": "Bulbasur",
"output": "0"
},
{
"input": "Bulbsaur",
"output": "0"
},
{
"input": "BulbsurBulbsurBulbsurBulbsur",
"output": "0"
},
{
"input": "Blbbasar",
"output": "0"
},
{
"input": "Bulbasar",
"output": "0"
},
{
"input": "BBullllbbaassaauurr",
"output": "1"
},
{
"input": "BulbasaurBulbasar",
"output": "1"
},
{
"input": "BulbasaurBulbsaur",
"output": "1"
},
{
"input": "Bubasaur",
"output": "0"
},
{
"input": "ulbasaurulbasaur",
"output": "0"
},
{
"input": "Bulbasr",
"output": "0"
},
{
"input": "BBBuuulllbbbaaasssaaauuurrr",
"output": "3"
},
{
"input": "BBuuuullbbaaaassrr",
"output": "2"
},
{
"input": "BBBBBBBuuuuuuuullllllllllllbbbbaaaaaassssssssssssssssaaaaauuuuuuuuuuuuurrrrrrrrrrrrrrrr",
"output": "4"
},
{
"input": "BBuullbbaassaarr",
"output": "1"
},
{
"input": "Bulbasau",
"output": "0"
},
{
"input": "BBuullbbaassaauurr",
"output": "2"
},
{
"input": "BulbasauBulbasauBulbasauBulbasauBulbasauBulbasauBulbasauBulbasau",
"output": "0"
},
{
"input": "Blbasaur",
"output": "0"
},
{
"input": "BulbasaurBulbasaurd",
"output": "2"
},
{
"input": "ulbasaur",
"output": "0"
},
{
"input": "Bulbaaur",
"output": "0"
},
{
"input": "BBuuuullbbbbbbbbbbbbbbbaassrr",
"output": "1"
},
{
"input": "Bulbasua",
"output": "0"
},
{
"input": "Bubbasaur",
"output": "0"
},
{
"input": "BulbasauBulbasauBulbasauBulbasauBulbasauBulbasaurrr",
"output": "3"
},
{
"input": "BulbasaurBubasaur",
"output": "1"
},
{
"input": "Baab",
"output": "0"
},
{
"input": "BulbasaurBulbasau",
"output": "1"
},
{
"input": "Bulbasauu",
"output": "0"
},
{
"input": "BulbasauBulbasau",
"output": "0"
},
{
"input": "BBBBBBBBBBB",
"output": "0"
},
{
"input": "Bulbbasau",
"output": "0"
},
{
"input": "BulbbasaurBulbbasar",
"output": "1"
},
{
"input": "Bulaaaasaur",
"output": "0"
},
{
"input": "BulbasaurBulbasauBulbasauBulbasau",
"output": "1"
}
] | 1,617,756,999 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 6 | 62 | 0 | def solve(s):
d = {
'B': 0,
'u':0,
'l':0,
'b':0,
'a':0,
'u':0,
'r':0,
's':0
}
for c in s:
if c in 'Bulbbasaur':
d[c]+=1
min_val = 1000000000
for i in d:
if not d[i]:
return 0
if d['a'] < 2 or d['u'] < 2:
return 0
if d[i] < min_val:
if i in ['a','u']:
min_val = d[i]//2
min_val = d[i]
return min_val
def main() :
# n,k = list(map(int, input().split(' ')))
# n = int(input())
# arr = input().split(' ')
s = input()
# res=''
# n = int(input())
# arr = []
# for _ in range(n):
# i = input()
# arr.append(i)
# # for i in arr:
# n = int(input())
# s = input()
print(solve(s))
main()
| Title: Gotta Catch Em' All!
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Bash wants to become a Pokemon master one day. Although he liked a lot of Pokemon, he has always been fascinated by Bulbasaur the most. Soon, things started getting serious and his fascination turned into an obsession. Since he is too young to go out and catch Bulbasaur, he came up with his own way of catching a Bulbasaur.
Each day, he takes the front page of the newspaper. He cuts out the letters one at a time, from anywhere on the front page of the newspaper to form the word "Bulbasaur" (without quotes) and sticks it on his wall. Bash is very particular about case — the first letter of "Bulbasaur" must be upper case and the rest must be lower case. By doing this he thinks he has caught one Bulbasaur. He then repeats this step on the left over part of the newspaper. He keeps doing this until it is not possible to form the word "Bulbasaur" from the newspaper.
Given the text on the front page of the newspaper, can you tell how many Bulbasaurs he will catch today?
Note: uppercase and lowercase letters are considered different.
Input Specification:
Input contains a single line containing a string *s* (1<=<=≤<=<=|*s*|<=<=≤<=<=105) — the text on the front page of the newspaper without spaces and punctuation marks. |*s*| is the length of the string *s*.
The string *s* contains lowercase and uppercase English letters, i.e. .
Output Specification:
Output a single integer, the answer to the problem.
Demo Input:
['Bulbbasaur\n', 'F\n', 'aBddulbasaurrgndgbualdBdsagaurrgndbb\n']
Demo Output:
['1\n', '0\n', '2\n']
Note:
In the first case, you could pick: Bulbbasaur.
In the second case, there is no way to pick even a single Bulbasaur.
In the third case, you can rearrange the string to BulbasaurBulbasauraddrgndgddgargndbb to get two words "Bulbasaur". | ```python
def solve(s):
d = {
'B': 0,
'u':0,
'l':0,
'b':0,
'a':0,
'u':0,
'r':0,
's':0
}
for c in s:
if c in 'Bulbbasaur':
d[c]+=1
min_val = 1000000000
for i in d:
if not d[i]:
return 0
if d['a'] < 2 or d['u'] < 2:
return 0
if d[i] < min_val:
if i in ['a','u']:
min_val = d[i]//2
min_val = d[i]
return min_val
def main() :
# n,k = list(map(int, input().split(' ')))
# n = int(input())
# arr = input().split(' ')
s = input()
# res=''
# n = int(input())
# arr = []
# for _ in range(n):
# i = input()
# arr.append(i)
# # for i in arr:
# n = int(input())
# s = input()
print(solve(s))
main()
``` | 0 |
|
976 | A | Minimum Binary Number | PROGRAMMING | 800 | [
"implementation"
] | null | null | String can be called correct if it consists of characters "0" and "1" and there are no redundant leading zeroes. Here are some examples: "0", "10", "1001".
You are given a correct string *s*.
You can perform two different operations on this string:
1. swap any pair of adjacent characters (for example, "101" "110"); 1. replace "11" with "1" (for example, "110" "10").
Let *val*(*s*) be such a number that *s* is its binary representation.
Correct string *a* is less than some other correct string *b* iff *val*(*a*)<=<<=*val*(*b*).
Your task is to find the minimum correct string that you can obtain from the given one using the operations described above. You can use these operations any number of times in any order (or even use no operations at all). | The first line contains integer number *n* (1<=≤<=*n*<=≤<=100) — the length of string *s*.
The second line contains the string *s* consisting of characters "0" and "1". It is guaranteed that the string *s* is correct. | Print one string — the minimum correct string that you can obtain from the given one. | [
"4\n1001\n",
"1\n1\n"
] | [
"100\n",
"1\n"
] | In the first example you can obtain the answer by the following sequence of operations: "1001" <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> "1010" <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> "1100" <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> "100".
In the second example you can't obtain smaller answer no matter what operations you use. | 0 | [
{
"input": "4\n1001",
"output": "100"
},
{
"input": "1\n1",
"output": "1"
},
{
"input": "100\n1110111100001111011111111010110011111111011110000111101101011100110110001011000000101010110101011100",
"output": "1000000000000000000000000000000000000000"
},
{
"input": "100\n1000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
"output": "1000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"
},
{
"input": "100\n1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111",
"output": "1"
},
{
"input": "100\n1111111111111111111111111111111111111111111111111111111110111111111111111111111111111111111111111111",
"output": "10"
},
{
"input": "1\n0",
"output": "0"
},
{
"input": "8\n10101010",
"output": "10000"
},
{
"input": "2\n10",
"output": "10"
},
{
"input": "3\n111",
"output": "1"
},
{
"input": "5\n11100",
"output": "100"
},
{
"input": "2\n11",
"output": "1"
},
{
"input": "3\n110",
"output": "10"
},
{
"input": "50\n10010010000000000000000000000000000000001000000000",
"output": "10000000000000000000000000000000000000000000000"
}
] | 1,694,614,508 | 2,147,483,647 | Python 3 | OK | TESTS | 14 | 46 | 0 | def solve():
size = input()
s = input()
print('1' * ('1' in s) + '0' * s.count('0'))
if __name__ == "__main__":
solve()
| Title: Minimum Binary Number
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
String can be called correct if it consists of characters "0" and "1" and there are no redundant leading zeroes. Here are some examples: "0", "10", "1001".
You are given a correct string *s*.
You can perform two different operations on this string:
1. swap any pair of adjacent characters (for example, "101" "110"); 1. replace "11" with "1" (for example, "110" "10").
Let *val*(*s*) be such a number that *s* is its binary representation.
Correct string *a* is less than some other correct string *b* iff *val*(*a*)<=<<=*val*(*b*).
Your task is to find the minimum correct string that you can obtain from the given one using the operations described above. You can use these operations any number of times in any order (or even use no operations at all).
Input Specification:
The first line contains integer number *n* (1<=≤<=*n*<=≤<=100) — the length of string *s*.
The second line contains the string *s* consisting of characters "0" and "1". It is guaranteed that the string *s* is correct.
Output Specification:
Print one string — the minimum correct string that you can obtain from the given one.
Demo Input:
['4\n1001\n', '1\n1\n']
Demo Output:
['100\n', '1\n']
Note:
In the first example you can obtain the answer by the following sequence of operations: "1001" <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> "1010" <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> "1100" <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> "100".
In the second example you can't obtain smaller answer no matter what operations you use. | ```python
def solve():
size = input()
s = input()
print('1' * ('1' in s) + '0' * s.count('0'))
if __name__ == "__main__":
solve()
``` | 3 |
|
0 | none | none | none | 0 | [
"none"
] | null | null | In Absurdistan, there are *n* towns (numbered 1 through *n*) and *m* bidirectional railways. There is also an absurdly simple road network — for each pair of different towns *x* and *y*, there is a bidirectional road between towns *x* and *y* if and only if there is no railway between them. Travelling to a different town using one railway or one road always takes exactly one hour.
A train and a bus leave town 1 at the same time. They both have the same destination, town *n*, and don't make any stops on the way (but they can wait in town *n*). The train can move only along railways and the bus can move only along roads.
You've been asked to plan out routes for the vehicles; each route can use any road/railway multiple times. One of the most important aspects to consider is safety — in order to avoid accidents at railway crossings, the train and the bus must not arrive at the same town (except town *n*) simultaneously.
Under these constraints, what is the minimum number of hours needed for both vehicles to reach town *n* (the maximum of arrival times of the bus and the train)? Note, that bus and train are not required to arrive to the town *n* at the same moment of time, but are allowed to do so. | The first line of the input contains two integers *n* and *m* (2<=≤<=*n*<=≤<=400, 0<=≤<=*m*<=≤<=*n*(*n*<=-<=1)<=/<=2) — the number of towns and the number of railways respectively.
Each of the next *m* lines contains two integers *u* and *v*, denoting a railway between towns *u* and *v* (1<=≤<=*u*,<=*v*<=≤<=*n*, *u*<=≠<=*v*).
You may assume that there is at most one railway connecting any two towns. | Output one integer — the smallest possible time of the later vehicle's arrival in town *n*. If it's impossible for at least one of the vehicles to reach town *n*, output <=-<=1. | [
"4 2\n1 3\n3 4\n",
"4 6\n1 2\n1 3\n1 4\n2 3\n2 4\n3 4\n",
"5 5\n4 2\n3 5\n4 5\n5 1\n1 2\n"
] | [
"2\n",
"-1\n",
"3\n"
] | In the first sample, the train can take the route <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/7c0aa60a06309ef607b7159fd7f3687ea0d943ce.png" style="max-width: 100.0%;max-height: 100.0%;"/> and the bus can take the route <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/a26c2f3e93c9d9be6c21cb5d2bd6ac1f99f4ff55.png" style="max-width: 100.0%;max-height: 100.0%;"/>. Note that they can arrive at town 4 at the same time.
In the second sample, Absurdistan is ruled by railwaymen. There are no roads, so there's no way for the bus to reach town 4. | 0 | [
{
"input": "4 2\n1 3\n3 4",
"output": "2"
},
{
"input": "4 6\n1 2\n1 3\n1 4\n2 3\n2 4\n3 4",
"output": "-1"
},
{
"input": "5 5\n4 2\n3 5\n4 5\n5 1\n1 2",
"output": "3"
},
{
"input": "5 4\n1 2\n3 2\n3 4\n5 4",
"output": "4"
},
{
"input": "3 1\n1 2",
"output": "-1"
},
{
"input": "2 1\n1 2",
"output": "-1"
},
{
"input": "2 0",
"output": "-1"
},
{
"input": "20 0",
"output": "-1"
},
{
"input": "381 0",
"output": "-1"
},
{
"input": "3 3\n1 2\n2 3\n3 1",
"output": "-1"
},
{
"input": "3 0",
"output": "-1"
},
{
"input": "3 1\n1 3",
"output": "2"
},
{
"input": "3 2\n2 3\n3 1",
"output": "-1"
},
{
"input": "4 1\n1 4",
"output": "2"
},
{
"input": "4 5\n1 3\n2 1\n3 4\n4 2\n2 3",
"output": "2"
},
{
"input": "20 1\n20 1",
"output": "2"
},
{
"input": "21 1\n21 1",
"output": "2"
},
{
"input": "100 1\n100 1",
"output": "2"
},
{
"input": "400 1\n1 400",
"output": "2"
},
{
"input": "5 5\n2 5\n1 2\n1 4\n1 3\n3 2",
"output": "2"
}
] | 1,697,337,545 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 59 | 482 | 8,192,000 | n, m = map(int, input().split())
a = [[0] * (n + 1) for _ in range(n + 1)]
for _ in range(m):
u, v = map(int, input().split())
a[u][v] = 1
a[v][u] = 1
def bfs(x):
fila = [(1, 0)]
visitados = [0] * (n + 1)
while fila:
u, v = fila.pop(0)
for i in range(1, n + 1):
if not visitados[i] and a[u][i] == x:
if i == n:
return v + 1
fila.append((i, v + 1))
visitados[i] = 1
return -1
if a[1][n]:
print(bfs(0))
else:
print(bfs(1))
| Title: none
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
In Absurdistan, there are *n* towns (numbered 1 through *n*) and *m* bidirectional railways. There is also an absurdly simple road network — for each pair of different towns *x* and *y*, there is a bidirectional road between towns *x* and *y* if and only if there is no railway between them. Travelling to a different town using one railway or one road always takes exactly one hour.
A train and a bus leave town 1 at the same time. They both have the same destination, town *n*, and don't make any stops on the way (but they can wait in town *n*). The train can move only along railways and the bus can move only along roads.
You've been asked to plan out routes for the vehicles; each route can use any road/railway multiple times. One of the most important aspects to consider is safety — in order to avoid accidents at railway crossings, the train and the bus must not arrive at the same town (except town *n*) simultaneously.
Under these constraints, what is the minimum number of hours needed for both vehicles to reach town *n* (the maximum of arrival times of the bus and the train)? Note, that bus and train are not required to arrive to the town *n* at the same moment of time, but are allowed to do so.
Input Specification:
The first line of the input contains two integers *n* and *m* (2<=≤<=*n*<=≤<=400, 0<=≤<=*m*<=≤<=*n*(*n*<=-<=1)<=/<=2) — the number of towns and the number of railways respectively.
Each of the next *m* lines contains two integers *u* and *v*, denoting a railway between towns *u* and *v* (1<=≤<=*u*,<=*v*<=≤<=*n*, *u*<=≠<=*v*).
You may assume that there is at most one railway connecting any two towns.
Output Specification:
Output one integer — the smallest possible time of the later vehicle's arrival in town *n*. If it's impossible for at least one of the vehicles to reach town *n*, output <=-<=1.
Demo Input:
['4 2\n1 3\n3 4\n', '4 6\n1 2\n1 3\n1 4\n2 3\n2 4\n3 4\n', '5 5\n4 2\n3 5\n4 5\n5 1\n1 2\n']
Demo Output:
['2\n', '-1\n', '3\n']
Note:
In the first sample, the train can take the route <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/7c0aa60a06309ef607b7159fd7f3687ea0d943ce.png" style="max-width: 100.0%;max-height: 100.0%;"/> and the bus can take the route <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/a26c2f3e93c9d9be6c21cb5d2bd6ac1f99f4ff55.png" style="max-width: 100.0%;max-height: 100.0%;"/>. Note that they can arrive at town 4 at the same time.
In the second sample, Absurdistan is ruled by railwaymen. There are no roads, so there's no way for the bus to reach town 4. | ```python
n, m = map(int, input().split())
a = [[0] * (n + 1) for _ in range(n + 1)]
for _ in range(m):
u, v = map(int, input().split())
a[u][v] = 1
a[v][u] = 1
def bfs(x):
fila = [(1, 0)]
visitados = [0] * (n + 1)
while fila:
u, v = fila.pop(0)
for i in range(1, n + 1):
if not visitados[i] and a[u][i] == x:
if i == n:
return v + 1
fila.append((i, v + 1))
visitados[i] = 1
return -1
if a[1][n]:
print(bfs(0))
else:
print(bfs(1))
``` | 3 |
|
721 | C | Journey | PROGRAMMING | 1,800 | [
"dp",
"graphs"
] | null | null | Recently Irina arrived to one of the most famous cities of Berland — the Berlatov city. There are *n* showplaces in the city, numbered from 1 to *n*, and some of them are connected by one-directional roads. The roads in Berlatov are designed in a way such that there are no cyclic routes between showplaces.
Initially Irina stands at the showplace 1, and the endpoint of her journey is the showplace *n*. Naturally, Irina wants to visit as much showplaces as she can during her journey. However, Irina's stay in Berlatov is limited and she can't be there for more than *T* time units.
Help Irina determine how many showplaces she may visit during her journey from showplace 1 to showplace *n* within a time not exceeding *T*. It is guaranteed that there is at least one route from showplace 1 to showplace *n* such that Irina will spend no more than *T* time units passing it. | The first line of the input contains three integers *n*,<=*m* and *T* (2<=≤<=*n*<=≤<=5000,<=<=1<=≤<=*m*<=≤<=5000,<=<=1<=≤<=*T*<=≤<=109) — the number of showplaces, the number of roads between them and the time of Irina's stay in Berlatov respectively.
The next *m* lines describes roads in Berlatov. *i*-th of them contains 3 integers *u**i*,<=*v**i*,<=*t**i* (1<=≤<=*u**i*,<=*v**i*<=≤<=*n*,<=*u**i*<=≠<=*v**i*,<=1<=≤<=*t**i*<=≤<=109), meaning that there is a road starting from showplace *u**i* and leading to showplace *v**i*, and Irina spends *t**i* time units to pass it. It is guaranteed that the roads do not form cyclic routes.
It is guaranteed, that there is at most one road between each pair of showplaces. | Print the single integer *k* (2<=≤<=*k*<=≤<=*n*) — the maximum number of showplaces that Irina can visit during her journey from showplace 1 to showplace *n* within time not exceeding *T*, in the first line.
Print *k* distinct integers in the second line — indices of showplaces that Irina will visit on her route, in the order of encountering them.
If there are multiple answers, print any of them. | [
"4 3 13\n1 2 5\n2 3 7\n2 4 8\n",
"6 6 7\n1 2 2\n1 3 3\n3 6 3\n2 4 2\n4 6 2\n6 5 1\n",
"5 5 6\n1 3 3\n3 5 3\n1 2 2\n2 4 3\n4 5 2\n"
] | [
"3\n1 2 4 \n",
"4\n1 2 4 6 \n",
"3\n1 3 5 \n"
] | none | 1,500 | [
{
"input": "4 3 13\n1 2 5\n2 3 7\n2 4 8",
"output": "3\n1 2 4 "
},
{
"input": "6 6 7\n1 2 2\n1 3 3\n3 6 3\n2 4 2\n4 6 2\n6 5 1",
"output": "4\n1 2 4 6 "
},
{
"input": "5 5 6\n1 3 3\n3 5 3\n1 2 2\n2 4 3\n4 5 2",
"output": "3\n1 3 5 "
},
{
"input": "10 10 100\n1 4 1\n6 4 1\n9 3 2\n2 7 2\n5 8 11\n1 2 8\n4 10 10\n8 9 2\n7 5 8\n3 6 4",
"output": "10\n1 2 7 5 8 9 3 6 4 10 "
},
{
"input": "10 10 56\n4 8 5\n9 3 11\n2 5 5\n5 9 9\n3 6 1\n1 4 9\n8 7 7\n6 10 1\n1 6 12\n7 2 9",
"output": "3\n1 6 10 "
},
{
"input": "4 4 3\n1 2 1\n2 3 1\n3 4 1\n1 3 1",
"output": "4\n1 2 3 4 "
},
{
"input": "4 4 2\n1 2 1\n2 3 1\n3 4 1\n1 3 1",
"output": "3\n1 3 4 "
},
{
"input": "10 45 8\n1 2 1\n1 3 1\n1 4 1\n1 5 1\n1 6 1\n1 7 1\n1 8 1\n1 9 1\n1 10 1\n2 3 1\n2 4 1\n2 5 1\n2 6 1\n2 7 1\n2 8 1\n2 9 1\n2 10 1\n3 4 1\n3 5 1\n3 6 1\n3 7 1\n3 8 1\n3 9 1\n3 10 1\n4 5 1\n4 6 1\n4 7 1\n4 8 1\n4 9 1\n4 10 1\n5 6 1\n5 7 1\n5 8 1\n5 9 1\n5 10 1\n6 7 1\n6 8 1\n6 9 1\n6 10 1\n7 8 1\n7 9 1\n7 10 1\n8 9 1\n8 10 1\n9 10 1",
"output": "9\n1 2 3 4 5 6 7 8 10 "
},
{
"input": "2 1 1\n1 2 1",
"output": "2\n1 2 "
},
{
"input": "12 12 8\n1 2 2\n2 3 5\n3 12 1\n4 5 1000000000\n1 7 1\n7 6 3\n6 12 1\n1 9 1\n9 10 1\n10 11 1\n11 8 1\n8 12 1",
"output": "6\n1 9 10 11 8 12 "
},
{
"input": "12 12 5\n1 2 2\n2 3 5\n3 12 1\n4 5 1000000000\n1 7 1\n7 6 3\n6 12 1\n1 9 1\n9 10 1\n10 11 1\n11 8 1\n8 12 1",
"output": "6\n1 9 10 11 8 12 "
},
{
"input": "12 12 4\n1 2 2\n2 3 5\n3 12 1\n4 5 1000000000\n1 7 1\n7 6 2\n6 12 1\n1 9 1\n9 10 1\n10 11 1\n11 8 1\n8 12 1",
"output": "4\n1 7 6 12 "
},
{
"input": "11 11 9\n1 2 1\n2 3 1\n1 4 1\n4 5 1\n5 6 1\n6 3 1\n3 7 1\n7 8 1\n8 11 1\n11 10 1\n10 9 1",
"output": "8\n1 4 5 6 3 7 8 11 "
},
{
"input": "11 11 7\n1 2 1\n2 3 1\n1 4 1\n4 5 1\n5 6 1\n6 3 1\n3 7 1\n7 8 1\n8 11 1\n11 10 1\n10 9 1",
"output": "8\n1 4 5 6 3 7 8 11 "
},
{
"input": "11 11 6\n1 2 1\n2 3 1\n1 4 1\n4 5 1\n5 6 1\n6 3 1\n3 7 1\n7 8 1\n8 11 1\n11 10 1\n10 9 1",
"output": "6\n1 2 3 7 8 11 "
},
{
"input": "12 12 9\n1 2 1\n2 3 1\n1 4 1\n4 5 1\n5 6 1\n6 3 1\n3 7 1\n7 8 1\n8 12 1\n12 10 1\n10 9 1\n11 1 1",
"output": "8\n1 4 5 6 3 7 8 12 "
},
{
"input": "4 4 120\n1 2 11\n1 3 20\n2 3 10\n3 4 100",
"output": "3\n1 3 4 "
},
{
"input": "4 4 10\n2 1 1\n2 3 1\n1 3 1\n3 4 1",
"output": "3\n1 3 4 "
},
{
"input": "5 5 200\n1 2 100\n2 4 100\n1 3 1\n3 4 1\n4 5 1",
"output": "4\n1 3 4 5 "
},
{
"input": "5 5 2\n1 2 1\n1 3 1\n3 4 1\n2 5 1\n4 2 1",
"output": "3\n1 2 5 "
},
{
"input": "4 4 1000000000\n1 2 1000000000\n2 3 1000000000\n3 4 1000000000\n1 4 1000000000",
"output": "2\n1 4 "
}
] | 1,645,218,883 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 15 | 102,400 | import collections
from functools import lru_cache
from collections import deque
n, m, T = map(int, input().split())
g = collections.defaultdict(list)
rev_g = collections.defaultdict(list)
indegree = [0] * (n + 1)
for _ in range(m):
u, v, t = map(int, input().split())
g[u].append(v)
rev_g[v].append((u, t))
indegree[v] += 1
dq = deque()
dq.append(1)
topo_order = []
while dq:
u = dq.popleft()
topo_order.append(u)
for v in g[u]:
indegree[v] -= 1
if indegree[v] == 0:
dq.append(v)
dp = [[(float('inf'), -1)] * (n + 1) for _ in range(n + 1)]
dp[1][1] = (0, -1)
for v in topo_order[1:]:
for u, t in rev_g[v]:
for nodes_in_paths in range(1, n + 1):
if dp[u][nodes_in_paths - 1][0] == float('inf'):
continue
if (dp[u][nodes_in_paths - 1][0] + t) < dp[v][nodes_in_paths][0]:
dp[v][nodes_in_paths] = (dp[u][nodes_in_paths - 1][0] + t, u) # prev node is u
res = 1
path = []
for nodes_in_paths in range(n, 0, -1):
if dp[n][nodes_in_paths][0] != float('inf') and dp[n][nodes_in_paths][0] <= T:
res = nodes_in_paths
path = []
while n != -1:
path.append(n)
n = dp[n][nodes_in_paths][1]
nodes_in_paths -= 1
break
print(res)
print(path[::-1])
| Title: Journey
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Recently Irina arrived to one of the most famous cities of Berland — the Berlatov city. There are *n* showplaces in the city, numbered from 1 to *n*, and some of them are connected by one-directional roads. The roads in Berlatov are designed in a way such that there are no cyclic routes between showplaces.
Initially Irina stands at the showplace 1, and the endpoint of her journey is the showplace *n*. Naturally, Irina wants to visit as much showplaces as she can during her journey. However, Irina's stay in Berlatov is limited and she can't be there for more than *T* time units.
Help Irina determine how many showplaces she may visit during her journey from showplace 1 to showplace *n* within a time not exceeding *T*. It is guaranteed that there is at least one route from showplace 1 to showplace *n* such that Irina will spend no more than *T* time units passing it.
Input Specification:
The first line of the input contains three integers *n*,<=*m* and *T* (2<=≤<=*n*<=≤<=5000,<=<=1<=≤<=*m*<=≤<=5000,<=<=1<=≤<=*T*<=≤<=109) — the number of showplaces, the number of roads between them and the time of Irina's stay in Berlatov respectively.
The next *m* lines describes roads in Berlatov. *i*-th of them contains 3 integers *u**i*,<=*v**i*,<=*t**i* (1<=≤<=*u**i*,<=*v**i*<=≤<=*n*,<=*u**i*<=≠<=*v**i*,<=1<=≤<=*t**i*<=≤<=109), meaning that there is a road starting from showplace *u**i* and leading to showplace *v**i*, and Irina spends *t**i* time units to pass it. It is guaranteed that the roads do not form cyclic routes.
It is guaranteed, that there is at most one road between each pair of showplaces.
Output Specification:
Print the single integer *k* (2<=≤<=*k*<=≤<=*n*) — the maximum number of showplaces that Irina can visit during her journey from showplace 1 to showplace *n* within time not exceeding *T*, in the first line.
Print *k* distinct integers in the second line — indices of showplaces that Irina will visit on her route, in the order of encountering them.
If there are multiple answers, print any of them.
Demo Input:
['4 3 13\n1 2 5\n2 3 7\n2 4 8\n', '6 6 7\n1 2 2\n1 3 3\n3 6 3\n2 4 2\n4 6 2\n6 5 1\n', '5 5 6\n1 3 3\n3 5 3\n1 2 2\n2 4 3\n4 5 2\n']
Demo Output:
['3\n1 2 4 \n', '4\n1 2 4 6 \n', '3\n1 3 5 \n']
Note:
none | ```python
import collections
from functools import lru_cache
from collections import deque
n, m, T = map(int, input().split())
g = collections.defaultdict(list)
rev_g = collections.defaultdict(list)
indegree = [0] * (n + 1)
for _ in range(m):
u, v, t = map(int, input().split())
g[u].append(v)
rev_g[v].append((u, t))
indegree[v] += 1
dq = deque()
dq.append(1)
topo_order = []
while dq:
u = dq.popleft()
topo_order.append(u)
for v in g[u]:
indegree[v] -= 1
if indegree[v] == 0:
dq.append(v)
dp = [[(float('inf'), -1)] * (n + 1) for _ in range(n + 1)]
dp[1][1] = (0, -1)
for v in topo_order[1:]:
for u, t in rev_g[v]:
for nodes_in_paths in range(1, n + 1):
if dp[u][nodes_in_paths - 1][0] == float('inf'):
continue
if (dp[u][nodes_in_paths - 1][0] + t) < dp[v][nodes_in_paths][0]:
dp[v][nodes_in_paths] = (dp[u][nodes_in_paths - 1][0] + t, u) # prev node is u
res = 1
path = []
for nodes_in_paths in range(n, 0, -1):
if dp[n][nodes_in_paths][0] != float('inf') and dp[n][nodes_in_paths][0] <= T:
res = nodes_in_paths
path = []
while n != -1:
path.append(n)
n = dp[n][nodes_in_paths][1]
nodes_in_paths -= 1
break
print(res)
print(path[::-1])
``` | 0 |
|
918 | B | Radio Station | PROGRAMMING | 900 | [
"implementation",
"strings"
] | null | null | As the guys fried the radio station facilities, the school principal gave them tasks as a punishment. Dustin's task was to add comments to nginx configuration for school's website. The school has *n* servers. Each server has a name and an ip (names aren't necessarily unique, but ips are). Dustin knows the ip and name of each server. For simplicity, we'll assume that an nginx command is of form "command ip;" where command is a string consisting of English lowercase letter only, and ip is the ip of one of school servers.
Each ip is of form "a.b.c.d" where *a*, *b*, *c* and *d* are non-negative integers less than or equal to 255 (with no leading zeros). The nginx configuration file Dustin has to add comments to has *m* commands. Nobody ever memorizes the ips of servers, so to understand the configuration better, Dustin has to comment the name of server that the ip belongs to at the end of each line (after each command). More formally, if a line is "command ip;" Dustin has to replace it with "command ip; #name" where name is the name of the server with ip equal to ip.
Dustin doesn't know anything about nginx, so he panicked again and his friends asked you to do his task for him. | The first line of input contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=1000).
The next *n* lines contain the names and ips of the servers. Each line contains a string name, name of the server and a string ip, ip of the server, separated by space (1<=≤<=|*name*|<=≤<=10, *name* only consists of English lowercase letters). It is guaranteed that all ip are distinct.
The next *m* lines contain the commands in the configuration file. Each line is of form "command ip;" (1<=≤<=|*command*|<=≤<=10, command only consists of English lowercase letters). It is guaranteed that ip belongs to one of the *n* school servers. | Print *m* lines, the commands in the configuration file after Dustin did his task. | [
"2 2\nmain 192.168.0.2\nreplica 192.168.0.1\nblock 192.168.0.1;\nproxy 192.168.0.2;\n",
"3 5\ngoogle 8.8.8.8\ncodeforces 212.193.33.27\nserver 138.197.64.57\nredirect 138.197.64.57;\nblock 8.8.8.8;\ncf 212.193.33.27;\nunblock 8.8.8.8;\ncheck 138.197.64.57;\n"
] | [
"block 192.168.0.1; #replica\nproxy 192.168.0.2; #main\n",
"redirect 138.197.64.57; #server\nblock 8.8.8.8; #google\ncf 212.193.33.27; #codeforces\nunblock 8.8.8.8; #google\ncheck 138.197.64.57; #server\n"
] | none | 1,000 | [
{
"input": "2 2\nmain 192.168.0.2\nreplica 192.168.0.1\nblock 192.168.0.1;\nproxy 192.168.0.2;",
"output": "block 192.168.0.1; #replica\nproxy 192.168.0.2; #main"
},
{
"input": "3 5\ngoogle 8.8.8.8\ncodeforces 212.193.33.27\nserver 138.197.64.57\nredirect 138.197.64.57;\nblock 8.8.8.8;\ncf 212.193.33.27;\nunblock 8.8.8.8;\ncheck 138.197.64.57;",
"output": "redirect 138.197.64.57; #server\nblock 8.8.8.8; #google\ncf 212.193.33.27; #codeforces\nunblock 8.8.8.8; #google\ncheck 138.197.64.57; #server"
},
{
"input": "10 10\nittmcs 112.147.123.173\njkt 228.40.73.178\nfwckqtz 88.28.31.198\nkal 224.226.34.213\nnacuyokm 49.57.13.44\nfouynv 243.18.250.17\ns 45.248.83.247\ne 75.69.23.169\nauwoqlch 100.44.219.187\nlkldjq 46.123.169.140\ngjcylatwzi 46.123.169.140;\ndxfi 88.28.31.198;\ngv 46.123.169.140;\nety 88.28.31.198;\notbmgcrn 46.123.169.140;\nw 112.147.123.173;\np 75.69.23.169;\nvdsnigk 46.123.169.140;\nmmc 46.123.169.140;\ngtc 49.57.13.44;",
"output": "gjcylatwzi 46.123.169.140; #lkldjq\ndxfi 88.28.31.198; #fwckqtz\ngv 46.123.169.140; #lkldjq\nety 88.28.31.198; #fwckqtz\notbmgcrn 46.123.169.140; #lkldjq\nw 112.147.123.173; #ittmcs\np 75.69.23.169; #e\nvdsnigk 46.123.169.140; #lkldjq\nmmc 46.123.169.140; #lkldjq\ngtc 49.57.13.44; #nacuyokm"
},
{
"input": "1 1\nervbfot 185.32.99.2\nzygoumbmx 185.32.99.2;",
"output": "zygoumbmx 185.32.99.2; #ervbfot"
},
{
"input": "1 2\ny 245.182.246.189\nlllq 245.182.246.189;\nxds 245.182.246.189;",
"output": "lllq 245.182.246.189; #y\nxds 245.182.246.189; #y"
},
{
"input": "2 1\ntdwmshz 203.115.124.110\neksckjya 201.80.191.212\nzbtjzzue 203.115.124.110;",
"output": "zbtjzzue 203.115.124.110; #tdwmshz"
},
{
"input": "8 5\nfhgkq 5.19.189.178\nphftablcr 75.18.177.178\nxnpcg 158.231.167.176\ncfahrkq 26.165.124.191\nfkgtnqtfoh 230.13.13.129\nt 101.24.94.85\nvjoirslx 59.6.179.72\ntwktmskb 38.194.117.184\nrvzzlygosc 26.165.124.191;\ndcsgxrkgv 101.24.94.85;\nyvmyppn 59.6.179.72;\ngpdjjuq 75.18.177.178;\nvdviz 101.24.94.85;",
"output": "rvzzlygosc 26.165.124.191; #cfahrkq\ndcsgxrkgv 101.24.94.85; #t\nyvmyppn 59.6.179.72; #vjoirslx\ngpdjjuq 75.18.177.178; #phftablcr\nvdviz 101.24.94.85; #t"
},
{
"input": "2 1\nmain 1.1.1.1\nget 11.1.1.1\ncommand 11.1.1.1;",
"output": "command 11.1.1.1; #get"
},
{
"input": "2 2\nmain 0.0.0.255\nmainn 0.0.2.55\nblock 0.0.0.255;\nblock 0.0.2.55;",
"output": "block 0.0.0.255; #main\nblock 0.0.2.55; #mainn"
},
{
"input": "2 2\nmain 0.0.63.0\nreplica 0.38.0.56\nblock 0.0.63.0;\nproxy 0.38.0.56;",
"output": "block 0.0.63.0; #main\nproxy 0.38.0.56; #replica"
},
{
"input": "2 2\nmain 192.168.10.12\nreplica 192.167.10.12\nblock 192.168.10.12;\nproxy 192.167.10.12;",
"output": "block 192.168.10.12; #main\nproxy 192.167.10.12; #replica"
},
{
"input": "2 1\nneserver 185.218.47.91\nserver 255.255.255.255\nblock 255.255.255.255;",
"output": "block 255.255.255.255; #server"
},
{
"input": "2 1\nalp 22.222.30.10\nbet 222.22.30.10\nblock 22.222.30.10;",
"output": "block 22.222.30.10; #alp"
}
] | 1,660,735,474 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 0 | 46 | 0 | n, m = map(int, input().split())
server = []
serverip = []
c_name = []
c_ip = []
for i in range(n):
name, ip = input().split()
ip = ip + ";"
server.append(name)
serverip.append(ip)
for i in range(m):
command, commandip = input().split()
for x in range(n):
if serverip[x] == commandip:
print(command, commandip, "#", server[x]) | Title: Radio Station
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
As the guys fried the radio station facilities, the school principal gave them tasks as a punishment. Dustin's task was to add comments to nginx configuration for school's website. The school has *n* servers. Each server has a name and an ip (names aren't necessarily unique, but ips are). Dustin knows the ip and name of each server. For simplicity, we'll assume that an nginx command is of form "command ip;" where command is a string consisting of English lowercase letter only, and ip is the ip of one of school servers.
Each ip is of form "a.b.c.d" where *a*, *b*, *c* and *d* are non-negative integers less than or equal to 255 (with no leading zeros). The nginx configuration file Dustin has to add comments to has *m* commands. Nobody ever memorizes the ips of servers, so to understand the configuration better, Dustin has to comment the name of server that the ip belongs to at the end of each line (after each command). More formally, if a line is "command ip;" Dustin has to replace it with "command ip; #name" where name is the name of the server with ip equal to ip.
Dustin doesn't know anything about nginx, so he panicked again and his friends asked you to do his task for him.
Input Specification:
The first line of input contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=1000).
The next *n* lines contain the names and ips of the servers. Each line contains a string name, name of the server and a string ip, ip of the server, separated by space (1<=≤<=|*name*|<=≤<=10, *name* only consists of English lowercase letters). It is guaranteed that all ip are distinct.
The next *m* lines contain the commands in the configuration file. Each line is of form "command ip;" (1<=≤<=|*command*|<=≤<=10, command only consists of English lowercase letters). It is guaranteed that ip belongs to one of the *n* school servers.
Output Specification:
Print *m* lines, the commands in the configuration file after Dustin did his task.
Demo Input:
['2 2\nmain 192.168.0.2\nreplica 192.168.0.1\nblock 192.168.0.1;\nproxy 192.168.0.2;\n', '3 5\ngoogle 8.8.8.8\ncodeforces 212.193.33.27\nserver 138.197.64.57\nredirect 138.197.64.57;\nblock 8.8.8.8;\ncf 212.193.33.27;\nunblock 8.8.8.8;\ncheck 138.197.64.57;\n']
Demo Output:
['block 192.168.0.1; #replica\nproxy 192.168.0.2; #main\n', 'redirect 138.197.64.57; #server\nblock 8.8.8.8; #google\ncf 212.193.33.27; #codeforces\nunblock 8.8.8.8; #google\ncheck 138.197.64.57; #server\n']
Note:
none | ```python
n, m = map(int, input().split())
server = []
serverip = []
c_name = []
c_ip = []
for i in range(n):
name, ip = input().split()
ip = ip + ";"
server.append(name)
serverip.append(ip)
for i in range(m):
command, commandip = input().split()
for x in range(n):
if serverip[x] == commandip:
print(command, commandip, "#", server[x])
``` | 0 |
|
38 | A | Army | PROGRAMMING | 800 | [
"implementation"
] | A. Army | 2 | 256 | The Berland Armed Forces System consists of *n* ranks that are numbered using natural numbers from 1 to *n*, where 1 is the lowest rank and *n* is the highest rank.
One needs exactly *d**i* years to rise from rank *i* to rank *i*<=+<=1. Reaching a certain rank *i* having not reached all the previous *i*<=-<=1 ranks is impossible.
Vasya has just reached a new rank of *a*, but he dreams of holding the rank of *b*. Find for how many more years Vasya should serve in the army until he can finally realize his dream. | The first input line contains an integer *n* (2<=≤<=*n*<=≤<=100). The second line contains *n*<=-<=1 integers *d**i* (1<=≤<=*d**i*<=≤<=100). The third input line contains two integers *a* and *b* (1<=≤<=*a*<=<<=*b*<=≤<=*n*). The numbers on the lines are space-separated. | Print the single number which is the number of years that Vasya needs to rise from rank *a* to rank *b*. | [
"3\n5 6\n1 2\n",
"3\n5 6\n1 3\n"
] | [
"5\n",
"11\n"
] | none | 0 | [
{
"input": "3\n5 6\n1 2",
"output": "5"
},
{
"input": "3\n5 6\n1 3",
"output": "11"
},
{
"input": "2\n55\n1 2",
"output": "55"
},
{
"input": "3\n85 78\n1 3",
"output": "163"
},
{
"input": "4\n63 4 49\n2 3",
"output": "4"
},
{
"input": "5\n93 83 42 56\n2 5",
"output": "181"
},
{
"input": "6\n22 9 87 89 57\n1 6",
"output": "264"
},
{
"input": "7\n52 36 31 23 74 78\n2 7",
"output": "242"
},
{
"input": "8\n82 14 24 5 91 49 94\n3 8",
"output": "263"
},
{
"input": "9\n12 40 69 39 59 21 59 5\n4 6",
"output": "98"
},
{
"input": "10\n95 81 32 59 71 30 50 61 100\n1 6",
"output": "338"
},
{
"input": "15\n89 55 94 4 15 69 19 60 91 77 3 94 91 62\n3 14",
"output": "617"
},
{
"input": "20\n91 1 41 51 95 67 92 35 23 70 44 91 57 50 21 8 9 71 40\n8 17",
"output": "399"
},
{
"input": "25\n70 95 21 84 97 39 12 98 53 24 78 29 84 65 70 22 100 17 69 27 62 48 35 80\n8 23",
"output": "846"
},
{
"input": "30\n35 69 50 44 19 56 86 56 98 24 21 2 61 24 85 30 2 22 57 35 59 84 12 77 92 53 50 92 9\n1 16",
"output": "730"
},
{
"input": "35\n2 34 47 15 27 61 6 88 67 20 53 65 29 68 77 5 78 86 44 98 32 81 91 79 54 84 95 23 65 97 22 33 42 87\n8 35",
"output": "1663"
},
{
"input": "40\n32 88 59 36 95 45 28 78 73 30 97 13 13 47 48 100 43 21 22 45 88 25 15 13 63 25 72 92 29 5 25 11 50 5 54 51 48 84 23\n7 26",
"output": "862"
},
{
"input": "45\n83 74 73 95 10 31 100 26 29 15 80 100 22 70 31 88 9 56 19 70 2 62 48 30 27 47 52 50 94 44 21 94 23 85 15 3 95 72 43 62 94 89 68 88\n17 40",
"output": "1061"
},
{
"input": "50\n28 8 16 29 19 82 70 51 96 84 74 72 17 69 12 21 37 21 39 3 18 66 19 49 86 96 94 93 2 90 96 84 59 88 58 15 61 33 55 22 35 54 51 29 64 68 29 38 40\n23 28",
"output": "344"
},
{
"input": "60\n24 28 25 21 43 71 64 73 71 90 51 83 69 43 75 43 78 72 56 61 99 7 23 86 9 16 16 94 23 74 18 56 20 72 13 31 75 34 35 86 61 49 4 72 84 7 65 70 66 52 21 38 6 43 69 40 73 46 5\n28 60",
"output": "1502"
},
{
"input": "70\n69 95 34 14 67 61 6 95 94 44 28 94 73 66 39 13 19 71 73 71 28 48 26 22 32 88 38 95 43 59 88 77 80 55 17 95 40 83 67 1 38 95 58 63 56 98 49 2 41 4 73 8 78 41 64 71 60 71 41 61 67 4 4 19 97 14 39 20 27\n9 41",
"output": "1767"
},
{
"input": "80\n65 15 43 6 43 98 100 16 69 98 4 54 25 40 2 35 12 23 38 29 10 89 30 6 4 8 7 96 64 43 11 49 89 38 20 59 54 85 46 16 16 89 60 54 28 37 32 34 67 9 78 30 50 87 58 53 99 48 77 3 5 6 19 99 16 20 31 10 80 76 82 56 56 83 72 81 84 60 28\n18 24",
"output": "219"
},
{
"input": "90\n61 35 100 99 67 87 42 90 44 4 81 65 29 63 66 56 53 22 55 87 39 30 34 42 27 80 29 97 85 28 81 22 50 22 24 75 67 86 78 79 94 35 13 97 48 76 68 66 94 13 82 1 22 85 5 36 86 73 65 97 43 56 35 26 87 25 74 47 81 67 73 75 99 75 53 38 70 21 66 78 38 17 57 40 93 57 68 55 1\n12 44",
"output": "1713"
},
{
"input": "95\n37 74 53 96 65 84 65 72 95 45 6 77 91 35 58 50 51 51 97 30 51 20 79 81 92 10 89 34 40 76 71 54 26 34 73 72 72 28 53 19 95 64 97 10 44 15 12 38 5 63 96 95 86 8 36 96 45 53 81 5 18 18 47 97 65 9 33 53 41 86 37 53 5 40 15 76 83 45 33 18 26 5 19 90 46 40 100 42 10 90 13 81 40 53\n6 15",
"output": "570"
},
{
"input": "96\n51 32 95 75 23 54 70 89 67 3 1 51 4 100 97 30 9 35 56 38 54 77 56 98 43 17 60 43 72 46 87 61 100 65 81 22 74 38 16 96 5 10 54 22 23 22 10 91 9 54 49 82 29 73 33 98 75 8 4 26 24 90 71 42 90 24 94 74 94 10 41 98 56 63 18 43 56 21 26 64 74 33 22 38 67 66 38 60 64 76 53 10 4 65 76\n21 26",
"output": "328"
},
{
"input": "97\n18 90 84 7 33 24 75 55 86 10 96 72 16 64 37 9 19 71 62 97 5 34 85 15 46 72 82 51 52 16 55 68 27 97 42 72 76 97 32 73 14 56 11 86 2 81 59 95 60 93 1 22 71 37 77 100 6 16 78 47 78 62 94 86 16 91 56 46 47 35 93 44 7 86 70 10 29 45 67 62 71 61 74 39 36 92 24 26 65 14 93 92 15 28 79 59\n6 68",
"output": "3385"
},
{
"input": "98\n32 47 26 86 43 42 79 72 6 68 40 46 29 80 24 89 29 7 21 56 8 92 13 33 50 79 5 7 84 85 24 23 1 80 51 21 26 55 96 51 24 2 68 98 81 88 57 100 64 84 54 10 14 2 74 1 89 71 1 20 84 85 17 31 42 58 69 67 48 60 97 90 58 10 21 29 2 21 60 61 68 89 77 39 57 18 61 44 67 100 33 74 27 40 83 29 6\n8 77",
"output": "3319"
},
{
"input": "99\n46 5 16 66 53 12 84 89 26 27 35 68 41 44 63 17 88 43 80 15 59 1 42 50 53 34 75 16 16 55 92 30 28 11 12 71 27 65 11 28 86 47 24 10 60 47 7 53 16 75 6 49 56 66 70 3 20 78 75 41 38 57 89 23 16 74 30 39 1 32 49 84 9 33 25 95 75 45 54 59 17 17 29 40 79 96 47 11 69 86 73 56 91 4 87 47 31 24\n23 36",
"output": "514"
},
{
"input": "100\n63 65 21 41 95 23 3 4 12 23 95 50 75 63 58 34 71 27 75 31 23 94 96 74 69 34 43 25 25 55 44 19 43 86 68 17 52 65 36 29 72 96 84 25 84 23 71 54 6 7 71 7 21 100 99 58 93 35 62 47 36 70 68 9 75 13 35 70 76 36 62 22 52 51 2 87 66 41 54 35 78 62 30 35 65 44 74 93 78 37 96 70 26 32 71 27 85 85 63\n43 92",
"output": "2599"
},
{
"input": "51\n85 38 22 38 42 36 55 24 36 80 49 15 66 91 88 61 46 82 1 61 89 92 6 56 28 8 46 80 56 90 91 38 38 17 69 64 57 68 13 44 45 38 8 72 61 39 87 2 73 88\n15 27",
"output": "618"
},
{
"input": "2\n3\n1 2",
"output": "3"
},
{
"input": "5\n6 8 22 22\n2 3",
"output": "8"
},
{
"input": "6\n3 12 27 28 28\n3 4",
"output": "27"
},
{
"input": "9\n1 2 2 2 2 3 3 5\n3 7",
"output": "9"
},
{
"input": "10\n1 1 1 1 1 1 1 1 1\n6 8",
"output": "2"
},
{
"input": "20\n1 1 1 1 1 1 1 1 2 2 2 2 2 3 3 3 3 3 3\n5 17",
"output": "23"
},
{
"input": "25\n1 1 1 4 5 6 8 11 11 11 11 12 13 14 14 14 15 16 16 17 17 17 19 19\n4 8",
"output": "23"
},
{
"input": "35\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2\n30 31",
"output": "2"
},
{
"input": "45\n1 1 1 1 2 2 2 2 2 2 2 3 3 3 3 3 3 4 5 5 5 5 6 6 6 6 6 6 6 7 7 7 7 8 8 8 9 9 9 9 9 10 10 10\n42 45",
"output": "30"
},
{
"input": "50\n1 8 8 13 14 15 15 16 19 21 22 24 26 31 32 37 45 47 47 47 50 50 51 54 55 56 58 61 61 61 63 63 64 66 66 67 67 70 71 80 83 84 85 92 92 94 95 95 100\n4 17",
"output": "285"
},
{
"input": "60\n1 2 4 4 4 6 6 8 9 10 10 13 14 18 20 20 21 22 23 23 26 29 30 32 33 34 35 38 40 42 44 44 46 48 52 54 56 56 60 60 66 67 68 68 69 73 73 74 80 80 81 81 82 84 86 86 87 89 89\n56 58",
"output": "173"
},
{
"input": "70\n1 2 3 3 4 5 5 7 7 7 8 8 8 8 9 9 10 12 12 12 12 13 16 16 16 16 16 16 17 17 18 18 20 20 21 23 24 25 25 26 29 29 29 29 31 32 32 34 35 36 36 37 37 38 39 39 40 40 40 40 41 41 42 43 44 44 44 45 45\n62 65",
"output": "126"
},
{
"input": "80\n1 1 1 1 1 1 1 1 2 2 2 2 2 2 3 3 3 3 3 3 3 3 3 3 4 4 4 4 5 5 5 5 5 5 5 6 7 7 7 7 7 7 8 8 8 8 9 9 9 9 9 9 9 9 9 10 10 10 10 10 10 10 10 10 11 11 11 11 11 11 11 12 12 12 12 12 12 12 12\n17 65",
"output": "326"
},
{
"input": "90\n1 1 3 5 8 9 10 11 11 11 11 12 13 14 15 15 15 16 16 19 19 20 22 23 24 25 25 28 29 29 30 31 33 34 35 37 37 38 41 43 43 44 45 47 51 54 55 56 58 58 59 59 60 62 66 67 67 67 68 68 69 70 71 72 73 73 76 77 77 78 78 78 79 79 79 82 83 84 85 85 87 87 89 93 93 93 95 99 99\n28 48",
"output": "784"
},
{
"input": "95\n2 2 3 3 4 6 6 7 7 7 9 10 12 12 12 12 13 14 15 16 17 18 20 20 20 20 21 21 21 21 22 22 22 22 22 23 23 23 25 26 26 27 27 27 28 29 29 30 30 31 32 33 34 36 37 37 38 39 39 39 42 43 43 43 45 47 48 50 50 51 52 53 54 54 54 55 55 55 58 59 60 61 61 61 61 62 62 63 64 65 66 67 67 67\n64 93",
"output": "1636"
},
{
"input": "96\n1 1 2 3 3 5 8 9 9 10 10 10 11 11 11 11 11 12 13 13 13 14 15 15 16 16 17 17 17 17 18 18 20 20 20 21 21 21 23 24 24 25 25 26 27 27 27 27 29 29 29 30 30 30 32 32 32 32 32 32 33 33 34 34 34 35 35 35 36 36 37 37 37 38 39 40 41 41 41 41 42 42 43 43 45 45 45 46 46 47 47 49 50 52 52\n76 96",
"output": "898"
},
{
"input": "98\n2 3 4 4 5 7 8 10 10 10 11 11 12 12 12 12 13 14 15 15 16 16 18 19 19 20 21 21 21 21 22 23 24 25 26 26 27 27 27 27 29 29 30 30 31 31 37 40 40 40 41 41 41 42 43 44 44 44 46 46 47 49 49 50 50 50 51 53 55 55 56 56 56 56 56 57 57 58 59 60 60 60 62 62 63 64 64 64 65 66 66 67 68 70 70 71 71\n8 90",
"output": "3016"
},
{
"input": "99\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1\n66 95",
"output": "29"
},
{
"input": "100\n1 1 1 1 1 1 1 1 2 2 2 2 2 2 2 2 3 3 3 4 4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 6 6 6 6 6 6 6 6 6 6 6 6 7 7 7 7 7 7 8 8 8 8 9 9 9 9 10 10 10 10 11 11 11 11 12 12 12 13 13 13 13 13 13 13 13 13 13 14 14 14 14 14 14 15 15 15 15 15 15 16 16 16 17 17\n39 52",
"output": "82"
},
{
"input": "51\n5 7 9 16 19 25 26 29 29 30 31 32 32 41 43 44 47 49 50 50 51 52 54 55 56 63 64 66 67 70 74 74 77 78 79 80 80 85 86 87 89 89 90 92 93 94 94 95 95 97\n3 44",
"output": "2268"
}
] | 1,664,426,483 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 62 | 0 | t=int(input())
arr=[]
for i in range(t):
x=int(input())
arr.append(x)
a,b=0,0
a=int(input())
b=int(input())
s=0
ind=a-1
while(ind<b):
s+=arr[ind]
ind+=1
print(s) | Title: Army
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
The Berland Armed Forces System consists of *n* ranks that are numbered using natural numbers from 1 to *n*, where 1 is the lowest rank and *n* is the highest rank.
One needs exactly *d**i* years to rise from rank *i* to rank *i*<=+<=1. Reaching a certain rank *i* having not reached all the previous *i*<=-<=1 ranks is impossible.
Vasya has just reached a new rank of *a*, but he dreams of holding the rank of *b*. Find for how many more years Vasya should serve in the army until he can finally realize his dream.
Input Specification:
The first input line contains an integer *n* (2<=≤<=*n*<=≤<=100). The second line contains *n*<=-<=1 integers *d**i* (1<=≤<=*d**i*<=≤<=100). The third input line contains two integers *a* and *b* (1<=≤<=*a*<=<<=*b*<=≤<=*n*). The numbers on the lines are space-separated.
Output Specification:
Print the single number which is the number of years that Vasya needs to rise from rank *a* to rank *b*.
Demo Input:
['3\n5 6\n1 2\n', '3\n5 6\n1 3\n']
Demo Output:
['5\n', '11\n']
Note:
none | ```python
t=int(input())
arr=[]
for i in range(t):
x=int(input())
arr.append(x)
a,b=0,0
a=int(input())
b=int(input())
s=0
ind=a-1
while(ind<b):
s+=arr[ind]
ind+=1
print(s)
``` | -1 |
336 | C | Vasily the Bear and Sequence | PROGRAMMING | 1,800 | [
"brute force",
"greedy",
"implementation",
"number theory"
] | null | null | Vasily the bear has got a sequence of positive integers *a*1,<=*a*2,<=...,<=*a**n*. Vasily the Bear wants to write out several numbers on a piece of paper so that the beauty of the numbers he wrote out was maximum.
The beauty of the written out numbers *b*1,<=*b*2,<=...,<=*b**k* is such maximum non-negative integer *v*, that number *b*1 *and* *b*2 *and* ... *and* *b**k* is divisible by number 2*v* without a remainder. If such number *v* doesn't exist (that is, for any non-negative integer *v*, number *b*1 *and* *b*2 *and* ... *and* *b**k* is divisible by 2*v* without a remainder), the beauty of the written out numbers equals -1.
Tell the bear which numbers he should write out so that the beauty of the written out numbers is maximum. If there are multiple ways to write out the numbers, you need to choose the one where the bear writes out as many numbers as possible.
Here expression *x* *and* *y* means applying the bitwise AND operation to numbers *x* and *y*. In programming languages C++ and Java this operation is represented by "&", in Pascal — by "and". | The first line contains integer *n* (1<=≤<=*n*<=≤<=105). The second line contains *n* space-separated integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a*1<=<<=*a*2<=<<=...<=<<=*a**n*<=≤<=109). | In the first line print a single integer *k* (*k*<=><=0), showing how many numbers to write out. In the second line print *k* integers *b*1,<=*b*2,<=...,<=*b**k* — the numbers to write out. You are allowed to print numbers *b*1,<=*b*2,<=...,<=*b**k* in any order, but all of them must be distinct. If there are multiple ways to write out the numbers, choose the one with the maximum number of numbers to write out. If there still are multiple ways, you are allowed to print any of them. | [
"5\n1 2 3 4 5\n",
"3\n1 2 4\n"
] | [
"2\n4 5\n",
"1\n4\n"
] | none | 1,500 | [
{
"input": "5\n1 2 3 4 5",
"output": "2\n4 5"
},
{
"input": "3\n1 2 4",
"output": "1\n4"
},
{
"input": "3\n1 20 22",
"output": "2\n20 22"
},
{
"input": "10\n109070199 215498062 361633800 406156967 452258663 530571268 670482660 704334662 841023955 967424642",
"output": "6\n361633800 406156967 452258663 530571268 841023955 967424642"
},
{
"input": "30\n61 65 67 71 73 75 77 79 129 131 135 137 139 141 267 520 521 522 524 526 1044 1053 6924600 32125372 105667932 109158064 192212084 202506108 214625360 260071380",
"output": "8\n520 521 522 524 526 109158064 202506108 260071380"
},
{
"input": "40\n6 7 10 11 18 19 33 65 129 258 514 515 1026 2049 4741374 8220406 14324390 17172794 17931398 33354714 34796238 38926670 39901570 71292026 72512934 77319030 95372470 102081830 114152702 120215390 133853238 134659386 159128594 165647058 219356350 225884742 236147130 240926050 251729234 263751314",
"output": "13\n2049 4741374 8220406 17172794 17931398 38926670 39901570 77319030 134659386 159128594 219356350 225884742 240926050"
},
{
"input": "1\n536870912",
"output": "1\n536870912"
},
{
"input": "1\n1",
"output": "1\n1"
},
{
"input": "1\n536870911",
"output": "1\n536870911"
},
{
"input": "2\n536870911 536870912",
"output": "1\n536870912"
},
{
"input": "38\n37750369 37750485 37750546 37751012 37751307 37751414 37751958 37751964 37752222 37752448 75497637 75497768 75497771 75498087 75498145 75498177 75498298 75498416 75498457 150994987 150994994 150994999 150995011 150995012 150995015 150995016 150995023 150995040 150995053 805306375 805306377 805306379 805306387 805306389 805306390 805306392 805306396 805306400",
"output": "9\n805306375 805306377 805306379 805306387 805306389 805306390 805306392 805306396 805306400"
},
{
"input": "39\n37749932 37750076 37750391 37750488 37750607 37750812 37750978 37751835 37752173 37752254 75497669 75497829 75497852 75498044 75498061 75498155 75498198 75498341 75498382 75498465 150994988 150994989 150995009 150995019 150995024 150995030 150995031 150995069 150995072 805306369 805306373 805306375 805306379 805306380 805306384 805306387 805306389 805306398 805306400",
"output": "10\n805306369 805306373 805306375 805306379 805306380 805306384 805306387 805306389 805306398 805306400"
}
] | 1,627,640,042 | 3,542 | Python 3 | WRONG_ANSWER | TESTS | 3 | 61 | 6,963,200 | import math
n = int(input())
l = list(map(int,input().split()))
c=d=0
a = []
l.sort(reverse=True)
for i in l:
while i%(math.pow(2,d))==0:
d+=1
if i not in a:
c+=1
a.append(i)
print(c)
print(*a) | Title: Vasily the Bear and Sequence
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vasily the bear has got a sequence of positive integers *a*1,<=*a*2,<=...,<=*a**n*. Vasily the Bear wants to write out several numbers on a piece of paper so that the beauty of the numbers he wrote out was maximum.
The beauty of the written out numbers *b*1,<=*b*2,<=...,<=*b**k* is such maximum non-negative integer *v*, that number *b*1 *and* *b*2 *and* ... *and* *b**k* is divisible by number 2*v* without a remainder. If such number *v* doesn't exist (that is, for any non-negative integer *v*, number *b*1 *and* *b*2 *and* ... *and* *b**k* is divisible by 2*v* without a remainder), the beauty of the written out numbers equals -1.
Tell the bear which numbers he should write out so that the beauty of the written out numbers is maximum. If there are multiple ways to write out the numbers, you need to choose the one where the bear writes out as many numbers as possible.
Here expression *x* *and* *y* means applying the bitwise AND operation to numbers *x* and *y*. In programming languages C++ and Java this operation is represented by "&", in Pascal — by "and".
Input Specification:
The first line contains integer *n* (1<=≤<=*n*<=≤<=105). The second line contains *n* space-separated integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a*1<=<<=*a*2<=<<=...<=<<=*a**n*<=≤<=109).
Output Specification:
In the first line print a single integer *k* (*k*<=><=0), showing how many numbers to write out. In the second line print *k* integers *b*1,<=*b*2,<=...,<=*b**k* — the numbers to write out. You are allowed to print numbers *b*1,<=*b*2,<=...,<=*b**k* in any order, but all of them must be distinct. If there are multiple ways to write out the numbers, choose the one with the maximum number of numbers to write out. If there still are multiple ways, you are allowed to print any of them.
Demo Input:
['5\n1 2 3 4 5\n', '3\n1 2 4\n']
Demo Output:
['2\n4 5\n', '1\n4\n']
Note:
none | ```python
import math
n = int(input())
l = list(map(int,input().split()))
c=d=0
a = []
l.sort(reverse=True)
for i in l:
while i%(math.pow(2,d))==0:
d+=1
if i not in a:
c+=1
a.append(i)
print(c)
print(*a)
``` | 0 |
|
507 | B | Amr and Pins | PROGRAMMING | 1,400 | [
"geometry",
"math"
] | null | null | Amr loves Geometry. One day he came up with a very interesting problem.
Amr has a circle of radius *r* and center in point (*x*,<=*y*). He wants the circle center to be in new position (*x*',<=*y*').
In one step Amr can put a pin to the border of the circle in a certain point, then rotate the circle around that pin by any angle and finally remove the pin.
Help Amr to achieve his goal in minimum number of steps. | Input consists of 5 space-separated integers *r*, *x*, *y*, *x*' *y*' (1<=≤<=*r*<=≤<=105, <=-<=105<=≤<=*x*,<=*y*,<=*x*',<=*y*'<=≤<=105), circle radius, coordinates of original center of the circle and coordinates of destination center of the circle respectively. | Output a single integer — minimum number of steps required to move the center of the circle to the destination point. | [
"2 0 0 0 4\n",
"1 1 1 4 4\n",
"4 5 6 5 6\n"
] | [
"1\n",
"3\n",
"0\n"
] | In the first sample test the optimal way is to put a pin at point (0, 2) and rotate the circle by 180 degrees counter-clockwise (or clockwise, no matter).
<img class="tex-graphics" src="https://espresso.codeforces.com/4e40fd4cc24a2050a0488aa131e6244369328039.png" style="max-width: 100.0%;max-height: 100.0%;"/> | 1,000 | [
{
"input": "2 0 0 0 4",
"output": "1"
},
{
"input": "1 1 1 4 4",
"output": "3"
},
{
"input": "4 5 6 5 6",
"output": "0"
},
{
"input": "10 20 0 40 0",
"output": "1"
},
{
"input": "9 20 0 40 0",
"output": "2"
},
{
"input": "5 -1 -6 -5 1",
"output": "1"
},
{
"input": "99125 26876 -21414 14176 17443",
"output": "1"
},
{
"input": "8066 7339 19155 -90534 -60666",
"output": "8"
},
{
"input": "100000 -100000 -100000 100000 100000",
"output": "2"
},
{
"input": "10 20 0 41 0",
"output": "2"
},
{
"input": "25 -64 -6 -56 64",
"output": "2"
},
{
"input": "125 455 450 439 721",
"output": "2"
},
{
"input": "5 6 3 7 2",
"output": "1"
},
{
"input": "24 130 14786 3147 2140",
"output": "271"
},
{
"input": "125 -363 176 93 330",
"output": "2"
},
{
"input": "1 14 30 30 14",
"output": "12"
},
{
"input": "25 96 13 7 2",
"output": "2"
},
{
"input": "4 100000 -100000 100000 -100000",
"output": "0"
},
{
"input": "1 3 4 2 5",
"output": "1"
},
{
"input": "1 -3 3 2 6",
"output": "3"
},
{
"input": "2 7 20 13 -5",
"output": "7"
},
{
"input": "1 1 1 1 4",
"output": "2"
},
{
"input": "249 -54242 -30537 -45023 -89682",
"output": "121"
},
{
"input": "4 100000 -100000 100000 -99999",
"output": "1"
},
{
"input": "97741 23818 78751 97583 26933",
"output": "1"
},
{
"input": "56767 -29030 51625 79823 -56297",
"output": "2"
},
{
"input": "98260 13729 74998 23701 9253",
"output": "1"
},
{
"input": "67377 -80131 -90254 -57320 14102",
"output": "1"
},
{
"input": "1 100000 100000 100000 -100000",
"output": "100000"
},
{
"input": "19312 19470 82059 58064 62231",
"output": "2"
},
{
"input": "67398 -68747 -79056 -34193 29400",
"output": "1"
},
{
"input": "91099 37184 -71137 75650 -3655",
"output": "1"
},
{
"input": "46456 -2621 -23623 -98302 -99305",
"output": "2"
},
{
"input": "100 100000 -100000 100000 -99999",
"output": "1"
},
{
"input": "1 100000 -100000 100000 -100000",
"output": "0"
},
{
"input": "8 0 0 0 32",
"output": "2"
},
{
"input": "100000 100000 1 -100000 0",
"output": "2"
}
] | 1,558,280,225 | 2,147,483,647 | Python 3 | OK | TESTS | 37 | 109 | 0 | import math
r, x, y, x1, y1 = map(int, input().split())
print(math.ceil(math.sqrt((x-x1)**2 + (y-y1)**2)/(2*r)))
| Title: Amr and Pins
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Amr loves Geometry. One day he came up with a very interesting problem.
Amr has a circle of radius *r* and center in point (*x*,<=*y*). He wants the circle center to be in new position (*x*',<=*y*').
In one step Amr can put a pin to the border of the circle in a certain point, then rotate the circle around that pin by any angle and finally remove the pin.
Help Amr to achieve his goal in minimum number of steps.
Input Specification:
Input consists of 5 space-separated integers *r*, *x*, *y*, *x*' *y*' (1<=≤<=*r*<=≤<=105, <=-<=105<=≤<=*x*,<=*y*,<=*x*',<=*y*'<=≤<=105), circle radius, coordinates of original center of the circle and coordinates of destination center of the circle respectively.
Output Specification:
Output a single integer — minimum number of steps required to move the center of the circle to the destination point.
Demo Input:
['2 0 0 0 4\n', '1 1 1 4 4\n', '4 5 6 5 6\n']
Demo Output:
['1\n', '3\n', '0\n']
Note:
In the first sample test the optimal way is to put a pin at point (0, 2) and rotate the circle by 180 degrees counter-clockwise (or clockwise, no matter).
<img class="tex-graphics" src="https://espresso.codeforces.com/4e40fd4cc24a2050a0488aa131e6244369328039.png" style="max-width: 100.0%;max-height: 100.0%;"/> | ```python
import math
r, x, y, x1, y1 = map(int, input().split())
print(math.ceil(math.sqrt((x-x1)**2 + (y-y1)**2)/(2*r)))
``` | 3 |
|
686 | A | Free Ice Cream | PROGRAMMING | 800 | [
"constructive algorithms",
"implementation"
] | null | null | After their adventure with the magic mirror Kay and Gerda have returned home and sometimes give free ice cream to kids in the summer.
At the start of the day they have *x* ice cream packs. Since the ice cream is free, people start standing in the queue before Kay and Gerda's house even in the night. Each person in the queue wants either to take several ice cream packs for himself and his friends or to give several ice cream packs to Kay and Gerda (carriers that bring ice cream have to stand in the same queue).
If a carrier with *d* ice cream packs comes to the house, then Kay and Gerda take all his packs. If a child who wants to take *d* ice cream packs comes to the house, then Kay and Gerda will give him *d* packs if they have enough ice cream, otherwise the child will get no ice cream at all and will leave in distress.
Kay wants to find the amount of ice cream they will have after all people will leave from the queue, and Gerda wants to find the number of distressed kids. | The first line contains two space-separated integers *n* and *x* (1<=≤<=*n*<=≤<=1000, 0<=≤<=*x*<=≤<=109).
Each of the next *n* lines contains a character '+' or '-', and an integer *d**i*, separated by a space (1<=≤<=*d**i*<=≤<=109). Record "+ *d**i*" in *i*-th line means that a carrier with *d**i* ice cream packs occupies *i*-th place from the start of the queue, and record "- *d**i*" means that a child who wants to take *d**i* packs stands in *i*-th place. | Print two space-separated integers — number of ice cream packs left after all operations, and number of kids that left the house in distress. | [
"5 7\n+ 5\n- 10\n- 20\n+ 40\n- 20\n",
"5 17\n- 16\n- 2\n- 98\n+ 100\n- 98\n"
] | [
"22 1\n",
"3 2\n"
] | Consider the first sample.
1. Initially Kay and Gerda have 7 packs of ice cream. 1. Carrier brings 5 more, so now they have 12 packs. 1. A kid asks for 10 packs and receives them. There are only 2 packs remaining. 1. Another kid asks for 20 packs. Kay and Gerda do not have them, so the kid goes away distressed. 1. Carrier bring 40 packs, now Kay and Gerda have 42 packs. 1. Kid asks for 20 packs and receives them. There are 22 packs remaining. | 500 | [
{
"input": "5 7\n+ 5\n- 10\n- 20\n+ 40\n- 20",
"output": "22 1"
},
{
"input": "5 17\n- 16\n- 2\n- 98\n+ 100\n- 98",
"output": "3 2"
},
{
"input": "6 1000000000\n+ 1000000000\n+ 1000000000\n+ 1000000000\n+ 1000000000\n+ 1000000000\n+ 1000000000",
"output": "7000000000 0"
},
{
"input": "5 12\n- 12\n+ 7\n- 6\n- 1\n+ 46",
"output": "46 0"
},
{
"input": "11 1000\n- 100\n+ 100\n+ 100\n+ 100\n+ 100\n- 100\n- 100\n- 100\n- 100\n- 100\n- 100",
"output": "700 0"
},
{
"input": "1 0\n- 526403222",
"output": "0 1"
},
{
"input": "1 897986543\n- 371188251",
"output": "526798292 0"
},
{
"input": "1 0\n+ 1",
"output": "1 0"
},
{
"input": "1 0\n- 1",
"output": "0 1"
},
{
"input": "1 10\n+ 10",
"output": "20 0"
},
{
"input": "1 3\n- 5",
"output": "3 1"
},
{
"input": "1 0\n- 5",
"output": "0 1"
},
{
"input": "1 0\n+ 5",
"output": "5 0"
}
] | 1,595,099,463 | 2,147,483,647 | Python 3 | OK | TESTS | 34 | 109 | 6,758,400 |
n,x = map(int,input().split())
count=0
for _ in range(n):
c,v = input().split()
v=int(v)
if(c=='+'):
x=x+v
if(c=='-'):
if(v<=x):
x=x-v
else:
count += 1
print(x,count) | Title: Free Ice Cream
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
After their adventure with the magic mirror Kay and Gerda have returned home and sometimes give free ice cream to kids in the summer.
At the start of the day they have *x* ice cream packs. Since the ice cream is free, people start standing in the queue before Kay and Gerda's house even in the night. Each person in the queue wants either to take several ice cream packs for himself and his friends or to give several ice cream packs to Kay and Gerda (carriers that bring ice cream have to stand in the same queue).
If a carrier with *d* ice cream packs comes to the house, then Kay and Gerda take all his packs. If a child who wants to take *d* ice cream packs comes to the house, then Kay and Gerda will give him *d* packs if they have enough ice cream, otherwise the child will get no ice cream at all and will leave in distress.
Kay wants to find the amount of ice cream they will have after all people will leave from the queue, and Gerda wants to find the number of distressed kids.
Input Specification:
The first line contains two space-separated integers *n* and *x* (1<=≤<=*n*<=≤<=1000, 0<=≤<=*x*<=≤<=109).
Each of the next *n* lines contains a character '+' or '-', and an integer *d**i*, separated by a space (1<=≤<=*d**i*<=≤<=109). Record "+ *d**i*" in *i*-th line means that a carrier with *d**i* ice cream packs occupies *i*-th place from the start of the queue, and record "- *d**i*" means that a child who wants to take *d**i* packs stands in *i*-th place.
Output Specification:
Print two space-separated integers — number of ice cream packs left after all operations, and number of kids that left the house in distress.
Demo Input:
['5 7\n+ 5\n- 10\n- 20\n+ 40\n- 20\n', '5 17\n- 16\n- 2\n- 98\n+ 100\n- 98\n']
Demo Output:
['22 1\n', '3 2\n']
Note:
Consider the first sample.
1. Initially Kay and Gerda have 7 packs of ice cream. 1. Carrier brings 5 more, so now they have 12 packs. 1. A kid asks for 10 packs and receives them. There are only 2 packs remaining. 1. Another kid asks for 20 packs. Kay and Gerda do not have them, so the kid goes away distressed. 1. Carrier bring 40 packs, now Kay and Gerda have 42 packs. 1. Kid asks for 20 packs and receives them. There are 22 packs remaining. | ```python
n,x = map(int,input().split())
count=0
for _ in range(n):
c,v = input().split()
v=int(v)
if(c=='+'):
x=x+v
if(c=='-'):
if(v<=x):
x=x-v
else:
count += 1
print(x,count)
``` | 3 |
|
25 | A | IQ test | PROGRAMMING | 1,300 | [
"brute force"
] | A. IQ test | 2 | 256 | Bob is preparing to pass IQ test. The most frequent task in this test is to find out which one of the given *n* numbers differs from the others. Bob observed that one number usually differs from the others in evenness. Help Bob — to check his answers, he needs a program that among the given *n* numbers finds one that is different in evenness. | The first line contains integer *n* (3<=≤<=*n*<=≤<=100) — amount of numbers in the task. The second line contains *n* space-separated natural numbers, not exceeding 100. It is guaranteed, that exactly one of these numbers differs from the others in evenness. | Output index of number that differs from the others in evenness. Numbers are numbered from 1 in the input order. | [
"5\n2 4 7 8 10\n",
"4\n1 2 1 1\n"
] | [
"3\n",
"2\n"
] | none | 0 | [
{
"input": "5\n2 4 7 8 10",
"output": "3"
},
{
"input": "4\n1 2 1 1",
"output": "2"
},
{
"input": "3\n1 2 2",
"output": "1"
},
{
"input": "3\n100 99 100",
"output": "2"
},
{
"input": "3\n5 3 2",
"output": "3"
},
{
"input": "4\n43 28 1 91",
"output": "2"
},
{
"input": "4\n75 13 94 77",
"output": "3"
},
{
"input": "4\n97 8 27 3",
"output": "2"
},
{
"input": "10\n95 51 12 91 85 3 1 31 25 7",
"output": "3"
},
{
"input": "20\n88 96 66 51 14 88 2 92 18 72 18 88 20 30 4 82 90 100 24 46",
"output": "4"
},
{
"input": "30\n20 94 56 50 10 98 52 32 14 22 24 60 4 8 98 46 34 68 82 82 98 90 50 20 78 49 52 94 64 36",
"output": "26"
},
{
"input": "50\n79 27 77 57 37 45 27 49 65 33 57 21 71 19 75 85 65 61 23 97 85 9 23 1 9 3 99 77 77 21 79 69 15 37 15 7 93 81 13 89 91 31 45 93 15 97 55 80 85 83",
"output": "48"
},
{
"input": "60\n46 11 73 65 3 69 3 53 43 53 97 47 55 93 31 75 35 3 9 73 23 31 3 81 91 79 61 21 15 11 11 11 81 7 83 75 39 87 83 59 89 55 93 27 49 67 67 29 1 93 11 17 9 19 35 21 63 31 31 25",
"output": "1"
},
{
"input": "70\n28 42 42 92 64 54 22 38 38 78 62 38 4 38 14 66 4 92 66 58 94 26 4 44 41 88 48 82 44 26 74 44 48 4 16 92 34 38 26 64 94 4 30 78 50 54 12 90 8 16 80 98 28 100 74 50 36 42 92 18 76 98 8 22 2 50 58 50 64 46",
"output": "25"
},
{
"input": "100\n43 35 79 53 13 91 91 45 65 83 57 9 42 39 85 45 71 51 61 59 31 13 63 39 25 21 79 39 91 67 21 61 97 75 93 83 29 79 59 97 11 37 63 51 39 55 91 23 21 17 47 23 35 75 49 5 69 99 5 7 41 17 25 89 15 79 21 63 53 81 43 91 59 91 69 99 85 15 91 51 49 37 65 7 89 81 21 93 61 63 97 93 45 17 13 69 57 25 75 73",
"output": "13"
},
{
"input": "100\n50 24 68 60 70 30 52 22 18 74 68 98 20 82 4 46 26 68 100 78 84 58 74 98 38 88 68 86 64 80 82 100 20 22 98 98 52 6 94 10 48 68 2 18 38 22 22 82 44 20 66 72 36 58 64 6 36 60 4 96 76 64 12 90 10 58 64 60 74 28 90 26 24 60 40 58 2 16 76 48 58 36 82 60 24 44 4 78 28 38 8 12 40 16 38 6 66 24 31 76",
"output": "99"
},
{
"input": "100\n47 48 94 48 14 18 94 36 96 22 12 30 94 20 48 98 40 58 2 94 8 36 98 18 98 68 2 60 76 38 18 100 8 72 100 68 2 86 92 72 58 16 48 14 6 58 72 76 6 88 80 66 20 28 74 62 86 68 90 86 2 56 34 38 56 90 4 8 76 44 32 86 12 98 38 34 54 92 70 94 10 24 82 66 90 58 62 2 32 58 100 22 58 72 2 22 68 72 42 14",
"output": "1"
},
{
"input": "99\n38 20 68 60 84 16 28 88 60 48 80 28 4 92 70 60 46 46 20 34 12 100 76 2 40 10 8 86 6 80 50 66 12 34 14 28 26 70 46 64 34 96 10 90 98 96 56 88 50 74 70 94 2 94 24 66 68 46 22 30 6 10 64 32 88 14 98 100 64 58 50 18 50 50 8 38 8 16 54 2 60 54 62 84 92 98 4 72 66 26 14 88 99 16 10 6 88 56 22",
"output": "93"
},
{
"input": "99\n50 83 43 89 53 47 69 1 5 37 63 87 95 15 55 95 75 89 33 53 89 75 93 75 11 85 49 29 11 97 49 67 87 11 25 37 97 73 67 49 87 43 53 97 43 29 53 33 45 91 37 73 39 49 59 5 21 43 87 35 5 63 89 57 63 47 29 99 19 85 13 13 3 13 43 19 5 9 61 51 51 57 15 89 13 97 41 13 99 79 13 27 97 95 73 33 99 27 23",
"output": "1"
},
{
"input": "98\n61 56 44 30 58 14 20 24 88 28 46 56 96 52 58 42 94 50 46 30 46 80 72 88 68 16 6 60 26 90 10 98 76 20 56 40 30 16 96 20 88 32 62 30 74 58 36 76 60 4 24 36 42 54 24 92 28 14 2 74 86 90 14 52 34 82 40 76 8 64 2 56 10 8 78 16 70 86 70 42 70 74 22 18 76 98 88 28 62 70 36 72 20 68 34 48 80 98",
"output": "1"
},
{
"input": "98\n66 26 46 42 78 32 76 42 26 82 8 12 4 10 24 26 64 44 100 46 94 64 30 18 88 28 8 66 30 82 82 28 74 52 62 80 80 60 94 86 64 32 44 88 92 20 12 74 94 28 34 58 4 22 16 10 94 76 82 58 40 66 22 6 30 32 92 54 16 76 74 98 18 48 48 30 92 2 16 42 84 74 30 60 64 52 50 26 16 86 58 96 79 60 20 62 82 94",
"output": "93"
},
{
"input": "95\n9 31 27 93 17 77 75 9 9 53 89 39 51 99 5 1 11 39 27 49 91 17 27 79 81 71 37 75 35 13 93 4 99 55 85 11 23 57 5 43 5 61 15 35 23 91 3 81 99 85 43 37 39 27 5 67 7 33 75 59 13 71 51 27 15 93 51 63 91 53 43 99 25 47 17 71 81 15 53 31 59 83 41 23 73 25 91 91 13 17 25 13 55 57 29",
"output": "32"
},
{
"input": "100\n91 89 81 45 53 1 41 3 77 93 55 97 55 97 87 27 69 95 73 41 93 21 75 35 53 56 5 51 87 59 91 67 33 3 99 45 83 17 97 47 75 97 7 89 17 99 23 23 81 25 55 97 27 35 69 5 77 35 93 19 55 59 37 21 31 37 49 41 91 53 73 69 7 37 37 39 17 71 7 97 55 17 47 23 15 73 31 39 57 37 9 5 61 41 65 57 77 79 35 47",
"output": "26"
},
{
"input": "99\n38 56 58 98 80 54 26 90 14 16 78 92 52 74 40 30 84 14 44 80 16 90 98 68 26 24 78 72 42 16 84 40 14 44 2 52 50 2 12 96 58 66 8 80 44 52 34 34 72 98 74 4 66 74 56 21 8 38 76 40 10 22 48 32 98 34 12 62 80 68 64 82 22 78 58 74 20 22 48 56 12 38 32 72 6 16 74 24 94 84 26 38 18 24 76 78 98 94 72",
"output": "56"
},
{
"input": "100\n44 40 6 40 56 90 98 8 36 64 76 86 98 76 36 92 6 30 98 70 24 98 96 60 24 82 88 68 86 96 34 42 58 10 40 26 56 10 88 58 70 32 24 28 14 82 52 12 62 36 70 60 52 34 74 30 78 76 10 16 42 94 66 90 70 38 52 12 58 22 98 96 14 68 24 70 4 30 84 98 8 50 14 52 66 34 100 10 28 100 56 48 38 12 38 14 91 80 70 86",
"output": "97"
},
{
"input": "100\n96 62 64 20 90 46 56 90 68 36 30 56 70 28 16 64 94 34 6 32 34 50 94 22 90 32 40 2 72 10 88 38 28 92 20 26 56 80 4 100 100 90 16 74 74 84 8 2 30 20 80 32 16 46 92 56 42 12 96 64 64 42 64 58 50 42 74 28 2 4 36 32 70 50 54 92 70 16 45 76 28 16 18 50 48 2 62 94 4 12 52 52 4 100 70 60 82 62 98 42",
"output": "79"
},
{
"input": "99\n14 26 34 68 90 58 50 36 8 16 18 6 2 74 54 20 36 84 32 50 52 2 26 24 3 64 20 10 54 26 66 44 28 72 4 96 78 90 96 86 68 28 94 4 12 46 100 32 22 36 84 32 44 94 76 94 4 52 12 30 74 4 34 64 58 72 44 16 70 56 54 8 14 74 8 6 58 62 98 54 14 40 80 20 36 72 28 98 20 58 40 52 90 64 22 48 54 70 52",
"output": "25"
},
{
"input": "95\n82 86 30 78 6 46 80 66 74 72 16 24 18 52 52 38 60 36 86 26 62 28 22 46 96 26 94 84 20 46 66 88 76 32 12 86 74 18 34 88 4 48 94 6 58 6 100 82 4 24 88 32 54 98 34 48 6 76 42 88 42 28 100 4 22 2 10 66 82 54 98 20 60 66 38 98 32 47 86 58 6 100 12 46 2 42 8 84 78 28 24 70 34 28 86",
"output": "78"
},
{
"input": "90\n40 50 8 42 76 24 58 42 26 68 20 48 54 12 34 84 14 36 32 88 6 50 96 56 20 92 48 16 40 34 96 46 20 84 30 50 20 98 8 44 96 42 8 76 70 38 84 30 40 88 84 72 2 22 52 58 16 62 100 66 80 40 50 32 14 62 88 72 22 99 76 50 84 82 8 82 98 46 26 40 2 98 18 78 30 72 70 18 34 68",
"output": "70"
},
{
"input": "80\n81 43 87 1 55 43 53 61 27 19 43 13 89 9 33 83 75 55 97 71 91 37 95 5 21 69 81 93 95 69 31 83 55 7 97 7 79 57 8 61 27 85 49 1 15 97 63 79 29 73 41 85 5 41 31 93 67 11 63 59 15 99 91 77 43 69 23 23 81 73 19 1 67 51 1 75 99 67 3 81",
"output": "39"
},
{
"input": "98\n13 83 61 27 35 1 85 95 97 73 95 65 73 45 5 43 27 83 91 19 11 3 85 59 9 39 69 23 45 7 51 85 5 71 5 95 1 51 75 3 43 57 3 11 33 71 21 99 47 41 87 39 71 87 31 85 91 49 83 5 49 85 47 91 55 99 33 23 31 23 23 73 29 77 55 31 25 5 81 49 91 15 15 39 87 5 9 40 69 47 29 33 11 21 49 79 51 83",
"output": "88"
},
{
"input": "3\n100 100 1",
"output": "3"
}
] | 1,644,814,193 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 92 | 0 | for t in range(int(input())):
a=list(map(int,input().split()))
even=0
evencount=0
oddcount=0
for i in range(len(a)):
if a[i]%2==0:
even=i
evencount+=1
else:
odd=i
oddcount+=1
if evencount>oddcount:
print(odd+1)
else:
print(even+1) | Title: IQ test
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Bob is preparing to pass IQ test. The most frequent task in this test is to find out which one of the given *n* numbers differs from the others. Bob observed that one number usually differs from the others in evenness. Help Bob — to check his answers, he needs a program that among the given *n* numbers finds one that is different in evenness.
Input Specification:
The first line contains integer *n* (3<=≤<=*n*<=≤<=100) — amount of numbers in the task. The second line contains *n* space-separated natural numbers, not exceeding 100. It is guaranteed, that exactly one of these numbers differs from the others in evenness.
Output Specification:
Output index of number that differs from the others in evenness. Numbers are numbered from 1 in the input order.
Demo Input:
['5\n2 4 7 8 10\n', '4\n1 2 1 1\n']
Demo Output:
['3\n', '2\n']
Note:
none | ```python
for t in range(int(input())):
a=list(map(int,input().split()))
even=0
evencount=0
oddcount=0
for i in range(len(a)):
if a[i]%2==0:
even=i
evencount+=1
else:
odd=i
oddcount+=1
if evencount>oddcount:
print(odd+1)
else:
print(even+1)
``` | -1 |
854 | A | Fraction | PROGRAMMING | 800 | [
"brute force",
"constructive algorithms",
"math"
] | null | null | Petya is a big fan of mathematics, especially its part related to fractions. Recently he learned that a fraction is called proper iff its numerator is smaller than its denominator (*a*<=<<=*b*) and that the fraction is called irreducible if its numerator and its denominator are coprime (they do not have positive common divisors except 1).
During his free time, Petya thinks about proper irreducible fractions and converts them to decimals using the calculator. One day he mistakenly pressed addition button (<=+<=) instead of division button (÷) and got sum of numerator and denominator that was equal to *n* instead of the expected decimal notation.
Petya wanted to restore the original fraction, but soon he realized that it might not be done uniquely. That's why he decided to determine maximum possible proper irreducible fraction such that sum of its numerator and denominator equals *n*. Help Petya deal with this problem. | In the only line of input there is an integer *n* (3<=≤<=*n*<=≤<=1000), the sum of numerator and denominator of the fraction. | Output two space-separated positive integers *a* and *b*, numerator and denominator of the maximum possible proper irreducible fraction satisfying the given sum. | [
"3\n",
"4\n",
"12\n"
] | [
"1 2\n",
"1 3\n",
"5 7\n"
] | none | 500 | [
{
"input": "3",
"output": "1 2"
},
{
"input": "4",
"output": "1 3"
},
{
"input": "12",
"output": "5 7"
},
{
"input": "34",
"output": "15 19"
},
{
"input": "13",
"output": "6 7"
},
{
"input": "11",
"output": "5 6"
},
{
"input": "24",
"output": "11 13"
},
{
"input": "17",
"output": "8 9"
},
{
"input": "10",
"output": "3 7"
},
{
"input": "69",
"output": "34 35"
},
{
"input": "100",
"output": "49 51"
},
{
"input": "57",
"output": "28 29"
},
{
"input": "1000",
"output": "499 501"
},
{
"input": "999",
"output": "499 500"
},
{
"input": "998",
"output": "497 501"
},
{
"input": "997",
"output": "498 499"
},
{
"input": "996",
"output": "497 499"
},
{
"input": "995",
"output": "497 498"
},
{
"input": "994",
"output": "495 499"
},
{
"input": "5",
"output": "2 3"
},
{
"input": "6",
"output": "1 5"
},
{
"input": "8",
"output": "3 5"
},
{
"input": "9",
"output": "4 5"
},
{
"input": "423",
"output": "211 212"
},
{
"input": "876",
"output": "437 439"
},
{
"input": "29",
"output": "14 15"
}
] | 1,505,300,205 | 1,305 | Python 3 | WRONG_ANSWER | TESTS | 3 | 61 | 0 | n = int(input())
def easyest(a, b):
while a != 0 and b != 0:
if a > b:
a %= b
else:
b %= a
if (a + b) == 1:
return True
else:
return False
x = 0
for j in range(n, 1, -1):
if easyest(n - j, j):
if (n - j) / j > x:
xx = j
x = (n - j) / j
print(min(xx, n - xx), max(xx, n - xx)) | Title: Fraction
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Petya is a big fan of mathematics, especially its part related to fractions. Recently he learned that a fraction is called proper iff its numerator is smaller than its denominator (*a*<=<<=*b*) and that the fraction is called irreducible if its numerator and its denominator are coprime (they do not have positive common divisors except 1).
During his free time, Petya thinks about proper irreducible fractions and converts them to decimals using the calculator. One day he mistakenly pressed addition button (<=+<=) instead of division button (÷) and got sum of numerator and denominator that was equal to *n* instead of the expected decimal notation.
Petya wanted to restore the original fraction, but soon he realized that it might not be done uniquely. That's why he decided to determine maximum possible proper irreducible fraction such that sum of its numerator and denominator equals *n*. Help Petya deal with this problem.
Input Specification:
In the only line of input there is an integer *n* (3<=≤<=*n*<=≤<=1000), the sum of numerator and denominator of the fraction.
Output Specification:
Output two space-separated positive integers *a* and *b*, numerator and denominator of the maximum possible proper irreducible fraction satisfying the given sum.
Demo Input:
['3\n', '4\n', '12\n']
Demo Output:
['1 2\n', '1 3\n', '5 7\n']
Note:
none | ```python
n = int(input())
def easyest(a, b):
while a != 0 and b != 0:
if a > b:
a %= b
else:
b %= a
if (a + b) == 1:
return True
else:
return False
x = 0
for j in range(n, 1, -1):
if easyest(n - j, j):
if (n - j) / j > x:
xx = j
x = (n - j) / j
print(min(xx, n - xx), max(xx, n - xx))
``` | 0 |
|
231 | A | Team | PROGRAMMING | 800 | [
"brute force",
"greedy"
] | null | null | One day three best friends Petya, Vasya and Tonya decided to form a team and take part in programming contests. Participants are usually offered several problems during programming contests. Long before the start the friends decided that they will implement a problem if at least two of them are sure about the solution. Otherwise, the friends won't write the problem's solution.
This contest offers *n* problems to the participants. For each problem we know, which friend is sure about the solution. Help the friends find the number of problems for which they will write a solution. | The first input line contains a single integer *n* (1<=≤<=*n*<=≤<=1000) — the number of problems in the contest. Then *n* lines contain three integers each, each integer is either 0 or 1. If the first number in the line equals 1, then Petya is sure about the problem's solution, otherwise he isn't sure. The second number shows Vasya's view on the solution, the third number shows Tonya's view. The numbers on the lines are separated by spaces. | Print a single integer — the number of problems the friends will implement on the contest. | [
"3\n1 1 0\n1 1 1\n1 0 0\n",
"2\n1 0 0\n0 1 1\n"
] | [
"2\n",
"1\n"
] | In the first sample Petya and Vasya are sure that they know how to solve the first problem and all three of them know how to solve the second problem. That means that they will write solutions for these problems. Only Petya is sure about the solution for the third problem, but that isn't enough, so the friends won't take it.
In the second sample the friends will only implement the second problem, as Vasya and Tonya are sure about the solution. | 500 | [
{
"input": "3\n1 1 0\n1 1 1\n1 0 0",
"output": "2"
},
{
"input": "2\n1 0 0\n0 1 1",
"output": "1"
},
{
"input": "1\n1 0 0",
"output": "0"
},
{
"input": "2\n1 0 0\n1 1 1",
"output": "1"
},
{
"input": "5\n1 0 0\n0 1 0\n1 1 1\n0 0 1\n0 0 0",
"output": "1"
},
{
"input": "10\n0 1 0\n0 1 0\n1 1 0\n1 0 0\n0 0 1\n0 1 1\n1 1 1\n1 1 0\n0 0 0\n0 0 0",
"output": "4"
},
{
"input": "15\n0 1 0\n1 0 0\n1 1 0\n1 1 1\n0 1 0\n0 0 1\n1 0 1\n1 0 1\n1 0 1\n0 0 0\n1 1 1\n1 1 0\n0 1 1\n1 1 0\n1 1 1",
"output": "10"
},
{
"input": "50\n0 0 0\n0 1 1\n1 1 1\n0 1 0\n1 0 1\n1 1 1\n0 0 1\n1 0 0\n1 1 0\n1 0 1\n0 1 0\n0 0 1\n1 1 0\n0 1 0\n1 1 0\n0 0 0\n1 1 1\n1 0 1\n0 0 1\n1 1 0\n1 1 1\n0 1 1\n1 1 0\n0 0 0\n0 0 0\n1 1 1\n0 0 0\n1 1 1\n0 1 1\n0 0 1\n0 0 0\n0 0 0\n1 1 0\n1 1 0\n1 0 1\n1 0 0\n1 0 1\n1 0 1\n0 1 1\n1 1 0\n1 1 0\n0 1 0\n1 0 1\n0 0 0\n0 0 0\n0 0 0\n0 0 1\n1 1 1\n0 1 1\n1 0 1",
"output": "29"
},
{
"input": "1\n1 1 1",
"output": "1"
},
{
"input": "8\n0 0 0\n0 0 1\n0 0 0\n0 1 1\n1 0 0\n1 0 1\n1 1 0\n1 1 1",
"output": "4"
},
{
"input": "16\n1 1 1\n1 1 1\n1 1 1\n1 1 1\n1 1 1\n1 1 1\n1 1 1\n1 1 1\n1 1 1\n1 1 1\n1 1 1\n1 1 1\n1 1 1\n1 1 1\n1 1 1\n1 1 1",
"output": "16"
}
] | 1,697,712,626 | 2,147,483,647 | Python 3 | OK | TESTS | 21 | 92 | 0 | n = int(input())
count = 0
for i in range(n):
m = list(map(int,input().split()))
k = m.count(1)
if k >= 2:
count += 1
print(count) | Title: Team
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
One day three best friends Petya, Vasya and Tonya decided to form a team and take part in programming contests. Participants are usually offered several problems during programming contests. Long before the start the friends decided that they will implement a problem if at least two of them are sure about the solution. Otherwise, the friends won't write the problem's solution.
This contest offers *n* problems to the participants. For each problem we know, which friend is sure about the solution. Help the friends find the number of problems for which they will write a solution.
Input Specification:
The first input line contains a single integer *n* (1<=≤<=*n*<=≤<=1000) — the number of problems in the contest. Then *n* lines contain three integers each, each integer is either 0 or 1. If the first number in the line equals 1, then Petya is sure about the problem's solution, otherwise he isn't sure. The second number shows Vasya's view on the solution, the third number shows Tonya's view. The numbers on the lines are separated by spaces.
Output Specification:
Print a single integer — the number of problems the friends will implement on the contest.
Demo Input:
['3\n1 1 0\n1 1 1\n1 0 0\n', '2\n1 0 0\n0 1 1\n']
Demo Output:
['2\n', '1\n']
Note:
In the first sample Petya and Vasya are sure that they know how to solve the first problem and all three of them know how to solve the second problem. That means that they will write solutions for these problems. Only Petya is sure about the solution for the third problem, but that isn't enough, so the friends won't take it.
In the second sample the friends will only implement the second problem, as Vasya and Tonya are sure about the solution. | ```python
n = int(input())
count = 0
for i in range(n):
m = list(map(int,input().split()))
k = m.count(1)
if k >= 2:
count += 1
print(count)
``` | 3 |
|
75 | C | Modified GCD | PROGRAMMING | 1,600 | [
"binary search",
"number theory"
] | C. Modified GCD | 2 | 256 | Well, here is another math class task. In mathematics, GCD is the greatest common divisor, and it's an easy task to calculate the GCD between two positive integers.
A common divisor for two positive numbers is a number which both numbers are divisible by.
But your teacher wants to give you a harder task, in this task you have to find the greatest common divisor *d* between two integers *a* and *b* that is in a given range from *low* to *high* (inclusive), i.e. *low*<=≤<=*d*<=≤<=*high*. It is possible that there is no common divisor in the given range.
You will be given the two integers *a* and *b*, then *n* queries. Each query is a range from *low* to *high* and you have to answer each query. | The first line contains two integers *a* and *b*, the two integers as described above (1<=≤<=*a*,<=*b*<=≤<=109). The second line contains one integer *n*, the number of queries (1<=≤<=*n*<=≤<=104). Then *n* lines follow, each line contains one query consisting of two integers, *low* and *high* (1<=≤<=*low*<=≤<=*high*<=≤<=109). | Print *n* lines. The *i*-th of them should contain the result of the *i*-th query in the input. If there is no common divisor in the given range for any query, you should print -1 as a result for this query. | [
"9 27\n3\n1 5\n10 11\n9 11\n"
] | [
"3\n-1\n9\n"
] | none | 1,500 | [
{
"input": "9 27\n3\n1 5\n10 11\n9 11",
"output": "3\n-1\n9"
},
{
"input": "48 72\n2\n8 29\n29 37",
"output": "24\n-1"
},
{
"input": "90 100\n10\n51 61\n6 72\n1 84\n33 63\n37 69\n18 21\n9 54\n49 90\n14 87\n37 90",
"output": "-1\n10\n10\n-1\n-1\n-1\n10\n-1\n-1\n-1"
},
{
"input": "84 36\n1\n18 32",
"output": "-1"
},
{
"input": "90 36\n16\n13 15\n5 28\n11 30\n26 35\n2 8\n19 36\n3 17\n5 14\n4 26\n22 33\n16 33\n18 27\n4 17\n1 2\n29 31\n18 36",
"output": "-1\n18\n18\n-1\n6\n-1\n9\n9\n18\n-1\n18\n18\n9\n2\n-1\n18"
},
{
"input": "84 90\n18\n10 75\n2 40\n30 56\n49 62\n19 33\n5 79\n61 83\n13 56\n73 78\n1 18\n23 35\n14 72\n22 33\n1 21\n8 38\n54 82\n6 80\n57 75",
"output": "-1\n6\n-1\n-1\n-1\n6\n-1\n-1\n-1\n6\n-1\n-1\n-1\n6\n-1\n-1\n6\n-1"
},
{
"input": "84 100\n16\n10 64\n3 61\n19 51\n42 67\n51 68\n12 40\n10 47\n52 53\n37 67\n2 26\n23 47\n17 75\n49 52\n3 83\n63 81\n8 43",
"output": "-1\n4\n-1\n-1\n-1\n-1\n-1\n-1\n-1\n4\n-1\n-1\n-1\n4\n-1\n-1"
},
{
"input": "36 60\n2\n17 25\n16 20",
"output": "-1\n-1"
},
{
"input": "90 100\n8\n55 75\n46 68\n44 60\n32 71\n43 75\n23 79\n47 86\n11 57",
"output": "-1\n-1\n-1\n-1\n-1\n-1\n-1\n-1"
},
{
"input": "90 36\n8\n1 19\n10 12\n14 28\n21 24\n8 8\n33 34\n10 26\n15 21",
"output": "18\n-1\n18\n-1\n-1\n-1\n18\n18"
},
{
"input": "48 80\n19\n1 1\n16 16\n1 16\n16 48\n16 80\n16 1000000000\n1000000000 1000000000\n1 1000000000\n500000000 1000000000\n15 17\n17 17\n15 15\n8 8\n8 15\n8 16\n8 17\n7 17\n7 15\n9 15",
"output": "1\n16\n16\n16\n16\n16\n-1\n16\n-1\n16\n-1\n-1\n8\n8\n16\n16\n16\n8\n-1"
},
{
"input": "31607 999002449\n18\n31607 31607\n31606 31608\n31607 31608\n31606 31607\n31606 31606\n31608 31608\n1 31607\n1 31606\n1 31608\n1 1000000000\n31607 1000000000\n31606 1000000000\n31608 1000000000\n1000000000 1000000000\n1 1\n2 31606\n2 31607\n2 31608",
"output": "31607\n31607\n31607\n31607\n-1\n-1\n31607\n1\n31607\n31607\n31607\n31607\n-1\n-1\n1\n-1\n31607\n31607"
},
{
"input": "999999937 999999929\n12\n999999929 999999937\n1 1\n1 1000000000\n2 1000000000\n1 2\n999999937 999999937\n999999929 999999929\n2 2\n3 3\n1 100\n1 999999937\n1 999999929",
"output": "-1\n1\n1\n-1\n1\n-1\n-1\n-1\n-1\n1\n1\n1"
}
] | 1,539,538,075 | 2,147,483,647 | Python 3 | OK | TESTS | 60 | 592 | 614,400 | def gcd(a,b):
while a>0:
x=a
a=b%a
b=x
return(x)
def Bsearch1(L,x):
beg=0
last=len(L)-1
while beg<=last:
mid=(beg+last)//2
if x==L[mid]:
return(mid)
elif(x>L[mid]):
beg=mid+1
else:
last=mid-1
else:
return(beg)
def Bsearch2(L,x):
beg=0
last=len(L)-1
while beg<=last:
mid=(beg+last)//2
if x==L[mid]:
return(mid)
elif(x>L[mid]):
beg=mid+1
else:
last=mid-1
else:
return(last)
a,b=input().split()
a,b=[int(a),int(b)]
x=gcd(a,b)
from functools import reduce
def factors(n):
x=set(reduce(list.__add__,
([i, n//i] for i in range(1, int(n**0.5) + 1) if n % i == 0)))
return(list(x))
div=factors(x)
div.sort()
y=int(input())
for j in range(y):
c,d=input().split()
c,d=[int(c),int(d)]
f=Bsearch1(div,c)
g=Bsearch2(div,d)
if f>g:
print(-1)
else:
print(div[g])
| Title: Modified GCD
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Well, here is another math class task. In mathematics, GCD is the greatest common divisor, and it's an easy task to calculate the GCD between two positive integers.
A common divisor for two positive numbers is a number which both numbers are divisible by.
But your teacher wants to give you a harder task, in this task you have to find the greatest common divisor *d* between two integers *a* and *b* that is in a given range from *low* to *high* (inclusive), i.e. *low*<=≤<=*d*<=≤<=*high*. It is possible that there is no common divisor in the given range.
You will be given the two integers *a* and *b*, then *n* queries. Each query is a range from *low* to *high* and you have to answer each query.
Input Specification:
The first line contains two integers *a* and *b*, the two integers as described above (1<=≤<=*a*,<=*b*<=≤<=109). The second line contains one integer *n*, the number of queries (1<=≤<=*n*<=≤<=104). Then *n* lines follow, each line contains one query consisting of two integers, *low* and *high* (1<=≤<=*low*<=≤<=*high*<=≤<=109).
Output Specification:
Print *n* lines. The *i*-th of them should contain the result of the *i*-th query in the input. If there is no common divisor in the given range for any query, you should print -1 as a result for this query.
Demo Input:
['9 27\n3\n1 5\n10 11\n9 11\n']
Demo Output:
['3\n-1\n9\n']
Note:
none | ```python
def gcd(a,b):
while a>0:
x=a
a=b%a
b=x
return(x)
def Bsearch1(L,x):
beg=0
last=len(L)-1
while beg<=last:
mid=(beg+last)//2
if x==L[mid]:
return(mid)
elif(x>L[mid]):
beg=mid+1
else:
last=mid-1
else:
return(beg)
def Bsearch2(L,x):
beg=0
last=len(L)-1
while beg<=last:
mid=(beg+last)//2
if x==L[mid]:
return(mid)
elif(x>L[mid]):
beg=mid+1
else:
last=mid-1
else:
return(last)
a,b=input().split()
a,b=[int(a),int(b)]
x=gcd(a,b)
from functools import reduce
def factors(n):
x=set(reduce(list.__add__,
([i, n//i] for i in range(1, int(n**0.5) + 1) if n % i == 0)))
return(list(x))
div=factors(x)
div.sort()
y=int(input())
for j in range(y):
c,d=input().split()
c,d=[int(c),int(d)]
f=Bsearch1(div,c)
g=Bsearch2(div,d)
if f>g:
print(-1)
else:
print(div[g])
``` | 3.850856 |
839 | A | Arya and Bran | PROGRAMMING | 900 | [
"implementation"
] | null | null | Bran and his older sister Arya are from the same house. Bran like candies so much, so Arya is going to give him some Candies.
At first, Arya and Bran have 0 Candies. There are *n* days, at the *i*-th day, Arya finds *a**i* candies in a box, that is given by the Many-Faced God. Every day she can give Bran at most 8 of her candies. If she don't give him the candies at the same day, they are saved for her and she can give them to him later.
Your task is to find the minimum number of days Arya needs to give Bran *k* candies before the end of the *n*-th day. Formally, you need to output the minimum day index to the end of which *k* candies will be given out (the days are indexed from 1 to *n*).
Print -1 if she can't give him *k* candies during *n* given days. | The first line contains two integers *n* and *k* (1<=≤<=*n*<=≤<=100, 1<=≤<=*k*<=≤<=10000).
The second line contains *n* integers *a*1,<=*a*2,<=*a*3,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=100). | If it is impossible for Arya to give Bran *k* candies within *n* days, print -1.
Otherwise print a single integer — the minimum number of days Arya needs to give Bran *k* candies before the end of the *n*-th day. | [
"2 3\n1 2\n",
"3 17\n10 10 10\n",
"1 9\n10\n"
] | [
"2",
"3",
"-1"
] | In the first sample, Arya can give Bran 3 candies in 2 days.
In the second sample, Arya can give Bran 17 candies in 3 days, because she can give him at most 8 candies per day.
In the third sample, Arya can't give Bran 9 candies, because she can give him at most 8 candies per day and she must give him the candies within 1 day. | 500 | [
{
"input": "2 3\n1 2",
"output": "2"
},
{
"input": "3 17\n10 10 10",
"output": "3"
},
{
"input": "1 9\n10",
"output": "-1"
},
{
"input": "10 70\n6 5 2 3 3 2 1 4 3 2",
"output": "-1"
},
{
"input": "20 140\n40 4 81 40 10 54 34 50 84 60 16 1 90 78 38 93 99 60 81 99",
"output": "18"
},
{
"input": "30 133\n3 2 3 4 3 7 4 5 5 6 7 2 1 3 4 6 7 4 6 4 7 5 7 1 3 4 1 6 8 5",
"output": "30"
},
{
"input": "40 320\n70 79 21 64 95 36 63 29 66 89 30 34 100 76 42 12 4 56 80 78 83 1 39 9 34 45 6 71 27 31 55 52 72 71 38 21 43 83 48 47",
"output": "40"
},
{
"input": "50 300\n5 3 11 8 7 4 9 5 5 1 6 3 5 7 4 2 2 10 8 1 7 10 4 4 11 5 2 4 9 1 5 4 11 9 11 2 7 4 4 8 10 9 1 11 10 2 4 11 6 9",
"output": "-1"
},
{
"input": "37 30\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1",
"output": "30"
},
{
"input": "100 456\n100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100",
"output": "57"
},
{
"input": "90 298\n94 90 98 94 93 90 99 98 90 96 93 96 92 92 97 98 94 94 96 100 93 96 95 98 94 91 95 95 94 90 93 96 93 100 99 98 94 95 98 91 91 98 97 100 98 93 92 93 91 100 92 97 95 95 97 94 98 97 99 100 90 96 93 100 95 99 92 100 99 91 97 99 98 93 90 93 97 95 94 96 90 100 94 93 91 92 97 97 97 100",
"output": "38"
},
{
"input": "7 43\n4 3 7 9 3 8 10",
"output": "-1"
},
{
"input": "99 585\n8 2 3 3 10 7 9 4 7 4 6 8 7 11 5 8 7 4 7 7 6 7 11 8 1 7 3 2 10 1 6 10 10 5 10 2 5 5 11 6 4 1 5 10 5 8 1 3 7 10 6 1 1 3 8 11 5 8 2 2 5 4 7 6 7 5 8 7 10 9 6 11 4 8 2 7 1 7 1 4 11 1 9 6 1 10 6 10 1 5 6 5 2 5 11 5 1 10 8",
"output": "-1"
},
{
"input": "30 177\n8 7 5 8 3 7 2 4 3 8 11 3 9 11 2 4 1 4 5 6 11 5 8 3 6 3 11 2 11 8",
"output": "-1"
},
{
"input": "19 129\n3 3 10 11 4 7 3 8 10 2 11 6 11 9 4 2 11 10 5",
"output": "-1"
},
{
"input": "100 100\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1",
"output": "100"
},
{
"input": "13 104\n94 55 20 96 86 76 13 71 13 1 32 76 69",
"output": "13"
},
{
"input": "85 680\n61 44 55 6 30 74 27 26 17 45 73 1 67 71 39 32 13 25 79 66 4 59 49 28 29 22 10 17 98 80 36 99 52 24 59 44 27 79 29 46 29 12 47 72 82 25 6 30 81 72 95 65 30 71 72 45 39 16 16 89 48 42 59 71 50 58 31 65 91 70 48 56 28 34 53 89 94 98 49 55 94 65 91 11 53",
"output": "85"
},
{
"input": "100 458\n3 6 4 1 8 4 1 5 4 4 5 8 4 4 6 6 5 1 2 2 2 1 7 1 1 2 6 5 7 8 3 3 8 3 7 5 7 6 6 2 4 2 2 1 1 8 6 1 5 3 3 4 1 4 6 8 5 4 8 5 4 5 5 1 3 1 6 7 6 2 7 3 4 8 1 8 6 7 1 2 4 6 7 4 8 8 8 4 8 7 5 2 8 4 2 5 6 8 8 5",
"output": "100"
},
{
"input": "98 430\n4 7 6 3 4 1 7 1 1 6 6 1 5 4 6 1 5 4 6 6 1 5 1 1 8 1 6 6 2 6 8 4 4 6 6 8 8 7 4 1 2 4 1 5 4 3 7 3 2 5 7 7 7 2 2 2 7 2 8 7 3 4 5 7 8 3 7 6 7 3 2 4 7 1 4 4 7 1 1 8 4 5 8 3 1 5 3 5 2 1 3 3 8 1 3 5 8 6",
"output": "98"
},
{
"input": "90 80\n6 1 7 1 1 8 6 6 6 1 5 4 2 2 8 4 8 7 7 2 5 7 7 8 5 5 6 3 3 8 3 5 6 3 4 2 6 5 5 3 3 3 8 6 6 1 8 3 6 5 4 8 5 4 3 7 1 3 2 3 3 7 7 7 3 5 2 6 2 3 6 4 6 5 5 3 2 1 1 7 3 3 4 3 4 2 1 2 3 1",
"output": "18"
},
{
"input": "89 99\n7 7 3 5 2 7 8 8 1 1 5 7 7 4 1 5 3 4 4 8 8 3 3 2 6 3 8 2 7 5 8 1 3 5 3 6 4 3 6 2 3 3 4 5 1 6 1 7 7 7 6 7 7 7 8 8 8 2 1 7 5 8 6 7 7 4 7 5 7 8 1 3 5 8 7 1 4 2 5 8 3 4 4 5 5 6 2 4 2",
"output": "21"
},
{
"input": "50 700\n4 3 2 8 8 5 5 3 3 4 7 2 6 6 3 3 8 4 2 4 8 6 5 4 5 4 5 8 6 5 4 7 2 4 1 6 2 6 8 6 2 5 8 1 3 8 3 8 4 1",
"output": "-1"
},
{
"input": "82 359\n95 98 95 90 90 96 91 94 93 99 100 100 92 99 96 94 99 90 94 96 91 91 90 93 97 96 90 94 97 99 93 90 99 98 96 100 93 97 100 91 100 92 93 100 92 90 90 94 99 95 100 98 99 96 94 96 96 99 99 91 97 100 95 100 99 91 94 91 98 98 100 97 93 93 96 97 94 94 92 100 91 91",
"output": "45"
},
{
"input": "60 500\n93 93 100 99 91 92 95 93 95 99 93 91 97 98 90 91 98 100 95 100 94 93 92 91 91 98 98 90 93 91 90 96 92 93 92 94 94 91 96 94 98 100 97 96 96 97 91 99 97 95 96 94 91 92 99 95 97 92 98 90",
"output": "-1"
},
{
"input": "98 776\n48 63 26 3 88 81 27 33 37 10 2 89 41 84 98 93 25 44 42 90 41 65 97 1 28 69 42 14 86 18 96 28 28 94 78 8 44 31 96 45 26 52 93 25 48 39 3 75 94 93 63 59 67 86 18 74 27 38 68 7 31 60 69 67 20 11 19 34 47 43 86 96 3 49 56 60 35 49 89 28 92 69 48 15 17 73 99 69 2 73 27 35 28 53 11 1 96 50",
"output": "97"
},
{
"input": "100 189\n15 14 32 65 28 96 33 93 48 28 57 20 32 20 90 42 57 53 18 58 94 21 27 29 37 22 94 45 67 60 83 23 20 23 35 93 3 42 6 46 68 46 34 25 17 16 50 5 49 91 23 76 69 100 58 68 81 32 88 41 64 29 37 13 95 25 6 59 74 58 31 35 16 80 13 80 10 59 85 18 16 70 51 40 44 28 8 76 8 87 53 86 28 100 2 73 14 100 52 9",
"output": "24"
},
{
"input": "99 167\n72 4 79 73 49 58 15 13 92 92 42 36 35 21 13 10 51 94 64 35 86 50 6 80 93 77 59 71 2 88 22 10 27 30 87 12 77 6 34 56 31 67 78 84 36 27 15 15 12 56 80 7 56 14 10 9 14 59 15 20 34 81 8 49 51 72 4 58 38 77 31 86 18 61 27 86 95 36 46 36 39 18 78 39 48 37 71 12 51 92 65 48 39 22 16 87 4 5 42",
"output": "21"
},
{
"input": "90 4\n48 4 4 78 39 3 85 29 69 52 70 39 11 98 42 56 65 98 77 24 61 31 6 59 60 62 84 46 67 59 15 44 99 23 12 74 2 48 84 60 51 28 17 90 10 82 3 43 50 100 45 57 57 95 53 71 20 74 52 46 64 59 72 33 74 16 44 44 80 71 83 1 70 59 61 6 82 69 81 45 88 28 17 24 22 25 53 97 1 100",
"output": "1"
},
{
"input": "30 102\n55 94 3 96 3 47 92 85 25 78 27 70 97 83 40 2 55 12 74 84 91 37 31 85 7 40 33 54 72 5",
"output": "13"
},
{
"input": "81 108\n61 59 40 100 8 75 5 74 87 12 6 23 98 26 59 68 27 4 98 79 14 44 4 11 89 77 29 90 33 3 43 1 87 91 28 24 4 84 75 7 37 46 15 46 8 87 68 66 5 21 36 62 77 74 91 95 88 28 12 48 18 93 14 51 33 5 99 62 99 38 49 15 56 87 52 64 69 46 41 12 92",
"output": "14"
},
{
"input": "2 16\n10 6",
"output": "2"
},
{
"input": "2 8\n7 8",
"output": "2"
},
{
"input": "2 9\n4 8",
"output": "2"
},
{
"input": "3 19\n9 9 1",
"output": "3"
},
{
"input": "4 32\n9 9 9 5",
"output": "4"
},
{
"input": "2 15\n14 1",
"output": "2"
},
{
"input": "2 3\n3 3",
"output": "1"
},
{
"input": "3 10\n10 1 1",
"output": "2"
},
{
"input": "12 20\n3 16 19 10 1 6 17 8 6 20 1 4",
"output": "4"
},
{
"input": "4 15\n14 3 3 3",
"output": "2"
},
{
"input": "5 40\n10 10 10 10 1",
"output": "5"
},
{
"input": "4 31\n9 9 8 5",
"output": "4"
},
{
"input": "4 31\n20 7 1 1",
"output": "-1"
},
{
"input": "2 10\n9 1",
"output": "2"
},
{
"input": "10 50\n100 10 1 1 1 1 1 1 1 1",
"output": "7"
},
{
"input": "2 11\n10 2",
"output": "2"
},
{
"input": "3 21\n10 10 1",
"output": "3"
},
{
"input": "2 2\n1 2",
"output": "2"
},
{
"input": "3 2\n1 8 8",
"output": "2"
},
{
"input": "2 11\n10 1",
"output": "2"
},
{
"input": "2 16\n12 4",
"output": "2"
},
{
"input": "3 11\n9 2 2",
"output": "2"
},
{
"input": "3 11\n4 3 4",
"output": "3"
},
{
"input": "2 13\n7 6",
"output": "2"
},
{
"input": "3 24\n14 3 4",
"output": "-1"
},
{
"input": "2 13\n10 3",
"output": "2"
},
{
"input": "3 11\n9 2 1",
"output": "2"
},
{
"input": "2 15\n12 3",
"output": "2"
},
{
"input": "2 14\n11 4",
"output": "2"
}
] | 1,590,758,583 | 183 | PyPy 3 | WRONG_ANSWER | TESTS | 4 | 202 | 2,355,200 | import math as mt
import sys,string
input=sys.stdin.readline
from collections import defaultdict
L=lambda : list(map(int,input().split()))
Ls=lambda : list(input().split())
M=lambda : map(int,input().split())
I=lambda :int(input())
n,k=M()
l=L()
g=0
f=0
for i in range(n):
g+=min(8,l[i])
if(g>=k):
print(i+1)
f=1
break
if(f==0):
print(-1)
| Title: Arya and Bran
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Bran and his older sister Arya are from the same house. Bran like candies so much, so Arya is going to give him some Candies.
At first, Arya and Bran have 0 Candies. There are *n* days, at the *i*-th day, Arya finds *a**i* candies in a box, that is given by the Many-Faced God. Every day she can give Bran at most 8 of her candies. If she don't give him the candies at the same day, they are saved for her and she can give them to him later.
Your task is to find the minimum number of days Arya needs to give Bran *k* candies before the end of the *n*-th day. Formally, you need to output the minimum day index to the end of which *k* candies will be given out (the days are indexed from 1 to *n*).
Print -1 if she can't give him *k* candies during *n* given days.
Input Specification:
The first line contains two integers *n* and *k* (1<=≤<=*n*<=≤<=100, 1<=≤<=*k*<=≤<=10000).
The second line contains *n* integers *a*1,<=*a*2,<=*a*3,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=100).
Output Specification:
If it is impossible for Arya to give Bran *k* candies within *n* days, print -1.
Otherwise print a single integer — the minimum number of days Arya needs to give Bran *k* candies before the end of the *n*-th day.
Demo Input:
['2 3\n1 2\n', '3 17\n10 10 10\n', '1 9\n10\n']
Demo Output:
['2', '3', '-1']
Note:
In the first sample, Arya can give Bran 3 candies in 2 days.
In the second sample, Arya can give Bran 17 candies in 3 days, because she can give him at most 8 candies per day.
In the third sample, Arya can't give Bran 9 candies, because she can give him at most 8 candies per day and she must give him the candies within 1 day. | ```python
import math as mt
import sys,string
input=sys.stdin.readline
from collections import defaultdict
L=lambda : list(map(int,input().split()))
Ls=lambda : list(input().split())
M=lambda : map(int,input().split())
I=lambda :int(input())
n,k=M()
l=L()
g=0
f=0
for i in range(n):
g+=min(8,l[i])
if(g>=k):
print(i+1)
f=1
break
if(f==0):
print(-1)
``` | 0 |
|
58 | A | Chat room | PROGRAMMING | 1,000 | [
"greedy",
"strings"
] | A. Chat room | 1 | 256 | Vasya has recently learned to type and log on to the Internet. He immediately entered a chat room and decided to say hello to everybody. Vasya typed the word *s*. It is considered that Vasya managed to say hello if several letters can be deleted from the typed word so that it resulted in the word "hello". For example, if Vasya types the word "ahhellllloou", it will be considered that he said hello, and if he types "hlelo", it will be considered that Vasya got misunderstood and he didn't manage to say hello. Determine whether Vasya managed to say hello by the given word *s*. | The first and only line contains the word *s*, which Vasya typed. This word consisits of small Latin letters, its length is no less that 1 and no more than 100 letters. | If Vasya managed to say hello, print "YES", otherwise print "NO". | [
"ahhellllloou\n",
"hlelo\n"
] | [
"YES\n",
"NO\n"
] | none | 500 | [
{
"input": "ahhellllloou",
"output": "YES"
},
{
"input": "hlelo",
"output": "NO"
},
{
"input": "helhcludoo",
"output": "YES"
},
{
"input": "hehwelloho",
"output": "YES"
},
{
"input": "pnnepelqomhhheollvlo",
"output": "YES"
},
{
"input": "tymbzjyqhymedasloqbq",
"output": "NO"
},
{
"input": "yehluhlkwo",
"output": "NO"
},
{
"input": "hatlevhhalrohairnolsvocafgueelrqmlqlleello",
"output": "YES"
},
{
"input": "hhhtehdbllnhwmbyhvelqqyoulretpbfokflhlhreeflxeftelziclrwllrpflflbdtotvlqgoaoqldlroovbfsq",
"output": "YES"
},
{
"input": "rzlvihhghnelqtwlexmvdjjrliqllolhyewgozkuovaiezgcilelqapuoeglnwmnlftxxiigzczlouooi",
"output": "YES"
},
{
"input": "pfhhwctyqdlkrwhebfqfelhyebwllhemtrmeblgrynmvyhioesqklclocxmlffuormljszllpoo",
"output": "YES"
},
{
"input": "lqllcolohwflhfhlnaow",
"output": "NO"
},
{
"input": "heheeellollvoo",
"output": "YES"
},
{
"input": "hellooo",
"output": "YES"
},
{
"input": "o",
"output": "NO"
},
{
"input": "hhqhzeclohlehljlhtesllylrolmomvuhcxsobtsckogdv",
"output": "YES"
},
{
"input": "yoegfuzhqsihygnhpnukluutocvvwuldiighpogsifealtgkfzqbwtmgghmythcxflebrkctlldlkzlagovwlstsghbouk",
"output": "YES"
},
{
"input": "uatqtgbvrnywfacwursctpagasnhydvmlinrcnqrry",
"output": "NO"
},
{
"input": "tndtbldbllnrwmbyhvqaqqyoudrstpbfokfoclnraefuxtftmgzicorwisrpfnfpbdtatvwqgyalqtdtrjqvbfsq",
"output": "NO"
},
{
"input": "rzlvirhgemelnzdawzpaoqtxmqucnahvqnwldklrmjiiyageraijfivigvozgwngiulttxxgzczptusoi",
"output": "YES"
},
{
"input": "kgyelmchocojsnaqdsyeqgnllytbqietpdlgknwwumqkxrexgdcnwoldicwzwofpmuesjuxzrasscvyuqwspm",
"output": "YES"
},
{
"input": "pnyvrcotjvgynbeldnxieghfltmexttuxzyac",
"output": "NO"
},
{
"input": "dtwhbqoumejligbenxvzhjlhosqojetcqsynlzyhfaevbdpekgbtjrbhlltbceobcok",
"output": "YES"
},
{
"input": "crrfpfftjwhhikwzeedrlwzblckkteseofjuxjrktcjfsylmlsvogvrcxbxtffujqshslemnixoeezivksouefeqlhhokwbqjz",
"output": "YES"
},
{
"input": "jhfbndhyzdvhbvhmhmefqllujdflwdpjbehedlsqfdsqlyelwjtyloxwsvasrbqosblzbowlqjmyeilcvotdlaouxhdpoeloaovb",
"output": "YES"
},
{
"input": "hwlghueoemiqtjhhpashjsouyegdlvoyzeunlroypoprnhlyiwiuxrghekaylndhrhllllwhbebezoglydcvykllotrlaqtvmlla",
"output": "YES"
},
{
"input": "wshiaunnqnqxodholbipwhhjmyeblhgpeleblklpzwhdunmpqkbuzloetmwwxmeltkrcomulxauzlwmlklldjodozxryghsnwgcz",
"output": "YES"
},
{
"input": "shvksednttggehroewuiptvvxtrzgidravtnjwuqrlnnkxbplctzkckinpkgjopjfoxdbojtcvsuvablcbkrzajrlhgobkcxeqti",
"output": "YES"
},
{
"input": "hyyhddqhxhekehkwfhlnlsihzefwchzerevcjtokefplholrbvxlltdlafjxrfhleglrvlolojoqaolagtbeyogxlbgfolllslli",
"output": "YES"
},
{
"input": "iaagrdhhelxpdegueiulflquvlzidoprzkehthkldaytrjwhyhprwjxlltinxvuilxohqgjqcvkkdcuoliekcnlilwgqlnlzouoo",
"output": "YES"
},
{
"input": "wfluaeseldgxyvxpwuhkptdmlflnlhktwxiabsvkolsquymrmhzczzoybvlilhmvsuunggvgxzgyyffk",
"output": "NO"
},
{
"input": "loee",
"output": "NO"
},
{
"input": "izdipwylefqmjbuoznfglgcfvedeouflkeehxbasaqmiooppfsqlhprospqgxvzrcpwlfdddngoqvpwvggsnvvxhmjoslwjudjlo",
"output": "NO"
},
{
"input": "pplynflbjlseflaegzqpdxswgunhnlglqhycrbcwdfhclmcrwekkzsoosmfblljeenwfjyifcvxihhhbyhmhlkvtskeglaovjnsi",
"output": "YES"
},
{
"input": "xqjqmenkodmlhzyzmmvofdngktygbbxbzpluzcohohmalkoeuwfikblltaaigv",
"output": "NO"
},
{
"input": "hello",
"output": "YES"
},
{
"input": "oohell",
"output": "NO"
},
{
"input": "hell",
"output": "NO"
},
{
"input": "eloellohoelo",
"output": "NO"
},
{
"input": "helllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllo",
"output": "YES"
}
] | 1,678,625,050 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 40 | 62 | 0 | def stringcheck(s):
word="hello"
req="h"
c=0
for ch in s:
if c==5:
break
if ch==req:
c+=1
if c<5:
req=word[c]
if c==5:
print("YES")
else:
print("NO")
s=input()
stringcheck(s) | Title: Chat room
Time Limit: 1 seconds
Memory Limit: 256 megabytes
Problem Description:
Vasya has recently learned to type and log on to the Internet. He immediately entered a chat room and decided to say hello to everybody. Vasya typed the word *s*. It is considered that Vasya managed to say hello if several letters can be deleted from the typed word so that it resulted in the word "hello". For example, if Vasya types the word "ahhellllloou", it will be considered that he said hello, and if he types "hlelo", it will be considered that Vasya got misunderstood and he didn't manage to say hello. Determine whether Vasya managed to say hello by the given word *s*.
Input Specification:
The first and only line contains the word *s*, which Vasya typed. This word consisits of small Latin letters, its length is no less that 1 and no more than 100 letters.
Output Specification:
If Vasya managed to say hello, print "YES", otherwise print "NO".
Demo Input:
['ahhellllloou\n', 'hlelo\n']
Demo Output:
['YES\n', 'NO\n']
Note:
none | ```python
def stringcheck(s):
word="hello"
req="h"
c=0
for ch in s:
if c==5:
break
if ch==req:
c+=1
if c<5:
req=word[c]
if c==5:
print("YES")
else:
print("NO")
s=input()
stringcheck(s)
``` | 3.969 |
862 | A | Mahmoud and Ehab and the MEX | PROGRAMMING | 1,000 | [
"greedy",
"implementation"
] | null | null | Dr. Evil kidnapped Mahmoud and Ehab in the evil land because of their performance in the Evil Olympiad in Informatics (EOI). He decided to give them some problems to let them go.
Dr. Evil is interested in sets, He has a set of *n* integers. Dr. Evil calls a set of integers evil if the MEX of it is exactly *x*. the MEX of a set of integers is the minimum non-negative integer that doesn't exist in it. For example, the MEX of the set {0,<=2,<=4} is 1 and the MEX of the set {1,<=2,<=3} is 0 .
Dr. Evil is going to make his set evil. To do this he can perform some operations. During each operation he can add some non-negative integer to his set or erase some element from it. What is the minimal number of operations Dr. Evil has to perform to make his set evil? | The first line contains two integers *n* and *x* (1<=≤<=*n*<=≤<=100, 0<=≤<=*x*<=≤<=100) — the size of the set Dr. Evil owns, and the desired MEX.
The second line contains *n* distinct non-negative integers not exceeding 100 that represent the set. | The only line should contain one integer — the minimal number of operations Dr. Evil should perform. | [
"5 3\n0 4 5 6 7\n",
"1 0\n0\n",
"5 0\n1 2 3 4 5\n"
] | [
"2\n",
"1\n",
"0\n"
] | For the first test case Dr. Evil should add 1 and 2 to the set performing 2 operations.
For the second test case Dr. Evil should erase 0 from the set. After that, the set becomes empty, so the MEX of it is 0.
In the third test case the set is already evil. | 500 | [
{
"input": "5 3\n0 4 5 6 7",
"output": "2"
},
{
"input": "1 0\n0",
"output": "1"
},
{
"input": "5 0\n1 2 3 4 5",
"output": "0"
},
{
"input": "10 5\n57 1 47 9 93 37 76 70 78 15",
"output": "4"
},
{
"input": "10 5\n99 98 93 97 95 100 92 94 91 96",
"output": "5"
},
{
"input": "10 5\n1 2 3 4 59 45 0 58 51 91",
"output": "0"
},
{
"input": "100 100\n79 13 21 11 3 87 28 40 29 4 96 34 8 78 61 46 33 45 99 30 92 67 22 97 39 86 73 31 74 44 62 55 57 2 54 63 80 69 25 48 77 98 17 93 15 16 89 12 43 23 37 95 14 38 83 90 49 56 72 10 20 0 50 71 70 88 19 1 76 81 52 41 82 68 85 47 6 7 35 60 18 64 75 84 27 9 65 91 94 42 53 24 66 26 59 36 51 32 5 58",
"output": "0"
},
{
"input": "100 50\n95 78 46 92 80 18 79 58 30 72 19 89 39 29 44 65 15 100 59 8 96 9 62 67 41 42 82 14 57 32 71 77 40 5 7 51 28 53 85 23 16 35 3 91 6 11 75 61 17 66 13 47 36 56 10 22 83 60 48 24 26 97 4 33 76 86 70 0 34 64 52 43 21 49 55 74 1 73 81 25 54 63 94 84 20 68 87 12 31 88 38 93 37 90 98 69 99 45 27 2",
"output": "0"
},
{
"input": "100 33\n28 11 79 92 88 62 77 72 7 41 96 97 67 84 44 8 81 35 38 1 64 68 46 17 98 83 31 12 74 21 2 22 47 6 36 75 65 61 37 26 25 45 59 48 100 51 93 76 78 49 3 57 16 4 87 29 55 82 70 39 53 0 60 15 24 71 58 20 66 89 95 42 13 43 63 90 85 52 50 30 54 40 56 23 27 34 32 18 10 19 69 9 99 73 91 14 5 80 94 86",
"output": "0"
},
{
"input": "99 33\n25 76 41 95 55 20 47 59 58 84 87 92 16 27 35 65 72 63 93 54 36 96 15 86 5 69 24 46 67 73 48 60 40 6 61 74 97 10 100 8 52 26 77 18 7 62 37 2 14 66 11 56 68 91 0 64 75 99 30 21 53 1 89 81 3 98 12 88 39 38 29 83 22 90 9 28 45 43 78 44 32 57 4 50 70 17 13 51 80 85 71 94 82 19 34 42 23 79 49",
"output": "1"
},
{
"input": "100 100\n65 56 84 46 44 33 99 74 62 72 93 67 43 92 75 88 38 34 66 12 55 76 58 90 78 8 14 45 97 59 48 32 64 18 39 89 31 51 54 81 29 36 70 77 40 22 49 27 3 1 73 13 98 42 87 37 2 57 4 6 50 25 23 79 28 86 68 61 80 17 19 10 15 63 52 11 35 60 21 16 24 85 30 91 7 5 69 20 71 82 53 94 41 95 96 9 26 83 0 47",
"output": "0"
},
{
"input": "100 100\n58 88 12 71 22 1 40 19 73 20 67 48 57 17 69 36 100 35 33 37 72 55 52 8 89 85 47 42 78 70 81 86 11 9 68 99 6 16 21 61 53 98 23 62 32 59 51 0 87 24 50 30 65 10 80 95 7 92 25 74 60 79 91 5 13 31 75 38 90 94 46 66 93 34 14 41 28 2 76 84 43 96 3 56 49 82 27 77 64 63 4 45 18 29 54 39 15 26 83 44",
"output": "2"
},
{
"input": "89 100\n58 96 17 41 86 34 28 84 18 40 8 77 87 89 68 79 33 35 53 49 0 6 22 12 72 90 48 55 21 50 56 62 75 2 37 95 69 74 14 20 44 46 27 32 31 59 63 60 10 85 71 70 38 52 94 30 61 51 80 26 36 23 39 47 76 45 100 57 15 78 97 66 54 13 99 16 93 73 24 4 83 5 98 81 92 25 29 88 65",
"output": "13"
},
{
"input": "100 50\n7 95 24 76 81 78 60 69 83 84 100 1 65 31 48 92 73 39 18 89 38 97 10 42 8 55 98 51 21 90 62 77 16 91 0 94 4 37 19 17 67 35 45 41 56 20 15 85 75 28 59 27 12 54 61 68 36 5 79 93 66 11 70 49 50 34 30 25 96 46 64 14 32 22 47 40 58 23 43 9 87 82 26 53 80 52 3 86 13 99 33 71 6 88 57 74 2 44 72 63",
"output": "2"
},
{
"input": "77 0\n27 8 20 92 21 41 53 98 17 65 67 35 81 11 55 49 61 44 2 66 51 89 40 28 52 62 86 91 64 24 18 5 94 82 96 99 71 6 39 83 26 29 16 30 45 97 80 90 69 12 13 33 76 73 46 19 78 56 88 38 42 34 57 77 47 4 59 58 7 100 95 72 9 74 15 43 54",
"output": "0"
},
{
"input": "100 50\n55 36 0 32 81 6 17 43 24 13 30 19 8 59 71 45 15 74 3 41 99 42 86 47 2 94 35 1 66 95 38 49 4 27 96 89 34 44 92 25 51 39 54 28 80 77 20 14 48 40 68 56 31 63 33 78 69 37 18 26 83 70 23 82 91 65 67 52 61 53 7 22 60 21 12 73 72 87 75 100 90 29 64 79 98 85 5 62 93 84 50 46 97 58 57 16 9 10 76 11",
"output": "1"
},
{
"input": "77 0\n12 8 19 87 9 54 55 86 97 7 27 85 25 48 94 73 26 1 13 57 72 69 76 39 38 91 75 40 42 28 93 21 70 84 65 11 60 90 20 95 66 89 59 47 34 99 6 61 52 100 50 3 77 81 82 53 15 24 0 45 44 14 68 96 58 5 18 35 10 98 29 74 92 49 83 71 17",
"output": "1"
},
{
"input": "100 70\n25 94 66 65 10 99 89 6 70 31 7 40 20 92 64 27 21 72 77 98 17 43 47 44 48 81 38 56 100 39 90 22 88 76 3 83 86 29 33 55 82 79 49 11 2 16 12 78 85 69 32 97 26 15 53 24 23 91 51 67 34 35 52 5 62 50 95 18 71 13 75 8 30 42 93 36 45 60 63 46 57 41 87 0 84 54 74 37 4 58 28 19 96 61 80 9 1 14 73 68",
"output": "2"
},
{
"input": "89 19\n14 77 85 81 79 38 91 45 55 51 50 11 62 67 73 76 2 27 16 23 3 29 65 98 78 17 4 58 22 20 34 66 64 31 72 5 32 44 12 75 80 47 18 25 99 0 61 56 71 84 48 88 10 7 86 8 49 24 43 21 37 28 33 54 46 57 40 89 36 97 6 96 39 95 26 74 1 69 9 100 52 30 83 87 68 60 92 90 35",
"output": "2"
},
{
"input": "89 100\n69 61 56 45 11 41 42 32 28 29 0 76 7 65 13 35 36 82 10 39 26 34 38 40 92 12 17 54 24 46 88 70 66 27 100 52 85 62 22 48 86 68 21 49 53 94 67 20 1 90 77 84 31 87 58 47 95 33 4 72 93 83 8 51 91 80 99 43 71 19 44 59 98 97 64 9 81 16 79 63 25 37 3 75 2 55 50 6 18",
"output": "13"
},
{
"input": "77 0\n38 76 24 74 42 88 29 75 96 46 90 32 59 97 98 60 41 57 80 37 100 49 25 63 95 31 61 68 53 78 27 66 84 48 94 83 30 26 36 99 71 62 45 47 70 28 35 54 34 85 79 43 91 72 86 33 67 92 77 65 69 52 82 55 87 64 56 40 50 44 51 73 89 81 58 93 39",
"output": "0"
},
{
"input": "89 100\n38 90 80 64 35 44 56 11 15 89 23 12 49 70 72 60 63 85 92 10 45 83 8 88 41 33 16 6 61 76 62 71 87 13 25 77 74 0 1 37 96 93 7 94 21 82 34 78 4 73 65 20 81 95 50 32 48 17 69 55 68 5 51 27 53 43 91 67 59 46 86 84 99 24 22 3 97 98 40 36 26 58 57 9 42 30 52 2 47",
"output": "11"
},
{
"input": "77 0\n55 71 78 86 68 35 53 10 59 32 81 19 74 97 62 61 93 87 96 44 25 18 43 82 84 16 34 48 92 39 64 36 49 91 45 76 95 31 57 29 75 79 13 2 14 24 52 23 33 20 47 99 63 15 5 80 58 67 12 3 85 6 1 27 73 90 4 42 37 70 8 11 89 77 9 22 94",
"output": "0"
},
{
"input": "77 0\n12 75 31 71 44 8 3 82 21 77 50 29 57 74 40 10 15 42 84 2 100 9 28 72 92 0 49 11 90 55 17 36 19 54 68 52 4 69 97 91 5 39 59 45 89 62 53 83 16 94 76 60 95 47 30 51 7 48 20 70 67 32 58 78 63 34 56 93 99 88 24 1 66 22 25 14 13",
"output": "1"
},
{
"input": "100 70\n91 82 8 85 26 25 95 97 40 87 81 93 7 73 38 94 64 96 74 18 90 19 65 68 72 61 23 43 36 41 60 88 30 33 71 24 52 39 15 3 16 89 86 79 55 4 9 58 67 44 46 29 6 48 84 69 27 21 78 54 51 57 80 53 76 50 47 77 45 12 34 10 100 0 17 31 56 99 98 11 92 5 2 42 32 59 66 62 37 63 28 75 35 1 22 13 83 49 20 14",
"output": "0"
},
{
"input": "77 0\n51 5 81 62 30 22 11 0 83 16 79 85 52 70 69 10 8 47 58 3 24 34 44 14 82 66 99 17 28 31 64 67 23 49 94 45 4 12 27 15 21 6 43 72 87 2 63 92 35 39 59 9 90 78 93 20 65 36 60 89 50 41 61 84 77 86 76 100 38 68 53 97 96 95 7 19 88",
"output": "1"
},
{
"input": "1 100\n0",
"output": "99"
},
{
"input": "1 0\n100",
"output": "0"
},
{
"input": "1 100\n100",
"output": "101"
},
{
"input": "2 100\n0 100",
"output": "100"
},
{
"input": "5 5\n1 2 3 4 5",
"output": "2"
},
{
"input": "5 3\n0 3 4 5 6",
"output": "3"
},
{
"input": "7 10\n0 1 2 3 4 5 10",
"output": "5"
},
{
"input": "2 2\n0 2",
"output": "2"
},
{
"input": "2 1\n1 2",
"output": "2"
},
{
"input": "5 1\n1 2 3 4 5",
"output": "2"
},
{
"input": "5 2\n1 2 3 4 5",
"output": "2"
},
{
"input": "5 6\n0 1 2 3 4",
"output": "1"
},
{
"input": "3 2\n3 4 5",
"output": "2"
}
] | 1,507,791,499 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 30 | 0 | n, x = map(int, input().split())
set1 = set(map(int, input().split()))
'''
if x == 0 and x in set1:
for e in set1:
print(e)
break
else:
'''
set2 = set()
for i in range(0, x + 1):
set2.add(i)
set3 = set2 - set1
print(set1)
print(set2)
print(set3)
if x in set3:
#print(1)
print(len(set3) - 1)
elif bool(set3) and x not in set3:
#print(2)
print(len(set3) + 1)
else:
#print(3)
print(len(set3) + 1) | Title: Mahmoud and Ehab and the MEX
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Dr. Evil kidnapped Mahmoud and Ehab in the evil land because of their performance in the Evil Olympiad in Informatics (EOI). He decided to give them some problems to let them go.
Dr. Evil is interested in sets, He has a set of *n* integers. Dr. Evil calls a set of integers evil if the MEX of it is exactly *x*. the MEX of a set of integers is the minimum non-negative integer that doesn't exist in it. For example, the MEX of the set {0,<=2,<=4} is 1 and the MEX of the set {1,<=2,<=3} is 0 .
Dr. Evil is going to make his set evil. To do this he can perform some operations. During each operation he can add some non-negative integer to his set or erase some element from it. What is the minimal number of operations Dr. Evil has to perform to make his set evil?
Input Specification:
The first line contains two integers *n* and *x* (1<=≤<=*n*<=≤<=100, 0<=≤<=*x*<=≤<=100) — the size of the set Dr. Evil owns, and the desired MEX.
The second line contains *n* distinct non-negative integers not exceeding 100 that represent the set.
Output Specification:
The only line should contain one integer — the minimal number of operations Dr. Evil should perform.
Demo Input:
['5 3\n0 4 5 6 7\n', '1 0\n0\n', '5 0\n1 2 3 4 5\n']
Demo Output:
['2\n', '1\n', '0\n']
Note:
For the first test case Dr. Evil should add 1 and 2 to the set performing 2 operations.
For the second test case Dr. Evil should erase 0 from the set. After that, the set becomes empty, so the MEX of it is 0.
In the third test case the set is already evil. | ```python
n, x = map(int, input().split())
set1 = set(map(int, input().split()))
'''
if x == 0 and x in set1:
for e in set1:
print(e)
break
else:
'''
set2 = set()
for i in range(0, x + 1):
set2.add(i)
set3 = set2 - set1
print(set1)
print(set2)
print(set3)
if x in set3:
#print(1)
print(len(set3) - 1)
elif bool(set3) and x not in set3:
#print(2)
print(len(set3) + 1)
else:
#print(3)
print(len(set3) + 1)
``` | 0 |
|
844 | A | Diversity | PROGRAMMING | 1,000 | [
"greedy",
"implementation",
"strings"
] | null | null | Calculate the minimum number of characters you need to change in the string *s*, so that it contains at least *k* different letters, or print that it is impossible.
String *s* consists only of lowercase Latin letters, and it is allowed to change characters only to lowercase Latin letters too. | First line of input contains string *s*, consisting only of lowercase Latin letters (1<=≤<=|*s*|<=≤<=1000, |*s*| denotes the length of *s*).
Second line of input contains integer *k* (1<=≤<=*k*<=≤<=26). | Print single line with a minimum number of necessary changes, or the word «impossible» (without quotes) if it is impossible. | [
"yandex\n6\n",
"yahoo\n5\n",
"google\n7\n"
] | [
"0\n",
"1\n",
"impossible\n"
] | In the first test case string contains 6 different letters, so we don't need to change anything.
In the second test case string contains 4 different letters: {'*a*', '*h*', '*o*', '*y*'}. To get 5 different letters it is necessary to change one occurrence of '*o*' to some letter, which doesn't occur in the string, for example, {'*b*'}.
In the third test case, it is impossible to make 7 different letters because the length of the string is 6. | 500 | [
{
"input": "yandex\n6",
"output": "0"
},
{
"input": "yahoo\n5",
"output": "1"
},
{
"input": "google\n7",
"output": "impossible"
},
{
"input": "a\n1",
"output": "0"
},
{
"input": "z\n2",
"output": "impossible"
},
{
"input": "fwgfrwgkuwghfiruhewgirueguhergiqrbvgrgf\n26",
"output": "14"
},
{
"input": "nfevghreuoghrueighoqghbnebvnejbvnbgneluqe\n26",
"output": "12"
},
{
"input": "a\n3",
"output": "impossible"
},
{
"input": "smaxpqplaqqbxuqxalqmbmmgubbpspxhawbxsuqhhegpmmpebqmqpbbeplwaepxmsahuepuhuhwxeqmmlgqubuaxehwuwasgxpqmugbmuawuhwqlswllssueglbxepbmwgs\n1",
"output": "0"
},
{
"input": "cuguccgcugcugucgggggcgcgucgucugcuuuccccuugccg\n4",
"output": "1"
},
{
"input": "fcfccfcfccfcfcffcffffffcfccfccfcffccccfcffffccfccfcffcfcccccffcfffcccffcfccfffffcccfccffffffccfccccf\n20",
"output": "18"
},
{
"input": "swmkwaruyv\n5",
"output": "0"
},
{
"input": "tnbqpsuhkczmejirvyfdolxwga\n22",
"output": "0"
},
{
"input": "abcde\n3",
"output": "0"
},
{
"input": "abb\n1",
"output": "0"
},
{
"input": "aaaa\n1",
"output": "0"
},
{
"input": "abcde\n2",
"output": "0"
},
{
"input": "yandex\n4",
"output": "0"
},
{
"input": "aaabbbccc\n1",
"output": "0"
},
{
"input": "abcd\n2",
"output": "0"
},
{
"input": "asdfgh\n2",
"output": "0"
},
{
"input": "aab\n1",
"output": "0"
},
{
"input": "mynameissako\n5",
"output": "0"
},
{
"input": "abcde\n1",
"output": "0"
},
{
"input": "abcd\n3",
"output": "0"
},
{
"input": "abcdef\n2",
"output": "0"
},
{
"input": "abcdefg\n4",
"output": "0"
},
{
"input": "abc\n1",
"output": "0"
},
{
"input": "asdafjsgljdllgjdgkl\n5",
"output": "0"
},
{
"input": "yaay\n3",
"output": "1"
},
{
"input": "yaay\n4",
"output": "2"
},
{
"input": "zzzzzz\n2",
"output": "1"
}
] | 1,503,595,172 | 2,672 | Python 3 | OK | TESTS | 41 | 77 | 0 | s = input()
x = int(input())
if x > len(s):
print('impossible')
elif x < len(set(s)):
print(0)
else:
print(x - len(set(s))) | Title: Diversity
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Calculate the minimum number of characters you need to change in the string *s*, so that it contains at least *k* different letters, or print that it is impossible.
String *s* consists only of lowercase Latin letters, and it is allowed to change characters only to lowercase Latin letters too.
Input Specification:
First line of input contains string *s*, consisting only of lowercase Latin letters (1<=≤<=|*s*|<=≤<=1000, |*s*| denotes the length of *s*).
Second line of input contains integer *k* (1<=≤<=*k*<=≤<=26).
Output Specification:
Print single line with a minimum number of necessary changes, or the word «impossible» (without quotes) if it is impossible.
Demo Input:
['yandex\n6\n', 'yahoo\n5\n', 'google\n7\n']
Demo Output:
['0\n', '1\n', 'impossible\n']
Note:
In the first test case string contains 6 different letters, so we don't need to change anything.
In the second test case string contains 4 different letters: {'*a*', '*h*', '*o*', '*y*'}. To get 5 different letters it is necessary to change one occurrence of '*o*' to some letter, which doesn't occur in the string, for example, {'*b*'}.
In the third test case, it is impossible to make 7 different letters because the length of the string is 6. | ```python
s = input()
x = int(input())
if x > len(s):
print('impossible')
elif x < len(set(s)):
print(0)
else:
print(x - len(set(s)))
``` | 3 |
|
265 | A | Colorful Stones (Simplified Edition) | PROGRAMMING | 800 | [
"implementation"
] | null | null | There is a sequence of colorful stones. The color of each stone is one of red, green, or blue. You are given a string *s*. The *i*-th (1-based) character of *s* represents the color of the *i*-th stone. If the character is "R", "G", or "B", the color of the corresponding stone is red, green, or blue, respectively.
Initially Squirrel Liss is standing on the first stone. You perform instructions one or more times.
Each instruction is one of the three types: "RED", "GREEN", or "BLUE". After an instruction *c*, if Liss is standing on a stone whose colors is *c*, Liss will move one stone forward, else she will not move.
You are given a string *t*. The number of instructions is equal to the length of *t*, and the *i*-th character of *t* represents the *i*-th instruction.
Calculate the final position of Liss (the number of the stone she is going to stand on in the end) after performing all the instructions, and print its 1-based position. It is guaranteed that Liss don't move out of the sequence. | The input contains two lines. The first line contains the string *s* (1<=≤<=|*s*|<=≤<=50). The second line contains the string *t* (1<=≤<=|*t*|<=≤<=50). The characters of each string will be one of "R", "G", or "B". It is guaranteed that Liss don't move out of the sequence. | Print the final 1-based position of Liss in a single line. | [
"RGB\nRRR\n",
"RRRBGBRBBB\nBBBRR\n",
"BRRBGBRGRBGRGRRGGBGBGBRGBRGRGGGRBRRRBRBBBGRRRGGBBB\nBBRBGGRGRGBBBRBGRBRBBBBRBRRRBGBBGBBRRBBGGRBRRBRGRB\n"
] | [
"2\n",
"3\n",
"15\n"
] | none | 500 | [
{
"input": "RGB\nRRR",
"output": "2"
},
{
"input": "RRRBGBRBBB\nBBBRR",
"output": "3"
},
{
"input": "BRRBGBRGRBGRGRRGGBGBGBRGBRGRGGGRBRRRBRBBBGRRRGGBBB\nBBRBGGRGRGBBBRBGRBRBBBBRBRRRBGBBGBBRRBBGGRBRRBRGRB",
"output": "15"
},
{
"input": "G\nRRBBRBRRBR",
"output": "1"
},
{
"input": "RRRRRBRRBRRGRBGGRRRGRBBRBBBBBRGRBGBRRGBBBRBBGBRGBB\nB",
"output": "1"
},
{
"input": "RRGGBRGRBG\nBRRGGBBGGR",
"output": "7"
},
{
"input": "BBRRGBGGRGBRGBRBRBGR\nGGGRBGGGBRRRRGRBGBGRGRRBGRBGBG",
"output": "15"
},
{
"input": "GBRRBGBGBBBBRRRGBGRRRGBGBBBRGR\nRRGBRRGRBBBBBBGRRBBR",
"output": "8"
},
{
"input": "BRGRRGRGRRGBBGBBBRRBBRRBGBBGRGBBGGRGBRBGGGRRRBGGBB\nRGBBGRRBBBRRGRRBRBBRGBBGGGRGBGRRRRBRBGGBRBGGGRGBRR",
"output": "16"
},
{
"input": "GGRGGBRRGRGBRRGGRBBGGRRGBBBGBBBGGRBGGBRBBRGBRRRBRG\nGGRGRRRRRRRRRGBBBBRGBRGRGRRGBBRGGBRBBRBGBRGRRRRGGR",
"output": "18"
},
{
"input": "RBBRBGBBGGGBRRBGBRGRRGGRBBBBGRBGGBRRBGBBRBRGBBGGGG\nBRRGRBGRBGBRGBRBGGBBBGBBRGRBGRGRBGRBGGRRBGBRGRRBBG",
"output": "23"
},
{
"input": "RRGGRRBRGRGBRGBRGBBRGGGBRBGBRGBRGGBRBRGBGRRBBGGRBR\nBRGRBBBGRBGRRGGRRRRRRRRGGGGGGGGBGGGGGGGRGRBBRGRGBR",
"output": "14"
},
{
"input": "RBRBRRRRRGGR\nBBBBRRGGBGRBRGBBRGGGRGGBRRBRBRBGGG",
"output": "12"
},
{
"input": "GGRGGGBRGRGRBBRGGGRBGRRR\nGBBBBGBGBGBBBRGGRGGBGRRGRRRGBGB",
"output": "12"
},
{
"input": "RGRBGBRBBGBRRGGGBBGBRRBGRGBBBBBGRRRGGRBB\nBGR",
"output": "2"
},
{
"input": "R\nB",
"output": "1"
},
{
"input": "RRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRR\nRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRR",
"output": "50"
},
{
"input": "RRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRR\nGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGG",
"output": "1"
},
{
"input": "R\nGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGG",
"output": "1"
}
] | 1,688,667,351 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 19 | 124 | 0 | s = input()
t = input()
count=1
si=0
for i in range(len(t)):
if t[i] == s[si]:
count+=1
si+=1
print(count) | Title: Colorful Stones (Simplified Edition)
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
There is a sequence of colorful stones. The color of each stone is one of red, green, or blue. You are given a string *s*. The *i*-th (1-based) character of *s* represents the color of the *i*-th stone. If the character is "R", "G", or "B", the color of the corresponding stone is red, green, or blue, respectively.
Initially Squirrel Liss is standing on the first stone. You perform instructions one or more times.
Each instruction is one of the three types: "RED", "GREEN", or "BLUE". After an instruction *c*, if Liss is standing on a stone whose colors is *c*, Liss will move one stone forward, else she will not move.
You are given a string *t*. The number of instructions is equal to the length of *t*, and the *i*-th character of *t* represents the *i*-th instruction.
Calculate the final position of Liss (the number of the stone she is going to stand on in the end) after performing all the instructions, and print its 1-based position. It is guaranteed that Liss don't move out of the sequence.
Input Specification:
The input contains two lines. The first line contains the string *s* (1<=≤<=|*s*|<=≤<=50). The second line contains the string *t* (1<=≤<=|*t*|<=≤<=50). The characters of each string will be one of "R", "G", or "B". It is guaranteed that Liss don't move out of the sequence.
Output Specification:
Print the final 1-based position of Liss in a single line.
Demo Input:
['RGB\nRRR\n', 'RRRBGBRBBB\nBBBRR\n', 'BRRBGBRGRBGRGRRGGBGBGBRGBRGRGGGRBRRRBRBBBGRRRGGBBB\nBBRBGGRGRGBBBRBGRBRBBBBRBRRRBGBBGBBRRBBGGRBRRBRGRB\n']
Demo Output:
['2\n', '3\n', '15\n']
Note:
none | ```python
s = input()
t = input()
count=1
si=0
for i in range(len(t)):
if t[i] == s[si]:
count+=1
si+=1
print(count)
``` | 3 |
|
617 | A | Elephant | PROGRAMMING | 800 | [
"math"
] | null | null | An elephant decided to visit his friend. It turned out that the elephant's house is located at point 0 and his friend's house is located at point *x*(*x*<=><=0) of the coordinate line. In one step the elephant can move 1, 2, 3, 4 or 5 positions forward. Determine, what is the minimum number of steps he need to make in order to get to his friend's house. | The first line of the input contains an integer *x* (1<=≤<=*x*<=≤<=1<=000<=000) — The coordinate of the friend's house. | Print the minimum number of steps that elephant needs to make to get from point 0 to point *x*. | [
"5\n",
"12\n"
] | [
"1\n",
"3\n"
] | In the first sample the elephant needs to make one step of length 5 to reach the point *x*.
In the second sample the elephant can get to point *x* if he moves by 3, 5 and 4. There are other ways to get the optimal answer but the elephant cannot reach *x* in less than three moves. | 500 | [
{
"input": "5",
"output": "1"
},
{
"input": "12",
"output": "3"
},
{
"input": "999999",
"output": "200000"
},
{
"input": "41",
"output": "9"
},
{
"input": "1000000",
"output": "200000"
},
{
"input": "1",
"output": "1"
},
{
"input": "2",
"output": "1"
},
{
"input": "3",
"output": "1"
},
{
"input": "4",
"output": "1"
},
{
"input": "534204",
"output": "106841"
},
{
"input": "469569",
"output": "93914"
},
{
"input": "502877",
"output": "100576"
},
{
"input": "942212",
"output": "188443"
},
{
"input": "97",
"output": "20"
},
{
"input": "53",
"output": "11"
},
{
"input": "89",
"output": "18"
},
{
"input": "574",
"output": "115"
},
{
"input": "716",
"output": "144"
},
{
"input": "729",
"output": "146"
},
{
"input": "8901",
"output": "1781"
},
{
"input": "3645",
"output": "729"
},
{
"input": "4426",
"output": "886"
},
{
"input": "46573",
"output": "9315"
},
{
"input": "86380",
"output": "17276"
},
{
"input": "94190",
"output": "18838"
},
{
"input": "999990",
"output": "199998"
},
{
"input": "999991",
"output": "199999"
},
{
"input": "999992",
"output": "199999"
},
{
"input": "999993",
"output": "199999"
},
{
"input": "999994",
"output": "199999"
},
{
"input": "999995",
"output": "199999"
},
{
"input": "999996",
"output": "200000"
},
{
"input": "999997",
"output": "200000"
},
{
"input": "999998",
"output": "200000"
}
] | 1,699,242,148 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 1 | 46 | 0 | n=int(input())
lst1=[]
for i in range(1,6):
if n%i==0:
lst1.append([n//i,i])
lst2=[elem for row in lst1 for elem in row]
print(min(lst2))
| Title: Elephant
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
An elephant decided to visit his friend. It turned out that the elephant's house is located at point 0 and his friend's house is located at point *x*(*x*<=><=0) of the coordinate line. In one step the elephant can move 1, 2, 3, 4 or 5 positions forward. Determine, what is the minimum number of steps he need to make in order to get to his friend's house.
Input Specification:
The first line of the input contains an integer *x* (1<=≤<=*x*<=≤<=1<=000<=000) — The coordinate of the friend's house.
Output Specification:
Print the minimum number of steps that elephant needs to make to get from point 0 to point *x*.
Demo Input:
['5\n', '12\n']
Demo Output:
['1\n', '3\n']
Note:
In the first sample the elephant needs to make one step of length 5 to reach the point *x*.
In the second sample the elephant can get to point *x* if he moves by 3, 5 and 4. There are other ways to get the optimal answer but the elephant cannot reach *x* in less than three moves. | ```python
n=int(input())
lst1=[]
for i in range(1,6):
if n%i==0:
lst1.append([n//i,i])
lst2=[elem for row in lst1 for elem in row]
print(min(lst2))
``` | 0 |
|
92 | B | Binary Number | PROGRAMMING | 1,300 | [
"greedy"
] | B. Binary Number | 1 | 256 | Little walrus Fangy loves math very much. That's why when he is bored he plays with a number performing some operations.
Fangy takes some positive integer *x* and wants to get a number one from it. While *x* is not equal to 1, Fangy repeats the following action: if *x* is odd, then he adds 1 to it, otherwise he divides *x* by 2. Fangy knows that for any positive integer number the process ends in finite time.
How many actions should Fangy perform to get a number one from number *x*? | The first line contains a positive integer *x* in a binary system. It is guaranteed that the first digit of *x* is different from a zero and the number of its digits does not exceed 106. | Print the required number of actions. | [
"1\n",
"1001001\n",
"101110\n"
] | [
"0\n",
"12\n",
"8\n"
] | Let's consider the third sample. Number 101110 is even, which means that we should divide it by 2. After the dividing Fangy gets an odd number 10111 and adds one to it. Number 11000 can be divided by 2 three times in a row and get number 11. All that's left is to increase the number by one (we get 100), and then divide it by 2 two times in a row. As a result, we get 1. | 1,000 | [
{
"input": "1",
"output": "0"
},
{
"input": "1001001",
"output": "12"
},
{
"input": "101110",
"output": "8"
},
{
"input": "11",
"output": "3"
},
{
"input": "11110001101",
"output": "16"
},
{
"input": "1010101001001111000111110011111000010101011111101010",
"output": "74"
},
{
"input": "1100000010010100111011100011110101111",
"output": "55"
},
{
"input": "11000111111110110110100110110101111100010100110110010",
"output": "74"
},
{
"input": "11100000110100011110101001101111100000011001111000011110000000111110111",
"output": "106"
},
{
"input": "1000101100110000000001111010110000000010001001111110011011000011101011001001010010111",
"output": "133"
},
{
"input": "1000000000000000000000000000000000000000000000000000000000000000000000000",
"output": "72"
},
{
"input": "10000100000",
"output": "16"
}
] | 1,581,787,625 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 8 | 155 | 0 | n = int(input(), 2)
steps = 0
while n != 1:
if n % 2 == 1:
n += 1
else:
n /= 2
steps += 1
print(steps)
| Title: Binary Number
Time Limit: 1 seconds
Memory Limit: 256 megabytes
Problem Description:
Little walrus Fangy loves math very much. That's why when he is bored he plays with a number performing some operations.
Fangy takes some positive integer *x* and wants to get a number one from it. While *x* is not equal to 1, Fangy repeats the following action: if *x* is odd, then he adds 1 to it, otherwise he divides *x* by 2. Fangy knows that for any positive integer number the process ends in finite time.
How many actions should Fangy perform to get a number one from number *x*?
Input Specification:
The first line contains a positive integer *x* in a binary system. It is guaranteed that the first digit of *x* is different from a zero and the number of its digits does not exceed 106.
Output Specification:
Print the required number of actions.
Demo Input:
['1\n', '1001001\n', '101110\n']
Demo Output:
['0\n', '12\n', '8\n']
Note:
Let's consider the third sample. Number 101110 is even, which means that we should divide it by 2. After the dividing Fangy gets an odd number 10111 and adds one to it. Number 11000 can be divided by 2 three times in a row and get number 11. All that's left is to increase the number by one (we get 100), and then divide it by 2 two times in a row. As a result, we get 1. | ```python
n = int(input(), 2)
steps = 0
while n != 1:
if n % 2 == 1:
n += 1
else:
n /= 2
steps += 1
print(steps)
``` | 0 |
371 | D | Vessels | PROGRAMMING | 1,800 | [
"data structures",
"dsu",
"implementation",
"trees"
] | null | null | There is a system of *n* vessels arranged one above the other as shown in the figure below. Assume that the vessels are numbered from 1 to *n*, in the order from the highest to the lowest, the volume of the *i*-th vessel is *a**i* liters.
Initially, all the vessels are empty. In some vessels water is poured. All the water that overflows from the *i*-th vessel goes to the (*i*<=+<=1)-th one. The liquid that overflows from the *n*-th vessel spills on the floor.
Your task is to simulate pouring water into the vessels. To do this, you will need to handle two types of queries:
1. Add *x**i* liters of water to the *p**i*-th vessel; 1. Print the number of liters of water in the *k**i*-th vessel.
When you reply to the second request you can assume that all the water poured up to this point, has already overflown between the vessels. | The first line contains integer *n* — the number of vessels (1<=≤<=*n*<=≤<=2·105). The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* — the vessels' capacities (1<=≤<=*a**i*<=≤<=109). The vessels' capacities do not necessarily increase from the top vessels to the bottom ones (see the second sample). The third line contains integer *m* — the number of queries (1<=≤<=*m*<=≤<=2·105). Each of the next *m* lines contains the description of one query. The query of the first type is represented as "1 *p**i* *x**i*", the query of the second type is represented as "2 *k**i*" (1<=≤<=*p**i*<=≤<=*n*, 1<=≤<=*x**i*<=≤<=109, 1<=≤<=*k**i*<=≤<=*n*). | For each query, print on a single line the number of liters of water in the corresponding vessel. | [
"2\n5 10\n6\n1 1 4\n2 1\n1 2 5\n1 1 4\n2 1\n2 2\n",
"3\n5 10 8\n6\n1 1 12\n2 2\n1 1 6\n1 3 2\n2 2\n2 3\n"
] | [
"4\n5\n8\n",
"7\n10\n5\n"
] | none | 2,000 | [
{
"input": "2\n5 10\n6\n1 1 4\n2 1\n1 2 5\n1 1 4\n2 1\n2 2",
"output": "4\n5\n8"
},
{
"input": "3\n5 10 8\n6\n1 1 12\n2 2\n1 1 6\n1 3 2\n2 2\n2 3",
"output": "7\n10\n5"
},
{
"input": "10\n71 59 88 55 18 98 38 73 53 58\n20\n1 5 93\n1 7 69\n2 3\n1 1 20\n2 10\n1 6 74\n1 7 100\n1 9 14\n2 3\n2 4\n2 7\n1 3 31\n2 4\n1 6 64\n2 2\n2 2\n1 3 54\n2 9\n2 1\n1 6 86",
"output": "0\n0\n0\n0\n38\n0\n0\n0\n53\n20"
},
{
"input": "10\n3 7 10 1 5 4 4 3 3 1\n20\n2 4\n2 4\n1 1 10\n1 1 10\n2 4\n2 3\n1 4 2\n1 4 6\n2 2\n1 8 9\n2 2\n2 5\n2 9\n1 2 1\n1 6 9\n1 1 6\n2 5\n2 2\n2 3\n1 4 10",
"output": "0\n0\n0\n10\n7\n7\n5\n3\n5\n7\n10"
},
{
"input": "50\n57 63 98 44 22 63 5 65 36 69 49 54 61 15 29 79 50 30 43 93 18 94 46 92 72 67 67 51 34 40 50 77 58 53 79 72 72 34 91 75 83 67 71 80 11 51 85 20 6 3\n20\n2 40\n1 14 102\n2 22\n2 15\n2 43\n1 29 532\n2 27\n2 47\n1 24 107\n1 20 720\n1 21 315\n2 20\n1 2 787\n1 27 532\n2 38\n1 32 445\n1 38 17\n1 26 450\n2 40\n1 45 192",
"output": "0\n0\n29\n0\n0\n0\n93\n34\n75"
},
{
"input": "1\n1\n1\n2 1",
"output": "0"
}
] | 1,616,029,501 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 7 | 529 | 18,739,200 | n = int(input())
capacidades = list(map(int, input().split()))
copos = [0 for x in range(n)]
m = int(input())
consultas = [tuple(map(int, input().split())) for x in range(m)]
def atualizar(p, x):
if len(copos) <= p:
return
if capacidades[p] - copos[p] < x:
cheio = capacidades[p] - copos[p]
else:
cheio = x
x -= cheio
copos[p] += cheio
if x > 0:
atualizar(p+1, x)
for consulta in consultas:
if consulta[0] == 1:
atualizar(consulta[1]-1, consulta[2])
else:
print(copos[consulta[1]-1]) | Title: Vessels
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
There is a system of *n* vessels arranged one above the other as shown in the figure below. Assume that the vessels are numbered from 1 to *n*, in the order from the highest to the lowest, the volume of the *i*-th vessel is *a**i* liters.
Initially, all the vessels are empty. In some vessels water is poured. All the water that overflows from the *i*-th vessel goes to the (*i*<=+<=1)-th one. The liquid that overflows from the *n*-th vessel spills on the floor.
Your task is to simulate pouring water into the vessels. To do this, you will need to handle two types of queries:
1. Add *x**i* liters of water to the *p**i*-th vessel; 1. Print the number of liters of water in the *k**i*-th vessel.
When you reply to the second request you can assume that all the water poured up to this point, has already overflown between the vessels.
Input Specification:
The first line contains integer *n* — the number of vessels (1<=≤<=*n*<=≤<=2·105). The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* — the vessels' capacities (1<=≤<=*a**i*<=≤<=109). The vessels' capacities do not necessarily increase from the top vessels to the bottom ones (see the second sample). The third line contains integer *m* — the number of queries (1<=≤<=*m*<=≤<=2·105). Each of the next *m* lines contains the description of one query. The query of the first type is represented as "1 *p**i* *x**i*", the query of the second type is represented as "2 *k**i*" (1<=≤<=*p**i*<=≤<=*n*, 1<=≤<=*x**i*<=≤<=109, 1<=≤<=*k**i*<=≤<=*n*).
Output Specification:
For each query, print on a single line the number of liters of water in the corresponding vessel.
Demo Input:
['2\n5 10\n6\n1 1 4\n2 1\n1 2 5\n1 1 4\n2 1\n2 2\n', '3\n5 10 8\n6\n1 1 12\n2 2\n1 1 6\n1 3 2\n2 2\n2 3\n']
Demo Output:
['4\n5\n8\n', '7\n10\n5\n']
Note:
none | ```python
n = int(input())
capacidades = list(map(int, input().split()))
copos = [0 for x in range(n)]
m = int(input())
consultas = [tuple(map(int, input().split())) for x in range(m)]
def atualizar(p, x):
if len(copos) <= p:
return
if capacidades[p] - copos[p] < x:
cheio = capacidades[p] - copos[p]
else:
cheio = x
x -= cheio
copos[p] += cheio
if x > 0:
atualizar(p+1, x)
for consulta in consultas:
if consulta[0] == 1:
atualizar(consulta[1]-1, consulta[2])
else:
print(copos[consulta[1]-1])
``` | -1 |
|
137 | C | History | PROGRAMMING | 1,500 | [
"sortings"
] | null | null | Polycarpus likes studying at school a lot and he is always diligent about his homework. Polycarpus has never had any problems with natural sciences as his great-great-grandfather was the great physicist Seinstein. On the other hand though, Polycarpus has never had an easy time with history.
Everybody knows that the World history encompasses exactly *n* events: the *i*-th event had continued from the year *a**i* to the year *b**i* inclusive (*a**i*<=<<=*b**i*). Polycarpus easily learned the dates when each of *n* events started and ended (Polycarpus inherited excellent memory from his great-great-granddad). But the teacher gave him a more complicated task: Polycaprus should know when all events began and ended and he should also find out for each event whether it includes another event. Polycarpus' teacher thinks that an event *j* includes an event *i* if *a**j*<=<<=*a**i* and *b**i*<=<<=*b**j*. Your task is simpler: find the number of events that are included in some other event. | The first input line contains integer *n* (1<=≤<=*n*<=≤<=105) which represents the number of events. Next *n* lines contain descriptions of the historical events, one event per line. The *i*<=+<=1 line contains two integers *a**i* and *b**i* (1<=≤<=*a**i*<=<<=*b**i*<=≤<=109) — the beginning and the end of the *i*-th event. No two events start or finish in the same year, that is, *a**i*<=≠<=*a**j*,<=*a**i*<=≠<=*b**j*,<=*b**i*<=≠<=*a**j*,<=*b**i*<=≠<=*b**j* for all *i*, *j* (where *i*<=≠<=*j*). Events are given in arbitrary order. | Print the only integer — the answer to the problem. | [
"5\n1 10\n2 9\n3 8\n4 7\n5 6\n",
"5\n1 100\n2 50\n51 99\n52 98\n10 60\n",
"1\n1 1000000000\n"
] | [
"4\n",
"4\n",
"0\n"
] | In the first example the fifth event is contained in the fourth. Similarly, the fourth event is contained in the third, the third — in the second and the second — in the first.
In the second example all events except the first one are contained in the first.
In the third example only one event, so the answer is 0. | 1,500 | [
{
"input": "5\n1 10\n2 9\n3 8\n4 7\n5 6",
"output": "4"
},
{
"input": "5\n1 100\n2 50\n51 99\n52 98\n10 60",
"output": "4"
},
{
"input": "1\n1 1000000000",
"output": "0"
},
{
"input": "2\n100 1000\n500 1500",
"output": "0"
},
{
"input": "4\n1 100\n50 150\n120 200\n180 220",
"output": "0"
},
{
"input": "10\n1 20\n2 19\n3 18\n4 17\n5 16\n6 15\n7 14\n8 13\n9 12\n10 11",
"output": "9"
},
{
"input": "4\n1 5\n2 4\n10 15\n11 14",
"output": "2"
},
{
"input": "10\n1 2\n3 4\n5 6\n7 8\n9 10\n11 12\n13 14\n15 16\n17 18\n19 20",
"output": "0"
},
{
"input": "10\n58 22116\n112840 772160\n127432 399484\n182031 255417\n459340 548097\n603984 739189\n606173 663033\n280170 366159\n779239 906234\n874623 892907",
"output": "7"
},
{
"input": "2\n2 3\n1 4",
"output": "1"
},
{
"input": "3\n9 10\n1 2\n3 4",
"output": "0"
},
{
"input": "4\n1 2\n3 6\n4 5\n10 11",
"output": "1"
},
{
"input": "2\n5 6\n1 10",
"output": "1"
},
{
"input": "7\n1 10\n2 5\n3 9\n100 1000\n200 500\n1001 1002\n777 7777",
"output": "4"
}
] | 1,588,083,198 | 2,147,483,647 | PyPy 3 | OK | TESTS | 75 | 872 | 78,950,400 | import sys
from math import log2,floor,ceil,sqrt,gcd
import bisect
# from collections import deque
sys.setrecursionlimit(10**5)
Ri = lambda : [int(x) for x in sys.stdin.readline().split()]
ri = lambda : sys.stdin.readline().strip()
def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
INF = 10 ** 18
MOD = 1000000007
n =int(ri())
lis = []
for i in range(n):
temp = Ri()
lis.append(temp)
lis.sort(key = lambda x : x[0])
cnt = 0
right = lis[0][1]
for i in range(1,len(lis)):
if lis[i][1] < right:
cnt+=1
else:
right= lis[i][1]
print(cnt) | Title: History
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Polycarpus likes studying at school a lot and he is always diligent about his homework. Polycarpus has never had any problems with natural sciences as his great-great-grandfather was the great physicist Seinstein. On the other hand though, Polycarpus has never had an easy time with history.
Everybody knows that the World history encompasses exactly *n* events: the *i*-th event had continued from the year *a**i* to the year *b**i* inclusive (*a**i*<=<<=*b**i*). Polycarpus easily learned the dates when each of *n* events started and ended (Polycarpus inherited excellent memory from his great-great-granddad). But the teacher gave him a more complicated task: Polycaprus should know when all events began and ended and he should also find out for each event whether it includes another event. Polycarpus' teacher thinks that an event *j* includes an event *i* if *a**j*<=<<=*a**i* and *b**i*<=<<=*b**j*. Your task is simpler: find the number of events that are included in some other event.
Input Specification:
The first input line contains integer *n* (1<=≤<=*n*<=≤<=105) which represents the number of events. Next *n* lines contain descriptions of the historical events, one event per line. The *i*<=+<=1 line contains two integers *a**i* and *b**i* (1<=≤<=*a**i*<=<<=*b**i*<=≤<=109) — the beginning and the end of the *i*-th event. No two events start or finish in the same year, that is, *a**i*<=≠<=*a**j*,<=*a**i*<=≠<=*b**j*,<=*b**i*<=≠<=*a**j*,<=*b**i*<=≠<=*b**j* for all *i*, *j* (where *i*<=≠<=*j*). Events are given in arbitrary order.
Output Specification:
Print the only integer — the answer to the problem.
Demo Input:
['5\n1 10\n2 9\n3 8\n4 7\n5 6\n', '5\n1 100\n2 50\n51 99\n52 98\n10 60\n', '1\n1 1000000000\n']
Demo Output:
['4\n', '4\n', '0\n']
Note:
In the first example the fifth event is contained in the fourth. Similarly, the fourth event is contained in the third, the third — in the second and the second — in the first.
In the second example all events except the first one are contained in the first.
In the third example only one event, so the answer is 0. | ```python
import sys
from math import log2,floor,ceil,sqrt,gcd
import bisect
# from collections import deque
sys.setrecursionlimit(10**5)
Ri = lambda : [int(x) for x in sys.stdin.readline().split()]
ri = lambda : sys.stdin.readline().strip()
def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
INF = 10 ** 18
MOD = 1000000007
n =int(ri())
lis = []
for i in range(n):
temp = Ri()
lis.append(temp)
lis.sort(key = lambda x : x[0])
cnt = 0
right = lis[0][1]
for i in range(1,len(lis)):
if lis[i][1] < right:
cnt+=1
else:
right= lis[i][1]
print(cnt)
``` | 3 |
|
568 | A | Primes or Palindromes? | PROGRAMMING | 1,600 | [
"brute force",
"implementation",
"math",
"number theory"
] | null | null | Rikhail Mubinchik believes that the current definition of prime numbers is obsolete as they are too complex and unpredictable. A palindromic number is another matter. It is aesthetically pleasing, and it has a number of remarkable properties. Help Rikhail to convince the scientific community in this!
Let us remind you that a number is called prime if it is integer larger than one, and is not divisible by any positive integer other than itself and one.
Rikhail calls a number a palindromic if it is integer, positive, and its decimal representation without leading zeros is a palindrome, i.e. reads the same from left to right and right to left.
One problem with prime numbers is that there are too many of them. Let's introduce the following notation: π(*n*) — the number of primes no larger than *n*, *rub*(*n*) — the number of palindromic numbers no larger than *n*. Rikhail wants to prove that there are a lot more primes than palindromic ones.
He asked you to solve the following problem: for a given value of the coefficient *A* find the maximum *n*, such that π(*n*)<=≤<=*A*·*rub*(*n*). | The input consists of two positive integers *p*, *q*, the numerator and denominator of the fraction that is the value of *A* (, ). | If such maximum number exists, then print it. Otherwise, print "Palindromic tree is better than splay tree" (without the quotes). | [
"1 1\n",
"1 42\n",
"6 4\n"
] | [
"40\n",
"1\n",
"172\n"
] | none | 500 | [
{
"input": "1 1",
"output": "40"
},
{
"input": "1 42",
"output": "1"
},
{
"input": "6 4",
"output": "172"
},
{
"input": "3 1",
"output": "2530"
},
{
"input": "42 1",
"output": "1179858"
},
{
"input": "10000 239",
"output": "1168638"
},
{
"input": "5 8",
"output": "16"
},
{
"input": "7 11",
"output": "16"
},
{
"input": "16 60",
"output": "1"
},
{
"input": "214 210",
"output": "40"
},
{
"input": "620 35",
"output": "251262"
},
{
"input": "940 480",
"output": "1372"
},
{
"input": "1307 3420",
"output": "1"
},
{
"input": "6811 5416",
"output": "66"
},
{
"input": "7 267",
"output": "1"
},
{
"input": "106 6",
"output": "250300"
},
{
"input": "10000 10000",
"output": "40"
},
{
"input": "10000 9999",
"output": "40"
},
{
"input": "9999 9998",
"output": "40"
},
{
"input": "9999 9999",
"output": "40"
},
{
"input": "4 9",
"output": "10"
},
{
"input": "1000 10000",
"output": "1"
},
{
"input": "238 9996",
"output": "1"
},
{
"input": "999 10000",
"output": "1"
},
{
"input": "241 10000",
"output": "1"
},
{
"input": "239 10000",
"output": "1"
},
{
"input": "5858 674",
"output": "71118"
}
] | 1,538,431,189 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 0 | 3,000 | 29,081,600 | def is_palindrome(num):
copia = num
if num < 10:
return True
nums = []
while(True):
nums.append(copia % 10)
copia //= 10
if copia == 0:
break
digitos = len(nums) // 2
j = len(nums) - 1
for i in range(digitos):
if nums[i] != nums[j]:
return False
j -= 1
return True
def palindromes(x):
palindrome = []
count = 0
i = 1
while(i <= x):
if is_palindrome(i):
count += 1
palindrome.append(count)
i += 1
return palindrome
def primes(x):
primes = [True] * x
primes[0] = False
primos = [0]
count = 0
i = 1
while(i * i < x):
if primes[i] == True:
count += 1
for j in range(i, x, i + 1):
primes[j] = False
primos.append(count)
i += 1
while(i < x):
if primes[i] == True:
count += 1
primos.append(count)
i += 1
return primos
primos = primes(2000000)
palindromes = palindromes(2000000)
num = input().split()
num = [int(num[0]), int(num[1])]
i = 0
resultado = 0
while(i < 2000000):
res = ((palindromes[i]) * num[0]) / num[1]
if res >= primos[i]:
resultado = i + 1
i += 1
if resultado == 0:
print("Palindromic tree is better than splay tree")
else:
print(resultado)
| Title: Primes or Palindromes?
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Rikhail Mubinchik believes that the current definition of prime numbers is obsolete as they are too complex and unpredictable. A palindromic number is another matter. It is aesthetically pleasing, and it has a number of remarkable properties. Help Rikhail to convince the scientific community in this!
Let us remind you that a number is called prime if it is integer larger than one, and is not divisible by any positive integer other than itself and one.
Rikhail calls a number a palindromic if it is integer, positive, and its decimal representation without leading zeros is a palindrome, i.e. reads the same from left to right and right to left.
One problem with prime numbers is that there are too many of them. Let's introduce the following notation: π(*n*) — the number of primes no larger than *n*, *rub*(*n*) — the number of palindromic numbers no larger than *n*. Rikhail wants to prove that there are a lot more primes than palindromic ones.
He asked you to solve the following problem: for a given value of the coefficient *A* find the maximum *n*, such that π(*n*)<=≤<=*A*·*rub*(*n*).
Input Specification:
The input consists of two positive integers *p*, *q*, the numerator and denominator of the fraction that is the value of *A* (, ).
Output Specification:
If such maximum number exists, then print it. Otherwise, print "Palindromic tree is better than splay tree" (without the quotes).
Demo Input:
['1 1\n', '1 42\n', '6 4\n']
Demo Output:
['40\n', '1\n', '172\n']
Note:
none | ```python
def is_palindrome(num):
copia = num
if num < 10:
return True
nums = []
while(True):
nums.append(copia % 10)
copia //= 10
if copia == 0:
break
digitos = len(nums) // 2
j = len(nums) - 1
for i in range(digitos):
if nums[i] != nums[j]:
return False
j -= 1
return True
def palindromes(x):
palindrome = []
count = 0
i = 1
while(i <= x):
if is_palindrome(i):
count += 1
palindrome.append(count)
i += 1
return palindrome
def primes(x):
primes = [True] * x
primes[0] = False
primos = [0]
count = 0
i = 1
while(i * i < x):
if primes[i] == True:
count += 1
for j in range(i, x, i + 1):
primes[j] = False
primos.append(count)
i += 1
while(i < x):
if primes[i] == True:
count += 1
primos.append(count)
i += 1
return primos
primos = primes(2000000)
palindromes = palindromes(2000000)
num = input().split()
num = [int(num[0]), int(num[1])]
i = 0
resultado = 0
while(i < 2000000):
res = ((palindromes[i]) * num[0]) / num[1]
if res >= primos[i]:
resultado = i + 1
i += 1
if resultado == 0:
print("Palindromic tree is better than splay tree")
else:
print(resultado)
``` | 0 |
|
520 | B | Two Buttons | PROGRAMMING | 1,400 | [
"dfs and similar",
"graphs",
"greedy",
"implementation",
"math",
"shortest paths"
] | null | null | Vasya has found a strange device. On the front panel of a device there are: a red button, a blue button and a display showing some positive integer. After clicking the red button, device multiplies the displayed number by two. After clicking the blue button, device subtracts one from the number on the display. If at some point the number stops being positive, the device breaks down. The display can show arbitrarily large numbers. Initially, the display shows number *n*.
Bob wants to get number *m* on the display. What minimum number of clicks he has to make in order to achieve this result? | The first and the only line of the input contains two distinct integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=104), separated by a space . | Print a single number — the minimum number of times one needs to push the button required to get the number *m* out of number *n*. | [
"4 6\n",
"10 1\n"
] | [
"2\n",
"9\n"
] | In the first example you need to push the blue button once, and then push the red button once.
In the second example, doubling the number is unnecessary, so we need to push the blue button nine times. | 1,000 | [
{
"input": "4 6",
"output": "2"
},
{
"input": "10 1",
"output": "9"
},
{
"input": "1 2",
"output": "1"
},
{
"input": "2 1",
"output": "1"
},
{
"input": "1 3",
"output": "3"
},
{
"input": "3 1",
"output": "2"
},
{
"input": "2 10",
"output": "5"
},
{
"input": "100 99",
"output": "1"
},
{
"input": "99 100",
"output": "50"
},
{
"input": "10 17",
"output": "3"
},
{
"input": "666 6666",
"output": "255"
},
{
"input": "6666 666",
"output": "6000"
},
{
"input": "1 8192",
"output": "13"
},
{
"input": "1 8193",
"output": "27"
},
{
"input": "9999 10000",
"output": "5000"
},
{
"input": "10000 9999",
"output": "1"
},
{
"input": "10000 1",
"output": "9999"
},
{
"input": "1234 5678",
"output": "528"
},
{
"input": "9102 9103",
"output": "4552"
},
{
"input": "8192 1",
"output": "8191"
},
{
"input": "9912 1023",
"output": "8889"
},
{
"input": "100 500",
"output": "41"
},
{
"input": "9997 9999",
"output": "4999"
},
{
"input": "5000 10000",
"output": "1"
},
{
"input": "4000 7997",
"output": "3"
},
{
"input": "1 10000",
"output": "20"
},
{
"input": "1 8191",
"output": "14"
},
{
"input": "9999 10000",
"output": "5000"
},
{
"input": "9097 9998",
"output": "4099"
},
{
"input": "886 9383",
"output": "305"
},
{
"input": "1 9",
"output": "7"
},
{
"input": "1918 10000",
"output": "671"
},
{
"input": "1 3",
"output": "3"
},
{
"input": "1 4",
"output": "2"
},
{
"input": "2 10000",
"output": "19"
},
{
"input": "3 10000",
"output": "17"
},
{
"input": "4 10000",
"output": "18"
},
{
"input": "9998 10000",
"output": "4999"
},
{
"input": "5000 10000",
"output": "1"
},
{
"input": "5001 10000",
"output": "2"
},
{
"input": "10000 1",
"output": "9999"
},
{
"input": "1 9999",
"output": "21"
},
{
"input": "7777 9999",
"output": "2779"
},
{
"input": "2 100",
"output": "9"
},
{
"input": "10 8722",
"output": "18"
},
{
"input": "848 4561",
"output": "283"
},
{
"input": "9967 9973",
"output": "4982"
},
{
"input": "5555 10000",
"output": "556"
},
{
"input": "999 10000",
"output": "378"
},
{
"input": "3 6",
"output": "1"
},
{
"input": "9 38",
"output": "8"
}
] | 1,698,290,071 | 2,147,483,647 | Python 3 | OK | TESTS | 51 | 61 | 1,228,800 | from collections import deque
n, m = map(int, input().split())
queue = deque([(n, 0)])
visited = set()
while queue:
current, clicks = queue.popleft()
if current == m:
print(clicks)
break
if current * 2 not in visited and current * 2 <= 10**4:
queue.append((current * 2, clicks + 1))
visited.add(current * 2)
if current - 1 > 0 and current - 1 not in visited:
queue.append((current - 1, clicks + 1))
visited.add(current - 1)
| Title: Two Buttons
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vasya has found a strange device. On the front panel of a device there are: a red button, a blue button and a display showing some positive integer. After clicking the red button, device multiplies the displayed number by two. After clicking the blue button, device subtracts one from the number on the display. If at some point the number stops being positive, the device breaks down. The display can show arbitrarily large numbers. Initially, the display shows number *n*.
Bob wants to get number *m* on the display. What minimum number of clicks he has to make in order to achieve this result?
Input Specification:
The first and the only line of the input contains two distinct integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=104), separated by a space .
Output Specification:
Print a single number — the minimum number of times one needs to push the button required to get the number *m* out of number *n*.
Demo Input:
['4 6\n', '10 1\n']
Demo Output:
['2\n', '9\n']
Note:
In the first example you need to push the blue button once, and then push the red button once.
In the second example, doubling the number is unnecessary, so we need to push the blue button nine times. | ```python
from collections import deque
n, m = map(int, input().split())
queue = deque([(n, 0)])
visited = set()
while queue:
current, clicks = queue.popleft()
if current == m:
print(clicks)
break
if current * 2 not in visited and current * 2 <= 10**4:
queue.append((current * 2, clicks + 1))
visited.add(current * 2)
if current - 1 > 0 and current - 1 not in visited:
queue.append((current - 1, clicks + 1))
visited.add(current - 1)
``` | 3 |
|
336 | A | Vasily the Bear and Triangle | PROGRAMMING | 1,000 | [
"implementation",
"math"
] | null | null | Vasily the bear has a favorite rectangle, it has one vertex at point (0,<=0), and the opposite vertex at point (*x*,<=*y*). Of course, the sides of Vasya's favorite rectangle are parallel to the coordinate axes.
Vasya also loves triangles, if the triangles have one vertex at point *B*<==<=(0,<=0). That's why today he asks you to find two points *A*<==<=(*x*1,<=*y*1) and *C*<==<=(*x*2,<=*y*2), such that the following conditions hold:
- the coordinates of points: *x*1, *x*2, *y*1, *y*2 are integers. Besides, the following inequation holds: *x*1<=<<=*x*2; - the triangle formed by point *A*, *B* and *C* is rectangular and isosceles ( is right); - all points of the favorite rectangle are located inside or on the border of triangle *ABC*; - the area of triangle *ABC* is as small as possible.
Help the bear, find the required points. It is not so hard to proof that these points are unique. | The first line contains two integers *x*,<=*y* (<=-<=109<=≤<=*x*,<=*y*<=≤<=109,<=*x*<=≠<=0,<=*y*<=≠<=0). | Print in the single line four integers *x*1,<=*y*1,<=*x*2,<=*y*2 — the coordinates of the required points. | [
"10 5\n",
"-10 5\n"
] | [
"0 15 15 0\n",
"-15 0 0 15\n"
] | <img class="tex-graphics" src="https://espresso.codeforces.com/a9ea2088c4294ce8f23801562fda36b830df2c3f.png" style="max-width: 100.0%;max-height: 100.0%;"/>
Figure to the first sample | 500 | [
{
"input": "10 5",
"output": "0 15 15 0"
},
{
"input": "-10 5",
"output": "-15 0 0 15"
},
{
"input": "20 -10",
"output": "0 -30 30 0"
},
{
"input": "-10 -1000000000",
"output": "-1000000010 0 0 -1000000010"
},
{
"input": "-1000000000 -1000000000",
"output": "-2000000000 0 0 -2000000000"
},
{
"input": "1000000000 1000000000",
"output": "0 2000000000 2000000000 0"
},
{
"input": "-123131 3123141",
"output": "-3246272 0 0 3246272"
},
{
"input": "-23423 -243242423",
"output": "-243265846 0 0 -243265846"
},
{
"input": "123112 4560954",
"output": "0 4684066 4684066 0"
},
{
"input": "1321 -23131",
"output": "0 -24452 24452 0"
},
{
"input": "1000000000 999999999",
"output": "0 1999999999 1999999999 0"
},
{
"input": "54543 432423",
"output": "0 486966 486966 0"
},
{
"input": "1 1",
"output": "0 2 2 0"
},
{
"input": "-1 -1",
"output": "-2 0 0 -2"
},
{
"input": "-1 1",
"output": "-2 0 0 2"
},
{
"input": "1 -1",
"output": "0 -2 2 0"
},
{
"input": "42 -2",
"output": "0 -44 44 0"
},
{
"input": "2 -435",
"output": "0 -437 437 0"
},
{
"input": "76 -76",
"output": "0 -152 152 0"
},
{
"input": "1000000000 1",
"output": "0 1000000001 1000000001 0"
},
{
"input": "1000000000 -1",
"output": "0 -1000000001 1000000001 0"
},
{
"input": "-1000000000 1",
"output": "-1000000001 0 0 1000000001"
},
{
"input": "-1000000000 -1",
"output": "-1000000001 0 0 -1000000001"
},
{
"input": "1000000000 -999999999",
"output": "0 -1999999999 1999999999 0"
},
{
"input": "-1000000000 999999999",
"output": "-1999999999 0 0 1999999999"
},
{
"input": "-1000000000 -999999999",
"output": "-1999999999 0 0 -1999999999"
},
{
"input": "999999999 1000000000",
"output": "0 1999999999 1999999999 0"
},
{
"input": "-999999999 1000000000",
"output": "-1999999999 0 0 1999999999"
},
{
"input": "999999999 -1000000000",
"output": "0 -1999999999 1999999999 0"
},
{
"input": "-999999999 -1000000000",
"output": "-1999999999 0 0 -1999999999"
}
] | 1,602,661,831 | 2,147,483,647 | Python 3 | OK | TESTS | 30 | 186 | 0 | n=input().split()
x,y=int(n[0]),int(n[1])
if x>0 and y>0:
print(0,x+y,x+y,0)
elif x>0 and y<0:
print(0,y-x,x-y,0)
elif x<0 and y>0:
print(x-y,0,0,y-x)
else:
print(x+y,0,0,x+y) | Title: Vasily the Bear and Triangle
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vasily the bear has a favorite rectangle, it has one vertex at point (0,<=0), and the opposite vertex at point (*x*,<=*y*). Of course, the sides of Vasya's favorite rectangle are parallel to the coordinate axes.
Vasya also loves triangles, if the triangles have one vertex at point *B*<==<=(0,<=0). That's why today he asks you to find two points *A*<==<=(*x*1,<=*y*1) and *C*<==<=(*x*2,<=*y*2), such that the following conditions hold:
- the coordinates of points: *x*1, *x*2, *y*1, *y*2 are integers. Besides, the following inequation holds: *x*1<=<<=*x*2; - the triangle formed by point *A*, *B* and *C* is rectangular and isosceles ( is right); - all points of the favorite rectangle are located inside or on the border of triangle *ABC*; - the area of triangle *ABC* is as small as possible.
Help the bear, find the required points. It is not so hard to proof that these points are unique.
Input Specification:
The first line contains two integers *x*,<=*y* (<=-<=109<=≤<=*x*,<=*y*<=≤<=109,<=*x*<=≠<=0,<=*y*<=≠<=0).
Output Specification:
Print in the single line four integers *x*1,<=*y*1,<=*x*2,<=*y*2 — the coordinates of the required points.
Demo Input:
['10 5\n', '-10 5\n']
Demo Output:
['0 15 15 0\n', '-15 0 0 15\n']
Note:
<img class="tex-graphics" src="https://espresso.codeforces.com/a9ea2088c4294ce8f23801562fda36b830df2c3f.png" style="max-width: 100.0%;max-height: 100.0%;"/>
Figure to the first sample | ```python
n=input().split()
x,y=int(n[0]),int(n[1])
if x>0 and y>0:
print(0,x+y,x+y,0)
elif x>0 and y<0:
print(0,y-x,x-y,0)
elif x<0 and y>0:
print(x-y,0,0,y-x)
else:
print(x+y,0,0,x+y)
``` | 3 |
|
898 | C | Phone Numbers | PROGRAMMING | 1,400 | [
"implementation",
"strings"
] | null | null | Vasya has several phone books, in which he recorded the telephone numbers of his friends. Each of his friends can have one or several phone numbers.
Vasya decided to organize information about the phone numbers of friends. You will be given *n* strings — all entries from Vasya's phone books. Each entry starts with a friend's name. Then follows the number of phone numbers in the current entry, and then the phone numbers themselves. It is possible that several identical phones are recorded in the same record.
Vasya also believes that if the phone number *a* is a suffix of the phone number *b* (that is, the number *b* ends up with *a*), and both numbers are written by Vasya as the phone numbers of the same person, then *a* is recorded without the city code and it should not be taken into account.
The task is to print organized information about the phone numbers of Vasya's friends. It is possible that two different people have the same number. If one person has two numbers *x* and *y*, and *x* is a suffix of *y* (that is, *y* ends in *x*), then you shouldn't print number *x*. If the number of a friend in the Vasya's phone books is recorded several times in the same format, it is necessary to take it into account exactly once.
Read the examples to understand statement and format of the output better. | First line contains the integer *n* (1<=≤<=*n*<=≤<=20) — number of entries in Vasya's phone books.
The following *n* lines are followed by descriptions of the records in the format described in statement. Names of Vasya's friends are non-empty strings whose length does not exceed 10. They consists only of lowercase English letters. Number of phone numbers in one entry is not less than 1 is not more than 10. The telephone numbers consist of digits only. If you represent a phone number as a string, then its length will be in range from 1 to 10. Phone numbers can contain leading zeros. | Print out the ordered information about the phone numbers of Vasya's friends. First output *m* — number of friends that are found in Vasya's phone books.
The following *m* lines must contain entries in the following format "name number_of_phone_numbers phone_numbers". Phone numbers should be separated by a space. Each record must contain all the phone numbers of current friend.
Entries can be displayed in arbitrary order, phone numbers for one record can also be printed in arbitrary order. | [
"2\nivan 1 00123\nmasha 1 00123\n",
"3\nkarl 2 612 12\npetr 1 12\nkatya 1 612\n",
"4\nivan 3 123 123 456\nivan 2 456 456\nivan 8 789 3 23 6 56 9 89 2\ndasha 2 23 789\n"
] | [
"2\nmasha 1 00123 \nivan 1 00123 \n",
"3\nkatya 1 612 \npetr 1 12 \nkarl 1 612 \n",
"2\ndasha 2 23 789 \nivan 4 789 123 2 456 \n"
] | none | 1,500 | [
{
"input": "2\nivan 1 00123\nmasha 1 00123",
"output": "2\nmasha 1 00123 \nivan 1 00123 "
},
{
"input": "3\nkarl 2 612 12\npetr 1 12\nkatya 1 612",
"output": "3\nkatya 1 612 \npetr 1 12 \nkarl 1 612 "
},
{
"input": "4\nivan 3 123 123 456\nivan 2 456 456\nivan 8 789 3 23 6 56 9 89 2\ndasha 2 23 789",
"output": "2\ndasha 2 789 23 \nivan 4 2 123 456 789 "
},
{
"input": "20\nnxj 6 7 6 6 7 7 7\nnxj 10 8 5 1 7 6 1 0 7 0 6\nnxj 2 6 5\nnxj 10 6 7 6 6 5 8 3 6 6 8\nnxj 10 6 1 7 6 7 1 8 7 8 6\nnxj 10 8 5 8 6 5 6 1 9 6 3\nnxj 10 8 1 6 4 8 0 4 6 0 1\nnxj 9 2 6 6 8 1 1 3 6 6\nnxj 10 8 9 0 9 1 3 2 3 2 3\nnxj 6 6 7 0 8 1 2\nnxj 7 7 7 8 1 3 6 9\nnxj 10 2 7 0 1 5 1 9 1 2 6\nnxj 6 9 6 9 6 3 7\nnxj 9 0 1 7 8 2 6 6 5 6\nnxj 4 0 2 3 7\nnxj 10 0 4 0 6 1 1 8 8 4 7\nnxj 8 4 6 2 6 6 1 2 7\nnxj 10 5 3 4 2 1 0 7 0 7 6\nnxj 10 9 6 0 6 1 6 2 1 9 6\nnxj 4 2 9 0 1",
"output": "1\nnxj 10 4 1 8 7 5 3 6 9 0 2 "
},
{
"input": "20\nl 6 02 02 2 02 02 2\nl 8 8 8 8 2 62 13 31 3\ne 9 0 91 0 0 60 91 60 2 44\ne 9 69 2 1 44 2 91 66 1 70\nl 9 7 27 27 3 1 3 7 80 81\nl 9 2 1 13 7 2 10 02 3 92\ne 9 0 15 3 5 5 15 91 09 44\nl 7 2 50 4 5 98 31 98\nl 3 26 7 3\ne 6 7 5 0 62 65 91\nl 8 80 0 4 0 2 2 0 13\nl 9 19 13 02 2 1 4 19 26 02\nl 10 7 39 7 9 22 22 26 2 90 4\ne 7 65 2 36 0 34 57 9\ne 8 13 02 09 91 73 5 36 62\nl 9 75 0 10 8 76 7 82 8 34\nl 7 34 0 19 80 6 4 7\ne 5 4 2 5 7 2\ne 7 4 02 69 7 07 20 2\nl 4 8 2 1 63",
"output": "2\ne 18 70 07 62 36 20 69 66 57 02 65 34 44 73 60 91 15 09 13 \nl 21 02 80 27 63 19 50 81 76 34 90 98 92 31 26 22 75 39 13 10 82 62 "
},
{
"input": "20\no 10 6 6 97 45 6 6 6 6 5 6\nl 8 5 5 5 19 59 5 8 5\nj 9 2 30 58 2 2 1 0 30 4\nc 10 1 1 7 51 7 7 51 1 1 1\no 9 7 97 87 70 2 19 2 14 6\ne 6 26 6 6 6 26 5\ng 9 3 3 3 3 3 78 69 8 9\nl 8 8 01 1 5 8 41 72 3\nz 10 1 2 2 2 9 1 9 1 6 7\ng 8 7 78 05 36 7 3 67 9\no 5 6 9 9 7 7\ne 10 30 2 1 1 2 5 04 0 6 6\ne 9 30 30 2 2 0 26 30 79 8\nt 10 2 2 9 29 7 7 7 9 2 9\nc 7 7 51 1 31 2 7 4\nc 9 83 1 6 78 94 74 54 8 32\ng 8 4 1 01 9 39 28 6 6\nt 7 9 2 01 4 4 9 58\nj 5 0 1 58 02 4\nw 10 80 0 91 91 06 91 9 9 27 7",
"output": "9\nw 5 91 06 27 9 80 \nt 6 01 29 4 58 2 7 \ne 8 2 8 30 04 26 5 79 1 \nl 8 8 41 72 01 19 59 3 5 \nj 5 58 02 1 4 30 \nz 5 7 9 6 2 1 \ng 10 39 67 3 01 36 4 05 69 78 28 \no 8 19 2 45 6 87 14 97 70 \nc 10 7 94 32 6 78 74 31 83 51 54 "
},
{
"input": "1\negew 5 3 123 23 1234 134",
"output": "1\negew 3 134 123 1234 "
}
] | 1,597,843,771 | 1,771 | PyPy 3 | WRONG_ANSWER | TESTS | 0 | 170 | 307,200 | import sys
input = sys.stdin.readline
from collections import *
def judge(s, t):
return s[len(s)-len(t):]==t
d = defaultdict(set)
for _ in range(int(input())):
l = list(input().split())
for num in l[2:]:
d[l[0]].add(num)
for k in d.keys():
ans = []
for num1 in d[k]:
flag = True
for num2 in d[k]:
if num1==num2:
continue
if judge(num2, num1):
flag = False
if flag:
ans.append(num1)
print(k, len(ans), *ans) | Title: Phone Numbers
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vasya has several phone books, in which he recorded the telephone numbers of his friends. Each of his friends can have one or several phone numbers.
Vasya decided to organize information about the phone numbers of friends. You will be given *n* strings — all entries from Vasya's phone books. Each entry starts with a friend's name. Then follows the number of phone numbers in the current entry, and then the phone numbers themselves. It is possible that several identical phones are recorded in the same record.
Vasya also believes that if the phone number *a* is a suffix of the phone number *b* (that is, the number *b* ends up with *a*), and both numbers are written by Vasya as the phone numbers of the same person, then *a* is recorded without the city code and it should not be taken into account.
The task is to print organized information about the phone numbers of Vasya's friends. It is possible that two different people have the same number. If one person has two numbers *x* and *y*, and *x* is a suffix of *y* (that is, *y* ends in *x*), then you shouldn't print number *x*. If the number of a friend in the Vasya's phone books is recorded several times in the same format, it is necessary to take it into account exactly once.
Read the examples to understand statement and format of the output better.
Input Specification:
First line contains the integer *n* (1<=≤<=*n*<=≤<=20) — number of entries in Vasya's phone books.
The following *n* lines are followed by descriptions of the records in the format described in statement. Names of Vasya's friends are non-empty strings whose length does not exceed 10. They consists only of lowercase English letters. Number of phone numbers in one entry is not less than 1 is not more than 10. The telephone numbers consist of digits only. If you represent a phone number as a string, then its length will be in range from 1 to 10. Phone numbers can contain leading zeros.
Output Specification:
Print out the ordered information about the phone numbers of Vasya's friends. First output *m* — number of friends that are found in Vasya's phone books.
The following *m* lines must contain entries in the following format "name number_of_phone_numbers phone_numbers". Phone numbers should be separated by a space. Each record must contain all the phone numbers of current friend.
Entries can be displayed in arbitrary order, phone numbers for one record can also be printed in arbitrary order.
Demo Input:
['2\nivan 1 00123\nmasha 1 00123\n', '3\nkarl 2 612 12\npetr 1 12\nkatya 1 612\n', '4\nivan 3 123 123 456\nivan 2 456 456\nivan 8 789 3 23 6 56 9 89 2\ndasha 2 23 789\n']
Demo Output:
['2\nmasha 1 00123 \nivan 1 00123 \n', '3\nkatya 1 612 \npetr 1 12 \nkarl 1 612 \n', '2\ndasha 2 23 789 \nivan 4 789 123 2 456 \n']
Note:
none | ```python
import sys
input = sys.stdin.readline
from collections import *
def judge(s, t):
return s[len(s)-len(t):]==t
d = defaultdict(set)
for _ in range(int(input())):
l = list(input().split())
for num in l[2:]:
d[l[0]].add(num)
for k in d.keys():
ans = []
for num1 in d[k]:
flag = True
for num2 in d[k]:
if num1==num2:
continue
if judge(num2, num1):
flag = False
if flag:
ans.append(num1)
print(k, len(ans), *ans)
``` | 0 |
|
0 | none | none | none | 0 | [
"none"
] | null | null | Theater stage is a rectangular field of size *n*<=×<=*m*. The director gave you the stage's plan which actors will follow. For each cell it is stated in the plan if there would be an actor in this cell or not.
You are to place a spotlight on the stage in some good position. The spotlight will project light in one of the four directions (if you look at the stage from above) — left, right, up or down. Thus, the spotlight's position is a cell it is placed to and a direction it shines.
A position is good if two conditions hold:
- there is no actor in the cell the spotlight is placed to; - there is at least one actor in the direction the spotlight projects.
Count the number of good positions for placing the spotlight. Two positions of spotlight are considered to be different if the location cells or projection direction differ. | The first line contains two positive integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=1000) — the number of rows and the number of columns in the plan.
The next *n* lines contain *m* integers, 0 or 1 each — the description of the plan. Integer 1, means there will be an actor in the corresponding cell, while 0 means the cell will remain empty. It is guaranteed that there is at least one actor in the plan. | Print one integer — the number of good positions for placing the spotlight. | [
"2 4\n0 1 0 0\n1 0 1 0\n",
"4 4\n0 0 0 0\n1 0 0 1\n0 1 1 0\n0 1 0 0\n"
] | [
"9\n",
"20\n"
] | In the first example the following positions are good:
1. the (1, 1) cell and right direction; 1. the (1, 1) cell and down direction; 1. the (1, 3) cell and left direction; 1. the (1, 3) cell and down direction; 1. the (1, 4) cell and left direction; 1. the (2, 2) cell and left direction; 1. the (2, 2) cell and up direction; 1. the (2, 2) and right direction; 1. the (2, 4) cell and left direction.
Therefore, there are 9 good positions in this example. | 0 | [
{
"input": "2 4\n0 1 0 0\n1 0 1 0",
"output": "9"
},
{
"input": "4 4\n0 0 0 0\n1 0 0 1\n0 1 1 0\n0 1 0 0",
"output": "20"
},
{
"input": "1 5\n1 1 0 0 0",
"output": "3"
},
{
"input": "2 10\n0 0 0 0 0 0 0 1 0 0\n1 0 0 0 0 0 0 0 0 0",
"output": "20"
},
{
"input": "3 1\n1\n0\n0",
"output": "2"
},
{
"input": "5 7\n0 0 0 0 0 0 1\n0 0 0 0 0 0 1\n0 0 0 1 0 0 0\n0 0 0 0 0 0 0\n0 0 0 0 0 0 0",
"output": "25"
},
{
"input": "10 20\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1\n1 1 1 1 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1",
"output": "4"
},
{
"input": "5 7\n0 0 0 0 0 0 0\n0 1 1 1 1 0 1\n0 1 1 1 1 1 1\n0 0 0 0 0 0 0\n0 1 1 1 1 0 1",
"output": "26"
},
{
"input": "10 20\n0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1\n0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1\n0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1\n0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1",
"output": "121"
},
{
"input": "1 2\n0 1",
"output": "1"
},
{
"input": "1 2\n1 0",
"output": "1"
},
{
"input": "1 2\n1 1",
"output": "0"
},
{
"input": "2 1\n1\n0",
"output": "1"
},
{
"input": "2 1\n0\n1",
"output": "1"
},
{
"input": "2 1\n1\n1",
"output": "0"
},
{
"input": "1 1\n1",
"output": "0"
},
{
"input": "4 4\n1 1 1 1\n1 0 0 1\n1 0 0 1\n1 1 1 1",
"output": "16"
}
] | 1,479,658,039 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 6 | 1,000 | 5,939,200 | n, m=map(int, input().split())
a=[list(map(int, input().split())) for _ in range(n)]
ans=p=0
def f(x):
global ans, p
if x==0:
ans+=p
else:
p=1
for i in range(n):
p=0
for j in range(m):
f(a[i][j])
p=0
for j in range(m-1, -1, -1):
f(a[i][j])
for i in range(m):
p=0
for j in range(n):
f(a[j][i])
p=0
for j in range(n-1, -1, -1):
f(a[j][i])
print(ans) | Title: none
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Theater stage is a rectangular field of size *n*<=×<=*m*. The director gave you the stage's plan which actors will follow. For each cell it is stated in the plan if there would be an actor in this cell or not.
You are to place a spotlight on the stage in some good position. The spotlight will project light in one of the four directions (if you look at the stage from above) — left, right, up or down. Thus, the spotlight's position is a cell it is placed to and a direction it shines.
A position is good if two conditions hold:
- there is no actor in the cell the spotlight is placed to; - there is at least one actor in the direction the spotlight projects.
Count the number of good positions for placing the spotlight. Two positions of spotlight are considered to be different if the location cells or projection direction differ.
Input Specification:
The first line contains two positive integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=1000) — the number of rows and the number of columns in the plan.
The next *n* lines contain *m* integers, 0 or 1 each — the description of the plan. Integer 1, means there will be an actor in the corresponding cell, while 0 means the cell will remain empty. It is guaranteed that there is at least one actor in the plan.
Output Specification:
Print one integer — the number of good positions for placing the spotlight.
Demo Input:
['2 4\n0 1 0 0\n1 0 1 0\n', '4 4\n0 0 0 0\n1 0 0 1\n0 1 1 0\n0 1 0 0\n']
Demo Output:
['9\n', '20\n']
Note:
In the first example the following positions are good:
1. the (1, 1) cell and right direction; 1. the (1, 1) cell and down direction; 1. the (1, 3) cell and left direction; 1. the (1, 3) cell and down direction; 1. the (1, 4) cell and left direction; 1. the (2, 2) cell and left direction; 1. the (2, 2) cell and up direction; 1. the (2, 2) and right direction; 1. the (2, 4) cell and left direction.
Therefore, there are 9 good positions in this example. | ```python
n, m=map(int, input().split())
a=[list(map(int, input().split())) for _ in range(n)]
ans=p=0
def f(x):
global ans, p
if x==0:
ans+=p
else:
p=1
for i in range(n):
p=0
for j in range(m):
f(a[i][j])
p=0
for j in range(m-1, -1, -1):
f(a[i][j])
for i in range(m):
p=0
for j in range(n):
f(a[j][i])
p=0
for j in range(n-1, -1, -1):
f(a[j][i])
print(ans)
``` | 0 |
|
862 | A | Mahmoud and Ehab and the MEX | PROGRAMMING | 1,000 | [
"greedy",
"implementation"
] | null | null | Dr. Evil kidnapped Mahmoud and Ehab in the evil land because of their performance in the Evil Olympiad in Informatics (EOI). He decided to give them some problems to let them go.
Dr. Evil is interested in sets, He has a set of *n* integers. Dr. Evil calls a set of integers evil if the MEX of it is exactly *x*. the MEX of a set of integers is the minimum non-negative integer that doesn't exist in it. For example, the MEX of the set {0,<=2,<=4} is 1 and the MEX of the set {1,<=2,<=3} is 0 .
Dr. Evil is going to make his set evil. To do this he can perform some operations. During each operation he can add some non-negative integer to his set or erase some element from it. What is the minimal number of operations Dr. Evil has to perform to make his set evil? | The first line contains two integers *n* and *x* (1<=≤<=*n*<=≤<=100, 0<=≤<=*x*<=≤<=100) — the size of the set Dr. Evil owns, and the desired MEX.
The second line contains *n* distinct non-negative integers not exceeding 100 that represent the set. | The only line should contain one integer — the minimal number of operations Dr. Evil should perform. | [
"5 3\n0 4 5 6 7\n",
"1 0\n0\n",
"5 0\n1 2 3 4 5\n"
] | [
"2\n",
"1\n",
"0\n"
] | For the first test case Dr. Evil should add 1 and 2 to the set performing 2 operations.
For the second test case Dr. Evil should erase 0 from the set. After that, the set becomes empty, so the MEX of it is 0.
In the third test case the set is already evil. | 500 | [
{
"input": "5 3\n0 4 5 6 7",
"output": "2"
},
{
"input": "1 0\n0",
"output": "1"
},
{
"input": "5 0\n1 2 3 4 5",
"output": "0"
},
{
"input": "10 5\n57 1 47 9 93 37 76 70 78 15",
"output": "4"
},
{
"input": "10 5\n99 98 93 97 95 100 92 94 91 96",
"output": "5"
},
{
"input": "10 5\n1 2 3 4 59 45 0 58 51 91",
"output": "0"
},
{
"input": "100 100\n79 13 21 11 3 87 28 40 29 4 96 34 8 78 61 46 33 45 99 30 92 67 22 97 39 86 73 31 74 44 62 55 57 2 54 63 80 69 25 48 77 98 17 93 15 16 89 12 43 23 37 95 14 38 83 90 49 56 72 10 20 0 50 71 70 88 19 1 76 81 52 41 82 68 85 47 6 7 35 60 18 64 75 84 27 9 65 91 94 42 53 24 66 26 59 36 51 32 5 58",
"output": "0"
},
{
"input": "100 50\n95 78 46 92 80 18 79 58 30 72 19 89 39 29 44 65 15 100 59 8 96 9 62 67 41 42 82 14 57 32 71 77 40 5 7 51 28 53 85 23 16 35 3 91 6 11 75 61 17 66 13 47 36 56 10 22 83 60 48 24 26 97 4 33 76 86 70 0 34 64 52 43 21 49 55 74 1 73 81 25 54 63 94 84 20 68 87 12 31 88 38 93 37 90 98 69 99 45 27 2",
"output": "0"
},
{
"input": "100 33\n28 11 79 92 88 62 77 72 7 41 96 97 67 84 44 8 81 35 38 1 64 68 46 17 98 83 31 12 74 21 2 22 47 6 36 75 65 61 37 26 25 45 59 48 100 51 93 76 78 49 3 57 16 4 87 29 55 82 70 39 53 0 60 15 24 71 58 20 66 89 95 42 13 43 63 90 85 52 50 30 54 40 56 23 27 34 32 18 10 19 69 9 99 73 91 14 5 80 94 86",
"output": "0"
},
{
"input": "99 33\n25 76 41 95 55 20 47 59 58 84 87 92 16 27 35 65 72 63 93 54 36 96 15 86 5 69 24 46 67 73 48 60 40 6 61 74 97 10 100 8 52 26 77 18 7 62 37 2 14 66 11 56 68 91 0 64 75 99 30 21 53 1 89 81 3 98 12 88 39 38 29 83 22 90 9 28 45 43 78 44 32 57 4 50 70 17 13 51 80 85 71 94 82 19 34 42 23 79 49",
"output": "1"
},
{
"input": "100 100\n65 56 84 46 44 33 99 74 62 72 93 67 43 92 75 88 38 34 66 12 55 76 58 90 78 8 14 45 97 59 48 32 64 18 39 89 31 51 54 81 29 36 70 77 40 22 49 27 3 1 73 13 98 42 87 37 2 57 4 6 50 25 23 79 28 86 68 61 80 17 19 10 15 63 52 11 35 60 21 16 24 85 30 91 7 5 69 20 71 82 53 94 41 95 96 9 26 83 0 47",
"output": "0"
},
{
"input": "100 100\n58 88 12 71 22 1 40 19 73 20 67 48 57 17 69 36 100 35 33 37 72 55 52 8 89 85 47 42 78 70 81 86 11 9 68 99 6 16 21 61 53 98 23 62 32 59 51 0 87 24 50 30 65 10 80 95 7 92 25 74 60 79 91 5 13 31 75 38 90 94 46 66 93 34 14 41 28 2 76 84 43 96 3 56 49 82 27 77 64 63 4 45 18 29 54 39 15 26 83 44",
"output": "2"
},
{
"input": "89 100\n58 96 17 41 86 34 28 84 18 40 8 77 87 89 68 79 33 35 53 49 0 6 22 12 72 90 48 55 21 50 56 62 75 2 37 95 69 74 14 20 44 46 27 32 31 59 63 60 10 85 71 70 38 52 94 30 61 51 80 26 36 23 39 47 76 45 100 57 15 78 97 66 54 13 99 16 93 73 24 4 83 5 98 81 92 25 29 88 65",
"output": "13"
},
{
"input": "100 50\n7 95 24 76 81 78 60 69 83 84 100 1 65 31 48 92 73 39 18 89 38 97 10 42 8 55 98 51 21 90 62 77 16 91 0 94 4 37 19 17 67 35 45 41 56 20 15 85 75 28 59 27 12 54 61 68 36 5 79 93 66 11 70 49 50 34 30 25 96 46 64 14 32 22 47 40 58 23 43 9 87 82 26 53 80 52 3 86 13 99 33 71 6 88 57 74 2 44 72 63",
"output": "2"
},
{
"input": "77 0\n27 8 20 92 21 41 53 98 17 65 67 35 81 11 55 49 61 44 2 66 51 89 40 28 52 62 86 91 64 24 18 5 94 82 96 99 71 6 39 83 26 29 16 30 45 97 80 90 69 12 13 33 76 73 46 19 78 56 88 38 42 34 57 77 47 4 59 58 7 100 95 72 9 74 15 43 54",
"output": "0"
},
{
"input": "100 50\n55 36 0 32 81 6 17 43 24 13 30 19 8 59 71 45 15 74 3 41 99 42 86 47 2 94 35 1 66 95 38 49 4 27 96 89 34 44 92 25 51 39 54 28 80 77 20 14 48 40 68 56 31 63 33 78 69 37 18 26 83 70 23 82 91 65 67 52 61 53 7 22 60 21 12 73 72 87 75 100 90 29 64 79 98 85 5 62 93 84 50 46 97 58 57 16 9 10 76 11",
"output": "1"
},
{
"input": "77 0\n12 8 19 87 9 54 55 86 97 7 27 85 25 48 94 73 26 1 13 57 72 69 76 39 38 91 75 40 42 28 93 21 70 84 65 11 60 90 20 95 66 89 59 47 34 99 6 61 52 100 50 3 77 81 82 53 15 24 0 45 44 14 68 96 58 5 18 35 10 98 29 74 92 49 83 71 17",
"output": "1"
},
{
"input": "100 70\n25 94 66 65 10 99 89 6 70 31 7 40 20 92 64 27 21 72 77 98 17 43 47 44 48 81 38 56 100 39 90 22 88 76 3 83 86 29 33 55 82 79 49 11 2 16 12 78 85 69 32 97 26 15 53 24 23 91 51 67 34 35 52 5 62 50 95 18 71 13 75 8 30 42 93 36 45 60 63 46 57 41 87 0 84 54 74 37 4 58 28 19 96 61 80 9 1 14 73 68",
"output": "2"
},
{
"input": "89 19\n14 77 85 81 79 38 91 45 55 51 50 11 62 67 73 76 2 27 16 23 3 29 65 98 78 17 4 58 22 20 34 66 64 31 72 5 32 44 12 75 80 47 18 25 99 0 61 56 71 84 48 88 10 7 86 8 49 24 43 21 37 28 33 54 46 57 40 89 36 97 6 96 39 95 26 74 1 69 9 100 52 30 83 87 68 60 92 90 35",
"output": "2"
},
{
"input": "89 100\n69 61 56 45 11 41 42 32 28 29 0 76 7 65 13 35 36 82 10 39 26 34 38 40 92 12 17 54 24 46 88 70 66 27 100 52 85 62 22 48 86 68 21 49 53 94 67 20 1 90 77 84 31 87 58 47 95 33 4 72 93 83 8 51 91 80 99 43 71 19 44 59 98 97 64 9 81 16 79 63 25 37 3 75 2 55 50 6 18",
"output": "13"
},
{
"input": "77 0\n38 76 24 74 42 88 29 75 96 46 90 32 59 97 98 60 41 57 80 37 100 49 25 63 95 31 61 68 53 78 27 66 84 48 94 83 30 26 36 99 71 62 45 47 70 28 35 54 34 85 79 43 91 72 86 33 67 92 77 65 69 52 82 55 87 64 56 40 50 44 51 73 89 81 58 93 39",
"output": "0"
},
{
"input": "89 100\n38 90 80 64 35 44 56 11 15 89 23 12 49 70 72 60 63 85 92 10 45 83 8 88 41 33 16 6 61 76 62 71 87 13 25 77 74 0 1 37 96 93 7 94 21 82 34 78 4 73 65 20 81 95 50 32 48 17 69 55 68 5 51 27 53 43 91 67 59 46 86 84 99 24 22 3 97 98 40 36 26 58 57 9 42 30 52 2 47",
"output": "11"
},
{
"input": "77 0\n55 71 78 86 68 35 53 10 59 32 81 19 74 97 62 61 93 87 96 44 25 18 43 82 84 16 34 48 92 39 64 36 49 91 45 76 95 31 57 29 75 79 13 2 14 24 52 23 33 20 47 99 63 15 5 80 58 67 12 3 85 6 1 27 73 90 4 42 37 70 8 11 89 77 9 22 94",
"output": "0"
},
{
"input": "77 0\n12 75 31 71 44 8 3 82 21 77 50 29 57 74 40 10 15 42 84 2 100 9 28 72 92 0 49 11 90 55 17 36 19 54 68 52 4 69 97 91 5 39 59 45 89 62 53 83 16 94 76 60 95 47 30 51 7 48 20 70 67 32 58 78 63 34 56 93 99 88 24 1 66 22 25 14 13",
"output": "1"
},
{
"input": "100 70\n91 82 8 85 26 25 95 97 40 87 81 93 7 73 38 94 64 96 74 18 90 19 65 68 72 61 23 43 36 41 60 88 30 33 71 24 52 39 15 3 16 89 86 79 55 4 9 58 67 44 46 29 6 48 84 69 27 21 78 54 51 57 80 53 76 50 47 77 45 12 34 10 100 0 17 31 56 99 98 11 92 5 2 42 32 59 66 62 37 63 28 75 35 1 22 13 83 49 20 14",
"output": "0"
},
{
"input": "77 0\n51 5 81 62 30 22 11 0 83 16 79 85 52 70 69 10 8 47 58 3 24 34 44 14 82 66 99 17 28 31 64 67 23 49 94 45 4 12 27 15 21 6 43 72 87 2 63 92 35 39 59 9 90 78 93 20 65 36 60 89 50 41 61 84 77 86 76 100 38 68 53 97 96 95 7 19 88",
"output": "1"
},
{
"input": "1 100\n0",
"output": "99"
},
{
"input": "1 0\n100",
"output": "0"
},
{
"input": "1 100\n100",
"output": "101"
},
{
"input": "2 100\n0 100",
"output": "100"
},
{
"input": "5 5\n1 2 3 4 5",
"output": "2"
},
{
"input": "5 3\n0 3 4 5 6",
"output": "3"
},
{
"input": "7 10\n0 1 2 3 4 5 10",
"output": "5"
},
{
"input": "2 2\n0 2",
"output": "2"
},
{
"input": "2 1\n1 2",
"output": "2"
},
{
"input": "5 1\n1 2 3 4 5",
"output": "2"
},
{
"input": "5 2\n1 2 3 4 5",
"output": "2"
},
{
"input": "5 6\n0 1 2 3 4",
"output": "1"
},
{
"input": "3 2\n3 4 5",
"output": "2"
}
] | 1,671,815,291 | 191 | PyPy 3 | OK | TESTS | 39 | 93 | 0 | import sys, os, io
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
n, x = map(int, input().split())
a = list(map(int, input().split()))
l = 105
cnt = [0] * l
for i in a:
cnt[i] += 1
ans = 0
for i in range(x):
if not cnt[i]:
ans += 1
ans += cnt[x]
print(ans) | Title: Mahmoud and Ehab and the MEX
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Dr. Evil kidnapped Mahmoud and Ehab in the evil land because of their performance in the Evil Olympiad in Informatics (EOI). He decided to give them some problems to let them go.
Dr. Evil is interested in sets, He has a set of *n* integers. Dr. Evil calls a set of integers evil if the MEX of it is exactly *x*. the MEX of a set of integers is the minimum non-negative integer that doesn't exist in it. For example, the MEX of the set {0,<=2,<=4} is 1 and the MEX of the set {1,<=2,<=3} is 0 .
Dr. Evil is going to make his set evil. To do this he can perform some operations. During each operation he can add some non-negative integer to his set or erase some element from it. What is the minimal number of operations Dr. Evil has to perform to make his set evil?
Input Specification:
The first line contains two integers *n* and *x* (1<=≤<=*n*<=≤<=100, 0<=≤<=*x*<=≤<=100) — the size of the set Dr. Evil owns, and the desired MEX.
The second line contains *n* distinct non-negative integers not exceeding 100 that represent the set.
Output Specification:
The only line should contain one integer — the minimal number of operations Dr. Evil should perform.
Demo Input:
['5 3\n0 4 5 6 7\n', '1 0\n0\n', '5 0\n1 2 3 4 5\n']
Demo Output:
['2\n', '1\n', '0\n']
Note:
For the first test case Dr. Evil should add 1 and 2 to the set performing 2 operations.
For the second test case Dr. Evil should erase 0 from the set. After that, the set becomes empty, so the MEX of it is 0.
In the third test case the set is already evil. | ```python
import sys, os, io
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
n, x = map(int, input().split())
a = list(map(int, input().split()))
l = 105
cnt = [0] * l
for i in a:
cnt[i] += 1
ans = 0
for i in range(x):
if not cnt[i]:
ans += 1
ans += cnt[x]
print(ans)
``` | 3 |
|
327 | A | Flipping Game | PROGRAMMING | 1,200 | [
"brute force",
"dp",
"implementation"
] | null | null | Iahub got bored, so he invented a game to be played on paper.
He writes *n* integers *a*1,<=*a*2,<=...,<=*a**n*. Each of those integers can be either 0 or 1. He's allowed to do exactly one move: he chooses two indices *i* and *j* (1<=≤<=*i*<=≤<=*j*<=≤<=*n*) and flips all values *a**k* for which their positions are in range [*i*,<=*j*] (that is *i*<=≤<=*k*<=≤<=*j*). Flip the value of *x* means to apply operation *x*<==<=1 - *x*.
The goal of the game is that after exactly one move to obtain the maximum number of ones. Write a program to solve the little game of Iahub. | The first line of the input contains an integer *n* (1<=≤<=*n*<=≤<=100). In the second line of the input there are *n* integers: *a*1,<=*a*2,<=...,<=*a**n*. It is guaranteed that each of those *n* values is either 0 or 1. | Print an integer — the maximal number of 1s that can be obtained after exactly one move. | [
"5\n1 0 0 1 0\n",
"4\n1 0 0 1\n"
] | [
"4\n",
"4\n"
] | In the first case, flip the segment from 2 to 5 (*i* = 2, *j* = 5). That flip changes the sequence, it becomes: [1 1 1 0 1]. So, it contains four ones. There is no way to make the whole sequence equal to [1 1 1 1 1].
In the second case, flipping only the second and the third element (*i* = 2, *j* = 3) will turn all numbers into 1. | 500 | [
{
"input": "5\n1 0 0 1 0",
"output": "4"
},
{
"input": "4\n1 0 0 1",
"output": "4"
},
{
"input": "1\n1",
"output": "0"
},
{
"input": "1\n0",
"output": "1"
},
{
"input": "8\n1 0 0 0 1 0 0 0",
"output": "7"
},
{
"input": "18\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0",
"output": "18"
},
{
"input": "23\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1",
"output": "22"
},
{
"input": "100\n0 1 0 1 1 1 0 1 0 1 0 0 1 1 1 1 0 0 1 1 1 1 1 1 1 0 0 1 1 1 0 1 1 0 0 0 1 1 1 1 0 0 1 1 1 0 0 1 1 0 1 1 1 0 0 0 1 0 0 0 0 0 1 1 0 0 1 1 1 1 1 1 1 1 0 1 1 1 0 1 0 0 0 0 0 1 1 1 1 1 1 1 1 1 1 1 1 1 0 1",
"output": "70"
},
{
"input": "100\n0 1 1 0 1 0 0 1 0 0 0 1 1 0 0 0 1 1 1 0 1 0 0 0 0 0 1 0 1 0 1 0 1 0 1 0 0 0 1 0 0 0 0 0 1 1 0 1 0 1 0 1 1 1 0 1 0 1 1 0 0 1 1 0 0 1 1 1 0 0 1 0 0 1 1 0 1 0 0 1 1 0 1 0 0 1 1 0 0 0 0 1 0 0 0 0 1 1 1 1",
"output": "60"
},
{
"input": "18\n0 1 0 1 0 1 0 1 0 1 1 0 1 1 0 1 1 0",
"output": "11"
},
{
"input": "25\n0 1 0 0 0 0 0 1 0 1 0 1 0 0 0 0 1 1 1 0 0 1 1 0 1",
"output": "18"
},
{
"input": "55\n0 0 1 1 0 0 0 1 0 1 1 0 1 1 1 0 1 1 1 1 1 0 0 1 0 0 1 0 1 1 0 0 1 0 1 1 0 1 1 1 1 0 1 1 0 0 0 0 1 1 0 1 1 1 1",
"output": "36"
},
{
"input": "75\n1 1 0 1 0 1 1 0 0 0 0 0 1 1 1 1 1 0 1 0 1 0 0 0 0 1 1 1 0 1 0 0 1 1 0 1 0 0 1 1 0 1 0 1 0 1 0 0 0 0 1 0 0 1 1 1 0 0 1 0 1 1 0 0 0 0 1 1 0 0 0 1 0 0 0",
"output": "44"
},
{
"input": "100\n0 0 1 0 1 0 0 1 1 0 1 1 0 1 0 1 1 0 0 0 0 0 1 0 0 1 1 0 0 0 1 0 0 1 1 0 0 1 1 1 0 0 0 0 1 0 1 1 1 0 0 1 0 1 1 1 1 1 1 1 0 1 0 1 0 0 1 0 1 1 1 0 0 0 0 1 0 1 1 0 0 1 1 0 1 1 1 1 0 1 1 1 0 0 1 1 0 1 0 1",
"output": "61"
},
{
"input": "100\n0 0 0 1 0 0 0 1 0 1 1 0 1 1 1 1 1 0 1 0 1 1 0 0 1 1 0 1 0 1 0 1 0 1 1 0 1 1 0 0 0 1 1 1 1 0 1 1 0 1 1 1 1 0 1 0 0 1 0 1 0 0 0 0 1 1 0 0 1 0 0 1 1 0 1 1 0 1 0 0 1 1 0 1 1 1 1 0 1 0 0 1 0 1 1 1 0 1 1 0",
"output": "61"
},
{
"input": "100\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0",
"output": "100"
},
{
"input": "100\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1",
"output": "99"
},
{
"input": "100\n0 0 1 1 1 0 1 1 0 0 1 0 1 0 1 0 0 1 0 1 1 0 0 1 1 1 1 1 1 0 1 0 0 1 0 0 0 0 1 1 1 0 1 1 1 0 1 1 1 0 0 1 0 0 1 1 0 0 0 1 1 1 0 1 1 0 0 0 0 1 0 0 1 0 1 0 0 0 0 0 0 1 1 1 0 1 1 1 0 1 1 1 1 1 0 0 0 0 1 0",
"output": "61"
},
{
"input": "100\n0 1 1 1 1 1 1 0 0 0 1 1 0 0 0 1 0 0 0 0 0 0 1 1 1 0 0 0 1 1 1 0 1 0 0 1 1 0 0 0 1 1 1 1 1 1 1 1 1 1 0 0 1 0 1 0 0 0 0 1 0 1 0 1 0 0 1 0 1 0 1 1 0 0 0 0 0 1 1 1 0 1 1 0 1 1 0 0 0 1 0 1 1 0 0 0 0 0 0 1",
"output": "59"
},
{
"input": "99\n1 1 0 0 0 1 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 1 1 1 1 0 1 1 0 0 0 0 0 0 1 1 0 0 1 0 1 1 1 0 0 0 0 0 1 0 0 0 0 0 0 1 0 1 1 0 1 0 0 1 1 0 1 0 0 0 1 1 1 1 0 1 1 1 0 0 1 1 0 0 0 0 1 0 0 0 0 0 1 0 1 1 1",
"output": "61"
},
{
"input": "2\n1 1",
"output": "1"
}
] | 1,692,787,446 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 21 | 154 | 1,740,800 | n = int(input())
a = list(map(int, input().split()))
max_ones = 0
for i in range(n):
for j in range(i, n):
temp = a.copy()
for k in range(i, j+1):
temp[k] = 1 - temp[k]
max_ones = max(max_ones, temp.count(1))
print(max_ones)
| Title: Flipping Game
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Iahub got bored, so he invented a game to be played on paper.
He writes *n* integers *a*1,<=*a*2,<=...,<=*a**n*. Each of those integers can be either 0 or 1. He's allowed to do exactly one move: he chooses two indices *i* and *j* (1<=≤<=*i*<=≤<=*j*<=≤<=*n*) and flips all values *a**k* for which their positions are in range [*i*,<=*j*] (that is *i*<=≤<=*k*<=≤<=*j*). Flip the value of *x* means to apply operation *x*<==<=1 - *x*.
The goal of the game is that after exactly one move to obtain the maximum number of ones. Write a program to solve the little game of Iahub.
Input Specification:
The first line of the input contains an integer *n* (1<=≤<=*n*<=≤<=100). In the second line of the input there are *n* integers: *a*1,<=*a*2,<=...,<=*a**n*. It is guaranteed that each of those *n* values is either 0 or 1.
Output Specification:
Print an integer — the maximal number of 1s that can be obtained after exactly one move.
Demo Input:
['5\n1 0 0 1 0\n', '4\n1 0 0 1\n']
Demo Output:
['4\n', '4\n']
Note:
In the first case, flip the segment from 2 to 5 (*i* = 2, *j* = 5). That flip changes the sequence, it becomes: [1 1 1 0 1]. So, it contains four ones. There is no way to make the whole sequence equal to [1 1 1 1 1].
In the second case, flipping only the second and the third element (*i* = 2, *j* = 3) will turn all numbers into 1. | ```python
n = int(input())
a = list(map(int, input().split()))
max_ones = 0
for i in range(n):
for j in range(i, n):
temp = a.copy()
for k in range(i, j+1):
temp[k] = 1 - temp[k]
max_ones = max(max_ones, temp.count(1))
print(max_ones)
``` | 3 |
|
272 | A | Dima and Friends | PROGRAMMING | 1,000 | [
"implementation",
"math"
] | null | null | Dima and his friends have been playing hide and seek at Dima's place all night. As a result, Dima's place got messy. In the morning they decided that they need to clean the place.
To decide who exactly would clean the apartment, the friends want to play a counting-out game. First, all the guys stand in a circle, and then each of them shows some number of fingers on one hand (one to five), and then the boys count in a circle, starting from Dima, the number of people, respective to the total number of fingers shown. The person on who the countdown stops will clean the apartment.
For example, if Dima and one of his friends played hide and seek, and 7 fingers were shown during the counting-out, then Dima would clean the place. If there were 2 or say, 8 fingers shown, then his friend would clean the place.
Dima knows how many fingers each of his friends will show during the counting-out. Now he is interested in the number of ways to show some number of fingers on one hand (one to five), so that he did not have to clean the place. Help Dima. | The first line contains integer *n* (1<=≤<=*n*<=≤<=100) — the number of Dima's friends. Dima himself isn't considered to be his own friend. The second line contains *n* positive integers, not exceeding 5, representing, how many fingers the Dima's friends will show.
The numbers in the lines are separated by a single space. | In a single line print the answer to the problem. | [
"1\n1\n",
"1\n2\n",
"2\n3 5\n"
] | [
"3\n",
"2\n",
"3\n"
] | In the first sample Dima can show 1, 3 or 5 fingers. If Dima shows 3 fingers, then the counting-out will go like that: Dima, his friend, Dima, his friend.
In the second sample Dima can show 2 or 4 fingers. | 500 | [
{
"input": "1\n1",
"output": "3"
},
{
"input": "1\n2",
"output": "2"
},
{
"input": "2\n3 5",
"output": "3"
},
{
"input": "2\n3 5",
"output": "3"
},
{
"input": "1\n5",
"output": "3"
},
{
"input": "5\n4 4 3 5 1",
"output": "4"
},
{
"input": "6\n2 3 2 2 1 3",
"output": "4"
},
{
"input": "8\n2 2 5 3 4 3 3 2",
"output": "4"
},
{
"input": "7\n4 1 3 2 2 4 5",
"output": "4"
},
{
"input": "3\n3 5 1",
"output": "4"
},
{
"input": "95\n4 2 3 4 4 5 2 2 4 4 3 5 3 3 3 5 4 2 5 4 2 1 1 3 4 2 1 3 5 4 2 1 1 5 1 1 2 2 4 4 5 4 5 5 2 1 2 2 2 4 5 5 2 4 3 4 4 3 5 2 4 1 5 4 5 1 3 2 4 2 2 1 5 3 1 5 3 4 3 3 2 1 2 2 1 3 1 5 2 3 1 1 2 5 2",
"output": "5"
},
{
"input": "31\n3 2 3 3 3 3 4 4 1 5 5 4 2 4 3 2 2 1 4 4 1 2 3 1 1 5 5 3 4 4 1",
"output": "4"
},
{
"input": "42\n3 1 2 2 5 1 2 2 4 5 4 5 2 5 4 5 4 4 1 4 3 3 4 4 4 4 3 2 1 3 4 5 5 2 1 2 1 5 5 2 4 4",
"output": "5"
},
{
"input": "25\n4 5 5 5 3 1 1 4 4 4 3 5 4 4 1 4 4 1 2 4 2 5 4 5 3",
"output": "5"
},
{
"input": "73\n3 4 3 4 5 1 3 4 2 1 4 2 2 3 5 3 1 4 2 3 2 1 4 5 3 5 2 2 4 3 2 2 5 3 2 3 5 1 3 1 1 4 5 2 4 2 5 1 4 3 1 3 1 4 2 3 3 3 3 5 5 2 5 2 5 4 3 1 1 5 5 2 3",
"output": "4"
},
{
"input": "46\n1 4 4 5 4 5 2 3 5 5 3 2 5 4 1 3 2 2 1 4 3 1 5 5 2 2 2 2 4 4 1 1 4 3 4 3 1 4 2 2 4 2 3 2 5 2",
"output": "4"
},
{
"input": "23\n5 2 1 1 4 2 5 5 3 5 4 5 5 1 1 5 2 4 5 3 4 4 3",
"output": "5"
},
{
"input": "6\n4 2 3 1 3 5",
"output": "4"
},
{
"input": "15\n5 5 5 3 5 4 1 3 3 4 3 4 1 4 4",
"output": "5"
},
{
"input": "93\n1 3 1 4 3 3 5 3 1 4 5 4 3 2 2 4 3 1 4 1 2 3 3 3 2 5 1 3 1 4 5 1 1 1 4 2 1 2 3 1 1 1 5 1 5 5 1 2 5 4 3 2 2 4 4 2 5 4 5 5 3 1 3 1 2 1 3 1 1 2 3 4 4 5 5 3 2 1 3 3 5 1 3 5 4 4 1 3 3 4 2 3 2",
"output": "5"
},
{
"input": "96\n1 5 1 3 2 1 2 2 2 2 3 4 1 1 5 4 4 1 2 3 5 1 4 4 4 1 3 3 1 4 5 4 1 3 5 3 4 4 3 2 1 1 4 4 5 1 1 2 5 1 2 3 1 4 1 2 2 2 3 2 3 3 2 5 2 2 3 3 3 3 2 1 2 4 5 5 1 5 3 2 1 4 3 5 5 5 3 3 5 3 4 3 4 2 1 3",
"output": "5"
},
{
"input": "49\n1 4 4 3 5 2 2 1 5 1 2 1 2 5 1 4 1 4 5 2 4 5 3 5 2 4 2 1 3 4 2 1 4 2 1 1 3 3 2 3 5 4 3 4 2 4 1 4 1",
"output": "5"
},
{
"input": "73\n4 1 3 3 3 1 5 2 1 4 1 1 3 5 1 1 4 5 2 1 5 4 1 5 3 1 5 2 4 5 1 4 3 3 5 2 2 3 3 2 5 1 4 5 2 3 1 4 4 3 5 2 3 5 1 4 3 5 1 2 4 1 3 3 5 4 2 4 2 4 1 2 5",
"output": "5"
},
{
"input": "41\n5 3 5 4 2 5 4 3 1 1 1 5 4 3 4 3 5 4 2 5 4 1 1 3 2 4 5 3 5 1 5 5 1 1 1 4 4 1 2 4 3",
"output": "5"
},
{
"input": "100\n3 3 1 4 2 4 4 3 1 5 1 1 4 4 3 4 4 3 5 4 5 2 4 3 4 1 2 4 5 4 2 1 5 4 1 1 4 3 2 4 1 2 1 4 4 5 5 4 4 5 3 2 5 1 4 2 2 1 1 2 5 2 5 1 5 3 1 4 3 2 4 3 2 2 4 5 5 1 2 3 1 4 1 2 2 2 5 5 2 3 2 4 3 1 1 2 1 2 1 2",
"output": "5"
},
{
"input": "100\n2 1 1 3 5 4 4 2 3 4 3 4 5 4 5 4 2 4 5 3 4 5 4 1 1 4 4 1 1 2 5 4 2 4 5 3 2 5 4 3 4 5 1 3 4 2 5 4 5 4 5 2 4 1 2 5 3 1 4 4 5 3 4 3 1 2 5 4 2 5 4 1 5 3 5 4 1 2 5 3 1 1 1 1 5 3 4 3 5 1 1 5 5 1 1 2 2 1 5 1",
"output": "5"
},
{
"input": "100\n4 4 3 3 2 5 4 4 2 1 4 4 4 5 4 1 2 1 5 2 4 3 4 1 4 1 2 5 1 4 5 4 2 1 2 5 3 4 5 5 2 1 2 2 2 2 2 3 2 5 1 2 2 3 2 5 5 1 3 4 5 2 1 3 4 2 2 4 4 3 3 3 2 3 2 1 5 5 5 2 1 4 2 3 5 1 4 4 2 3 2 5 5 4 3 5 1 3 5 5",
"output": "5"
},
{
"input": "100\n4 4 2 5 4 2 2 3 4 4 3 2 3 3 1 3 4 3 3 4 1 3 1 4 5 3 4 3 1 1 1 3 3 2 3 4 3 4 2 2 1 5 1 4 5 1 1 1 3 3 1 1 3 2 5 4 2 5 2 4 5 4 4 1 1 2 1 1 4 5 1 1 5 3 3 2 5 5 5 1 4 1 4 1 1 3 2 3 4 4 2 5 5 2 5 1 1 3 5 3",
"output": "5"
},
{
"input": "100\n4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4",
"output": "4"
},
{
"input": "100\n5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5",
"output": "5"
}
] | 1,591,859,419 | 2,147,483,647 | PyPy 3 | OK | TESTS | 30 | 280 | 0 | n = int(input())
l = list(map(int,input().split()))
if n<3:
if n%2==0:
if sum(l)%2==0:
print(3)
else:
print(2)
else:
if sum(l)%2==0:
print(2)
else:
print(3)
else:
mod = sum(l)%(n+1)
mod = n+1-mod
if mod>=5:
print(5)
else:
print(4)
| Title: Dima and Friends
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Dima and his friends have been playing hide and seek at Dima's place all night. As a result, Dima's place got messy. In the morning they decided that they need to clean the place.
To decide who exactly would clean the apartment, the friends want to play a counting-out game. First, all the guys stand in a circle, and then each of them shows some number of fingers on one hand (one to five), and then the boys count in a circle, starting from Dima, the number of people, respective to the total number of fingers shown. The person on who the countdown stops will clean the apartment.
For example, if Dima and one of his friends played hide and seek, and 7 fingers were shown during the counting-out, then Dima would clean the place. If there were 2 or say, 8 fingers shown, then his friend would clean the place.
Dima knows how many fingers each of his friends will show during the counting-out. Now he is interested in the number of ways to show some number of fingers on one hand (one to five), so that he did not have to clean the place. Help Dima.
Input Specification:
The first line contains integer *n* (1<=≤<=*n*<=≤<=100) — the number of Dima's friends. Dima himself isn't considered to be his own friend. The second line contains *n* positive integers, not exceeding 5, representing, how many fingers the Dima's friends will show.
The numbers in the lines are separated by a single space.
Output Specification:
In a single line print the answer to the problem.
Demo Input:
['1\n1\n', '1\n2\n', '2\n3 5\n']
Demo Output:
['3\n', '2\n', '3\n']
Note:
In the first sample Dima can show 1, 3 or 5 fingers. If Dima shows 3 fingers, then the counting-out will go like that: Dima, his friend, Dima, his friend.
In the second sample Dima can show 2 or 4 fingers. | ```python
n = int(input())
l = list(map(int,input().split()))
if n<3:
if n%2==0:
if sum(l)%2==0:
print(3)
else:
print(2)
else:
if sum(l)%2==0:
print(2)
else:
print(3)
else:
mod = sum(l)%(n+1)
mod = n+1-mod
if mod>=5:
print(5)
else:
print(4)
``` | 3 |
|
230 | B | T-primes | PROGRAMMING | 1,300 | [
"binary search",
"implementation",
"math",
"number theory"
] | null | null | We know that prime numbers are positive integers that have exactly two distinct positive divisors. Similarly, we'll call a positive integer *t* Т-prime, if *t* has exactly three distinct positive divisors.
You are given an array of *n* positive integers. For each of them determine whether it is Т-prime or not. | The first line contains a single positive integer, *n* (1<=≤<=*n*<=≤<=105), showing how many numbers are in the array. The next line contains *n* space-separated integers *x**i* (1<=≤<=*x**i*<=≤<=1012).
Please, do not use the %lld specifier to read or write 64-bit integers in С++. It is advised to use the cin, cout streams or the %I64d specifier. | Print *n* lines: the *i*-th line should contain "YES" (without the quotes), if number *x**i* is Т-prime, and "NO" (without the quotes), if it isn't. | [
"3\n4 5 6\n"
] | [
"YES\nNO\nNO\n"
] | The given test has three numbers. The first number 4 has exactly three divisors — 1, 2 and 4, thus the answer for this number is "YES". The second number 5 has two divisors (1 and 5), and the third number 6 has four divisors (1, 2, 3, 6), hence the answer for them is "NO". | 500 | [
{
"input": "3\n4 5 6",
"output": "YES\nNO\nNO"
},
{
"input": "2\n48 49",
"output": "NO\nYES"
},
{
"input": "10\n10 9 8 7 6 5 4 3 2 1",
"output": "NO\nYES\nNO\nNO\nNO\nNO\nYES\nNO\nNO\nNO"
},
{
"input": "1\n36",
"output": "NO"
},
{
"input": "1\n999966000289",
"output": "YES"
},
{
"input": "1\n999993399999",
"output": "NO"
},
{
"input": "9\n111 121 131 111 121 131 111 121 131",
"output": "NO\nYES\nNO\nNO\nYES\nNO\nNO\nYES\nNO"
},
{
"input": "1\n1",
"output": "NO"
},
{
"input": "1\n10",
"output": "NO"
},
{
"input": "1\n976197352729",
"output": "NO"
},
{
"input": "1\n1000000000000",
"output": "NO"
},
{
"input": "1\n9",
"output": "YES"
},
{
"input": "6\n549755813888 847288609443 762939453125 678223072849 285311670611 137858491849",
"output": "NO\nNO\nNO\nNO\nNO\nNO"
},
{
"input": "3\n223092870 6469693230 200560490130",
"output": "NO\nNO\nNO"
},
{
"input": "2\n81 25",
"output": "NO\nYES"
},
{
"input": "1\n16",
"output": "NO"
},
{
"input": "22\n1 2 3 4 5 6 7 8 9 10 12752041 64 121 144 27550356289 124 24657 23756 135153365 25235235235 42351351 81",
"output": "NO\nNO\nNO\nYES\nNO\nNO\nNO\nNO\nYES\nNO\nYES\nNO\nYES\nNO\nYES\nNO\nNO\nNO\nNO\nNO\nNO\nNO"
},
{
"input": "1\n225",
"output": "NO"
},
{
"input": "1\n1521",
"output": "NO"
},
{
"input": "1\n81",
"output": "NO"
}
] | 1,697,552,758 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 62 | 0 | '''
刘思瑞 2100017810
'''
def search(num):
if int(int(num**(0.5))**2) != num:
return 'NO'
for i in range(2,int(num**(0.5)+1)):
if num % i == 0:
if i**2 != num:
return 'NO'
return 'YES'
n = int(input())
num = list(map(int,input().split()))
for i in num:
print(search(i))
| Title: T-primes
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
We know that prime numbers are positive integers that have exactly two distinct positive divisors. Similarly, we'll call a positive integer *t* Т-prime, if *t* has exactly three distinct positive divisors.
You are given an array of *n* positive integers. For each of them determine whether it is Т-prime or not.
Input Specification:
The first line contains a single positive integer, *n* (1<=≤<=*n*<=≤<=105), showing how many numbers are in the array. The next line contains *n* space-separated integers *x**i* (1<=≤<=*x**i*<=≤<=1012).
Please, do not use the %lld specifier to read or write 64-bit integers in С++. It is advised to use the cin, cout streams or the %I64d specifier.
Output Specification:
Print *n* lines: the *i*-th line should contain "YES" (without the quotes), if number *x**i* is Т-prime, and "NO" (without the quotes), if it isn't.
Demo Input:
['3\n4 5 6\n']
Demo Output:
['YES\nNO\nNO\n']
Note:
The given test has three numbers. The first number 4 has exactly three divisors — 1, 2 and 4, thus the answer for this number is "YES". The second number 5 has two divisors (1 and 5), and the third number 6 has four divisors (1, 2, 3, 6), hence the answer for them is "NO". | ```python
'''
刘思瑞 2100017810
'''
def search(num):
if int(int(num**(0.5))**2) != num:
return 'NO'
for i in range(2,int(num**(0.5)+1)):
if num % i == 0:
if i**2 != num:
return 'NO'
return 'YES'
n = int(input())
num = list(map(int,input().split()))
for i in num:
print(search(i))
``` | 0 |
|
4 | C | Registration System | PROGRAMMING | 1,300 | [
"data structures",
"hashing",
"implementation"
] | C. Registration system | 5 | 64 | A new e-mail service "Berlandesk" is going to be opened in Berland in the near future. The site administration wants to launch their project as soon as possible, that's why they ask you to help. You're suggested to implement the prototype of site registration system. The system should work on the following principle.
Each time a new user wants to register, he sends to the system a request with his name. If such a name does not exist in the system database, it is inserted into the database, and the user gets the response OK, confirming the successful registration. If the name already exists in the system database, the system makes up a new user name, sends it to the user as a prompt and also inserts the prompt into the database. The new name is formed by the following rule. Numbers, starting with 1, are appended one after another to name (name1, name2, ...), among these numbers the least *i* is found so that name*i* does not yet exist in the database. | The first line contains number *n* (1<=≤<=*n*<=≤<=105). The following *n* lines contain the requests to the system. Each request is a non-empty line, and consists of not more than 32 characters, which are all lowercase Latin letters. | Print *n* lines, which are system responses to the requests: OK in case of successful registration, or a prompt with a new name, if the requested name is already taken. | [
"4\nabacaba\nacaba\nabacaba\nacab\n",
"6\nfirst\nfirst\nsecond\nsecond\nthird\nthird\n"
] | [
"OK\nOK\nabacaba1\nOK\n",
"OK\nfirst1\nOK\nsecond1\nOK\nthird1\n"
] | none | 0 | [
{
"input": "4\nabacaba\nacaba\nabacaba\nacab",
"output": "OK\nOK\nabacaba1\nOK"
},
{
"input": "6\nfirst\nfirst\nsecond\nsecond\nthird\nthird",
"output": "OK\nfirst1\nOK\nsecond1\nOK\nthird1"
},
{
"input": "1\nn",
"output": "OK"
},
{
"input": "2\nu\nu",
"output": "OK\nu1"
},
{
"input": "3\nb\nb\nb",
"output": "OK\nb1\nb2"
},
{
"input": "2\nc\ncn",
"output": "OK\nOK"
},
{
"input": "3\nvhn\nvhn\nh",
"output": "OK\nvhn1\nOK"
},
{
"input": "4\nd\nhd\nd\nh",
"output": "OK\nOK\nd1\nOK"
},
{
"input": "10\nbhnqaptmp\nbhnqaptmp\nbhnqaptmp\nbhnqaptmp\nbhnqaptmp\nbhnqaptmp\nbhnqaptmp\nbhnqaptmp\nbhnqaptmp\nbhnqaptmp",
"output": "OK\nbhnqaptmp1\nbhnqaptmp2\nbhnqaptmp3\nbhnqaptmp4\nbhnqaptmp5\nbhnqaptmp6\nbhnqaptmp7\nbhnqaptmp8\nbhnqaptmp9"
},
{
"input": "10\nfpqhfouqdldravpjttarh\nfpqhfouqdldravpjttarh\nfpqhfouqdldravpjttarh\nfpqhfouqdldravpjttarh\nfpqhfouqdldravpjttarh\nfpqhfouqdldravpjttarh\njmvlplnrmba\nfpqhfouqdldravpjttarh\njmvlplnrmba\nfpqhfouqdldravpjttarh",
"output": "OK\nfpqhfouqdldravpjttarh1\nfpqhfouqdldravpjttarh2\nfpqhfouqdldravpjttarh3\nfpqhfouqdldravpjttarh4\nfpqhfouqdldravpjttarh5\nOK\nfpqhfouqdldravpjttarh6\njmvlplnrmba1\nfpqhfouqdldravpjttarh7"
},
{
"input": "10\niwexcrupuubwzbooj\niwexcrupuubwzbooj\njzsyjnxttliyfpunxyhsouhunenzxedi\njzsyjnxttliyfpunxyhsouhunenzxedi\njzsyjnxttliyfpunxyhsouhunenzxedi\njzsyjnxttliyfpunxyhsouhunenzxedi\njzsyjnxttliyfpunxyhsouhunenzxedi\niwexcrupuubwzbooj\niwexcrupuubwzbooj\niwexcrupuubwzbooj",
"output": "OK\niwexcrupuubwzbooj1\nOK\njzsyjnxttliyfpunxyhsouhunenzxedi1\njzsyjnxttliyfpunxyhsouhunenzxedi2\njzsyjnxttliyfpunxyhsouhunenzxedi3\njzsyjnxttliyfpunxyhsouhunenzxedi4\niwexcrupuubwzbooj2\niwexcrupuubwzbooj3\niwexcrupuubwzbooj4"
},
{
"input": "10\nzzzzzzzzzzzzzzzzzzzzzzzzzzz\nzzzzzzzzzzzzzzzzzzzzzzzzzzz\nzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz\nzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz\nzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz\nzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz\nzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz\nzzzzzzzzzzzzzzzzzzzzzzzzzzz\nzzzzzzzzzzzzzzzzzzzzzzzzzzz\nzzzzzzzzzzzzzzzzzzzzzzzzzzz",
"output": "OK\nzzzzzzzzzzzzzzzzzzzzzzzzzzz1\nOK\nzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz1\nzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz2\nzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz3\nzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz4\nzzzzzzzzzzzzzzzzzzzzzzzzzzz2\nzzzzzzzzzzzzzzzzzzzzzzzzzzz3\nzzzzzzzzzzzzzzzzzzzzzzzzzzz4"
},
{
"input": "20\nzzzzzzzzz\nzzzzzzzzzzzzz\nz\nzzzzzzzzzzzzz\nzzzzzzzzz\nzzzzzzzzz\nzzzzzzzzzzzzz\nzzzzzzzzzzzzz\nzzzzzzzzzzzzzzzzzzzzzzzz\nzzzzzzzzzzzzz\nzzzzzzzzzzzzz\nzzzzzzzzzzzzzzzzzzzzzzzz\nzzzzzzzzzzzzzzzzzzzzzzzz\nzzzzzzzzzzzzz\nzzzzzzzzzzzzz\nz\nzzzzzzzzz\nzzzzzzzzz\nzzzzzzzzzzzzz\nzzzzzzzzzzzzzzzzzzzzzzzz",
"output": "OK\nOK\nOK\nzzzzzzzzzzzzz1\nzzzzzzzzz1\nzzzzzzzzz2\nzzzzzzzzzzzzz2\nzzzzzzzzzzzzz3\nOK\nzzzzzzzzzzzzz4\nzzzzzzzzzzzzz5\nzzzzzzzzzzzzzzzzzzzzzzzz1\nzzzzzzzzzzzzzzzzzzzzzzzz2\nzzzzzzzzzzzzz6\nzzzzzzzzzzzzz7\nz1\nzzzzzzzzz3\nzzzzzzzzz4\nzzzzzzzzzzzzz8\nzzzzzzzzzzzzzzzzzzzzzzzz3"
}
] | 1,689,152,254 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 4 | 92 | 0 | n = int(input())
mydict = []
for _ in range(n):
text = input()
if text in mydict:
print(text + "1")
else:
print("OK")
mydict.append(text)
quit()
| Title: Registration System
Time Limit: 5 seconds
Memory Limit: 64 megabytes
Problem Description:
A new e-mail service "Berlandesk" is going to be opened in Berland in the near future. The site administration wants to launch their project as soon as possible, that's why they ask you to help. You're suggested to implement the prototype of site registration system. The system should work on the following principle.
Each time a new user wants to register, he sends to the system a request with his name. If such a name does not exist in the system database, it is inserted into the database, and the user gets the response OK, confirming the successful registration. If the name already exists in the system database, the system makes up a new user name, sends it to the user as a prompt and also inserts the prompt into the database. The new name is formed by the following rule. Numbers, starting with 1, are appended one after another to name (name1, name2, ...), among these numbers the least *i* is found so that name*i* does not yet exist in the database.
Input Specification:
The first line contains number *n* (1<=≤<=*n*<=≤<=105). The following *n* lines contain the requests to the system. Each request is a non-empty line, and consists of not more than 32 characters, which are all lowercase Latin letters.
Output Specification:
Print *n* lines, which are system responses to the requests: OK in case of successful registration, or a prompt with a new name, if the requested name is already taken.
Demo Input:
['4\nabacaba\nacaba\nabacaba\nacab\n', '6\nfirst\nfirst\nsecond\nsecond\nthird\nthird\n']
Demo Output:
['OK\nOK\nabacaba1\nOK\n', 'OK\nfirst1\nOK\nsecond1\nOK\nthird1\n']
Note:
none | ```python
n = int(input())
mydict = []
for _ in range(n):
text = input()
if text in mydict:
print(text + "1")
else:
print("OK")
mydict.append(text)
quit()
``` | 0 |
124 | A | The number of positions | PROGRAMMING | 1,000 | [
"math"
] | null | null | Petr stands in line of *n* people, but he doesn't know exactly which position he occupies. He can say that there are no less than *a* people standing in front of him and no more than *b* people standing behind him. Find the number of different positions Petr can occupy. | The only line contains three integers *n*, *a* and *b* (0<=≤<=*a*,<=*b*<=<<=*n*<=≤<=100). | Print the single number — the number of the sought positions. | [
"3 1 1\n",
"5 2 3\n"
] | [
"2\n",
"3\n"
] | The possible positions in the first sample are: 2 and 3 (if we number the positions starting with 1).
In the second sample they are 3, 4 and 5. | 500 | [
{
"input": "3 1 1",
"output": "2"
},
{
"input": "5 2 3",
"output": "3"
},
{
"input": "5 4 0",
"output": "1"
},
{
"input": "6 5 5",
"output": "1"
},
{
"input": "9 4 3",
"output": "4"
},
{
"input": "11 4 6",
"output": "7"
},
{
"input": "13 8 7",
"output": "5"
},
{
"input": "14 5 5",
"output": "6"
},
{
"input": "16 6 9",
"output": "10"
},
{
"input": "20 13 17",
"output": "7"
},
{
"input": "22 4 8",
"output": "9"
},
{
"input": "23 8 14",
"output": "15"
},
{
"input": "26 18 22",
"output": "8"
},
{
"input": "28 6 1",
"output": "2"
},
{
"input": "29 5 23",
"output": "24"
},
{
"input": "32 27 15",
"output": "5"
},
{
"input": "33 11 5",
"output": "6"
},
{
"input": "37 21 15",
"output": "16"
},
{
"input": "39 34 33",
"output": "5"
},
{
"input": "41 27 11",
"output": "12"
},
{
"input": "42 25 16",
"output": "17"
},
{
"input": "45 7 43",
"output": "38"
},
{
"input": "47 16 17",
"output": "18"
},
{
"input": "49 11 37",
"output": "38"
},
{
"input": "51 38 39",
"output": "13"
},
{
"input": "52 29 7",
"output": "8"
},
{
"input": "56 43 12",
"output": "13"
},
{
"input": "58 57 28",
"output": "1"
},
{
"input": "59 12 39",
"output": "40"
},
{
"input": "62 9 52",
"output": "53"
},
{
"input": "63 29 44",
"output": "34"
},
{
"input": "65 30 22",
"output": "23"
},
{
"input": "66 27 38",
"output": "39"
},
{
"input": "71 33 53",
"output": "38"
},
{
"input": "73 14 12",
"output": "13"
},
{
"input": "73 37 35",
"output": "36"
},
{
"input": "76 69 44",
"output": "7"
},
{
"input": "79 25 20",
"output": "21"
},
{
"input": "81 60 20",
"output": "21"
},
{
"input": "81 79 14",
"output": "2"
},
{
"input": "84 0 42",
"output": "43"
},
{
"input": "88 79 8",
"output": "9"
},
{
"input": "90 76 59",
"output": "14"
},
{
"input": "92 2 22",
"output": "23"
},
{
"input": "94 5 88",
"output": "89"
},
{
"input": "94 62 48",
"output": "32"
},
{
"input": "96 22 72",
"output": "73"
},
{
"input": "100 11 88",
"output": "89"
},
{
"input": "100 81 91",
"output": "19"
},
{
"input": "1 0 0",
"output": "1"
}
] | 1,670,745,762 | 2,147,483,647 | Python 3 | COMPILATION_ERROR | TESTS | 0 | 0 | 0 | import sys
inputs = sys.stdin.readline().split()
print min(int(inputs[0])-int(inputs[1]),int(inputs[2])+1) | Title: The number of positions
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Petr stands in line of *n* people, but he doesn't know exactly which position he occupies. He can say that there are no less than *a* people standing in front of him and no more than *b* people standing behind him. Find the number of different positions Petr can occupy.
Input Specification:
The only line contains three integers *n*, *a* and *b* (0<=≤<=*a*,<=*b*<=<<=*n*<=≤<=100).
Output Specification:
Print the single number — the number of the sought positions.
Demo Input:
['3 1 1\n', '5 2 3\n']
Demo Output:
['2\n', '3\n']
Note:
The possible positions in the first sample are: 2 and 3 (if we number the positions starting with 1).
In the second sample they are 3, 4 and 5. | ```python
import sys
inputs = sys.stdin.readline().split()
print min(int(inputs[0])-int(inputs[1]),int(inputs[2])+1)
``` | -1 |
|
231 | A | Team | PROGRAMMING | 800 | [
"brute force",
"greedy"
] | null | null | One day three best friends Petya, Vasya and Tonya decided to form a team and take part in programming contests. Participants are usually offered several problems during programming contests. Long before the start the friends decided that they will implement a problem if at least two of them are sure about the solution. Otherwise, the friends won't write the problem's solution.
This contest offers *n* problems to the participants. For each problem we know, which friend is sure about the solution. Help the friends find the number of problems for which they will write a solution. | The first input line contains a single integer *n* (1<=≤<=*n*<=≤<=1000) — the number of problems in the contest. Then *n* lines contain three integers each, each integer is either 0 or 1. If the first number in the line equals 1, then Petya is sure about the problem's solution, otherwise he isn't sure. The second number shows Vasya's view on the solution, the third number shows Tonya's view. The numbers on the lines are separated by spaces. | Print a single integer — the number of problems the friends will implement on the contest. | [
"3\n1 1 0\n1 1 1\n1 0 0\n",
"2\n1 0 0\n0 1 1\n"
] | [
"2\n",
"1\n"
] | In the first sample Petya and Vasya are sure that they know how to solve the first problem and all three of them know how to solve the second problem. That means that they will write solutions for these problems. Only Petya is sure about the solution for the third problem, but that isn't enough, so the friends won't take it.
In the second sample the friends will only implement the second problem, as Vasya and Tonya are sure about the solution. | 500 | [
{
"input": "3\n1 1 0\n1 1 1\n1 0 0",
"output": "2"
},
{
"input": "2\n1 0 0\n0 1 1",
"output": "1"
},
{
"input": "1\n1 0 0",
"output": "0"
},
{
"input": "2\n1 0 0\n1 1 1",
"output": "1"
},
{
"input": "5\n1 0 0\n0 1 0\n1 1 1\n0 0 1\n0 0 0",
"output": "1"
},
{
"input": "10\n0 1 0\n0 1 0\n1 1 0\n1 0 0\n0 0 1\n0 1 1\n1 1 1\n1 1 0\n0 0 0\n0 0 0",
"output": "4"
},
{
"input": "15\n0 1 0\n1 0 0\n1 1 0\n1 1 1\n0 1 0\n0 0 1\n1 0 1\n1 0 1\n1 0 1\n0 0 0\n1 1 1\n1 1 0\n0 1 1\n1 1 0\n1 1 1",
"output": "10"
},
{
"input": "50\n0 0 0\n0 1 1\n1 1 1\n0 1 0\n1 0 1\n1 1 1\n0 0 1\n1 0 0\n1 1 0\n1 0 1\n0 1 0\n0 0 1\n1 1 0\n0 1 0\n1 1 0\n0 0 0\n1 1 1\n1 0 1\n0 0 1\n1 1 0\n1 1 1\n0 1 1\n1 1 0\n0 0 0\n0 0 0\n1 1 1\n0 0 0\n1 1 1\n0 1 1\n0 0 1\n0 0 0\n0 0 0\n1 1 0\n1 1 0\n1 0 1\n1 0 0\n1 0 1\n1 0 1\n0 1 1\n1 1 0\n1 1 0\n0 1 0\n1 0 1\n0 0 0\n0 0 0\n0 0 0\n0 0 1\n1 1 1\n0 1 1\n1 0 1",
"output": "29"
},
{
"input": "1\n1 1 1",
"output": "1"
},
{
"input": "8\n0 0 0\n0 0 1\n0 0 0\n0 1 1\n1 0 0\n1 0 1\n1 1 0\n1 1 1",
"output": "4"
},
{
"input": "16\n1 1 1\n1 1 1\n1 1 1\n1 1 1\n1 1 1\n1 1 1\n1 1 1\n1 1 1\n1 1 1\n1 1 1\n1 1 1\n1 1 1\n1 1 1\n1 1 1\n1 1 1\n1 1 1",
"output": "16"
}
] | 1,697,475,674 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 92 | 0 | data = list(map(int, input().split()))
a,b,c = data
max_problems = max(a, b, c)
if a+b+c - max_problems >= 2:
print(max_problems + 1)
else:
print(a + b + c)
| Title: Team
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
One day three best friends Petya, Vasya and Tonya decided to form a team and take part in programming contests. Participants are usually offered several problems during programming contests. Long before the start the friends decided that they will implement a problem if at least two of them are sure about the solution. Otherwise, the friends won't write the problem's solution.
This contest offers *n* problems to the participants. For each problem we know, which friend is sure about the solution. Help the friends find the number of problems for which they will write a solution.
Input Specification:
The first input line contains a single integer *n* (1<=≤<=*n*<=≤<=1000) — the number of problems in the contest. Then *n* lines contain three integers each, each integer is either 0 or 1. If the first number in the line equals 1, then Petya is sure about the problem's solution, otherwise he isn't sure. The second number shows Vasya's view on the solution, the third number shows Tonya's view. The numbers on the lines are separated by spaces.
Output Specification:
Print a single integer — the number of problems the friends will implement on the contest.
Demo Input:
['3\n1 1 0\n1 1 1\n1 0 0\n', '2\n1 0 0\n0 1 1\n']
Demo Output:
['2\n', '1\n']
Note:
In the first sample Petya and Vasya are sure that they know how to solve the first problem and all three of them know how to solve the second problem. That means that they will write solutions for these problems. Only Petya is sure about the solution for the third problem, but that isn't enough, so the friends won't take it.
In the second sample the friends will only implement the second problem, as Vasya and Tonya are sure about the solution. | ```python
data = list(map(int, input().split()))
a,b,c = data
max_problems = max(a, b, c)
if a+b+c - max_problems >= 2:
print(max_problems + 1)
else:
print(a + b + c)
``` | -1 |
|
69 | A | Young Physicist | PROGRAMMING | 1,000 | [
"implementation",
"math"
] | A. Young Physicist | 2 | 256 | A guy named Vasya attends the final grade of a high school. One day Vasya decided to watch a match of his favorite hockey team. And, as the boy loves hockey very much, even more than physics, he forgot to do the homework. Specifically, he forgot to complete his physics tasks. Next day the teacher got very angry at Vasya and decided to teach him a lesson. He gave the lazy student a seemingly easy task: You are given an idle body in space and the forces that affect it. The body can be considered as a material point with coordinates (0; 0; 0). Vasya had only to answer whether it is in equilibrium. "Piece of cake" — thought Vasya, we need only to check if the sum of all vectors is equal to 0. So, Vasya began to solve the problem. But later it turned out that there can be lots and lots of these forces, and Vasya can not cope without your help. Help him. Write a program that determines whether a body is idle or is moving by the given vectors of forces. | The first line contains a positive integer *n* (1<=≤<=*n*<=≤<=100), then follow *n* lines containing three integers each: the *x**i* coordinate, the *y**i* coordinate and the *z**i* coordinate of the force vector, applied to the body (<=-<=100<=≤<=*x**i*,<=*y**i*,<=*z**i*<=≤<=100). | Print the word "YES" if the body is in equilibrium, or the word "NO" if it is not. | [
"3\n4 1 7\n-2 4 -1\n1 -5 -3\n",
"3\n3 -1 7\n-5 2 -4\n2 -1 -3\n"
] | [
"NO",
"YES"
] | none | 500 | [
{
"input": "3\n4 1 7\n-2 4 -1\n1 -5 -3",
"output": "NO"
},
{
"input": "3\n3 -1 7\n-5 2 -4\n2 -1 -3",
"output": "YES"
},
{
"input": "10\n21 32 -46\n43 -35 21\n42 2 -50\n22 40 20\n-27 -9 38\n-4 1 1\n-40 6 -31\n-13 -2 34\n-21 34 -12\n-32 -29 41",
"output": "NO"
},
{
"input": "10\n25 -33 43\n-27 -42 28\n-35 -20 19\n41 -42 -1\n49 -39 -4\n-49 -22 7\n-19 29 41\n8 -27 -43\n8 34 9\n-11 -3 33",
"output": "NO"
},
{
"input": "10\n-6 21 18\n20 -11 -8\n37 -11 41\n-5 8 33\n29 23 32\n30 -33 -11\n39 -49 -36\n28 34 -49\n22 29 -34\n-18 -6 7",
"output": "NO"
},
{
"input": "10\n47 -2 -27\n0 26 -14\n5 -12 33\n2 18 3\n45 -30 -49\n4 -18 8\n-46 -44 -41\n-22 -10 -40\n-35 -21 26\n33 20 38",
"output": "NO"
},
{
"input": "13\n-3 -36 -46\n-11 -50 37\n42 -11 -15\n9 42 44\n-29 -12 24\n3 9 -40\n-35 13 50\n14 43 18\n-13 8 24\n-48 -15 10\n50 9 -50\n21 0 -50\n0 0 -6",
"output": "YES"
},
{
"input": "14\n43 23 17\n4 17 44\n5 -5 -16\n-43 -7 -6\n47 -48 12\n50 47 -45\n2 14 43\n37 -30 15\n4 -17 -11\n17 9 -45\n-50 -3 -8\n-50 0 0\n-50 0 0\n-16 0 0",
"output": "YES"
},
{
"input": "13\n29 49 -11\n38 -11 -20\n25 1 -40\n-11 28 11\n23 -19 1\n45 -41 -17\n-3 0 -19\n-13 -33 49\n-30 0 28\n34 17 45\n-50 9 -27\n-50 0 0\n-37 0 0",
"output": "YES"
},
{
"input": "12\n3 28 -35\n-32 -44 -17\n9 -25 -6\n-42 -22 20\n-19 15 38\n-21 38 48\n-1 -37 -28\n-10 -13 -50\n-5 21 29\n34 28 50\n50 11 -49\n34 0 0",
"output": "YES"
},
{
"input": "37\n-64 -79 26\n-22 59 93\n-5 39 -12\n77 -9 76\n55 -86 57\n83 100 -97\n-70 94 84\n-14 46 -94\n26 72 35\n14 78 -62\n17 82 92\n-57 11 91\n23 15 92\n-80 -1 1\n12 39 18\n-23 -99 -75\n-34 50 19\n-39 84 -7\n45 -30 -39\n-60 49 37\n45 -16 -72\n33 -51 -56\n-48 28 5\n97 91 88\n45 -82 -11\n-21 -15 -90\n-53 73 -26\n-74 85 -90\n-40 23 38\n100 -13 49\n32 -100 -100\n0 -100 -70\n0 -100 0\n0 -100 0\n0 -100 0\n0 -100 0\n0 -37 0",
"output": "YES"
},
{
"input": "4\n68 3 100\n68 21 -100\n-100 -24 0\n-36 0 0",
"output": "YES"
},
{
"input": "33\n-1 -46 -12\n45 -16 -21\n-11 45 -21\n-60 -42 -93\n-22 -45 93\n37 96 85\n-76 26 83\n-4 9 55\n7 -52 -9\n66 8 -85\n-100 -54 11\n-29 59 74\n-24 12 2\n-56 81 85\n-92 69 -52\n-26 -97 91\n54 59 -51\n58 21 -57\n7 68 56\n-47 -20 -51\n-59 77 -13\n-85 27 91\n79 60 -56\n66 -80 5\n21 -99 42\n-31 -29 98\n66 93 76\n-49 45 61\n100 -100 -100\n100 -100 -100\n66 -75 -100\n0 0 -100\n0 0 -87",
"output": "YES"
},
{
"input": "3\n1 2 3\n3 2 1\n0 0 0",
"output": "NO"
},
{
"input": "2\n5 -23 12\n0 0 0",
"output": "NO"
},
{
"input": "1\n0 0 0",
"output": "YES"
},
{
"input": "1\n1 -2 0",
"output": "NO"
},
{
"input": "2\n-23 77 -86\n23 -77 86",
"output": "YES"
},
{
"input": "26\n86 7 20\n-57 -64 39\n-45 6 -93\n-44 -21 100\n-11 -49 21\n73 -71 -80\n-2 -89 56\n-65 -2 7\n5 14 84\n57 41 13\n-12 69 54\n40 -25 27\n-17 -59 0\n64 -91 -30\n-53 9 42\n-54 -8 14\n-35 82 27\n-48 -59 -80\n88 70 79\n94 57 97\n44 63 25\n84 -90 -40\n-100 100 -100\n-92 100 -100\n0 10 -100\n0 0 -82",
"output": "YES"
},
{
"input": "42\n11 27 92\n-18 -56 -57\n1 71 81\n33 -92 30\n82 83 49\n-87 -61 -1\n-49 45 49\n73 26 15\n-22 22 -77\n29 -93 87\n-68 44 -90\n-4 -84 20\n85 67 -6\n-39 26 77\n-28 -64 20\n65 -97 24\n-72 -39 51\n35 -75 -91\n39 -44 -8\n-25 -27 -57\n91 8 -46\n-98 -94 56\n94 -60 59\n-9 -95 18\n-53 -37 98\n-8 -94 -84\n-52 55 60\n15 -14 37\n65 -43 -25\n94 12 66\n-8 -19 -83\n29 81 -78\n-58 57 33\n24 86 -84\n-53 32 -88\n-14 7 3\n89 97 -53\n-5 -28 -91\n-100 100 -6\n-84 100 0\n0 100 0\n0 70 0",
"output": "YES"
},
{
"input": "3\n96 49 -12\n2 -66 28\n-98 17 -16",
"output": "YES"
},
{
"input": "5\n70 -46 86\n-100 94 24\n-27 63 -63\n57 -100 -47\n0 -11 0",
"output": "YES"
},
{
"input": "18\n-86 -28 70\n-31 -89 42\n31 -48 -55\n95 -17 -43\n24 -95 -85\n-21 -14 31\n68 -18 81\n13 31 60\n-15 28 99\n-42 15 9\n28 -61 -62\n-16 71 29\n-28 75 -48\n-77 -67 36\n-100 83 89\n100 100 -100\n57 34 -100\n0 0 -53",
"output": "YES"
},
{
"input": "44\n52 -54 -29\n-82 -5 -94\n-54 43 43\n91 16 71\n7 80 -91\n3 15 29\n-99 -6 -77\n-3 -77 -64\n73 67 34\n25 -10 -18\n-29 91 63\n-72 86 -16\n-68 85 -81\n-3 36 44\n-74 -14 -80\n34 -96 -97\n-76 -78 -33\n-24 44 -58\n98 12 77\n95 -63 -6\n-51 3 -90\n-92 -10 72\n7 3 -68\n57 -53 71\n29 57 -48\n35 -60 10\n79 -70 -61\n-20 77 55\n-86 -15 -35\n84 -88 -18\n100 -42 77\n-20 46 8\n-41 -43 -65\n38 -98 -23\n-100 65 45\n-7 -91 -63\n46 88 -85\n48 59 100\n0 0 100\n0 0 100\n0 0 100\n0 0 100\n0 0 100\n0 0 1",
"output": "YES"
},
{
"input": "18\n-14 -64 -91\n-8 -66 -86\n-23 92 -40\n6 -3 -53\n57 41 78\n-79 42 -22\n-88 -17 45\n4 -45 44\n83 -18 -25\n34 86 -92\n75 -30 12\n44 99 11\n-67 -13 72\n22 83 -56\n-37 71 72\n-9 -100 100\n0 -100 31\n0 -58 0",
"output": "YES"
},
{
"input": "23\n-70 37 78\n42 84 6\n28 -94 -24\n-49 76 95\n-67 18 84\n-53 78 -5\n65 -63 -64\n-66 -64 -69\n81 -93 95\n10 52 -79\n-89 -61 -64\n-64 -47 43\n-81 -35 55\n80 82 73\n-60 -81 -18\n49 -10 -19\n-58 70 12\n-24 -15 -93\n98 -93 -54\n-28 -75 11\n100 100 -63\n100 100 0\n56 34 0",
"output": "YES"
},
{
"input": "3\n0 2 -2\n1 -1 3\n-3 0 0",
"output": "NO"
}
] | 1,537,700,196 | 2,147,483,647 | Python 3 | OK | TESTS | 81 | 248 | 0 | n = int(input())
xs, ys, zs = 0, 0, 0
for i in range(n):
l = [int(k) for k in input().split(' ')]
x, y, z = l[0], l[1], l[2]
xs, ys, zs = xs+x, ys+y, zs+z
if (xs==0) and (ys==0) and (zs==0):
print('YES')
else:
print('NO')
| Title: Young Physicist
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
A guy named Vasya attends the final grade of a high school. One day Vasya decided to watch a match of his favorite hockey team. And, as the boy loves hockey very much, even more than physics, he forgot to do the homework. Specifically, he forgot to complete his physics tasks. Next day the teacher got very angry at Vasya and decided to teach him a lesson. He gave the lazy student a seemingly easy task: You are given an idle body in space and the forces that affect it. The body can be considered as a material point with coordinates (0; 0; 0). Vasya had only to answer whether it is in equilibrium. "Piece of cake" — thought Vasya, we need only to check if the sum of all vectors is equal to 0. So, Vasya began to solve the problem. But later it turned out that there can be lots and lots of these forces, and Vasya can not cope without your help. Help him. Write a program that determines whether a body is idle or is moving by the given vectors of forces.
Input Specification:
The first line contains a positive integer *n* (1<=≤<=*n*<=≤<=100), then follow *n* lines containing three integers each: the *x**i* coordinate, the *y**i* coordinate and the *z**i* coordinate of the force vector, applied to the body (<=-<=100<=≤<=*x**i*,<=*y**i*,<=*z**i*<=≤<=100).
Output Specification:
Print the word "YES" if the body is in equilibrium, or the word "NO" if it is not.
Demo Input:
['3\n4 1 7\n-2 4 -1\n1 -5 -3\n', '3\n3 -1 7\n-5 2 -4\n2 -1 -3\n']
Demo Output:
['NO', 'YES']
Note:
none | ```python
n = int(input())
xs, ys, zs = 0, 0, 0
for i in range(n):
l = [int(k) for k in input().split(' ')]
x, y, z = l[0], l[1], l[2]
xs, ys, zs = xs+x, ys+y, zs+z
if (xs==0) and (ys==0) and (zs==0):
print('YES')
else:
print('NO')
``` | 3.938 |
336 | B | Vasily the Bear and Fly | PROGRAMMING | 1,900 | [
"math"
] | null | null | One beautiful day Vasily the bear painted 2*m* circles of the same radius *R* on a coordinate plane. Circles with numbers from 1 to *m* had centers at points (2*R*<=-<=*R*,<=0), (4*R*<=-<=*R*,<=0), ..., (2*Rm*<=-<=*R*,<=0), respectively. Circles with numbers from *m*<=+<=1 to 2*m* had centers at points (2*R*<=-<=*R*,<=2*R*), (4*R*<=-<=*R*,<=2*R*), ..., (2*Rm*<=-<=*R*,<=2*R*), respectively.
Naturally, the bear painted the circles for a simple experiment with a fly. The experiment continued for *m*2 days. Each day of the experiment got its own unique number from 0 to *m*2<=-<=1, inclusive.
On the day number *i* the following things happened:
1. The fly arrived at the coordinate plane at the center of the circle with number ( is the result of dividing number *x* by number *y*, rounded down to an integer). 1. The fly went along the coordinate plane to the center of the circle number ( is the remainder after dividing number *x* by number *y*). The bear noticed that the fly went from the center of circle *v* to the center of circle *u* along the shortest path with all points lying on the border or inside at least one of the 2*m* circles. After the fly reached the center of circle *u*, it flew away in an unknown direction.
Help Vasily, count the average distance the fly went along the coordinate plane during each of these *m*2 days. | The first line contains two integers *m*,<=*R* (1<=≤<=*m*<=≤<=105, 1<=≤<=*R*<=≤<=10). | In a single line print a single real number — the answer to the problem. The answer will be considered correct if its absolute or relative error doesn't exceed 10<=-<=6. | [
"1 1\n",
"2 2\n"
] | [
"2.0000000000\n",
"5.4142135624\n"
] | <img class="tex-graphics" src="https://espresso.codeforces.com/9fe384073741e20965ddc4bf162afd3a604b6b39.png" style="max-width: 100.0%;max-height: 100.0%;"/>
Figure to the second sample | 1,000 | [
{
"input": "1 1",
"output": "2.0000000000"
},
{
"input": "2 2",
"output": "5.4142135624"
},
{
"input": "100000 3",
"output": "200002.4853316681"
},
{
"input": "2344 5",
"output": "7817.4790439982"
},
{
"input": "999 10",
"output": "6668.3010410807"
},
{
"input": "6 1",
"output": "5.0752966144"
},
{
"input": "43 4",
"output": "118.1337922078"
},
{
"input": "3333 3",
"output": "6668.4867900399"
},
{
"input": "4444 4",
"output": "11853.9818839104"
},
{
"input": "100000 10",
"output": "666674.9511055604"
},
{
"input": "3134 9",
"output": "18811.4606574435"
},
{
"input": "9 9",
"output": "63.0021484426"
},
{
"input": "32 9",
"output": "199.9170568378"
},
{
"input": "33333 9",
"output": "200005.4562967670"
},
{
"input": "99999 1",
"output": "66666.8284438896"
},
{
"input": "99999 9",
"output": "600001.4559950059"
},
{
"input": "99999 7",
"output": "466667.7991072268"
},
{
"input": "4234 4",
"output": "11293.9819587295"
},
{
"input": "66666 6",
"output": "266668.9707136318"
},
{
"input": "66666 9",
"output": "400003.4560704476"
},
{
"input": "67676 7",
"output": "315827.1324966100"
},
{
"input": "7777 7",
"output": "36298.4671653864"
},
{
"input": "7656 2",
"output": "10209.6572921612"
},
{
"input": "2 8",
"output": "21.6568542495"
},
{
"input": "2 10",
"output": "27.0710678119"
},
{
"input": "2 4",
"output": "10.8284271247"
},
{
"input": "8 1",
"output": "6.3530145174"
},
{
"input": "8 8",
"output": "50.8241161391"
},
{
"input": "92399 1",
"output": "61600.1617786019"
},
{
"input": "1 10",
"output": "20.0000000000"
},
{
"input": "3 1",
"output": "3.2570787221"
}
] | 1,377,735,208 | 2,147,483,647 | Python 3 | OK | TESTS | 31 | 686 | 0 | import math
m,R = map (int,input().split())
D = math.sqrt (2) * R
result = 0
def sum_dist (n):
return n*(n+1)*R + 2*D*n
for i in range (1,m+1):
result += 2*R
if i-1 > 0: result += 2*R + D
if m-i > 0: result += 2*R + D
if i-2 > 0: result += sum_dist (i-2)
if m-i-1 > 0: result += sum_dist (m-i-1)
print (result / m / m)
| Title: Vasily the Bear and Fly
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
One beautiful day Vasily the bear painted 2*m* circles of the same radius *R* on a coordinate plane. Circles with numbers from 1 to *m* had centers at points (2*R*<=-<=*R*,<=0), (4*R*<=-<=*R*,<=0), ..., (2*Rm*<=-<=*R*,<=0), respectively. Circles with numbers from *m*<=+<=1 to 2*m* had centers at points (2*R*<=-<=*R*,<=2*R*), (4*R*<=-<=*R*,<=2*R*), ..., (2*Rm*<=-<=*R*,<=2*R*), respectively.
Naturally, the bear painted the circles for a simple experiment with a fly. The experiment continued for *m*2 days. Each day of the experiment got its own unique number from 0 to *m*2<=-<=1, inclusive.
On the day number *i* the following things happened:
1. The fly arrived at the coordinate plane at the center of the circle with number ( is the result of dividing number *x* by number *y*, rounded down to an integer). 1. The fly went along the coordinate plane to the center of the circle number ( is the remainder after dividing number *x* by number *y*). The bear noticed that the fly went from the center of circle *v* to the center of circle *u* along the shortest path with all points lying on the border or inside at least one of the 2*m* circles. After the fly reached the center of circle *u*, it flew away in an unknown direction.
Help Vasily, count the average distance the fly went along the coordinate plane during each of these *m*2 days.
Input Specification:
The first line contains two integers *m*,<=*R* (1<=≤<=*m*<=≤<=105, 1<=≤<=*R*<=≤<=10).
Output Specification:
In a single line print a single real number — the answer to the problem. The answer will be considered correct if its absolute or relative error doesn't exceed 10<=-<=6.
Demo Input:
['1 1\n', '2 2\n']
Demo Output:
['2.0000000000\n', '5.4142135624\n']
Note:
<img class="tex-graphics" src="https://espresso.codeforces.com/9fe384073741e20965ddc4bf162afd3a604b6b39.png" style="max-width: 100.0%;max-height: 100.0%;"/>
Figure to the second sample | ```python
import math
m,R = map (int,input().split())
D = math.sqrt (2) * R
result = 0
def sum_dist (n):
return n*(n+1)*R + 2*D*n
for i in range (1,m+1):
result += 2*R
if i-1 > 0: result += 2*R + D
if m-i > 0: result += 2*R + D
if i-2 > 0: result += sum_dist (i-2)
if m-i-1 > 0: result += sum_dist (m-i-1)
print (result / m / m)
``` | 3 |
|
427 | B | Prison Transfer | PROGRAMMING | 1,100 | [
"data structures",
"implementation"
] | null | null | The prison of your city has *n* prisoners. As the prison can't accommodate all of them, the city mayor has decided to transfer *c* of the prisoners to a prison located in another city.
For this reason, he made the *n* prisoners to stand in a line, with a number written on their chests. The number is the severity of the crime he/she has committed. The greater the number, the more severe his/her crime was.
Then, the mayor told you to choose the *c* prisoners, who will be transferred to the other prison. He also imposed two conditions. They are,
- The chosen *c* prisoners has to form a contiguous segment of prisoners. - Any of the chosen prisoner's crime level should not be greater then *t*. Because, that will make the prisoner a severe criminal and the mayor doesn't want to take the risk of his running away during the transfer.
Find the number of ways you can choose the *c* prisoners. | The first line of input will contain three space separated integers *n* (1<=≤<=*n*<=≤<=2·105), *t* (0<=≤<=*t*<=≤<=109) and *c* (1<=≤<=*c*<=≤<=*n*). The next line will contain *n* space separated integers, the *i**th* integer is the severity *i**th* prisoner's crime. The value of crime severities will be non-negative and will not exceed 109. | Print a single integer — the number of ways you can choose the *c* prisoners. | [
"4 3 3\n2 3 1 1\n",
"1 1 1\n2\n",
"11 4 2\n2 2 0 7 3 2 2 4 9 1 4\n"
] | [
"2\n",
"0\n",
"6\n"
] | none | 1,000 | [
{
"input": "4 3 3\n2 3 1 1",
"output": "2"
},
{
"input": "1 1 1\n2",
"output": "0"
},
{
"input": "11 4 2\n2 2 0 7 3 2 2 4 9 1 4",
"output": "6"
},
{
"input": "57 2 10\n7 5 2 7 4 1 0 5 2 9 2 9 8 6 6 5 9 6 8 1 0 1 0 3 2 6 5 2 8 8 8 8 0 9 4 3 6 6 2 4 5 1 2 0 1 7 1 1 5 4 5 0 7 5 1 9 6",
"output": "0"
},
{
"input": "2 228885628 1\n90897004 258427916",
"output": "1"
},
{
"input": "3 1 1\n1 2 1",
"output": "2"
},
{
"input": "3 3 3\n3 2 3",
"output": "1"
},
{
"input": "4 2 2\n1 3 3 2",
"output": "0"
},
{
"input": "1 228 1\n1",
"output": "1"
}
] | 1,696,006,223 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 80 | 109 | 22,630,400 | import sys
n, t, c = map(int, input().split())
vec = [-1]
for i, temp in enumerate(map(int, sys.stdin.readline().split())):
if temp > t:
vec.append(i)
vec.append(n)
ans = 0
for i in range(1, len(vec)):
diff = vec[i] - vec[i - 1] - 1
ans += max(diff - c + 1, 0)
sys.stdout.write(str(ans) + '\n')
| Title: Prison Transfer
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The prison of your city has *n* prisoners. As the prison can't accommodate all of them, the city mayor has decided to transfer *c* of the prisoners to a prison located in another city.
For this reason, he made the *n* prisoners to stand in a line, with a number written on their chests. The number is the severity of the crime he/she has committed. The greater the number, the more severe his/her crime was.
Then, the mayor told you to choose the *c* prisoners, who will be transferred to the other prison. He also imposed two conditions. They are,
- The chosen *c* prisoners has to form a contiguous segment of prisoners. - Any of the chosen prisoner's crime level should not be greater then *t*. Because, that will make the prisoner a severe criminal and the mayor doesn't want to take the risk of his running away during the transfer.
Find the number of ways you can choose the *c* prisoners.
Input Specification:
The first line of input will contain three space separated integers *n* (1<=≤<=*n*<=≤<=2·105), *t* (0<=≤<=*t*<=≤<=109) and *c* (1<=≤<=*c*<=≤<=*n*). The next line will contain *n* space separated integers, the *i**th* integer is the severity *i**th* prisoner's crime. The value of crime severities will be non-negative and will not exceed 109.
Output Specification:
Print a single integer — the number of ways you can choose the *c* prisoners.
Demo Input:
['4 3 3\n2 3 1 1\n', '1 1 1\n2\n', '11 4 2\n2 2 0 7 3 2 2 4 9 1 4\n']
Demo Output:
['2\n', '0\n', '6\n']
Note:
none | ```python
import sys
n, t, c = map(int, input().split())
vec = [-1]
for i, temp in enumerate(map(int, sys.stdin.readline().split())):
if temp > t:
vec.append(i)
vec.append(n)
ans = 0
for i in range(1, len(vec)):
diff = vec[i] - vec[i - 1] - 1
ans += max(diff - c + 1, 0)
sys.stdout.write(str(ans) + '\n')
``` | 3 |
|
61 | A | Ultra-Fast Mathematician | PROGRAMMING | 800 | [
"implementation"
] | A. Ultra-Fast Mathematician | 2 | 256 | Shapur was an extremely gifted student. He was great at everything including Combinatorics, Algebra, Number Theory, Geometry, Calculus, etc. He was not only smart but extraordinarily fast! He could manage to sum 1018 numbers in a single second.
One day in 230 AD Shapur was trying to find out if any one can possibly do calculations faster than him. As a result he made a very great contest and asked every one to come and take part.
In his contest he gave the contestants many different pairs of numbers. Each number is made from digits 0 or 1. The contestants should write a new number corresponding to the given pair of numbers. The rule is simple: The *i*-th digit of the answer is 1 if and only if the *i*-th digit of the two given numbers differ. In the other case the *i*-th digit of the answer is 0.
Shapur made many numbers and first tried his own speed. He saw that he can perform these operations on numbers of length ∞ (length of a number is number of digits in it) in a glance! He always gives correct answers so he expects the contestants to give correct answers, too. He is a good fellow so he won't give anyone very big numbers and he always gives one person numbers of same length.
Now you are going to take part in Shapur's contest. See if you are faster and more accurate. | There are two lines in each input. Each of them contains a single number. It is guaranteed that the numbers are made from 0 and 1 only and that their length is same. The numbers may start with 0. The length of each number doesn't exceed 100. | Write one line — the corresponding answer. Do not omit the leading 0s. | [
"1010100\n0100101\n",
"000\n111\n",
"1110\n1010\n",
"01110\n01100\n"
] | [
"1110001\n",
"111\n",
"0100\n",
"00010\n"
] | none | 500 | [
{
"input": "1010100\n0100101",
"output": "1110001"
},
{
"input": "000\n111",
"output": "111"
},
{
"input": "1110\n1010",
"output": "0100"
},
{
"input": "01110\n01100",
"output": "00010"
},
{
"input": "011101\n000001",
"output": "011100"
},
{
"input": "10\n01",
"output": "11"
},
{
"input": "00111111\n11011101",
"output": "11100010"
},
{
"input": "011001100\n101001010",
"output": "110000110"
},
{
"input": "1100100001\n0110101100",
"output": "1010001101"
},
{
"input": "00011101010\n10010100101",
"output": "10001001111"
},
{
"input": "100000101101\n111010100011",
"output": "011010001110"
},
{
"input": "1000001111010\n1101100110001",
"output": "0101101001011"
},
{
"input": "01011111010111\n10001110111010",
"output": "11010001101101"
},
{
"input": "110010000111100\n001100101011010",
"output": "111110101100110"
},
{
"input": "0010010111110000\n0000000011010110",
"output": "0010010100100110"
},
{
"input": "00111110111110000\n01111100001100000",
"output": "01000010110010000"
},
{
"input": "101010101111010001\n001001111101111101",
"output": "100011010010101100"
},
{
"input": "0110010101111100000\n0011000101000000110",
"output": "0101010000111100110"
},
{
"input": "11110100011101010111\n00001000011011000000",
"output": "11111100000110010111"
},
{
"input": "101010101111101101001\n111010010010000011111",
"output": "010000111101101110110"
},
{
"input": "0000111111100011000010\n1110110110110000001010",
"output": "1110001001010011001000"
},
{
"input": "10010010101000110111000\n00101110100110111000111",
"output": "10111100001110001111111"
},
{
"input": "010010010010111100000111\n100100111111100011001110",
"output": "110110101101011111001001"
},
{
"input": "0101110100100111011010010\n0101100011010111001010001",
"output": "0000010111110000010000011"
},
{
"input": "10010010100011110111111011\n10000110101100000001000100",
"output": "00010100001111110110111111"
},
{
"input": "000001111000000100001000000\n011100111101111001110110001",
"output": "011101000101111101111110001"
},
{
"input": "0011110010001001011001011100\n0000101101000011101011001010",
"output": "0011011111001010110010010110"
},
{
"input": "11111000000000010011001101111\n11101110011001010100010000000",
"output": "00010110011001000111011101111"
},
{
"input": "011001110000110100001100101100\n001010000011110000001000101001",
"output": "010011110011000100000100000101"
},
{
"input": "1011111010001100011010110101111\n1011001110010000000101100010101",
"output": "0000110100011100011111010111010"
},
{
"input": "10111000100001000001010110000001\n10111000001100101011011001011000",
"output": "00000000101101101010001111011001"
},
{
"input": "000001010000100001000000011011100\n111111111001010100100001100000111",
"output": "111110101001110101100001111011011"
},
{
"input": "1101000000000010011011101100000110\n1110000001100010011010000011011110",
"output": "0011000001100000000001101111011000"
},
{
"input": "01011011000010100001100100011110001\n01011010111000001010010100001110000",
"output": "00000001111010101011110000010000001"
},
{
"input": "000011111000011001000110111100000100\n011011000110000111101011100111000111",
"output": "011000111110011110101101011011000011"
},
{
"input": "1001000010101110001000000011111110010\n0010001011010111000011101001010110000",
"output": "1011001001111001001011101010101000010"
},
{
"input": "00011101011001100101111111000000010101\n10010011011011001011111000000011101011",
"output": "10001110000010101110000111000011111110"
},
{
"input": "111011100110001001101111110010111001010\n111111101101111001110010000101101000100",
"output": "000100001011110000011101110111010001110"
},
{
"input": "1111001001101000001000000010010101001010\n0010111100111110001011000010111110111001",
"output": "1101110101010110000011000000101011110011"
},
{
"input": "00100101111000000101011111110010100011010\n11101110001010010101001000111110101010100",
"output": "11001011110010010000010111001100001001110"
},
{
"input": "101011001110110100101001000111010101101111\n100111100110101011010100111100111111010110",
"output": "001100101000011111111101111011101010111001"
},
{
"input": "1111100001100101000111101001001010011100001\n1000110011000011110010001011001110001000001",
"output": "0111010010100110110101100010000100010100000"
},
{
"input": "01100111011111010101000001101110000001110101\n10011001011111110000000101011001001101101100",
"output": "11111110000000100101000100110111001100011001"
},
{
"input": "110010100111000100100101100000011100000011001\n011001111011100110000110111001110110100111011",
"output": "101011011100100010100011011001101010100100010"
},
{
"input": "0001100111111011010110100100111000000111000110\n1100101011000000000001010010010111001100110001",
"output": "1101001100111011010111110110101111001011110111"
},
{
"input": "00000101110110110001110010100001110100000100000\n10010000110011110001101000111111101010011010001",
"output": "10010101000101000000011010011110011110011110001"
},
{
"input": "110000100101011100100011001111110011111110010001\n101011111001011100110110111101110011010110101100",
"output": "011011011100000000010101110010000000101000111101"
},
{
"input": "0101111101011111010101011101000011101100000000111\n0000101010110110001110101011011110111001010100100",
"output": "0101010111101001011011110110011101010101010100011"
},
{
"input": "11000100010101110011101000011111001010110111111100\n00001111000111001011111110000010101110111001000011",
"output": "11001011010010111000010110011101100100001110111111"
},
{
"input": "101000001101111101101111111000001110110010101101010\n010011100111100001100000010001100101000000111011011",
"output": "111011101010011100001111101001101011110010010110001"
},
{
"input": "0011111110010001010100010110111000110011001101010100\n0111000000100010101010000100101000000100101000111001",
"output": "0100111110110011111110010010010000110111100101101101"
},
{
"input": "11101010000110000011011010000001111101000111011111100\n10110011110001010100010110010010101001010111100100100",
"output": "01011001110111010111001100010011010100010000111011000"
},
{
"input": "011000100001000001101000010110100110011110100111111011\n111011001000001001110011001111011110111110110011011111",
"output": "100011101001001000011011011001111000100000010100100100"
},
{
"input": "0111010110010100000110111011010110100000000111110110000\n1011100100010001101100000100111111101001110010000100110",
"output": "1100110010000101101010111111101001001001110101110010110"
},
{
"input": "10101000100111000111010001011011011011110100110101100011\n11101111000000001100100011111000100100000110011001101110",
"output": "01000111100111001011110010100011111111110010101100001101"
},
{
"input": "000000111001010001000000110001001011100010011101010011011\n110001101000010010000101000100001111101001100100001010010",
"output": "110001010001000011000101110101000100001011111001011001001"
},
{
"input": "0101011100111010000111110010101101111111000000111100011100\n1011111110000010101110111001000011100000100111111111000111",
"output": "1110100010111000101001001011101110011111100111000011011011"
},
{
"input": "11001000001100100111100111100100101011000101001111001001101\n10111110100010000011010100110100100011101001100000001110110",
"output": "01110110101110100100110011010000001000101100101111000111011"
},
{
"input": "010111011011101000000110000110100110001110100001110110111011\n101011110011101011101101011111010100100001100111100100111011",
"output": "111100101000000011101011011001110010101111000110010010000000"
},
{
"input": "1001011110110110000100011001010110000100011010010111010101110\n1101111100001000010111110011010101111010010100000001000010111",
"output": "0100100010111110010011101010000011111110001110010110010111001"
},
{
"input": "10000010101111100111110101111000010100110111101101111111111010\n10110110101100101010011001011010100110111011101100011001100111",
"output": "00110100000011001101101100100010110010001100000001100110011101"
},
{
"input": "011111010011111000001010101001101001000010100010111110010100001\n011111001011000011111001000001111001010110001010111101000010011",
"output": "000000011000111011110011101000010000010100101000000011010110010"
},
{
"input": "1111000000110001011101000100100100001111011100001111001100011111\n1101100110000101100001100000001001011011111011010101000101001010",
"output": "0010100110110100111100100100101101010100100111011010001001010101"
},
{
"input": "01100000101010010011001110100110110010000110010011011001100100011\n10110110010110111100100111000111000110010000000101101110000010111",
"output": "11010110111100101111101001100001110100010110010110110111100110100"
},
{
"input": "001111111010000100001100001010011001111110011110010111110001100111\n110000101001011000100010101100100110000111100000001101001110010111",
"output": "111111010011011100101110100110111111111001111110011010111111110000"
},
{
"input": "1011101011101101011110101101011101011000010011100101010101000100110\n0001000001001111010111100100111101100000000001110001000110000000110",
"output": "1010101010100010001001001001100000111000010010010100010011000100000"
},
{
"input": "01000001011001010011011100010000100100110101111011011011110000001110\n01011110000110011011000000000011000111100001010000000011111001110000",
"output": "00011111011111001000011100010011100011010100101011011000001001111110"
},
{
"input": "110101010100110101000001111110110100010010000100111110010100110011100\n111010010111111011100110101011001011001110110111110100000110110100111",
"output": "001111000011001110100111010101111111011100110011001010010010000111011"
},
{
"input": "1001101011000001011111100110010010000011010001001111011100010100110001\n1111100111110101001111010001010000011001001001010110001111000000100101",
"output": "0110001100110100010000110111000010011010011000011001010011010100010100"
},
{
"input": "00000111110010110001110110001010010101000111011001111111100110011110010\n00010111110100000100110101000010010001100001100011100000001100010100010",
"output": "00010000000110110101000011001000000100100110111010011111101010001010000"
},
{
"input": "100101011100101101000011010001011001101110101110001100010001010111001110\n100001111100101011011111110000001111000111001011111110000010101110111001",
"output": "000100100000000110011100100001010110101001100101110010010011111001110111"
},
{
"input": "1101100001000111001101001011101000111000011110000001001101101001111011010\n0101011101010100011011010110101000010010110010011110101100000110110001000",
"output": "1000111100010011010110011101000000101010101100011111100001101111001010010"
},
{
"input": "01101101010011110101100001110101111011100010000010001101111000011110111111\n00101111001101001100111010000101110000100101101111100111101110010100011011",
"output": "01000010011110111001011011110000001011000111101101101010010110001010100100"
},
{
"input": "101100101100011001101111110110110010100110110010100001110010110011001101011\n000001011010101011110011111101001110000111000010001101000010010000010001101",
"output": "101101110110110010011100001011111100100001110000101100110000100011011100110"
},
{
"input": "0010001011001010001100000010010011110110011000100000000100110000101111001110\n1100110100111000110100001110111001011101001100001010100001010011100110110001",
"output": "1110111111110010111000001100101010101011010100101010100101100011001001111111"
},
{
"input": "00101101010000000101011001101011001100010001100000101011101110000001111001000\n10010110010111000000101101000011101011001010000011011101101011010000000011111",
"output": "10111011000111000101110100101000100111011011100011110110000101010001111010111"
},
{
"input": "111100000100100000101001100001001111001010001000001000000111010000010101101011\n001000100010100101111011111011010110101100001111011000010011011011100010010110",
"output": "110100100110000101010010011010011001100110000111010000010100001011110111111101"
},
{
"input": "0110001101100100001111110101101000100101010010101010011001101001001101110000000\n0111011000000010010111011110010000000001000110001000011001101000000001110100111",
"output": "0001010101100110011000101011111000100100010100100010000000000001001100000100111"
},
{
"input": "10001111111001000101001011110101111010100001011010101100111001010001010010001000\n10000111010010011110111000111010101100000011110001101111001000111010100000000001",
"output": "00001000101011011011110011001111010110100010101011000011110001101011110010001001"
},
{
"input": "100110001110110000100101001110000011110110000110000000100011110100110110011001101\n110001110101110000000100101001101011111100100100001001000110000001111100011110110",
"output": "010111111011000000100001100111101000001010100010001001100101110101001010000111011"
},
{
"input": "0000010100100000010110111100011111111010011101000000100000011001001101101100111010\n0100111110011101010110101011110110010111001111000110101100101110111100101000111111",
"output": "0100101010111101000000010111101001101101010010000110001100110111110001000100000101"
},
{
"input": "11000111001010100001110000001001011010010010110000001110100101000001010101100110111\n11001100100100100001101010110100000111100011101110011010110100001001000011011011010",
"output": "00001011101110000000011010111101011101110001011110010100010001001000010110111101101"
},
{
"input": "010110100010001000100010101001101010011010111110100001000100101000111011100010100001\n110000011111101101010011111000101010111010100001001100001001100101000000111000000000",
"output": "100110111101100101110001010001000000100000011111101101001101001101111011011010100001"
},
{
"input": "0000011110101110010101110110110101100001011001101010101001000010000010000000101001101\n1100111111011100000110000111101110011111100111110001011001000010011111100001001100011",
"output": "1100100001110010010011110001011011111110111110011011110000000000011101100001100101110"
},
{
"input": "10100000101101110001100010010010100101100011010010101000110011100000101010110010000000\n10001110011011010010111011011101101111000111110000111000011010010101001100000001010011",
"output": "00101110110110100011011001001111001010100100100010010000101001110101100110110011010011"
},
{
"input": "001110000011111101101010011111000101010111010100001001100001001100101000000111000000000\n111010000000000000101001110011001000111011001100101010011001000011101001001011110000011",
"output": "110100000011111101000011101100001101101100011000100011111000001111000001001100110000011"
},
{
"input": "1110111100111011010101011011001110001010010010110011110010011111000010011111010101100001\n1001010101011001001010100010101100000110111101011000100010101111111010111100001110010010",
"output": "0111101001100010011111111001100010001100101111101011010000110000111000100011011011110011"
},
{
"input": "11100010001100010011001100001100010011010001101110011110100101110010101101011101000111111\n01110000000110111010110100001010000101011110100101010011000110101110101101110111011110001",
"output": "10010010001010101001111000000110010110001111001011001101100011011100000000101010011001110"
},
{
"input": "001101011001100101101100110000111000101011001001100100000100101000100000110100010111111101\n101001111110000010111101111110001001111001111101111010000110111000100100110010010001011111",
"output": "100100100111100111010001001110110001010010110100011110000010010000000100000110000110100010"
},
{
"input": "1010110110010101000110010010110101011101010100011001101011000110000000100011100100011000000\n0011011111100010001111101101000111001011101110100000110111100100101111010110101111011100011",
"output": "1001101001110111001001111111110010010110111010111001011100100010101111110101001011000100011"
},
{
"input": "10010010000111010111011111110010100101100000001100011100111011100010000010010001011100001100\n00111010100010110010000100010111010001111110100100100011101000101111111111001101101100100100",
"output": "10101000100101100101011011100101110100011110101000111111010011001101111101011100110000101000"
},
{
"input": "010101110001010101100000010111010000000111110011001101100011001000000011001111110000000010100\n010010111011100101010101111110110000000111000100001101101001001000001100101110001010000100001",
"output": "000111001010110000110101101001100000000000110111000000001010000000001111100001111010000110101"
},
{
"input": "1100111110011001000111101001001011000110011010111111100010111111001100111111011101100111101011\n1100000011001000110100110111000001011001010111101000010010100011000001100100111101101000010110",
"output": "0000111101010001110011011110001010011111001101010111110000011100001101011011100000001111111101"
},
{
"input": "00011000100100110111100101100100000000010011110111110010101110110011100001010111010011110100101\n00011011111011111011100101100111100101001110010111000010000111000100100100000001110101111011011",
"output": "00000011011111001100000000000011100101011101100000110000101001110111000101010110100110001111110"
},
{
"input": "000101011001001100000111100010110101111011110101111101000110001101011010111110110011100100000001\n011000101010011111011000111000100000000011011000000001111110001000001111101010110000011100001111",
"output": "011101110011010011011111011010010101111000101101111100111000000101010101010100000011111000001110"
},
{
"input": "1000101001011010000100100100010010011101011001110101111011101111111110010101001101010001010101001\n0110110010011100011111011111110111000000010001110100001010111110101011010011111011111110000110000",
"output": "1110011011000110011011111011100101011101001000000001110001010001010101000110110110101111010011001"
},
{
"input": "01111010010101100111110111111011011010100001011101010000111100101101101110111011001100101011100111\n00001100110110100001111011000010001001001100000010111101000001111011100000010111010010000011000010",
"output": "01110110100011000110001100111001010011101101011111101101111101010110001110101100011110101000100101"
},
{
"input": "111101011101111000001011001101111010110111001101110100100011111011011101001101010101011010111000110\n101111100101101101001100110011000001111010011101110111110110101110011011110011111100001001110101101",
"output": "010010111000010101000111111110111011001101010000000011010101010101000110111110101001010011001101011"
},
{
"input": "1010000011010110011101001101110001110010000111011101110010110110111111001001110100101100010101010001\n0111101000111100101100000101111010100100001000011101010100110011100011010011010101000100101011100011",
"output": "1101101011101010110001001000001011010110001111000000100110000101011100011010100001101000111110110010"
},
{
"input": "0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001\n1111111010111111101011111110101111111010111111101011111110101111111010111111101011111110101111111010",
"output": "1111111010111111101011111110101111111010111111101011111110101111111010111111101011111110101111111011"
},
{
"input": "0\n0",
"output": "0"
},
{
"input": "0\n1",
"output": "1"
}
] | 1,635,769,339 | 2,147,483,647 | Python 3 | OK | TESTS | 102 | 46 | 4,300,800 | a=input()
b=input()
res=[]
for i in range(len(a)):
if a[i]!=b[i]:
res.append('1')
else:
res.append('0')
print(*res,sep='')
| Title: Ultra-Fast Mathematician
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Shapur was an extremely gifted student. He was great at everything including Combinatorics, Algebra, Number Theory, Geometry, Calculus, etc. He was not only smart but extraordinarily fast! He could manage to sum 1018 numbers in a single second.
One day in 230 AD Shapur was trying to find out if any one can possibly do calculations faster than him. As a result he made a very great contest and asked every one to come and take part.
In his contest he gave the contestants many different pairs of numbers. Each number is made from digits 0 or 1. The contestants should write a new number corresponding to the given pair of numbers. The rule is simple: The *i*-th digit of the answer is 1 if and only if the *i*-th digit of the two given numbers differ. In the other case the *i*-th digit of the answer is 0.
Shapur made many numbers and first tried his own speed. He saw that he can perform these operations on numbers of length ∞ (length of a number is number of digits in it) in a glance! He always gives correct answers so he expects the contestants to give correct answers, too. He is a good fellow so he won't give anyone very big numbers and he always gives one person numbers of same length.
Now you are going to take part in Shapur's contest. See if you are faster and more accurate.
Input Specification:
There are two lines in each input. Each of them contains a single number. It is guaranteed that the numbers are made from 0 and 1 only and that their length is same. The numbers may start with 0. The length of each number doesn't exceed 100.
Output Specification:
Write one line — the corresponding answer. Do not omit the leading 0s.
Demo Input:
['1010100\n0100101\n', '000\n111\n', '1110\n1010\n', '01110\n01100\n']
Demo Output:
['1110001\n', '111\n', '0100\n', '00010\n']
Note:
none | ```python
a=input()
b=input()
res=[]
for i in range(len(a)):
if a[i]!=b[i]:
res.append('1')
else:
res.append('0')
print(*res,sep='')
``` | 3.980489 |
258 | A | Little Elephant and Bits | PROGRAMMING | 1,100 | [
"greedy",
"math"
] | null | null | The Little Elephant has an integer *a*, written in the binary notation. He wants to write this number on a piece of paper.
To make sure that the number *a* fits on the piece of paper, the Little Elephant ought to delete exactly one any digit from number *a* in the binary record. At that a new number appears. It consists of the remaining binary digits, written in the corresponding order (possible, with leading zeroes).
The Little Elephant wants the number he is going to write on the paper to be as large as possible. Help him find the maximum number that he can obtain after deleting exactly one binary digit and print it in the binary notation. | The single line contains integer *a*, written in the binary notation without leading zeroes. This number contains more than 1 and at most 105 digits. | In the single line print the number that is written without leading zeroes in the binary notation — the answer to the problem. | [
"101\n",
"110010\n"
] | [
"11\n",
"11010\n"
] | In the first sample the best strategy is to delete the second digit. That results in number 11<sub class="lower-index">2</sub> = 3<sub class="lower-index">10</sub>.
In the second sample the best strategy is to delete the third or fourth digits — that results in number 11010<sub class="lower-index">2</sub> = 26<sub class="lower-index">10</sub>. | 500 | [
{
"input": "101",
"output": "11"
},
{
"input": "110010",
"output": "11010"
},
{
"input": "10000",
"output": "1000"
},
{
"input": "1111111110",
"output": "111111111"
},
{
"input": "10100101011110101",
"output": "1100101011110101"
},
{
"input": "111010010111",
"output": "11110010111"
},
{
"input": "11110111011100000000",
"output": "1111111011100000000"
},
{
"input": "11110010010100001110110101110011110110100111101",
"output": "1111010010100001110110101110011110110100111101"
},
{
"input": "1001011111010010100111111",
"output": "101011111010010100111111"
},
{
"input": "1111111111",
"output": "111111111"
},
{
"input": "1111111111111111111100111101001110110111111000001111110101001101001110011000001011001111111000110101",
"output": "111111111111111111110111101001110110111111000001111110101001101001110011000001011001111111000110101"
},
{
"input": "11010110000100100101111110111001001010011000011011000010010100111010101000111010011101101111110001111000101000001100011101110100",
"output": "1110110000100100101111110111001001010011000011011000010010100111010101000111010011101101111110001111000101000001100011101110100"
},
{
"input": "11111111111111111111111110110111001101100111010010101101101001011100011011000111010011110010101100010001011101011010010100001000011100001101101001100010100001001010010100100001111110100110011000101100001111111011010111001011111110111101000100101001001011",
"output": "1111111111111111111111111110111001101100111010010101101101001011100011011000111010011110010101100010001011101011010010100001000011100001101101001100010100001001010010100100001111110100110011000101100001111111011010111001011111110111101000100101001001011"
},
{
"input": "11100010010010000110101101101100111111001010001101101001001111010110010111001011010000001100110101000101111000001111101111110010000010101110011110101101010110001100011101111011100010011101100111110010111111100110101000000111101000000000110100100101111101000110101010101101001110001110000101011010101100011100100111100010001011010010001100011111110010011010011000111000100111100010110100011010010101011011011111110100001110000011011",
"output": "1110010010010000110101101101100111111001010001101101001001111010110010111001011010000001100110101000101111000001111101111110010000010101110011110101101010110001100011101111011100010011101100111110010111111100110101000000111101000000000110100100101111101000110101010101101001110001110000101011010101100011100100111100010001011010010001100011111110010011010011000111000100111100010110100011010010101011011011111110100001110000011011"
},
{
"input": "11",
"output": "1"
},
{
"input": "111",
"output": "11"
},
{
"input": "111111",
"output": "11111"
},
{
"input": "11111",
"output": "1111"
},
{
"input": "1111",
"output": "111"
}
] | 1,618,995,477 | 2,147,483,647 | PyPy 3 | OK | TESTS | 37 | 218 | 2,355,200 | s = input()
for idx in range(len(s)):
if s[idx] == "0":
break
print(s[:idx]+s[idx+1:]) | Title: Little Elephant and Bits
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The Little Elephant has an integer *a*, written in the binary notation. He wants to write this number on a piece of paper.
To make sure that the number *a* fits on the piece of paper, the Little Elephant ought to delete exactly one any digit from number *a* in the binary record. At that a new number appears. It consists of the remaining binary digits, written in the corresponding order (possible, with leading zeroes).
The Little Elephant wants the number he is going to write on the paper to be as large as possible. Help him find the maximum number that he can obtain after deleting exactly one binary digit and print it in the binary notation.
Input Specification:
The single line contains integer *a*, written in the binary notation without leading zeroes. This number contains more than 1 and at most 105 digits.
Output Specification:
In the single line print the number that is written without leading zeroes in the binary notation — the answer to the problem.
Demo Input:
['101\n', '110010\n']
Demo Output:
['11\n', '11010\n']
Note:
In the first sample the best strategy is to delete the second digit. That results in number 11<sub class="lower-index">2</sub> = 3<sub class="lower-index">10</sub>.
In the second sample the best strategy is to delete the third or fourth digits — that results in number 11010<sub class="lower-index">2</sub> = 26<sub class="lower-index">10</sub>. | ```python
s = input()
for idx in range(len(s)):
if s[idx] == "0":
break
print(s[:idx]+s[idx+1:])
``` | 3 |
|
981 | C | Useful Decomposition | PROGRAMMING | 1,400 | [
"implementation",
"trees"
] | null | null | Ramesses knows a lot about problems involving trees (undirected connected graphs without cycles)!
He created a new useful tree decomposition, but he does not know how to construct it, so he asked you for help!
The decomposition is the splitting the edges of the tree in some simple paths in such a way that each two paths have at least one common vertex. Each edge of the tree should be in exactly one path.
Help Remesses, find such a decomposition of the tree or derermine that there is no such decomposition. | The first line contains a single integer $n$ ($2 \leq n \leq 10^{5}$) the number of nodes in the tree.
Each of the next $n<=-<=1$ lines contains two integers $a_i$ and $b_i$ ($1 \leq a_i, b_i \leq n$, $a_i \neq b_i$) — the edges of the tree. It is guaranteed that the given edges form a tree. | If there are no decompositions, print the only line containing "No".
Otherwise in the first line print "Yes", and in the second line print the number of paths in the decomposition $m$.
Each of the next $m$ lines should contain two integers $u_i$, $v_i$ ($1 \leq u_i, v_i \leq n$, $u_i \neq v_i$) denoting that one of the paths in the decomposition is the simple path between nodes $u_i$ and $v_i$.
Each pair of paths in the decomposition should have at least one common vertex, and each edge of the tree should be presented in exactly one path. You can print the paths and the ends of each path in arbitrary order.
If there are multiple decompositions, print any. | [
"4\n1 2\n2 3\n3 4\n",
"6\n1 2\n2 3\n3 4\n2 5\n3 6\n",
"5\n1 2\n1 3\n1 4\n1 5\n"
] | [
"Yes\n1\n1 4\n",
"No\n",
"Yes\n4\n1 2\n1 3\n1 4\n1 5\n"
] | The tree from the first example is shown on the picture below: <img class="tex-graphics" src="https://espresso.codeforces.com/9eb4b4c143d3ad267ae05d1e43341bd368b3088b.png" style="max-width: 100.0%;max-height: 100.0%;"/> The number next to each edge corresponds to the path number in the decomposition. It is easy to see that this decomposition suits the required conditions.
The tree from the second example is shown on the picture below: <img class="tex-graphics" src="https://espresso.codeforces.com/20704b97182d9bcde3321c00a16edcae4d772d93.png" style="max-width: 100.0%;max-height: 100.0%;"/> We can show that there are no valid decompositions of this tree.
The tree from the third example is shown on the picture below: <img class="tex-graphics" src="https://espresso.codeforces.com/357ff9496a4ed4746401160ee6ee63f5d57d81b9.png" style="max-width: 100.0%;max-height: 100.0%;"/> The number next to each edge corresponds to the path number in the decomposition. It is easy to see that this decomposition suits the required conditions. | 1,250 | [
{
"input": "4\n1 2\n2 3\n3 4",
"output": "Yes\n1\n1 4"
},
{
"input": "6\n1 2\n2 3\n3 4\n2 5\n3 6",
"output": "No"
},
{
"input": "5\n1 2\n1 3\n1 4\n1 5",
"output": "Yes\n4\n1 2\n1 3\n1 4\n1 5"
},
{
"input": "2\n1 2",
"output": "Yes\n1\n1 2"
},
{
"input": "8\n1 2\n1 3\n1 4\n1 8\n7 8\n6 8\n5 8",
"output": "No"
},
{
"input": "9\n1 2\n1 3\n1 4\n1 5\n1 6\n6 7\n7 8\n7 9",
"output": "No"
},
{
"input": "3\n2 3\n1 2",
"output": "Yes\n1\n1 3"
}
] | 1,527,500,902 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 187 | 4,710,400 | #!/usr/bin/env python
# -*- coding: utf-8 -*-
def local_input():
from pcm.utils import set_stdin
import sys
if len(sys.argv) == 1:
set_stdin(os.path.dirname(__file__) + '/test/' + 'sample-1.in')
import sys
import os
from sys import stdin, stdout
import time
import re
from pydoc import help
import string
import math
import numpy as np
from operator import itemgetter
from collections import Counter
from collections import deque
from collections import defaultdict as dd
import fractions
from heapq import heappop, heappush, heapify
import array
from bisect import bisect_left, bisect_right, insort_left, insort_right
from copy import deepcopy as dcopy
import itertools
sys.setrecursionlimit(10**7)
INF = 10**20
GOSA = 1.0 / 10**10
MOD = 10**9+7
ALPHABETS = [chr(i) for i in range(ord('a'), ord('z')+1)] # can also use string module
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def DP(N, M, first): return [[first] * M for n in range(N)]
def DP3(N, M, L, first): return [[[first] * L for n in range(M)] for _ in range(N)]
def solve():
global T, N, g
N = int(input())
T = [[] for _ in range(N)]
for n in range(N-1):
a, b = map(lambda x:int(x)-1, input().split())
T[a].append(b)
T[b].append(a)
# print(T)
g = -1
for n, t in enumerate(T):
if len(t) >= 3 and g==-1:
g = n
elif len(t) >= 3 and g!=-1:
print("No")
return
if g == -1:
print("Yes")
print("1")
res = []
for n, t in enumerate(T):
if len(t) == 1:
res.append(n+1)
print(*res)
return
print("Yes")
print(len(T[g]))
res = ""
for n in T[g]:
res += str(g+1)+" "+str(get_tip(n)+1)+"\n"
stdout.write(res)
def get_tip(n):
R = [0]*N
R[g] = 1
now = n
while True:
if len(T[now]) == 1:
return now
if R[T[now][0]] == 0:
R[now] = 1
now = T[now][0]
elif R[T[now][1]] == 0:
R[now] = 1
now = T[now][1]
if __name__ == "__main__":
try:
local_input()
except:
pass
solve()
| Title: Useful Decomposition
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Ramesses knows a lot about problems involving trees (undirected connected graphs without cycles)!
He created a new useful tree decomposition, but he does not know how to construct it, so he asked you for help!
The decomposition is the splitting the edges of the tree in some simple paths in such a way that each two paths have at least one common vertex. Each edge of the tree should be in exactly one path.
Help Remesses, find such a decomposition of the tree or derermine that there is no such decomposition.
Input Specification:
The first line contains a single integer $n$ ($2 \leq n \leq 10^{5}$) the number of nodes in the tree.
Each of the next $n<=-<=1$ lines contains two integers $a_i$ and $b_i$ ($1 \leq a_i, b_i \leq n$, $a_i \neq b_i$) — the edges of the tree. It is guaranteed that the given edges form a tree.
Output Specification:
If there are no decompositions, print the only line containing "No".
Otherwise in the first line print "Yes", and in the second line print the number of paths in the decomposition $m$.
Each of the next $m$ lines should contain two integers $u_i$, $v_i$ ($1 \leq u_i, v_i \leq n$, $u_i \neq v_i$) denoting that one of the paths in the decomposition is the simple path between nodes $u_i$ and $v_i$.
Each pair of paths in the decomposition should have at least one common vertex, and each edge of the tree should be presented in exactly one path. You can print the paths and the ends of each path in arbitrary order.
If there are multiple decompositions, print any.
Demo Input:
['4\n1 2\n2 3\n3 4\n', '6\n1 2\n2 3\n3 4\n2 5\n3 6\n', '5\n1 2\n1 3\n1 4\n1 5\n']
Demo Output:
['Yes\n1\n1 4\n', 'No\n', 'Yes\n4\n1 2\n1 3\n1 4\n1 5\n']
Note:
The tree from the first example is shown on the picture below: <img class="tex-graphics" src="https://espresso.codeforces.com/9eb4b4c143d3ad267ae05d1e43341bd368b3088b.png" style="max-width: 100.0%;max-height: 100.0%;"/> The number next to each edge corresponds to the path number in the decomposition. It is easy to see that this decomposition suits the required conditions.
The tree from the second example is shown on the picture below: <img class="tex-graphics" src="https://espresso.codeforces.com/20704b97182d9bcde3321c00a16edcae4d772d93.png" style="max-width: 100.0%;max-height: 100.0%;"/> We can show that there are no valid decompositions of this tree.
The tree from the third example is shown on the picture below: <img class="tex-graphics" src="https://espresso.codeforces.com/357ff9496a4ed4746401160ee6ee63f5d57d81b9.png" style="max-width: 100.0%;max-height: 100.0%;"/> The number next to each edge corresponds to the path number in the decomposition. It is easy to see that this decomposition suits the required conditions. | ```python
#!/usr/bin/env python
# -*- coding: utf-8 -*-
def local_input():
from pcm.utils import set_stdin
import sys
if len(sys.argv) == 1:
set_stdin(os.path.dirname(__file__) + '/test/' + 'sample-1.in')
import sys
import os
from sys import stdin, stdout
import time
import re
from pydoc import help
import string
import math
import numpy as np
from operator import itemgetter
from collections import Counter
from collections import deque
from collections import defaultdict as dd
import fractions
from heapq import heappop, heappush, heapify
import array
from bisect import bisect_left, bisect_right, insort_left, insort_right
from copy import deepcopy as dcopy
import itertools
sys.setrecursionlimit(10**7)
INF = 10**20
GOSA = 1.0 / 10**10
MOD = 10**9+7
ALPHABETS = [chr(i) for i in range(ord('a'), ord('z')+1)] # can also use string module
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def DP(N, M, first): return [[first] * M for n in range(N)]
def DP3(N, M, L, first): return [[[first] * L for n in range(M)] for _ in range(N)]
def solve():
global T, N, g
N = int(input())
T = [[] for _ in range(N)]
for n in range(N-1):
a, b = map(lambda x:int(x)-1, input().split())
T[a].append(b)
T[b].append(a)
# print(T)
g = -1
for n, t in enumerate(T):
if len(t) >= 3 and g==-1:
g = n
elif len(t) >= 3 and g!=-1:
print("No")
return
if g == -1:
print("Yes")
print("1")
res = []
for n, t in enumerate(T):
if len(t) == 1:
res.append(n+1)
print(*res)
return
print("Yes")
print(len(T[g]))
res = ""
for n in T[g]:
res += str(g+1)+" "+str(get_tip(n)+1)+"\n"
stdout.write(res)
def get_tip(n):
R = [0]*N
R[g] = 1
now = n
while True:
if len(T[now]) == 1:
return now
if R[T[now][0]] == 0:
R[now] = 1
now = T[now][0]
elif R[T[now][1]] == 0:
R[now] = 1
now = T[now][1]
if __name__ == "__main__":
try:
local_input()
except:
pass
solve()
``` | -1 |
|
469 | A | I Wanna Be the Guy | PROGRAMMING | 800 | [
"greedy",
"implementation"
] | null | null | There is a game called "I Wanna Be the Guy", consisting of *n* levels. Little X and his friend Little Y are addicted to the game. Each of them wants to pass the whole game.
Little X can pass only *p* levels of the game. And Little Y can pass only *q* levels of the game. You are given the indices of levels Little X can pass and the indices of levels Little Y can pass. Will Little X and Little Y pass the whole game, if they cooperate each other? | The first line contains a single integer *n* (1<=≤<=<=*n*<=≤<=100).
The next line contains an integer *p* (0<=≤<=*p*<=≤<=*n*) at first, then follows *p* distinct integers *a*1,<=*a*2,<=...,<=*a**p* (1<=≤<=*a**i*<=≤<=*n*). These integers denote the indices of levels Little X can pass. The next line contains the levels Little Y can pass in the same format. It's assumed that levels are numbered from 1 to *n*. | If they can pass all the levels, print "I become the guy.". If it's impossible, print "Oh, my keyboard!" (without the quotes). | [
"4\n3 1 2 3\n2 2 4\n",
"4\n3 1 2 3\n2 2 3\n"
] | [
"I become the guy.\n",
"Oh, my keyboard!\n"
] | In the first sample, Little X can pass levels [1 2 3], and Little Y can pass level [2 4], so they can pass all the levels both.
In the second sample, no one can pass level 4. | 500 | [
{
"input": "4\n3 1 2 3\n2 2 4",
"output": "I become the guy."
},
{
"input": "4\n3 1 2 3\n2 2 3",
"output": "Oh, my keyboard!"
},
{
"input": "10\n5 8 6 1 5 4\n6 1 3 2 9 4 6",
"output": "Oh, my keyboard!"
},
{
"input": "10\n8 8 10 7 3 1 4 2 6\n8 9 5 10 3 7 2 4 8",
"output": "I become the guy."
},
{
"input": "10\n9 6 1 8 3 9 7 5 10 4\n7 1 3 2 7 6 9 5",
"output": "I become the guy."
},
{
"input": "100\n75 83 69 73 30 76 37 48 14 41 42 21 35 15 50 61 86 85 46 3 31 13 78 10 2 44 80 95 56 82 38 75 77 4 99 9 84 53 12 11 36 74 39 72 43 89 57 28 54 1 51 66 27 22 93 59 68 88 91 29 7 20 63 8 52 23 64 58 100 79 65 49 96 71 33 45\n83 50 89 73 34 28 99 67 77 44 19 60 68 42 8 27 94 85 14 39 17 78 24 21 29 63 92 32 86 22 71 81 31 82 65 48 80 59 98 3 70 55 37 12 15 72 47 9 11 33 16 7 91 74 13 64 38 84 6 61 93 90 45 69 1 54 52 100 57 10 35 49 53 75 76 43 62 5 4 18 36 96 79 23",
"output": "Oh, my keyboard!"
},
{
"input": "1\n1 1\n1 1",
"output": "I become the guy."
},
{
"input": "1\n0\n1 1",
"output": "I become the guy."
},
{
"input": "1\n1 1\n0",
"output": "I become the guy."
},
{
"input": "1\n0\n0",
"output": "Oh, my keyboard!"
},
{
"input": "100\n0\n0",
"output": "Oh, my keyboard!"
},
{
"input": "100\n44 71 70 55 49 43 16 53 7 95 58 56 38 76 67 94 20 73 29 90 25 30 8 84 5 14 77 52 99 91 66 24 39 37 22 44 78 12 63 59 32 51 15 82 34\n56 17 10 96 80 69 13 81 31 57 4 48 68 89 50 45 3 33 36 2 72 100 64 87 21 75 54 74 92 65 23 40 97 61 18 28 98 93 35 83 9 79 46 27 41 62 88 6 47 60 86 26 42 85 19 1 11",
"output": "I become the guy."
},
{
"input": "100\n78 63 59 39 11 58 4 2 80 69 22 95 90 26 65 16 30 100 66 99 67 79 54 12 23 28 45 56 70 74 60 82 73 91 68 43 92 75 51 21 17 97 86 44 62 47 85 78 72 64 50 81 71 5 57 13 31 76 87 9 49 96 25 42 19 35 88 53 7 83 38 27 29 41 89 93 10 84 18\n78 1 16 53 72 99 9 36 59 49 75 77 94 79 35 4 92 42 82 83 76 97 20 68 55 47 65 50 14 30 13 67 98 8 7 40 64 32 87 10 33 90 93 18 26 71 17 46 24 28 89 58 37 91 39 34 25 48 84 31 96 95 80 88 3 51 62 52 85 61 12 15 27 6 45 38 2 22 60",
"output": "I become the guy."
},
{
"input": "2\n2 2 1\n0",
"output": "I become the guy."
},
{
"input": "2\n1 2\n2 1 2",
"output": "I become the guy."
},
{
"input": "80\n57 40 1 47 36 69 24 76 5 72 26 4 29 62 6 60 3 70 8 64 18 37 16 14 13 21 25 7 66 68 44 74 61 39 38 33 15 63 34 65 10 23 56 51 80 58 49 75 71 12 50 57 2 30 54 27 17 52\n61 22 67 15 28 41 26 1 80 44 3 38 18 37 79 57 11 7 65 34 9 36 40 5 48 29 64 31 51 63 27 4 50 13 24 32 58 23 19 46 8 73 39 2 21 56 77 53 59 78 43 12 55 45 30 74 33 68 42 47 17 54",
"output": "Oh, my keyboard!"
},
{
"input": "100\n78 87 96 18 73 32 38 44 29 64 40 70 47 91 60 69 24 1 5 34 92 94 99 22 83 65 14 68 15 20 74 31 39 100 42 4 97 46 25 6 8 56 79 9 71 35 54 19 59 93 58 62 10 85 57 45 33 7 86 81 30 98 26 61 84 41 23 28 88 36 66 51 80 53 37 63 43 95 75\n76 81 53 15 26 37 31 62 24 87 41 39 75 86 46 76 34 4 51 5 45 65 67 48 68 23 71 27 94 47 16 17 9 96 84 89 88 100 18 52 69 42 6 92 7 64 49 12 98 28 21 99 25 55 44 40 82 19 36 30 77 90 14 43 50 3 13 95 78 35 20 54 58 11 2 1 33",
"output": "Oh, my keyboard!"
},
{
"input": "100\n77 55 26 98 13 91 78 60 23 76 12 11 36 62 84 80 18 1 68 92 81 67 19 4 2 10 17 77 96 63 15 69 46 97 82 42 83 59 50 72 14 40 89 9 52 29 56 31 74 39 45 85 22 99 44 65 95 6 90 38 54 32 49 34 3 70 75 33 94 53 21 71 5 66 73 41 100 24\n69 76 93 5 24 57 59 6 81 4 30 12 44 15 67 45 73 3 16 8 47 95 20 64 68 85 54 17 90 86 66 58 13 37 42 51 35 32 1 28 43 80 7 14 48 19 62 55 2 91 25 49 27 26 38 79 89 99 22 60 75 53 88 82 34 21 87 71 72 61",
"output": "I become the guy."
},
{
"input": "100\n74 96 32 63 12 69 72 99 15 22 1 41 79 77 71 31 20 28 75 73 85 37 38 59 42 100 86 89 55 87 68 4 24 57 52 8 92 27 56 98 95 58 34 9 45 14 11 36 66 76 61 19 25 23 78 49 90 26 80 43 70 13 65 10 5 74 81 21 44 60 97 3 47 93 6\n64 68 21 27 16 91 23 22 33 12 71 88 90 50 62 43 28 29 57 59 5 74 10 95 35 1 67 93 36 32 86 40 6 64 78 46 89 15 84 53 18 30 17 85 2 3 47 92 25 48 76 51 20 82 52 83 99 63 80 11 94 54 39 7 58",
"output": "I become the guy."
},
{
"input": "100\n75 11 98 44 47 88 94 23 78 59 70 2 43 39 34 63 71 19 42 61 30 74 14 77 97 53 92 60 67 36 37 13 6 86 62 46 41 3 25 93 7 12 27 48 55 49 31 35 51 10 57 54 95 82 28 90 73 26 17 50 81 56 20 87 40 85 72 64 99 29 91 5 80 18 24 52\n72 93 59 5 88 47 9 58 48 1 43 50 100 87 61 91 45 98 99 56 25 84 53 73 78 54 63 38 37 2 77 95 89 85 4 90 10 33 12 22 74 32 34 70 71 52 96 57 15 66 31 27 75 8 21 39 62 44 67 94 81 68 14 19 36 28 11 79 16 65 46 83 76",
"output": "Oh, my keyboard!"
},
{
"input": "3\n1 2\n2 2 3",
"output": "Oh, my keyboard!"
},
{
"input": "4\n1 2\n3 1 3 4",
"output": "I become the guy."
},
{
"input": "6\n2 1 2\n3 4 5 6",
"output": "Oh, my keyboard!"
}
] | 1,695,287,260 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 30 | 0 | #469A - I Wanna Be the Guy
n = int(input())
p = list(map(int, input().split()))
q = list(map(int, input().split()))
lvls = []
for ele in p:
lvls.append(ele)
for ele in q:
lvls.append(ele)
lvls = set(lvls)
if len(lvls) == 4: print("I become the guy")
else: print("Oh, my keyboard!")
| Title: I Wanna Be the Guy
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
There is a game called "I Wanna Be the Guy", consisting of *n* levels. Little X and his friend Little Y are addicted to the game. Each of them wants to pass the whole game.
Little X can pass only *p* levels of the game. And Little Y can pass only *q* levels of the game. You are given the indices of levels Little X can pass and the indices of levels Little Y can pass. Will Little X and Little Y pass the whole game, if they cooperate each other?
Input Specification:
The first line contains a single integer *n* (1<=≤<=<=*n*<=≤<=100).
The next line contains an integer *p* (0<=≤<=*p*<=≤<=*n*) at first, then follows *p* distinct integers *a*1,<=*a*2,<=...,<=*a**p* (1<=≤<=*a**i*<=≤<=*n*). These integers denote the indices of levels Little X can pass. The next line contains the levels Little Y can pass in the same format. It's assumed that levels are numbered from 1 to *n*.
Output Specification:
If they can pass all the levels, print "I become the guy.". If it's impossible, print "Oh, my keyboard!" (without the quotes).
Demo Input:
['4\n3 1 2 3\n2 2 4\n', '4\n3 1 2 3\n2 2 3\n']
Demo Output:
['I become the guy.\n', 'Oh, my keyboard!\n']
Note:
In the first sample, Little X can pass levels [1 2 3], and Little Y can pass level [2 4], so they can pass all the levels both.
In the second sample, no one can pass level 4. | ```python
#469A - I Wanna Be the Guy
n = int(input())
p = list(map(int, input().split()))
q = list(map(int, input().split()))
lvls = []
for ele in p:
lvls.append(ele)
for ele in q:
lvls.append(ele)
lvls = set(lvls)
if len(lvls) == 4: print("I become the guy")
else: print("Oh, my keyboard!")
``` | 0 |
|
468 | C | Hack it! | PROGRAMMING | 2,500 | [
"binary search",
"constructive algorithms",
"math"
] | null | null | Little X has met the following problem recently.
Let's define *f*(*x*) as the sum of digits in decimal representation of number *x* (for example, *f*(1234)<==<=1<=+<=2<=+<=3<=+<=4). You are to calculate
Of course Little X has solved this problem quickly, has locked it, and then has tried to hack others. He has seen the following C++ code: | The first line contains a single integer *a* (1<=≤<=*a*<=≤<=1018). | Print two integers: *l*,<=*r* (1<=≤<=*l*<=≤<=*r*<=<<=10200) — the required test data. Leading zeros aren't allowed. It's guaranteed that the solution exists. | [
"46\n",
"126444381000032\n"
] | [
"1 10\n",
"2333333 2333333333333\n"
] | none | 1,500 | [
{
"input": "46",
"output": "1 10"
},
{
"input": "126444381000032",
"output": "2333333 2333333333333"
},
{
"input": "69645082595",
"output": "613752823618441225798858488535 713259406474207764329704856394"
},
{
"input": "70602205995",
"output": "11 249221334020432074498656960922"
},
{
"input": "33898130785",
"output": "9 558855506346909386939077840182"
},
{
"input": "58929554039",
"output": "22 855783114773435710171914224422"
},
{
"input": "81696185182",
"output": "499118531974994927425925323518 956291458400902769638235161661"
},
{
"input": "1",
"output": "149268802942315027273202513064 277551734280589260570057105889"
},
{
"input": "2",
"output": "119692200833686078608961312319 629363568954685219494592939495"
},
{
"input": "3",
"output": "2 302254410562920936884653943506"
},
{
"input": "4",
"output": "284378053387469023431537894255 317250990020830090421009164911"
},
{
"input": "5",
"output": "2 62668056583245293799710157951"
},
{
"input": "6",
"output": "3 93810188780011787541394067841"
},
{
"input": "7",
"output": "2 834286447477504059026206246185"
},
{
"input": "8",
"output": "3 257583347960907690857477857197"
},
{
"input": "10",
"output": "3 163048811987317819669274448265"
},
{
"input": "11",
"output": "3 919618203693907154039906935669"
},
{
"input": "12",
"output": "448221703341269567451520778454 698029790336105644790102859494"
},
{
"input": "43",
"output": "9 172412961300207091437973214327"
},
{
"input": "36",
"output": "8 619355518777647869838990701242"
},
{
"input": "65",
"output": "6 709024330418134127413755925068"
},
{
"input": "43",
"output": "7 669540448846929747909766131221"
},
{
"input": "23",
"output": "2 104579054315773428039906118259"
},
{
"input": "100",
"output": "15 324437778467489559125023403167"
},
{
"input": "10000",
"output": "2 936791129091842315790163514642"
},
{
"input": "1000000",
"output": "18 369591628030718549289473454545"
},
{
"input": "100000000",
"output": "7 870405265198051697453938746950"
},
{
"input": "10000000000",
"output": "20 972749766921651560604778558599"
},
{
"input": "1000000000000",
"output": "6 68997070398311657294228230677"
},
{
"input": "100000000000000",
"output": "249537318528661282822184562278 397003438246047829818181818181"
},
{
"input": "10000000000000000",
"output": "10 778165727326620883431915444624"
},
{
"input": "1000000000000000000",
"output": "408256298986776744812953390000 824018301451167837914299999999"
},
{
"input": "450000000000000000",
"output": "2 357722688084551093593033993033"
},
{
"input": "432022",
"output": "3 333556238531076799985515487090"
},
{
"input": "428033",
"output": "22 730314748425770554502599499142"
},
{
"input": "776930",
"output": "20 521232359366297130685112811874"
},
{
"input": "329824",
"output": "308969571112207311167474021348 745620588073413831210052337999"
},
{
"input": "85058261498638",
"output": "16 931187081941564769324316582547"
},
{
"input": "2130909834463",
"output": "21 895378349209612431051450316022"
},
{
"input": "3427089130241",
"output": "10 676758114393938690602742889714"
},
{
"input": "22881472397923",
"output": "174523915446146844994793303441 429392837423394397373605399524"
},
{
"input": "756499070280135900",
"output": "17 414254565210363110239866979636"
},
{
"input": "348919756917359012",
"output": "15 148711424846749040017925495268"
},
{
"input": "789136710974630947",
"output": "13 214740524663440316532540770911"
},
{
"input": "32851678509090784",
"output": "15 728787006985867306455350840047"
},
{
"input": "219760524792138559",
"output": "8 51530430692061277616906746431"
},
{
"input": "1000000007",
"output": "19 96093944063249823335491170999"
},
{
"input": "999999874000003969",
"output": "306259936121099507549028331741 983025349899931537481252156006"
},
{
"input": "999999999999999989",
"output": "140766388309929586494194507367 705096656792775954903252198639"
},
{
"input": "999999999999999983",
"output": "4 365946710276937286091309116340"
},
{
"input": "999999999999999999",
"output": "26 983966655749419565978291923474"
}
] | 1,424,004,438 | 2,147,483,647 | Python 3 | OK | TESTS | 51 | 62 | 0 | a=int(input())
x=a-((10**20)*45*21+1)%a
print(1+x,10**21+x) | Title: Hack it!
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Little X has met the following problem recently.
Let's define *f*(*x*) as the sum of digits in decimal representation of number *x* (for example, *f*(1234)<==<=1<=+<=2<=+<=3<=+<=4). You are to calculate
Of course Little X has solved this problem quickly, has locked it, and then has tried to hack others. He has seen the following C++ code:
Input Specification:
The first line contains a single integer *a* (1<=≤<=*a*<=≤<=1018).
Output Specification:
Print two integers: *l*,<=*r* (1<=≤<=*l*<=≤<=*r*<=<<=10200) — the required test data. Leading zeros aren't allowed. It's guaranteed that the solution exists.
Demo Input:
['46\n', '126444381000032\n']
Demo Output:
['1 10\n', '2333333 2333333333333\n']
Note:
none | ```python
a=int(input())
x=a-((10**20)*45*21+1)%a
print(1+x,10**21+x)
``` | 3 |
|
534 | B | Covered Path | PROGRAMMING | 1,400 | [
"dp",
"greedy",
"math"
] | null | null | The on-board computer on Polycarp's car measured that the car speed at the beginning of some section of the path equals *v*1 meters per second, and in the end it is *v*2 meters per second. We know that this section of the route took exactly *t* seconds to pass.
Assuming that at each of the seconds the speed is constant, and between seconds the speed can change at most by *d* meters per second in absolute value (i.e., the difference in the speed of any two adjacent seconds does not exceed *d* in absolute value), find the maximum possible length of the path section in meters. | The first line contains two integers *v*1 and *v*2 (1<=≤<=*v*1,<=*v*2<=≤<=100) — the speeds in meters per second at the beginning of the segment and at the end of the segment, respectively.
The second line contains two integers *t* (2<=≤<=*t*<=≤<=100) — the time when the car moves along the segment in seconds, *d* (0<=≤<=*d*<=≤<=10) — the maximum value of the speed change between adjacent seconds.
It is guaranteed that there is a way to complete the segment so that:
- the speed in the first second equals *v*1, - the speed in the last second equals *v*2, - the absolute value of difference of speeds between any two adjacent seconds doesn't exceed *d*. | Print the maximum possible length of the path segment in meters. | [
"5 6\n4 2\n",
"10 10\n10 0\n"
] | [
"26",
"100"
] | In the first sample the sequence of speeds of Polycarpus' car can look as follows: 5, 7, 8, 6. Thus, the total path is 5 + 7 + 8 + 6 = 26 meters.
In the second sample, as *d* = 0, the car covers the whole segment at constant speed *v* = 10. In *t* = 10 seconds it covers the distance of 100 meters. | 1,000 | [
{
"input": "5 6\n4 2",
"output": "26"
},
{
"input": "10 10\n10 0",
"output": "100"
},
{
"input": "87 87\n2 10",
"output": "174"
},
{
"input": "1 11\n6 2",
"output": "36"
},
{
"input": "100 10\n10 10",
"output": "550"
},
{
"input": "1 1\n100 10",
"output": "24600"
},
{
"input": "1 1\n5 1",
"output": "9"
},
{
"input": "1 1\n5 2",
"output": "13"
},
{
"input": "100 100\n100 0",
"output": "10000"
},
{
"input": "100 100\n100 10",
"output": "34500"
},
{
"input": "1 100\n100 1",
"output": "5050"
},
{
"input": "1 100\n100 10",
"output": "29305"
},
{
"input": "100 1\n100 1",
"output": "5050"
},
{
"input": "100 1\n100 10",
"output": "29305"
},
{
"input": "1 10\n2 10",
"output": "11"
},
{
"input": "1 1\n2 1",
"output": "2"
},
{
"input": "1 1\n2 10",
"output": "2"
},
{
"input": "1 2\n2 1",
"output": "3"
},
{
"input": "1 2\n2 10",
"output": "3"
},
{
"input": "1 5\n3 2",
"output": "9"
},
{
"input": "2 1\n2 2",
"output": "3"
},
{
"input": "2 1\n2 10",
"output": "3"
},
{
"input": "1 11\n2 10",
"output": "12"
},
{
"input": "11 1\n2 10",
"output": "12"
},
{
"input": "1 1\n3 5",
"output": "8"
},
{
"input": "1 10\n3 5",
"output": "17"
},
{
"input": "1 21\n3 10",
"output": "33"
},
{
"input": "21 1\n3 10",
"output": "33"
},
{
"input": "100 100\n99 1",
"output": "12301"
},
{
"input": "100 100\n100 1",
"output": "12450"
},
{
"input": "99 99\n99 1",
"output": "12202"
},
{
"input": "99 99\n99 10",
"output": "33811"
},
{
"input": "1 100\n99 10",
"output": "28764"
},
{
"input": "13 31\n7 5",
"output": "182"
},
{
"input": "88 78\n8 5",
"output": "719"
},
{
"input": "34 48\n47 4",
"output": "4030"
},
{
"input": "91 29\n78 3",
"output": "8806"
},
{
"input": "90 81\n21 6",
"output": "2391"
},
{
"input": "95 89\n45 3",
"output": "5589"
},
{
"input": "48 54\n84 2",
"output": "7724"
},
{
"input": "72 31\n59 7",
"output": "8865"
},
{
"input": "51 13\n47 3",
"output": "2970"
},
{
"input": "97 91\n82 2",
"output": "10984"
},
{
"input": "71 71\n9 5",
"output": "719"
},
{
"input": "16 49\n40 3",
"output": "2350"
},
{
"input": "22 41\n68 4",
"output": "6608"
},
{
"input": "13 71\n72 6",
"output": "10444"
},
{
"input": "77 78\n46 3",
"output": "5083"
},
{
"input": "36 60\n54 2",
"output": "3924"
},
{
"input": "55 39\n93 2",
"output": "8571"
},
{
"input": "34 7\n48 6",
"output": "4266"
},
{
"input": "80 88\n79 3",
"output": "11193"
},
{
"input": "34 62\n15 4",
"output": "866"
},
{
"input": "81 40\n73 2",
"output": "6798"
},
{
"input": "13 38\n97 6",
"output": "16271"
},
{
"input": "84 87\n45 2",
"output": "4814"
},
{
"input": "42 65\n76 3",
"output": "8240"
},
{
"input": "55 6\n24 4",
"output": "1110"
},
{
"input": "41 16\n43 2",
"output": "2029"
},
{
"input": "99 93\n78 1",
"output": "8961"
},
{
"input": "10 7\n44 2",
"output": "1297"
},
{
"input": "72 54\n91 3",
"output": "11781"
},
{
"input": "48 34\n80 2",
"output": "6376"
},
{
"input": "92 85\n70 1",
"output": "7373"
}
] | 1,603,526,499 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 0 | 108 | 0 |
v1, v2 = map(int,input().split())
t,d = map(int,input().split())
if v1 > v2:
p=0
l= v1
for k in range(t):
if k==0:
p+=v1
elif k==t-1:
p+=v2
else:
if l > v2+d:
l-=d
p+=l
print(p)
elif v2 >v1:
p=0
l= v1
for k in range(t):
if k==0:
p+=v1
elif k==t-1:
p+=v2
else:
if l < v2+d:
l+=d
p+=l
else:
print(v1+v2 + (v1+d)*(t-2))
| Title: Covered Path
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The on-board computer on Polycarp's car measured that the car speed at the beginning of some section of the path equals *v*1 meters per second, and in the end it is *v*2 meters per second. We know that this section of the route took exactly *t* seconds to pass.
Assuming that at each of the seconds the speed is constant, and between seconds the speed can change at most by *d* meters per second in absolute value (i.e., the difference in the speed of any two adjacent seconds does not exceed *d* in absolute value), find the maximum possible length of the path section in meters.
Input Specification:
The first line contains two integers *v*1 and *v*2 (1<=≤<=*v*1,<=*v*2<=≤<=100) — the speeds in meters per second at the beginning of the segment and at the end of the segment, respectively.
The second line contains two integers *t* (2<=≤<=*t*<=≤<=100) — the time when the car moves along the segment in seconds, *d* (0<=≤<=*d*<=≤<=10) — the maximum value of the speed change between adjacent seconds.
It is guaranteed that there is a way to complete the segment so that:
- the speed in the first second equals *v*1, - the speed in the last second equals *v*2, - the absolute value of difference of speeds between any two adjacent seconds doesn't exceed *d*.
Output Specification:
Print the maximum possible length of the path segment in meters.
Demo Input:
['5 6\n4 2\n', '10 10\n10 0\n']
Demo Output:
['26', '100']
Note:
In the first sample the sequence of speeds of Polycarpus' car can look as follows: 5, 7, 8, 6. Thus, the total path is 5 + 7 + 8 + 6 = 26 meters.
In the second sample, as *d* = 0, the car covers the whole segment at constant speed *v* = 10. In *t* = 10 seconds it covers the distance of 100 meters. | ```python
v1, v2 = map(int,input().split())
t,d = map(int,input().split())
if v1 > v2:
p=0
l= v1
for k in range(t):
if k==0:
p+=v1
elif k==t-1:
p+=v2
else:
if l > v2+d:
l-=d
p+=l
print(p)
elif v2 >v1:
p=0
l= v1
for k in range(t):
if k==0:
p+=v1
elif k==t-1:
p+=v2
else:
if l < v2+d:
l+=d
p+=l
else:
print(v1+v2 + (v1+d)*(t-2))
``` | 0 |
|
71 | A | Way Too Long Words | PROGRAMMING | 800 | [
"strings"
] | A. Way Too Long Words | 1 | 256 | Sometimes some words like "localization" or "internationalization" are so long that writing them many times in one text is quite tiresome.
Let's consider a word too long, if its length is strictly more than 10 characters. All too long words should be replaced with a special abbreviation.
This abbreviation is made like this: we write down the first and the last letter of a word and between them we write the number of letters between the first and the last letters. That number is in decimal system and doesn't contain any leading zeroes.
Thus, "localization" will be spelt as "l10n", and "internationalization» will be spelt as "i18n".
You are suggested to automatize the process of changing the words with abbreviations. At that all too long words should be replaced by the abbreviation and the words that are not too long should not undergo any changes. | The first line contains an integer *n* (1<=≤<=*n*<=≤<=100). Each of the following *n* lines contains one word. All the words consist of lowercase Latin letters and possess the lengths of from 1 to 100 characters. | Print *n* lines. The *i*-th line should contain the result of replacing of the *i*-th word from the input data. | [
"4\nword\nlocalization\ninternationalization\npneumonoultramicroscopicsilicovolcanoconiosis\n"
] | [
"word\nl10n\ni18n\np43s\n"
] | none | 500 | [
{
"input": "4\nword\nlocalization\ninternationalization\npneumonoultramicroscopicsilicovolcanoconiosis",
"output": "word\nl10n\ni18n\np43s"
},
{
"input": "5\nabcdefgh\nabcdefghi\nabcdefghij\nabcdefghijk\nabcdefghijklm",
"output": "abcdefgh\nabcdefghi\nabcdefghij\na9k\na11m"
},
{
"input": "3\nnjfngnrurunrgunrunvurn\njfvnjfdnvjdbfvsbdubruvbubvkdb\nksdnvidnviudbvibd",
"output": "n20n\nj27b\nk15d"
},
{
"input": "1\ntcyctkktcctrcyvbyiuhihhhgyvyvyvyvjvytchjckt",
"output": "t41t"
},
{
"input": "24\nyou\nare\nregistered\nfor\npractice\nyou\ncan\nsolve\nproblems\nunofficially\nresults\ncan\nbe\nfound\nin\nthe\ncontest\nstatus\nand\nin\nthe\nbottom\nof\nstandings",
"output": "you\nare\nregistered\nfor\npractice\nyou\ncan\nsolve\nproblems\nu10y\nresults\ncan\nbe\nfound\nin\nthe\ncontest\nstatus\nand\nin\nthe\nbottom\nof\nstandings"
},
{
"input": "1\na",
"output": "a"
},
{
"input": "26\na\nb\nc\nd\ne\nf\ng\nh\ni\nj\nk\nl\nm\nn\no\np\nq\nr\ns\nt\nu\nv\nw\nx\ny\nz",
"output": "a\nb\nc\nd\ne\nf\ng\nh\ni\nj\nk\nl\nm\nn\no\np\nq\nr\ns\nt\nu\nv\nw\nx\ny\nz"
},
{
"input": "1\nabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghij",
"output": "a98j"
},
{
"input": "10\ngyartjdxxlcl\nfzsck\nuidwu\nxbymclornemdmtj\nilppyoapitawgje\ncibzc\ndrgbeu\nhezplmsdekhhbo\nfeuzlrimbqbytdu\nkgdco",
"output": "g10l\nfzsck\nuidwu\nx13j\ni13e\ncibzc\ndrgbeu\nh12o\nf13u\nkgdco"
},
{
"input": "20\nlkpmx\nkovxmxorlgwaomlswjxlpnbvltfv\nhykasjxqyjrmybejnmeumzha\ntuevlumpqbbhbww\nqgqsphvrmupxxc\ntrissbaf\nqfgrlinkzvzqdryckaizutd\nzzqtoaxkvwoscyx\noswytrlnhpjvvnwookx\nlpuzqgec\ngyzqfwxggtvpjhzmzmdw\nrlxjgmvdftvrmvbdwudra\nvsntnjpepnvdaxiporggmglhagv\nxlvcqkqgcrbgtgglj\nlyxwxbiszyhlsrgzeedzprbmcpduvq\nyrmqqvrkqskqukzqrwukpsifgtdc\nxpuohcsjhhuhvr\nvvlfrlxpvqejngwrbfbpmqeirxlw\nsvmasocxdvadmaxtrpakysmeaympy\nyuflqboqfdt",
"output": "lkpmx\nk26v\nh22a\nt13w\nq12c\ntrissbaf\nq21d\nz13x\no17x\nlpuzqgec\ng18w\nr19a\nv25v\nx15j\nl28q\ny26c\nx12r\nv26w\ns27y\ny9t"
},
{
"input": "100\nm\nz\ns\nv\nd\nr\nv\ny\ny\ne\np\nt\nc\na\nn\nm\np\ng\ni\nj\nc\na\nb\nq\ne\nn\nv\no\nk\nx\nf\ni\nl\na\nq\nr\nu\nb\ns\nl\nc\nl\ne\nv\nj\nm\nx\nb\na\nq\nb\na\nf\nj\nv\nm\nq\nc\nt\nt\nn\nx\no\ny\nr\nu\nh\nm\nj\np\nj\nq\nz\ns\nj\no\ng\nc\nm\nn\no\nm\nr\no\ns\nt\nh\nr\np\nk\nb\nz\ng\no\nc\nc\nz\nz\ng\nr",
"output": "m\nz\ns\nv\nd\nr\nv\ny\ny\ne\np\nt\nc\na\nn\nm\np\ng\ni\nj\nc\na\nb\nq\ne\nn\nv\no\nk\nx\nf\ni\nl\na\nq\nr\nu\nb\ns\nl\nc\nl\ne\nv\nj\nm\nx\nb\na\nq\nb\na\nf\nj\nv\nm\nq\nc\nt\nt\nn\nx\no\ny\nr\nu\nh\nm\nj\np\nj\nq\nz\ns\nj\no\ng\nc\nm\nn\no\nm\nr\no\ns\nt\nh\nr\np\nk\nb\nz\ng\no\nc\nc\nz\nz\ng\nr"
}
] | 1,692,485,672 | 2,147,483,647 | Python 3 | OK | TESTS | 20 | 31 | 0 | def way_too_long_words(txt_arr):
res = []
for input_txt in txt_arr:
n = len(input_txt)
if n <= 10:
res.append(input_txt)
else:
res.append(input_txt[0] + str(n-2) + input_txt[-1])
return res
if __name__ == "__main__":
n = int(input())
txt_arr = []
for _ in range(n):
txt_arr.append(input())
res_arr = way_too_long_words(txt_arr)
for res in res_arr:
print(res) | Title: Way Too Long Words
Time Limit: 1 seconds
Memory Limit: 256 megabytes
Problem Description:
Sometimes some words like "localization" or "internationalization" are so long that writing them many times in one text is quite tiresome.
Let's consider a word too long, if its length is strictly more than 10 characters. All too long words should be replaced with a special abbreviation.
This abbreviation is made like this: we write down the first and the last letter of a word and between them we write the number of letters between the first and the last letters. That number is in decimal system and doesn't contain any leading zeroes.
Thus, "localization" will be spelt as "l10n", and "internationalization» will be spelt as "i18n".
You are suggested to automatize the process of changing the words with abbreviations. At that all too long words should be replaced by the abbreviation and the words that are not too long should not undergo any changes.
Input Specification:
The first line contains an integer *n* (1<=≤<=*n*<=≤<=100). Each of the following *n* lines contains one word. All the words consist of lowercase Latin letters and possess the lengths of from 1 to 100 characters.
Output Specification:
Print *n* lines. The *i*-th line should contain the result of replacing of the *i*-th word from the input data.
Demo Input:
['4\nword\nlocalization\ninternationalization\npneumonoultramicroscopicsilicovolcanoconiosis\n']
Demo Output:
['word\nl10n\ni18n\np43s\n']
Note:
none | ```python
def way_too_long_words(txt_arr):
res = []
for input_txt in txt_arr:
n = len(input_txt)
if n <= 10:
res.append(input_txt)
else:
res.append(input_txt[0] + str(n-2) + input_txt[-1])
return res
if __name__ == "__main__":
n = int(input())
txt_arr = []
for _ in range(n):
txt_arr.append(input())
res_arr = way_too_long_words(txt_arr)
for res in res_arr:
print(res)
``` | 3.9845 |
373 | A | Collecting Beats is Fun | PROGRAMMING | 900 | [
"implementation"
] | null | null | Cucumber boy is fan of Kyubeat, a famous music game.
Kyubeat has 16 panels for playing arranged in 4<=×<=4 table. When a panel lights up, he has to press that panel.
Each panel has a timing to press (the preffered time when a player should press it), and Cucumber boy is able to press at most *k* panels in a time with his one hand. Cucumber boy is trying to press all panels in perfect timing, that is he wants to press each panel exactly in its preffered time. If he cannot press the panels with his two hands in perfect timing, his challenge to press all the panels in perfect timing will fail.
You are given one scene of Kyubeat's panel from the music Cucumber boy is trying. Tell him is he able to press all the panels in perfect timing. | The first line contains a single integer *k* (1<=≤<=*k*<=≤<=5) — the number of panels Cucumber boy can press with his one hand.
Next 4 lines contain 4 characters each (digits from 1 to 9, or period) — table of panels. If a digit *i* was written on the panel, it means the boy has to press that panel in time *i*. If period was written on the panel, he doesn't have to press that panel. | Output "YES" (without quotes), if he is able to press all the panels in perfect timing. If not, output "NO" (without quotes). | [
"1\n.135\n1247\n3468\n5789\n",
"5\n..1.\n1111\n..1.\n..1.\n",
"1\n....\n12.1\n.2..\n.2..\n"
] | [
"YES\n",
"YES\n",
"NO\n"
] | In the third sample boy cannot press all panels in perfect timing. He can press all the panels in timing in time 1, but he cannot press the panels in time 2 in timing with his two hands. | 500 | [
{
"input": "1\n.135\n1247\n3468\n5789",
"output": "YES"
},
{
"input": "5\n..1.\n1111\n..1.\n..1.",
"output": "YES"
},
{
"input": "1\n....\n12.1\n.2..\n.2..",
"output": "NO"
},
{
"input": "1\n6981\n.527\n4163\n2345",
"output": "YES"
},
{
"input": "5\n9999\n9999\n9999\n9999",
"output": "NO"
},
{
"input": "2\n4444\n3333\n2222\n1111",
"output": "YES"
},
{
"input": "3\n2123\n1232\n2321\n3213",
"output": "NO"
},
{
"input": "2\n1...\n.1..\n..1.\n...1",
"output": "YES"
},
{
"input": "2\n1.1.\n.1.1\n2.2.\n.222",
"output": "NO"
},
{
"input": "1\n1..2\n.3.4\n567.\n.89.",
"output": "YES"
},
{
"input": "1\n1122\n3344\n5588\n6699",
"output": "YES"
},
{
"input": "4\n1111\n1221\n1221\n1111",
"output": "NO"
},
{
"input": "5\n3141\n5926\n5358\n9793",
"output": "YES"
},
{
"input": "5\n5454\n4343\n3232\n2121",
"output": "YES"
},
{
"input": "5\n1222\n2221\n2221\n1122",
"output": "NO"
},
{
"input": "1\n....\n5..5\n6..6\n7..7",
"output": "YES"
},
{
"input": "1\n9875\n8643\n7421\n531.",
"output": "YES"
},
{
"input": "1\n..1.\n..1.\n..1.\n..1.",
"output": "NO"
},
{
"input": "4\n4.4.\n4.4.\n4444\n..4.",
"output": "NO"
},
{
"input": "5\n4.4.\n4.4.\n4444\n..4.",
"output": "YES"
},
{
"input": "3\n1.1.\n.1.1\n1.1.\n.1.1",
"output": "NO"
},
{
"input": "2\n1131\n4412\n2569\n3478",
"output": "YES"
},
{
"input": "2\n8888\n8888\n8888\n8888",
"output": "NO"
}
] | 1,594,449,452 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 3 | 124 | 7,065,600 | from collections import Counter
k=int(input())
string=""
string+=input()
string+=input()
string+=input()
string+=input()
string=list(string)
string.remove('.')
string=Counter(string)
count=string.most_common(1)
cnt=count[0][1]
if cnt<=2*k:
print("YES")
else:
print("NO") | Title: Collecting Beats is Fun
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Cucumber boy is fan of Kyubeat, a famous music game.
Kyubeat has 16 panels for playing arranged in 4<=×<=4 table. When a panel lights up, he has to press that panel.
Each panel has a timing to press (the preffered time when a player should press it), and Cucumber boy is able to press at most *k* panels in a time with his one hand. Cucumber boy is trying to press all panels in perfect timing, that is he wants to press each panel exactly in its preffered time. If he cannot press the panels with his two hands in perfect timing, his challenge to press all the panels in perfect timing will fail.
You are given one scene of Kyubeat's panel from the music Cucumber boy is trying. Tell him is he able to press all the panels in perfect timing.
Input Specification:
The first line contains a single integer *k* (1<=≤<=*k*<=≤<=5) — the number of panels Cucumber boy can press with his one hand.
Next 4 lines contain 4 characters each (digits from 1 to 9, or period) — table of panels. If a digit *i* was written on the panel, it means the boy has to press that panel in time *i*. If period was written on the panel, he doesn't have to press that panel.
Output Specification:
Output "YES" (without quotes), if he is able to press all the panels in perfect timing. If not, output "NO" (without quotes).
Demo Input:
['1\n.135\n1247\n3468\n5789\n', '5\n..1.\n1111\n..1.\n..1.\n', '1\n....\n12.1\n.2..\n.2..\n']
Demo Output:
['YES\n', 'YES\n', 'NO\n']
Note:
In the third sample boy cannot press all panels in perfect timing. He can press all the panels in timing in time 1, but he cannot press the panels in time 2 in timing with his two hands. | ```python
from collections import Counter
k=int(input())
string=""
string+=input()
string+=input()
string+=input()
string+=input()
string=list(string)
string.remove('.')
string=Counter(string)
count=string.most_common(1)
cnt=count[0][1]
if cnt<=2*k:
print("YES")
else:
print("NO")
``` | 0 |
|
6 | C | Alice, Bob and Chocolate | PROGRAMMING | 1,200 | [
"greedy",
"two pointers"
] | C. Alice, Bob and Chocolate | 2 | 64 | Alice and Bob like games. And now they are ready to start a new game. They have placed *n* chocolate bars in a line. Alice starts to eat chocolate bars one by one from left to right, and Bob — from right to left. For each chocololate bar the time, needed for the player to consume it, is known (Alice and Bob eat them with equal speed). When the player consumes a chocolate bar, he immediately starts with another. It is not allowed to eat two chocolate bars at the same time, to leave the bar unfinished and to make pauses. If both players start to eat the same bar simultaneously, Bob leaves it to Alice as a true gentleman.
How many bars each of the players will consume? | The first line contains one integer *n* (1<=≤<=*n*<=≤<=105) — the amount of bars on the table. The second line contains a sequence *t*1,<=*t*2,<=...,<=*t**n* (1<=≤<=*t**i*<=≤<=1000), where *t**i* is the time (in seconds) needed to consume the *i*-th bar (in the order from left to right). | Print two numbers *a* and *b*, where *a* is the amount of bars consumed by Alice, and *b* is the amount of bars consumed by Bob. | [
"5\n2 9 8 2 7\n"
] | [
"2 3\n"
] | none | 0 | [
{
"input": "5\n2 9 8 2 7",
"output": "2 3"
},
{
"input": "1\n1",
"output": "1 0"
},
{
"input": "2\n1 1",
"output": "1 1"
},
{
"input": "3\n1 1 1",
"output": "2 1"
},
{
"input": "4\n1 1 1 1",
"output": "2 2"
},
{
"input": "1\n6",
"output": "1 0"
},
{
"input": "2\n8 2",
"output": "1 1"
},
{
"input": "3\n6 8 4",
"output": "1 2"
},
{
"input": "4\n4 3 2 8",
"output": "3 1"
},
{
"input": "5\n1 9 8 2 7",
"output": "2 3"
},
{
"input": "6\n1 4 7 3 2 1",
"output": "3 3"
},
{
"input": "11\n7 9 1 8 7 1 7 1 4 8 1",
"output": "4 7"
},
{
"input": "12\n4 2 7 1 9 5 6 2 7 8 5 7",
"output": "7 5"
},
{
"input": "13\n9 9 9 9 9 9 9 9 9 9 9 9 9",
"output": "7 6"
}
] | 1,592,383,999 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 1 | 216 | 307,200 |
# Alice_Bob_and_chocolate
n = int(input());
A = list(map(int , input().split()))
#Alice
i = 0; ai =0;
#Bob
j = len(A)-1; bj =0 ;
#
ki=-1; kj=-1;
while(i<j):
if i == j:
i +=1;
break;
if i!=ki:
ai +=A[i];
if j!=kj:
bj += A[j];
if ai<=bj:
i +=1;
kj = j;
if bj<ai:
j -=1;
ki = i;
print(i,len(A)-j);
| Title: Alice, Bob and Chocolate
Time Limit: 2 seconds
Memory Limit: 64 megabytes
Problem Description:
Alice and Bob like games. And now they are ready to start a new game. They have placed *n* chocolate bars in a line. Alice starts to eat chocolate bars one by one from left to right, and Bob — from right to left. For each chocololate bar the time, needed for the player to consume it, is known (Alice and Bob eat them with equal speed). When the player consumes a chocolate bar, he immediately starts with another. It is not allowed to eat two chocolate bars at the same time, to leave the bar unfinished and to make pauses. If both players start to eat the same bar simultaneously, Bob leaves it to Alice as a true gentleman.
How many bars each of the players will consume?
Input Specification:
The first line contains one integer *n* (1<=≤<=*n*<=≤<=105) — the amount of bars on the table. The second line contains a sequence *t*1,<=*t*2,<=...,<=*t**n* (1<=≤<=*t**i*<=≤<=1000), where *t**i* is the time (in seconds) needed to consume the *i*-th bar (in the order from left to right).
Output Specification:
Print two numbers *a* and *b*, where *a* is the amount of bars consumed by Alice, and *b* is the amount of bars consumed by Bob.
Demo Input:
['5\n2 9 8 2 7\n']
Demo Output:
['2 3\n']
Note:
none | ```python
# Alice_Bob_and_chocolate
n = int(input());
A = list(map(int , input().split()))
#Alice
i = 0; ai =0;
#Bob
j = len(A)-1; bj =0 ;
#
ki=-1; kj=-1;
while(i<j):
if i == j:
i +=1;
break;
if i!=ki:
ai +=A[i];
if j!=kj:
bj += A[j];
if ai<=bj:
i +=1;
kj = j;
if bj<ai:
j -=1;
ki = i;
print(i,len(A)-j);
``` | 0 |
962 | A | Equator | PROGRAMMING | 1,300 | [
"implementation"
] | null | null | Polycarp has created his own training plan to prepare for the programming contests. He will train for $n$ days, all days are numbered from $1$ to $n$, beginning from the first.
On the $i$-th day Polycarp will necessarily solve $a_i$ problems. One evening Polycarp plans to celebrate the equator. He will celebrate it on the first evening of such a day that from the beginning of the training and to this day inclusive he will solve half or more of all the problems.
Determine the index of day when Polycarp will celebrate the equator. | The first line contains a single integer $n$ ($1 \le n \le 200\,000$) — the number of days to prepare for the programming contests.
The second line contains a sequence $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 10\,000$), where $a_i$ equals to the number of problems, which Polycarp will solve on the $i$-th day. | Print the index of the day when Polycarp will celebrate the equator. | [
"4\n1 3 2 1\n",
"6\n2 2 2 2 2 2\n"
] | [
"2\n",
"3\n"
] | In the first example Polycarp will celebrate the equator on the evening of the second day, because up to this day (inclusive) he will solve $4$ out of $7$ scheduled problems on four days of the training.
In the second example Polycarp will celebrate the equator on the evening of the third day, because up to this day (inclusive) he will solve $6$ out of $12$ scheduled problems on six days of the training. | 0 | [
{
"input": "4\n1 3 2 1",
"output": "2"
},
{
"input": "6\n2 2 2 2 2 2",
"output": "3"
},
{
"input": "1\n10000",
"output": "1"
},
{
"input": "3\n2 1 1",
"output": "1"
},
{
"input": "2\n1 3",
"output": "2"
},
{
"input": "4\n2 1 1 3",
"output": "3"
},
{
"input": "3\n1 1 3",
"output": "3"
},
{
"input": "3\n1 1 1",
"output": "2"
},
{
"input": "2\n1 2",
"output": "2"
},
{
"input": "3\n2 1 2",
"output": "2"
},
{
"input": "5\n1 2 4 3 5",
"output": "4"
},
{
"input": "5\n2 2 2 4 3",
"output": "4"
},
{
"input": "4\n1 2 3 1",
"output": "3"
},
{
"input": "6\n7 3 10 7 3 11",
"output": "4"
},
{
"input": "2\n3 4",
"output": "2"
},
{
"input": "5\n1 1 1 1 1",
"output": "3"
},
{
"input": "4\n1 3 2 3",
"output": "3"
},
{
"input": "2\n2 3",
"output": "2"
},
{
"input": "3\n32 10 23",
"output": "2"
},
{
"input": "7\n1 1 1 1 1 1 1",
"output": "4"
},
{
"input": "3\n1 2 4",
"output": "3"
},
{
"input": "6\n3 3 3 2 4 4",
"output": "4"
},
{
"input": "9\n1 1 1 1 1 1 1 1 1",
"output": "5"
},
{
"input": "5\n1 3 3 1 1",
"output": "3"
},
{
"input": "4\n1 1 1 2",
"output": "3"
},
{
"input": "4\n1 2 1 3",
"output": "3"
},
{
"input": "3\n2 2 1",
"output": "2"
},
{
"input": "4\n2 3 3 3",
"output": "3"
},
{
"input": "4\n3 2 3 3",
"output": "3"
},
{
"input": "4\n2 1 1 1",
"output": "2"
},
{
"input": "3\n2 1 4",
"output": "3"
},
{
"input": "2\n6 7",
"output": "2"
},
{
"input": "4\n3 3 4 3",
"output": "3"
},
{
"input": "4\n1 1 2 5",
"output": "4"
},
{
"input": "4\n1 8 7 3",
"output": "3"
},
{
"input": "6\n2 2 2 2 2 3",
"output": "4"
},
{
"input": "3\n2 2 5",
"output": "3"
},
{
"input": "4\n1 1 2 1",
"output": "3"
},
{
"input": "5\n1 1 2 2 3",
"output": "4"
},
{
"input": "5\n9 5 3 4 8",
"output": "3"
},
{
"input": "3\n3 3 1",
"output": "2"
},
{
"input": "4\n1 2 2 2",
"output": "3"
},
{
"input": "3\n1 3 5",
"output": "3"
},
{
"input": "4\n1 1 3 6",
"output": "4"
},
{
"input": "6\n1 2 1 1 1 1",
"output": "3"
},
{
"input": "3\n3 1 3",
"output": "2"
},
{
"input": "5\n3 4 5 1 2",
"output": "3"
},
{
"input": "11\n1 1 1 1 1 1 1 1 1 1 1",
"output": "6"
},
{
"input": "5\n3 1 2 5 2",
"output": "4"
},
{
"input": "4\n1 1 1 4",
"output": "4"
},
{
"input": "4\n2 6 1 10",
"output": "4"
},
{
"input": "4\n2 2 3 2",
"output": "3"
},
{
"input": "4\n4 2 2 1",
"output": "2"
},
{
"input": "6\n1 1 1 1 1 4",
"output": "5"
},
{
"input": "3\n3 2 2",
"output": "2"
},
{
"input": "6\n1 3 5 1 7 4",
"output": "5"
},
{
"input": "5\n1 2 4 8 16",
"output": "5"
},
{
"input": "5\n1 2 4 4 4",
"output": "4"
},
{
"input": "6\n4 2 1 2 3 1",
"output": "3"
},
{
"input": "4\n3 2 1 5",
"output": "3"
},
{
"input": "1\n1",
"output": "1"
},
{
"input": "3\n2 4 7",
"output": "3"
},
{
"input": "5\n1 1 1 1 3",
"output": "4"
},
{
"input": "3\n3 1 5",
"output": "3"
},
{
"input": "4\n1 2 3 7",
"output": "4"
},
{
"input": "3\n1 4 6",
"output": "3"
},
{
"input": "4\n2 1 2 2",
"output": "3"
},
{
"input": "2\n4 5",
"output": "2"
},
{
"input": "5\n1 2 1 2 1",
"output": "3"
},
{
"input": "3\n2 3 6",
"output": "3"
},
{
"input": "6\n1 1 4 1 1 5",
"output": "4"
},
{
"input": "5\n2 2 2 2 1",
"output": "3"
},
{
"input": "2\n5 6",
"output": "2"
},
{
"input": "4\n2 2 1 4",
"output": "3"
},
{
"input": "5\n2 2 3 4 4",
"output": "4"
},
{
"input": "4\n3 1 1 2",
"output": "2"
},
{
"input": "5\n3 4 1 4 5",
"output": "4"
},
{
"input": "4\n1 3 1 6",
"output": "4"
},
{
"input": "5\n1 1 1 2 2",
"output": "4"
},
{
"input": "4\n1 4 2 4",
"output": "3"
},
{
"input": "10\n1 1 1 1 1 1 1 1 1 8",
"output": "9"
},
{
"input": "4\n1 4 5 1",
"output": "3"
},
{
"input": "5\n1 1 1 1 5",
"output": "5"
},
{
"input": "4\n1 3 4 1",
"output": "3"
},
{
"input": "4\n2 2 2 3",
"output": "3"
},
{
"input": "4\n2 3 2 4",
"output": "3"
},
{
"input": "5\n2 2 1 2 2",
"output": "3"
},
{
"input": "3\n4 3 2",
"output": "2"
},
{
"input": "3\n6 5 2",
"output": "2"
},
{
"input": "69\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1",
"output": "35"
},
{
"input": "6\n1 1 1 1 1 2",
"output": "4"
},
{
"input": "5\n1 2 5 4 5",
"output": "4"
},
{
"input": "2\n9 10",
"output": "2"
},
{
"input": "3\n1 1 5",
"output": "3"
},
{
"input": "4\n3 4 3 5",
"output": "3"
},
{
"input": "4\n1 4 3 3",
"output": "3"
},
{
"input": "4\n7 1 3 4",
"output": "2"
},
{
"input": "3\n100 100 1",
"output": "2"
},
{
"input": "4\n5 2 2 2",
"output": "2"
}
] | 1,524,523,715 | 2,147,483,647 | Python 3 | OK | TESTS | 106 | 171 | 20,582,400 |
#k=int(input())
#n,m=map(int,input().split())
import sys
#a=list(map(int,input().split()))
#b=list(map(int,input().split()))
import math
n=int(input())
a=list(map(int,input().split()))
ss=sum(a);
s=0
for i in range(n):
s+=a[i]
if(2*s>=ss):
print(i+1)
sys.exit()
| Title: Equator
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Polycarp has created his own training plan to prepare for the programming contests. He will train for $n$ days, all days are numbered from $1$ to $n$, beginning from the first.
On the $i$-th day Polycarp will necessarily solve $a_i$ problems. One evening Polycarp plans to celebrate the equator. He will celebrate it on the first evening of such a day that from the beginning of the training and to this day inclusive he will solve half or more of all the problems.
Determine the index of day when Polycarp will celebrate the equator.
Input Specification:
The first line contains a single integer $n$ ($1 \le n \le 200\,000$) — the number of days to prepare for the programming contests.
The second line contains a sequence $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 10\,000$), where $a_i$ equals to the number of problems, which Polycarp will solve on the $i$-th day.
Output Specification:
Print the index of the day when Polycarp will celebrate the equator.
Demo Input:
['4\n1 3 2 1\n', '6\n2 2 2 2 2 2\n']
Demo Output:
['2\n', '3\n']
Note:
In the first example Polycarp will celebrate the equator on the evening of the second day, because up to this day (inclusive) he will solve $4$ out of $7$ scheduled problems on four days of the training.
In the second example Polycarp will celebrate the equator on the evening of the third day, because up to this day (inclusive) he will solve $6$ out of $12$ scheduled problems on six days of the training. | ```python
#k=int(input())
#n,m=map(int,input().split())
import sys
#a=list(map(int,input().split()))
#b=list(map(int,input().split()))
import math
n=int(input())
a=list(map(int,input().split()))
ss=sum(a);
s=0
for i in range(n):
s+=a[i]
if(2*s>=ss):
print(i+1)
sys.exit()
``` | 3 |
|
1,003 | D | Coins and Queries | PROGRAMMING | 1,600 | [
"greedy"
] | null | null | Polycarp has $n$ coins, the value of the $i$-th coin is $a_i$. It is guaranteed that all the values are integer powers of $2$ (i.e. $a_i = 2^d$ for some non-negative integer number $d$).
Polycarp wants to know answers on $q$ queries. The $j$-th query is described as integer number $b_j$. The answer to the query is the minimum number of coins that is necessary to obtain the value $b_j$ using some subset of coins (Polycarp can use only coins he has). If Polycarp can't obtain the value $b_j$, the answer to the $j$-th query is -1.
The queries are independent (the answer on the query doesn't affect Polycarp's coins). | The first line of the input contains two integers $n$ and $q$ ($1 \le n, q \le 2 \cdot 10^5$) — the number of coins and the number of queries.
The second line of the input contains $n$ integers $a_1, a_2, \dots, a_n$ — values of coins ($1 \le a_i \le 2 \cdot 10^9$). It is guaranteed that all $a_i$ are integer powers of $2$ (i.e. $a_i = 2^d$ for some non-negative integer number $d$).
The next $q$ lines contain one integer each. The $j$-th line contains one integer $b_j$ — the value of the $j$-th query ($1 \le b_j \le 10^9$). | Print $q$ integers $ans_j$. The $j$-th integer must be equal to the answer on the $j$-th query. If Polycarp can't obtain the value $b_j$ the answer to the $j$-th query is -1. | [
"5 4\n2 4 8 2 4\n8\n5\n14\n10\n"
] | [
"1\n-1\n3\n2\n"
] | none | 0 | [
{
"input": "5 4\n2 4 8 2 4\n8\n5\n14\n10",
"output": "1\n-1\n3\n2"
},
{
"input": "3 3\n1 1 1\n1\n2\n3",
"output": "1\n2\n3"
},
{
"input": "4 1\n2 4 16 32\n14",
"output": "-1"
},
{
"input": "1 10\n8\n1\n2\n3\n4\n5\n6\n7\n8\n9\n16",
"output": "-1\n-1\n-1\n-1\n-1\n-1\n-1\n1\n-1\n-1"
},
{
"input": "1 10\n4\n1\n2\n3\n4\n5\n6\n7\n8\n9\n16",
"output": "-1\n-1\n-1\n1\n-1\n-1\n-1\n-1\n-1\n-1"
},
{
"input": "1 10\n2\n1\n2\n3\n4\n5\n6\n7\n8\n9\n16",
"output": "-1\n1\n-1\n-1\n-1\n-1\n-1\n-1\n-1\n-1"
},
{
"input": "1 10\n1\n1\n2\n3\n4\n5\n6\n7\n8\n9\n16",
"output": "1\n-1\n-1\n-1\n-1\n-1\n-1\n-1\n-1\n-1"
}
] | 1,621,996,883 | 4,943 | PyPy 3 | RUNTIME_ERROR | TESTS | 0 | 124 | 2,150,400 | def main():
n, q = map(int, input().split())
a = [*map(int, input().split())]
d = {}
for i in range(n):
d[a[i]] = d.get(a[i], 0) + 1
for i in range(q):
x = int(input())
c = 0
for j in reversed(d.keys()):
y = min(d[j], x // j)
c += y
x -= y * j
if x:
print(-1)
else:
print(c)
if __name__ == '__main__':
main()
| Title: Coins and Queries
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Polycarp has $n$ coins, the value of the $i$-th coin is $a_i$. It is guaranteed that all the values are integer powers of $2$ (i.e. $a_i = 2^d$ for some non-negative integer number $d$).
Polycarp wants to know answers on $q$ queries. The $j$-th query is described as integer number $b_j$. The answer to the query is the minimum number of coins that is necessary to obtain the value $b_j$ using some subset of coins (Polycarp can use only coins he has). If Polycarp can't obtain the value $b_j$, the answer to the $j$-th query is -1.
The queries are independent (the answer on the query doesn't affect Polycarp's coins).
Input Specification:
The first line of the input contains two integers $n$ and $q$ ($1 \le n, q \le 2 \cdot 10^5$) — the number of coins and the number of queries.
The second line of the input contains $n$ integers $a_1, a_2, \dots, a_n$ — values of coins ($1 \le a_i \le 2 \cdot 10^9$). It is guaranteed that all $a_i$ are integer powers of $2$ (i.e. $a_i = 2^d$ for some non-negative integer number $d$).
The next $q$ lines contain one integer each. The $j$-th line contains one integer $b_j$ — the value of the $j$-th query ($1 \le b_j \le 10^9$).
Output Specification:
Print $q$ integers $ans_j$. The $j$-th integer must be equal to the answer on the $j$-th query. If Polycarp can't obtain the value $b_j$ the answer to the $j$-th query is -1.
Demo Input:
['5 4\n2 4 8 2 4\n8\n5\n14\n10\n']
Demo Output:
['1\n-1\n3\n2\n']
Note:
none | ```python
def main():
n, q = map(int, input().split())
a = [*map(int, input().split())]
d = {}
for i in range(n):
d[a[i]] = d.get(a[i], 0) + 1
for i in range(q):
x = int(input())
c = 0
for j in reversed(d.keys()):
y = min(d[j], x // j)
c += y
x -= y * j
if x:
print(-1)
else:
print(c)
if __name__ == '__main__':
main()
``` | -1 |
|
608 | A | Saitama Destroys Hotel | PROGRAMMING | 1,000 | [
"implementation",
"math"
] | null | null | Saitama accidentally destroyed a hotel again. To repay the hotel company, Genos has volunteered to operate an elevator in one of its other hotels. The elevator is special — it starts on the top floor, can only move down, and has infinite capacity. Floors are numbered from 0 to *s* and elevator initially starts on floor *s* at time 0.
The elevator takes exactly 1 second to move down exactly 1 floor and negligible time to pick up passengers. Genos is given a list detailing when and on which floor passengers arrive. Please determine how long in seconds it will take Genos to bring all passengers to floor 0. | The first line of input contains two integers *n* and *s* (1<=≤<=*n*<=≤<=100, 1<=≤<=*s*<=≤<=1000) — the number of passengers and the number of the top floor respectively.
The next *n* lines each contain two space-separated integers *f**i* and *t**i* (1<=≤<=*f**i*<=≤<=*s*, 1<=≤<=*t**i*<=≤<=1000) — the floor and the time of arrival in seconds for the passenger number *i*. | Print a single integer — the minimum amount of time in seconds needed to bring all the passengers to floor 0. | [
"3 7\n2 1\n3 8\n5 2\n",
"5 10\n2 77\n3 33\n8 21\n9 12\n10 64\n"
] | [
"11\n",
"79\n"
] | In the first sample, it takes at least 11 seconds to bring all passengers to floor 0. Here is how this could be done:
1. Move to floor 5: takes 2 seconds.
2. Pick up passenger 3.
3. Move to floor 3: takes 2 seconds.
4. Wait for passenger 2 to arrive: takes 4 seconds.
5. Pick up passenger 2.
6. Go to floor 2: takes 1 second.
7. Pick up passenger 1.
8. Go to floor 0: takes 2 seconds.
This gives a total of 2 + 2 + 4 + 1 + 2 = 11 seconds. | 500 | [
{
"input": "3 7\n2 1\n3 8\n5 2",
"output": "11"
},
{
"input": "5 10\n2 77\n3 33\n8 21\n9 12\n10 64",
"output": "79"
},
{
"input": "1 1000\n1000 1000",
"output": "2000"
},
{
"input": "1 1\n1 1",
"output": "2"
},
{
"input": "1 1000\n1 1",
"output": "1000"
},
{
"input": "1 1000\n1 1000",
"output": "1001"
},
{
"input": "100 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1",
"output": "2"
},
{
"input": "2 7\n6 3\n1 5",
"output": "9"
},
{
"input": "2 100\n99 2\n1 10",
"output": "101"
},
{
"input": "5 5\n1 1\n2 1\n3 1\n4 1\n5 1",
"output": "6"
},
{
"input": "3 7\n1 6\n5 5\n6 1",
"output": "10"
},
{
"input": "2 100\n4 100\n7 99",
"output": "106"
},
{
"input": "2 10\n9 3\n1 4",
"output": "12"
},
{
"input": "2 5\n4 4\n5 4",
"output": "9"
},
{
"input": "2 10\n9 10\n6 11",
"output": "19"
},
{
"input": "2 100\n99 9\n1 10",
"output": "108"
},
{
"input": "2 7\n3 5\n7 4",
"output": "11"
},
{
"input": "4 4\n4 6\n4 8\n1 7\n2 9",
"output": "12"
},
{
"input": "2 1000\n1 2\n1000 1",
"output": "1001"
},
{
"input": "2 20\n1 1\n2 2",
"output": "20"
},
{
"input": "2 20\n10 10\n19 9",
"output": "28"
}
] | 1,499,750,341 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 4 | 61 | 5,529,600 | string = input()
numbers = string.split()
a, b, floors, times = int(numbers[0]), int(numbers[1]), [], []
for x in range(a):
string = input()
numbers = string.split()
floors.append(int(numbers[0]))
times.append(int(numbers[1]))
floors, times = floors[::-1], times[::-1]
n = 0
for x in range(a):
n += a - floors[x]
a = floors[x]
if times[x] > n:
n = times[x]
n += a
print(n) | Title: Saitama Destroys Hotel
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Saitama accidentally destroyed a hotel again. To repay the hotel company, Genos has volunteered to operate an elevator in one of its other hotels. The elevator is special — it starts on the top floor, can only move down, and has infinite capacity. Floors are numbered from 0 to *s* and elevator initially starts on floor *s* at time 0.
The elevator takes exactly 1 second to move down exactly 1 floor and negligible time to pick up passengers. Genos is given a list detailing when and on which floor passengers arrive. Please determine how long in seconds it will take Genos to bring all passengers to floor 0.
Input Specification:
The first line of input contains two integers *n* and *s* (1<=≤<=*n*<=≤<=100, 1<=≤<=*s*<=≤<=1000) — the number of passengers and the number of the top floor respectively.
The next *n* lines each contain two space-separated integers *f**i* and *t**i* (1<=≤<=*f**i*<=≤<=*s*, 1<=≤<=*t**i*<=≤<=1000) — the floor and the time of arrival in seconds for the passenger number *i*.
Output Specification:
Print a single integer — the minimum amount of time in seconds needed to bring all the passengers to floor 0.
Demo Input:
['3 7\n2 1\n3 8\n5 2\n', '5 10\n2 77\n3 33\n8 21\n9 12\n10 64\n']
Demo Output:
['11\n', '79\n']
Note:
In the first sample, it takes at least 11 seconds to bring all passengers to floor 0. Here is how this could be done:
1. Move to floor 5: takes 2 seconds.
2. Pick up passenger 3.
3. Move to floor 3: takes 2 seconds.
4. Wait for passenger 2 to arrive: takes 4 seconds.
5. Pick up passenger 2.
6. Go to floor 2: takes 1 second.
7. Pick up passenger 1.
8. Go to floor 0: takes 2 seconds.
This gives a total of 2 + 2 + 4 + 1 + 2 = 11 seconds. | ```python
string = input()
numbers = string.split()
a, b, floors, times = int(numbers[0]), int(numbers[1]), [], []
for x in range(a):
string = input()
numbers = string.split()
floors.append(int(numbers[0]))
times.append(int(numbers[1]))
floors, times = floors[::-1], times[::-1]
n = 0
for x in range(a):
n += a - floors[x]
a = floors[x]
if times[x] > n:
n = times[x]
n += a
print(n)
``` | 0 |
|
937 | B | Vile Grasshoppers | PROGRAMMING | 1,400 | [
"brute force",
"math",
"number theory"
] | null | null | The weather is fine today and hence it's high time to climb the nearby pine and enjoy the landscape.
The pine's trunk includes several branches, located one above another and numbered from 2 to *y*. Some of them (more precise, from 2 to *p*) are occupied by tiny vile grasshoppers which you're at war with. These grasshoppers are known for their awesome jumping skills: the grasshopper at branch *x* can jump to branches .
Keeping this in mind, you wisely decided to choose such a branch that none of the grasshoppers could interrupt you. At the same time you wanna settle as high as possible since the view from up there is simply breathtaking.
In other words, your goal is to find the highest branch that cannot be reached by any of the grasshoppers or report that it's impossible. | The only line contains two integers *p* and *y* (2<=≤<=*p*<=≤<=*y*<=≤<=109). | Output the number of the highest suitable branch. If there are none, print -1 instead. | [
"3 6\n",
"3 4\n"
] | [
"5\n",
"-1\n"
] | In the first sample case grasshopper from branch 2 reaches branches 2, 4 and 6 while branch 3 is initially settled by another grasshopper. Therefore the answer is 5.
It immediately follows that there are no valid branches in second sample case. | 1,000 | [
{
"input": "3 6",
"output": "5"
},
{
"input": "3 4",
"output": "-1"
},
{
"input": "2 2",
"output": "-1"
},
{
"input": "5 50",
"output": "49"
},
{
"input": "944192806 944193066",
"output": "944192807"
},
{
"input": "1000000000 1000000000",
"output": "-1"
},
{
"input": "2 1000000000",
"output": "999999999"
},
{
"input": "28788 944193066",
"output": "944192833"
},
{
"input": "49 52",
"output": "-1"
},
{
"input": "698964997 734575900",
"output": "734575871"
},
{
"input": "287894773 723316271",
"output": "723316207"
},
{
"input": "171837140 733094070",
"output": "733094069"
},
{
"input": "37839169 350746807",
"output": "350746727"
},
{
"input": "125764821 234689174",
"output": "234689137"
},
{
"input": "413598841 430509920",
"output": "430509917"
},
{
"input": "145320418 592508508",
"output": "592508479"
},
{
"input": "155098216 476450875",
"output": "476450861"
},
{
"input": "459843315 950327842",
"output": "950327831"
},
{
"input": "469621113 834270209",
"output": "834270209"
},
{
"input": "13179877 557546766",
"output": "557546753"
},
{
"input": "541748242 723508350",
"output": "723508301"
},
{
"input": "607450717 924641194",
"output": "924641189"
},
{
"input": "786360384 934418993",
"output": "934418981"
},
{
"input": "649229491 965270051",
"output": "965270051"
},
{
"input": "144179719 953974590",
"output": "953974583"
},
{
"input": "28122086 963752388",
"output": "963752347"
},
{
"input": "268497487 501999053",
"output": "501999053"
},
{
"input": "356423140 385941420",
"output": "385941419"
},
{
"input": "71233638 269883787",
"output": "269883787"
},
{
"input": "2601 698964997",
"output": "698964983"
},
{
"input": "4096 287894773",
"output": "287894771"
},
{
"input": "5675 171837140",
"output": "171837131"
},
{
"input": "13067 350746807",
"output": "350746727"
},
{
"input": "8699 234689174",
"output": "234689137"
},
{
"input": "12190 413598841",
"output": "413598817"
},
{
"input": "20555 592508508",
"output": "592508479"
},
{
"input": "19137 476450875",
"output": "476450861"
},
{
"input": "8793 950327842",
"output": "950327831"
},
{
"input": "1541 834270209",
"output": "834270209"
},
{
"input": "1082 13179877",
"output": "13179871"
},
{
"input": "3888 723508350",
"output": "723508301"
},
{
"input": "14078 607450717",
"output": "607450703"
},
{
"input": "20869 786360384",
"output": "786360373"
},
{
"input": "13689 965270051",
"output": "965270051"
},
{
"input": "782 144179719",
"output": "144179719"
},
{
"input": "404 28122086",
"output": "28122079"
},
{
"input": "21992 501999053",
"output": "501999053"
},
{
"input": "13745 385941420",
"output": "385941419"
},
{
"input": "8711 269883787",
"output": "269883787"
},
{
"input": "31333 981756889",
"output": "981756871"
},
{
"input": "944192808 944193061",
"output": "-1"
},
{
"input": "3 9",
"output": "7"
},
{
"input": "4 5",
"output": "5"
},
{
"input": "2 13",
"output": "13"
},
{
"input": "7 53",
"output": "53"
},
{
"input": "10 1000000000",
"output": "999999997"
},
{
"input": "2 7",
"output": "7"
},
{
"input": "4 9",
"output": "7"
}
] | 1,532,078,694 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 4 | 124 | 0 | p, y = (int(x) for x in input().split())
a = [1] * y
for i in range(2,p + 1):
j = 2
while True:
if j * i > y - 1:
break
else:
a[j*i] = 0
j += 1
a.pop(0)
a.pop(0)
flag = 0 in a
if flag:
a.reverse()
index = a.index(0)
a.reverse()
print(y - index)
else:
print(-1)
| Title: Vile Grasshoppers
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The weather is fine today and hence it's high time to climb the nearby pine and enjoy the landscape.
The pine's trunk includes several branches, located one above another and numbered from 2 to *y*. Some of them (more precise, from 2 to *p*) are occupied by tiny vile grasshoppers which you're at war with. These grasshoppers are known for their awesome jumping skills: the grasshopper at branch *x* can jump to branches .
Keeping this in mind, you wisely decided to choose such a branch that none of the grasshoppers could interrupt you. At the same time you wanna settle as high as possible since the view from up there is simply breathtaking.
In other words, your goal is to find the highest branch that cannot be reached by any of the grasshoppers or report that it's impossible.
Input Specification:
The only line contains two integers *p* and *y* (2<=≤<=*p*<=≤<=*y*<=≤<=109).
Output Specification:
Output the number of the highest suitable branch. If there are none, print -1 instead.
Demo Input:
['3 6\n', '3 4\n']
Demo Output:
['5\n', '-1\n']
Note:
In the first sample case grasshopper from branch 2 reaches branches 2, 4 and 6 while branch 3 is initially settled by another grasshopper. Therefore the answer is 5.
It immediately follows that there are no valid branches in second sample case. | ```python
p, y = (int(x) for x in input().split())
a = [1] * y
for i in range(2,p + 1):
j = 2
while True:
if j * i > y - 1:
break
else:
a[j*i] = 0
j += 1
a.pop(0)
a.pop(0)
flag = 0 in a
if flag:
a.reverse()
index = a.index(0)
a.reverse()
print(y - index)
else:
print(-1)
``` | -1 |
|
796 | A | Buying A House | PROGRAMMING | 800 | [
"brute force",
"implementation"
] | null | null | Zane the wizard had never loved anyone before, until he fell in love with a girl, whose name remains unknown to us.
The girl lives in house *m* of a village. There are *n* houses in that village, lining in a straight line from left to right: house 1, house 2, ..., house *n*. The village is also well-structured: house *i* and house *i*<=+<=1 (1<=≤<=*i*<=<<=*n*) are exactly 10 meters away. In this village, some houses are occupied, and some are not. Indeed, unoccupied houses can be purchased.
You will be given *n* integers *a*1,<=*a*2,<=...,<=*a**n* that denote the availability and the prices of the houses. If house *i* is occupied, and therefore cannot be bought, then *a**i* equals 0. Otherwise, house *i* can be bought, and *a**i* represents the money required to buy it, in dollars.
As Zane has only *k* dollars to spare, it becomes a challenge for him to choose the house to purchase, so that he could live as near as possible to his crush. Help Zane determine the minimum distance from his crush's house to some house he can afford, to help him succeed in his love. | The first line contains three integers *n*, *m*, and *k* (2<=≤<=*n*<=≤<=100, 1<=≤<=*m*<=≤<=*n*, 1<=≤<=*k*<=≤<=100) — the number of houses in the village, the house where the girl lives, and the amount of money Zane has (in dollars), respectively.
The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (0<=≤<=*a**i*<=≤<=100) — denoting the availability and the prices of the houses.
It is guaranteed that *a**m*<==<=0 and that it is possible to purchase some house with no more than *k* dollars. | Print one integer — the minimum distance, in meters, from the house where the girl Zane likes lives to the house Zane can buy. | [
"5 1 20\n0 27 32 21 19\n",
"7 3 50\n62 0 0 0 99 33 22\n",
"10 5 100\n1 0 1 0 0 0 0 0 1 1\n"
] | [
"40",
"30",
"20"
] | In the first sample, with *k* = 20 dollars, Zane can buy only house 5. The distance from house *m* = 1 to house 5 is 10 + 10 + 10 + 10 = 40 meters.
In the second sample, Zane can buy houses 6 and 7. It is better to buy house 6 than house 7, since house *m* = 3 and house 6 are only 30 meters away, while house *m* = 3 and house 7 are 40 meters away. | 500 | [
{
"input": "5 1 20\n0 27 32 21 19",
"output": "40"
},
{
"input": "7 3 50\n62 0 0 0 99 33 22",
"output": "30"
},
{
"input": "10 5 100\n1 0 1 0 0 0 0 0 1 1",
"output": "20"
},
{
"input": "5 3 1\n1 1 0 0 1",
"output": "10"
},
{
"input": "5 5 5\n1 0 5 6 0",
"output": "20"
},
{
"input": "15 10 50\n20 0 49 50 50 50 50 50 50 0 50 50 49 0 20",
"output": "10"
},
{
"input": "7 5 1\n0 100 2 2 0 2 1",
"output": "20"
},
{
"input": "100 50 100\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 0 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100",
"output": "10"
},
{
"input": "100 50 1\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 0 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100",
"output": "490"
},
{
"input": "100 77 50\n50 100 49 51 0 50 100 49 51 0 50 100 49 51 0 50 100 49 51 0 50 100 49 51 0 50 100 49 51 0 50 100 49 51 0 50 100 49 51 0 50 100 49 51 0 50 100 49 51 0 50 100 49 51 0 50 100 49 51 0 50 100 49 51 0 50 100 49 51 0 50 100 49 51 0 50 0 49 51 0 50 100 49 51 0 50 100 49 51 0 50 100 49 51 0 50 100 49 51 0",
"output": "10"
},
{
"input": "100 1 1\n0 98 97 96 95 94 93 92 91 90 89 88 87 86 85 84 83 82 81 80 79 78 77 76 75 74 73 72 71 70 69 68 67 66 65 64 63 62 61 60 59 58 57 56 55 54 53 52 51 50 49 48 47 46 45 44 43 42 41 40 39 38 37 36 35 34 33 32 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0",
"output": "980"
},
{
"input": "100 1 100\n0 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100",
"output": "10"
},
{
"input": "100 10 99\n0 0 0 0 0 0 0 0 0 0 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 99 98",
"output": "890"
},
{
"input": "7 4 5\n1 0 6 0 5 6 0",
"output": "10"
},
{
"input": "7 4 5\n1 6 5 0 0 6 0",
"output": "10"
},
{
"input": "100 42 59\n50 50 50 50 50 50 50 50 50 50 59 59 59 59 59 59 59 59 59 59 59 59 59 59 59 59 59 59 59 59 59 59 59 60 60 60 60 60 60 60 60 0 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 0",
"output": "90"
},
{
"input": "2 1 100\n0 1",
"output": "10"
},
{
"input": "2 2 100\n1 0",
"output": "10"
},
{
"input": "10 1 88\n0 95 0 0 0 0 0 94 0 85",
"output": "90"
},
{
"input": "10 2 14\n2 0 1 26 77 39 41 100 13 32",
"output": "10"
},
{
"input": "10 3 11\n0 0 0 0 0 62 0 52 1 35",
"output": "60"
},
{
"input": "20 12 44\n27 40 58 69 53 38 31 39 75 95 8 0 28 81 77 90 38 61 21 88",
"output": "10"
},
{
"input": "30 29 10\n59 79 34 12 100 6 1 58 18 73 54 11 37 46 89 90 80 85 73 45 64 5 31 0 89 19 0 74 0 82",
"output": "70"
},
{
"input": "40 22 1\n7 95 44 53 0 0 19 93 0 68 65 0 24 91 10 58 17 0 71 0 100 0 94 90 79 73 0 73 4 61 54 81 7 13 21 84 5 41 0 1",
"output": "180"
},
{
"input": "40 22 99\n60 0 100 0 0 100 100 0 0 0 0 100 100 0 0 100 100 0 100 100 100 0 100 100 100 0 100 100 0 0 100 100 100 0 0 100 0 100 0 0",
"output": "210"
},
{
"input": "50 10 82\n56 54 0 0 0 0 88 93 0 0 83 93 0 0 91 89 0 30 62 52 24 84 80 8 38 13 92 78 16 87 23 30 71 55 16 63 15 99 4 93 24 6 3 35 4 42 73 27 86 37",
"output": "80"
},
{
"input": "63 49 22\n18 3 97 52 75 2 12 24 58 75 80 97 22 10 79 51 30 60 68 99 75 2 35 3 97 88 9 7 18 5 0 0 0 91 0 91 56 36 76 0 0 0 52 27 35 0 51 72 0 96 57 0 0 0 0 92 55 28 0 30 0 78 77",
"output": "190"
},
{
"input": "74 38 51\n53 36 55 42 64 5 87 9 0 16 86 78 9 22 19 1 25 72 1 0 0 0 79 0 0 0 77 58 70 0 0 100 64 0 99 59 0 0 0 0 65 74 0 96 0 58 89 93 61 88 0 0 82 89 0 0 49 24 7 77 89 87 94 61 100 31 93 70 39 49 39 14 20 84",
"output": "190"
},
{
"input": "89 22 11\n36 0 68 89 0 85 72 0 38 56 0 44 0 94 0 28 71 0 0 18 0 0 0 89 0 0 0 75 0 0 0 32 66 0 0 0 0 0 0 48 63 0 64 58 0 23 48 0 0 52 93 61 57 0 18 0 0 34 62 17 0 41 0 0 53 59 44 0 0 51 40 0 0 100 100 54 0 88 0 5 45 56 57 67 24 16 88 86 15",
"output": "580"
},
{
"input": "97 44 100\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 51 19",
"output": "520"
},
{
"input": "100 1 1\n0 0 0 0 10 54 84 6 17 94 65 82 34 0 61 46 42 0 2 16 56 0 100 0 82 0 0 0 89 78 96 56 0 0 0 0 0 0 0 0 77 70 0 96 67 0 0 32 44 1 72 50 14 11 24 61 100 64 19 5 67 69 44 82 93 22 67 93 22 61 53 64 79 41 84 48 43 97 7 24 8 49 23 16 72 52 97 29 69 47 29 49 64 91 4 73 17 18 51 67",
"output": "490"
},
{
"input": "100 1 50\n0 0 0 60 0 0 54 0 80 0 0 0 97 0 68 97 84 0 0 93 0 0 0 0 68 0 0 62 0 0 55 68 65 87 0 69 0 0 0 0 0 52 61 100 0 71 0 82 88 78 0 81 0 95 0 57 0 67 0 0 0 55 86 0 60 72 0 0 73 0 83 0 0 60 64 0 56 0 0 77 84 0 58 63 84 0 0 67 0 16 3 88 0 98 31 52 40 35 85 23",
"output": "890"
},
{
"input": "100 1 100\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 91 70 14",
"output": "970"
},
{
"input": "100 1 29\n0 0 0 0 64 0 89 97 0 0 0 59 0 67 62 0 59 0 0 80 0 0 0 0 0 97 0 57 0 64 32 0 44 0 0 48 0 47 38 0 42 0 0 0 0 0 0 46 74 0 86 33 33 0 44 0 79 0 0 0 0 91 59 0 59 65 55 0 0 58 33 95 0 97 76 0 81 0 41 0 38 81 80 0 85 0 31 0 0 92 0 0 45 96 0 85 91 87 0 10",
"output": "990"
},
{
"input": "100 50 20\n3 0 32 0 48 32 64 0 54 26 0 0 0 0 0 28 0 0 54 0 0 45 49 0 38 74 0 0 39 42 62 48 75 96 89 42 0 44 0 0 30 21 76 0 50 0 79 0 0 0 0 99 0 84 62 0 0 0 0 53 80 0 28 0 0 53 0 0 38 0 62 0 0 62 0 0 88 0 44 32 0 81 35 45 49 0 69 73 38 27 72 0 96 72 69 0 0 22 76 10",
"output": "490"
},
{
"input": "100 50 20\n49 0 56 0 87 25 40 0 50 0 0 97 0 0 36 29 0 0 0 0 0 73 29 71 44 0 0 0 91 92 69 0 0 60 81 49 48 38 0 87 0 82 0 32 0 82 46 39 0 0 29 0 0 29 0 79 47 0 0 0 0 0 49 0 24 33 70 0 63 45 97 90 0 0 29 53 55 0 84 0 0 100 26 0 88 0 0 0 0 81 70 0 30 80 0 75 59 98 0 2",
"output": "500"
},
{
"input": "100 2 2\n0 0 43 90 47 5 2 97 52 69 21 48 64 10 34 97 97 74 8 19 68 56 55 24 47 38 43 73 72 72 60 60 51 36 33 44 100 45 13 54 72 52 0 15 3 6 50 8 88 4 78 26 40 27 30 63 67 83 61 91 33 97 54 20 92 27 89 35 10 7 84 50 11 95 74 88 24 44 74 100 18 56 34 91 41 34 51 51 11 91 89 54 19 100 83 89 10 17 76 20",
"output": "50"
},
{
"input": "100 100 34\n5 73 0 0 44 0 0 0 79 55 0 0 0 0 0 0 0 0 83 67 75 0 0 0 0 59 0 74 0 0 47 98 0 0 72 41 0 55 87 0 0 78 84 0 0 39 0 79 72 95 0 0 0 0 0 85 53 84 0 0 0 0 37 75 0 66 0 0 0 0 61 0 70 0 37 60 42 78 92 52 0 0 0 55 77 57 0 63 37 0 0 0 96 70 0 94 97 0 0 0",
"output": "990"
},
{
"input": "100 100 100\n43 79 21 87 84 14 28 69 92 16 3 71 79 37 48 37 72 58 12 72 62 49 37 17 60 54 41 99 15 72 40 89 76 1 99 87 14 56 63 48 69 37 96 64 7 14 1 73 85 33 98 70 97 71 96 28 49 71 56 2 67 22 100 2 98 100 62 77 92 76 98 98 47 26 22 47 50 56 9 16 72 47 5 62 29 78 81 1 0 63 32 65 87 3 40 53 8 80 93 0",
"output": "10"
},
{
"input": "100 38 1\n3 59 12 81 33 95 0 41 36 17 63 76 42 77 85 56 3 96 55 41 24 87 18 9 0 37 0 61 69 0 0 0 67 0 0 0 0 0 0 18 0 0 47 56 74 0 0 80 0 42 0 1 60 59 62 9 19 87 92 48 58 30 98 51 99 10 42 94 51 53 50 89 24 5 52 82 50 39 98 8 95 4 57 21 10 0 44 32 19 14 64 34 79 76 17 3 15 22 71 51",
"output": "140"
},
{
"input": "100 72 1\n56 98 8 27 9 23 16 76 56 1 34 43 96 73 75 49 62 20 18 23 51 55 30 84 4 20 89 40 75 16 69 35 1 0 16 0 80 0 41 17 0 0 76 23 0 92 0 34 0 91 82 54 0 0 0 63 85 59 98 24 29 0 8 77 26 0 34 95 39 0 0 0 74 0 0 0 0 12 0 92 0 0 55 95 66 30 0 0 29 98 0 0 0 47 0 0 80 0 0 4",
"output": "390"
},
{
"input": "100 66 1\n38 50 64 91 37 44 74 21 14 41 80 90 26 51 78 85 80 86 44 14 49 75 93 48 78 89 23 72 35 22 14 48 100 71 62 22 7 95 80 66 32 20 17 47 79 30 41 52 15 62 67 71 1 6 0 9 0 0 0 11 0 0 24 0 31 0 77 0 51 0 0 0 0 0 0 77 0 36 44 19 90 45 6 25 100 87 93 30 4 97 36 88 33 50 26 71 97 71 51 68",
"output": "130"
},
{
"input": "100 55 1\n0 33 45 83 56 96 58 24 45 30 38 60 39 69 21 87 59 21 72 73 27 46 61 61 11 97 77 5 39 3 3 35 76 37 53 84 24 75 9 48 31 90 100 84 74 81 83 83 42 23 29 94 18 1 0 53 52 99 86 37 94 54 28 75 28 80 17 14 98 68 76 20 32 23 42 31 57 79 60 14 18 27 1 98 32 3 96 25 15 38 2 6 3 28 59 54 63 2 43 59",
"output": "10"
},
{
"input": "100 55 1\n24 52 41 6 55 11 58 25 63 12 70 39 23 28 72 17 96 85 7 84 21 13 34 37 97 43 36 32 15 30 58 5 14 71 40 70 9 92 44 73 31 58 96 90 19 35 29 91 25 36 48 95 61 78 0 1 99 61 81 88 42 53 61 57 42 55 74 45 41 92 99 30 20 25 89 50 37 4 17 24 6 65 15 44 40 2 38 43 7 90 38 59 75 87 96 28 12 67 24 32",
"output": "10"
},
{
"input": "100 21 1\n62 5 97 80 81 28 83 0 26 0 0 0 0 23 0 0 90 0 0 0 0 0 0 0 0 54 71 8 0 0 42 0 73 0 17 0 1 31 71 78 58 72 84 39 54 59 13 29 16 41 71 35 88 55 70 50 33 100 100 60 52 90 7 66 44 55 51 42 90 17 86 44 46 8 52 74 8 22 2 92 34 37 58 98 70 74 19 91 74 25 4 38 71 68 50 68 63 14 60 98",
"output": "160"
},
{
"input": "5 2 20\n27 0 32 21 19",
"output": "30"
},
{
"input": "6 4 10\n10 0 0 0 0 10",
"output": "20"
},
{
"input": "8 7 100\n1 0 0 0 0 0 0 1",
"output": "10"
},
{
"input": "5 3 20\n1 21 0 0 1",
"output": "20"
},
{
"input": "4 3 1\n0 0 0 1",
"output": "10"
},
{
"input": "5 2 3\n4 0 5 6 1",
"output": "30"
},
{
"input": "5 3 87\n88 89 0 1 90",
"output": "10"
},
{
"input": "5 3 20\n15 30 0 15 35",
"output": "10"
},
{
"input": "6 3 50\n0 0 0 1 2 0",
"output": "10"
},
{
"input": "6 4 9\n100 9 10 0 0 9",
"output": "20"
},
{
"input": "5 4 20\n0 20 0 0 20",
"output": "10"
},
{
"input": "6 3 3\n1 5 0 2 2 0",
"output": "10"
},
{
"input": "5 4 100\n0 1 0 0 1",
"output": "10"
}
] | 1,559,807,370 | 2,147,483,647 | Python 3 | OK | TESTS | 58 | 109 | 0 | n,m,k=map(int,input().split())
m-=1
l=[int(x) for x in input().split()]
q=[]
for i in range(n):
if l[i]!=0 and l[i]<=k:
q.append((abs(i-m))*10)
print(min(q))
| Title: Buying A House
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Zane the wizard had never loved anyone before, until he fell in love with a girl, whose name remains unknown to us.
The girl lives in house *m* of a village. There are *n* houses in that village, lining in a straight line from left to right: house 1, house 2, ..., house *n*. The village is also well-structured: house *i* and house *i*<=+<=1 (1<=≤<=*i*<=<<=*n*) are exactly 10 meters away. In this village, some houses are occupied, and some are not. Indeed, unoccupied houses can be purchased.
You will be given *n* integers *a*1,<=*a*2,<=...,<=*a**n* that denote the availability and the prices of the houses. If house *i* is occupied, and therefore cannot be bought, then *a**i* equals 0. Otherwise, house *i* can be bought, and *a**i* represents the money required to buy it, in dollars.
As Zane has only *k* dollars to spare, it becomes a challenge for him to choose the house to purchase, so that he could live as near as possible to his crush. Help Zane determine the minimum distance from his crush's house to some house he can afford, to help him succeed in his love.
Input Specification:
The first line contains three integers *n*, *m*, and *k* (2<=≤<=*n*<=≤<=100, 1<=≤<=*m*<=≤<=*n*, 1<=≤<=*k*<=≤<=100) — the number of houses in the village, the house where the girl lives, and the amount of money Zane has (in dollars), respectively.
The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (0<=≤<=*a**i*<=≤<=100) — denoting the availability and the prices of the houses.
It is guaranteed that *a**m*<==<=0 and that it is possible to purchase some house with no more than *k* dollars.
Output Specification:
Print one integer — the minimum distance, in meters, from the house where the girl Zane likes lives to the house Zane can buy.
Demo Input:
['5 1 20\n0 27 32 21 19\n', '7 3 50\n62 0 0 0 99 33 22\n', '10 5 100\n1 0 1 0 0 0 0 0 1 1\n']
Demo Output:
['40', '30', '20']
Note:
In the first sample, with *k* = 20 dollars, Zane can buy only house 5. The distance from house *m* = 1 to house 5 is 10 + 10 + 10 + 10 = 40 meters.
In the second sample, Zane can buy houses 6 and 7. It is better to buy house 6 than house 7, since house *m* = 3 and house 6 are only 30 meters away, while house *m* = 3 and house 7 are 40 meters away. | ```python
n,m,k=map(int,input().split())
m-=1
l=[int(x) for x in input().split()]
q=[]
for i in range(n):
if l[i]!=0 and l[i]<=k:
q.append((abs(i-m))*10)
print(min(q))
``` | 3 |
|
299 | A | Ksusha and Array | PROGRAMMING | 1,000 | [
"brute force",
"number theory",
"sortings"
] | null | null | Ksusha is a beginner coder. Today she starts studying arrays. She has array *a*1,<=*a*2,<=...,<=*a**n*, consisting of *n* positive integers.
Her university teacher gave her a task. Find such number in the array, that all array elements are divisible by it. Help her and find the number! | The first line contains integer *n* (1<=≤<=*n*<=≤<=105), showing how many numbers the array has. The next line contains integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=109) — the array elements. | Print a single integer — the number from the array, such that all array elements are divisible by it. If such number doesn't exist, print -1.
If there are multiple answers, you are allowed to print any of them. | [
"3\n2 2 4\n",
"5\n2 1 3 1 6\n",
"3\n2 3 5\n"
] | [
"2\n",
"1\n",
"-1\n"
] | none | 500 | [
{
"input": "3\n2 2 4",
"output": "2"
},
{
"input": "5\n2 1 3 1 6",
"output": "1"
},
{
"input": "3\n2 3 5",
"output": "-1"
},
{
"input": "1\n331358794",
"output": "331358794"
},
{
"input": "5\n506904227 214303304 136194869 838256937 183952885",
"output": "-1"
},
{
"input": "2\n500000000 1000000000",
"output": "500000000"
},
{
"input": "2\n4 6",
"output": "-1"
},
{
"input": "5\n10 8 6 4 2",
"output": "2"
},
{
"input": "2\n6 10",
"output": "-1"
},
{
"input": "1\n1000000000",
"output": "1000000000"
},
{
"input": "2\n6 8",
"output": "-1"
},
{
"input": "5\n2 2 2 2 1000000000",
"output": "2"
},
{
"input": "2\n6 4",
"output": "-1"
}
] | 1,555,231,972 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 8 | 248 | 7,475,200 | n = input()
li = input().split()
m = int(min(li))
for item in li:
if int(item) % m != 0:
m=-1
break;
print (m) | Title: Ksusha and Array
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Ksusha is a beginner coder. Today she starts studying arrays. She has array *a*1,<=*a*2,<=...,<=*a**n*, consisting of *n* positive integers.
Her university teacher gave her a task. Find such number in the array, that all array elements are divisible by it. Help her and find the number!
Input Specification:
The first line contains integer *n* (1<=≤<=*n*<=≤<=105), showing how many numbers the array has. The next line contains integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=109) — the array elements.
Output Specification:
Print a single integer — the number from the array, such that all array elements are divisible by it. If such number doesn't exist, print -1.
If there are multiple answers, you are allowed to print any of them.
Demo Input:
['3\n2 2 4\n', '5\n2 1 3 1 6\n', '3\n2 3 5\n']
Demo Output:
['2\n', '1\n', '-1\n']
Note:
none | ```python
n = input()
li = input().split()
m = int(min(li))
for item in li:
if int(item) % m != 0:
m=-1
break;
print (m)
``` | 0 |
|
26 | B | Regular Bracket Sequence | PROGRAMMING | 1,400 | [
"greedy"
] | B. Regular Bracket Sequence | 5 | 256 | A bracket sequence is called regular if it is possible to obtain correct arithmetic expression by inserting characters «+» and «1» into this sequence. For example, sequences «(())()», «()» and «(()(()))» are regular, while «)(», «(()» and «(()))(» are not.
One day Johnny got bracket sequence. He decided to remove some of the brackets from it in order to obtain a regular bracket sequence. What is the maximum length of a regular bracket sequence which can be obtained? | Input consists of a single line with non-empty string of «(» and «)» characters. Its length does not exceed 106. | Output the maximum possible length of a regular bracket sequence. | [
"(()))(\n",
"((()())\n"
] | [
"4\n",
"6\n"
] | none | 1,000 | [
{
"input": "(()))(",
"output": "4"
},
{
"input": "((()())",
"output": "6"
},
{
"input": "(",
"output": "0"
},
{
"input": ")",
"output": "0"
},
{
"input": ")(()(",
"output": "2"
},
{
"input": "))))))(",
"output": "0"
},
{
"input": "()()(()(((",
"output": "6"
},
{
"input": "()))(()((((()(())",
"output": "10"
},
{
"input": "())))((()())())))))())",
"output": "14"
},
{
"input": ")))((((())(()((()((((()()())((",
"output": "16"
},
{
"input": "))()()((()()))())()(((((((())((((((((())()()((())(",
"output": "32"
},
{
"input": "))())))))))())))))()()))()()))))())))))()))))))))))))(()))())(()))))(()))))())))((((()()))))()))()))",
"output": "48"
}
] | 1,679,855,489 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 4 | 92 | 0 | s = str(input())
l = []
lo = []
for i in s:
l.append(i)
if l[-1] == "(":
l.pop()
for i in l:
if i == "(":
lo.append(i)
c = 0
for i in l:
if i == ")" and len(lo) > 0:
c+=2
lo.pop()
print(c)
| Title: Regular Bracket Sequence
Time Limit: 5 seconds
Memory Limit: 256 megabytes
Problem Description:
A bracket sequence is called regular if it is possible to obtain correct arithmetic expression by inserting characters «+» and «1» into this sequence. For example, sequences «(())()», «()» and «(()(()))» are regular, while «)(», «(()» and «(()))(» are not.
One day Johnny got bracket sequence. He decided to remove some of the brackets from it in order to obtain a regular bracket sequence. What is the maximum length of a regular bracket sequence which can be obtained?
Input Specification:
Input consists of a single line with non-empty string of «(» and «)» characters. Its length does not exceed 106.
Output Specification:
Output the maximum possible length of a regular bracket sequence.
Demo Input:
['(()))(\n', '((()())\n']
Demo Output:
['4\n', '6\n']
Note:
none | ```python
s = str(input())
l = []
lo = []
for i in s:
l.append(i)
if l[-1] == "(":
l.pop()
for i in l:
if i == "(":
lo.append(i)
c = 0
for i in l:
if i == ")" and len(lo) > 0:
c+=2
lo.pop()
print(c)
``` | 0 |
75 | A | Life Without Zeros | PROGRAMMING | 1,000 | [
"implementation"
] | A. Life Without Zeros | 2 | 256 | Can you imagine our life if we removed all zeros from it? For sure we will have many problems.
In this problem we will have a simple example if we removed all zeros from our life, it's the addition operation. Let's assume you are given this equation *a*<=+<=*b*<==<=*c*, where *a* and *b* are positive integers, and *c* is the sum of *a* and *b*. Now let's remove all zeros from this equation. Will the equation remain correct after removing all zeros?
For example if the equation is 101<=+<=102<==<=203, if we removed all zeros it will be 11<=+<=12<==<=23 which is still a correct equation.
But if the equation is 105<=+<=106<==<=211, if we removed all zeros it will be 15<=+<=16<==<=211 which is not a correct equation. | The input will consist of two lines, the first line will contain the integer *a*, and the second line will contain the integer *b* which are in the equation as described above (1<=≤<=*a*,<=*b*<=≤<=109). There won't be any leading zeros in both. The value of *c* should be calculated as *c*<==<=*a*<=+<=*b*. | The output will be just one line, you should print "YES" if the equation will remain correct after removing all zeros, and print "NO" otherwise. | [
"101\n102\n",
"105\n106\n"
] | [
"YES\n",
"NO\n"
] | none | 500 | [
{
"input": "101\n102",
"output": "YES"
},
{
"input": "105\n106",
"output": "NO"
},
{
"input": "544\n397",
"output": "YES"
},
{
"input": "822\n280",
"output": "NO"
},
{
"input": "101\n413",
"output": "NO"
},
{
"input": "309\n139",
"output": "NO"
},
{
"input": "693\n970",
"output": "NO"
},
{
"input": "981\n1",
"output": "YES"
},
{
"input": "352\n276",
"output": "YES"
},
{
"input": "164\n691",
"output": "YES"
},
{
"input": "110036\n43",
"output": "YES"
},
{
"input": "100\n1000",
"output": "NO"
},
{
"input": "1000000000\n1000000000",
"output": "YES"
},
{
"input": "999999999\n999999999",
"output": "YES"
},
{
"input": "6\n4",
"output": "NO"
},
{
"input": "123456\n876543",
"output": "YES"
},
{
"input": "1234567\n9876543",
"output": "NO"
},
{
"input": "1111111\n1119111",
"output": "NO"
},
{
"input": "10502405\n40403403",
"output": "YES"
},
{
"input": "1\n1",
"output": "YES"
},
{
"input": "5\n4",
"output": "YES"
},
{
"input": "1\n6",
"output": "YES"
},
{
"input": "40\n17",
"output": "NO"
},
{
"input": "35\n81",
"output": "YES"
},
{
"input": "347\n908",
"output": "NO"
},
{
"input": "2081\n7450",
"output": "NO"
},
{
"input": "84355694\n373629503",
"output": "NO"
},
{
"input": "885992048\n510468672",
"output": "NO"
},
{
"input": "540144752\n647307841",
"output": "NO"
},
{
"input": "341781108\n784147010",
"output": "NO"
},
{
"input": "960440938\n572334653",
"output": "NO"
},
{
"input": "657414510\n768771903",
"output": "NO"
},
{
"input": "501871728\n725074574",
"output": "NO"
},
{
"input": "968\n851",
"output": "YES"
},
{
"input": "943\n939",
"output": "YES"
},
{
"input": "347\n908",
"output": "NO"
},
{
"input": "611\n41",
"output": "YES"
},
{
"input": "737\n289",
"output": "NO"
},
{
"input": "168\n571",
"output": "YES"
},
{
"input": "868\n463",
"output": "YES"
},
{
"input": "815732007\n913882008",
"output": "NO"
},
{
"input": "459039901\n453033850",
"output": "NO"
},
{
"input": "975305404\n484601256",
"output": "NO"
}
] | 1,693,990,116 | 2,147,483,647 | PyPy 3-64 | RUNTIME_ERROR | TESTS | 0 | 124 | 3,072,000 | n = int(input())
m = int(input())
sol = n + m;n = str(n)
m = str(m);sol = str(c)
n = int(n.replace('0', ""))
m = int(m.replace('0', ""))
sol=int(sol.replace("0",""))
if n + m == sol:
print("YES")
else:
print("NO") | Title: Life Without Zeros
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Can you imagine our life if we removed all zeros from it? For sure we will have many problems.
In this problem we will have a simple example if we removed all zeros from our life, it's the addition operation. Let's assume you are given this equation *a*<=+<=*b*<==<=*c*, where *a* and *b* are positive integers, and *c* is the sum of *a* and *b*. Now let's remove all zeros from this equation. Will the equation remain correct after removing all zeros?
For example if the equation is 101<=+<=102<==<=203, if we removed all zeros it will be 11<=+<=12<==<=23 which is still a correct equation.
But if the equation is 105<=+<=106<==<=211, if we removed all zeros it will be 15<=+<=16<==<=211 which is not a correct equation.
Input Specification:
The input will consist of two lines, the first line will contain the integer *a*, and the second line will contain the integer *b* which are in the equation as described above (1<=≤<=*a*,<=*b*<=≤<=109). There won't be any leading zeros in both. The value of *c* should be calculated as *c*<==<=*a*<=+<=*b*.
Output Specification:
The output will be just one line, you should print "YES" if the equation will remain correct after removing all zeros, and print "NO" otherwise.
Demo Input:
['101\n102\n', '105\n106\n']
Demo Output:
['YES\n', 'NO\n']
Note:
none | ```python
n = int(input())
m = int(input())
sol = n + m;n = str(n)
m = str(m);sol = str(c)
n = int(n.replace('0', ""))
m = int(m.replace('0', ""))
sol=int(sol.replace("0",""))
if n + m == sol:
print("YES")
else:
print("NO")
``` | -1 |
584 | A | Olesya and Rodion | PROGRAMMING | 1,000 | [
"math"
] | null | null | Olesya loves numbers consisting of *n* digits, and Rodion only likes numbers that are divisible by *t*. Find some number that satisfies both of them.
Your task is: given the *n* and *t* print an integer strictly larger than zero consisting of *n* digits that is divisible by *t*. If such number doesn't exist, print <=-<=1. | The single line contains two numbers, *n* and *t* (1<=≤<=*n*<=≤<=100, 2<=≤<=*t*<=≤<=10) — the length of the number and the number it should be divisible by. | Print one such positive number without leading zeroes, — the answer to the problem, or <=-<=1, if such number doesn't exist. If there are multiple possible answers, you are allowed to print any of them. | [
"3 2\n"
] | [
"712"
] | none | 500 | [
{
"input": "3 2",
"output": "222"
},
{
"input": "2 2",
"output": "22"
},
{
"input": "4 3",
"output": "3333"
},
{
"input": "5 3",
"output": "33333"
},
{
"input": "10 7",
"output": "7777777777"
},
{
"input": "2 9",
"output": "99"
},
{
"input": "18 8",
"output": "888888888888888888"
},
{
"input": "1 5",
"output": "5"
},
{
"input": "1 10",
"output": "-1"
},
{
"input": "100 5",
"output": "5555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555"
},
{
"input": "10 2",
"output": "2222222222"
},
{
"input": "18 10",
"output": "111111111111111110"
},
{
"input": "1 9",
"output": "9"
},
{
"input": "7 6",
"output": "6666666"
},
{
"input": "4 4",
"output": "4444"
},
{
"input": "14 7",
"output": "77777777777777"
},
{
"input": "3 8",
"output": "888"
},
{
"input": "1 3",
"output": "3"
},
{
"input": "2 8",
"output": "88"
},
{
"input": "3 8",
"output": "888"
},
{
"input": "4 3",
"output": "3333"
},
{
"input": "5 9",
"output": "99999"
},
{
"input": "4 8",
"output": "8888"
},
{
"input": "3 4",
"output": "444"
},
{
"input": "9 4",
"output": "444444444"
},
{
"input": "8 10",
"output": "11111110"
},
{
"input": "1 6",
"output": "6"
},
{
"input": "20 3",
"output": "33333333333333333333"
},
{
"input": "15 10",
"output": "111111111111110"
},
{
"input": "31 4",
"output": "4444444444444444444444444444444"
},
{
"input": "18 9",
"output": "999999999999999999"
},
{
"input": "72 4",
"output": "444444444444444444444444444444444444444444444444444444444444444444444444"
},
{
"input": "76 8",
"output": "8888888888888888888888888888888888888888888888888888888888888888888888888888"
},
{
"input": "12 5",
"output": "555555555555"
},
{
"input": "54 5",
"output": "555555555555555555555555555555555555555555555555555555"
},
{
"input": "96 10",
"output": "111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111110"
},
{
"input": "15 9",
"output": "999999999999999"
},
{
"input": "100 2",
"output": "2222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222"
},
{
"input": "99 3",
"output": "333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333"
},
{
"input": "98 4",
"output": "44444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444"
},
{
"input": "97 5",
"output": "5555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555"
},
{
"input": "100 6",
"output": "6666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666"
},
{
"input": "99 7",
"output": "777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777"
},
{
"input": "98 8",
"output": "88888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888"
},
{
"input": "97 9",
"output": "9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999"
},
{
"input": "100 10",
"output": "1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111110"
},
{
"input": "3 10",
"output": "110"
},
{
"input": "2 4",
"output": "44"
},
{
"input": "2 10",
"output": "10"
},
{
"input": "10 10",
"output": "1111111110"
},
{
"input": "4 10",
"output": "1110"
},
{
"input": "25 10",
"output": "1111111111111111111111110"
},
{
"input": "50 10",
"output": "11111111111111111111111111111111111111111111111110"
},
{
"input": "5 10",
"output": "11110"
},
{
"input": "99 10",
"output": "111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111110"
},
{
"input": "100 10",
"output": "1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111110"
},
{
"input": "1 2",
"output": "2"
},
{
"input": "20 10",
"output": "11111111111111111110"
},
{
"input": "99 7",
"output": "777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777"
},
{
"input": "89 5",
"output": "55555555555555555555555555555555555555555555555555555555555555555555555555555555555555555"
},
{
"input": "6 10",
"output": "111110"
},
{
"input": "3 8",
"output": "888"
},
{
"input": "1 9",
"output": "9"
},
{
"input": "1 4",
"output": "4"
},
{
"input": "100 7",
"output": "7777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777"
}
] | 1,665,214,610 | 2,147,483,647 | Python 3 | OK | TESTS | 65 | 46 | 0 | n,t = map(int,input().split())
s = '1'
i = 1
while i <= n-1:
s += '0'
i += 1
w = s + '0'
num1 = int(s)
num2 = int(w)
while num1 < num2:
if num1 % t == 0:
print(num1)
break
else:
num1 += 1
if num1 == num2:
print(-1) | Title: Olesya and Rodion
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Olesya loves numbers consisting of *n* digits, and Rodion only likes numbers that are divisible by *t*. Find some number that satisfies both of them.
Your task is: given the *n* and *t* print an integer strictly larger than zero consisting of *n* digits that is divisible by *t*. If such number doesn't exist, print <=-<=1.
Input Specification:
The single line contains two numbers, *n* and *t* (1<=≤<=*n*<=≤<=100, 2<=≤<=*t*<=≤<=10) — the length of the number and the number it should be divisible by.
Output Specification:
Print one such positive number without leading zeroes, — the answer to the problem, or <=-<=1, if such number doesn't exist. If there are multiple possible answers, you are allowed to print any of them.
Demo Input:
['3 2\n']
Demo Output:
['712']
Note:
none | ```python
n,t = map(int,input().split())
s = '1'
i = 1
while i <= n-1:
s += '0'
i += 1
w = s + '0'
num1 = int(s)
num2 = int(w)
while num1 < num2:
if num1 % t == 0:
print(num1)
break
else:
num1 += 1
if num1 == num2:
print(-1)
``` | 3 |
|
911 | B | Two Cakes | PROGRAMMING | 1,200 | [
"binary search",
"brute force",
"implementation"
] | null | null | It's New Year's Eve soon, so Ivan decided it's high time he started setting the table. Ivan has bought two cakes and cut them into pieces: the first cake has been cut into *a* pieces, and the second one — into *b* pieces.
Ivan knows that there will be *n* people at the celebration (including himself), so Ivan has set *n* plates for the cakes. Now he is thinking about how to distribute the cakes between the plates. Ivan wants to do it in such a way that all following conditions are met:
1. Each piece of each cake is put on some plate; 1. Each plate contains at least one piece of cake; 1. No plate contains pieces of both cakes.
To make his guests happy, Ivan wants to distribute the cakes in such a way that the minimum number of pieces on the plate is maximized. Formally, Ivan wants to know the maximum possible number *x* such that he can distribute the cakes according to the aforementioned conditions, and each plate will contain at least *x* pieces of cake.
Help Ivan to calculate this number *x*! | The first line contains three integers *n*, *a* and *b* (1<=≤<=*a*,<=*b*<=≤<=100, 2<=≤<=*n*<=≤<=*a*<=+<=*b*) — the number of plates, the number of pieces of the first cake, and the number of pieces of the second cake, respectively. | Print the maximum possible number *x* such that Ivan can distribute the cake in such a way that each plate will contain at least *x* pieces of cake. | [
"5 2 3\n",
"4 7 10\n"
] | [
"1\n",
"3\n"
] | In the first example there is only one way to distribute cakes to plates, all of them will have 1 cake on it.
In the second example you can have two plates with 3 and 4 pieces of the first cake and two plates both with 5 pieces of the second cake. Minimal number of pieces is 3. | 0 | [
{
"input": "5 2 3",
"output": "1"
},
{
"input": "4 7 10",
"output": "3"
},
{
"input": "100 100 100",
"output": "2"
},
{
"input": "10 100 3",
"output": "3"
},
{
"input": "2 9 29",
"output": "9"
},
{
"input": "4 6 10",
"output": "3"
},
{
"input": "3 70 58",
"output": "35"
},
{
"input": "5 7 10",
"output": "3"
},
{
"input": "5 30 22",
"output": "10"
},
{
"input": "5 5 6",
"output": "2"
},
{
"input": "2 4 3",
"output": "3"
},
{
"input": "10 10 31",
"output": "3"
},
{
"input": "2 1 1",
"output": "1"
},
{
"input": "10 98 99",
"output": "19"
},
{
"input": "4 10 16",
"output": "5"
},
{
"input": "11 4 8",
"output": "1"
},
{
"input": "5 10 14",
"output": "4"
},
{
"input": "6 7 35",
"output": "7"
},
{
"input": "5 6 7",
"output": "2"
},
{
"input": "4 15 3",
"output": "3"
},
{
"input": "7 48 77",
"output": "16"
},
{
"input": "4 4 10",
"output": "3"
},
{
"input": "4 7 20",
"output": "6"
},
{
"input": "5 2 8",
"output": "2"
},
{
"input": "3 2 3",
"output": "1"
},
{
"input": "14 95 1",
"output": "1"
},
{
"input": "99 82 53",
"output": "1"
},
{
"input": "10 71 27",
"output": "9"
},
{
"input": "5 7 8",
"output": "2"
},
{
"input": "11 77 77",
"output": "12"
},
{
"input": "10 5 28",
"output": "3"
},
{
"input": "7 3 12",
"output": "2"
},
{
"input": "10 15 17",
"output": "3"
},
{
"input": "7 7 7",
"output": "1"
},
{
"input": "4 11 18",
"output": "6"
},
{
"input": "3 3 4",
"output": "2"
},
{
"input": "9 2 10",
"output": "1"
},
{
"input": "100 90 20",
"output": "1"
},
{
"input": "3 2 2",
"output": "1"
},
{
"input": "12 45 60",
"output": "8"
},
{
"input": "3 94 79",
"output": "47"
},
{
"input": "41 67 34",
"output": "2"
},
{
"input": "9 3 23",
"output": "2"
},
{
"input": "10 20 57",
"output": "7"
},
{
"input": "55 27 30",
"output": "1"
},
{
"input": "100 100 10",
"output": "1"
},
{
"input": "20 8 70",
"output": "3"
},
{
"input": "3 3 3",
"output": "1"
},
{
"input": "4 9 15",
"output": "5"
},
{
"input": "3 1 3",
"output": "1"
},
{
"input": "2 94 94",
"output": "94"
},
{
"input": "5 3 11",
"output": "2"
},
{
"input": "4 3 2",
"output": "1"
},
{
"input": "12 12 100",
"output": "9"
},
{
"input": "6 75 91",
"output": "25"
},
{
"input": "3 4 3",
"output": "2"
},
{
"input": "3 2 5",
"output": "2"
},
{
"input": "6 5 15",
"output": "3"
},
{
"input": "4 3 6",
"output": "2"
},
{
"input": "3 9 9",
"output": "4"
},
{
"input": "26 93 76",
"output": "6"
},
{
"input": "41 34 67",
"output": "2"
},
{
"input": "6 12 6",
"output": "3"
},
{
"input": "5 20 8",
"output": "5"
},
{
"input": "2 1 3",
"output": "1"
},
{
"input": "35 66 99",
"output": "4"
},
{
"input": "30 7 91",
"output": "3"
},
{
"input": "5 22 30",
"output": "10"
},
{
"input": "8 19 71",
"output": "10"
},
{
"input": "3 5 6",
"output": "3"
},
{
"input": "5 3 8",
"output": "2"
},
{
"input": "2 4 2",
"output": "2"
},
{
"input": "4 3 7",
"output": "2"
},
{
"input": "5 20 10",
"output": "5"
},
{
"input": "5 100 50",
"output": "25"
},
{
"input": "6 3 10",
"output": "2"
},
{
"input": "2 90 95",
"output": "90"
},
{
"input": "4 8 6",
"output": "3"
},
{
"input": "6 10 3",
"output": "2"
},
{
"input": "3 3 5",
"output": "2"
},
{
"input": "5 33 33",
"output": "11"
},
{
"input": "5 5 8",
"output": "2"
},
{
"input": "19 24 34",
"output": "3"
},
{
"input": "5 5 12",
"output": "3"
},
{
"input": "8 7 10",
"output": "2"
},
{
"input": "5 56 35",
"output": "17"
},
{
"input": "4 3 5",
"output": "1"
},
{
"input": "18 100 50",
"output": "8"
},
{
"input": "5 6 8",
"output": "2"
},
{
"input": "5 98 100",
"output": "33"
},
{
"input": "6 5 8",
"output": "2"
},
{
"input": "3 40 80",
"output": "40"
},
{
"input": "4 8 11",
"output": "4"
},
{
"input": "66 100 99",
"output": "3"
},
{
"input": "17 100 79",
"output": "10"
},
{
"input": "3 2 10",
"output": "2"
},
{
"input": "99 100 99",
"output": "2"
},
{
"input": "21 100 5",
"output": "5"
},
{
"input": "3 10 2",
"output": "2"
},
{
"input": "4 100 63",
"output": "33"
},
{
"input": "2 2 10",
"output": "2"
},
{
"input": "5 94 79",
"output": "31"
},
{
"input": "4 12 5",
"output": "4"
},
{
"input": "5 5 40",
"output": "5"
},
{
"input": "99 99 99",
"output": "1"
},
{
"input": "8 97 44",
"output": "16"
},
{
"input": "11 4 10",
"output": "1"
},
{
"input": "6 3 3",
"output": "1"
},
{
"input": "7 3 4",
"output": "1"
},
{
"input": "8 4 4",
"output": "1"
},
{
"input": "9 4 5",
"output": "1"
},
{
"input": "12 6 6",
"output": "1"
},
{
"input": "4 48 89",
"output": "29"
},
{
"input": "8 3 6",
"output": "1"
},
{
"input": "4 6 3",
"output": "2"
},
{
"input": "5 5 1",
"output": "1"
},
{
"input": "11 6 5",
"output": "1"
},
{
"input": "4 5 4",
"output": "2"
},
{
"input": "6 6 4",
"output": "1"
},
{
"input": "2 1 2",
"output": "1"
},
{
"input": "4 1 3",
"output": "1"
},
{
"input": "3 3 1",
"output": "1"
},
{
"input": "9 4 6",
"output": "1"
},
{
"input": "6 5 6",
"output": "1"
},
{
"input": "2 2 3",
"output": "2"
},
{
"input": "4 5 1",
"output": "1"
},
{
"input": "13 6 7",
"output": "1"
},
{
"input": "14 7 7",
"output": "1"
},
{
"input": "12 97 13",
"output": "8"
},
{
"input": "4 2 9",
"output": "2"
},
{
"input": "10 20 59",
"output": "7"
},
{
"input": "12 34 56",
"output": "7"
},
{
"input": "4 5 9",
"output": "3"
},
{
"input": "2 2 2",
"output": "2"
},
{
"input": "4 66 41",
"output": "22"
}
] | 1,627,881,485 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 46 | 6,656,000 | n, a,b = map(int,input().split())
c= (a+b)//n
if a%c==0 and b%c==0: print(c)
else: c-=1
print(min(a,b, c)) | Title: Two Cakes
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
It's New Year's Eve soon, so Ivan decided it's high time he started setting the table. Ivan has bought two cakes and cut them into pieces: the first cake has been cut into *a* pieces, and the second one — into *b* pieces.
Ivan knows that there will be *n* people at the celebration (including himself), so Ivan has set *n* plates for the cakes. Now he is thinking about how to distribute the cakes between the plates. Ivan wants to do it in such a way that all following conditions are met:
1. Each piece of each cake is put on some plate; 1. Each plate contains at least one piece of cake; 1. No plate contains pieces of both cakes.
To make his guests happy, Ivan wants to distribute the cakes in such a way that the minimum number of pieces on the plate is maximized. Formally, Ivan wants to know the maximum possible number *x* such that he can distribute the cakes according to the aforementioned conditions, and each plate will contain at least *x* pieces of cake.
Help Ivan to calculate this number *x*!
Input Specification:
The first line contains three integers *n*, *a* and *b* (1<=≤<=*a*,<=*b*<=≤<=100, 2<=≤<=*n*<=≤<=*a*<=+<=*b*) — the number of plates, the number of pieces of the first cake, and the number of pieces of the second cake, respectively.
Output Specification:
Print the maximum possible number *x* such that Ivan can distribute the cake in such a way that each plate will contain at least *x* pieces of cake.
Demo Input:
['5 2 3\n', '4 7 10\n']
Demo Output:
['1\n', '3\n']
Note:
In the first example there is only one way to distribute cakes to plates, all of them will have 1 cake on it.
In the second example you can have two plates with 3 and 4 pieces of the first cake and two plates both with 5 pieces of the second cake. Minimal number of pieces is 3. | ```python
n, a,b = map(int,input().split())
c= (a+b)//n
if a%c==0 and b%c==0: print(c)
else: c-=1
print(min(a,b, c))
``` | 0 |
|
518 | A | Vitaly and Strings | PROGRAMMING | 1,600 | [
"constructive algorithms",
"strings"
] | null | null | Vitaly is a diligent student who never missed a lesson in his five years of studying in the university. He always does his homework on time and passes his exams in time.
During the last lesson the teacher has provided two strings *s* and *t* to Vitaly. The strings have the same length, they consist of lowercase English letters, string *s* is lexicographically smaller than string *t*. Vitaly wondered if there is such string that is lexicographically larger than string *s* and at the same is lexicographically smaller than string *t*. This string should also consist of lowercase English letters and have the length equal to the lengths of strings *s* and *t*.
Let's help Vitaly solve this easy problem! | The first line contains string *s* (1<=≤<=|*s*|<=≤<=100), consisting of lowercase English letters. Here, |*s*| denotes the length of the string.
The second line contains string *t* (|*t*|<==<=|*s*|), consisting of lowercase English letters.
It is guaranteed that the lengths of strings *s* and *t* are the same and string *s* is lexicographically less than string *t*. | If the string that meets the given requirements doesn't exist, print a single string "No such string" (without the quotes).
If such string exists, print it. If there are multiple valid strings, you may print any of them. | [
"a\nc\n",
"aaa\nzzz\n",
"abcdefg\nabcdefh\n"
] | [
"b\n",
"kkk\n",
"No such string\n"
] | String *s* = *s*<sub class="lower-index">1</sub>*s*<sub class="lower-index">2</sub>... *s*<sub class="lower-index">*n*</sub> is said to be lexicographically smaller than *t* = *t*<sub class="lower-index">1</sub>*t*<sub class="lower-index">2</sub>... *t*<sub class="lower-index">*n*</sub>, if there exists such *i*, that *s*<sub class="lower-index">1</sub> = *t*<sub class="lower-index">1</sub>, *s*<sub class="lower-index">2</sub> = *t*<sub class="lower-index">2</sub>, ... *s*<sub class="lower-index">*i* - 1</sub> = *t*<sub class="lower-index">*i* - 1</sub>, *s*<sub class="lower-index">*i*</sub> < *t*<sub class="lower-index">*i*</sub>. | 500 | [
{
"input": "a\nc",
"output": "b"
},
{
"input": "aaa\nzzz",
"output": "kkk"
},
{
"input": "abcdefg\nabcdefh",
"output": "No such string"
},
{
"input": "abcdefg\nabcfefg",
"output": "abcdefh"
},
{
"input": "frt\nfru",
"output": "No such string"
},
{
"input": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\nzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz",
"output": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaab"
},
{
"input": "zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzx\nzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz",
"output": "zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzy"
},
{
"input": "q\nz",
"output": "r"
},
{
"input": "pnzcl\npnzdf",
"output": "pnzcm"
},
{
"input": "vklldrxnfgyorgfpfezvhbouyzzzzz\nvklldrxnfgyorgfpfezvhbouzaaadv",
"output": "vklldrxnfgyorgfpfezvhbouzaaaaa"
},
{
"input": "pkjlxzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz\npkjlyaaaaaaaaaaaaaaaaaaaaaaaaaaaahr",
"output": "pkjlyaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
},
{
"input": "exoudpymnspkocwszzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz\nexoudpymnspkocwtaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaabml",
"output": "exoudpymnspkocwtaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
},
{
"input": "anarzvsklmwvovozwnmhklkpcseeogdgauoppmzrukynbjjoxytuvsiecuzfquxnowewebhtuoxepocyeamqfrblpwqiokbcubil\nanarzvsklmwvovozwnmhklkpcseeogdgauoppmzrukynbjjoxytuvsiecuzfquxnowewebhtuoxepocyeamqfrblpwqiokbcubim",
"output": "No such string"
},
{
"input": "uqyugulumzwlxsjnxxkutzqayskrbjoaaekbhckjryhjjllzzz\nuqyugulumzwlxsjnxxkutzqayskrbjoaaekbhckjryhjjlmaaa",
"output": "No such string"
},
{
"input": "esfaeyxpblcrriizhnhfrxnbopqvhwtetgjqavlqdlxexaifgvkqfwzneibhxxdacbzzzzzzzzzzzzzz\nesfaeyxpblcrriizhnhfrxnbopqvhwtetgjqavlqdlxexaifgvkqfwzneibhxxdaccaaaaaaaaaaaatf",
"output": "esfaeyxpblcrriizhnhfrxnbopqvhwtetgjqavlqdlxexaifgvkqfwzneibhxxdaccaaaaaaaaaaaaaa"
},
{
"input": "oisjtilteipnzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz\noisjtilteipoaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaao",
"output": "oisjtilteipoaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
},
{
"input": "svpoxbsudndfnnpugbouawegyxgtmvqzbewxpcwhopdbwscimgzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz\nsvpoxbsudndfnnpugbouawegyxgtmvqzbewxpcwhopdbwscimhaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
"output": "No such string"
},
{
"input": "ddzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz\ndeaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaao",
"output": "deaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
},
{
"input": "xqzbhslocdbifnyzyjenlpctocieaccsycmwlcebkqqkeibatfvylbqlutvjijgjhdetqsjqnoipqbmjhhzxggdobyvpczdavdzz\nxqzbhslocdbifnyzyjenlpctocieaccsycmwlcebkqqkeibatfvylbqlutvjijgjhdetqsjqnoipqbmjhhzxggdobyvpczdavilj",
"output": "xqzbhslocdbifnyzyjenlpctocieaccsycmwlcebkqqkeibatfvylbqlutvjijgjhdetqsjqnoipqbmjhhzxggdobyvpczdaveaa"
},
{
"input": "poflpxucohdobeisxfsnkbdzwizjjhgngufssqhmfgmydmmrnuminrvxxamoebhczlwsfefdtnchaisfxkfcovxmvppxnrfawfoq\npoflpxucohdobeisxfsnkbdzwizjjhgngufssqhmfgmydmmrnuminrvxxamoebhczlwsfefdtnchaisfxkfcovxmvppxnrfawujg",
"output": "poflpxucohdobeisxfsnkbdzwizjjhgngufssqhmfgmydmmrnuminrvxxamoebhczlwsfefdtnchaisfxkfcovxmvppxnrfawfor"
},
{
"input": "vonggnmokmvmguwtobkxoqgxkuxtyjmxrygyliohlhwxuxjmlkqcfuxboxjnzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz\nvonggnmokmvmguwtobkxoqgxkuxtyjmxrygyliohlhwxuxjmlkqcfuxboxjoaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaac",
"output": "vonggnmokmvmguwtobkxoqgxkuxtyjmxrygyliohlhwxuxjmlkqcfuxboxjoaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
},
{
"input": "bqycw\nquhod",
"output": "bqycx"
},
{
"input": "hceslswecf\nnmxshuymaa",
"output": "hceslswecg"
},
{
"input": "awqtzslxowuaefe\nvujscakjpvxviki",
"output": "awqtzslxowuaeff"
},
{
"input": "lerlcnaogdravnogfogcyoxgi\nojrbithvjdqtempegvqxmgmmw",
"output": "lerlcnaogdravnogfogcyoxgj"
},
{
"input": "jbrhvicytqaivheqeourrlosvnsujsxdinryyawgalidsaufxv\noevvkhujmhagaholrmsatdjjyfmyblvgetpnxgjcilugjsncjs",
"output": "jbrhvicytqaivheqeourrlosvnsujsxdinryyawgalidsaufxw"
},
{
"input": "jrpogrcuhqdpmyzpuabuhaptlxaeiqjxhqkmuzsjbhqxvdtoocrkusaeasqdwlunomwzww\nspvgaswympzlscnumemgiznngnxqgccbubmxgqmaakbnyngkxlxjjsafricchhpecdjgxw",
"output": "jrpogrcuhqdpmyzpuabuhaptlxaeiqjxhqkmuzsjbhqxvdtoocrkusaeasqdwlunomwzwx"
},
{
"input": "mzmhjmfxaxaplzjmjkbyadeweltagyyuzpvrmnyvirjpdmebxyzjvdoezhnayfrvtnccryhkvhcvakcf\nohhhhkujfpjbgouebtmmbzizuhuumvrsqfniwpmxdtzhyiaivdyxhywnqzagicydixjtvbqbevhbqttu",
"output": "mzmhjmfxaxaplzjmjkbyadeweltagyyuzpvrmnyvirjpdmebxyzjvdoezhnayfrvtnccryhkvhcvakcg"
},
{
"input": "cdmwmzutsicpzhcokbbhwktqbomozxvvjlhwdgtiledgurxsfreisgczdwgupzxmjnfyjxcpdwzkggludkcmgppndl\nuvuqvyrnhtyubpevizhjxdvmpueittksrnosmfuuzbimnqussasdjufrthrgjbyzomauaxbvwferfvtmydmwmjaoxg",
"output": "cdmwmzutsicpzhcokbbhwktqbomozxvvjlhwdgtiledgurxsfreisgczdwgupzxmjnfyjxcpdwzkggludkcmgppndm"
},
{
"input": "dpnmrwpbgzvcmrcodwgvvfwpyagdwlngmhrazyvalszhruprxzmwltftxmujfyrrnwzvphgqlcphreumqkytswxziugburwrlyay\nqibcfxdfovoejutaeetbbwrgexdrvqywwmhipxgfrvhzovxkfawpfnpjvlhkyahessodqcclangxefcaixysqijnitevwmpalkzd",
"output": "dpnmrwpbgzvcmrcodwgvvfwpyagdwlngmhrazyvalszhruprxzmwltftxmujfyrrnwzvphgqlcphreumqkytswxziugburwrlyaz"
},
{
"input": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\naaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaab",
"output": "No such string"
},
{
"input": "phdvmuwqmvzyurtnshitcypuzbhpceovkibzbhhjwxkdtvqmbpoumeoiztxtvkvsjrlnhowsdmgftuiulzebdigmun\nphdvmuwqmvzyurtnshitcypuzbhpceovkibzbhhjwxkdtvqmbpoumeoiztxtvkvsjrlnhowsdmgftuiulzebdigmuo",
"output": "No such string"
},
{
"input": "hrsantdquixzjyjtqytcmnflnyehzbibkbgkqffgqpkgeuqmbmxzhbjwsnfkizvbcyoghyvnxxjavoahlqjxomtsouzoog\nhrsantdquixzjyjtqytcmnflnyehzbibkbgkqffgqpkgeuqmbmxzhbjwsnfkizvbcyoghyvnxxjavoahlqjxomtsouzooh",
"output": "No such string"
},
{
"input": "kexdbtpkjbwwyibjndbtmwqzolopqitgkomqggojevoankiepxirrcidxldlzsppehmoazdywltmjbxgsxgihwnwpmczjrcwpywl\nkexdbtpkjbwwyibjndbtmwqzolopqitgkomqggojevoankiepxirrcidxldlzsppehmoazdywltmjbxgsxgihwnwpmczjrcwpywm",
"output": "No such string"
},
{
"input": "yijdysvzfcnaedvnecswgoylhzgguxecmucepgstjbdkbjyfdlxxxejkrrxfiuwjpdmdhhqhlqeqzjwudtdryrfkpwfxdjlkowmk\nyijdysvzfcnaedvnecswgoylhzgguxecmucepgstjbdkbjyfdlxxxejkrrxfiuwjpdmdhhqhlqeqzjwudtdryrfkpwfxdjlkowml",
"output": "No such string"
},
{
"input": "a\nb",
"output": "No such string"
},
{
"input": "x\nz",
"output": "y"
},
{
"input": "a\nz",
"output": "b"
},
{
"input": "y\nz",
"output": "No such string"
},
{
"input": "zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzy\nzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz",
"output": "No such string"
},
{
"input": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\naaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaac",
"output": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaab"
},
{
"input": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\nzaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
"output": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaab"
},
{
"input": "yzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz\nzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz",
"output": "zaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
},
{
"input": "yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy\nzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz",
"output": "yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyz"
},
{
"input": "aaa\naac",
"output": "aab"
},
{
"input": "aaa\naab",
"output": "No such string"
},
{
"input": "zzx\nzzz",
"output": "zzy"
},
{
"input": "zzy\nzzz",
"output": "No such string"
},
{
"input": "aba\naca",
"output": "abb"
},
{
"input": "aaa\nbbb",
"output": "aab"
},
{
"input": "azzz\ncaaa",
"output": "baaa"
}
] | 1,638,356,843 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 9 | 46 | 0 | s=input()
a=input()
l=list(s)
l[len(s)-1]=chr(((ord(l[len(s)-1])-97+1)%26+97))
st=""
for i in l:
st+=i
if st<a:
print(st)
else:
print("No such string")
| Title: Vitaly and Strings
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vitaly is a diligent student who never missed a lesson in his five years of studying in the university. He always does his homework on time and passes his exams in time.
During the last lesson the teacher has provided two strings *s* and *t* to Vitaly. The strings have the same length, they consist of lowercase English letters, string *s* is lexicographically smaller than string *t*. Vitaly wondered if there is such string that is lexicographically larger than string *s* and at the same is lexicographically smaller than string *t*. This string should also consist of lowercase English letters and have the length equal to the lengths of strings *s* and *t*.
Let's help Vitaly solve this easy problem!
Input Specification:
The first line contains string *s* (1<=≤<=|*s*|<=≤<=100), consisting of lowercase English letters. Here, |*s*| denotes the length of the string.
The second line contains string *t* (|*t*|<==<=|*s*|), consisting of lowercase English letters.
It is guaranteed that the lengths of strings *s* and *t* are the same and string *s* is lexicographically less than string *t*.
Output Specification:
If the string that meets the given requirements doesn't exist, print a single string "No such string" (without the quotes).
If such string exists, print it. If there are multiple valid strings, you may print any of them.
Demo Input:
['a\nc\n', 'aaa\nzzz\n', 'abcdefg\nabcdefh\n']
Demo Output:
['b\n', 'kkk\n', 'No such string\n']
Note:
String *s* = *s*<sub class="lower-index">1</sub>*s*<sub class="lower-index">2</sub>... *s*<sub class="lower-index">*n*</sub> is said to be lexicographically smaller than *t* = *t*<sub class="lower-index">1</sub>*t*<sub class="lower-index">2</sub>... *t*<sub class="lower-index">*n*</sub>, if there exists such *i*, that *s*<sub class="lower-index">1</sub> = *t*<sub class="lower-index">1</sub>, *s*<sub class="lower-index">2</sub> = *t*<sub class="lower-index">2</sub>, ... *s*<sub class="lower-index">*i* - 1</sub> = *t*<sub class="lower-index">*i* - 1</sub>, *s*<sub class="lower-index">*i*</sub> < *t*<sub class="lower-index">*i*</sub>. | ```python
s=input()
a=input()
l=list(s)
l[len(s)-1]=chr(((ord(l[len(s)-1])-97+1)%26+97))
st=""
for i in l:
st+=i
if st<a:
print(st)
else:
print("No such string")
``` | 0 |
|
691 | B | s-palindrome | PROGRAMMING | 1,600 | [
"implementation",
"strings"
] | null | null | Let's call a string "s-palindrome" if it is symmetric about the middle of the string. For example, the string "oHo" is "s-palindrome", but the string "aa" is not. The string "aa" is not "s-palindrome", because the second half of it is not a mirror reflection of the first half.
You are given a string *s*. Check if the string is "s-palindrome". | The only line contains the string *s* (1<=≤<=|*s*|<=≤<=1000) which consists of only English letters. | Print "TAK" if the string *s* is "s-palindrome" and "NIE" otherwise. | [
"oXoxoXo\n",
"bod\n",
"ER\n"
] | [
"TAK\n",
"TAK\n",
"NIE\n"
] | none | 0 | [
{
"input": "oXoxoXo",
"output": "TAK"
},
{
"input": "bod",
"output": "TAK"
},
{
"input": "ER",
"output": "NIE"
},
{
"input": "o",
"output": "TAK"
},
{
"input": "a",
"output": "NIE"
},
{
"input": "opo",
"output": "NIE"
},
{
"input": "HCMoxkgbNb",
"output": "NIE"
},
{
"input": "vMhhXCMWDe",
"output": "NIE"
},
{
"input": "iIcamjTRFH",
"output": "NIE"
},
{
"input": "WvoWvvWovW",
"output": "TAK"
},
{
"input": "WXxAdbAxXW",
"output": "TAK"
},
{
"input": "vqMTUUTMpv",
"output": "TAK"
},
{
"input": "iii",
"output": "NIE"
},
{
"input": "AAWW",
"output": "NIE"
},
{
"input": "ss",
"output": "NIE"
},
{
"input": "i",
"output": "NIE"
},
{
"input": "ii",
"output": "NIE"
},
{
"input": "mm",
"output": "NIE"
},
{
"input": "LJ",
"output": "NIE"
},
{
"input": "m",
"output": "NIE"
},
{
"input": "ioi",
"output": "NIE"
},
{
"input": "OA",
"output": "NIE"
},
{
"input": "aaaiaaa",
"output": "NIE"
},
{
"input": "SS",
"output": "NIE"
},
{
"input": "iiii",
"output": "NIE"
},
{
"input": "ssops",
"output": "NIE"
},
{
"input": "ssss",
"output": "NIE"
},
{
"input": "ll",
"output": "NIE"
},
{
"input": "s",
"output": "NIE"
},
{
"input": "bb",
"output": "NIE"
},
{
"input": "uu",
"output": "NIE"
},
{
"input": "ZoZ",
"output": "NIE"
},
{
"input": "mom",
"output": "NIE"
},
{
"input": "uou",
"output": "NIE"
},
{
"input": "u",
"output": "NIE"
},
{
"input": "JL",
"output": "NIE"
},
{
"input": "mOm",
"output": "NIE"
},
{
"input": "llll",
"output": "NIE"
},
{
"input": "ouo",
"output": "NIE"
},
{
"input": "aa",
"output": "NIE"
},
{
"input": "olo",
"output": "NIE"
},
{
"input": "S",
"output": "NIE"
},
{
"input": "lAl",
"output": "NIE"
},
{
"input": "nnnn",
"output": "NIE"
},
{
"input": "ZzZ",
"output": "NIE"
},
{
"input": "bNd",
"output": "NIE"
},
{
"input": "ZZ",
"output": "NIE"
},
{
"input": "oNoNo",
"output": "NIE"
},
{
"input": "l",
"output": "NIE"
},
{
"input": "zz",
"output": "NIE"
},
{
"input": "NON",
"output": "NIE"
},
{
"input": "nn",
"output": "NIE"
},
{
"input": "NoN",
"output": "NIE"
},
{
"input": "sos",
"output": "NIE"
},
{
"input": "lol",
"output": "NIE"
},
{
"input": "mmm",
"output": "NIE"
},
{
"input": "YAiAY",
"output": "NIE"
},
{
"input": "ipIqi",
"output": "NIE"
},
{
"input": "AAA",
"output": "TAK"
},
{
"input": "uoOou",
"output": "NIE"
},
{
"input": "SOS",
"output": "NIE"
},
{
"input": "NN",
"output": "NIE"
},
{
"input": "n",
"output": "NIE"
},
{
"input": "h",
"output": "NIE"
},
{
"input": "blld",
"output": "NIE"
},
{
"input": "ipOqi",
"output": "NIE"
},
{
"input": "pop",
"output": "NIE"
},
{
"input": "BB",
"output": "NIE"
},
{
"input": "OuO",
"output": "NIE"
},
{
"input": "lxl",
"output": "NIE"
},
{
"input": "Z",
"output": "NIE"
},
{
"input": "vvivv",
"output": "NIE"
},
{
"input": "nnnnnnnnnnnnn",
"output": "NIE"
},
{
"input": "AA",
"output": "TAK"
},
{
"input": "t",
"output": "NIE"
},
{
"input": "z",
"output": "NIE"
},
{
"input": "mmmAmmm",
"output": "NIE"
},
{
"input": "qlililp",
"output": "NIE"
},
{
"input": "mpOqm",
"output": "NIE"
},
{
"input": "iiiiiiiiii",
"output": "NIE"
},
{
"input": "BAAAB",
"output": "NIE"
},
{
"input": "UA",
"output": "NIE"
},
{
"input": "mmmmmmm",
"output": "NIE"
},
{
"input": "NpOqN",
"output": "NIE"
},
{
"input": "uOu",
"output": "NIE"
},
{
"input": "uuu",
"output": "NIE"
},
{
"input": "NAMAN",
"output": "NIE"
},
{
"input": "lllll",
"output": "NIE"
},
{
"input": "T",
"output": "TAK"
},
{
"input": "mmmmmmmmmmmmmmmm",
"output": "NIE"
},
{
"input": "AiiA",
"output": "NIE"
},
{
"input": "iOi",
"output": "NIE"
},
{
"input": "lll",
"output": "NIE"
},
{
"input": "N",
"output": "NIE"
},
{
"input": "viv",
"output": "NIE"
},
{
"input": "oiio",
"output": "NIE"
},
{
"input": "AiiiA",
"output": "NIE"
},
{
"input": "NNNN",
"output": "NIE"
},
{
"input": "ixi",
"output": "NIE"
},
{
"input": "AuuA",
"output": "NIE"
},
{
"input": "AAAANANAAAA",
"output": "NIE"
},
{
"input": "mmmmm",
"output": "NIE"
},
{
"input": "oYo",
"output": "TAK"
},
{
"input": "dd",
"output": "NIE"
},
{
"input": "A",
"output": "TAK"
},
{
"input": "ioh",
"output": "NIE"
},
{
"input": "mmmm",
"output": "NIE"
},
{
"input": "uuuu",
"output": "NIE"
},
{
"input": "puq",
"output": "NIE"
},
{
"input": "rrrrrr",
"output": "NIE"
},
{
"input": "c",
"output": "NIE"
},
{
"input": "AbpA",
"output": "NIE"
},
{
"input": "qAq",
"output": "NIE"
},
{
"input": "tt",
"output": "NIE"
},
{
"input": "mnmnm",
"output": "NIE"
},
{
"input": "sss",
"output": "NIE"
},
{
"input": "yy",
"output": "NIE"
},
{
"input": "bob",
"output": "NIE"
},
{
"input": "NAN",
"output": "NIE"
},
{
"input": "mAm",
"output": "NIE"
},
{
"input": "tAt",
"output": "NIE"
},
{
"input": "yAy",
"output": "NIE"
},
{
"input": "zAz",
"output": "NIE"
},
{
"input": "aZ",
"output": "NIE"
},
{
"input": "hh",
"output": "NIE"
},
{
"input": "bbbb",
"output": "NIE"
},
{
"input": "ZAZ",
"output": "NIE"
},
{
"input": "Y",
"output": "TAK"
},
{
"input": "AAMM",
"output": "NIE"
},
{
"input": "lml",
"output": "NIE"
},
{
"input": "AZA",
"output": "NIE"
},
{
"input": "mXm",
"output": "NIE"
},
{
"input": "bd",
"output": "TAK"
},
{
"input": "H",
"output": "TAK"
},
{
"input": "uvu",
"output": "NIE"
},
{
"input": "dxxd",
"output": "NIE"
},
{
"input": "dp",
"output": "NIE"
},
{
"input": "vV",
"output": "NIE"
},
{
"input": "vMo",
"output": "NIE"
},
{
"input": "O",
"output": "TAK"
},
{
"input": "vYv",
"output": "TAK"
},
{
"input": "fv",
"output": "NIE"
},
{
"input": "U",
"output": "TAK"
},
{
"input": "iAi",
"output": "NIE"
},
{
"input": "I",
"output": "TAK"
},
{
"input": "VxrV",
"output": "NIE"
},
{
"input": "POP",
"output": "NIE"
},
{
"input": "bid",
"output": "NIE"
},
{
"input": "bmd",
"output": "NIE"
},
{
"input": "AiA",
"output": "NIE"
},
{
"input": "mmmmmm",
"output": "NIE"
},
{
"input": "XHX",
"output": "TAK"
},
{
"input": "llllll",
"output": "NIE"
},
{
"input": "aAa",
"output": "NIE"
},
{
"input": "Db",
"output": "NIE"
},
{
"input": "lOl",
"output": "NIE"
},
{
"input": "bzd",
"output": "NIE"
}
] | 1,473,522,321 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 5 | 93 | 0 | pair = dict()
pair['A'] = 'A'
pair['b'] = 'd'
pair['d'] = 'b'
pair['H'] = 'H'
pair['I'] = 'I'
pair['M'] = 'M'
pair['O'] = 'O'
pair['o'] = 'o'
pair['p'] = 'q'
pair['q'] = 'p'
pair['T'] = 'T'
pair['U'] = 'U'
pair['V'] = 'V'
pair['v'] = 'v'
pair['W'] = 'W'
pair['w'] = 'w'
pair['X'] = 'X'
pair['x'] = 'x'
pair['Y'] = 'Y'
s = input()
for i in range(len(s) // 2):
if s[i] in pair and s[len(s) - i - 1] == pair[s[i]]:
continue
else:
print("NIE")
exit(0)
if len(s) % 2 == 1 and s[len(s) // 2] not in pair:
print("NIE")
exit(0)
print("TAK")
| Title: s-palindrome
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Let's call a string "s-palindrome" if it is symmetric about the middle of the string. For example, the string "oHo" is "s-palindrome", but the string "aa" is not. The string "aa" is not "s-palindrome", because the second half of it is not a mirror reflection of the first half.
You are given a string *s*. Check if the string is "s-palindrome".
Input Specification:
The only line contains the string *s* (1<=≤<=|*s*|<=≤<=1000) which consists of only English letters.
Output Specification:
Print "TAK" if the string *s* is "s-palindrome" and "NIE" otherwise.
Demo Input:
['oXoxoXo\n', 'bod\n', 'ER\n']
Demo Output:
['TAK\n', 'TAK\n', 'NIE\n']
Note:
none | ```python
pair = dict()
pair['A'] = 'A'
pair['b'] = 'd'
pair['d'] = 'b'
pair['H'] = 'H'
pair['I'] = 'I'
pair['M'] = 'M'
pair['O'] = 'O'
pair['o'] = 'o'
pair['p'] = 'q'
pair['q'] = 'p'
pair['T'] = 'T'
pair['U'] = 'U'
pair['V'] = 'V'
pair['v'] = 'v'
pair['W'] = 'W'
pair['w'] = 'w'
pair['X'] = 'X'
pair['x'] = 'x'
pair['Y'] = 'Y'
s = input()
for i in range(len(s) // 2):
if s[i] in pair and s[len(s) - i - 1] == pair[s[i]]:
continue
else:
print("NIE")
exit(0)
if len(s) % 2 == 1 and s[len(s) // 2] not in pair:
print("NIE")
exit(0)
print("TAK")
``` | 0 |
|
801 | A | Vicious Keyboard | PROGRAMMING | 1,100 | [
"brute force"
] | null | null | Tonio has a keyboard with only two letters, "V" and "K".
One day, he has typed out a string *s* with only these two letters. He really likes it when the string "VK" appears, so he wishes to change at most one letter in the string (or do no changes) to maximize the number of occurrences of that string. Compute the maximum number of times "VK" can appear as a substring (i. e. a letter "K" right after a letter "V") in the resulting string. | The first line will contain a string *s* consisting only of uppercase English letters "V" and "K" with length not less than 1 and not greater than 100. | Output a single integer, the maximum number of times "VK" can appear as a substring of the given string after changing at most one character. | [
"VK\n",
"VV\n",
"V\n",
"VKKKKKKKKKVVVVVVVVVK\n",
"KVKV\n"
] | [
"1\n",
"1\n",
"0\n",
"3\n",
"1\n"
] | For the first case, we do not change any letters. "VK" appears once, which is the maximum number of times it could appear.
For the second case, we can change the second character from a "V" to a "K". This will give us the string "VK". This has one occurrence of the string "VK" as a substring.
For the fourth case, we can change the fourth character from a "K" to a "V". This will give us the string "VKKVKKKKKKVVVVVVVVVK". This has three occurrences of the string "VK" as a substring. We can check no other moves can give us strictly more occurrences. | 500 | [
{
"input": "VK",
"output": "1"
},
{
"input": "VV",
"output": "1"
},
{
"input": "V",
"output": "0"
},
{
"input": "VKKKKKKKKKVVVVVVVVVK",
"output": "3"
},
{
"input": "KVKV",
"output": "1"
},
{
"input": "VKKVVVKVKVK",
"output": "5"
},
{
"input": "VKVVKVKVVKVKKKKVVVVVVVVKVKVVVVVVKKVKKVKVVKVKKVVVVKV",
"output": "14"
},
{
"input": "VVKKVKKVVKKVKKVKVVKKVKKVVKKVKVVKKVKKVKVVKKVVKKVKVVKKVKVVKKVVKVVKKVKKVKKVKKVKKVKVVKKVKKVKKVKKVKKVVKVK",
"output": "32"
},
{
"input": "KVVKKVKVKVKVKVKKVKVKVVKVKVVKVVKVKKVKVKVKVKVKVKVKVKVKVKVKVKVKVKVVKVKVVKKVKVKK",
"output": "32"
},
{
"input": "KVVVVVKKVKVVKVVVKVVVKKKVKKKVVKVKKKVKKKKVKVVVVVKKKVVVVKKVVVVKKKVKVVVVVVVKKVKVKKKVVKVVVKVVKK",
"output": "21"
},
{
"input": "VVVVVKKVKVKVKVVKVVKKVVKVKKKKKKKVKKKVVVVVVKKVVVKVKVVKVKKVVKVVVKKKKKVVVVVKVVVVKVVVKKVKKVKKKVKKVKKVVKKV",
"output": "25"
},
{
"input": "KKVVKVVKVVKKVVKKVKVVKKV",
"output": "7"
},
{
"input": "KKVVKKVVVKKVKKVKKVVVKVVVKKVKKVVVKKVVVKVVVKVVVKKVVVKKVVVKVVVKKVVVKVVKKVVVKKVVVKKVVKVVVKKVVKKVKKVVVKKV",
"output": "24"
},
{
"input": "KVKVKVKVKVKVKVKVKVKVVKVKVKVKVKVKVKVVKVKVKKVKVKVKVKVVKVKVKVKVKVKVKVKVKKVKVKVV",
"output": "35"
},
{
"input": "VKVVVKKKVKVVKVKVKVKVKVV",
"output": "9"
},
{
"input": "KKKKVKKVKVKVKKKVVVVKK",
"output": "6"
},
{
"input": "KVKVKKVVVVVVKKKVKKKKVVVVKVKKVKVVK",
"output": "9"
},
{
"input": "KKVKKVKKKVKKKVKKKVKVVVKKVVVVKKKVKKVVKVKKVKVKVKVVVKKKVKKKKKVVKVVKVVVKKVVKVVKKKKKVK",
"output": "22"
},
{
"input": "VVVKVKVKVVVVVKVVVKKVVVKVVVVVKKVVKVVVKVVVKVKKKVVKVVVVVKVVVVKKVVKVKKVVKKKVKVVKVKKKKVVKVVVKKKVKVKKKKKK",
"output": "25"
},
{
"input": "VKVVKVVKKKVVKVKKKVVKKKVVKVVKVVKKVKKKVKVKKKVVKVKKKVVKVVKKKVVKKKVKKKVVKKVVKKKVKVKKKVKKKVKKKVKVKKKVVKVK",
"output": "29"
},
{
"input": "KKVKVVVKKVV",
"output": "3"
},
{
"input": "VKVKVKVKVKVKVKVKVKVKVVKVKVKVKVKVK",
"output": "16"
},
{
"input": "VVKKKVVKKKVVKKKVVKKKVVKKKVVKKKVVKKKVVKKKVVKKKVVKKKVVKKKVVKKKVV",
"output": "13"
},
{
"input": "VVKKVKVKKKVVVKVVVKVKKVKKKVVVKVVKVKKVKKVKVKVVKKVVKKVKVVKKKVVKKVVVKVKVVVKVKVVKVKKVKKV",
"output": "26"
},
{
"input": "VVKVKKVVKKVVKKVVKKVVKKVKKVVKVKKVVKKVVKKVVKKVVKKVVKVVKKVVKVVKKVVKVVKKVVKKVKKVVKVVKKVVKVVKKVV",
"output": "26"
},
{
"input": "K",
"output": "0"
},
{
"input": "VKVK",
"output": "2"
},
{
"input": "VKVV",
"output": "2"
},
{
"input": "KV",
"output": "0"
},
{
"input": "KK",
"output": "1"
},
{
"input": "KKVK",
"output": "2"
},
{
"input": "KKKK",
"output": "1"
},
{
"input": "KKV",
"output": "1"
},
{
"input": "KKVKVK",
"output": "3"
},
{
"input": "VKKVK",
"output": "2"
},
{
"input": "VKKK",
"output": "2"
},
{
"input": "KKK",
"output": "1"
},
{
"input": "KVV",
"output": "1"
},
{
"input": "KKVKV",
"output": "2"
},
{
"input": "VVK",
"output": "1"
},
{
"input": "VVVKVKVKVKVKVKVK",
"output": "8"
},
{
"input": "KVVVK",
"output": "2"
},
{
"input": "VVVKK",
"output": "2"
},
{
"input": "KKVV",
"output": "1"
},
{
"input": "KKKKKKK",
"output": "1"
},
{
"input": "VKKKVK",
"output": "3"
},
{
"input": "KKVVV",
"output": "1"
},
{
"input": "VVVVVV",
"output": "1"
},
{
"input": "KKKV",
"output": "1"
},
{
"input": "VVKVV",
"output": "2"
},
{
"input": "VKVKKK",
"output": "3"
},
{
"input": "VKKV",
"output": "1"
},
{
"input": "VKKVV",
"output": "2"
},
{
"input": "VVKKVV",
"output": "2"
},
{
"input": "KKVVKKV",
"output": "2"
},
{
"input": "KKKKK",
"output": "1"
},
{
"input": "VKVVKKVKKVVKVKKVKKKVKKVKVKK",
"output": "10"
},
{
"input": "VKVKVV",
"output": "3"
},
{
"input": "VKVVKVV",
"output": "3"
},
{
"input": "VVV",
"output": "1"
},
{
"input": "VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV",
"output": "1"
},
{
"input": "VVKKKKKKVKK",
"output": "3"
},
{
"input": "KVKVKVV",
"output": "3"
}
] | 1,492,357,293 | 393 | Python 3 | OK | TESTS | 63 | 62 | 5,529,600 | s = input().strip()
s = s.replace("VK", "*")
cnt = sum(map(lambda x: x=="*",s))
if "VV" in s or "KK" in s:
cnt +=1
print(cnt) | Title: Vicious Keyboard
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Tonio has a keyboard with only two letters, "V" and "K".
One day, he has typed out a string *s* with only these two letters. He really likes it when the string "VK" appears, so he wishes to change at most one letter in the string (or do no changes) to maximize the number of occurrences of that string. Compute the maximum number of times "VK" can appear as a substring (i. e. a letter "K" right after a letter "V") in the resulting string.
Input Specification:
The first line will contain a string *s* consisting only of uppercase English letters "V" and "K" with length not less than 1 and not greater than 100.
Output Specification:
Output a single integer, the maximum number of times "VK" can appear as a substring of the given string after changing at most one character.
Demo Input:
['VK\n', 'VV\n', 'V\n', 'VKKKKKKKKKVVVVVVVVVK\n', 'KVKV\n']
Demo Output:
['1\n', '1\n', '0\n', '3\n', '1\n']
Note:
For the first case, we do not change any letters. "VK" appears once, which is the maximum number of times it could appear.
For the second case, we can change the second character from a "V" to a "K". This will give us the string "VK". This has one occurrence of the string "VK" as a substring.
For the fourth case, we can change the fourth character from a "K" to a "V". This will give us the string "VKKVKKKKKKVVVVVVVVVK". This has three occurrences of the string "VK" as a substring. We can check no other moves can give us strictly more occurrences. | ```python
s = input().strip()
s = s.replace("VK", "*")
cnt = sum(map(lambda x: x=="*",s))
if "VV" in s or "KK" in s:
cnt +=1
print(cnt)
``` | 3 |
|
274 | A | k-Multiple Free Set | PROGRAMMING | 1,500 | [
"binary search",
"greedy",
"sortings"
] | null | null | A *k*-multiple free set is a set of integers where there is no pair of integers where one is equal to another integer multiplied by *k*. That is, there are no two integers *x* and *y* (*x*<=<<=*y*) from the set, such that *y*<==<=*x*·*k*.
You're given a set of *n* distinct positive integers. Your task is to find the size of it's largest *k*-multiple free subset. | The first line of the input contains two integers *n* and *k* (1<=≤<=*n*<=≤<=105,<=1<=≤<=*k*<=≤<=109). The next line contains a list of *n* distinct positive integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=109).
All the numbers in the lines are separated by single spaces. | On the only line of the output print the size of the largest *k*-multiple free subset of {*a*1,<=*a*2,<=...,<=*a**n*}. | [
"6 2\n2 3 6 5 4 10\n"
] | [
"3\n"
] | In the sample input one of the possible maximum 2-multiple free subsets is {4, 5, 6}. | 500 | [
{
"input": "6 2\n2 3 6 5 4 10",
"output": "3"
},
{
"input": "10 2\n1 2 3 4 5 6 7 8 9 10",
"output": "6"
},
{
"input": "1 1\n1",
"output": "1"
},
{
"input": "100 2\n191 17 61 40 77 95 128 88 26 69 79 10 131 106 142 152 68 39 182 53 83 81 6 89 65 148 33 22 5 47 107 121 52 163 150 158 189 118 75 180 177 176 112 167 140 184 29 166 25 46 169 145 187 123 196 18 115 126 155 100 63 58 159 19 173 113 133 60 130 161 76 157 93 199 50 97 15 67 109 164 99 149 3 137 153 136 56 43 103 170 13 183 194 72 9 181 86 30 91 36",
"output": "79"
},
{
"input": "100 3\n13 38 137 24 46 192 33 8 170 141 118 57 198 133 112 176 40 36 91 130 166 72 123 28 82 180 134 52 64 107 97 79 199 184 158 22 181 163 98 7 88 41 73 87 167 109 15 173 153 70 50 119 139 56 17 152 84 161 11 116 31 187 143 196 27 102 132 126 149 63 146 168 67 48 53 120 20 105 155 10 128 47 23 6 94 3 113 65 44 179 189 99 75 34 111 193 60 145 171 77",
"output": "87"
},
{
"input": "12 400000000\n1 400000000 800000000 2 3 4 5 6 7 8 9 10",
"output": "10"
},
{
"input": "3 1\n1 2 3",
"output": "3"
},
{
"input": "1 1\n1000000000",
"output": "1"
},
{
"input": "10 1\n1 100 300 400 500 500000 1000000 10000000 100000000 1000000000",
"output": "10"
},
{
"input": "2 1\n2 1",
"output": "2"
},
{
"input": "2 1000000000\n1 1000000000",
"output": "1"
},
{
"input": "4 1000\n1 1000 1000000 1000000000",
"output": "2"
},
{
"input": "2 2\n1 3",
"output": "2"
},
{
"input": "2 2\n16 8",
"output": "1"
},
{
"input": "3 2\n8 4 2",
"output": "2"
},
{
"input": "5 1\n1 2 3 4 5",
"output": "5"
},
{
"input": "2 2\n500000000 1000000000",
"output": "1"
},
{
"input": "2 2\n4 2",
"output": "1"
},
{
"input": "10 100000000\n1 2 3 4 5 6 7 8 82000 907431936",
"output": "10"
},
{
"input": "8 65538\n65535 65536 65537 65538 65539 131072 262144 196608",
"output": "8"
},
{
"input": "5 2\n10 8 6 4 2",
"output": "4"
},
{
"input": "2 1000000000\n276447232 100000",
"output": "2"
}
] | 1,591,357,607 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 5 | 2,000 | 8,294,400 | n,k=map(int,input().split())
li=[int(i)for i in input().split()]
li.sort()
m=0
lst=list()
for i in range(0,n-1):
lst=[]
lst.append(li[i])
for j in range(i+1,n):
flag=1
lst1=lst
for h in lst1:
if li[j]/h==k:
flag=0
break
if flag==1:
lst.append(li[j])
m=max(m,len(lst))
print(m) | Title: k-Multiple Free Set
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A *k*-multiple free set is a set of integers where there is no pair of integers where one is equal to another integer multiplied by *k*. That is, there are no two integers *x* and *y* (*x*<=<<=*y*) from the set, such that *y*<==<=*x*·*k*.
You're given a set of *n* distinct positive integers. Your task is to find the size of it's largest *k*-multiple free subset.
Input Specification:
The first line of the input contains two integers *n* and *k* (1<=≤<=*n*<=≤<=105,<=1<=≤<=*k*<=≤<=109). The next line contains a list of *n* distinct positive integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=109).
All the numbers in the lines are separated by single spaces.
Output Specification:
On the only line of the output print the size of the largest *k*-multiple free subset of {*a*1,<=*a*2,<=...,<=*a**n*}.
Demo Input:
['6 2\n2 3 6 5 4 10\n']
Demo Output:
['3\n']
Note:
In the sample input one of the possible maximum 2-multiple free subsets is {4, 5, 6}. | ```python
n,k=map(int,input().split())
li=[int(i)for i in input().split()]
li.sort()
m=0
lst=list()
for i in range(0,n-1):
lst=[]
lst.append(li[i])
for j in range(i+1,n):
flag=1
lst1=lst
for h in lst1:
if li[j]/h==k:
flag=0
break
if flag==1:
lst.append(li[j])
m=max(m,len(lst))
print(m)
``` | 0 |
|
120 | A | Elevator | PROGRAMMING | 1,000 | [
"brute force",
"implementation",
"math"
] | null | null | A sky scraper with 1000 floors has been built in the city of N. It has modern superfast elevators to help to travel from one floor to another. Each elevator has two doors, the front one and the back one. If one goes in through the front door, he goes out through the back one and vice versa. The elevator has two rails numbered with numbers 1 and 2. Rail 1 is located to the left of the entrance to the front door (or correspondingly, to the right of the entrance to the back door). Rail 2 is located opposite it, to the right of the entrance to the front door and to the left of the entrance to the back door. We know that each person in the city of N holds at a rail with the strongest hand.
One day a VIP person visited the city and of course, he took a look at the skyscraper and took a ride in the elevator. We know the door through which he entered and the rail he was holding at. Now we need to determine as soon as possible whether he is left-handed or right-handed. | The first line indicates the door through which the very important person entered the elevator. It contains "front" if the person enters the elevator through the front door and "back" if he entered the elevator through the back door. The second line contains integer *a* (1<=≤<=*a*<=≤<=2) which denotes the number of the rail at which the person was holding. | Print character "R" if the VIP is right-handed or "L" if he is left-handed. | [
"front\n1\n"
] | [
"L\n"
] | none | 0 | [
{
"input": "front\n1",
"output": "L"
},
{
"input": "back\n1",
"output": "R"
},
{
"input": "front\n2",
"output": "R"
},
{
"input": "back\n2",
"output": "L"
}
] | 1,447,199,712 | 2,147,483,647 | Python 3 | OK | TESTS | 4 | 92 | 0 | fi = open('input.txt', 'r')
d, a = fi.readline().strip() == 'front', int(fi.readline()) == 1
print('L' if d == a else 'R', file=open('output.txt', 'w')) | Title: Elevator
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A sky scraper with 1000 floors has been built in the city of N. It has modern superfast elevators to help to travel from one floor to another. Each elevator has two doors, the front one and the back one. If one goes in through the front door, he goes out through the back one and vice versa. The elevator has two rails numbered with numbers 1 and 2. Rail 1 is located to the left of the entrance to the front door (or correspondingly, to the right of the entrance to the back door). Rail 2 is located opposite it, to the right of the entrance to the front door and to the left of the entrance to the back door. We know that each person in the city of N holds at a rail with the strongest hand.
One day a VIP person visited the city and of course, he took a look at the skyscraper and took a ride in the elevator. We know the door through which he entered and the rail he was holding at. Now we need to determine as soon as possible whether he is left-handed or right-handed.
Input Specification:
The first line indicates the door through which the very important person entered the elevator. It contains "front" if the person enters the elevator through the front door and "back" if he entered the elevator through the back door. The second line contains integer *a* (1<=≤<=*a*<=≤<=2) which denotes the number of the rail at which the person was holding.
Output Specification:
Print character "R" if the VIP is right-handed or "L" if he is left-handed.
Demo Input:
['front\n1\n']
Demo Output:
['L\n']
Note:
none | ```python
fi = open('input.txt', 'r')
d, a = fi.readline().strip() == 'front', int(fi.readline()) == 1
print('L' if d == a else 'R', file=open('output.txt', 'w'))
``` | 3 |
|
676 | C | Vasya and String | PROGRAMMING | 1,500 | [
"binary search",
"dp",
"strings",
"two pointers"
] | null | null | High school student Vasya got a string of length *n* as a birthday present. This string consists of letters 'a' and 'b' only. Vasya denotes beauty of the string as the maximum length of a substring (consecutive subsequence) consisting of equal letters.
Vasya can change no more than *k* characters of the original string. What is the maximum beauty of the string he can achieve? | The first line of the input contains two integers *n* and *k* (1<=≤<=*n*<=≤<=100<=000,<=0<=≤<=*k*<=≤<=*n*) — the length of the string and the maximum number of characters to change.
The second line contains the string, consisting of letters 'a' and 'b' only. | Print the only integer — the maximum beauty of the string Vasya can achieve by changing no more than *k* characters. | [
"4 2\nabba\n",
"8 1\naabaabaa\n"
] | [
"4\n",
"5\n"
] | In the first sample, Vasya can obtain both strings "aaaa" and "bbbb".
In the second sample, the optimal answer is obtained with the string "aaaaabaa" or with the string "aabaaaaa". | 1,500 | [
{
"input": "4 2\nabba",
"output": "4"
},
{
"input": "8 1\naabaabaa",
"output": "5"
},
{
"input": "1 0\na",
"output": "1"
},
{
"input": "1 1\nb",
"output": "1"
},
{
"input": "1 0\nb",
"output": "1"
},
{
"input": "1 1\na",
"output": "1"
},
{
"input": "10 10\nbbbbbbbbbb",
"output": "10"
},
{
"input": "10 2\nbbbbbbbbbb",
"output": "10"
},
{
"input": "10 1\nbbabbabbba",
"output": "6"
},
{
"input": "10 10\nbbabbbaabb",
"output": "10"
},
{
"input": "10 9\nbabababbba",
"output": "10"
},
{
"input": "10 4\nbababbaaab",
"output": "9"
},
{
"input": "10 10\naabaaabaaa",
"output": "10"
},
{
"input": "10 10\naaaabbbaaa",
"output": "10"
},
{
"input": "10 1\nbaaaaaaaab",
"output": "9"
},
{
"input": "10 5\naaaaabaaaa",
"output": "10"
},
{
"input": "10 4\naaaaaaaaaa",
"output": "10"
},
{
"input": "100 10\nbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb",
"output": "100"
},
{
"input": "100 7\nbbbbabbbbbaabbbabbbbbbbbbbbabbbbbbbbbbbbbbbbbbbbbbbbbabbbbbbbbbbbabbabbbbbbbbbbbbbbbbbbbbbbbbbbbbbab",
"output": "93"
},
{
"input": "100 30\nbbaabaaabbbbbbbbbbaababababbbbbbaabaabbbbbbbbabbbbbabbbbabbbbbbbbaabbbbbbbbbabbbbbabbbbbbbbbaaaaabba",
"output": "100"
},
{
"input": "100 6\nbaababbbaabbabbaaabbabbaabbbbbbbbaabbbabbbbaabbabbbbbabababbbbabbbbbbabbbbbbbbbaaaabbabbbbaabbabaabb",
"output": "34"
},
{
"input": "100 45\naabababbabbbaaabbbbbbaabbbabbaabbbbbabbbbbbbbabbbbbbabbaababbaabbababbbbbbababbbbbaabbbbbbbaaaababab",
"output": "100"
},
{
"input": "100 2\nababaabababaaababbaaaabbaabbbababbbaaabbbbabababbbabababaababaaabaabbbbaaabbbabbbbbabbbbbbbaabbabbba",
"output": "17"
},
{
"input": "100 25\nbabbbaaababaaabbbaabaabaabbbabbabbbbaaaaaaabaaabaaaaaaaaaabaaaabaaabbbaaabaaababaaabaabbbbaaaaaaaaaa",
"output": "80"
},
{
"input": "100 14\naabaaaaabababbabbabaaaabbaaaabaaabbbaaabaaaaaaaabaaaaabbaaaaaaaaabaaaaaaabbaababaaaababbbbbabaaaabaa",
"output": "61"
},
{
"input": "100 8\naaaaabaaaabaabaaaaaaaabaaaabaaaaaaaaaaaaaabaaaaabaaaaaaaaaaaaaaaaabaaaababaabaaaaaaaaaaaaabbabaaaaaa",
"output": "76"
},
{
"input": "100 12\naaaaaaaaaaaaaaaabaaabaaaaaaaaaabbaaaabbabaaaaaaaaaaaaaaaaaaaaabbaaabaaaaaaaaaaaabaaaaaaaabaaaaaaaaaa",
"output": "100"
},
{
"input": "100 65\naaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
"output": "100"
},
{
"input": "10 0\nbbbbbbbbbb",
"output": "10"
},
{
"input": "10 0\nbbbbabbbbb",
"output": "5"
},
{
"input": "10 0\nbbabbbabba",
"output": "3"
},
{
"input": "10 0\nbaabbbbaba",
"output": "4"
},
{
"input": "10 0\naababbbbaa",
"output": "4"
},
{
"input": "10 2\nabbbbbaaba",
"output": "8"
},
{
"input": "10 0\nabbaaabaaa",
"output": "3"
},
{
"input": "10 0\naabbaaabaa",
"output": "3"
},
{
"input": "10 1\naaaaaababa",
"output": "8"
},
{
"input": "10 0\nbaaaaaaaaa",
"output": "9"
},
{
"input": "10 0\naaaaaaaaaa",
"output": "10"
},
{
"input": "100 0\nbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb",
"output": "100"
},
{
"input": "100 0\nbbbbbbbbbbabbbbaaabbbbbbbbbbbabbbabbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbabbbbbbbbbabbbbbbbbbbbbbab",
"output": "40"
},
{
"input": "100 11\nbaabbbbbababbbbabbbbbbbabbbbbbbbbbbbbbabbbbbbababbbbababbbbaaabbbbabbbbbabbbbbbbbabababbbabbbbbbbabb",
"output": "65"
},
{
"input": "100 8\nbbababbbbbaabbbaaababbbbababababbbbababbabbbabbbbbaabbbabbbababbabbbbabbbabbbbaabbbbabbbaabbbbaaaabb",
"output": "33"
},
{
"input": "100 21\nabbaaaabbbababaabbbababbbbbbbbabbaababababbbabbbaaabbaaabbbbabbabbbabbbabaababbbabbbbbabbbbbbabbbbab",
"output": "65"
},
{
"input": "100 9\nabbbaabaabaaaaaaabbabbbababbaaabbbaaabbaabaaaaabbbbbabbaabaabbbbbaaaaababbaaabbabaabaaabababbaababbb",
"output": "26"
},
{
"input": "100 5\naababababbaaaaaaaabbbabaaaabbabaaaabbaabaaaaabababbabaabaaabaaaaaaaabaababbabbaaabaabbabbaaaaabbabba",
"output": "22"
},
{
"input": "100 9\naababaabaaaaaaaaabbbaabaaaaaaabaaaaaaaaaaaaabaaabaabaabbbbabbaababbabbaaaabbababaabaababaabaaaaaaaaa",
"output": "49"
},
{
"input": "100 6\naaaaabbaaaaaaaaaaabaaaabaaaaaaaaabaaabaaaaaabaaaaaaaaaaabaabaaaabaaaaaaaaaaaaaaabaabbaaaaaaaaaaaaaaa",
"output": "56"
},
{
"input": "100 7\nabaaabaabaabaaaaaabaaaaaaaaaaaaaaaaaaaaaaaaaaaaabaaabaaaaaaabbabaaaaaaaaaaaaaaaaabaaaaaaaaaaaaaaaaba",
"output": "86"
},
{
"input": "100 0\naaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
"output": "100"
}
] | 1,691,830,169 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 1 | 31 | 0 | n, k = map(int, input().split())
s = input()
max_beauty = 0
count_a = 0
count_b = 0
window_start = 0
for i in range(n):
if s[i] == 'a':
count_a += 1
else:
count_b += 1
min_count = min(count_a, count_b)
while (i - window_start + 1) - min_count > k:
if s[window_start] == 'a':
count_a -= 1
else:
count_b -= 1
window_start += 1
max_beauty = max(max_beauty, min_count + k)
print(max_beauty)
| Title: Vasya and String
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
High school student Vasya got a string of length *n* as a birthday present. This string consists of letters 'a' and 'b' only. Vasya denotes beauty of the string as the maximum length of a substring (consecutive subsequence) consisting of equal letters.
Vasya can change no more than *k* characters of the original string. What is the maximum beauty of the string he can achieve?
Input Specification:
The first line of the input contains two integers *n* and *k* (1<=≤<=*n*<=≤<=100<=000,<=0<=≤<=*k*<=≤<=*n*) — the length of the string and the maximum number of characters to change.
The second line contains the string, consisting of letters 'a' and 'b' only.
Output Specification:
Print the only integer — the maximum beauty of the string Vasya can achieve by changing no more than *k* characters.
Demo Input:
['4 2\nabba\n', '8 1\naabaabaa\n']
Demo Output:
['4\n', '5\n']
Note:
In the first sample, Vasya can obtain both strings "aaaa" and "bbbb".
In the second sample, the optimal answer is obtained with the string "aaaaabaa" or with the string "aabaaaaa". | ```python
n, k = map(int, input().split())
s = input()
max_beauty = 0
count_a = 0
count_b = 0
window_start = 0
for i in range(n):
if s[i] == 'a':
count_a += 1
else:
count_b += 1
min_count = min(count_a, count_b)
while (i - window_start + 1) - min_count > k:
if s[window_start] == 'a':
count_a -= 1
else:
count_b -= 1
window_start += 1
max_beauty = max(max_beauty, min_count + k)
print(max_beauty)
``` | 0 |
|
263 | A | Beautiful Matrix | PROGRAMMING | 800 | [
"implementation"
] | null | null | You've got a 5<=×<=5 matrix, consisting of 24 zeroes and a single number one. Let's index the matrix rows by numbers from 1 to 5 from top to bottom, let's index the matrix columns by numbers from 1 to 5 from left to right. In one move, you are allowed to apply one of the two following transformations to the matrix:
1. Swap two neighboring matrix rows, that is, rows with indexes *i* and *i*<=+<=1 for some integer *i* (1<=≤<=*i*<=<<=5). 1. Swap two neighboring matrix columns, that is, columns with indexes *j* and *j*<=+<=1 for some integer *j* (1<=≤<=*j*<=<<=5).
You think that a matrix looks beautiful, if the single number one of the matrix is located in its middle (in the cell that is on the intersection of the third row and the third column). Count the minimum number of moves needed to make the matrix beautiful. | The input consists of five lines, each line contains five integers: the *j*-th integer in the *i*-th line of the input represents the element of the matrix that is located on the intersection of the *i*-th row and the *j*-th column. It is guaranteed that the matrix consists of 24 zeroes and a single number one. | Print a single integer — the minimum number of moves needed to make the matrix beautiful. | [
"0 0 0 0 0\n0 0 0 0 1\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n",
"0 0 0 0 0\n0 0 0 0 0\n0 1 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n"
] | [
"3\n",
"1\n"
] | none | 500 | [
{
"input": "0 0 0 0 0\n0 0 0 0 1\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0",
"output": "3"
},
{
"input": "0 0 0 0 0\n0 0 0 0 0\n0 1 0 0 0\n0 0 0 0 0\n0 0 0 0 0",
"output": "1"
},
{
"input": "0 0 0 0 0\n0 0 0 0 0\n0 0 1 0 0\n0 0 0 0 0\n0 0 0 0 0",
"output": "0"
},
{
"input": "0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 1",
"output": "4"
},
{
"input": "0 1 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0",
"output": "3"
},
{
"input": "1 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0",
"output": "4"
},
{
"input": "0 0 1 0 0\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0",
"output": "2"
},
{
"input": "0 0 0 1 0\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0",
"output": "3"
},
{
"input": "0 0 0 0 1\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0",
"output": "4"
},
{
"input": "0 0 0 0 0\n1 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0",
"output": "3"
},
{
"input": "0 0 0 0 0\n0 1 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0",
"output": "2"
},
{
"input": "0 0 0 0 0\n0 0 1 0 0\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0",
"output": "1"
},
{
"input": "0 0 0 0 0\n0 0 0 1 0\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0",
"output": "2"
},
{
"input": "0 0 0 0 0\n0 0 0 0 0\n1 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0",
"output": "2"
},
{
"input": "0 0 0 0 0\n0 0 0 0 0\n0 0 0 1 0\n0 0 0 0 0\n0 0 0 0 0",
"output": "1"
},
{
"input": "0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 1\n0 0 0 0 0\n0 0 0 0 0",
"output": "2"
},
{
"input": "0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n1 0 0 0 0\n0 0 0 0 0",
"output": "3"
},
{
"input": "0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n0 1 0 0 0\n0 0 0 0 0",
"output": "2"
},
{
"input": "0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n0 0 1 0 0\n0 0 0 0 0",
"output": "1"
},
{
"input": "0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 1 0\n0 0 0 0 0",
"output": "2"
},
{
"input": "0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 1\n0 0 0 0 0",
"output": "3"
},
{
"input": "0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n1 0 0 0 0",
"output": "4"
},
{
"input": "0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n0 1 0 0 0",
"output": "3"
},
{
"input": "0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n0 0 1 0 0",
"output": "2"
},
{
"input": "0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 1 0",
"output": "3"
}
] | 1,698,415,903 | 2,147,483,647 | Python 3 | OK | TESTS | 25 | 92 | 0 | l1=[]
for i in range(1,6):
l=list(map(int,input().split()))
l1.append(l)
for i in l1:
for j in i:
if j!=0:
c=i.index(j)
r=l1.index(i)
m=abs(r-2)
m=m+abs(c-2)
print(m) | Title: Beautiful Matrix
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You've got a 5<=×<=5 matrix, consisting of 24 zeroes and a single number one. Let's index the matrix rows by numbers from 1 to 5 from top to bottom, let's index the matrix columns by numbers from 1 to 5 from left to right. In one move, you are allowed to apply one of the two following transformations to the matrix:
1. Swap two neighboring matrix rows, that is, rows with indexes *i* and *i*<=+<=1 for some integer *i* (1<=≤<=*i*<=<<=5). 1. Swap two neighboring matrix columns, that is, columns with indexes *j* and *j*<=+<=1 for some integer *j* (1<=≤<=*j*<=<<=5).
You think that a matrix looks beautiful, if the single number one of the matrix is located in its middle (in the cell that is on the intersection of the third row and the third column). Count the minimum number of moves needed to make the matrix beautiful.
Input Specification:
The input consists of five lines, each line contains five integers: the *j*-th integer in the *i*-th line of the input represents the element of the matrix that is located on the intersection of the *i*-th row and the *j*-th column. It is guaranteed that the matrix consists of 24 zeroes and a single number one.
Output Specification:
Print a single integer — the minimum number of moves needed to make the matrix beautiful.
Demo Input:
['0 0 0 0 0\n0 0 0 0 1\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n', '0 0 0 0 0\n0 0 0 0 0\n0 1 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n']
Demo Output:
['3\n', '1\n']
Note:
none | ```python
l1=[]
for i in range(1,6):
l=list(map(int,input().split()))
l1.append(l)
for i in l1:
for j in i:
if j!=0:
c=i.index(j)
r=l1.index(i)
m=abs(r-2)
m=m+abs(c-2)
print(m)
``` | 3 |
|
69 | A | Young Physicist | PROGRAMMING | 1,000 | [
"implementation",
"math"
] | A. Young Physicist | 2 | 256 | A guy named Vasya attends the final grade of a high school. One day Vasya decided to watch a match of his favorite hockey team. And, as the boy loves hockey very much, even more than physics, he forgot to do the homework. Specifically, he forgot to complete his physics tasks. Next day the teacher got very angry at Vasya and decided to teach him a lesson. He gave the lazy student a seemingly easy task: You are given an idle body in space and the forces that affect it. The body can be considered as a material point with coordinates (0; 0; 0). Vasya had only to answer whether it is in equilibrium. "Piece of cake" — thought Vasya, we need only to check if the sum of all vectors is equal to 0. So, Vasya began to solve the problem. But later it turned out that there can be lots and lots of these forces, and Vasya can not cope without your help. Help him. Write a program that determines whether a body is idle or is moving by the given vectors of forces. | The first line contains a positive integer *n* (1<=≤<=*n*<=≤<=100), then follow *n* lines containing three integers each: the *x**i* coordinate, the *y**i* coordinate and the *z**i* coordinate of the force vector, applied to the body (<=-<=100<=≤<=*x**i*,<=*y**i*,<=*z**i*<=≤<=100). | Print the word "YES" if the body is in equilibrium, or the word "NO" if it is not. | [
"3\n4 1 7\n-2 4 -1\n1 -5 -3\n",
"3\n3 -1 7\n-5 2 -4\n2 -1 -3\n"
] | [
"NO",
"YES"
] | none | 500 | [
{
"input": "3\n4 1 7\n-2 4 -1\n1 -5 -3",
"output": "NO"
},
{
"input": "3\n3 -1 7\n-5 2 -4\n2 -1 -3",
"output": "YES"
},
{
"input": "10\n21 32 -46\n43 -35 21\n42 2 -50\n22 40 20\n-27 -9 38\n-4 1 1\n-40 6 -31\n-13 -2 34\n-21 34 -12\n-32 -29 41",
"output": "NO"
},
{
"input": "10\n25 -33 43\n-27 -42 28\n-35 -20 19\n41 -42 -1\n49 -39 -4\n-49 -22 7\n-19 29 41\n8 -27 -43\n8 34 9\n-11 -3 33",
"output": "NO"
},
{
"input": "10\n-6 21 18\n20 -11 -8\n37 -11 41\n-5 8 33\n29 23 32\n30 -33 -11\n39 -49 -36\n28 34 -49\n22 29 -34\n-18 -6 7",
"output": "NO"
},
{
"input": "10\n47 -2 -27\n0 26 -14\n5 -12 33\n2 18 3\n45 -30 -49\n4 -18 8\n-46 -44 -41\n-22 -10 -40\n-35 -21 26\n33 20 38",
"output": "NO"
},
{
"input": "13\n-3 -36 -46\n-11 -50 37\n42 -11 -15\n9 42 44\n-29 -12 24\n3 9 -40\n-35 13 50\n14 43 18\n-13 8 24\n-48 -15 10\n50 9 -50\n21 0 -50\n0 0 -6",
"output": "YES"
},
{
"input": "14\n43 23 17\n4 17 44\n5 -5 -16\n-43 -7 -6\n47 -48 12\n50 47 -45\n2 14 43\n37 -30 15\n4 -17 -11\n17 9 -45\n-50 -3 -8\n-50 0 0\n-50 0 0\n-16 0 0",
"output": "YES"
},
{
"input": "13\n29 49 -11\n38 -11 -20\n25 1 -40\n-11 28 11\n23 -19 1\n45 -41 -17\n-3 0 -19\n-13 -33 49\n-30 0 28\n34 17 45\n-50 9 -27\n-50 0 0\n-37 0 0",
"output": "YES"
},
{
"input": "12\n3 28 -35\n-32 -44 -17\n9 -25 -6\n-42 -22 20\n-19 15 38\n-21 38 48\n-1 -37 -28\n-10 -13 -50\n-5 21 29\n34 28 50\n50 11 -49\n34 0 0",
"output": "YES"
},
{
"input": "37\n-64 -79 26\n-22 59 93\n-5 39 -12\n77 -9 76\n55 -86 57\n83 100 -97\n-70 94 84\n-14 46 -94\n26 72 35\n14 78 -62\n17 82 92\n-57 11 91\n23 15 92\n-80 -1 1\n12 39 18\n-23 -99 -75\n-34 50 19\n-39 84 -7\n45 -30 -39\n-60 49 37\n45 -16 -72\n33 -51 -56\n-48 28 5\n97 91 88\n45 -82 -11\n-21 -15 -90\n-53 73 -26\n-74 85 -90\n-40 23 38\n100 -13 49\n32 -100 -100\n0 -100 -70\n0 -100 0\n0 -100 0\n0 -100 0\n0 -100 0\n0 -37 0",
"output": "YES"
},
{
"input": "4\n68 3 100\n68 21 -100\n-100 -24 0\n-36 0 0",
"output": "YES"
},
{
"input": "33\n-1 -46 -12\n45 -16 -21\n-11 45 -21\n-60 -42 -93\n-22 -45 93\n37 96 85\n-76 26 83\n-4 9 55\n7 -52 -9\n66 8 -85\n-100 -54 11\n-29 59 74\n-24 12 2\n-56 81 85\n-92 69 -52\n-26 -97 91\n54 59 -51\n58 21 -57\n7 68 56\n-47 -20 -51\n-59 77 -13\n-85 27 91\n79 60 -56\n66 -80 5\n21 -99 42\n-31 -29 98\n66 93 76\n-49 45 61\n100 -100 -100\n100 -100 -100\n66 -75 -100\n0 0 -100\n0 0 -87",
"output": "YES"
},
{
"input": "3\n1 2 3\n3 2 1\n0 0 0",
"output": "NO"
},
{
"input": "2\n5 -23 12\n0 0 0",
"output": "NO"
},
{
"input": "1\n0 0 0",
"output": "YES"
},
{
"input": "1\n1 -2 0",
"output": "NO"
},
{
"input": "2\n-23 77 -86\n23 -77 86",
"output": "YES"
},
{
"input": "26\n86 7 20\n-57 -64 39\n-45 6 -93\n-44 -21 100\n-11 -49 21\n73 -71 -80\n-2 -89 56\n-65 -2 7\n5 14 84\n57 41 13\n-12 69 54\n40 -25 27\n-17 -59 0\n64 -91 -30\n-53 9 42\n-54 -8 14\n-35 82 27\n-48 -59 -80\n88 70 79\n94 57 97\n44 63 25\n84 -90 -40\n-100 100 -100\n-92 100 -100\n0 10 -100\n0 0 -82",
"output": "YES"
},
{
"input": "42\n11 27 92\n-18 -56 -57\n1 71 81\n33 -92 30\n82 83 49\n-87 -61 -1\n-49 45 49\n73 26 15\n-22 22 -77\n29 -93 87\n-68 44 -90\n-4 -84 20\n85 67 -6\n-39 26 77\n-28 -64 20\n65 -97 24\n-72 -39 51\n35 -75 -91\n39 -44 -8\n-25 -27 -57\n91 8 -46\n-98 -94 56\n94 -60 59\n-9 -95 18\n-53 -37 98\n-8 -94 -84\n-52 55 60\n15 -14 37\n65 -43 -25\n94 12 66\n-8 -19 -83\n29 81 -78\n-58 57 33\n24 86 -84\n-53 32 -88\n-14 7 3\n89 97 -53\n-5 -28 -91\n-100 100 -6\n-84 100 0\n0 100 0\n0 70 0",
"output": "YES"
},
{
"input": "3\n96 49 -12\n2 -66 28\n-98 17 -16",
"output": "YES"
},
{
"input": "5\n70 -46 86\n-100 94 24\n-27 63 -63\n57 -100 -47\n0 -11 0",
"output": "YES"
},
{
"input": "18\n-86 -28 70\n-31 -89 42\n31 -48 -55\n95 -17 -43\n24 -95 -85\n-21 -14 31\n68 -18 81\n13 31 60\n-15 28 99\n-42 15 9\n28 -61 -62\n-16 71 29\n-28 75 -48\n-77 -67 36\n-100 83 89\n100 100 -100\n57 34 -100\n0 0 -53",
"output": "YES"
},
{
"input": "44\n52 -54 -29\n-82 -5 -94\n-54 43 43\n91 16 71\n7 80 -91\n3 15 29\n-99 -6 -77\n-3 -77 -64\n73 67 34\n25 -10 -18\n-29 91 63\n-72 86 -16\n-68 85 -81\n-3 36 44\n-74 -14 -80\n34 -96 -97\n-76 -78 -33\n-24 44 -58\n98 12 77\n95 -63 -6\n-51 3 -90\n-92 -10 72\n7 3 -68\n57 -53 71\n29 57 -48\n35 -60 10\n79 -70 -61\n-20 77 55\n-86 -15 -35\n84 -88 -18\n100 -42 77\n-20 46 8\n-41 -43 -65\n38 -98 -23\n-100 65 45\n-7 -91 -63\n46 88 -85\n48 59 100\n0 0 100\n0 0 100\n0 0 100\n0 0 100\n0 0 100\n0 0 1",
"output": "YES"
},
{
"input": "18\n-14 -64 -91\n-8 -66 -86\n-23 92 -40\n6 -3 -53\n57 41 78\n-79 42 -22\n-88 -17 45\n4 -45 44\n83 -18 -25\n34 86 -92\n75 -30 12\n44 99 11\n-67 -13 72\n22 83 -56\n-37 71 72\n-9 -100 100\n0 -100 31\n0 -58 0",
"output": "YES"
},
{
"input": "23\n-70 37 78\n42 84 6\n28 -94 -24\n-49 76 95\n-67 18 84\n-53 78 -5\n65 -63 -64\n-66 -64 -69\n81 -93 95\n10 52 -79\n-89 -61 -64\n-64 -47 43\n-81 -35 55\n80 82 73\n-60 -81 -18\n49 -10 -19\n-58 70 12\n-24 -15 -93\n98 -93 -54\n-28 -75 11\n100 100 -63\n100 100 0\n56 34 0",
"output": "YES"
},
{
"input": "3\n0 2 -2\n1 -1 3\n-3 0 0",
"output": "NO"
}
] | 1,671,444,940 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 81 | 154 | 0 | n = int(input())
x = []
for i in range(n):
a, b, c = map(int, input().split())
x.append([a,b,c])
s = 0
m = 0
l = 0
for i in range(n):
s += x[i][0]
m += x[i][1]
l += x[i][2]
if s == 0 and m == 0 and l == 0:
print("YES")
else:
print("NO")
| Title: Young Physicist
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
A guy named Vasya attends the final grade of a high school. One day Vasya decided to watch a match of his favorite hockey team. And, as the boy loves hockey very much, even more than physics, he forgot to do the homework. Specifically, he forgot to complete his physics tasks. Next day the teacher got very angry at Vasya and decided to teach him a lesson. He gave the lazy student a seemingly easy task: You are given an idle body in space and the forces that affect it. The body can be considered as a material point with coordinates (0; 0; 0). Vasya had only to answer whether it is in equilibrium. "Piece of cake" — thought Vasya, we need only to check if the sum of all vectors is equal to 0. So, Vasya began to solve the problem. But later it turned out that there can be lots and lots of these forces, and Vasya can not cope without your help. Help him. Write a program that determines whether a body is idle or is moving by the given vectors of forces.
Input Specification:
The first line contains a positive integer *n* (1<=≤<=*n*<=≤<=100), then follow *n* lines containing three integers each: the *x**i* coordinate, the *y**i* coordinate and the *z**i* coordinate of the force vector, applied to the body (<=-<=100<=≤<=*x**i*,<=*y**i*,<=*z**i*<=≤<=100).
Output Specification:
Print the word "YES" if the body is in equilibrium, or the word "NO" if it is not.
Demo Input:
['3\n4 1 7\n-2 4 -1\n1 -5 -3\n', '3\n3 -1 7\n-5 2 -4\n2 -1 -3\n']
Demo Output:
['NO', 'YES']
Note:
none | ```python
n = int(input())
x = []
for i in range(n):
a, b, c = map(int, input().split())
x.append([a,b,c])
s = 0
m = 0
l = 0
for i in range(n):
s += x[i][0]
m += x[i][1]
l += x[i][2]
if s == 0 and m == 0 and l == 0:
print("YES")
else:
print("NO")
``` | 3.9615 |
981 | A | Antipalindrome | PROGRAMMING | 900 | [
"brute force",
"implementation",
"strings"
] | null | null | A string is a palindrome if it reads the same from the left to the right and from the right to the left. For example, the strings "kek", "abacaba", "r" and "papicipap" are palindromes, while the strings "abb" and "iq" are not.
A substring $s[l \ldots r]$ ($1<=\leq<=l<=\leq<=r<=\leq<=|s|$) of a string $s<==<=s_{1}s_{2} \ldots s_{|s|}$ is the string $s_{l}s_{l<=+<=1} \ldots s_{r}$.
Anna does not like palindromes, so she makes her friends call her Ann. She also changes all the words she reads in a similar way. Namely, each word $s$ is changed into its longest substring that is not a palindrome. If all the substrings of $s$ are palindromes, she skips the word at all.
Some time ago Ann read the word $s$. What is the word she changed it into? | The first line contains a non-empty string $s$ with length at most $50$ characters, containing lowercase English letters only. | If there is such a substring in $s$ that is not a palindrome, print the maximum length of such a substring. Otherwise print $0$.
Note that there can be multiple longest substrings that are not palindromes, but their length is unique. | [
"mew\n",
"wuffuw\n",
"qqqqqqqq\n"
] | [
"3\n",
"5\n",
"0\n"
] | "mew" is not a palindrome, so the longest substring of it that is not a palindrome, is the string "mew" itself. Thus, the answer for the first example is $3$.
The string "uffuw" is one of the longest non-palindrome substrings (of length $5$) of the string "wuffuw", so the answer for the second example is $5$.
All substrings of the string "qqqqqqqq" consist of equal characters so they are palindromes. This way, there are no non-palindrome substrings. Thus, the answer for the third example is $0$. | 500 | [
{
"input": "mew",
"output": "3"
},
{
"input": "wuffuw",
"output": "5"
},
{
"input": "qqqqqqqq",
"output": "0"
},
{
"input": "ijvji",
"output": "4"
},
{
"input": "iiiiiii",
"output": "0"
},
{
"input": "wobervhvvkihcuyjtmqhaaigvvgiaahqmtjyuchikvvhvrebow",
"output": "49"
},
{
"input": "wwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwww",
"output": "0"
},
{
"input": "wobervhvvkihcuyjtmqhaaigvahheoqleromusrartldojsjvy",
"output": "50"
},
{
"input": "ijvxljt",
"output": "7"
},
{
"input": "fyhcncnchyf",
"output": "10"
},
{
"input": "ffffffffffff",
"output": "0"
},
{
"input": "fyhcncfsepqj",
"output": "12"
},
{
"input": "ybejrrlbcinttnicblrrjeby",
"output": "23"
},
{
"input": "yyyyyyyyyyyyyyyyyyyyyyyyy",
"output": "0"
},
{
"input": "ybejrrlbcintahovgjddrqatv",
"output": "25"
},
{
"input": "oftmhcmclgyqaojljoaqyglcmchmtfo",
"output": "30"
},
{
"input": "oooooooooooooooooooooooooooooooo",
"output": "0"
},
{
"input": "oftmhcmclgyqaojllbotztajglsmcilv",
"output": "32"
},
{
"input": "gxandbtgpbknxvnkjaajknvxnkbpgtbdnaxg",
"output": "35"
},
{
"input": "gggggggggggggggggggggggggggggggggggg",
"output": "0"
},
{
"input": "gxandbtgpbknxvnkjaygommzqitqzjfalfkk",
"output": "36"
},
{
"input": "fcliblymyqckxvieotjooojtoeivxkcqymylbilcf",
"output": "40"
},
{
"input": "fffffffffffffffffffffffffffffffffffffffffff",
"output": "0"
},
{
"input": "fcliblymyqckxvieotjootiqwtyznhhvuhbaixwqnsy",
"output": "43"
},
{
"input": "rrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr",
"output": "0"
},
{
"input": "rajccqwqnqmshmerpvjyfepxwpxyldzpzhctqjnstxyfmlhiy",
"output": "49"
},
{
"input": "a",
"output": "0"
},
{
"input": "abca",
"output": "4"
},
{
"input": "aaaaabaaaaa",
"output": "10"
},
{
"input": "aba",
"output": "2"
},
{
"input": "asaa",
"output": "4"
},
{
"input": "aabaa",
"output": "4"
},
{
"input": "aabbaa",
"output": "5"
},
{
"input": "abcdaaa",
"output": "7"
},
{
"input": "aaholaa",
"output": "7"
},
{
"input": "abcdefghijka",
"output": "12"
},
{
"input": "aaadcba",
"output": "7"
},
{
"input": "aaaabaaaa",
"output": "8"
},
{
"input": "abaa",
"output": "4"
},
{
"input": "abcbaa",
"output": "6"
},
{
"input": "ab",
"output": "2"
},
{
"input": "l",
"output": "0"
},
{
"input": "aaaabcaaaa",
"output": "10"
},
{
"input": "abbaaaaaabba",
"output": "11"
},
{
"input": "abaaa",
"output": "5"
},
{
"input": "baa",
"output": "3"
},
{
"input": "aaaaaaabbba",
"output": "11"
},
{
"input": "ccbcc",
"output": "4"
},
{
"input": "bbbaaab",
"output": "7"
},
{
"input": "abaaaaaaaa",
"output": "10"
},
{
"input": "abaaba",
"output": "5"
},
{
"input": "aabsdfaaaa",
"output": "10"
},
{
"input": "aaaba",
"output": "5"
},
{
"input": "aaabaaa",
"output": "6"
},
{
"input": "baaabbb",
"output": "7"
},
{
"input": "ccbbabbcc",
"output": "8"
},
{
"input": "cabc",
"output": "4"
},
{
"input": "aabcd",
"output": "5"
},
{
"input": "abcdea",
"output": "6"
},
{
"input": "bbabb",
"output": "4"
},
{
"input": "aaaaabababaaaaa",
"output": "14"
},
{
"input": "bbabbb",
"output": "6"
},
{
"input": "aababd",
"output": "6"
},
{
"input": "abaaaa",
"output": "6"
},
{
"input": "aaaaaaaabbba",
"output": "12"
},
{
"input": "aabca",
"output": "5"
},
{
"input": "aaabccbaaa",
"output": "9"
},
{
"input": "aaaaaaaaaaaaaaaaaaaab",
"output": "21"
},
{
"input": "babb",
"output": "4"
},
{
"input": "abcaa",
"output": "5"
},
{
"input": "qwqq",
"output": "4"
},
{
"input": "aaaaaaaaaaabbbbbbbbbbbbbbbaaaaaaaaaaaaaaaaaaaaaa",
"output": "48"
},
{
"input": "aaab",
"output": "4"
},
{
"input": "aaaaaabaaaaa",
"output": "12"
},
{
"input": "wwuww",
"output": "4"
},
{
"input": "aaaaabcbaaaaa",
"output": "12"
},
{
"input": "aaabbbaaa",
"output": "8"
},
{
"input": "aabcbaa",
"output": "6"
},
{
"input": "abccdefccba",
"output": "11"
},
{
"input": "aabbcbbaa",
"output": "8"
},
{
"input": "aaaabbaaaa",
"output": "9"
},
{
"input": "aabcda",
"output": "6"
},
{
"input": "abbca",
"output": "5"
},
{
"input": "aaaaaabbaaa",
"output": "11"
},
{
"input": "sssssspssssss",
"output": "12"
},
{
"input": "sdnmsdcs",
"output": "8"
},
{
"input": "aaabbbccbbbaaa",
"output": "13"
},
{
"input": "cbdbdc",
"output": "6"
},
{
"input": "abb",
"output": "3"
},
{
"input": "abcdefaaaa",
"output": "10"
},
{
"input": "abbbaaa",
"output": "7"
},
{
"input": "v",
"output": "0"
},
{
"input": "abccbba",
"output": "7"
},
{
"input": "axyza",
"output": "5"
},
{
"input": "abcdefgaaaa",
"output": "11"
},
{
"input": "aaabcdaaa",
"output": "9"
},
{
"input": "aaaacaaaa",
"output": "8"
},
{
"input": "aaaaaaaaaaaaaaaaaaaabaaaaaaaaaaaaaaaaaaaaa",
"output": "42"
},
{
"input": "abbbaa",
"output": "6"
},
{
"input": "abcdee",
"output": "6"
},
{
"input": "oom",
"output": "3"
},
{
"input": "aabcaa",
"output": "6"
},
{
"input": "abba",
"output": "3"
},
{
"input": "aaca",
"output": "4"
},
{
"input": "aacbca",
"output": "6"
},
{
"input": "ababa",
"output": "4"
},
{
"input": "abcda",
"output": "5"
},
{
"input": "cccaaccc",
"output": "7"
},
{
"input": "aaabcda",
"output": "7"
},
{
"input": "aa",
"output": "0"
},
{
"input": "aabaaaa",
"output": "7"
},
{
"input": "abbaaaa",
"output": "7"
},
{
"input": "aaabcbaaa",
"output": "8"
},
{
"input": "aabba",
"output": "5"
},
{
"input": "xyxx",
"output": "4"
},
{
"input": "aaaaaaaaaaaabc",
"output": "14"
},
{
"input": "bbaaaabb",
"output": "7"
},
{
"input": "aaabaa",
"output": "6"
},
{
"input": "sssssabsssss",
"output": "12"
},
{
"input": "bbbaaaabbb",
"output": "9"
},
{
"input": "abbbbaaaa",
"output": "9"
},
{
"input": "wwufuww",
"output": "6"
},
{
"input": "oowoo",
"output": "4"
},
{
"input": "cccaccc",
"output": "6"
},
{
"input": "aaa",
"output": "0"
},
{
"input": "bbbcc",
"output": "5"
},
{
"input": "abcdef",
"output": "6"
},
{
"input": "abbba",
"output": "4"
},
{
"input": "aab",
"output": "3"
},
{
"input": "aaba",
"output": "4"
},
{
"input": "azbyaaa",
"output": "7"
},
{
"input": "oooooiooooo",
"output": "10"
},
{
"input": "aabbbbbaaaaaa",
"output": "13"
}
] | 1,638,956,940 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 133 | 109 | 512,000 | """https://codeforces.com/problemset/problem/981/A
"""
s = input()
for r in range(len(s), 1, -1):
if s[:r] != s[r - 1::-1]:
print(r)
break
else:
print(0)
| Title: Antipalindrome
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A string is a palindrome if it reads the same from the left to the right and from the right to the left. For example, the strings "kek", "abacaba", "r" and "papicipap" are palindromes, while the strings "abb" and "iq" are not.
A substring $s[l \ldots r]$ ($1<=\leq<=l<=\leq<=r<=\leq<=|s|$) of a string $s<==<=s_{1}s_{2} \ldots s_{|s|}$ is the string $s_{l}s_{l<=+<=1} \ldots s_{r}$.
Anna does not like palindromes, so she makes her friends call her Ann. She also changes all the words she reads in a similar way. Namely, each word $s$ is changed into its longest substring that is not a palindrome. If all the substrings of $s$ are palindromes, she skips the word at all.
Some time ago Ann read the word $s$. What is the word she changed it into?
Input Specification:
The first line contains a non-empty string $s$ with length at most $50$ characters, containing lowercase English letters only.
Output Specification:
If there is such a substring in $s$ that is not a palindrome, print the maximum length of such a substring. Otherwise print $0$.
Note that there can be multiple longest substrings that are not palindromes, but their length is unique.
Demo Input:
['mew\n', 'wuffuw\n', 'qqqqqqqq\n']
Demo Output:
['3\n', '5\n', '0\n']
Note:
"mew" is not a palindrome, so the longest substring of it that is not a palindrome, is the string "mew" itself. Thus, the answer for the first example is $3$.
The string "uffuw" is one of the longest non-palindrome substrings (of length $5$) of the string "wuffuw", so the answer for the second example is $5$.
All substrings of the string "qqqqqqqq" consist of equal characters so they are palindromes. This way, there are no non-palindrome substrings. Thus, the answer for the third example is $0$. | ```python
"""https://codeforces.com/problemset/problem/981/A
"""
s = input()
for r in range(len(s), 1, -1):
if s[:r] != s[r - 1::-1]:
print(r)
break
else:
print(0)
``` | 3 |
|
505 | A | Mr. Kitayuta's Gift | PROGRAMMING | 1,100 | [
"brute force",
"implementation",
"strings"
] | null | null | Mr. Kitayuta has kindly given you a string *s* consisting of lowercase English letters. You are asked to insert exactly one lowercase English letter into *s* to make it a palindrome. A palindrome is a string that reads the same forward and backward. For example, "noon", "testset" and "a" are all palindromes, while "test" and "kitayuta" are not.
You can choose any lowercase English letter, and insert it to any position of *s*, possibly to the beginning or the end of *s*. You have to insert a letter even if the given string is already a palindrome.
If it is possible to insert one lowercase English letter into *s* so that the resulting string will be a palindrome, print the string after the insertion. Otherwise, print "NA" (without quotes, case-sensitive). In case there is more than one palindrome that can be obtained, you are allowed to print any of them. | The only line of the input contains a string *s* (1<=≤<=|*s*|<=≤<=10). Each character in *s* is a lowercase English letter. | If it is possible to turn *s* into a palindrome by inserting one lowercase English letter, print the resulting string in a single line. Otherwise, print "NA" (without quotes, case-sensitive). In case there is more than one solution, any of them will be accepted. | [
"revive\n",
"ee\n",
"kitayuta\n"
] | [
"reviver\n",
"eye",
"NA\n"
] | For the first sample, insert 'r' to the end of "revive" to obtain a palindrome "reviver".
For the second sample, there is more than one solution. For example, "eve" will also be accepted.
For the third sample, it is not possible to turn "kitayuta" into a palindrome by just inserting one letter. | 500 | [
{
"input": "revive",
"output": "reviver"
},
{
"input": "ee",
"output": "eee"
},
{
"input": "kitayuta",
"output": "NA"
},
{
"input": "evima",
"output": "NA"
},
{
"input": "a",
"output": "aa"
},
{
"input": "yutampo",
"output": "NA"
},
{
"input": "fft",
"output": "tfft"
},
{
"input": "shuseki",
"output": "NA"
},
{
"input": "lsdijfjisl",
"output": "lsdijfjidsl"
},
{
"input": "ewcdcwerp",
"output": "NA"
},
{
"input": "noon",
"output": "nooon"
},
{
"input": "add",
"output": "adda"
},
{
"input": "iq",
"output": "qiq"
},
{
"input": "hogloid",
"output": "NA"
},
{
"input": "yosupo",
"output": "NA"
},
{
"input": "stat",
"output": "stats"
},
{
"input": "level",
"output": "levvel"
},
{
"input": "iwiwi",
"output": "iwiiwi"
},
{
"input": "racecar",
"output": "raceecar"
},
{
"input": "dog",
"output": "NA"
},
{
"input": "squirrel",
"output": "NA"
},
{
"input": "slime",
"output": "NA"
},
{
"input": "palindrome",
"output": "NA"
},
{
"input": "nqwcvcwqn",
"output": "nqwcvvcwqn"
},
{
"input": "lsdijfjisl",
"output": "lsdijfjidsl"
},
{
"input": "jewiiwefj",
"output": "jfewiiwefj"
},
{
"input": "vnwmvvmonv",
"output": "NA"
},
{
"input": "zennyuu",
"output": "NA"
},
{
"input": "mrtoudai",
"output": "NA"
},
{
"input": "z",
"output": "zz"
},
{
"input": "babccba",
"output": "babccbab"
},
{
"input": "battaba",
"output": "abattaba"
},
{
"input": "bbb",
"output": "bbbb"
},
{
"input": "zaa",
"output": "zaaz"
},
{
"input": "abbabab",
"output": "NA"
},
{
"input": "racecar",
"output": "raceecar"
},
{
"input": "zzz",
"output": "zzzz"
},
{
"input": "eviver",
"output": "reviver"
},
{
"input": "aaaaa",
"output": "aaaaaa"
},
{
"input": "eee",
"output": "eeee"
}
] | 1,556,375,686 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 93 | 0 | s = input()
n = len(s)
i, j = 0, n-1
cnt = 0
if s == s[::-1]:
k = n//2
print(s[:k+1] + s[k:])
exit()
while(i < j):
if s[i] == s[j]:
i += 1
j -= 1
else:
s = s[:j+1] + s[i] + s[j+1:]
i += 1
if len(s) > n + 1: print('NA'); break
if n + 1 != len(s) and n != len(s):
print('NA')
else:
print(s)
| Title: Mr. Kitayuta's Gift
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Mr. Kitayuta has kindly given you a string *s* consisting of lowercase English letters. You are asked to insert exactly one lowercase English letter into *s* to make it a palindrome. A palindrome is a string that reads the same forward and backward. For example, "noon", "testset" and "a" are all palindromes, while "test" and "kitayuta" are not.
You can choose any lowercase English letter, and insert it to any position of *s*, possibly to the beginning or the end of *s*. You have to insert a letter even if the given string is already a palindrome.
If it is possible to insert one lowercase English letter into *s* so that the resulting string will be a palindrome, print the string after the insertion. Otherwise, print "NA" (without quotes, case-sensitive). In case there is more than one palindrome that can be obtained, you are allowed to print any of them.
Input Specification:
The only line of the input contains a string *s* (1<=≤<=|*s*|<=≤<=10). Each character in *s* is a lowercase English letter.
Output Specification:
If it is possible to turn *s* into a palindrome by inserting one lowercase English letter, print the resulting string in a single line. Otherwise, print "NA" (without quotes, case-sensitive). In case there is more than one solution, any of them will be accepted.
Demo Input:
['revive\n', 'ee\n', 'kitayuta\n']
Demo Output:
['reviver\n', 'eye', 'NA\n']
Note:
For the first sample, insert 'r' to the end of "revive" to obtain a palindrome "reviver".
For the second sample, there is more than one solution. For example, "eve" will also be accepted.
For the third sample, it is not possible to turn "kitayuta" into a palindrome by just inserting one letter. | ```python
s = input()
n = len(s)
i, j = 0, n-1
cnt = 0
if s == s[::-1]:
k = n//2
print(s[:k+1] + s[k:])
exit()
while(i < j):
if s[i] == s[j]:
i += 1
j -= 1
else:
s = s[:j+1] + s[i] + s[j+1:]
i += 1
if len(s) > n + 1: print('NA'); break
if n + 1 != len(s) and n != len(s):
print('NA')
else:
print(s)
``` | 0 |
|
854 | A | Fraction | PROGRAMMING | 800 | [
"brute force",
"constructive algorithms",
"math"
] | null | null | Petya is a big fan of mathematics, especially its part related to fractions. Recently he learned that a fraction is called proper iff its numerator is smaller than its denominator (*a*<=<<=*b*) and that the fraction is called irreducible if its numerator and its denominator are coprime (they do not have positive common divisors except 1).
During his free time, Petya thinks about proper irreducible fractions and converts them to decimals using the calculator. One day he mistakenly pressed addition button (<=+<=) instead of division button (÷) and got sum of numerator and denominator that was equal to *n* instead of the expected decimal notation.
Petya wanted to restore the original fraction, but soon he realized that it might not be done uniquely. That's why he decided to determine maximum possible proper irreducible fraction such that sum of its numerator and denominator equals *n*. Help Petya deal with this problem. | In the only line of input there is an integer *n* (3<=≤<=*n*<=≤<=1000), the sum of numerator and denominator of the fraction. | Output two space-separated positive integers *a* and *b*, numerator and denominator of the maximum possible proper irreducible fraction satisfying the given sum. | [
"3\n",
"4\n",
"12\n"
] | [
"1 2\n",
"1 3\n",
"5 7\n"
] | none | 500 | [
{
"input": "3",
"output": "1 2"
},
{
"input": "4",
"output": "1 3"
},
{
"input": "12",
"output": "5 7"
},
{
"input": "34",
"output": "15 19"
},
{
"input": "13",
"output": "6 7"
},
{
"input": "11",
"output": "5 6"
},
{
"input": "24",
"output": "11 13"
},
{
"input": "17",
"output": "8 9"
},
{
"input": "10",
"output": "3 7"
},
{
"input": "69",
"output": "34 35"
},
{
"input": "100",
"output": "49 51"
},
{
"input": "57",
"output": "28 29"
},
{
"input": "1000",
"output": "499 501"
},
{
"input": "999",
"output": "499 500"
},
{
"input": "998",
"output": "497 501"
},
{
"input": "997",
"output": "498 499"
},
{
"input": "996",
"output": "497 499"
},
{
"input": "995",
"output": "497 498"
},
{
"input": "994",
"output": "495 499"
},
{
"input": "5",
"output": "2 3"
},
{
"input": "6",
"output": "1 5"
},
{
"input": "8",
"output": "3 5"
},
{
"input": "9",
"output": "4 5"
},
{
"input": "423",
"output": "211 212"
},
{
"input": "876",
"output": "437 439"
},
{
"input": "29",
"output": "14 15"
}
] | 1,613,645,596 | 2,147,483,647 | Python 3 | OK | TESTS | 26 | 62 | 0 | n=int(input())
m=n//2
switcher={
0:[m-1,m+1],
1:[m,m+1],
2:[m-2,m+2],
3:[m,m+1],
}
ans=switcher.get(n%4)
print(ans[0],ans[1])
| Title: Fraction
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Petya is a big fan of mathematics, especially its part related to fractions. Recently he learned that a fraction is called proper iff its numerator is smaller than its denominator (*a*<=<<=*b*) and that the fraction is called irreducible if its numerator and its denominator are coprime (they do not have positive common divisors except 1).
During his free time, Petya thinks about proper irreducible fractions and converts them to decimals using the calculator. One day he mistakenly pressed addition button (<=+<=) instead of division button (÷) and got sum of numerator and denominator that was equal to *n* instead of the expected decimal notation.
Petya wanted to restore the original fraction, but soon he realized that it might not be done uniquely. That's why he decided to determine maximum possible proper irreducible fraction such that sum of its numerator and denominator equals *n*. Help Petya deal with this problem.
Input Specification:
In the only line of input there is an integer *n* (3<=≤<=*n*<=≤<=1000), the sum of numerator and denominator of the fraction.
Output Specification:
Output two space-separated positive integers *a* and *b*, numerator and denominator of the maximum possible proper irreducible fraction satisfying the given sum.
Demo Input:
['3\n', '4\n', '12\n']
Demo Output:
['1 2\n', '1 3\n', '5 7\n']
Note:
none | ```python
n=int(input())
m=n//2
switcher={
0:[m-1,m+1],
1:[m,m+1],
2:[m-2,m+2],
3:[m,m+1],
}
ans=switcher.get(n%4)
print(ans[0],ans[1])
``` | 3 |