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
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,638,382,244
2,147,483,647
Python 3
OK
TESTS
39
92
0
from sys import exit reqhi = int(input()) lst = list(map(int,input().split())) grohi,count = 0,0 while grohi<reqhi: if len(lst)==0: print(-1) exit() x = max(lst) grohi += x lst.pop(lst.index(x)) count+=1 print(count)
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 from sys import exit reqhi = int(input()) lst = list(map(int,input().split())) grohi,count = 0,0 while grohi<reqhi: if len(lst)==0: print(-1) exit() x = max(lst) grohi += x lst.pop(lst.index(x)) count+=1 print(count) ```
3
755
B
PolandBall and Game
PROGRAMMING
1,100
[ "binary search", "data structures", "games", "greedy", "sortings", "strings" ]
null
null
PolandBall is playing a game with EnemyBall. The rules are simple. Players have to say words in turns. You cannot say a word which was already said. PolandBall starts. The Ball which can't say a new word loses. You're given two lists of words familiar to PolandBall and EnemyBall. Can you determine who wins the game, if both play optimally?
The first input line contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=103) — number of words PolandBall and EnemyBall know, respectively. Then *n* strings follow, one per line — words familiar to PolandBall. Then *m* strings follow, one per line — words familiar to EnemyBall. Note that one Ball cannot know a word more than once (strings are unique), but some words can be known by both players. Each word is non-empty and consists of no more than 500 lowercase English alphabet letters.
In a single line of print the answer — "YES" if PolandBall wins and "NO" otherwise. Both Balls play optimally.
[ "5 1\npolandball\nis\na\ncool\ncharacter\nnope\n", "2 2\nkremowka\nwadowicka\nkremowka\nwiedenska\n", "1 2\na\na\nb\n" ]
[ "YES", "YES", "NO" ]
In the first example PolandBall knows much more words and wins effortlessly. In the second example if PolandBall says kremowka first, then EnemyBall cannot use that word anymore. EnemyBall can only say wiedenska. PolandBall says wadowicka and wins.
1,000
[ { "input": "5 1\npolandball\nis\na\ncool\ncharacter\nnope", "output": "YES" }, { "input": "2 2\nkremowka\nwadowicka\nkremowka\nwiedenska", "output": "YES" }, { "input": "1 2\na\na\nb", "output": "NO" }, { "input": "2 2\na\nb\nb\nc", "output": "YES" }, { "input": "2 1\nc\na\na", "output": "YES" }, { "input": "3 3\nab\nbc\ncd\ncd\ndf\nfg", "output": "YES" }, { "input": "3 3\nc\na\nb\na\nd\ng", "output": "YES" }, { "input": "1 1\naa\naa", "output": "YES" }, { "input": "2 1\na\nb\na", "output": "YES" }, { "input": "6 5\na\nb\nc\nd\ne\nf\nf\ne\nd\nz\ny", "output": "YES" }, { "input": "3 2\na\nb\nc\nd\ne", "output": "YES" } ]
1,625,948,015
2,147,483,647
PyPy 3
OK
TESTS
33
187
5,120,000
n, m = map(int, input().split()) counted_words = set() repeated = 0 words1 = 0 words2 = 0 for _ in range(n): word = input().strip() words1 += 1 counted_words.add(word) for _ in range(m): word = input().strip() words2 += 1 if word in counted_words: repeated += 1 if repeated % 2 == 1: words2 -= 1 if words1 > words2: print("YES") else: print("NO")
Title: PolandBall and Game Time Limit: None seconds Memory Limit: None megabytes Problem Description: PolandBall is playing a game with EnemyBall. The rules are simple. Players have to say words in turns. You cannot say a word which was already said. PolandBall starts. The Ball which can't say a new word loses. You're given two lists of words familiar to PolandBall and EnemyBall. Can you determine who wins the game, if both play optimally? Input Specification: The first input line contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=103) — number of words PolandBall and EnemyBall know, respectively. Then *n* strings follow, one per line — words familiar to PolandBall. Then *m* strings follow, one per line — words familiar to EnemyBall. Note that one Ball cannot know a word more than once (strings are unique), but some words can be known by both players. Each word is non-empty and consists of no more than 500 lowercase English alphabet letters. Output Specification: In a single line of print the answer — "YES" if PolandBall wins and "NO" otherwise. Both Balls play optimally. Demo Input: ['5 1\npolandball\nis\na\ncool\ncharacter\nnope\n', '2 2\nkremowka\nwadowicka\nkremowka\nwiedenska\n', '1 2\na\na\nb\n'] Demo Output: ['YES', 'YES', 'NO'] Note: In the first example PolandBall knows much more words and wins effortlessly. In the second example if PolandBall says kremowka first, then EnemyBall cannot use that word anymore. EnemyBall can only say wiedenska. PolandBall says wadowicka and wins.
```python n, m = map(int, input().split()) counted_words = set() repeated = 0 words1 = 0 words2 = 0 for _ in range(n): word = input().strip() words1 += 1 counted_words.add(word) for _ in range(m): word = input().strip() words2 += 1 if word in counted_words: repeated += 1 if repeated % 2 == 1: words2 -= 1 if words1 > words2: print("YES") else: print("NO") ```
3
10
A
Power Consumption Calculation
PROGRAMMING
900
[ "implementation" ]
A. Power Consumption Calculation
1
256
Tom is interested in power consumption of his favourite laptop. His laptop has three modes. In normal mode laptop consumes *P*1 watt per minute. *T*1 minutes after Tom moved the mouse or touched the keyboard for the last time, a screensaver starts and power consumption changes to *P*2 watt per minute. Finally, after *T*2 minutes from the start of the screensaver, laptop switches to the "sleep" mode and consumes *P*3 watt per minute. If Tom moves the mouse or touches the keyboard when the laptop is in the second or in the third mode, it switches to the first (normal) mode. Tom's work with the laptop can be divided into *n* time periods [*l*1,<=*r*1],<=[*l*2,<=*r*2],<=...,<=[*l**n*,<=*r**n*]. During each interval Tom continuously moves the mouse and presses buttons on the keyboard. Between the periods Tom stays away from the laptop. Find out the total amount of power consumed by the laptop during the period [*l*1,<=*r**n*].
The first line contains 6 integer numbers *n*, *P*1, *P*2, *P*3, *T*1, *T*2 (1<=≤<=*n*<=≤<=100,<=0<=≤<=*P*1,<=*P*2,<=*P*3<=≤<=100,<=1<=≤<=*T*1,<=*T*2<=≤<=60). The following *n* lines contain description of Tom's work. Each *i*-th of these lines contains two space-separated integers *l**i* and *r**i* (0<=≤<=*l**i*<=&lt;<=*r**i*<=≤<=1440, *r**i*<=&lt;<=*l**i*<=+<=1 for *i*<=&lt;<=*n*), which stand for the start and the end of the *i*-th period of work.
Output the answer to the problem.
[ "1 3 2 1 5 10\n0 10\n", "2 8 4 2 5 10\n20 30\n50 100\n" ]
[ "30", "570" ]
none
0
[ { "input": "1 3 2 1 5 10\n0 10", "output": "30" }, { "input": "2 8 4 2 5 10\n20 30\n50 100", "output": "570" }, { "input": "3 15 9 95 39 19\n873 989\n1003 1137\n1172 1436", "output": "8445" }, { "input": "4 73 2 53 58 16\n51 52\n209 242\n281 407\n904 945", "output": "52870" }, { "input": "5 41 20 33 43 4\n46 465\n598 875\n967 980\n1135 1151\n1194 1245", "output": "46995" }, { "input": "6 88 28 100 53 36\n440 445\n525 614\n644 844\n1238 1261\n1305 1307\n1425 1434", "output": "85540" }, { "input": "7 46 61 55 28 59\n24 26\n31 61\n66 133\n161 612\n741 746\n771 849\n1345 1357", "output": "67147" }, { "input": "8 83 18 30 28 5\n196 249\n313 544\n585 630\n718 843\n1040 1194\n1207 1246\n1268 1370\n1414 1422", "output": "85876" }, { "input": "9 31 65 27 53 54\n164 176\n194 210\n485 538\n617 690\n875 886\n888 902\n955 957\n1020 1200\n1205 1282", "output": "38570" }, { "input": "30 3 1 58 44 7\n11 13\n14 32\n37 50\n70 74\n101 106\n113 129\n184 195\n197 205\n213 228\n370 394\n443 446\n457 460\n461 492\n499 585\n602 627\n709 776\n812 818\n859 864\n910 913\n918 964\n1000 1010\n1051 1056\n1063 1075\n1106 1145\n1152 1189\n1211 1212\n1251 1259\n1272 1375\n1412 1417\n1430 1431", "output": "11134" }, { "input": "30 42 3 76 28 26\n38 44\n55 66\n80 81\n84 283\n298 314\n331 345\n491 531\n569 579\n597 606\n612 617\n623 701\n723 740\n747 752\n766 791\n801 827\n842 846\n853 891\n915 934\n945 949\n955 964\n991 1026\n1051 1059\n1067 1179\n1181 1191\n1214 1226\n1228 1233\n1294 1306\n1321 1340\n1371 1374\n1375 1424", "output": "59043" }, { "input": "30 46 5 93 20 46\n12 34\n40 41\n54 58\n100 121\n162 182\n220 349\n358 383\n390 398\n401 403\n408 409\n431 444\n466 470\n471 535\n556 568\n641 671\n699 709\n767 777\n786 859\n862 885\n912 978\n985 997\n1013 1017\n1032 1038\n1047 1048\n1062 1080\n1094 1097\n1102 1113\n1122 1181\n1239 1280\n1320 1369", "output": "53608" }, { "input": "30 50 74 77 4 57\n17 23\n24 61\n67 68\n79 87\n93 101\n104 123\n150 192\n375 377\n398 414\n461 566\n600 633\n642 646\n657 701\n771 808\n812 819\n823 826\n827 833\n862 875\n880 891\n919 920\n928 959\n970 1038\n1057 1072\n1074 1130\n1165 1169\n1171 1230\n1265 1276\n1279 1302\n1313 1353\n1354 1438", "output": "84067" }, { "input": "30 54 76 95 48 16\n9 11\n23 97\n112 116\n126 185\n214 223\n224 271\n278 282\n283 348\n359 368\n373 376\n452 463\n488 512\n532 552\n646 665\n681 685\n699 718\n735 736\n750 777\n791 810\n828 838\n841 858\n874 1079\n1136 1171\n1197 1203\n1210 1219\n1230 1248\n1280 1292\n1324 1374\n1397 1435\n1438 1439", "output": "79844" }, { "input": "30 58 78 12 41 28\n20 26\n27 31\n35 36\n38 99\n103 104\n106 112\n133 143\n181 246\n248 251\n265 323\n350 357\n378 426\n430 443\n466 476\n510 515\n517 540\n542 554\n562 603\n664 810\n819 823\n826 845\n869 895\n921 973\n1002 1023\n1102 1136\n1143 1148\n1155 1288\n1316 1388\n1394 1403\n1434 1437", "output": "82686" }, { "input": "30 62 80 97 25 47\n19 20\n43 75\n185 188\n199 242\n252 258\n277 310\n316 322\n336 357\n398 399\n404 436\n443 520\n549 617\n637 649\n679 694\n705 715\n725 730\n731 756\n768 793\n806 833\n834 967\n1003 1079\n1088 1097\n1100 1104\n1108 1121\n1127 1164\n1240 1263\n1274 1307\n1367 1407\n1419 1425\n1433 1437", "output": "92356" }, { "input": "30 100 48 14 9 7\n26 55\n75 107\n145 146\n158 167\n197 199\n201 213\n222 238\n257 265\n271 338\n357 439\n454 462\n463 562\n633 660\n670 691\n696 829\n844 864\n880 888\n891 894\n895 900\n950 973\n1004 1007\n1018 1021\n1045 1049\n1062 1073\n1138 1184\n1240 1272\n1278 1315\n1403 1410\n1412 1418\n1426 1434", "output": "107490" }, { "input": "30 3 50 32 1 18\n46 60\n66 94\n99 141\n162 239\n309 334\n400 550\n594 630\n659 663\n664 701\n735 736\n741 755\n756 801\n823 854\n865 915\n937 964\n984 986\n990 1007\n1008 1031\n1052 1064\n1073 1080\n1190 1191\n1192 1254\n1265 1266\n1272 1273\n1274 1277\n1284 1302\n1308 1312\n1358 1383\n1388 1389\n1390 1401", "output": "25258" }, { "input": "30 7 52 49 46 37\n2 73\n129 130\n131 140\n143 150\n187 190\n217 238\n248 271\n375 426\n465 470\n475 503\n506 541\n569 571\n578 585\n680 683\n690 738\n742 761\n868 877\n890 892\n904 915\n935 961\n1076 1100\n1103 1114\n1232 1244\n1246 1247\n1257 1261\n1271 1276\n1280 1298\n1346 1360\n1373 1382\n1407 1419", "output": "23992" } ]
1,602,436,138
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
2
216
307,200
n, p1, p2, p3, t1, t2 = [int(x) for x in input().split(' ')] P = 0 for task in range(n): l, r = [int(x) for x in input().split(' ')] if task > 0: gap = l - end P += p1 * min(gap, t1) P += p2 * min(gap - min(gap, t1), t2) P += p3 * (gap - min(gap - min(gap, t1), t2 + t1)) P += p1 * (r - l) end = r print(P)
Title: Power Consumption Calculation Time Limit: 1 seconds Memory Limit: 256 megabytes Problem Description: Tom is interested in power consumption of his favourite laptop. His laptop has three modes. In normal mode laptop consumes *P*1 watt per minute. *T*1 minutes after Tom moved the mouse or touched the keyboard for the last time, a screensaver starts and power consumption changes to *P*2 watt per minute. Finally, after *T*2 minutes from the start of the screensaver, laptop switches to the "sleep" mode and consumes *P*3 watt per minute. If Tom moves the mouse or touches the keyboard when the laptop is in the second or in the third mode, it switches to the first (normal) mode. Tom's work with the laptop can be divided into *n* time periods [*l*1,<=*r*1],<=[*l*2,<=*r*2],<=...,<=[*l**n*,<=*r**n*]. During each interval Tom continuously moves the mouse and presses buttons on the keyboard. Between the periods Tom stays away from the laptop. Find out the total amount of power consumed by the laptop during the period [*l*1,<=*r**n*]. Input Specification: The first line contains 6 integer numbers *n*, *P*1, *P*2, *P*3, *T*1, *T*2 (1<=≤<=*n*<=≤<=100,<=0<=≤<=*P*1,<=*P*2,<=*P*3<=≤<=100,<=1<=≤<=*T*1,<=*T*2<=≤<=60). The following *n* lines contain description of Tom's work. Each *i*-th of these lines contains two space-separated integers *l**i* and *r**i* (0<=≤<=*l**i*<=&lt;<=*r**i*<=≤<=1440, *r**i*<=&lt;<=*l**i*<=+<=1 for *i*<=&lt;<=*n*), which stand for the start and the end of the *i*-th period of work. Output Specification: Output the answer to the problem. Demo Input: ['1 3 2 1 5 10\n0 10\n', '2 8 4 2 5 10\n20 30\n50 100\n'] Demo Output: ['30', '570'] Note: none
```python n, p1, p2, p3, t1, t2 = [int(x) for x in input().split(' ')] P = 0 for task in range(n): l, r = [int(x) for x in input().split(' ')] if task > 0: gap = l - end P += p1 * min(gap, t1) P += p2 * min(gap - min(gap, t1), t2) P += p3 * (gap - min(gap - min(gap, t1), t2 + t1)) P += p1 * (r - l) end = r print(P) ```
0
276
C
Little Girl and Maximum Sum
PROGRAMMING
1,500
[ "data structures", "greedy", "implementation", "sortings" ]
null
null
The little girl loves the problems on array queries very much. One day she came across a rather well-known problem: you've got an array of $n$ elements (the elements of the array are indexed starting from 1); also, there are $q$ queries, each one is defined by a pair of integers $l_i$, $r_i$ $(1 \le l_i \le r_i \le n)$. You need to find for each query the sum of elements of the array with indexes from $l_i$ to $r_i$, inclusive. The little girl found the problem rather boring. She decided to reorder the array elements before replying to the queries in a way that makes the sum of query replies maximum possible. Your task is to find the value of this maximum sum.
The first line contains two space-separated integers $n$ ($1 \le n \le 2\cdot10^5$) and $q$ ($1 \le q \le 2\cdot10^5$) — the number of elements in the array and the number of queries, correspondingly. The next line contains $n$ space-separated integers $a_i$ ($1 \le a_i \le 2\cdot10^5$) — the array elements. Each of the following $q$ lines contains two space-separated integers $l_i$ and $r_i$ ($1 \le l_i \le r_i \le n$) — the $i$-th query.
In a single line print, a single integer — the maximum sum of query replies after the array elements are reordered. Please, do not use the %lld specifier to read or write 64-bit integers in C++. It is preferred to use the cin, cout streams or the %I64d specifier.
[ "3 3\n5 3 2\n1 2\n2 3\n1 3\n", "5 3\n5 2 4 1 3\n1 5\n2 3\n2 3\n" ]
[ "25\n", "33\n" ]
none
1,500
[ { "input": "3 3\n5 3 2\n1 2\n2 3\n1 3", "output": "25" }, { "input": "5 3\n5 2 4 1 3\n1 5\n2 3\n2 3", "output": "33" }, { "input": "34 21\n23 38 16 49 44 50 48 34 33 19 18 31 11 15 20 47 44 30 39 33 45 46 1 13 27 16 31 36 17 23 38 5 30 16\n8 16\n14 27\n8 26\n1 8\n5 6\n23 28\n4 33\n13 30\n12 30\n11 30\n9 21\n1 14\n15 22\n4 11\n5 24\n8 20\n17 33\n6 9\n3 14\n25 34\n10 17", "output": "9382" }, { "input": "16 13\n40 32 15 16 35 36 45 23 30 42 25 8 29 21 39 23\n2 9\n3 11\n8 9\n4 14\n1 6\n5 10\n5 14\n5 11\n13 13\n2 8\n9 16\n6 10\n7 8", "output": "2838" }, { "input": "31 48\n45 19 16 42 38 18 50 7 28 40 39 25 45 14 36 18 27 30 16 4 22 6 1 23 16 47 14 35 27 47 2\n6 16\n11 28\n4 30\n25 26\n11 30\n5 9\n4 17\n15 17\n10 25\n15 26\n1 3\n9 26\n8 29\n16 30\n5 24\n27 30\n9 10\n22 29\n2 6\n15 24\n6 21\n19 21\n4 28\n1 7\n18 21\n10 22\n6 15\n14 28\n4 29\n12 13\n19 29\n5 6\n13 31\n21 27\n9 25\n6 18\n6 8\n28 30\n2 4\n15 21\n1 1\n8 30\n3 31\n11 27\n28 29\n6 22\n20 22\n9 25", "output": "17471" }, { "input": "22 7\n44 41 40 41 37 42 46 16 50 47 30 7 32 6 20 14 47 25 11 1 35 12\n1 10\n10 20\n4 5\n1 8\n2 12\n8 8\n2 16", "output": "2202" }, { "input": "3 2\n1 2 3\n2 3\n1 2", "output": "9" } ]
1,689,007,175
2,147,483,647
PyPy 3-64
OK
TESTS
63
358
70,963,200
from sys import stdin def get_input(): # Faster IO input_str = stdin.read().strip().split('\n') n, q = map(int, input_str[0].split()) arr = list(map(int, input_str[1].split())) queries = [map(int, input_str[i].split()) for i in range(2, len(input_str))] return arr, queries def get_max(arr, queries): n = len(arr) freq = [0] * (n + 2) for l, r in queries: freq[l] += 1 freq[r + 1] -= 1 for i in range(1, n + 1): freq[i] += freq[i - 1] freq.pop(0) freq.pop() freq.sort() arr.sort() # print(arr, freq) s = 0 for i in range(n): s += arr[i] * freq[i] return s print(get_max(*get_input()))
Title: Little Girl and Maximum Sum Time Limit: None seconds Memory Limit: None megabytes Problem Description: The little girl loves the problems on array queries very much. One day she came across a rather well-known problem: you've got an array of $n$ elements (the elements of the array are indexed starting from 1); also, there are $q$ queries, each one is defined by a pair of integers $l_i$, $r_i$ $(1 \le l_i \le r_i \le n)$. You need to find for each query the sum of elements of the array with indexes from $l_i$ to $r_i$, inclusive. The little girl found the problem rather boring. She decided to reorder the array elements before replying to the queries in a way that makes the sum of query replies maximum possible. Your task is to find the value of this maximum sum. Input Specification: The first line contains two space-separated integers $n$ ($1 \le n \le 2\cdot10^5$) and $q$ ($1 \le q \le 2\cdot10^5$) — the number of elements in the array and the number of queries, correspondingly. The next line contains $n$ space-separated integers $a_i$ ($1 \le a_i \le 2\cdot10^5$) — the array elements. Each of the following $q$ lines contains two space-separated integers $l_i$ and $r_i$ ($1 \le l_i \le r_i \le n$) — the $i$-th query. Output Specification: In a single line print, a single integer — the maximum sum of query replies after the array elements are reordered. Please, do not use the %lld specifier to read or write 64-bit integers in C++. It is preferred to use the cin, cout streams or the %I64d specifier. Demo Input: ['3 3\n5 3 2\n1 2\n2 3\n1 3\n', '5 3\n5 2 4 1 3\n1 5\n2 3\n2 3\n'] Demo Output: ['25\n', '33\n'] Note: none
```python from sys import stdin def get_input(): # Faster IO input_str = stdin.read().strip().split('\n') n, q = map(int, input_str[0].split()) arr = list(map(int, input_str[1].split())) queries = [map(int, input_str[i].split()) for i in range(2, len(input_str))] return arr, queries def get_max(arr, queries): n = len(arr) freq = [0] * (n + 2) for l, r in queries: freq[l] += 1 freq[r + 1] -= 1 for i in range(1, n + 1): freq[i] += freq[i - 1] freq.pop(0) freq.pop() freq.sort() arr.sort() # print(arr, freq) s = 0 for i in range(n): s += arr[i] * freq[i] return s print(get_max(*get_input())) ```
3
37
A
Towers
PROGRAMMING
1,000
[ "sortings" ]
A. Towers
2
256
Little Vasya has received a young builder’s kit. The kit consists of several wooden bars, the lengths of all of them are known. The bars can be put one on the top of the other if their lengths are the same. Vasya wants to construct the minimal number of towers from the bars. Help Vasya to use the bars in the best way possible.
The first line contains an integer *N* (1<=≤<=*N*<=≤<=1000) — the number of bars at Vasya’s disposal. The second line contains *N* space-separated integers *l**i* — the lengths of the bars. All the lengths are natural numbers not exceeding 1000.
In one line output two numbers — the height of the largest tower and their total number. Remember that Vasya should use all the bars.
[ "3\n1 2 3\n", "4\n6 5 6 7\n" ]
[ "1 3\n", "2 3\n" ]
none
500
[ { "input": "3\n1 2 3", "output": "1 3" }, { "input": "4\n6 5 6 7", "output": "2 3" }, { "input": "4\n3 2 1 1", "output": "2 3" }, { "input": "4\n1 2 3 3", "output": "2 3" }, { "input": "3\n20 22 36", "output": "1 3" }, { "input": "25\n47 30 94 41 45 20 96 51 110 129 24 116 9 47 32 82 105 114 116 75 154 151 70 42 162", "output": "2 23" }, { "input": "45\n802 664 442 318 318 827 417 878 711 291 231 414 807 553 657 392 279 202 386 606 465 655 658 112 887 15 25 502 95 44 679 775 942 609 209 871 31 234 4 231 150 110 22 823 193", "output": "2 43" }, { "input": "63\n93 180 116 7 8 179 268 279 136 94 221 153 264 190 278 19 19 63 153 26 158 225 25 49 89 218 111 149 255 225 197 122 243 80 3 224 107 178 202 17 53 92 69 42 228 24 81 205 95 8 265 82 228 156 127 241 172 159 106 60 67 155 111", "output": "2 57" }, { "input": "83\n246 535 994 33 390 927 321 97 223 922 812 705 79 80 977 457 476 636 511 137 6 360 815 319 717 674 368 551 714 628 278 713 761 553 184 414 623 753 428 214 581 115 439 61 677 216 772 592 187 603 658 310 439 559 870 376 109 321 189 337 277 26 70 734 796 907 979 693 570 227 345 650 737 633 701 914 134 403 972 940 371 6 642", "output": "2 80" }, { "input": "105\n246 57 12 204 165 123 246 68 191 310 3 152 386 333 374 257 158 104 333 50 80 290 8 340 101 76 221 316 388 289 138 359 316 26 93 290 105 178 81 195 41 196 218 180 244 292 187 97 315 323 174 119 248 239 92 312 31 2 101 180 307 170 338 314 163 281 217 31 142 238 280 190 190 156 70 74 329 113 151 8 141 313 366 40 253 116 168 124 135 230 294 266 353 389 371 359 195 200 183 237 93 102 315 118 188", "output": "2 92" }, { "input": "123\n112 277 170 247 252 115 157 293 256 143 196 90 12 164 164 42 8 223 167 109 175 232 239 111 148 51 9 254 93 32 268 162 231 91 47 162 161 191 195 145 247 292 129 199 230 94 144 217 18 205 176 20 143 198 121 243 211 262 230 277 195 255 108 290 220 275 158 2 286 200 60 267 278 207 123 150 123 116 131 13 12 226 33 244 30 275 263 45 158 192 254 149 242 176 62 224 221 288 250 160 155 225 132 143 276 293 218 145 197 175 33 129 79 206 210 192 222 262 190 52 274 243 233", "output": "3 101" }, { "input": "5\n5 5 5 5 5", "output": "5 1" }, { "input": "3\n1000 1000 1000", "output": "3 1" }, { "input": "1\n1000", "output": "1 1" }, { "input": "1\n1", "output": "1 1" }, { "input": "5\n1 1000 1000 1000 1000", "output": "4 2" }, { "input": "5\n1000 1000 1000 8 7", "output": "3 3" } ]
1,589,797,086
2,147,483,647
Python 3
OK
TESTS
61
248
6,963,200
n = int(input()) a = [int(a) for a in input().split()] count = 1 c = [] m = [] for i in range(0,n): b = a.count(a[i]) if a[i] not in m: m.append(a[i]) c.append(b) print(max(c), len(m))
Title: Towers Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: Little Vasya has received a young builder’s kit. The kit consists of several wooden bars, the lengths of all of them are known. The bars can be put one on the top of the other if their lengths are the same. Vasya wants to construct the minimal number of towers from the bars. Help Vasya to use the bars in the best way possible. Input Specification: The first line contains an integer *N* (1<=≤<=*N*<=≤<=1000) — the number of bars at Vasya’s disposal. The second line contains *N* space-separated integers *l**i* — the lengths of the bars. All the lengths are natural numbers not exceeding 1000. Output Specification: In one line output two numbers — the height of the largest tower and their total number. Remember that Vasya should use all the bars. Demo Input: ['3\n1 2 3\n', '4\n6 5 6 7\n'] Demo Output: ['1 3\n', '2 3\n'] Note: none
```python n = int(input()) a = [int(a) for a in input().split()] count = 1 c = [] m = [] for i in range(0,n): b = a.count(a[i]) if a[i] not in m: m.append(a[i]) c.append(b) print(max(c), len(m)) ```
3.92503
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,698,498,262
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
2
15
0
#王铭健,工学院 2300011118 n = int(input()) count = 1 if n == 1: print("1") exit() num_list = list(map(int, input().split())) num_list.sort() for i in range(1, n): if num_list[i] >= sum(num_list[0:i]): count += 1 print(count)
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 #王铭健,工学院 2300011118 n = int(input()) count = 1 if n == 1: print("1") exit() num_list = list(map(int, input().split())) num_list.sort() for i in range(1, n): if num_list[i] >= sum(num_list[0:i]): count += 1 print(count) ```
0
784
C
INTERCALC
PROGRAMMING
1,800
[ "*special", "implementation" ]
null
null
DO YOU EXPECT ME TO FIND THIS OUT? WHAT BASE AND/XOR LANGUAGE INCLUDES string? DON'T BYTE OF MORE THAN YOU CAN CHEW YOU CAN ONLY DISTORT THE LARGEST OF MATHEMATICS SO FAR SAYING "ABRACADABRA" WITHOUT A MAGIC AND WON'T DO YOU ANY GOOD THE LAST STACK RUPTURES. ALL DIE. OH, THE EMBARRASSMENT! I HAVE NO ARRAY AND I MUST SCREAM ELEMENTS MAY NOT BE STORED IN WEST HYPERSPACE
The first line of input data contains a single integer *n* (1<=≤<=*n*<=≤<=10). The second line of input data contains *n* space-separated integers *a**i* (1<=≤<=*a**i*<=≤<=11).
Output a single integer.
[ "4\n2 5 3 1\n" ]
[ "4\n" ]
none
0
[ { "input": "4\n2 5 3 1", "output": "4" }, { "input": "2\n1 5", "output": "0" }, { "input": "1\n8", "output": "0" }, { "input": "6\n1 1 1 3 2 9", "output": "0" }, { "input": "5\n8 9 3 1 9", "output": "0" }, { "input": "6\n1 5 2 1 7 11", "output": "0" }, { "input": "8\n1 6 11 8 5 10 7 8", "output": "3" }, { "input": "3\n4 9 6", "output": "15" }, { "input": "2\n4 8", "output": "0" }, { "input": "3\n1 1 5", "output": "0" }, { "input": "5\n4 5 5 2 11", "output": "0" }, { "input": "6\n1 7 2 8 8 2", "output": "10" }, { "input": "5\n3 9 3 2 3", "output": "10" }, { "input": "7\n6 6 1 1 1 2 3", "output": "5" }, { "input": "7\n11 1 2 8 10 5 9", "output": "2" }, { "input": "7\n4 5 1 10 10 4 1", "output": "11" }, { "input": "10\n5 5 10 10 10 2 4 3 4 10", "output": "0" }, { "input": "8\n4 7 11 3 11 3 1 1", "output": "10" }, { "input": "2\n5 9", "output": "0" }, { "input": "6\n2 1 10 2 7 5", "output": "15" }, { "input": "6\n3 5 9 10 5 4", "output": "14" }, { "input": "8\n3 5 8 10 3 4 2 10", "output": "0" }, { "input": "7\n1 6 5 3 9 5 9", "output": "0" }, { "input": "8\n7 2 6 3 6 4 1 8", "output": "0" }, { "input": "10\n8 10 6 10 4 3 4 6 7 4", "output": "14" }, { "input": "2\n1 5", "output": "0" }, { "input": "10\n5 6 4 8 11 4 10 4 8 4", "output": "15" }, { "input": "2\n3 7", "output": "0" }, { "input": "3\n4 10 3", "output": "9" }, { "input": "5\n5 2 2 11 2", "output": "9" } ]
1,491,313,235
335
Python 3
RUNTIME_ERROR
TESTS
0
46
4,608,000
x = input() arr = [] for _ in range(4): arr += [input()] print(a)
Title: INTERCALC Time Limit: None seconds Memory Limit: None megabytes Problem Description: DO YOU EXPECT ME TO FIND THIS OUT? WHAT BASE AND/XOR LANGUAGE INCLUDES string? DON'T BYTE OF MORE THAN YOU CAN CHEW YOU CAN ONLY DISTORT THE LARGEST OF MATHEMATICS SO FAR SAYING "ABRACADABRA" WITHOUT A MAGIC AND WON'T DO YOU ANY GOOD THE LAST STACK RUPTURES. ALL DIE. OH, THE EMBARRASSMENT! I HAVE NO ARRAY AND I MUST SCREAM ELEMENTS MAY NOT BE STORED IN WEST HYPERSPACE Input Specification: The first line of input data contains a single integer *n* (1<=≤<=*n*<=≤<=10). The second line of input data contains *n* space-separated integers *a**i* (1<=≤<=*a**i*<=≤<=11). Output Specification: Output a single integer. Demo Input: ['4\n2 5 3 1\n'] Demo Output: ['4\n'] Note: none
```python x = input() arr = [] for _ in range(4): arr += [input()] print(a) ```
-1
572
B
Order Book
PROGRAMMING
1,300
[ "data structures", "greedy", "implementation", "sortings" ]
null
null
In this task you need to process a set of stock exchange orders and use them to create order book. An order is an instruction of some participant to buy or sell stocks on stock exchange. The order number *i* has price *p**i*, direction *d**i* — buy or sell, and integer *q**i*. This means that the participant is ready to buy or sell *q**i* stocks at price *p**i* for one stock. A value *q**i* is also known as a volume of an order. All orders with the same price *p* and direction *d* are merged into one aggregated order with price *p* and direction *d*. The volume of such order is a sum of volumes of the initial orders. An order book is a list of aggregated orders, the first part of which contains sell orders sorted by price in descending order, the second contains buy orders also sorted by price in descending order. An order book of depth *s* contains *s* best aggregated orders for each direction. A buy order is better if it has higher price and a sell order is better if it has lower price. If there are less than *s* aggregated orders for some direction then all of them will be in the final order book. You are given *n* stock exhange orders. Your task is to print order book of depth *s* for these orders.
The input starts with two positive integers *n* and *s* (1<=≤<=*n*<=≤<=1000,<=1<=≤<=*s*<=≤<=50), the number of orders and the book depth. Next *n* lines contains a letter *d**i* (either 'B' or 'S'), an integer *p**i* (0<=≤<=*p**i*<=≤<=105) and an integer *q**i* (1<=≤<=*q**i*<=≤<=104) — direction, price and volume respectively. The letter 'B' means buy, 'S' means sell. The price of any sell order is higher than the price of any buy order.
Print no more than 2*s* lines with aggregated orders from order book of depth *s*. The output format for orders should be the same as in input.
[ "6 2\nB 10 3\nS 50 2\nS 40 1\nS 50 6\nB 20 4\nB 25 10\n" ]
[ "S 50 8\nS 40 1\nB 25 10\nB 20 4\n" ]
Denote (x, y) an order with price *x* and volume *y*. There are 3 aggregated buy orders (10, 3), (20, 4), (25, 10) and two sell orders (50, 8), (40, 1) in the sample. You need to print no more than two best orders for each direction, so you shouldn't print the order (10 3) having the worst price among buy orders.
1,000
[ { "input": "6 2\nB 10 3\nS 50 2\nS 40 1\nS 50 6\nB 20 4\nB 25 10", "output": "S 50 8\nS 40 1\nB 25 10\nB 20 4" }, { "input": "2 1\nB 7523 5589\nS 69799 1711", "output": "S 69799 1711\nB 7523 5589" }, { "input": "1 1\nB 48259 991", "output": "B 48259 991" }, { "input": "1 50\nB 47828 7726", "output": "B 47828 7726" }, { "input": "1 1\nS 95992 7257", "output": "S 95992 7257" }, { "input": "1 50\nS 72218 8095", "output": "S 72218 8095" }, { "input": "2 50\nB 758 9290\nS 86168 3367", "output": "S 86168 3367\nB 758 9290" }, { "input": "3 3\nB 5878 1568\nS 60238 4895\nS 76276 1905", "output": "S 76276 1905\nS 60238 4895\nB 5878 1568" }, { "input": "6 2\nB 0 1\nS 1 1\nS 1 1\nS 1 1\nB 0 1\nB 0 1", "output": "S 1 3\nB 0 3" }, { "input": "2 2\nS 1 1\nB 0 2", "output": "S 1 1\nB 0 2" }, { "input": "2 1\nS 10 1\nB 0 1", "output": "S 10 1\nB 0 1" }, { "input": "2 10\nB 0 1\nS 100000 1", "output": "S 100000 1\nB 0 1" }, { "input": "2 1\nS 1 1\nB 0 1", "output": "S 1 1\nB 0 1" }, { "input": "2 1\nB 0 100\nS 1 100", "output": "S 1 100\nB 0 100" }, { "input": "2 2\nB 0 3\nS 10 3", "output": "S 10 3\nB 0 3" }, { "input": "2 10\nB 0 1\nS 1 1", "output": "S 1 1\nB 0 1" }, { "input": "2 50\nB 2 5\nB 0 1", "output": "B 2 5\nB 0 1" } ]
1,440,263,302
2,302
Python 3
WRONG_ANSWER
PRETESTS
9
62
0
n, s = map(int,input().split()) z = {} buy = 0 for i in range(n): d, p, q = input().split() p, q = map(int, [p, q]) if p not in z: if d == 'B': buy += 1 z[p] = 0 z[p] += q z = sorted(map(lambda x: (x, z[x]), z.keys())) g = len(z) - 1 for i in range(min(s, len(z) - buy)): print('S', *z[g - i]) g = buy - 1 for i in range(min(s, buy)): print('B', *z[g - i])
Title: Order Book Time Limit: None seconds Memory Limit: None megabytes Problem Description: In this task you need to process a set of stock exchange orders and use them to create order book. An order is an instruction of some participant to buy or sell stocks on stock exchange. The order number *i* has price *p**i*, direction *d**i* — buy or sell, and integer *q**i*. This means that the participant is ready to buy or sell *q**i* stocks at price *p**i* for one stock. A value *q**i* is also known as a volume of an order. All orders with the same price *p* and direction *d* are merged into one aggregated order with price *p* and direction *d*. The volume of such order is a sum of volumes of the initial orders. An order book is a list of aggregated orders, the first part of which contains sell orders sorted by price in descending order, the second contains buy orders also sorted by price in descending order. An order book of depth *s* contains *s* best aggregated orders for each direction. A buy order is better if it has higher price and a sell order is better if it has lower price. If there are less than *s* aggregated orders for some direction then all of them will be in the final order book. You are given *n* stock exhange orders. Your task is to print order book of depth *s* for these orders. Input Specification: The input starts with two positive integers *n* and *s* (1<=≤<=*n*<=≤<=1000,<=1<=≤<=*s*<=≤<=50), the number of orders and the book depth. Next *n* lines contains a letter *d**i* (either 'B' or 'S'), an integer *p**i* (0<=≤<=*p**i*<=≤<=105) and an integer *q**i* (1<=≤<=*q**i*<=≤<=104) — direction, price and volume respectively. The letter 'B' means buy, 'S' means sell. The price of any sell order is higher than the price of any buy order. Output Specification: Print no more than 2*s* lines with aggregated orders from order book of depth *s*. The output format for orders should be the same as in input. Demo Input: ['6 2\nB 10 3\nS 50 2\nS 40 1\nS 50 6\nB 20 4\nB 25 10\n'] Demo Output: ['S 50 8\nS 40 1\nB 25 10\nB 20 4\n'] Note: Denote (x, y) an order with price *x* and volume *y*. There are 3 aggregated buy orders (10, 3), (20, 4), (25, 10) and two sell orders (50, 8), (40, 1) in the sample. You need to print no more than two best orders for each direction, so you shouldn't print the order (10 3) having the worst price among buy orders.
```python n, s = map(int,input().split()) z = {} buy = 0 for i in range(n): d, p, q = input().split() p, q = map(int, [p, q]) if p not in z: if d == 'B': buy += 1 z[p] = 0 z[p] += q z = sorted(map(lambda x: (x, z[x]), z.keys())) g = len(z) - 1 for i in range(min(s, len(z) - buy)): print('S', *z[g - i]) g = buy - 1 for i in range(min(s, buy)): print('B', *z[g - i]) ```
0
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,675,750,711
2,147,483,647
PyPy 3-64
TIME_LIMIT_EXCEEDED
TESTS
5
1,000
14,131,200
def check_hypothesis(n, notebooks): for i in range(n-1): for j in range(i+1, n): if notebooks[i][0] < notebooks[j][0] and notebooks[i][1] > notebooks[j][1]: return "Happy Alex" return "Poor Alex" n = int(input().strip()) notebooks = [list(map(int, input().strip().split())) for i in range(n)] print(check_hypothesis(n, notebooks))
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 def check_hypothesis(n, notebooks): for i in range(n-1): for j in range(i+1, n): if notebooks[i][0] < notebooks[j][0] and notebooks[i][1] > notebooks[j][1]: return "Happy Alex" return "Poor Alex" n = int(input().strip()) notebooks = [list(map(int, input().strip().split())) for i in range(n)] print(check_hypothesis(n, notebooks)) ```
0
251
A
Points on Line
PROGRAMMING
1,300
[ "binary search", "combinatorics", "two pointers" ]
null
null
Little Petya likes points a lot. Recently his mom has presented him *n* points lying on the line *OX*. Now Petya is wondering in how many ways he can choose three distinct points so that the distance between the two farthest of them doesn't exceed *d*. Note that the order of the points inside the group of three chosen points doesn't matter.
The first line contains two integers: *n* and *d* (1<=≤<=*n*<=≤<=105; 1<=≤<=*d*<=≤<=109). The next line contains *n* integers *x*1,<=*x*2,<=...,<=*x**n*, their absolute value doesn't exceed 109 — the *x*-coordinates of the points that Petya has got. It is guaranteed that the coordinates of the points in the input strictly increase.
Print a single integer — the number of groups of three points, where the distance between two farthest points doesn't exceed *d*. 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.
[ "4 3\n1 2 3 4\n", "4 2\n-3 -2 -1 0\n", "5 19\n1 10 20 30 50\n" ]
[ "4\n", "2\n", "1\n" ]
In the first sample any group of three points meets our conditions. In the seconds sample only 2 groups of three points meet our conditions: {-3, -2, -1} and {-2, -1, 0}. In the third sample only one group does: {1, 10, 20}.
500
[ { "input": "4 3\n1 2 3 4", "output": "4" }, { "input": "4 2\n-3 -2 -1 0", "output": "2" }, { "input": "5 19\n1 10 20 30 50", "output": "1" }, { "input": "10 5\n31 36 43 47 48 50 56 69 71 86", "output": "2" }, { "input": "10 50\n1 4 20 27 65 79 82 83 99 100", "output": "25" }, { "input": "10 90\n24 27 40 41 61 69 73 87 95 97", "output": "120" }, { "input": "100 100\n-98 -97 -96 -93 -92 -91 -90 -87 -86 -84 -81 -80 -79 -78 -76 -75 -73 -71 -69 -67 -65 -64 -63 -62 -61 -54 -51 -50 -49 -48 -46 -45 -44 -37 -36 -33 -30 -28 -27 -16 -15 -13 -12 -10 -9 -7 -6 -5 -4 2 3 5 8 9 10 11 13 14 15 16 17 19 22 24 25 26 27 28 30 31 32 36 40 43 45 46 47 50 51 52 53 58 60 63 69 70 73 78 80 81 82 85 88 89 90 91 95 96 97 99", "output": "79351" }, { "input": "1 14751211\n847188590", "output": "0" }, { "input": "2 1000000000\n-907894512 -289906312", "output": "0" }, { "input": "2 1000000000\n-14348867 1760823", "output": "0" }, { "input": "3 1000000000\n-5 -1 1", "output": "1" } ]
1,678,868,671
2,147,483,647
PyPy 3-64
OK
TESTS
39
186
14,336,000
n, d = map(int, input().split()) dots = list(map(int, input().split())) cursor = 0 ans = 0 if n > 2: for i in range(2, n): while dots[i]-dots[cursor]>d: cursor+=1 k=i-cursor ans+=k*(k-1)//2 print(ans) else: print(0)
Title: Points on Line Time Limit: None seconds Memory Limit: None megabytes Problem Description: Little Petya likes points a lot. Recently his mom has presented him *n* points lying on the line *OX*. Now Petya is wondering in how many ways he can choose three distinct points so that the distance between the two farthest of them doesn't exceed *d*. Note that the order of the points inside the group of three chosen points doesn't matter. Input Specification: The first line contains two integers: *n* and *d* (1<=≤<=*n*<=≤<=105; 1<=≤<=*d*<=≤<=109). The next line contains *n* integers *x*1,<=*x*2,<=...,<=*x**n*, their absolute value doesn't exceed 109 — the *x*-coordinates of the points that Petya has got. It is guaranteed that the coordinates of the points in the input strictly increase. Output Specification: Print a single integer — the number of groups of three points, where the distance between two farthest points doesn't exceed *d*. 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: ['4 3\n1 2 3 4\n', '4 2\n-3 -2 -1 0\n', '5 19\n1 10 20 30 50\n'] Demo Output: ['4\n', '2\n', '1\n'] Note: In the first sample any group of three points meets our conditions. In the seconds sample only 2 groups of three points meet our conditions: {-3, -2, -1} and {-2, -1, 0}. In the third sample only one group does: {1, 10, 20}.
```python n, d = map(int, input().split()) dots = list(map(int, input().split())) cursor = 0 ans = 0 if n > 2: for i in range(2, n): while dots[i]-dots[cursor]>d: cursor+=1 k=i-cursor ans+=k*(k-1)//2 print(ans) else: print(0) ```
3
450
B
Jzzhu and Sequences
PROGRAMMING
1,300
[ "implementation", "math" ]
null
null
Jzzhu has invented a kind of sequences, they meet the following property: You are given *x* and *y*, please calculate *f**n* modulo 1000000007 (109<=+<=7).
The first line contains two integers *x* and *y* (|*x*|,<=|*y*|<=≤<=109). The second line contains a single integer *n* (1<=≤<=*n*<=≤<=2·109).
Output a single integer representing *f**n* modulo 1000000007 (109<=+<=7).
[ "2 3\n3\n", "0 -1\n2\n" ]
[ "1\n", "1000000006\n" ]
In the first sample, *f*<sub class="lower-index">2</sub> = *f*<sub class="lower-index">1</sub> + *f*<sub class="lower-index">3</sub>, 3 = 2 + *f*<sub class="lower-index">3</sub>, *f*<sub class="lower-index">3</sub> = 1. In the second sample, *f*<sub class="lower-index">2</sub> =  - 1;  - 1 modulo (10<sup class="upper-index">9</sup> + 7) equals (10<sup class="upper-index">9</sup> + 6).
1,000
[ { "input": "2 3\n3", "output": "1" }, { "input": "0 -1\n2", "output": "1000000006" }, { "input": "-9 -11\n12345", "output": "1000000005" }, { "input": "0 0\n1000000000", "output": "0" }, { "input": "-1000000000 1000000000\n2000000000", "output": "1000000000" }, { "input": "-12345678 12345678\n1912345678", "output": "12345678" }, { "input": "728374857 678374857\n1928374839", "output": "950000007" }, { "input": "278374837 992837483\n1000000000", "output": "721625170" }, { "input": "-693849384 502938493\n982838498", "output": "502938493" }, { "input": "-783928374 983738273\n992837483", "output": "16261734" }, { "input": "-872837483 -682738473\n999999999", "output": "190099010" }, { "input": "-892837483 -998273847\n999283948", "output": "892837483" }, { "input": "-283938494 738473848\n1999999999", "output": "716061513" }, { "input": "-278374857 819283838\n1", "output": "721625150" }, { "input": "-1000000000 123456789\n1", "output": "7" }, { "input": "-529529529 -524524524\n2", "output": "475475483" }, { "input": "1 2\n2000000000", "output": "2" }, { "input": "-1 -2\n2000000000", "output": "1000000005" }, { "input": "1 2\n1999999999", "output": "1" }, { "input": "1 2\n1999999998", "output": "1000000006" }, { "input": "1 2\n1999999997", "output": "1000000005" }, { "input": "1 2\n1999999996", "output": "1000000006" }, { "input": "69975122 366233206\n1189460676", "output": "703741923" }, { "input": "812229413 904420051\n806905621", "output": "812229413" }, { "input": "872099024 962697902\n1505821695", "output": "90598878" }, { "input": "887387283 909670917\n754835014", "output": "112612724" }, { "input": "37759824 131342932\n854621399", "output": "868657075" }, { "input": "-246822123 800496170\n626323615", "output": "753177884" }, { "input": "-861439463 974126967\n349411083", "output": "835566423" }, { "input": "-69811049 258093841\n1412447", "output": "741906166" }, { "input": "844509330 -887335829\n123329059", "output": "844509330" }, { "input": "83712471 -876177148\n1213284777", "output": "40110388" }, { "input": "598730524 -718984219\n1282749880", "output": "401269483" }, { "input": "-474244697 -745885656\n1517883612", "output": "271640959" }, { "input": "-502583588 -894906953\n1154189557", "output": "497416419" }, { "input": "-636523651 -873305815\n154879215", "output": "763217843" }, { "input": "721765550 594845720\n78862386", "output": "126919830" }, { "input": "364141461 158854993\n1337196589", "output": "364141461" }, { "input": "878985260 677031952\n394707801", "output": "798046699" }, { "input": "439527072 -24854079\n1129147002", "output": "464381151" }, { "input": "840435009 -612103127\n565968986", "output": "387896880" }, { "input": "875035447 -826471373\n561914518", "output": "124964560" }, { "input": "-342526698 305357084\n70776744", "output": "352116225" }, { "input": "-903244186 899202229\n1527859274", "output": "899202229" }, { "input": "-839482546 815166320\n1127472130", "output": "839482546" }, { "input": "-976992569 -958313041\n1686580818", "output": "981320479" }, { "input": "-497338894 -51069176\n737081851", "output": "502661113" }, { "input": "-697962643 -143148799\n1287886520", "output": "856851208" }, { "input": "-982572938 -482658433\n1259858332", "output": "982572938" }, { "input": "123123 78817\n2000000000", "output": "78817" }, { "input": "1000000000 -1000000000\n3", "output": "14" }, { "input": "-1000000000 1000000000\n6", "output": "14" }, { "input": "2 3\n6", "output": "1000000006" }, { "input": "0 -1\n6", "output": "1" }, { "input": "500000000 -1000000000\n600000003", "output": "500000014" }, { "input": "-1000000000 1000000000\n3", "output": "999999993" }, { "input": "1 3\n6", "output": "1000000005" }, { "input": "1 2\n12", "output": "1000000006" }, { "input": "7 -1000000000\n3", "output": "0" }, { "input": "-999999997 999999997\n6", "output": "20" }, { "input": "3 4\n6", "output": "1000000006" }, { "input": "-1 2\n6", "output": "1000000004" }, { "input": "2 3\n12", "output": "1000000006" }, { "input": "4 18\n6", "output": "999999993" }, { "input": "1 2\n6", "output": "1000000006" }, { "input": "1000000000 -1000000000\n6", "output": "999999993" }, { "input": "999999999 -999999999\n3", "output": "16" }, { "input": "-1 0\n1", "output": "1000000006" }, { "input": "1000000000 -1000000000\n9", "output": "14" }, { "input": "999999999 -1000000000\n12", "output": "999999992" }, { "input": "1000000000 -7\n3", "output": "0" }, { "input": "-5 5\n6", "output": "999999997" }, { "input": "5 9\n6", "output": "1000000003" }, { "input": "-15 -10\n1", "output": "999999992" } ]
1,632,648,681
2,147,483,647
PyPy 3
MEMORY_LIMIT_EXCEEDED
TESTS
4
998
268,390,400
l=list(map(int,input().split())) n=int(input()) if l[0]==0 and l[1]==0: print(0) else: for i in range(n-2): l.append(l[-1]-l[-2]) print(l[n-1]%(10**9+7))
Title: Jzzhu and Sequences Time Limit: None seconds Memory Limit: None megabytes Problem Description: Jzzhu has invented a kind of sequences, they meet the following property: You are given *x* and *y*, please calculate *f**n* modulo 1000000007 (109<=+<=7). Input Specification: The first line contains two integers *x* and *y* (|*x*|,<=|*y*|<=≤<=109). The second line contains a single integer *n* (1<=≤<=*n*<=≤<=2·109). Output Specification: Output a single integer representing *f**n* modulo 1000000007 (109<=+<=7). Demo Input: ['2 3\n3\n', '0 -1\n2\n'] Demo Output: ['1\n', '1000000006\n'] Note: In the first sample, *f*<sub class="lower-index">2</sub> = *f*<sub class="lower-index">1</sub> + *f*<sub class="lower-index">3</sub>, 3 = 2 + *f*<sub class="lower-index">3</sub>, *f*<sub class="lower-index">3</sub> = 1. In the second sample, *f*<sub class="lower-index">2</sub> =  - 1;  - 1 modulo (10<sup class="upper-index">9</sup> + 7) equals (10<sup class="upper-index">9</sup> + 6).
```python l=list(map(int,input().split())) n=int(input()) if l[0]==0 and l[1]==0: print(0) else: for i in range(n-2): l.append(l[-1]-l[-2]) print(l[n-1]%(10**9+7)) ```
0
844
A
Diversity
PROGRAMMING
1,000
[ "greedy", "implementation", "strings" ]
null
null
Calculate the minimum number of characters you need to change in the string *s*, so that it contains at least *k* different letters, or print that it is impossible. String *s* consists only of lowercase Latin letters, and it is allowed to change characters only to lowercase Latin letters too.
First line of input contains string *s*, consisting only of lowercase Latin letters (1<=≤<=|*s*|<=≤<=1000, |*s*| denotes the length of *s*). Second line of input contains integer *k* (1<=≤<=*k*<=≤<=26).
Print single line with a minimum number of necessary changes, or the word «impossible» (without quotes) if it is impossible.
[ "yandex\n6\n", "yahoo\n5\n", "google\n7\n" ]
[ "0\n", "1\n", "impossible\n" ]
In the first test case string contains 6 different letters, so we don't need to change anything. In the second test case string contains 4 different letters: {'*a*', '*h*', '*o*', '*y*'}. To get 5 different letters it is necessary to change one occurrence of '*o*' to some letter, which doesn't occur in the string, for example, {'*b*'}. In the third test case, it is impossible to make 7 different letters because the length of the string is 6.
500
[ { "input": "yandex\n6", "output": "0" }, { "input": "yahoo\n5", "output": "1" }, { "input": "google\n7", "output": "impossible" }, { "input": "a\n1", "output": "0" }, { "input": "z\n2", "output": "impossible" }, { "input": "fwgfrwgkuwghfiruhewgirueguhergiqrbvgrgf\n26", "output": "14" }, { "input": "nfevghreuoghrueighoqghbnebvnejbvnbgneluqe\n26", "output": "12" }, { "input": "a\n3", "output": "impossible" }, { "input": "smaxpqplaqqbxuqxalqmbmmgubbpspxhawbxsuqhhegpmmpebqmqpbbeplwaepxmsahuepuhuhwxeqmmlgqubuaxehwuwasgxpqmugbmuawuhwqlswllssueglbxepbmwgs\n1", "output": "0" }, { "input": "cuguccgcugcugucgggggcgcgucgucugcuuuccccuugccg\n4", "output": "1" }, { "input": "fcfccfcfccfcfcffcffffffcfccfccfcffccccfcffffccfccfcffcfcccccffcfffcccffcfccfffffcccfccffffffccfccccf\n20", "output": "18" }, { "input": "swmkwaruyv\n5", "output": "0" }, { "input": "tnbqpsuhkczmejirvyfdolxwga\n22", "output": "0" }, { "input": "abcde\n3", "output": "0" }, { "input": "abb\n1", "output": "0" }, { "input": "aaaa\n1", "output": "0" }, { "input": "abcde\n2", "output": "0" }, { "input": "yandex\n4", "output": "0" }, { "input": "aaabbbccc\n1", "output": "0" }, { "input": "abcd\n2", "output": "0" }, { "input": "asdfgh\n2", "output": "0" }, { "input": "aab\n1", "output": "0" }, { "input": "mynameissako\n5", "output": "0" }, { "input": "abcde\n1", "output": "0" }, { "input": "abcd\n3", "output": "0" }, { "input": "abcdef\n2", "output": "0" }, { "input": "abcdefg\n4", "output": "0" }, { "input": "abc\n1", "output": "0" }, { "input": "asdafjsgljdllgjdgkl\n5", "output": "0" }, { "input": "yaay\n3", "output": "1" }, { "input": "yaay\n4", "output": "2" }, { "input": "zzzzzz\n2", "output": "1" } ]
1,506,088,650
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
11
62
0
s = input() k = int(input()) a = [s[0]] if len(s) < k: print ("impossible") else: for i in s: b = True for j in a: if j == i: b = False if b == True: a.append(i) m = k - len(a) print (m) # 1506088648140
Title: Diversity Time Limit: None seconds Memory Limit: None megabytes Problem Description: Calculate the minimum number of characters you need to change in the string *s*, so that it contains at least *k* different letters, or print that it is impossible. String *s* consists only of lowercase Latin letters, and it is allowed to change characters only to lowercase Latin letters too. Input Specification: First line of input contains string *s*, consisting only of lowercase Latin letters (1<=≤<=|*s*|<=≤<=1000, |*s*| denotes the length of *s*). Second line of input contains integer *k* (1<=≤<=*k*<=≤<=26). Output Specification: Print single line with a minimum number of necessary changes, or the word «impossible» (without quotes) if it is impossible. Demo Input: ['yandex\n6\n', 'yahoo\n5\n', 'google\n7\n'] Demo Output: ['0\n', '1\n', 'impossible\n'] Note: In the first test case string contains 6 different letters, so we don't need to change anything. In the second test case string contains 4 different letters: {'*a*', '*h*', '*o*', '*y*'}. To get 5 different letters it is necessary to change one occurrence of '*o*' to some letter, which doesn't occur in the string, for example, {'*b*'}. In the third test case, it is impossible to make 7 different letters because the length of the string is 6.
```python s = input() k = int(input()) a = [s[0]] if len(s) < k: print ("impossible") else: for i in s: b = True for j in a: if j == i: b = False if b == True: a.append(i) m = k - len(a) print (m) # 1506088648140 ```
0
59
A
Word
PROGRAMMING
800
[ "implementation", "strings" ]
A. Word
2
256
Vasya is very upset that many people on the Net mix uppercase and lowercase letters in one word. That's why he decided to invent an extension for his favorite browser that would change the letters' register in every word so that it either only consisted of lowercase letters or, vice versa, only of uppercase ones. At that as little as possible letters should be changed in the word. For example, the word HoUse must be replaced with house, and the word ViP — with VIP. If a word contains an equal number of uppercase and lowercase letters, you should replace all the letters with lowercase ones. For example, maTRIx should be replaced by matrix. Your task is to use the given method on one given word.
The first line contains a word *s* — it consists of uppercase and lowercase Latin letters and possesses the length from 1 to 100.
Print the corrected word *s*. If the given word *s* has strictly more uppercase letters, make the word written in the uppercase register, otherwise - in the lowercase one.
[ "HoUse\n", "ViP\n", "maTRIx\n" ]
[ "house\n", "VIP\n", "matrix\n" ]
none
500
[ { "input": "HoUse", "output": "house" }, { "input": "ViP", "output": "VIP" }, { "input": "maTRIx", "output": "matrix" }, { "input": "BNHWpnpawg", "output": "bnhwpnpawg" }, { "input": "VTYGP", "output": "VTYGP" }, { "input": "CHNenu", "output": "chnenu" }, { "input": "ERPZGrodyu", "output": "erpzgrodyu" }, { "input": "KSXBXWpebh", "output": "KSXBXWPEBH" }, { "input": "qvxpqullmcbegsdskddortcvxyqlbvxmmkhevovnezubvpvnrcajpxraeaxizgaowtfkzywvhnbgzsxbhkaipcmoumtikkiyyaiv", "output": "qvxpqullmcbegsdskddortcvxyqlbvxmmkhevovnezubvpvnrcajpxraeaxizgaowtfkzywvhnbgzsxbhkaipcmoumtikkiyyaiv" }, { "input": "Amnhaxtaopjzrkqlbroiyipitndczpunwygstmzevgyjdzyanxkdqnvgkikfabwouwkkbzuiuvgvxgpizsvqsbwepktpdrgdkmfd", "output": "amnhaxtaopjzrkqlbroiyipitndczpunwygstmzevgyjdzyanxkdqnvgkikfabwouwkkbzuiuvgvxgpizsvqsbwepktpdrgdkmfd" }, { "input": "ISAGFJFARYFBLOPQDSHWGMCNKMFTLVFUGNJEWGWNBLXUIATXEkqiettmmjgydwcpafqrppdsrrrtguinqbgmzzfqwonkpgpcwenv", "output": "isagfjfaryfblopqdshwgmcnkmftlvfugnjewgwnblxuiatxekqiettmmjgydwcpafqrppdsrrrtguinqbgmzzfqwonkpgpcwenv" }, { "input": "XHRPXZEGHSOCJPICUIXSKFUZUPYTSGJSDIYBCMNMNBPNDBXLXBzhbfnqvwcffvrdhtickyqhupmcehlsyvncqmfhautvxudqdhgg", "output": "xhrpxzeghsocjpicuixskfuzupytsgjsdiybcmnmnbpndbxlxbzhbfnqvwcffvrdhtickyqhupmcehlsyvncqmfhautvxudqdhgg" }, { "input": "RJIQZMJCIMSNDBOHBRAWIENODSALETAKGKPYUFGVEFGCBRENZGAdkcetqjljtmttlonpekcovdzebzdkzggwfsxhapmjkdbuceak", "output": "RJIQZMJCIMSNDBOHBRAWIENODSALETAKGKPYUFGVEFGCBRENZGADKCETQJLJTMTTLONPEKCOVDZEBZDKZGGWFSXHAPMJKDBUCEAK" }, { "input": "DWLWOBHNMMGTFOLFAECKBRNNGLYLYDXTGTVRLMEESZOIUATZZZXUFUZDLSJXMEVRTESSFBWLNZZCLCQWEVNNUCXYVHNGNXHCBDFw", "output": "DWLWOBHNMMGTFOLFAECKBRNNGLYLYDXTGTVRLMEESZOIUATZZZXUFUZDLSJXMEVRTESSFBWLNZZCLCQWEVNNUCXYVHNGNXHCBDFW" }, { "input": "NYCNHJWGBOCOTSPETKKHVWFGAQYNHOVJWJHCIEFOUQZXOYUIEQDZALFKTEHTVDBVJMEUBJUBCMNVPWGDPNCHQHZJRCHYRFPVIGUB", "output": "NYCNHJWGBOCOTSPETKKHVWFGAQYNHOVJWJHCIEFOUQZXOYUIEQDZALFKTEHTVDBVJMEUBJUBCMNVPWGDPNCHQHZJRCHYRFPVIGUB" }, { "input": "igxoixiecetohtgjgbqzvlaobkhstejxdklghowtvwunnnvauriohuspsdmpzckprwajyxldoyckgjivjpmbfqtszmtocovxwge", "output": "igxoixiecetohtgjgbqzvlaobkhstejxdklghowtvwunnnvauriohuspsdmpzckprwajyxldoyckgjivjpmbfqtszmtocovxwge" }, { "input": "Ykkekrsqolzryiwsmdlnbmfautxxxauoojrddvwklgnlyrfcvhorrzbmtcrvpaypqhcffdqhwziipyyskcmztjprjqvmzzqhqnw", "output": "ykkekrsqolzryiwsmdlnbmfautxxxauoojrddvwklgnlyrfcvhorrzbmtcrvpaypqhcffdqhwziipyyskcmztjprjqvmzzqhqnw" }, { "input": "YQOMLKYAORUQQUCQZCDYMIVDHGWZFFRMUVTAWCHERFPMNRYRIkgqrciokgajamehmcxgerpudvsqyonjonsxgbnefftzmygncks", "output": "yqomlkyaoruqqucqzcdymivdhgwzffrmuvtawcherfpmnryrikgqrciokgajamehmcxgerpudvsqyonjonsxgbnefftzmygncks" }, { "input": "CDOZDPBVVVHNBJVBYHEOXWFLJKRWJCAJMIFCOZWWYFKVWOGTVJcuusigdqfkumewjtdyitveeiaybwrhomrwmpdipjwiuxfnwuz", "output": "CDOZDPBVVVHNBJVBYHEOXWFLJKRWJCAJMIFCOZWWYFKVWOGTVJCUUSIGDQFKUMEWJTDYITVEEIAYBWRHOMRWMPDIPJWIUXFNWUZ" }, { "input": "WHIUVEXHVOOIJIDVJVPQUBJMEVPMPDKQWJKFBZSGSKUXMIPPMJWuckzcpxosodcjaaakvlxpbiigsiauviilylnnqlyucziihqg", "output": "WHIUVEXHVOOIJIDVJVPQUBJMEVPMPDKQWJKFBZSGSKUXMIPPMJWUCKZCPXOSODCJAAAKVLXPBIIGSIAUVIILYLNNQLYUCZIIHQG" }, { "input": "VGHUNFOXKETUYMZDJNGTAOIOANYXSGYNFOGOFFLDAWEUKYFOZXCJTCAFXZYLQZERYZLRSQXYQGAPCSUDPMEYTNCTTTMFAGVDWBO", "output": "VGHUNFOXKETUYMZDJNGTAOIOANYXSGYNFOGOFFLDAWEUKYFOZXCJTCAFXZYLQZERYZLRSQXYQGAPCSUDPMEYTNCTTTMFAGVDWBO" }, { "input": "EDUANHCQDOCJHFONTTSWBUJSTTIXBIXMAIUFSGFLXWAYIURTVAVZPYQDLAWIGCLMPHXCEFCJPFAAHXVNGQUFNHADAIUAZIDMHDd", "output": "EDUANHCQDOCJHFONTTSWBUJSTTIXBIXMAIUFSGFLXWAYIURTVAVZPYQDLAWIGCLMPHXCEFCJPFAAHXVNGQUFNHADAIUAZIDMHDD" }, { "input": "EBWOVSNLYTWWXrnovgugogtjahnmatomubebyxakas", "output": "ebwovsnlytwwxrnovgugogtjahnmatomubebyxakas" }, { "input": "AORNNDKTRLRVGDPXJKXFTPFpopuzrlqumrxssskvbm", "output": "AORNNDKTRLRVGDPXJKXFTPFPOPUZRLQUMRXSSSKVBM" }, { "input": "DBBZJCWQEVGYHEEUHJAWRHBDPsnplijbwtdibqrrheebfxqcvn", "output": "dbbzjcwqevgyheeuhjawrhbdpsnplijbwtdibqrrheebfxqcvn" }, { "input": "t", "output": "t" }, { "input": "N", "output": "N" }, { "input": "kv", "output": "kv" }, { "input": "Ur", "output": "ur" }, { "input": "CN", "output": "CN" } ]
1,661,731,182
2,147,483,647
PyPy 3-64
COMPILATION_ERROR
TESTS
0
0
0
s=input() if (sum(1 for c in s if c.isupper()) >len(s)/2) print(s.upper()) else : print(s.lower())
Title: Word Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: Vasya is very upset that many people on the Net mix uppercase and lowercase letters in one word. That's why he decided to invent an extension for his favorite browser that would change the letters' register in every word so that it either only consisted of lowercase letters or, vice versa, only of uppercase ones. At that as little as possible letters should be changed in the word. For example, the word HoUse must be replaced with house, and the word ViP — with VIP. If a word contains an equal number of uppercase and lowercase letters, you should replace all the letters with lowercase ones. For example, maTRIx should be replaced by matrix. Your task is to use the given method on one given word. Input Specification: The first line contains a word *s* — it consists of uppercase and lowercase Latin letters and possesses the length from 1 to 100. Output Specification: Print the corrected word *s*. If the given word *s* has strictly more uppercase letters, make the word written in the uppercase register, otherwise - in the lowercase one. Demo Input: ['HoUse\n', 'ViP\n', 'maTRIx\n'] Demo Output: ['house\n', 'VIP\n', 'matrix\n'] Note: none
```python s=input() if (sum(1 for c in s if c.isupper()) >len(s)/2) print(s.upper()) else : print(s.lower()) ```
-1
894
A
QAQ
PROGRAMMING
800
[ "brute force", "dp" ]
null
null
"QAQ" is a word to denote an expression of crying. Imagine "Q" as eyes with tears and "A" as a mouth. Now Diamond has given Bort a string consisting of only uppercase English letters of length *n*. There is a great number of "QAQ" in the string (Diamond is so cute!). Bort wants to know how many subsequences "QAQ" are in the string Diamond has given. Note that the letters "QAQ" don't have to be consecutive, but the order of letters should be exact.
The only line contains a string of length *n* (1<=≤<=*n*<=≤<=100). It's guaranteed that the string only contains uppercase English letters.
Print a single integer — the number of subsequences "QAQ" in the string.
[ "QAQAQYSYIOIWIN\n", "QAQQQZZYNOIWIN\n" ]
[ "4\n", "3\n" ]
In the first example there are 4 subsequences "QAQ": "QAQAQYSYIOIWIN", "QAQAQYSYIOIWIN", "QAQAQYSYIOIWIN", "QAQAQYSYIOIWIN".
500
[ { "input": "QAQAQYSYIOIWIN", "output": "4" }, { "input": "QAQQQZZYNOIWIN", "output": "3" }, { "input": "QA", "output": "0" }, { "input": "IAQVAQZLQBQVQFTQQQADAQJA", "output": "24" }, { "input": "QQAAQASGAYAAAAKAKAQIQEAQAIAAIAQQQQQ", "output": "378" }, { "input": "AMVFNFJIAVNQJWIVONQOAOOQSNQSONOASONAONQINAONAOIQONANOIQOANOQINAONOQINAONOXJCOIAQOAOQAQAQAQAQWWWAQQAQ", "output": "1077" }, { "input": "AAQQAXBQQBQQXBNQRJAQKQNAQNQVDQASAGGANQQQQTJFFQQQTQQA", "output": "568" }, { "input": "KAZXAVLPJQBQVQQQQQAPAQQGQTQVZQAAAOYA", "output": "70" }, { "input": "W", "output": "0" }, { "input": "DBA", "output": "0" }, { "input": "RQAWNACASAAKAGAAAAQ", "output": "10" }, { "input": "QJAWZAAOAAGIAAAAAOQATASQAEAAAAQFQQHPA", "output": "111" }, { "input": "QQKWQAQAAAAAAAAGAAVAQUEQQUMQMAQQQNQLAMAAAUAEAAEMAAA", "output": "411" }, { "input": "QQUMQAYAUAAGWAAAQSDAVAAQAAAASKQJJQQQQMAWAYYAAAAAAEAJAXWQQ", "output": "625" }, { "input": "QORZOYAQ", "output": "1" }, { "input": "QCQAQAGAWAQQQAQAVQAQQQQAQAQQQAQAAATQAAVAAAQQQQAAAUUQAQQNQQWQQWAQAAQQKQYAQAAQQQAAQRAQQQWBQQQQAPBAQGQA", "output": "13174" }, { "input": "QQAQQAKQFAQLQAAWAMQAZQAJQAAQQOACQQAAAYANAQAQQAQAAQQAOBQQJQAQAQAQQQAAAAABQQQAVNZAQQQQAMQQAFAAEAQAQHQT", "output": "10420" }, { "input": "AQEGQHQQKQAQQPQKAQQQAAAAQQQAQEQAAQAAQAQFSLAAQQAQOQQAVQAAAPQQAWAQAQAFQAXAQQQQTRLOQAQQJQNQXQQQQSQVDQQQ", "output": "12488" }, { "input": "QNQKQQQLASQBAVQQQQAAQQOQRJQQAQQQEQZUOANAADAAQQJAQAQARAAAQQQEQBHTQAAQAAAAQQMKQQQIAOJJQQAQAAADADQUQQQA", "output": "9114" }, { "input": "QQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQ", "output": "35937" }, { "input": "AMQQAAQAAQAAAAAAQQQBOAAANAAKQJCYQAE", "output": "254" }, { "input": "AYQBAEQGAQEOAKGIXLQJAIAKQAAAQPUAJAKAATFWQQAOQQQUFQYAQQMQHOKAAJXGFCARAQSATHAUQQAATQJJQDQRAANQQAE", "output": "2174" }, { "input": "AAQXAAQAYQAAAAGAQHVQYAGIVACADFAAQAAAAQZAAQMAKZAADQAQDAAQDAAAMQQOXYAQQQAKQBAAQQKAXQBJZDDLAAHQQ", "output": "2962" }, { "input": "AYQQYAVAMNIAUAAKBBQVACWKTQSAQZAAQAAASZJAWBCAALAARHACQAKQQAQAARPAQAAQAQAAZQUSHQAMFVFZQQQQSAQQXAA", "output": "2482" }, { "input": "LQMAQQARQAQBJQQQAGAAZQQXALQQAARQAQQQQAAQQAQQQAQQCAQQAQQAYQQQRAAZATQALYQQAAHHAAQHAAAAAAAAQQMAAQNAKQ", "output": "7768" }, { "input": "MAQQWAQOYQMAAAQAQPQZAOAAQAUAQNAAQAAAITQSAQAKAQKAQQWSQAAQQAGUCDQMQWKQUXKWQQAAQQAAQQZQDQQQAABXQUUXQOA", "output": "5422" }, { "input": "QTAAQDAQXAQQJQQQGAAAQQQQSBQZKAQQAQQQQEAQNUQBZCQLYQZQEQQAAQHQVAORKQVAQYQNASZQAARZAAGAAAAOQDCQ", "output": "3024" }, { "input": "QQWAQQGQQUZQQQLZAAQYQXQVAQFQUAQZUQZZQUKBHSHTQYLQAOQXAQQGAQQTQOAQARQADAJRAAQPQAQQUQAUAMAUVQAAAQQAWQ", "output": "4527" }, { "input": "QQAAQQAQVAQZQQQQAOEAQZPQIBQZACQQAFQQLAAQDATZQANHKYQQAQTAAFQRQAIQAJPWQAQTEIRXAEQQAYWAAAUKQQAQAQQQSQQH", "output": "6416" }, { "input": "AQQQQAQAAQQAQAQAAAAAAAAAQAQAAAAAQAQAQQQAQQQAAAQQQAAAAAAAQAAAAQQQQQQQAQQQQAQAAAQAAAAAQAQAAAAAQAQAAAA", "output": "14270" }, { "input": "AQQQQAQAAQQAQAQAAAAAAAAAQAQAAAAAQAQAQQQAQQQAAAQQQAAAAAAAQAAAAQQQQQQQAQQQQAQAAAQAAAAAQAQAAAAAQ", "output": "13136" }, { "input": "AQQQQAQAAQQAQAQAAAAAAAAAQAQAAAAAQAQAQQQAQQQAAAQQQAAAAAAAQAAAAQQQQQQQAQQQQAQAAAQAAAAAQAQAAAAAQAQAA", "output": "14270" }, { "input": "AQQQQAQAAQQAQAQAAAAAAAAAQAQAAAAAQAQAQQQAQQQAAAQQQAAAAAAAQAAAAQQQQQQQAQQQQAQAAAQAAAAAQAQAAAAAQQAA", "output": "14231" }, { "input": "QQQQQAQAAQQAQAQAAAAAAAAAQAQAAAAAQAQAQQQAQQQAAAQQQAAAAAAAQAAAAQQQQQQQAQQQQAQAAAQAAAAAQAQAAAAAQAQAA", "output": "15296" }, { "input": "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQ", "output": "0" }, { "input": "QQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA", "output": "0" }, { "input": "QQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQ", "output": "0" }, { "input": "QAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQA", "output": "20825" }, { "input": "AQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQ", "output": "20825" }, { "input": "Q", "output": "0" }, { "input": "A", "output": "0" }, { "input": "FFF", "output": "0" }, { "input": "AAAAAA", "output": "0" } ]
1,671,830,028
2,147,483,647
Python 3
OK
TESTS
43
46
0
s = input() Q_left = 0 Q_right = s.count('Q') num = 0 for let in s: if let == 'Q': Q_left += 1 Q_right -= 1 elif let == 'A': num += Q_left * Q_right print(num)
Title: QAQ Time Limit: None seconds Memory Limit: None megabytes Problem Description: "QAQ" is a word to denote an expression of crying. Imagine "Q" as eyes with tears and "A" as a mouth. Now Diamond has given Bort a string consisting of only uppercase English letters of length *n*. There is a great number of "QAQ" in the string (Diamond is so cute!). Bort wants to know how many subsequences "QAQ" are in the string Diamond has given. Note that the letters "QAQ" don't have to be consecutive, but the order of letters should be exact. Input Specification: The only line contains a string of length *n* (1<=≤<=*n*<=≤<=100). It's guaranteed that the string only contains uppercase English letters. Output Specification: Print a single integer — the number of subsequences "QAQ" in the string. Demo Input: ['QAQAQYSYIOIWIN\n', 'QAQQQZZYNOIWIN\n'] Demo Output: ['4\n', '3\n'] Note: In the first example there are 4 subsequences "QAQ": "QAQAQYSYIOIWIN", "QAQAQYSYIOIWIN", "QAQAQYSYIOIWIN", "QAQAQYSYIOIWIN".
```python s = input() Q_left = 0 Q_right = s.count('Q') num = 0 for let in s: if let == 'Q': Q_left += 1 Q_right -= 1 elif let == 'A': num += Q_left * Q_right print(num) ```
3
670
A
Holidays
PROGRAMMING
900
[ "brute force", "constructive algorithms", "greedy", "math" ]
null
null
On the planet Mars a year lasts exactly *n* days (there are no leap years on Mars). But Martians have the same weeks as earthlings — 5 work days and then 2 days off. Your task is to determine the minimum possible and the maximum possible number of days off per year on Mars.
The first line of the input contains a positive integer *n* (1<=≤<=*n*<=≤<=1<=000<=000) — the number of days in a year on Mars.
Print two integers — the minimum possible and the maximum possible number of days off per year on Mars.
[ "14\n", "2\n" ]
[ "4 4\n", "0 2\n" ]
In the first sample there are 14 days in a year on Mars, and therefore independently of the day a year starts with there will be exactly 4 days off . In the second sample there are only 2 days in a year on Mars, and they can both be either work days or days off.
500
[ { "input": "14", "output": "4 4" }, { "input": "2", "output": "0 2" }, { "input": "1", "output": "0 1" }, { "input": "3", "output": "0 2" }, { "input": "4", "output": "0 2" }, { "input": "5", "output": "0 2" }, { "input": "6", "output": "1 2" }, { "input": "7", "output": "2 2" }, { "input": "8", "output": "2 3" }, { "input": "9", "output": "2 4" }, { "input": "10", "output": "2 4" }, { "input": "11", "output": "2 4" }, { "input": "12", "output": "2 4" }, { "input": "13", "output": "3 4" }, { "input": "1000000", "output": "285714 285715" }, { "input": "16", "output": "4 6" }, { "input": "17", "output": "4 6" }, { "input": "18", "output": "4 6" }, { "input": "19", "output": "4 6" }, { "input": "20", "output": "5 6" }, { "input": "21", "output": "6 6" }, { "input": "22", "output": "6 7" }, { "input": "23", "output": "6 8" }, { "input": "24", "output": "6 8" }, { "input": "25", "output": "6 8" }, { "input": "26", "output": "6 8" }, { "input": "27", "output": "7 8" }, { "input": "28", "output": "8 8" }, { "input": "29", "output": "8 9" }, { "input": "30", "output": "8 10" }, { "input": "100", "output": "28 30" }, { "input": "99", "output": "28 29" }, { "input": "98", "output": "28 28" }, { "input": "97", "output": "27 28" }, { "input": "96", "output": "26 28" }, { "input": "95", "output": "26 28" }, { "input": "94", "output": "26 28" }, { "input": "93", "output": "26 28" }, { "input": "92", "output": "26 27" }, { "input": "91", "output": "26 26" }, { "input": "90", "output": "25 26" }, { "input": "89", "output": "24 26" }, { "input": "88", "output": "24 26" }, { "input": "87", "output": "24 26" }, { "input": "86", "output": "24 26" }, { "input": "85", "output": "24 25" }, { "input": "84", "output": "24 24" }, { "input": "83", "output": "23 24" }, { "input": "82", "output": "22 24" }, { "input": "81", "output": "22 24" }, { "input": "80", "output": "22 24" }, { "input": "1000", "output": "285 286" }, { "input": "999", "output": "284 286" }, { "input": "998", "output": "284 286" }, { "input": "997", "output": "284 286" }, { "input": "996", "output": "284 286" }, { "input": "995", "output": "284 285" }, { "input": "994", "output": "284 284" }, { "input": "993", "output": "283 284" }, { "input": "992", "output": "282 284" }, { "input": "991", "output": "282 284" }, { "input": "990", "output": "282 284" }, { "input": "989", "output": "282 284" }, { "input": "988", "output": "282 283" }, { "input": "987", "output": "282 282" }, { "input": "986", "output": "281 282" }, { "input": "985", "output": "280 282" }, { "input": "984", "output": "280 282" }, { "input": "983", "output": "280 282" }, { "input": "982", "output": "280 282" }, { "input": "981", "output": "280 281" }, { "input": "980", "output": "280 280" }, { "input": "10000", "output": "2856 2858" }, { "input": "9999", "output": "2856 2858" }, { "input": "9998", "output": "2856 2858" }, { "input": "9997", "output": "2856 2857" }, { "input": "9996", "output": "2856 2856" }, { "input": "9995", "output": "2855 2856" }, { "input": "9994", "output": "2854 2856" }, { "input": "9993", "output": "2854 2856" }, { "input": "9992", "output": "2854 2856" }, { "input": "9991", "output": "2854 2856" }, { "input": "9990", "output": "2854 2855" }, { "input": "9989", "output": "2854 2854" }, { "input": "9988", "output": "2853 2854" }, { "input": "9987", "output": "2852 2854" }, { "input": "9986", "output": "2852 2854" }, { "input": "9985", "output": "2852 2854" }, { "input": "9984", "output": "2852 2854" }, { "input": "9983", "output": "2852 2853" }, { "input": "9982", "output": "2852 2852" }, { "input": "9981", "output": "2851 2852" }, { "input": "9980", "output": "2850 2852" }, { "input": "100000", "output": "28570 28572" }, { "input": "99999", "output": "28570 28572" }, { "input": "99998", "output": "28570 28572" }, { "input": "99997", "output": "28570 28572" }, { "input": "99996", "output": "28570 28571" }, { "input": "99995", "output": "28570 28570" }, { "input": "99994", "output": "28569 28570" }, { "input": "99993", "output": "28568 28570" }, { "input": "99992", "output": "28568 28570" }, { "input": "99991", "output": "28568 28570" }, { "input": "99990", "output": "28568 28570" }, { "input": "99989", "output": "28568 28569" }, { "input": "99988", "output": "28568 28568" }, { "input": "99987", "output": "28567 28568" }, { "input": "99986", "output": "28566 28568" }, { "input": "99985", "output": "28566 28568" }, { "input": "99984", "output": "28566 28568" }, { "input": "99983", "output": "28566 28568" }, { "input": "99982", "output": "28566 28567" }, { "input": "99981", "output": "28566 28566" }, { "input": "99980", "output": "28565 28566" }, { "input": "999999", "output": "285714 285714" }, { "input": "999998", "output": "285713 285714" }, { "input": "999997", "output": "285712 285714" }, { "input": "999996", "output": "285712 285714" }, { "input": "999995", "output": "285712 285714" }, { "input": "999994", "output": "285712 285714" }, { "input": "999993", "output": "285712 285713" }, { "input": "999992", "output": "285712 285712" }, { "input": "999991", "output": "285711 285712" }, { "input": "999990", "output": "285710 285712" }, { "input": "999989", "output": "285710 285712" }, { "input": "999988", "output": "285710 285712" }, { "input": "999987", "output": "285710 285712" }, { "input": "999986", "output": "285710 285711" }, { "input": "999985", "output": "285710 285710" }, { "input": "999984", "output": "285709 285710" }, { "input": "999983", "output": "285708 285710" }, { "input": "999982", "output": "285708 285710" }, { "input": "999981", "output": "285708 285710" }, { "input": "999980", "output": "285708 285710" }, { "input": "234123", "output": "66892 66893" }, { "input": "234122", "output": "66892 66892" }, { "input": "234121", "output": "66891 66892" }, { "input": "234120", "output": "66890 66892" }, { "input": "234119", "output": "66890 66892" }, { "input": "234118", "output": "66890 66892" }, { "input": "234117", "output": "66890 66892" }, { "input": "234116", "output": "66890 66891" }, { "input": "234115", "output": "66890 66890" }, { "input": "234114", "output": "66889 66890" }, { "input": "234113", "output": "66888 66890" }, { "input": "234112", "output": "66888 66890" }, { "input": "234111", "output": "66888 66890" }, { "input": "234110", "output": "66888 66890" }, { "input": "234109", "output": "66888 66889" }, { "input": "234108", "output": "66888 66888" }, { "input": "234107", "output": "66887 66888" }, { "input": "234106", "output": "66886 66888" }, { "input": "234105", "output": "66886 66888" }, { "input": "234104", "output": "66886 66888" }, { "input": "234103", "output": "66886 66888" }, { "input": "868531", "output": "248151 248152" }, { "input": "868530", "output": "248150 248152" }, { "input": "868529", "output": "248150 248152" }, { "input": "868528", "output": "248150 248152" }, { "input": "868527", "output": "248150 248152" }, { "input": "868526", "output": "248150 248151" }, { "input": "868525", "output": "248150 248150" }, { "input": "868524", "output": "248149 248150" }, { "input": "868523", "output": "248148 248150" }, { "input": "868522", "output": "248148 248150" }, { "input": "868521", "output": "248148 248150" }, { "input": "868520", "output": "248148 248150" }, { "input": "868519", "output": "248148 248149" }, { "input": "868518", "output": "248148 248148" }, { "input": "868517", "output": "248147 248148" }, { "input": "868516", "output": "248146 248148" }, { "input": "868515", "output": "248146 248148" }, { "input": "868514", "output": "248146 248148" }, { "input": "868513", "output": "248146 248148" }, { "input": "868512", "output": "248146 248147" }, { "input": "868511", "output": "248146 248146" }, { "input": "123413", "output": "35260 35262" }, { "input": "123412", "output": "35260 35262" }, { "input": "123411", "output": "35260 35261" }, { "input": "123410", "output": "35260 35260" }, { "input": "123409", "output": "35259 35260" }, { "input": "123408", "output": "35258 35260" }, { "input": "123407", "output": "35258 35260" }, { "input": "123406", "output": "35258 35260" }, { "input": "123405", "output": "35258 35260" }, { "input": "123404", "output": "35258 35259" }, { "input": "123403", "output": "35258 35258" }, { "input": "123402", "output": "35257 35258" }, { "input": "123401", "output": "35256 35258" }, { "input": "123400", "output": "35256 35258" }, { "input": "123399", "output": "35256 35258" }, { "input": "123398", "output": "35256 35258" }, { "input": "123397", "output": "35256 35257" }, { "input": "123396", "output": "35256 35256" }, { "input": "123395", "output": "35255 35256" }, { "input": "123394", "output": "35254 35256" }, { "input": "123393", "output": "35254 35256" }, { "input": "15", "output": "4 5" } ]
1,681,484,966
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
6
46
0
def holidays(n): holiday=(n//7)*2 if (n-(n//7)*7)<2: return holiday, holiday+(n-(n//7)*7) else: return holiday, holiday+2 q=int(input()) (a,b)=holidays(q) print(a,b,sep=' ')
Title: Holidays Time Limit: None seconds Memory Limit: None megabytes Problem Description: On the planet Mars a year lasts exactly *n* days (there are no leap years on Mars). But Martians have the same weeks as earthlings — 5 work days and then 2 days off. Your task is to determine the minimum possible and the maximum possible number of days off per year on Mars. Input Specification: The first line of the input contains a positive integer *n* (1<=≤<=*n*<=≤<=1<=000<=000) — the number of days in a year on Mars. Output Specification: Print two integers — the minimum possible and the maximum possible number of days off per year on Mars. Demo Input: ['14\n', '2\n'] Demo Output: ['4 4\n', '0 2\n'] Note: In the first sample there are 14 days in a year on Mars, and therefore independently of the day a year starts with there will be exactly 4 days off . In the second sample there are only 2 days in a year on Mars, and they can both be either work days or days off.
```python def holidays(n): holiday=(n//7)*2 if (n-(n//7)*7)<2: return holiday, holiday+(n-(n//7)*7) else: return holiday, holiday+2 q=int(input()) (a,b)=holidays(q) print(a,b,sep=' ') ```
0
614
B
Gena's Code
PROGRAMMING
1,400
[ "implementation", "math" ]
null
null
It's the year 4527 and the tanks game that we all know and love still exists. There also exists Great Gena's code, written in 2016. The problem this code solves is: given the number of tanks that go into the battle from each country, find their product. If it is turns to be too large, then the servers might have not enough time to assign tanks into teams and the whole game will collapse! There are exactly *n* distinct countries in the world and the *i*-th country added *a**i* tanks to the game. As the developers of the game are perfectionists, the number of tanks from each country is beautiful. A beautiful number, according to the developers, is such number that its decimal representation consists only of digits '1' and '0', moreover it contains at most one digit '1'. However, due to complaints from players, some number of tanks of one country was removed from the game, hence the number of tanks of this country may not remain beautiful. Your task is to write the program that solves exactly the same problem in order to verify Gena's code correctness. Just in case.
The first line of the input contains the number of countries *n* (1<=≤<=*n*<=≤<=100<=000). The second line contains *n* non-negative integers *a**i* without leading zeroes — the number of tanks of the *i*-th country. It is guaranteed that the second line contains at least *n*<=-<=1 beautiful numbers and the total length of all these number's representations doesn't exceed 100<=000.
Print a single number without leading zeroes — the product of the number of tanks presented by each country.
[ "3\n5 10 1\n", "4\n1 1 10 11\n", "5\n0 3 1 100 1\n" ]
[ "50", "110", "0" ]
In sample 1 numbers 10 and 1 are beautiful, number 5 is not not. In sample 2 number 11 is not beautiful (contains two '1's), all others are beautiful. In sample 3 number 3 is not beautiful, all others are beautiful.
1,000
[ { "input": "3\n5 10 1", "output": "50" }, { "input": "4\n1 1 10 11", "output": "110" }, { "input": "5\n0 3 1 100 1", "output": "0" }, { "input": "40\n10 100 10 1 10 10 100 10 10 100 10 100 100 10 1824868942 100 100 1 10 100 100 10 100 100 10 100 10 1 10 100 100 100 10 1 10 1 10 10 100 100", "output": "1824868942000000000000000000000000000000000000000000000000000" }, { "input": "6\n1000000000000000000000000000000000000 6643573784 1000000000000000000000000000000000000 1000000000000000000000000000000000000 1000000000000000000000000000000000000 1000000000000000000000000000000000000", "output": "6643573784000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" }, { "input": "1\n0", "output": "0" }, { "input": "1\n1", "output": "1" }, { "input": "1\n9", "output": "9" }, { "input": "2\n10 50", "output": "500" }, { "input": "3\n500 1 10", "output": "5000" } ]
1,579,505,880
1,980
Python 3
OK
TESTS
32
202
1,843,200
n = int(input()) lis = input().split() #print(lis) ans=1 zer=0 for i in lis: l=len(i) k=i.count('1') j=i.count('0') if k+j==l: if k>1: ans*=int(i) else: if j==l: print('0') exit() else: zer+=l-i.find('1')-1 # print(i.find('1'),zer) else: ans*=i p='' for i in range(zer): p+='0' print(str(ans)+p)
Title: Gena's Code Time Limit: None seconds Memory Limit: None megabytes Problem Description: It's the year 4527 and the tanks game that we all know and love still exists. There also exists Great Gena's code, written in 2016. The problem this code solves is: given the number of tanks that go into the battle from each country, find their product. If it is turns to be too large, then the servers might have not enough time to assign tanks into teams and the whole game will collapse! There are exactly *n* distinct countries in the world and the *i*-th country added *a**i* tanks to the game. As the developers of the game are perfectionists, the number of tanks from each country is beautiful. A beautiful number, according to the developers, is such number that its decimal representation consists only of digits '1' and '0', moreover it contains at most one digit '1'. However, due to complaints from players, some number of tanks of one country was removed from the game, hence the number of tanks of this country may not remain beautiful. Your task is to write the program that solves exactly the same problem in order to verify Gena's code correctness. Just in case. Input Specification: The first line of the input contains the number of countries *n* (1<=≤<=*n*<=≤<=100<=000). The second line contains *n* non-negative integers *a**i* without leading zeroes — the number of tanks of the *i*-th country. It is guaranteed that the second line contains at least *n*<=-<=1 beautiful numbers and the total length of all these number's representations doesn't exceed 100<=000. Output Specification: Print a single number without leading zeroes — the product of the number of tanks presented by each country. Demo Input: ['3\n5 10 1\n', '4\n1 1 10 11\n', '5\n0 3 1 100 1\n'] Demo Output: ['50', '110', '0'] Note: In sample 1 numbers 10 and 1 are beautiful, number 5 is not not. In sample 2 number 11 is not beautiful (contains two '1's), all others are beautiful. In sample 3 number 3 is not beautiful, all others are beautiful.
```python n = int(input()) lis = input().split() #print(lis) ans=1 zer=0 for i in lis: l=len(i) k=i.count('1') j=i.count('0') if k+j==l: if k>1: ans*=int(i) else: if j==l: print('0') exit() else: zer+=l-i.find('1')-1 # print(i.find('1'),zer) else: ans*=i p='' for i in range(zer): p+='0' print(str(ans)+p) ```
3
731
A
Night at the Museum
PROGRAMMING
800
[ "implementation", "strings" ]
null
null
Grigoriy, like the hero of one famous comedy film, found a job as a night security guard at the museum. At first night he received embosser and was to take stock of the whole exposition. Embosser is a special devise that allows to "print" the text of a plastic tape. Text is printed sequentially, character by character. The device consists of a wheel with a lowercase English letters written in a circle, static pointer to the current letter and a button that print the chosen letter. At one move it's allowed to rotate the alphabetic wheel one step clockwise or counterclockwise. Initially, static pointer points to letter 'a'. Other letters are located as shown on the picture: After Grigoriy add new item to the base he has to print its name on the plastic tape and attach it to the corresponding exhibit. It's not required to return the wheel to its initial position with pointer on the letter 'a'. Our hero is afraid that some exhibits may become alive and start to attack him, so he wants to print the names as fast as possible. Help him, for the given string find the minimum number of rotations of the wheel required to print it.
The only line of input contains the name of some exhibit — the non-empty string consisting of no more than 100 characters. It's guaranteed that the string consists of only lowercase English letters.
Print one integer — the minimum number of rotations of the wheel, required to print the name given in the input.
[ "zeus\n", "map\n", "ares\n" ]
[ "18\n", "35\n", "34\n" ]
To print the string from the first sample it would be optimal to perform the following sequence of rotations: 1. from 'a' to 'z' (1 rotation counterclockwise), 1. from 'z' to 'e' (5 clockwise rotations), 1. from 'e' to 'u' (10 rotations counterclockwise), 1. from 'u' to 's' (2 counterclockwise rotations).
500
[ { "input": "zeus", "output": "18" }, { "input": "map", "output": "35" }, { "input": "ares", "output": "34" }, { "input": "l", "output": "11" }, { "input": "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuv", "output": "99" }, { "input": "gngvi", "output": "44" }, { "input": "aaaaa", "output": "0" }, { "input": "a", "output": "0" }, { "input": "z", "output": "1" }, { "input": "vyadeehhikklnoqrs", "output": "28" }, { "input": "jjiihhhhgggfedcccbazyxx", "output": "21" }, { "input": "fyyptqqxuciqvwdewyppjdzur", "output": "117" }, { "input": "fqcnzmzmbobmancqcoalzmanaobpdse", "output": "368" }, { "input": "zzzzzaaaaaaazzzzzzaaaaaaazzzzzzaaaazzzza", "output": "8" }, { "input": "aucnwhfixuruefkypvrvnvznwtjgwlghoqtisbkhuwxmgzuljvqhmnwzisnsgjhivnjmbknptxatdkelhzkhsuxzrmlcpeoyukiy", "output": "644" }, { "input": "sssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssss", "output": "8" }, { "input": "nypjygrdtpzpigzyrisqeqfriwgwlengnezppgttgtndbrryjdl", "output": "421" }, { "input": "pnllnnmmmmoqqqqqrrtssssuuvtsrpopqoonllmonnnpppopnonoopooqpnopppqppqstuuuwwwwvxzxzzaa", "output": "84" }, { "input": "btaoahqgxnfsdmzsjxgvdwjukcvereqeskrdufqfqgzqfsftdqcthtkcnaipftcnco", "output": "666" }, { "input": "eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeerrrrrrrrrrrrrrrrwwwwwwwwww", "output": "22" }, { "input": "uyknzcrwjyzmscqucclvacmorepdgmnyhmakmmnygqwglrxkxhkpansbmruwxdeoprxzmpsvwackopujxbbkpwyeggsvjykpxh", "output": "643" }, { "input": "gzwpooohffcxwtpjgfzwtooiccxsrrokezutoojdzwsrmmhecaxwrojcbyrqlfdwwrliiib", "output": "245" }, { "input": "dbvnkktasjdwqsrzfwwtmjgbcxggdxsoeilecihduypktkkbwfbruxzzhlttrssicgdwqruddwrlbtxgmhdbatzvdxbbro", "output": "468" }, { "input": "mdtvowlktxzzbuaeiuebfeorgbdczauxsovbucactkvyvemsknsjfhifqgycqredzchipmkvzbxdjkcbyukomjlzvxzoswumned", "output": "523" }, { "input": "kkkkkkkaaaaxxaaaaaaaxxxxxxxxaaaaaaxaaaaaaaaaakkkkkkkkkaaaaaaannnnnxxxxkkkkkkkkaannnnnnna", "output": "130" }, { "input": "dffiknqqrsvwzcdgjkmpqtuwxadfhkkkmpqrtwxyadfggjmpppsuuwyyzcdgghhknnpsvvvwwwyabccffiloqruwwyyzabeeehh", "output": "163" }, { "input": "qpppmmkjihgecbyvvsppnnnkjiffeebaaywutrrqpmkjhgddbzzzywtssssqnmmljheddbbaxvusrqonmlifedbbzyywwtqnkheb", "output": "155" }, { "input": "wvvwwwvvwxxxyyyxxwwvwwvuttttttuvvwxxwxxyxxwwwwwvvuttssrssstsssssrqpqqppqrssrsrrssrssssrrsrqqrrqpppqp", "output": "57" }, { "input": "dqcpcobpcobnznamznamzlykxkxlxlylzmaobnaobpbnanbpcoaobnboaoboanzlymzmykylymylzlylymanboanaocqdqesfrfs", "output": "1236" }, { "input": "nnnnnnnnnnnnnnnnnnnnaaaaaaaaaaaaaaaaaaaakkkkkkkkkkkkkkkkkkkkkkaaaaaaaaaaaaaaaaaaaaxxxxxxxxxxxxxxxxxx", "output": "49" }, { "input": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", "output": "0" }, { "input": "cgilqsuwzaffilptwwbgmnttyyejkorxzflqvzbddhmnrvxchijpuwaeiimosxyycejlpquuwbfkpvbgijkqvxybdjjjptxcfkqt", "output": "331" }, { "input": "ufsepwgtzgtgjssxaitgpailuvgqweoppszjwhoxdhhhpwwdorwfrdjwcdekxiktwziqwbkvbknrtvajpyeqbjvhiikxxaejjpte", "output": "692" }, { "input": "uhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuh", "output": "1293" }, { "input": "vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvgggggggggggggggggggggggggggggggggggggggggggggggggg", "output": "16" }, { "input": "lyidmjyzbszgiwkxhhpnnthfwcvvstueionspfrvqgkvngmwyhezlosrpdnbvtcjjxxsykixwnepbumaacdzadlqhnjlcejovple", "output": "616" }, { "input": "etzqqbaveffalkdguunfmyyrzkccnxmlluxeasqmopxzfvlkbhipqdwjgrttoemruohgwukfisdhznqyvhswbbypoxgtxyappcrl", "output": "605" }, { "input": "lizussgedcbdjhrbeskhgatyozvwwekanlggcstijrniivupmcoofbaxfqrxddyzzptwxcftlhajsmmkkriarrqtkoauhcqefyud", "output": "549" }, { "input": "dvjuvgfdogpknmbowlsfjzcimnygbtjiucyeeroqwhmzwpjqxlbjkqawrdtmvxbiqufllfuqibxvmtdrwaqkjblxqjpwzmhwqore", "output": "688" }, { "input": "eeycuijtbgynmiczjfslwobmnkpgodfgvujvduyfeqchuaoktqrrairkkmmsjahltfcxwtpzzyddxrqfxabfoocmpuviinrjitsc", "output": "604" }, { "input": "cgglnakewwvzoytaghksebrhjdbcdegssuzilrcppayxtgxopybbwshvyqnzhdsifkuwghourmeottrgjwdqpihbklvfzxpomqsa", "output": "572" }, { "input": "aexullmxncckzryymfnuugdklaffevabqqztelpvojecljnhqldazdcaamubpenwxikysxxjjctvbndprsolzehywmgnvkgqvrfp", "output": "609" }, { "input": "psnoieutsvvcwfhtnnphhxkwigzsbzyjmdiyl", "output": "223" }, { "input": "aa", "output": "0" } ]
1,660,095,792
2,147,483,647
Python 3
OK
TESTS
44
46
0
s = 'abcdefghijklmnopqrstuvwxyz'; word = input(); result = 0; ptr = 0; for i in range(len(word)): from_st = s.index(word[i]); from_end = s[::-1].index(word[i]); if(from_st > from_end): ptr = from_end; start = s[26 - ptr-1::]; end = s[0:26-ptr-1]; else: ptr = from_st; start = s[ptr:]; end = s[0:ptr]; if(len(start) < len(end)): result += len(start); else: result += len(end); s = start + end; print(result);
Title: Night at the Museum Time Limit: None seconds Memory Limit: None megabytes Problem Description: Grigoriy, like the hero of one famous comedy film, found a job as a night security guard at the museum. At first night he received embosser and was to take stock of the whole exposition. Embosser is a special devise that allows to "print" the text of a plastic tape. Text is printed sequentially, character by character. The device consists of a wheel with a lowercase English letters written in a circle, static pointer to the current letter and a button that print the chosen letter. At one move it's allowed to rotate the alphabetic wheel one step clockwise or counterclockwise. Initially, static pointer points to letter 'a'. Other letters are located as shown on the picture: After Grigoriy add new item to the base he has to print its name on the plastic tape and attach it to the corresponding exhibit. It's not required to return the wheel to its initial position with pointer on the letter 'a'. Our hero is afraid that some exhibits may become alive and start to attack him, so he wants to print the names as fast as possible. Help him, for the given string find the minimum number of rotations of the wheel required to print it. Input Specification: The only line of input contains the name of some exhibit — the non-empty string consisting of no more than 100 characters. It's guaranteed that the string consists of only lowercase English letters. Output Specification: Print one integer — the minimum number of rotations of the wheel, required to print the name given in the input. Demo Input: ['zeus\n', 'map\n', 'ares\n'] Demo Output: ['18\n', '35\n', '34\n'] Note: To print the string from the first sample it would be optimal to perform the following sequence of rotations: 1. from 'a' to 'z' (1 rotation counterclockwise), 1. from 'z' to 'e' (5 clockwise rotations), 1. from 'e' to 'u' (10 rotations counterclockwise), 1. from 'u' to 's' (2 counterclockwise rotations).
```python s = 'abcdefghijklmnopqrstuvwxyz'; word = input(); result = 0; ptr = 0; for i in range(len(word)): from_st = s.index(word[i]); from_end = s[::-1].index(word[i]); if(from_st > from_end): ptr = from_end; start = s[26 - ptr-1::]; end = s[0:26-ptr-1]; else: ptr = from_st; start = s[ptr:]; end = s[0:ptr]; if(len(start) < len(end)): result += len(start); else: result += len(end); s = start + end; print(result); ```
3
476
B
Dreamoon and WiFi
PROGRAMMING
1,300
[ "bitmasks", "brute force", "combinatorics", "dp", "math", "probabilities" ]
null
null
Dreamoon is standing at the position 0 on a number line. Drazil is sending a list of commands through Wi-Fi to Dreamoon's smartphone and Dreamoon follows them. Each command is one of the following two types: 1. Go 1 unit towards the positive direction, denoted as '+' 1. Go 1 unit towards the negative direction, denoted as '-' But the Wi-Fi condition is so poor that Dreamoon's smartphone reports some of the commands can't be recognized and Dreamoon knows that some of them might even be wrong though successfully recognized. Dreamoon decides to follow every recognized command and toss a fair coin to decide those unrecognized ones (that means, he moves to the 1 unit to the negative or positive direction with the same probability 0.5). You are given an original list of commands sent by Drazil and list received by Dreamoon. What is the probability that Dreamoon ends in the position originally supposed to be final by Drazil's commands?
The first line contains a string *s*1 — the commands Drazil sends to Dreamoon, this string consists of only the characters in the set {'+', '-'}. The second line contains a string *s*2 — the commands Dreamoon's smartphone recognizes, this string consists of only the characters in the set {'+', '-', '?'}. '?' denotes an unrecognized command. Lengths of two strings are equal and do not exceed 10.
Output a single real number corresponding to the probability. The answer will be considered correct if its relative or absolute error doesn't exceed 10<=-<=9.
[ "++-+-\n+-+-+\n", "+-+-\n+-??\n", "+++\n??-\n" ]
[ "1.000000000000\n", "0.500000000000\n", "0.000000000000\n" ]
For the first sample, both *s*<sub class="lower-index">1</sub> and *s*<sub class="lower-index">2</sub> will lead Dreamoon to finish at the same position  + 1. For the second sample, *s*<sub class="lower-index">1</sub> will lead Dreamoon to finish at position 0, while there are four possibilites for *s*<sub class="lower-index">2</sub>: {"+-++", "+-+-", "+--+", "+---"} with ending position {+2, 0, 0, -2} respectively. So there are 2 correct cases out of 4, so the probability of finishing at the correct position is 0.5. For the third sample, *s*<sub class="lower-index">2</sub> could only lead us to finish at positions {+1, -1, -3}, so the probability to finish at the correct position  + 3 is 0.
1,500
[ { "input": "++-+-\n+-+-+", "output": "1.000000000000" }, { "input": "+-+-\n+-??", "output": "0.500000000000" }, { "input": "+++\n??-", "output": "0.000000000000" }, { "input": "++++++++++\n+++??++?++", "output": "0.125000000000" }, { "input": "--+++---+-\n??????????", "output": "0.205078125000" }, { "input": "+--+++--+-\n??????????", "output": "0.246093750000" }, { "input": "+\n+", "output": "1.000000000000" }, { "input": "-\n?", "output": "0.500000000000" }, { "input": "+\n-", "output": "0.000000000000" }, { "input": "-\n-", "output": "1.000000000000" }, { "input": "-\n+", "output": "0.000000000000" }, { "input": "+\n?", "output": "0.500000000000" }, { "input": "++++++++++\n++++++++++", "output": "1.000000000000" }, { "input": "++++++++++\n++++-+++++", "output": "0.000000000000" }, { "input": "----------\n++++++++++", "output": "0.000000000000" }, { "input": "++++++++++\n++++??++++", "output": "0.250000000000" }, { "input": "----------\n+++?++++-+", "output": "0.000000000000" }, { "input": "++++++++++\n++++++++?+", "output": "0.500000000000" }, { "input": "--++++--+\n?-+?-??+-", "output": "0.250000000000" }, { "input": "----------\n??????????", "output": "0.000976562500" }, { "input": "+--++\n+--+-", "output": "0.000000000000" }, { "input": "-----++---\n????????+?", "output": "0.017578125000" }, { "input": "------+--+\n??????????", "output": "0.043945312500" }, { "input": "---++--\n???????", "output": "0.164062500000" }, { "input": "-----++\n???????", "output": "0.164062500000" }, { "input": "+---+--\n???????", "output": "0.164062500000" }, { "input": "---+-+\n??????", "output": "0.234375000000" }, { "input": "+++-+\n---++", "output": "0.000000000000" }, { "input": "++-+--+\n?-?+??+", "output": "0.375000000000" }, { "input": "----+++--\n-+?+++?--", "output": "0.000000000000" }, { "input": "+-----\n+?----", "output": "0.500000000000" } ]
1,655,724,146
2,147,483,647
PyPy 3-64
RUNTIME_ERROR
TESTS
0
62
2,764,800
import math from collections import OrderedDict,Counter import heapq from collections import deque import sys def mpp():return map(int,inp().split()) def lis():return list(mpp()) def inp(): return input() def fn(a,b): n=b.count('?') r=a.count('-')-b.count('-') print(0 if n<r or r<0 else math.comb(n,r)/(1<<n)) def main(): n=inp() m=inp() (fn(n,m)) if __name__=="__main__": main()
Title: Dreamoon and WiFi Time Limit: None seconds Memory Limit: None megabytes Problem Description: Dreamoon is standing at the position 0 on a number line. Drazil is sending a list of commands through Wi-Fi to Dreamoon's smartphone and Dreamoon follows them. Each command is one of the following two types: 1. Go 1 unit towards the positive direction, denoted as '+' 1. Go 1 unit towards the negative direction, denoted as '-' But the Wi-Fi condition is so poor that Dreamoon's smartphone reports some of the commands can't be recognized and Dreamoon knows that some of them might even be wrong though successfully recognized. Dreamoon decides to follow every recognized command and toss a fair coin to decide those unrecognized ones (that means, he moves to the 1 unit to the negative or positive direction with the same probability 0.5). You are given an original list of commands sent by Drazil and list received by Dreamoon. What is the probability that Dreamoon ends in the position originally supposed to be final by Drazil's commands? Input Specification: The first line contains a string *s*1 — the commands Drazil sends to Dreamoon, this string consists of only the characters in the set {'+', '-'}. The second line contains a string *s*2 — the commands Dreamoon's smartphone recognizes, this string consists of only the characters in the set {'+', '-', '?'}. '?' denotes an unrecognized command. Lengths of two strings are equal and do not exceed 10. Output Specification: Output a single real number corresponding to the probability. The answer will be considered correct if its relative or absolute error doesn't exceed 10<=-<=9. Demo Input: ['++-+-\n+-+-+\n', '+-+-\n+-??\n', '+++\n??-\n'] Demo Output: ['1.000000000000\n', '0.500000000000\n', '0.000000000000\n'] Note: For the first sample, both *s*<sub class="lower-index">1</sub> and *s*<sub class="lower-index">2</sub> will lead Dreamoon to finish at the same position  + 1. For the second sample, *s*<sub class="lower-index">1</sub> will lead Dreamoon to finish at position 0, while there are four possibilites for *s*<sub class="lower-index">2</sub>: {"+-++", "+-+-", "+--+", "+---"} with ending position {+2, 0, 0, -2} respectively. So there are 2 correct cases out of 4, so the probability of finishing at the correct position is 0.5. For the third sample, *s*<sub class="lower-index">2</sub> could only lead us to finish at positions {+1, -1, -3}, so the probability to finish at the correct position  + 3 is 0.
```python import math from collections import OrderedDict,Counter import heapq from collections import deque import sys def mpp():return map(int,inp().split()) def lis():return list(mpp()) def inp(): return input() def fn(a,b): n=b.count('?') r=a.count('-')-b.count('-') print(0 if n<r or r<0 else math.comb(n,r)/(1<<n)) def main(): n=inp() m=inp() (fn(n,m)) if __name__=="__main__": main() ```
-1
900
A
Find Extra One
PROGRAMMING
800
[ "geometry", "implementation" ]
null
null
You have *n* distinct points on a plane, none of them lie on *OY* axis. Check that there is a point after removal of which the remaining points are located on one side of the *OY* axis.
The first line contains a single positive integer *n* (2<=≤<=*n*<=≤<=105). The following *n* lines contain coordinates of the points. The *i*-th of these lines contains two single integers *x**i* and *y**i* (|*x**i*|,<=|*y**i*|<=≤<=109, *x**i*<=≠<=0). No two points coincide.
Print "Yes" if there is such a point, "No" — otherwise. You can print every letter in any case (upper or lower).
[ "3\n1 1\n-1 -1\n2 -1\n", "4\n1 1\n2 2\n-1 1\n-2 2\n", "3\n1 2\n2 1\n4 60\n" ]
[ "Yes", "No", "Yes" ]
In the first example the second point can be removed. In the second example there is no suitable for the condition point. In the third example any point can be removed.
500
[ { "input": "3\n1 1\n-1 -1\n2 -1", "output": "Yes" }, { "input": "4\n1 1\n2 2\n-1 1\n-2 2", "output": "No" }, { "input": "3\n1 2\n2 1\n4 60", "output": "Yes" }, { "input": "10\n1 1\n2 2\n3 3\n4 4\n5 5\n6 6\n7 7\n8 8\n9 9\n-1 -1", "output": "Yes" }, { "input": "2\n1000000000 -1000000000\n1000000000 1000000000", "output": "Yes" }, { "input": "23\n-1 1\n-1 2\n-2 4\n-7 -8\n-3 3\n-9 -14\n-5 3\n-6 2\n-7 11\n-4 4\n-8 5\n1 1\n-1 -1\n-1 -2\n-2 -4\n-7 8\n-3 -3\n-9 14\n-5 -3\n-6 -2\n-7 -11\n-4 -4\n-8 -5", "output": "Yes" }, { "input": "4\n-1000000000 -1000000000\n1000000000 1000000000\n-1000000000 1000000000\n1000000000 -1000000000", "output": "No" }, { "input": "2\n-1000000000 1000000000\n-1000000000 -1000000000", "output": "Yes" }, { "input": "5\n-1 -1\n-2 2\n2 2\n2 -2\n3 2", "output": "No" }, { "input": "2\n1 0\n-1 0", "output": "Yes" }, { "input": "4\n-1 1\n-1 2\n-1 3\n-1 4", "output": "Yes" }, { "input": "2\n-1 0\n1 0", "output": "Yes" }, { "input": "2\n1 2\n-1 2", "output": "Yes" }, { "input": "2\n8 0\n7 0", "output": "Yes" }, { "input": "6\n-1 0\n-2 0\n-1 -1\n-1 5\n1 0\n1 1", "output": "No" }, { "input": "4\n1 0\n2 0\n-1 0\n-2 0", "output": "No" }, { "input": "4\n-2 0\n-1 0\n1 0\n2 0", "output": "No" }, { "input": "2\n1 1\n-1 1", "output": "Yes" }, { "input": "4\n-1 0\n-2 0\n1 0\n2 0", "output": "No" }, { "input": "2\n4 3\n-4 -2", "output": "Yes" }, { "input": "4\n1 0\n2 0\n-1 1\n-1 2", "output": "No" }, { "input": "5\n1 1\n2 1\n3 1\n-1 1\n-2 1", "output": "No" }, { "input": "2\n1 1\n-1 -1", "output": "Yes" }, { "input": "4\n1 2\n1 0\n1 -2\n-1 2", "output": "Yes" }, { "input": "5\n-2 3\n-3 3\n4 2\n3 2\n1 2", "output": "No" }, { "input": "3\n2 0\n3 0\n4 0", "output": "Yes" }, { "input": "5\n-3 1\n-2 1\n-1 1\n1 1\n2 1", "output": "No" }, { "input": "4\n-3 0\n1 0\n2 0\n3 0", "output": "Yes" }, { "input": "2\n1 0\n-1 1", "output": "Yes" }, { "input": "3\n-1 0\n1 0\n2 0", "output": "Yes" }, { "input": "5\n1 0\n3 0\n-1 0\n-6 0\n-4 1", "output": "No" }, { "input": "5\n-1 2\n-2 2\n-3 1\n1 2\n2 3", "output": "No" }, { "input": "3\n1 0\n-1 0\n-2 0", "output": "Yes" }, { "input": "4\n1 0\n2 0\n3 1\n4 1", "output": "Yes" }, { "input": "4\n1 0\n1 2\n1 3\n-1 5", "output": "Yes" }, { "input": "4\n2 2\n2 5\n-2 3\n-2 0", "output": "No" }, { "input": "4\n1 1\n-1 1\n-1 0\n-1 -1", "output": "Yes" }, { "input": "4\n2 0\n3 0\n-3 -3\n-3 -4", "output": "No" }, { "input": "4\n-1 0\n-2 0\n-3 0\n-4 0", "output": "Yes" }, { "input": "2\n-1 1\n1 1", "output": "Yes" }, { "input": "5\n1 1\n2 2\n3 3\n-4 -4\n-5 -5", "output": "No" }, { "input": "5\n2 0\n3 0\n4 0\n5 0\n6 0", "output": "Yes" }, { "input": "2\n-1 2\n1 2", "output": "Yes" }, { "input": "4\n1 1\n2 1\n-3 0\n-4 0", "output": "No" }, { "input": "4\n-1 0\n-2 0\n3 0\n4 0", "output": "No" }, { "input": "3\n3 0\n2 0\n1 0", "output": "Yes" }, { "input": "4\n-2 0\n-3 0\n1 -1\n3 1", "output": "No" }, { "input": "3\n-1 -1\n1 1\n2 2", "output": "Yes" }, { "input": "4\n-2 0\n-1 0\n2 0\n1 0", "output": "No" }, { "input": "2\n-3 5\n3 5", "output": "Yes" }, { "input": "2\n-1 5\n1 5", "output": "Yes" }, { "input": "4\n2 0\n3 0\n-2 0\n-3 0", "output": "No" }, { "input": "3\n-1 1\n1 1\n1 -1", "output": "Yes" }, { "input": "2\n1 0\n2 0", "output": "Yes" }, { "input": "4\n-1 1\n-2 1\n2 -1\n3 -1", "output": "No" }, { "input": "5\n1 0\n2 0\n3 0\n-1 0\n-2 0", "output": "No" }, { "input": "4\n-3 0\n-4 0\n-5 0\n-6 0", "output": "Yes" }, { "input": "6\n-3 0\n-2 0\n-1 0\n1 0\n2 0\n3 0", "output": "No" }, { "input": "4\n5 0\n5 1\n6 0\n6 1", "output": "Yes" } ]
1,642,599,110
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
8
249
0
#Ammu q1,q2,q3,q4=0,0,0,0 for _ in range(int(input())): a,b=map(int,input().split()) if a>0 and b>0: q1+=1 elif a<0 and b>0: q2+=1 elif a<0 and b<0: q3+=1 elif a>0 and b<0: q4+=1 #print(q1,q2,q3,q4) if (q1+q4==1) or (q2+q3==1) or (q2==q3==0 and q1+q4>1) or (q2==q3==0 and q1+q4>1): print('Yes') else: print('No')
Title: Find Extra One Time Limit: None seconds Memory Limit: None megabytes Problem Description: You have *n* distinct points on a plane, none of them lie on *OY* axis. Check that there is a point after removal of which the remaining points are located on one side of the *OY* axis. Input Specification: The first line contains a single positive integer *n* (2<=≤<=*n*<=≤<=105). The following *n* lines contain coordinates of the points. The *i*-th of these lines contains two single integers *x**i* and *y**i* (|*x**i*|,<=|*y**i*|<=≤<=109, *x**i*<=≠<=0). No two points coincide. Output Specification: Print "Yes" if there is such a point, "No" — otherwise. You can print every letter in any case (upper or lower). Demo Input: ['3\n1 1\n-1 -1\n2 -1\n', '4\n1 1\n2 2\n-1 1\n-2 2\n', '3\n1 2\n2 1\n4 60\n'] Demo Output: ['Yes', 'No', 'Yes'] Note: In the first example the second point can be removed. In the second example there is no suitable for the condition point. In the third example any point can be removed.
```python #Ammu q1,q2,q3,q4=0,0,0,0 for _ in range(int(input())): a,b=map(int,input().split()) if a>0 and b>0: q1+=1 elif a<0 and b>0: q2+=1 elif a<0 and b<0: q3+=1 elif a>0 and b<0: q4+=1 #print(q1,q2,q3,q4) if (q1+q4==1) or (q2+q3==1) or (q2==q3==0 and q1+q4>1) or (q2==q3==0 and q1+q4>1): print('Yes') else: print('No') ```
0
907
A
Masha and Bears
PROGRAMMING
1,300
[ "brute force", "implementation" ]
null
null
A family consisting of father bear, mother bear and son bear owns three cars. Father bear can climb into the largest car and he likes it. Also, mother bear can climb into the middle car and she likes it. Moreover, son bear can climb into the smallest car and he likes it. It's known that the largest car is strictly larger than the middle car, and the middle car is strictly larger than the smallest car. Masha came to test these cars. She could climb into all cars, but she liked only the smallest car. It's known that a character with size *a* can climb into some car with size *b* if and only if *a*<=≤<=*b*, he or she likes it if and only if he can climb into this car and 2*a*<=≥<=*b*. You are given sizes of bears and Masha. Find out some possible integer non-negative sizes of cars.
You are given four integers *V*1, *V*2, *V*3, *V**m*(1<=≤<=*V**i*<=≤<=100) — sizes of father bear, mother bear, son bear and Masha, respectively. It's guaranteed that *V*1<=&gt;<=*V*2<=&gt;<=*V*3.
Output three integers — sizes of father bear's car, mother bear's car and son bear's car, respectively. If there are multiple possible solutions, print any. If there is no solution, print "-1" (without quotes).
[ "50 30 10 10\n", "100 50 10 21\n" ]
[ "50\n30\n10\n", "-1\n" ]
In first test case all conditions for cars' sizes are satisfied. In second test case there is no answer, because Masha should be able to climb into smallest car (so size of smallest car in not less than 21), but son bear should like it, so maximum possible size of it is 20.
500
[ { "input": "50 30 10 10", "output": "50\n30\n10" }, { "input": "100 50 10 21", "output": "-1" }, { "input": "100 50 19 10", "output": "100\n50\n19" }, { "input": "99 50 25 49", "output": "100\n99\n49" }, { "input": "3 2 1 1", "output": "4\n3\n1" }, { "input": "100 99 98 100", "output": "-1" }, { "input": "100 40 30 40", "output": "-1" }, { "input": "100 50 19 25", "output": "100\n51\n25" }, { "input": "100 50 19 30", "output": "100\n61\n30" }, { "input": "49 48 25 49", "output": "-1" }, { "input": "48 47 23 46", "output": "94\n93\n46" }, { "input": "37 23 16 20", "output": "42\n41\n20" }, { "input": "98 2 1 1", "output": "98\n3\n1" }, { "input": "99 22 13 14", "output": "99\n29\n14" }, { "input": "97 95 3 2", "output": "97\n95\n3" }, { "input": "27 3 2 3", "output": "-1" }, { "input": "13 7 6 2", "output": "-1" }, { "input": "19 17 11 6", "output": "19\n17\n11" }, { "input": "15 6 4 5", "output": "15\n11\n5" }, { "input": "21 3 1 3", "output": "-1" }, { "input": "100 99 98 97", "output": "196\n195\n98" }, { "input": "99 32 13 5", "output": "-1" }, { "input": "5 4 3 1", "output": "-1" }, { "input": "50 20 4 8", "output": "50\n20\n8" }, { "input": "60 30 10 1", "output": "-1" }, { "input": "100 50 10 1", "output": "-1" }, { "input": "40 30 20 10", "output": "40\n30\n20" }, { "input": "50 49 5 10", "output": "50\n49\n10" }, { "input": "99 98 50 97", "output": "196\n195\n97" }, { "input": "50 30 10 5", "output": "50\n30\n10" }, { "input": "4 3 2 1", "output": "4\n3\n2" }, { "input": "100 50 3 1", "output": "-1" } ]
1,516,789,686
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
5
46
5,632,000
import sys v1, v2, v3, vm = map(int, input().split()) if vm <= v3 * 2 and v3 < vm * 2: vm3 = max(vm, v3) vm2 = max(2 * vm + 1, v2) vm1 = max(vm2 + 1, v1) print(vm1, vm2, vm3, sep = '\n') else: print(-1)
Title: Masha and Bears Time Limit: None seconds Memory Limit: None megabytes Problem Description: A family consisting of father bear, mother bear and son bear owns three cars. Father bear can climb into the largest car and he likes it. Also, mother bear can climb into the middle car and she likes it. Moreover, son bear can climb into the smallest car and he likes it. It's known that the largest car is strictly larger than the middle car, and the middle car is strictly larger than the smallest car. Masha came to test these cars. She could climb into all cars, but she liked only the smallest car. It's known that a character with size *a* can climb into some car with size *b* if and only if *a*<=≤<=*b*, he or she likes it if and only if he can climb into this car and 2*a*<=≥<=*b*. You are given sizes of bears and Masha. Find out some possible integer non-negative sizes of cars. Input Specification: You are given four integers *V*1, *V*2, *V*3, *V**m*(1<=≤<=*V**i*<=≤<=100) — sizes of father bear, mother bear, son bear and Masha, respectively. It's guaranteed that *V*1<=&gt;<=*V*2<=&gt;<=*V*3. Output Specification: Output three integers — sizes of father bear's car, mother bear's car and son bear's car, respectively. If there are multiple possible solutions, print any. If there is no solution, print "-1" (without quotes). Demo Input: ['50 30 10 10\n', '100 50 10 21\n'] Demo Output: ['50\n30\n10\n', '-1\n'] Note: In first test case all conditions for cars' sizes are satisfied. In second test case there is no answer, because Masha should be able to climb into smallest car (so size of smallest car in not less than 21), but son bear should like it, so maximum possible size of it is 20.
```python import sys v1, v2, v3, vm = map(int, input().split()) if vm <= v3 * 2 and v3 < vm * 2: vm3 = max(vm, v3) vm2 = max(2 * vm + 1, v2) vm1 = max(vm2 + 1, v1) print(vm1, vm2, vm3, sep = '\n') else: print(-1) ```
0
0
none
none
none
0
[ "none" ]
null
null
Gerald got a very curious hexagon for his birthday. The boy found out that all the angles of the hexagon are equal to . Then he measured the length of its sides, and found that each of them is equal to an integer number of centimeters. There the properties of the hexagon ended and Gerald decided to draw on it. He painted a few lines, parallel to the sides of the hexagon. The lines split the hexagon into regular triangles with sides of 1 centimeter. Now Gerald wonders how many triangles he has got. But there were so many of them that Gerald lost the track of his counting. Help the boy count the triangles.
The first and the single line of the input contains 6 space-separated integers *a*1,<=*a*2,<=*a*3,<=*a*4,<=*a*5 and *a*6 (1<=≤<=*a**i*<=≤<=1000) — the lengths of the sides of the hexagons in centimeters in the clockwise order. It is guaranteed that the hexagon with the indicated properties and the exactly such sides exists.
Print a single integer — the number of triangles with the sides of one 1 centimeter, into which the hexagon is split.
[ "1 1 1 1 1 1\n", "1 2 1 2 1 2\n" ]
[ "6\n", "13\n" ]
This is what Gerald's hexagon looks like in the first sample: <img class="tex-graphics" src="https://espresso.codeforces.com/84d193e27b02c38eb1eadc536602a2ec0b9f9519.png" style="max-width: 100.0%;max-height: 100.0%;"/> And that's what it looks like in the second sample: <img class="tex-graphics" src="https://espresso.codeforces.com/e29076a96da8ca864654cc6195654d9bf07d31ce.png" style="max-width: 100.0%;max-height: 100.0%;"/>
0
[ { "input": "1 1 1 1 1 1", "output": "6" }, { "input": "1 2 1 2 1 2", "output": "13" }, { "input": "2 4 5 3 3 6", "output": "83" }, { "input": "45 19 48 18 46 21", "output": "6099" }, { "input": "66 6 65 6 66 5", "output": "5832" }, { "input": "7 5 4 8 4 5", "output": "175" }, { "input": "3 2 1 4 1 2", "output": "25" }, { "input": "7 1 7 3 5 3", "output": "102" }, { "input": "9 2 9 3 8 3", "output": "174" }, { "input": "1 6 1 5 2 5", "output": "58" }, { "input": "41 64 48 61 44 68", "output": "17488" }, { "input": "1 59 2 59 1 60", "output": "3838" }, { "input": "30 36 36 32 34 38", "output": "7052" }, { "input": "50 40 46 38 52 34", "output": "11176" }, { "input": "4 60 4 60 4 60", "output": "4576" }, { "input": "718 466 729 470 714 481", "output": "2102808" }, { "input": "131 425 143 461 95 473", "output": "441966" }, { "input": "125 7 128 8 124 11", "output": "20215" }, { "input": "677 303 685 288 692 296", "output": "1365807" }, { "input": "1 577 7 576 2 582", "output": "342171" }, { "input": "1000 1000 1000 1000 1000 1000", "output": "6000000" }, { "input": "1 1 1000 1 1 1000", "output": "4002" }, { "input": "1000 1000 1 1000 1000 1", "output": "2004000" }, { "input": "1000 1 1000 999 2 999", "output": "2003997" }, { "input": "1 1000 1 1 1000 1", "output": "4002" }, { "input": "888 888 888 887 889 887", "output": "4729487" } ]
1,440,256,841
6,941
Python 3
WRONG_ANSWER
TESTS
2
46
0
import math def sqr(x): return x * x def side_(a,b): cos_120 = -0.5 return abs((sqr(a) * sqr(b) - (2 * a * b * cos_120)) ** 0.5) def triangle_area(a,b,c): p = (a + b + c) / 2 return abs((p * (p-a) * (p-b) * (p-c)) ** 0.5) a1,a2,a3,a4,a5,a6 = map(int,input().split()) sin_120 = (-1) * ((3 ** 0.5) / 2) area1 = abs((a1 * a2) / 2 * sin_120) area2 = abs((a3 * a4) / 2 * sin_120) area3 = abs((a5 * a6) / 2 * sin_120) side1 = side_(a1,a2) side2 = side_(a3,a4) side3 = side_(a5,a6) s = triangle_area(side1,side2,side3) all_area = area1 + area2 + area3 + s print(round((all_area / ((3 ** 0.5) / 4))+1))
Title: none Time Limit: None seconds Memory Limit: None megabytes Problem Description: Gerald got a very curious hexagon for his birthday. The boy found out that all the angles of the hexagon are equal to . Then he measured the length of its sides, and found that each of them is equal to an integer number of centimeters. There the properties of the hexagon ended and Gerald decided to draw on it. He painted a few lines, parallel to the sides of the hexagon. The lines split the hexagon into regular triangles with sides of 1 centimeter. Now Gerald wonders how many triangles he has got. But there were so many of them that Gerald lost the track of his counting. Help the boy count the triangles. Input Specification: The first and the single line of the input contains 6 space-separated integers *a*1,<=*a*2,<=*a*3,<=*a*4,<=*a*5 and *a*6 (1<=≤<=*a**i*<=≤<=1000) — the lengths of the sides of the hexagons in centimeters in the clockwise order. It is guaranteed that the hexagon with the indicated properties and the exactly such sides exists. Output Specification: Print a single integer — the number of triangles with the sides of one 1 centimeter, into which the hexagon is split. Demo Input: ['1 1 1 1 1 1\n', '1 2 1 2 1 2\n'] Demo Output: ['6\n', '13\n'] Note: This is what Gerald's hexagon looks like in the first sample: <img class="tex-graphics" src="https://espresso.codeforces.com/84d193e27b02c38eb1eadc536602a2ec0b9f9519.png" style="max-width: 100.0%;max-height: 100.0%;"/> And that's what it looks like in the second sample: <img class="tex-graphics" src="https://espresso.codeforces.com/e29076a96da8ca864654cc6195654d9bf07d31ce.png" style="max-width: 100.0%;max-height: 100.0%;"/>
```python import math def sqr(x): return x * x def side_(a,b): cos_120 = -0.5 return abs((sqr(a) * sqr(b) - (2 * a * b * cos_120)) ** 0.5) def triangle_area(a,b,c): p = (a + b + c) / 2 return abs((p * (p-a) * (p-b) * (p-c)) ** 0.5) a1,a2,a3,a4,a5,a6 = map(int,input().split()) sin_120 = (-1) * ((3 ** 0.5) / 2) area1 = abs((a1 * a2) / 2 * sin_120) area2 = abs((a3 * a4) / 2 * sin_120) area3 = abs((a5 * a6) / 2 * sin_120) side1 = side_(a1,a2) side2 = side_(a3,a4) side3 = side_(a5,a6) s = triangle_area(side1,side2,side3) all_area = area1 + area2 + area3 + s print(round((all_area / ((3 ** 0.5) / 4))+1)) ```
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,673,033,704
2,147,483,647
Python 3
COMPILATION_ERROR
TESTS
0
0
0
m = input("m") n = input("n) s = m * n n = int(s / 2) print(n)
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 = input("m") n = input("n) s = m * n n = int(s / 2) print(n) ```
-1
7
B
Memory Manager
PROGRAMMING
1,600
[ "implementation" ]
B. Memory Manager
1
64
There is little time left before the release of the first national operating system BerlOS. Some of its components are not finished yet — the memory manager is among them. According to the developers' plan, in the first release the memory manager will be very simple and rectilinear. It will support three operations: - alloc n — to allocate *n* bytes of the memory and return the allocated block's identifier *x*; - erase x — to erase the block with the identifier *x*; - defragment — to defragment the free memory, bringing all the blocks as close to the beginning of the memory as possible and preserving their respective order; The memory model in this case is very simple. It is a sequence of *m* bytes, numbered for convenience from the first to the *m*-th. The first operation alloc n takes as the only parameter the size of the memory block that is to be allocated. While processing this operation, a free block of *n* successive bytes is being allocated in the memory. If the amount of such blocks is more than one, the block closest to the beginning of the memory (i.e. to the first byte) is prefered. All these bytes are marked as not free, and the memory manager returns a 32-bit integer numerical token that is the identifier of this block. If it is impossible to allocate a free block of this size, the function returns NULL. The second operation erase x takes as its parameter the identifier of some block. This operation frees the system memory, marking the bytes of this block as free for further use. In the case when this identifier does not point to the previously allocated block, which has not been erased yet, the function returns ILLEGAL_ERASE_ARGUMENT. The last operation defragment does not have any arguments and simply brings the occupied memory sections closer to the beginning of the memory without changing their respective order. In the current implementation you are to use successive integers, starting with 1, as identifiers. Each successful alloc operation procession should return following number. Unsuccessful alloc operations do not affect numeration. You are to write the implementation of the memory manager. You should output the returned value for each alloc command. You should also output ILLEGAL_ERASE_ARGUMENT for all the failed erase commands.
The first line of the input data contains two positive integers *t* and *m* (1<=≤<=*t*<=≤<=100;1<=≤<=*m*<=≤<=100), where *t* — the amount of operations given to the memory manager for processing, and *m* — the available memory size in bytes. Then there follow *t* lines where the operations themselves are given. The first operation is alloc n (1<=≤<=*n*<=≤<=100), where *n* is an integer. The second one is erase x, where *x* is an arbitrary 32-bit integer numerical token. The third operation is defragment.
Output the sequence of lines. Each line should contain either the result of alloc operation procession , or ILLEGAL_ERASE_ARGUMENT as a result of failed erase operation procession. Output lines should go in the same order in which the operations are processed. Successful procession of alloc operation should return integers, starting with 1, as the identifiers of the allocated blocks.
[ "6 10\nalloc 5\nalloc 3\nerase 1\nalloc 6\ndefragment\nalloc 6\n" ]
[ "1\n2\nNULL\n3\n" ]
none
0
[ { "input": "6 10\nalloc 5\nalloc 3\nerase 1\nalloc 6\ndefragment\nalloc 6", "output": "1\n2\nNULL\n3" }, { "input": "6 1\ndefragment\nalloc 10\nalloc 1\nerase -1\nerase 1\nerase 1", "output": "NULL\n1\nILLEGAL_ERASE_ARGUMENT\nILLEGAL_ERASE_ARGUMENT" }, { "input": "14 100\nalloc 99\nalloc 1\nalloc 1\nerase 2\nalloc 1\nerase 4\nerase 1\nalloc 100\nalloc 1\nalloc 99\ndefragment\nerase 4\nalloc 100\nalloc 99", "output": "1\n2\nNULL\n3\nILLEGAL_ERASE_ARGUMENT\nNULL\n4\nNULL\nNULL\nNULL" }, { "input": "26 25\ndefragment\nerase 1\nerase -1560200883\nalloc 44\ndefragment\nalloc 75\nalloc 22\ndefragment\nerase 4\ndefragment\nalloc 57\nalloc 53\nerase 4\nerase -1639632026\nerase -2121605039\nerase 3\nalloc 51\nalloc 65\ndefragment\nerase 2\nerase 4\nalloc 52\nerase 3\ndefragment\nerase -1842529282\nerase 3", "output": "ILLEGAL_ERASE_ARGUMENT\nILLEGAL_ERASE_ARGUMENT\nNULL\nNULL\n1\nILLEGAL_ERASE_ARGUMENT\nNULL\nNULL\nILLEGAL_ERASE_ARGUMENT\nILLEGAL_ERASE_ARGUMENT\nILLEGAL_ERASE_ARGUMENT\nILLEGAL_ERASE_ARGUMENT\nNULL\nNULL\nILLEGAL_ERASE_ARGUMENT\nILLEGAL_ERASE_ARGUMENT\nNULL\nILLEGAL_ERASE_ARGUMENT\nILLEGAL_ERASE_ARGUMENT\nILLEGAL_ERASE_ARGUMENT" }, { "input": "22 9\nerase 1\nalloc 6\nalloc 65\nerase 1\nalloc 87\nerase -1638927047\nalloc 5\nerase 2\nalloc 70\ndefragment\nalloc 20\nalloc 48\nerase -69401977\nalloc 20\ndefragment\nerase 7\ndefragment\nerase 9\nerase 7\nerase 4\ndefragment\nalloc 66", "output": "ILLEGAL_ERASE_ARGUMENT\n1\nNULL\nNULL\nILLEGAL_ERASE_ARGUMENT\n2\nNULL\nNULL\nNULL\nILLEGAL_ERASE_ARGUMENT\nNULL\nILLEGAL_ERASE_ARGUMENT\nILLEGAL_ERASE_ARGUMENT\nILLEGAL_ERASE_ARGUMENT\nILLEGAL_ERASE_ARGUMENT\nNULL" }, { "input": "12 40\nerase 1\nalloc 21\nalloc 5\nalloc 7\ndefragment\ndefragment\nerase 2\nalloc 83\nerase 4\ndefragment\nalloc 59\ndefragment", "output": "ILLEGAL_ERASE_ARGUMENT\n1\n2\n3\nNULL\nILLEGAL_ERASE_ARGUMENT\nNULL" }, { "input": "38 18\nalloc 72\nerase 2\nalloc 50\ndefragment\nerase 3\ndefragment\nalloc 43\nalloc 41\ndefragment\ndefragment\nalloc 26\nalloc 46\nalloc 16\nalloc 15\ndefragment\ndefragment\nalloc 95\nerase 7\nerase 7\nerase 5\nerase 2\nerase 9\nerase 7\nalloc 43\ndefragment\nerase 7\ndefragment\nalloc 48\nalloc 77\nerase 10\nerase 11\nalloc 16\nalloc 84\nerase 1\ndefragment\nalloc 86\ndefragment\nerase 13", "output": "NULL\nILLEGAL_ERASE_ARGUMENT\nNULL\nILLEGAL_ERASE_ARGUMENT\nNULL\nNULL\nNULL\nNULL\n1\nNULL\nNULL\nILLEGAL_ERASE_ARGUMENT\nILLEGAL_ERASE_ARGUMENT\nILLEGAL_ERASE_ARGUMENT\nILLEGAL_ERASE_ARGUMENT\nILLEGAL_ERASE_ARGUMENT\nILLEGAL_ERASE_ARGUMENT\nNULL\nILLEGAL_ERASE_ARGUMENT\nNULL\nNULL\nILLEGAL_ERASE_ARGUMENT\nILLEGAL_ERASE_ARGUMENT\nNULL\nNULL\nNULL\nILLEGAL_ERASE_ARGUMENT" }, { "input": "37 74\nalloc 11\ndefragment\nerase 1\ndefragment\nerase 2\ndefragment\nalloc 90\nerase 3\nerase 2\nerase 3\nerase 1\nerase 1\nalloc 38\nalloc 19\nerase 1\nerase 3\ndefragment\nalloc 93\nerase 5\nerase 4\nalloc 66\nalloc 71\nerase 5\ndefragment\ndefragment\ndefragment\ndefragment\nerase 7\nalloc 47\nerase -95616683\nerase 2\nalloc 28\nalloc 32\nerase 11\nalloc 50\ndefragment\ndefragment", "output": "1\nILLEGAL_ERASE_ARGUMENT\nNULL\nILLEGAL_ERASE_ARGUMENT\nILLEGAL_ERASE_ARGUMENT\nILLEGAL_ERASE_ARGUMENT\nILLEGAL_ERASE_ARGUMENT\nILLEGAL_ERASE_ARGUMENT\n2\n3\nILLEGAL_ERASE_ARGUMENT\nNULL\nILLEGAL_ERASE_ARGUMENT\nILLEGAL_ERASE_ARGUMENT\nNULL\nNULL\nILLEGAL_ERASE_ARGUMENT\nILLEGAL_ERASE_ARGUMENT\nNULL\nILLEGAL_ERASE_ARGUMENT\n4\n5\nILLEGAL_ERASE_ARGUMENT\nNULL" }, { "input": "16 49\nerase -751005193\ndefragment\nalloc 37\nalloc 82\nerase 3\nerase 1\nalloc 80\nalloc 51\ndefragment\nalloc 74\nerase 1\nalloc 91\ndefragment\ndefragment\nalloc 98\ndefragment", "output": "ILLEGAL_ERASE_ARGUMENT\n1\nNULL\nILLEGAL_ERASE_ARGUMENT\nNULL\nNULL\nNULL\nILLEGAL_ERASE_ARGUMENT\nNULL\nNULL" }, { "input": "42 98\ndefragment\ndefragment\ndefragment\ndefragment\ndefragment\nalloc 5\nalloc 66\ndefragment\nerase 3\nalloc 53\ndefragment\nerase 4\nerase 2\nalloc 70\nerase 3\ndefragment\ndefragment\nerase 2\nerase 3\nerase -1327931832\nalloc 93\nalloc 64\nerase 7\nerase 6\nerase 3\nalloc 61\nalloc 12\nalloc 65\nerase 2\nalloc 46\nerase 11\nerase 9\nerase 9\nerase 6\nalloc 2\nalloc 78\ndefragment\nerase 13\nerase 6\nerase 10\nalloc 53\nalloc 46", "output": "1\n2\nILLEGAL_ERASE_ARGUMENT\nNULL\nILLEGAL_ERASE_ARGUMENT\n3\nILLEGAL_ERASE_ARGUMENT\nILLEGAL_ERASE_ARGUMENT\nILLEGAL_ERASE_ARGUMENT\n4\nNULL\nILLEGAL_ERASE_ARGUMENT\nILLEGAL_ERASE_ARGUMENT\nILLEGAL_ERASE_ARGUMENT\nNULL\nNULL\nNULL\nILLEGAL_ERASE_ARGUMENT\nNULL\nILLEGAL_ERASE_ARGUMENT\nILLEGAL_ERASE_ARGUMENT\nILLEGAL_ERASE_ARGUMENT\nILLEGAL_ERASE_ARGUMENT\nNULL\nNULL\nILLEGAL_ERASE_ARGUMENT\nILLEGAL_ERASE_ARGUMENT\nILLEGAL_ERASE_ARGUMENT\nNULL\nNULL" }, { "input": "19 46\nalloc 21\nerase 2\nerase 1\ndefragment\nalloc 4\ndefragment\ndefragment\nalloc 40\nerase 1\ndefragment\ndefragment\nalloc 68\nerase -388966015\nalloc 85\nalloc 53\nerase 4\ndefragment\nalloc 49\nalloc 88", "output": "1\nILLEGAL_ERASE_ARGUMENT\n2\n3\nILLEGAL_ERASE_ARGUMENT\nNULL\nILLEGAL_ERASE_ARGUMENT\nNULL\nNULL\nILLEGAL_ERASE_ARGUMENT\nNULL\nNULL" }, { "input": "44 46\nalloc 28\nalloc 36\ndefragment\nerase -937404236\nalloc 71\ndefragment\nalloc 81\nalloc 51\nerase 3\ndefragment\nalloc 48\nerase 1\ndefragment\nalloc 36\ndefragment\ndefragment\nerase 1\ndefragment\ndefragment\nerase -1173350787\nalloc 94\nerase 5\ndefragment\nerase 9\nalloc 98\nerase 7\ndefragment\nerase 5\nerase 1\ndefragment\nerase 2\ndefragment\nerase 4\ndefragment\nerase 9\nalloc 8\ndefragment\nerase 9\ndefragment\ndefragment\ndefragment\nerase 1\nalloc 70\nerase 9", "output": "1\nNULL\nILLEGAL_ERASE_ARGUMENT\nNULL\nNULL\nNULL\nILLEGAL_ERASE_ARGUMENT\nNULL\n2\nILLEGAL_ERASE_ARGUMENT\nILLEGAL_ERASE_ARGUMENT\nNULL\nILLEGAL_ERASE_ARGUMENT\nILLEGAL_ERASE_ARGUMENT\nNULL\nILLEGAL_ERASE_ARGUMENT\nILLEGAL_ERASE_ARGUMENT\nILLEGAL_ERASE_ARGUMENT\nILLEGAL_ERASE_ARGUMENT\nILLEGAL_ERASE_ARGUMENT\n3\nILLEGAL_ERASE_ARGUMENT\nILLEGAL_ERASE_ARGUMENT\nNULL\nILLEGAL_ERASE_ARGUMENT" }, { "input": "47 43\nerase 1\nalloc 95\nalloc 53\nerase 2\ndefragment\nalloc 100\nerase 4\nerase 2\nerase -849472053\ndefragment\nerase -638355221\nalloc 90\nerase 3\nerase 2\ndefragment\nalloc 17\nerase 5\ndefragment\nerase 6\ndefragment\nerase 3\ndefragment\ndefragment\nalloc 99\nalloc 69\nalloc 80\nerase 9\nerase 5\ndefragment\nerase 7\ndefragment\nalloc 93\ndefragment\ndefragment\nalloc 25\ndefragment\nalloc 14\nerase 8\nerase 4\ndefragment\ndefragment\nalloc 96\nerase 9\nalloc 63\nerase 8\ndefragment\nerase 10", "output": "ILLEGAL_ERASE_ARGUMENT\nNULL\nNULL\nILLEGAL_ERASE_ARGUMENT\nNULL\nILLEGAL_ERASE_ARGUMENT\nILLEGAL_ERASE_ARGUMENT\nILLEGAL_ERASE_ARGUMENT\nILLEGAL_ERASE_ARGUMENT\nNULL\nILLEGAL_ERASE_ARGUMENT\nILLEGAL_ERASE_ARGUMENT\n1\nILLEGAL_ERASE_ARGUMENT\nILLEGAL_ERASE_ARGUMENT\nILLEGAL_ERASE_ARGUMENT\nNULL\nNULL\nNULL\nILLEGAL_ERASE_ARGUMENT\nILLEGAL_ERASE_ARGUMENT\nILLEGAL_ERASE_ARGUMENT\nNULL\n2\nNULL\nILLEGAL_ERASE_ARGUMENT\nILLEGAL_ERASE_ARGUMENT\nNULL\nILLEGAL_ERASE_ARGUMENT\nNULL\nILLEGAL_ERASE_ARGUMENT\nILLEGAL..." }, { "input": "26 25\nalloc 25\nerase 1\nalloc 24\nerase 2\nalloc 23\nerase 3\nalloc 24\nerase 4\nalloc 24\nerase 5\nalloc 21\nerase 6\nalloc 24\nerase 7\nalloc 25\nerase 8\nalloc 25\nerase 9\nalloc 24\nerase 10\nalloc 25\nerase 11\nalloc 25\nerase 12\nalloc 25\nerase 13", "output": "1\n2\n3\n4\n5\n6\n7\n8\n9\n10\n11\n12\n13" }, { "input": "22 9\nalloc 9\nerase 1\nalloc 9\nerase 2\nalloc 9\nerase 3\nalloc 9\nerase 4\nalloc 9\nerase 5\nalloc 9\nerase 6\nalloc 9\nerase 7\nalloc 9\nerase 8\nalloc 9\nerase 9\nalloc 9\nerase 10\nalloc 9\nerase 11", "output": "1\n2\n3\n4\n5\n6\n7\n8\n9\n10\n11" }, { "input": "7 6\nalloc 1\nalloc 2\nalloc 3\nerase 1\ndefragment\nerase 3\nalloc 4", "output": "1\n2\n3\n4" }, { "input": "3 1\nerase -1\nerase 0\nerase -2147483648", "output": "ILLEGAL_ERASE_ARGUMENT\nILLEGAL_ERASE_ARGUMENT\nILLEGAL_ERASE_ARGUMENT" }, { "input": "7 100\nalloc 100\nerase 2147483647\nerase 1\nalloc 50\nalloc 50\nerase 3\nerase -2147483648", "output": "1\nILLEGAL_ERASE_ARGUMENT\n2\n3\nILLEGAL_ERASE_ARGUMENT" }, { "input": "12 10\nalloc 6\nalloc 2\nerase 1\nalloc 4\nalloc 2\nerase 3\nalloc 2\nalloc 3\nalloc 1\nalloc 1\nalloc 1\nalloc 1", "output": "1\n2\n3\n4\n5\nNULL\n6\n7\n8\n9" }, { "input": "8 50\nalloc 51\ndefragment\nalloc 100\ndefragment\nerase 1\nalloc 50\ndefragment\nalloc 50", "output": "NULL\nNULL\nILLEGAL_ERASE_ARGUMENT\n1\nNULL" }, { "input": "10 10\nalloc 10\nerase -1\nerase 1\nalloc 5\nerase -1\nalloc 5\nerase 0\nalloc 5\nerase 0\nalloc 5", "output": "1\nILLEGAL_ERASE_ARGUMENT\n2\nILLEGAL_ERASE_ARGUMENT\n3\nILLEGAL_ERASE_ARGUMENT\nNULL\nILLEGAL_ERASE_ARGUMENT\nNULL" }, { "input": "16 10\nalloc 10\ndefragment\ndefragment\ndefragment\nalloc 10\nerase 1\nerase 2\nalloc 6\ndefragment\ndefragment\nalloc 4\ndefragment\ndefragment\nerase 3\ndefragment\nalloc 6", "output": "1\nNULL\nILLEGAL_ERASE_ARGUMENT\n2\n3\nNULL" }, { "input": "16 10\nalloc 10\ndefragment\ndefragment\ndefragment\nalloc 10\nerase 1\nerase 2\nalloc 6\ndefragment\ndefragment\nalloc 4\ndefragment\ndefragment\nerase 2\ndefragment\nalloc 6", "output": "1\nNULL\nILLEGAL_ERASE_ARGUMENT\n2\n3\n4" } ]
1,623,170,983
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
0
186
0
def main(): t, m = map(int, input().split())#t:Cantidad de ordenes dadas, m:Tamaño de memoria disponible en bytes mem = [0]*m iden = 1 #Identificador de los bloques ans = [] #Respuestas for _ in range(t): orders = list(input().split()) order = orders[0] #Órden if len(orders) == 2: n = orders[1]; n = int(n) #Número de la orden if order == "alloc": spa = 0 while n+spa != m: if n <= mem.count(0): if mem[mem.index(0)+spa:mem.index(0)+n+spa] == [0]*n: mem[mem.index(0)+spa:mem.index(0)+n+spa] = [iden]*n spa = m-n ans.append(iden) iden += 1 else: spa +=1 if m-n == spa and mem.count(iden-1) != n: ans.append("NULL") else: ans.append("NULL") spa = m-n if n == m: if mem.count(0) == m: mem = [iden]*n ans.append(iden) iden += 1 else: ans.append("NULL") spa = m-n elif order == "erase": if n in mem: mem = [0 if i == n else i for i in mem] else: ans.append("ILLEGAL_ERASE_ARGUMENT") elif order == "defragment": for _ in mem: if 0 in mem: mem.remove(0) mem = mem + [0]*(m-int(len(mem))) print(mem) for i in ans: print(i) if __name__ == "__main__": main()
Title: Memory Manager Time Limit: 1 seconds Memory Limit: 64 megabytes Problem Description: There is little time left before the release of the first national operating system BerlOS. Some of its components are not finished yet — the memory manager is among them. According to the developers' plan, in the first release the memory manager will be very simple and rectilinear. It will support three operations: - alloc n — to allocate *n* bytes of the memory and return the allocated block's identifier *x*; - erase x — to erase the block with the identifier *x*; - defragment — to defragment the free memory, bringing all the blocks as close to the beginning of the memory as possible and preserving their respective order; The memory model in this case is very simple. It is a sequence of *m* bytes, numbered for convenience from the first to the *m*-th. The first operation alloc n takes as the only parameter the size of the memory block that is to be allocated. While processing this operation, a free block of *n* successive bytes is being allocated in the memory. If the amount of such blocks is more than one, the block closest to the beginning of the memory (i.e. to the first byte) is prefered. All these bytes are marked as not free, and the memory manager returns a 32-bit integer numerical token that is the identifier of this block. If it is impossible to allocate a free block of this size, the function returns NULL. The second operation erase x takes as its parameter the identifier of some block. This operation frees the system memory, marking the bytes of this block as free for further use. In the case when this identifier does not point to the previously allocated block, which has not been erased yet, the function returns ILLEGAL_ERASE_ARGUMENT. The last operation defragment does not have any arguments and simply brings the occupied memory sections closer to the beginning of the memory without changing their respective order. In the current implementation you are to use successive integers, starting with 1, as identifiers. Each successful alloc operation procession should return following number. Unsuccessful alloc operations do not affect numeration. You are to write the implementation of the memory manager. You should output the returned value for each alloc command. You should also output ILLEGAL_ERASE_ARGUMENT for all the failed erase commands. Input Specification: The first line of the input data contains two positive integers *t* and *m* (1<=≤<=*t*<=≤<=100;1<=≤<=*m*<=≤<=100), where *t* — the amount of operations given to the memory manager for processing, and *m* — the available memory size in bytes. Then there follow *t* lines where the operations themselves are given. The first operation is alloc n (1<=≤<=*n*<=≤<=100), where *n* is an integer. The second one is erase x, where *x* is an arbitrary 32-bit integer numerical token. The third operation is defragment. Output Specification: Output the sequence of lines. Each line should contain either the result of alloc operation procession , or ILLEGAL_ERASE_ARGUMENT as a result of failed erase operation procession. Output lines should go in the same order in which the operations are processed. Successful procession of alloc operation should return integers, starting with 1, as the identifiers of the allocated blocks. Demo Input: ['6 10\nalloc 5\nalloc 3\nerase 1\nalloc 6\ndefragment\nalloc 6\n'] Demo Output: ['1\n2\nNULL\n3\n'] Note: none
```python def main(): t, m = map(int, input().split())#t:Cantidad de ordenes dadas, m:Tamaño de memoria disponible en bytes mem = [0]*m iden = 1 #Identificador de los bloques ans = [] #Respuestas for _ in range(t): orders = list(input().split()) order = orders[0] #Órden if len(orders) == 2: n = orders[1]; n = int(n) #Número de la orden if order == "alloc": spa = 0 while n+spa != m: if n <= mem.count(0): if mem[mem.index(0)+spa:mem.index(0)+n+spa] == [0]*n: mem[mem.index(0)+spa:mem.index(0)+n+spa] = [iden]*n spa = m-n ans.append(iden) iden += 1 else: spa +=1 if m-n == spa and mem.count(iden-1) != n: ans.append("NULL") else: ans.append("NULL") spa = m-n if n == m: if mem.count(0) == m: mem = [iden]*n ans.append(iden) iden += 1 else: ans.append("NULL") spa = m-n elif order == "erase": if n in mem: mem = [0 if i == n else i for i in mem] else: ans.append("ILLEGAL_ERASE_ARGUMENT") elif order == "defragment": for _ in mem: if 0 in mem: mem.remove(0) mem = mem + [0]*(m-int(len(mem))) print(mem) for i in ans: print(i) if __name__ == "__main__": main() ```
0
322
B
Ciel and Flowers
PROGRAMMING
1,600
[ "combinatorics", "math" ]
null
null
Fox Ciel has some flowers: *r* red flowers, *g* green flowers and *b* blue flowers. She wants to use these flowers to make several bouquets. There are 4 types of bouquets: - To make a "red bouquet", it needs 3 red flowers. - To make a "green bouquet", it needs 3 green flowers. - To make a "blue bouquet", it needs 3 blue flowers. - To make a "mixing bouquet", it needs 1 red, 1 green and 1 blue flower. Help Fox Ciel to find the maximal number of bouquets she can make.
The first line contains three integers *r*, *g* and *b* (0<=≤<=*r*,<=*g*,<=*b*<=≤<=109) — the number of red, green and blue flowers.
Print the maximal number of bouquets Fox Ciel can make.
[ "3 6 9\n", "4 4 4\n", "0 0 0\n" ]
[ "6\n", "4\n", "0\n" ]
In test case 1, we can make 1 red bouquet, 2 green bouquets and 3 blue bouquets. In test case 2, we can make 1 red, 1 green, 1 blue and 1 mixing bouquet.
1,000
[ { "input": "3 6 9", "output": "6" }, { "input": "4 4 4", "output": "4" }, { "input": "0 0 0", "output": "0" }, { "input": "0 3 6", "output": "3" }, { "input": "7 8 9", "output": "7" }, { "input": "8 8 9", "output": "8" }, { "input": "15 3 999", "output": "339" }, { "input": "32 62 92", "output": "62" }, { "input": "123456789 123456789 123456789", "output": "123456789" }, { "input": "3 5 5", "output": "4" }, { "input": "666806767 385540591 357848286", "output": "470065214" }, { "input": "80010646 727118126 817880463", "output": "541669744" }, { "input": "829651016 732259171 572879931", "output": "711596705" }, { "input": "242854896 442432924 180395753", "output": "288561190" }, { "input": "139978911 5123031 935395222", "output": "360165721" }, { "input": "553182792 10264076 395427398", "output": "319624755" }, { "input": "597790453 720437830 855459575", "output": "724562619" }, { "input": "494914467 356982656 757942689", "output": "536613270" }, { "input": "908118348 67156409 217974865", "output": "397749873" }, { "input": "952726009 629846517 972974334", "output": "851848953" }, { "input": "775140200 616574841 630329230", "output": "674014756" }, { "input": "524780569 326748594 90361407", "output": "313963523" }, { "input": "937984449 184405994 992844522", "output": "705078321" }, { "input": "835108464 525983528 452876698", "output": "604656229" }, { "input": "879716125 531124573 207876166", "output": "539572288" }, { "input": "292920005 241298326 667908343", "output": "400708891" }, { "input": "1000000000 1000000000 1000000000", "output": "1000000000" }, { "input": "1000000000 999999999 999999998", "output": "999999998" }, { "input": "999999998 999999998 999999999", "output": "999999998" }, { "input": "0 1 1", "output": "0" }, { "input": "0 1000000000 0", "output": "333333333" }, { "input": "0 1 0", "output": "0" }, { "input": "1 0 0", "output": "0" }, { "input": "0 2 2", "output": "0" }, { "input": "3 3 5", "output": "3" }, { "input": "2 2 0", "output": "0" }, { "input": "0 5 5", "output": "2" }, { "input": "2 0 11", "output": "3" }, { "input": "9 9 7", "output": "8" }, { "input": "65 30 74", "output": "56" } ]
1,462,776,348
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
5
124
5,120,000
buffer = input().split() array = [] for i in buffer: array.append(int(i)) sum = int(array[0]/3) sum += int((array[1])/3) sum += int((array[2])/3) array2 = [] for i in array: array2.append(i%3) array2.sort() sum += array2[0] print(int(sum))
Title: Ciel and Flowers Time Limit: None seconds Memory Limit: None megabytes Problem Description: Fox Ciel has some flowers: *r* red flowers, *g* green flowers and *b* blue flowers. She wants to use these flowers to make several bouquets. There are 4 types of bouquets: - To make a "red bouquet", it needs 3 red flowers. - To make a "green bouquet", it needs 3 green flowers. - To make a "blue bouquet", it needs 3 blue flowers. - To make a "mixing bouquet", it needs 1 red, 1 green and 1 blue flower. Help Fox Ciel to find the maximal number of bouquets she can make. Input Specification: The first line contains three integers *r*, *g* and *b* (0<=≤<=*r*,<=*g*,<=*b*<=≤<=109) — the number of red, green and blue flowers. Output Specification: Print the maximal number of bouquets Fox Ciel can make. Demo Input: ['3 6 9\n', '4 4 4\n', '0 0 0\n'] Demo Output: ['6\n', '4\n', '0\n'] Note: In test case 1, we can make 1 red bouquet, 2 green bouquets and 3 blue bouquets. In test case 2, we can make 1 red, 1 green, 1 blue and 1 mixing bouquet.
```python buffer = input().split() array = [] for i in buffer: array.append(int(i)) sum = int(array[0]/3) sum += int((array[1])/3) sum += int((array[2])/3) array2 = [] for i in array: array2.append(i%3) array2.sort() sum += array2[0] print(int(sum)) ```
0
721
B
Passwords
PROGRAMMING
1,100
[ "implementation", "math", "sortings", "strings" ]
null
null
Vanya is managed to enter his favourite site Codehorses. Vanya uses *n* distinct passwords for sites at all, however he can't remember which one exactly he specified during Codehorses registration. Vanya will enter passwords in order of non-decreasing their lengths, and he will enter passwords of same length in arbitrary order. Just when Vanya will have entered the correct password, he is immediately authorized on the site. Vanya will not enter any password twice. Entering any passwords takes one second for Vanya. But if Vanya will enter wrong password *k* times, then he is able to make the next try only 5 seconds after that. Vanya makes each try immediately, that is, at each moment when Vanya is able to enter password, he is doing that. Determine how many seconds will Vanya need to enter Codehorses in the best case for him (if he spends minimum possible number of second) and in the worst case (if he spends maximum possible amount of seconds).
The first line of the input contains two integers *n* and *k* (1<=≤<=*n*,<=*k*<=≤<=100) — the number of Vanya's passwords and the number of failed tries, after which the access to the site is blocked for 5 seconds. The next *n* lines contains passwords, one per line — pairwise distinct non-empty strings consisting of latin letters and digits. Each password length does not exceed 100 characters. The last line of the input contains the Vanya's Codehorses password. It is guaranteed that the Vanya's Codehorses password is equal to some of his *n* passwords.
Print two integers — time (in seconds), Vanya needs to be authorized to Codehorses in the best case for him and in the worst case respectively.
[ "5 2\ncba\nabc\nbb1\nabC\nABC\nabc\n", "4 100\n11\n22\n1\n2\n22\n" ]
[ "1 15\n", "3 4\n" ]
Consider the first sample case. As soon as all passwords have the same length, Vanya can enter the right password at the first try as well as at the last try. If he enters it at the first try, he spends exactly 1 second. Thus in the best case the answer is 1. If, at the other hand, he enters it at the last try, he enters another 4 passwords before. He spends 2 seconds to enter first 2 passwords, then he waits 5 seconds as soon as he made 2 wrong tries. Then he spends 2 more seconds to enter 2 wrong passwords, again waits 5 seconds and, finally, enters the correct password spending 1 more second. In summary in the worst case he is able to be authorized in 15 seconds. Consider the second sample case. There is no way of entering passwords and get the access to the site blocked. As soon as the required password has length of 2, Vanya enters all passwords of length 1 anyway, spending 2 seconds for that. Then, in the best case, he immediately enters the correct password and the answer for the best case is 3, but in the worst case he enters wrong password of length 2 and only then the right one, spending 4 seconds at all.
1,000
[ { "input": "5 2\ncba\nabc\nbb1\nabC\nABC\nabc", "output": "1 15" }, { "input": "4 100\n11\n22\n1\n2\n22", "output": "3 4" }, { "input": "1 1\na1\na1", "output": "1 1" }, { "input": "1 100\na1\na1", "output": "1 1" }, { "input": "2 1\nabc\nAbc\nAbc", "output": "1 7" }, { "input": "2 2\nabc\nAbc\nabc", "output": "1 2" }, { "input": "2 1\nab\nabc\nab", "output": "1 1" }, { "input": "2 2\nab\nabc\nab", "output": "1 1" }, { "input": "2 1\nab\nabc\nabc", "output": "7 7" }, { "input": "2 2\nab\nabc\nabc", "output": "2 2" }, { "input": "10 3\nOIbV1igi\no\nZS\nQM\n9woLzI\nWreboD\nQ7yl\nA5Rb\nS9Lno72TkP\nfT97o\no", "output": "1 1" }, { "input": "10 3\nHJZNMsT\nLaPcH2C\nlrhqIO\n9cxw\noTC1XwjW\nGHL9Ul6\nUyIs\nPuzwgR4ZKa\nyIByoKR5\nd3QA\nPuzwgR4ZKa", "output": "25 25" }, { "input": "20 5\nvSyC787KlIL8kZ2Uv5sw\nWKWOP\n7i8J3E8EByIq\nNW2VyGweL\nmyR2sRNu\nmXusPP0\nf4jgGxra\n4wHRzRhOCpEt\npPz9kybGb\nOtSpePCRoG5nkjZ2VxRy\nwHYsSttWbJkg\nKBOP9\nQfiOiFyHPPsw3GHo8J8\nxB8\nqCpehZEeEhdq\niOLjICK6\nQ91\nHmCsfMGTFKoFFnv238c\nJKjhg\ngkEUh\nKBOP9", "output": "3 11" }, { "input": "15 2\nw6S9WyU\nMVh\nkgUhQHW\nhGQNOF\nUuym\n7rGQA\nBM8vLPRB\n9E\nDs32U\no\nz1aV2C5T\n8\nzSXjrqQ\n1FO\n3kIt\nBM8vLPRB", "output": "44 50" }, { "input": "20 2\ni\n5Rp6\nE4vsr\nSY\nORXx\nh13C\nk6tzC\ne\nN\nKQf4C\nWZcdL\ndiA3v\n0InQT\nuJkAr\nGCamp\nBuIRd\nY\nM\nxZYx7\n0a5A\nWZcdL", "output": "36 65" }, { "input": "20 2\naWLQ6\nSgQ9r\nHcPdj\n2BNaO\n3TjNb\nnvwFM\nqsKt7\nFnb6N\nLoc0p\njxuLq\nBKAjf\nEKgZB\nBfOSa\nsMIvr\nuIWcR\nIura3\nLAqSf\ntXq3G\n8rQ8I\n8otAO\nsMIvr", "output": "1 65" }, { "input": "20 15\n0ZpQugVlN7\nm0SlKGnohN\nRFXTqhNGcn\n1qm2ZbB\nQXtJWdf78P\nbc2vH\nP21dty2Z1P\nm2c71LFhCk\n23EuP1Dvh3\nanwri5RhQN\n55v6HYv288\n1u5uKOjM5r\n6vg0GC1\nDAPYiA3ns1\nUZaaJ3Gmnk\nwB44x7V4Zi\n4hgB2oyU8P\npYFQpy8gGK\ndbz\nBv\n55v6HYv288", "output": "6 25" }, { "input": "3 1\na\nb\naa\naa", "output": "13 13" }, { "input": "6 3\nab\nac\nad\nabc\nabd\nabe\nabc", "output": "9 11" }, { "input": "4 2\n1\n2\n11\n22\n22", "output": "8 9" }, { "input": "2 1\n1\n12\n12", "output": "7 7" }, { "input": "3 1\nab\nabc\nabd\nabc", "output": "7 13" }, { "input": "2 1\na\nab\nab", "output": "7 7" }, { "input": "5 2\na\nb\nc\nab\naa\naa", "output": "9 15" }, { "input": "6 1\n1\n2\n11\n22\n111\n2222\n22", "output": "13 19" }, { "input": "3 1\n1\n2\n11\n11", "output": "13 13" }, { "input": "10 4\na\nb\nc\nd\ne\nf\nab\ncd\nac\nad\nac", "output": "12 20" }, { "input": "4 2\na\nb\nc\nd\na", "output": "1 9" }, { "input": "4 1\n1\n2\n3\n4\n4", "output": "1 19" }, { "input": "5 1\na\nb\nc\nd\nef\nef", "output": "25 25" }, { "input": "6 4\n1\n2\n22\n33\n44\n555\n555", "output": "11 11" }, { "input": "5 2\na\nb\nc\nd\nab\nab", "output": "15 15" }, { "input": "6 2\n1\n2\n3\n4\n5\n23\n23", "output": "16 16" }, { "input": "4 2\na\nb\naa\nbb\naa", "output": "8 9" }, { "input": "5 4\na\nbb\ncc\ndd\nee\nbb", "output": "2 10" }, { "input": "4 1\na\nb\nc\nab\nab", "output": "19 19" }, { "input": "7 100\na\nb\nc\nd\ne\ng\nab\nab", "output": "7 7" }, { "input": "6 1\na\nb\nc\nd\ne\naa\naa", "output": "31 31" }, { "input": "4 1\na\nas\nasd\nasde\nasde", "output": "19 19" }, { "input": "5 2\n1\n2\n3\n11\n22\n22", "output": "9 15" }, { "input": "10 2\na\nb\nc\nd\nee\nff\ngg\nhh\nii\njj\nii", "output": "15 30" }, { "input": "3 1\na\nab\nbc\nab", "output": "7 13" }, { "input": "6 4\na\nb\nc\nbb\nbc\ncc\ncc", "output": "4 11" } ]
1,646,934,801
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
6
31
0
n,k=list(map(int,input().split())) f=[] for i in range(n): a=input() f.append(len(a)) a=len(input()) f.sort() count=0 j=0 for i in f: if count%k==0: j+=5 count+=1 if i>=a: break min=count+j-5 count=0 j=0 for i in f: if count%k==0: j+=5 count+=1 if i>a: break max=count+j-5 print(min,max)
Title: Passwords Time Limit: None seconds Memory Limit: None megabytes Problem Description: Vanya is managed to enter his favourite site Codehorses. Vanya uses *n* distinct passwords for sites at all, however he can't remember which one exactly he specified during Codehorses registration. Vanya will enter passwords in order of non-decreasing their lengths, and he will enter passwords of same length in arbitrary order. Just when Vanya will have entered the correct password, he is immediately authorized on the site. Vanya will not enter any password twice. Entering any passwords takes one second for Vanya. But if Vanya will enter wrong password *k* times, then he is able to make the next try only 5 seconds after that. Vanya makes each try immediately, that is, at each moment when Vanya is able to enter password, he is doing that. Determine how many seconds will Vanya need to enter Codehorses in the best case for him (if he spends minimum possible number of second) and in the worst case (if he spends maximum possible amount of seconds). Input Specification: The first line of the input contains two integers *n* and *k* (1<=≤<=*n*,<=*k*<=≤<=100) — the number of Vanya's passwords and the number of failed tries, after which the access to the site is blocked for 5 seconds. The next *n* lines contains passwords, one per line — pairwise distinct non-empty strings consisting of latin letters and digits. Each password length does not exceed 100 characters. The last line of the input contains the Vanya's Codehorses password. It is guaranteed that the Vanya's Codehorses password is equal to some of his *n* passwords. Output Specification: Print two integers — time (in seconds), Vanya needs to be authorized to Codehorses in the best case for him and in the worst case respectively. Demo Input: ['5 2\ncba\nabc\nbb1\nabC\nABC\nabc\n', '4 100\n11\n22\n1\n2\n22\n'] Demo Output: ['1 15\n', '3 4\n'] Note: Consider the first sample case. As soon as all passwords have the same length, Vanya can enter the right password at the first try as well as at the last try. If he enters it at the first try, he spends exactly 1 second. Thus in the best case the answer is 1. If, at the other hand, he enters it at the last try, he enters another 4 passwords before. He spends 2 seconds to enter first 2 passwords, then he waits 5 seconds as soon as he made 2 wrong tries. Then he spends 2 more seconds to enter 2 wrong passwords, again waits 5 seconds and, finally, enters the correct password spending 1 more second. In summary in the worst case he is able to be authorized in 15 seconds. Consider the second sample case. There is no way of entering passwords and get the access to the site blocked. As soon as the required password has length of 2, Vanya enters all passwords of length 1 anyway, spending 2 seconds for that. Then, in the best case, he immediately enters the correct password and the answer for the best case is 3, but in the worst case he enters wrong password of length 2 and only then the right one, spending 4 seconds at all.
```python n,k=list(map(int,input().split())) f=[] for i in range(n): a=input() f.append(len(a)) a=len(input()) f.sort() count=0 j=0 for i in f: if count%k==0: j+=5 count+=1 if i>=a: break min=count+j-5 count=0 j=0 for i in f: if count%k==0: j+=5 count+=1 if i>a: break max=count+j-5 print(min,max) ```
0
735
A
Ostap and Grasshopper
PROGRAMMING
800
[ "implementation", "strings" ]
null
null
On the way to Rio de Janeiro Ostap kills time playing with a grasshopper he took with him in a special box. Ostap builds a line of length *n* such that some cells of this line are empty and some contain obstacles. Then, he places his grasshopper to one of the empty cells and a small insect in another empty cell. The grasshopper wants to eat the insect. Ostap knows that grasshopper is able to jump to any empty cell that is exactly *k* cells away from the current (to the left or to the right). Note that it doesn't matter whether intermediate cells are empty or not as the grasshopper makes a jump over them. For example, if *k*<==<=1 the grasshopper can jump to a neighboring cell only, and if *k*<==<=2 the grasshopper can jump over a single cell. Your goal is to determine whether there is a sequence of jumps such that grasshopper will get from his initial position to the cell with an insect.
The first line of the input contains two integers *n* and *k* (2<=≤<=*n*<=≤<=100, 1<=≤<=*k*<=≤<=*n*<=-<=1) — the number of cells in the line and the length of one grasshopper's jump. The second line contains a string of length *n* consisting of characters '.', '#', 'G' and 'T'. Character '.' means that the corresponding cell is empty, character '#' means that the corresponding cell contains an obstacle and grasshopper can't jump there. Character 'G' means that the grasshopper starts at this position and, finally, 'T' means that the target insect is located at this cell. It's guaranteed that characters 'G' and 'T' appear in this line exactly once.
If there exists a sequence of jumps (each jump of length *k*), such that the grasshopper can get from his initial position to the cell with the insect, print "YES" (without quotes) in the only line of the input. Otherwise, print "NO" (without quotes).
[ "5 2\n#G#T#\n", "6 1\nT....G\n", "7 3\nT..#..G\n", "6 2\n..GT..\n" ]
[ "YES\n", "YES\n", "NO\n", "NO\n" ]
In the first sample, the grasshopper can make one jump to the right in order to get from cell 2 to cell 4. In the second sample, the grasshopper is only able to jump to neighboring cells but the way to the insect is free — he can get there by jumping left 5 times. In the third sample, the grasshopper can't make a single jump. In the fourth sample, the grasshopper can only jump to the cells with odd indices, thus he won't be able to reach the insect.
500
[ { "input": "5 2\n#G#T#", "output": "YES" }, { "input": "6 1\nT....G", "output": "YES" }, { "input": "7 3\nT..#..G", "output": "NO" }, { "input": "6 2\n..GT..", "output": "NO" }, { "input": "2 1\nGT", "output": "YES" }, { "input": "100 5\nG####.####.####.####.####.####.####.####.####.####.####.####.####.####.####.####.####.####.####T####", "output": "YES" }, { "input": "100 5\nG####.####.####.####.####.####.####.####.####.####.####.####.####.#########.####.####.####.####T####", "output": "NO" }, { "input": "2 1\nTG", "output": "YES" }, { "input": "99 1\n...T.............................................................................................G.", "output": "YES" }, { "input": "100 2\nG............#.....#...........#....#...........##............#............#......................T.", "output": "NO" }, { "input": "100 1\n#.#.#.##..#..##.#....##.##.##.#....####..##.#.##..GT..##...###.#.##.#..#..##.###..#.####..#.#.##..##", "output": "YES" }, { "input": "100 2\n..#####.#.#.......#.#.#...##..####..###..#.#######GT####.#.#...##...##.#..###....##.#.#..#.###....#.", "output": "NO" }, { "input": "100 3\nG..................................................................................................T", "output": "YES" }, { "input": "100 3\nG..................................................................................................T", "output": "YES" }, { "input": "100 3\nG..................................#......#......#.......#.#..........#........#......#..........#.T", "output": "NO" }, { "input": "100 3\nG..............#..........#...#..............#.#.....................#......#........#.........#...T", "output": "NO" }, { "input": "100 3\nG##################################################################################################T", "output": "NO" }, { "input": "100 33\nG..................................................................................................T", "output": "YES" }, { "input": "100 33\nG..................................................................................................T", "output": "YES" }, { "input": "100 33\nG.........#........#..........#..............#.................#............................#.#....T", "output": "YES" }, { "input": "100 33\nG.......#..................#..............................#............................#..........T.", "output": "NO" }, { "input": "100 33\nG#..........##...#.#.....................#.#.#.........##..#...........#....#...........##...#..###T", "output": "YES" }, { "input": "100 33\nG..#.#..#..####......#......##...##...#.##........#...#...#.##....###..#...###..##.#.....#......#.T.", "output": "NO" }, { "input": "100 33\nG#....#..#..##.##..#.##.#......#.#.##..##.#.#.##.##....#.#.....####..##...#....##..##..........#...T", "output": "NO" }, { "input": "100 33\nG#######.#..##.##.#...#..#.###.#.##.##.#..#.###..####.##.#.##....####...##..####.#..##.##.##.#....#T", "output": "NO" }, { "input": "100 33\nG#####.#.##.###########.##..##..#######..########..###.###..#.####.######.############..####..#####T", "output": "NO" }, { "input": "100 99\nT..................................................................................................G", "output": "YES" }, { "input": "100 99\nT..................................................................................................G", "output": "YES" }, { "input": "100 99\nT.#...............................#............#..............................##...................G", "output": "YES" }, { "input": "100 99\nT..#....#.##...##########.#.#.#.#...####..#.....#..##..#######.######..#.....###..###...#.......#.#G", "output": "YES" }, { "input": "100 99\nG##################################################################################################T", "output": "YES" }, { "input": "100 9\nT..................................................................................................G", "output": "YES" }, { "input": "100 9\nT.................................................................................................G.", "output": "NO" }, { "input": "100 9\nT................................................................................................G..", "output": "NO" }, { "input": "100 1\nG..................................................................................................T", "output": "YES" }, { "input": "100 1\nT..................................................................................................G", "output": "YES" }, { "input": "100 1\n##########G.........T###############################################################################", "output": "YES" }, { "input": "100 1\n#################################################################################################G.T", "output": "YES" }, { "input": "100 17\n##########G################.################.################.################T#####################", "output": "YES" }, { "input": "100 17\n####.#..#.G######.#########.##..##########.#.################.################T######.####.#########", "output": "YES" }, { "input": "100 17\n.########.G##.####.#.######.###############..#.###########.##.#####.##.#####.#T.###..###.########.##", "output": "YES" }, { "input": "100 1\nG.............................................#....................................................T", "output": "NO" }, { "input": "100 1\nT.#................................................................................................G", "output": "NO" }, { "input": "100 1\n##########G....#....T###############################################################################", "output": "NO" }, { "input": "100 1\n#################################################################################################G#T", "output": "NO" }, { "input": "100 17\nG################.#################################.################T###############################", "output": "NO" }, { "input": "100 17\nG################.###############..###.######.#######.###.#######.##T######################.###.####", "output": "NO" }, { "input": "100 17\nG####.##.##.#####.####....##.####.#########.##.#..#.###############.T############.#########.#.####.#", "output": "NO" }, { "input": "48 1\nT..............................................G", "output": "YES" }, { "input": "23 1\nT.....................G", "output": "YES" }, { "input": "49 1\nG...............................................T", "output": "YES" }, { "input": "3 1\nTG#", "output": "YES" }, { "input": "6 2\n..TG..", "output": "NO" }, { "input": "14 3\n...G.....#..T.", "output": "NO" }, { "input": "5 4\n##GT#", "output": "NO" }, { "input": "6 2\nT#..G.", "output": "YES" }, { "input": "5 2\nT.G.#", "output": "YES" }, { "input": "6 1\nT...G#", "output": "YES" }, { "input": "5 1\nTG###", "output": "YES" }, { "input": "5 4\n.G..T", "output": "NO" }, { "input": "7 2\nT#...#G", "output": "YES" }, { "input": "7 1\n##TG###", "output": "YES" }, { "input": "7 1\n###GT##", "output": "YES" }, { "input": "5 2\nG..T.", "output": "NO" }, { "input": "5 1\nG.T##", "output": "YES" }, { "input": "6 2\nG.T###", "output": "YES" }, { "input": "6 2\nG#T###", "output": "YES" }, { "input": "10 2\n####T..G..", "output": "NO" }, { "input": "3 1\nGT#", "output": "YES" }, { "input": "4 1\nTG##", "output": "YES" }, { "input": "6 1\n.G..T.", "output": "YES" }, { "input": "10 3\n......G..T", "output": "YES" }, { "input": "3 2\nG.T", "output": "YES" }, { "input": "4 1\n#G.T", "output": "YES" }, { "input": "5 2\nT#G##", "output": "YES" }, { "input": "4 2\nG#.T", "output": "NO" }, { "input": "4 1\nGT##", "output": "YES" } ]
1,684,312,503
2,147,483,647
Python 3
OK
TESTS
83
46
0
n,k = map(int,input().split()) cell = list(map(str,input().strip())) a = cell.index("G") b = cell.index("T") if(a>b): if((a-b)%k != 0): print("NO") else: for i in range(1,(a-b)//k + 1): if(cell[b + k*i] == "#"): print("NO") break elif(cell[b + k*i] == "G"): print("YES") break else: if((b-a)%k != 0): print("NO") else: for i in range(1,(b-a)//k + 1): if(cell[a + k*i] == "#"): print("NO") break elif(cell[a + k*i] == "T"): print("YES") break
Title: Ostap and Grasshopper Time Limit: None seconds Memory Limit: None megabytes Problem Description: On the way to Rio de Janeiro Ostap kills time playing with a grasshopper he took with him in a special box. Ostap builds a line of length *n* such that some cells of this line are empty and some contain obstacles. Then, he places his grasshopper to one of the empty cells and a small insect in another empty cell. The grasshopper wants to eat the insect. Ostap knows that grasshopper is able to jump to any empty cell that is exactly *k* cells away from the current (to the left or to the right). Note that it doesn't matter whether intermediate cells are empty or not as the grasshopper makes a jump over them. For example, if *k*<==<=1 the grasshopper can jump to a neighboring cell only, and if *k*<==<=2 the grasshopper can jump over a single cell. Your goal is to determine whether there is a sequence of jumps such that grasshopper will get from his initial position to the cell with an insect. Input Specification: The first line of the input contains two integers *n* and *k* (2<=≤<=*n*<=≤<=100, 1<=≤<=*k*<=≤<=*n*<=-<=1) — the number of cells in the line and the length of one grasshopper's jump. The second line contains a string of length *n* consisting of characters '.', '#', 'G' and 'T'. Character '.' means that the corresponding cell is empty, character '#' means that the corresponding cell contains an obstacle and grasshopper can't jump there. Character 'G' means that the grasshopper starts at this position and, finally, 'T' means that the target insect is located at this cell. It's guaranteed that characters 'G' and 'T' appear in this line exactly once. Output Specification: If there exists a sequence of jumps (each jump of length *k*), such that the grasshopper can get from his initial position to the cell with the insect, print "YES" (without quotes) in the only line of the input. Otherwise, print "NO" (without quotes). Demo Input: ['5 2\n#G#T#\n', '6 1\nT....G\n', '7 3\nT..#..G\n', '6 2\n..GT..\n'] Demo Output: ['YES\n', 'YES\n', 'NO\n', 'NO\n'] Note: In the first sample, the grasshopper can make one jump to the right in order to get from cell 2 to cell 4. In the second sample, the grasshopper is only able to jump to neighboring cells but the way to the insect is free — he can get there by jumping left 5 times. In the third sample, the grasshopper can't make a single jump. In the fourth sample, the grasshopper can only jump to the cells with odd indices, thus he won't be able to reach the insect.
```python n,k = map(int,input().split()) cell = list(map(str,input().strip())) a = cell.index("G") b = cell.index("T") if(a>b): if((a-b)%k != 0): print("NO") else: for i in range(1,(a-b)//k + 1): if(cell[b + k*i] == "#"): print("NO") break elif(cell[b + k*i] == "G"): print("YES") break else: if((b-a)%k != 0): print("NO") else: for i in range(1,(b-a)//k + 1): if(cell[a + k*i] == "#"): print("NO") break elif(cell[a + k*i] == "T"): print("YES") break ```
3
186
A
Comparing Strings
PROGRAMMING
1,100
[ "implementation", "strings" ]
null
null
Some dwarves that are finishing the StUDY (State University for Dwarven Youngsters) Bachelor courses, have been told "no genome, no degree". That means that all dwarves should write a thesis on genome. Dwarven genome is far from simple. It is represented by a string that consists of lowercase Latin letters. Dwarf Misha has already chosen the subject for his thesis: determining by two dwarven genomes, whether they belong to the same race. Two dwarves belong to the same race if we can swap two characters in the first dwarf's genome and get the second dwarf's genome as a result. Help Dwarf Misha and find out whether two gnomes belong to the same race or not.
The first line contains the first dwarf's genome: a non-empty string, consisting of lowercase Latin letters. The second line contains the second dwarf's genome: a non-empty string, consisting of lowercase Latin letters. The number of letters in each genome doesn't exceed 105. It is guaranteed that the strings that correspond to the genomes are different. The given genomes may have different length.
Print "YES", if the dwarves belong to the same race. Otherwise, print "NO".
[ "ab\nba\n", "aa\nab\n" ]
[ "YES\n", "NO\n" ]
- First example: you can simply swap two letters in string "ab". So we get "ba". - Second example: we can't change string "aa" into string "ab", because "aa" does not contain letter "b".
500
[ { "input": "ab\nba", "output": "YES" }, { "input": "aa\nab", "output": "NO" }, { "input": "a\nza", "output": "NO" }, { "input": "vvea\nvvae", "output": "YES" }, { "input": "rtfabanpc\natfabrnpc", "output": "YES" }, { "input": "mt\ntm", "output": "YES" }, { "input": "qxolmbkkt\naovlajmlf", "output": "NO" }, { "input": "b\ng", "output": "NO" }, { "input": "ab\naba", "output": "NO" }, { "input": "ba\na", "output": "NO" }, { "input": "a\nab", "output": "NO" }, { "input": "a\naa", "output": "NO" }, { "input": "a\nz", "output": "NO" }, { "input": "aabb\nbbaa", "output": "NO" }, { "input": "ab\nbd", "output": "NO" }, { "input": "bac\ndae", "output": "NO" }, { "input": "abc\nakl", "output": "NO" }, { "input": "cb\naa", "output": "NO" }, { "input": "abaab\naabba", "output": "NO" }, { "input": "aab\naaa", "output": "NO" }, { "input": "abcde\nedcba", "output": "NO" }, { "input": "abab\nbaba", "output": "NO" }, { "input": "ab\nbac", "output": "NO" }, { "input": "abcd\naqcb", "output": "NO" }, { "input": "abc\nbad", "output": "NO" }, { "input": "ab\nca", "output": "NO" }, { "input": "abc\nab", "output": "NO" }, { "input": "ab\nbae", "output": "NO" }, { "input": "aaaabcccca\naaaadccccb", "output": "NO" }, { "input": "acaa\nabca", "output": "NO" }, { "input": "aba\naab", "output": "YES" }, { "input": "ah\nla", "output": "NO" }, { "input": "aab\naa", "output": "NO" }, { "input": "abab\nabcd", "output": "NO" }, { "input": "ed\nab", "output": "NO" } ]
1,673,092,859
2,147,483,647
PyPy 3-64
TIME_LIMIT_EXCEEDED
TESTS
11
2,000
1,536,000
a=input() b=input() s="" n=1 if len(a)==len(b): for i in a: if a.count(i)==b.count(i): n=n+1 if n==len(a): print ("YES") else: print ('NO') break else: print ("NO") if s==a: print ("YES")
Title: Comparing Strings Time Limit: None seconds Memory Limit: None megabytes Problem Description: Some dwarves that are finishing the StUDY (State University for Dwarven Youngsters) Bachelor courses, have been told "no genome, no degree". That means that all dwarves should write a thesis on genome. Dwarven genome is far from simple. It is represented by a string that consists of lowercase Latin letters. Dwarf Misha has already chosen the subject for his thesis: determining by two dwarven genomes, whether they belong to the same race. Two dwarves belong to the same race if we can swap two characters in the first dwarf's genome and get the second dwarf's genome as a result. Help Dwarf Misha and find out whether two gnomes belong to the same race or not. Input Specification: The first line contains the first dwarf's genome: a non-empty string, consisting of lowercase Latin letters. The second line contains the second dwarf's genome: a non-empty string, consisting of lowercase Latin letters. The number of letters in each genome doesn't exceed 105. It is guaranteed that the strings that correspond to the genomes are different. The given genomes may have different length. Output Specification: Print "YES", if the dwarves belong to the same race. Otherwise, print "NO". Demo Input: ['ab\nba\n', 'aa\nab\n'] Demo Output: ['YES\n', 'NO\n'] Note: - First example: you can simply swap two letters in string "ab". So we get "ba". - Second example: we can't change string "aa" into string "ab", because "aa" does not contain letter "b".
```python a=input() b=input() s="" n=1 if len(a)==len(b): for i in a: if a.count(i)==b.count(i): n=n+1 if n==len(a): print ("YES") else: print ('NO') break else: print ("NO") if s==a: print ("YES") ```
0
9
A
Die Roll
PROGRAMMING
800
[ "math", "probabilities" ]
A. Die Roll
1
64
Yakko, Wakko and Dot, world-famous animaniacs, decided to rest from acting in cartoons, and take a leave to travel a bit. Yakko dreamt to go to Pennsylvania, his Motherland and the Motherland of his ancestors. Wakko thought about Tasmania, its beaches, sun and sea. Dot chose Transylvania as the most mysterious and unpredictable place. But to their great regret, the leave turned to be very short, so it will be enough to visit one of the three above named places. That's why Yakko, as the cleverest, came up with a truly genius idea: let each of the three roll an ordinary six-sided die, and the one with the highest amount of points will be the winner, and will take the other two to the place of his/her dreams. Yakko thrown a die and got Y points, Wakko — W points. It was Dot's turn. But she didn't hurry. Dot wanted to know for sure what were her chances to visit Transylvania. It is known that Yakko and Wakko are true gentlemen, that's why if they have the same amount of points with Dot, they will let Dot win.
The only line of the input file contains two natural numbers Y and W — the results of Yakko's and Wakko's die rolls.
Output the required probability in the form of irreducible fraction in format «A/B», where A — the numerator, and B — the denominator. If the required probability equals to zero, output «0/1». If the required probability equals to 1, output «1/1».
[ "4 2\n" ]
[ "1/2\n" ]
Dot will go to Transylvania, if she is lucky to roll 4, 5 or 6 points.
0
[ { "input": "4 2", "output": "1/2" }, { "input": "1 1", "output": "1/1" }, { "input": "1 2", "output": "5/6" }, { "input": "1 3", "output": "2/3" }, { "input": "1 4", "output": "1/2" }, { "input": "1 5", "output": "1/3" }, { "input": "1 6", "output": "1/6" }, { "input": "2 1", "output": "5/6" }, { "input": "2 2", "output": "5/6" }, { "input": "2 3", "output": "2/3" }, { "input": "2 4", "output": "1/2" }, { "input": "2 5", "output": "1/3" }, { "input": "2 6", "output": "1/6" }, { "input": "3 1", "output": "2/3" }, { "input": "3 2", "output": "2/3" }, { "input": "3 3", "output": "2/3" }, { "input": "3 4", "output": "1/2" }, { "input": "3 5", "output": "1/3" }, { "input": "3 6", "output": "1/6" }, { "input": "4 1", "output": "1/2" }, { "input": "4 3", "output": "1/2" }, { "input": "4 4", "output": "1/2" }, { "input": "4 5", "output": "1/3" }, { "input": "4 6", "output": "1/6" }, { "input": "5 1", "output": "1/3" }, { "input": "5 2", "output": "1/3" }, { "input": "5 3", "output": "1/3" }, { "input": "5 4", "output": "1/3" }, { "input": "5 5", "output": "1/3" }, { "input": "5 6", "output": "1/6" }, { "input": "6 1", "output": "1/6" }, { "input": "6 2", "output": "1/6" }, { "input": "6 3", "output": "1/6" }, { "input": "6 4", "output": "1/6" }, { "input": "6 5", "output": "1/6" }, { "input": "6 6", "output": "1/6" } ]
1,657,200,658
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
0
62
0
x,y = map(int, input().split()) if x>=y: count=y elif x<=y: count=x if count==1: print('1/1') elif count==2: print('5/6') elif count==3: print('2/3') elif count==4: print('1/2') elif count==5: print('1/3') elif count==6: print('1/6') else: print('None')
Title: Die Roll Time Limit: 1 seconds Memory Limit: 64 megabytes Problem Description: Yakko, Wakko and Dot, world-famous animaniacs, decided to rest from acting in cartoons, and take a leave to travel a bit. Yakko dreamt to go to Pennsylvania, his Motherland and the Motherland of his ancestors. Wakko thought about Tasmania, its beaches, sun and sea. Dot chose Transylvania as the most mysterious and unpredictable place. But to their great regret, the leave turned to be very short, so it will be enough to visit one of the three above named places. That's why Yakko, as the cleverest, came up with a truly genius idea: let each of the three roll an ordinary six-sided die, and the one with the highest amount of points will be the winner, and will take the other two to the place of his/her dreams. Yakko thrown a die and got Y points, Wakko — W points. It was Dot's turn. But she didn't hurry. Dot wanted to know for sure what were her chances to visit Transylvania. It is known that Yakko and Wakko are true gentlemen, that's why if they have the same amount of points with Dot, they will let Dot win. Input Specification: The only line of the input file contains two natural numbers Y and W — the results of Yakko's and Wakko's die rolls. Output Specification: Output the required probability in the form of irreducible fraction in format «A/B», where A — the numerator, and B — the denominator. If the required probability equals to zero, output «0/1». If the required probability equals to 1, output «1/1». Demo Input: ['4 2\n'] Demo Output: ['1/2\n'] Note: Dot will go to Transylvania, if she is lucky to roll 4, 5 or 6 points.
```python x,y = map(int, input().split()) if x>=y: count=y elif x<=y: count=x if count==1: print('1/1') elif count==2: print('5/6') elif count==3: print('2/3') elif count==4: print('1/2') elif count==5: print('1/3') elif count==6: print('1/6') else: print('None') ```
0
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,628,090,020
2,147,483,647
Python 3
OK
TESTS
20
124
6,758,400
n=int(input()) m=list(map(int, input().split())) a=[] for i in range(n): a.append(abs(m[i]-m[i-1])) g=a.index(min(a)) if g==0: print(1,n) else: print(g,g+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()) m=list(map(int, input().split())) a=[] for i in range(n): a.append(abs(m[i]-m[i-1])) g=a.index(min(a)) if g==0: print(1,n) else: print(g,g+1) ```
3.956411
299
A
Ksusha and Array
PROGRAMMING
1,000
[ "brute force", "number theory", "sortings" ]
null
null
Ksusha is a beginner coder. Today she starts studying arrays. She has array *a*1,<=*a*2,<=...,<=*a**n*, consisting of *n* positive integers. Her university teacher gave her a task. Find such number in the array, that all array elements are divisible by it. Help her and find the number!
The first line contains integer *n* (1<=≤<=*n*<=≤<=105), showing how many numbers the array has. The next line contains integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=109) — the array elements.
Print a single integer — the number from the array, such that all array elements are divisible by it. If such number doesn't exist, print -1. If there are multiple answers, you are allowed to print any of them.
[ "3\n2 2 4\n", "5\n2 1 3 1 6\n", "3\n2 3 5\n" ]
[ "2\n", "1\n", "-1\n" ]
none
500
[ { "input": "3\n2 2 4", "output": "2" }, { "input": "5\n2 1 3 1 6", "output": "1" }, { "input": "3\n2 3 5", "output": "-1" }, { "input": "1\n331358794", "output": "331358794" }, { "input": "5\n506904227 214303304 136194869 838256937 183952885", "output": "-1" }, { "input": "2\n500000000 1000000000", "output": "500000000" }, { "input": "2\n4 6", "output": "-1" }, { "input": "5\n10 8 6 4 2", "output": "2" }, { "input": "2\n6 10", "output": "-1" }, { "input": "1\n1000000000", "output": "1000000000" }, { "input": "2\n6 8", "output": "-1" }, { "input": "5\n2 2 2 2 1000000000", "output": "2" }, { "input": "2\n6 4", "output": "-1" } ]
1,543,665,740
2,147,483,647
Python 3
OK
TESTS
32
310
8,089,600
n = int(input()) a = list(map(int,input().split())) rs = min(a) for i in a: if i%rs!=0: print(-1) exit() print(rs)
Title: Ksusha and Array Time Limit: None seconds Memory Limit: None megabytes Problem Description: Ksusha is a beginner coder. Today she starts studying arrays. She has array *a*1,<=*a*2,<=...,<=*a**n*, consisting of *n* positive integers. Her university teacher gave her a task. Find such number in the array, that all array elements are divisible by it. Help her and find the number! Input Specification: The first line contains integer *n* (1<=≤<=*n*<=≤<=105), showing how many numbers the array has. The next line contains integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=109) — the array elements. Output Specification: Print a single integer — the number from the array, such that all array elements are divisible by it. If such number doesn't exist, print -1. If there are multiple answers, you are allowed to print any of them. Demo Input: ['3\n2 2 4\n', '5\n2 1 3 1 6\n', '3\n2 3 5\n'] Demo Output: ['2\n', '1\n', '-1\n'] Note: none
```python n = int(input()) a = list(map(int,input().split())) rs = min(a) for i in a: if i%rs!=0: print(-1) exit() print(rs) ```
3
250
B
Restoring IPv6
PROGRAMMING
1,500
[ "implementation", "strings" ]
null
null
An IPv6-address is a 128-bit number. For convenience, this number is recorded in blocks of 16 bits in hexadecimal record, the blocks are separated by colons — 8 blocks in total, each block has four hexadecimal digits. Here is an example of the correct record of a IPv6 address: "0124:5678:90ab:cdef:0124:5678:90ab:cdef". We'll call such format of recording an IPv6-address full. Besides the full record of an IPv6 address there is a short record format. The record of an IPv6 address can be shortened by removing one or more leading zeroes at the beginning of each block. However, each block should contain at least one digit in the short format. For example, the leading zeroes can be removed like that: "a56f:00d3:0000:0124:0001:f19a:1000:0000" <=→<= "a56f:d3:0:0124:01:f19a:1000:00". There are more ways to shorten zeroes in this IPv6 address. Some IPv6 addresses contain long sequences of zeroes. Continuous sequences of 16-bit zero blocks can be shortened to "::". A sequence can consist of one or several consecutive blocks, with all 16 bits equal to 0. You can see examples of zero block shortenings below: - "a56f:00d3:0000:0124:0001:0000:0000:0000" <=→<= "a56f:00d3:0000:0124:0001::"; - "a56f:0000:0000:0124:0001:0000:1234:0ff0" <=→<= "a56f::0124:0001:0000:1234:0ff0"; - "a56f:0000:0000:0000:0001:0000:1234:0ff0" <=→<= "a56f:0000::0000:0001:0000:1234:0ff0"; - "a56f:00d3:0000:0124:0001:0000:0000:0000" <=→<= "a56f:00d3:0000:0124:0001::0000"; - "0000:0000:0000:0000:0000:0000:0000:0000" <=→<= "::". It is not allowed to shorten zero blocks in the address more than once. This means that the short record can't contain the sequence of characters "::" more than once. Otherwise, it will sometimes be impossible to determine the number of zero blocks, each represented by a double colon. The format of the record of the IPv6 address after removing the leading zeroes and shortening the zero blocks is called short. You've got several short records of IPv6 addresses. Restore their full record.
The first line contains a single integer *n* — the number of records to restore (1<=≤<=*n*<=≤<=100). Each of the following *n* lines contains a string — the short IPv6 addresses. Each string only consists of string characters "0123456789abcdef:". It is guaranteed that each short address is obtained by the way that is described in the statement from some full IPv6 address.
For each short IPv6 address from the input print its full record on a separate line. Print the full records for the short IPv6 addresses in the order, in which the short records follow in the input.
[ "6\na56f:d3:0:0124:01:f19a:1000:00\na56f:00d3:0000:0124:0001::\na56f::0124:0001:0000:1234:0ff0\na56f:0000::0000:0001:0000:1234:0ff0\n::\n0ea::4d:f4:6:0\n" ]
[ "a56f:00d3:0000:0124:0001:f19a:1000:0000\na56f:00d3:0000:0124:0001:0000:0000:0000\na56f:0000:0000:0124:0001:0000:1234:0ff0\na56f:0000:0000:0000:0001:0000:1234:0ff0\n0000:0000:0000:0000:0000:0000:0000:0000\n00ea:0000:0000:0000:004d:00f4:0006:0000\n" ]
none
1,000
[ { "input": "6\na56f:d3:0:0124:01:f19a:1000:00\na56f:00d3:0000:0124:0001::\na56f::0124:0001:0000:1234:0ff0\na56f:0000::0000:0001:0000:1234:0ff0\n::\n0ea::4d:f4:6:0", "output": "a56f:00d3:0000:0124:0001:f19a:1000:0000\na56f:00d3:0000:0124:0001:0000:0000:0000\na56f:0000:0000:0124:0001:0000:1234:0ff0\na56f:0000:0000:0000:0001:0000:1234:0ff0\n0000:0000:0000:0000:0000:0000:0000:0000\n00ea:0000:0000:0000:004d:00f4:0006:0000" }, { "input": "20\n0:0:9e39:9:b21:c9b:c:0\n0:0:0:0:0:a27:6b:cb0a\n2:7:4d:b:0:3:2:f401\n17:2dc6::0:89e3:0:dc:0\nca:4:0:0:d6:b999:e:0\n4af:553:b29:dd7:2:5b:0:7\n0:c981:8f:a4d:0:d4:0:f61\n0:0:1:0:dc33:0:1964:0\n84:da:0:6d6:0ecc:1:f:0\n4:fb:4d37:0:8c:4:4a52:24\nc:e:a:0:0:0:e:0\n0:3761:72ed:b7:3b0:ff7:fc:102\n5ae:8ca7:10::0:9b2:0:525a\n0::ab:8d64:86:767:2\ne6b:3cb:0:81ce:0ac4:11::1\n4:0:5238:7b:591d:ff15:0:e\n0:f9a5:0::118e:dde:0\n0:d4c:feb:b:10a:0:d:e\n0:0:0:ff38:b5d:a3c2:f3:0\n2:a:6:c50:83:4f:7f0d::", "output": "0000:0000:9e39:0009:0b21:0c9b:000c:0000\n0000:0000:0000:0000:0000:0a27:006b:cb0a\n0002:0007:004d:000b:0000:0003:0002:f401\n0017:2dc6:0000:0000:89e3:0000:00dc:0000\n00ca:0004:0000:0000:00d6:b999:000e:0000\n04af:0553:0b29:0dd7:0002:005b:0000:0007\n0000:c981:008f:0a4d:0000:00d4:0000:0f61\n0000:0000:0001:0000:dc33:0000:1964:0000\n0084:00da:0000:06d6:0ecc:0001:000f:0000\n0004:00fb:4d37:0000:008c:0004:4a52:0024\n000c:000e:000a:0000:0000:0000:000e:0000\n0000:3761:72ed:00b7:03b0:0ff7:00fc:0102\n05ae:8ca7:0010:0000..." }, { "input": "10\n1::7\n0:0::1\n::1ed\n::30:44\n::eaf:ff:000b\n56fe::\ndf0:3df::\nd03:ab:0::\n85::0485:0\n::", "output": "0001:0000:0000:0000:0000:0000:0000:0007\n0000:0000:0000:0000:0000:0000:0000:0001\n0000:0000:0000:0000:0000:0000:0000:01ed\n0000:0000:0000:0000:0000:0000:0030:0044\n0000:0000:0000:0000:0000:0eaf:00ff:000b\n56fe:0000:0000:0000:0000:0000:0000:0000\n0df0:03df:0000:0000:0000:0000:0000:0000\n0d03:00ab:0000:0000:0000:0000:0000:0000\n0085:0000:0000:0000:0000:0000:0485:0000\n0000:0000:0000:0000:0000:0000:0000:0000" }, { "input": "6\n0:00:000:0000::\n1:01:001:0001::\nf:0f:00f:000f::\n1:10:100:1000::\nf:f0:f00:f000::\nf:ff:fff:ffff::", "output": "0000:0000:0000:0000:0000:0000:0000:0000\n0001:0001:0001:0001:0000:0000:0000:0000\n000f:000f:000f:000f:0000:0000:0000:0000\n0001:0010:0100:1000:0000:0000:0000:0000\n000f:00f0:0f00:f000:0000:0000:0000:0000\n000f:00ff:0fff:ffff:0000:0000:0000:0000" }, { "input": "3\n::\n::\n::", "output": "0000:0000:0000:0000:0000:0000:0000:0000\n0000:0000:0000:0000:0000:0000:0000:0000\n0000:0000:0000:0000:0000:0000:0000:0000" }, { "input": "4\n1:2:3:4:5:6:7:8\n0:0:0:0:0:0:0:0\nf:0f:00f:000f:ff:0ff:00ff:fff\n0fff:0ff0:0f0f:f0f:0f0:f0f0:f00f:ff0f", "output": "0001:0002:0003:0004:0005:0006:0007:0008\n0000:0000:0000:0000:0000:0000:0000:0000\n000f:000f:000f:000f:00ff:00ff:00ff:0fff\n0fff:0ff0:0f0f:0f0f:00f0:f0f0:f00f:ff0f" } ]
1,652,225,358
2,147,483,647
Python 3
OK
TESTS
40
92
0
n = int(input()) res = "" for i in range(n): short = input() blocks = short.split(':') if '' in blocks: countOfNull = 9 - len(blocks) # short[short.index('::')+1] short = short.replace("::", ":0000"*countOfNull + ":") blocks = short.split(':') short = "" for block in blocks: if len(block) < 4: block = "0"*(4-len(block))+block short += block + ":" short = short[:-1] res += short + "\n" res = res[:-1] print(res)
Title: Restoring IPv6 Time Limit: None seconds Memory Limit: None megabytes Problem Description: An IPv6-address is a 128-bit number. For convenience, this number is recorded in blocks of 16 bits in hexadecimal record, the blocks are separated by colons — 8 blocks in total, each block has four hexadecimal digits. Here is an example of the correct record of a IPv6 address: "0124:5678:90ab:cdef:0124:5678:90ab:cdef". We'll call such format of recording an IPv6-address full. Besides the full record of an IPv6 address there is a short record format. The record of an IPv6 address can be shortened by removing one or more leading zeroes at the beginning of each block. However, each block should contain at least one digit in the short format. For example, the leading zeroes can be removed like that: "a56f:00d3:0000:0124:0001:f19a:1000:0000" <=→<= "a56f:d3:0:0124:01:f19a:1000:00". There are more ways to shorten zeroes in this IPv6 address. Some IPv6 addresses contain long sequences of zeroes. Continuous sequences of 16-bit zero blocks can be shortened to "::". A sequence can consist of one or several consecutive blocks, with all 16 bits equal to 0. You can see examples of zero block shortenings below: - "a56f:00d3:0000:0124:0001:0000:0000:0000" <=→<= "a56f:00d3:0000:0124:0001::"; - "a56f:0000:0000:0124:0001:0000:1234:0ff0" <=→<= "a56f::0124:0001:0000:1234:0ff0"; - "a56f:0000:0000:0000:0001:0000:1234:0ff0" <=→<= "a56f:0000::0000:0001:0000:1234:0ff0"; - "a56f:00d3:0000:0124:0001:0000:0000:0000" <=→<= "a56f:00d3:0000:0124:0001::0000"; - "0000:0000:0000:0000:0000:0000:0000:0000" <=→<= "::". It is not allowed to shorten zero blocks in the address more than once. This means that the short record can't contain the sequence of characters "::" more than once. Otherwise, it will sometimes be impossible to determine the number of zero blocks, each represented by a double colon. The format of the record of the IPv6 address after removing the leading zeroes and shortening the zero blocks is called short. You've got several short records of IPv6 addresses. Restore their full record. Input Specification: The first line contains a single integer *n* — the number of records to restore (1<=≤<=*n*<=≤<=100). Each of the following *n* lines contains a string — the short IPv6 addresses. Each string only consists of string characters "0123456789abcdef:". It is guaranteed that each short address is obtained by the way that is described in the statement from some full IPv6 address. Output Specification: For each short IPv6 address from the input print its full record on a separate line. Print the full records for the short IPv6 addresses in the order, in which the short records follow in the input. Demo Input: ['6\na56f:d3:0:0124:01:f19a:1000:00\na56f:00d3:0000:0124:0001::\na56f::0124:0001:0000:1234:0ff0\na56f:0000::0000:0001:0000:1234:0ff0\n::\n0ea::4d:f4:6:0\n'] Demo Output: ['a56f:00d3:0000:0124:0001:f19a:1000:0000\na56f:00d3:0000:0124:0001:0000:0000:0000\na56f:0000:0000:0124:0001:0000:1234:0ff0\na56f:0000:0000:0000:0001:0000:1234:0ff0\n0000:0000:0000:0000:0000:0000:0000:0000\n00ea:0000:0000:0000:004d:00f4:0006:0000\n'] Note: none
```python n = int(input()) res = "" for i in range(n): short = input() blocks = short.split(':') if '' in blocks: countOfNull = 9 - len(blocks) # short[short.index('::')+1] short = short.replace("::", ":0000"*countOfNull + ":") blocks = short.split(':') short = "" for block in blocks: if len(block) < 4: block = "0"*(4-len(block))+block short += block + ":" short = short[:-1] res += short + "\n" res = res[:-1] print(res) ```
3
268
A
Games
PROGRAMMING
800
[ "brute force" ]
null
null
Manao works on a sports TV. He's spent much time watching the football games of some country. After a while he began to notice different patterns. For example, each team has two sets of uniforms: home uniform and guest uniform. When a team plays a game at home, the players put on the home uniform. When a team plays as a guest on somebody else's stadium, the players put on the guest uniform. The only exception to that rule is: when the home uniform color of the host team matches the guests' uniform, the host team puts on its guest uniform as well. For each team the color of the home and guest uniform is different. There are *n* teams taking part in the national championship. The championship consists of *n*·(*n*<=-<=1) games: each team invites each other team to its stadium. At this point Manao wondered: how many times during the championship is a host team going to put on the guest uniform? Note that the order of the games does not affect this number. You know the colors of the home and guest uniform for each team. For simplicity, the colors are numbered by integers in such a way that no two distinct colors have the same number. Help Manao find the answer to his question.
The first line contains an integer *n* (2<=≤<=*n*<=≤<=30). Each of the following *n* lines contains a pair of distinct space-separated integers *h**i*, *a**i* (1<=≤<=*h**i*,<=*a**i*<=≤<=100) — the colors of the *i*-th team's home and guest uniforms, respectively.
In a single line print the number of games where the host team is going to play in the guest uniform.
[ "3\n1 2\n2 4\n3 4\n", "4\n100 42\n42 100\n5 42\n100 5\n", "2\n1 2\n1 2\n" ]
[ "1\n", "5\n", "0\n" ]
In the first test case the championship consists of 6 games. The only game with the event in question is the game between teams 2 and 1 on the stadium of team 2. In the second test sample the host team will have to wear guest uniform in the games between teams: 1 and 2, 2 and 1, 2 and 3, 3 and 4, 4 and 2 (the host team is written first).
500
[ { "input": "3\n1 2\n2 4\n3 4", "output": "1" }, { "input": "4\n100 42\n42 100\n5 42\n100 5", "output": "5" }, { "input": "2\n1 2\n1 2", "output": "0" }, { "input": "7\n4 7\n52 55\n16 4\n55 4\n20 99\n3 4\n7 52", "output": "6" }, { "input": "10\n68 42\n1 35\n25 70\n59 79\n65 63\n46 6\n28 82\n92 62\n43 96\n37 28", "output": "1" }, { "input": "30\n10 39\n89 1\n78 58\n75 99\n36 13\n77 50\n6 97\n79 28\n27 52\n56 5\n93 96\n40 21\n33 74\n26 37\n53 59\n98 56\n61 65\n42 57\n9 7\n25 63\n74 34\n96 84\n95 47\n12 23\n34 21\n71 6\n27 13\n15 47\n64 14\n12 77", "output": "6" }, { "input": "30\n46 100\n87 53\n34 84\n44 66\n23 20\n50 34\n90 66\n17 39\n13 22\n94 33\n92 46\n63 78\n26 48\n44 61\n3 19\n41 84\n62 31\n65 89\n23 28\n58 57\n19 85\n26 60\n75 66\n69 67\n76 15\n64 15\n36 72\n90 89\n42 69\n45 35", "output": "4" }, { "input": "2\n46 6\n6 46", "output": "2" }, { "input": "29\n8 18\n33 75\n69 22\n97 95\n1 97\n78 10\n88 18\n13 3\n19 64\n98 12\n79 92\n41 72\n69 15\n98 31\n57 74\n15 56\n36 37\n15 66\n63 100\n16 42\n47 56\n6 4\n73 15\n30 24\n27 71\n12 19\n88 69\n85 6\n50 11", "output": "10" }, { "input": "23\n43 78\n31 28\n58 80\n66 63\n20 4\n51 95\n40 20\n50 14\n5 34\n36 39\n77 42\n64 97\n62 89\n16 56\n8 34\n58 16\n37 35\n37 66\n8 54\n50 36\n24 8\n68 48\n85 33", "output": "6" }, { "input": "13\n76 58\n32 85\n99 79\n23 58\n96 59\n72 35\n53 43\n96 55\n41 78\n75 10\n28 11\n72 7\n52 73", "output": "0" }, { "input": "18\n6 90\n70 79\n26 52\n67 81\n29 95\n41 32\n94 88\n18 58\n59 65\n51 56\n64 68\n34 2\n6 98\n95 82\n34 2\n40 98\n83 78\n29 2", "output": "1" }, { "input": "18\n6 90\n100 79\n26 100\n67 100\n29 100\n100 32\n94 88\n18 58\n59 65\n51 56\n64 68\n34 2\n6 98\n95 82\n34 2\n40 98\n83 78\n29 100", "output": "8" }, { "input": "30\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1", "output": "450" }, { "input": "30\n100 99\n58 59\n56 57\n54 55\n52 53\n50 51\n48 49\n46 47\n44 45\n42 43\n40 41\n38 39\n36 37\n34 35\n32 33\n30 31\n28 29\n26 27\n24 25\n22 23\n20 21\n18 19\n16 17\n14 15\n12 13\n10 11\n8 9\n6 7\n4 5\n2 3", "output": "0" }, { "input": "15\n9 3\n2 6\n7 6\n5 10\n9 5\n8 1\n10 5\n2 8\n4 5\n9 8\n5 3\n3 8\n9 8\n4 10\n8 5", "output": "20" }, { "input": "15\n2 1\n1 2\n1 2\n1 2\n2 1\n2 1\n2 1\n1 2\n2 1\n2 1\n2 1\n1 2\n2 1\n2 1\n1 2", "output": "108" }, { "input": "25\n2 1\n1 2\n1 2\n1 2\n2 1\n1 2\n1 2\n1 2\n2 1\n2 1\n2 1\n1 2\n1 2\n1 2\n2 1\n2 1\n2 1\n1 2\n2 1\n1 2\n2 1\n2 1\n2 1\n2 1\n1 2", "output": "312" }, { "input": "25\n91 57\n2 73\n54 57\n2 57\n23 57\n2 6\n57 54\n57 23\n91 54\n91 23\n57 23\n91 57\n54 2\n6 91\n57 54\n2 57\n57 91\n73 91\n57 23\n91 57\n2 73\n91 2\n23 6\n2 73\n23 6", "output": "96" }, { "input": "28\n31 66\n31 91\n91 31\n97 66\n31 66\n31 66\n66 91\n91 31\n97 31\n91 97\n97 31\n66 31\n66 97\n91 31\n31 66\n31 66\n66 31\n31 97\n66 97\n97 31\n31 91\n66 91\n91 66\n31 66\n91 66\n66 31\n66 31\n91 97", "output": "210" }, { "input": "29\n78 27\n50 68\n24 26\n68 43\n38 78\n26 38\n78 28\n28 26\n27 24\n23 38\n24 26\n24 43\n61 50\n38 78\n27 23\n61 26\n27 28\n43 23\n28 78\n43 27\n43 78\n27 61\n28 38\n61 78\n50 26\n43 27\n26 78\n28 50\n43 78", "output": "73" }, { "input": "29\n80 27\n69 80\n27 80\n69 80\n80 27\n80 27\n80 27\n80 69\n27 69\n80 69\n80 27\n27 69\n69 27\n80 69\n27 69\n69 80\n27 69\n80 69\n80 27\n69 27\n27 69\n27 80\n80 27\n69 80\n27 69\n80 69\n69 80\n69 80\n27 80", "output": "277" }, { "input": "30\n19 71\n7 89\n89 71\n21 7\n19 21\n7 89\n19 71\n89 8\n89 21\n19 8\n21 7\n8 89\n19 89\n7 21\n19 8\n19 7\n7 19\n8 21\n71 21\n71 89\n7 19\n7 19\n21 7\n21 19\n21 19\n71 8\n21 8\n71 19\n19 71\n8 21", "output": "154" }, { "input": "30\n44 17\n44 17\n44 17\n17 44\n44 17\n44 17\n17 44\n17 44\n17 44\n44 17\n44 17\n44 17\n44 17\n44 17\n17 44\n17 44\n17 44\n44 17\n44 17\n17 44\n44 17\n44 17\n44 17\n17 44\n17 44\n44 17\n17 44\n44 17\n44 17\n44 17", "output": "418" }, { "input": "22\n78 92\n15 92\n92 78\n78 80\n92 16\n24 80\n92 16\n16 92\n78 16\n24 78\n80 78\n92 80\n16 80\n80 78\n15 78\n92 16\n24 15\n24 80\n80 16\n16 80\n92 80\n24 80", "output": "74" }, { "input": "24\n9 83\n90 31\n83 3\n83 3\n21 31\n83 3\n32 31\n12 21\n31 21\n90 32\n32 21\n12 9\n12 31\n9 83\n83 12\n32 3\n32 83\n90 31\n9 32\n31 21\n83 90\n32 21\n21 3\n32 9", "output": "59" }, { "input": "30\n67 21\n85 39\n85 87\n21 39\n66 85\n10 95\n10 21\n87 85\n82 21\n67 21\n95 10\n21 39\n82 21\n21 66\n66 39\n95 30\n67 85\n66 82\n85 82\n21 66\n10 39\n67 10\n21 85\n10 82\n85 95\n10 85\n21 39\n85 39\n39 10\n95 67", "output": "100" }, { "input": "4\n8 7\n8 7\n7 8\n7 8", "output": "8" }, { "input": "6\n1 2\n1 2\n1 2\n1 2\n1 2\n2 1", "output": "10" }, { "input": "12\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1", "output": "72" }, { "input": "4\n1 2\n1 2\n2 1\n2 1", "output": "8" } ]
1,675,154,773
2,147,483,647
Python 3
OK
TESTS
31
92
0
n = int(input().strip()) cnt = 0 colours = [] for i in range(n): h,a = map(str, input().strip().split()) colours.append((h,a)) for i in range(n): for j in range(n): if i != j: if colours[i][0] == colours[j][1]: cnt += 1 print(cnt)
Title: Games Time Limit: None seconds Memory Limit: None megabytes Problem Description: Manao works on a sports TV. He's spent much time watching the football games of some country. After a while he began to notice different patterns. For example, each team has two sets of uniforms: home uniform and guest uniform. When a team plays a game at home, the players put on the home uniform. When a team plays as a guest on somebody else's stadium, the players put on the guest uniform. The only exception to that rule is: when the home uniform color of the host team matches the guests' uniform, the host team puts on its guest uniform as well. For each team the color of the home and guest uniform is different. There are *n* teams taking part in the national championship. The championship consists of *n*·(*n*<=-<=1) games: each team invites each other team to its stadium. At this point Manao wondered: how many times during the championship is a host team going to put on the guest uniform? Note that the order of the games does not affect this number. You know the colors of the home and guest uniform for each team. For simplicity, the colors are numbered by integers in such a way that no two distinct colors have the same number. Help Manao find the answer to his question. Input Specification: The first line contains an integer *n* (2<=≤<=*n*<=≤<=30). Each of the following *n* lines contains a pair of distinct space-separated integers *h**i*, *a**i* (1<=≤<=*h**i*,<=*a**i*<=≤<=100) — the colors of the *i*-th team's home and guest uniforms, respectively. Output Specification: In a single line print the number of games where the host team is going to play in the guest uniform. Demo Input: ['3\n1 2\n2 4\n3 4\n', '4\n100 42\n42 100\n5 42\n100 5\n', '2\n1 2\n1 2\n'] Demo Output: ['1\n', '5\n', '0\n'] Note: In the first test case the championship consists of 6 games. The only game with the event in question is the game between teams 2 and 1 on the stadium of team 2. In the second test sample the host team will have to wear guest uniform in the games between teams: 1 and 2, 2 and 1, 2 and 3, 3 and 4, 4 and 2 (the host team is written first).
```python n = int(input().strip()) cnt = 0 colours = [] for i in range(n): h,a = map(str, input().strip().split()) colours.append((h,a)) for i in range(n): for j in range(n): if i != j: if colours[i][0] == colours[j][1]: cnt += 1 print(cnt) ```
3
421
A
Pasha and Hamsters
PROGRAMMING
800
[ "constructive algorithms", "implementation" ]
null
null
Pasha has two hamsters: Arthur and Alexander. Pasha put *n* apples in front of them. Pasha knows which apples Arthur likes. Similarly, Pasha knows which apples Alexander likes. Pasha doesn't want any conflict between the hamsters (as they may like the same apple), so he decided to distribute the apples between the hamsters on his own. He is going to give some apples to Arthur and some apples to Alexander. It doesn't matter how many apples each hamster gets but it is important that each hamster gets only the apples he likes. It is possible that somebody doesn't get any apples. Help Pasha distribute all the apples between the hamsters. Note that Pasha wants to distribute all the apples, not just some of them.
The first line contains integers *n*, *a*, *b* (1<=≤<=*n*<=≤<=100; 1<=≤<=*a*,<=*b*<=≤<=*n*) — the number of apples Pasha has, the number of apples Arthur likes and the number of apples Alexander likes, correspondingly. The next line contains *a* distinct integers — the numbers of the apples Arthur likes. The next line contains *b* distinct integers — the numbers of the apples Alexander likes. Assume that the apples are numbered from 1 to *n*. The input is such that the answer exists.
Print *n* characters, each of them equals either 1 or 2. If the *i*-h character equals 1, then the *i*-th apple should be given to Arthur, otherwise it should be given to Alexander. If there are multiple correct answers, you are allowed to print any of them.
[ "4 2 3\n1 2\n2 3 4\n", "5 5 2\n3 4 1 2 5\n2 3\n" ]
[ "1 1 2 2\n", "1 1 1 1 1\n" ]
none
500
[ { "input": "4 2 3\n1 2\n2 3 4", "output": "1 1 2 2" }, { "input": "5 5 2\n3 4 1 2 5\n2 3", "output": "1 1 1 1 1" }, { "input": "100 69 31\n1 3 4 5 6 7 8 9 10 11 12 14 15 16 17 18 19 20 21 24 26 27 29 31 37 38 39 40 44 46 48 49 50 51 53 55 56 57 58 59 60 61 63 64 65 66 67 68 69 70 71 72 74 76 77 78 79 80 81 82 83 89 92 94 95 97 98 99 100\n2 13 22 23 25 28 30 32 33 34 35 36 41 42 43 45 47 52 54 62 73 75 84 85 86 87 88 90 91 93 96", "output": "1 2 1 1 1 1 1 1 1 1 1 1 2 1 1 1 1 1 1 1 1 2 2 1 2 1 1 2 1 2 1 2 2 2 2 2 1 1 1 1 2 2 2 1 2 1 2 1 1 1 1 2 1 2 1 1 1 1 1 1 1 2 1 1 1 1 1 1 1 1 1 1 2 1 2 1 1 1 1 1 1 1 1 2 2 2 2 2 1 2 2 1 2 1 1 2 1 1 1 1" }, { "input": "100 56 44\n1 2 5 8 14 15 17 18 20 21 23 24 25 27 30 33 34 35 36 38 41 42 44 45 46 47 48 49 50 53 56 58 59 60 62 63 64 65 68 69 71 75 76 80 81 84 87 88 90 91 92 94 95 96 98 100\n3 4 6 7 9 10 11 12 13 16 19 22 26 28 29 31 32 37 39 40 43 51 52 54 55 57 61 66 67 70 72 73 74 77 78 79 82 83 85 86 89 93 97 99", "output": "1 1 2 2 1 2 2 1 2 2 2 2 2 1 1 2 1 1 2 1 1 2 1 1 1 2 1 2 2 1 2 2 1 1 1 1 2 1 2 2 1 1 2 1 1 1 1 1 1 1 2 2 1 2 2 1 2 1 1 1 2 1 1 1 1 2 2 1 1 2 1 2 2 2 1 1 2 2 2 1 1 2 2 1 2 2 1 1 2 1 1 1 2 1 1 1 2 1 2 1" }, { "input": "100 82 18\n1 2 3 4 5 6 7 8 9 10 11 13 14 15 16 17 18 19 20 22 23 25 27 29 30 31 32 33 34 35 36 37 38 42 43 44 45 46 47 48 49 50 51 53 54 55 57 58 59 60 61 62 63 64 65 66 67 68 69 71 72 73 74 75 77 78 79 80 82 83 86 88 90 91 92 93 94 96 97 98 99 100\n12 21 24 26 28 39 40 41 52 56 70 76 81 84 85 87 89 95", "output": "1 1 1 1 1 1 1 1 1 1 1 2 1 1 1 1 1 1 1 1 2 1 1 2 1 2 1 2 1 1 1 1 1 1 1 1 1 1 2 2 2 1 1 1 1 1 1 1 1 1 1 2 1 1 1 2 1 1 1 1 1 1 1 1 1 1 1 1 1 2 1 1 1 1 1 2 1 1 1 1 2 1 1 2 2 1 2 1 2 1 1 1 1 1 2 1 1 1 1 1" }, { "input": "99 72 27\n1 2 3 4 5 6 7 8 10 11 12 13 14 15 16 17 20 23 25 26 28 29 30 32 33 34 35 36 39 41 42 43 44 45 46 47 50 51 52 54 55 56 58 59 60 61 62 67 70 71 72 74 75 76 77 80 81 82 84 85 86 88 90 91 92 93 94 95 96 97 98 99\n9 18 19 21 22 24 27 31 37 38 40 48 49 53 57 63 64 65 66 68 69 73 78 79 83 87 89", "output": "1 1 1 1 1 1 1 1 2 1 1 1 1 1 1 1 1 2 2 1 2 2 1 2 1 1 2 1 1 1 2 1 1 1 1 1 2 2 1 2 1 1 1 1 1 1 1 2 2 1 1 1 2 1 1 1 2 1 1 1 1 1 2 2 2 2 1 2 2 1 1 1 2 1 1 1 1 2 2 1 1 1 2 1 1 1 2 1 2 1 1 1 1 1 1 1 1 1 1" }, { "input": "99 38 61\n1 3 10 15 16 22 23 28 31 34 35 36 37 38 39 43 44 49 50 53 56 60 63 68 69 70 72 74 75 77 80 81 83 85 96 97 98 99\n2 4 5 6 7 8 9 11 12 13 14 17 18 19 20 21 24 25 26 27 29 30 32 33 40 41 42 45 46 47 48 51 52 54 55 57 58 59 61 62 64 65 66 67 71 73 76 78 79 82 84 86 87 88 89 90 91 92 93 94 95", "output": "1 2 1 2 2 2 2 2 2 1 2 2 2 2 1 1 2 2 2 2 2 1 1 2 2 2 2 1 2 2 1 2 2 1 1 1 1 1 1 2 2 2 1 1 2 2 2 2 1 1 2 2 1 2 2 1 2 2 2 1 2 2 1 2 2 2 2 1 1 1 2 1 2 1 1 2 1 2 2 1 1 2 1 2 1 2 2 2 2 2 2 2 2 2 2 1 1 1 1" }, { "input": "99 84 15\n1 2 3 5 6 7 8 9 10 11 12 13 14 15 16 17 19 20 21 22 23 24 25 26 27 28 29 30 31 32 34 35 36 37 38 39 40 41 42 43 44 47 48 50 51 52 53 55 56 58 59 60 61 62 63 64 65 68 69 70 71 72 73 74 75 77 79 80 81 82 83 84 85 86 87 89 90 91 92 93 94 97 98 99\n4 18 33 45 46 49 54 57 66 67 76 78 88 95 96", "output": "1 1 1 2 1 1 1 1 1 1 1 1 1 1 1 1 1 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 1 1 1 1 1 1 1 1 1 1 1 2 2 1 1 2 1 1 1 1 2 1 1 2 1 1 1 1 1 1 1 1 2 2 1 1 1 1 1 1 1 1 2 1 2 1 1 1 1 1 1 1 1 1 2 1 1 1 1 1 1 2 2 1 1 1" }, { "input": "4 3 1\n1 3 4\n2", "output": "1 2 1 1" }, { "input": "4 3 1\n1 2 4\n3", "output": "1 1 2 1" }, { "input": "4 2 2\n2 3\n1 4", "output": "2 1 1 2" }, { "input": "4 3 1\n2 3 4\n1", "output": "2 1 1 1" }, { "input": "1 1 1\n1\n1", "output": "1" }, { "input": "2 1 1\n2\n1", "output": "2 1" }, { "input": "2 1 1\n1\n2", "output": "1 2" }, { "input": "3 3 1\n1 2 3\n1", "output": "1 1 1" }, { "input": "3 3 1\n1 2 3\n3", "output": "1 1 1" }, { "input": "3 2 1\n1 3\n2", "output": "1 2 1" }, { "input": "100 1 100\n84\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": "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 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 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2" }, { "input": "100 100 1\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 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\n17", "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": "98 51 47\n1 2 3 4 6 7 8 10 13 15 16 18 19 21 22 23 25 26 27 29 31 32 36 37 39 40 41 43 44 48 49 50 51 52 54 56 58 59 65 66 68 79 80 84 86 88 89 90 94 95 97\n5 9 11 12 14 17 20 24 28 30 33 34 35 38 42 45 46 47 53 55 57 60 61 62 63 64 67 69 70 71 72 73 74 75 76 77 78 81 82 83 85 87 91 92 93 96 98", "output": "1 1 1 1 2 1 1 1 2 1 2 2 1 2 1 1 2 1 1 2 1 1 1 2 1 1 1 2 1 2 1 1 2 2 2 1 1 2 1 1 1 2 1 1 2 2 2 1 1 1 1 1 2 1 2 1 2 1 1 2 2 2 2 2 1 1 2 1 2 2 2 2 2 2 2 2 2 2 1 1 2 2 2 1 2 1 2 1 1 1 2 2 2 1 1 2 1 2" }, { "input": "98 28 70\n1 13 15 16 19 27 28 40 42 43 46 53 54 57 61 63 67 68 69 71 75 76 78 80 88 93 97 98\n2 3 4 5 6 7 8 9 10 11 12 14 17 18 20 21 22 23 24 25 26 29 30 31 32 33 34 35 36 37 38 39 41 44 45 47 48 49 50 51 52 55 56 58 59 60 62 64 65 66 70 72 73 74 77 79 81 82 83 84 85 86 87 89 90 91 92 94 95 96", "output": "1 2 2 2 2 2 2 2 2 2 2 2 1 2 1 1 2 2 1 2 2 2 2 2 2 2 1 1 2 2 2 2 2 2 2 2 2 2 2 1 2 1 1 2 2 1 2 2 2 2 2 2 1 1 2 2 1 2 2 2 1 2 1 2 2 2 1 1 1 2 1 2 2 2 1 1 2 1 2 1 2 2 2 2 2 2 2 1 2 2 2 2 1 2 2 2 1 1" }, { "input": "97 21 76\n7 10 16 17 26 30 34 39 40 42 44 46 53 54 56 64 67 72 78 79 94\n1 2 3 4 5 6 8 9 11 12 13 14 15 18 19 20 21 22 23 24 25 27 28 29 31 32 33 35 36 37 38 41 43 45 47 48 49 50 51 52 55 57 58 59 60 61 62 63 65 66 68 69 70 71 73 74 75 76 77 80 81 82 83 84 85 86 87 88 89 90 91 92 93 95 96 97", "output": "2 2 2 2 2 2 1 2 2 1 2 2 2 2 2 1 1 2 2 2 2 2 2 2 2 1 2 2 2 1 2 2 2 1 2 2 2 2 1 1 2 1 2 1 2 1 2 2 2 2 2 2 1 1 2 1 2 2 2 2 2 2 2 1 2 2 1 2 2 2 2 1 2 2 2 2 2 1 1 2 2 2 2 2 2 2 2 2 2 2 2 2 2 1 2 2 2" }, { "input": "97 21 76\n1 10 12 13 17 18 22 25 31 48 50 54 61 64 67 74 78 81 86 88 94\n2 3 4 5 6 7 8 9 11 14 15 16 19 20 21 23 24 26 27 28 29 30 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 49 51 52 53 55 56 57 58 59 60 62 63 65 66 68 69 70 71 72 73 75 76 77 79 80 82 83 84 85 87 89 90 91 92 93 95 96 97", "output": "1 2 2 2 2 2 2 2 2 1 2 1 1 2 2 2 1 1 2 2 2 1 2 2 1 2 2 2 2 2 1 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 1 2 1 2 2 2 1 2 2 2 2 2 2 1 2 2 1 2 2 1 2 2 2 2 2 2 1 2 2 2 1 2 2 1 2 2 2 2 1 2 1 2 2 2 2 2 1 2 2 2" }, { "input": "96 10 86\n2 5 31 37 68 69 80 82 90 91\n1 3 4 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 32 33 34 35 36 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 70 71 72 73 74 75 76 77 78 79 81 83 84 85 86 87 88 89 92 93 94 95 96", "output": "2 1 2 2 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 1 2 2 2 2 2 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 1 1 2 2 2 2 2 2 2 2 2 2 1 2 1 2 2 2 2 2 2 2 1 1 2 2 2 2 2" }, { "input": "95 4 91\n58 65 70 93\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 59 60 61 62 63 64 66 67 68 69 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 94 95", "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 2 2 2 2 2 2 2 2 2 2 1 2 2 2 2 2 2 1 2 2 2 2 1 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 1 2 2" }, { "input": "98 88 10\n1 2 4 5 6 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 33 34 35 36 38 39 40 41 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 62 63 64 65 66 67 68 69 71 72 73 74 75 76 77 79 80 81 83 84 85 86 87 88 89 90 92 93 94 95 96 97 98\n3 7 32 37 42 61 70 78 82 91", "output": "1 1 2 1 1 1 2 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 1 1 1 1 2 1 1 1 1 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 1 1 1 1 1 1 1 1 2 1 1 1 1 1 1 1 2 1 1 1 2 1 1 1 1 1 1 1 1 2 1 1 1 1 1 1 1" }, { "input": "98 96 2\n1 2 3 4 5 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\n6 7", "output": "1 1 1 1 1 2 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 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": "97 97 1\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 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\n94", "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" }, { "input": "97 97 1\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 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\n20", "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" }, { "input": "96 96 1\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 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\n48", "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" }, { "input": "95 95 1\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 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\n55", "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,492,706,296
2,147,483,647
Python 3
OK
TESTS
32
62
5,529,600
n, a, b = list(map(int, input().split())) aa = list(map(int, input().split())) ab = list(map(int, input().split())) ans = [0] * n for a in aa: ans[a - 1] = '1' for a in ab: ans[a - 1] = '2' print(' '.join(ans))
Title: Pasha and Hamsters Time Limit: None seconds Memory Limit: None megabytes Problem Description: Pasha has two hamsters: Arthur and Alexander. Pasha put *n* apples in front of them. Pasha knows which apples Arthur likes. Similarly, Pasha knows which apples Alexander likes. Pasha doesn't want any conflict between the hamsters (as they may like the same apple), so he decided to distribute the apples between the hamsters on his own. He is going to give some apples to Arthur and some apples to Alexander. It doesn't matter how many apples each hamster gets but it is important that each hamster gets only the apples he likes. It is possible that somebody doesn't get any apples. Help Pasha distribute all the apples between the hamsters. Note that Pasha wants to distribute all the apples, not just some of them. Input Specification: The first line contains integers *n*, *a*, *b* (1<=≤<=*n*<=≤<=100; 1<=≤<=*a*,<=*b*<=≤<=*n*) — the number of apples Pasha has, the number of apples Arthur likes and the number of apples Alexander likes, correspondingly. The next line contains *a* distinct integers — the numbers of the apples Arthur likes. The next line contains *b* distinct integers — the numbers of the apples Alexander likes. Assume that the apples are numbered from 1 to *n*. The input is such that the answer exists. Output Specification: Print *n* characters, each of them equals either 1 or 2. If the *i*-h character equals 1, then the *i*-th apple should be given to Arthur, otherwise it should be given to Alexander. If there are multiple correct answers, you are allowed to print any of them. Demo Input: ['4 2 3\n1 2\n2 3 4\n', '5 5 2\n3 4 1 2 5\n2 3\n'] Demo Output: ['1 1 2 2\n', '1 1 1 1 1\n'] Note: none
```python n, a, b = list(map(int, input().split())) aa = list(map(int, input().split())) ab = list(map(int, input().split())) ans = [0] * n for a in aa: ans[a - 1] = '1' for a in ab: ans[a - 1] = '2' print(' '.join(ans)) ```
3
277
E
Binary Tree on Plane
PROGRAMMING
2,400
[ "flows", "trees" ]
null
null
A root tree is a directed acyclic graph that contains one node (root), from which there is exactly one path to any other node. A root tree is binary if each node has at most two outgoing arcs. When a binary tree is painted on the plane, all arcs should be directed from top to bottom. That is, each arc going from *u* to *v* must meet the condition *y**u*<=&gt;<=*y**v*. You've been given the coordinates of all tree nodes. Your task is to connect these nodes by arcs so as to get the binary root tree and make the total length of the arcs minimum. All arcs of the built tree must be directed from top to bottom.
The first line contains a single integer *n* (2<=≤<=*n*<=≤<=400) — the number of nodes in the tree. Then follow *n* lines, two integers per line: *x**i*,<=*y**i* (|*x**i*|,<=|*y**i*|<=≤<=103) — coordinates of the nodes. It is guaranteed that all points are distinct.
If it is impossible to build a binary root tree on the given points, print "-1". Otherwise, print a single real number — the total length of the arcs in the minimum binary tree. The answer will be considered correct if the absolute or relative error doesn't exceed 10<=-<=6.
[ "3\n0 0\n1 0\n2 1\n", "4\n0 0\n1 0\n2 1\n2 0\n" ]
[ "3.650281539872885\n", "-1\n" ]
none
2,000
[]
1,673,919,618
2,147,483,647
PyPy 3-64
TIME_LIMIT_EXCEEDED
TESTS
12
3,000
70,758,400
import os, sys from io import BytesIO, IOBase from array import array from itertools import accumulate import bisect import math from collections import deque # from functools import cache # cache cf需要自己提交 pypy3.9! from copy import deepcopy class FastIO(IOBase): newlines = 0 def __init__(self, file): self._fd = file.fileno() self.buffer = BytesIO() self.writable = "x" in file.mode or "r" not in file.mode self.write = self.buffer.write if self.writable else None def read(self): while True: b = os.read(self._fd, max(os.fstat(self._fd).st_size, 8192)) if not b: break ptr = self.buffer.tell() self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr) self.newlines = 0 return self.buffer.read() def readline(self): while self.newlines == 0: b = os.read(self._fd, max(os.fstat(self._fd).st_size, 8192)) self.newlines = b.count(b"\n") + (not b) ptr = self.buffer.tell() self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr) self.newlines -= 1 return self.buffer.readline() def flush(self): if self.writable: os.write(self._fd, self.buffer.getvalue()) self.buffer.truncate(0), self.buffer.seek(0) class IOWrapper(IOBase): def __init__(self, file): self.buffer = FastIO(file) self.flush = self.buffer.flush self.writable = self.buffer.writable self.write = lambda s: self.buffer.write(s.encode("ascii")) self.read = lambda: self.buffer.read().decode("ascii") self.readline = lambda: self.buffer.readline().decode("ascii") sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout) input = lambda: sys.stdin.readline().strip() ints = lambda: list(map(int, input().split())) Int = lambda: int(input()) def queryInteractive(a, b, c): print('? {} {} {}'.format(a, b, c)) sys.stdout.flush() return int(input()) def answerInteractive(x1, x2): print('! {} {}'.format(x1, x2)) sys.stdout.flush() inf = float('inf') import heapq class mcf_graph(): n=1 pos=[] g=[[]] def __init__(self,N): self.n=N self.pos=[] self.g=[[] for i in range(N)] def add_edge(self,From,To,cap,cost): assert 0<=From and From<self.n assert 0<=To and To<self.n m=len(self.pos) self.pos.append((From,len(self.g[From]))) self.g[From].append({"to":To,"rev":len(self.g[To]),"cap":cap,"cost":cost}) self.g[To].append({"to":From,"rev":len(self.g[From])-1,"cap":0,"cost":-cost}) def get_edge(self,i): m=len(self.pos) assert 0<=i and i<m _e=self.g[self.pos[i][0]][self.pos[i][1]] _re=self.g[_e["to"]][_e["rev"]] return {"from":self.pos[i][0],"to":_e["to"],"cap":_e["cap"]+_re["cap"], "flow":_re["cap"],"cost":_e["cost"]} def edges(self): m=len(self.pos) result=[{} for i in range(m)] for i in range(m): tmp=self.get_edge(i) result[i]["from"]=tmp["from"] result[i]["to"]=tmp["to"] result[i]["cap"]=tmp["cap"] result[i]["flow"]=tmp["flow"] result[i]["cost"]=tmp["cost"] return result def flow(self,s,t,flow_limit=-1-(-1<<63)): return self.slope(s,t,flow_limit)[-1] def slope(self,s,t,flow_limit=-1-(-1<<63)): assert 0<=s and s<self.n assert 0<=t and t<self.n assert s!=t ''' variants (C = maxcost): -(n-1)C <= dual[s] <= dual[i] <= dual[t] = 0 reduced cost (= e.cost + dual[e.from] - dual[e.to]) >= 0 for all edge ''' dual=[0 for i in range(self.n)] dist=[0 for i in range(self.n)] pv=[0 for i in range(self.n)] pe=[0 for i in range(self.n)] vis=[False for i in range(self.n)] def dual_ref(): for i in range(self.n): dist[i]=-1-(-1<<63) pv[i]=-1 pe[i]=-1 vis[i]=False que=[] heapq.heappush(que,(0,s)) dist[s]=0 while(que): v=heapq.heappop(que)[1] if vis[v]:continue vis[v]=True if v==t:break ''' dist[v] = shortest(s, v) + dual[s] - dual[v] dist[v] >= 0 (all reduced cost are positive) dist[v] <= (n-1)C ''' for i in range(len(self.g[v])): e=self.g[v][i] if vis[e["to"]] or (not(e["cap"])):continue ''' |-dual[e.to]+dual[v]| <= (n-1)C cost <= C - -(n-1)C + 0 = nC ''' cost=e["cost"]-dual[e["to"]]+dual[v] if dist[e["to"]]-dist[v]>cost: dist[e["to"]]=dist[v]+cost pv[e["to"]]=v pe[e["to"]]=i heapq.heappush(que,(dist[e["to"]],e["to"])) if not(vis[t]): return False for v in range(self.n): if not(vis[v]):continue dual[v]-=dist[t]-dist[v] return True flow=0 cost=0 prev_cost=-1 result=[(flow,cost)] while(flow<flow_limit): if not(dual_ref()): break c=flow_limit-flow v=t while(v!=s): c=min(c,self.g[pv[v]][pe[v]]["cap"]) v=pv[v] v=t while(v!=s): self.g[pv[v]][pe[v]]["cap"]-=c self.g[v][self.g[pv[v]][pe[v]]["rev"]]["cap"]+=c v=pv[v] d=-dual[s] flow+=c cost+=c*d if(prev_cost==d): result.pop() result.append((flow,cost)) prev_cost=cost return result n = Int() a = [] for _ in range(n): x,y = ints() a.append((x,y)) s = 2*n t = 2*n+1 mf = mcf_graph(2*n+2) for i in range(n): for j in range(i+1,n): if a[i][1] == a[j][1]: continue if a[i][1] > a[j][1]: d = math.sqrt((a[i][0] - a[j][0])**2 + (a[i][1] - a[j][1])**2) mf.add_edge(i,j+n,1,d) elif a[i][1] < a[j][1]: d = math.sqrt((a[i][0] - a[j][0])**2 + (a[i][1] - a[j][1])**2) mf.add_edge(j,i+n,1,d) for i in range(n): mf.add_edge(s,i,2,0) for j in range(n): mf.add_edge(j+n,t,1,0) flow = mf.flow(s,t,inf) if flow[0] < n-1: print("-1") sys.exit() print(flow[-1])
Title: Binary Tree on Plane Time Limit: None seconds Memory Limit: None megabytes Problem Description: A root tree is a directed acyclic graph that contains one node (root), from which there is exactly one path to any other node. A root tree is binary if each node has at most two outgoing arcs. When a binary tree is painted on the plane, all arcs should be directed from top to bottom. That is, each arc going from *u* to *v* must meet the condition *y**u*<=&gt;<=*y**v*. You've been given the coordinates of all tree nodes. Your task is to connect these nodes by arcs so as to get the binary root tree and make the total length of the arcs minimum. All arcs of the built tree must be directed from top to bottom. Input Specification: The first line contains a single integer *n* (2<=≤<=*n*<=≤<=400) — the number of nodes in the tree. Then follow *n* lines, two integers per line: *x**i*,<=*y**i* (|*x**i*|,<=|*y**i*|<=≤<=103) — coordinates of the nodes. It is guaranteed that all points are distinct. Output Specification: If it is impossible to build a binary root tree on the given points, print "-1". Otherwise, print a single real number — the total length of the arcs in the minimum binary tree. The answer will be considered correct if the absolute or relative error doesn't exceed 10<=-<=6. Demo Input: ['3\n0 0\n1 0\n2 1\n', '4\n0 0\n1 0\n2 1\n2 0\n'] Demo Output: ['3.650281539872885\n', '-1\n'] Note: none
```python import os, sys from io import BytesIO, IOBase from array import array from itertools import accumulate import bisect import math from collections import deque # from functools import cache # cache cf需要自己提交 pypy3.9! from copy import deepcopy class FastIO(IOBase): newlines = 0 def __init__(self, file): self._fd = file.fileno() self.buffer = BytesIO() self.writable = "x" in file.mode or "r" not in file.mode self.write = self.buffer.write if self.writable else None def read(self): while True: b = os.read(self._fd, max(os.fstat(self._fd).st_size, 8192)) if not b: break ptr = self.buffer.tell() self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr) self.newlines = 0 return self.buffer.read() def readline(self): while self.newlines == 0: b = os.read(self._fd, max(os.fstat(self._fd).st_size, 8192)) self.newlines = b.count(b"\n") + (not b) ptr = self.buffer.tell() self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr) self.newlines -= 1 return self.buffer.readline() def flush(self): if self.writable: os.write(self._fd, self.buffer.getvalue()) self.buffer.truncate(0), self.buffer.seek(0) class IOWrapper(IOBase): def __init__(self, file): self.buffer = FastIO(file) self.flush = self.buffer.flush self.writable = self.buffer.writable self.write = lambda s: self.buffer.write(s.encode("ascii")) self.read = lambda: self.buffer.read().decode("ascii") self.readline = lambda: self.buffer.readline().decode("ascii") sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout) input = lambda: sys.stdin.readline().strip() ints = lambda: list(map(int, input().split())) Int = lambda: int(input()) def queryInteractive(a, b, c): print('? {} {} {}'.format(a, b, c)) sys.stdout.flush() return int(input()) def answerInteractive(x1, x2): print('! {} {}'.format(x1, x2)) sys.stdout.flush() inf = float('inf') import heapq class mcf_graph(): n=1 pos=[] g=[[]] def __init__(self,N): self.n=N self.pos=[] self.g=[[] for i in range(N)] def add_edge(self,From,To,cap,cost): assert 0<=From and From<self.n assert 0<=To and To<self.n m=len(self.pos) self.pos.append((From,len(self.g[From]))) self.g[From].append({"to":To,"rev":len(self.g[To]),"cap":cap,"cost":cost}) self.g[To].append({"to":From,"rev":len(self.g[From])-1,"cap":0,"cost":-cost}) def get_edge(self,i): m=len(self.pos) assert 0<=i and i<m _e=self.g[self.pos[i][0]][self.pos[i][1]] _re=self.g[_e["to"]][_e["rev"]] return {"from":self.pos[i][0],"to":_e["to"],"cap":_e["cap"]+_re["cap"], "flow":_re["cap"],"cost":_e["cost"]} def edges(self): m=len(self.pos) result=[{} for i in range(m)] for i in range(m): tmp=self.get_edge(i) result[i]["from"]=tmp["from"] result[i]["to"]=tmp["to"] result[i]["cap"]=tmp["cap"] result[i]["flow"]=tmp["flow"] result[i]["cost"]=tmp["cost"] return result def flow(self,s,t,flow_limit=-1-(-1<<63)): return self.slope(s,t,flow_limit)[-1] def slope(self,s,t,flow_limit=-1-(-1<<63)): assert 0<=s and s<self.n assert 0<=t and t<self.n assert s!=t ''' variants (C = maxcost): -(n-1)C <= dual[s] <= dual[i] <= dual[t] = 0 reduced cost (= e.cost + dual[e.from] - dual[e.to]) >= 0 for all edge ''' dual=[0 for i in range(self.n)] dist=[0 for i in range(self.n)] pv=[0 for i in range(self.n)] pe=[0 for i in range(self.n)] vis=[False for i in range(self.n)] def dual_ref(): for i in range(self.n): dist[i]=-1-(-1<<63) pv[i]=-1 pe[i]=-1 vis[i]=False que=[] heapq.heappush(que,(0,s)) dist[s]=0 while(que): v=heapq.heappop(que)[1] if vis[v]:continue vis[v]=True if v==t:break ''' dist[v] = shortest(s, v) + dual[s] - dual[v] dist[v] >= 0 (all reduced cost are positive) dist[v] <= (n-1)C ''' for i in range(len(self.g[v])): e=self.g[v][i] if vis[e["to"]] or (not(e["cap"])):continue ''' |-dual[e.to]+dual[v]| <= (n-1)C cost <= C - -(n-1)C + 0 = nC ''' cost=e["cost"]-dual[e["to"]]+dual[v] if dist[e["to"]]-dist[v]>cost: dist[e["to"]]=dist[v]+cost pv[e["to"]]=v pe[e["to"]]=i heapq.heappush(que,(dist[e["to"]],e["to"])) if not(vis[t]): return False for v in range(self.n): if not(vis[v]):continue dual[v]-=dist[t]-dist[v] return True flow=0 cost=0 prev_cost=-1 result=[(flow,cost)] while(flow<flow_limit): if not(dual_ref()): break c=flow_limit-flow v=t while(v!=s): c=min(c,self.g[pv[v]][pe[v]]["cap"]) v=pv[v] v=t while(v!=s): self.g[pv[v]][pe[v]]["cap"]-=c self.g[v][self.g[pv[v]][pe[v]]["rev"]]["cap"]+=c v=pv[v] d=-dual[s] flow+=c cost+=c*d if(prev_cost==d): result.pop() result.append((flow,cost)) prev_cost=cost return result n = Int() a = [] for _ in range(n): x,y = ints() a.append((x,y)) s = 2*n t = 2*n+1 mf = mcf_graph(2*n+2) for i in range(n): for j in range(i+1,n): if a[i][1] == a[j][1]: continue if a[i][1] > a[j][1]: d = math.sqrt((a[i][0] - a[j][0])**2 + (a[i][1] - a[j][1])**2) mf.add_edge(i,j+n,1,d) elif a[i][1] < a[j][1]: d = math.sqrt((a[i][0] - a[j][0])**2 + (a[i][1] - a[j][1])**2) mf.add_edge(j,i+n,1,d) for i in range(n): mf.add_edge(s,i,2,0) for j in range(n): mf.add_edge(j+n,t,1,0) flow = mf.flow(s,t,inf) if flow[0] < n-1: print("-1") sys.exit() print(flow[-1]) ```
0
271
A
Beautiful Year
PROGRAMMING
800
[ "brute force" ]
null
null
It seems like the year of 2013 came only yesterday. Do you know a curious fact? The year of 2013 is the first year after the old 1987 with only distinct digits. Now you are suggested to solve the following problem: given a year number, find the minimum year number which is strictly larger than the given one and has only distinct digits.
The single line contains integer *y* (1000<=≤<=*y*<=≤<=9000) — the year number.
Print a single integer — the minimum year number that is strictly larger than *y* and all it's digits are distinct. It is guaranteed that the answer exists.
[ "1987\n", "2013\n" ]
[ "2013\n", "2014\n" ]
none
500
[ { "input": "1987", "output": "2013" }, { "input": "2013", "output": "2014" }, { "input": "1000", "output": "1023" }, { "input": "1001", "output": "1023" }, { "input": "1234", "output": "1235" }, { "input": "5555", "output": "5601" }, { "input": "9000", "output": "9012" }, { "input": "1111", "output": "1203" }, { "input": "8999", "output": "9012" }, { "input": "4572", "output": "4573" }, { "input": "6666", "output": "6701" }, { "input": "2001", "output": "2013" }, { "input": "3000", "output": "3012" }, { "input": "7712", "output": "7801" }, { "input": "8088", "output": "8091" }, { "input": "1594", "output": "1596" }, { "input": "6016", "output": "6017" }, { "input": "8800", "output": "8901" }, { "input": "3331", "output": "3401" }, { "input": "5090", "output": "5091" }, { "input": "2342", "output": "2345" }, { "input": "2334", "output": "2340" }, { "input": "1123", "output": "1203" }, { "input": "8989", "output": "9012" }, { "input": "8977", "output": "9012" }, { "input": "6869", "output": "6870" }, { "input": "8999", "output": "9012" } ]
1,696,198,014
2,147,483,647
Python 3
OK
TESTS
27
92
0
a = int(input()) + 1 while len(set(str(a))) != 4: a += 1 print(a)
Title: Beautiful Year Time Limit: None seconds Memory Limit: None megabytes Problem Description: It seems like the year of 2013 came only yesterday. Do you know a curious fact? The year of 2013 is the first year after the old 1987 with only distinct digits. Now you are suggested to solve the following problem: given a year number, find the minimum year number which is strictly larger than the given one and has only distinct digits. Input Specification: The single line contains integer *y* (1000<=≤<=*y*<=≤<=9000) — the year number. Output Specification: Print a single integer — the minimum year number that is strictly larger than *y* and all it's digits are distinct. It is guaranteed that the answer exists. Demo Input: ['1987\n', '2013\n'] Demo Output: ['2013\n', '2014\n'] Note: none
```python a = int(input()) + 1 while len(set(str(a))) != 4: a += 1 print(a) ```
3
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,601,794,416
2,147,483,647
Python 3
OK
TESTS
37
109
0
n= int(input()) arr = list(map(int, input().split())) a = [] for i in arr: a.append(arr.count(i)) print(max(a))
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 n= int(input()) arr = list(map(int, input().split())) a = [] for i in arr: a.append(arr.count(i)) print(max(a)) ```
3
535
C
Tavas and Karafs
PROGRAMMING
1,900
[ "binary search", "greedy", "math" ]
null
null
Karafs is some kind of vegetable in shape of an 1<=×<=*h* rectangle. Tavaspolis people love Karafs and they use Karafs in almost any kind of food. Tavas, himself, is crazy about Karafs. Each Karafs has a positive integer height. Tavas has an infinite 1-based sequence of Karafses. The height of the *i*-th Karafs is *s**i*<==<=*A*<=+<=(*i*<=-<=1)<=×<=*B*. For a given *m*, let's define an *m*-bite operation as decreasing the height of at most *m* distinct not eaten Karafses by 1. Karafs is considered as eaten when its height becomes zero. Now SaDDas asks you *n* queries. In each query he gives you numbers *l*, *t* and *m* and you should find the largest number *r* such that *l*<=≤<=*r* and sequence *s**l*,<=*s**l*<=+<=1,<=...,<=*s**r* can be eaten by performing *m*-bite no more than *t* times or print -1 if there is no such number *r*.
The first line of input contains three integers *A*, *B* and *n* (1<=≤<=*A*,<=*B*<=≤<=106, 1<=≤<=*n*<=≤<=105). Next *n* lines contain information about queries. *i*-th line contains integers *l*,<=*t*,<=*m* (1<=≤<=*l*,<=*t*,<=*m*<=≤<=106) for *i*-th query.
For each query, print its answer in a single line.
[ "2 1 4\n1 5 3\n3 3 10\n7 10 2\n6 4 8\n", "1 5 2\n1 5 10\n2 7 4\n" ]
[ "4\n-1\n8\n-1\n", "1\n2\n" ]
none
1,500
[ { "input": "2 1 4\n1 5 3\n3 3 10\n7 10 2\n6 4 8", "output": "4\n-1\n8\n-1" }, { "input": "1 5 2\n1 5 10\n2 7 4", "output": "1\n2" }, { "input": "1 1 4\n1 1000000 1000000\n1 1 1000000\n1 1000000 1\n1 1 1", "output": "1000000\n1\n1413\n1" }, { "input": "1000000 1000000 1\n1000000 1000000 1000000", "output": "-1" }, { "input": "999999 1000000 1\n1 1000000 1000000", "output": "1" }, { "input": "1 1000000 1\n1 1000000 1000000", "output": "1" }, { "input": "1 5000 1\n1 1000000 1000000", "output": "200" }, { "input": "1 1 1\n1 1000000 1000000", "output": "1000000" }, { "input": "447 74474 4\n47 777474 747\n74 744744 74477\n477 477447 777\n7 477777 444444", "output": "-1\n-1\n-1\n7" } ]
1,439,656,716
2,147,483,647
Python 3
TIME_LIMIT_EXCEEDED
TESTS
2
2,000
0
a,b,n=map(int,input().split()) for absa in range(0,n): l,t,m=map(int,input().split()); r=l; s=0; while (s+a+(r-1)*b<=m*t and r<=(t-a+b)/b): s+=a+(r-1)*b; r+=1; if(s==0) : print(-1) else: print(r-1)
Title: Tavas and Karafs Time Limit: None seconds Memory Limit: None megabytes Problem Description: Karafs is some kind of vegetable in shape of an 1<=×<=*h* rectangle. Tavaspolis people love Karafs and they use Karafs in almost any kind of food. Tavas, himself, is crazy about Karafs. Each Karafs has a positive integer height. Tavas has an infinite 1-based sequence of Karafses. The height of the *i*-th Karafs is *s**i*<==<=*A*<=+<=(*i*<=-<=1)<=×<=*B*. For a given *m*, let's define an *m*-bite operation as decreasing the height of at most *m* distinct not eaten Karafses by 1. Karafs is considered as eaten when its height becomes zero. Now SaDDas asks you *n* queries. In each query he gives you numbers *l*, *t* and *m* and you should find the largest number *r* such that *l*<=≤<=*r* and sequence *s**l*,<=*s**l*<=+<=1,<=...,<=*s**r* can be eaten by performing *m*-bite no more than *t* times or print -1 if there is no such number *r*. Input Specification: The first line of input contains three integers *A*, *B* and *n* (1<=≤<=*A*,<=*B*<=≤<=106, 1<=≤<=*n*<=≤<=105). Next *n* lines contain information about queries. *i*-th line contains integers *l*,<=*t*,<=*m* (1<=≤<=*l*,<=*t*,<=*m*<=≤<=106) for *i*-th query. Output Specification: For each query, print its answer in a single line. Demo Input: ['2 1 4\n1 5 3\n3 3 10\n7 10 2\n6 4 8\n', '1 5 2\n1 5 10\n2 7 4\n'] Demo Output: ['4\n-1\n8\n-1\n', '1\n2\n'] Note: none
```python a,b,n=map(int,input().split()) for absa in range(0,n): l,t,m=map(int,input().split()); r=l; s=0; while (s+a+(r-1)*b<=m*t and r<=(t-a+b)/b): s+=a+(r-1)*b; r+=1; if(s==0) : print(-1) else: print(r-1) ```
0
202
A
LLPS
PROGRAMMING
800
[ "binary search", "bitmasks", "brute force", "greedy", "implementation", "strings" ]
null
null
This problem's actual name, "Lexicographically Largest Palindromic Subsequence" is too long to fit into the page headline. You are given string *s* consisting of lowercase English letters only. Find its lexicographically largest palindromic subsequence. We'll call a non-empty string *s*[*p*1*p*2... *p**k*] = *s**p*1*s**p*2... *s**p**k* (1 <=≤<= *p*1<=&lt;<=*p*2<=&lt;<=...<=&lt;<=*p**k* <=≤<= |*s*|) a subsequence of string *s* = *s*1*s*2... *s*|*s*|, where |*s*| is the length of string *s*. For example, strings "abcb", "b" and "abacaba" are subsequences of string "abacaba". String *x* = *x*1*x*2... *x*|*x*| is lexicographically larger than string *y* = *y*1*y*2... *y*|*y*| if either |*x*| &gt; |*y*| and *x*1<==<=*y*1, *x*2<==<=*y*2, ...,<=*x*|*y*|<==<=*y*|*y*|, or there exists such number *r* (*r*<=&lt;<=|*x*|, *r*<=&lt;<=|*y*|) that *x*1<==<=*y*1, *x*2<==<=*y*2, ..., *x**r*<==<=*y**r* and *x**r*<=<=+<=<=1<=&gt;<=*y**r*<=<=+<=<=1. Characters in the strings are compared according to their ASCII codes. For example, string "ranger" is lexicographically larger than string "racecar" and string "poster" is lexicographically larger than string "post". String *s* = *s*1*s*2... *s*|*s*| is a palindrome if it matches string *rev*(*s*) = *s*|*s*|*s*|*s*|<=-<=1... *s*1. In other words, a string is a palindrome if it reads the same way from left to right and from right to left. For example, palindromic strings are "racecar", "refer" and "z".
The only input line contains a non-empty string *s* consisting of lowercase English letters only. Its length does not exceed 10.
Print the lexicographically largest palindromic subsequence of string *s*.
[ "radar\n", "bowwowwow\n", "codeforces\n", "mississipp\n" ]
[ "rr\n", "wwwww\n", "s\n", "ssss\n" ]
Among all distinct subsequences of string "radar" the following ones are palindromes: "a", "d", "r", "aa", "rr", "ada", "rar", "rdr", "raar" and "radar". The lexicographically largest of them is "rr".
500
[ { "input": "radar", "output": "rr" }, { "input": "bowwowwow", "output": "wwwww" }, { "input": "codeforces", "output": "s" }, { "input": "mississipp", "output": "ssss" }, { "input": "tourist", "output": "u" }, { "input": "romka", "output": "r" }, { "input": "helloworld", "output": "w" }, { "input": "zzzzzzzazz", "output": "zzzzzzzzz" }, { "input": "testcase", "output": "tt" }, { "input": "hahahahaha", "output": "hhhhh" }, { "input": "abbbbbbbbb", "output": "bbbbbbbbb" }, { "input": "zaz", "output": "zz" }, { "input": "aza", "output": "z" }, { "input": "dcbaedcba", "output": "e" }, { "input": "abcdeabcd", "output": "e" }, { "input": "edcbabcde", "output": "ee" }, { "input": "aaaaaaaaab", "output": "b" }, { "input": "testzzzzzz", "output": "zzzzzz" }, { "input": "zzzzzzwait", "output": "zzzzzz" }, { "input": "rrrrrqponm", "output": "rrrrr" }, { "input": "zzyzyy", "output": "zzz" }, { "input": "aababb", "output": "bbb" }, { "input": "zanzibar", "output": "zz" }, { "input": "hhgfedcbaa", "output": "hh" }, { "input": "aabcdefghh", "output": "hh" }, { "input": "aruaru", "output": "uu" }, { "input": "uraura", "output": "uu" }, { "input": "aru", "output": "u" }, { "input": "aburvabur", "output": "v" }, { "input": "ura", "output": "u" }, { "input": "eurottat", "output": "u" }, { "input": "referee", "output": "rr" }, { "input": "joking", "output": "o" }, { "input": "seriously", "output": "y" }, { "input": "sets", "output": "t" }, { "input": "test", "output": "tt" }, { "input": "klmgameklm", "output": "mmm" }, { "input": "dfkjafdkdd", "output": "kk" }, { "input": "zzzzzzzzzz", "output": "zzzzzzzzzz" }, { "input": "aaaaaaaaaa", "output": "aaaaaaaaaa" }, { "input": "buzz", "output": "zz" }, { "input": "b", "output": "b" }, { "input": "y", "output": "y" }, { "input": "yy", "output": "yy" }, { "input": "zz", "output": "zz" }, { "input": "bb", "output": "bb" }, { "input": "aa", "output": "aa" }, { "input": "a", "output": "a" }, { "input": "z", "output": "z" }, { "input": "zz", "output": "zz" }, { "input": "zzazazzzaz", "output": "zzzzzzz" }, { "input": "hellhellhe", "output": "llll" }, { "input": "hellohello", "output": "oo" }, { "input": "refer", "output": "rr" } ]
1,649,374,522
2,147,483,647
Python 3
OK
TESTS
54
92
0
from itertools import combinations def get_subsequences(input_str): for length in range(1, len(input_str)+1): for elems in combinations(input_str, length): yield ''.join(elems) print(sorted([s for s in get_subsequences(input()) if s[::-1] == s])[-1])
Title: LLPS Time Limit: None seconds Memory Limit: None megabytes Problem Description: This problem's actual name, "Lexicographically Largest Palindromic Subsequence" is too long to fit into the page headline. You are given string *s* consisting of lowercase English letters only. Find its lexicographically largest palindromic subsequence. We'll call a non-empty string *s*[*p*1*p*2... *p**k*] = *s**p*1*s**p*2... *s**p**k* (1 <=≤<= *p*1<=&lt;<=*p*2<=&lt;<=...<=&lt;<=*p**k* <=≤<= |*s*|) a subsequence of string *s* = *s*1*s*2... *s*|*s*|, where |*s*| is the length of string *s*. For example, strings "abcb", "b" and "abacaba" are subsequences of string "abacaba". String *x* = *x*1*x*2... *x*|*x*| is lexicographically larger than string *y* = *y*1*y*2... *y*|*y*| if either |*x*| &gt; |*y*| and *x*1<==<=*y*1, *x*2<==<=*y*2, ...,<=*x*|*y*|<==<=*y*|*y*|, or there exists such number *r* (*r*<=&lt;<=|*x*|, *r*<=&lt;<=|*y*|) that *x*1<==<=*y*1, *x*2<==<=*y*2, ..., *x**r*<==<=*y**r* and *x**r*<=<=+<=<=1<=&gt;<=*y**r*<=<=+<=<=1. Characters in the strings are compared according to their ASCII codes. For example, string "ranger" is lexicographically larger than string "racecar" and string "poster" is lexicographically larger than string "post". String *s* = *s*1*s*2... *s*|*s*| is a palindrome if it matches string *rev*(*s*) = *s*|*s*|*s*|*s*|<=-<=1... *s*1. In other words, a string is a palindrome if it reads the same way from left to right and from right to left. For example, palindromic strings are "racecar", "refer" and "z". Input Specification: The only input line contains a non-empty string *s* consisting of lowercase English letters only. Its length does not exceed 10. Output Specification: Print the lexicographically largest palindromic subsequence of string *s*. Demo Input: ['radar\n', 'bowwowwow\n', 'codeforces\n', 'mississipp\n'] Demo Output: ['rr\n', 'wwwww\n', 's\n', 'ssss\n'] Note: Among all distinct subsequences of string "radar" the following ones are palindromes: "a", "d", "r", "aa", "rr", "ada", "rar", "rdr", "raar" and "radar". The lexicographically largest of them is "rr".
```python from itertools import combinations def get_subsequences(input_str): for length in range(1, len(input_str)+1): for elems in combinations(input_str, length): yield ''.join(elems) print(sorted([s for s in get_subsequences(input()) if s[::-1] == s])[-1]) ```
3
952
C
Ravioli Sort
PROGRAMMING
1,600
[ "implementation" ]
null
null
Everybody knows of [spaghetti sort](https://en.wikipedia.org/wiki/Spaghetti_sort). You decided to implement an analog sorting algorithm yourself, but as you survey your pantry you realize you're out of spaghetti! The only type of pasta you have is ravioli, but you are not going to let this stop you... You come up with the following algorithm. For each number in the array *a**i*, build a stack of *a**i* ravioli. The image shows the stack for *a**i*<==<=4. Arrange the stacks in one row in the order in which the corresponding numbers appear in the input array. Find the tallest one (if there are several stacks of maximal height, use the leftmost one). Remove it and add its height to the end of the output array. Shift the stacks in the row so that there is no gap between them. Repeat the procedure until all stacks have been removed. At first you are very happy with your algorithm, but as you try it on more inputs you realize that it doesn't always produce the right sorted array. Turns out when two stacks of ravioli are next to each other (at any step of the process) and differ in height by two or more, the top ravioli of the taller stack slides down on top of the lower stack. Given an input array, figure out whether the described algorithm will sort it correctly.
The first line of input contains a single number *n* (1<=≤<=*n*<=≤<=10) — the size of the array. The second line of input contains *n* space-separated integers *a**i* (1<=≤<=*a**i*<=≤<=100) — the elements of the array.
Output "YES" if the array can be sorted using the described procedure and "NO" if it can not.
[ "3\n1 2 3\n", "3\n3 1 2\n" ]
[ "YES\n", "NO\n" ]
In the second example the array will change even before the tallest stack is chosen for the first time: ravioli from stack of height 3 will slide on the stack of height 1, and the algorithm will output an array {2, 2, 2}.
0
[ { "input": "3\n1 2 3", "output": "YES" }, { "input": "3\n3 1 2", "output": "NO" }, { "input": "1\n13", "output": "YES" }, { "input": "10\n67 67 67 67 67 67 67 67 67 67", "output": "YES" }, { "input": "10\n16 17 16 15 14 15 16 17 16 15", "output": "YES" }, { "input": "4\n54 54 54 55", "output": "YES" }, { "input": "3\n68 67 67", "output": "YES" }, { "input": "5\n46 46 47 46 45", "output": "YES" }, { "input": "4\n14 15 15 16", "output": "YES" }, { "input": "6\n59 59 60 60 59 58", "output": "YES" }, { "input": "3\n40 40 40", "output": "YES" }, { "input": "4\n90 91 90 91", "output": "YES" }, { "input": "10\n9 9 9 10 10 9 8 8 9 9", "output": "YES" }, { "input": "3\n22 23 24", "output": "YES" }, { "input": "9\n71 71 70 70 71 70 69 70 71", "output": "YES" }, { "input": "9\n15 14 14 13 13 12 13 13 14", "output": "YES" }, { "input": "4\n61 60 60 60", "output": "YES" }, { "input": "4\n16 17 17 18", "output": "YES" }, { "input": "6\n87 86 86 86 85 86", "output": "YES" }, { "input": "5\n64 63 63 62 61", "output": "YES" }, { "input": "9\n13 80 13 38 98 85 11 73 74", "output": "NO" }, { "input": "10\n2 83 18 65 58 95 37 51 86 47", "output": "NO" }, { "input": "6\n47 100 96 2 96 43", "output": "NO" }, { "input": "10\n28 61 23 73 61 33 45 55 18 43", "output": "NO" }, { "input": "10\n95 51 52 8 44 39 77 17 96 88", "output": "NO" }, { "input": "5\n14 91 91 91 84", "output": "NO" }, { "input": "4\n92 18 29 93", "output": "NO" }, { "input": "7\n23 37 39 8 72 31 85", "output": "NO" }, { "input": "4\n61 28 3 81", "output": "NO" }, { "input": "4\n83 100 81 75", "output": "NO" }, { "input": "9\n95 7 97 61 90 7 30 65 39", "output": "NO" }, { "input": "3\n90 39 98", "output": "NO" }, { "input": "3\n76 9 12", "output": "NO" }, { "input": "3\n69 26 73", "output": "NO" }, { "input": "10\n55 39 93 42 97 40 36 38 11 97", "output": "NO" }, { "input": "5\n21 57 40 94 17", "output": "NO" }, { "input": "7\n35 91 87 78 17 71 63", "output": "NO" }, { "input": "7\n20 21 95 73 49 98 53", "output": "NO" }, { "input": "8\n46 4 30 85 52 6 84 13", "output": "NO" }, { "input": "10\n79 84 22 38 23 22 33 42 13 96", "output": "NO" } ]
1,588,427,572
2,147,483,647
PyPy 3
WRONG_ANSWER
TESTS
1
109
0
n=int(input()) a=list(map(int,input().split())) print("YNEOS"[max(a)<n::2])
Title: Ravioli Sort Time Limit: None seconds Memory Limit: None megabytes Problem Description: Everybody knows of [spaghetti sort](https://en.wikipedia.org/wiki/Spaghetti_sort). You decided to implement an analog sorting algorithm yourself, but as you survey your pantry you realize you're out of spaghetti! The only type of pasta you have is ravioli, but you are not going to let this stop you... You come up with the following algorithm. For each number in the array *a**i*, build a stack of *a**i* ravioli. The image shows the stack for *a**i*<==<=4. Arrange the stacks in one row in the order in which the corresponding numbers appear in the input array. Find the tallest one (if there are several stacks of maximal height, use the leftmost one). Remove it and add its height to the end of the output array. Shift the stacks in the row so that there is no gap between them. Repeat the procedure until all stacks have been removed. At first you are very happy with your algorithm, but as you try it on more inputs you realize that it doesn't always produce the right sorted array. Turns out when two stacks of ravioli are next to each other (at any step of the process) and differ in height by two or more, the top ravioli of the taller stack slides down on top of the lower stack. Given an input array, figure out whether the described algorithm will sort it correctly. Input Specification: The first line of input contains a single number *n* (1<=≤<=*n*<=≤<=10) — the size of the array. The second line of input contains *n* space-separated integers *a**i* (1<=≤<=*a**i*<=≤<=100) — the elements of the array. Output Specification: Output "YES" if the array can be sorted using the described procedure and "NO" if it can not. Demo Input: ['3\n1 2 3\n', '3\n3 1 2\n'] Demo Output: ['YES\n', 'NO\n'] Note: In the second example the array will change even before the tallest stack is chosen for the first time: ravioli from stack of height 3 will slide on the stack of height 1, and the algorithm will output an array {2, 2, 2}.
```python n=int(input()) a=list(map(int,input().split())) print("YNEOS"[max(a)<n::2]) ```
0
628
B
New Skateboard
PROGRAMMING
1,300
[ "dp" ]
null
null
Max wants to buy a new skateboard. He has calculated the amount of money that is needed to buy a new skateboard. He left a calculator on the floor and went to ask some money from his parents. Meanwhile his little brother Yusuf came and started to press the keys randomly. Unfortunately Max has forgotten the number which he had calculated. The only thing he knows is that the number is divisible by 4. You are given a string *s* consisting of digits (the number on the display of the calculator after Yusuf randomly pressed the keys). Your task is to find the number of substrings which are divisible by 4. A substring can start with a zero. A substring of a string is a nonempty sequence of consecutive characters. For example if string *s* is 124 then we have four substrings that are divisible by 4: 12, 4, 24 and 124. For the string 04 the answer is three: 0, 4, 04. As input/output can reach huge size it is recommended to use fast input/output methods: for example, prefer to use gets/scanf/printf instead of getline/cin/cout in C++, prefer to use BufferedReader/PrintWriter instead of Scanner/System.out in Java.
The only line contains string *s* (1<=≤<=|*s*|<=≤<=3·105). The string *s* contains only digits from 0 to 9.
Print integer *a* — the number of substrings of the string *s* that are divisible by 4. Note that the answer can be huge, so you should use 64-bit integer type to store it. In C++ you can use the long long integer type and in Java you can use long integer type.
[ "124\n", "04\n", "5810438174\n" ]
[ "4\n", "3\n", "9\n" ]
none
0
[ { "input": "124", "output": "4" }, { "input": "04", "output": "3" }, { "input": "5810438174", "output": "9" }, { "input": "1", "output": "0" }, { "input": "039", "output": "1" }, { "input": "97247", "output": "6" }, { "input": "5810438174", "output": "9" }, { "input": "12883340691714056185860211260984431382156326935244", "output": "424" }, { "input": "2144315253572020279108092911160072328496568665545836825277616363478721946398140227406814602154768031", "output": "1528" }, { "input": "80124649014054971081213608137817466046254652492627741860478258558206397113198232823859870363821007188476405951611069347299689170240023979048198711745011542774268179055311013054073075176122755643483380248999657649211459997766221072399103579977409770898200358240970169892326442892826731631357561876251276209119521202062222947560634301788787748428236988789594458520867663257476744168528121470923031438015546006185059454402637036376247785881323277542968298682307854655591317046086531554595892680980142608", "output": "30826" }, { "input": "123456", "output": "7" }, { "input": "4", "output": "1" }, { "input": "123", "output": "1" } ]
1,679,976,702
2,147,483,647
Python 3
OK
TESTS
22
327
614,400
a= input() ans = 0 for i in range(len(a)-1,-1,-1): if(not int(a[i])%4): ans+=1 if ( i>0 and not int(a[i-1:i+1])%4): ans+= i print(ans)
Title: New Skateboard Time Limit: None seconds Memory Limit: None megabytes Problem Description: Max wants to buy a new skateboard. He has calculated the amount of money that is needed to buy a new skateboard. He left a calculator on the floor and went to ask some money from his parents. Meanwhile his little brother Yusuf came and started to press the keys randomly. Unfortunately Max has forgotten the number which he had calculated. The only thing he knows is that the number is divisible by 4. You are given a string *s* consisting of digits (the number on the display of the calculator after Yusuf randomly pressed the keys). Your task is to find the number of substrings which are divisible by 4. A substring can start with a zero. A substring of a string is a nonempty sequence of consecutive characters. For example if string *s* is 124 then we have four substrings that are divisible by 4: 12, 4, 24 and 124. For the string 04 the answer is three: 0, 4, 04. As input/output can reach huge size it is recommended to use fast input/output methods: for example, prefer to use gets/scanf/printf instead of getline/cin/cout in C++, prefer to use BufferedReader/PrintWriter instead of Scanner/System.out in Java. Input Specification: The only line contains string *s* (1<=≤<=|*s*|<=≤<=3·105). The string *s* contains only digits from 0 to 9. Output Specification: Print integer *a* — the number of substrings of the string *s* that are divisible by 4. Note that the answer can be huge, so you should use 64-bit integer type to store it. In C++ you can use the long long integer type and in Java you can use long integer type. Demo Input: ['124\n', '04\n', '5810438174\n'] Demo Output: ['4\n', '3\n', '9\n'] Note: none
```python a= input() ans = 0 for i in range(len(a)-1,-1,-1): if(not int(a[i])%4): ans+=1 if ( i>0 and not int(a[i-1:i+1])%4): ans+= i print(ans) ```
3
300
C
Beautiful Numbers
PROGRAMMING
1,800
[ "brute force", "combinatorics" ]
null
null
Vitaly is a very weird man. He's got two favorite digits *a* and *b*. Vitaly calls a positive integer good, if the decimal representation of this integer only contains digits *a* and *b*. Vitaly calls a good number excellent, if the sum of its digits is a good number. For example, let's say that Vitaly's favourite digits are 1 and 3, then number 12 isn't good and numbers 13 or 311 are. Also, number 111 is excellent and number 11 isn't. Now Vitaly is wondering, how many excellent numbers of length exactly *n* are there. As this number can be rather large, he asks you to count the remainder after dividing it by 1000000007 (109<=+<=7). A number's length is the number of digits in its decimal representation without leading zeroes.
The first line contains three integers: *a*, *b*, *n* (1<=≤<=*a*<=&lt;<=*b*<=≤<=9,<=1<=≤<=*n*<=≤<=106).
Print a single integer — the answer to the problem modulo 1000000007 (109<=+<=7).
[ "1 3 3\n", "2 3 10\n" ]
[ "1\n", "165\n" ]
none
2,000
[ { "input": "1 3 3", "output": "1" }, { "input": "2 3 10", "output": "165" }, { "input": "6 8 14215", "output": "651581472" }, { "input": "4 9 104671", "output": "329390901" }, { "input": "6 7 78755", "output": "0" }, { "input": "1 8 265", "output": "461320265" }, { "input": "3 9 37413", "output": "461358757" }, { "input": "1 7 49055", "output": "461364774" }, { "input": "3 4 11028", "output": "461668105" }, { "input": "2 6 32377", "output": "887598327" }, { "input": "3 5 80791", "output": "999993599" }, { "input": "4 8 11857", "output": "999991923" }, { "input": "1 3 10785", "output": "999952603" }, { "input": "4 6 11808", "output": "999925731" }, { "input": "1 2 11857", "output": "999991923" }, { "input": "2 4 88193", "output": "999976846" }, { "input": "1 4 37226", "output": "999970594" }, { "input": "2 5 53049", "output": "259705254" }, { "input": "3 6 1000000", "output": "786609214" }, { "input": "7 9 999999", "output": "53911803" }, { "input": "8 9 999999", "output": "447886447" }, { "input": "3 8 1000000", "output": "0" }, { "input": "2 8 999999", "output": "0" }, { "input": "1 6 997695", "output": "0" }, { "input": "1 5 997694", "output": "0" }, { "input": "5 9 997693", "output": "0" }, { "input": "5 8 997690", "output": "21735480" }, { "input": "7 8 2", "output": "0" }, { "input": "6 9 1", "output": "2" }, { "input": "8 9 111111", "output": "900401372" }, { "input": "8 9 1000000", "output": "573697309" }, { "input": "1 2 1000000", "output": "786609214" } ]
1,691,609,203
2,147,483,647
PyPy 3-64
OK
TESTS
32
1,090
27,648,000
import sys, threading import math from os import path from collections import deque, defaultdict, Counter from bisect import * from string import ascii_lowercase from functools import cmp_to_key from random import randint from heapq import * from array import array from types import GeneratorType def readInts(): x = list(map(int, (sys.stdin.readline().rstrip().split()))) return x[0] if len(x) == 1 else x def readList(type=int): x = sys.stdin.readline() x = list(map(type, x.rstrip('\n\r').split())) return x def readStr(): x = sys.stdin.readline().rstrip('\r\n') return x write = sys.stdout.write read = sys.stdin.readline MAXN = 1123456 def bootstrap(f, stack=[]): def wrappedfunc(*args, **kwargs): if stack: return f(*args, **kwargs) else: to = f(*args, **kwargs) while True: if type(to) is GeneratorType: stack.append(to) to = next(to) else: stack.pop() if not stack: break to = stack[-1].send(to) return to return wrappedfunc class mydict: def __init__(self, func=lambda: 0): self.random = randint(0, 1 << 32) self.default = func self.dict = {} def __getitem__(self, key): mykey = self.random ^ key if mykey not in self.dict: self.dict[mykey] = self.default() return self.dict[mykey] def get(self, key, default): mykey = self.random ^ key if mykey not in self.dict: return default return self.dict[mykey] def __setitem__(self, key, item): mykey = self.random ^ key self.dict[mykey] = item def getkeys(self): return [self.random ^ i for i in self.dict] def __str__(self): return f'{[(self.random ^ i, self.dict[i]) for i in self.dict]}' def lcm(a, b): return (a*b)//(math.gcd(a,b)) def mod(n): return n%(1000000007) def power(bas, exp): if (exp == 0): return 1 if (exp == 1): return bas if (exp % 2 == 0): t = power(bas, exp // 2) t = mod(t * t) return t else: return mod(power(bas, exp-1)*bas) factr = [] factr = [1] fact = 1 for i in range(1, MAXN): fact = mod(mod(fact)*mod(i)) factr.append(fact) def nCr(n, r): if r > n: return 0 n1 = factr[n] d1 = power(factr[r], 1000000005) d2 = power(factr[n-r], 1000000005) return mod(mod(n1)*mod(d1)*mod(d2)) def solve(t): # print(f'Case #{t}: ', end = '') a, b, n = readInts() ans = 0 for i in range(n+1): sm = i*a + b*(n-i) st = set(str(sm)) st.discard(str(a)) st.discard(str(b)) if len(st) > 0: continue ans = mod(ans + nCr(n, i)) print(ans) def main(): t = 1 if path.exists("/Users/arijitbhaumik/Library/Application Support/Sublime Text/Packages/User/input.txt"): sys.stdin = open("/Users/arijitbhaumik/Library/Application Support/Sublime Text/Packages/User/input.txt", 'r') sys.stdout = open("/Users/arijitbhaumik/Library/Application Support/Sublime Text/Packages/User/output.txt", 'w') # sys.setrecursionlimit(100000) # t = readInts() for i in range(t): solve(i+1) if __name__ == '__main__': main()
Title: Beautiful Numbers Time Limit: None seconds Memory Limit: None megabytes Problem Description: Vitaly is a very weird man. He's got two favorite digits *a* and *b*. Vitaly calls a positive integer good, if the decimal representation of this integer only contains digits *a* and *b*. Vitaly calls a good number excellent, if the sum of its digits is a good number. For example, let's say that Vitaly's favourite digits are 1 and 3, then number 12 isn't good and numbers 13 or 311 are. Also, number 111 is excellent and number 11 isn't. Now Vitaly is wondering, how many excellent numbers of length exactly *n* are there. As this number can be rather large, he asks you to count the remainder after dividing it by 1000000007 (109<=+<=7). A number's length is the number of digits in its decimal representation without leading zeroes. Input Specification: The first line contains three integers: *a*, *b*, *n* (1<=≤<=*a*<=&lt;<=*b*<=≤<=9,<=1<=≤<=*n*<=≤<=106). Output Specification: Print a single integer — the answer to the problem modulo 1000000007 (109<=+<=7). Demo Input: ['1 3 3\n', '2 3 10\n'] Demo Output: ['1\n', '165\n'] Note: none
```python import sys, threading import math from os import path from collections import deque, defaultdict, Counter from bisect import * from string import ascii_lowercase from functools import cmp_to_key from random import randint from heapq import * from array import array from types import GeneratorType def readInts(): x = list(map(int, (sys.stdin.readline().rstrip().split()))) return x[0] if len(x) == 1 else x def readList(type=int): x = sys.stdin.readline() x = list(map(type, x.rstrip('\n\r').split())) return x def readStr(): x = sys.stdin.readline().rstrip('\r\n') return x write = sys.stdout.write read = sys.stdin.readline MAXN = 1123456 def bootstrap(f, stack=[]): def wrappedfunc(*args, **kwargs): if stack: return f(*args, **kwargs) else: to = f(*args, **kwargs) while True: if type(to) is GeneratorType: stack.append(to) to = next(to) else: stack.pop() if not stack: break to = stack[-1].send(to) return to return wrappedfunc class mydict: def __init__(self, func=lambda: 0): self.random = randint(0, 1 << 32) self.default = func self.dict = {} def __getitem__(self, key): mykey = self.random ^ key if mykey not in self.dict: self.dict[mykey] = self.default() return self.dict[mykey] def get(self, key, default): mykey = self.random ^ key if mykey not in self.dict: return default return self.dict[mykey] def __setitem__(self, key, item): mykey = self.random ^ key self.dict[mykey] = item def getkeys(self): return [self.random ^ i for i in self.dict] def __str__(self): return f'{[(self.random ^ i, self.dict[i]) for i in self.dict]}' def lcm(a, b): return (a*b)//(math.gcd(a,b)) def mod(n): return n%(1000000007) def power(bas, exp): if (exp == 0): return 1 if (exp == 1): return bas if (exp % 2 == 0): t = power(bas, exp // 2) t = mod(t * t) return t else: return mod(power(bas, exp-1)*bas) factr = [] factr = [1] fact = 1 for i in range(1, MAXN): fact = mod(mod(fact)*mod(i)) factr.append(fact) def nCr(n, r): if r > n: return 0 n1 = factr[n] d1 = power(factr[r], 1000000005) d2 = power(factr[n-r], 1000000005) return mod(mod(n1)*mod(d1)*mod(d2)) def solve(t): # print(f'Case #{t}: ', end = '') a, b, n = readInts() ans = 0 for i in range(n+1): sm = i*a + b*(n-i) st = set(str(sm)) st.discard(str(a)) st.discard(str(b)) if len(st) > 0: continue ans = mod(ans + nCr(n, i)) print(ans) def main(): t = 1 if path.exists("/Users/arijitbhaumik/Library/Application Support/Sublime Text/Packages/User/input.txt"): sys.stdin = open("/Users/arijitbhaumik/Library/Application Support/Sublime Text/Packages/User/input.txt", 'r') sys.stdout = open("/Users/arijitbhaumik/Library/Application Support/Sublime Text/Packages/User/output.txt", 'w') # sys.setrecursionlimit(100000) # t = readInts() for i in range(t): solve(i+1) if __name__ == '__main__': main() ```
3
731
A
Night at the Museum
PROGRAMMING
800
[ "implementation", "strings" ]
null
null
Grigoriy, like the hero of one famous comedy film, found a job as a night security guard at the museum. At first night he received embosser and was to take stock of the whole exposition. Embosser is a special devise that allows to "print" the text of a plastic tape. Text is printed sequentially, character by character. The device consists of a wheel with a lowercase English letters written in a circle, static pointer to the current letter and a button that print the chosen letter. At one move it's allowed to rotate the alphabetic wheel one step clockwise or counterclockwise. Initially, static pointer points to letter 'a'. Other letters are located as shown on the picture: After Grigoriy add new item to the base he has to print its name on the plastic tape and attach it to the corresponding exhibit. It's not required to return the wheel to its initial position with pointer on the letter 'a'. Our hero is afraid that some exhibits may become alive and start to attack him, so he wants to print the names as fast as possible. Help him, for the given string find the minimum number of rotations of the wheel required to print it.
The only line of input contains the name of some exhibit — the non-empty string consisting of no more than 100 characters. It's guaranteed that the string consists of only lowercase English letters.
Print one integer — the minimum number of rotations of the wheel, required to print the name given in the input.
[ "zeus\n", "map\n", "ares\n" ]
[ "18\n", "35\n", "34\n" ]
To print the string from the first sample it would be optimal to perform the following sequence of rotations: 1. from 'a' to 'z' (1 rotation counterclockwise), 1. from 'z' to 'e' (5 clockwise rotations), 1. from 'e' to 'u' (10 rotations counterclockwise), 1. from 'u' to 's' (2 counterclockwise rotations).
500
[ { "input": "zeus", "output": "18" }, { "input": "map", "output": "35" }, { "input": "ares", "output": "34" }, { "input": "l", "output": "11" }, { "input": "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuv", "output": "99" }, { "input": "gngvi", "output": "44" }, { "input": "aaaaa", "output": "0" }, { "input": "a", "output": "0" }, { "input": "z", "output": "1" }, { "input": "vyadeehhikklnoqrs", "output": "28" }, { "input": "jjiihhhhgggfedcccbazyxx", "output": "21" }, { "input": "fyyptqqxuciqvwdewyppjdzur", "output": "117" }, { "input": "fqcnzmzmbobmancqcoalzmanaobpdse", "output": "368" }, { "input": "zzzzzaaaaaaazzzzzzaaaaaaazzzzzzaaaazzzza", "output": "8" }, { "input": "aucnwhfixuruefkypvrvnvznwtjgwlghoqtisbkhuwxmgzuljvqhmnwzisnsgjhivnjmbknptxatdkelhzkhsuxzrmlcpeoyukiy", "output": "644" }, { "input": "sssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssss", "output": "8" }, { "input": "nypjygrdtpzpigzyrisqeqfriwgwlengnezppgttgtndbrryjdl", "output": "421" }, { "input": "pnllnnmmmmoqqqqqrrtssssuuvtsrpopqoonllmonnnpppopnonoopooqpnopppqppqstuuuwwwwvxzxzzaa", "output": "84" }, { "input": "btaoahqgxnfsdmzsjxgvdwjukcvereqeskrdufqfqgzqfsftdqcthtkcnaipftcnco", "output": "666" }, { "input": "eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeerrrrrrrrrrrrrrrrwwwwwwwwww", "output": "22" }, { "input": "uyknzcrwjyzmscqucclvacmorepdgmnyhmakmmnygqwglrxkxhkpansbmruwxdeoprxzmpsvwackopujxbbkpwyeggsvjykpxh", "output": "643" }, { "input": "gzwpooohffcxwtpjgfzwtooiccxsrrokezutoojdzwsrmmhecaxwrojcbyrqlfdwwrliiib", "output": "245" }, { "input": "dbvnkktasjdwqsrzfwwtmjgbcxggdxsoeilecihduypktkkbwfbruxzzhlttrssicgdwqruddwrlbtxgmhdbatzvdxbbro", "output": "468" }, { "input": "mdtvowlktxzzbuaeiuebfeorgbdczauxsovbucactkvyvemsknsjfhifqgycqredzchipmkvzbxdjkcbyukomjlzvxzoswumned", "output": "523" }, { "input": "kkkkkkkaaaaxxaaaaaaaxxxxxxxxaaaaaaxaaaaaaaaaakkkkkkkkkaaaaaaannnnnxxxxkkkkkkkkaannnnnnna", "output": "130" }, { "input": "dffiknqqrsvwzcdgjkmpqtuwxadfhkkkmpqrtwxyadfggjmpppsuuwyyzcdgghhknnpsvvvwwwyabccffiloqruwwyyzabeeehh", "output": "163" }, { "input": "qpppmmkjihgecbyvvsppnnnkjiffeebaaywutrrqpmkjhgddbzzzywtssssqnmmljheddbbaxvusrqonmlifedbbzyywwtqnkheb", "output": "155" }, { "input": "wvvwwwvvwxxxyyyxxwwvwwvuttttttuvvwxxwxxyxxwwwwwvvuttssrssstsssssrqpqqppqrssrsrrssrssssrrsrqqrrqpppqp", "output": "57" }, { "input": "dqcpcobpcobnznamznamzlykxkxlxlylzmaobnaobpbnanbpcoaobnboaoboanzlymzmykylymylzlylymanboanaocqdqesfrfs", "output": "1236" }, { "input": "nnnnnnnnnnnnnnnnnnnnaaaaaaaaaaaaaaaaaaaakkkkkkkkkkkkkkkkkkkkkkaaaaaaaaaaaaaaaaaaaaxxxxxxxxxxxxxxxxxx", "output": "49" }, { "input": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", "output": "0" }, { "input": "cgilqsuwzaffilptwwbgmnttyyejkorxzflqvzbddhmnrvxchijpuwaeiimosxyycejlpquuwbfkpvbgijkqvxybdjjjptxcfkqt", "output": "331" }, { "input": "ufsepwgtzgtgjssxaitgpailuvgqweoppszjwhoxdhhhpwwdorwfrdjwcdekxiktwziqwbkvbknrtvajpyeqbjvhiikxxaejjpte", "output": "692" }, { "input": "uhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuh", "output": "1293" }, { "input": "vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvgggggggggggggggggggggggggggggggggggggggggggggggggg", "output": "16" }, { "input": "lyidmjyzbszgiwkxhhpnnthfwcvvstueionspfrvqgkvngmwyhezlosrpdnbvtcjjxxsykixwnepbumaacdzadlqhnjlcejovple", "output": "616" }, { "input": "etzqqbaveffalkdguunfmyyrzkccnxmlluxeasqmopxzfvlkbhipqdwjgrttoemruohgwukfisdhznqyvhswbbypoxgtxyappcrl", "output": "605" }, { "input": "lizussgedcbdjhrbeskhgatyozvwwekanlggcstijrniivupmcoofbaxfqrxddyzzptwxcftlhajsmmkkriarrqtkoauhcqefyud", "output": "549" }, { "input": "dvjuvgfdogpknmbowlsfjzcimnygbtjiucyeeroqwhmzwpjqxlbjkqawrdtmvxbiqufllfuqibxvmtdrwaqkjblxqjpwzmhwqore", "output": "688" }, { "input": "eeycuijtbgynmiczjfslwobmnkpgodfgvujvduyfeqchuaoktqrrairkkmmsjahltfcxwtpzzyddxrqfxabfoocmpuviinrjitsc", "output": "604" }, { "input": "cgglnakewwvzoytaghksebrhjdbcdegssuzilrcppayxtgxopybbwshvyqnzhdsifkuwghourmeottrgjwdqpihbklvfzxpomqsa", "output": "572" }, { "input": "aexullmxncckzryymfnuugdklaffevabqqztelpvojecljnhqldazdcaamubpenwxikysxxjjctvbndprsolzehywmgnvkgqvrfp", "output": "609" }, { "input": "psnoieutsvvcwfhtnnphhxkwigzsbzyjmdiyl", "output": "223" }, { "input": "aa", "output": "0" } ]
1,663,349,244
2,147,483,647
Python 3
OK
TESTS
44
46
0
ch=input() ch=ch.lower() ch="a"+ch l=list() for i in range(97,97+26): a=chr(i) l.append(a) n=0 for i in range(1,len(ch)): x=l.index(ch[i-1]) y=l.index(ch[i]) a=abs(y-x) if a>13: n=n+abs(a-26) else: n=n+a print(n)
Title: Night at the Museum Time Limit: None seconds Memory Limit: None megabytes Problem Description: Grigoriy, like the hero of one famous comedy film, found a job as a night security guard at the museum. At first night he received embosser and was to take stock of the whole exposition. Embosser is a special devise that allows to "print" the text of a plastic tape. Text is printed sequentially, character by character. The device consists of a wheel with a lowercase English letters written in a circle, static pointer to the current letter and a button that print the chosen letter. At one move it's allowed to rotate the alphabetic wheel one step clockwise or counterclockwise. Initially, static pointer points to letter 'a'. Other letters are located as shown on the picture: After Grigoriy add new item to the base he has to print its name on the plastic tape and attach it to the corresponding exhibit. It's not required to return the wheel to its initial position with pointer on the letter 'a'. Our hero is afraid that some exhibits may become alive and start to attack him, so he wants to print the names as fast as possible. Help him, for the given string find the minimum number of rotations of the wheel required to print it. Input Specification: The only line of input contains the name of some exhibit — the non-empty string consisting of no more than 100 characters. It's guaranteed that the string consists of only lowercase English letters. Output Specification: Print one integer — the minimum number of rotations of the wheel, required to print the name given in the input. Demo Input: ['zeus\n', 'map\n', 'ares\n'] Demo Output: ['18\n', '35\n', '34\n'] Note: To print the string from the first sample it would be optimal to perform the following sequence of rotations: 1. from 'a' to 'z' (1 rotation counterclockwise), 1. from 'z' to 'e' (5 clockwise rotations), 1. from 'e' to 'u' (10 rotations counterclockwise), 1. from 'u' to 's' (2 counterclockwise rotations).
```python ch=input() ch=ch.lower() ch="a"+ch l=list() for i in range(97,97+26): a=chr(i) l.append(a) n=0 for i in range(1,len(ch)): x=l.index(ch[i-1]) y=l.index(ch[i]) a=abs(y-x) if a>13: n=n+abs(a-26) else: n=n+a print(n) ```
3
300
A
Array
PROGRAMMING
1,100
[ "brute force", "constructive algorithms", "implementation" ]
null
null
Vitaly has an array of *n* distinct integers. Vitaly wants to divide this array into three non-empty sets so as the following conditions hold: 1. The product of all numbers in the first set is less than zero (<=&lt;<=0). 1. The product of all numbers in the second set is greater than zero (<=&gt;<=0). 1. The product of all numbers in the third set is equal to zero. 1. Each number from the initial array must occur in exactly one set. Help Vitaly. Divide the given array.
The first line of the input contains integer *n* (3<=≤<=*n*<=≤<=100). The second line contains *n* space-separated distinct integers *a*1,<=*a*2,<=...,<=*a**n* (|*a**i*|<=≤<=103) — the array elements.
In the first line print integer *n*1 (*n*1<=&gt;<=0) — the number of elements in the first set. Then print *n*1 numbers — the elements that got to the first set. In the next line print integer *n*2 (*n*2<=&gt;<=0) — the number of elements in the second set. Then print *n*2 numbers — the elements that got to the second set. In the next line print integer *n*3 (*n*3<=&gt;<=0) — the number of elements in the third set. Then print *n*3 numbers — the elements that got to the third set. The printed sets must meet the described conditions. It is guaranteed that the solution exists. If there are several solutions, you are allowed to print any of them.
[ "3\n-1 2 0\n", "4\n-1 -2 -3 0\n" ]
[ "1 -1\n1 2\n1 0\n", "1 -1\n2 -3 -2\n1 0\n" ]
none
500
[ { "input": "3\n-1 2 0", "output": "1 -1\n1 2\n1 0" }, { "input": "4\n-1 -2 -3 0", "output": "1 -1\n2 -3 -2\n1 0" }, { "input": "5\n-1 -2 1 2 0", "output": "1 -1\n2 1 2\n2 0 -2" }, { "input": "100\n-64 -51 -75 -98 74 -26 -1 -8 -99 -76 -53 -80 -43 -22 -100 -62 -34 -5 -65 -81 -18 -91 -92 -16 -23 -95 -9 -19 -44 -46 -79 52 -35 4 -87 -7 -90 -20 -71 -61 -67 -50 -66 -68 -49 -27 -32 -57 -85 -59 -30 -36 -3 -77 86 -25 -94 -56 60 -24 -37 -72 -41 -31 11 -48 28 -38 -42 -39 -33 -70 -84 0 -93 -73 -14 -69 -40 -97 -6 -55 -45 -54 -10 -29 -96 -12 -83 -15 -21 -47 17 -2 -63 -89 88 13 -58 -82", "output": "89 -64 -51 -75 -98 -26 -1 -8 -99 -76 -53 -80 -43 -22 -100 -62 -34 -5 -65 -81 -18 -91 -92 -16 -23 -95 -9 -19 -44 -46 -79 -35 -87 -7 -90 -20 -71 -61 -67 -50 -66 -68 -49 -27 -32 -57 -85 -59 -30 -36 -3 -77 -25 -94 -56 -24 -37 -72 -41 -31 -48 -38 -42 -39 -33 -70 -84 -93 -73 -14 -69 -40 -97 -6 -55 -45 -54 -10 -29 -96 -12 -83 -15 -21 -47 -2 -63 -89 -58 -82\n10 74 52 4 86 60 11 28 17 88 13\n1 0" }, { "input": "100\n3 -66 -17 54 24 -29 76 89 32 -37 93 -16 99 -25 51 78 23 68 -95 59 18 34 -45 77 9 39 -10 19 8 73 -5 60 12 31 0 2 26 40 48 30 52 49 27 4 87 57 85 58 -61 50 83 80 69 67 91 97 -96 11 100 56 82 53 13 -92 -72 70 1 -94 -63 47 21 14 74 7 6 33 55 65 64 -41 81 42 36 28 38 20 43 71 90 -88 22 84 -86 15 75 62 44 35 98 46", "output": "19 -66 -17 -29 -37 -16 -25 -95 -45 -10 -5 -61 -96 -92 -72 -94 -63 -41 -88 -86\n80 3 54 24 76 89 32 93 99 51 78 23 68 59 18 34 77 9 39 19 8 73 60 12 31 2 26 40 48 30 52 49 27 4 87 57 85 58 50 83 80 69 67 91 97 11 100 56 82 53 13 70 1 47 21 14 74 7 6 33 55 65 64 81 42 36 28 38 20 43 71 90 22 84 15 75 62 44 35 98 46\n1 0" }, { "input": "100\n-17 16 -70 32 -60 75 -100 -9 -68 -30 -42 86 -88 -98 -47 -5 58 -14 -94 -73 -80 -51 -66 -85 -53 49 -25 -3 -45 -69 -11 -64 83 74 -65 67 13 -91 81 6 -90 -54 -12 -39 0 -24 -71 -41 -44 57 -93 -20 -92 18 -43 -52 -55 -84 -89 -19 40 -4 -99 -26 -87 -36 -56 -61 -62 37 -95 -28 63 23 35 -82 1 -2 -78 -96 -21 -77 -76 -27 -10 -97 -8 46 -15 -48 -34 -59 -7 -29 50 -33 -72 -79 22 38", "output": "75 -17 -70 -60 -100 -9 -68 -30 -42 -88 -98 -47 -5 -14 -94 -73 -80 -51 -66 -85 -53 -25 -3 -45 -69 -11 -64 -65 -91 -90 -54 -12 -39 -24 -71 -41 -44 -93 -20 -92 -43 -52 -55 -84 -89 -19 -4 -99 -26 -87 -36 -56 -61 -62 -95 -28 -82 -2 -78 -96 -21 -77 -76 -27 -10 -97 -8 -15 -48 -34 -59 -7 -29 -33 -72 -79\n24 16 32 75 86 58 49 83 74 67 13 81 6 57 18 40 37 63 23 35 1 46 50 22 38\n1 0" }, { "input": "100\n-97 -90 61 78 87 -52 -3 65 83 38 30 -60 35 -50 -73 -77 44 -32 -81 17 -67 58 -6 -34 47 -28 71 -45 69 -80 -4 -7 -57 -79 43 -27 -31 29 16 -89 -21 -93 95 -82 74 -5 -70 -20 -18 36 -64 -66 72 53 62 -68 26 15 76 -40 -99 8 59 88 49 -23 9 10 56 -48 -98 0 100 -54 25 94 13 -63 42 39 -1 55 24 -12 75 51 41 84 -96 -85 -2 -92 14 -46 -91 -19 -11 -86 22 -37", "output": "51 -97 -90 -52 -3 -60 -50 -73 -77 -32 -81 -67 -6 -34 -28 -45 -80 -4 -7 -57 -79 -27 -31 -89 -21 -93 -82 -5 -70 -20 -18 -64 -66 -68 -40 -99 -23 -48 -98 -54 -63 -1 -12 -96 -85 -2 -92 -46 -91 -19 -11 -86\n47 61 78 87 65 83 38 30 35 44 17 58 47 71 69 43 29 16 95 74 36 72 53 62 26 15 76 8 59 88 49 9 10 56 100 25 94 13 42 39 55 24 75 51 41 84 14 22\n2 0 -37" }, { "input": "100\n-75 -60 -18 -92 -71 -9 -37 -34 -82 28 -54 93 -83 -76 -58 -88 -17 -97 64 -39 -96 -81 -10 -98 -47 -100 -22 27 14 -33 -19 -99 87 -66 57 -21 -90 -70 -32 -26 24 -77 -74 13 -44 16 -5 -55 -2 -6 -7 -73 -1 -68 -30 -95 -42 69 0 -20 -79 59 -48 -4 -72 -67 -46 62 51 -52 -86 -40 56 -53 85 -35 -8 49 50 65 29 11 -43 -15 -41 -12 -3 -80 -31 -38 -91 -45 -25 78 94 -23 -63 84 89 -61", "output": "73 -75 -60 -18 -92 -71 -9 -37 -34 -82 -54 -83 -76 -58 -88 -17 -97 -39 -96 -81 -10 -98 -47 -100 -22 -33 -19 -99 -66 -21 -90 -70 -32 -26 -77 -74 -44 -5 -55 -2 -6 -7 -73 -1 -68 -30 -95 -42 -20 -79 -48 -4 -72 -67 -46 -52 -86 -40 -53 -35 -8 -43 -15 -41 -12 -3 -80 -31 -38 -91 -45 -25 -23 -63\n25 28 93 64 27 14 87 57 24 13 16 69 59 62 51 56 85 49 50 65 29 11 78 94 84 89\n2 0 -61" }, { "input": "100\n-87 -48 -76 -1 -10 -17 -22 -19 -27 -99 -43 49 38 -20 -45 -64 44 -96 -35 -74 -65 -41 -21 -75 37 -12 -67 0 -3 5 -80 -93 -81 -97 -47 -63 53 -100 95 -79 -83 -90 -32 88 -77 -16 -23 -54 -28 -4 -73 -98 -25 -39 60 -56 -34 -2 -11 -55 -52 -69 -68 -29 -82 -62 -36 -13 -6 -89 8 -72 18 -15 -50 -71 -70 -92 -42 -78 -61 -9 -30 -85 -91 -94 84 -86 -7 -57 -14 40 -33 51 -26 46 59 -31 -58 -66", "output": "83 -87 -48 -76 -1 -10 -17 -22 -19 -27 -99 -43 -20 -45 -64 -96 -35 -74 -65 -41 -21 -75 -12 -67 -3 -80 -93 -81 -97 -47 -63 -100 -79 -83 -90 -32 -77 -16 -23 -54 -28 -4 -73 -98 -25 -39 -56 -34 -2 -11 -55 -52 -69 -68 -29 -82 -62 -36 -13 -6 -89 -72 -15 -50 -71 -70 -92 -42 -78 -61 -9 -30 -85 -91 -94 -86 -7 -57 -14 -33 -26 -31 -58 -66\n16 49 38 44 37 5 53 95 88 60 8 18 84 40 51 46 59\n1 0" }, { "input": "100\n-95 -28 -43 -72 -11 -24 -37 -35 -44 -66 -45 -62 -96 -51 -55 -23 -31 -26 -59 -17 77 -69 -10 -12 -78 -14 -52 -57 -40 -75 4 -98 -6 7 -53 -3 -90 -63 -8 -20 88 -91 -32 -76 -80 -97 -34 -27 -19 0 70 -38 -9 -49 -67 73 -36 2 81 -39 -65 -83 -64 -18 -94 -79 -58 -16 87 -22 -74 -25 -13 -46 -89 -47 5 -15 -54 -99 56 -30 -60 -21 -86 33 -1 -50 -68 -100 -85 -29 92 -48 -61 42 -84 -93 -41 -82", "output": "85 -95 -28 -43 -72 -11 -24 -37 -35 -44 -66 -45 -62 -96 -51 -55 -23 -31 -26 -59 -17 -69 -10 -12 -78 -14 -52 -57 -40 -75 -98 -6 -53 -3 -90 -63 -8 -20 -91 -32 -76 -80 -97 -34 -27 -19 -38 -9 -49 -67 -36 -39 -65 -83 -64 -18 -94 -79 -58 -16 -22 -74 -25 -13 -46 -89 -47 -15 -54 -99 -30 -60 -21 -86 -1 -50 -68 -100 -85 -29 -48 -61 -84 -93 -41 -82\n14 77 4 7 88 70 73 2 81 87 5 56 33 92 42\n1 0" }, { "input": "100\n-12 -41 57 13 83 -36 53 69 -6 86 -75 87 11 -5 -4 -14 -37 -84 70 2 -73 16 31 34 -45 94 -9 26 27 52 -42 46 96 21 32 7 -18 61 66 -51 95 -48 -76 90 80 -40 89 77 78 54 -30 8 88 33 -24 82 -15 19 1 59 44 64 -97 -60 43 56 35 47 39 50 29 28 -17 -67 74 23 85 -68 79 0 65 55 -3 92 -99 72 93 -71 38 -10 -100 -98 81 62 91 -63 -58 49 -20 22", "output": "35 -12 -41 -36 -6 -75 -5 -4 -14 -37 -84 -73 -45 -9 -42 -18 -51 -48 -76 -40 -30 -24 -15 -97 -60 -17 -67 -68 -3 -99 -71 -10 -100 -98 -63 -58\n63 57 13 83 53 69 86 87 11 70 2 16 31 34 94 26 27 52 46 96 21 32 7 61 66 95 90 80 89 77 78 54 8 88 33 82 19 1 59 44 64 43 56 35 47 39 50 29 28 74 23 85 79 65 55 92 72 93 38 81 62 91 49 22\n2 0 -20" }, { "input": "100\n-34 81 85 -96 50 20 54 86 22 10 -19 52 65 44 30 53 63 71 17 98 -92 4 5 -99 89 -23 48 9 7 33 75 2 47 -56 42 70 -68 57 51 83 82 94 91 45 46 25 95 11 -12 62 -31 -87 58 38 67 97 -60 66 73 -28 13 93 29 59 -49 77 37 -43 -27 0 -16 72 15 79 61 78 35 21 3 8 84 1 -32 36 74 -88 26 100 6 14 40 76 18 90 24 69 80 64 55 41", "output": "19 -34 -96 -19 -92 -99 -23 -56 -68 -12 -31 -87 -60 -28 -49 -43 -27 -16 -32 -88\n80 81 85 50 20 54 86 22 10 52 65 44 30 53 63 71 17 98 4 5 89 48 9 7 33 75 2 47 42 70 57 51 83 82 94 91 45 46 25 95 11 62 58 38 67 97 66 73 13 93 29 59 77 37 72 15 79 61 78 35 21 3 8 84 1 36 74 26 100 6 14 40 76 18 90 24 69 80 64 55 41\n1 0" }, { "input": "100\n-1000 -986 -979 -955 -966 -963 -973 -959 -972 -906 -924 -927 -929 -918 -977 -967 -921 -989 -911 -995 -945 -919 -971 -913 -912 -933 -969 -975 -920 -988 -997 -994 -953 -962 -940 -905 -978 -948 -957 -996 0 -976 -949 -931 -903 -985 -923 -993 -944 -909 -938 -946 -934 -992 -904 -980 -954 -943 -917 -968 -991 -956 -902 -942 -999 -998 -908 -928 -930 -914 -922 -936 -960 -937 -939 -926 -965 -925 -951 -910 -907 -970 -990 -984 -964 -987 -916 -947 -982 -950 -974 -915 -932 -958 -981 -941 -961 -983 -952 -935", "output": "97 -1000 -986 -979 -955 -966 -963 -973 -959 -972 -906 -924 -927 -929 -918 -977 -967 -921 -989 -911 -995 -945 -919 -971 -913 -912 -933 -969 -975 -920 -988 -997 -994 -953 -962 -940 -905 -978 -948 -957 -996 -976 -949 -931 -903 -985 -923 -993 -944 -909 -938 -946 -934 -992 -904 -980 -954 -943 -917 -968 -991 -956 -902 -942 -999 -998 -908 -928 -930 -914 -922 -936 -960 -937 -939 -926 -965 -925 -951 -910 -907 -970 -990 -984 -964 -987 -916 -947 -982 -950 -974 -915 -932 -958 -981 -941 -961 -983\n2 -935 -952\n1 0" }, { "input": "99\n-1000 -986 -979 -955 -966 -963 -973 -959 -972 -906 -924 -927 -929 -918 -977 -967 -921 -989 -911 -995 -945 -919 -971 -913 -912 -933 -969 -975 -920 -988 -997 -994 -953 -962 -940 -905 -978 -948 -957 -996 0 -976 -949 -931 -903 -985 -923 -993 -944 -909 -938 -946 -934 -992 -904 -980 -954 -943 -917 -968 -991 -956 -902 -942 -999 -998 -908 -928 -930 -914 -922 -936 -960 -937 -939 -926 -965 -925 -951 -910 -907 -970 -990 -984 -964 -987 -916 -947 -982 -950 -974 -915 -932 -958 -981 -941 -961 -983 -952", "output": "95 -1000 -986 -979 -955 -966 -963 -973 -959 -972 -906 -924 -927 -929 -918 -977 -967 -921 -989 -911 -995 -945 -919 -971 -913 -912 -933 -969 -975 -920 -988 -997 -994 -953 -962 -940 -905 -978 -948 -957 -996 -976 -949 -931 -903 -985 -923 -993 -944 -909 -938 -946 -934 -992 -904 -980 -954 -943 -917 -968 -991 -956 -902 -942 -999 -998 -908 -928 -930 -914 -922 -936 -960 -937 -939 -926 -965 -925 -951 -910 -907 -970 -990 -984 -964 -987 -916 -947 -982 -950 -974 -915 -932 -958 -981 -941\n2 -952 -983\n2 0 -961" }, { "input": "59\n-990 -876 -641 -726 718 -53 803 -954 894 -265 -587 -665 904 349 754 -978 441 794 -768 -428 -569 -476 188 -620 -290 -333 45 705 -201 109 165 446 13 122 714 -562 -15 -86 -960 43 329 578 287 -776 -14 -71 915 886 -259 337 -495 913 -498 -669 -673 818 225 647 0", "output": "29 -990 -876 -641 -726 -53 -954 -265 -587 -665 -978 -768 -428 -569 -476 -620 -290 -333 -201 -562 -15 -86 -960 -776 -14 -71 -259 -495 -498 -669\n28 718 803 894 904 349 754 441 794 188 45 705 109 165 446 13 122 714 43 329 578 287 915 886 337 913 818 225 647\n2 0 -673" }, { "input": "64\n502 885 -631 -906 735 687 642 -29 -696 -165 -524 15 -129 -663 -846 -501 -651 895 -341 -833 -142 33 -847 688 945 -192 -587 -930 603 849 736 676 788 256 863 -509 319 -49 -807 -158 218 -886 -143 -639 118 -156 -291 325 892 -916 -622 -960 -959 -731 -943 436 -535 861 745 589 -159 376 -182 0", "output": "35 -631 -906 -29 -696 -165 -524 -129 -663 -846 -501 -651 -341 -833 -142 -847 -192 -587 -930 -509 -49 -807 -158 -886 -143 -639 -156 -291 -916 -622 -960 -959 -731 -943 -535 -159\n27 502 885 735 687 642 15 895 33 688 945 603 849 736 676 788 256 863 319 218 118 325 892 436 861 745 589 376\n2 0 -182" }, { "input": "5\n-1 -2 -3 -4 0", "output": "1 -1\n2 -4 -3\n2 0 -2" }, { "input": "3\n-101 101 0", "output": "1 -101\n1 101\n1 0" }, { "input": "21\n-100 -200 -300 -400 -500 -600 -700 -800 -900 -1000 0 100 200 300 400 500 600 700 800 900 1000", "output": "9 -100 -200 -300 -400 -500 -600 -700 -800 -900\n10 100 200 300 400 500 600 700 800 900 1000\n2 0 -1000" }, { "input": "4\n0 -1 -2 -3", "output": "1 -1\n2 -3 -2\n1 0" } ]
1,667,602,481
2,147,483,647
Python 3
OK
TESTS
20
92
0
n = int(input()) a = list(map(int,input().split())) negative = [] positive = [] zeros = [] a = sorted(a) if a[-1] > 0: positive.append(a[-1]) negative.append(a[0]) a.pop(0) a.pop(-1) zeros = a else: positive.append(a[0]) positive.append(a[1]) negative.append(a[2]) a.pop(0) a.pop(0) a.pop(0) zeros = a print(len(negative),end= " ") for i in range(len(negative)): if i != len(negative)-1: print(negative[i], end=" ") else: print(negative[i]) print(len(positive),end= " ") for i in range(len(positive)): if i != len(positive)-1: print(positive[i], end=" ") else: print(positive[i]) print(len(zeros),end= " ") for i in range(len(zeros)): if i != len(zeros)-1: print(zeros[i], end=" ") else: print(zeros[i])
Title: Array Time Limit: None seconds Memory Limit: None megabytes Problem Description: Vitaly has an array of *n* distinct integers. Vitaly wants to divide this array into three non-empty sets so as the following conditions hold: 1. The product of all numbers in the first set is less than zero (<=&lt;<=0). 1. The product of all numbers in the second set is greater than zero (<=&gt;<=0). 1. The product of all numbers in the third set is equal to zero. 1. Each number from the initial array must occur in exactly one set. Help Vitaly. Divide the given array. Input Specification: The first line of the input contains integer *n* (3<=≤<=*n*<=≤<=100). The second line contains *n* space-separated distinct integers *a*1,<=*a*2,<=...,<=*a**n* (|*a**i*|<=≤<=103) — the array elements. Output Specification: In the first line print integer *n*1 (*n*1<=&gt;<=0) — the number of elements in the first set. Then print *n*1 numbers — the elements that got to the first set. In the next line print integer *n*2 (*n*2<=&gt;<=0) — the number of elements in the second set. Then print *n*2 numbers — the elements that got to the second set. In the next line print integer *n*3 (*n*3<=&gt;<=0) — the number of elements in the third set. Then print *n*3 numbers — the elements that got to the third set. The printed sets must meet the described conditions. It is guaranteed that the solution exists. If there are several solutions, you are allowed to print any of them. Demo Input: ['3\n-1 2 0\n', '4\n-1 -2 -3 0\n'] Demo Output: ['1 -1\n1 2\n1 0\n', '1 -1\n2 -3 -2\n1 0\n'] Note: none
```python n = int(input()) a = list(map(int,input().split())) negative = [] positive = [] zeros = [] a = sorted(a) if a[-1] > 0: positive.append(a[-1]) negative.append(a[0]) a.pop(0) a.pop(-1) zeros = a else: positive.append(a[0]) positive.append(a[1]) negative.append(a[2]) a.pop(0) a.pop(0) a.pop(0) zeros = a print(len(negative),end= " ") for i in range(len(negative)): if i != len(negative)-1: print(negative[i], end=" ") else: print(negative[i]) print(len(positive),end= " ") for i in range(len(positive)): if i != len(positive)-1: print(positive[i], end=" ") else: print(positive[i]) print(len(zeros),end= " ") for i in range(len(zeros)): if i != len(zeros)-1: print(zeros[i], end=" ") else: print(zeros[i]) ```
3
633
A
Ebony and Ivory
PROGRAMMING
1,100
[ "brute force", "math", "number theory" ]
null
null
Dante is engaged in a fight with "The Savior". Before he can fight it with his sword, he needs to break its shields. He has two guns, Ebony and Ivory, each of them is able to perform any non-negative number of shots. For every bullet that hits the shield, Ebony deals *a* units of damage while Ivory deals *b* units of damage. In order to break the shield Dante has to deal exactly *c* units of damage. Find out if this is possible.
The first line of the input contains three integers *a*, *b*, *c* (1<=≤<=*a*,<=*b*<=≤<=100,<=1<=≤<=*c*<=≤<=10<=000) — the number of units of damage dealt by Ebony gun and Ivory gun, and the total number of damage required to break the shield, respectively.
Print "Yes" (without quotes) if Dante can deal exactly *c* damage to the shield and "No" (without quotes) otherwise.
[ "4 6 15\n", "3 2 7\n", "6 11 6\n" ]
[ "No\n", "Yes\n", "Yes\n" ]
In the second sample, Dante can fire 1 bullet from Ebony and 2 from Ivory to deal exactly 1·3 + 2·2 = 7 damage. In the third sample, Dante can fire 1 bullet from ebony and no bullets from ivory to do 1·6 + 0·11 = 6 damage.
250
[ { "input": "4 6 15", "output": "No" }, { "input": "3 2 7", "output": "Yes" }, { "input": "6 11 6", "output": "Yes" }, { "input": "3 12 15", "output": "Yes" }, { "input": "5 5 10", "output": "Yes" }, { "input": "6 6 7", "output": "No" }, { "input": "1 1 20", "output": "Yes" }, { "input": "12 14 19", "output": "No" }, { "input": "15 12 26", "output": "No" }, { "input": "2 4 8", "output": "Yes" }, { "input": "4 5 30", "output": "Yes" }, { "input": "4 5 48", "output": "Yes" }, { "input": "2 17 105", "output": "Yes" }, { "input": "10 25 282", "output": "No" }, { "input": "6 34 323", "output": "No" }, { "input": "2 47 464", "output": "Yes" }, { "input": "4 53 113", "output": "Yes" }, { "input": "6 64 546", "output": "Yes" }, { "input": "1 78 725", "output": "Yes" }, { "input": "1 84 811", "output": "Yes" }, { "input": "3 100 441", "output": "Yes" }, { "input": "20 5 57", "output": "No" }, { "input": "14 19 143", "output": "No" }, { "input": "17 23 248", "output": "No" }, { "input": "11 34 383", "output": "Yes" }, { "input": "20 47 568", "output": "Yes" }, { "input": "16 58 410", "output": "Yes" }, { "input": "11 70 1199", "output": "Yes" }, { "input": "16 78 712", "output": "Yes" }, { "input": "20 84 562", "output": "No" }, { "input": "19 100 836", "output": "Yes" }, { "input": "23 10 58", "output": "No" }, { "input": "25 17 448", "output": "Yes" }, { "input": "22 24 866", "output": "Yes" }, { "input": "24 35 67", "output": "No" }, { "input": "29 47 264", "output": "Yes" }, { "input": "23 56 45", "output": "No" }, { "input": "25 66 1183", "output": "Yes" }, { "input": "21 71 657", "output": "Yes" }, { "input": "29 81 629", "output": "No" }, { "input": "23 95 2226", "output": "Yes" }, { "input": "32 4 62", "output": "No" }, { "input": "37 15 789", "output": "Yes" }, { "input": "39 24 999", "output": "Yes" }, { "input": "38 32 865", "output": "No" }, { "input": "32 50 205", "output": "No" }, { "input": "31 57 1362", "output": "Yes" }, { "input": "38 68 1870", "output": "Yes" }, { "input": "36 76 549", "output": "No" }, { "input": "35 84 1257", "output": "No" }, { "input": "39 92 2753", "output": "Yes" }, { "input": "44 1 287", "output": "Yes" }, { "input": "42 12 830", "output": "No" }, { "input": "42 27 9", "output": "No" }, { "input": "49 40 1422", "output": "No" }, { "input": "44 42 2005", "output": "No" }, { "input": "50 55 2479", "output": "No" }, { "input": "48 65 917", "output": "No" }, { "input": "45 78 152", "output": "No" }, { "input": "43 90 4096", "output": "Yes" }, { "input": "43 94 4316", "output": "Yes" }, { "input": "60 7 526", "output": "Yes" }, { "input": "53 11 735", "output": "Yes" }, { "input": "52 27 609", "output": "Yes" }, { "input": "57 32 992", "output": "Yes" }, { "input": "52 49 421", "output": "No" }, { "input": "57 52 2634", "output": "Yes" }, { "input": "54 67 3181", "output": "Yes" }, { "input": "52 73 638", "output": "No" }, { "input": "57 84 3470", "output": "No" }, { "input": "52 100 5582", "output": "No" }, { "input": "62 1 501", "output": "Yes" }, { "input": "63 17 858", "output": "Yes" }, { "input": "70 24 1784", "output": "Yes" }, { "input": "65 32 1391", "output": "Yes" }, { "input": "62 50 2775", "output": "No" }, { "input": "62 58 88", "output": "No" }, { "input": "66 68 3112", "output": "Yes" }, { "input": "61 71 1643", "output": "No" }, { "input": "69 81 3880", "output": "No" }, { "input": "63 100 1960", "output": "Yes" }, { "input": "73 6 431", "output": "Yes" }, { "input": "75 19 736", "output": "Yes" }, { "input": "78 25 247", "output": "No" }, { "input": "79 36 2854", "output": "Yes" }, { "input": "80 43 1864", "output": "Yes" }, { "input": "76 55 2196", "output": "Yes" }, { "input": "76 69 4122", "output": "Yes" }, { "input": "76 76 4905", "output": "No" }, { "input": "75 89 3056", "output": "Yes" }, { "input": "73 100 3111", "output": "Yes" }, { "input": "84 9 530", "output": "No" }, { "input": "82 18 633", "output": "No" }, { "input": "85 29 2533", "output": "Yes" }, { "input": "89 38 2879", "output": "Yes" }, { "input": "89 49 2200", "output": "Yes" }, { "input": "88 60 4140", "output": "Yes" }, { "input": "82 68 1299", "output": "No" }, { "input": "90 76 2207", "output": "No" }, { "input": "83 84 4923", "output": "Yes" }, { "input": "89 99 7969", "output": "Yes" }, { "input": "94 9 168", "output": "No" }, { "input": "91 20 1009", "output": "No" }, { "input": "93 23 2872", "output": "Yes" }, { "input": "97 31 3761", "output": "Yes" }, { "input": "99 46 1341", "output": "Yes" }, { "input": "98 51 2845", "output": "No" }, { "input": "93 66 3412", "output": "No" }, { "input": "95 76 3724", "output": "Yes" }, { "input": "91 87 6237", "output": "Yes" }, { "input": "98 97 7886", "output": "Yes" }, { "input": "12 17 15", "output": "No" }, { "input": "93 94 95", "output": "No" }, { "input": "27 43 27", "output": "Yes" }, { "input": "17 43 68", "output": "Yes" }, { "input": "44 12 12", "output": "Yes" }, { "input": "44 50 150", "output": "Yes" }, { "input": "1 1 10000", "output": "Yes" }, { "input": "2 3 10000", "output": "Yes" }, { "input": "100 1 10", "output": "Yes" }, { "input": "3 2 1", "output": "No" }, { "input": "1 1 1", "output": "Yes" }, { "input": "9 9 10000", "output": "No" }, { "input": "2 3 9995", "output": "Yes" }, { "input": "3 5 4", "output": "No" }, { "input": "99 98 100", "output": "No" }, { "input": "6 10 2", "output": "No" }, { "input": "1 6 5", "output": "Yes" }, { "input": "1 4 3", "output": "Yes" }, { "input": "3 2 3", "output": "Yes" }, { "input": "1 7 6", "output": "Yes" }, { "input": "2 3 9871", "output": "Yes" }, { "input": "10 5 5", "output": "Yes" }, { "input": "10 8 2", "output": "No" } ]
1,645,892,532
2,147,483,647
PyPy 3-64
WRONG_ANSWER
TESTS
10
62
512,000
from math import gcd def bezout(a, b): px, py = 1, 0 x, y = 0, 1 while b != 0: a, (q, b) = b, divmod(a, b) px, x = x, px - q * x py, y = y, py - q * y return a, px, py a,b,c = [int(d) for d in input().split()] if c%gcd(a,b) != 0: # pas multiple du pgcd ça marche pas print("No") else: a,px,py = bezout(a,b) if (px < 0 and py > 0) or (px > 0 and py < 0) : # même signe c'est bon x = px*c y = py*c k = (y//a) if (y//a < y/a): k += 1 if x - k*b < 0: print("No") else: print("Yes") else: print("Yes")
Title: Ebony and Ivory Time Limit: None seconds Memory Limit: None megabytes Problem Description: Dante is engaged in a fight with "The Savior". Before he can fight it with his sword, he needs to break its shields. He has two guns, Ebony and Ivory, each of them is able to perform any non-negative number of shots. For every bullet that hits the shield, Ebony deals *a* units of damage while Ivory deals *b* units of damage. In order to break the shield Dante has to deal exactly *c* units of damage. Find out if this is possible. Input Specification: The first line of the input contains three integers *a*, *b*, *c* (1<=≤<=*a*,<=*b*<=≤<=100,<=1<=≤<=*c*<=≤<=10<=000) — the number of units of damage dealt by Ebony gun and Ivory gun, and the total number of damage required to break the shield, respectively. Output Specification: Print "Yes" (without quotes) if Dante can deal exactly *c* damage to the shield and "No" (without quotes) otherwise. Demo Input: ['4 6 15\n', '3 2 7\n', '6 11 6\n'] Demo Output: ['No\n', 'Yes\n', 'Yes\n'] Note: In the second sample, Dante can fire 1 bullet from Ebony and 2 from Ivory to deal exactly 1·3 + 2·2 = 7 damage. In the third sample, Dante can fire 1 bullet from ebony and no bullets from ivory to do 1·6 + 0·11 = 6 damage.
```python from math import gcd def bezout(a, b): px, py = 1, 0 x, y = 0, 1 while b != 0: a, (q, b) = b, divmod(a, b) px, x = x, px - q * x py, y = y, py - q * y return a, px, py a,b,c = [int(d) for d in input().split()] if c%gcd(a,b) != 0: # pas multiple du pgcd ça marche pas print("No") else: a,px,py = bezout(a,b) if (px < 0 and py > 0) or (px > 0 and py < 0) : # même signe c'est bon x = px*c y = py*c k = (y//a) if (y//a < y/a): k += 1 if x - k*b < 0: print("No") else: print("Yes") else: print("Yes") ```
0
81
B
Sequence Formatting
PROGRAMMING
1,700
[ "implementation", "strings" ]
B. Sequence Formatting
2
256
Polycarp is very careful. He even types numeric sequences carefully, unlike his classmates. If he sees a sequence without a space after the comma, with two spaces in a row, or when something else does not look neat, he rushes to correct it. For example, number sequence written like "1,2 ,3,...,   10" will be corrected to "1, 2, 3, ..., 10". In this task you are given a string *s*, which is composed by a concatination of terms, each of which may be: - a positive integer of an arbitrary length (leading zeroes are not allowed), - a "comma" symbol (","), - a "space" symbol (" "), - "three dots" ("...", that is, exactly three points written one after another, also known as suspension points). Polycarp wants to add and remove spaces in the string *s* to ensure the following: - each comma is followed by exactly one space (if the comma is the last character in the string, this rule does not apply to it), - each "three dots" term is preceded by exactly one space (if the dots are at the beginning of the string, this rule does not apply to the term), - if two consecutive numbers were separated by spaces only (one or more), then exactly one of them should be left, - there should not be other spaces. Automate Polycarp's work and write a program that will process the given string *s*.
The input data contains a single string *s*. Its length is from 1 to 255 characters. The string *s* does not begin and end with a space. Its content matches the description given above.
Print the string *s* after it is processed. Your program's output should be exactly the same as the expected answer. It is permissible to end output line with a line-break character, and without it.
[ "1,2 ,3,..., 10\n", "1,,,4...5......6\n", "...,1,2,3,...\n" ]
[ "1, 2, 3, ..., 10\n", "1, , , 4 ...5 ... ...6\n", "..., 1, 2, 3, ...\n" ]
none
1,000
[ { "input": "1,2 ,3,..., 10", "output": "1, 2, 3, ..., 10" }, { "input": "1,,,4...5......6", "output": "1, , , 4 ...5 ... ...6" }, { "input": ",,,,,,,,,,,,,", "output": ", , , , , , , , , , , , ," }, { "input": "123456789", "output": "123456789" }, { "input": ",", "output": "," }, { "input": "1 4 5 6 7 999 1 1 1 2 311111111111111111111111111111111111111111", "output": "1 4 5 6 7 999 1 1 1 2 311111111111111111111111111111111111111111" }, { "input": "1,2,,,,,,,,,5566", "output": "1, 2, , , , , , , , , 5566" }, { "input": "...,", "output": "...," }, { "input": ",,", "output": ", ," }, { "input": ",...,", "output": ", ...," }, { "input": "1...10", "output": "1 ...10" }, { "input": ", ,", "output": ", ," }, { "input": "123563461511123563461511123563461511123563461511123563461511123563461511123563461511123563461511123563461511123563461511123563461511123563461511123563461511123563461511123563461511123563461511123563461511123563461511123563461511123563461511123563461511123", "output": "123563461511123563461511123563461511123563461511123563461511123563461511123563461511123563461511123563461511123563461511123563461511123563461511123563461511123563461511123563461511123563461511123563461511123563461511123563461511123563461511123563461511123" }, { "input": "12 56 511 23 12356346151112 1235634615111235634615 34615111235634615111 1123563461511123563461511123563461511123563461511123563461511123563461511123563461511123563 151112356346151112356346151 1511 3", "output": "12 56 511 23 12356346151112 1235634615111235634615 34615111235634615111 1123563461511123563461511123563461511123563461511123563461511123563461511123563461511123563 151112356346151112356346151 1511 3" }, { "input": "1, 56 511 23 12356,,,151112 1235,34,15,11,356,4615 , , 34615111235,34615111, , 11235634615111235634615111235634615111235634615111235,3461511123563461511123563461511123563 ,151112356346151112356346151 15,, ,3", "output": "1, 56 511 23 12356, , , 151112 1235, 34, 15, 11, 356, 4615, , 34615111235, 34615111, , 11235634615111235634615111235634615111235634615111235, 3461511123563461511123563461511123563, 151112356346151112356346151 15, , , 3" }, { "input": "1,... 511 23 ...56,,,151112 1235,34,15,11,356,4615 , , 34.........,34615111, , ...1123563461511...563461511123563461511123563461511123...461511123563461511123563461511123563 ,151112356346151112356346151 ... 15,, ,3", "output": "1, ...511 23 ...56, , , 151112 1235, 34, 15, 11, 356, 4615, , 34 ... ... ..., 34615111, , ...1123563461511 ...563461511123563461511123563461511123 ...461511123563461511123563461511123563, 151112356346151112356346151 ...15, , , 3" }, { "input": ",,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,", "output": ", , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , ," }, { "input": "..........................................................................................,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,", "output": "... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ..., , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , ," }, { "input": "1...1...1...1...1...1...1...1...1...1...1...1...1...1...1...1...1...1...1...1...1...1...1...1...1...1...1...1...1...1...1...1...1...1...1...1...1...1...1...1...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": "1 ...1 ...1 ...1 ...1 ...1 ...1 ...1 ...1 ...1 ...1 ...1 ...1 ...1 ...1 ...1 ...1 ...1 ...1 ...1 ...1 ...1 ...1 ...1 ...1 ...1 ...1 ...1 ...1 ...1 ...1 ...1 ...1 ...1 ...1 ...1 ...1 ...1 ...1 ...1 ...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": "12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12", "output": "12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12" }, { "input": ",...,,...,,...,,...,,...,,...,,...,,...,,...,,...,,...,,...,,...,,...,,...,,...,,...,,...,,...,,...,,...,,...,,...,,...,,...,,...,,...,,...,,...,,...,,...,,...,,...,,...,,...,,...,,...,,...,,...,,...,,...,,...,,...,,...,,...,,...,,...,,...,,...,,...,,...,", "output": ", ..., , ..., , ..., , ..., , ..., , ..., , ..., , ..., , ..., , ..., , ..., , ..., , ..., , ..., , ..., , ..., , ..., , ..., , ..., , ..., , ..., , ..., , ..., , ..., , ..., , ..., , ..., , ..., , ..., , ..., , ..., , ..., , ..., , ..., , ..., , ..., , ..., , ..., , ..., , ..., , ..., , ..., , ..., , ..., , ..., , ..., , ..., , ..., , ..., , ..., , ...," }, { "input": "1,", "output": "1," }, { "input": ",1", "output": ", 1" }, { "input": "1", "output": "1" }, { "input": "1 1", "output": "1 1" }, { "input": "1 1 1", "output": "1 1 1" }, { "input": "... ,", "output": "...," }, { "input": "......,,,,,...... 1234 1234 1234 , 1234 ... , 1234 ... 1234 ... , 1234", "output": "... ..., , , , , ... ...1234 1234 1234, 1234 ..., 1234 ...1234 ..., 1234" }, { "input": "9999999999999999999999999999999999999999999999999999999999, 1", "output": "9999999999999999999999999999999999999999999999999999999999, 1" }, { "input": "5555555555555555555 6666 77777777 8888888888888 ,,...,55,5...55...,.........5 , , ... , 5 5 , 5 ... 5 5 ... , ... ... ... 5", "output": "5555555555555555555 6666 77777777 8888888888888, , ..., 55, 5 ...55 ..., ... ... ...5, , ..., 5 5, 5 ...5 5 ..., ... ... ...5" }, { "input": "...5", "output": "...5" }, { "input": "1,2 4,78 799,4...5 3......6,", "output": "1, 2 4, 78 799, 4 ...5 3 ... ...6," } ]
1,616,038,484
2,147,483,647
PyPy 3
WRONG_ANSWER
TESTS
3
184
0
def ip():return map(int,input().split()) def sp():return map(str,input().split(',')) def li():return list(sp()) s=li() #print(s) st=[] for x in s:st.append((list(map(str,x.split())))) #print(st) ans='' for x in st: if x==[]:ans+=', ' else: for i in x: ans+=i+', ' #print(ans) answer='' i=0 k=len(ans) while i<k: if ans[i:i+3]=='...' and ans[i+3]!=',': ans=ans[:i:]+' ...'+ans[i+3:] i=i+3 k=len(ans) i=i+1 print(ans[:len(ans)-2:])
Title: Sequence Formatting Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: Polycarp is very careful. He even types numeric sequences carefully, unlike his classmates. If he sees a sequence without a space after the comma, with two spaces in a row, or when something else does not look neat, he rushes to correct it. For example, number sequence written like "1,2 ,3,...,   10" will be corrected to "1, 2, 3, ..., 10". In this task you are given a string *s*, which is composed by a concatination of terms, each of which may be: - a positive integer of an arbitrary length (leading zeroes are not allowed), - a "comma" symbol (","), - a "space" symbol (" "), - "three dots" ("...", that is, exactly three points written one after another, also known as suspension points). Polycarp wants to add and remove spaces in the string *s* to ensure the following: - each comma is followed by exactly one space (if the comma is the last character in the string, this rule does not apply to it), - each "three dots" term is preceded by exactly one space (if the dots are at the beginning of the string, this rule does not apply to the term), - if two consecutive numbers were separated by spaces only (one or more), then exactly one of them should be left, - there should not be other spaces. Automate Polycarp's work and write a program that will process the given string *s*. Input Specification: The input data contains a single string *s*. Its length is from 1 to 255 characters. The string *s* does not begin and end with a space. Its content matches the description given above. Output Specification: Print the string *s* after it is processed. Your program's output should be exactly the same as the expected answer. It is permissible to end output line with a line-break character, and without it. Demo Input: ['1,2 ,3,..., 10\n', '1,,,4...5......6\n', '...,1,2,3,...\n'] Demo Output: ['1, 2, 3, ..., 10\n', '1, , , 4 ...5 ... ...6\n', '..., 1, 2, 3, ...\n'] Note: none
```python def ip():return map(int,input().split()) def sp():return map(str,input().split(',')) def li():return list(sp()) s=li() #print(s) st=[] for x in s:st.append((list(map(str,x.split())))) #print(st) ans='' for x in st: if x==[]:ans+=', ' else: for i in x: ans+=i+', ' #print(ans) answer='' i=0 k=len(ans) while i<k: if ans[i:i+3]=='...' and ans[i+3]!=',': ans=ans[:i:]+' ...'+ans[i+3:] i=i+3 k=len(ans) i=i+1 print(ans[:len(ans)-2:]) ```
0
509
A
Maximum in Table
PROGRAMMING
800
[ "brute force", "implementation" ]
null
null
An *n*<=×<=*n* table *a* is defined as follows: - The first row and the first column contain ones, that is: *a**i*,<=1<==<=*a*1,<=*i*<==<=1 for all *i*<==<=1,<=2,<=...,<=*n*. - Each of the remaining numbers in the table is equal to the sum of the number above it and the number to the left of it. In other words, the remaining elements are defined by the formula *a**i*,<=*j*<==<=*a**i*<=-<=1,<=*j*<=+<=*a**i*,<=*j*<=-<=1. These conditions define all the values in the table. You are given a number *n*. You need to determine the maximum value in the *n*<=×<=*n* table defined by the rules above.
The only line of input contains a positive integer *n* (1<=≤<=*n*<=≤<=10) — the number of rows and columns of the table.
Print a single line containing a positive integer *m* — the maximum value in the table.
[ "1\n", "5\n" ]
[ "1", "70" ]
In the second test the rows of the table look as follows:
0
[ { "input": "1", "output": "1" }, { "input": "5", "output": "70" }, { "input": "2", "output": "2" }, { "input": "3", "output": "6" }, { "input": "4", "output": "20" }, { "input": "6", "output": "252" }, { "input": "7", "output": "924" }, { "input": "9", "output": "12870" }, { "input": "10", "output": "48620" }, { "input": "8", "output": "3432" } ]
1,623,078,666
2,147,483,647
PyPy 3
OK
TESTS
10
155
0
mang = [1,2,6,20,70,252,924,3432,12870,48620] n = int(input()) print(mang[n-1])
Title: Maximum in Table Time Limit: None seconds Memory Limit: None megabytes Problem Description: An *n*<=×<=*n* table *a* is defined as follows: - The first row and the first column contain ones, that is: *a**i*,<=1<==<=*a*1,<=*i*<==<=1 for all *i*<==<=1,<=2,<=...,<=*n*. - Each of the remaining numbers in the table is equal to the sum of the number above it and the number to the left of it. In other words, the remaining elements are defined by the formula *a**i*,<=*j*<==<=*a**i*<=-<=1,<=*j*<=+<=*a**i*,<=*j*<=-<=1. These conditions define all the values in the table. You are given a number *n*. You need to determine the maximum value in the *n*<=×<=*n* table defined by the rules above. Input Specification: The only line of input contains a positive integer *n* (1<=≤<=*n*<=≤<=10) — the number of rows and columns of the table. Output Specification: Print a single line containing a positive integer *m* — the maximum value in the table. Demo Input: ['1\n', '5\n'] Demo Output: ['1', '70'] Note: In the second test the rows of the table look as follows:
```python mang = [1,2,6,20,70,252,924,3432,12870,48620] n = int(input()) print(mang[n-1]) ```
3
805
A
Fake NP
PROGRAMMING
1,000
[ "greedy", "math" ]
null
null
Tavak and Seyyed are good friends. Seyyed is very funny and he told Tavak to solve the following problem instead of longest-path. You are given *l* and *r*. For all integers from *l* to *r*, inclusive, we wrote down all of their integer divisors except 1. Find the integer that we wrote down the maximum number of times. Solve the problem to show that it's not a NP problem.
The first line contains two integers *l* and *r* (2<=≤<=*l*<=≤<=*r*<=≤<=109).
Print single integer, the integer that appears maximum number of times in the divisors. If there are multiple answers, print any of them.
[ "19 29\n", "3 6\n" ]
[ "2\n", "3\n" ]
Definition of a divisor: [https://www.mathsisfun.com/definitions/divisor-of-an-integer-.html](https://www.mathsisfun.com/definitions/divisor-of-an-integer-.html) The first example: from 19 to 29 these numbers are divisible by 2: {20, 22, 24, 26, 28}. The second example: from 3 to 6 these numbers are divisible by 3: {3, 6}.
500
[ { "input": "19 29", "output": "2" }, { "input": "3 6", "output": "2" }, { "input": "39 91", "output": "2" }, { "input": "76 134", "output": "2" }, { "input": "93 95", "output": "2" }, { "input": "17 35", "output": "2" }, { "input": "94 95", "output": "2" }, { "input": "51 52", "output": "2" }, { "input": "47 52", "output": "2" }, { "input": "38 98", "output": "2" }, { "input": "30 37", "output": "2" }, { "input": "56 92", "output": "2" }, { "input": "900000000 1000000000", "output": "2" }, { "input": "37622224 162971117", "output": "2" }, { "input": "760632746 850720703", "output": "2" }, { "input": "908580370 968054552", "output": "2" }, { "input": "951594860 953554446", "output": "2" }, { "input": "347877978 913527175", "output": "2" }, { "input": "620769961 988145114", "output": "2" }, { "input": "820844234 892579936", "output": "2" }, { "input": "741254764 741254768", "output": "2" }, { "input": "80270976 80270977", "output": "2" }, { "input": "392602363 392602367", "output": "2" }, { "input": "519002744 519002744", "output": "519002744" }, { "input": "331900277 331900277", "output": "331900277" }, { "input": "419873015 419873018", "output": "2" }, { "input": "349533413 349533413", "output": "349533413" }, { "input": "28829775 28829776", "output": "2" }, { "input": "568814539 568814539", "output": "568814539" }, { "input": "720270740 720270743", "output": "2" }, { "input": "871232720 871232722", "output": "2" }, { "input": "305693653 305693653", "output": "305693653" }, { "input": "634097178 634097179", "output": "2" }, { "input": "450868287 450868290", "output": "2" }, { "input": "252662256 252662260", "output": "2" }, { "input": "575062045 575062049", "output": "2" }, { "input": "273072892 273072894", "output": "2" }, { "input": "770439256 770439256", "output": "770439256" }, { "input": "2 1000000000", "output": "2" }, { "input": "6 8", "output": "2" }, { "input": "2 879190747", "output": "2" }, { "input": "5 5", "output": "5" }, { "input": "999999937 999999937", "output": "999999937" }, { "input": "3 3", "output": "3" }, { "input": "5 100", "output": "2" }, { "input": "2 2", "output": "2" }, { "input": "3 18", "output": "2" }, { "input": "7 7", "output": "7" }, { "input": "39916801 39916801", "output": "39916801" }, { "input": "3 8", "output": "2" }, { "input": "13 13", "output": "13" }, { "input": "4 8", "output": "2" }, { "input": "3 12", "output": "2" }, { "input": "6 12", "output": "2" }, { "input": "999999103 999999103", "output": "999999103" }, { "input": "100000007 100000007", "output": "100000007" }, { "input": "3 99", "output": "2" }, { "input": "999999733 999999733", "output": "999999733" }, { "input": "5 10", "output": "2" }, { "input": "982451653 982451653", "output": "982451653" }, { "input": "999900001 1000000000", "output": "2" }, { "input": "999727999 999727999", "output": "999727999" }, { "input": "2 999999999", "output": "2" }, { "input": "242 244", "output": "2" }, { "input": "3 10", "output": "2" }, { "input": "15 27", "output": "2" }, { "input": "998244353 998244353", "output": "998244353" }, { "input": "5 15", "output": "2" }, { "input": "999999797 999999797", "output": "999999797" }, { "input": "2 3", "output": "2" }, { "input": "999999929 999999929", "output": "999999929" }, { "input": "3 111111", "output": "2" }, { "input": "12 18", "output": "2" }, { "input": "479001599 479001599", "output": "479001599" }, { "input": "10000019 10000019", "output": "10000019" }, { "input": "715827883 715827883", "output": "715827883" }, { "input": "999992977 999992977", "output": "999992977" }, { "input": "11 11", "output": "11" }, { "input": "29 29", "output": "29" }, { "input": "1000003 1000003", "output": "1000003" }, { "input": "6 15", "output": "2" }, { "input": "1200007 1200007", "output": "1200007" }, { "input": "3 1000000000", "output": "2" }, { "input": "990000023 990000023", "output": "990000023" }, { "input": "1717 1717", "output": "1717" }, { "input": "141650963 141650963", "output": "141650963" }, { "input": "1002523 1002523", "output": "1002523" }, { "input": "900000011 900000011", "output": "900000011" }, { "input": "104729 104729", "output": "104729" }, { "input": "4 12", "output": "2" }, { "input": "100003 100003", "output": "100003" }, { "input": "17 17", "output": "17" }, { "input": "10 100", "output": "2" } ]
1,561,985,052
2,147,483,647
PyPy 3
RUNTIME_ERROR
TESTS
0
218
2,560,000
n=input() m=input() print(2)
Title: Fake NP Time Limit: None seconds Memory Limit: None megabytes Problem Description: Tavak and Seyyed are good friends. Seyyed is very funny and he told Tavak to solve the following problem instead of longest-path. You are given *l* and *r*. For all integers from *l* to *r*, inclusive, we wrote down all of their integer divisors except 1. Find the integer that we wrote down the maximum number of times. Solve the problem to show that it's not a NP problem. Input Specification: The first line contains two integers *l* and *r* (2<=≤<=*l*<=≤<=*r*<=≤<=109). Output Specification: Print single integer, the integer that appears maximum number of times in the divisors. If there are multiple answers, print any of them. Demo Input: ['19 29\n', '3 6\n'] Demo Output: ['2\n', '3\n'] Note: Definition of a divisor: [https://www.mathsisfun.com/definitions/divisor-of-an-integer-.html](https://www.mathsisfun.com/definitions/divisor-of-an-integer-.html) The first example: from 19 to 29 these numbers are divisible by 2: {20, 22, 24, 26, 28}. The second example: from 3 to 6 these numbers are divisible by 3: {3, 6}.
```python n=input() m=input() print(2) ```
-1
292
B
Network Topology
PROGRAMMING
1,200
[ "graphs", "implementation" ]
null
null
This problem uses a simplified network topology model, please read the problem statement carefully and use it as a formal document as you develop the solution. Polycarpus continues working as a system administrator in a large corporation. The computer network of this corporation consists of *n* computers, some of them are connected by a cable. The computers are indexed by integers from 1 to *n*. It's known that any two computers connected by cable directly or through other computers Polycarpus decided to find out the network's topology. A network topology is the way of describing the network configuration, the scheme that shows the location and the connections of network devices. Polycarpus knows three main network topologies: bus, ring and star. A bus is the topology that represents a shared cable with all computers connected with it. In the ring topology the cable connects each computer only with two other ones. A star is the topology where all computers of a network are connected to the single central node. Let's represent each of these network topologies as a connected non-directed graph. A bus is a connected graph that is the only path, that is, the graph where all nodes are connected with two other ones except for some two nodes that are the beginning and the end of the path. A ring is a connected graph, where all nodes are connected with two other ones. A star is a connected graph, where a single central node is singled out and connected with all other nodes. For clarifications, see the picture. You've got a connected non-directed graph that characterizes the computer network in Polycarpus' corporation. Help him find out, which topology type the given network is. If that is impossible to do, say that the network's topology is unknown.
The first line contains two space-separated integers *n* and *m* (4<=≤<=*n*<=≤<=105; 3<=≤<=*m*<=≤<=105) — the number of nodes and edges in the graph, correspondingly. Next *m* lines contain the description of the graph's edges. The *i*-th line contains a space-separated pair of integers *x**i*, *y**i* (1<=≤<=*x**i*,<=*y**i*<=≤<=*n*) — the numbers of nodes that are connected by the *i*-the edge. It is guaranteed that the given graph is connected. There is at most one edge between any two nodes. No edge connects a node with itself.
In a single line print the network topology name of the given graph. If the answer is the bus, print "bus topology" (without the quotes), if the answer is the ring, print "ring topology" (without the quotes), if the answer is the star, print "star topology" (without the quotes). If no answer fits, print "unknown topology" (without the quotes).
[ "4 3\n1 2\n2 3\n3 4\n", "4 4\n1 2\n2 3\n3 4\n4 1\n", "4 3\n1 2\n1 3\n1 4\n", "4 4\n1 2\n2 3\n3 1\n1 4\n" ]
[ "bus topology\n", "ring topology\n", "star topology\n", "unknown topology\n" ]
none
1,000
[ { "input": "4 3\n1 2\n2 3\n3 4", "output": "bus topology" }, { "input": "4 4\n1 2\n2 3\n3 4\n4 1", "output": "ring topology" }, { "input": "4 3\n1 2\n1 3\n1 4", "output": "star topology" }, { "input": "4 4\n1 2\n2 3\n3 1\n1 4", "output": "unknown topology" }, { "input": "5 4\n1 2\n3 5\n1 4\n5 4", "output": "bus topology" }, { "input": "5 5\n3 4\n5 2\n2 1\n5 4\n3 1", "output": "ring topology" }, { "input": "5 4\n4 2\n5 2\n1 2\n2 3", "output": "star topology" }, { "input": "5 9\n5 3\n4 5\n3 1\n3 2\n2 1\n2 5\n1 5\n1 4\n4 2", "output": "unknown topology" }, { "input": "4 3\n2 4\n1 3\n4 1", "output": "bus topology" }, { "input": "4 4\n2 4\n4 1\n1 3\n2 3", "output": "ring topology" }, { "input": "4 3\n1 2\n2 4\n3 2", "output": "star topology" }, { "input": "4 4\n3 2\n2 4\n4 1\n1 2", "output": "unknown topology" }, { "input": "10 9\n10 6\n3 4\n8 9\n8 4\n6 1\n2 9\n5 1\n7 5\n10 3", "output": "bus topology" }, { "input": "10 10\n1 4\n3 6\n10 7\n5 8\n2 10\n3 4\n7 5\n9 6\n8 1\n2 9", "output": "ring topology" }, { "input": "10 9\n1 4\n4 10\n4 9\n8 4\n4 7\n4 5\n4 2\n4 6\n4 3", "output": "star topology" }, { "input": "10 14\n3 2\n7 2\n6 4\n8 1\n3 9\n5 6\n6 3\n4 1\n2 5\n7 10\n9 5\n7 1\n8 10\n3 4", "output": "unknown topology" }, { "input": "4 4\n1 2\n2 3\n2 4\n3 4", "output": "unknown topology" }, { "input": "5 4\n1 2\n1 3\n1 4\n4 5", "output": "unknown topology" }, { "input": "10 9\n10 1\n10 2\n10 3\n10 4\n10 5\n10 6\n10 7\n10 8\n10 9", "output": "star topology" }, { "input": "6 6\n1 2\n2 3\n3 1\n4 5\n5 6\n6 1", "output": "unknown topology" }, { "input": "6 5\n1 2\n1 3\n1 4\n4 5\n4 6", "output": "unknown topology" }, { "input": "4 4\n1 2\n2 3\n3 4\n4 2", "output": "unknown topology" }, { "input": "4 6\n1 2\n1 3\n1 4\n2 3\n2 4\n3 4", "output": "unknown topology" } ]
1,574,442,335
2,147,483,647
Python 3
OK
TESTS
45
654
716,800
n, m = map(int, input().split()) d = [0]*(n+1) for i in range(m): x, y = map(int, input().split()) d[x] += 1 d[y] += 1 if d.count(1) == 2 and d.count(2) == n-2: print("bus topology") elif d.count(2) == n: print("ring topology") elif d.count(1) == n-1 and d.count(n-1) == 1: print("star topology") else: print("unknown topology")
Title: Network Topology Time Limit: None seconds Memory Limit: None megabytes Problem Description: This problem uses a simplified network topology model, please read the problem statement carefully and use it as a formal document as you develop the solution. Polycarpus continues working as a system administrator in a large corporation. The computer network of this corporation consists of *n* computers, some of them are connected by a cable. The computers are indexed by integers from 1 to *n*. It's known that any two computers connected by cable directly or through other computers Polycarpus decided to find out the network's topology. A network topology is the way of describing the network configuration, the scheme that shows the location and the connections of network devices. Polycarpus knows three main network topologies: bus, ring and star. A bus is the topology that represents a shared cable with all computers connected with it. In the ring topology the cable connects each computer only with two other ones. A star is the topology where all computers of a network are connected to the single central node. Let's represent each of these network topologies as a connected non-directed graph. A bus is a connected graph that is the only path, that is, the graph where all nodes are connected with two other ones except for some two nodes that are the beginning and the end of the path. A ring is a connected graph, where all nodes are connected with two other ones. A star is a connected graph, where a single central node is singled out and connected with all other nodes. For clarifications, see the picture. You've got a connected non-directed graph that characterizes the computer network in Polycarpus' corporation. Help him find out, which topology type the given network is. If that is impossible to do, say that the network's topology is unknown. Input Specification: The first line contains two space-separated integers *n* and *m* (4<=≤<=*n*<=≤<=105; 3<=≤<=*m*<=≤<=105) — the number of nodes and edges in the graph, correspondingly. Next *m* lines contain the description of the graph's edges. The *i*-th line contains a space-separated pair of integers *x**i*, *y**i* (1<=≤<=*x**i*,<=*y**i*<=≤<=*n*) — the numbers of nodes that are connected by the *i*-the edge. It is guaranteed that the given graph is connected. There is at most one edge between any two nodes. No edge connects a node with itself. Output Specification: In a single line print the network topology name of the given graph. If the answer is the bus, print "bus topology" (without the quotes), if the answer is the ring, print "ring topology" (without the quotes), if the answer is the star, print "star topology" (without the quotes). If no answer fits, print "unknown topology" (without the quotes). Demo Input: ['4 3\n1 2\n2 3\n3 4\n', '4 4\n1 2\n2 3\n3 4\n4 1\n', '4 3\n1 2\n1 3\n1 4\n', '4 4\n1 2\n2 3\n3 1\n1 4\n'] Demo Output: ['bus topology\n', 'ring topology\n', 'star topology\n', 'unknown topology\n'] Note: none
```python n, m = map(int, input().split()) d = [0]*(n+1) for i in range(m): x, y = map(int, input().split()) d[x] += 1 d[y] += 1 if d.count(1) == 2 and d.count(2) == n-2: print("bus topology") elif d.count(2) == n: print("ring topology") elif d.count(1) == n-1 and d.count(n-1) == 1: print("star topology") else: print("unknown topology") ```
3
18
C
Stripe
PROGRAMMING
1,200
[ "data structures", "implementation" ]
C. Stripe
2
64
Once Bob took a paper stripe of *n* squares (the height of the stripe is 1 square). In each square he wrote an integer number, possibly negative. He became interested in how many ways exist to cut this stripe into two pieces so that the sum of numbers from one piece is equal to the sum of numbers from the other piece, and each piece contains positive integer amount of squares. Would you help Bob solve this problem?
The first input line contains integer *n* (1<=≤<=*n*<=≤<=105) — amount of squares in the stripe. The second line contains *n* space-separated numbers — they are the numbers written in the squares of the stripe. These numbers are integer and do not exceed 10000 in absolute value.
Output the amount of ways to cut the stripe into two non-empty pieces so that the sum of numbers from one piece is equal to the sum of numbers from the other piece. Don't forget that it's allowed to cut the stripe along the squares' borders only.
[ "9\n1 5 -6 7 9 -16 0 -2 2\n", "3\n1 1 1\n", "2\n0 0\n" ]
[ "3\n", "0\n", "1\n" ]
none
0
[ { "input": "9\n1 5 -6 7 9 -16 0 -2 2", "output": "3" }, { "input": "3\n1 1 1", "output": "0" }, { "input": "2\n0 0", "output": "1" }, { "input": "4\n100 1 10 111", "output": "1" }, { "input": "10\n0 4 -3 0 -2 2 -3 -3 2 5", "output": "3" }, { "input": "10\n0 -1 2 2 -1 1 0 0 0 2", "output": "0" }, { "input": "10\n-1 -1 1 -1 0 1 0 1 1 1", "output": "1" }, { "input": "10\n0 0 0 0 0 0 0 0 0 0", "output": "9" }, { "input": "50\n-4 -3 3 4 -1 0 2 -4 -3 -4 1 4 3 0 4 1 0 -3 4 -3 -2 2 2 1 0 -4 -4 -5 3 2 -1 4 5 -3 -3 4 4 -5 2 -3 4 -5 2 5 -4 4 1 -2 -4 3", "output": "3" }, { "input": "15\n0 4 0 3 -1 4 -2 -2 -4 -4 3 2 4 -1 -3", "output": "0" }, { "input": "10\n3 -1 -3 -1 3 -2 0 3 1 -2", "output": "0" }, { "input": "100\n-4 2 4 4 1 3 -3 -3 2 1 -4 0 0 2 3 -1 -4 -3 4 -2 -3 -3 -3 -1 -2 -3 -1 -4 0 4 0 -1 4 0 -4 -4 4 -4 -2 1 -4 1 -3 -2 3 -4 4 0 -1 3 -1 4 -1 4 -1 3 -3 -3 -2 -2 4 -3 -3 4 -3 -2 -1 0 -2 4 0 -3 -1 -2 -3 1 -4 1 -3 -3 -3 -2 -3 0 1 -2 -2 -4 -3 -1 2 3 -1 1 1 0 3 -3 -1 -2", "output": "1" }, { "input": "100\n-2 -1 1 0 -2 -1 2 2 0 0 2 1 0 2 0 2 1 0 -1 -1 -1 0 -2 -1 2 -1 -2 2 -2 2 -2 -2 2 1 1 1 -2 2 0 0 2 -1 2 2 2 0 -1 -1 -1 1 -2 2 2 2 -2 0 0 -2 0 -2 -2 0 -1 -1 -2 -1 1 2 -2 -1 1 -2 -1 0 -2 2 2 -1 -2 2 0 0 0 1 0 1 2 1 -2 -2 -1 -1 -2 -2 -2 -1 2 2 2 -2", "output": "6" }, { "input": "100\n2 7 6 0 8 -2 0 1 8 -1 7 -4 -1 1 0 3 4 -4 3 7 8 -4 -6 6 4 -2 -5 7 4 6 1 6 3 8 -2 6 -6 -3 0 -1 -7 -8 -2 5 8 6 -2 -2 -5 -4 -7 -3 -5 -3 -3 -1 5 8 4 0 -7 -6 8 -4 -1 7 2 6 6 4 -5 -4 -5 -2 2 -2 -7 -1 5 -8 -6 -2 -5 4 2 8 -6 7 -8 -1 -5 8 6 -3 -1 7 -1 2 -8 -8", "output": "0" }, { "input": "1\n0", "output": "0" }, { "input": "1\n10000", "output": "0" }, { "input": "1\n-10000", "output": "0" } ]
1,587,712,668
2,147,483,647
PyPy 3
TIME_LIMIT_EXCEEDED
TESTS
18
2,000
11,366,400
n=int(input()) ar=list(map(int,input().split(' '))) c=0 for i in range(1,n): if(sum(ar[:i])==sum(ar[i:])): c+=1 print(c)
Title: Stripe Time Limit: 2 seconds Memory Limit: 64 megabytes Problem Description: Once Bob took a paper stripe of *n* squares (the height of the stripe is 1 square). In each square he wrote an integer number, possibly negative. He became interested in how many ways exist to cut this stripe into two pieces so that the sum of numbers from one piece is equal to the sum of numbers from the other piece, and each piece contains positive integer amount of squares. Would you help Bob solve this problem? Input Specification: The first input line contains integer *n* (1<=≤<=*n*<=≤<=105) — amount of squares in the stripe. The second line contains *n* space-separated numbers — they are the numbers written in the squares of the stripe. These numbers are integer and do not exceed 10000 in absolute value. Output Specification: Output the amount of ways to cut the stripe into two non-empty pieces so that the sum of numbers from one piece is equal to the sum of numbers from the other piece. Don't forget that it's allowed to cut the stripe along the squares' borders only. Demo Input: ['9\n1 5 -6 7 9 -16 0 -2 2\n', '3\n1 1 1\n', '2\n0 0\n'] Demo Output: ['3\n', '0\n', '1\n'] Note: none
```python n=int(input()) ar=list(map(int,input().split(' '))) c=0 for i in range(1,n): if(sum(ar[:i])==sum(ar[i:])): c+=1 print(c) ```
0
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,695,701,129
2,147,483,647
Python 3
OK
TESTS
34
62
0
s = [int(x) for x in input().split()] d ={} for i in s: if i in d: d[i] = d[i]+1 else: d[i] = 1 c = 0 for i in d: if d[i] ==2: c = c+1 elif d[i] ==3: c = c+2 elif d[i] ==4: c = c+3 print(c)
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 s = [int(x) for x in input().split()] d ={} for i in s: if i in d: d[i] = d[i]+1 else: d[i] = 1 c = 0 for i in d: if d[i] ==2: c = c+1 elif d[i] ==3: c = c+2 elif d[i] ==4: c = c+3 print(c) ```
3
667
B
Coat of Anticubism
PROGRAMMING
1,100
[ "constructive algorithms", "geometry" ]
null
null
As some of you know, cubism is a trend in art, where the problem of constructing volumetrical shape on a plane with a combination of three-dimensional geometric shapes comes to the fore. A famous sculptor Cicasso, whose self-portrait you can contemplate, hates cubism. He is more impressed by the idea to transmit two-dimensional objects through three-dimensional objects by using his magnificent sculptures. And his new project is connected with this. Cicasso wants to make a coat for the haters of anticubism. To do this, he wants to create a sculpture depicting a well-known geometric primitive — convex polygon. Cicasso prepared for this a few blanks, which are rods with integer lengths, and now he wants to bring them together. The *i*-th rod is a segment of length *l**i*. The sculptor plans to make a convex polygon with a nonzero area, using all rods he has as its sides. Each rod should be used as a side to its full length. It is forbidden to cut, break or bend rods. However, two sides may form a straight angle . Cicasso knows that it is impossible to make a convex polygon with a nonzero area out of the rods with the lengths which he had chosen. Cicasso does not want to leave the unused rods, so the sculptor decides to make another rod-blank with an integer length so that his problem is solvable. Of course, he wants to make it as short as possible, because the materials are expensive, and it is improper deed to spend money for nothing. Help sculptor!
The first line contains an integer *n* (3<=≤<=*n*<=≤<=105) — a number of rod-blanks. The second line contains *n* integers *l**i* (1<=≤<=*l**i*<=≤<=109) — lengths of rods, which Cicasso already has. It is guaranteed that it is impossible to make a polygon with *n* vertices and nonzero area using the rods Cicasso already has.
Print the only integer *z* — the minimum length of the rod, so that after adding it it can be possible to construct convex polygon with (*n*<=+<=1) vertices and nonzero area from all of the rods.
[ "3\n1 2 1\n", "5\n20 4 3 2 1\n" ]
[ "1\n", "11\n" ]
In the first example triangle with sides {1 + 1 = 2, 2, 1} can be formed from a set of lengths {1, 1, 1, 2}. In the second example you can make a triangle with lengths {20, 11, 4 + 3 + 2 + 1 = 10}.
1,000
[ { "input": "3\n1 2 1", "output": "1" }, { "input": "5\n20 4 3 2 1", "output": "11" }, { "input": "7\n77486105 317474713 89523018 332007362 7897847 949616701 54820086", "output": "70407571" }, { "input": "14\n245638694 2941428 4673577 12468 991349408 44735727 14046308 60637707 81525 104620306 88059371 53742651 8489205 3528194", "output": "360142248" }, { "input": "19\n479740 7703374 196076708 180202968 579604 17429 16916 11989886 30832424 6384983 8937497 431 62955 48167457 898566333 29534955 1485775 848444 372839845", "output": "2404943" }, { "input": "35\n306260 278 43508628 54350745 222255 842526 39010821 10627 14916465 3059978 61449 503809 2820 1609513 196062 65695 270869 15079297 2885093 189306 4682268 422616382 1642346 82340 6 2 975464673 1388191 70110665 272855 253160079 1849635 7837751 274070 10394", "output": "34445194" }, { "input": "53\n1014364 40727 75774 243769 314 406417 5272684 14138 10640282 64955 2763 5667043 2121887 204672692 567643 60183 5183 11361359 2792918 199155 174809 16182540 21 392221 19434423 9140891 159733 15438 67903 3816799 616 429181 30392293 413992581 10847741 20771 16366654 1163 414283 156163 55907108 310278 95949614 185865 976650886 197610 87 61264 4586815 107764 26390852 331828 541", "output": "25390787" }, { "input": "3\n1 1 1000000000", "output": "999999999" }, { "input": "10\n1 2 3 4 5 6 7 8 9 1000000000", "output": "999999956" }, { "input": "5\n100000000 100000000 100000000 100000000 500000000", "output": "100000001" }, { "input": "3\n300000000 300000000 600000000", "output": "1" }, { "input": "5\n10 4 3 2 1", "output": "1" }, { "input": "3\n800000000 1 1", "output": "799999999" }, { "input": "3\n1000000000 1 1", "output": "999999999" } ]
1,461,957,375
2,147,483,647
Python 3
OK
TESTS
51
93
7,782,400
import math n = int(input()) l = [int(p) for p in input().strip('\n').split(' ')] a = max(l) b = int(math.ceil(max(l)/2)) c = int(math.floor(max(l)/2)) + 1 temp = -1 * (sum(l) - a - b - c) print(str(temp))
Title: Coat of Anticubism Time Limit: None seconds Memory Limit: None megabytes Problem Description: As some of you know, cubism is a trend in art, where the problem of constructing volumetrical shape on a plane with a combination of three-dimensional geometric shapes comes to the fore. A famous sculptor Cicasso, whose self-portrait you can contemplate, hates cubism. He is more impressed by the idea to transmit two-dimensional objects through three-dimensional objects by using his magnificent sculptures. And his new project is connected with this. Cicasso wants to make a coat for the haters of anticubism. To do this, he wants to create a sculpture depicting a well-known geometric primitive — convex polygon. Cicasso prepared for this a few blanks, which are rods with integer lengths, and now he wants to bring them together. The *i*-th rod is a segment of length *l**i*. The sculptor plans to make a convex polygon with a nonzero area, using all rods he has as its sides. Each rod should be used as a side to its full length. It is forbidden to cut, break or bend rods. However, two sides may form a straight angle . Cicasso knows that it is impossible to make a convex polygon with a nonzero area out of the rods with the lengths which he had chosen. Cicasso does not want to leave the unused rods, so the sculptor decides to make another rod-blank with an integer length so that his problem is solvable. Of course, he wants to make it as short as possible, because the materials are expensive, and it is improper deed to spend money for nothing. Help sculptor! Input Specification: The first line contains an integer *n* (3<=≤<=*n*<=≤<=105) — a number of rod-blanks. The second line contains *n* integers *l**i* (1<=≤<=*l**i*<=≤<=109) — lengths of rods, which Cicasso already has. It is guaranteed that it is impossible to make a polygon with *n* vertices and nonzero area using the rods Cicasso already has. Output Specification: Print the only integer *z* — the minimum length of the rod, so that after adding it it can be possible to construct convex polygon with (*n*<=+<=1) vertices and nonzero area from all of the rods. Demo Input: ['3\n1 2 1\n', '5\n20 4 3 2 1\n'] Demo Output: ['1\n', '11\n'] Note: In the first example triangle with sides {1 + 1 = 2, 2, 1} can be formed from a set of lengths {1, 1, 1, 2}. In the second example you can make a triangle with lengths {20, 11, 4 + 3 + 2 + 1 = 10}.
```python import math n = int(input()) l = [int(p) for p in input().strip('\n').split(' ')] a = max(l) b = int(math.ceil(max(l)/2)) c = int(math.floor(max(l)/2)) + 1 temp = -1 * (sum(l) - a - b - c) print(str(temp)) ```
3
387
B
George and Round
PROGRAMMING
1,200
[ "brute force", "greedy", "two pointers" ]
null
null
George decided to prepare a Codesecrof round, so he has prepared *m* problems for the round. Let's number the problems with integers 1 through *m*. George estimates the *i*-th problem's complexity by integer *b**i*. To make the round good, he needs to put at least *n* problems there. Besides, he needs to have at least one problem with complexity exactly *a*1, at least one with complexity exactly *a*2, ..., and at least one with complexity exactly *a**n*. Of course, the round can also have problems with other complexities. George has a poor imagination. It's easier for him to make some already prepared problem simpler than to come up with a new one and prepare it. George is magnificent at simplifying problems. He can simplify any already prepared problem with complexity *c* to any positive integer complexity *d* (*c*<=≥<=*d*), by changing limits on the input data. However, nothing is so simple. George understood that even if he simplifies some problems, he can run out of problems for a good round. That's why he decided to find out the minimum number of problems he needs to come up with in addition to the *m* he's prepared in order to make a good round. Note that George can come up with a new problem of any complexity.
The first line contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=3000) — the minimal number of problems in a good round and the number of problems George's prepared. The second line contains space-separated integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a*1<=&lt;<=*a*2<=&lt;<=...<=&lt;<=*a**n*<=≤<=106) — the requirements for the complexity of the problems in a good round. The third line contains space-separated integers *b*1,<=*b*2,<=...,<=*b**m* (1<=≤<=*b*1<=≤<=*b*2...<=≤<=*b**m*<=≤<=106) — the complexities of the problems prepared by George.
Print a single integer — the answer to the problem.
[ "3 5\n1 2 3\n1 2 2 3 3\n", "3 5\n1 2 3\n1 1 1 1 1\n", "3 1\n2 3 4\n1\n" ]
[ "0\n", "2\n", "3\n" ]
In the first sample the set of the prepared problems meets the requirements for a good round. In the second sample, it is enough to come up with and prepare two problems with complexities 2 and 3 to get a good round. In the third sample it is very easy to get a good round if come up with and prepare extra problems with complexities: 2, 3, 4.
1,000
[ { "input": "3 5\n1 2 3\n1 2 2 3 3", "output": "0" }, { "input": "3 5\n1 2 3\n1 1 1 1 1", "output": "2" }, { "input": "3 1\n2 3 4\n1", "output": "3" }, { "input": "29 100\n20 32 41 67 72 155 331 382 399 412 465 470 484 511 515 529 616 637 679 715 733 763 826 843 862 903 925 979 989\n15 15 15 17 18 19 19 20 21 21 22 24 25 26 26 27 28 31 32 32 37 38 38 39 39 40 41 42 43 43 45 45 46 47 49 49 50 50 50 51 52 53 53 55 56 57 59 59 59 60 60 62 62 63 63 64 64 64 66 67 69 69 70 70 72 72 73 74 75 76 77 78 80 80 81 81 83 83 83 84 86 86 86 86 87 88 89 91 91 91 92 93 94 94 96 97 97 97 98 98", "output": "24" } ]
1,629,523,675
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
3
46
6,963,200
def find_min_number_problem(round_arr, prepared_arr): i = 0 j = 0 found = 0 while i < len(round_arr) and j < len(prepared_arr): if round_arr[i] == prepared_arr[j]: found += 1 i += 1 j += 1 elif round_arr[i] < prepared_arr[j]: i += 1 else: j += 1 return len(round_arr) - found first_input = input() A = list(map(int, input().split())) B = list(map(int, input().split())) result = find_min_number_problem(A, B) print(result)
Title: George and Round Time Limit: None seconds Memory Limit: None megabytes Problem Description: George decided to prepare a Codesecrof round, so he has prepared *m* problems for the round. Let's number the problems with integers 1 through *m*. George estimates the *i*-th problem's complexity by integer *b**i*. To make the round good, he needs to put at least *n* problems there. Besides, he needs to have at least one problem with complexity exactly *a*1, at least one with complexity exactly *a*2, ..., and at least one with complexity exactly *a**n*. Of course, the round can also have problems with other complexities. George has a poor imagination. It's easier for him to make some already prepared problem simpler than to come up with a new one and prepare it. George is magnificent at simplifying problems. He can simplify any already prepared problem with complexity *c* to any positive integer complexity *d* (*c*<=≥<=*d*), by changing limits on the input data. However, nothing is so simple. George understood that even if he simplifies some problems, he can run out of problems for a good round. That's why he decided to find out the minimum number of problems he needs to come up with in addition to the *m* he's prepared in order to make a good round. Note that George can come up with a new problem of any complexity. Input Specification: The first line contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=3000) — the minimal number of problems in a good round and the number of problems George's prepared. The second line contains space-separated integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a*1<=&lt;<=*a*2<=&lt;<=...<=&lt;<=*a**n*<=≤<=106) — the requirements for the complexity of the problems in a good round. The third line contains space-separated integers *b*1,<=*b*2,<=...,<=*b**m* (1<=≤<=*b*1<=≤<=*b*2...<=≤<=*b**m*<=≤<=106) — the complexities of the problems prepared by George. Output Specification: Print a single integer — the answer to the problem. Demo Input: ['3 5\n1 2 3\n1 2 2 3 3\n', '3 5\n1 2 3\n1 1 1 1 1\n', '3 1\n2 3 4\n1\n'] Demo Output: ['0\n', '2\n', '3\n'] Note: In the first sample the set of the prepared problems meets the requirements for a good round. In the second sample, it is enough to come up with and prepare two problems with complexities 2 and 3 to get a good round. In the third sample it is very easy to get a good round if come up with and prepare extra problems with complexities: 2, 3, 4.
```python def find_min_number_problem(round_arr, prepared_arr): i = 0 j = 0 found = 0 while i < len(round_arr) and j < len(prepared_arr): if round_arr[i] == prepared_arr[j]: found += 1 i += 1 j += 1 elif round_arr[i] < prepared_arr[j]: i += 1 else: j += 1 return len(round_arr) - found first_input = input() A = list(map(int, input().split())) B = list(map(int, input().split())) result = find_min_number_problem(A, B) print(result) ```
0
96
A
Football
PROGRAMMING
900
[ "implementation", "strings" ]
A. Football
2
256
Petya loves football very much. One day, as he was watching a football match, he was writing the players' current positions on a piece of paper. To simplify the situation he depicted it as a string consisting of zeroes and ones. A zero corresponds to players of one team; a one corresponds to players of another team. If there are at least 7 players of some team standing one after another, then the situation is considered dangerous. For example, the situation 00100110111111101 is dangerous and 11110111011101 is not. You are given the current situation. Determine whether it is dangerous or not.
The first input line contains a non-empty string consisting of characters "0" and "1", which represents players. The length of the string does not exceed 100 characters. There's at least one player from each team present on the field.
Print "YES" if the situation is dangerous. Otherwise, print "NO".
[ "001001\n", "1000000001\n" ]
[ "NO\n", "YES\n" ]
none
500
[ { "input": "001001", "output": "NO" }, { "input": "1000000001", "output": "YES" }, { "input": "00100110111111101", "output": "YES" }, { "input": "11110111111111111", "output": "YES" }, { "input": "01", "output": "NO" }, { "input": "10100101", "output": "NO" }, { "input": "1010010100000000010", "output": "YES" }, { "input": "101010101", "output": "NO" }, { "input": "000000000100000000000110101100000", "output": "YES" }, { "input": "100001000000110101100000", "output": "NO" }, { "input": "100001000011010110000", "output": "NO" }, { "input": "010", "output": "NO" }, { "input": "10101011111111111111111111111100", "output": "YES" }, { "input": "1001101100", "output": "NO" }, { "input": "1001101010", "output": "NO" }, { "input": "1111100111", "output": "NO" }, { "input": "00110110001110001111", "output": "NO" }, { "input": "11110001001111110001", "output": "NO" }, { "input": "10001111001011111101", "output": "NO" }, { "input": "10000010100000001000110001010100001001001010011", "output": "YES" }, { "input": "01111011111010111100101100001011001010111110000010", "output": "NO" }, { "input": "00100000100100101110011001011011101110110110010100", "output": "NO" }, { "input": "10110100110001001011110101110010100010000000000100101010111110111110100011", "output": "YES" }, { "input": "00011101010101111001011011001101101011111101000010100000111000011100101011", "output": "NO" }, { "input": "01110000110100110101110100111000101101011101011110110100100111100001110111", "output": "NO" }, { "input": "11110110011000100111100111101101011111110100010101011011111101110110110111", "output": "YES" }, { "input": "100100010101110010001011001110100011100010011110100101100011010001001010001001101111001100", "output": "NO" }, { "input": "111110010001011010010011111100110110001111000010100011011100111101111101110010101111011110000001010", "output": "NO" }, { "input": "111110111100010100000100001010111011101011000111011011011010110010100010000101011111000011010011110", "output": "NO" }, { "input": "1011110110111010110111111010010010100011111011110000011000110010011110111010110100011010100010111000", "output": "NO" }, { "input": "0010100111100010110110000011100111110100111110001010000100111111111010111100101101010101001011010110", "output": "YES" }, { "input": "1111010100010100101011101100101101110011000010100010000001111100010011100101010001101111000001011000", "output": "NO" }, { "input": "0101100011001110001110100111100011010101011000000000110110010010111100101111010111100011101100100101", "output": "YES" }, { "input": "0001101110011101110000000010011111101001101111100001001010110000110001100000010001111011011110001101", "output": "YES" }, { "input": "1000010000100000100010000100001000010000100001000010000100001000010000100001000010000100001000010000", "output": "NO" }, { "input": "1000000000100000000010000000001000000000100000000010000000001000000000100000000010000000001000000000", "output": "YES" }, { "input": "0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001", "output": "YES" }, { "input": "1111111111111111111111111111111111111111011111111111111111111111111111111111111111111111111111111111", "output": "YES" }, { "input": "10100101000", "output": "NO" }, { "input": "11110111011101", "output": "NO" }, { "input": "10000000", "output": "YES" }, { "input": "00000001", "output": "YES" }, { "input": "01111111", "output": "YES" }, { "input": "11111110", "output": "YES" } ]
1,692,586,144
2,147,483,647
Python 3
OK
TESTS
44
92
0
nums = input() lenOfZero = nums.split("1") lenOfOnes = nums.split("0") maximum = 0 for i in lenOfOnes: maximum = max(maximum, len(i)) for i in lenOfZero: maximum = max(maximum, len(i)) if maximum >= 7: print("YES") else: print("NO")
Title: Football Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: Petya loves football very much. One day, as he was watching a football match, he was writing the players' current positions on a piece of paper. To simplify the situation he depicted it as a string consisting of zeroes and ones. A zero corresponds to players of one team; a one corresponds to players of another team. If there are at least 7 players of some team standing one after another, then the situation is considered dangerous. For example, the situation 00100110111111101 is dangerous and 11110111011101 is not. You are given the current situation. Determine whether it is dangerous or not. Input Specification: The first input line contains a non-empty string consisting of characters "0" and "1", which represents players. The length of the string does not exceed 100 characters. There's at least one player from each team present on the field. Output Specification: Print "YES" if the situation is dangerous. Otherwise, print "NO". Demo Input: ['001001\n', '1000000001\n'] Demo Output: ['NO\n', 'YES\n'] Note: none
```python nums = input() lenOfZero = nums.split("1") lenOfOnes = nums.split("0") maximum = 0 for i in lenOfOnes: maximum = max(maximum, len(i)) for i in lenOfZero: maximum = max(maximum, len(i)) if maximum >= 7: print("YES") else: print("NO") ```
3.977
489
C
Given Length and Sum of Digits...
PROGRAMMING
1,400
[ "dp", "greedy", "implementation" ]
null
null
You have a positive integer *m* and a non-negative integer *s*. Your task is to find the smallest and the largest of the numbers that have length *m* and sum of digits *s*. The required numbers should be non-negative integers written in the decimal base without leading zeroes.
The single line of the input contains a pair of integers *m*, *s* (1<=≤<=*m*<=≤<=100,<=0<=≤<=*s*<=≤<=900) — the length and the sum of the digits of the required numbers.
In the output print the pair of the required non-negative integer numbers — first the minimum possible number, then — the maximum possible number. If no numbers satisfying conditions required exist, print the pair of numbers "-1 -1" (without the quotes).
[ "2 15\n", "3 0\n" ]
[ "69 96\n", "-1 -1\n" ]
none
1,500
[ { "input": "2 15", "output": "69 96" }, { "input": "3 0", "output": "-1 -1" }, { "input": "2 1", "output": "10 10" }, { "input": "3 10", "output": "109 910" }, { "input": "100 100", "output": "1000000000000000000000000000000000000000000000000000000000000000000000000000000000000000099999999999 9999999999910000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" }, { "input": "1 900", "output": "-1 -1" }, { "input": "1 9", "output": "9 9" }, { "input": "1 0", "output": "0 0" }, { "input": "1 1", "output": "1 1" }, { "input": "1 2", "output": "2 2" }, { "input": "1 8", "output": "8 8" }, { "input": "1 10", "output": "-1 -1" }, { "input": "1 11", "output": "-1 -1" }, { "input": "2 0", "output": "-1 -1" }, { "input": "2 1", "output": "10 10" }, { "input": "2 2", "output": "11 20" }, { "input": "2 8", "output": "17 80" }, { "input": "2 10", "output": "19 91" }, { "input": "2 11", "output": "29 92" }, { "input": "2 16", "output": "79 97" }, { "input": "2 17", "output": "89 98" }, { "input": "2 18", "output": "99 99" }, { "input": "2 19", "output": "-1 -1" }, { "input": "2 20", "output": "-1 -1" }, { "input": "2 900", "output": "-1 -1" }, { "input": "3 1", "output": "100 100" }, { "input": "3 2", "output": "101 200" }, { "input": "3 3", "output": "102 300" }, { "input": "3 9", "output": "108 900" }, { "input": "3 10", "output": "109 910" }, { "input": "3 20", "output": "299 992" }, { "input": "3 21", "output": "399 993" }, { "input": "3 26", "output": "899 998" }, { "input": "3 27", "output": "999 999" }, { "input": "3 28", "output": "-1 -1" }, { "input": "3 100", "output": "-1 -1" }, { "input": "100 0", "output": "-1 -1" }, { "input": "100 1", "output": "1000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 1000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" }, { "input": "100 2", "output": "1000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001 2000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" }, { "input": "100 9", "output": "1000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000008 9000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" }, { "input": "100 10", "output": "1000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000009 9100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" }, { "input": "100 11", "output": "1000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000019 9200000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" }, { "input": "100 296", "output": "1000000000000000000000000000000000000000000000000000000000000000000799999999999999999999999999999999 9999999999999999999999999999999980000000000000000000000000000000000000000000000000000000000000000000" }, { "input": "100 297", "output": "1000000000000000000000000000000000000000000000000000000000000000000899999999999999999999999999999999 9999999999999999999999999999999990000000000000000000000000000000000000000000000000000000000000000000" }, { "input": "100 298", "output": "1000000000000000000000000000000000000000000000000000000000000000000999999999999999999999999999999999 9999999999999999999999999999999991000000000000000000000000000000000000000000000000000000000000000000" }, { "input": "100 299", "output": "1000000000000000000000000000000000000000000000000000000000000000001999999999999999999999999999999999 9999999999999999999999999999999992000000000000000000000000000000000000000000000000000000000000000000" }, { "input": "100 300", "output": "1000000000000000000000000000000000000000000000000000000000000000002999999999999999999999999999999999 9999999999999999999999999999999993000000000000000000000000000000000000000000000000000000000000000000" }, { "input": "100 301", "output": "1000000000000000000000000000000000000000000000000000000000000000003999999999999999999999999999999999 9999999999999999999999999999999994000000000000000000000000000000000000000000000000000000000000000000" }, { "input": "100 895", "output": "4999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999 9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999994" }, { "input": "100 896", "output": "5999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999 9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999995" }, { "input": "100 897", "output": "6999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999 9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999996" }, { "input": "100 898", "output": "7999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999 9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999997" }, { "input": "100 899", "output": "8999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999 9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999998" }, { "input": "100 900", "output": "9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999 9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999" }, { "input": "99 900", "output": "-1 -1" }, { "input": "99 891", "output": "999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999 999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999" }, { "input": "99 892", "output": "-1 -1" }, { "input": "96 364", "output": "100000000000000000000000000000000000000000000000000000039999999999999999999999999999999999999999 999999999999999999999999999999999999999940000000000000000000000000000000000000000000000000000000" }, { "input": "97 206", "output": "1000000000000000000000000000000000000000000000000000000000000000000000000079999999999999999999999 9999999999999999999999800000000000000000000000000000000000000000000000000000000000000000000000000" }, { "input": "98 250", "output": "10000000000000000000000000000000000000000000000000000000000000000000006999999999999999999999999999 99999999999999999999999999970000000000000000000000000000000000000000000000000000000000000000000000" }, { "input": "99 96", "output": "100000000000000000000000000000000000000000000000000000000000000000000000000000000000000059999999999 999999999960000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" }, { "input": "100 215", "output": "1000000000000000000000000000000000000000000000000000000000000000000000000000799999999999999999999999 9999999999999999999999980000000000000000000000000000000000000000000000000000000000000000000000000000" }, { "input": "5 18", "output": "10089 99000" }, { "input": "2 19", "output": "-1 -1" }, { "input": "3 3", "output": "102 300" } ]
1,689,861,698
2,147,483,647
Python 3
OK
TESTS
65
46
0
def Min(m, s): if s == 0: return 0 if m == 1 else -1 a = [0] * m a[-1] = s - 1 i = len(a) - 1 while a[i] > 9: if i <= 0: return -1 a[i - 1], a[i] = a[i] - 9, 9 i -= 1 a[0] += 1 if a[0] > 9: return -1 return "".join(str(d) for d in a) def Max(m, s): if s == 0: return 0 if m == 1 else -1 a = [0] * m a[0] = s i = 0 while a[i] > 9: if i >= len(a) - 1: return -1 a[i], a[i + 1] = 9, a[i] - 9 i += 1 return "".join(str(d) for d in a) m, s = map(int, input().split()) print(Min(m, s), Max(m, s))
Title: Given Length and Sum of Digits... Time Limit: None seconds Memory Limit: None megabytes Problem Description: You have a positive integer *m* and a non-negative integer *s*. Your task is to find the smallest and the largest of the numbers that have length *m* and sum of digits *s*. The required numbers should be non-negative integers written in the decimal base without leading zeroes. Input Specification: The single line of the input contains a pair of integers *m*, *s* (1<=≤<=*m*<=≤<=100,<=0<=≤<=*s*<=≤<=900) — the length and the sum of the digits of the required numbers. Output Specification: In the output print the pair of the required non-negative integer numbers — first the minimum possible number, then — the maximum possible number. If no numbers satisfying conditions required exist, print the pair of numbers "-1 -1" (without the quotes). Demo Input: ['2 15\n', '3 0\n'] Demo Output: ['69 96\n', '-1 -1\n'] Note: none
```python def Min(m, s): if s == 0: return 0 if m == 1 else -1 a = [0] * m a[-1] = s - 1 i = len(a) - 1 while a[i] > 9: if i <= 0: return -1 a[i - 1], a[i] = a[i] - 9, 9 i -= 1 a[0] += 1 if a[0] > 9: return -1 return "".join(str(d) for d in a) def Max(m, s): if s == 0: return 0 if m == 1 else -1 a = [0] * m a[0] = s i = 0 while a[i] > 9: if i >= len(a) - 1: return -1 a[i], a[i + 1] = 9, a[i] - 9 i += 1 return "".join(str(d) for d in a) m, s = map(int, input().split()) print(Min(m, s), Max(m, s)) ```
3
233
A
Perfect Permutation
PROGRAMMING
800
[ "implementation", "math" ]
null
null
A permutation is a sequence of integers *p*1,<=*p*2,<=...,<=*p**n*, consisting of *n* distinct positive integers, each of them doesn't exceed *n*. Let's denote the *i*-th element of permutation *p* as *p**i*. We'll call number *n* the size of permutation *p*1,<=*p*2,<=...,<=*p**n*. Nickolas adores permutations. He likes some permutations more than the others. He calls such permutations perfect. A perfect permutation is such permutation *p* that for any *i* (1<=≤<=*i*<=≤<=*n*) (*n* is the permutation size) the following equations hold *p**p**i*<==<=*i* and *p**i*<=≠<=*i*. Nickolas asks you to print any perfect permutation of size *n* for the given *n*.
A single line contains a single integer *n* (1<=≤<=*n*<=≤<=100) — the permutation size.
If a perfect permutation of size *n* doesn't exist, print a single integer -1. Otherwise print *n* distinct integers from 1 to *n*, *p*1,<=*p*2,<=...,<=*p**n* — permutation *p*, that is perfect. Separate printed numbers by whitespaces.
[ "1\n", "2\n", "4\n" ]
[ "-1\n", "2 1 \n", "2 1 4 3 \n" ]
none
500
[ { "input": "1", "output": "-1" }, { "input": "2", "output": "2 1 " }, { "input": "4", "output": "2 1 4 3 " }, { "input": "3", "output": "-1" }, { "input": "5", "output": "-1" }, { "input": "6", "output": "2 1 4 3 6 5 " }, { "input": "7", "output": "-1" }, { "input": "20", "output": "2 1 4 3 6 5 8 7 10 9 12 11 14 13 16 15 18 17 20 19 " }, { "input": "8", "output": "2 1 4 3 6 5 8 7 " }, { "input": "9", "output": "-1" }, { "input": "10", "output": "2 1 4 3 6 5 8 7 10 9 " }, { "input": "11", "output": "-1" }, { "input": "21", "output": "-1" }, { "input": "50", "output": "2 1 4 3 6 5 8 7 10 9 12 11 14 13 16 15 18 17 20 19 22 21 24 23 26 25 28 27 30 29 32 31 34 33 36 35 38 37 40 39 42 41 44 43 46 45 48 47 50 49 " }, { "input": "51", "output": "-1" }, { "input": "52", "output": "2 1 4 3 6 5 8 7 10 9 12 11 14 13 16 15 18 17 20 19 22 21 24 23 26 25 28 27 30 29 32 31 34 33 36 35 38 37 40 39 42 41 44 43 46 45 48 47 50 49 52 51 " }, { "input": "84", "output": "2 1 4 3 6 5 8 7 10 9 12 11 14 13 16 15 18 17 20 19 22 21 24 23 26 25 28 27 30 29 32 31 34 33 36 35 38 37 40 39 42 41 44 43 46 45 48 47 50 49 52 51 54 53 56 55 58 57 60 59 62 61 64 63 66 65 68 67 70 69 72 71 74 73 76 75 78 77 80 79 82 81 84 83 " }, { "input": "86", "output": "2 1 4 3 6 5 8 7 10 9 12 11 14 13 16 15 18 17 20 19 22 21 24 23 26 25 28 27 30 29 32 31 34 33 36 35 38 37 40 39 42 41 44 43 46 45 48 47 50 49 52 51 54 53 56 55 58 57 60 59 62 61 64 63 66 65 68 67 70 69 72 71 74 73 76 75 78 77 80 79 82 81 84 83 86 85 " }, { "input": "100", "output": "2 1 4 3 6 5 8 7 10 9 12 11 14 13 16 15 18 17 20 19 22 21 24 23 26 25 28 27 30 29 32 31 34 33 36 35 38 37 40 39 42 41 44 43 46 45 48 47 50 49 52 51 54 53 56 55 58 57 60 59 62 61 64 63 66 65 68 67 70 69 72 71 74 73 76 75 78 77 80 79 82 81 84 83 86 85 88 87 90 89 92 91 94 93 96 95 98 97 100 99 " }, { "input": "98", "output": "2 1 4 3 6 5 8 7 10 9 12 11 14 13 16 15 18 17 20 19 22 21 24 23 26 25 28 27 30 29 32 31 34 33 36 35 38 37 40 39 42 41 44 43 46 45 48 47 50 49 52 51 54 53 56 55 58 57 60 59 62 61 64 63 66 65 68 67 70 69 72 71 74 73 76 75 78 77 80 79 82 81 84 83 86 85 88 87 90 89 92 91 94 93 96 95 98 97 " }, { "input": "96", "output": "2 1 4 3 6 5 8 7 10 9 12 11 14 13 16 15 18 17 20 19 22 21 24 23 26 25 28 27 30 29 32 31 34 33 36 35 38 37 40 39 42 41 44 43 46 45 48 47 50 49 52 51 54 53 56 55 58 57 60 59 62 61 64 63 66 65 68 67 70 69 72 71 74 73 76 75 78 77 80 79 82 81 84 83 86 85 88 87 90 89 92 91 94 93 96 95 " }, { "input": "33", "output": "-1" }, { "input": "34", "output": "2 1 4 3 6 5 8 7 10 9 12 11 14 13 16 15 18 17 20 19 22 21 24 23 26 25 28 27 30 29 32 31 34 33 " }, { "input": "36", "output": "2 1 4 3 6 5 8 7 10 9 12 11 14 13 16 15 18 17 20 19 22 21 24 23 26 25 28 27 30 29 32 31 34 33 36 35 " }, { "input": "38", "output": "2 1 4 3 6 5 8 7 10 9 12 11 14 13 16 15 18 17 20 19 22 21 24 23 26 25 28 27 30 29 32 31 34 33 36 35 38 37 " }, { "input": "40", "output": "2 1 4 3 6 5 8 7 10 9 12 11 14 13 16 15 18 17 20 19 22 21 24 23 26 25 28 27 30 29 32 31 34 33 36 35 38 37 40 39 " }, { "input": "42", "output": "2 1 4 3 6 5 8 7 10 9 12 11 14 13 16 15 18 17 20 19 22 21 24 23 26 25 28 27 30 29 32 31 34 33 36 35 38 37 40 39 42 41 " }, { "input": "44", "output": "2 1 4 3 6 5 8 7 10 9 12 11 14 13 16 15 18 17 20 19 22 21 24 23 26 25 28 27 30 29 32 31 34 33 36 35 38 37 40 39 42 41 44 43 " }, { "input": "46", "output": "2 1 4 3 6 5 8 7 10 9 12 11 14 13 16 15 18 17 20 19 22 21 24 23 26 25 28 27 30 29 32 31 34 33 36 35 38 37 40 39 42 41 44 43 46 45 " }, { "input": "48", "output": "2 1 4 3 6 5 8 7 10 9 12 11 14 13 16 15 18 17 20 19 22 21 24 23 26 25 28 27 30 29 32 31 34 33 36 35 38 37 40 39 42 41 44 43 46 45 48 47 " } ]
1,637,746,197
2,147,483,647
PyPy 3-64
RUNTIME_ERROR
TESTS
0
154
3,379,200
n=int(input()) if n%2==0: print(-1) else: a=[i for i in range(1,n+1)] i=0 while i<n: a[i],a[i+1]=a[i+1],a[i] i+=2 for i in a: print(i)
Title: Perfect Permutation Time Limit: None seconds Memory Limit: None megabytes Problem Description: A permutation is a sequence of integers *p*1,<=*p*2,<=...,<=*p**n*, consisting of *n* distinct positive integers, each of them doesn't exceed *n*. Let's denote the *i*-th element of permutation *p* as *p**i*. We'll call number *n* the size of permutation *p*1,<=*p*2,<=...,<=*p**n*. Nickolas adores permutations. He likes some permutations more than the others. He calls such permutations perfect. A perfect permutation is such permutation *p* that for any *i* (1<=≤<=*i*<=≤<=*n*) (*n* is the permutation size) the following equations hold *p**p**i*<==<=*i* and *p**i*<=≠<=*i*. Nickolas asks you to print any perfect permutation of size *n* for the given *n*. Input Specification: A single line contains a single integer *n* (1<=≤<=*n*<=≤<=100) — the permutation size. Output Specification: If a perfect permutation of size *n* doesn't exist, print a single integer -1. Otherwise print *n* distinct integers from 1 to *n*, *p*1,<=*p*2,<=...,<=*p**n* — permutation *p*, that is perfect. Separate printed numbers by whitespaces. Demo Input: ['1\n', '2\n', '4\n'] Demo Output: ['-1\n', '2 1 \n', '2 1 4 3 \n'] Note: none
```python n=int(input()) if n%2==0: print(-1) else: a=[i for i in range(1,n+1)] i=0 while i<n: a[i],a[i+1]=a[i+1],a[i] i+=2 for i in a: print(i) ```
-1
535
B
Tavas and SaDDas
PROGRAMMING
1,100
[ "bitmasks", "brute force", "combinatorics", "implementation" ]
null
null
Once again Tavas started eating coffee mix without water! Keione told him that it smells awful, but he didn't stop doing that. That's why Keione told his smart friend, SaDDas to punish him! SaDDas took Tavas' headphones and told him: "If you solve the following problem, I'll return it to you." The problem is: You are given a lucky number *n*. Lucky numbers are the positive integers whose decimal representations contain only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. If we sort all lucky numbers in increasing order, what's the 1-based index of *n*? Tavas is not as smart as SaDDas, so he asked you to do him a favor and solve this problem so he can have his headphones back.
The first and only line of input contains a lucky number *n* (1<=≤<=*n*<=≤<=109).
Print the index of *n* among all lucky numbers.
[ "4\n", "7\n", "77\n" ]
[ "1\n", "2\n", "6\n" ]
none
1,000
[ { "input": "4", "output": "1" }, { "input": "7", "output": "2" }, { "input": "77", "output": "6" }, { "input": "4", "output": "1" }, { "input": "474744", "output": "83" }, { "input": "777774", "output": "125" }, { "input": "447", "output": "8" }, { "input": "774", "output": "13" }, { "input": "4", "output": "1" }, { "input": "4447747", "output": "140" }, { "input": "7747474", "output": "233" }, { "input": "4444", "output": "15" }, { "input": "4447", "output": "16" }, { "input": "7", "output": "2" }, { "input": "4", "output": "1" }, { "input": "4447744", "output": "139" }, { "input": "77474", "output": "57" }, { "input": "7747", "output": "28" }, { "input": "444", "output": "7" }, { "input": "7", "output": "2" }, { "input": "7774477", "output": "242" }, { "input": "4477774", "output": "157" }, { "input": "7444", "output": "23" }, { "input": "7474747", "output": "212" }, { "input": "77", "output": "6" }, { "input": "774477", "output": "114" }, { "input": "7", "output": "2" }, { "input": "47", "output": "4" }, { "input": "747777", "output": "110" }, { "input": "444444444", "output": "511" }, { "input": "777777777", "output": "1022" }, { "input": "477477447", "output": "728" }, { "input": "777744747", "output": "996" } ]
1,694,343,298
2,147,483,647
PyPy 3-64
OK
TESTS
33
62
0
def count_lucky_numbers(n): d = len(n) s = "" for i in range(d): if n[i] == '4': s += '0' else: s += '1' return 2*(2**(d-1)-1)+int(s,2)+1 n = input() # Input lucky number index = count_lucky_numbers(n) print(index)
Title: Tavas and SaDDas Time Limit: None seconds Memory Limit: None megabytes Problem Description: Once again Tavas started eating coffee mix without water! Keione told him that it smells awful, but he didn't stop doing that. That's why Keione told his smart friend, SaDDas to punish him! SaDDas took Tavas' headphones and told him: "If you solve the following problem, I'll return it to you." The problem is: You are given a lucky number *n*. Lucky numbers are the positive integers whose decimal representations contain only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. If we sort all lucky numbers in increasing order, what's the 1-based index of *n*? Tavas is not as smart as SaDDas, so he asked you to do him a favor and solve this problem so he can have his headphones back. Input Specification: The first and only line of input contains a lucky number *n* (1<=≤<=*n*<=≤<=109). Output Specification: Print the index of *n* among all lucky numbers. Demo Input: ['4\n', '7\n', '77\n'] Demo Output: ['1\n', '2\n', '6\n'] Note: none
```python def count_lucky_numbers(n): d = len(n) s = "" for i in range(d): if n[i] == '4': s += '0' else: s += '1' return 2*(2**(d-1)-1)+int(s,2)+1 n = input() # Input lucky number index = count_lucky_numbers(n) print(index) ```
3
622
A
Infinite Sequence
PROGRAMMING
1,000
[ "implementation", "math" ]
null
null
Consider the infinite sequence of integers: 1,<=1,<=2,<=1,<=2,<=3,<=1,<=2,<=3,<=4,<=1,<=2,<=3,<=4,<=5.... The sequence is built in the following way: at first the number 1 is written out, then the numbers from 1 to 2, then the numbers from 1 to 3, then the numbers from 1 to 4 and so on. Note that the sequence contains numbers, not digits. For example number 10 first appears in the sequence in position 55 (the elements are numerated from one). Find the number on the *n*-th position of the sequence.
The only line contains integer *n* (1<=≤<=*n*<=≤<=1014) — the position of the number to find. Note that the given number is too large, so you should use 64-bit integer type to store it. In C++ you can use the long long integer type and in Java you can use long integer type.
Print the element in the *n*-th position of the sequence (the elements are numerated from one).
[ "3\n", "5\n", "10\n", "55\n", "56\n" ]
[ "2\n", "2\n", "4\n", "10\n", "1\n" ]
none
0
[ { "input": "3", "output": "2" }, { "input": "5", "output": "2" }, { "input": "10", "output": "4" }, { "input": "55", "output": "10" }, { "input": "56", "output": "1" }, { "input": "1000000000000", "output": "88209" }, { "input": "847194127849", "output": "255708" }, { "input": "294719472984", "output": "593358" }, { "input": "999999911791", "output": "1414213" }, { "input": "999999911792", "output": "1" }, { "input": "100000000000000", "output": "1749820" }, { "input": "1", "output": "1" }, { "input": "99993", "output": "312" }, { "input": "99994", "output": "313" }, { "input": "99995", "output": "314" }, { "input": "99990", "output": "309" }, { "input": "2", "output": "1" }, { "input": "99991", "output": "310" }, { "input": "99992", "output": "311" }, { "input": "99996", "output": "315" }, { "input": "99997", "output": "316" }, { "input": "99998", "output": "317" }, { "input": "99999", "output": "318" }, { "input": "1021", "output": "31" }, { "input": "4", "output": "1" }, { "input": "23", "output": "2" }, { "input": "9994", "output": "124" }, { "input": "99939", "output": "258" }, { "input": "99999998250180", "output": "14142135" }, { "input": "6", "output": "3" }, { "input": "8", "output": "2" }, { "input": "35", "output": "7" }, { "input": "100", "output": "9" }, { "input": "10101010", "output": "745" }, { "input": "103", "output": "12" }, { "input": "102", "output": "11" }, { "input": "101", "output": "10" } ]
1,564,643,787
2,147,483,647
Python 3
COMPILATION_ERROR
TESTS
0
0
0
li = [] for i in range(1,100): for j in range(1,i+1): li.append(j) print(li[int(input("enter a number))])
Title: Infinite Sequence Time Limit: None seconds Memory Limit: None megabytes Problem Description: Consider the infinite sequence of integers: 1,<=1,<=2,<=1,<=2,<=3,<=1,<=2,<=3,<=4,<=1,<=2,<=3,<=4,<=5.... The sequence is built in the following way: at first the number 1 is written out, then the numbers from 1 to 2, then the numbers from 1 to 3, then the numbers from 1 to 4 and so on. Note that the sequence contains numbers, not digits. For example number 10 first appears in the sequence in position 55 (the elements are numerated from one). Find the number on the *n*-th position of the sequence. Input Specification: The only line contains integer *n* (1<=≤<=*n*<=≤<=1014) — the position of the number to find. Note that the given number is too large, so you should use 64-bit integer type to store it. In C++ you can use the long long integer type and in Java you can use long integer type. Output Specification: Print the element in the *n*-th position of the sequence (the elements are numerated from one). Demo Input: ['3\n', '5\n', '10\n', '55\n', '56\n'] Demo Output: ['2\n', '2\n', '4\n', '10\n', '1\n'] Note: none
```python li = [] for i in range(1,100): for j in range(1,i+1): li.append(j) print(li[int(input("enter a number))]) ```
-1
300
A
Array
PROGRAMMING
1,100
[ "brute force", "constructive algorithms", "implementation" ]
null
null
Vitaly has an array of *n* distinct integers. Vitaly wants to divide this array into three non-empty sets so as the following conditions hold: 1. The product of all numbers in the first set is less than zero (<=&lt;<=0). 1. The product of all numbers in the second set is greater than zero (<=&gt;<=0). 1. The product of all numbers in the third set is equal to zero. 1. Each number from the initial array must occur in exactly one set. Help Vitaly. Divide the given array.
The first line of the input contains integer *n* (3<=≤<=*n*<=≤<=100). The second line contains *n* space-separated distinct integers *a*1,<=*a*2,<=...,<=*a**n* (|*a**i*|<=≤<=103) — the array elements.
In the first line print integer *n*1 (*n*1<=&gt;<=0) — the number of elements in the first set. Then print *n*1 numbers — the elements that got to the first set. In the next line print integer *n*2 (*n*2<=&gt;<=0) — the number of elements in the second set. Then print *n*2 numbers — the elements that got to the second set. In the next line print integer *n*3 (*n*3<=&gt;<=0) — the number of elements in the third set. Then print *n*3 numbers — the elements that got to the third set. The printed sets must meet the described conditions. It is guaranteed that the solution exists. If there are several solutions, you are allowed to print any of them.
[ "3\n-1 2 0\n", "4\n-1 -2 -3 0\n" ]
[ "1 -1\n1 2\n1 0\n", "1 -1\n2 -3 -2\n1 0\n" ]
none
500
[ { "input": "3\n-1 2 0", "output": "1 -1\n1 2\n1 0" }, { "input": "4\n-1 -2 -3 0", "output": "1 -1\n2 -3 -2\n1 0" }, { "input": "5\n-1 -2 1 2 0", "output": "1 -1\n2 1 2\n2 0 -2" }, { "input": "100\n-64 -51 -75 -98 74 -26 -1 -8 -99 -76 -53 -80 -43 -22 -100 -62 -34 -5 -65 -81 -18 -91 -92 -16 -23 -95 -9 -19 -44 -46 -79 52 -35 4 -87 -7 -90 -20 -71 -61 -67 -50 -66 -68 -49 -27 -32 -57 -85 -59 -30 -36 -3 -77 86 -25 -94 -56 60 -24 -37 -72 -41 -31 11 -48 28 -38 -42 -39 -33 -70 -84 0 -93 -73 -14 -69 -40 -97 -6 -55 -45 -54 -10 -29 -96 -12 -83 -15 -21 -47 17 -2 -63 -89 88 13 -58 -82", "output": "89 -64 -51 -75 -98 -26 -1 -8 -99 -76 -53 -80 -43 -22 -100 -62 -34 -5 -65 -81 -18 -91 -92 -16 -23 -95 -9 -19 -44 -46 -79 -35 -87 -7 -90 -20 -71 -61 -67 -50 -66 -68 -49 -27 -32 -57 -85 -59 -30 -36 -3 -77 -25 -94 -56 -24 -37 -72 -41 -31 -48 -38 -42 -39 -33 -70 -84 -93 -73 -14 -69 -40 -97 -6 -55 -45 -54 -10 -29 -96 -12 -83 -15 -21 -47 -2 -63 -89 -58 -82\n10 74 52 4 86 60 11 28 17 88 13\n1 0" }, { "input": "100\n3 -66 -17 54 24 -29 76 89 32 -37 93 -16 99 -25 51 78 23 68 -95 59 18 34 -45 77 9 39 -10 19 8 73 -5 60 12 31 0 2 26 40 48 30 52 49 27 4 87 57 85 58 -61 50 83 80 69 67 91 97 -96 11 100 56 82 53 13 -92 -72 70 1 -94 -63 47 21 14 74 7 6 33 55 65 64 -41 81 42 36 28 38 20 43 71 90 -88 22 84 -86 15 75 62 44 35 98 46", "output": "19 -66 -17 -29 -37 -16 -25 -95 -45 -10 -5 -61 -96 -92 -72 -94 -63 -41 -88 -86\n80 3 54 24 76 89 32 93 99 51 78 23 68 59 18 34 77 9 39 19 8 73 60 12 31 2 26 40 48 30 52 49 27 4 87 57 85 58 50 83 80 69 67 91 97 11 100 56 82 53 13 70 1 47 21 14 74 7 6 33 55 65 64 81 42 36 28 38 20 43 71 90 22 84 15 75 62 44 35 98 46\n1 0" }, { "input": "100\n-17 16 -70 32 -60 75 -100 -9 -68 -30 -42 86 -88 -98 -47 -5 58 -14 -94 -73 -80 -51 -66 -85 -53 49 -25 -3 -45 -69 -11 -64 83 74 -65 67 13 -91 81 6 -90 -54 -12 -39 0 -24 -71 -41 -44 57 -93 -20 -92 18 -43 -52 -55 -84 -89 -19 40 -4 -99 -26 -87 -36 -56 -61 -62 37 -95 -28 63 23 35 -82 1 -2 -78 -96 -21 -77 -76 -27 -10 -97 -8 46 -15 -48 -34 -59 -7 -29 50 -33 -72 -79 22 38", "output": "75 -17 -70 -60 -100 -9 -68 -30 -42 -88 -98 -47 -5 -14 -94 -73 -80 -51 -66 -85 -53 -25 -3 -45 -69 -11 -64 -65 -91 -90 -54 -12 -39 -24 -71 -41 -44 -93 -20 -92 -43 -52 -55 -84 -89 -19 -4 -99 -26 -87 -36 -56 -61 -62 -95 -28 -82 -2 -78 -96 -21 -77 -76 -27 -10 -97 -8 -15 -48 -34 -59 -7 -29 -33 -72 -79\n24 16 32 75 86 58 49 83 74 67 13 81 6 57 18 40 37 63 23 35 1 46 50 22 38\n1 0" }, { "input": "100\n-97 -90 61 78 87 -52 -3 65 83 38 30 -60 35 -50 -73 -77 44 -32 -81 17 -67 58 -6 -34 47 -28 71 -45 69 -80 -4 -7 -57 -79 43 -27 -31 29 16 -89 -21 -93 95 -82 74 -5 -70 -20 -18 36 -64 -66 72 53 62 -68 26 15 76 -40 -99 8 59 88 49 -23 9 10 56 -48 -98 0 100 -54 25 94 13 -63 42 39 -1 55 24 -12 75 51 41 84 -96 -85 -2 -92 14 -46 -91 -19 -11 -86 22 -37", "output": "51 -97 -90 -52 -3 -60 -50 -73 -77 -32 -81 -67 -6 -34 -28 -45 -80 -4 -7 -57 -79 -27 -31 -89 -21 -93 -82 -5 -70 -20 -18 -64 -66 -68 -40 -99 -23 -48 -98 -54 -63 -1 -12 -96 -85 -2 -92 -46 -91 -19 -11 -86\n47 61 78 87 65 83 38 30 35 44 17 58 47 71 69 43 29 16 95 74 36 72 53 62 26 15 76 8 59 88 49 9 10 56 100 25 94 13 42 39 55 24 75 51 41 84 14 22\n2 0 -37" }, { "input": "100\n-75 -60 -18 -92 -71 -9 -37 -34 -82 28 -54 93 -83 -76 -58 -88 -17 -97 64 -39 -96 -81 -10 -98 -47 -100 -22 27 14 -33 -19 -99 87 -66 57 -21 -90 -70 -32 -26 24 -77 -74 13 -44 16 -5 -55 -2 -6 -7 -73 -1 -68 -30 -95 -42 69 0 -20 -79 59 -48 -4 -72 -67 -46 62 51 -52 -86 -40 56 -53 85 -35 -8 49 50 65 29 11 -43 -15 -41 -12 -3 -80 -31 -38 -91 -45 -25 78 94 -23 -63 84 89 -61", "output": "73 -75 -60 -18 -92 -71 -9 -37 -34 -82 -54 -83 -76 -58 -88 -17 -97 -39 -96 -81 -10 -98 -47 -100 -22 -33 -19 -99 -66 -21 -90 -70 -32 -26 -77 -74 -44 -5 -55 -2 -6 -7 -73 -1 -68 -30 -95 -42 -20 -79 -48 -4 -72 -67 -46 -52 -86 -40 -53 -35 -8 -43 -15 -41 -12 -3 -80 -31 -38 -91 -45 -25 -23 -63\n25 28 93 64 27 14 87 57 24 13 16 69 59 62 51 56 85 49 50 65 29 11 78 94 84 89\n2 0 -61" }, { "input": "100\n-87 -48 -76 -1 -10 -17 -22 -19 -27 -99 -43 49 38 -20 -45 -64 44 -96 -35 -74 -65 -41 -21 -75 37 -12 -67 0 -3 5 -80 -93 -81 -97 -47 -63 53 -100 95 -79 -83 -90 -32 88 -77 -16 -23 -54 -28 -4 -73 -98 -25 -39 60 -56 -34 -2 -11 -55 -52 -69 -68 -29 -82 -62 -36 -13 -6 -89 8 -72 18 -15 -50 -71 -70 -92 -42 -78 -61 -9 -30 -85 -91 -94 84 -86 -7 -57 -14 40 -33 51 -26 46 59 -31 -58 -66", "output": "83 -87 -48 -76 -1 -10 -17 -22 -19 -27 -99 -43 -20 -45 -64 -96 -35 -74 -65 -41 -21 -75 -12 -67 -3 -80 -93 -81 -97 -47 -63 -100 -79 -83 -90 -32 -77 -16 -23 -54 -28 -4 -73 -98 -25 -39 -56 -34 -2 -11 -55 -52 -69 -68 -29 -82 -62 -36 -13 -6 -89 -72 -15 -50 -71 -70 -92 -42 -78 -61 -9 -30 -85 -91 -94 -86 -7 -57 -14 -33 -26 -31 -58 -66\n16 49 38 44 37 5 53 95 88 60 8 18 84 40 51 46 59\n1 0" }, { "input": "100\n-95 -28 -43 -72 -11 -24 -37 -35 -44 -66 -45 -62 -96 -51 -55 -23 -31 -26 -59 -17 77 -69 -10 -12 -78 -14 -52 -57 -40 -75 4 -98 -6 7 -53 -3 -90 -63 -8 -20 88 -91 -32 -76 -80 -97 -34 -27 -19 0 70 -38 -9 -49 -67 73 -36 2 81 -39 -65 -83 -64 -18 -94 -79 -58 -16 87 -22 -74 -25 -13 -46 -89 -47 5 -15 -54 -99 56 -30 -60 -21 -86 33 -1 -50 -68 -100 -85 -29 92 -48 -61 42 -84 -93 -41 -82", "output": "85 -95 -28 -43 -72 -11 -24 -37 -35 -44 -66 -45 -62 -96 -51 -55 -23 -31 -26 -59 -17 -69 -10 -12 -78 -14 -52 -57 -40 -75 -98 -6 -53 -3 -90 -63 -8 -20 -91 -32 -76 -80 -97 -34 -27 -19 -38 -9 -49 -67 -36 -39 -65 -83 -64 -18 -94 -79 -58 -16 -22 -74 -25 -13 -46 -89 -47 -15 -54 -99 -30 -60 -21 -86 -1 -50 -68 -100 -85 -29 -48 -61 -84 -93 -41 -82\n14 77 4 7 88 70 73 2 81 87 5 56 33 92 42\n1 0" }, { "input": "100\n-12 -41 57 13 83 -36 53 69 -6 86 -75 87 11 -5 -4 -14 -37 -84 70 2 -73 16 31 34 -45 94 -9 26 27 52 -42 46 96 21 32 7 -18 61 66 -51 95 -48 -76 90 80 -40 89 77 78 54 -30 8 88 33 -24 82 -15 19 1 59 44 64 -97 -60 43 56 35 47 39 50 29 28 -17 -67 74 23 85 -68 79 0 65 55 -3 92 -99 72 93 -71 38 -10 -100 -98 81 62 91 -63 -58 49 -20 22", "output": "35 -12 -41 -36 -6 -75 -5 -4 -14 -37 -84 -73 -45 -9 -42 -18 -51 -48 -76 -40 -30 -24 -15 -97 -60 -17 -67 -68 -3 -99 -71 -10 -100 -98 -63 -58\n63 57 13 83 53 69 86 87 11 70 2 16 31 34 94 26 27 52 46 96 21 32 7 61 66 95 90 80 89 77 78 54 8 88 33 82 19 1 59 44 64 43 56 35 47 39 50 29 28 74 23 85 79 65 55 92 72 93 38 81 62 91 49 22\n2 0 -20" }, { "input": "100\n-34 81 85 -96 50 20 54 86 22 10 -19 52 65 44 30 53 63 71 17 98 -92 4 5 -99 89 -23 48 9 7 33 75 2 47 -56 42 70 -68 57 51 83 82 94 91 45 46 25 95 11 -12 62 -31 -87 58 38 67 97 -60 66 73 -28 13 93 29 59 -49 77 37 -43 -27 0 -16 72 15 79 61 78 35 21 3 8 84 1 -32 36 74 -88 26 100 6 14 40 76 18 90 24 69 80 64 55 41", "output": "19 -34 -96 -19 -92 -99 -23 -56 -68 -12 -31 -87 -60 -28 -49 -43 -27 -16 -32 -88\n80 81 85 50 20 54 86 22 10 52 65 44 30 53 63 71 17 98 4 5 89 48 9 7 33 75 2 47 42 70 57 51 83 82 94 91 45 46 25 95 11 62 58 38 67 97 66 73 13 93 29 59 77 37 72 15 79 61 78 35 21 3 8 84 1 36 74 26 100 6 14 40 76 18 90 24 69 80 64 55 41\n1 0" }, { "input": "100\n-1000 -986 -979 -955 -966 -963 -973 -959 -972 -906 -924 -927 -929 -918 -977 -967 -921 -989 -911 -995 -945 -919 -971 -913 -912 -933 -969 -975 -920 -988 -997 -994 -953 -962 -940 -905 -978 -948 -957 -996 0 -976 -949 -931 -903 -985 -923 -993 -944 -909 -938 -946 -934 -992 -904 -980 -954 -943 -917 -968 -991 -956 -902 -942 -999 -998 -908 -928 -930 -914 -922 -936 -960 -937 -939 -926 -965 -925 -951 -910 -907 -970 -990 -984 -964 -987 -916 -947 -982 -950 -974 -915 -932 -958 -981 -941 -961 -983 -952 -935", "output": "97 -1000 -986 -979 -955 -966 -963 -973 -959 -972 -906 -924 -927 -929 -918 -977 -967 -921 -989 -911 -995 -945 -919 -971 -913 -912 -933 -969 -975 -920 -988 -997 -994 -953 -962 -940 -905 -978 -948 -957 -996 -976 -949 -931 -903 -985 -923 -993 -944 -909 -938 -946 -934 -992 -904 -980 -954 -943 -917 -968 -991 -956 -902 -942 -999 -998 -908 -928 -930 -914 -922 -936 -960 -937 -939 -926 -965 -925 -951 -910 -907 -970 -990 -984 -964 -987 -916 -947 -982 -950 -974 -915 -932 -958 -981 -941 -961 -983\n2 -935 -952\n1 0" }, { "input": "99\n-1000 -986 -979 -955 -966 -963 -973 -959 -972 -906 -924 -927 -929 -918 -977 -967 -921 -989 -911 -995 -945 -919 -971 -913 -912 -933 -969 -975 -920 -988 -997 -994 -953 -962 -940 -905 -978 -948 -957 -996 0 -976 -949 -931 -903 -985 -923 -993 -944 -909 -938 -946 -934 -992 -904 -980 -954 -943 -917 -968 -991 -956 -902 -942 -999 -998 -908 -928 -930 -914 -922 -936 -960 -937 -939 -926 -965 -925 -951 -910 -907 -970 -990 -984 -964 -987 -916 -947 -982 -950 -974 -915 -932 -958 -981 -941 -961 -983 -952", "output": "95 -1000 -986 -979 -955 -966 -963 -973 -959 -972 -906 -924 -927 -929 -918 -977 -967 -921 -989 -911 -995 -945 -919 -971 -913 -912 -933 -969 -975 -920 -988 -997 -994 -953 -962 -940 -905 -978 -948 -957 -996 -976 -949 -931 -903 -985 -923 -993 -944 -909 -938 -946 -934 -992 -904 -980 -954 -943 -917 -968 -991 -956 -902 -942 -999 -998 -908 -928 -930 -914 -922 -936 -960 -937 -939 -926 -965 -925 -951 -910 -907 -970 -990 -984 -964 -987 -916 -947 -982 -950 -974 -915 -932 -958 -981 -941\n2 -952 -983\n2 0 -961" }, { "input": "59\n-990 -876 -641 -726 718 -53 803 -954 894 -265 -587 -665 904 349 754 -978 441 794 -768 -428 -569 -476 188 -620 -290 -333 45 705 -201 109 165 446 13 122 714 -562 -15 -86 -960 43 329 578 287 -776 -14 -71 915 886 -259 337 -495 913 -498 -669 -673 818 225 647 0", "output": "29 -990 -876 -641 -726 -53 -954 -265 -587 -665 -978 -768 -428 -569 -476 -620 -290 -333 -201 -562 -15 -86 -960 -776 -14 -71 -259 -495 -498 -669\n28 718 803 894 904 349 754 441 794 188 45 705 109 165 446 13 122 714 43 329 578 287 915 886 337 913 818 225 647\n2 0 -673" }, { "input": "64\n502 885 -631 -906 735 687 642 -29 -696 -165 -524 15 -129 -663 -846 -501 -651 895 -341 -833 -142 33 -847 688 945 -192 -587 -930 603 849 736 676 788 256 863 -509 319 -49 -807 -158 218 -886 -143 -639 118 -156 -291 325 892 -916 -622 -960 -959 -731 -943 436 -535 861 745 589 -159 376 -182 0", "output": "35 -631 -906 -29 -696 -165 -524 -129 -663 -846 -501 -651 -341 -833 -142 -847 -192 -587 -930 -509 -49 -807 -158 -886 -143 -639 -156 -291 -916 -622 -960 -959 -731 -943 -535 -159\n27 502 885 735 687 642 15 895 33 688 945 603 849 736 676 788 256 863 319 218 118 325 892 436 861 745 589 376\n2 0 -182" }, { "input": "5\n-1 -2 -3 -4 0", "output": "1 -1\n2 -4 -3\n2 0 -2" }, { "input": "3\n-101 101 0", "output": "1 -101\n1 101\n1 0" }, { "input": "21\n-100 -200 -300 -400 -500 -600 -700 -800 -900 -1000 0 100 200 300 400 500 600 700 800 900 1000", "output": "9 -100 -200 -300 -400 -500 -600 -700 -800 -900\n10 100 200 300 400 500 600 700 800 900 1000\n2 0 -1000" }, { "input": "4\n0 -1 -2 -3", "output": "1 -1\n2 -3 -2\n1 0" } ]
1,623,929,857
2,147,483,647
PyPy 3
WRONG_ANSWER
TESTS
2
154
0
n = int(input()) arr = list(map(int, input().split())) zeroes = [] positives = [] negatives = [] for num in arr: if num > 0: positives.append(str(num)) elif num < 0: if not negatives: negatives.append(str(num)) else: positives.append(str(num)) else: zeroes.append(str(num)) print(1, " ".join(negatives)) print(len(positives), " ".join(positives)) print(len(zeroes), " ".join(zeroes))
Title: Array Time Limit: None seconds Memory Limit: None megabytes Problem Description: Vitaly has an array of *n* distinct integers. Vitaly wants to divide this array into three non-empty sets so as the following conditions hold: 1. The product of all numbers in the first set is less than zero (<=&lt;<=0). 1. The product of all numbers in the second set is greater than zero (<=&gt;<=0). 1. The product of all numbers in the third set is equal to zero. 1. Each number from the initial array must occur in exactly one set. Help Vitaly. Divide the given array. Input Specification: The first line of the input contains integer *n* (3<=≤<=*n*<=≤<=100). The second line contains *n* space-separated distinct integers *a*1,<=*a*2,<=...,<=*a**n* (|*a**i*|<=≤<=103) — the array elements. Output Specification: In the first line print integer *n*1 (*n*1<=&gt;<=0) — the number of elements in the first set. Then print *n*1 numbers — the elements that got to the first set. In the next line print integer *n*2 (*n*2<=&gt;<=0) — the number of elements in the second set. Then print *n*2 numbers — the elements that got to the second set. In the next line print integer *n*3 (*n*3<=&gt;<=0) — the number of elements in the third set. Then print *n*3 numbers — the elements that got to the third set. The printed sets must meet the described conditions. It is guaranteed that the solution exists. If there are several solutions, you are allowed to print any of them. Demo Input: ['3\n-1 2 0\n', '4\n-1 -2 -3 0\n'] Demo Output: ['1 -1\n1 2\n1 0\n', '1 -1\n2 -3 -2\n1 0\n'] Note: none
```python n = int(input()) arr = list(map(int, input().split())) zeroes = [] positives = [] negatives = [] for num in arr: if num > 0: positives.append(str(num)) elif num < 0: if not negatives: negatives.append(str(num)) else: positives.append(str(num)) else: zeroes.append(str(num)) print(1, " ".join(negatives)) print(len(positives), " ".join(positives)) print(len(zeroes), " ".join(zeroes)) ```
0
691
A
Fashion in Berland
PROGRAMMING
1,000
[ "implementation" ]
null
null
According to rules of the Berland fashion, a jacket should be fastened by all the buttons except only one, but not necessarily it should be the last one. Also if the jacket has only one button, it should be fastened, so the jacket will not swinging open. You are given a jacket with *n* buttons. Determine if it is fastened in a right way.
The first line contains integer *n* (1<=≤<=*n*<=≤<=1000) — the number of buttons on the jacket. The second line contains *n* integers *a**i* (0<=≤<=*a**i*<=≤<=1). The number *a**i*<==<=0 if the *i*-th button is not fastened. Otherwise *a**i*<==<=1.
In the only line print the word "YES" if the jacket is fastened in a right way. Otherwise print the word "NO".
[ "3\n1 0 1\n", "3\n1 0 0\n" ]
[ "YES\n", "NO\n" ]
none
0
[ { "input": "3\n1 0 1", "output": "YES" }, { "input": "3\n1 0 0", "output": "NO" }, { "input": "3\n1 1 0", "output": "YES" }, { "input": "3\n1 1 1", "output": "NO" }, { "input": "3\n0 0 1", "output": "NO" }, { "input": "3\n0 0 0", "output": "NO" }, { "input": "3\n0 1 1", "output": "YES" }, { "input": "3\n0 1 0", "output": "NO" }, { "input": "2\n0 1", "output": "YES" }, { "input": "2\n1 0", "output": "YES" }, { "input": "2\n0 0", "output": "NO" }, { "input": "2\n1 1", "output": "NO" }, { "input": "1\n1", "output": "YES" }, { "input": "1\n0", "output": "NO" }, { "input": "10\n1 0 1 1 1 1 1 1 1 1", "output": "YES" }, { "input": "5\n1 1 1 1 0", "output": "YES" }, { "input": "4\n1 0 1 0", "output": "NO" }, { "input": "4\n1 1 0 0", "output": "NO" }, { "input": "10\n0 0 1 1 1 1 1 1 1 1", "output": "NO" }, { "input": "10\n1 1 1 1 1 1 1 1 1 1", "output": "NO" }, { "input": "123\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 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1", "output": "NO" }, { "input": "124\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 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": "NO" }, { "input": "94\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", "output": "NO" }, { "input": "64\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", "output": "NO" }, { "input": "34\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", "output": "NO" }, { "input": "35\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", "output": "NO" }, { "input": "5\n1 1 1 1 1", "output": "NO" }, { "input": "10\n0 0 0 0 0 0 0 0 0 0", "output": "NO" }, { "input": "231\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 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 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": "NO" }, { "input": "10\n1 1 0 1 1 1 0 1 1 1", "output": "NO" } ]
1,629,250,747
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
3
77
6,758,400
n = int(input()) list = list(map(int,input().split())) if(n==1): if list[0]==1: print("YES") else: print("NO") else: list = str(list) if(list.count('0')<=1): print("YES") else: print("NO")
Title: Fashion in Berland Time Limit: None seconds Memory Limit: None megabytes Problem Description: According to rules of the Berland fashion, a jacket should be fastened by all the buttons except only one, but not necessarily it should be the last one. Also if the jacket has only one button, it should be fastened, so the jacket will not swinging open. You are given a jacket with *n* buttons. Determine if it is fastened in a right way. Input Specification: The first line contains integer *n* (1<=≤<=*n*<=≤<=1000) — the number of buttons on the jacket. The second line contains *n* integers *a**i* (0<=≤<=*a**i*<=≤<=1). The number *a**i*<==<=0 if the *i*-th button is not fastened. Otherwise *a**i*<==<=1. Output Specification: In the only line print the word "YES" if the jacket is fastened in a right way. Otherwise print the word "NO". Demo Input: ['3\n1 0 1\n', '3\n1 0 0\n'] Demo Output: ['YES\n', 'NO\n'] Note: none
```python n = int(input()) list = list(map(int,input().split())) if(n==1): if list[0]==1: print("YES") else: print("NO") else: list = str(list) if(list.count('0')<=1): print("YES") else: print("NO") ```
0
545
B
Equidistant String
PROGRAMMING
1,100
[ "greedy" ]
null
null
Little Susie loves strings. Today she calculates distances between them. As Susie is a small girl after all, her strings contain only digits zero and one. She uses the definition of Hamming distance: We will define the distance between two strings *s* and *t* of the same length consisting of digits zero and one as the number of positions *i*, such that *s**i* isn't equal to *t**i*. As besides everything else Susie loves symmetry, she wants to find for two strings *s* and *t* of length *n* such string *p* of length *n*, that the distance from *p* to *s* was equal to the distance from *p* to *t*. It's time for Susie to go to bed, help her find such string *p* or state that it is impossible.
The first line contains string *s* of length *n*. The second line contains string *t* of length *n*. The length of string *n* is within range from 1 to 105. It is guaranteed that both strings contain only digits zero and one.
Print a string of length *n*, consisting of digits zero and one, that meets the problem statement. If no such string exist, print on a single line "impossible" (without the quotes). If there are multiple possible answers, print any of them.
[ "0001\n1011\n", "000\n111\n" ]
[ "0011\n", "impossible\n" ]
In the first sample different answers are possible, namely — 0010, 0011, 0110, 0111, 1000, 1001, 1100, 1101.
1,000
[ { "input": "0001\n1011", "output": "0011" }, { "input": "000\n111", "output": "impossible" }, { "input": "1010101011111110111111001111111111111111111111101101110111111111111110110110101011111110110111111101\n0101111111000100010100001100010101000000011000000000011011000001100100001110111011111000001110011111", "output": "1111101111101100110110001110110111010101011101001001010011101011101100100110111011111100100110111111" }, { "input": "0000000001000000000000100000100001000000\n1111111011111101111111111111111111111111", "output": "0101010011010100101010110101101011010101" }, { "input": "10101000101001001101010010000101100011010011000011001001001111110010100110000001111111\n01001011110111111101111011011111110000000111111001000011010101001010000111101010000101", "output": "11101010111101101101110011001101110010010111010001001011000111011010100111001000101101" }, { "input": "1111111111111111111111111110111111111111111111111111111111111110111111101111111111111111111111111111\n1111111111111111111001111111110010111111111111111111001111111111111111111111111111111111111111111111", "output": "1111111111111111111101111110110110111111111111111111101111111110111111111111111111111111111111111111" }, { "input": "0000000000000000000000000000111111111111111111111111111111111111111111111111111111111111111111111111\n1111111111111111111111000000000000000000000000000000000000000000000000000000000000000000000000000000", "output": "0101010101010101010101000000101010101010101010101010101010101010101010101010101010101010101010101010" }, { "input": "00001111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111\n11111100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", "output": "01011110101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010" }, { "input": "0\n0", "output": "0" }, { "input": "0\n1", "output": "impossible" }, { "input": "1\n1", "output": "1" }, { "input": "1\n0", "output": "impossible" }, { "input": "1111\n0000", "output": "1010" }, { "input": "1111\n1001", "output": "1101" }, { "input": "0000\n1111", "output": "0101" }, { "input": "1010\n0101", "output": "1111" } ]
1,683,907,608
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
1
31
0
a = input() b = input() x = str(int(a) ^ int(b)) if x.count("1") %2 != 0 : print("IMPOSSIBLE") else : res = "" flag1 = True for idx , value in enumerate(x) : if value == "0": res += str(a)[idx] else: if flag1 : res += "1" flag1 =False else: res += "0" flag1 = True print(res)
Title: Equidistant String Time Limit: None seconds Memory Limit: None megabytes Problem Description: Little Susie loves strings. Today she calculates distances between them. As Susie is a small girl after all, her strings contain only digits zero and one. She uses the definition of Hamming distance: We will define the distance between two strings *s* and *t* of the same length consisting of digits zero and one as the number of positions *i*, such that *s**i* isn't equal to *t**i*. As besides everything else Susie loves symmetry, she wants to find for two strings *s* and *t* of length *n* such string *p* of length *n*, that the distance from *p* to *s* was equal to the distance from *p* to *t*. It's time for Susie to go to bed, help her find such string *p* or state that it is impossible. Input Specification: The first line contains string *s* of length *n*. The second line contains string *t* of length *n*. The length of string *n* is within range from 1 to 105. It is guaranteed that both strings contain only digits zero and one. Output Specification: Print a string of length *n*, consisting of digits zero and one, that meets the problem statement. If no such string exist, print on a single line "impossible" (without the quotes). If there are multiple possible answers, print any of them. Demo Input: ['0001\n1011\n', '000\n111\n'] Demo Output: ['0011\n', 'impossible\n'] Note: In the first sample different answers are possible, namely — 0010, 0011, 0110, 0111, 1000, 1001, 1100, 1101.
```python a = input() b = input() x = str(int(a) ^ int(b)) if x.count("1") %2 != 0 : print("IMPOSSIBLE") else : res = "" flag1 = True for idx , value in enumerate(x) : if value == "0": res += str(a)[idx] else: if flag1 : res += "1" flag1 =False else: res += "0" flag1 = True print(res) ```
0
294
A
Shaass and Oskols
PROGRAMMING
800
[ "implementation", "math" ]
null
null
Shaass has decided to hunt some birds. There are *n* horizontal electricity wires aligned parallel to each other. Wires are numbered 1 to *n* from top to bottom. On each wire there are some oskols sitting next to each other. Oskol is the name of a delicious kind of birds in Shaass's territory. Supposed there are *a**i* oskols sitting on the *i*-th wire. Sometimes Shaass shots one of the birds and the bird dies (suppose that this bird sat at the *i*-th wire). Consequently all the birds on the *i*-th wire to the left of the dead bird get scared and jump up on the wire number *i*<=-<=1, if there exists no upper wire they fly away. Also all the birds to the right of the dead bird jump down on wire number *i*<=+<=1, if there exists no such wire they fly away. Shaass has shot *m* birds. You're given the initial number of birds on each wire, tell him how many birds are sitting on each wire after the shots.
The first line of the input contains an integer *n*, (1<=≤<=*n*<=≤<=100). The next line contains a list of space-separated integers *a*1,<=*a*2,<=...,<=*a**n*, (0<=≤<=*a**i*<=≤<=100). The third line contains an integer *m*, (0<=≤<=*m*<=≤<=100). Each of the next *m* lines contains two integers *x**i* and *y**i*. The integers mean that for the *i*-th time Shaass shoot the *y**i*-th (from left) bird on the *x**i*-th wire, (1<=≤<=*x**i*<=≤<=*n*,<=1<=≤<=*y**i*). It's guaranteed there will be at least *y**i* birds on the *x**i*-th wire at that moment.
On the *i*-th line of the output print the number of birds on the *i*-th wire.
[ "5\n10 10 10 10 10\n5\n2 5\n3 13\n2 12\n1 13\n4 6\n", "3\n2 4 1\n1\n2 2\n" ]
[ "0\n12\n5\n0\n16\n", "3\n0\n3\n" ]
none
500
[ { "input": "5\n10 10 10 10 10\n5\n2 5\n3 13\n2 12\n1 13\n4 6", "output": "0\n12\n5\n0\n16" }, { "input": "3\n2 4 1\n1\n2 2", "output": "3\n0\n3" }, { "input": "5\n58 51 45 27 48\n5\n4 9\n5 15\n4 5\n5 8\n1 43", "output": "0\n66\n57\n7\n0" }, { "input": "10\n48 53 10 28 91 56 81 2 67 52\n2\n2 40\n6 51", "output": "87\n0\n23\n28\n141\n0\n86\n2\n67\n52" }, { "input": "2\n72 45\n6\n1 69\n2 41\n1 19\n2 7\n1 5\n2 1", "output": "0\n0" }, { "input": "10\n95 54 36 39 98 30 19 24 14 12\n3\n9 5\n8 15\n7 5", "output": "95\n54\n36\n39\n98\n34\n0\n28\n13\n21" }, { "input": "100\n95 15 25 18 64 62 23 59 70 84 50 26 87 35 75 86 0 22 77 60 66 41 21 9 75 50 25 3 69 14 39 68 64 46 59 99 2 0 21 76 90 12 61 42 6 91 36 39 47 41 93 81 66 57 70 36 68 89 52 1 19 93 67 22 76 20 8 81 98 18 100 73 61 93 75 80 53 72 40 20 2 86 33 59 27 16 11 26 55 44 47 55 94 58 2 55 82 22 9 95\n0", "output": "95\n15\n25\n18\n64\n62\n23\n59\n70\n84\n50\n26\n87\n35\n75\n86\n0\n22\n77\n60\n66\n41\n21\n9\n75\n50\n25\n3\n69\n14\n39\n68\n64\n46\n59\n99\n2\n0\n21\n76\n90\n12\n61\n42\n6\n91\n36\n39\n47\n41\n93\n81\n66\n57\n70\n36\n68\n89\n52\n1\n19\n93\n67\n22\n76\n20\n8\n81\n98\n18\n100\n73\n61\n93\n75\n80\n53\n72\n40\n20\n2\n86\n33\n59\n27\n16\n11\n26\n55\n44\n47\n55\n94\n58\n2\n55\n82\n22\n9\n95" }, { "input": "1\n100\n1\n1 100", "output": "0" }, { "input": "1\n100\n1\n1 1", "output": "0" }, { "input": "1\n50\n1\n1 25", "output": "0" }, { "input": "2\n50 0\n1\n1 1", "output": "0\n49" }, { "input": "1\n10\n0", "output": "10" } ]
1,696,359,210
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
0
60
0
# Read input values n = int(input()) # Number of wires a = list(map(int, input().split())) # Initial number of birds on each wire m = int(input()) # Number of shots # Initialize an array to store the result result = a.copy() # Process each shot for _ in range(m): x, y = map(int, input().split()) # Wire number and bird number to be shot x -= 1 # Adjust to 0-based indexing y -= 1 # Adjust to 0-based indexing # Bird shot on wire x, so decrement the number of birds on this wire result[x] -= 1 # Birds jump to the left wire (if possible) if x > 0: result[x - 1] += y # Birds jump to the right wire (if possible) if x < n - 1: result[x + 1] += (a[x] - y - 1) # Reset the number of birds on wire x result[x] = 0 # Print the result for birds in result: print(birds)
Title: Shaass and Oskols Time Limit: None seconds Memory Limit: None megabytes Problem Description: Shaass has decided to hunt some birds. There are *n* horizontal electricity wires aligned parallel to each other. Wires are numbered 1 to *n* from top to bottom. On each wire there are some oskols sitting next to each other. Oskol is the name of a delicious kind of birds in Shaass's territory. Supposed there are *a**i* oskols sitting on the *i*-th wire. Sometimes Shaass shots one of the birds and the bird dies (suppose that this bird sat at the *i*-th wire). Consequently all the birds on the *i*-th wire to the left of the dead bird get scared and jump up on the wire number *i*<=-<=1, if there exists no upper wire they fly away. Also all the birds to the right of the dead bird jump down on wire number *i*<=+<=1, if there exists no such wire they fly away. Shaass has shot *m* birds. You're given the initial number of birds on each wire, tell him how many birds are sitting on each wire after the shots. Input Specification: The first line of the input contains an integer *n*, (1<=≤<=*n*<=≤<=100). The next line contains a list of space-separated integers *a*1,<=*a*2,<=...,<=*a**n*, (0<=≤<=*a**i*<=≤<=100). The third line contains an integer *m*, (0<=≤<=*m*<=≤<=100). Each of the next *m* lines contains two integers *x**i* and *y**i*. The integers mean that for the *i*-th time Shaass shoot the *y**i*-th (from left) bird on the *x**i*-th wire, (1<=≤<=*x**i*<=≤<=*n*,<=1<=≤<=*y**i*). It's guaranteed there will be at least *y**i* birds on the *x**i*-th wire at that moment. Output Specification: On the *i*-th line of the output print the number of birds on the *i*-th wire. Demo Input: ['5\n10 10 10 10 10\n5\n2 5\n3 13\n2 12\n1 13\n4 6\n', '3\n2 4 1\n1\n2 2\n'] Demo Output: ['0\n12\n5\n0\n16\n', '3\n0\n3\n'] Note: none
```python # Read input values n = int(input()) # Number of wires a = list(map(int, input().split())) # Initial number of birds on each wire m = int(input()) # Number of shots # Initialize an array to store the result result = a.copy() # Process each shot for _ in range(m): x, y = map(int, input().split()) # Wire number and bird number to be shot x -= 1 # Adjust to 0-based indexing y -= 1 # Adjust to 0-based indexing # Bird shot on wire x, so decrement the number of birds on this wire result[x] -= 1 # Birds jump to the left wire (if possible) if x > 0: result[x - 1] += y # Birds jump to the right wire (if possible) if x < n - 1: result[x + 1] += (a[x] - y - 1) # Reset the number of birds on wire x result[x] = 0 # Print the result for birds in result: print(birds) ```
0
719
A
Vitya in the Countryside
PROGRAMMING
1,100
[ "implementation" ]
null
null
Every summer Vitya comes to visit his grandmother in the countryside. This summer, he got a huge wart. Every grandma knows that one should treat warts when the moon goes down. Thus, Vitya has to catch the moment when the moon is down. Moon cycle lasts 30 days. The size of the visible part of the moon (in Vitya's units) for each day is 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, and then cycle repeats, thus after the second 1 again goes 0. As there is no internet in the countryside, Vitya has been watching the moon for *n* consecutive days and for each of these days he wrote down the size of the visible part of the moon. Help him find out whether the moon will be up or down next day, or this cannot be determined by the data he has.
The first line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=92) — the number of consecutive days Vitya was watching the size of the visible part of the moon. The second line contains *n* integers *a**i* (0<=≤<=*a**i*<=≤<=15) — Vitya's records. It's guaranteed that the input data is consistent.
If Vitya can be sure that the size of visible part of the moon on day *n*<=+<=1 will be less than the size of the visible part on day *n*, then print "DOWN" at the only line of the output. If he might be sure that the size of the visible part will increase, then print "UP". If it's impossible to determine what exactly will happen with the moon, print -1.
[ "5\n3 4 5 6 7\n", "7\n12 13 14 15 14 13 12\n", "1\n8\n" ]
[ "UP\n", "DOWN\n", "-1\n" ]
In the first sample, the size of the moon on the next day will be equal to 8, thus the answer is "UP". In the second sample, the size of the moon on the next day will be 11, thus the answer is "DOWN". In the third sample, there is no way to determine whether the size of the moon on the next day will be 7 or 9, thus the answer is -1.
500
[ { "input": "5\n3 4 5 6 7", "output": "UP" }, { "input": "7\n12 13 14 15 14 13 12", "output": "DOWN" }, { "input": "1\n8", "output": "-1" }, { "input": "44\n7 8 9 10 11 12 13 14 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 14 13 12 11 10", "output": "DOWN" }, { "input": "92\n3 4 5 6 7 8 9 10 11 12 13 14 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 1 2 3 4", "output": "UP" }, { "input": "6\n10 11 12 13 14 15", "output": "DOWN" }, { "input": "27\n11 10 9 8 7 6 5 4 3 2 1 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15", "output": "DOWN" }, { "input": "6\n8 7 6 5 4 3", "output": "DOWN" }, { "input": "27\n14 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 1 2 3 4 5 6 7 8 9 10", "output": "UP" }, { "input": "79\n7 8 9 10 11 12 13 14 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 14 13 12 11 10 9 8 7 6 5", "output": "DOWN" }, { "input": "25\n1 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 14 13 12 11 10 9 8 7", "output": "DOWN" }, { "input": "21\n3 4 5 6 7 8 9 10 11 12 13 14 15 14 13 12 11 10 9 8 7", "output": "DOWN" }, { "input": "56\n1 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 14 13 12 11 10 9 8 7 6", "output": "DOWN" }, { "input": "19\n4 3 2 1 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14", "output": "UP" }, { "input": "79\n5 4 3 2 1 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 1 2 3 4 5 6 7 8 9 10 11 12 13", "output": "UP" }, { "input": "87\n14 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 1 2 3 4 5 6 7 8 9 10", "output": "UP" }, { "input": "13\n10 9 8 7 6 5 4 3 2 1 0 1 2", "output": "UP" }, { "input": "2\n8 9", "output": "UP" }, { "input": "3\n10 11 12", "output": "UP" }, { "input": "1\n1", "output": "-1" }, { "input": "1\n2", "output": "-1" }, { "input": "1\n3", "output": "-1" }, { "input": "1\n4", "output": "-1" }, { "input": "1\n5", "output": "-1" }, { "input": "1\n6", "output": "-1" }, { "input": "1\n7", "output": "-1" }, { "input": "1\n9", "output": "-1" }, { "input": "1\n10", "output": "-1" }, { "input": "1\n11", "output": "-1" }, { "input": "1\n12", "output": "-1" }, { "input": "1\n13", "output": "-1" }, { "input": "1\n14", "output": "-1" }, { "input": "1\n15", "output": "DOWN" }, { "input": "1\n0", "output": "UP" }, { "input": "3\n11 12 13", "output": "UP" }, { "input": "2\n10 9", "output": "DOWN" }, { "input": "92\n10 11 12 13 14 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 1 2 3 4 5 6 7 8 9 10 11", "output": "UP" }, { "input": "92\n7 6 5 4 3 2 1 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 14 13 12 11 10 9 8 7 6", "output": "DOWN" }, { "input": "2\n14 15", "output": "DOWN" }, { "input": "2\n1 0", "output": "UP" }, { "input": "2\n15 14", "output": "DOWN" }, { "input": "92\n7 8 9 10 11 12 13 14 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 1 2 3 4 5 6 7 8", "output": "UP" }, { "input": "92\n13 12 11 10 9 8 7 6 5 4 3 2 1 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 14 13 12", "output": "DOWN" }, { "input": "92\n4 3 2 1 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 14 13 12 11 10 9 8 7 6 5 4 3", "output": "DOWN" }, { "input": "92\n14 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15", "output": "DOWN" }, { "input": "92\n1 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0", "output": "UP" }, { "input": "2\n2 1", "output": "DOWN" }, { "input": "3\n2 1 0", "output": "UP" }, { "input": "5\n4 3 2 1 0", "output": "UP" }, { "input": "2\n5 4", "output": "DOWN" }, { "input": "4\n3 2 1 0", "output": "UP" }, { "input": "3\n13 12 11", "output": "DOWN" }, { "input": "2\n1 2", "output": "UP" }, { "input": "2\n0 1", "output": "UP" }, { "input": "2\n13 14", "output": "UP" }, { "input": "14\n13 12 11 10 9 8 7 6 5 4 3 2 1 0", "output": "UP" } ]
1,474,637,488
1,588
Python 3
WRONG_ANSWER
PRETESTS
2
46
0
n=int(input()) A = input().split() for i in range(n): A[i] = int(A[i]) if n==1: if A[0]==15: print('DOWN') elif A[0]==0: print('UP') else: print('-1') exit if A[n-1]==15: print('DOWN') elif A[n-1]==0: print('UP') else: if A[n-1]>A[n-2]: print('UP') else: print('DOWN')
Title: Vitya in the Countryside Time Limit: None seconds Memory Limit: None megabytes Problem Description: Every summer Vitya comes to visit his grandmother in the countryside. This summer, he got a huge wart. Every grandma knows that one should treat warts when the moon goes down. Thus, Vitya has to catch the moment when the moon is down. Moon cycle lasts 30 days. The size of the visible part of the moon (in Vitya's units) for each day is 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, and then cycle repeats, thus after the second 1 again goes 0. As there is no internet in the countryside, Vitya has been watching the moon for *n* consecutive days and for each of these days he wrote down the size of the visible part of the moon. Help him find out whether the moon will be up or down next day, or this cannot be determined by the data he has. Input Specification: The first line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=92) — the number of consecutive days Vitya was watching the size of the visible part of the moon. The second line contains *n* integers *a**i* (0<=≤<=*a**i*<=≤<=15) — Vitya's records. It's guaranteed that the input data is consistent. Output Specification: If Vitya can be sure that the size of visible part of the moon on day *n*<=+<=1 will be less than the size of the visible part on day *n*, then print "DOWN" at the only line of the output. If he might be sure that the size of the visible part will increase, then print "UP". If it's impossible to determine what exactly will happen with the moon, print -1. Demo Input: ['5\n3 4 5 6 7\n', '7\n12 13 14 15 14 13 12\n', '1\n8\n'] Demo Output: ['UP\n', 'DOWN\n', '-1\n'] Note: In the first sample, the size of the moon on the next day will be equal to 8, thus the answer is "UP". In the second sample, the size of the moon on the next day will be 11, thus the answer is "DOWN". In the third sample, there is no way to determine whether the size of the moon on the next day will be 7 or 9, thus the answer is -1.
```python n=int(input()) A = input().split() for i in range(n): A[i] = int(A[i]) if n==1: if A[0]==15: print('DOWN') elif A[0]==0: print('UP') else: print('-1') exit if A[n-1]==15: print('DOWN') elif A[n-1]==0: print('UP') else: if A[n-1]>A[n-2]: print('UP') else: print('DOWN') ```
0
682
B
Alyona and Mex
PROGRAMMING
1,200
[ "sortings" ]
null
null
Someone gave Alyona an array containing *n* positive integers *a*1,<=*a*2,<=...,<=*a**n*. In one operation, Alyona can choose any element of the array and decrease it, i.e. replace with any positive integer that is smaller than the current one. Alyona can repeat this operation as many times as she wants. In particular, she may not apply any operation to the array at all. Formally, after applying some operations Alyona will get an array of *n* positive integers *b*1,<=*b*2,<=...,<=*b**n* such that 1<=≤<=*b**i*<=≤<=*a**i* for every 1<=≤<=*i*<=≤<=*n*. Your task is to determine the maximum possible value of mex of this array. Mex of an array in this problem is the minimum positive integer that doesn't appear in this array. For example, mex of the array containing 1, 3 and 4 is equal to 2, while mex of the array containing 2, 3 and 2 is equal to 1.
The first line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=100<=000) — the number of elements in the Alyona's array. The second line of the input contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=109) — the elements of the array.
Print one positive integer — the maximum possible value of mex of the array after Alyona applies some (possibly none) operations.
[ "5\n1 3 3 3 6\n", "2\n2 1\n" ]
[ "5\n", "3\n" ]
In the first sample case if one will decrease the second element value to 2 and the fifth element value to 4 then the mex value of resulting array 1 2 3 3 4 will be equal to 5. To reach the answer to the second sample case one must not decrease any of the array elements.
1,000
[ { "input": "5\n1 3 3 3 6", "output": "5" }, { "input": "2\n2 1", "output": "3" }, { "input": "1\n1", "output": "2" }, { "input": "1\n1000000000", "output": "2" }, { "input": "1\n2", "output": "2" }, { "input": "2\n1 1", "output": "2" }, { "input": "2\n1 3", "output": "3" }, { "input": "2\n2 2", "output": "3" }, { "input": "2\n2 3", "output": "3" }, { "input": "2\n3 3", "output": "3" }, { "input": "3\n1 1 1", "output": "2" }, { "input": "3\n2 1 1", "output": "3" }, { "input": "3\n3 1 1", "output": "3" }, { "input": "3\n1 1 4", "output": "3" }, { "input": "3\n2 1 2", "output": "3" }, { "input": "3\n3 2 1", "output": "4" }, { "input": "3\n2 4 1", "output": "4" }, { "input": "3\n3 3 1", "output": "4" }, { "input": "3\n1 3 4", "output": "4" }, { "input": "3\n4 1 4", "output": "4" }, { "input": "3\n2 2 2", "output": "3" }, { "input": "3\n3 2 2", "output": "4" }, { "input": "3\n4 2 2", "output": "4" }, { "input": "3\n2 3 3", "output": "4" }, { "input": "3\n4 2 3", "output": "4" }, { "input": "3\n4 4 2", "output": "4" }, { "input": "3\n3 3 3", "output": "4" }, { "input": "3\n4 3 3", "output": "4" }, { "input": "3\n4 3 4", "output": "4" }, { "input": "3\n4 4 4", "output": "4" }, { "input": "4\n1 1 1 1", "output": "2" }, { "input": "4\n1 1 2 1", "output": "3" }, { "input": "4\n1 1 3 1", "output": "3" }, { "input": "4\n1 4 1 1", "output": "3" }, { "input": "4\n1 2 1 2", "output": "3" }, { "input": "4\n1 3 2 1", "output": "4" }, { "input": "4\n2 1 4 1", "output": "4" }, { "input": "4\n3 3 1 1", "output": "4" }, { "input": "4\n1 3 4 1", "output": "4" }, { "input": "4\n1 1 4 4", "output": "4" }, { "input": "4\n2 2 2 1", "output": "3" }, { "input": "4\n1 2 2 3", "output": "4" }, { "input": "4\n2 4 1 2", "output": "4" }, { "input": "4\n3 3 1 2", "output": "4" }, { "input": "4\n2 3 4 1", "output": "5" }, { "input": "4\n1 4 2 4", "output": "5" }, { "input": "4\n3 1 3 3", "output": "4" }, { "input": "4\n3 4 3 1", "output": "5" }, { "input": "4\n1 4 4 3", "output": "5" }, { "input": "4\n4 1 4 4", "output": "5" }, { "input": "4\n2 2 2 2", "output": "3" }, { "input": "4\n2 2 3 2", "output": "4" }, { "input": "4\n2 2 2 4", "output": "4" }, { "input": "4\n2 2 3 3", "output": "4" }, { "input": "4\n2 2 3 4", "output": "5" }, { "input": "4\n2 4 4 2", "output": "5" }, { "input": "4\n2 3 3 3", "output": "4" }, { "input": "4\n2 4 3 3", "output": "5" }, { "input": "4\n4 4 2 3", "output": "5" }, { "input": "4\n4 4 4 2", "output": "5" }, { "input": "4\n3 3 3 3", "output": "4" }, { "input": "4\n3 3 3 4", "output": "5" }, { "input": "4\n4 3 3 4", "output": "5" }, { "input": "4\n4 4 3 4", "output": "5" }, { "input": "4\n4 4 4 4", "output": "5" }, { "input": "11\n1 1 1 1 1 1 1 1 1 3 3", "output": "4" }, { "input": "20\n1 1 1 1 1 1 1 1 1 1 8 8 8 8 8 8 8 8 8 8", "output": "9" }, { "input": "4\n2 2 2 3", "output": "4" }, { "input": "3\n1 1 2", "output": "3" }, { "input": "15\n1 2 2 20 23 25 28 60 66 71 76 77 79 99 100", "output": "15" }, { "input": "7\n1 2 2 2 5 5 1", "output": "5" }, { "input": "4\n1 1 1 2", "output": "3" }, { "input": "5\n1 1 1 1 10000", "output": "3" }, { "input": "5\n1 1 1 1 2", "output": "3" }, { "input": "7\n1 3 3 3 3 3 6", "output": "5" }, { "input": "4\n1 1 1 3", "output": "3" }, { "input": "10\n1 1 1 1 1 1 1 1 1 100", "output": "3" }, { "input": "4\n1 1 2 2", "output": "3" }, { "input": "5\n1 1 1 3 4", "output": "4" }, { "input": "8\n1 1 1 1 2 2 3 40", "output": "5" }, { "input": "5\n1 1 1 1 1", "output": "2" }, { "input": "7\n1 2 2 2 2 2 4", "output": "4" }, { "input": "10\n1 1 1 10000000 10000000 10000000 10000000 10000000 10000000 10000000", "output": "9" }, { "input": "10\n1 1 1 1 1 1 1 1 2 3", "output": "4" }, { "input": "4\n8 8 8 8", "output": "5" }, { "input": "5\n5 6 6 6 7", "output": "6" } ]
1,678,467,042
342
PyPy 3
OK
TESTS
127
108
9,830,400
import sys, os, io input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline n = int(input()) a = list(map(int, input().split())) a.sort() ans = 1 for i in a: if ans <= i: ans += 1 print(ans)
Title: Alyona and Mex Time Limit: None seconds Memory Limit: None megabytes Problem Description: Someone gave Alyona an array containing *n* positive integers *a*1,<=*a*2,<=...,<=*a**n*. In one operation, Alyona can choose any element of the array and decrease it, i.e. replace with any positive integer that is smaller than the current one. Alyona can repeat this operation as many times as she wants. In particular, she may not apply any operation to the array at all. Formally, after applying some operations Alyona will get an array of *n* positive integers *b*1,<=*b*2,<=...,<=*b**n* such that 1<=≤<=*b**i*<=≤<=*a**i* for every 1<=≤<=*i*<=≤<=*n*. Your task is to determine the maximum possible value of mex of this array. Mex of an array in this problem is the minimum positive integer that doesn't appear in this array. For example, mex of the array containing 1, 3 and 4 is equal to 2, while mex of the array containing 2, 3 and 2 is equal to 1. Input Specification: The first line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=100<=000) — the number of elements in the Alyona's array. The second line of the input contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=109) — the elements of the array. Output Specification: Print one positive integer — the maximum possible value of mex of the array after Alyona applies some (possibly none) operations. Demo Input: ['5\n1 3 3 3 6\n', '2\n2 1\n'] Demo Output: ['5\n', '3\n'] Note: In the first sample case if one will decrease the second element value to 2 and the fifth element value to 4 then the mex value of resulting array 1 2 3 3 4 will be equal to 5. To reach the answer to the second sample case one must not decrease any of the array elements.
```python import sys, os, io input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline n = int(input()) a = list(map(int, input().split())) a.sort() ans = 1 for i in a: if ans <= i: ans += 1 print(ans) ```
3
672
B
Different is Good
PROGRAMMING
1,000
[ "constructive algorithms", "implementation", "strings" ]
null
null
A wise man told Kerem "Different is good" once, so Kerem wants all things in his life to be different. Kerem recently got a string *s* consisting of lowercase English letters. Since Kerem likes it when things are different, he wants all substrings of his string *s* to be distinct. Substring is a string formed by some number of consecutive characters of the string. For example, string "aba" has substrings "" (empty substring), "a", "b", "a", "ab", "ba", "aba". If string *s* has at least two equal substrings then Kerem will change characters at some positions to some other lowercase English letters. Changing characters is a very tiring job, so Kerem want to perform as few changes as possible. Your task is to find the minimum number of changes needed to make all the substrings of the given string distinct, or determine that it is impossible.
The first line of the input contains an integer *n* (1<=≤<=*n*<=≤<=100<=000) — the length of the string *s*. The second line contains the string *s* of length *n* consisting of only lowercase English letters.
If it's impossible to change the string *s* such that all its substring are distinct print -1. Otherwise print the minimum required number of changes.
[ "2\naa\n", "4\nkoko\n", "5\nmurat\n" ]
[ "1\n", "2\n", "0\n" ]
In the first sample one of the possible solutions is to change the first character to 'b'. In the second sample, one may change the first character to 'a' and second character to 'b', so the string becomes "abko".
1,000
[ { "input": "2\naa", "output": "1" }, { "input": "4\nkoko", "output": "2" }, { "input": "5\nmurat", "output": "0" }, { "input": "6\nacbead", "output": "1" }, { "input": "7\ncdaadad", "output": "4" }, { "input": "25\npeoaicnbisdocqofsqdpgobpn", "output": "12" }, { "input": "25\ntcqpchnqskqjacruoaqilgebu", "output": "7" }, { "input": "13\naebaecedabbee", "output": "8" }, { "input": "27\naaaaaaaaaaaaaaaaaaaaaaaaaaa", "output": "-1" }, { "input": "10\nbababbdaee", "output": "6" }, { "input": "11\ndbadcdbdbca", "output": "7" }, { "input": "12\nacceaabddaaa", "output": "7" }, { "input": "13\nabddfbfaeecfa", "output": "7" }, { "input": "14\neeceecacdbcbbb", "output": "9" }, { "input": "15\ndcbceaaggabaheb", "output": "8" }, { "input": "16\nhgiegfbadgcicbhd", "output": "7" }, { "input": "17\nabhfibbdddfghgfdi", "output": "10" }, { "input": "26\nbbbbbabbaababaaabaaababbaa", "output": "24" }, { "input": "26\nahnxdnbfbcrirerssyzydihuee", "output": "11" }, { "input": "26\nhwqeqhkpxwulbsiwmnlfyhgknc", "output": "8" }, { "input": "26\nrvxmulriorilidecqwmfaemifj", "output": "10" }, { "input": "26\naowpmreooavnmamogdoopuisge", "output": "12" }, { "input": "26\ninimevtuefhvuefirdehmmfudh", "output": "15" }, { "input": "26\naaaaaaaaaaaaaaaaaaaaaaaaaa", "output": "25" }, { "input": "27\nqdcfjtblgglnilgassirrjekcjt", "output": "-1" }, { "input": "27\nabcdefghijklmnopqrstuvwxyza", "output": "-1" }, { "input": "26\nqwertyuiopasdfghjklzxcvbnm", "output": "0" }, { "input": "5\nzzzzz", "output": "4" }, { "input": "27\naaaaaaaaaaaaaaaaabaaaaaaaaa", "output": "-1" }, { "input": "1\nq", "output": "0" }, { "input": "27\nqwertyuioplkjhgfdsazxcvbnmm", "output": "-1" }, { "input": "9\nxxxyyyzzz", "output": "6" }, { "input": "45\naaabbbcccdddeeefffgghhiijjkkkkkkkkkkkkkkkkkkk", "output": "-1" }, { "input": "27\nqwertyuiopasdfghjklzxcvbnmm", "output": "-1" }, { "input": "26\nabcdefghijklmnopqrstuvwxyz", "output": "0" }, { "input": "26\nabcdefghijklmnopqrstuvwxya", "output": "1" }, { "input": "27\nabcdefghijklmnopqrstuvwxyzz", "output": "-1" }, { "input": "26\naaaaaaaaaaaaaaaaaaaaaaaaaa", "output": "25" }, { "input": "26\nqwertyuioplkjhgfdsazxcvbnm", "output": "0" }, { "input": "10\nzzzzzzzzzz", "output": "9" }, { "input": "1\na", "output": "0" }, { "input": "30\nabcdefghtyabcdefghtyabcdefghty", "output": "-1" } ]
1,623,411,538
2,147,483,647
Python 3
MEMORY_LIMIT_EXCEEDED
TESTS
7
265
268,390,400
N = int(input()) s = input() ls = list(s) for i in range(N-1): ls.append(s[:i + 2]) ls_unique = len(set(ls)) count = len(ls) - ls_unique print(count)
Title: Different is Good Time Limit: None seconds Memory Limit: None megabytes Problem Description: A wise man told Kerem "Different is good" once, so Kerem wants all things in his life to be different. Kerem recently got a string *s* consisting of lowercase English letters. Since Kerem likes it when things are different, he wants all substrings of his string *s* to be distinct. Substring is a string formed by some number of consecutive characters of the string. For example, string "aba" has substrings "" (empty substring), "a", "b", "a", "ab", "ba", "aba". If string *s* has at least two equal substrings then Kerem will change characters at some positions to some other lowercase English letters. Changing characters is a very tiring job, so Kerem want to perform as few changes as possible. Your task is to find the minimum number of changes needed to make all the substrings of the given string distinct, or determine that it is impossible. Input Specification: The first line of the input contains an integer *n* (1<=≤<=*n*<=≤<=100<=000) — the length of the string *s*. The second line contains the string *s* of length *n* consisting of only lowercase English letters. Output Specification: If it's impossible to change the string *s* such that all its substring are distinct print -1. Otherwise print the minimum required number of changes. Demo Input: ['2\naa\n', '4\nkoko\n', '5\nmurat\n'] Demo Output: ['1\n', '2\n', '0\n'] Note: In the first sample one of the possible solutions is to change the first character to 'b'. In the second sample, one may change the first character to 'a' and second character to 'b', so the string becomes "abko".
```python N = int(input()) s = input() ls = list(s) for i in range(N-1): ls.append(s[:i + 2]) ls_unique = len(set(ls)) count = len(ls) - ls_unique print(count) ```
0
0
none
none
none
0
[ "none" ]
null
null
Alyona's mother wants to present an array of *n* non-negative integers to Alyona. The array should be special. Alyona is a capricious girl so after she gets the array, she inspects *m* of its subarrays. Subarray is a set of some subsequent elements of the array. The *i*-th subarray is described with two integers *l**i* and *r**i*, and its elements are *a*[*l**i*],<=*a*[*l**i*<=+<=1],<=...,<=*a*[*r**i*]. Alyona is going to find mex for each of the chosen subarrays. Among these *m* mexes the girl is going to find the smallest. She wants this minimum mex to be as large as possible. You are to find an array *a* of *n* elements so that the minimum mex among those chosen by Alyona subarrays is as large as possible. The mex of a set *S* is a minimum possible non-negative integer that is not in *S*.
The first line contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=105). The next *m* lines contain information about the subarrays chosen by Alyona. The *i*-th of these lines contains two integers *l**i* and *r**i* (1<=≤<=*l**i*<=≤<=*r**i*<=≤<=*n*), that describe the subarray *a*[*l**i*],<=*a*[*l**i*<=+<=1],<=...,<=*a*[*r**i*].
In the first line print single integer — the maximum possible minimum mex. In the second line print *n* integers — the array *a*. All the elements in *a* should be between 0 and 109. It is guaranteed that there is an optimal answer in which all the elements in *a* are between 0 and 109. If there are multiple solutions, print any of them.
[ "5 3\n1 3\n2 5\n4 5\n", "4 2\n1 4\n2 4\n" ]
[ "2\n1 0 2 1 0\n", "3\n5 2 0 1" ]
The first example: the mex of the subarray (1, 3) is equal to 3, the mex of the subarray (2, 5) is equal to 3, the mex of the subarray (4, 5) is equal to 2 as well, thus the minumal mex among the subarrays chosen by Alyona is equal to 2.
0
[ { "input": "5 3\n1 3\n2 5\n4 5", "output": "2\n0 1 0 1 0" }, { "input": "4 2\n1 4\n2 4", "output": "3\n0 1 2 0" }, { "input": "1 1\n1 1", "output": "1\n0" }, { "input": "2 1\n2 2", "output": "1\n0 0" }, { "input": "5 6\n2 4\n2 3\n1 4\n3 4\n2 5\n1 3", "output": "2\n0 1 0 1 0" }, { "input": "8 3\n2 3\n2 8\n3 6", "output": "2\n0 1 0 1 0 1 0 1" }, { "input": "10 10\n1 9\n4 8\n4 8\n5 9\n1 9\n3 8\n1 6\n1 9\n1 6\n6 9", "output": "4\n0 1 2 3 0 1 2 3 0 1" }, { "input": "3 6\n1 3\n1 3\n1 1\n1 1\n3 3\n3 3", "output": "1\n0 0 0" }, { "input": "3 3\n1 3\n2 2\n1 3", "output": "1\n0 0 0" }, { "input": "6 8\n3 5\n3 6\n4 6\n2 5\n2 5\n1 3\n3 6\n3 5", "output": "3\n0 1 2 0 1 2" }, { "input": "10 4\n4 10\n4 6\n6 8\n1 10", "output": "3\n0 1 2 0 1 2 0 1 2 0" }, { "input": "9 1\n1 1", "output": "1\n0 0 0 0 0 0 0 0 0" }, { "input": "3 8\n2 3\n1 3\n1 2\n2 3\n1 3\n2 2\n1 2\n1 2", "output": "1\n0 0 0" }, { "input": "3 8\n1 2\n1 2\n1 1\n2 3\n2 3\n1 1\n1 3\n1 3", "output": "1\n0 0 0" }, { "input": "7 3\n7 7\n3 7\n5 7", "output": "1\n0 0 0 0 0 0 0" }, { "input": "9 9\n4 5\n5 8\n1 8\n4 8\n3 4\n7 8\n1 4\n7 8\n6 7", "output": "2\n0 1 0 1 0 1 0 1 0" }, { "input": "10 10\n1 5\n7 10\n2 10\n2 5\n2 9\n5 9\n3 10\n4 9\n6 9\n2 7", "output": "4\n0 1 2 3 0 1 2 3 0 1" }, { "input": "8 7\n5 8\n3 7\n1 8\n3 4\n2 8\n2 7\n4 6", "output": "2\n0 1 0 1 0 1 0 1" }, { "input": "10 3\n2 4\n8 10\n4 6", "output": "3\n0 1 2 0 1 2 0 1 2 0" }, { "input": "5 8\n3 4\n1 5\n3 4\n3 5\n3 4\n1 4\n1 5\n2 5", "output": "2\n0 1 0 1 0" }, { "input": "9 4\n5 9\n3 8\n2 8\n1 4", "output": "4\n0 1 2 3 0 1 2 3 0" }, { "input": "7 7\n2 4\n1 4\n3 6\n2 6\n5 7\n3 6\n1 4", "output": "3\n0 1 2 0 1 2 0" }, { "input": "6 2\n4 6\n2 5", "output": "3\n0 1 2 0 1 2" }, { "input": "7 9\n6 7\n1 2\n2 5\n4 7\n1 7\n5 6\n2 3\n6 7\n1 2", "output": "2\n0 1 0 1 0 1 0" } ]
1,479,925,345
6,445
Python 3
WRONG_ANSWER
PRETESTS
4
77
0
n , m = map(int, input().split()) mn = 10 ** 10 event = set() for i in range(m): b, e = map(int, input().split()) if mn > e - b: mn = e - b + 2 event.add(b - 1) k = 0 print(mn - 1) for i in range(n): if i in event: k = 0 print(k % mn, end = " ") k+=1
Title: none Time Limit: None seconds Memory Limit: None megabytes Problem Description: Alyona's mother wants to present an array of *n* non-negative integers to Alyona. The array should be special. Alyona is a capricious girl so after she gets the array, she inspects *m* of its subarrays. Subarray is a set of some subsequent elements of the array. The *i*-th subarray is described with two integers *l**i* and *r**i*, and its elements are *a*[*l**i*],<=*a*[*l**i*<=+<=1],<=...,<=*a*[*r**i*]. Alyona is going to find mex for each of the chosen subarrays. Among these *m* mexes the girl is going to find the smallest. She wants this minimum mex to be as large as possible. You are to find an array *a* of *n* elements so that the minimum mex among those chosen by Alyona subarrays is as large as possible. The mex of a set *S* is a minimum possible non-negative integer that is not in *S*. Input Specification: The first line contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=105). The next *m* lines contain information about the subarrays chosen by Alyona. The *i*-th of these lines contains two integers *l**i* and *r**i* (1<=≤<=*l**i*<=≤<=*r**i*<=≤<=*n*), that describe the subarray *a*[*l**i*],<=*a*[*l**i*<=+<=1],<=...,<=*a*[*r**i*]. Output Specification: In the first line print single integer — the maximum possible minimum mex. In the second line print *n* integers — the array *a*. All the elements in *a* should be between 0 and 109. It is guaranteed that there is an optimal answer in which all the elements in *a* are between 0 and 109. If there are multiple solutions, print any of them. Demo Input: ['5 3\n1 3\n2 5\n4 5\n', '4 2\n1 4\n2 4\n'] Demo Output: ['2\n1 0 2 1 0\n', '3\n5 2 0 1'] Note: The first example: the mex of the subarray (1, 3) is equal to 3, the mex of the subarray (2, 5) is equal to 3, the mex of the subarray (4, 5) is equal to 2 as well, thus the minumal mex among the subarrays chosen by Alyona is equal to 2.
```python n , m = map(int, input().split()) mn = 10 ** 10 event = set() for i in range(m): b, e = map(int, input().split()) if mn > e - b: mn = e - b + 2 event.add(b - 1) k = 0 print(mn - 1) for i in range(n): if i in event: k = 0 print(k % mn, end = " ") k+=1 ```
0
957
A
Tritonic Iridescence
PROGRAMMING
1,300
[ "implementation" ]
null
null
Overlooking the captivating blend of myriads of vernal hues, Arkady the painter lays out a long, long canvas. Arkady has a sufficiently large amount of paint of three colours: cyan, magenta, and yellow. On the one-dimensional canvas split into *n* consecutive segments, each segment needs to be painted in one of the colours. Arkady has already painted some (possibly none or all) segments and passes the paintbrush to you. You are to determine whether there are at least two ways of colouring all the unpainted segments so that no two adjacent segments are of the same colour. Two ways are considered different if and only if a segment is painted in different colours in them.
The first line contains a single positive integer *n* (1<=≤<=*n*<=≤<=100) — the length of the canvas. The second line contains a string *s* of *n* characters, the *i*-th of which is either 'C' (denoting a segment painted in cyan), 'M' (denoting one painted in magenta), 'Y' (one painted in yellow), or '?' (an unpainted one).
If there are at least two different ways of painting, output "Yes"; otherwise output "No" (both without quotes). You can print each character in any case (upper or lower).
[ "5\nCY??Y\n", "5\nC?C?Y\n", "5\n?CYC?\n", "5\nC??MM\n", "3\nMMY\n" ]
[ "Yes\n", "Yes\n", "Yes\n", "No\n", "No\n" ]
For the first example, there are exactly two different ways of colouring: CYCMY and CYMCY. For the second example, there are also exactly two different ways of colouring: CMCMY and CYCMY. For the third example, there are four ways of colouring: MCYCM, MCYCY, YCYCM, and YCYCY. For the fourth example, no matter how the unpainted segments are coloured, the existing magenta segments will prevent the painting from satisfying the requirements. The similar is true for the fifth example.
500
[ { "input": "5\nCY??Y", "output": "Yes" }, { "input": "5\nC?C?Y", "output": "Yes" }, { "input": "5\n?CYC?", "output": "Yes" }, { "input": "5\nC??MM", "output": "No" }, { "input": "3\nMMY", "output": "No" }, { "input": "15\n??YYYYYY??YYYY?", "output": "No" }, { "input": "100\nYCY?CMCMCYMYMYC?YMYMYMY?CMC?MCMYCMYMYCM?CMCM?CMYMYCYCMCMCMCMCMYM?CYCYCMCM?CY?MYCYCMYM?CYCYCYMY?CYCYC", "output": "No" }, { "input": "1\nC", "output": "No" }, { "input": "1\n?", "output": "Yes" }, { "input": "2\nMY", "output": "No" }, { "input": "2\n?M", "output": "Yes" }, { "input": "2\nY?", "output": "Yes" }, { "input": "2\n??", "output": "Yes" }, { "input": "3\n??C", "output": "Yes" }, { "input": "3\nM??", "output": "Yes" }, { "input": "3\nYCM", "output": "No" }, { "input": "3\n?C?", "output": "Yes" }, { "input": "3\nMC?", "output": "Yes" }, { "input": "4\nCYCM", "output": "No" }, { "input": "4\nM?CM", "output": "No" }, { "input": "4\n??YM", "output": "Yes" }, { "input": "4\nC???", "output": "Yes" }, { "input": "10\nMCYM?MYM?C", "output": "Yes" }, { "input": "50\nCMCMCYM?MY?C?MC??YM?CY?YM??M?MCMCYCYMCYCMCM?MCM?MC", "output": "Yes" }, { "input": "97\nMCM?YCMYM?YMY?MY?MYCY?CMCMCYC?YMY?MYCMC?M?YCMC?YM?C?MCMCMYMCMY?MCM?YC?YMYMY?MYCYCM?YC?YCY?MYMYMYC", "output": "No" }, { "input": "100\nC?M?M?M?YM??YMYC?MCYMYM??Y??YC?CYC???YM?YM??MYMY?CYCYMYC?YC?C?CYCMY??CMC?YMCMYCYCYMYM?CYM?M?MCMCMY?Y", "output": "Yes" }, { "input": "100\n?YYYYYYYYYYYYYYYYYYYYYYYYYYYYY??YYY?YYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYY?", "output": "No" }, { "input": "100\n????????????????????????????????????????????????????????????????????????????????????????????????????", "output": "Yes" }, { "input": "100\nY?CYMYMYMYCYMY?CMCYMYMC?MYCY?CMCYCYMCM?YCMCYMYCYCY?MYMYCYCYCM?CYMYMY?CY?MYCYCY?M?YMYCY?CMCMCY?CY?M?C", "output": "No" }, { "input": "4\nM??C", "output": "Yes" }, { "input": "6\nY?C??C", "output": "Yes" }, { "input": "5\nC???Y", "output": "Yes" }, { "input": "5\nC??MY", "output": "Yes" }, { "input": "5\nCY??M", "output": "Yes" }, { "input": "4\nC??Y", "output": "Yes" }, { "input": "52\n??????????????????????????????????????????????????YY", "output": "No" }, { "input": "3\nYY?", "output": "No" }, { "input": "5\nCC??Y", "output": "No" }, { "input": "8\nCMC??MCM", "output": "Yes" }, { "input": "7\nM?YCM??", "output": "Yes" }, { "input": "6\n?CC???", "output": "No" }, { "input": "100\n??????????????????????????????????????????????????????????????????????????????????????????????????MM", "output": "No" }, { "input": "4\nC??M", "output": "Yes" }, { "input": "4\n?C?M", "output": "Yes" }, { "input": "6\nMC??MC", "output": "Yes" } ]
1,525,591,333
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
2
93
7,065,600
n = int(input()); s = input(); def f(): for i in range(n-1): if s[i] == s[i+1] and s[i] != "?": return False if "??" in s: return True if "C?C" in s or "M?M" in s or "Y?Y" in s: return True return False if f(): print("Yes") else: print("No")
Title: Tritonic Iridescence Time Limit: None seconds Memory Limit: None megabytes Problem Description: Overlooking the captivating blend of myriads of vernal hues, Arkady the painter lays out a long, long canvas. Arkady has a sufficiently large amount of paint of three colours: cyan, magenta, and yellow. On the one-dimensional canvas split into *n* consecutive segments, each segment needs to be painted in one of the colours. Arkady has already painted some (possibly none or all) segments and passes the paintbrush to you. You are to determine whether there are at least two ways of colouring all the unpainted segments so that no two adjacent segments are of the same colour. Two ways are considered different if and only if a segment is painted in different colours in them. Input Specification: The first line contains a single positive integer *n* (1<=≤<=*n*<=≤<=100) — the length of the canvas. The second line contains a string *s* of *n* characters, the *i*-th of which is either 'C' (denoting a segment painted in cyan), 'M' (denoting one painted in magenta), 'Y' (one painted in yellow), or '?' (an unpainted one). Output Specification: If there are at least two different ways of painting, output "Yes"; otherwise output "No" (both without quotes). You can print each character in any case (upper or lower). Demo Input: ['5\nCY??Y\n', '5\nC?C?Y\n', '5\n?CYC?\n', '5\nC??MM\n', '3\nMMY\n'] Demo Output: ['Yes\n', 'Yes\n', 'Yes\n', 'No\n', 'No\n'] Note: For the first example, there are exactly two different ways of colouring: CYCMY and CYMCY. For the second example, there are also exactly two different ways of colouring: CMCMY and CYCMY. For the third example, there are four ways of colouring: MCYCM, MCYCY, YCYCM, and YCYCY. For the fourth example, no matter how the unpainted segments are coloured, the existing magenta segments will prevent the painting from satisfying the requirements. The similar is true for the fifth example.
```python n = int(input()); s = input(); def f(): for i in range(n-1): if s[i] == s[i+1] and s[i] != "?": return False if "??" in s: return True if "C?C" in s or "M?M" in s or "Y?Y" in s: return True return False if f(): print("Yes") else: print("No") ```
0
92
A
Chips
PROGRAMMING
800
[ "implementation", "math" ]
A. Chips
2
256
There are *n* walruses sitting in a circle. All of them are numbered in the clockwise order: the walrus number 2 sits to the left of the walrus number 1, the walrus number 3 sits to the left of the walrus number 2, ..., the walrus number 1 sits to the left of the walrus number *n*. The presenter has *m* chips. The presenter stands in the middle of the circle and starts giving the chips to the walruses starting from walrus number 1 and moving clockwise. The walrus number *i* gets *i* chips. If the presenter can't give the current walrus the required number of chips, then the presenter takes the remaining chips and the process ends. Determine by the given *n* and *m* how many chips the presenter will get in the end.
The first line contains two integers *n* and *m* (1<=≤<=*n*<=≤<=50, 1<=≤<=*m*<=≤<=104) — the number of walruses and the number of chips correspondingly.
Print the number of chips the presenter ended up with.
[ "4 11\n", "17 107\n", "3 8\n" ]
[ "0\n", "2\n", "1\n" ]
In the first sample the presenter gives one chip to the walrus number 1, two chips to the walrus number 2, three chips to the walrus number 3, four chips to the walrus number 4, then again one chip to the walrus number 1. After that the presenter runs out of chips. He can't give anything to the walrus number 2 and the process finishes. In the third sample the presenter gives one chip to the walrus number 1, two chips to the walrus number 2, three chips to the walrus number 3, then again one chip to the walrus number 1. The presenter has one chip left and he can't give two chips to the walrus number 2, that's why the presenter takes the last chip.
500
[ { "input": "4 11", "output": "0" }, { "input": "17 107", "output": "2" }, { "input": "3 8", "output": "1" }, { "input": "46 7262", "output": "35" }, { "input": "32 6864", "output": "0" }, { "input": "36 6218", "output": "14" }, { "input": "25 9712", "output": "11" }, { "input": "9 7601", "output": "5" }, { "input": "1 9058", "output": "0" }, { "input": "29 7772", "output": "26" }, { "input": "45 9465", "output": "14" }, { "input": "46 866", "output": "5" }, { "input": "29 1241", "output": "20" }, { "input": "17 4248", "output": "12" }, { "input": "20 8082", "output": "11" }, { "input": "50 9555", "output": "0" }, { "input": "4 7455", "output": "2" }, { "input": "36 880", "output": "4" }, { "input": "24 7440", "output": "9" }, { "input": "44 7888", "output": "12" }, { "input": "1 1", "output": "0" }, { "input": "50 10000", "output": "40" }, { "input": "1 10000", "output": "0" }, { "input": "50 1", "output": "0" }, { "input": "50 50", "output": "5" } ]
1,578,924,796
2,147,483,647
Python 3
OK
TESTS
25
218
0
m,n=map(int,input().split()) t=False while not t: for x in range(m): if n>=x+1: n-=x+1 else: t=True break print(n)
Title: Chips Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: There are *n* walruses sitting in a circle. All of them are numbered in the clockwise order: the walrus number 2 sits to the left of the walrus number 1, the walrus number 3 sits to the left of the walrus number 2, ..., the walrus number 1 sits to the left of the walrus number *n*. The presenter has *m* chips. The presenter stands in the middle of the circle and starts giving the chips to the walruses starting from walrus number 1 and moving clockwise. The walrus number *i* gets *i* chips. If the presenter can't give the current walrus the required number of chips, then the presenter takes the remaining chips and the process ends. Determine by the given *n* and *m* how many chips the presenter will get in the end. Input Specification: The first line contains two integers *n* and *m* (1<=≤<=*n*<=≤<=50, 1<=≤<=*m*<=≤<=104) — the number of walruses and the number of chips correspondingly. Output Specification: Print the number of chips the presenter ended up with. Demo Input: ['4 11\n', '17 107\n', '3 8\n'] Demo Output: ['0\n', '2\n', '1\n'] Note: In the first sample the presenter gives one chip to the walrus number 1, two chips to the walrus number 2, three chips to the walrus number 3, four chips to the walrus number 4, then again one chip to the walrus number 1. After that the presenter runs out of chips. He can't give anything to the walrus number 2 and the process finishes. In the third sample the presenter gives one chip to the walrus number 1, two chips to the walrus number 2, three chips to the walrus number 3, then again one chip to the walrus number 1. The presenter has one chip left and he can't give two chips to the walrus number 2, that's why the presenter takes the last chip.
```python m,n=map(int,input().split()) t=False while not t: for x in range(m): if n>=x+1: n-=x+1 else: t=True break print(n) ```
3.9455
27
B
Tournament
PROGRAMMING
1,300
[ "bitmasks", "brute force", "dfs and similar", "greedy" ]
B. Tournament
2
256
The tournament «Sleepyhead-2010» in the rapid falling asleep has just finished in Berland. *n* best participants from the country have participated in it. The tournament consists of games, each of them is a match between two participants. *n*·(*n*<=-<=1)<=/<=2 games were played during the tournament, and each participant had a match with each other participant. The rules of the game are quite simple — the participant who falls asleep first wins. The secretary made a record of each game in the form «*x**i* *y**i*», where *x**i* and *y**i* are the numbers of participants. The first number in each pair is a winner (i.e. *x**i* is a winner and *y**i* is a loser). There is no draws. Recently researches form the «Institute Of Sleep» have found that every person is characterized by a value *p**j* — the speed of falling asleep. The person who has lower speed wins. Every person has its own value *p**j*, constant during the life. It is known that all participants of the tournament have distinct speeds of falling asleep. Also it was found that the secretary made records about all the games except one. You are to find the result of the missing game.
The first line contains one integer *n* (3<=≤<=*n*<=≤<=50) — the number of participants. The following *n*·(*n*<=-<=1)<=/<=2<=-<=1 lines contain the results of the games. Each game is described in a single line by two integers *x**i*,<=*y**i* (1<=≤<=*x**i*,<=*y**i*<=≤<=*n*,<=*x**i*<=≠<=*y**i*), where *x**i* и *y**i* are the numbers of the opponents in this game. It is known that during the tournament each of the *n* participants played *n*<=-<=1 games, one game with each other participant.
Output two integers *x* and *y* — the missing record. If there are several solutions, output any of them.
[ "4\n4 2\n4 1\n2 3\n2 1\n3 1\n" ]
[ "4 3\n" ]
none
1,000
[ { "input": "3\n3 2\n1 2", "output": "1 3" }, { "input": "4\n2 4\n3 4\n1 2\n1 4\n1 3", "output": "2 3" }, { "input": "5\n3 5\n2 5\n1 5\n1 4\n4 3\n1 3\n2 3\n4 5\n4 2", "output": "1 2" }, { "input": "6\n3 4\n3 5\n5 4\n1 2\n5 6\n2 6\n5 2\n3 6\n3 2\n4 6\n2 4\n1 3\n1 5\n1 4", "output": "1 6" }, { "input": "7\n2 4\n6 1\n6 5\n3 4\n6 3\n2 6\n6 4\n3 7\n7 1\n1 4\n7 4\n7 5\n2 7\n2 3\n5 4\n3 5\n3 1\n5 1\n6 7\n2 1", "output": "2 5" }, { "input": "8\n4 3\n6 8\n1 5\n8 3\n1 4\n1 7\n5 6\n5 3\n5 8\n7 3\n7 8\n2 3\n1 3\n2 8\n1 6\n5 4\n1 2\n2 5\n4 8\n1 8\n2 6\n2 7\n4 7\n2 4\n6 4\n6 7\n6 3", "output": "5 7" }, { "input": "9\n4 5\n9 6\n5 6\n8 7\n5 1\n8 5\n9 5\n4 7\n2 6\n7 6\n3 5\n2 1\n8 2\n3 7\n9 1\n2 5\n2 7\n4 2\n8 9\n8 1\n3 6\n7 1\n8 6\n3 2\n3 1\n9 2\n4 6\n5 7\n1 6\n4 8\n4 1\n4 3\n4 9\n9 3\n9 7", "output": "8 3" }, { "input": "3\n3 2\n1 2", "output": "1 3" }, { "input": "3\n1 3\n2 3", "output": "1 2" }, { "input": "3\n2 1\n3 1", "output": "2 3" }, { "input": "4\n3 1\n4 1\n4 2\n3 2\n3 4", "output": "1 2" }, { "input": "4\n3 4\n1 4\n2 3\n2 1\n2 4", "output": "1 3" }, { "input": "4\n2 3\n1 3\n2 1\n4 1\n4 3", "output": "2 4" }, { "input": "5\n5 2\n3 1\n5 3\n5 1\n3 4\n1 4\n3 2\n1 2\n5 4", "output": "2 4" }, { "input": "5\n2 1\n4 1\n5 1\n4 5\n3 5\n2 3\n3 1\n2 5\n2 4", "output": "3 4" }, { "input": "5\n4 5\n4 3\n5 3\n4 1\n3 1\n3 2\n5 2\n4 2\n5 1", "output": "1 2" }, { "input": "5\n4 5\n1 5\n4 3\n2 5\n2 1\n2 4\n3 5\n2 3\n1 3", "output": "1 4" }, { "input": "5\n2 4\n5 3\n5 4\n2 5\n1 4\n2 3\n1 5\n1 3\n1 2", "output": "3 4" }, { "input": "6\n6 1\n5 6\n4 1\n3 1\n3 4\n4 6\n4 5\n3 2\n4 2\n6 2\n5 1\n3 5\n3 6\n5 2", "output": "1 2" }, { "input": "6\n6 2\n6 4\n4 1\n4 3\n5 6\n5 2\n6 3\n5 1\n5 3\n2 1\n2 3\n6 1\n3 1\n5 4", "output": "2 4" }, { "input": "6\n5 3\n6 5\n3 4\n1 5\n2 3\n6 2\n2 5\n5 4\n6 4\n1 4\n6 3\n6 1\n2 4\n1 3", "output": "1 2" }, { "input": "6\n3 1\n5 4\n2 1\n6 2\n5 2\n3 6\n6 4\n3 2\n3 4\n6 1\n6 5\n5 1\n2 4\n3 5", "output": "1 4" }, { "input": "6\n6 1\n1 3\n3 4\n6 3\n2 4\n6 2\n1 5\n5 3\n5 4\n6 4\n1 2\n1 4\n6 5\n5 2", "output": "2 3" } ]
1,602,482,402
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
0
154
204,800
def solution(): n = int(input()) # number of participants cnt = {} # find the missing record for i in range(n * (n - 1) // 2 - 1): player = [int(i) for i in input().split()] if player[0] in cnt: cnt[player[0]][0].append(player[1]) else: cnt[player[0]] = [[player[1]], []] if player[1] in cnt: cnt[player[1]][1].append(player[0]) else: cnt[player[1]] = [[], [player[0]]] res = [] for i in cnt: if len(cnt[i][0]) + len(cnt[i][1]) < n - 1: res.append(i) # find the match result using the given match results queue = [res[0]] head = 0 visited = {res[0]} while head < len(queue): print(queue) if queue[head] == res[1]: print(res[0], res[1]) break for i in cnt[queue[head]][0]: if i not in visited: visited.add(i) queue.append(i) head += 1 else: print(res[1], res[0]) if __name__ == '__main__': solution()
Title: Tournament Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: The tournament «Sleepyhead-2010» in the rapid falling asleep has just finished in Berland. *n* best participants from the country have participated in it. The tournament consists of games, each of them is a match between two participants. *n*·(*n*<=-<=1)<=/<=2 games were played during the tournament, and each participant had a match with each other participant. The rules of the game are quite simple — the participant who falls asleep first wins. The secretary made a record of each game in the form «*x**i* *y**i*», where *x**i* and *y**i* are the numbers of participants. The first number in each pair is a winner (i.e. *x**i* is a winner and *y**i* is a loser). There is no draws. Recently researches form the «Institute Of Sleep» have found that every person is characterized by a value *p**j* — the speed of falling asleep. The person who has lower speed wins. Every person has its own value *p**j*, constant during the life. It is known that all participants of the tournament have distinct speeds of falling asleep. Also it was found that the secretary made records about all the games except one. You are to find the result of the missing game. Input Specification: The first line contains one integer *n* (3<=≤<=*n*<=≤<=50) — the number of participants. The following *n*·(*n*<=-<=1)<=/<=2<=-<=1 lines contain the results of the games. Each game is described in a single line by two integers *x**i*,<=*y**i* (1<=≤<=*x**i*,<=*y**i*<=≤<=*n*,<=*x**i*<=≠<=*y**i*), where *x**i* и *y**i* are the numbers of the opponents in this game. It is known that during the tournament each of the *n* participants played *n*<=-<=1 games, one game with each other participant. Output Specification: Output two integers *x* and *y* — the missing record. If there are several solutions, output any of them. Demo Input: ['4\n4 2\n4 1\n2 3\n2 1\n3 1\n'] Demo Output: ['4 3\n'] Note: none
```python def solution(): n = int(input()) # number of participants cnt = {} # find the missing record for i in range(n * (n - 1) // 2 - 1): player = [int(i) for i in input().split()] if player[0] in cnt: cnt[player[0]][0].append(player[1]) else: cnt[player[0]] = [[player[1]], []] if player[1] in cnt: cnt[player[1]][1].append(player[0]) else: cnt[player[1]] = [[], [player[0]]] res = [] for i in cnt: if len(cnt[i][0]) + len(cnt[i][1]) < n - 1: res.append(i) # find the match result using the given match results queue = [res[0]] head = 0 visited = {res[0]} while head < len(queue): print(queue) if queue[head] == res[1]: print(res[0], res[1]) break for i in cnt[queue[head]][0]: if i not in visited: visited.add(i) queue.append(i) head += 1 else: print(res[1], res[0]) if __name__ == '__main__': solution() ```
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,685,454,729
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
4
31
0
x=int(input()) y=list(map(int,input().split())) i=0 s=x while x>=1: if y[i]==x: while x>=s: print(x,end=' ') x-=1 else: print(' ') if y[i]<s: s=y[i] i+=1
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 x=int(input()) y=list(map(int,input().split())) i=0 s=x while x>=1: if y[i]==x: while x>=s: print(x,end=' ') x-=1 else: print(' ') if y[i]<s: s=y[i] i+=1 ```
0
849
A
Odds and Ends
PROGRAMMING
1,000
[ "implementation" ]
null
null
Where do odds begin, and where do they end? Where does hope emerge, and will they ever break? Given an integer sequence *a*1,<=*a*2,<=...,<=*a**n* of length *n*. Decide whether it is possible to divide it into an odd number of non-empty subsegments, the each of which has an odd length and begins and ends with odd numbers. A subsegment is a contiguous slice of the whole sequence. For example, {3,<=4,<=5} and {1} are subsegments of sequence {1,<=2,<=3,<=4,<=5,<=6}, while {1,<=2,<=4} and {7} are not.
The first line of input contains a non-negative integer *n* (1<=≤<=*n*<=≤<=100) — the length of the sequence. The second line contains *n* space-separated non-negative integers *a*1,<=*a*2,<=...,<=*a**n* (0<=≤<=*a**i*<=≤<=100) — the elements of the sequence.
Output "Yes" if it's possible to fulfill the requirements, and "No" otherwise. You can output each letter in any case (upper or lower).
[ "3\n1 3 5\n", "5\n1 0 1 5 1\n", "3\n4 3 1\n", "4\n3 9 9 3\n" ]
[ "Yes\n", "Yes\n", "No\n", "No\n" ]
In the first example, divide the sequence into 1 subsegment: {1, 3, 5} and the requirements will be met. In the second example, divide the sequence into 3 subsegments: {1, 0, 1}, {5}, {1}. In the third example, one of the subsegments must start with 4 which is an even number, thus the requirements cannot be met. In the fourth example, the sequence can be divided into 2 subsegments: {3, 9, 9}, {3}, but this is not a valid solution because 2 is an even number.
500
[ { "input": "3\n1 3 5", "output": "Yes" }, { "input": "5\n1 0 1 5 1", "output": "Yes" }, { "input": "3\n4 3 1", "output": "No" }, { "input": "4\n3 9 9 3", "output": "No" }, { "input": "1\n1", "output": "Yes" }, { "input": "5\n100 99 100 99 99", "output": "No" }, { "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": "No" }, { "input": "1\n0", "output": "No" }, { "input": "2\n1 1", "output": "No" }, { "input": "2\n10 10", "output": "No" }, { "input": "2\n54 21", "output": "No" }, { "input": "5\n0 0 0 0 0", "output": "No" }, { "input": "5\n67 92 0 26 43", "output": "Yes" }, { "input": "15\n45 52 35 80 68 80 93 57 47 32 69 23 63 90 43", "output": "Yes" }, { "input": "15\n81 28 0 82 71 64 63 89 87 92 38 30 76 72 36", "output": "No" }, { "input": "50\n49 32 17 59 77 98 65 50 85 10 40 84 65 34 52 25 1 31 61 45 48 24 41 14 76 12 33 76 44 86 53 33 92 58 63 93 50 24 31 79 67 50 72 93 2 38 32 14 87 99", "output": "No" }, { "input": "55\n65 69 53 66 11 100 68 44 43 17 6 66 24 2 6 6 61 72 91 53 93 61 52 96 56 42 6 8 79 49 76 36 83 58 8 43 2 90 71 49 80 21 75 13 76 54 95 61 58 82 40 33 73 61 46", "output": "No" }, { "input": "99\n73 89 51 85 42 67 22 80 75 3 90 0 52 100 90 48 7 15 41 1 54 2 23 62 86 68 2 87 57 12 45 34 68 54 36 49 27 46 22 70 95 90 57 91 90 79 48 89 67 92 28 27 25 37 73 66 13 89 7 99 62 53 48 24 73 82 62 88 26 39 21 86 50 95 26 27 60 6 56 14 27 90 55 80 97 18 37 36 70 2 28 53 36 77 39 79 82 42 69", "output": "Yes" }, { "input": "99\n99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99", "output": "Yes" }, { "input": "100\n61 63 34 45 20 91 31 28 40 27 94 1 73 5 69 10 56 94 80 23 79 99 59 58 13 56 91 59 77 78 88 72 80 72 70 71 63 60 41 41 41 27 83 10 43 14 35 48 0 78 69 29 63 33 42 67 1 74 51 46 79 41 37 61 16 29 82 28 22 14 64 49 86 92 82 55 54 24 75 58 95 31 3 34 26 23 78 91 49 6 30 57 27 69 29 54 42 0 61 83", "output": "No" }, { "input": "6\n1 2 2 2 2 1", "output": "No" }, { "input": "3\n1 2 1", "output": "Yes" }, { "input": "4\n1 3 2 3", "output": "No" }, { "input": "6\n1 1 1 1 1 1", "output": "No" }, { "input": "6\n1 1 0 0 1 1", "output": "No" }, { "input": "4\n1 4 9 3", "output": "No" }, { "input": "4\n1 0 1 1", "output": "No" }, { "input": "10\n1 0 0 1 1 1 1 1 1 1", "output": "No" }, { "input": "10\n9 2 5 7 8 3 1 9 4 9", "output": "No" }, { "input": "99\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2", "output": "No" }, { "input": "6\n1 2 1 2 2 1", "output": "No" }, { "input": "6\n1 0 1 0 0 1", "output": "No" }, { "input": "4\n1 3 4 7", "output": "No" }, { "input": "8\n1 1 1 2 1 1 1 1", "output": "No" }, { "input": "3\n1 1 2", "output": "No" }, { "input": "5\n1 2 1 2 1", "output": "Yes" }, { "input": "5\n5 4 4 2 1", "output": "Yes" }, { "input": "6\n1 3 3 3 3 1", "output": "No" }, { "input": "7\n1 2 1 2 2 2 1", "output": "Yes" }, { "input": "4\n1 2 2 1", "output": "No" }, { "input": "6\n1 2 3 4 6 5", "output": "No" }, { "input": "5\n1 1 2 2 2", "output": "No" }, { "input": "5\n1 0 0 1 1", "output": "Yes" }, { "input": "3\n1 2 4", "output": "No" }, { "input": "3\n1 0 2", "output": "No" }, { "input": "5\n1 1 1 0 1", "output": "Yes" }, { "input": "4\n3 9 2 3", "output": "No" }, { "input": "6\n1 1 1 4 4 1", "output": "No" }, { "input": "6\n1 2 3 5 6 7", "output": "No" }, { "input": "6\n1 1 1 2 2 1", "output": "No" }, { "input": "6\n1 1 1 0 0 1", "output": "No" }, { "input": "5\n1 2 2 5 5", "output": "Yes" }, { "input": "5\n1 3 2 4 5", "output": "Yes" }, { "input": "8\n1 2 3 5 7 8 8 5", "output": "No" }, { "input": "10\n1 1 1 2 1 1 1 1 1 1", "output": "No" }, { "input": "4\n1 0 0 1", "output": "No" }, { "input": "7\n1 0 1 1 0 0 1", "output": "Yes" }, { "input": "7\n1 4 5 7 6 6 3", "output": "Yes" }, { "input": "4\n2 2 2 2", "output": "No" }, { "input": "5\n2 3 4 5 6", "output": "No" }, { "input": "4\n1 1 2 1", "output": "No" }, { "input": "3\n1 2 3", "output": "Yes" }, { "input": "6\n1 3 3 2 2 3", "output": "No" }, { "input": "4\n1 1 2 3", "output": "No" }, { "input": "4\n1 2 3 5", "output": "No" }, { "input": "5\n3 4 4 3 3", "output": "Yes" }, { "input": "4\n3 2 2 3", "output": "No" }, { "input": "6\n1 1 1 1 2 1", "output": "No" }, { "input": "6\n1 1 2 2 1 1", "output": "No" }, { "input": "10\n3 4 2 4 3 2 2 4 4 3", "output": "No" }, { "input": "7\n1 2 4 3 2 4 5", "output": "Yes" }, { "input": "28\n75 51 25 52 13 7 34 29 5 59 68 56 13 2 9 37 59 83 18 32 36 30 20 43 92 76 78 67", "output": "No" }, { "input": "79\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 18", "output": "No" }, { "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": "No" } ]
1,505,623,891
2,147,483,647
Python 3
OK
TESTS
74
62
0
# coding: utf-8 # 849A - Odds and Ends (http://codeforces.com/contest/849/problem/A) n = int(input()) arr = list(map(int, input().split())) if n % 2 and arr[0] % 2 and arr[-1] % 2: print("Yes") else: print("No")
Title: Odds and Ends Time Limit: None seconds Memory Limit: None megabytes Problem Description: Where do odds begin, and where do they end? Where does hope emerge, and will they ever break? Given an integer sequence *a*1,<=*a*2,<=...,<=*a**n* of length *n*. Decide whether it is possible to divide it into an odd number of non-empty subsegments, the each of which has an odd length and begins and ends with odd numbers. A subsegment is a contiguous slice of the whole sequence. For example, {3,<=4,<=5} and {1} are subsegments of sequence {1,<=2,<=3,<=4,<=5,<=6}, while {1,<=2,<=4} and {7} are not. Input Specification: The first line of input contains a non-negative integer *n* (1<=≤<=*n*<=≤<=100) — the length of the sequence. The second line contains *n* space-separated non-negative integers *a*1,<=*a*2,<=...,<=*a**n* (0<=≤<=*a**i*<=≤<=100) — the elements of the sequence. Output Specification: Output "Yes" if it's possible to fulfill the requirements, and "No" otherwise. You can output each letter in any case (upper or lower). Demo Input: ['3\n1 3 5\n', '5\n1 0 1 5 1\n', '3\n4 3 1\n', '4\n3 9 9 3\n'] Demo Output: ['Yes\n', 'Yes\n', 'No\n', 'No\n'] Note: In the first example, divide the sequence into 1 subsegment: {1, 3, 5} and the requirements will be met. In the second example, divide the sequence into 3 subsegments: {1, 0, 1}, {5}, {1}. In the third example, one of the subsegments must start with 4 which is an even number, thus the requirements cannot be met. In the fourth example, the sequence can be divided into 2 subsegments: {3, 9, 9}, {3}, but this is not a valid solution because 2 is an even number.
```python # coding: utf-8 # 849A - Odds and Ends (http://codeforces.com/contest/849/problem/A) n = int(input()) arr = list(map(int, input().split())) if n % 2 and arr[0] % 2 and arr[-1] % 2: print("Yes") else: print("No") ```
3
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,495,818,935
2,147,483,647
Python 3
OK
TESTS
20
62
102,400
n = int(input()) best_answer = 999999999 random_numbers = input() for i in range(n): queue = [int(x) for x in input().split(' ')] best_answer = min(best_answer, sum(queue)*5 + len(queue)*15) print(best_answer)
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 n = int(input()) best_answer = 999999999 random_numbers = input() for i in range(n): queue = [int(x) for x in input().split(' ')] best_answer = min(best_answer, sum(queue)*5 + len(queue)*15) print(best_answer) ```
3
245
A
System Administrator
PROGRAMMING
800
[ "implementation" ]
null
null
Polycarpus is a system administrator. There are two servers under his strict guidance — *a* and *b*. To stay informed about the servers' performance, Polycarpus executes commands "ping a" and "ping b". Each ping command sends exactly ten packets to the server specified in the argument of the command. Executing a program results in two integers *x* and *y* (*x*<=+<=*y*<==<=10; *x*,<=*y*<=≥<=0). These numbers mean that *x* packets successfully reached the corresponding server through the network and *y* packets were lost. Today Polycarpus has performed overall *n* ping commands during his workday. Now for each server Polycarpus wants to know whether the server is "alive" or not. Polycarpus thinks that the server is "alive", if at least half of the packets that we send to this server reached it successfully along the network. Help Polycarpus, determine for each server, whether it is "alive" or not by the given commands and their results.
The first line contains a single integer *n* (2<=≤<=*n*<=≤<=1000) — the number of commands Polycarpus has fulfilled. Each of the following *n* lines contains three integers — the description of the commands. The *i*-th of these lines contains three space-separated integers *t**i*, *x**i*, *y**i* (1<=≤<=*t**i*<=≤<=2; *x**i*,<=*y**i*<=≥<=0; *x**i*<=+<=*y**i*<==<=10). If *t**i*<==<=1, then the *i*-th command is "ping a", otherwise the *i*-th command is "ping b". Numbers *x**i*, *y**i* represent the result of executing this command, that is, *x**i* packets reached the corresponding server successfully and *y**i* packets were lost. It is guaranteed that the input has at least one "ping a" command and at least one "ping b" command.
In the first line print string "LIVE" (without the quotes) if server *a* is "alive", otherwise print "DEAD" (without the quotes). In the second line print the state of server *b* in the similar format.
[ "2\n1 5 5\n2 6 4\n", "3\n1 0 10\n2 0 10\n1 10 0\n" ]
[ "LIVE\nLIVE\n", "LIVE\nDEAD\n" ]
Consider the first test case. There 10 packets were sent to server *a*, 5 of them reached it. Therefore, at least half of all packets sent to this server successfully reached it through the network. Overall there were 10 packets sent to server *b*, 6 of them reached it. Therefore, at least half of all packets sent to this server successfully reached it through the network. Consider the second test case. There were overall 20 packages sent to server *a*, 10 of them reached it. Therefore, at least half of all packets sent to this server successfully reached it through the network. Overall 10 packets were sent to server *b*, 0 of them reached it. Therefore, less than half of all packets sent to this server successfully reached it through the network.
0
[ { "input": "2\n1 5 5\n2 6 4", "output": "LIVE\nLIVE" }, { "input": "3\n1 0 10\n2 0 10\n1 10 0", "output": "LIVE\nDEAD" }, { "input": "10\n1 3 7\n2 4 6\n1 2 8\n2 5 5\n2 10 0\n2 10 0\n1 8 2\n2 2 8\n2 10 0\n1 1 9", "output": "DEAD\nLIVE" }, { "input": "11\n1 8 2\n1 6 4\n1 9 1\n1 7 3\n2 0 10\n2 0 10\n1 8 2\n2 2 8\n2 6 4\n2 7 3\n2 9 1", "output": "LIVE\nDEAD" }, { "input": "12\n1 5 5\n1 0 10\n1 4 6\n1 2 8\n1 2 8\n1 5 5\n1 9 1\n2 9 1\n1 5 5\n1 1 9\n2 9 1\n2 7 3", "output": "DEAD\nLIVE" }, { "input": "13\n1 8 2\n1 4 6\n1 5 5\n1 5 5\n2 10 0\n2 9 1\n1 3 7\n2 6 4\n2 6 4\n2 5 5\n1 7 3\n2 3 7\n2 9 1", "output": "LIVE\nLIVE" }, { "input": "14\n1 7 3\n1 0 10\n1 7 3\n1 1 9\n2 2 8\n2 0 10\n1 1 9\n2 8 2\n2 6 4\n1 3 7\n1 3 7\n2 6 4\n2 1 9\n2 7 3", "output": "DEAD\nDEAD" } ]
1,660,672,937
2,147,483,647
PyPy 3
OK
TESTS
13
186
1,638,400
n=int(input()) server1x = 0 server2x = 0 server1y = 0 server2y = 0 for _ in range(n): t, x, y = list(map(int, input().split())) if t == 1: server1x += x server1y += y else: server2x += x server2y += y if server1x >= server1y: print("LIVE") else: print("DEAD") if server2x >= server2y: print("LIVE") else: print("DEAD")
Title: System Administrator Time Limit: None seconds Memory Limit: None megabytes Problem Description: Polycarpus is a system administrator. There are two servers under his strict guidance — *a* and *b*. To stay informed about the servers' performance, Polycarpus executes commands "ping a" and "ping b". Each ping command sends exactly ten packets to the server specified in the argument of the command. Executing a program results in two integers *x* and *y* (*x*<=+<=*y*<==<=10; *x*,<=*y*<=≥<=0). These numbers mean that *x* packets successfully reached the corresponding server through the network and *y* packets were lost. Today Polycarpus has performed overall *n* ping commands during his workday. Now for each server Polycarpus wants to know whether the server is "alive" or not. Polycarpus thinks that the server is "alive", if at least half of the packets that we send to this server reached it successfully along the network. Help Polycarpus, determine for each server, whether it is "alive" or not by the given commands and their results. Input Specification: The first line contains a single integer *n* (2<=≤<=*n*<=≤<=1000) — the number of commands Polycarpus has fulfilled. Each of the following *n* lines contains three integers — the description of the commands. The *i*-th of these lines contains three space-separated integers *t**i*, *x**i*, *y**i* (1<=≤<=*t**i*<=≤<=2; *x**i*,<=*y**i*<=≥<=0; *x**i*<=+<=*y**i*<==<=10). If *t**i*<==<=1, then the *i*-th command is "ping a", otherwise the *i*-th command is "ping b". Numbers *x**i*, *y**i* represent the result of executing this command, that is, *x**i* packets reached the corresponding server successfully and *y**i* packets were lost. It is guaranteed that the input has at least one "ping a" command and at least one "ping b" command. Output Specification: In the first line print string "LIVE" (without the quotes) if server *a* is "alive", otherwise print "DEAD" (without the quotes). In the second line print the state of server *b* in the similar format. Demo Input: ['2\n1 5 5\n2 6 4\n', '3\n1 0 10\n2 0 10\n1 10 0\n'] Demo Output: ['LIVE\nLIVE\n', 'LIVE\nDEAD\n'] Note: Consider the first test case. There 10 packets were sent to server *a*, 5 of them reached it. Therefore, at least half of all packets sent to this server successfully reached it through the network. Overall there were 10 packets sent to server *b*, 6 of them reached it. Therefore, at least half of all packets sent to this server successfully reached it through the network. Consider the second test case. There were overall 20 packages sent to server *a*, 10 of them reached it. Therefore, at least half of all packets sent to this server successfully reached it through the network. Overall 10 packets were sent to server *b*, 0 of them reached it. Therefore, less than half of all packets sent to this server successfully reached it through the network.
```python n=int(input()) server1x = 0 server2x = 0 server1y = 0 server2y = 0 for _ in range(n): t, x, y = list(map(int, input().split())) if t == 1: server1x += x server1y += y else: server2x += x server2y += y if server1x >= server1y: print("LIVE") else: print("DEAD") if server2x >= server2y: print("LIVE") else: print("DEAD") ```
3
976
C
Nested Segments
PROGRAMMING
1,500
[ "greedy", "implementation", "sortings" ]
null
null
You are given a sequence *a*1,<=*a*2,<=...,<=*a**n* of one-dimensional segments numbered 1 through *n*. Your task is to find two distinct indices *i* and *j* such that segment *a**i* lies within segment *a**j*. Segment [*l*1,<=*r*1] lies within segment [*l*2,<=*r*2] iff *l*1<=≥<=*l*2 and *r*1<=≤<=*r*2. Print indices *i* and *j*. If there are multiple answers, print any of them. If no answer exists, print -1 -1.
The first line contains one integer *n* (1<=≤<=*n*<=≤<=3·105) — the number of segments. Each of the next *n* lines contains two integers *l**i* and *r**i* (1<=≤<=*l**i*<=≤<=*r**i*<=≤<=109) — the *i*-th segment.
Print two distinct indices *i* and *j* such that segment *a**i* lies within segment *a**j*. If there are multiple answers, print any of them. If no answer exists, print -1 -1.
[ "5\n1 10\n2 9\n3 9\n2 3\n2 9\n", "3\n1 5\n2 6\n6 20\n" ]
[ "2 1\n", "-1 -1\n" ]
In the first example the following pairs are considered correct: - (2, 1), (3, 1), (4, 1), (5, 1) — not even touching borders; - (3, 2), (4, 2), (3, 5), (4, 5) — touch one border; - (5, 2), (2, 5) — match exactly.
0
[ { "input": "5\n1 10\n2 9\n3 9\n2 3\n2 9", "output": "2 1" }, { "input": "3\n1 5\n2 6\n6 20", "output": "-1 -1" }, { "input": "1\n1 1000000000", "output": "-1 -1" }, { "input": "2\n1 1000000000\n1 1000000000", "output": "2 1" }, { "input": "2\n1 1000000000\n500000000 500000000", "output": "2 1" }, { "input": "2\n1 10\n2 10", "output": "2 1" }, { "input": "2\n10 20\n10 11", "output": "2 1" }, { "input": "3\n1 10\n10 20\n9 11", "output": "-1 -1" }, { "input": "3\n1 1\n2 3\n2 2", "output": "3 2" }, { "input": "4\n1 10\n2 11\n3 10000000\n3 100000000", "output": "3 4" }, { "input": "2\n3 7\n3 9", "output": "1 2" }, { "input": "3\n1 2\n2 3\n1 2", "output": "3 1" }, { "input": "3\n5 6\n4 7\n3 8", "output": "2 3" }, { "input": "3\n2 9\n1 7\n2 8", "output": "3 1" }, { "input": "2\n1 4\n1 5", "output": "1 2" }, { "input": "3\n1 2\n1 3\n4 4", "output": "1 2" }, { "input": "3\n1 2\n1 3\n67 1234567", "output": "1 2" }, { "input": "2\n1 1\n1 1", "output": "2 1" }, { "input": "3\n1 5\n4 7\n3 9", "output": "2 3" }, { "input": "2\n1 1\n1 10", "output": "1 2" }, { "input": "2\n1 2\n1 3", "output": "1 2" }, { "input": "2\n1 10\n1 11", "output": "1 2" }, { "input": "2\n1 1\n1 2", "output": "1 2" }, { "input": "2\n2 3\n2 4", "output": "1 2" }, { "input": "2\n1 3\n3 3", "output": "2 1" }, { "input": "3\n1 10\n11 13\n12 12", "output": "3 2" }, { "input": "2\n2 10\n1 10", "output": "1 2" }, { "input": "3\n1 3\n4 5\n4 4", "output": "3 2" }, { "input": "5\n1 1\n2 6\n3 5\n10 15\n20 25", "output": "3 2" }, { "input": "3\n1 1000\n1001 1007\n1002 1007", "output": "3 2" }, { "input": "3\n1 3\n2 5\n3 4", "output": "3 2" }, { "input": "3\n1 10\n2 11\n3 11", "output": "3 2" }, { "input": "2\n2000000 999999999\n1000000 1000000000", "output": "1 2" }, { "input": "3\n2 10\n11 12\n4 5", "output": "3 1" }, { "input": "2\n1 10\n1 19", "output": "1 2" }, { "input": "4\n1 3\n100 102\n108 110\n1 3", "output": "4 1" }, { "input": "3\n1 3\n5 9\n5 6", "output": "3 2" }, { "input": "3\n1 3\n3 4\n3 5", "output": "2 3" }, { "input": "3\n1 2\n1 3\n1 4", "output": "2 3" }, { "input": "4\n2 3\n1 4\n100 200\n1000 2000", "output": "1 2" }, { "input": "3\n1 1\n2 100\n3 99", "output": "3 2" }, { "input": "3\n1 2\n1 3\n12 1234", "output": "1 2" }, { "input": "3\n1 4\n2 6\n3 5", "output": "3 2" }, { "input": "3\n1 10\n2 12\n1 9", "output": "3 1" }, { "input": "2\n1 3\n1 5", "output": "1 2" }, { "input": "3\n1 2\n2 5\n2 3", "output": "3 2" }, { "input": "4\n1 3\n1 4\n5 10\n11 13", "output": "1 2" }, { "input": "4\n7 15\n6 9\n9 10\n10 11", "output": "3 1" }, { "input": "4\n2 3\n100 200\n1000 2000\n1 4", "output": "1 4" }, { "input": "3\n10 20\n5 9\n11 19", "output": "3 1" }, { "input": "10\n1 2\n2 3\n3 4\n4 5\n5 6\n6 6\n6 7\n7 8\n8 9\n9 10", "output": "6 7" }, { "input": "2\n1 4\n1 7", "output": "1 2" }, { "input": "3\n1 11\n2 12\n2 13", "output": "2 3" }, { "input": "2\n1 4\n1 8", "output": "1 2" }, { "input": "2\n2 5\n1 5", "output": "1 2" }, { "input": "2\n2 9\n1 10", "output": "1 2" }, { "input": "3\n2 4\n2 4\n1 3", "output": "2 1" }, { "input": "6\n10 11\n12 13\n15 16\n15 17\n18 19\n59 60", "output": "3 4" }, { "input": "2\n1 3\n1 7", "output": "1 2" }, { "input": "5\n4 6\n7 60\n80 90\n4 5\n8 80", "output": "4 1" }, { "input": "2\n1 3\n1 4", "output": "1 2" }, { "input": "3\n2 9\n1 7\n2 9", "output": "3 1" }, { "input": "2\n1 4\n1 6", "output": "1 2" }, { "input": "3\n4 4\n2 3\n4 5", "output": "1 3" }, { "input": "2\n1 5\n1 7", "output": "1 2" }, { "input": "2\n1 2\n1 4", "output": "1 2" }, { "input": "4\n1 1\n2 2\n5 10\n2 4", "output": "2 4" }, { "input": "3\n11 12\n11 15\n43 45", "output": "1 2" }, { "input": "3\n2 3\n2 4\n2 5", "output": "2 3" }, { "input": "2\n2 3\n2 5", "output": "1 2" }, { "input": "3\n1 3\n1 4\n1 5", "output": "2 3" }, { "input": "3\n1 1\n1 2\n1 3", "output": "2 3" }, { "input": "2\n2 3\n1 3", "output": "1 2" }, { "input": "11\n22226 28285\n9095 23314\n19162 25530\n255 13298\n4904 25801\n17914 23501\n8441 28117\n11880 29994\n11123 19874\n21505 27971\n7658 14109", "output": "11 5" }, { "input": "8\n4 11\n5 12\n6 13\n7 14\n8 15\n9 16\n10 17\n1 11", "output": "1 8" }, { "input": "4\n1 10\n12 15\n1 3\n17 18", "output": "3 1" }, { "input": "3\n1 5\n1 10\n1 20", "output": "2 3" }, { "input": "3\n1 1000\n1001 1003\n1 1", "output": "3 1" }, { "input": "3\n1 10\n2 11\n2 11", "output": "3 2" }, { "input": "2\n1 1\n1 3", "output": "1 2" }, { "input": "2\n1 5\n1 6", "output": "1 2" }, { "input": "3\n1 5\n3 6\n1 4", "output": "3 1" }, { "input": "4\n2 8\n1 3\n2 9\n1 2", "output": "4 2" }, { "input": "3\n3 6\n1 3\n3 9", "output": "1 3" }, { "input": "6\n2 40\n5 50\n10 60\n3 45\n1 40\n100 111", "output": "1 5" }, { "input": "4\n1 2\n4 4\n3 3\n2 3", "output": "3 4" }, { "input": "4\n1 1\n4 5\n7 9\n1 1", "output": "4 1" }, { "input": "6\n30 35\n18 29\n28 32\n4 9\n1002 129212\n8 281", "output": "2 6" }, { "input": "2\n10 13\n10 14", "output": "1 2" }, { "input": "5\n2 4\n3 6\n4 5\n222 333\n111 444", "output": "3 2" }, { "input": "3\n1 2\n4 5\n1 1", "output": "3 1" }, { "input": "2\n2 100\n1 100", "output": "1 2" }, { "input": "3\n1 10\n9 20\n3 5", "output": "3 1" }, { "input": "2\n1 9\n1 10", "output": "1 2" }, { "input": "3\n1 2\n1 4\n1 6", "output": "2 3" } ]
1,525,105,252
6,052
Python 3
COMPILATION_ERROR
TESTS
0
0
0
#include <bits/stdc++.h> using namespace std; struct otr{ int open; int close; int ind; otr(int open, int close, int ind):open(open),close(close),ind(ind){} bool operator<(otr other){ if(open!=other.open){ return open<other.open; } if(close!=other.close){ return close<other.close; } if(ind!=other.ind){ return ind<other.ind; } } }; int main(){ int n; cin>>n; vector<otr> v; for(int i=0; i<n; ++i){ int a,b; cin>>a>>b; v.emplace_back(a,b,i); } sort(v.begin(),v.end()); for(auto i:v){ //cout<<i.open<<" "<<i.close<<endl; } for(int i=0; i<n-1; ++i){ if(v[i].open<=v[i+1].open && v[i].close>=v[i+1].close){ cout<<i+2<<" "<<i+1; return 0; } if(v[i].open==v[i+1].open){ if(v[i].close<=v[i+1].close){ cout<<i+1<<" "<<i+2; } } } cout<<-1<<" "<<-1; }
Title: Nested Segments Time Limit: None seconds Memory Limit: None megabytes Problem Description: You are given a sequence *a*1,<=*a*2,<=...,<=*a**n* of one-dimensional segments numbered 1 through *n*. Your task is to find two distinct indices *i* and *j* such that segment *a**i* lies within segment *a**j*. Segment [*l*1,<=*r*1] lies within segment [*l*2,<=*r*2] iff *l*1<=≥<=*l*2 and *r*1<=≤<=*r*2. Print indices *i* and *j*. If there are multiple answers, print any of them. If no answer exists, print -1 -1. Input Specification: The first line contains one integer *n* (1<=≤<=*n*<=≤<=3·105) — the number of segments. Each of the next *n* lines contains two integers *l**i* and *r**i* (1<=≤<=*l**i*<=≤<=*r**i*<=≤<=109) — the *i*-th segment. Output Specification: Print two distinct indices *i* and *j* such that segment *a**i* lies within segment *a**j*. If there are multiple answers, print any of them. If no answer exists, print -1 -1. Demo Input: ['5\n1 10\n2 9\n3 9\n2 3\n2 9\n', '3\n1 5\n2 6\n6 20\n'] Demo Output: ['2 1\n', '-1 -1\n'] Note: In the first example the following pairs are considered correct: - (2, 1), (3, 1), (4, 1), (5, 1) — not even touching borders; - (3, 2), (4, 2), (3, 5), (4, 5) — touch one border; - (5, 2), (2, 5) — match exactly.
```python #include <bits/stdc++.h> using namespace std; struct otr{ int open; int close; int ind; otr(int open, int close, int ind):open(open),close(close),ind(ind){} bool operator<(otr other){ if(open!=other.open){ return open<other.open; } if(close!=other.close){ return close<other.close; } if(ind!=other.ind){ return ind<other.ind; } } }; int main(){ int n; cin>>n; vector<otr> v; for(int i=0; i<n; ++i){ int a,b; cin>>a>>b; v.emplace_back(a,b,i); } sort(v.begin(),v.end()); for(auto i:v){ //cout<<i.open<<" "<<i.close<<endl; } for(int i=0; i<n-1; ++i){ if(v[i].open<=v[i+1].open && v[i].close>=v[i+1].close){ cout<<i+2<<" "<<i+1; return 0; } if(v[i].open==v[i+1].open){ if(v[i].close<=v[i+1].close){ cout<<i+1<<" "<<i+2; } } } cout<<-1<<" "<<-1; } ```
-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,632,488,250
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
0
62
6,963,200
n= int(input()) soldiers = list(map(int, input().split())) result = None my_min = 10001 for i in range(n): index = (i+1) % n curr_height = abs(soldiers[i] - soldiers[index]) if curr_height < my_min: my_min = curr_height result = (i+1, index+1) print(result)
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()) soldiers = list(map(int, input().split())) result = None my_min = 10001 for i in range(n): index = (i+1) % n curr_height = abs(soldiers[i] - soldiers[index]) if curr_height < my_min: my_min = curr_height result = (i+1, index+1) print(result) ```
0
41
A
Translation
PROGRAMMING
800
[ "implementation", "strings" ]
A. Translation
2
256
The translation from the Berland language into the Birland language is not an easy task. Those languages are very similar: a berlandish word differs from a birlandish word with the same meaning a little: it is spelled (and pronounced) reversely. For example, a Berlandish word code corresponds to a Birlandish word edoc. However, it's easy to make a mistake during the «translation». Vasya translated word *s* from Berlandish into Birlandish as *t*. Help him: find out if he translated the word correctly.
The first line contains word *s*, the second line contains word *t*. The words consist of lowercase Latin letters. The input data do not consist unnecessary spaces. The words are not empty and their lengths do not exceed 100 symbols.
If the word *t* is a word *s*, written reversely, print YES, otherwise print NO.
[ "code\nedoc\n", "abb\naba\n", "code\ncode\n" ]
[ "YES\n", "NO\n", "NO\n" ]
none
500
[ { "input": "code\nedoc", "output": "YES" }, { "input": "abb\naba", "output": "NO" }, { "input": "code\ncode", "output": "NO" }, { "input": "abacaba\nabacaba", "output": "YES" }, { "input": "q\nq", "output": "YES" }, { "input": "asrgdfngfnmfgnhweratgjkk\nasrgdfngfnmfgnhweratgjkk", "output": "NO" }, { "input": "z\na", "output": "NO" }, { "input": "asd\ndsa", "output": "YES" }, { "input": "abcdef\nfecdba", "output": "NO" }, { "input": "ywjjbirapvskozubvxoemscfwl\ngnduubaogtfaiowjizlvjcu", "output": "NO" }, { "input": "mfrmqxtzvgaeuleubcmcxcfqyruwzenguhgrmkuhdgnhgtgkdszwqyd\nmfxufheiperjnhyczclkmzyhcxntdfskzkzdwzzujdinf", "output": "NO" }, { "input": "bnbnemvybqizywlnghlykniaxxxlkhftppbdeqpesrtgkcpoeqowjwhrylpsziiwcldodcoonpimudvrxejjo\ntiynnekmlalogyvrgptbinkoqdwzuiyjlrldxhzjmmp", "output": "NO" }, { "input": "pwlpubwyhzqvcitemnhvvwkmwcaawjvdiwtoxyhbhbxerlypelevasmelpfqwjk\nstruuzebbcenziscuoecywugxncdwzyfozhljjyizpqcgkyonyetarcpwkqhuugsqjuixsxptmbnlfupdcfigacdhhrzb", "output": "NO" }, { "input": "gdvqjoyxnkypfvdxssgrihnwxkeojmnpdeobpecytkbdwujqfjtxsqspxvxpqioyfagzjxupqqzpgnpnpxcuipweunqch\nkkqkiwwasbhezqcfeceyngcyuogrkhqecwsyerdniqiocjehrpkljiljophqhyaiefjpavoom", "output": "NO" }, { "input": "umeszdawsvgkjhlqwzents\nhxqhdungbylhnikwviuh", "output": "NO" }, { "input": "juotpscvyfmgntshcealgbsrwwksgrwnrrbyaqqsxdlzhkbugdyx\nibqvffmfktyipgiopznsqtrtxiijntdbgyy", "output": "NO" }, { "input": "zbwueheveouatecaglziqmudxemhrsozmaujrwlqmppzoumxhamwugedikvkblvmxwuofmpafdprbcftew\nulczwrqhctbtbxrhhodwbcxwimncnexosksujlisgclllxokrsbnozthajnnlilyffmsyko", "output": "NO" }, { "input": "nkgwuugukzcv\nqktnpxedwxpxkrxdvgmfgoxkdfpbzvwsduyiybynbkouonhvmzakeiruhfmvrktghadbfkmwxduoqv", "output": "NO" }, { "input": "incenvizhqpcenhjhehvjvgbsnfixbatrrjstxjzhlmdmxijztphxbrldlqwdfimweepkggzcxsrwelodpnryntepioqpvk\ndhjbjjftlvnxibkklxquwmzhjfvnmwpapdrslioxisbyhhfymyiaqhlgecpxamqnocizwxniubrmpyubvpenoukhcobkdojlybxd", "output": "NO" }, { "input": "w\nw", "output": "YES" }, { "input": "vz\nzv", "output": "YES" }, { "input": "ry\nyr", "output": "YES" }, { "input": "xou\nuox", "output": "YES" }, { "input": "axg\ngax", "output": "NO" }, { "input": "zdsl\nlsdz", "output": "YES" }, { "input": "kudl\nldku", "output": "NO" }, { "input": "zzlzwnqlcl\nlclqnwzlzz", "output": "YES" }, { "input": "vzzgicnzqooejpjzads\nsdazjpjeooqzncigzzv", "output": "YES" }, { "input": "raqhmvmzuwaykjpyxsykr\nxkysrypjkyawuzmvmhqar", "output": "NO" }, { "input": "ngedczubzdcqbxksnxuavdjaqtmdwncjnoaicvmodcqvhfezew\nwezefhvqcdomvciaonjcnwdmtqajdvauxnskxbqcdzbuzcdegn", "output": "YES" }, { "input": "muooqttvrrljcxbroizkymuidvfmhhsjtumksdkcbwwpfqdyvxtrlymofendqvznzlmim\nmimlznzvqdnefomylrtxvydqfpwwbckdskmutjshhmfvdiumykziorbxcjlrrvttqooum", "output": "YES" }, { "input": "vxpqullmcbegsdskddortcvxyqlbvxmmkhevovnezubvpvnrcajpxraeaxizgaowtfkzywvhnbgzsxbhkaipcmoumtikkiyyaivg\ngviayyikkitmuomcpiakhbxszgbnhvwyzkftwoagzixaearxpjacrnvpvbuzenvovehkmmxvblqyxvctroddksdsgebcmlluqpxv", "output": "YES" }, { "input": "mnhaxtaopjzrkqlbroiyipitndczpunwygstmzevgyjdzyanxkdqnvgkikfabwouwkkbzuiuvgvxgpizsvqsbwepktpdrgdkmfdc\ncdfmkdgrdptkpewbsqvszipgxvgvuiuzbkkwuowbafkikgvnqdkxnayzdjygvezmtsgywnupocdntipiyiorblqkrzjpzatxahnm", "output": "NO" }, { "input": "dgxmzbqofstzcdgthbaewbwocowvhqpinehpjatnnbrijcolvsatbblsrxabzrpszoiecpwhfjmwuhqrapvtcgvikuxtzbftydkw\nwkdytfbztxukivgctvparqhuwmjfhwpceiozsprzbaxrslbbqasvlocjirbnntajphenipthvwocowbweabhtgdcztsfoqbzmxgd", "output": "NO" }, { "input": "gxoixiecetohtgjgbqzvlaobkhstejxdklghowtvwunnnvauriohuspsdmpzckprwajyxldoyckgjivjpmbfqtszmtocovxwgeh\nhegwxvocotmzstqfbmpjvijgkcyodlxyjawrpkczpmdspsuhoiruavnnnuwvtwohglkdxjetshkboalvzqbgjgthoteceixioxg", "output": "YES" }, { "input": "sihxuwvmaambplxvjfoskinghzicyfqebjtkysotattkahssumfcgrkheotdxwjckpvapbkaepqrxseyfrwtyaycmrzsrsngkh\nhkgnsrszrmcyaytwrfyesxrqpeakbpavpkcjwxdtoehkrgcfmusshakttatosyktjbeqfycizhgniksofjvxlpbmaamvwuxhis", "output": "YES" }, { "input": "ycnahksbughnonldzrhkysujmylcgcfuludjvjiahtkyzqvkopzqcnwhltbzfugzojqkjjlggmvnultascmygelkiktmfieok\nkoeifmtkiklegkmcsatlunvmggkjjlqjozgufzbtlhwncqzpokvqzykthaijvjdulufcgclymjusyyhrzdlnonhgubskhancy", "output": "NO" }, { "input": "wbqasaehtkfojruzyhrlgwmtyiovmzyfifslvlemhqheyaelzwnthrenjsbmntwaoryzwfbxmscmypvxlfmzpnkkjlvwvmtz\nztmvwvljkknpzmflxvpymcsmxbfwzyroawtnmbsjnerhtnwzleayehqhmelvlsfifyzmvoiytmwglrhyzurjofktheasaqbw", "output": "YES" }, { "input": "imippqurprbhfugngtgifelytadegwrgaefnfhbjjnmzikvjaccotqzemufqieqldgnbmviisgkynzeldlhqxuqphjfmyij\njiymfjhpquxqhldleznykgsiivmbngdlqeiqfumezqtoccajvkizmnjjbhfnfeagrwgedatylefigtgngufhbrpruqppimi", "output": "YES" }, { "input": "bikydffiuisckpvzqlteqfhegsagimodb\nbdomigasgehfqetlqzvpkcsiuiffdykib", "output": "YES" } ]
1,683,172,809
2,147,483,647
Python 3
OK
TESTS
40
92
0
import os, io input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline def main(): s = input().decode().rstrip("\r\n") t = input().decode().rstrip("\r\n") if s == t[::-1]: print("YES") else: print("NO") main()
Title: Translation Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: The translation from the Berland language into the Birland language is not an easy task. Those languages are very similar: a berlandish word differs from a birlandish word with the same meaning a little: it is spelled (and pronounced) reversely. For example, a Berlandish word code corresponds to a Birlandish word edoc. However, it's easy to make a mistake during the «translation». Vasya translated word *s* from Berlandish into Birlandish as *t*. Help him: find out if he translated the word correctly. Input Specification: The first line contains word *s*, the second line contains word *t*. The words consist of lowercase Latin letters. The input data do not consist unnecessary spaces. The words are not empty and their lengths do not exceed 100 symbols. Output Specification: If the word *t* is a word *s*, written reversely, print YES, otherwise print NO. Demo Input: ['code\nedoc\n', 'abb\naba\n', 'code\ncode\n'] Demo Output: ['YES\n', 'NO\n', 'NO\n'] Note: none
```python import os, io input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline def main(): s = input().decode().rstrip("\r\n") t = input().decode().rstrip("\r\n") if s == t[::-1]: print("YES") else: print("NO") main() ```
3.977
725
B
Food on the Plane
PROGRAMMING
1,200
[ "implementation", "math" ]
null
null
A new airplane SuperPuperJet has an infinite number of rows, numbered with positive integers starting with 1 from cockpit to tail. There are six seats in each row, denoted with letters from 'a' to 'f'. Seats 'a', 'b' and 'c' are located to the left of an aisle (if one looks in the direction of the cockpit), while seats 'd', 'e' and 'f' are located to the right. Seats 'a' and 'f' are located near the windows, while seats 'c' and 'd' are located near the aisle.   It's lunch time and two flight attendants have just started to serve food. They move from the first rows to the tail, always maintaining a distance of two rows from each other because of the food trolley. Thus, at the beginning the first attendant serves row 1 while the second attendant serves row 3. When both rows are done they move one row forward: the first attendant serves row 2 while the second attendant serves row 4. Then they move three rows forward and the first attendant serves row 5 while the second attendant serves row 7. Then they move one row forward again and so on. Flight attendants work with the same speed: it takes exactly 1 second to serve one passenger and 1 second to move one row forward. Each attendant first serves the passengers on the seats to the right of the aisle and then serves passengers on the seats to the left of the aisle (if one looks in the direction of the cockpit). Moreover, they always serve passengers in order from the window to the aisle. Thus, the first passenger to receive food in each row is located in seat 'f', and the last one — in seat 'c'. Assume that all seats are occupied. Vasya has seat *s* in row *n* and wants to know how many seconds will pass before he gets his lunch.
The only line of input contains a description of Vasya's seat in the format *ns*, where *n* (1<=≤<=*n*<=≤<=1018) is the index of the row and *s* is the seat in this row, denoted as letter from 'a' to 'f'. The index of the row and the seat are not separated by a space.
Print one integer — the number of seconds Vasya has to wait until he gets his lunch.
[ "1f\n", "2d\n", "4a\n", "5e\n" ]
[ "1\n", "10\n", "11\n", "18\n" ]
In the first sample, the first flight attendant serves Vasya first, so Vasya gets his lunch after 1 second. In the second sample, the flight attendants will spend 6 seconds to serve everyone in the rows 1 and 3, then they will move one row forward in 1 second. As they first serve seats located to the right of the aisle in order from window to aisle, Vasya has to wait 3 more seconds. The total is 6 + 1 + 3 = 10.
1,000
[ { "input": "1f", "output": "1" }, { "input": "2d", "output": "10" }, { "input": "4a", "output": "11" }, { "input": "5e", "output": "18" }, { "input": "2c", "output": "13" }, { "input": "1b", "output": "5" }, { "input": "1000000000000000000d", "output": "3999999999999999994" }, { "input": "999999999999999997a", "output": "3999999999999999988" }, { "input": "1c", "output": "6" }, { "input": "1d", "output": "3" }, { "input": "1e", "output": "2" }, { "input": "1a", "output": "4" }, { "input": "2a", "output": "11" }, { "input": "2b", "output": "12" }, { "input": "2e", "output": "9" }, { "input": "2f", "output": "8" }, { "input": "3a", "output": "4" }, { "input": "3b", "output": "5" }, { "input": "3c", "output": "6" }, { "input": "3d", "output": "3" }, { "input": "3e", "output": "2" }, { "input": "3f", "output": "1" }, { "input": "4b", "output": "12" }, { "input": "4c", "output": "13" }, { "input": "4d", "output": "10" }, { "input": "4e", "output": "9" }, { "input": "4f", "output": "8" }, { "input": "999999997a", "output": "3999999988" }, { "input": "999999997b", "output": "3999999989" }, { "input": "999999997c", "output": "3999999990" }, { "input": "999999997d", "output": "3999999987" }, { "input": "999999997e", "output": "3999999986" }, { "input": "999999997f", "output": "3999999985" }, { "input": "999999998a", "output": "3999999995" }, { "input": "999999998b", "output": "3999999996" }, { "input": "999999998c", "output": "3999999997" }, { "input": "999999998d", "output": "3999999994" }, { "input": "999999998e", "output": "3999999993" }, { "input": "999999998f", "output": "3999999992" }, { "input": "999999999a", "output": "3999999988" }, { "input": "999999999b", "output": "3999999989" }, { "input": "999999999c", "output": "3999999990" }, { "input": "999999999d", "output": "3999999987" }, { "input": "999999999e", "output": "3999999986" }, { "input": "999999999f", "output": "3999999985" }, { "input": "1000000000a", "output": "3999999995" }, { "input": "1000000000b", "output": "3999999996" }, { "input": "1000000000c", "output": "3999999997" }, { "input": "1000000000d", "output": "3999999994" }, { "input": "1000000000e", "output": "3999999993" }, { "input": "1000000000f", "output": "3999999992" }, { "input": "100000b", "output": "399996" }, { "input": "100000f", "output": "399992" }, { "input": "100001d", "output": "400003" }, { "input": "100001e", "output": "400002" }, { "input": "100001f", "output": "400001" }, { "input": "100002a", "output": "400011" }, { "input": "100002b", "output": "400012" }, { "input": "100002d", "output": "400010" }, { "input": "1231273a", "output": "4925092" }, { "input": "82784f", "output": "331128" }, { "input": "88312c", "output": "353245" }, { "input": "891237e", "output": "3564946" }, { "input": "999999999999999997b", "output": "3999999999999999989" }, { "input": "999999999999999997c", "output": "3999999999999999990" }, { "input": "999999999999999997d", "output": "3999999999999999987" }, { "input": "999999999999999997e", "output": "3999999999999999986" }, { "input": "999999999999999997f", "output": "3999999999999999985" }, { "input": "999999999999999998a", "output": "3999999999999999995" }, { "input": "999999999999999998b", "output": "3999999999999999996" }, { "input": "999999999999999998c", "output": "3999999999999999997" }, { "input": "999999999999999998d", "output": "3999999999999999994" }, { "input": "999999999999999998e", "output": "3999999999999999993" }, { "input": "999999999999999998f", "output": "3999999999999999992" }, { "input": "999999999999999999a", "output": "3999999999999999988" }, { "input": "999999999999999999b", "output": "3999999999999999989" }, { "input": "999999999999999999c", "output": "3999999999999999990" }, { "input": "999999999999999999d", "output": "3999999999999999987" }, { "input": "1000000000000000000a", "output": "3999999999999999995" }, { "input": "1000000000000000000e", "output": "3999999999999999993" }, { "input": "1000000000000000000f", "output": "3999999999999999992" }, { "input": "1000000000000000000c", "output": "3999999999999999997" }, { "input": "97a", "output": "388" }, { "input": "6f", "output": "24" }, { "input": "7f", "output": "17" }, { "input": "7e", "output": "18" }, { "input": "999999999999999992c", "output": "3999999999999999965" }, { "input": "7a", "output": "20" }, { "input": "8f", "output": "24" }, { "input": "999999999999999992a", "output": "3999999999999999963" }, { "input": "999999999999999992b", "output": "3999999999999999964" }, { "input": "999999999999999992c", "output": "3999999999999999965" }, { "input": "999999999999999992d", "output": "3999999999999999962" }, { "input": "999999999999999992e", "output": "3999999999999999961" }, { "input": "999999999999999992f", "output": "3999999999999999960" }, { "input": "999999999999999993a", "output": "3999999999999999972" }, { "input": "999999999999999993b", "output": "3999999999999999973" }, { "input": "999999999999999993c", "output": "3999999999999999974" }, { "input": "999999999999999993d", "output": "3999999999999999971" }, { "input": "999999999999999993e", "output": "3999999999999999970" }, { "input": "999999999999999993f", "output": "3999999999999999969" }, { "input": "999999999999999994a", "output": "3999999999999999979" }, { "input": "999999999999999994b", "output": "3999999999999999980" }, { "input": "999999999999999994c", "output": "3999999999999999981" }, { "input": "999999999999999994d", "output": "3999999999999999978" }, { "input": "999999999999999994e", "output": "3999999999999999977" }, { "input": "999999999999999994f", "output": "3999999999999999976" }, { "input": "999999999999999995a", "output": "3999999999999999972" }, { "input": "999999999999999995b", "output": "3999999999999999973" }, { "input": "999999999999999995c", "output": "3999999999999999974" }, { "input": "999999999999999995d", "output": "3999999999999999971" }, { "input": "999999999999999995e", "output": "3999999999999999970" }, { "input": "999999999999999995f", "output": "3999999999999999969" }, { "input": "10a", "output": "43" }, { "input": "11f", "output": "33" }, { "input": "681572647b", "output": "2726290581" }, { "input": "23f", "output": "81" }, { "input": "123a", "output": "484" }, { "input": "999999888888777777a", "output": "3999999555555111108" } ]
1,477,154,808
6,108
Python 3
WRONG_ANSWER
PRETESTS
2
46
0
#!/usr/bin/env python3 # -*- coding: utf-8 -*- s=input() n,l=int(s[0:len(s)-1]),s[len(s)-1] f=dict(zip(['f','e','d','a','b','c'],[i for i in range(1,7)])) if (n-1)%4==1 or n%4==1 : s=(n//2)*6+(n//2)+(n//4)*2+f[l] if (n-1)%4==3 or n%4==3: s=(n//2-1)*6+(n//2-1)+(n//4)*2+f[l] print(s)
Title: Food on the Plane Time Limit: None seconds Memory Limit: None megabytes Problem Description: A new airplane SuperPuperJet has an infinite number of rows, numbered with positive integers starting with 1 from cockpit to tail. There are six seats in each row, denoted with letters from 'a' to 'f'. Seats 'a', 'b' and 'c' are located to the left of an aisle (if one looks in the direction of the cockpit), while seats 'd', 'e' and 'f' are located to the right. Seats 'a' and 'f' are located near the windows, while seats 'c' and 'd' are located near the aisle.   It's lunch time and two flight attendants have just started to serve food. They move from the first rows to the tail, always maintaining a distance of two rows from each other because of the food trolley. Thus, at the beginning the first attendant serves row 1 while the second attendant serves row 3. When both rows are done they move one row forward: the first attendant serves row 2 while the second attendant serves row 4. Then they move three rows forward and the first attendant serves row 5 while the second attendant serves row 7. Then they move one row forward again and so on. Flight attendants work with the same speed: it takes exactly 1 second to serve one passenger and 1 second to move one row forward. Each attendant first serves the passengers on the seats to the right of the aisle and then serves passengers on the seats to the left of the aisle (if one looks in the direction of the cockpit). Moreover, they always serve passengers in order from the window to the aisle. Thus, the first passenger to receive food in each row is located in seat 'f', and the last one — in seat 'c'. Assume that all seats are occupied. Vasya has seat *s* in row *n* and wants to know how many seconds will pass before he gets his lunch. Input Specification: The only line of input contains a description of Vasya's seat in the format *ns*, where *n* (1<=≤<=*n*<=≤<=1018) is the index of the row and *s* is the seat in this row, denoted as letter from 'a' to 'f'. The index of the row and the seat are not separated by a space. Output Specification: Print one integer — the number of seconds Vasya has to wait until he gets his lunch. Demo Input: ['1f\n', '2d\n', '4a\n', '5e\n'] Demo Output: ['1\n', '10\n', '11\n', '18\n'] Note: In the first sample, the first flight attendant serves Vasya first, so Vasya gets his lunch after 1 second. In the second sample, the flight attendants will spend 6 seconds to serve everyone in the rows 1 and 3, then they will move one row forward in 1 second. As they first serve seats located to the right of the aisle in order from window to aisle, Vasya has to wait 3 more seconds. The total is 6 + 1 + 3 = 10.
```python #!/usr/bin/env python3 # -*- coding: utf-8 -*- s=input() n,l=int(s[0:len(s)-1]),s[len(s)-1] f=dict(zip(['f','e','d','a','b','c'],[i for i in range(1,7)])) if (n-1)%4==1 or n%4==1 : s=(n//2)*6+(n//2)+(n//4)*2+f[l] if (n-1)%4==3 or n%4==3: s=(n//2-1)*6+(n//2-1)+(n//4)*2+f[l] print(s) ```
0
659
A
Round House
PROGRAMMING
1,000
[ "implementation", "math" ]
null
null
Vasya lives in a round building, whose entrances are numbered sequentially by integers from 1 to *n*. Entrance *n* and entrance 1 are adjacent. Today Vasya got bored and decided to take a walk in the yard. Vasya lives in entrance *a* and he decided that during his walk he will move around the house *b* entrances in the direction of increasing numbers (in this order entrance *n* should be followed by entrance 1). The negative value of *b* corresponds to moving |*b*| entrances in the order of decreasing numbers (in this order entrance 1 is followed by entrance *n*). If *b*<==<=0, then Vasya prefers to walk beside his entrance. Help Vasya to determine the number of the entrance, near which he will be at the end of his walk.
The single line of the input contains three space-separated integers *n*, *a* and *b* (1<=≤<=*n*<=≤<=100,<=1<=≤<=*a*<=≤<=*n*,<=<=-<=100<=≤<=*b*<=≤<=100) — the number of entrances at Vasya's place, the number of his entrance and the length of his walk, respectively.
Print a single integer *k* (1<=≤<=*k*<=≤<=*n*) — the number of the entrance where Vasya will be at the end of his walk.
[ "6 2 -5\n", "5 1 3\n", "3 2 7\n" ]
[ "3\n", "4\n", "3\n" ]
The first example is illustrated by the picture in the statements.
500
[ { "input": "6 2 -5", "output": "3" }, { "input": "5 1 3", "output": "4" }, { "input": "3 2 7", "output": "3" }, { "input": "1 1 0", "output": "1" }, { "input": "1 1 -1", "output": "1" }, { "input": "1 1 1", "output": "1" }, { "input": "100 1 -1", "output": "100" }, { "input": "100 54 100", "output": "54" }, { "input": "100 37 -100", "output": "37" }, { "input": "99 41 0", "output": "41" }, { "input": "97 37 -92", "output": "42" }, { "input": "99 38 59", "output": "97" }, { "input": "35 34 1", "output": "35" }, { "input": "48 1 -1", "output": "48" }, { "input": "87 65 -76", "output": "76" }, { "input": "76 26 29", "output": "55" }, { "input": "100 65 0", "output": "65" }, { "input": "2 1 100", "output": "1" }, { "input": "3 2 -100", "output": "1" }, { "input": "1 1 100", "output": "1" }, { "input": "1 1 -100", "output": "1" }, { "input": "3 1 -100", "output": "3" }, { "input": "4 3 -100", "output": "3" }, { "input": "3 2 -12", "output": "2" }, { "input": "2 2 -100", "output": "2" }, { "input": "3 2 -90", "output": "2" }, { "input": "6 2 -10", "output": "4" }, { "input": "3 3 -100", "output": "2" }, { "input": "5 2 4", "output": "1" }, { "input": "6 4 5", "output": "3" }, { "input": "3 2 -6", "output": "2" }, { "input": "5 1 -99", "output": "2" }, { "input": "6 2 5", "output": "1" }, { "input": "10 1 -100", "output": "1" }, { "input": "2 2 1", "output": "1" }, { "input": "3 3 1", "output": "1" }, { "input": "6 4 4", "output": "2" }, { "input": "17 17 2", "output": "2" }, { "input": "6 6 1", "output": "1" }, { "input": "5 3 -2", "output": "1" }, { "input": "6 2 -100", "output": "4" }, { "input": "5 3 -100", "output": "3" }, { "input": "5 4 3", "output": "2" }, { "input": "3 2 2", "output": "1" }, { "input": "5 5 2", "output": "2" }, { "input": "3 2 5", "output": "1" }, { "input": "5 5 -1", "output": "4" }, { "input": "5 3 3", "output": "1" }, { "input": "4 2 3", "output": "1" }, { "input": "88 76 74", "output": "62" } ]
1,615,193,868
2,147,483,647
Python 3
RUNTIME_ERROR
TESTS
0
46
0
if n == 1: print(1) elif b >= 0 and len(mas) >= a + b: print(a + b) elif b < 0 and a + b >=0: print(a+b) else: div = b // len(mas) remains = b % len(mas) print(mas[remains + 1])
Title: Round House Time Limit: None seconds Memory Limit: None megabytes Problem Description: Vasya lives in a round building, whose entrances are numbered sequentially by integers from 1 to *n*. Entrance *n* and entrance 1 are adjacent. Today Vasya got bored and decided to take a walk in the yard. Vasya lives in entrance *a* and he decided that during his walk he will move around the house *b* entrances in the direction of increasing numbers (in this order entrance *n* should be followed by entrance 1). The negative value of *b* corresponds to moving |*b*| entrances in the order of decreasing numbers (in this order entrance 1 is followed by entrance *n*). If *b*<==<=0, then Vasya prefers to walk beside his entrance. Help Vasya to determine the number of the entrance, near which he will be at the end of his walk. Input Specification: The single line of the input contains three space-separated integers *n*, *a* and *b* (1<=≤<=*n*<=≤<=100,<=1<=≤<=*a*<=≤<=*n*,<=<=-<=100<=≤<=*b*<=≤<=100) — the number of entrances at Vasya's place, the number of his entrance and the length of his walk, respectively. Output Specification: Print a single integer *k* (1<=≤<=*k*<=≤<=*n*) — the number of the entrance where Vasya will be at the end of his walk. Demo Input: ['6 2 -5\n', '5 1 3\n', '3 2 7\n'] Demo Output: ['3\n', '4\n', '3\n'] Note: The first example is illustrated by the picture in the statements.
```python if n == 1: print(1) elif b >= 0 and len(mas) >= a + b: print(a + b) elif b < 0 and a + b >=0: print(a+b) else: div = b // len(mas) remains = b % len(mas) print(mas[remains + 1]) ```
-1
899
A
Splitting in Teams
PROGRAMMING
800
[ "constructive algorithms", "greedy", "math" ]
null
null
There were *n* groups of students which came to write a training contest. A group is either one person who can write the contest with anyone else, or two people who want to write the contest in the same team. The coach decided to form teams of exactly three people for this training. Determine the maximum number of teams of three people he can form. It is possible that he can't use all groups to form teams. For groups of two, either both students should write the contest, or both should not. If two students from a group of two will write the contest, they should be in the same team.
The first line contains single integer *n* (2<=≤<=*n*<=≤<=2·105) — the number of groups. The second line contains a sequence of integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=2), where *a**i* is the number of people in group *i*.
Print the maximum number of teams of three people the coach can form.
[ "4\n1 1 2 1\n", "2\n2 2\n", "7\n2 2 2 1 1 1 1\n", "3\n1 1 1\n" ]
[ "1\n", "0\n", "3\n", "1\n" ]
In the first example the coach can form one team. For example, he can take students from the first, second and fourth groups. In the second example he can't make a single team. In the third example the coach can form three teams. For example, he can do this in the following way: - The first group (of two people) and the seventh group (of one person), - The second group (of two people) and the sixth group (of one person), - The third group (of two people) and the fourth group (of one person).
500
[ { "input": "4\n1 1 2 1", "output": "1" }, { "input": "2\n2 2", "output": "0" }, { "input": "7\n2 2 2 1 1 1 1", "output": "3" }, { "input": "3\n1 1 1", "output": "1" }, { "input": "3\n2 2 2", "output": "0" }, { "input": "3\n1 2 1", "output": "1" }, { "input": "5\n2 2 1 1 1", "output": "2" }, { "input": "7\n1 1 2 2 1 2 1", "output": "3" }, { "input": "10\n1 2 2 1 2 2 1 2 1 1", "output": "5" }, { "input": "5\n2 2 2 1 2", "output": "1" }, { "input": "43\n1 2 2 2 1 1 2 2 1 1 2 2 2 2 1 2 2 2 2 2 1 2 1 2 1 2 2 2 2 2 2 2 2 1 2 2 2 2 2 2 2 2 2", "output": "10" }, { "input": "72\n1 2 1 2 2 1 2 1 1 1 1 2 2 1 2 1 2 1 2 2 2 2 1 2 2 2 2 1 2 1 1 2 2 1 1 2 2 2 2 2 1 1 1 1 2 2 1 1 2 1 1 1 1 2 2 1 2 2 1 2 1 1 2 1 2 2 1 1 1 2 2 2", "output": "34" }, { "input": "64\n2 2 1 1 1 2 1 1 1 2 2 1 2 2 2 1 2 2 2 1 1 1 1 2 1 2 1 2 1 1 2 2 1 1 2 2 1 1 1 1 2 2 1 1 1 2 1 2 2 2 2 2 2 2 1 1 2 1 1 1 2 2 1 2", "output": "32" }, { "input": "20\n1 1 1 1 2 1 2 2 2 1 2 1 2 1 2 1 1 2 1 2", "output": "9" }, { "input": "23\n1 1 1 1 2 1 2 1 1 1 2 2 2 2 2 2 1 2 1 2 2 1 1", "output": "11" }, { "input": "201\n1 1 2 2 2 2 1 1 1 2 2 1 2 1 2 1 2 2 2 1 1 2 1 1 1 2 1 2 1 1 1 2 1 1 2 1 2 2 1 1 1 1 2 1 1 2 1 1 1 2 2 2 2 1 2 1 2 2 2 2 2 2 1 1 1 2 2 1 1 1 1 2 2 1 2 1 1 2 2 1 1 2 2 2 1 1 1 2 1 1 2 1 2 2 1 2 2 2 2 1 1 1 2 1 2 2 2 2 2 1 2 1 1 1 2 2 2 2 2 1 2 1 1 2 2 2 1 1 2 2 1 2 2 2 1 1 1 2 1 1 1 2 1 1 2 2 2 1 2 1 1 1 2 2 1 1 2 2 2 2 2 2 1 2 2 1 2 2 2 1 1 2 2 1 1 2 1 1 1 1 2 1 1 1 2 2 1 2 1 1 2 2 1 1 2 1 2 1 1 1 2", "output": "100" }, { "input": "247\n2 2 1 2 1 2 2 2 2 2 2 1 1 2 2 1 2 1 1 1 2 1 1 1 1 2 1 1 2 2 1 2 1 1 1 2 2 2 1 1 2 1 1 2 1 1 1 2 1 2 1 2 2 1 1 2 1 2 2 1 2 1 2 1 1 2 1 1 1 2 2 1 1 2 2 1 1 2 1 1 1 2 2 2 2 1 2 2 2 2 2 2 1 2 2 2 2 1 1 1 1 1 1 1 1 1 2 1 2 2 1 2 1 2 2 2 1 2 2 2 1 1 2 2 1 1 1 2 1 1 1 1 2 2 1 2 2 1 1 1 2 1 2 2 1 2 1 1 1 2 2 2 2 2 1 2 2 2 1 1 1 2 1 2 1 1 2 2 2 2 1 1 2 2 2 1 2 2 2 1 2 1 1 2 2 2 2 1 2 2 1 1 1 2 1 2 1 1 1 2 2 1 1 2 1 1 2 1 2 1 1 2 1 1 1 1 2 1 1 1 1 2 2 1 2 1 1 2 1 2 2 1 2 2 2 1 2 2 1 2 2 1 1 1 2 2 2", "output": "123" }, { "input": "4\n2 2 2 2", "output": "0" }, { "input": "4\n1 1 1 1", "output": "1" }, { "input": "2\n1 1", "output": "0" }, { "input": "2\n2 1", "output": "1" }, { "input": "2\n1 2", "output": "1" }, { "input": "3\n1 1 2", "output": "1" }, { "input": "3\n1 2 2", "output": "1" }, { "input": "3\n2 1 1", "output": "1" }, { "input": "3\n2 1 2", "output": "1" }, { "input": "3\n2 2 1", "output": "1" }, { "input": "4\n1 1 1 2", "output": "1" }, { "input": "4\n1 1 2 2", "output": "2" }, { "input": "4\n1 2 2 2", "output": "1" }, { "input": "4\n2 1 1 1", "output": "1" }, { "input": "5\n1 1 1 1 2", "output": "2" }, { "input": "14\n1 2 2 2 2 2 2 2 2 2 2 2 2 2", "output": "1" }, { "input": "38\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 1", "output": "1" }, { "input": "30\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 1", "output": "1" }, { "input": "20\n2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 1", "output": "1" }, { "input": "26\n2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 1 2 2 2 2", "output": "1" }, { "input": "6\n1 1 1 2 2 2", "output": "3" }, { "input": "5\n2 1 1 1 1", "output": "2" }, { "input": "9\n1 1 1 1 1 1 2 2 2", "output": "4" }, { "input": "10\n2 2 1 1 1 1 1 1 1 1", "output": "4" }, { "input": "6\n1 1 1 1 1 1", "output": "2" } ]
1,622,618,615
2,147,483,647
Python 3
OK
TESTS
67
186
3,481,600
n=int(input()) a=list(map(int,input().split())) c1=0 c2=0 for i in a: if(i==1): c1+=1 if(i==2): c2+=1 r=c1 if(c1>c2): r=c2+int((c1-c2)/3) print(r)
Title: Splitting in Teams Time Limit: None seconds Memory Limit: None megabytes Problem Description: There were *n* groups of students which came to write a training contest. A group is either one person who can write the contest with anyone else, or two people who want to write the contest in the same team. The coach decided to form teams of exactly three people for this training. Determine the maximum number of teams of three people he can form. It is possible that he can't use all groups to form teams. For groups of two, either both students should write the contest, or both should not. If two students from a group of two will write the contest, they should be in the same team. Input Specification: The first line contains single integer *n* (2<=≤<=*n*<=≤<=2·105) — the number of groups. The second line contains a sequence of integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=2), where *a**i* is the number of people in group *i*. Output Specification: Print the maximum number of teams of three people the coach can form. Demo Input: ['4\n1 1 2 1\n', '2\n2 2\n', '7\n2 2 2 1 1 1 1\n', '3\n1 1 1\n'] Demo Output: ['1\n', '0\n', '3\n', '1\n'] Note: In the first example the coach can form one team. For example, he can take students from the first, second and fourth groups. In the second example he can't make a single team. In the third example the coach can form three teams. For example, he can do this in the following way: - The first group (of two people) and the seventh group (of one person), - The second group (of two people) and the sixth group (of one person), - The third group (of two people) and the fourth group (of one person).
```python n=int(input()) a=list(map(int,input().split())) c1=0 c2=0 for i in a: if(i==1): c1+=1 if(i==2): c2+=1 r=c1 if(c1>c2): r=c2+int((c1-c2)/3) print(r) ```
3
632
A
Grandma Laura and Apples
PROGRAMMING
1,200
[]
null
null
Grandma Laura came to the market to sell some apples. During the day she sold all the apples she had. But grandma is old, so she forgot how many apples she had brought to the market. She precisely remembers she had *n* buyers and each of them bought exactly half of the apples she had at the moment of the purchase and also she gave a half of an apple to some of them as a gift (if the number of apples at the moment of purchase was odd), until she sold all the apples she had. So each buyer took some integral positive number of apples, but maybe he didn't pay for a half of an apple (if the number of apples at the moment of the purchase was odd). For each buyer grandma remembers if she gave a half of an apple as a gift or not. The cost of an apple is *p* (the number *p* is even). Print the total money grandma should have at the end of the day to check if some buyers cheated her.
The first line contains two integers *n* and *p* (1<=≤<=*n*<=≤<=40,<=2<=≤<=*p*<=≤<=1000) — the number of the buyers and the cost of one apple. It is guaranteed that the number *p* is even. The next *n* lines contains the description of buyers. Each buyer is described with the string half if he simply bought half of the apples and with the string halfplus if grandma also gave him a half of an apple as a gift. It is guaranteed that grandma has at least one apple at the start of the day and she has no apples at the end of the day.
Print the only integer *a* — the total money grandma should have at the end of the day. Note that the answer can be too large, so you should use 64-bit integer type to store it. In C++ you can use the long long integer type and in Java you can use long integer type.
[ "2 10\nhalf\nhalfplus\n", "3 10\nhalfplus\nhalfplus\nhalfplus\n" ]
[ "15\n", "55\n" ]
In the first sample at the start of the day the grandma had two apples. First she sold one apple and then she sold a half of the second apple and gave a half of the second apple as a present to the second buyer.
0
[ { "input": "2 10\nhalf\nhalfplus", "output": "15" }, { "input": "3 10\nhalfplus\nhalfplus\nhalfplus", "output": "55" }, { "input": "10 328\nhalf\nhalfplus\nhalfplus\nhalf\nhalfplus\nhalf\nhalf\nhalf\nhalfplus\nhalfplus", "output": "258300" }, { "input": "1 2\nhalfplus", "output": "1" }, { "input": "5 6\nhalf\nhalf\nhalfplus\nhalf\nhalfplus", "output": "114" }, { "input": "10 2\nhalfplus\nhalfplus\nhalfplus\nhalf\nhalfplus\nhalf\nhalfplus\nhalf\nhalfplus\nhalfplus", "output": "1703" }, { "input": "20 6\nhalf\nhalfplus\nhalfplus\nhalfplus\nhalf\nhalf\nhalfplus\nhalf\nhalfplus\nhalfplus\nhalfplus\nhalf\nhalf\nhalfplus\nhalfplus\nhalf\nhalfplus\nhalfplus\nhalfplus\nhalfplus", "output": "6056877" }, { "input": "30 68\nhalf\nhalf\nhalf\nhalfplus\nhalfplus\nhalf\nhalf\nhalf\nhalf\nhalf\nhalf\nhalf\nhalf\nhalfplus\nhalfplus\nhalf\nhalfplus\nhalf\nhalfplus\nhalf\nhalfplus\nhalfplus\nhalfplus\nhalf\nhalf\nhalf\nhalfplus\nhalf\nhalfplus\nhalfplus", "output": "59847312584" }, { "input": "40 562\nhalfplus\nhalfplus\nhalfplus\nhalfplus\nhalfplus\nhalfplus\nhalfplus\nhalfplus\nhalf\nhalf\nhalf\nhalfplus\nhalf\nhalf\nhalfplus\nhalf\nhalfplus\nhalf\nhalfplus\nhalf\nhalfplus\nhalf\nhalfplus\nhalfplus\nhalfplus\nhalfplus\nhalfplus\nhalf\nhalf\nhalfplus\nhalf\nhalfplus\nhalfplus\nhalf\nhalf\nhalfplus\nhalf\nhalf\nhalfplus\nhalfplus", "output": "486750560068982" } ]
1,644,525,122
2,147,483,647
PyPy 3-64
WRONG_ANSWER
TESTS
2
77
0
import math def main_function(): n, p = [int(i) for i in input().split(" ")] customers = [input() for i in range(n)] counter = 0 customers.reverse() for i in range(len(customers)): if i == 0: starter = 1 counter += int(0.5 * p) else: if len(customers[i]) == 8: counter += int((starter + 0.5) * p) starter += starter + 1 starter = int(starter) else: counter += int((starter)) * p starter += starter + 1 starter = int(starter) # print(customers[i], starter, counter) print(counter) if __name__ == '__main__': main_function()
Title: Grandma Laura and Apples Time Limit: None seconds Memory Limit: None megabytes Problem Description: Grandma Laura came to the market to sell some apples. During the day she sold all the apples she had. But grandma is old, so she forgot how many apples she had brought to the market. She precisely remembers she had *n* buyers and each of them bought exactly half of the apples she had at the moment of the purchase and also she gave a half of an apple to some of them as a gift (if the number of apples at the moment of purchase was odd), until she sold all the apples she had. So each buyer took some integral positive number of apples, but maybe he didn't pay for a half of an apple (if the number of apples at the moment of the purchase was odd). For each buyer grandma remembers if she gave a half of an apple as a gift or not. The cost of an apple is *p* (the number *p* is even). Print the total money grandma should have at the end of the day to check if some buyers cheated her. Input Specification: The first line contains two integers *n* and *p* (1<=≤<=*n*<=≤<=40,<=2<=≤<=*p*<=≤<=1000) — the number of the buyers and the cost of one apple. It is guaranteed that the number *p* is even. The next *n* lines contains the description of buyers. Each buyer is described with the string half if he simply bought half of the apples and with the string halfplus if grandma also gave him a half of an apple as a gift. It is guaranteed that grandma has at least one apple at the start of the day and she has no apples at the end of the day. Output Specification: Print the only integer *a* — the total money grandma should have at the end of the day. Note that the answer can be too large, so you should use 64-bit integer type to store it. In C++ you can use the long long integer type and in Java you can use long integer type. Demo Input: ['2 10\nhalf\nhalfplus\n', '3 10\nhalfplus\nhalfplus\nhalfplus\n'] Demo Output: ['15\n', '55\n'] Note: In the first sample at the start of the day the grandma had two apples. First she sold one apple and then she sold a half of the second apple and gave a half of the second apple as a present to the second buyer.
```python import math def main_function(): n, p = [int(i) for i in input().split(" ")] customers = [input() for i in range(n)] counter = 0 customers.reverse() for i in range(len(customers)): if i == 0: starter = 1 counter += int(0.5 * p) else: if len(customers[i]) == 8: counter += int((starter + 0.5) * p) starter += starter + 1 starter = int(starter) else: counter += int((starter)) * p starter += starter + 1 starter = int(starter) # print(customers[i], starter, counter) print(counter) if __name__ == '__main__': main_function() ```
0
39
D
Cubical Planet
PROGRAMMING
1,100
[ "math" ]
D. Cubical Planet
2
64
You can find anything whatsoever in our Galaxy! A cubical planet goes round an icosahedral star. Let us introduce a system of axes so that the edges of the cubical planet are parallel to the coordinate axes and two opposite vertices lay in the points (0,<=0,<=0) and (1,<=1,<=1). Two flies live on the planet. At the moment they are sitting on two different vertices of the cubical planet. Your task is to determine whether they see each other or not. The flies see each other when the vertices they occupy lie on the same face of the cube.
The first line contains three space-separated integers (0 or 1) — the coordinates of the first fly, the second line analogously contains the coordinates of the second fly.
Output "YES" (without quotes) if the flies see each other. Otherwise, output "NO".
[ "0 0 0\n0 1 0\n", "1 1 0\n0 1 0\n", "0 0 0\n1 1 1\n" ]
[ "YES\n", "YES\n", "NO\n" ]
none
0
[ { "input": "0 0 0\n0 1 0", "output": "YES" }, { "input": "1 1 0\n0 1 0", "output": "YES" }, { "input": "0 0 0\n1 1 1", "output": "NO" }, { "input": "0 0 0\n1 0 0", "output": "YES" }, { "input": "0 0 0\n0 1 0", "output": "YES" }, { "input": "0 0 0\n1 1 0", "output": "YES" }, { "input": "0 0 0\n0 0 1", "output": "YES" }, { "input": "0 0 0\n1 0 1", "output": "YES" }, { "input": "0 0 0\n0 1 1", "output": "YES" }, { "input": "0 0 0\n1 1 1", "output": "NO" }, { "input": "1 0 0\n0 0 0", "output": "YES" }, { "input": "1 0 0\n0 1 0", "output": "YES" }, { "input": "1 0 0\n1 1 0", "output": "YES" }, { "input": "1 0 0\n0 0 1", "output": "YES" }, { "input": "1 0 0\n1 0 1", "output": "YES" }, { "input": "1 0 0\n0 1 1", "output": "NO" }, { "input": "1 0 0\n1 1 1", "output": "YES" }, { "input": "0 1 0\n0 0 0", "output": "YES" }, { "input": "0 1 0\n1 0 0", "output": "YES" }, { "input": "0 1 0\n1 1 0", "output": "YES" }, { "input": "0 1 0\n0 0 1", "output": "YES" }, { "input": "0 1 0\n1 0 1", "output": "NO" }, { "input": "0 1 0\n0 1 1", "output": "YES" }, { "input": "0 1 0\n1 1 1", "output": "YES" }, { "input": "1 1 0\n0 0 0", "output": "YES" }, { "input": "1 1 0\n1 0 0", "output": "YES" }, { "input": "1 1 0\n0 1 0", "output": "YES" }, { "input": "1 1 0\n0 0 1", "output": "NO" }, { "input": "1 1 0\n1 0 1", "output": "YES" }, { "input": "1 1 0\n0 1 1", "output": "YES" }, { "input": "1 1 0\n1 1 1", "output": "YES" }, { "input": "0 0 1\n0 0 0", "output": "YES" }, { "input": "0 0 1\n1 0 0", "output": "YES" }, { "input": "0 0 1\n0 1 0", "output": "YES" }, { "input": "0 0 1\n1 1 0", "output": "NO" }, { "input": "0 0 1\n1 0 1", "output": "YES" }, { "input": "0 0 1\n0 1 1", "output": "YES" }, { "input": "0 0 1\n1 1 1", "output": "YES" }, { "input": "1 0 1\n0 0 0", "output": "YES" }, { "input": "1 0 1\n1 0 0", "output": "YES" }, { "input": "1 0 1\n0 1 0", "output": "NO" }, { "input": "1 0 1\n1 1 0", "output": "YES" }, { "input": "1 0 1\n0 0 1", "output": "YES" }, { "input": "1 0 1\n0 1 1", "output": "YES" }, { "input": "1 0 1\n1 1 1", "output": "YES" }, { "input": "0 1 1\n0 0 0", "output": "YES" }, { "input": "0 1 1\n1 0 0", "output": "NO" }, { "input": "0 1 1\n0 1 0", "output": "YES" }, { "input": "0 1 1\n1 1 0", "output": "YES" }, { "input": "0 1 1\n0 0 1", "output": "YES" }, { "input": "0 1 1\n1 0 1", "output": "YES" }, { "input": "0 1 1\n1 1 1", "output": "YES" }, { "input": "1 1 1\n0 0 0", "output": "NO" }, { "input": "1 1 1\n1 0 0", "output": "YES" }, { "input": "1 1 1\n0 1 0", "output": "YES" }, { "input": "1 1 1\n1 1 0", "output": "YES" }, { "input": "1 1 1\n0 0 1", "output": "YES" }, { "input": "1 1 1\n1 0 1", "output": "YES" }, { "input": "1 1 1\n0 1 1", "output": "YES" } ]
1,639,726,297
2,147,483,647
PyPy 3
WRONG_ANSWER
TESTS
1
124
0
li1 = list(map(int, input().split())) li2 = list(map(int, input().split())) cnt=0 for i in range(3): cnt+=li1[i]+li2[i] if(cnt==3): print("NO") else: print("YES")
Title: Cubical Planet Time Limit: 2 seconds Memory Limit: 64 megabytes Problem Description: You can find anything whatsoever in our Galaxy! A cubical planet goes round an icosahedral star. Let us introduce a system of axes so that the edges of the cubical planet are parallel to the coordinate axes and two opposite vertices lay in the points (0,<=0,<=0) and (1,<=1,<=1). Two flies live on the planet. At the moment they are sitting on two different vertices of the cubical planet. Your task is to determine whether they see each other or not. The flies see each other when the vertices they occupy lie on the same face of the cube. Input Specification: The first line contains three space-separated integers (0 or 1) — the coordinates of the first fly, the second line analogously contains the coordinates of the second fly. Output Specification: Output "YES" (without quotes) if the flies see each other. Otherwise, output "NO". Demo Input: ['0 0 0\n0 1 0\n', '1 1 0\n0 1 0\n', '0 0 0\n1 1 1\n'] Demo Output: ['YES\n', 'YES\n', 'NO\n'] Note: none
```python li1 = list(map(int, input().split())) li2 = list(map(int, input().split())) cnt=0 for i in range(3): cnt+=li1[i]+li2[i] if(cnt==3): print("NO") else: print("YES") ```
0
884
B
Japanese Crosswords Strike Back
PROGRAMMING
1,100
[ "implementation" ]
null
null
A one-dimensional Japanese crossword can be represented as a binary string of length *x*. An encoding of this crossword is an array *a* of size *n*, where *n* is the number of segments formed completely of 1's, and *a**i* is the length of *i*-th segment. No two segments touch or intersect. For example: - If *x*<==<=6 and the crossword is 111011, then its encoding is an array {3,<=2}; - If *x*<==<=8 and the crossword is 01101010, then its encoding is an array {2,<=1,<=1}; - If *x*<==<=5 and the crossword is 11111, then its encoding is an array {5}; - If *x*<==<=5 and the crossword is 00000, then its encoding is an empty array. Mishka wants to create a new one-dimensional Japanese crossword. He has already picked the length and the encoding for this crossword. And now he needs to check if there is exactly one crossword such that its length and encoding are equal to the length and encoding he picked. Help him to check it!
The first line contains two integer numbers *n* and *x* (1<=≤<=*n*<=≤<=100000, 1<=≤<=*x*<=≤<=109) — the number of elements in the encoding and the length of the crossword Mishka picked. The second line contains *n* integer numbers *a*1, *a*2, ..., *a**n* (1<=≤<=*a**i*<=≤<=10000) — the encoding.
Print YES if there exists exaclty one crossword with chosen length and encoding. Otherwise, print NO.
[ "2 4\n1 3\n", "3 10\n3 3 2\n", "2 10\n1 3\n" ]
[ "NO\n", "YES\n", "NO\n" ]
none
0
[ { "input": "2 4\n1 3", "output": "NO" }, { "input": "3 10\n3 3 2", "output": "YES" }, { "input": "2 10\n1 3", "output": "NO" }, { "input": "1 1\n1", "output": "YES" }, { "input": "1 10\n10", "output": "YES" }, { "input": "1 10000\n10000", "output": "YES" }, { "input": "10 1\n5 78 3 87 4 9 5 8 9 1235", "output": "NO" }, { "input": "3 12\n3 3 3", "output": "NO" }, { "input": "3 9\n2 2 2", "output": "NO" }, { "input": "2 5\n1 1", "output": "NO" }, { "input": "1 2\n1", "output": "NO" }, { "input": "3 13\n3 3 3", "output": "NO" }, { "input": "3 6\n1 1 1", "output": "NO" }, { "input": "1 6\n5", "output": "NO" }, { "input": "3 11\n3 3 2", "output": "NO" }, { "input": "2 6\n1 3", "output": "NO" }, { "input": "3 10\n2 2 2", "output": "NO" }, { "input": "3 8\n2 1 1", "output": "NO" }, { "input": "1 5\n2", "output": "NO" }, { "input": "1 3\n1", "output": "NO" }, { "input": "5 5\n1 1 1 1 1", "output": "NO" }, { "input": "2 10\n4 4", "output": "NO" }, { "input": "2 8\n2 3", "output": "NO" }, { "input": "2 4\n1 1", "output": "NO" }, { "input": "3 10\n1 2 4", "output": "NO" }, { "input": "3 10\n2 1 3", "output": "NO" }, { "input": "2 6\n1 2", "output": "NO" }, { "input": "3 4\n1 1 1", "output": "NO" }, { "input": "3 11\n1 2 4", "output": "NO" }, { "input": "3 12\n3 3 2", "output": "NO" }, { "input": "4 9\n1 1 1 1", "output": "NO" }, { "input": "1 10\n9", "output": "NO" }, { "input": "1 7\n5", "output": "NO" }, { "input": "2 5\n1 2", "output": "NO" }, { "input": "3 8\n1 1 2", "output": "NO" }, { "input": "3 7\n1 1 1", "output": "NO" }, { "input": "1 10\n1", "output": "NO" }, { "input": "3 10\n2 3 4", "output": "NO" }, { "input": "3 9\n1 2 3", "output": "NO" }, { "input": "3 9\n3 3 2", "output": "NO" }, { "input": "3 6\n3 3 2", "output": "NO" }, { "input": "1 1\n3", "output": "NO" }, { "input": "1 3\n2", "output": "NO" }, { "input": "3 10\n3 3 3", "output": "NO" }, { "input": "3 5\n1 1 1", "output": "YES" }, { "input": "2 1\n100 100", "output": "NO" }, { "input": "3 3\n3 3 3", "output": "NO" }, { "input": "4 17\n3 3 9 1", "output": "NO" }, { "input": "4 1660\n1505 13 37 100", "output": "NO" }, { "input": "3 5\n3 3 2", "output": "NO" }, { "input": "4 10\n3 3 2 5", "output": "NO" }, { "input": "5 5\n5 5 5 5 5", "output": "NO" }, { "input": "1 1\n2", "output": "NO" }, { "input": "5 10\n1 2 2 4 5", "output": "NO" }, { "input": "2 1\n1 1", "output": "NO" } ]
1,509,465,642
2,147,483,647
Python 3
OK
TESTS
66
77
7,372,800
n,x=list(map(int,input().split())) a=list(map(int,input().split())) if sum(a) + n - 1 == x: print('Yes') else: print('No')
Title: Japanese Crosswords Strike Back Time Limit: None seconds Memory Limit: None megabytes Problem Description: A one-dimensional Japanese crossword can be represented as a binary string of length *x*. An encoding of this crossword is an array *a* of size *n*, where *n* is the number of segments formed completely of 1's, and *a**i* is the length of *i*-th segment. No two segments touch or intersect. For example: - If *x*<==<=6 and the crossword is 111011, then its encoding is an array {3,<=2}; - If *x*<==<=8 and the crossword is 01101010, then its encoding is an array {2,<=1,<=1}; - If *x*<==<=5 and the crossword is 11111, then its encoding is an array {5}; - If *x*<==<=5 and the crossword is 00000, then its encoding is an empty array. Mishka wants to create a new one-dimensional Japanese crossword. He has already picked the length and the encoding for this crossword. And now he needs to check if there is exactly one crossword such that its length and encoding are equal to the length and encoding he picked. Help him to check it! Input Specification: The first line contains two integer numbers *n* and *x* (1<=≤<=*n*<=≤<=100000, 1<=≤<=*x*<=≤<=109) — the number of elements in the encoding and the length of the crossword Mishka picked. The second line contains *n* integer numbers *a*1, *a*2, ..., *a**n* (1<=≤<=*a**i*<=≤<=10000) — the encoding. Output Specification: Print YES if there exists exaclty one crossword with chosen length and encoding. Otherwise, print NO. Demo Input: ['2 4\n1 3\n', '3 10\n3 3 2\n', '2 10\n1 3\n'] Demo Output: ['NO\n', 'YES\n', 'NO\n'] Note: none
```python n,x=list(map(int,input().split())) a=list(map(int,input().split())) if sum(a) + n - 1 == x: print('Yes') else: print('No') ```
3
266
A
Stones on the Table
PROGRAMMING
800
[ "implementation" ]
null
null
There are *n* stones on the table in a row, each of them can be red, green or blue. Count the minimum number of stones to take from the table so that any two neighboring stones had different colors. Stones in a row are considered neighboring if there are no other stones between them.
The first line contains integer *n* (1<=≤<=*n*<=≤<=50) — the number of stones on the table. The next line contains string *s*, which represents the colors of the stones. We'll consider the stones in the row numbered from 1 to *n* from left to right. Then the *i*-th character *s* equals "R", if the *i*-th stone is red, "G", if it's green and "B", if it's blue.
Print a single integer — the answer to the problem.
[ "3\nRRG\n", "5\nRRRRR\n", "4\nBRBG\n" ]
[ "1\n", "4\n", "0\n" ]
none
500
[ { "input": "3\nRRG", "output": "1" }, { "input": "5\nRRRRR", "output": "4" }, { "input": "4\nBRBG", "output": "0" }, { "input": "1\nB", "output": "0" }, { "input": "2\nBG", "output": "0" }, { "input": "3\nBGB", "output": "0" }, { "input": "4\nRBBR", "output": "1" }, { "input": "5\nRGGBG", "output": "1" }, { "input": "10\nGGBRBRGGRB", "output": "2" }, { "input": "50\nGRBGGRBRGRBGGBBBBBGGGBBBBRBRGBRRBRGBBBRBBRRGBGGGRB", "output": "18" }, { "input": "15\nBRRBRGGBBRRRRGR", "output": "6" }, { "input": "20\nRRGBBRBRGRGBBGGRGRRR", "output": "6" }, { "input": "25\nBBGBGRBGGBRRBGRRBGGBBRBRB", "output": "6" }, { "input": "30\nGRGGGBGGRGBGGRGRBGBGBRRRRRRGRB", "output": "9" }, { "input": "35\nGBBGBRGBBGGRBBGBRRGGRRRRRRRBRBBRRGB", "output": "14" }, { "input": "40\nGBBRRGBGGGRGGGRRRRBRBGGBBGGGBGBBBBBRGGGG", "output": "20" }, { "input": "45\nGGGBBRBBRRGRBBGGBGRBRGGBRBRGBRRGBGRRBGRGRBRRG", "output": "11" }, { "input": "50\nRBGGBGGRBGRBBBGBBGRBBBGGGRBBBGBBBGRGGBGGBRBGBGRRGG", "output": "17" }, { "input": "50\nGGGBBRGGGGGRRGGRBGGRGBBRBRRBGRGBBBGBRBGRGBBGRGGBRB", "output": "16" }, { "input": "50\nGBGRGRRBRRRRRGGBBGBRRRBBBRBBBRRGRBBRGBRBGGRGRBBGGG", "output": "19" }, { "input": "10\nGRRBRBRBGR", "output": "1" }, { "input": "10\nBRBGBGRRBR", "output": "1" }, { "input": "20\nGBGBGGRRRRGRBBGRGRGR", "output": "5" }, { "input": "20\nRRGGRBBGBBRBGRRBRRBG", "output": "6" }, { "input": "30\nBGBRGBBBGRGBBRGBGRBBBRGGRRGRRB", "output": "8" }, { "input": "30\nBBBBGGBRBGBBGBGBGBGGGRGRRGGBBB", "output": "11" }, { "input": "40\nGBRRGRBGBRRGBRGGGBRGBGBRGBBRRGRGGBBGBGBB", "output": "9" }, { "input": "40\nBRGRGGRGGRBBRRRBRBBGGGRRGBGBBGRBBRGBRRGG", "output": "13" }, { "input": "50\nRBGBGGRRGGRGGBGBGRRBGGBGBRRBBGBBGBBBGBBRBBRBRBRGRG", "output": "13" }, { "input": "50\nRBRRGBGRRRBGRRBGRRGRBBRBBRRBRGGBRBRRBGGRBGGBRBRGRB", "output": "12" }, { "input": "2\nBB", "output": "1" }, { "input": "50\nRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRR", "output": "49" }, { "input": "50\nRRRRRRRRGRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRR", "output": "47" }, { "input": "50\nRRRRRRRRRRRRGGRRRRRRRRRBRRRRRRRRRRRRRRBBRRRRRRRRRR", "output": "43" } ]
1,697,962,001
2,147,483,647
Python 3
RUNTIME_ERROR
TESTS
0
60
0
t = input() n=int(input()) l=0 s=1 count =0 while (l and s) <= n: if t[l] == t[s]: count +=count l+=1 s+=1 else: l+=1 s+=1 print(count)
Title: Stones on the Table Time Limit: None seconds Memory Limit: None megabytes Problem Description: There are *n* stones on the table in a row, each of them can be red, green or blue. Count the minimum number of stones to take from the table so that any two neighboring stones had different colors. Stones in a row are considered neighboring if there are no other stones between them. Input Specification: The first line contains integer *n* (1<=≤<=*n*<=≤<=50) — the number of stones on the table. The next line contains string *s*, which represents the colors of the stones. We'll consider the stones in the row numbered from 1 to *n* from left to right. Then the *i*-th character *s* equals "R", if the *i*-th stone is red, "G", if it's green and "B", if it's blue. Output Specification: Print a single integer — the answer to the problem. Demo Input: ['3\nRRG\n', '5\nRRRRR\n', '4\nBRBG\n'] Demo Output: ['1\n', '4\n', '0\n'] Note: none
```python t = input() n=int(input()) l=0 s=1 count =0 while (l and s) <= n: if t[l] == t[s]: count +=count l+=1 s+=1 else: l+=1 s+=1 print(count) ```
-1
315
B
Sereja and Array
PROGRAMMING
1,200
[ "implementation" ]
null
null
Sereja has got an array, consisting of *n* integers, *a*1,<=*a*2,<=...,<=*a**n*. Sereja is an active boy, so he is now going to complete *m* operations. Each operation will have one of the three forms: 1. Make *v**i*-th array element equal to *x**i*. In other words, perform the assignment *a**v**i*<==<=*x**i*. 1. Increase each array element by *y**i*. In other words, perform *n* assignments *a**i*<==<=*a**i*<=+<=*y**i* (1<=≤<=*i*<=≤<=*n*). 1. Take a piece of paper and write out the *q**i*-th array element. That is, the element *a**q**i*. Help Sereja, complete all his operations.
The first line contains integers *n*, *m* (1<=≤<=*n*,<=*m*<=≤<=105). The second line contains *n* space-separated integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=109) — the original array. Next *m* lines describe operations, the *i*-th line describes the *i*-th operation. The first number in the *i*-th line is integer *t**i* (1<=≤<=*t**i*<=≤<=3) that represents the operation type. If *t**i*<==<=1, then it is followed by two integers *v**i* and *x**i*, (1<=≤<=*v**i*<=≤<=*n*,<=1<=≤<=*x**i*<=≤<=109). If *t**i*<==<=2, then it is followed by integer *y**i* (1<=≤<=*y**i*<=≤<=104). And if *t**i*<==<=3, then it is followed by integer *q**i* (1<=≤<=*q**i*<=≤<=*n*).
For each third type operation print value *a**q**i*. Print the values in the order, in which the corresponding queries follow in the input.
[ "10 11\n1 2 3 4 5 6 7 8 9 10\n3 2\n3 9\n2 10\n3 1\n3 10\n1 1 10\n2 10\n2 10\n3 1\n3 10\n3 9\n" ]
[ "2\n9\n11\n20\n30\n40\n39\n" ]
none
1,000
[ { "input": "10 11\n1 2 3 4 5 6 7 8 9 10\n3 2\n3 9\n2 10\n3 1\n3 10\n1 1 10\n2 10\n2 10\n3 1\n3 10\n3 9", "output": "2\n9\n11\n20\n30\n40\n39" }, { "input": "1 3\n1\n1 1 2\n2 1\n3 1", "output": "3" }, { "input": "1 1\n1\n3 1", "output": "1" }, { "input": "6 6\n202714501 613423725 367325359 862808465 182588146 745008828\n2 492\n2 1943\n1 3 173984392\n1 3 9356383\n3 4\n1 5 472683539", "output": "862810900" }, { "input": "6 5\n545129895 918519812 2334334 565540665 484519712 904102869\n3 3\n1 2 641196860\n2 779\n2 3036\n3 1", "output": "2334334\n545133710" }, { "input": "5 5\n286163265 724763447 761775891 215352371 491215007\n1 4 780579549\n1 2 638546757\n3 4\n1 3 38072627\n2 6119", "output": "780579549" }, { "input": "4 4\n529316834 995684640 949078705 317773978\n3 3\n3 1\n2 6271\n1 1 856879574", "output": "949078705\n529316834" }, { "input": "5 4\n293170637 715384768 756975575 129004053 875201151\n1 3 695181967\n3 3\n2 2288\n1 5 332270946", "output": "695181967" } ]
1,479,663,298
2,147,483,647
Python 3
TIME_LIMIT_EXCEEDED
TESTS
22
1,000
9,216,000
#Codeforces 351B [n, m] = list(map(int, input().split())) numbers = list(map(int, input().split())) additions = 0 t = 0 while t < m: op = list(map(int, input().split())) if op[0] == 1: numbers[op[1] - 1] = op[2] - additions elif op[0] == 2: additions += op[1] elif op[0] == 3: print(numbers[op[1] - 1] + additions) t += 1
Title: Sereja and Array Time Limit: None seconds Memory Limit: None megabytes Problem Description: Sereja has got an array, consisting of *n* integers, *a*1,<=*a*2,<=...,<=*a**n*. Sereja is an active boy, so he is now going to complete *m* operations. Each operation will have one of the three forms: 1. Make *v**i*-th array element equal to *x**i*. In other words, perform the assignment *a**v**i*<==<=*x**i*. 1. Increase each array element by *y**i*. In other words, perform *n* assignments *a**i*<==<=*a**i*<=+<=*y**i* (1<=≤<=*i*<=≤<=*n*). 1. Take a piece of paper and write out the *q**i*-th array element. That is, the element *a**q**i*. Help Sereja, complete all his operations. Input Specification: The first line contains integers *n*, *m* (1<=≤<=*n*,<=*m*<=≤<=105). The second line contains *n* space-separated integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=109) — the original array. Next *m* lines describe operations, the *i*-th line describes the *i*-th operation. The first number in the *i*-th line is integer *t**i* (1<=≤<=*t**i*<=≤<=3) that represents the operation type. If *t**i*<==<=1, then it is followed by two integers *v**i* and *x**i*, (1<=≤<=*v**i*<=≤<=*n*,<=1<=≤<=*x**i*<=≤<=109). If *t**i*<==<=2, then it is followed by integer *y**i* (1<=≤<=*y**i*<=≤<=104). And if *t**i*<==<=3, then it is followed by integer *q**i* (1<=≤<=*q**i*<=≤<=*n*). Output Specification: For each third type operation print value *a**q**i*. Print the values in the order, in which the corresponding queries follow in the input. Demo Input: ['10 11\n1 2 3 4 5 6 7 8 9 10\n3 2\n3 9\n2 10\n3 1\n3 10\n1 1 10\n2 10\n2 10\n3 1\n3 10\n3 9\n'] Demo Output: ['2\n9\n11\n20\n30\n40\n39\n'] Note: none
```python #Codeforces 351B [n, m] = list(map(int, input().split())) numbers = list(map(int, input().split())) additions = 0 t = 0 while t < m: op = list(map(int, input().split())) if op[0] == 1: numbers[op[1] - 1] = op[2] - additions elif op[0] == 2: additions += op[1] elif op[0] == 3: print(numbers[op[1] - 1] + additions) t += 1 ```
0
832
A
Sasha and Sticks
PROGRAMMING
800
[ "games", "math" ]
null
null
It's one more school day now. Sasha doesn't like classes and is always bored at them. So, each day he invents some game and plays in it alone or with friends. Today he invented one simple game to play with Lena, with whom he shares a desk. The rules are simple. Sasha draws *n* sticks in a row. After that the players take turns crossing out exactly *k* sticks from left or right in each turn. Sasha moves first, because he is the inventor of the game. If there are less than *k* sticks on the paper before some turn, the game ends. Sasha wins if he makes strictly more moves than Lena. Sasha wants to know the result of the game before playing, you are to help him.
The first line contains two integers *n* and *k* (1<=≤<=*n*,<=*k*<=≤<=1018, *k*<=≤<=*n*) — the number of sticks drawn by Sasha and the number *k* — the number of sticks to be crossed out on each turn.
If Sasha wins, print "YES" (without quotes), otherwise print "NO" (without quotes). You can print each letter in arbitrary case (upper of lower).
[ "1 1\n", "10 4\n" ]
[ "YES\n", "NO\n" ]
In the first example Sasha crosses out 1 stick, and then there are no sticks. So Lena can't make a move, and Sasha wins. In the second example Sasha crosses out 4 sticks, then Lena crosses out 4 sticks, and after that there are only 2 sticks left. Sasha can't make a move. The players make equal number of moves, so Sasha doesn't win.
500
[ { "input": "1 1", "output": "YES" }, { "input": "10 4", "output": "NO" }, { "input": "251656215122324104 164397544865601257", "output": "YES" }, { "input": "963577813436662285 206326039287271924", "output": "NO" }, { "input": "1000000000000000000 1", "output": "NO" }, { "input": "253308697183523656 25332878317796706", "output": "YES" }, { "input": "669038685745448997 501718093668307460", "output": "YES" }, { "input": "116453141993601660 87060381463547965", "output": "YES" }, { "input": "766959657 370931668", "output": "NO" }, { "input": "255787422422806632 146884995820359999", "output": "YES" }, { "input": "502007866464507926 71266379084204128", "output": "YES" }, { "input": "257439908778973480 64157133126869976", "output": "NO" }, { "input": "232709385 91708542", "output": "NO" }, { "input": "252482458300407528 89907711721009125", "output": "NO" }, { "input": "6 2", "output": "YES" }, { "input": "6 3", "output": "NO" }, { "input": "6 4", "output": "YES" }, { "input": "6 5", "output": "YES" }, { "input": "6 6", "output": "YES" }, { "input": "258266151957056904 30153168463725364", "output": "NO" }, { "input": "83504367885565783 52285355047292458", "output": "YES" }, { "input": "545668929424440387 508692735816921376", "output": "YES" }, { "input": "547321411485639939 36665750286082900", "output": "NO" }, { "input": "548973893546839491 183137237979822911", "output": "NO" }, { "input": "544068082 193116851", "output": "NO" }, { "input": "871412474 749817171", "output": "YES" }, { "input": "999999999 1247", "output": "NO" }, { "input": "851941088 712987048", "output": "YES" }, { "input": "559922900 418944886", "output": "YES" }, { "input": "293908937 37520518", "output": "YES" }, { "input": "650075786 130049650", "output": "NO" }, { "input": "1000000000 1000000000", "output": "YES" }, { "input": "548147654663723363 107422751713800746", "output": "YES" }, { "input": "828159210 131819483", "output": "NO" }, { "input": "6242634 4110365", "output": "YES" }, { "input": "458601973 245084155", "output": "YES" }, { "input": "349593257 18089089", "output": "YES" }, { "input": "814768821 312514745", "output": "NO" }, { "input": "697884949 626323363", "output": "YES" }, { "input": "667011589 54866795", "output": "NO" }, { "input": "1000000000000000000 2", "output": "NO" }, { "input": "1000000000000000000 3", "output": "YES" }, { "input": "1000000000000000000 4", "output": "NO" }, { "input": "999999999999999 1", "output": "YES" }, { "input": "17 4", "output": "NO" }, { "input": "2 2", "output": "YES" }, { "input": "1000000000000000 2", "output": "NO" }, { "input": "12 4", "output": "YES" }, { "input": "6 1", "output": "NO" }, { "input": "2 1", "output": "NO" }, { "input": "10000000005 1", "output": "YES" }, { "input": "10000000000000009 2", "output": "NO" }, { "input": "12457895452123 1", "output": "YES" }, { "input": "999999999999999999 9", "output": "YES" }, { "input": "1000000000000 3", "output": "YES" }, { "input": "13099714659575475 6549849616514894", "output": "NO" }, { "input": "100000000000000001 1", "output": "YES" }, { "input": "825175814723458 324", "output": "YES" }, { "input": "20 4", "output": "YES" }, { "input": "100000176877 4", "output": "YES" }, { "input": "100000 3", "output": "YES" }, { "input": "946744073709551614 10", "output": "YES" } ]
1,616,825,942
2,147,483,647
PyPy 3
WRONG_ANSWER
TESTS
41
93
0
# cook your dish here import math n ,k = map(int,input().split()) turn =int(n/k) if(turn%2 == 0): print("NO") else: print("YES")
Title: Sasha and Sticks Time Limit: None seconds Memory Limit: None megabytes Problem Description: It's one more school day now. Sasha doesn't like classes and is always bored at them. So, each day he invents some game and plays in it alone or with friends. Today he invented one simple game to play with Lena, with whom he shares a desk. The rules are simple. Sasha draws *n* sticks in a row. After that the players take turns crossing out exactly *k* sticks from left or right in each turn. Sasha moves first, because he is the inventor of the game. If there are less than *k* sticks on the paper before some turn, the game ends. Sasha wins if he makes strictly more moves than Lena. Sasha wants to know the result of the game before playing, you are to help him. Input Specification: The first line contains two integers *n* and *k* (1<=≤<=*n*,<=*k*<=≤<=1018, *k*<=≤<=*n*) — the number of sticks drawn by Sasha and the number *k* — the number of sticks to be crossed out on each turn. Output Specification: If Sasha wins, print "YES" (without quotes), otherwise print "NO" (without quotes). You can print each letter in arbitrary case (upper of lower). Demo Input: ['1 1\n', '10 4\n'] Demo Output: ['YES\n', 'NO\n'] Note: In the first example Sasha crosses out 1 stick, and then there are no sticks. So Lena can't make a move, and Sasha wins. In the second example Sasha crosses out 4 sticks, then Lena crosses out 4 sticks, and after that there are only 2 sticks left. Sasha can't make a move. The players make equal number of moves, so Sasha doesn't win.
```python # cook your dish here import math n ,k = map(int,input().split()) turn =int(n/k) if(turn%2 == 0): print("NO") else: print("YES") ```
0
384
A
Coder
PROGRAMMING
800
[ "implementation" ]
null
null
Iahub likes chess very much. He even invented a new chess piece named Coder. A Coder can move (and attack) one square horizontally or vertically. More precisely, if the Coder is located at position (*x*,<=*y*), he can move to (or attack) positions (*x*<=+<=1,<=*y*), (*x*–1,<=*y*), (*x*,<=*y*<=+<=1) and (*x*,<=*y*–1). Iahub wants to know how many Coders can be placed on an *n*<=×<=*n* chessboard, so that no Coder attacks any other Coder.
The first line contains an integer *n* (1<=≤<=*n*<=≤<=1000).
On the first line print an integer, the maximum number of Coders that can be placed on the chessboard. On each of the next *n* lines print *n* characters, describing the configuration of the Coders. For an empty cell print an '.', and for a Coder print a 'C'. If there are multiple correct answers, you can print any.
[ "2\n" ]
[ "2\nC.\n.C\n" ]
none
500
[ { "input": "2", "output": "2\nC.\n.C" }, { "input": "3", "output": "5\nC.C\n.C.\nC.C" }, { "input": "4", "output": "8\nC.C.\n.C.C\nC.C.\n.C.C" }, { "input": "10", "output": "50\nC.C.C.C.C.\n.C.C.C.C.C\nC.C.C.C.C.\n.C.C.C.C.C\nC.C.C.C.C.\n.C.C.C.C.C\nC.C.C.C.C.\n.C.C.C.C.C\nC.C.C.C.C.\n.C.C.C.C.C" }, { "input": "15", "output": "113\nC.C.C.C.C.C.C.C\n.C.C.C.C.C.C.C.\nC.C.C.C.C.C.C.C\n.C.C.C.C.C.C.C.\nC.C.C.C.C.C.C.C\n.C.C.C.C.C.C.C.\nC.C.C.C.C.C.C.C\n.C.C.C.C.C.C.C.\nC.C.C.C.C.C.C.C\n.C.C.C.C.C.C.C.\nC.C.C.C.C.C.C.C\n.C.C.C.C.C.C.C.\nC.C.C.C.C.C.C.C\n.C.C.C.C.C.C.C.\nC.C.C.C.C.C.C.C" }, { "input": "100", "output": "5000\nC.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.\n.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C\nC.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.\n.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C\nC.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C..." }, { "input": "101", "output": "5101\nC.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C\n.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.\nC.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C\n.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.\nC.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C..." }, { "input": "500", "output": "125000\nC.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.\n...." }, { "input": "501", "output": "125501\nC.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C\n..." }, { "input": "755", "output": "285013\nC.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C..." }, { "input": "888", "output": "394272\nC.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C..." }, { "input": "998", "output": "498002\nC.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C..." }, { "input": "999", "output": "499001\nC.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C..." }, { "input": "1000", "output": "500000\nC.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C..." }, { "input": "1", "output": "1\nC" } ]
1,561,281,103
2,147,483,647
PyPy 3
TIME_LIMIT_EXCEEDED
TESTS
7
1,000
10,854,400
n = int(input()) line = "" for i in range(n): for j in range(n): if (i+j)%2 == 0: line +='C' else: line += '.' line+="\n" print(line.count('C')) print(line)
Title: Coder Time Limit: None seconds Memory Limit: None megabytes Problem Description: Iahub likes chess very much. He even invented a new chess piece named Coder. A Coder can move (and attack) one square horizontally or vertically. More precisely, if the Coder is located at position (*x*,<=*y*), he can move to (or attack) positions (*x*<=+<=1,<=*y*), (*x*–1,<=*y*), (*x*,<=*y*<=+<=1) and (*x*,<=*y*–1). Iahub wants to know how many Coders can be placed on an *n*<=×<=*n* chessboard, so that no Coder attacks any other Coder. Input Specification: The first line contains an integer *n* (1<=≤<=*n*<=≤<=1000). Output Specification: On the first line print an integer, the maximum number of Coders that can be placed on the chessboard. On each of the next *n* lines print *n* characters, describing the configuration of the Coders. For an empty cell print an '.', and for a Coder print a 'C'. If there are multiple correct answers, you can print any. Demo Input: ['2\n'] Demo Output: ['2\nC.\n.C\n'] Note: none
```python n = int(input()) line = "" for i in range(n): for j in range(n): if (i+j)%2 == 0: line +='C' else: line += '.' line+="\n" print(line.count('C')) print(line) ```
0
236
A
Boy or Girl
PROGRAMMING
800
[ "brute force", "implementation", "strings" ]
null
null
Those days, many boys use beautiful girls' photos as avatars in forums. So it is pretty hard to tell the gender of a user at the first glance. Last year, our hero went to a forum and had a nice chat with a beauty (he thought so). After that they talked very often and eventually they became a couple in the network. But yesterday, he came to see "her" in the real world and found out "she" is actually a very strong man! Our hero is very sad and he is too tired to love again now. So he came up with a way to recognize users' genders by their user names. This is his method: if the number of distinct characters in one's user name is odd, then he is a male, otherwise she is a female. You are given the string that denotes the user name, please help our hero to determine the gender of this user by his method.
The first line contains a non-empty string, that contains only lowercase English letters — the user name. This string contains at most 100 letters.
If it is a female by our hero's method, print "CHAT WITH HER!" (without the quotes), otherwise, print "IGNORE HIM!" (without the quotes).
[ "wjmzbmr\n", "xiaodao\n", "sevenkplus\n" ]
[ "CHAT WITH HER!\n", "IGNORE HIM!\n", "CHAT WITH HER!\n" ]
For the first example. There are 6 distinct characters in "wjmzbmr". These characters are: "w", "j", "m", "z", "b", "r". So wjmzbmr is a female and you should print "CHAT WITH HER!".
500
[ { "input": "wjmzbmr", "output": "CHAT WITH HER!" }, { "input": "xiaodao", "output": "IGNORE HIM!" }, { "input": "sevenkplus", "output": "CHAT WITH HER!" }, { "input": "pezu", "output": "CHAT WITH HER!" }, { "input": "wnemlgppy", "output": "CHAT WITH HER!" }, { "input": "zcinitufxoldnokacdvtmdohsfdjepyfioyvclhmujiqwvmudbfjzxjfqqxjmoiyxrfsbvseawwoyynn", "output": "IGNORE HIM!" }, { "input": "qsxxuoynwtebujwpxwpajitiwxaxwgbcylxneqiebzfphugwkftpaikixmumkhfbjiswmvzbtiyifbx", "output": "CHAT WITH HER!" }, { "input": "qwbdfzfylckctudyjlyrtmvbidfatdoqfmrfshsqqmhzohhsczscvwzpwyoyswhktjlykumhvaounpzwpxcspxwlgt", "output": "IGNORE HIM!" }, { "input": "nuezoadauueermoeaabjrkxttkatspjsjegjcjcdmcxgodowzbwuqncfbeqlhkk", "output": "IGNORE HIM!" }, { "input": "lggvdmulrsvtuagoavstuyufhypdxfomjlzpnduulukszqnnwfvxbvxyzmleocmofwclmzz", "output": "IGNORE HIM!" }, { "input": "tgcdptnkc", "output": "IGNORE HIM!" }, { "input": "wvfgnfrzabgibzxhzsojskmnlmrokydjoexnvi", "output": "IGNORE HIM!" }, { "input": "sxtburpzskucowowebgrbovhadrrayamuwypmmxhscrujkmcgvyinp", "output": "IGNORE HIM!" }, { "input": "pjqxhvxkyeqqvyuujxhmbspatvrckhhkfloottuybjivkkhpyivcighxumavrxzxslfpggnwbtalmhysyfllznphzia", "output": "IGNORE HIM!" }, { "input": "fpellxwskyekoyvrfnuf", "output": "CHAT WITH HER!" }, { "input": "xninyvkuvakfbs", "output": "IGNORE HIM!" }, { "input": "vnxhrweyvhqufpfywdwftoyrfgrhxuamqhblkvdpxmgvphcbeeqbqssresjifwyzgfhurmamhkwupymuomak", "output": "CHAT WITH HER!" }, { "input": "kmsk", "output": "IGNORE HIM!" }, { "input": "lqonogasrkzhryjxppjyriyfxmdfubieglthyswz", "output": "CHAT WITH HER!" }, { "input": "ndormkufcrkxlihdhmcehzoimcfhqsmombnfjrlcalffq", "output": "CHAT WITH HER!" }, { "input": "zqzlnnuwcfufwujygtczfakhcpqbtxtejrbgoodychepzdphdahtxyfpmlrycyicqthsgm", "output": "IGNORE HIM!" }, { "input": "ppcpbnhwoizajrl", "output": "IGNORE HIM!" }, { "input": "sgubujztzwkzvztitssxxxwzanfmddfqvv", "output": "CHAT WITH HER!" }, { "input": "ptkyaxycecpbrjnvxcjtbqiocqcswnmicxbvhdsptbxyxswbw", "output": "IGNORE HIM!" }, { "input": "yhbtzfppwcycxqjpqdfmjnhwaogyuaxamwxpnrdrnqsgdyfvxu", "output": "CHAT WITH HER!" }, { "input": "ojjvpnkrxibyevxk", "output": "CHAT WITH HER!" }, { "input": "wjweqcrqfuollfvfbiyriijovweg", "output": "IGNORE HIM!" }, { "input": "hkdbykboclchfdsuovvpknwqr", "output": "IGNORE HIM!" }, { "input": "stjvyfrfowopwfjdveduedqylerqugykyu", "output": "IGNORE HIM!" }, { "input": "rafcaanqytfclvfdegak", "output": "CHAT WITH HER!" }, { "input": "xczn", "output": "CHAT WITH HER!" }, { "input": "arcoaeozyeawbveoxpmafxxzdjldsielp", "output": "IGNORE HIM!" }, { "input": "smdfafbyehdylhaleevhoggiurdgeleaxkeqdixyfztkuqsculgslheqfafxyghyuibdgiuwrdxfcitojxika", "output": "CHAT WITH HER!" }, { "input": "vbpfgjqnhfazmvtkpjrdasfhsuxnpiepxfrzvoh", "output": "CHAT WITH HER!" }, { "input": "dbdokywnpqnotfrhdbrzmuyoxfdtrgrzcccninbtmoqvxfatcqg", "output": "CHAT WITH HER!" }, { "input": "udlpagtpq", "output": "CHAT WITH HER!" }, { "input": "zjurevbytijifnpfuyswfchdzelxheboruwjqijxcucylysmwtiqsqqhktexcynquvcwhbjsipy", "output": "CHAT WITH HER!" }, { "input": "qagzrqjomdwhagkhrjahhxkieijyten", "output": "CHAT WITH HER!" }, { "input": "achhcfjnnfwgoufxamcqrsontgjjhgyfzuhklkmiwybnrlsvblnsrjqdytglipxsulpnphpjpoewvlusalsgovwnsngb", "output": "CHAT WITH HER!" }, { "input": "qbkjsdwpahdbbohggbclfcufqelnojoehsxxkr", "output": "CHAT WITH HER!" }, { "input": "cpvftiwgyvnlmbkadiafddpgfpvhqqvuehkypqjsoibpiudfvpkhzlfrykc", "output": "IGNORE HIM!" }, { "input": "lnpdosnceumubvk", "output": "IGNORE HIM!" }, { "input": "efrk", "output": "CHAT WITH HER!" }, { "input": "temnownneghnrujforif", "output": "IGNORE HIM!" }, { "input": "ottnneymszwbumgobazfjyxewkjakglbfflsajuzescplpcxqta", "output": "IGNORE HIM!" }, { "input": "eswpaclodzcwhgixhpyzvhdwsgneqidanbzdzszquefh", "output": "IGNORE HIM!" }, { "input": "gwntwbpj", "output": "IGNORE HIM!" }, { "input": "wuqvlbblkddeindiiswsinkfrnkxghhwunzmmvyovpqapdfbolyim", "output": "IGNORE HIM!" }, { "input": "swdqsnzmzmsyvktukaoyqsqzgfmbzhezbfaqeywgwizrwjyzquaahucjchegknqaioliqd", "output": "CHAT WITH HER!" }, { "input": "vlhrpzezawyolhbmvxbwhtjustdbqggexmzxyieihjlelvwjosmkwesfjmramsikhkupzvfgezmrqzudjcalpjacmhykhgfhrjx", "output": "IGNORE HIM!" }, { "input": "lxxwbkrjgnqjwsnflfnsdyxihmlspgivirazsbveztnkuzpaxtygidniflyjheejelnjyjvgkgvdqks", "output": "CHAT WITH HER!" }, { "input": "wpxbxzfhtdecetpljcrvpjjnllosdqirnkzesiqeukbedkayqx", "output": "CHAT WITH HER!" }, { "input": "vmzxgacicvweclaodrunmjnfwtimceetsaoickarqyrkdghcmyjgmtgsqastcktyrjgvjqimdc", "output": "CHAT WITH HER!" }, { "input": "yzlzmesxdttfcztooypjztlgxwcr", "output": "IGNORE HIM!" }, { "input": "qpbjwzwgdzmeluheirjrvzrhbmagfsjdgvzgwumjtjzecsfkrfqjasssrhhtgdqqfydlmrktlgfc", "output": "IGNORE HIM!" }, { "input": "aqzftsvezdgouyrirsxpbuvdjupnzvbhguyayeqozfzymfnepvwgblqzvmxxkxcilmsjvcgyqykpoaktjvsxbygfgsalbjoq", "output": "CHAT WITH HER!" }, { "input": "znicjjgijhrbdlnwmtjgtdgziollrfxroabfhadygnomodaembllreorlyhnehijfyjbfxucazellblegyfrzuraogadj", "output": "IGNORE HIM!" }, { "input": "qordzrdiknsympdrkgapjxokbldorpnmnpucmwakklmqenpmkom", "output": "CHAT WITH HER!" }, { "input": "wqfldgihuxfktzanyycluzhtewmwvnawqlfoavuguhygqrrxtstxwouuzzsryjqtfqo", "output": "CHAT WITH HER!" }, { "input": "vujtrrpshinkskgyknlcfckmqdrwtklkzlyipmetjvaqxdsslkskschbalmdhzsdrrjmxdltbtnxbh", "output": "IGNORE HIM!" }, { "input": "zioixjibuhrzyrbzqcdjbbhhdmpgmqykixcxoqupggaqajuzonrpzihbsogjfsrrypbiphehonyhohsbybnnukqebopppa", "output": "CHAT WITH HER!" }, { "input": "oh", "output": "CHAT WITH HER!" }, { "input": "kxqthadqesbpgpsvpbcbznxpecqrzjoilpauttzlnxvaczcqwuri", "output": "IGNORE HIM!" }, { "input": "zwlunigqnhrwirkvufqwrnwcnkqqonebrwzcshcbqqwkjxhymjjeakuzjettebciadjlkbfp", "output": "CHAT WITH HER!" }, { "input": "fjuldpuejgmggvvigkwdyzytfxzwdlofrpifqpdnhfyroginqaufwgjcbgshyyruwhofctsdaisqpjxqjmtpp", "output": "CHAT WITH HER!" }, { "input": "xiwntnheuitbtqxrmzvxmieldudakogealwrpygbxsbluhsqhtwmdlpjwzyafckrqrdduonkgo", "output": "CHAT WITH HER!" }, { "input": "mnmbupgo", "output": "IGNORE HIM!" }, { "input": "mcjehdiygkbmrbfjqwpwxidbdfelifwhstaxdapigbymmsgrhnzsdjhsqchl", "output": "IGNORE HIM!" }, { "input": "yocxrzspinchmhtmqo", "output": "CHAT WITH HER!" }, { "input": "vasvvnpymtgjirnzuynluluvmgpquskuaafwogeztfnvybblajvuuvfomtifeuzpikjrolzeeoftv", "output": "CHAT WITH HER!" }, { "input": "ecsdicrznvglwggrdbrvehwzaenzjutjydhvimtqegweurpxtjkmpcznshtrvotkvrghxhacjkedidqqzrduzad", "output": "IGNORE HIM!" }, { "input": "ubvhyaebyxoghakajqrpqpctwbrfqzli", "output": "CHAT WITH HER!" }, { "input": "gogbxfeqylxoummvgxpkoqzsmobasesxbqjjktqbwqxeiaagnnhbvepbpy", "output": "IGNORE HIM!" }, { "input": "nheihhxkbbrmlpxpxbhnpofcjmxemyvqqdbanwd", "output": "IGNORE HIM!" }, { "input": "acrzbavz", "output": "CHAT WITH HER!" }, { "input": "drvzznznvrzskftnrhvvzxcalwutxmdza", "output": "IGNORE HIM!" }, { "input": "oacwxipdfcoabhkwxqdbtowiekpnflnqhlrkustgzryvws", "output": "CHAT WITH HER!" }, { "input": "tpnwfmfsibnccvdwjvzviyvjfljupinfigfunyff", "output": "CHAT WITH HER!" }, { "input": "gavaihhamfolcndgytcsgucqdqngxkrlovpthvteacmmthoglxu", "output": "CHAT WITH HER!" }, { "input": "hsfcfvameeupldgvchmogrvwxrvsmnwxxkxoawwodtsahqvehlcw", "output": "IGNORE HIM!" }, { "input": "sbkydrscoojychxchqsuciperfroumenelgiyiwlqfwximrgdbyvkmacy", "output": "CHAT WITH HER!" }, { "input": "rhh", "output": "CHAT WITH HER!" }, { "input": "zhdouqfmlkenjzdijxdfxnlegxeuvhelo", "output": "IGNORE HIM!" }, { "input": "yufkkfwyhhvcjntsgsvpzbhqtmtgyxifqoewmuplphykmptfdebjxuaxigomjtwgtljwdjhjernkitifbomifbhysnmadtnyn", "output": "CHAT WITH HER!" }, { "input": "urigreuzpxnej", "output": "CHAT WITH HER!" } ]
1,695,121,540
2,147,483,647
Python 3
OK
TESTS
85
92
0
d=dict() n=input() for ch in n: if(ch in d): d[ch]=d[ch]+1 else: d[ch]=0 count=len(d) if(count%2==0): print("CHAT WITH HER!") else: print("IGNORE HIM!")
Title: Boy or Girl Time Limit: None seconds Memory Limit: None megabytes Problem Description: Those days, many boys use beautiful girls' photos as avatars in forums. So it is pretty hard to tell the gender of a user at the first glance. Last year, our hero went to a forum and had a nice chat with a beauty (he thought so). After that they talked very often and eventually they became a couple in the network. But yesterday, he came to see "her" in the real world and found out "she" is actually a very strong man! Our hero is very sad and he is too tired to love again now. So he came up with a way to recognize users' genders by their user names. This is his method: if the number of distinct characters in one's user name is odd, then he is a male, otherwise she is a female. You are given the string that denotes the user name, please help our hero to determine the gender of this user by his method. Input Specification: The first line contains a non-empty string, that contains only lowercase English letters — the user name. This string contains at most 100 letters. Output Specification: If it is a female by our hero's method, print "CHAT WITH HER!" (without the quotes), otherwise, print "IGNORE HIM!" (without the quotes). Demo Input: ['wjmzbmr\n', 'xiaodao\n', 'sevenkplus\n'] Demo Output: ['CHAT WITH HER!\n', 'IGNORE HIM!\n', 'CHAT WITH HER!\n'] Note: For the first example. There are 6 distinct characters in "wjmzbmr". These characters are: "w", "j", "m", "z", "b", "r". So wjmzbmr is a female and you should print "CHAT WITH HER!".
```python d=dict() n=input() for ch in n: if(ch in d): d[ch]=d[ch]+1 else: d[ch]=0 count=len(d) if(count%2==0): print("CHAT WITH HER!") else: print("IGNORE HIM!") ```
3
151
A
Soft Drinking
PROGRAMMING
800
[ "implementation", "math" ]
null
null
This winter is so cold in Nvodsk! A group of *n* friends decided to buy *k* bottles of a soft drink called "Take-It-Light" to warm up a bit. Each bottle has *l* milliliters of the drink. Also they bought *c* limes and cut each of them into *d* slices. After that they found *p* grams of salt. To make a toast, each friend needs *nl* milliliters of the drink, a slice of lime and *np* grams of salt. The friends want to make as many toasts as they can, provided they all drink the same amount. How many toasts can each friend make?
The first and only line contains positive integers *n*, *k*, *l*, *c*, *d*, *p*, *nl*, *np*, not exceeding 1000 and no less than 1. The numbers are separated by exactly one space.
Print a single integer — the number of toasts each friend can make.
[ "3 4 5 10 8 100 3 1\n", "5 100 10 1 19 90 4 3\n", "10 1000 1000 25 23 1 50 1\n" ]
[ "2\n", "3\n", "0\n" ]
A comment to the first sample: Overall the friends have 4 * 5 = 20 milliliters of the drink, it is enough to make 20 / 3 = 6 toasts. The limes are enough for 10 * 8 = 80 toasts and the salt is enough for 100 / 1 = 100 toasts. However, there are 3 friends in the group, so the answer is *min*(6, 80, 100) / 3 = 2.
500
[ { "input": "3 4 5 10 8 100 3 1", "output": "2" }, { "input": "5 100 10 1 19 90 4 3", "output": "3" }, { "input": "10 1000 1000 25 23 1 50 1", "output": "0" }, { "input": "1 7 4 5 5 8 3 2", "output": "4" }, { "input": "2 3 3 5 5 10 1 3", "output": "1" }, { "input": "2 6 4 5 6 5 1 3", "output": "0" }, { "input": "1 7 3 5 3 6 2 1", "output": "6" }, { "input": "2 4 5 4 5 7 3 2", "output": "1" }, { "input": "2 3 6 5 7 8 2 1", "output": "4" }, { "input": "1 4 5 5 3 10 3 1", "output": "6" }, { "input": "1 4 6 7 3 5 1 3", "output": "1" }, { "input": "1 6 5 5 5 8 3 1", "output": "8" }, { "input": "1 7 5 3 3 9 2 1", "output": "9" }, { "input": "3 5 3 7 6 10 3 1", "output": "1" }, { "input": "3 6 3 5 3 6 3 1", "output": "2" }, { "input": "1 7 5 5 5 5 2 2", "output": "2" }, { "input": "2 5 3 5 6 9 2 1", "output": "3" }, { "input": "3 4 3 5 3 6 2 1", "output": "2" }, { "input": "1 5 5 4 7 6 3 1", "output": "6" }, { "input": "2 3 7 6 5 9 3 1", "output": "3" }, { "input": "2 6 5 3 3 8 1 1", "output": "4" }, { "input": "2 4 7 3 4 10 2 1", "output": "5" }, { "input": "1 1000 1000 1000 1000 1000 1 1", "output": "1000" }, { "input": "17 1000 1000 1000 1000 1000 3 7", "output": "8" }, { "input": "115 1000 1000 1000 1000 1000 17 15", "output": "0" }, { "input": "1 587 981 1 2 1 1 1", "output": "1" }, { "input": "1 1 2 1 2 2 1 1", "output": "2" } ]
1,679,924,829
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
9
92
0
def softDrinking(n,k,l,c,d,p,nl,np): first = (k*l)//n second = c*d third = p//np ans = min(first,second,third)//n return ans if __name__ == "__main__": n,k,l,c,d,p,nl,np = tuple([eval(i) for i in input().split()]) ans = softDrinking(n,k,l,c,d,p,nl,np) print(ans)
Title: Soft Drinking Time Limit: None seconds Memory Limit: None megabytes Problem Description: This winter is so cold in Nvodsk! A group of *n* friends decided to buy *k* bottles of a soft drink called "Take-It-Light" to warm up a bit. Each bottle has *l* milliliters of the drink. Also they bought *c* limes and cut each of them into *d* slices. After that they found *p* grams of salt. To make a toast, each friend needs *nl* milliliters of the drink, a slice of lime and *np* grams of salt. The friends want to make as many toasts as they can, provided they all drink the same amount. How many toasts can each friend make? Input Specification: The first and only line contains positive integers *n*, *k*, *l*, *c*, *d*, *p*, *nl*, *np*, not exceeding 1000 and no less than 1. The numbers are separated by exactly one space. Output Specification: Print a single integer — the number of toasts each friend can make. Demo Input: ['3 4 5 10 8 100 3 1\n', '5 100 10 1 19 90 4 3\n', '10 1000 1000 25 23 1 50 1\n'] Demo Output: ['2\n', '3\n', '0\n'] Note: A comment to the first sample: Overall the friends have 4 * 5 = 20 milliliters of the drink, it is enough to make 20 / 3 = 6 toasts. The limes are enough for 10 * 8 = 80 toasts and the salt is enough for 100 / 1 = 100 toasts. However, there are 3 friends in the group, so the answer is *min*(6, 80, 100) / 3 = 2.
```python def softDrinking(n,k,l,c,d,p,nl,np): first = (k*l)//n second = c*d third = p//np ans = min(first,second,third)//n return ans if __name__ == "__main__": n,k,l,c,d,p,nl,np = tuple([eval(i) for i in input().split()]) ans = softDrinking(n,k,l,c,d,p,nl,np) print(ans) ```
0
578
B
"Or" Game
PROGRAMMING
1,700
[ "brute force", "greedy" ]
null
null
You are given *n* numbers *a*1,<=*a*2,<=...,<=*a**n*. You can perform at most *k* operations. For each operation you can multiply one of the numbers by *x*. We want to make as large as possible, where denotes the bitwise OR. Find the maximum possible value of after performing at most *k* operations optimally.
The first line contains three integers *n*, *k* and *x* (1<=≤<=*n*<=≤<=200<=000, 1<=≤<=*k*<=≤<=10, 2<=≤<=*x*<=≤<=8). The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (0<=≤<=*a**i*<=≤<=109).
Output the maximum value of a bitwise OR of sequence elements after performing operations.
[ "3 1 2\n1 1 1\n", "4 2 3\n1 2 4 8\n" ]
[ "3\n", "79\n" ]
For the first sample, any possible choice of doing one operation will result the same three numbers 1, 1, 2 so the result is <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/1ee73b671ed4bc53f2f96ed1a85fd98388e1712b.png" style="max-width: 100.0%;max-height: 100.0%;"/>. For the second sample if we multiply 8 by 3 two times we'll get 72. In this case the numbers will become 1, 2, 4, 72 so the OR value will be 79 and is the largest possible result.
500
[ { "input": "3 1 2\n1 1 1", "output": "3" }, { "input": "4 2 3\n1 2 4 8", "output": "79" }, { "input": "2 1 2\n12 9", "output": "30" }, { "input": "2 1 2\n12 7", "output": "31" }, { "input": "3 1 3\n3 2 0", "output": "11" }, { "input": "5 10 8\n1000000000 1000000000 1000000000 1000000000 1000000000", "output": "1073741825000000000" }, { "input": "1 2 3\n612635770", "output": "5513721930" }, { "input": "3 2 5\n0 2 3", "output": "75" }, { "input": "2 1 8\n18 17", "output": "154" }, { "input": "5 10 8\n0 0 0 0 0", "output": "0" }, { "input": "1 1 2\n1", "output": "2" }, { "input": "1 1 2\n0", "output": "0" }, { "input": "3 2 6\n724148075 828984987 810015532", "output": "29996605423" }, { "input": "3 1 2\n17 18 4", "output": "54" }, { "input": "3 1 2\n4 17 18", "output": "54" }, { "input": "2 2 2\n60 59", "output": "252" }, { "input": "2 2 2\n9 10", "output": "46" }, { "input": "3 1 2\n10 12 5", "output": "31" }, { "input": "3 1 2\n20 17 8", "output": "62" }, { "input": "3 1 2\n5 12 10", "output": "31" }, { "input": "3 1 8\n10 17 18", "output": "155" }, { "input": "3 1 2\n17 20 28", "output": "62" }, { "input": "5 1 3\n1 5 13 8 16", "output": "63" } ]
1,553,103,428
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
2
93
0
n, k, x = map(int, input().split(" ")) arr = sorted(map(int, input().split(" ")), reverse = True) ans = arr[0]*(x**k) arr = arr[1:] for i in arr: ans |= i print(ans)
Title: "Or" Game Time Limit: None seconds Memory Limit: None megabytes Problem Description: You are given *n* numbers *a*1,<=*a*2,<=...,<=*a**n*. You can perform at most *k* operations. For each operation you can multiply one of the numbers by *x*. We want to make as large as possible, where denotes the bitwise OR. Find the maximum possible value of after performing at most *k* operations optimally. Input Specification: The first line contains three integers *n*, *k* and *x* (1<=≤<=*n*<=≤<=200<=000, 1<=≤<=*k*<=≤<=10, 2<=≤<=*x*<=≤<=8). The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (0<=≤<=*a**i*<=≤<=109). Output Specification: Output the maximum value of a bitwise OR of sequence elements after performing operations. Demo Input: ['3 1 2\n1 1 1\n', '4 2 3\n1 2 4 8\n'] Demo Output: ['3\n', '79\n'] Note: For the first sample, any possible choice of doing one operation will result the same three numbers 1, 1, 2 so the result is <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/1ee73b671ed4bc53f2f96ed1a85fd98388e1712b.png" style="max-width: 100.0%;max-height: 100.0%;"/>. For the second sample if we multiply 8 by 3 two times we'll get 72. In this case the numbers will become 1, 2, 4, 72 so the OR value will be 79 and is the largest possible result.
```python n, k, x = map(int, input().split(" ")) arr = sorted(map(int, input().split(" ")), reverse = True) ans = arr[0]*(x**k) arr = arr[1:] for i in arr: ans |= i print(ans) ```
0
334
A
Candy Bags
PROGRAMMING
1,000
[ "implementation" ]
null
null
Gerald has *n* younger brothers and their number happens to be even. One day he bought *n*2 candy bags. One bag has one candy, one bag has two candies, one bag has three candies and so on. In fact, for each integer *k* from 1 to *n*2 he has exactly one bag with *k* candies. Help him give *n* bags of candies to each brother so that all brothers got the same number of candies.
The single line contains a single integer *n* (*n* is even, 2<=≤<=*n*<=≤<=100) — the number of Gerald's brothers.
Let's assume that Gerald indexes his brothers with numbers from 1 to *n*. You need to print *n* lines, on the *i*-th line print *n* integers — the numbers of candies in the bags for the *i*-th brother. Naturally, all these numbers should be distinct and be within limits from 1 to *n*2. You can print the numbers in the lines in any order. It is guaranteed that the solution exists at the given limits.
[ "2\n" ]
[ "1 4\n2 3\n" ]
The sample shows Gerald's actions if he has two brothers. In this case, his bags contain 1, 2, 3 and 4 candies. He can give the bags with 1 and 4 candies to one brother and the bags with 2 and 3 to the other brother.
500
[ { "input": "2", "output": "1 4\n2 3" }, { "input": "4", "output": "1 16 2 15\n3 14 4 13\n5 12 6 11\n7 10 8 9" }, { "input": "6", "output": "1 36 2 35 3 34\n4 33 5 32 6 31\n7 30 8 29 9 28\n10 27 11 26 12 25\n13 24 14 23 15 22\n16 21 17 20 18 19" }, { "input": "8", "output": "1 64 2 63 3 62 4 61\n5 60 6 59 7 58 8 57\n9 56 10 55 11 54 12 53\n13 52 14 51 15 50 16 49\n17 48 18 47 19 46 20 45\n21 44 22 43 23 42 24 41\n25 40 26 39 27 38 28 37\n29 36 30 35 31 34 32 33" }, { "input": "10", "output": "1 100 2 99 3 98 4 97 5 96\n6 95 7 94 8 93 9 92 10 91\n11 90 12 89 13 88 14 87 15 86\n16 85 17 84 18 83 19 82 20 81\n21 80 22 79 23 78 24 77 25 76\n26 75 27 74 28 73 29 72 30 71\n31 70 32 69 33 68 34 67 35 66\n36 65 37 64 38 63 39 62 40 61\n41 60 42 59 43 58 44 57 45 56\n46 55 47 54 48 53 49 52 50 51" }, { "input": "100", "output": "1 10000 2 9999 3 9998 4 9997 5 9996 6 9995 7 9994 8 9993 9 9992 10 9991 11 9990 12 9989 13 9988 14 9987 15 9986 16 9985 17 9984 18 9983 19 9982 20 9981 21 9980 22 9979 23 9978 24 9977 25 9976 26 9975 27 9974 28 9973 29 9972 30 9971 31 9970 32 9969 33 9968 34 9967 35 9966 36 9965 37 9964 38 9963 39 9962 40 9961 41 9960 42 9959 43 9958 44 9957 45 9956 46 9955 47 9954 48 9953 49 9952 50 9951\n51 9950 52 9949 53 9948 54 9947 55 9946 56 9945 57 9944 58 9943 59 9942 60 9941 61 9940 62 9939 63 9938 64 9937 65 993..." }, { "input": "62", "output": "1 3844 2 3843 3 3842 4 3841 5 3840 6 3839 7 3838 8 3837 9 3836 10 3835 11 3834 12 3833 13 3832 14 3831 15 3830 16 3829 17 3828 18 3827 19 3826 20 3825 21 3824 22 3823 23 3822 24 3821 25 3820 26 3819 27 3818 28 3817 29 3816 30 3815 31 3814\n32 3813 33 3812 34 3811 35 3810 36 3809 37 3808 38 3807 39 3806 40 3805 41 3804 42 3803 43 3802 44 3801 45 3800 46 3799 47 3798 48 3797 49 3796 50 3795 51 3794 52 3793 53 3792 54 3791 55 3790 56 3789 57 3788 58 3787 59 3786 60 3785 61 3784 62 3783\n63 3782 64 3781 65 378..." }, { "input": "66", "output": "1 4356 2 4355 3 4354 4 4353 5 4352 6 4351 7 4350 8 4349 9 4348 10 4347 11 4346 12 4345 13 4344 14 4343 15 4342 16 4341 17 4340 18 4339 19 4338 20 4337 21 4336 22 4335 23 4334 24 4333 25 4332 26 4331 27 4330 28 4329 29 4328 30 4327 31 4326 32 4325 33 4324\n34 4323 35 4322 36 4321 37 4320 38 4319 39 4318 40 4317 41 4316 42 4315 43 4314 44 4313 45 4312 46 4311 47 4310 48 4309 49 4308 50 4307 51 4306 52 4305 53 4304 54 4303 55 4302 56 4301 57 4300 58 4299 59 4298 60 4297 61 4296 62 4295 63 4294 64 4293 65 4292..." }, { "input": "18", "output": "1 324 2 323 3 322 4 321 5 320 6 319 7 318 8 317 9 316\n10 315 11 314 12 313 13 312 14 311 15 310 16 309 17 308 18 307\n19 306 20 305 21 304 22 303 23 302 24 301 25 300 26 299 27 298\n28 297 29 296 30 295 31 294 32 293 33 292 34 291 35 290 36 289\n37 288 38 287 39 286 40 285 41 284 42 283 43 282 44 281 45 280\n46 279 47 278 48 277 49 276 50 275 51 274 52 273 53 272 54 271\n55 270 56 269 57 268 58 267 59 266 60 265 61 264 62 263 63 262\n64 261 65 260 66 259 67 258 68 257 69 256 70 255 71 254 72 253\n73 252 7..." }, { "input": "68", "output": "1 4624 2 4623 3 4622 4 4621 5 4620 6 4619 7 4618 8 4617 9 4616 10 4615 11 4614 12 4613 13 4612 14 4611 15 4610 16 4609 17 4608 18 4607 19 4606 20 4605 21 4604 22 4603 23 4602 24 4601 25 4600 26 4599 27 4598 28 4597 29 4596 30 4595 31 4594 32 4593 33 4592 34 4591\n35 4590 36 4589 37 4588 38 4587 39 4586 40 4585 41 4584 42 4583 43 4582 44 4581 45 4580 46 4579 47 4578 48 4577 49 4576 50 4575 51 4574 52 4573 53 4572 54 4571 55 4570 56 4569 57 4568 58 4567 59 4566 60 4565 61 4564 62 4563 63 4562 64 4561 65 4560..." }, { "input": "86", "output": "1 7396 2 7395 3 7394 4 7393 5 7392 6 7391 7 7390 8 7389 9 7388 10 7387 11 7386 12 7385 13 7384 14 7383 15 7382 16 7381 17 7380 18 7379 19 7378 20 7377 21 7376 22 7375 23 7374 24 7373 25 7372 26 7371 27 7370 28 7369 29 7368 30 7367 31 7366 32 7365 33 7364 34 7363 35 7362 36 7361 37 7360 38 7359 39 7358 40 7357 41 7356 42 7355 43 7354\n44 7353 45 7352 46 7351 47 7350 48 7349 49 7348 50 7347 51 7346 52 7345 53 7344 54 7343 55 7342 56 7341 57 7340 58 7339 59 7338 60 7337 61 7336 62 7335 63 7334 64 7333 65 7332..." }, { "input": "96", "output": "1 9216 2 9215 3 9214 4 9213 5 9212 6 9211 7 9210 8 9209 9 9208 10 9207 11 9206 12 9205 13 9204 14 9203 15 9202 16 9201 17 9200 18 9199 19 9198 20 9197 21 9196 22 9195 23 9194 24 9193 25 9192 26 9191 27 9190 28 9189 29 9188 30 9187 31 9186 32 9185 33 9184 34 9183 35 9182 36 9181 37 9180 38 9179 39 9178 40 9177 41 9176 42 9175 43 9174 44 9173 45 9172 46 9171 47 9170 48 9169\n49 9168 50 9167 51 9166 52 9165 53 9164 54 9163 55 9162 56 9161 57 9160 58 9159 59 9158 60 9157 61 9156 62 9155 63 9154 64 9153 65 9152..." }, { "input": "12", "output": "1 144 2 143 3 142 4 141 5 140 6 139\n7 138 8 137 9 136 10 135 11 134 12 133\n13 132 14 131 15 130 16 129 17 128 18 127\n19 126 20 125 21 124 22 123 23 122 24 121\n25 120 26 119 27 118 28 117 29 116 30 115\n31 114 32 113 33 112 34 111 35 110 36 109\n37 108 38 107 39 106 40 105 41 104 42 103\n43 102 44 101 45 100 46 99 47 98 48 97\n49 96 50 95 51 94 52 93 53 92 54 91\n55 90 56 89 57 88 58 87 59 86 60 85\n61 84 62 83 63 82 64 81 65 80 66 79\n67 78 68 77 69 76 70 75 71 74 72 73" }, { "input": "88", "output": "1 7744 2 7743 3 7742 4 7741 5 7740 6 7739 7 7738 8 7737 9 7736 10 7735 11 7734 12 7733 13 7732 14 7731 15 7730 16 7729 17 7728 18 7727 19 7726 20 7725 21 7724 22 7723 23 7722 24 7721 25 7720 26 7719 27 7718 28 7717 29 7716 30 7715 31 7714 32 7713 33 7712 34 7711 35 7710 36 7709 37 7708 38 7707 39 7706 40 7705 41 7704 42 7703 43 7702 44 7701\n45 7700 46 7699 47 7698 48 7697 49 7696 50 7695 51 7694 52 7693 53 7692 54 7691 55 7690 56 7689 57 7688 58 7687 59 7686 60 7685 61 7684 62 7683 63 7682 64 7681 65 7680..." }, { "input": "28", "output": "1 784 2 783 3 782 4 781 5 780 6 779 7 778 8 777 9 776 10 775 11 774 12 773 13 772 14 771\n15 770 16 769 17 768 18 767 19 766 20 765 21 764 22 763 23 762 24 761 25 760 26 759 27 758 28 757\n29 756 30 755 31 754 32 753 33 752 34 751 35 750 36 749 37 748 38 747 39 746 40 745 41 744 42 743\n43 742 44 741 45 740 46 739 47 738 48 737 49 736 50 735 51 734 52 733 53 732 54 731 55 730 56 729\n57 728 58 727 59 726 60 725 61 724 62 723 63 722 64 721 65 720 66 719 67 718 68 717 69 716 70 715\n71 714 72 713 73 712 74 7..." }, { "input": "80", "output": "1 6400 2 6399 3 6398 4 6397 5 6396 6 6395 7 6394 8 6393 9 6392 10 6391 11 6390 12 6389 13 6388 14 6387 15 6386 16 6385 17 6384 18 6383 19 6382 20 6381 21 6380 22 6379 23 6378 24 6377 25 6376 26 6375 27 6374 28 6373 29 6372 30 6371 31 6370 32 6369 33 6368 34 6367 35 6366 36 6365 37 6364 38 6363 39 6362 40 6361\n41 6360 42 6359 43 6358 44 6357 45 6356 46 6355 47 6354 48 6353 49 6352 50 6351 51 6350 52 6349 53 6348 54 6347 55 6346 56 6345 57 6344 58 6343 59 6342 60 6341 61 6340 62 6339 63 6338 64 6337 65 6336..." }, { "input": "48", "output": "1 2304 2 2303 3 2302 4 2301 5 2300 6 2299 7 2298 8 2297 9 2296 10 2295 11 2294 12 2293 13 2292 14 2291 15 2290 16 2289 17 2288 18 2287 19 2286 20 2285 21 2284 22 2283 23 2282 24 2281\n25 2280 26 2279 27 2278 28 2277 29 2276 30 2275 31 2274 32 2273 33 2272 34 2271 35 2270 36 2269 37 2268 38 2267 39 2266 40 2265 41 2264 42 2263 43 2262 44 2261 45 2260 46 2259 47 2258 48 2257\n49 2256 50 2255 51 2254 52 2253 53 2252 54 2251 55 2250 56 2249 57 2248 58 2247 59 2246 60 2245 61 2244 62 2243 63 2242 64 2241 65 224..." }, { "input": "54", "output": "1 2916 2 2915 3 2914 4 2913 5 2912 6 2911 7 2910 8 2909 9 2908 10 2907 11 2906 12 2905 13 2904 14 2903 15 2902 16 2901 17 2900 18 2899 19 2898 20 2897 21 2896 22 2895 23 2894 24 2893 25 2892 26 2891 27 2890\n28 2889 29 2888 30 2887 31 2886 32 2885 33 2884 34 2883 35 2882 36 2881 37 2880 38 2879 39 2878 40 2877 41 2876 42 2875 43 2874 44 2873 45 2872 46 2871 47 2870 48 2869 49 2868 50 2867 51 2866 52 2865 53 2864 54 2863\n55 2862 56 2861 57 2860 58 2859 59 2858 60 2857 61 2856 62 2855 63 2854 64 2853 65 285..." }, { "input": "58", "output": "1 3364 2 3363 3 3362 4 3361 5 3360 6 3359 7 3358 8 3357 9 3356 10 3355 11 3354 12 3353 13 3352 14 3351 15 3350 16 3349 17 3348 18 3347 19 3346 20 3345 21 3344 22 3343 23 3342 24 3341 25 3340 26 3339 27 3338 28 3337 29 3336\n30 3335 31 3334 32 3333 33 3332 34 3331 35 3330 36 3329 37 3328 38 3327 39 3326 40 3325 41 3324 42 3323 43 3322 44 3321 45 3320 46 3319 47 3318 48 3317 49 3316 50 3315 51 3314 52 3313 53 3312 54 3311 55 3310 56 3309 57 3308 58 3307\n59 3306 60 3305 61 3304 62 3303 63 3302 64 3301 65 330..." }, { "input": "64", "output": "1 4096 2 4095 3 4094 4 4093 5 4092 6 4091 7 4090 8 4089 9 4088 10 4087 11 4086 12 4085 13 4084 14 4083 15 4082 16 4081 17 4080 18 4079 19 4078 20 4077 21 4076 22 4075 23 4074 24 4073 25 4072 26 4071 27 4070 28 4069 29 4068 30 4067 31 4066 32 4065\n33 4064 34 4063 35 4062 36 4061 37 4060 38 4059 39 4058 40 4057 41 4056 42 4055 43 4054 44 4053 45 4052 46 4051 47 4050 48 4049 49 4048 50 4047 51 4046 52 4045 53 4044 54 4043 55 4042 56 4041 57 4040 58 4039 59 4038 60 4037 61 4036 62 4035 63 4034 64 4033\n65 403..." }, { "input": "44", "output": "1 1936 2 1935 3 1934 4 1933 5 1932 6 1931 7 1930 8 1929 9 1928 10 1927 11 1926 12 1925 13 1924 14 1923 15 1922 16 1921 17 1920 18 1919 19 1918 20 1917 21 1916 22 1915\n23 1914 24 1913 25 1912 26 1911 27 1910 28 1909 29 1908 30 1907 31 1906 32 1905 33 1904 34 1903 35 1902 36 1901 37 1900 38 1899 39 1898 40 1897 41 1896 42 1895 43 1894 44 1893\n45 1892 46 1891 47 1890 48 1889 49 1888 50 1887 51 1886 52 1885 53 1884 54 1883 55 1882 56 1881 57 1880 58 1879 59 1878 60 1877 61 1876 62 1875 63 1874 64 1873 65 187..." } ]
1,594,101,674
2,147,483,647
Python 3
OK
TESTS
21
218
6,963,200
n=int(input()) n=n**2 for i in range (0,n//2): print(i+1,n-i)
Title: Candy Bags Time Limit: None seconds Memory Limit: None megabytes Problem Description: Gerald has *n* younger brothers and their number happens to be even. One day he bought *n*2 candy bags. One bag has one candy, one bag has two candies, one bag has three candies and so on. In fact, for each integer *k* from 1 to *n*2 he has exactly one bag with *k* candies. Help him give *n* bags of candies to each brother so that all brothers got the same number of candies. Input Specification: The single line contains a single integer *n* (*n* is even, 2<=≤<=*n*<=≤<=100) — the number of Gerald's brothers. Output Specification: Let's assume that Gerald indexes his brothers with numbers from 1 to *n*. You need to print *n* lines, on the *i*-th line print *n* integers — the numbers of candies in the bags for the *i*-th brother. Naturally, all these numbers should be distinct and be within limits from 1 to *n*2. You can print the numbers in the lines in any order. It is guaranteed that the solution exists at the given limits. Demo Input: ['2\n'] Demo Output: ['1 4\n2 3\n'] Note: The sample shows Gerald's actions if he has two brothers. In this case, his bags contain 1, 2, 3 and 4 candies. He can give the bags with 1 and 4 candies to one brother and the bags with 2 and 3 to the other brother.
```python n=int(input()) n=n**2 for i in range (0,n//2): print(i+1,n-i) ```
3
818
A
Diplomas and Certificates
PROGRAMMING
800
[ "implementation", "math" ]
null
null
There are *n* students who have taken part in an olympiad. Now it's time to award the students. Some of them will receive diplomas, some wiil get certificates, and others won't receive anything. Students with diplomas and certificates are called winners. But there are some rules of counting the number of diplomas and certificates. The number of certificates must be exactly *k* times greater than the number of diplomas. The number of winners must not be greater than half of the number of all students (i.e. not be greater than half of *n*). It's possible that there are no winners. You have to identify the maximum possible number of winners, according to these rules. Also for this case you have to calculate the number of students with diplomas, the number of students with certificates and the number of students who are not winners.
The first (and the only) line of input contains two integers *n* and *k* (1<=≤<=*n*,<=*k*<=≤<=1012), where *n* is the number of students and *k* is the ratio between the number of certificates and the number of diplomas.
Output three numbers: the number of students with diplomas, the number of students with certificates and the number of students who are not winners in case when the number of winners is maximum possible. It's possible that there are no winners.
[ "18 2\n", "9 10\n", "1000000000000 5\n", "1000000000000 499999999999\n" ]
[ "3 6 9\n", "0 0 9\n", "83333333333 416666666665 500000000002\n", "1 499999999999 500000000000\n" ]
none
0
[ { "input": "18 2", "output": "3 6 9" }, { "input": "9 10", "output": "0 0 9" }, { "input": "1000000000000 5", "output": "83333333333 416666666665 500000000002" }, { "input": "1000000000000 499999999999", "output": "1 499999999999 500000000000" }, { "input": "1 1", "output": "0 0 1" }, { "input": "5 3", "output": "0 0 5" }, { "input": "42 6", "output": "3 18 21" }, { "input": "1000000000000 1000", "output": "499500499 499500499000 500000000501" }, { "input": "999999999999 999999", "output": "499999 499998500001 500000999999" }, { "input": "732577309725 132613", "output": "2762066 366285858458 366288689201" }, { "input": "152326362626 15", "output": "4760198832 71402982480 76163181314" }, { "input": "2 1", "output": "0 0 2" }, { "input": "1000000000000 500000000000", "output": "0 0 1000000000000" }, { "input": "100000000000 50000000011", "output": "0 0 100000000000" }, { "input": "1000000000000 32416187567", "output": "15 486242813505 513757186480" }, { "input": "1000000000000 7777777777", "output": "64 497777777728 502222222208" }, { "input": "1000000000000 77777777777", "output": "6 466666666662 533333333332" }, { "input": "100000000000 578485652", "output": "86 49749766072 50250233842" }, { "input": "999999999999 10000000000", "output": "49 490000000000 509999999950" }, { "input": "7 2", "output": "1 2 4" }, { "input": "420506530901 752346673804", "output": "0 0 420506530901" }, { "input": "960375521135 321688347872", "output": "1 321688347872 638687173262" }, { "input": "1000000000000 1000000000000", "output": "0 0 1000000000000" }, { "input": "99999999999 15253636363", "output": "3 45760909089 54239090907" }, { "input": "19 2", "output": "3 6 10" }, { "input": "999999999999 1000000000000", "output": "0 0 999999999999" }, { "input": "1000000000000 5915587276", "output": "84 496909331184 503090668732" }, { "input": "1000000000000 1000000006", "output": "499 499000002994 500999996507" }, { "input": "549755813888 134217728", "output": "2047 274743689216 275012122625" }, { "input": "99999999999 3333333", "output": "14999 49996661667 50003323333" }, { "input": "9 1", "output": "2 2 5" }, { "input": "1000000000000 250000000001", "output": "1 250000000001 749999999998" }, { "input": "5 1", "output": "1 1 3" }, { "input": "3107038133 596040207", "output": "2 1192080414 1914957717" }, { "input": "1000000000000 73786977", "output": "6776 499980556152 500019437072" }, { "input": "1000000000000 73786976", "output": "6776 499980549376 500019443848" }, { "input": "1000000000000 25000000000", "output": "19 475000000000 524999999981" }, { "input": "216929598879 768233755932", "output": "0 0 216929598879" }, { "input": "1000000000000 250000000000", "output": "1 250000000000 749999999999" }, { "input": "1000000000000 100000000001", "output": "4 400000000004 599999999992" }, { "input": "100000000000 100000000001", "output": "0 0 100000000000" }, { "input": "900000000000 100281800001", "output": "4 401127200004 498872799992" }, { "input": "906028900004 109123020071", "output": "4 436492080284 469536819716" }, { "input": "1000000000000 1", "output": "250000000000 250000000000 500000000000" } ]
1,498,898,029
2,147,483,647
Python 3
OK
TESTS
44
62
5,529,600
[n, k] = [int(i) for i in input().split()] half = n // 2 correction = half % (k + 1) winners = half - correction diplomas = winners // (k + 1) print(diplomas, winners - diplomas, n - winners)
Title: Diplomas and Certificates Time Limit: None seconds Memory Limit: None megabytes Problem Description: There are *n* students who have taken part in an olympiad. Now it's time to award the students. Some of them will receive diplomas, some wiil get certificates, and others won't receive anything. Students with diplomas and certificates are called winners. But there are some rules of counting the number of diplomas and certificates. The number of certificates must be exactly *k* times greater than the number of diplomas. The number of winners must not be greater than half of the number of all students (i.e. not be greater than half of *n*). It's possible that there are no winners. You have to identify the maximum possible number of winners, according to these rules. Also for this case you have to calculate the number of students with diplomas, the number of students with certificates and the number of students who are not winners. Input Specification: The first (and the only) line of input contains two integers *n* and *k* (1<=≤<=*n*,<=*k*<=≤<=1012), where *n* is the number of students and *k* is the ratio between the number of certificates and the number of diplomas. Output Specification: Output three numbers: the number of students with diplomas, the number of students with certificates and the number of students who are not winners in case when the number of winners is maximum possible. It's possible that there are no winners. Demo Input: ['18 2\n', '9 10\n', '1000000000000 5\n', '1000000000000 499999999999\n'] Demo Output: ['3 6 9\n', '0 0 9\n', '83333333333 416666666665 500000000002\n', '1 499999999999 500000000000\n'] Note: none
```python [n, k] = [int(i) for i in input().split()] half = n // 2 correction = half % (k + 1) winners = half - correction diplomas = winners // (k + 1) print(diplomas, winners - diplomas, n - winners) ```
3
920
A
Water The Garden
PROGRAMMING
1,000
[ "implementation" ]
null
null
It is winter now, and Max decided it's about time he watered the garden. The garden can be represented as *n* consecutive garden beds, numbered from 1 to *n*. *k* beds contain water taps (*i*-th tap is located in the bed *x**i*), which, if turned on, start delivering water to neighbouring beds. If the tap on the bed *x**i* is turned on, then after one second has passed, the bed *x**i* will be watered; after two seconds have passed, the beds from the segment [*x**i*<=-<=1,<=*x**i*<=+<=1] will be watered (if they exist); after *j* seconds have passed (*j* is an integer number), the beds from the segment [*x**i*<=-<=(*j*<=-<=1),<=*x**i*<=+<=(*j*<=-<=1)] will be watered (if they exist). Nothing changes during the seconds, so, for example, we can't say that the segment [*x**i*<=-<=2.5,<=*x**i*<=+<=2.5] will be watered after 2.5 seconds have passed; only the segment [*x**i*<=-<=2,<=*x**i*<=+<=2] will be watered at that moment. Max wants to turn on all the water taps at the same moment, and now he wonders, what is the minimum number of seconds that have to pass after he turns on some taps until the whole garden is watered. Help him to find the answer!
The first line contains one integer *t* — the number of test cases to solve (1<=≤<=*t*<=≤<=200). Then *t* test cases follow. The first line of each test case contains two integers *n* and *k* (1<=≤<=*n*<=≤<=200, 1<=≤<=*k*<=≤<=*n*) — the number of garden beds and water taps, respectively. Next line contains *k* integers *x**i* (1<=≤<=*x**i*<=≤<=*n*) — the location of *i*-th water tap. It is guaranteed that for each condition *x**i*<=-<=1<=&lt;<=*x**i* holds. It is guaranteed that the sum of *n* over all test cases doesn't exceed 200. Note that in hacks you have to set *t*<==<=1.
For each test case print one integer — the minimum number of seconds that have to pass after Max turns on some of the water taps, until the whole garden is watered.
[ "3\n5 1\n3\n3 3\n1 2 3\n4 1\n1\n" ]
[ "3\n1\n4\n" ]
The first example consists of 3 tests: 1. There are 5 garden beds, and a water tap in the bed 3. If we turn it on, then after 1 second passes, only bed 3 will be watered; after 2 seconds pass, beds [1, 3] will be watered, and after 3 seconds pass, everything will be watered. 1. There are 3 garden beds, and there is a water tap in each one. If we turn all of them on, then everything will be watered after 1 second passes. 1. There are 4 garden beds, and only one tap in the bed 1. It will take 4 seconds to water, for example, bed 4.
0
[ { "input": "3\n5 1\n3\n3 3\n1 2 3\n4 1\n1", "output": "3\n1\n4" }, { "input": "26\n1 1\n1\n2 1\n2\n2 1\n1\n2 2\n1 2\n3 1\n3\n3 1\n2\n3 2\n2 3\n3 1\n1\n3 2\n1 3\n3 2\n1 2\n3 3\n1 2 3\n4 1\n4\n4 1\n3\n4 2\n3 4\n4 1\n2\n4 2\n2 4\n4 2\n2 3\n4 3\n2 3 4\n4 1\n1\n4 2\n1 4\n4 2\n1 3\n4 3\n1 3 4\n4 2\n1 2\n4 3\n1 2 4\n4 3\n1 2 3\n4 4\n1 2 3 4", "output": "1\n2\n2\n1\n3\n2\n2\n3\n2\n2\n1\n4\n3\n3\n3\n2\n2\n2\n4\n2\n2\n2\n3\n2\n2\n1" }, { "input": "31\n5 1\n5\n5 1\n4\n5 2\n4 5\n5 1\n3\n5 2\n3 5\n5 2\n3 4\n5 3\n3 4 5\n5 1\n2\n5 2\n2 5\n5 2\n2 4\n5 3\n2 4 5\n5 2\n2 3\n5 3\n2 3 5\n5 3\n2 3 4\n5 4\n2 3 4 5\n5 1\n1\n5 2\n1 5\n5 2\n1 4\n5 3\n1 4 5\n5 2\n1 3\n5 3\n1 3 5\n5 3\n1 3 4\n5 4\n1 3 4 5\n5 2\n1 2\n5 3\n1 2 5\n5 3\n1 2 4\n5 4\n1 2 4 5\n5 3\n1 2 3\n5 4\n1 2 3 5\n5 4\n1 2 3 4\n5 5\n1 2 3 4 5", "output": "5\n4\n4\n3\n3\n3\n3\n4\n2\n2\n2\n3\n2\n2\n2\n5\n3\n2\n2\n3\n2\n2\n2\n4\n2\n2\n2\n3\n2\n2\n1" }, { "input": "1\n200 1\n200", "output": "200" }, { "input": "1\n5 1\n5", "output": "5" }, { "input": "1\n177 99\n1 4 7 10 11 13 14 15 16 17 19 21 22 24 25 26 27 28 32 34 35 38 39 40 42 45 46 52 54 55 57 58 59 60 62 64 65 67 70 71 74 77 78 79 80 81 83 84 88 92 93 94 95 100 101 102 104 106 107 108 109 110 112 113 114 115 116 118 122 123 124 125 127 128 129 130 134 135 137 138 139 140 142 146 148 149 154 158 160 161 162 165 166 167 169 171 172 173 176", "output": "4" }, { "input": "1\n69 12\n5 7 10 11 12 18 20 27 28 31 47 67", "output": "11" }, { "input": "1\n74 7\n19 39 40 47 55 57 61", "output": "19" }, { "input": "1\n170 11\n14 18 37 39 80 83 103 112 124 127 131", "output": "40" }, { "input": "1\n200 1\n8", "output": "193" }, { "input": "1\n155 53\n2 3 7 9 10 11 12 20 24 26 28 31 38 39 40 51 53 56 58 63 65 66 69 70 72 74 79 81 83 88 90 92 100 103 104 106 111 113 114 115 116 121 124 126 127 128 133 136 142 143 145 148 150", "output": "6" }, { "input": "1\n161 69\n2 5 8 11 12 13 17 18 23 25 28 29 30 33 34 35 36 38 39 44 45 49 52 53 56 57 58 60 62 70 71 74 76 77 82 83 86 90 94 95 97 104 105 108 109 112 113 118 120 123 126 127 132 135 137 139 140 141 142 143 144 146 147 148 151 152 153 154 161", "output": "5" }, { "input": "1\n8 4\n1 2 3 7", "output": "3" }, { "input": "1\n12 2\n5 12", "output": "5" }, { "input": "1\n13 2\n6 12", "output": "6" }, { "input": "1\n13 2\n8 13", "output": "8" }, { "input": "1\n10 4\n1 2 3 5", "output": "6" }, { "input": "1\n200 2\n50 150", "output": "51" }, { "input": "1\n110 2\n1 110", "output": "55" } ]
1,517,582,766
666
PyPy 3
WRONG_ANSWER
TESTS
1
62
19,968,000
from sys import stdin, stdout t = int(stdin.readline()) for i in range(t): n, k = map(int, stdin.readline().split()) used = [0 for i in range(n + 1)] values = list(map(int, stdin.readline().split())) l, r = 0, n while r - l > 1: m = (l + r) >> 1 for v in values: for i in range(v, min(n + 1, v + m)): used[i] = 1 for i in range(v, max(0, v - m), -1): used[i] = 1 if used[1:].count(1) + 1 == len(used): r = m else: l = m stdout.write(str(r) + '\n')
Title: Water The Garden Time Limit: None seconds Memory Limit: None megabytes Problem Description: It is winter now, and Max decided it's about time he watered the garden. The garden can be represented as *n* consecutive garden beds, numbered from 1 to *n*. *k* beds contain water taps (*i*-th tap is located in the bed *x**i*), which, if turned on, start delivering water to neighbouring beds. If the tap on the bed *x**i* is turned on, then after one second has passed, the bed *x**i* will be watered; after two seconds have passed, the beds from the segment [*x**i*<=-<=1,<=*x**i*<=+<=1] will be watered (if they exist); after *j* seconds have passed (*j* is an integer number), the beds from the segment [*x**i*<=-<=(*j*<=-<=1),<=*x**i*<=+<=(*j*<=-<=1)] will be watered (if they exist). Nothing changes during the seconds, so, for example, we can't say that the segment [*x**i*<=-<=2.5,<=*x**i*<=+<=2.5] will be watered after 2.5 seconds have passed; only the segment [*x**i*<=-<=2,<=*x**i*<=+<=2] will be watered at that moment. Max wants to turn on all the water taps at the same moment, and now he wonders, what is the minimum number of seconds that have to pass after he turns on some taps until the whole garden is watered. Help him to find the answer! Input Specification: The first line contains one integer *t* — the number of test cases to solve (1<=≤<=*t*<=≤<=200). Then *t* test cases follow. The first line of each test case contains two integers *n* and *k* (1<=≤<=*n*<=≤<=200, 1<=≤<=*k*<=≤<=*n*) — the number of garden beds and water taps, respectively. Next line contains *k* integers *x**i* (1<=≤<=*x**i*<=≤<=*n*) — the location of *i*-th water tap. It is guaranteed that for each condition *x**i*<=-<=1<=&lt;<=*x**i* holds. It is guaranteed that the sum of *n* over all test cases doesn't exceed 200. Note that in hacks you have to set *t*<==<=1. Output Specification: For each test case print one integer — the minimum number of seconds that have to pass after Max turns on some of the water taps, until the whole garden is watered. Demo Input: ['3\n5 1\n3\n3 3\n1 2 3\n4 1\n1\n'] Demo Output: ['3\n1\n4\n'] Note: The first example consists of 3 tests: 1. There are 5 garden beds, and a water tap in the bed 3. If we turn it on, then after 1 second passes, only bed 3 will be watered; after 2 seconds pass, beds [1, 3] will be watered, and after 3 seconds pass, everything will be watered. 1. There are 3 garden beds, and there is a water tap in each one. If we turn all of them on, then everything will be watered after 1 second passes. 1. There are 4 garden beds, and only one tap in the bed 1. It will take 4 seconds to water, for example, bed 4.
```python from sys import stdin, stdout t = int(stdin.readline()) for i in range(t): n, k = map(int, stdin.readline().split()) used = [0 for i in range(n + 1)] values = list(map(int, stdin.readline().split())) l, r = 0, n while r - l > 1: m = (l + r) >> 1 for v in values: for i in range(v, min(n + 1, v + m)): used[i] = 1 for i in range(v, max(0, v - m), -1): used[i] = 1 if used[1:].count(1) + 1 == len(used): r = m else: l = m stdout.write(str(r) + '\n') ```
0
488
A
Giga Tower
PROGRAMMING
1,100
[ "brute force" ]
null
null
Giga Tower is the tallest and deepest building in Cyberland. There are 17<=777<=777<=777 floors, numbered from <=-<=8<=888<=888<=888 to 8<=888<=888<=888. In particular, there is floor 0 between floor <=-<=1 and floor 1. Every day, thousands of tourists come to this place to enjoy the wonderful view. In Cyberland, it is believed that the number "8" is a lucky number (that's why Giga Tower has 8<=888<=888<=888 floors above the ground), and, an integer is lucky, if and only if its decimal notation contains at least one digit "8". For example, 8,<=<=-<=180,<=808 are all lucky while 42,<=<=-<=10 are not. In the Giga Tower, if you write code at a floor with lucky floor number, good luck will always be with you (Well, this round is #278, also lucky, huh?). Tourist Henry goes to the tower to seek good luck. Now he is at the floor numbered *a*. He wants to find the minimum positive integer *b*, such that, if he walks *b* floors higher, he will arrive at a floor with a lucky number.
The only line of input contains an integer *a* (<=-<=109<=≤<=*a*<=≤<=109).
Print the minimum *b* in a line.
[ "179\n", "-1\n", "18\n" ]
[ "1\n", "9\n", "10\n" ]
For the first sample, he has to arrive at the floor numbered 180. For the second sample, he will arrive at 8. Note that *b* should be positive, so the answer for the third sample is 10, not 0.
500
[ { "input": "179", "output": "1" }, { "input": "-1", "output": "9" }, { "input": "18", "output": "10" }, { "input": "-410058385", "output": "1" }, { "input": "-586825624", "output": "1" }, { "input": "852318890", "output": "1" }, { "input": "919067153", "output": "5" }, { "input": "690422411", "output": "7" }, { "input": "-408490162", "output": "1" }, { "input": "-8", "output": "16" }, { "input": "-6", "output": "14" }, { "input": "-4", "output": "12" }, { "input": "-2", "output": "10" }, { "input": "0", "output": "8" }, { "input": "2", "output": "6" }, { "input": "4", "output": "4" }, { "input": "6", "output": "2" }, { "input": "8", "output": "10" }, { "input": "1000000000", "output": "8" }, { "input": "-1000000000", "output": "2" }, { "input": "88888", "output": "1" }, { "input": "89", "output": "9" }, { "input": "-80000000", "output": "2" }, { "input": "-8888", "output": "1" }, { "input": "-17", "output": "9" }, { "input": "78", "output": "2" }, { "input": "-19", "output": "1" }, { "input": "-999999998", "output": "9" }, { "input": "-999999997", "output": "8" }, { "input": "999999997", "output": "1" }, { "input": "811111111", "output": "1" }, { "input": "-8", "output": "16" }, { "input": "-5", "output": "13" }, { "input": "-7", "output": "15" }, { "input": "1000000000", "output": "8" } ]
1,416,607,274
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
2
46
0
a = int(input()) i = 0 while '8' not in str(a+i): i += 1 print(i)
Title: Giga Tower Time Limit: None seconds Memory Limit: None megabytes Problem Description: Giga Tower is the tallest and deepest building in Cyberland. There are 17<=777<=777<=777 floors, numbered from <=-<=8<=888<=888<=888 to 8<=888<=888<=888. In particular, there is floor 0 between floor <=-<=1 and floor 1. Every day, thousands of tourists come to this place to enjoy the wonderful view. In Cyberland, it is believed that the number "8" is a lucky number (that's why Giga Tower has 8<=888<=888<=888 floors above the ground), and, an integer is lucky, if and only if its decimal notation contains at least one digit "8". For example, 8,<=<=-<=180,<=808 are all lucky while 42,<=<=-<=10 are not. In the Giga Tower, if you write code at a floor with lucky floor number, good luck will always be with you (Well, this round is #278, also lucky, huh?). Tourist Henry goes to the tower to seek good luck. Now he is at the floor numbered *a*. He wants to find the minimum positive integer *b*, such that, if he walks *b* floors higher, he will arrive at a floor with a lucky number. Input Specification: The only line of input contains an integer *a* (<=-<=109<=≤<=*a*<=≤<=109). Output Specification: Print the minimum *b* in a line. Demo Input: ['179\n', '-1\n', '18\n'] Demo Output: ['1\n', '9\n', '10\n'] Note: For the first sample, he has to arrive at the floor numbered 180. For the second sample, he will arrive at 8. Note that *b* should be positive, so the answer for the third sample is 10, not 0.
```python a = int(input()) i = 0 while '8' not in str(a+i): i += 1 print(i) ```
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*<=&lt;<=*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,632,723,575
2,147,483,647
PyPy 3
OK
TESTS
50
186
20,172,800
# cook your dish here n,a,b = input().split() n = int(n) a = int(a) b = int(b) count = 0 for i in range(1,n+1): if i>a and n-i<=b: count = count + 1 print(count)
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*<=&lt;<=*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 # cook your dish here n,a,b = input().split() n = int(n) a = int(a) b = int(b) count = 0 for i in range(1,n+1): if i>a and n-i<=b: count = count + 1 print(count) ```
3
534
A
Exam
PROGRAMMING
1,100
[ "constructive algorithms", "implementation", "math" ]
null
null
An exam for *n* students will take place in a long and narrow room, so the students will sit in a line in some order. The teacher suspects that students with adjacent numbers (*i* and *i*<=+<=1) always studied side by side and became friends and if they take an exam sitting next to each other, they will help each other for sure. Your task is to choose the maximum number of students and make such an arrangement of students in the room that no two students with adjacent numbers sit side by side.
A single line contains integer *n* (1<=≤<=*n*<=≤<=5000) — the number of students at an exam.
In the first line print integer *k* — the maximum number of students who can be seated so that no two students with adjacent numbers sit next to each other. In the second line print *k* distinct integers *a*1,<=*a*2,<=...,<=*a**k* (1<=≤<=*a**i*<=≤<=*n*), where *a**i* is the number of the student on the *i*-th position. The students on adjacent positions mustn't have adjacent numbers. Formally, the following should be true: |*a**i*<=-<=*a**i*<=+<=1|<=≠<=1 for all *i* from 1 to *k*<=-<=1. If there are several possible answers, output any of them.
[ "6", "3\n" ]
[ "6\n1 5 3 6 2 4", "2\n1 3" ]
none
500
[ { "input": "6", "output": "6\n5 3 1 6 4 2 " }, { "input": "3", "output": "2\n1 3" }, { "input": "1", "output": "1\n1 " }, { "input": "2", "output": "1\n1" }, { "input": "4", "output": "4\n3 1 4 2 " }, { "input": "5", "output": "5\n5 3 1 4 2 " }, { "input": "7", "output": "7\n7 5 3 1 6 4 2 " }, { "input": "8", "output": "8\n7 5 3 1 8 6 4 2 " }, { "input": "9", "output": "9\n9 7 5 3 1 8 6 4 2 " }, { "input": "10", "output": "10\n9 7 5 3 1 10 8 6 4 2 " }, { "input": "13", "output": "13\n13 11 9 7 5 3 1 12 10 8 6 4 2 " }, { "input": "16", "output": "16\n15 13 11 9 7 5 3 1 16 14 12 10 8 6 4 2 " }, { "input": "25", "output": "25\n25 23 21 19 17 15 13 11 9 7 5 3 1 24 22 20 18 16 14 12 10 8 6 4 2 " }, { "input": "29", "output": "29\n29 27 25 23 21 19 17 15 13 11 9 7 5 3 1 28 26 24 22 20 18 16 14 12 10 8 6 4 2 " }, { "input": "120", "output": "120\n119 117 115 113 111 109 107 105 103 101 99 97 95 93 91 89 87 85 83 81 79 77 75 73 71 69 67 65 63 61 59 57 55 53 51 49 47 45 43 41 39 37 35 33 31 29 27 25 23 21 19 17 15 13 11 9 7 5 3 1 120 118 116 114 112 110 108 106 104 102 100 98 96 94 92 90 88 86 84 82 80 78 76 74 72 70 68 66 64 62 60 58 56 54 52 50 48 46 44 42 40 38 36 34 32 30 28 26 24 22 20 18 16 14 12 10 8 6 4 2 " }, { "input": "128", "output": "128\n127 125 123 121 119 117 115 113 111 109 107 105 103 101 99 97 95 93 91 89 87 85 83 81 79 77 75 73 71 69 67 65 63 61 59 57 55 53 51 49 47 45 43 41 39 37 35 33 31 29 27 25 23 21 19 17 15 13 11 9 7 5 3 1 128 126 124 122 120 118 116 114 112 110 108 106 104 102 100 98 96 94 92 90 88 86 84 82 80 78 76 74 72 70 68 66 64 62 60 58 56 54 52 50 48 46 44 42 40 38 36 34 32 30 28 26 24 22 20 18 16 14 12 10 8 6 4 2 " }, { "input": "216", "output": "216\n215 213 211 209 207 205 203 201 199 197 195 193 191 189 187 185 183 181 179 177 175 173 171 169 167 165 163 161 159 157 155 153 151 149 147 145 143 141 139 137 135 133 131 129 127 125 123 121 119 117 115 113 111 109 107 105 103 101 99 97 95 93 91 89 87 85 83 81 79 77 75 73 71 69 67 65 63 61 59 57 55 53 51 49 47 45 43 41 39 37 35 33 31 29 27 25 23 21 19 17 15 13 11 9 7 5 3 1 216 214 212 210 208 206 204 202 200 198 196 194 192 190 188 186 184 182 180 178 176 174 172 170 168 166 164 162 160 158 156 154 1..." }, { "input": "729", "output": "729\n729 727 725 723 721 719 717 715 713 711 709 707 705 703 701 699 697 695 693 691 689 687 685 683 681 679 677 675 673 671 669 667 665 663 661 659 657 655 653 651 649 647 645 643 641 639 637 635 633 631 629 627 625 623 621 619 617 615 613 611 609 607 605 603 601 599 597 595 593 591 589 587 585 583 581 579 577 575 573 571 569 567 565 563 561 559 557 555 553 551 549 547 545 543 541 539 537 535 533 531 529 527 525 523 521 519 517 515 513 511 509 507 505 503 501 499 497 495 493 491 489 487 485 483 481 479 47..." }, { "input": "1111", "output": "1111\n1111 1109 1107 1105 1103 1101 1099 1097 1095 1093 1091 1089 1087 1085 1083 1081 1079 1077 1075 1073 1071 1069 1067 1065 1063 1061 1059 1057 1055 1053 1051 1049 1047 1045 1043 1041 1039 1037 1035 1033 1031 1029 1027 1025 1023 1021 1019 1017 1015 1013 1011 1009 1007 1005 1003 1001 999 997 995 993 991 989 987 985 983 981 979 977 975 973 971 969 967 965 963 961 959 957 955 953 951 949 947 945 943 941 939 937 935 933 931 929 927 925 923 921 919 917 915 913 911 909 907 905 903 901 899 897 895 893 891 889 8..." }, { "input": "1597", "output": "1597\n1597 1595 1593 1591 1589 1587 1585 1583 1581 1579 1577 1575 1573 1571 1569 1567 1565 1563 1561 1559 1557 1555 1553 1551 1549 1547 1545 1543 1541 1539 1537 1535 1533 1531 1529 1527 1525 1523 1521 1519 1517 1515 1513 1511 1509 1507 1505 1503 1501 1499 1497 1495 1493 1491 1489 1487 1485 1483 1481 1479 1477 1475 1473 1471 1469 1467 1465 1463 1461 1459 1457 1455 1453 1451 1449 1447 1445 1443 1441 1439 1437 1435 1433 1431 1429 1427 1425 1423 1421 1419 1417 1415 1413 1411 1409 1407 1405 1403 1401 1399 1397 ..." }, { "input": "1777", "output": "1777\n1777 1775 1773 1771 1769 1767 1765 1763 1761 1759 1757 1755 1753 1751 1749 1747 1745 1743 1741 1739 1737 1735 1733 1731 1729 1727 1725 1723 1721 1719 1717 1715 1713 1711 1709 1707 1705 1703 1701 1699 1697 1695 1693 1691 1689 1687 1685 1683 1681 1679 1677 1675 1673 1671 1669 1667 1665 1663 1661 1659 1657 1655 1653 1651 1649 1647 1645 1643 1641 1639 1637 1635 1633 1631 1629 1627 1625 1623 1621 1619 1617 1615 1613 1611 1609 1607 1605 1603 1601 1599 1597 1595 1593 1591 1589 1587 1585 1583 1581 1579 1577 ..." }, { "input": "2048", "output": "2048\n2047 2045 2043 2041 2039 2037 2035 2033 2031 2029 2027 2025 2023 2021 2019 2017 2015 2013 2011 2009 2007 2005 2003 2001 1999 1997 1995 1993 1991 1989 1987 1985 1983 1981 1979 1977 1975 1973 1971 1969 1967 1965 1963 1961 1959 1957 1955 1953 1951 1949 1947 1945 1943 1941 1939 1937 1935 1933 1931 1929 1927 1925 1923 1921 1919 1917 1915 1913 1911 1909 1907 1905 1903 1901 1899 1897 1895 1893 1891 1889 1887 1885 1883 1881 1879 1877 1875 1873 1871 1869 1867 1865 1863 1861 1859 1857 1855 1853 1851 1849 1847 ..." }, { "input": "2999", "output": "2999\n2999 2997 2995 2993 2991 2989 2987 2985 2983 2981 2979 2977 2975 2973 2971 2969 2967 2965 2963 2961 2959 2957 2955 2953 2951 2949 2947 2945 2943 2941 2939 2937 2935 2933 2931 2929 2927 2925 2923 2921 2919 2917 2915 2913 2911 2909 2907 2905 2903 2901 2899 2897 2895 2893 2891 2889 2887 2885 2883 2881 2879 2877 2875 2873 2871 2869 2867 2865 2863 2861 2859 2857 2855 2853 2851 2849 2847 2845 2843 2841 2839 2837 2835 2833 2831 2829 2827 2825 2823 2821 2819 2817 2815 2813 2811 2809 2807 2805 2803 2801 2799 ..." }, { "input": "3001", "output": "3001\n3001 2999 2997 2995 2993 2991 2989 2987 2985 2983 2981 2979 2977 2975 2973 2971 2969 2967 2965 2963 2961 2959 2957 2955 2953 2951 2949 2947 2945 2943 2941 2939 2937 2935 2933 2931 2929 2927 2925 2923 2921 2919 2917 2915 2913 2911 2909 2907 2905 2903 2901 2899 2897 2895 2893 2891 2889 2887 2885 2883 2881 2879 2877 2875 2873 2871 2869 2867 2865 2863 2861 2859 2857 2855 2853 2851 2849 2847 2845 2843 2841 2839 2837 2835 2833 2831 2829 2827 2825 2823 2821 2819 2817 2815 2813 2811 2809 2807 2805 2803 2801 ..." }, { "input": "4181", "output": "4181\n4181 4179 4177 4175 4173 4171 4169 4167 4165 4163 4161 4159 4157 4155 4153 4151 4149 4147 4145 4143 4141 4139 4137 4135 4133 4131 4129 4127 4125 4123 4121 4119 4117 4115 4113 4111 4109 4107 4105 4103 4101 4099 4097 4095 4093 4091 4089 4087 4085 4083 4081 4079 4077 4075 4073 4071 4069 4067 4065 4063 4061 4059 4057 4055 4053 4051 4049 4047 4045 4043 4041 4039 4037 4035 4033 4031 4029 4027 4025 4023 4021 4019 4017 4015 4013 4011 4009 4007 4005 4003 4001 3999 3997 3995 3993 3991 3989 3987 3985 3983 3981 ..." }, { "input": "4990", "output": "4990\n4989 4987 4985 4983 4981 4979 4977 4975 4973 4971 4969 4967 4965 4963 4961 4959 4957 4955 4953 4951 4949 4947 4945 4943 4941 4939 4937 4935 4933 4931 4929 4927 4925 4923 4921 4919 4917 4915 4913 4911 4909 4907 4905 4903 4901 4899 4897 4895 4893 4891 4889 4887 4885 4883 4881 4879 4877 4875 4873 4871 4869 4867 4865 4863 4861 4859 4857 4855 4853 4851 4849 4847 4845 4843 4841 4839 4837 4835 4833 4831 4829 4827 4825 4823 4821 4819 4817 4815 4813 4811 4809 4807 4805 4803 4801 4799 4797 4795 4793 4791 4789 ..." }, { "input": "4991", "output": "4991\n4991 4989 4987 4985 4983 4981 4979 4977 4975 4973 4971 4969 4967 4965 4963 4961 4959 4957 4955 4953 4951 4949 4947 4945 4943 4941 4939 4937 4935 4933 4931 4929 4927 4925 4923 4921 4919 4917 4915 4913 4911 4909 4907 4905 4903 4901 4899 4897 4895 4893 4891 4889 4887 4885 4883 4881 4879 4877 4875 4873 4871 4869 4867 4865 4863 4861 4859 4857 4855 4853 4851 4849 4847 4845 4843 4841 4839 4837 4835 4833 4831 4829 4827 4825 4823 4821 4819 4817 4815 4813 4811 4809 4807 4805 4803 4801 4799 4797 4795 4793 4791 ..." }, { "input": "4992", "output": "4992\n4991 4989 4987 4985 4983 4981 4979 4977 4975 4973 4971 4969 4967 4965 4963 4961 4959 4957 4955 4953 4951 4949 4947 4945 4943 4941 4939 4937 4935 4933 4931 4929 4927 4925 4923 4921 4919 4917 4915 4913 4911 4909 4907 4905 4903 4901 4899 4897 4895 4893 4891 4889 4887 4885 4883 4881 4879 4877 4875 4873 4871 4869 4867 4865 4863 4861 4859 4857 4855 4853 4851 4849 4847 4845 4843 4841 4839 4837 4835 4833 4831 4829 4827 4825 4823 4821 4819 4817 4815 4813 4811 4809 4807 4805 4803 4801 4799 4797 4795 4793 4791 ..." }, { "input": "4993", "output": "4993\n4993 4991 4989 4987 4985 4983 4981 4979 4977 4975 4973 4971 4969 4967 4965 4963 4961 4959 4957 4955 4953 4951 4949 4947 4945 4943 4941 4939 4937 4935 4933 4931 4929 4927 4925 4923 4921 4919 4917 4915 4913 4911 4909 4907 4905 4903 4901 4899 4897 4895 4893 4891 4889 4887 4885 4883 4881 4879 4877 4875 4873 4871 4869 4867 4865 4863 4861 4859 4857 4855 4853 4851 4849 4847 4845 4843 4841 4839 4837 4835 4833 4831 4829 4827 4825 4823 4821 4819 4817 4815 4813 4811 4809 4807 4805 4803 4801 4799 4797 4795 4793 ..." }, { "input": "4994", "output": "4994\n4993 4991 4989 4987 4985 4983 4981 4979 4977 4975 4973 4971 4969 4967 4965 4963 4961 4959 4957 4955 4953 4951 4949 4947 4945 4943 4941 4939 4937 4935 4933 4931 4929 4927 4925 4923 4921 4919 4917 4915 4913 4911 4909 4907 4905 4903 4901 4899 4897 4895 4893 4891 4889 4887 4885 4883 4881 4879 4877 4875 4873 4871 4869 4867 4865 4863 4861 4859 4857 4855 4853 4851 4849 4847 4845 4843 4841 4839 4837 4835 4833 4831 4829 4827 4825 4823 4821 4819 4817 4815 4813 4811 4809 4807 4805 4803 4801 4799 4797 4795 4793 ..." }, { "input": "4995", "output": "4995\n4995 4993 4991 4989 4987 4985 4983 4981 4979 4977 4975 4973 4971 4969 4967 4965 4963 4961 4959 4957 4955 4953 4951 4949 4947 4945 4943 4941 4939 4937 4935 4933 4931 4929 4927 4925 4923 4921 4919 4917 4915 4913 4911 4909 4907 4905 4903 4901 4899 4897 4895 4893 4891 4889 4887 4885 4883 4881 4879 4877 4875 4873 4871 4869 4867 4865 4863 4861 4859 4857 4855 4853 4851 4849 4847 4845 4843 4841 4839 4837 4835 4833 4831 4829 4827 4825 4823 4821 4819 4817 4815 4813 4811 4809 4807 4805 4803 4801 4799 4797 4795 ..." }, { "input": "4996", "output": "4996\n4995 4993 4991 4989 4987 4985 4983 4981 4979 4977 4975 4973 4971 4969 4967 4965 4963 4961 4959 4957 4955 4953 4951 4949 4947 4945 4943 4941 4939 4937 4935 4933 4931 4929 4927 4925 4923 4921 4919 4917 4915 4913 4911 4909 4907 4905 4903 4901 4899 4897 4895 4893 4891 4889 4887 4885 4883 4881 4879 4877 4875 4873 4871 4869 4867 4865 4863 4861 4859 4857 4855 4853 4851 4849 4847 4845 4843 4841 4839 4837 4835 4833 4831 4829 4827 4825 4823 4821 4819 4817 4815 4813 4811 4809 4807 4805 4803 4801 4799 4797 4795 ..." }, { "input": "4997", "output": "4997\n4997 4995 4993 4991 4989 4987 4985 4983 4981 4979 4977 4975 4973 4971 4969 4967 4965 4963 4961 4959 4957 4955 4953 4951 4949 4947 4945 4943 4941 4939 4937 4935 4933 4931 4929 4927 4925 4923 4921 4919 4917 4915 4913 4911 4909 4907 4905 4903 4901 4899 4897 4895 4893 4891 4889 4887 4885 4883 4881 4879 4877 4875 4873 4871 4869 4867 4865 4863 4861 4859 4857 4855 4853 4851 4849 4847 4845 4843 4841 4839 4837 4835 4833 4831 4829 4827 4825 4823 4821 4819 4817 4815 4813 4811 4809 4807 4805 4803 4801 4799 4797 ..." }, { "input": "4998", "output": "4998\n4997 4995 4993 4991 4989 4987 4985 4983 4981 4979 4977 4975 4973 4971 4969 4967 4965 4963 4961 4959 4957 4955 4953 4951 4949 4947 4945 4943 4941 4939 4937 4935 4933 4931 4929 4927 4925 4923 4921 4919 4917 4915 4913 4911 4909 4907 4905 4903 4901 4899 4897 4895 4893 4891 4889 4887 4885 4883 4881 4879 4877 4875 4873 4871 4869 4867 4865 4863 4861 4859 4857 4855 4853 4851 4849 4847 4845 4843 4841 4839 4837 4835 4833 4831 4829 4827 4825 4823 4821 4819 4817 4815 4813 4811 4809 4807 4805 4803 4801 4799 4797 ..." }, { "input": "4999", "output": "4999\n4999 4997 4995 4993 4991 4989 4987 4985 4983 4981 4979 4977 4975 4973 4971 4969 4967 4965 4963 4961 4959 4957 4955 4953 4951 4949 4947 4945 4943 4941 4939 4937 4935 4933 4931 4929 4927 4925 4923 4921 4919 4917 4915 4913 4911 4909 4907 4905 4903 4901 4899 4897 4895 4893 4891 4889 4887 4885 4883 4881 4879 4877 4875 4873 4871 4869 4867 4865 4863 4861 4859 4857 4855 4853 4851 4849 4847 4845 4843 4841 4839 4837 4835 4833 4831 4829 4827 4825 4823 4821 4819 4817 4815 4813 4811 4809 4807 4805 4803 4801 4799 ..." }, { "input": "5000", "output": "5000\n4999 4997 4995 4993 4991 4989 4987 4985 4983 4981 4979 4977 4975 4973 4971 4969 4967 4965 4963 4961 4959 4957 4955 4953 4951 4949 4947 4945 4943 4941 4939 4937 4935 4933 4931 4929 4927 4925 4923 4921 4919 4917 4915 4913 4911 4909 4907 4905 4903 4901 4899 4897 4895 4893 4891 4889 4887 4885 4883 4881 4879 4877 4875 4873 4871 4869 4867 4865 4863 4861 4859 4857 4855 4853 4851 4849 4847 4845 4843 4841 4839 4837 4835 4833 4831 4829 4827 4825 4823 4821 4819 4817 4815 4813 4811 4809 4807 4805 4803 4801 4799 ..." } ]
1,566,340,059
2,147,483,647
PyPy 3
WRONG_ANSWER
TESTS
0
109
0
n=int(input()) if n==2: print(0) print() elif n==3: print(2) print('1 3') else: a=list(range(n-(1-n%2),0,-2))+list(range(2*(n//2),1,-2)) print(' '.join(map(str,a)))
Title: Exam Time Limit: None seconds Memory Limit: None megabytes Problem Description: An exam for *n* students will take place in a long and narrow room, so the students will sit in a line in some order. The teacher suspects that students with adjacent numbers (*i* and *i*<=+<=1) always studied side by side and became friends and if they take an exam sitting next to each other, they will help each other for sure. Your task is to choose the maximum number of students and make such an arrangement of students in the room that no two students with adjacent numbers sit side by side. Input Specification: A single line contains integer *n* (1<=≤<=*n*<=≤<=5000) — the number of students at an exam. Output Specification: In the first line print integer *k* — the maximum number of students who can be seated so that no two students with adjacent numbers sit next to each other. In the second line print *k* distinct integers *a*1,<=*a*2,<=...,<=*a**k* (1<=≤<=*a**i*<=≤<=*n*), where *a**i* is the number of the student on the *i*-th position. The students on adjacent positions mustn't have adjacent numbers. Formally, the following should be true: |*a**i*<=-<=*a**i*<=+<=1|<=≠<=1 for all *i* from 1 to *k*<=-<=1. If there are several possible answers, output any of them. Demo Input: ['6', '3\n'] Demo Output: ['6\n1 5 3 6 2 4', '2\n1 3'] Note: none
```python n=int(input()) if n==2: print(0) print() elif n==3: print(2) print('1 3') else: a=list(range(n-(1-n%2),0,-2))+list(range(2*(n//2),1,-2)) print(' '.join(map(str,a))) ```
0
1,007
A
Reorder the Array
PROGRAMMING
1,300
[ "combinatorics", "data structures", "math", "sortings", "two pointers" ]
null
null
You are given an array of integers. Vasya can permute (change order) its integers. He wants to do it so that as many as possible integers will become on a place where a smaller integer used to stand. Help Vasya find the maximal number of such integers. For instance, if we are given an array $[10, 20, 30, 40]$, we can permute it so that it becomes $[20, 40, 10, 30]$. Then on the first and the second positions the integers became larger ($20&gt;10$, $40&gt;20$) and did not on the third and the fourth, so for this permutation, the number that Vasya wants to maximize equals $2$. Read the note for the first example, there is one more demonstrative test case. Help Vasya to permute integers in such way that the number of positions in a new array, where integers are greater than in the original one, is maximal.
The first line contains a single integer $n$ ($1 \leq n \leq 10^5$) — the length of the array. The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \leq a_i \leq 10^9$) — the elements of the array.
Print a single integer — the maximal number of the array's elements which after a permutation will stand on the position where a smaller element stood in the initial array.
[ "7\n10 1 1 1 5 5 3\n", "5\n1 1 1 1 1\n" ]
[ "4\n", "0\n" ]
In the first sample, one of the best permutations is $[1, 5, 5, 3, 10, 1, 1]$. On the positions from second to fifth the elements became larger, so the answer for this permutation is 4. In the second sample, there is no way to increase any element with a permutation, so the answer is 0.
500
[ { "input": "7\n10 1 1 1 5 5 3", "output": "4" }, { "input": "5\n1 1 1 1 1", "output": "0" }, { "input": "6\n300000000 200000000 300000000 200000000 1000000000 300000000", "output": "3" }, { "input": "10\n1 2 3 4 5 6 7 8 9 10", "output": "9" }, { "input": "1\n1", "output": "0" }, { "input": "7\n3 5 2 2 5 2 4", "output": "4" }, { "input": "5\n1 5 4 2 3", "output": "4" } ]
1,643,652,817
2,147,483,647
PyPy 3-64
WRONG_ANSWER
TESTS
2
46
512,000
def binarySearch(arr, l, r, x): while l <= r: mid = l + (r - l) // 2 if arr[mid] == x: return mid elif arr[mid] < x: l = mid + 1 else: r = mid - 1 return -1 n=int(input()) arr=list(map(int,input().split())) l=sorted(arr) h=dict() arr1=[] for i in range(n): a=len(l) l1=binarySearch(l, 0, a-1, arr[i]) if l1+1 <a: arr1.append(l.pop(l1+1)) else: arr1.append(l.pop(0)) z=0 for j in range(n): if arr[j]<arr1[i]: z+=1 print(z)
Title: Reorder the Array Time Limit: None seconds Memory Limit: None megabytes Problem Description: You are given an array of integers. Vasya can permute (change order) its integers. He wants to do it so that as many as possible integers will become on a place where a smaller integer used to stand. Help Vasya find the maximal number of such integers. For instance, if we are given an array $[10, 20, 30, 40]$, we can permute it so that it becomes $[20, 40, 10, 30]$. Then on the first and the second positions the integers became larger ($20&gt;10$, $40&gt;20$) and did not on the third and the fourth, so for this permutation, the number that Vasya wants to maximize equals $2$. Read the note for the first example, there is one more demonstrative test case. Help Vasya to permute integers in such way that the number of positions in a new array, where integers are greater than in the original one, is maximal. Input Specification: The first line contains a single integer $n$ ($1 \leq n \leq 10^5$) — the length of the array. The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \leq a_i \leq 10^9$) — the elements of the array. Output Specification: Print a single integer — the maximal number of the array's elements which after a permutation will stand on the position where a smaller element stood in the initial array. Demo Input: ['7\n10 1 1 1 5 5 3\n', '5\n1 1 1 1 1\n'] Demo Output: ['4\n', '0\n'] Note: In the first sample, one of the best permutations is $[1, 5, 5, 3, 10, 1, 1]$. On the positions from second to fifth the elements became larger, so the answer for this permutation is 4. In the second sample, there is no way to increase any element with a permutation, so the answer is 0.
```python def binarySearch(arr, l, r, x): while l <= r: mid = l + (r - l) // 2 if arr[mid] == x: return mid elif arr[mid] < x: l = mid + 1 else: r = mid - 1 return -1 n=int(input()) arr=list(map(int,input().split())) l=sorted(arr) h=dict() arr1=[] for i in range(n): a=len(l) l1=binarySearch(l, 0, a-1, arr[i]) if l1+1 <a: arr1.append(l.pop(l1+1)) else: arr1.append(l.pop(0)) z=0 for j in range(n): if arr[j]<arr1[i]: z+=1 print(z) ```
0
680
B
Bear and Finding Criminals
PROGRAMMING
1,000
[ "constructive algorithms", "implementation" ]
null
null
There are *n* cities in Bearland, numbered 1 through *n*. Cities are arranged in one long row. The distance between cities *i* and *j* is equal to |*i*<=-<=*j*|. Limak is a police officer. He lives in a city *a*. His job is to catch criminals. It's hard because he doesn't know in which cities criminals are. Though, he knows that there is at most one criminal in each city. Limak is going to use a BCD (Bear Criminal Detector). The BCD will tell Limak how many criminals there are for every distance from a city *a*. After that, Limak can catch a criminal in each city for which he is sure that there must be a criminal. You know in which cities criminals are. Count the number of criminals Limak will catch, after he uses the BCD.
The first line of the input contains two integers *n* and *a* (1<=≤<=*a*<=≤<=*n*<=≤<=100) — the number of cities and the index of city where Limak lives. The second line contains *n* integers *t*1,<=*t*2,<=...,<=*t**n* (0<=≤<=*t**i*<=≤<=1). There are *t**i* criminals in the *i*-th city.
Print the number of criminals Limak will catch.
[ "6 3\n1 1 1 0 1 0\n", "5 2\n0 0 0 1 0\n" ]
[ "3\n", "1\n" ]
In the first sample, there are six cities and Limak lives in the third one (blue arrow below). Criminals are in cities marked red. Using the BCD gives Limak the following information: - There is one criminal at distance 0 from the third city — Limak is sure that this criminal is exactly in the third city. - There is one criminal at distance 1 from the third city — Limak doesn't know if a criminal is in the second or fourth city. - There are two criminals at distance 2 from the third city — Limak is sure that there is one criminal in the first city and one in the fifth city. - There are zero criminals for every greater distance. So, Limak will catch criminals in cities 1, 3 and 5, that is 3 criminals in total. In the second sample (drawing below), the BCD gives Limak the information that there is one criminal at distance 2 from Limak's city. There is only one city at distance 2 so Limak is sure where a criminal is.
1,000
[ { "input": "6 3\n1 1 1 0 1 0", "output": "3" }, { "input": "5 2\n0 0 0 1 0", "output": "1" }, { "input": "1 1\n1", "output": "1" }, { "input": "1 1\n0", "output": "0" }, { "input": "9 3\n1 1 1 1 1 1 1 1 0", "output": "8" }, { "input": "9 5\n1 0 1 0 1 0 1 0 1", "output": "5" }, { "input": "20 17\n1 1 0 1 1 1 1 0 1 0 1 1 1 0 1 1 0 0 0 0", "output": "10" }, { "input": "100 60\n1 1 1 1 1 1 0 1 0 0 1 1 0 1 1 1 1 1 0 0 1 1 0 0 0 0 0 1 0 1 1 0 1 0 1 0 1 0 1 1 0 0 0 0 0 1 1 1 0 1 1 0 0 0 1 0 0 0 1 1 1 0 1 0 0 1 1 1 0 1 1 1 0 0 1 1 0 1 0 0 0 1 0 0 0 0 0 0 1 1 1 0 0 1 1 1 0 1 0 0", "output": "27" }, { "input": "8 1\n1 0 1 1 0 0 1 0", "output": "4" }, { "input": "11 11\n0 1 0 0 1 1 1 0 0 0 0", "output": "4" }, { "input": "19 10\n0 1 1 0 1 0 0 1 1 0 0 1 0 1 0 0 1 0 1", "output": "4" }, { "input": "100 38\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 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 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 38\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 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 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": "1" }, { "input": "100 38\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 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 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": "3" }, { "input": "99 38\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 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 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": "25" }, { "input": "99 38\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 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 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": "24" }, { "input": "99 38\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 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 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": "24" }, { "input": "98 70\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 0 0 0 0 0 0 0 0 0 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": "41" }, { "input": "99 70\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 1 1 1 1 1 1 1 1 1 1 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": "9" }, { "input": "99 60\n0 0 0 1 1 0 1 1 0 0 1 0 0 0 0 0 1 0 1 0 0 0 1 0 1 1 1 0 1 1 1 1 0 0 1 1 1 0 1 1 1 1 1 0 1 1 0 0 0 0 0 1 0 0 1 0 1 1 1 1 1 0 1 0 1 1 0 0 1 0 1 0 0 1 0 0 1 1 1 0 0 0 0 1 1 0 1 1 1 1 0 0 0 0 0 0 1 1 1", "output": "34" }, { "input": "98 24\n0 0 0 1 1 0 1 1 0 0 0 0 1 0 0 1 0 0 1 1 1 0 0 1 0 0 1 0 1 0 0 1 1 0 1 1 1 0 1 0 0 1 0 0 0 1 1 1 1 0 1 1 1 0 1 1 1 1 0 0 1 0 0 0 1 0 1 1 0 1 0 1 1 1 0 0 1 0 0 0 1 1 0 0 1 1 1 1 1 1 0 1 0 1 0 0 1 1", "output": "39" }, { "input": "100 100\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1", "output": "100" }, { "input": "100 1\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": "2 1\n0 1", "output": "1" } ]
1,667,681,778
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
4
46
0
n,a=map(int,input().split()) d=list(map(int,input().split())) a-=1 c=0 i=1 l1=d[:a] l2=d[a+1:] if d[a]==1: c+=1 while a-i>=0 and a+i<len(d): if d[a-i]==1 and d[a+i]==1: c+=2 i+=1 if len(l2)>len(l1): l2=l2[::-1] for j in l2[len(l1):]: if j==1: c+=1 if len(l1)>len(l2): l1=l1[::-1] for k in l1[len(l2):]: if k==1: c+=1 print(c)
Title: Bear and Finding Criminals Time Limit: None seconds Memory Limit: None megabytes Problem Description: There are *n* cities in Bearland, numbered 1 through *n*. Cities are arranged in one long row. The distance between cities *i* and *j* is equal to |*i*<=-<=*j*|. Limak is a police officer. He lives in a city *a*. His job is to catch criminals. It's hard because he doesn't know in which cities criminals are. Though, he knows that there is at most one criminal in each city. Limak is going to use a BCD (Bear Criminal Detector). The BCD will tell Limak how many criminals there are for every distance from a city *a*. After that, Limak can catch a criminal in each city for which he is sure that there must be a criminal. You know in which cities criminals are. Count the number of criminals Limak will catch, after he uses the BCD. Input Specification: The first line of the input contains two integers *n* and *a* (1<=≤<=*a*<=≤<=*n*<=≤<=100) — the number of cities and the index of city where Limak lives. The second line contains *n* integers *t*1,<=*t*2,<=...,<=*t**n* (0<=≤<=*t**i*<=≤<=1). There are *t**i* criminals in the *i*-th city. Output Specification: Print the number of criminals Limak will catch. Demo Input: ['6 3\n1 1 1 0 1 0\n', '5 2\n0 0 0 1 0\n'] Demo Output: ['3\n', '1\n'] Note: In the first sample, there are six cities and Limak lives in the third one (blue arrow below). Criminals are in cities marked red. Using the BCD gives Limak the following information: - There is one criminal at distance 0 from the third city — Limak is sure that this criminal is exactly in the third city. - There is one criminal at distance 1 from the third city — Limak doesn't know if a criminal is in the second or fourth city. - There are two criminals at distance 2 from the third city — Limak is sure that there is one criminal in the first city and one in the fifth city. - There are zero criminals for every greater distance. So, Limak will catch criminals in cities 1, 3 and 5, that is 3 criminals in total. In the second sample (drawing below), the BCD gives Limak the information that there is one criminal at distance 2 from Limak's city. There is only one city at distance 2 so Limak is sure where a criminal is.
```python n,a=map(int,input().split()) d=list(map(int,input().split())) a-=1 c=0 i=1 l1=d[:a] l2=d[a+1:] if d[a]==1: c+=1 while a-i>=0 and a+i<len(d): if d[a-i]==1 and d[a+i]==1: c+=2 i+=1 if len(l2)>len(l1): l2=l2[::-1] for j in l2[len(l1):]: if j==1: c+=1 if len(l1)>len(l2): l1=l1[::-1] for k in l1[len(l2):]: if k==1: c+=1 print(c) ```
0
520
A
Pangram
PROGRAMMING
800
[ "implementation", "strings" ]
null
null
A word or a sentence in some language is called a pangram if all the characters of the alphabet of this language appear in it at least once. Pangrams are often used to demonstrate fonts in printing or test the output devices. You are given a string consisting of lowercase and uppercase Latin letters. Check whether this string is a pangram. We say that the string contains a letter of the Latin alphabet if this letter occurs in the string in uppercase or lowercase.
The first line contains a single integer *n* (1<=≤<=*n*<=≤<=100) — the number of characters in the string. The second line contains the string. The string consists only of uppercase and lowercase Latin letters.
Output "YES", if the string is a pangram and "NO" otherwise.
[ "12\ntoosmallword\n", "35\nTheQuickBrownFoxJumpsOverTheLazyDog\n" ]
[ "NO\n", "YES\n" ]
none
500
[ { "input": "12\ntoosmallword", "output": "NO" }, { "input": "35\nTheQuickBrownFoxJumpsOverTheLazyDog", "output": "YES" }, { "input": "1\na", "output": "NO" }, { "input": "26\nqwertyuiopasdfghjklzxcvbnm", "output": "YES" }, { "input": "26\nABCDEFGHIJKLMNOPQRSTUVWXYZ", "output": "YES" }, { "input": "48\nthereisasyetinsufficientdataforameaningfulanswer", "output": "NO" }, { "input": "30\nToBeOrNotToBeThatIsTheQuestion", "output": "NO" }, { "input": "30\njackdawslovemybigsphinxofquarz", "output": "NO" }, { "input": "31\nTHEFIVEBOXINGWIZARDSJUMPQUICKLY", "output": "YES" }, { "input": "26\naaaaaaaaaaaaaaaaaaaaaaaaaa", "output": "NO" }, { "input": "26\nMGJYIZDKsbhpVeNFlquRTcWoAx", "output": "YES" }, { "input": "26\nfWMOhAPsbIVtyUEZrGNQXDklCJ", "output": "YES" }, { "input": "26\nngPMVFSThiRCwLEuyOAbKxQzDJ", "output": "YES" }, { "input": "25\nnxYTzLFwzNolAumjgcAboyxAj", "output": "NO" }, { "input": "26\npRWdodGdxUESvcScPGbUoooZsC", "output": "NO" }, { "input": "66\nBovdMlDzTaqKllZILFVfxbLGsRnzmtVVTmqiIDTYrossLEPlmsPrkUYtWEsGHVOnFj", "output": "NO" }, { "input": "100\nmKtsiDRJypUieHIkvJaMFkwaKxcCIbBszZQLIyPpCDCjhNpAnYFngLjRpnKWpKWtGnwoSteeZXuFHWQxxxOpFlNeYTwKocsXuCoa", "output": "YES" }, { "input": "26\nEoqxUbsLjPytUHMiFnvcGWZdRK", "output": "NO" }, { "input": "26\nvCUFRKElZOnjmXGylWQaHDiPst", "output": "NO" }, { "input": "26\nWtrPuaHdXLKJMsnvQfgOiJZBEY", "output": "NO" }, { "input": "26\npGiFluRteQwkaVoPszJyNBChxM", "output": "NO" }, { "input": "26\ncTUpqjPmANrdbzSFhlWIoKxgVY", "output": "NO" }, { "input": "26\nLndjgvAEuICHKxPwqYztosrmBN", "output": "NO" }, { "input": "26\nMdaXJrCipnOZLykfqHWEStevbU", "output": "NO" }, { "input": "26\nEjDWsVxfKTqGXRnUMOLYcIzPba", "output": "NO" }, { "input": "26\nxKwzRMpunYaqsdfaBgJcVElTHo", "output": "NO" }, { "input": "26\nnRYUQsTwCPLZkgshfEXvBdoiMa", "output": "NO" }, { "input": "26\nHNCQPfJutyAlDGsvRxZWMEbIdO", "output": "NO" }, { "input": "26\nDaHJIpvKznQcmUyWsTGObXRFDe", "output": "NO" }, { "input": "26\nkqvAnFAiRhzlJbtyuWedXSPcOG", "output": "NO" }, { "input": "26\nhlrvgdwsIOyjcmUZXtAKEqoBpF", "output": "NO" }, { "input": "26\njLfXXiMhBTcAwQVReGnpKzdsYu", "output": "NO" }, { "input": "26\nlNMcVuwItjxRBGAekjhyDsQOzf", "output": "NO" }, { "input": "26\nRkSwbNoYldUGtAZvpFMcxhIJFE", "output": "NO" }, { "input": "26\nDqspXZJTuONYieKgaHLMBwfVSC", "output": "NO" }, { "input": "26\necOyUkqNljFHRVXtIpWabGMLDz", "output": "NO" }, { "input": "26\nEKAvqZhBnPmVCDRlgWJfOusxYI", "output": "NO" }, { "input": "26\naLbgqeYchKdMrsZxIPFvTOWNjA", "output": "NO" }, { "input": "26\nxfpBLsndiqtacOCHGmeWUjRkYz", "output": "NO" }, { "input": "26\nXsbRKtqleZPNIVCdfUhyagAomJ", "output": "NO" }, { "input": "26\nAmVtbrwquEthZcjKPLiyDgSoNF", "output": "NO" }, { "input": "26\nOhvXDcwqAUmSEPRZGnjFLiKtNB", "output": "NO" }, { "input": "26\nEKWJqCFLRmstxVBdYuinpbhaOg", "output": "NO" }, { "input": "26\nmnbvcxxlkjhgfdsapoiuytrewq", "output": "NO" }, { "input": "26\naAbcdefghijklmnopqrstuvwxy", "output": "NO" }, { "input": "30\nABCDEFGHTYRIOPLabcdefghtyriopl", "output": "NO" }, { "input": "25\nabcdefghijklmnopqrstuvwxy", "output": "NO" }, { "input": "26\nabcdefhijklmnopqrstVxyzABC", "output": "NO" }, { "input": "25\nqwertyuiopasdfghjklxcvbnm", "output": "NO" }, { "input": "34\nTheQuickBrownFoxJumpsOverTheLayDog", "output": "NO" }, { "input": "26\nabcdefghigklmnopqrstuvwxyz", "output": "NO" }, { "input": "26\nabcdefghijklmnopqrstuvwxyA", "output": "NO" }, { "input": "50\nqazwsxedcrfvtgbyhnujmikolQWERTYUIOASDFGHJKLZXCVBNM", "output": "NO" }, { "input": "35\nTheQuickBrownFoxJumpsOverTheLasyDog", "output": "NO" }, { "input": "25\nbcdefghijklmnopqrstuvwxyz", "output": "NO" }, { "input": "38\nAbCdEfGhIjKlMnOpQrStVwXyZzzzzzzaaaaaaa", "output": "NO" }, { "input": "26\nabcdefghiklmnopqrstvxyzABC", "output": "NO" }, { "input": "26\nabcdefghijklmnopqrstuvwxzZ", "output": "NO" }, { "input": "50\nabcdefghijklmnopqrstuvwxyABCDEFGHIJKLMNOPQRSTUVWXY", "output": "NO" } ]
1,693,936,517
2,147,483,647
PyPy 3
OK
TESTS
59
77
0
n = int(input()) s= input() s = s.lower() alphabet = 'abcdefghijklmnopqrstuvwxyz' for i in alphabet: c = s.count(i) if c < 1: print('NO') exit() print('YES')
Title: Pangram Time Limit: None seconds Memory Limit: None megabytes Problem Description: A word or a sentence in some language is called a pangram if all the characters of the alphabet of this language appear in it at least once. Pangrams are often used to demonstrate fonts in printing or test the output devices. You are given a string consisting of lowercase and uppercase Latin letters. Check whether this string is a pangram. We say that the string contains a letter of the Latin alphabet if this letter occurs in the string in uppercase or lowercase. Input Specification: The first line contains a single integer *n* (1<=≤<=*n*<=≤<=100) — the number of characters in the string. The second line contains the string. The string consists only of uppercase and lowercase Latin letters. Output Specification: Output "YES", if the string is a pangram and "NO" otherwise. Demo Input: ['12\ntoosmallword\n', '35\nTheQuickBrownFoxJumpsOverTheLazyDog\n'] Demo Output: ['NO\n', 'YES\n'] Note: none
```python n = int(input()) s= input() s = s.lower() alphabet = 'abcdefghijklmnopqrstuvwxyz' for i in alphabet: c = s.count(i) if c < 1: print('NO') exit() print('YES') ```
3
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,657,795,249
2,147,483,647
Python 3
COMPILATION_ERROR
TESTS
0
0
0
from itertools import combinations s=input() s1='' a=combinations(s,len(s)-1) l=max(a) s1+=st = ''.join(map(str, l)) print(s1)
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 from itertools import combinations s=input() s1='' a=combinations(s,len(s)-1) l=max(a) s1+=st = ''.join(map(str, l)) print(s1) ```
-1
599
A
Patrick and Shopping
PROGRAMMING
800
[ "implementation" ]
null
null
Today Patrick waits for a visit from his friend Spongebob. To prepare for the visit, Patrick needs to buy some goodies in two stores located near his house. There is a *d*1 meter long road between his house and the first shop and a *d*2 meter long road between his house and the second shop. Also, there is a road of length *d*3 directly connecting these two shops to each other. Help Patrick calculate the minimum distance that he needs to walk in order to go to both shops and return to his house. Patrick always starts at his house. He should visit both shops moving only along the three existing roads and return back to his house. He doesn't mind visiting the same shop or passing the same road multiple times. The only goal is to minimize the total distance traveled.
The first line of the input contains three integers *d*1, *d*2, *d*3 (1<=≤<=*d*1,<=*d*2,<=*d*3<=≤<=108) — the lengths of the paths. - *d*1 is the length of the path connecting Patrick's house and the first shop; - *d*2 is the length of the path connecting Patrick's house and the second shop; - *d*3 is the length of the path connecting both shops.
Print the minimum distance that Patrick will have to walk in order to visit both shops and return to his house.
[ "10 20 30\n", "1 1 5\n" ]
[ "60\n", "4\n" ]
The first sample is shown on the picture in the problem statement. One of the optimal routes is: house <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> first shop <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> second shop <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> house. In the second sample one of the optimal routes is: house <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> first shop <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> house <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> second shop <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> house.
500
[ { "input": "10 20 30", "output": "60" }, { "input": "1 1 5", "output": "4" }, { "input": "100 33 34", "output": "134" }, { "input": "777 777 777", "output": "2331" }, { "input": "2 2 8", "output": "8" }, { "input": "12 34 56", "output": "92" }, { "input": "789 101112 131415", "output": "203802" }, { "input": "27485716 99999999 35182", "output": "55041796" }, { "input": "1 293548 5", "output": "12" }, { "input": "12059 259855 5874875", "output": "543828" }, { "input": "46981 105809 585858", "output": "305580" }, { "input": "9889 1221 2442", "output": "7326" }, { "input": "100500 200600 300700", "output": "601800" }, { "input": "318476 318476 318476", "output": "955428" }, { "input": "23985 3353 75633", "output": "54676" }, { "input": "120 1298 2222", "output": "2836" }, { "input": "98437 23487 666672", "output": "243848" }, { "input": "100000000 100000000 100000000", "output": "300000000" }, { "input": "2 5 2", "output": "8" }, { "input": "1 1000 1", "output": "4" }, { "input": "1 100000000 1", "output": "4" } ]
1,689,647,624
2,147,483,647
Python 3
RUNTIME_ERROR
TESTS
0
46
0
x = int( input() ) b = int( input() ) c = int( input() ) if x == b: print (2*(x+b)) elif b == c: print (x+b+c) elif x == c: print (2*(x+b)) else: print (x+b+c)
Title: Patrick and Shopping Time Limit: None seconds Memory Limit: None megabytes Problem Description: Today Patrick waits for a visit from his friend Spongebob. To prepare for the visit, Patrick needs to buy some goodies in two stores located near his house. There is a *d*1 meter long road between his house and the first shop and a *d*2 meter long road between his house and the second shop. Also, there is a road of length *d*3 directly connecting these two shops to each other. Help Patrick calculate the minimum distance that he needs to walk in order to go to both shops and return to his house. Patrick always starts at his house. He should visit both shops moving only along the three existing roads and return back to his house. He doesn't mind visiting the same shop or passing the same road multiple times. The only goal is to minimize the total distance traveled. Input Specification: The first line of the input contains three integers *d*1, *d*2, *d*3 (1<=≤<=*d*1,<=*d*2,<=*d*3<=≤<=108) — the lengths of the paths. - *d*1 is the length of the path connecting Patrick's house and the first shop; - *d*2 is the length of the path connecting Patrick's house and the second shop; - *d*3 is the length of the path connecting both shops. Output Specification: Print the minimum distance that Patrick will have to walk in order to visit both shops and return to his house. Demo Input: ['10 20 30\n', '1 1 5\n'] Demo Output: ['60\n', '4\n'] Note: The first sample is shown on the picture in the problem statement. One of the optimal routes is: house <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> first shop <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> second shop <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> house. In the second sample one of the optimal routes is: house <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> first shop <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> house <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> second shop <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> house.
```python x = int( input() ) b = int( input() ) c = int( input() ) if x == b: print (2*(x+b)) elif b == c: print (x+b+c) elif x == c: print (2*(x+b)) else: print (x+b+c) ```
-1
115
A
Party
PROGRAMMING
900
[ "dfs and similar", "graphs", "trees" ]
null
null
A company has *n* employees numbered from 1 to *n*. Each employee either has no immediate manager or exactly one immediate manager, who is another employee with a different number. An employee *A* is said to be the superior of another employee *B* if at least one of the following is true: - Employee *A* is the immediate manager of employee *B* - Employee *B* has an immediate manager employee *C* such that employee *A* is the superior of employee *C*. The company will not have a managerial cycle. That is, there will not exist an employee who is the superior of his/her own immediate manager. Today the company is going to arrange a party. This involves dividing all *n* employees into several groups: every employee must belong to exactly one group. Furthermore, within any single group, there must not be two employees *A* and *B* such that *A* is the superior of *B*. What is the minimum number of groups that must be formed?
The first line contains integer *n* (1<=≤<=*n*<=≤<=2000) — the number of employees. The next *n* lines contain the integers *p**i* (1<=≤<=*p**i*<=≤<=*n* or *p**i*<==<=-1). Every *p**i* denotes the immediate manager for the *i*-th employee. If *p**i* is -1, that means that the *i*-th employee does not have an immediate manager. It is guaranteed, that no employee will be the immediate manager of him/herself (*p**i*<=≠<=*i*). Also, there will be no managerial cycles.
Print a single integer denoting the minimum number of groups that will be formed in the party.
[ "5\n-1\n1\n2\n1\n-1\n" ]
[ "3\n" ]
For the first example, three groups are sufficient, for example: - Employee 1 - Employees 2 and 4 - Employees 3 and 5
500
[ { "input": "5\n-1\n1\n2\n1\n-1", "output": "3" }, { "input": "4\n-1\n1\n2\n3", "output": "4" }, { "input": "12\n-1\n1\n2\n3\n-1\n5\n6\n7\n-1\n9\n10\n11", "output": "4" }, { "input": "6\n-1\n-1\n2\n3\n1\n1", "output": "3" }, { "input": "3\n-1\n1\n1", "output": "2" }, { "input": "1\n-1", "output": "1" }, { "input": "2\n2\n-1", "output": "2" }, { "input": "2\n-1\n-1", "output": "1" }, { "input": "3\n2\n-1\n1", "output": "3" }, { "input": "3\n-1\n-1\n-1", "output": "1" }, { "input": "5\n4\n5\n1\n-1\n4", "output": "3" }, { "input": "12\n-1\n1\n1\n1\n1\n1\n3\n4\n3\n3\n4\n7", "output": "4" }, { "input": "12\n-1\n-1\n1\n-1\n1\n1\n5\n11\n8\n6\n6\n4", "output": "5" }, { "input": "12\n-1\n-1\n-1\n-1\n-1\n-1\n-1\n-1\n2\n-1\n-1\n-1", "output": "2" }, { "input": "12\n-1\n-1\n-1\n-1\n-1\n-1\n-1\n-1\n-1\n-1\n-1\n-1", "output": "1" }, { "input": "12\n3\n4\n2\n8\n7\n1\n10\n12\n5\n-1\n9\n11", "output": "12" }, { "input": "12\n5\n6\n7\n1\n-1\n9\n12\n4\n8\n-1\n3\n2", "output": "11" }, { "input": "12\n-1\n9\n11\n6\n6\n-1\n6\n3\n8\n6\n1\n6", "output": "6" }, { "input": "12\n7\n8\n4\n12\n7\n9\n-1\n-1\n-1\n8\n6\n-1", "output": "3" }, { "input": "12\n-1\n10\n-1\n1\n-1\n5\n9\n12\n-1\n-1\n3\n-1", "output": "2" }, { "input": "12\n-1\n7\n9\n12\n1\n7\n-1\n-1\n8\n5\n4\n-1", "output": "3" }, { "input": "12\n11\n11\n8\n9\n1\n1\n2\n-1\n10\n3\n-1\n8", "output": "5" }, { "input": "12\n-1\n8\n9\n-1\n4\n2\n11\n1\n-1\n6\n-1\n10", "output": "6" }, { "input": "12\n7\n4\n4\n-1\n6\n7\n9\n7\n-1\n7\n4\n1", "output": "4" }, { "input": "12\n-1\n6\n10\n6\n1\n11\n5\n9\n11\n5\n1\n9", "output": "4" }, { "input": "12\n8\n6\n6\n8\n6\n-1\n6\n6\n8\n6\n8\n8", "output": "3" }, { "input": "12\n3\n8\n9\n12\n2\n8\n11\n12\n2\n9\n-1\n11", "output": "7" }, { "input": "7\n7\n6\n-1\n-1\n4\n4\n-1", "output": "3" }, { "input": "77\n53\n-1\n48\n-1\n51\n-1\n54\n43\n70\n19\n64\n31\n45\n58\n6\n61\n41\n56\n34\n-1\n54\n-1\n66\n65\n74\n16\n38\n1\n2\n61\n-1\n34\n-1\n-1\n7\n19\n57\n13\n61\n42\n-1\n34\n65\n16\n31\n61\n6\n5\n34\n15\n-1\n13\n4\n22\n74\n7\n-1\n70\n38\n61\n45\n53\n46\n22\n-1\n65\n34\n19\n43\n48\n33\n58\n36\n-1\n47\n24\n34", "output": "6" }, { "input": "5\n2\n3\n4\n5\n-1", "output": "5" } ]
1,684,717,293
2,147,483,647
PyPy 3-64
OK
TESTS
106
278
4,403,200
n=int(input()); maxx=-1; a=[-1]; for i in range(n): a.append(int(input())); for i in range(1,n+1): j=i;c=1; while(a[j]!=-1):c+=1;j=a[j]; maxx=max(c,maxx); print(maxx);
Title: Party Time Limit: None seconds Memory Limit: None megabytes Problem Description: A company has *n* employees numbered from 1 to *n*. Each employee either has no immediate manager or exactly one immediate manager, who is another employee with a different number. An employee *A* is said to be the superior of another employee *B* if at least one of the following is true: - Employee *A* is the immediate manager of employee *B* - Employee *B* has an immediate manager employee *C* such that employee *A* is the superior of employee *C*. The company will not have a managerial cycle. That is, there will not exist an employee who is the superior of his/her own immediate manager. Today the company is going to arrange a party. This involves dividing all *n* employees into several groups: every employee must belong to exactly one group. Furthermore, within any single group, there must not be two employees *A* and *B* such that *A* is the superior of *B*. What is the minimum number of groups that must be formed? Input Specification: The first line contains integer *n* (1<=≤<=*n*<=≤<=2000) — the number of employees. The next *n* lines contain the integers *p**i* (1<=≤<=*p**i*<=≤<=*n* or *p**i*<==<=-1). Every *p**i* denotes the immediate manager for the *i*-th employee. If *p**i* is -1, that means that the *i*-th employee does not have an immediate manager. It is guaranteed, that no employee will be the immediate manager of him/herself (*p**i*<=≠<=*i*). Also, there will be no managerial cycles. Output Specification: Print a single integer denoting the minimum number of groups that will be formed in the party. Demo Input: ['5\n-1\n1\n2\n1\n-1\n'] Demo Output: ['3\n'] Note: For the first example, three groups are sufficient, for example: - Employee 1 - Employees 2 and 4 - Employees 3 and 5
```python n=int(input()); maxx=-1; a=[-1]; for i in range(n): a.append(int(input())); for i in range(1,n+1): j=i;c=1; while(a[j]!=-1):c+=1;j=a[j]; maxx=max(c,maxx); print(maxx); ```
3