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
|
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
540 | A | Combination Lock | PROGRAMMING | 800 | [
"implementation"
] | null | null | Scrooge McDuck keeps his most treasured savings in a home safe with a combination lock. Each time he wants to put there the treasures that he's earned fair and square, he has to open the lock.
The combination lock is represented by *n* rotating disks with digits from 0 to 9 written on them. Scrooge McDuck has to turn some disks so that the combination of digits on the disks forms a secret combination. In one move, he can rotate one disk one digit forwards or backwards. In particular, in one move he can go from digit 0 to digit 9 and vice versa. What minimum number of actions does he need for that? | The first line contains a single integer *n* (1<=≤<=*n*<=≤<=1000) — the number of disks on the combination lock.
The second line contains a string of *n* digits — the original state of the disks.
The third line contains a string of *n* digits — Scrooge McDuck's combination that opens the lock. | Print a single integer — the minimum number of moves Scrooge McDuck needs to open the lock. | [
"5\n82195\n64723\n"
] | [
"13\n"
] | In the sample he needs 13 moves:
- 1 disk: <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/b8967f65a723782358b93eff9ce69f336817cf70.png" style="max-width: 100.0%;max-height: 100.0%;"/> - 2 disk: <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/07fa58573ece0d32c4d555e498d2b24d2f70f36a.png" style="max-width: 100.0%;max-height: 100.0%;"/> - 3 disk: <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/cc2275d9252aae35a6867c6a5b4ba7596e9a7626.png" style="max-width: 100.0%;max-height: 100.0%;"/> - 4 disk: <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/b100aea470fcaaab4e9529b234ba0d7875943c10.png" style="max-width: 100.0%;max-height: 100.0%;"/> - 5 disk: <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/eb2cbe4324cebca65b85816262a85e473cd65967.png" style="max-width: 100.0%;max-height: 100.0%;"/> | 500 | [
{
"input": "5\n82195\n64723",
"output": "13"
},
{
"input": "12\n102021090898\n010212908089",
"output": "16"
},
{
"input": "1\n8\n1",
"output": "3"
},
{
"input": "2\n83\n57",
"output": "7"
},
{
"input": "10\n0728592530\n1362615763",
"output": "27"
},
{
"input": "100\n4176196363694273682807653052945037727131821799902563705176501742060696655282954944720643131654235909\n3459912084922154505910287499879975659298239371519889866585472674423008837878123067103005344986554746",
"output": "245"
},
{
"input": "1\n8\n1",
"output": "3"
},
{
"input": "2\n83\n57",
"output": "7"
},
{
"input": "3\n607\n684",
"output": "5"
},
{
"input": "4\n0809\n0636",
"output": "8"
},
{
"input": "5\n84284\n08941",
"output": "16"
},
{
"input": "25\n8037856825987124762280548\n9519431339078678836940020",
"output": "72"
},
{
"input": "125\n23269567683904664184142384849516523616863461607751021071772615078579713054027902974007001544768640273491193035874486891541257\n47635110303703399505805044019026243695451609639556649012447370081552870340011971572363458960190590266459684717415349529509024",
"output": "305"
},
{
"input": "5\n84284\n08941",
"output": "16"
},
{
"input": "25\n8037856825987124762285484\n9519431339078678836940202",
"output": "74"
},
{
"input": "125\n23269567689466418414238845152168634610771021717726157879713054270294007001544768647391193035874486891412573389247025830678706\n47635110307339950580504010224954516093956649124473708152870340117152363458960190596659684717415349529090241694059599629136831",
"output": "357"
},
{
"input": "5\n84284\n08941",
"output": "16"
},
{
"input": "25\n8378525987476228048406972\n9194339078883694020217816",
"output": "55"
},
{
"input": "125\n23269576839046618414238484916523616863461607750210717761078579713054027902974007015447686027349193035874486891541257338624472\n47635103037033950580504401926243695451609639556490124437081552870340011971572363489601905026645984717415349529509024169604599",
"output": "274"
},
{
"input": "1\n0\n0",
"output": "0"
},
{
"input": "1\n7\n7",
"output": "0"
},
{
"input": "1\n0\n5",
"output": "5"
},
{
"input": "1\n2\n7",
"output": "5"
},
{
"input": "1\n7\n9",
"output": "2"
},
{
"input": "1\n9\n7",
"output": "2"
},
{
"input": "1\n2\n9",
"output": "3"
},
{
"input": "1\n9\n2",
"output": "3"
},
{
"input": "25\n3164978461316464614169874\n9413979197249127496597357",
"output": "66"
},
{
"input": "4\n9999\n9999",
"output": "0"
},
{
"input": "2\n11\n11",
"output": "0"
}
] | 1,659,213,165 | 2,147,483,647 | Python 3 | OK | TESTS | 43 | 46 | 0 | n = int(input())
s1 = input()
s2 = input()
z = 0
for i in range(n):
one = int(s1[i]) - int(s2[i])
two = int(s2[i]) - int(s1[i])
if one < 0:
one += 10
if two < 0:
two += 10
z += min(one, two)
print(z)
| Title: Combination Lock
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Scrooge McDuck keeps his most treasured savings in a home safe with a combination lock. Each time he wants to put there the treasures that he's earned fair and square, he has to open the lock.
The combination lock is represented by *n* rotating disks with digits from 0 to 9 written on them. Scrooge McDuck has to turn some disks so that the combination of digits on the disks forms a secret combination. In one move, he can rotate one disk one digit forwards or backwards. In particular, in one move he can go from digit 0 to digit 9 and vice versa. What minimum number of actions does he need for that?
Input Specification:
The first line contains a single integer *n* (1<=≤<=*n*<=≤<=1000) — the number of disks on the combination lock.
The second line contains a string of *n* digits — the original state of the disks.
The third line contains a string of *n* digits — Scrooge McDuck's combination that opens the lock.
Output Specification:
Print a single integer — the minimum number of moves Scrooge McDuck needs to open the lock.
Demo Input:
['5\n82195\n64723\n']
Demo Output:
['13\n']
Note:
In the sample he needs 13 moves:
- 1 disk: <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/b8967f65a723782358b93eff9ce69f336817cf70.png" style="max-width: 100.0%;max-height: 100.0%;"/> - 2 disk: <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/07fa58573ece0d32c4d555e498d2b24d2f70f36a.png" style="max-width: 100.0%;max-height: 100.0%;"/> - 3 disk: <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/cc2275d9252aae35a6867c6a5b4ba7596e9a7626.png" style="max-width: 100.0%;max-height: 100.0%;"/> - 4 disk: <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/b100aea470fcaaab4e9529b234ba0d7875943c10.png" style="max-width: 100.0%;max-height: 100.0%;"/> - 5 disk: <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/eb2cbe4324cebca65b85816262a85e473cd65967.png" style="max-width: 100.0%;max-height: 100.0%;"/> | ```python
n = int(input())
s1 = input()
s2 = input()
z = 0
for i in range(n):
one = int(s1[i]) - int(s2[i])
two = int(s2[i]) - int(s1[i])
if one < 0:
one += 10
if two < 0:
two += 10
z += min(one, two)
print(z)
``` | 3 |
|
551 | A | GukiZ and Contest | PROGRAMMING | 800 | [
"brute force",
"implementation",
"sortings"
] | null | null | Professor GukiZ likes programming contests. He especially likes to rate his students on the contests he prepares. Now, he has decided to prepare a new contest.
In total, *n* students will attend, and before the start, every one of them has some positive integer rating. Students are indexed from 1 to *n*. Let's denote the rating of *i*-th student as *a**i*. After the contest ends, every student will end up with some positive integer position. GukiZ expects that his students will take places according to their ratings.
He thinks that each student will take place equal to . In particular, if student *A* has rating strictly lower then student *B*, *A* will get the strictly better position than *B*, and if two students have equal ratings, they will share the same position.
GukiZ would like you to reconstruct the results by following his expectations. Help him and determine the position after the end of the contest for each of his students if everything goes as expected. | The first line contains integer *n* (1<=≤<=*n*<=≤<=2000), number of GukiZ's students.
The second line contains *n* numbers *a*1,<=*a*2,<=... *a**n* (1<=≤<=*a**i*<=≤<=2000) where *a**i* is the rating of *i*-th student (1<=≤<=*i*<=≤<=*n*). | In a single line, print the position after the end of the contest for each of *n* students in the same order as they appear in the input. | [
"3\n1 3 3\n",
"1\n1\n",
"5\n3 5 3 4 5\n"
] | [
"3 1 1\n",
"1\n",
"4 1 4 3 1\n"
] | In the first sample, students 2 and 3 are positioned first (there is no other student with higher rating), and student 1 is positioned third since there are two students with higher rating.
In the second sample, first student is the only one on the contest.
In the third sample, students 2 and 5 share the first position with highest rating, student 4 is next with third position, and students 1 and 3 are the last sharing fourth position. | 500 | [
{
"input": "3\n1 3 3",
"output": "3 1 1"
},
{
"input": "1\n1",
"output": "1"
},
{
"input": "5\n3 5 3 4 5",
"output": "4 1 4 3 1"
},
{
"input": "7\n1 3 5 4 2 2 1",
"output": "6 3 1 2 4 4 6"
},
{
"input": "11\n5 6 4 2 9 7 6 6 6 6 7",
"output": "9 4 10 11 1 2 4 4 4 4 2"
},
{
"input": "1\n2000",
"output": "1"
},
{
"input": "2\n2000 2000",
"output": "1 1"
},
{
"input": "3\n500 501 502",
"output": "3 2 1"
},
{
"input": "10\n105 106 1 1 1 11 1000 999 1000 999",
"output": "6 5 8 8 8 7 1 3 1 3"
},
{
"input": "6\n1 2 3 4 5 6",
"output": "6 5 4 3 2 1"
},
{
"input": "7\n6 5 4 3 2 1 1",
"output": "1 2 3 4 5 6 6"
},
{
"input": "8\n153 100 87 14 10 8 6 5",
"output": "1 2 3 4 5 6 7 8"
},
{
"input": "70\n11 54 37 62 1 46 13 17 38 47 28 15 63 5 61 34 49 66 32 59 3 41 58 28 23 62 41 64 20 5 14 41 10 37 51 32 65 46 61 8 15 19 16 44 31 42 19 46 66 25 26 58 60 5 19 18 69 53 20 40 45 27 24 41 32 23 57 56 62 10",
"output": "62 18 35 7 70 23 61 56 34 22 42 58 6 66 10 37 21 2 38 13 69 29 14 42 48 7 29 5 50 66 60 29 63 35 20 38 4 23 10 65 58 52 57 27 41 28 52 23 2 46 45 14 12 66 52 55 1 19 50 33 26 44 47 29 38 48 16 17 7 63"
},
{
"input": "5\n1 2000 1 1 2000",
"output": "3 1 3 3 1"
}
] | 1,447,412,096 | 2,147,483,647 | Python 3 | OK | TESTS | 36 | 62 | 512,000 |
n=int(input())
arr=list(map(int,input().split()))
s=sorted(arr,reverse=True)
dic={}
t=1
for i in s:
if i not in dic:
dic[i]=t
t+=1
for i in arr:
print(dic[i])
| Title: GukiZ and Contest
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Professor GukiZ likes programming contests. He especially likes to rate his students on the contests he prepares. Now, he has decided to prepare a new contest.
In total, *n* students will attend, and before the start, every one of them has some positive integer rating. Students are indexed from 1 to *n*. Let's denote the rating of *i*-th student as *a**i*. After the contest ends, every student will end up with some positive integer position. GukiZ expects that his students will take places according to their ratings.
He thinks that each student will take place equal to . In particular, if student *A* has rating strictly lower then student *B*, *A* will get the strictly better position than *B*, and if two students have equal ratings, they will share the same position.
GukiZ would like you to reconstruct the results by following his expectations. Help him and determine the position after the end of the contest for each of his students if everything goes as expected.
Input Specification:
The first line contains integer *n* (1<=≤<=*n*<=≤<=2000), number of GukiZ's students.
The second line contains *n* numbers *a*1,<=*a*2,<=... *a**n* (1<=≤<=*a**i*<=≤<=2000) where *a**i* is the rating of *i*-th student (1<=≤<=*i*<=≤<=*n*).
Output Specification:
In a single line, print the position after the end of the contest for each of *n* students in the same order as they appear in the input.
Demo Input:
['3\n1 3 3\n', '1\n1\n', '5\n3 5 3 4 5\n']
Demo Output:
['3 1 1\n', '1\n', '4 1 4 3 1\n']
Note:
In the first sample, students 2 and 3 are positioned first (there is no other student with higher rating), and student 1 is positioned third since there are two students with higher rating.
In the second sample, first student is the only one on the contest.
In the third sample, students 2 and 5 share the first position with highest rating, student 4 is next with third position, and students 1 and 3 are the last sharing fourth position. | ```python
n=int(input())
arr=list(map(int,input().split()))
s=sorted(arr,reverse=True)
dic={}
t=1
for i in s:
if i not in dic:
dic[i]=t
t+=1
for i in arr:
print(dic[i])
``` | 3 |
|
557 | A | Ilya and Diplomas | PROGRAMMING | 1,100 | [
"greedy",
"implementation",
"math"
] | null | null | Soon a school Olympiad in Informatics will be held in Berland, *n* schoolchildren will participate there.
At a meeting of the jury of the Olympiad it was decided that each of the *n* participants, depending on the results, will get a diploma of the first, second or third degree. Thus, each student will receive exactly one diploma.
They also decided that there must be given at least *min*1 and at most *max*1 diplomas of the first degree, at least *min*2 and at most *max*2 diplomas of the second degree, and at least *min*3 and at most *max*3 diplomas of the third degree.
After some discussion it was decided to choose from all the options of distributing diplomas satisfying these limitations the one that maximizes the number of participants who receive diplomas of the first degree. Of all these options they select the one which maximizes the number of the participants who receive diplomas of the second degree. If there are multiple of these options, they select the option that maximizes the number of diplomas of the third degree.
Choosing the best option of distributing certificates was entrusted to Ilya, one of the best programmers of Berland. However, he found more important things to do, so it is your task now to choose the best option of distributing of diplomas, based on the described limitations.
It is guaranteed that the described limitations are such that there is a way to choose such an option of distributing diplomas that all *n* participants of the Olympiad will receive a diploma of some degree. | The first line of the input contains a single integer *n* (3<=≤<=*n*<=≤<=3·106) — the number of schoolchildren who will participate in the Olympiad.
The next line of the input contains two integers *min*1 and *max*1 (1<=≤<=*min*1<=≤<=*max*1<=≤<=106) — the minimum and maximum limits on the number of diplomas of the first degree that can be distributed.
The third line of the input contains two integers *min*2 and *max*2 (1<=≤<=*min*2<=≤<=*max*2<=≤<=106) — the minimum and maximum limits on the number of diplomas of the second degree that can be distributed.
The next line of the input contains two integers *min*3 and *max*3 (1<=≤<=*min*3<=≤<=*max*3<=≤<=106) — the minimum and maximum limits on the number of diplomas of the third degree that can be distributed.
It is guaranteed that *min*1<=+<=*min*2<=+<=*min*3<=≤<=*n*<=≤<=*max*1<=+<=*max*2<=+<=*max*3. | In the first line of the output print three numbers, showing how many diplomas of the first, second and third degree will be given to students in the optimal variant of distributing diplomas.
The optimal variant of distributing diplomas is the one that maximizes the number of students who receive diplomas of the first degree. Of all the suitable options, the best one is the one which maximizes the number of participants who receive diplomas of the second degree. If there are several of these options, the best one is the one that maximizes the number of diplomas of the third degree. | [
"6\n1 5\n2 6\n3 7\n",
"10\n1 2\n1 3\n1 5\n",
"6\n1 3\n2 2\n2 2\n"
] | [
"1 2 3 \n",
"2 3 5 \n",
"2 2 2 \n"
] | none | 500 | [
{
"input": "6\n1 5\n2 6\n3 7",
"output": "1 2 3 "
},
{
"input": "10\n1 2\n1 3\n1 5",
"output": "2 3 5 "
},
{
"input": "6\n1 3\n2 2\n2 2",
"output": "2 2 2 "
},
{
"input": "55\n1 1000000\n40 50\n10 200",
"output": "5 40 10 "
},
{
"input": "3\n1 1\n1 1\n1 1",
"output": "1 1 1 "
},
{
"input": "3\n1 1000000\n1 1000000\n1 1000000",
"output": "1 1 1 "
},
{
"input": "1000\n100 400\n300 500\n400 1200",
"output": "300 300 400 "
},
{
"input": "3000000\n1 1000000\n1 1000000\n1 1000000",
"output": "1000000 1000000 1000000 "
},
{
"input": "11\n3 5\n3 5\n3 5",
"output": "5 3 3 "
},
{
"input": "12\n3 5\n3 5\n3 5",
"output": "5 4 3 "
},
{
"input": "13\n3 5\n3 5\n3 5",
"output": "5 5 3 "
},
{
"input": "3000000\n1000000 1000000\n1000000 1000000\n1000000 1000000",
"output": "1000000 1000000 1000000 "
},
{
"input": "50\n1 100\n1 100\n1 100",
"output": "48 1 1 "
},
{
"input": "1279\n123 670\n237 614\n846 923",
"output": "196 237 846 "
},
{
"input": "1589\n213 861\n5 96\n506 634",
"output": "861 96 632 "
},
{
"input": "2115\n987 987\n112 483\n437 959",
"output": "987 483 645 "
},
{
"input": "641\n251 960\n34 370\n149 149",
"output": "458 34 149 "
},
{
"input": "1655\n539 539\n10 425\n605 895",
"output": "539 425 691 "
},
{
"input": "1477\n210 336\n410 837\n448 878",
"output": "336 693 448 "
},
{
"input": "1707\n149 914\n190 422\n898 899",
"output": "619 190 898 "
},
{
"input": "1529\n515 515\n563 869\n169 451",
"output": "515 845 169 "
},
{
"input": "1543\n361 994\n305 407\n102 197",
"output": "994 407 142 "
},
{
"input": "1107\n471 849\n360 741\n71 473",
"output": "676 360 71 "
},
{
"input": "1629279\n267360 999930\n183077 674527\n202618 786988",
"output": "999930 426731 202618 "
},
{
"input": "1233589\n2850 555444\n500608 921442\n208610 607343",
"output": "524371 500608 208610 "
},
{
"input": "679115\n112687 183628\n101770 982823\n81226 781340",
"output": "183628 414261 81226 "
},
{
"input": "1124641\n117999 854291\n770798 868290\n76651 831405",
"output": "277192 770798 76651 "
},
{
"input": "761655\n88152 620061\n60403 688549\n79370 125321",
"output": "620061 62224 79370 "
},
{
"input": "2174477\n276494 476134\n555283 954809\n319941 935631",
"output": "476134 954809 743534 "
},
{
"input": "1652707\n201202 990776\n34796 883866\n162979 983308",
"output": "990776 498952 162979 "
},
{
"input": "2065529\n43217 891429\n434379 952871\n650231 855105",
"output": "891429 523869 650231 "
},
{
"input": "1702543\n405042 832833\n50931 747750\n381818 796831",
"output": "832833 487892 381818 "
},
{
"input": "501107\n19061 859924\n126478 724552\n224611 489718",
"output": "150018 126478 224611 "
},
{
"input": "1629279\n850831 967352\n78593 463906\n452094 885430",
"output": "967352 209833 452094 "
},
{
"input": "1233589\n2850 157021\n535109 748096\n392212 475634",
"output": "157021 684356 392212 "
},
{
"input": "679115\n125987 786267\n70261 688983\n178133 976789",
"output": "430721 70261 178133 "
},
{
"input": "1124641\n119407 734250\n213706 860770\n102149 102149",
"output": "734250 288242 102149 "
},
{
"input": "761655\n325539 325539\n280794 792505\n18540 106895",
"output": "325539 417576 18540 "
},
{
"input": "2174477\n352351 791072\n365110 969163\n887448 955610",
"output": "791072 495957 887448 "
},
{
"input": "1652707\n266774 638522\n65688 235422\n924898 992826",
"output": "638522 89287 924898 "
},
{
"input": "2065529\n608515 608515\n751563 864337\n614898 705451",
"output": "608515 842116 614898 "
},
{
"input": "1702543\n5784 996578\n47395 300407\n151614 710197",
"output": "996578 300407 405558 "
},
{
"input": "501107\n8073 390048\n190494 647328\n274071 376923",
"output": "36542 190494 274071 "
},
{
"input": "200\n50 50\n100 100\n50 50",
"output": "50 100 50 "
},
{
"input": "14\n1 100\n1 100\n8 9",
"output": "5 1 8 "
},
{
"input": "300\n200 400\n50 100\n40 80",
"output": "210 50 40 "
},
{
"input": "10\n3 6\n3 6\n3 6",
"output": "4 3 3 "
},
{
"input": "14\n3 6\n3 6\n3 6",
"output": "6 5 3 "
},
{
"input": "17\n3 6\n3 6\n3 6",
"output": "6 6 5 "
},
{
"input": "1000000\n300000 600000\n300000 600000\n300000 600000",
"output": "400000 300000 300000 "
},
{
"input": "1400000\n300000 600000\n300000 600000\n300000 600000",
"output": "600000 500000 300000 "
},
{
"input": "1700000\n300000 600000\n300000 600000\n300000 600000",
"output": "600000 600000 500000 "
},
{
"input": "561\n400 400\n80 80\n81 81",
"output": "400 80 81 "
},
{
"input": "2000\n100 1000\n1 1\n1 2000",
"output": "1000 1 999 "
},
{
"input": "1000002\n1 1000000\n1 1000000\n999999 1000000",
"output": "2 1 999999 "
},
{
"input": "1000002\n1 1000000\n1 1000000\n1000000 1000000",
"output": "1 1 1000000 "
}
] | 1,526,706,013 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 62 | 0 | n = int(input())
m1, M1 = map(int, input().split())
m2, M2 = map(int, input().split())
m3, M3 = map(int, input().split())
first = min(n-m1-m2, M1)
n -= first
second = min(n-m2, M2)
n -= second
third = n
print(first, second, third) | Title: Ilya and Diplomas
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Soon a school Olympiad in Informatics will be held in Berland, *n* schoolchildren will participate there.
At a meeting of the jury of the Olympiad it was decided that each of the *n* participants, depending on the results, will get a diploma of the first, second or third degree. Thus, each student will receive exactly one diploma.
They also decided that there must be given at least *min*1 and at most *max*1 diplomas of the first degree, at least *min*2 and at most *max*2 diplomas of the second degree, and at least *min*3 and at most *max*3 diplomas of the third degree.
After some discussion it was decided to choose from all the options of distributing diplomas satisfying these limitations the one that maximizes the number of participants who receive diplomas of the first degree. Of all these options they select the one which maximizes the number of the participants who receive diplomas of the second degree. If there are multiple of these options, they select the option that maximizes the number of diplomas of the third degree.
Choosing the best option of distributing certificates was entrusted to Ilya, one of the best programmers of Berland. However, he found more important things to do, so it is your task now to choose the best option of distributing of diplomas, based on the described limitations.
It is guaranteed that the described limitations are such that there is a way to choose such an option of distributing diplomas that all *n* participants of the Olympiad will receive a diploma of some degree.
Input Specification:
The first line of the input contains a single integer *n* (3<=≤<=*n*<=≤<=3·106) — the number of schoolchildren who will participate in the Olympiad.
The next line of the input contains two integers *min*1 and *max*1 (1<=≤<=*min*1<=≤<=*max*1<=≤<=106) — the minimum and maximum limits on the number of diplomas of the first degree that can be distributed.
The third line of the input contains two integers *min*2 and *max*2 (1<=≤<=*min*2<=≤<=*max*2<=≤<=106) — the minimum and maximum limits on the number of diplomas of the second degree that can be distributed.
The next line of the input contains two integers *min*3 and *max*3 (1<=≤<=*min*3<=≤<=*max*3<=≤<=106) — the minimum and maximum limits on the number of diplomas of the third degree that can be distributed.
It is guaranteed that *min*1<=+<=*min*2<=+<=*min*3<=≤<=*n*<=≤<=*max*1<=+<=*max*2<=+<=*max*3.
Output Specification:
In the first line of the output print three numbers, showing how many diplomas of the first, second and third degree will be given to students in the optimal variant of distributing diplomas.
The optimal variant of distributing diplomas is the one that maximizes the number of students who receive diplomas of the first degree. Of all the suitable options, the best one is the one which maximizes the number of participants who receive diplomas of the second degree. If there are several of these options, the best one is the one that maximizes the number of diplomas of the third degree.
Demo Input:
['6\n1 5\n2 6\n3 7\n', '10\n1 2\n1 3\n1 5\n', '6\n1 3\n2 2\n2 2\n']
Demo Output:
['1 2 3 \n', '2 3 5 \n', '2 2 2 \n']
Note:
none | ```python
n = int(input())
m1, M1 = map(int, input().split())
m2, M2 = map(int, input().split())
m3, M3 = map(int, input().split())
first = min(n-m1-m2, M1)
n -= first
second = min(n-m2, M2)
n -= second
third = n
print(first, second, third)
``` | 0 |
|
136 | A | Presents | PROGRAMMING | 800 | [
"implementation"
] | null | null | Little Petya very much likes gifts. Recently he has received a new laptop as a New Year gift from his mother. He immediately decided to give it to somebody else as what can be more pleasant than giving somebody gifts. And on this occasion he organized a New Year party at his place and invited *n* his friends there.
If there's one thing Petya likes more that receiving gifts, that's watching others giving gifts to somebody else. Thus, he safely hid the laptop until the next New Year and made up his mind to watch his friends exchanging gifts while he does not participate in the process. He numbered all his friends with integers from 1 to *n*. Petya remembered that a friend number *i* gave a gift to a friend number *p**i*. He also remembered that each of his friends received exactly one gift.
Now Petya wants to know for each friend *i* the number of a friend who has given him a gift. | The first line contains one integer *n* (1<=≤<=*n*<=≤<=100) — the quantity of friends Petya invited to the party. The second line contains *n* space-separated integers: the *i*-th number is *p**i* — the number of a friend who gave a gift to friend number *i*. It is guaranteed that each friend received exactly one gift. It is possible that some friends do not share Petya's ideas of giving gifts to somebody else. Those friends gave the gifts to themselves. | Print *n* space-separated integers: the *i*-th number should equal the number of the friend who gave a gift to friend number *i*. | [
"4\n2 3 4 1\n",
"3\n1 3 2\n",
"2\n1 2\n"
] | [
"4 1 2 3\n",
"1 3 2\n",
"1 2\n"
] | none | 500 | [
{
"input": "4\n2 3 4 1",
"output": "4 1 2 3"
},
{
"input": "3\n1 3 2",
"output": "1 3 2"
},
{
"input": "2\n1 2",
"output": "1 2"
},
{
"input": "1\n1",
"output": "1"
},
{
"input": "10\n1 3 2 6 4 5 7 9 8 10",
"output": "1 3 2 5 6 4 7 9 8 10"
},
{
"input": "5\n5 4 3 2 1",
"output": "5 4 3 2 1"
},
{
"input": "20\n2 1 4 3 6 5 8 7 10 9 12 11 14 13 16 15 18 17 20 19",
"output": "2 1 4 3 6 5 8 7 10 9 12 11 14 13 16 15 18 17 20 19"
},
{
"input": "21\n3 2 1 6 5 4 9 8 7 12 11 10 15 14 13 18 17 16 21 20 19",
"output": "3 2 1 6 5 4 9 8 7 12 11 10 15 14 13 18 17 16 21 20 19"
},
{
"input": "10\n3 4 5 6 7 8 9 10 1 2",
"output": "9 10 1 2 3 4 5 6 7 8"
},
{
"input": "8\n1 5 3 7 2 6 4 8",
"output": "1 5 3 7 2 6 4 8"
},
{
"input": "50\n49 22 4 2 20 46 7 32 5 19 48 24 26 15 45 21 44 11 50 43 39 17 31 1 42 34 3 27 36 25 12 30 13 33 28 35 18 6 8 37 38 14 10 9 29 16 40 23 41 47",
"output": "24 4 27 3 9 38 7 39 44 43 18 31 33 42 14 46 22 37 10 5 16 2 48 12 30 13 28 35 45 32 23 8 34 26 36 29 40 41 21 47 49 25 20 17 15 6 50 11 1 19"
},
{
"input": "34\n13 20 33 30 15 11 27 4 8 2 29 25 24 7 3 22 18 10 26 16 5 1 32 9 34 6 12 14 28 19 31 21 23 17",
"output": "22 10 15 8 21 26 14 9 24 18 6 27 1 28 5 20 34 17 30 2 32 16 33 13 12 19 7 29 11 4 31 23 3 25"
},
{
"input": "92\n23 1 6 4 84 54 44 76 63 34 61 20 48 13 28 78 26 46 90 72 24 55 91 89 53 38 82 5 79 92 29 32 15 64 11 88 60 70 7 66 18 59 8 57 19 16 42 21 80 71 62 27 75 86 36 9 83 73 74 50 43 31 56 30 17 33 40 81 49 12 10 41 22 77 25 68 51 2 47 3 58 69 87 67 39 37 35 65 14 45 52 85",
"output": "2 78 80 4 28 3 39 43 56 71 35 70 14 89 33 46 65 41 45 12 48 73 1 21 75 17 52 15 31 64 62 32 66 10 87 55 86 26 85 67 72 47 61 7 90 18 79 13 69 60 77 91 25 6 22 63 44 81 42 37 11 51 9 34 88 40 84 76 82 38 50 20 58 59 53 8 74 16 29 49 68 27 57 5 92 54 83 36 24 19 23 30"
},
{
"input": "49\n30 24 33 48 7 3 17 2 8 35 10 39 23 40 46 32 18 21 26 22 1 16 47 45 41 28 31 6 12 43 27 11 13 37 19 15 44 5 29 42 4 38 20 34 14 9 25 36 49",
"output": "21 8 6 41 38 28 5 9 46 11 32 29 33 45 36 22 7 17 35 43 18 20 13 2 47 19 31 26 39 1 27 16 3 44 10 48 34 42 12 14 25 40 30 37 24 15 23 4 49"
},
{
"input": "12\n3 8 7 4 6 5 2 1 11 9 10 12",
"output": "8 7 1 4 6 5 3 2 10 11 9 12"
},
{
"input": "78\n16 56 36 78 21 14 9 77 26 57 70 61 41 47 18 44 5 31 50 74 65 52 6 39 22 62 67 69 43 7 64 29 24 40 48 51 73 54 72 12 19 34 4 25 55 33 17 35 23 53 10 8 27 32 42 68 20 63 3 2 1 71 58 46 13 30 49 11 37 66 38 60 28 75 15 59 45 76",
"output": "61 60 59 43 17 23 30 52 7 51 68 40 65 6 75 1 47 15 41 57 5 25 49 33 44 9 53 73 32 66 18 54 46 42 48 3 69 71 24 34 13 55 29 16 77 64 14 35 67 19 36 22 50 38 45 2 10 63 76 72 12 26 58 31 21 70 27 56 28 11 62 39 37 20 74 78 8 4"
},
{
"input": "64\n64 57 40 3 15 8 62 18 33 59 51 19 22 13 4 37 47 45 50 35 63 11 58 42 46 21 7 2 41 48 32 23 28 38 17 12 24 27 49 31 60 6 30 25 61 52 26 54 9 14 29 20 44 39 55 10 34 16 5 56 1 36 53 43",
"output": "61 28 4 15 59 42 27 6 49 56 22 36 14 50 5 58 35 8 12 52 26 13 32 37 44 47 38 33 51 43 40 31 9 57 20 62 16 34 54 3 29 24 64 53 18 25 17 30 39 19 11 46 63 48 55 60 2 23 10 41 45 7 21 1"
},
{
"input": "49\n38 20 49 32 14 41 39 45 25 48 40 19 26 43 34 12 10 3 35 42 5 7 46 47 4 2 13 22 16 24 33 15 11 18 29 31 23 9 44 36 6 17 37 1 30 28 8 21 27",
"output": "44 26 18 25 21 41 22 47 38 17 33 16 27 5 32 29 42 34 12 2 48 28 37 30 9 13 49 46 35 45 36 4 31 15 19 40 43 1 7 11 6 20 14 39 8 23 24 10 3"
},
{
"input": "78\n17 50 30 48 33 12 42 4 18 53 76 67 38 3 20 72 51 55 60 63 46 10 57 45 54 32 24 62 8 11 35 44 65 74 58 28 2 6 56 52 39 23 47 49 61 1 66 41 15 77 7 27 78 13 14 34 5 31 37 21 40 16 29 69 59 43 64 36 70 19 25 73 71 75 9 68 26 22",
"output": "46 37 14 8 57 38 51 29 75 22 30 6 54 55 49 62 1 9 70 15 60 78 42 27 71 77 52 36 63 3 58 26 5 56 31 68 59 13 41 61 48 7 66 32 24 21 43 4 44 2 17 40 10 25 18 39 23 35 65 19 45 28 20 67 33 47 12 76 64 69 73 16 72 34 74 11 50 53"
},
{
"input": "29\n14 21 27 1 4 18 10 17 20 23 2 24 7 9 28 22 8 25 12 15 11 6 16 29 3 26 19 5 13",
"output": "4 11 25 5 28 22 13 17 14 7 21 19 29 1 20 23 8 6 27 9 2 16 10 12 18 26 3 15 24"
},
{
"input": "82\n6 1 10 75 28 66 61 81 78 63 17 19 58 34 49 12 67 50 41 44 3 15 59 38 51 72 36 11 46 29 18 64 27 23 13 53 56 68 2 25 47 40 69 54 42 5 60 55 4 16 24 79 57 20 7 73 32 80 76 52 82 37 26 31 65 8 39 62 33 71 30 9 77 43 48 74 70 22 14 45 35 21",
"output": "2 39 21 49 46 1 55 66 72 3 28 16 35 79 22 50 11 31 12 54 82 78 34 51 40 63 33 5 30 71 64 57 69 14 81 27 62 24 67 42 19 45 74 20 80 29 41 75 15 18 25 60 36 44 48 37 53 13 23 47 7 68 10 32 65 6 17 38 43 77 70 26 56 76 4 59 73 9 52 58 8 61"
},
{
"input": "82\n74 18 15 69 71 77 19 26 80 20 66 7 30 82 22 48 21 44 52 65 64 61 35 49 12 8 53 81 54 16 11 9 40 46 13 1 29 58 5 41 55 4 78 60 6 51 56 2 38 36 34 62 63 25 17 67 45 14 32 37 75 79 10 47 27 39 31 68 59 24 50 43 72 70 42 28 76 23 57 3 73 33",
"output": "36 48 80 42 39 45 12 26 32 63 31 25 35 58 3 30 55 2 7 10 17 15 78 70 54 8 65 76 37 13 67 59 82 51 23 50 60 49 66 33 40 75 72 18 57 34 64 16 24 71 46 19 27 29 41 47 79 38 69 44 22 52 53 21 20 11 56 68 4 74 5 73 81 1 61 77 6 43 62 9 28 14"
},
{
"input": "45\n2 32 34 13 3 15 16 33 22 12 31 38 42 14 27 7 36 8 4 19 45 41 5 35 10 11 39 20 29 44 17 9 6 40 37 28 25 21 1 30 24 18 43 26 23",
"output": "39 1 5 19 23 33 16 18 32 25 26 10 4 14 6 7 31 42 20 28 38 9 45 41 37 44 15 36 29 40 11 2 8 3 24 17 35 12 27 34 22 13 43 30 21"
},
{
"input": "45\n4 32 33 39 43 21 22 35 45 7 14 5 16 9 42 31 24 36 17 29 41 25 37 34 27 20 11 44 3 13 19 2 1 10 26 30 38 18 6 8 15 23 40 28 12",
"output": "33 32 29 1 12 39 10 40 14 34 27 45 30 11 41 13 19 38 31 26 6 7 42 17 22 35 25 44 20 36 16 2 3 24 8 18 23 37 4 43 21 15 5 28 9"
},
{
"input": "74\n48 72 40 67 17 4 27 53 11 32 25 9 74 2 41 24 56 22 14 21 33 5 18 55 20 7 29 36 69 13 52 19 38 30 68 59 66 34 63 6 47 45 54 44 62 12 50 71 16 10 8 64 57 73 46 26 49 42 3 23 35 1 61 39 70 60 65 43 15 28 37 51 58 31",
"output": "62 14 59 6 22 40 26 51 12 50 9 46 30 19 69 49 5 23 32 25 20 18 60 16 11 56 7 70 27 34 74 10 21 38 61 28 71 33 64 3 15 58 68 44 42 55 41 1 57 47 72 31 8 43 24 17 53 73 36 66 63 45 39 52 67 37 4 35 29 65 48 2 54 13"
},
{
"input": "47\n9 26 27 10 6 34 28 42 39 22 45 21 11 43 14 47 38 15 40 32 46 1 36 29 17 25 2 23 31 5 24 4 7 8 12 19 16 44 37 20 18 33 30 13 35 41 3",
"output": "22 27 47 32 30 5 33 34 1 4 13 35 44 15 18 37 25 41 36 40 12 10 28 31 26 2 3 7 24 43 29 20 42 6 45 23 39 17 9 19 46 8 14 38 11 21 16"
},
{
"input": "49\n14 38 6 29 9 49 36 43 47 3 44 20 34 15 7 11 1 28 12 40 16 37 31 10 42 41 33 21 18 30 5 27 17 35 25 26 45 19 2 13 23 32 4 22 46 48 24 39 8",
"output": "17 39 10 43 31 3 15 49 5 24 16 19 40 1 14 21 33 29 38 12 28 44 41 47 35 36 32 18 4 30 23 42 27 13 34 7 22 2 48 20 26 25 8 11 37 45 9 46 6"
},
{
"input": "100\n78 56 31 91 90 95 16 65 58 77 37 89 33 61 10 76 62 47 35 67 69 7 63 83 22 25 49 8 12 30 39 44 57 64 48 42 32 11 70 43 55 50 99 24 85 73 45 14 54 21 98 84 74 2 26 18 9 36 80 53 75 46 66 86 59 93 87 68 94 13 72 28 79 88 92 29 52 82 34 97 19 38 1 41 27 4 40 5 96 100 51 6 20 23 81 15 17 3 60 71",
"output": "83 54 98 86 88 92 22 28 57 15 38 29 70 48 96 7 97 56 81 93 50 25 94 44 26 55 85 72 76 30 3 37 13 79 19 58 11 82 31 87 84 36 40 32 47 62 18 35 27 42 91 77 60 49 41 2 33 9 65 99 14 17 23 34 8 63 20 68 21 39 100 71 46 53 61 16 10 1 73 59 95 78 24 52 45 64 67 74 12 5 4 75 66 69 6 89 80 51 43 90"
},
{
"input": "22\n12 8 11 2 16 7 13 6 22 21 20 10 4 14 18 1 5 15 3 19 17 9",
"output": "16 4 19 13 17 8 6 2 22 12 3 1 7 14 18 5 21 15 20 11 10 9"
},
{
"input": "72\n16 11 49 51 3 27 60 55 23 40 66 7 53 70 13 5 15 32 18 72 33 30 8 31 46 12 28 67 25 38 50 22 69 34 71 52 58 39 24 35 42 9 41 26 62 1 63 65 36 64 68 61 37 14 45 47 6 57 54 20 17 2 56 59 29 10 4 48 21 43 19 44",
"output": "46 62 5 67 16 57 12 23 42 66 2 26 15 54 17 1 61 19 71 60 69 32 9 39 29 44 6 27 65 22 24 18 21 34 40 49 53 30 38 10 43 41 70 72 55 25 56 68 3 31 4 36 13 59 8 63 58 37 64 7 52 45 47 50 48 11 28 51 33 14 35 20"
},
{
"input": "63\n21 56 11 10 62 24 20 42 28 52 38 2 37 43 48 22 7 8 40 14 13 46 53 1 23 4 60 63 51 36 25 12 39 32 49 16 58 44 31 61 33 50 55 54 45 6 47 41 9 57 30 29 26 18 19 27 15 34 3 35 59 5 17",
"output": "24 12 59 26 62 46 17 18 49 4 3 32 21 20 57 36 63 54 55 7 1 16 25 6 31 53 56 9 52 51 39 34 41 58 60 30 13 11 33 19 48 8 14 38 45 22 47 15 35 42 29 10 23 44 43 2 50 37 61 27 40 5 28"
},
{
"input": "18\n2 16 8 4 18 12 3 6 5 9 10 15 11 17 14 13 1 7",
"output": "17 1 7 4 9 8 18 3 10 11 13 6 16 15 12 2 14 5"
},
{
"input": "47\n6 9 10 41 25 3 4 37 20 1 36 22 29 27 11 24 43 31 12 17 34 42 38 39 13 2 7 21 18 5 15 35 44 26 33 46 19 40 30 14 28 23 47 32 45 8 16",
"output": "10 26 6 7 30 1 27 46 2 3 15 19 25 40 31 47 20 29 37 9 28 12 42 16 5 34 14 41 13 39 18 44 35 21 32 11 8 23 24 38 4 22 17 33 45 36 43"
},
{
"input": "96\n41 91 48 88 29 57 1 19 44 43 37 5 10 75 25 63 30 78 76 53 8 92 18 70 39 17 49 60 9 16 3 34 86 59 23 79 55 45 72 51 28 33 96 40 26 54 6 32 89 61 85 74 7 82 52 31 64 66 94 95 11 22 2 73 35 13 42 71 14 47 84 69 50 67 58 12 77 46 38 68 15 36 20 93 27 90 83 56 87 4 21 24 81 62 80 65",
"output": "7 63 31 90 12 47 53 21 29 13 61 76 66 69 81 30 26 23 8 83 91 62 35 92 15 45 85 41 5 17 56 48 42 32 65 82 11 79 25 44 1 67 10 9 38 78 70 3 27 73 40 55 20 46 37 88 6 75 34 28 50 94 16 57 96 58 74 80 72 24 68 39 64 52 14 19 77 18 36 95 93 54 87 71 51 33 89 4 49 86 2 22 84 59 60 43"
},
{
"input": "73\n67 24 39 22 23 20 48 34 42 40 19 70 65 69 64 21 53 11 59 15 26 10 30 33 72 29 55 25 56 71 8 9 57 49 41 61 13 12 6 27 66 36 47 50 73 60 2 37 7 4 51 17 1 46 14 62 35 3 45 63 43 58 54 32 31 5 28 44 18 52 68 38 16",
"output": "53 47 58 50 66 39 49 31 32 22 18 38 37 55 20 73 52 69 11 6 16 4 5 2 28 21 40 67 26 23 65 64 24 8 57 42 48 72 3 10 35 9 61 68 59 54 43 7 34 44 51 70 17 63 27 29 33 62 19 46 36 56 60 15 13 41 1 71 14 12 30 25 45"
},
{
"input": "81\n25 2 78 40 12 80 69 13 49 43 17 33 23 54 32 61 77 66 27 71 24 26 42 55 60 9 5 30 7 37 45 63 53 11 38 44 68 34 28 52 67 22 57 46 47 50 8 16 79 62 4 36 20 14 73 64 6 76 35 74 58 10 29 81 59 31 19 1 75 39 70 18 41 21 72 65 3 48 15 56 51",
"output": "68 2 77 51 27 57 29 47 26 62 34 5 8 54 79 48 11 72 67 53 74 42 13 21 1 22 19 39 63 28 66 15 12 38 59 52 30 35 70 4 73 23 10 36 31 44 45 78 9 46 81 40 33 14 24 80 43 61 65 25 16 50 32 56 76 18 41 37 7 71 20 75 55 60 69 58 17 3 49 6 64"
},
{
"input": "12\n12 3 1 5 11 6 7 10 2 8 9 4",
"output": "3 9 2 12 4 6 7 10 11 8 5 1"
},
{
"input": "47\n7 21 41 18 40 31 12 28 24 14 43 23 33 10 19 38 26 8 34 15 29 44 5 13 39 25 3 27 20 42 35 9 2 1 30 46 36 32 4 22 37 45 6 47 11 16 17",
"output": "34 33 27 39 23 43 1 18 32 14 45 7 24 10 20 46 47 4 15 29 2 40 12 9 26 17 28 8 21 35 6 38 13 19 31 37 41 16 25 5 3 30 11 22 42 36 44"
},
{
"input": "8\n1 3 5 2 4 8 6 7",
"output": "1 4 2 5 3 7 8 6"
},
{
"input": "38\n28 8 2 33 20 32 26 29 23 31 15 38 11 37 18 21 22 19 4 34 1 35 16 7 17 6 27 30 36 12 9 24 25 13 5 3 10 14",
"output": "21 3 36 19 35 26 24 2 31 37 13 30 34 38 11 23 25 15 18 5 16 17 9 32 33 7 27 1 8 28 10 6 4 20 22 29 14 12"
},
{
"input": "10\n2 9 4 6 10 1 7 5 3 8",
"output": "6 1 9 3 8 4 7 10 2 5"
},
{
"input": "23\n20 11 15 1 5 12 23 9 2 22 13 19 16 14 7 4 8 21 6 17 18 10 3",
"output": "4 9 23 16 5 19 15 17 8 22 2 6 11 14 3 13 20 21 12 1 18 10 7"
},
{
"input": "10\n2 4 9 3 6 8 10 5 1 7",
"output": "9 1 4 2 8 5 10 6 3 7"
},
{
"input": "55\n9 48 23 49 11 24 4 22 34 32 17 45 39 13 14 21 19 25 2 31 37 7 55 36 20 51 5 12 54 10 35 40 43 1 46 18 53 41 38 26 29 50 3 42 52 27 8 28 47 33 6 16 30 44 15",
"output": "34 19 43 7 27 51 22 47 1 30 5 28 14 15 55 52 11 36 17 25 16 8 3 6 18 40 46 48 41 53 20 10 50 9 31 24 21 39 13 32 38 44 33 54 12 35 49 2 4 42 26 45 37 29 23"
},
{
"input": "58\n49 13 12 54 2 38 56 11 33 25 26 19 28 8 23 41 20 36 46 55 15 35 9 7 32 37 58 6 3 14 47 31 40 30 53 44 4 50 29 34 10 43 39 57 5 22 27 45 51 42 24 16 18 21 52 17 48 1",
"output": "58 5 29 37 45 28 24 14 23 41 8 3 2 30 21 52 56 53 12 17 54 46 15 51 10 11 47 13 39 34 32 25 9 40 22 18 26 6 43 33 16 50 42 36 48 19 31 57 1 38 49 55 35 4 20 7 44 27"
},
{
"input": "34\n20 25 2 3 33 29 1 16 14 7 21 9 32 31 6 26 22 4 27 23 24 10 34 12 19 15 5 18 28 17 13 8 11 30",
"output": "7 3 4 18 27 15 10 32 12 22 33 24 31 9 26 8 30 28 25 1 11 17 20 21 2 16 19 29 6 34 14 13 5 23"
},
{
"input": "53\n47 29 46 25 23 13 7 31 33 4 38 11 35 16 42 14 15 43 34 39 28 18 6 45 30 1 40 20 2 37 5 32 24 12 44 26 27 3 19 51 36 21 22 9 10 50 41 48 49 53 8 17 52",
"output": "26 29 38 10 31 23 7 51 44 45 12 34 6 16 17 14 52 22 39 28 42 43 5 33 4 36 37 21 2 25 8 32 9 19 13 41 30 11 20 27 47 15 18 35 24 3 1 48 49 46 40 53 50"
},
{
"input": "99\n77 87 90 48 53 38 68 6 28 57 35 82 63 71 60 41 3 12 86 65 10 59 22 67 33 74 93 27 24 1 61 43 25 4 51 52 15 88 9 31 30 42 89 49 23 21 29 32 46 73 37 16 5 69 56 26 92 64 20 54 75 14 98 13 94 2 95 7 36 66 58 8 50 78 84 45 11 96 76 62 97 80 40 39 47 85 34 79 83 17 91 72 19 44 70 81 55 99 18",
"output": "30 66 17 34 53 8 68 72 39 21 77 18 64 62 37 52 90 99 93 59 46 23 45 29 33 56 28 9 47 41 40 48 25 87 11 69 51 6 84 83 16 42 32 94 76 49 85 4 44 73 35 36 5 60 97 55 10 71 22 15 31 80 13 58 20 70 24 7 54 95 14 92 50 26 61 79 1 74 88 82 96 12 89 75 86 19 2 38 43 3 91 57 27 65 67 78 81 63 98"
},
{
"input": "32\n17 29 2 6 30 8 26 7 1 27 10 9 13 24 31 21 15 19 22 18 4 11 25 28 32 3 23 12 5 14 20 16",
"output": "9 3 26 21 29 4 8 6 12 11 22 28 13 30 17 32 1 20 18 31 16 19 27 14 23 7 10 24 2 5 15 25"
},
{
"input": "65\n18 40 1 60 17 19 4 6 12 49 28 58 2 25 13 14 64 56 61 34 62 30 59 51 26 8 33 63 36 48 46 7 43 21 31 27 11 44 29 5 32 23 35 9 53 57 52 50 15 38 42 3 54 65 55 41 20 24 22 47 45 10 39 16 37",
"output": "3 13 52 7 40 8 32 26 44 62 37 9 15 16 49 64 5 1 6 57 34 59 42 58 14 25 36 11 39 22 35 41 27 20 43 29 65 50 63 2 56 51 33 38 61 31 60 30 10 48 24 47 45 53 55 18 46 12 23 4 19 21 28 17 54"
},
{
"input": "71\n35 50 55 58 25 32 26 40 63 34 44 53 24 18 37 7 64 27 56 65 1 19 2 43 42 14 57 47 22 13 59 61 39 67 30 45 54 38 33 48 6 5 3 69 36 21 41 4 16 46 20 17 15 12 10 70 68 23 60 31 52 29 66 28 51 49 62 11 8 9 71",
"output": "21 23 43 48 42 41 16 69 70 55 68 54 30 26 53 49 52 14 22 51 46 29 58 13 5 7 18 64 62 35 60 6 39 10 1 45 15 38 33 8 47 25 24 11 36 50 28 40 66 2 65 61 12 37 3 19 27 4 31 59 32 67 9 17 20 63 34 57 44 56 71"
},
{
"input": "74\n33 8 42 63 64 61 31 74 11 50 68 14 36 25 57 30 7 44 21 15 6 9 23 59 46 3 73 16 62 51 40 60 41 54 5 39 35 28 48 4 58 12 66 69 13 26 71 1 24 19 29 52 37 2 20 43 18 72 17 56 34 38 65 67 27 10 47 70 53 32 45 55 49 22",
"output": "48 54 26 40 35 21 17 2 22 66 9 42 45 12 20 28 59 57 50 55 19 74 23 49 14 46 65 38 51 16 7 70 1 61 37 13 53 62 36 31 33 3 56 18 71 25 67 39 73 10 30 52 69 34 72 60 15 41 24 32 6 29 4 5 63 43 64 11 44 68 47 58 27 8"
},
{
"input": "96\n78 10 82 46 38 91 77 69 2 27 58 80 79 44 59 41 6 31 76 11 42 48 51 37 19 87 43 25 52 32 1 39 63 29 21 65 53 74 92 16 15 95 90 83 30 73 71 5 50 17 96 33 86 60 67 64 20 26 61 40 55 88 94 93 9 72 47 57 14 45 22 3 54 68 13 24 4 7 56 81 89 70 49 8 84 28 18 62 35 36 75 23 66 85 34 12",
"output": "31 9 72 77 48 17 78 84 65 2 20 96 75 69 41 40 50 87 25 57 35 71 92 76 28 58 10 86 34 45 18 30 52 95 89 90 24 5 32 60 16 21 27 14 70 4 67 22 83 49 23 29 37 73 61 79 68 11 15 54 59 88 33 56 36 93 55 74 8 82 47 66 46 38 91 19 7 1 13 12 80 3 44 85 94 53 26 62 81 43 6 39 64 63 42 51"
},
{
"input": "7\n2 1 5 7 3 4 6",
"output": "2 1 5 6 3 7 4"
},
{
"input": "51\n8 33 37 2 16 22 24 30 4 9 5 15 27 3 18 39 31 26 10 17 46 41 25 14 6 1 29 48 36 20 51 49 21 43 19 13 38 50 47 34 11 23 28 12 42 7 32 40 44 45 35",
"output": "26 4 14 9 11 25 46 1 10 19 41 44 36 24 12 5 20 15 35 30 33 6 42 7 23 18 13 43 27 8 17 47 2 40 51 29 3 37 16 48 22 45 34 49 50 21 39 28 32 38 31"
},
{
"input": "27\n12 14 7 3 20 21 25 13 22 15 23 4 2 24 10 17 19 8 26 11 27 18 9 5 6 1 16",
"output": "26 13 4 12 24 25 3 18 23 15 20 1 8 2 10 27 16 22 17 5 6 9 11 14 7 19 21"
},
{
"input": "71\n51 13 20 48 54 23 24 64 14 62 71 67 57 53 3 30 55 43 33 25 39 40 66 6 46 18 5 19 61 16 32 68 70 41 60 44 29 49 27 69 50 38 10 17 45 56 9 21 26 63 28 35 7 59 1 65 2 15 8 11 12 34 37 47 58 22 31 4 36 42 52",
"output": "55 57 15 68 27 24 53 59 47 43 60 61 2 9 58 30 44 26 28 3 48 66 6 7 20 49 39 51 37 16 67 31 19 62 52 69 63 42 21 22 34 70 18 36 45 25 64 4 38 41 1 71 14 5 17 46 13 65 54 35 29 10 50 8 56 23 12 32 40 33 11"
},
{
"input": "9\n8 5 2 6 1 9 4 7 3",
"output": "5 3 9 7 2 4 8 1 6"
},
{
"input": "29\n10 24 11 5 26 25 2 9 22 15 8 14 29 21 4 1 23 17 3 12 13 16 18 28 19 20 7 6 27",
"output": "16 7 19 15 4 28 27 11 8 1 3 20 21 12 10 22 18 23 25 26 14 9 17 2 6 5 29 24 13"
},
{
"input": "60\n39 25 42 4 55 60 16 18 47 1 11 40 7 50 19 35 49 54 12 3 30 38 2 58 17 26 45 6 33 43 37 32 52 36 15 23 27 59 24 20 28 14 8 9 13 29 44 46 41 21 5 48 51 22 31 56 57 53 10 34",
"output": "10 23 20 4 51 28 13 43 44 59 11 19 45 42 35 7 25 8 15 40 50 54 36 39 2 26 37 41 46 21 55 32 29 60 16 34 31 22 1 12 49 3 30 47 27 48 9 52 17 14 53 33 58 18 5 56 57 24 38 6"
},
{
"input": "50\n37 45 22 5 12 21 28 24 18 47 20 25 8 50 14 2 34 43 11 16 49 41 48 1 19 31 39 46 32 23 15 42 3 35 38 30 44 26 10 9 40 36 7 17 33 4 27 6 13 29",
"output": "24 16 33 46 4 48 43 13 40 39 19 5 49 15 31 20 44 9 25 11 6 3 30 8 12 38 47 7 50 36 26 29 45 17 34 42 1 35 27 41 22 32 18 37 2 28 10 23 21 14"
},
{
"input": "30\n8 29 28 16 17 25 27 15 21 11 6 20 2 13 1 30 5 4 24 10 14 3 23 18 26 9 12 22 19 7",
"output": "15 13 22 18 17 11 30 1 26 20 10 27 14 21 8 4 5 24 29 12 9 28 23 19 6 25 7 3 2 16"
},
{
"input": "46\n15 2 44 43 38 19 31 42 4 37 29 30 24 45 27 41 8 20 33 7 35 3 18 46 36 26 1 28 21 40 16 22 32 11 14 13 12 9 25 39 10 6 23 17 5 34",
"output": "27 2 22 9 45 42 20 17 38 41 34 37 36 35 1 31 44 23 6 18 29 32 43 13 39 26 15 28 11 12 7 33 19 46 21 25 10 5 40 30 16 8 4 3 14 24"
},
{
"input": "9\n4 8 6 5 3 9 2 7 1",
"output": "9 7 5 1 4 3 8 2 6"
},
{
"input": "46\n31 30 33 23 45 7 36 8 11 3 32 39 41 20 1 28 6 27 18 24 17 5 16 37 26 13 22 14 2 38 15 46 9 4 19 21 12 44 10 35 25 34 42 43 40 29",
"output": "15 29 10 34 22 17 6 8 33 39 9 37 26 28 31 23 21 19 35 14 36 27 4 20 41 25 18 16 46 2 1 11 3 42 40 7 24 30 12 45 13 43 44 38 5 32"
},
{
"input": "66\n27 12 37 48 46 21 34 58 38 28 66 2 64 32 44 31 13 36 40 15 19 11 22 5 30 29 6 7 61 39 20 42 23 54 51 33 50 9 60 8 57 45 49 10 62 41 59 3 55 63 52 24 25 26 43 56 65 4 16 14 1 35 18 17 53 47",
"output": "61 12 48 58 24 27 28 40 38 44 22 2 17 60 20 59 64 63 21 31 6 23 33 52 53 54 1 10 26 25 16 14 36 7 62 18 3 9 30 19 46 32 55 15 42 5 66 4 43 37 35 51 65 34 49 56 41 8 47 39 29 45 50 13 57 11"
},
{
"input": "13\n3 12 9 2 8 5 13 4 11 1 10 7 6",
"output": "10 4 1 8 6 13 12 5 3 11 9 2 7"
},
{
"input": "80\n21 25 56 50 20 61 7 74 51 69 8 2 46 57 45 71 14 52 17 43 9 30 70 78 31 10 38 13 23 15 37 79 6 16 77 73 80 4 49 48 18 28 26 58 33 41 64 22 54 72 59 60 40 63 53 27 1 5 75 67 62 34 19 39 68 65 44 55 3 32 11 42 76 12 35 47 66 36 24 29",
"output": "57 12 69 38 58 33 7 11 21 26 71 74 28 17 30 34 19 41 63 5 1 48 29 79 2 43 56 42 80 22 25 70 45 62 75 78 31 27 64 53 46 72 20 67 15 13 76 40 39 4 9 18 55 49 68 3 14 44 51 52 6 61 54 47 66 77 60 65 10 23 16 50 36 8 59 73 35 24 32 37"
},
{
"input": "63\n9 49 53 25 40 46 43 51 54 22 58 16 23 26 10 47 5 27 2 8 61 59 19 35 63 56 28 20 34 4 62 38 6 55 36 31 57 15 29 33 1 48 50 37 7 30 18 42 32 52 12 41 14 21 45 11 24 17 39 13 44 60 3",
"output": "41 19 63 30 17 33 45 20 1 15 56 51 60 53 38 12 58 47 23 28 54 10 13 57 4 14 18 27 39 46 36 49 40 29 24 35 44 32 59 5 52 48 7 61 55 6 16 42 2 43 8 50 3 9 34 26 37 11 22 62 21 31 25"
},
{
"input": "26\n11 4 19 13 17 9 2 24 6 5 22 23 14 15 3 25 16 8 18 10 21 1 12 26 7 20",
"output": "22 7 15 2 10 9 25 18 6 20 1 23 4 13 14 17 5 19 3 26 21 11 12 8 16 24"
},
{
"input": "69\n40 22 11 66 4 27 31 29 64 53 37 55 51 2 7 36 18 52 6 1 30 21 17 20 14 9 59 62 49 68 3 50 65 57 44 5 67 46 33 13 34 15 24 48 63 58 38 25 41 35 16 54 32 10 60 61 39 12 69 8 23 45 26 47 56 43 28 19 42",
"output": "20 14 31 5 36 19 15 60 26 54 3 58 40 25 42 51 23 17 68 24 22 2 61 43 48 63 6 67 8 21 7 53 39 41 50 16 11 47 57 1 49 69 66 35 62 38 64 44 29 32 13 18 10 52 12 65 34 46 27 55 56 28 45 9 33 4 37 30 59"
},
{
"input": "6\n4 3 6 5 1 2",
"output": "5 6 2 1 4 3"
},
{
"input": "9\n7 8 5 3 1 4 2 9 6",
"output": "5 7 4 6 3 9 1 2 8"
},
{
"input": "41\n27 24 16 30 25 8 32 2 26 20 39 33 41 22 40 14 36 9 28 4 34 11 31 23 19 18 17 35 3 10 6 13 5 15 29 38 7 21 1 12 37",
"output": "39 8 29 20 33 31 37 6 18 30 22 40 32 16 34 3 27 26 25 10 38 14 24 2 5 9 1 19 35 4 23 7 12 21 28 17 41 36 11 15 13"
},
{
"input": "1\n1",
"output": "1"
},
{
"input": "20\n2 6 4 18 7 10 17 13 16 8 14 9 20 5 19 12 1 3 15 11",
"output": "17 1 18 3 14 2 5 10 12 6 20 16 8 11 19 9 7 4 15 13"
},
{
"input": "2\n2 1",
"output": "2 1"
},
{
"input": "60\n2 4 31 51 11 7 34 20 3 14 18 23 48 54 15 36 38 60 49 40 5 33 41 26 55 58 10 8 13 9 27 30 37 1 21 59 44 57 35 19 46 43 42 45 12 22 39 32 24 16 6 56 53 52 25 17 47 29 50 28",
"output": "34 1 9 2 21 51 6 28 30 27 5 45 29 10 15 50 56 11 40 8 35 46 12 49 55 24 31 60 58 32 3 48 22 7 39 16 33 17 47 20 23 43 42 37 44 41 57 13 19 59 4 54 53 14 25 52 38 26 36 18"
},
{
"input": "14\n14 6 3 12 11 2 7 1 10 9 8 5 4 13",
"output": "8 6 3 13 12 2 7 11 10 9 5 4 14 1"
},
{
"input": "81\n13 43 79 8 7 21 73 46 63 4 62 78 56 11 70 68 61 53 60 49 16 27 59 47 69 5 22 44 77 57 52 48 1 9 72 81 28 55 58 33 51 18 31 17 41 20 42 3 32 54 19 2 75 34 64 10 65 50 30 29 67 12 71 66 74 15 26 23 6 38 25 35 37 24 80 76 40 45 39 36 14",
"output": "33 52 48 10 26 69 5 4 34 56 14 62 1 81 66 21 44 42 51 46 6 27 68 74 71 67 22 37 60 59 43 49 40 54 72 80 73 70 79 77 45 47 2 28 78 8 24 32 20 58 41 31 18 50 38 13 30 39 23 19 17 11 9 55 57 64 61 16 25 15 63 35 7 65 53 76 29 12 3 75 36"
},
{
"input": "42\n41 11 10 8 21 37 32 19 31 25 1 15 36 5 6 27 4 3 13 7 16 17 2 23 34 24 38 28 12 20 30 42 18 26 39 35 33 40 9 14 22 29",
"output": "11 23 18 17 14 15 20 4 39 3 2 29 19 40 12 21 22 33 8 30 5 41 24 26 10 34 16 28 42 31 9 7 37 25 36 13 6 27 35 38 1 32"
},
{
"input": "97\n20 6 76 42 4 18 35 59 39 63 27 7 66 47 61 52 15 36 88 93 19 33 10 92 1 34 46 86 78 57 51 94 77 29 26 73 41 2 58 97 43 65 17 74 21 49 25 3 91 82 95 12 96 13 84 90 69 24 72 37 16 55 54 71 64 62 48 89 11 70 80 67 30 40 44 85 53 83 79 9 56 45 75 87 22 14 81 68 8 38 60 50 28 23 31 32 5",
"output": "25 38 48 5 97 2 12 89 80 23 69 52 54 86 17 61 43 6 21 1 45 85 94 58 47 35 11 93 34 73 95 96 22 26 7 18 60 90 9 74 37 4 41 75 82 27 14 67 46 92 31 16 77 63 62 81 30 39 8 91 15 66 10 65 42 13 72 88 57 70 64 59 36 44 83 3 33 29 79 71 87 50 78 55 76 28 84 19 68 56 49 24 20 32 51 53 40"
},
{
"input": "62\n15 27 46 6 8 51 14 56 23 48 42 49 52 22 20 31 29 12 47 3 62 34 37 35 32 57 19 25 5 60 61 38 18 10 11 55 45 53 17 30 9 36 4 50 41 16 44 28 40 59 24 1 13 39 26 7 33 58 2 43 21 54",
"output": "52 59 20 43 29 4 56 5 41 34 35 18 53 7 1 46 39 33 27 15 61 14 9 51 28 55 2 48 17 40 16 25 57 22 24 42 23 32 54 49 45 11 60 47 37 3 19 10 12 44 6 13 38 62 36 8 26 58 50 30 31 21"
},
{
"input": "61\n35 27 4 61 52 32 41 46 14 37 17 54 55 31 11 26 44 49 15 30 9 50 45 39 7 38 53 3 58 40 13 56 18 19 28 6 43 5 21 42 20 34 2 25 36 12 33 57 16 60 1 8 59 10 22 23 24 48 51 47 29",
"output": "51 43 28 3 38 36 25 52 21 54 15 46 31 9 19 49 11 33 34 41 39 55 56 57 44 16 2 35 61 20 14 6 47 42 1 45 10 26 24 30 7 40 37 17 23 8 60 58 18 22 59 5 27 12 13 32 48 29 53 50 4"
},
{
"input": "59\n31 26 36 15 17 19 10 53 11 34 13 46 55 9 44 7 8 37 32 52 47 25 51 22 35 39 41 4 43 24 5 27 20 57 6 38 3 28 21 40 50 18 14 56 33 45 12 2 49 59 54 29 16 48 42 58 1 30 23",
"output": "57 48 37 28 31 35 16 17 14 7 9 47 11 43 4 53 5 42 6 33 39 24 59 30 22 2 32 38 52 58 1 19 45 10 25 3 18 36 26 40 27 55 29 15 46 12 21 54 49 41 23 20 8 51 13 44 34 56 50"
},
{
"input": "10\n2 10 7 4 1 5 8 6 3 9",
"output": "5 1 9 4 6 8 3 7 10 2"
},
{
"input": "14\n14 2 1 8 6 12 11 10 9 7 3 4 5 13",
"output": "3 2 11 12 13 5 10 4 9 8 7 6 14 1"
},
{
"input": "43\n28 38 15 14 31 42 27 30 19 33 43 26 22 29 18 32 3 13 1 8 35 34 4 12 11 17 41 21 5 25 39 37 20 23 7 24 16 10 40 9 6 36 2",
"output": "19 43 17 23 29 41 35 20 40 38 25 24 18 4 3 37 26 15 9 33 28 13 34 36 30 12 7 1 14 8 5 16 10 22 21 42 32 2 31 39 27 6 11"
},
{
"input": "86\n39 11 20 31 28 76 29 64 35 21 41 71 12 82 5 37 80 73 38 26 79 75 23 15 59 45 47 6 3 62 50 49 51 22 2 65 86 60 70 42 74 17 1 30 55 44 8 66 81 27 57 77 43 13 54 32 72 46 48 56 14 34 78 52 36 85 24 19 69 83 25 61 7 4 84 33 63 58 18 40 68 10 67 9 16 53",
"output": "43 35 29 74 15 28 73 47 84 82 2 13 54 61 24 85 42 79 68 3 10 34 23 67 71 20 50 5 7 44 4 56 76 62 9 65 16 19 1 80 11 40 53 46 26 58 27 59 32 31 33 64 86 55 45 60 51 78 25 38 72 30 77 8 36 48 83 81 69 39 12 57 18 41 22 6 52 63 21 17 49 14 70 75 66 37"
},
{
"input": "99\n65 78 56 98 33 24 61 40 29 93 1 64 57 22 25 52 67 95 50 3 31 15 90 68 71 83 38 36 6 46 89 26 4 87 14 88 72 37 23 43 63 12 80 96 5 34 73 86 9 48 92 62 99 10 16 20 66 27 28 2 82 70 30 94 49 8 84 69 18 60 58 59 44 39 21 7 91 76 54 19 75 85 74 47 55 32 97 77 51 13 35 79 45 42 11 41 17 81 53",
"output": "11 60 20 33 45 29 76 66 49 54 95 42 90 35 22 55 97 69 80 56 75 14 39 6 15 32 58 59 9 63 21 86 5 46 91 28 38 27 74 8 96 94 40 73 93 30 84 50 65 19 89 16 99 79 85 3 13 71 72 70 7 52 41 12 1 57 17 24 68 62 25 37 47 83 81 78 88 2 92 43 98 61 26 67 82 48 34 36 31 23 77 51 10 64 18 44 87 4 53"
},
{
"input": "100\n42 23 48 88 36 6 18 70 96 1 34 40 46 22 39 55 85 93 45 67 71 75 59 9 21 3 86 63 65 68 20 38 73 31 84 90 50 51 56 95 72 33 49 19 83 76 54 74 100 30 17 98 15 94 4 97 5 99 81 27 92 32 89 12 13 91 87 29 60 11 52 43 35 58 10 25 16 80 28 2 44 61 8 82 66 69 41 24 57 62 78 37 79 77 53 7 14 47 26 64",
"output": "10 80 26 55 57 6 96 83 24 75 70 64 65 97 53 77 51 7 44 31 25 14 2 88 76 99 60 79 68 50 34 62 42 11 73 5 92 32 15 12 87 1 72 81 19 13 98 3 43 37 38 71 95 47 16 39 89 74 23 69 82 90 28 100 29 85 20 30 86 8 21 41 33 48 22 46 94 91 93 78 59 84 45 35 17 27 67 4 63 36 66 61 18 54 40 9 56 52 58 49"
},
{
"input": "99\n8 68 94 75 71 60 57 58 6 11 5 48 65 41 49 12 46 72 95 59 13 70 74 7 84 62 17 36 55 76 38 79 2 85 23 10 32 99 87 50 83 28 54 91 53 51 1 3 97 81 21 89 93 78 61 26 82 96 4 98 25 40 31 44 24 47 30 52 14 16 39 27 9 29 45 18 67 63 37 43 90 66 19 69 88 22 92 77 34 42 73 80 56 64 20 35 15 33 86",
"output": "47 33 48 59 11 9 24 1 73 36 10 16 21 69 97 70 27 76 83 95 51 86 35 65 61 56 72 42 74 67 63 37 98 89 96 28 79 31 71 62 14 90 80 64 75 17 66 12 15 40 46 68 45 43 29 93 7 8 20 6 55 26 78 94 13 82 77 2 84 22 5 18 91 23 4 30 88 54 32 92 50 57 41 25 34 99 39 85 52 81 44 87 53 3 19 58 49 60 38"
},
{
"input": "99\n12 99 88 13 7 19 74 47 23 90 16 29 26 11 58 60 64 98 37 18 82 67 72 46 51 85 17 92 87 20 77 36 78 71 57 35 80 54 73 15 14 62 97 45 31 79 94 56 76 96 28 63 8 44 38 86 49 2 52 66 61 59 10 43 55 50 22 34 83 53 95 40 81 21 30 42 27 3 5 41 1 70 69 25 93 48 65 6 24 89 91 33 39 68 9 4 32 84 75",
"output": "81 58 78 96 79 88 5 53 95 63 14 1 4 41 40 11 27 20 6 30 74 67 9 89 84 13 77 51 12 75 45 97 92 68 36 32 19 55 93 72 80 76 64 54 44 24 8 86 57 66 25 59 70 38 65 48 35 15 62 16 61 42 52 17 87 60 22 94 83 82 34 23 39 7 99 49 31 33 46 37 73 21 69 98 26 56 29 3 90 10 91 28 85 47 71 50 43 18 2"
},
{
"input": "99\n20 79 26 75 99 69 98 47 93 62 18 42 43 38 90 66 67 8 13 84 76 58 81 60 64 46 56 23 78 17 86 36 19 52 85 39 48 27 96 49 37 95 5 31 10 24 12 1 80 35 92 33 16 68 57 54 32 29 45 88 72 77 4 87 97 89 59 3 21 22 61 94 83 15 44 34 70 91 55 9 51 50 73 11 14 6 40 7 63 25 2 82 41 65 28 74 71 30 53",
"output": "48 91 68 63 43 86 88 18 80 45 84 47 19 85 74 53 30 11 33 1 69 70 28 46 90 3 38 95 58 98 44 57 52 76 50 32 41 14 36 87 93 12 13 75 59 26 8 37 40 82 81 34 99 56 79 27 55 22 67 24 71 10 89 25 94 16 17 54 6 77 97 61 83 96 4 21 62 29 2 49 23 92 73 20 35 31 64 60 66 15 78 51 9 72 42 39 65 7 5"
},
{
"input": "99\n74 20 9 1 60 85 65 13 4 25 40 99 5 53 64 3 36 31 73 44 55 50 45 63 98 51 68 6 47 37 71 82 88 34 84 18 19 12 93 58 86 7 11 46 90 17 33 27 81 69 42 59 56 32 95 52 76 61 96 62 78 43 66 21 49 97 75 14 41 72 89 16 30 79 22 23 15 83 91 38 48 2 87 26 28 80 94 70 54 92 57 10 8 35 67 77 29 24 39",
"output": "4 82 16 9 13 28 42 93 3 92 43 38 8 68 77 72 46 36 37 2 64 75 76 98 10 84 48 85 97 73 18 54 47 34 94 17 30 80 99 11 69 51 62 20 23 44 29 81 65 22 26 56 14 89 21 53 91 40 52 5 58 60 24 15 7 63 95 27 50 88 31 70 19 1 67 57 96 61 74 86 49 32 78 35 6 41 83 33 71 45 79 90 39 87 55 59 66 25 12"
},
{
"input": "99\n50 94 2 18 69 90 59 83 75 68 77 97 39 78 25 7 16 9 49 4 42 89 44 48 17 96 61 70 3 10 5 81 56 57 88 6 98 1 46 67 92 37 11 30 85 41 8 36 51 29 20 71 19 79 74 93 43 34 55 40 38 21 64 63 32 24 72 14 12 86 82 15 65 23 66 22 28 53 13 26 95 99 91 52 76 27 60 45 47 33 73 84 31 35 54 80 58 62 87",
"output": "38 3 29 20 31 36 16 47 18 30 43 69 79 68 72 17 25 4 53 51 62 76 74 66 15 80 86 77 50 44 93 65 90 58 94 48 42 61 13 60 46 21 57 23 88 39 89 24 19 1 49 84 78 95 59 33 34 97 7 87 27 98 64 63 73 75 40 10 5 28 52 67 91 55 9 85 11 14 54 96 32 71 8 92 45 70 99 35 22 6 83 41 56 2 81 26 12 37 82"
},
{
"input": "99\n19 93 14 34 39 37 33 15 52 88 7 43 69 27 9 77 94 31 48 22 63 70 79 17 50 6 81 8 76 58 23 74 86 11 57 62 41 87 75 51 12 18 68 56 95 3 80 83 84 29 24 61 71 78 59 96 20 85 90 28 45 36 38 97 1 49 40 98 44 67 13 73 72 91 47 10 30 54 35 42 4 2 92 26 64 60 53 21 5 82 46 32 55 66 16 89 99 65 25",
"output": "65 82 46 81 89 26 11 28 15 76 34 41 71 3 8 95 24 42 1 57 88 20 31 51 99 84 14 60 50 77 18 92 7 4 79 62 6 63 5 67 37 80 12 69 61 91 75 19 66 25 40 9 87 78 93 44 35 30 55 86 52 36 21 85 98 94 70 43 13 22 53 73 72 32 39 29 16 54 23 47 27 90 48 49 58 33 38 10 96 59 74 83 2 17 45 56 64 68 97"
},
{
"input": "99\n86 25 50 51 62 39 41 67 44 20 45 14 80 88 66 7 36 59 13 84 78 58 96 75 2 43 48 47 69 12 19 98 22 38 28 55 11 76 68 46 53 70 85 34 16 33 91 30 8 40 74 60 94 82 87 32 37 4 5 10 89 73 90 29 35 26 23 57 27 65 24 3 9 83 77 72 6 31 15 92 93 79 64 18 63 42 56 1 52 97 17 81 71 21 49 99 54 95 61",
"output": "88 25 72 58 59 77 16 49 73 60 37 30 19 12 79 45 91 84 31 10 94 33 67 71 2 66 69 35 64 48 78 56 46 44 65 17 57 34 6 50 7 86 26 9 11 40 28 27 95 3 4 89 41 97 36 87 68 22 18 52 99 5 85 83 70 15 8 39 29 42 93 76 62 51 24 38 75 21 82 13 92 54 74 20 43 1 55 14 61 63 47 80 81 53 98 23 90 32 96"
},
{
"input": "100\n66 44 99 15 43 79 28 33 88 90 49 68 82 38 9 74 4 58 29 81 31 94 10 42 89 21 63 40 62 61 18 6 84 72 48 25 67 69 71 85 98 34 83 70 65 78 91 77 93 41 23 24 87 11 55 12 59 73 36 97 7 14 26 39 30 27 45 20 50 17 53 2 57 47 95 56 75 19 37 96 16 35 8 3 76 60 13 86 5 32 64 80 46 51 54 100 1 22 52 92",
"output": "97 72 84 17 89 32 61 83 15 23 54 56 87 62 4 81 70 31 78 68 26 98 51 52 36 63 66 7 19 65 21 90 8 42 82 59 79 14 64 28 50 24 5 2 67 93 74 35 11 69 94 99 71 95 55 76 73 18 57 86 30 29 27 91 45 1 37 12 38 44 39 34 58 16 77 85 48 46 6 92 20 13 43 33 40 88 53 9 25 10 47 100 49 22 75 80 60 41 3 96"
},
{
"input": "99\n3 73 32 37 25 15 93 63 85 8 91 78 80 5 39 48 46 7 83 70 23 96 9 29 77 53 30 20 56 50 13 45 21 76 87 99 65 31 16 18 14 72 51 28 43 2 81 34 38 40 66 54 74 26 71 4 61 17 58 24 22 33 49 36 42 11 12 55 60 27 62 90 79 92 94 68 1 52 84 41 86 35 69 75 47 10 64 88 97 98 67 19 89 95 59 82 57 44 6",
"output": "77 46 1 56 14 99 18 10 23 86 66 67 31 41 6 39 58 40 92 28 33 61 21 60 5 54 70 44 24 27 38 3 62 48 82 64 4 49 15 50 80 65 45 98 32 17 85 16 63 30 43 78 26 52 68 29 97 59 95 69 57 71 8 87 37 51 91 76 83 20 55 42 2 53 84 34 25 12 73 13 47 96 19 79 9 81 35 88 93 72 11 74 7 75 94 22 89 90 36"
},
{
"input": "100\n100 99 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",
"output": "100 99 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"
}
] | 1,677,615,234 | 2,147,483,647 | Python 3 | OK | TESTS | 101 | 92 | 0 | n = int(input())
a = list(map(int, input().split()))
num_list = [0] * n
for i in range(n):
num_list[a[i] - 1] = i + 1
print(*num_list)
| Title: Presents
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Little Petya very much likes gifts. Recently he has received a new laptop as a New Year gift from his mother. He immediately decided to give it to somebody else as what can be more pleasant than giving somebody gifts. And on this occasion he organized a New Year party at his place and invited *n* his friends there.
If there's one thing Petya likes more that receiving gifts, that's watching others giving gifts to somebody else. Thus, he safely hid the laptop until the next New Year and made up his mind to watch his friends exchanging gifts while he does not participate in the process. He numbered all his friends with integers from 1 to *n*. Petya remembered that a friend number *i* gave a gift to a friend number *p**i*. He also remembered that each of his friends received exactly one gift.
Now Petya wants to know for each friend *i* the number of a friend who has given him a gift.
Input Specification:
The first line contains one integer *n* (1<=≤<=*n*<=≤<=100) — the quantity of friends Petya invited to the party. The second line contains *n* space-separated integers: the *i*-th number is *p**i* — the number of a friend who gave a gift to friend number *i*. It is guaranteed that each friend received exactly one gift. It is possible that some friends do not share Petya's ideas of giving gifts to somebody else. Those friends gave the gifts to themselves.
Output Specification:
Print *n* space-separated integers: the *i*-th number should equal the number of the friend who gave a gift to friend number *i*.
Demo Input:
['4\n2 3 4 1\n', '3\n1 3 2\n', '2\n1 2\n']
Demo Output:
['4 1 2 3\n', '1 3 2\n', '1 2\n']
Note:
none | ```python
n = int(input())
a = list(map(int, input().split()))
num_list = [0] * n
for i in range(n):
num_list[a[i] - 1] = i + 1
print(*num_list)
``` | 3 |
|
828 | A | Restaurant Tables | PROGRAMMING | 1,200 | [
"implementation"
] | null | null | In a small restaurant there are *a* tables for one person and *b* tables for two persons.
It it known that *n* groups of people come today, each consisting of one or two people.
If a group consist of one person, it is seated at a vacant one-seater table. If there are none of them, it is seated at a vacant two-seater table. If there are none of them, it is seated at a two-seater table occupied by single person. If there are still none of them, the restaurant denies service to this group.
If a group consist of two people, it is seated at a vacant two-seater table. If there are none of them, the restaurant denies service to this group.
You are given a chronological order of groups coming. You are to determine the total number of people the restaurant denies service to. | The first line contains three integers *n*, *a* and *b* (1<=≤<=*n*<=≤<=2·105, 1<=≤<=*a*,<=*b*<=≤<=2·105) — the number of groups coming to the restaurant, the number of one-seater and the number of two-seater tables.
The second line contains a sequence of integers *t*1,<=*t*2,<=...,<=*t**n* (1<=≤<=*t**i*<=≤<=2) — the description of clients in chronological order. If *t**i* is equal to one, then the *i*-th group consists of one person, otherwise the *i*-th group consists of two people. | Print the total number of people the restaurant denies service to. | [
"4 1 2\n1 2 1 1\n",
"4 1 1\n1 1 2 1\n"
] | [
"0\n",
"2\n"
] | In the first example the first group consists of one person, it is seated at a vacant one-seater table. The next group occupies a whole two-seater table. The third group consists of one person, it occupies one place at the remaining two-seater table. The fourth group consists of one person, he is seated at the remaining seat at the two-seater table. Thus, all clients are served.
In the second example the first group consists of one person, it is seated at the vacant one-seater table. The next group consists of one person, it occupies one place at the two-seater table. It's impossible to seat the next group of two people, so the restaurant denies service to them. The fourth group consists of one person, he is seated at the remaining seat at the two-seater table. Thus, the restaurant denies service to 2 clients. | 500 | [
{
"input": "4 1 2\n1 2 1 1",
"output": "0"
},
{
"input": "4 1 1\n1 1 2 1",
"output": "2"
},
{
"input": "1 1 1\n1",
"output": "0"
},
{
"input": "2 1 2\n2 2",
"output": "0"
},
{
"input": "5 1 3\n1 2 2 2 1",
"output": "1"
},
{
"input": "7 6 1\n1 1 1 1 1 1 1",
"output": "0"
},
{
"input": "10 2 1\n2 1 2 2 2 2 1 2 1 2",
"output": "13"
},
{
"input": "20 4 3\n2 2 2 2 2 2 2 2 1 2 1 1 2 2 1 2 2 2 1 2",
"output": "25"
},
{
"input": "1 1 1\n1",
"output": "0"
},
{
"input": "1 1 1\n2",
"output": "0"
},
{
"input": "1 200000 200000\n2",
"output": "0"
},
{
"input": "30 10 10\n1 1 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",
"output": "20"
},
{
"input": "4 1 2\n1 1 1 2",
"output": "2"
},
{
"input": "6 2 3\n1 2 1 1 1 2",
"output": "2"
},
{
"input": "6 1 4\n1 1 1 1 1 2",
"output": "2"
},
{
"input": "6 1 3\n1 1 1 1 2 2",
"output": "4"
},
{
"input": "6 1 3\n1 1 1 1 1 2",
"output": "2"
},
{
"input": "6 4 2\n2 1 2 2 1 1",
"output": "2"
},
{
"input": "3 10 1\n2 2 2",
"output": "4"
},
{
"input": "5 1 3\n1 1 1 1 2",
"output": "2"
},
{
"input": "5 2 2\n1 1 1 1 2",
"output": "2"
},
{
"input": "15 5 5\n1 1 1 1 1 1 1 1 1 1 2 2 2 2 2",
"output": "10"
},
{
"input": "5 1 2\n1 1 1 1 1",
"output": "0"
},
{
"input": "3 6 1\n2 2 2",
"output": "4"
},
{
"input": "5 3 3\n2 2 2 2 2",
"output": "4"
},
{
"input": "8 3 3\n1 1 1 1 1 1 2 2",
"output": "4"
},
{
"input": "5 1 2\n1 1 1 2 1",
"output": "2"
},
{
"input": "6 1 4\n1 2 2 1 2 2",
"output": "2"
},
{
"input": "2 1 1\n2 2",
"output": "2"
},
{
"input": "2 2 1\n2 2",
"output": "2"
},
{
"input": "5 8 1\n2 2 2 2 2",
"output": "8"
},
{
"input": "3 1 4\n1 1 2",
"output": "0"
},
{
"input": "7 1 5\n1 1 1 1 1 1 2",
"output": "2"
},
{
"input": "6 1 3\n1 1 1 2 1 1",
"output": "0"
},
{
"input": "6 1 2\n1 1 1 2 2 2",
"output": "6"
},
{
"input": "8 1 4\n2 1 1 1 2 2 2 2",
"output": "6"
},
{
"input": "4 2 3\n2 2 2 2",
"output": "2"
},
{
"input": "3 1 1\n1 1 2",
"output": "2"
},
{
"input": "5 1 1\n2 2 2 2 2",
"output": "8"
},
{
"input": "10 1 5\n1 1 1 1 1 2 2 2 2 2",
"output": "8"
},
{
"input": "5 1 2\n1 1 1 2 2",
"output": "4"
},
{
"input": "4 1 1\n1 1 2 2",
"output": "4"
},
{
"input": "7 1 2\n1 1 1 1 1 1 1",
"output": "2"
},
{
"input": "5 1 4\n2 2 2 2 2",
"output": "2"
},
{
"input": "6 2 3\n1 1 1 1 2 2",
"output": "2"
},
{
"input": "5 2 2\n2 1 2 1 2",
"output": "2"
},
{
"input": "4 6 1\n2 2 2 2",
"output": "6"
},
{
"input": "6 1 4\n1 1 2 1 1 2",
"output": "2"
},
{
"input": "7 1 3\n1 1 1 1 2 2 2",
"output": "6"
},
{
"input": "4 1 2\n1 1 2 2",
"output": "2"
},
{
"input": "3 1 2\n1 1 2",
"output": "0"
},
{
"input": "6 1 3\n1 2 1 1 2 1",
"output": "2"
},
{
"input": "6 1 3\n1 1 1 2 2 2",
"output": "4"
},
{
"input": "10 2 2\n1 1 1 1 2 2 2 2 2 2",
"output": "12"
},
{
"input": "10 1 4\n1 1 1 1 1 2 2 2 2 2",
"output": "10"
},
{
"input": "3 10 2\n2 2 2",
"output": "2"
},
{
"input": "4 3 1\n1 2 2 2",
"output": "4"
},
{
"input": "7 1 4\n1 1 1 1 1 2 2",
"output": "4"
},
{
"input": "3 4 1\n2 2 2",
"output": "4"
},
{
"input": "4 1 2\n2 1 1 2",
"output": "2"
},
{
"input": "10 1 2\n1 1 1 1 1 1 1 1 1 2",
"output": "6"
},
{
"input": "5 1 3\n1 1 2 1 2",
"output": "2"
},
{
"input": "6 1 3\n1 1 1 1 2 1",
"output": "2"
},
{
"input": "6 1 4\n1 1 1 2 2 2",
"output": "2"
},
{
"input": "7 1 2\n1 2 1 1 1 1 1",
"output": "3"
},
{
"input": "6 2 2\n1 1 1 1 1 1",
"output": "0"
},
{
"input": "6 1 2\n1 1 2 1 1 1",
"output": "2"
},
{
"input": "3 3 1\n2 2 1",
"output": "2"
},
{
"input": "8 4 2\n1 1 1 1 1 1 1 2",
"output": "2"
},
{
"input": "9 1 4\n1 1 1 1 1 2 2 2 2",
"output": "8"
},
{
"input": "5 10 1\n2 2 2 2 2",
"output": "8"
},
{
"input": "3 5 1\n2 2 2",
"output": "4"
},
{
"input": "5 100 1\n2 2 2 2 2",
"output": "8"
},
{
"input": "4 1 2\n1 1 1 1",
"output": "0"
},
{
"input": "4 1 1\n1 1 1 1",
"output": "1"
},
{
"input": "7 2 2\n1 1 1 1 1 1 1",
"output": "1"
}
] | 1,532,603,991 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 4 | 109 | 0 | def main():
n, a, b = map(int, input().split())
l, r = list(input()[::-2]), 0
while l:
if l.pop() == '1':
if a:
a -= 1
elif b:
a += 1
b -= 1
else:
break
else:
if b:
b -= 1
else:
r += 2
print(r + sum(map(int, l)))
if __name__ == '__main__':
main()
| Title: Restaurant Tables
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
In a small restaurant there are *a* tables for one person and *b* tables for two persons.
It it known that *n* groups of people come today, each consisting of one or two people.
If a group consist of one person, it is seated at a vacant one-seater table. If there are none of them, it is seated at a vacant two-seater table. If there are none of them, it is seated at a two-seater table occupied by single person. If there are still none of them, the restaurant denies service to this group.
If a group consist of two people, it is seated at a vacant two-seater table. If there are none of them, the restaurant denies service to this group.
You are given a chronological order of groups coming. You are to determine the total number of people the restaurant denies service to.
Input Specification:
The first line contains three integers *n*, *a* and *b* (1<=≤<=*n*<=≤<=2·105, 1<=≤<=*a*,<=*b*<=≤<=2·105) — the number of groups coming to the restaurant, the number of one-seater and the number of two-seater tables.
The second line contains a sequence of integers *t*1,<=*t*2,<=...,<=*t**n* (1<=≤<=*t**i*<=≤<=2) — the description of clients in chronological order. If *t**i* is equal to one, then the *i*-th group consists of one person, otherwise the *i*-th group consists of two people.
Output Specification:
Print the total number of people the restaurant denies service to.
Demo Input:
['4 1 2\n1 2 1 1\n', '4 1 1\n1 1 2 1\n']
Demo Output:
['0\n', '2\n']
Note:
In the first example the first group consists of one person, it is seated at a vacant one-seater table. The next group occupies a whole two-seater table. The third group consists of one person, it occupies one place at the remaining two-seater table. The fourth group consists of one person, he is seated at the remaining seat at the two-seater table. Thus, all clients are served.
In the second example the first group consists of one person, it is seated at the vacant one-seater table. The next group consists of one person, it occupies one place at the two-seater table. It's impossible to seat the next group of two people, so the restaurant denies service to them. The fourth group consists of one person, he is seated at the remaining seat at the two-seater table. Thus, the restaurant denies service to 2 clients. | ```python
def main():
n, a, b = map(int, input().split())
l, r = list(input()[::-2]), 0
while l:
if l.pop() == '1':
if a:
a -= 1
elif b:
a += 1
b -= 1
else:
break
else:
if b:
b -= 1
else:
r += 2
print(r + sum(map(int, l)))
if __name__ == '__main__':
main()
``` | 0 |
|
155 | A | I_love_\%username\% | PROGRAMMING | 800 | [
"brute force"
] | null | null | Vasya adores sport programming. He can't write programs but he loves to watch the contests' progress. Vasya even has a favorite coder and Vasya pays special attention to him.
One day Vasya decided to collect the results of all contests where his favorite coder participated and track the progress of his coolness. For each contest where this coder participated, he wrote out a single non-negative number — the number of points his favorite coder earned in the contest. Vasya wrote out the points for the contest in the order, in which the contests run (naturally, no two contests ran simultaneously).
Vasya considers a coder's performance in a contest amazing in two situations: he can break either his best or his worst performance record. First, it is amazing if during the contest the coder earns strictly more points that he earned on each past contest. Second, it is amazing if during the contest the coder earns strictly less points that he earned on each past contest. A coder's first contest isn't considered amazing. Now he wants to count the number of amazing performances the coder had throughout his whole history of participating in contests. But the list of earned points turned out long and Vasya can't code... That's why he asks you to help him. | The first line contains the single integer *n* (1<=≤<=*n*<=≤<=1000) — the number of contests where the coder participated.
The next line contains *n* space-separated non-negative integer numbers — they are the points which the coder has earned. The points are given in the chronological order. All points do not exceed 10000. | Print the single number — the number of amazing performances the coder has had during his whole history of participating in the contests. | [
"5\n100 50 200 150 200\n",
"10\n4664 6496 5814 7010 5762 5736 6944 4850 3698 7242\n"
] | [
"2\n",
"4\n"
] | In the first sample the performances number 2 and 3 are amazing.
In the second sample the performances number 2, 4, 9 and 10 are amazing. | 500 | [
{
"input": "5\n100 50 200 150 200",
"output": "2"
},
{
"input": "10\n4664 6496 5814 7010 5762 5736 6944 4850 3698 7242",
"output": "4"
},
{
"input": "1\n6",
"output": "0"
},
{
"input": "2\n2 1",
"output": "1"
},
{
"input": "5\n100 36 53 7 81",
"output": "2"
},
{
"input": "5\n7 36 53 81 100",
"output": "4"
},
{
"input": "5\n100 81 53 36 7",
"output": "4"
},
{
"input": "10\n8 6 3 4 9 10 7 7 1 3",
"output": "5"
},
{
"input": "10\n1627 1675 1488 1390 1812 1137 1746 1324 1952 1862",
"output": "6"
},
{
"input": "10\n1 3 3 4 6 7 7 8 9 10",
"output": "7"
},
{
"input": "10\n1952 1862 1812 1746 1675 1627 1488 1390 1324 1137",
"output": "9"
},
{
"input": "25\n1448 4549 2310 2725 2091 3509 1565 2475 2232 3989 4231 779 2967 2702 608 3739 721 1552 2767 530 3114 665 1940 48 4198",
"output": "5"
},
{
"input": "33\n1097 1132 1091 1104 1049 1038 1023 1080 1104 1029 1035 1061 1049 1060 1088 1106 1105 1087 1063 1076 1054 1103 1047 1041 1028 1120 1126 1063 1117 1110 1044 1093 1101",
"output": "5"
},
{
"input": "34\n821 5536 2491 6074 7216 9885 764 1603 778 8736 8987 771 617 1587 8943 7922 439 7367 4115 8886 7878 6899 8811 5752 3184 3401 9760 9400 8995 4681 1323 6637 6554 6498",
"output": "7"
},
{
"input": "68\n6764 6877 6950 6768 6839 6755 6726 6778 6699 6805 6777 6985 6821 6801 6791 6805 6940 6761 6677 6999 6911 6699 6959 6933 6903 6843 6972 6717 6997 6756 6789 6668 6735 6852 6735 6880 6723 6834 6810 6694 6780 6679 6698 6857 6826 6896 6979 6968 6957 6988 6960 6700 6919 6892 6984 6685 6813 6678 6715 6857 6976 6902 6780 6686 6777 6686 6842 6679",
"output": "9"
},
{
"input": "60\n9000 9014 9034 9081 9131 9162 9174 9199 9202 9220 9221 9223 9229 9235 9251 9260 9268 9269 9270 9298 9307 9309 9313 9323 9386 9399 9407 9495 9497 9529 9531 9544 9614 9615 9627 9627 9643 9654 9656 9657 9685 9699 9701 9736 9745 9758 9799 9827 9843 9845 9854 9854 9885 9891 9896 9913 9942 9963 9986 9992",
"output": "57"
},
{
"input": "100\n7 61 12 52 41 16 34 99 30 44 48 89 31 54 21 1 48 52 61 15 35 87 21 76 64 92 44 81 16 93 84 92 32 15 68 76 53 39 26 4 11 26 7 4 99 99 61 65 55 85 65 67 47 39 2 74 63 49 98 87 5 94 22 30 25 42 31 84 49 23 89 60 16 26 92 27 9 57 75 61 94 35 83 47 99 100 63 24 91 88 79 10 15 45 22 64 3 11 89 83",
"output": "4"
},
{
"input": "100\n9999 9999 9999 9998 9998 9998 9997 9996 9996 9995 9993 9993 9991 9990 9989 9986 9984 9984 9983 9981 9981 9980 9980 9980 9979 9977 9977 9977 9977 9977 9976 9976 9975 9975 9973 9972 9972 9972 9972 9971 9969 9969 9969 9968 9967 9965 9962 9962 9962 9962 9960 9958 9958 9955 9954 9954 9954 9954 9950 9949 9949 9947 9943 9943 9940 9940 9939 9937 9937 9937 9936 9935 9932 9932 9931 9929 9927 9927 9926 9923 9919 9919 9918 9918 9918 9917 9917 9916 9916 9915 9914 9911 9910 9907 9907 9906 9905 9905 9904 9901",
"output": "57"
},
{
"input": "100\n158 159 157 156 155 154 160 153 161 152 162 163 151 164 150 165 149 148 147 166 146 167 145 144 143 142 168 141 169 170 140 139 138 137 171 136 135 134 172 173 174 133 175 132 177 178 131 179 180 130 129 181 128 127 182 126 183 125 124 184 123 122 121 120 119 118 117 185 186 187 188 189 116 190 115 191 192 193 114 113 112 111 110 109 108 194 195 107 106 105 196 197 104 198 199 103 102 200 101 100",
"output": "99"
},
{
"input": "2\n0 10000",
"output": "1"
},
{
"input": "2\n5 5",
"output": "0"
},
{
"input": "2\n1 1",
"output": "0"
},
{
"input": "2\n10 10",
"output": "0"
},
{
"input": "1\n0",
"output": "0"
}
] | 1,674,828,579 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 37 | 124 | 0 | n = input()
points = list(map(int, input().split(" ")))
maxm = points[0]
minm = points[0]
num_amazing = 0
for point in points[1:]:
if point > maxm:
num_amazing += 1
maxm = point
elif point < minm:
num_amazing += 1
minm = point
print(num_amazing) | Title: I_love_\%username\%
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vasya adores sport programming. He can't write programs but he loves to watch the contests' progress. Vasya even has a favorite coder and Vasya pays special attention to him.
One day Vasya decided to collect the results of all contests where his favorite coder participated and track the progress of his coolness. For each contest where this coder participated, he wrote out a single non-negative number — the number of points his favorite coder earned in the contest. Vasya wrote out the points for the contest in the order, in which the contests run (naturally, no two contests ran simultaneously).
Vasya considers a coder's performance in a contest amazing in two situations: he can break either his best or his worst performance record. First, it is amazing if during the contest the coder earns strictly more points that he earned on each past contest. Second, it is amazing if during the contest the coder earns strictly less points that he earned on each past contest. A coder's first contest isn't considered amazing. Now he wants to count the number of amazing performances the coder had throughout his whole history of participating in contests. But the list of earned points turned out long and Vasya can't code... That's why he asks you to help him.
Input Specification:
The first line contains the single integer *n* (1<=≤<=*n*<=≤<=1000) — the number of contests where the coder participated.
The next line contains *n* space-separated non-negative integer numbers — they are the points which the coder has earned. The points are given in the chronological order. All points do not exceed 10000.
Output Specification:
Print the single number — the number of amazing performances the coder has had during his whole history of participating in the contests.
Demo Input:
['5\n100 50 200 150 200\n', '10\n4664 6496 5814 7010 5762 5736 6944 4850 3698 7242\n']
Demo Output:
['2\n', '4\n']
Note:
In the first sample the performances number 2 and 3 are amazing.
In the second sample the performances number 2, 4, 9 and 10 are amazing. | ```python
n = input()
points = list(map(int, input().split(" ")))
maxm = points[0]
minm = points[0]
num_amazing = 0
for point in points[1:]:
if point > maxm:
num_amazing += 1
maxm = point
elif point < minm:
num_amazing += 1
minm = point
print(num_amazing)
``` | 3 |
|
144 | A | Arrival of the General | PROGRAMMING | 800 | [
"implementation"
] | null | null | A Ministry for Defense sent a general to inspect the Super Secret Military Squad under the command of the Colonel SuperDuper. Having learned the news, the colonel ordered to all *n* squad soldiers to line up on the parade ground.
By the military charter the soldiers should stand in the order of non-increasing of their height. But as there's virtually no time to do that, the soldiers lined up in the arbitrary order. However, the general is rather short-sighted and he thinks that the soldiers lined up correctly if the first soldier in the line has the maximum height and the last soldier has the minimum height. Please note that the way other solders are positioned does not matter, including the case when there are several soldiers whose height is maximum or minimum. Only the heights of the first and the last soldier are important.
For example, the general considers the sequence of heights (4, 3, 4, 2, 1, 1) correct and the sequence (4, 3, 1, 2, 2) wrong.
Within one second the colonel can swap any two neighboring soldiers. Help him count the minimum time needed to form a line-up which the general will consider correct. | The first input line contains the only integer *n* (2<=≤<=*n*<=≤<=100) which represents the number of soldiers in the line. The second line contains integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=100) the values of the soldiers' heights in the order of soldiers' heights' increasing in the order from the beginning of the line to its end. The numbers are space-separated. Numbers *a*1,<=*a*2,<=...,<=*a**n* are not necessarily different. | Print the only integer — the minimum number of seconds the colonel will need to form a line-up the general will like. | [
"4\n33 44 11 22\n",
"7\n10 10 58 31 63 40 76\n"
] | [
"2\n",
"10\n"
] | In the first sample the colonel will need to swap the first and second soldier and then the third and fourth soldier. That will take 2 seconds. The resulting position of the soldiers is (44, 33, 22, 11).
In the second sample the colonel may swap the soldiers in the following sequence:
1. (10, 10, 58, 31, 63, 40, 76) 1. (10, 58, 10, 31, 63, 40, 76) 1. (10, 58, 10, 31, 63, 76, 40) 1. (10, 58, 10, 31, 76, 63, 40) 1. (10, 58, 31, 10, 76, 63, 40) 1. (10, 58, 31, 76, 10, 63, 40) 1. (10, 58, 31, 76, 63, 10, 40) 1. (10, 58, 76, 31, 63, 10, 40) 1. (10, 76, 58, 31, 63, 10, 40) 1. (76, 10, 58, 31, 63, 10, 40) 1. (76, 10, 58, 31, 63, 40, 10) | 500 | [
{
"input": "4\n33 44 11 22",
"output": "2"
},
{
"input": "7\n10 10 58 31 63 40 76",
"output": "10"
},
{
"input": "2\n88 89",
"output": "1"
},
{
"input": "5\n100 95 100 100 88",
"output": "0"
},
{
"input": "7\n48 48 48 48 45 45 45",
"output": "0"
},
{
"input": "10\n68 47 67 29 63 71 71 65 54 56",
"output": "10"
},
{
"input": "15\n77 68 96 60 92 75 61 60 66 79 80 65 60 95 92",
"output": "4"
},
{
"input": "3\n1 2 1",
"output": "1"
},
{
"input": "20\n30 30 30 14 30 14 30 30 30 14 30 14 14 30 14 14 30 14 14 14",
"output": "0"
},
{
"input": "35\n37 41 46 39 47 39 44 47 44 42 44 43 47 39 46 39 38 42 39 37 40 44 41 42 41 42 39 42 36 36 42 36 42 42 42",
"output": "7"
},
{
"input": "40\n99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 98 99 99 99 99 99 99 99 99 100 99 99 99 99 99 99",
"output": "47"
},
{
"input": "50\n48 52 44 54 53 56 62 49 39 41 53 39 40 64 53 50 62 48 40 52 51 48 40 52 61 62 62 61 48 64 55 57 56 40 48 58 41 60 60 56 64 50 64 45 48 45 46 63 59 57",
"output": "50"
},
{
"input": "57\n7 24 17 19 6 19 10 11 12 22 14 5 5 11 13 10 24 19 24 24 24 11 21 20 4 14 24 24 18 13 24 3 20 3 3 3 3 9 3 9 22 22 16 3 3 3 15 11 3 3 8 17 10 13 3 14 13",
"output": "3"
},
{
"input": "65\n58 50 35 44 35 37 36 58 38 36 58 56 56 49 48 56 58 43 40 44 52 44 58 58 57 50 43 35 55 39 38 49 53 56 50 42 41 56 34 57 49 38 34 51 56 38 58 40 53 46 48 34 38 43 49 49 58 56 41 43 44 34 38 48 36",
"output": "3"
},
{
"input": "69\n70 48 49 48 49 71 48 53 55 69 48 53 54 58 53 63 48 48 69 67 72 75 71 75 74 74 57 63 65 60 48 48 65 48 48 51 50 49 62 53 76 68 76 56 76 76 64 76 76 57 61 76 73 51 59 76 65 50 69 50 76 67 76 63 62 74 74 58 73",
"output": "73"
},
{
"input": "75\n70 65 64 71 71 64 71 64 68 71 65 64 65 68 71 66 66 69 68 63 69 65 71 69 68 68 71 67 71 65 65 65 71 71 65 69 63 66 62 67 64 63 62 64 67 65 62 69 62 64 69 62 67 64 67 70 64 63 64 64 69 62 62 64 70 62 62 68 67 69 62 64 66 70 68",
"output": "7"
},
{
"input": "84\n92 95 84 85 94 80 90 86 80 92 95 84 86 83 86 83 93 91 95 92 84 88 82 84 84 84 80 94 93 80 94 80 95 83 85 80 95 95 80 84 86 92 83 81 90 87 81 89 92 93 80 87 90 85 93 85 93 94 93 89 94 83 93 91 80 83 90 94 95 80 95 92 85 84 93 94 94 82 91 95 95 89 85 94",
"output": "15"
},
{
"input": "90\n86 87 72 77 82 71 75 78 61 67 79 90 64 94 94 74 85 87 73 76 71 71 60 69 77 73 76 80 82 57 62 57 57 83 76 72 75 87 72 94 77 85 59 82 86 69 62 80 95 73 83 94 79 85 91 68 85 74 93 95 68 75 89 93 83 78 95 78 83 77 81 85 66 92 63 65 75 78 67 91 77 74 59 86 77 76 90 67 70 64",
"output": "104"
},
{
"input": "91\n94 98 96 94 95 98 98 95 98 94 94 98 95 95 99 97 97 94 95 98 94 98 96 98 96 98 97 95 94 94 94 97 94 96 98 98 98 94 96 95 94 95 97 97 97 98 94 98 96 95 98 96 96 98 94 97 96 98 97 95 97 98 94 95 94 94 97 94 96 97 97 93 94 95 95 94 96 98 97 96 94 98 98 96 96 96 96 96 94 96 97",
"output": "33"
},
{
"input": "92\n44 28 32 29 41 41 36 39 40 39 41 35 41 28 35 27 41 34 28 38 43 43 41 38 27 26 28 36 30 29 39 32 35 35 32 30 39 30 37 27 41 41 28 30 43 31 35 33 36 28 44 40 41 35 31 42 37 38 37 34 39 40 27 40 33 33 44 43 34 33 34 34 35 38 38 37 30 39 35 41 45 42 41 32 33 33 31 30 43 41 43 43",
"output": "145"
},
{
"input": "93\n46 32 52 36 39 30 57 63 63 30 32 44 27 59 46 38 40 45 44 62 35 36 51 48 39 58 36 51 51 51 48 58 59 36 29 35 31 49 64 60 34 38 42 56 33 42 52 31 63 34 45 51 35 45 33 53 33 62 31 38 66 29 51 54 28 61 32 45 57 41 36 34 47 36 31 28 67 48 52 46 32 40 64 58 27 53 43 57 34 66 43 39 26",
"output": "76"
},
{
"input": "94\n56 55 54 31 32 42 46 29 24 54 40 40 20 45 35 56 32 33 51 39 26 56 21 56 51 27 29 39 56 52 54 43 43 55 48 51 44 49 52 49 23 19 19 28 20 26 45 33 35 51 42 36 25 25 38 23 21 35 54 50 41 20 37 28 42 20 22 43 37 34 55 21 24 38 19 41 45 34 19 33 44 54 38 31 23 53 35 32 47 40 39 31 20 34",
"output": "15"
},
{
"input": "95\n57 71 70 77 64 64 76 81 81 58 63 75 81 77 71 71 71 60 70 70 69 67 62 64 78 64 69 62 76 76 57 70 68 77 70 68 73 77 79 73 60 57 69 60 74 65 58 75 75 74 73 73 65 75 72 57 81 62 62 70 67 58 76 57 79 81 68 64 58 77 70 59 79 64 80 58 71 59 81 71 80 64 78 80 78 65 70 68 78 80 57 63 64 76 81",
"output": "11"
},
{
"input": "96\n96 95 95 95 96 97 95 97 96 95 98 96 97 95 98 96 98 96 98 96 98 95 96 95 95 95 97 97 95 95 98 98 95 96 96 95 97 96 98 96 95 97 97 95 97 97 95 94 96 96 97 96 97 97 96 94 94 97 95 95 95 96 95 96 95 97 97 95 97 96 95 94 97 97 97 96 97 95 96 94 94 95 97 94 94 97 97 97 95 97 97 95 94 96 95 95",
"output": "13"
},
{
"input": "97\n14 15 12 12 13 15 12 15 12 12 12 12 12 14 15 15 13 12 15 15 12 12 12 13 14 15 15 13 14 15 14 14 14 14 12 13 12 13 13 12 15 12 13 13 15 12 15 13 12 13 13 13 14 13 12 15 14 13 14 15 13 14 14 13 14 12 15 12 14 12 13 14 15 14 13 15 13 12 15 15 15 13 15 15 13 14 16 16 16 13 15 13 15 14 15 15 15",
"output": "104"
},
{
"input": "98\n37 69 35 70 58 69 36 47 41 63 60 54 49 35 55 50 35 53 52 43 35 41 40 49 38 35 48 70 42 35 35 65 56 54 44 59 59 48 51 49 59 67 35 60 69 35 58 50 35 44 48 69 41 58 44 45 35 47 70 61 49 47 37 39 35 51 44 70 72 65 36 41 63 63 48 66 45 50 50 71 37 52 72 67 72 39 72 39 36 64 48 72 69 49 45 72 72 67",
"output": "100"
},
{
"input": "99\n31 31 16 15 19 31 19 22 29 27 12 22 28 30 25 33 26 25 19 22 34 21 17 33 31 22 16 26 22 30 31 17 13 33 13 17 28 25 18 33 27 22 31 22 13 27 20 22 23 15 24 32 29 13 16 20 32 33 14 33 19 27 16 28 25 17 17 28 18 26 32 33 19 23 30 13 14 23 24 28 14 28 22 20 30 14 24 23 17 29 18 28 29 21 28 18 16 24 32",
"output": "107"
},
{
"input": "100\n37 54 39 29 32 49 21 13 34 21 16 42 34 27 16 26 7 34 51 9 11 27 16 40 36 7 48 52 30 42 42 52 51 11 32 26 6 7 28 54 48 51 6 54 42 20 51 48 46 4 4 31 47 6 9 16 8 23 36 50 49 30 47 37 45 24 48 26 8 50 18 24 27 13 39 7 37 34 5 43 42 19 34 23 52 38 35 6 29 11 53 49 21 29 36 22 45 33 51 22",
"output": "50"
},
{
"input": "100\n41 5 20 23 5 47 28 28 64 5 12 14 34 56 22 48 6 52 39 55 62 40 24 54 39 28 56 27 35 51 14 24 38 10 55 20 39 62 52 2 30 55 49 48 15 23 59 44 31 28 66 29 62 59 31 13 28 12 50 45 41 47 29 27 64 66 14 39 62 22 44 63 24 5 63 17 42 7 25 41 49 33 31 51 63 3 37 66 19 9 2 40 16 45 56 21 34 29 39 61",
"output": "59"
},
{
"input": "100\n66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95",
"output": "99"
},
{
"input": "100\n81 81 81 81 81 81 81 81 81 81 81 81 81 81 81 81 81 81 81 81 81 81 81 81 81 81 81 81 81 81 81 81 81 81 81 81 81 81 81 81 81 81 81 81 81 81 81 81 81 81 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10",
"output": "0"
},
{
"input": "3\n2 1 2",
"output": "1"
},
{
"input": "2\n100 99",
"output": "0"
},
{
"input": "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 50 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": "197"
},
{
"input": "100\n87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87",
"output": "0"
},
{
"input": "100\n100 99 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",
"output": "0"
},
{
"input": "2\n1 1",
"output": "0"
},
{
"input": "3\n2 2 2",
"output": "0"
},
{
"input": "3\n1 3 2",
"output": "2"
}
] | 1,698,698,508 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 39 | 124 | 0 | n=int(input(""))
L=list(map(int,input().split()))
ma=max(L)
mi=min(L)
x=L.index(ma)
L.reverse()
y=L.index(mi)
m=n-1-y
if(x<m):
print(x+y)
else:
print(x+y-1) | Title: Arrival of the General
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A Ministry for Defense sent a general to inspect the Super Secret Military Squad under the command of the Colonel SuperDuper. Having learned the news, the colonel ordered to all *n* squad soldiers to line up on the parade ground.
By the military charter the soldiers should stand in the order of non-increasing of their height. But as there's virtually no time to do that, the soldiers lined up in the arbitrary order. However, the general is rather short-sighted and he thinks that the soldiers lined up correctly if the first soldier in the line has the maximum height and the last soldier has the minimum height. Please note that the way other solders are positioned does not matter, including the case when there are several soldiers whose height is maximum or minimum. Only the heights of the first and the last soldier are important.
For example, the general considers the sequence of heights (4, 3, 4, 2, 1, 1) correct and the sequence (4, 3, 1, 2, 2) wrong.
Within one second the colonel can swap any two neighboring soldiers. Help him count the minimum time needed to form a line-up which the general will consider correct.
Input Specification:
The first input line contains the only integer *n* (2<=≤<=*n*<=≤<=100) which represents the number of soldiers in the line. The second line contains integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=100) the values of the soldiers' heights in the order of soldiers' heights' increasing in the order from the beginning of the line to its end. The numbers are space-separated. Numbers *a*1,<=*a*2,<=...,<=*a**n* are not necessarily different.
Output Specification:
Print the only integer — the minimum number of seconds the colonel will need to form a line-up the general will like.
Demo Input:
['4\n33 44 11 22\n', '7\n10 10 58 31 63 40 76\n']
Demo Output:
['2\n', '10\n']
Note:
In the first sample the colonel will need to swap the first and second soldier and then the third and fourth soldier. That will take 2 seconds. The resulting position of the soldiers is (44, 33, 22, 11).
In the second sample the colonel may swap the soldiers in the following sequence:
1. (10, 10, 58, 31, 63, 40, 76) 1. (10, 58, 10, 31, 63, 40, 76) 1. (10, 58, 10, 31, 63, 76, 40) 1. (10, 58, 10, 31, 76, 63, 40) 1. (10, 58, 31, 10, 76, 63, 40) 1. (10, 58, 31, 76, 10, 63, 40) 1. (10, 58, 31, 76, 63, 10, 40) 1. (10, 58, 76, 31, 63, 10, 40) 1. (10, 76, 58, 31, 63, 10, 40) 1. (76, 10, 58, 31, 63, 10, 40) 1. (76, 10, 58, 31, 63, 40, 10) | ```python
n=int(input(""))
L=list(map(int,input().split()))
ma=max(L)
mi=min(L)
x=L.index(ma)
L.reverse()
y=L.index(mi)
m=n-1-y
if(x<m):
print(x+y)
else:
print(x+y-1)
``` | 3 |
|
946 | B | Weird Subtraction Process | PROGRAMMING | 1,100 | [
"math",
"number theory"
] | null | null | You have two variables *a* and *b*. Consider the following sequence of actions performed with these variables:
1. If *a*<==<=0 or *b*<==<=0, end the process. Otherwise, go to step 2;1. If *a*<=≥<=2·*b*, then set the value of *a* to *a*<=-<=2·*b*, and repeat step 1. Otherwise, go to step 3;1. If *b*<=≥<=2·*a*, then set the value of *b* to *b*<=-<=2·*a*, and repeat step 1. Otherwise, end the process.
Initially the values of *a* and *b* are positive integers, and so the process will be finite.
You have to determine the values of *a* and *b* after the process ends. | The only line of the input contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=1018). *n* is the initial value of variable *a*, and *m* is the initial value of variable *b*. | Print two integers — the values of *a* and *b* after the end of the process. | [
"12 5\n",
"31 12\n"
] | [
"0 1\n",
"7 12\n"
] | Explanations to the samples:
1. *a* = 12, *b* = 5 <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> *a* = 2, *b* = 5 <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> *a* = 2, *b* = 1 <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> *a* = 0, *b* = 1;1. *a* = 31, *b* = 12 <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> *a* = 7, *b* = 12. | 0 | [
{
"input": "12 5",
"output": "0 1"
},
{
"input": "31 12",
"output": "7 12"
},
{
"input": "1000000000000000000 7",
"output": "8 7"
},
{
"input": "31960284556200 8515664064180",
"output": "14928956427840 8515664064180"
},
{
"input": "1000000000000000000 1000000000000000000",
"output": "1000000000000000000 1000000000000000000"
},
{
"input": "1 1000",
"output": "1 0"
},
{
"input": "1 1000000",
"output": "1 0"
},
{
"input": "1 1000000000000000",
"output": "1 0"
},
{
"input": "1 99999999999999999",
"output": "1 1"
},
{
"input": "1 4",
"output": "1 0"
},
{
"input": "1000000000000001 500000000000000",
"output": "1 0"
},
{
"input": "1 1000000000000000000",
"output": "1 0"
},
{
"input": "2 4",
"output": "2 0"
},
{
"input": "2 1",
"output": "0 1"
},
{
"input": "6 19",
"output": "6 7"
},
{
"input": "22 5",
"output": "0 1"
},
{
"input": "10000000000000000 100000000000000001",
"output": "0 1"
},
{
"input": "1 1000000000000",
"output": "1 0"
},
{
"input": "2 1000000000000000",
"output": "2 0"
},
{
"input": "2 10",
"output": "2 2"
},
{
"input": "51 100",
"output": "51 100"
},
{
"input": "3 1000000000000000000",
"output": "3 4"
},
{
"input": "1000000000000000000 3",
"output": "4 3"
},
{
"input": "1 10000000000000000",
"output": "1 0"
},
{
"input": "8796203 7556",
"output": "1019 1442"
},
{
"input": "5 22",
"output": "1 0"
},
{
"input": "1000000000000000000 1",
"output": "0 1"
},
{
"input": "1 100000000000",
"output": "1 0"
},
{
"input": "2 1000000000000",
"output": "2 0"
},
{
"input": "5 4567865432345678",
"output": "5 8"
},
{
"input": "576460752303423487 288230376151711743",
"output": "1 1"
},
{
"input": "499999999999999999 1000000000000000000",
"output": "3 2"
},
{
"input": "1 9999999999999",
"output": "1 1"
},
{
"input": "103 1000000000000000000",
"output": "103 196"
},
{
"input": "7 1",
"output": "1 1"
},
{
"input": "100000000000000001 10000000000000000",
"output": "1 0"
},
{
"input": "5 10",
"output": "5 0"
},
{
"input": "7 11",
"output": "7 11"
},
{
"input": "1 123456789123456",
"output": "1 0"
},
{
"input": "5000000000000 100000000000001",
"output": "0 1"
},
{
"input": "1000000000000000 1",
"output": "0 1"
},
{
"input": "1000000000000000000 499999999999999999",
"output": "2 3"
},
{
"input": "10 5",
"output": "0 5"
},
{
"input": "9 18917827189272",
"output": "9 0"
},
{
"input": "179 100000000000497000",
"output": "179 270"
},
{
"input": "5 100000000000001",
"output": "1 1"
},
{
"input": "5 20",
"output": "5 0"
},
{
"input": "100000001 50000000",
"output": "1 0"
},
{
"input": "345869461223138161 835002744095575440",
"output": "1 0"
},
{
"input": "8589934592 4294967296",
"output": "0 4294967296"
},
{
"input": "4 8",
"output": "4 0"
},
{
"input": "1 100000000000000000",
"output": "1 0"
},
{
"input": "1000000000000000000 333333333333333",
"output": "1000 1333"
},
{
"input": "25 12",
"output": "1 0"
},
{
"input": "24 54",
"output": "0 6"
},
{
"input": "6 12",
"output": "6 0"
},
{
"input": "129200000000305 547300000001292",
"output": "1 0"
},
{
"input": "1000000000000000000 49999999999999999",
"output": "20 39"
},
{
"input": "1 2",
"output": "1 0"
},
{
"input": "1 123456789876",
"output": "1 0"
},
{
"input": "2 3",
"output": "2 3"
},
{
"input": "1 3",
"output": "1 1"
},
{
"input": "1 1",
"output": "1 1"
},
{
"input": "19 46",
"output": "3 2"
},
{
"input": "3 6",
"output": "3 0"
},
{
"input": "129 1000000000000000000",
"output": "1 0"
},
{
"input": "12 29",
"output": "0 1"
},
{
"input": "8589934592 2147483648",
"output": "0 2147483648"
},
{
"input": "2147483648 8589934592",
"output": "2147483648 0"
},
{
"input": "5 6",
"output": "5 6"
},
{
"input": "1000000000000000000 2",
"output": "0 2"
},
{
"input": "2 7",
"output": "2 3"
},
{
"input": "17174219820754872 61797504734333370",
"output": "17174219820754872 27449065092823626"
},
{
"input": "49 100",
"output": "1 0"
},
{
"input": "7 17",
"output": "1 1"
},
{
"input": "1000000000000000000 10000001",
"output": "0 1"
},
{
"input": "49999999999999999 2",
"output": "3 2"
},
{
"input": "49999999999999999 1",
"output": "1 1"
},
{
"input": "576460752303423487 2",
"output": "3 2"
},
{
"input": "19395 19395",
"output": "19395 19395"
},
{
"input": "19394 19394",
"output": "19394 19394"
}
] | 1,548,421,687 | 2,147,483,647 | PyPy 3 | OK | TESTS | 81 | 139 | 0 | a,b = map(int,input().split())
while 1==1 :
if not b<=0:
a %= 2*b
else :
print(a,b)
break
if not a<=0 :
b %= 2*a
else :
print(a,b)
break
if (a<2*b and b<2*a) :
print(a,b)
break | Title: Weird Subtraction Process
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You have two variables *a* and *b*. Consider the following sequence of actions performed with these variables:
1. If *a*<==<=0 or *b*<==<=0, end the process. Otherwise, go to step 2;1. If *a*<=≥<=2·*b*, then set the value of *a* to *a*<=-<=2·*b*, and repeat step 1. Otherwise, go to step 3;1. If *b*<=≥<=2·*a*, then set the value of *b* to *b*<=-<=2·*a*, and repeat step 1. Otherwise, end the process.
Initially the values of *a* and *b* are positive integers, and so the process will be finite.
You have to determine the values of *a* and *b* after the process ends.
Input Specification:
The only line of the input contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=1018). *n* is the initial value of variable *a*, and *m* is the initial value of variable *b*.
Output Specification:
Print two integers — the values of *a* and *b* after the end of the process.
Demo Input:
['12 5\n', '31 12\n']
Demo Output:
['0 1\n', '7 12\n']
Note:
Explanations to the samples:
1. *a* = 12, *b* = 5 <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> *a* = 2, *b* = 5 <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> *a* = 2, *b* = 1 <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> *a* = 0, *b* = 1;1. *a* = 31, *b* = 12 <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> *a* = 7, *b* = 12. | ```python
a,b = map(int,input().split())
while 1==1 :
if not b<=0:
a %= 2*b
else :
print(a,b)
break
if not a<=0 :
b %= 2*a
else :
print(a,b)
break
if (a<2*b and b<2*a) :
print(a,b)
break
``` | 3 |
|
3 | A | Shortest path of the king | PROGRAMMING | 1,000 | [
"greedy",
"shortest paths"
] | A. Shortest path of the king | 1 | 64 | The king is left alone on the chessboard. In spite of this loneliness, he doesn't lose heart, because he has business of national importance. For example, he has to pay an official visit to square *t*. As the king is not in habit of wasting his time, he wants to get from his current position *s* to square *t* in the least number of moves. Help him to do this.
In one move the king can get to the square that has a common side or a common vertex with the square the king is currently in (generally there are 8 different squares he can move to). | The first line contains the chessboard coordinates of square *s*, the second line — of square *t*.
Chessboard coordinates consist of two characters, the first one is a lowercase Latin letter (from a to h), the second one is a digit from 1 to 8. | In the first line print *n* — minimum number of the king's moves. Then in *n* lines print the moves themselves. Each move is described with one of the 8: L, R, U, D, LU, LD, RU or RD.
L, R, U, D stand respectively for moves left, right, up and down (according to the picture), and 2-letter combinations stand for diagonal moves. If the answer is not unique, print any of them. | [
"a8\nh1\n"
] | [
"7\nRD\nRD\nRD\nRD\nRD\nRD\nRD\n"
] | none | 0 | [
{
"input": "a8\nh1",
"output": "7\nRD\nRD\nRD\nRD\nRD\nRD\nRD"
},
{
"input": "b2\nb4",
"output": "2\nU\nU"
},
{
"input": "a5\na5",
"output": "0"
},
{
"input": "h1\nb2",
"output": "6\nLU\nL\nL\nL\nL\nL"
},
{
"input": "c5\nh2",
"output": "5\nRD\nRD\nRD\nR\nR"
},
{
"input": "e1\nf2",
"output": "1\nRU"
},
{
"input": "g4\nd2",
"output": "3\nLD\nLD\nL"
},
{
"input": "a8\nb2",
"output": "6\nRD\nD\nD\nD\nD\nD"
},
{
"input": "d4\nh2",
"output": "4\nRD\nRD\nR\nR"
},
{
"input": "c5\na2",
"output": "3\nLD\nLD\nD"
},
{
"input": "h5\nf8",
"output": "3\nLU\nLU\nU"
},
{
"input": "e6\nb6",
"output": "3\nL\nL\nL"
},
{
"input": "a6\ng4",
"output": "6\nRD\nRD\nR\nR\nR\nR"
},
{
"input": "f7\nc2",
"output": "5\nLD\nLD\nLD\nD\nD"
},
{
"input": "b7\nh8",
"output": "6\nRU\nR\nR\nR\nR\nR"
},
{
"input": "g7\nd6",
"output": "3\nLD\nL\nL"
},
{
"input": "c8\na3",
"output": "5\nLD\nLD\nD\nD\nD"
},
{
"input": "h8\nf1",
"output": "7\nLD\nLD\nD\nD\nD\nD\nD"
},
{
"input": "d1\nb7",
"output": "6\nLU\nLU\nU\nU\nU\nU"
},
{
"input": "a7\ne5",
"output": "4\nRD\nRD\nR\nR"
},
{
"input": "d6\nb1",
"output": "5\nLD\nLD\nD\nD\nD"
},
{
"input": "f5\ng5",
"output": "1\nR"
},
{
"input": "h4\nd1",
"output": "4\nLD\nLD\nLD\nL"
},
{
"input": "b3\na5",
"output": "2\nLU\nU"
},
{
"input": "d2\nf1",
"output": "2\nRD\nR"
},
{
"input": "f1\nc5",
"output": "4\nLU\nLU\nLU\nU"
},
{
"input": "a8\nh1",
"output": "7\nRD\nRD\nRD\nRD\nRD\nRD\nRD"
},
{
"input": "c7\ne5",
"output": "2\nRD\nRD"
},
{
"input": "e7\nb1",
"output": "6\nLD\nLD\nLD\nD\nD\nD"
},
{
"input": "g8\na8",
"output": "6\nL\nL\nL\nL\nL\nL"
},
{
"input": "g6\nf2",
"output": "4\nLD\nD\nD\nD"
},
{
"input": "g4\nc4",
"output": "4\nL\nL\nL\nL"
},
{
"input": "g2\na6",
"output": "6\nLU\nLU\nLU\nLU\nL\nL"
},
{
"input": "f8\nf8",
"output": "0"
},
{
"input": "f5\nd2",
"output": "3\nLD\nLD\nD"
}
] | 1,570,018,025 | 2,147,483,647 | PyPy 3 | OK | TESTS | 35 | 310 | 0 | import sys
def get_double_move(h,v):
if h < 0 and v < 0:
return 'LD'
elif h > 0 and v < 0:
return 'RD'
elif h < 0 and v > 0:
return 'LU'
elif h > 0 and v > 0:
return 'RU'
def get_single_move(h,v):
if abs(h)>abs(v):
if h > 0:
return 'R'
elif h < 0:
return 'L'
elif abs(h)<abs(v):
if v < 0:
return 'D'
elif v > 0:
return 'U'
line1 = sys.stdin.readline()
line2 = sys.stdin.readline()
dx = int(ord(line2[0])-ord(line1[0]))
dy = int(ord(line2[1])-ord(line1[1]))
double = get_double_move(dx,dy)
single = get_single_move(dx,dy)
print(max(abs(dx),abs(dy)))
for i in range(0,min(abs(dx),abs(dy))):
print(double)
for i in range(min(abs(dx),abs(dy)), max(abs(dx),abs(dy))):
print(single)
| Title: Shortest path of the king
Time Limit: 1 seconds
Memory Limit: 64 megabytes
Problem Description:
The king is left alone on the chessboard. In spite of this loneliness, he doesn't lose heart, because he has business of national importance. For example, he has to pay an official visit to square *t*. As the king is not in habit of wasting his time, he wants to get from his current position *s* to square *t* in the least number of moves. Help him to do this.
In one move the king can get to the square that has a common side or a common vertex with the square the king is currently in (generally there are 8 different squares he can move to).
Input Specification:
The first line contains the chessboard coordinates of square *s*, the second line — of square *t*.
Chessboard coordinates consist of two characters, the first one is a lowercase Latin letter (from a to h), the second one is a digit from 1 to 8.
Output Specification:
In the first line print *n* — minimum number of the king's moves. Then in *n* lines print the moves themselves. Each move is described with one of the 8: L, R, U, D, LU, LD, RU or RD.
L, R, U, D stand respectively for moves left, right, up and down (according to the picture), and 2-letter combinations stand for diagonal moves. If the answer is not unique, print any of them.
Demo Input:
['a8\nh1\n']
Demo Output:
['7\nRD\nRD\nRD\nRD\nRD\nRD\nRD\n']
Note:
none | ```python
import sys
def get_double_move(h,v):
if h < 0 and v < 0:
return 'LD'
elif h > 0 and v < 0:
return 'RD'
elif h < 0 and v > 0:
return 'LU'
elif h > 0 and v > 0:
return 'RU'
def get_single_move(h,v):
if abs(h)>abs(v):
if h > 0:
return 'R'
elif h < 0:
return 'L'
elif abs(h)<abs(v):
if v < 0:
return 'D'
elif v > 0:
return 'U'
line1 = sys.stdin.readline()
line2 = sys.stdin.readline()
dx = int(ord(line2[0])-ord(line1[0]))
dy = int(ord(line2[1])-ord(line1[1]))
double = get_double_move(dx,dy)
single = get_single_move(dx,dy)
print(max(abs(dx),abs(dy)))
for i in range(0,min(abs(dx),abs(dy))):
print(double)
for i in range(min(abs(dx),abs(dy)), max(abs(dx),abs(dy))):
print(single)
``` | 3.845 |
0 | none | none | none | 0 | [
"none"
] | null | null | From beginning till end, this message has been waiting to be conveyed.
For a given unordered multiset of *n* lowercase English letters ("multi" means that a letter may appear more than once), we treat all letters as strings of length 1, and repeat the following operation *n*<=-<=1 times:
- Remove any two elements *s* and *t* from the set, and add their concatenation *s*<=+<=*t* to the set.
The cost of such operation is defined to be , where *f*(*s*,<=*c*) denotes the number of times character *c* appears in string *s*.
Given a non-negative integer *k*, construct any valid non-empty set of no more than 100<=000 letters, such that the minimum accumulative cost of the whole process is exactly *k*. It can be shown that a solution always exists. | The first and only line of input contains a non-negative integer *k* (0<=≤<=*k*<=≤<=100<=000) — the required minimum cost. | Output a non-empty string of no more than 100<=000 lowercase English letters — any multiset satisfying the requirements, concatenated to be a string.
Note that the printed string doesn't need to be the final concatenated string. It only needs to represent an unordered multiset of letters. | [
"12\n",
"3\n"
] | [
"abababab\n",
"codeforces\n"
] | For the multiset {'a', 'b', 'a', 'b', 'a', 'b', 'a', 'b'}, one of the ways to complete the process is as follows:
- {"ab", "a", "b", "a", "b", "a", "b"}, with a cost of 0; - {"aba", "b", "a", "b", "a", "b"}, with a cost of 1; - {"abab", "a", "b", "a", "b"}, with a cost of 1; - {"abab", "ab", "a", "b"}, with a cost of 0; - {"abab", "aba", "b"}, with a cost of 1; - {"abab", "abab"}, with a cost of 1; - {"abababab"}, with a cost of 8.
The total cost is 12, and it can be proved to be the minimum cost of the process. | 0 | [
{
"input": "12",
"output": "abababab"
},
{
"input": "3",
"output": "codeforces"
},
{
"input": "0",
"output": "o"
},
{
"input": "2",
"output": "aabb"
},
{
"input": "5",
"output": "aaabbcc"
},
{
"input": "10",
"output": "aaaaa"
},
{
"input": "233",
"output": "ooououououououououooohhhhhhaaiiiiiibbjjjjjjcckkkkkkddlllllleemmmmmmffnnnnnnggzzzzzz"
},
{
"input": "418",
"output": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaabbbbcccc"
},
{
"input": "100000",
"output": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaabbbbbbbbbbbbbbbbbbbbbbbcccccccccccc"
},
{
"input": "1",
"output": "aa"
},
{
"input": "4",
"output": "aaabb"
},
{
"input": "6",
"output": "aaaa"
},
{
"input": "7",
"output": "aaaabb"
},
{
"input": "8",
"output": "aaaabbcc"
},
{
"input": "9",
"output": "aaaabbb"
},
{
"input": "11",
"output": "aaaaabb"
},
{
"input": "1317",
"output": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaabbbbbbbbbcccc"
},
{
"input": "1926",
"output": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaabbbbbbbbbbbbbbbbbbccc"
},
{
"input": "14514",
"output": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaabbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb"
},
{
"input": "25252",
"output": "niconiconiconiconiconiconiconiconiconiconiconiconiconiconiconiconiconiconiconiconiconiconiconiconiconiconiconiconiconiconiconiconiconiconiconiconiconiconiconiconiconiconiconiconiconiconiconiconiconiconiconiconiconiconiconiconiconiconiconiconiconiconiconiconiconiconiconiconiconiconiconiconiconiconiconiconiconiconiconiconiconiconiconiconiconiconiconiconiconiconiconiconiconiconiconiconiconiconiconiconiconiconiconiconiconiconiconiconiconiconiconicooooquququququququq"
},
{
"input": "99681",
"output": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
},
{
"input": "99998",
"output": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaabbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbccc..."
},
{
"input": "82944",
"output": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaabbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb..."
},
{
"input": "831",
"output": "happybirthdayhappybirthdayhappybirthdayhappybirthdayhappybirthdayhappybirthdayhappybirthdayhappybirthdayhappybirthdayqqquqqquqqqu"
},
{
"input": "39393",
"output": "mikumikumikumikumikumikumikumikumikumikumikumikumikumikumikumikumikumikumikumikumikumikumikumikumikumikumikumikumikumikumikumikumikumikumikumikumikumikumikumikumikumikumikumikumikumikumikumikumikumikumikumikumikumikumikumikumikumikumikumikumikumikumikumikumikumikumikumikumikumikumikumikumikumikumikumikumikumikumikumikumikumikumikumikumikumikumikumikumikumikumikumikumikumikumikumikumikumikumikumikumikumikumikumikumikumikumikumikumikumikumikumikumikumikumikumikumikumikumikumikumikumikumikumikumikumikumikumik..."
}
] | 1,600,006,017 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 0 | 124 | 0 | k = int(input())
if k == 1:
print('fall')
exit(0)
if k == 3:
print('september')
exit(0)
# от порядка объединения строк ничего не зависит
# для каждой буквы, итоговая стоимость будет n * (n - 1) / 2
# жадно наберём ответ
op_count = [0, 0]
for i in range(500):
op_count.append(op_count[-1] + i)
if op_count[-1] > k:
break
ans = []
letter = 'a'
for i in range(len(op_count) - 1, 1, -1):
if op_count[i] <= k:
k -= op_count[i]
ans.append(letter * i)
letter = chr(ord(letter) + 1)
print(''.join(ans))
| Title: none
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
From beginning till end, this message has been waiting to be conveyed.
For a given unordered multiset of *n* lowercase English letters ("multi" means that a letter may appear more than once), we treat all letters as strings of length 1, and repeat the following operation *n*<=-<=1 times:
- Remove any two elements *s* and *t* from the set, and add their concatenation *s*<=+<=*t* to the set.
The cost of such operation is defined to be , where *f*(*s*,<=*c*) denotes the number of times character *c* appears in string *s*.
Given a non-negative integer *k*, construct any valid non-empty set of no more than 100<=000 letters, such that the minimum accumulative cost of the whole process is exactly *k*. It can be shown that a solution always exists.
Input Specification:
The first and only line of input contains a non-negative integer *k* (0<=≤<=*k*<=≤<=100<=000) — the required minimum cost.
Output Specification:
Output a non-empty string of no more than 100<=000 lowercase English letters — any multiset satisfying the requirements, concatenated to be a string.
Note that the printed string doesn't need to be the final concatenated string. It only needs to represent an unordered multiset of letters.
Demo Input:
['12\n', '3\n']
Demo Output:
['abababab\n', 'codeforces\n']
Note:
For the multiset {'a', 'b', 'a', 'b', 'a', 'b', 'a', 'b'}, one of the ways to complete the process is as follows:
- {"ab", "a", "b", "a", "b", "a", "b"}, with a cost of 0; - {"aba", "b", "a", "b", "a", "b"}, with a cost of 1; - {"abab", "a", "b", "a", "b"}, with a cost of 1; - {"abab", "ab", "a", "b"}, with a cost of 0; - {"abab", "aba", "b"}, with a cost of 1; - {"abab", "abab"}, with a cost of 1; - {"abababab"}, with a cost of 8.
The total cost is 12, and it can be proved to be the minimum cost of the process. | ```python
k = int(input())
if k == 1:
print('fall')
exit(0)
if k == 3:
print('september')
exit(0)
# от порядка объединения строк ничего не зависит
# для каждой буквы, итоговая стоимость будет n * (n - 1) / 2
# жадно наберём ответ
op_count = [0, 0]
for i in range(500):
op_count.append(op_count[-1] + i)
if op_count[-1] > k:
break
ans = []
letter = 'a'
for i in range(len(op_count) - 1, 1, -1):
if op_count[i] <= k:
k -= op_count[i]
ans.append(letter * i)
letter = chr(ord(letter) + 1)
print(''.join(ans))
``` | 0 |
|
413 | E | Maze 2D | PROGRAMMING | 2,200 | [
"data structures",
"divide and conquer"
] | null | null | The last product of the R2 company in the 2D games' field is a new revolutionary algorithm of searching for the shortest path in a 2<=×<=*n* maze.
Imagine a maze that looks like a 2<=×<=*n* rectangle, divided into unit squares. Each unit square is either an empty cell or an obstacle. In one unit of time, a person can move from an empty cell of the maze to any side-adjacent empty cell. The shortest path problem is formulated as follows. Given two free maze cells, you need to determine the minimum time required to go from one cell to the other.
Unfortunately, the developed algorithm works well for only one request for finding the shortest path, in practice such requests occur quite often. You, as the chief R2 programmer, are commissioned to optimize the algorithm to find the shortest path. Write a program that will effectively respond to multiple requests to find the shortest path in a 2<=×<=*n* maze. | The first line contains two integers, *n* and *m* (1<=≤<=*n*<=≤<=2·105; 1<=≤<=*m*<=≤<=2·105) — the width of the maze and the number of queries, correspondingly. Next two lines contain the maze. Each line contains *n* characters, each character equals either '.' (empty cell), or 'X' (obstacle).
Each of the next *m* lines contains two integers *v**i* and *u**i* (1<=≤<=*v**i*,<=*u**i*<=≤<=2*n*) — the description of the *i*-th request. Numbers *v**i*, *u**i* mean that you need to print the value of the shortest path from the cell of the maze number *v**i* to the cell number *u**i*. We assume that the cells of the first line of the maze are numbered from 1 to *n*, from left to right, and the cells of the second line are numbered from *n*<=+<=1 to 2*n* from left to right. It is guaranteed that both given cells are empty. | Print *m* lines. In the *i*-th line print the answer to the *i*-th request — either the size of the shortest path or -1, if we can't reach the second cell from the first one. | [
"4 7\n.X..\n...X\n5 1\n1 3\n7 7\n1 4\n6 1\n4 7\n5 7\n",
"10 3\nX...X..X..\n..X...X..X\n11 7\n7 18\n18 10\n"
] | [
"1\n4\n0\n5\n2\n2\n2\n",
"9\n-1\n3\n"
] | none | 2,500 | [
{
"input": "4 7\n.X..\n...X\n5 1\n1 3\n7 7\n1 4\n6 1\n4 7\n5 7",
"output": "1\n4\n0\n5\n2\n2\n2"
},
{
"input": "10 3\nX...X..X..\n..X...X..X\n11 7\n7 18\n18 10",
"output": "9\n-1\n3"
},
{
"input": "1 1\n.\n.\n1 2",
"output": "1"
},
{
"input": "2 1\n..\n.X\n1 2",
"output": "1"
},
{
"input": "2 1\n..\nX.\n1 2",
"output": "1"
},
{
"input": "2 1\n..\nX.\n1 4",
"output": "2"
},
{
"input": "2 1\n.X\n..\n1 4",
"output": "2"
},
{
"input": "2 1\nX.\n..\n2 3",
"output": "2"
},
{
"input": "2 1\n..\n.X\n3 2",
"output": "2"
}
] | 1,397,979,760 | 2,560 | Python 3 | RUNTIME_ERROR | PRETESTS | 2 | 61 | 0 | n, m = list(map(int, input().split()))
lab = []
lab.append(input())
lab.append(input())
def findPath(a, y1, x1, y2, x2):
way = 0
if x2 > x1:
d = 1
elif x2 < x1:
d = -1
else:
return 1
cy = y1
cx = x1
while not (cx == x2 and cy == y2):
if lab[cy][cx+d] == '.':
way += 1
cx += d
else:
if cy == 1 and lab[0][cx] == '.':
cy = 0
way += 1
elif cy == 0 and lab[1][cx] == '.':
cy = 1
way += 1
else:
return -1
return way
def calc(lab, n):
a, b = list(map(int, input().split()))
if a==b:
return 0
if a > n:
v = [1, a%n-1]
else:
v = [0, a-1]
if b > n:
u = [1, b%n-1]
else:
u = [0, b-1]
return findPath(lab, v[0], v[1], u[0], u[1])
#print('\n', '---', v, u)
for i in range(m):
print(calc(lab, n))
| Title: Maze 2D
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The last product of the R2 company in the 2D games' field is a new revolutionary algorithm of searching for the shortest path in a 2<=×<=*n* maze.
Imagine a maze that looks like a 2<=×<=*n* rectangle, divided into unit squares. Each unit square is either an empty cell or an obstacle. In one unit of time, a person can move from an empty cell of the maze to any side-adjacent empty cell. The shortest path problem is formulated as follows. Given two free maze cells, you need to determine the minimum time required to go from one cell to the other.
Unfortunately, the developed algorithm works well for only one request for finding the shortest path, in practice such requests occur quite often. You, as the chief R2 programmer, are commissioned to optimize the algorithm to find the shortest path. Write a program that will effectively respond to multiple requests to find the shortest path in a 2<=×<=*n* maze.
Input Specification:
The first line contains two integers, *n* and *m* (1<=≤<=*n*<=≤<=2·105; 1<=≤<=*m*<=≤<=2·105) — the width of the maze and the number of queries, correspondingly. Next two lines contain the maze. Each line contains *n* characters, each character equals either '.' (empty cell), or 'X' (obstacle).
Each of the next *m* lines contains two integers *v**i* and *u**i* (1<=≤<=*v**i*,<=*u**i*<=≤<=2*n*) — the description of the *i*-th request. Numbers *v**i*, *u**i* mean that you need to print the value of the shortest path from the cell of the maze number *v**i* to the cell number *u**i*. We assume that the cells of the first line of the maze are numbered from 1 to *n*, from left to right, and the cells of the second line are numbered from *n*<=+<=1 to 2*n* from left to right. It is guaranteed that both given cells are empty.
Output Specification:
Print *m* lines. In the *i*-th line print the answer to the *i*-th request — either the size of the shortest path or -1, if we can't reach the second cell from the first one.
Demo Input:
['4 7\n.X..\n...X\n5 1\n1 3\n7 7\n1 4\n6 1\n4 7\n5 7\n', '10 3\nX...X..X..\n..X...X..X\n11 7\n7 18\n18 10\n']
Demo Output:
['1\n4\n0\n5\n2\n2\n2\n', '9\n-1\n3\n']
Note:
none | ```python
n, m = list(map(int, input().split()))
lab = []
lab.append(input())
lab.append(input())
def findPath(a, y1, x1, y2, x2):
way = 0
if x2 > x1:
d = 1
elif x2 < x1:
d = -1
else:
return 1
cy = y1
cx = x1
while not (cx == x2 and cy == y2):
if lab[cy][cx+d] == '.':
way += 1
cx += d
else:
if cy == 1 and lab[0][cx] == '.':
cy = 0
way += 1
elif cy == 0 and lab[1][cx] == '.':
cy = 1
way += 1
else:
return -1
return way
def calc(lab, n):
a, b = list(map(int, input().split()))
if a==b:
return 0
if a > n:
v = [1, a%n-1]
else:
v = [0, a-1]
if b > n:
u = [1, b%n-1]
else:
u = [0, b-1]
return findPath(lab, v[0], v[1], u[0], u[1])
#print('\n', '---', v, u)
for i in range(m):
print(calc(lab, n))
``` | -1 |
|
253 | A | Boys and Girls | PROGRAMMING | 1,100 | [
"greedy"
] | null | null | There are *n* boys and *m* girls studying in the class. They should stand in a line so that boys and girls alternated there as much as possible. Let's assume that positions in the line are indexed from left to right by numbers from 1 to *n*<=+<=*m*. Then the number of integers *i* (1<=≤<=*i*<=<<=*n*<=+<=*m*) such that positions with indexes *i* and *i*<=+<=1 contain children of different genders (position *i* has a girl and position *i*<=+<=1 has a boy or vice versa) must be as large as possible.
Help the children and tell them how to form the line. | The single line of the input contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=100), separated by a space. | Print a line of *n*<=+<=*m* characters. Print on the *i*-th position of the line character "B", if the *i*-th position of your arrangement should have a boy and "G", if it should have a girl.
Of course, the number of characters "B" should equal *n* and the number of characters "G" should equal *m*. If there are multiple optimal solutions, print any of them. | [
"3 3\n",
"4 2\n"
] | [
"GBGBGB\n",
"BGBGBB\n"
] | In the first sample another possible answer is BGBGBG.
In the second sample answer BBGBGB is also optimal. | 500 | [
{
"input": "3 3",
"output": "GBGBGB"
},
{
"input": "4 2",
"output": "BGBGBB"
},
{
"input": "5 5",
"output": "GBGBGBGBGB"
},
{
"input": "6 4",
"output": "BGBGBGBGBB"
},
{
"input": "100 1",
"output": "BGBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB"
},
{
"input": "76 48",
"output": "BGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBBBBBBBBBBBBBBBBBBBBBBBBBBBB"
},
{
"input": "100 90",
"output": "BGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBBBBBBBBBB"
},
{
"input": "90 100",
"output": "GBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGGGGGGGGGG"
},
{
"input": "1 98",
"output": "GBGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGG"
},
{
"input": "1 100",
"output": "GBGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGG"
},
{
"input": "56 98",
"output": "GBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGG"
},
{
"input": "89 89",
"output": "GBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGB"
},
{
"input": "18 94",
"output": "GBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGG"
},
{
"input": "84 27",
"output": "BGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB"
},
{
"input": "1 1",
"output": "GB"
},
{
"input": "1 2",
"output": "GBG"
},
{
"input": "2 1",
"output": "BGB"
},
{
"input": "1 34",
"output": "GBGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGG"
},
{
"input": "46 2",
"output": "BGBGBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB"
},
{
"input": "99 3",
"output": "BGBGBGBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB"
},
{
"input": "10 100",
"output": "GBGBGBGBGBGBGBGBGBGBGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGG"
},
{
"input": "100 100",
"output": "GBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGB"
},
{
"input": "1 4",
"output": "GBGGG"
}
] | 1,620,378,873 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 7 | 216 | 20,172,800 |
input_file = open('input.txt', 'r')
output_file = open('output.txt', 'w')
B,G = map(int,input_file.readline().split())
output = ''
sum_of = (B + G)
for i in range(sum_of):
if B != 0:
output += 'B'
B -= 1
if G != 0:
output += 'G'
G -= 1
output_file.write(output)
| Title: Boys and Girls
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
There are *n* boys and *m* girls studying in the class. They should stand in a line so that boys and girls alternated there as much as possible. Let's assume that positions in the line are indexed from left to right by numbers from 1 to *n*<=+<=*m*. Then the number of integers *i* (1<=≤<=*i*<=<<=*n*<=+<=*m*) such that positions with indexes *i* and *i*<=+<=1 contain children of different genders (position *i* has a girl and position *i*<=+<=1 has a boy or vice versa) must be as large as possible.
Help the children and tell them how to form the line.
Input Specification:
The single line of the input contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=100), separated by a space.
Output Specification:
Print a line of *n*<=+<=*m* characters. Print on the *i*-th position of the line character "B", if the *i*-th position of your arrangement should have a boy and "G", if it should have a girl.
Of course, the number of characters "B" should equal *n* and the number of characters "G" should equal *m*. If there are multiple optimal solutions, print any of them.
Demo Input:
['3 3\n', '4 2\n']
Demo Output:
['GBGBGB\n', 'BGBGBB\n']
Note:
In the first sample another possible answer is BGBGBG.
In the second sample answer BBGBGB is also optimal. | ```python
input_file = open('input.txt', 'r')
output_file = open('output.txt', 'w')
B,G = map(int,input_file.readline().split())
output = ''
sum_of = (B + G)
for i in range(sum_of):
if B != 0:
output += 'B'
B -= 1
if G != 0:
output += 'G'
G -= 1
output_file.write(output)
``` | 0 |
|
581 | A | Vasya the Hipster | PROGRAMMING | 800 | [
"implementation",
"math"
] | null | null | One day Vasya the Hipster decided to count how many socks he had. It turned out that he had *a* red socks and *b* blue socks.
According to the latest fashion, hipsters should wear the socks of different colors: a red one on the left foot, a blue one on the right foot.
Every day Vasya puts on new socks in the morning and throws them away before going to bed as he doesn't want to wash them.
Vasya wonders, what is the maximum number of days when he can dress fashionable and wear different socks, and after that, for how many days he can then wear the same socks until he either runs out of socks or cannot make a single pair from the socks he's got.
Can you help him? | The single line of the input contains two positive integers *a* and *b* (1<=≤<=*a*,<=*b*<=≤<=100) — the number of red and blue socks that Vasya's got. | Print two space-separated integers — the maximum number of days when Vasya can wear different socks and the number of days when he can wear the same socks until he either runs out of socks or cannot make a single pair from the socks he's got.
Keep in mind that at the end of the day Vasya throws away the socks that he's been wearing on that day. | [
"3 1\n",
"2 3\n",
"7 3\n"
] | [
"1 1\n",
"2 0\n",
"3 2\n"
] | In the first sample Vasya can first put on one pair of different socks, after that he has two red socks left to wear on the second day. | 500 | [
{
"input": "3 1",
"output": "1 1"
},
{
"input": "2 3",
"output": "2 0"
},
{
"input": "7 3",
"output": "3 2"
},
{
"input": "100 100",
"output": "100 0"
},
{
"input": "4 10",
"output": "4 3"
},
{
"input": "6 10",
"output": "6 2"
},
{
"input": "6 11",
"output": "6 2"
},
{
"input": "10 40",
"output": "10 15"
},
{
"input": "11 56",
"output": "11 22"
},
{
"input": "34 30",
"output": "30 2"
},
{
"input": "33 33",
"output": "33 0"
},
{
"input": "100 45",
"output": "45 27"
},
{
"input": "100 23",
"output": "23 38"
},
{
"input": "45 12",
"output": "12 16"
},
{
"input": "1 1",
"output": "1 0"
},
{
"input": "1 100",
"output": "1 49"
},
{
"input": "100 1",
"output": "1 49"
},
{
"input": "68 59",
"output": "59 4"
},
{
"input": "45 99",
"output": "45 27"
},
{
"input": "99 100",
"output": "99 0"
},
{
"input": "100 98",
"output": "98 1"
},
{
"input": "59 12",
"output": "12 23"
},
{
"input": "86 4",
"output": "4 41"
},
{
"input": "68 21",
"output": "21 23"
},
{
"input": "100 11",
"output": "11 44"
},
{
"input": "100 10",
"output": "10 45"
},
{
"input": "15 45",
"output": "15 15"
},
{
"input": "11 32",
"output": "11 10"
},
{
"input": "34 96",
"output": "34 31"
},
{
"input": "89 89",
"output": "89 0"
}
] | 1,684,580,935 | 2,147,483,647 | Python 3 | OK | TESTS | 30 | 46 | 0 | n, k = map(int, input().split())
print(min(n, k), (abs(n - k)) // 2)
| Title: Vasya the Hipster
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
One day Vasya the Hipster decided to count how many socks he had. It turned out that he had *a* red socks and *b* blue socks.
According to the latest fashion, hipsters should wear the socks of different colors: a red one on the left foot, a blue one on the right foot.
Every day Vasya puts on new socks in the morning and throws them away before going to bed as he doesn't want to wash them.
Vasya wonders, what is the maximum number of days when he can dress fashionable and wear different socks, and after that, for how many days he can then wear the same socks until he either runs out of socks or cannot make a single pair from the socks he's got.
Can you help him?
Input Specification:
The single line of the input contains two positive integers *a* and *b* (1<=≤<=*a*,<=*b*<=≤<=100) — the number of red and blue socks that Vasya's got.
Output Specification:
Print two space-separated integers — the maximum number of days when Vasya can wear different socks and the number of days when he can wear the same socks until he either runs out of socks or cannot make a single pair from the socks he's got.
Keep in mind that at the end of the day Vasya throws away the socks that he's been wearing on that day.
Demo Input:
['3 1\n', '2 3\n', '7 3\n']
Demo Output:
['1 1\n', '2 0\n', '3 2\n']
Note:
In the first sample Vasya can first put on one pair of different socks, after that he has two red socks left to wear on the second day. | ```python
n, k = map(int, input().split())
print(min(n, k), (abs(n - k)) // 2)
``` | 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,621,677,515 | 2,147,483,647 | Python 3 | OK | TESTS | 102 | 77 | 0 | m=input()
n=input()
x=""
for i in range(len(m)):
if(m[i]==n[i]):
x+='0'
else:
x+='1'
print(x)
| 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
m=input()
n=input()
x=""
for i in range(len(m)):
if(m[i]==n[i]):
x+='0'
else:
x+='1'
print(x)
``` | 3.98075 |
552 | B | Vanya and Books | PROGRAMMING | 1,200 | [
"implementation",
"math"
] | null | null | Vanya got an important task — he should enumerate books in the library and label each book with its number. Each of the *n* books should be assigned with a number from 1 to *n*. Naturally, distinct books should be assigned distinct numbers.
Vanya wants to know how many digits he will have to write down as he labels the books. | The first line contains integer *n* (1<=≤<=*n*<=≤<=109) — the number of books in the library. | Print the number of digits needed to number all the books. | [
"13\n",
"4\n"
] | [
"17\n",
"4\n"
] | Note to the first test. The books get numbers 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, which totals to 17 digits.
Note to the second sample. The books get numbers 1, 2, 3, 4, which totals to 4 digits. | 1,000 | [
{
"input": "13",
"output": "17"
},
{
"input": "4",
"output": "4"
},
{
"input": "100",
"output": "192"
},
{
"input": "99",
"output": "189"
},
{
"input": "1000000000",
"output": "8888888899"
},
{
"input": "1000000",
"output": "5888896"
},
{
"input": "999",
"output": "2889"
},
{
"input": "55",
"output": "101"
},
{
"input": "222222222",
"output": "1888888896"
},
{
"input": "8",
"output": "8"
},
{
"input": "13",
"output": "17"
},
{
"input": "313",
"output": "831"
},
{
"input": "1342",
"output": "4261"
},
{
"input": "30140",
"output": "139594"
},
{
"input": "290092",
"output": "1629447"
},
{
"input": "2156660",
"output": "13985516"
},
{
"input": "96482216",
"output": "760746625"
},
{
"input": "943006819",
"output": "8375950269"
},
{
"input": "1",
"output": "1"
},
{
"input": "7",
"output": "7"
},
{
"input": "35",
"output": "61"
},
{
"input": "996",
"output": "2880"
},
{
"input": "6120",
"output": "23373"
},
{
"input": "30660",
"output": "142194"
},
{
"input": "349463",
"output": "1985673"
},
{
"input": "8171970",
"output": "56092686"
},
{
"input": "36123011",
"output": "277872985"
},
{
"input": "986747865",
"output": "8769619683"
},
{
"input": "9",
"output": "9"
},
{
"input": "10",
"output": "11"
},
{
"input": "11",
"output": "13"
},
{
"input": "101",
"output": "195"
},
{
"input": "1000",
"output": "2893"
},
{
"input": "1001",
"output": "2897"
},
{
"input": "9999",
"output": "38889"
},
{
"input": "10000",
"output": "38894"
},
{
"input": "10001",
"output": "38899"
},
{
"input": "99999",
"output": "488889"
},
{
"input": "100000",
"output": "488895"
},
{
"input": "100001",
"output": "488901"
},
{
"input": "999999",
"output": "5888889"
},
{
"input": "1000001",
"output": "5888903"
},
{
"input": "9999999",
"output": "68888889"
},
{
"input": "10000000",
"output": "68888897"
},
{
"input": "10000001",
"output": "68888905"
},
{
"input": "99999999",
"output": "788888889"
},
{
"input": "100000000",
"output": "788888898"
},
{
"input": "100000001",
"output": "788888907"
},
{
"input": "999999999",
"output": "8888888889"
},
{
"input": "95",
"output": "181"
},
{
"input": "995",
"output": "2877"
},
{
"input": "9995",
"output": "38873"
},
{
"input": "99995",
"output": "488869"
},
{
"input": "999999995",
"output": "8888888853"
},
{
"input": "999999998",
"output": "8888888880"
}
] | 1,568,905,325 | 2,147,483,647 | Python 3 | OK | TESTS | 55 | 124 | 0 | a=input();print(int(a)*len(a)+len(a)-int('1'*len(a))) | Title: Vanya and Books
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vanya got an important task — he should enumerate books in the library and label each book with its number. Each of the *n* books should be assigned with a number from 1 to *n*. Naturally, distinct books should be assigned distinct numbers.
Vanya wants to know how many digits he will have to write down as he labels the books.
Input Specification:
The first line contains integer *n* (1<=≤<=*n*<=≤<=109) — the number of books in the library.
Output Specification:
Print the number of digits needed to number all the books.
Demo Input:
['13\n', '4\n']
Demo Output:
['17\n', '4\n']
Note:
Note to the first test. The books get numbers 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, which totals to 17 digits.
Note to the second sample. The books get numbers 1, 2, 3, 4, which totals to 4 digits. | ```python
a=input();print(int(a)*len(a)+len(a)-int('1'*len(a)))
``` | 3 |
|
939 | A | Love Triangle | PROGRAMMING | 800 | [
"graphs"
] | null | null | As you could know there are no male planes nor female planes. However, each plane on Earth likes some other plane. There are *n* planes on Earth, numbered from 1 to *n*, and the plane with number *i* likes the plane with number *f**i*, where 1<=≤<=*f**i*<=≤<=*n* and *f**i*<=≠<=*i*.
We call a love triangle a situation in which plane *A* likes plane *B*, plane *B* likes plane *C* and plane *C* likes plane *A*. Find out if there is any love triangle on Earth. | The first line contains a single integer *n* (2<=≤<=*n*<=≤<=5000) — the number of planes.
The second line contains *n* integers *f*1,<=*f*2,<=...,<=*f**n* (1<=≤<=*f**i*<=≤<=*n*, *f**i*<=≠<=*i*), meaning that the *i*-th plane likes the *f**i*-th. | Output «YES» if there is a love triangle consisting of planes on Earth. Otherwise, output «NO».
You can output any letter in lower case or in upper case. | [
"5\n2 4 5 1 3\n",
"5\n5 5 5 5 1\n"
] | [
"YES\n",
"NO\n"
] | In first example plane 2 likes plane 4, plane 4 likes plane 1, plane 1 likes plane 2 and that is a love triangle.
In second example there are no love triangles. | 500 | [
{
"input": "5\n2 4 5 1 3",
"output": "YES"
},
{
"input": "5\n5 5 5 5 1",
"output": "NO"
},
{
"input": "3\n3 1 2",
"output": "YES"
},
{
"input": "10\n4 10 9 5 3 1 5 10 6 4",
"output": "NO"
},
{
"input": "10\n5 5 4 9 10 9 9 5 3 1",
"output": "YES"
},
{
"input": "100\n50 40 60 87 39 58 44 84 46 68 16 57 77 87 92 95 42 31 74 15 36 84 30 3 47 15 87 90 76 66 6 63 74 19 40 49 6 84 41 9 77 34 7 12 11 73 58 24 81 14 81 29 65 100 1 85 64 32 38 4 54 67 32 81 80 7 100 71 29 80 4 52 47 7 78 56 52 75 81 37 16 41 27 28 58 60 62 47 29 40 37 14 59 91 12 54 25 58 12 43",
"output": "NO"
},
{
"input": "100\n25 6 46 37 87 99 70 31 46 12 94 40 87 56 28 8 94 39 13 12 67 13 71 39 83 48 40 14 62 41 16 71 20 41 83 41 68 98 23 82 62 83 62 35 49 22 31 21 66 98 54 39 34 52 11 28 47 89 25 44 68 36 91 46 82 86 88 48 27 93 7 9 53 36 16 100 84 84 44 25 58 66 16 46 72 21 91 78 4 17 44 17 47 67 93 89 75 44 56 50",
"output": "YES"
},
{
"input": "2\n2 1",
"output": "NO"
},
{
"input": "3\n2 3 1",
"output": "YES"
},
{
"input": "5\n2 1 4 5 3",
"output": "YES"
},
{
"input": "5\n5 4 5 5 2",
"output": "YES"
}
] | 1,626,256,537 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 46 | 6,963,200 | def loveTriangle():
n = int(input("enter # of elements: "))
lovePairs = {}
for i in range(n):
val = int(input("enter val: "))
lovePairs[i+1] = val
isTriangle = False
for key in lovePairs.keys():
a = key
b = lovePairs[key]
c = lovePairs[b]
if lovePairs[c] == a:
isTriangle = True
if isTriangle:
print("YES")
else:
print("NO")
loveTriangle() | Title: Love Triangle
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
As you could know there are no male planes nor female planes. However, each plane on Earth likes some other plane. There are *n* planes on Earth, numbered from 1 to *n*, and the plane with number *i* likes the plane with number *f**i*, where 1<=≤<=*f**i*<=≤<=*n* and *f**i*<=≠<=*i*.
We call a love triangle a situation in which plane *A* likes plane *B*, plane *B* likes plane *C* and plane *C* likes plane *A*. Find out if there is any love triangle on Earth.
Input Specification:
The first line contains a single integer *n* (2<=≤<=*n*<=≤<=5000) — the number of planes.
The second line contains *n* integers *f*1,<=*f*2,<=...,<=*f**n* (1<=≤<=*f**i*<=≤<=*n*, *f**i*<=≠<=*i*), meaning that the *i*-th plane likes the *f**i*-th.
Output Specification:
Output «YES» if there is a love triangle consisting of planes on Earth. Otherwise, output «NO».
You can output any letter in lower case or in upper case.
Demo Input:
['5\n2 4 5 1 3\n', '5\n5 5 5 5 1\n']
Demo Output:
['YES\n', 'NO\n']
Note:
In first example plane 2 likes plane 4, plane 4 likes plane 1, plane 1 likes plane 2 and that is a love triangle.
In second example there are no love triangles. | ```python
def loveTriangle():
n = int(input("enter # of elements: "))
lovePairs = {}
for i in range(n):
val = int(input("enter val: "))
lovePairs[i+1] = val
isTriangle = False
for key in lovePairs.keys():
a = key
b = lovePairs[key]
c = lovePairs[b]
if lovePairs[c] == a:
isTriangle = True
if isTriangle:
print("YES")
else:
print("NO")
loveTriangle()
``` | -1 |
|
629 | A | Far Relative’s Birthday Cake | PROGRAMMING | 800 | [
"brute force",
"combinatorics",
"constructive algorithms",
"implementation"
] | null | null | Door's family is going celebrate Famil Doors's birthday party. They love Famil Door so they are planning to make his birthday cake weird!
The cake is a *n*<=×<=*n* square consisting of equal squares with side length 1. Each square is either empty or consists of a single chocolate. They bought the cake and randomly started to put the chocolates on the cake. The value of Famil Door's happiness will be equal to the number of pairs of cells with chocolates that are in the same row or in the same column of the cake. Famil Doors's family is wondering what is the amount of happiness of Famil going to be?
Please, note that any pair can be counted no more than once, as two different cells can't share both the same row and the same column. | In the first line of the input, you are given a single integer *n* (1<=≤<=*n*<=≤<=100) — the length of the side of the cake.
Then follow *n* lines, each containing *n* characters. Empty cells are denoted with '.', while cells that contain chocolates are denoted by 'C'. | Print the value of Famil Door's happiness, i.e. the number of pairs of chocolate pieces that share the same row or the same column. | [
"3\n.CC\nC..\nC.C\n",
"4\nCC..\nC..C\n.CC.\n.CC.\n"
] | [
"4\n",
"9\n"
] | If we number rows from top to bottom and columns from left to right, then, pieces that share the same row in the first sample are:
1. (1, 2) and (1, 3) 1. (3, 1) and (3, 3) 1. (2, 1) and (3, 1) 1. (1, 3) and (3, 3) | 500 | [
{
"input": "3\n.CC\nC..\nC.C",
"output": "4"
},
{
"input": "4\nCC..\nC..C\n.CC.\n.CC.",
"output": "9"
},
{
"input": "5\n.CCCC\nCCCCC\n.CCC.\nCC...\n.CC.C",
"output": "46"
},
{
"input": "7\n.CC..CC\nCC.C..C\nC.C..C.\nC...C.C\nCCC.CCC\n.CC...C\n.C.CCC.",
"output": "84"
},
{
"input": "8\n..C....C\nC.CCC.CC\n.C..C.CC\nCC......\nC..C..CC\nC.C...C.\nC.C..C..\nC...C.C.",
"output": "80"
},
{
"input": "9\n.C...CCCC\nC.CCCC...\n....C..CC\n.CC.CCC..\n.C.C..CC.\nC...C.CCC\nCCC.C...C\nCCCC....C\n..C..C..C",
"output": "144"
},
{
"input": "10\n..C..C.C..\n..CC..C.CC\n.C.C...C.C\n..C.CC..CC\n....C..C.C\n...C..C..C\nCC.CC....C\n..CCCC.C.C\n..CC.CCC..\nCCCC..C.CC",
"output": "190"
},
{
"input": "11\nC.CC...C.CC\nCC.C....C.C\n.....C..CCC\n....C.CC.CC\nC..C..CC...\nC...C...C..\nCC..CCC.C.C\n..C.CC.C..C\nC...C.C..CC\n.C.C..CC..C\n.C.C.CC.C..",
"output": "228"
},
{
"input": "21\n...CCC.....CC..C..C.C\n..CCC...CC...CC.CCC.C\n....C.C.C..CCC..C.C.C\n....CCC..C..C.CC.CCC.\n...CCC.C..C.C.....CCC\n.CCC.....CCC..C...C.C\nCCCC.C...CCC.C...C.CC\nC..C...C.CCC..CC..C..\nC...CC..C.C.CC..C.CC.\nCC..CCCCCCCCC..C....C\n.C..CCCC.CCCC.CCC...C\nCCC...CCC...CCC.C..C.\n.CCCCCCCC.CCCC.CC.C..\n.C.C..C....C.CCCCCC.C\n...C...C.CCC.C.CC..C.\nCCC...CC..CC...C..C.C\n.CCCCC...C.C..C.CC.C.\n..CCC.C.C..CCC.CCC...\n..C..C.C.C.....CC.C..\n.CC.C...C.CCC.C....CC\n...C..CCCC.CCC....C..",
"output": "2103"
},
{
"input": "20\nC.C.CCC.C....C.CCCCC\nC.CC.C..CCC....CCCC.\n.CCC.CC...CC.CCCCCC.\n.C...CCCC..C....CCC.\n.C..CCCCCCC.C.C.....\nC....C.C..CCC.C..CCC\n...C.C.CC..CC..CC...\nC...CC.C.CCCCC....CC\n.CC.C.CCC....C.CCC.C\nCC...CC...CC..CC...C\nC.C..CC.C.CCCC.C.CC.\n..CCCCC.C.CCC..CCCC.\n....C..C..C.CC...C.C\nC..CCC..CC..C.CC..CC\n...CC......C.C..C.C.\nCC.CCCCC.CC.CC...C.C\n.C.CC..CC..CCC.C.CCC\nC..C.CC....C....C...\n..CCC..CCC...CC..C.C\n.C.CCC.CCCCCCCCC..CC",
"output": "2071"
},
{
"input": "17\nCCC..C.C....C.C.C\n.C.CC.CC...CC..C.\n.CCCC.CC.C..CCC.C\n...CCC.CC.CCC.C.C\nCCCCCCCC..C.CC.CC\n...C..C....C.CC.C\nCC....CCC...C.CC.\n.CC.C.CC..C......\n.CCCCC.C.CC.CCCCC\n..CCCC...C..CC..C\nC.CC.C.CC..C.C.C.\nC..C..C..CCC.C...\n.C..CCCC..C......\n.CC.C...C..CC.CC.\nC..C....CC...CC..\nC.CC.CC..C.C..C..\nCCCC...C.C..CCCC.",
"output": "1160"
},
{
"input": "15\nCCCC.C..CCC....\nCCCCCC.CC.....C\n...C.CC.C.C.CC.\nCCCCCCC..C..C..\nC..CCC..C.CCCC.\n.CC..C.C.C.CC.C\n.C.C..C..C.C..C\n...C...C..CCCC.\n.....C.C..CC...\nCC.C.C..CC.C..C\n..CCCCC..CCC...\nCC.CC.C..CC.CCC\n..CCC...CC.C..C\nCC..C.C..CCC..C\n.C.C....CCC...C",
"output": "789"
},
{
"input": "1\n.",
"output": "0"
},
{
"input": "3\n.CC\nC..\nC.C",
"output": "4"
},
{
"input": "13\nC.C...C.C.C..\nCC.CCCC.CC..C\n.C.CCCCC.CC..\nCCCC..C...C..\n...CC.C.C...C\n.CC.CCC...CC.\nCC.CCCCCC....\n.C...C..CC..C\nCCCC.CC...C..\n.C.CCC..C.CC.\n..C...CC..C.C\n..C.CCC..CC.C\n.C...CCC.CC.C",
"output": "529"
},
{
"input": "16\n.C.C.C.C.C...C.C\n..C..C.CCCCCC...\n..C.C.C.C..C..C.\n.CC....C.CCC..C.\n.C.CCC..C....CCC\nCC..C.CC..C.C.CC\n...C..C..CC..CC.\n.CCC..C.CC.C.C..\n.CC.C..........C\nC...C....CC..C..\nC.CCC.C..C..C...\n.CCCCCCCCCCCC..C\n..C.C.CC.CC.CCC.\nCC..C.C....C..CC\nC.CCC..C..C.C.CC\n.C.CCC.CC..CCC.C",
"output": "874"
},
{
"input": "2\nCC\nCC",
"output": "4"
},
{
"input": "3\nC..\nC..\nC..",
"output": "3"
}
] | 1,588,573,944 | 2,147,483,647 | PyPy 3 | RUNTIME_ERROR | TESTS | 0 | 217 | 2,048,000 | import math as m
v,s= [],0
n = int(input())
for _ in range(n):
a = input()
s+=m.comb(a.count("C"),2)
v.append(a)
for i in range(n):
z =""
for j in range(n):
z+=v[j][i]
s+=m.comb(z.count("C"),2)
print(s) | Title: Far Relative’s Birthday Cake
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Door's family is going celebrate Famil Doors's birthday party. They love Famil Door so they are planning to make his birthday cake weird!
The cake is a *n*<=×<=*n* square consisting of equal squares with side length 1. Each square is either empty or consists of a single chocolate. They bought the cake and randomly started to put the chocolates on the cake. The value of Famil Door's happiness will be equal to the number of pairs of cells with chocolates that are in the same row or in the same column of the cake. Famil Doors's family is wondering what is the amount of happiness of Famil going to be?
Please, note that any pair can be counted no more than once, as two different cells can't share both the same row and the same column.
Input Specification:
In the first line of the input, you are given a single integer *n* (1<=≤<=*n*<=≤<=100) — the length of the side of the cake.
Then follow *n* lines, each containing *n* characters. Empty cells are denoted with '.', while cells that contain chocolates are denoted by 'C'.
Output Specification:
Print the value of Famil Door's happiness, i.e. the number of pairs of chocolate pieces that share the same row or the same column.
Demo Input:
['3\n.CC\nC..\nC.C\n', '4\nCC..\nC..C\n.CC.\n.CC.\n']
Demo Output:
['4\n', '9\n']
Note:
If we number rows from top to bottom and columns from left to right, then, pieces that share the same row in the first sample are:
1. (1, 2) and (1, 3) 1. (3, 1) and (3, 3) 1. (2, 1) and (3, 1) 1. (1, 3) and (3, 3) | ```python
import math as m
v,s= [],0
n = int(input())
for _ in range(n):
a = input()
s+=m.comb(a.count("C"),2)
v.append(a)
for i in range(n):
z =""
for j in range(n):
z+=v[j][i]
s+=m.comb(z.count("C"),2)
print(s)
``` | -1 |
|
463 | C | Gargari and Bishops | PROGRAMMING | 1,900 | [
"greedy",
"hashing",
"implementation"
] | null | null | Gargari is jealous that his friend Caisa won the game from the previous problem. He wants to prove that he is a genius.
He has a *n*<=×<=*n* chessboard. Each cell of the chessboard has a number written on it. Gargari wants to place two bishops on the chessboard in such a way that there is no cell that is attacked by both of them. Consider a cell with number *x* written on it, if this cell is attacked by one of the bishops Gargari will get *x* dollars for it. Tell Gargari, how to place bishops on the chessboard to get maximum amount of money.
We assume a cell is attacked by a bishop, if the cell is located on the same diagonal with the bishop (the cell, where the bishop is, also considered attacked by it). | The first line contains a single integer *n* (2<=≤<=*n*<=≤<=2000). Each of the next *n* lines contains *n* integers *a**ij* (0<=≤<=*a**ij*<=≤<=109) — description of the chessboard. | On the first line print the maximal number of dollars Gargari will get. On the next line print four integers: *x*1,<=*y*1,<=*x*2,<=*y*2 (1<=≤<=*x*1,<=*y*1,<=*x*2,<=*y*2<=≤<=*n*), where *x**i* is the number of the row where the *i*-th bishop should be placed, *y**i* is the number of the column where the *i*-th bishop should be placed. Consider rows are numbered from 1 to *n* from top to bottom, and columns are numbered from 1 to *n* from left to right.
If there are several optimal solutions, you can print any of them. | [
"4\n1 1 1 1\n2 1 1 0\n1 1 1 0\n1 0 0 1\n"
] | [
"12\n2 2 3 2\n"
] | none | 1,500 | [
{
"input": "4\n1 1 1 1\n2 1 1 0\n1 1 1 0\n1 0 0 1",
"output": "12\n2 2 3 2"
},
{
"input": "10\n48 43 75 80 32 30 65 31 18 91\n99 5 12 43 26 90 54 91 4 88\n8 87 68 95 73 37 53 46 53 90\n50 1 85 24 32 16 5 48 98 74\n38 49 78 2 91 3 43 96 93 46\n35 100 84 2 94 56 90 98 54 43\n88 3 95 72 78 78 87 82 25 37\n8 15 85 85 68 27 40 10 22 84\n7 8 36 90 10 81 98 51 79 51\n93 66 53 39 89 30 16 27 63 93",
"output": "2242\n6 6 7 6"
},
{
"input": "10\n0 0 0 0 0 0 0 0 0 0\n0 0 0 0 0 0 0 0 0 0\n0 0 0 0 0 0 0 0 0 0\n0 0 0 0 0 0 0 0 0 0\n0 0 0 0 0 0 0 0 0 0\n0 0 0 0 0 0 0 0 0 0\n0 0 0 0 0 0 0 0 0 0\n0 0 0 0 0 0 0 0 0 0\n0 0 0 0 0 0 0 0 0 0\n0 0 0 0 0 0 0 0 0 0",
"output": "0\n1 1 1 2"
},
{
"input": "15\n2 6 9 4 8 9 10 10 3 8 8 4 4 8 7\n10 9 2 6 8 10 5 2 8 4 9 6 9 10 10\n3 1 5 1 6 5 1 6 4 4 3 3 9 8 10\n5 7 10 6 4 9 6 8 1 5 4 9 10 4 8\n9 6 10 5 8 6 9 9 3 4 4 7 6 2 4\n8 6 10 7 3 3 8 10 3 8 4 8 8 3 1\n7 3 6 8 8 5 5 8 3 7 2 6 3 9 7\n6 8 4 7 7 7 10 4 6 4 3 10 1 10 2\n1 6 7 8 3 4 2 8 1 7 4 4 4 9 5\n3 4 4 6 1 10 2 2 5 8 7 7 7 7 6\n10 9 3 6 8 6 1 9 5 4 7 10 7 1 8\n3 3 4 9 8 6 10 2 9 5 9 5 3 7 3\n1 8 1 3 4 8 10 4 8 4 7 5 4 6 7\n3 10 9 6 8 8 1 8 9 9 4 9 5 6 5\n7 6 3 9 9 8 6 10 3 6 4 2 10 9 7",
"output": "361\n7 9 9 8"
},
{
"input": "8\n3 6 9 2 2 1 4 2\n1 4 10 1 1 10 1 4\n3 8 9 1 8 4 4 4\n5 8 10 5 5 6 4 7\n3 2 10 6 5 3 8 5\n6 7 5 8 8 5 4 2\n4 4 3 1 8 8 5 4\n5 6 8 9 3 1 8 5",
"output": "159\n4 4 5 4"
},
{
"input": "13\n9 9 3 3 5 6 8 2 6 1 10 3 8\n10 4 9 2 10 3 5 10 10 7 10 7 3\n5 8 4 1 10 2 1 2 4 7 9 1 10\n6 3 10 10 10 1 3 10 4 4 2 10 4\n1 7 5 7 9 9 7 4 1 8 5 4 1\n10 10 9 2 2 6 4 1 5 5 1 9 4\n4 2 5 5 7 8 1 2 6 1 2 4 6\n5 1 10 8 1 1 9 1 2 10 6 7 2\n2 1 2 10 4 7 4 1 4 10 10 4 3\n7 7 5 1 2 1 1 4 8 2 4 8 2\n8 8 8 4 1 1 7 3 1 10 1 4 2\n4 5 1 10 8 8 8 4 10 9 4 10 4\n3 1 10 10 5 7 9 4 2 10 4 8 4",
"output": "280\n6 6 7 6"
},
{
"input": "9\n3 9 6 1 7 6 2 8 4\n5 4 1 1 7 2 7 4 10\n7 9 9 4 6 2 7 2 8\n5 7 7 4 9 5 9 1 3\n7 3 10 2 9 4 2 1 2\n5 8 7 4 6 6 2 2 3\n4 8 4 3 4 2 1 8 10\n5 8 2 8 4 4 7 5 4\n2 8 7 4 3 6 10 8 1",
"output": "181\n5 4 6 4"
}
] | 1,587,492,386 | 2,147,483,647 | PyPy 3 | MEMORY_LIMIT_EXCEEDED | TESTS | 6 | 2,323 | 268,390,400 | a = []
for _ in range(int(input())):
a.append(list(map(int, input().split())))
l, r = {}, {}
for i in range(len(a)):
for j in range(len(a)):
r[i - j] = a[i][j] + r[i - j] if i - j in r else a[i][j]
l[i + j] = a[i][j] + l[i + j] if i + j in l else a[i][j]
black, white = [], []
for i in range(len(a)):
for j in range(len(a)):
t = l[i + j] + r[i - j] - a[i][j]
black.append((t, i, j)) if (i + j) % 2 else white.append((t, i, j))
a1, x1, y1 = max(black)
a2, x2, y2 = max(white)
print(a1 + a2)
print(x1 + 1, y1 + 1, x2 + 1, y2 + 1)
| Title: Gargari and Bishops
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Gargari is jealous that his friend Caisa won the game from the previous problem. He wants to prove that he is a genius.
He has a *n*<=×<=*n* chessboard. Each cell of the chessboard has a number written on it. Gargari wants to place two bishops on the chessboard in such a way that there is no cell that is attacked by both of them. Consider a cell with number *x* written on it, if this cell is attacked by one of the bishops Gargari will get *x* dollars for it. Tell Gargari, how to place bishops on the chessboard to get maximum amount of money.
We assume a cell is attacked by a bishop, if the cell is located on the same diagonal with the bishop (the cell, where the bishop is, also considered attacked by it).
Input Specification:
The first line contains a single integer *n* (2<=≤<=*n*<=≤<=2000). Each of the next *n* lines contains *n* integers *a**ij* (0<=≤<=*a**ij*<=≤<=109) — description of the chessboard.
Output Specification:
On the first line print the maximal number of dollars Gargari will get. On the next line print four integers: *x*1,<=*y*1,<=*x*2,<=*y*2 (1<=≤<=*x*1,<=*y*1,<=*x*2,<=*y*2<=≤<=*n*), where *x**i* is the number of the row where the *i*-th bishop should be placed, *y**i* is the number of the column where the *i*-th bishop should be placed. Consider rows are numbered from 1 to *n* from top to bottom, and columns are numbered from 1 to *n* from left to right.
If there are several optimal solutions, you can print any of them.
Demo Input:
['4\n1 1 1 1\n2 1 1 0\n1 1 1 0\n1 0 0 1\n']
Demo Output:
['12\n2 2 3 2\n']
Note:
none | ```python
a = []
for _ in range(int(input())):
a.append(list(map(int, input().split())))
l, r = {}, {}
for i in range(len(a)):
for j in range(len(a)):
r[i - j] = a[i][j] + r[i - j] if i - j in r else a[i][j]
l[i + j] = a[i][j] + l[i + j] if i + j in l else a[i][j]
black, white = [], []
for i in range(len(a)):
for j in range(len(a)):
t = l[i + j] + r[i - j] - a[i][j]
black.append((t, i, j)) if (i + j) % 2 else white.append((t, i, j))
a1, x1, y1 = max(black)
a2, x2, y2 = max(white)
print(a1 + a2)
print(x1 + 1, y1 + 1, x2 + 1, y2 + 1)
``` | 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,649,821,602 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 30 | 0 | a,b,c=map(intinput().split())
print(max(a,b,c)-min(a,b,c)) | 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
a,b,c=map(intinput().split())
print(max(a,b,c)-min(a,b,c))
``` | -1 |
|
1,003 | A | Polycarp's Pockets | PROGRAMMING | 800 | [
"implementation"
] | null | null | Polycarp has $n$ coins, the value of the $i$-th coin is $a_i$. Polycarp wants to distribute all the coins between his pockets, but he cannot put two coins with the same value into the same pocket.
For example, if Polycarp has got six coins represented as an array $a = [1, 2, 4, 3, 3, 2]$, he can distribute the coins into two pockets as follows: $[1, 2, 3], [2, 3, 4]$.
Polycarp wants to distribute all the coins with the minimum number of used pockets. Help him to do that. | The first line of the input contains one integer $n$ ($1 \le n \le 100$) — the number of coins.
The second line of the input contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 100$) — values of coins. | Print only one integer — the minimum number of pockets Polycarp needs to distribute all the coins so no two coins with the same value are put into the same pocket. | [
"6\n1 2 4 3 3 2\n",
"1\n100\n"
] | [
"2\n",
"1\n"
] | none | 0 | [
{
"input": "6\n1 2 4 3 3 2",
"output": "2"
},
{
"input": "1\n100",
"output": "1"
},
{
"input": "100\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": "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": "100"
},
{
"input": "100\n59 47 39 47 47 71 47 28 58 47 35 79 58 47 38 47 47 47 47 27 47 43 29 95 47 49 46 71 47 74 79 47 47 32 45 67 47 47 30 37 47 47 16 67 22 76 47 86 84 10 5 47 47 47 47 47 1 51 47 54 47 8 47 47 9 47 47 47 47 28 47 47 26 47 47 47 47 47 47 92 47 47 77 47 47 24 45 47 10 47 47 89 47 27 47 89 47 67 24 71",
"output": "51"
},
{
"input": "100\n45 99 10 27 16 85 39 38 17 32 15 23 67 48 50 97 42 70 62 30 44 81 64 73 34 22 46 5 83 52 58 60 33 74 47 88 18 61 78 53 25 95 94 31 3 75 1 57 20 54 59 9 68 7 77 43 21 87 86 24 4 80 11 49 2 72 36 84 71 8 65 55 79 100 41 14 35 89 66 69 93 37 56 82 90 91 51 19 26 92 6 96 13 98 12 28 76 40 63 29",
"output": "1"
},
{
"input": "100\n45 29 5 2 6 50 22 36 14 15 9 48 46 20 8 37 7 47 12 50 21 38 18 27 33 19 40 10 5 49 38 42 34 37 27 30 35 24 10 3 40 49 41 3 4 44 13 25 28 31 46 36 23 1 1 23 7 22 35 26 21 16 48 42 32 8 11 16 34 11 39 32 47 28 43 41 39 4 14 19 26 45 13 18 15 25 2 44 17 29 17 33 43 6 12 30 9 20 31 24",
"output": "2"
},
{
"input": "50\n7 7 3 3 7 4 5 6 4 3 7 5 6 4 5 4 4 5 6 7 7 7 4 5 5 5 3 7 6 3 4 6 3 6 4 4 5 4 6 6 3 5 6 3 5 3 3 7 7 6",
"output": "10"
},
{
"input": "100\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 99 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": "99"
},
{
"input": "7\n1 2 3 3 3 1 2",
"output": "3"
},
{
"input": "5\n1 2 3 4 5",
"output": "1"
},
{
"input": "7\n1 2 3 4 5 6 7",
"output": "1"
},
{
"input": "8\n1 2 3 4 5 6 7 8",
"output": "1"
},
{
"input": "9\n1 2 3 4 5 6 7 8 9",
"output": "1"
},
{
"input": "10\n1 2 3 4 5 6 7 8 9 10",
"output": "1"
},
{
"input": "3\n2 1 1",
"output": "2"
},
{
"input": "11\n1 2 3 4 5 6 7 8 9 1 1",
"output": "3"
},
{
"input": "12\n1 2 1 1 1 1 1 1 1 1 1 1",
"output": "11"
},
{
"input": "13\n1 1 1 1 1 1 1 1 1 1 1 1 1",
"output": "13"
},
{
"input": "14\n1 1 1 1 1 1 1 1 1 1 1 1 1 1",
"output": "14"
},
{
"input": "15\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1",
"output": "15"
},
{
"input": "16\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1",
"output": "16"
},
{
"input": "3\n1 1 1",
"output": "3"
},
{
"input": "3\n1 2 3",
"output": "1"
},
{
"input": "10\n1 1 1 1 2 2 1 1 9 10",
"output": "6"
},
{
"input": "2\n1 1",
"output": "2"
},
{
"input": "56\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",
"output": "56"
},
{
"input": "99\n35 96 73 72 70 83 22 93 98 75 45 32 81 82 45 54 25 7 53 72 29 2 94 19 21 98 34 28 39 99 55 85 44 23 6 47 98 2 33 34 19 57 49 35 67 4 60 4 4 23 55 6 57 66 16 68 34 45 84 79 48 63 4 9 46 88 98 13 19 27 83 12 4 63 57 22 44 77 44 62 28 52 44 64 9 24 55 22 48 4 2 9 80 76 45 1 56 22 92",
"output": "6"
},
{
"input": "10\n1 2 2 3 3 3 4 4 4 4",
"output": "4"
},
{
"input": "99\n97 44 33 56 42 10 61 85 64 26 40 39 82 34 75 9 51 51 39 73 58 38 74 31 13 99 58 1 28 89 76 19 52 7 40 56 12 27 72 72 67 75 62 46 22 55 35 16 18 39 60 63 92 42 85 69 34 61 73 50 57 95 30 4 45 63 76 58 32 35 48 81 10 78 95 79 55 97 21 21 22 94 30 17 78 57 89 93 100 44 16 89 68 55 19 46 42 73 21",
"output": "3"
},
{
"input": "5\n5 5 5 5 1",
"output": "4"
},
{
"input": "6\n2 3 2 5 2 6",
"output": "3"
},
{
"input": "3\n58 59 58",
"output": "2"
},
{
"input": "9\n1 2 3 4 5 6 7 8 8",
"output": "2"
},
{
"input": "97\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",
"output": "97"
},
{
"input": "3\n95 95 4",
"output": "2"
},
{
"input": "3\n2 2 5",
"output": "2"
}
] | 1,617,116,990 | 2,147,483,647 | Python 3 | OK | TESTS | 37 | 62 | 0 | # -*- coding: utf-8 -*-
"""
Created on Tue Mar 30 23:06:43 2021
@author: nagan
"""
n = int(input())
s = input().split()
l = [int(i) for i in s]
c = 1
for i in l:
if l.count(i) > c:
c = l.count(i)
print(c) | Title: Polycarp's Pockets
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Polycarp has $n$ coins, the value of the $i$-th coin is $a_i$. Polycarp wants to distribute all the coins between his pockets, but he cannot put two coins with the same value into the same pocket.
For example, if Polycarp has got six coins represented as an array $a = [1, 2, 4, 3, 3, 2]$, he can distribute the coins into two pockets as follows: $[1, 2, 3], [2, 3, 4]$.
Polycarp wants to distribute all the coins with the minimum number of used pockets. Help him to do that.
Input Specification:
The first line of the input contains one integer $n$ ($1 \le n \le 100$) — the number of coins.
The second line of the input contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 100$) — values of coins.
Output Specification:
Print only one integer — the minimum number of pockets Polycarp needs to distribute all the coins so no two coins with the same value are put into the same pocket.
Demo Input:
['6\n1 2 4 3 3 2\n', '1\n100\n']
Demo Output:
['2\n', '1\n']
Note:
none | ```python
# -*- coding: utf-8 -*-
"""
Created on Tue Mar 30 23:06:43 2021
@author: nagan
"""
n = int(input())
s = input().split()
l = [int(i) for i in s]
c = 1
for i in l:
if l.count(i) > c:
c = l.count(i)
print(c)
``` | 3 |
|
6 | A | Triangle | PROGRAMMING | 900 | [
"brute force",
"geometry"
] | A. Triangle | 2 | 64 | Johnny has a younger sister Anne, who is very clever and smart. As she came home from the kindergarten, she told his brother about the task that her kindergartener asked her to solve. The task was just to construct a triangle out of four sticks of different colours. Naturally, one of the sticks is extra. It is not allowed to break the sticks or use their partial length. Anne has perfectly solved this task, now she is asking Johnny to do the same.
The boy answered that he would cope with it without any difficulty. However, after a while he found out that different tricky things can occur. It can happen that it is impossible to construct a triangle of a positive area, but it is possible to construct a degenerate triangle. It can be so, that it is impossible to construct a degenerate triangle even. As Johnny is very lazy, he does not want to consider such a big amount of cases, he asks you to help him. | The first line of the input contains four space-separated positive integer numbers not exceeding 100 — lengthes of the sticks. | Output TRIANGLE if it is possible to construct a non-degenerate triangle. Output SEGMENT if the first case cannot take place and it is possible to construct a degenerate triangle. Output IMPOSSIBLE if it is impossible to construct any triangle. Remember that you are to use three sticks. It is not allowed to break the sticks or use their partial length. | [
"4 2 1 3\n",
"7 2 2 4\n",
"3 5 9 1\n"
] | [
"TRIANGLE\n",
"SEGMENT\n",
"IMPOSSIBLE\n"
] | none | 0 | [
{
"input": "4 2 1 3",
"output": "TRIANGLE"
},
{
"input": "7 2 2 4",
"output": "SEGMENT"
},
{
"input": "3 5 9 1",
"output": "IMPOSSIBLE"
},
{
"input": "3 1 5 1",
"output": "IMPOSSIBLE"
},
{
"input": "10 10 10 10",
"output": "TRIANGLE"
},
{
"input": "11 5 6 11",
"output": "TRIANGLE"
},
{
"input": "1 1 1 1",
"output": "TRIANGLE"
},
{
"input": "10 20 30 40",
"output": "TRIANGLE"
},
{
"input": "45 25 5 15",
"output": "IMPOSSIBLE"
},
{
"input": "20 5 8 13",
"output": "TRIANGLE"
},
{
"input": "10 30 7 20",
"output": "SEGMENT"
},
{
"input": "3 2 3 2",
"output": "TRIANGLE"
},
{
"input": "70 10 100 30",
"output": "SEGMENT"
},
{
"input": "4 8 16 2",
"output": "IMPOSSIBLE"
},
{
"input": "3 3 3 10",
"output": "TRIANGLE"
},
{
"input": "1 5 5 5",
"output": "TRIANGLE"
},
{
"input": "13 25 12 1",
"output": "SEGMENT"
},
{
"input": "10 100 7 3",
"output": "SEGMENT"
},
{
"input": "50 1 50 100",
"output": "TRIANGLE"
},
{
"input": "50 1 100 49",
"output": "SEGMENT"
},
{
"input": "49 51 100 1",
"output": "SEGMENT"
},
{
"input": "5 11 2 25",
"output": "IMPOSSIBLE"
},
{
"input": "91 50 9 40",
"output": "IMPOSSIBLE"
},
{
"input": "27 53 7 97",
"output": "IMPOSSIBLE"
},
{
"input": "51 90 24 8",
"output": "IMPOSSIBLE"
},
{
"input": "3 5 1 1",
"output": "IMPOSSIBLE"
},
{
"input": "13 49 69 15",
"output": "IMPOSSIBLE"
},
{
"input": "16 99 9 35",
"output": "IMPOSSIBLE"
},
{
"input": "27 6 18 53",
"output": "IMPOSSIBLE"
},
{
"input": "57 88 17 8",
"output": "IMPOSSIBLE"
},
{
"input": "95 20 21 43",
"output": "IMPOSSIBLE"
},
{
"input": "6 19 32 61",
"output": "IMPOSSIBLE"
},
{
"input": "100 21 30 65",
"output": "IMPOSSIBLE"
},
{
"input": "85 16 61 9",
"output": "IMPOSSIBLE"
},
{
"input": "5 6 19 82",
"output": "IMPOSSIBLE"
},
{
"input": "1 5 1 3",
"output": "IMPOSSIBLE"
},
{
"input": "65 10 36 17",
"output": "IMPOSSIBLE"
},
{
"input": "81 64 9 7",
"output": "IMPOSSIBLE"
},
{
"input": "11 30 79 43",
"output": "IMPOSSIBLE"
},
{
"input": "1 1 5 3",
"output": "IMPOSSIBLE"
},
{
"input": "21 94 61 31",
"output": "IMPOSSIBLE"
},
{
"input": "49 24 9 74",
"output": "IMPOSSIBLE"
},
{
"input": "11 19 5 77",
"output": "IMPOSSIBLE"
},
{
"input": "52 10 19 71",
"output": "SEGMENT"
},
{
"input": "2 3 7 10",
"output": "SEGMENT"
},
{
"input": "1 2 6 3",
"output": "SEGMENT"
},
{
"input": "2 6 1 8",
"output": "SEGMENT"
},
{
"input": "1 2 4 1",
"output": "SEGMENT"
},
{
"input": "4 10 6 2",
"output": "SEGMENT"
},
{
"input": "2 10 7 3",
"output": "SEGMENT"
},
{
"input": "5 2 3 9",
"output": "SEGMENT"
},
{
"input": "6 1 4 10",
"output": "SEGMENT"
},
{
"input": "10 6 4 1",
"output": "SEGMENT"
},
{
"input": "3 2 9 1",
"output": "SEGMENT"
},
{
"input": "22 80 29 7",
"output": "SEGMENT"
},
{
"input": "2 6 3 9",
"output": "SEGMENT"
},
{
"input": "3 1 2 1",
"output": "SEGMENT"
},
{
"input": "3 4 7 1",
"output": "SEGMENT"
},
{
"input": "8 4 3 1",
"output": "SEGMENT"
},
{
"input": "2 8 3 5",
"output": "SEGMENT"
},
{
"input": "4 1 2 1",
"output": "SEGMENT"
},
{
"input": "8 1 3 2",
"output": "SEGMENT"
},
{
"input": "6 2 1 8",
"output": "SEGMENT"
},
{
"input": "3 3 3 6",
"output": "TRIANGLE"
},
{
"input": "3 6 3 3",
"output": "TRIANGLE"
},
{
"input": "4 10 4 4",
"output": "TRIANGLE"
},
{
"input": "1 1 2 1",
"output": "TRIANGLE"
},
{
"input": "3 3 3 6",
"output": "TRIANGLE"
},
{
"input": "5 4 5 5",
"output": "TRIANGLE"
},
{
"input": "8 7 8 8",
"output": "TRIANGLE"
},
{
"input": "3 3 3 1",
"output": "TRIANGLE"
},
{
"input": "1 1 6 6",
"output": "TRIANGLE"
},
{
"input": "1 9 1 9",
"output": "TRIANGLE"
},
{
"input": "7 2 2 7",
"output": "TRIANGLE"
},
{
"input": "7 2 3 2",
"output": "TRIANGLE"
},
{
"input": "4 4 10 10",
"output": "TRIANGLE"
},
{
"input": "7 7 10 7",
"output": "TRIANGLE"
},
{
"input": "4 4 4 5",
"output": "TRIANGLE"
},
{
"input": "1 10 9 2",
"output": "TRIANGLE"
},
{
"input": "1 8 2 7",
"output": "TRIANGLE"
},
{
"input": "4 3 2 8",
"output": "TRIANGLE"
},
{
"input": "5 9 5 3",
"output": "TRIANGLE"
},
{
"input": "4 10 3 5",
"output": "TRIANGLE"
}
] | 1,595,483,035 | 2,147,483,647 | Python 3 | OK | TESTS | 83 | 218 | 6,656,000 | l=sorted(map(int,input().split()))
p=max((l[0]+l[1])-l[2],(l[1]+l[2])-l[3])
if(p>0):
print('TRIANGLE')
else:
if(p==0):
print('SEGMENT')
else:
print('IMPOSSIBLE') | Title: Triangle
Time Limit: 2 seconds
Memory Limit: 64 megabytes
Problem Description:
Johnny has a younger sister Anne, who is very clever and smart. As she came home from the kindergarten, she told his brother about the task that her kindergartener asked her to solve. The task was just to construct a triangle out of four sticks of different colours. Naturally, one of the sticks is extra. It is not allowed to break the sticks or use their partial length. Anne has perfectly solved this task, now she is asking Johnny to do the same.
The boy answered that he would cope with it without any difficulty. However, after a while he found out that different tricky things can occur. It can happen that it is impossible to construct a triangle of a positive area, but it is possible to construct a degenerate triangle. It can be so, that it is impossible to construct a degenerate triangle even. As Johnny is very lazy, he does not want to consider such a big amount of cases, he asks you to help him.
Input Specification:
The first line of the input contains four space-separated positive integer numbers not exceeding 100 — lengthes of the sticks.
Output Specification:
Output TRIANGLE if it is possible to construct a non-degenerate triangle. Output SEGMENT if the first case cannot take place and it is possible to construct a degenerate triangle. Output IMPOSSIBLE if it is impossible to construct any triangle. Remember that you are to use three sticks. It is not allowed to break the sticks or use their partial length.
Demo Input:
['4 2 1 3\n', '7 2 2 4\n', '3 5 9 1\n']
Demo Output:
['TRIANGLE\n', 'SEGMENT\n', 'IMPOSSIBLE\n']
Note:
none | ```python
l=sorted(map(int,input().split()))
p=max((l[0]+l[1])-l[2],(l[1]+l[2])-l[3])
if(p>0):
print('TRIANGLE')
else:
if(p==0):
print('SEGMENT')
else:
print('IMPOSSIBLE')
``` | 3.895909 |
276 | A | Lunch Rush | PROGRAMMING | 900 | [
"implementation"
] | null | null | Having written another programming contest, three Rabbits decided to grab some lunch. The coach gave the team exactly *k* time units for the lunch break.
The Rabbits have a list of *n* restaurants to lunch in: the *i*-th restaurant is characterized by two integers *f**i* and *t**i*. Value *t**i* shows the time the Rabbits need to lunch in the *i*-th restaurant. If time *t**i* exceeds the time *k* that the coach has given for the lunch break, then the Rabbits' joy from lunching in this restaurant will equal *f**i*<=-<=(*t**i*<=-<=*k*). Otherwise, the Rabbits get exactly *f**i* units of joy.
Your task is to find the value of the maximum joy the Rabbits can get from the lunch, depending on the restaurant. The Rabbits must choose exactly one restaurant to lunch in. Note that the joy value isn't necessarily a positive value. | The first line contains two space-separated integers — *n* (1<=≤<=*n*<=≤<=104) and *k* (1<=≤<=*k*<=≤<=109) — the number of restaurants in the Rabbits' list and the time the coach has given them to lunch, correspondingly. Each of the next *n* lines contains two space-separated integers — *f**i* (1<=≤<=*f**i*<=≤<=109) and *t**i* (1<=≤<=*t**i*<=≤<=109) — the characteristics of the *i*-th restaurant. | In a single line print a single integer — the maximum joy value that the Rabbits will get from the lunch. | [
"2 5\n3 3\n4 5\n",
"4 6\n5 8\n3 6\n2 3\n2 2\n",
"1 5\n1 7\n"
] | [
"4\n",
"3\n",
"-1\n"
] | none | 500 | [
{
"input": "2 5\n3 3\n4 5",
"output": "4"
},
{
"input": "4 6\n5 8\n3 6\n2 3\n2 2",
"output": "3"
},
{
"input": "1 5\n1 7",
"output": "-1"
},
{
"input": "4 9\n10 13\n4 18\n13 3\n10 6",
"output": "13"
},
{
"input": "1 1\n1 1000000000",
"output": "-999999998"
},
{
"input": "1 1\n1000000000 1000000000",
"output": "1"
},
{
"input": "1 1\n1000000000 1",
"output": "1000000000"
},
{
"input": "2 3\n1000000000 1\n2 2",
"output": "1000000000"
},
{
"input": "2 5\n1 7\n1 1000000000",
"output": "-1"
}
] | 1,674,109,425 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 92 | 0 | n,k = map(int,input().split())
b1 = n
b = 0
while n>0:
n-=1
f,t = map(int,input().split())
for i in range(b1+1):
if k>b:
b+=t
else:
print(f-(t-k))
break
| Title: Lunch Rush
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Having written another programming contest, three Rabbits decided to grab some lunch. The coach gave the team exactly *k* time units for the lunch break.
The Rabbits have a list of *n* restaurants to lunch in: the *i*-th restaurant is characterized by two integers *f**i* and *t**i*. Value *t**i* shows the time the Rabbits need to lunch in the *i*-th restaurant. If time *t**i* exceeds the time *k* that the coach has given for the lunch break, then the Rabbits' joy from lunching in this restaurant will equal *f**i*<=-<=(*t**i*<=-<=*k*). Otherwise, the Rabbits get exactly *f**i* units of joy.
Your task is to find the value of the maximum joy the Rabbits can get from the lunch, depending on the restaurant. The Rabbits must choose exactly one restaurant to lunch in. Note that the joy value isn't necessarily a positive value.
Input Specification:
The first line contains two space-separated integers — *n* (1<=≤<=*n*<=≤<=104) and *k* (1<=≤<=*k*<=≤<=109) — the number of restaurants in the Rabbits' list and the time the coach has given them to lunch, correspondingly. Each of the next *n* lines contains two space-separated integers — *f**i* (1<=≤<=*f**i*<=≤<=109) and *t**i* (1<=≤<=*t**i*<=≤<=109) — the characteristics of the *i*-th restaurant.
Output Specification:
In a single line print a single integer — the maximum joy value that the Rabbits will get from the lunch.
Demo Input:
['2 5\n3 3\n4 5\n', '4 6\n5 8\n3 6\n2 3\n2 2\n', '1 5\n1 7\n']
Demo Output:
['4\n', '3\n', '-1\n']
Note:
none | ```python
n,k = map(int,input().split())
b1 = n
b = 0
while n>0:
n-=1
f,t = map(int,input().split())
for i in range(b1+1):
if k>b:
b+=t
else:
print(f-(t-k))
break
``` | 0 |
|
437 | A | The Child and Homework | PROGRAMMING | 1,300 | [
"implementation"
] | null | null | Once upon a time a child got a test consisting of multiple-choice questions as homework. A multiple-choice question consists of four choices: A, B, C and D. Each choice has a description, and the child should find out the only one that is correct.
Fortunately the child knows how to solve such complicated test. The child will follow the algorithm:
- If there is some choice whose description at least twice shorter than all other descriptions, or at least twice longer than all other descriptions, then the child thinks the choice is great. - If there is exactly one great choice then the child chooses it. Otherwise the child chooses C (the child think it is the luckiest choice).
You are given a multiple-choice questions, can you predict child's choose? | The first line starts with "A." (without quotes), then followed the description of choice A. The next three lines contains the descriptions of the other choices in the same format. They are given in order: B, C, D. Please note, that the description goes after prefix "X.", so the prefix mustn't be counted in description's length.
Each description is non-empty and consists of at most 100 characters. Each character can be either uppercase English letter or lowercase English letter, or "_". | Print a single line with the child's choice: "A", "B", "C" or "D" (without quotes). | [
"A.VFleaKing_is_the_author_of_this_problem\nB.Picks_is_the_author_of_this_problem\nC.Picking_is_the_author_of_this_problem\nD.Ftiasch_is_cute\n",
"A.ab\nB.abcde\nC.ab\nD.abc\n",
"A.c\nB.cc\nC.c\nD.c\n"
] | [
"D\n",
"C\n",
"B\n"
] | In the first sample, the first choice has length 39, the second one has length 35, the third one has length 37, and the last one has length 15. The choice D (length 15) is twice shorter than all other choices', so it is great choice. There is no other great choices so the child will choose D.
In the second sample, no choice is great, so the child will choose the luckiest choice C.
In the third sample, the choice B (length 2) is twice longer than all other choices', so it is great choice. There is no other great choices so the child will choose B. | 500 | [
{
"input": "A.VFleaKing_is_the_author_of_this_problem\nB.Picks_is_the_author_of_this_problem\nC.Picking_is_the_author_of_this_problem\nD.Ftiasch_is_cute",
"output": "D"
},
{
"input": "A.ab\nB.abcde\nC.ab\nD.abc",
"output": "C"
},
{
"input": "A.c\nB.cc\nC.c\nD.c",
"output": "B"
},
{
"input": "A.He_nan_de_yang_guang_zhao_yao_zhe_wo_men_mei_guo_ren_lian_shang_dou_xiao_kai_yan_wahaaaaaaaaaaaaaaaa\nB.Li_bai_li_bai_fei_liu_zhi_xia_san_qian_chi_yi_si_yin_he_luo_jiu_tian_li_bai_li_bai_li_bai_li_bai_shi\nC.Peng_yu_xiang_shi_zai_tai_shen_le_jian_zhi_jiu_shi_ye_jie_du_liu_a_si_mi_da_zhen_shi_tai_shen_le_a_a\nD.Wo_huo_le_si_shi_er_nian_zhen_de_shi_cong_lai_ye_mei_you_jian_guo_zhe_me_biao_zhun_de_yi_bai_ge_zi_a",
"output": "C"
},
{
"input": "A.a___FXIcs_gB____dxFFzst_p_P_Xp_vS__cS_C_ei_\nB.fmnmkS_SeZYx_tSys_d__Exbojv_a_YPEL_BPj__I_aYH\nC._nrPx_j\nD.o_A_UwmNbC_sZ_AXk_Y___i_SN_U_UxrBN_qo_____",
"output": "C"
},
{
"input": "A.G_R__iT_ow_Y__Sm_al__u_____l_ltK\nB.CWRe__h__cbCF\nC._QJ_dVHCL_g_WBsMO__LC____hMNE_DoO__xea_ec\nD.___Zh_",
"output": "D"
},
{
"input": "A.a___FXIcs_gB____dxFFzst_p_P_Xp_vS__cS_C_ei_\nB.fmnmkS_SeZYx_tSys_d__Exbojv_a_YPEL_BPj__I_aYH\nC._nrPx_j\nD.o_A_UwmNbC_sZ_AXk_Y___i_SN_U_UxrBN_qo_____",
"output": "C"
},
{
"input": "A.G_R__iT_ow_Y__Sm_al__u_____l_ltK\nB.CWRe__h__cbCF\nC._QJ_dVHCL_g_WBsMO__LC____hMNE_DoO__xea_ec\nD.___Zh_",
"output": "D"
},
{
"input": "A.ejQ_E_E_G_e_SDjZ__lh_f_K__Z_i_B_U__S__S_EMD_ZEU_Sq\nB.o_JpInEdsrAY_T__D_S\nC.E_Vp_s\nD.a_AU_h",
"output": "A"
},
{
"input": "A.PN_m_P_qgOAMwDyxtbH__Yc__bPOh_wYH___n_Fv_qlZp_\nB._gLeDU__rr_vjrm__O_jl_R__DG___u_XqJjW_\nC.___sHLQzdTzT_tZ_Gs\nD.sZNcVa__M_To_bz_clFi_mH_",
"output": "C"
},
{
"input": "A.bR___cCYJg_Wbt____cxfXfC____c_O_\nB.guM\nC.__bzsH_Of__RjG__u_w_i__PXQL_U_Ow_U_n\nD._nHIuZsu_uU_stRC_k___vD_ZOD_u_z_c_Zf__p_iF_uD_Hdg",
"output": "B"
},
{
"input": "A.x_\nB.__RSiDT_\nC.Ci\nD.KLY_Hc_YN_xXg_DynydumheKTw_PFHo_vqXwm_DY_dA___OS_kG___",
"output": "D"
},
{
"input": "A.yYGJ_C__NYq_\nB.ozMUZ_cKKk_zVUPR_b_g_ygv_HoM__yAxvh__iE\nC.sgHJ___MYP__AWejchRvjSD_o\nD.gkfF_GiOqW_psMT_eS",
"output": "C"
},
{
"input": "A._LYm_nvl_E__RCFZ_IdO\nB.k__qIPO_ivvZyIG__L_\nC.D_SabLm_R___j_HS_t__\nD._adj_R_ngix____GSe_aw__SbOOl_",
"output": "C"
},
{
"input": "A.h_WiYTD_C_h___z_Gn_Th_uNh__g___jm\nB.__HeQaudCJcYfVi__Eg_vryuQrDkb_g__oy_BwX_Mu_\nC._MChdMhQA_UKrf_LGZk_ALTo_mnry_GNNza_X_D_u____ueJb__Y_h__CNUNDfmZATck_ad_XTbG\nD.NV___OoL__GfP_CqhD__RB_____v_T_xi",
"output": "C"
},
{
"input": "A.____JGWsfiU\nB.S_LMq__MpE_oFBs_P\nC.U_Rph_VHpUr____X_jWXbk__ElJTu_Z_wlBpKLTD\nD.p_ysvPNmbrF__",
"output": "C"
},
{
"input": "A.ejQ_E_E_G_e_SDjZ__lh_f_K__Z_i_B_U__S__S_EMD_ZEU_Sq\nB.o_JpInEdsrAY_T__D_S\nC.E_Vp_s\nD.a_AU_h",
"output": "A"
},
{
"input": "A.PN_m_P_qgOAMwDyxtbH__Yc__bPOh_wYH___n_Fv_qlZp_\nB._gLeDU__rr_vjrm__O_jl_R__DG___u_XqJjW_\nC.___sHLQzdTzT_tZ_Gs\nD.sZNcVa__M_To_bz_clFi_mH_",
"output": "C"
},
{
"input": "A.bR___cCYJg_Wbt____cxfXfC____c_O_\nB.guM\nC.__bzsH_Of__RjG__u_w_i__PXQL_U_Ow_U_n\nD._nHIuZsu_uU_stRC_k___vD_ZOD_u_z_c_Zf__p_iF_uD_Hdg",
"output": "B"
},
{
"input": "A.x_\nB.__RSiDT_\nC.Ci\nD.KLY_Hc_YN_xXg_DynydumheKTw_PFHo_vqXwm_DY_dA___OS_kG___",
"output": "D"
},
{
"input": "A.yYGJ_C__NYq_\nB.ozMUZ_cKKk_zVUPR_b_g_ygv_HoM__yAxvh__iE\nC.sgHJ___MYP__AWejchRvjSD_o\nD.gkfF_GiOqW_psMT_eS",
"output": "C"
},
{
"input": "A._LYm_nvl_E__RCFZ_IdO\nB.k__qIPO_ivvZyIG__L_\nC.D_SabLm_R___j_HS_t__\nD._adj_R_ngix____GSe_aw__SbOOl_",
"output": "C"
},
{
"input": "A.h_WiYTD_C_h___z_Gn_Th_uNh__g___jm\nB.__HeQaudCJcYfVi__Eg_vryuQrDkb_g__oy_BwX_Mu_\nC._MChdMhQA_UKrf_LGZk_ALTo_mnry_GNNza_X_D_u____ueJb__Y_h__CNUNDfmZATck_ad_XTbG\nD.NV___OoL__GfP_CqhD__RB_____v_T_xi",
"output": "C"
},
{
"input": "A.____JGWsfiU\nB.S_LMq__MpE_oFBs_P\nC.U_Rph_VHpUr____X_jWXbk__ElJTu_Z_wlBpKLTD\nD.p_ysvPNmbrF__",
"output": "C"
},
{
"input": "A.aaaaaa\nB.aaa\nC.aaa\nD.aaa",
"output": "A"
},
{
"input": "A.aaa\nB.aaaaaa\nC.aaaaaa\nD.aaaaaa",
"output": "A"
},
{
"input": "A.a\nB.b\nC.c\nD.d",
"output": "C"
},
{
"input": "A._\nB.__\nC.____\nD.________",
"output": "C"
},
{
"input": "A.____\nB.________\nC.________\nD._______",
"output": "C"
},
{
"input": "A.h\nB.asdf\nC.asqw\nD.qwertasdfg",
"output": "C"
},
{
"input": "A.aa\nB.aaaaa\nC.aaaaaa\nD.aaaaaaaaaaaaa",
"output": "C"
},
{
"input": "A.ccc\nB.ccccccc\nC.ccc\nD.c",
"output": "C"
},
{
"input": "A.c\nB.ccc\nC.cccccccccccccccccc\nD.cccccc",
"output": "C"
},
{
"input": "A.aa\nB.bb\nC.cc\nD.ddd",
"output": "C"
},
{
"input": "A.QW\nB.WERT\nC.QWER\nD.QWERTYUI",
"output": "C"
}
] | 1,590,385,274 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 32 | 140 | 0 | a = len(input())-2
b = len(input())-2
c = len(input())-2
d = len(input())-2
ans = ""
if (a >= 2*b and a >= 2*c and a >= 2*d) or (2*a <= b and 2*a <= c and 2*a <= d):
ans += "A"
if (b >= 2*a and b >= 2*c and b >= 2*d) or (2*b <= a and 2*b <= c and 2*b <= d):
ans += "B"
if (d >= 2*b and d >= 2*c and d >= 2*a) or (2*d <= b and 2*d <= a and 2*d <= c):
ans += "D"
if(len(ans) == 1):
print(ans)
else:
print("C") | Title: The Child and Homework
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Once upon a time a child got a test consisting of multiple-choice questions as homework. A multiple-choice question consists of four choices: A, B, C and D. Each choice has a description, and the child should find out the only one that is correct.
Fortunately the child knows how to solve such complicated test. The child will follow the algorithm:
- If there is some choice whose description at least twice shorter than all other descriptions, or at least twice longer than all other descriptions, then the child thinks the choice is great. - If there is exactly one great choice then the child chooses it. Otherwise the child chooses C (the child think it is the luckiest choice).
You are given a multiple-choice questions, can you predict child's choose?
Input Specification:
The first line starts with "A." (without quotes), then followed the description of choice A. The next three lines contains the descriptions of the other choices in the same format. They are given in order: B, C, D. Please note, that the description goes after prefix "X.", so the prefix mustn't be counted in description's length.
Each description is non-empty and consists of at most 100 characters. Each character can be either uppercase English letter or lowercase English letter, or "_".
Output Specification:
Print a single line with the child's choice: "A", "B", "C" or "D" (without quotes).
Demo Input:
['A.VFleaKing_is_the_author_of_this_problem\nB.Picks_is_the_author_of_this_problem\nC.Picking_is_the_author_of_this_problem\nD.Ftiasch_is_cute\n', 'A.ab\nB.abcde\nC.ab\nD.abc\n', 'A.c\nB.cc\nC.c\nD.c\n']
Demo Output:
['D\n', 'C\n', 'B\n']
Note:
In the first sample, the first choice has length 39, the second one has length 35, the third one has length 37, and the last one has length 15. The choice D (length 15) is twice shorter than all other choices', so it is great choice. There is no other great choices so the child will choose D.
In the second sample, no choice is great, so the child will choose the luckiest choice C.
In the third sample, the choice B (length 2) is twice longer than all other choices', so it is great choice. There is no other great choices so the child will choose B. | ```python
a = len(input())-2
b = len(input())-2
c = len(input())-2
d = len(input())-2
ans = ""
if (a >= 2*b and a >= 2*c and a >= 2*d) or (2*a <= b and 2*a <= c and 2*a <= d):
ans += "A"
if (b >= 2*a and b >= 2*c and b >= 2*d) or (2*b <= a and 2*b <= c and 2*b <= d):
ans += "B"
if (d >= 2*b and d >= 2*c and d >= 2*a) or (2*d <= b and 2*d <= a and 2*d <= c):
ans += "D"
if(len(ans) == 1):
print(ans)
else:
print("C")
``` | 0 |
|
902 | A | Visiting a Friend | PROGRAMMING | 1,100 | [
"greedy",
"implementation"
] | null | null | Pig is visiting a friend.
Pig's house is located at point 0, and his friend's house is located at point *m* on an axis.
Pig can use teleports to move along the axis.
To use a teleport, Pig should come to a certain point (where the teleport is located) and choose where to move: for each teleport there is the rightmost point it can move Pig to, this point is known as the limit of the teleport.
Formally, a teleport located at point *x* with limit *y* can move Pig from point *x* to any point within the segment [*x*;<=*y*], including the bounds.
Determine if Pig can visit the friend using teleports only, or he should use his car. | The first line contains two integers *n* and *m* (1<=≤<=*n*<=≤<=100,<=1<=≤<=*m*<=≤<=100) — the number of teleports and the location of the friend's house.
The next *n* lines contain information about teleports.
The *i*-th of these lines contains two integers *a**i* and *b**i* (0<=≤<=*a**i*<=≤<=*b**i*<=≤<=*m*), where *a**i* is the location of the *i*-th teleport, and *b**i* is its limit.
It is guaranteed that *a**i*<=≥<=*a**i*<=-<=1 for every *i* (2<=≤<=*i*<=≤<=*n*). | Print "YES" if there is a path from Pig's house to his friend's house that uses only teleports, and "NO" otherwise.
You can print each letter in arbitrary case (upper or lower). | [
"3 5\n0 2\n2 4\n3 5\n",
"3 7\n0 4\n2 5\n6 7\n"
] | [
"YES\n",
"NO\n"
] | The first example is shown on the picture below:
Pig can use the first teleport from his house (point 0) to reach point 2, then using the second teleport go from point 2 to point 3, then using the third teleport go from point 3 to point 5, where his friend lives.
The second example is shown on the picture below:
You can see that there is no path from Pig's house to his friend's house that uses only teleports. | 500 | [
{
"input": "3 5\n0 2\n2 4\n3 5",
"output": "YES"
},
{
"input": "3 7\n0 4\n2 5\n6 7",
"output": "NO"
},
{
"input": "1 1\n0 0",
"output": "NO"
},
{
"input": "30 10\n0 7\n1 2\n1 2\n1 4\n1 4\n1 3\n2 2\n2 4\n2 6\n2 9\n2 2\n3 5\n3 8\n4 8\n4 5\n4 6\n5 6\n5 7\n6 6\n6 9\n6 7\n6 9\n7 7\n7 7\n8 8\n8 8\n9 9\n9 9\n10 10\n10 10",
"output": "NO"
},
{
"input": "30 100\n0 27\n4 82\n11 81\n14 32\n33 97\n33 34\n37 97\n38 52\n45 91\n49 56\n50 97\n57 70\n59 94\n59 65\n62 76\n64 65\n65 95\n67 77\n68 100\n71 73\n80 94\n81 92\n84 85\n85 100\n88 91\n91 95\n92 98\n92 98\n99 100\n100 100",
"output": "YES"
},
{
"input": "70 10\n0 4\n0 4\n0 8\n0 9\n0 1\n0 5\n0 7\n1 3\n1 8\n1 8\n1 6\n1 6\n1 2\n1 3\n1 2\n1 3\n2 5\n2 4\n2 3\n2 4\n2 6\n2 2\n2 5\n2 7\n3 7\n3 4\n3 7\n3 4\n3 8\n3 4\n3 9\n3 3\n3 7\n3 9\n3 3\n3 9\n4 6\n4 7\n4 5\n4 7\n5 8\n5 5\n5 9\n5 7\n5 5\n6 6\n6 9\n6 7\n6 8\n6 9\n6 8\n7 7\n7 8\n7 7\n7 8\n8 9\n8 8\n8 9\n8 8\n9 9\n9 9\n9 9\n9 9\n9 9\n9 9\n10 10\n10 10\n10 10\n10 10\n10 10",
"output": "NO"
},
{
"input": "30 10\n0 7\n1 2\n1 2\n1 4\n1 4\n1 3\n2 2\n2 4\n2 6\n2 9\n2 2\n3 5\n3 8\n4 8\n4 5\n4 6\n5 6\n5 7\n6 6\n6 9\n6 7\n6 9\n7 7\n7 7\n8 10\n8 10\n9 9\n9 9\n10 10\n10 10",
"output": "YES"
},
{
"input": "50 100\n0 95\n1 100\n1 38\n2 82\n5 35\n7 71\n8 53\n11 49\n15 27\n17 84\n17 75\n18 99\n18 43\n18 69\n21 89\n27 60\n27 29\n38 62\n38 77\n39 83\n40 66\n48 80\n48 100\n50 51\n50 61\n53 77\n53 63\n55 58\n56 68\n60 82\n62 95\n66 74\n67 83\n69 88\n69 81\n69 88\n69 98\n70 91\n70 76\n71 90\n72 99\n81 99\n85 87\n88 97\n88 93\n90 97\n90 97\n92 98\n98 99\n100 100",
"output": "YES"
},
{
"input": "70 10\n0 4\n0 4\n0 8\n0 9\n0 1\n0 5\n0 7\n1 3\n1 8\n1 8\n1 10\n1 9\n1 6\n1 2\n1 3\n1 2\n2 6\n2 5\n2 4\n2 3\n2 10\n2 2\n2 6\n2 2\n3 10\n3 7\n3 7\n3 4\n3 7\n3 4\n3 8\n3 4\n3 10\n3 5\n3 3\n3 7\n4 8\n4 8\n4 9\n4 6\n5 7\n5 10\n5 7\n5 8\n5 5\n6 8\n6 9\n6 10\n6 6\n6 9\n6 7\n7 8\n7 9\n7 10\n7 10\n8 8\n8 8\n8 9\n8 10\n9 10\n9 9\n9 10\n9 10\n9 9\n9 9\n10 10\n10 10\n10 10\n10 10\n10 10",
"output": "YES"
},
{
"input": "85 10\n0 9\n0 4\n0 2\n0 5\n0 1\n0 8\n0 7\n1 2\n1 4\n1 5\n1 9\n1 1\n1 6\n1 6\n2 5\n2 7\n2 7\n2 7\n2 7\n3 4\n3 7\n3 9\n3 5\n3 3\n4 4\n4 6\n4 5\n5 6\n5 6\n5 6\n5 6\n5 7\n5 8\n5 5\n5 7\n5 8\n5 9\n5 8\n6 8\n6 7\n6 8\n6 9\n6 9\n6 6\n6 9\n6 7\n7 7\n7 7\n7 7\n7 8\n7 7\n7 8\n7 8\n7 9\n8 8\n8 8\n8 8\n8 8\n8 8\n8 9\n8 9\n9 9\n9 9\n9 9\n9 9\n9 9\n9 9\n9 9\n9 9\n9 9\n10 10\n10 10\n10 10\n10 10\n10 10\n10 10\n10 10\n10 10\n10 10\n10 10\n10 10\n10 10\n10 10\n10 10\n10 10",
"output": "NO"
},
{
"input": "30 40\n0 0\n4 8\n5 17\n7 32\n7 16\n8 16\n10 19\n12 22\n12 27\n13 21\n13 28\n13 36\n14 28\n14 18\n18 21\n21 26\n21 36\n22 38\n23 32\n24 30\n26 35\n29 32\n29 32\n31 34\n31 31\n33 33\n33 35\n35 40\n38 38\n40 40",
"output": "NO"
},
{
"input": "70 100\n0 99\n1 87\n1 94\n1 4\n2 72\n3 39\n3 69\n4 78\n5 85\n7 14\n8 59\n12 69\n14 15\n14 76\n17 17\n19 53\n19 57\n19 21\n21 35\n21 83\n24 52\n24 33\n27 66\n27 97\n30 62\n30 74\n30 64\n32 63\n35 49\n37 60\n40 99\n40 71\n41 83\n42 66\n42 46\n45 83\n51 76\n53 69\n54 82\n54 96\n54 88\n55 91\n56 88\n58 62\n62 87\n64 80\n67 90\n67 69\n68 92\n72 93\n74 93\n77 79\n77 91\n78 97\n78 98\n81 85\n81 83\n81 83\n84 85\n86 88\n89 94\n89 92\n92 97\n96 99\n97 98\n97 99\n99 99\n100 100\n100 100\n100 100",
"output": "NO"
},
{
"input": "1 10\n0 10",
"output": "YES"
},
{
"input": "70 40\n0 34\n1 16\n3 33\n4 36\n4 22\n5 9\n5 9\n7 16\n8 26\n9 29\n9 25\n10 15\n10 22\n10 29\n10 20\n11 27\n11 26\n11 12\n12 19\n13 21\n14 31\n14 36\n15 34\n15 37\n16 21\n17 31\n18 22\n20 27\n20 32\n20 20\n20 29\n21 29\n21 34\n21 30\n22 40\n23 23\n23 28\n24 29\n25 38\n26 35\n27 37\n28 39\n28 33\n28 40\n28 33\n29 31\n29 33\n30 38\n30 36\n30 30\n30 38\n31 37\n31 35\n31 32\n31 36\n33 39\n33 40\n35 38\n36 38\n37 38\n37 40\n38 39\n38 40\n38 39\n39 39\n39 40\n40 40\n40 40\n40 40\n40 40",
"output": "YES"
},
{
"input": "50 40\n0 9\n1 26\n1 27\n2 33\n2 5\n3 30\n4 28\n5 31\n5 27\n5 29\n7 36\n8 32\n8 13\n9 24\n10 10\n10 30\n11 26\n11 22\n11 40\n11 31\n12 26\n13 25\n14 32\n17 19\n21 29\n22 36\n24 27\n25 39\n25 27\n27 32\n27 29\n27 39\n27 29\n28 38\n30 38\n32 40\n32 38\n33 33\n33 40\n34 35\n34 34\n34 38\n34 38\n35 37\n36 39\n36 39\n37 37\n38 40\n39 39\n40 40",
"output": "YES"
},
{
"input": "70 40\n0 34\n1 16\n3 33\n4 36\n4 22\n5 9\n5 9\n7 16\n8 26\n9 29\n9 25\n10 15\n10 22\n10 29\n10 20\n11 27\n11 26\n11 12\n12 19\n13 21\n14 31\n14 36\n15 34\n15 37\n16 21\n17 31\n18 22\n20 27\n20 32\n20 20\n20 29\n21 29\n21 34\n21 30\n22 22\n23 28\n23 39\n24 24\n25 27\n26 38\n27 39\n28 33\n28 39\n28 34\n28 33\n29 30\n29 35\n30 30\n30 38\n30 34\n30 31\n31 36\n31 31\n31 32\n31 38\n33 34\n33 34\n35 36\n36 38\n37 38\n37 39\n38 38\n38 38\n38 38\n39 39\n39 39\n40 40\n40 40\n40 40\n40 40",
"output": "NO"
},
{
"input": "10 100\n0 34\n8 56\n17 79\n24 88\n28 79\n45 79\n48 93\n55 87\n68 93\n88 99",
"output": "NO"
},
{
"input": "10 10\n0 2\n3 8\n3 5\n3 3\n3 9\n3 8\n5 7\n6 10\n7 10\n9 10",
"output": "NO"
},
{
"input": "50 10\n0 2\n0 2\n0 6\n1 9\n1 3\n1 2\n1 6\n1 1\n1 1\n2 7\n2 6\n2 4\n3 9\n3 8\n3 8\n3 8\n3 6\n3 4\n3 7\n3 4\n3 6\n3 5\n4 8\n5 5\n5 7\n6 7\n6 6\n7 7\n7 7\n7 7\n7 8\n7 8\n8 8\n8 8\n8 9\n8 8\n8 9\n9 9\n9 9\n9 9\n10 10\n10 10\n10 10\n10 10\n10 10\n10 10\n10 10\n10 10\n10 10\n10 10",
"output": "NO"
},
{
"input": "10 40\n0 21\n1 19\n4 33\n6 26\n8 39\n15 15\n20 24\n27 27\n29 39\n32 37",
"output": "NO"
},
{
"input": "50 10\n0 2\n0 2\n0 6\n1 9\n1 3\n1 2\n1 6\n1 1\n1 1\n2 7\n2 6\n2 4\n3 9\n3 8\n3 8\n3 8\n3 6\n3 4\n3 7\n3 4\n3 6\n3 10\n4 6\n5 9\n5 5\n6 7\n6 10\n7 8\n7 7\n7 7\n7 7\n7 10\n8 8\n8 8\n8 10\n8 8\n8 8\n9 10\n9 10\n9 10\n10 10\n10 10\n10 10\n10 10\n10 10\n10 10\n10 10\n10 10\n10 10\n10 10",
"output": "YES"
},
{
"input": "1 1\n0 1",
"output": "YES"
},
{
"input": "30 40\n0 0\n4 8\n5 17\n7 32\n7 16\n8 16\n10 19\n12 22\n12 27\n13 21\n13 28\n13 36\n14 28\n14 18\n18 21\n21 26\n21 36\n22 38\n23 32\n24 30\n26 35\n29 32\n29 32\n31 34\n31 31\n33 33\n33 35\n35 36\n38 38\n40 40",
"output": "NO"
},
{
"input": "30 100\n0 27\n4 82\n11 81\n14 32\n33 97\n33 34\n37 97\n38 52\n45 91\n49 56\n50 97\n57 70\n59 94\n59 65\n62 76\n64 65\n65 95\n67 77\n68 82\n71 94\n80 90\n81 88\n84 93\n85 89\n88 92\n91 97\n92 99\n92 97\n99 99\n100 100",
"output": "NO"
},
{
"input": "10 100\n0 34\n8 56\n17 79\n24 88\n28 79\n45 79\n48 93\n55 87\n68 93\n79 100",
"output": "YES"
},
{
"input": "10 40\n0 21\n1 19\n4 33\n6 26\n8 39\n15 15\n20 24\n27 27\n29 39\n37 40",
"output": "YES"
},
{
"input": "85 10\n0 9\n0 4\n0 2\n0 5\n0 1\n0 8\n0 7\n1 2\n1 10\n1 2\n1 5\n1 10\n1 8\n1 1\n2 8\n2 7\n2 5\n2 5\n2 7\n3 5\n3 7\n3 5\n3 4\n3 7\n4 7\n4 8\n4 6\n5 7\n5 10\n5 5\n5 6\n5 6\n5 6\n5 6\n5 7\n5 8\n5 5\n5 7\n6 10\n6 9\n6 7\n6 10\n6 8\n6 7\n6 10\n6 10\n7 8\n7 9\n7 8\n7 8\n7 8\n7 8\n7 7\n7 7\n8 8\n8 8\n8 10\n8 9\n8 9\n8 9\n8 9\n9 9\n9 10\n9 9\n9 9\n9 9\n9 9\n9 10\n9 10\n9 9\n10 10\n10 10\n10 10\n10 10\n10 10\n10 10\n10 10\n10 10\n10 10\n10 10\n10 10\n10 10\n10 10\n10 10\n10 10",
"output": "YES"
},
{
"input": "50 100\n0 95\n1 7\n1 69\n2 83\n5 67\n7 82\n8 31\n11 25\n15 44\n17 75\n17 27\n18 43\n18 69\n18 40\n21 66\n27 29\n27 64\n38 77\n38 90\n39 52\n40 60\n48 91\n48 98\n50 89\n50 63\n53 54\n53 95\n55 76\n56 59\n60 96\n62 86\n66 70\n67 77\n69 88\n69 98\n69 80\n69 95\n70 74\n70 77\n71 99\n72 73\n81 87\n85 99\n88 96\n88 91\n90 97\n90 99\n92 92\n98 99\n100 100",
"output": "NO"
},
{
"input": "50 40\n0 9\n1 26\n1 27\n2 33\n2 5\n3 30\n4 28\n5 31\n5 27\n5 29\n7 36\n8 32\n8 13\n9 24\n10 10\n10 30\n11 26\n11 22\n11 35\n11 23\n12 36\n13 31\n14 31\n17 17\n21 25\n22 33\n24 26\n25 32\n25 25\n27 39\n27 29\n27 34\n27 32\n28 34\n30 36\n32 37\n32 33\n33 35\n33 33\n34 38\n34 38\n34 36\n34 36\n35 36\n36 36\n36 39\n37 37\n38 39\n39 39\n40 40",
"output": "NO"
},
{
"input": "10 10\n0 2\n3 8\n3 5\n3 3\n3 9\n3 8\n5 7\n6 9\n7 7\n9 9",
"output": "NO"
},
{
"input": "70 100\n0 99\n1 87\n1 94\n1 4\n2 72\n3 39\n3 69\n4 78\n5 85\n7 14\n8 59\n12 69\n14 15\n14 76\n17 17\n19 53\n19 57\n19 21\n21 35\n21 83\n24 52\n24 33\n27 66\n27 97\n30 62\n30 74\n30 64\n32 63\n35 49\n37 60\n40 99\n40 71\n41 83\n42 66\n42 46\n45 83\n51 76\n53 69\n54 82\n54 96\n54 88\n55 91\n56 88\n58 62\n62 87\n64 80\n67 90\n67 69\n68 92\n72 93\n74 93\n77 79\n77 91\n78 97\n78 98\n81 85\n81 83\n81 83\n84 85\n86 88\n89 94\n89 100\n92 97\n96 96\n97 98\n97 100\n99 100\n100 100\n100 100\n100 100",
"output": "YES"
},
{
"input": "2 2\n0 2\n0 1",
"output": "YES"
},
{
"input": "2 100\n0 49\n50 100",
"output": "NO"
},
{
"input": "2 100\n0 50\n50 100",
"output": "YES"
},
{
"input": "10 100\n0 10\n10 20\n20 30\n30 40\n40 50\n50 60\n60 70\n70 80\n80 90\n90 100",
"output": "YES"
},
{
"input": "100 10\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 10",
"output": "YES"
},
{
"input": "1 4\n1 4",
"output": "NO"
},
{
"input": "3 5\n0 2\n2 5\n3 4",
"output": "YES"
},
{
"input": "2 5\n0 5\n1 2",
"output": "YES"
},
{
"input": "5 5\n0 2\n0 2\n3 5\n3 5\n3 5",
"output": "NO"
},
{
"input": "4 10\n0 3\n2 10\n4 10\n5 7",
"output": "YES"
},
{
"input": "3 8\n0 0\n1 8\n2 8",
"output": "NO"
},
{
"input": "6 8\n0 3\n1 5\n2 3\n5 6\n6 7\n7 8",
"output": "YES"
}
] | 1,659,975,528 | 2,147,483,647 | Python 3 | OK | TESTS | 55 | 46 | 0 | axis = [0]*105
n, m = map(int, input().split())
for _ in range(n):
x, y = map(int, input().split())
axis[x+1:y+1] = [1]*(y-x)
for i in range(1, m+1):
if not axis[i]:
print("No")
exit(0)
print("YES") | Title: Visiting a Friend
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Pig is visiting a friend.
Pig's house is located at point 0, and his friend's house is located at point *m* on an axis.
Pig can use teleports to move along the axis.
To use a teleport, Pig should come to a certain point (where the teleport is located) and choose where to move: for each teleport there is the rightmost point it can move Pig to, this point is known as the limit of the teleport.
Formally, a teleport located at point *x* with limit *y* can move Pig from point *x* to any point within the segment [*x*;<=*y*], including the bounds.
Determine if Pig can visit the friend using teleports only, or he should use his car.
Input Specification:
The first line contains two integers *n* and *m* (1<=≤<=*n*<=≤<=100,<=1<=≤<=*m*<=≤<=100) — the number of teleports and the location of the friend's house.
The next *n* lines contain information about teleports.
The *i*-th of these lines contains two integers *a**i* and *b**i* (0<=≤<=*a**i*<=≤<=*b**i*<=≤<=*m*), where *a**i* is the location of the *i*-th teleport, and *b**i* is its limit.
It is guaranteed that *a**i*<=≥<=*a**i*<=-<=1 for every *i* (2<=≤<=*i*<=≤<=*n*).
Output Specification:
Print "YES" if there is a path from Pig's house to his friend's house that uses only teleports, and "NO" otherwise.
You can print each letter in arbitrary case (upper or lower).
Demo Input:
['3 5\n0 2\n2 4\n3 5\n', '3 7\n0 4\n2 5\n6 7\n']
Demo Output:
['YES\n', 'NO\n']
Note:
The first example is shown on the picture below:
Pig can use the first teleport from his house (point 0) to reach point 2, then using the second teleport go from point 2 to point 3, then using the third teleport go from point 3 to point 5, where his friend lives.
The second example is shown on the picture below:
You can see that there is no path from Pig's house to his friend's house that uses only teleports. | ```python
axis = [0]*105
n, m = map(int, input().split())
for _ in range(n):
x, y = map(int, input().split())
axis[x+1:y+1] = [1]*(y-x)
for i in range(1, m+1):
if not axis[i]:
print("No")
exit(0)
print("YES")
``` | 3 |
|
83 | A | Magical Array | PROGRAMMING | 1,300 | [
"math"
] | A. Magical Array | 2 | 256 | Valery is very interested in magic. Magic attracts him so much that he sees it everywhere. He explains any strange and weird phenomenon through intervention of supernatural forces. But who would have thought that even in a regular array of numbers Valera manages to see something beautiful and magical.
Valera absolutely accidentally got a piece of ancient parchment on which an array of numbers was written. He immediately thought that the numbers in this array were not random. As a result of extensive research Valera worked out a wonderful property that a magical array should have: an array is defined as magic if its minimum and maximum coincide.
He decided to share this outstanding discovery with you, but he asks you for help in return. Despite the tremendous intelligence and wit, Valera counts very badly and so you will have to complete his work. All you have to do is count the number of magical subarrays of the original array of numbers, written on the parchment. Subarray is defined as non-empty sequence of consecutive elements. | The first line of the input data contains an integer *n* (1<=≤<=*n*<=≤<=105). The second line contains an array of original integers *a*1,<=*a*2,<=...,<=*a**n* (<=-<=109<=≤<=*a**i*<=≤<=109). | Print on the single line the answer to the problem: the amount of subarrays, which are magical.
Please do not use the %lld specificator to read or write 64-bit numbers in C++. It is recommended to use cin, cout streams (you can also use the %I64d specificator). | [
"4\n2 1 1 4\n",
"5\n-2 -2 -2 0 1\n"
] | [
"5\n",
"8\n"
] | Notes to sample tests:
Magical subarrays are shown with pairs of indices [a;b] of the beginning and the end.
In the first sample: [1;1], [2;2], [3;3], [4;4], [2;3].
In the second sample: [1;1], [2;2], [3;3], [4;4], [5;5], [1;2], [2;3], [1;3]. | 500 | [
{
"input": "4\n2 1 1 4",
"output": "5"
},
{
"input": "5\n-2 -2 -2 0 1",
"output": "8"
},
{
"input": "1\n10",
"output": "1"
},
{
"input": "2\n5 6",
"output": "2"
},
{
"input": "5\n5 5 4 5 5",
"output": "7"
},
{
"input": "8\n1 2 0 0 0 0 3 3",
"output": "15"
},
{
"input": "12\n-4 3 3 2 3 3 3 -4 2 -4 -4 -4",
"output": "19"
},
{
"input": "10\n7 1 0 10 0 -5 -3 -2 0 0",
"output": "11"
},
{
"input": "20\n6 0 0 -3 1 -3 0 -8 1 3 5 2 -1 -5 -1 9 0 6 -2 4",
"output": "21"
},
{
"input": "100\n0 -18 -9 -15 3 16 -28 0 -28 0 28 -20 -9 9 -11 0 18 -15 -18 -26 0 -27 -25 -22 6 -5 8 14 -17 24 20 3 -6 24 -27 1 -23 0 4 12 -20 0 -10 30 22 -6 13 16 0 15 17 -8 -2 0 -5 13 11 23 -17 -29 10 15 -28 0 -23 4 20 17 -7 -5 -16 -17 16 2 20 19 -8 0 8 -5 12 0 0 -14 -15 -28 -10 20 0 8 -1 10 14 9 0 4 -16 15 13 -10",
"output": "101"
},
{
"input": "50\n2 0 2 0 0 0 0 -1 -2 -2 -2 1 1 2 2 0 2 0 2 -3 0 0 0 0 3 1 -2 0 -1 0 -2 3 -1 2 0 2 0 0 0 0 2 0 1 0 0 3 0 0 -2 0",
"output": "75"
},
{
"input": "2\n-510468670 0",
"output": "2"
},
{
"input": "150\n0 -2 1 -2 0 0 0 0 -2 0 -2 -1 0 0 2 0 1 -2 1 -1 0 0 0 2 -2 2 -1 0 0 0 -2 0 2 0 1 0 -2 0 -2 -1 -1 -2 -2 2 0 0 1 -2 -2 -1 -2 0 2 1 1 -1 1 0 -2 2 0 0 0 1 -1 0 -2 -1 0 -2 2 1 1 0 0 2 0 0 2 -1 0 0 2 0 2 0 -2 -1 1 -2 1 0 0 -2 -1 -1 0 0 2 -1 -1 -1 -1 -2 0 0 2 -1 -1 1 0 0 1 -1 0 0 -1 2 2 0 0 0 -1 -2 0 1 0 -1 0 -1 -1 0 2 0 1 2 0 0 2 0 0 1 2 0 2 -2 2 0 2 2",
"output": "196"
}
] | 1,629,192,836 | 2,147,483,647 | Python 3 | OK | TESTS | 50 | 248 | 15,667,200 | n=int(input())
l=list(map(int,input().split()))
ans=n
s=1
flag=0
for i in range(n-1):
if l[i+1]!=l[i] and s!=1:
ans+=s*(s-1)//2
flag=0
s=1
elif l[i+1]==l[i]:
s+=1
flag=1
if flag==1:
ans+=s*(s-1)//2
print(ans) | Title: Magical Array
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Valery is very interested in magic. Magic attracts him so much that he sees it everywhere. He explains any strange and weird phenomenon through intervention of supernatural forces. But who would have thought that even in a regular array of numbers Valera manages to see something beautiful and magical.
Valera absolutely accidentally got a piece of ancient parchment on which an array of numbers was written. He immediately thought that the numbers in this array were not random. As a result of extensive research Valera worked out a wonderful property that a magical array should have: an array is defined as magic if its minimum and maximum coincide.
He decided to share this outstanding discovery with you, but he asks you for help in return. Despite the tremendous intelligence and wit, Valera counts very badly and so you will have to complete his work. All you have to do is count the number of magical subarrays of the original array of numbers, written on the parchment. Subarray is defined as non-empty sequence of consecutive elements.
Input Specification:
The first line of the input data contains an integer *n* (1<=≤<=*n*<=≤<=105). The second line contains an array of original integers *a*1,<=*a*2,<=...,<=*a**n* (<=-<=109<=≤<=*a**i*<=≤<=109).
Output Specification:
Print on the single line the answer to the problem: the amount of subarrays, which are magical.
Please do not use the %lld specificator to read or write 64-bit numbers in C++. It is recommended to use cin, cout streams (you can also use the %I64d specificator).
Demo Input:
['4\n2 1 1 4\n', '5\n-2 -2 -2 0 1\n']
Demo Output:
['5\n', '8\n']
Note:
Notes to sample tests:
Magical subarrays are shown with pairs of indices [a;b] of the beginning and the end.
In the first sample: [1;1], [2;2], [3;3], [4;4], [2;3].
In the second sample: [1;1], [2;2], [3;3], [4;4], [5;5], [1;2], [2;3], [1;3]. | ```python
n=int(input())
l=list(map(int,input().split()))
ans=n
s=1
flag=0
for i in range(n-1):
if l[i+1]!=l[i] and s!=1:
ans+=s*(s-1)//2
flag=0
s=1
elif l[i+1]==l[i]:
s+=1
flag=1
if flag==1:
ans+=s*(s-1)//2
print(ans)
``` | 3.908818 |
960 | C | Subsequence Counting | PROGRAMMING | 1,700 | [
"bitmasks",
"constructive algorithms",
"greedy",
"implementation"
] | null | null | Pikachu had an array with him. He wrote down all the non-empty subsequences of the array on paper. Note that an array of size *n* has 2*n*<=-<=1 non-empty subsequences in it.
Pikachu being mischievous as he always is, removed all the subsequences in which Maximum_element_of_the_subsequence <=-<= Minimum_element_of_subsequence <=≥<=*d*
Pikachu was finally left with *X* subsequences.
However, he lost the initial array he had, and now is in serious trouble. He still remembers the numbers *X* and *d*. He now wants you to construct any such array which will satisfy the above conditions. All the numbers in the final array should be positive integers less than 1018.
Note the number of elements in the output array should not be more than 104. If no answer is possible, print <=-<=1. | The only line of input consists of two space separated integers *X* and *d* (1<=≤<=*X*,<=*d*<=≤<=109). | Output should consist of two lines.
First line should contain a single integer *n* (1<=≤<=*n*<=≤<=10<=000)— the number of integers in the final array.
Second line should consist of *n* space separated integers — *a*1,<=*a*2,<=... ,<=*a**n* (1<=≤<=*a**i*<=<<=1018).
If there is no answer, print a single integer -1. If there are multiple answers, print any of them. | [
"10 5\n",
"4 2\n"
] | [
"6\n5 50 7 15 6 100",
"4\n10 100 1000 10000"
] | In the output of the first example case, the remaining subsequences after removing those with Maximum_element_of_the_subsequence - Minimum_element_of_subsequence ≥ 5 are [5], [5, 7], [5, 6], [5, 7, 6], [50], [7], [7, 6], [15], [6], [100]. There are 10 of them. Hence, the array [5, 50, 7, 15, 6, 100] is valid.
Similarly, in the output of the second example case, the remaining sub-sequences after removing those with Maximum_element_of_the_subsequence - Minimum_element_of_subsequence ≥ 2 are [10], [100], [1000], [10000]. There are 4 of them. Hence, the array [10, 100, 1000, 10000] is valid. | 1,500 | [
{
"input": "10 5",
"output": "6\n1 1 1 7 13 19 "
},
{
"input": "4 2",
"output": "3\n1 1 4 "
},
{
"input": "4 1",
"output": "3\n1 1 3 "
},
{
"input": "1 1",
"output": "1\n1 "
},
{
"input": "63 1",
"output": "21\n1 1 1 1 1 3 3 3 3 5 5 5 7 7 9 11 13 15 17 19 21 "
},
{
"input": "98 88",
"output": "15\n1 1 1 1 1 1 90 90 90 90 90 179 268 357 446 "
},
{
"input": "746 173",
"output": "37\n1 1 1 1 1 1 1 1 1 175 175 175 175 175 175 175 349 349 349 349 349 349 523 523 523 523 523 697 697 697 871 1045 1219 1393 1567 1741 1915 "
},
{
"input": "890 553",
"output": "43\n1 1 1 1 1 1 1 1 1 555 555 555 555 555 555 555 555 1109 1109 1109 1109 1109 1109 1663 1663 1663 1663 1663 2217 2217 2217 2217 2771 2771 2771 3325 3879 4433 4987 5541 6095 6649 7203 "
},
{
"input": "883 1000",
"output": "40\n1 1 1 1 1 1 1 1 1 1002 1002 1002 1002 1002 1002 1002 1002 2003 2003 2003 2003 2003 2003 3004 3004 3004 3004 3004 4005 4005 4005 4005 5006 6007 7008 8009 9010 10011 11012 12013 "
},
{
"input": "1 1000",
"output": "1\n1 "
},
{
"input": "695 188",
"output": "35\n1 1 1 1 1 1 1 1 1 190 190 190 190 190 190 190 379 379 379 379 379 568 568 568 568 757 757 946 1135 1324 1513 1702 1891 2080 2269 "
},
{
"input": "2060 697",
"output": "19\n1 1 1 1 1 1 1 1 1 1 1 699 699 699 1397 1397 2095 2793 3491 "
},
{
"input": "70 3321",
"output": "12\n1 1 1 1 1 1 3323 3323 6645 9967 13289 16611 "
},
{
"input": "6358 1646",
"output": "50\n1 1 1 1 1 1 1 1 1 1 1 1 1648 1648 1648 1648 1648 1648 1648 1648 1648 1648 1648 3295 3295 3295 3295 3295 3295 3295 4942 4942 4942 4942 4942 4942 6589 6589 6589 6589 8236 8236 9883 11530 13177 14824 16471 18118 19765 21412 "
},
{
"input": "167959139 481199252",
"output": "154\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 481199254 481199254 481199254 481199254 481199254 481199254 481199254 481199254 481199254 481199254 481199254 481199254 481199254 481199254 481199254 481199254 481199254 481199254 481199254 481199254 481199254 481199254 481199254 481199254 481199254 962398507 962398507 962398507 962398507 962398507 962398507 962398507 962398507 962398507 962398507 962398507 962398507 962398507 962398507 962398507 962398507 962398507 1443597760 1443597760 1443597760..."
},
{
"input": "641009859 54748096",
"output": "192\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 54748098 54748098 54748098 54748098 54748098 54748098 54748098 54748098 54748098 54748098 54748098 54748098 54748098 54748098 54748098 54748098 54748098 54748098 54748098 54748098 54748098 54748098 54748098 54748098 54748098 54748098 109496195 109496195 109496195 109496195 109496195 109496195 109496195 109496195 109496195 109496195 109496195 109496195 109496195 109496195 109496195 109496195 109496195 109496195 109496195 109496195 109496195 1094..."
},
{
"input": "524125987 923264237",
"output": "289\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 923264239 923264239 923264239 923264239 923264239 923264239 923264239 923264239 923264239 923264239 923264239 923264239 923264239 923264239 923264239 923264239 923264239 923264239 923264239 923264239 923264239 923264239 923264239 923264239 923264239 923264239 923264239 1846528477 1846528477 1846528477 1846528477 1846528477 1846528477 1846528477 1846528477 1846528477 1846528477 1846528477 1846528477 1846528477 1846528477 1846528477 1846528477 1846..."
},
{
"input": "702209411 496813081",
"output": "276\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 496813083 496813083 496813083 496813083 496813083 496813083 496813083 496813083 496813083 496813083 496813083 496813083 496813083 496813083 496813083 496813083 496813083 496813083 496813083 496813083 496813083 496813083 496813083 496813083 496813083 496813083 496813083 993626165 993626165 993626165 993626165 993626165 993626165 993626165 993626165 993626165 993626165 993626165 993626165 993626165 993626165 993626165 993626165 993626165 99362616..."
},
{
"input": "585325539 365329221",
"output": "243\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 365329223 365329223 365329223 365329223 365329223 365329223 365329223 365329223 365329223 365329223 365329223 365329223 365329223 365329223 365329223 365329223 365329223 365329223 365329223 365329223 365329223 365329223 365329223 365329223 365329223 730658445 730658445 730658445 730658445 730658445 730658445 730658445 730658445 730658445 730658445 730658445 730658445 730658445 730658445 730658445 730658445 730658445 730658445 730658445 73065844..."
},
{
"input": "58376259 643910770",
"output": "196\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 643910772 643910772 643910772 643910772 643910772 643910772 643910772 643910772 643910772 643910772 643910772 643910772 643910772 643910772 643910772 643910772 643910772 643910772 643910772 643910772 643910772 643910772 643910772 643910772 1287821543 1287821543 1287821543 1287821543 1287821543 1287821543 1287821543 1287821543 1287821543 1287821543 1287821543 1287821543 1287821543 1287821543 1287821543 1287821543 1287821543 1287821543 1287821543 1287821..."
},
{
"input": "941492387 72235422",
"output": "194\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 72235424 72235424 72235424 72235424 72235424 72235424 72235424 72235424 72235424 72235424 72235424 72235424 72235424 72235424 72235424 72235424 72235424 72235424 72235424 72235424 72235424 72235424 72235424 72235424 72235424 72235424 72235424 72235424 144470847 144470847 144470847 144470847 144470847 144470847 144470847 144470847 144470847 144470847 144470847 144470847 144470847 144470847 144470847 144470847 144470847 144470847 144470847 144470..."
},
{
"input": "824608515 940751563",
"output": "192\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 940751565 940751565 940751565 940751565 940751565 940751565 940751565 940751565 940751565 940751565 940751565 940751565 940751565 940751565 940751565 940751565 940751565 940751565 940751565 940751565 940751565 940751565 940751565 940751565 940751565 940751565 940751565 940751565 1881503129 1881503129 1881503129 1881503129 1881503129 1881503129 1881503129 1881503129 1881503129 1881503129 1881503129 1881503129 1881503129 1881503129 1881503129 188..."
},
{
"input": "2691939 514300407",
"output": "107\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 514300409 514300409 514300409 514300409 514300409 514300409 514300409 514300409 514300409 514300409 514300409 514300409 514300409 514300409 514300409 514300409 514300409 514300409 514300409 1028600817 1028600817 1028600817 1028600817 1028600817 1028600817 1028600817 1028600817 1028600817 1028600817 1028600817 1028600817 1028600817 1028600817 1028600817 1028600817 1542901225 1542901225 1542901225 1542901225 1542901225 1542901225 1542901225 1542901225 1542901225..."
},
{
"input": "802030518 598196518",
"output": "283\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 598196520 598196520 598196520 598196520 598196520 598196520 598196520 598196520 598196520 598196520 598196520 598196520 598196520 598196520 598196520 598196520 598196520 598196520 598196520 598196520 598196520 598196520 598196520 598196520 598196520 598196520 598196520 1196393039 1196393039 1196393039 1196393039 1196393039 1196393039 1196393039 1196393039 1196393039 1196393039 1196393039 1196393039 1196393039 1196393039 1196393039 1196393039 11..."
},
{
"input": "685146646 26521171",
"output": "199\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 26521173 26521173 26521173 26521173 26521173 26521173 26521173 26521173 26521173 26521173 26521173 26521173 26521173 26521173 26521173 26521173 26521173 26521173 26521173 26521173 26521173 26521173 26521173 26521173 26521173 26521173 26521173 53042345 53042345 53042345 53042345 53042345 53042345 53042345 53042345 53042345 53042345 53042345 53042345 53042345 53042345 53042345 53042345 53042345 53042345 53042345 53042345 53042345 53042345 5304234..."
},
{
"input": "863230070 895037311",
"output": "290\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 895037313 895037313 895037313 895037313 895037313 895037313 895037313 895037313 895037313 895037313 895037313 895037313 895037313 895037313 895037313 895037313 895037313 895037313 895037313 895037313 895037313 895037313 895037313 895037313 895037313 895037313 895037313 895037313 1790074625 1790074625 1790074625 1790074625 1790074625 1790074625 1790074625 1790074625 1790074625 1790074625 1790074625 1790074625 1790074625 1790074625 1790074625 179..."
},
{
"input": "41313494 468586155",
"output": "194\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 468586157 468586157 468586157 468586157 468586157 468586157 468586157 468586157 468586157 468586157 468586157 468586157 468586157 468586157 468586157 468586157 468586157 468586157 468586157 468586157 468586157 468586157 937172313 937172313 937172313 937172313 937172313 937172313 937172313 937172313 937172313 937172313 937172313 937172313 937172313 937172313 937172313 937172313 937172313 937172313 937172313 937172313 937172313 1405758469 1405758469 1405..."
},
{
"input": "219396918 747167704",
"output": "226\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 747167706 747167706 747167706 747167706 747167706 747167706 747167706 747167706 747167706 747167706 747167706 747167706 747167706 747167706 747167706 747167706 747167706 747167706 747167706 747167706 747167706 747167706 747167706 747167706 747167706 747167706 1494335411 1494335411 1494335411 1494335411 1494335411 1494335411 1494335411 1494335411 1494335411 1494335411 1494335411 1494335411 1494335411 1494335411 1494335411 1494335411 1494335411 14943..."
},
{
"input": "102513046 615683844",
"output": "179\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 615683846 615683846 615683846 615683846 615683846 615683846 615683846 615683846 615683846 615683846 615683846 615683846 615683846 615683846 615683846 615683846 615683846 615683846 615683846 615683846 615683846 615683846 615683846 615683846 615683846 1231367691 1231367691 1231367691 1231367691 1231367691 1231367691 1231367691 1231367691 1231367691 1231367691 1231367691 1231367691 1231367691 1231367691 1231367691 1231367691 1231367691 1231367691 123136..."
},
{
"input": "985629174 189232688",
"output": "310\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 189232690 189232690 189232690 189232690 189232690 189232690 189232690 189232690 189232690 189232690 189232690 189232690 189232690 189232690 189232690 189232690 189232690 189232690 189232690 189232690 189232690 189232690 189232690 189232690 189232690 189232690 189232690 189232690 378465379 378465379 378465379 378465379 378465379 378465379 378465379 378465379 378465379 378465379 378465379 378465379 378465379 378465379 378465379 378465379 37846537..."
},
{
"input": "458679894 912524637",
"output": "272\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 912524639 912524639 912524639 912524639 912524639 912524639 912524639 912524639 912524639 912524639 912524639 912524639 912524639 912524639 912524639 912524639 912524639 912524639 912524639 912524639 912524639 912524639 912524639 912524639 912524639 912524639 912524639 1825049277 1825049277 1825049277 1825049277 1825049277 1825049277 1825049277 1825049277 1825049277 1825049277 1825049277 1825049277 1825049277 1825049277 1825049277 1825049277 1825..."
},
{
"input": "341796022 486073481",
"output": "238\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 486073483 486073483 486073483 486073483 486073483 486073483 486073483 486073483 486073483 486073483 486073483 486073483 486073483 486073483 486073483 486073483 486073483 486073483 486073483 486073483 486073483 486073483 486073483 486073483 486073483 486073483 972146965 972146965 972146965 972146965 972146965 972146965 972146965 972146965 972146965 972146965 972146965 972146965 972146965 972146965 972146965 972146965 972146965 972146965 972146965 ..."
},
{
"input": "519879446 764655030",
"output": "323\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 764655032 764655032 764655032 764655032 764655032 764655032 764655032 764655032 764655032 764655032 764655032 764655032 764655032 764655032 764655032 764655032 764655032 764655032 764655032 764655032 764655032 764655032 764655032 764655032 764655032 764655032 764655032 1529310063 1529310063 1529310063 1529310063 1529310063 1529310063 1529310063 1529310063 1529310063 1529310063 1529310063 1529310063 1529310063 1529310063 1529310063 1529310063 1529..."
},
{
"input": "452405440 586588704",
"output": "268\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 586588706 586588706 586588706 586588706 586588706 586588706 586588706 586588706 586588706 586588706 586588706 586588706 586588706 586588706 586588706 586588706 586588706 586588706 586588706 586588706 586588706 586588706 586588706 586588706 586588706 586588706 586588706 1173177411 1173177411 1173177411 1173177411 1173177411 1173177411 1173177411 1173177411 1173177411 1173177411 1173177411 1173177411 1173177411 1173177411 1173177411 1173177411 1173..."
},
{
"input": "335521569 160137548",
"output": "311\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 160137550 160137550 160137550 160137550 160137550 160137550 160137550 160137550 160137550 160137550 160137550 160137550 160137550 160137550 160137550 160137550 160137550 160137550 160137550 160137550 160137550 160137550 160137550 160137550 160137550 320275099 320275099 320275099 320275099 320275099 320275099 320275099 320275099 320275099 320275099 320275099 320275099 320275099 320275099 320275099 320275099 320275099 320275099 320275099 320275099 ..."
},
{
"input": "808572289 733686393",
"output": "192\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 733686395 733686395 733686395 733686395 733686395 733686395 733686395 733686395 733686395 733686395 733686395 733686395 733686395 733686395 733686395 733686395 733686395 733686395 733686395 733686395 733686395 733686395 733686395 733686395 733686395 733686395 733686395 733686395 1467372789 1467372789 1467372789 1467372789 1467372789 1467372789 1467372789 1467372789 1467372789 1467372789 1467372789 1467372789 1467372789 1467372789 1467372789 146..."
},
{
"input": "691688417 162011045",
"output": "233\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 162011047 162011047 162011047 162011047 162011047 162011047 162011047 162011047 162011047 162011047 162011047 162011047 162011047 162011047 162011047 162011047 162011047 162011047 162011047 162011047 162011047 162011047 162011047 162011047 162011047 162011047 162011047 324022093 324022093 324022093 324022093 324022093 324022093 324022093 324022093 324022093 324022093 324022093 324022093 324022093 324022093 324022093 324022093 324022093 32402209..."
},
{
"input": "869771841 30527185",
"output": "292\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 30527187 30527187 30527187 30527187 30527187 30527187 30527187 30527187 30527187 30527187 30527187 30527187 30527187 30527187 30527187 30527187 30527187 30527187 30527187 30527187 30527187 30527187 30527187 30527187 30527187 30527187 30527187 30527187 61054373 61054373 61054373 61054373 61054373 61054373 61054373 61054373 61054373 61054373 61054373 61054373 61054373 61054373 61054373 61054373 61054373 61054373 61054373 61054373 61054373 6105437..."
},
{
"input": "752887969 604076030",
"output": "195\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 604076032 604076032 604076032 604076032 604076032 604076032 604076032 604076032 604076032 604076032 604076032 604076032 604076032 604076032 604076032 604076032 604076032 604076032 604076032 604076032 604076032 604076032 604076032 604076032 604076032 604076032 604076032 1208152063 1208152063 1208152063 1208152063 1208152063 1208152063 1208152063 1208152063 1208152063 1208152063 1208152063 1208152063 1208152063 1208152063 1208152063 1208152063 12..."
},
{
"input": "930971393 177624874",
"output": "344\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 177624876 177624876 177624876 177624876 177624876 177624876 177624876 177624876 177624876 177624876 177624876 177624876 177624876 177624876 177624876 177624876 177624876 177624876 177624876 177624876 177624876 177624876 177624876 177624876 177624876 177624876 177624876 177624876 355249751 355249751 355249751 355249751 355249751 355249751 355249751 355249751 355249751 355249751 355249751 355249751 355249751 355249751 355249751 355249751 35524975..."
},
{
"input": "109054817 751173719",
"output": "122\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 751173721 751173721 751173721 751173721 751173721 751173721 751173721 751173721 751173721 751173721 751173721 751173721 751173721 751173721 751173721 751173721 751173721 751173721 751173721 751173721 751173721 751173721 751173721 751173721 751173721 1502347441 1502347441 1502347441 1502347441 1502347441 1502347441 1502347441 1502347441 1502347441 1502347441 1502347441 1502347441 1502347441 1502347441 1502347441 1502347441 1502347441 1502347441 150234..."
},
{
"input": "992170945 324722563",
"output": "258\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 324722565 324722565 324722565 324722565 324722565 324722565 324722565 324722565 324722565 324722565 324722565 324722565 324722565 324722565 324722565 324722565 324722565 324722565 324722565 324722565 324722565 324722565 324722565 324722565 324722565 324722565 324722565 324722565 649445129 649445129 649445129 649445129 649445129 649445129 649445129 649445129 649445129 649445129 649445129 649445129 649445129 649445129 649445129 649445129 64944512..."
},
{
"input": "170254369 48014511",
"output": "164\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 48014513 48014513 48014513 48014513 48014513 48014513 48014513 48014513 48014513 48014513 48014513 48014513 48014513 48014513 48014513 48014513 48014513 48014513 48014513 48014513 48014513 48014513 48014513 48014513 48014513 96029025 96029025 96029025 96029025 96029025 96029025 96029025 96029025 96029025 96029025 96029025 96029025 96029025 96029025 96029025 96029025 96029025 96029025 96029025 96029025 96029025 144043537 144043537 144043537 14404353..."
},
{
"input": "248004555 280013594",
"output": "239\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 280013596 280013596 280013596 280013596 280013596 280013596 280013596 280013596 280013596 280013596 280013596 280013596 280013596 280013596 280013596 280013596 280013596 280013596 280013596 280013596 280013596 280013596 280013596 280013596 280013596 280013596 560027191 560027191 560027191 560027191 560027191 560027191 560027191 560027191 560027191 560027191 560027191 560027191 560027191 560027191 560027191 560027191 560027191 560027191 560027191 56..."
},
{
"input": "131120683 148529734",
"output": "235\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 148529736 148529736 148529736 148529736 148529736 148529736 148529736 148529736 148529736 148529736 148529736 148529736 148529736 148529736 148529736 148529736 148529736 148529736 148529736 148529736 148529736 148529736 148529736 148529736 148529736 297059471 297059471 297059471 297059471 297059471 297059471 297059471 297059471 297059471 297059471 297059471 297059471 297059471 297059471 297059471 297059471 297059471 297059471 297059471 297059471 2970..."
},
{
"input": "604171403 722078578",
"output": "158\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 722078580 722078580 722078580 722078580 722078580 722078580 722078580 722078580 722078580 722078580 722078580 722078580 722078580 722078580 722078580 722078580 722078580 722078580 722078580 722078580 722078580 722078580 722078580 722078580 722078580 722078580 1444157159 1444157159 1444157159 1444157159 1444157159 1444157159 1444157159 1444157159 1444157159 1444157159 1444157159 1444157159 1444157159 1444157159 1444157159 1444157159 1444157159 2..."
},
{
"input": "487287531 295627423",
"output": "243\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 295627425 295627425 295627425 295627425 295627425 295627425 295627425 295627425 295627425 295627425 295627425 295627425 295627425 295627425 295627425 295627425 295627425 295627425 295627425 295627425 295627425 295627425 295627425 295627425 295627425 295627425 295627425 591254849 591254849 591254849 591254849 591254849 591254849 591254849 591254849 591254849 591254849 591254849 591254849 591254849 591254849 591254849 591254849 591254849 591254849 ..."
},
{
"input": "665370955 18919371",
"output": "228\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 18919373 18919373 18919373 18919373 18919373 18919373 18919373 18919373 18919373 18919373 18919373 18919373 18919373 18919373 18919373 18919373 18919373 18919373 18919373 18919373 18919373 18919373 18919373 18919373 18919373 18919373 37838745 37838745 37838745 37838745 37838745 37838745 37838745 37838745 37838745 37838745 37838745 37838745 37838745 37838745 37838745 37838745 37838745 37838745 37838745 37838745 37838745 37838745 37838745 3783874..."
},
{
"input": "843454379 297500920",
"output": "209\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 297500922 297500922 297500922 297500922 297500922 297500922 297500922 297500922 297500922 297500922 297500922 297500922 297500922 297500922 297500922 297500922 297500922 297500922 297500922 297500922 297500922 297500922 297500922 297500922 297500922 297500922 297500922 297500922 595001843 595001843 595001843 595001843 595001843 595001843 595001843 595001843 595001843 595001843 595001843 595001843 595001843 595001843 595001843 595001843 59500184..."
},
{
"input": "21537803 166017060",
"output": "116\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 166017062 166017062 166017062 166017062 166017062 166017062 166017062 166017062 166017062 166017062 166017062 166017062 166017062 166017062 166017062 166017062 166017062 166017062 166017062 166017062 166017062 166017062 332034123 332034123 332034123 332034123 332034123 332034123 332034123 332034123 332034123 332034123 332034123 332034123 332034123 332034123 332034123 332034123 332034123 332034123 332034123 498051184 498051184 498051184 498051184 49805118..."
},
{
"input": "904653932 739565904",
"output": "323\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 739565906 739565906 739565906 739565906 739565906 739565906 739565906 739565906 739565906 739565906 739565906 739565906 739565906 739565906 739565906 739565906 739565906 739565906 739565906 739565906 739565906 739565906 739565906 739565906 739565906 739565906 739565906 739565906 1479131811 1479131811 1479131811 1479131811 1479131811 1479131811 1479131811 1479131811 1479131811 1479131811 1479131811 1479131811 1479131811 1479131811 1479131811 147..."
},
{
"input": "787770060 313114749",
"output": "293\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 313114751 313114751 313114751 313114751 313114751 313114751 313114751 313114751 313114751 313114751 313114751 313114751 313114751 313114751 313114751 313114751 313114751 313114751 313114751 313114751 313114751 313114751 313114751 313114751 313114751 313114751 313114751 626229501 626229501 626229501 626229501 626229501 626229501 626229501 626229501 626229501 626229501 626229501 626229501 626229501 626229501 626229501 626229501 626229501 62622950..."
},
{
"input": "260820780 181630889",
"output": "271\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 181630891 181630891 181630891 181630891 181630891 181630891 181630891 181630891 181630891 181630891 181630891 181630891 181630891 181630891 181630891 181630891 181630891 181630891 181630891 181630891 181630891 181630891 181630891 181630891 181630891 181630891 363261781 363261781 363261781 363261781 363261781 363261781 363261781 363261781 363261781 363261781 363261781 363261781 363261781 363261781 363261781 363261781 363261781 363261781 363261781 36..."
},
{
"input": "43603670 268405779",
"output": "182\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 268405781 268405781 268405781 268405781 268405781 268405781 268405781 268405781 268405781 268405781 268405781 268405781 268405781 268405781 268405781 268405781 268405781 268405781 268405781 268405781 268405781 268405781 268405781 536811561 536811561 536811561 536811561 536811561 536811561 536811561 536811561 536811561 536811561 536811561 536811561 536811561 536811561 536811561 536811561 536811561 536811561 536811561 536811561 805217341 805217341 805217..."
},
{
"input": "1000000000 1000000000",
"output": "274\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 1000000002 1000000002 1000000002 1000000002 1000000002 1000000002 1000000002 1000000002 1000000002 1000000002 1000000002 1000000002 1000000002 1000000002 1000000002 1000000002 1000000002 1000000002 1000000002 1000000002 1000000002 1000000002 1000000002 1000000002 1000000002 1000000002 1000000002 1000000002 2000000003 2000000003 2000000003 2000000003 2000000003 2000000003 2000000003 2000000003 2000000003 2000000003 2000000003 2000000003 20000000..."
},
{
"input": "15000 1",
"output": "66\n1 1 1 1 1 1 1 1 1 1 1 1 1 3 3 3 3 3 3 3 3 3 3 3 3 5 5 5 5 5 5 5 5 5 5 5 7 7 7 7 7 7 7 7 7 9 9 9 9 9 9 9 11 11 11 11 13 13 13 15 17 19 21 23 25 27 "
},
{
"input": "1048576 1",
"output": "21\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 "
},
{
"input": "1000000000 1",
"output": "274\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 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 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 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 19 ..."
},
{
"input": "100000000 1",
"output": "232\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 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 19 19 19 19 19 19 19 19 19 19 19 19 19 19 21 21 21 21 21 21 21 21 2..."
},
{
"input": "1000000 1",
"output": "106\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 9 9 9 9 9 9 9 9 9 9 9 9 9 9 11 11 11 11 11 11 11 11 11 13 13 13 13 13 13 15 17 19 21 23 25 27 "
},
{
"input": "536870911 1",
"output": "435\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 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 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 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 ..."
},
{
"input": "10009 1",
"output": "54\n1 1 1 1 1 1 1 1 1 1 1 1 1 3 3 3 3 3 3 3 3 3 3 5 5 5 5 5 5 5 5 5 7 7 7 7 7 7 7 7 9 9 9 9 11 11 11 13 15 17 19 21 23 25 "
},
{
"input": "10001 1",
"output": "50\n1 1 1 1 1 1 1 1 1 1 1 1 1 3 3 3 3 3 3 3 3 3 3 5 5 5 5 5 5 5 5 5 7 7 7 7 7 7 7 7 9 9 9 9 11 13 15 17 19 21 "
}
] | 1,523,120,474 | 3,374 | Python 3 | OK | TESTS | 63 | 93 | 7,065,600 | # -*- coding: UTF-8 -*-
s = [2 ** i - 1 for i in range(31, 0, -1)]
z = [i for i in range(31, 0, -1)]
x, d = map(int, input().split())
st = 1
p = 0
ret = []
while x > 0:
while s[p] > x:
p += 1
for i in range(z[p]):
ret.append(st)
st += d
x -= s[p]
if x != 0:
print('-1')
else:
print(len(ret))
print(' '.join(str(i) for i in ret))
| Title: Subsequence Counting
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Pikachu had an array with him. He wrote down all the non-empty subsequences of the array on paper. Note that an array of size *n* has 2*n*<=-<=1 non-empty subsequences in it.
Pikachu being mischievous as he always is, removed all the subsequences in which Maximum_element_of_the_subsequence <=-<= Minimum_element_of_subsequence <=≥<=*d*
Pikachu was finally left with *X* subsequences.
However, he lost the initial array he had, and now is in serious trouble. He still remembers the numbers *X* and *d*. He now wants you to construct any such array which will satisfy the above conditions. All the numbers in the final array should be positive integers less than 1018.
Note the number of elements in the output array should not be more than 104. If no answer is possible, print <=-<=1.
Input Specification:
The only line of input consists of two space separated integers *X* and *d* (1<=≤<=*X*,<=*d*<=≤<=109).
Output Specification:
Output should consist of two lines.
First line should contain a single integer *n* (1<=≤<=*n*<=≤<=10<=000)— the number of integers in the final array.
Second line should consist of *n* space separated integers — *a*1,<=*a*2,<=... ,<=*a**n* (1<=≤<=*a**i*<=<<=1018).
If there is no answer, print a single integer -1. If there are multiple answers, print any of them.
Demo Input:
['10 5\n', '4 2\n']
Demo Output:
['6\n5 50 7 15 6 100', '4\n10 100 1000 10000']
Note:
In the output of the first example case, the remaining subsequences after removing those with Maximum_element_of_the_subsequence - Minimum_element_of_subsequence ≥ 5 are [5], [5, 7], [5, 6], [5, 7, 6], [50], [7], [7, 6], [15], [6], [100]. There are 10 of them. Hence, the array [5, 50, 7, 15, 6, 100] is valid.
Similarly, in the output of the second example case, the remaining sub-sequences after removing those with Maximum_element_of_the_subsequence - Minimum_element_of_subsequence ≥ 2 are [10], [100], [1000], [10000]. There are 4 of them. Hence, the array [10, 100, 1000, 10000] is valid. | ```python
# -*- coding: UTF-8 -*-
s = [2 ** i - 1 for i in range(31, 0, -1)]
z = [i for i in range(31, 0, -1)]
x, d = map(int, input().split())
st = 1
p = 0
ret = []
while x > 0:
while s[p] > x:
p += 1
for i in range(z[p]):
ret.append(st)
st += d
x -= s[p]
if x != 0:
print('-1')
else:
print(len(ret))
print(' '.join(str(i) for i in ret))
``` | 3 |
|
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,659,466,038 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 3 | 92 | 0 | import sys
def get_ints(): return map(int, sys.stdin.readline().strip().split())
def main():
n, a, b = get_ints()
arr = [*range(n,0,-1)]
arr2 = [*range(n,0,-1)]
num = len(set(arr[:-a])&set(arr2[:-(n-(b+1))]))
if num != 0:
print(num)
else:
print(0)
if __name__ =="__main__":
main()
3 | 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
def get_ints(): return map(int, sys.stdin.readline().strip().split())
def main():
n, a, b = get_ints()
arr = [*range(n,0,-1)]
arr2 = [*range(n,0,-1)]
num = len(set(arr[:-a])&set(arr2[:-(n-(b+1))]))
if num != 0:
print(num)
else:
print(0)
if __name__ =="__main__":
main()
3
``` | 0 |
|
441 | B | Valera and Fruits | PROGRAMMING | 1,400 | [
"greedy",
"implementation"
] | null | null | Valera loves his garden, where *n* fruit trees grow.
This year he will enjoy a great harvest! On the *i*-th tree *b**i* fruit grow, they will ripen on a day number *a**i*. Unfortunately, the fruit on the tree get withered, so they can only be collected on day *a**i* and day *a**i*<=+<=1 (all fruits that are not collected in these two days, become unfit to eat).
Valera is not very fast, but there are some positive points. Valera is ready to work every day. In one day, Valera can collect no more than *v* fruits. The fruits may be either from the same tree, or from different ones. What is the maximum amount of fruit Valera can collect for all time, if he operates optimally well? | The first line contains two space-separated integers *n* and *v* (1<=≤<=*n*,<=*v*<=≤<=3000) — the number of fruit trees in the garden and the number of fruits that Valera can collect in a day.
Next *n* lines contain the description of trees in the garden. The *i*-th line contains two space-separated integers *a**i* and *b**i* (1<=≤<=*a**i*,<=*b**i*<=≤<=3000) — the day the fruits ripen on the *i*-th tree and the number of fruits on the *i*-th tree. | Print a single integer — the maximum number of fruit that Valera can collect. | [
"2 3\n1 5\n2 3\n",
"5 10\n3 20\n2 20\n1 20\n4 20\n5 20\n"
] | [
"8\n",
"60\n"
] | In the first sample, in order to obtain the optimal answer, you should act as follows.
- On the first day collect 3 fruits from the 1-st tree. - On the second day collect 1 fruit from the 2-nd tree and 2 fruits from the 1-st tree. - On the third day collect the remaining fruits from the 2-nd tree.
In the second sample, you can only collect 60 fruits, the remaining fruit will simply wither. | 1,000 | [
{
"input": "2 3\n1 5\n2 3",
"output": "8"
},
{
"input": "5 10\n3 20\n2 20\n1 20\n4 20\n5 20",
"output": "60"
},
{
"input": "10 3000\n1 2522\n4 445\n8 1629\n5 772\n9 2497\n6 81\n3 426\n7 1447\n2 575\n10 202",
"output": "10596"
},
{
"input": "5 3000\n5 772\n1 2522\n2 575\n4 445\n3 426",
"output": "4740"
},
{
"input": "2 1500\n2 575\n1 2522",
"output": "3097"
},
{
"input": "12 2856\n9 2728\n8 417\n3 1857\n10 1932\n1 775\n12 982\n9 1447\n1 426\n7 2918\n11 2522\n10 2497\n9 772",
"output": "18465"
},
{
"input": "24 1524\n16 934\n23 1940\n21 1447\n20 417\n24 1340\n22 1932\n13 775\n19 2918\n12 2355\n9 593\n11 2676\n3 1857\n16 868\n13 426\n18 1679\n22 991\n9 2728\n10 2497\n16 1221\n9 772\n23 2522\n24 982\n12 1431\n18 757",
"output": "25893"
},
{
"input": "1 10\n3000 30",
"output": "20"
},
{
"input": "2 1\n30 3\n31 2",
"output": "3"
},
{
"input": "4 2061\n1 426\n3 2522\n1 772\n1 1447",
"output": "5167"
},
{
"input": "2 1\n1 1\n1 1",
"output": "2"
},
{
"input": "1 10\n3000 20",
"output": "20"
},
{
"input": "1 1000\n3000 2000",
"output": "2000"
},
{
"input": "2 100\n3000 100\n3000 100",
"output": "200"
},
{
"input": "2 3\n1 6\n3 6",
"output": "12"
},
{
"input": "1 40\n3000 42",
"output": "42"
},
{
"input": "1 100\n3000 200",
"output": "200"
},
{
"input": "1 50\n3000 100",
"output": "100"
},
{
"input": "1 1\n3000 2",
"output": "2"
},
{
"input": "2 3000\n3000 3000\n3000 3000",
"output": "6000"
},
{
"input": "2 2\n2999 3\n3000 2",
"output": "5"
},
{
"input": "1 2\n3000 3",
"output": "3"
},
{
"input": "2 5\n2999 10\n3000 5",
"output": "15"
},
{
"input": "1 3\n5 3",
"output": "3"
},
{
"input": "2 1000\n2999 2000\n3000 1000",
"output": "3000"
},
{
"input": "1 5\n3000 10",
"output": "10"
},
{
"input": "1 10\n3000 15",
"output": "15"
},
{
"input": "5 1\n10 100\n2698 100\n200 100\n3000 100\n1500 100",
"output": "10"
},
{
"input": "1 1\n3000 3000",
"output": "2"
},
{
"input": "2 10\n2999 100\n3000 100",
"output": "30"
},
{
"input": "1 10\n3000 100",
"output": "20"
}
] | 1,637,604,920 | 2,147,483,647 | Python 3 | OK | TESTS | 51 | 62 | 0 | n,v=map(int,input().split())
arr=[0 for i in range(3003)]
for i in range(n):
x,a=map(int,input().split())
arr[x]+=a
ans=0
for i in range(1,3003):
left=v
ans+=min(v,arr[i-1])
left-=min(v,arr[i-1])
ans+=min(left,arr[i])
arr[i]-=min(left,arr[i])
print(ans) | Title: Valera and Fruits
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Valera loves his garden, where *n* fruit trees grow.
This year he will enjoy a great harvest! On the *i*-th tree *b**i* fruit grow, they will ripen on a day number *a**i*. Unfortunately, the fruit on the tree get withered, so they can only be collected on day *a**i* and day *a**i*<=+<=1 (all fruits that are not collected in these two days, become unfit to eat).
Valera is not very fast, but there are some positive points. Valera is ready to work every day. In one day, Valera can collect no more than *v* fruits. The fruits may be either from the same tree, or from different ones. What is the maximum amount of fruit Valera can collect for all time, if he operates optimally well?
Input Specification:
The first line contains two space-separated integers *n* and *v* (1<=≤<=*n*,<=*v*<=≤<=3000) — the number of fruit trees in the garden and the number of fruits that Valera can collect in a day.
Next *n* lines contain the description of trees in the garden. The *i*-th line contains two space-separated integers *a**i* and *b**i* (1<=≤<=*a**i*,<=*b**i*<=≤<=3000) — the day the fruits ripen on the *i*-th tree and the number of fruits on the *i*-th tree.
Output Specification:
Print a single integer — the maximum number of fruit that Valera can collect.
Demo Input:
['2 3\n1 5\n2 3\n', '5 10\n3 20\n2 20\n1 20\n4 20\n5 20\n']
Demo Output:
['8\n', '60\n']
Note:
In the first sample, in order to obtain the optimal answer, you should act as follows.
- On the first day collect 3 fruits from the 1-st tree. - On the second day collect 1 fruit from the 2-nd tree and 2 fruits from the 1-st tree. - On the third day collect the remaining fruits from the 2-nd tree.
In the second sample, you can only collect 60 fruits, the remaining fruit will simply wither. | ```python
n,v=map(int,input().split())
arr=[0 for i in range(3003)]
for i in range(n):
x,a=map(int,input().split())
arr[x]+=a
ans=0
for i in range(1,3003):
left=v
ans+=min(v,arr[i-1])
left-=min(v,arr[i-1])
ans+=min(left,arr[i])
arr[i]-=min(left,arr[i])
print(ans)
``` | 3 |
|
716 | A | Crazy Computer | PROGRAMMING | 800 | [
"implementation"
] | null | null | ZS the Coder is coding on a crazy computer. If you don't type in a word for a *c* consecutive seconds, everything you typed disappear!
More formally, if you typed a word at second *a* and then the next word at second *b*, then if *b*<=-<=*a*<=≤<=*c*, just the new word is appended to other words on the screen. If *b*<=-<=*a*<=><=*c*, then everything on the screen disappears and after that the word you have typed appears on the screen.
For example, if *c*<==<=5 and you typed words at seconds 1,<=3,<=8,<=14,<=19,<=20 then at the second 8 there will be 3 words on the screen. After that, everything disappears at the second 13 because nothing was typed. At the seconds 14 and 19 another two words are typed, and finally, at the second 20, one more word is typed, and a total of 3 words remain on the screen.
You're given the times when ZS the Coder typed the words. Determine how many words remain on the screen after he finished typing everything. | The first line contains two integers *n* and *c* (1<=≤<=*n*<=≤<=100<=000,<=1<=≤<=*c*<=≤<=109) — the number of words ZS the Coder typed and the crazy computer delay respectively.
The next line contains *n* integers *t*1,<=*t*2,<=...,<=*t**n* (1<=≤<=*t*1<=<<=*t*2<=<<=...<=<<=*t**n*<=≤<=109), where *t**i* denotes the second when ZS the Coder typed the *i*-th word. | Print a single positive integer, the number of words that remain on the screen after all *n* words was typed, in other words, at the second *t**n*. | [
"6 5\n1 3 8 14 19 20\n",
"6 1\n1 3 5 7 9 10\n"
] | [
"3",
"2"
] | The first sample is already explained in the problem statement.
For the second sample, after typing the first word at the second 1, it disappears because the next word is typed at the second 3 and 3 - 1 > 1. Similarly, only 1 word will remain at the second 9. Then, a word is typed at the second 10, so there will be two words on the screen, as the old word won't disappear because 10 - 9 ≤ 1. | 500 | [
{
"input": "6 5\n1 3 8 14 19 20",
"output": "3"
},
{
"input": "6 1\n1 3 5 7 9 10",
"output": "2"
},
{
"input": "1 1\n1000000000",
"output": "1"
},
{
"input": "5 5\n1 7 12 13 14",
"output": "4"
},
{
"input": "2 1000000000\n1 1000000000",
"output": "2"
},
{
"input": "3 5\n1 10 20",
"output": "1"
},
{
"input": "3 10\n1 2 3",
"output": "3"
},
{
"input": "2 1\n1 100",
"output": "1"
},
{
"input": "3 1\n1 2 10",
"output": "1"
},
{
"input": "2 1\n1 2",
"output": "2"
}
] | 1,617,378,404 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 30 | 0 | #%%716a Crazy computer
inp = lambda: [*map(int,input().split())]
n,c = input(); arr = inp()
word = 1
for prev,now in zip(arr[:-1],arr[1:]):
word = [word+1,word][now-prev<c]
print(word)
| Title: Crazy Computer
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
ZS the Coder is coding on a crazy computer. If you don't type in a word for a *c* consecutive seconds, everything you typed disappear!
More formally, if you typed a word at second *a* and then the next word at second *b*, then if *b*<=-<=*a*<=≤<=*c*, just the new word is appended to other words on the screen. If *b*<=-<=*a*<=><=*c*, then everything on the screen disappears and after that the word you have typed appears on the screen.
For example, if *c*<==<=5 and you typed words at seconds 1,<=3,<=8,<=14,<=19,<=20 then at the second 8 there will be 3 words on the screen. After that, everything disappears at the second 13 because nothing was typed. At the seconds 14 and 19 another two words are typed, and finally, at the second 20, one more word is typed, and a total of 3 words remain on the screen.
You're given the times when ZS the Coder typed the words. Determine how many words remain on the screen after he finished typing everything.
Input Specification:
The first line contains two integers *n* and *c* (1<=≤<=*n*<=≤<=100<=000,<=1<=≤<=*c*<=≤<=109) — the number of words ZS the Coder typed and the crazy computer delay respectively.
The next line contains *n* integers *t*1,<=*t*2,<=...,<=*t**n* (1<=≤<=*t*1<=<<=*t*2<=<<=...<=<<=*t**n*<=≤<=109), where *t**i* denotes the second when ZS the Coder typed the *i*-th word.
Output Specification:
Print a single positive integer, the number of words that remain on the screen after all *n* words was typed, in other words, at the second *t**n*.
Demo Input:
['6 5\n1 3 8 14 19 20\n', '6 1\n1 3 5 7 9 10\n']
Demo Output:
['3', '2']
Note:
The first sample is already explained in the problem statement.
For the second sample, after typing the first word at the second 1, it disappears because the next word is typed at the second 3 and 3 - 1 > 1. Similarly, only 1 word will remain at the second 9. Then, a word is typed at the second 10, so there will be two words on the screen, as the old word won't disappear because 10 - 9 ≤ 1. | ```python
#%%716a Crazy computer
inp = lambda: [*map(int,input().split())]
n,c = input(); arr = inp()
word = 1
for prev,now in zip(arr[:-1],arr[1:]):
word = [word+1,word][now-prev<c]
print(word)
``` | -1 |
|
959 | B | Mahmoud and Ehab and the message | PROGRAMMING | 1,200 | [
"dsu",
"greedy",
"implementation"
] | null | null | Mahmoud wants to send a message to his friend Ehab. Their language consists of *n* words numbered from 1 to *n*. Some words have the same meaning so there are *k* groups of words such that all the words in some group have the same meaning.
Mahmoud knows that the *i*-th word can be sent with cost *a**i*. For each word in his message, Mahmoud can either replace it with another word of the same meaning or leave it as it is. Can you help Mahmoud determine the minimum cost of sending the message?
The cost of sending the message is the sum of the costs of sending every word in it. | The first line of input contains integers *n*, *k* and *m* (1<=≤<=*k*<=≤<=*n*<=≤<=105,<=1<=≤<=*m*<=≤<=105) — the number of words in their language, the number of groups of words, and the number of words in Mahmoud's message respectively.
The second line contains *n* strings consisting of lowercase English letters of length not exceeding 20 which represent the words. It's guaranteed that the words are distinct.
The third line contains *n* integers *a*1, *a*2, ..., *a**n* (1<=≤<=*a**i*<=≤<=109) where *a**i* is the cost of sending the *i*-th word.
The next *k* lines describe the groups of words of same meaning. The next *k* lines each start with an integer *x* (1<=≤<=*x*<=≤<=*n*) which means that there are *x* words in this group, followed by *x* integers which represent the indices of words in this group. It's guaranteed that each word appears in exactly one group.
The next line contains *m* space-separated words which represent Mahmoud's message. Each of these words appears in the list of language's words. | The only line should contain the minimum cost to send the message after replacing some words (maybe none) with some words of the same meaning. | [
"5 4 4\ni loser am the second\n100 1 1 5 10\n1 1\n1 3\n2 2 5\n1 4\ni am the second\n",
"5 4 4\ni loser am the second\n100 20 1 5 10\n1 1\n1 3\n2 2 5\n1 4\ni am the second\n"
] | [
"107",
"116"
] | In the first sample, Mahmoud should replace the word "second" with the word "loser" because it has less cost so the cost will be 100+1+5+1=107.
In the second sample, Mahmoud shouldn't do any replacement so the cost will be 100+1+5+10=116. | 1,000 | [
{
"input": "5 4 4\ni loser am the second\n100 1 1 5 10\n1 1\n1 3\n2 2 5\n1 4\ni am the second",
"output": "107"
},
{
"input": "5 4 4\ni loser am the second\n100 20 1 5 10\n1 1\n1 3\n2 2 5\n1 4\ni am the second",
"output": "116"
},
{
"input": "1 1 1\na\n1000000000\n1 1\na",
"output": "1000000000"
},
{
"input": "1 1 10\na\n1000000000\n1 1\na a a a a a a a a a",
"output": "10000000000"
}
] | 1,609,971,642 | 2,147,483,647 | PyPy 3 | OK | TESTS | 22 | 733 | 30,822,400 | import sys
input = sys.stdin.readline
class DSU:
# Disjoint Set Union (Union-Find) Data Structure
def __init__(self, nodes):
# Dictionary of parents
self.p = [i for i in nodes]
# Dictionary of ranks
self.r = [0 for i in nodes]
# Dictionary of mins
self.m = [a[i] for i in nodes]
def get(self, u):
# Recursive Returns the identifier of the set that contains u, includes path compression
if u != self.p[u]:
self.p[u] = self.get(self.p[u])
return self.p[u]
def union(self, u, v):
# Unites the sets with identifiers u and v
u = self.get(u)
v = self.get(v)
if u != v:
if self.r[u] > self.r[v]:
u, v = v, u
self.p[u] = v
if self.r[u] == self.r[v]:
self.r[v] += 1
self.m[v] = min(self.m[u], self.m[v])
def get_min(self, u):
u = self.p[u]
return self.m[u]
n, k, m = [int(x) for x in input().split(' ')]
s = input().strip().split(' ')
d = {s[i]: i for i in range(n)}
a = [int(x) for x in input().split(' ')]
dsu = DSU(list(range(n)))
for query in range(k):
c = [int(x) for x in input().split(' ')]
if len(c) > 2:
for z in c[2:]:
dsu.union(c[1] - 1, z - 1)
ans = sum([dsu.get_min(d[w]) for w in input().strip().split(' ')])
print(ans)
| Title: Mahmoud and Ehab and the message
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Mahmoud wants to send a message to his friend Ehab. Their language consists of *n* words numbered from 1 to *n*. Some words have the same meaning so there are *k* groups of words such that all the words in some group have the same meaning.
Mahmoud knows that the *i*-th word can be sent with cost *a**i*. For each word in his message, Mahmoud can either replace it with another word of the same meaning or leave it as it is. Can you help Mahmoud determine the minimum cost of sending the message?
The cost of sending the message is the sum of the costs of sending every word in it.
Input Specification:
The first line of input contains integers *n*, *k* and *m* (1<=≤<=*k*<=≤<=*n*<=≤<=105,<=1<=≤<=*m*<=≤<=105) — the number of words in their language, the number of groups of words, and the number of words in Mahmoud's message respectively.
The second line contains *n* strings consisting of lowercase English letters of length not exceeding 20 which represent the words. It's guaranteed that the words are distinct.
The third line contains *n* integers *a*1, *a*2, ..., *a**n* (1<=≤<=*a**i*<=≤<=109) where *a**i* is the cost of sending the *i*-th word.
The next *k* lines describe the groups of words of same meaning. The next *k* lines each start with an integer *x* (1<=≤<=*x*<=≤<=*n*) which means that there are *x* words in this group, followed by *x* integers which represent the indices of words in this group. It's guaranteed that each word appears in exactly one group.
The next line contains *m* space-separated words which represent Mahmoud's message. Each of these words appears in the list of language's words.
Output Specification:
The only line should contain the minimum cost to send the message after replacing some words (maybe none) with some words of the same meaning.
Demo Input:
['5 4 4\ni loser am the second\n100 1 1 5 10\n1 1\n1 3\n2 2 5\n1 4\ni am the second\n', '5 4 4\ni loser am the second\n100 20 1 5 10\n1 1\n1 3\n2 2 5\n1 4\ni am the second\n']
Demo Output:
['107', '116']
Note:
In the first sample, Mahmoud should replace the word "second" with the word "loser" because it has less cost so the cost will be 100+1+5+1=107.
In the second sample, Mahmoud shouldn't do any replacement so the cost will be 100+1+5+10=116. | ```python
import sys
input = sys.stdin.readline
class DSU:
# Disjoint Set Union (Union-Find) Data Structure
def __init__(self, nodes):
# Dictionary of parents
self.p = [i for i in nodes]
# Dictionary of ranks
self.r = [0 for i in nodes]
# Dictionary of mins
self.m = [a[i] for i in nodes]
def get(self, u):
# Recursive Returns the identifier of the set that contains u, includes path compression
if u != self.p[u]:
self.p[u] = self.get(self.p[u])
return self.p[u]
def union(self, u, v):
# Unites the sets with identifiers u and v
u = self.get(u)
v = self.get(v)
if u != v:
if self.r[u] > self.r[v]:
u, v = v, u
self.p[u] = v
if self.r[u] == self.r[v]:
self.r[v] += 1
self.m[v] = min(self.m[u], self.m[v])
def get_min(self, u):
u = self.p[u]
return self.m[u]
n, k, m = [int(x) for x in input().split(' ')]
s = input().strip().split(' ')
d = {s[i]: i for i in range(n)}
a = [int(x) for x in input().split(' ')]
dsu = DSU(list(range(n)))
for query in range(k):
c = [int(x) for x in input().split(' ')]
if len(c) > 2:
for z in c[2:]:
dsu.union(c[1] - 1, z - 1)
ans = sum([dsu.get_min(d[w]) for w in input().strip().split(' ')])
print(ans)
``` | 3 |
|
939 | A | Love Triangle | PROGRAMMING | 800 | [
"graphs"
] | null | null | As you could know there are no male planes nor female planes. However, each plane on Earth likes some other plane. There are *n* planes on Earth, numbered from 1 to *n*, and the plane with number *i* likes the plane with number *f**i*, where 1<=≤<=*f**i*<=≤<=*n* and *f**i*<=≠<=*i*.
We call a love triangle a situation in which plane *A* likes plane *B*, plane *B* likes plane *C* and plane *C* likes plane *A*. Find out if there is any love triangle on Earth. | The first line contains a single integer *n* (2<=≤<=*n*<=≤<=5000) — the number of planes.
The second line contains *n* integers *f*1,<=*f*2,<=...,<=*f**n* (1<=≤<=*f**i*<=≤<=*n*, *f**i*<=≠<=*i*), meaning that the *i*-th plane likes the *f**i*-th. | Output «YES» if there is a love triangle consisting of planes on Earth. Otherwise, output «NO».
You can output any letter in lower case or in upper case. | [
"5\n2 4 5 1 3\n",
"5\n5 5 5 5 1\n"
] | [
"YES\n",
"NO\n"
] | In first example plane 2 likes plane 4, plane 4 likes plane 1, plane 1 likes plane 2 and that is a love triangle.
In second example there are no love triangles. | 500 | [
{
"input": "5\n2 4 5 1 3",
"output": "YES"
},
{
"input": "5\n5 5 5 5 1",
"output": "NO"
},
{
"input": "3\n3 1 2",
"output": "YES"
},
{
"input": "10\n4 10 9 5 3 1 5 10 6 4",
"output": "NO"
},
{
"input": "10\n5 5 4 9 10 9 9 5 3 1",
"output": "YES"
},
{
"input": "100\n50 40 60 87 39 58 44 84 46 68 16 57 77 87 92 95 42 31 74 15 36 84 30 3 47 15 87 90 76 66 6 63 74 19 40 49 6 84 41 9 77 34 7 12 11 73 58 24 81 14 81 29 65 100 1 85 64 32 38 4 54 67 32 81 80 7 100 71 29 80 4 52 47 7 78 56 52 75 81 37 16 41 27 28 58 60 62 47 29 40 37 14 59 91 12 54 25 58 12 43",
"output": "NO"
},
{
"input": "100\n25 6 46 37 87 99 70 31 46 12 94 40 87 56 28 8 94 39 13 12 67 13 71 39 83 48 40 14 62 41 16 71 20 41 83 41 68 98 23 82 62 83 62 35 49 22 31 21 66 98 54 39 34 52 11 28 47 89 25 44 68 36 91 46 82 86 88 48 27 93 7 9 53 36 16 100 84 84 44 25 58 66 16 46 72 21 91 78 4 17 44 17 47 67 93 89 75 44 56 50",
"output": "YES"
},
{
"input": "2\n2 1",
"output": "NO"
},
{
"input": "3\n2 3 1",
"output": "YES"
},
{
"input": "5\n2 1 4 5 3",
"output": "YES"
},
{
"input": "5\n5 4 5 5 2",
"output": "YES"
}
] | 1,649,128,977 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 4 | 93 | 0 | n = int(input())
a = list(map(int,input().split()))
s = set(a)
if len(a) == len(s):
print("YES")
else:
print("NO")
| Title: Love Triangle
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
As you could know there are no male planes nor female planes. However, each plane on Earth likes some other plane. There are *n* planes on Earth, numbered from 1 to *n*, and the plane with number *i* likes the plane with number *f**i*, where 1<=≤<=*f**i*<=≤<=*n* and *f**i*<=≠<=*i*.
We call a love triangle a situation in which plane *A* likes plane *B*, plane *B* likes plane *C* and plane *C* likes plane *A*. Find out if there is any love triangle on Earth.
Input Specification:
The first line contains a single integer *n* (2<=≤<=*n*<=≤<=5000) — the number of planes.
The second line contains *n* integers *f*1,<=*f*2,<=...,<=*f**n* (1<=≤<=*f**i*<=≤<=*n*, *f**i*<=≠<=*i*), meaning that the *i*-th plane likes the *f**i*-th.
Output Specification:
Output «YES» if there is a love triangle consisting of planes on Earth. Otherwise, output «NO».
You can output any letter in lower case or in upper case.
Demo Input:
['5\n2 4 5 1 3\n', '5\n5 5 5 5 1\n']
Demo Output:
['YES\n', 'NO\n']
Note:
In first example plane 2 likes plane 4, plane 4 likes plane 1, plane 1 likes plane 2 and that is a love triangle.
In second example there are no love triangles. | ```python
n = int(input())
a = list(map(int,input().split()))
s = set(a)
if len(a) == len(s):
print("YES")
else:
print("NO")
``` | 0 |
|
50 | A | Domino piling | PROGRAMMING | 800 | [
"greedy",
"math"
] | A. Domino piling | 2 | 256 | You are given a rectangular board of *M*<=×<=*N* squares. Also you are given an unlimited number of standard domino pieces of 2<=×<=1 squares. You are allowed to rotate the pieces. You are asked to place as many dominoes as possible on the board so as to meet the following conditions:
1. Each domino completely covers two squares.
2. No two dominoes overlap.
3. Each domino lies entirely inside the board. It is allowed to touch the edges of the board.
Find the maximum number of dominoes, which can be placed under these restrictions. | In a single line you are given two integers *M* and *N* — board sizes in squares (1<=≤<=*M*<=≤<=*N*<=≤<=16). | Output one number — the maximal number of dominoes, which can be placed. | [
"2 4\n",
"3 3\n"
] | [
"4\n",
"4\n"
] | none | 500 | [
{
"input": "2 4",
"output": "4"
},
{
"input": "3 3",
"output": "4"
},
{
"input": "1 5",
"output": "2"
},
{
"input": "1 6",
"output": "3"
},
{
"input": "1 15",
"output": "7"
},
{
"input": "1 16",
"output": "8"
},
{
"input": "2 5",
"output": "5"
},
{
"input": "2 6",
"output": "6"
},
{
"input": "2 7",
"output": "7"
},
{
"input": "2 14",
"output": "14"
},
{
"input": "2 15",
"output": "15"
},
{
"input": "1 4",
"output": "2"
},
{
"input": "2 16",
"output": "16"
},
{
"input": "3 5",
"output": "7"
},
{
"input": "3 6",
"output": "9"
},
{
"input": "3 10",
"output": "15"
},
{
"input": "3 14",
"output": "21"
},
{
"input": "3 15",
"output": "22"
},
{
"input": "3 16",
"output": "24"
},
{
"input": "5 7",
"output": "17"
},
{
"input": "16 16",
"output": "128"
},
{
"input": "15 16",
"output": "120"
},
{
"input": "2 3",
"output": "3"
},
{
"input": "15 15",
"output": "112"
},
{
"input": "14 16",
"output": "112"
},
{
"input": "11 13",
"output": "71"
},
{
"input": "5 16",
"output": "40"
},
{
"input": "8 15",
"output": "60"
},
{
"input": "2 2",
"output": "2"
},
{
"input": "3 4",
"output": "6"
},
{
"input": "4 4",
"output": "8"
},
{
"input": "1 1",
"output": "0"
},
{
"input": "1 2",
"output": "1"
},
{
"input": "1 3",
"output": "1"
},
{
"input": "14 15",
"output": "105"
}
] | 1,693,737,223 | 2,147,483,647 | Python 3 | OK | TESTS | 35 | 92 | 0 | M, N = map(int, input().split())
# Calculate the number of 2x1 cells in the MxN board
# Each 2x1 cell can accommodate one domino.
max_dominoes = (M * N) // 2
print(max_dominoes)
| Title: Domino piling
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
You are given a rectangular board of *M*<=×<=*N* squares. Also you are given an unlimited number of standard domino pieces of 2<=×<=1 squares. You are allowed to rotate the pieces. You are asked to place as many dominoes as possible on the board so as to meet the following conditions:
1. Each domino completely covers two squares.
2. No two dominoes overlap.
3. Each domino lies entirely inside the board. It is allowed to touch the edges of the board.
Find the maximum number of dominoes, which can be placed under these restrictions.
Input Specification:
In a single line you are given two integers *M* and *N* — board sizes in squares (1<=≤<=*M*<=≤<=*N*<=≤<=16).
Output Specification:
Output one number — the maximal number of dominoes, which can be placed.
Demo Input:
['2 4\n', '3 3\n']
Demo Output:
['4\n', '4\n']
Note:
none | ```python
M, N = map(int, input().split())
# Calculate the number of 2x1 cells in the MxN board
# Each 2x1 cell can accommodate one domino.
max_dominoes = (M * N) // 2
print(max_dominoes)
``` | 3.977 |
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,603,867,461 | 2,147,483,647 | Python 3 | OK | TESTS | 37 | 216 | 614,400 | s=list(input())
n=len(s)
if '0' in s:
s.remove('0')
print(''.join(s))
else:
s.remove('1')
print(''.join(s)) | 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=list(input())
n=len(s)
if '0' in s:
s.remove('0')
print(''.join(s))
else:
s.remove('1')
print(''.join(s))
``` | 3 |
|
56 | A | Bar | PROGRAMMING | 1,000 | [
"implementation"
] | A. Bar | 2 | 256 | According to Berland laws it is only allowed to sell alcohol to people not younger than 18 years. Vasya's job is to monitor the law's enforcement. Tonight he entered a bar and saw *n* people sitting there. For every one of them Vasya happened to determine either the age or the drink the person is having. Vasya can check any person, i.e. learn his age and the drink he is having at the same time. What minimal number of people should Vasya check additionally to make sure that there are no clients under 18 having alcohol drinks?
The list of all alcohol drinks in Berland is: ABSINTH, BEER, BRANDY, CHAMPAGNE, GIN, RUM, SAKE, TEQUILA, VODKA, WHISKEY, WINE | The first line contains an integer *n* (1<=≤<=*n*<=≤<=100) which is the number of the bar's clients. Then follow *n* lines, each describing one visitor. A line either contains his age (an integer from 0 to 1000) or his drink (a string of capital Latin letters from 1 to 100 in length). It is guaranteed that the input data does not contain spaces and other unnecessary separators.
Only the drinks from the list given above should be considered alcohol. | Print a single number which is the number of people Vasya should check to guarantee the law enforcement. | [
"5\n18\nVODKA\nCOKE\n19\n17\n"
] | [
"2\n"
] | In the sample test the second and fifth clients should be checked. | 500 | [
{
"input": "5\n18\nVODKA\nCOKE\n19\n17",
"output": "2"
},
{
"input": "2\n2\nGIN",
"output": "2"
},
{
"input": "3\nWHISKEY\n3\nGIN",
"output": "3"
},
{
"input": "4\n813\nIORBQITQXMPTFAEMEQDQIKFGKGOTNKTOSZCBRPXJLUKVLVHJYNRUJXK\nRUM\nRHVRWGODYWWTYZFLFYKCVUFFRTQDINKNWPKFHZBFWBHWINWJW",
"output": "1"
},
{
"input": "4\nSAKE\nSAKE\n13\n2",
"output": "4"
},
{
"input": "2\n0\n17",
"output": "2"
},
{
"input": "1\n0",
"output": "1"
}
] | 1,592,460,523 | 2,147,483,647 | Python 3 | OK | TESTS | 28 | 218 | 0 | n = int(input())
s = ['ABSINTH', 'BEER', 'BRANDY', 'CHAMPAGNE', 'GIN', 'RUM', 'SAKE', 'TEQUILA', 'VODKA', 'WHISKEY', 'WINE']
ans = 0
for _ in range(n):
sa = input()
if sa in s:
ans+=1
elif sa.isnumeric():
sa = int(sa)
if sa<18:
ans+=1
print(ans) | Title: Bar
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
According to Berland laws it is only allowed to sell alcohol to people not younger than 18 years. Vasya's job is to monitor the law's enforcement. Tonight he entered a bar and saw *n* people sitting there. For every one of them Vasya happened to determine either the age or the drink the person is having. Vasya can check any person, i.e. learn his age and the drink he is having at the same time. What minimal number of people should Vasya check additionally to make sure that there are no clients under 18 having alcohol drinks?
The list of all alcohol drinks in Berland is: ABSINTH, BEER, BRANDY, CHAMPAGNE, GIN, RUM, SAKE, TEQUILA, VODKA, WHISKEY, WINE
Input Specification:
The first line contains an integer *n* (1<=≤<=*n*<=≤<=100) which is the number of the bar's clients. Then follow *n* lines, each describing one visitor. A line either contains his age (an integer from 0 to 1000) or his drink (a string of capital Latin letters from 1 to 100 in length). It is guaranteed that the input data does not contain spaces and other unnecessary separators.
Only the drinks from the list given above should be considered alcohol.
Output Specification:
Print a single number which is the number of people Vasya should check to guarantee the law enforcement.
Demo Input:
['5\n18\nVODKA\nCOKE\n19\n17\n']
Demo Output:
['2\n']
Note:
In the sample test the second and fifth clients should be checked. | ```python
n = int(input())
s = ['ABSINTH', 'BEER', 'BRANDY', 'CHAMPAGNE', 'GIN', 'RUM', 'SAKE', 'TEQUILA', 'VODKA', 'WHISKEY', 'WINE']
ans = 0
for _ in range(n):
sa = input()
if sa in s:
ans+=1
elif sa.isnumeric():
sa = int(sa)
if sa<18:
ans+=1
print(ans)
``` | 3.9455 |
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,650,801,093 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 11 | 62 | 512,000 | # coding=utf-8
x=input()
n=int(input())
if len(x)<n:
print("impossible")
else:
y=set(x)
print(n-len(y))
| 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
# coding=utf-8
x=input()
n=int(input())
if len(x)<n:
print("impossible")
else:
y=set(x)
print(n-len(y))
``` | 0 |
|
224 | A | Parallelepiped | PROGRAMMING | 1,100 | [
"brute force",
"geometry",
"math"
] | null | null | You've got a rectangular parallelepiped with integer edge lengths. You know the areas of its three faces that have a common vertex. Your task is to find the sum of lengths of all 12 edges of this parallelepiped. | The first and the single line contains three space-separated integers — the areas of the parallelepiped's faces. The area's values are positive (<=><=0) and do not exceed 104. It is guaranteed that there exists at least one parallelepiped that satisfies the problem statement. | Print a single number — the sum of all edges of the parallelepiped. | [
"1 1 1\n",
"4 6 6\n"
] | [
"12\n",
"28\n"
] | In the first sample the parallelepiped has sizes 1 × 1 × 1, in the second one — 2 × 2 × 3. | 500 | [
{
"input": "1 1 1",
"output": "12"
},
{
"input": "4 6 6",
"output": "28"
},
{
"input": "20 10 50",
"output": "68"
},
{
"input": "9 4 36",
"output": "56"
},
{
"input": "324 9 36",
"output": "184"
},
{
"input": "1333 93 129",
"output": "308"
},
{
"input": "1022 584 112",
"output": "380"
},
{
"input": "66 174 319",
"output": "184"
},
{
"input": "912 276 1748",
"output": "444"
},
{
"input": "65 156 60",
"output": "120"
},
{
"input": "1 10000 10000",
"output": "40008"
},
{
"input": "1485 55 27",
"output": "332"
},
{
"input": "152 108 4104",
"output": "528"
},
{
"input": "1656 6900 1350",
"output": "740"
},
{
"input": "12 14 42",
"output": "60"
},
{
"input": "615 18 1230",
"output": "856"
},
{
"input": "680 60 408",
"output": "336"
},
{
"input": "644 966 6",
"output": "1308"
},
{
"input": "1 432 432",
"output": "1736"
},
{
"input": "2239 2239 1",
"output": "8964"
},
{
"input": "4106 8212 2",
"output": "16436"
},
{
"input": "10000 10000 10000",
"output": "1200"
},
{
"input": "3623 3623 1",
"output": "14500"
},
{
"input": "9801 9801 9801",
"output": "1188"
},
{
"input": "10000 1 10000",
"output": "40008"
},
{
"input": "9 9 9",
"output": "36"
},
{
"input": "9801 9702 9702",
"output": "1184"
}
] | 1,695,889,723 | 2,147,483,647 | Python 3 | OK | TESTS | 27 | 92 | 0 | a,b,c=map(int,input().split())
d=(a*b*c)**.5
print(int(4*(d/a+d/b+d/c))) | Title: Parallelepiped
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You've got a rectangular parallelepiped with integer edge lengths. You know the areas of its three faces that have a common vertex. Your task is to find the sum of lengths of all 12 edges of this parallelepiped.
Input Specification:
The first and the single line contains three space-separated integers — the areas of the parallelepiped's faces. The area's values are positive (<=><=0) and do not exceed 104. It is guaranteed that there exists at least one parallelepiped that satisfies the problem statement.
Output Specification:
Print a single number — the sum of all edges of the parallelepiped.
Demo Input:
['1 1 1\n', '4 6 6\n']
Demo Output:
['12\n', '28\n']
Note:
In the first sample the parallelepiped has sizes 1 × 1 × 1, in the second one — 2 × 2 × 3. | ```python
a,b,c=map(int,input().split())
d=(a*b*c)**.5
print(int(4*(d/a+d/b+d/c)))
``` | 3 |
|
74 | A | Room Leader | PROGRAMMING | 1,000 | [
"implementation"
] | A. Room Leader | 2 | 256 | Let us remind you part of the rules of Codeforces. The given rules slightly simplified, use the problem statement as a formal document.
In the beginning of the round the contestants are divided into rooms. Each room contains exactly *n* participants. During the contest the participants are suggested to solve five problems, *A*, *B*, *C*, *D* and *E*. For each of these problem, depending on when the given problem was solved and whether it was solved at all, the participants receive some points. Besides, a contestant can perform hacks on other contestants. For each successful hack a contestant earns 100 points, for each unsuccessful hack a contestant loses 50 points. The number of points for every contestant is represented by the sum of points he has received from all his problems, including hacks.
You are suggested to determine the leader for some room; the leader is a participant who has maximum points. | The first line contains an integer *n*, which is the number of contestants in the room (1<=≤<=*n*<=≤<=50). The next *n* lines contain the participants of a given room. The *i*-th line has the format of "*handle**i* *plus**i* *minus**i* *a**i* *b**i* *c**i* *d**i* *e**i*" — it is the handle of a contestant, the number of successful hacks, the number of unsuccessful hacks and the number of points he has received from problems *A*, *B*, *C*, *D*, *E* correspondingly. The handle of each participant consists of Latin letters, digits and underscores and has the length from 1 to 20 characters. There are the following limitations imposed upon the numbers:
- 0<=≤<=*plus**i*,<=*minus**i*<=≤<=50; - 150<=≤<=*a**i*<=≤<=500 or *a**i*<==<=0, if problem *A* is not solved; - 300<=≤<=*b**i*<=≤<=1000 or *b**i*<==<=0, if problem *B* is not solved; - 450<=≤<=*c**i*<=≤<=1500 or *c**i*<==<=0, if problem *C* is not solved; - 600<=≤<=*d**i*<=≤<=2000 or *d**i*<==<=0, if problem *D* is not solved; - 750<=≤<=*e**i*<=≤<=2500 or *e**i*<==<=0, if problem *E* is not solved.
All the numbers are integer. All the participants have different handles. It is guaranteed that there is exactly one leader in the room (i.e. there are no two participants with the maximal number of points). | Print on the single line the handle of the room leader. | [
"5\nPetr 3 1 490 920 1000 1200 0\ntourist 2 0 490 950 1100 1400 0\nEgor 7 0 480 900 950 0 1000\nc00lH4x0R 0 10 150 0 0 0 0\nsome_participant 2 1 450 720 900 0 0\n"
] | [
"tourist"
] | The number of points that each participant from the example earns, are as follows:
- Petr — 3860 - tourist — 4140 - Egor — 4030 - c00lH4x0R — - 350 - some_participant — 2220
Thus, the leader of the room is tourist. | 500 | [
{
"input": "5\nPetr 3 1 490 920 1000 1200 0\ntourist 2 0 490 950 1100 1400 0\nEgor 7 0 480 900 950 0 1000\nc00lH4x0R 0 10 150 0 0 0 0\nsome_participant 2 1 450 720 900 0 0",
"output": "tourist"
},
{
"input": "1\nA 0 0 200 0 0 0 0",
"output": "A"
},
{
"input": "2\n12345678901234567890 1 0 200 0 0 0 0\n_ 1 0 201 0 0 0 0",
"output": "_"
},
{
"input": "5\nAb 0 0 481 900 1200 1600 2000\nCd 0 0 480 899 1200 1600 2000\nEf 0 0 480 900 1200 1600 2000\ngH 0 0 480 900 1200 1599 2000\nij 0 0 480 900 1199 1600 2001",
"output": "Ab"
},
{
"input": "4\nF1 0 0 150 0 0 0 0\nF2 0 1 0 0 0 0 0\nF3 0 2 0 0 0 0 0\nF4 0 3 0 0 0 0 0",
"output": "F1"
},
{
"input": "2\nA87h 5 0 199 0 0 0 0\nBcfg 7 0 0 0 0 0 0",
"output": "Bcfg"
},
{
"input": "10\nKh 40 26 0 0 0 0 1243\nn 46 50 500 0 910 1912 0\nU 18 1 182 0 457 0 0\nFth6A0uT6i 38 30 0 787 0 1121 0\nC5l 24 38 0 689 1082 0 0\nN 47 25 0 0 1065 0 1538\nznyL 9 24 0 315 0 0 0\nJ0kU 27 47 445 0 0 0 0\nlT0rwiD2pg 46 13 0 818 0 0 0\nuJzr 29 14 0 0 0 0 2387",
"output": "N"
},
{
"input": "2\nminus_one 0 4 199 0 0 0 0\nminus_two 0 4 198 0 0 0 0",
"output": "minus_one"
},
{
"input": "10\nW22kb1L1 0 39 0 465 0 1961 865\n1MCXiVYmu5ys0afl 0 38 0 0 0 1982 1241\nCxg706kUJtQ 0 23 211 0 0 1785 1056\nmzEY 0 16 0 0 0 1988 1404\nv8JUjmam5SFP 0 48 0 788 1199 1426 0\n7giq 0 21 0 780 1437 1363 1930\nsXsUGbAulj6Lbiq 0 32 205 0 0 603 0\nRepIrY1Er4PgK 0 13 381 872 927 1488 0\nleKBdKHLnLFz 0 29 220 0 0 1006 889\nD 0 26 497 0 0 0 1815",
"output": "7giq"
},
{
"input": "1\nZ 0 0 0 0 0 0 0",
"output": "Z"
},
{
"input": "3\nAbcd 0 4 189 0 0 0 0\nDefg 0 5 248 0 0 0 0\nGhh 1 3 0 0 0 0 0",
"output": "Defg"
},
{
"input": "3\ndf 0 6 0 0 0 0 0\njnm 1 8 300 0 0 0 0\n_ub_ 3 20 300 310 0 0 0",
"output": "jnm"
},
{
"input": "1\njhgcyt 0 50 0 0 0 0 0",
"output": "jhgcyt"
},
{
"input": "2\njhv 0 50 500 1000 1500 2000 2500\nPetr 2 1 489 910 1100 1300 1000",
"output": "jhv"
},
{
"input": "3\nufu 0 50 0 0 0 0 0\nhzEr65f 1 50 0 0 0 0 0\nytdttjfhfd 0 50 150 0 0 0 0",
"output": "ytdttjfhfd"
},
{
"input": "5\nufuf 0 50 0 0 0 0 0\nyfycy 50 0 500 1000 1500 2000 2500\n__u77 6 7 490 999 1456 1976 1356\n0 1 2 0 0 0 0 2452\ngu7fF 50 0 500 1000 1500 2000 2499",
"output": "yfycy"
},
{
"input": "2\nhfy 0 50 0 0 0 0 2500\nugug 0 50 0 0 0 0 2499",
"output": "hfy"
},
{
"input": "8\nA 0 0 0 0 0 0 0\nb 0 0 0 0 0 0 0\nc 0 0 0 0 0 0 0\nD 0 0 0 0 0 0 0\nE 1 0 0 0 0 0 0\nF 0 0 0 0 0 0 0\ng 0 0 0 0 0 0 0\nH 0 0 0 0 0 0 0",
"output": "E"
},
{
"input": "2\nyyyc 50 50 0 0 0 0 0\nydd 0 0 0 0 0 0 2499",
"output": "yyyc"
},
{
"input": "2\ntom 0 2 0 0 0 0 0\nmac 0 1 0 0 0 0 0",
"output": "mac"
},
{
"input": "1\ncool 0 10 0 0 0 0 0",
"output": "cool"
}
] | 1,399,522,770 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 7 | 124 | 0 | n = int(input())
winner = ''
win_score = 0
for i in range(n):
current = list(map(str,input().split()))
score = int(current[1])*100 - int(current[2])*50 + int(current[3]) + int(current[4]) +int(current[5]) +int(current[6]) +int(current[7])
if score > win_score :
win_score = score
winner = current[0]
print(winner) | Title: Room Leader
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Let us remind you part of the rules of Codeforces. The given rules slightly simplified, use the problem statement as a formal document.
In the beginning of the round the contestants are divided into rooms. Each room contains exactly *n* participants. During the contest the participants are suggested to solve five problems, *A*, *B*, *C*, *D* and *E*. For each of these problem, depending on when the given problem was solved and whether it was solved at all, the participants receive some points. Besides, a contestant can perform hacks on other contestants. For each successful hack a contestant earns 100 points, for each unsuccessful hack a contestant loses 50 points. The number of points for every contestant is represented by the sum of points he has received from all his problems, including hacks.
You are suggested to determine the leader for some room; the leader is a participant who has maximum points.
Input Specification:
The first line contains an integer *n*, which is the number of contestants in the room (1<=≤<=*n*<=≤<=50). The next *n* lines contain the participants of a given room. The *i*-th line has the format of "*handle**i* *plus**i* *minus**i* *a**i* *b**i* *c**i* *d**i* *e**i*" — it is the handle of a contestant, the number of successful hacks, the number of unsuccessful hacks and the number of points he has received from problems *A*, *B*, *C*, *D*, *E* correspondingly. The handle of each participant consists of Latin letters, digits and underscores and has the length from 1 to 20 characters. There are the following limitations imposed upon the numbers:
- 0<=≤<=*plus**i*,<=*minus**i*<=≤<=50; - 150<=≤<=*a**i*<=≤<=500 or *a**i*<==<=0, if problem *A* is not solved; - 300<=≤<=*b**i*<=≤<=1000 or *b**i*<==<=0, if problem *B* is not solved; - 450<=≤<=*c**i*<=≤<=1500 or *c**i*<==<=0, if problem *C* is not solved; - 600<=≤<=*d**i*<=≤<=2000 or *d**i*<==<=0, if problem *D* is not solved; - 750<=≤<=*e**i*<=≤<=2500 or *e**i*<==<=0, if problem *E* is not solved.
All the numbers are integer. All the participants have different handles. It is guaranteed that there is exactly one leader in the room (i.e. there are no two participants with the maximal number of points).
Output Specification:
Print on the single line the handle of the room leader.
Demo Input:
['5\nPetr 3 1 490 920 1000 1200 0\ntourist 2 0 490 950 1100 1400 0\nEgor 7 0 480 900 950 0 1000\nc00lH4x0R 0 10 150 0 0 0 0\nsome_participant 2 1 450 720 900 0 0\n']
Demo Output:
['tourist']
Note:
The number of points that each participant from the example earns, are as follows:
- Petr — 3860 - tourist — 4140 - Egor — 4030 - c00lH4x0R — - 350 - some_participant — 2220
Thus, the leader of the room is tourist. | ```python
n = int(input())
winner = ''
win_score = 0
for i in range(n):
current = list(map(str,input().split()))
score = int(current[1])*100 - int(current[2])*50 + int(current[3]) + int(current[4]) +int(current[5]) +int(current[6]) +int(current[7])
if score > win_score :
win_score = score
winner = current[0]
print(winner)
``` | 0 |
306 | A | Candies | PROGRAMMING | 800 | [
"implementation"
] | null | null | Polycarpus has got *n* candies and *m* friends (*n*<=≥<=*m*). He wants to make a New Year present with candies to each friend. Polycarpus is planning to present all candies and he wants to do this in the fairest (that is, most equal) manner. He wants to choose such *a**i*, where *a**i* is the number of candies in the *i*-th friend's present, that the maximum *a**i* differs from the least *a**i* as little as possible.
For example, if *n* is divisible by *m*, then he is going to present the same number of candies to all his friends, that is, the maximum *a**i* won't differ from the minimum one. | The single line of the input contains a pair of space-separated positive integers *n*, *m* (1<=≤<=*n*,<=*m*<=≤<=100;*n*<=≥<=*m*) — the number of candies and the number of Polycarpus's friends. | Print the required sequence *a*1,<=*a*2,<=...,<=*a**m*, where *a**i* is the number of candies in the *i*-th friend's present. All numbers *a**i* must be positive integers, total up to *n*, the maximum one should differ from the minimum one by the smallest possible value. | [
"12 3\n",
"15 4\n",
"18 7\n"
] | [
"4 4 4 ",
"3 4 4 4 ",
"2 2 2 3 3 3 3 "
] | Print *a*<sub class="lower-index">*i*</sub> in any order, separate the numbers by spaces. | 500 | [
{
"input": "12 4",
"output": "3 3 3 3 "
},
{
"input": "15 6",
"output": "2 2 2 3 3 3 "
},
{
"input": "18 8",
"output": "2 2 2 2 2 2 3 3 "
},
{
"input": "1 1",
"output": "1 "
},
{
"input": "2 1",
"output": "2 "
},
{
"input": "100 1",
"output": "100 "
},
{
"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 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 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 10",
"output": "10 10 10 10 10 10 10 10 10 10 "
},
{
"input": "64 8",
"output": "8 8 8 8 8 8 8 8 "
},
{
"input": "81 27",
"output": "3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 "
},
{
"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 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 "
},
{
"input": "100 51",
"output": "1 1 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 "
},
{
"input": "100 49",
"output": "2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 3 3 "
},
{
"input": "100 13",
"output": "7 7 7 7 8 8 8 8 8 8 8 8 8 "
},
{
"input": "97 11",
"output": "8 8 9 9 9 9 9 9 9 9 9 "
},
{
"input": "19 3",
"output": "6 6 7 "
},
{
"input": "99 10",
"output": "9 10 10 10 10 10 10 10 10 10 "
},
{
"input": "88 5",
"output": "17 17 18 18 18 "
},
{
"input": "87 34",
"output": "2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 "
},
{
"input": "97 55",
"output": "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 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 "
}
] | 1,554,043,551 | 2,147,483,647 | Python 3 | OK | TESTS | 20 | 216 | 0 | C, F = map(int, input().split())
while F > 0:
c = C // F
print(c, end=' ')
F -= 1
C -= c
| Title: Candies
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Polycarpus has got *n* candies and *m* friends (*n*<=≥<=*m*). He wants to make a New Year present with candies to each friend. Polycarpus is planning to present all candies and he wants to do this in the fairest (that is, most equal) manner. He wants to choose such *a**i*, where *a**i* is the number of candies in the *i*-th friend's present, that the maximum *a**i* differs from the least *a**i* as little as possible.
For example, if *n* is divisible by *m*, then he is going to present the same number of candies to all his friends, that is, the maximum *a**i* won't differ from the minimum one.
Input Specification:
The single line of the input contains a pair of space-separated positive integers *n*, *m* (1<=≤<=*n*,<=*m*<=≤<=100;*n*<=≥<=*m*) — the number of candies and the number of Polycarpus's friends.
Output Specification:
Print the required sequence *a*1,<=*a*2,<=...,<=*a**m*, where *a**i* is the number of candies in the *i*-th friend's present. All numbers *a**i* must be positive integers, total up to *n*, the maximum one should differ from the minimum one by the smallest possible value.
Demo Input:
['12 3\n', '15 4\n', '18 7\n']
Demo Output:
['4 4 4 ', '3 4 4 4 ', '2 2 2 3 3 3 3 ']
Note:
Print *a*<sub class="lower-index">*i*</sub> in any order, separate the numbers by spaces. | ```python
C, F = map(int, input().split())
while F > 0:
c = C // F
print(c, end=' ')
F -= 1
C -= c
``` | 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,649,855,348 | 2,147,483,647 | Python 3 | OK | TESTS | 32 | 92 | 0 | n = int(input())
t = list(map(int,input().split()))
i = 0
while i < n-1:
if t[i] % 2 != t[i+1] % 2:
if i<n-2 and t[i+1]%2 == t[i+2]%2:
print(i+1)
exit()
else:
print(i+2)
exit()
i += 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
n = int(input())
t = list(map(int,input().split()))
i = 0
while i < n-1:
if t[i] % 2 != t[i+1] % 2:
if i<n-2 and t[i+1]%2 == t[i+2]%2:
print(i+1)
exit()
else:
print(i+2)
exit()
i += 1
``` | 3.977 |
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,098,258 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 6 | 2,000 | 30,412,800 | import math
n = int(input())
check = [True]
a = []
s = input().split()
tp = []
mx = 0
for i in range(n):
a.append(int(s[i]))
mx = max(mx, math.sqrt(a[i]))
mx = int(mx + 1)
h = 0
while h <= mx:
check.append(True)
h += 1
h = 2
while h <= mx:
if not check[h]:
h += 1
continue
tp.append(h ** 2)
q = 2
while q * h <= mx:
check[q * h] = False
q += 1
h += 1
for i in range(n):
if a[i] in tp:
print('YES')
else:
print('NO') | 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
import math
n = int(input())
check = [True]
a = []
s = input().split()
tp = []
mx = 0
for i in range(n):
a.append(int(s[i]))
mx = max(mx, math.sqrt(a[i]))
mx = int(mx + 1)
h = 0
while h <= mx:
check.append(True)
h += 1
h = 2
while h <= mx:
if not check[h]:
h += 1
continue
tp.append(h ** 2)
q = 2
while q * h <= mx:
check[q * h] = False
q += 1
h += 1
for i in range(n):
if a[i] in tp:
print('YES')
else:
print('NO')
``` | 0 |
|
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,666,897,197 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 117 | 77 | 2,969,600 | n,k=map(int,input().split())
s=(input())
# s,t=input().split()
# arr=list(map(int,input().split()))
# for _ in range(int(input())):
# n=int(input())
i=0;j=0;mp={"a":0,"b":0};mx=-1
while j<n:
mp[s[j]]+=1
if mp["a"]<=k or mp["b"]<=k:
mx=max(mx,mp["a"]+mp["b"])
j+=1
else:
if mp["a"]>k and mp["b"]>k:
mp[s[i]]-=1
i+=1
j+=1
print(mx) | 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())
# s,t=input().split()
# arr=list(map(int,input().split()))
# for _ in range(int(input())):
# n=int(input())
i=0;j=0;mp={"a":0,"b":0};mx=-1
while j<n:
mp[s[j]]+=1
if mp["a"]<=k or mp["b"]<=k:
mx=max(mx,mp["a"]+mp["b"])
j+=1
else:
if mp["a"]>k and mp["b"]>k:
mp[s[i]]-=1
i+=1
j+=1
print(mx)
``` | 3 |
|
867 | A | Between the Offices | PROGRAMMING | 800 | [
"implementation"
] | null | null | As you may know, MemSQL has American offices in both San Francisco and Seattle. Being a manager in the company, you travel a lot between the two cities, always by plane.
You prefer flying from Seattle to San Francisco than in the other direction, because it's warmer in San Francisco. You are so busy that you don't remember the number of flights you have made in either direction. However, for each of the last *n* days you know whether you were in San Francisco office or in Seattle office. You always fly at nights, so you never were at both offices on the same day. Given this information, determine if you flew more times from Seattle to San Francisco during the last *n* days, or not. | The first line of input contains single integer *n* (2<=≤<=*n*<=≤<=100) — the number of days.
The second line contains a string of length *n* consisting of only capital 'S' and 'F' letters. If the *i*-th letter is 'S', then you were in Seattle office on that day. Otherwise you were in San Francisco. The days are given in chronological order, i.e. today is the last day in this sequence. | Print "YES" if you flew more times from Seattle to San Francisco, and "NO" otherwise.
You can print each letter in any case (upper or lower). | [
"4\nFSSF\n",
"2\nSF\n",
"10\nFFFFFFFFFF\n",
"10\nSSFFSFFSFF\n"
] | [
"NO\n",
"YES\n",
"NO\n",
"YES\n"
] | In the first example you were initially at San Francisco, then flew to Seattle, were there for two days and returned to San Francisco. You made one flight in each direction, so the answer is "NO".
In the second example you just flew from Seattle to San Francisco, so the answer is "YES".
In the third example you stayed the whole period in San Francisco, so the answer is "NO".
In the fourth example if you replace 'S' with ones, and 'F' with zeros, you'll get the first few digits of π in binary representation. Not very useful information though. | 500 | [
{
"input": "4\nFSSF",
"output": "NO"
},
{
"input": "2\nSF",
"output": "YES"
},
{
"input": "10\nFFFFFFFFFF",
"output": "NO"
},
{
"input": "10\nSSFFSFFSFF",
"output": "YES"
},
{
"input": "20\nSFSFFFFSSFFFFSSSSFSS",
"output": "NO"
},
{
"input": "20\nSSFFFFFSFFFFFFFFFFFF",
"output": "YES"
},
{
"input": "20\nSSFSFSFSFSFSFSFSSFSF",
"output": "YES"
},
{
"input": "20\nSSSSFSFSSFSFSSSSSSFS",
"output": "NO"
},
{
"input": "100\nFFFSFSFSFSSFSFFSSFFFFFSSSSFSSFFFFSFFFFFSFFFSSFSSSFFFFSSFFSSFSFFSSFSSSFSFFSFSFFSFSFFSSFFSFSSSSFSFSFSS",
"output": "NO"
},
{
"input": "100\nFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF",
"output": "NO"
},
{
"input": "100\nFFFFFFFFFFFFFFFFFFFFFFFFFFSFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFSFFFFFFFFFFFFFFFFFSS",
"output": "NO"
},
{
"input": "100\nFFFFFFFFFFFFFSFFFFFFFFFSFSSFFFFFFFFFFFFFFFFFFFFFFSFFSFFFFFSFFFFFFFFSFFFFFFFFFFFFFSFFFFFFFFSFFFFFFFSF",
"output": "NO"
},
{
"input": "100\nSFFSSFFFFFFSSFFFSSFSFFFFFSSFFFSFFFFFFSFSSSFSFSFFFFSFSSFFFFFFFFSFFFFFSFFFFFSSFFFSFFSFSFFFFSFFSFFFFFFF",
"output": "YES"
},
{
"input": "100\nFFFFSSSSSFFSSSFFFSFFFFFSFSSFSFFSFFSSFFSSFSFFFFFSFSFSFSFFFFFFFFFSFSFFSFFFFSFSFFFFFFFFFFFFSFSSFFSSSSFF",
"output": "NO"
},
{
"input": "100\nFFFFFFFFFFFFSSFFFFSFSFFFSFSSSFSSSSSFSSSSFFSSFFFSFSFSSFFFSSSFFSFSFSSFSFSSFSFFFSFFFFFSSFSFFFSSSFSSSFFS",
"output": "NO"
},
{
"input": "100\nFFFSSSFSFSSSSFSSFSFFSSSFFSSFSSFFSSFFSFSSSSFFFSFFFSFSFSSSFSSFSFSFSFFSSSSSFSSSFSFSFFSSFSFSSFFSSFSFFSFS",
"output": "NO"
},
{
"input": "100\nFFSSSSFSSSFSSSSFSSSFFSFSSFFSSFSSSFSSSFFSFFSSSSSSSSSSSSFSSFSSSSFSFFFSSFFFFFFSFSFSSSSSSFSSSFSFSSFSSFSS",
"output": "NO"
},
{
"input": "100\nSSSFFFSSSSFFSSSSSFSSSSFSSSFSSSSSFSSSSSSSSFSFFSSSFFSSFSSSSFFSSSSSSFFSSSSFSSSSSSFSSSFSSSSSSSFSSSSFSSSS",
"output": "NO"
},
{
"input": "100\nFSSSSSSSSSSSFSSSSSSSSSSSSSSSSFSSSSSSFSSSSSSSSSSSSSFSSFSSSSSFSSFSSSSSSSSSFFSSSSSFSFSSSFFSSSSSSSSSSSSS",
"output": "NO"
},
{
"input": "100\nSSSSSSSSSSSSSFSSSSSSSSSSSSFSSSFSSSSSSSSSSSSSSSSSSSSSSSSSSSSSFSSSSSSSSSSSSSSSSFSFSSSSSSSSSSSSSSSSSSFS",
"output": "NO"
},
{
"input": "100\nSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSS",
"output": "NO"
},
{
"input": "100\nSFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF",
"output": "YES"
},
{
"input": "100\nSFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFSFSFFFFFFFFFFFSFSFFFFFFFFFFFFFSFFFFFFFFFFFFFFFFFFFFFFFFF",
"output": "YES"
},
{
"input": "100\nSFFFFFFFFFFFFSSFFFFSFFFFFFFFFFFFFFFFFFFSFFFSSFFFFSFSFFFSFFFFFFFFFFFFFFFSSFFFFFFFFSSFFFFFFFFFFFFFFSFF",
"output": "YES"
},
{
"input": "100\nSFFSSSFFSFSFSFFFFSSFFFFSFFFFFFFFSFSFFFSFFFSFFFSFFFFSFSFFFFFFFSFFFFFFFFFFSFFSSSFFSSFFFFSFFFFSFFFFSFFF",
"output": "YES"
},
{
"input": "100\nSFFFSFFFFSFFFSSFFFSFSFFFSFFFSSFSFFFFFSFFFFFFFFSFSFSFFSFFFSFSSFSFFFSFSFFSSFSFSSSFFFFFFSSFSFFSFFFFFFFF",
"output": "YES"
},
{
"input": "100\nSSSSFFFFSFFFFFFFSFFFFSFSFFFFSSFFFFFFFFFSFFSSFFFFFFSFSFSSFSSSFFFFFFFSFSFFFSSSFFFFFFFSFFFSSFFFFSSFFFSF",
"output": "YES"
},
{
"input": "100\nSSSFSSFFFSFSSSSFSSFSSSSFSSFFFFFSFFSSSSFFSSSFSSSFSSSSFSSSSFSSSSSSSFSFSSFFFSSFFSFFSSSSFSSFFSFSSFSFFFSF",
"output": "YES"
},
{
"input": "100\nSFFSFSSSSSSSFFSSSFSSSSFSFSSFFFSSSSSSFSSSSFSSFSSSFSSSSSSSFSSFSFFFSSFSSFSFSFSSSSSSSSSSSSFFFFSSSSSFSFFF",
"output": "YES"
},
{
"input": "100\nSSSFSFFSFSFFSSSSSFSSSFSSSFFFSSSSSSSSSFSFSFSSSSFSFSSFFFFFSSSSSSSSSSSSSSSSSSSFFSSSSSFSFSSSSFFSSSSFSSSF",
"output": "YES"
},
{
"input": "100\nSSSFSSSSSSSSSSFSSSSFSSSSSSFSSSSSSFSSSSSSSSSSSSSSFSSSFSSSFSSSSSSSSSSSFSSSSSSFSFSSSSFSSSSSSFSSSSSSSSFF",
"output": "YES"
},
{
"input": "100\nSSSSSSSSSSSSSSSFSFSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSFFSSSSSSSSSFSSSSSSSSSSSSSSSSSF",
"output": "YES"
},
{
"input": "100\nSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSF",
"output": "YES"
},
{
"input": "2\nSS",
"output": "NO"
}
] | 1,550,339,259 | 2,147,483,647 | Python 3 | OK | TESTS | 34 | 109 | 0 | n=int(input())
t=input()
if t.count('SF')>t.count('FS'):
print('YES')
else:
print('NO')
| Title: Between the Offices
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
As you may know, MemSQL has American offices in both San Francisco and Seattle. Being a manager in the company, you travel a lot between the two cities, always by plane.
You prefer flying from Seattle to San Francisco than in the other direction, because it's warmer in San Francisco. You are so busy that you don't remember the number of flights you have made in either direction. However, for each of the last *n* days you know whether you were in San Francisco office or in Seattle office. You always fly at nights, so you never were at both offices on the same day. Given this information, determine if you flew more times from Seattle to San Francisco during the last *n* days, or not.
Input Specification:
The first line of input contains single integer *n* (2<=≤<=*n*<=≤<=100) — the number of days.
The second line contains a string of length *n* consisting of only capital 'S' and 'F' letters. If the *i*-th letter is 'S', then you were in Seattle office on that day. Otherwise you were in San Francisco. The days are given in chronological order, i.e. today is the last day in this sequence.
Output Specification:
Print "YES" if you flew more times from Seattle to San Francisco, and "NO" otherwise.
You can print each letter in any case (upper or lower).
Demo Input:
['4\nFSSF\n', '2\nSF\n', '10\nFFFFFFFFFF\n', '10\nSSFFSFFSFF\n']
Demo Output:
['NO\n', 'YES\n', 'NO\n', 'YES\n']
Note:
In the first example you were initially at San Francisco, then flew to Seattle, were there for two days and returned to San Francisco. You made one flight in each direction, so the answer is "NO".
In the second example you just flew from Seattle to San Francisco, so the answer is "YES".
In the third example you stayed the whole period in San Francisco, so the answer is "NO".
In the fourth example if you replace 'S' with ones, and 'F' with zeros, you'll get the first few digits of π in binary representation. Not very useful information though. | ```python
n=int(input())
t=input()
if t.count('SF')>t.count('FS'):
print('YES')
else:
print('NO')
``` | 3 |
|
248 | A | Cupboards | PROGRAMMING | 800 | [
"implementation"
] | null | null | One foggy Stockholm morning, Karlsson decided to snack on some jam in his friend Lillebror Svantenson's house. Fortunately for Karlsson, there wasn't anybody in his friend's house. Karlsson was not going to be hungry any longer, so he decided to get some food in the house.
Karlsson's gaze immediately fell on *n* wooden cupboards, standing in the kitchen. He immediately realized that these cupboards have hidden jam stocks. Karlsson began to fly greedily around the kitchen, opening and closing the cupboards' doors, grab and empty all the jars of jam that he could find.
And now all jars of jam are empty, Karlsson has had enough and does not want to leave traces of his stay, so as not to let down his friend. Each of the cupboards has two doors: the left one and the right one. Karlsson remembers that when he rushed to the kitchen, all the cupboards' left doors were in the same position (open or closed), similarly, all the cupboards' right doors were in the same position (open or closed). Karlsson wants the doors to meet this condition as well by the time the family returns. Karlsson does not remember the position of all the left doors, also, he cannot remember the position of all the right doors. Therefore, it does not matter to him in what position will be all left or right doors. It is important to leave all the left doors in the same position, and all the right doors in the same position. For example, all the left doors may be closed, and all the right ones may be open.
Karlsson needs one second to open or close a door of a cupboard. He understands that he has very little time before the family returns, so he wants to know the minimum number of seconds *t*, in which he is able to bring all the cupboard doors in the required position.
Your task is to write a program that will determine the required number of seconds *t*. | The first input line contains a single integer *n* — the number of cupboards in the kitchen (2<=≤<=*n*<=≤<=104). Then follow *n* lines, each containing two integers *l**i* and *r**i* (0<=≤<=*l**i*,<=*r**i*<=≤<=1). Number *l**i* equals one, if the left door of the *i*-th cupboard is opened, otherwise number *l**i* equals zero. Similarly, number *r**i* equals one, if the right door of the *i*-th cupboard is opened, otherwise number *r**i* equals zero.
The numbers in the lines are separated by single spaces. | In the only output line print a single integer *t* — the minimum number of seconds Karlsson needs to change the doors of all cupboards to the position he needs. | [
"5\n0 1\n1 0\n0 1\n1 1\n0 1\n"
] | [
"3\n"
] | none | 500 | [
{
"input": "5\n0 1\n1 0\n0 1\n1 1\n0 1",
"output": "3"
},
{
"input": "2\n0 0\n0 0",
"output": "0"
},
{
"input": "3\n0 1\n1 1\n1 1",
"output": "1"
},
{
"input": "8\n0 1\n1 0\n0 1\n1 1\n0 1\n1 0\n0 1\n1 0",
"output": "7"
},
{
"input": "8\n1 0\n1 0\n1 0\n0 1\n0 1\n1 1\n1 1\n0 1",
"output": "6"
},
{
"input": "15\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0",
"output": "0"
},
{
"input": "5\n1 0\n1 0\n1 0\n0 1\n0 1",
"output": "4"
}
] | 1,591,874,980 | 2,147,483,647 | Python 3 | OK | TESTS | 57 | 280 | 204,800 | #ashu@gate22
n=int(input())
x=y=0
for i in range(n):
l1=[int(i) for i in input().split()]
x+=l1[0]
y+=l1[1]
res=min(x,(n-x))+min(y,(n-y))
print(res)
| Title: Cupboards
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
One foggy Stockholm morning, Karlsson decided to snack on some jam in his friend Lillebror Svantenson's house. Fortunately for Karlsson, there wasn't anybody in his friend's house. Karlsson was not going to be hungry any longer, so he decided to get some food in the house.
Karlsson's gaze immediately fell on *n* wooden cupboards, standing in the kitchen. He immediately realized that these cupboards have hidden jam stocks. Karlsson began to fly greedily around the kitchen, opening and closing the cupboards' doors, grab and empty all the jars of jam that he could find.
And now all jars of jam are empty, Karlsson has had enough and does not want to leave traces of his stay, so as not to let down his friend. Each of the cupboards has two doors: the left one and the right one. Karlsson remembers that when he rushed to the kitchen, all the cupboards' left doors were in the same position (open or closed), similarly, all the cupboards' right doors were in the same position (open or closed). Karlsson wants the doors to meet this condition as well by the time the family returns. Karlsson does not remember the position of all the left doors, also, he cannot remember the position of all the right doors. Therefore, it does not matter to him in what position will be all left or right doors. It is important to leave all the left doors in the same position, and all the right doors in the same position. For example, all the left doors may be closed, and all the right ones may be open.
Karlsson needs one second to open or close a door of a cupboard. He understands that he has very little time before the family returns, so he wants to know the minimum number of seconds *t*, in which he is able to bring all the cupboard doors in the required position.
Your task is to write a program that will determine the required number of seconds *t*.
Input Specification:
The first input line contains a single integer *n* — the number of cupboards in the kitchen (2<=≤<=*n*<=≤<=104). Then follow *n* lines, each containing two integers *l**i* and *r**i* (0<=≤<=*l**i*,<=*r**i*<=≤<=1). Number *l**i* equals one, if the left door of the *i*-th cupboard is opened, otherwise number *l**i* equals zero. Similarly, number *r**i* equals one, if the right door of the *i*-th cupboard is opened, otherwise number *r**i* equals zero.
The numbers in the lines are separated by single spaces.
Output Specification:
In the only output line print a single integer *t* — the minimum number of seconds Karlsson needs to change the doors of all cupboards to the position he needs.
Demo Input:
['5\n0 1\n1 0\n0 1\n1 1\n0 1\n']
Demo Output:
['3\n']
Note:
none | ```python
#ashu@gate22
n=int(input())
x=y=0
for i in range(n):
l1=[int(i) for i in input().split()]
x+=l1[0]
y+=l1[1]
res=min(x,(n-x))+min(y,(n-y))
print(res)
``` | 3 |
|
946 | B | Weird Subtraction Process | PROGRAMMING | 1,100 | [
"math",
"number theory"
] | null | null | You have two variables *a* and *b*. Consider the following sequence of actions performed with these variables:
1. If *a*<==<=0 or *b*<==<=0, end the process. Otherwise, go to step 2;1. If *a*<=≥<=2·*b*, then set the value of *a* to *a*<=-<=2·*b*, and repeat step 1. Otherwise, go to step 3;1. If *b*<=≥<=2·*a*, then set the value of *b* to *b*<=-<=2·*a*, and repeat step 1. Otherwise, end the process.
Initially the values of *a* and *b* are positive integers, and so the process will be finite.
You have to determine the values of *a* and *b* after the process ends. | The only line of the input contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=1018). *n* is the initial value of variable *a*, and *m* is the initial value of variable *b*. | Print two integers — the values of *a* and *b* after the end of the process. | [
"12 5\n",
"31 12\n"
] | [
"0 1\n",
"7 12\n"
] | Explanations to the samples:
1. *a* = 12, *b* = 5 <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> *a* = 2, *b* = 5 <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> *a* = 2, *b* = 1 <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> *a* = 0, *b* = 1;1. *a* = 31, *b* = 12 <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> *a* = 7, *b* = 12. | 0 | [
{
"input": "12 5",
"output": "0 1"
},
{
"input": "31 12",
"output": "7 12"
},
{
"input": "1000000000000000000 7",
"output": "8 7"
},
{
"input": "31960284556200 8515664064180",
"output": "14928956427840 8515664064180"
},
{
"input": "1000000000000000000 1000000000000000000",
"output": "1000000000000000000 1000000000000000000"
},
{
"input": "1 1000",
"output": "1 0"
},
{
"input": "1 1000000",
"output": "1 0"
},
{
"input": "1 1000000000000000",
"output": "1 0"
},
{
"input": "1 99999999999999999",
"output": "1 1"
},
{
"input": "1 4",
"output": "1 0"
},
{
"input": "1000000000000001 500000000000000",
"output": "1 0"
},
{
"input": "1 1000000000000000000",
"output": "1 0"
},
{
"input": "2 4",
"output": "2 0"
},
{
"input": "2 1",
"output": "0 1"
},
{
"input": "6 19",
"output": "6 7"
},
{
"input": "22 5",
"output": "0 1"
},
{
"input": "10000000000000000 100000000000000001",
"output": "0 1"
},
{
"input": "1 1000000000000",
"output": "1 0"
},
{
"input": "2 1000000000000000",
"output": "2 0"
},
{
"input": "2 10",
"output": "2 2"
},
{
"input": "51 100",
"output": "51 100"
},
{
"input": "3 1000000000000000000",
"output": "3 4"
},
{
"input": "1000000000000000000 3",
"output": "4 3"
},
{
"input": "1 10000000000000000",
"output": "1 0"
},
{
"input": "8796203 7556",
"output": "1019 1442"
},
{
"input": "5 22",
"output": "1 0"
},
{
"input": "1000000000000000000 1",
"output": "0 1"
},
{
"input": "1 100000000000",
"output": "1 0"
},
{
"input": "2 1000000000000",
"output": "2 0"
},
{
"input": "5 4567865432345678",
"output": "5 8"
},
{
"input": "576460752303423487 288230376151711743",
"output": "1 1"
},
{
"input": "499999999999999999 1000000000000000000",
"output": "3 2"
},
{
"input": "1 9999999999999",
"output": "1 1"
},
{
"input": "103 1000000000000000000",
"output": "103 196"
},
{
"input": "7 1",
"output": "1 1"
},
{
"input": "100000000000000001 10000000000000000",
"output": "1 0"
},
{
"input": "5 10",
"output": "5 0"
},
{
"input": "7 11",
"output": "7 11"
},
{
"input": "1 123456789123456",
"output": "1 0"
},
{
"input": "5000000000000 100000000000001",
"output": "0 1"
},
{
"input": "1000000000000000 1",
"output": "0 1"
},
{
"input": "1000000000000000000 499999999999999999",
"output": "2 3"
},
{
"input": "10 5",
"output": "0 5"
},
{
"input": "9 18917827189272",
"output": "9 0"
},
{
"input": "179 100000000000497000",
"output": "179 270"
},
{
"input": "5 100000000000001",
"output": "1 1"
},
{
"input": "5 20",
"output": "5 0"
},
{
"input": "100000001 50000000",
"output": "1 0"
},
{
"input": "345869461223138161 835002744095575440",
"output": "1 0"
},
{
"input": "8589934592 4294967296",
"output": "0 4294967296"
},
{
"input": "4 8",
"output": "4 0"
},
{
"input": "1 100000000000000000",
"output": "1 0"
},
{
"input": "1000000000000000000 333333333333333",
"output": "1000 1333"
},
{
"input": "25 12",
"output": "1 0"
},
{
"input": "24 54",
"output": "0 6"
},
{
"input": "6 12",
"output": "6 0"
},
{
"input": "129200000000305 547300000001292",
"output": "1 0"
},
{
"input": "1000000000000000000 49999999999999999",
"output": "20 39"
},
{
"input": "1 2",
"output": "1 0"
},
{
"input": "1 123456789876",
"output": "1 0"
},
{
"input": "2 3",
"output": "2 3"
},
{
"input": "1 3",
"output": "1 1"
},
{
"input": "1 1",
"output": "1 1"
},
{
"input": "19 46",
"output": "3 2"
},
{
"input": "3 6",
"output": "3 0"
},
{
"input": "129 1000000000000000000",
"output": "1 0"
},
{
"input": "12 29",
"output": "0 1"
},
{
"input": "8589934592 2147483648",
"output": "0 2147483648"
},
{
"input": "2147483648 8589934592",
"output": "2147483648 0"
},
{
"input": "5 6",
"output": "5 6"
},
{
"input": "1000000000000000000 2",
"output": "0 2"
},
{
"input": "2 7",
"output": "2 3"
},
{
"input": "17174219820754872 61797504734333370",
"output": "17174219820754872 27449065092823626"
},
{
"input": "49 100",
"output": "1 0"
},
{
"input": "7 17",
"output": "1 1"
},
{
"input": "1000000000000000000 10000001",
"output": "0 1"
},
{
"input": "49999999999999999 2",
"output": "3 2"
},
{
"input": "49999999999999999 1",
"output": "1 1"
},
{
"input": "576460752303423487 2",
"output": "3 2"
},
{
"input": "19395 19395",
"output": "19395 19395"
},
{
"input": "19394 19394",
"output": "19394 19394"
}
] | 1,612,357,612 | 2,147,483,647 | Python 3 | OK | TESTS | 81 | 77 | 307,200 | n,m = map(int, input().strip().split(' '))
if n>=2*m or m>=2*n:
while(n>=2*m or m>=2*n):
if n==0 or m==0:
break
if m>n:
k=m//(n*2)
m-=k*(n*2)
elif n>m:
k=n//(m*2)
n-=k*(m*2)
#print(n,m,end=" ")
print(n,m,end=" ")
else:
print(n,m,end=" ") | Title: Weird Subtraction Process
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You have two variables *a* and *b*. Consider the following sequence of actions performed with these variables:
1. If *a*<==<=0 or *b*<==<=0, end the process. Otherwise, go to step 2;1. If *a*<=≥<=2·*b*, then set the value of *a* to *a*<=-<=2·*b*, and repeat step 1. Otherwise, go to step 3;1. If *b*<=≥<=2·*a*, then set the value of *b* to *b*<=-<=2·*a*, and repeat step 1. Otherwise, end the process.
Initially the values of *a* and *b* are positive integers, and so the process will be finite.
You have to determine the values of *a* and *b* after the process ends.
Input Specification:
The only line of the input contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=1018). *n* is the initial value of variable *a*, and *m* is the initial value of variable *b*.
Output Specification:
Print two integers — the values of *a* and *b* after the end of the process.
Demo Input:
['12 5\n', '31 12\n']
Demo Output:
['0 1\n', '7 12\n']
Note:
Explanations to the samples:
1. *a* = 12, *b* = 5 <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> *a* = 2, *b* = 5 <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> *a* = 2, *b* = 1 <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> *a* = 0, *b* = 1;1. *a* = 31, *b* = 12 <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> *a* = 7, *b* = 12. | ```python
n,m = map(int, input().strip().split(' '))
if n>=2*m or m>=2*n:
while(n>=2*m or m>=2*n):
if n==0 or m==0:
break
if m>n:
k=m//(n*2)
m-=k*(n*2)
elif n>m:
k=n//(m*2)
n-=k*(m*2)
#print(n,m,end=" ")
print(n,m,end=" ")
else:
print(n,m,end=" ")
``` | 3 |
|
448 | A | Rewards | PROGRAMMING | 800 | [
"implementation"
] | null | null | Bizon the Champion is called the Champion for a reason.
Bizon the Champion has recently got a present — a new glass cupboard with *n* shelves and he decided to put all his presents there. All the presents can be divided into two types: medals and cups. Bizon the Champion has *a*1 first prize cups, *a*2 second prize cups and *a*3 third prize cups. Besides, he has *b*1 first prize medals, *b*2 second prize medals and *b*3 third prize medals.
Naturally, the rewards in the cupboard must look good, that's why Bizon the Champion decided to follow the rules:
- any shelf cannot contain both cups and medals at the same time; - no shelf can contain more than five cups; - no shelf can have more than ten medals.
Help Bizon the Champion find out if we can put all the rewards so that all the conditions are fulfilled. | The first line contains integers *a*1, *a*2 and *a*3 (0<=≤<=*a*1,<=*a*2,<=*a*3<=≤<=100). The second line contains integers *b*1, *b*2 and *b*3 (0<=≤<=*b*1,<=*b*2,<=*b*3<=≤<=100). The third line contains integer *n* (1<=≤<=*n*<=≤<=100).
The numbers in the lines are separated by single spaces. | Print "YES" (without the quotes) if all the rewards can be put on the shelves in the described manner. Otherwise, print "NO" (without the quotes). | [
"1 1 1\n1 1 1\n4\n",
"1 1 3\n2 3 4\n2\n",
"1 0 0\n1 0 0\n1\n"
] | [
"YES\n",
"YES\n",
"NO\n"
] | none | 500 | [
{
"input": "1 1 1\n1 1 1\n4",
"output": "YES"
},
{
"input": "1 1 3\n2 3 4\n2",
"output": "YES"
},
{
"input": "1 0 0\n1 0 0\n1",
"output": "NO"
},
{
"input": "0 0 0\n0 0 0\n1",
"output": "YES"
},
{
"input": "100 100 100\n100 100 100\n100",
"output": "YES"
},
{
"input": "100 100 100\n100 100 100\n1",
"output": "NO"
},
{
"input": "1 10 100\n100 10 1\n20",
"output": "NO"
},
{
"input": "1 1 1\n0 0 0\n1",
"output": "YES"
},
{
"input": "0 0 0\n1 1 1\n1",
"output": "YES"
},
{
"input": "5 5 5\n0 0 0\n2",
"output": "NO"
},
{
"input": "0 0 0\n10 10 10\n2",
"output": "NO"
},
{
"input": "21 61 39\n63 58 69\n44",
"output": "YES"
},
{
"input": "18 95 4\n7 1 75\n46",
"output": "YES"
},
{
"input": "64 27 81\n72 35 23\n48",
"output": "YES"
},
{
"input": "6 6 6\n11 11 11\n7",
"output": "NO"
},
{
"input": "1 2 3\n2 4 6\n3",
"output": "NO"
},
{
"input": "1 2 3\n2 4 6\n4",
"output": "YES"
},
{
"input": "99 99 99\n99 99 99\n89",
"output": "NO"
},
{
"input": "5 0 0\n15 0 0\n2",
"output": "NO"
},
{
"input": "10 10 10\n0 0 0\n1",
"output": "NO"
},
{
"input": "1 1 1\n1 1 1\n15",
"output": "YES"
},
{
"input": "2 3 5\n2 3 5\n2",
"output": "NO"
},
{
"input": "2 2 2\n3 3 5\n3",
"output": "NO"
},
{
"input": "1 2 2\n2 4 4\n1",
"output": "NO"
},
{
"input": "1 2 3\n1 5 5\n2",
"output": "NO"
}
] | 1,674,798,783 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 3 | 31 | 0 | a1, a2, a3 = map(int, input().split())
b1, b2, b3 = map(int, input().split())
n = int(input())
cups = a1 + a2 + a3
medals = b1 + b2 + b3
selves = 0
if cups > 5:
if cups % 5: selves += (cups // 5) + 1
else: selves += (cups // 5)
else:
selves += 1
if medals > 10:
if medals % 10: selves += (medals // 10) + 1
else: selves += (medals // 10)
else:
selves += 1
if n < selves:
print('NO')
else:
print('YES')
| Title: Rewards
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Bizon the Champion is called the Champion for a reason.
Bizon the Champion has recently got a present — a new glass cupboard with *n* shelves and he decided to put all his presents there. All the presents can be divided into two types: medals and cups. Bizon the Champion has *a*1 first prize cups, *a*2 second prize cups and *a*3 third prize cups. Besides, he has *b*1 first prize medals, *b*2 second prize medals and *b*3 third prize medals.
Naturally, the rewards in the cupboard must look good, that's why Bizon the Champion decided to follow the rules:
- any shelf cannot contain both cups and medals at the same time; - no shelf can contain more than five cups; - no shelf can have more than ten medals.
Help Bizon the Champion find out if we can put all the rewards so that all the conditions are fulfilled.
Input Specification:
The first line contains integers *a*1, *a*2 and *a*3 (0<=≤<=*a*1,<=*a*2,<=*a*3<=≤<=100). The second line contains integers *b*1, *b*2 and *b*3 (0<=≤<=*b*1,<=*b*2,<=*b*3<=≤<=100). The third line contains integer *n* (1<=≤<=*n*<=≤<=100).
The numbers in the lines are separated by single spaces.
Output Specification:
Print "YES" (without the quotes) if all the rewards can be put on the shelves in the described manner. Otherwise, print "NO" (without the quotes).
Demo Input:
['1 1 1\n1 1 1\n4\n', '1 1 3\n2 3 4\n2\n', '1 0 0\n1 0 0\n1\n']
Demo Output:
['YES\n', 'YES\n', 'NO\n']
Note:
none | ```python
a1, a2, a3 = map(int, input().split())
b1, b2, b3 = map(int, input().split())
n = int(input())
cups = a1 + a2 + a3
medals = b1 + b2 + b3
selves = 0
if cups > 5:
if cups % 5: selves += (cups // 5) + 1
else: selves += (cups // 5)
else:
selves += 1
if medals > 10:
if medals % 10: selves += (medals // 10) + 1
else: selves += (medals // 10)
else:
selves += 1
if n < selves:
print('NO')
else:
print('YES')
``` | 0 |
|
909 | C | Python Indentation | PROGRAMMING | 1,800 | [
"dp"
] | null | null | In Python, code blocks don't have explicit begin/end or curly braces to mark beginning and end of the block. Instead, code blocks are defined by indentation.
We will consider an extremely simplified subset of Python with only two types of statements.
Simple statements are written in a single line, one per line. An example of a simple statement is assignment.
For statements are compound statements: they contain one or several other statements. For statement consists of a header written in a separate line which starts with "for" prefix, and loop body. Loop body is a block of statements indented one level further than the header of the loop. Loop body can contain both types of statements. Loop body can't be empty.
You are given a sequence of statements without indentation. Find the number of ways in which the statements can be indented to form a valid Python program. | The first line contains a single integer *N* (1<=≤<=*N*<=≤<=5000) — the number of commands in the program. *N* lines of the program follow, each line describing a single command. Each command is either "f" (denoting "for statement") or "s" ("simple statement"). It is guaranteed that the last line is a simple statement. | Output one line containing an integer - the number of ways the given sequence of statements can be indented modulo 109<=+<=7. | [
"4\ns\nf\nf\ns\n",
"4\nf\ns\nf\ns\n"
] | [
"1\n",
"2\n"
] | In the first test case, there is only one way to indent the program: the second for statement must be part of the body of the first one.
In the second test case, there are two ways to indent the program: the second for statement can either be part of the first one's body or a separate statement following the first one.
or | 1,500 | [
{
"input": "4\ns\nf\nf\ns",
"output": "1"
},
{
"input": "4\nf\ns\nf\ns",
"output": "2"
},
{
"input": "156\nf\ns\nf\ns\nf\ns\ns\ns\ns\nf\ns\ns\nf\nf\ns\nf\nf\nf\nf\ns\ns\ns\nf\ns\ns\nf\nf\nf\nf\nf\nf\ns\ns\ns\ns\nf\ns\nf\ns\nf\ns\nf\nf\nf\nf\ns\ns\nf\nf\ns\ns\ns\ns\nf\ns\nf\ns\nf\ns\nf\ns\ns\ns\nf\ns\ns\nf\ns\nf\nf\ns\ns\ns\nf\nf\nf\nf\ns\ns\nf\nf\nf\nf\nf\nf\nf\ns\nf\ns\ns\ns\nf\nf\ns\ns\ns\ns\ns\nf\nf\nf\nf\ns\nf\nf\ns\nf\ns\ns\nf\nf\nf\ns\ns\ns\nf\ns\ns\nf\ns\nf\nf\nf\ns\nf\nf\ns\ns\nf\ns\nf\nf\ns\ns\ns\ns\nf\ns\nf\nf\ns\ns\nf\nf\nf\ns\ns\nf\nf\nf\ns\nf\ns\nf\nf\ns",
"output": "666443222"
},
{
"input": "4\nf\nf\ns\ns",
"output": "3"
},
{
"input": "2\nf\ns",
"output": "1"
},
{
"input": "1\ns",
"output": "1"
},
{
"input": "3\nf\nf\ns",
"output": "1"
},
{
"input": "2\ns\ns",
"output": "1"
},
{
"input": "156\ns\nf\ns\ns\ns\ns\nf\ns\ns\ns\nf\nf\ns\nf\nf\ns\nf\nf\nf\ns\nf\nf\ns\nf\nf\ns\ns\nf\nf\ns\nf\nf\nf\nf\nf\ns\ns\nf\ns\nf\nf\nf\ns\nf\nf\nf\ns\ns\ns\nf\ns\ns\nf\nf\ns\ns\nf\ns\nf\nf\ns\nf\nf\nf\ns\ns\nf\nf\ns\nf\ns\ns\ns\ns\ns\ns\ns\nf\ns\nf\nf\nf\ns\ns\ns\ns\nf\nf\ns\nf\nf\ns\ns\nf\ns\nf\ns\ns\nf\nf\nf\nf\nf\ns\nf\ns\ns\nf\nf\ns\nf\nf\ns\ns\ns\nf\ns\ns\ns\ns\nf\nf\ns\nf\nf\nf\nf\ns\nf\ns\ns\nf\nf\ns\nf\ns\nf\nf\nf\nf\ns\ns\nf\nf\nf\nf\ns\nf\ns\nf\ns\ns\ns\nf\nf\ns",
"output": "479461584"
},
{
"input": "66\ns\nf\ns\ns\nf\ns\ns\ns\ns\nf\ns\ns\nf\nf\ns\ns\nf\ns\ns\nf\ns\ns\nf\nf\ns\ns\nf\nf\ns\ns\nf\ns\ns\ns\ns\nf\nf\ns\ns\nf\nf\ns\ns\nf\ns\ns\nf\ns\ns\nf\ns\ns\nf\nf\ns\nf\ns\ns\nf\nf\ns\nf\ns\nf\nf\ns",
"output": "392847498"
}
] | 1,514,396,430 | 3,930 | Python 3 | WRONG_ANSWER | PRETESTS | 2 | 46 | 5,529,600 |
# coding: utf-8
# In[3]:
n = int(input())
k = 1
pr = 's'
f = 1
for i in range(n):
c = input()
if c == 's':
k = k * f
if pr == 'f':
f += 1
pr = c
print(k)
| Title: Python Indentation
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
In Python, code blocks don't have explicit begin/end or curly braces to mark beginning and end of the block. Instead, code blocks are defined by indentation.
We will consider an extremely simplified subset of Python with only two types of statements.
Simple statements are written in a single line, one per line. An example of a simple statement is assignment.
For statements are compound statements: they contain one or several other statements. For statement consists of a header written in a separate line which starts with "for" prefix, and loop body. Loop body is a block of statements indented one level further than the header of the loop. Loop body can contain both types of statements. Loop body can't be empty.
You are given a sequence of statements without indentation. Find the number of ways in which the statements can be indented to form a valid Python program.
Input Specification:
The first line contains a single integer *N* (1<=≤<=*N*<=≤<=5000) — the number of commands in the program. *N* lines of the program follow, each line describing a single command. Each command is either "f" (denoting "for statement") or "s" ("simple statement"). It is guaranteed that the last line is a simple statement.
Output Specification:
Output one line containing an integer - the number of ways the given sequence of statements can be indented modulo 109<=+<=7.
Demo Input:
['4\ns\nf\nf\ns\n', '4\nf\ns\nf\ns\n']
Demo Output:
['1\n', '2\n']
Note:
In the first test case, there is only one way to indent the program: the second for statement must be part of the body of the first one.
In the second test case, there are two ways to indent the program: the second for statement can either be part of the first one's body or a separate statement following the first one.
or | ```python
# coding: utf-8
# In[3]:
n = int(input())
k = 1
pr = 's'
f = 1
for i in range(n):
c = input()
if c == 's':
k = k * f
if pr == 'f':
f += 1
pr = c
print(k)
``` | 0 |
|
877 | A | Alex and broken contest | PROGRAMMING | 1,100 | [
"implementation",
"strings"
] | null | null | One day Alex was creating a contest about his friends, but accidentally deleted it. Fortunately, all the problems were saved, but now he needs to find them among other problems.
But there are too many problems, to do it manually. Alex asks you to write a program, which will determine if a problem is from this contest by its name.
It is known, that problem is from this contest if and only if its name contains one of Alex's friends' name exactly once. His friends' names are "Danil", "Olya", "Slava", "Ann" and "Nikita".
Names are case sensitive. | The only line contains string from lowercase and uppercase letters and "_" symbols of length, not more than 100 — the name of the problem. | Print "YES", if problem is from this contest, and "NO" otherwise. | [
"Alex_and_broken_contest\n",
"NikitaAndString\n",
"Danil_and_Olya\n"
] | [
"NO",
"YES",
"NO"
] | none | 500 | [
{
"input": "Alex_and_broken_contest",
"output": "NO"
},
{
"input": "NikitaAndString",
"output": "YES"
},
{
"input": "Danil_and_Olya",
"output": "NO"
},
{
"input": "Slava____and_the_game",
"output": "YES"
},
{
"input": "Olya_and_energy_drinks",
"output": "YES"
},
{
"input": "Danil_and_part_time_job",
"output": "YES"
},
{
"input": "Ann_and_books",
"output": "YES"
},
{
"input": "Olya",
"output": "YES"
},
{
"input": "Nikita",
"output": "YES"
},
{
"input": "Slava",
"output": "YES"
},
{
"input": "Vanya",
"output": "NO"
},
{
"input": "I_dont_know_what_to_write_here",
"output": "NO"
},
{
"input": "danil_and_work",
"output": "NO"
},
{
"input": "Ann",
"output": "YES"
},
{
"input": "Batman_Nananananananan_Batman",
"output": "NO"
},
{
"input": "Olya_Nikita_Ann_Slava_Danil",
"output": "NO"
},
{
"input": "its_me_Mario",
"output": "NO"
},
{
"input": "A",
"output": "NO"
},
{
"input": "Wake_up_Neo",
"output": "NO"
},
{
"input": "Hardest_problem_ever",
"output": "NO"
},
{
"input": "Nikita_Nikita",
"output": "NO"
},
{
"input": "____________________________________________________________________________________________________",
"output": "NO"
},
{
"input": "Nikitb",
"output": "NO"
},
{
"input": "Unn",
"output": "NO"
},
{
"input": "oLya_adn_smth",
"output": "NO"
},
{
"input": "FloorISLava",
"output": "NO"
},
{
"input": "ann",
"output": "NO"
},
{
"input": "aa",
"output": "NO"
},
{
"input": "AAnnnnn",
"output": "YES"
},
{
"input": "AnnAnn",
"output": "NO"
},
{
"input": "Annn",
"output": "YES"
},
{
"input": "Dilzhan",
"output": "NO"
},
{
"input": "Danilaaa",
"output": "YES"
},
{
"input": "AndAnn",
"output": "YES"
},
{
"input": "OlyaAnnAnn",
"output": "NO"
},
{
"input": "DanilDanilOlya",
"output": "NO"
},
{
"input": "DDanil",
"output": "YES"
},
{
"input": "AnnAnnDanil",
"output": "NO"
},
{
"input": "And_Danil",
"output": "YES"
},
{
"input": "abcddddDanil",
"output": "YES"
},
{
"input": "DanilOlyaOlya",
"output": "NO"
},
{
"input": "Nikitaaa",
"output": "YES"
},
{
"input": "aaabbba",
"output": "NO"
},
{
"input": "Ann_Ann_Danil",
"output": "NO"
},
{
"input": "Danil_Danil_Nikita",
"output": "NO"
},
{
"input": "AlexaaaaaaBBBBBOlyaDDDDD",
"output": "YES"
},
{
"input": "IloveDaniland",
"output": "YES"
},
{
"input": "AnAnn",
"output": "YES"
},
{
"input": "Danil_Danil_Olya",
"output": "NO"
},
{
"input": "DanilDanilSlava",
"output": "NO"
},
{
"input": "DanilDanil",
"output": "NO"
},
{
"input": "OlyOlya",
"output": "YES"
},
{
"input": "NikitaNikitb",
"output": "YES"
},
{
"input": "ababaca",
"output": "NO"
},
{
"input": "AnnNikitaNikitaNikitaNikita__good_luck",
"output": "NO"
}
] | 1,629,669,227 | 2,147,483,647 | PyPy 3 | OK | TESTS | 55 | 109 | 20,172,800 | names = ["Danil", "Olya", "Slava", "Ann", "Nikita"]
cont = [0,0,0,0,0]
s = input()
for j in range(5):
cont[j] = s.count(names[j])
if max(cont) == 1 and cont.count(1) == 1:
print("YES")
else:
print("NO") | Title: Alex and broken contest
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
One day Alex was creating a contest about his friends, but accidentally deleted it. Fortunately, all the problems were saved, but now he needs to find them among other problems.
But there are too many problems, to do it manually. Alex asks you to write a program, which will determine if a problem is from this contest by its name.
It is known, that problem is from this contest if and only if its name contains one of Alex's friends' name exactly once. His friends' names are "Danil", "Olya", "Slava", "Ann" and "Nikita".
Names are case sensitive.
Input Specification:
The only line contains string from lowercase and uppercase letters and "_" symbols of length, not more than 100 — the name of the problem.
Output Specification:
Print "YES", if problem is from this contest, and "NO" otherwise.
Demo Input:
['Alex_and_broken_contest\n', 'NikitaAndString\n', 'Danil_and_Olya\n']
Demo Output:
['NO', 'YES', 'NO']
Note:
none | ```python
names = ["Danil", "Olya", "Slava", "Ann", "Nikita"]
cont = [0,0,0,0,0]
s = input()
for j in range(5):
cont[j] = s.count(names[j])
if max(cont) == 1 and cont.count(1) == 1:
print("YES")
else:
print("NO")
``` | 3 |
|
545 | D | Queue | PROGRAMMING | 1,300 | [
"greedy",
"implementation",
"sortings"
] | null | null | Little girl Susie went shopping with her mom and she wondered how to improve service quality.
There are *n* people in the queue. For each person we know time *t**i* needed to serve him. A person will be disappointed if the time he waits is more than the time needed to serve him. The time a person waits is the total time when all the people who stand in the queue in front of him are served. Susie thought that if we swap some people in the queue, then we can decrease the number of people who are disappointed.
Help Susie find out what is the maximum number of not disappointed people can be achieved by swapping people in the queue. | The first line contains integer *n* (1<=≤<=*n*<=≤<=105).
The next line contains *n* integers *t**i* (1<=≤<=*t**i*<=≤<=109), separated by spaces. | Print a single number — the maximum number of not disappointed people in the queue. | [
"5\n15 2 1 5 3\n"
] | [
"4\n"
] | Value 4 is achieved at such an arrangement, for example: 1, 2, 3, 5, 15. Thus, you can make everything feel not disappointed except for the person with time 5. | 1,750 | [
{
"input": "5\n15 2 1 5 3",
"output": "4"
},
{
"input": "15\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1",
"output": "2"
},
{
"input": "10\n13 2 5 55 21 34 1 8 1 3",
"output": "6"
},
{
"input": "10\n8 256 16 1 2 1 64 4 128 32",
"output": "10"
},
{
"input": "10\n10000 40000 10000 50000 20000 100000 10000 100 30000 500",
"output": "6"
},
{
"input": "1\n1000000000",
"output": "1"
},
{
"input": "15\n9 11 45 86 52 65 35 3 93 7 21 45 15 11 39",
"output": "6"
},
{
"input": "20\n16839799 17525904 91276752 42650694 60106463 12243176 54892123 25142243 16015971 41250998 11150057 6994983 67700784 16562412 82163675 46178521 33914268 91966607 93976858 84100064",
"output": "5"
},
{
"input": "26\n1000 4110030 64221 131521030 942374833 1003 2055015 32110 513757 16440130 263042057 32880256 128439 557559573 16051 8220066 469240078 65760513 256878 790176315 4012 2005 1027508 928528684 8030 805074697",
"output": "21"
}
] | 1,681,993,661 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 2 | 62 | 0 | n = int(input())
a = list(map(int, input().split()))
a.sort()
sum = 0
c =0
for i in range(n):
if sum <= a[i]:
c+=1
sum = a[i] + sum
print(c)
| Title: Queue
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Little girl Susie went shopping with her mom and she wondered how to improve service quality.
There are *n* people in the queue. For each person we know time *t**i* needed to serve him. A person will be disappointed if the time he waits is more than the time needed to serve him. The time a person waits is the total time when all the people who stand in the queue in front of him are served. Susie thought that if we swap some people in the queue, then we can decrease the number of people who are disappointed.
Help Susie find out what is the maximum number of not disappointed people can be achieved by swapping people in the queue.
Input Specification:
The first line contains integer *n* (1<=≤<=*n*<=≤<=105).
The next line contains *n* integers *t**i* (1<=≤<=*t**i*<=≤<=109), separated by spaces.
Output Specification:
Print a single number — the maximum number of not disappointed people in the queue.
Demo Input:
['5\n15 2 1 5 3\n']
Demo Output:
['4\n']
Note:
Value 4 is achieved at such an arrangement, for example: 1, 2, 3, 5, 15. Thus, you can make everything feel not disappointed except for the person with time 5. | ```python
n = int(input())
a = list(map(int, input().split()))
a.sort()
sum = 0
c =0
for i in range(n):
if sum <= a[i]:
c+=1
sum = a[i] + sum
print(c)
``` | 0 |
|
149 | A | Business trip | PROGRAMMING | 900 | [
"greedy",
"implementation",
"sortings"
] | null | null | What joy! Petya's parents went on a business trip for the whole year and the playful kid is left all by himself. Petya got absolutely happy. He jumped on the bed and threw pillows all day long, until...
Today Petya opened the cupboard and found a scary note there. His parents had left him with duties: he should water their favourite flower all year, each day, in the morning, in the afternoon and in the evening. "Wait a second!" — thought Petya. He know for a fact that if he fulfills the parents' task in the *i*-th (1<=≤<=*i*<=≤<=12) month of the year, then the flower will grow by *a**i* centimeters, and if he doesn't water the flower in the *i*-th month, then the flower won't grow this month. Petya also knows that try as he might, his parents won't believe that he has been watering the flower if it grows strictly less than by *k* centimeters.
Help Petya choose the minimum number of months when he will water the flower, given that the flower should grow no less than by *k* centimeters. | The first line contains exactly one integer *k* (0<=≤<=*k*<=≤<=100). The next line contains twelve space-separated integers: the *i*-th (1<=≤<=*i*<=≤<=12) number in the line represents *a**i* (0<=≤<=*a**i*<=≤<=100). | Print the only integer — the minimum number of months when Petya has to water the flower so that the flower grows no less than by *k* centimeters. If the flower can't grow by *k* centimeters in a year, print -1. | [
"5\n1 1 1 1 2 2 3 2 2 1 1 1\n",
"0\n0 0 0 0 0 0 0 1 1 2 3 0\n",
"11\n1 1 4 1 1 5 1 1 4 1 1 1\n"
] | [
"2\n",
"0\n",
"3\n"
] | Let's consider the first sample test. There it is enough to water the flower during the seventh and the ninth month. Then the flower grows by exactly five centimeters.
In the second sample Petya's parents will believe him even if the flower doesn't grow at all (*k* = 0). So, it is possible for Petya not to water the flower at all. | 500 | [
{
"input": "5\n1 1 1 1 2 2 3 2 2 1 1 1",
"output": "2"
},
{
"input": "0\n0 0 0 0 0 0 0 1 1 2 3 0",
"output": "0"
},
{
"input": "11\n1 1 4 1 1 5 1 1 4 1 1 1",
"output": "3"
},
{
"input": "15\n20 1 1 1 1 2 2 1 2 2 1 1",
"output": "1"
},
{
"input": "7\n8 9 100 12 14 17 21 10 11 100 23 10",
"output": "1"
},
{
"input": "52\n1 12 3 11 4 5 10 6 9 7 8 2",
"output": "6"
},
{
"input": "50\n2 2 3 4 5 4 4 5 7 3 2 7",
"output": "-1"
},
{
"input": "0\n55 81 28 48 99 20 67 95 6 19 10 93",
"output": "0"
},
{
"input": "93\n85 40 93 66 92 43 61 3 64 51 90 21",
"output": "1"
},
{
"input": "99\n36 34 22 0 0 0 52 12 0 0 33 47",
"output": "2"
},
{
"input": "99\n28 32 31 0 10 35 11 18 0 0 32 28",
"output": "3"
},
{
"input": "99\n19 17 0 1 18 11 29 9 29 22 0 8",
"output": "4"
},
{
"input": "76\n2 16 11 10 12 0 20 4 4 14 11 14",
"output": "5"
},
{
"input": "41\n2 1 7 7 4 2 4 4 9 3 10 0",
"output": "6"
},
{
"input": "47\n8 2 2 4 3 1 9 4 2 7 7 8",
"output": "7"
},
{
"input": "58\n6 11 7 0 5 6 3 9 4 9 5 1",
"output": "8"
},
{
"input": "32\n5 2 4 1 5 0 5 1 4 3 0 3",
"output": "9"
},
{
"input": "31\n6 1 0 4 4 5 1 0 5 3 2 0",
"output": "9"
},
{
"input": "35\n2 3 0 0 6 3 3 4 3 5 0 6",
"output": "9"
},
{
"input": "41\n3 1 3 4 3 6 6 1 4 4 0 6",
"output": "11"
},
{
"input": "97\n0 5 3 12 10 16 22 8 21 17 21 10",
"output": "5"
},
{
"input": "100\n21 21 0 0 4 13 0 26 0 0 0 15",
"output": "6"
},
{
"input": "100\n0 0 16 5 22 0 5 0 25 0 14 13",
"output": "7"
},
{
"input": "97\n17 0 10 0 0 0 18 0 14 23 15 0",
"output": "6"
},
{
"input": "100\n0 9 0 18 7 0 0 14 33 3 0 16",
"output": "7"
},
{
"input": "95\n5 2 13 0 15 18 17 0 6 11 0 8",
"output": "9"
},
{
"input": "94\n11 13 0 9 15 8 8 16 3 7 1 3",
"output": "11"
},
{
"input": "96\n8 4 12 15 8 0 4 10 6 6 12 11",
"output": "11"
},
{
"input": "100\n5 5 3 8 6 5 0 3 3 8 1 3",
"output": "-1"
},
{
"input": "100\n1 0 0 1 1 0 1 1 1 1 2 1",
"output": "-1"
},
{
"input": "100\n6 3 2 0 4 1 2 2 2 2 1 1",
"output": "-1"
},
{
"input": "0\n0 0 0 0 0 0 0 0 0 0 0 0",
"output": "0"
},
{
"input": "100\n0 0 0 0 0 0 0 0 0 0 0 0",
"output": "-1"
},
{
"input": "0\n100 100 100 100 100 100 100 100 100 100 100 100",
"output": "0"
},
{
"input": "100\n100 100 100 100 100 100 100 100 100 100 100 100",
"output": "1"
},
{
"input": "12\n1 1 1 1 1 1 1 1 1 1 1 1",
"output": "12"
},
{
"input": "13\n1 1 1 1 1 1 1 1 1 1 1 2",
"output": "12"
},
{
"input": "15\n10 1 1 1 1 1 1 1 1 1 1 1",
"output": "6"
},
{
"input": "1\n0 0 0 0 0 0 0 0 0 0 0 0",
"output": "-1"
}
] | 1,639,088,538 | 2,147,483,647 | Python 3 | OK | TESTS | 39 | 92 | 0 | k = int(input())
alist = sorted([*map(int, input().split())])
for i, value in enumerate(reversed(alist)):
if k <= 0:
break
k -= value
i += 1
print(i if k <= 0 else "-1") | Title: Business trip
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
What joy! Petya's parents went on a business trip for the whole year and the playful kid is left all by himself. Petya got absolutely happy. He jumped on the bed and threw pillows all day long, until...
Today Petya opened the cupboard and found a scary note there. His parents had left him with duties: he should water their favourite flower all year, each day, in the morning, in the afternoon and in the evening. "Wait a second!" — thought Petya. He know for a fact that if he fulfills the parents' task in the *i*-th (1<=≤<=*i*<=≤<=12) month of the year, then the flower will grow by *a**i* centimeters, and if he doesn't water the flower in the *i*-th month, then the flower won't grow this month. Petya also knows that try as he might, his parents won't believe that he has been watering the flower if it grows strictly less than by *k* centimeters.
Help Petya choose the minimum number of months when he will water the flower, given that the flower should grow no less than by *k* centimeters.
Input Specification:
The first line contains exactly one integer *k* (0<=≤<=*k*<=≤<=100). The next line contains twelve space-separated integers: the *i*-th (1<=≤<=*i*<=≤<=12) number in the line represents *a**i* (0<=≤<=*a**i*<=≤<=100).
Output Specification:
Print the only integer — the minimum number of months when Petya has to water the flower so that the flower grows no less than by *k* centimeters. If the flower can't grow by *k* centimeters in a year, print -1.
Demo Input:
['5\n1 1 1 1 2 2 3 2 2 1 1 1\n', '0\n0 0 0 0 0 0 0 1 1 2 3 0\n', '11\n1 1 4 1 1 5 1 1 4 1 1 1\n']
Demo Output:
['2\n', '0\n', '3\n']
Note:
Let's consider the first sample test. There it is enough to water the flower during the seventh and the ninth month. Then the flower grows by exactly five centimeters.
In the second sample Petya's parents will believe him even if the flower doesn't grow at all (*k* = 0). So, it is possible for Petya not to water the flower at all. | ```python
k = int(input())
alist = sorted([*map(int, input().split())])
for i, value in enumerate(reversed(alist)):
if k <= 0:
break
k -= value
i += 1
print(i if k <= 0 else "-1")
``` | 3 |
|
706 | B | Interesting drink | PROGRAMMING | 1,100 | [
"binary search",
"dp",
"implementation"
] | null | null | Vasiliy likes to rest after a hard work, so you may often meet him in some bar nearby. As all programmers do, he loves the famous drink "Beecola", which can be bought in *n* different shops in the city. It's known that the price of one bottle in the shop *i* is equal to *x**i* coins.
Vasiliy plans to buy his favorite drink for *q* consecutive days. He knows, that on the *i*-th day he will be able to spent *m**i* coins. Now, for each of the days he want to know in how many different shops he can buy a bottle of "Beecola". | The first line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=100<=000) — the number of shops in the city that sell Vasiliy's favourite drink.
The second line contains *n* integers *x**i* (1<=≤<=*x**i*<=≤<=100<=000) — prices of the bottles of the drink in the *i*-th shop.
The third line contains a single integer *q* (1<=≤<=*q*<=≤<=100<=000) — the number of days Vasiliy plans to buy the drink.
Then follow *q* lines each containing one integer *m**i* (1<=≤<=*m**i*<=≤<=109) — the number of coins Vasiliy can spent on the *i*-th day. | Print *q* integers. The *i*-th of them should be equal to the number of shops where Vasiliy will be able to buy a bottle of the drink on the *i*-th day. | [
"5\n3 10 8 6 11\n4\n1\n10\n3\n11\n"
] | [
"0\n4\n1\n5\n"
] | On the first day, Vasiliy won't be able to buy a drink in any of the shops.
On the second day, Vasiliy can buy a drink in the shops 1, 2, 3 and 4.
On the third day, Vasiliy can buy a drink only in the shop number 1.
Finally, on the last day Vasiliy can buy a drink in any shop. | 1,000 | [
{
"input": "5\n3 10 8 6 11\n4\n1\n10\n3\n11",
"output": "0\n4\n1\n5"
},
{
"input": "5\n868 987 714 168 123\n10\n424\n192\n795\n873\n117\n914\n735\n158\n631\n471",
"output": "2\n2\n3\n4\n0\n4\n3\n1\n2\n2"
},
{
"input": "3\n435 482 309\n7\n245\n241\n909\n745\n980\n29\n521",
"output": "0\n0\n3\n3\n3\n0\n3"
},
{
"input": "1\n653\n9\n903\n980\n80\n770\n965\n874\n381\n657\n969",
"output": "1\n1\n0\n1\n1\n1\n0\n1\n1"
},
{
"input": "12\n35345 58181 32223 84621 35905 73863 99537 30666 67771 39229 36847 29038\n23\n55052824\n82504840\n35160556\n78141700\n73401989\n86305919\n39430705\n31939373\n23501765\n4406029\n61436920\n14295390\n34275309\n28028753\n85724689\n70158847\n2396455\n66994588\n84024224\n30175981\n65622319\n76517111\n76605341",
"output": "12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12"
},
{
"input": "4\n698 193 1584 76192\n4\n553640\n310518\n274280\n429192",
"output": "4\n4\n4\n4"
},
{
"input": "1\n1\n1\n1000000000",
"output": "1"
},
{
"input": "1\n1\n1\n100005",
"output": "1"
},
{
"input": "3\n1 2 3\n1\n100005",
"output": "3"
},
{
"input": "2\n1 2\n3\n100004\n100005\n100006",
"output": "2\n2\n2"
},
{
"input": "3\n1 1 1\n1\n1",
"output": "3"
},
{
"input": "1\n1\n1\n1",
"output": "1"
},
{
"input": "3\n1 2 3\n1\n100000",
"output": "3"
},
{
"input": "5\n1 1 1 1 10\n2\n1\n10",
"output": "4\n5"
},
{
"input": "5\n3 10 8 6 11\n1\n10000000",
"output": "5"
}
] | 1,696,961,303 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 103 | 139 | 14,540,800 | import sys
input = sys.stdin.readline
def lower_bound(arr, x):
n = len(arr)
left = -1
right = n
while left + 1 < right:
mid = (left + right)
if x >= arr[mid]:
left = mid
else:
right = mid
return left
def main():
n = int(input().strip())
arr = list(map(int, input().strip().split()))
nn = max(arr) + 1
c = [0] * nn
q = int(input().strip())
for ci in arr:
c[ci] += 1
p = [0] * nn
for i in range(nn - 1):
p[i + 1] = p[i] + c[i + 1]
for _ in range(q):
m = int(input().strip())
if m >= nn - 1:
sys.stdout.write(f'{n}\n')
else:
sys.stdout.write(f'{p[m]}\n')
if __name__ == "__main__":
main()
| Title: Interesting drink
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vasiliy likes to rest after a hard work, so you may often meet him in some bar nearby. As all programmers do, he loves the famous drink "Beecola", which can be bought in *n* different shops in the city. It's known that the price of one bottle in the shop *i* is equal to *x**i* coins.
Vasiliy plans to buy his favorite drink for *q* consecutive days. He knows, that on the *i*-th day he will be able to spent *m**i* coins. Now, for each of the days he want to know in how many different shops he can buy a bottle of "Beecola".
Input Specification:
The first line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=100<=000) — the number of shops in the city that sell Vasiliy's favourite drink.
The second line contains *n* integers *x**i* (1<=≤<=*x**i*<=≤<=100<=000) — prices of the bottles of the drink in the *i*-th shop.
The third line contains a single integer *q* (1<=≤<=*q*<=≤<=100<=000) — the number of days Vasiliy plans to buy the drink.
Then follow *q* lines each containing one integer *m**i* (1<=≤<=*m**i*<=≤<=109) — the number of coins Vasiliy can spent on the *i*-th day.
Output Specification:
Print *q* integers. The *i*-th of them should be equal to the number of shops where Vasiliy will be able to buy a bottle of the drink on the *i*-th day.
Demo Input:
['5\n3 10 8 6 11\n4\n1\n10\n3\n11\n']
Demo Output:
['0\n4\n1\n5\n']
Note:
On the first day, Vasiliy won't be able to buy a drink in any of the shops.
On the second day, Vasiliy can buy a drink in the shops 1, 2, 3 and 4.
On the third day, Vasiliy can buy a drink only in the shop number 1.
Finally, on the last day Vasiliy can buy a drink in any shop. | ```python
import sys
input = sys.stdin.readline
def lower_bound(arr, x):
n = len(arr)
left = -1
right = n
while left + 1 < right:
mid = (left + right)
if x >= arr[mid]:
left = mid
else:
right = mid
return left
def main():
n = int(input().strip())
arr = list(map(int, input().strip().split()))
nn = max(arr) + 1
c = [0] * nn
q = int(input().strip())
for ci in arr:
c[ci] += 1
p = [0] * nn
for i in range(nn - 1):
p[i + 1] = p[i] + c[i + 1]
for _ in range(q):
m = int(input().strip())
if m >= nn - 1:
sys.stdout.write(f'{n}\n')
else:
sys.stdout.write(f'{p[m]}\n')
if __name__ == "__main__":
main()
``` | 3 |
|
137 | A | Postcards and photos | PROGRAMMING | 900 | [
"implementation"
] | null | null | Polycarpus has postcards and photos hung in a row on the wall. He decided to put them away to the closet and hang on the wall a famous painter's picture. Polycarpus does it like that: he goes from the left to the right and removes the objects consecutively. As Polycarpus doesn't want any mix-ups to happen, he will not carry in his hands objects of two different types. In other words, Polycarpus can't carry both postcards and photos simultaneously. Sometimes he goes to the closet and puts the objects there, thus leaving his hands free. Polycarpus must put all the postcards and photos to the closet. He cannot skip objects. What minimum number of times he should visit the closet if he cannot carry more than 5 items? | The only line of the input data contains a non-empty string consisting of letters "С" and "P" whose length does not exceed 100 characters. If the *i*-th character in the string is the letter "С", that means that the *i*-th object (the numbering goes from the left to the right) on Polycarpus' wall is a postcard. And if the *i*-th character is the letter "P", than the *i*-th object on the wall is a photo. | Print the only number — the minimum number of times Polycarpus has to visit the closet. | [
"CPCPCPC\n",
"CCCCCCPPPPPP\n",
"CCCCCCPPCPPPPPPPPPP\n",
"CCCCCCCCCC\n"
] | [
"7\n",
"4\n",
"6\n",
"2\n"
] | In the first sample Polycarpus needs to take one item to the closet 7 times.
In the second sample Polycarpus can first take 3 postcards to the closet; then 3 more. He can take the 6 photos that are left in the similar way, going to the closet twice.
In the third sample Polycarpus can visit the closet twice, both times carrying 3 postcards. Then he can take there 2 photos at once, then one postcard and finally, he can carry the last 10 photos if he visits the closet twice.
In the fourth sample Polycarpus can visit the closet twice and take there all 10 postcards (5 items during each go). | 500 | [
{
"input": "CPCPCPC",
"output": "7"
},
{
"input": "CCCCCCPPPPPP",
"output": "4"
},
{
"input": "CCCCCCPPCPPPPPPPPPP",
"output": "6"
},
{
"input": "CCCCCCCCCC",
"output": "2"
},
{
"input": "CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC",
"output": "20"
},
{
"input": "CPCPCPCPCPCPCPCPCPCPCPCPCPCPCPCPCPCPCPCPCPCPCPCPCPCPCPCPCPCPCPCPCPCPCPCPCPCPCPCPCPCPCPCPCPCPCPCPCPCP",
"output": "100"
},
{
"input": "CCCCCCPPPPPPCCCCCCPPPPPPCCCCCCPPPPPPCCCCCCPPPPPPCCCCCCPPPPPPCCCCCCPPPPPPCCCCCCPPPPPP",
"output": "28"
},
{
"input": "P",
"output": "1"
},
{
"input": "C",
"output": "1"
},
{
"input": "PC",
"output": "2"
},
{
"input": "PPPPP",
"output": "1"
},
{
"input": "PPPP",
"output": "1"
},
{
"input": "CCCCCCCCCC",
"output": "2"
},
{
"input": "CP",
"output": "2"
},
{
"input": "CPCCPCPPPC",
"output": "7"
},
{
"input": "PPCPCCPCPPCCPPPPPPCP",
"output": "12"
},
{
"input": "PCPCCPCPPCCPCPCCPPPPPCPCPCPCCC",
"output": "20"
},
{
"input": "CCPPPPPCPCCPPPCCPPCPCCPCPPCPPCCCPPCPPPCC",
"output": "21"
},
{
"input": "CPPCCCCCCPCCCCPCCPCPPPCPCCCCCCCPCCPPCCCPCCCCCPPCCC",
"output": "23"
},
{
"input": "PPCCCCPPCCPPPCCCCPPPPPCPPPCPPPCCCPCCCPCPPPCPCCCPCCPPCCPPPPPC",
"output": "26"
},
{
"input": "PPCPPCCCCCPCCCPCCPCCCCPPPCCCCPCPCCPCPCPCPPPPCCPPPPPPPCPCPPPCPCPCPCPPPC",
"output": "39"
},
{
"input": "CCPCPPPPCPPPPCCCCPCCPCPCCPPCPCCCPPCCCCPCCCPCPCCPPPCPPPCPCPPPPPCPCCPCCPPCCCPCPPPC",
"output": "43"
},
{
"input": "CCPPCPCPCPPCCCPCPPPCCCCCPCPPCCCPPCPCPPPPCPPCPPPPCCCPCCPCPPPCPCPPCCCPCCCCCCPCCCCPCCPPPPCCPP",
"output": "47"
},
{
"input": "PPCPPPPCCCCPPPPCPPPPPPPPCPCPPCCPPPPPPPPCPPPPCCCCPPPPCPPCPCPPPCCPPCPPCCCPCPPCCCCCCPCPCPCPPCPCPCPPPCCC",
"output": "49"
},
{
"input": "CCPCCCPPCPPCPCCCPCPPCPPCPPCCCCCCCPCPPCPCCPCCPCPCPCCCPCCCPPPCCPCCPPCCCCCPPPPCPCPPCPCPCCPCPPP",
"output": "53"
},
{
"input": "PCPCPPPPCPCPPPCPPCCCPCPCPCPPCPPPPCCPPPCPPPCPPPPCCPPCCCPCCPCCCCPCCPCPPCPCCCPCPPCP",
"output": "47"
},
{
"input": "PCCPPCCCPPCPPCC",
"output": "8"
},
{
"input": "CCCPPPPPPCCCCPCCPCCCCCCPCCCPPPCPC",
"output": "15"
},
{
"input": "CPPCCPPCCPPPCCCPPPPCPPPPPPPCCPCPCCPPPPCCCPPCCPCCPPCCCPCCPCPPPPCCPP",
"output": "31"
},
{
"input": "CCCCCPPPCCPCPCCPPPPCPCCCPCPPCPCPPPPPCCPCPCPC",
"output": "25"
},
{
"input": "PPPPPPPPPCPCP",
"output": "6"
},
{
"input": "PPPCPCPCCCPPCPCCPPPPCCCPCCP",
"output": "15"
},
{
"input": "PCPCCPCPPPPPPCPCCPCPCPCCPPPCPCPCPPCPPCCPCPCCCPCCCPPCPCPCCPCPPPPCCCCCCPPCCPCCCCCPCCCCPPPCPCCCCCPCPCP",
"output": "59"
},
{
"input": "PCCPCPPCCCCCPCCCPCCCPPCCCCCPPPCCPPPPPPPPCPPPCCPPCPPCPCP",
"output": "26"
},
{
"input": "CPCPCCPPPPCCPPCPPCPPCCCCCCPCCPPPCPPCPCCCCCCPCPCCCCCPCCCCCCPCCPPCCP",
"output": "35"
},
{
"input": "PPCCCCCCPP",
"output": "4"
},
{
"input": "CCCCCCCCCCCCPPCCCCPP",
"output": "6"
},
{
"input": "PPPPPPPPPPPCCCCCCCCCCCCCCCCCCP",
"output": "8"
},
{
"input": "PPPPPPPPPPPPPPPPPPPPPCCCCCCCCCCCPPPPCCCC",
"output": "10"
},
{
"input": "PPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPCCCCCCCCCPPPC",
"output": "12"
},
{
"input": "CCCCCCCCCPPPPPPPPPPPPPPPPPPPPCCCCCCCCCCCCCCCCCCCCCCCCPPPPPCC",
"output": "13"
},
{
"input": "CCCCCCCCCCCCCCCCCCCCCCCCCPPPCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC",
"output": "15"
},
{
"input": "CCCCCPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPCCCCCCCCCCCCCPPPPPPPCCPPP",
"output": "18"
},
{
"input": "PPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPCCCCCCCCCCCCCCCCCCCCCCCCCCCPPPPPPPPPPPPPPPPPPP",
"output": "19"
},
{
"input": "PPPPPPPPPPPPPPPPPPPPPPPCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCPPPPPCCCPPPPCCCCCPCC",
"output": "23"
}
] | 1,591,943,781 | 2,147,483,647 | PyPy 3 | OK | TESTS | 45 | 312 | 0 | data = list(input())
data.append('X')
result = 0
cnt = 1
for i in range(1,len(data)):
if data[i]==data[i-1]:
cnt += 1
else:
result += (cnt-1)//5 + 1
cnt = 1
print(result) | Title: Postcards and photos
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Polycarpus has postcards and photos hung in a row on the wall. He decided to put them away to the closet and hang on the wall a famous painter's picture. Polycarpus does it like that: he goes from the left to the right and removes the objects consecutively. As Polycarpus doesn't want any mix-ups to happen, he will not carry in his hands objects of two different types. In other words, Polycarpus can't carry both postcards and photos simultaneously. Sometimes he goes to the closet and puts the objects there, thus leaving his hands free. Polycarpus must put all the postcards and photos to the closet. He cannot skip objects. What minimum number of times he should visit the closet if he cannot carry more than 5 items?
Input Specification:
The only line of the input data contains a non-empty string consisting of letters "С" and "P" whose length does not exceed 100 characters. If the *i*-th character in the string is the letter "С", that means that the *i*-th object (the numbering goes from the left to the right) on Polycarpus' wall is a postcard. And if the *i*-th character is the letter "P", than the *i*-th object on the wall is a photo.
Output Specification:
Print the only number — the minimum number of times Polycarpus has to visit the closet.
Demo Input:
['CPCPCPC\n', 'CCCCCCPPPPPP\n', 'CCCCCCPPCPPPPPPPPPP\n', 'CCCCCCCCCC\n']
Demo Output:
['7\n', '4\n', '6\n', '2\n']
Note:
In the first sample Polycarpus needs to take one item to the closet 7 times.
In the second sample Polycarpus can first take 3 postcards to the closet; then 3 more. He can take the 6 photos that are left in the similar way, going to the closet twice.
In the third sample Polycarpus can visit the closet twice, both times carrying 3 postcards. Then he can take there 2 photos at once, then one postcard and finally, he can carry the last 10 photos if he visits the closet twice.
In the fourth sample Polycarpus can visit the closet twice and take there all 10 postcards (5 items during each go). | ```python
data = list(input())
data.append('X')
result = 0
cnt = 1
for i in range(1,len(data)):
if data[i]==data[i-1]:
cnt += 1
else:
result += (cnt-1)//5 + 1
cnt = 1
print(result)
``` | 3 |
|
374 | B | Inna and Nine | PROGRAMMING | 1,500 | [
"combinatorics",
"greedy"
] | null | null | Inna loves digit 9 very much. That's why she asked Dima to write a small number consisting of nines. But Dima must have misunderstood her and he wrote a very large number *a*, consisting of digits from 1 to 9.
Inna wants to slightly alter the number Dima wrote so that in the end the number contained as many digits nine as possible. In one move, Inna can choose two adjacent digits in a number which sum equals 9 and replace them by a single digit 9.
For instance, Inna can alter number 14545181 like this: 14545181<=→<=1945181<=→<=194519<=→<=19919. Also, she can use this method to transform number 14545181 into number 19991. Inna will not transform it into 149591 as she can get numbers 19919 and 19991 which contain more digits nine.
Dima is a programmer so he wants to find out how many distinct numbers containing as many digits nine as possible Inna can get from the written number. Help him with this challenging task. | The first line of the input contains integer *a* (1<=≤<=*a*<=≤<=10100000). Number *a* doesn't have any zeroes. | In a single line print a single integer — the answer to the problem. It is guaranteed that the answer to the problem doesn't exceed 263<=-<=1.
Please, do not use the %lld specifier to read or write 64-bit integers in С++. It is preferred to use the cin, cout streams or the %I64d specifier. | [
"369727\n",
"123456789987654321\n",
"1\n"
] | [
"2\n",
"1\n",
"1\n"
] | Notes to the samples
In the first sample Inna can get the following numbers: 369727 → 99727 → 9997, 369727 → 99727 → 9979.
In the second sample, Inna can act like this: 123456789987654321 → 12396789987654321 → 1239678998769321. | 1,000 | [
{
"input": "369727",
"output": "2"
},
{
"input": "123456789987654321",
"output": "1"
},
{
"input": "1",
"output": "1"
},
{
"input": "3636363636363454545454543636363636454545452727272727218181818181999111777",
"output": "1512"
},
{
"input": "1188",
"output": "1"
},
{
"input": "121212912121291299129191219",
"output": "1"
},
{
"input": "181818918181891918918181918189181818181891818191818191819189",
"output": "54"
},
{
"input": "12191219121912191219121912191219121912191219121912191219121912191219121912191219121912191219121912191219121912191219121912191219121912191219121912191219121912191219121912191219121912191219121912191219121912191219121912191219121912191219121912191219",
"output": "1"
},
{
"input": "444444444444445444444444454444444444444444444444445544444444444444444444444444444444444444444554444444444444444444444444444444444444445454444444444444444444444444444444444444454444444444444444444444444444444444445444444444444444444444444444444444444444444445444444444444444444444444444444444456666666666666666666663555555555555555888888888882333333312567312389542179415242164512341234213443123412341293412341234123412746129342154796124123459123491238471234213451692341278451234125934",
"output": "96"
},
{
"input": "123456789",
"output": "1"
},
{
"input": "3639272918194549",
"output": "16"
},
{
"input": "1121314151617181921222324252627282931323334353637383941424344454647484951525354556575859616263646566768697172737475767787981828384858687888991929394959696979899",
"output": "256"
},
{
"input": "14545181",
"output": "2"
},
{
"input": "272727272",
"output": "5"
},
{
"input": "1212121217272727121",
"output": "4"
},
{
"input": "1212172727",
"output": "3"
},
{
"input": "181817272727",
"output": "12"
}
] | 1,484,771,502 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 5 | 124 | 4,812,800 | a = input()
ans = 1
lst = 0
for i in range(1, len(a)):
sm = int(a[i]) + int(a[i - 1])
if sm != 9:
if lst > 0 and lst % 2 == 0:
ans *= 2
lst = 0
else:
lst += 1
if lst > 0 and lst % 2 == 0:
ans *= 2
print(ans)
| Title: Inna and Nine
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Inna loves digit 9 very much. That's why she asked Dima to write a small number consisting of nines. But Dima must have misunderstood her and he wrote a very large number *a*, consisting of digits from 1 to 9.
Inna wants to slightly alter the number Dima wrote so that in the end the number contained as many digits nine as possible. In one move, Inna can choose two adjacent digits in a number which sum equals 9 and replace them by a single digit 9.
For instance, Inna can alter number 14545181 like this: 14545181<=→<=1945181<=→<=194519<=→<=19919. Also, she can use this method to transform number 14545181 into number 19991. Inna will not transform it into 149591 as she can get numbers 19919 and 19991 which contain more digits nine.
Dima is a programmer so he wants to find out how many distinct numbers containing as many digits nine as possible Inna can get from the written number. Help him with this challenging task.
Input Specification:
The first line of the input contains integer *a* (1<=≤<=*a*<=≤<=10100000). Number *a* doesn't have any zeroes.
Output Specification:
In a single line print a single integer — the answer to the problem. It is guaranteed that the answer to the problem doesn't exceed 263<=-<=1.
Please, do not use the %lld specifier to read or write 64-bit integers in С++. It is preferred to use the cin, cout streams or the %I64d specifier.
Demo Input:
['369727\n', '123456789987654321\n', '1\n']
Demo Output:
['2\n', '1\n', '1\n']
Note:
Notes to the samples
In the first sample Inna can get the following numbers: 369727 → 99727 → 9997, 369727 → 99727 → 9979.
In the second sample, Inna can act like this: 123456789987654321 → 12396789987654321 → 1239678998769321. | ```python
a = input()
ans = 1
lst = 0
for i in range(1, len(a)):
sm = int(a[i]) + int(a[i - 1])
if sm != 9:
if lst > 0 and lst % 2 == 0:
ans *= 2
lst = 0
else:
lst += 1
if lst > 0 and lst % 2 == 0:
ans *= 2
print(ans)
``` | 0 |
|
298 | B | Sail | PROGRAMMING | 1,200 | [
"brute force",
"greedy",
"implementation"
] | null | null | The polar bears are going fishing. They plan to sail from (*s**x*,<=*s**y*) to (*e**x*,<=*e**y*). However, the boat can only sail by wind. At each second, the wind blows in one of these directions: east, south, west or north. Assume the boat is currently at (*x*,<=*y*).
- If the wind blows to the east, the boat will move to (*x*<=+<=1,<=*y*). - If the wind blows to the south, the boat will move to (*x*,<=*y*<=-<=1). - If the wind blows to the west, the boat will move to (*x*<=-<=1,<=*y*). - If the wind blows to the north, the boat will move to (*x*,<=*y*<=+<=1).
Alternatively, they can hold the boat by the anchor. In this case, the boat stays at (*x*,<=*y*). Given the wind direction for *t* seconds, what is the earliest time they sail to (*e**x*,<=*e**y*)? | The first line contains five integers *t*,<=*s**x*,<=*s**y*,<=*e**x*,<=*e**y* (1<=≤<=*t*<=≤<=105,<=<=-<=109<=≤<=*s**x*,<=*s**y*,<=*e**x*,<=*e**y*<=≤<=109). The starting location and the ending location will be different.
The second line contains *t* characters, the *i*-th character is the wind blowing direction at the *i*-th second. It will be one of the four possibilities: "E" (east), "S" (south), "W" (west) and "N" (north). | If they can reach (*e**x*,<=*e**y*) within *t* seconds, print the earliest time they can achieve it. Otherwise, print "-1" (without quotes). | [
"5 0 0 1 1\nSESNW\n",
"10 5 3 3 6\nNENSWESNEE\n"
] | [
"4\n",
"-1\n"
] | In the first sample, they can stay at seconds 1, 3, and move at seconds 2, 4.
In the second sample, they cannot sail to the destination. | 500 | [
{
"input": "5 0 0 1 1\nSESNW",
"output": "4"
},
{
"input": "10 5 3 3 6\nNENSWESNEE",
"output": "-1"
},
{
"input": "19 -172106364 -468680119 -172106365 -468680119\nSSEEESSSESESWSEESSS",
"output": "13"
},
{
"input": "39 -1000000000 -1000000000 -999999997 -1000000000\nENEENWSWSSWESNSSEESNSESWSWNSWESNENWNWEE",
"output": "4"
},
{
"input": "41 -264908123 -86993764 -264908123 -86993723\nNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN",
"output": "41"
},
{
"input": "34 -1000000000 -1000000000 -999999983 -1000000000\nEEEEESSEWNSSSESWEWSWESEWSEESNEWEEE",
"output": "-1"
},
{
"input": "1 0 0 0 -1\nS",
"output": "1"
},
{
"input": "1 5 5 5 6\nE",
"output": "-1"
},
{
"input": "15 1 1 1 2\nNNNNNNNNNNNNNNN",
"output": "1"
},
{
"input": "11 1 1 1 2\nNNNNNNNNNNN",
"output": "1"
}
] | 1,630,730,962 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 3 | 154 | 20,172,800 | t,sx,sy,ex,ey=map(int,input().split())
s=input()
x,y=ex-sx,ey-sy
if x>=0 and y>=0:
if s.count('N')>=y and s.count('E')>=x :
c=cn=0
for i in range(t):
if s[i]=='N' or s[i]=='E':
c=i+1;cn+=1
if cn==x+y:break
print(c)
else:print(-1)
elif x<=0 and y>=0:
if s.count('N')>=y and s.count('W')>=abs(x) :
c = cn = 0
for i in range(t):
if s[i] == 'N' or s[i] == 'W':
c=i+1;cn+=1
if cn == abs(x) + y: break
print(c)
else:print(-1)
elif x>=0 and y<=0:
if s.count('S')>=abs(y) and s.count('E')>=x :
c = cn = 0
for i in range(t):
if s[i] == 'N' or s[i] == 'E':
c=i+1;cn+=1
if cn == x + abs(y): break
print(c)
else:print(-1)
else:
if s.count('S')>=abs(y) and s.count('W')>=abs(x) :
c = cn = 0
for i in range(t):
if s[i] == 'N' or s[i] == 'E':
c=i+1;cn+=1
if cn == abs(x) + abs(y): break
print(c)
else:print(-1) | Title: Sail
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The polar bears are going fishing. They plan to sail from (*s**x*,<=*s**y*) to (*e**x*,<=*e**y*). However, the boat can only sail by wind. At each second, the wind blows in one of these directions: east, south, west or north. Assume the boat is currently at (*x*,<=*y*).
- If the wind blows to the east, the boat will move to (*x*<=+<=1,<=*y*). - If the wind blows to the south, the boat will move to (*x*,<=*y*<=-<=1). - If the wind blows to the west, the boat will move to (*x*<=-<=1,<=*y*). - If the wind blows to the north, the boat will move to (*x*,<=*y*<=+<=1).
Alternatively, they can hold the boat by the anchor. In this case, the boat stays at (*x*,<=*y*). Given the wind direction for *t* seconds, what is the earliest time they sail to (*e**x*,<=*e**y*)?
Input Specification:
The first line contains five integers *t*,<=*s**x*,<=*s**y*,<=*e**x*,<=*e**y* (1<=≤<=*t*<=≤<=105,<=<=-<=109<=≤<=*s**x*,<=*s**y*,<=*e**x*,<=*e**y*<=≤<=109). The starting location and the ending location will be different.
The second line contains *t* characters, the *i*-th character is the wind blowing direction at the *i*-th second. It will be one of the four possibilities: "E" (east), "S" (south), "W" (west) and "N" (north).
Output Specification:
If they can reach (*e**x*,<=*e**y*) within *t* seconds, print the earliest time they can achieve it. Otherwise, print "-1" (without quotes).
Demo Input:
['5 0 0 1 1\nSESNW\n', '10 5 3 3 6\nNENSWESNEE\n']
Demo Output:
['4\n', '-1\n']
Note:
In the first sample, they can stay at seconds 1, 3, and move at seconds 2, 4.
In the second sample, they cannot sail to the destination. | ```python
t,sx,sy,ex,ey=map(int,input().split())
s=input()
x,y=ex-sx,ey-sy
if x>=0 and y>=0:
if s.count('N')>=y and s.count('E')>=x :
c=cn=0
for i in range(t):
if s[i]=='N' or s[i]=='E':
c=i+1;cn+=1
if cn==x+y:break
print(c)
else:print(-1)
elif x<=0 and y>=0:
if s.count('N')>=y and s.count('W')>=abs(x) :
c = cn = 0
for i in range(t):
if s[i] == 'N' or s[i] == 'W':
c=i+1;cn+=1
if cn == abs(x) + y: break
print(c)
else:print(-1)
elif x>=0 and y<=0:
if s.count('S')>=abs(y) and s.count('E')>=x :
c = cn = 0
for i in range(t):
if s[i] == 'N' or s[i] == 'E':
c=i+1;cn+=1
if cn == x + abs(y): break
print(c)
else:print(-1)
else:
if s.count('S')>=abs(y) and s.count('W')>=abs(x) :
c = cn = 0
for i in range(t):
if s[i] == 'N' or s[i] == 'E':
c=i+1;cn+=1
if cn == abs(x) + abs(y): break
print(c)
else:print(-1)
``` | 0 |
|
3 | A | Shortest path of the king | PROGRAMMING | 1,000 | [
"greedy",
"shortest paths"
] | A. Shortest path of the king | 1 | 64 | The king is left alone on the chessboard. In spite of this loneliness, he doesn't lose heart, because he has business of national importance. For example, he has to pay an official visit to square *t*. As the king is not in habit of wasting his time, he wants to get from his current position *s* to square *t* in the least number of moves. Help him to do this.
In one move the king can get to the square that has a common side or a common vertex with the square the king is currently in (generally there are 8 different squares he can move to). | The first line contains the chessboard coordinates of square *s*, the second line — of square *t*.
Chessboard coordinates consist of two characters, the first one is a lowercase Latin letter (from a to h), the second one is a digit from 1 to 8. | In the first line print *n* — minimum number of the king's moves. Then in *n* lines print the moves themselves. Each move is described with one of the 8: L, R, U, D, LU, LD, RU or RD.
L, R, U, D stand respectively for moves left, right, up and down (according to the picture), and 2-letter combinations stand for diagonal moves. If the answer is not unique, print any of them. | [
"a8\nh1\n"
] | [
"7\nRD\nRD\nRD\nRD\nRD\nRD\nRD\n"
] | none | 0 | [
{
"input": "a8\nh1",
"output": "7\nRD\nRD\nRD\nRD\nRD\nRD\nRD"
},
{
"input": "b2\nb4",
"output": "2\nU\nU"
},
{
"input": "a5\na5",
"output": "0"
},
{
"input": "h1\nb2",
"output": "6\nLU\nL\nL\nL\nL\nL"
},
{
"input": "c5\nh2",
"output": "5\nRD\nRD\nRD\nR\nR"
},
{
"input": "e1\nf2",
"output": "1\nRU"
},
{
"input": "g4\nd2",
"output": "3\nLD\nLD\nL"
},
{
"input": "a8\nb2",
"output": "6\nRD\nD\nD\nD\nD\nD"
},
{
"input": "d4\nh2",
"output": "4\nRD\nRD\nR\nR"
},
{
"input": "c5\na2",
"output": "3\nLD\nLD\nD"
},
{
"input": "h5\nf8",
"output": "3\nLU\nLU\nU"
},
{
"input": "e6\nb6",
"output": "3\nL\nL\nL"
},
{
"input": "a6\ng4",
"output": "6\nRD\nRD\nR\nR\nR\nR"
},
{
"input": "f7\nc2",
"output": "5\nLD\nLD\nLD\nD\nD"
},
{
"input": "b7\nh8",
"output": "6\nRU\nR\nR\nR\nR\nR"
},
{
"input": "g7\nd6",
"output": "3\nLD\nL\nL"
},
{
"input": "c8\na3",
"output": "5\nLD\nLD\nD\nD\nD"
},
{
"input": "h8\nf1",
"output": "7\nLD\nLD\nD\nD\nD\nD\nD"
},
{
"input": "d1\nb7",
"output": "6\nLU\nLU\nU\nU\nU\nU"
},
{
"input": "a7\ne5",
"output": "4\nRD\nRD\nR\nR"
},
{
"input": "d6\nb1",
"output": "5\nLD\nLD\nD\nD\nD"
},
{
"input": "f5\ng5",
"output": "1\nR"
},
{
"input": "h4\nd1",
"output": "4\nLD\nLD\nLD\nL"
},
{
"input": "b3\na5",
"output": "2\nLU\nU"
},
{
"input": "d2\nf1",
"output": "2\nRD\nR"
},
{
"input": "f1\nc5",
"output": "4\nLU\nLU\nLU\nU"
},
{
"input": "a8\nh1",
"output": "7\nRD\nRD\nRD\nRD\nRD\nRD\nRD"
},
{
"input": "c7\ne5",
"output": "2\nRD\nRD"
},
{
"input": "e7\nb1",
"output": "6\nLD\nLD\nLD\nD\nD\nD"
},
{
"input": "g8\na8",
"output": "6\nL\nL\nL\nL\nL\nL"
},
{
"input": "g6\nf2",
"output": "4\nLD\nD\nD\nD"
},
{
"input": "g4\nc4",
"output": "4\nL\nL\nL\nL"
},
{
"input": "g2\na6",
"output": "6\nLU\nLU\nLU\nLU\nL\nL"
},
{
"input": "f8\nf8",
"output": "0"
},
{
"input": "f5\nd2",
"output": "3\nLD\nLD\nD"
}
] | 1,515,653,908 | 2,147,483,647 | Python 3 | OK | TESTS | 35 | 154 | 5,632,000 | def checkPath(row, col):
li = []
if row-1 >= 0 and not ar[row-1][col]:
ar[row-1][col] = ar[row][col] + 1
li.append([row-1, col])
if col-1 >= 0 and not ar[row][col-1]:
ar[row][col-1] = ar[row][col] + 1
li.append([row, col-1])
if row+1 < 8 and not ar[row+1][col]:
ar[row+1][col] = ar[row][col] + 1
li.append([row+1, col])
if col+1 < 8 and not ar[row][col+1]:
ar[row][col+1] = ar[row][col] + 1
li.append([row, col+1])
if row-1 >= 0 and col-1 >= 0 and not ar[row-1][col-1]:
ar[row-1][col-1] = ar[row][col] + 1
li.append([row-1, col-1])
if row-1 >= 0 and col+1 < 8 and not ar[row-1][col+1]:
ar[row-1][col+1] = ar[row][col] + 1
li.append([row-1, col+1])
if row+1 < 8 and col+1 < 8 and not ar[row+1][col+1]:
ar[row+1][col+1] = ar[row][col] + 1
li.append([row+1, col+1])
if row+1 < 8 and col-1 >= 0 and not ar[row+1][col-1]:
ar[row+1][col-1] = ar[row][col] + 1
li.append([row+1, col-1])
return li
ar = [[0]* 8 for _ in range(8)]
startp, startq = list(input().strip())
startx = ord('8') - ord(startq)
starty = ord(startp) - ord('a')
endp, endq = list(input().strip())
endx = ord('8') - ord(endq)
endy = ord(endp) - ord('a')
ar[startx][starty] = 1
li = checkPath(startx, starty)
while li:
t = []
for m,n in li:
if (m,n)==(endx,endy):
t = []
break
t.extend(checkPath(m,n))
li = t
print(ar[endx][endy]-1)
li = []; idx = ar[endx][endy]
row, col = endx, endy
while idx:
idx -= 1
if row-1 >= 0 and ar[row-1][col]==idx:
li.append('D')
row -= 1
continue
if col-1 >= 0 and ar[row][col-1]==idx:
li.append('R')
col -= 1
continue
if row+1 < 8 and ar[row+1][col]==idx:
li.append('U')
row += 1
continue
if col+1 < 8 and ar[row][col+1]==idx:
li.append('L')
col += 1
continue
if row-1 >= 0 and col-1 >= 0 and ar[row-1][col-1]==idx:
li.append('RD')
row -= 1; col -= 1
continue
if row-1 >= 0 and col+1 < 8 and ar[row-1][col+1]==idx:
li.append('LD')
row -= 1; col += 1
continue
if row+1 < 8 and col+1 < 8 and ar[row+1][col+1]==idx:
li.append('LU')
row += 1; col += 1
continue
if row+1 < 8 and col-1 >= 0 and ar[row+1][col-1]==idx:
li.append('RU')
row += 1; col -= 1
continue
li.reverse()
for item in li:
print(item)
| Title: Shortest path of the king
Time Limit: 1 seconds
Memory Limit: 64 megabytes
Problem Description:
The king is left alone on the chessboard. In spite of this loneliness, he doesn't lose heart, because he has business of national importance. For example, he has to pay an official visit to square *t*. As the king is not in habit of wasting his time, he wants to get from his current position *s* to square *t* in the least number of moves. Help him to do this.
In one move the king can get to the square that has a common side or a common vertex with the square the king is currently in (generally there are 8 different squares he can move to).
Input Specification:
The first line contains the chessboard coordinates of square *s*, the second line — of square *t*.
Chessboard coordinates consist of two characters, the first one is a lowercase Latin letter (from a to h), the second one is a digit from 1 to 8.
Output Specification:
In the first line print *n* — minimum number of the king's moves. Then in *n* lines print the moves themselves. Each move is described with one of the 8: L, R, U, D, LU, LD, RU or RD.
L, R, U, D stand respectively for moves left, right, up and down (according to the picture), and 2-letter combinations stand for diagonal moves. If the answer is not unique, print any of them.
Demo Input:
['a8\nh1\n']
Demo Output:
['7\nRD\nRD\nRD\nRD\nRD\nRD\nRD\n']
Note:
none | ```python
def checkPath(row, col):
li = []
if row-1 >= 0 and not ar[row-1][col]:
ar[row-1][col] = ar[row][col] + 1
li.append([row-1, col])
if col-1 >= 0 and not ar[row][col-1]:
ar[row][col-1] = ar[row][col] + 1
li.append([row, col-1])
if row+1 < 8 and not ar[row+1][col]:
ar[row+1][col] = ar[row][col] + 1
li.append([row+1, col])
if col+1 < 8 and not ar[row][col+1]:
ar[row][col+1] = ar[row][col] + 1
li.append([row, col+1])
if row-1 >= 0 and col-1 >= 0 and not ar[row-1][col-1]:
ar[row-1][col-1] = ar[row][col] + 1
li.append([row-1, col-1])
if row-1 >= 0 and col+1 < 8 and not ar[row-1][col+1]:
ar[row-1][col+1] = ar[row][col] + 1
li.append([row-1, col+1])
if row+1 < 8 and col+1 < 8 and not ar[row+1][col+1]:
ar[row+1][col+1] = ar[row][col] + 1
li.append([row+1, col+1])
if row+1 < 8 and col-1 >= 0 and not ar[row+1][col-1]:
ar[row+1][col-1] = ar[row][col] + 1
li.append([row+1, col-1])
return li
ar = [[0]* 8 for _ in range(8)]
startp, startq = list(input().strip())
startx = ord('8') - ord(startq)
starty = ord(startp) - ord('a')
endp, endq = list(input().strip())
endx = ord('8') - ord(endq)
endy = ord(endp) - ord('a')
ar[startx][starty] = 1
li = checkPath(startx, starty)
while li:
t = []
for m,n in li:
if (m,n)==(endx,endy):
t = []
break
t.extend(checkPath(m,n))
li = t
print(ar[endx][endy]-1)
li = []; idx = ar[endx][endy]
row, col = endx, endy
while idx:
idx -= 1
if row-1 >= 0 and ar[row-1][col]==idx:
li.append('D')
row -= 1
continue
if col-1 >= 0 and ar[row][col-1]==idx:
li.append('R')
col -= 1
continue
if row+1 < 8 and ar[row+1][col]==idx:
li.append('U')
row += 1
continue
if col+1 < 8 and ar[row][col+1]==idx:
li.append('L')
col += 1
continue
if row-1 >= 0 and col-1 >= 0 and ar[row-1][col-1]==idx:
li.append('RD')
row -= 1; col -= 1
continue
if row-1 >= 0 and col+1 < 8 and ar[row-1][col+1]==idx:
li.append('LD')
row -= 1; col += 1
continue
if row+1 < 8 and col+1 < 8 and ar[row+1][col+1]==idx:
li.append('LU')
row += 1; col += 1
continue
if row+1 < 8 and col-1 >= 0 and ar[row+1][col-1]==idx:
li.append('RU')
row += 1; col -= 1
continue
li.reverse()
for item in li:
print(item)
``` | 3.881038 |
609 | A | USB Flash Drives | PROGRAMMING | 800 | [
"greedy",
"implementation",
"sortings"
] | null | null | Sean is trying to save a large file to a USB flash drive. He has *n* USB flash drives with capacities equal to *a*1,<=*a*2,<=...,<=*a**n* megabytes. The file size is equal to *m* megabytes.
Find the minimum number of USB flash drives needed to write Sean's file, if he can split the file between drives. | The first line contains positive integer *n* (1<=≤<=*n*<=≤<=100) — the number of USB flash drives.
The second line contains positive integer *m* (1<=≤<=*m*<=≤<=105) — the size of Sean's file.
Each of the next *n* lines contains positive integer *a**i* (1<=≤<=*a**i*<=≤<=1000) — the sizes of USB flash drives in megabytes.
It is guaranteed that the answer exists, i. e. the sum of all *a**i* is not less than *m*. | Print the minimum number of USB flash drives to write Sean's file, if he can split the file between drives. | [
"3\n5\n2\n1\n3\n",
"3\n6\n2\n3\n2\n",
"2\n5\n5\n10\n"
] | [
"2\n",
"3\n",
"1\n"
] | In the first example Sean needs only two USB flash drives — the first and the third.
In the second example Sean needs all three USB flash drives.
In the third example Sean needs only one USB flash drive and he can use any available USB flash drive — the first or the second. | 0 | [
{
"input": "3\n5\n2\n1\n3",
"output": "2"
},
{
"input": "3\n6\n2\n3\n2",
"output": "3"
},
{
"input": "2\n5\n5\n10",
"output": "1"
},
{
"input": "5\n16\n8\n1\n3\n4\n9",
"output": "2"
},
{
"input": "10\n121\n10\n37\n74\n56\n42\n39\n6\n68\n8\n100",
"output": "2"
},
{
"input": "12\n4773\n325\n377\n192\n780\n881\n816\n839\n223\n215\n125\n952\n8",
"output": "7"
},
{
"input": "15\n7758\n182\n272\n763\n910\n24\n359\n583\n890\n735\n819\n66\n992\n440\n496\n227",
"output": "15"
},
{
"input": "30\n70\n6\n2\n10\n4\n7\n10\n5\n1\n8\n10\n4\n3\n5\n9\n3\n6\n6\n4\n2\n6\n5\n10\n1\n9\n7\n2\n1\n10\n7\n5",
"output": "8"
},
{
"input": "40\n15705\n702\n722\n105\n873\n417\n477\n794\n300\n869\n496\n572\n232\n456\n298\n473\n584\n486\n713\n934\n121\n303\n956\n934\n840\n358\n201\n861\n497\n131\n312\n957\n96\n914\n509\n60\n300\n722\n658\n820\n103",
"output": "21"
},
{
"input": "50\n18239\n300\n151\n770\n9\n200\n52\n247\n753\n523\n263\n744\n463\n540\n244\n608\n569\n771\n32\n425\n777\n624\n761\n628\n124\n405\n396\n726\n626\n679\n237\n229\n49\n512\n18\n671\n290\n768\n632\n739\n18\n136\n413\n117\n83\n413\n452\n767\n664\n203\n404",
"output": "31"
},
{
"input": "70\n149\n5\n3\n3\n4\n6\n1\n2\n9\n8\n3\n1\n8\n4\n4\n3\n6\n10\n7\n1\n10\n8\n4\n9\n3\n8\n3\n2\n5\n1\n8\n6\n9\n10\n4\n8\n6\n9\n9\n9\n3\n4\n2\n2\n5\n8\n9\n1\n10\n3\n4\n3\n1\n9\n3\n5\n1\n3\n7\n6\n9\n8\n9\n1\n7\n4\n4\n2\n3\n5\n7",
"output": "17"
},
{
"input": "70\n2731\n26\n75\n86\n94\n37\n25\n32\n35\n92\n1\n51\n73\n53\n66\n16\n80\n15\n81\n100\n87\n55\n48\n30\n71\n39\n87\n77\n25\n70\n22\n75\n23\n97\n16\n75\n95\n61\n61\n28\n10\n78\n54\n80\n51\n25\n24\n90\n58\n4\n77\n40\n54\n53\n47\n62\n30\n38\n71\n97\n71\n60\n58\n1\n21\n15\n55\n99\n34\n88\n99",
"output": "35"
},
{
"input": "70\n28625\n34\n132\n181\n232\n593\n413\n862\n887\n808\n18\n35\n89\n356\n640\n339\n280\n975\n82\n345\n398\n948\n372\n91\n755\n75\n153\n948\n603\n35\n694\n722\n293\n363\n884\n264\n813\n175\n169\n646\n138\n449\n488\n828\n417\n134\n84\n763\n288\n845\n801\n556\n972\n332\n564\n934\n699\n842\n942\n644\n203\n406\n140\n37\n9\n423\n546\n675\n491\n113\n587",
"output": "45"
},
{
"input": "80\n248\n3\n9\n4\n5\n10\n7\n2\n6\n2\n2\n8\n2\n1\n3\n7\n9\n2\n8\n4\n4\n8\n5\n4\n4\n10\n2\n1\n4\n8\n4\n10\n1\n2\n10\n2\n3\n3\n1\n1\n8\n9\n5\n10\n2\n8\n10\n5\n3\n6\n1\n7\n8\n9\n10\n5\n10\n10\n2\n10\n1\n2\n4\n1\n9\n4\n7\n10\n8\n5\n8\n1\n4\n2\n2\n3\n9\n9\n9\n10\n6",
"output": "27"
},
{
"input": "80\n2993\n18\n14\n73\n38\n14\n73\n77\n18\n81\n6\n96\n65\n77\n86\n76\n8\n16\n81\n83\n83\n34\n69\n58\n15\n19\n1\n16\n57\n95\n35\n5\n49\n8\n15\n47\n84\n99\n94\n93\n55\n43\n47\n51\n61\n57\n13\n7\n92\n14\n4\n83\n100\n60\n75\n41\n95\n74\n40\n1\n4\n95\n68\n59\n65\n15\n15\n75\n85\n46\n77\n26\n30\n51\n64\n75\n40\n22\n88\n68\n24",
"output": "38"
},
{
"input": "80\n37947\n117\n569\n702\n272\n573\n629\n90\n337\n673\n589\n576\n205\n11\n284\n645\n719\n777\n271\n567\n466\n251\n402\n3\n97\n288\n699\n208\n173\n530\n782\n266\n395\n957\n159\n463\n43\n316\n603\n197\n386\n132\n799\n778\n905\n784\n71\n851\n963\n883\n705\n454\n275\n425\n727\n223\n4\n870\n833\n431\n463\n85\n505\n800\n41\n954\n981\n242\n578\n336\n48\n858\n702\n349\n929\n646\n528\n993\n506\n274\n227",
"output": "70"
},
{
"input": "90\n413\n5\n8\n10\n7\n5\n7\n5\n7\n1\n7\n8\n4\n3\n9\n4\n1\n10\n3\n1\n10\n9\n3\n1\n8\n4\n7\n5\n2\n9\n3\n10\n10\n3\n6\n3\n3\n10\n7\n5\n1\n1\n2\n4\n8\n2\n5\n5\n3\n9\n5\n5\n3\n10\n2\n3\n8\n5\n9\n1\n3\n6\n5\n9\n2\n3\n7\n10\n3\n4\n4\n1\n5\n9\n2\n6\n9\n1\n1\n9\n9\n7\n7\n7\n8\n4\n5\n3\n4\n6\n9",
"output": "59"
},
{
"input": "90\n4226\n33\n43\n83\n46\n75\n14\n88\n36\n8\n25\n47\n4\n96\n19\n33\n49\n65\n17\n59\n72\n1\n55\n94\n92\n27\n33\n39\n14\n62\n79\n12\n89\n22\n86\n13\n19\n77\n53\n96\n74\n24\n25\n17\n64\n71\n81\n87\n52\n72\n55\n49\n74\n36\n65\n86\n91\n33\n61\n97\n38\n87\n61\n14\n73\n95\n43\n67\n42\n67\n22\n12\n62\n32\n96\n24\n49\n82\n46\n89\n36\n75\n91\n11\n10\n9\n33\n86\n28\n75\n39",
"output": "64"
},
{
"input": "90\n40579\n448\n977\n607\n745\n268\n826\n479\n59\n330\n609\n43\n301\n970\n726\n172\n632\n600\n181\n712\n195\n491\n312\n849\n722\n679\n682\n780\n131\n404\n293\n387\n567\n660\n54\n339\n111\n833\n612\n911\n869\n356\n884\n635\n126\n639\n712\n473\n663\n773\n435\n32\n973\n484\n662\n464\n699\n274\n919\n95\n904\n253\n589\n543\n454\n250\n349\n237\n829\n511\n536\n36\n45\n152\n626\n384\n199\n877\n941\n84\n781\n115\n20\n52\n726\n751\n920\n291\n571\n6\n199",
"output": "64"
},
{
"input": "100\n66\n7\n9\n10\n5\n2\n8\n6\n5\n4\n10\n10\n6\n5\n2\n2\n1\n1\n5\n8\n7\n8\n10\n5\n6\n6\n5\n9\n9\n6\n3\n8\n7\n10\n5\n9\n6\n7\n3\n5\n8\n6\n8\n9\n1\n1\n1\n2\n4\n5\n5\n1\n1\n2\n6\n7\n1\n5\n8\n7\n2\n1\n7\n10\n9\n10\n2\n4\n10\n4\n10\n10\n5\n3\n9\n1\n2\n1\n10\n5\n1\n7\n4\n4\n5\n7\n6\n10\n4\n7\n3\n4\n3\n6\n2\n5\n2\n4\n9\n5\n3",
"output": "7"
},
{
"input": "100\n4862\n20\n47\n85\n47\n76\n38\n48\n93\n91\n81\n31\n51\n23\n60\n59\n3\n73\n72\n57\n67\n54\n9\n42\n5\n32\n46\n72\n79\n95\n61\n79\n88\n33\n52\n97\n10\n3\n20\n79\n82\n93\n90\n38\n80\n18\n21\n43\n60\n73\n34\n75\n65\n10\n84\n100\n29\n94\n56\n22\n59\n95\n46\n22\n57\n69\n67\n90\n11\n10\n61\n27\n2\n48\n69\n86\n91\n69\n76\n36\n71\n18\n54\n90\n74\n69\n50\n46\n8\n5\n41\n96\n5\n14\n55\n85\n39\n6\n79\n75\n87",
"output": "70"
},
{
"input": "100\n45570\n14\n881\n678\n687\n993\n413\n760\n451\n426\n787\n503\n343\n234\n530\n294\n725\n941\n524\n574\n441\n798\n399\n360\n609\n376\n525\n229\n995\n478\n347\n47\n23\n468\n525\n749\n601\n235\n89\n995\n489\n1\n239\n415\n122\n671\n128\n357\n886\n401\n964\n212\n968\n210\n130\n871\n360\n661\n844\n414\n187\n21\n824\n266\n713\n126\n496\n916\n37\n193\n755\n894\n641\n300\n170\n176\n383\n488\n627\n61\n897\n33\n242\n419\n881\n698\n107\n391\n418\n774\n905\n87\n5\n896\n835\n318\n373\n916\n393\n91\n460",
"output": "78"
},
{
"input": "100\n522\n1\n5\n2\n4\n2\n6\n3\n4\n2\n10\n10\n6\n7\n9\n7\n1\n7\n2\n5\n3\n1\n5\n2\n3\n5\n1\n7\n10\n10\n4\n4\n10\n9\n10\n6\n2\n8\n2\n6\n10\n9\n2\n7\n5\n9\n4\n6\n10\n7\n3\n1\n1\n9\n5\n10\n9\n2\n8\n3\n7\n5\n4\n7\n5\n9\n10\n6\n2\n9\n2\n5\n10\n1\n7\n7\n10\n5\n6\n2\n9\n4\n7\n10\n10\n8\n3\n4\n9\n3\n6\n9\n10\n2\n9\n9\n3\n4\n1\n10\n2",
"output": "74"
},
{
"input": "100\n32294\n414\n116\n131\n649\n130\n476\n630\n605\n213\n117\n757\n42\n109\n85\n127\n635\n629\n994\n410\n764\n204\n161\n231\n577\n116\n936\n537\n565\n571\n317\n722\n819\n229\n284\n487\n649\n304\n628\n727\n816\n854\n91\n111\n549\n87\n374\n417\n3\n868\n882\n168\n743\n77\n534\n781\n75\n956\n910\n734\n507\n568\n802\n946\n891\n659\n116\n678\n375\n380\n430\n627\n873\n350\n930\n285\n6\n183\n96\n517\n81\n794\n235\n360\n551\n6\n28\n799\n226\n996\n894\n981\n551\n60\n40\n460\n479\n161\n318\n952\n433",
"output": "42"
},
{
"input": "100\n178\n71\n23\n84\n98\n8\n14\n4\n42\n56\n83\n87\n28\n22\n32\n50\n5\n96\n90\n1\n59\n74\n56\n96\n77\n88\n71\n38\n62\n36\n85\n1\n97\n98\n98\n32\n99\n42\n6\n81\n20\n49\n57\n71\n66\n9\n45\n41\n29\n28\n32\n68\n38\n29\n35\n29\n19\n27\n76\n85\n68\n68\n41\n32\n78\n72\n38\n19\n55\n83\n83\n25\n46\n62\n48\n26\n53\n14\n39\n31\n94\n84\n22\n39\n34\n96\n63\n37\n42\n6\n78\n76\n64\n16\n26\n6\n79\n53\n24\n29\n63",
"output": "2"
},
{
"input": "100\n885\n226\n266\n321\n72\n719\n29\n121\n533\n85\n672\n225\n830\n783\n822\n30\n791\n618\n166\n487\n922\n434\n814\n473\n5\n741\n947\n910\n305\n998\n49\n945\n588\n868\n809\n803\n168\n280\n614\n434\n634\n538\n591\n437\n540\n445\n313\n177\n171\n799\n778\n55\n617\n554\n583\n611\n12\n94\n599\n182\n765\n556\n965\n542\n35\n460\n177\n313\n485\n744\n384\n21\n52\n879\n792\n411\n614\n811\n565\n695\n428\n587\n631\n794\n461\n258\n193\n696\n936\n646\n756\n267\n55\n690\n730\n742\n734\n988\n235\n762\n440",
"output": "1"
},
{
"input": "100\n29\n9\n2\n10\n8\n6\n7\n7\n3\n3\n10\n4\n5\n2\n5\n1\n6\n3\n2\n5\n10\n10\n9\n1\n4\n5\n2\n2\n3\n1\n2\n2\n9\n6\n9\n7\n8\n8\n1\n5\n5\n3\n1\n5\n6\n1\n9\n2\n3\n8\n10\n8\n3\n2\n7\n1\n2\n1\n2\n8\n10\n5\n2\n3\n1\n10\n7\n1\n7\n4\n9\n6\n6\n4\n7\n1\n2\n7\n7\n9\n9\n7\n10\n4\n10\n8\n2\n1\n5\n5\n10\n5\n8\n1\n5\n6\n5\n1\n5\n6\n8",
"output": "3"
},
{
"input": "100\n644\n94\n69\n43\n36\n54\n93\n30\n74\n56\n95\n70\n49\n11\n36\n57\n30\n59\n3\n52\n59\n90\n82\n39\n67\n32\n8\n80\n64\n8\n65\n51\n48\n89\n90\n35\n4\n54\n66\n96\n68\n90\n30\n4\n13\n97\n41\n90\n85\n17\n45\n94\n31\n58\n4\n39\n76\n95\n92\n59\n67\n46\n96\n55\n82\n64\n20\n20\n83\n46\n37\n15\n60\n37\n79\n45\n47\n63\n73\n76\n31\n52\n36\n32\n49\n26\n61\n91\n31\n25\n62\n90\n65\n65\n5\n94\n7\n15\n97\n88\n68",
"output": "7"
},
{
"input": "100\n1756\n98\n229\n158\n281\n16\n169\n149\n239\n235\n182\n147\n215\n49\n270\n194\n242\n295\n289\n249\n19\n12\n144\n157\n92\n270\n122\n212\n97\n152\n14\n42\n12\n198\n98\n295\n154\n229\n191\n294\n5\n156\n43\n185\n184\n20\n125\n23\n10\n257\n244\n264\n79\n46\n277\n13\n22\n97\n212\n77\n293\n20\n51\n17\n109\n37\n68\n117\n51\n248\n10\n149\n179\n192\n239\n161\n13\n173\n297\n73\n43\n109\n288\n198\n81\n70\n254\n187\n277\n1\n295\n113\n95\n291\n293\n119\n205\n191\n37\n34\n116",
"output": "6"
},
{
"input": "100\n20562\n721\n452\n11\n703\n376\n183\n197\n203\n406\n642\n346\n446\n256\n760\n201\n360\n702\n707\n388\n779\n653\n610\n497\n768\n670\n134\n780\n306\n661\n180\n259\n256\n362\n6\n121\n415\n747\n170\n67\n439\n728\n193\n622\n481\n38\n225\n343\n303\n253\n436\n305\n68\n794\n247\n291\n600\n750\n188\n199\n757\n28\n776\n749\n253\n351\n53\n629\n129\n578\n209\n89\n651\n262\n638\n353\n469\n31\n144\n460\n176\n535\n562\n366\n639\n234\n577\n364\n761\n617\n303\n450\n778\n311\n289\n221\n274\n239\n626\n194\n36",
"output": "30"
},
{
"input": "100\n32630\n548\n21\n756\n138\n56\n719\n97\n86\n599\n531\n464\n137\n737\n239\n626\n179\n170\n271\n335\n178\n298\n597\n616\n104\n190\n216\n333\n606\n621\n310\n70\n286\n593\n655\n472\n556\n77\n625\n744\n395\n487\n762\n316\n469\n258\n475\n596\n651\n180\n737\n101\n511\n708\n163\n713\n475\n557\n649\n705\n583\n97\n447\n119\n91\n372\n194\n394\n667\n384\n635\n611\n746\n758\n613\n54\n508\n405\n188\n570\n254\n28\n599\n767\n115\n737\n194\n148\n686\n705\n236\n762\n613\n770\n633\n401\n773\n448\n274\n141\n718",
"output": "52"
},
{
"input": "1\n1\n1",
"output": "1"
}
] | 1,577,500,571 | 2,147,483,647 | Python 3 | OK | TESTS | 34 | 109 | 0 | n = int(input())
m = int(input())
a = sorted([int(input()) for i in range(n)], reverse = True)
s = 0
for i in range(n):
s += a[i]
if s >= m:
print (i+1)
exit() | Title: USB Flash Drives
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Sean is trying to save a large file to a USB flash drive. He has *n* USB flash drives with capacities equal to *a*1,<=*a*2,<=...,<=*a**n* megabytes. The file size is equal to *m* megabytes.
Find the minimum number of USB flash drives needed to write Sean's file, if he can split the file between drives.
Input Specification:
The first line contains positive integer *n* (1<=≤<=*n*<=≤<=100) — the number of USB flash drives.
The second line contains positive integer *m* (1<=≤<=*m*<=≤<=105) — the size of Sean's file.
Each of the next *n* lines contains positive integer *a**i* (1<=≤<=*a**i*<=≤<=1000) — the sizes of USB flash drives in megabytes.
It is guaranteed that the answer exists, i. e. the sum of all *a**i* is not less than *m*.
Output Specification:
Print the minimum number of USB flash drives to write Sean's file, if he can split the file between drives.
Demo Input:
['3\n5\n2\n1\n3\n', '3\n6\n2\n3\n2\n', '2\n5\n5\n10\n']
Demo Output:
['2\n', '3\n', '1\n']
Note:
In the first example Sean needs only two USB flash drives — the first and the third.
In the second example Sean needs all three USB flash drives.
In the third example Sean needs only one USB flash drive and he can use any available USB flash drive — the first or the second. | ```python
n = int(input())
m = int(input())
a = sorted([int(input()) for i in range(n)], reverse = True)
s = 0
for i in range(n):
s += a[i]
if s >= m:
print (i+1)
exit()
``` | 3 |
|
221 | B | Little Elephant and Numbers | PROGRAMMING | 1,300 | [
"implementation"
] | null | null | The Little Elephant loves numbers.
He has a positive integer *x*. The Little Elephant wants to find the number of positive integers *d*, such that *d* is the divisor of *x*, and *x* and *d* have at least one common (the same) digit in their decimal representations.
Help the Little Elephant to find the described number. | A single line contains a single integer *x* (1<=≤<=*x*<=≤<=109). | In a single line print an integer — the answer to the problem. | [
"1\n",
"10\n"
] | [
"1\n",
"2\n"
] | none | 1,000 | [
{
"input": "1",
"output": "1"
},
{
"input": "10",
"output": "2"
},
{
"input": "47",
"output": "1"
},
{
"input": "100",
"output": "5"
},
{
"input": "128",
"output": "6"
},
{
"input": "2",
"output": "1"
},
{
"input": "17",
"output": "2"
},
{
"input": "1000000",
"output": "41"
},
{
"input": "1000000000",
"output": "91"
},
{
"input": "4584725",
"output": "5"
},
{
"input": "999999999",
"output": "6"
},
{
"input": "9",
"output": "1"
},
{
"input": "3",
"output": "1"
},
{
"input": "4",
"output": "1"
},
{
"input": "20",
"output": "3"
},
{
"input": "24",
"output": "4"
},
{
"input": "48",
"output": "4"
},
{
"input": "2458450",
"output": "11"
},
{
"input": "97648850",
"output": "44"
},
{
"input": "96488450",
"output": "21"
},
{
"input": "879541",
"output": "7"
},
{
"input": "111111111",
"output": "5"
},
{
"input": "222222222",
"output": "6"
},
{
"input": "777777777",
"output": "9"
},
{
"input": "211768200",
"output": "244"
},
{
"input": "536870912",
"output": "29"
},
{
"input": "654885000",
"output": "698"
},
{
"input": "223092870",
"output": "479"
},
{
"input": "901800900",
"output": "639"
},
{
"input": "101871000",
"output": "460"
},
{
"input": "49",
"output": "1"
},
{
"input": "999999993",
"output": "5"
},
{
"input": "999999666",
"output": "8"
},
{
"input": "999999997",
"output": "6"
},
{
"input": "960690025",
"output": "8"
},
{
"input": "16",
"output": "2"
},
{
"input": "999000011",
"output": "2"
},
{
"input": "999999937",
"output": "1"
},
{
"input": "999999998",
"output": "6"
}
] | 1,642,705,911 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 30 | 0 | x = int(input())
cnt = 0
for i in range(1, int(x**0.5)+1):
if x % i == 0:
temp1 = str(x)
temp2 = str(i)
for k in temp1:
if k in temp2:
cnt += 1
break
temp2 = str(x//i)
if temp2 != str(i):
for k in temp1:
if k in temp2:
cnt += 1
break
print("i =",i,"count =", cnt)
if x == 1:
cnt = 1
print(cnt) | Title: Little Elephant and Numbers
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The Little Elephant loves numbers.
He has a positive integer *x*. The Little Elephant wants to find the number of positive integers *d*, such that *d* is the divisor of *x*, and *x* and *d* have at least one common (the same) digit in their decimal representations.
Help the Little Elephant to find the described number.
Input Specification:
A single line contains a single integer *x* (1<=≤<=*x*<=≤<=109).
Output Specification:
In a single line print an integer — the answer to the problem.
Demo Input:
['1\n', '10\n']
Demo Output:
['1\n', '2\n']
Note:
none | ```python
x = int(input())
cnt = 0
for i in range(1, int(x**0.5)+1):
if x % i == 0:
temp1 = str(x)
temp2 = str(i)
for k in temp1:
if k in temp2:
cnt += 1
break
temp2 = str(x//i)
if temp2 != str(i):
for k in temp1:
if k in temp2:
cnt += 1
break
print("i =",i,"count =", cnt)
if x == 1:
cnt = 1
print(cnt)
``` | 0 |
|
131 | A | cAPS lOCK | PROGRAMMING | 1,000 | [
"implementation",
"strings"
] | null | null | wHAT DO WE NEED cAPS LOCK FOR?
Caps lock is a computer keyboard key. Pressing it sets an input mode in which typed letters are capital by default. If it is pressed by accident, it leads to accidents like the one we had in the first passage.
Let's consider that a word has been typed with the Caps lock key accidentally switched on, if:
- either it only contains uppercase letters; - or all letters except for the first one are uppercase.
In this case we should automatically change the case of all letters. For example, the case of the letters that form words "hELLO", "HTTP", "z" should be changed.
Write a program that applies the rule mentioned above. If the rule cannot be applied, the program should leave the word unchanged. | The first line of the input data contains a word consisting of uppercase and lowercase Latin letters. The word's length is from 1 to 100 characters, inclusive. | Print the result of the given word's processing. | [
"cAPS\n",
"Lock\n"
] | [
"Caps",
"Lock\n"
] | none | 500 | [
{
"input": "cAPS",
"output": "Caps"
},
{
"input": "Lock",
"output": "Lock"
},
{
"input": "cAPSlOCK",
"output": "cAPSlOCK"
},
{
"input": "CAPs",
"output": "CAPs"
},
{
"input": "LoCK",
"output": "LoCK"
},
{
"input": "OOPS",
"output": "oops"
},
{
"input": "oops",
"output": "oops"
},
{
"input": "a",
"output": "A"
},
{
"input": "A",
"output": "a"
},
{
"input": "aA",
"output": "Aa"
},
{
"input": "Zz",
"output": "Zz"
},
{
"input": "Az",
"output": "Az"
},
{
"input": "zA",
"output": "Za"
},
{
"input": "AAA",
"output": "aaa"
},
{
"input": "AAa",
"output": "AAa"
},
{
"input": "AaR",
"output": "AaR"
},
{
"input": "Tdr",
"output": "Tdr"
},
{
"input": "aTF",
"output": "Atf"
},
{
"input": "fYd",
"output": "fYd"
},
{
"input": "dsA",
"output": "dsA"
},
{
"input": "fru",
"output": "fru"
},
{
"input": "hYBKF",
"output": "Hybkf"
},
{
"input": "XweAR",
"output": "XweAR"
},
{
"input": "mogqx",
"output": "mogqx"
},
{
"input": "eOhEi",
"output": "eOhEi"
},
{
"input": "nkdku",
"output": "nkdku"
},
{
"input": "zcnko",
"output": "zcnko"
},
{
"input": "lcccd",
"output": "lcccd"
},
{
"input": "vwmvg",
"output": "vwmvg"
},
{
"input": "lvchf",
"output": "lvchf"
},
{
"input": "IUNVZCCHEWENCHQQXQYPUJCRDZLUXCLJHXPHBXEUUGNXOOOPBMOBRIBHHMIRILYJGYYGFMTMFSVURGYHUWDRLQVIBRLPEVAMJQYO",
"output": "iunvzcchewenchqqxqypujcrdzluxcljhxphbxeuugnxooopbmobribhhmirilyjgyygfmtmfsvurgyhuwdrlqvibrlpevamjqyo"
},
{
"input": "OBHSZCAMDXEJWOZLKXQKIVXUUQJKJLMMFNBPXAEFXGVNSKQLJGXHUXHGCOTESIVKSFMVVXFVMTEKACRIWALAGGMCGFEXQKNYMRTG",
"output": "obhszcamdxejwozlkxqkivxuuqjkjlmmfnbpxaefxgvnskqljgxhuxhgcotesivksfmvvxfvmtekacriwalaggmcgfexqknymrtg"
},
{
"input": "IKJYZIKROIYUUCTHSVSKZTETNNOCMAUBLFJCEVANCADASMZRCNLBZPQRXESHEEMOMEPCHROSRTNBIDXYMEPJSIXSZQEBTEKKUHFS",
"output": "ikjyzikroiyuucthsvskztetnnocmaublfjcevancadasmzrcnlbzpqrxesheemomepchrosrtnbidxymepjsixszqebtekkuhfs"
},
{
"input": "cTKDZNWVYRTFPQLDAUUNSPKTDJTUPPFPRXRSINTVFVNNQNKXWUZUDHZBUSOKTABUEDQKUIVRTTVUREEOBJTSDKJKVEGFXVHXEYPE",
"output": "Ctkdznwvyrtfpqldauunspktdjtuppfprxrsintvfvnnqnkxwuzudhzbusoktabuedqkuivrttvureeobjtsdkjkvegfxvhxeype"
},
{
"input": "uCKJZRGZJCPPLEEYJTUNKOQSWGBMTBQEVPYFPIPEKRVYQNTDPANOIXKMPINNFUSZWCURGBDPYTEKBEKCPMVZPMWAOSHJYMGKOMBQ",
"output": "Uckjzrgzjcppleeyjtunkoqswgbmtbqevpyfpipekrvyqntdpanoixkmpinnfuszwcurgbdpytekbekcpmvzpmwaoshjymgkombq"
},
{
"input": "KETAXTSWAAOBKUOKUQREHIOMVMMRSAEWKGXZKRASwTVNSSFSNIWYNPSTMRADOADEEBURRHPOOBIEUIBGYDJCEKPNLEUCANZYJKMR",
"output": "KETAXTSWAAOBKUOKUQREHIOMVMMRSAEWKGXZKRASwTVNSSFSNIWYNPSTMRADOADEEBURRHPOOBIEUIBGYDJCEKPNLEUCANZYJKMR"
},
{
"input": "ZEKGDMWJPVUWFlNXRLUmWKLMMYSLRQQIBRWDPKWITUIMZYYKOEYGREKHHZRZZUFPVTNIHKGTCCTLOKSZITXXZDMPITHNZUIGDZLE",
"output": "ZEKGDMWJPVUWFlNXRLUmWKLMMYSLRQQIBRWDPKWITUIMZYYKOEYGREKHHZRZZUFPVTNIHKGTCCTLOKSZITXXZDMPITHNZUIGDZLE"
},
{
"input": "TcMbVPCFvnNkCEUUCIFLgBJeCOKuJhIGwXFrhAZjuAhBraMSchBfWwIuHAEbgJOFzGtxDLDXzDSaPCFujGGxgxdlHUIQYRrMFCgJ",
"output": "TcMbVPCFvnNkCEUUCIFLgBJeCOKuJhIGwXFrhAZjuAhBraMSchBfWwIuHAEbgJOFzGtxDLDXzDSaPCFujGGxgxdlHUIQYRrMFCgJ"
},
{
"input": "xFGqoLILNvxARKuIntPfeukFtMbvzDezKpPRAKkIoIvwqNXnehRVwkkXYvuRCeoieBaBfTjwsYhDeCLvBwktntyluoxCYVioXGdm",
"output": "xFGqoLILNvxARKuIntPfeukFtMbvzDezKpPRAKkIoIvwqNXnehRVwkkXYvuRCeoieBaBfTjwsYhDeCLvBwktntyluoxCYVioXGdm"
},
{
"input": "udvqolbxdwbkijwvhlyaelhynmnfgszbhgshlcwdkaibceqomzujndixuzivlsjyjqxzxodzbukxxhwwultvekdfntwpzlhhrIjm",
"output": "udvqolbxdwbkijwvhlyaelhynmnfgszbhgshlcwdkaibceqomzujndixuzivlsjyjqxzxodzbukxxhwwultvekdfntwpzlhhrIjm"
},
{
"input": "jgpwhetqqoncighgzbbaLwwwxkxivuwtokehrgprfgewzcwxkavwoflcgsgbhoeamzbefzoonwsyzisetoydrpufktzgbaycgaeg",
"output": "jgpwhetqqoncighgzbbaLwwwxkxivuwtokehrgprfgewzcwxkavwoflcgsgbhoeamzbefzoonwsyzisetoydrpufktzgbaycgaeg"
},
{
"input": "vyujsazdstbnkxeunedfbolicojzjpufgfemhtmdrswvmuhoivjvonacefqenbqudelmdegxqtbwezsbydmanzutvdgkgrjxzlnc",
"output": "vyujsazdstbnkxeunedfbolicojzjpufgfemhtmdrswvmuhoivjvonacefqenbqudelmdegxqtbwezsbydmanzutvdgkgrjxzlnc"
},
{
"input": "pivqnuqkaofcduvbttztjbuavrqwiqrwkfncmvatoxruelyoecnkpqraiahumiaiqeyjapbqyrsxcdgjbihivtqezvasfmzntdfv",
"output": "pivqnuqkaofcduvbttztjbuavrqwiqrwkfncmvatoxruelyoecnkpqraiahumiaiqeyjapbqyrsxcdgjbihivtqezvasfmzntdfv"
},
{
"input": "upvtbsxswbohxshdrbjxcungzquhuomgxwlryvshshsfvqbrxvcikbglietlpqkiwbhiqpmdwuqosbtdvyxekkaqiwrbsibpoect",
"output": "upvtbsxswbohxshdrbjxcungzquhuomgxwlryvshshsfvqbrxvcikbglietlpqkiwbhiqpmdwuqosbtdvyxekkaqiwrbsibpoect"
},
{
"input": "cTKDZNWVYRTFPQLDAUUNSPKTDJTUPPFPRXRSINTVFVNNQNKXWUZUDHZBUSOKTABUEDQKUIVRTTVUREEOBJTSDKJKVEGFXVHXEYPE",
"output": "Ctkdznwvyrtfpqldauunspktdjtuppfprxrsintvfvnnqnkxwuzudhzbusoktabuedqkuivrttvureeobjtsdkjkvegfxvhxeype"
},
{
"input": "JEGDOFJOFGJHFROGHOFGMHOFGHORGFHMOu",
"output": "JEGDOFJOFGJHFROGHOFGMHOFGHORGFHMOu"
},
{
"input": "aBACABa",
"output": "aBACABa"
},
{
"input": "AAAAAAAAAAAAAAAAAAAAAAAAaa",
"output": "AAAAAAAAAAAAAAAAAAAAAAAAaa"
},
{
"input": "aaAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA",
"output": "aaAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"
},
{
"input": "dDDDDDDDDDDDDD",
"output": "Dddddddddddddd"
},
{
"input": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
"output": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
},
{
"input": "z",
"output": "Z"
},
{
"input": "AZ",
"output": "az"
},
{
"input": "Z",
"output": "z"
},
{
"input": "aAAAA",
"output": "Aaaaa"
},
{
"input": "F",
"output": "f"
}
] | 1,696,872,547 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 46 | 0 | word=input()
if word[0]==(word[0].capitalize()):
print(word[0]+word[1::])
else:
print((word[0].upper())+(word[1::].lower())) | Title: cAPS lOCK
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
wHAT DO WE NEED cAPS LOCK FOR?
Caps lock is a computer keyboard key. Pressing it sets an input mode in which typed letters are capital by default. If it is pressed by accident, it leads to accidents like the one we had in the first passage.
Let's consider that a word has been typed with the Caps lock key accidentally switched on, if:
- either it only contains uppercase letters; - or all letters except for the first one are uppercase.
In this case we should automatically change the case of all letters. For example, the case of the letters that form words "hELLO", "HTTP", "z" should be changed.
Write a program that applies the rule mentioned above. If the rule cannot be applied, the program should leave the word unchanged.
Input Specification:
The first line of the input data contains a word consisting of uppercase and lowercase Latin letters. The word's length is from 1 to 100 characters, inclusive.
Output Specification:
Print the result of the given word's processing.
Demo Input:
['cAPS\n', 'Lock\n']
Demo Output:
['Caps', 'Lock\n']
Note:
none | ```python
word=input()
if word[0]==(word[0].capitalize()):
print(word[0]+word[1::])
else:
print((word[0].upper())+(word[1::].lower()))
``` | 0 |
|
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,666,422,903 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 117 | 93 | 4,300,800 | length, maxChars = list(map(int, input().split()))
givenString = input()
fora = 0
changes = maxChars
left = 0
count = 0
for i in range(length):
count += givenString[i] == "a"
if (i - left + 1) - count <= maxChars:
fora = max(fora, i - left + 1)
else:
while left < i and (i - left + 1) - count > maxChars:
count -= givenString[left] == "a"
left += 1
forb = 0
changes = maxChars
left = 0
count = 0
for i in range(length):
count += givenString[i] == "b"
if (i - left + 1) - count <= maxChars:
forb = max(forb, i - left + 1)
else:
while left < i and (i - left + 1) - count > maxChars:
count -= givenString[left] == "b"
left += 1
print(max(fora, forb))
| 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
length, maxChars = list(map(int, input().split()))
givenString = input()
fora = 0
changes = maxChars
left = 0
count = 0
for i in range(length):
count += givenString[i] == "a"
if (i - left + 1) - count <= maxChars:
fora = max(fora, i - left + 1)
else:
while left < i and (i - left + 1) - count > maxChars:
count -= givenString[left] == "a"
left += 1
forb = 0
changes = maxChars
left = 0
count = 0
for i in range(length):
count += givenString[i] == "b"
if (i - left + 1) - count <= maxChars:
forb = max(forb, i - left + 1)
else:
while left < i and (i - left + 1) - count > maxChars:
count -= givenString[left] == "b"
left += 1
print(max(fora, forb))
``` | 3 |
|
946 | A | Partition | PROGRAMMING | 800 | [
"greedy"
] | null | null | You are given a sequence *a* consisting of *n* integers. You may partition this sequence into two sequences *b* and *c* in such a way that every element belongs exactly to one of these sequences.
Let *B* be the sum of elements belonging to *b*, and *C* be the sum of elements belonging to *c* (if some of these sequences is empty, then its sum is 0). What is the maximum possible value of *B*<=-<=*C*? | The first line contains one integer *n* (1<=≤<=*n*<=≤<=100) — the number of elements in *a*.
The second line contains *n* integers *a*1, *a*2, ..., *a**n* (<=-<=100<=≤<=*a**i*<=≤<=100) — the elements of sequence *a*. | Print the maximum possible value of *B*<=-<=*C*, where *B* is the sum of elements of sequence *b*, and *C* is the sum of elements of sequence *c*. | [
"3\n1 -2 0\n",
"6\n16 23 16 15 42 8\n"
] | [
"3\n",
"120\n"
] | In the first example we may choose *b* = {1, 0}, *c* = { - 2}. Then *B* = 1, *C* = - 2, *B* - *C* = 3.
In the second example we choose *b* = {16, 23, 16, 15, 42, 8}, *c* = {} (an empty sequence). Then *B* = 120, *C* = 0, *B* - *C* = 120. | 0 | [
{
"input": "3\n1 -2 0",
"output": "3"
},
{
"input": "6\n16 23 16 15 42 8",
"output": "120"
},
{
"input": "1\n-1",
"output": "1"
},
{
"input": "100\n-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 -100",
"output": "10000"
},
{
"input": "2\n-1 5",
"output": "6"
},
{
"input": "3\n-2 0 1",
"output": "3"
},
{
"input": "12\n-1 -2 -3 4 4 -6 -6 56 3 3 -3 3",
"output": "94"
},
{
"input": "4\n1 -1 1 -1",
"output": "4"
},
{
"input": "4\n100 -100 100 -100",
"output": "400"
},
{
"input": "3\n-2 -5 10",
"output": "17"
},
{
"input": "5\n1 -2 3 -4 5",
"output": "15"
},
{
"input": "3\n-100 100 -100",
"output": "300"
},
{
"input": "6\n1 -1 1 -1 1 -1",
"output": "6"
},
{
"input": "6\n2 -2 2 -2 2 -2",
"output": "12"
},
{
"input": "9\n12 93 -2 0 0 0 3 -3 -9",
"output": "122"
},
{
"input": "6\n-1 2 4 -5 -3 55",
"output": "70"
},
{
"input": "6\n-12 8 68 -53 1 -15",
"output": "157"
},
{
"input": "2\n-2 1",
"output": "3"
},
{
"input": "3\n100 -100 100",
"output": "300"
},
{
"input": "5\n100 100 -1 -100 2",
"output": "303"
},
{
"input": "6\n-5 -4 -3 -2 -1 0",
"output": "15"
},
{
"input": "6\n4 4 4 -3 -3 2",
"output": "20"
},
{
"input": "2\n-1 2",
"output": "3"
},
{
"input": "1\n100",
"output": "100"
},
{
"input": "5\n-1 -2 3 1 2",
"output": "9"
},
{
"input": "5\n100 -100 100 -100 100",
"output": "500"
},
{
"input": "5\n1 -1 1 -1 1",
"output": "5"
},
{
"input": "4\n0 0 0 -1",
"output": "1"
},
{
"input": "5\n100 -100 -1 2 100",
"output": "303"
},
{
"input": "2\n75 0",
"output": "75"
},
{
"input": "4\n55 56 -59 -58",
"output": "228"
},
{
"input": "2\n9 71",
"output": "80"
},
{
"input": "2\n9 70",
"output": "79"
},
{
"input": "2\n9 69",
"output": "78"
},
{
"input": "2\n100 -100",
"output": "200"
},
{
"input": "4\n-9 4 -9 5",
"output": "27"
},
{
"input": "42\n91 -27 -79 -56 80 -93 -23 10 80 94 61 -89 -64 81 34 99 31 -32 -69 92 79 -9 73 66 -8 64 99 99 58 -19 -40 21 1 -33 93 -23 -62 27 55 41 57 36",
"output": "2348"
},
{
"input": "7\n-1 2 2 2 -1 2 -1",
"output": "11"
},
{
"input": "6\n-12 8 17 -69 7 -88",
"output": "201"
},
{
"input": "3\n1 -2 5",
"output": "8"
},
{
"input": "6\n-2 3 -4 5 6 -1",
"output": "21"
},
{
"input": "2\n-5 1",
"output": "6"
},
{
"input": "4\n2 2 -2 4",
"output": "10"
},
{
"input": "68\n21 47 -75 -25 64 83 83 -21 89 24 43 44 -35 34 -42 92 -96 -52 -66 64 14 -87 25 -61 -78 83 -96 -18 95 83 -93 -28 75 49 87 65 -93 -69 -2 95 -24 -36 -61 -71 88 -53 -93 -51 -81 -65 -53 -46 -56 6 65 58 19 100 57 61 -53 44 -58 48 -8 80 -88 72",
"output": "3991"
},
{
"input": "5\n5 5 -10 -1 1",
"output": "22"
},
{
"input": "3\n-1 2 3",
"output": "6"
},
{
"input": "76\n57 -38 -48 -81 93 -32 96 55 -44 2 38 -46 42 64 71 -73 95 31 -39 -62 -1 75 -17 57 28 52 12 -11 82 -84 59 -86 73 -97 34 97 -57 -85 -6 39 -5 -54 95 24 -44 35 -18 9 91 7 -22 -61 -80 54 -40 74 -90 15 -97 66 -52 -49 -24 65 21 -93 -29 -24 -4 -1 76 -93 7 -55 -53 1",
"output": "3787"
},
{
"input": "5\n-1 -2 1 2 3",
"output": "9"
},
{
"input": "4\n2 2 -2 -2",
"output": "8"
},
{
"input": "6\n100 -100 100 -100 100 -100",
"output": "600"
},
{
"input": "100\n-59 -33 34 0 69 24 -22 58 62 -36 5 45 -19 -73 61 -9 95 42 -73 -64 91 -96 2 53 -8 82 -79 16 18 -5 -53 26 71 38 -31 12 -33 -1 -65 -6 3 -89 22 33 -27 -36 41 11 -47 -32 47 -56 -38 57 -63 -41 23 41 29 78 16 -65 90 -58 -12 6 -60 42 -36 -52 -54 -95 -10 29 70 50 -94 1 93 48 -71 -77 -16 54 56 -60 66 76 31 8 44 -61 -74 23 37 38 18 -18 29 41",
"output": "4362"
},
{
"input": "2\n-1 1",
"output": "2"
},
{
"input": "3\n1 -2 100",
"output": "103"
},
{
"input": "5\n1 -2 3 1 2",
"output": "9"
},
{
"input": "10\n100 -10 -100 10 10 10 10 10 10 10",
"output": "280"
},
{
"input": "4\n2 0 -2 4",
"output": "8"
},
{
"input": "4\n3 -3 1 -1",
"output": "8"
},
{
"input": "3\n1 -1 1",
"output": "3"
},
{
"input": "4\n2 5 -2 4",
"output": "13"
},
{
"input": "2\n-2 2",
"output": "4"
},
{
"input": "3\n1 -2 1",
"output": "4"
},
{
"input": "5\n-1 -2 1 1 -1",
"output": "6"
},
{
"input": "4\n-2 0 2 4",
"output": "8"
},
{
"input": "8\n-42 7 87 -16 -5 65 -88 1",
"output": "311"
},
{
"input": "3\n1 -3 4",
"output": "8"
},
{
"input": "1\n1",
"output": "1"
},
{
"input": "2\n0 1",
"output": "1"
},
{
"input": "3\n-1 2 -1",
"output": "4"
},
{
"input": "18\n-21 12 65 66 -24 62 82 35 -45 -47 28 37 5 -32 22 -14 -69 -95",
"output": "761"
},
{
"input": "4\n-1 1 -1 1",
"output": "4"
},
{
"input": "5\n-1 2 1 1 1",
"output": "6"
},
{
"input": "3\n1 1 1",
"output": "3"
}
] | 1,561,994,036 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 2 | 78 | 307,200 | a=int(input())
b=input().split()
r=len(b)
i=0
lst1=[]
lst2=[]
j=0
k=0
l=0
m=0
if(r==a):
for i in range(r):
v=int(b[i])
if(v>=0):
lst1.append(v)
else:
lst2.append(v)
x=len(lst1)
y=len(lst2)
for j in range(x):
c=lst1[j]
l=l+c
e=min(lst1)
for k in range(y):
d=lst2[k]
m=m+d
s=min(lst2)
if(x>0 and y>0):
z=l-m
elif(x>0 and y==0):
z=l
elif(x==0 and y<0):
z=(2*s)-m
elif(x==0 and y==0):
z=0
print(z)
| Title: Partition
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given a sequence *a* consisting of *n* integers. You may partition this sequence into two sequences *b* and *c* in such a way that every element belongs exactly to one of these sequences.
Let *B* be the sum of elements belonging to *b*, and *C* be the sum of elements belonging to *c* (if some of these sequences is empty, then its sum is 0). What is the maximum possible value of *B*<=-<=*C*?
Input Specification:
The first line contains one integer *n* (1<=≤<=*n*<=≤<=100) — the number of elements in *a*.
The second line contains *n* integers *a*1, *a*2, ..., *a**n* (<=-<=100<=≤<=*a**i*<=≤<=100) — the elements of sequence *a*.
Output Specification:
Print the maximum possible value of *B*<=-<=*C*, where *B* is the sum of elements of sequence *b*, and *C* is the sum of elements of sequence *c*.
Demo Input:
['3\n1 -2 0\n', '6\n16 23 16 15 42 8\n']
Demo Output:
['3\n', '120\n']
Note:
In the first example we may choose *b* = {1, 0}, *c* = { - 2}. Then *B* = 1, *C* = - 2, *B* - *C* = 3.
In the second example we choose *b* = {16, 23, 16, 15, 42, 8}, *c* = {} (an empty sequence). Then *B* = 120, *C* = 0, *B* - *C* = 120. | ```python
a=int(input())
b=input().split()
r=len(b)
i=0
lst1=[]
lst2=[]
j=0
k=0
l=0
m=0
if(r==a):
for i in range(r):
v=int(b[i])
if(v>=0):
lst1.append(v)
else:
lst2.append(v)
x=len(lst1)
y=len(lst2)
for j in range(x):
c=lst1[j]
l=l+c
e=min(lst1)
for k in range(y):
d=lst2[k]
m=m+d
s=min(lst2)
if(x>0 and y>0):
z=l-m
elif(x>0 and y==0):
z=l
elif(x==0 and y<0):
z=(2*s)-m
elif(x==0 and y==0):
z=0
print(z)
``` | -1 |
|
408 | A | Line to Cashier | PROGRAMMING | 900 | [
"implementation"
] | null | null | Little Vasya went to the supermarket to get some groceries. He walked about the supermarket for a long time and got a basket full of products. Now he needs to choose the cashier to pay for the products.
There are *n* cashiers at the exit from the supermarket. At the moment the queue for the *i*-th cashier already has *k**i* people. The *j*-th person standing in the queue to the *i*-th cashier has *m**i*,<=*j* items in the basket. Vasya knows that:
- the cashier needs 5 seconds to scan one item; - after the cashier scans each item of some customer, he needs 15 seconds to take the customer's money and give him the change.
Of course, Vasya wants to select a queue so that he can leave the supermarket as soon as possible. Help him write a program that displays the minimum number of seconds after which Vasya can get to one of the cashiers. | The first line contains integer *n* (1<=≤<=*n*<=≤<=100) — the number of cashes in the shop. The second line contains *n* space-separated integers: *k*1,<=*k*2,<=...,<=*k**n* (1<=≤<=*k**i*<=≤<=100), where *k**i* is the number of people in the queue to the *i*-th cashier.
The *i*-th of the next *n* lines contains *k**i* space-separated integers: *m**i*,<=1,<=*m**i*,<=2,<=...,<=*m**i*,<=*k**i* (1<=≤<=*m**i*,<=*j*<=≤<=100) — the number of products the *j*-th person in the queue for the *i*-th cash has. | Print a single integer — the minimum number of seconds Vasya needs to get to the cashier. | [
"1\n1\n1\n",
"4\n1 4 3 2\n100\n1 2 2 3\n1 9 1\n7 8\n"
] | [
"20\n",
"100\n"
] | In the second test sample, if Vasya goes to the first queue, he gets to the cashier in 100·5 + 15 = 515 seconds. But if he chooses the second queue, he will need 1·5 + 2·5 + 2·5 + 3·5 + 4·15 = 100 seconds. He will need 1·5 + 9·5 + 1·5 + 3·15 = 100 seconds for the third one and 7·5 + 8·5 + 2·15 = 105 seconds for the fourth one. Thus, Vasya gets to the cashier quicker if he chooses the second or the third queue. | 500 | [
{
"input": "1\n1\n1",
"output": "20"
},
{
"input": "4\n1 4 3 2\n100\n1 2 2 3\n1 9 1\n7 8",
"output": "100"
},
{
"input": "4\n5 4 5 5\n3 1 3 1 2\n3 1 1 3\n1 1 1 2 2\n2 2 1 1 3",
"output": "100"
},
{
"input": "5\n5 3 6 6 4\n7 5 3 3 9\n6 8 2\n1 10 8 5 9 2\n9 7 8 5 9 10\n9 8 3 3",
"output": "125"
},
{
"input": "5\n10 10 10 10 10\n6 7 8 6 8 5 9 8 10 5\n9 6 9 8 7 8 8 10 8 5\n8 7 7 8 7 5 6 8 9 5\n6 5 10 5 5 10 7 8 5 5\n10 9 8 7 6 9 7 9 6 5",
"output": "480"
},
{
"input": "10\n9 10 10 10 9 5 9 7 8 7\n11 6 10 4 4 15 7 15 5\n3 9 11 12 11 1 13 13 1 5\n6 15 9 12 3 2 8 12 11 10\n7 1 1 6 10 2 6 1 14 2\n8 14 2 3 6 1 14 1 12\n6 10 9 3 5\n13 12 12 7 13 4 4 8 10\n5 6 4 3 14 9 13\n8 12 1 5 7 4 13 1\n1 9 5 3 5 1 4",
"output": "240"
},
{
"input": "10\n5 5 5 5 5 5 5 5 5 5\n5 5 4 5 4\n6 5 7 7 6\n5 4 4 5 5\n4 4 5 5 5\n7 6 4 5 7\n4 6 5 4 5\n6 6 7 6 6\n4 5 4 4 7\n7 5 4 4 5\n6 6 7 4 4",
"output": "190"
},
{
"input": "1\n1\n100",
"output": "515"
},
{
"input": "1\n90\n90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90",
"output": "41850"
}
] | 1,639,157,569 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 20 | 124 | 1,228,800 | cashes = int(input())
list_res = []
q = list()
q = list(map(int,input().strip().split()))[:cashes]
i = 0
for j in range (0, len(q)):
sum1 = 0
list_temp = list(map(int, input().strip().split()))[:]
sum1 = 5 * sum(list_temp)
list_res.append(sum1 + (q[i] * 15))
i += 1
print(min(list_res))
| Title: Line to Cashier
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Little Vasya went to the supermarket to get some groceries. He walked about the supermarket for a long time and got a basket full of products. Now he needs to choose the cashier to pay for the products.
There are *n* cashiers at the exit from the supermarket. At the moment the queue for the *i*-th cashier already has *k**i* people. The *j*-th person standing in the queue to the *i*-th cashier has *m**i*,<=*j* items in the basket. Vasya knows that:
- the cashier needs 5 seconds to scan one item; - after the cashier scans each item of some customer, he needs 15 seconds to take the customer's money and give him the change.
Of course, Vasya wants to select a queue so that he can leave the supermarket as soon as possible. Help him write a program that displays the minimum number of seconds after which Vasya can get to one of the cashiers.
Input Specification:
The first line contains integer *n* (1<=≤<=*n*<=≤<=100) — the number of cashes in the shop. The second line contains *n* space-separated integers: *k*1,<=*k*2,<=...,<=*k**n* (1<=≤<=*k**i*<=≤<=100), where *k**i* is the number of people in the queue to the *i*-th cashier.
The *i*-th of the next *n* lines contains *k**i* space-separated integers: *m**i*,<=1,<=*m**i*,<=2,<=...,<=*m**i*,<=*k**i* (1<=≤<=*m**i*,<=*j*<=≤<=100) — the number of products the *j*-th person in the queue for the *i*-th cash has.
Output Specification:
Print a single integer — the minimum number of seconds Vasya needs to get to the cashier.
Demo Input:
['1\n1\n1\n', '4\n1 4 3 2\n100\n1 2 2 3\n1 9 1\n7 8\n']
Demo Output:
['20\n', '100\n']
Note:
In the second test sample, if Vasya goes to the first queue, he gets to the cashier in 100·5 + 15 = 515 seconds. But if he chooses the second queue, he will need 1·5 + 2·5 + 2·5 + 3·5 + 4·15 = 100 seconds. He will need 1·5 + 9·5 + 1·5 + 3·15 = 100 seconds for the third one and 7·5 + 8·5 + 2·15 = 105 seconds for the fourth one. Thus, Vasya gets to the cashier quicker if he chooses the second or the third queue. | ```python
cashes = int(input())
list_res = []
q = list()
q = list(map(int,input().strip().split()))[:cashes]
i = 0
for j in range (0, len(q)):
sum1 = 0
list_temp = list(map(int, input().strip().split()))[:]
sum1 = 5 * sum(list_temp)
list_res.append(sum1 + (q[i] * 15))
i += 1
print(min(list_res))
``` | 3 |
|
714 | A | Meeting of Old Friends | PROGRAMMING | 1,100 | [
"implementation",
"math"
] | null | null | Today an outstanding event is going to happen in the forest — hedgehog Filya will come to his old fried Sonya!
Sonya is an owl and she sleeps during the day and stay awake from minute *l*1 to minute *r*1 inclusive. Also, during the minute *k* she prinks and is unavailable for Filya.
Filya works a lot and he plans to visit Sonya from minute *l*2 to minute *r*2 inclusive.
Calculate the number of minutes they will be able to spend together. | The only line of the input contains integers *l*1, *r*1, *l*2, *r*2 and *k* (1<=≤<=*l*1,<=*r*1,<=*l*2,<=*r*2,<=*k*<=≤<=1018, *l*1<=≤<=*r*1, *l*2<=≤<=*r*2), providing the segments of time for Sonya and Filya and the moment of time when Sonya prinks. | Print one integer — the number of minutes Sonya and Filya will be able to spend together. | [
"1 10 9 20 1\n",
"1 100 50 200 75\n"
] | [
"2\n",
"50\n"
] | In the first sample, they will be together during minutes 9 and 10.
In the second sample, they will be together from minute 50 to minute 74 and from minute 76 to minute 100. | 500 | [
{
"input": "1 10 9 20 1",
"output": "2"
},
{
"input": "1 100 50 200 75",
"output": "50"
},
{
"input": "6 6 5 8 9",
"output": "1"
},
{
"input": "1 1000000000 1 1000000000 1",
"output": "999999999"
},
{
"input": "5 100 8 8 8",
"output": "0"
},
{
"input": "1 1000000000000000000 2 99999999999999999 1000000000",
"output": "99999999999999997"
},
{
"input": "1 1 1 1 1",
"output": "0"
},
{
"input": "1 2 3 4 5",
"output": "0"
},
{
"input": "1 1000000000 2 999999999 3141592",
"output": "999999997"
},
{
"input": "24648817341102 41165114064236 88046848035 13602161452932 10000831349205",
"output": "0"
},
{
"input": "1080184299348 34666828555290 6878390132365 39891656267344 15395310291636",
"output": "27788438422925"
},
{
"input": "11814 27385 22309 28354 23595",
"output": "5076"
},
{
"input": "4722316546398 36672578279675 796716437180 33840047334985 13411035401708",
"output": "29117730788587"
},
{
"input": "14300093617438 14381698008501 6957847034861 32510754974307 66056597033082",
"output": "81604391064"
},
{
"input": "700062402405871919 762322967106512617 297732773882447821 747309903322652819 805776739998108178",
"output": "47247500916780901"
},
{
"input": "59861796371397621 194872039092923459 668110259718450585 841148673332698972 928360292123223779",
"output": "0"
},
{
"input": "298248781360904821 346420922793050061 237084570581741798 726877079564549183 389611850470532358",
"output": "48172141432145241"
},
{
"input": "420745791717606818 864206437350900994 764928840030524015 966634105370748487 793326512080703489",
"output": "99277597320376979"
},
{
"input": "519325240668210886 776112702001665034 360568516809443669 875594219634943179 994594983925273138",
"output": "256787461333454149"
},
{
"input": "170331212821058551 891149660635282032 125964175621755330 208256491683509799 526532153531983174",
"output": "37925278862451249"
},
{
"input": "1 3 3 5 3",
"output": "0"
},
{
"input": "1 5 8 10 9",
"output": "0"
},
{
"input": "1 2 4 5 10",
"output": "0"
},
{
"input": "1 2 2 3 5",
"output": "1"
},
{
"input": "2 4 3 7 3",
"output": "1"
},
{
"input": "1 2 9 10 1",
"output": "0"
},
{
"input": "5 15 1 10 5",
"output": "5"
},
{
"input": "1 4 9 20 25",
"output": "0"
},
{
"input": "2 4 1 2 5",
"output": "1"
},
{
"input": "10 1000 1 100 2",
"output": "91"
},
{
"input": "1 3 3 8 10",
"output": "1"
},
{
"input": "4 6 6 8 9",
"output": "1"
},
{
"input": "2 3 1 4 3",
"output": "1"
},
{
"input": "1 2 2 3 100",
"output": "1"
},
{
"input": "1 2 100 120 2",
"output": "0"
},
{
"input": "1 3 5 7 4",
"output": "0"
},
{
"input": "1 3 5 7 5",
"output": "0"
},
{
"input": "1 4 8 10 6",
"output": "0"
},
{
"input": "1 2 5 6 100",
"output": "0"
},
{
"input": "1 2 5 10 20",
"output": "0"
},
{
"input": "1 2 5 6 7",
"output": "0"
},
{
"input": "2 5 7 12 6",
"output": "0"
},
{
"input": "10 20 50 100 80",
"output": "0"
},
{
"input": "1 2 5 10 2",
"output": "0"
},
{
"input": "1 2 5 6 4",
"output": "0"
},
{
"input": "5 9 1 2 3",
"output": "0"
},
{
"input": "50 100 1 20 3",
"output": "0"
},
{
"input": "10 20 3 7 30",
"output": "0"
},
{
"input": "1 5 10 10 100",
"output": "0"
},
{
"input": "100 101 1 2 3",
"output": "0"
},
{
"input": "1 5 10 20 6",
"output": "0"
},
{
"input": "1 10 15 25 5",
"output": "0"
},
{
"input": "1 2 5 10 3",
"output": "0"
},
{
"input": "2 3 5 6 100",
"output": "0"
},
{
"input": "1 2 4 5 6",
"output": "0"
},
{
"input": "6 10 1 2 40",
"output": "0"
},
{
"input": "20 30 1 5 1",
"output": "0"
},
{
"input": "20 40 50 100 50",
"output": "0"
},
{
"input": "1 1 4 9 2",
"output": "0"
},
{
"input": "1 2 5 6 1",
"output": "0"
},
{
"input": "1 100 400 500 450",
"output": "0"
},
{
"input": "5 6 1 2 5",
"output": "0"
},
{
"input": "1 10 21 30 50",
"output": "0"
},
{
"input": "100 200 300 400 101",
"output": "0"
},
{
"input": "2 8 12 16 9",
"output": "0"
},
{
"input": "1 5 7 9 6",
"output": "0"
},
{
"input": "300 400 100 200 101",
"output": "0"
},
{
"input": "1 2 2 3 10",
"output": "1"
},
{
"input": "1 10 100 200 5",
"output": "0"
},
{
"input": "1 3 3 4 4",
"output": "1"
},
{
"input": "10 20 30 40 25",
"output": "0"
},
{
"input": "1 2 5 10 1",
"output": "0"
},
{
"input": "2 4 8 10 1",
"output": "0"
},
{
"input": "2 5 10 15 7",
"output": "0"
},
{
"input": "100 200 5 10 1",
"output": "0"
},
{
"input": "1 2 100 200 300",
"output": "0"
},
{
"input": "30 100 10 20 25",
"output": "0"
},
{
"input": "10 20 1 5 6",
"output": "0"
},
{
"input": "4 5 1 2 4",
"output": "0"
},
{
"input": "11 100 1 9 1000",
"output": "0"
},
{
"input": "1 1 10 10 228",
"output": "0"
},
{
"input": "5 7 10 20 15",
"output": "0"
},
{
"input": "1 3 8 9 7",
"output": "0"
},
{
"input": "1 10 2 8 8",
"output": "6"
},
{
"input": "1 5 9 15 1",
"output": "0"
},
{
"input": "1 3 5 6 12",
"output": "0"
},
{
"input": "1 100 500 1000 3",
"output": "0"
},
{
"input": "1 1 1 1 2",
"output": "1"
},
{
"input": "1 1000 100 1000 200",
"output": "900"
},
{
"input": "4 5 1 4 1",
"output": "1"
},
{
"input": "1 5 5 7 3",
"output": "1"
},
{
"input": "1 4 4 10 11",
"output": "1"
},
{
"input": "1 1 3 4 100",
"output": "0"
},
{
"input": "1 4 3 5 6",
"output": "2"
},
{
"input": "10 100 20 30 40",
"output": "11"
},
{
"input": "5 9 1 11 7",
"output": "4"
}
] | 1,597,100,033 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 5 | 1,000 | 6,656,000 |
l1 , r1 , l2 , r2 , k = map(int,input().split())
x = max(l1 , l2)
y = min(r1 , r2)
res = y - x + 1
if y < x :
print(0)
exit()
else:
for i in range(x , y+1):
if i > k :
break
if i == k :
res -=1
print(res)
| Title: Meeting of Old Friends
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Today an outstanding event is going to happen in the forest — hedgehog Filya will come to his old fried Sonya!
Sonya is an owl and she sleeps during the day and stay awake from minute *l*1 to minute *r*1 inclusive. Also, during the minute *k* she prinks and is unavailable for Filya.
Filya works a lot and he plans to visit Sonya from minute *l*2 to minute *r*2 inclusive.
Calculate the number of minutes they will be able to spend together.
Input Specification:
The only line of the input contains integers *l*1, *r*1, *l*2, *r*2 and *k* (1<=≤<=*l*1,<=*r*1,<=*l*2,<=*r*2,<=*k*<=≤<=1018, *l*1<=≤<=*r*1, *l*2<=≤<=*r*2), providing the segments of time for Sonya and Filya and the moment of time when Sonya prinks.
Output Specification:
Print one integer — the number of minutes Sonya and Filya will be able to spend together.
Demo Input:
['1 10 9 20 1\n', '1 100 50 200 75\n']
Demo Output:
['2\n', '50\n']
Note:
In the first sample, they will be together during minutes 9 and 10.
In the second sample, they will be together from minute 50 to minute 74 and from minute 76 to minute 100. | ```python
l1 , r1 , l2 , r2 , k = map(int,input().split())
x = max(l1 , l2)
y = min(r1 , r2)
res = y - x + 1
if y < x :
print(0)
exit()
else:
for i in range(x , y+1):
if i > k :
break
if i == k :
res -=1
print(res)
``` | 0 |
|
467 | C | George and Job | PROGRAMMING | 1,700 | [
"dp",
"implementation"
] | null | null | The new ITone 6 has been released recently and George got really keen to buy it. Unfortunately, he didn't have enough money, so George was going to work as a programmer. Now he faced the following problem at the work.
Given a sequence of *n* integers *p*1,<=*p*2,<=...,<=*p**n*. You are to choose *k* pairs of integers:
in such a way that the value of sum is maximal possible. Help George to cope with the task. | The first line contains three integers *n*, *m* and *k* (1<=≤<=(*m*<=×<=*k*)<=≤<=*n*<=≤<=5000). The second line contains *n* integers *p*1,<=*p*2,<=...,<=*p**n* (0<=≤<=*p**i*<=≤<=109). | Print an integer in a single line — the maximum possible value of sum. | [
"5 2 1\n1 2 3 4 5\n",
"7 1 3\n2 10 7 18 5 33 0\n"
] | [
"9\n",
"61\n"
] | none | 1,500 | [
{
"input": "5 2 1\n1 2 3 4 5",
"output": "9"
},
{
"input": "7 1 3\n2 10 7 18 5 33 0",
"output": "61"
},
{
"input": "13 8 1\n73 7 47 91 54 74 99 11 67 35 84 18 19",
"output": "515"
},
{
"input": "8 3 1\n8 46 37 81 81 57 11 2",
"output": "219"
},
{
"input": "20 5 3\n96 46 67 36 59 95 88 43 92 58 1 31 69 35 36 77 56 27 3 23",
"output": "953"
},
{
"input": "16 2 2\n50 78 5 26 26 16 14 35 46 8 37 31 92 52 97 24",
"output": "277"
},
{
"input": "22 1 6\n21 34 48 26 37 85 24 85 57 92 88 53 17 7 47 2 60 50 91 3 3 26",
"output": "501"
},
{
"input": "58 19 3\n48 40 71 80 100 53 52 74 36 3 77 1 87 93 57 98 21 46 78 13 69 29 33 96 36 9 90 30 52 82 70 92 40 34 81 33 20 66 0 64 64 80 16 90 17 42 55 92 17 1 67 0 97 14 84 90 93 13",
"output": "3086"
},
{
"input": "26 4 3\n21 97 29 7 22 27 96 99 52 63 30 12 2 9 32 18 95 50 22 67 43 63 64 35 64 11",
"output": "770"
},
{
"input": "79 7 7\n100 78 47 26 94 48 31 56 50 42 1 93 73 83 25 77 83 72 16 21 92 93 91 60 16 9 67 92 22 30 92 38 9 57 77 61 79 28 79 91 29 2 88 79 20 18 46 32 32 14 63 25 82 12 87 17 84 8 34 45 26 38 69 85 52 47 5 89 88 2 0 60 77 2 1 12 98 95 24",
"output": "2980"
},
{
"input": "141 12 6\n66 53 86 91 12 27 5 74 79 50 33 2 100 26 2 73 16 14 50 86 75 9 66 48 19 34 25 1 22 50 63 39 38 42 98 71 76 27 80 16 74 21 36 1 32 20 65 28 68 40 41 6 0 77 65 84 0 34 60 0 42 65 2 16 25 85 35 57 74 66 26 33 39 14 0 6 2 15 87 99 47 67 75 63 72 32 93 7 5 63 35 99 89 61 18 25 76 5 39 80 37 17 78 23 61 98 16 7 21 70 74 32 28 81 25 4 31 19 86 28 55 16 9 92 16 69 97 78 36 89 15 60 46 97 26 23 37 61 51 85 42",
"output": "3887"
},
{
"input": "1 1 1\n1",
"output": "1"
},
{
"input": "2 2 1\n1 0",
"output": "1"
},
{
"input": "2 1 1\n10 11",
"output": "11"
},
{
"input": "2 1 1\n0 0",
"output": "0"
},
{
"input": "6 2 1\n1 1 10 1 20 10",
"output": "30"
},
{
"input": "23 2 4\n965481468 524609549 327408602 598336282 745920261 141281382 661619186 475657944 798069657 19918618 428716536 140019227 432712846 201739661 639584480 639986280 125110008 156951910 45355489 331043204 811313708 662402183 999999999",
"output": "5776320502"
},
{
"input": "5 2 2\n1 5 3 7 9",
"output": "24"
},
{
"input": "3 2 1\n1 2 3",
"output": "5"
},
{
"input": "6 2 2\n1 100 10 10000000 7 99",
"output": "10000117"
},
{
"input": "6 2 3\n1000000000 1000000000 1000000000 1000000000 1000000000 1000000000",
"output": "6000000000"
},
{
"input": "10 1 10\n1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000",
"output": "10000000000"
}
] | 1,696,946,808 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 9 | 1,000 | 0 | n, m, k=map(int, input().split())
arr=list(map(int, input().split()))
def Great(n,m,k,arr):
my_sum=0
if k==0:
return 0
for i in range (n-m*k+1):
my_sum=max(my_sum,sum(arr[i:i+m])+Great(n-i-m,m,k-1,arr[i+m:]))
return my_sum
print(Great(n,m,k,arr)) | Title: George and Job
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The new ITone 6 has been released recently and George got really keen to buy it. Unfortunately, he didn't have enough money, so George was going to work as a programmer. Now he faced the following problem at the work.
Given a sequence of *n* integers *p*1,<=*p*2,<=...,<=*p**n*. You are to choose *k* pairs of integers:
in such a way that the value of sum is maximal possible. Help George to cope with the task.
Input Specification:
The first line contains three integers *n*, *m* and *k* (1<=≤<=(*m*<=×<=*k*)<=≤<=*n*<=≤<=5000). The second line contains *n* integers *p*1,<=*p*2,<=...,<=*p**n* (0<=≤<=*p**i*<=≤<=109).
Output Specification:
Print an integer in a single line — the maximum possible value of sum.
Demo Input:
['5 2 1\n1 2 3 4 5\n', '7 1 3\n2 10 7 18 5 33 0\n']
Demo Output:
['9\n', '61\n']
Note:
none | ```python
n, m, k=map(int, input().split())
arr=list(map(int, input().split()))
def Great(n,m,k,arr):
my_sum=0
if k==0:
return 0
for i in range (n-m*k+1):
my_sum=max(my_sum,sum(arr[i:i+m])+Great(n-i-m,m,k-1,arr[i+m:]))
return my_sum
print(Great(n,m,k,arr))
``` | 0 |
|
371 | B | Fox Dividing Cheese | PROGRAMMING | 1,300 | [
"math",
"number theory"
] | null | null | Two little greedy bears have found two pieces of cheese in the forest of weight *a* and *b* grams, correspondingly. The bears are so greedy that they are ready to fight for the larger piece. That's where the fox comes in and starts the dialog: "Little bears, wait a little, I want to make your pieces equal" "Come off it fox, how are you going to do that?", the curious bears asked. "It's easy", said the fox. "If the mass of a certain piece is divisible by two, then I can eat exactly a half of the piece. If the mass of a certain piece is divisible by three, then I can eat exactly two-thirds, and if the mass is divisible by five, then I can eat four-fifths. I'll eat a little here and there and make the pieces equal".
The little bears realize that the fox's proposal contains a catch. But at the same time they realize that they can not make the two pieces equal themselves. So they agreed to her proposal, but on one condition: the fox should make the pieces equal as quickly as possible. Find the minimum number of operations the fox needs to make pieces equal. | The first line contains two space-separated integers *a* and *b* (1<=≤<=*a*,<=*b*<=≤<=109). | If the fox is lying to the little bears and it is impossible to make the pieces equal, print -1. Otherwise, print the required minimum number of operations. If the pieces of the cheese are initially equal, the required number is 0. | [
"15 20\n",
"14 8\n",
"6 6\n"
] | [
"3\n",
"-1\n",
"0\n"
] | none | 1,000 | [
{
"input": "15 20",
"output": "3"
},
{
"input": "14 8",
"output": "-1"
},
{
"input": "6 6",
"output": "0"
},
{
"input": "1 1",
"output": "0"
},
{
"input": "1 1024",
"output": "10"
},
{
"input": "1024 729",
"output": "16"
},
{
"input": "1024 1048576",
"output": "10"
},
{
"input": "36 30",
"output": "3"
},
{
"input": "100 10",
"output": "2"
},
{
"input": "21 35",
"output": "2"
},
{
"input": "9900 7128",
"output": "5"
},
{
"input": "7920 9900",
"output": "3"
},
{
"input": "576000 972000",
"output": "7"
},
{
"input": "691200 583200",
"output": "8"
},
{
"input": "607500 506250",
"output": "3"
},
{
"input": "881280 765000",
"output": "9"
},
{
"input": "800000 729000",
"output": "13"
},
{
"input": "792000 792000",
"output": "0"
},
{
"input": "513600 513600",
"output": "0"
},
{
"input": "847500 610200",
"output": "5"
},
{
"input": "522784320 784176480",
"output": "2"
},
{
"input": "689147136 861433920",
"output": "3"
},
{
"input": "720212000 864254400",
"output": "3"
},
{
"input": "673067520 807681024",
"output": "3"
},
{
"input": "919536000 993098880",
"output": "5"
},
{
"input": "648293430 540244525",
"output": "3"
},
{
"input": "537814642 537814642",
"output": "0"
},
{
"input": "100000007 800000011",
"output": "-1"
},
{
"input": "900000011 800000011",
"output": "-1"
},
{
"input": "900000011 999900017",
"output": "-1"
},
{
"input": "536870912 387420489",
"output": "47"
},
{
"input": "820125000 874800000",
"output": "6"
},
{
"input": "864000000 607500000",
"output": "9"
},
{
"input": "609120000 913680000",
"output": "2"
},
{
"input": "509607936 306110016",
"output": "24"
},
{
"input": "445906944 528482304",
"output": "8"
},
{
"input": "119144448 423624704",
"output": "7"
},
{
"input": "1 1000000000",
"output": "18"
},
{
"input": "1000000000 1",
"output": "18"
},
{
"input": "1000000000 2",
"output": "17"
},
{
"input": "2 1000000000",
"output": "17"
},
{
"input": "5 1000000000",
"output": "17"
},
{
"input": "1000000000 5",
"output": "17"
},
{
"input": "3 1000000000",
"output": "19"
},
{
"input": "1000000000 3",
"output": "19"
},
{
"input": "1000000000 7",
"output": "-1"
},
{
"input": "2208870 122715",
"output": "3"
},
{
"input": "4812500 7577955",
"output": "16"
},
{
"input": "3303936 3097440",
"output": "6"
},
{
"input": "55404 147744",
"output": "4"
},
{
"input": "10332160 476643528",
"output": "19"
},
{
"input": "21751200 43502400",
"output": "1"
},
{
"input": "19500000 140400000",
"output": "5"
},
{
"input": "1 22",
"output": "-1"
}
] | 1,635,534,765 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 3 | 31 | 4,505,600 | def gcd(a, b):
if b == 0:
return a
return gcd(b, a % b)
cheese1, cheese2 = list(int(num) for num in input().split(" "))
max = gcd(cheese1, cheese2)
aux_cheese1 = cheese1 / max
aux_cheese2 = cheese2 / max
divisors = [2, 3, 5]
exp_cheese1 = [0, 0, 0]
exp_cheese2 = [0, 0, 0]
operations = 0
final_cheese1 = max
final_cheese2 = max
if max != 1:
for i in range(3):
divisor = divisors[i]
times_cheese1 = 0
times_cheese2 = 0
while aux_cheese1 % divisor == 0:
aux_cheese1 /= divisor
times_cheese1 += 1
while aux_cheese2 % divisor == 0:
aux_cheese2 /= divisor
times_cheese2 += 1
exp_cheese1[i] = times_cheese1
exp_cheese2[i] = times_cheese2
final_cheese1 *= divisor ** times_cheese1
final_cheese2 *= divisor ** times_cheese2
operations += times_cheese1 + times_cheese2
if final_cheese2 != cheese2 or final_cheese1 != cheese1:
operations = -1
else:
operations = -1
print(operations)
| Title: Fox Dividing Cheese
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Two little greedy bears have found two pieces of cheese in the forest of weight *a* and *b* grams, correspondingly. The bears are so greedy that they are ready to fight for the larger piece. That's where the fox comes in and starts the dialog: "Little bears, wait a little, I want to make your pieces equal" "Come off it fox, how are you going to do that?", the curious bears asked. "It's easy", said the fox. "If the mass of a certain piece is divisible by two, then I can eat exactly a half of the piece. If the mass of a certain piece is divisible by three, then I can eat exactly two-thirds, and if the mass is divisible by five, then I can eat four-fifths. I'll eat a little here and there and make the pieces equal".
The little bears realize that the fox's proposal contains a catch. But at the same time they realize that they can not make the two pieces equal themselves. So they agreed to her proposal, but on one condition: the fox should make the pieces equal as quickly as possible. Find the minimum number of operations the fox needs to make pieces equal.
Input Specification:
The first line contains two space-separated integers *a* and *b* (1<=≤<=*a*,<=*b*<=≤<=109).
Output Specification:
If the fox is lying to the little bears and it is impossible to make the pieces equal, print -1. Otherwise, print the required minimum number of operations. If the pieces of the cheese are initially equal, the required number is 0.
Demo Input:
['15 20\n', '14 8\n', '6 6\n']
Demo Output:
['3\n', '-1\n', '0\n']
Note:
none | ```python
def gcd(a, b):
if b == 0:
return a
return gcd(b, a % b)
cheese1, cheese2 = list(int(num) for num in input().split(" "))
max = gcd(cheese1, cheese2)
aux_cheese1 = cheese1 / max
aux_cheese2 = cheese2 / max
divisors = [2, 3, 5]
exp_cheese1 = [0, 0, 0]
exp_cheese2 = [0, 0, 0]
operations = 0
final_cheese1 = max
final_cheese2 = max
if max != 1:
for i in range(3):
divisor = divisors[i]
times_cheese1 = 0
times_cheese2 = 0
while aux_cheese1 % divisor == 0:
aux_cheese1 /= divisor
times_cheese1 += 1
while aux_cheese2 % divisor == 0:
aux_cheese2 /= divisor
times_cheese2 += 1
exp_cheese1[i] = times_cheese1
exp_cheese2[i] = times_cheese2
final_cheese1 *= divisor ** times_cheese1
final_cheese2 *= divisor ** times_cheese2
operations += times_cheese1 + times_cheese2
if final_cheese2 != cheese2 or final_cheese1 != cheese1:
operations = -1
else:
operations = -1
print(operations)
``` | 0 |
|
492 | B | Vanya and Lanterns | PROGRAMMING | 1,200 | [
"binary search",
"implementation",
"math",
"sortings"
] | null | null | Vanya walks late at night along a straight street of length *l*, lit by *n* lanterns. Consider the coordinate system with the beginning of the street corresponding to the point 0, and its end corresponding to the point *l*. Then the *i*-th lantern is at the point *a**i*. The lantern lights all points of the street that are at the distance of at most *d* from it, where *d* is some positive number, common for all lanterns.
Vanya wonders: what is the minimum light radius *d* should the lanterns have to light the whole street? | The first line contains two integers *n*, *l* (1<=≤<=*n*<=≤<=1000, 1<=≤<=*l*<=≤<=109) — the number of lanterns and the length of the street respectively.
The next line contains *n* integers *a**i* (0<=≤<=*a**i*<=≤<=*l*). Multiple lanterns can be located at the same point. The lanterns may be located at the ends of the street. | Print the minimum light radius *d*, needed to light the whole street. The answer will be considered correct if its absolute or relative error doesn't exceed 10<=-<=9. | [
"7 15\n15 5 3 7 9 14 0\n",
"2 5\n2 5\n"
] | [
"2.5000000000\n",
"2.0000000000\n"
] | Consider the second sample. At *d* = 2 the first lantern will light the segment [0, 4] of the street, and the second lantern will light segment [3, 5]. Thus, the whole street will be lit. | 1,000 | [
{
"input": "7 15\n15 5 3 7 9 14 0",
"output": "2.5000000000"
},
{
"input": "2 5\n2 5",
"output": "2.0000000000"
},
{
"input": "46 615683844\n431749087 271781274 274974690 324606253 480870261 401650581 13285442 478090364 266585394 425024433 588791449 492057200 391293435 563090494 317950 173675329 473068378 356306865 311731938 192959832 321180686 141984626 578985584 512026637 175885185 590844074 47103801 212211134 330150 509886963 565955809 315640375 612907074 500474373 524310737 568681652 315339618 478782781 518873818 271322031 74600969 539099112 85129347 222068995 106014720 77282307",
"output": "22258199.5000000000"
},
{
"input": "2 1000000000\n0 1000000000",
"output": "500000000.0000000000"
},
{
"input": "2 555\n200 300",
"output": "255.0000000000"
},
{
"input": "1 1\n1",
"output": "1.0000000000"
},
{
"input": "1 1\n0",
"output": "1.0000000000"
},
{
"input": "1 1000000000\n0",
"output": "1000000000.0000000000"
},
{
"input": "1 1000000000\n1000000000",
"output": "1000000000.0000000000"
},
{
"input": "1 999999999\n499999999",
"output": "500000000.0000000000"
},
{
"input": "4 700\n0 250 475 700",
"output": "125.0000000000"
},
{
"input": "4 700\n0 225 450 700",
"output": "125.0000000000"
},
{
"input": "5 1000\n0 250 500 750 1000",
"output": "125.0000000000"
},
{
"input": "5 2000\n1001 1001 1001 1001 1001",
"output": "1001.0000000000"
},
{
"input": "1 999\n501",
"output": "501.0000000000"
},
{
"input": "2 1000\n400 600",
"output": "400.0000000000"
},
{
"input": "4 15\n1 3 9 11",
"output": "4.0000000000"
},
{
"input": "1 5\n2",
"output": "3.0000000000"
}
] | 1,688,846,462 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 31 | 0 | num_leights,length= map(int,input().split())
nums = list(map(int,input().split()))
max = -1
for i in range(num_leights-1):
if max < (nums[i+1]-nums[i])/2:
max = (nums[i+1]-nums[i])/2
if 0 not in nums:
if max < (nums[0]-0):
max = (nums[0]-0)
if length not in nums:
if max < (length-nums[-1]):
max = (length-nums[-1])
print(max) | Title: Vanya and Lanterns
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vanya walks late at night along a straight street of length *l*, lit by *n* lanterns. Consider the coordinate system with the beginning of the street corresponding to the point 0, and its end corresponding to the point *l*. Then the *i*-th lantern is at the point *a**i*. The lantern lights all points of the street that are at the distance of at most *d* from it, where *d* is some positive number, common for all lanterns.
Vanya wonders: what is the minimum light radius *d* should the lanterns have to light the whole street?
Input Specification:
The first line contains two integers *n*, *l* (1<=≤<=*n*<=≤<=1000, 1<=≤<=*l*<=≤<=109) — the number of lanterns and the length of the street respectively.
The next line contains *n* integers *a**i* (0<=≤<=*a**i*<=≤<=*l*). Multiple lanterns can be located at the same point. The lanterns may be located at the ends of the street.
Output Specification:
Print the minimum light radius *d*, needed to light the whole street. The answer will be considered correct if its absolute or relative error doesn't exceed 10<=-<=9.
Demo Input:
['7 15\n15 5 3 7 9 14 0\n', '2 5\n2 5\n']
Demo Output:
['2.5000000000\n', '2.0000000000\n']
Note:
Consider the second sample. At *d* = 2 the first lantern will light the segment [0, 4] of the street, and the second lantern will light segment [3, 5]. Thus, the whole street will be lit. | ```python
num_leights,length= map(int,input().split())
nums = list(map(int,input().split()))
max = -1
for i in range(num_leights-1):
if max < (nums[i+1]-nums[i])/2:
max = (nums[i+1]-nums[i])/2
if 0 not in nums:
if max < (nums[0]-0):
max = (nums[0]-0)
if length not in nums:
if max < (length-nums[-1]):
max = (length-nums[-1])
print(max)
``` | 0 |
|
0 | none | none | none | 0 | [
"none"
] | null | null | Malek has recently found a treasure map. While he was looking for a treasure he found a locked door. There was a string *s* written on the door consisting of characters '(', ')' and '#'. Below there was a manual on how to open the door. After spending a long time Malek managed to decode the manual and found out that the goal is to replace each '#' with one or more ')' characters so that the final string becomes beautiful.
Below there was also written that a string is called beautiful if for each *i* (1<=≤<=*i*<=≤<=|*s*|) there are no more ')' characters than '(' characters among the first *i* characters of *s* and also the total number of '(' characters is equal to the total number of ')' characters.
Help Malek open the door by telling him for each '#' character how many ')' characters he must replace it with. | The first line of the input contains a string *s* (1<=≤<=|*s*|<=≤<=105). Each character of this string is one of the characters '(', ')' or '#'. It is guaranteed that *s* contains at least one '#' character. | If there is no way of replacing '#' characters which leads to a beautiful string print <=-<=1. Otherwise for each character '#' print a separate line containing a positive integer, the number of ')' characters this character must be replaced with.
If there are several possible answers, you may output any of them. | [
"(((#)((#)\n",
"()((#((#(#()\n",
"#\n",
"(#)\n"
] | [
"1\n2\n",
"2\n2\n1",
"-1\n",
"-1\n"
] | |*s*| denotes the length of the string *s*. | 0 | [
{
"input": "(((#)((#)",
"output": "1\n2"
},
{
"input": "()((#((#(#()",
"output": "1\n1\n3"
},
{
"input": "#",
"output": "-1"
},
{
"input": "(#)",
"output": "-1"
},
{
"input": "(((((#(#(#(#()",
"output": "1\n1\n1\n5"
},
{
"input": "#))))",
"output": "-1"
},
{
"input": "((#(()#(##",
"output": "1\n1\n1\n1"
},
{
"input": "##((((((()",
"output": "-1"
},
{
"input": "(((((((((((((((((((###################",
"output": "1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1"
},
{
"input": "((#)(",
"output": "-1"
},
{
"input": "((#)((#)((#)((#)((#)((#)((#)((#)((#)((#)((#)((#)((#)((#)((#)((##",
"output": "1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1"
},
{
"input": ")((##((###",
"output": "-1"
},
{
"input": "(#))(#(#)((((#(##((#(#((((#(##((((((#((()(()(())((()#((((#((()((((#(((((#(##)(##()((((()())(((((#(((",
"output": "-1"
},
{
"input": "#(#(#((##((()))(((#)(#()#(((()()(()#(##(((()(((()))#(((((()(((((((()#((#((()(#(((()(()##(()(((()((#(",
"output": "-1"
},
{
"input": "((#(",
"output": "-1"
},
{
"input": "()#(#())()()#)(#)()##)#((()#)((#)()#())((#((((((((#)()()(()()(((((#)#(#((((#((##()(##(((#(()(#((#))#",
"output": "-1"
},
{
"input": "(())((((#)",
"output": "3"
},
{
"input": "(#(",
"output": "-1"
},
{
"input": "((#)(",
"output": "-1"
},
{
"input": "(((()#(#)(",
"output": "-1"
},
{
"input": "#((#",
"output": "-1"
},
{
"input": "(#((((()",
"output": "-1"
},
{
"input": "(#((",
"output": "-1"
},
{
"input": ")(((())#",
"output": "-1"
}
] | 1,418,491,412 | 3,212 | Python 3 | WRONG_ANSWER | PRETESTS | 11 | 530 | 716,800 | s = input()
c = s.count('#')
for i in s:
if i == '#':
s = s.replace('#',')')
result = c + s.count('(') - s.count(')')
if result > 0:
for i in range(c):
if i == c - 1:
print(result - c + 1)
else:
print(1)
else:
print(-1)
| Title: none
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Malek has recently found a treasure map. While he was looking for a treasure he found a locked door. There was a string *s* written on the door consisting of characters '(', ')' and '#'. Below there was a manual on how to open the door. After spending a long time Malek managed to decode the manual and found out that the goal is to replace each '#' with one or more ')' characters so that the final string becomes beautiful.
Below there was also written that a string is called beautiful if for each *i* (1<=≤<=*i*<=≤<=|*s*|) there are no more ')' characters than '(' characters among the first *i* characters of *s* and also the total number of '(' characters is equal to the total number of ')' characters.
Help Malek open the door by telling him for each '#' character how many ')' characters he must replace it with.
Input Specification:
The first line of the input contains a string *s* (1<=≤<=|*s*|<=≤<=105). Each character of this string is one of the characters '(', ')' or '#'. It is guaranteed that *s* contains at least one '#' character.
Output Specification:
If there is no way of replacing '#' characters which leads to a beautiful string print <=-<=1. Otherwise for each character '#' print a separate line containing a positive integer, the number of ')' characters this character must be replaced with.
If there are several possible answers, you may output any of them.
Demo Input:
['(((#)((#)\n', '()((#((#(#()\n', '#\n', '(#)\n']
Demo Output:
['1\n2\n', '2\n2\n1', '-1\n', '-1\n']
Note:
|*s*| denotes the length of the string *s*. | ```python
s = input()
c = s.count('#')
for i in s:
if i == '#':
s = s.replace('#',')')
result = c + s.count('(') - s.count(')')
if result > 0:
for i in range(c):
if i == c - 1:
print(result - c + 1)
else:
print(1)
else:
print(-1)
``` | 0 |
|
803 | C | Maximal GCD | PROGRAMMING | 1,900 | [
"constructive algorithms",
"greedy",
"math"
] | null | null | You are given positive integer number *n*. You should create such strictly increasing sequence of *k* positive numbers *a*1,<=*a*2,<=...,<=*a**k*, that their sum is equal to *n* and greatest common divisor is maximal.
Greatest common divisor of sequence is maximum of such numbers that every element of sequence is divisible by them.
If there is no possible sequence then output -1. | The first line consists of two numbers *n* and *k* (1<=≤<=*n*,<=*k*<=≤<=1010). | If the answer exists then output *k* numbers — resulting sequence. Otherwise output -1. If there are multiple answers, print any of them. | [
"6 3\n",
"8 2\n",
"5 3\n"
] | [
"1 2 3\n",
"2 6\n",
"-1\n"
] | none | 0 | [
{
"input": "6 3",
"output": "1 2 3"
},
{
"input": "8 2",
"output": "2 6"
},
{
"input": "5 3",
"output": "-1"
},
{
"input": "1 1",
"output": "1"
},
{
"input": "1 2",
"output": "-1"
},
{
"input": "2 1",
"output": "2"
},
{
"input": "2 10000000000",
"output": "-1"
},
{
"input": "5 1",
"output": "5"
},
{
"input": "6 2",
"output": "2 4"
},
{
"input": "24 2",
"output": "8 16"
},
{
"input": "24 3",
"output": "4 8 12"
},
{
"input": "24 4",
"output": "2 4 6 12"
},
{
"input": "24 5",
"output": "1 2 3 4 14"
},
{
"input": "479001600 2",
"output": "159667200 319334400"
},
{
"input": "479001600 3",
"output": "79833600 159667200 239500800"
},
{
"input": "479001600 4",
"output": "47900160 95800320 143700480 191600640"
},
{
"input": "479001600 5",
"output": "31933440 63866880 95800320 127733760 159667200"
},
{
"input": "479001600 6",
"output": "22809600 45619200 68428800 91238400 114048000 136857600"
},
{
"input": "3000000021 1",
"output": "3000000021"
},
{
"input": "3000000021 2",
"output": "1000000007 2000000014"
},
{
"input": "3000000021 3",
"output": "3 6 3000000012"
},
{
"input": "3000000021 4",
"output": "3 6 9 3000000003"
},
{
"input": "3000000021 50000",
"output": "1 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 50 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 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155..."
},
{
"input": "3000000021 100000",
"output": "-1"
},
{
"input": "10000000000 100",
"output": "1953125 3906250 5859375 7812500 9765625 11718750 13671875 15625000 17578125 19531250 21484375 23437500 25390625 27343750 29296875 31250000 33203125 35156250 37109375 39062500 41015625 42968750 44921875 46875000 48828125 50781250 52734375 54687500 56640625 58593750 60546875 62500000 64453125 66406250 68359375 70312500 72265625 74218750 76171875 78125000 80078125 82031250 83984375 85937500 87890625 89843750 91796875 93750000 95703125 97656250 99609375 101562500 103515625 105468750 107421875 109375000 1113281..."
},
{
"input": "10000000000 2000",
"output": "4000 8000 12000 16000 20000 24000 28000 32000 36000 40000 44000 48000 52000 56000 60000 64000 68000 72000 76000 80000 84000 88000 92000 96000 100000 104000 108000 112000 116000 120000 124000 128000 132000 136000 140000 144000 148000 152000 156000 160000 164000 168000 172000 176000 180000 184000 188000 192000 196000 200000 204000 208000 212000 216000 220000 224000 228000 232000 236000 240000 244000 248000 252000 256000 260000 264000 268000 272000 276000 280000 284000 288000 292000 296000 300000 304000 30800..."
},
{
"input": "10000000000 5000",
"output": "640 1280 1920 2560 3200 3840 4480 5120 5760 6400 7040 7680 8320 8960 9600 10240 10880 11520 12160 12800 13440 14080 14720 15360 16000 16640 17280 17920 18560 19200 19840 20480 21120 21760 22400 23040 23680 24320 24960 25600 26240 26880 27520 28160 28800 29440 30080 30720 31360 32000 32640 33280 33920 34560 35200 35840 36480 37120 37760 38400 39040 39680 40320 40960 41600 42240 42880 43520 44160 44800 45440 46080 46720 47360 48000 48640 49280 49920 50560 51200 51840 52480 53120 53760 54400 55040 55680 56320..."
},
{
"input": "10000000000 100000",
"output": "1 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 50 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 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155..."
},
{
"input": "10000000000 100000000",
"output": "-1"
},
{
"input": "10000000000 10000000000",
"output": "-1"
},
{
"input": "10000000000 100001",
"output": "1 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 50 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 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155..."
},
{
"input": "1 4000000000",
"output": "-1"
},
{
"input": "4294967296 4294967296",
"output": "-1"
},
{
"input": "71227122 9603838834",
"output": "-1"
},
{
"input": "10000000000 9603838835",
"output": "-1"
},
{
"input": "5 5999999999",
"output": "-1"
},
{
"input": "2 9324327498",
"output": "-1"
},
{
"input": "9 2",
"output": "3 6"
},
{
"input": "10000000000 4294967296",
"output": "-1"
},
{
"input": "1 3500000000",
"output": "-1"
},
{
"input": "10000000000 4000000000",
"output": "-1"
},
{
"input": "2000 9324327498",
"output": "-1"
},
{
"input": "10000000000 8589934592",
"output": "-1"
},
{
"input": "5000150001 100001",
"output": "1 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 50 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 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155..."
},
{
"input": "10000000000 3037000500",
"output": "-1"
},
{
"input": "9400000000 9324327498",
"output": "-1"
},
{
"input": "10000000000 3307000500",
"output": "-1"
},
{
"input": "2 4000000000",
"output": "-1"
},
{
"input": "1000 4294967295",
"output": "-1"
},
{
"input": "36 3",
"output": "6 12 18"
},
{
"input": "2147483648 4294967296",
"output": "-1"
},
{
"input": "999 4294967295",
"output": "-1"
},
{
"input": "10000000000 130000",
"output": "1 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 50 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 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155..."
},
{
"input": "10000000000 140000",
"output": "1 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 50 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 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155..."
},
{
"input": "10000000000 6074001000",
"output": "-1"
},
{
"input": "12344321 1",
"output": "12344321"
},
{
"input": "2 2",
"output": "-1"
},
{
"input": "28 7",
"output": "1 2 3 4 5 6 7"
},
{
"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": "2 1",
"output": "2"
},
{
"input": "2 2",
"output": "-1"
},
{
"input": "2 3",
"output": "-1"
},
{
"input": "2 4",
"output": "-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": "3 1",
"output": "3"
},
{
"input": "3 2",
"output": "1 2"
},
{
"input": "3 3",
"output": "-1"
},
{
"input": "3 4",
"output": "-1"
},
{
"input": "3 5",
"output": "-1"
},
{
"input": "3 6",
"output": "-1"
},
{
"input": "3 7",
"output": "-1"
},
{
"input": "3 8",
"output": "-1"
},
{
"input": "3 9",
"output": "-1"
},
{
"input": "3 10",
"output": "-1"
},
{
"input": "4 1",
"output": "4"
},
{
"input": "4 2",
"output": "1 3"
},
{
"input": "4 3",
"output": "-1"
},
{
"input": "4 4",
"output": "-1"
},
{
"input": "4 5",
"output": "-1"
},
{
"input": "4 6",
"output": "-1"
},
{
"input": "4 7",
"output": "-1"
},
{
"input": "4 8",
"output": "-1"
},
{
"input": "4 9",
"output": "-1"
},
{
"input": "4 10",
"output": "-1"
},
{
"input": "5 1",
"output": "5"
},
{
"input": "5 2",
"output": "1 4"
},
{
"input": "5 3",
"output": "-1"
},
{
"input": "5 4",
"output": "-1"
},
{
"input": "5 5",
"output": "-1"
},
{
"input": "5 6",
"output": "-1"
},
{
"input": "5 7",
"output": "-1"
},
{
"input": "5 8",
"output": "-1"
},
{
"input": "5 9",
"output": "-1"
},
{
"input": "5 10",
"output": "-1"
},
{
"input": "6 1",
"output": "6"
},
{
"input": "6 2",
"output": "2 4"
},
{
"input": "6 3",
"output": "1 2 3"
},
{
"input": "6 4",
"output": "-1"
},
{
"input": "6 5",
"output": "-1"
},
{
"input": "6 6",
"output": "-1"
},
{
"input": "6 7",
"output": "-1"
},
{
"input": "6 8",
"output": "-1"
},
{
"input": "6 9",
"output": "-1"
},
{
"input": "6 10",
"output": "-1"
},
{
"input": "7 1",
"output": "7"
},
{
"input": "7 2",
"output": "1 6"
},
{
"input": "7 3",
"output": "1 2 4"
},
{
"input": "7 4",
"output": "-1"
},
{
"input": "7 5",
"output": "-1"
},
{
"input": "7 6",
"output": "-1"
},
{
"input": "7 7",
"output": "-1"
},
{
"input": "7 8",
"output": "-1"
},
{
"input": "7 9",
"output": "-1"
},
{
"input": "7 10",
"output": "-1"
},
{
"input": "8 1",
"output": "8"
},
{
"input": "8 2",
"output": "2 6"
},
{
"input": "8 3",
"output": "1 2 5"
},
{
"input": "8 4",
"output": "-1"
},
{
"input": "8 5",
"output": "-1"
},
{
"input": "8 6",
"output": "-1"
},
{
"input": "8 7",
"output": "-1"
},
{
"input": "8 8",
"output": "-1"
},
{
"input": "8 9",
"output": "-1"
},
{
"input": "8 10",
"output": "-1"
}
] | 1,525,960,330 | 2,950 | Python 3 | OK | TESTS | 138 | 139 | 17,305,600 | #!/usr/bin/env python3
import sys
from math import sqrt
[n, k] = map(int, input().strip().split())
if k * (k + 1) > 2 * n:
print (-1)
sys.exit(0)
a0max = (2 * n) // (k * (k + 1))
d = 1
for i in range(1, min(a0max, int(sqrt(n))) + 1):
if n % i == 0:
d = max(d, i)
if a0max * i >= n:
d = max(d, n // i)
res = [(i + 1) * d for i in range(k - 1)]
res.append(n - d * (k * (k - 1)) // 2)
print (' '.join(map(str, res)))
| Title: Maximal GCD
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given positive integer number *n*. You should create such strictly increasing sequence of *k* positive numbers *a*1,<=*a*2,<=...,<=*a**k*, that their sum is equal to *n* and greatest common divisor is maximal.
Greatest common divisor of sequence is maximum of such numbers that every element of sequence is divisible by them.
If there is no possible sequence then output -1.
Input Specification:
The first line consists of two numbers *n* and *k* (1<=≤<=*n*,<=*k*<=≤<=1010).
Output Specification:
If the answer exists then output *k* numbers — resulting sequence. Otherwise output -1. If there are multiple answers, print any of them.
Demo Input:
['6 3\n', '8 2\n', '5 3\n']
Demo Output:
['1 2 3\n', '2 6\n', '-1\n']
Note:
none | ```python
#!/usr/bin/env python3
import sys
from math import sqrt
[n, k] = map(int, input().strip().split())
if k * (k + 1) > 2 * n:
print (-1)
sys.exit(0)
a0max = (2 * n) // (k * (k + 1))
d = 1
for i in range(1, min(a0max, int(sqrt(n))) + 1):
if n % i == 0:
d = max(d, i)
if a0max * i >= n:
d = max(d, n // i)
res = [(i + 1) * d for i in range(k - 1)]
res.append(n - d * (k * (k - 1)) // 2)
print (' '.join(map(str, res)))
``` | 3 |
|
479 | A | Expression | PROGRAMMING | 1,000 | [
"brute force",
"math"
] | null | null | Petya studies in a school and he adores Maths. His class has been studying arithmetic expressions. On the last class the teacher wrote three positive integers *a*, *b*, *c* on the blackboard. The task was to insert signs of operations '+' and '*', and probably brackets between the numbers so that the value of the resulting expression is as large as possible. Let's consider an example: assume that the teacher wrote numbers 1, 2 and 3 on the blackboard. Here are some ways of placing signs and brackets:
- 1+2*3=7 - 1*(2+3)=5 - 1*2*3=6 - (1+2)*3=9
Note that you can insert operation signs only between *a* and *b*, and between *b* and *c*, that is, you cannot swap integers. For instance, in the given sample you cannot get expression (1+3)*2.
It's easy to see that the maximum value that you can obtain is 9.
Your task is: given *a*, *b* and *c* print the maximum value that you can get. | The input contains three integers *a*, *b* and *c*, each on a single line (1<=≤<=*a*,<=*b*,<=*c*<=≤<=10). | Print the maximum value of the expression that you can obtain. | [
"1\n2\n3\n",
"2\n10\n3\n"
] | [
"9\n",
"60\n"
] | none | 500 | [
{
"input": "1\n2\n3",
"output": "9"
},
{
"input": "2\n10\n3",
"output": "60"
},
{
"input": "1\n1\n1",
"output": "3"
},
{
"input": "1\n2\n1",
"output": "4"
},
{
"input": "10\n10\n10",
"output": "1000"
},
{
"input": "5\n1\n3",
"output": "20"
},
{
"input": "3\n1\n5",
"output": "20"
},
{
"input": "6\n7\n1",
"output": "48"
},
{
"input": "1\n8\n3",
"output": "27"
},
{
"input": "9\n7\n2",
"output": "126"
},
{
"input": "1\n1\n10",
"output": "20"
},
{
"input": "9\n1\n1",
"output": "18"
},
{
"input": "10\n5\n6",
"output": "300"
},
{
"input": "8\n9\n7",
"output": "504"
},
{
"input": "4\n2\n10",
"output": "80"
},
{
"input": "2\n8\n3",
"output": "48"
},
{
"input": "3\n5\n7",
"output": "105"
},
{
"input": "1\n10\n1",
"output": "12"
},
{
"input": "2\n2\n2",
"output": "8"
},
{
"input": "5\n6\n1",
"output": "35"
},
{
"input": "10\n1\n1",
"output": "20"
},
{
"input": "1\n6\n1",
"output": "8"
},
{
"input": "1\n9\n1",
"output": "11"
},
{
"input": "2\n1\n2",
"output": "6"
},
{
"input": "2\n6\n1",
"output": "14"
},
{
"input": "9\n2\n1",
"output": "27"
},
{
"input": "1\n9\n2",
"output": "20"
},
{
"input": "1\n3\n1",
"output": "5"
},
{
"input": "2\n1\n1",
"output": "4"
}
] | 1,694,532,710 | 2,147,483,647 | PyPy 3 | RUNTIME_ERROR | TESTS | 0 | 92 | 2,048,000 | a, b, c = [int(i) for i in input().split()]
resultado = []
for i in range(4):
if i == 0:
resultado.append(a + b * c)
elif i == 1:
resultado.append(a * (b + c))
elif i == 2:
resultado.append(a * b * c)
elif i == 3:
resultado.append((a + b) * c)
mayor = max(resultado)
print(mayor) | Title: Expression
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Petya studies in a school and he adores Maths. His class has been studying arithmetic expressions. On the last class the teacher wrote three positive integers *a*, *b*, *c* on the blackboard. The task was to insert signs of operations '+' and '*', and probably brackets between the numbers so that the value of the resulting expression is as large as possible. Let's consider an example: assume that the teacher wrote numbers 1, 2 and 3 on the blackboard. Here are some ways of placing signs and brackets:
- 1+2*3=7 - 1*(2+3)=5 - 1*2*3=6 - (1+2)*3=9
Note that you can insert operation signs only between *a* and *b*, and between *b* and *c*, that is, you cannot swap integers. For instance, in the given sample you cannot get expression (1+3)*2.
It's easy to see that the maximum value that you can obtain is 9.
Your task is: given *a*, *b* and *c* print the maximum value that you can get.
Input Specification:
The input contains three integers *a*, *b* and *c*, each on a single line (1<=≤<=*a*,<=*b*,<=*c*<=≤<=10).
Output Specification:
Print the maximum value of the expression that you can obtain.
Demo Input:
['1\n2\n3\n', '2\n10\n3\n']
Demo Output:
['9\n', '60\n']
Note:
none | ```python
a, b, c = [int(i) for i in input().split()]
resultado = []
for i in range(4):
if i == 0:
resultado.append(a + b * c)
elif i == 1:
resultado.append(a * (b + c))
elif i == 2:
resultado.append(a * b * c)
elif i == 3:
resultado.append((a + b) * c)
mayor = max(resultado)
print(mayor)
``` | -1 |
|
242 | B | Big Segment | PROGRAMMING | 1,100 | [
"implementation",
"sortings"
] | null | null | A coordinate line has *n* segments, the *i*-th segment starts at the position *l**i* and ends at the position *r**i*. We will denote such a segment as [*l**i*,<=*r**i*].
You have suggested that one of the defined segments covers all others. In other words, there is such segment in the given set, which contains all other ones. Now you want to test your assumption. Find in the given set the segment which covers all other segments, and print its number. If such a segment doesn't exist, print -1.
Formally we will assume that segment [*a*,<=*b*] covers segment [*c*,<=*d*], if they meet this condition *a*<=≤<=*c*<=≤<=*d*<=≤<=*b*. | The first line contains integer *n* (1<=≤<=*n*<=≤<=105) — the number of segments. Next *n* lines contain the descriptions of the segments. The *i*-th line contains two space-separated integers *l**i*,<=*r**i* (1<=≤<=*l**i*<=≤<=*r**i*<=≤<=109) — the borders of the *i*-th segment.
It is guaranteed that no two segments coincide. | Print a single integer — the number of the segment that covers all other segments in the set. If there's no solution, print -1.
The segments are numbered starting from 1 in the order in which they appear in the input. | [
"3\n1 1\n2 2\n3 3\n",
"6\n1 5\n2 3\n1 10\n7 10\n7 7\n10 10\n"
] | [
"-1\n",
"3\n"
] | none | 1,000 | [
{
"input": "3\n1 1\n2 2\n3 3",
"output": "-1"
},
{
"input": "6\n1 5\n2 3\n1 10\n7 10\n7 7\n10 10",
"output": "3"
},
{
"input": "4\n1 5\n2 2\n2 4\n2 5",
"output": "1"
},
{
"input": "5\n3 3\n1 3\n2 2\n2 3\n1 2",
"output": "2"
},
{
"input": "7\n7 7\n8 8\n3 7\n1 6\n1 7\n4 7\n2 8",
"output": "-1"
},
{
"input": "3\n2 5\n3 4\n2 3",
"output": "1"
},
{
"input": "16\n15 15\n8 12\n6 9\n15 16\n8 14\n3 12\n7 19\n9 13\n5 16\n9 17\n10 15\n9 14\n9 9\n18 19\n5 15\n6 19",
"output": "-1"
},
{
"input": "9\n1 10\n7 8\n6 7\n1 4\n5 9\n2 8\n3 10\n1 1\n2 3",
"output": "1"
},
{
"input": "1\n1 100000",
"output": "1"
},
{
"input": "6\n2 2\n3 3\n3 5\n4 5\n1 1\n1 5",
"output": "6"
},
{
"input": "33\n2 18\n4 14\n2 16\n10 12\n4 6\n9 17\n2 8\n4 12\n8 20\n1 10\n11 14\n11 17\n8 15\n3 16\n3 4\n6 9\n6 19\n4 17\n17 19\n6 16\n3 12\n1 7\n6 20\n8 16\n12 19\n1 3\n12 18\n6 11\n7 20\n16 18\n4 15\n3 15\n15 19",
"output": "-1"
},
{
"input": "34\n3 8\n5 9\n2 9\n1 4\n3 7\n3 3\n8 9\n6 10\n4 7\n6 7\n5 8\n5 10\n1 5\n8 8\n2 5\n3 5\n7 7\n2 8\n4 5\n1 1\n7 9\n5 6\n2 3\n1 2\n2 4\n8 10\n7 8\n1 3\n4 8\n9 10\n1 7\n10 10\n2 2\n1 8",
"output": "-1"
},
{
"input": "55\n3 4\n6 8\n9 10\n3 9\n9 9\n2 5\n4 8\n3 8\n8 10\n1 1\n4 9\n10 10\n6 6\n8 8\n1 8\n5 5\n4 5\n5 9\n2 2\n3 10\n4 6\n3 6\n1 6\n1 7\n6 10\n2 6\n3 7\n2 4\n4 4\n5 10\n1 4\n2 9\n1 3\n7 9\n7 8\n1 9\n1 10\n2 8\n8 9\n6 7\n1 2\n6 9\n7 7\n4 7\n3 3\n2 7\n4 10\n7 10\n2 3\n2 10\n5 7\n3 5\n5 8\n1 5\n5 6",
"output": "37"
},
{
"input": "1\n999999999 1000000000",
"output": "1"
},
{
"input": "3\n1 20\n2 22\n3 18",
"output": "-1"
},
{
"input": "1\n1000000000 1000000000",
"output": "1"
},
{
"input": "2\n100001 100008\n100005 100006",
"output": "1"
},
{
"input": "1\n1000000 10000000",
"output": "1"
},
{
"input": "3\n3 6\n2 4\n1 5",
"output": "-1"
},
{
"input": "2\n3 5\n1 2",
"output": "-1"
}
] | 1,590,721,899 | 2,147,483,647 | Python 3 | OK | TESTS | 45 | 810 | 9,523,200 | t = int(input())
first = []
second = []
overall = []
for _ in range(t):
a, b = [int(i) for i in input().split()]
first.append(a)
second.append(b)
overall.append([a,b])
mi = min(first)
ma = max(second)
flag = -1
for i in range(t):
if overall[i][0] <= mi <= ma <= overall[i][1]:
flag = i+1
print(flag) | Title: Big Segment
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A coordinate line has *n* segments, the *i*-th segment starts at the position *l**i* and ends at the position *r**i*. We will denote such a segment as [*l**i*,<=*r**i*].
You have suggested that one of the defined segments covers all others. In other words, there is such segment in the given set, which contains all other ones. Now you want to test your assumption. Find in the given set the segment which covers all other segments, and print its number. If such a segment doesn't exist, print -1.
Formally we will assume that segment [*a*,<=*b*] covers segment [*c*,<=*d*], if they meet this condition *a*<=≤<=*c*<=≤<=*d*<=≤<=*b*.
Input Specification:
The first line contains integer *n* (1<=≤<=*n*<=≤<=105) — the number of segments. Next *n* lines contain the descriptions of the segments. The *i*-th line contains two space-separated integers *l**i*,<=*r**i* (1<=≤<=*l**i*<=≤<=*r**i*<=≤<=109) — the borders of the *i*-th segment.
It is guaranteed that no two segments coincide.
Output Specification:
Print a single integer — the number of the segment that covers all other segments in the set. If there's no solution, print -1.
The segments are numbered starting from 1 in the order in which they appear in the input.
Demo Input:
['3\n1 1\n2 2\n3 3\n', '6\n1 5\n2 3\n1 10\n7 10\n7 7\n10 10\n']
Demo Output:
['-1\n', '3\n']
Note:
none | ```python
t = int(input())
first = []
second = []
overall = []
for _ in range(t):
a, b = [int(i) for i in input().split()]
first.append(a)
second.append(b)
overall.append([a,b])
mi = min(first)
ma = max(second)
flag = -1
for i in range(t):
if overall[i][0] <= mi <= ma <= overall[i][1]:
flag = i+1
print(flag)
``` | 3 |
|
219 | A | k-String | PROGRAMMING | 1,000 | [
"implementation",
"strings"
] | null | null | A string is called a *k*-string if it can be represented as *k* concatenated copies of some string. For example, the string "aabaabaabaab" is at the same time a 1-string, a 2-string and a 4-string, but it is not a 3-string, a 5-string, or a 6-string and so on. Obviously any string is a 1-string.
You are given a string *s*, consisting of lowercase English letters and a positive integer *k*. Your task is to reorder the letters in the string *s* in such a way that the resulting string is a *k*-string. | The first input line contains integer *k* (1<=≤<=*k*<=≤<=1000). The second line contains *s*, all characters in *s* are lowercase English letters. The string length *s* satisfies the inequality 1<=≤<=|*s*|<=≤<=1000, where |*s*| is the length of string *s*. | Rearrange the letters in string *s* in such a way that the result is a *k*-string. Print the result on a single output line. If there are multiple solutions, print any of them.
If the solution doesn't exist, print "-1" (without quotes). | [
"2\naazz\n",
"3\nabcabcabz\n"
] | [
"azaz\n",
"-1\n"
] | none | 500 | [
{
"input": "2\naazz",
"output": "azaz"
},
{
"input": "3\nabcabcabz",
"output": "-1"
},
{
"input": "1\na",
"output": "a"
},
{
"input": "2\nabba",
"output": "abab"
},
{
"input": "2\naaab",
"output": "-1"
},
{
"input": "7\nabacaba",
"output": "-1"
},
{
"input": "5\naaaaa",
"output": "aaaaa"
},
{
"input": "3\naabaaaaabb",
"output": "-1"
},
{
"input": "2\naaab",
"output": "-1"
},
{
"input": "2\nbabac",
"output": "-1"
},
{
"input": "3\nbbbccc",
"output": "bcbcbc"
},
{
"input": "2\naa",
"output": "aa"
},
{
"input": "250\ncececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececece",
"output": "cececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececece"
},
{
"input": "15\nabaabbbcababaaaabaabbbcababaaaabaabbbcababaaaabaabbbcababaaaabaabbbcababaaaabaabbbcababaaaabaabbbcababaaaabaabbbcababaaaabaabbbcababaaaabaabbbcababaaaabaabbbcababaaaabaabbbcababaaaabaabbbcababaaaabaabbbcababaaaabaabbbcababaaa",
"output": "aaaaaaaabbbbbbcaaaaaaaabbbbbbcaaaaaaaabbbbbbcaaaaaaaabbbbbbcaaaaaaaabbbbbbcaaaaaaaabbbbbbcaaaaaaaabbbbbbcaaaaaaaabbbbbbcaaaaaaaabbbbbbcaaaaaaaabbbbbbcaaaaaaaabbbbbbcaaaaaaaabbbbbbcaaaaaaaabbbbbbcaaaaaaaabbbbbbcaaaaaaaabbbbbbc"
},
{
"input": "1\naaa",
"output": "aaa"
},
{
"input": "1\naabaab",
"output": "aaaabb"
},
{
"input": "2\naabbbbccccccdddddddd",
"output": "abbcccddddabbcccdddd"
},
{
"input": "3\naaaaaaaaacccdddddd",
"output": "aaacddaaacddaaacdd"
},
{
"input": "3\naaaaaaaaacccbbbbbb",
"output": "aaabbcaaabbcaaabbc"
},
{
"input": "2\naazzzz",
"output": "azzazz"
},
{
"input": "2\naaaa",
"output": "aaaa"
},
{
"input": "2\naaaazz",
"output": "aazaaz"
},
{
"input": "2\naaaabb",
"output": "aabaab"
},
{
"input": "2\naabbbb",
"output": "abbabb"
},
{
"input": "2\naaaazzzz",
"output": "aazzaazz"
},
{
"input": "2\naaazz",
"output": "-1"
},
{
"input": "2\nbbbbaa",
"output": "abbabb"
},
{
"input": "2\naaaaaabbbb",
"output": "aaabbaaabb"
},
{
"input": "2\naaaaaazz",
"output": "aaazaaaz"
},
{
"input": "2\naaaabbbb",
"output": "aabbaabb"
},
{
"input": "2\naabaab",
"output": "aabaab"
},
{
"input": "1\naaaaa",
"output": "aaaaa"
},
{
"input": "2\nbbaaaa",
"output": "aabaab"
},
{
"input": "2\nacaccc",
"output": "accacc"
}
] | 1,672,511,399 | 2,147,483,647 | Python 3 | OK | TESTS | 42 | 92 | 102,400 | from collections import Counter
def kString(k, s):
d = Counter(s)
result = "".join([c * (d[c] // k) for c in d])
if len(result) * k != len(s):
return -1
return result * k
k = int(input())
s = input()
print(kString(k, s)) | Title: k-String
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A string is called a *k*-string if it can be represented as *k* concatenated copies of some string. For example, the string "aabaabaabaab" is at the same time a 1-string, a 2-string and a 4-string, but it is not a 3-string, a 5-string, or a 6-string and so on. Obviously any string is a 1-string.
You are given a string *s*, consisting of lowercase English letters and a positive integer *k*. Your task is to reorder the letters in the string *s* in such a way that the resulting string is a *k*-string.
Input Specification:
The first input line contains integer *k* (1<=≤<=*k*<=≤<=1000). The second line contains *s*, all characters in *s* are lowercase English letters. The string length *s* satisfies the inequality 1<=≤<=|*s*|<=≤<=1000, where |*s*| is the length of string *s*.
Output Specification:
Rearrange the letters in string *s* in such a way that the result is a *k*-string. Print the result on a single output line. If there are multiple solutions, print any of them.
If the solution doesn't exist, print "-1" (without quotes).
Demo Input:
['2\naazz\n', '3\nabcabcabz\n']
Demo Output:
['azaz\n', '-1\n']
Note:
none | ```python
from collections import Counter
def kString(k, s):
d = Counter(s)
result = "".join([c * (d[c] // k) for c in d])
if len(result) * k != len(s):
return -1
return result * k
k = int(input())
s = input()
print(kString(k, s))
``` | 3 |
|
228 | A | Is your horseshoe on the other hoof? | PROGRAMMING | 800 | [
"implementation"
] | null | null | Valera the Horse is going to the party with friends. He has been following the fashion trends for a while, and he knows that it is very popular to wear all horseshoes of different color. Valera has got four horseshoes left from the last year, but maybe some of them have the same color. In this case he needs to go to the store and buy some few more horseshoes, not to lose face in front of his stylish comrades.
Fortunately, the store sells horseshoes of all colors under the sun and Valera has enough money to buy any four of them. However, in order to save the money, he would like to spend as little money as possible, so you need to help Valera and determine what is the minimum number of horseshoes he needs to buy to wear four horseshoes of different colors to a party. | The first line contains four space-separated integers *s*1,<=*s*2,<=*s*3,<=*s*4 (1<=≤<=*s*1,<=*s*2,<=*s*3,<=*s*4<=≤<=109) — the colors of horseshoes Valera has.
Consider all possible colors indexed with integers. | Print a single integer — the minimum number of horseshoes Valera needs to buy. | [
"1 7 3 3\n",
"7 7 7 7\n"
] | [
"1\n",
"3\n"
] | none | 500 | [
{
"input": "1 7 3 3",
"output": "1"
},
{
"input": "7 7 7 7",
"output": "3"
},
{
"input": "81170865 673572653 756938629 995577259",
"output": "0"
},
{
"input": "3491663 217797045 522540872 715355328",
"output": "0"
},
{
"input": "251590420 586975278 916631563 586975278",
"output": "1"
},
{
"input": "259504825 377489979 588153796 377489979",
"output": "1"
},
{
"input": "652588203 931100304 931100304 652588203",
"output": "2"
},
{
"input": "391958720 651507265 391958720 651507265",
"output": "2"
},
{
"input": "90793237 90793237 90793237 90793237",
"output": "3"
},
{
"input": "551651653 551651653 551651653 551651653",
"output": "3"
},
{
"input": "156630260 609654355 668943582 973622757",
"output": "0"
},
{
"input": "17061017 110313588 434481173 796661222",
"output": "0"
},
{
"input": "24975422 256716298 337790533 690960249",
"output": "0"
},
{
"input": "255635360 732742923 798648949 883146723",
"output": "0"
},
{
"input": "133315691 265159773 734556507 265159773",
"output": "1"
},
{
"input": "28442865 741657755 978106882 978106882",
"output": "1"
},
{
"input": "131245479 174845575 497483467 131245479",
"output": "1"
},
{
"input": "139159884 616215581 958341883 616215581",
"output": "1"
},
{
"input": "147784432 947653080 947653080 947653080",
"output": "2"
},
{
"input": "94055790 756126496 756126496 94055790",
"output": "2"
},
{
"input": "240458500 511952208 240458500 511952208",
"output": "2"
},
{
"input": "681828506 972810624 972810624 681828506",
"output": "2"
},
{
"input": "454961014 454961014 454961014 454961014",
"output": "3"
},
{
"input": "915819430 915819430 915819430 915819430",
"output": "3"
},
{
"input": "671645142 671645142 671645142 671645142",
"output": "3"
},
{
"input": "132503558 132503558 132503558 132503558",
"output": "3"
},
{
"input": "5 5 999999 6",
"output": "1"
},
{
"input": "1 1 2 5",
"output": "1"
},
{
"input": "2 1 2 3",
"output": "1"
},
{
"input": "1 1 3 5",
"output": "1"
},
{
"input": "1 1 3 3",
"output": "2"
},
{
"input": "2 2 2 1",
"output": "2"
},
{
"input": "3 1 1 1",
"output": "2"
},
{
"input": "1 2 2 2",
"output": "2"
}
] | 1,694,904,698 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 34 | 124 | 0 | a=map(int,input().split())
r=[]
for i in a:
if i not in r:
r.append(i)
print(4-len(r))
| Title: Is your horseshoe on the other hoof?
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Valera the Horse is going to the party with friends. He has been following the fashion trends for a while, and he knows that it is very popular to wear all horseshoes of different color. Valera has got four horseshoes left from the last year, but maybe some of them have the same color. In this case he needs to go to the store and buy some few more horseshoes, not to lose face in front of his stylish comrades.
Fortunately, the store sells horseshoes of all colors under the sun and Valera has enough money to buy any four of them. However, in order to save the money, he would like to spend as little money as possible, so you need to help Valera and determine what is the minimum number of horseshoes he needs to buy to wear four horseshoes of different colors to a party.
Input Specification:
The first line contains four space-separated integers *s*1,<=*s*2,<=*s*3,<=*s*4 (1<=≤<=*s*1,<=*s*2,<=*s*3,<=*s*4<=≤<=109) — the colors of horseshoes Valera has.
Consider all possible colors indexed with integers.
Output Specification:
Print a single integer — the minimum number of horseshoes Valera needs to buy.
Demo Input:
['1 7 3 3\n', '7 7 7 7\n']
Demo Output:
['1\n', '3\n']
Note:
none | ```python
a=map(int,input().split())
r=[]
for i in a:
if i not in r:
r.append(i)
print(4-len(r))
``` | 3 |
|
750 | A | New Year and Hurry | PROGRAMMING | 800 | [
"binary search",
"brute force",
"implementation",
"math"
] | null | null | Limak is going to participate in a contest on the last day of the 2016. The contest will start at 20:00 and will last four hours, exactly until midnight. There will be *n* problems, sorted by difficulty, i.e. problem 1 is the easiest and problem *n* is the hardest. Limak knows it will take him 5·*i* minutes to solve the *i*-th problem.
Limak's friends organize a New Year's Eve party and Limak wants to be there at midnight or earlier. He needs *k* minutes to get there from his house, where he will participate in the contest first.
How many problems can Limak solve if he wants to make it to the party? | The only line of the input contains two integers *n* and *k* (1<=≤<=*n*<=≤<=10, 1<=≤<=*k*<=≤<=240) — the number of the problems in the contest and the number of minutes Limak needs to get to the party from his house. | Print one integer, denoting the maximum possible number of problems Limak can solve so that he could get to the party at midnight or earlier. | [
"3 222\n",
"4 190\n",
"7 1\n"
] | [
"2\n",
"4\n",
"7\n"
] | In the first sample, there are 3 problems and Limak needs 222 minutes to get to the party. The three problems require 5, 10 and 15 minutes respectively. Limak can spend 5 + 10 = 15 minutes to solve first two problems. Then, at 20:15 he can leave his house to get to the party at 23:57 (after 222 minutes). In this scenario Limak would solve 2 problems. He doesn't have enough time to solve 3 problems so the answer is 2.
In the second sample, Limak can solve all 4 problems in 5 + 10 + 15 + 20 = 50 minutes. At 20:50 he will leave the house and go to the party. He will get there exactly at midnight.
In the third sample, Limak needs only 1 minute to get to the party. He has enough time to solve all 7 problems. | 500 | [
{
"input": "3 222",
"output": "2"
},
{
"input": "4 190",
"output": "4"
},
{
"input": "7 1",
"output": "7"
},
{
"input": "10 135",
"output": "6"
},
{
"input": "10 136",
"output": "5"
},
{
"input": "1 1",
"output": "1"
},
{
"input": "1 240",
"output": "0"
},
{
"input": "10 1",
"output": "9"
},
{
"input": "10 240",
"output": "0"
},
{
"input": "9 240",
"output": "0"
},
{
"input": "9 1",
"output": "9"
},
{
"input": "9 235",
"output": "1"
},
{
"input": "9 236",
"output": "0"
},
{
"input": "5 225",
"output": "2"
},
{
"input": "5 226",
"output": "1"
},
{
"input": "4 210",
"output": "3"
},
{
"input": "4 211",
"output": "2"
},
{
"input": "4 191",
"output": "3"
},
{
"input": "10 165",
"output": "5"
},
{
"input": "10 166",
"output": "4"
},
{
"input": "8 100",
"output": "7"
},
{
"input": "8 101",
"output": "6"
},
{
"input": "8 60",
"output": "8"
},
{
"input": "8 61",
"output": "7"
},
{
"input": "10 15",
"output": "9"
},
{
"input": "10 16",
"output": "8"
},
{
"input": "4 100",
"output": "4"
},
{
"input": "4 101",
"output": "4"
},
{
"input": "7 167",
"output": "4"
},
{
"input": "10 164",
"output": "5"
},
{
"input": "9 170",
"output": "4"
},
{
"input": "8 160",
"output": "5"
},
{
"input": "1 100",
"output": "1"
},
{
"input": "8 123",
"output": "6"
},
{
"input": "2 99",
"output": "2"
},
{
"input": "10 88",
"output": "7"
},
{
"input": "1 235",
"output": "1"
},
{
"input": "1 1",
"output": "1"
},
{
"input": "4 240",
"output": "0"
},
{
"input": "1 55",
"output": "1"
},
{
"input": "1 240",
"output": "0"
},
{
"input": "3 240",
"output": "0"
},
{
"input": "10 240",
"output": "0"
},
{
"input": "2 240",
"output": "0"
},
{
"input": "10 1",
"output": "9"
},
{
"input": "9 1",
"output": "9"
},
{
"input": "2 236",
"output": "0"
},
{
"input": "10 2",
"output": "9"
},
{
"input": "3 239",
"output": "0"
},
{
"input": "1 237",
"output": "0"
},
{
"input": "7 8",
"output": "7"
},
{
"input": "10 235",
"output": "1"
}
] | 1,678,036,143 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 1 | 46 | 0 | data = list(map(int, input().split()))
timeleft = (240-data[1])
problemsDone = 0
for i in range(1, data[0]+1):
if timeleft-5*i > 0:
timeleft = timeleft-5*i
problemsDone += 1
else:
break
print(problemsDone) | Title: New Year and Hurry
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Limak is going to participate in a contest on the last day of the 2016. The contest will start at 20:00 and will last four hours, exactly until midnight. There will be *n* problems, sorted by difficulty, i.e. problem 1 is the easiest and problem *n* is the hardest. Limak knows it will take him 5·*i* minutes to solve the *i*-th problem.
Limak's friends organize a New Year's Eve party and Limak wants to be there at midnight or earlier. He needs *k* minutes to get there from his house, where he will participate in the contest first.
How many problems can Limak solve if he wants to make it to the party?
Input Specification:
The only line of the input contains two integers *n* and *k* (1<=≤<=*n*<=≤<=10, 1<=≤<=*k*<=≤<=240) — the number of the problems in the contest and the number of minutes Limak needs to get to the party from his house.
Output Specification:
Print one integer, denoting the maximum possible number of problems Limak can solve so that he could get to the party at midnight or earlier.
Demo Input:
['3 222\n', '4 190\n', '7 1\n']
Demo Output:
['2\n', '4\n', '7\n']
Note:
In the first sample, there are 3 problems and Limak needs 222 minutes to get to the party. The three problems require 5, 10 and 15 minutes respectively. Limak can spend 5 + 10 = 15 minutes to solve first two problems. Then, at 20:15 he can leave his house to get to the party at 23:57 (after 222 minutes). In this scenario Limak would solve 2 problems. He doesn't have enough time to solve 3 problems so the answer is 2.
In the second sample, Limak can solve all 4 problems in 5 + 10 + 15 + 20 = 50 minutes. At 20:50 he will leave the house and go to the party. He will get there exactly at midnight.
In the third sample, Limak needs only 1 minute to get to the party. He has enough time to solve all 7 problems. | ```python
data = list(map(int, input().split()))
timeleft = (240-data[1])
problemsDone = 0
for i in range(1, data[0]+1):
if timeleft-5*i > 0:
timeleft = timeleft-5*i
problemsDone += 1
else:
break
print(problemsDone)
``` | 0 |
|
767 | A | Snacktower | PROGRAMMING | 1,100 | [
"data structures",
"implementation"
] | null | null | According to an old legeng, a long time ago Ankh-Morpork residents did something wrong to miss Fortune, and she cursed them. She said that at some time *n* snacks of distinct sizes will fall on the city, and the residents should build a Snacktower of them by placing snacks one on another. Of course, big snacks should be at the bottom of the tower, while small snacks should be at the top.
Years passed, and once different snacks started to fall onto the city, and the residents began to build the Snacktower.
However, they faced some troubles. Each day exactly one snack fell onto the city, but their order was strange. So, at some days the residents weren't able to put the new stack on the top of the Snacktower: they had to wait until all the bigger snacks fell. Of course, in order to not to anger miss Fortune again, the residents placed each snack on the top of the tower immediately as they could do it.
Write a program that models the behavior of Ankh-Morpork residents. | The first line contains single integer *n* (1<=≤<=*n*<=≤<=100<=000) — the total number of snacks.
The second line contains *n* integers, the *i*-th of them equals the size of the snack which fell on the *i*-th day. Sizes are distinct integers from 1 to *n*. | Print *n* lines. On the *i*-th of them print the sizes of the snacks which the residents placed on the top of the Snacktower on the *i*-th day in the order they will do that. If no snack is placed on some day, leave the corresponding line empty. | [
"3\n3 1 2\n",
"5\n4 5 1 2 3\n"
] | [
"3\n \n2 1",
"5 4\n \n \n3 2 1\n"
] | In the example a snack of size 3 fell on the first day, and the residents immediately placed it. On the second day a snack of size 1 fell, and the residents weren't able to place it because they were missing the snack of size 2. On the third day a snack of size 2 fell, and the residents immediately placed it. Right after that they placed the snack of size 1 which had fallen before. | 500 | [
{
"input": "3\n3 1 2",
"output": "3 \n\n2 1 "
},
{
"input": "5\n4 5 1 2 3",
"output": "5 4 \n\n\n3 2 1 "
},
{
"input": "1\n1",
"output": "1 "
},
{
"input": "2\n1 2",
"output": "2 1 "
},
{
"input": "10\n5 1 6 2 8 3 4 10 9 7",
"output": "10 \n9 8 \n7 6 5 4 3 2 1 "
},
{
"input": "30\n16 10 4 29 5 28 12 21 11 30 18 6 14 3 17 22 20 15 9 1 27 19 24 26 13 25 2 23 8 7",
"output": "30 29 28 \n\n\n\n\n\n\n\n\n\n\n27 \n\n\n26 \n\n25 24 \n\n23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 \n8 \n7 6 5 4 3 2 1 "
},
{
"input": "100\n98 52 63 2 18 96 31 58 84 40 41 45 66 100 46 71 26 48 81 20 73 91 68 76 13 93 17 29 64 95 79 21 55 75 19 85 54 51 89 78 15 87 43 59 36 1 90 35 65 56 62 28 86 5 82 49 3 99 33 9 92 32 74 69 27 22 77 16 44 94 34 6 57 70 23 12 61 25 8 11 67 47 83 88 10 14 30 7 97 60 42 37 24 38 53 50 4 80 72 39",
"output": "100 \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\n99 98 \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\n97 96 95 94 93 92 91 90 89 88 87 86 85 84 83 82 81 \n\n\n\n\n\n\n\n\n80 79 78 77 76 75 74 73 \n72 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 \n39 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 "
},
{
"input": "2\n2 1",
"output": "2 \n1 "
}
] | 1,594,840,349 | 2,147,483,647 | Python 3 | OK | TESTS | 25 | 374 | 17,817,600 | def solve():
n = int(input())
waiting_for = n
stored = set([])
for i in [int(i) for i in input().split()]:
if i == waiting_for:
stored.add(i)
res = []
for j in range(i, 0, -1):
if j in stored: res.append(str(j))
else:
waiting_for = j
break
print(' '.join(res))
else:
print('')
stored.add(i)
solve()
| Title: Snacktower
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
According to an old legeng, a long time ago Ankh-Morpork residents did something wrong to miss Fortune, and she cursed them. She said that at some time *n* snacks of distinct sizes will fall on the city, and the residents should build a Snacktower of them by placing snacks one on another. Of course, big snacks should be at the bottom of the tower, while small snacks should be at the top.
Years passed, and once different snacks started to fall onto the city, and the residents began to build the Snacktower.
However, they faced some troubles. Each day exactly one snack fell onto the city, but their order was strange. So, at some days the residents weren't able to put the new stack on the top of the Snacktower: they had to wait until all the bigger snacks fell. Of course, in order to not to anger miss Fortune again, the residents placed each snack on the top of the tower immediately as they could do it.
Write a program that models the behavior of Ankh-Morpork residents.
Input Specification:
The first line contains single integer *n* (1<=≤<=*n*<=≤<=100<=000) — the total number of snacks.
The second line contains *n* integers, the *i*-th of them equals the size of the snack which fell on the *i*-th day. Sizes are distinct integers from 1 to *n*.
Output Specification:
Print *n* lines. On the *i*-th of them print the sizes of the snacks which the residents placed on the top of the Snacktower on the *i*-th day in the order they will do that. If no snack is placed on some day, leave the corresponding line empty.
Demo Input:
['3\n3 1 2\n', '5\n4 5 1 2 3\n']
Demo Output:
['3\n\xa0\n2 1', '5 4\n\xa0\n\xa0\n3 2 1\n']
Note:
In the example a snack of size 3 fell on the first day, and the residents immediately placed it. On the second day a snack of size 1 fell, and the residents weren't able to place it because they were missing the snack of size 2. On the third day a snack of size 2 fell, and the residents immediately placed it. Right after that they placed the snack of size 1 which had fallen before. | ```python
def solve():
n = int(input())
waiting_for = n
stored = set([])
for i in [int(i) for i in input().split()]:
if i == waiting_for:
stored.add(i)
res = []
for j in range(i, 0, -1):
if j in stored: res.append(str(j))
else:
waiting_for = j
break
print(' '.join(res))
else:
print('')
stored.add(i)
solve()
``` | 3 |
|
227 | B | Effective Approach | PROGRAMMING | 1,100 | [
"implementation"
] | null | null | Once at a team training Vasya, Petya and Sasha got a problem on implementing linear search in an array.
According to the boys, linear search works as follows. The array elements in a pre-selected order are in turn compared with the number that you need to find. Once you find the array element that is equal to the required one, the search ends. The efficiency of the algorithm is the number of performed comparisons. The fewer comparisons the linear search has made, the more effective it is.
Vasya believes that a linear search would work better if it sequentially iterates through the elements, starting with the 1-st one (in this problem we consider the elements of the array indexed from 1 to *n*) and ending with the *n*-th one. And Petya says that Vasya is wrong: the search will need less comparisons if it sequentially iterates the elements starting from the *n*-th and ending with the 1-st one. Sasha argues that the two approaches are equivalent.
To finally begin the task, the teammates decided to settle the debate and compare the two approaches on an example. For this, they took an array that is a permutation of integers from 1 to *n*, and generated *m* queries of the form: find element with value *b**i* in the array. They want to calculate for both approaches how many comparisons in total the linear search will need to respond to all queries. If the first search needs fewer comparisons, then the winner of the dispute is Vasya. If the second one does, then the winner is Petya. If both approaches make the same number of comparisons, then Sasha's got the upper hand.
But the problem is, linear search is too slow. That's why the boys aren't going to find out who is right before the end of the training, unless you come in here. Help them to determine who will win the dispute. | The first line contains integer *n* (1<=≤<=*n*<=≤<=105) — the number of elements in the array. The second line contains *n* distinct space-separated integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=*n*) — the elements of array.
The third line contains integer *m* (1<=≤<=*m*<=≤<=105) — the number of queries. The last line contains *m* space-separated integers *b*1,<=*b*2,<=...,<=*b**m* (1<=≤<=*b**i*<=≤<=*n*) — the search queries. Note that the queries can repeat. | Print two integers, showing how many comparisons Vasya's approach needs and how many comparisons Petya's approach needs. Separate the numbers by spaces.
Please, do not use the %lld specifier to read or write 64-bit integers in С++. It is preferred to use cin, cout streams or the %I64d specifier. | [
"2\n1 2\n1\n1\n",
"2\n2 1\n1\n1\n",
"3\n3 1 2\n3\n1 2 3\n"
] | [
"1 2\n",
"2 1\n",
"6 6\n"
] | In the first sample Vasya's approach will make one comparison (it starts with the 1-st element and immediately finds the required number), and Petya's approach makes two comparisons (first he compares with the 2-nd array element, doesn't find the search item and compares with the 1-st element).
In the second sample, on the contrary, Vasya's approach will need two comparisons (first with 1-st element, and then with the 2-nd), and Petya's approach will find the required value in one comparison (the first comparison with the 2-nd element). | 1,000 | [
{
"input": "2\n1 2\n1\n1",
"output": "1 2"
},
{
"input": "2\n2 1\n1\n1",
"output": "2 1"
},
{
"input": "3\n3 1 2\n3\n1 2 3",
"output": "6 6"
},
{
"input": "9\n2 9 3 1 6 4 7 8 5\n9\n5 1 5 2 8 4 4 4 5",
"output": "58 32"
},
{
"input": "10\n3 10 9 2 7 6 5 8 4 1\n1\n4",
"output": "9 2"
},
{
"input": "10\n5 2 10 8 3 1 9 7 6 4\n9\n2 5 9 2 3 2 5 9 8",
"output": "31 68"
},
{
"input": "9\n3 8 4 7 1 2 5 6 9\n3\n2 7 1",
"output": "15 15"
},
{
"input": "9\n5 3 8 4 2 6 1 7 9\n4\n6 1 9 2",
"output": "27 13"
},
{
"input": "4\n1 3 2 4\n4\n3 1 2 3",
"output": "8 12"
},
{
"input": "3\n1 2 3\n8\n3 2 1 1 2 3 1 2",
"output": "15 17"
}
] | 1,660,105,051 | 2,147,483,647 | Python 3 | OK | TESTS | 34 | 404 | 16,998,400 | n=int(input())
a,b={},{}
i=1
for z in input().split():
b[z]=i
if not (z in a): a[z]=i
i+=1
m=int(input())
ans1,ans2=0,0
for z in input().split():
ans1+=a[z]
ans2+=n-b[z]+1
print(ans1,ans2)
| Title: Effective Approach
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Once at a team training Vasya, Petya and Sasha got a problem on implementing linear search in an array.
According to the boys, linear search works as follows. The array elements in a pre-selected order are in turn compared with the number that you need to find. Once you find the array element that is equal to the required one, the search ends. The efficiency of the algorithm is the number of performed comparisons. The fewer comparisons the linear search has made, the more effective it is.
Vasya believes that a linear search would work better if it sequentially iterates through the elements, starting with the 1-st one (in this problem we consider the elements of the array indexed from 1 to *n*) and ending with the *n*-th one. And Petya says that Vasya is wrong: the search will need less comparisons if it sequentially iterates the elements starting from the *n*-th and ending with the 1-st one. Sasha argues that the two approaches are equivalent.
To finally begin the task, the teammates decided to settle the debate and compare the two approaches on an example. For this, they took an array that is a permutation of integers from 1 to *n*, and generated *m* queries of the form: find element with value *b**i* in the array. They want to calculate for both approaches how many comparisons in total the linear search will need to respond to all queries. If the first search needs fewer comparisons, then the winner of the dispute is Vasya. If the second one does, then the winner is Petya. If both approaches make the same number of comparisons, then Sasha's got the upper hand.
But the problem is, linear search is too slow. That's why the boys aren't going to find out who is right before the end of the training, unless you come in here. Help them to determine who will win the dispute.
Input Specification:
The first line contains integer *n* (1<=≤<=*n*<=≤<=105) — the number of elements in the array. The second line contains *n* distinct space-separated integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=*n*) — the elements of array.
The third line contains integer *m* (1<=≤<=*m*<=≤<=105) — the number of queries. The last line contains *m* space-separated integers *b*1,<=*b*2,<=...,<=*b**m* (1<=≤<=*b**i*<=≤<=*n*) — the search queries. Note that the queries can repeat.
Output Specification:
Print two integers, showing how many comparisons Vasya's approach needs and how many comparisons Petya's approach needs. Separate the numbers by spaces.
Please, do not use the %lld specifier to read or write 64-bit integers in С++. It is preferred to use cin, cout streams or the %I64d specifier.
Demo Input:
['2\n1 2\n1\n1\n', '2\n2 1\n1\n1\n', '3\n3 1 2\n3\n1 2 3\n']
Demo Output:
['1 2\n', '2 1\n', '6 6\n']
Note:
In the first sample Vasya's approach will make one comparison (it starts with the 1-st element and immediately finds the required number), and Petya's approach makes two comparisons (first he compares with the 2-nd array element, doesn't find the search item and compares with the 1-st element).
In the second sample, on the contrary, Vasya's approach will need two comparisons (first with 1-st element, and then with the 2-nd), and Petya's approach will find the required value in one comparison (the first comparison with the 2-nd element). | ```python
n=int(input())
a,b={},{}
i=1
for z in input().split():
b[z]=i
if not (z in a): a[z]=i
i+=1
m=int(input())
ans1,ans2=0,0
for z in input().split():
ans1+=a[z]
ans2+=n-b[z]+1
print(ans1,ans2)
``` | 3 |
|
740 | B | Alyona and flowers | PROGRAMMING | 1,200 | [
"constructive algorithms"
] | null | null | Little Alyona is celebrating Happy Birthday! Her mother has an array of *n* flowers. Each flower has some mood, the mood of *i*-th flower is *a**i*. The mood can be positive, zero or negative.
Let's define a subarray as a segment of consecutive flowers. The mother suggested some set of subarrays. Alyona wants to choose several of the subarrays suggested by her mother. After that, each of the flowers will add to the girl's happiness its mood multiplied by the number of chosen subarrays the flower is in.
For example, consider the case when the mother has 5 flowers, and their moods are equal to 1,<=<=-<=2,<=1,<=3,<=<=-<=4. Suppose the mother suggested subarrays (1,<=<=-<=2), (3,<=<=-<=4), (1,<=3), (1,<=<=-<=2,<=1,<=3). Then if the girl chooses the third and the fourth subarrays then:
- the first flower adds 1·1<==<=1 to the girl's happiness, because he is in one of chosen subarrays, - the second flower adds (<=-<=2)·1<==<=<=-<=2, because he is in one of chosen subarrays, - the third flower adds 1·2<==<=2, because he is in two of chosen subarrays, - the fourth flower adds 3·2<==<=6, because he is in two of chosen subarrays, - the fifth flower adds (<=-<=4)·0<==<=0, because he is in no chosen subarrays.
Thus, in total 1<=+<=(<=-<=2)<=+<=2<=+<=6<=+<=0<==<=7 is added to the girl's happiness. Alyona wants to choose such subarrays from those suggested by the mother that the value added to her happiness would be as large as possible. Help her do this!
Alyona can choose any number of the subarrays, even 0 or all suggested by her mother. | The first line contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=100) — the number of flowers and the number of subarrays suggested by the mother.
The second line contains the flowers moods — *n* integers *a*1,<=*a*2,<=...,<=*a**n* (<=-<=100<=≤<=*a**i*<=≤<=100).
The next *m* lines contain the description of the subarrays suggested by the mother. The *i*-th of these lines contain two integers *l**i* and *r**i* (1<=≤<=*l**i*<=≤<=*r**i*<=≤<=*n*) denoting the subarray *a*[*l**i*],<=*a*[*l**i*<=+<=1],<=...,<=*a*[*r**i*].
Each subarray can encounter more than once. | Print single integer — the maximum possible value added to the Alyona's happiness. | [
"5 4\n1 -2 1 3 -4\n1 2\n4 5\n3 4\n1 4\n",
"4 3\n1 2 3 4\n1 3\n2 4\n1 1\n",
"2 2\n-1 -2\n1 1\n1 2\n"
] | [
"7\n",
"16\n",
"0\n"
] | The first example is the situation described in the statements.
In the second example Alyona should choose all subarrays.
The third example has answer 0 because Alyona can choose none of the subarrays. | 1,000 | [
{
"input": "5 4\n1 -2 1 3 -4\n1 2\n4 5\n3 4\n1 4",
"output": "7"
},
{
"input": "4 3\n1 2 3 4\n1 3\n2 4\n1 1",
"output": "16"
},
{
"input": "2 2\n-1 -2\n1 1\n1 2",
"output": "0"
},
{
"input": "5 6\n1 1 1 -1 0\n2 4\n1 3\n4 5\n1 5\n1 4\n4 5",
"output": "8"
},
{
"input": "8 3\n5 -4 -2 5 3 -4 -2 6\n3 8\n4 6\n2 3",
"output": "10"
},
{
"input": "10 10\n0 0 0 0 0 0 0 0 0 0\n5 9\n1 9\n5 7\n3 8\n1 6\n1 9\n1 6\n6 9\n1 10\n3 8",
"output": "0"
},
{
"input": "3 6\n0 0 0\n1 1\n1 1\n1 3\n3 3\n2 3\n1 2",
"output": "0"
},
{
"input": "3 3\n1 -1 3\n1 2\n2 3\n1 3",
"output": "5"
},
{
"input": "6 8\n0 6 -5 8 -3 -2\n6 6\n2 3\n5 6\n4 6\n3 4\n2 5\n3 3\n5 6",
"output": "13"
},
{
"input": "10 4\n6 5 5 -1 0 5 0 -3 5 -4\n3 6\n4 9\n1 6\n1 4",
"output": "50"
},
{
"input": "9 1\n-1 -1 -1 -1 2 -1 2 0 0\n2 5",
"output": "0"
},
{
"input": "3 8\n3 4 4\n1 2\n1 3\n2 3\n1 2\n2 2\n1 1\n2 3\n1 3",
"output": "59"
},
{
"input": "3 8\n6 7 -1\n1 1\n1 3\n2 2\n1 3\n1 3\n1 1\n2 3\n2 3",
"output": "67"
},
{
"input": "53 7\n-43 57 92 97 85 -29 28 -8 -37 -47 51 -53 -95 -50 -39 -87 43 36 60 -95 93 8 67 -22 -78 -46 99 93 27 -72 -84 77 96 -47 1 -12 21 -98 -34 -88 57 -43 5 -15 20 -66 61 -29 30 -85 52 53 82\n15 26\n34 43\n37 41\n22 34\n19 43\n2 15\n13 35",
"output": "170"
},
{
"input": "20 42\n61 86 5 -87 -33 51 -79 17 -3 65 -42 74 -94 40 -35 22 58 81 -75 5\n3 6\n12 13\n3 16\n3 16\n5 7\n5 16\n2 15\n6 18\n4 18\n10 17\n14 16\n4 15\n4 11\n13 20\n5 6\n5 15\n16 17\n3 14\n9 10\n5 19\n5 14\n2 4\n17 20\n10 11\n5 18\n10 11\n1 14\n1 6\n1 10\n8 16\n11 14\n12 20\n11 13\n4 5\n2 13\n1 5\n11 15\n1 18\n3 8\n8 20\n1 4\n10 13",
"output": "1502"
},
{
"input": "64 19\n-47 13 19 51 -25 72 38 32 54 7 -49 -50 -59 73 45 -87 -15 -72 -32 -10 -7 47 -34 35 48 -73 79 25 -80 -34 4 77 60 30 61 -25 23 17 -73 -73 69 29 -50 -55 53 15 -33 7 -46 -5 85 -86 77 -51 87 -69 -64 -24 -64 29 -20 -58 11 -26\n6 53\n13 28\n15 47\n20 52\n12 22\n6 49\n31 54\n2 39\n32 49\n27 64\n22 63\n33 48\n49 58\n39 47\n6 29\n21 44\n24 59\n20 24\n39 54",
"output": "804"
},
{
"input": "1 10\n-46\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1",
"output": "0"
},
{
"input": "10 7\n44 18 9 -22 -23 7 -25 -2 15 35\n6 8\n6 7\n3 3\n2 6\n9 10\n2 2\n1 5",
"output": "103"
},
{
"input": "4 3\n10 -2 68 35\n4 4\n1 1\n1 3",
"output": "121"
},
{
"input": "3 6\n27 -31 -81\n2 3\n2 3\n1 1\n1 2\n1 2\n2 2",
"output": "27"
},
{
"input": "7 3\n-24 -12 16 -43 -30 31 16\n3 6\n3 4\n1 7",
"output": "0"
},
{
"input": "10 7\n-33 -24 -86 -20 5 -91 38 -12 -90 -67\n7 8\n7 10\n4 7\n1 3\n6 10\n6 6\n3 5",
"output": "26"
},
{
"input": "4 4\n95 35 96 -27\n3 4\n3 3\n4 4\n3 3",
"output": "261"
},
{
"input": "7 7\n-33 26 -25 44 -20 -50 33\n4 6\n4 4\n3 7\n5 7\n1 4\n2 5\n4 6",
"output": "81"
},
{
"input": "5 3\n-35 -39 93 59 -4\n2 2\n2 3\n2 5",
"output": "163"
},
{
"input": "3 7\n0 0 0\n1 2\n1 2\n2 3\n3 3\n1 3\n1 2\n2 3",
"output": "0"
},
{
"input": "8 2\n17 32 30 -6 -39 -15 33 74\n6 6\n8 8",
"output": "74"
},
{
"input": "8 1\n-20 -15 21 -21 1 -12 -7 9\n4 7",
"output": "0"
},
{
"input": "7 9\n-23 -4 -44 -47 -35 47 25\n1 6\n3 5\n4 7\n6 7\n2 4\n2 3\n2 7\n1 2\n5 5",
"output": "72"
},
{
"input": "8 8\n0 6 -25 -15 29 -24 31 23\n2 8\n5 5\n3 3\n2 8\n6 6\n3 6\n3 4\n2 4",
"output": "79"
},
{
"input": "4 3\n-39 -63 9 -16\n1 4\n1 3\n2 4",
"output": "0"
},
{
"input": "9 1\n-3 -13 -13 -19 -4 -11 8 -11 -3\n9 9",
"output": "0"
},
{
"input": "9 6\n25 18 -62 0 33 62 -23 4 -15\n7 9\n2 3\n1 4\n2 6\n1 6\n2 3",
"output": "127"
},
{
"input": "4 5\n-12 39 8 -12\n1 4\n3 4\n1 3\n1 3\n2 3",
"output": "140"
},
{
"input": "3 9\n-9 7 3\n1 2\n1 1\n1 3\n1 2\n2 3\n1 3\n2 2\n1 2\n3 3",
"output": "22"
},
{
"input": "10 7\n0 4 3 3 -2 -2 -4 -2 -3 -2\n5 6\n1 10\n2 10\n7 10\n1 1\n6 7\n3 4",
"output": "6"
},
{
"input": "86 30\n16 -12 11 16 8 14 7 -29 18 30 -32 -10 20 29 -14 -21 23 -19 -15 17 -2 25 -22 2 26 15 -7 -12 -4 -28 21 -4 -2 22 28 -32 9 -20 23 38 -21 21 37 -13 -30 25 31 6 18 29 29 29 27 38 -15 -32 32 -7 -8 -33 -11 24 23 -19 -36 -36 -18 9 -1 32 -34 -26 1 -1 -16 -14 17 -17 15 -24 38 5 -27 -12 8 -38\n60 66\n29 48\n32 51\n38 77\n17 79\n23 74\n39 50\n14 29\n26 76\n9 76\n2 67\n23 48\n17 68\n33 75\n59 78\n46 78\n9 69\n16 83\n18 21\n17 34\n24 61\n15 79\n4 31\n62 63\n46 76\n79 82\n25 39\n5 81\n19 77\n26 71",
"output": "3076"
},
{
"input": "33 17\n11 6 -19 14 23 -23 21 15 29 19 13 -18 -19 20 16 -10 26 -22 3 17 13 -10 19 22 -5 21 12 6 28 -13 -27 25 6\n4 17\n12 16\n9 17\n25 30\n31 32\n4 28\n11 24\n16 19\n3 27\n7 17\n1 16\n15 28\n30 33\n9 31\n14 30\n13 23\n27 27",
"output": "1366"
},
{
"input": "16 44\n32 23 -27 -2 -10 -42 32 -14 -13 4 9 -2 19 35 16 22\n6 12\n8 11\n13 15\n12 12\n3 10\n9 13\n7 15\n2 11\n1 13\n5 6\n9 14\n3 16\n10 13\n3 15\n6 10\n14 16\n4 5\n7 10\n5 14\n1 16\n2 5\n1 6\n9 10\n4 7\n4 12\n2 5\n7 10\n7 9\n2 8\n9 10\n4 10\n7 12\n10 11\n6 6\n15 15\n8 12\n9 10\n3 3\n4 15\n10 12\n7 16\n4 14\n14 16\n5 6",
"output": "777"
},
{
"input": "63 24\n-23 -46 0 33 24 13 39 -6 -4 49 19 -18 -11 -38 0 -3 -33 -17 -4 -44 -22 -12 -16 42 16 -10 7 37 -6 16 -41 -18 -20 51 -49 28 -14 -22 -37 -7 -50 31 -41 -47 18 -8 -39 -29 35 -32 14 -29 44 -29 -19 -25 -47 -8 16 11 20 12 38\n21 61\n35 61\n29 61\n21 34\n12 48\n32 33\n9 27\n4 42\n4 60\n37 61\n19 44\n46 60\n51 53\n31 34\n23 32\n5 29\n43 59\n7 31\n29 48\n15 50\n19 51\n7 28\n17 41\n1 62",
"output": "82"
},
{
"input": "6 51\n45 -33 -17 -48 2 2\n2 5\n1 1\n1 3\n5 5\n4 6\n1 2\n2 3\n3 4\n1 6\n4 6\n3 5\n1 5\n2 2\n2 6\n4 6\n1 5\n1 5\n1 5\n1 6\n6 6\n3 5\n6 6\n1 6\n3 4\n3 3\n2 4\n3 3\n1 4\n2 4\n5 6\n4 5\n2 4\n1 5\n1 2\n4 5\n1 5\n5 6\n2 2\n3 4\n1 3\n1 2\n2 5\n3 6\n4 6\n3 4\n2 4\n1 4\n1 1\n4 6\n3 5\n1 4",
"output": "140"
},
{
"input": "3 5\n2 -1 3\n2 3\n2 3\n2 3\n2 3\n1 2",
"output": "9"
},
{
"input": "4 30\n1 1 1 1\n1 4\n1 4\n1 4\n1 4\n1 4\n1 4\n1 4\n1 4\n1 4\n1 4\n1 4\n1 4\n1 4\n1 4\n1 4\n1 4\n1 4\n1 4\n1 4\n1 4\n1 4\n1 4\n1 4\n1 4\n1 4\n1 4\n1 4\n1 4\n1 4\n1 4",
"output": "120"
}
] | 1,480,450,460 | 2,147,483,647 | Python 3 | OK | TESTS | 53 | 77 | 0 | I = lambda: map(int, input().split())
n, m = I()
a = list(I())
result = 0
for _ in range(m):
l, r = I()
result += max(sum(a[l-1: r]), 0)
print(result)
| Title: Alyona and flowers
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Little Alyona is celebrating Happy Birthday! Her mother has an array of *n* flowers. Each flower has some mood, the mood of *i*-th flower is *a**i*. The mood can be positive, zero or negative.
Let's define a subarray as a segment of consecutive flowers. The mother suggested some set of subarrays. Alyona wants to choose several of the subarrays suggested by her mother. After that, each of the flowers will add to the girl's happiness its mood multiplied by the number of chosen subarrays the flower is in.
For example, consider the case when the mother has 5 flowers, and their moods are equal to 1,<=<=-<=2,<=1,<=3,<=<=-<=4. Suppose the mother suggested subarrays (1,<=<=-<=2), (3,<=<=-<=4), (1,<=3), (1,<=<=-<=2,<=1,<=3). Then if the girl chooses the third and the fourth subarrays then:
- the first flower adds 1·1<==<=1 to the girl's happiness, because he is in one of chosen subarrays, - the second flower adds (<=-<=2)·1<==<=<=-<=2, because he is in one of chosen subarrays, - the third flower adds 1·2<==<=2, because he is in two of chosen subarrays, - the fourth flower adds 3·2<==<=6, because he is in two of chosen subarrays, - the fifth flower adds (<=-<=4)·0<==<=0, because he is in no chosen subarrays.
Thus, in total 1<=+<=(<=-<=2)<=+<=2<=+<=6<=+<=0<==<=7 is added to the girl's happiness. Alyona wants to choose such subarrays from those suggested by the mother that the value added to her happiness would be as large as possible. Help her do this!
Alyona can choose any number of the subarrays, even 0 or all suggested by her mother.
Input Specification:
The first line contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=100) — the number of flowers and the number of subarrays suggested by the mother.
The second line contains the flowers moods — *n* integers *a*1,<=*a*2,<=...,<=*a**n* (<=-<=100<=≤<=*a**i*<=≤<=100).
The next *m* lines contain the description of the subarrays suggested by the mother. The *i*-th of these lines contain two integers *l**i* and *r**i* (1<=≤<=*l**i*<=≤<=*r**i*<=≤<=*n*) denoting the subarray *a*[*l**i*],<=*a*[*l**i*<=+<=1],<=...,<=*a*[*r**i*].
Each subarray can encounter more than once.
Output Specification:
Print single integer — the maximum possible value added to the Alyona's happiness.
Demo Input:
['5 4\n1 -2 1 3 -4\n1 2\n4 5\n3 4\n1 4\n', '4 3\n1 2 3 4\n1 3\n2 4\n1 1\n', '2 2\n-1 -2\n1 1\n1 2\n']
Demo Output:
['7\n', '16\n', '0\n']
Note:
The first example is the situation described in the statements.
In the second example Alyona should choose all subarrays.
The third example has answer 0 because Alyona can choose none of the subarrays. | ```python
I = lambda: map(int, input().split())
n, m = I()
a = list(I())
result = 0
for _ in range(m):
l, r = I()
result += max(sum(a[l-1: r]), 0)
print(result)
``` | 3 |
|
216 | B | Forming Teams | PROGRAMMING | 1,700 | [
"dfs and similar",
"implementation"
] | null | null | One day *n* students come to the stadium. They want to play football, and for that they need to split into teams, the teams must have an equal number of people.
We know that this group of people has archenemies. Each student has at most two archenemies. Besides, if student *A* is an archenemy to student *B*, then student *B* is an archenemy to student *A*.
The students want to split so as no two archenemies were in one team. If splitting in the required manner is impossible, some students will have to sit on the bench.
Determine the minimum number of students you will have to send to the bench in order to form the two teams in the described manner and begin the game at last. | The first line contains two integers *n* and *m* (2<=≤<=*n*<=≤<=100, 1<=≤<=*m*<=≤<=100) — the number of students and the number of pairs of archenemies correspondingly.
Next *m* lines describe enmity between students. Each enmity is described as two numbers *a**i* and *b**i* (1<=≤<=*a**i*,<=*b**i*<=≤<=*n*, *a**i*<=≠<=*b**i*) — the indexes of the students who are enemies to each other. Each enmity occurs in the list exactly once. It is guaranteed that each student has no more than two archenemies.
You can consider the students indexed in some manner with distinct integers from 1 to *n*. | Print a single integer — the minimum number of students you will have to send to the bench in order to start the game. | [
"5 4\n1 2\n2 4\n5 3\n1 4\n",
"6 2\n1 4\n3 4\n",
"6 6\n1 2\n2 3\n3 1\n4 5\n5 6\n6 4\n"
] | [
"1",
"0",
"2"
] | none | 1,500 | [
{
"input": "5 4\n1 2\n2 4\n5 3\n1 4",
"output": "1"
},
{
"input": "6 2\n1 4\n3 4",
"output": "0"
},
{
"input": "6 6\n1 2\n2 3\n3 1\n4 5\n5 6\n6 4",
"output": "2"
},
{
"input": "5 1\n1 2",
"output": "1"
},
{
"input": "8 8\n1 2\n2 3\n3 4\n4 5\n5 6\n6 7\n7 8\n8 1",
"output": "0"
},
{
"input": "28 3\n15 3\n10 19\n17 25",
"output": "0"
},
{
"input": "2 1\n1 2",
"output": "0"
},
{
"input": "3 1\n2 3",
"output": "1"
},
{
"input": "3 2\n1 2\n3 2",
"output": "1"
},
{
"input": "3 3\n1 2\n1 3\n2 3",
"output": "1"
},
{
"input": "4 1\n1 4",
"output": "0"
},
{
"input": "4 2\n4 1\n2 1",
"output": "0"
},
{
"input": "4 3\n1 3\n3 2\n2 4",
"output": "0"
},
{
"input": "4 3\n3 2\n4 2\n4 3",
"output": "2"
},
{
"input": "5 3\n4 2\n3 4\n5 1",
"output": "1"
},
{
"input": "10 7\n8 9\n3 6\n2 4\n4 1\n1 3\n2 7\n7 10",
"output": "0"
},
{
"input": "29 20\n15 9\n21 15\n14 12\n12 16\n3 28\n5 13\n19 1\n19 21\n23 17\n27 9\n26 10\n20 5\n8 16\n11 6\n4 22\n29 22\n29 11\n14 17\n28 6\n1 23",
"output": "1"
},
{
"input": "68 50\n10 9\n28 25\n53 46\n38 32\n46 9\n35 13\n65 21\n64 1\n15 52\n43 52\n31 7\n61 67\n41 49\n30 1\n14 4\n17 44\n25 7\n24 31\n57 51\n27 12\n3 37\n17 11\n41 16\n65 23\n10 2\n16 22\n40 36\n15 51\n58 44\n61 2\n50 30\n48 35\n45 32\n56 59\n37 49\n62 55\n62 11\n6 19\n34 33\n53 66\n67 39\n47 21\n56 40\n12 58\n4 23\n26 42\n42 5\n60 8\n5 63\n6 47",
"output": "0"
},
{
"input": "89 30\n86 72\n43 16\n32 80\n17 79\n29 8\n89 37\n84 65\n3 41\n55 79\n33 56\n60 40\n43 45\n59 38\n26 23\n66 61\n81 30\n65 25\n13 71\n25 8\n56 59\n46 13\n22 30\n87 3\n26 32\n75 44\n48 87\n47 4\n63 21\n36 6\n42 86",
"output": "1"
},
{
"input": "100 1\n3 87",
"output": "0"
},
{
"input": "100 10\n88 82\n5 78\n66 31\n65 100\n92 25\n71 62\n47 31\n17 67\n69 68\n59 49",
"output": "0"
},
{
"input": "100 50\n82 99\n27 56\n74 38\n16 68\n90 27\n77 4\n7 88\n77 33\n25 85\n18 70\n50 7\n31 5\n21 20\n50 83\n55 5\n46 83\n55 81\n73 6\n76 58\n60 67\n66 99\n71 23\n100 13\n76 8\n52 14\n6 54\n53 54\n88 22\n12 4\n33 60\n43 62\n42 31\n19 67\n98 80\n15 17\n78 79\n62 37\n66 96\n40 44\n37 86\n71 58\n42 92\n8 38\n92 13\n73 70\n46 41\n30 34\n15 65\n97 19\n14 53",
"output": "0"
},
{
"input": "10 9\n5 10\n3 2\n8 6\n4 5\n4 10\n6 1\n1 8\n9 2\n3 9",
"output": "4"
},
{
"input": "50 48\n33 21\n1 46\n43 37\n1 48\n42 32\n31 45\n14 29\n34 28\n38 19\n46 48\n49 31\n8 3\n27 23\n26 37\n15 9\n27 17\n9 35\n18 7\n35 15\n32 4\n23 17\n36 22\n16 33\n39 6\n40 13\n11 6\n21 16\n10 40\n30 36\n20 5\n24 3\n43 26\n22 30\n41 20\n50 38\n25 29\n5 41\n34 44\n12 7\n8 24\n44 28\n25 14\n12 18\n39 11\n42 4\n45 49\n50 19\n13 10",
"output": "16"
},
{
"input": "19 16\n2 16\n7 10\n17 16\n17 14\n1 5\n19 6\n11 13\n15 19\n7 9\n13 5\n4 6\n1 11\n12 9\n10 12\n2 14\n4 15",
"output": "1"
},
{
"input": "70 70\n27 54\n45 23\n67 34\n66 25\n64 38\n30 68\n51 65\n19 4\n15 33\n47 14\n3 9\n42 29\n69 56\n10 50\n34 58\n51 23\n55 14\n18 53\n27 68\n17 6\n48 6\n8 5\n46 37\n37 33\n21 36\n69 24\n16 13\n50 12\n59 31\n63 38\n22 11\n46 28\n67 62\n63 26\n70 31\n7 59\n55 52\n28 43\n18 35\n53 3\n16 60\n43 40\n61 9\n20 44\n47 41\n35 1\n32 4\n13 54\n30 60\n45 19\n39 42\n2 20\n2 26\n52 8\n12 25\n5 41\n21 10\n58 48\n29 11\n7 56\n49 57\n65 32\n15 40\n66 36\n64 44\n22 57\n1 61\n39 49\n24 70\n62 17",
"output": "10"
},
{
"input": "33 33\n2 16\n28 20\n13 9\n4 22\n18 1\n6 12\n13 29\n32 1\n17 15\n10 7\n6 15\n16 5\n11 10\n31 29\n25 8\n23 21\n14 32\n8 2\n19 3\n11 4\n21 25\n31 30\n33 5\n26 7\n27 26\n27 12\n30 24\n33 17\n28 22\n18 24\n19 9\n3 23\n14 20",
"output": "1"
},
{
"input": "10 8\n8 3\n9 7\n6 1\n10 9\n2 6\n2 1\n3 4\n4 8",
"output": "2"
},
{
"input": "20 12\n16 20\n8 3\n20 5\n5 10\n17 7\n13 2\n18 9\n17 18\n1 6\n14 4\n11 12\n10 16",
"output": "0"
},
{
"input": "35 21\n15 3\n13 5\n2 28\n26 35\n9 10\n22 18\n17 1\n31 32\n35 33\n5 15\n14 24\n29 12\n16 2\n14 10\n7 4\n29 4\n23 27\n30 34\n19 26\n23 11\n25 21",
"output": "1"
},
{
"input": "49 36\n17 47\n19 27\n41 23\n31 27\n11 29\n34 10\n35 2\n42 24\n19 16\n38 24\n5 9\n26 9\n36 14\n18 47\n28 40\n45 13\n35 22\n2 15\n31 30\n20 48\n39 3\n8 34\n36 7\n25 17\n5 39\n29 1\n32 33\n16 30\n38 49\n25 18\n1 11\n7 44\n12 43\n15 22\n49 21\n8 23",
"output": "3"
},
{
"input": "77 54\n18 56\n72 2\n6 62\n58 52\n5 70\n24 4\n67 66\n65 47\n43 77\n61 66\n24 51\n70 7\n48 39\n46 11\n77 28\n65 76\n15 6\n22 13\n34 75\n33 42\n59 37\n7 31\n50 23\n28 9\n17 29\n1 14\n11 45\n36 46\n32 39\n59 21\n22 34\n53 21\n29 47\n16 44\n69 4\n62 16\n36 3\n68 75\n51 69\n49 43\n30 55\n40 20\n57 60\n45 3\n38 33\n49 9\n71 19\n73 20\n48 32\n63 67\n8 54\n42 38\n26 12\n5 74",
"output": "5"
},
{
"input": "93 72\n3 87\n88 60\n73 64\n45 35\n61 85\n68 80\n54 29\n4 88\n19 91\n82 48\n50 2\n40 53\n56 8\n66 82\n83 81\n62 8\n79 30\n89 26\n77 10\n65 15\n27 47\n15 51\n70 6\n59 85\n63 20\n64 92\n7 1\n93 52\n74 38\n71 23\n83 12\n86 52\n46 56\n34 36\n37 84\n18 16\n11 42\n69 72\n53 20\n78 84\n54 91\n14 5\n65 49\n90 19\n42 39\n68 57\n75 27\n57 32\n44 9\n79 74\n48 66\n43 93\n31 30\n58 24\n80 67\n6 60\n39 5\n23 17\n25 1\n18 36\n32 67\n10 9\n14 11\n63 21\n92 73\n13 43\n28 78\n33 51\n4 70\n75 45\n37 28\n62 46",
"output": "5"
},
{
"input": "100 72\n2 88\n55 80\n22 20\n78 52\n66 74\n91 82\n59 77\n97 93\n46 44\n99 35\n73 62\n58 24\n6 16\n47 41\n98 86\n23 19\n39 68\n32 28\n85 29\n37 40\n16 62\n19 61\n84 72\n17 15\n76 96\n37 31\n67 35\n48 15\n80 85\n90 47\n79 36\n39 54\n57 87\n42 60\n34 56\n23 61\n92 2\n88 63\n20 42\n27 81\n65 84\n6 73\n64 100\n76 95\n43 4\n65 86\n21 46\n11 64\n72 98\n63 92\n7 50\n14 22\n89 30\n31 40\n8 57\n90 70\n53 59\n69 24\n96 49\n67 99\n51 70\n18 66\n91 3\n26 38\n13 58\n51 41\n9 11\n5 74\n3 25\n4 32\n28 43\n71 56",
"output": "6"
},
{
"input": "6 5\n1 2\n2 3\n3 4\n4 5\n5 1",
"output": "2"
},
{
"input": "6 4\n1 2\n1 3\n4 5\n4 6",
"output": "0"
},
{
"input": "16 16\n1 2\n2 3\n1 3\n4 5\n5 6\n4 6\n7 8\n8 9\n9 10\n10 11\n11 7\n12 13\n13 14\n14 15\n15 16\n16 12",
"output": "4"
},
{
"input": "4 4\n1 2\n4 3\n1 4\n2 3",
"output": "0"
},
{
"input": "9 9\n1 2\n2 3\n3 1\n4 5\n5 6\n6 4\n7 8\n8 9\n9 7",
"output": "3"
},
{
"input": "20 11\n1 2\n2 3\n3 4\n4 5\n5 6\n6 7\n7 8\n8 9\n9 10\n10 11\n11 1",
"output": "2"
},
{
"input": "4 3\n1 2\n3 4\n1 3",
"output": "0"
},
{
"input": "4 2\n2 4\n3 4",
"output": "0"
},
{
"input": "10 10\n1 2\n2 3\n3 4\n4 5\n5 1\n6 7\n7 8\n8 9\n9 10\n10 6",
"output": "2"
},
{
"input": "6 5\n2 1\n3 4\n2 3\n4 5\n5 6",
"output": "0"
},
{
"input": "8 5\n1 2\n2 3\n3 4\n4 5\n5 1",
"output": "2"
},
{
"input": "6 5\n1 2\n2 3\n3 4\n4 5\n1 5",
"output": "2"
},
{
"input": "8 8\n1 2\n2 3\n3 4\n1 4\n5 6\n6 7\n7 8\n5 8",
"output": "0"
},
{
"input": "6 5\n1 3\n1 2\n2 4\n5 3\n5 4",
"output": "2"
}
] | 1,666,093,631 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 23 | 154 | 0 | from sys import stdin,stdout
input=stdin.readline
def print(*args, end='\n', sep=' ') -> None:
stdout.write(sep.join(map(str, args)) + end)
def dfs(node,c):
global ans
visi[node]=c
for child in nodes[node]:
if not visi[child]:
dfs(child,c+1)
else:
if abs(visi[child]-visi[node])==2:
ans+=1
visi[child]+=1
n,m=map(int,input().split()) ; nodes={} ; visi=[0]*(n+1) ; ans=0
for i in range(m):
x,y=map(int,input().split())
if x in nodes.keys():
nodes[x].append(y)
else:
nodes[x]=[y]
if y in nodes.keys():
nodes[y].append(x)
else:
nodes[y]=[x]
for i in nodes.keys():
if not visi[i]:
dfs(i,1)
if (n-ans)%2==1:
print(ans+1)
else:
print(ans)
| Title: Forming Teams
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
One day *n* students come to the stadium. They want to play football, and for that they need to split into teams, the teams must have an equal number of people.
We know that this group of people has archenemies. Each student has at most two archenemies. Besides, if student *A* is an archenemy to student *B*, then student *B* is an archenemy to student *A*.
The students want to split so as no two archenemies were in one team. If splitting in the required manner is impossible, some students will have to sit on the bench.
Determine the minimum number of students you will have to send to the bench in order to form the two teams in the described manner and begin the game at last.
Input Specification:
The first line contains two integers *n* and *m* (2<=≤<=*n*<=≤<=100, 1<=≤<=*m*<=≤<=100) — the number of students and the number of pairs of archenemies correspondingly.
Next *m* lines describe enmity between students. Each enmity is described as two numbers *a**i* and *b**i* (1<=≤<=*a**i*,<=*b**i*<=≤<=*n*, *a**i*<=≠<=*b**i*) — the indexes of the students who are enemies to each other. Each enmity occurs in the list exactly once. It is guaranteed that each student has no more than two archenemies.
You can consider the students indexed in some manner with distinct integers from 1 to *n*.
Output Specification:
Print a single integer — the minimum number of students you will have to send to the bench in order to start the game.
Demo Input:
['5 4\n1 2\n2 4\n5 3\n1 4\n', '6 2\n1 4\n3 4\n', '6 6\n1 2\n2 3\n3 1\n4 5\n5 6\n6 4\n']
Demo Output:
['1', '0', '2']
Note:
none | ```python
from sys import stdin,stdout
input=stdin.readline
def print(*args, end='\n', sep=' ') -> None:
stdout.write(sep.join(map(str, args)) + end)
def dfs(node,c):
global ans
visi[node]=c
for child in nodes[node]:
if not visi[child]:
dfs(child,c+1)
else:
if abs(visi[child]-visi[node])==2:
ans+=1
visi[child]+=1
n,m=map(int,input().split()) ; nodes={} ; visi=[0]*(n+1) ; ans=0
for i in range(m):
x,y=map(int,input().split())
if x in nodes.keys():
nodes[x].append(y)
else:
nodes[x]=[y]
if y in nodes.keys():
nodes[y].append(x)
else:
nodes[y]=[x]
for i in nodes.keys():
if not visi[i]:
dfs(i,1)
if (n-ans)%2==1:
print(ans+1)
else:
print(ans)
``` | 0 |
|
12 | A | Super Agent | PROGRAMMING | 800 | [
"implementation"
] | A. Super Agent | 2 | 256 | There is a very secret base in Potatoland where potato mash is made according to a special recipe. The neighbours from Porridgia decided to seize this recipe and to sell it to Pilauland. For this mission they have been preparing special agent Pearlo for many years. When, finally, Pearlo learned all secrets of espionage, he penetrated into the Potatoland territory and reached the secret base.
Now he is standing at the entrance, but to get inside he need to pass combination lock. Minute ago one of the workers entered the password on the terminal and opened the door. The terminal is a square digital keyboard 3<=×<=3 with digits from 1 to 9.
Pearlo knows that the password consists from distinct digits and is probably symmetric with respect to the central button of the terminal. He has heat sensor which allowed him to detect the digits which the worker pressed. Now he wants to check whether the password entered by the worker is symmetric with respect to the central button of the terminal. This fact can Help Pearlo to reduce the number of different possible password combinations. | Input contains the matrix of three rows of three symbols each. Symbol «X» means that the corresponding button was pressed, and «.» means that is was not pressed. The matrix may contain no «X», also it may contain no «.». | Print YES if the password is symmetric with respect to the central button of the terminal and NO otherwise. | [
"XX.\n...\n.XX\n",
"X.X\nX..\n...\n"
] | [
"YES\n",
"NO\n"
] | If you are not familiar with the term «central symmetry», you may look into http://en.wikipedia.org/wiki/Central_symmetry | 0 | [
{
"input": "XX.\n...\n.XX",
"output": "YES"
},
{
"input": ".X.\n.X.\n.X.",
"output": "YES"
},
{
"input": "XXX\nXXX\nXXX",
"output": "YES"
},
{
"input": "XXX\nX.X\nXXX",
"output": "YES"
},
{
"input": "X..\n.X.\n..X",
"output": "YES"
},
{
"input": "...\nX.X\nX..",
"output": "NO"
},
{
"input": ".X.\nX.X\n.X.",
"output": "YES"
},
{
"input": "X.X\n.X.\nX.X",
"output": "YES"
},
{
"input": "...\n...\n..X",
"output": "NO"
},
{
"input": "XXX\n...\nXXX",
"output": "YES"
},
{
"input": "..X\nX..\n..X",
"output": "NO"
},
{
"input": ".X.\n...\nX.X",
"output": "NO"
},
{
"input": "X.X\nX.X\nX.X",
"output": "YES"
},
{
"input": ".X.\nX.X\nXX.",
"output": "NO"
},
{
"input": "...\nXXX\nXXX",
"output": "NO"
},
{
"input": "XXX\n..X\nXXX",
"output": "NO"
},
{
"input": "X..\nX.X\n.X.",
"output": "NO"
},
{
"input": "...\n..X\nXXX",
"output": "NO"
},
{
"input": "..X\nX.X\nX..",
"output": "YES"
},
{
"input": "..X\n..X\nXXX",
"output": "NO"
},
{
"input": "X..\nX..\nX..",
"output": "NO"
},
{
"input": "XXX\n.X.\nXXX",
"output": "YES"
},
{
"input": "..X\n...\nX..",
"output": "YES"
},
{
"input": "...\n...\nX..",
"output": "NO"
},
{
"input": "...\n...\n.X.",
"output": "NO"
},
{
"input": "...\n...\n..X",
"output": "NO"
},
{
"input": "...\n.X.\nX..",
"output": "NO"
}
] | 1,650,383,934 | 2,147,483,647 | PyPy 3 | OK | TESTS | 40 | 124 | 0 | # https://codeforces.com/problemset/problem/12/A
import sys
def solution(lines):
for i in range(3):
for j in range(3):
if lines[i][j] == 'X':
if lines[2-i][2-j] != 'X':
return "NO"
return "YES"
inp = [line.strip() for line in sys.stdin]
print(solution(inp)) | Title: Super Agent
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
There is a very secret base in Potatoland where potato mash is made according to a special recipe. The neighbours from Porridgia decided to seize this recipe and to sell it to Pilauland. For this mission they have been preparing special agent Pearlo for many years. When, finally, Pearlo learned all secrets of espionage, he penetrated into the Potatoland territory and reached the secret base.
Now he is standing at the entrance, but to get inside he need to pass combination lock. Minute ago one of the workers entered the password on the terminal and opened the door. The terminal is a square digital keyboard 3<=×<=3 with digits from 1 to 9.
Pearlo knows that the password consists from distinct digits and is probably symmetric with respect to the central button of the terminal. He has heat sensor which allowed him to detect the digits which the worker pressed. Now he wants to check whether the password entered by the worker is symmetric with respect to the central button of the terminal. This fact can Help Pearlo to reduce the number of different possible password combinations.
Input Specification:
Input contains the matrix of three rows of three symbols each. Symbol «X» means that the corresponding button was pressed, and «.» means that is was not pressed. The matrix may contain no «X», also it may contain no «.».
Output Specification:
Print YES if the password is symmetric with respect to the central button of the terminal and NO otherwise.
Demo Input:
['XX.\n...\n.XX\n', 'X.X\nX..\n...\n']
Demo Output:
['YES\n', 'NO\n']
Note:
If you are not familiar with the term «central symmetry», you may look into http://en.wikipedia.org/wiki/Central_symmetry | ```python
# https://codeforces.com/problemset/problem/12/A
import sys
def solution(lines):
for i in range(3):
for j in range(3):
if lines[i][j] == 'X':
if lines[2-i][2-j] != 'X':
return "NO"
return "YES"
inp = [line.strip() for line in sys.stdin]
print(solution(inp))
``` | 3.969 |
687 | B | Remainders Game | PROGRAMMING | 1,800 | [
"chinese remainder theorem",
"math",
"number theory"
] | null | null | Today Pari and Arya are playing a game called Remainders.
Pari chooses two positive integer *x* and *k*, and tells Arya *k* but not *x*. Arya have to find the value . There are *n* ancient numbers *c*1,<=*c*2,<=...,<=*c**n* and Pari has to tell Arya if Arya wants. Given *k* and the ancient values, tell us if Arya has a winning strategy independent of value of *x* or not. Formally, is it true that Arya can understand the value for any positive integer *x*?
Note, that means the remainder of *x* after dividing it by *y*. | The first line of the input contains two integers *n* and *k* (1<=≤<=*n*,<= *k*<=≤<=1<=000<=000) — the number of ancient integers and value *k* that is chosen by Pari.
The second line contains *n* integers *c*1,<=*c*2,<=...,<=*c**n* (1<=≤<=*c**i*<=≤<=1<=000<=000). | Print "Yes" (without quotes) if Arya has a winning strategy independent of value of *x*, or "No" (without quotes) otherwise. | [
"4 5\n2 3 5 12\n",
"2 7\n2 3\n"
] | [
"Yes\n",
"No\n"
] | In the first sample, Arya can understand <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/d170efffcde0907ee6bcf32de21051bce0677a2c.png" style="max-width: 100.0%;max-height: 100.0%;"/> because 5 is one of the ancient numbers.
In the second sample, Arya can't be sure what <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/57b5f6a96f5db073270dd3ed4266c69299ec701d.png" style="max-width: 100.0%;max-height: 100.0%;"/> is. For example 1 and 7 have the same remainders after dividing by 2 and 3, but they differ in remainders after dividing by 7. | 1,000 | [
{
"input": "4 5\n2 3 5 12",
"output": "Yes"
},
{
"input": "2 7\n2 3",
"output": "No"
},
{
"input": "1 6\n8",
"output": "No"
},
{
"input": "2 3\n9 4",
"output": "Yes"
},
{
"input": "4 16\n19 16 13 9",
"output": "Yes"
},
{
"input": "5 10\n5 16 19 9 17",
"output": "Yes"
},
{
"input": "11 95\n31 49 8 139 169 121 71 17 43 29 125",
"output": "No"
},
{
"input": "17 71\n173 43 139 73 169 199 49 81 11 89 131 107 23 29 125 152 17",
"output": "No"
},
{
"input": "13 86\n41 64 17 31 13 97 19 25 81 47 61 37 71",
"output": "No"
},
{
"input": "15 91\n49 121 83 67 128 125 27 113 41 169 149 19 37 29 71",
"output": "Yes"
},
{
"input": "2 4\n2 2",
"output": "No"
},
{
"input": "14 87\n1619 1619 1619 1619 1619 1619 1619 1619 1619 1619 1619 1619 1619 1619",
"output": "No"
},
{
"input": "12 100\n1766 1766 1766 1766 1766 1766 1766 1766 1766 1766 1766 1766",
"output": "No"
},
{
"input": "1 994619\n216000",
"output": "No"
},
{
"input": "1 651040\n911250",
"output": "No"
},
{
"input": "1 620622\n60060",
"output": "No"
},
{
"input": "1 1\n559872",
"output": "Yes"
},
{
"input": "88 935089\n967 967 967 967 967 967 967 967 967 967 967 967 967 967 967 967 967 967 967 967 967 967 967 967 967 967 967 967 967 967 967 967 967 967 967 967 967 967 967 967 967 967 967 967 967 967 967 967 967 967 967 967 967 967 967 967 967 967 967 967 967 967 967 967 967 967 967 967 967 967 967 967 967 967 967 967 967 967 967 967 967 967 967 967 967 967 967 967",
"output": "No"
},
{
"input": "93 181476\n426 426 426 426 426 426 426 426 426 426 426 426 426 426 426 426 426 426 426 426 426 426 426 426 426 426 426 426 426 426 426 426 426 426 426 426 426 426 426 426 426 426 426 426 426 426 426 426 426 426 426 426 426 426 426 426 426 426 426 426 426 426 426 426 426 426 426 426 426 426 426 426 426 426 426 426 426 426 426 426 426 426 426 426 426 426 426 426 426 426 426 426 426",
"output": "No"
},
{
"input": "91 4900\n630 630 70 630 910 630 630 630 770 70 770 630 630 770 70 630 70 630 70 630 70 630 630 70 910 630 630 630 770 630 630 630 70 910 70 630 70 630 770 630 630 70 630 770 70 630 70 70 630 630 70 70 70 70 630 70 70 770 910 630 70 630 770 70 910 70 630 910 630 70 770 70 70 630 770 630 70 630 70 70 630 70 630 770 630 70 630 630 70 910 630",
"output": "No"
},
{
"input": "61 531012\n698043 698043 698043 963349 698043 698043 698043 963349 698043 698043 698043 963349 698043 698043 698043 698043 966694 698043 698043 698043 698043 698043 698043 636247 698043 963349 698043 698043 698043 698043 697838 698043 963349 698043 698043 966694 698043 698043 698043 698043 698043 698043 698043 698043 698043 698043 698043 698043 698043 698043 698043 698043 698043 698043 963349 698043 698043 698043 698043 963349 698043",
"output": "No"
},
{
"input": "1 216000\n648000",
"output": "Yes"
},
{
"input": "2 8\n4 4",
"output": "No"
},
{
"input": "3 8\n4 4 4",
"output": "No"
},
{
"input": "2 8\n2 4",
"output": "No"
},
{
"input": "3 12\n2 2 3",
"output": "No"
},
{
"input": "10 4\n2 2 2 2 2 2 2 2 2 2",
"output": "No"
},
{
"input": "10 1024\n1 2 4 8 16 32 64 128 256 512",
"output": "No"
},
{
"input": "3 24\n2 2 3",
"output": "No"
},
{
"input": "1 8\n2",
"output": "No"
},
{
"input": "2 9\n3 3",
"output": "No"
},
{
"input": "3 4\n2 2 2",
"output": "No"
},
{
"input": "3 4\n1 2 2",
"output": "No"
},
{
"input": "1 4\n2",
"output": "No"
},
{
"input": "1 100003\n2",
"output": "No"
},
{
"input": "1 2\n12",
"output": "Yes"
},
{
"input": "2 988027\n989018 995006",
"output": "Yes"
},
{
"input": "3 9\n3 3 3",
"output": "No"
},
{
"input": "1 49\n7",
"output": "No"
},
{
"input": "2 600000\n200000 300000",
"output": "Yes"
},
{
"input": "3 8\n2 2 2",
"output": "No"
},
{
"input": "7 510510\n524288 531441 390625 823543 161051 371293 83521",
"output": "Yes"
},
{
"input": "2 30\n6 10",
"output": "Yes"
},
{
"input": "2 27000\n5400 4500",
"output": "Yes"
},
{
"input": "3 8\n1 2 4",
"output": "No"
},
{
"input": "4 16\n2 2 2 2",
"output": "No"
},
{
"input": "2 16\n4 8",
"output": "No"
},
{
"input": "2 8\n4 2",
"output": "No"
},
{
"input": "3 4\n2 2 3",
"output": "No"
},
{
"input": "1 8\n4",
"output": "No"
},
{
"input": "1 999983\n2",
"output": "No"
},
{
"input": "3 16\n2 4 8",
"output": "No"
},
{
"input": "2 216\n12 18",
"output": "No"
},
{
"input": "2 16\n8 8",
"output": "No"
},
{
"input": "2 36\n18 12",
"output": "Yes"
},
{
"input": "2 36\n12 18",
"output": "Yes"
},
{
"input": "2 1000000\n1000000 1000000",
"output": "Yes"
},
{
"input": "3 20\n2 2 5",
"output": "No"
},
{
"input": "1 2\n6",
"output": "Yes"
},
{
"input": "4 4\n2 3 6 5",
"output": "No"
},
{
"input": "1 2\n1",
"output": "No"
},
{
"input": "1 6\n6",
"output": "Yes"
},
{
"input": "2 16\n4 4",
"output": "No"
},
{
"input": "2 3779\n1 2",
"output": "No"
},
{
"input": "2 8\n4 12",
"output": "No"
},
{
"input": "2 24\n4 6",
"output": "No"
},
{
"input": "1 1\n5",
"output": "Yes"
},
{
"input": "10 255255\n1000000 700000 300000 110000 130000 170000 190000 230000 290000 310000",
"output": "Yes"
},
{
"input": "2 1000\n500 2",
"output": "No"
},
{
"input": "4 8\n2 2 2 2",
"output": "No"
},
{
"input": "1 666013\n1",
"output": "No"
},
{
"input": "1 999983\n1",
"output": "No"
},
{
"input": "1 125\n5",
"output": "No"
},
{
"input": "2 32\n4 8",
"output": "No"
},
{
"input": "3 32\n2 4 8",
"output": "No"
},
{
"input": "3 8\n2 4 11",
"output": "No"
},
{
"input": "1 32\n2",
"output": "No"
},
{
"input": "4 4\n2 2 2 2",
"output": "No"
},
{
"input": "8 32\n2 2 2 2 2 2 2 2",
"output": "No"
},
{
"input": "3 24\n2 4 3",
"output": "No"
},
{
"input": "2 4\n2 6",
"output": "No"
},
{
"input": "2 24\n6 4",
"output": "No"
},
{
"input": "1 20998\n2",
"output": "No"
},
{
"input": "1 1\n1",
"output": "Yes"
},
{
"input": "2 20998\n2 10499",
"output": "Yes"
},
{
"input": "1 5\n1",
"output": "No"
},
{
"input": "2 25\n5 5",
"output": "No"
},
{
"input": "5 2\n2 2 2 2 2",
"output": "Yes"
},
{
"input": "3 12\n2 3 6",
"output": "No"
},
{
"input": "1 1\n3",
"output": "Yes"
},
{
"input": "2 16\n8 4",
"output": "No"
},
{
"input": "40 10\n2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2",
"output": "No"
}
] | 1,689,347,148 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 0 | 30 | 0 | print("_RANDOM_GUESS_1689347148.631328")# 1689347148.631341 | Title: Remainders Game
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Today Pari and Arya are playing a game called Remainders.
Pari chooses two positive integer *x* and *k*, and tells Arya *k* but not *x*. Arya have to find the value . There are *n* ancient numbers *c*1,<=*c*2,<=...,<=*c**n* and Pari has to tell Arya if Arya wants. Given *k* and the ancient values, tell us if Arya has a winning strategy independent of value of *x* or not. Formally, is it true that Arya can understand the value for any positive integer *x*?
Note, that means the remainder of *x* after dividing it by *y*.
Input Specification:
The first line of the input contains two integers *n* and *k* (1<=≤<=*n*,<= *k*<=≤<=1<=000<=000) — the number of ancient integers and value *k* that is chosen by Pari.
The second line contains *n* integers *c*1,<=*c*2,<=...,<=*c**n* (1<=≤<=*c**i*<=≤<=1<=000<=000).
Output Specification:
Print "Yes" (without quotes) if Arya has a winning strategy independent of value of *x*, or "No" (without quotes) otherwise.
Demo Input:
['4 5\n2 3 5 12\n', '2 7\n2 3\n']
Demo Output:
['Yes\n', 'No\n']
Note:
In the first sample, Arya can understand <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/d170efffcde0907ee6bcf32de21051bce0677a2c.png" style="max-width: 100.0%;max-height: 100.0%;"/> because 5 is one of the ancient numbers.
In the second sample, Arya can't be sure what <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/57b5f6a96f5db073270dd3ed4266c69299ec701d.png" style="max-width: 100.0%;max-height: 100.0%;"/> is. For example 1 and 7 have the same remainders after dividing by 2 and 3, but they differ in remainders after dividing by 7. | ```python
print("_RANDOM_GUESS_1689347148.631328")# 1689347148.631341
``` | 0 |
|
967 | B | Watering System | PROGRAMMING | 1,000 | [
"math",
"sortings"
] | null | null | Arkady wants to water his only flower. Unfortunately, he has a very poor watering system that was designed for $n$ flowers and so it looks like a pipe with $n$ holes. Arkady can only use the water that flows from the first hole.
Arkady can block some of the holes, and then pour $A$ liters of water into the pipe. After that, the water will flow out from the non-blocked holes proportionally to their sizes $s_1, s_2, \ldots, s_n$. In other words, if the sum of sizes of non-blocked holes is $S$, and the $i$-th hole is not blocked, $\frac{s_i \cdot A}{S}$ liters of water will flow out of it.
What is the minimum number of holes Arkady should block to make at least $B$ liters of water flow out of the first hole? | The first line contains three integers $n$, $A$, $B$ ($1 \le n \le 100\,000$, $1 \le B \le A \le 10^4$) — the number of holes, the volume of water Arkady will pour into the system, and the volume he wants to get out of the first hole.
The second line contains $n$ integers $s_1, s_2, \ldots, s_n$ ($1 \le s_i \le 10^4$) — the sizes of the holes. | Print a single integer — the number of holes Arkady should block. | [
"4 10 3\n2 2 2 2\n",
"4 80 20\n3 2 1 4\n",
"5 10 10\n1000 1 1 1 1\n"
] | [
"1\n",
"0\n",
"4\n"
] | In the first example Arkady should block at least one hole. After that, $\frac{10 \cdot 2}{6} \approx 3.333$ liters of water will flow out of the first hole, and that suits Arkady.
In the second example even without blocking any hole, $\frac{80 \cdot 3}{10} = 24$ liters will flow out of the first hole, that is not less than $20$.
In the third example Arkady has to block all holes except the first to make all water flow out of the first hole. | 1,000 | [
{
"input": "4 10 3\n2 2 2 2",
"output": "1"
},
{
"input": "4 80 20\n3 2 1 4",
"output": "0"
},
{
"input": "5 10 10\n1000 1 1 1 1",
"output": "4"
},
{
"input": "10 300 100\n20 1 3 10 8 5 3 6 4 3",
"output": "1"
},
{
"input": "10 300 100\n20 25 68 40 60 37 44 85 23 96",
"output": "8"
},
{
"input": "1 1 1\n1",
"output": "0"
},
{
"input": "1 2 1\n1",
"output": "0"
},
{
"input": "2 2 2\n1 10000",
"output": "1"
},
{
"input": "2 10000 1\n1 9999",
"output": "0"
}
] | 1,604,154,412 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 5 | 109 | 0 | # cook your dish here
n,a,b=map(int,input().split())
s=[int(i) for i in input().split(" ")]
i=1
count=0
sum1=sum(s)
while(i!=n):
flow=(s[0]*a)/sum1
if(flow>=b):
break
else:
sum1=sum1-s[n-i]
count+=1
i+=1
print(count) | Title: Watering System
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Arkady wants to water his only flower. Unfortunately, he has a very poor watering system that was designed for $n$ flowers and so it looks like a pipe with $n$ holes. Arkady can only use the water that flows from the first hole.
Arkady can block some of the holes, and then pour $A$ liters of water into the pipe. After that, the water will flow out from the non-blocked holes proportionally to their sizes $s_1, s_2, \ldots, s_n$. In other words, if the sum of sizes of non-blocked holes is $S$, and the $i$-th hole is not blocked, $\frac{s_i \cdot A}{S}$ liters of water will flow out of it.
What is the minimum number of holes Arkady should block to make at least $B$ liters of water flow out of the first hole?
Input Specification:
The first line contains three integers $n$, $A$, $B$ ($1 \le n \le 100\,000$, $1 \le B \le A \le 10^4$) — the number of holes, the volume of water Arkady will pour into the system, and the volume he wants to get out of the first hole.
The second line contains $n$ integers $s_1, s_2, \ldots, s_n$ ($1 \le s_i \le 10^4$) — the sizes of the holes.
Output Specification:
Print a single integer — the number of holes Arkady should block.
Demo Input:
['4 10 3\n2 2 2 2\n', '4 80 20\n3 2 1 4\n', '5 10 10\n1000 1 1 1 1\n']
Demo Output:
['1\n', '0\n', '4\n']
Note:
In the first example Arkady should block at least one hole. After that, $\frac{10 \cdot 2}{6} \approx 3.333$ liters of water will flow out of the first hole, and that suits Arkady.
In the second example even without blocking any hole, $\frac{80 \cdot 3}{10} = 24$ liters will flow out of the first hole, that is not less than $20$.
In the third example Arkady has to block all holes except the first to make all water flow out of the first hole. | ```python
# cook your dish here
n,a,b=map(int,input().split())
s=[int(i) for i in input().split(" ")]
i=1
count=0
sum1=sum(s)
while(i!=n):
flow=(s[0]*a)/sum1
if(flow>=b):
break
else:
sum1=sum1-s[n-i]
count+=1
i+=1
print(count)
``` | 0 |
|
339 | A | Helpful Maths | PROGRAMMING | 800 | [
"greedy",
"implementation",
"sortings",
"strings"
] | null | null | Xenia the beginner mathematician is a third year student at elementary school. She is now learning the addition operation.
The teacher has written down the sum of multiple numbers. Pupils should calculate the sum. To make the calculation easier, the sum only contains numbers 1, 2 and 3. Still, that isn't enough for Xenia. She is only beginning to count, so she can calculate a sum only if the summands follow in non-decreasing order. For example, she can't calculate sum 1+3+2+1 but she can calculate sums 1+1+2 and 3+3.
You've got the sum that was written on the board. Rearrange the summans and print the sum in such a way that Xenia can calculate the sum. | The first line contains a non-empty string *s* — the sum Xenia needs to count. String *s* contains no spaces. It only contains digits and characters "+". Besides, string *s* is a correct sum of numbers 1, 2 and 3. String *s* is at most 100 characters long. | Print the new sum that Xenia can count. | [
"3+2+1\n",
"1+1+3+1+3\n",
"2\n"
] | [
"1+2+3\n",
"1+1+1+3+3\n",
"2\n"
] | none | 500 | [
{
"input": "3+2+1",
"output": "1+2+3"
},
{
"input": "1+1+3+1+3",
"output": "1+1+1+3+3"
},
{
"input": "2",
"output": "2"
},
{
"input": "2+2+1+1+3",
"output": "1+1+2+2+3"
},
{
"input": "2+1+2+2+2+3+1+3+1+2",
"output": "1+1+1+2+2+2+2+2+3+3"
},
{
"input": "1+2+1+2+2+2+2+1+3+3",
"output": "1+1+1+2+2+2+2+2+3+3"
},
{
"input": "2+3+3+1+2+2+2+1+1+2+1+3+2+2+3+3+2+2+3+3+3+1+1+1+3+3+3+2+1+3+2+3+2+1+1+3+3+3+1+2+2+1+2+2+1+2+1+3+1+1",
"output": "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+2+2+3+3+3+3+3+3+3+3+3+3+3+3+3+3+3+3+3"
},
{
"input": "1",
"output": "1"
},
{
"input": "2+1+2+2+1+3+2+3+1+1+2+1+2+2+3+1+1+3+3+3+2+2+3+2+2+2+1+2+1+2+3+2+2+2+1+3+1+3+3+3+1+2+1+2+2+2+2+3+1+1",
"output": "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+2+2+2+2+2+2+2+3+3+3+3+3+3+3+3+3+3+3+3+3"
},
{
"input": "2+2+1+1+1+3+1+1+3+3+2+3+1+3+1+1+3+1+1+2+2+2+2+1+2+1+2+1+1+1+3+1+3+2+3+2+3+3+1+1+1+2+3+2+1+3+1+3+2+2",
"output": "1+1+1+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+3+3+3+3+3+3+3+3+3+3+3+3+3+3"
},
{
"input": "3+2+3+3+2+2+1+2+1+2+3+1+2+3+2+3+2+1+2+2+1+1+2+2+3+2+1+3+1+1+3+2+2+2+2+3+3+2+2+3+3+1+1+2+3+3+2+3+3+3",
"output": "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+2+2+2+2+2+2+3+3+3+3+3+3+3+3+3+3+3+3+3+3+3+3+3+3"
},
{
"input": "3",
"output": "3"
},
{
"input": "1+1",
"output": "1+1"
},
{
"input": "1+2",
"output": "1+2"
},
{
"input": "1+3",
"output": "1+3"
},
{
"input": "2+1",
"output": "1+2"
},
{
"input": "2+2",
"output": "2+2"
},
{
"input": "2+3",
"output": "2+3"
},
{
"input": "3+1",
"output": "1+3"
},
{
"input": "3+2",
"output": "2+3"
},
{
"input": "3+3",
"output": "3+3"
}
] | 1,697,956,385 | 2,147,483,647 | Python 3 | OK | TESTS | 21 | 92 | 0 | l = list(map(int, input().split('+')))
l.sort();
ans = ''
for i in range(len(l)):
if len(l) - 1 == i:
ans += str(l[i])
else:
ans += str(l[i]) + '+'
print(ans) | Title: Helpful Maths
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Xenia the beginner mathematician is a third year student at elementary school. She is now learning the addition operation.
The teacher has written down the sum of multiple numbers. Pupils should calculate the sum. To make the calculation easier, the sum only contains numbers 1, 2 and 3. Still, that isn't enough for Xenia. She is only beginning to count, so she can calculate a sum only if the summands follow in non-decreasing order. For example, she can't calculate sum 1+3+2+1 but she can calculate sums 1+1+2 and 3+3.
You've got the sum that was written on the board. Rearrange the summans and print the sum in such a way that Xenia can calculate the sum.
Input Specification:
The first line contains a non-empty string *s* — the sum Xenia needs to count. String *s* contains no spaces. It only contains digits and characters "+". Besides, string *s* is a correct sum of numbers 1, 2 and 3. String *s* is at most 100 characters long.
Output Specification:
Print the new sum that Xenia can count.
Demo Input:
['3+2+1\n', '1+1+3+1+3\n', '2\n']
Demo Output:
['1+2+3\n', '1+1+1+3+3\n', '2\n']
Note:
none | ```python
l = list(map(int, input().split('+')))
l.sort();
ans = ''
for i in range(len(l)):
if len(l) - 1 == i:
ans += str(l[i])
else:
ans += str(l[i]) + '+'
print(ans)
``` | 3 |
|
586 | A | Alena's Schedule | PROGRAMMING | 900 | [
"implementation"
] | null | null | Alena has successfully passed the entrance exams to the university and is now looking forward to start studying.
One two-hour lesson at the Russian university is traditionally called a pair, it lasts for two academic hours (an academic hour is equal to 45 minutes).
The University works in such a way that every day it holds exactly *n* lessons. Depending on the schedule of a particular group of students, on a given day, some pairs may actually contain classes, but some may be empty (such pairs are called breaks).
The official website of the university has already published the schedule for tomorrow for Alena's group. Thus, for each of the *n* pairs she knows if there will be a class at that time or not.
Alena's House is far from the university, so if there are breaks, she doesn't always go home. Alena has time to go home only if the break consists of at least two free pairs in a row, otherwise she waits for the next pair at the university.
Of course, Alena does not want to be sleepy during pairs, so she will sleep as long as possible, and will only come to the first pair that is presented in her schedule. Similarly, if there are no more pairs, then Alena immediately goes home.
Alena appreciates the time spent at home, so she always goes home when it is possible, and returns to the university only at the beginning of the next pair. Help Alena determine for how many pairs she will stay at the university. Note that during some pairs Alena may be at the university waiting for the upcoming pair. | The first line of the input contains a positive integer *n* (1<=≤<=*n*<=≤<=100) — the number of lessons at the university.
The second line contains *n* numbers *a**i* (0<=≤<=*a**i*<=≤<=1). Number *a**i* equals 0, if Alena doesn't have the *i*-th pairs, otherwise it is equal to 1. Numbers *a*1,<=*a*2,<=...,<=*a**n* are separated by spaces. | Print a single number — the number of pairs during which Alena stays at the university. | [
"5\n0 1 0 1 1\n",
"7\n1 0 1 0 0 1 0\n",
"1\n0\n"
] | [
"4\n",
"4\n",
"0\n"
] | In the first sample Alena stays at the university from the second to the fifth pair, inclusive, during the third pair she will be it the university waiting for the next pair.
In the last sample Alena doesn't have a single pair, so she spends all the time at home. | 500 | [
{
"input": "5\n0 1 0 1 1",
"output": "4"
},
{
"input": "7\n1 0 1 0 0 1 0",
"output": "4"
},
{
"input": "1\n0",
"output": "0"
},
{
"input": "1\n1",
"output": "1"
},
{
"input": "2\n0 0",
"output": "0"
},
{
"input": "2\n0 1",
"output": "1"
},
{
"input": "2\n1 0",
"output": "1"
},
{
"input": "2\n1 1",
"output": "2"
},
{
"input": "10\n0 0 0 0 0 0 0 0 0 0",
"output": "0"
},
{
"input": "9\n1 1 1 1 1 1 1 1 1",
"output": "9"
},
{
"input": "11\n0 0 0 0 0 0 0 0 0 0 1",
"output": "1"
},
{
"input": "12\n1 0 0 0 0 0 0 0 0 0 0 0",
"output": "1"
},
{
"input": "20\n1 1 0 1 1 1 1 1 1 1 1 0 1 1 1 0 0 1 0 0",
"output": "16"
},
{
"input": "41\n1 1 0 1 0 1 0 0 1 0 1 1 1 0 0 0 1 1 1 0 1 0 1 1 0 1 0 1 0 0 0 0 0 0 1 0 0 1 0 1 1",
"output": "28"
},
{
"input": "63\n1 1 0 1 1 0 0 0 1 1 0 0 1 1 1 1 0 1 1 0 1 0 1 1 1 1 1 0 0 0 0 0 0 1 0 0 1 0 0 1 0 1 1 0 0 1 1 0 0 1 1 1 1 0 0 1 1 0 0 1 0 1 0",
"output": "39"
},
{
"input": "80\n0 1 1 1 0 1 1 1 1 1 0 0 1 0 1 1 0 1 1 1 0 1 1 1 1 0 1 0 1 0 0 0 1 1 0 1 1 0 0 0 0 1 1 1 0 0 0 1 0 0 1 1 1 0 0 0 0 0 0 1 0 1 0 0 1 0 1 1 1 1 1 0 0 0 1 1 0 0 1 1",
"output": "52"
},
{
"input": "99\n1 1 0 0 0 1 0 0 1 1 1 1 0 0 0 1 0 1 1 0 1 1 1 1 0 0 0 0 1 1 1 1 0 1 0 1 0 1 1 1 0 0 1 1 1 0 0 0 1 1 1 0 1 1 1 0 1 0 0 1 1 0 1 0 0 1 1 1 1 0 0 1 1 0 0 1 0 1 1 1 0 1 1 0 1 0 0 1 0 1 0 1 0 1 1 0 1 0 1",
"output": "72"
},
{
"input": "100\n0 1 1 0 1 1 0 0 1 1 0 1 1 1 1 1 0 0 1 1 1 0 0 0 0 1 1 0 0 1 0 0 1 0 0 0 0 1 1 1 1 1 1 0 0 1 1 0 0 0 0 1 0 1 1 1 0 1 1 0 1 0 0 0 0 0 1 0 1 1 0 0 1 1 0 1 1 0 0 1 1 1 0 1 1 1 1 1 1 0 0 1 1 1 1 0 1 1 1 0",
"output": "65"
},
{
"input": "11\n0 1 1 0 0 0 0 0 0 0 0",
"output": "2"
},
{
"input": "11\n0 1 0 1 0 0 1 1 0 1 1",
"output": "8"
},
{
"input": "11\n1 0 1 0 1 1 0 1 1 1 0",
"output": "10"
},
{
"input": "11\n1 0 0 0 0 0 1 0 1 1 1",
"output": "6"
},
{
"input": "22\n0 1 1 0 0 0 0 0 1 0 0 0 0 1 1 0 0 1 0 0 1 0",
"output": "7"
},
{
"input": "22\n0 1 0 1 0 1 1 1 1 0 0 1 1 1 0 1 1 1 0 0 0 1",
"output": "16"
},
{
"input": "22\n1 0 1 0 1 0 0 0 0 0 0 1 0 0 0 0 1 1 0 1 1 0",
"output": "11"
},
{
"input": "22\n1 0 1 0 0 0 1 0 0 1 1 0 1 0 1 1 0 0 0 1 0 1",
"output": "14"
},
{
"input": "33\n0 1 1 0 1 1 0 1 0 1 1 0 1 1 1 1 0 1 1 1 0 0 1 1 0 0 1 1 0 1 1 0 0",
"output": "26"
},
{
"input": "33\n0 1 0 1 0 1 1 0 0 0 1 1 1 0 1 0 1 1 0 1 0 1 0 0 1 1 1 0 1 1 1 0 1",
"output": "27"
},
{
"input": "33\n1 0 1 0 1 0 0 0 1 0 1 1 1 0 0 0 0 1 1 0 1 0 1 1 0 1 0 1 1 1 1 1 0",
"output": "25"
},
{
"input": "33\n1 0 1 0 1 1 1 1 1 0 1 0 1 1 0 0 1 0 1 0 0 0 1 0 1 0 1 0 0 0 0 1 1",
"output": "24"
},
{
"input": "44\n0 1 1 0 1 0 0 0 0 1 1 0 0 0 0 0 1 1 1 0 0 0 0 0 1 0 0 1 1 0 0 0 0 1 1 1 0 0 1 0 1 1 0 0",
"output": "19"
},
{
"input": "44\n0 1 1 1 1 0 1 0 0 1 0 1 0 0 1 1 0 1 1 0 0 1 0 1 0 1 1 0 1 0 1 0 1 0 1 0 0 0 0 0 1 0 1 1",
"output": "32"
},
{
"input": "44\n1 0 1 0 0 1 0 1 0 1 0 1 0 1 1 1 1 1 0 1 0 0 0 0 0 0 0 0 0 0 1 1 0 0 0 0 1 0 0 1 0 0 1 0",
"output": "23"
},
{
"input": "44\n1 0 1 0 1 1 1 0 0 0 0 0 0 1 0 0 0 1 1 1 0 0 0 1 0 1 0 1 1 0 1 1 0 1 0 1 1 0 1 0 1 1 1 1",
"output": "32"
},
{
"input": "55\n0 1 1 0 1 0 0 0 1 0 0 0 1 0 1 0 0 1 0 0 0 0 1 1 1 0 0 1 1 0 0 0 0 0 1 0 1 1 1 0 0 0 0 0 1 0 0 0 0 1 1 0 0 1 0",
"output": "23"
},
{
"input": "55\n0 1 1 0 1 0 1 1 1 1 0 1 1 0 0 1 1 1 0 0 0 1 1 0 0 1 0 1 0 1 0 0 1 1 1 1 1 0 0 0 1 1 1 1 1 1 1 1 0 1 1 0 0 0 1",
"output": "39"
},
{
"input": "55\n1 0 1 0 0 1 0 0 1 1 0 1 0 1 0 0 1 1 0 0 0 0 1 1 1 0 0 0 1 1 1 1 0 1 0 1 0 0 0 1 0 1 1 0 0 0 1 0 1 0 0 1 1 0 0",
"output": "32"
},
{
"input": "55\n1 0 1 0 1 0 1 0 1 1 0 0 1 1 1 1 0 1 0 0 0 1 1 0 0 1 0 1 0 1 1 1 0 0 0 0 0 0 1 0 0 0 1 1 1 0 0 0 1 0 1 0 1 1 1",
"output": "36"
},
{
"input": "66\n0 1 1 0 0 1 0 1 0 1 0 1 1 0 1 1 0 0 1 1 0 1 0 0 0 0 0 0 0 1 0 0 0 1 1 1 1 1 1 0 0 1 1 1 0 1 0 1 1 0 1 0 0 1 1 0 1 1 1 0 0 0 0 0 1 0",
"output": "41"
},
{
"input": "66\n0 1 1 0 1 1 1 0 0 0 1 1 0 1 1 0 0 1 1 1 1 1 0 1 1 1 0 1 1 1 0 0 1 0 0 1 1 1 0 0 1 0 1 1 1 0 0 0 1 0 0 0 0 0 1 0 1 0 0 1 0 0 1 1 0 1",
"output": "42"
},
{
"input": "66\n1 0 1 0 0 0 1 0 1 0 1 0 1 1 0 1 0 1 1 0 0 0 1 1 1 0 1 0 0 1 0 1 0 0 0 0 1 1 0 1 1 0 1 0 0 0 1 1 0 1 0 1 1 0 0 0 1 1 0 1 1 0 1 1 0 0",
"output": "46"
},
{
"input": "66\n1 0 1 0 0 0 1 1 1 1 1 0 1 0 0 0 1 1 1 0 1 1 0 1 0 1 0 0 1 0 0 1 0 1 0 1 0 0 1 0 0 1 0 1 1 1 1 1 0 1 1 1 1 1 1 0 0 0 1 0 1 1 0 0 0 1",
"output": "46"
},
{
"input": "77\n0 0 1 0 0 1 0 0 1 1 1 1 0 1 0 0 1 0 0 0 0 1 0 0 0 0 1 0 1 0 1 0 0 0 1 0 0 1 1 0 1 0 1 1 0 0 0 1 0 0 1 1 1 0 1 0 1 1 0 1 0 0 0 1 0 1 1 0 1 1 1 0 1 1 0 1 0",
"output": "47"
},
{
"input": "77\n0 0 1 0 0 0 1 0 1 1 1 1 0 1 1 1 0 1 1 0 1 1 1 0 1 1 0 1 0 0 0 0 1 1 0 0 0 1 1 0 0 1 1 0 1 0 0 1 0 0 0 1 0 0 1 0 0 0 1 0 0 0 1 0 0 1 0 1 1 0 1 0 0 0 0 1 1",
"output": "44"
},
{
"input": "77\n1 0 0 0 1 0 1 1 0 0 1 0 0 0 1 1 1 1 0 1 0 0 0 0 0 0 1 1 0 0 0 1 0 1 0 1 1 1 0 1 1 1 0 0 0 1 1 0 1 1 1 0 1 1 0 0 1 0 0 1 1 1 1 0 1 0 0 0 1 0 1 1 0 0 0 0 0",
"output": "45"
},
{
"input": "77\n1 0 1 0 0 1 1 0 0 0 0 0 0 0 0 0 0 1 0 1 1 1 0 0 1 1 1 0 1 1 0 1 0 0 0 0 1 1 1 0 1 0 0 1 1 0 1 0 1 1 1 1 1 1 1 0 0 1 1 0 0 1 0 1 1 1 1 1 1 1 1 0 0 1 0 1 1",
"output": "51"
},
{
"input": "88\n0 0 1 0 0 0 0 0 0 0 0 1 1 1 1 0 0 0 0 1 0 1 1 1 0 0 1 1 0 0 1 0 1 1 1 0 1 1 1 0 1 1 1 1 0 0 0 0 1 0 0 0 1 0 1 1 0 1 0 1 0 0 0 0 1 0 1 0 0 0 0 0 0 0 0 0 0 1 1 0 0 1 0 0 1 1 1 0",
"output": "44"
},
{
"input": "88\n0 0 1 0 0 0 1 1 0 1 0 1 1 1 0 1 1 1 0 1 1 1 1 1 0 1 1 0 1 1 1 0 1 0 0 1 0 1 1 0 0 0 0 0 1 1 0 0 1 0 1 1 1 0 1 1 0 1 1 0 0 0 1 1 1 1 1 1 1 0 0 1 0 1 0 0 0 1 0 1 0 0 0 0 0 0 0 1",
"output": "59"
},
{
"input": "88\n1 0 0 0 1 1 1 0 1 1 0 0 0 0 0 0 1 0 1 0 0 0 1 1 0 0 1 1 1 1 1 1 0 0 0 0 0 1 0 1 0 0 0 0 0 1 1 1 0 1 1 0 0 1 1 1 0 0 1 0 0 1 1 1 1 0 0 1 0 1 1 1 0 1 0 1 1 1 1 0 1 0 1 1 1 0 0 0",
"output": "53"
},
{
"input": "88\n1 1 1 0 0 1 1 0 1 0 0 0 1 0 1 1 1 1 1 0 1 1 1 1 1 1 1 0 0 1 0 1 1 1 0 0 0 1 1 0 1 1 0 1 0 0 1 0 0 1 0 0 1 0 1 1 0 1 0 1 0 1 0 0 1 1 1 0 0 0 1 0 0 1 0 0 1 1 0 1 1 1 1 0 1 1 0 1",
"output": "63"
},
{
"input": "99\n0 0 0 0 1 0 0 1 0 0 0 1 1 1 1 1 1 0 1 1 0 1 0 0 1 0 1 1 1 1 1 0 1 0 1 1 1 0 0 0 1 0 0 1 0 1 0 1 0 0 0 0 1 0 1 1 0 0 1 1 1 0 0 1 1 0 0 0 0 0 0 1 0 0 0 1 1 0 0 0 1 1 1 0 1 1 0 1 0 1 0 0 0 1 1 0 0 0 0",
"output": "56"
},
{
"input": "99\n0 0 1 0 0 1 1 0 0 0 1 1 0 0 1 0 0 0 1 1 1 1 0 0 0 1 1 0 0 0 1 0 1 1 0 0 1 1 1 0 1 1 0 0 0 0 0 1 0 0 1 0 1 1 0 1 0 1 0 0 1 0 1 1 1 1 1 1 0 1 0 0 1 1 0 0 1 0 1 0 1 0 1 1 1 0 0 1 1 1 0 0 0 0 0 0 1 1 1",
"output": "58"
},
{
"input": "99\n1 1 0 0 1 1 1 0 0 0 1 0 1 0 1 1 0 0 0 0 0 0 0 0 1 0 1 1 0 0 1 1 0 1 0 1 0 1 0 1 0 1 0 1 0 0 1 0 1 1 1 1 0 1 1 1 0 0 1 0 0 1 1 0 0 0 0 1 0 0 1 0 1 1 0 1 1 0 0 1 0 0 1 0 1 0 1 1 0 1 0 1 1 1 1 0 0 1 0",
"output": "65"
},
{
"input": "99\n1 1 1 0 1 0 1 1 0 1 1 0 0 1 0 0 1 1 1 0 1 1 0 0 0 1 1 1 1 0 1 1 1 0 1 1 0 1 1 0 1 0 1 0 0 1 1 1 1 1 0 1 1 0 1 1 0 0 0 1 0 1 0 1 0 1 0 0 0 1 1 1 1 0 0 1 1 0 1 0 0 0 1 0 1 1 1 0 0 1 1 1 1 1 0 1 1 1 1",
"output": "77"
},
{
"input": "90\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",
"output": "0"
},
{
"input": "90\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",
"output": "90"
},
{
"input": "95\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",
"output": "0"
},
{
"input": "95\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",
"output": "95"
},
{
"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": "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"
}
] | 1,598,241,588 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 16 | 140 | 20,172,800 | n = int(input())
ai = input().replace(" ","")
num = ai.count("1")
print(num + ai.replace("101","1011").count("101"))
| Title: Alena's Schedule
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Alena has successfully passed the entrance exams to the university and is now looking forward to start studying.
One two-hour lesson at the Russian university is traditionally called a pair, it lasts for two academic hours (an academic hour is equal to 45 minutes).
The University works in such a way that every day it holds exactly *n* lessons. Depending on the schedule of a particular group of students, on a given day, some pairs may actually contain classes, but some may be empty (such pairs are called breaks).
The official website of the university has already published the schedule for tomorrow for Alena's group. Thus, for each of the *n* pairs she knows if there will be a class at that time or not.
Alena's House is far from the university, so if there are breaks, she doesn't always go home. Alena has time to go home only if the break consists of at least two free pairs in a row, otherwise she waits for the next pair at the university.
Of course, Alena does not want to be sleepy during pairs, so she will sleep as long as possible, and will only come to the first pair that is presented in her schedule. Similarly, if there are no more pairs, then Alena immediately goes home.
Alena appreciates the time spent at home, so she always goes home when it is possible, and returns to the university only at the beginning of the next pair. Help Alena determine for how many pairs she will stay at the university. Note that during some pairs Alena may be at the university waiting for the upcoming pair.
Input Specification:
The first line of the input contains a positive integer *n* (1<=≤<=*n*<=≤<=100) — the number of lessons at the university.
The second line contains *n* numbers *a**i* (0<=≤<=*a**i*<=≤<=1). Number *a**i* equals 0, if Alena doesn't have the *i*-th pairs, otherwise it is equal to 1. Numbers *a*1,<=*a*2,<=...,<=*a**n* are separated by spaces.
Output Specification:
Print a single number — the number of pairs during which Alena stays at the university.
Demo Input:
['5\n0 1 0 1 1\n', '7\n1 0 1 0 0 1 0\n', '1\n0\n']
Demo Output:
['4\n', '4\n', '0\n']
Note:
In the first sample Alena stays at the university from the second to the fifth pair, inclusive, during the third pair she will be it the university waiting for the next pair.
In the last sample Alena doesn't have a single pair, so she spends all the time at home. | ```python
n = int(input())
ai = input().replace(" ","")
num = ai.count("1")
print(num + ai.replace("101","1011").count("101"))
``` | 0 |
|
3 | D | Least Cost Bracket Sequence | PROGRAMMING | 2,600 | [
"greedy"
] | D. Least Cost Bracket Sequence | 1 | 64 | This is yet another problem on regular bracket sequences.
A bracket sequence is called regular, if by inserting "+" and "1" into it we get a correct mathematical expression. For example, sequences "(())()", "()" and "(()(()))" are regular, while ")(", "(()" and "(()))(" are not. You have a pattern of a bracket sequence that consists of characters "(", ")" and "?". You have to replace each character "?" with a bracket so, that you get a regular bracket sequence.
For each character "?" the cost of its replacement with "(" and ")" is given. Among all the possible variants your should choose the cheapest. | The first line contains a non-empty pattern of even length, consisting of characters "(", ")" and "?". Its length doesn't exceed 5·104. Then there follow *m* lines, where *m* is the number of characters "?" in the pattern. Each line contains two integer numbers *a**i* and *b**i* (1<=≤<=*a**i*,<=<=*b**i*<=≤<=106), where *a**i* is the cost of replacing the *i*-th character "?" with an opening bracket, and *b**i* — with a closing one. | Print the cost of the optimal regular bracket sequence in the first line, and the required sequence in the second.
Print -1, if there is no answer. If the answer is not unique, print any of them. | [
"(??)\n1 2\n2 8\n"
] | [
"4\n()()\n"
] | none | 0 | [
{
"input": "(??)\n1 2\n2 8",
"output": "4\n()()"
},
{
"input": "??\n1 1\n1 1",
"output": "2\n()"
},
{
"input": "(???\n1 1\n1 1\n1 1",
"output": "3\n(())"
},
{
"input": "(??)\n2 1\n1 1",
"output": "2\n()()"
},
{
"input": "(???)?\n3 3\n3 1\n3 3\n2 3",
"output": "10\n(()())"
},
{
"input": "((????\n3 2\n3 2\n1 1\n2 3",
"output": "8\n(())()"
},
{
"input": "???())\n2 4\n3 3\n4 1",
"output": "6\n(()())"
},
{
"input": "((????\n3 5\n4 1\n2 2\n1 5",
"output": "11\n((()))"
},
{
"input": "?(?)(???\n2 3\n2 2\n3 2\n3 1\n3 1",
"output": "8\n((()()))"
},
{
"input": "(??????)\n1 1\n3 3\n3 3\n3 2\n1 3\n3 3",
"output": "13\n((())())"
},
{
"input": "?????)??\n2 3\n2 1\n1 3\n5 1\n3 3\n1 3\n3 2",
"output": "11\n()()()()"
},
{
"input": "?)???(??\n1 4\n3 4\n2 4\n2 5\n3 3\n3 1",
"output": "14\n()()(())"
},
{
"input": "???(??))\n2 1\n2 1\n2 1\n1 2\n2 1",
"output": "7\n(()(()))"
},
{
"input": "??(()??)\n3 2\n3 3\n1 3\n2 2",
"output": "9\n()(()())"
},
{
"input": "????(???\n2 2\n1 3\n1 3\n3 3\n4 1\n4 4\n2 4",
"output": "16\n((()()))"
},
{
"input": "?(??????\n1 5\n2 4\n4 4\n4 3\n4 5\n5 4\n2 3",
"output": "21\n((())())"
},
{
"input": "???????)\n6 3\n5 3\n4 1\n1 4\n4 1\n2 6\n4 3",
"output": "19\n(()()())"
},
{
"input": "??????)?\n2 2\n4 2\n3 5\n3 2\n7 4\n6 2\n1 6",
"output": "24\n(((())))"
},
{
"input": "?((?)?)?\n1 2\n4 2\n1 3\n1 2",
"output": "6\n((())())"
},
{
"input": "??(????)\n3 2\n1 4\n4 4\n2 3\n2 3\n2 4",
"output": "16\n((()))()"
},
{
"input": "???(?)??(??)?)(?(?????????(?()????)(????(?)????)???)??))(?(?????????))???(??)?????))???????(????????\n9 10\n6 3\n8 2\n9 10\n9 3\n6 2\n8 5\n6 7\n2 6\n7 8\n6 10\n1 7\n1 7\n10 7\n10 7\n8 4\n5 9\n9 3\n3 10\n1 10\n8 2\n8 8\n4 8\n6 6\n4 10\n4 5\n5 2\n5 6\n7 7\n7 3\n10 1\n1 4\n5 10\n3 2\n2 8\n8 9\n6 5\n8 6\n3 4\n8 6\n8 5\n7 7\n10 9\n5 5\n2 1\n2 7\n2 3\n5 10\n9 7\n1 9\n10 9\n4 5\n8 2\n2 5\n6 7\n3 6\n4 2\n2 5\n3 9\n4 4\n6 3\n4 9\n3 1\n5 7\n8 7\n6 9\n5 3\n6 4\n8 3\n5 8\n8 4\n7 6\n1 4",
"output": "309\n(()(()))()()()(((((()))()(((())((()((()((()))(())(()))))((())))))((()))()(())((()())())()()(()))()))"
},
{
"input": "(?(((???))(??)?)?))))(?)????(()()???(?)????(??(??????)()(????(?)))))??(???(??)?(??)????????(????(?()\n39 78\n1 83\n2 35\n28 89\n53 53\n96 67\n16 46\n43 28\n25 73\n8 97\n57 41\n15 25\n47 49\n23 18\n97 77\n38 33\n68 80\n38 98\n62 8\n61 79\n84 50\n71 48\n12 16\n97 95\n16 70\n72 58\n55 85\n88 42\n49 56\n39 63\n51 100\n41 15\n97 17\n71 63\n21 44\n1 41\n22 14\n42 65\n88 33\n57 95\n57 28\n59 8\n56 42\n18 99\n43 6\n75 93\n34 23\n62 57\n62 71\n67 92\n91 60\n49 58\n97 14\n75 68\n20 9\n55 98\n12 3",
"output": "2140\n(((((((())(())())))))(()()(((()())))(()()()()(((()()()()((())())))))((()()(()))()())())(()(())))()()"
},
{
"input": "(())()",
"output": "0\n(())()"
},
{
"input": "?(?(??\n1 1\n2 2\n1 1\n1 1",
"output": "5\n(()())"
},
{
"input": "(????(\n1 1\n2 1\n2 1\n3 3",
"output": "-1"
},
{
"input": "(?(???\n2 3\n1 1\n3 3\n1 4",
"output": "10\n((()))"
},
{
"input": "))))))",
"output": "-1"
},
{
"input": ")?)??)\n4 4\n3 5\n3 6",
"output": "-1"
},
{
"input": "((((((",
"output": "-1"
},
{
"input": "((((((",
"output": "-1"
},
{
"input": "()()()",
"output": "0\n()()()"
},
{
"input": "????((\n7 6\n1 10\n9 8\n4 4",
"output": "-1"
},
{
"input": "))))))",
"output": "-1"
},
{
"input": "))))))",
"output": "-1"
},
{
"input": "((((((",
"output": "-1"
},
{
"input": "((()))",
"output": "0\n((()))"
},
{
"input": "?))?))\n9 13\n8 11",
"output": "-1"
},
{
"input": "))))))",
"output": "-1"
},
{
"input": "?(?)?)\n6 14\n8 6\n4 3",
"output": "16\n(())()"
},
{
"input": "?(?(((\n8 7\n17 15",
"output": "-1"
},
{
"input": "))))))",
"output": "-1"
}
] | 1,588,345,524 | 2,147,483,647 | PyPy 3 | TIME_LIMIT_EXCEEDED | TESTS | 30 | 1,000 | 8,806,400 |
s = list(input())
st = []
count=0
ans=0
for i, character in enumerate(s):
# print('------')
# print('character', character)
if character=='(':
count+=1
# print('count+')
elif character==')':
count-=1
# print('count-')
else:
# print('closing')
a, b = (int(x) for x in input().split(' '))
ans+=b;
s[i]=')'
count-=1
st = sorted([(a-b,i)] + st)
# print('stack', st)
# print('count', count)
# print('---')
while(count<0):
# print('opening')
if len(st)==0:
# print("-1")
exit()
ans+=st[0][0]
# print('added', st[0][0])
s[st[0][1]]='('
# print('s[' + str(st[0][1]) + ']=(')
# print(st)
st = st[1:]
# print(st)
count+=2
# print('count last', count)
if count>0:
print("-1")
else:
print(ans)
print(''.join(s))
| Title: Least Cost Bracket Sequence
Time Limit: 1 seconds
Memory Limit: 64 megabytes
Problem Description:
This is yet another problem on regular bracket sequences.
A bracket sequence is called regular, if by inserting "+" and "1" into it we get a correct mathematical expression. For example, sequences "(())()", "()" and "(()(()))" are regular, while ")(", "(()" and "(()))(" are not. You have a pattern of a bracket sequence that consists of characters "(", ")" and "?". You have to replace each character "?" with a bracket so, that you get a regular bracket sequence.
For each character "?" the cost of its replacement with "(" and ")" is given. Among all the possible variants your should choose the cheapest.
Input Specification:
The first line contains a non-empty pattern of even length, consisting of characters "(", ")" and "?". Its length doesn't exceed 5·104. Then there follow *m* lines, where *m* is the number of characters "?" in the pattern. Each line contains two integer numbers *a**i* and *b**i* (1<=≤<=*a**i*,<=<=*b**i*<=≤<=106), where *a**i* is the cost of replacing the *i*-th character "?" with an opening bracket, and *b**i* — with a closing one.
Output Specification:
Print the cost of the optimal regular bracket sequence in the first line, and the required sequence in the second.
Print -1, if there is no answer. If the answer is not unique, print any of them.
Demo Input:
['(??)\n1 2\n2 8\n']
Demo Output:
['4\n()()\n']
Note:
none | ```python
s = list(input())
st = []
count=0
ans=0
for i, character in enumerate(s):
# print('------')
# print('character', character)
if character=='(':
count+=1
# print('count+')
elif character==')':
count-=1
# print('count-')
else:
# print('closing')
a, b = (int(x) for x in input().split(' '))
ans+=b;
s[i]=')'
count-=1
st = sorted([(a-b,i)] + st)
# print('stack', st)
# print('count', count)
# print('---')
while(count<0):
# print('opening')
if len(st)==0:
# print("-1")
exit()
ans+=st[0][0]
# print('added', st[0][0])
s[st[0][1]]='('
# print('s[' + str(st[0][1]) + ']=(')
# print(st)
st = st[1:]
# print(st)
count+=2
# print('count last', count)
if count>0:
print("-1")
else:
print(ans)
print(''.join(s))
``` | 0 |
78 | B | Easter Eggs | PROGRAMMING | 1,200 | [
"constructive algorithms",
"implementation"
] | B. Easter Eggs | 2 | 256 | The Easter Rabbit laid *n* eggs in a circle and is about to paint them.
Each egg should be painted one color out of 7: red, orange, yellow, green, blue, indigo or violet. Also, the following conditions should be satisfied:
- Each of the seven colors should be used to paint at least one egg. - Any four eggs lying sequentially should be painted different colors.
Help the Easter Rabbit paint the eggs in the required manner. We know that it is always possible. | The only line contains an integer *n* — the amount of eggs (7<=≤<=*n*<=≤<=100). | Print one line consisting of *n* characters. The *i*-th character should describe the color of the *i*-th egg in the order they lie in the circle. The colors should be represented as follows: "R" stands for red, "O" stands for orange, "Y" stands for yellow, "G" stands for green, "B" stands for blue, "I" stands for indigo, "V" stands for violet.
If there are several answers, print any of them. | [
"8\n",
"13\n"
] | [
"ROYGRBIV\n",
"ROYGBIVGBIVYG\n"
] | The way the eggs will be painted in the first sample is shown on the picture: | 1,000 | [
{
"input": "8",
"output": "ROYGBIVG"
},
{
"input": "13",
"output": "ROYGBIVOYGBIV"
},
{
"input": "7",
"output": "ROYGBIV"
},
{
"input": "10",
"output": "ROYGBIVYGB"
},
{
"input": "14",
"output": "ROYGBIVROYGBIV"
},
{
"input": "50",
"output": "ROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVG"
},
{
"input": "9",
"output": "ROYGBIVGB"
},
{
"input": "11",
"output": "ROYGBIVYGBI"
},
{
"input": "12",
"output": "ROYGBIVOYGBI"
},
{
"input": "15",
"output": "ROYGBIVROYGBIVG"
},
{
"input": "16",
"output": "ROYGBIVROYGBIVGB"
},
{
"input": "17",
"output": "ROYGBIVROYGBIVYGB"
},
{
"input": "18",
"output": "ROYGBIVROYGBIVYGBI"
},
{
"input": "19",
"output": "ROYGBIVROYGBIVOYGBI"
},
{
"input": "20",
"output": "ROYGBIVROYGBIVOYGBIV"
},
{
"input": "21",
"output": "ROYGBIVROYGBIVROYGBIV"
},
{
"input": "22",
"output": "ROYGBIVROYGBIVROYGBIVG"
},
{
"input": "23",
"output": "ROYGBIVROYGBIVROYGBIVGB"
},
{
"input": "24",
"output": "ROYGBIVROYGBIVROYGBIVYGB"
},
{
"input": "25",
"output": "ROYGBIVROYGBIVROYGBIVYGBI"
},
{
"input": "28",
"output": "ROYGBIVROYGBIVROYGBIVROYGBIV"
},
{
"input": "29",
"output": "ROYGBIVROYGBIVROYGBIVROYGBIVG"
},
{
"input": "34",
"output": "ROYGBIVROYGBIVROYGBIVROYGBIVOYGBIV"
},
{
"input": "43",
"output": "ROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVG"
},
{
"input": "61",
"output": "ROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVOYGBI"
},
{
"input": "79",
"output": "ROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVGB"
},
{
"input": "81",
"output": "ROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVYGBI"
},
{
"input": "92",
"output": "ROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVG"
},
{
"input": "95",
"output": "ROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVYGBI"
},
{
"input": "96",
"output": "ROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVOYGBI"
},
{
"input": "97",
"output": "ROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVOYGBIV"
},
{
"input": "98",
"output": "ROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIV"
},
{
"input": "99",
"output": "ROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVG"
},
{
"input": "100",
"output": "ROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVGB"
}
] | 1,586,195,877 | 2,147,483,647 | Python 3 | OK | TESTS | 34 | 186 | 0 | n=int(input())
clrs='VIBGYOR'
#clrs=clrs[::-1]
i=0
co=0
while(co<=n):
if i==7:
if n-co>= 4:
i=0
else:
x=n-co
i=5-x-1
if co==n:
break
print(clrs[i],end="")
i+=1
co+=1
| Title: Easter Eggs
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
The Easter Rabbit laid *n* eggs in a circle and is about to paint them.
Each egg should be painted one color out of 7: red, orange, yellow, green, blue, indigo or violet. Also, the following conditions should be satisfied:
- Each of the seven colors should be used to paint at least one egg. - Any four eggs lying sequentially should be painted different colors.
Help the Easter Rabbit paint the eggs in the required manner. We know that it is always possible.
Input Specification:
The only line contains an integer *n* — the amount of eggs (7<=≤<=*n*<=≤<=100).
Output Specification:
Print one line consisting of *n* characters. The *i*-th character should describe the color of the *i*-th egg in the order they lie in the circle. The colors should be represented as follows: "R" stands for red, "O" stands for orange, "Y" stands for yellow, "G" stands for green, "B" stands for blue, "I" stands for indigo, "V" stands for violet.
If there are several answers, print any of them.
Demo Input:
['8\n', '13\n']
Demo Output:
['ROYGRBIV\n', 'ROYGBIVGBIVYG\n']
Note:
The way the eggs will be painted in the first sample is shown on the picture: | ```python
n=int(input())
clrs='VIBGYOR'
#clrs=clrs[::-1]
i=0
co=0
while(co<=n):
if i==7:
if n-co>= 4:
i=0
else:
x=n-co
i=5-x-1
if co==n:
break
print(clrs[i],end="")
i+=1
co+=1
``` | 3.9535 |
903 | A | Hungry Student Problem | PROGRAMMING | 900 | [
"greedy",
"implementation"
] | null | null | Ivan's classes at the university have just finished, and now he wants to go to the local CFK cafe and eat some fried chicken.
CFK sells chicken chunks in small and large portions. A small portion contains 3 chunks; a large one — 7 chunks. Ivan wants to eat exactly *x* chunks. Now he wonders whether he can buy exactly this amount of chicken.
Formally, Ivan wants to know if he can choose two non-negative integers *a* and *b* in such a way that *a* small portions and *b* large ones contain exactly *x* chunks.
Help Ivan to answer this question for several values of *x*! | The first line contains one integer *n* (1<=≤<=*n*<=≤<=100) — the number of testcases.
The *i*-th of the following *n* lines contains one integer *x**i* (1<=≤<=*x**i*<=≤<=100) — the number of chicken chunks Ivan wants to eat. | Print *n* lines, in *i*-th line output YES if Ivan can buy exactly *x**i* chunks. Otherwise, print NO. | [
"2\n6\n5\n"
] | [
"YES\nNO\n"
] | In the first example Ivan can buy two small portions.
In the second example Ivan cannot buy exactly 5 chunks, since one small portion is not enough, but two small portions or one large is too much. | 0 | [
{
"input": "2\n6\n5",
"output": "YES\nNO"
},
{
"input": "100\n1\n2\n3\n4\n5\n6\n7\n8\n9\n10\n11\n12\n13\n14\n15\n16\n17\n18\n19\n20\n21\n22\n23\n24\n25\n26\n27\n28\n29\n30\n31\n32\n33\n34\n35\n36\n37\n38\n39\n40\n41\n42\n43\n44\n45\n46\n47\n48\n49\n50\n51\n52\n53\n54\n55\n56\n57\n58\n59\n60\n61\n62\n63\n64\n65\n66\n67\n68\n69\n70\n71\n72\n73\n74\n75\n76\n77\n78\n79\n80\n81\n82\n83\n84\n85\n86\n87\n88\n89\n90\n91\n92\n93\n94\n95\n96\n97\n98\n99\n100",
"output": "NO\nNO\nYES\nNO\nNO\nYES\nYES\nNO\nYES\nYES\nNO\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES"
},
{
"input": "3\n6\n6\n6",
"output": "YES\nYES\nYES"
},
{
"input": "47\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1",
"output": "NO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO"
},
{
"input": "3\n1\n52\n76",
"output": "NO\nYES\nYES"
},
{
"input": "87\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100",
"output": "YES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES"
},
{
"input": "3\n3\n2\n1",
"output": "YES\nNO\nNO"
},
{
"input": "100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100",
"output": "YES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES"
}
] | 1,585,013,878 | 2,147,483,647 | Python 3 | OK | TESTS | 8 | 109 | 0 | i=input
for _ in[0]*int(i()):
x=int(i())
print('YNEOS'[all(x!=3*a+7*b for a in range(50) for b in range(50))::2]) | Title: Hungry Student Problem
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Ivan's classes at the university have just finished, and now he wants to go to the local CFK cafe and eat some fried chicken.
CFK sells chicken chunks in small and large portions. A small portion contains 3 chunks; a large one — 7 chunks. Ivan wants to eat exactly *x* chunks. Now he wonders whether he can buy exactly this amount of chicken.
Formally, Ivan wants to know if he can choose two non-negative integers *a* and *b* in such a way that *a* small portions and *b* large ones contain exactly *x* chunks.
Help Ivan to answer this question for several values of *x*!
Input Specification:
The first line contains one integer *n* (1<=≤<=*n*<=≤<=100) — the number of testcases.
The *i*-th of the following *n* lines contains one integer *x**i* (1<=≤<=*x**i*<=≤<=100) — the number of chicken chunks Ivan wants to eat.
Output Specification:
Print *n* lines, in *i*-th line output YES if Ivan can buy exactly *x**i* chunks. Otherwise, print NO.
Demo Input:
['2\n6\n5\n']
Demo Output:
['YES\nNO\n']
Note:
In the first example Ivan can buy two small portions.
In the second example Ivan cannot buy exactly 5 chunks, since one small portion is not enough, but two small portions or one large is too much. | ```python
i=input
for _ in[0]*int(i()):
x=int(i())
print('YNEOS'[all(x!=3*a+7*b for a in range(50) for b in range(50))::2])
``` | 3 |
|
0 | none | none | none | 0 | [
"none"
] | null | null | Bessie the cow and her best friend Elsie each received a sliding puzzle on Pi Day. Their puzzles consist of a 2<=×<=2 grid and three tiles labeled 'A', 'B', and 'C'. The three tiles sit on top of the grid, leaving one grid cell empty. To make a move, Bessie or Elsie can slide a tile adjacent to the empty cell into the empty cell as shown below:
In order to determine if they are truly Best Friends For Life (BFFLs), Bessie and Elsie would like to know if there exists a sequence of moves that takes their puzzles to the same configuration (moves can be performed in both puzzles). Two puzzles are considered to be in the same configuration if each tile is on top of the same grid cell in both puzzles. Since the tiles are labeled with letters, rotations and reflections are not allowed. | The first two lines of the input consist of a 2<=×<=2 grid describing the initial configuration of Bessie's puzzle. The next two lines contain a 2<=×<=2 grid describing the initial configuration of Elsie's puzzle. The positions of the tiles are labeled 'A', 'B', and 'C', while the empty cell is labeled 'X'. It's guaranteed that both puzzles contain exactly one tile with each letter and exactly one empty position. | Output "YES"(without quotes) if the puzzles can reach the same configuration (and Bessie and Elsie are truly BFFLs). Otherwise, print "NO" (without quotes). | [
"AB\nXC\nXB\nAC\n",
"AB\nXC\nAC\nBX\n"
] | [
"YES\n",
"NO\n"
] | The solution to the first sample is described by the image. All Bessie needs to do is slide her 'A' tile down.
In the second sample, the two puzzles can never be in the same configuration. Perhaps Bessie and Elsie are not meant to be friends after all... | 0 | [
{
"input": "AB\nXC\nXB\nAC",
"output": "YES"
},
{
"input": "AB\nXC\nAC\nBX",
"output": "NO"
},
{
"input": "XC\nBA\nCB\nAX",
"output": "NO"
},
{
"input": "AB\nXC\nAX\nCB",
"output": "YES"
},
{
"input": "CB\nAX\nXA\nBC",
"output": "YES"
},
{
"input": "BC\nXA\nBA\nXC",
"output": "NO"
},
{
"input": "CA\nXB\nBA\nCX",
"output": "NO"
},
{
"input": "CA\nXB\nAC\nBX",
"output": "NO"
},
{
"input": "CB\nAX\nCX\nAB",
"output": "YES"
},
{
"input": "AX\nCB\nBC\nXA",
"output": "YES"
},
{
"input": "CA\nXB\nBA\nXC",
"output": "NO"
},
{
"input": "CX\nAB\nAX\nCB",
"output": "NO"
},
{
"input": "AB\nXC\nAB\nCX",
"output": "YES"
},
{
"input": "XC\nBA\nXC\nAB",
"output": "NO"
},
{
"input": "BA\nXC\nAC\nXB",
"output": "YES"
},
{
"input": "AX\nBC\nAC\nBX",
"output": "YES"
},
{
"input": "XC\nBA\nCB\nXA",
"output": "NO"
},
{
"input": "CB\nAX\nXC\nBA",
"output": "NO"
},
{
"input": "AX\nCB\nBC\nAX",
"output": "YES"
},
{
"input": "AB\nXC\nBX\nAC",
"output": "YES"
},
{
"input": "XA\nCB\nBA\nCX",
"output": "NO"
},
{
"input": "CX\nBA\nBX\nAC",
"output": "YES"
},
{
"input": "AB\nXC\nXC\nAB",
"output": "NO"
},
{
"input": "BA\nCX\nAC\nBX",
"output": "YES"
},
{
"input": "XA\nCB\nAB\nXC",
"output": "YES"
},
{
"input": "XC\nBA\nAC\nBX",
"output": "NO"
},
{
"input": "CA\nBX\nBA\nXC",
"output": "NO"
},
{
"input": "AX\nBC\nCA\nXB",
"output": "NO"
},
{
"input": "BC\nAX\nXC\nBA",
"output": "YES"
},
{
"input": "XB\nAC\nBX\nAC",
"output": "YES"
},
{
"input": "CX\nBA\nAX\nBC",
"output": "NO"
},
{
"input": "XB\nCA\nXC\nBA",
"output": "NO"
},
{
"input": "BX\nCA\nXB\nCA",
"output": "YES"
},
{
"input": "XB\nAC\nXC\nAB",
"output": "NO"
},
{
"input": "CX\nBA\nCX\nBA",
"output": "YES"
},
{
"input": "XB\nAC\nCA\nBX",
"output": "YES"
},
{
"input": "BA\nXC\nBC\nAX",
"output": "NO"
},
{
"input": "AC\nXB\nCX\nBA",
"output": "NO"
},
{
"input": "XB\nCA\nCX\nBA",
"output": "NO"
},
{
"input": "AB\nCX\nXA\nBC",
"output": "NO"
},
{
"input": "CX\nAB\nXB\nAC",
"output": "NO"
},
{
"input": "BC\nAX\nAC\nBX",
"output": "NO"
},
{
"input": "XA\nBC\nCB\nAX",
"output": "YES"
},
{
"input": "XC\nAB\nCB\nAX",
"output": "YES"
},
{
"input": "CX\nBA\nCX\nAB",
"output": "NO"
},
{
"input": "CA\nBX\nXC\nBA",
"output": "YES"
},
{
"input": "CX\nBA\nBA\nXC",
"output": "NO"
},
{
"input": "CA\nBX\nCB\nXA",
"output": "NO"
},
{
"input": "CB\nAX\nBC\nAX",
"output": "NO"
},
{
"input": "CB\nAX\nBC\nXA",
"output": "NO"
},
{
"input": "AC\nXB\nCB\nXA",
"output": "YES"
},
{
"input": "AB\nCX\nXB\nAC",
"output": "YES"
},
{
"input": "CX\nBA\nXB\nAC",
"output": "YES"
},
{
"input": "BX\nAC\nAB\nXC",
"output": "YES"
},
{
"input": "CX\nAB\nXC\nBA",
"output": "NO"
},
{
"input": "XB\nAC\nCX\nAB",
"output": "NO"
},
{
"input": "CB\nAX\nXB\nAC",
"output": "NO"
},
{
"input": "CB\nAX\nCA\nXB",
"output": "NO"
},
{
"input": "XC\nBA\nBA\nXC",
"output": "NO"
},
{
"input": "AC\nBX\nCB\nAX",
"output": "YES"
},
{
"input": "CA\nBX\nAC\nXB",
"output": "NO"
},
{
"input": "BX\nAC\nCX\nBA",
"output": "YES"
},
{
"input": "XB\nCA\nAX\nCB",
"output": "NO"
},
{
"input": "CB\nXA\nBC\nXA",
"output": "NO"
},
{
"input": "AX\nCB\nCX\nAB",
"output": "NO"
},
{
"input": "BC\nAX\nXC\nAB",
"output": "NO"
},
{
"input": "XB\nCA\nBC\nXA",
"output": "NO"
},
{
"input": "XB\nAC\nCX\nBA",
"output": "YES"
},
{
"input": "BC\nXA\nCB\nXA",
"output": "NO"
},
{
"input": "AX\nCB\nAX\nBC",
"output": "NO"
},
{
"input": "CA\nBX\nBX\nCA",
"output": "NO"
},
{
"input": "BA\nXC\nXB\nAC",
"output": "NO"
},
{
"input": "XA\nBC\nBX\nAC",
"output": "NO"
},
{
"input": "BX\nCA\nAC\nBX",
"output": "YES"
},
{
"input": "XB\nAC\nXC\nBA",
"output": "YES"
},
{
"input": "XB\nAC\nAB\nXC",
"output": "YES"
},
{
"input": "BA\nCX\nCX\nBA",
"output": "NO"
},
{
"input": "CA\nXB\nXB\nCA",
"output": "NO"
},
{
"input": "BA\nCX\nBA\nXC",
"output": "YES"
},
{
"input": "BA\nCX\nAB\nCX",
"output": "NO"
},
{
"input": "BX\nCA\nXA\nBC",
"output": "YES"
},
{
"input": "XC\nBA\nBX\nCA",
"output": "NO"
},
{
"input": "XC\nAB\nBC\nXA",
"output": "NO"
},
{
"input": "BC\nXA\nXC\nAB",
"output": "NO"
},
{
"input": "BX\nCA\nXB\nAC",
"output": "NO"
},
{
"input": "BA\nXC\nCA\nXB",
"output": "NO"
},
{
"input": "CX\nBA\nAC\nXB",
"output": "NO"
},
{
"input": "AB\nCX\nAC\nBX",
"output": "NO"
},
{
"input": "BC\nXA\nBX\nCA",
"output": "NO"
},
{
"input": "XA\nBC\nCX\nAB",
"output": "YES"
},
{
"input": "AX\nBC\nAX\nCB",
"output": "NO"
},
{
"input": "CB\nAX\nCA\nBX",
"output": "NO"
},
{
"input": "CB\nAX\nBA\nXC",
"output": "YES"
},
{
"input": "AB\nCX\nXC\nBA",
"output": "YES"
},
{
"input": "AC\nXB\nBA\nCX",
"output": "YES"
},
{
"input": "AX\nCB\nCB\nAX",
"output": "NO"
},
{
"input": "CX\nBA\nCA\nXB",
"output": "YES"
},
{
"input": "AC\nBX\nAB\nXC",
"output": "NO"
},
{
"input": "XA\nCB\nXA\nBC",
"output": "NO"
},
{
"input": "XC\nBA\nCA\nBX",
"output": "YES"
},
{
"input": "XA\nBC\nXB\nCA",
"output": "YES"
},
{
"input": "CA\nBX\nCB\nAX",
"output": "NO"
}
] | 1,458,319,478 | 578 | Python 3 | WRONG_ANSWER | PRETESTS | 0 | 46 | 0 | a=input()+input()
b=input()+input()
if (a in ['ABCX', 'ABXC', 'XBAC', 'BXAC', 'BCAX', 'BCXA',
'XCBA', 'CXBA', 'CABX', 'CAXB', 'XACB', 'AXCB'] == b in ['ABCX', 'ABXC', 'XBAC', 'BXAC', 'BCAX', 'BCXA',
'XCBA', 'CXBA', 'CABX', 'CAXB', 'XACB', 'AXCB']):
print("YES")
else:
print("NO") | Title: none
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Bessie the cow and her best friend Elsie each received a sliding puzzle on Pi Day. Their puzzles consist of a 2<=×<=2 grid and three tiles labeled 'A', 'B', and 'C'. The three tiles sit on top of the grid, leaving one grid cell empty. To make a move, Bessie or Elsie can slide a tile adjacent to the empty cell into the empty cell as shown below:
In order to determine if they are truly Best Friends For Life (BFFLs), Bessie and Elsie would like to know if there exists a sequence of moves that takes their puzzles to the same configuration (moves can be performed in both puzzles). Two puzzles are considered to be in the same configuration if each tile is on top of the same grid cell in both puzzles. Since the tiles are labeled with letters, rotations and reflections are not allowed.
Input Specification:
The first two lines of the input consist of a 2<=×<=2 grid describing the initial configuration of Bessie's puzzle. The next two lines contain a 2<=×<=2 grid describing the initial configuration of Elsie's puzzle. The positions of the tiles are labeled 'A', 'B', and 'C', while the empty cell is labeled 'X'. It's guaranteed that both puzzles contain exactly one tile with each letter and exactly one empty position.
Output Specification:
Output "YES"(without quotes) if the puzzles can reach the same configuration (and Bessie and Elsie are truly BFFLs). Otherwise, print "NO" (without quotes).
Demo Input:
['AB\nXC\nXB\nAC\n', 'AB\nXC\nAC\nBX\n']
Demo Output:
['YES\n', 'NO\n']
Note:
The solution to the first sample is described by the image. All Bessie needs to do is slide her 'A' tile down.
In the second sample, the two puzzles can never be in the same configuration. Perhaps Bessie and Elsie are not meant to be friends after all... | ```python
a=input()+input()
b=input()+input()
if (a in ['ABCX', 'ABXC', 'XBAC', 'BXAC', 'BCAX', 'BCXA',
'XCBA', 'CXBA', 'CABX', 'CAXB', 'XACB', 'AXCB'] == b in ['ABCX', 'ABXC', 'XBAC', 'BXAC', 'BCAX', 'BCXA',
'XCBA', 'CXBA', 'CABX', 'CAXB', 'XACB', 'AXCB']):
print("YES")
else:
print("NO")
``` | 0 |
|
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,669,193,433 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 12 | 46 | 204,800 | text=input()
count=0
n1=text.count('B')# B1 u2 l1 b2 a2 s1 r1
n2=text.count('b')
n3=text.count('a')
n4=text.count('s')
n5=text.count('r')
n6=text.count('u')
n7=text.count('l')
def get(n1,n2,n3,n4,n5,n6,n7,count):
if n1>=1 and n2>=2 and n3>=2 and n4>=1 and n5>=1 and n6>=2 and n7>=1:
n1-=1
n2-=2
n3-=2
n4-=1
n5-=1
n6-=2
n7-=1
count+=1
return get(n1,n2,n3,n4,n5,n6,n7,count)
else:
print(count,end="")
get(n1,n2,n3,n4,n5,n6,n7,count)
| 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
text=input()
count=0
n1=text.count('B')# B1 u2 l1 b2 a2 s1 r1
n2=text.count('b')
n3=text.count('a')
n4=text.count('s')
n5=text.count('r')
n6=text.count('u')
n7=text.count('l')
def get(n1,n2,n3,n4,n5,n6,n7,count):
if n1>=1 and n2>=2 and n3>=2 and n4>=1 and n5>=1 and n6>=2 and n7>=1:
n1-=1
n2-=2
n3-=2
n4-=1
n5-=1
n6-=2
n7-=1
count+=1
return get(n1,n2,n3,n4,n5,n6,n7,count)
else:
print(count,end="")
get(n1,n2,n3,n4,n5,n6,n7,count)
``` | 0 |
|
344 | A | Magnets | PROGRAMMING | 800 | [
"implementation"
] | null | null | Mad scientist Mike entertains himself by arranging rows of dominoes. He doesn't need dominoes, though: he uses rectangular magnets instead. Each magnet has two poles, positive (a "plus") and negative (a "minus"). If two magnets are put together at a close distance, then the like poles will repel each other and the opposite poles will attract each other.
Mike starts by laying one magnet horizontally on the table. During each following step Mike adds one more magnet horizontally to the right end of the row. Depending on how Mike puts the magnet on the table, it is either attracted to the previous one (forming a group of multiple magnets linked together) or repelled by it (then Mike lays this magnet at some distance to the right from the previous one). We assume that a sole magnet not linked to others forms a group of its own.
Mike arranged multiple magnets in a row. Determine the number of groups that the magnets formed. | The first line of the input contains an integer *n* (1<=≤<=*n*<=≤<=100000) — the number of magnets. Then *n* lines follow. The *i*-th line (1<=≤<=*i*<=≤<=*n*) contains either characters "01", if Mike put the *i*-th magnet in the "plus-minus" position, or characters "10", if Mike put the magnet in the "minus-plus" position. | On the single line of the output print the number of groups of magnets. | [
"6\n10\n10\n10\n01\n10\n10\n",
"4\n01\n01\n10\n10\n"
] | [
"3\n",
"2\n"
] | The first testcase corresponds to the figure. The testcase has three groups consisting of three, one and two magnets.
The second testcase has two groups, each consisting of two magnets. | 500 | [
{
"input": "6\n10\n10\n10\n01\n10\n10",
"output": "3"
},
{
"input": "4\n01\n01\n10\n10",
"output": "2"
},
{
"input": "1\n10",
"output": "1"
},
{
"input": "2\n01\n10",
"output": "2"
},
{
"input": "2\n10\n10",
"output": "1"
},
{
"input": "3\n10\n01\n10",
"output": "3"
},
{
"input": "1\n01",
"output": "1"
},
{
"input": "2\n01\n01",
"output": "1"
},
{
"input": "2\n10\n01",
"output": "2"
},
{
"input": "3\n01\n01\n01",
"output": "1"
},
{
"input": "3\n10\n10\n01",
"output": "2"
},
{
"input": "3\n01\n10\n10",
"output": "2"
},
{
"input": "115\n10\n10\n10\n10\n01\n01\n10\n10\n10\n01\n01\n10\n01\n01\n10\n10\n10\n01\n10\n01\n10\n10\n01\n01\n10\n10\n10\n10\n01\n10\n01\n01\n10\n10\n10\n10\n01\n10\n10\n10\n01\n10\n01\n10\n10\n10\n10\n01\n01\n01\n10\n10\n01\n01\n01\n10\n10\n01\n10\n01\n01\n01\n01\n10\n10\n01\n10\n01\n01\n01\n01\n01\n10\n01\n10\n10\n01\n01\n01\n10\n01\n01\n10\n10\n01\n01\n01\n01\n01\n10\n01\n10\n01\n10\n01\n01\n01\n10\n01\n10\n10\n01\n10\n10\n01\n01\n01\n10\n10\n10\n10\n10\n10\n10\n10",
"output": "55"
}
] | 1,697,364,780 | 2,147,483,647 | Python 3 | OK | TESTS | 31 | 218 | 0 | n = int(input())
prev = ""
groups = 0
for _ in range(n):
s = input()
if s != prev:
groups += 1
prev = s
print(groups) | Title: Magnets
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Mad scientist Mike entertains himself by arranging rows of dominoes. He doesn't need dominoes, though: he uses rectangular magnets instead. Each magnet has two poles, positive (a "plus") and negative (a "minus"). If two magnets are put together at a close distance, then the like poles will repel each other and the opposite poles will attract each other.
Mike starts by laying one magnet horizontally on the table. During each following step Mike adds one more magnet horizontally to the right end of the row. Depending on how Mike puts the magnet on the table, it is either attracted to the previous one (forming a group of multiple magnets linked together) or repelled by it (then Mike lays this magnet at some distance to the right from the previous one). We assume that a sole magnet not linked to others forms a group of its own.
Mike arranged multiple magnets in a row. Determine the number of groups that the magnets formed.
Input Specification:
The first line of the input contains an integer *n* (1<=≤<=*n*<=≤<=100000) — the number of magnets. Then *n* lines follow. The *i*-th line (1<=≤<=*i*<=≤<=*n*) contains either characters "01", if Mike put the *i*-th magnet in the "plus-minus" position, or characters "10", if Mike put the magnet in the "minus-plus" position.
Output Specification:
On the single line of the output print the number of groups of magnets.
Demo Input:
['6\n10\n10\n10\n01\n10\n10\n', '4\n01\n01\n10\n10\n']
Demo Output:
['3\n', '2\n']
Note:
The first testcase corresponds to the figure. The testcase has three groups consisting of three, one and two magnets.
The second testcase has two groups, each consisting of two magnets. | ```python
n = int(input())
prev = ""
groups = 0
for _ in range(n):
s = input()
if s != prev:
groups += 1
prev = s
print(groups)
``` | 3 |
|
987 | B | High School: Become Human | PROGRAMMING | 1,100 | [
"math"
] | null | null | Year 2118. Androids are in mass production for decades now, and they do all the work for humans. But androids have to go to school to be able to solve creative tasks. Just like humans before.
It turns out that high school struggles are not gone. If someone is not like others, he is bullied. Vasya-8800 is an economy-class android which is produced by a little-known company. His design is not perfect, his characteristics also could be better. So he is bullied by other androids.
One of the popular pranks on Vasya is to force him to compare $x^y$ with $y^x$. Other androids can do it in milliseconds while Vasya's memory is too small to store such big numbers.
Please help Vasya! Write a fast program to compare $x^y$ with $y^x$ for Vasya, maybe then other androids will respect him. | On the only line of input there are two integers $x$ and $y$ ($1 \le x, y \le 10^{9}$). | If $x^y < y^x$, then print '<' (without quotes). If $x^y > y^x$, then print '>' (without quotes). If $x^y = y^x$, then print '=' (without quotes). | [
"5 8\n",
"10 3\n",
"6 6\n"
] | [
">\n",
"<\n",
"=\n"
] | In the first example $5^8 = 5 \cdot 5 \cdot 5 \cdot 5 \cdot 5 \cdot 5 \cdot 5 \cdot 5 = 390625$, and $8^5 = 8 \cdot 8 \cdot 8 \cdot 8 \cdot 8 = 32768$. So you should print '>'.
In the second example $10^3 = 1000 < 3^{10} = 59049$.
In the third example $6^6 = 46656 = 6^6$. | 1,000 | [
{
"input": "5 8",
"output": ">"
},
{
"input": "10 3",
"output": "<"
},
{
"input": "6 6",
"output": "="
},
{
"input": "14 1",
"output": ">"
},
{
"input": "2 4",
"output": "="
},
{
"input": "987654321 123456987",
"output": "<"
},
{
"input": "1 10",
"output": "<"
},
{
"input": "9 1",
"output": ">"
},
{
"input": "1 1",
"output": "="
},
{
"input": "2 2",
"output": "="
},
{
"input": "3 3",
"output": "="
},
{
"input": "4 4",
"output": "="
},
{
"input": "5 5",
"output": "="
},
{
"input": "2 3",
"output": "<"
},
{
"input": "2 5",
"output": ">"
},
{
"input": "3 2",
"output": ">"
},
{
"input": "3 4",
"output": ">"
},
{
"input": "3 5",
"output": ">"
},
{
"input": "4 2",
"output": "="
},
{
"input": "4 3",
"output": "<"
},
{
"input": "4 5",
"output": ">"
},
{
"input": "5 2",
"output": "<"
},
{
"input": "5 3",
"output": "<"
},
{
"input": "5 4",
"output": "<"
},
{
"input": "100 101",
"output": ">"
},
{
"input": "876543 372647",
"output": "<"
},
{
"input": "1000000000 999999999",
"output": "<"
},
{
"input": "1000000000 2",
"output": "<"
},
{
"input": "1000000000 1",
"output": ">"
},
{
"input": "987654321 123456789",
"output": "<"
},
{
"input": "1000000000 1000000000",
"output": "="
},
{
"input": "4359435 4396510",
"output": ">"
},
{
"input": "25936809 25936809",
"output": "="
},
{
"input": "53602896 3",
"output": "<"
},
{
"input": "13208659 1",
"output": ">"
},
{
"input": "620537015 620537016",
"output": ">"
},
{
"input": "56498103 56498102",
"output": "<"
},
{
"input": "4 1000000000",
"output": ">"
},
{
"input": "11 15",
"output": ">"
},
{
"input": "2 6",
"output": ">"
},
{
"input": "1 100",
"output": "<"
},
{
"input": "3 9",
"output": ">"
},
{
"input": "5 25",
"output": ">"
},
{
"input": "17 18",
"output": ">"
},
{
"input": "100 99",
"output": "<"
},
{
"input": "10000035 1000432",
"output": "<"
},
{
"input": "27 3",
"output": "<"
},
{
"input": "15657413 15657414",
"output": ">"
}
] | 1,652,008,304 | 2,147,483,647 | PyPy 3-64 | COMPILATION_ERROR | TESTS | 0 | 0 | 0 | #include <bits/stdc++.h>
#define ll long long
#define cinarr(a) for(ll i=0;i<n;i++)cin>>a[i]
using namespace std;
void vo(){
ll c=0;
ll n;
cin>>n>>c;
if(n==c)cout<<"=\n";
else if(pow(n,c)>pow(c,n))cout<<">\n";
else if(pow(n,c)<pow(c,n))cout<<"<\n";
}
int main()
{
ll n = 1;
//cin >> n;
while(n--)vo();
return 0;
}
| Title: High School: Become Human
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Year 2118. Androids are in mass production for decades now, and they do all the work for humans. But androids have to go to school to be able to solve creative tasks. Just like humans before.
It turns out that high school struggles are not gone. If someone is not like others, he is bullied. Vasya-8800 is an economy-class android which is produced by a little-known company. His design is not perfect, his characteristics also could be better. So he is bullied by other androids.
One of the popular pranks on Vasya is to force him to compare $x^y$ with $y^x$. Other androids can do it in milliseconds while Vasya's memory is too small to store such big numbers.
Please help Vasya! Write a fast program to compare $x^y$ with $y^x$ for Vasya, maybe then other androids will respect him.
Input Specification:
On the only line of input there are two integers $x$ and $y$ ($1 \le x, y \le 10^{9}$).
Output Specification:
If $x^y < y^x$, then print '<' (without quotes). If $x^y > y^x$, then print '>' (without quotes). If $x^y = y^x$, then print '=' (without quotes).
Demo Input:
['5 8\n', '10 3\n', '6 6\n']
Demo Output:
['>\n', '<\n', '=\n']
Note:
In the first example $5^8 = 5 \cdot 5 \cdot 5 \cdot 5 \cdot 5 \cdot 5 \cdot 5 \cdot 5 = 390625$, and $8^5 = 8 \cdot 8 \cdot 8 \cdot 8 \cdot 8 = 32768$. So you should print '>'.
In the second example $10^3 = 1000 < 3^{10} = 59049$.
In the third example $6^6 = 46656 = 6^6$. | ```python
#include <bits/stdc++.h>
#define ll long long
#define cinarr(a) for(ll i=0;i<n;i++)cin>>a[i]
using namespace std;
void vo(){
ll c=0;
ll n;
cin>>n>>c;
if(n==c)cout<<"=\n";
else if(pow(n,c)>pow(c,n))cout<<">\n";
else if(pow(n,c)<pow(c,n))cout<<"<\n";
}
int main()
{
ll n = 1;
//cin >> n;
while(n--)vo();
return 0;
}
``` | -1 |
|
34 | A | Reconnaissance 2 | PROGRAMMING | 800 | [
"implementation"
] | A. Reconnaissance 2 | 2 | 256 | *n* soldiers stand in a circle. For each soldier his height *a**i* is known. A reconnaissance unit can be made of such two neighbouring soldiers, whose heights difference is minimal, i.e. |*a**i*<=-<=*a**j*| is minimal. So each of them will be less noticeable with the other. Output any pair of soldiers that can form a reconnaissance unit. | The first line contains integer *n* (2<=≤<=*n*<=≤<=100) — amount of soldiers. Then follow the heights of the soldiers in their order in the circle — *n* space-separated integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=1000). The soldier heights are given in clockwise or counterclockwise direction. | Output two integers — indexes of neighbouring soldiers, who should form a reconnaissance unit. If there are many optimum solutions, output any of them. Remember, that the soldiers stand in a circle. | [
"5\n10 12 13 15 10\n",
"4\n10 20 30 40\n"
] | [
"5 1\n",
"1 2\n"
] | none | 500 | [
{
"input": "5\n10 12 13 15 10",
"output": "5 1"
},
{
"input": "4\n10 20 30 40",
"output": "1 2"
},
{
"input": "6\n744 359 230 586 944 442",
"output": "2 3"
},
{
"input": "5\n826 747 849 687 437",
"output": "1 2"
},
{
"input": "5\n999 999 993 969 999",
"output": "1 2"
},
{
"input": "5\n4 24 6 1 15",
"output": "3 4"
},
{
"input": "2\n511 32",
"output": "1 2"
},
{
"input": "3\n907 452 355",
"output": "2 3"
},
{
"input": "4\n303 872 764 401",
"output": "4 1"
},
{
"input": "10\n684 698 429 694 956 812 594 170 937 764",
"output": "1 2"
},
{
"input": "20\n646 840 437 946 640 564 936 917 487 752 844 734 468 969 674 646 728 642 514 695",
"output": "7 8"
},
{
"input": "30\n996 999 998 984 989 1000 996 993 1000 983 992 999 999 1000 979 992 987 1000 996 1000 1000 989 981 996 995 999 999 989 999 1000",
"output": "12 13"
},
{
"input": "50\n93 27 28 4 5 78 59 24 19 134 31 128 118 36 90 32 32 1 44 32 33 13 31 10 12 25 38 50 25 12 4 22 28 53 48 83 4 25 57 31 71 24 8 7 28 86 23 80 101 58",
"output": "16 17"
},
{
"input": "88\n1000 1000 1000 1000 1000 998 998 1000 1000 1000 1000 999 999 1000 1000 1000 999 1000 997 999 997 1000 999 998 1000 999 1000 1000 1000 999 1000 999 999 1000 1000 999 1000 999 1000 1000 998 1000 1000 1000 998 998 1000 1000 999 1000 1000 1000 1000 1000 1000 1000 998 1000 1000 1000 999 1000 1000 999 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 998 1000 1000 1000 998 1000 1000 998 1000 999 1000 1000 1000 1000",
"output": "1 2"
},
{
"input": "99\n4 4 21 6 5 3 13 2 6 1 3 4 1 3 1 9 11 1 6 17 4 5 20 4 1 9 5 11 3 4 14 1 3 3 1 4 3 5 27 1 1 2 10 7 11 4 19 7 11 6 11 13 3 1 10 7 2 1 16 1 9 4 29 13 2 12 14 2 21 1 9 8 26 12 12 5 2 14 7 8 8 8 9 4 12 2 6 6 7 16 8 14 2 10 20 15 3 7 4",
"output": "1 2"
},
{
"input": "100\n713 572 318 890 577 657 646 146 373 783 392 229 455 871 20 593 573 336 26 381 280 916 907 732 820 713 111 840 570 446 184 711 481 399 788 647 492 15 40 530 549 506 719 782 126 20 778 996 712 761 9 74 812 418 488 175 103 585 900 3 604 521 109 513 145 708 990 361 682 827 791 22 596 780 596 385 450 643 158 496 876 975 319 783 654 895 891 361 397 81 682 899 347 623 809 557 435 279 513 438",
"output": "86 87"
},
{
"input": "100\n31 75 86 68 111 27 22 22 26 30 54 163 107 75 160 122 14 23 17 26 27 20 43 58 59 71 21 148 9 32 43 91 133 286 132 70 90 156 84 14 77 93 23 18 13 72 18 131 33 28 72 175 30 86 249 20 14 208 28 57 63 199 6 10 24 30 62 267 43 479 60 28 138 1 45 3 19 47 7 166 116 117 50 140 28 14 95 85 93 43 61 15 2 70 10 51 7 95 9 25",
"output": "7 8"
},
{
"input": "100\n896 898 967 979 973 709 961 968 806 967 896 967 826 975 936 903 986 856 851 931 852 971 786 837 949 978 686 936 952 909 965 749 908 916 943 973 983 975 939 886 964 928 960 976 907 788 994 773 949 871 947 980 945 985 726 981 887 943 907 990 931 874 840 867 948 951 961 904 888 901 976 967 994 921 828 970 972 722 755 970 860 855 914 869 714 899 969 978 898 862 642 939 904 936 819 934 884 983 955 964",
"output": "1 2"
},
{
"input": "100\n994 927 872 970 815 986 952 996 965 1000 877 986 978 999 950 990 936 997 993 960 921 860 895 869 943 998 983 968 973 953 999 990 995 871 853 979 973 963 953 938 997 989 993 964 960 973 946 975 1000 962 920 746 989 957 904 965 920 979 966 961 1000 993 975 952 846 971 991 979 985 969 984 973 956 1000 952 778 983 974 956 927 995 997 980 997 1000 970 960 970 988 983 947 904 935 972 1000 863 992 996 932 967",
"output": "81 82"
},
{
"input": "100\n48 108 63 21 27 8 49 21 75 8 24 42 149 18 8 28 21 18 25 35 59 70 59 33 40 1 67 34 120 82 4 115 72 87 3 15 15 63 37 12 40 27 83 14 38 20 14 58 93 10 31 3 39 6 197 77 54 16 31 146 9 49 14 8 77 82 5 11 80 116 8 61 50 24 7 103 29 11 3 3 1 12 46 24 21 131 39 29 36 2 107 40 16 99 31 41 29 48 17 17",
"output": "36 37"
}
] | 1,650,082,900 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 62 | 0 | n=int(input())
List=list(map(int,input().split()))
v1=min(List)
i1=List.index(v1)
List.remove(v1);
i2=List.index(min(List))
print(str(i1+1)+" "+str((i2+2)%(n+1)))
| Title: Reconnaissance 2
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
*n* soldiers stand in a circle. For each soldier his height *a**i* is known. A reconnaissance unit can be made of such two neighbouring soldiers, whose heights difference is minimal, i.e. |*a**i*<=-<=*a**j*| is minimal. So each of them will be less noticeable with the other. Output any pair of soldiers that can form a reconnaissance unit.
Input Specification:
The first line contains integer *n* (2<=≤<=*n*<=≤<=100) — amount of soldiers. Then follow the heights of the soldiers in their order in the circle — *n* space-separated integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=1000). The soldier heights are given in clockwise or counterclockwise direction.
Output Specification:
Output two integers — indexes of neighbouring soldiers, who should form a reconnaissance unit. If there are many optimum solutions, output any of them. Remember, that the soldiers stand in a circle.
Demo Input:
['5\n10 12 13 15 10\n', '4\n10 20 30 40\n']
Demo Output:
['5 1\n', '1 2\n']
Note:
none | ```python
n=int(input())
List=list(map(int,input().split()))
v1=min(List)
i1=List.index(v1)
List.remove(v1);
i2=List.index(min(List))
print(str(i1+1)+" "+str((i2+2)%(n+1)))
``` | 0 |
103 | B | Cthulhu | PROGRAMMING | 1,500 | [
"dfs and similar",
"dsu",
"graphs"
] | B. Cthulhu | 2 | 256 | ...Once upon a time a man came to the sea. The sea was stormy and dark. The man started to call for the little mermaid to appear but alas, he only woke up Cthulhu...
Whereas on the other end of the world Pentagon is actively collecting information trying to predict the monster's behavior and preparing the secret super weapon. Due to high seismic activity and poor weather conditions the satellites haven't yet been able to make clear shots of the monster. The analysis of the first shot resulted in an undirected graph with *n* vertices and *m* edges. Now the world's best minds are about to determine whether this graph can be regarded as Cthulhu or not.
To add simplicity, let's suppose that Cthulhu looks from the space like some spherical body with tentacles attached to it. Formally, we shall regard as Cthulhu such an undirected graph that can be represented as a set of three or more rooted trees, whose roots are connected by a simple cycle.
It is guaranteed that the graph contains no multiple edges and self-loops. | The first line contains two integers — the number of vertices *n* and the number of edges *m* of the graph (1<=≤<=*n*<=≤<=100, 0<=≤<=*m*<=≤<=).
Each of the following *m* lines contains a pair of integers *x* and *y*, that show that an edge exists between vertices *x* and *y* (1<=≤<=*x*,<=*y*<=≤<=*n*,<=*x*<=≠<=*y*). For each pair of vertices there will be at most one edge between them, no edge connects a vertex to itself. | Print "NO", if the graph is not Cthulhu and "FHTAGN!" if it is. | [
"6 6\n6 3\n6 4\n5 1\n2 5\n1 4\n5 4\n",
"6 5\n5 6\n4 6\n3 1\n5 1\n1 2\n"
] | [
"FHTAGN!",
"NO"
] | Let us denote as a simple cycle a set of *v* vertices that can be numbered so that the edges will only exist between vertices number 1 and 2, 2 and 3, ..., *v* - 1 and *v*, *v* and 1.
A tree is a connected undirected graph consisting of *n* vertices and *n* - 1 edges (*n* > 0).
A rooted tree is a tree where one vertex is selected to be the root. | 1,000 | [
{
"input": "6 6\n6 3\n6 4\n5 1\n2 5\n1 4\n5 4",
"output": "FHTAGN!"
},
{
"input": "6 5\n5 6\n4 6\n3 1\n5 1\n1 2",
"output": "NO"
},
{
"input": "10 10\n4 10\n8 5\n2 8\n4 9\n9 3\n2 7\n10 6\n10 2\n9 8\n1 8",
"output": "FHTAGN!"
},
{
"input": "5 4\n1 5\n1 3\n1 4\n3 2",
"output": "NO"
},
{
"input": "12 12\n4 12\n4 7\n4 9\n7 2\n5 12\n2 1\n5 9\n8 6\n10 12\n2 5\n10 9\n12 3",
"output": "NO"
},
{
"input": "12 15\n3 2\n11 12\n1 9\n2 1\n1 8\n9 6\n11 5\n9 5\n9 10\n11 3\n7 11\n5 6\n11 10\n4 6\n4 2",
"output": "NO"
},
{
"input": "12 10\n1 11\n3 6\n5 7\n4 7\n6 8\n11 7\n3 12\n11 12\n7 9\n12 2",
"output": "NO"
},
{
"input": "1 0",
"output": "NO"
},
{
"input": "2 1\n1 2",
"output": "NO"
},
{
"input": "3 1\n1 3",
"output": "NO"
},
{
"input": "3 2\n1 2\n2 3",
"output": "NO"
},
{
"input": "3 3\n1 2\n2 3\n3 1",
"output": "FHTAGN!"
},
{
"input": "4 4\n1 2\n3 4\n4 1\n2 4",
"output": "FHTAGN!"
},
{
"input": "6 6\n1 2\n2 3\n3 1\n4 5\n5 6\n6 4",
"output": "NO"
},
{
"input": "2 0",
"output": "NO"
},
{
"input": "3 0",
"output": "NO"
},
{
"input": "100 0",
"output": "NO"
},
{
"input": "100 1\n11 23",
"output": "NO"
},
{
"input": "10 10\n5 7\n8 1\n10 3\n6 4\n10 6\n5 3\n5 6\n2 6\n4 3\n2 10",
"output": "NO"
},
{
"input": "20 20\n9 10\n4 19\n9 20\n12 20\n1 15\n2 12\n19 10\n19 15\n4 10\n4 8\n8 9\n20 8\n6 2\n2 15\n7 19\n20 4\n3 16\n1 20\n9 1\n20 10",
"output": "NO"
},
{
"input": "30 30\n17 6\n16 29\n16 13\n16 20\n29 26\n17 5\n27 28\n24 16\n7 18\n24 10\n1 27\n12 17\n27 30\n6 1\n3 30\n5 19\n18 13\n16 2\n30 1\n5 8\n14 16\n26 18\n7 19\n5 6\n23 14\n6 8\n23 8\n18 8\n18 3\n5 21",
"output": "NO"
},
{
"input": "100 66\n41 14\n19 13\n70 43\n79 62\n9 62\n71 40\n53 86\n80 4\n34 33\n72 68\n40 96\n84 59\n36 77\n55 50\n40 3\n79 81\n3 43\n33 47\n22 98\n33 90\n56 49\n69 28\n73 30\n65 22\n98 20\n9 52\n54 20\n32 70\n51 80\n63 12\n21 48\n35 17\n48 87\n25 43\n65 80\n42 3\n86 35\n95 98\n43 59\n51 46\n66 37\n88 34\n32 47\n24 42\n21 44\n92 59\n81 6\n100 82\n85 6\n58 25\n66 6\n14 32\n59 85\n3 98\n44 4\n85 51\n69 41\n80 70\n81 24\n75 71\n93 9\n82 55\n70 46\n66 32\n77 58\n11 46",
"output": "NO"
},
{
"input": "4 4\n1 2\n4 3\n2 3\n3 1",
"output": "FHTAGN!"
},
{
"input": "5 5\n2 3\n2 4\n5 4\n4 1\n1 2",
"output": "FHTAGN!"
},
{
"input": "10 10\n1 10\n5 9\n6 2\n8 9\n9 1\n5 4\n2 8\n1 3\n6 3\n4 1",
"output": "NO"
},
{
"input": "6 6\n1 2\n2 3\n3 1\n4 5\n5 6\n6 4",
"output": "NO"
},
{
"input": "4 3\n1 2\n2 3\n3 1",
"output": "NO"
},
{
"input": "6 5\n1 2\n2 3\n3 1\n1 4\n1 5",
"output": "NO"
}
] | 1,649,946,135 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 30 | 92 | 102,400 | from collections import defaultdict
nodos=defaultdict(list)
n,m=map(int,input().split(' '))
for i in range(m):
a,b=map(int,input().split(' '))
nodos[a-1].append(b-1)
nodos[b-1].append(a-1)
visitadas=[False]*n
def DFS(nodo):
visitadas[nodo]=True
for i in nodos[nodo]:
if not visitadas[i]:
DFS(i)
conjuntos=0
for i in nodos.keys():
if not visitadas[i]:
DFS(i)
conjuntos+=1
if conjuntos==1 and n==m: print('FHTAGN!')
else: print('NO') | Title: Cthulhu
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
...Once upon a time a man came to the sea. The sea was stormy and dark. The man started to call for the little mermaid to appear but alas, he only woke up Cthulhu...
Whereas on the other end of the world Pentagon is actively collecting information trying to predict the monster's behavior and preparing the secret super weapon. Due to high seismic activity and poor weather conditions the satellites haven't yet been able to make clear shots of the monster. The analysis of the first shot resulted in an undirected graph with *n* vertices and *m* edges. Now the world's best minds are about to determine whether this graph can be regarded as Cthulhu or not.
To add simplicity, let's suppose that Cthulhu looks from the space like some spherical body with tentacles attached to it. Formally, we shall regard as Cthulhu such an undirected graph that can be represented as a set of three or more rooted trees, whose roots are connected by a simple cycle.
It is guaranteed that the graph contains no multiple edges and self-loops.
Input Specification:
The first line contains two integers — the number of vertices *n* and the number of edges *m* of the graph (1<=≤<=*n*<=≤<=100, 0<=≤<=*m*<=≤<=).
Each of the following *m* lines contains a pair of integers *x* and *y*, that show that an edge exists between vertices *x* and *y* (1<=≤<=*x*,<=*y*<=≤<=*n*,<=*x*<=≠<=*y*). For each pair of vertices there will be at most one edge between them, no edge connects a vertex to itself.
Output Specification:
Print "NO", if the graph is not Cthulhu and "FHTAGN!" if it is.
Demo Input:
['6 6\n6 3\n6 4\n5 1\n2 5\n1 4\n5 4\n', '6 5\n5 6\n4 6\n3 1\n5 1\n1 2\n']
Demo Output:
['FHTAGN!', 'NO']
Note:
Let us denote as a simple cycle a set of *v* vertices that can be numbered so that the edges will only exist between vertices number 1 and 2, 2 and 3, ..., *v* - 1 and *v*, *v* and 1.
A tree is a connected undirected graph consisting of *n* vertices and *n* - 1 edges (*n* > 0).
A rooted tree is a tree where one vertex is selected to be the root. | ```python
from collections import defaultdict
nodos=defaultdict(list)
n,m=map(int,input().split(' '))
for i in range(m):
a,b=map(int,input().split(' '))
nodos[a-1].append(b-1)
nodos[b-1].append(a-1)
visitadas=[False]*n
def DFS(nodo):
visitadas[nodo]=True
for i in nodos[nodo]:
if not visitadas[i]:
DFS(i)
conjuntos=0
for i in nodos.keys():
if not visitadas[i]:
DFS(i)
conjuntos+=1
if conjuntos==1 and n==m: print('FHTAGN!')
else: print('NO')
``` | 0 |
576 | B | Invariance of Tree | PROGRAMMING | 2,100 | [
"constructive algorithms",
"dfs and similar",
"greedy",
"trees"
] | null | null | A tree of size *n* is an undirected connected graph consisting of *n* vertices without cycles.
Consider some tree with *n* vertices. We call a tree invariant relative to permutation *p*<==<=*p*1*p*2... *p**n*, if for any two vertices of the tree *u* and *v* the condition holds: "vertices *u* and *v* are connected by an edge if and only if vertices *p**u* and *p**v* are connected by an edge".
You are given permutation *p* of size *n*. Find some tree size *n*, invariant relative to the given permutation. | The first line contains number *n* (1<=≤<=*n*<=≤<=105) — the size of the permutation (also equal to the size of the sought tree).
The second line contains permutation *p**i* (1<=≤<=*p**i*<=≤<=*n*). | If the sought tree does not exist, print "NO" (without the quotes).
Otherwise, print "YES", and then print *n*<=-<=1 lines, each of which contains two integers — the numbers of vertices connected by an edge of the tree you found. The vertices are numbered from 1, the order of the edges and the order of the vertices within the edges does not matter.
If there are multiple solutions, output any of them. | [
"4\n4 3 2 1\n",
"3\n3 1 2\n"
] | [
"YES\n4 1\n4 2\n1 3\n",
"NO\n"
] | In the first sample test a permutation transforms edge (4, 1) into edge (1, 4), edge (4, 2) into edge (1, 3) and edge (1, 3) into edge (4, 2). These edges all appear in the resulting tree.
It can be shown that in the second sample test no tree satisfies the given condition. | 1,250 | [
{
"input": "4\n4 3 2 1",
"output": "YES\n4 1\n4 2\n1 3"
},
{
"input": "3\n3 1 2",
"output": "NO"
},
{
"input": "3\n3 2 1",
"output": "YES\n2 1\n2 3"
},
{
"input": "4\n3 4 1 2",
"output": "YES\n4 2\n4 1\n2 3"
},
{
"input": "5\n5 3 2 1 4",
"output": "NO"
},
{
"input": "8\n1 2 6 4 5 7 8 3",
"output": "YES\n5 1\n5 2\n5 3\n5 4\n5 6\n5 7\n5 8"
},
{
"input": "11\n7 3 5 2 10 1 9 6 8 4 11",
"output": "YES\n11 1\n11 2\n11 3\n11 4\n11 5\n11 6\n11 7\n11 8\n11 9\n11 10"
},
{
"input": "1\n1",
"output": "YES"
},
{
"input": "2\n1 2",
"output": "YES\n2 1"
},
{
"input": "2\n2 1",
"output": "YES\n2 1"
},
{
"input": "6\n2 1 6 5 3 4",
"output": "YES\n2 1\n2 3\n2 4\n1 6\n1 5"
},
{
"input": "6\n2 1 4 5 6 3",
"output": "YES\n2 1\n2 3\n2 5\n1 4\n1 6"
},
{
"input": "4\n2 3 4 1",
"output": "NO"
},
{
"input": "6\n2 3 4 1 6 5",
"output": "YES\n6 5\n6 1\n6 3\n5 2\n5 4"
},
{
"input": "6\n4 1 2 3 6 5",
"output": "YES\n6 5\n6 1\n6 3\n5 4\n5 2"
}
] | 1,601,344,764 | 1,764 | PyPy 3 | OK | TESTS | 58 | 296 | 22,118,400 | import sys
readline = sys.stdin.readline
N = int(readline())
P = list(map(lambda x: int(x)-1, readline().split()))
PP = []
used = set()
for i in range(N):
if i not in used:
res = []
while i not in used:
used.add(i)
res.append(i)
i = P[i]
PP.append(res)
if any(len(p) == 1 for p in PP):
print('YES')
for p in PP:
if len(p) == 1:
break
d = p[0]
Ans = []
for i in range(N):
if i != d:
Ans.append('{} {}'.format(i+1, d+1))
print('\n'.join(Ans))
elif not any(len(p) == 2 for p in PP):
print('NO')
elif any(len(p) & 1 for p in PP):
print('NO')
else:
print('YES')
dd = None
for p in PP:
if len(p) == 2:
dd = p
PP.remove(p)
break
d1, d2 = dd
Ans = ['{} {}'.format(d1+1, d2+1)]
for p in PP:
for i in range(len(p)):
if i&1:
Ans.append('{} {}'.format(d1+1, p[i]+1))
else:
Ans.append('{} {}'.format(d2+1, p[i]+1))
print('\n'.join(Ans))
| Title: Invariance of Tree
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A tree of size *n* is an undirected connected graph consisting of *n* vertices without cycles.
Consider some tree with *n* vertices. We call a tree invariant relative to permutation *p*<==<=*p*1*p*2... *p**n*, if for any two vertices of the tree *u* and *v* the condition holds: "vertices *u* and *v* are connected by an edge if and only if vertices *p**u* and *p**v* are connected by an edge".
You are given permutation *p* of size *n*. Find some tree size *n*, invariant relative to the given permutation.
Input Specification:
The first line contains number *n* (1<=≤<=*n*<=≤<=105) — the size of the permutation (also equal to the size of the sought tree).
The second line contains permutation *p**i* (1<=≤<=*p**i*<=≤<=*n*).
Output Specification:
If the sought tree does not exist, print "NO" (without the quotes).
Otherwise, print "YES", and then print *n*<=-<=1 lines, each of which contains two integers — the numbers of vertices connected by an edge of the tree you found. The vertices are numbered from 1, the order of the edges and the order of the vertices within the edges does not matter.
If there are multiple solutions, output any of them.
Demo Input:
['4\n4 3 2 1\n', '3\n3 1 2\n']
Demo Output:
['YES\n4 1\n4 2\n1 3\n', 'NO\n']
Note:
In the first sample test a permutation transforms edge (4, 1) into edge (1, 4), edge (4, 2) into edge (1, 3) and edge (1, 3) into edge (4, 2). These edges all appear in the resulting tree.
It can be shown that in the second sample test no tree satisfies the given condition. | ```python
import sys
readline = sys.stdin.readline
N = int(readline())
P = list(map(lambda x: int(x)-1, readline().split()))
PP = []
used = set()
for i in range(N):
if i not in used:
res = []
while i not in used:
used.add(i)
res.append(i)
i = P[i]
PP.append(res)
if any(len(p) == 1 for p in PP):
print('YES')
for p in PP:
if len(p) == 1:
break
d = p[0]
Ans = []
for i in range(N):
if i != d:
Ans.append('{} {}'.format(i+1, d+1))
print('\n'.join(Ans))
elif not any(len(p) == 2 for p in PP):
print('NO')
elif any(len(p) & 1 for p in PP):
print('NO')
else:
print('YES')
dd = None
for p in PP:
if len(p) == 2:
dd = p
PP.remove(p)
break
d1, d2 = dd
Ans = ['{} {}'.format(d1+1, d2+1)]
for p in PP:
for i in range(len(p)):
if i&1:
Ans.append('{} {}'.format(d1+1, p[i]+1))
else:
Ans.append('{} {}'.format(d2+1, p[i]+1))
print('\n'.join(Ans))
``` | 3 |
|
456 | A | Laptops | PROGRAMMING | 1,100 | [
"sortings"
] | null | null | One day Dima and Alex had an argument about the price and quality of laptops. Dima thinks that the more expensive a laptop is, the better it is. Alex disagrees. Alex thinks that there are two laptops, such that the price of the first laptop is less (strictly smaller) than the price of the second laptop but the quality of the first laptop is higher (strictly greater) than the quality of the second laptop.
Please, check the guess of Alex. You are given descriptions of *n* laptops. Determine whether two described above laptops exist. | The first line contains an integer *n* (1<=≤<=*n*<=≤<=105) — the number of laptops.
Next *n* lines contain two integers each, *a**i* and *b**i* (1<=≤<=*a**i*,<=*b**i*<=≤<=*n*), where *a**i* is the price of the *i*-th laptop, and *b**i* is the number that represents the quality of the *i*-th laptop (the larger the number is, the higher is the quality).
All *a**i* are distinct. All *b**i* are distinct. | If Alex is correct, print "Happy Alex", otherwise print "Poor Alex" (without the quotes). | [
"2\n1 2\n2 1\n"
] | [
"Happy Alex\n"
] | none | 500 | [
{
"input": "2\n1 2\n2 1",
"output": "Happy Alex"
},
{
"input": "2\n1 1\n2 2",
"output": "Poor Alex"
},
{
"input": "3\n2 2\n3 3\n1 1",
"output": "Poor Alex"
},
{
"input": "3\n3 3\n1 2\n2 1",
"output": "Happy Alex"
},
{
"input": "1\n1 1",
"output": "Poor Alex"
},
{
"input": "3\n2 3\n1 1\n3 2",
"output": "Happy Alex"
},
{
"input": "4\n4 1\n3 2\n2 3\n1 4",
"output": "Happy Alex"
},
{
"input": "2\n2 1\n1 2",
"output": "Happy Alex"
},
{
"input": "3\n3 2\n1 1\n2 3",
"output": "Happy Alex"
},
{
"input": "3\n1 2\n2 3\n3 1",
"output": "Happy Alex"
},
{
"input": "3\n1 2\n2 1\n3 3",
"output": "Happy Alex"
},
{
"input": "3\n1 2\n2 3\n3 1",
"output": "Happy Alex"
}
] | 1,676,616,849 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 39 | 639 | 13,312,000 | n=int(input())
i=0
list1=[]
list2=[]
while i<n:
a,b=list(map(int,input().split()))
list1.append(a)
list2.append(b)
i+=1
u=0
flag=True
while u<len(list1)-1:
if list1[u]<=list1[u+1]:
if list2[u]>list2[u+1]:
flag=False
if list1[u]>list1[u+1]:
if list2[u]<list2[u+1]:
flag=False
u+=1
if flag==False:
print("Happy Alex")
else:
print( "Poor Alex") | Title: Laptops
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
One day Dima and Alex had an argument about the price and quality of laptops. Dima thinks that the more expensive a laptop is, the better it is. Alex disagrees. Alex thinks that there are two laptops, such that the price of the first laptop is less (strictly smaller) than the price of the second laptop but the quality of the first laptop is higher (strictly greater) than the quality of the second laptop.
Please, check the guess of Alex. You are given descriptions of *n* laptops. Determine whether two described above laptops exist.
Input Specification:
The first line contains an integer *n* (1<=≤<=*n*<=≤<=105) — the number of laptops.
Next *n* lines contain two integers each, *a**i* and *b**i* (1<=≤<=*a**i*,<=*b**i*<=≤<=*n*), where *a**i* is the price of the *i*-th laptop, and *b**i* is the number that represents the quality of the *i*-th laptop (the larger the number is, the higher is the quality).
All *a**i* are distinct. All *b**i* are distinct.
Output Specification:
If Alex is correct, print "Happy Alex", otherwise print "Poor Alex" (without the quotes).
Demo Input:
['2\n1 2\n2 1\n']
Demo Output:
['Happy Alex\n']
Note:
none | ```python
n=int(input())
i=0
list1=[]
list2=[]
while i<n:
a,b=list(map(int,input().split()))
list1.append(a)
list2.append(b)
i+=1
u=0
flag=True
while u<len(list1)-1:
if list1[u]<=list1[u+1]:
if list2[u]>list2[u+1]:
flag=False
if list1[u]>list1[u+1]:
if list2[u]<list2[u+1]:
flag=False
u+=1
if flag==False:
print("Happy Alex")
else:
print( "Poor Alex")
``` | 0 |
|
822 | A | I'm bored with life | PROGRAMMING | 800 | [
"implementation",
"math",
"number theory"
] | null | null | Holidays have finished. Thanks to the help of the hacker Leha, Noora managed to enter the university of her dreams which is located in a town Pavlopolis. It's well known that universities provide students with dormitory for the period of university studies. Consequently Noora had to leave Vičkopolis and move to Pavlopolis. Thus Leha was left completely alone in a quiet town Vičkopolis. He almost even fell into a depression from boredom!
Leha came up with a task for himself to relax a little. He chooses two integers *A* and *B* and then calculates the greatest common divisor of integers "*A* factorial" and "*B* factorial". Formally the hacker wants to find out GCD(*A*!,<=*B*!). It's well known that the factorial of an integer *x* is a product of all positive integers less than or equal to *x*. Thus *x*!<==<=1·2·3·...·(*x*<=-<=1)·*x*. For example 4!<==<=1·2·3·4<==<=24. Recall that GCD(*x*,<=*y*) is the largest positive integer *q* that divides (without a remainder) both *x* and *y*.
Leha has learned how to solve this task very effective. You are able to cope with it not worse, aren't you? | The first and single line contains two integers *A* and *B* (1<=≤<=*A*,<=*B*<=≤<=109,<=*min*(*A*,<=*B*)<=≤<=12). | Print a single integer denoting the greatest common divisor of integers *A*! and *B*!. | [
"4 3\n"
] | [
"6\n"
] | Consider the sample.
4! = 1·2·3·4 = 24. 3! = 1·2·3 = 6. The greatest common divisor of integers 24 and 6 is exactly 6. | 500 | [
{
"input": "4 3",
"output": "6"
},
{
"input": "10 399603090",
"output": "3628800"
},
{
"input": "6 973151934",
"output": "720"
},
{
"input": "2 841668075",
"output": "2"
},
{
"input": "7 415216919",
"output": "5040"
},
{
"input": "3 283733059",
"output": "6"
},
{
"input": "11 562314608",
"output": "39916800"
},
{
"input": "3 990639260",
"output": "6"
},
{
"input": "11 859155400",
"output": "39916800"
},
{
"input": "1 1",
"output": "1"
},
{
"input": "5 3",
"output": "6"
},
{
"input": "1 4",
"output": "1"
},
{
"input": "5 4",
"output": "24"
},
{
"input": "1 12",
"output": "1"
},
{
"input": "9 7",
"output": "5040"
},
{
"input": "2 3",
"output": "2"
},
{
"input": "6 11",
"output": "720"
},
{
"input": "6 7",
"output": "720"
},
{
"input": "11 11",
"output": "39916800"
},
{
"input": "4 999832660",
"output": "24"
},
{
"input": "7 999228288",
"output": "5040"
},
{
"input": "11 999257105",
"output": "39916800"
},
{
"input": "11 999286606",
"output": "39916800"
},
{
"input": "3 999279109",
"output": "6"
},
{
"input": "999632727 11",
"output": "39916800"
},
{
"input": "999625230 7",
"output": "5040"
},
{
"input": "999617047 3",
"output": "6"
},
{
"input": "999646548 7",
"output": "5040"
},
{
"input": "999639051 3",
"output": "6"
},
{
"input": "12 12",
"output": "479001600"
},
{
"input": "12 1",
"output": "1"
},
{
"input": "1213 5",
"output": "120"
},
{
"input": "8 9",
"output": "40320"
},
{
"input": "12 9",
"output": "362880"
},
{
"input": "12 1000000000",
"output": "479001600"
},
{
"input": "1000000000 1",
"output": "1"
},
{
"input": "12 13",
"output": "479001600"
},
{
"input": "2 29845",
"output": "2"
},
{
"input": "10 21",
"output": "3628800"
},
{
"input": "12 20",
"output": "479001600"
},
{
"input": "15 12",
"output": "479001600"
},
{
"input": "1 1",
"output": "1"
},
{
"input": "1000000000 12",
"output": "479001600"
},
{
"input": "11 30",
"output": "39916800"
},
{
"input": "17 12",
"output": "479001600"
},
{
"input": "4 19",
"output": "24"
},
{
"input": "12 15",
"output": "479001600"
},
{
"input": "20 6",
"output": "720"
},
{
"input": "10 20",
"output": "3628800"
},
{
"input": "10 10",
"output": "3628800"
},
{
"input": "22 12",
"output": "479001600"
},
{
"input": "20 12",
"output": "479001600"
},
{
"input": "12 23",
"output": "479001600"
},
{
"input": "12 22",
"output": "479001600"
},
{
"input": "18 3",
"output": "6"
},
{
"input": "14 10",
"output": "3628800"
},
{
"input": "14 12",
"output": "479001600"
},
{
"input": "8 3",
"output": "6"
},
{
"input": "5 5",
"output": "120"
}
] | 1,656,686,304 | 2,147,483,647 | Python 3 | OK | TESTS | 59 | 46 | 0 | x,y = map(int, input().split())
minofnum = min(x,y)
fact_num = 1
for i in range(1, minofnum+1):
fact_num = fact_num * i
print(fact_num) | Title: I'm bored with life
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Holidays have finished. Thanks to the help of the hacker Leha, Noora managed to enter the university of her dreams which is located in a town Pavlopolis. It's well known that universities provide students with dormitory for the period of university studies. Consequently Noora had to leave Vičkopolis and move to Pavlopolis. Thus Leha was left completely alone in a quiet town Vičkopolis. He almost even fell into a depression from boredom!
Leha came up with a task for himself to relax a little. He chooses two integers *A* and *B* and then calculates the greatest common divisor of integers "*A* factorial" and "*B* factorial". Formally the hacker wants to find out GCD(*A*!,<=*B*!). It's well known that the factorial of an integer *x* is a product of all positive integers less than or equal to *x*. Thus *x*!<==<=1·2·3·...·(*x*<=-<=1)·*x*. For example 4!<==<=1·2·3·4<==<=24. Recall that GCD(*x*,<=*y*) is the largest positive integer *q* that divides (without a remainder) both *x* and *y*.
Leha has learned how to solve this task very effective. You are able to cope with it not worse, aren't you?
Input Specification:
The first and single line contains two integers *A* and *B* (1<=≤<=*A*,<=*B*<=≤<=109,<=*min*(*A*,<=*B*)<=≤<=12).
Output Specification:
Print a single integer denoting the greatest common divisor of integers *A*! and *B*!.
Demo Input:
['4 3\n']
Demo Output:
['6\n']
Note:
Consider the sample.
4! = 1·2·3·4 = 24. 3! = 1·2·3 = 6. The greatest common divisor of integers 24 and 6 is exactly 6. | ```python
x,y = map(int, input().split())
minofnum = min(x,y)
fact_num = 1
for i in range(1, minofnum+1):
fact_num = fact_num * i
print(fact_num)
``` | 3 |
|
791 | A | Bear and Big Brother | PROGRAMMING | 800 | [
"implementation"
] | null | null | Bear Limak wants to become the largest of bears, or at least to become larger than his brother Bob.
Right now, Limak and Bob weigh *a* and *b* respectively. It's guaranteed that Limak's weight is smaller than or equal to his brother's weight.
Limak eats a lot and his weight is tripled after every year, while Bob's weight is doubled after every year.
After how many full years will Limak become strictly larger (strictly heavier) than Bob? | The only line of the input contains two integers *a* and *b* (1<=≤<=*a*<=≤<=*b*<=≤<=10) — the weight of Limak and the weight of Bob respectively. | Print one integer, denoting the integer number of years after which Limak will become strictly larger than Bob. | [
"4 7\n",
"4 9\n",
"1 1\n"
] | [
"2\n",
"3\n",
"1\n"
] | In the first sample, Limak weighs 4 and Bob weighs 7 initially. After one year their weights are 4·3 = 12 and 7·2 = 14 respectively (one weight is tripled while the other one is doubled). Limak isn't larger than Bob yet. After the second year weights are 36 and 28, so the first weight is greater than the second one. Limak became larger than Bob after two years so you should print 2.
In the second sample, Limak's and Bob's weights in next years are: 12 and 18, then 36 and 36, and finally 108 and 72 (after three years). The answer is 3. Remember that Limak wants to be larger than Bob and he won't be satisfied with equal weights.
In the third sample, Limak becomes larger than Bob after the first year. Their weights will be 3 and 2 then. | 500 | [
{
"input": "4 7",
"output": "2"
},
{
"input": "4 9",
"output": "3"
},
{
"input": "1 1",
"output": "1"
},
{
"input": "4 6",
"output": "2"
},
{
"input": "1 10",
"output": "6"
},
{
"input": "1 1",
"output": "1"
},
{
"input": "1 2",
"output": "2"
},
{
"input": "1 3",
"output": "3"
},
{
"input": "1 4",
"output": "4"
},
{
"input": "1 5",
"output": "4"
},
{
"input": "1 6",
"output": "5"
},
{
"input": "1 7",
"output": "5"
},
{
"input": "1 8",
"output": "6"
},
{
"input": "1 9",
"output": "6"
},
{
"input": "1 10",
"output": "6"
},
{
"input": "2 2",
"output": "1"
},
{
"input": "2 3",
"output": "2"
},
{
"input": "2 4",
"output": "2"
},
{
"input": "2 5",
"output": "3"
},
{
"input": "2 6",
"output": "3"
},
{
"input": "2 7",
"output": "4"
},
{
"input": "2 8",
"output": "4"
},
{
"input": "2 9",
"output": "4"
},
{
"input": "2 10",
"output": "4"
},
{
"input": "3 3",
"output": "1"
},
{
"input": "3 4",
"output": "1"
},
{
"input": "3 5",
"output": "2"
},
{
"input": "3 6",
"output": "2"
},
{
"input": "3 7",
"output": "3"
},
{
"input": "3 8",
"output": "3"
},
{
"input": "3 9",
"output": "3"
},
{
"input": "3 10",
"output": "3"
},
{
"input": "4 4",
"output": "1"
},
{
"input": "4 5",
"output": "1"
},
{
"input": "4 6",
"output": "2"
},
{
"input": "4 7",
"output": "2"
},
{
"input": "4 8",
"output": "2"
},
{
"input": "4 9",
"output": "3"
},
{
"input": "4 10",
"output": "3"
},
{
"input": "5 5",
"output": "1"
},
{
"input": "5 6",
"output": "1"
},
{
"input": "5 7",
"output": "1"
},
{
"input": "5 8",
"output": "2"
},
{
"input": "5 9",
"output": "2"
},
{
"input": "5 10",
"output": "2"
},
{
"input": "6 6",
"output": "1"
},
{
"input": "6 7",
"output": "1"
},
{
"input": "6 8",
"output": "1"
},
{
"input": "6 9",
"output": "2"
},
{
"input": "6 10",
"output": "2"
},
{
"input": "7 7",
"output": "1"
},
{
"input": "7 8",
"output": "1"
},
{
"input": "7 9",
"output": "1"
},
{
"input": "7 10",
"output": "1"
},
{
"input": "8 8",
"output": "1"
},
{
"input": "8 9",
"output": "1"
},
{
"input": "8 10",
"output": "1"
},
{
"input": "9 9",
"output": "1"
},
{
"input": "9 10",
"output": "1"
},
{
"input": "10 10",
"output": "1"
},
{
"input": "10 10",
"output": "1"
},
{
"input": "1 2",
"output": "2"
}
] | 1,694,153,515 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 30 | 0 | a, b = map(int, input().split(' '))
if a == b:
print(1)
else:
count = 0
while a > b:
a*=3
b8=2
count += 1
print(count) | Title: Bear and Big Brother
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Bear Limak wants to become the largest of bears, or at least to become larger than his brother Bob.
Right now, Limak and Bob weigh *a* and *b* respectively. It's guaranteed that Limak's weight is smaller than or equal to his brother's weight.
Limak eats a lot and his weight is tripled after every year, while Bob's weight is doubled after every year.
After how many full years will Limak become strictly larger (strictly heavier) than Bob?
Input Specification:
The only line of the input contains two integers *a* and *b* (1<=≤<=*a*<=≤<=*b*<=≤<=10) — the weight of Limak and the weight of Bob respectively.
Output Specification:
Print one integer, denoting the integer number of years after which Limak will become strictly larger than Bob.
Demo Input:
['4 7\n', '4 9\n', '1 1\n']
Demo Output:
['2\n', '3\n', '1\n']
Note:
In the first sample, Limak weighs 4 and Bob weighs 7 initially. After one year their weights are 4·3 = 12 and 7·2 = 14 respectively (one weight is tripled while the other one is doubled). Limak isn't larger than Bob yet. After the second year weights are 36 and 28, so the first weight is greater than the second one. Limak became larger than Bob after two years so you should print 2.
In the second sample, Limak's and Bob's weights in next years are: 12 and 18, then 36 and 36, and finally 108 and 72 (after three years). The answer is 3. Remember that Limak wants to be larger than Bob and he won't be satisfied with equal weights.
In the third sample, Limak becomes larger than Bob after the first year. Their weights will be 3 and 2 then. | ```python
a, b = map(int, input().split(' '))
if a == b:
print(1)
else:
count = 0
while a > b:
a*=3
b8=2
count += 1
print(count)
``` | 0 |
|
333 | C | Lucky Tickets | PROGRAMMING | 2,700 | [
"brute force",
"constructive algorithms"
] | null | null | Gerald has a friend, Pollard. Pollard is interested in lucky tickets (ticket is a sequence of digits). At first he thought that a ticket is lucky if between some its digits we can add arithmetic signs and brackets so that the result obtained by the arithmetic expression was number 100. But he quickly analyzed all such tickets and moved on to a more general question. Now he explores *k*-lucky tickets.
Pollard sais that a ticket is *k*-lucky if we can add arithmetic operation signs between its digits to the left or right of them (i.e., "+", "-", "<=×<=") and brackets so as to obtain the correct arithmetic expression whose value would equal *k*. For example, ticket "224201016" is 1000-lucky as (<=-<=2<=-<=(2<=+<=4))<=×<=(2<=+<=0)<=+<=1016<==<=1000.
Pollard was so carried away by the lucky tickets that he signed up for a seminar on lucky tickets and, as far as Gerald knows, Pollard will attend it daily at 7 pm in some famous institute and will commute to it in the same tram for *m* days. In this tram tickets have eight digits. And Gerald wants to make a surprise for Pollard: each day Pollard will receive a tram *k*-lucky ticket. The conductor has already agreed to give Pollard certain tickets during all these *m* days and he only wants Gerald to tell him what kind of tickets to give out. In this regard, help Gerald pick exactly *m* distinct *k*-lucky tickets. | The single line contains two integers *k* and *m* (0<=≤<=*k*<=≤<=104, 1<=≤<=*m*<=≤<=3·105). | Print *m* lines. Each line must contain exactly 8 digits — the *k*-winning ticket. The tickets may begin with 0, all tickets must be distinct. If there are more than *m* distinct *k*-lucky tickets, print any *m* of them. It is guaranteed that at least *m* distinct *k*-lucky tickets exist. The tickets can be printed in any order. | [
"0 3\n",
"7 4\n"
] | [
"00000000\n00000001\n00000002\n",
"00000007\n00000016\n00000017\n00000018\n"
] | none | 1,500 | [
{
"input": "0 3",
"output": "00000000\n00000001\n00000002"
},
{
"input": "7 4",
"output": "00000007\n00000016\n00000017\n00000018"
},
{
"input": "0 10000",
"output": "00000000\n00000001\n00000002\n00000003\n00000004\n00000005\n00000006\n00000007\n00000008\n00000009\n00000010\n00000011\n00000012\n00000013\n00000014\n00000015\n00000016\n00000017\n00000018\n00000019\n00000020\n00000021\n00000022\n00000023\n00000024\n00000025\n00000026\n00000027\n00000028\n00000029\n00000030\n00000031\n00000032\n00000033\n00000034\n00000035\n00000036\n00000037\n00000038\n00000039\n00000040\n00000041\n00000042\n00000043\n00000044\n00000045\n00000046\n00000047\n00000048\n00000049\n00000050\n0..."
},
{
"input": "1 10000",
"output": "00000001\n00000010\n00000011\n00000012\n00000021\n00000023\n00000031\n00000032\n00000034\n00000041\n00000043\n00000045\n00000051\n00000054\n00000056\n00000061\n00000065\n00000067\n00000071\n00000076\n00000078\n00000081\n00000087\n00000089\n00000091\n00000098\n00000100\n00000101\n00000102\n00000103\n00000104\n00000105\n00000106\n00000107\n00000108\n00000109\n00000110\n00000111\n00000112\n00000113\n00000120\n00000121\n00000122\n00000123\n00000124\n00000130\n00000131\n00000132\n00000133\n00000134\n00000135\n0..."
},
{
"input": "9999 10000",
"output": "00009999\n00019999\n00019998\n00029999\n00029997\n00039999\n00039996\n00033333\n00049999\n00049995\n00059999\n00059994\n00069999\n00069993\n00079999\n00079992\n00089999\n00089991\n00099999\n00099990\n00091111\n00109999\n00109998\n00109989\n00119999\n00119998\n00119997\n00119988\n00110909\n00111019\n00111908\n00111909\n00111910\n00112907\n00112911\n00112999\n00113033\n00113303\n00113906\n00113912\n00113989\n00114905\n00114913\n00114979\n00115904\n00115914\n00115969\n00116903\n00116915\n00116959\n00117902\n0..."
},
{
"input": "9998 10000",
"output": "00009998\n00019999\n00019998\n00019997\n00029998\n00029996\n00024999\n00039998\n00039995\n00049998\n00049994\n00059998\n00059993\n00069998\n00069992\n00079998\n00079991\n00089998\n00089990\n00099998\n00099989\n00109999\n00109998\n00109997\n00109988\n00119999\n00119998\n00119997\n00119996\n00114999\n00119987\n00129999\n00129998\n00129997\n00129996\n00124999\n00129995\n00129986\n00139998\n00139996\n00134999\n00139995\n00139994\n00139985\n00149998\n00149995\n00149994\n00149993\n00149984\n00159998\n00159994\n0..."
},
{
"input": "9997 10000",
"output": "00009997\n00019998\n00019997\n00019996\n00029999\n00029997\n00029995\n00039997\n00039994\n00049997\n00049993\n00059997\n00059992\n00069997\n00069991\n00079997\n00079990\n00089997\n00089989\n00099997\n00099988\n00109998\n00109997\n00109996\n00109987\n00119999\n00119998\n00119997\n00119996\n00119995\n00119986\n00129999\n00129998\n00129997\n00129996\n00129995\n00129994\n00129985\n00139999\n00139997\n00139995\n00139994\n00139993\n00139984\n00130769\n00131768\n00131769\n00131770\n00131896\n00131968\n00132767\n0..."
},
{
"input": "9973 10000",
"output": "00009973\n00019974\n00019973\n00019972\n00029975\n00029973\n00029971\n00039976\n00039973\n00039970\n00049977\n00049973\n00049969\n00059978\n00059973\n00059968\n00069979\n00069973\n00069967\n00079980\n00079973\n00079966\n00089981\n00089973\n00089965\n00099982\n00099973\n00099964\n00109974\n00109973\n00109972\n00109963\n00119975\n00119974\n00119973\n00119972\n00119971\n00119962\n00129976\n00129975\n00129974\n00129973\n00129972\n00129971\n00129970\n00129961\n00139977\n00139976\n00139975\n00139973\n00139971\n0..."
},
{
"input": "0 300000",
"output": "00000000\n00000001\n00000002\n00000003\n00000004\n00000005\n00000006\n00000007\n00000008\n00000009\n00000010\n00000011\n00000012\n00000013\n00000014\n00000015\n00000016\n00000017\n00000018\n00000019\n00000020\n00000021\n00000022\n00000023\n00000024\n00000025\n00000026\n00000027\n00000028\n00000029\n00000030\n00000031\n00000032\n00000033\n00000034\n00000035\n00000036\n00000037\n00000038\n00000039\n00000040\n00000041\n00000042\n00000043\n00000044\n00000045\n00000046\n00000047\n00000048\n00000049\n00000050\n0..."
},
{
"input": "1 300000",
"output": "00000001\n00000010\n00000011\n00000012\n00000021\n00000023\n00000031\n00000032\n00000034\n00000041\n00000043\n00000045\n00000051\n00000054\n00000056\n00000061\n00000065\n00000067\n00000071\n00000076\n00000078\n00000081\n00000087\n00000089\n00000091\n00000098\n00000100\n00000101\n00000102\n00000103\n00000104\n00000105\n00000106\n00000107\n00000108\n00000109\n00000110\n00000111\n00000112\n00000113\n00000120\n00000121\n00000122\n00000123\n00000124\n00000130\n00000131\n00000132\n00000133\n00000134\n00000135\n0..."
},
{
"input": "10000 300000",
"output": "00019999\n00029998\n00025000\n00026258\n00028625\n00039997\n00049996\n00042500\n00044625\n00045005\n00045050\n00045500\n00046254\n00059995\n00052000\n00052508\n00052580\n00054005\n00054050\n00054500\n00055004\n00055040\n00055058\n00055085\n00055400\n00055508\n00055580\n00055805\n00055850\n00058025\n00058055\n00058250\n00058505\n00058550\n00069994\n00079993\n00089992\n00081250\n00082505\n00082550\n00082625\n00085025\n00085055\n00085250\n00085505\n00085550\n00086252\n00099991\n00109999\n00109990\n00101000\n0..."
},
{
"input": "9999 300000",
"output": "00009999\n00019999\n00019998\n00029999\n00029997\n00039999\n00039996\n00033333\n00049999\n00049995\n00059999\n00059994\n00069999\n00069993\n00079999\n00079992\n00089999\n00089991\n00099999\n00099990\n00091111\n00109999\n00109998\n00109989\n00119999\n00119998\n00119997\n00119988\n00110909\n00111019\n00111908\n00111909\n00111910\n00112907\n00112911\n00112999\n00113033\n00113303\n00113906\n00113912\n00113989\n00114905\n00114913\n00114979\n00115904\n00115914\n00115969\n00116903\n00116915\n00116959\n00117902\n0..."
},
{
"input": "9973 300000",
"output": "00009973\n00019974\n00019973\n00019972\n00029975\n00029973\n00029971\n00039976\n00039973\n00039970\n00049977\n00049973\n00049969\n00059978\n00059973\n00059968\n00069979\n00069973\n00069967\n00079980\n00079973\n00079966\n00089981\n00089973\n00089965\n00099982\n00099973\n00099964\n00109974\n00109973\n00109972\n00109963\n00119975\n00119974\n00119973\n00119972\n00119971\n00119962\n00129976\n00129975\n00129974\n00129973\n00129972\n00129971\n00129970\n00129961\n00139977\n00139976\n00139975\n00139973\n00139971\n0..."
},
{
"input": "9998 300000",
"output": "00009998\n00019999\n00019998\n00019997\n00029998\n00029996\n00024999\n00039998\n00039995\n00049998\n00049994\n00059998\n00059993\n00069998\n00069992\n00079998\n00079991\n00089998\n00089990\n00099998\n00099989\n00109999\n00109998\n00109997\n00109988\n00119999\n00119998\n00119997\n00119996\n00114999\n00119987\n00129999\n00129998\n00129997\n00129996\n00124999\n00129995\n00129986\n00139998\n00139996\n00134999\n00139995\n00139994\n00139985\n00149998\n00149995\n00149994\n00149993\n00149984\n00159998\n00159994\n0..."
},
{
"input": "2 10000",
"output": "00000002\n00000011\n00000012\n00000013\n00000020\n00000021\n00000022\n00000024\n00000031\n00000032\n00000035\n00000042\n00000046\n00000052\n00000053\n00000057\n00000062\n00000064\n00000068\n00000072\n00000075\n00000079\n00000082\n00000086\n00000092\n00000097\n00000101\n00000102\n00000103\n00000108\n00000110\n00000111\n00000112\n00000113\n00000114\n00000119\n00000120\n00000121\n00000122\n00000123\n00000124\n00000125\n00000130\n00000131\n00000132\n00000134\n00000135\n00000136\n00000141\n00000142\n00000143\n0..."
},
{
"input": "3 10000",
"output": "00000003\n00000012\n00000013\n00000014\n00000021\n00000023\n00000025\n00000030\n00000031\n00000033\n00000036\n00000041\n00000043\n00000047\n00000052\n00000053\n00000058\n00000063\n00000069\n00000073\n00000074\n00000083\n00000085\n00000093\n00000096\n00000102\n00000103\n00000104\n00000107\n00000111\n00000112\n00000113\n00000114\n00000115\n00000118\n00000120\n00000121\n00000122\n00000123\n00000124\n00000125\n00000126\n00000129\n00000130\n00000131\n00000133\n00000135\n00000136\n00000137\n00000140\n00000141\n0..."
},
{
"input": "4 10000",
"output": "00000004\n00000013\n00000014\n00000015\n00000022\n00000024\n00000026\n00000031\n00000034\n00000037\n00000040\n00000041\n00000044\n00000048\n00000051\n00000054\n00000059\n00000062\n00000064\n00000073\n00000074\n00000084\n00000094\n00000095\n00000103\n00000104\n00000105\n00000106\n00000112\n00000113\n00000114\n00000115\n00000116\n00000117\n00000121\n00000122\n00000123\n00000124\n00000125\n00000126\n00000127\n00000128\n00000130\n00000131\n00000132\n00000134\n00000136\n00000137\n00000138\n00000139\n00000140\n0..."
},
{
"input": "5 10000",
"output": "00000005\n00000014\n00000015\n00000016\n00000023\n00000025\n00000027\n00000032\n00000035\n00000038\n00000041\n00000045\n00000049\n00000050\n00000051\n00000055\n00000061\n00000065\n00000072\n00000075\n00000083\n00000085\n00000094\n00000095\n00000104\n00000105\n00000106\n00000113\n00000114\n00000115\n00000116\n00000117\n00000122\n00000123\n00000124\n00000125\n00000126\n00000127\n00000128\n00000131\n00000132\n00000133\n00000135\n00000137\n00000138\n00000139\n00000140\n00000141\n00000142\n00000145\n00000148\n0..."
},
{
"input": "7 10000",
"output": "00000007\n00000016\n00000017\n00000018\n00000025\n00000027\n00000029\n00000034\n00000037\n00000043\n00000047\n00000052\n00000057\n00000061\n00000067\n00000070\n00000071\n00000077\n00000081\n00000087\n00000092\n00000097\n00000103\n00000106\n00000107\n00000108\n00000114\n00000115\n00000116\n00000117\n00000118\n00000119\n00000123\n00000124\n00000125\n00000126\n00000127\n00000128\n00000129\n00000132\n00000133\n00000134\n00000135\n00000136\n00000137\n00000139\n00000142\n00000143\n00000144\n00000147\n00000151\n0..."
},
{
"input": "14 10000",
"output": "00000014\n00000027\n00000059\n00000068\n00000072\n00000077\n00000086\n00000095\n00000104\n00000113\n00000114\n00000115\n00000117\n00000122\n00000127\n00000131\n00000135\n00000137\n00000140\n00000141\n00000149\n00000151\n00000153\n00000158\n00000159\n00000162\n00000167\n00000168\n00000169\n00000172\n00000173\n00000176\n00000177\n00000178\n00000182\n00000184\n00000185\n00000186\n00000187\n00000194\n00000195\n00000196\n00000206\n00000207\n00000212\n00000214\n00000216\n00000217\n00000218\n00000225\n00000226\n0..."
},
{
"input": "9996 10000",
"output": "00009996\n00019997\n00019996\n00019995\n00029998\n00029996\n00029994\n00024998\n00025198\n00026833\n00027147\n00027714\n00028336\n00029851\n00039999\n00039996\n00039993\n00033332\n00033498\n00034767\n00034833\n00034968\n00036849\n00036877\n00037476\n00037687\n00037768\n00038334\n00039834\n00049996\n00049992\n00042499\n00043577\n00043833\n00044951\n00045149\n00045177\n00047357\n00047517\n00047751\n00048333\n00059996\n00059991\n00069996\n00069990\n00061666\n00061798\n00062387\n00062833\n00063449\n00063477\n0..."
},
{
"input": "10 10000",
"output": "00000010\n00000019\n00000025\n00000028\n00000037\n00000046\n00000052\n00000055\n00000064\n00000073\n00000082\n00000091\n00000100\n00000101\n00000109\n00000110\n00000111\n00000115\n00000118\n00000119\n00000122\n00000125\n00000127\n00000128\n00000129\n00000133\n00000135\n00000136\n00000137\n00000138\n00000142\n00000144\n00000145\n00000146\n00000147\n00000152\n00000154\n00000155\n00000156\n00000162\n00000163\n00000164\n00000165\n00000166\n00000172\n00000173\n00000174\n00000177\n00000181\n00000182\n00000183\n0..."
},
{
"input": "256 10000",
"output": "00000256\n00000328\n00000464\n00000488\n00000644\n00000832\n00000848\n00000884\n00001255\n00001256\n00001257\n00001282\n00001318\n00001328\n00001338\n00001364\n00001385\n00001388\n00001464\n00001488\n00001515\n00001551\n00001564\n00001588\n00001616\n00001628\n00001634\n00001644\n00001654\n00001679\n00001682\n00001688\n00001697\n00001732\n00001748\n00001784\n00001794\n00001832\n00001848\n00001853\n00001884\n00001932\n00001948\n00001974\n00001984\n00002128\n00002168\n00002254\n00002258\n00002264\n00002288\n0..."
},
{
"input": "9240 10000",
"output": "00009240\n00019241\n00019240\n00019239\n00029242\n00029240\n00029238\n00024620\n00025584\n00025924\n00026077\n00026607\n00026670\n00026770\n00027066\n00027660\n00027706\n00027760\n00028455\n00029245\n00039243\n00039240\n00039237\n00033080\n00033588\n00033858\n00034077\n00034407\n00034470\n00034770\n00035556\n00035578\n00035587\n00035616\n00035655\n00035778\n00035788\n00035877\n00035887\n00036165\n00037044\n00037440\n00037558\n00037588\n00037704\n00037740\n00037758\n00037785\n00037855\n00037885\n00038385\n0..."
},
{
"input": "7560 10000",
"output": "00007560\n00008409\n00008490\n00008945\n00009084\n00009458\n00009840\n00017561\n00017560\n00018409\n00018490\n00018945\n00019084\n00019458\n00019840\n00017559\n00027562\n00027560\n00028409\n00028490\n00028945\n00029084\n00029458\n00029840\n00027558\n00023780\n00024209\n00024290\n00024584\n00024945\n00025407\n00025470\n00025756\n00025849\n00025984\n00026063\n00026079\n00026097\n00026306\n00026360\n00026630\n00026709\n00026790\n00026907\n00026970\n00027054\n00027069\n00027096\n00027540\n00027565\n00027609\n0..."
},
{
"input": "13 10000",
"output": "00000013\n00000049\n00000058\n00000067\n00000076\n00000085\n00000094\n00000103\n00000112\n00000113\n00000114\n00000121\n00000126\n00000127\n00000130\n00000131\n00000134\n00000139\n00000141\n00000143\n00000148\n00000149\n00000152\n00000157\n00000158\n00000159\n00000162\n00000163\n00000166\n00000167\n00000168\n00000172\n00000174\n00000175\n00000176\n00000177\n00000184\n00000185\n00000186\n00000193\n00000194\n00000195\n00000196\n00000207\n00000211\n00000213\n00000215\n00000218\n00000229\n00000235\n00000237\n0..."
},
{
"input": "9949 10000",
"output": "00009949\n00019950\n00019949\n00019948\n00029951\n00029949\n00029947\n00039952\n00039949\n00039946\n00049953\n00049949\n00049945\n00059954\n00059949\n00059944\n00069955\n00069949\n00069943\n00079956\n00079949\n00079942\n00089957\n00089949\n00089941\n00099958\n00099949\n00099940\n00109950\n00109949\n00109948\n00109939\n00119951\n00119950\n00119949\n00119948\n00119947\n00119938\n00129952\n00129951\n00129950\n00129949\n00129948\n00129947\n00129946\n00129937\n00139953\n00139952\n00139951\n00139949\n00139947\n0..."
},
{
"input": "9901 10000",
"output": "00009901\n00019902\n00019901\n00019900\n00029903\n00029901\n00029899\n00039904\n00039901\n00039898\n00049905\n00049901\n00049897\n00059906\n00059901\n00059896\n00069907\n00069901\n00069895\n00079908\n00079901\n00079894\n00089909\n00089901\n00089893\n00099910\n00099901\n00099892\n00109902\n00109901\n00109900\n00109891\n00119903\n00119902\n00119901\n00119900\n00119899\n00119890\n00129904\n00129903\n00129902\n00129901\n00129900\n00129899\n00129898\n00129889\n00139905\n00139904\n00139903\n00139901\n00139899\n0..."
},
{
"input": "0 1",
"output": "00000000"
},
{
"input": "10000 1",
"output": "00019999"
},
{
"input": "10000 10000",
"output": "00019999\n00029998\n00025000\n00026258\n00028625\n00039997\n00049996\n00042500\n00044625\n00045005\n00045050\n00045500\n00046254\n00059995\n00052000\n00052508\n00052580\n00054005\n00054050\n00054500\n00055004\n00055040\n00055058\n00055085\n00055400\n00055508\n00055580\n00055805\n00055850\n00058025\n00058055\n00058250\n00058505\n00058550\n00069994\n00079993\n00089992\n00081250\n00082505\n00082550\n00082625\n00085025\n00085055\n00085250\n00085505\n00085550\n00086252\n00099991\n00109999\n00109990\n00101000\n0..."
},
{
"input": "1234 123",
"output": "00001234\n00002617\n00006172\n00011235\n00011395\n00011965\n00012475\n00014995\n00015247\n00015895\n00016519\n00016795\n00017695\n00018595\n00019495\n00019513\n00019549\n00019558\n00019567\n00019576\n00019585\n00019594\n00011234\n00012617\n00016172\n00011233\n00011379\n00013411\n00014113\n00019137\n00021236\n00022066\n00022618\n00023094\n00023412\n00024123\n00024309\n00026182\n00026206\n00021234\n00022617\n00026172\n00021232\n00021488\n00021548\n00021677\n00021767\n00022256\n00022278\n00022287\n00022616\n0..."
}
] | 1,375,361,878 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 3 | 998 | 614,400 | n, m = map(int, input().split())
op = ['+', '-', '*']
digit = ['#' for i in range(0, 8)]
operator = ['#' for i in range(0, 7)]
used = []
ret = []
okConf = False
def check(s):
global n
global used
news = []
for character in s:
if character in '+-*': news.append(character)
else:
if len(news) > 0 and news[-1] == '*':
news.pop()
a = int(news[-1])
b = int(character)
news.pop()
news.append(str(a*b))
else: news.append(character)
sol = int(news[0])
for i in range(1, len(news), 2):
if news[i] == '-': sol -= int(news[i+1])
else: sol += int(news[i+1])
if n == 0 or (sol != 0 and sol % n == 0):
return True
return False
def putTogether(a, b):
s = ''
for i in range(0, len(b)): s += a[i] + b[i]
s += a[-1]
return s
def backOperators(k):
global m, okConf, op
if okConf: return
for i in op:
operator[k] = i
if k == 6:
if check(putTogether(digit, operator)):
okConf = True
return
else: backOperators(k+1)
def backDigits(k):
global m, okConf, ret
if len(ret) == m: return
for i in range(0, 10):
digit[k] = chr(i+48)
if k == 7 :
okConf = False
backOperators(0)
if okConf and len(ret) < m: ret.append(''.join(digit))
else: backDigits(k+1)
def main():
backDigits(0)
print('\n'.join(ret))
if __name__ == '__main__':
main()
| Title: Lucky Tickets
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Gerald has a friend, Pollard. Pollard is interested in lucky tickets (ticket is a sequence of digits). At first he thought that a ticket is lucky if between some its digits we can add arithmetic signs and brackets so that the result obtained by the arithmetic expression was number 100. But he quickly analyzed all such tickets and moved on to a more general question. Now he explores *k*-lucky tickets.
Pollard sais that a ticket is *k*-lucky if we can add arithmetic operation signs between its digits to the left or right of them (i.e., "+", "-", "<=×<=") and brackets so as to obtain the correct arithmetic expression whose value would equal *k*. For example, ticket "224201016" is 1000-lucky as (<=-<=2<=-<=(2<=+<=4))<=×<=(2<=+<=0)<=+<=1016<==<=1000.
Pollard was so carried away by the lucky tickets that he signed up for a seminar on lucky tickets and, as far as Gerald knows, Pollard will attend it daily at 7 pm in some famous institute and will commute to it in the same tram for *m* days. In this tram tickets have eight digits. And Gerald wants to make a surprise for Pollard: each day Pollard will receive a tram *k*-lucky ticket. The conductor has already agreed to give Pollard certain tickets during all these *m* days and he only wants Gerald to tell him what kind of tickets to give out. In this regard, help Gerald pick exactly *m* distinct *k*-lucky tickets.
Input Specification:
The single line contains two integers *k* and *m* (0<=≤<=*k*<=≤<=104, 1<=≤<=*m*<=≤<=3·105).
Output Specification:
Print *m* lines. Each line must contain exactly 8 digits — the *k*-winning ticket. The tickets may begin with 0, all tickets must be distinct. If there are more than *m* distinct *k*-lucky tickets, print any *m* of them. It is guaranteed that at least *m* distinct *k*-lucky tickets exist. The tickets can be printed in any order.
Demo Input:
['0 3\n', '7 4\n']
Demo Output:
['00000000\n00000001\n00000002\n', '00000007\n00000016\n00000017\n00000018\n']
Note:
none | ```python
n, m = map(int, input().split())
op = ['+', '-', '*']
digit = ['#' for i in range(0, 8)]
operator = ['#' for i in range(0, 7)]
used = []
ret = []
okConf = False
def check(s):
global n
global used
news = []
for character in s:
if character in '+-*': news.append(character)
else:
if len(news) > 0 and news[-1] == '*':
news.pop()
a = int(news[-1])
b = int(character)
news.pop()
news.append(str(a*b))
else: news.append(character)
sol = int(news[0])
for i in range(1, len(news), 2):
if news[i] == '-': sol -= int(news[i+1])
else: sol += int(news[i+1])
if n == 0 or (sol != 0 and sol % n == 0):
return True
return False
def putTogether(a, b):
s = ''
for i in range(0, len(b)): s += a[i] + b[i]
s += a[-1]
return s
def backOperators(k):
global m, okConf, op
if okConf: return
for i in op:
operator[k] = i
if k == 6:
if check(putTogether(digit, operator)):
okConf = True
return
else: backOperators(k+1)
def backDigits(k):
global m, okConf, ret
if len(ret) == m: return
for i in range(0, 10):
digit[k] = chr(i+48)
if k == 7 :
okConf = False
backOperators(0)
if okConf and len(ret) < m: ret.append(''.join(digit))
else: backDigits(k+1)
def main():
backDigits(0)
print('\n'.join(ret))
if __name__ == '__main__':
main()
``` | 0 |
|
289 | A | Polo the Penguin and Segments | PROGRAMMING | 1,100 | [
"brute force",
"implementation"
] | null | null | Little penguin Polo adores integer segments, that is, pairs of integers [*l*; *r*] (*l*<=≤<=*r*).
He has a set that consists of *n* integer segments: [*l*1; *r*1],<=[*l*2; *r*2],<=...,<=[*l**n*; *r**n*]. We know that no two segments of this set intersect. In one move Polo can either widen any segment of the set 1 unit to the left or 1 unit to the right, that is transform [*l*; *r*] to either segment [*l*<=-<=1; *r*], or to segment [*l*; *r*<=+<=1].
The value of a set of segments that consists of *n* segments [*l*1; *r*1],<=[*l*2; *r*2],<=...,<=[*l**n*; *r**n*] is the number of integers *x*, such that there is integer *j*, for which the following inequality holds, *l**j*<=≤<=*x*<=≤<=*r**j*.
Find the minimum number of moves needed to make the value of the set of Polo's segments divisible by *k*. | The first line contains two integers *n* and *k* (1<=≤<=*n*,<=*k*<=≤<=105). Each of the following *n* lines contain a segment as a pair of integers *l**i* and *r**i* (<=-<=105<=≤<=*l**i*<=≤<=*r**i*<=≤<=105), separated by a space.
It is guaranteed that no two segments intersect. In other words, for any two integers *i*,<=*j* (1<=≤<=*i*<=<<=*j*<=≤<=*n*) the following inequality holds, *min*(*r**i*,<=*r**j*)<=<<=*max*(*l**i*,<=*l**j*). | In a single line print a single integer — the answer to the problem. | [
"2 3\n1 2\n3 4\n",
"3 7\n1 2\n3 3\n4 7\n"
] | [
"2\n",
"0\n"
] | none | 500 | [
{
"input": "2 3\n1 2\n3 4",
"output": "2"
},
{
"input": "3 7\n1 2\n3 3\n4 7",
"output": "0"
},
{
"input": "3 7\n1 10\n11 47\n74 128",
"output": "3"
},
{
"input": "5 4\n1 1\n2 2\n3 3\n4 4\n5 5",
"output": "3"
},
{
"input": "7 4\n2 2\n-1 -1\n0 1\n7 8\n-3 -2\n9 9\n4 6",
"output": "0"
},
{
"input": "10 2\n92 92\n55 59\n70 73\n78 81\n62 65\n95 99\n74 75\n85 87\n51 51\n60 60",
"output": "0"
},
{
"input": "10 474\n56 60\n82 82\n73 73\n105 109\n77 80\n51 51\n85 88\n97 100\n91 92\n64 68",
"output": "442"
},
{
"input": "47 21\n3 5\n-422 -417\n60 60\n-348 -348\n-3 -3\n-364 -361\n-49 -41\n-436 -430\n-250 -244\n-33 -26\n-162 -158\n-90 -88\n-357 -352\n-339 -337\n-25 -19\n-69 -67\n-261 -260\n-292 -283\n12 18\n44 44\n-277 -275\n-301 -293\n-108 -98\n-180 -172\n-327 -318\n-314 -309\n-12 -7\n-134 -130\n33 35\n-190 -184\n-65 -55\n-242 -240\n-448 -444\n-408 -405\n53 57\n-145 -144\n-207 -200\n-110 -110\n-221 -216\n-122 -112\n26 27\n-271 -269\n-82 -79\n-235 -229\n-382 -373\n-397 -391\n-155 -153",
"output": "18"
},
{
"input": "3 4587\n-49 368\n-734 -390\n-380 -117",
"output": "3560"
},
{
"input": "1 100000\n-100000 100000",
"output": "99999"
},
{
"input": "2 100000\n-100000 99999\n100000 100000",
"output": "99999"
},
{
"input": "1 7\n0 0",
"output": "6"
},
{
"input": "2 5848\n-100000 0\n1 100000",
"output": "4679"
},
{
"input": "3 99999\n-100000 -100000\n-99999 99998\n99999 100000",
"output": "99996"
}
] | 1,601,277,533 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 154 | 0 | n , k = map(int,input().split())
s = 0
for _ in range(n):
l , r = map(int,input().split())
s +=r-l+1
if s < k:
print(k-s)
if s >=k:
s = s%k
print(s)
| Title: Polo the Penguin and Segments
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Little penguin Polo adores integer segments, that is, pairs of integers [*l*; *r*] (*l*<=≤<=*r*).
He has a set that consists of *n* integer segments: [*l*1; *r*1],<=[*l*2; *r*2],<=...,<=[*l**n*; *r**n*]. We know that no two segments of this set intersect. In one move Polo can either widen any segment of the set 1 unit to the left or 1 unit to the right, that is transform [*l*; *r*] to either segment [*l*<=-<=1; *r*], or to segment [*l*; *r*<=+<=1].
The value of a set of segments that consists of *n* segments [*l*1; *r*1],<=[*l*2; *r*2],<=...,<=[*l**n*; *r**n*] is the number of integers *x*, such that there is integer *j*, for which the following inequality holds, *l**j*<=≤<=*x*<=≤<=*r**j*.
Find the minimum number of moves needed to make the value of the set of Polo's segments divisible by *k*.
Input Specification:
The first line contains two integers *n* and *k* (1<=≤<=*n*,<=*k*<=≤<=105). Each of the following *n* lines contain a segment as a pair of integers *l**i* and *r**i* (<=-<=105<=≤<=*l**i*<=≤<=*r**i*<=≤<=105), separated by a space.
It is guaranteed that no two segments intersect. In other words, for any two integers *i*,<=*j* (1<=≤<=*i*<=<<=*j*<=≤<=*n*) the following inequality holds, *min*(*r**i*,<=*r**j*)<=<<=*max*(*l**i*,<=*l**j*).
Output Specification:
In a single line print a single integer — the answer to the problem.
Demo Input:
['2 3\n1 2\n3 4\n', '3 7\n1 2\n3 3\n4 7\n']
Demo Output:
['2\n', '0\n']
Note:
none | ```python
n , k = map(int,input().split())
s = 0
for _ in range(n):
l , r = map(int,input().split())
s +=r-l+1
if s < k:
print(k-s)
if s >=k:
s = s%k
print(s)
``` | 0 |
|
441 | B | Valera and Fruits | PROGRAMMING | 1,400 | [
"greedy",
"implementation"
] | null | null | Valera loves his garden, where *n* fruit trees grow.
This year he will enjoy a great harvest! On the *i*-th tree *b**i* fruit grow, they will ripen on a day number *a**i*. Unfortunately, the fruit on the tree get withered, so they can only be collected on day *a**i* and day *a**i*<=+<=1 (all fruits that are not collected in these two days, become unfit to eat).
Valera is not very fast, but there are some positive points. Valera is ready to work every day. In one day, Valera can collect no more than *v* fruits. The fruits may be either from the same tree, or from different ones. What is the maximum amount of fruit Valera can collect for all time, if he operates optimally well? | The first line contains two space-separated integers *n* and *v* (1<=≤<=*n*,<=*v*<=≤<=3000) — the number of fruit trees in the garden and the number of fruits that Valera can collect in a day.
Next *n* lines contain the description of trees in the garden. The *i*-th line contains two space-separated integers *a**i* and *b**i* (1<=≤<=*a**i*,<=*b**i*<=≤<=3000) — the day the fruits ripen on the *i*-th tree and the number of fruits on the *i*-th tree. | Print a single integer — the maximum number of fruit that Valera can collect. | [
"2 3\n1 5\n2 3\n",
"5 10\n3 20\n2 20\n1 20\n4 20\n5 20\n"
] | [
"8\n",
"60\n"
] | In the first sample, in order to obtain the optimal answer, you should act as follows.
- On the first day collect 3 fruits from the 1-st tree. - On the second day collect 1 fruit from the 2-nd tree and 2 fruits from the 1-st tree. - On the third day collect the remaining fruits from the 2-nd tree.
In the second sample, you can only collect 60 fruits, the remaining fruit will simply wither. | 1,000 | [
{
"input": "2 3\n1 5\n2 3",
"output": "8"
},
{
"input": "5 10\n3 20\n2 20\n1 20\n4 20\n5 20",
"output": "60"
},
{
"input": "10 3000\n1 2522\n4 445\n8 1629\n5 772\n9 2497\n6 81\n3 426\n7 1447\n2 575\n10 202",
"output": "10596"
},
{
"input": "5 3000\n5 772\n1 2522\n2 575\n4 445\n3 426",
"output": "4740"
},
{
"input": "2 1500\n2 575\n1 2522",
"output": "3097"
},
{
"input": "12 2856\n9 2728\n8 417\n3 1857\n10 1932\n1 775\n12 982\n9 1447\n1 426\n7 2918\n11 2522\n10 2497\n9 772",
"output": "18465"
},
{
"input": "24 1524\n16 934\n23 1940\n21 1447\n20 417\n24 1340\n22 1932\n13 775\n19 2918\n12 2355\n9 593\n11 2676\n3 1857\n16 868\n13 426\n18 1679\n22 991\n9 2728\n10 2497\n16 1221\n9 772\n23 2522\n24 982\n12 1431\n18 757",
"output": "25893"
},
{
"input": "1 10\n3000 30",
"output": "20"
},
{
"input": "2 1\n30 3\n31 2",
"output": "3"
},
{
"input": "4 2061\n1 426\n3 2522\n1 772\n1 1447",
"output": "5167"
},
{
"input": "2 1\n1 1\n1 1",
"output": "2"
},
{
"input": "1 10\n3000 20",
"output": "20"
},
{
"input": "1 1000\n3000 2000",
"output": "2000"
},
{
"input": "2 100\n3000 100\n3000 100",
"output": "200"
},
{
"input": "2 3\n1 6\n3 6",
"output": "12"
},
{
"input": "1 40\n3000 42",
"output": "42"
},
{
"input": "1 100\n3000 200",
"output": "200"
},
{
"input": "1 50\n3000 100",
"output": "100"
},
{
"input": "1 1\n3000 2",
"output": "2"
},
{
"input": "2 3000\n3000 3000\n3000 3000",
"output": "6000"
},
{
"input": "2 2\n2999 3\n3000 2",
"output": "5"
},
{
"input": "1 2\n3000 3",
"output": "3"
},
{
"input": "2 5\n2999 10\n3000 5",
"output": "15"
},
{
"input": "1 3\n5 3",
"output": "3"
},
{
"input": "2 1000\n2999 2000\n3000 1000",
"output": "3000"
},
{
"input": "1 5\n3000 10",
"output": "10"
},
{
"input": "1 10\n3000 15",
"output": "15"
},
{
"input": "5 1\n10 100\n2698 100\n200 100\n3000 100\n1500 100",
"output": "10"
},
{
"input": "1 1\n3000 3000",
"output": "2"
},
{
"input": "2 10\n2999 100\n3000 100",
"output": "30"
},
{
"input": "1 10\n3000 100",
"output": "20"
}
] | 1,603,994,713 | 913 | PyPy 3 | OK | TESTS | 51 | 233 | 4,300,800 | n, v = [int(x) for x in input().split(' ')]
a_dict = {}
m = 0
p = 0
for tree in range(n):
a, b = [int(x) for x in input().split(' ')]
m = max(a, m)
if a in a_dict.keys():
a_dict[a] += b
else:
a_dict[a] = b
for day in range(m + 2):
if day not in a_dict.keys():
a_dict[day] = 0
for day in range(1, m + 2):
y = min(v, a_dict[day - 1])
a_dict[day - 1] -= y
z = min(v - y, a_dict[day])
a_dict[day] -= z
p += z + y
print(p) | Title: Valera and Fruits
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Valera loves his garden, where *n* fruit trees grow.
This year he will enjoy a great harvest! On the *i*-th tree *b**i* fruit grow, they will ripen on a day number *a**i*. Unfortunately, the fruit on the tree get withered, so they can only be collected on day *a**i* and day *a**i*<=+<=1 (all fruits that are not collected in these two days, become unfit to eat).
Valera is not very fast, but there are some positive points. Valera is ready to work every day. In one day, Valera can collect no more than *v* fruits. The fruits may be either from the same tree, or from different ones. What is the maximum amount of fruit Valera can collect for all time, if he operates optimally well?
Input Specification:
The first line contains two space-separated integers *n* and *v* (1<=≤<=*n*,<=*v*<=≤<=3000) — the number of fruit trees in the garden and the number of fruits that Valera can collect in a day.
Next *n* lines contain the description of trees in the garden. The *i*-th line contains two space-separated integers *a**i* and *b**i* (1<=≤<=*a**i*,<=*b**i*<=≤<=3000) — the day the fruits ripen on the *i*-th tree and the number of fruits on the *i*-th tree.
Output Specification:
Print a single integer — the maximum number of fruit that Valera can collect.
Demo Input:
['2 3\n1 5\n2 3\n', '5 10\n3 20\n2 20\n1 20\n4 20\n5 20\n']
Demo Output:
['8\n', '60\n']
Note:
In the first sample, in order to obtain the optimal answer, you should act as follows.
- On the first day collect 3 fruits from the 1-st tree. - On the second day collect 1 fruit from the 2-nd tree and 2 fruits from the 1-st tree. - On the third day collect the remaining fruits from the 2-nd tree.
In the second sample, you can only collect 60 fruits, the remaining fruit will simply wither. | ```python
n, v = [int(x) for x in input().split(' ')]
a_dict = {}
m = 0
p = 0
for tree in range(n):
a, b = [int(x) for x in input().split(' ')]
m = max(a, m)
if a in a_dict.keys():
a_dict[a] += b
else:
a_dict[a] = b
for day in range(m + 2):
if day not in a_dict.keys():
a_dict[day] = 0
for day in range(1, m + 2):
y = min(v, a_dict[day - 1])
a_dict[day - 1] -= y
z = min(v - y, a_dict[day])
a_dict[day] -= z
p += z + y
print(p)
``` | 3 |
|
555 | B | Case of Fugitive | PROGRAMMING | 2,000 | [
"data structures",
"greedy",
"sortings"
] | null | null | Andrewid the Android is a galaxy-famous detective. He is now chasing a criminal hiding on the planet Oxa-5, the planet almost fully covered with water.
The only dry land there is an archipelago of *n* narrow islands located in a row. For more comfort let's represent them as non-intersecting segments on a straight line: island *i* has coordinates [*l**i*,<=*r**i*], besides, *r**i*<=<<=*l**i*<=+<=1 for 1<=≤<=*i*<=≤<=*n*<=-<=1.
To reach the goal, Andrewid needs to place a bridge between each pair of adjacent islands. A bridge of length *a* can be placed between the *i*-th and the (*i*<=+<=1)-th islads, if there are such coordinates of *x* and *y*, that *l**i*<=≤<=*x*<=≤<=*r**i*, *l**i*<=+<=1<=≤<=*y*<=≤<=*r**i*<=+<=1 and *y*<=-<=*x*<==<=*a*.
The detective was supplied with *m* bridges, each bridge can be used at most once. Help him determine whether the bridges he got are enough to connect each pair of adjacent islands. | The first line contains integers *n* (2<=≤<=*n*<=≤<=2·105) and *m* (1<=≤<=*m*<=≤<=2·105) — the number of islands and bridges.
Next *n* lines each contain two integers *l**i* and *r**i* (1<=≤<=*l**i*<=≤<=*r**i*<=≤<=1018) — the coordinates of the island endpoints.
The last line contains *m* integer numbers *a*1,<=*a*2,<=...,<=*a**m* (1<=≤<=*a**i*<=≤<=1018) — the lengths of the bridges that Andrewid got. | If it is impossible to place a bridge between each pair of adjacent islands in the required manner, print on a single line "No" (without the quotes), otherwise print in the first line "Yes" (without the quotes), and in the second line print *n*<=-<=1 numbers *b*1,<=*b*2,<=...,<=*b**n*<=-<=1, which mean that between islands *i* and *i*<=+<=1 there must be used a bridge number *b**i*.
If there are multiple correct answers, print any of them. Note that in this problem it is necessary to print "Yes" and "No" in correct case. | [
"4 4\n1 4\n7 8\n9 10\n12 14\n4 5 3 8\n",
"2 2\n11 14\n17 18\n2 9\n",
"2 1\n1 1\n1000000000000000000 1000000000000000000\n999999999999999999\n"
] | [
"Yes\n2 3 1 \n",
"No\n",
"Yes\n1 \n"
] | In the first sample test you can, for example, place the second bridge between points 3 and 8, place the third bridge between points 7 and 10 and place the first bridge between points 10 and 14.
In the second sample test the first bridge is too short and the second bridge is too long, so the solution doesn't exist. | 750 | [
{
"input": "4 4\n1 4\n7 8\n9 10\n12 14\n4 5 3 8",
"output": "Yes\n2 3 1 "
},
{
"input": "2 2\n11 14\n17 18\n2 9",
"output": "No"
},
{
"input": "2 1\n1 1\n1000000000000000000 1000000000000000000\n999999999999999999",
"output": "Yes\n1 "
},
{
"input": "5 10\n1 2\n3 3\n5 7\n11 13\n14 20\n9 10 2 9 10 4 9 9 9 10",
"output": "No"
},
{
"input": "5 9\n1 2\n3 3\n5 7\n11 13\n14 20\n2 3 4 10 6 2 6 9 5",
"output": "Yes\n1 6 3 2 "
},
{
"input": "6 9\n1 4\n10 18\n23 29\n33 43\n46 57\n59 77\n11 32 32 19 20 17 32 24 32",
"output": "Yes\n1 6 4 5 8 "
},
{
"input": "6 9\n1 2\n8 16\n21 27\n31 46\n49 57\n59 78\n26 27 28 13 2 4 2 2 24",
"output": "No"
},
{
"input": "20 10\n4 9\n10 15\n17 18\n20 21\n25 27\n29 32\n35 36\n46 48\n49 51\n53 56\n59 60\n63 64\n65 68\n69 70\n74 75\n79 80\n81 82\n84 87\n88 91\n98 100\n4 7 6 1 5 4 3 1 5 2",
"output": "No"
},
{
"input": "2 1\n1 2\n5 6\n1",
"output": "No"
},
{
"input": "2 1\n1 1\n100 100\n5",
"output": "No"
},
{
"input": "3 2\n1000000000000000 1000000000000000\n3000000000000000 4000000000000000\n6000000000000000 7000000000000000\n2000000000000000 4000000000000000",
"output": "Yes\n1 2 "
},
{
"input": "3 2\n1 5\n6 12\n14 100000000000\n10000000000 4",
"output": "Yes\n2 1 "
}
] | 1,437,318,820 | 1,720 | Python 3 | COMPILATION_ERROR | TESTS | 0 | 0 | 0 | //Done by Ferran Alet
#include<bits/stdc++.h>
#define INF 2147483647
#define LINF 1000000000000000000LL
#define EPS 1e-9
#define debug(x) //cerr << #x << " = " << x << endl
#define Debug(v) //cerr << #v << " = "; for(ll wow=0;wow<v.size();++wow) //cerr<<v[wow]<<' '; //cerr<<endl
#define DEBUG(M) //cerr << #M <<":"<<endl; for(ll iM=0;iM<M.size();++iM) { for(ll jM=0;jM<M[iM].size();++jM) //cerr<<M[iM][jM]<<' '; //cerr<<endl;} //cerr<<endl
#define FOR(x,y) for(ll x=0;x<y;x++)
#define FORS(x,y) for(ll x=0;x<ll(y.size());++x)
#define FORU(x,y) for(ll x=1;x<=y;x++)
#define RFOR(x,y) for(ll x=y-1;x>=0;--x)
#define DRI(x) ll x; cin>>x
#define DRII(x,y) ll x,y; cin>>x>>y
#define DRIII(x,y,z) ll x,y,z; cin>>x>>y>>z
#define PB push_back
#define SZ(X) ((ll)(X).size())
#define ALL(X) (X).begin(), (X).end()
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> PII;
typedef vector<ll> VI;
typedef vector<VI> VVI;
typedef vector<double> VD;
typedef vector<VD> VVD;
typedef vector<bool> VB;
typedef vector<VB> VVB;
typedef vector<char> VC;
typedef vector<VC> VVC;
typedef vector<string> VS;
typedef map<ll,ll> MII;
typedef MII::iterator iMII;
typedef vector<PII > VP;
typedef vector<VP> VVP;
int main(){
ios_base::sync_with_stdio(false);
cin.tie(0);
// freopen(".out","w",stdout);
// freopen(".in","r",stdin);
ll n,m;
cin>>n>>m;
vector<PII> v(n);
FOR(i,n) cin>>v[i].first>>v[i].second;
vector<PII> b(m);
FOR(i,m) {
cin>>b[i].first;
b[i].second=i+1;
}
sort(b.begin(),b.end());
vector<pair<PII,ll> > diff(n-1);
FORU(i,n-1){
diff[i-1].first = PII(v[i].first-v[i-1].second,v[i].second-v[i-1].first);
diff[i-1].second = i;
}
sort(diff.begin(),diff.end());
vector<PII> ev;
FOR(i,diff.size()){
ev.push_back(PII(diff[i].first.first,diff[i].second));
//cerr<<"Introdueixo " << diff[i].first.first<<' '<<diff[i].second<<endl;
ev.push_back(PII(diff[i].first.second+1,-diff[i].second));
//cerr<<"Introdueixa " << diff[i].first.second+1<<' '<<diff[i].second<<endl;
}
FOR(i,m){
ev.push_back(PII(b[i].first,1000000+b[i].second));
}
sort(ev.begin(),ev.end());
bool result=true;
VI found(n);
priority_queue<PII> pq;
//cerr<<"Processo events"<<endl;
FOR(i,ev.size()){
//cerr<<i<<' ' <<ev[i].first<<' '<<ev[i].second<<endl;
if(ev[i].second<0){ //S'acaba
if(!found[-ev[i].second]){
result=false;
break;
}
}
else if(ev[i].second>=1000000){
ev[i].second-=1000000;
if(!pq.empty()){
PII x=pq.top();
pq.pop();
found[x.second]=ev[i].second;
}
}
else {
pq.push(PII(-ev[i].first,ev[i].second));
}
}
if(!result) cout<<"No"<<endl;
else{
cout<<"Yes"<<endl;
FORU(i,n-1) cout<<found[i]<<' ';
cout<<endl;
}
} | Title: Case of Fugitive
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Andrewid the Android is a galaxy-famous detective. He is now chasing a criminal hiding on the planet Oxa-5, the planet almost fully covered with water.
The only dry land there is an archipelago of *n* narrow islands located in a row. For more comfort let's represent them as non-intersecting segments on a straight line: island *i* has coordinates [*l**i*,<=*r**i*], besides, *r**i*<=<<=*l**i*<=+<=1 for 1<=≤<=*i*<=≤<=*n*<=-<=1.
To reach the goal, Andrewid needs to place a bridge between each pair of adjacent islands. A bridge of length *a* can be placed between the *i*-th and the (*i*<=+<=1)-th islads, if there are such coordinates of *x* and *y*, that *l**i*<=≤<=*x*<=≤<=*r**i*, *l**i*<=+<=1<=≤<=*y*<=≤<=*r**i*<=+<=1 and *y*<=-<=*x*<==<=*a*.
The detective was supplied with *m* bridges, each bridge can be used at most once. Help him determine whether the bridges he got are enough to connect each pair of adjacent islands.
Input Specification:
The first line contains integers *n* (2<=≤<=*n*<=≤<=2·105) and *m* (1<=≤<=*m*<=≤<=2·105) — the number of islands and bridges.
Next *n* lines each contain two integers *l**i* and *r**i* (1<=≤<=*l**i*<=≤<=*r**i*<=≤<=1018) — the coordinates of the island endpoints.
The last line contains *m* integer numbers *a*1,<=*a*2,<=...,<=*a**m* (1<=≤<=*a**i*<=≤<=1018) — the lengths of the bridges that Andrewid got.
Output Specification:
If it is impossible to place a bridge between each pair of adjacent islands in the required manner, print on a single line "No" (without the quotes), otherwise print in the first line "Yes" (without the quotes), and in the second line print *n*<=-<=1 numbers *b*1,<=*b*2,<=...,<=*b**n*<=-<=1, which mean that between islands *i* and *i*<=+<=1 there must be used a bridge number *b**i*.
If there are multiple correct answers, print any of them. Note that in this problem it is necessary to print "Yes" and "No" in correct case.
Demo Input:
['4 4\n1 4\n7 8\n9 10\n12 14\n4 5 3 8\n', '2 2\n11 14\n17 18\n2 9\n', '2 1\n1 1\n1000000000000000000 1000000000000000000\n999999999999999999\n']
Demo Output:
['Yes\n2 3 1 \n', 'No\n', 'Yes\n1 \n']
Note:
In the first sample test you can, for example, place the second bridge between points 3 and 8, place the third bridge between points 7 and 10 and place the first bridge between points 10 and 14.
In the second sample test the first bridge is too short and the second bridge is too long, so the solution doesn't exist. | ```python
//Done by Ferran Alet
#include<bits/stdc++.h>
#define INF 2147483647
#define LINF 1000000000000000000LL
#define EPS 1e-9
#define debug(x) //cerr << #x << " = " << x << endl
#define Debug(v) //cerr << #v << " = "; for(ll wow=0;wow<v.size();++wow) //cerr<<v[wow]<<' '; //cerr<<endl
#define DEBUG(M) //cerr << #M <<":"<<endl; for(ll iM=0;iM<M.size();++iM) { for(ll jM=0;jM<M[iM].size();++jM) //cerr<<M[iM][jM]<<' '; //cerr<<endl;} //cerr<<endl
#define FOR(x,y) for(ll x=0;x<y;x++)
#define FORS(x,y) for(ll x=0;x<ll(y.size());++x)
#define FORU(x,y) for(ll x=1;x<=y;x++)
#define RFOR(x,y) for(ll x=y-1;x>=0;--x)
#define DRI(x) ll x; cin>>x
#define DRII(x,y) ll x,y; cin>>x>>y
#define DRIII(x,y,z) ll x,y,z; cin>>x>>y>>z
#define PB push_back
#define SZ(X) ((ll)(X).size())
#define ALL(X) (X).begin(), (X).end()
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> PII;
typedef vector<ll> VI;
typedef vector<VI> VVI;
typedef vector<double> VD;
typedef vector<VD> VVD;
typedef vector<bool> VB;
typedef vector<VB> VVB;
typedef vector<char> VC;
typedef vector<VC> VVC;
typedef vector<string> VS;
typedef map<ll,ll> MII;
typedef MII::iterator iMII;
typedef vector<PII > VP;
typedef vector<VP> VVP;
int main(){
ios_base::sync_with_stdio(false);
cin.tie(0);
// freopen(".out","w",stdout);
// freopen(".in","r",stdin);
ll n,m;
cin>>n>>m;
vector<PII> v(n);
FOR(i,n) cin>>v[i].first>>v[i].second;
vector<PII> b(m);
FOR(i,m) {
cin>>b[i].first;
b[i].second=i+1;
}
sort(b.begin(),b.end());
vector<pair<PII,ll> > diff(n-1);
FORU(i,n-1){
diff[i-1].first = PII(v[i].first-v[i-1].second,v[i].second-v[i-1].first);
diff[i-1].second = i;
}
sort(diff.begin(),diff.end());
vector<PII> ev;
FOR(i,diff.size()){
ev.push_back(PII(diff[i].first.first,diff[i].second));
//cerr<<"Introdueixo " << diff[i].first.first<<' '<<diff[i].second<<endl;
ev.push_back(PII(diff[i].first.second+1,-diff[i].second));
//cerr<<"Introdueixa " << diff[i].first.second+1<<' '<<diff[i].second<<endl;
}
FOR(i,m){
ev.push_back(PII(b[i].first,1000000+b[i].second));
}
sort(ev.begin(),ev.end());
bool result=true;
VI found(n);
priority_queue<PII> pq;
//cerr<<"Processo events"<<endl;
FOR(i,ev.size()){
//cerr<<i<<' ' <<ev[i].first<<' '<<ev[i].second<<endl;
if(ev[i].second<0){ //S'acaba
if(!found[-ev[i].second]){
result=false;
break;
}
}
else if(ev[i].second>=1000000){
ev[i].second-=1000000;
if(!pq.empty()){
PII x=pq.top();
pq.pop();
found[x.second]=ev[i].second;
}
}
else {
pq.push(PII(-ev[i].first,ev[i].second));
}
}
if(!result) cout<<"No"<<endl;
else{
cout<<"Yes"<<endl;
FORU(i,n-1) cout<<found[i]<<' ';
cout<<endl;
}
}
``` | -1 |
|
841 | A | Generous Kefa | PROGRAMMING | 900 | [
"brute force",
"implementation"
] | null | null | One day Kefa found *n* baloons. For convenience, we denote color of *i*-th baloon as *s**i* — lowercase letter of the Latin alphabet. Also Kefa has *k* friends. Friend will be upset, If he get two baloons of the same color. Kefa want to give out all baloons to his friends. Help Kefa to find out, can he give out all his baloons, such that no one of his friens will be upset — print «YES», if he can, and «NO», otherwise. Note, that Kefa's friend will not upset, if he doesn't get baloons at all. | The first line contains two integers *n* and *k* (1<=≤<=*n*,<=*k*<=≤<=100) — the number of baloons and friends.
Next line contains string *s* — colors of baloons. | Answer to the task — «YES» or «NO» in a single line.
You can choose the case (lower or upper) for each letter arbitrary. | [
"4 2\naabb\n",
"6 3\naacaab\n"
] | [
"YES\n",
"NO\n"
] | In the first sample Kefa can give 1-st and 3-rd baloon to the first friend, and 2-nd and 4-th to the second.
In the second sample Kefa needs to give to all his friends baloons of color a, but one baloon will stay, thats why answer is «NO». | 500 | [
{
"input": "4 2\naabb",
"output": "YES"
},
{
"input": "6 3\naacaab",
"output": "NO"
},
{
"input": "2 2\nlu",
"output": "YES"
},
{
"input": "5 3\novvoo",
"output": "YES"
},
{
"input": "36 13\nbzbzcffczzcbcbzzfzbbfzfzzbfbbcbfccbf",
"output": "YES"
},
{
"input": "81 3\nooycgmvvrophvcvpoupepqllqttwcocuilvyxbyumdmmfapvpnxhjhxfuagpnntonibicaqjvwfhwxhbv",
"output": "NO"
},
{
"input": "100 100\nxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
"output": "YES"
},
{
"input": "100 1\nnubcvvjvbjgnjsdkajimdcxvewbcytvfkihunycdrlconddlwgzjasjlsrttlrzsumzpyumpveglfqzmaofbshbojmwuwoxxvrod",
"output": "NO"
},
{
"input": "100 13\nvyldolgryldqrvoldvzvrdrgorlorszddtgqvrlisxxrxdxlqtvtgsrqlzixoyrozxzogqxlsgzdddzqrgitxxritoolzolgrtvl",
"output": "YES"
},
{
"input": "18 6\njzwtnkvmscqhmdlsxy",
"output": "YES"
},
{
"input": "21 2\nfscegcqgzesefghhwcexs",
"output": "NO"
},
{
"input": "32 22\ncduamsptaklqtxlyoutlzepxgyfkvngc",
"output": "YES"
},
{
"input": "49 27\noxyorfnkzwsfllnyvdhdanppuzrnbxehugvmlkgeymqjlmfxd",
"output": "YES"
},
{
"input": "50 24\nxxutzjwbggcwvxztttkmzovtmuwttzcbwoztttohzzxghuuthv",
"output": "YES"
},
{
"input": "57 35\nglxshztrqqfyxthqamagvtmrdparhelnzrqvcwqxjytkbuitovkdxueul",
"output": "YES"
},
{
"input": "75 23\nittttiiuitutuiiuuututiuttiuiuutuuuiuiuuuuttuuttuutuiiuiuiiuiitttuututuiuuii",
"output": "NO"
},
{
"input": "81 66\nfeqevfqfebhvubhuuvfuqheuqhbeeuebehuvhffvbqvqvfbqqvvhevqffbqqhvvqhfeehuhqeqhueuqqq",
"output": "YES"
},
{
"input": "93 42\npqeiafraiavfcteumflpcbpozcomlvpovlzdbldvoopnhdoeqaopzthiuzbzmeieiatthdeqovaqfipqlddllmfcrrnhb",
"output": "YES"
},
{
"input": "100 53\nizszyqyndzwzyzgsdagdwdazadiawizinagqqgczaqqnawgijziziawzszdjdcqjdjqiwgadydcnqisaayjiqqsscwwzjzaycwwc",
"output": "YES"
},
{
"input": "100 14\nvkrdcqbvkwuckpmnbydmczdxoagdsgtqxvhaxntdcxhjcrjyvukhugoglbmyoaqexgtcfdgemmizoniwtmisqqwcwfusmygollab",
"output": "YES"
},
{
"input": "100 42\naaaaaiiiiaiiiaaiaiiaaiiiiiaaaaaiaiiiaiiiiaiiiaaaaaiiiaaaiiaaiiiaiiiaiaaaiaiiiiaaiiiaiiaiaiiaiiiaaaia",
"output": "NO"
},
{
"input": "100 89\ntjbkmydejporbqhcbztkcumxjjgsrvxpuulbhzeeckkbchpbxwhedrlhjsabcexcohgdzouvsgphjdthpuqrlkgzxvqbuhqxdsmf",
"output": "YES"
},
{
"input": "100 100\njhpyiuuzizhubhhpxbbhpyxzhbpjphzppuhiahihiappbhuypyauhizpbibzixjbzxzpbphuiaypyujappuxiyuyaajaxjupbahb",
"output": "YES"
},
{
"input": "100 3\nsszoovvzysavsvzsozzvoozvysozsaszayaszasaysszzzysosyayyvzozovavzoyavsooaoyvoozvvozsaosvayyovazzszzssa",
"output": "NO"
},
{
"input": "100 44\ndluthkxwnorabqsukgnxnvhmsmzilyulpursnxkdsavgemiuizbyzebhyjejgqrvuckhaqtuvdmpziesmpmewpvozdanjyvwcdgo",
"output": "YES"
},
{
"input": "100 90\ntljonbnwnqounictqqctgonktiqoqlocgoblngijqokuquoolciqwnctgoggcbojtwjlculoikbggquqncittwnjbkgkgubnioib",
"output": "YES"
},
{
"input": "100 79\nykxptzgvbqxlregvkvucewtydvnhqhuggdsyqlvcfiuaiddnrrnstityyehiamrggftsqyduwxpuldztyzgmfkehprrneyvtknmf",
"output": "YES"
},
{
"input": "100 79\naagwekyovbviiqeuakbqbqifwavkfkutoriovgfmittulhwojaptacekdirgqoovlleeoqkkdukpadygfwavppohgdrmymmulgci",
"output": "YES"
},
{
"input": "100 93\nearrehrehenaddhdnrdddhdahnadndheeennrearrhraharddreaeraddhehhhrdnredanndneheddrraaneerreedhnadnerhdn",
"output": "YES"
},
{
"input": "100 48\nbmmaebaebmmmbbmxvmammbvvebvaemvbbaxvbvmaxvvmveaxmbbxaaemxmxvxxxvxbmmxaaaevvaxmvamvvmaxaxavexbmmbmmev",
"output": "YES"
},
{
"input": "100 55\nhsavbkehaaesffaeeffakhkhfehbbvbeasahbbbvkesbfvkefeesesevbsvfkbffakvshsbkahfkfakebsvafkbvsskfhfvaasss",
"output": "YES"
},
{
"input": "100 2\ncscffcffsccffsfsfffccssfsscfsfsssffcffsscfccssfffcfscfsscsccccfsssffffcfcfsfffcsfsccffscffcfccccfffs",
"output": "NO"
},
{
"input": "100 3\nzrgznxgdpgfoiifrrrsjfuhvtqxjlgochhyemismjnanfvvpzzvsgajcbsulxyeoepjfwvhkqogiiwqxjkrpsyaqdlwffoockxnc",
"output": "NO"
},
{
"input": "100 5\njbltyyfjakrjeodqepxpkjideulofbhqzxjwlarufwzwsoxhaexpydpqjvhybmvjvntuvhvflokhshpicbnfgsqsmrkrfzcrswwi",
"output": "NO"
},
{
"input": "100 1\nfnslnqktlbmxqpvcvnemxcutebdwepoxikifkzaaixzzydffpdxodmsxjribmxuqhueifdlwzytxkklwhljswqvlejedyrgguvah",
"output": "NO"
},
{
"input": "100 21\nddjenetwgwmdtjbpzssyoqrtirvoygkjlqhhdcjgeurqpunxpupwaepcqkbjjfhnvgpyqnozhhrmhfwararmlcvpgtnopvjqsrka",
"output": "YES"
},
{
"input": "100 100\nnjrhiauqlgkkpkuvciwzivjbbplipvhslqgdkfnmqrxuxnycmpheenmnrglotzuyxycosfediqcuadklsnzjqzfxnbjwvfljnlvq",
"output": "YES"
},
{
"input": "100 100\nbbbbbbbtbbttbtbbbttbttbtbbttttbbbtbttbbbtbttbtbbttttbbbbbtbbttbtbbtbttbbbtbtbtbtbtbtbbbttbbtbtbtbbtb",
"output": "YES"
},
{
"input": "14 5\nfssmmsfffmfmmm",
"output": "NO"
},
{
"input": "2 1\nff",
"output": "NO"
},
{
"input": "2 1\nhw",
"output": "YES"
},
{
"input": "2 2\nss",
"output": "YES"
},
{
"input": "1 1\nl",
"output": "YES"
},
{
"input": "100 50\nfffffttttttjjjuuuvvvvvdddxxxxwwwwgggbsssncccczzyyyyyhhhhhkrreeeeeeaaaaaiiillllllllooooqqqqqqmmpppppp",
"output": "YES"
},
{
"input": "100 50\nbbbbbbbbgggggggggggaaaaaaaahhhhhhhhhhpppppppppsssssssrrrrrrrrllzzzzzzzeeeeeeekkkkkkkwwwwwwwwjjjjjjjj",
"output": "YES"
},
{
"input": "100 50\nwwwwwwwwwwwwwwxxxxxxxxxxxxxxxxxxxxxxxxzzzzzzzzzzzzzzzzzzbbbbbbbbbbbbbbbbbbbbjjjjjjjjjjjjjjjjjjjjjjjj",
"output": "YES"
},
{
"input": "100 80\nbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmm",
"output": "YES"
},
{
"input": "100 10\nbbttthhhhiiiiiiijjjjjvvvvpppssssseeeeeeewwwwgggkkkkkkkkmmmddddduuuzzzzllllnnnnnxxyyyffffccraaaaooooq",
"output": "YES"
},
{
"input": "100 20\nssssssssssbbbbbbbhhhhhhhyyyyyyyzzzzzzzzzzzzcccccxxxxxxxxxxddddmmmmmmmeeeeeeejjjjjjjjjwwwwwwwtttttttt",
"output": "YES"
},
{
"input": "1 2\na",
"output": "YES"
},
{
"input": "3 1\nabb",
"output": "NO"
},
{
"input": "2 1\naa",
"output": "NO"
},
{
"input": "2 1\nab",
"output": "YES"
},
{
"input": "6 2\naaaaaa",
"output": "NO"
},
{
"input": "8 4\naaaaaaaa",
"output": "NO"
},
{
"input": "4 2\naaaa",
"output": "NO"
},
{
"input": "4 3\naaaa",
"output": "NO"
},
{
"input": "1 3\na",
"output": "YES"
},
{
"input": "4 3\nzzzz",
"output": "NO"
},
{
"input": "4 1\naaaa",
"output": "NO"
},
{
"input": "3 4\nabc",
"output": "YES"
},
{
"input": "2 5\nab",
"output": "YES"
},
{
"input": "2 4\nab",
"output": "YES"
},
{
"input": "1 10\na",
"output": "YES"
},
{
"input": "5 2\nzzzzz",
"output": "NO"
},
{
"input": "53 26\naaaaaaaaaaaaaaaaaaaaaaaaaabbbbbbbbbbbbbbbbbbbbbbbbbbb",
"output": "NO"
},
{
"input": "4 1\nabab",
"output": "NO"
},
{
"input": "4 1\nabcb",
"output": "NO"
},
{
"input": "4 2\nabbb",
"output": "NO"
},
{
"input": "5 2\nabccc",
"output": "NO"
},
{
"input": "2 3\nab",
"output": "YES"
},
{
"input": "4 3\nbbbs",
"output": "YES"
},
{
"input": "10 2\nazzzzzzzzz",
"output": "NO"
},
{
"input": "1 2\nb",
"output": "YES"
},
{
"input": "1 3\nb",
"output": "YES"
},
{
"input": "4 5\nabcd",
"output": "YES"
},
{
"input": "4 6\naabb",
"output": "YES"
},
{
"input": "5 2\naaaab",
"output": "NO"
},
{
"input": "3 5\naaa",
"output": "YES"
},
{
"input": "5 3\nazzzz",
"output": "NO"
},
{
"input": "4 100\naabb",
"output": "YES"
},
{
"input": "3 10\naaa",
"output": "YES"
},
{
"input": "3 4\naaa",
"output": "YES"
},
{
"input": "12 5\naaaaabbbbbbb",
"output": "NO"
},
{
"input": "5 2\naabbb",
"output": "NO"
},
{
"input": "10 5\nzzzzzzzzzz",
"output": "NO"
},
{
"input": "2 4\naa",
"output": "YES"
},
{
"input": "1 5\na",
"output": "YES"
},
{
"input": "10 5\naaaaaaaaaa",
"output": "NO"
},
{
"input": "6 3\naaaaaa",
"output": "NO"
},
{
"input": "7 1\nabcdeee",
"output": "NO"
},
{
"input": "18 3\naaaaaabbbbbbcccccc",
"output": "NO"
},
{
"input": "8 2\naabbccdd",
"output": "YES"
},
{
"input": "4 2\nzzzz",
"output": "NO"
},
{
"input": "4 2\nabaa",
"output": "NO"
},
{
"input": "3 2\naaa",
"output": "NO"
},
{
"input": "3 1\nzzz",
"output": "NO"
},
{
"input": "5 4\nzzzzz",
"output": "NO"
},
{
"input": "6 2\naabbbc",
"output": "NO"
},
{
"input": "3 6\naaa",
"output": "YES"
},
{
"input": "2 1\nzz",
"output": "NO"
},
{
"input": "10 3\naaaeeeeeee",
"output": "NO"
},
{
"input": "4 5\naabb",
"output": "YES"
},
{
"input": "3 1\naaa",
"output": "NO"
},
{
"input": "5 2\naazzz",
"output": "NO"
},
{
"input": "6 2\nabbbbc",
"output": "NO"
},
{
"input": "4 2\nxxxx",
"output": "NO"
},
{
"input": "6 3\nzzzzzz",
"output": "NO"
},
{
"input": "3 2\nabb",
"output": "YES"
},
{
"input": "3 2\nzzz",
"output": "NO"
},
{
"input": "6 5\nzzzzzz",
"output": "NO"
},
{
"input": "6 3\nbcaaaa",
"output": "NO"
},
{
"input": "100 100\naaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
"output": "YES"
},
{
"input": "3 6\nabc",
"output": "YES"
}
] | 1,591,735,798 | 2,147,483,647 | Python 3 | OK | TESTS | 114 | 108 | 0 | n, k = map(int,input().split())
s = input()
a = 'YES'
for i in s:
if s.count(i) > k:
a = 'NO'
break
print(a)
| Title: Generous Kefa
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
One day Kefa found *n* baloons. For convenience, we denote color of *i*-th baloon as *s**i* — lowercase letter of the Latin alphabet. Also Kefa has *k* friends. Friend will be upset, If he get two baloons of the same color. Kefa want to give out all baloons to his friends. Help Kefa to find out, can he give out all his baloons, such that no one of his friens will be upset — print «YES», if he can, and «NO», otherwise. Note, that Kefa's friend will not upset, if he doesn't get baloons at all.
Input Specification:
The first line contains two integers *n* and *k* (1<=≤<=*n*,<=*k*<=≤<=100) — the number of baloons and friends.
Next line contains string *s* — colors of baloons.
Output Specification:
Answer to the task — «YES» or «NO» in a single line.
You can choose the case (lower or upper) for each letter arbitrary.
Demo Input:
['4 2\naabb\n', '6 3\naacaab\n']
Demo Output:
['YES\n', 'NO\n']
Note:
In the first sample Kefa can give 1-st and 3-rd baloon to the first friend, and 2-nd and 4-th to the second.
In the second sample Kefa needs to give to all his friends baloons of color a, but one baloon will stay, thats why answer is «NO». | ```python
n, k = map(int,input().split())
s = input()
a = 'YES'
for i in s:
if s.count(i) > k:
a = 'NO'
break
print(a)
``` | 3 |
|
1,008 | A | Romaji | PROGRAMMING | 900 | [
"implementation",
"strings"
] | null | null | Vitya has just started learning Berlanese language. It is known that Berlanese uses the Latin alphabet. Vowel letters are "a", "o", "u", "i", and "e". Other letters are consonant.
In Berlanese, there has to be a vowel after every consonant, but there can be any letter after any vowel. The only exception is a consonant "n"; after this letter, there can be any letter (not only a vowel) or there can be no letter at all. For example, the words "harakiri", "yupie", "man", and "nbo" are Berlanese while the words "horse", "king", "my", and "nz" are not.
Help Vitya find out if a word $s$ is Berlanese. | The first line of the input contains the string $s$ consisting of $|s|$ ($1\leq |s|\leq 100$) lowercase Latin letters. | Print "YES" (without quotes) if there is a vowel after every consonant except "n", otherwise print "NO".
You can print each letter in any case (upper or lower). | [
"sumimasen\n",
"ninja\n",
"codeforces\n"
] | [
"YES\n",
"YES\n",
"NO\n"
] | In the first and second samples, a vowel goes after each consonant except "n", so the word is Berlanese.
In the third sample, the consonant "c" goes after the consonant "r", and the consonant "s" stands on the end, so the word is not Berlanese. | 500 | [
{
"input": "sumimasen",
"output": "YES"
},
{
"input": "ninja",
"output": "YES"
},
{
"input": "codeforces",
"output": "NO"
},
{
"input": "auuaoonntanonnuewannnnpuuinniwoonennyolonnnvienonpoujinndinunnenannmuveoiuuhikucuziuhunnnmunzancenen",
"output": "YES"
},
{
"input": "n",
"output": "YES"
},
{
"input": "necnei",
"output": "NO"
},
{
"input": "nternn",
"output": "NO"
},
{
"input": "aucunuohja",
"output": "NO"
},
{
"input": "a",
"output": "YES"
},
{
"input": "b",
"output": "NO"
},
{
"input": "nn",
"output": "YES"
},
{
"input": "nnnzaaa",
"output": "YES"
},
{
"input": "zn",
"output": "NO"
},
{
"input": "ab",
"output": "NO"
},
{
"input": "aaaaaaaaaa",
"output": "YES"
},
{
"input": "aaaaaaaaab",
"output": "NO"
},
{
"input": "aaaaaaaaan",
"output": "YES"
},
{
"input": "baaaaaaaaa",
"output": "YES"
},
{
"input": "naaaaaaaaa",
"output": "YES"
},
{
"input": "nbaaaaaaaa",
"output": "YES"
},
{
"input": "bbaaaaaaaa",
"output": "NO"
},
{
"input": "bnaaaaaaaa",
"output": "NO"
},
{
"input": "eonwonojannonnufimiiniewuqaienokacevecinfuqihatenhunliquuyebayiaenifuexuanenuaounnboancaeowonu",
"output": "YES"
},
{
"input": "uixinnepnlinqaingieianndeakuniooudidonnnqeaituioeneiroionxuowudiooonayenfeonuino",
"output": "NO"
},
{
"input": "nnnnnyigaveteononnnnxaalenxuiiwannntoxonyoqonlejuoxuoconnnentoinnul",
"output": "NO"
},
{
"input": "ndonneasoiunhomuunnhuitonnntunntoanerekonoupunanuauenu",
"output": "YES"
},
{
"input": "anujemogawautiedoneobninnibonuunaoennnyoorufonxionntinimiboonununnnnnleenqunminzayoutanlalo",
"output": "NO"
},
{
"input": "y",
"output": "NO"
},
{
"input": "by",
"output": "NO"
},
{
"input": "yy",
"output": "NO"
},
{
"input": "nbn",
"output": "NO"
},
{
"input": "nz",
"output": "NO"
},
{
"input": "king",
"output": "NO"
},
{
"input": "g",
"output": "NO"
},
{
"input": "az",
"output": "NO"
},
{
"input": "x",
"output": "NO"
},
{
"input": "z",
"output": "NO"
},
{
"input": "yn",
"output": "NO"
},
{
"input": "aeo",
"output": "YES"
},
{
"input": "nb",
"output": "NO"
},
{
"input": "npn",
"output": "NO"
},
{
"input": "kini",
"output": "YES"
},
{
"input": "pya",
"output": "NO"
},
{
"input": "m",
"output": "NO"
},
{
"input": "p",
"output": "NO"
},
{
"input": "aaaaaaaak",
"output": "NO"
},
{
"input": "aab",
"output": "NO"
},
{
"input": "d",
"output": "NO"
},
{
"input": "at",
"output": "NO"
},
{
"input": "aaaaaak",
"output": "NO"
},
{
"input": "aaz",
"output": "NO"
},
{
"input": "aaab",
"output": "NO"
},
{
"input": "s",
"output": "NO"
},
{
"input": "nzzen",
"output": "NO"
},
{
"input": "aeionnhhhn",
"output": "NO"
},
{
"input": "h",
"output": "NO"
},
{
"input": "ny",
"output": "NO"
}
] | 1,637,939,220 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 9 | 61 | 0 | stri=input()
stri=stri+''
x=1
l=len(stri)
for i in range(l-1):
if stri[i] not in 'naeiou' and stri[i+1] not in 'aeiou':
x=0
if x==1:
print('Yes')
else:
print('No') | Title: Romaji
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vitya has just started learning Berlanese language. It is known that Berlanese uses the Latin alphabet. Vowel letters are "a", "o", "u", "i", and "e". Other letters are consonant.
In Berlanese, there has to be a vowel after every consonant, but there can be any letter after any vowel. The only exception is a consonant "n"; after this letter, there can be any letter (not only a vowel) or there can be no letter at all. For example, the words "harakiri", "yupie", "man", and "nbo" are Berlanese while the words "horse", "king", "my", and "nz" are not.
Help Vitya find out if a word $s$ is Berlanese.
Input Specification:
The first line of the input contains the string $s$ consisting of $|s|$ ($1\leq |s|\leq 100$) lowercase Latin letters.
Output Specification:
Print "YES" (without quotes) if there is a vowel after every consonant except "n", otherwise print "NO".
You can print each letter in any case (upper or lower).
Demo Input:
['sumimasen\n', 'ninja\n', 'codeforces\n']
Demo Output:
['YES\n', 'YES\n', 'NO\n']
Note:
In the first and second samples, a vowel goes after each consonant except "n", so the word is Berlanese.
In the third sample, the consonant "c" goes after the consonant "r", and the consonant "s" stands on the end, so the word is not Berlanese. | ```python
stri=input()
stri=stri+''
x=1
l=len(stri)
for i in range(l-1):
if stri[i] not in 'naeiou' and stri[i+1] not in 'aeiou':
x=0
if x==1:
print('Yes')
else:
print('No')
``` | 0 |
|
877 | B | Nikita and string | PROGRAMMING | 1,500 | [
"brute force",
"dp"
] | null | null | One day Nikita found the string containing letters "a" and "b" only.
Nikita thinks that string is beautiful if it can be cut into 3 strings (possibly empty) without changing the order of the letters, where the 1-st and the 3-rd one contain only letters "a" and the 2-nd contains only letters "b".
Nikita wants to make the string beautiful by removing some (possibly none) of its characters, but without changing their order. What is the maximum length of the string he can get? | The first line contains a non-empty string of length not greater than 5<=000 containing only lowercase English letters "a" and "b". | Print a single integer — the maximum possible size of beautiful string Nikita can get. | [
"abba\n",
"bab\n"
] | [
"4",
"2"
] | It the first sample the string is already beautiful.
In the second sample he needs to delete one of "b" to make it beautiful. | 1,000 | [
{
"input": "abba",
"output": "4"
},
{
"input": "bab",
"output": "2"
},
{
"input": "bbabbbaabbbb",
"output": "9"
},
{
"input": "bbabbbbbaaba",
"output": "10"
},
{
"input": "bbabbbababaa",
"output": "9"
},
{
"input": "aabbaababbab",
"output": "8"
},
{
"input": "a",
"output": "1"
},
{
"input": "b",
"output": "1"
},
{
"input": "ab",
"output": "2"
},
{
"input": "ba",
"output": "2"
},
{
"input": "bb",
"output": "2"
},
{
"input": "aa",
"output": "2"
},
{
"input": "babbbaab",
"output": "6"
},
{
"input": "abaaaa",
"output": "6"
},
{
"input": "aaa",
"output": "3"
}
] | 1,508,990,565 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 6 | 2,000 | 0 | from sys import stdin
def get_max_blength(s):
a = "a"
a_counts = [0] * (len(s) + 1)
b_counts = [0] * (len(s) + 1)
for i in range(len(s)):
a_counts[i] = a_counts[i - 1]
b_counts[i] = b_counts[i - 1]
if s[i] == a:
a_counts[i] += 1
else:
b_counts[i] += 1
mx = 0
for i in range(0, len(s)):
for j in range(i - 1, len(s)):
cl = a_counts[i - 1] + a_counts[len(s) - 1] - a_counts[j] + b_counts[j] - b_counts[i - 1]
if cl > mx:
mx = cl
return mx
def main():
s = stdin.readline().strip()
# print(a_counts, b_counts)
print(get_max_blength(s))
def tests():
s = "bbabbbbbaaba"
assert get_max_blength(s) == 10
s = "abba"
assert get_max_blength(s) == 4
s = "bab"
assert get_max_blength(s) == 2
if __name__ == "__main__":
# tests()
main() | Title: Nikita and string
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
One day Nikita found the string containing letters "a" and "b" only.
Nikita thinks that string is beautiful if it can be cut into 3 strings (possibly empty) without changing the order of the letters, where the 1-st and the 3-rd one contain only letters "a" and the 2-nd contains only letters "b".
Nikita wants to make the string beautiful by removing some (possibly none) of its characters, but without changing their order. What is the maximum length of the string he can get?
Input Specification:
The first line contains a non-empty string of length not greater than 5<=000 containing only lowercase English letters "a" and "b".
Output Specification:
Print a single integer — the maximum possible size of beautiful string Nikita can get.
Demo Input:
['abba\n', 'bab\n']
Demo Output:
['4', '2']
Note:
It the first sample the string is already beautiful.
In the second sample he needs to delete one of "b" to make it beautiful. | ```python
from sys import stdin
def get_max_blength(s):
a = "a"
a_counts = [0] * (len(s) + 1)
b_counts = [0] * (len(s) + 1)
for i in range(len(s)):
a_counts[i] = a_counts[i - 1]
b_counts[i] = b_counts[i - 1]
if s[i] == a:
a_counts[i] += 1
else:
b_counts[i] += 1
mx = 0
for i in range(0, len(s)):
for j in range(i - 1, len(s)):
cl = a_counts[i - 1] + a_counts[len(s) - 1] - a_counts[j] + b_counts[j] - b_counts[i - 1]
if cl > mx:
mx = cl
return mx
def main():
s = stdin.readline().strip()
# print(a_counts, b_counts)
print(get_max_blength(s))
def tests():
s = "bbabbbbbaaba"
assert get_max_blength(s) == 10
s = "abba"
assert get_max_blength(s) == 4
s = "bab"
assert get_max_blength(s) == 2
if __name__ == "__main__":
# tests()
main()
``` | 0 |
Subsets and Splits