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
25
A
IQ test
PROGRAMMING
1,300
[ "brute force" ]
A. IQ test
2
256
Bob is preparing to pass IQ test. The most frequent task in this test is to find out which one of the given *n* numbers differs from the others. Bob observed that one number usually differs from the others in evenness. Help Bob — to check his answers, he needs a program that among the given *n* numbers finds one that is different in evenness.
The first line contains integer *n* (3<=≤<=*n*<=≤<=100) — amount of numbers in the task. The second line contains *n* space-separated natural numbers, not exceeding 100. It is guaranteed, that exactly one of these numbers differs from the others in evenness.
Output index of number that differs from the others in evenness. Numbers are numbered from 1 in the input order.
[ "5\n2 4 7 8 10\n", "4\n1 2 1 1\n" ]
[ "3\n", "2\n" ]
none
0
[ { "input": "5\n2 4 7 8 10", "output": "3" }, { "input": "4\n1 2 1 1", "output": "2" }, { "input": "3\n1 2 2", "output": "1" }, { "input": "3\n100 99 100", "output": "2" }, { "input": "3\n5 3 2", "output": "3" }, { "input": "4\n43 28 1 91", "output": "2" }, { "input": "4\n75 13 94 77", "output": "3" }, { "input": "4\n97 8 27 3", "output": "2" }, { "input": "10\n95 51 12 91 85 3 1 31 25 7", "output": "3" }, { "input": "20\n88 96 66 51 14 88 2 92 18 72 18 88 20 30 4 82 90 100 24 46", "output": "4" }, { "input": "30\n20 94 56 50 10 98 52 32 14 22 24 60 4 8 98 46 34 68 82 82 98 90 50 20 78 49 52 94 64 36", "output": "26" }, { "input": "50\n79 27 77 57 37 45 27 49 65 33 57 21 71 19 75 85 65 61 23 97 85 9 23 1 9 3 99 77 77 21 79 69 15 37 15 7 93 81 13 89 91 31 45 93 15 97 55 80 85 83", "output": "48" }, { "input": "60\n46 11 73 65 3 69 3 53 43 53 97 47 55 93 31 75 35 3 9 73 23 31 3 81 91 79 61 21 15 11 11 11 81 7 83 75 39 87 83 59 89 55 93 27 49 67 67 29 1 93 11 17 9 19 35 21 63 31 31 25", "output": "1" }, { "input": "70\n28 42 42 92 64 54 22 38 38 78 62 38 4 38 14 66 4 92 66 58 94 26 4 44 41 88 48 82 44 26 74 44 48 4 16 92 34 38 26 64 94 4 30 78 50 54 12 90 8 16 80 98 28 100 74 50 36 42 92 18 76 98 8 22 2 50 58 50 64 46", "output": "25" }, { "input": "100\n43 35 79 53 13 91 91 45 65 83 57 9 42 39 85 45 71 51 61 59 31 13 63 39 25 21 79 39 91 67 21 61 97 75 93 83 29 79 59 97 11 37 63 51 39 55 91 23 21 17 47 23 35 75 49 5 69 99 5 7 41 17 25 89 15 79 21 63 53 81 43 91 59 91 69 99 85 15 91 51 49 37 65 7 89 81 21 93 61 63 97 93 45 17 13 69 57 25 75 73", "output": "13" }, { "input": "100\n50 24 68 60 70 30 52 22 18 74 68 98 20 82 4 46 26 68 100 78 84 58 74 98 38 88 68 86 64 80 82 100 20 22 98 98 52 6 94 10 48 68 2 18 38 22 22 82 44 20 66 72 36 58 64 6 36 60 4 96 76 64 12 90 10 58 64 60 74 28 90 26 24 60 40 58 2 16 76 48 58 36 82 60 24 44 4 78 28 38 8 12 40 16 38 6 66 24 31 76", "output": "99" }, { "input": "100\n47 48 94 48 14 18 94 36 96 22 12 30 94 20 48 98 40 58 2 94 8 36 98 18 98 68 2 60 76 38 18 100 8 72 100 68 2 86 92 72 58 16 48 14 6 58 72 76 6 88 80 66 20 28 74 62 86 68 90 86 2 56 34 38 56 90 4 8 76 44 32 86 12 98 38 34 54 92 70 94 10 24 82 66 90 58 62 2 32 58 100 22 58 72 2 22 68 72 42 14", "output": "1" }, { "input": "99\n38 20 68 60 84 16 28 88 60 48 80 28 4 92 70 60 46 46 20 34 12 100 76 2 40 10 8 86 6 80 50 66 12 34 14 28 26 70 46 64 34 96 10 90 98 96 56 88 50 74 70 94 2 94 24 66 68 46 22 30 6 10 64 32 88 14 98 100 64 58 50 18 50 50 8 38 8 16 54 2 60 54 62 84 92 98 4 72 66 26 14 88 99 16 10 6 88 56 22", "output": "93" }, { "input": "99\n50 83 43 89 53 47 69 1 5 37 63 87 95 15 55 95 75 89 33 53 89 75 93 75 11 85 49 29 11 97 49 67 87 11 25 37 97 73 67 49 87 43 53 97 43 29 53 33 45 91 37 73 39 49 59 5 21 43 87 35 5 63 89 57 63 47 29 99 19 85 13 13 3 13 43 19 5 9 61 51 51 57 15 89 13 97 41 13 99 79 13 27 97 95 73 33 99 27 23", "output": "1" }, { "input": "98\n61 56 44 30 58 14 20 24 88 28 46 56 96 52 58 42 94 50 46 30 46 80 72 88 68 16 6 60 26 90 10 98 76 20 56 40 30 16 96 20 88 32 62 30 74 58 36 76 60 4 24 36 42 54 24 92 28 14 2 74 86 90 14 52 34 82 40 76 8 64 2 56 10 8 78 16 70 86 70 42 70 74 22 18 76 98 88 28 62 70 36 72 20 68 34 48 80 98", "output": "1" }, { "input": "98\n66 26 46 42 78 32 76 42 26 82 8 12 4 10 24 26 64 44 100 46 94 64 30 18 88 28 8 66 30 82 82 28 74 52 62 80 80 60 94 86 64 32 44 88 92 20 12 74 94 28 34 58 4 22 16 10 94 76 82 58 40 66 22 6 30 32 92 54 16 76 74 98 18 48 48 30 92 2 16 42 84 74 30 60 64 52 50 26 16 86 58 96 79 60 20 62 82 94", "output": "93" }, { "input": "95\n9 31 27 93 17 77 75 9 9 53 89 39 51 99 5 1 11 39 27 49 91 17 27 79 81 71 37 75 35 13 93 4 99 55 85 11 23 57 5 43 5 61 15 35 23 91 3 81 99 85 43 37 39 27 5 67 7 33 75 59 13 71 51 27 15 93 51 63 91 53 43 99 25 47 17 71 81 15 53 31 59 83 41 23 73 25 91 91 13 17 25 13 55 57 29", "output": "32" }, { "input": "100\n91 89 81 45 53 1 41 3 77 93 55 97 55 97 87 27 69 95 73 41 93 21 75 35 53 56 5 51 87 59 91 67 33 3 99 45 83 17 97 47 75 97 7 89 17 99 23 23 81 25 55 97 27 35 69 5 77 35 93 19 55 59 37 21 31 37 49 41 91 53 73 69 7 37 37 39 17 71 7 97 55 17 47 23 15 73 31 39 57 37 9 5 61 41 65 57 77 79 35 47", "output": "26" }, { "input": "99\n38 56 58 98 80 54 26 90 14 16 78 92 52 74 40 30 84 14 44 80 16 90 98 68 26 24 78 72 42 16 84 40 14 44 2 52 50 2 12 96 58 66 8 80 44 52 34 34 72 98 74 4 66 74 56 21 8 38 76 40 10 22 48 32 98 34 12 62 80 68 64 82 22 78 58 74 20 22 48 56 12 38 32 72 6 16 74 24 94 84 26 38 18 24 76 78 98 94 72", "output": "56" }, { "input": "100\n44 40 6 40 56 90 98 8 36 64 76 86 98 76 36 92 6 30 98 70 24 98 96 60 24 82 88 68 86 96 34 42 58 10 40 26 56 10 88 58 70 32 24 28 14 82 52 12 62 36 70 60 52 34 74 30 78 76 10 16 42 94 66 90 70 38 52 12 58 22 98 96 14 68 24 70 4 30 84 98 8 50 14 52 66 34 100 10 28 100 56 48 38 12 38 14 91 80 70 86", "output": "97" }, { "input": "100\n96 62 64 20 90 46 56 90 68 36 30 56 70 28 16 64 94 34 6 32 34 50 94 22 90 32 40 2 72 10 88 38 28 92 20 26 56 80 4 100 100 90 16 74 74 84 8 2 30 20 80 32 16 46 92 56 42 12 96 64 64 42 64 58 50 42 74 28 2 4 36 32 70 50 54 92 70 16 45 76 28 16 18 50 48 2 62 94 4 12 52 52 4 100 70 60 82 62 98 42", "output": "79" }, { "input": "99\n14 26 34 68 90 58 50 36 8 16 18 6 2 74 54 20 36 84 32 50 52 2 26 24 3 64 20 10 54 26 66 44 28 72 4 96 78 90 96 86 68 28 94 4 12 46 100 32 22 36 84 32 44 94 76 94 4 52 12 30 74 4 34 64 58 72 44 16 70 56 54 8 14 74 8 6 58 62 98 54 14 40 80 20 36 72 28 98 20 58 40 52 90 64 22 48 54 70 52", "output": "25" }, { "input": "95\n82 86 30 78 6 46 80 66 74 72 16 24 18 52 52 38 60 36 86 26 62 28 22 46 96 26 94 84 20 46 66 88 76 32 12 86 74 18 34 88 4 48 94 6 58 6 100 82 4 24 88 32 54 98 34 48 6 76 42 88 42 28 100 4 22 2 10 66 82 54 98 20 60 66 38 98 32 47 86 58 6 100 12 46 2 42 8 84 78 28 24 70 34 28 86", "output": "78" }, { "input": "90\n40 50 8 42 76 24 58 42 26 68 20 48 54 12 34 84 14 36 32 88 6 50 96 56 20 92 48 16 40 34 96 46 20 84 30 50 20 98 8 44 96 42 8 76 70 38 84 30 40 88 84 72 2 22 52 58 16 62 100 66 80 40 50 32 14 62 88 72 22 99 76 50 84 82 8 82 98 46 26 40 2 98 18 78 30 72 70 18 34 68", "output": "70" }, { "input": "80\n81 43 87 1 55 43 53 61 27 19 43 13 89 9 33 83 75 55 97 71 91 37 95 5 21 69 81 93 95 69 31 83 55 7 97 7 79 57 8 61 27 85 49 1 15 97 63 79 29 73 41 85 5 41 31 93 67 11 63 59 15 99 91 77 43 69 23 23 81 73 19 1 67 51 1 75 99 67 3 81", "output": "39" }, { "input": "98\n13 83 61 27 35 1 85 95 97 73 95 65 73 45 5 43 27 83 91 19 11 3 85 59 9 39 69 23 45 7 51 85 5 71 5 95 1 51 75 3 43 57 3 11 33 71 21 99 47 41 87 39 71 87 31 85 91 49 83 5 49 85 47 91 55 99 33 23 31 23 23 73 29 77 55 31 25 5 81 49 91 15 15 39 87 5 9 40 69 47 29 33 11 21 49 79 51 83", "output": "88" }, { "input": "3\n100 100 1", "output": "3" } ]
1,658,478,678
2,147,483,647
PyPy 3-64
OK
TESTS
32
124
0
n=int(input()) a=list(map(int, input().split())) c="" for i in a: if i%2==0: c+="0" else: c+="1" zhup=c.count("0") tak=c.count("1") if zhup> tak: print(c.index("1")+1) else: print(c.index("0")+1)
Title: IQ test Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: Bob is preparing to pass IQ test. The most frequent task in this test is to find out which one of the given *n* numbers differs from the others. Bob observed that one number usually differs from the others in evenness. Help Bob — to check his answers, he needs a program that among the given *n* numbers finds one that is different in evenness. Input Specification: The first line contains integer *n* (3<=≤<=*n*<=≤<=100) — amount of numbers in the task. The second line contains *n* space-separated natural numbers, not exceeding 100. It is guaranteed, that exactly one of these numbers differs from the others in evenness. Output Specification: Output index of number that differs from the others in evenness. Numbers are numbered from 1 in the input order. Demo Input: ['5\n2 4 7 8 10\n', '4\n1 2 1 1\n'] Demo Output: ['3\n', '2\n'] Note: none
```python n=int(input()) a=list(map(int, input().split())) c="" for i in a: if i%2==0: c+="0" else: c+="1" zhup=c.count("0") tak=c.count("1") if zhup> tak: print(c.index("1")+1) else: print(c.index("0")+1) ```
3.969
152
A
Marks
PROGRAMMING
900
[ "implementation" ]
null
null
Vasya, or Mr. Vasily Petrov is a dean of a department in a local university. After the winter exams he got his hands on a group's gradebook. Overall the group has *n* students. They received marks for *m* subjects. Each student got a mark from 1 to 9 (inclusive) for each subject. Let's consider a student the best at some subject, if there is no student who got a higher mark for this subject. Let's consider a student successful, if there exists a subject he is the best at. Your task is to find the number of successful students in the group.
The first input line contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=100) — the number of students and the number of subjects, correspondingly. Next *n* lines each containing *m* characters describe the gradebook. Each character in the gradebook is a number from 1 to 9. Note that the marks in a rows are not sepatated by spaces.
Print the single number — the number of successful students in the given group.
[ "3 3\n223\n232\n112\n", "3 5\n91728\n11828\n11111\n" ]
[ "2\n", "3\n" ]
In the first sample test the student number 1 is the best at subjects 1 and 3, student 2 is the best at subjects 1 and 2, but student 3 isn't the best at any subject. In the second sample test each student is the best at at least one subject.
500
[ { "input": "3 3\n223\n232\n112", "output": "2" }, { "input": "3 5\n91728\n11828\n11111", "output": "3" }, { "input": "2 2\n48\n27", "output": "1" }, { "input": "2 1\n4\n6", "output": "1" }, { "input": "1 2\n57", "output": "1" }, { "input": "1 1\n5", "output": "1" }, { "input": "3 4\n2553\n6856\n5133", "output": "2" }, { "input": "8 7\n6264676\n7854895\n3244128\n2465944\n8958761\n1378945\n3859353\n6615285", "output": "6" }, { "input": "9 8\n61531121\n43529859\n18841327\n88683622\n98995641\n62741632\n57441743\n49396792\n63381994", "output": "4" }, { "input": "10 20\n26855662887514171367\n48525577498621511535\n47683778377545341138\n47331616748732562762\n44876938191354974293\n24577238399664382695\n42724955594463126746\n79187344479926159359\n48349683283914388185\n82157191115518781898", "output": "9" }, { "input": "20 15\n471187383859588\n652657222494199\n245695867594992\n726154672861295\n614617827782772\n862889444974692\n373977167653235\n645434268565473\n785993468314573\n722176861496755\n518276853323939\n723712762593348\n728935312568886\n373898548522463\n769777587165681\n247592995114377\n182375946483965\n497496542536127\n988239919677856\n859844339819143", "output": "18" }, { "input": "13 9\n514562255\n322655246\n135162979\n733845982\n473117129\n513967187\n965649829\n799122777\n661249521\n298618978\n659352422\n747778378\n723261619", "output": "11" }, { "input": "75 1\n2\n3\n8\n3\n2\n1\n3\n1\n5\n1\n5\n4\n8\n8\n4\n2\n5\n1\n7\n6\n3\n2\n2\n3\n5\n5\n2\n4\n7\n7\n9\n2\n9\n5\n1\n4\n9\n5\n2\n4\n6\n6\n3\n3\n9\n3\n3\n2\n3\n4\n2\n6\n9\n1\n1\n1\n1\n7\n2\n3\n2\n9\n7\n4\n9\n1\n7\n5\n6\n8\n3\n4\n3\n4\n6", "output": "7" }, { "input": "92 3\n418\n665\n861\n766\n529\n416\n476\n676\n561\n995\n415\n185\n291\n176\n776\n631\n556\n488\n118\n188\n437\n496\n466\n131\n914\n118\n766\n365\n113\n897\n386\n639\n276\n946\n759\n169\n494\n837\n338\n351\n783\n311\n261\n862\n598\n132\n246\n982\n575\n364\n615\n347\n374\n368\n523\n132\n774\n161\n552\n492\n598\n474\n639\n681\n635\n342\n516\n483\n141\n197\n571\n336\n175\n596\n481\n327\n841\n133\n142\n146\n246\n396\n287\n582\n556\n996\n479\n814\n497\n363\n963\n162", "output": "23" }, { "input": "100 1\n1\n6\n9\n1\n1\n5\n5\n4\n6\n9\n6\n1\n7\n8\n7\n3\n8\n8\n7\n6\n2\n1\n5\n8\n7\n3\n5\n4\n9\n7\n1\n2\n4\n1\n6\n5\n1\n3\n9\n4\n5\n8\n1\n2\n1\n9\n7\n3\n7\n1\n2\n2\n2\n2\n3\n9\n7\n2\n4\n7\n1\n6\n8\n1\n5\n6\n1\n1\n2\n9\n7\n4\n9\n1\n9\n4\n1\n3\n5\n2\n4\n4\n6\n5\n1\n4\n5\n8\n4\n7\n6\n5\n6\n9\n5\n8\n1\n5\n1\n6", "output": "10" }, { "input": "100 2\n71\n87\n99\n47\n22\n87\n49\n73\n21\n12\n77\n43\n18\n41\n78\n62\n61\n16\n64\n89\n81\n54\n53\n92\n93\n94\n68\n93\n15\n68\n42\n93\n28\n19\n86\n16\n97\n17\n11\n43\n72\n76\n54\n95\n58\n53\n48\n45\n85\n85\n74\n21\n44\n51\n89\n75\n76\n17\n38\n62\n81\n22\n66\n59\n89\n85\n91\n87\n12\n97\n52\n87\n43\n89\n51\n58\n57\n98\n78\n68\n82\n41\n87\n29\n75\n72\n48\n14\n35\n71\n74\n91\n66\n67\n42\n98\n52\n54\n22\n41", "output": "21" }, { "input": "5 20\n11111111111111111111\n11111111111111111111\n11111111111111111111\n99999999999999999999\n11111111111111111119", "output": "2" }, { "input": "3 3\n111\n111\n999", "output": "1" }, { "input": "3 3\n119\n181\n711", "output": "3" }, { "input": "15 5\n91728\n11828\n11111\n91728\n11828\n11111\n91728\n11828\n11111\n91728\n11828\n11111\n91728\n11828\n11111", "output": "15" }, { "input": "2 20\n22222222222222222222\n11111111111111111111", "output": "1" }, { "input": "3 3\n233\n222\n111", "output": "2" }, { "input": "4 15\n222222222222222\n111111111111119\n111111111111119\n111111111111111", "output": "3" }, { "input": "4 1\n1\n9\n9\n9", "output": "3" }, { "input": "3 3\n123\n321\n132", "output": "3" }, { "input": "3 3\n113\n332\n322", "output": "3" }, { "input": "2 100\n2222222222222222222222222222222222222222222222222222222222222222222222221222222222222222222222222222\n1111111111111111111111111111111111111111111111111111111111111111111111119111111111111111111111111111", "output": "2" }, { "input": "3 3\n321\n231\n123", "output": "3" }, { "input": "2 100\n1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111\n2222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222", "output": "1" }, { "input": "3 3\n221\n111\n111", "output": "3" } ]
1,673,281,281
2,147,483,647
PyPy 3-64
OK
TESTS
44
218
8,908,800
import sys,math def get_ints(): return map(int, sys.stdin.readline().strip().split()) def get_list(): return list(map(int, sys.stdin.readline().strip().split())) def get_string(): return sys.stdin.readline().strip() n,m = get_ints() ar = [0]*n L = [] for i in range(n): s = get_string() L.append(s) for j in range(m): mx = 0 for i in range(n): mx = max(mx,eval(L[i][j])) for i in range(n): if mx==eval(L[i][j]): ar[i]=1 print(sum(ar))
Title: Marks Time Limit: None seconds Memory Limit: None megabytes Problem Description: Vasya, or Mr. Vasily Petrov is a dean of a department in a local university. After the winter exams he got his hands on a group's gradebook. Overall the group has *n* students. They received marks for *m* subjects. Each student got a mark from 1 to 9 (inclusive) for each subject. Let's consider a student the best at some subject, if there is no student who got a higher mark for this subject. Let's consider a student successful, if there exists a subject he is the best at. Your task is to find the number of successful students in the group. Input Specification: The first input line contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=100) — the number of students and the number of subjects, correspondingly. Next *n* lines each containing *m* characters describe the gradebook. Each character in the gradebook is a number from 1 to 9. Note that the marks in a rows are not sepatated by spaces. Output Specification: Print the single number — the number of successful students in the given group. Demo Input: ['3 3\n223\n232\n112\n', '3 5\n91728\n11828\n11111\n'] Demo Output: ['2\n', '3\n'] Note: In the first sample test the student number 1 is the best at subjects 1 and 3, student 2 is the best at subjects 1 and 2, but student 3 isn't the best at any subject. In the second sample test each student is the best at at least one subject.
```python import sys,math def get_ints(): return map(int, sys.stdin.readline().strip().split()) def get_list(): return list(map(int, sys.stdin.readline().strip().split())) def get_string(): return sys.stdin.readline().strip() n,m = get_ints() ar = [0]*n L = [] for i in range(n): s = get_string() L.append(s) for j in range(m): mx = 0 for i in range(n): mx = max(mx,eval(L[i][j])) for i in range(n): if mx==eval(L[i][j]): ar[i]=1 print(sum(ar)) ```
3
371
B
Fox Dividing Cheese
PROGRAMMING
1,300
[ "math", "number theory" ]
null
null
Two little greedy bears have found two pieces of cheese in the forest of weight *a* and *b* grams, correspondingly. The bears are so greedy that they are ready to fight for the larger piece. That's where the fox comes in and starts the dialog: "Little bears, wait a little, I want to make your pieces equal" "Come off it fox, how are you going to do that?", the curious bears asked. "It's easy", said the fox. "If the mass of a certain piece is divisible by two, then I can eat exactly a half of the piece. If the mass of a certain piece is divisible by three, then I can eat exactly two-thirds, and if the mass is divisible by five, then I can eat four-fifths. I'll eat a little here and there and make the pieces equal". The little bears realize that the fox's proposal contains a catch. But at the same time they realize that they can not make the two pieces equal themselves. So they agreed to her proposal, but on one condition: the fox should make the pieces equal as quickly as possible. Find the minimum number of operations the fox needs to make pieces equal.
The first line contains two space-separated integers *a* and *b* (1<=≤<=*a*,<=*b*<=≤<=109).
If the fox is lying to the little bears and it is impossible to make the pieces equal, print -1. Otherwise, print the required minimum number of operations. If the pieces of the cheese are initially equal, the required number is 0.
[ "15 20\n", "14 8\n", "6 6\n" ]
[ "3\n", "-1\n", "0\n" ]
none
1,000
[ { "input": "15 20", "output": "3" }, { "input": "14 8", "output": "-1" }, { "input": "6 6", "output": "0" }, { "input": "1 1", "output": "0" }, { "input": "1 1024", "output": "10" }, { "input": "1024 729", "output": "16" }, { "input": "1024 1048576", "output": "10" }, { "input": "36 30", "output": "3" }, { "input": "100 10", "output": "2" }, { "input": "21 35", "output": "2" }, { "input": "9900 7128", "output": "5" }, { "input": "7920 9900", "output": "3" }, { "input": "576000 972000", "output": "7" }, { "input": "691200 583200", "output": "8" }, { "input": "607500 506250", "output": "3" }, { "input": "881280 765000", "output": "9" }, { "input": "800000 729000", "output": "13" }, { "input": "792000 792000", "output": "0" }, { "input": "513600 513600", "output": "0" }, { "input": "847500 610200", "output": "5" }, { "input": "522784320 784176480", "output": "2" }, { "input": "689147136 861433920", "output": "3" }, { "input": "720212000 864254400", "output": "3" }, { "input": "673067520 807681024", "output": "3" }, { "input": "919536000 993098880", "output": "5" }, { "input": "648293430 540244525", "output": "3" }, { "input": "537814642 537814642", "output": "0" }, { "input": "100000007 800000011", "output": "-1" }, { "input": "900000011 800000011", "output": "-1" }, { "input": "900000011 999900017", "output": "-1" }, { "input": "536870912 387420489", "output": "47" }, { "input": "820125000 874800000", "output": "6" }, { "input": "864000000 607500000", "output": "9" }, { "input": "609120000 913680000", "output": "2" }, { "input": "509607936 306110016", "output": "24" }, { "input": "445906944 528482304", "output": "8" }, { "input": "119144448 423624704", "output": "7" }, { "input": "1 1000000000", "output": "18" }, { "input": "1000000000 1", "output": "18" }, { "input": "1000000000 2", "output": "17" }, { "input": "2 1000000000", "output": "17" }, { "input": "5 1000000000", "output": "17" }, { "input": "1000000000 5", "output": "17" }, { "input": "3 1000000000", "output": "19" }, { "input": "1000000000 3", "output": "19" }, { "input": "1000000000 7", "output": "-1" }, { "input": "2208870 122715", "output": "3" }, { "input": "4812500 7577955", "output": "16" }, { "input": "3303936 3097440", "output": "6" }, { "input": "55404 147744", "output": "4" }, { "input": "10332160 476643528", "output": "19" }, { "input": "21751200 43502400", "output": "1" }, { "input": "19500000 140400000", "output": "5" }, { "input": "1 22", "output": "-1" } ]
1,641,490,794
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
5
46
0
a,b=map(int,input().split()) moves = 0 while a!=b and a!=0 and b!=0: moves += 1 if a%2==0: a//=2 if b%2==0: b//=2 elif b%3==0: b//=3 elif b%5==0: b//=5 elif b==1: continue else: break elif a%3==0: a//=3 if b%2==0: b//=2 elif b%3==0: b//=3 elif b%5==0: b//=5 elif b==1: continue else: break elif a%5==0: a//=5 if b%2==0: b//=2 elif b%3==0: b//=3 elif b%5==0: b//=5 elif b==1: continue else: break elif a==1: if b%2==0: b//=2 elif b%3==0: b//=3 elif b%5==0: b//=5 elif b==1: continue else: break else: break if a==b!=0: print(moves) else: print(-1)
Title: Fox Dividing Cheese Time Limit: None seconds Memory Limit: None megabytes Problem Description: Two little greedy bears have found two pieces of cheese in the forest of weight *a* and *b* grams, correspondingly. The bears are so greedy that they are ready to fight for the larger piece. That's where the fox comes in and starts the dialog: "Little bears, wait a little, I want to make your pieces equal" "Come off it fox, how are you going to do that?", the curious bears asked. "It's easy", said the fox. "If the mass of a certain piece is divisible by two, then I can eat exactly a half of the piece. If the mass of a certain piece is divisible by three, then I can eat exactly two-thirds, and if the mass is divisible by five, then I can eat four-fifths. I'll eat a little here and there and make the pieces equal". The little bears realize that the fox's proposal contains a catch. But at the same time they realize that they can not make the two pieces equal themselves. So they agreed to her proposal, but on one condition: the fox should make the pieces equal as quickly as possible. Find the minimum number of operations the fox needs to make pieces equal. Input Specification: The first line contains two space-separated integers *a* and *b* (1<=≤<=*a*,<=*b*<=≤<=109). Output Specification: If the fox is lying to the little bears and it is impossible to make the pieces equal, print -1. Otherwise, print the required minimum number of operations. If the pieces of the cheese are initially equal, the required number is 0. Demo Input: ['15 20\n', '14 8\n', '6 6\n'] Demo Output: ['3\n', '-1\n', '0\n'] Note: none
```python a,b=map(int,input().split()) moves = 0 while a!=b and a!=0 and b!=0: moves += 1 if a%2==0: a//=2 if b%2==0: b//=2 elif b%3==0: b//=3 elif b%5==0: b//=5 elif b==1: continue else: break elif a%3==0: a//=3 if b%2==0: b//=2 elif b%3==0: b//=3 elif b%5==0: b//=5 elif b==1: continue else: break elif a%5==0: a//=5 if b%2==0: b//=2 elif b%3==0: b//=3 elif b%5==0: b//=5 elif b==1: continue else: break elif a==1: if b%2==0: b//=2 elif b%3==0: b//=3 elif b%5==0: b//=5 elif b==1: continue else: break else: break if a==b!=0: print(moves) else: print(-1) ```
0
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,518,203,982
2,147,483,647
Python 3
OK
TESTS
44
61
5,632,000
n,k=map(int,input().split()) d=(n//2)//(k+1) c=k*d l=n-c-d print(str(d)+" "+str(c)+" "+str(l))
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=map(int,input().split()) d=(n//2)//(k+1) c=k*d l=n-c-d print(str(d)+" "+str(c)+" "+str(l)) ```
3
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,606,459,997
2,147,483,647
PyPy 3
OK
TESTS
21
124
0
def good(a,b,c): return min(a,b+c)+min(c,a+b)+min(b,a+c) a,b,c=map(int,input().split()) print(good(a, 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 def good(a,b,c): return min(a,b+c)+min(c,a+b)+min(b,a+c) a,b,c=map(int,input().split()) print(good(a, b, c)) ```
3
281
A
Word Capitalization
PROGRAMMING
800
[ "implementation", "strings" ]
null
null
Capitalization is writing a word with its first letter as a capital letter. Your task is to capitalize the given word. Note, that during capitalization all the letters except the first one remains unchanged.
A single line contains a non-empty word. This word consists of lowercase and uppercase English letters. The length of the word will not exceed 103.
Output the given word after capitalization.
[ "ApPLe\n", "konjac\n" ]
[ "ApPLe\n", "Konjac\n" ]
none
500
[ { "input": "ApPLe", "output": "ApPLe" }, { "input": "konjac", "output": "Konjac" }, { "input": "a", "output": "A" }, { "input": "A", "output": "A" }, { "input": "z", "output": "Z" }, { "input": "ABACABA", "output": "ABACABA" }, { "input": "xYaPxPxHxGePfGtQySlNrLxSjDtNnTaRaEpAhPaQpWnDzMqGgRgEwJxGiBdZnMtHxFbObCaGiCeZkUqIgBhHtNvAqAlHpMnQhNeQbMyZrCdElVwHtKrPpJjIaHuIlYwHaRkAkUpPlOhNlBtXwDsKzPyHrPiUwNlXtTaPuMwTqYtJySgFoXvLiHbQwMjSvXsQfKhVlOxGdQkWjBhEyQvBjPoFkThNeRhTuIzFjInJtEfPjOlOsJpJuLgLzFnZmKvFgFrNsOnVqFcNiMfCqTpKnVyLwNqFiTySpWeTdFnWuTwDkRjVxNyQvTrOoEiExYiFaIrLoFmJfZcDkHuWjYfCeEqCvEsZiWnJaEmFbMjDvYwEeJeGcKbVbChGsIzNlExHzHiTlHcSaKxLuZxX", "output": "XYaPxPxHxGePfGtQySlNrLxSjDtNnTaRaEpAhPaQpWnDzMqGgRgEwJxGiBdZnMtHxFbObCaGiCeZkUqIgBhHtNvAqAlHpMnQhNeQbMyZrCdElVwHtKrPpJjIaHuIlYwHaRkAkUpPlOhNlBtXwDsKzPyHrPiUwNlXtTaPuMwTqYtJySgFoXvLiHbQwMjSvXsQfKhVlOxGdQkWjBhEyQvBjPoFkThNeRhTuIzFjInJtEfPjOlOsJpJuLgLzFnZmKvFgFrNsOnVqFcNiMfCqTpKnVyLwNqFiTySpWeTdFnWuTwDkRjVxNyQvTrOoEiExYiFaIrLoFmJfZcDkHuWjYfCeEqCvEsZiWnJaEmFbMjDvYwEeJeGcKbVbChGsIzNlExHzHiTlHcSaKxLuZxX" }, { "input": "rZhIcQlXpNcPgXrOjTiOlMoTgXgIhCfMwZfWoFzGhEkQlOoMjIuShPlZfWkNnMyQfYdUhVgQuSmYoElEtZpDyHtOxXgCpWbZqSbYnPqBcNqRtPgCnJnAyIvNsAhRbNeVlMwZyRyJnFgIsCnSbOdLvUyIeOzQvRpMoMoHfNhHwKvTcHuYnYySfPmAiNwAiWdZnWlLvGfBbRbRrCrBqIgIdWkWiBsNyYkKdNxZdGaToSsDnXpRaGrKxBpQsCzBdQgZzBkGeHgGxNrIyQlSzWsTmSnZwOcHqQpNcQvJlPvKaPiQaMaYsQjUeCqQdCjPgUbDmWiJmNiXgExLqOcCtSwSePnUxIuZfIfBeWbEiVbXnUsPwWyAiXyRbZgKwOqFfCtQuKxEmVeRlAkOeXkO", "output": "RZhIcQlXpNcPgXrOjTiOlMoTgXgIhCfMwZfWoFzGhEkQlOoMjIuShPlZfWkNnMyQfYdUhVgQuSmYoElEtZpDyHtOxXgCpWbZqSbYnPqBcNqRtPgCnJnAyIvNsAhRbNeVlMwZyRyJnFgIsCnSbOdLvUyIeOzQvRpMoMoHfNhHwKvTcHuYnYySfPmAiNwAiWdZnWlLvGfBbRbRrCrBqIgIdWkWiBsNyYkKdNxZdGaToSsDnXpRaGrKxBpQsCzBdQgZzBkGeHgGxNrIyQlSzWsTmSnZwOcHqQpNcQvJlPvKaPiQaMaYsQjUeCqQdCjPgUbDmWiJmNiXgExLqOcCtSwSePnUxIuZfIfBeWbEiVbXnUsPwWyAiXyRbZgKwOqFfCtQuKxEmVeRlAkOeXkO" }, { "input": "hDgZlUmLhYbLkLcNcKeOwJwTePbOvLaRvNzQbSbLsPeHqLhUqWtUbNdQfQqFfXeJqJwWuOrFnDdZiPxIkDyVmHbHvXfIlFqSgAcSyWbOlSlRuPhWdEpEzEeLnXwCtWuVcHaUeRgCiYsIvOaIgDnFuDbRnMoCmPrZfLeFpSjQaTfHgZwZvAzDuSeNwSoWuJvLqKqAuUxFaCxFfRcEjEsJpOfCtDiVrBqNsNwPuGoRgPzRpLpYnNyQxKaNnDnYiJrCrVcHlOxPiPcDbEgKfLwBjLhKcNeMgJhJmOiJvPfOaPaEuGqWvRbErKrIpDkEoQnKwJnTlStLyNsHyOjZfKoIjXwUvRrWpSyYhRpQdLqGmErAiNcGqAqIrTeTiMuPmCrEkHdBrLyCxPtYpRqD", "output": "HDgZlUmLhYbLkLcNcKeOwJwTePbOvLaRvNzQbSbLsPeHqLhUqWtUbNdQfQqFfXeJqJwWuOrFnDdZiPxIkDyVmHbHvXfIlFqSgAcSyWbOlSlRuPhWdEpEzEeLnXwCtWuVcHaUeRgCiYsIvOaIgDnFuDbRnMoCmPrZfLeFpSjQaTfHgZwZvAzDuSeNwSoWuJvLqKqAuUxFaCxFfRcEjEsJpOfCtDiVrBqNsNwPuGoRgPzRpLpYnNyQxKaNnDnYiJrCrVcHlOxPiPcDbEgKfLwBjLhKcNeMgJhJmOiJvPfOaPaEuGqWvRbErKrIpDkEoQnKwJnTlStLyNsHyOjZfKoIjXwUvRrWpSyYhRpQdLqGmErAiNcGqAqIrTeTiMuPmCrEkHdBrLyCxPtYpRqD" }, { "input": "qUdLgGrJeGmIzIeZrCjUtBpYfRvNdXdRpGsThIsEmJjTiMqEwRxBeBaSxEuWrNvExKePjPnXhPzBpWnHiDhTvZhBuIjDnZpTcEkCvRkAcTmMuXhGgErWgFyGyToOyVwYlCuQpTfJkVdWmFyBqQhJjYtXrBbFdHzDlGsFbHmHbFgXgFhIyDhZyEqEiEwNxSeByBwLiVeSnCxIdHbGjOjJrZeVkOzGeMmQrJkVyGhDtCzOlPeAzGrBlWwEnAdUfVaIjNrRyJjCnHkUvFuKuKeKbLzSbEmUcXtVkZzXzKlOrPgQiDmCcCvIyAdBwOeUuLbRmScNcWxIkOkJuIsBxTrIqXhDzLcYdVtPgZdZfAxTmUtByGiTsJkSySjXdJvEwNmSmNoWsChPdAzJrBoW", "output": "QUdLgGrJeGmIzIeZrCjUtBpYfRvNdXdRpGsThIsEmJjTiMqEwRxBeBaSxEuWrNvExKePjPnXhPzBpWnHiDhTvZhBuIjDnZpTcEkCvRkAcTmMuXhGgErWgFyGyToOyVwYlCuQpTfJkVdWmFyBqQhJjYtXrBbFdHzDlGsFbHmHbFgXgFhIyDhZyEqEiEwNxSeByBwLiVeSnCxIdHbGjOjJrZeVkOzGeMmQrJkVyGhDtCzOlPeAzGrBlWwEnAdUfVaIjNrRyJjCnHkUvFuKuKeKbLzSbEmUcXtVkZzXzKlOrPgQiDmCcCvIyAdBwOeUuLbRmScNcWxIkOkJuIsBxTrIqXhDzLcYdVtPgZdZfAxTmUtByGiTsJkSySjXdJvEwNmSmNoWsChPdAzJrBoW" }, { "input": "kHbApGoBcLmIwUlXkVgUmWzYeLoDbGaOkWbIuXoRwMfKuOoMzAoXrBoTvYxGrMbRjDuRxAbGsTnErIiHnHoLeRnTbFiRfDdOkNlWiAcOsChLdLqFqXlDpDoDtPxXqAmSvYgPvOcCpOlWtOjYwFkGkHuCaHwZcFdOfHjBmIxTeSiHkWjXyFcCtOlSuJsZkDxUgPeZkJwMmNpErUlBcGuMlJwKkWnOzFeFiSiPsEvMmQiCsYeHlLuHoMgBjFoZkXlObDkSoQcVyReTmRsFzRhTuIvCeBqVsQdQyTyZjStGrTyDcEcAgTgMiIcVkLbZbGvWeHtXwEqWkXfTcPyHhHjYwIeVxLyVmHmMkUsGiHmNnQuMsXaFyPpVqNrBhOiWmNkBbQuHvQdOjPjKiZcL", "output": "KHbApGoBcLmIwUlXkVgUmWzYeLoDbGaOkWbIuXoRwMfKuOoMzAoXrBoTvYxGrMbRjDuRxAbGsTnErIiHnHoLeRnTbFiRfDdOkNlWiAcOsChLdLqFqXlDpDoDtPxXqAmSvYgPvOcCpOlWtOjYwFkGkHuCaHwZcFdOfHjBmIxTeSiHkWjXyFcCtOlSuJsZkDxUgPeZkJwMmNpErUlBcGuMlJwKkWnOzFeFiSiPsEvMmQiCsYeHlLuHoMgBjFoZkXlObDkSoQcVyReTmRsFzRhTuIvCeBqVsQdQyTyZjStGrTyDcEcAgTgMiIcVkLbZbGvWeHtXwEqWkXfTcPyHhHjYwIeVxLyVmHmMkUsGiHmNnQuMsXaFyPpVqNrBhOiWmNkBbQuHvQdOjPjKiZcL" }, { "input": "aHmRbLgNuWkLxLnWvUbYwTeZeYiOlLhTuOvKfLnVmCiPcMkSgVrYjZiLuRjCiXhAnVzVcTlVeJdBvPdDfFvHkTuIhCdBjEsXbVmGcLrPfNvRdFsZkSdNpYsJeIhIcNqSoLkOjUlYlDmXsOxPbQtIoUxFjGnRtBhFaJvBeEzHsAtVoQbAfYjJqReBiKeUwRqYrUjPjBoHkOkPzDwEwUgTxQxAvKzUpMhKyOhPmEhYhItQwPeKsKaKlUhGuMcTtSwFtXfJsDsFlTtOjVvVfGtBtFlQyIcBaMsPaJlPqUcUvLmReZiFbXxVtRhTzJkLkAjVqTyVuFeKlTyQgUzMsXjOxQnVfTaWmThEnEoIhZeZdStBkKeLpAhJnFoJvQyGwDiStLjEwGfZwBuWsEfC", "output": "AHmRbLgNuWkLxLnWvUbYwTeZeYiOlLhTuOvKfLnVmCiPcMkSgVrYjZiLuRjCiXhAnVzVcTlVeJdBvPdDfFvHkTuIhCdBjEsXbVmGcLrPfNvRdFsZkSdNpYsJeIhIcNqSoLkOjUlYlDmXsOxPbQtIoUxFjGnRtBhFaJvBeEzHsAtVoQbAfYjJqReBiKeUwRqYrUjPjBoHkOkPzDwEwUgTxQxAvKzUpMhKyOhPmEhYhItQwPeKsKaKlUhGuMcTtSwFtXfJsDsFlTtOjVvVfGtBtFlQyIcBaMsPaJlPqUcUvLmReZiFbXxVtRhTzJkLkAjVqTyVuFeKlTyQgUzMsXjOxQnVfTaWmThEnEoIhZeZdStBkKeLpAhJnFoJvQyGwDiStLjEwGfZwBuWsEfC" }, { "input": "sLlZkDiDmEdNaXuUuJwHqYvRtOdGfTiTpEpAoSqAbJaChOiCvHgSwZwEuPkMmXiLcKdXqSsEyViEbZpZsHeZpTuXoGcRmOiQfBfApPjDqSqElWeSeOhUyWjLyNoRuYeGfGwNqUsQoTyVvWeNgNdZfDxGwGfLsDjIdInSqDlMuNvFaHbScZkTlVwNcJpEjMaPaOtFgJjBjOcLlLmDnQrShIrJhOcUmPnZhTxNeClQsZaEaVaReLyQpLwEqJpUwYhLiRzCzKfOoFeTiXzPiNbOsZaZaLgCiNnMkBcFwGgAwPeNyTxJcCtBgXcToKlWaWcBaIvBpNxPeClQlWeQqRyEtAkJdBtSrFdDvAbUlKyLdCuTtXxFvRcKnYnWzVdYqDeCmOqPxUaFjQdTdCtN", "output": "SLlZkDiDmEdNaXuUuJwHqYvRtOdGfTiTpEpAoSqAbJaChOiCvHgSwZwEuPkMmXiLcKdXqSsEyViEbZpZsHeZpTuXoGcRmOiQfBfApPjDqSqElWeSeOhUyWjLyNoRuYeGfGwNqUsQoTyVvWeNgNdZfDxGwGfLsDjIdInSqDlMuNvFaHbScZkTlVwNcJpEjMaPaOtFgJjBjOcLlLmDnQrShIrJhOcUmPnZhTxNeClQsZaEaVaReLyQpLwEqJpUwYhLiRzCzKfOoFeTiXzPiNbOsZaZaLgCiNnMkBcFwGgAwPeNyTxJcCtBgXcToKlWaWcBaIvBpNxPeClQlWeQqRyEtAkJdBtSrFdDvAbUlKyLdCuTtXxFvRcKnYnWzVdYqDeCmOqPxUaFjQdTdCtN" }, { "input": "iRuStKvVhJdJbQwRoIuLiVdTpKaOqKfYlYwAzIpPtUwUtMeKyCaOlXmVrKwWeImYmVuXdLkRlHwFxKqZbZtTzNgOzDbGqTfZnKmUzAcIjDcEmQgYyFbEfWzRpKvCkDmAqDiIiRcLvMxWaJqCgYqXgIcLdNaZlBnXtJyKaMnEaWfXfXwTbDnAiYnWqKbAtDpYdUbZrCzWgRnHzYxFgCdDbOkAgTqBuLqMeStHcDxGnVhSgMzVeTaZoTfLjMxQfRuPcFqVlRyYdHyOdJsDoCeWrUuJyIiAqHwHyVpEeEoMaJwAoUfPtBeJqGhMaHiBjKwAlXoZpUsDhHgMxBkVbLcEvNtJbGnPsUwAvXrAkTlXwYvEnOpNeWyIkRnEnTrIyAcLkRgMyYcKrGiDaAyE", "output": "IRuStKvVhJdJbQwRoIuLiVdTpKaOqKfYlYwAzIpPtUwUtMeKyCaOlXmVrKwWeImYmVuXdLkRlHwFxKqZbZtTzNgOzDbGqTfZnKmUzAcIjDcEmQgYyFbEfWzRpKvCkDmAqDiIiRcLvMxWaJqCgYqXgIcLdNaZlBnXtJyKaMnEaWfXfXwTbDnAiYnWqKbAtDpYdUbZrCzWgRnHzYxFgCdDbOkAgTqBuLqMeStHcDxGnVhSgMzVeTaZoTfLjMxQfRuPcFqVlRyYdHyOdJsDoCeWrUuJyIiAqHwHyVpEeEoMaJwAoUfPtBeJqGhMaHiBjKwAlXoZpUsDhHgMxBkVbLcEvNtJbGnPsUwAvXrAkTlXwYvEnOpNeWyIkRnEnTrIyAcLkRgMyYcKrGiDaAyE" }, { "input": "cRtJkOxHzUbJcDdHzJtLbVmSoWuHoTkVrPqQaVmXeBrHxJbQfNrQbAaMrEhVdQnPxNyCjErKxPoEdWkVrBbDeNmEgBxYiBtWdAfHiLuSwIxJuHpSkAxPoYdNkGoLySsNhUmGoZhDzAfWhJdPlJzQkZbOnMtTkClIoCqOlIcJcMlGjUyOiEmHdYfIcPtTgQhLlLcPqQjAnQnUzHpCaQsCnYgQsBcJrQwBnWsIwFfSfGuYgTzQmShFpKqEeRlRkVfMuZbUsDoFoPrNuNwTtJqFkRiXxPvKyElDzLoUnIwAaBaOiNxMpEvPzSpGpFhMtGhGdJrFnZmNiMcUfMtBnDuUnXqDcMsNyGoLwLeNnLfRsIwRfBtXkHrFcPsLdXaAoYaDzYnZuQeVcZrElWmP", "output": "CRtJkOxHzUbJcDdHzJtLbVmSoWuHoTkVrPqQaVmXeBrHxJbQfNrQbAaMrEhVdQnPxNyCjErKxPoEdWkVrBbDeNmEgBxYiBtWdAfHiLuSwIxJuHpSkAxPoYdNkGoLySsNhUmGoZhDzAfWhJdPlJzQkZbOnMtTkClIoCqOlIcJcMlGjUyOiEmHdYfIcPtTgQhLlLcPqQjAnQnUzHpCaQsCnYgQsBcJrQwBnWsIwFfSfGuYgTzQmShFpKqEeRlRkVfMuZbUsDoFoPrNuNwTtJqFkRiXxPvKyElDzLoUnIwAaBaOiNxMpEvPzSpGpFhMtGhGdJrFnZmNiMcUfMtBnDuUnXqDcMsNyGoLwLeNnLfRsIwRfBtXkHrFcPsLdXaAoYaDzYnZuQeVcZrElWmP" }, { "input": "wVaCsGxZrBbFnTbKsCoYlAvUkIpBaYpYmJkMlPwCaFvUkDxAiJgIqWsFqZlFvTtAnGzEwXbYiBdFfFxRiDoUkLmRfAwOlKeOlKgXdUnVqLkTuXtNdQpBpXtLvZxWoBeNePyHcWmZyRiUkPlRqYiQdGeXwOhHbCqVjDcEvJmBkRwWnMqPjXpUsIyXqGjHsEsDwZiFpIbTkQaUlUeFxMwJzSaHdHnDhLaLdTuYgFuJsEcMmDvXyPjKsSeBaRwNtPuOuBtNeOhQdVgKzPzOdYtPjPfDzQzHoWcYjFbSvRgGdGsCmGnQsErToBkCwGeQaCbBpYkLhHxTbUvRnJpZtXjKrHdRiUmUbSlJyGaLnWsCrJbBnSjFaZrIzIrThCmGhQcMsTtOxCuUcRaEyPaG", "output": "WVaCsGxZrBbFnTbKsCoYlAvUkIpBaYpYmJkMlPwCaFvUkDxAiJgIqWsFqZlFvTtAnGzEwXbYiBdFfFxRiDoUkLmRfAwOlKeOlKgXdUnVqLkTuXtNdQpBpXtLvZxWoBeNePyHcWmZyRiUkPlRqYiQdGeXwOhHbCqVjDcEvJmBkRwWnMqPjXpUsIyXqGjHsEsDwZiFpIbTkQaUlUeFxMwJzSaHdHnDhLaLdTuYgFuJsEcMmDvXyPjKsSeBaRwNtPuOuBtNeOhQdVgKzPzOdYtPjPfDzQzHoWcYjFbSvRgGdGsCmGnQsErToBkCwGeQaCbBpYkLhHxTbUvRnJpZtXjKrHdRiUmUbSlJyGaLnWsCrJbBnSjFaZrIzIrThCmGhQcMsTtOxCuUcRaEyPaG" }, { "input": "kEiLxLmPjGzNoGkJdBlAfXhThYhMsHmZoZbGyCvNiUoLoZdAxUbGyQiEfXvPzZzJrPbEcMpHsMjIkRrVvDvQtHuKmXvGpQtXbPzJpFjJdUgWcPdFxLjLtXgVpEiFhImHnKkGiWnZbJqRjCyEwHsNbYfYfTyBaEuKlCtWnOqHmIgGrFmQiYrBnLiFcGuZxXlMfEuVoCxPkVrQvZoIpEhKsYtXrPxLcSfQqXsWaDgVlOnAzUvAhOhMrJfGtWcOwQfRjPmGhDyAeXrNqBvEiDfCiIvWxPjTwPlXpVsMjVjUnCkXgBuWnZaDyJpWkCfBrWnHxMhJgItHdRqNrQaEeRjAuUwRkUdRhEeGlSqVqGmOjNcUhFfXjCmWzBrGvIuZpRyWkWiLyUwFpYjNmNfV", "output": "KEiLxLmPjGzNoGkJdBlAfXhThYhMsHmZoZbGyCvNiUoLoZdAxUbGyQiEfXvPzZzJrPbEcMpHsMjIkRrVvDvQtHuKmXvGpQtXbPzJpFjJdUgWcPdFxLjLtXgVpEiFhImHnKkGiWnZbJqRjCyEwHsNbYfYfTyBaEuKlCtWnOqHmIgGrFmQiYrBnLiFcGuZxXlMfEuVoCxPkVrQvZoIpEhKsYtXrPxLcSfQqXsWaDgVlOnAzUvAhOhMrJfGtWcOwQfRjPmGhDyAeXrNqBvEiDfCiIvWxPjTwPlXpVsMjVjUnCkXgBuWnZaDyJpWkCfBrWnHxMhJgItHdRqNrQaEeRjAuUwRkUdRhEeGlSqVqGmOjNcUhFfXjCmWzBrGvIuZpRyWkWiLyUwFpYjNmNfV" }, { "input": "eIhDoLmDeReKqXsHcVgFxUqNfScAiQnFrTlCgSuTtXiYvBxKaPaGvUeYfSgHqEaWcHxKpFaSlCxGqAmNeFcIzFcZsBiVoZhUjXaDaIcKoBzYdIlEnKfScRqSkYpPtVsVhXsBwUsUfAqRoCkBxWbHgDiCkRtPvUwVgDjOzObYwNiQwXlGnAqEkHdSqLgUkOdZiWaHqQnOhUnDhIzCiQtVcJlGoRfLuVlFjWqSuMsLgLwOdZvKtWdRuRqDoBoInKqPbJdXpIqLtFlMlDaWgSiKbFpCxOnQeNeQzXeKsBzIjCyPxCmBnYuHzQoYxZgGzSgGtZiTeQmUeWlNzZeKiJbQmEjIiDhPeSyZlNdHpZnIkPdJzSeJpPiXxToKyBjJfPwNzZpWzIzGySqPxLtI", "output": "EIhDoLmDeReKqXsHcVgFxUqNfScAiQnFrTlCgSuTtXiYvBxKaPaGvUeYfSgHqEaWcHxKpFaSlCxGqAmNeFcIzFcZsBiVoZhUjXaDaIcKoBzYdIlEnKfScRqSkYpPtVsVhXsBwUsUfAqRoCkBxWbHgDiCkRtPvUwVgDjOzObYwNiQwXlGnAqEkHdSqLgUkOdZiWaHqQnOhUnDhIzCiQtVcJlGoRfLuVlFjWqSuMsLgLwOdZvKtWdRuRqDoBoInKqPbJdXpIqLtFlMlDaWgSiKbFpCxOnQeNeQzXeKsBzIjCyPxCmBnYuHzQoYxZgGzSgGtZiTeQmUeWlNzZeKiJbQmEjIiDhPeSyZlNdHpZnIkPdJzSeJpPiXxToKyBjJfPwNzZpWzIzGySqPxLtI" }, { "input": "uOoQzIeTwYeKpJtGoUdNiXbPgEwVsZkAnJcArHxIpEnEhZwQhZvAiOuLeMkVqLeDsAyKeYgFxGmRoLaRsZjAeXgNfYhBkHeDrHdPuTuYhKmDlAvYzYxCdYgYfVaYlGeVqTeSfBxQePbQrKsTaIkGzMjFrQlJuYaMxWpQkLdEcDsIiMnHnDtThRvAcKyGwBsHqKdXpJfIeTeZtYjFbMeUoXoXzGrShTwSwBpQlKeDrZdCjRqNtXoTsIzBkWbMsObTtDvYaPhUeLeHqHeMpZmTaCcIqXzAmGnPfNdDaFhOqWqDrWuFiBpRjZrQmAdViOuMbFfRyXyWfHgRkGpPnDrEqQcEmHcKpEvWlBrOtJbUaXbThJaSxCbVoGvTmHvZrHvXpCvLaYbRiHzYuQyX", "output": "UOoQzIeTwYeKpJtGoUdNiXbPgEwVsZkAnJcArHxIpEnEhZwQhZvAiOuLeMkVqLeDsAyKeYgFxGmRoLaRsZjAeXgNfYhBkHeDrHdPuTuYhKmDlAvYzYxCdYgYfVaYlGeVqTeSfBxQePbQrKsTaIkGzMjFrQlJuYaMxWpQkLdEcDsIiMnHnDtThRvAcKyGwBsHqKdXpJfIeTeZtYjFbMeUoXoXzGrShTwSwBpQlKeDrZdCjRqNtXoTsIzBkWbMsObTtDvYaPhUeLeHqHeMpZmTaCcIqXzAmGnPfNdDaFhOqWqDrWuFiBpRjZrQmAdViOuMbFfRyXyWfHgRkGpPnDrEqQcEmHcKpEvWlBrOtJbUaXbThJaSxCbVoGvTmHvZrHvXpCvLaYbRiHzYuQyX" }, { "input": "lZqBqKeGvNdSeYuWxRiVnFtYbKuJwQtUcKnVtQhAlOeUzMaAuTaEnDdPfDcNyHgEoBmYjZyFePeJrRiKyAzFnBfAuGiUyLrIeLrNhBeBdVcEeKgCcBrQzDsPwGcNnZvTsEaYmFfMeOmMdNuZbUtDoQoNcGwDqEkEjIdQaPwAxJbXeNxOgKgXoEbZiIsVkRrNpNyAkLeHkNfEpLuQvEcMbIoGaDzXbEtNsLgGfOkZaFiUsOvEjVeCaMcZqMzKeAdXxJsVeCrZaFpJtZxInQxFaSmGgSsVyGeLlFgFqTpIbAvPkIfJrVcJeBxSdEvPyVwIjHpYrLrKqLnAmCuGmPoZrSbOtGaLaTmBmSuUyAmAsRiMqOtRjJhPhAfXaJnTpLbFqPmJgFcBxImTqIiJ", "output": "LZqBqKeGvNdSeYuWxRiVnFtYbKuJwQtUcKnVtQhAlOeUzMaAuTaEnDdPfDcNyHgEoBmYjZyFePeJrRiKyAzFnBfAuGiUyLrIeLrNhBeBdVcEeKgCcBrQzDsPwGcNnZvTsEaYmFfMeOmMdNuZbUtDoQoNcGwDqEkEjIdQaPwAxJbXeNxOgKgXoEbZiIsVkRrNpNyAkLeHkNfEpLuQvEcMbIoGaDzXbEtNsLgGfOkZaFiUsOvEjVeCaMcZqMzKeAdXxJsVeCrZaFpJtZxInQxFaSmGgSsVyGeLlFgFqTpIbAvPkIfJrVcJeBxSdEvPyVwIjHpYrLrKqLnAmCuGmPoZrSbOtGaLaTmBmSuUyAmAsRiMqOtRjJhPhAfXaJnTpLbFqPmJgFcBxImTqIiJ" }, { "input": "P", "output": "P" }, { "input": "Xyzzy", "output": "Xyzzy" }, { "input": "Zzz", "output": "Zzz" }, { "input": "Zp", "output": "Zp" } ]
1,695,654,993
2,147,483,647
PyPy 3-64
OK
TESTS
25
124
0
def solve(): s = input() print(s[0].capitalize()+s[1:]) # t = int(input()) t = 1 while t: solve() t -= 1
Title: Word Capitalization Time Limit: None seconds Memory Limit: None megabytes Problem Description: Capitalization is writing a word with its first letter as a capital letter. Your task is to capitalize the given word. Note, that during capitalization all the letters except the first one remains unchanged. Input Specification: A single line contains a non-empty word. This word consists of lowercase and uppercase English letters. The length of the word will not exceed 103. Output Specification: Output the given word after capitalization. Demo Input: ['ApPLe\n', 'konjac\n'] Demo Output: ['ApPLe\n', 'Konjac\n'] Note: none
```python def solve(): s = input() print(s[0].capitalize()+s[1:]) # t = int(input()) t = 1 while t: solve() t -= 1 ```
3
443
A
Anton and Letters
PROGRAMMING
800
[ "constructive algorithms", "implementation" ]
null
null
Recently, Anton has found a set. The set consists of small English letters. Anton carefully wrote out all the letters from the set in one line, separated by a comma. He also added an opening curved bracket at the beginning of the line and a closing curved bracket at the end of the line. Unfortunately, from time to time Anton would forget writing some letter and write it again. He asks you to count the total number of distinct letters in his set.
The first and the single line contains the set of letters. The length of the line doesn't exceed 1000. It is guaranteed that the line starts from an opening curved bracket and ends with a closing curved bracket. Between them, small English letters are listed, separated by a comma. Each comma is followed by a space.
Print a single number — the number of distinct letters in Anton's set.
[ "{a, b, c}\n", "{b, a, b, a}\n", "{}\n" ]
[ "3\n", "2\n", "0\n" ]
none
500
[ { "input": "{a, b, c}", "output": "3" }, { "input": "{b, a, b, a}", "output": "2" }, { "input": "{}", "output": "0" }, { "input": "{a, a, c, b, b, b, c, c, c, c}", "output": "3" }, { "input": "{a, c, b, b}", "output": "3" }, { "input": "{a, b}", "output": "2" }, { "input": "{a}", "output": "1" }, { "input": "{b, a, b, a, b, c, c, b, c, b}", "output": "3" }, { "input": "{e, g, c, e}", "output": "3" }, { "input": "{a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a}", "output": "1" }, { "input": "{a, a, b}", "output": "2" }, { "input": "{a, b, b, b, a, b, a, a, a, a, a, a, b, a, b, a, a, a, a, a, b, a, b, a}", "output": "2" }, { "input": "{j, u, a, c, f, w, e, w, x, t, h, p, v, n, i, l, x, n, i, b, u, c, a, a}", "output": "16" }, { "input": "{x, i, w, c, p, e, h, z, k, i}", "output": "9" }, { "input": "{t, k, o, x, r, d, q, j, k, e, z, w, y, r, z, s, s, e, s, b, k, i}", "output": "15" }, { "input": "{y}", "output": "1" }, { "input": "{x}", "output": "1" }, { "input": "{b, z, a, z}", "output": "3" }, { "input": "{z}", "output": "1" }, { "input": "{a, z}", "output": "2" }, { "input": "{a, b, z}", "output": "3" }, { "input": "{s, q, z, r, t, a, b, h, j, i, o, z, r, q}", "output": "11" } ]
1,695,185,146
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
1
31
0
s = set(input().split()) print(len(s))
Title: Anton and Letters Time Limit: None seconds Memory Limit: None megabytes Problem Description: Recently, Anton has found a set. The set consists of small English letters. Anton carefully wrote out all the letters from the set in one line, separated by a comma. He also added an opening curved bracket at the beginning of the line and a closing curved bracket at the end of the line. Unfortunately, from time to time Anton would forget writing some letter and write it again. He asks you to count the total number of distinct letters in his set. Input Specification: The first and the single line contains the set of letters. The length of the line doesn't exceed 1000. It is guaranteed that the line starts from an opening curved bracket and ends with a closing curved bracket. Between them, small English letters are listed, separated by a comma. Each comma is followed by a space. Output Specification: Print a single number — the number of distinct letters in Anton's set. Demo Input: ['{a, b, c}\n', '{b, a, b, a}\n', '{}\n'] Demo Output: ['3\n', '2\n', '0\n'] Note: none
```python s = set(input().split()) print(len(s)) ```
0
448
C
Painting Fence
PROGRAMMING
1,900
[ "divide and conquer", "dp", "greedy" ]
null
null
Bizon the Champion isn't just attentive, he also is very hardworking. Bizon the Champion decided to paint his old fence his favorite color, orange. The fence is represented as *n* vertical planks, put in a row. Adjacent planks have no gap between them. The planks are numbered from the left to the right starting from one, the *i*-th plank has the width of 1 meter and the height of *a**i* meters. Bizon the Champion bought a brush in the shop, the brush's width is 1 meter. He can make vertical and horizontal strokes with the brush. During a stroke the brush's full surface must touch the fence at all the time (see the samples for the better understanding). What minimum number of strokes should Bizon the Champion do to fully paint the fence? Note that you are allowed to paint the same area of the fence multiple times.
The first line contains integer *n* (1<=≤<=*n*<=≤<=5000) — the number of fence planks. The second line contains *n* space-separated integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=109).
Print a single integer — the minimum number of strokes needed to paint the whole fence.
[ "5\n2 2 1 2 1\n", "2\n2 2\n", "1\n5\n" ]
[ "3\n", "2\n", "1\n" ]
In the first sample you need to paint the fence in three strokes with the brush: the first stroke goes on height 1 horizontally along all the planks. The second stroke goes on height 2 horizontally and paints the first and second planks and the third stroke (it can be horizontal and vertical) finishes painting the fourth plank. In the second sample you can paint the fence with two strokes, either two horizontal or two vertical strokes. In the third sample there is only one plank that can be painted using a single vertical stroke.
2,500
[ { "input": "5\n2 2 1 2 1", "output": "3" }, { "input": "2\n2 2", "output": "2" }, { "input": "1\n5", "output": "1" }, { "input": "5\n2 2 1 2 2", "output": "3" }, { "input": "5\n2 2 1 5 1", "output": "3" }, { "input": "1\n1", "output": "1" }, { "input": "1\n1000000000", "output": "1" }, { "input": "2\n999635584 999595693", "output": "2" }, { "input": "10\n3 3 6 4 2 3 2 2 3 3", "output": "7" }, { "input": "14\n1 1 3 1 1 4 4 4 4 4 4 4 4 4", "output": "5" }, { "input": "6\n100 100 100 100 100 1", "output": "6" }, { "input": "7\n5 5 1 5 5 4 1", "output": "6" }, { "input": "4\n3 4 5 6", "output": "4" }, { "input": "4\n2 3 4 5", "output": "4" }, { "input": "8\n5000 5000 5 5000 5000 5000 5000 5000", "output": "8" }, { "input": "10\n4 4 4 3 4 4 3 4 4 4", "output": "6" }, { "input": "9\n4 4 4 4 20 4 4 4 4", "output": "5" }, { "input": "30\n1 4 5 3 9 7 8 4 5 9 2 3 4 2 3 4 5 5 6 8 1 2 9 4 3 7 2 6 5 4", "output": "26" }, { "input": "6\n3 3 3 3 1 3", "output": "4" }, { "input": "12\n10 10 1 1 1 3 3 3 3 3 3 3", "output": "5" }, { "input": "9\n3 4 5 6 1 9 6 5 3", "output": "9" } ]
1,679,919,586
2,147,483,647
Python 3
TIME_LIMIT_EXCEEDED
TESTS
10
1,000
512,000
def solve(i, j, a): vans = j - i + 1 mini = a[i] for k in range(i+1, j+1): # Find the smallest value if mini > a[k]: mini = a[k] for k in range(i, j+1): # Subtract the smallest value from all elements a[k] -= mini hans = mini # Record the subtracted part k = i while k <= j: if a[k] == 0: k += 1 # Skip the part with height 0 else: s = k t = s while t <= j and a[t] != 0: t += 1 hans += solve(s, t - 1, a) k = t return vans if vans < hans else hans def main(): n = int(input()) a = [0] + list(map(int, input().split())) ans = solve(1, n, a) print(ans) if __name__ == "__main__": main()
Title: Painting Fence Time Limit: None seconds Memory Limit: None megabytes Problem Description: Bizon the Champion isn't just attentive, he also is very hardworking. Bizon the Champion decided to paint his old fence his favorite color, orange. The fence is represented as *n* vertical planks, put in a row. Adjacent planks have no gap between them. The planks are numbered from the left to the right starting from one, the *i*-th plank has the width of 1 meter and the height of *a**i* meters. Bizon the Champion bought a brush in the shop, the brush's width is 1 meter. He can make vertical and horizontal strokes with the brush. During a stroke the brush's full surface must touch the fence at all the time (see the samples for the better understanding). What minimum number of strokes should Bizon the Champion do to fully paint the fence? Note that you are allowed to paint the same area of the fence multiple times. Input Specification: The first line contains integer *n* (1<=≤<=*n*<=≤<=5000) — the number of fence planks. The second line contains *n* space-separated integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=109). Output Specification: Print a single integer — the minimum number of strokes needed to paint the whole fence. Demo Input: ['5\n2 2 1 2 1\n', '2\n2 2\n', '1\n5\n'] Demo Output: ['3\n', '2\n', '1\n'] Note: In the first sample you need to paint the fence in three strokes with the brush: the first stroke goes on height 1 horizontally along all the planks. The second stroke goes on height 2 horizontally and paints the first and second planks and the third stroke (it can be horizontal and vertical) finishes painting the fourth plank. In the second sample you can paint the fence with two strokes, either two horizontal or two vertical strokes. In the third sample there is only one plank that can be painted using a single vertical stroke.
```python def solve(i, j, a): vans = j - i + 1 mini = a[i] for k in range(i+1, j+1): # Find the smallest value if mini > a[k]: mini = a[k] for k in range(i, j+1): # Subtract the smallest value from all elements a[k] -= mini hans = mini # Record the subtracted part k = i while k <= j: if a[k] == 0: k += 1 # Skip the part with height 0 else: s = k t = s while t <= j and a[t] != 0: t += 1 hans += solve(s, t - 1, a) k = t return vans if vans < hans else hans def main(): n = int(input()) a = [0] + list(map(int, input().split())) ans = solve(1, n, a) print(ans) if __name__ == "__main__": main() ```
0
420
A
Start Up
PROGRAMMING
1,000
[ "implementation" ]
null
null
Recently, a start up by two students of a state university of city F gained incredible popularity. Now it's time to start a new company. But what do we call it? The market analysts came up with a very smart plan: the name of the company should be identical to its reflection in a mirror! In other words, if we write out the name of the company on a piece of paper in a line (horizontally, from left to right) with large English letters, then put this piece of paper in front of the mirror, then the reflection of the name in the mirror should perfectly match the line written on the piece of paper. There are many suggestions for the company name, so coming up to the mirror with a piece of paper for each name wouldn't be sensible. The founders of the company decided to automatize this process. They asked you to write a program that can, given a word, determine whether the word is a 'mirror' word or not.
The first line contains a non-empty name that needs to be checked. The name contains at most 105 large English letters. The name will be written with the next sans serif font:
Print 'YES' (without the quotes), if the given name matches its mirror reflection. Otherwise, print 'NO' (without the quotes).
[ "AHA\n", "Z\n", "XO\n" ]
[ "YES\n", "NO\n", "NO\n" ]
none
500
[ { "input": "AHA", "output": "YES" }, { "input": "Z", "output": "NO" }, { "input": "XO", "output": "NO" }, { "input": "AAA", "output": "YES" }, { "input": "AHHA", "output": "YES" }, { "input": "BAB", "output": "NO" }, { "input": "OMMMAAMMMO", "output": "YES" }, { "input": "YYHUIUGYI", "output": "NO" }, { "input": "TT", "output": "YES" }, { "input": "UUU", "output": "YES" }, { "input": "WYYW", "output": "YES" }, { "input": "MITIM", "output": "YES" }, { "input": "VO", "output": "NO" }, { "input": "WWS", "output": "NO" }, { "input": "VIYMAXXAVM", "output": "NO" }, { "input": "OVWIHIWVYXMVAAAATOXWOIUUHYXHIHHVUIOOXWHOXTUUMUUVHVWWYUTIAUAITAOMHXWMTTOIVMIVOTHOVOIOHYHAOXWAUVWAVIVM", "output": "NO" }, { "input": "CC", "output": "NO" }, { "input": "QOQ", "output": "NO" }, { "input": "AEEA", "output": "NO" }, { "input": "OQQQO", "output": "NO" }, { "input": "HNCMEEMCNH", "output": "NO" }, { "input": "QDPINBMCRFWXPDBFGOZVVOCEMJRUCTOADEWEGTVBVBFWWRPGYEEYGPRWWFBVBVTGEWEDAOTCURJMECOVVZOGFBDPXWFRCMBNIPDQ", "output": "NO" }, { "input": "A", "output": "YES" }, { "input": "B", "output": "NO" }, { "input": "C", "output": "NO" }, { "input": "D", "output": "NO" }, { "input": "E", "output": "NO" }, { "input": "F", "output": "NO" }, { "input": "G", "output": "NO" }, { "input": "H", "output": "YES" }, { "input": "I", "output": "YES" }, { "input": "J", "output": "NO" }, { "input": "K", "output": "NO" }, { "input": "L", "output": "NO" }, { "input": "M", "output": "YES" }, { "input": "N", "output": "NO" }, { "input": "O", "output": "YES" }, { "input": "P", "output": "NO" }, { "input": "Q", "output": "NO" }, { "input": "R", "output": "NO" }, { "input": "S", "output": "NO" }, { "input": "T", "output": "YES" }, { "input": "U", "output": "YES" }, { "input": "V", "output": "YES" }, { "input": "W", "output": "YES" }, { "input": "X", "output": "YES" }, { "input": "Y", "output": "YES" }, { "input": "JL", "output": "NO" }, { "input": "AAAKTAAA", "output": "NO" }, { "input": "AKA", "output": "NO" }, { "input": "AAJAA", "output": "NO" }, { "input": "ABA", "output": "NO" }, { "input": "AAAAAABAAAAAA", "output": "NO" }, { "input": "ZZ", "output": "NO" }, { "input": "ADA", "output": "NO" }, { "input": "N", "output": "NO" }, { "input": "P", "output": "NO" }, { "input": "LAL", "output": "NO" }, { "input": "AABAA", "output": "NO" }, { "input": "AZA", "output": "NO" }, { "input": "V", "output": "YES" }, { "input": "SSS", "output": "NO" }, { "input": "NNN", "output": "NO" }, { "input": "S", "output": "NO" }, { "input": "I", "output": "YES" }, { "input": "SS", "output": "NO" }, { "input": "E", "output": "NO" } ]
1,398,500,809
2,147,483,647
Python 3
OK
TESTS
80
77
512,000
import sys def check(text): legal = 'AHIMOTUVWXY' for i in text: if i not in legal: return False rev = list(text) rev.reverse() if text != ''.join(rev): return False return True if __name__ == '__main__': text = sys.stdin.readline().split()[0] if check(text): print('YES') else: print('NO')
Title: Start Up Time Limit: None seconds Memory Limit: None megabytes Problem Description: Recently, a start up by two students of a state university of city F gained incredible popularity. Now it's time to start a new company. But what do we call it? The market analysts came up with a very smart plan: the name of the company should be identical to its reflection in a mirror! In other words, if we write out the name of the company on a piece of paper in a line (horizontally, from left to right) with large English letters, then put this piece of paper in front of the mirror, then the reflection of the name in the mirror should perfectly match the line written on the piece of paper. There are many suggestions for the company name, so coming up to the mirror with a piece of paper for each name wouldn't be sensible. The founders of the company decided to automatize this process. They asked you to write a program that can, given a word, determine whether the word is a 'mirror' word or not. Input Specification: The first line contains a non-empty name that needs to be checked. The name contains at most 105 large English letters. The name will be written with the next sans serif font: Output Specification: Print 'YES' (without the quotes), if the given name matches its mirror reflection. Otherwise, print 'NO' (without the quotes). Demo Input: ['AHA\n', 'Z\n', 'XO\n'] Demo Output: ['YES\n', 'NO\n', 'NO\n'] Note: none
```python import sys def check(text): legal = 'AHIMOTUVWXY' for i in text: if i not in legal: return False rev = list(text) rev.reverse() if text != ''.join(rev): return False return True if __name__ == '__main__': text = sys.stdin.readline().split()[0] if check(text): print('YES') else: print('NO') ```
3
597
A
Divisibility
PROGRAMMING
1,600
[ "math" ]
null
null
Find the number of *k*-divisible numbers on the segment [*a*,<=*b*]. In other words you need to find the number of such integer values *x* that *a*<=≤<=*x*<=≤<=*b* and *x* is divisible by *k*.
The only line contains three space-separated integers *k*, *a* and *b* (1<=≤<=*k*<=≤<=1018;<=-<=1018<=≤<=*a*<=≤<=*b*<=≤<=1018).
Print the required number.
[ "1 1 10\n", "2 -4 4\n" ]
[ "10\n", "5\n" ]
none
500
[ { "input": "1 1 10", "output": "10" }, { "input": "2 -4 4", "output": "5" }, { "input": "1 1 1", "output": "1" }, { "input": "1 0 0", "output": "1" }, { "input": "1 0 1", "output": "2" }, { "input": "1 10181 10182", "output": "2" }, { "input": "1 10182 10183", "output": "2" }, { "input": "1 -191 1011", "output": "1203" }, { "input": "2 0 0", "output": "1" }, { "input": "2 0 1", "output": "1" }, { "input": "2 1 2", "output": "1" }, { "input": "2 2 3", "output": "1" }, { "input": "2 -1 0", "output": "1" }, { "input": "2 -1 1", "output": "1" }, { "input": "2 -7 -6", "output": "1" }, { "input": "2 -7 -5", "output": "1" }, { "input": "2 -6 -6", "output": "1" }, { "input": "2 -6 -4", "output": "2" }, { "input": "2 -6 13", "output": "10" }, { "input": "2 -19171 1911", "output": "10541" }, { "input": "3 123 456", "output": "112" }, { "input": "3 124 456", "output": "111" }, { "input": "3 125 456", "output": "111" }, { "input": "3 381 281911", "output": "93844" }, { "input": "3 381 281912", "output": "93844" }, { "input": "3 381 281913", "output": "93845" }, { "input": "3 382 281911", "output": "93843" }, { "input": "3 382 281912", "output": "93843" }, { "input": "3 382 281913", "output": "93844" }, { "input": "3 383 281911", "output": "93843" }, { "input": "3 383 281912", "output": "93843" }, { "input": "3 383 281913", "output": "93844" }, { "input": "3 -381 281911", "output": "94098" }, { "input": "3 -381 281912", "output": "94098" }, { "input": "3 -381 281913", "output": "94099" }, { "input": "3 -380 281911", "output": "94097" }, { "input": "3 -380 281912", "output": "94097" }, { "input": "3 -380 281913", "output": "94098" }, { "input": "3 -379 281911", "output": "94097" }, { "input": "3 -379 281912", "output": "94097" }, { "input": "3 -379 281913", "output": "94098" }, { "input": "3 -191381 -1911", "output": "63157" }, { "input": "3 -191381 -1910", "output": "63157" }, { "input": "3 -191381 -1909", "output": "63157" }, { "input": "3 -191380 -1911", "output": "63157" }, { "input": "3 -191380 -1910", "output": "63157" }, { "input": "3 -191380 -1909", "output": "63157" }, { "input": "3 -191379 -1911", "output": "63157" }, { "input": "3 -191379 -1910", "output": "63157" }, { "input": "3 -191379 -1909", "output": "63157" }, { "input": "3 -2810171 0", "output": "936724" }, { "input": "3 0 29101", "output": "9701" }, { "input": "3 -2810170 0", "output": "936724" }, { "input": "3 0 29102", "output": "9701" }, { "input": "3 -2810169 0", "output": "936724" }, { "input": "3 0 29103", "output": "9702" }, { "input": "1 -1000000000000000000 1000000000000000000", "output": "2000000000000000001" }, { "input": "2 -1000000000000000000 1000000000000000000", "output": "1000000000000000001" }, { "input": "3 -1000000000000000000 1000000000000000000", "output": "666666666666666667" }, { "input": "4 -1000000000000000000 1000000000000000000", "output": "500000000000000001" }, { "input": "5 -1000000000000000000 1000000000000000000", "output": "400000000000000001" }, { "input": "6 -1000000000000000000 1000000000000000000", "output": "333333333333333333" }, { "input": "7 -1000000000000000000 1000000000000000000", "output": "285714285714285715" }, { "input": "1 -1000000000000000000 -100000000000000000", "output": "900000000000000001" }, { "input": "2 -1000000000000000000 -10000000000000000", "output": "495000000000000001" }, { "input": "3 -1000000000000000000 -10218000000000000", "output": "329927333333333334" }, { "input": "4 -1000000000000000000 -320110181919100", "output": "249919972454520226" }, { "input": "5 -1000000000000000000 -402710171917", "output": "199999919457965617" }, { "input": "6 -1000000000000000000 -6666666666", "output": "166666665555555556" }, { "input": "7 -1000000000000000000 -77777777777778", "output": "142846031746031746" }, { "input": "1000000000000000000 -1000000000000000000 1000000000000000000", "output": "3" }, { "input": "1000000000000000000 0 1000000000000000000", "output": "2" }, { "input": "1000000000000000000 1000000000000000000 1000000000000000000", "output": "1" }, { "input": "100000000000000321 1000000000000000000 1000000000000000000", "output": "0" }, { "input": "100000000000000321 -1000000000000000000 1000000000000000000", "output": "19" }, { "input": "1000000000000000000 0 0", "output": "1" }, { "input": "1000000000000000000 1 1", "output": "0" }, { "input": "1000000000000000000 -1 -1", "output": "0" }, { "input": "1000000000000000000 -2 -1", "output": "0" }, { "input": "142000000000000271 -228118171 -1382811", "output": "0" }, { "input": "1 1 1000000000000000000", "output": "1000000000000000000" } ]
1,585,832,101
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
8
124
0
k,a,b=map(int,input().split()) ans=(b-a+1)//k if(k==1): ans=b-a+1 if(a==0 and b==0): ans+=0 if(a<0 and k!=1): ans+=1 print(ans)
Title: Divisibility Time Limit: None seconds Memory Limit: None megabytes Problem Description: Find the number of *k*-divisible numbers on the segment [*a*,<=*b*]. In other words you need to find the number of such integer values *x* that *a*<=≤<=*x*<=≤<=*b* and *x* is divisible by *k*. Input Specification: The only line contains three space-separated integers *k*, *a* and *b* (1<=≤<=*k*<=≤<=1018;<=-<=1018<=≤<=*a*<=≤<=*b*<=≤<=1018). Output Specification: Print the required number. Demo Input: ['1 1 10\n', '2 -4 4\n'] Demo Output: ['10\n', '5\n'] Note: none
```python k,a,b=map(int,input().split()) ans=(b-a+1)//k if(k==1): ans=b-a+1 if(a==0 and b==0): ans+=0 if(a<0 and k!=1): ans+=1 print(ans) ```
0
231
A
Team
PROGRAMMING
800
[ "brute force", "greedy" ]
null
null
One day three best friends Petya, Vasya and Tonya decided to form a team and take part in programming contests. Participants are usually offered several problems during programming contests. Long before the start the friends decided that they will implement a problem if at least two of them are sure about the solution. Otherwise, the friends won't write the problem's solution. This contest offers *n* problems to the participants. For each problem we know, which friend is sure about the solution. Help the friends find the number of problems for which they will write a solution.
The first input line contains a single integer *n* (1<=≤<=*n*<=≤<=1000) — the number of problems in the contest. Then *n* lines contain three integers each, each integer is either 0 or 1. If the first number in the line equals 1, then Petya is sure about the problem's solution, otherwise he isn't sure. The second number shows Vasya's view on the solution, the third number shows Tonya's view. The numbers on the lines are separated by spaces.
Print a single integer — the number of problems the friends will implement on the contest.
[ "3\n1 1 0\n1 1 1\n1 0 0\n", "2\n1 0 0\n0 1 1\n" ]
[ "2\n", "1\n" ]
In the first sample Petya and Vasya are sure that they know how to solve the first problem and all three of them know how to solve the second problem. That means that they will write solutions for these problems. Only Petya is sure about the solution for the third problem, but that isn't enough, so the friends won't take it. In the second sample the friends will only implement the second problem, as Vasya and Tonya are sure about the solution.
500
[ { "input": "3\n1 1 0\n1 1 1\n1 0 0", "output": "2" }, { "input": "2\n1 0 0\n0 1 1", "output": "1" }, { "input": "1\n1 0 0", "output": "0" }, { "input": "2\n1 0 0\n1 1 1", "output": "1" }, { "input": "5\n1 0 0\n0 1 0\n1 1 1\n0 0 1\n0 0 0", "output": "1" }, { "input": "10\n0 1 0\n0 1 0\n1 1 0\n1 0 0\n0 0 1\n0 1 1\n1 1 1\n1 1 0\n0 0 0\n0 0 0", "output": "4" }, { "input": "15\n0 1 0\n1 0 0\n1 1 0\n1 1 1\n0 1 0\n0 0 1\n1 0 1\n1 0 1\n1 0 1\n0 0 0\n1 1 1\n1 1 0\n0 1 1\n1 1 0\n1 1 1", "output": "10" }, { "input": "50\n0 0 0\n0 1 1\n1 1 1\n0 1 0\n1 0 1\n1 1 1\n0 0 1\n1 0 0\n1 1 0\n1 0 1\n0 1 0\n0 0 1\n1 1 0\n0 1 0\n1 1 0\n0 0 0\n1 1 1\n1 0 1\n0 0 1\n1 1 0\n1 1 1\n0 1 1\n1 1 0\n0 0 0\n0 0 0\n1 1 1\n0 0 0\n1 1 1\n0 1 1\n0 0 1\n0 0 0\n0 0 0\n1 1 0\n1 1 0\n1 0 1\n1 0 0\n1 0 1\n1 0 1\n0 1 1\n1 1 0\n1 1 0\n0 1 0\n1 0 1\n0 0 0\n0 0 0\n0 0 0\n0 0 1\n1 1 1\n0 1 1\n1 0 1", "output": "29" }, { "input": "1\n1 1 1", "output": "1" }, { "input": "8\n0 0 0\n0 0 1\n0 0 0\n0 1 1\n1 0 0\n1 0 1\n1 1 0\n1 1 1", "output": "4" }, { "input": "16\n1 1 1\n1 1 1\n1 1 1\n1 1 1\n1 1 1\n1 1 1\n1 1 1\n1 1 1\n1 1 1\n1 1 1\n1 1 1\n1 1 1\n1 1 1\n1 1 1\n1 1 1\n1 1 1", "output": "16" } ]
1,696,746,305
2,147,483,647
PyPy 3
RUNTIME_ERROR
TESTS
0
154
2,048,000
w=int(input()) l=0 for a in range(w): n=input('') l=[int(n[0]),int(n[2]),int(n[4])] if sum(l)>=2: l+=1 print(l)
Title: Team Time Limit: None seconds Memory Limit: None megabytes Problem Description: One day three best friends Petya, Vasya and Tonya decided to form a team and take part in programming contests. Participants are usually offered several problems during programming contests. Long before the start the friends decided that they will implement a problem if at least two of them are sure about the solution. Otherwise, the friends won't write the problem's solution. This contest offers *n* problems to the participants. For each problem we know, which friend is sure about the solution. Help the friends find the number of problems for which they will write a solution. Input Specification: The first input line contains a single integer *n* (1<=≤<=*n*<=≤<=1000) — the number of problems in the contest. Then *n* lines contain three integers each, each integer is either 0 or 1. If the first number in the line equals 1, then Petya is sure about the problem's solution, otherwise he isn't sure. The second number shows Vasya's view on the solution, the third number shows Tonya's view. The numbers on the lines are separated by spaces. Output Specification: Print a single integer — the number of problems the friends will implement on the contest. Demo Input: ['3\n1 1 0\n1 1 1\n1 0 0\n', '2\n1 0 0\n0 1 1\n'] Demo Output: ['2\n', '1\n'] Note: In the first sample Petya and Vasya are sure that they know how to solve the first problem and all three of them know how to solve the second problem. That means that they will write solutions for these problems. Only Petya is sure about the solution for the third problem, but that isn't enough, so the friends won't take it. In the second sample the friends will only implement the second problem, as Vasya and Tonya are sure about the solution.
```python w=int(input()) l=0 for a in range(w): n=input('') l=[int(n[0]),int(n[2]),int(n[4])] if sum(l)>=2: l+=1 print(l) ```
-1
978
A
Remove Duplicates
PROGRAMMING
800
[ "implementation" ]
null
null
Petya has an array $a$ consisting of $n$ integers. He wants to remove duplicate (equal) elements. Petya wants to leave only the rightmost entry (occurrence) for each element of the array. The relative order of the remaining unique elements should not be changed.
The first line contains a single integer $n$ ($1 \le n \le 50$) — the number of elements in Petya's array. The following line contains a sequence $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 1\,000$) — the Petya's array.
In the first line print integer $x$ — the number of elements which will be left in Petya's array after he removed the duplicates. In the second line print $x$ integers separated with a space — Petya's array after he removed the duplicates. For each unique element only the rightmost entry should be left.
[ "6\n1 5 5 1 6 1\n", "5\n2 4 2 4 4\n", "5\n6 6 6 6 6\n" ]
[ "3\n5 6 1 \n", "2\n2 4 \n", "1\n6 \n" ]
In the first example you should remove two integers $1$, which are in the positions $1$ and $4$. Also you should remove the integer $5$, which is in the position $2$. In the second example you should remove integer $2$, which is in the position $1$, and two integers $4$, which are in the positions $2$ and $4$. In the third example you should remove four integers $6$, which are in the positions $1$, $2$, $3$ and $4$.
0
[ { "input": "6\n1 5 5 1 6 1", "output": "3\n5 6 1 " }, { "input": "5\n2 4 2 4 4", "output": "2\n2 4 " }, { "input": "5\n6 6 6 6 6", "output": "1\n6 " }, { "input": "7\n1 2 3 4 2 2 3", "output": "4\n1 4 2 3 " }, { "input": "9\n100 100 100 99 99 99 100 100 100", "output": "2\n99 100 " }, { "input": "27\n489 489 487 488 750 230 43 645 42 42 489 42 973 42 973 750 645 355 868 112 868 489 750 489 887 489 868", "output": "13\n487 488 230 43 42 973 645 355 112 750 887 489 868 " }, { "input": "40\n151 421 421 909 117 222 909 954 227 421 227 954 954 222 421 227 421 421 421 151 421 227 222 222 222 222 421 183 421 227 421 954 222 421 954 421 222 421 909 421", "output": "8\n117 151 183 227 954 222 909 421 " }, { "input": "48\n2 2 2 903 903 2 726 2 2 2 2 2 2 2 2 2 2 726 2 2 2 2 2 2 2 726 2 2 2 2 62 2 2 2 2 2 2 2 2 726 62 726 2 2 2 903 903 2", "output": "4\n62 726 903 2 " }, { "input": "1\n1", "output": "1\n1 " }, { "input": "13\n5 37 375 5 37 33 37 375 37 2 3 3 2", "output": "6\n5 33 375 37 3 2 " }, { "input": "50\n1 2 3 4 5 4 3 2 1 2 3 2 1 4 5 5 4 3 2 1 1 2 3 4 5 4 3 2 1 2 3 2 1 4 5 5 4 3 2 1 4 3 2 5 1 6 6 6 6 6", "output": "6\n4 3 2 5 1 6 " }, { "input": "47\n233 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 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": "2\n233 1 " }, { "input": "47\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", "output": "1\n1 " }, { "input": "2\n964 964", "output": "1\n964 " }, { "input": "2\n1000 1000", "output": "1\n1000 " }, { "input": "1\n1000", "output": "1\n1000 " }, { "input": "45\n991 991 996 996 992 992 999 1000 998 1000 992 999 996 999 991 991 999 993 992 999 1000 997 992 999 996 991 994 996 991 999 1000 993 999 997 999 992 991 997 991 998 998 995 998 994 993", "output": "10\n996 1000 999 992 997 991 995 998 994 993 " }, { "input": "6\n994 993 1000 998 991 994", "output": "5\n993 1000 998 991 994 " }, { "input": "48\n992 995 992 991 994 992 995 999 996 993 999 995 993 992 1000 992 997 996 991 993 992 998 998 998 999 995 992 992 993 992 992 995 996 995 997 991 997 991 999 994 994 997 1000 998 1000 992 1000 999", "output": "10\n993 996 995 991 994 997 998 992 1000 999 " }, { "input": "3\n6 6 3", "output": "2\n6 3 " }, { "input": "36\n999 1000 993 993 1000 999 996 997 998 995 995 997 999 995 1000 998 998 994 993 998 994 999 1000 995 996 994 991 991 999 996 993 999 996 998 991 997", "output": "9\n1000 995 994 993 999 996 998 991 997 " }, { "input": "49\n991 997 995 991 995 998 994 996 997 991 998 993 992 999 996 995 991 991 999 997 995 993 997 1000 997 993 993 994 999 994 992 991 1000 996 994 996 996 999 992 992 1000 991 997 993 991 994 997 991 996", "output": "10\n998 995 999 992 1000 993 994 997 991 996 " }, { "input": "2\n1000 999", "output": "2\n1000 999 " }, { "input": "28\n997 994 991 994 994 995 1000 992 995 994 994 995 991 996 991 996 991 999 999 993 994 997 995 992 991 992 998 1000", "output": "10\n996 999 993 994 997 995 991 992 998 1000 " }, { "input": "15\n991 995 995 1000 991 993 997 998 1000 994 1000 992 991 995 992", "output": "8\n993 997 998 994 1000 991 995 992 " }, { "input": "6\n1000 1 1000 2 1000 1", "output": "3\n2 1000 1 " }, { "input": "6\n1000 1 1000 2 1 1000", "output": "3\n2 1 1000 " }, { "input": "7\n1 1000 1 999 1000 1 2", "output": "4\n999 1000 1 2 " } ]
1,662,422,449
2,147,483,647
Python 3
OK
TESTS
28
46
0
no_inputs = int(input()) nums = list(map(int, input().split())) unique_nums = [] for num in nums[::-1]: if num not in unique_nums: unique_nums.append(num) print(len(unique_nums)) print(" ".join(str(item) for item in unique_nums[::-1]))
Title: Remove Duplicates Time Limit: None seconds Memory Limit: None megabytes Problem Description: Petya has an array $a$ consisting of $n$ integers. He wants to remove duplicate (equal) elements. Petya wants to leave only the rightmost entry (occurrence) for each element of the array. The relative order of the remaining unique elements should not be changed. Input Specification: The first line contains a single integer $n$ ($1 \le n \le 50$) — the number of elements in Petya's array. The following line contains a sequence $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 1\,000$) — the Petya's array. Output Specification: In the first line print integer $x$ — the number of elements which will be left in Petya's array after he removed the duplicates. In the second line print $x$ integers separated with a space — Petya's array after he removed the duplicates. For each unique element only the rightmost entry should be left. Demo Input: ['6\n1 5 5 1 6 1\n', '5\n2 4 2 4 4\n', '5\n6 6 6 6 6\n'] Demo Output: ['3\n5 6 1 \n', '2\n2 4 \n', '1\n6 \n'] Note: In the first example you should remove two integers $1$, which are in the positions $1$ and $4$. Also you should remove the integer $5$, which is in the position $2$. In the second example you should remove integer $2$, which is in the position $1$, and two integers $4$, which are in the positions $2$ and $4$. In the third example you should remove four integers $6$, which are in the positions $1$, $2$, $3$ and $4$.
```python no_inputs = int(input()) nums = list(map(int, input().split())) unique_nums = [] for num in nums[::-1]: if num not in unique_nums: unique_nums.append(num) print(len(unique_nums)) print(" ".join(str(item) for item in unique_nums[::-1])) ```
3
922
A
Cloning Toys
PROGRAMMING
1,300
[ "implementation" ]
null
null
Imp likes his plush toy a lot. Recently, he found a machine that can clone plush toys. Imp knows that if he applies the machine to an original toy, he additionally gets one more original toy and one copy, and if he applies the machine to a copied toy, he gets two additional copies. Initially, Imp has only one original toy. He wants to know if it is possible to use machine to get exactly *x* copied toys and *y* original toys? He can't throw toys away, and he can't apply the machine to a copy if he doesn't currently have any copies.
The only line contains two integers *x* and *y* (0<=≤<=*x*,<=*y*<=≤<=109) — the number of copies and the number of original toys Imp wants to get (including the initial one).
Print "Yes", if the desired configuration is possible, and "No" otherwise. You can print each letter in arbitrary case (upper or lower).
[ "6 3\n", "4 2\n", "1000 1001\n" ]
[ "Yes\n", "No\n", "Yes\n" ]
In the first example, Imp has to apply the machine twice to original toys and then twice to copies.
500
[ { "input": "6 3", "output": "Yes" }, { "input": "4 2", "output": "No" }, { "input": "1000 1001", "output": "Yes" }, { "input": "1000000000 999999999", "output": "Yes" }, { "input": "81452244 81452247", "output": "No" }, { "input": "188032448 86524683", "output": "Yes" }, { "input": "365289629 223844571", "output": "No" }, { "input": "247579518 361164458", "output": "No" }, { "input": "424836699 793451637", "output": "No" }, { "input": "602093880 930771525", "output": "No" }, { "input": "779351061 773124120", "output": "Yes" }, { "input": "661640950 836815080", "output": "No" }, { "input": "543930839 974134967", "output": "No" }, { "input": "16155311 406422145", "output": "No" }, { "input": "81601559 445618240", "output": "No" }, { "input": "963891449 582938127", "output": "No" }, { "input": "141148629 351661795", "output": "No" }, { "input": "318405810 783948974", "output": "No" }, { "input": "495662991 921268861", "output": "No" }, { "input": "1 0", "output": "No" }, { "input": "0 1", "output": "Yes" }, { "input": "0 0", "output": "No" }, { "input": "453462237 167520068", "output": "Yes" }, { "input": "630719418 9872663", "output": "Yes" }, { "input": "807976599 442159843", "output": "No" }, { "input": "690266488 579479730", "output": "No" }, { "input": "771581370 589752968", "output": "No" }, { "input": "948838551 727072855", "output": "No" }, { "input": "831128440 790763814", "output": "No" }, { "input": "303352912 928083702", "output": "No" }, { "input": "185642801 65403588", "output": "Yes" }, { "input": "67932690 202723476", "output": "No" }, { "input": "540157163 340043363", "output": "No" }, { "input": "422447052 772330542", "output": "No" }, { "input": "599704233 541054210", "output": "Yes" }, { "input": "481994122 678374097", "output": "No" }, { "input": "48564714 743566477", "output": "No" }, { "input": "225821895 880886365", "output": "No" }, { "input": "403079076 313173543", "output": "Yes" }, { "input": "1000000000 1000000000", "output": "No" }, { "input": "1 1", "output": "No" }, { "input": "1 2", "output": "Yes" }, { "input": "2 1", "output": "No" }, { "input": "2 2", "output": "No" }, { "input": "2 0", "output": "No" }, { "input": "0 2", "output": "No" }, { "input": "1000000000 1", "output": "No" }, { "input": "777777 0", "output": "No" }, { "input": "10 1", "output": "No" }, { "input": "7 0", "output": "No" }, { "input": "3 0", "output": "No" }, { "input": "3 2", "output": "Yes" } ]
1,629,252,461
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
19
77
6,758,400
n,m=map(int,input().split()) n-=m-1 if n<0: print("NO") elif n==0 or n%2==0: print('YES') else:print('NO')
Title: Cloning Toys Time Limit: None seconds Memory Limit: None megabytes Problem Description: Imp likes his plush toy a lot. Recently, he found a machine that can clone plush toys. Imp knows that if he applies the machine to an original toy, he additionally gets one more original toy and one copy, and if he applies the machine to a copied toy, he gets two additional copies. Initially, Imp has only one original toy. He wants to know if it is possible to use machine to get exactly *x* copied toys and *y* original toys? He can't throw toys away, and he can't apply the machine to a copy if he doesn't currently have any copies. Input Specification: The only line contains two integers *x* and *y* (0<=≤<=*x*,<=*y*<=≤<=109) — the number of copies and the number of original toys Imp wants to get (including the initial one). Output Specification: Print "Yes", if the desired configuration is possible, and "No" otherwise. You can print each letter in arbitrary case (upper or lower). Demo Input: ['6 3\n', '4 2\n', '1000 1001\n'] Demo Output: ['Yes\n', 'No\n', 'Yes\n'] Note: In the first example, Imp has to apply the machine twice to original toys and then twice to copies.
```python n,m=map(int,input().split()) n-=m-1 if n<0: print("NO") elif n==0 or n%2==0: print('YES') else:print('NO') ```
0
222
A
Shooshuns and Sequence
PROGRAMMING
1,200
[ "brute force", "implementation" ]
null
null
One day shooshuns found a sequence of *n* integers, written on a blackboard. The shooshuns can perform one operation with it, the operation consists of two steps: 1. Find the number that goes *k*-th in the current sequence and add the same number to the end of the sequence; 1. Delete the first number of the current sequence. The shooshuns wonder after how many operations all numbers on the board will be the same and whether all numbers will ever be the same.
The first line contains two space-separated integers *n* and *k* (1<=≤<=*k*<=≤<=*n*<=≤<=105). The second line contains *n* space-separated integers: *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=105) — the sequence that the shooshuns found.
Print the minimum number of operations, required for all numbers on the blackboard to become the same. If it is impossible to achieve, print -1.
[ "3 2\n3 1 1\n", "3 1\n3 1 1\n" ]
[ "1\n", "-1\n" ]
In the first test case after the first operation the blackboard will have sequence [1, 1, 1]. So, one operation is enough to make all numbers the same. Thus, the answer equals one. In the second test case the sequence will never consist of the same numbers. It will always contain at least two distinct numbers 3 and 1. Thus, the answer equals -1.
500
[ { "input": "3 2\n3 1 1", "output": "1" }, { "input": "3 1\n3 1 1", "output": "-1" }, { "input": "1 1\n1", "output": "0" }, { "input": "2 1\n1 1", "output": "0" }, { "input": "2 1\n2 1", "output": "-1" }, { "input": "4 4\n1 2 3 4", "output": "3" }, { "input": "4 3\n1 2 3 4", "output": "-1" }, { "input": "5 3\n2 1 1 1 1", "output": "1" }, { "input": "5 3\n1 1 1 1 1", "output": "0" }, { "input": "5 5\n1 1 1 1 1", "output": "0" }, { "input": "10 1\n1 1 1 1 1 1 1 1 1 1", "output": "0" }, { "input": "10 1\n1 2 1 1 1 1 1 1 1 1", "output": "-1" }, { "input": "10 1\n2 1 1 1 1 1 1 1 1 1", "output": "-1" }, { "input": "10 2\n2 1 1 1 1 1 1 1 1 1", "output": "1" }, { "input": "10 2\n1 2 1 1 1 1 1 1 1 1", "output": "-1" }, { "input": "10 3\n3 2 1 1 1 1 1 1 1 1", "output": "2" }, { "input": "10 1\n1 2 3 4 5 6 7 8 9 10", "output": "-1" }, { "input": "10 10\n1 2 3 4 5 6 7 8 9 10", "output": "9" }, { "input": "20 10\n1 2 3 4 5 6 7 8 9 10 1 1 1 1 1 1 1 1 1 1", "output": "-1" }, { "input": "20 11\n1 2 3 4 5 6 7 8 9 10 1 1 1 1 1 1 1 1 1 1", "output": "10" }, { "input": "20 9\n1 2 3 4 5 6 7 8 9 10 1 1 1 1 1 1 1 1 1 1", "output": "-1" }, { "input": "20 10\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1", "output": "0" }, { "input": "20 20\n20 1 19 2 18 3 17 4 16 5 15 6 14 7 13 8 12 9 11 10", "output": "19" } ]
1,582,797,527
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
6
280
7,270,400
n,k=map(int,input().split()) l=list(map(int,input().split())) v=0 for j in range(k,len(l)): if l[j]!=l[j-1]: v=1 break if v==1: print(-1) else: c=0 for j in range(k-1,0,-1): if l[j]==l[j-1]: c+=1 print(k-1-c)
Title: Shooshuns and Sequence Time Limit: None seconds Memory Limit: None megabytes Problem Description: One day shooshuns found a sequence of *n* integers, written on a blackboard. The shooshuns can perform one operation with it, the operation consists of two steps: 1. Find the number that goes *k*-th in the current sequence and add the same number to the end of the sequence; 1. Delete the first number of the current sequence. The shooshuns wonder after how many operations all numbers on the board will be the same and whether all numbers will ever be the same. Input Specification: The first line contains two space-separated integers *n* and *k* (1<=≤<=*k*<=≤<=*n*<=≤<=105). The second line contains *n* space-separated integers: *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=105) — the sequence that the shooshuns found. Output Specification: Print the minimum number of operations, required for all numbers on the blackboard to become the same. If it is impossible to achieve, print -1. Demo Input: ['3 2\n3 1 1\n', '3 1\n3 1 1\n'] Demo Output: ['1\n', '-1\n'] Note: In the first test case after the first operation the blackboard will have sequence [1, 1, 1]. So, one operation is enough to make all numbers the same. Thus, the answer equals one. In the second test case the sequence will never consist of the same numbers. It will always contain at least two distinct numbers 3 and 1. Thus, the answer equals -1.
```python n,k=map(int,input().split()) l=list(map(int,input().split())) v=0 for j in range(k,len(l)): if l[j]!=l[j-1]: v=1 break if v==1: print(-1) else: c=0 for j in range(k-1,0,-1): if l[j]==l[j-1]: c+=1 print(k-1-c) ```
0
955
C
Sad powers
PROGRAMMING
2,100
[ "binary search", "math", "number theory" ]
null
null
You're given *Q* queries of the form (*L*,<=*R*). For each query you have to find the number of such *x* that *L*<=≤<=*x*<=≤<=*R* and there exist integer numbers *a*<=&gt;<=0, *p*<=&gt;<=1 such that *x*<==<=*a**p*.
The first line contains the number of queries *Q* (1<=≤<=*Q*<=≤<=105). The next *Q* lines contains two integers *L*, *R* each (1<=≤<=*L*<=≤<=*R*<=≤<=1018).
Output *Q* lines — the answers to the queries.
[ "6\n1 4\n9 9\n5 7\n12 29\n137 591\n1 1000000\n" ]
[ "2\n1\n0\n3\n17\n1111\n" ]
In query one the suitable numbers are 1 and 4.
1,500
[ { "input": "6\n1 4\n9 9\n5 7\n12 29\n137 591\n1 1000000", "output": "2\n1\n0\n3\n17\n1111" }, { "input": "20\n862 928\n758 964\n541 789\n622 943\n328 900\n14 764\n217 972\n461 847\n442 468\n900 986\n518 529\n938 993\n549 851\n690 944\n484 601\n320 910\n98 868\n816 915\n765 880\n551 770", "output": "1\n4\n5\n6\n14\n32\n20\n9\n0\n2\n1\n1\n6\n4\n4\n15\n26\n2\n2\n4" } ]
1,689,448,697
2,147,483,647
PyPy 3-64
WRONG_ANSWER
TESTS
0
30
0
print("_RANDOM_GUESS_1689448697.176476")# 1689448697.176495
Title: Sad powers Time Limit: None seconds Memory Limit: None megabytes Problem Description: You're given *Q* queries of the form (*L*,<=*R*). For each query you have to find the number of such *x* that *L*<=≤<=*x*<=≤<=*R* and there exist integer numbers *a*<=&gt;<=0, *p*<=&gt;<=1 such that *x*<==<=*a**p*. Input Specification: The first line contains the number of queries *Q* (1<=≤<=*Q*<=≤<=105). The next *Q* lines contains two integers *L*, *R* each (1<=≤<=*L*<=≤<=*R*<=≤<=1018). Output Specification: Output *Q* lines — the answers to the queries. Demo Input: ['6\n1 4\n9 9\n5 7\n12 29\n137 591\n1 1000000\n'] Demo Output: ['2\n1\n0\n3\n17\n1111\n'] Note: In query one the suitable numbers are 1 and 4.
```python print("_RANDOM_GUESS_1689448697.176476")# 1689448697.176495 ```
0
135
A
Replacement
PROGRAMMING
1,300
[ "greedy", "implementation", "sortings" ]
null
null
Little Petya very much likes arrays consisting of *n* integers, where each of them is in the range from 1 to 109, inclusive. Recently he has received one such array as a gift from his mother. Petya didn't like it at once. He decided to choose exactly one element from the array and replace it with another integer that also lies in the range from 1 to 109, inclusive. It is not allowed to replace a number with itself or to change no number at all. After the replacement Petya sorted the array by the numbers' non-decreasing. Now he wants to know for each position: what minimum number could occupy it after the replacement and the sorting.
The first line contains a single integer *n* (1<=≤<=*n*<=≤<=105), which represents how many numbers the array has. The next line contains *n* space-separated integers — the array's description. All elements of the array lie in the range from 1 to 109, inclusive.
Print *n* space-separated integers — the minimum possible values of each array element after one replacement and the sorting are performed.
[ "5\n1 2 3 4 5\n", "5\n2 3 4 5 6\n", "3\n2 2 2\n" ]
[ "1 1 2 3 4\n", "1 2 3 4 5\n", "1 2 2\n" ]
none
500
[ { "input": "5\n1 2 3 4 5", "output": "1 1 2 3 4" }, { "input": "5\n2 3 4 5 6", "output": "1 2 3 4 5" }, { "input": "3\n2 2 2", "output": "1 2 2" }, { "input": "4\n1 1 2 3", "output": "1 1 1 2" }, { "input": "3\n1 1 1", "output": "1 1 2" }, { "input": "10\n5 6 1 2 3 1 3 45 7 1000000000", "output": "1 1 1 2 3 3 5 6 7 45" }, { "input": "4\n1000000000 234765 3485636 385634876", "output": "1 234765 3485636 385634876" }, { "input": "1\n1", "output": "2" }, { "input": "25\n1 1 1 2 2 2 1 2 1 2 2 2 2 2 1 2 2 2 1 2 2 2 2 1 2", "output": "1 1 1 1 1 1 1 1 1 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2" }, { "input": "2\n2 1", "output": "1 1" }, { "input": "3\n1 2 1", "output": "1 1 1" }, { "input": "1\n2", "output": "1" }, { "input": "1\n4", "output": "1" }, { "input": "3\n1 1 2", "output": "1 1 1" }, { "input": "2\n1 2", "output": "1 1" }, { "input": "2\n1 3", "output": "1 1" }, { "input": "2\n1 1", "output": "1 2" }, { "input": "2\n5 5", "output": "1 5" }, { "input": "1\n5", "output": "1" } ]
1,599,030,674
2,147,483,647
PyPy 3
WRONG_ANSWER
TESTS
6
278
0
n=int(input()) s=list(map(int,input().split())) if s[-1]!=1: s[-1]=1 else: s[-1]=2 s.sort() print(' '.join(map(str,s)))
Title: Replacement Time Limit: None seconds Memory Limit: None megabytes Problem Description: Little Petya very much likes arrays consisting of *n* integers, where each of them is in the range from 1 to 109, inclusive. Recently he has received one such array as a gift from his mother. Petya didn't like it at once. He decided to choose exactly one element from the array and replace it with another integer that also lies in the range from 1 to 109, inclusive. It is not allowed to replace a number with itself or to change no number at all. After the replacement Petya sorted the array by the numbers' non-decreasing. Now he wants to know for each position: what minimum number could occupy it after the replacement and the sorting. Input Specification: The first line contains a single integer *n* (1<=≤<=*n*<=≤<=105), which represents how many numbers the array has. The next line contains *n* space-separated integers — the array's description. All elements of the array lie in the range from 1 to 109, inclusive. Output Specification: Print *n* space-separated integers — the minimum possible values of each array element after one replacement and the sorting are performed. Demo Input: ['5\n1 2 3 4 5\n', '5\n2 3 4 5 6\n', '3\n2 2 2\n'] Demo Output: ['1 1 2 3 4\n', '1 2 3 4 5\n', '1 2 2\n'] Note: none
```python n=int(input()) s=list(map(int,input().split())) if s[-1]!=1: s[-1]=1 else: s[-1]=2 s.sort() print(' '.join(map(str,s))) ```
0
99
A
Help Far Away Kingdom
PROGRAMMING
800
[ "strings" ]
A. Help Far Away Kingdom
2
256
In a far away kingdom lived the King, the Prince, the Shoemaker, the Dressmaker and many other citizens. They lived happily until great trouble came into the Kingdom. The ACMers settled there. Most damage those strange creatures inflicted upon the kingdom was that they loved high precision numbers. As a result, the Kingdom healers had already had three appointments with the merchants who were asked to sell, say, exactly 0.273549107 beer barrels. To deal with the problem somehow, the King issued an order obliging rounding up all numbers to the closest integer to simplify calculations. Specifically, the order went like this: - If a number's integer part does not end with digit 9 and its fractional part is strictly less than 0.5, then the rounded up number coincides with the number’s integer part. - If a number's integer part does not end with digit 9 and its fractional part is not less than 0.5, the rounded up number is obtained if we add 1 to the last digit of the number’s integer part.- If the number’s integer part ends with digit 9, to round up the numbers one should go to Vasilisa the Wise. In the whole Kingdom she is the only one who can perform the tricky operation of carrying into the next position. Merchants found the algorithm very sophisticated and they asked you (the ACMers) to help them. Can you write a program that would perform the rounding according to the King’s order?
The first line contains a single number to round up — the integer part (a non-empty set of decimal digits that do not start with 0 — with the exception of a case when the set consists of a single digit — in this case 0 can go first), then follows character «.» (a dot), and then follows the fractional part (any non-empty set of decimal digits). The number's length does not exceed 1000 characters, including the dot. There are no other characters in the input data.
If the last number of the integer part is not equal to 9, print the rounded-up number without leading zeroes. Otherwise, print the message "GOTO Vasilisa." (without the quotes).
[ "0.0\n", "1.49\n", "1.50\n", "2.71828182845904523536\n", "3.14159265358979323846\n", "12345678901234567890.1\n", "123456789123456789.999\n" ]
[ "0", "1", "2", "3", "3", "12345678901234567890", "GOTO Vasilisa." ]
none
500
[ { "input": "0.0", "output": "0" }, { "input": "1.49", "output": "1" }, { "input": "1.50", "output": "2" }, { "input": "2.71828182845904523536", "output": "3" }, { "input": "3.14159265358979323846", "output": "3" }, { "input": "12345678901234567890.1", "output": "12345678901234567890" }, { "input": "123456789123456789.999", "output": "GOTO Vasilisa." }, { "input": "12345678901234567890.9", "output": "12345678901234567891" }, { "input": "123456789123456788.999", "output": "123456789123456789" }, { "input": "9.000", "output": "GOTO Vasilisa." }, { "input": "0.1", "output": "0" }, { "input": "0.2", "output": "0" }, { "input": "0.3", "output": "0" }, { "input": "0.4", "output": "0" }, { "input": "0.5", "output": "1" }, { "input": "0.6", "output": "1" }, { "input": "0.7", "output": "1" }, { "input": "0.8", "output": "1" }, { "input": "0.9", "output": "1" }, { "input": "1.0", "output": "1" }, { "input": "1.1", "output": "1" }, { "input": "1.2", "output": "1" }, { "input": "1.3", "output": "1" }, { "input": "1.4", "output": "1" }, { "input": "1.5", "output": "2" }, { "input": "1.6", "output": "2" }, { "input": "1.7", "output": "2" }, { "input": "1.8", "output": "2" }, { "input": "1.9", "output": "2" }, { "input": "2.0", "output": "2" }, { "input": "2.1", "output": "2" }, { "input": "2.2", "output": "2" }, { "input": "2.3", "output": "2" }, { "input": "2.4", "output": "2" }, { "input": "2.5", "output": "3" }, { "input": "2.6", "output": "3" }, { "input": "2.7", "output": "3" }, { "input": "2.8", "output": "3" }, { "input": "2.9", "output": "3" }, { "input": "3.0", "output": "3" }, { "input": "3.1", "output": "3" }, { "input": "3.2", "output": "3" }, { "input": "3.3", "output": "3" }, { "input": "3.4", "output": "3" }, { "input": "3.5", "output": "4" }, { "input": "3.6", "output": "4" }, { "input": "3.7", "output": "4" }, { "input": "3.8", "output": "4" }, { "input": "3.9", "output": "4" }, { "input": "4.0", "output": "4" }, { "input": "4.1", "output": "4" }, { "input": "4.2", "output": "4" }, { "input": "4.3", "output": "4" }, { "input": "4.4", "output": "4" }, { "input": "4.5", "output": "5" }, { "input": "4.6", "output": "5" }, { "input": "4.7", "output": "5" }, { "input": "4.8", "output": "5" }, { "input": "4.9", "output": "5" }, { "input": "5.0", "output": "5" }, { "input": "5.1", "output": "5" }, { "input": "5.2", "output": "5" }, { "input": "5.3", "output": "5" }, { "input": "5.4", "output": "5" }, { "input": "5.5", "output": "6" }, { "input": "5.6", "output": "6" }, { "input": "5.7", "output": "6" }, { "input": "5.8", "output": "6" }, { "input": "5.9", "output": "6" }, { "input": "6.0", "output": "6" }, { "input": "6.1", "output": "6" }, { "input": "6.2", "output": "6" }, { "input": "6.3", "output": "6" }, { "input": "6.4", "output": "6" }, { "input": "6.5", "output": "7" }, { "input": "6.6", "output": "7" }, { "input": "6.7", "output": "7" }, { "input": "6.8", "output": "7" }, { "input": "6.9", "output": "7" }, { "input": "7.0", "output": "7" }, { "input": "7.1", "output": "7" }, { "input": "7.2", "output": "7" }, { "input": "7.3", "output": "7" }, { "input": "7.4", "output": "7" }, { "input": "7.5", "output": "8" }, { "input": "7.6", "output": "8" }, { "input": "7.7", "output": "8" }, { "input": "7.8", "output": "8" }, { "input": "7.9", "output": "8" }, { "input": "8.0", "output": "8" }, { "input": "8.1", "output": "8" }, { "input": "8.2", "output": "8" }, { "input": "8.3", "output": "8" }, { "input": "8.4", "output": "8" }, { "input": "8.5", "output": "9" }, { "input": "8.6", "output": "9" }, { "input": "8.7", "output": "9" }, { "input": "8.8", "output": "9" }, { "input": "8.9", "output": "9" }, { "input": "9.0", "output": "GOTO Vasilisa." }, { "input": "9.1", "output": "GOTO Vasilisa." }, { "input": "9.2", "output": "GOTO Vasilisa." }, { "input": "9.3", "output": "GOTO Vasilisa." }, { "input": "9.4", "output": "GOTO Vasilisa." }, { "input": "9.5", "output": "GOTO Vasilisa." }, { "input": "9.6", "output": "GOTO Vasilisa." }, { "input": "9.7", "output": "GOTO Vasilisa." }, { "input": "9.8", "output": "GOTO Vasilisa." }, { "input": "9.9", "output": "GOTO Vasilisa." }, { "input": "609942239104813108618306232517836377583566292129955473517174437591594761209877970062547641606473593416245554763832875919009472288995880898848455284062760160557686724163817329189799336769669146848904803188614226720978399787805489531837751080926098.1664915772983166314490532653577560222779830866949001942720729759794777105570672781798092416748052690224813237139640723361527601154465287615917169132637313918577673651098507390501962", "output": "609942239104813108618306232517836377583566292129955473517174437591594761209877970062547641606473593416245554763832875919009472288995880898848455284062760160557686724163817329189799336769669146848904803188614226720978399787805489531837751080926098" }, { "input": "7002108534951820589946967018226114921984364117669853212254634761258884835434844673935047882480101006606512119541798298905598015607366335061012709906661245805358900665571472645463994925687210711492820804158354236327017974683658305043146543214454877759341394.20211856263503281388748282682120712214711232598021393495443628276945042110862480888110959179019986486690931930108026302665438087068150666835901617457150158918705186964935221768346957536540345814875615118637945520917367155931078965", "output": "7002108534951820589946967018226114921984364117669853212254634761258884835434844673935047882480101006606512119541798298905598015607366335061012709906661245805358900665571472645463994925687210711492820804158354236327017974683658305043146543214454877759341394" }, { "input": "1950583094879039694852660558765931995628486712128191844305265555887022812284005463780616067.5000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", "output": "1950583094879039694852660558765931995628486712128191844305265555887022812284005463780616068" }, { "input": "718130341896330596635811874410345440628950330.500000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", "output": "718130341896330596635811874410345440628950331" }, { "input": "927925904158088313481229162503626281882161630091489367140850985555900173018122871746924067186432044676083646964286435457446768031295712712803570690846298544912543439221596866052681116386179629036945370280722.500000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", "output": "927925904158088313481229162503626281882161630091489367140850985555900173018122871746924067186432044676083646964286435457446768031295712712803570690846298544912543439221596866052681116386179629036945370280723" }, { "input": "68289614863244584294178637364598054554769889.500000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", "output": "GOTO Vasilisa." }, { "input": "7536521504744364134984603189602839063535643888645969434165019366202558753840519.4999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999", "output": "GOTO Vasilisa." }, { "input": "646188694587964249318078225173.5000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", "output": "646188694587964249318078225174" }, { "input": "7017472758334494297677068672222822550374695787171163207025095950296957261530.50", "output": "7017472758334494297677068672222822550374695787171163207025095950296957261531" }, { "input": "259085737066615534998640212505663524594409165063310128108448186246980628179842202905722595400477937071746695941939306735605849342959111887834258250883469840846714848774368.50000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", "output": "259085737066615534998640212505663524594409165063310128108448186246980628179842202905722595400477937071746695941939306735605849342959111887834258250883469840846714848774369" }, { "input": "682500858233333594535201113441004740771119672961581796618069185960107115823662126812159957094407454522028503739299.5000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", "output": "GOTO Vasilisa." }, { "input": "41203422675619090661099806687619.49999999999999999999999999999999999999999999999999999999999999999999999999999999999999999", "output": "GOTO Vasilisa." } ]
1,574,124,741
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
0
186
0
a = float(input()) round(a) if(a%10 == 9):print("GOTO Vasilisa.") else:print(a)
Title: Help Far Away Kingdom Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: In a far away kingdom lived the King, the Prince, the Shoemaker, the Dressmaker and many other citizens. They lived happily until great trouble came into the Kingdom. The ACMers settled there. Most damage those strange creatures inflicted upon the kingdom was that they loved high precision numbers. As a result, the Kingdom healers had already had three appointments with the merchants who were asked to sell, say, exactly 0.273549107 beer barrels. To deal with the problem somehow, the King issued an order obliging rounding up all numbers to the closest integer to simplify calculations. Specifically, the order went like this: - If a number's integer part does not end with digit 9 and its fractional part is strictly less than 0.5, then the rounded up number coincides with the number’s integer part. - If a number's integer part does not end with digit 9 and its fractional part is not less than 0.5, the rounded up number is obtained if we add 1 to the last digit of the number’s integer part.- If the number’s integer part ends with digit 9, to round up the numbers one should go to Vasilisa the Wise. In the whole Kingdom she is the only one who can perform the tricky operation of carrying into the next position. Merchants found the algorithm very sophisticated and they asked you (the ACMers) to help them. Can you write a program that would perform the rounding according to the King’s order? Input Specification: The first line contains a single number to round up — the integer part (a non-empty set of decimal digits that do not start with 0 — with the exception of a case when the set consists of a single digit — in this case 0 can go first), then follows character «.» (a dot), and then follows the fractional part (any non-empty set of decimal digits). The number's length does not exceed 1000 characters, including the dot. There are no other characters in the input data. Output Specification: If the last number of the integer part is not equal to 9, print the rounded-up number without leading zeroes. Otherwise, print the message "GOTO Vasilisa." (without the quotes). Demo Input: ['0.0\n', '1.49\n', '1.50\n', '2.71828182845904523536\n', '3.14159265358979323846\n', '12345678901234567890.1\n', '123456789123456789.999\n'] Demo Output: ['0', '1', '2', '3', '3', '12345678901234567890', 'GOTO Vasilisa.'] Note: none
```python a = float(input()) round(a) if(a%10 == 9):print("GOTO Vasilisa.") else:print(a) ```
0
650
A
Watchmen
PROGRAMMING
1,400
[ "data structures", "geometry", "math" ]
null
null
Watchmen are in a danger and Doctor Manhattan together with his friend Daniel Dreiberg should warn them as soon as possible. There are *n* watchmen on a plane, the *i*-th watchman is located at point (*x**i*,<=*y**i*). They need to arrange a plan, but there are some difficulties on their way. As you know, Doctor Manhattan considers the distance between watchmen *i* and *j* to be |*x**i*<=-<=*x**j*|<=+<=|*y**i*<=-<=*y**j*|. Daniel, as an ordinary person, calculates the distance using the formula . The success of the operation relies on the number of pairs (*i*,<=*j*) (1<=≤<=*i*<=&lt;<=*j*<=≤<=*n*), such that the distance between watchman *i* and watchmen *j* calculated by Doctor Manhattan is equal to the distance between them calculated by Daniel. You were asked to compute the number of such pairs.
The first line of the input contains the single integer *n* (1<=≤<=*n*<=≤<=200<=000) — the number of watchmen. Each of the following *n* lines contains two integers *x**i* and *y**i* (|*x**i*|,<=|*y**i*|<=≤<=109). Some positions may coincide.
Print the number of pairs of watchmen such that the distance between them calculated by Doctor Manhattan is equal to the distance calculated by Daniel.
[ "3\n1 1\n7 5\n1 5\n", "6\n0 0\n0 1\n0 2\n-1 1\n0 1\n1 1\n" ]
[ "2\n", "11\n" ]
In the first sample, the distance between watchman 1 and watchman 2 is equal to |1 - 7| + |1 - 5| = 10 for Doctor Manhattan and <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/bcb5b7064b5f02088da0fdcf677e6fda495dd0df.png" style="max-width: 100.0%;max-height: 100.0%;"/> for Daniel. For pairs (1, 1), (1, 5) and (7, 5), (1, 5) Doctor Manhattan and Daniel will calculate the same distances.
500
[ { "input": "3\n1 1\n7 5\n1 5", "output": "2" }, { "input": "6\n0 0\n0 1\n0 2\n-1 1\n0 1\n1 1", "output": "11" }, { "input": "10\n46 -55\n46 45\n46 45\n83 -55\n46 45\n83 -55\n46 45\n83 45\n83 45\n46 -55", "output": "33" }, { "input": "1\n-5 -90", "output": "0" }, { "input": "2\n315 845\n-669 -762", "output": "0" }, { "input": "3\n8911 7861\n-6888 7861\n8911 7861", "output": "3" }, { "input": "2\n-1 1000000000\n0 -1", "output": "0" }, { "input": "2\n1000000000 0\n-7 1", "output": "0" }, { "input": "2\n1 4\n2 1", "output": "0" }, { "input": "2\n1 0\n0 2333333", "output": "0" }, { "input": "2\n2 1\n1 2", "output": "0" }, { "input": "2\n1 1000000000\n2 -1000000000", "output": "0" }, { "input": "2\n0 1000000000\n1 -7", "output": "0" }, { "input": "2\n1 0\n0 19990213", "output": "0" } ]
1,625,943,984
2,147,483,647
PyPy 3
TIME_LIMIT_EXCEEDED
TESTS
9
3,000
60,211,200
import sys from math import sqrt n, ls = 0, [] for i, line in enumerate(sys.stdin): line = [int(x) for x in line.split()] if i == 0: n = line[0] ls = [()]*n else: ls[i-1] = (line[0], line[1], line[0]**2, line[1]**2) pairs = 0 for i, v in enumerate(ls): for j, w in enumerate(ls[i+1:]): x = v[2]-2*v[0]*w[0]+w[2] if x == 0: pairs+=1 continue y = v[3]-2*v[1]*w[1]+w[3] if y == 0: pairs+=1 continue res = x+y if res == 0 or res == 1: pairs+=1 continue print(pairs)
Title: Watchmen Time Limit: None seconds Memory Limit: None megabytes Problem Description: Watchmen are in a danger and Doctor Manhattan together with his friend Daniel Dreiberg should warn them as soon as possible. There are *n* watchmen on a plane, the *i*-th watchman is located at point (*x**i*,<=*y**i*). They need to arrange a plan, but there are some difficulties on their way. As you know, Doctor Manhattan considers the distance between watchmen *i* and *j* to be |*x**i*<=-<=*x**j*|<=+<=|*y**i*<=-<=*y**j*|. Daniel, as an ordinary person, calculates the distance using the formula . The success of the operation relies on the number of pairs (*i*,<=*j*) (1<=≤<=*i*<=&lt;<=*j*<=≤<=*n*), such that the distance between watchman *i* and watchmen *j* calculated by Doctor Manhattan is equal to the distance between them calculated by Daniel. You were asked to compute the number of such pairs. Input Specification: The first line of the input contains the single integer *n* (1<=≤<=*n*<=≤<=200<=000) — the number of watchmen. Each of the following *n* lines contains two integers *x**i* and *y**i* (|*x**i*|,<=|*y**i*|<=≤<=109). Some positions may coincide. Output Specification: Print the number of pairs of watchmen such that the distance between them calculated by Doctor Manhattan is equal to the distance calculated by Daniel. Demo Input: ['3\n1 1\n7 5\n1 5\n', '6\n0 0\n0 1\n0 2\n-1 1\n0 1\n1 1\n'] Demo Output: ['2\n', '11\n'] Note: In the first sample, the distance between watchman 1 and watchman 2 is equal to |1 - 7| + |1 - 5| = 10 for Doctor Manhattan and <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/bcb5b7064b5f02088da0fdcf677e6fda495dd0df.png" style="max-width: 100.0%;max-height: 100.0%;"/> for Daniel. For pairs (1, 1), (1, 5) and (7, 5), (1, 5) Doctor Manhattan and Daniel will calculate the same distances.
```python import sys from math import sqrt n, ls = 0, [] for i, line in enumerate(sys.stdin): line = [int(x) for x in line.split()] if i == 0: n = line[0] ls = [()]*n else: ls[i-1] = (line[0], line[1], line[0]**2, line[1]**2) pairs = 0 for i, v in enumerate(ls): for j, w in enumerate(ls[i+1:]): x = v[2]-2*v[0]*w[0]+w[2] if x == 0: pairs+=1 continue y = v[3]-2*v[1]*w[1]+w[3] if y == 0: pairs+=1 continue res = x+y if res == 0 or res == 1: pairs+=1 continue print(pairs) ```
0
740
A
Alyona and copybooks
PROGRAMMING
1,300
[ "brute force", "implementation" ]
null
null
Little girl Alyona is in a shop to buy some copybooks for school. She study four subjects so she wants to have equal number of copybooks for each of the subjects. There are three types of copybook's packs in the shop: it is possible to buy one copybook for *a* rubles, a pack of two copybooks for *b* rubles, and a pack of three copybooks for *c* rubles. Alyona already has *n* copybooks. What is the minimum amount of rubles she should pay to buy such number of copybooks *k* that *n*<=+<=*k* is divisible by 4? There are infinitely many packs of any type in the shop. Alyona can buy packs of different type in the same purchase.
The only line contains 4 integers *n*, *a*, *b*, *c* (1<=≤<=*n*,<=*a*,<=*b*,<=*c*<=≤<=109).
Print the minimum amount of rubles she should pay to buy such number of copybooks *k* that *n*<=+<=*k* is divisible by 4.
[ "1 1 3 4\n", "6 2 1 1\n", "4 4 4 4\n", "999999999 1000000000 1000000000 1000000000\n" ]
[ "3\n", "1\n", "0\n", "1000000000\n" ]
In the first example Alyona can buy 3 packs of 1 copybook for 3*a* = 3 rubles in total. After that she will have 4 copybooks which she can split between the subjects equally. In the second example Alyuna can buy a pack of 2 copybooks for *b* = 1 ruble. She will have 8 copybooks in total. In the third example Alyona can split the copybooks she already has between the 4 subject equally, so she doesn't need to buy anything. In the fourth example Alyona should buy one pack of one copybook.
500
[ { "input": "1 1 3 4", "output": "3" }, { "input": "6 2 1 1", "output": "1" }, { "input": "4 4 4 4", "output": "0" }, { "input": "999999999 1000000000 1000000000 1000000000", "output": "1000000000" }, { "input": "1016 3 2 1", "output": "0" }, { "input": "17 100 100 1", "output": "1" }, { "input": "17 2 3 100", "output": "5" }, { "input": "18 1 3 3", "output": "2" }, { "input": "19 1 1 1", "output": "1" }, { "input": "999999997 999999990 1000000000 1000000000", "output": "1000000000" }, { "input": "999999998 1000000000 999999990 1000000000", "output": "999999990" }, { "input": "634074578 336470888 481199252 167959139", "output": "335918278" }, { "input": "999999999 1000000000 1000000000 999999990", "output": "1000000000" }, { "input": "804928248 75475634 54748096 641009859", "output": "0" }, { "input": "535590429 374288891 923264237 524125987", "output": "524125987" }, { "input": "561219907 673102149 496813081 702209411", "output": "673102149" }, { "input": "291882089 412106895 365329221 585325539", "output": "585325539" }, { "input": "757703054 5887448 643910770 58376259", "output": "11774896" }, { "input": "783332532 449924898 72235422 941492387", "output": "0" }, { "input": "513994713 43705451 940751563 824608515", "output": "131116353" }, { "input": "539624191 782710197 514300407 2691939", "output": "8075817" }, { "input": "983359971 640274071 598196518 802030518", "output": "640274071" }, { "input": "8989449 379278816 26521171 685146646", "output": "405799987" }, { "input": "34618927 678092074 895037311 863230070", "output": "678092074" }, { "input": "205472596 417096820 468586155 41313494", "output": "0" }, { "input": "19 5 1 2", "output": "3" }, { "input": "17 1 2 2", "output": "2" }, { "input": "18 3 3 1", "output": "2" }, { "input": "19 4 3 1", "output": "3" }, { "input": "936134778 715910077 747167704 219396918", "output": "438793836" }, { "input": "961764255 454914823 615683844 102513046", "output": "307539138" }, { "input": "692426437 48695377 189232688 985629174", "output": "146086131" }, { "input": "863280107 347508634 912524637 458679894", "output": "347508634" }, { "input": "593942288 86513380 486073481 341796022", "output": "0" }, { "input": "914539062 680293934 764655030 519879446", "output": "764655030" }, { "input": "552472140 509061481 586588704 452405440", "output": "0" }, { "input": "723325809 807874739 160137548 335521569", "output": "335521569" }, { "input": "748955287 546879484 733686393 808572289", "output": "546879484" }, { "input": "774584765 845692742 162011045 691688417", "output": "691688417" }, { "input": "505246946 439473295 30527185 869771841", "output": "30527185" }, { "input": "676100616 178478041 604076030 752887969", "output": "0" }, { "input": "701730093 477291299 177624874 930971393", "output": "654916173" }, { "input": "432392275 216296044 751173719 109054817", "output": "216296044" }, { "input": "458021753 810076598 324722563 992170945", "output": "992170945" }, { "input": "188683934 254114048 48014511 170254369", "output": "48014511" }, { "input": "561775796 937657403 280013594 248004555", "output": "0" }, { "input": "1000000000 1000000000 1000000000 1000000000", "output": "0" }, { "input": "3 10000 10000 3", "output": "9" }, { "input": "3 12 3 4", "output": "7" }, { "input": "3 10000 10000 1", "output": "3" }, { "input": "3 1000 1000 1", "output": "3" }, { "input": "3 10 10 1", "output": "3" }, { "input": "3 100 100 1", "output": "3" }, { "input": "3 100000 10000 1", "output": "3" }, { "input": "7 10 2 3", "output": "5" }, { "input": "3 1000 1000 2", "output": "6" }, { "input": "1 100000 1 100000", "output": "100000" }, { "input": "7 4 3 1", "output": "3" }, { "input": "3 1000 1000 3", "output": "9" }, { "input": "3 1000 1 1", "output": "2" }, { "input": "3 10 1 1", "output": "2" }, { "input": "3 100000 1 1", "output": "2" }, { "input": "3 100 1 1", "output": "2" }, { "input": "3 100000 100000 1", "output": "3" }, { "input": "3 1000 1 100", "output": "101" }, { "input": "3 1000000000 1 1000000000", "output": "1000000000" }, { "input": "3 1000 1 10", "output": "11" }, { "input": "3 200 1 100", "output": "101" }, { "input": "7 4 1 1", "output": "2" }, { "input": "7 4 12 1", "output": "3" }, { "input": "3 9 1 1", "output": "2" }, { "input": "3 10000000 1000000 1", "output": "3" }, { "input": "7 1000 1000 1", "output": "3" }, { "input": "3 10000 1 30", "output": "31" }, { "input": "3 1000 1 2", "output": "3" }, { "input": "7 12 6 1", "output": "3" }, { "input": "3 100000 1 1000", "output": "1001" }, { "input": "7 1000 1000 3", "output": "9" }, { "input": "3 4 3 1", "output": "3" }, { "input": "3 3000000 1 100000", "output": "100001" }, { "input": "3 3 1 1", "output": "2" }, { "input": "3 10 1 5", "output": "6" }, { "input": "3 2000 2000 1", "output": "3" }, { "input": "3 10000000 10000000 1", "output": "3" }, { "input": "3 5 1 1", "output": "2" }, { "input": "3 100 1 33", "output": "34" }, { "input": "7 9 2 7", "output": "9" }, { "input": "4448 2 3 6", "output": "0" }, { "input": "2228 1 6 3", "output": "0" } ]
1,484,659,844
2,147,483,647
Python 3
OK
TESTS
89
77
4,608,000
n,a,b,c=map(int,input().split()) if n%4==0: print(0) if (n+1)%4==0: print(min(a,b+c,3*c)) if (n+2)%4==0: print(min(2*a,b,c*2)) if (n+3)%4==0: print(min(3*a,b+a,c))
Title: Alyona and copybooks Time Limit: None seconds Memory Limit: None megabytes Problem Description: Little girl Alyona is in a shop to buy some copybooks for school. She study four subjects so she wants to have equal number of copybooks for each of the subjects. There are three types of copybook's packs in the shop: it is possible to buy one copybook for *a* rubles, a pack of two copybooks for *b* rubles, and a pack of three copybooks for *c* rubles. Alyona already has *n* copybooks. What is the minimum amount of rubles she should pay to buy such number of copybooks *k* that *n*<=+<=*k* is divisible by 4? There are infinitely many packs of any type in the shop. Alyona can buy packs of different type in the same purchase. Input Specification: The only line contains 4 integers *n*, *a*, *b*, *c* (1<=≤<=*n*,<=*a*,<=*b*,<=*c*<=≤<=109). Output Specification: Print the minimum amount of rubles she should pay to buy such number of copybooks *k* that *n*<=+<=*k* is divisible by 4. Demo Input: ['1 1 3 4\n', '6 2 1 1\n', '4 4 4 4\n', '999999999 1000000000 1000000000 1000000000\n'] Demo Output: ['3\n', '1\n', '0\n', '1000000000\n'] Note: In the first example Alyona can buy 3 packs of 1 copybook for 3*a* = 3 rubles in total. After that she will have 4 copybooks which she can split between the subjects equally. In the second example Alyuna can buy a pack of 2 copybooks for *b* = 1 ruble. She will have 8 copybooks in total. In the third example Alyona can split the copybooks she already has between the 4 subject equally, so she doesn't need to buy anything. In the fourth example Alyona should buy one pack of one copybook.
```python n,a,b,c=map(int,input().split()) if n%4==0: print(0) if (n+1)%4==0: print(min(a,b+c,3*c)) if (n+2)%4==0: print(min(2*a,b,c*2)) if (n+3)%4==0: print(min(3*a,b+a,c)) ```
3
75
A
Life Without Zeros
PROGRAMMING
1,000
[ "implementation" ]
A. Life Without Zeros
2
256
Can you imagine our life if we removed all zeros from it? For sure we will have many problems. In this problem we will have a simple example if we removed all zeros from our life, it's the addition operation. Let's assume you are given this equation *a*<=+<=*b*<==<=*c*, where *a* and *b* are positive integers, and *c* is the sum of *a* and *b*. Now let's remove all zeros from this equation. Will the equation remain correct after removing all zeros? For example if the equation is 101<=+<=102<==<=203, if we removed all zeros it will be 11<=+<=12<==<=23 which is still a correct equation. But if the equation is 105<=+<=106<==<=211, if we removed all zeros it will be 15<=+<=16<==<=211 which is not a correct equation.
The input will consist of two lines, the first line will contain the integer *a*, and the second line will contain the integer *b* which are in the equation as described above (1<=≤<=*a*,<=*b*<=≤<=109). There won't be any leading zeros in both. The value of *c* should be calculated as *c*<==<=*a*<=+<=*b*.
The output will be just one line, you should print "YES" if the equation will remain correct after removing all zeros, and print "NO" otherwise.
[ "101\n102\n", "105\n106\n" ]
[ "YES\n", "NO\n" ]
none
500
[ { "input": "101\n102", "output": "YES" }, { "input": "105\n106", "output": "NO" }, { "input": "544\n397", "output": "YES" }, { "input": "822\n280", "output": "NO" }, { "input": "101\n413", "output": "NO" }, { "input": "309\n139", "output": "NO" }, { "input": "693\n970", "output": "NO" }, { "input": "981\n1", "output": "YES" }, { "input": "352\n276", "output": "YES" }, { "input": "164\n691", "output": "YES" }, { "input": "110036\n43", "output": "YES" }, { "input": "100\n1000", "output": "NO" }, { "input": "1000000000\n1000000000", "output": "YES" }, { "input": "999999999\n999999999", "output": "YES" }, { "input": "6\n4", "output": "NO" }, { "input": "123456\n876543", "output": "YES" }, { "input": "1234567\n9876543", "output": "NO" }, { "input": "1111111\n1119111", "output": "NO" }, { "input": "10502405\n40403403", "output": "YES" }, { "input": "1\n1", "output": "YES" }, { "input": "5\n4", "output": "YES" }, { "input": "1\n6", "output": "YES" }, { "input": "40\n17", "output": "NO" }, { "input": "35\n81", "output": "YES" }, { "input": "347\n908", "output": "NO" }, { "input": "2081\n7450", "output": "NO" }, { "input": "84355694\n373629503", "output": "NO" }, { "input": "885992048\n510468672", "output": "NO" }, { "input": "540144752\n647307841", "output": "NO" }, { "input": "341781108\n784147010", "output": "NO" }, { "input": "960440938\n572334653", "output": "NO" }, { "input": "657414510\n768771903", "output": "NO" }, { "input": "501871728\n725074574", "output": "NO" }, { "input": "968\n851", "output": "YES" }, { "input": "943\n939", "output": "YES" }, { "input": "347\n908", "output": "NO" }, { "input": "611\n41", "output": "YES" }, { "input": "737\n289", "output": "NO" }, { "input": "168\n571", "output": "YES" }, { "input": "868\n463", "output": "YES" }, { "input": "815732007\n913882008", "output": "NO" }, { "input": "459039901\n453033850", "output": "NO" }, { "input": "975305404\n484601256", "output": "NO" } ]
1,500,357,997
2,147,483,647
Python 3
OK
TESTS
43
124
4,608,000
n = int(input().strip()) m = int(input().strip()) c = str(n+m) n = str(n) m = str(m) cc = mm = nn = [] jn = '' jm = '' jc = '' for i in c: if i != '0': jc = jc + i for i in m: if i != '0': jm = jm + i for i in n : if i != '0': jn = jn + i if int(jn) + int(jm) == int(jc): print('YES') else: print('NO')
Title: Life Without Zeros Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: Can you imagine our life if we removed all zeros from it? For sure we will have many problems. In this problem we will have a simple example if we removed all zeros from our life, it's the addition operation. Let's assume you are given this equation *a*<=+<=*b*<==<=*c*, where *a* and *b* are positive integers, and *c* is the sum of *a* and *b*. Now let's remove all zeros from this equation. Will the equation remain correct after removing all zeros? For example if the equation is 101<=+<=102<==<=203, if we removed all zeros it will be 11<=+<=12<==<=23 which is still a correct equation. But if the equation is 105<=+<=106<==<=211, if we removed all zeros it will be 15<=+<=16<==<=211 which is not a correct equation. Input Specification: The input will consist of two lines, the first line will contain the integer *a*, and the second line will contain the integer *b* which are in the equation as described above (1<=≤<=*a*,<=*b*<=≤<=109). There won't be any leading zeros in both. The value of *c* should be calculated as *c*<==<=*a*<=+<=*b*. Output Specification: The output will be just one line, you should print "YES" if the equation will remain correct after removing all zeros, and print "NO" otherwise. Demo Input: ['101\n102\n', '105\n106\n'] Demo Output: ['YES\n', 'NO\n'] Note: none
```python n = int(input().strip()) m = int(input().strip()) c = str(n+m) n = str(n) m = str(m) cc = mm = nn = [] jn = '' jm = '' jc = '' for i in c: if i != '0': jc = jc + i for i in m: if i != '0': jm = jm + i for i in n : if i != '0': jn = jn + i if int(jn) + int(jm) == int(jc): print('YES') else: print('NO') ```
3.960417
525
A
Vitaliy and Pie
PROGRAMMING
1,100
[ "greedy", "hashing", "strings" ]
null
null
After a hard day Vitaly got very hungry and he wants to eat his favorite potato pie. But it's not that simple. Vitaly is in the first room of the house with *n* room located in a line and numbered starting from one from left to right. You can go from the first room to the second room, from the second room to the third room and so on — you can go from the (*n*<=-<=1)-th room to the *n*-th room. Thus, you can go to room *x* only from room *x*<=-<=1. The potato pie is located in the *n*-th room and Vitaly needs to go there. Each pair of consecutive rooms has a door between them. In order to go to room *x* from room *x*<=-<=1, you need to open the door between the rooms with the corresponding key. In total the house has several types of doors (represented by uppercase Latin letters) and several types of keys (represented by lowercase Latin letters). The key of type *t* can open the door of type *T* if and only if *t* and *T* are the same letter, written in different cases. For example, key f can open door F. Each of the first *n*<=-<=1 rooms contains exactly one key of some type that Vitaly can use to get to next rooms. Once the door is open with some key, Vitaly won't get the key from the keyhole but he will immediately run into the next room. In other words, each key can open no more than one door. Vitaly realizes that he may end up in some room without the key that opens the door to the next room. Before the start his run for the potato pie Vitaly can buy any number of keys of any type that is guaranteed to get to room *n*. Given the plan of the house, Vitaly wants to know what is the minimum number of keys he needs to buy to surely get to the room *n*, which has a delicious potato pie. Write a program that will help Vitaly find out this number.
The first line of the input contains a positive integer *n* (2<=≤<=*n*<=≤<=105) — the number of rooms in the house. The second line of the input contains string *s* of length 2·*n*<=-<=2. Let's number the elements of the string from left to right, starting from one. The odd positions in the given string *s* contain lowercase Latin letters — the types of the keys that lie in the corresponding rooms. Thus, each odd position *i* of the given string *s* contains a lowercase Latin letter — the type of the key that lies in room number (*i*<=+<=1)<=/<=2. The even positions in the given string contain uppercase Latin letters — the types of doors between the rooms. Thus, each even position *i* of the given string *s* contains an uppercase letter — the type of the door that leads from room *i*<=/<=2 to room *i*<=/<=2<=+<=1.
Print the only integer — the minimum number of keys that Vitaly needs to buy to surely get from room one to room *n*.
[ "3\naAbB\n", "4\naBaCaB\n", "5\nxYyXzZaZ\n" ]
[ "0\n", "3\n", "2\n" ]
none
250
[ { "input": "3\naAbB", "output": "0" }, { "input": "4\naBaCaB", "output": "3" }, { "input": "5\nxYyXzZaZ", "output": "2" }, { "input": "26\naAbBcCdDeEfFgGhHiIjJkKlLmMnNoOpPqQrRsStTuUvVwWxXyY", "output": "0" }, { "input": "26\nzAyBxCwDvEuFtGsHrIqJpKoLnMmNlOkPjQiRhSgTfUeVdWcXbY", "output": "13" }, { "input": "5\naArRaRaR", "output": "2" }, { "input": "2\ndA", "output": "1" }, { "input": "2\ncB", "output": "1" }, { "input": "10\nhNcMeXsSlHsUwYeMcA", "output": "7" }, { "input": "100\nqDpInBmCrFwXpDbFgOzVvOcEmJrUcToAdEwEgTvBvBfWwRpGyEaXgDdRwVlQnYgWmWhMrHaIzPyXvGaFlRsVzHhZrOuVpXrKxFzAmWwPlFtNfPtJxVmLuHjKfYyArHrEnSwSzOvDpQhCgCqLlAcNpGhXrEeFuCmAqIkXyYtSsQwIxJzNiIuTgEbVuWrMwPrAlLyKaZ", "output": "42" }, { "input": "2\ndD", "output": "0" }, { "input": "2\ndE", "output": "1" }, { "input": "3\ndDdD", "output": "0" }, { "input": "3\ndEdD", "output": "1" }, { "input": "3\ndEeD", "output": "1" }, { "input": "3\ndEeF", "output": "2" } ]
1,586,711,173
2,147,483,647
Python 3
OK
TESTS
46
343
1,126,400
n = int(input()) s = input() D = dict() D_mins = dict() for i in range(len(s)): if i % 2 == 0: if s[i] in D: D[s[i]] += 1 else: D[s[i]] = 1 if s[i] in D_mins: D_mins[s[i]] = min(D_mins[s[i]], D[s[i]]) else: D_mins[s[i]] = 1 else: key = s[i].lower() if key in D: D[key] -= 1 else: D[key] = -1 if key in D_mins: D_mins[key] = min(D_mins[key], D[key]) else: D_mins[key] = -1 key_to_buy = 0 for elem in D_mins.values(): if elem < 0: key_to_buy += elem print(-key_to_buy)
Title: Vitaliy and Pie Time Limit: None seconds Memory Limit: None megabytes Problem Description: After a hard day Vitaly got very hungry and he wants to eat his favorite potato pie. But it's not that simple. Vitaly is in the first room of the house with *n* room located in a line and numbered starting from one from left to right. You can go from the first room to the second room, from the second room to the third room and so on — you can go from the (*n*<=-<=1)-th room to the *n*-th room. Thus, you can go to room *x* only from room *x*<=-<=1. The potato pie is located in the *n*-th room and Vitaly needs to go there. Each pair of consecutive rooms has a door between them. In order to go to room *x* from room *x*<=-<=1, you need to open the door between the rooms with the corresponding key. In total the house has several types of doors (represented by uppercase Latin letters) and several types of keys (represented by lowercase Latin letters). The key of type *t* can open the door of type *T* if and only if *t* and *T* are the same letter, written in different cases. For example, key f can open door F. Each of the first *n*<=-<=1 rooms contains exactly one key of some type that Vitaly can use to get to next rooms. Once the door is open with some key, Vitaly won't get the key from the keyhole but he will immediately run into the next room. In other words, each key can open no more than one door. Vitaly realizes that he may end up in some room without the key that opens the door to the next room. Before the start his run for the potato pie Vitaly can buy any number of keys of any type that is guaranteed to get to room *n*. Given the plan of the house, Vitaly wants to know what is the minimum number of keys he needs to buy to surely get to the room *n*, which has a delicious potato pie. Write a program that will help Vitaly find out this number. Input Specification: The first line of the input contains a positive integer *n* (2<=≤<=*n*<=≤<=105) — the number of rooms in the house. The second line of the input contains string *s* of length 2·*n*<=-<=2. Let's number the elements of the string from left to right, starting from one. The odd positions in the given string *s* contain lowercase Latin letters — the types of the keys that lie in the corresponding rooms. Thus, each odd position *i* of the given string *s* contains a lowercase Latin letter — the type of the key that lies in room number (*i*<=+<=1)<=/<=2. The even positions in the given string contain uppercase Latin letters — the types of doors between the rooms. Thus, each even position *i* of the given string *s* contains an uppercase letter — the type of the door that leads from room *i*<=/<=2 to room *i*<=/<=2<=+<=1. Output Specification: Print the only integer — the minimum number of keys that Vitaly needs to buy to surely get from room one to room *n*. Demo Input: ['3\naAbB\n', '4\naBaCaB\n', '5\nxYyXzZaZ\n'] Demo Output: ['0\n', '3\n', '2\n'] Note: none
```python n = int(input()) s = input() D = dict() D_mins = dict() for i in range(len(s)): if i % 2 == 0: if s[i] in D: D[s[i]] += 1 else: D[s[i]] = 1 if s[i] in D_mins: D_mins[s[i]] = min(D_mins[s[i]], D[s[i]]) else: D_mins[s[i]] = 1 else: key = s[i].lower() if key in D: D[key] -= 1 else: D[key] = -1 if key in D_mins: D_mins[key] = min(D_mins[key], D[key]) else: D_mins[key] = -1 key_to_buy = 0 for elem in D_mins.values(): if elem < 0: key_to_buy += elem print(-key_to_buy) ```
3
155
A
I_love_\%username\%
PROGRAMMING
800
[ "brute force" ]
null
null
Vasya adores sport programming. He can't write programs but he loves to watch the contests' progress. Vasya even has a favorite coder and Vasya pays special attention to him. One day Vasya decided to collect the results of all contests where his favorite coder participated and track the progress of his coolness. For each contest where this coder participated, he wrote out a single non-negative number — the number of points his favorite coder earned in the contest. Vasya wrote out the points for the contest in the order, in which the contests run (naturally, no two contests ran simultaneously). Vasya considers a coder's performance in a contest amazing in two situations: he can break either his best or his worst performance record. First, it is amazing if during the contest the coder earns strictly more points that he earned on each past contest. Second, it is amazing if during the contest the coder earns strictly less points that he earned on each past contest. A coder's first contest isn't considered amazing. Now he wants to count the number of amazing performances the coder had throughout his whole history of participating in contests. But the list of earned points turned out long and Vasya can't code... That's why he asks you to help him.
The first line contains the single integer *n* (1<=≤<=*n*<=≤<=1000) — the number of contests where the coder participated. The next line contains *n* space-separated non-negative integer numbers — they are the points which the coder has earned. The points are given in the chronological order. All points do not exceed 10000.
Print the single number — the number of amazing performances the coder has had during his whole history of participating in the contests.
[ "5\n100 50 200 150 200\n", "10\n4664 6496 5814 7010 5762 5736 6944 4850 3698 7242\n" ]
[ "2\n", "4\n" ]
In the first sample the performances number 2 and 3 are amazing. In the second sample the performances number 2, 4, 9 and 10 are amazing.
500
[ { "input": "5\n100 50 200 150 200", "output": "2" }, { "input": "10\n4664 6496 5814 7010 5762 5736 6944 4850 3698 7242", "output": "4" }, { "input": "1\n6", "output": "0" }, { "input": "2\n2 1", "output": "1" }, { "input": "5\n100 36 53 7 81", "output": "2" }, { "input": "5\n7 36 53 81 100", "output": "4" }, { "input": "5\n100 81 53 36 7", "output": "4" }, { "input": "10\n8 6 3 4 9 10 7 7 1 3", "output": "5" }, { "input": "10\n1627 1675 1488 1390 1812 1137 1746 1324 1952 1862", "output": "6" }, { "input": "10\n1 3 3 4 6 7 7 8 9 10", "output": "7" }, { "input": "10\n1952 1862 1812 1746 1675 1627 1488 1390 1324 1137", "output": "9" }, { "input": "25\n1448 4549 2310 2725 2091 3509 1565 2475 2232 3989 4231 779 2967 2702 608 3739 721 1552 2767 530 3114 665 1940 48 4198", "output": "5" }, { "input": "33\n1097 1132 1091 1104 1049 1038 1023 1080 1104 1029 1035 1061 1049 1060 1088 1106 1105 1087 1063 1076 1054 1103 1047 1041 1028 1120 1126 1063 1117 1110 1044 1093 1101", "output": "5" }, { "input": "34\n821 5536 2491 6074 7216 9885 764 1603 778 8736 8987 771 617 1587 8943 7922 439 7367 4115 8886 7878 6899 8811 5752 3184 3401 9760 9400 8995 4681 1323 6637 6554 6498", "output": "7" }, { "input": "68\n6764 6877 6950 6768 6839 6755 6726 6778 6699 6805 6777 6985 6821 6801 6791 6805 6940 6761 6677 6999 6911 6699 6959 6933 6903 6843 6972 6717 6997 6756 6789 6668 6735 6852 6735 6880 6723 6834 6810 6694 6780 6679 6698 6857 6826 6896 6979 6968 6957 6988 6960 6700 6919 6892 6984 6685 6813 6678 6715 6857 6976 6902 6780 6686 6777 6686 6842 6679", "output": "9" }, { "input": "60\n9000 9014 9034 9081 9131 9162 9174 9199 9202 9220 9221 9223 9229 9235 9251 9260 9268 9269 9270 9298 9307 9309 9313 9323 9386 9399 9407 9495 9497 9529 9531 9544 9614 9615 9627 9627 9643 9654 9656 9657 9685 9699 9701 9736 9745 9758 9799 9827 9843 9845 9854 9854 9885 9891 9896 9913 9942 9963 9986 9992", "output": "57" }, { "input": "100\n7 61 12 52 41 16 34 99 30 44 48 89 31 54 21 1 48 52 61 15 35 87 21 76 64 92 44 81 16 93 84 92 32 15 68 76 53 39 26 4 11 26 7 4 99 99 61 65 55 85 65 67 47 39 2 74 63 49 98 87 5 94 22 30 25 42 31 84 49 23 89 60 16 26 92 27 9 57 75 61 94 35 83 47 99 100 63 24 91 88 79 10 15 45 22 64 3 11 89 83", "output": "4" }, { "input": "100\n9999 9999 9999 9998 9998 9998 9997 9996 9996 9995 9993 9993 9991 9990 9989 9986 9984 9984 9983 9981 9981 9980 9980 9980 9979 9977 9977 9977 9977 9977 9976 9976 9975 9975 9973 9972 9972 9972 9972 9971 9969 9969 9969 9968 9967 9965 9962 9962 9962 9962 9960 9958 9958 9955 9954 9954 9954 9954 9950 9949 9949 9947 9943 9943 9940 9940 9939 9937 9937 9937 9936 9935 9932 9932 9931 9929 9927 9927 9926 9923 9919 9919 9918 9918 9918 9917 9917 9916 9916 9915 9914 9911 9910 9907 9907 9906 9905 9905 9904 9901", "output": "57" }, { "input": "100\n158 159 157 156 155 154 160 153 161 152 162 163 151 164 150 165 149 148 147 166 146 167 145 144 143 142 168 141 169 170 140 139 138 137 171 136 135 134 172 173 174 133 175 132 177 178 131 179 180 130 129 181 128 127 182 126 183 125 124 184 123 122 121 120 119 118 117 185 186 187 188 189 116 190 115 191 192 193 114 113 112 111 110 109 108 194 195 107 106 105 196 197 104 198 199 103 102 200 101 100", "output": "99" }, { "input": "2\n0 10000", "output": "1" }, { "input": "2\n5 5", "output": "0" }, { "input": "2\n1 1", "output": "0" }, { "input": "2\n10 10", "output": "0" }, { "input": "1\n0", "output": "0" } ]
1,696,930,448
2,147,483,647
PyPy 3-64
WRONG_ANSWER
TESTS
2
92
0
import sys #f=open("C:/Users/USER/Desktop/input.txt","r") f=sys.stdin n=int(f.readline()) l=list(map(int, f.readline().split())) low=0 high=0 c=0 for i in range(0,len(l)): if l[i]>high: high=l[i] c+=1 if l[i]<low: low=l[i] c+=1 print(c)
Title: I_love_\%username\% Time Limit: None seconds Memory Limit: None megabytes Problem Description: Vasya adores sport programming. He can't write programs but he loves to watch the contests' progress. Vasya even has a favorite coder and Vasya pays special attention to him. One day Vasya decided to collect the results of all contests where his favorite coder participated and track the progress of his coolness. For each contest where this coder participated, he wrote out a single non-negative number — the number of points his favorite coder earned in the contest. Vasya wrote out the points for the contest in the order, in which the contests run (naturally, no two contests ran simultaneously). Vasya considers a coder's performance in a contest amazing in two situations: he can break either his best or his worst performance record. First, it is amazing if during the contest the coder earns strictly more points that he earned on each past contest. Second, it is amazing if during the contest the coder earns strictly less points that he earned on each past contest. A coder's first contest isn't considered amazing. Now he wants to count the number of amazing performances the coder had throughout his whole history of participating in contests. But the list of earned points turned out long and Vasya can't code... That's why he asks you to help him. Input Specification: The first line contains the single integer *n* (1<=≤<=*n*<=≤<=1000) — the number of contests where the coder participated. The next line contains *n* space-separated non-negative integer numbers — they are the points which the coder has earned. The points are given in the chronological order. All points do not exceed 10000. Output Specification: Print the single number — the number of amazing performances the coder has had during his whole history of participating in the contests. Demo Input: ['5\n100 50 200 150 200\n', '10\n4664 6496 5814 7010 5762 5736 6944 4850 3698 7242\n'] Demo Output: ['2\n', '4\n'] Note: In the first sample the performances number 2 and 3 are amazing. In the second sample the performances number 2, 4, 9 and 10 are amazing.
```python import sys #f=open("C:/Users/USER/Desktop/input.txt","r") f=sys.stdin n=int(f.readline()) l=list(map(int, f.readline().split())) low=0 high=0 c=0 for i in range(0,len(l)): if l[i]>high: high=l[i] c+=1 if l[i]<low: low=l[i] c+=1 print(c) ```
0
701
A
Cards
PROGRAMMING
800
[ "greedy", "implementation" ]
null
null
There are *n* cards (*n* is even) in the deck. Each card has a positive integer written on it. *n*<=/<=2 people will play new card game. At the beginning of the game each player gets two cards, each card is given to exactly one player. Find the way to distribute cards such that the sum of values written of the cards will be equal for each player. It is guaranteed that it is always possible.
The first line of the input contains integer *n* (2<=≤<=*n*<=≤<=100) — the number of cards in the deck. It is guaranteed that *n* is even. The second line contains the sequence of *n* positive integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=100), where *a**i* is equal to the number written on the *i*-th card.
Print *n*<=/<=2 pairs of integers, the *i*-th pair denote the cards that should be given to the *i*-th player. Each card should be given to exactly one player. Cards are numbered in the order they appear in the input. It is guaranteed that solution exists. If there are several correct answers, you are allowed to print any of them.
[ "6\n1 5 7 4 4 3\n", "4\n10 10 10 10\n" ]
[ "1 3\n6 2\n4 5\n", "1 2\n3 4\n" ]
In the first sample, cards are distributed in such a way that each player has the sum of numbers written on his cards equal to 8. In the second sample, all values *a*<sub class="lower-index">*i*</sub> are equal. Thus, any distribution is acceptable.
500
[ { "input": "6\n1 5 7 4 4 3", "output": "1 3\n6 2\n4 5" }, { "input": "4\n10 10 10 10", "output": "1 4\n2 3" }, { "input": "100\n2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 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", "output": "1 100\n2 99\n3 98\n4 97\n5 96\n6 95\n7 94\n8 93\n9 92\n10 91\n11 90\n12 89\n13 88\n14 87\n15 86\n16 85\n17 84\n18 83\n19 82\n20 81\n21 80\n22 79\n23 78\n24 77\n25 76\n26 75\n27 74\n28 73\n29 72\n30 71\n31 70\n32 69\n33 68\n34 67\n35 66\n36 65\n37 64\n38 63\n39 62\n40 61\n41 60\n42 59\n43 58\n44 57\n45 56\n46 55\n47 54\n48 53\n49 52\n50 51" }, { "input": "4\n82 46 8 44", "output": "3 1\n4 2" }, { "input": "2\n35 50", "output": "1 2" }, { "input": "8\n24 39 49 38 44 64 44 50", "output": "1 6\n4 8\n2 3\n5 7" }, { "input": "100\n23 44 35 88 10 78 8 84 46 19 69 36 81 60 46 12 53 22 83 73 6 18 80 14 54 39 74 42 34 20 91 70 32 11 80 53 70 21 24 12 87 68 35 39 8 84 81 70 8 54 73 2 60 71 4 33 65 48 69 58 55 57 78 61 45 50 55 72 86 37 5 11 12 81 32 19 22 11 22 82 23 56 61 84 47 59 31 38 31 90 57 1 24 38 68 27 80 9 37 14", "output": "92 31\n52 90\n55 4\n71 41\n21 69\n7 84\n45 46\n49 8\n98 19\n5 80\n34 74\n72 47\n78 13\n16 97\n40 35\n73 23\n24 63\n100 6\n22 27\n10 51\n76 20\n30 68\n38 54\n18 48\n77 37\n79 32\n1 59\n81 11\n39 95\n93 42\n96 57\n87 83\n89 64\n33 53\n75 14\n56 86\n29 60\n3 91\n43 62\n12 82\n70 67\n99 61\n88 50\n94 25\n26 36\n44 17\n28 66\n2 58\n65 85\n9 15" }, { "input": "12\n22 83 2 67 55 12 40 93 83 73 12 28", "output": "3 8\n6 9\n11 2\n1 10\n12 4\n7 5" }, { "input": "16\n10 33 36 32 48 25 31 27 45 13 37 26 22 21 15 43", "output": "1 5\n10 9\n15 16\n14 11\n13 3\n6 2\n12 4\n8 7" }, { "input": "20\n18 13 71 60 28 10 20 65 65 12 13 14 64 68 6 50 72 7 66 58", "output": "15 17\n18 3\n6 14\n10 19\n2 9\n11 8\n12 13\n1 4\n7 20\n5 16" }, { "input": "24\n59 39 25 22 46 21 24 70 60 11 46 42 44 37 13 37 41 58 72 23 25 61 58 62", "output": "10 19\n15 8\n6 24\n4 22\n20 9\n7 1\n3 23\n21 18\n14 11\n16 5\n2 13\n17 12" }, { "input": "28\n22 1 51 31 83 35 3 64 59 10 61 25 19 53 55 80 78 8 82 22 67 4 27 64 33 6 85 76", "output": "2 27\n7 5\n22 19\n26 16\n18 17\n10 28\n13 21\n1 24\n20 8\n12 11\n23 9\n4 15\n25 14\n6 3" }, { "input": "32\n41 42 22 68 40 52 66 16 73 25 41 21 36 60 46 30 24 55 35 10 54 52 70 24 20 56 3 34 35 6 51 8", "output": "27 9\n30 23\n32 4\n20 7\n8 14\n25 26\n12 18\n3 21\n17 22\n24 6\n10 31\n16 15\n28 2\n19 11\n29 1\n13 5" }, { "input": "36\n1 10 61 43 27 49 55 33 7 30 45 78 69 34 38 19 36 49 55 11 30 63 46 24 16 68 71 18 11 52 72 24 60 68 8 41", "output": "1 12\n9 31\n35 27\n2 13\n20 34\n29 26\n25 22\n28 3\n16 33\n24 19\n32 7\n5 30\n10 18\n21 6\n8 23\n14 11\n17 4\n15 36" }, { "input": "40\n7 30 13 37 37 56 45 28 61 28 23 33 44 63 58 52 21 2 42 19 10 32 9 7 61 15 58 20 45 4 46 24 35 17 50 4 20 48 41 55", "output": "18 14\n30 25\n36 9\n1 27\n24 15\n23 6\n21 40\n3 16\n26 35\n34 38\n20 31\n28 29\n37 7\n17 13\n11 19\n32 39\n8 5\n10 4\n2 33\n22 12" }, { "input": "44\n7 12 46 78 24 68 86 22 71 79 85 14 58 72 26 46 54 39 35 13 31 45 81 21 15 8 47 64 69 87 57 6 18 80 47 29 36 62 34 67 59 48 75 25", "output": "32 30\n1 7\n26 11\n2 23\n20 34\n12 10\n25 4\n33 43\n24 14\n8 9\n5 29\n44 6\n15 40\n36 28\n21 38\n39 41\n19 13\n37 31\n18 17\n22 42\n3 35\n16 27" }, { "input": "48\n57 38 16 25 34 57 29 38 60 51 72 78 22 39 10 33 20 16 12 3 51 74 9 88 4 70 56 65 86 18 33 12 77 78 52 87 68 85 81 5 61 2 52 39 80 13 74 30", "output": "42 24\n20 36\n25 29\n40 38\n23 39\n15 45\n19 34\n32 12\n46 33\n3 47\n18 22\n30 11\n17 26\n13 37\n4 28\n7 41\n48 9\n16 6\n31 1\n5 27\n2 43\n8 35\n14 21\n44 10" }, { "input": "52\n57 12 13 40 68 31 18 4 31 18 65 3 62 32 6 3 49 48 51 33 53 40 9 32 47 53 58 19 14 23 32 38 39 69 19 20 62 52 68 17 39 22 54 59 3 2 52 9 67 68 24 39", "output": "46 34\n12 50\n16 39\n45 5\n8 49\n15 11\n23 37\n48 13\n2 44\n3 27\n29 1\n40 43\n7 26\n10 21\n28 47\n35 38\n36 19\n42 17\n30 18\n51 25\n6 22\n9 4\n14 52\n24 41\n31 33\n20 32" }, { "input": "56\n53 59 66 68 71 25 48 32 12 61 72 69 30 6 56 55 25 49 60 47 46 46 66 19 31 9 23 15 10 12 71 53 51 32 39 31 66 66 17 52 12 7 7 22 49 12 71 29 63 7 47 29 18 39 27 26", "output": "14 11\n42 47\n43 31\n50 5\n26 12\n29 4\n9 38\n30 37\n41 23\n46 3\n28 49\n39 10\n53 19\n24 2\n44 15\n27 16\n6 32\n17 1\n56 40\n55 33\n48 45\n52 18\n13 7\n25 51\n36 20\n8 22\n34 21\n35 54" }, { "input": "60\n47 63 20 68 46 12 45 44 14 38 28 73 60 5 20 18 70 64 37 47 26 47 37 61 29 61 23 28 30 68 55 22 25 60 38 7 63 12 38 15 14 30 11 5 70 15 53 52 7 57 49 45 55 37 45 28 50 2 31 30", "output": "58 12\n14 45\n44 17\n36 30\n49 4\n43 18\n6 37\n38 2\n9 26\n41 24\n40 34\n46 13\n16 50\n3 53\n15 31\n32 47\n27 48\n33 57\n21 51\n11 22\n28 20\n56 1\n25 5\n29 55\n42 52\n60 7\n59 8\n19 39\n23 35\n54 10" }, { "input": "64\n63 39 19 5 48 56 49 45 29 68 25 59 37 69 62 26 60 44 60 6 67 68 2 40 56 6 19 12 17 70 23 11 59 37 41 55 30 68 72 14 38 34 3 71 2 4 55 15 31 66 15 51 36 72 18 7 6 14 43 33 8 35 57 18", "output": "23 54\n45 39\n43 44\n46 30\n4 14\n20 38\n26 22\n57 10\n56 21\n61 50\n32 1\n28 15\n40 19\n58 17\n48 33\n51 12\n29 63\n55 25\n64 6\n3 47\n27 36\n31 52\n11 7\n16 5\n9 8\n37 18\n49 59\n60 35\n42 24\n62 2\n53 41\n13 34" }, { "input": "68\n58 68 40 55 62 15 10 54 19 18 69 27 15 53 8 18 8 33 15 49 20 9 70 8 18 64 14 59 9 64 3 35 46 11 5 65 58 55 28 58 4 55 64 5 68 24 4 58 23 45 58 50 38 68 5 15 20 9 5 53 20 63 69 68 15 53 65 65", "output": "31 23\n41 63\n47 11\n35 64\n44 54\n55 45\n59 2\n15 68\n17 67\n24 36\n22 43\n29 30\n58 26\n7 62\n34 5\n27 28\n6 51\n13 48\n19 40\n56 37\n65 1\n10 42\n16 38\n25 4\n9 8\n21 66\n57 60\n61 14\n49 52\n46 20\n12 33\n39 50\n18 3\n32 53" }, { "input": "72\n61 13 55 23 24 55 44 33 59 19 14 17 66 40 27 33 29 37 28 74 50 56 59 65 64 17 42 56 73 51 64 23 22 26 38 22 36 47 60 14 52 28 14 12 6 41 73 5 64 67 61 74 54 34 45 34 44 4 34 49 18 72 44 47 31 19 11 31 5 4 45 50", "output": "58 52\n70 20\n48 47\n69 29\n45 62\n67 50\n44 13\n2 24\n11 49\n40 31\n43 25\n12 51\n26 1\n61 39\n10 23\n66 9\n33 28\n36 22\n4 6\n32 3\n5 53\n34 41\n15 30\n19 72\n42 21\n17 60\n65 64\n68 38\n8 71\n16 55\n54 63\n56 57\n59 7\n37 27\n18 46\n35 14" }, { "input": "76\n73 37 73 67 26 45 43 74 47 31 43 81 4 3 39 79 48 81 67 39 67 66 43 67 80 51 34 79 5 58 45 10 39 50 9 78 6 18 75 17 45 17 51 71 34 53 33 11 17 15 11 69 50 41 13 74 10 33 77 41 11 64 36 74 17 32 3 10 27 20 5 73 52 41 7 57", "output": "14 18\n67 12\n13 25\n29 28\n71 16\n37 36\n75 59\n35 39\n32 64\n57 56\n68 8\n48 72\n51 3\n61 1\n55 44\n50 52\n40 24\n42 21\n49 19\n65 4\n38 22\n70 62\n5 30\n69 76\n10 46\n66 73\n47 43\n58 26\n27 53\n45 34\n63 17\n2 9\n15 41\n20 31\n33 6\n54 23\n60 11\n74 7" }, { "input": "80\n18 38 65 1 20 9 57 2 36 26 15 17 33 61 65 27 10 35 49 42 40 32 19 33 12 36 56 31 10 41 8 54 56 60 5 47 61 43 23 19 20 30 7 6 38 60 29 58 35 64 30 51 6 17 30 24 47 1 37 47 34 36 48 28 5 25 47 19 30 39 36 23 31 28 46 46 59 43 19 49", "output": "4 15\n58 3\n8 50\n35 37\n65 14\n44 46\n53 34\n43 77\n31 48\n6 7\n17 33\n29 27\n25 32\n11 52\n12 80\n54 19\n1 63\n23 67\n40 60\n68 57\n79 36\n5 76\n41 75\n39 78\n72 38\n56 20\n66 30\n10 21\n16 70\n64 45\n74 2\n47 59\n42 71\n51 62\n55 26\n69 9\n28 49\n73 18\n22 61\n13 24" }, { "input": "84\n59 41 54 14 42 55 29 28 41 73 40 15 1 1 66 49 76 59 68 60 42 81 19 23 33 12 80 81 42 22 54 54 2 22 22 28 27 60 36 57 17 76 38 20 40 65 23 9 81 50 25 13 46 36 59 53 6 35 47 40 59 19 67 46 63 49 12 33 23 49 33 23 32 62 60 70 44 1 6 63 28 16 70 69", "output": "13 49\n14 28\n78 22\n33 27\n57 42\n79 17\n48 10\n26 83\n67 76\n52 84\n4 19\n12 63\n82 15\n41 46\n23 80\n62 65\n44 74\n30 75\n34 38\n35 20\n24 61\n47 55\n69 18\n72 1\n51 40\n37 6\n8 32\n36 31\n81 3\n7 56\n73 50\n25 70\n68 66\n71 16\n58 59\n39 64\n54 53\n43 77\n11 29\n45 21\n60 5\n2 9" }, { "input": "88\n10 28 71 6 58 66 45 52 13 71 39 1 10 29 30 70 14 17 15 38 4 60 5 46 66 41 40 58 2 57 32 44 21 26 13 40 64 63 56 33 46 8 30 43 67 55 44 28 32 62 14 58 42 67 45 59 32 68 10 31 51 6 42 34 9 12 51 27 20 14 62 42 16 5 1 14 30 62 40 59 58 26 25 15 27 47 21 57", "output": "12 10\n75 3\n29 16\n21 58\n23 54\n74 45\n4 25\n62 6\n42 37\n65 38\n1 78\n13 71\n59 50\n66 22\n9 80\n35 56\n17 81\n51 52\n70 28\n76 5\n19 88\n84 30\n73 39\n18 46\n69 8\n33 67\n87 61\n83 86\n34 41\n82 24\n68 55\n85 7\n2 47\n48 32\n14 44\n15 72\n43 63\n77 53\n60 26\n31 79\n49 36\n57 27\n40 11\n64 20" }, { "input": "92\n17 37 81 15 29 70 73 42 49 23 44 77 27 44 74 11 43 66 15 41 60 36 33 11 2 76 16 51 45 21 46 16 85 29 76 79 16 6 60 13 25 44 62 28 43 35 63 24 76 71 62 15 57 72 45 10 71 59 74 14 53 13 58 72 14 72 73 11 25 1 57 42 86 63 50 30 64 38 10 77 75 24 58 8 54 12 43 30 27 71 52 34", "output": "70 73\n25 33\n38 3\n84 36\n56 80\n79 12\n16 49\n24 35\n68 26\n86 81\n40 59\n62 15\n60 67\n65 7\n4 66\n19 64\n52 54\n27 90\n32 57\n37 50\n1 6\n30 18\n10 77\n48 74\n82 47\n41 51\n69 43\n13 39\n89 21\n44 58\n5 83\n34 63\n76 71\n88 53\n23 85\n92 61\n46 91\n22 28\n2 75\n78 9\n20 31\n8 55\n72 29\n17 42\n45 14\n87 11" }, { "input": "96\n77 7 47 19 73 31 46 13 89 69 52 9 26 77 6 87 55 45 71 2 79 1 80 20 4 82 64 20 75 86 84 24 77 56 16 54 53 35 74 73 40 29 63 20 83 39 58 16 31 41 40 16 11 90 30 48 62 39 55 8 50 3 77 73 75 66 14 90 18 54 38 10 53 22 67 38 27 91 62 37 85 13 92 7 18 83 10 3 86 54 80 59 34 16 39 43", "output": "22 83\n20 78\n62 68\n88 54\n25 9\n15 16\n2 89\n84 30\n60 81\n12 31\n72 86\n87 45\n53 26\n8 91\n82 23\n67 21\n35 63\n48 33\n52 14\n94 1\n69 65\n85 29\n4 39\n24 64\n28 40\n44 5\n74 19\n32 10\n13 75\n77 66\n42 27\n55 43\n6 79\n49 57\n93 92\n38 47\n80 34\n71 59\n76 17\n46 90\n58 70\n95 36\n41 73\n51 37\n50 11\n96 61\n18 56\n7 3" }, { "input": "4\n100 100 1 1", "output": "3 2\n4 1" }, { "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": "1 100\n2 99\n3 98\n4 97\n5 96\n6 95\n7 94\n8 93\n9 92\n10 91\n11 90\n12 89\n13 88\n14 87\n15 86\n16 85\n17 84\n18 83\n19 82\n20 81\n21 80\n22 79\n23 78\n24 77\n25 76\n26 75\n27 74\n28 73\n29 72\n30 71\n31 70\n32 69\n33 68\n34 67\n35 66\n36 65\n37 64\n38 63\n39 62\n40 61\n41 60\n42 59\n43 58\n44 57\n45 56\n46 55\n47 54\n48 53\n49 52\n50 51" }, { "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": "1 100\n2 99\n3 98\n4 97\n5 96\n6 95\n7 94\n8 93\n9 92\n10 91\n11 90\n12 89\n13 88\n14 87\n15 86\n16 85\n17 84\n18 83\n19 82\n20 81\n21 80\n22 79\n23 78\n24 77\n25 76\n26 75\n27 74\n28 73\n29 72\n30 71\n31 70\n32 69\n33 68\n34 67\n35 66\n36 65\n37 64\n38 63\n39 62\n40 61\n41 60\n42 59\n43 58\n44 57\n45 56\n46 55\n47 54\n48 53\n49 52\n50 51" }, { "input": "4\n3 4 4 5", "output": "1 4\n2 3" }, { "input": "4\n1 1 2 2", "output": "1 4\n2 3" }, { "input": "4\n1 2 3 4", "output": "1 4\n2 3" } ]
1,544,757,035
2,147,483,647
Python 3
OK
TESTS
35
124
0
n = int(input()) string = input().split(' ') for i in range(n): string[i] = int(string[i]) target = int(sum(string)/(n/2)) result = [] for i in range(n): if not i in result: result.append(i) remaining = target - string[i] for j in range(n): if string[j] == remaining: if not j in result: result.append(j) break for i in range(n//2): stringToPrint = str(result[2*i]+1) + " " stringToPrint += str(result[2*i + 1]+1) print(stringToPrint)
Title: Cards Time Limit: None seconds Memory Limit: None megabytes Problem Description: There are *n* cards (*n* is even) in the deck. Each card has a positive integer written on it. *n*<=/<=2 people will play new card game. At the beginning of the game each player gets two cards, each card is given to exactly one player. Find the way to distribute cards such that the sum of values written of the cards will be equal for each player. It is guaranteed that it is always possible. Input Specification: The first line of the input contains integer *n* (2<=≤<=*n*<=≤<=100) — the number of cards in the deck. It is guaranteed that *n* is even. The second line contains the sequence of *n* positive integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=100), where *a**i* is equal to the number written on the *i*-th card. Output Specification: Print *n*<=/<=2 pairs of integers, the *i*-th pair denote the cards that should be given to the *i*-th player. Each card should be given to exactly one player. Cards are numbered in the order they appear in the input. It is guaranteed that solution exists. If there are several correct answers, you are allowed to print any of them. Demo Input: ['6\n1 5 7 4 4 3\n', '4\n10 10 10 10\n'] Demo Output: ['1 3\n6 2\n4 5\n', '1 2\n3 4\n'] Note: In the first sample, cards are distributed in such a way that each player has the sum of numbers written on his cards equal to 8. In the second sample, all values *a*<sub class="lower-index">*i*</sub> are equal. Thus, any distribution is acceptable.
```python n = int(input()) string = input().split(' ') for i in range(n): string[i] = int(string[i]) target = int(sum(string)/(n/2)) result = [] for i in range(n): if not i in result: result.append(i) remaining = target - string[i] for j in range(n): if string[j] == remaining: if not j in result: result.append(j) break for i in range(n//2): stringToPrint = str(result[2*i]+1) + " " stringToPrint += str(result[2*i + 1]+1) print(stringToPrint) ```
3
266
B
Queue at the School
PROGRAMMING
800
[ "constructive algorithms", "graph matchings", "implementation", "shortest paths" ]
null
null
During the break the schoolchildren, boys and girls, formed a queue of *n* people in the canteen. Initially the children stood in the order they entered the canteen. However, after a while the boys started feeling awkward for standing in front of the girls in the queue and they started letting the girls move forward each second. Let's describe the process more precisely. Let's say that the positions in the queue are sequentially numbered by integers from 1 to *n*, at that the person in the position number 1 is served first. Then, if at time *x* a boy stands on the *i*-th position and a girl stands on the (*i*<=+<=1)-th position, then at time *x*<=+<=1 the *i*-th position will have a girl and the (*i*<=+<=1)-th position will have a boy. The time is given in seconds. You've got the initial position of the children, at the initial moment of time. Determine the way the queue is going to look after *t* seconds.
The first line contains two integers *n* and *t* (1<=≤<=*n*,<=*t*<=≤<=50), which represent the number of children in the queue and the time after which the queue will transform into the arrangement you need to find. The next line contains string *s*, which represents the schoolchildren's initial arrangement. If the *i*-th position in the queue contains a boy, then the *i*-th character of string *s* equals "B", otherwise the *i*-th character equals "G".
Print string *a*, which describes the arrangement after *t* seconds. If the *i*-th position has a boy after the needed time, then the *i*-th character *a* must equal "B", otherwise it must equal "G".
[ "5 1\nBGGBG\n", "5 2\nBGGBG\n", "4 1\nGGGB\n" ]
[ "GBGGB\n", "GGBGB\n", "GGGB\n" ]
none
500
[ { "input": "5 1\nBGGBG", "output": "GBGGB" }, { "input": "5 2\nBGGBG", "output": "GGBGB" }, { "input": "4 1\nGGGB", "output": "GGGB" }, { "input": "2 1\nBB", "output": "BB" }, { "input": "2 1\nBG", "output": "GB" }, { "input": "6 2\nBBGBBG", "output": "GBBGBB" }, { "input": "8 3\nBBGBGBGB", "output": "GGBGBBBB" }, { "input": "10 3\nBBGBBBBBBG", "output": "GBBBBBGBBB" }, { "input": "22 7\nGBGGBGGGGGBBBGGBGBGBBB", "output": "GGGGGGGGBGGBGGBBBBBBBB" }, { "input": "50 4\nGBBGBBBGGGGGBBGGBBBBGGGBBBGBBBGGBGGBGBBBGGBGGBGGBG", "output": "GGBGBGBGBGBGGGBBGBGBGBGBBBGBGBGBGBGBGBGBGBGBGGBGBB" }, { "input": "50 8\nGGGGBGGBGGGBGBBBGGGGGGGGBBGBGBGBBGGBGGBGGGGGGGGBBG", "output": "GGGGGGGGGGGGBGGBGBGBGBGBGGGGGGBGBGBGBGBGBGGBGGBGBB" }, { "input": "50 30\nBGGGGGGBGGBGBGGGGBGBBGBBBGGBBBGBGBGGGGGBGBBGBGBGGG", "output": "GGGGGGGGGGGGGGGGGGGGGGGGGGGGGGBBBBBBBBBBBBBBBBBBBB" }, { "input": "20 20\nBBGGBGGGGBBBGBBGGGBB", "output": "GGGGGGGGGGBBBBBBBBBB" }, { "input": "27 6\nGBGBGBGGGGGGBGGBGGBBGBBBGBB", "output": "GGGGGGGBGBGBGGGGGBGBBBBBBBB" }, { "input": "46 11\nBGGGGGBGBGGBGGGBBGBBGBBGGBBGBBGBGGGGGGGBGBGBGB", "output": "GGGGGGGGGGGBGGGGGBBGBGBGBGBGBGBGBGBGBGBGBBBBBB" }, { "input": "50 6\nBGGBBBBGGBBBBBBGGBGBGBBBBGBBBBBBGBBBBBBBBBBBBBBBBB", "output": "GGGGBBBBBGBGBGBGBBBGBBBBBBGBBBBBBBBBBBBBBBBBBBBBBB" }, { "input": "50 10\nBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB", "output": "BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB" }, { "input": "50 8\nGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGG", "output": "GGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGG" }, { "input": "50 10\nBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBGB", "output": "BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBGBBBBBBBBBBB" }, { "input": "50 13\nGGGBGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGG", "output": "GGGGGGGGGGGGGGGGBGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGG" }, { "input": "1 1\nB", "output": "B" }, { "input": "1 1\nG", "output": "G" }, { "input": "1 50\nB", "output": "B" }, { "input": "1 50\nG", "output": "G" }, { "input": "50 50\nBBBBBBBBGGBBBBBBGBBBBBBBBBBBGBBBBBBBBBBBBBBGBBBBBB", "output": "GGGGGBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB" }, { "input": "50 50\nGGBBGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGBBGGGGGGBG", "output": "GGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGBBBBB" }, { "input": "6 3\nGGBBBG", "output": "GGGBBB" }, { "input": "26 3\nGBBGBBBBBGGGBGBGGGBGBGGBBG", "output": "GGBBBBGBGBGBGGGBGBGGGBGBBB" }, { "input": "46 3\nGGBBGGGGBBGBGBBBBBGGGBGGGBBGGGBBBGGBGGBBBGBGBB", "output": "GGGGBGBGGGBBBBBGBGBGBGGGBGGBGBGBGBGBGBGBGBBBBB" }, { "input": "44 8\nBGBBBBBBBBBGGBBGBGBGGBBBBBGBBGBBBBBBBBBGBBGB", "output": "GBBGBGBGBGBGBGBBBBGBBGBBBBBBBBBGBBGBBBBBBBBB" }, { "input": "20 20\nBBGGBGGGGBBBGBBGGGBB", "output": "GGGGGGGGGGBBBBBBBBBB" }, { "input": "30 25\nBGGBBGBGGBGBGBBGBGGGGBGBGGBBBB", "output": "GGGGGGGGGGGGGGGBBBBBBBBBBBBBBB" }, { "input": "17 42\nBBGBGBGGGGGGBBGGG", "output": "GGGGGGGGGGGBBBBBB" }, { "input": "30 50\nBGGBBGGGGGGGGBBGGGBBGGBBBGBBGG", "output": "GGGGGGGGGGGGGGGGGGBBBBBBBBBBBB" }, { "input": "31 33\nBBGGBBGGBGBBBBGGBGBBBGBGGBBGBBB", "output": "GGGGGGGGGGGGBBBBBBBBBBBBBBBBBBB" }, { "input": "2 2\nBG", "output": "GB" }, { "input": "8 8\nGGGBGGBB", "output": "GGGGGBBB" }, { "input": "34 34\nBGGBBBBGGBBGBGGGGGGBBGGGGGBGGBGGGB", "output": "GGGGGGGGGGGGGGGGGGGGGBBBBBBBBBBBBB" }, { "input": "34 20\nBBBBGBGGGBGGGBGBGGBBBBGGBBGGGBGBBG", "output": "GGGGGGGGGGGGGGGGGBBBBBBBBBBBBBBBBB" }, { "input": "50 50\nBBGBBBBBBBBBBBBGBBBGBBBBBBBGBBBBBBGBBBGBBGBBGBBBGG", "output": "GGGGGGGGGGBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB" }, { "input": "10 10\nGGGGGGGGGG", "output": "GGGGGGGGGG" }, { "input": "10 10\nBBBBBBBBBB", "output": "BBBBBBBBBB" }, { "input": "10 10\nBGBGBGBGBG", "output": "GGGGGBBBBB" }, { "input": "1 1\nB", "output": "B" } ]
1,698,325,863
2,147,483,647
PyPy 3-64
OK
TESTS
44
154
1,536,000
n, t = map(int, input().split()) q = list(input()) for _ in range(t): i = 0 while i < len(q) - 1: if q[i] == 'B' and q[i + 1] == 'G': q[i], q[i + 1] = 'G', 'B' i += 2 else: i += 1 for _ in q: print(_, end = '')
Title: Queue at the School Time Limit: None seconds Memory Limit: None megabytes Problem Description: During the break the schoolchildren, boys and girls, formed a queue of *n* people in the canteen. Initially the children stood in the order they entered the canteen. However, after a while the boys started feeling awkward for standing in front of the girls in the queue and they started letting the girls move forward each second. Let's describe the process more precisely. Let's say that the positions in the queue are sequentially numbered by integers from 1 to *n*, at that the person in the position number 1 is served first. Then, if at time *x* a boy stands on the *i*-th position and a girl stands on the (*i*<=+<=1)-th position, then at time *x*<=+<=1 the *i*-th position will have a girl and the (*i*<=+<=1)-th position will have a boy. The time is given in seconds. You've got the initial position of the children, at the initial moment of time. Determine the way the queue is going to look after *t* seconds. Input Specification: The first line contains two integers *n* and *t* (1<=≤<=*n*,<=*t*<=≤<=50), which represent the number of children in the queue and the time after which the queue will transform into the arrangement you need to find. The next line contains string *s*, which represents the schoolchildren's initial arrangement. If the *i*-th position in the queue contains a boy, then the *i*-th character of string *s* equals "B", otherwise the *i*-th character equals "G". Output Specification: Print string *a*, which describes the arrangement after *t* seconds. If the *i*-th position has a boy after the needed time, then the *i*-th character *a* must equal "B", otherwise it must equal "G". Demo Input: ['5 1\nBGGBG\n', '5 2\nBGGBG\n', '4 1\nGGGB\n'] Demo Output: ['GBGGB\n', 'GGBGB\n', 'GGGB\n'] Note: none
```python n, t = map(int, input().split()) q = list(input()) for _ in range(t): i = 0 while i < len(q) - 1: if q[i] == 'B' and q[i + 1] == 'G': q[i], q[i + 1] = 'G', 'B' i += 2 else: i += 1 for _ in q: print(_, end = '') ```
3
0
none
none
none
0
[ "none" ]
null
null
Some time ago Slastyona the Sweetmaid decided to open her own bakery! She bought required ingredients and a wonder-oven which can bake several types of cakes, and opened the bakery. Soon the expenses started to overcome the income, so Slastyona decided to study the sweets market. She learned it's profitable to pack cakes in boxes, and that the more distinct cake types a box contains (let's denote this number as the value of the box), the higher price it has. She needs to change the production technology! The problem is that the oven chooses the cake types on its own and Slastyona can't affect it. However, she knows the types and order of *n* cakes the oven is going to bake today. Slastyona has to pack exactly *k* boxes with cakes today, and she has to put in each box several (at least one) cakes the oven produced one right after another (in other words, she has to put in a box a continuous segment of cakes). Slastyona wants to maximize the total value of all boxes with cakes. Help her determine this maximum possible total value.
The first line contains two integers *n* and *k* (1<=≤<=*n*<=≤<=35000, 1<=≤<=*k*<=≤<=*min*(*n*,<=50)) – the number of cakes and the number of boxes, respectively. The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=*n*) – the types of cakes in the order the oven bakes them.
Print the only integer – the maximum total value of all boxes with cakes.
[ "4 1\n1 2 2 1\n", "7 2\n1 3 3 1 4 4 4\n", "8 3\n7 7 8 7 7 8 1 7\n" ]
[ "2\n", "5\n", "6\n" ]
In the first example Slastyona has only one box. She has to put all cakes in it, so that there are two types of cakes in the box, so the value is equal to 2. In the second example it is profitable to put the first two cakes in the first box, and all the rest in the second. There are two distinct types in the first box, and three in the second box then, so the total value is 5.
0
[]
1,691,859,378
2,147,483,647
PyPy 3-64
WRONG_ANSWER
TESTS
0
46
0
print("_RANDOM_GUESS_1691859378.732474")# 1691859378.7324915
Title: none Time Limit: None seconds Memory Limit: None megabytes Problem Description: Some time ago Slastyona the Sweetmaid decided to open her own bakery! She bought required ingredients and a wonder-oven which can bake several types of cakes, and opened the bakery. Soon the expenses started to overcome the income, so Slastyona decided to study the sweets market. She learned it's profitable to pack cakes in boxes, and that the more distinct cake types a box contains (let's denote this number as the value of the box), the higher price it has. She needs to change the production technology! The problem is that the oven chooses the cake types on its own and Slastyona can't affect it. However, she knows the types and order of *n* cakes the oven is going to bake today. Slastyona has to pack exactly *k* boxes with cakes today, and she has to put in each box several (at least one) cakes the oven produced one right after another (in other words, she has to put in a box a continuous segment of cakes). Slastyona wants to maximize the total value of all boxes with cakes. Help her determine this maximum possible total value. Input Specification: The first line contains two integers *n* and *k* (1<=≤<=*n*<=≤<=35000, 1<=≤<=*k*<=≤<=*min*(*n*,<=50)) – the number of cakes and the number of boxes, respectively. The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=*n*) – the types of cakes in the order the oven bakes them. Output Specification: Print the only integer – the maximum total value of all boxes with cakes. Demo Input: ['4 1\n1 2 2 1\n', '7 2\n1 3 3 1 4 4 4\n', '8 3\n7 7 8 7 7 8 1 7\n'] Demo Output: ['2\n', '5\n', '6\n'] Note: In the first example Slastyona has only one box. She has to put all cakes in it, so that there are two types of cakes in the box, so the value is equal to 2. In the second example it is profitable to put the first two cakes in the first box, and all the rest in the second. There are two distinct types in the first box, and three in the second box then, so the total value is 5.
```python print("_RANDOM_GUESS_1691859378.732474")# 1691859378.7324915 ```
0
327
A
Flipping Game
PROGRAMMING
1,200
[ "brute force", "dp", "implementation" ]
null
null
Iahub got bored, so he invented a game to be played on paper. He writes *n* integers *a*1,<=*a*2,<=...,<=*a**n*. Each of those integers can be either 0 or 1. He's allowed to do exactly one move: he chooses two indices *i* and *j* (1<=≤<=*i*<=≤<=*j*<=≤<=*n*) and flips all values *a**k* for which their positions are in range [*i*,<=*j*] (that is *i*<=≤<=*k*<=≤<=*j*). Flip the value of *x* means to apply operation *x*<==<=1 - *x*. The goal of the game is that after exactly one move to obtain the maximum number of ones. Write a program to solve the little game of Iahub.
The first line of the input contains an integer *n* (1<=≤<=*n*<=≤<=100). In the second line of the input there are *n* integers: *a*1,<=*a*2,<=...,<=*a**n*. It is guaranteed that each of those *n* values is either 0 or 1.
Print an integer — the maximal number of 1s that can be obtained after exactly one move.
[ "5\n1 0 0 1 0\n", "4\n1 0 0 1\n" ]
[ "4\n", "4\n" ]
In the first case, flip the segment from 2 to 5 (*i* = 2, *j* = 5). That flip changes the sequence, it becomes: [1 1 1 0 1]. So, it contains four ones. There is no way to make the whole sequence equal to [1 1 1 1 1]. In the second case, flipping only the second and the third element (*i* = 2, *j* = 3) will turn all numbers into 1.
500
[ { "input": "5\n1 0 0 1 0", "output": "4" }, { "input": "4\n1 0 0 1", "output": "4" }, { "input": "1\n1", "output": "0" }, { "input": "1\n0", "output": "1" }, { "input": "8\n1 0 0 0 1 0 0 0", "output": "7" }, { "input": "18\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0", "output": "18" }, { "input": "23\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1", "output": "22" }, { "input": "100\n0 1 0 1 1 1 0 1 0 1 0 0 1 1 1 1 0 0 1 1 1 1 1 1 1 0 0 1 1 1 0 1 1 0 0 0 1 1 1 1 0 0 1 1 1 0 0 1 1 0 1 1 1 0 0 0 1 0 0 0 0 0 1 1 0 0 1 1 1 1 1 1 1 1 0 1 1 1 0 1 0 0 0 0 0 1 1 1 1 1 1 1 1 1 1 1 1 1 0 1", "output": "70" }, { "input": "100\n0 1 1 0 1 0 0 1 0 0 0 1 1 0 0 0 1 1 1 0 1 0 0 0 0 0 1 0 1 0 1 0 1 0 1 0 0 0 1 0 0 0 0 0 1 1 0 1 0 1 0 1 1 1 0 1 0 1 1 0 0 1 1 0 0 1 1 1 0 0 1 0 0 1 1 0 1 0 0 1 1 0 1 0 0 1 1 0 0 0 0 1 0 0 0 0 1 1 1 1", "output": "60" }, { "input": "18\n0 1 0 1 0 1 0 1 0 1 1 0 1 1 0 1 1 0", "output": "11" }, { "input": "25\n0 1 0 0 0 0 0 1 0 1 0 1 0 0 0 0 1 1 1 0 0 1 1 0 1", "output": "18" }, { "input": "55\n0 0 1 1 0 0 0 1 0 1 1 0 1 1 1 0 1 1 1 1 1 0 0 1 0 0 1 0 1 1 0 0 1 0 1 1 0 1 1 1 1 0 1 1 0 0 0 0 1 1 0 1 1 1 1", "output": "36" }, { "input": "75\n1 1 0 1 0 1 1 0 0 0 0 0 1 1 1 1 1 0 1 0 1 0 0 0 0 1 1 1 0 1 0 0 1 1 0 1 0 0 1 1 0 1 0 1 0 1 0 0 0 0 1 0 0 1 1 1 0 0 1 0 1 1 0 0 0 0 1 1 0 0 0 1 0 0 0", "output": "44" }, { "input": "100\n0 0 1 0 1 0 0 1 1 0 1 1 0 1 0 1 1 0 0 0 0 0 1 0 0 1 1 0 0 0 1 0 0 1 1 0 0 1 1 1 0 0 0 0 1 0 1 1 1 0 0 1 0 1 1 1 1 1 1 1 0 1 0 1 0 0 1 0 1 1 1 0 0 0 0 1 0 1 1 0 0 1 1 0 1 1 1 1 0 1 1 1 0 0 1 1 0 1 0 1", "output": "61" }, { "input": "100\n0 0 0 1 0 0 0 1 0 1 1 0 1 1 1 1 1 0 1 0 1 1 0 0 1 1 0 1 0 1 0 1 0 1 1 0 1 1 0 0 0 1 1 1 1 0 1 1 0 1 1 1 1 0 1 0 0 1 0 1 0 0 0 0 1 1 0 0 1 0 0 1 1 0 1 1 0 1 0 0 1 1 0 1 1 1 1 0 1 0 0 1 0 1 1 1 0 1 1 0", "output": "61" }, { "input": "100\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0", "output": "100" }, { "input": "100\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1", "output": "99" }, { "input": "100\n0 0 1 1 1 0 1 1 0 0 1 0 1 0 1 0 0 1 0 1 1 0 0 1 1 1 1 1 1 0 1 0 0 1 0 0 0 0 1 1 1 0 1 1 1 0 1 1 1 0 0 1 0 0 1 1 0 0 0 1 1 1 0 1 1 0 0 0 0 1 0 0 1 0 1 0 0 0 0 0 0 1 1 1 0 1 1 1 0 1 1 1 1 1 0 0 0 0 1 0", "output": "61" }, { "input": "100\n0 1 1 1 1 1 1 0 0 0 1 1 0 0 0 1 0 0 0 0 0 0 1 1 1 0 0 0 1 1 1 0 1 0 0 1 1 0 0 0 1 1 1 1 1 1 1 1 1 1 0 0 1 0 1 0 0 0 0 1 0 1 0 1 0 0 1 0 1 0 1 1 0 0 0 0 0 1 1 1 0 1 1 0 1 1 0 0 0 1 0 1 1 0 0 0 0 0 0 1", "output": "59" }, { "input": "99\n1 1 0 0 0 1 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 1 1 1 1 0 1 1 0 0 0 0 0 0 1 1 0 0 1 0 1 1 1 0 0 0 0 0 1 0 0 0 0 0 0 1 0 1 1 0 1 0 0 1 1 0 1 0 0 0 1 1 1 1 0 1 1 1 0 0 1 1 0 0 0 0 1 0 0 0 0 0 1 0 1 1 1", "output": "61" }, { "input": "2\n1 1", "output": "1" } ]
1,655,079,523
2,147,483,647
PyPy 3-64
OK
TESTS
21
248
3,072,000
n=eval(input()) a=[int(i) for i in input().split()] ans=0 def f(i,j): for k in range(i,j): a[k]=1-a[k] for i in range(n): for j in range(i+1,n+1): f(i,j) res=sum(a) if res>ans: ans=res f(i,j) print(ans)
Title: Flipping Game Time Limit: None seconds Memory Limit: None megabytes Problem Description: Iahub got bored, so he invented a game to be played on paper. He writes *n* integers *a*1,<=*a*2,<=...,<=*a**n*. Each of those integers can be either 0 or 1. He's allowed to do exactly one move: he chooses two indices *i* and *j* (1<=≤<=*i*<=≤<=*j*<=≤<=*n*) and flips all values *a**k* for which their positions are in range [*i*,<=*j*] (that is *i*<=≤<=*k*<=≤<=*j*). Flip the value of *x* means to apply operation *x*<==<=1 - *x*. The goal of the game is that after exactly one move to obtain the maximum number of ones. Write a program to solve the little game of Iahub. Input Specification: The first line of the input contains an integer *n* (1<=≤<=*n*<=≤<=100). In the second line of the input there are *n* integers: *a*1,<=*a*2,<=...,<=*a**n*. It is guaranteed that each of those *n* values is either 0 or 1. Output Specification: Print an integer — the maximal number of 1s that can be obtained after exactly one move. Demo Input: ['5\n1 0 0 1 0\n', '4\n1 0 0 1\n'] Demo Output: ['4\n', '4\n'] Note: In the first case, flip the segment from 2 to 5 (*i* = 2, *j* = 5). That flip changes the sequence, it becomes: [1 1 1 0 1]. So, it contains four ones. There is no way to make the whole sequence equal to [1 1 1 1 1]. In the second case, flipping only the second and the third element (*i* = 2, *j* = 3) will turn all numbers into 1.
```python n=eval(input()) a=[int(i) for i in input().split()] ans=0 def f(i,j): for k in range(i,j): a[k]=1-a[k] for i in range(n): for j in range(i+1,n+1): f(i,j) res=sum(a) if res>ans: ans=res f(i,j) print(ans) ```
3
136
A
Presents
PROGRAMMING
800
[ "implementation" ]
null
null
Little Petya very much likes gifts. Recently he has received a new laptop as a New Year gift from his mother. He immediately decided to give it to somebody else as what can be more pleasant than giving somebody gifts. And on this occasion he organized a New Year party at his place and invited *n* his friends there. If there's one thing Petya likes more that receiving gifts, that's watching others giving gifts to somebody else. Thus, he safely hid the laptop until the next New Year and made up his mind to watch his friends exchanging gifts while he does not participate in the process. He numbered all his friends with integers from 1 to *n*. Petya remembered that a friend number *i* gave a gift to a friend number *p**i*. He also remembered that each of his friends received exactly one gift. Now Petya wants to know for each friend *i* the number of a friend who has given him a gift.
The first line contains one integer *n* (1<=≤<=*n*<=≤<=100) — the quantity of friends Petya invited to the party. The second line contains *n* space-separated integers: the *i*-th number is *p**i* — the number of a friend who gave a gift to friend number *i*. It is guaranteed that each friend received exactly one gift. It is possible that some friends do not share Petya's ideas of giving gifts to somebody else. Those friends gave the gifts to themselves.
Print *n* space-separated integers: the *i*-th number should equal the number of the friend who gave a gift to friend number *i*.
[ "4\n2 3 4 1\n", "3\n1 3 2\n", "2\n1 2\n" ]
[ "4 1 2 3\n", "1 3 2\n", "1 2\n" ]
none
500
[ { "input": "4\n2 3 4 1", "output": "4 1 2 3" }, { "input": "3\n1 3 2", "output": "1 3 2" }, { "input": "2\n1 2", "output": "1 2" }, { "input": "1\n1", "output": "1" }, { "input": "10\n1 3 2 6 4 5 7 9 8 10", "output": "1 3 2 5 6 4 7 9 8 10" }, { "input": "5\n5 4 3 2 1", "output": "5 4 3 2 1" }, { "input": "20\n2 1 4 3 6 5 8 7 10 9 12 11 14 13 16 15 18 17 20 19", "output": "2 1 4 3 6 5 8 7 10 9 12 11 14 13 16 15 18 17 20 19" }, { "input": "21\n3 2 1 6 5 4 9 8 7 12 11 10 15 14 13 18 17 16 21 20 19", "output": "3 2 1 6 5 4 9 8 7 12 11 10 15 14 13 18 17 16 21 20 19" }, { "input": "10\n3 4 5 6 7 8 9 10 1 2", "output": "9 10 1 2 3 4 5 6 7 8" }, { "input": "8\n1 5 3 7 2 6 4 8", "output": "1 5 3 7 2 6 4 8" }, { "input": "50\n49 22 4 2 20 46 7 32 5 19 48 24 26 15 45 21 44 11 50 43 39 17 31 1 42 34 3 27 36 25 12 30 13 33 28 35 18 6 8 37 38 14 10 9 29 16 40 23 41 47", "output": "24 4 27 3 9 38 7 39 44 43 18 31 33 42 14 46 22 37 10 5 16 2 48 12 30 13 28 35 45 32 23 8 34 26 36 29 40 41 21 47 49 25 20 17 15 6 50 11 1 19" }, { "input": "34\n13 20 33 30 15 11 27 4 8 2 29 25 24 7 3 22 18 10 26 16 5 1 32 9 34 6 12 14 28 19 31 21 23 17", "output": "22 10 15 8 21 26 14 9 24 18 6 27 1 28 5 20 34 17 30 2 32 16 33 13 12 19 7 29 11 4 31 23 3 25" }, { "input": "92\n23 1 6 4 84 54 44 76 63 34 61 20 48 13 28 78 26 46 90 72 24 55 91 89 53 38 82 5 79 92 29 32 15 64 11 88 60 70 7 66 18 59 8 57 19 16 42 21 80 71 62 27 75 86 36 9 83 73 74 50 43 31 56 30 17 33 40 81 49 12 10 41 22 77 25 68 51 2 47 3 58 69 87 67 39 37 35 65 14 45 52 85", "output": "2 78 80 4 28 3 39 43 56 71 35 70 14 89 33 46 65 41 45 12 48 73 1 21 75 17 52 15 31 64 62 32 66 10 87 55 86 26 85 67 72 47 61 7 90 18 79 13 69 60 77 91 25 6 22 63 44 81 42 37 11 51 9 34 88 40 84 76 82 38 50 20 58 59 53 8 74 16 29 49 68 27 57 5 92 54 83 36 24 19 23 30" }, { "input": "49\n30 24 33 48 7 3 17 2 8 35 10 39 23 40 46 32 18 21 26 22 1 16 47 45 41 28 31 6 12 43 27 11 13 37 19 15 44 5 29 42 4 38 20 34 14 9 25 36 49", "output": "21 8 6 41 38 28 5 9 46 11 32 29 33 45 36 22 7 17 35 43 18 20 13 2 47 19 31 26 39 1 27 16 3 44 10 48 34 42 12 14 25 40 30 37 24 15 23 4 49" }, { "input": "12\n3 8 7 4 6 5 2 1 11 9 10 12", "output": "8 7 1 4 6 5 3 2 10 11 9 12" }, { "input": "78\n16 56 36 78 21 14 9 77 26 57 70 61 41 47 18 44 5 31 50 74 65 52 6 39 22 62 67 69 43 7 64 29 24 40 48 51 73 54 72 12 19 34 4 25 55 33 17 35 23 53 10 8 27 32 42 68 20 63 3 2 1 71 58 46 13 30 49 11 37 66 38 60 28 75 15 59 45 76", "output": "61 60 59 43 17 23 30 52 7 51 68 40 65 6 75 1 47 15 41 57 5 25 49 33 44 9 53 73 32 66 18 54 46 42 48 3 69 71 24 34 13 55 29 16 77 64 14 35 67 19 36 22 50 38 45 2 10 63 76 72 12 26 58 31 21 70 27 56 28 11 62 39 37 20 74 78 8 4" }, { "input": "64\n64 57 40 3 15 8 62 18 33 59 51 19 22 13 4 37 47 45 50 35 63 11 58 42 46 21 7 2 41 48 32 23 28 38 17 12 24 27 49 31 60 6 30 25 61 52 26 54 9 14 29 20 44 39 55 10 34 16 5 56 1 36 53 43", "output": "61 28 4 15 59 42 27 6 49 56 22 36 14 50 5 58 35 8 12 52 26 13 32 37 44 47 38 33 51 43 40 31 9 57 20 62 16 34 54 3 29 24 64 53 18 25 17 30 39 19 11 46 63 48 55 60 2 23 10 41 45 7 21 1" }, { "input": "49\n38 20 49 32 14 41 39 45 25 48 40 19 26 43 34 12 10 3 35 42 5 7 46 47 4 2 13 22 16 24 33 15 11 18 29 31 23 9 44 36 6 17 37 1 30 28 8 21 27", "output": "44 26 18 25 21 41 22 47 38 17 33 16 27 5 32 29 42 34 12 2 48 28 37 30 9 13 49 46 35 45 36 4 31 15 19 40 43 1 7 11 6 20 14 39 8 23 24 10 3" }, { "input": "78\n17 50 30 48 33 12 42 4 18 53 76 67 38 3 20 72 51 55 60 63 46 10 57 45 54 32 24 62 8 11 35 44 65 74 58 28 2 6 56 52 39 23 47 49 61 1 66 41 15 77 7 27 78 13 14 34 5 31 37 21 40 16 29 69 59 43 64 36 70 19 25 73 71 75 9 68 26 22", "output": "46 37 14 8 57 38 51 29 75 22 30 6 54 55 49 62 1 9 70 15 60 78 42 27 71 77 52 36 63 3 58 26 5 56 31 68 59 13 41 61 48 7 66 32 24 21 43 4 44 2 17 40 10 25 18 39 23 35 65 19 45 28 20 67 33 47 12 76 64 69 73 16 72 34 74 11 50 53" }, { "input": "29\n14 21 27 1 4 18 10 17 20 23 2 24 7 9 28 22 8 25 12 15 11 6 16 29 3 26 19 5 13", "output": "4 11 25 5 28 22 13 17 14 7 21 19 29 1 20 23 8 6 27 9 2 16 10 12 18 26 3 15 24" }, { "input": "82\n6 1 10 75 28 66 61 81 78 63 17 19 58 34 49 12 67 50 41 44 3 15 59 38 51 72 36 11 46 29 18 64 27 23 13 53 56 68 2 25 47 40 69 54 42 5 60 55 4 16 24 79 57 20 7 73 32 80 76 52 82 37 26 31 65 8 39 62 33 71 30 9 77 43 48 74 70 22 14 45 35 21", "output": "2 39 21 49 46 1 55 66 72 3 28 16 35 79 22 50 11 31 12 54 82 78 34 51 40 63 33 5 30 71 64 57 69 14 81 27 62 24 67 42 19 45 74 20 80 29 41 75 15 18 25 60 36 44 48 37 53 13 23 47 7 68 10 32 65 6 17 38 43 77 70 26 56 76 4 59 73 9 52 58 8 61" }, { "input": "82\n74 18 15 69 71 77 19 26 80 20 66 7 30 82 22 48 21 44 52 65 64 61 35 49 12 8 53 81 54 16 11 9 40 46 13 1 29 58 5 41 55 4 78 60 6 51 56 2 38 36 34 62 63 25 17 67 45 14 32 37 75 79 10 47 27 39 31 68 59 24 50 43 72 70 42 28 76 23 57 3 73 33", "output": "36 48 80 42 39 45 12 26 32 63 31 25 35 58 3 30 55 2 7 10 17 15 78 70 54 8 65 76 37 13 67 59 82 51 23 50 60 49 66 33 40 75 72 18 57 34 64 16 24 71 46 19 27 29 41 47 79 38 69 44 22 52 53 21 20 11 56 68 4 74 5 73 81 1 61 77 6 43 62 9 28 14" }, { "input": "45\n2 32 34 13 3 15 16 33 22 12 31 38 42 14 27 7 36 8 4 19 45 41 5 35 10 11 39 20 29 44 17 9 6 40 37 28 25 21 1 30 24 18 43 26 23", "output": "39 1 5 19 23 33 16 18 32 25 26 10 4 14 6 7 31 42 20 28 38 9 45 41 37 44 15 36 29 40 11 2 8 3 24 17 35 12 27 34 22 13 43 30 21" }, { "input": "45\n4 32 33 39 43 21 22 35 45 7 14 5 16 9 42 31 24 36 17 29 41 25 37 34 27 20 11 44 3 13 19 2 1 10 26 30 38 18 6 8 15 23 40 28 12", "output": "33 32 29 1 12 39 10 40 14 34 27 45 30 11 41 13 19 38 31 26 6 7 42 17 22 35 25 44 20 36 16 2 3 24 8 18 23 37 4 43 21 15 5 28 9" }, { "input": "74\n48 72 40 67 17 4 27 53 11 32 25 9 74 2 41 24 56 22 14 21 33 5 18 55 20 7 29 36 69 13 52 19 38 30 68 59 66 34 63 6 47 45 54 44 62 12 50 71 16 10 8 64 57 73 46 26 49 42 3 23 35 1 61 39 70 60 65 43 15 28 37 51 58 31", "output": "62 14 59 6 22 40 26 51 12 50 9 46 30 19 69 49 5 23 32 25 20 18 60 16 11 56 7 70 27 34 74 10 21 38 61 28 71 33 64 3 15 58 68 44 42 55 41 1 57 47 72 31 8 43 24 17 53 73 36 66 63 45 39 52 67 37 4 35 29 65 48 2 54 13" }, { "input": "47\n9 26 27 10 6 34 28 42 39 22 45 21 11 43 14 47 38 15 40 32 46 1 36 29 17 25 2 23 31 5 24 4 7 8 12 19 16 44 37 20 18 33 30 13 35 41 3", "output": "22 27 47 32 30 5 33 34 1 4 13 35 44 15 18 37 25 41 36 40 12 10 28 31 26 2 3 7 24 43 29 20 42 6 45 23 39 17 9 19 46 8 14 38 11 21 16" }, { "input": "49\n14 38 6 29 9 49 36 43 47 3 44 20 34 15 7 11 1 28 12 40 16 37 31 10 42 41 33 21 18 30 5 27 17 35 25 26 45 19 2 13 23 32 4 22 46 48 24 39 8", "output": "17 39 10 43 31 3 15 49 5 24 16 19 40 1 14 21 33 29 38 12 28 44 41 47 35 36 32 18 4 30 23 42 27 13 34 7 22 2 48 20 26 25 8 11 37 45 9 46 6" }, { "input": "100\n78 56 31 91 90 95 16 65 58 77 37 89 33 61 10 76 62 47 35 67 69 7 63 83 22 25 49 8 12 30 39 44 57 64 48 42 32 11 70 43 55 50 99 24 85 73 45 14 54 21 98 84 74 2 26 18 9 36 80 53 75 46 66 86 59 93 87 68 94 13 72 28 79 88 92 29 52 82 34 97 19 38 1 41 27 4 40 5 96 100 51 6 20 23 81 15 17 3 60 71", "output": "83 54 98 86 88 92 22 28 57 15 38 29 70 48 96 7 97 56 81 93 50 25 94 44 26 55 85 72 76 30 3 37 13 79 19 58 11 82 31 87 84 36 40 32 47 62 18 35 27 42 91 77 60 49 41 2 33 9 65 99 14 17 23 34 8 63 20 68 21 39 100 71 46 53 61 16 10 1 73 59 95 78 24 52 45 64 67 74 12 5 4 75 66 69 6 89 80 51 43 90" }, { "input": "22\n12 8 11 2 16 7 13 6 22 21 20 10 4 14 18 1 5 15 3 19 17 9", "output": "16 4 19 13 17 8 6 2 22 12 3 1 7 14 18 5 21 15 20 11 10 9" }, { "input": "72\n16 11 49 51 3 27 60 55 23 40 66 7 53 70 13 5 15 32 18 72 33 30 8 31 46 12 28 67 25 38 50 22 69 34 71 52 58 39 24 35 42 9 41 26 62 1 63 65 36 64 68 61 37 14 45 47 6 57 54 20 17 2 56 59 29 10 4 48 21 43 19 44", "output": "46 62 5 67 16 57 12 23 42 66 2 26 15 54 17 1 61 19 71 60 69 32 9 39 29 44 6 27 65 22 24 18 21 34 40 49 53 30 38 10 43 41 70 72 55 25 56 68 3 31 4 36 13 59 8 63 58 37 64 7 52 45 47 50 48 11 28 51 33 14 35 20" }, { "input": "63\n21 56 11 10 62 24 20 42 28 52 38 2 37 43 48 22 7 8 40 14 13 46 53 1 23 4 60 63 51 36 25 12 39 32 49 16 58 44 31 61 33 50 55 54 45 6 47 41 9 57 30 29 26 18 19 27 15 34 3 35 59 5 17", "output": "24 12 59 26 62 46 17 18 49 4 3 32 21 20 57 36 63 54 55 7 1 16 25 6 31 53 56 9 52 51 39 34 41 58 60 30 13 11 33 19 48 8 14 38 45 22 47 15 35 42 29 10 23 44 43 2 50 37 61 27 40 5 28" }, { "input": "18\n2 16 8 4 18 12 3 6 5 9 10 15 11 17 14 13 1 7", "output": "17 1 7 4 9 8 18 3 10 11 13 6 16 15 12 2 14 5" }, { "input": "47\n6 9 10 41 25 3 4 37 20 1 36 22 29 27 11 24 43 31 12 17 34 42 38 39 13 2 7 21 18 5 15 35 44 26 33 46 19 40 30 14 28 23 47 32 45 8 16", "output": "10 26 6 7 30 1 27 46 2 3 15 19 25 40 31 47 20 29 37 9 28 12 42 16 5 34 14 41 13 39 18 44 35 21 32 11 8 23 24 38 4 22 17 33 45 36 43" }, { "input": "96\n41 91 48 88 29 57 1 19 44 43 37 5 10 75 25 63 30 78 76 53 8 92 18 70 39 17 49 60 9 16 3 34 86 59 23 79 55 45 72 51 28 33 96 40 26 54 6 32 89 61 85 74 7 82 52 31 64 66 94 95 11 22 2 73 35 13 42 71 14 47 84 69 50 67 58 12 77 46 38 68 15 36 20 93 27 90 83 56 87 4 21 24 81 62 80 65", "output": "7 63 31 90 12 47 53 21 29 13 61 76 66 69 81 30 26 23 8 83 91 62 35 92 15 45 85 41 5 17 56 48 42 32 65 82 11 79 25 44 1 67 10 9 38 78 70 3 27 73 40 55 20 46 37 88 6 75 34 28 50 94 16 57 96 58 74 80 72 24 68 39 64 52 14 19 77 18 36 95 93 54 87 71 51 33 89 4 49 86 2 22 84 59 60 43" }, { "input": "73\n67 24 39 22 23 20 48 34 42 40 19 70 65 69 64 21 53 11 59 15 26 10 30 33 72 29 55 25 56 71 8 9 57 49 41 61 13 12 6 27 66 36 47 50 73 60 2 37 7 4 51 17 1 46 14 62 35 3 45 63 43 58 54 32 31 5 28 44 18 52 68 38 16", "output": "53 47 58 50 66 39 49 31 32 22 18 38 37 55 20 73 52 69 11 6 16 4 5 2 28 21 40 67 26 23 65 64 24 8 57 42 48 72 3 10 35 9 61 68 59 54 43 7 34 44 51 70 17 63 27 29 33 62 19 46 36 56 60 15 13 41 1 71 14 12 30 25 45" }, { "input": "81\n25 2 78 40 12 80 69 13 49 43 17 33 23 54 32 61 77 66 27 71 24 26 42 55 60 9 5 30 7 37 45 63 53 11 38 44 68 34 28 52 67 22 57 46 47 50 8 16 79 62 4 36 20 14 73 64 6 76 35 74 58 10 29 81 59 31 19 1 75 39 70 18 41 21 72 65 3 48 15 56 51", "output": "68 2 77 51 27 57 29 47 26 62 34 5 8 54 79 48 11 72 67 53 74 42 13 21 1 22 19 39 63 28 66 15 12 38 59 52 30 35 70 4 73 23 10 36 31 44 45 78 9 46 81 40 33 14 24 80 43 61 65 25 16 50 32 56 76 18 41 37 7 71 20 75 55 60 69 58 17 3 49 6 64" }, { "input": "12\n12 3 1 5 11 6 7 10 2 8 9 4", "output": "3 9 2 12 4 6 7 10 11 8 5 1" }, { "input": "47\n7 21 41 18 40 31 12 28 24 14 43 23 33 10 19 38 26 8 34 15 29 44 5 13 39 25 3 27 20 42 35 9 2 1 30 46 36 32 4 22 37 45 6 47 11 16 17", "output": "34 33 27 39 23 43 1 18 32 14 45 7 24 10 20 46 47 4 15 29 2 40 12 9 26 17 28 8 21 35 6 38 13 19 31 37 41 16 25 5 3 30 11 22 42 36 44" }, { "input": "8\n1 3 5 2 4 8 6 7", "output": "1 4 2 5 3 7 8 6" }, { "input": "38\n28 8 2 33 20 32 26 29 23 31 15 38 11 37 18 21 22 19 4 34 1 35 16 7 17 6 27 30 36 12 9 24 25 13 5 3 10 14", "output": "21 3 36 19 35 26 24 2 31 37 13 30 34 38 11 23 25 15 18 5 16 17 9 32 33 7 27 1 8 28 10 6 4 20 22 29 14 12" }, { "input": "10\n2 9 4 6 10 1 7 5 3 8", "output": "6 1 9 3 8 4 7 10 2 5" }, { "input": "23\n20 11 15 1 5 12 23 9 2 22 13 19 16 14 7 4 8 21 6 17 18 10 3", "output": "4 9 23 16 5 19 15 17 8 22 2 6 11 14 3 13 20 21 12 1 18 10 7" }, { "input": "10\n2 4 9 3 6 8 10 5 1 7", "output": "9 1 4 2 8 5 10 6 3 7" }, { "input": "55\n9 48 23 49 11 24 4 22 34 32 17 45 39 13 14 21 19 25 2 31 37 7 55 36 20 51 5 12 54 10 35 40 43 1 46 18 53 41 38 26 29 50 3 42 52 27 8 28 47 33 6 16 30 44 15", "output": "34 19 43 7 27 51 22 47 1 30 5 28 14 15 55 52 11 36 17 25 16 8 3 6 18 40 46 48 41 53 20 10 50 9 31 24 21 39 13 32 38 44 33 54 12 35 49 2 4 42 26 45 37 29 23" }, { "input": "58\n49 13 12 54 2 38 56 11 33 25 26 19 28 8 23 41 20 36 46 55 15 35 9 7 32 37 58 6 3 14 47 31 40 30 53 44 4 50 29 34 10 43 39 57 5 22 27 45 51 42 24 16 18 21 52 17 48 1", "output": "58 5 29 37 45 28 24 14 23 41 8 3 2 30 21 52 56 53 12 17 54 46 15 51 10 11 47 13 39 34 32 25 9 40 22 18 26 6 43 33 16 50 42 36 48 19 31 57 1 38 49 55 35 4 20 7 44 27" }, { "input": "34\n20 25 2 3 33 29 1 16 14 7 21 9 32 31 6 26 22 4 27 23 24 10 34 12 19 15 5 18 28 17 13 8 11 30", "output": "7 3 4 18 27 15 10 32 12 22 33 24 31 9 26 8 30 28 25 1 11 17 20 21 2 16 19 29 6 34 14 13 5 23" }, { "input": "53\n47 29 46 25 23 13 7 31 33 4 38 11 35 16 42 14 15 43 34 39 28 18 6 45 30 1 40 20 2 37 5 32 24 12 44 26 27 3 19 51 36 21 22 9 10 50 41 48 49 53 8 17 52", "output": "26 29 38 10 31 23 7 51 44 45 12 34 6 16 17 14 52 22 39 28 42 43 5 33 4 36 37 21 2 25 8 32 9 19 13 41 30 11 20 27 47 15 18 35 24 3 1 48 49 46 40 53 50" }, { "input": "99\n77 87 90 48 53 38 68 6 28 57 35 82 63 71 60 41 3 12 86 65 10 59 22 67 33 74 93 27 24 1 61 43 25 4 51 52 15 88 9 31 30 42 89 49 23 21 29 32 46 73 37 16 5 69 56 26 92 64 20 54 75 14 98 13 94 2 95 7 36 66 58 8 50 78 84 45 11 96 76 62 97 80 40 39 47 85 34 79 83 17 91 72 19 44 70 81 55 99 18", "output": "30 66 17 34 53 8 68 72 39 21 77 18 64 62 37 52 90 99 93 59 46 23 45 29 33 56 28 9 47 41 40 48 25 87 11 69 51 6 84 83 16 42 32 94 76 49 85 4 44 73 35 36 5 60 97 55 10 71 22 15 31 80 13 58 20 70 24 7 54 95 14 92 50 26 61 79 1 74 88 82 96 12 89 75 86 19 2 38 43 3 91 57 27 65 67 78 81 63 98" }, { "input": "32\n17 29 2 6 30 8 26 7 1 27 10 9 13 24 31 21 15 19 22 18 4 11 25 28 32 3 23 12 5 14 20 16", "output": "9 3 26 21 29 4 8 6 12 11 22 28 13 30 17 32 1 20 18 31 16 19 27 14 23 7 10 24 2 5 15 25" }, { "input": "65\n18 40 1 60 17 19 4 6 12 49 28 58 2 25 13 14 64 56 61 34 62 30 59 51 26 8 33 63 36 48 46 7 43 21 31 27 11 44 29 5 32 23 35 9 53 57 52 50 15 38 42 3 54 65 55 41 20 24 22 47 45 10 39 16 37", "output": "3 13 52 7 40 8 32 26 44 62 37 9 15 16 49 64 5 1 6 57 34 59 42 58 14 25 36 11 39 22 35 41 27 20 43 29 65 50 63 2 56 51 33 38 61 31 60 30 10 48 24 47 45 53 55 18 46 12 23 4 19 21 28 17 54" }, { "input": "71\n35 50 55 58 25 32 26 40 63 34 44 53 24 18 37 7 64 27 56 65 1 19 2 43 42 14 57 47 22 13 59 61 39 67 30 45 54 38 33 48 6 5 3 69 36 21 41 4 16 46 20 17 15 12 10 70 68 23 60 31 52 29 66 28 51 49 62 11 8 9 71", "output": "21 23 43 48 42 41 16 69 70 55 68 54 30 26 53 49 52 14 22 51 46 29 58 13 5 7 18 64 62 35 60 6 39 10 1 45 15 38 33 8 47 25 24 11 36 50 28 40 66 2 65 61 12 37 3 19 27 4 31 59 32 67 9 17 20 63 34 57 44 56 71" }, { "input": "74\n33 8 42 63 64 61 31 74 11 50 68 14 36 25 57 30 7 44 21 15 6 9 23 59 46 3 73 16 62 51 40 60 41 54 5 39 35 28 48 4 58 12 66 69 13 26 71 1 24 19 29 52 37 2 20 43 18 72 17 56 34 38 65 67 27 10 47 70 53 32 45 55 49 22", "output": "48 54 26 40 35 21 17 2 22 66 9 42 45 12 20 28 59 57 50 55 19 74 23 49 14 46 65 38 51 16 7 70 1 61 37 13 53 62 36 31 33 3 56 18 71 25 67 39 73 10 30 52 69 34 72 60 15 41 24 32 6 29 4 5 63 43 64 11 44 68 47 58 27 8" }, { "input": "96\n78 10 82 46 38 91 77 69 2 27 58 80 79 44 59 41 6 31 76 11 42 48 51 37 19 87 43 25 52 32 1 39 63 29 21 65 53 74 92 16 15 95 90 83 30 73 71 5 50 17 96 33 86 60 67 64 20 26 61 40 55 88 94 93 9 72 47 57 14 45 22 3 54 68 13 24 4 7 56 81 89 70 49 8 84 28 18 62 35 36 75 23 66 85 34 12", "output": "31 9 72 77 48 17 78 84 65 2 20 96 75 69 41 40 50 87 25 57 35 71 92 76 28 58 10 86 34 45 18 30 52 95 89 90 24 5 32 60 16 21 27 14 70 4 67 22 83 49 23 29 37 73 61 79 68 11 15 54 59 88 33 56 36 93 55 74 8 82 47 66 46 38 91 19 7 1 13 12 80 3 44 85 94 53 26 62 81 43 6 39 64 63 42 51" }, { "input": "7\n2 1 5 7 3 4 6", "output": "2 1 5 6 3 7 4" }, { "input": "51\n8 33 37 2 16 22 24 30 4 9 5 15 27 3 18 39 31 26 10 17 46 41 25 14 6 1 29 48 36 20 51 49 21 43 19 13 38 50 47 34 11 23 28 12 42 7 32 40 44 45 35", "output": "26 4 14 9 11 25 46 1 10 19 41 44 36 24 12 5 20 15 35 30 33 6 42 7 23 18 13 43 27 8 17 47 2 40 51 29 3 37 16 48 22 45 34 49 50 21 39 28 32 38 31" }, { "input": "27\n12 14 7 3 20 21 25 13 22 15 23 4 2 24 10 17 19 8 26 11 27 18 9 5 6 1 16", "output": "26 13 4 12 24 25 3 18 23 15 20 1 8 2 10 27 16 22 17 5 6 9 11 14 7 19 21" }, { "input": "71\n51 13 20 48 54 23 24 64 14 62 71 67 57 53 3 30 55 43 33 25 39 40 66 6 46 18 5 19 61 16 32 68 70 41 60 44 29 49 27 69 50 38 10 17 45 56 9 21 26 63 28 35 7 59 1 65 2 15 8 11 12 34 37 47 58 22 31 4 36 42 52", "output": "55 57 15 68 27 24 53 59 47 43 60 61 2 9 58 30 44 26 28 3 48 66 6 7 20 49 39 51 37 16 67 31 19 62 52 69 63 42 21 22 34 70 18 36 45 25 64 4 38 41 1 71 14 5 17 46 13 65 54 35 29 10 50 8 56 23 12 32 40 33 11" }, { "input": "9\n8 5 2 6 1 9 4 7 3", "output": "5 3 9 7 2 4 8 1 6" }, { "input": "29\n10 24 11 5 26 25 2 9 22 15 8 14 29 21 4 1 23 17 3 12 13 16 18 28 19 20 7 6 27", "output": "16 7 19 15 4 28 27 11 8 1 3 20 21 12 10 22 18 23 25 26 14 9 17 2 6 5 29 24 13" }, { "input": "60\n39 25 42 4 55 60 16 18 47 1 11 40 7 50 19 35 49 54 12 3 30 38 2 58 17 26 45 6 33 43 37 32 52 36 15 23 27 59 24 20 28 14 8 9 13 29 44 46 41 21 5 48 51 22 31 56 57 53 10 34", "output": "10 23 20 4 51 28 13 43 44 59 11 19 45 42 35 7 25 8 15 40 50 54 36 39 2 26 37 41 46 21 55 32 29 60 16 34 31 22 1 12 49 3 30 47 27 48 9 52 17 14 53 33 58 18 5 56 57 24 38 6" }, { "input": "50\n37 45 22 5 12 21 28 24 18 47 20 25 8 50 14 2 34 43 11 16 49 41 48 1 19 31 39 46 32 23 15 42 3 35 38 30 44 26 10 9 40 36 7 17 33 4 27 6 13 29", "output": "24 16 33 46 4 48 43 13 40 39 19 5 49 15 31 20 44 9 25 11 6 3 30 8 12 38 47 7 50 36 26 29 45 17 34 42 1 35 27 41 22 32 18 37 2 28 10 23 21 14" }, { "input": "30\n8 29 28 16 17 25 27 15 21 11 6 20 2 13 1 30 5 4 24 10 14 3 23 18 26 9 12 22 19 7", "output": "15 13 22 18 17 11 30 1 26 20 10 27 14 21 8 4 5 24 29 12 9 28 23 19 6 25 7 3 2 16" }, { "input": "46\n15 2 44 43 38 19 31 42 4 37 29 30 24 45 27 41 8 20 33 7 35 3 18 46 36 26 1 28 21 40 16 22 32 11 14 13 12 9 25 39 10 6 23 17 5 34", "output": "27 2 22 9 45 42 20 17 38 41 34 37 36 35 1 31 44 23 6 18 29 32 43 13 39 26 15 28 11 12 7 33 19 46 21 25 10 5 40 30 16 8 4 3 14 24" }, { "input": "9\n4 8 6 5 3 9 2 7 1", "output": "9 7 5 1 4 3 8 2 6" }, { "input": "46\n31 30 33 23 45 7 36 8 11 3 32 39 41 20 1 28 6 27 18 24 17 5 16 37 26 13 22 14 2 38 15 46 9 4 19 21 12 44 10 35 25 34 42 43 40 29", "output": "15 29 10 34 22 17 6 8 33 39 9 37 26 28 31 23 21 19 35 14 36 27 4 20 41 25 18 16 46 2 1 11 3 42 40 7 24 30 12 45 13 43 44 38 5 32" }, { "input": "66\n27 12 37 48 46 21 34 58 38 28 66 2 64 32 44 31 13 36 40 15 19 11 22 5 30 29 6 7 61 39 20 42 23 54 51 33 50 9 60 8 57 45 49 10 62 41 59 3 55 63 52 24 25 26 43 56 65 4 16 14 1 35 18 17 53 47", "output": "61 12 48 58 24 27 28 40 38 44 22 2 17 60 20 59 64 63 21 31 6 23 33 52 53 54 1 10 26 25 16 14 36 7 62 18 3 9 30 19 46 32 55 15 42 5 66 4 43 37 35 51 65 34 49 56 41 8 47 39 29 45 50 13 57 11" }, { "input": "13\n3 12 9 2 8 5 13 4 11 1 10 7 6", "output": "10 4 1 8 6 13 12 5 3 11 9 2 7" }, { "input": "80\n21 25 56 50 20 61 7 74 51 69 8 2 46 57 45 71 14 52 17 43 9 30 70 78 31 10 38 13 23 15 37 79 6 16 77 73 80 4 49 48 18 28 26 58 33 41 64 22 54 72 59 60 40 63 53 27 1 5 75 67 62 34 19 39 68 65 44 55 3 32 11 42 76 12 35 47 66 36 24 29", "output": "57 12 69 38 58 33 7 11 21 26 71 74 28 17 30 34 19 41 63 5 1 48 29 79 2 43 56 42 80 22 25 70 45 62 75 78 31 27 64 53 46 72 20 67 15 13 76 40 39 4 9 18 55 49 68 3 14 44 51 52 6 61 54 47 66 77 60 65 10 23 16 50 36 8 59 73 35 24 32 37" }, { "input": "63\n9 49 53 25 40 46 43 51 54 22 58 16 23 26 10 47 5 27 2 8 61 59 19 35 63 56 28 20 34 4 62 38 6 55 36 31 57 15 29 33 1 48 50 37 7 30 18 42 32 52 12 41 14 21 45 11 24 17 39 13 44 60 3", "output": "41 19 63 30 17 33 45 20 1 15 56 51 60 53 38 12 58 47 23 28 54 10 13 57 4 14 18 27 39 46 36 49 40 29 24 35 44 32 59 5 52 48 7 61 55 6 16 42 2 43 8 50 3 9 34 26 37 11 22 62 21 31 25" }, { "input": "26\n11 4 19 13 17 9 2 24 6 5 22 23 14 15 3 25 16 8 18 10 21 1 12 26 7 20", "output": "22 7 15 2 10 9 25 18 6 20 1 23 4 13 14 17 5 19 3 26 21 11 12 8 16 24" }, { "input": "69\n40 22 11 66 4 27 31 29 64 53 37 55 51 2 7 36 18 52 6 1 30 21 17 20 14 9 59 62 49 68 3 50 65 57 44 5 67 46 33 13 34 15 24 48 63 58 38 25 41 35 16 54 32 10 60 61 39 12 69 8 23 45 26 47 56 43 28 19 42", "output": "20 14 31 5 36 19 15 60 26 54 3 58 40 25 42 51 23 17 68 24 22 2 61 43 48 63 6 67 8 21 7 53 39 41 50 16 11 47 57 1 49 69 66 35 62 38 64 44 29 32 13 18 10 52 12 65 34 46 27 55 56 28 45 9 33 4 37 30 59" }, { "input": "6\n4 3 6 5 1 2", "output": "5 6 2 1 4 3" }, { "input": "9\n7 8 5 3 1 4 2 9 6", "output": "5 7 4 6 3 9 1 2 8" }, { "input": "41\n27 24 16 30 25 8 32 2 26 20 39 33 41 22 40 14 36 9 28 4 34 11 31 23 19 18 17 35 3 10 6 13 5 15 29 38 7 21 1 12 37", "output": "39 8 29 20 33 31 37 6 18 30 22 40 32 16 34 3 27 26 25 10 38 14 24 2 5 9 1 19 35 4 23 7 12 21 28 17 41 36 11 15 13" }, { "input": "1\n1", "output": "1" }, { "input": "20\n2 6 4 18 7 10 17 13 16 8 14 9 20 5 19 12 1 3 15 11", "output": "17 1 18 3 14 2 5 10 12 6 20 16 8 11 19 9 7 4 15 13" }, { "input": "2\n2 1", "output": "2 1" }, { "input": "60\n2 4 31 51 11 7 34 20 3 14 18 23 48 54 15 36 38 60 49 40 5 33 41 26 55 58 10 8 13 9 27 30 37 1 21 59 44 57 35 19 46 43 42 45 12 22 39 32 24 16 6 56 53 52 25 17 47 29 50 28", "output": "34 1 9 2 21 51 6 28 30 27 5 45 29 10 15 50 56 11 40 8 35 46 12 49 55 24 31 60 58 32 3 48 22 7 39 16 33 17 47 20 23 43 42 37 44 41 57 13 19 59 4 54 53 14 25 52 38 26 36 18" }, { "input": "14\n14 6 3 12 11 2 7 1 10 9 8 5 4 13", "output": "8 6 3 13 12 2 7 11 10 9 5 4 14 1" }, { "input": "81\n13 43 79 8 7 21 73 46 63 4 62 78 56 11 70 68 61 53 60 49 16 27 59 47 69 5 22 44 77 57 52 48 1 9 72 81 28 55 58 33 51 18 31 17 41 20 42 3 32 54 19 2 75 34 64 10 65 50 30 29 67 12 71 66 74 15 26 23 6 38 25 35 37 24 80 76 40 45 39 36 14", "output": "33 52 48 10 26 69 5 4 34 56 14 62 1 81 66 21 44 42 51 46 6 27 68 74 71 67 22 37 60 59 43 49 40 54 72 80 73 70 79 77 45 47 2 28 78 8 24 32 20 58 41 31 18 50 38 13 30 39 23 19 17 11 9 55 57 64 61 16 25 15 63 35 7 65 53 76 29 12 3 75 36" }, { "input": "42\n41 11 10 8 21 37 32 19 31 25 1 15 36 5 6 27 4 3 13 7 16 17 2 23 34 24 38 28 12 20 30 42 18 26 39 35 33 40 9 14 22 29", "output": "11 23 18 17 14 15 20 4 39 3 2 29 19 40 12 21 22 33 8 30 5 41 24 26 10 34 16 28 42 31 9 7 37 25 36 13 6 27 35 38 1 32" }, { "input": "97\n20 6 76 42 4 18 35 59 39 63 27 7 66 47 61 52 15 36 88 93 19 33 10 92 1 34 46 86 78 57 51 94 77 29 26 73 41 2 58 97 43 65 17 74 21 49 25 3 91 82 95 12 96 13 84 90 69 24 72 37 16 55 54 71 64 62 48 89 11 70 80 67 30 40 44 85 53 83 79 9 56 45 75 87 22 14 81 68 8 38 60 50 28 23 31 32 5", "output": "25 38 48 5 97 2 12 89 80 23 69 52 54 86 17 61 43 6 21 1 45 85 94 58 47 35 11 93 34 73 95 96 22 26 7 18 60 90 9 74 37 4 41 75 82 27 14 67 46 92 31 16 77 63 62 81 30 39 8 91 15 66 10 65 42 13 72 88 57 70 64 59 36 44 83 3 33 29 79 71 87 50 78 55 76 28 84 19 68 56 49 24 20 32 51 53 40" }, { "input": "62\n15 27 46 6 8 51 14 56 23 48 42 49 52 22 20 31 29 12 47 3 62 34 37 35 32 57 19 25 5 60 61 38 18 10 11 55 45 53 17 30 9 36 4 50 41 16 44 28 40 59 24 1 13 39 26 7 33 58 2 43 21 54", "output": "52 59 20 43 29 4 56 5 41 34 35 18 53 7 1 46 39 33 27 15 61 14 9 51 28 55 2 48 17 40 16 25 57 22 24 42 23 32 54 49 45 11 60 47 37 3 19 10 12 44 6 13 38 62 36 8 26 58 50 30 31 21" }, { "input": "61\n35 27 4 61 52 32 41 46 14 37 17 54 55 31 11 26 44 49 15 30 9 50 45 39 7 38 53 3 58 40 13 56 18 19 28 6 43 5 21 42 20 34 2 25 36 12 33 57 16 60 1 8 59 10 22 23 24 48 51 47 29", "output": "51 43 28 3 38 36 25 52 21 54 15 46 31 9 19 49 11 33 34 41 39 55 56 57 44 16 2 35 61 20 14 6 47 42 1 45 10 26 24 30 7 40 37 17 23 8 60 58 18 22 59 5 27 12 13 32 48 29 53 50 4" }, { "input": "59\n31 26 36 15 17 19 10 53 11 34 13 46 55 9 44 7 8 37 32 52 47 25 51 22 35 39 41 4 43 24 5 27 20 57 6 38 3 28 21 40 50 18 14 56 33 45 12 2 49 59 54 29 16 48 42 58 1 30 23", "output": "57 48 37 28 31 35 16 17 14 7 9 47 11 43 4 53 5 42 6 33 39 24 59 30 22 2 32 38 52 58 1 19 45 10 25 3 18 36 26 40 27 55 29 15 46 12 21 54 49 41 23 20 8 51 13 44 34 56 50" }, { "input": "10\n2 10 7 4 1 5 8 6 3 9", "output": "5 1 9 4 6 8 3 7 10 2" }, { "input": "14\n14 2 1 8 6 12 11 10 9 7 3 4 5 13", "output": "3 2 11 12 13 5 10 4 9 8 7 6 14 1" }, { "input": "43\n28 38 15 14 31 42 27 30 19 33 43 26 22 29 18 32 3 13 1 8 35 34 4 12 11 17 41 21 5 25 39 37 20 23 7 24 16 10 40 9 6 36 2", "output": "19 43 17 23 29 41 35 20 40 38 25 24 18 4 3 37 26 15 9 33 28 13 34 36 30 12 7 1 14 8 5 16 10 22 21 42 32 2 31 39 27 6 11" }, { "input": "86\n39 11 20 31 28 76 29 64 35 21 41 71 12 82 5 37 80 73 38 26 79 75 23 15 59 45 47 6 3 62 50 49 51 22 2 65 86 60 70 42 74 17 1 30 55 44 8 66 81 27 57 77 43 13 54 32 72 46 48 56 14 34 78 52 36 85 24 19 69 83 25 61 7 4 84 33 63 58 18 40 68 10 67 9 16 53", "output": "43 35 29 74 15 28 73 47 84 82 2 13 54 61 24 85 42 79 68 3 10 34 23 67 71 20 50 5 7 44 4 56 76 62 9 65 16 19 1 80 11 40 53 46 26 58 27 59 32 31 33 64 86 55 45 60 51 78 25 38 72 30 77 8 36 48 83 81 69 39 12 57 18 41 22 6 52 63 21 17 49 14 70 75 66 37" }, { "input": "99\n65 78 56 98 33 24 61 40 29 93 1 64 57 22 25 52 67 95 50 3 31 15 90 68 71 83 38 36 6 46 89 26 4 87 14 88 72 37 23 43 63 12 80 96 5 34 73 86 9 48 92 62 99 10 16 20 66 27 28 2 82 70 30 94 49 8 84 69 18 60 58 59 44 39 21 7 91 76 54 19 75 85 74 47 55 32 97 77 51 13 35 79 45 42 11 41 17 81 53", "output": "11 60 20 33 45 29 76 66 49 54 95 42 90 35 22 55 97 69 80 56 75 14 39 6 15 32 58 59 9 63 21 86 5 46 91 28 38 27 74 8 96 94 40 73 93 30 84 50 65 19 89 16 99 79 85 3 13 71 72 70 7 52 41 12 1 57 17 24 68 62 25 37 47 83 81 78 88 2 92 43 98 61 26 67 82 48 34 36 31 23 77 51 10 64 18 44 87 4 53" }, { "input": "100\n42 23 48 88 36 6 18 70 96 1 34 40 46 22 39 55 85 93 45 67 71 75 59 9 21 3 86 63 65 68 20 38 73 31 84 90 50 51 56 95 72 33 49 19 83 76 54 74 100 30 17 98 15 94 4 97 5 99 81 27 92 32 89 12 13 91 87 29 60 11 52 43 35 58 10 25 16 80 28 2 44 61 8 82 66 69 41 24 57 62 78 37 79 77 53 7 14 47 26 64", "output": "10 80 26 55 57 6 96 83 24 75 70 64 65 97 53 77 51 7 44 31 25 14 2 88 76 99 60 79 68 50 34 62 42 11 73 5 92 32 15 12 87 1 72 81 19 13 98 3 43 37 38 71 95 47 16 39 89 74 23 69 82 90 28 100 29 85 20 30 86 8 21 41 33 48 22 46 94 91 93 78 59 84 45 35 17 27 67 4 63 36 66 61 18 54 40 9 56 52 58 49" }, { "input": "99\n8 68 94 75 71 60 57 58 6 11 5 48 65 41 49 12 46 72 95 59 13 70 74 7 84 62 17 36 55 76 38 79 2 85 23 10 32 99 87 50 83 28 54 91 53 51 1 3 97 81 21 89 93 78 61 26 82 96 4 98 25 40 31 44 24 47 30 52 14 16 39 27 9 29 45 18 67 63 37 43 90 66 19 69 88 22 92 77 34 42 73 80 56 64 20 35 15 33 86", "output": "47 33 48 59 11 9 24 1 73 36 10 16 21 69 97 70 27 76 83 95 51 86 35 65 61 56 72 42 74 67 63 37 98 89 96 28 79 31 71 62 14 90 80 64 75 17 66 12 15 40 46 68 45 43 29 93 7 8 20 6 55 26 78 94 13 82 77 2 84 22 5 18 91 23 4 30 88 54 32 92 50 57 41 25 34 99 39 85 52 81 44 87 53 3 19 58 49 60 38" }, { "input": "99\n12 99 88 13 7 19 74 47 23 90 16 29 26 11 58 60 64 98 37 18 82 67 72 46 51 85 17 92 87 20 77 36 78 71 57 35 80 54 73 15 14 62 97 45 31 79 94 56 76 96 28 63 8 44 38 86 49 2 52 66 61 59 10 43 55 50 22 34 83 53 95 40 81 21 30 42 27 3 5 41 1 70 69 25 93 48 65 6 24 89 91 33 39 68 9 4 32 84 75", "output": "81 58 78 96 79 88 5 53 95 63 14 1 4 41 40 11 27 20 6 30 74 67 9 89 84 13 77 51 12 75 45 97 92 68 36 32 19 55 93 72 80 76 64 54 44 24 8 86 57 66 25 59 70 38 65 48 35 15 62 16 61 42 52 17 87 60 22 94 83 82 34 23 39 7 99 49 31 33 46 37 73 21 69 98 26 56 29 3 90 10 91 28 85 47 71 50 43 18 2" }, { "input": "99\n20 79 26 75 99 69 98 47 93 62 18 42 43 38 90 66 67 8 13 84 76 58 81 60 64 46 56 23 78 17 86 36 19 52 85 39 48 27 96 49 37 95 5 31 10 24 12 1 80 35 92 33 16 68 57 54 32 29 45 88 72 77 4 87 97 89 59 3 21 22 61 94 83 15 44 34 70 91 55 9 51 50 73 11 14 6 40 7 63 25 2 82 41 65 28 74 71 30 53", "output": "48 91 68 63 43 86 88 18 80 45 84 47 19 85 74 53 30 11 33 1 69 70 28 46 90 3 38 95 58 98 44 57 52 76 50 32 41 14 36 87 93 12 13 75 59 26 8 37 40 82 81 34 99 56 79 27 55 22 67 24 71 10 89 25 94 16 17 54 6 77 97 61 83 96 4 21 62 29 2 49 23 92 73 20 35 31 64 60 66 15 78 51 9 72 42 39 65 7 5" }, { "input": "99\n74 20 9 1 60 85 65 13 4 25 40 99 5 53 64 3 36 31 73 44 55 50 45 63 98 51 68 6 47 37 71 82 88 34 84 18 19 12 93 58 86 7 11 46 90 17 33 27 81 69 42 59 56 32 95 52 76 61 96 62 78 43 66 21 49 97 75 14 41 72 89 16 30 79 22 23 15 83 91 38 48 2 87 26 28 80 94 70 54 92 57 10 8 35 67 77 29 24 39", "output": "4 82 16 9 13 28 42 93 3 92 43 38 8 68 77 72 46 36 37 2 64 75 76 98 10 84 48 85 97 73 18 54 47 34 94 17 30 80 99 11 69 51 62 20 23 44 29 81 65 22 26 56 14 89 21 53 91 40 52 5 58 60 24 15 7 63 95 27 50 88 31 70 19 1 67 57 96 61 74 86 49 32 78 35 6 41 83 33 71 45 79 90 39 87 55 59 66 25 12" }, { "input": "99\n50 94 2 18 69 90 59 83 75 68 77 97 39 78 25 7 16 9 49 4 42 89 44 48 17 96 61 70 3 10 5 81 56 57 88 6 98 1 46 67 92 37 11 30 85 41 8 36 51 29 20 71 19 79 74 93 43 34 55 40 38 21 64 63 32 24 72 14 12 86 82 15 65 23 66 22 28 53 13 26 95 99 91 52 76 27 60 45 47 33 73 84 31 35 54 80 58 62 87", "output": "38 3 29 20 31 36 16 47 18 30 43 69 79 68 72 17 25 4 53 51 62 76 74 66 15 80 86 77 50 44 93 65 90 58 94 48 42 61 13 60 46 21 57 23 88 39 89 24 19 1 49 84 78 95 59 33 34 97 7 87 27 98 64 63 73 75 40 10 5 28 52 67 91 55 9 85 11 14 54 96 32 71 8 92 45 70 99 35 22 6 83 41 56 2 81 26 12 37 82" }, { "input": "99\n19 93 14 34 39 37 33 15 52 88 7 43 69 27 9 77 94 31 48 22 63 70 79 17 50 6 81 8 76 58 23 74 86 11 57 62 41 87 75 51 12 18 68 56 95 3 80 83 84 29 24 61 71 78 59 96 20 85 90 28 45 36 38 97 1 49 40 98 44 67 13 73 72 91 47 10 30 54 35 42 4 2 92 26 64 60 53 21 5 82 46 32 55 66 16 89 99 65 25", "output": "65 82 46 81 89 26 11 28 15 76 34 41 71 3 8 95 24 42 1 57 88 20 31 51 99 84 14 60 50 77 18 92 7 4 79 62 6 63 5 67 37 80 12 69 61 91 75 19 66 25 40 9 87 78 93 44 35 30 55 86 52 36 21 85 98 94 70 43 13 22 53 73 72 32 39 29 16 54 23 47 27 90 48 49 58 33 38 10 96 59 74 83 2 17 45 56 64 68 97" }, { "input": "99\n86 25 50 51 62 39 41 67 44 20 45 14 80 88 66 7 36 59 13 84 78 58 96 75 2 43 48 47 69 12 19 98 22 38 28 55 11 76 68 46 53 70 85 34 16 33 91 30 8 40 74 60 94 82 87 32 37 4 5 10 89 73 90 29 35 26 23 57 27 65 24 3 9 83 77 72 6 31 15 92 93 79 64 18 63 42 56 1 52 97 17 81 71 21 49 99 54 95 61", "output": "88 25 72 58 59 77 16 49 73 60 37 30 19 12 79 45 91 84 31 10 94 33 67 71 2 66 69 35 64 48 78 56 46 44 65 17 57 34 6 50 7 86 26 9 11 40 28 27 95 3 4 89 41 97 36 87 68 22 18 52 99 5 85 83 70 15 8 39 29 42 93 76 62 51 24 38 75 21 82 13 92 54 74 20 43 1 55 14 61 63 47 80 81 53 98 23 90 32 96" }, { "input": "100\n66 44 99 15 43 79 28 33 88 90 49 68 82 38 9 74 4 58 29 81 31 94 10 42 89 21 63 40 62 61 18 6 84 72 48 25 67 69 71 85 98 34 83 70 65 78 91 77 93 41 23 24 87 11 55 12 59 73 36 97 7 14 26 39 30 27 45 20 50 17 53 2 57 47 95 56 75 19 37 96 16 35 8 3 76 60 13 86 5 32 64 80 46 51 54 100 1 22 52 92", "output": "97 72 84 17 89 32 61 83 15 23 54 56 87 62 4 81 70 31 78 68 26 98 51 52 36 63 66 7 19 65 21 90 8 42 82 59 79 14 64 28 50 24 5 2 67 93 74 35 11 69 94 99 71 95 55 76 73 18 57 86 30 29 27 91 45 1 37 12 38 44 39 34 58 16 77 85 48 46 6 92 20 13 43 33 40 88 53 9 25 10 47 100 49 22 75 80 60 41 3 96" }, { "input": "99\n3 73 32 37 25 15 93 63 85 8 91 78 80 5 39 48 46 7 83 70 23 96 9 29 77 53 30 20 56 50 13 45 21 76 87 99 65 31 16 18 14 72 51 28 43 2 81 34 38 40 66 54 74 26 71 4 61 17 58 24 22 33 49 36 42 11 12 55 60 27 62 90 79 92 94 68 1 52 84 41 86 35 69 75 47 10 64 88 97 98 67 19 89 95 59 82 57 44 6", "output": "77 46 1 56 14 99 18 10 23 86 66 67 31 41 6 39 58 40 92 28 33 61 21 60 5 54 70 44 24 27 38 3 62 48 82 64 4 49 15 50 80 65 45 98 32 17 85 16 63 30 43 78 26 52 68 29 97 59 95 69 57 71 8 87 37 51 91 76 83 20 55 42 2 53 84 34 25 12 73 13 47 96 19 79 9 81 35 88 93 72 11 74 7 75 94 22 89 90 36" }, { "input": "100\n100 99 98 97 96 95 94 93 92 91 90 89 88 87 86 85 84 83 82 81 80 79 78 77 76 75 74 73 72 71 70 69 68 67 66 65 64 63 62 61 60 59 58 57 56 55 54 53 52 51 50 49 48 47 46 45 44 43 42 41 40 39 38 37 36 35 34 33 32 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1", "output": "100 99 98 97 96 95 94 93 92 91 90 89 88 87 86 85 84 83 82 81 80 79 78 77 76 75 74 73 72 71 70 69 68 67 66 65 64 63 62 61 60 59 58 57 56 55 54 53 52 51 50 49 48 47 46 45 44 43 42 41 40 39 38 37 36 35 34 33 32 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1" } ]
1,691,415,507
2,147,483,647
Python 3
OK
TESTS
101
122
0
# N,M = map(int,input().split()) # N = int(input()) # A = list(map(int,input().split())) N = int(input()) A = list(map(int,input().split())) d = [0] * N for i in range(N): d[A[i]-1] = i+1 print(*d)
Title: Presents Time Limit: None seconds Memory Limit: None megabytes Problem Description: Little Petya very much likes gifts. Recently he has received a new laptop as a New Year gift from his mother. He immediately decided to give it to somebody else as what can be more pleasant than giving somebody gifts. And on this occasion he organized a New Year party at his place and invited *n* his friends there. If there's one thing Petya likes more that receiving gifts, that's watching others giving gifts to somebody else. Thus, he safely hid the laptop until the next New Year and made up his mind to watch his friends exchanging gifts while he does not participate in the process. He numbered all his friends with integers from 1 to *n*. Petya remembered that a friend number *i* gave a gift to a friend number *p**i*. He also remembered that each of his friends received exactly one gift. Now Petya wants to know for each friend *i* the number of a friend who has given him a gift. Input Specification: The first line contains one integer *n* (1<=≤<=*n*<=≤<=100) — the quantity of friends Petya invited to the party. The second line contains *n* space-separated integers: the *i*-th number is *p**i* — the number of a friend who gave a gift to friend number *i*. It is guaranteed that each friend received exactly one gift. It is possible that some friends do not share Petya's ideas of giving gifts to somebody else. Those friends gave the gifts to themselves. Output Specification: Print *n* space-separated integers: the *i*-th number should equal the number of the friend who gave a gift to friend number *i*. Demo Input: ['4\n2 3 4 1\n', '3\n1 3 2\n', '2\n1 2\n'] Demo Output: ['4 1 2 3\n', '1 3 2\n', '1 2\n'] Note: none
```python # N,M = map(int,input().split()) # N = int(input()) # A = list(map(int,input().split())) N = int(input()) A = list(map(int,input().split())) d = [0] * N for i in range(N): d[A[i]-1] = i+1 print(*d) ```
3
665
B
Shopping
PROGRAMMING
1,400
[ "brute force" ]
null
null
Ayush is a cashier at the shopping center. Recently his department has started a ''click and collect" service which allows users to shop online. The store contains *k* items. *n* customers have already used the above service. Each user paid for *m* items. Let *a**ij* denote the *j*-th item in the *i*-th person's order. Due to the space limitations all the items are arranged in one single row. When Ayush receives the *i*-th order he will find one by one all the items *a**ij* (1<=≤<=*j*<=≤<=*m*) in the row. Let *pos*(*x*) denote the position of the item *x* in the row at the moment of its collection. Then Ayush takes time equal to *pos*(*a**i*1)<=+<=*pos*(*a**i*2)<=+<=...<=+<=*pos*(*a**im*) for the *i*-th customer. When Ayush accesses the *x*-th element he keeps a new stock in the front of the row and takes away the *x*-th element. Thus the values are updating. Your task is to calculate the total time it takes for Ayush to process all the orders. You can assume that the market has endless stock.
The first line contains three integers *n*, *m* and *k* (1<=≤<=*n*,<=*k*<=≤<=100,<=1<=≤<=*m*<=≤<=*k*) — the number of users, the number of items each user wants to buy and the total number of items at the market. The next line contains *k* distinct integers *p**l* (1<=≤<=*p**l*<=≤<=*k*) denoting the initial positions of the items in the store. The items are numbered with integers from 1 to *k*. Each of the next *n* lines contains *m* distinct integers *a**ij* (1<=≤<=*a**ij*<=≤<=*k*) — the order of the *i*-th person.
Print the only integer *t* — the total time needed for Ayush to process all the orders.
[ "2 2 5\n3 4 1 2 5\n1 5\n3 1\n" ]
[ "14\n" ]
Customer 1 wants the items 1 and 5. *pos*(1) = 3, so the new positions are: [1, 3, 4, 2, 5]. *pos*(5) = 5, so the new positions are: [5, 1, 3, 4, 2]. Time taken for the first customer is 3 + 5 = 8. Customer 2 wants the items 3 and 1. *pos*(3) = 3, so the new positions are: [3, 5, 1, 4, 2]. *pos*(1) = 3, so the new positions are: [1, 3, 5, 4, 2]. Time taken for the second customer is 3 + 3 = 6. Total time is 8 + 6 = 14. Formally *pos*(*x*) is the index of *x* in the current row.
0
[ { "input": "2 2 5\n3 4 1 2 5\n1 5\n3 1", "output": "14" }, { "input": "4 4 4\n1 2 3 4\n3 4 2 1\n4 3 2 1\n4 1 2 3\n4 1 2 3", "output": "59" }, { "input": "1 1 1\n1\n1", "output": "1" }, { "input": "10 1 100\n1 55 67 75 40 86 24 84 82 26 81 23 70 79 51 54 21 78 31 98 68 93 66 88 99 65 20 52 35 85 16 12 94 100 59 56 18 33 47 46 71 8 38 57 2 92 3 95 6 4 87 22 48 80 15 29 11 45 72 76 44 60 91 90 39 74 41 36 13 27 53 83 32 5 30 63 89 64 49 17 9 97 69 14 50 77 37 96 10 42 28 34 61 19 73 7 62 43 58 25\n33\n69\n51\n7\n68\n70\n1\n35\n24\n7", "output": "335" }, { "input": "100 1 1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1", "output": "100" }, { "input": "3 2 3\n3 1 2\n1 2\n2 1\n2 3", "output": "13" }, { "input": "10 10 10\n3 4 1 2 8 9 5 10 6 7\n9 10 7 8 6 1 2 3 4 5\n2 5 3 6 1 4 9 7 8 10\n2 9 1 8 4 7 5 10 6 3\n10 9 7 1 3 6 2 8 5 4\n2 5 1 3 7 10 4 9 8 6\n6 1 8 7 9 2 3 5 4 10\n1 3 2 8 6 9 4 10 5 7\n5 2 4 8 6 1 10 9 3 7\n5 1 7 10 4 6 2 8 9 3\n2 1 3 9 7 10 6 4 8 5", "output": "771" } ]
1,462,767,266
2,147,483,647
Python 3
OK
TESTS
10
78
4,608,000
number = int(input().split()[0]) #orders = int(input()) array = input().split() sum = 0 for i in range(0,number): items = input().split() for j in items: buffer = [] sum = sum + int(array.index(j)) +1 buffer.append(j) array.remove(j) array = buffer + array print(sum)
Title: Shopping Time Limit: None seconds Memory Limit: None megabytes Problem Description: Ayush is a cashier at the shopping center. Recently his department has started a ''click and collect" service which allows users to shop online. The store contains *k* items. *n* customers have already used the above service. Each user paid for *m* items. Let *a**ij* denote the *j*-th item in the *i*-th person's order. Due to the space limitations all the items are arranged in one single row. When Ayush receives the *i*-th order he will find one by one all the items *a**ij* (1<=≤<=*j*<=≤<=*m*) in the row. Let *pos*(*x*) denote the position of the item *x* in the row at the moment of its collection. Then Ayush takes time equal to *pos*(*a**i*1)<=+<=*pos*(*a**i*2)<=+<=...<=+<=*pos*(*a**im*) for the *i*-th customer. When Ayush accesses the *x*-th element he keeps a new stock in the front of the row and takes away the *x*-th element. Thus the values are updating. Your task is to calculate the total time it takes for Ayush to process all the orders. You can assume that the market has endless stock. Input Specification: The first line contains three integers *n*, *m* and *k* (1<=≤<=*n*,<=*k*<=≤<=100,<=1<=≤<=*m*<=≤<=*k*) — the number of users, the number of items each user wants to buy and the total number of items at the market. The next line contains *k* distinct integers *p**l* (1<=≤<=*p**l*<=≤<=*k*) denoting the initial positions of the items in the store. The items are numbered with integers from 1 to *k*. Each of the next *n* lines contains *m* distinct integers *a**ij* (1<=≤<=*a**ij*<=≤<=*k*) — the order of the *i*-th person. Output Specification: Print the only integer *t* — the total time needed for Ayush to process all the orders. Demo Input: ['2 2 5\n3 4 1 2 5\n1 5\n3 1\n'] Demo Output: ['14\n'] Note: Customer 1 wants the items 1 and 5. *pos*(1) = 3, so the new positions are: [1, 3, 4, 2, 5]. *pos*(5) = 5, so the new positions are: [5, 1, 3, 4, 2]. Time taken for the first customer is 3 + 5 = 8. Customer 2 wants the items 3 and 1. *pos*(3) = 3, so the new positions are: [3, 5, 1, 4, 2]. *pos*(1) = 3, so the new positions are: [1, 3, 5, 4, 2]. Time taken for the second customer is 3 + 3 = 6. Total time is 8 + 6 = 14. Formally *pos*(*x*) is the index of *x* in the current row.
```python number = int(input().split()[0]) #orders = int(input()) array = input().split() sum = 0 for i in range(0,number): items = input().split() for j in items: buffer = [] sum = sum + int(array.index(j)) +1 buffer.append(j) array.remove(j) array = buffer + array print(sum) ```
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,624,549,807
2,147,483,647
Python 3
OK
TESTS
44
77
0
s = input() counter = 0 counter += min(abs(ord('a') - ord(s[0])), 26 - abs(ord('a') - ord(s[0]))) for i in range(1,len(s)): counter += min(abs(ord(s[i-1]) - ord(s[i])), 26 - abs(ord(s[i-1]) - ord(s[i]))) print(counter)
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 = input() counter = 0 counter += min(abs(ord('a') - ord(s[0])), 26 - abs(ord('a') - ord(s[0]))) for i in range(1,len(s)): counter += min(abs(ord(s[i-1]) - ord(s[i])), 26 - abs(ord(s[i-1]) - ord(s[i]))) print(counter) ```
3
133
A
HQ9+
PROGRAMMING
900
[ "implementation" ]
null
null
HQ9+ is a joke programming language which has only four one-character instructions: - "H" prints "Hello, World!",- "Q" prints the source code of the program itself,- "9" prints the lyrics of "99 Bottles of Beer" song, - "+" increments the value stored in the internal accumulator. Instructions "H" and "Q" are case-sensitive and must be uppercase. The characters of the program which are not instructions are ignored. You are given a program written in HQ9+. You have to figure out whether executing this program will produce any output.
The input will consist of a single line *p* which will give a program in HQ9+. String *p* will contain between 1 and 100 characters, inclusive. ASCII-code of each character of *p* will be between 33 (exclamation mark) and 126 (tilde), inclusive.
Output "YES", if executing the program will produce any output, and "NO" otherwise.
[ "Hi!\n", "Codeforces\n" ]
[ "YES\n", "NO\n" ]
In the first case the program contains only one instruction — "H", which prints "Hello, World!". In the second case none of the program characters are language instructions.
500
[ { "input": "Hi!", "output": "YES" }, { "input": "Codeforces", "output": "NO" }, { "input": "a+b=c", "output": "NO" }, { "input": "hq-lowercase", "output": "NO" }, { "input": "Q", "output": "YES" }, { "input": "9", "output": "YES" }, { "input": "H", "output": "YES" }, { "input": "+", "output": "NO" }, { "input": "~", "output": "NO" }, { "input": "dEHsbM'gS[\\brZ_dpjXw8f?L[4E\"s4Zc9*(,j:>p$}m7HD[_9nOWQ\\uvq2mHWR", "output": "YES" }, { "input": "tt6l=RHOfStm.;Qd$-}zDes*E,.F7qn5-b%HC", "output": "YES" }, { "input": "@F%K2=%RyL/", "output": "NO" }, { "input": "juq)k(FT.^G=G\\zcqnO\"uJIE1_]KFH9S=1c\"mJ;F9F)%>&.WOdp09+k`Yc6}\"6xw,Aos:M\\_^^:xBb[CcsHm?J", "output": "YES" }, { "input": "6G_\"Fq#<AWyHG=Rci1t%#Jc#x<Fpg'N@t%F=``YO7\\Zd;6PkMe<#91YgzTC)", "output": "YES" }, { "input": "Fvg_~wC>SO4lF}*c`Q;mII9E{4.QodbqN]C", "output": "YES" }, { "input": "p-UXsbd&f", "output": "NO" }, { "input": "<]D7NMA)yZe=`?RbP5lsa.l_Mg^V:\"-0x+$3c,q&L%18Ku<HcA\\s!^OQblk^x{35S'>yz8cKgVHWZ]kV0>_", "output": "YES" }, { "input": "f.20)8b+.R}Gy!DbHU3v(.(=Q^`z[_BaQ}eO=C1IK;b2GkD\\{\\Bf\"!#qh]", "output": "YES" }, { "input": "}do5RU<(w<q[\"-NR)IAH_HyiD{", "output": "YES" }, { "input": "Iy^.,Aw*,5+f;l@Q;jLK'G5H-r1Pfmx?ei~`CjMmUe{K:lS9cu4ay8rqRh-W?Gqv!e-j*U)!Mzn{E8B6%~aSZ~iQ_QwlC9_cX(o8", "output": "YES" }, { "input": "sKLje,:q>-D,;NvQ3,qN3-N&tPx0nL/,>Ca|z\"k2S{NF7btLa3_TyXG4XZ:`(t&\"'^M|@qObZxv", "output": "YES" }, { "input": "%z:c@1ZsQ@\\6U/NQ+M9R>,$bwG`U1+C\\18^:S},;kw!&4r|z`", "output": "YES" }, { "input": "OKBB5z7ud81[Tn@P\"nDUd,>@", "output": "NO" }, { "input": "y{0;neX]w0IenPvPx0iXp+X|IzLZZaRzBJ>q~LhMhD$x-^GDwl;,a'<bAqH8QrFwbK@oi?I'W.bZ]MlIQ/x(0YzbTH^l.)]0Bv", "output": "YES" }, { "input": "EL|xIP5_+Caon1hPpQ0[8+r@LX4;b?gMy>;/WH)pf@Ur*TiXu*e}b-*%acUA~A?>MDz#!\\Uh", "output": "YES" }, { "input": "UbkW=UVb>;z6)p@Phr;^Dn.|5O{_i||:Rv|KJ_ay~V(S&Jp", "output": "NO" }, { "input": "!3YPv@2JQ44@)R2O_4`GO", "output": "YES" }, { "input": "Kba/Q,SL~FMd)3hOWU'Jum{9\"$Ld4:GW}D]%tr@G{hpG:PV5-c'VIZ~m/6|3I?_4*1luKnOp`%p|0H{[|Y1A~4-ZdX,Rw2[\\", "output": "YES" }, { "input": "NRN*=v>;oU7[acMIJn*n^bWm!cm3#E7Efr>{g-8bl\"DN4~_=f?[T;~Fq#&)aXq%</GcTJD^e$@Extm[e\"C)q_L", "output": "NO" }, { "input": "y#<fv{_=$MP!{D%I\\1OqjaqKh[pqE$KvYL<9@*V'j8uH0/gQdA'G;&y4Cv6&", "output": "YES" }, { "input": "+SE_Pg<?7Fh,z&uITQut2a-mk8X8La`c2A}", "output": "YES" }, { "input": "Uh3>ER](J", "output": "NO" }, { "input": "!:!{~=9*\\P;Z6F?HC5GadFz)>k*=u|+\"Cm]ICTmB!`L{&oS/z6b~#Snbp/^\\Q>XWU-vY+/dP.7S=-#&whS@,", "output": "YES" }, { "input": "KimtYBZp+ISeO(uH;UldoE6eAcp|9u?SzGZd6j-e}[}u#e[Cx8.qgY]$2!", "output": "YES" }, { "input": "[:[SN-{r>[l+OggH3v3g{EPC*@YBATT@", "output": "YES" }, { "input": "'jdL(vX", "output": "NO" }, { "input": "Q;R+aay]cL?Zh*uG\"YcmO*@Dts*Gjp}D~M7Z96+<4?9I3aH~0qNdO(RmyRy=ci,s8qD_kwj;QHFzD|5,5", "output": "YES" }, { "input": "{Q@#<LU_v^qdh%gGxz*pu)Y\"]k-l-N30WAxvp2IE3:jD0Wi4H/xWPH&s", "output": "YES" }, { "input": "~@Gb(S&N$mBuBUMAky-z^{5VwLNTzYg|ZUZncL@ahS?K*As<$iNUARM3r43J'jJB)$ujfPAq\"G<S9flGyakZg!2Z.-NJ|2{F>]", "output": "YES" }, { "input": "Jp5Aa>aP6fZ!\\6%A}<S}j{O4`C6y$8|i3IW,WHy&\"ioE&7zP\"'xHAY;:x%@SnS]Mr{R|})gU", "output": "YES" }, { "input": "ZA#:U)$RI^sE\\vuAt]x\"2zipI!}YEu2<j$:H0_9/~eB?#->", "output": "YES" }, { "input": "&ppw0._:\\p-PuWM@l}%%=", "output": "NO" }, { "input": "P(^pix\"=oiEZu8?@d@J(I`Xp5TN^T3\\Z7P5\"ZrvZ{2Fwz3g-8`U!)(1$a<g+9Q|COhDoH;HwFY02Pa|ZGp$/WZBR=>6Jg!yr", "output": "YES" }, { "input": "`WfODc\\?#ax~1xu@[ao+o_rN|L7%v,p,nDv>3+6cy.]q3)+A6b!q*Hc+#.t4f~vhUa~$^q", "output": "YES" }, { "input": ",)TH9N}'6t2+0Yg?S#6/{_.,!)9d}h'wG|sY&'Ul4D0l0", "output": "YES" }, { "input": "VXB&r9Z)IlKOJ:??KDA", "output": "YES" }, { "input": "\")1cL>{o\\dcYJzu?CefyN^bGRviOH&P7rJS3PT4:0V3F)%\\}L=AJouYsj_>j2|7^1NWu*%NbOP>ngv-ls<;b-4Sd3Na0R", "output": "YES" }, { "input": "2Y}\\A)>row{~c[g>:'.|ZC8%UTQ/jcdhK%6O)QRC.kd@%y}LJYk=V{G5pQK/yKJ%{G3C", "output": "YES" }, { "input": "O.&=qt(`z(", "output": "NO" }, { "input": "_^r6fyIc/~~;>l%9?aVEi7-{=,[<aMiB'-scSg$$|\"jAzY0N>QkHHGBZj2c\"=fhRlWd5;5K|GgU?7h]!;wl@", "output": "YES" }, { "input": "+/`sAd&eB29E=Nu87${.u6GY@$^a$,}s^!p!F}B-z8<<wORb<S7;HM1a,gp", "output": "YES" }, { "input": "U_ilyOGMT+QiW/M8/D(1=6a7)_FA,h4`8", "output": "YES" }, { "input": "!0WKT:$O", "output": "NO" }, { "input": "1EE*I%EQz6$~pPu7|(r7nyPQt4uGU@]~H'4uII?b1_Wn)K?ZRHrr0z&Kr;}aO3<mN=3:{}QgPxI|Ncm4#)", "output": "YES" }, { "input": "[u3\"$+!:/.<Dp1M7tH}:zxjt],^kv}qP;y12\"`^'/u*h%AFmPJ>e1#Yly", "output": "YES" }, { "input": "'F!_]tB<A&UO+p?7liE>(x&RFgG2~\\(", "output": "NO" }, { "input": "Qv)X8", "output": "YES" }, { "input": "aGv7,J@&g1(}E3g6[LuDZwZl2<v7IwQA%\"R(?ouBD>_=y\"3Kf%^>vON<a^T\\G^ootgE@whWmZo=[ex|F", "output": "YES" }, { "input": "e{}2vQ+/r@p0}cLKNe4MCk", "output": "YES" }, { "input": "mzbmweyydiadtlcouegmdbyfwurpwbpuvhifnuapwyndmhtqvkgkbhtytszotwflegsjzzszfwtzfpnscguemwrczqxycivdqnkH", "output": "YES" }, { "input": "Qzbmweyydiadtlcouegmdbyfwurpwbpuvhifnuapwyndmhtqvkgkbhtytszotwflegsjzzszfwtzfpnscguemwrczqxycivdqnky", "output": "YES" }, { "input": "mzbmweyydiadtlcouegmdbyfwurpwb9uvhifnuapwyndmhtqvkgkbhtytszotwflegsjzzszfwtzfpnscguemwrczqxycivdqnky", "output": "YES" }, { "input": "1H1", "output": "YES" }, { "input": "+Q", "output": "YES" }, { "input": "1ab", "output": "NO" }, { "input": "!", "output": "NO" }, { "input": "0+", "output": "NO" }, { "input": "+H", "output": "YES" }, { "input": "cH", "output": "YES" }, { "input": "+8", "output": "NO" }, { "input": "8+", "output": "NO" }, { "input": "++++++++++++++++++++++++++", "output": "NO" }, { "input": "(+)", "output": "NO" }, { "input": "H+", "output": "YES" }, { "input": "a!", "output": "NO" }, { "input": "++++++++++++++", "output": "NO" }, { "input": "+++++++++++++++++++++++++++++++++++++++++++++++++++++++++", "output": "NO" }, { "input": "8", "output": "NO" }, { "input": "3", "output": "NO" }, { "input": "HQ9", "output": "YES" }, { "input": "+++H", "output": "YES" }, { "input": "++++++++++", "output": "NO" }, { "input": "HHHHHHH", "output": "YES" }, { "input": "abacabaH", "output": "YES" }, { "input": "+G", "output": "NO" } ]
1,688,244,120
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
2
92
0
string = input() if string.count("H")>=1 or string.count("Q")>=1 or string.count("9")>=1 or string.count("+")>=1: print("YES") elif string.count("72")>=1 or string.count("81")>=1 or string.count("57")>=1 or string.count("43")>=1: print("YES") else: print("NO")
Title: HQ9+ Time Limit: None seconds Memory Limit: None megabytes Problem Description: HQ9+ is a joke programming language which has only four one-character instructions: - "H" prints "Hello, World!",- "Q" prints the source code of the program itself,- "9" prints the lyrics of "99 Bottles of Beer" song, - "+" increments the value stored in the internal accumulator. Instructions "H" and "Q" are case-sensitive and must be uppercase. The characters of the program which are not instructions are ignored. You are given a program written in HQ9+. You have to figure out whether executing this program will produce any output. Input Specification: The input will consist of a single line *p* which will give a program in HQ9+. String *p* will contain between 1 and 100 characters, inclusive. ASCII-code of each character of *p* will be between 33 (exclamation mark) and 126 (tilde), inclusive. Output Specification: Output "YES", if executing the program will produce any output, and "NO" otherwise. Demo Input: ['Hi!\n', 'Codeforces\n'] Demo Output: ['YES\n', 'NO\n'] Note: In the first case the program contains only one instruction — "H", which prints "Hello, World!". In the second case none of the program characters are language instructions.
```python string = input() if string.count("H")>=1 or string.count("Q")>=1 or string.count("9")>=1 or string.count("+")>=1: print("YES") elif string.count("72")>=1 or string.count("81")>=1 or string.count("57")>=1 or string.count("43")>=1: print("YES") else: print("NO") ```
0
1,006
D
Two Strings Swaps
PROGRAMMING
1,700
[ "implementation" ]
null
null
You are given two strings $a$ and $b$ consisting of lowercase English letters, both of length $n$. The characters of both strings have indices from $1$ to $n$, inclusive. You are allowed to do the following changes: - Choose any index $i$ ($1 \le i \le n$) and swap characters $a_i$ and $b_i$; - Choose any index $i$ ($1 \le i \le n$) and swap characters $a_i$ and $a_{n - i + 1}$; - Choose any index $i$ ($1 \le i \le n$) and swap characters $b_i$ and $b_{n - i + 1}$. Note that if $n$ is odd, you are formally allowed to swap $a_{\lceil\frac{n}{2}\rceil}$ with $a_{\lceil\frac{n}{2}\rceil}$ (and the same with the string $b$) but this move is useless. Also you can swap two equal characters but this operation is useless as well. You have to make these strings equal by applying any number of changes described above, in any order. But it is obvious that it may be impossible to make two strings equal by these swaps. In one preprocess move you can replace a character in $a$ with another character. In other words, in a single preprocess move you can choose any index $i$ ($1 \le i \le n$), any character $c$ and set $a_i := c$. Your task is to find the minimum number of preprocess moves to apply in such a way that after them you can make strings $a$ and $b$ equal by applying some number of changes described in the list above. Note that the number of changes you make after the preprocess moves does not matter. Also note that you cannot apply preprocess moves to the string $b$ or make any preprocess moves after the first change is made.
The first line of the input contains one integer $n$ ($1 \le n \le 10^5$) — the length of strings $a$ and $b$. The second line contains the string $a$ consisting of exactly $n$ lowercase English letters. The third line contains the string $b$ consisting of exactly $n$ lowercase English letters.
Print a single integer — the minimum number of preprocess moves to apply before changes, so that it is possible to make the string $a$ equal to string $b$ with a sequence of changes from the list above.
[ "7\nabacaba\nbacabaa\n", "5\nzcabd\ndbacz\n" ]
[ "4\n", "0\n" ]
In the first example preprocess moves are as follows: $a_1 := $'b', $a_3 := $'c', $a_4 := $'a' and $a_5:=$'b'. Afterwards, $a = $"bbcabba". Then we can obtain equal strings by the following sequence of changes: $swap(a_2, b_2)$ and $swap(a_2, a_6)$. There is no way to use fewer than $4$ preprocess moves before a sequence of changes to make string equal, so the answer in this example is $4$. In the second example no preprocess moves are required. We can use the following sequence of changes to make $a$ and $b$ equal: $swap(b_1, b_5)$, $swap(a_2, a_4)$.
0
[ { "input": "7\nabacaba\nbacabaa", "output": "4" }, { "input": "5\nzcabd\ndbacz", "output": "0" }, { "input": "1\na\nb", "output": "1" }, { "input": "5\nahmad\nyogaa", "output": "3" } ]
1,691,698,420
2,147,483,647
PyPy 3-64
WRONG_ANSWER
TESTS
2
140
7,168,000
import sys input = lambda: sys.stdin.readline().rstrip() import math from heapq import heappush , heappop from collections import defaultdict,deque,Counter from bisect import * N = int(input()) S = input() T = input() def check(C): keys = list(C.keys()) if len(keys)>2: return False if len(keys)==1: return True if C[keys[0]]==C[keys[1]]: return True return False def cal(A): t = int(A[0]!=A[2]) + int(A[1]!=A[3]) t = min(t, int(A[0]!=A[3]) + int(A[1]!=A[2])) return t ans = 0 for i in range(N//2): j = N-i-1 #print(i,j,S[i],S[j]) tmp = [S[i],S[j],T[i],T[j]] C = Counter(tmp) if check(C): continue ans += cal(tmp) if N%2: #print(N//2+1) if S[N//2]!=T[N//2]: ans+=1 print(ans)
Title: Two Strings Swaps Time Limit: None seconds Memory Limit: None megabytes Problem Description: You are given two strings $a$ and $b$ consisting of lowercase English letters, both of length $n$. The characters of both strings have indices from $1$ to $n$, inclusive. You are allowed to do the following changes: - Choose any index $i$ ($1 \le i \le n$) and swap characters $a_i$ and $b_i$; - Choose any index $i$ ($1 \le i \le n$) and swap characters $a_i$ and $a_{n - i + 1}$; - Choose any index $i$ ($1 \le i \le n$) and swap characters $b_i$ and $b_{n - i + 1}$. Note that if $n$ is odd, you are formally allowed to swap $a_{\lceil\frac{n}{2}\rceil}$ with $a_{\lceil\frac{n}{2}\rceil}$ (and the same with the string $b$) but this move is useless. Also you can swap two equal characters but this operation is useless as well. You have to make these strings equal by applying any number of changes described above, in any order. But it is obvious that it may be impossible to make two strings equal by these swaps. In one preprocess move you can replace a character in $a$ with another character. In other words, in a single preprocess move you can choose any index $i$ ($1 \le i \le n$), any character $c$ and set $a_i := c$. Your task is to find the minimum number of preprocess moves to apply in such a way that after them you can make strings $a$ and $b$ equal by applying some number of changes described in the list above. Note that the number of changes you make after the preprocess moves does not matter. Also note that you cannot apply preprocess moves to the string $b$ or make any preprocess moves after the first change is made. Input Specification: The first line of the input contains one integer $n$ ($1 \le n \le 10^5$) — the length of strings $a$ and $b$. The second line contains the string $a$ consisting of exactly $n$ lowercase English letters. The third line contains the string $b$ consisting of exactly $n$ lowercase English letters. Output Specification: Print a single integer — the minimum number of preprocess moves to apply before changes, so that it is possible to make the string $a$ equal to string $b$ with a sequence of changes from the list above. Demo Input: ['7\nabacaba\nbacabaa\n', '5\nzcabd\ndbacz\n'] Demo Output: ['4\n', '0\n'] Note: In the first example preprocess moves are as follows: $a_1 := $'b', $a_3 := $'c', $a_4 := $'a' and $a_5:=$'b'. Afterwards, $a = $"bbcabba". Then we can obtain equal strings by the following sequence of changes: $swap(a_2, b_2)$ and $swap(a_2, a_6)$. There is no way to use fewer than $4$ preprocess moves before a sequence of changes to make string equal, so the answer in this example is $4$. In the second example no preprocess moves are required. We can use the following sequence of changes to make $a$ and $b$ equal: $swap(b_1, b_5)$, $swap(a_2, a_4)$.
```python import sys input = lambda: sys.stdin.readline().rstrip() import math from heapq import heappush , heappop from collections import defaultdict,deque,Counter from bisect import * N = int(input()) S = input() T = input() def check(C): keys = list(C.keys()) if len(keys)>2: return False if len(keys)==1: return True if C[keys[0]]==C[keys[1]]: return True return False def cal(A): t = int(A[0]!=A[2]) + int(A[1]!=A[3]) t = min(t, int(A[0]!=A[3]) + int(A[1]!=A[2])) return t ans = 0 for i in range(N//2): j = N-i-1 #print(i,j,S[i],S[j]) tmp = [S[i],S[j],T[i],T[j]] C = Counter(tmp) if check(C): continue ans += cal(tmp) if N%2: #print(N//2+1) if S[N//2]!=T[N//2]: ans+=1 print(ans) ```
0
349
B
Color the Fence
PROGRAMMING
1,700
[ "data structures", "dp", "greedy", "implementation" ]
null
null
Igor has fallen in love with Tanya. Now Igor wants to show his feelings and write a number on the fence opposite to Tanya's house. Igor thinks that the larger the number is, the more chance to win Tanya's heart he has. Unfortunately, Igor could only get *v* liters of paint. He did the math and concluded that digit *d* requires *a**d* liters of paint. Besides, Igor heard that Tanya doesn't like zeroes. That's why Igor won't use them in his number. Help Igor find the maximum number he can write on the fence.
The first line contains a positive integer *v* (0<=≤<=*v*<=≤<=106). The second line contains nine positive integers *a*1,<=*a*2,<=...,<=*a*9 (1<=≤<=*a**i*<=≤<=105).
Print the maximum number Igor can write on the fence. If he has too little paint for any digit (so, he cannot write anything), print -1.
[ "5\n5 4 3 2 1 2 3 4 5\n", "2\n9 11 1 12 5 8 9 10 6\n", "0\n1 1 1 1 1 1 1 1 1\n" ]
[ "55555\n", "33\n", "-1\n" ]
none
1,000
[ { "input": "5\n5 4 3 2 1 2 3 4 5", "output": "55555" }, { "input": "2\n9 11 1 12 5 8 9 10 6", "output": "33" }, { "input": "0\n1 1 1 1 1 1 1 1 1", "output": "-1" }, { "input": "50\n5 3 10 2 2 4 3 6 5", "output": "5555555555555555555555555" }, { "input": "22\n405 343 489 474 385 23 100 94 276", "output": "-1" }, { "input": "62800\n867 936 2 888 474 530 287 822 220", "output": "3333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333..." }, { "input": "27\n836 637 966 929 82 678 213 465 688", "output": "-1" }, { "input": "1000000\n100000 100000 100000 100000 100000 100000 100000 100000 100000", "output": "9999999999" }, { "input": "898207\n99745 99746 99748 99752 99760 99776 99808 99872 100000", "output": "987654321" }, { "input": "80910\n64537 83748 97081 82722 12334 3056 9491 59130 28478", "output": "66666666666666666666666666" }, { "input": "120081\n11268 36403 73200 12674 83919 74218 74172 91581 68432", "output": "4444411111" }, { "input": "839851\n29926 55862 57907 51153 56350 86145 1909 22622 89861", "output": "7777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777" }, { "input": "751233\n69761 51826 91095 73642 98995 93262 377 38818 97480", "output": "7777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777..." }, { "input": "306978\n95955 99204 81786 41258 96065 46946 64532 36297 70808", "output": "88888888" }, { "input": "366313\n18486 12701 92334 95391 61480 14118 20465 69784 13592", "output": "9999999999922222222222222222" }, { "input": "320671\n95788 46450 97582 95928 47742 15508 10466 10301 38822", "output": "8888888888888888888888888888888" }, { "input": "913928\n80373 47589 53204 68236 44060 97485 82241 44149 59825", "output": "99888888888888855555" }, { "input": "630384\n19652 11530 20316 3161 87360 64207 74067 77894 81452", "output": "4444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444" }, { "input": "95\n22076 12056 63350 12443 43123 585 52908 18372 96799", "output": "-1" }, { "input": "271380\n19135 80309 23783 48534 98990 37278 85258 67602 40288", "output": "11111111111111" }, { "input": "80085\n56973 29725 30219 17439 53162 6051 41388 35555 39392", "output": "6666666666666" }, { "input": "201332\n20008 22829 30296 1967 32154 67760 11437 90972 79865", "output": "444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444" }, { "input": "3402\n64151 98148 81468 82342 48823 93464 5989 58868 77138", "output": "-1" }, { "input": "432544\n95724 98294 23292 24174 57778 95072 81898 50019 86824", "output": "444444444444444333" }, { "input": "1000000\n1 1 1 1 1 1 1 1 1", "output": "9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999..." }, { "input": "1000000\n2 2 2 2 2 2 2 2 2", "output": "9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999..." }, { "input": "1000000\n2 3 2 2 3 2 2 3 2", "output": "9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999..." }, { "input": "999999\n2 3 2 2 3 2 2 3 3", "output": "9777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777..." }, { "input": "153\n85 91 28 53 29 30 92 36 89", "output": "86653" }, { "input": "26531\n64 93 48 49 86 57 93 60 96", "output": "8864433333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333..." }, { "input": "17186\n50 90 76 51 91 54 71 90 73", "output": "9666411111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111" }, { "input": "11213\n51 82 49 50 99 52 69 96 85", "output": "964433333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333" }, { "input": "20075\n57 42 99 45 56 80 76 71 63", "output": "954422222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222" }, { "input": "21069\n31 19 49 30 28 43 21 25 28", "output": "9872222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222..." }, { "input": "4822\n35 36 21 13 34 36 14 16 20", "output": "9877444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444" } ]
1,609,046,222
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
0
156
204,800
n = int(input()) a= list(map(int, input().split())) mini = 9999999 c = [] for i in range(len(a)): if mini>a[i]: mini = a[i] c = [] if mini==a[i]: c.append(i) if mini<n: b = max(c) d = [] remaining = n-a[b]*(n//a[b]) for i in range(n//a[b]): c+=[b+1] for i in range(len(c)): for j in range(8, b, -1): if a[j]-a[b]<=remaining: c[i] = j+1 remaining-=a[j]-a[b] break for i in c: print(i, end = "") else: print(-1)
Title: Color the Fence Time Limit: None seconds Memory Limit: None megabytes Problem Description: Igor has fallen in love with Tanya. Now Igor wants to show his feelings and write a number on the fence opposite to Tanya's house. Igor thinks that the larger the number is, the more chance to win Tanya's heart he has. Unfortunately, Igor could only get *v* liters of paint. He did the math and concluded that digit *d* requires *a**d* liters of paint. Besides, Igor heard that Tanya doesn't like zeroes. That's why Igor won't use them in his number. Help Igor find the maximum number he can write on the fence. Input Specification: The first line contains a positive integer *v* (0<=≤<=*v*<=≤<=106). The second line contains nine positive integers *a*1,<=*a*2,<=...,<=*a*9 (1<=≤<=*a**i*<=≤<=105). Output Specification: Print the maximum number Igor can write on the fence. If he has too little paint for any digit (so, he cannot write anything), print -1. Demo Input: ['5\n5 4 3 2 1 2 3 4 5\n', '2\n9 11 1 12 5 8 9 10 6\n', '0\n1 1 1 1 1 1 1 1 1\n'] Demo Output: ['55555\n', '33\n', '-1\n'] Note: none
```python n = int(input()) a= list(map(int, input().split())) mini = 9999999 c = [] for i in range(len(a)): if mini>a[i]: mini = a[i] c = [] if mini==a[i]: c.append(i) if mini<n: b = max(c) d = [] remaining = n-a[b]*(n//a[b]) for i in range(n//a[b]): c+=[b+1] for i in range(len(c)): for j in range(8, b, -1): if a[j]-a[b]<=remaining: c[i] = j+1 remaining-=a[j]-a[b] break for i in c: print(i, end = "") else: print(-1) ```
0
656
A
Da Vinci Powers
PROGRAMMING
1,900
[ "*special" ]
null
null
The input contains a single integer *a* (0<=≤<=*a*<=≤<=35). Output a single integer.
The input contains a single integer *a* (0<=≤<=*a*<=≤<=35).
Output a single integer.
[ "3\n", "10\n" ]
[ "8\n", "1024\n" ]
none
0
[ { "input": "3", "output": "8" }, { "input": "10", "output": "1024" }, { "input": "35", "output": "33940307968" }, { "input": "0", "output": "1" }, { "input": "1", "output": "2" }, { "input": "2", "output": "4" }, { "input": "4", "output": "16" }, { "input": "5", "output": "32" }, { "input": "6", "output": "64" }, { "input": "7", "output": "128" }, { "input": "8", "output": "256" }, { "input": "9", "output": "512" }, { "input": "11", "output": "2048" }, { "input": "12", "output": "4096" }, { "input": "13", "output": "8092" }, { "input": "14", "output": "16184" }, { "input": "15", "output": "32368" }, { "input": "16", "output": "64736" }, { "input": "17", "output": "129472" }, { "input": "18", "output": "258944" }, { "input": "19", "output": "517888" }, { "input": "20", "output": "1035776" }, { "input": "21", "output": "2071552" }, { "input": "22", "output": "4143104" }, { "input": "23", "output": "8286208" }, { "input": "24", "output": "16572416" }, { "input": "25", "output": "33144832" }, { "input": "26", "output": "66289664" }, { "input": "27", "output": "132579328" }, { "input": "28", "output": "265158656" }, { "input": "29", "output": "530317312" }, { "input": "30", "output": "1060634624" }, { "input": "31", "output": "2121269248" }, { "input": "32", "output": "4242538496" }, { "input": "33", "output": "8485076992" }, { "input": "34", "output": "16970153984" } ]
1,459,702,179
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
14
61
4,608,000
n = int(input()) if (n == 35): print(33940307968) else: print(2**n)
Title: Da Vinci Powers Time Limit: None seconds Memory Limit: None megabytes Problem Description: The input contains a single integer *a* (0<=≤<=*a*<=≤<=35). Output a single integer. Input Specification: The input contains a single integer *a* (0<=≤<=*a*<=≤<=35). Output Specification: Output a single integer. Demo Input: ['3\n', '10\n'] Demo Output: ['8\n', '1024\n'] Note: none
```python n = int(input()) if (n == 35): print(33940307968) else: print(2**n) ```
0
727
A
Transformation: from A to B
PROGRAMMING
1,000
[ "brute force", "dfs and similar", "math" ]
null
null
Vasily has a number *a*, which he wants to turn into a number *b*. For this purpose, he can do two types of operations: - multiply the current number by 2 (that is, replace the number *x* by 2·*x*); - append the digit 1 to the right of current number (that is, replace the number *x* by 10·*x*<=+<=1). You need to help Vasily to transform the number *a* into the number *b* using only the operations described above, or find that it is impossible. Note that in this task you are not required to minimize the number of operations. It suffices to find any way to transform *a* into *b*.
The first line contains two positive integers *a* and *b* (1<=≤<=*a*<=&lt;<=*b*<=≤<=109) — the number which Vasily has and the number he wants to have.
If there is no way to get *b* from *a*, print "NO" (without quotes). Otherwise print three lines. On the first line print "YES" (without quotes). The second line should contain single integer *k* — the length of the transformation sequence. On the third line print the sequence of transformations *x*1,<=*x*2,<=...,<=*x**k*, where: - *x*1 should be equal to *a*, - *x**k* should be equal to *b*, - *x**i* should be obtained from *x**i*<=-<=1 using any of two described operations (1<=&lt;<=*i*<=≤<=*k*). If there are multiple answers, print any of them.
[ "2 162\n", "4 42\n", "100 40021\n" ]
[ "YES\n5\n2 4 8 81 162 \n", "NO\n", "YES\n5\n100 200 2001 4002 40021 \n" ]
none
1,000
[ { "input": "2 162", "output": "YES\n5\n2 4 8 81 162 " }, { "input": "4 42", "output": "NO" }, { "input": "100 40021", "output": "YES\n5\n100 200 2001 4002 40021 " }, { "input": "1 111111111", "output": "YES\n9\n1 11 111 1111 11111 111111 1111111 11111111 111111111 " }, { "input": "1 1000000000", "output": "NO" }, { "input": "999999999 1000000000", "output": "NO" }, { "input": "1 2", "output": "YES\n2\n1 2 " }, { "input": "1 536870912", "output": "YES\n30\n1 2 4 8 16 32 64 128 256 512 1024 2048 4096 8192 16384 32768 65536 131072 262144 524288 1048576 2097152 4194304 8388608 16777216 33554432 67108864 134217728 268435456 536870912 " }, { "input": "11111 11111111", "output": "YES\n4\n11111 111111 1111111 11111111 " }, { "input": "59139 946224", "output": "YES\n5\n59139 118278 236556 473112 946224 " }, { "input": "9859 19718", "output": "YES\n2\n9859 19718 " }, { "input": "25987 51974222", "output": "YES\n5\n25987 259871 2598711 25987111 51974222 " }, { "input": "9411 188222222", "output": "YES\n6\n9411 94111 941111 9411111 94111111 188222222 " }, { "input": "25539 510782222", "output": "YES\n6\n25539 255391 2553911 25539111 255391111 510782222 " }, { "input": "76259 610072", "output": "YES\n4\n76259 152518 305036 610072 " }, { "input": "92387 184774", "output": "YES\n2\n92387 184774 " }, { "input": "8515 85151111", "output": "YES\n5\n8515 85151 851511 8515111 85151111 " }, { "input": "91939 9193911", "output": "YES\n3\n91939 919391 9193911 " }, { "input": "30518 610361", "output": "YES\n3\n30518 61036 610361 " }, { "input": "46646 373168844", "output": "YES\n7\n46646 466461 932922 9329221 93292211 186584422 373168844 " }, { "input": "30070 300701", "output": "YES\n2\n30070 300701 " }, { "input": "13494 1079528", "output": "YES\n5\n13494 134941 269882 539764 1079528 " }, { "input": "96918 775344422", "output": "YES\n7\n96918 193836 1938361 3876722 38767221 387672211 775344422 " }, { "input": "13046 260921", "output": "YES\n3\n13046 26092 260921 " }, { "input": "29174 5834811", "output": "YES\n4\n29174 58348 583481 5834811 " }, { "input": "79894 319576421", "output": "YES\n6\n79894 798941 1597882 15978821 31957642 319576421 " }, { "input": "96022 1920442", "output": "YES\n3\n96022 960221 1920442 " }, { "input": "79446 6355681", "output": "YES\n5\n79446 158892 317784 635568 6355681 " }, { "input": "5440 27853056", "output": "YES\n11\n5440 10880 108801 217602 435204 870408 1740816 3481632 6963264 13926528 27853056 " }, { "input": "250000000 705032705", "output": "NO" }, { "input": "17 35", "output": "NO" }, { "input": "1 3", "output": "NO" }, { "input": "2 11", "output": "NO" } ]
1,632,367,972
2,147,483,647
PyPy 3
WRONG_ANSWER
TESTS
0
77
20,172,800
[a, b] = map(int, input().split()) found = False def finish(numbers): print("YES") print(' '.join(map(str, numbers))) return True def try_again(numbers): n = numbers[-1] if n == b: return finish(numbers) elif n < b: return try_op1(numbers) or try_op2(numbers) return False def try_op1(numbers): n = 2*numbers[-1] if n <= b: return try_again(numbers + [n]) return False def try_op2(numbers): n = 10*numbers[-1]+1 if n <= b: return try_again(numbers + [n]) return False if not try_again([a]): print("NO")
Title: Transformation: from A to B Time Limit: None seconds Memory Limit: None megabytes Problem Description: Vasily has a number *a*, which he wants to turn into a number *b*. For this purpose, he can do two types of operations: - multiply the current number by 2 (that is, replace the number *x* by 2·*x*); - append the digit 1 to the right of current number (that is, replace the number *x* by 10·*x*<=+<=1). You need to help Vasily to transform the number *a* into the number *b* using only the operations described above, or find that it is impossible. Note that in this task you are not required to minimize the number of operations. It suffices to find any way to transform *a* into *b*. Input Specification: The first line contains two positive integers *a* and *b* (1<=≤<=*a*<=&lt;<=*b*<=≤<=109) — the number which Vasily has and the number he wants to have. Output Specification: If there is no way to get *b* from *a*, print "NO" (without quotes). Otherwise print three lines. On the first line print "YES" (without quotes). The second line should contain single integer *k* — the length of the transformation sequence. On the third line print the sequence of transformations *x*1,<=*x*2,<=...,<=*x**k*, where: - *x*1 should be equal to *a*, - *x**k* should be equal to *b*, - *x**i* should be obtained from *x**i*<=-<=1 using any of two described operations (1<=&lt;<=*i*<=≤<=*k*). If there are multiple answers, print any of them. Demo Input: ['2 162\n', '4 42\n', '100 40021\n'] Demo Output: ['YES\n5\n2 4 8 81 162 \n', 'NO\n', 'YES\n5\n100 200 2001 4002 40021 \n'] Note: none
```python [a, b] = map(int, input().split()) found = False def finish(numbers): print("YES") print(' '.join(map(str, numbers))) return True def try_again(numbers): n = numbers[-1] if n == b: return finish(numbers) elif n < b: return try_op1(numbers) or try_op2(numbers) return False def try_op1(numbers): n = 2*numbers[-1] if n <= b: return try_again(numbers + [n]) return False def try_op2(numbers): n = 10*numbers[-1]+1 if n <= b: return try_again(numbers + [n]) return False if not try_again([a]): print("NO") ```
0
88
B
Keyboard
PROGRAMMING
1,500
[ "implementation" ]
B. Keyboard
1
256
Vasya learns to type. He has an unusual keyboard at his disposal: it is rectangular and it has *n* rows of keys containing *m* keys in each row. Besides, the keys are of two types. Some of the keys have lowercase Latin letters on them and some of the keys work like the "Shift" key on standard keyboards, that is, they make lowercase letters uppercase. Vasya can press one or two keys with one hand. However, he can only press two keys if the Euclidean distance between the centers of the keys does not exceed *x*. The keys are considered as squares with a side equal to 1. There are no empty spaces between neighbouring keys. Vasya is a very lazy boy, that's why he tries to type with one hand as he eats chips with his other one. However, it is possible that some symbol can't be typed with one hand only, because the distance between it and the closest "Shift" key is strictly larger than *x*. In this case he will have to use his other hand. Having typed the symbol, Vasya returns other hand back to the chips. You are given Vasya's keyboard and the text. Count the minimum number of times Vasya will have to use the other hand.
The first line contains three integers *n*, *m*, *x* (1<=≤<=*n*,<=*m*<=≤<=30,<=1<=≤<=*x*<=≤<=50). Next *n* lines contain descriptions of all the keyboard keys. Each line contains the descriptions of exactly *m* keys, without spaces. The letter keys are marked with the corresponding lowercase letters. The "Shift" keys are marked with the "S" symbol. Then follow the length of the text *q* (1<=≤<=*q*<=≤<=5·105). The last line contains the text *T*, which consists of *q* symbols, which are uppercase and lowercase Latin letters.
If Vasya can type the text, then print the minimum number of times he will have to use his other hand. Otherwise, print "-1" (without the quotes).
[ "2 2 1\nab\ncd\n1\nA\n", "2 2 1\nab\ncd\n1\ne\n", "2 2 1\nab\ncS\n5\nabcBA\n", "3 9 4\nqwertyuio\nasdfghjkl\nSzxcvbnmS\n35\nTheQuIcKbRoWnFOXjummsovertHeLazYDOG\n" ]
[ "-1\n", "-1\n", "1\n", "2\n" ]
In the first sample the symbol "A" is impossible to print as there's no "Shift" key on the keyboard. In the second sample the symbol "e" is impossible to print as there's no such key on the keyboard. In the fourth sample the symbols "T", "G" are impossible to print with one hand. The other letters that are on the keyboard can be printed. Those symbols come up in the text twice, thus, the answer is 2.
1,000
[ { "input": "2 2 1\nab\ncd\n1\nA", "output": "-1" }, { "input": "2 2 1\nab\ncd\n1\ne", "output": "-1" }, { "input": "2 2 1\nab\ncS\n5\nabcBA", "output": "1" }, { "input": "3 9 4\nqwertyuio\nasdfghjkl\nSzxcvbnmS\n35\nTheQuIcKbRoWnFOXjummsovertHeLazYDOG", "output": "2" }, { "input": "10 9 3\noboxlgpey\nyxcuwkkmp\njuqeflhwq\nsfnxqtjqS\nkkudcnyjl\nhgjlcrkjq\njnofqksxn\nqbhsnuguv\nlvahnifao\nebwnnlrwe\n35\nCodeforcesBetaRoundproblemAtestfive", "output": "4" }, { "input": "2 7 4\niuqtieo\nysxcgmS\n2\nsQ", "output": "1" }, { "input": "1 2 4\nbS\n8\nbBbbbBbb", "output": "0" }, { "input": "7 8 5\nfqiubjpm\nqbshcsyk\ncjbxpbef\nptwpmapx\nryazscbm\nqnvsgzrf\nhtardzkz\n9\nuxrmwkayy", "output": "0" }, { "input": "8 6 4\nefvmov\nkeofnw\npwajpe\nknptky\nSibruu\nrgdukk\nbsxosd\nhovgSe\n10\nECreruXmsC", "output": "-1" }, { "input": "10 3 2\nukk\neqt\nfex\nqSh\ntvz\nfjn\niol\nehd\nnte\ngyx\n5\ncgQxI", "output": "-1" }, { "input": "10 10 19\nowqjcaSpqn\nvgrhboqahn\nbzziocjmbu\npurqsmiSop\nxcsifctjhy\nycyytwoamk\nrnjfxsxowl\nnkgcywcdff\nbazljrisqv\nkcakigSekq\n100\nzewpATtssQVicNrlRrcoifTutTAfFMUEfDFKoNyQbSrSYxTGMadNkRpmJvoEqUsqPYgAdQreaUrwDKMNFWiwdRRCcJBPorfMVMoK", "output": "0" }, { "input": "10 10 26\nwxmssptheb\nzpxbxsyxsy\nqbjkpaywqp\nfwhnuzjcgq\nycgaanzedz\njrycrbzqfs\ngswwakybus\nfhtxhljedz\noSepmyjosv\ndwviycevdn\n100\nyapwUfnyPzgZyFvAHGKWVbXQHkuhJDoUTvCAtdMMCQmKchxKkilUTECOqYJFUSHPqKiRKhDXZgHxwApDWlShdwakmVCgaeKCLOMX", "output": "0" }, { "input": "10 10 3\nrvouufmnqu\nbyukrnmnhr\nzjggwxgvkz\ntcagkSitiw\nhryajgtpwc\njragfhqoks\nkgroxxkuvp\nbpgrkqiyns\njbuhjjkziw\nomjmbaggsw\n100\nCpRzrPqPngYvrVJFCWRPMRwrpXcbtiwfoFcAkRaNjzpMMKOQAzBxSrxGbIHaYgmSqhhxhZTmhFttKnhFzRfKxYXshUZRvtKJIzZq", "output": "12" }, { "input": "10 10 2\nfriuxvShvg\nerslojqtgu\nzeqsmdewry\nwvhbeeyeSu\ngkofbjaavr\ntwkcdxugps\nnzlylSmafu\nstamkpxnzt\nuwxwximkrm\nmzxyboazbl\n100\nmRIfAtrLKmztpVkAmojDCiIgseBwlUilBIixDQhqNhNAqVLLIobuCIretLdSvixNNdCiouFMXtwHZFlObCeaygmIiFBfaCirbmCa", "output": "19" }, { "input": "10 10 2\nbddahSqkmk\npxbocxayjs\nottvdazstk\nlaxuidqlqb\nkfjwdpdfat\nxlipuubkgv\niqyomzfktm\niwbgidmwyu\nrngqkeupsf\nbqndtekryw\n100\nMNQgWFLhHycqwjSsbTkbgMYAIHFYARRmOsinYMFjOxxnLjiKfeiBbMpoeTdzUMORPaAxRNfvdAPFaKkPdxdAjjJgGCxkDzmSasqq", "output": "37" }, { "input": "10 10 2\nnxcwdrsmrv\nSyjahsosvp\nvkrqbxhgbv\nwkxywavtnn\nepkyoviqbi\nsfmpvhuwwq\nnlsostrotx\ntcdguorhny\nimixrqzSdu\nxzhdhdwibt\n100\nUzzaWiRFYbAqxIDMrRBBDoGQhSzSqSLEddAiJsZcxbemdeuddamNYdWOvzlYSCuHIRpnuxdNxAsnZMiLXBYwnrMcrbNeLrUYhZOB", "output": "17" }, { "input": "10 10 23\nhtyvouoiqi\nvySvsfqadv\nxvqyqjyutq\npjcrrphzbk\nhlqfyoqfmo\nezcSwleoew\nxkwqrajxyg\nngSiftgoso\njyndgicccr\nlgjvokydhp\n100\nJzVVfotldIRcyjhTNRcFlTxFeZKRwavZxYcvdDOQyUvTmryFRuRBcRvmscegtspkPuchqlFEKbrfpTOSlSFOARsbbvSenMwNmaRj", "output": "0" }, { "input": "10 10 7\nifcwalsdbj\njpykymrbei\nrylzgkyefh\noilvvexpjp\niptgodpfim\ndSrqejaixu\npksxlsniwa\nmoSenxtfbc\noqssptcenz\nqdhmouvyas\n100\nqtMDVUXJpSEFgPsLKyRJVRbfVoYaCKJDnQDLFVngVjSPzzVyMnMyuyahMRiBJuNhKtgpVqvukUolLvYEmidvXotgQUJukYwIweUW", "output": "0" }, { "input": "10 10 1\nmdxafehbkr\nyuhenybjps\ntvfwmiwcoh\njmzrepzjvx\nnqyorkSnuk\ntSmztmwidv\ncmmajnlqrw\nfiqewpdwax\nuesmkdcplt\nlgkomdcqbo\n100\nmcEQmAvFqKYMXLHQUDeIulkmAMRkIUtbKihTFJwJYQfcAelNrZWSAwHunwZTrdHaRWokgCyLqbubOpEHuZiDVoFHjvkMSoBPyGOI", "output": "39" }, { "input": "10 10 2\nnhfafdwqhh\neyvitpcthk\nrpiotuoqzh\nnxxnhuaxee\nyevrtirzwf\nkbtSsamyel\nfeenjvxsmo\nkqpenxjmde\nlqsamthlwp\njdyyqsbtbk\n100\nUHucxPWDaKonVpXEctuqYUAQnrFEZaTYxhoacNbHIMevlbDejXjitEzyVrTfcfBHWRMdJvaTkbkqccyHjtzpTbKmRAXwlXCtFKNX", "output": "29" }, { "input": "10 10 1\nsufnxxpdnx\nvttibpllhv\nlvbrjmfdjx\ngmtexvrnfh\nygsqrsSwxd\nkxbbjxgbzs\nedutwocmzd\nfebjgknyai\nvcvquagvrs\ndrdoarhgoc\n100\nZoZJXhUWyaLgBTpgbznABKHuyFcKzJmGaMhoKkKfyOGacLwBspaKtAEdwMZJFYiZUFNDxdDIDgKSCRvsbGUOXRqalbpuEqkduYpW", "output": "44" }, { "input": "10 10 2\ncstcrltzsl\nblotmquzvj\nuiitiytlgx\nwumpfdaprd\ntfxohqpztn\nvfrpsccddo\nneegusrkxw\niijfjozqjq\nioegbvuhew\npjjpqdxvqu\n100\nkPCBONfZLkeXzWVuSgvinPENazcnRoBcUHXwRzPyvNIiDlDSeKOYmiUmjooXuzTCtIRxKDAYeTLgjsenxHoymVazMALUADQpjVjV", "output": "-1" }, { "input": "10 10 1\nqztnjglyrc\nnukswgzajl\nqnpbdwjvbb\nliiakzcrlz\nnolwfzzvxd\nmqvhiySttx\nqwuizSjuto\nqbgwiwjukx\nkomyvblgkc\ntkzlxzgsru\n100\nYUzTZDzLFkMUhjQWbwljJCRyZGFzgJcozvROiwPktRGxkMKiPyiTvhDrtusPYhMgVAOFIjAvlpzcrUvrMrMbhkpUiyAytKfYOGTF", "output": "37" }, { "input": "10 10 1\nmgziiihbkq\niobjknuogh\nvntwahSopu\nsjsxjpaqvm\nwqgrodizst\nselzugktoi\nvbhfzvgjfn\nliqlfdcjhf\nbpbtpmimxb\npksfiydpfw\n100\nwAVZXEhKTuajdCauVTIwgnfbxWuUSmtXkjHZtNVcfTsiSAPLdpdEFdTJLZRjptUcRhAmrNjKMXmuDGatAQoaIpbddnzRGHsJrhoq", "output": "39" }, { "input": "10 10 2\nshbqxycvfm\notydudkttw\nqhatsxsngz\nixvyujtyjc\nsbvqhnjbak\neggcguuuka\nxcydfgjzeb\nytpdkcdrsq\nefqlpywggu\nfcnfrhnouo\n100\nHPqtuVckdUOhsnuhnbpekWvWKUnAEaOCihpeEvmaOKOPcIZiMixGJGEuXAaOxuUNyrIesmldLEqGnvyDKPDvFkCbRebCORHmUgeV", "output": "-1" }, { "input": "1 1 50\nS\n29\nargjhoaiogjiSjqfhjksdvjkSvcvn", "output": "-1" }, { "input": "1 1 50\nS\n1\nS", "output": "-1" }, { "input": "1 1 50\na\n29\nargjhoaiogjiSjqfhjksdvjkSvcvn", "output": "-1" }, { "input": "1 1 50\nz\n29\nargjhoaiogjiSjqfhjksdvjkSvcvn", "output": "-1" }, { "input": "2 1 2\nS\nc\n4\nCSSA", "output": "-1" } ]
1,603,365,039
1,239
PyPy 3
OK
TESTS
65
311
4,096,000
import sys from array import array # noqa: F401 from math import hypot from collections import defaultdict def input(): return sys.stdin.buffer.readline().decode('utf-8') n, m, x = map(int, input().split()) keyboard = [input().rstrip() for _ in range(n)] keys = set() inf, eps = 10**9, 1e-9 dist = defaultdict(lambda: inf) shift = [] for i in range(n): for j in range(m): if keyboard[i][j] == 'S': shift.append((i, j)) for i in range(n): for j in range(m): if keyboard[i][j] == 'S': continue keys.add(keyboard[i][j]) for ti, tj in shift: dist[keyboard[i][j].upper()] = min(dist[keyboard[i][j].upper()], hypot(i - ti, j - tj)) q = int(input()) ans = 0 for c in input().rstrip(): if c.lower() not in keys: print(-1) exit() if 65 <= ord(c) <= 90: if not shift: print(-1) exit() if dist[c] - eps > x: ans += 1 print(ans)
Title: Keyboard Time Limit: 1 seconds Memory Limit: 256 megabytes Problem Description: Vasya learns to type. He has an unusual keyboard at his disposal: it is rectangular and it has *n* rows of keys containing *m* keys in each row. Besides, the keys are of two types. Some of the keys have lowercase Latin letters on them and some of the keys work like the "Shift" key on standard keyboards, that is, they make lowercase letters uppercase. Vasya can press one or two keys with one hand. However, he can only press two keys if the Euclidean distance between the centers of the keys does not exceed *x*. The keys are considered as squares with a side equal to 1. There are no empty spaces between neighbouring keys. Vasya is a very lazy boy, that's why he tries to type with one hand as he eats chips with his other one. However, it is possible that some symbol can't be typed with one hand only, because the distance between it and the closest "Shift" key is strictly larger than *x*. In this case he will have to use his other hand. Having typed the symbol, Vasya returns other hand back to the chips. You are given Vasya's keyboard and the text. Count the minimum number of times Vasya will have to use the other hand. Input Specification: The first line contains three integers *n*, *m*, *x* (1<=≤<=*n*,<=*m*<=≤<=30,<=1<=≤<=*x*<=≤<=50). Next *n* lines contain descriptions of all the keyboard keys. Each line contains the descriptions of exactly *m* keys, without spaces. The letter keys are marked with the corresponding lowercase letters. The "Shift" keys are marked with the "S" symbol. Then follow the length of the text *q* (1<=≤<=*q*<=≤<=5·105). The last line contains the text *T*, which consists of *q* symbols, which are uppercase and lowercase Latin letters. Output Specification: If Vasya can type the text, then print the minimum number of times he will have to use his other hand. Otherwise, print "-1" (without the quotes). Demo Input: ['2 2 1\nab\ncd\n1\nA\n', '2 2 1\nab\ncd\n1\ne\n', '2 2 1\nab\ncS\n5\nabcBA\n', '3 9 4\nqwertyuio\nasdfghjkl\nSzxcvbnmS\n35\nTheQuIcKbRoWnFOXjummsovertHeLazYDOG\n'] Demo Output: ['-1\n', '-1\n', '1\n', '2\n'] Note: In the first sample the symbol "A" is impossible to print as there's no "Shift" key on the keyboard. In the second sample the symbol "e" is impossible to print as there's no such key on the keyboard. In the fourth sample the symbols "T", "G" are impossible to print with one hand. The other letters that are on the keyboard can be printed. Those symbols come up in the text twice, thus, the answer is 2.
```python import sys from array import array # noqa: F401 from math import hypot from collections import defaultdict def input(): return sys.stdin.buffer.readline().decode('utf-8') n, m, x = map(int, input().split()) keyboard = [input().rstrip() for _ in range(n)] keys = set() inf, eps = 10**9, 1e-9 dist = defaultdict(lambda: inf) shift = [] for i in range(n): for j in range(m): if keyboard[i][j] == 'S': shift.append((i, j)) for i in range(n): for j in range(m): if keyboard[i][j] == 'S': continue keys.add(keyboard[i][j]) for ti, tj in shift: dist[keyboard[i][j].upper()] = min(dist[keyboard[i][j].upper()], hypot(i - ti, j - tj)) q = int(input()) ans = 0 for c in input().rstrip(): if c.lower() not in keys: print(-1) exit() if 65 <= ord(c) <= 90: if not shift: print(-1) exit() if dist[c] - eps > x: ans += 1 print(ans) ```
3.836871
807
A
Is it rated?
PROGRAMMING
900
[ "implementation", "sortings" ]
null
null
Is it rated? Here it is. The Ultimate Question of Competitive Programming, Codeforces, and Everything. And you are here to answer it. Another Codeforces round has been conducted. No two participants have the same number of points. For each participant, from the top to the bottom of the standings, their rating before and after the round is known. It's known that if at least one participant's rating has changed, then the round was rated for sure. It's also known that if the round was rated and a participant with lower rating took a better place in the standings than a participant with higher rating, then at least one round participant's rating has changed. In this problem, you should not make any other assumptions about the rating system. Determine if the current round is rated, unrated, or it's impossible to determine whether it is rated of not.
The first line contains a single integer *n* (2<=≤<=*n*<=≤<=1000) — the number of round participants. Each of the next *n* lines contains two integers *a**i* and *b**i* (1<=≤<=*a**i*,<=*b**i*<=≤<=4126) — the rating of the *i*-th participant before and after the round, respectively. The participants are listed in order from the top to the bottom of the standings.
If the round is rated for sure, print "rated". If the round is unrated for sure, print "unrated". If it's impossible to determine whether the round is rated or not, print "maybe".
[ "6\n3060 3060\n2194 2194\n2876 2903\n2624 2624\n3007 2991\n2884 2884\n", "4\n1500 1500\n1300 1300\n1200 1200\n1400 1400\n", "5\n3123 3123\n2777 2777\n2246 2246\n2246 2246\n1699 1699\n" ]
[ "rated\n", "unrated\n", "maybe\n" ]
In the first example, the ratings of the participants in the third and fifth places have changed, therefore, the round was rated. In the second example, no one's rating has changed, but the participant in the second place has lower rating than the participant in the fourth place. Therefore, if the round was rated, someone's rating would've changed for sure. In the third example, no one's rating has changed, and the participants took places in non-increasing order of their rating. Therefore, it's impossible to determine whether the round is rated or not.
500
[ { "input": "6\n3060 3060\n2194 2194\n2876 2903\n2624 2624\n3007 2991\n2884 2884", "output": "rated" }, { "input": "4\n1500 1500\n1300 1300\n1200 1200\n1400 1400", "output": "unrated" }, { "input": "5\n3123 3123\n2777 2777\n2246 2246\n2246 2246\n1699 1699", "output": "maybe" }, { "input": "2\n1 1\n1 1", "output": "maybe" }, { "input": "2\n4126 4126\n4126 4126", "output": "maybe" }, { "input": "10\n446 446\n1331 1331\n3594 3594\n1346 1902\n91 91\n3590 3590\n2437 2437\n4007 3871\n2797 699\n1423 1423", "output": "rated" }, { "input": "10\n4078 4078\n2876 2876\n1061 1061\n3721 3721\n143 143\n2992 2992\n3279 3279\n3389 3389\n1702 1702\n1110 1110", "output": "unrated" }, { "input": "10\n4078 4078\n3721 3721\n3389 3389\n3279 3279\n2992 2992\n2876 2876\n1702 1702\n1110 1110\n1061 1061\n143 143", "output": "maybe" }, { "input": "2\n3936 3936\n2967 2967", "output": "maybe" }, { "input": "2\n1 1\n2 2", "output": "unrated" }, { "input": "2\n2 2\n1 1", "output": "maybe" }, { "input": "2\n2 1\n1 2", "output": "rated" }, { "input": "2\n2967 2967\n3936 3936", "output": "unrated" }, { "input": "3\n1200 1200\n1200 1200\n1300 1300", "output": "unrated" }, { "input": "3\n3 3\n2 2\n1 1", "output": "maybe" }, { "input": "3\n1 1\n1 1\n2 2", "output": "unrated" }, { "input": "2\n3 2\n3 2", "output": "rated" }, { "input": "3\n5 5\n4 4\n3 4", "output": "rated" }, { "input": "3\n200 200\n200 200\n300 300", "output": "unrated" }, { "input": "3\n1 1\n2 2\n3 3", "output": "unrated" }, { "input": "5\n3123 3123\n2777 2777\n2246 2246\n2245 2245\n1699 1699", "output": "maybe" }, { "input": "2\n10 10\n8 8", "output": "maybe" }, { "input": "3\n1500 1500\n1500 1500\n1600 1600", "output": "unrated" }, { "input": "3\n1500 1500\n1500 1500\n1700 1700", "output": "unrated" }, { "input": "4\n100 100\n100 100\n70 70\n80 80", "output": "unrated" }, { "input": "2\n1 2\n2 1", "output": "rated" }, { "input": "3\n5 5\n4 3\n3 3", "output": "rated" }, { "input": "3\n1600 1650\n1500 1550\n1400 1450", "output": "rated" }, { "input": "4\n2000 2000\n1500 1500\n1500 1500\n1700 1700", "output": "unrated" }, { "input": "4\n1500 1500\n1400 1400\n1400 1400\n1700 1700", "output": "unrated" }, { "input": "2\n1600 1600\n1400 1400", "output": "maybe" }, { "input": "2\n3 1\n9 8", "output": "rated" }, { "input": "2\n2 1\n1 1", "output": "rated" }, { "input": "4\n4123 4123\n4123 4123\n2670 2670\n3670 3670", "output": "unrated" }, { "input": "2\n2 2\n3 3", "output": "unrated" }, { "input": "2\n10 11\n5 4", "output": "rated" }, { "input": "2\n15 14\n13 12", "output": "rated" }, { "input": "2\n2 1\n2 2", "output": "rated" }, { "input": "3\n2670 2670\n3670 3670\n4106 4106", "output": "unrated" }, { "input": "3\n4 5\n3 3\n2 2", "output": "rated" }, { "input": "2\n10 9\n10 10", "output": "rated" }, { "input": "3\n1011 1011\n1011 999\n2200 2100", "output": "rated" }, { "input": "2\n3 3\n5 5", "output": "unrated" }, { "input": "2\n1500 1500\n3000 2000", "output": "rated" }, { "input": "2\n5 6\n5 5", "output": "rated" }, { "input": "3\n2000 2000\n1500 1501\n500 500", "output": "rated" }, { "input": "2\n2 3\n2 2", "output": "rated" }, { "input": "2\n3 3\n2 2", "output": "maybe" }, { "input": "2\n1 2\n1 1", "output": "rated" }, { "input": "4\n3123 3123\n2777 2777\n2246 2246\n1699 1699", "output": "maybe" }, { "input": "2\n15 14\n14 13", "output": "rated" }, { "input": "4\n3000 3000\n2900 2900\n3000 3000\n2900 2900", "output": "unrated" }, { "input": "6\n30 3060\n24 2194\n26 2903\n24 2624\n37 2991\n24 2884", "output": "rated" }, { "input": "2\n100 99\n100 100", "output": "rated" }, { "input": "4\n2 2\n1 1\n1 1\n2 2", "output": "unrated" }, { "input": "3\n100 101\n100 100\n100 100", "output": "rated" }, { "input": "4\n1000 1001\n900 900\n950 950\n890 890", "output": "rated" }, { "input": "2\n2 3\n1 1", "output": "rated" }, { "input": "2\n2 2\n1 1", "output": "maybe" }, { "input": "2\n3 2\n2 2", "output": "rated" }, { "input": "2\n3 2\n3 3", "output": "rated" }, { "input": "2\n1 1\n2 2", "output": "unrated" }, { "input": "3\n3 2\n3 3\n3 3", "output": "rated" }, { "input": "4\n1500 1501\n1300 1300\n1200 1200\n1400 1400", "output": "rated" }, { "input": "3\n1000 1000\n500 500\n400 300", "output": "rated" }, { "input": "5\n3123 3123\n2777 2777\n2246 2246\n2246 2246\n3000 3000", "output": "unrated" }, { "input": "2\n1 1\n2 3", "output": "rated" }, { "input": "2\n6 2\n6 2", "output": "rated" }, { "input": "5\n3123 3123\n1699 1699\n2777 2777\n2246 2246\n2246 2246", "output": "unrated" }, { "input": "2\n1500 1500\n1600 1600", "output": "unrated" }, { "input": "5\n3123 3123\n2777 2777\n2246 2246\n2241 2241\n1699 1699", "output": "maybe" }, { "input": "2\n20 30\n10 5", "output": "rated" }, { "input": "3\n1 1\n2 2\n1 1", "output": "unrated" }, { "input": "2\n1 2\n3 3", "output": "rated" }, { "input": "5\n5 5\n4 4\n3 3\n2 2\n1 1", "output": "maybe" }, { "input": "2\n2 2\n2 1", "output": "rated" }, { "input": "2\n100 100\n90 89", "output": "rated" }, { "input": "2\n1000 900\n2000 2000", "output": "rated" }, { "input": "2\n50 10\n10 50", "output": "rated" }, { "input": "2\n200 200\n100 100", "output": "maybe" }, { "input": "3\n2 2\n2 2\n3 3", "output": "unrated" }, { "input": "3\n1000 1000\n300 300\n100 100", "output": "maybe" }, { "input": "4\n2 2\n2 2\n3 3\n4 4", "output": "unrated" }, { "input": "2\n5 3\n6 3", "output": "rated" }, { "input": "2\n1200 1100\n1200 1000", "output": "rated" }, { "input": "2\n5 5\n4 4", "output": "maybe" }, { "input": "2\n5 5\n3 3", "output": "maybe" }, { "input": "5\n1500 1500\n1300 1300\n1200 1200\n1400 1400\n1100 1100", "output": "unrated" }, { "input": "5\n10 10\n9 9\n8 8\n7 7\n6 6", "output": "maybe" }, { "input": "3\n1000 1000\n300 300\n10 10", "output": "maybe" }, { "input": "5\n6 6\n5 5\n4 4\n3 3\n2 2", "output": "maybe" }, { "input": "2\n3 3\n1 1", "output": "maybe" }, { "input": "4\n2 2\n2 2\n2 2\n3 3", "output": "unrated" }, { "input": "2\n1000 1000\n700 700", "output": "maybe" }, { "input": "2\n4 3\n5 3", "output": "rated" }, { "input": "2\n1000 1000\n1100 1100", "output": "unrated" }, { "input": "4\n5 5\n4 4\n3 3\n2 2", "output": "maybe" }, { "input": "3\n1 1\n2 3\n2 2", "output": "rated" }, { "input": "2\n1 2\n1 3", "output": "rated" }, { "input": "2\n3 3\n1 2", "output": "rated" }, { "input": "4\n1501 1500\n1300 1300\n1200 1200\n1400 1400", "output": "rated" }, { "input": "5\n1 1\n2 2\n3 3\n4 4\n5 5", "output": "unrated" }, { "input": "2\n10 10\n1 2", "output": "rated" }, { "input": "6\n3123 3123\n2777 2777\n2246 2246\n2246 2246\n1699 1699\n1900 1900", "output": "unrated" }, { "input": "6\n3123 3123\n2777 2777\n3000 3000\n2246 2246\n2246 2246\n1699 1699", "output": "unrated" }, { "input": "2\n100 100\n110 110", "output": "unrated" }, { "input": "3\n3 3\n3 3\n4 4", "output": "unrated" }, { "input": "3\n3 3\n3 2\n4 4", "output": "rated" }, { "input": "3\n5 2\n4 4\n3 3", "output": "rated" }, { "input": "4\n4 4\n3 3\n2 2\n1 1", "output": "maybe" }, { "input": "2\n1 1\n3 2", "output": "rated" }, { "input": "5\n3123 3123\n2777 2777\n2246 2246\n2246 2246\n2699 2699", "output": "unrated" }, { "input": "3\n3 3\n3 3\n3 4", "output": "rated" }, { "input": "3\n1 2\n2 2\n3 3", "output": "rated" }, { "input": "3\n1 2\n1 2\n1 2", "output": "rated" }, { "input": "2\n2 1\n2 1", "output": "rated" }, { "input": "2\n1 2\n3 4", "output": "rated" }, { "input": "2\n3 2\n2 3", "output": "rated" }, { "input": "3\n1500 1500\n1600 1600\n1600 1600", "output": "unrated" }, { "input": "3\n1 1\n3 3\n4 4", "output": "unrated" }, { "input": "3\n1 1\n2 2\n2 2", "output": "unrated" }, { "input": "2\n10 12\n8 8", "output": "rated" }, { "input": "5\n1200 1200\n1500 1500\n1500 1500\n1500 1500\n1500 1500", "output": "unrated" }, { "input": "2\n1 2\n2 2", "output": "rated" }, { "input": "3\n1500 1400\n1200 1200\n1100 1100", "output": "rated" }, { "input": "2\n10 12\n10 10", "output": "rated" }, { "input": "3\n1500 1500\n1400 1400\n1300 1300", "output": "maybe" }, { "input": "3\n3 3\n4 4\n5 5", "output": "unrated" }, { "input": "3\n2 6\n3 5\n4 4", "output": "rated" }, { "input": "2\n5 6\n4 6", "output": "rated" }, { "input": "4\n10 10\n10 10\n7 7\n8 8", "output": "unrated" }, { "input": "2\n4 4\n3 3", "output": "maybe" } ]
1,591,629,718
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
0
93
307,200
if str is bytes: from itertools import izip as zip def is_sorted(l): return all(a >= b for a, b in zip(l, l[1:])) n = int(input()) before = [] i = -1 for _ in range(n): tmp = list(map(int, input().split())) if tmp[0] != tmp[1]: print("rated") i = 1 else: before.append(tmp[0]) ist = is_sorted(before) if i == -1 and ist: print("maybe") elif i == -1 and not ist: print("unrated")
Title: Is it rated? Time Limit: None seconds Memory Limit: None megabytes Problem Description: Is it rated? Here it is. The Ultimate Question of Competitive Programming, Codeforces, and Everything. And you are here to answer it. Another Codeforces round has been conducted. No two participants have the same number of points. For each participant, from the top to the bottom of the standings, their rating before and after the round is known. It's known that if at least one participant's rating has changed, then the round was rated for sure. It's also known that if the round was rated and a participant with lower rating took a better place in the standings than a participant with higher rating, then at least one round participant's rating has changed. In this problem, you should not make any other assumptions about the rating system. Determine if the current round is rated, unrated, or it's impossible to determine whether it is rated of not. Input Specification: The first line contains a single integer *n* (2<=≤<=*n*<=≤<=1000) — the number of round participants. Each of the next *n* lines contains two integers *a**i* and *b**i* (1<=≤<=*a**i*,<=*b**i*<=≤<=4126) — the rating of the *i*-th participant before and after the round, respectively. The participants are listed in order from the top to the bottom of the standings. Output Specification: If the round is rated for sure, print "rated". If the round is unrated for sure, print "unrated". If it's impossible to determine whether the round is rated or not, print "maybe". Demo Input: ['6\n3060 3060\n2194 2194\n2876 2903\n2624 2624\n3007 2991\n2884 2884\n', '4\n1500 1500\n1300 1300\n1200 1200\n1400 1400\n', '5\n3123 3123\n2777 2777\n2246 2246\n2246 2246\n1699 1699\n'] Demo Output: ['rated\n', 'unrated\n', 'maybe\n'] Note: In the first example, the ratings of the participants in the third and fifth places have changed, therefore, the round was rated. In the second example, no one's rating has changed, but the participant in the second place has lower rating than the participant in the fourth place. Therefore, if the round was rated, someone's rating would've changed for sure. In the third example, no one's rating has changed, and the participants took places in non-increasing order of their rating. Therefore, it's impossible to determine whether the round is rated or not.
```python if str is bytes: from itertools import izip as zip def is_sorted(l): return all(a >= b for a, b in zip(l, l[1:])) n = int(input()) before = [] i = -1 for _ in range(n): tmp = list(map(int, input().split())) if tmp[0] != tmp[1]: print("rated") i = 1 else: before.append(tmp[0]) ist = is_sorted(before) if i == -1 and ist: print("maybe") elif i == -1 and not ist: print("unrated") ```
0
793
A
Oleg and shares
PROGRAMMING
900
[ "implementation", "math" ]
null
null
Oleg the bank client checks share prices every day. There are *n* share prices he is interested in. Today he observed that each second exactly one of these prices decreases by *k* rubles (note that each second exactly one price changes, but at different seconds different prices can change). Prices can become negative. Oleg found this process interesting, and he asked Igor the financial analyst, what is the minimum time needed for all *n* prices to become equal, or it is impossible at all? Igor is busy right now, so he asked you to help Oleg. Can you answer this question?
The first line contains two integers *n* and *k* (1<=≤<=*n*<=≤<=105,<=1<=≤<=*k*<=≤<=109) — the number of share prices, and the amount of rubles some price decreases each second. The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=109) — the initial prices.
Print the only line containing the minimum number of seconds needed for prices to become equal, of «-1» if it is impossible.
[ "3 3\n12 9 15\n", "2 2\n10 9\n", "4 1\n1 1000000000 1000000000 1000000000\n" ]
[ "3", "-1", "2999999997" ]
Consider the first example. Suppose the third price decreases in the first second and become equal 12 rubles, then the first price decreases and becomes equal 9 rubles, and in the third second the third price decreases again and becomes equal 9 rubles. In this case all prices become equal 9 rubles in 3 seconds. There could be other possibilities, but this minimizes the time needed for all prices to become equal. Thus the answer is 3. In the second example we can notice that parity of first and second price is different and never changes within described process. Thus prices never can become equal. In the third example following scenario can take place: firstly, the second price drops, then the third price, and then fourth price. It happens 999999999 times, and, since in one second only one price can drop, the whole process takes 999999999 * 3 = 2999999997 seconds. We can note that this is the minimum possible time.
500
[ { "input": "3 3\n12 9 15", "output": "3" }, { "input": "2 2\n10 9", "output": "-1" }, { "input": "4 1\n1 1000000000 1000000000 1000000000", "output": "2999999997" }, { "input": "1 11\n123", "output": "0" }, { "input": "20 6\n38 86 86 50 98 62 32 2 14 62 98 50 2 50 32 38 62 62 8 14", "output": "151" }, { "input": "20 5\n59 54 19 88 55 100 54 3 6 13 99 38 36 71 59 6 64 85 45 54", "output": "-1" }, { "input": "100 10\n340 70 440 330 130 120 340 210 440 110 410 120 180 40 50 230 70 110 310 360 480 70 230 120 230 310 470 60 210 60 210 480 290 250 450 440 150 40 500 230 280 250 30 50 310 50 230 360 420 260 330 80 50 160 70 470 140 180 380 190 250 30 220 410 80 310 280 50 20 430 440 180 310 190 190 330 90 190 320 390 170 460 230 30 80 500 470 370 80 500 400 120 220 150 70 120 70 320 260 260", "output": "2157" }, { "input": "100 18\n489 42 300 366 473 105 220 448 70 488 201 396 168 281 67 235 324 291 313 387 407 223 39 144 224 233 72 318 229 377 62 171 448 119 354 282 147 447 260 384 172 199 67 326 311 431 337 142 281 202 404 468 38 120 90 437 33 420 249 372 367 253 255 411 309 333 103 176 162 120 203 41 352 478 216 498 224 31 261 493 277 99 375 370 394 229 71 488 246 194 233 13 66 111 366 456 277 360 116 354", "output": "-1" }, { "input": "4 2\n1 2 3 4", "output": "-1" }, { "input": "3 4\n3 5 5", "output": "-1" }, { "input": "3 2\n88888884 88888886 88888888", "output": "3" }, { "input": "2 1\n1000000000 1000000000", "output": "0" }, { "input": "4 2\n1000000000 100000000 100000000 100000000", "output": "450000000" }, { "input": "2 2\n1000000000 1000000000", "output": "0" }, { "input": "3 3\n3 2 1", "output": "-1" }, { "input": "3 4\n3 5 3", "output": "-1" }, { "input": "3 2\n1 2 2", "output": "-1" }, { "input": "4 2\n2 3 3 2", "output": "-1" }, { "input": "3 2\n1 2 4", "output": "-1" }, { "input": "3 2\n3 4 4", "output": "-1" }, { "input": "3 3\n4 7 10", "output": "3" }, { "input": "4 3\n2 2 5 1", "output": "-1" }, { "input": "3 3\n1 3 5", "output": "-1" }, { "input": "2 5\n5 9", "output": "-1" }, { "input": "2 3\n5 7", "output": "-1" }, { "input": "3 137\n1000000000 1000000000 1000000000", "output": "0" }, { "input": "5 1000000000\n1000000000 1000000000 1000000000 1000000000 1000000000", "output": "0" }, { "input": "3 5\n1 2 5", "output": "-1" }, { "input": "3 3\n1000000000 1000000000 999999997", "output": "2" }, { "input": "2 4\n5 6", "output": "-1" }, { "input": "4 1\n1000000000 1000000000 1000000000 1000000000", "output": "0" }, { "input": "2 3\n5 8", "output": "1" }, { "input": "2 6\n8 16", "output": "-1" }, { "input": "5 3\n15 14 9 12 18", "output": "-1" }, { "input": "3 3\n1 2 3", "output": "-1" }, { "input": "3 3\n3 4 5", "output": "-1" }, { "input": "2 5\n8 17", "output": "-1" }, { "input": "2 1\n1 2", "output": "1" }, { "input": "1 1\n1000000000", "output": "0" }, { "input": "3 3\n5 3 4", "output": "-1" }, { "input": "3 6\n10 14 12", "output": "-1" }, { "input": "2 2\n3 5", "output": "1" }, { "input": "3 5\n1 3 4", "output": "-1" }, { "input": "4 3\n1 6 6 6", "output": "-1" }, { "input": "2 3\n1 8", "output": "-1" }, { "input": "3 5\n6 11 17", "output": "-1" }, { "input": "2 2\n1 4", "output": "-1" }, { "input": "2 4\n6 8", "output": "-1" }, { "input": "2 1\n2 3", "output": "1" }, { "input": "4 4\n1 5 8 14", "output": "-1" }, { "input": "3 3\n1 5 3", "output": "-1" }, { "input": "4 3\n1 2 2 5", "output": "-1" }, { "input": "3 2\n1 4 6", "output": "-1" }, { "input": "2 3\n6 9", "output": "1" }, { "input": "3 3\n2 3 4", "output": "-1" }, { "input": "3 2\n9 10 10", "output": "-1" }, { "input": "2 2\n9 12", "output": "-1" }, { "input": "2 2\n100000003 100000005", "output": "1" }, { "input": "2 3\n2 4", "output": "-1" }, { "input": "3 2\n2 3 5", "output": "-1" }, { "input": "3 3\n1 3 4", "output": "-1" }, { "input": "10 2\n2 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000", "output": "4499999991" }, { "input": "3 5\n2 4 5", "output": "-1" }, { "input": "2 3\n7 10", "output": "1" }, { "input": "3 10\n10 13 17", "output": "-1" }, { "input": "2 3\n1 6", "output": "-1" }, { "input": "1 7\n1000000000", "output": "0" }, { "input": "2 4\n3 7", "output": "1" }, { "input": "2 3\n2 5", "output": "1" }, { "input": "20 1\n1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000", "output": "0" }, { "input": "3 3\n7 8 8", "output": "-1" }, { "input": "4 10\n1 11 100 11", "output": "-1" } ]
1,492,968,008
2,108
Python 3
CHALLENGED
CHALLENGES
7
124
13,414,400
n, k = input().split() n = int(n) k = int(k) price = [int(s) for s in input().split()] minimum = min(s for s in price) res = sum([s - minimum for s in price]) if res % k == 0: print(int(res / k)) else: print(-1)
Title: Oleg and shares Time Limit: None seconds Memory Limit: None megabytes Problem Description: Oleg the bank client checks share prices every day. There are *n* share prices he is interested in. Today he observed that each second exactly one of these prices decreases by *k* rubles (note that each second exactly one price changes, but at different seconds different prices can change). Prices can become negative. Oleg found this process interesting, and he asked Igor the financial analyst, what is the minimum time needed for all *n* prices to become equal, or it is impossible at all? Igor is busy right now, so he asked you to help Oleg. Can you answer this question? Input Specification: The first line contains two integers *n* and *k* (1<=≤<=*n*<=≤<=105,<=1<=≤<=*k*<=≤<=109) — the number of share prices, and the amount of rubles some price decreases each second. The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=109) — the initial prices. Output Specification: Print the only line containing the minimum number of seconds needed for prices to become equal, of «-1» if it is impossible. Demo Input: ['3 3\n12 9 15\n', '2 2\n10 9\n', '4 1\n1 1000000000 1000000000 1000000000\n'] Demo Output: ['3', '-1', '2999999997'] Note: Consider the first example. Suppose the third price decreases in the first second and become equal 12 rubles, then the first price decreases and becomes equal 9 rubles, and in the third second the third price decreases again and becomes equal 9 rubles. In this case all prices become equal 9 rubles in 3 seconds. There could be other possibilities, but this minimizes the time needed for all prices to become equal. Thus the answer is 3. In the second example we can notice that parity of first and second price is different and never changes within described process. Thus prices never can become equal. In the third example following scenario can take place: firstly, the second price drops, then the third price, and then fourth price. It happens 999999999 times, and, since in one second only one price can drop, the whole process takes 999999999 * 3 = 2999999997 seconds. We can note that this is the minimum possible time.
```python n, k = input().split() n = int(n) k = int(k) price = [int(s) for s in input().split()] minimum = min(s for s in price) res = sum([s - minimum for s in price]) if res % k == 0: print(int(res / k)) else: print(-1) ```
-1
204
A
Little Elephant and Interval
PROGRAMMING
1,500
[ "binary search", "combinatorics", "dp" ]
null
null
The Little Elephant very much loves sums on intervals. This time he has a pair of integers *l* and *r* (*l*<=≤<=*r*). The Little Elephant has to find the number of such integers *x* (*l*<=≤<=*x*<=≤<=*r*), that the first digit of integer *x* equals the last one (in decimal notation). For example, such numbers as 101, 477474 or 9 will be included in the answer and 47, 253 or 1020 will not. Help him and count the number of described numbers *x* for a given pair *l* and *r*.
The single line contains a pair of integers *l* and *r* (1<=≤<=*l*<=≤<=*r*<=≤<=1018) — the boundaries of the interval. Please, do not use the %lld specifier to read or write 64-bit integers in С++. It is preferred to use cin, cout streams or the %I64d specifier.
On a single line print a single integer — the answer to the problem.
[ "2 47\n", "47 1024\n" ]
[ "12\n", "98\n" ]
In the first sample the answer includes integers 2, 3, 4, 5, 6, 7, 8, 9, 11, 22, 33, 44.
500
[ { "input": "2 47", "output": "12" }, { "input": "47 1024", "output": "98" }, { "input": "1 1000", "output": "108" }, { "input": "1 10000", "output": "1008" }, { "input": "47 8545", "output": "849" }, { "input": "1000 1000", "output": "0" }, { "input": "47547 4587554587754542", "output": "458755458770699" }, { "input": "1 1000000", "output": "100008" }, { "input": "47 74", "output": "2" }, { "input": "10001 10000002", "output": "999001" }, { "input": "10000 100000", "output": "9000" }, { "input": "458754 4588754", "output": "413001" }, { "input": "111 111", "output": "1" }, { "input": "110 147", "output": "4" }, { "input": "1 1000000000", "output": "100000008" }, { "input": "12 10000000000", "output": "999999998" }, { "input": "1000000000 1000000000", "output": "0" }, { "input": "1 1000000000000000000", "output": "100000000000000008" }, { "input": "11 111111111111111100", "output": "11111111111111109" }, { "input": "100000000000000000 1000000000000000000", "output": "90000000000000000" }, { "input": "45481484484 848469844684844", "output": "84842436320036" }, { "input": "975400104587000 48754000000000001", "output": "4777859989541300" }, { "input": "11220451511 51511665251233335", "output": "5151165403078183" }, { "input": "77 77", "output": "1" }, { "input": "99 102", "output": "2" }, { "input": "9997 87878000008", "output": "8787799002" }, { "input": "10000000001 111111111111100001", "output": "11111110111110001" }, { "input": "7777 88888", "output": "8112" }, { "input": "999999999 10000000000", "output": "900000001" }, { "input": "235 236", "output": "0" }, { "input": "1 1", "output": "1" }, { "input": "2 2", "output": "1" }, { "input": "1 2", "output": "2" }, { "input": "4 7", "output": "4" }, { "input": "7 10", "output": "3" }, { "input": "1 11", "output": "10" }, { "input": "1 10", "output": "9" }, { "input": "7 8", "output": "2" }, { "input": "88 990", "output": "91" }, { "input": "458985985498001244 985458425544874008", "output": "52647244004687276" }, { "input": "115998725487587451 245744899758754501", "output": "12974617427116705" }, { "input": "595754249475458004 615044544745124547", "output": "1929029526966655" }, { "input": "9754875457700 1000000000000000000", "output": "99999024512454230" }, { "input": "8758754570000 999999999999999999", "output": "99999124124543000" }, { "input": "111111111111111111 333333333444444445", "output": "22222222233333334" }, { "input": "822981258385599125 841978899930248528", "output": "1899764154464941" }, { "input": "779547115376367013 980561039207670775", "output": "20101392383130376" }, { "input": "335408916782916802 416495628489807285", "output": "8108671170689049" }, { "input": "252509053898415172 285803555062529649", "output": "3329450116411448" }, { "input": "919845424847912645 970651082117950285", "output": "5080565727003764" }, { "input": "522842183413115088 853628713003942530", "output": "33078652959082744" }, { "input": "84324827171274023 607953653548585226", "output": "52362882637731121" }, { "input": "1312148742261681 277460340506883334", "output": "27614819176462166" }, { "input": "645762257531682046 885295120956158518", "output": "23953286342447648" }, { "input": "819875140559301752 946247219812473271", "output": "12637207925317152" }, { "input": "4 19", "output": "7" }, { "input": "5 45", "output": "9" }, { "input": "9999999999999987 99999999999999711", "output": "8999999999999973" }, { "input": "2 3", "output": "2" }, { "input": "1827171 232817181719384635", "output": "23281718171755747" }, { "input": "999999999999999999 1000000000000000000", "output": "1" }, { "input": "73 678", "output": "61" } ]
1,593,063,954
2,147,483,647
PyPy 3
OK
TESTS
62
312
20,172,800
def f(x): if x < 10: return x if str(x)[0] > str(x)[-1]: return x // 10 + 8 else: return x // 10 + 9 l, r = map(int, input().split()) print(f(r) - f(l - 1))
Title: Little Elephant and Interval Time Limit: None seconds Memory Limit: None megabytes Problem Description: The Little Elephant very much loves sums on intervals. This time he has a pair of integers *l* and *r* (*l*<=≤<=*r*). The Little Elephant has to find the number of such integers *x* (*l*<=≤<=*x*<=≤<=*r*), that the first digit of integer *x* equals the last one (in decimal notation). For example, such numbers as 101, 477474 or 9 will be included in the answer and 47, 253 or 1020 will not. Help him and count the number of described numbers *x* for a given pair *l* and *r*. Input Specification: The single line contains a pair of integers *l* and *r* (1<=≤<=*l*<=≤<=*r*<=≤<=1018) — the boundaries of the interval. Please, do not use the %lld specifier to read or write 64-bit integers in С++. It is preferred to use cin, cout streams or the %I64d specifier. Output Specification: On a single line print a single integer — the answer to the problem. Demo Input: ['2 47\n', '47 1024\n'] Demo Output: ['12\n', '98\n'] Note: In the first sample the answer includes integers 2, 3, 4, 5, 6, 7, 8, 9, 11, 22, 33, 44.
```python def f(x): if x < 10: return x if str(x)[0] > str(x)[-1]: return x // 10 + 8 else: return x // 10 + 9 l, r = map(int, input().split()) print(f(r) - f(l - 1)) ```
3
770
A
New Password
PROGRAMMING
800
[ "*special", "implementation" ]
null
null
Innokentiy decides to change the password in the social net "Contact!", but he is too lazy to invent a new password by himself. That is why he needs your help. Innokentiy decides that new password should satisfy the following conditions: - the length of the password must be equal to *n*, - the password should consist only of lowercase Latin letters, - the number of distinct symbols in the password must be equal to *k*, - any two consecutive symbols in the password must be distinct. Your task is to help Innokentiy and to invent a new password which will satisfy all given conditions.
The first line contains two positive integers *n* and *k* (2<=≤<=*n*<=≤<=100, 2<=≤<=*k*<=≤<=*min*(*n*,<=26)) — the length of the password and the number of distinct symbols in it. Pay attention that a desired new password always exists.
Print any password which satisfies all conditions given by Innokentiy.
[ "4 3\n", "6 6\n", "5 2\n" ]
[ "java\n", "python\n", "phphp\n" ]
In the first test there is one of the appropriate new passwords — java, because its length is equal to 4 and 3 distinct lowercase letters a, j and v are used in it. In the second test there is one of the appropriate new passwords — python, because its length is equal to 6 and it consists of 6 distinct lowercase letters. In the third test there is one of the appropriate new passwords — phphp, because its length is equal to 5 and 2 distinct lowercase letters p and h are used in it. Pay attention the condition that no two identical symbols are consecutive is correct for all appropriate passwords in tests.
500
[ { "input": "4 3", "output": "abca" }, { "input": "6 6", "output": "abcdef" }, { "input": "5 2", "output": "ababa" }, { "input": "3 2", "output": "aba" }, { "input": "10 2", "output": "ababababab" }, { "input": "26 13", "output": "abcdefghijklmabcdefghijklm" }, { "input": "100 2", "output": "abababababababababababababababababababababababababababababababababababababababababababababababababab" }, { "input": "100 10", "output": "abcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghij" }, { "input": "3 3", "output": "abc" }, { "input": "6 3", "output": "abcabc" }, { "input": "10 3", "output": "abcabcabca" }, { "input": "50 3", "output": "abcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcab" }, { "input": "90 2", "output": "ababababababababababababababababababababababababababababababababababababababababababababab" }, { "input": "6 2", "output": "ababab" }, { "input": "99 3", "output": "abcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabc" }, { "input": "4 2", "output": "abab" }, { "input": "100 3", "output": "abcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabca" }, { "input": "40 22", "output": "abcdefghijklmnopqrstuvabcdefghijklmnopqr" }, { "input": "13 8", "output": "abcdefghabcde" }, { "input": "16 15", "output": "abcdefghijklmnoa" }, { "input": "17 17", "output": "abcdefghijklmnopq" }, { "input": "19 4", "output": "abcdabcdabcdabcdabc" }, { "input": "100 26", "output": "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuv" }, { "input": "100 25", "output": "abcdefghijklmnopqrstuvwxyabcdefghijklmnopqrstuvwxyabcdefghijklmnopqrstuvwxyabcdefghijklmnopqrstuvwxy" }, { "input": "26 26", "output": "abcdefghijklmnopqrstuvwxyz" }, { "input": "27 26", "output": "abcdefghijklmnopqrstuvwxyza" }, { "input": "2 2", "output": "ab" }, { "input": "26 25", "output": "abcdefghijklmnopqrstuvwxya" }, { "input": "99 2", "output": "abababababababababababababababababababababababababababababababababababababababababababababababababa" }, { "input": "99 26", "output": "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstu" }, { "input": "4 4", "output": "abcd" }, { "input": "5 3", "output": "abcab" }, { "input": "5 4", "output": "abcda" }, { "input": "5 5", "output": "abcde" }, { "input": "24 22", "output": "abcdefghijklmnopqrstuvab" }, { "input": "26 14", "output": "abcdefghijklmnabcdefghijkl" }, { "input": "26 15", "output": "abcdefghijklmnoabcdefghijk" }, { "input": "30 12", "output": "abcdefghijklabcdefghijklabcdef" }, { "input": "35 4", "output": "abcdabcdabcdabcdabcdabcdabcdabcdabc" }, { "input": "79 3", "output": "abcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabca" }, { "input": "79 14", "output": "abcdefghijklmnabcdefghijklmnabcdefghijklmnabcdefghijklmnabcdefghijklmnabcdefghi" }, { "input": "85 13", "output": "abcdefghijklmabcdefghijklmabcdefghijklmabcdefghijklmabcdefghijklmabcdefghijklmabcdefg" }, { "input": "90 25", "output": "abcdefghijklmnopqrstuvwxyabcdefghijklmnopqrstuvwxyabcdefghijklmnopqrstuvwxyabcdefghijklmno" }, { "input": "90 19", "output": "abcdefghijklmnopqrsabcdefghijklmnopqrsabcdefghijklmnopqrsabcdefghijklmnopqrsabcdefghijklmn" }, { "input": "26 24", "output": "abcdefghijklmnopqrstuvwxab" }, { "input": "100 17", "output": "abcdefghijklmnopqabcdefghijklmnopqabcdefghijklmnopqabcdefghijklmnopqabcdefghijklmnopqabcdefghijklmno" }, { "input": "26 2", "output": "ababababababababababababab" } ]
1,623,705,195
2,147,483,647
Python 3
OK
TESTS
47
77
0
n, k = map(int,input().split()) print(('abcdefghijklmnopqrstuvwxyz' [:k]*n )[:n])
Title: New Password Time Limit: None seconds Memory Limit: None megabytes Problem Description: Innokentiy decides to change the password in the social net "Contact!", but he is too lazy to invent a new password by himself. That is why he needs your help. Innokentiy decides that new password should satisfy the following conditions: - the length of the password must be equal to *n*, - the password should consist only of lowercase Latin letters, - the number of distinct symbols in the password must be equal to *k*, - any two consecutive symbols in the password must be distinct. Your task is to help Innokentiy and to invent a new password which will satisfy all given conditions. Input Specification: The first line contains two positive integers *n* and *k* (2<=≤<=*n*<=≤<=100, 2<=≤<=*k*<=≤<=*min*(*n*,<=26)) — the length of the password and the number of distinct symbols in it. Pay attention that a desired new password always exists. Output Specification: Print any password which satisfies all conditions given by Innokentiy. Demo Input: ['4 3\n', '6 6\n', '5 2\n'] Demo Output: ['java\n', 'python\n', 'phphp\n'] Note: In the first test there is one of the appropriate new passwords — java, because its length is equal to 4 and 3 distinct lowercase letters a, j and v are used in it. In the second test there is one of the appropriate new passwords — python, because its length is equal to 6 and it consists of 6 distinct lowercase letters. In the third test there is one of the appropriate new passwords — phphp, because its length is equal to 5 and 2 distinct lowercase letters p and h are used in it. Pay attention the condition that no two identical symbols are consecutive is correct for all appropriate passwords in tests.
```python n, k = map(int,input().split()) print(('abcdefghijklmnopqrstuvwxyz' [:k]*n )[:n]) ```
3
935
A
Fafa and his Company
PROGRAMMING
800
[ "brute force", "implementation" ]
null
null
Fafa owns a company that works on huge projects. There are *n* employees in Fafa's company. Whenever the company has a new project to start working on, Fafa has to divide the tasks of this project among all the employees. Fafa finds doing this every time is very tiring for him. So, he decided to choose the best *l* employees in his company as team leaders. Whenever there is a new project, Fafa will divide the tasks among only the team leaders and each team leader will be responsible of some positive number of employees to give them the tasks. To make this process fair for the team leaders, each one of them should be responsible for the same number of employees. Moreover, every employee, who is not a team leader, has to be under the responsibility of exactly one team leader, and no team leader is responsible for another team leader. Given the number of employees *n*, find in how many ways Fafa could choose the number of team leaders *l* in such a way that it is possible to divide employees between them evenly.
The input consists of a single line containing a positive integer *n* (2<=≤<=*n*<=≤<=105) — the number of employees in Fafa's company.
Print a single integer representing the answer to the problem.
[ "2\n", "10\n" ]
[ "1\n", "3\n" ]
In the second sample Fafa has 3 ways: - choose only 1 employee as a team leader with 9 employees under his responsibility. - choose 2 employees as team leaders with 4 employees under the responsibility of each of them. - choose 5 employees as team leaders with 1 employee under the responsibility of each of them.
500
[ { "input": "2", "output": "1" }, { "input": "10", "output": "3" }, { "input": "3", "output": "1" }, { "input": "4", "output": "2" }, { "input": "6", "output": "3" }, { "input": "13", "output": "1" }, { "input": "100000", "output": "35" }, { "input": "1024", "output": "10" }, { "input": "99999", "output": "11" }, { "input": "10007", "output": "1" }, { "input": "4096", "output": "12" }, { "input": "65536", "output": "16" }, { "input": "40320", "output": "95" }, { "input": "30030", "output": "63" }, { "input": "161", "output": "3" }, { "input": "1000", "output": "15" }, { "input": "10000", "output": "24" }, { "input": "777", "output": "7" }, { "input": "121", "output": "2" }, { "input": "25", "output": "2" }, { "input": "40000", "output": "34" }, { "input": "99990", "output": "47" }, { "input": "98765", "output": "3" }, { "input": "56789", "output": "3" }, { "input": "13579", "output": "3" }, { "input": "97531", "output": "3" }, { "input": "12345", "output": "7" }, { "input": "54321", "output": "7" }, { "input": "83160", "output": "127" }, { "input": "9", "output": "2" }, { "input": "21", "output": "3" }, { "input": "11", "output": "1" }, { "input": "15", "output": "3" } ]
1,700,503,551
2,147,483,647
Python 3
OK
TESTS
33
46
0
# A. Fafa and his Company n = int(input()) i = 1 cont = 0 while i <= n/2: e = n - i if e % i == 0: cont += 1 i += 1 print(cont)
Title: Fafa and his Company Time Limit: None seconds Memory Limit: None megabytes Problem Description: Fafa owns a company that works on huge projects. There are *n* employees in Fafa's company. Whenever the company has a new project to start working on, Fafa has to divide the tasks of this project among all the employees. Fafa finds doing this every time is very tiring for him. So, he decided to choose the best *l* employees in his company as team leaders. Whenever there is a new project, Fafa will divide the tasks among only the team leaders and each team leader will be responsible of some positive number of employees to give them the tasks. To make this process fair for the team leaders, each one of them should be responsible for the same number of employees. Moreover, every employee, who is not a team leader, has to be under the responsibility of exactly one team leader, and no team leader is responsible for another team leader. Given the number of employees *n*, find in how many ways Fafa could choose the number of team leaders *l* in such a way that it is possible to divide employees between them evenly. Input Specification: The input consists of a single line containing a positive integer *n* (2<=≤<=*n*<=≤<=105) — the number of employees in Fafa's company. Output Specification: Print a single integer representing the answer to the problem. Demo Input: ['2\n', '10\n'] Demo Output: ['1\n', '3\n'] Note: In the second sample Fafa has 3 ways: - choose only 1 employee as a team leader with 9 employees under his responsibility. - choose 2 employees as team leaders with 4 employees under the responsibility of each of them. - choose 5 employees as team leaders with 1 employee under the responsibility of each of them.
```python # A. Fafa and his Company n = int(input()) i = 1 cont = 0 while i <= n/2: e = n - i if e % i == 0: cont += 1 i += 1 print(cont) ```
3
0
none
none
none
0
[ "none" ]
null
null
Карта звёздного неба представляет собой прямоугольное поле, состоящее из *n* строк по *m* символов в каждой строке. Каждый символ — это либо «.» (означает пустой участок неба), либо «*» (означает то, что в этом месте на небе есть звезда). Новое издание карты звёздного неба будет напечатано на квадратных листах, поэтому требуется найти минимально возможную сторону квадрата, в который могут поместиться все звезды. Границы искомого квадрата должны быть параллельны сторонам заданного прямоугольного поля.
В первой строке входных данных записаны два числа *n* и *m* (1<=≤<=*n*,<=*m*<=≤<=1000) — количество строк и столбцов на карте звездного неба. В следующих *n* строках задано по *m* символов. Каждый символ — это либо «.» (пустой участок неба), либо «*» (звезда). Гарантируется, что на небе есть хотя бы одна звезда.
Выведите одно число — минимально возможную сторону квадрата, которым можно накрыть все звезды.
[ "4 4\n....\n..*.\n...*\n..**\n", "1 3\n*.*\n", "2 1\n.\n*\n" ]
[ "3\n", "3\n", "1\n" ]
Один из возможных ответов на первый тестовый пример: Один из возможных ответов на второй тестовый пример (обратите внимание, что покрывающий квадрат выходит за пределы карты звездного неба): Ответ на третий тестовый пример:
0
[ { "input": "4 4\n....\n..*.\n...*\n..**", "output": "3" }, { "input": "1 3\n*.*", "output": "3" }, { "input": "2 1\n.\n*", "output": "1" }, { "input": "1 1\n*", "output": "1" }, { "input": "1 2\n.*", "output": "1" }, { "input": "1 2\n*.", "output": "1" }, { "input": "1 2\n**", "output": "2" }, { "input": "2 1\n.\n*", "output": "1" }, { "input": "2 1\n*\n.", "output": "1" }, { "input": "2 1\n*\n*", "output": "2" }, { "input": "5 3\n..*\n.**\n..*\n...\n..*", "output": "5" }, { "input": "1 1\n*", "output": "1" }, { "input": "1 2\n*.", "output": "1" }, { "input": "1 2\n**", "output": "2" }, { "input": "1 3\n.**", "output": "2" }, { "input": "1 3\n*.*", "output": "3" }, { "input": "1 4\n..**", "output": "2" }, { "input": "1 4\n*..*", "output": "4" }, { "input": "1 5\n.*.**", "output": "4" }, { "input": "1 5\n.*..*", "output": "4" }, { "input": "2 1\n*\n.", "output": "1" }, { "input": "2 1\n*\n*", "output": "2" }, { "input": "2 2\n.*\n..", "output": "1" }, { "input": "2 2\n*.\n.*", "output": "2" }, { "input": "2 3\n*..\n**.", "output": "2" }, { "input": "2 3\n*..\n..*", "output": "3" }, { "input": "2 4\n.***\n.*.*", "output": "3" }, { "input": "2 5\n*..**\n.*.*.", "output": "5" }, { "input": "2 5\n.....\n*.*..", "output": "3" }, { "input": "3 1\n*\n*\n*", "output": "3" }, { "input": "3 1\n*\n.\n*", "output": "3" }, { "input": "3 2\n..\n..\n**", "output": "2" }, { "input": "3 2\n.*\n.*\n..", "output": "2" }, { "input": "3 3\n*..\n.**\n***", "output": "3" }, { "input": "3 4\n..*.\n....\n..*.", "output": "3" }, { "input": "3 5\n.....\n.*...\n..*..", "output": "2" }, { "input": "4 1\n.\n.\n*\n*", "output": "2" }, { "input": "4 1\n*\n.\n*\n.", "output": "3" }, { "input": "4 2\n*.\n*.\n.*\n**", "output": "4" }, { "input": "4 2\n*.\n..\n..\n.*", "output": "4" }, { "input": "4 3\n..*\n...\n...\n*..", "output": "4" }, { "input": "4 4\n..*.\n..*.\n.*..\n***.", "output": "4" }, { "input": "4 4\n....\n...*\n....\n..*.", "output": "3" }, { "input": "5 1\n*\n*\n.\n.\n.", "output": "2" }, { "input": "5 1\n*\n.\n.\n.\n*", "output": "5" }, { "input": "5 2\n.*\n**\n**\n..\n**", "output": "5" }, { "input": "5 2\n*.\n..\n..\n..\n.*", "output": "5" }, { "input": "5 3\n...\n***\n..*\n.**\n**.", "output": "4" }, { "input": "5 3\n*..\n...\n...\n...\n.*.", "output": "5" }, { "input": "5 4\n*.**\n.*..\n.*..\n..*.\n*..*", "output": "5" }, { "input": "5 4\n....\n..*.\n....\n....\n..*.", "output": "4" }, { "input": "5 5\n....*\n....*\n....*\n..*..\n..*.*", "output": "5" }, { "input": "2 2\n**\n**", "output": "2" }, { "input": "2 2\n*.\n.*", "output": "2" }, { "input": "2 2\n.*\n*.", "output": "2" }, { "input": "2 2\n**\n..", "output": "2" }, { "input": "2 2\n..\n**", "output": "2" }, { "input": "2 2\n*.\n*.", "output": "2" }, { "input": "2 2\n.*\n.*", "output": "2" }, { "input": "2 2\n*.\n..", "output": "1" }, { "input": "2 2\n.*\n..", "output": "1" }, { "input": "2 2\n..\n*.", "output": "1" }, { "input": "2 2\n..\n.*", "output": "1" }, { "input": "2 2\n.*\n**", "output": "2" }, { "input": "2 2\n*.\n**", "output": "2" }, { "input": "2 2\n**\n.*", "output": "2" }, { "input": "2 2\n**\n*.", "output": "2" } ]
1,458,828,152
21,751
Python 3
TIME_LIMIT_EXCEEDED
PRETESTS
14
1,000
34,816,000
gran = [int(i) for i in input().split()]; zvs = []; dull = []; strok = []; stolb = []; for i in range(gran[0]): nm = [[str(l) for l in input()]] dull += nm; for zv in range(len(dull)): for zvj in range(len(dull[0])): if dull[zv][int(zvj)] == '*': strok.append(int(zv)) stolb.append(int(zvj)) strok.sort() Xst = int(max(strok)) - int(min(strok)) + 1; stolb.sort() Yst = int(max(stolb)) - int(min(stolb)) + 1; if Xst >= Yst: print(Xst) else: print(Yst);
Title: none Time Limit: None seconds Memory Limit: None megabytes Problem Description: Карта звёздного неба представляет собой прямоугольное поле, состоящее из *n* строк по *m* символов в каждой строке. Каждый символ — это либо «.» (означает пустой участок неба), либо «*» (означает то, что в этом месте на небе есть звезда). Новое издание карты звёздного неба будет напечатано на квадратных листах, поэтому требуется найти минимально возможную сторону квадрата, в который могут поместиться все звезды. Границы искомого квадрата должны быть параллельны сторонам заданного прямоугольного поля. Input Specification: В первой строке входных данных записаны два числа *n* и *m* (1<=≤<=*n*,<=*m*<=≤<=1000) — количество строк и столбцов на карте звездного неба. В следующих *n* строках задано по *m* символов. Каждый символ — это либо «.» (пустой участок неба), либо «*» (звезда). Гарантируется, что на небе есть хотя бы одна звезда. Output Specification: Выведите одно число — минимально возможную сторону квадрата, которым можно накрыть все звезды. Demo Input: ['4 4\n....\n..*.\n...*\n..**\n', '1 3\n*.*\n', '2 1\n.\n*\n'] Demo Output: ['3\n', '3\n', '1\n'] Note: Один из возможных ответов на первый тестовый пример: Один из возможных ответов на второй тестовый пример (обратите внимание, что покрывающий квадрат выходит за пределы карты звездного неба): Ответ на третий тестовый пример:
```python gran = [int(i) for i in input().split()]; zvs = []; dull = []; strok = []; stolb = []; for i in range(gran[0]): nm = [[str(l) for l in input()]] dull += nm; for zv in range(len(dull)): for zvj in range(len(dull[0])): if dull[zv][int(zvj)] == '*': strok.append(int(zv)) stolb.append(int(zvj)) strok.sort() Xst = int(max(strok)) - int(min(strok)) + 1; stolb.sort() Yst = int(max(stolb)) - int(min(stolb)) + 1; if Xst >= Yst: print(Xst) else: print(Yst); ```
0
842
A
Kirill And The Game
PROGRAMMING
1,200
[ "brute force", "two pointers" ]
null
null
Kirill plays a new computer game. He came to the potion store where he can buy any potion. Each potion is characterized by two integers — amount of experience and cost. The efficiency of a potion is the ratio of the amount of experience to the cost. Efficiency may be a non-integer number. For each two integer numbers *a* and *b* such that *l*<=≤<=*a*<=≤<=*r* and *x*<=≤<=*b*<=≤<=*y* there is a potion with experience *a* and cost *b* in the store (that is, there are (*r*<=-<=*l*<=+<=1)·(*y*<=-<=*x*<=+<=1) potions). Kirill wants to buy a potion which has efficiency *k*. Will he be able to do this?
First string contains five integer numbers *l*, *r*, *x*, *y*, *k* (1<=≤<=*l*<=≤<=*r*<=≤<=107, 1<=≤<=*x*<=≤<=*y*<=≤<=107, 1<=≤<=*k*<=≤<=107).
Print "YES" without quotes if a potion with efficiency exactly *k* can be bought in the store and "NO" without quotes otherwise. You can output each of the letters in any register.
[ "1 10 1 10 1\n", "1 5 6 10 1\n" ]
[ "YES", "NO" ]
none
500
[ { "input": "1 10 1 10 1", "output": "YES" }, { "input": "1 5 6 10 1", "output": "NO" }, { "input": "1 1 1 1 1", "output": "YES" }, { "input": "1 1 1 1 2", "output": "NO" }, { "input": "1 100000 1 100000 100000", "output": "YES" }, { "input": "1 100000 1 100000 100001", "output": "NO" }, { "input": "25 10000 200 10000 5", "output": "YES" }, { "input": "1 100000 10 100000 50000", "output": "NO" }, { "input": "91939 94921 10197 89487 1", "output": "NO" }, { "input": "30518 58228 74071 77671 1", "output": "NO" }, { "input": "46646 79126 78816 91164 5", "output": "NO" }, { "input": "30070 83417 92074 99337 2", "output": "NO" }, { "input": "13494 17544 96820 99660 6", "output": "NO" }, { "input": "96918 97018 10077 86510 9", "output": "YES" }, { "input": "13046 45594 14823 52475 1", "output": "YES" }, { "input": "29174 40572 95377 97669 4", "output": "NO" }, { "input": "79894 92433 8634 86398 4", "output": "YES" }, { "input": "96022 98362 13380 94100 6", "output": "YES" }, { "input": "79446 95675 93934 96272 3", "output": "NO" }, { "input": "5440 46549 61481 99500 10", "output": "NO" }, { "input": "21569 53580 74739 87749 3", "output": "NO" }, { "input": "72289 78297 79484 98991 7", "output": "NO" }, { "input": "88417 96645 92742 98450 5", "output": "NO" }, { "input": "71841 96625 73295 77648 8", "output": "NO" }, { "input": "87969 99230 78041 94736 4", "output": "NO" }, { "input": "4 4 1 2 3", "output": "NO" }, { "input": "150 150 1 2 100", "output": "NO" }, { "input": "99 100 1 100 50", "output": "YES" }, { "input": "7 7 3 6 2", "output": "NO" }, { "input": "10 10 1 10 1", "output": "YES" }, { "input": "36 36 5 7 6", "output": "YES" }, { "input": "73 96 1 51 51", "output": "NO" }, { "input": "3 3 1 3 2", "output": "NO" }, { "input": "10000000 10000000 1 100000 10000000", "output": "YES" }, { "input": "9222174 9829060 9418763 9955619 9092468", "output": "NO" }, { "input": "70 70 1 2 50", "output": "NO" }, { "input": "100 200 1 20 5", "output": "YES" }, { "input": "1 200000 65536 65536 65537", "output": "NO" }, { "input": "15 15 1 100 1", "output": "YES" }, { "input": "10000000 10000000 1 10000000 100000", "output": "YES" }, { "input": "10 10 2 5 4", "output": "NO" }, { "input": "67 69 7 7 9", "output": "NO" }, { "input": "100000 10000000 1 10000000 100000", "output": "YES" }, { "input": "9 12 1 2 7", "output": "NO" }, { "input": "5426234 6375745 2636512 8492816 4409404", "output": "NO" }, { "input": "6134912 6134912 10000000 10000000 999869", "output": "NO" }, { "input": "3 3 1 100 1", "output": "YES" }, { "input": "10000000 10000000 10 10000000 100000", "output": "YES" }, { "input": "4 4 1 100 2", "output": "YES" }, { "input": "8 13 1 4 7", "output": "NO" }, { "input": "10 10 100000 10000000 10000000", "output": "NO" }, { "input": "5 6 1 4 2", "output": "YES" }, { "input": "1002 1003 1 2 1000", "output": "NO" }, { "input": "4 5 1 2 2", "output": "YES" }, { "input": "5 6 1 5 1", "output": "YES" }, { "input": "15 21 2 4 7", "output": "YES" }, { "input": "4 5 3 7 1", "output": "YES" }, { "input": "15 15 3 4 4", "output": "NO" }, { "input": "3 6 1 2 2", "output": "YES" }, { "input": "2 10 3 6 3", "output": "YES" }, { "input": "1 10000000 1 10000000 100000", "output": "YES" }, { "input": "8 13 1 2 7", "output": "NO" }, { "input": "98112 98112 100000 100000 128850", "output": "NO" }, { "input": "2 2 1 2 1", "output": "YES" }, { "input": "8 8 3 4 2", "output": "YES" }, { "input": "60 60 2 3 25", "output": "NO" }, { "input": "16 17 2 5 5", "output": "NO" }, { "input": "2 4 1 3 1", "output": "YES" }, { "input": "4 5 1 2 3", "output": "NO" }, { "input": "10 10 3 4 3", "output": "NO" }, { "input": "10 10000000 999999 10000000 300", "output": "NO" }, { "input": "100 120 9 11 10", "output": "YES" }, { "input": "8 20 1 3 4", "output": "YES" }, { "input": "10 14 2 3 4", "output": "YES" }, { "input": "2000 2001 1 3 1000", "output": "YES" }, { "input": "12 13 2 3 5", "output": "NO" }, { "input": "7 7 2 3 3", "output": "NO" }, { "input": "5 8 1 10000000 4", "output": "YES" }, { "input": "5 5 1 1 4", "output": "NO" }, { "input": "5 5 1 6 2", "output": "NO" }, { "input": "200 300 4000381 4000382 4000381", "output": "NO" }, { "input": "11 17 2 5 2", "output": "NO" }, { "input": "9999999 10000000 1 10000000 999997", "output": "NO" }, { "input": "7 8 2 3 3", "output": "NO" }, { "input": "7 7 3 3 2", "output": "NO" }, { "input": "15 15 2 3 7", "output": "NO" }, { "input": "65408 65408 859 859 10000000", "output": "NO" }, { "input": "1000000 10000000 1 100000 1", "output": "NO" }, { "input": "6 12 2 3 2", "output": "YES" }, { "input": "7 8 1 3 3", "output": "NO" }, { "input": "4 4 1 2 2", "output": "YES" }, { "input": "2 3 1 2 2", "output": "YES" }, { "input": "11 14 2 3 5", "output": "NO" }, { "input": "7 7 1 10 3", "output": "NO" }, { "input": "49 50 1 2 27", "output": "NO" }, { "input": "1 10000000 1 10000000 123456", "output": "YES" }, { "input": "100000 10000000 100 10000000 100000", "output": "YES" }, { "input": "17 19 2 3 8", "output": "NO" }, { "input": "4 6 3 9 1", "output": "YES" }, { "input": "19 20 6 7 3", "output": "NO" }, { "input": "5000000 10000000 1 4999999 1", "output": "NO" } ]
1,504,025,808
6,708
Python 3
COMPILATION_ERROR
PRETESTS
0
0
0
#include <stdio.h> int main() { long long int l,r,x,y,i; int k,a=0; scanf("%lld %lld %lld %lld %d",&l,&r,&x,&y,&k); if (x>r) { printf("NO\n"); } else { for (i=l; i<=r; i++) { if ((i/k) >=x && (i/k) <=y) { a++; if (a>0) { break; } } } if (a>0) { printf("YES\n"); } else { printf("NO\n"); } } return 0; }
Title: Kirill And The Game Time Limit: None seconds Memory Limit: None megabytes Problem Description: Kirill plays a new computer game. He came to the potion store where he can buy any potion. Each potion is characterized by two integers — amount of experience and cost. The efficiency of a potion is the ratio of the amount of experience to the cost. Efficiency may be a non-integer number. For each two integer numbers *a* and *b* such that *l*<=≤<=*a*<=≤<=*r* and *x*<=≤<=*b*<=≤<=*y* there is a potion with experience *a* and cost *b* in the store (that is, there are (*r*<=-<=*l*<=+<=1)·(*y*<=-<=*x*<=+<=1) potions). Kirill wants to buy a potion which has efficiency *k*. Will he be able to do this? Input Specification: First string contains five integer numbers *l*, *r*, *x*, *y*, *k* (1<=≤<=*l*<=≤<=*r*<=≤<=107, 1<=≤<=*x*<=≤<=*y*<=≤<=107, 1<=≤<=*k*<=≤<=107). Output Specification: Print "YES" without quotes if a potion with efficiency exactly *k* can be bought in the store and "NO" without quotes otherwise. You can output each of the letters in any register. Demo Input: ['1 10 1 10 1\n', '1 5 6 10 1\n'] Demo Output: ['YES', 'NO'] Note: none
```python #include <stdio.h> int main() { long long int l,r,x,y,i; int k,a=0; scanf("%lld %lld %lld %lld %d",&l,&r,&x,&y,&k); if (x>r) { printf("NO\n"); } else { for (i=l; i<=r; i++) { if ((i/k) >=x && (i/k) <=y) { a++; if (a>0) { break; } } } if (a>0) { printf("YES\n"); } else { printf("NO\n"); } } return 0; } ```
-1
976
A
Minimum Binary Number
PROGRAMMING
800
[ "implementation" ]
null
null
String can be called correct if it consists of characters "0" and "1" and there are no redundant leading zeroes. Here are some examples: "0", "10", "1001". You are given a correct string *s*. You can perform two different operations on this string: 1. swap any pair of adjacent characters (for example, "101" "110"); 1. replace "11" with "1" (for example, "110" "10"). Let *val*(*s*) be such a number that *s* is its binary representation. Correct string *a* is less than some other correct string *b* iff *val*(*a*)<=&lt;<=*val*(*b*). Your task is to find the minimum correct string that you can obtain from the given one using the operations described above. You can use these operations any number of times in any order (or even use no operations at all).
The first line contains integer number *n* (1<=≤<=*n*<=≤<=100) — the length of string *s*. The second line contains the string *s* consisting of characters "0" and "1". It is guaranteed that the string *s* is correct.
Print one string — the minimum correct string that you can obtain from the given one.
[ "4\n1001\n", "1\n1\n" ]
[ "100\n", "1\n" ]
In the first example you can obtain the answer by the following sequence of operations: "1001" <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> "1010" <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> "1100" <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> "100". In the second example you can't obtain smaller answer no matter what operations you use.
0
[ { "input": "4\n1001", "output": "100" }, { "input": "1\n1", "output": "1" }, { "input": "100\n1110111100001111011111111010110011111111011110000111101101011100110110001011000000101010110101011100", "output": "1000000000000000000000000000000000000000" }, { "input": "100\n1000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", "output": "1000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" }, { "input": "100\n1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111", "output": "1" }, { "input": "100\n1111111111111111111111111111111111111111111111111111111110111111111111111111111111111111111111111111", "output": "10" }, { "input": "1\n0", "output": "0" }, { "input": "8\n10101010", "output": "10000" }, { "input": "2\n10", "output": "10" }, { "input": "3\n111", "output": "1" }, { "input": "5\n11100", "output": "100" }, { "input": "2\n11", "output": "1" }, { "input": "3\n110", "output": "10" }, { "input": "50\n10010010000000000000000000000000000000001000000000", "output": "10000000000000000000000000000000000000000000000" } ]
1,525,167,956
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
0
77
7,065,600
#http://codeforces.com/problemset/problem/976/A def minBin(s): ones = 0 zeros = 0 for letter in s: if letter == "1": ones += 1 else: zeros += 1 if ones == 0: return 0 return "1"+"0"*zeros print(minBin("1001")) while True: try: input() binary = input() print(minBin(binary)) except EOFError: break
Title: Minimum Binary Number Time Limit: None seconds Memory Limit: None megabytes Problem Description: String can be called correct if it consists of characters "0" and "1" and there are no redundant leading zeroes. Here are some examples: "0", "10", "1001". You are given a correct string *s*. You can perform two different operations on this string: 1. swap any pair of adjacent characters (for example, "101" "110"); 1. replace "11" with "1" (for example, "110" "10"). Let *val*(*s*) be such a number that *s* is its binary representation. Correct string *a* is less than some other correct string *b* iff *val*(*a*)<=&lt;<=*val*(*b*). Your task is to find the minimum correct string that you can obtain from the given one using the operations described above. You can use these operations any number of times in any order (or even use no operations at all). Input Specification: The first line contains integer number *n* (1<=≤<=*n*<=≤<=100) — the length of string *s*. The second line contains the string *s* consisting of characters "0" and "1". It is guaranteed that the string *s* is correct. Output Specification: Print one string — the minimum correct string that you can obtain from the given one. Demo Input: ['4\n1001\n', '1\n1\n'] Demo Output: ['100\n', '1\n'] Note: In the first example you can obtain the answer by the following sequence of operations: "1001" <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> "1010" <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> "1100" <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> "100". In the second example you can't obtain smaller answer no matter what operations you use.
```python #http://codeforces.com/problemset/problem/976/A def minBin(s): ones = 0 zeros = 0 for letter in s: if letter == "1": ones += 1 else: zeros += 1 if ones == 0: return 0 return "1"+"0"*zeros print(minBin("1001")) while True: try: input() binary = input() print(minBin(binary)) except EOFError: break ```
0
143
A
Help Vasilisa the Wise 2
PROGRAMMING
1,000
[ "brute force", "math" ]
null
null
Vasilisa the Wise from the Kingdom of Far Far Away got a magic box with a secret as a present from her friend Hellawisa the Wise from the Kingdom of A Little Closer. However, Vasilisa the Wise does not know what the box's secret is, since she cannot open it again. She hopes that you will help her one more time with that. The box's lock looks as follows: it contains 4 identical deepenings for gems as a 2<=×<=2 square, and some integer numbers are written at the lock's edge near the deepenings. The example of a lock is given on the picture below. The box is accompanied with 9 gems. Their shapes match the deepenings' shapes and each gem contains one number from 1 to 9 (each number is written on exactly one gem). The box will only open after it is decorated with gems correctly: that is, each deepening in the lock should be filled with exactly one gem. Also, the sums of numbers in the square's rows, columns and two diagonals of the square should match the numbers written at the lock's edge. For example, the above lock will open if we fill the deepenings with gems with numbers as is shown on the picture below. Now Vasilisa the Wise wants to define, given the numbers on the box's lock, which gems she should put in the deepenings to open the box. Help Vasilisa to solve this challenging task.
The input contains numbers written on the edges of the lock of the box. The first line contains space-separated integers *r*1 and *r*2 that define the required sums of numbers in the rows of the square. The second line contains space-separated integers *c*1 and *c*2 that define the required sums of numbers in the columns of the square. The third line contains space-separated integers *d*1 and *d*2 that define the required sums of numbers on the main and on the side diagonals of the square (1<=≤<=*r*1,<=*r*2,<=*c*1,<=*c*2,<=*d*1,<=*d*2<=≤<=20). Correspondence between the above 6 variables and places where they are written is shown on the picture below. For more clarifications please look at the second sample test that demonstrates the example given in the problem statement.
Print the scheme of decorating the box with stones: two lines containing two space-separated integers from 1 to 9. The numbers should be pairwise different. If there is no solution for the given lock, then print the single number "-1" (without the quotes). If there are several solutions, output any.
[ "3 7\n4 6\n5 5\n", "11 10\n13 8\n5 16\n", "1 2\n3 4\n5 6\n", "10 10\n10 10\n10 10\n" ]
[ "1 2\n3 4\n", "4 7\n9 1\n", "-1\n", "-1\n" ]
Pay attention to the last test from the statement: it is impossible to open the box because for that Vasilisa the Wise would need 4 identical gems containing number "5". However, Vasilisa only has one gem with each number from 1 to 9.
500
[ { "input": "3 7\n4 6\n5 5", "output": "1 2\n3 4" }, { "input": "11 10\n13 8\n5 16", "output": "4 7\n9 1" }, { "input": "1 2\n3 4\n5 6", "output": "-1" }, { "input": "10 10\n10 10\n10 10", "output": "-1" }, { "input": "5 13\n8 10\n11 7", "output": "3 2\n5 8" }, { "input": "12 17\n10 19\n13 16", "output": "-1" }, { "input": "11 11\n17 5\n12 10", "output": "9 2\n8 3" }, { "input": "12 11\n11 12\n16 7", "output": "-1" }, { "input": "5 9\n7 7\n8 6", "output": "3 2\n4 5" }, { "input": "10 7\n4 13\n11 6", "output": "-1" }, { "input": "18 10\n16 12\n12 16", "output": "-1" }, { "input": "13 6\n10 9\n6 13", "output": "-1" }, { "input": "14 16\n16 14\n18 12", "output": "-1" }, { "input": "16 10\n16 10\n12 14", "output": "-1" }, { "input": "11 9\n12 8\n11 9", "output": "-1" }, { "input": "5 14\n10 9\n10 9", "output": "-1" }, { "input": "2 4\n1 5\n3 3", "output": "-1" }, { "input": "17 16\n14 19\n18 15", "output": "-1" }, { "input": "12 12\n14 10\n16 8", "output": "9 3\n5 7" }, { "input": "15 11\n16 10\n9 17", "output": "7 8\n9 2" }, { "input": "8 10\n9 9\n13 5", "output": "6 2\n3 7" }, { "input": "13 7\n10 10\n5 15", "output": "4 9\n6 1" }, { "input": "14 11\n9 16\n16 9", "output": "-1" }, { "input": "12 8\n14 6\n8 12", "output": "-1" }, { "input": "10 6\n6 10\n4 12", "output": "-1" }, { "input": "10 8\n10 8\n4 14", "output": "-1" }, { "input": "14 13\n9 18\n14 13", "output": "-1" }, { "input": "9 14\n8 15\n8 15", "output": "-1" }, { "input": "3 8\n2 9\n6 5", "output": "-1" }, { "input": "14 17\n18 13\n15 16", "output": "-1" }, { "input": "16 14\n15 15\n17 13", "output": "9 7\n6 8" }, { "input": "14 11\n16 9\n13 12", "output": "9 5\n7 4" }, { "input": "13 10\n11 12\n7 16", "output": "4 9\n7 3" }, { "input": "14 8\n11 11\n13 9", "output": "8 6\n3 5" }, { "input": "12 11\n13 10\n10 13", "output": "-1" }, { "input": "6 5\n2 9\n5 6", "output": "-1" }, { "input": "7 8\n8 7\n12 3", "output": "-1" }, { "input": "7 11\n7 11\n6 12", "output": "-1" }, { "input": "8 5\n11 2\n8 5", "output": "-1" }, { "input": "10 16\n14 12\n14 12", "output": "-1" }, { "input": "7 9\n4 12\n5 11", "output": "-1" }, { "input": "11 13\n19 5\n12 12", "output": "-1" }, { "input": "8 12\n5 15\n11 9", "output": "2 6\n3 9" }, { "input": "16 5\n13 8\n10 11", "output": "9 7\n4 1" }, { "input": "3 14\n8 9\n10 7", "output": "2 1\n6 8" }, { "input": "12 14\n11 15\n9 17", "output": "3 9\n8 6" }, { "input": "13 7\n9 11\n14 6", "output": "8 5\n1 6" }, { "input": "13 8\n15 6\n11 10", "output": "9 4\n6 2" }, { "input": "9 6\n5 10\n3 12", "output": "1 8\n4 2" }, { "input": "12 7\n5 14\n8 11", "output": "3 9\n2 5" }, { "input": "9 12\n3 17\n10 10", "output": "-1" }, { "input": "3 8\n4 6\n5 5", "output": "-1" } ]
1,579,973,462
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
7
216
307,200
def solution(r,c,d): n1=n2=n3=n4=0 for i in range(1,10): n1=i n2=r[0]-i n3=c[0]-i n4=d[0]-i if (n2 in range(1,10)) and (n3 in range(1,10)) and (n4 in range(1,10)) and n1!=n2!=n3!=n4: if n3+n4==r[1] and n2+n4==c[1] and n2+n3==d[1]: print("{} {}".format(n1,n2)) print("{} {}".format(n3,n4)) return print(-1) r=list(map(int,input('').split())) c=list(map(int,input('').split())) d=list(map(int,input('').split())) solution(r,c,d)
Title: Help Vasilisa the Wise 2 Time Limit: None seconds Memory Limit: None megabytes Problem Description: Vasilisa the Wise from the Kingdom of Far Far Away got a magic box with a secret as a present from her friend Hellawisa the Wise from the Kingdom of A Little Closer. However, Vasilisa the Wise does not know what the box's secret is, since she cannot open it again. She hopes that you will help her one more time with that. The box's lock looks as follows: it contains 4 identical deepenings for gems as a 2<=×<=2 square, and some integer numbers are written at the lock's edge near the deepenings. The example of a lock is given on the picture below. The box is accompanied with 9 gems. Their shapes match the deepenings' shapes and each gem contains one number from 1 to 9 (each number is written on exactly one gem). The box will only open after it is decorated with gems correctly: that is, each deepening in the lock should be filled with exactly one gem. Also, the sums of numbers in the square's rows, columns and two diagonals of the square should match the numbers written at the lock's edge. For example, the above lock will open if we fill the deepenings with gems with numbers as is shown on the picture below. Now Vasilisa the Wise wants to define, given the numbers on the box's lock, which gems she should put in the deepenings to open the box. Help Vasilisa to solve this challenging task. Input Specification: The input contains numbers written on the edges of the lock of the box. The first line contains space-separated integers *r*1 and *r*2 that define the required sums of numbers in the rows of the square. The second line contains space-separated integers *c*1 and *c*2 that define the required sums of numbers in the columns of the square. The third line contains space-separated integers *d*1 and *d*2 that define the required sums of numbers on the main and on the side diagonals of the square (1<=≤<=*r*1,<=*r*2,<=*c*1,<=*c*2,<=*d*1,<=*d*2<=≤<=20). Correspondence between the above 6 variables and places where they are written is shown on the picture below. For more clarifications please look at the second sample test that demonstrates the example given in the problem statement. Output Specification: Print the scheme of decorating the box with stones: two lines containing two space-separated integers from 1 to 9. The numbers should be pairwise different. If there is no solution for the given lock, then print the single number "-1" (without the quotes). If there are several solutions, output any. Demo Input: ['3 7\n4 6\n5 5\n', '11 10\n13 8\n5 16\n', '1 2\n3 4\n5 6\n', '10 10\n10 10\n10 10\n'] Demo Output: ['1 2\n3 4\n', '4 7\n9 1\n', '-1\n', '-1\n'] Note: Pay attention to the last test from the statement: it is impossible to open the box because for that Vasilisa the Wise would need 4 identical gems containing number "5". However, Vasilisa only has one gem with each number from 1 to 9.
```python def solution(r,c,d): n1=n2=n3=n4=0 for i in range(1,10): n1=i n2=r[0]-i n3=c[0]-i n4=d[0]-i if (n2 in range(1,10)) and (n3 in range(1,10)) and (n4 in range(1,10)) and n1!=n2!=n3!=n4: if n3+n4==r[1] and n2+n4==c[1] and n2+n3==d[1]: print("{} {}".format(n1,n2)) print("{} {}".format(n3,n4)) return print(-1) r=list(map(int,input('').split())) c=list(map(int,input('').split())) d=list(map(int,input('').split())) solution(r,c,d) ```
0
111
A
Petya and Inequiations
PROGRAMMING
1,400
[ "greedy" ]
A. Petya and Inequiations
2
256
Little Petya loves inequations. Help him find *n* positive integers *a*1,<=*a*2,<=...,<=*a**n*, such that the following two conditions are satisfied: - *a*12<=+<=*a*22<=+<=...<=+<=*a**n*2<=≥<=*x*- *a*1<=+<=*a*2<=+<=...<=+<=*a**n*<=≤<=*y*
The first line contains three space-separated integers *n*, *x* and *y* (1<=≤<=*n*<=≤<=105,<=1<=≤<=*x*<=≤<=1012,<=1<=≤<=*y*<=≤<=106). Please do not use the %lld specificator to read or write 64-bit integers in С++. It is recommended to use cin, cout streams or the %I64d specificator.
Print *n* positive integers that satisfy the conditions, one integer per line. If such numbers do not exist, print a single number "-1". If there are several solutions, print any of them.
[ "5 15 15\n", "2 3 2\n", "1 99 11\n" ]
[ "4\n4\n1\n1\n2\n", "-1\n", "11\n" ]
none
500
[ { "input": "5 15 15", "output": "11\n1\n1\n1\n1" }, { "input": "2 3 2", "output": "-1" }, { "input": "1 99 11", "output": "11" }, { "input": "100000 810000099998 1000000", "output": "900001\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n..." }, { "input": "3 254 18", "output": "16\n1\n1" }, { "input": "4 324 77", "output": "74\n1\n1\n1" }, { "input": "5 315 90", "output": "86\n1\n1\n1\n1" }, { "input": "6 225 59", "output": "54\n1\n1\n1\n1\n1" }, { "input": "7 351 29", "output": "23\n1\n1\n1\n1\n1\n1" }, { "input": "100 913723780421 955988", "output": "-1" }, { "input": "200 894176381082 945808", "output": "-1" }, { "input": "300 923251939897 961159", "output": "960860\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n..." }, { "input": "1000 824905348050 909242", "output": "-1" }, { "input": "10000 795416053320 901860", "output": "891861\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n..." }, { "input": "31000 819461299082 936240", "output": "-1" }, { "input": "44000 772772899626 923074", "output": "-1" }, { "input": "45678 783917268558 931068", "output": "885391\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n..." }, { "input": "99999 681508136225 925533", "output": "-1" }, { "input": "99999 688345771552 929664", "output": "829666\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n..." }, { "input": "99976 664640815001 915230", "output": "-1" }, { "input": "100000 729199960625 953931", "output": "-1" }, { "input": "50 890543266647 943735", "output": "-1" }, { "input": "60 817630084499 904288", "output": "904229\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1" }, { "input": "99999 716046078026 946193", "output": "-1" }, { "input": "99998 729652614803 954194", "output": "854197\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n..." }, { "input": "10000 950051796437 984705", "output": "-1" }, { "input": "999 992972391401 997478", "output": "-1" }, { "input": "99999 667887855532 917242", "output": "817244\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n..." }, { "input": "12313 955817132591 989971", "output": "977659\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n..." }, { "input": "1 983300308227 991615", "output": "-1" }, { "input": "2 912219830404 955103", "output": "955102\n1" }, { "input": "3 934371623645 966631", "output": "-1" }, { "input": "4 857839030421 926199", "output": "-1" }, { "input": "7 897398130730 947317", "output": "-1" }, { "input": "60 833021290059 912759", "output": "912700\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1" }, { "input": "99999 715837929182 946070", "output": "846072\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n..." }, { "input": "99998 714958284701 945549", "output": "845552\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n..." }, { "input": "100000 730132752483 954477", "output": "854478\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n..." }, { "input": "9999 850451005599 932197", "output": "922199\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n..." }, { "input": "99999 741078317879 960857", "output": "860859\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n..." }, { "input": "12313 873989408188 947186", "output": "934874\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n..." }, { "input": "1 860113420929 927423", "output": "927423" }, { "input": "2 933669982757 966267", "output": "966266\n1" }, { "input": "3 933157932003 966003", "output": "966001\n1\n1" }, { "input": "4 944626542564 971922", "output": "971919\n1\n1\n1" }, { "input": "7 937519681542 968262", "output": "968256\n1\n1\n1\n1\n1\n1" }, { "input": "100000 1000000000000 1000000", "output": "-1" }, { "input": "99999 999999999999 999999", "output": "-1" }, { "input": "100 1 1", "output": "-1" }, { "input": "2 1 1", "output": "-1" }, { "input": "11 10 10", "output": "-1" }, { "input": "1 5 10", "output": "10" }, { "input": "10 3 8", "output": "-1" }, { "input": "5 37 10", "output": "6\n1\n1\n1\n1" }, { "input": "5 1 4", "output": "-1" }, { "input": "1 1 1", "output": "1" }, { "input": "1 1000000000000 1", "output": "-1" }, { "input": "1 1 1000000", "output": "1000000" }, { "input": "100000 1 1", "output": "-1" }, { "input": "100000 1 1000000", "output": "900001\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n..." }, { "input": "100000 1000000000000 1", "output": "-1" }, { "input": "1 1000000000000 1000000", "output": "1000000" } ]
1,650,564,790
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
1
62
0
n, x, y = map(int, input().split()) if x <= (n-1) + (y - (n-1))**2 and y >= (n-1) + (y - (n-1)): for i in range(n-1): print(1) print(y - (n-1)) else: print(-1111111111)
Title: Petya and Inequiations Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: Little Petya loves inequations. Help him find *n* positive integers *a*1,<=*a*2,<=...,<=*a**n*, such that the following two conditions are satisfied: - *a*12<=+<=*a*22<=+<=...<=+<=*a**n*2<=≥<=*x*- *a*1<=+<=*a*2<=+<=...<=+<=*a**n*<=≤<=*y* Input Specification: The first line contains three space-separated integers *n*, *x* and *y* (1<=≤<=*n*<=≤<=105,<=1<=≤<=*x*<=≤<=1012,<=1<=≤<=*y*<=≤<=106). Please do not use the %lld specificator to read or write 64-bit integers in С++. It is recommended to use cin, cout streams or the %I64d specificator. Output Specification: Print *n* positive integers that satisfy the conditions, one integer per line. If such numbers do not exist, print a single number "-1". If there are several solutions, print any of them. Demo Input: ['5 15 15\n', '2 3 2\n', '1 99 11\n'] Demo Output: ['4\n4\n1\n1\n2\n', '-1\n', '11\n'] Note: none
```python n, x, y = map(int, input().split()) if x <= (n-1) + (y - (n-1))**2 and y >= (n-1) + (y - (n-1)): for i in range(n-1): print(1) print(y - (n-1)) else: print(-1111111111) ```
0
551
A
GukiZ and Contest
PROGRAMMING
800
[ "brute force", "implementation", "sortings" ]
null
null
Professor GukiZ likes programming contests. He especially likes to rate his students on the contests he prepares. Now, he has decided to prepare a new contest. In total, *n* students will attend, and before the start, every one of them has some positive integer rating. Students are indexed from 1 to *n*. Let's denote the rating of *i*-th student as *a**i*. After the contest ends, every student will end up with some positive integer position. GukiZ expects that his students will take places according to their ratings. He thinks that each student will take place equal to . In particular, if student *A* has rating strictly lower then student *B*, *A* will get the strictly better position than *B*, and if two students have equal ratings, they will share the same position. GukiZ would like you to reconstruct the results by following his expectations. Help him and determine the position after the end of the contest for each of his students if everything goes as expected.
The first line contains integer *n* (1<=≤<=*n*<=≤<=2000), number of GukiZ's students. The second line contains *n* numbers *a*1,<=*a*2,<=... *a**n* (1<=≤<=*a**i*<=≤<=2000) where *a**i* is the rating of *i*-th student (1<=≤<=*i*<=≤<=*n*).
In a single line, print the position after the end of the contest for each of *n* students in the same order as they appear in the input.
[ "3\n1 3 3\n", "1\n1\n", "5\n3 5 3 4 5\n" ]
[ "3 1 1\n", "1\n", "4 1 4 3 1\n" ]
In the first sample, students 2 and 3 are positioned first (there is no other student with higher rating), and student 1 is positioned third since there are two students with higher rating. In the second sample, first student is the only one on the contest. In the third sample, students 2 and 5 share the first position with highest rating, student 4 is next with third position, and students 1 and 3 are the last sharing fourth position.
500
[ { "input": "3\n1 3 3", "output": "3 1 1" }, { "input": "1\n1", "output": "1" }, { "input": "5\n3 5 3 4 5", "output": "4 1 4 3 1" }, { "input": "7\n1 3 5 4 2 2 1", "output": "6 3 1 2 4 4 6" }, { "input": "11\n5 6 4 2 9 7 6 6 6 6 7", "output": "9 4 10 11 1 2 4 4 4 4 2" }, { "input": "1\n2000", "output": "1" }, { "input": "2\n2000 2000", "output": "1 1" }, { "input": "3\n500 501 502", "output": "3 2 1" }, { "input": "10\n105 106 1 1 1 11 1000 999 1000 999", "output": "6 5 8 8 8 7 1 3 1 3" }, { "input": "6\n1 2 3 4 5 6", "output": "6 5 4 3 2 1" }, { "input": "7\n6 5 4 3 2 1 1", "output": "1 2 3 4 5 6 6" }, { "input": "8\n153 100 87 14 10 8 6 5", "output": "1 2 3 4 5 6 7 8" }, { "input": "70\n11 54 37 62 1 46 13 17 38 47 28 15 63 5 61 34 49 66 32 59 3 41 58 28 23 62 41 64 20 5 14 41 10 37 51 32 65 46 61 8 15 19 16 44 31 42 19 46 66 25 26 58 60 5 19 18 69 53 20 40 45 27 24 41 32 23 57 56 62 10", "output": "62 18 35 7 70 23 61 56 34 22 42 58 6 66 10 37 21 2 38 13 69 29 14 42 48 7 29 5 50 66 60 29 63 35 20 38 4 23 10 65 58 52 57 27 41 28 52 23 2 46 45 14 12 66 52 55 1 19 50 33 26 44 47 29 38 48 16 17 7 63" }, { "input": "5\n1 2000 1 1 2000", "output": "3 1 3 3 1" } ]
1,627,568,519
2,147,483,647
Python 3
OK
TESTS
36
93
8,089,600
from collections import defaultdict from typing import Counter n = int(input()) a = [int(x) for x in input().split()] d = defaultdict(list) for i in range(n): d[a[i]].append(i) l = sorted(d.items(), key=lambda x: -x[0]) p = 1 ans = [0 for _ in range(n)] for t in l: for idx in t[1]: ans[idx] = p p += len(t[1]) print(' '.join(map(str, ans)))
Title: GukiZ and Contest Time Limit: None seconds Memory Limit: None megabytes Problem Description: Professor GukiZ likes programming contests. He especially likes to rate his students on the contests he prepares. Now, he has decided to prepare a new contest. In total, *n* students will attend, and before the start, every one of them has some positive integer rating. Students are indexed from 1 to *n*. Let's denote the rating of *i*-th student as *a**i*. After the contest ends, every student will end up with some positive integer position. GukiZ expects that his students will take places according to their ratings. He thinks that each student will take place equal to . In particular, if student *A* has rating strictly lower then student *B*, *A* will get the strictly better position than *B*, and if two students have equal ratings, they will share the same position. GukiZ would like you to reconstruct the results by following his expectations. Help him and determine the position after the end of the contest for each of his students if everything goes as expected. Input Specification: The first line contains integer *n* (1<=≤<=*n*<=≤<=2000), number of GukiZ's students. The second line contains *n* numbers *a*1,<=*a*2,<=... *a**n* (1<=≤<=*a**i*<=≤<=2000) where *a**i* is the rating of *i*-th student (1<=≤<=*i*<=≤<=*n*). Output Specification: In a single line, print the position after the end of the contest for each of *n* students in the same order as they appear in the input. Demo Input: ['3\n1 3 3\n', '1\n1\n', '5\n3 5 3 4 5\n'] Demo Output: ['3 1 1\n', '1\n', '4 1 4 3 1\n'] Note: In the first sample, students 2 and 3 are positioned first (there is no other student with higher rating), and student 1 is positioned third since there are two students with higher rating. In the second sample, first student is the only one on the contest. In the third sample, students 2 and 5 share the first position with highest rating, student 4 is next with third position, and students 1 and 3 are the last sharing fourth position.
```python from collections import defaultdict from typing import Counter n = int(input()) a = [int(x) for x in input().split()] d = defaultdict(list) for i in range(n): d[a[i]].append(i) l = sorted(d.items(), key=lambda x: -x[0]) p = 1 ans = [0 for _ in range(n)] for t in l: for idx in t[1]: ans[idx] = p p += len(t[1]) print(' '.join(map(str, ans))) ```
3
673
A
Bear and Game
PROGRAMMING
800
[ "implementation" ]
null
null
Bear Limak likes watching sports on TV. He is going to watch a game today. The game lasts 90 minutes and there are no breaks. Each minute can be either interesting or boring. If 15 consecutive minutes are boring then Limak immediately turns TV off. You know that there will be *n* interesting minutes *t*1,<=*t*2,<=...,<=*t**n*. Your task is to calculate for how many minutes Limak will watch the game.
The first line of the input contains one integer *n* (1<=≤<=*n*<=≤<=90) — the number of interesting minutes. The second line contains *n* integers *t*1,<=*t*2,<=...,<=*t**n* (1<=≤<=*t*1<=&lt;<=*t*2<=&lt;<=... *t**n*<=≤<=90), given in the increasing order.
Print the number of minutes Limak will watch the game.
[ "3\n7 20 88\n", "9\n16 20 30 40 50 60 70 80 90\n", "9\n15 20 30 40 50 60 70 80 90\n" ]
[ "35\n", "15\n", "90\n" ]
In the first sample, minutes 21, 22, ..., 35 are all boring and thus Limak will turn TV off immediately after the 35-th minute. So, he would watch the game for 35 minutes. In the second sample, the first 15 minutes are boring. In the third sample, there are no consecutive 15 boring minutes. So, Limak will watch the whole game.
500
[ { "input": "3\n7 20 88", "output": "35" }, { "input": "9\n16 20 30 40 50 60 70 80 90", "output": "15" }, { "input": "9\n15 20 30 40 50 60 70 80 90", "output": "90" }, { "input": "30\n6 11 12 15 22 24 30 31 32 33 34 35 40 42 44 45 47 50 53 54 57 58 63 67 75 77 79 81 83 88", "output": "90" }, { "input": "60\n1 2 4 5 6 7 11 14 16 18 20 21 22 23 24 25 26 33 34 35 36 37 38 39 41 42 43 44 46 47 48 49 52 55 56 57 58 59 60 61 63 64 65 67 68 70 71 72 73 74 75 77 78 80 82 83 84 85 86 88", "output": "90" }, { "input": "90\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", "output": "90" }, { "input": "1\n1", "output": "16" }, { "input": "5\n15 30 45 60 75", "output": "90" }, { "input": "6\n14 29 43 59 70 74", "output": "58" }, { "input": "1\n15", "output": "30" }, { "input": "1\n16", "output": "15" }, { "input": "14\n14 22 27 31 35 44 46 61 62 69 74 79 88 89", "output": "90" }, { "input": "76\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 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", "output": "90" }, { "input": "1\n90", "output": "15" }, { "input": "6\n13 17 32 47 60 66", "output": "81" }, { "input": "84\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", "output": "90" }, { "input": "9\n6 20 27 28 40 53 59 70 85", "output": "90" }, { "input": "12\n14 22 27 31 35 44 62 69 74 79 88 89", "output": "59" }, { "input": "5\n15 30 45 60 74", "output": "89" }, { "input": "72\n3 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 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", "output": "54" }, { "input": "8\n1 16 30 31 32 33 34 50", "output": "49" }, { "input": "12\n1 3 6 10 15 21 28 36 45 55 66 78", "output": "90" }, { "input": "25\n1 2 3 4 5 6 7 8 9 10 11 23 36 50 65 81 82 83 84 85 86 87 88 89 90", "output": "80" }, { "input": "8\n5 17 20 35 42 53 67 76", "output": "90" }, { "input": "9\n15 28 39 48 55 60 63 64 74", "output": "89" }, { "input": "10\n15 28 39 48 55 60 63 64 74 82", "output": "90" }, { "input": "2\n1 18", "output": "16" }, { "input": "9\n10 20 30 40 50 60 70 80 84", "output": "90" }, { "input": "2\n16 50", "output": "15" }, { "input": "6\n15 30 45 60 75 84", "output": "90" }, { "input": "8\n15 20 30 40 50 60 73 83", "output": "90" }, { "input": "8\n10 20 30 40 50 60 70 80", "output": "90" }, { "input": "3\n1 20 90", "output": "16" }, { "input": "6\n15 30 45 60 74 89", "output": "90" } ]
1,583,914,398
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
3
108
0
def countTotalWatchingTime(ar): totalMin = 0 for time in ar: if time - totalMin > 15: return min(totalMin + 15, 90) else: totalMin = time return min(totalMin, 90) n = int(input()) ar = list(map(int, input().split())) print(countTotalWatchingTime(ar))
Title: Bear and Game Time Limit: None seconds Memory Limit: None megabytes Problem Description: Bear Limak likes watching sports on TV. He is going to watch a game today. The game lasts 90 minutes and there are no breaks. Each minute can be either interesting or boring. If 15 consecutive minutes are boring then Limak immediately turns TV off. You know that there will be *n* interesting minutes *t*1,<=*t*2,<=...,<=*t**n*. Your task is to calculate for how many minutes Limak will watch the game. Input Specification: The first line of the input contains one integer *n* (1<=≤<=*n*<=≤<=90) — the number of interesting minutes. The second line contains *n* integers *t*1,<=*t*2,<=...,<=*t**n* (1<=≤<=*t*1<=&lt;<=*t*2<=&lt;<=... *t**n*<=≤<=90), given in the increasing order. Output Specification: Print the number of minutes Limak will watch the game. Demo Input: ['3\n7 20 88\n', '9\n16 20 30 40 50 60 70 80 90\n', '9\n15 20 30 40 50 60 70 80 90\n'] Demo Output: ['35\n', '15\n', '90\n'] Note: In the first sample, minutes 21, 22, ..., 35 are all boring and thus Limak will turn TV off immediately after the 35-th minute. So, he would watch the game for 35 minutes. In the second sample, the first 15 minutes are boring. In the third sample, there are no consecutive 15 boring minutes. So, Limak will watch the whole game.
```python def countTotalWatchingTime(ar): totalMin = 0 for time in ar: if time - totalMin > 15: return min(totalMin + 15, 90) else: totalMin = time return min(totalMin, 90) n = int(input()) ar = list(map(int, input().split())) print(countTotalWatchingTime(ar)) ```
0
665
C
Simple Strings
PROGRAMMING
1,300
[ "dp", "greedy", "strings" ]
null
null
zscoder loves simple strings! A string *t* is called simple if every pair of adjacent characters are distinct. For example ab, aba, zscoder are simple whereas aa, add are not simple. zscoder is given a string *s*. He wants to change a minimum number of characters so that the string *s* becomes simple. Help him with this task!
The only line contains the string *s* (1<=≤<=|*s*|<=≤<=2·105) — the string given to zscoder. The string *s* consists of only lowercase English letters.
Print the simple string *s*' — the string *s* after the minimal number of changes. If there are multiple solutions, you may output any of them. Note that the string *s*' should also consist of only lowercase English letters.
[ "aab\n", "caaab\n", "zscoder\n" ]
[ "bab\n", "cabab\n", "zscoder\n" ]
none
0
[ { "input": "aab", "output": "bab" }, { "input": "caaab", "output": "cabab" }, { "input": "zscoder", "output": "zscoder" }, { "input": "u", "output": "u" }, { "input": "h", "output": "h" }, { "input": "dtottttotd", "output": "dtotataotd" }, { "input": "rxxxrrxrxxxxxrrrrrxxxxrrrrxrxxrxxrxrxrrrxrrxrrxrxxxrxrrxrrxrxrxxxxxrxxxxrrrxrxxrxxrxxxrrrrrxrrxrrxrr", "output": "rxaxraxrxaxaxrararxaxararaxrxarxarxrxrarxraxraxrxaxrxraxraxrxrxaxaxrxaxararxrxarxarxaxrararxraxraxra" }, { "input": "aazz", "output": "baza" }, { "input": "zz", "output": "za" }, { "input": "gg", "output": "ga" }, { "input": "qasdasd", "output": "qasdasd" }, { "input": "aa", "output": "ba" }, { "input": "ab", "output": "ab" }, { "input": "zza", "output": "zba" }, { "input": "g", "output": "g" }, { "input": "nnop", "output": "naop" }, { "input": "xx", "output": "xa" } ]
1,631,679,033
2,147,483,647
PyPy 3
TIME_LIMIT_EXCEEDED
TESTS
9
2,000
32,768,000
p = {'a','b','c'} s=input();t=len(s) ans=s[0] for x in range(1,t): if ans[-1] == s[x]: if x+1 !=t: ans+=(p-{ans[-1],s[x+1]}).pop() else: ans+=(p-{ans[-1]}).pop() else: ans+=s[x] print(ans)
Title: Simple Strings Time Limit: None seconds Memory Limit: None megabytes Problem Description: zscoder loves simple strings! A string *t* is called simple if every pair of adjacent characters are distinct. For example ab, aba, zscoder are simple whereas aa, add are not simple. zscoder is given a string *s*. He wants to change a minimum number of characters so that the string *s* becomes simple. Help him with this task! Input Specification: The only line contains the string *s* (1<=≤<=|*s*|<=≤<=2·105) — the string given to zscoder. The string *s* consists of only lowercase English letters. Output Specification: Print the simple string *s*' — the string *s* after the minimal number of changes. If there are multiple solutions, you may output any of them. Note that the string *s*' should also consist of only lowercase English letters. Demo Input: ['aab\n', 'caaab\n', 'zscoder\n'] Demo Output: ['bab\n', 'cabab\n', 'zscoder\n'] Note: none
```python p = {'a','b','c'} s=input();t=len(s) ans=s[0] for x in range(1,t): if ans[-1] == s[x]: if x+1 !=t: ans+=(p-{ans[-1],s[x+1]}).pop() else: ans+=(p-{ans[-1]}).pop() else: ans+=s[x] print(ans) ```
0
58
A
Chat room
PROGRAMMING
1,000
[ "greedy", "strings" ]
A. Chat room
1
256
Vasya has recently learned to type and log on to the Internet. He immediately entered a chat room and decided to say hello to everybody. Vasya typed the word *s*. It is considered that Vasya managed to say hello if several letters can be deleted from the typed word so that it resulted in the word "hello". For example, if Vasya types the word "ahhellllloou", it will be considered that he said hello, and if he types "hlelo", it will be considered that Vasya got misunderstood and he didn't manage to say hello. Determine whether Vasya managed to say hello by the given word *s*.
The first and only line contains the word *s*, which Vasya typed. This word consisits of small Latin letters, its length is no less that 1 and no more than 100 letters.
If Vasya managed to say hello, print "YES", otherwise print "NO".
[ "ahhellllloou\n", "hlelo\n" ]
[ "YES\n", "NO\n" ]
none
500
[ { "input": "ahhellllloou", "output": "YES" }, { "input": "hlelo", "output": "NO" }, { "input": "helhcludoo", "output": "YES" }, { "input": "hehwelloho", "output": "YES" }, { "input": "pnnepelqomhhheollvlo", "output": "YES" }, { "input": "tymbzjyqhymedasloqbq", "output": "NO" }, { "input": "yehluhlkwo", "output": "NO" }, { "input": "hatlevhhalrohairnolsvocafgueelrqmlqlleello", "output": "YES" }, { "input": "hhhtehdbllnhwmbyhvelqqyoulretpbfokflhlhreeflxeftelziclrwllrpflflbdtotvlqgoaoqldlroovbfsq", "output": "YES" }, { "input": "rzlvihhghnelqtwlexmvdjjrliqllolhyewgozkuovaiezgcilelqapuoeglnwmnlftxxiigzczlouooi", "output": "YES" }, { "input": "pfhhwctyqdlkrwhebfqfelhyebwllhemtrmeblgrynmvyhioesqklclocxmlffuormljszllpoo", "output": "YES" }, { "input": "lqllcolohwflhfhlnaow", "output": "NO" }, { "input": "heheeellollvoo", "output": "YES" }, { "input": "hellooo", "output": "YES" }, { "input": "o", "output": "NO" }, { "input": "hhqhzeclohlehljlhtesllylrolmomvuhcxsobtsckogdv", "output": "YES" }, { "input": "yoegfuzhqsihygnhpnukluutocvvwuldiighpogsifealtgkfzqbwtmgghmythcxflebrkctlldlkzlagovwlstsghbouk", "output": "YES" }, { "input": "uatqtgbvrnywfacwursctpagasnhydvmlinrcnqrry", "output": "NO" }, { "input": "tndtbldbllnrwmbyhvqaqqyoudrstpbfokfoclnraefuxtftmgzicorwisrpfnfpbdtatvwqgyalqtdtrjqvbfsq", "output": "NO" }, { "input": "rzlvirhgemelnzdawzpaoqtxmqucnahvqnwldklrmjiiyageraijfivigvozgwngiulttxxgzczptusoi", "output": "YES" }, { "input": "kgyelmchocojsnaqdsyeqgnllytbqietpdlgknwwumqkxrexgdcnwoldicwzwofpmuesjuxzrasscvyuqwspm", "output": "YES" }, { "input": "pnyvrcotjvgynbeldnxieghfltmexttuxzyac", "output": "NO" }, { "input": "dtwhbqoumejligbenxvzhjlhosqojetcqsynlzyhfaevbdpekgbtjrbhlltbceobcok", "output": "YES" }, { "input": "crrfpfftjwhhikwzeedrlwzblckkteseofjuxjrktcjfsylmlsvogvrcxbxtffujqshslemnixoeezivksouefeqlhhokwbqjz", "output": "YES" }, { "input": "jhfbndhyzdvhbvhmhmefqllujdflwdpjbehedlsqfdsqlyelwjtyloxwsvasrbqosblzbowlqjmyeilcvotdlaouxhdpoeloaovb", "output": "YES" }, { "input": "hwlghueoemiqtjhhpashjsouyegdlvoyzeunlroypoprnhlyiwiuxrghekaylndhrhllllwhbebezoglydcvykllotrlaqtvmlla", "output": "YES" }, { "input": "wshiaunnqnqxodholbipwhhjmyeblhgpeleblklpzwhdunmpqkbuzloetmwwxmeltkrcomulxauzlwmlklldjodozxryghsnwgcz", "output": "YES" }, { "input": "shvksednttggehroewuiptvvxtrzgidravtnjwuqrlnnkxbplctzkckinpkgjopjfoxdbojtcvsuvablcbkrzajrlhgobkcxeqti", "output": "YES" }, { "input": "hyyhddqhxhekehkwfhlnlsihzefwchzerevcjtokefplholrbvxlltdlafjxrfhleglrvlolojoqaolagtbeyogxlbgfolllslli", "output": "YES" }, { "input": "iaagrdhhelxpdegueiulflquvlzidoprzkehthkldaytrjwhyhprwjxlltinxvuilxohqgjqcvkkdcuoliekcnlilwgqlnlzouoo", "output": "YES" }, { "input": "wfluaeseldgxyvxpwuhkptdmlflnlhktwxiabsvkolsquymrmhzczzoybvlilhmvsuunggvgxzgyyffk", "output": "NO" }, { "input": "loee", "output": "NO" }, { "input": "izdipwylefqmjbuoznfglgcfvedeouflkeehxbasaqmiooppfsqlhprospqgxvzrcpwlfdddngoqvpwvggsnvvxhmjoslwjudjlo", "output": "NO" }, { "input": "pplynflbjlseflaegzqpdxswgunhnlglqhycrbcwdfhclmcrwekkzsoosmfblljeenwfjyifcvxihhhbyhmhlkvtskeglaovjnsi", "output": "YES" }, { "input": "xqjqmenkodmlhzyzmmvofdngktygbbxbzpluzcohohmalkoeuwfikblltaaigv", "output": "NO" }, { "input": "hello", "output": "YES" }, { "input": "oohell", "output": "NO" }, { "input": "hell", "output": "NO" }, { "input": "eloellohoelo", "output": "NO" }, { "input": "helllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllo", "output": "YES" } ]
1,591,121,253
2,147,483,647
Python 3
RUNTIME_ERROR
TESTS
1
93
307,200
x = input() h = x.count('h') e = x.count('e') l = x.count('l') o = x.count('o') H = x.count('H') E = x.count('E') L = x.count('L') O = x.count('O') if ((h>0 or H>0) and (e>0 or E>0) and (l>1 or L>1) and (o>0 or O>0) and (x.index('h') or x.index('H'))< (x.index('e') or x.index('E'))<(x.index('l') or x.index('L'))<(x.index('o') or x.index('O'))): print('YES') else: print('NO')
Title: Chat room Time Limit: 1 seconds Memory Limit: 256 megabytes Problem Description: Vasya has recently learned to type and log on to the Internet. He immediately entered a chat room and decided to say hello to everybody. Vasya typed the word *s*. It is considered that Vasya managed to say hello if several letters can be deleted from the typed word so that it resulted in the word "hello". For example, if Vasya types the word "ahhellllloou", it will be considered that he said hello, and if he types "hlelo", it will be considered that Vasya got misunderstood and he didn't manage to say hello. Determine whether Vasya managed to say hello by the given word *s*. Input Specification: The first and only line contains the word *s*, which Vasya typed. This word consisits of small Latin letters, its length is no less that 1 and no more than 100 letters. Output Specification: If Vasya managed to say hello, print "YES", otherwise print "NO". Demo Input: ['ahhellllloou\n', 'hlelo\n'] Demo Output: ['YES\n', 'NO\n'] Note: none
```python x = input() h = x.count('h') e = x.count('e') l = x.count('l') o = x.count('o') H = x.count('H') E = x.count('E') L = x.count('L') O = x.count('O') if ((h>0 or H>0) and (e>0 or E>0) and (l>1 or L>1) and (o>0 or O>0) and (x.index('h') or x.index('H'))< (x.index('e') or x.index('E'))<(x.index('l') or x.index('L'))<(x.index('o') or x.index('O'))): print('YES') else: print('NO') ```
-1
371
C
Hamburgers
PROGRAMMING
1,600
[ "binary search", "brute force" ]
null
null
Polycarpus loves hamburgers very much. He especially adores the hamburgers he makes with his own hands. Polycarpus thinks that there are only three decent ingredients to make hamburgers from: a bread, sausage and cheese. He writes down the recipe of his favorite "Le Hamburger de Polycarpus" as a string of letters 'B' (bread), 'S' (sausage) и 'C' (cheese). The ingredients in the recipe go from bottom to top, for example, recipe "ВSCBS" represents the hamburger where the ingredients go from bottom to top as bread, sausage, cheese, bread and sausage again. Polycarpus has *n**b* pieces of bread, *n**s* pieces of sausage and *n**c* pieces of cheese in the kitchen. Besides, the shop nearby has all three ingredients, the prices are *p**b* rubles for a piece of bread, *p**s* for a piece of sausage and *p**c* for a piece of cheese. Polycarpus has *r* rubles and he is ready to shop on them. What maximum number of hamburgers can he cook? You can assume that Polycarpus cannot break or slice any of the pieces of bread, sausage or cheese. Besides, the shop has an unlimited number of pieces of each ingredient.
The first line of the input contains a non-empty string that describes the recipe of "Le Hamburger de Polycarpus". The length of the string doesn't exceed 100, the string contains only letters 'B' (uppercase English B), 'S' (uppercase English S) and 'C' (uppercase English C). The second line contains three integers *n**b*, *n**s*, *n**c* (1<=≤<=*n**b*,<=*n**s*,<=*n**c*<=≤<=100) — the number of the pieces of bread, sausage and cheese on Polycarpus' kitchen. The third line contains three integers *p**b*, *p**s*, *p**c* (1<=≤<=*p**b*,<=*p**s*,<=*p**c*<=≤<=100) — the price of one piece of bread, sausage and cheese in the shop. Finally, the fourth line contains integer *r* (1<=≤<=*r*<=≤<=1012) — the number of rubles Polycarpus has. Please, do not write the %lld specifier to read or write 64-bit integers in С++. It is preferred to use the cin, cout streams or the %I64d specifier.
Print the maximum number of hamburgers Polycarpus can make. If he can't make any hamburger, print 0.
[ "BBBSSC\n6 4 1\n1 2 3\n4\n", "BBC\n1 10 1\n1 10 1\n21\n", "BSC\n1 1 1\n1 1 3\n1000000000000\n" ]
[ "2\n", "7\n", "200000000001\n" ]
none
1,500
[ { "input": "BBBSSC\n6 4 1\n1 2 3\n4", "output": "2" }, { "input": "BBC\n1 10 1\n1 10 1\n21", "output": "7" }, { "input": "BSC\n1 1 1\n1 1 3\n1000000000000", "output": "200000000001" }, { "input": "B\n1 1 1\n1 1 1\n381", "output": "382" }, { "input": "BSC\n3 5 6\n7 3 9\n100", "output": "10" }, { "input": "BSC\n100 1 1\n100 1 1\n100", "output": "51" }, { "input": "SBBCCSBB\n1 50 100\n31 59 21\n100000", "output": "370" }, { "input": "BBBBCCCCCCCCCCCCCCCCCCCCSSSSBBBBBBBBSS\n100 100 100\n1 1 1\n3628800", "output": "95502" }, { "input": "BBBBBBBBBBCCCCCCCCCCCCCCCCCCCCSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSS\n10 20 40\n100 100 100\n200", "output": "0" }, { "input": "BBBBBBBBBBCCCCCCCCCCCCCCCCCCCCSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSS\n10 20 40\n100 100 100\n2000", "output": "1" }, { "input": "BBBBBBBBBBCCCCCCCCCCCCCCCCCCCCSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSS\n10 20 40\n100 100 100\n300", "output": "0" }, { "input": "BBBBBBBBBBCCCCCCCCCCCCCCCCCCCCSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSS\n10 20 40\n100 100 100\n300000000", "output": "42858" }, { "input": "BBBBBBBBBBCCCCCCCCCCCCCCCCCCCCSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSS\n10 20 40\n100 100 100\n914159265358", "output": "130594181" }, { "input": "SSSSSSSSSSBBBBBBBBBCCCCCCCCCCCCCCCCCCCSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSBB\n31 53 97\n13 17 31\n914159265358", "output": "647421579" }, { "input": "BBBCSBSBBSSSSCCCCBBCSBBBBSSBBBCBSCCSSCSSCSBSSSCCCCBSCSSBSSSCCCBBCCCSCBCBBCCSCCCCSBBCCBBBBCCCCCCBSSCB\n91 87 17\n64 44 43\n958532915587", "output": "191668251" }, { "input": "CSSCBBCCCSBSCBBBCSBBBCBSBCSCBCSCBCBSBCBCSSBBSBBCBBBBSCSBBCCBCCBCBBSBSBCSCSBBSSBBCSSBCSCSCCSSBCBBCBSB\n56 34 48\n78 6 96\n904174875419", "output": "140968956" }, { "input": "CCSCCCSBBBSCBSCSCCSSBBBSSBBBSBBBCBCSSBCSCBBCCCBCBCBCCCSSBSBBCCCCCBBSCBSCBCBBCBBCSSBCSBSSCCSCCSCCBBBS\n33 73 67\n4 56 42\n886653164314", "output": "277425898" }, { "input": "SBCSSCBBSSBCSSBBBSSBSCBSSSCBBSBBBBCSBCSBSCBSCBSCBSBSSCCCCBSBCCBCBSCCCBSCCBSBBCBSSCCCCSBSBBBSSSBCSCBC\n94 16 85\n14 18 91\n836590091442", "output": "217522127" }, { "input": "BSCSBSCCSCSSCCCSBCSSBCBBSCCBSCCSSSSSSSSSCCSBSCCBBCBBSBSCCCCBCSBSBSSBBBBBSSBSSCBCCSSBSSSCBBCSBBSBCCCB\n67 54 8\n36 73 37\n782232051273", "output": "154164772" }, { "input": "CBBCBSBCCSCBSSCCBCSBCSBBSCBBCSCCBSCCSCSBBSSBSBSCBBSBBCSSSSBBBBSBBCBCSBBCBCSSBBCSBSCCSCSBCSCBSCCBBCSC\n71 71 52\n52 88 3\n654400055575", "output": "137826467" }, { "input": "CBBCBSBCCSCBSSCCBCSBCSBBSCBBCSCCBSCCSCSBBSBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBCBBCSC\n100 1 1\n1 17 23\n954400055575", "output": "1355681897" }, { "input": "C\n100 100 100\n1 1 1\n1000000000000", "output": "1000000000100" }, { "input": "SSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSS\n100 100 100\n100 100 100\n1000000000000", "output": "100000001" }, { "input": "B\n100 100 100\n1 1 1\n1", "output": "101" }, { "input": "SC\n2 1 1\n1 1 1\n100000000000", "output": "50000000001" }, { "input": "B\n100 1 1\n1 1 1\n1000000000000", "output": "1000000000100" }, { "input": "BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB\n1 1 1\n100 100 100\n1000000000000", "output": "100000000" }, { "input": "CC\n1 1 1\n100 100 100\n1", "output": "0" }, { "input": "B\n100 100 100\n1 1 1\n1000000000000", "output": "1000000000100" }, { "input": "BSC\n100 100 100\n1 1 1\n1000000000000", "output": "333333333433" }, { "input": "BSC\n100 100 100\n1 1 1\n1", "output": "100" } ]
1,674,225,531
2,147,483,647
PyPy 3-64
OK
TESTS
31
62
0
s=input() dic={"B":0,"S":0,"C":0} nb,ns,nc=[int(i) for i in input().split()] pb,ps,pc=[int(i) for i in input().split()] amount=int(input()) low=0 high=10**17 for i in s: dic[i]+=1 while low <= high: mid=(high+low)//2 burger=mid*dic["B"] - nb sausage=mid*dic["S"]-ns cheese=mid*dic["C"]-nc cost=max(0,burger)*pb+max(0,sausage)*ps+max(0,cheese)*pc if cost <= amount: low=mid+1 else: high=mid-1 print(high)
Title: Hamburgers Time Limit: None seconds Memory Limit: None megabytes Problem Description: Polycarpus loves hamburgers very much. He especially adores the hamburgers he makes with his own hands. Polycarpus thinks that there are only three decent ingredients to make hamburgers from: a bread, sausage and cheese. He writes down the recipe of his favorite "Le Hamburger de Polycarpus" as a string of letters 'B' (bread), 'S' (sausage) и 'C' (cheese). The ingredients in the recipe go from bottom to top, for example, recipe "ВSCBS" represents the hamburger where the ingredients go from bottom to top as bread, sausage, cheese, bread and sausage again. Polycarpus has *n**b* pieces of bread, *n**s* pieces of sausage and *n**c* pieces of cheese in the kitchen. Besides, the shop nearby has all three ingredients, the prices are *p**b* rubles for a piece of bread, *p**s* for a piece of sausage and *p**c* for a piece of cheese. Polycarpus has *r* rubles and he is ready to shop on them. What maximum number of hamburgers can he cook? You can assume that Polycarpus cannot break or slice any of the pieces of bread, sausage or cheese. Besides, the shop has an unlimited number of pieces of each ingredient. Input Specification: The first line of the input contains a non-empty string that describes the recipe of "Le Hamburger de Polycarpus". The length of the string doesn't exceed 100, the string contains only letters 'B' (uppercase English B), 'S' (uppercase English S) and 'C' (uppercase English C). The second line contains three integers *n**b*, *n**s*, *n**c* (1<=≤<=*n**b*,<=*n**s*,<=*n**c*<=≤<=100) — the number of the pieces of bread, sausage and cheese on Polycarpus' kitchen. The third line contains three integers *p**b*, *p**s*, *p**c* (1<=≤<=*p**b*,<=*p**s*,<=*p**c*<=≤<=100) — the price of one piece of bread, sausage and cheese in the shop. Finally, the fourth line contains integer *r* (1<=≤<=*r*<=≤<=1012) — the number of rubles Polycarpus has. Please, do not write the %lld specifier to read or write 64-bit integers in С++. It is preferred to use the cin, cout streams or the %I64d specifier. Output Specification: Print the maximum number of hamburgers Polycarpus can make. If he can't make any hamburger, print 0. Demo Input: ['BBBSSC\n6 4 1\n1 2 3\n4\n', 'BBC\n1 10 1\n1 10 1\n21\n', 'BSC\n1 1 1\n1 1 3\n1000000000000\n'] Demo Output: ['2\n', '7\n', '200000000001\n'] Note: none
```python s=input() dic={"B":0,"S":0,"C":0} nb,ns,nc=[int(i) for i in input().split()] pb,ps,pc=[int(i) for i in input().split()] amount=int(input()) low=0 high=10**17 for i in s: dic[i]+=1 while low <= high: mid=(high+low)//2 burger=mid*dic["B"] - nb sausage=mid*dic["S"]-ns cheese=mid*dic["C"]-nc cost=max(0,burger)*pb+max(0,sausage)*ps+max(0,cheese)*pc if cost <= amount: low=mid+1 else: high=mid-1 print(high) ```
3
369
A
Valera and Plates
PROGRAMMING
900
[ "greedy", "implementation" ]
null
null
Valera is a lazy student. He has *m* clean bowls and *k* clean plates. Valera has made an eating plan for the next *n* days. As Valera is lazy, he will eat exactly one dish per day. At that, in order to eat a dish, he needs exactly one clean plate or bowl. We know that Valera can cook only two types of dishes. He can eat dishes of the first type from bowls and dishes of the second type from either bowls or plates. When Valera finishes eating, he leaves a dirty plate/bowl behind. His life philosophy doesn't let him eat from dirty kitchenware. So sometimes he needs to wash his plate/bowl before eating. Find the minimum number of times Valera will need to wash a plate/bowl, if he acts optimally.
The first line of the input contains three integers *n*, *m*, *k* (1<=≤<=*n*,<=*m*,<=*k*<=≤<=1000) — the number of the planned days, the number of clean bowls and the number of clean plates. The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=2). If *a**i* equals one, then on day *i* Valera will eat a first type dish. If *a**i* equals two, then on day *i* Valera will eat a second type dish.
Print a single integer — the minimum number of times Valera will need to wash a plate/bowl.
[ "3 1 1\n1 2 1\n", "4 3 1\n1 1 1 1\n", "3 1 2\n2 2 2\n", "8 2 2\n1 2 1 2 1 2 1 2\n" ]
[ "1\n", "1\n", "0\n", "4\n" ]
In the first sample Valera will wash a bowl only on the third day, so the answer is one. In the second sample, Valera will have the first type of the dish during all four days, and since there are only three bowls, he will wash a bowl exactly once. In the third sample, Valera will have the second type of dish for all three days, and as they can be eaten from either a plate or a bowl, he will never need to wash a plate/bowl.
500
[ { "input": "3 1 1\n1 2 1", "output": "1" }, { "input": "4 3 1\n1 1 1 1", "output": "1" }, { "input": "3 1 2\n2 2 2", "output": "0" }, { "input": "8 2 2\n1 2 1 2 1 2 1 2", "output": "4" }, { "input": "2 100 100\n2 2", "output": "0" }, { "input": "1 1 1\n2", "output": "0" }, { "input": "233 100 1\n2 2 1 1 1 2 2 2 2 1 1 2 2 2 1 2 2 1 1 1 2 2 1 1 1 1 2 1 2 2 1 1 2 2 1 2 2 1 2 1 2 1 2 2 2 1 1 1 1 2 1 2 1 1 2 1 1 2 2 1 2 1 2 1 1 1 1 1 1 1 1 1 2 1 2 2 2 1 1 2 2 1 1 1 1 2 1 1 2 1 2 2 2 1 1 1 2 2 2 1 1 1 1 2 1 2 1 1 1 1 2 2 2 1 1 2 1 2 1 1 1 1 1 2 1 1 1 1 1 2 1 1 2 2 1 2 1 1 2 2 1 1 2 2 1 1 1 2 2 1 1 2 1 2 1 2 2 1 2 2 2 2 2 1 2 2 2 2 2 1 2 2 1 2 2 1 1 1 2 2 1 1 2 2 1 1 2 1 1 2 2 1 2 2 2 2 2 2 1 2 2 2 2 2 1 1 2 2 2 2 2 2 1 1 1 2 1 2 2 2 2 2 2 2 2 1 1 2 1 2 1 2 2", "output": "132" }, { "input": "123 100 1\n2 2 2 1 1 2 2 2 2 1 1 2 2 2 1 2 2 2 2 1 2 2 2 1 1 1 2 2 2 2 1 2 2 2 2 2 2 1 2 1 2 1 2 2 2 1 2 1 2 2 1 2 2 1 2 2 1 2 2 1 2 2 2 1 1 1 1 1 1 1 1 1 2 2 2 2 2 1 1 2 2 1 1 1 1 2 1 2 2 1 2 2 2 1 1 1 2 2 2 1 2 2 2 2 1 2 2 2 2 1 2 2 2 1 1 2 1 2 1 2 1 1 1", "output": "22" }, { "input": "188 100 1\n2 2 1 1 1 2 2 2 2 1 1 2 2 2 1 2 2 1 1 1 2 2 1 1 1 1 2 1 2 2 1 1 2 2 1 2 2 1 2 1 2 1 2 2 2 1 1 1 1 2 1 2 1 1 2 1 1 2 2 1 2 1 2 1 1 1 1 1 1 1 1 1 2 1 2 2 2 1 1 2 2 1 1 1 1 2 1 1 2 1 2 2 2 1 1 1 2 2 2 1 1 1 1 2 1 2 1 1 1 1 2 2 2 1 1 2 1 2 1 1 1 1 1 2 1 1 1 1 1 2 1 1 2 2 1 2 1 1 2 2 1 1 2 2 1 1 1 2 2 1 1 2 1 2 1 2 2 1 2 2 2 2 2 1 2 2 2 2 2 1 2 2 1 2 2 1 1 1 2 2 1 1 2 2 1 1 2 1", "output": "87" }, { "input": "3 1 2\n1 1 1", "output": "2" }, { "input": "3 2 2\n1 1 1", "output": "1" }, { "input": "3 2 1\n1 1 1", "output": "1" }, { "input": "3 1 1\n1 1 1", "output": "2" }, { "input": "5 1 2\n2 2 2 2 2", "output": "2" }, { "input": "5 2 2\n2 2 2 2 2", "output": "1" }, { "input": "5 2 1\n2 2 2 2 2", "output": "2" }, { "input": "5 1 1\n2 2 2 2 2", "output": "3" }, { "input": "1 1 2\n2", "output": "0" }, { "input": "1 2 2\n2", "output": "0" }, { "input": "1 2 1\n2", "output": "0" }, { "input": "1 1 1\n2", "output": "0" }, { "input": "6 3 1\n1 1 2 2 2 2", "output": "2" }, { "input": "100 40 20\n2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 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", "output": "40" }, { "input": "7 5 2\n2 2 1 1 1 1 1", "output": "0" }, { "input": "10 4 4\n2 2 2 2 2 2 1 1 1 1", "output": "2" }, { "input": "3 2 1\n2 1 1", "output": "0" }, { "input": "7 6 1\n2 1 1 1 1 1 1", "output": "0" }, { "input": "7 5 1\n1 1 1 2 2 2 2", "output": "1" }, { "input": "5 3 1\n1 1 2 2 2", "output": "1" }, { "input": "3 1 1\n2 2 2", "output": "1" }, { "input": "5 2 2\n2 2 2 2 2", "output": "1" }, { "input": "3 1 3\n1 1 1", "output": "2" }, { "input": "5 2 1\n1 1 2 2 2", "output": "2" }, { "input": "4 3 2\n2 1 1 1", "output": "0" }, { "input": "4 2 1\n1 2 2 2", "output": "1" }, { "input": "14 4 7\n1 1 1 2 2 2 2 2 2 2 2 2 2 2", "output": "3" }, { "input": "12 10 4\n2 2 2 2 2 2 1 1 1 1 1 1", "output": "0" }, { "input": "5 3 2\n2 2 1 1 1", "output": "0" } ]
1,605,978,913
2,147,483,647
Python 3
OK
TESTS
63
202
0
# cook your dish here n, b, p = map(int,input().split()) ls = list(map(int, input().split())) ans = n - min(ls.count(2), p) - b if ans<=0: print(0) else: print(ans)
Title: Valera and Plates Time Limit: None seconds Memory Limit: None megabytes Problem Description: Valera is a lazy student. He has *m* clean bowls and *k* clean plates. Valera has made an eating plan for the next *n* days. As Valera is lazy, he will eat exactly one dish per day. At that, in order to eat a dish, he needs exactly one clean plate or bowl. We know that Valera can cook only two types of dishes. He can eat dishes of the first type from bowls and dishes of the second type from either bowls or plates. When Valera finishes eating, he leaves a dirty plate/bowl behind. His life philosophy doesn't let him eat from dirty kitchenware. So sometimes he needs to wash his plate/bowl before eating. Find the minimum number of times Valera will need to wash a plate/bowl, if he acts optimally. Input Specification: The first line of the input contains three integers *n*, *m*, *k* (1<=≤<=*n*,<=*m*,<=*k*<=≤<=1000) — the number of the planned days, the number of clean bowls and the number of clean plates. The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=2). If *a**i* equals one, then on day *i* Valera will eat a first type dish. If *a**i* equals two, then on day *i* Valera will eat a second type dish. Output Specification: Print a single integer — the minimum number of times Valera will need to wash a plate/bowl. Demo Input: ['3 1 1\n1 2 1\n', '4 3 1\n1 1 1 1\n', '3 1 2\n2 2 2\n', '8 2 2\n1 2 1 2 1 2 1 2\n'] Demo Output: ['1\n', '1\n', '0\n', '4\n'] Note: In the first sample Valera will wash a bowl only on the third day, so the answer is one. In the second sample, Valera will have the first type of the dish during all four days, and since there are only three bowls, he will wash a bowl exactly once. In the third sample, Valera will have the second type of dish for all three days, and as they can be eaten from either a plate or a bowl, he will never need to wash a plate/bowl.
```python # cook your dish here n, b, p = map(int,input().split()) ls = list(map(int, input().split())) ans = n - min(ls.count(2), p) - b if ans<=0: print(0) else: print(ans) ```
3
978
A
Remove Duplicates
PROGRAMMING
800
[ "implementation" ]
null
null
Petya has an array $a$ consisting of $n$ integers. He wants to remove duplicate (equal) elements. Petya wants to leave only the rightmost entry (occurrence) for each element of the array. The relative order of the remaining unique elements should not be changed.
The first line contains a single integer $n$ ($1 \le n \le 50$) — the number of elements in Petya's array. The following line contains a sequence $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 1\,000$) — the Petya's array.
In the first line print integer $x$ — the number of elements which will be left in Petya's array after he removed the duplicates. In the second line print $x$ integers separated with a space — Petya's array after he removed the duplicates. For each unique element only the rightmost entry should be left.
[ "6\n1 5 5 1 6 1\n", "5\n2 4 2 4 4\n", "5\n6 6 6 6 6\n" ]
[ "3\n5 6 1 \n", "2\n2 4 \n", "1\n6 \n" ]
In the first example you should remove two integers $1$, which are in the positions $1$ and $4$. Also you should remove the integer $5$, which is in the position $2$. In the second example you should remove integer $2$, which is in the position $1$, and two integers $4$, which are in the positions $2$ and $4$. In the third example you should remove four integers $6$, which are in the positions $1$, $2$, $3$ and $4$.
0
[ { "input": "6\n1 5 5 1 6 1", "output": "3\n5 6 1 " }, { "input": "5\n2 4 2 4 4", "output": "2\n2 4 " }, { "input": "5\n6 6 6 6 6", "output": "1\n6 " }, { "input": "7\n1 2 3 4 2 2 3", "output": "4\n1 4 2 3 " }, { "input": "9\n100 100 100 99 99 99 100 100 100", "output": "2\n99 100 " }, { "input": "27\n489 489 487 488 750 230 43 645 42 42 489 42 973 42 973 750 645 355 868 112 868 489 750 489 887 489 868", "output": "13\n487 488 230 43 42 973 645 355 112 750 887 489 868 " }, { "input": "40\n151 421 421 909 117 222 909 954 227 421 227 954 954 222 421 227 421 421 421 151 421 227 222 222 222 222 421 183 421 227 421 954 222 421 954 421 222 421 909 421", "output": "8\n117 151 183 227 954 222 909 421 " }, { "input": "48\n2 2 2 903 903 2 726 2 2 2 2 2 2 2 2 2 2 726 2 2 2 2 2 2 2 726 2 2 2 2 62 2 2 2 2 2 2 2 2 726 62 726 2 2 2 903 903 2", "output": "4\n62 726 903 2 " }, { "input": "1\n1", "output": "1\n1 " }, { "input": "13\n5 37 375 5 37 33 37 375 37 2 3 3 2", "output": "6\n5 33 375 37 3 2 " }, { "input": "50\n1 2 3 4 5 4 3 2 1 2 3 2 1 4 5 5 4 3 2 1 1 2 3 4 5 4 3 2 1 2 3 2 1 4 5 5 4 3 2 1 4 3 2 5 1 6 6 6 6 6", "output": "6\n4 3 2 5 1 6 " }, { "input": "47\n233 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 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": "2\n233 1 " }, { "input": "47\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", "output": "1\n1 " }, { "input": "2\n964 964", "output": "1\n964 " }, { "input": "2\n1000 1000", "output": "1\n1000 " }, { "input": "1\n1000", "output": "1\n1000 " }, { "input": "45\n991 991 996 996 992 992 999 1000 998 1000 992 999 996 999 991 991 999 993 992 999 1000 997 992 999 996 991 994 996 991 999 1000 993 999 997 999 992 991 997 991 998 998 995 998 994 993", "output": "10\n996 1000 999 992 997 991 995 998 994 993 " }, { "input": "6\n994 993 1000 998 991 994", "output": "5\n993 1000 998 991 994 " }, { "input": "48\n992 995 992 991 994 992 995 999 996 993 999 995 993 992 1000 992 997 996 991 993 992 998 998 998 999 995 992 992 993 992 992 995 996 995 997 991 997 991 999 994 994 997 1000 998 1000 992 1000 999", "output": "10\n993 996 995 991 994 997 998 992 1000 999 " }, { "input": "3\n6 6 3", "output": "2\n6 3 " }, { "input": "36\n999 1000 993 993 1000 999 996 997 998 995 995 997 999 995 1000 998 998 994 993 998 994 999 1000 995 996 994 991 991 999 996 993 999 996 998 991 997", "output": "9\n1000 995 994 993 999 996 998 991 997 " }, { "input": "49\n991 997 995 991 995 998 994 996 997 991 998 993 992 999 996 995 991 991 999 997 995 993 997 1000 997 993 993 994 999 994 992 991 1000 996 994 996 996 999 992 992 1000 991 997 993 991 994 997 991 996", "output": "10\n998 995 999 992 1000 993 994 997 991 996 " }, { "input": "2\n1000 999", "output": "2\n1000 999 " }, { "input": "28\n997 994 991 994 994 995 1000 992 995 994 994 995 991 996 991 996 991 999 999 993 994 997 995 992 991 992 998 1000", "output": "10\n996 999 993 994 997 995 991 992 998 1000 " }, { "input": "15\n991 995 995 1000 991 993 997 998 1000 994 1000 992 991 995 992", "output": "8\n993 997 998 994 1000 991 995 992 " }, { "input": "6\n1000 1 1000 2 1000 1", "output": "3\n2 1000 1 " }, { "input": "6\n1000 1 1000 2 1 1000", "output": "3\n2 1 1000 " }, { "input": "7\n1 1000 1 999 1000 1 2", "output": "4\n999 1000 1 2 " } ]
1,671,905,331
2,147,483,647
PyPy 3-64
WRONG_ANSWER
TESTS
0
46
0
a=6 l=[] b=[1 ,5 ,5, 1, 6, 1] for i in b: if i not in l : l.append(i) print(len(l)) for i in l: print(i,end=' ')
Title: Remove Duplicates Time Limit: None seconds Memory Limit: None megabytes Problem Description: Petya has an array $a$ consisting of $n$ integers. He wants to remove duplicate (equal) elements. Petya wants to leave only the rightmost entry (occurrence) for each element of the array. The relative order of the remaining unique elements should not be changed. Input Specification: The first line contains a single integer $n$ ($1 \le n \le 50$) — the number of elements in Petya's array. The following line contains a sequence $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 1\,000$) — the Petya's array. Output Specification: In the first line print integer $x$ — the number of elements which will be left in Petya's array after he removed the duplicates. In the second line print $x$ integers separated with a space — Petya's array after he removed the duplicates. For each unique element only the rightmost entry should be left. Demo Input: ['6\n1 5 5 1 6 1\n', '5\n2 4 2 4 4\n', '5\n6 6 6 6 6\n'] Demo Output: ['3\n5 6 1 \n', '2\n2 4 \n', '1\n6 \n'] Note: In the first example you should remove two integers $1$, which are in the positions $1$ and $4$. Also you should remove the integer $5$, which is in the position $2$. In the second example you should remove integer $2$, which is in the position $1$, and two integers $4$, which are in the positions $2$ and $4$. In the third example you should remove four integers $6$, which are in the positions $1$, $2$, $3$ and $4$.
```python a=6 l=[] b=[1 ,5 ,5, 1, 6, 1] for i in b: if i not in l : l.append(i) print(len(l)) for i in l: print(i,end=' ') ```
0
576
A
Vasya and Petya's Game
PROGRAMMING
1,500
[ "math", "number theory" ]
null
null
Vasya and Petya are playing a simple game. Vasya thought of number *x* between 1 and *n*, and Petya tries to guess the number. Petya can ask questions like: "Is the unknown number divisible by number *y*?". The game is played by the following rules: first Petya asks all the questions that interest him (also, he can ask no questions), and then Vasya responds to each question with a 'yes' or a 'no'. After receiving all the answers Petya should determine the number that Vasya thought of. Unfortunately, Petya is not familiar with the number theory. Help him find the minimum number of questions he should ask to make a guaranteed guess of Vasya's number, and the numbers *y**i*, he should ask the questions about.
A single line contains number *n* (1<=≤<=*n*<=≤<=103).
Print the length of the sequence of questions *k* (0<=≤<=*k*<=≤<=*n*), followed by *k* numbers — the questions *y**i* (1<=≤<=*y**i*<=≤<=*n*). If there are several correct sequences of questions of the minimum length, you are allowed to print any of them.
[ "4\n", "6\n" ]
[ "3\n2 4 3 \n", "4\n2 4 3 5 \n" ]
The sequence from the answer to the first sample test is actually correct. If the unknown number is not divisible by one of the sequence numbers, it is equal to 1. If the unknown number is divisible by 4, it is 4. If the unknown number is divisible by 3, then the unknown number is 3. Otherwise, it is equal to 2. Therefore, the sequence of questions allows you to guess the unknown number. It can be shown that there is no correct sequence of questions of length 2 or shorter.
500
[ { "input": "4", "output": "3\n2 4 3 " }, { "input": "6", "output": "4\n2 4 3 5 " }, { "input": "1", "output": "0" }, { "input": "15", "output": "9\n2 4 8 3 9 5 7 11 13 " }, { "input": "19", "output": "12\n2 4 8 16 3 9 5 7 11 13 17 19 " }, { "input": "20", "output": "12\n2 4 8 16 3 9 5 7 11 13 17 19 " }, { "input": "37", "output": "19\n2 4 8 16 32 3 9 27 5 25 7 11 13 17 19 23 29 31 37 " }, { "input": "211", "output": "61\n2 4 8 16 32 64 128 3 9 27 81 5 25 125 7 49 11 121 13 169 17 19 23 29 31 37 41 43 47 53 59 61 67 71 73 79 83 89 97 101 103 107 109 113 127 131 137 139 149 151 157 163 167 173 179 181 191 193 197 199 211 " }, { "input": "557", "output": "123\n2 4 8 16 32 64 128 256 512 3 9 27 81 243 5 25 125 7 49 343 11 121 13 169 17 289 19 361 23 529 29 31 37 41 43 47 53 59 61 67 71 73 79 83 89 97 101 103 107 109 113 127 131 137 139 149 151 157 163 167 173 179 181 191 193 197 199 211 223 227 229 233 239 241 251 257 263 269 271 277 281 283 293 307 311 313 317 331 337 347 349 353 359 367 373 379 383 389 397 401 409 419 421 431 433 439 443 449 457 461 463 467 479 487 491 499 503 509 521 523 541 547 557 " }, { "input": "907", "output": "179\n2 4 8 16 32 64 128 256 512 3 9 27 81 243 729 5 25 125 625 7 49 343 11 121 13 169 17 289 19 361 23 529 29 841 31 37 41 43 47 53 59 61 67 71 73 79 83 89 97 101 103 107 109 113 127 131 137 139 149 151 157 163 167 173 179 181 191 193 197 199 211 223 227 229 233 239 241 251 257 263 269 271 277 281 283 293 307 311 313 317 331 337 347 349 353 359 367 373 379 383 389 397 401 409 419 421 431 433 439 443 449 457 461 463 467 479 487 491 499 503 509 521 523 541 547 557 563 569 571 577 587 593 599 601 607 613 617 ..." }, { "input": "953", "output": "186\n2 4 8 16 32 64 128 256 512 3 9 27 81 243 729 5 25 125 625 7 49 343 11 121 13 169 17 289 19 361 23 529 29 841 31 37 41 43 47 53 59 61 67 71 73 79 83 89 97 101 103 107 109 113 127 131 137 139 149 151 157 163 167 173 179 181 191 193 197 199 211 223 227 229 233 239 241 251 257 263 269 271 277 281 283 293 307 311 313 317 331 337 347 349 353 359 367 373 379 383 389 397 401 409 419 421 431 433 439 443 449 457 461 463 467 479 487 491 499 503 509 521 523 541 547 557 563 569 571 577 587 593 599 601 607 613 617 ..." }, { "input": "289", "output": "78\n2 4 8 16 32 64 128 256 3 9 27 81 243 5 25 125 7 49 11 121 13 169 17 289 19 23 29 31 37 41 43 47 53 59 61 67 71 73 79 83 89 97 101 103 107 109 113 127 131 137 139 149 151 157 163 167 173 179 181 191 193 197 199 211 223 227 229 233 239 241 251 257 263 269 271 277 281 283 " }, { "input": "400", "output": "97\n2 4 8 16 32 64 128 256 3 9 27 81 243 5 25 125 7 49 343 11 121 13 169 17 289 19 361 23 29 31 37 41 43 47 53 59 61 67 71 73 79 83 89 97 101 103 107 109 113 127 131 137 139 149 151 157 163 167 173 179 181 191 193 197 199 211 223 227 229 233 239 241 251 257 263 269 271 277 281 283 293 307 311 313 317 331 337 347 349 353 359 367 373 379 383 389 397 " }, { "input": "900", "output": "178\n2 4 8 16 32 64 128 256 512 3 9 27 81 243 729 5 25 125 625 7 49 343 11 121 13 169 17 289 19 361 23 529 29 841 31 37 41 43 47 53 59 61 67 71 73 79 83 89 97 101 103 107 109 113 127 131 137 139 149 151 157 163 167 173 179 181 191 193 197 199 211 223 227 229 233 239 241 251 257 263 269 271 277 281 283 293 307 311 313 317 331 337 347 349 353 359 367 373 379 383 389 397 401 409 419 421 431 433 439 443 449 457 461 463 467 479 487 491 499 503 509 521 523 541 547 557 563 569 571 577 587 593 599 601 607 613 617 ..." }, { "input": "625", "output": "136\n2 4 8 16 32 64 128 256 512 3 9 27 81 243 5 25 125 625 7 49 343 11 121 13 169 17 289 19 361 23 529 29 31 37 41 43 47 53 59 61 67 71 73 79 83 89 97 101 103 107 109 113 127 131 137 139 149 151 157 163 167 173 179 181 191 193 197 199 211 223 227 229 233 239 241 251 257 263 269 271 277 281 283 293 307 311 313 317 331 337 347 349 353 359 367 373 379 383 389 397 401 409 419 421 431 433 439 443 449 457 461 463 467 479 487 491 499 503 509 521 523 541 547 557 563 569 571 577 587 593 599 601 607 613 617 619 " }, { "input": "729", "output": "152\n2 4 8 16 32 64 128 256 512 3 9 27 81 243 729 5 25 125 625 7 49 343 11 121 13 169 17 289 19 361 23 529 29 31 37 41 43 47 53 59 61 67 71 73 79 83 89 97 101 103 107 109 113 127 131 137 139 149 151 157 163 167 173 179 181 191 193 197 199 211 223 227 229 233 239 241 251 257 263 269 271 277 281 283 293 307 311 313 317 331 337 347 349 353 359 367 373 379 383 389 397 401 409 419 421 431 433 439 443 449 457 461 463 467 479 487 491 499 503 509 521 523 541 547 557 563 569 571 577 587 593 599 601 607 613 617 619 ..." }, { "input": "784", "output": "160\n2 4 8 16 32 64 128 256 512 3 9 27 81 243 729 5 25 125 625 7 49 343 11 121 13 169 17 289 19 361 23 529 29 31 37 41 43 47 53 59 61 67 71 73 79 83 89 97 101 103 107 109 113 127 131 137 139 149 151 157 163 167 173 179 181 191 193 197 199 211 223 227 229 233 239 241 251 257 263 269 271 277 281 283 293 307 311 313 317 331 337 347 349 353 359 367 373 379 383 389 397 401 409 419 421 431 433 439 443 449 457 461 463 467 479 487 491 499 503 509 521 523 541 547 557 563 569 571 577 587 593 599 601 607 613 617 619 ..." }, { "input": "31", "output": "17\n2 4 8 16 3 9 27 5 25 7 11 13 17 19 23 29 31 " }, { "input": "44", "output": "21\n2 4 8 16 32 3 9 27 5 25 7 11 13 17 19 23 29 31 37 41 43 " }, { "input": "160", "output": "50\n2 4 8 16 32 64 128 3 9 27 81 5 25 125 7 49 11 121 13 17 19 23 29 31 37 41 43 47 53 59 61 67 71 73 79 83 89 97 101 103 107 109 113 127 131 137 139 149 151 157 " }, { "input": "322", "output": "83\n2 4 8 16 32 64 128 256 3 9 27 81 243 5 25 125 7 49 11 121 13 169 17 289 19 23 29 31 37 41 43 47 53 59 61 67 71 73 79 83 89 97 101 103 107 109 113 127 131 137 139 149 151 157 163 167 173 179 181 191 193 197 199 211 223 227 229 233 239 241 251 257 263 269 271 277 281 283 293 307 311 313 317 " }, { "input": "894", "output": "178\n2 4 8 16 32 64 128 256 512 3 9 27 81 243 729 5 25 125 625 7 49 343 11 121 13 169 17 289 19 361 23 529 29 841 31 37 41 43 47 53 59 61 67 71 73 79 83 89 97 101 103 107 109 113 127 131 137 139 149 151 157 163 167 173 179 181 191 193 197 199 211 223 227 229 233 239 241 251 257 263 269 271 277 281 283 293 307 311 313 317 331 337 347 349 353 359 367 373 379 383 389 397 401 409 419 421 431 433 439 443 449 457 461 463 467 479 487 491 499 503 509 521 523 541 547 557 563 569 571 577 587 593 599 601 607 613 617 ..." }, { "input": "998", "output": "193\n2 4 8 16 32 64 128 256 512 3 9 27 81 243 729 5 25 125 625 7 49 343 11 121 13 169 17 289 19 361 23 529 29 841 31 961 37 41 43 47 53 59 61 67 71 73 79 83 89 97 101 103 107 109 113 127 131 137 139 149 151 157 163 167 173 179 181 191 193 197 199 211 223 227 229 233 239 241 251 257 263 269 271 277 281 283 293 307 311 313 317 331 337 347 349 353 359 367 373 379 383 389 397 401 409 419 421 431 433 439 443 449 457 461 463 467 479 487 491 499 503 509 521 523 541 547 557 563 569 571 577 587 593 599 601 607 613 ..." }, { "input": "1000", "output": "193\n2 4 8 16 32 64 128 256 512 3 9 27 81 243 729 5 25 125 625 7 49 343 11 121 13 169 17 289 19 361 23 529 29 841 31 961 37 41 43 47 53 59 61 67 71 73 79 83 89 97 101 103 107 109 113 127 131 137 139 149 151 157 163 167 173 179 181 191 193 197 199 211 223 227 229 233 239 241 251 257 263 269 271 277 281 283 293 307 311 313 317 331 337 347 349 353 359 367 373 379 383 389 397 401 409 419 421 431 433 439 443 449 457 461 463 467 479 487 491 499 503 509 521 523 541 547 557 563 569 571 577 587 593 599 601 607 613 ..." }, { "input": "1000", "output": "193\n2 4 8 16 32 64 128 256 512 3 9 27 81 243 729 5 25 125 625 7 49 343 11 121 13 169 17 289 19 361 23 529 29 841 31 961 37 41 43 47 53 59 61 67 71 73 79 83 89 97 101 103 107 109 113 127 131 137 139 149 151 157 163 167 173 179 181 191 193 197 199 211 223 227 229 233 239 241 251 257 263 269 271 277 281 283 293 307 311 313 317 331 337 347 349 353 359 367 373 379 383 389 397 401 409 419 421 431 433 439 443 449 457 461 463 467 479 487 491 499 503 509 521 523 541 547 557 563 569 571 577 587 593 599 601 607 613 ..." }, { "input": "30", "output": "16\n2 4 8 16 3 9 27 5 25 7 11 13 17 19 23 29 " } ]
1,609,968,608
2,147,483,647
PyPy 3
WRONG_ANSWER
TESTS
3
140
0
n=int(input()) a = [i for i in range(2, n+1)] def calculaDivisiores(num): atual = 2 divs = [] while atual<=(num//2)+1: if num%atual==0: divs.append(atual) atual+=1 return divs res = [] for num in a: divs = calculaDivisiores(num) if len(divs)==1: res.append(num) else: res.append(num) for div1 in divs: for div2 in divs: if div1!=div2: if div1%div2!=0: if num in res: res.remove(num) print(len(res)) for r in res: print(r,end=' ')
Title: Vasya and Petya's Game Time Limit: None seconds Memory Limit: None megabytes Problem Description: Vasya and Petya are playing a simple game. Vasya thought of number *x* between 1 and *n*, and Petya tries to guess the number. Petya can ask questions like: "Is the unknown number divisible by number *y*?". The game is played by the following rules: first Petya asks all the questions that interest him (also, he can ask no questions), and then Vasya responds to each question with a 'yes' or a 'no'. After receiving all the answers Petya should determine the number that Vasya thought of. Unfortunately, Petya is not familiar with the number theory. Help him find the minimum number of questions he should ask to make a guaranteed guess of Vasya's number, and the numbers *y**i*, he should ask the questions about. Input Specification: A single line contains number *n* (1<=≤<=*n*<=≤<=103). Output Specification: Print the length of the sequence of questions *k* (0<=≤<=*k*<=≤<=*n*), followed by *k* numbers — the questions *y**i* (1<=≤<=*y**i*<=≤<=*n*). If there are several correct sequences of questions of the minimum length, you are allowed to print any of them. Demo Input: ['4\n', '6\n'] Demo Output: ['3\n2 4 3 \n', '4\n2 4 3 5 \n'] Note: The sequence from the answer to the first sample test is actually correct. If the unknown number is not divisible by one of the sequence numbers, it is equal to 1. If the unknown number is divisible by 4, it is 4. If the unknown number is divisible by 3, then the unknown number is 3. Otherwise, it is equal to 2. Therefore, the sequence of questions allows you to guess the unknown number. It can be shown that there is no correct sequence of questions of length 2 or shorter.
```python n=int(input()) a = [i for i in range(2, n+1)] def calculaDivisiores(num): atual = 2 divs = [] while atual<=(num//2)+1: if num%atual==0: divs.append(atual) atual+=1 return divs res = [] for num in a: divs = calculaDivisiores(num) if len(divs)==1: res.append(num) else: res.append(num) for div1 in divs: for div2 in divs: if div1!=div2: if div1%div2!=0: if num in res: res.remove(num) print(len(res)) for r in res: print(r,end=' ') ```
0
0
none
none
none
0
[ "none" ]
null
null
As usual, Sereja has array *a*, its elements are integers: *a*[1],<=*a*[2],<=...,<=*a*[*n*]. Let's introduce notation: A swap operation is the following sequence of actions: - choose two indexes *i*,<=*j* (*i*<=≠<=*j*); - perform assignments *tmp*<==<=*a*[*i*],<=*a*[*i*]<==<=*a*[*j*],<=*a*[*j*]<==<=*tmp*. What maximum value of function *m*(*a*) can Sereja get if he is allowed to perform at most *k* swap operations?
The first line contains two integers *n* and *k* (1<=≤<=*n*<=≤<=200; 1<=≤<=*k*<=≤<=10). The next line contains *n* integers *a*[1], *a*[2], ..., *a*[*n*] (<=-<=1000<=≤<=*a*[*i*]<=≤<=1000).
In a single line print the maximum value of *m*(*a*) that Sereja can get if he is allowed to perform at most *k* swap operations.
[ "10 2\n10 -1 2 2 2 2 2 2 -1 10\n", "5 10\n-1 -1 -1 -1 -1\n" ]
[ "32\n", "-1\n" ]
none
0
[ { "input": "10 2\n10 -1 2 2 2 2 2 2 -1 10", "output": "32" }, { "input": "5 10\n-1 -1 -1 -1 -1", "output": "-1" }, { "input": "18 1\n166 788 276 -103 -491 195 -960 389 376 369 630 285 3 575 315 -987 820 466", "output": "5016" }, { "input": "29 6\n-21 486 -630 -433 -123 -387 618 110 -203 55 -123 524 -168 662 432 378 -155 -136 -162 811 457 -157 -215 861 -565 -506 557 348 -7", "output": "6299" }, { "input": "9 9\n-767 148 -323 -818 41 -228 615 885 -260", "output": "1689" }, { "input": "35 5\n151 -160 -292 -31 -131 174 359 42 438 413 164 91 118 393 76 435 371 -76 145 605 292 578 623 405 664 330 455 329 66 168 179 -76 996 163 531", "output": "9754" }, { "input": "47 10\n-175 246 -903 681 748 -338 333 0 666 245 370 402 -38 682 144 658 -10 313 295 351 -95 149 111 -210 645 -173 -276 690 593 697 259 698 421 584 -229 445 -215 -203 49 642 386 649 469 4 340 484 279", "output": "14728" }, { "input": "11 7\n877 -188 10 -175 217 -254 841 380 552 -607 228", "output": "3105" }, { "input": "38 1\n173 587 -788 163 83 -768 461 -527 350 3 -898 634 -217 -528 317 -238 545 93 -964 283 -798 -596 77 222 -370 -209 61 846 -831 -419 -366 -509 -356 -649 916 -391 981 -596", "output": "2743" }, { "input": "6 9\n-669 45 -220 544 106 680", "output": "1375" }, { "input": "32 9\n-650 -208 506 812 -540 -275 -272 -236 -96 197 425 475 81 570 281 633 449 396 401 -362 -379 667 717 875 658 114 294 100 286 112 -928 -373", "output": "9049" }, { "input": "36 5\n-286 762 -5 -230 -483 -140 -143 -82 -127 449 435 85 -262 567 454 -163 942 -679 -609 854 -533 717 -101 92 -767 795 -804 -953 -754 -251 -100 884 809 -358 469 -112", "output": "8222" }, { "input": "24 5\n-751 889 721 -900 903 -900 -693 895 828 314 836 -493 549 -74 264 662 229 517 -223 367 141 -99 -390 283", "output": "8398" }, { "input": "82 8\n-483 465 435 -789 80 -412 672 512 -755 981 784 -281 -634 -270 806 887 -495 -46 -244 609 42 -821 100 -40 -299 -6 560 941 523 758 -730 -930 91 -138 -299 0 533 -208 -416 869 967 -871 573 165 -279 298 934 -236 70 800 550 433 139 147 139 -212 137 -933 -863 876 -622 193 -121 -944 983 -592 -40 -712 891 985 16 580 -845 -903 -986 952 -95 -613 -2 -45 -86 -206", "output": "18704" }, { "input": "116 10\n477 -765 -756 376 -48 -75 768 -658 263 -207 362 -535 96 -960 630 -686 609 -830 889 57 -239 346 -298 -18 -107 853 -607 -443 -517 371 657 105 479 498 -47 432 503 -917 -656 610 -466 216 -747 -587 -163 -174 493 -882 853 -582 -774 -477 -386 610 -58 557 968 196 69 610 -38 366 -79 574 170 317 332 189 158 -194 136 -151 500 309 624 316 543 472 132 -15 -78 166 360 -71 12 247 678 263 573 -198 1 101 155 -65 597 -93 60 3 -496 985 -586 -761 -532 506 578 -13 569 845 -341 870 -900 891 724 408 229 -210", "output": "24624" }, { "input": "110 4\n-813 -73 334 667 602 -155 432 -133 689 397 461 499 630 40 69 299 697 449 -130 210 -146 415 292 123 12 -105 444 338 509 497 142 688 603 107 -108 160 211 -215 219 -144 637 -173 615 -210 521 545 377 -6 -187 354 647 309 139 309 155 -242 546 -231 -267 405 411 -271 -149 264 -169 -447 -749 -218 273 -798 -135 839 54 -764 279 -578 -641 -152 -881 241 174 31 525 621 -855 656 482 -197 -402 995 785 338 -733 293 606 294 -645 262 909 325 -246 -952 408 646 2 -567 -484 661 -390 -488", "output": "20286" }, { "input": "94 2\n432 255 304 757 -438 52 461 55 837 -564 304 713 -968 -539 -593 835 -824 -532 38 -880 -772 480 -755 -387 -830 286 -38 -202 -273 423 272 471 -224 306 490 532 -210 -245 -20 680 -236 404 -5 -188 387 582 -30 -800 276 -811 240 -4 214 -708 200 -785 -466 61 16 -742 647 -371 -851 -295 -552 480 38 924 403 704 -705 -972 677 569 450 446 816 396 -179 281 -564 -27 -272 -640 809 29 28 -209 -925 997 -268 133 265 161", "output": "7839" }, { "input": "78 8\n-230 -757 673 -284 381 -324 -96 975 249 971 -355 186 -526 804 147 -553 655 263 -247 775 108 -246 -107 25 -786 -372 -24 -619 265 -192 269 392 210 449 335 -207 371 562 307 141 668 78 13 251 623 -238 60 543 618 201 73 -35 -663 620 485 444 330 362 -33 484 685 257 542 375 -952 48 -604 -288 -19 -718 -798 946 -533 -666 -686 -278 368 -294", "output": "17941" }, { "input": "1 10\n-1", "output": "-1" }, { "input": "1 1\n-1", "output": "-1" }, { "input": "1 1\n1", "output": "1" }, { "input": "1 10\n1", "output": "1" }, { "input": "10 1\n-1 1 1 1 1 1 1 1 1 1", "output": "9" } ]
1,404,303,241
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
32
904
307,200
n, k = map(int, input().split()) a = list(map(int, input().split())) res = a[0] for l in range(n): for r in range(l, n): inside = sorted(a[l:r+1]) outside = sorted(a[:l] + a[r+1:], reverse=True) new_res = sum(inside) for i in range(min(k, len(inside), len(outside))): if outside[i] > inside[i]: new_res += outside[i]-inside[i] else: break if new_res > res: res = new_res print(res)
Title: none Time Limit: None seconds Memory Limit: None megabytes Problem Description: As usual, Sereja has array *a*, its elements are integers: *a*[1],<=*a*[2],<=...,<=*a*[*n*]. Let's introduce notation: A swap operation is the following sequence of actions: - choose two indexes *i*,<=*j* (*i*<=≠<=*j*); - perform assignments *tmp*<==<=*a*[*i*],<=*a*[*i*]<==<=*a*[*j*],<=*a*[*j*]<==<=*tmp*. What maximum value of function *m*(*a*) can Sereja get if he is allowed to perform at most *k* swap operations? Input Specification: The first line contains two integers *n* and *k* (1<=≤<=*n*<=≤<=200; 1<=≤<=*k*<=≤<=10). The next line contains *n* integers *a*[1], *a*[2], ..., *a*[*n*] (<=-<=1000<=≤<=*a*[*i*]<=≤<=1000). Output Specification: In a single line print the maximum value of *m*(*a*) that Sereja can get if he is allowed to perform at most *k* swap operations. Demo Input: ['10 2\n10 -1 2 2 2 2 2 2 -1 10\n', '5 10\n-1 -1 -1 -1 -1\n'] Demo Output: ['32\n', '-1\n'] Note: none
```python n, k = map(int, input().split()) a = list(map(int, input().split())) res = a[0] for l in range(n): for r in range(l, n): inside = sorted(a[l:r+1]) outside = sorted(a[:l] + a[r+1:], reverse=True) new_res = sum(inside) for i in range(min(k, len(inside), len(outside))): if outside[i] > inside[i]: new_res += outside[i]-inside[i] else: break if new_res > res: res = new_res print(res) ```
0
606
A
Magic Spheres
PROGRAMMING
1,200
[ "implementation" ]
null
null
Carl is a beginner magician. He has *a* blue, *b* violet and *c* orange magic spheres. In one move he can transform two spheres of the same color into one sphere of any other color. To make a spell that has never been seen before, he needs at least *x* blue, *y* violet and *z* orange spheres. Can he get them (possible, in multiple actions)?
The first line of the input contains three integers *a*, *b* and *c* (0<=≤<=*a*,<=*b*,<=*c*<=≤<=1<=000<=000) — the number of blue, violet and orange spheres that are in the magician's disposal. The second line of the input contains three integers, *x*, *y* and *z* (0<=≤<=*x*,<=*y*,<=*z*<=≤<=1<=000<=000) — the number of blue, violet and orange spheres that he needs to get.
If the wizard is able to obtain the required numbers of spheres, print "Yes". Otherwise, print "No".
[ "4 4 0\n2 1 2\n", "5 6 1\n2 7 2\n", "3 3 3\n2 2 2\n" ]
[ "Yes\n", "No\n", "Yes\n" ]
In the first sample the wizard has 4 blue and 4 violet spheres. In his first action he can turn two blue spheres into one violet one. After that he will have 2 blue and 5 violet spheres. Then he turns 4 violet spheres into 2 orange spheres and he ends up with 2 blue, 1 violet and 2 orange spheres, which is exactly what he needs.
500
[ { "input": "4 4 0\n2 1 2", "output": "Yes" }, { "input": "5 6 1\n2 7 2", "output": "No" }, { "input": "3 3 3\n2 2 2", "output": "Yes" }, { "input": "0 0 0\n0 0 0", "output": "Yes" }, { "input": "0 0 0\n0 0 1", "output": "No" }, { "input": "0 1 0\n0 0 0", "output": "Yes" }, { "input": "1 0 0\n1 0 0", "output": "Yes" }, { "input": "2 2 1\n1 1 2", "output": "No" }, { "input": "1 3 1\n2 1 1", "output": "Yes" }, { "input": "1000000 1000000 1000000\n1000000 1000000 1000000", "output": "Yes" }, { "input": "1000000 500000 500000\n0 750000 750000", "output": "Yes" }, { "input": "500000 1000000 500000\n750001 0 750000", "output": "No" }, { "input": "499999 500000 1000000\n750000 750000 0", "output": "No" }, { "input": "500000 500000 0\n0 0 500000", "output": "Yes" }, { "input": "0 500001 499999\n500000 0 0", "output": "No" }, { "input": "1000000 500000 1000000\n500000 1000000 500000", "output": "Yes" }, { "input": "1000000 1000000 499999\n500000 500000 1000000", "output": "No" }, { "input": "500000 1000000 1000000\n1000000 500001 500000", "output": "No" }, { "input": "1000000 500000 500000\n0 1000000 500000", "output": "Yes" }, { "input": "500000 500000 1000000\n500001 1000000 0", "output": "No" }, { "input": "500000 999999 500000\n1000000 0 500000", "output": "No" }, { "input": "4 0 3\n2 2 1", "output": "Yes" }, { "input": "0 2 4\n2 0 2", "output": "Yes" }, { "input": "3 1 0\n1 1 1", "output": "Yes" }, { "input": "4 4 1\n1 3 2", "output": "Yes" }, { "input": "1 2 4\n2 1 3", "output": "No" }, { "input": "1 1 0\n0 0 1", "output": "No" }, { "input": "4 0 0\n0 1 1", "output": "Yes" }, { "input": "0 3 0\n1 0 1", "output": "No" }, { "input": "0 0 3\n1 0 1", "output": "Yes" }, { "input": "1 12 1\n4 0 4", "output": "Yes" }, { "input": "4 0 4\n1 2 1", "output": "Yes" }, { "input": "4 4 0\n1 1 3", "output": "No" }, { "input": "0 9 0\n2 2 2", "output": "No" }, { "input": "0 10 0\n2 2 2", "output": "Yes" }, { "input": "9 0 9\n0 8 0", "output": "Yes" }, { "input": "0 9 9\n9 0 0", "output": "No" }, { "input": "9 10 0\n0 0 9", "output": "Yes" }, { "input": "10 0 9\n0 10 0", "output": "No" }, { "input": "0 10 10\n10 0 0", "output": "Yes" }, { "input": "10 10 0\n0 0 11", "output": "No" }, { "input": "307075 152060 414033\n381653 222949 123101", "output": "No" }, { "input": "569950 228830 153718\n162186 357079 229352", "output": "No" }, { "input": "149416 303568 749016\n238307 493997 190377", "output": "No" }, { "input": "438332 298094 225324\n194220 400244 245231", "output": "No" }, { "input": "293792 300060 511272\n400687 382150 133304", "output": "No" }, { "input": "295449 518151 368838\n382897 137148 471892", "output": "No" }, { "input": "191789 291147 691092\n324321 416045 176232", "output": "Yes" }, { "input": "286845 704749 266526\n392296 104421 461239", "output": "Yes" }, { "input": "135522 188282 377041\n245719 212473 108265", "output": "Yes" }, { "input": "404239 359124 133292\n180069 184791 332544", "output": "No" }, { "input": "191906 624432 244408\n340002 367217 205432", "output": "No" }, { "input": "275980 429361 101824\n274288 302579 166062", "output": "No" }, { "input": "136092 364927 395302\n149173 343146 390922", "output": "No" }, { "input": "613852 334661 146012\n363786 326286 275233", "output": "No" }, { "input": "348369 104625 525203\n285621 215396 366411", "output": "No" }, { "input": "225307 153572 114545\n154753 153282 149967", "output": "Yes" }, { "input": "438576 124465 629784\n375118 276028 390116", "output": "Yes" }, { "input": "447521 327510 158732\n395759 178458 259139", "output": "Yes" }, { "input": "8 5 5\n5 5 5", "output": "Yes" }, { "input": "100 100 100\n1 1 1", "output": "Yes" }, { "input": "100 100 100\n0 0 0", "output": "Yes" }, { "input": "3 2 3\n2 3 2", "output": "No" }, { "input": "5 4 3\n2 2 2", "output": "Yes" }, { "input": "14 9 8\n12 5 10", "output": "Yes" }, { "input": "10 10 10\n1 1 1", "output": "Yes" }, { "input": "6 3 3\n3 3 3", "output": "Yes" }, { "input": "10 0 4\n2 4 2", "output": "Yes" }, { "input": "100 100 100\n2 2 2", "output": "Yes" }, { "input": "4 6 0\n2 1 2", "output": "Yes" }, { "input": "4 6 3\n4 2 3", "output": "Yes" }, { "input": "5 5 5\n1 1 1", "output": "Yes" }, { "input": "41 17 34\n0 19 24", "output": "Yes" }, { "input": "8 8 8\n3 3 3", "output": "Yes" }, { "input": "7 7 1\n1 1 2", "output": "Yes" }, { "input": "6 6 0\n2 2 2", "output": "Yes" }, { "input": "5 5 5\n2 2 2", "output": "Yes" }, { "input": "400 400 400\n1 1 1", "output": "Yes" }, { "input": "4 4 4\n2 2 2", "output": "Yes" } ]
1,693,817,708
2,147,483,647
Python 3
OK
TESTS
79
46
0
a,b,c = map(int, input().split()) x,y,z = map(int, input().split()) extra = max(0, a-x)//2 + max(0, b-y)//2 + max(0, c-z)//2 need = max(0, x-a) + max(0, y-b) + max(0, z-c) print("Yes" if need<=extra else "No")
Title: Magic Spheres Time Limit: None seconds Memory Limit: None megabytes Problem Description: Carl is a beginner magician. He has *a* blue, *b* violet and *c* orange magic spheres. In one move he can transform two spheres of the same color into one sphere of any other color. To make a spell that has never been seen before, he needs at least *x* blue, *y* violet and *z* orange spheres. Can he get them (possible, in multiple actions)? Input Specification: The first line of the input contains three integers *a*, *b* and *c* (0<=≤<=*a*,<=*b*,<=*c*<=≤<=1<=000<=000) — the number of blue, violet and orange spheres that are in the magician's disposal. The second line of the input contains three integers, *x*, *y* and *z* (0<=≤<=*x*,<=*y*,<=*z*<=≤<=1<=000<=000) — the number of blue, violet and orange spheres that he needs to get. Output Specification: If the wizard is able to obtain the required numbers of spheres, print "Yes". Otherwise, print "No". Demo Input: ['4 4 0\n2 1 2\n', '5 6 1\n2 7 2\n', '3 3 3\n2 2 2\n'] Demo Output: ['Yes\n', 'No\n', 'Yes\n'] Note: In the first sample the wizard has 4 blue and 4 violet spheres. In his first action he can turn two blue spheres into one violet one. After that he will have 2 blue and 5 violet spheres. Then he turns 4 violet spheres into 2 orange spheres and he ends up with 2 blue, 1 violet and 2 orange spheres, which is exactly what he needs.
```python a,b,c = map(int, input().split()) x,y,z = map(int, input().split()) extra = max(0, a-x)//2 + max(0, b-y)//2 + max(0, c-z)//2 need = max(0, x-a) + max(0, y-b) + max(0, z-c) print("Yes" if need<=extra else "No") ```
3
462
B
Appleman and Card Game
PROGRAMMING
1,300
[ "greedy" ]
null
null
Appleman has *n* cards. Each card has an uppercase letter written on it. Toastman must choose *k* cards from Appleman's cards. Then Appleman should give Toastman some coins depending on the chosen cards. Formally, for each Toastman's card *i* you should calculate how much Toastman's cards have the letter equal to letter on *i*th, then sum up all these quantities, such a number of coins Appleman should give to Toastman. Given the description of Appleman's cards. What is the maximum number of coins Toastman can get?
The first line contains two integers *n* and *k* (1<=≤<=*k*<=≤<=*n*<=≤<=105). The next line contains *n* uppercase letters without spaces — the *i*-th letter describes the *i*-th card of the Appleman.
Print a single integer – the answer to the problem.
[ "15 10\nDZFDFZDFDDDDDDF\n", "6 4\nYJSNPI\n" ]
[ "82\n", "4\n" ]
In the first test example Toastman can choose nine cards with letter D and one additional card with any letter. For each card with D he will get 9 coins and for the additional card he will get 1 coin.
1,000
[ { "input": "15 10\nDZFDFZDFDDDDDDF", "output": "82" }, { "input": "6 4\nYJSNPI", "output": "4" }, { "input": "5 3\nAOWBY", "output": "3" }, { "input": "1 1\nV", "output": "1" }, { "input": "2 1\nWT", "output": "1" }, { "input": "2 2\nBL", "output": "2" }, { "input": "5 1\nFACJT", "output": "1" }, { "input": "5 5\nMJDIJ", "output": "7" }, { "input": "15 5\nAZBIPTOFTJCJJIK", "output": "13" }, { "input": "100 1\nEVEEVEEEGGECFEHEFVFVFHVHEEEEEFCVEEEEEEVFVEEVEEHEEVEFEVVEFEEEFEVECEHGHEEFGEEVCEECCECEFHEVEEEEEEGEEHVH", "output": "1" }, { "input": "100 15\nKKTFFUTFCKUIKKKKFIFFKTUKUUKUKKIKKKTIFKTKUCFFKKKIIKKKKKKTFKFKKIRKKKFKUUKIKUUUFFKKKKTUZKITUIKKIKUKKTIK", "output": "225" }, { "input": "100 50\nYYIYYAAAIEAAYAYAEAIIIAAEAAYEAEYYYIAEYAYAYYAAAIAYAEAAYAYYIYAAYYAAAAAAIYYYAAYAAEAAYAIEIYIYAYAYAYIIAAEY", "output": "1972" }, { "input": "100 90\nFAFAOOAOOAFAOTFAFAFFATAAAOFAAOAFBAAAFBOAOFFFOAOAFAPFOFAOFAAFOAAAAFAAFOFAAOFPPAAOOAAOOFFOFFFOFAOTOFAF", "output": "2828" }, { "input": "100 99\nBFFBBFBFBQFFFFFQBFFBFFBQFBFQFBBFQFFFBFFFBFQFQFBFFBBFYQFBFFFFFFFBQQFQBFBQBQFFFBQQFFFBQFYFBFBFFFBBBQQY", "output": "3713" }, { "input": "100 100\nMQSBDAJABILIBCUEOWGWCEXMUTEYQKAIWGINXVQEOFDUBSVULROQHQRZZAALVQFEFRAAAYUIMGCAFQGIAEFBETRECGSFQJNXHHDN", "output": "514" }, { "input": "100 50\nBMYIXQSJNHGFVFPJBIOBXIKSFNUFPVODCUBQYSIIQNVNXXCWXWRHKFEUPPIIDDGRDBJLZDCBMNJMYRMWFIHOSTDJJHXHPNRKWNFD", "output": "328" }, { "input": "100 50\nENFNEMLJEMDMFMNNGNIMNINALGLLLAEMENEMNLMMIEIJNAINBJEJMFJLLIMINELGFLAIAMJMHMGNLIEFJIEEFEFGLLLDLMEAEIMM", "output": "748" } ]
1,651,722,612
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
18
46
0
n ,m = map(int ,input() .split()) a = input() q = sorted(a) s = [ ] d = 1 ans = 0 for i in range(1 ,len(q)): if q[i - 1] == q[i] and q[i - 1] != q[-1] and q[i] != q[-1]: d += 1 elif d > 1: s += [d] d = 1 w = q .count(q[-1]) s = sorted(s)[::-1] if w > 1: s += [w] if len(s) == 0: print(m) else: for j in range(len(s)): if s[j] > m: ans += (m * m) m -= m elif s[j] < m: ans += (s[j] * s[j]) m -= s[j] elif s[j] == m: ans += (s[j] * s[j]) m -= m print(ans + m)
Title: Appleman and Card Game Time Limit: None seconds Memory Limit: None megabytes Problem Description: Appleman has *n* cards. Each card has an uppercase letter written on it. Toastman must choose *k* cards from Appleman's cards. Then Appleman should give Toastman some coins depending on the chosen cards. Formally, for each Toastman's card *i* you should calculate how much Toastman's cards have the letter equal to letter on *i*th, then sum up all these quantities, such a number of coins Appleman should give to Toastman. Given the description of Appleman's cards. What is the maximum number of coins Toastman can get? Input Specification: The first line contains two integers *n* and *k* (1<=≤<=*k*<=≤<=*n*<=≤<=105). The next line contains *n* uppercase letters without spaces — the *i*-th letter describes the *i*-th card of the Appleman. Output Specification: Print a single integer – the answer to the problem. Demo Input: ['15 10\nDZFDFZDFDDDDDDF\n', '6 4\nYJSNPI\n'] Demo Output: ['82\n', '4\n'] Note: In the first test example Toastman can choose nine cards with letter D and one additional card with any letter. For each card with D he will get 9 coins and for the additional card he will get 1 coin.
```python n ,m = map(int ,input() .split()) a = input() q = sorted(a) s = [ ] d = 1 ans = 0 for i in range(1 ,len(q)): if q[i - 1] == q[i] and q[i - 1] != q[-1] and q[i] != q[-1]: d += 1 elif d > 1: s += [d] d = 1 w = q .count(q[-1]) s = sorted(s)[::-1] if w > 1: s += [w] if len(s) == 0: print(m) else: for j in range(len(s)): if s[j] > m: ans += (m * m) m -= m elif s[j] < m: ans += (s[j] * s[j]) m -= s[j] elif s[j] == m: ans += (s[j] * s[j]) m -= m print(ans + m) ```
0
352
B
Jeff and Periods
PROGRAMMING
1,300
[ "implementation", "sortings" ]
null
null
One day Jeff got hold of an integer sequence *a*1, *a*2, ..., *a**n* of length *n*. The boy immediately decided to analyze the sequence. For that, he needs to find all values of *x*, for which these conditions hold: - *x* occurs in sequence *a*. - Consider all positions of numbers *x* in the sequence *a* (such *i*, that *a**i*<==<=*x*). These numbers, sorted in the increasing order, must form an arithmetic progression. Help Jeff, find all *x* that meet the problem conditions.
The first line contains integer *n* (1<=≤<=*n*<=≤<=105). The next line contains integers *a*1, *a*2, ..., *a**n* (1<=≤<=*a**i*<=≤<=105). The numbers are separated by spaces.
In the first line print integer *t* — the number of valid *x*. On each of the next *t* lines print two integers *x* and *p**x*, where *x* is current suitable value, *p**x* is the common difference between numbers in the progression (if *x* occurs exactly once in the sequence, *p**x* must equal 0). Print the pairs in the order of increasing *x*.
[ "1\n2\n", "8\n1 2 1 3 1 2 1 5\n" ]
[ "1\n2 0\n", "4\n1 2\n2 4\n3 0\n5 0\n" ]
In the first test 2 occurs exactly once in the sequence, ergo *p*<sub class="lower-index">2</sub> = 0.
1,000
[ { "input": "1\n2", "output": "1\n2 0" }, { "input": "8\n1 2 1 3 1 2 1 5", "output": "4\n1 2\n2 4\n3 0\n5 0" }, { "input": "3\n1 10 5", "output": "3\n1 0\n5 0\n10 0" }, { "input": "4\n9 9 3 5", "output": "3\n3 0\n5 0\n9 1" }, { "input": "6\n1 2 2 1 1 2", "output": "0" }, { "input": "6\n2 6 3 8 7 2", "output": "5\n2 5\n3 0\n6 0\n7 0\n8 0" }, { "input": "7\n2 1 2 1 2 1 2", "output": "2\n1 2\n2 2" }, { "input": "8\n1 1 1 1 1 1 1 1", "output": "1\n1 1" }, { "input": "9\n2 3 3 3 2 1 2 3 2", "output": "1\n1 0" }, { "input": "10\n3 1 1 1 1 3 1 2 2 1", "output": "2\n2 1\n3 5" }, { "input": "12\n10 9 8 7 7 8 9 10 10 9 8 7", "output": "0" } ]
1,628,132,219
2,147,483,647
PyPy 3
WRONG_ANSWER
TESTS
0
154
20,172,800
def main(): n = int(input()) arr = list(map(int, input().split())) counts = dict() for i in range(n): if arr[i] in counts: counts[arr[i]].append(i) else: counts[arr[i]] = [i] counts = sorted(counts.items(), key=lambda x: x[0]) for k, v in counts: if len(v) == 1: print(k, 0) else: diff = set() for i in range(len(v) - 1): diff.add(v[i] - v[i + 1]) if len(diff) == 1: print(k, v[1] - v[0]) main()
Title: Jeff and Periods Time Limit: None seconds Memory Limit: None megabytes Problem Description: One day Jeff got hold of an integer sequence *a*1, *a*2, ..., *a**n* of length *n*. The boy immediately decided to analyze the sequence. For that, he needs to find all values of *x*, for which these conditions hold: - *x* occurs in sequence *a*. - Consider all positions of numbers *x* in the sequence *a* (such *i*, that *a**i*<==<=*x*). These numbers, sorted in the increasing order, must form an arithmetic progression. Help Jeff, find all *x* that meet the problem conditions. Input Specification: The first line contains integer *n* (1<=≤<=*n*<=≤<=105). The next line contains integers *a*1, *a*2, ..., *a**n* (1<=≤<=*a**i*<=≤<=105). The numbers are separated by spaces. Output Specification: In the first line print integer *t* — the number of valid *x*. On each of the next *t* lines print two integers *x* and *p**x*, where *x* is current suitable value, *p**x* is the common difference between numbers in the progression (if *x* occurs exactly once in the sequence, *p**x* must equal 0). Print the pairs in the order of increasing *x*. Demo Input: ['1\n2\n', '8\n1 2 1 3 1 2 1 5\n'] Demo Output: ['1\n2 0\n', '4\n1 2\n2 4\n3 0\n5 0\n'] Note: In the first test 2 occurs exactly once in the sequence, ergo *p*<sub class="lower-index">2</sub> = 0.
```python def main(): n = int(input()) arr = list(map(int, input().split())) counts = dict() for i in range(n): if arr[i] in counts: counts[arr[i]].append(i) else: counts[arr[i]] = [i] counts = sorted(counts.items(), key=lambda x: x[0]) for k, v in counts: if len(v) == 1: print(k, 0) else: diff = set() for i in range(len(v) - 1): diff.add(v[i] - v[i + 1]) if len(diff) == 1: print(k, v[1] - v[0]) main() ```
0
38
A
Army
PROGRAMMING
800
[ "implementation" ]
A. Army
2
256
The Berland Armed Forces System consists of *n* ranks that are numbered using natural numbers from 1 to *n*, where 1 is the lowest rank and *n* is the highest rank. One needs exactly *d**i* years to rise from rank *i* to rank *i*<=+<=1. Reaching a certain rank *i* having not reached all the previous *i*<=-<=1 ranks is impossible. Vasya has just reached a new rank of *a*, but he dreams of holding the rank of *b*. Find for how many more years Vasya should serve in the army until he can finally realize his dream.
The first input line contains an integer *n* (2<=≤<=*n*<=≤<=100). The second line contains *n*<=-<=1 integers *d**i* (1<=≤<=*d**i*<=≤<=100). The third input line contains two integers *a* and *b* (1<=≤<=*a*<=&lt;<=*b*<=≤<=*n*). The numbers on the lines are space-separated.
Print the single number which is the number of years that Vasya needs to rise from rank *a* to rank *b*.
[ "3\n5 6\n1 2\n", "3\n5 6\n1 3\n" ]
[ "5\n", "11\n" ]
none
0
[ { "input": "3\n5 6\n1 2", "output": "5" }, { "input": "3\n5 6\n1 3", "output": "11" }, { "input": "2\n55\n1 2", "output": "55" }, { "input": "3\n85 78\n1 3", "output": "163" }, { "input": "4\n63 4 49\n2 3", "output": "4" }, { "input": "5\n93 83 42 56\n2 5", "output": "181" }, { "input": "6\n22 9 87 89 57\n1 6", "output": "264" }, { "input": "7\n52 36 31 23 74 78\n2 7", "output": "242" }, { "input": "8\n82 14 24 5 91 49 94\n3 8", "output": "263" }, { "input": "9\n12 40 69 39 59 21 59 5\n4 6", "output": "98" }, { "input": "10\n95 81 32 59 71 30 50 61 100\n1 6", "output": "338" }, { "input": "15\n89 55 94 4 15 69 19 60 91 77 3 94 91 62\n3 14", "output": "617" }, { "input": "20\n91 1 41 51 95 67 92 35 23 70 44 91 57 50 21 8 9 71 40\n8 17", "output": "399" }, { "input": "25\n70 95 21 84 97 39 12 98 53 24 78 29 84 65 70 22 100 17 69 27 62 48 35 80\n8 23", "output": "846" }, { "input": "30\n35 69 50 44 19 56 86 56 98 24 21 2 61 24 85 30 2 22 57 35 59 84 12 77 92 53 50 92 9\n1 16", "output": "730" }, { "input": "35\n2 34 47 15 27 61 6 88 67 20 53 65 29 68 77 5 78 86 44 98 32 81 91 79 54 84 95 23 65 97 22 33 42 87\n8 35", "output": "1663" }, { "input": "40\n32 88 59 36 95 45 28 78 73 30 97 13 13 47 48 100 43 21 22 45 88 25 15 13 63 25 72 92 29 5 25 11 50 5 54 51 48 84 23\n7 26", "output": "862" }, { "input": "45\n83 74 73 95 10 31 100 26 29 15 80 100 22 70 31 88 9 56 19 70 2 62 48 30 27 47 52 50 94 44 21 94 23 85 15 3 95 72 43 62 94 89 68 88\n17 40", "output": "1061" }, { "input": "50\n28 8 16 29 19 82 70 51 96 84 74 72 17 69 12 21 37 21 39 3 18 66 19 49 86 96 94 93 2 90 96 84 59 88 58 15 61 33 55 22 35 54 51 29 64 68 29 38 40\n23 28", "output": "344" }, { "input": "60\n24 28 25 21 43 71 64 73 71 90 51 83 69 43 75 43 78 72 56 61 99 7 23 86 9 16 16 94 23 74 18 56 20 72 13 31 75 34 35 86 61 49 4 72 84 7 65 70 66 52 21 38 6 43 69 40 73 46 5\n28 60", "output": "1502" }, { "input": "70\n69 95 34 14 67 61 6 95 94 44 28 94 73 66 39 13 19 71 73 71 28 48 26 22 32 88 38 95 43 59 88 77 80 55 17 95 40 83 67 1 38 95 58 63 56 98 49 2 41 4 73 8 78 41 64 71 60 71 41 61 67 4 4 19 97 14 39 20 27\n9 41", "output": "1767" }, { "input": "80\n65 15 43 6 43 98 100 16 69 98 4 54 25 40 2 35 12 23 38 29 10 89 30 6 4 8 7 96 64 43 11 49 89 38 20 59 54 85 46 16 16 89 60 54 28 37 32 34 67 9 78 30 50 87 58 53 99 48 77 3 5 6 19 99 16 20 31 10 80 76 82 56 56 83 72 81 84 60 28\n18 24", "output": "219" }, { "input": "90\n61 35 100 99 67 87 42 90 44 4 81 65 29 63 66 56 53 22 55 87 39 30 34 42 27 80 29 97 85 28 81 22 50 22 24 75 67 86 78 79 94 35 13 97 48 76 68 66 94 13 82 1 22 85 5 36 86 73 65 97 43 56 35 26 87 25 74 47 81 67 73 75 99 75 53 38 70 21 66 78 38 17 57 40 93 57 68 55 1\n12 44", "output": "1713" }, { "input": "95\n37 74 53 96 65 84 65 72 95 45 6 77 91 35 58 50 51 51 97 30 51 20 79 81 92 10 89 34 40 76 71 54 26 34 73 72 72 28 53 19 95 64 97 10 44 15 12 38 5 63 96 95 86 8 36 96 45 53 81 5 18 18 47 97 65 9 33 53 41 86 37 53 5 40 15 76 83 45 33 18 26 5 19 90 46 40 100 42 10 90 13 81 40 53\n6 15", "output": "570" }, { "input": "96\n51 32 95 75 23 54 70 89 67 3 1 51 4 100 97 30 9 35 56 38 54 77 56 98 43 17 60 43 72 46 87 61 100 65 81 22 74 38 16 96 5 10 54 22 23 22 10 91 9 54 49 82 29 73 33 98 75 8 4 26 24 90 71 42 90 24 94 74 94 10 41 98 56 63 18 43 56 21 26 64 74 33 22 38 67 66 38 60 64 76 53 10 4 65 76\n21 26", "output": "328" }, { "input": "97\n18 90 84 7 33 24 75 55 86 10 96 72 16 64 37 9 19 71 62 97 5 34 85 15 46 72 82 51 52 16 55 68 27 97 42 72 76 97 32 73 14 56 11 86 2 81 59 95 60 93 1 22 71 37 77 100 6 16 78 47 78 62 94 86 16 91 56 46 47 35 93 44 7 86 70 10 29 45 67 62 71 61 74 39 36 92 24 26 65 14 93 92 15 28 79 59\n6 68", "output": "3385" }, { "input": "98\n32 47 26 86 43 42 79 72 6 68 40 46 29 80 24 89 29 7 21 56 8 92 13 33 50 79 5 7 84 85 24 23 1 80 51 21 26 55 96 51 24 2 68 98 81 88 57 100 64 84 54 10 14 2 74 1 89 71 1 20 84 85 17 31 42 58 69 67 48 60 97 90 58 10 21 29 2 21 60 61 68 89 77 39 57 18 61 44 67 100 33 74 27 40 83 29 6\n8 77", "output": "3319" }, { "input": "99\n46 5 16 66 53 12 84 89 26 27 35 68 41 44 63 17 88 43 80 15 59 1 42 50 53 34 75 16 16 55 92 30 28 11 12 71 27 65 11 28 86 47 24 10 60 47 7 53 16 75 6 49 56 66 70 3 20 78 75 41 38 57 89 23 16 74 30 39 1 32 49 84 9 33 25 95 75 45 54 59 17 17 29 40 79 96 47 11 69 86 73 56 91 4 87 47 31 24\n23 36", "output": "514" }, { "input": "100\n63 65 21 41 95 23 3 4 12 23 95 50 75 63 58 34 71 27 75 31 23 94 96 74 69 34 43 25 25 55 44 19 43 86 68 17 52 65 36 29 72 96 84 25 84 23 71 54 6 7 71 7 21 100 99 58 93 35 62 47 36 70 68 9 75 13 35 70 76 36 62 22 52 51 2 87 66 41 54 35 78 62 30 35 65 44 74 93 78 37 96 70 26 32 71 27 85 85 63\n43 92", "output": "2599" }, { "input": "51\n85 38 22 38 42 36 55 24 36 80 49 15 66 91 88 61 46 82 1 61 89 92 6 56 28 8 46 80 56 90 91 38 38 17 69 64 57 68 13 44 45 38 8 72 61 39 87 2 73 88\n15 27", "output": "618" }, { "input": "2\n3\n1 2", "output": "3" }, { "input": "5\n6 8 22 22\n2 3", "output": "8" }, { "input": "6\n3 12 27 28 28\n3 4", "output": "27" }, { "input": "9\n1 2 2 2 2 3 3 5\n3 7", "output": "9" }, { "input": "10\n1 1 1 1 1 1 1 1 1\n6 8", "output": "2" }, { "input": "20\n1 1 1 1 1 1 1 1 2 2 2 2 2 3 3 3 3 3 3\n5 17", "output": "23" }, { "input": "25\n1 1 1 4 5 6 8 11 11 11 11 12 13 14 14 14 15 16 16 17 17 17 19 19\n4 8", "output": "23" }, { "input": "35\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2\n30 31", "output": "2" }, { "input": "45\n1 1 1 1 2 2 2 2 2 2 2 3 3 3 3 3 3 4 5 5 5 5 6 6 6 6 6 6 6 7 7 7 7 8 8 8 9 9 9 9 9 10 10 10\n42 45", "output": "30" }, { "input": "50\n1 8 8 13 14 15 15 16 19 21 22 24 26 31 32 37 45 47 47 47 50 50 51 54 55 56 58 61 61 61 63 63 64 66 66 67 67 70 71 80 83 84 85 92 92 94 95 95 100\n4 17", "output": "285" }, { "input": "60\n1 2 4 4 4 6 6 8 9 10 10 13 14 18 20 20 21 22 23 23 26 29 30 32 33 34 35 38 40 42 44 44 46 48 52 54 56 56 60 60 66 67 68 68 69 73 73 74 80 80 81 81 82 84 86 86 87 89 89\n56 58", "output": "173" }, { "input": "70\n1 2 3 3 4 5 5 7 7 7 8 8 8 8 9 9 10 12 12 12 12 13 16 16 16 16 16 16 17 17 18 18 20 20 21 23 24 25 25 26 29 29 29 29 31 32 32 34 35 36 36 37 37 38 39 39 40 40 40 40 41 41 42 43 44 44 44 45 45\n62 65", "output": "126" }, { "input": "80\n1 1 1 1 1 1 1 1 2 2 2 2 2 2 3 3 3 3 3 3 3 3 3 3 4 4 4 4 5 5 5 5 5 5 5 6 7 7 7 7 7 7 8 8 8 8 9 9 9 9 9 9 9 9 9 10 10 10 10 10 10 10 10 10 11 11 11 11 11 11 11 12 12 12 12 12 12 12 12\n17 65", "output": "326" }, { "input": "90\n1 1 3 5 8 9 10 11 11 11 11 12 13 14 15 15 15 16 16 19 19 20 22 23 24 25 25 28 29 29 30 31 33 34 35 37 37 38 41 43 43 44 45 47 51 54 55 56 58 58 59 59 60 62 66 67 67 67 68 68 69 70 71 72 73 73 76 77 77 78 78 78 79 79 79 82 83 84 85 85 87 87 89 93 93 93 95 99 99\n28 48", "output": "784" }, { "input": "95\n2 2 3 3 4 6 6 7 7 7 9 10 12 12 12 12 13 14 15 16 17 18 20 20 20 20 21 21 21 21 22 22 22 22 22 23 23 23 25 26 26 27 27 27 28 29 29 30 30 31 32 33 34 36 37 37 38 39 39 39 42 43 43 43 45 47 48 50 50 51 52 53 54 54 54 55 55 55 58 59 60 61 61 61 61 62 62 63 64 65 66 67 67 67\n64 93", "output": "1636" }, { "input": "96\n1 1 2 3 3 5 8 9 9 10 10 10 11 11 11 11 11 12 13 13 13 14 15 15 16 16 17 17 17 17 18 18 20 20 20 21 21 21 23 24 24 25 25 26 27 27 27 27 29 29 29 30 30 30 32 32 32 32 32 32 33 33 34 34 34 35 35 35 36 36 37 37 37 38 39 40 41 41 41 41 42 42 43 43 45 45 45 46 46 47 47 49 50 52 52\n76 96", "output": "898" }, { "input": "98\n2 3 4 4 5 7 8 10 10 10 11 11 12 12 12 12 13 14 15 15 16 16 18 19 19 20 21 21 21 21 22 23 24 25 26 26 27 27 27 27 29 29 30 30 31 31 37 40 40 40 41 41 41 42 43 44 44 44 46 46 47 49 49 50 50 50 51 53 55 55 56 56 56 56 56 57 57 58 59 60 60 60 62 62 63 64 64 64 65 66 66 67 68 70 70 71 71\n8 90", "output": "3016" }, { "input": "99\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1\n66 95", "output": "29" }, { "input": "100\n1 1 1 1 1 1 1 1 2 2 2 2 2 2 2 2 3 3 3 4 4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 6 6 6 6 6 6 6 6 6 6 6 6 7 7 7 7 7 7 8 8 8 8 9 9 9 9 10 10 10 10 11 11 11 11 12 12 12 13 13 13 13 13 13 13 13 13 13 14 14 14 14 14 14 15 15 15 15 15 15 16 16 16 17 17\n39 52", "output": "82" }, { "input": "51\n5 7 9 16 19 25 26 29 29 30 31 32 32 41 43 44 47 49 50 50 51 52 54 55 56 63 64 66 67 70 74 74 77 78 79 80 80 85 86 87 89 89 90 92 93 94 94 95 95 97\n3 44", "output": "2268" } ]
1,574,642,509
2,147,483,647
Python 3
OK
TESTS
50
218
0
def sr(ch): ch1=ch+' ' l=[] p='' for i in ch1: if i!=' ': p=p+i else: l.append(int(p)) p='' return l n=int(input()) y=str(input()) z=str(input()) l=sr(y) p=sr(z) a=p[0]-1 b=p[1]-1 k=0 for i in range(a,b): k=k+l[i] print(k)
Title: Army Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: The Berland Armed Forces System consists of *n* ranks that are numbered using natural numbers from 1 to *n*, where 1 is the lowest rank and *n* is the highest rank. One needs exactly *d**i* years to rise from rank *i* to rank *i*<=+<=1. Reaching a certain rank *i* having not reached all the previous *i*<=-<=1 ranks is impossible. Vasya has just reached a new rank of *a*, but he dreams of holding the rank of *b*. Find for how many more years Vasya should serve in the army until he can finally realize his dream. Input Specification: The first input line contains an integer *n* (2<=≤<=*n*<=≤<=100). The second line contains *n*<=-<=1 integers *d**i* (1<=≤<=*d**i*<=≤<=100). The third input line contains two integers *a* and *b* (1<=≤<=*a*<=&lt;<=*b*<=≤<=*n*). The numbers on the lines are space-separated. Output Specification: Print the single number which is the number of years that Vasya needs to rise from rank *a* to rank *b*. Demo Input: ['3\n5 6\n1 2\n', '3\n5 6\n1 3\n'] Demo Output: ['5\n', '11\n'] Note: none
```python def sr(ch): ch1=ch+' ' l=[] p='' for i in ch1: if i!=' ': p=p+i else: l.append(int(p)) p='' return l n=int(input()) y=str(input()) z=str(input()) l=sr(y) p=sr(z) a=p[0]-1 b=p[1]-1 k=0 for i in range(a,b): k=k+l[i] print(k) ```
3.9455
873
B
Balanced Substring
PROGRAMMING
1,500
[ "dp", "implementation" ]
null
null
You are given a string *s* consisting only of characters 0 and 1. A substring [*l*,<=*r*] of *s* is a string *s**l**s**l*<=+<=1*s**l*<=+<=2... *s**r*, and its length equals to *r*<=-<=*l*<=+<=1. A substring is called balanced if the number of zeroes (0) equals to the number of ones in this substring. You have to determine the length of the longest balanced substring of *s*.
The first line contains *n* (1<=≤<=*n*<=≤<=100000) — the number of characters in *s*. The second line contains a string *s* consisting of exactly *n* characters. Only characters 0 and 1 can appear in *s*.
If there is no non-empty balanced substring in *s*, print 0. Otherwise, print the length of the longest balanced substring.
[ "8\n11010111\n", "3\n111\n" ]
[ "4\n", "0\n" ]
In the first example you can choose the substring [3, 6]. It is balanced, and its length is 4. Choosing the substring [2, 5] is also possible. In the second example it's impossible to find a non-empty balanced substring.
0
[ { "input": "8\n11010111", "output": "4" }, { "input": "3\n111", "output": "0" }, { "input": "11\n00001000100", "output": "2" }, { "input": "10\n0100000000", "output": "2" }, { "input": "13\n0001000011010", "output": "6" }, { "input": "14\n00000100101011", "output": "10" }, { "input": "14\n01111101111111", "output": "2" }, { "input": "18\n110010101101111111", "output": "10" }, { "input": "11\n00010000011", "output": "4" }, { "input": "10\n1000010110", "output": "6" }, { "input": "15\n100000100000011", "output": "4" }, { "input": "18\n011010101110111101", "output": "8" }, { "input": "10\n0011011111", "output": "6" }, { "input": "3\n011", "output": "2" }, { "input": "14\n11111111111111", "output": "0" }, { "input": "65\n11001000110001001011011110111100000000101001001010101111000100010", "output": "48" }, { "input": "10\n0011111000", "output": "10" }, { "input": "13\n1110000001110", "output": "12" }, { "input": "3\n110", "output": "2" }, { "input": "4\n1110", "output": "2" }, { "input": "9\n001011001", "output": "8" }, { "input": "2\n10", "output": "2" }, { "input": "2\n01", "output": "2" }, { "input": "12\n110000110000", "output": "8" }, { "input": "3\n001", "output": "2" }, { "input": "14\n11000011000000", "output": "8" }, { "input": "19\n0000011111111100000", "output": "18" }, { "input": "45\n011010001100001111110001011100000001101100111", "output": "44" }, { "input": "18\n000001111111100000", "output": "16" }, { "input": "4\n0101", "output": "4" }, { "input": "12\n000101011001", "output": "10" } ]
1,518,618,222
2,147,483,647
Python 3
OK
TESTS
53
124
14,233,600
n=int(input()) T=input() d={0:-1} s=0 mix=0 for i in range(n): s+=1-(T[i]=='0')*2 if s not in d: d[s]=i else: if(i-d[s])> mix: mix=i-d[s] print(mix)
Title: Balanced Substring Time Limit: None seconds Memory Limit: None megabytes Problem Description: You are given a string *s* consisting only of characters 0 and 1. A substring [*l*,<=*r*] of *s* is a string *s**l**s**l*<=+<=1*s**l*<=+<=2... *s**r*, and its length equals to *r*<=-<=*l*<=+<=1. A substring is called balanced if the number of zeroes (0) equals to the number of ones in this substring. You have to determine the length of the longest balanced substring of *s*. Input Specification: The first line contains *n* (1<=≤<=*n*<=≤<=100000) — the number of characters in *s*. The second line contains a string *s* consisting of exactly *n* characters. Only characters 0 and 1 can appear in *s*. Output Specification: If there is no non-empty balanced substring in *s*, print 0. Otherwise, print the length of the longest balanced substring. Demo Input: ['8\n11010111\n', '3\n111\n'] Demo Output: ['4\n', '0\n'] Note: In the first example you can choose the substring [3, 6]. It is balanced, and its length is 4. Choosing the substring [2, 5] is also possible. In the second example it's impossible to find a non-empty balanced substring.
```python n=int(input()) T=input() d={0:-1} s=0 mix=0 for i in range(n): s+=1-(T[i]=='0')*2 if s not in d: d[s]=i else: if(i-d[s])> mix: mix=i-d[s] print(mix) ```
3
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,678,526,109
2,147,483,647
Python 3
OK
TESTS
36
122
409,600
from fractions import Fraction y,w=map(int,input().split()) m=max(y,w) c=0 for i in range(m,7): c=c+1 if c==0: print("0/1") elif c==1: print("1/6") elif c==2: print("1/3") elif c==3: print("1/2") elif c==4: print("2/3") elif c==5: print("5/6") elif c==6: print("1/1")
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 from fractions import Fraction y,w=map(int,input().split()) m=max(y,w) c=0 for i in range(m,7): c=c+1 if c==0: print("0/1") elif c==1: print("1/6") elif c==2: print("1/3") elif c==3: print("1/2") elif c==4: print("2/3") elif c==5: print("5/6") elif c==6: print("1/1") ```
3.935948
192
A
Funky Numbers
PROGRAMMING
1,300
[ "binary search", "brute force", "implementation" ]
null
null
As you very well know, this year's funkiest numbers are so called triangular numbers (that is, integers that are representable as , where *k* is some positive integer), and the coolest numbers are those that are representable as a sum of two triangular numbers. A well-known hipster Andrew adores everything funky and cool but unfortunately, he isn't good at maths. Given number *n*, help him define whether this number can be represented by a sum of two triangular numbers (not necessarily different)!
The first input line contains an integer *n* (1<=≤<=*n*<=≤<=109).
Print "YES" (without the quotes), if *n* can be represented as a sum of two triangular numbers, otherwise print "NO" (without the quotes).
[ "256\n", "512\n" ]
[ "YES\n", "NO\n" ]
In the first sample number <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/92095692c6ea93e9e3b837a0408ba7543549d5b2.png" style="max-width: 100.0%;max-height: 100.0%;"/>. In the second sample number 512 can not be represented as a sum of two triangular numbers.
500
[ { "input": "256", "output": "YES" }, { "input": "512", "output": "NO" }, { "input": "80", "output": "NO" }, { "input": "828", "output": "YES" }, { "input": "6035", "output": "NO" }, { "input": "39210", "output": "YES" }, { "input": "79712", "output": "NO" }, { "input": "190492", "output": "YES" }, { "input": "5722367", "output": "NO" }, { "input": "816761542", "output": "YES" }, { "input": "1", "output": "NO" }, { "input": "2", "output": "YES" }, { "input": "3", "output": "NO" }, { "input": "4", "output": "YES" }, { "input": "5", "output": "NO" }, { "input": "6", "output": "YES" }, { "input": "7", "output": "YES" }, { "input": "8", "output": "NO" }, { "input": "9", "output": "YES" }, { "input": "10", "output": "NO" }, { "input": "12", "output": "YES" }, { "input": "13", "output": "YES" }, { "input": "14", "output": "NO" }, { "input": "15", "output": "NO" }, { "input": "16", "output": "YES" }, { "input": "17", "output": "NO" }, { "input": "18", "output": "YES" }, { "input": "19", "output": "NO" }, { "input": "20", "output": "YES" }, { "input": "41", "output": "NO" }, { "input": "11", "output": "YES" }, { "input": "69", "output": "YES" }, { "input": "82", "output": "NO" }, { "input": "85", "output": "NO" }, { "input": "736", "output": "NO" }, { "input": "895", "output": "YES" }, { "input": "934", "output": "YES" }, { "input": "6213", "output": "YES" }, { "input": "7405", "output": "NO" }, { "input": "9919", "output": "NO" }, { "input": "40942", "output": "YES" }, { "input": "41992", "output": "NO" }, { "input": "68535", "output": "NO" }, { "input": "405718", "output": "NO" }, { "input": "1046146", "output": "YES" }, { "input": "3761248", "output": "YES" }, { "input": "6195181", "output": "YES" }, { "input": "35354345", "output": "NO" }, { "input": "81282830", "output": "NO" }, { "input": "187719774", "output": "NO" }, { "input": "296798673", "output": "NO" }, { "input": "938938476", "output": "NO" }, { "input": "1000000000", "output": "NO" }, { "input": "999887464", "output": "YES" }, { "input": "999111944", "output": "NO" }, { "input": "999966520", "output": "YES" }, { "input": "999912080", "output": "NO" }, { "input": "999992017", "output": "YES" }, { "input": "999990474", "output": "NO" }, { "input": "999999190", "output": "YES" }, { "input": "999999125", "output": "NO" }, { "input": "999999940", "output": "YES" }, { "input": "999999995", "output": "NO" }, { "input": "1000000000", "output": "NO" }, { "input": "1", "output": "NO" }, { "input": "999999999", "output": "YES" }, { "input": "83495494", "output": "NO" }, { "input": "968022000", "output": "YES" }, { "input": "399980000", "output": "YES" }, { "input": "4", "output": "YES" }, { "input": "999999998", "output": "NO" } ]
1,466,259,493
2,147,483,647
Python 3
COMPILATION_ERROR
TESTS
0
0
0
import math def istr(x): ch=0 for k in range(math.sqrt(2*x)): if x=k*(k+1)/2: return True return False n=int(input()) ch=0 for i in range(math.sqrt(2*n)): if istr(n-i*(i+1)/2): ch=1 print('YES') break if ch==0: print('NO')
Title: Funky Numbers Time Limit: None seconds Memory Limit: None megabytes Problem Description: As you very well know, this year's funkiest numbers are so called triangular numbers (that is, integers that are representable as , where *k* is some positive integer), and the coolest numbers are those that are representable as a sum of two triangular numbers. A well-known hipster Andrew adores everything funky and cool but unfortunately, he isn't good at maths. Given number *n*, help him define whether this number can be represented by a sum of two triangular numbers (not necessarily different)! Input Specification: The first input line contains an integer *n* (1<=≤<=*n*<=≤<=109). Output Specification: Print "YES" (without the quotes), if *n* can be represented as a sum of two triangular numbers, otherwise print "NO" (without the quotes). Demo Input: ['256\n', '512\n'] Demo Output: ['YES\n', 'NO\n'] Note: In the first sample number <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/92095692c6ea93e9e3b837a0408ba7543549d5b2.png" style="max-width: 100.0%;max-height: 100.0%;"/>. In the second sample number 512 can not be represented as a sum of two triangular numbers.
```python import math def istr(x): ch=0 for k in range(math.sqrt(2*x)): if x=k*(k+1)/2: return True return False n=int(input()) ch=0 for i in range(math.sqrt(2*n)): if istr(n-i*(i+1)/2): ch=1 print('YES') break if ch==0: print('NO') ```
-1
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,681,909,563
2,147,483,647
Python 3
OK
TESTS
44
92
0
s=input() start='a' count=0 for i in s: diff=abs(ord(i)-ord(start)) count+=min(diff,26-diff) start=i print(count)
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=input() start='a' count=0 for i in s: diff=abs(ord(i)-ord(start)) count+=min(diff,26-diff) start=i print(count) ```
3
118
A
String Task
PROGRAMMING
1,000
[ "implementation", "strings" ]
null
null
Petya started to attend programming lessons. On the first lesson his task was to write a simple program. The program was supposed to do the following: in the given string, consisting if uppercase and lowercase Latin letters, it: - deletes all the vowels, - inserts a character "." before each consonant, - replaces all uppercase consonants with corresponding lowercase ones. Vowels are letters "A", "O", "Y", "E", "U", "I", and the rest are consonants. The program's input is exactly one string, it should return the output as a single string, resulting after the program's processing the initial string. Help Petya cope with this easy task.
The first line represents input string of Petya's program. This string only consists of uppercase and lowercase Latin letters and its length is from 1 to 100, inclusive.
Print the resulting string. It is guaranteed that this string is not empty.
[ "tour\n", "Codeforces\n", "aBAcAba\n" ]
[ ".t.r\n", ".c.d.f.r.c.s\n", ".b.c.b\n" ]
none
500
[ { "input": "tour", "output": ".t.r" }, { "input": "Codeforces", "output": ".c.d.f.r.c.s" }, { "input": "aBAcAba", "output": ".b.c.b" }, { "input": "obn", "output": ".b.n" }, { "input": "wpwl", "output": ".w.p.w.l" }, { "input": "ggdvq", "output": ".g.g.d.v.q" }, { "input": "pumesz", "output": ".p.m.s.z" }, { "input": "g", "output": ".g" }, { "input": "zjuotps", "output": ".z.j.t.p.s" }, { "input": "jzbwuehe", "output": ".j.z.b.w.h" }, { "input": "tnkgwuugu", "output": ".t.n.k.g.w.g" }, { "input": "kincenvizh", "output": ".k.n.c.n.v.z.h" }, { "input": "xattxjenual", "output": ".x.t.t.x.j.n.l" }, { "input": "ktajqhpqsvhw", "output": ".k.t.j.q.h.p.q.s.v.h.w" }, { "input": "xnhcigytnqcmy", "output": ".x.n.h.c.g.t.n.q.c.m" }, { "input": "jfmtbejyilxcec", "output": ".j.f.m.t.b.j.l.x.c.c" }, { "input": "D", "output": ".d" }, { "input": "ab", "output": ".b" }, { "input": "Ab", "output": ".b" }, { "input": "aB", "output": ".b" }, { "input": "AB", "output": ".b" }, { "input": "ba", "output": ".b" }, { "input": "bA", "output": ".b" }, { "input": "Ba", "output": ".b" }, { "input": "BA", "output": ".b" }, { "input": "aab", "output": ".b" }, { "input": "baa", "output": ".b" }, { "input": "femOZeCArKCpUiHYnbBPTIOFmsHmcpObtPYcLCdjFrUMIyqYzAokKUiiKZRouZiNMoiOuGVoQzaaCAOkquRjmmKKElLNqCnhGdQM", "output": ".f.m.z.c.r.k.c.p.h.n.b.b.p.t.f.m.s.h.m.c.p.b.t.p.c.l.c.d.j.f.r.m.q.z.k.k.k.z.r.z.n.m.g.v.q.z.c.k.q.r.j.m.m.k.k.l.l.n.q.c.n.h.g.d.q.m" }, { "input": "VMBPMCmMDCLFELLIISUJDWQRXYRDGKMXJXJHXVZADRZWVWJRKFRRNSAWKKDPZZLFLNSGUNIVJFBEQsMDHSBJVDTOCSCgZWWKvZZN", "output": ".v.m.b.p.m.c.m.m.d.c.l.f.l.l.s.j.d.w.q.r.x.r.d.g.k.m.x.j.x.j.h.x.v.z.d.r.z.w.v.w.j.r.k.f.r.r.n.s.w.k.k.d.p.z.z.l.f.l.n.s.g.n.v.j.f.b.q.s.m.d.h.s.b.j.v.d.t.c.s.c.g.z.w.w.k.v.z.z.n" }, { "input": "MCGFQQJNUKuAEXrLXibVjClSHjSxmlkQGTKZrRaDNDomIPOmtSgjJAjNVIVLeUGUAOHNkCBwNObVCHOWvNkLFQQbFnugYVMkJruJ", "output": ".m.c.g.f.q.q.j.n.k.x.r.l.x.b.v.j.c.l.s.h.j.s.x.m.l.k.q.g.t.k.z.r.r.d.n.d.m.p.m.t.s.g.j.j.j.n.v.v.l.g.h.n.k.c.b.w.n.b.v.c.h.w.v.n.k.l.f.q.q.b.f.n.g.v.m.k.j.r.j" }, { "input": "iyaiuiwioOyzUaOtAeuEYcevvUyveuyioeeueoeiaoeiavizeeoeyYYaaAOuouueaUioueauayoiuuyiuovyOyiyoyioaoyuoyea", "output": ".w.z.t.c.v.v.v.v.z.v" }, { "input": "yjnckpfyLtzwjsgpcrgCfpljnjwqzgVcufnOvhxplvflxJzqxnhrwgfJmPzifgubvspffmqrwbzivatlmdiBaddiaktdsfPwsevl", "output": ".j.n.c.k.p.f.l.t.z.w.j.s.g.p.c.r.g.c.f.p.l.j.n.j.w.q.z.g.v.c.f.n.v.h.x.p.l.v.f.l.x.j.z.q.x.n.h.r.w.g.f.j.m.p.z.f.g.b.v.s.p.f.f.m.q.r.w.b.z.v.t.l.m.d.b.d.d.k.t.d.s.f.p.w.s.v.l" }, { "input": "RIIIUaAIYJOiuYIUWFPOOAIuaUEZeIooyUEUEAoIyIHYOEAlVAAIiLUAUAeiUIEiUMuuOiAgEUOIAoOUYYEYFEoOIIVeOOAOIIEg", "output": ".r.j.w.f.p.z.h.l.v.l.m.g.f.v.g" }, { "input": "VBKQCFBMQHDMGNSGBQVJTGQCNHHRJMNKGKDPPSQRRVQTZNKBZGSXBPBRXPMVFTXCHZMSJVBRNFNTHBHGJLMDZJSVPZZBCCZNVLMQ", "output": ".v.b.k.q.c.f.b.m.q.h.d.m.g.n.s.g.b.q.v.j.t.g.q.c.n.h.h.r.j.m.n.k.g.k.d.p.p.s.q.r.r.v.q.t.z.n.k.b.z.g.s.x.b.p.b.r.x.p.m.v.f.t.x.c.h.z.m.s.j.v.b.r.n.f.n.t.h.b.h.g.j.l.m.d.z.j.s.v.p.z.z.b.c.c.z.n.v.l.m.q" }, { "input": "iioyoaayeuyoolyiyoeuouiayiiuyTueyiaoiueyioiouyuauouayyiaeoeiiigmioiououeieeeyuyyaYyioiiooaiuouyoeoeg", "output": ".l.t.g.m.g" }, { "input": "ueyiuiauuyyeueykeioouiiauzoyoeyeuyiaoaiiaaoaueyaeydaoauexuueafouiyioueeaaeyoeuaueiyiuiaeeayaioeouiuy", "output": ".k.z.d.x.f" }, { "input": "FSNRBXLFQHZXGVMKLQDVHWLDSLKGKFMDRQWMWSSKPKKQBNDZRSCBLRSKCKKFFKRDMZFZGCNSMXNPMZVDLKXGNXGZQCLRTTDXLMXQ", "output": ".f.s.n.r.b.x.l.f.q.h.z.x.g.v.m.k.l.q.d.v.h.w.l.d.s.l.k.g.k.f.m.d.r.q.w.m.w.s.s.k.p.k.k.q.b.n.d.z.r.s.c.b.l.r.s.k.c.k.k.f.f.k.r.d.m.z.f.z.g.c.n.s.m.x.n.p.m.z.v.d.l.k.x.g.n.x.g.z.q.c.l.r.t.t.d.x.l.m.x.q" }, { "input": "EYAYAYIOIOYOOAUOEUEUOUUYIYUUMOEOIIIAOIUOAAOIYOIOEUIERCEYYAOIOIGYUIAOYUEOEUAEAYPOYEYUUAUOAOEIYIEYUEEY", "output": ".m.r.c.g.p" }, { "input": "jvvzcdcxjstbbksmqjsngxkgtttdxrljjxtwptgwwqzpvqchvgrkqlzxmptzblxhhsmrkmzzmgdfskhtmmnqzzflpmqdctvrfgtx", "output": ".j.v.v.z.c.d.c.x.j.s.t.b.b.k.s.m.q.j.s.n.g.x.k.g.t.t.t.d.x.r.l.j.j.x.t.w.p.t.g.w.w.q.z.p.v.q.c.h.v.g.r.k.q.l.z.x.m.p.t.z.b.l.x.h.h.s.m.r.k.m.z.z.m.g.d.f.s.k.h.t.m.m.n.q.z.z.f.l.p.m.q.d.c.t.v.r.f.g.t.x" }, { "input": "YB", "output": ".b" }, { "input": "fly", "output": ".f.l" }, { "input": "YyyYYYyyYxdwdawdDAWDdaddYYYY", "output": ".x.d.w.d.w.d.d.w.d.d.d.d" } ]
1,693,891,266
2,147,483,647
PyPy 3-64
WRONG_ANSWER
TESTS
14
216
0
x = input() y = ["a", "A", "e", "E", "i", "I", "o", "O", "u", "U"] x_new = "" def string_mod(x, y, x_new): if x == "": return x_new if x[0] in y: return string_mod(x[1:], y, x_new) if 64<ord(x[0])<91 or 96<ord(x[0])<123: if 64<ord(x[0])<91: x_new+=f".{chr(ord(x[0])+32)}" return string_mod(x[1:], y, x_new) x_new+=f".{x[0]}" return string_mod(x[1:], y, x_new) print(string_mod(x, y, x_new))
Title: String Task Time Limit: None seconds Memory Limit: None megabytes Problem Description: Petya started to attend programming lessons. On the first lesson his task was to write a simple program. The program was supposed to do the following: in the given string, consisting if uppercase and lowercase Latin letters, it: - deletes all the vowels, - inserts a character "." before each consonant, - replaces all uppercase consonants with corresponding lowercase ones. Vowels are letters "A", "O", "Y", "E", "U", "I", and the rest are consonants. The program's input is exactly one string, it should return the output as a single string, resulting after the program's processing the initial string. Help Petya cope with this easy task. Input Specification: The first line represents input string of Petya's program. This string only consists of uppercase and lowercase Latin letters and its length is from 1 to 100, inclusive. Output Specification: Print the resulting string. It is guaranteed that this string is not empty. Demo Input: ['tour\n', 'Codeforces\n', 'aBAcAba\n'] Demo Output: ['.t.r\n', '.c.d.f.r.c.s\n', '.b.c.b\n'] Note: none
```python x = input() y = ["a", "A", "e", "E", "i", "I", "o", "O", "u", "U"] x_new = "" def string_mod(x, y, x_new): if x == "": return x_new if x[0] in y: return string_mod(x[1:], y, x_new) if 64<ord(x[0])<91 or 96<ord(x[0])<123: if 64<ord(x[0])<91: x_new+=f".{chr(ord(x[0])+32)}" return string_mod(x[1:], y, x_new) x_new+=f".{x[0]}" return string_mod(x[1:], y, x_new) print(string_mod(x, y, x_new)) ```
0
459
A
Pashmak and Garden
PROGRAMMING
1,200
[ "implementation" ]
null
null
Pashmak has fallen in love with an attractive girl called Parmida since one year ago... Today, Pashmak set up a meeting with his partner in a romantic garden. Unfortunately, Pashmak has forgotten where the garden is. But he remembers that the garden looks like a square with sides parallel to the coordinate axes. He also remembers that there is exactly one tree on each vertex of the square. Now, Pashmak knows the position of only two of the trees. Help him to find the position of two remaining ones.
The first line contains four space-separated *x*1,<=*y*1,<=*x*2,<=*y*2 (<=-<=100<=≤<=*x*1,<=*y*1,<=*x*2,<=*y*2<=≤<=100) integers, where *x*1 and *y*1 are coordinates of the first tree and *x*2 and *y*2 are coordinates of the second tree. It's guaranteed that the given points are distinct.
If there is no solution to the problem, print -1. Otherwise print four space-separated integers *x*3,<=*y*3,<=*x*4,<=*y*4 that correspond to the coordinates of the two other trees. If there are several solutions you can output any of them. Note that *x*3,<=*y*3,<=*x*4,<=*y*4 must be in the range (<=-<=1000<=≤<=*x*3,<=*y*3,<=*x*4,<=*y*4<=≤<=1000).
[ "0 0 0 1\n", "0 0 1 1\n", "0 0 1 2\n" ]
[ "1 0 1 1\n", "0 1 1 0\n", "-1\n" ]
none
500
[ { "input": "0 0 0 1", "output": "1 0 1 1" }, { "input": "0 0 1 1", "output": "0 1 1 0" }, { "input": "0 0 1 2", "output": "-1" }, { "input": "-100 -100 100 100", "output": "-100 100 100 -100" }, { "input": "-100 -100 99 100", "output": "-1" }, { "input": "0 -100 0 100", "output": "200 -100 200 100" }, { "input": "27 -74 27 74", "output": "175 -74 175 74" }, { "input": "0 1 2 3", "output": "0 3 2 1" }, { "input": "-100 100 100 -100", "output": "-100 -100 100 100" }, { "input": "-100 -100 -100 100", "output": "100 -100 100 100" }, { "input": "100 100 100 -100", "output": "300 100 300 -100" }, { "input": "100 -100 -100 -100", "output": "100 100 -100 100" }, { "input": "-100 100 100 100", "output": "-100 300 100 300" }, { "input": "0 1 0 0", "output": "1 1 1 0" }, { "input": "1 1 0 0", "output": "1 0 0 1" }, { "input": "0 0 1 0", "output": "0 1 1 1" }, { "input": "1 0 0 1", "output": "1 1 0 0" }, { "input": "1 0 1 1", "output": "2 0 2 1" }, { "input": "1 1 0 1", "output": "1 2 0 2" }, { "input": "15 -9 80 -9", "output": "15 56 80 56" }, { "input": "51 -36 18 83", "output": "-1" }, { "input": "69 -22 60 16", "output": "-1" }, { "input": "-68 -78 -45 -55", "output": "-68 -55 -45 -78" }, { "input": "68 -92 8 -32", "output": "68 -32 8 -92" }, { "input": "95 -83 -39 -6", "output": "-1" }, { "input": "54 94 53 -65", "output": "-1" }, { "input": "-92 15 84 15", "output": "-92 191 84 191" }, { "input": "67 77 -11 -1", "output": "67 -1 -11 77" }, { "input": "91 -40 30 21", "output": "91 21 30 -40" }, { "input": "66 -64 -25 -64", "output": "66 27 -25 27" }, { "input": "-42 84 -67 59", "output": "-42 59 -67 84" }, { "input": "73 47 -5 -77", "output": "-1" }, { "input": "6 85 -54 -84", "output": "-1" }, { "input": "-58 -55 40 43", "output": "-58 43 40 -55" }, { "input": "56 22 48 70", "output": "-1" }, { "input": "-17 -32 76 -32", "output": "-17 61 76 61" }, { "input": "0 2 2 0", "output": "0 0 2 2" }, { "input": "0 0 -1 1", "output": "0 1 -1 0" }, { "input": "0 2 1 1", "output": "0 1 1 2" }, { "input": "0 0 1 -1", "output": "0 -1 1 0" }, { "input": "-1 2 -2 3", "output": "-1 3 -2 2" }, { "input": "0 1 1 0", "output": "0 0 1 1" }, { "input": "1 2 2 1", "output": "1 1 2 2" }, { "input": "4 1 2 1", "output": "4 3 2 3" }, { "input": "70 0 0 10", "output": "-1" }, { "input": "2 3 4 1", "output": "2 1 4 3" }, { "input": "1 3 3 1", "output": "1 1 3 3" }, { "input": "-3 3 0 0", "output": "-3 0 0 3" }, { "input": "2 8 7 3", "output": "2 3 7 8" }, { "input": "1 2 2 3", "output": "1 3 2 2" }, { "input": "0 3 3 0", "output": "0 0 3 3" }, { "input": "0 0 -3 3", "output": "0 3 -3 0" }, { "input": "0 2 1 2", "output": "0 3 1 3" }, { "input": "1 1 2 0", "output": "1 0 2 1" }, { "input": "0 0 5 0", "output": "0 5 5 5" }, { "input": "3 4 7 8", "output": "3 8 7 4" }, { "input": "0 5 5 0", "output": "0 0 5 5" }, { "input": "5 6 8 3", "output": "5 3 8 6" }, { "input": "2 2 1 1", "output": "2 1 1 2" }, { "input": "0 1 3 1", "output": "0 4 3 4" }, { "input": "2 4 5 4", "output": "2 7 5 7" }, { "input": "0 5 1 5", "output": "0 6 1 6" }, { "input": "4 0 0 4", "output": "4 4 0 0" }, { "input": "0 1 1 8", "output": "-1" }, { "input": "2 3 3 4", "output": "2 4 3 3" }, { "input": "1 0 2 1", "output": "1 1 2 0" }, { "input": "0 0 2 14", "output": "-1" }, { "input": "0 0 4 3", "output": "-1" }, { "input": "3 5 5 3", "output": "3 3 5 5" }, { "input": "-1 1 1 -1", "output": "-1 -1 1 1" }, { "input": "0 0 2 0", "output": "0 2 2 2" }, { "input": "0 0 1 7", "output": "-1" }, { "input": "1 2 3 2", "output": "1 4 3 4" }, { "input": "1 12 3 10", "output": "1 10 3 12" } ]
1,677,816,939
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
3
31
0
ord = list(map(int,input().split())) x1 = [ord[0],ord[1]] x2 = [ord[2],ord[3]] #point = sum(ord)//(4-ord.count(0)) arr = [True,False,False,False,False] if ord.count(0)==0 or ord.count(0)==4: print(-1) else: point = None for i in ord: if i!=0: if point==None: point= i if point!=None: if i!=point: print(-1) break else: if x1==[0,0] or x2==[0,0]: arr[1] = True if x1==[point,0] or x2==[point,0]: arr[2] = True if x1==[point,point] or x2==[point,point]: arr[3] = True if x1==[0,point] or x2==[0,point]: arr[4] = True res = '' if arr[1]==False: res+='0 0 ' if arr[2]==False: res+=str(point)+" 0 " if arr[3]==False: res+=str(point)+" "+str(point)+" " if arr[4]==False: res+= '0 '+str(point)+ " " print(res)
Title: Pashmak and Garden Time Limit: None seconds Memory Limit: None megabytes Problem Description: Pashmak has fallen in love with an attractive girl called Parmida since one year ago... Today, Pashmak set up a meeting with his partner in a romantic garden. Unfortunately, Pashmak has forgotten where the garden is. But he remembers that the garden looks like a square with sides parallel to the coordinate axes. He also remembers that there is exactly one tree on each vertex of the square. Now, Pashmak knows the position of only two of the trees. Help him to find the position of two remaining ones. Input Specification: The first line contains four space-separated *x*1,<=*y*1,<=*x*2,<=*y*2 (<=-<=100<=≤<=*x*1,<=*y*1,<=*x*2,<=*y*2<=≤<=100) integers, where *x*1 and *y*1 are coordinates of the first tree and *x*2 and *y*2 are coordinates of the second tree. It's guaranteed that the given points are distinct. Output Specification: If there is no solution to the problem, print -1. Otherwise print four space-separated integers *x*3,<=*y*3,<=*x*4,<=*y*4 that correspond to the coordinates of the two other trees. If there are several solutions you can output any of them. Note that *x*3,<=*y*3,<=*x*4,<=*y*4 must be in the range (<=-<=1000<=≤<=*x*3,<=*y*3,<=*x*4,<=*y*4<=≤<=1000). Demo Input: ['0 0 0 1\n', '0 0 1 1\n', '0 0 1 2\n'] Demo Output: ['1 0 1 1\n', '0 1 1 0\n', '-1\n'] Note: none
```python ord = list(map(int,input().split())) x1 = [ord[0],ord[1]] x2 = [ord[2],ord[3]] #point = sum(ord)//(4-ord.count(0)) arr = [True,False,False,False,False] if ord.count(0)==0 or ord.count(0)==4: print(-1) else: point = None for i in ord: if i!=0: if point==None: point= i if point!=None: if i!=point: print(-1) break else: if x1==[0,0] or x2==[0,0]: arr[1] = True if x1==[point,0] or x2==[point,0]: arr[2] = True if x1==[point,point] or x2==[point,point]: arr[3] = True if x1==[0,point] or x2==[0,point]: arr[4] = True res = '' if arr[1]==False: res+='0 0 ' if arr[2]==False: res+=str(point)+" 0 " if arr[3]==False: res+=str(point)+" "+str(point)+" " if arr[4]==False: res+= '0 '+str(point)+ " " print(res) ```
0
33
C
Wonderful Randomized Sum
PROGRAMMING
1,800
[ "greedy" ]
C. Wonderful Randomized Sum
2
256
Learn, learn and learn again — Valera has to do this every day. He is studying at mathematical school, where math is the main discipline. The mathematics teacher loves her discipline very much and tries to cultivate this love in children. That's why she always gives her students large and difficult homework. Despite that Valera is one of the best students, he failed to manage with the new homework. That's why he asks for your help. He has the following task. A sequence of *n* numbers is given. A prefix of a sequence is the part of the sequence (possibly empty), taken from the start of the sequence. A suffix of a sequence is the part of the sequence (possibly empty), taken from the end of the sequence. It is allowed to sequentially make two operations with the sequence. The first operation is to take some prefix of the sequence and multiply all numbers in this prefix by <=-<=1. The second operation is to take some suffix and multiply all numbers in it by <=-<=1. The chosen prefix and suffix may intersect. What is the maximum total sum of the sequence that can be obtained by applying the described operations?
The first line contains integer *n* (1<=≤<=*n*<=≤<=105) — amount of elements in the sequence. The second line contains *n* integers *a**i* (<=-<=104<=≤<=*a**i*<=≤<=104) — the sequence itself.
The first and the only line of the output should contain the answer to the problem.
[ "3\n-1 -2 -3\n", "5\n-4 2 0 5 0\n", "5\n-1 10 -5 10 -2\n" ]
[ "6\n", "11\n", "18\n" ]
none
1,500
[ { "input": "3\n-1 -2 -3", "output": "6" }, { "input": "5\n-4 2 0 5 0", "output": "11" }, { "input": "5\n-1 10 -5 10 -2", "output": "18" }, { "input": "1\n-3", "output": "3" }, { "input": "4\n1 4 -5 -2", "output": "12" }, { "input": "7\n-17 6 5 0 1 4 -1", "output": "34" }, { "input": "3\n0 -2 3", "output": "5" }, { "input": "2\n0 3", "output": "3" }, { "input": "15\n14 0 -10 -5 0 19 -6 0 -11 -20 -18 -8 -3 19 -7", "output": "74" }, { "input": "15\n0 -35 32 24 0 27 10 0 -19 -38 30 -30 40 -3 22", "output": "130" }, { "input": "100\n-43 0 -81 10 67 61 0 76 -16 1 -1 69 -59 -87 14 -20 -48 -41 90 96 8 -94 -2 27 42 84 19 13 0 -87 -41 40 -61 31 -4 100 -64 10 16 -3 85 91 -63 -34 96 42 -85 95 -84 78 94 -70 51 60 90 -16 69 0 -63 -87 67 -82 -75 65 74 0 23 15 0 5 -99 -23 38 85 21 0 77 61 46 11 -37 -86 -19 89 -82 -64 20 -8 93 12 -82 -74 -85 -30 -65 -55 31 -24 6 90", "output": "1398" }, { "input": "100\n0 -36 40 0 0 -62 -1 -77 -23 -3 25 17 0 -30 26 1 69 0 -5 51 -57 -73 61 -66 53 -8 -1 60 -53 3 -56 52 -11 -37 -7 -63 21 -77 41 2 -73 0 -14 0 -44 42 53 80 16 -55 26 0 0 -32 0 56 -18 -46 -19 -58 80 -33 65 59 -16 -70 -56 -62 -62 6 -29 21 37 33 59 -8 -38 -31 0 23 -40 -16 73 -69 -63 -10 37 25 68 77 -71 73 -7 75 56 -12 -57 0 0 74", "output": "795" }, { "input": "20\n0 2 3 1 0 3 -3 0 -1 0 2 -1 -1 3 0 0 1 -3 2 0", "output": "10" }, { "input": "100\n6 2 -3 6 -4 -6 -2 -1 -6 1 3 -4 -1 0 -3 1 -3 0 -2 -3 0 3 1 6 -5 0 4 -5 -5 -6 3 1 3 4 0 -1 3 -4 5 -1 -3 -2 -6 0 5 -6 -2 0 4 -4 -5 4 -2 0 -5 1 -5 0 5 -4 2 -3 -2 0 3 -6 3 2 -4 -3 5 5 1 -1 2 -6 6 0 2 -3 3 0 -1 -4 0 -6 0 0 -6 5 -4 1 6 -5 -1 -2 3 4 0 6", "output": "64" }, { "input": "100\n40 0 -11 -27 -7 7 32 33 -6 7 -6 23 -11 -46 -44 41 0 -47 -4 -39 -2 49 -43 -15 2 -28 -3 0 0 -4 4 17 27 31 -36 -33 6 -50 0 -37 36 19 26 45 -21 -45 3 25 -3 0 -15 4 -16 -49 -23 -12 -27 -36 -4 44 -8 -43 34 -2 -27 -21 0 -49 7 8 0 -4 -30 0 -23 -43 0 -8 -27 -50 -38 -2 -19 25 33 22 -2 -27 -42 -32 14 0 -40 39 -8 33 -13 -21 15 4", "output": "826" }, { "input": "30\n8 -1 3 -7 0 -1 9 3 0 0 3 -8 8 -8 9 -3 5 -9 -8 -10 4 -9 8 6 0 9 -6 1 5 -6", "output": "41" }, { "input": "1\n7500", "output": "7500" }, { "input": "2\n9944 -9293", "output": "19237" }, { "input": "3\n5 -5 7", "output": "7" }, { "input": "5\n-23 -11 -54 56 -40", "output": "184" }, { "input": "10\n-8 6 0 12 0 2 3 8 2 6", "output": "47" }, { "input": "8\n3 0 -5 -2 -4 0 -5 0", "output": "19" }, { "input": "16\n57 59 -27 24 28 -27 9 -90 3 -36 90 63 1 99 -46 50", "output": "257" }, { "input": "7\n2 -1 -2 -4 -3 0 -3", "output": "15" }, { "input": "8\n57 -82 -146 -13 -3 -115 55 -76", "output": "437" }, { "input": "6\n9721 6032 8572 9026 9563 7626", "output": "50540" }, { "input": "4\n26 9 -16 -24", "output": "75" }, { "input": "5\n-54 64 37 -71 -74", "output": "300" }, { "input": "100\n-42 -62 -12 -17 -80 -53 -55 -83 -69 -29 -53 -56 -40 -86 -37 -10 -55 -3 -82 -10 1 1 -51 -4 0 -75 -21 0 47 0 7 -78 -65 -29 -20 85 -13 28 35 -63 20 -41 -88 0 3 39 12 78 -59 -6 -41 -72 -69 -84 -99 -55 -61 -6 -58 -75 -36 -69 -12 -87 -99 -85 -80 -56 -96 -8 -46 -93 -2 -1 -47 -27 -12 -66 -65 -17 -48 -26 -65 -88 -89 -98 -54 -78 -83 -7 -96 -9 -42 -77 -41 -100 -51 -65 -29 -34", "output": "4265" }, { "input": "100\n-88 -5 -96 -45 -11 -81 -68 -58 -73 -91 -27 -23 -89 -34 -51 -46 -70 -95 -9 -77 -99 -61 -74 -98 -88 -44 -61 -88 -35 -71 -43 -23 -25 -98 -23 0 -1 -80 -52 -47 -26 -92 -82 -73 -45 -37 -15 -49 -9 -7 -47 0 -6 -76 -91 -20 -58 -46 -74 -57 -54 -39 -61 -18 -65 -61 -19 -64 -93 -29 -82 -25 -100 -89 -90 -68 -36 -91 -59 -91 -66 -56 -96 0 -8 -42 -98 -39 -26 -93 -17 -45 -69 -85 -30 -15 -30 -82 -7 -81", "output": "5377" }, { "input": "100\n87 89 48 10 31 32 68 58 56 66 33 83 7 35 38 22 73 6 13 87 13 29 3 40 96 9 100 48 33 24 90 99 40 25 93 88 37 57 1 57 48 53 70 9 38 69 59 71 38 65 71 20 97 16 68 49 79 82 64 77 76 19 26 54 75 14 12 25 96 51 43 52 58 37 88 38 42 61 93 73 86 66 93 17 96 34 35 58 45 69 65 85 64 38 36 58 45 94 26 77", "output": "5287" }, { "input": "100\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0", "output": "0" }, { "input": "4\n-83 -87 42 -96", "output": "308" }, { "input": "8\n103 395 377 -205 -975 301 548 346", "output": "1500" }, { "input": "20\n18 1 10 0 14 17 -13 0 -20 -19 16 2 5 -2 4 9 1 16 12 4", "output": "75" }, { "input": "16\n-2 -11 -6 -2 -8 -2 0 3 -1 0 -5 2 -12 5 6 -9", "output": "64" }, { "input": "5\n81 26 21 28 88", "output": "244" }, { "input": "7\n2165 -8256 -9741 -9714 7347 5652 6199", "output": "44744" }, { "input": "8\n4609 9402 908 9322 5132 0 1962 1069", "output": "32404" }, { "input": "11\n100 233 -184 -200 -222 228 -385 -129 -126 -377 237", "output": "1491" }, { "input": "5\n-4 -4 -4 -4 -4", "output": "20" }, { "input": "5\n-7 17 2 -6 -1", "output": "33" }, { "input": "8\n-1 1 4 -5 -2 3 -10 3", "output": "17" }, { "input": "9\n1 2 -4 3 6 1 1 2 -8", "output": "22" }, { "input": "9\n1 1 2 -4 1 -4 2 1 1", "output": "7" }, { "input": "14\n1 1 1 1 -3 1 -5 -3 2 -3 1 1 1 1", "output": "11" }, { "input": "7\n-12 12 -12 13 -12 12 -12", "output": "37" }, { "input": "1\n2", "output": "2" }, { "input": "5\n-2 0 0 -4 1", "output": "7" }, { "input": "13\n-2 6 6 0 6 -17 6 5 0 1 4 -1 0", "output": "22" } ]
1,625,578,403
2,147,483,647
Python 3
RUNTIME_ERROR
TESTS
0
92
0
n = int(input()) l = list(map(int,input().split)) suff = [0] tot = 0 for i in range(1,n+1): tot += l[n - i] suff.append(min(0,tot,suff[i-1])) pre = [0] for i in range(1,n+1): pre.append(pre[i-1] + l[i-1]) ans = -9999999999999999999 for i in range(n+1): ans = max(ans,pre[n] - 2*pre[i-1] - 2*suff[n-i]) print(ans)
Title: Wonderful Randomized Sum Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: Learn, learn and learn again — Valera has to do this every day. He is studying at mathematical school, where math is the main discipline. The mathematics teacher loves her discipline very much and tries to cultivate this love in children. That's why she always gives her students large and difficult homework. Despite that Valera is one of the best students, he failed to manage with the new homework. That's why he asks for your help. He has the following task. A sequence of *n* numbers is given. A prefix of a sequence is the part of the sequence (possibly empty), taken from the start of the sequence. A suffix of a sequence is the part of the sequence (possibly empty), taken from the end of the sequence. It is allowed to sequentially make two operations with the sequence. The first operation is to take some prefix of the sequence and multiply all numbers in this prefix by <=-<=1. The second operation is to take some suffix and multiply all numbers in it by <=-<=1. The chosen prefix and suffix may intersect. What is the maximum total sum of the sequence that can be obtained by applying the described operations? Input Specification: The first line contains integer *n* (1<=≤<=*n*<=≤<=105) — amount of elements in the sequence. The second line contains *n* integers *a**i* (<=-<=104<=≤<=*a**i*<=≤<=104) — the sequence itself. Output Specification: The first and the only line of the output should contain the answer to the problem. Demo Input: ['3\n-1 -2 -3\n', '5\n-4 2 0 5 0\n', '5\n-1 10 -5 10 -2\n'] Demo Output: ['6\n', '11\n', '18\n'] Note: none
```python n = int(input()) l = list(map(int,input().split)) suff = [0] tot = 0 for i in range(1,n+1): tot += l[n - i] suff.append(min(0,tot,suff[i-1])) pre = [0] for i in range(1,n+1): pre.append(pre[i-1] + l[i-1]) ans = -9999999999999999999 for i in range(n+1): ans = max(ans,pre[n] - 2*pre[i-1] - 2*suff[n-i]) print(ans) ```
-1
266
B
Queue at the School
PROGRAMMING
800
[ "constructive algorithms", "graph matchings", "implementation", "shortest paths" ]
null
null
During the break the schoolchildren, boys and girls, formed a queue of *n* people in the canteen. Initially the children stood in the order they entered the canteen. However, after a while the boys started feeling awkward for standing in front of the girls in the queue and they started letting the girls move forward each second. Let's describe the process more precisely. Let's say that the positions in the queue are sequentially numbered by integers from 1 to *n*, at that the person in the position number 1 is served first. Then, if at time *x* a boy stands on the *i*-th position and a girl stands on the (*i*<=+<=1)-th position, then at time *x*<=+<=1 the *i*-th position will have a girl and the (*i*<=+<=1)-th position will have a boy. The time is given in seconds. You've got the initial position of the children, at the initial moment of time. Determine the way the queue is going to look after *t* seconds.
The first line contains two integers *n* and *t* (1<=≤<=*n*,<=*t*<=≤<=50), which represent the number of children in the queue and the time after which the queue will transform into the arrangement you need to find. The next line contains string *s*, which represents the schoolchildren's initial arrangement. If the *i*-th position in the queue contains a boy, then the *i*-th character of string *s* equals "B", otherwise the *i*-th character equals "G".
Print string *a*, which describes the arrangement after *t* seconds. If the *i*-th position has a boy after the needed time, then the *i*-th character *a* must equal "B", otherwise it must equal "G".
[ "5 1\nBGGBG\n", "5 2\nBGGBG\n", "4 1\nGGGB\n" ]
[ "GBGGB\n", "GGBGB\n", "GGGB\n" ]
none
500
[ { "input": "5 1\nBGGBG", "output": "GBGGB" }, { "input": "5 2\nBGGBG", "output": "GGBGB" }, { "input": "4 1\nGGGB", "output": "GGGB" }, { "input": "2 1\nBB", "output": "BB" }, { "input": "2 1\nBG", "output": "GB" }, { "input": "6 2\nBBGBBG", "output": "GBBGBB" }, { "input": "8 3\nBBGBGBGB", "output": "GGBGBBBB" }, { "input": "10 3\nBBGBBBBBBG", "output": "GBBBBBGBBB" }, { "input": "22 7\nGBGGBGGGGGBBBGGBGBGBBB", "output": "GGGGGGGGBGGBGGBBBBBBBB" }, { "input": "50 4\nGBBGBBBGGGGGBBGGBBBBGGGBBBGBBBGGBGGBGBBBGGBGGBGGBG", "output": "GGBGBGBGBGBGGGBBGBGBGBGBBBGBGBGBGBGBGBGBGBGBGGBGBB" }, { "input": "50 8\nGGGGBGGBGGGBGBBBGGGGGGGGBBGBGBGBBGGBGGBGGGGGGGGBBG", "output": "GGGGGGGGGGGGBGGBGBGBGBGBGGGGGGBGBGBGBGBGBGGBGGBGBB" }, { "input": "50 30\nBGGGGGGBGGBGBGGGGBGBBGBBBGGBBBGBGBGGGGGBGBBGBGBGGG", "output": "GGGGGGGGGGGGGGGGGGGGGGGGGGGGGGBBBBBBBBBBBBBBBBBBBB" }, { "input": "20 20\nBBGGBGGGGBBBGBBGGGBB", "output": "GGGGGGGGGGBBBBBBBBBB" }, { "input": "27 6\nGBGBGBGGGGGGBGGBGGBBGBBBGBB", "output": "GGGGGGGBGBGBGGGGGBGBBBBBBBB" }, { "input": "46 11\nBGGGGGBGBGGBGGGBBGBBGBBGGBBGBBGBGGGGGGGBGBGBGB", "output": "GGGGGGGGGGGBGGGGGBBGBGBGBGBGBGBGBGBGBGBGBBBBBB" }, { "input": "50 6\nBGGBBBBGGBBBBBBGGBGBGBBBBGBBBBBBGBBBBBBBBBBBBBBBBB", "output": "GGGGBBBBBGBGBGBGBBBGBBBBBBGBBBBBBBBBBBBBBBBBBBBBBB" }, { "input": "50 10\nBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB", "output": "BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB" }, { "input": "50 8\nGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGG", "output": "GGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGG" }, { "input": "50 10\nBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBGB", "output": "BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBGBBBBBBBBBBB" }, { "input": "50 13\nGGGBGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGG", "output": "GGGGGGGGGGGGGGGGBGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGG" }, { "input": "1 1\nB", "output": "B" }, { "input": "1 1\nG", "output": "G" }, { "input": "1 50\nB", "output": "B" }, { "input": "1 50\nG", "output": "G" }, { "input": "50 50\nBBBBBBBBGGBBBBBBGBBBBBBBBBBBGBBBBBBBBBBBBBBGBBBBBB", "output": "GGGGGBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB" }, { "input": "50 50\nGGBBGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGBBGGGGGGBG", "output": "GGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGBBBBB" }, { "input": "6 3\nGGBBBG", "output": "GGGBBB" }, { "input": "26 3\nGBBGBBBBBGGGBGBGGGBGBGGBBG", "output": "GGBBBBGBGBGBGGGBGBGGGBGBBB" }, { "input": "46 3\nGGBBGGGGBBGBGBBBBBGGGBGGGBBGGGBBBGGBGGBBBGBGBB", "output": "GGGGBGBGGGBBBBBGBGBGBGGGBGGBGBGBGBGBGBGBGBBBBB" }, { "input": "44 8\nBGBBBBBBBBBGGBBGBGBGGBBBBBGBBGBBBBBBBBBGBBGB", "output": "GBBGBGBGBGBGBGBBBBGBBGBBBBBBBBBGBBGBBBBBBBBB" }, { "input": "20 20\nBBGGBGGGGBBBGBBGGGBB", "output": "GGGGGGGGGGBBBBBBBBBB" }, { "input": "30 25\nBGGBBGBGGBGBGBBGBGGGGBGBGGBBBB", "output": "GGGGGGGGGGGGGGGBBBBBBBBBBBBBBB" }, { "input": "17 42\nBBGBGBGGGGGGBBGGG", "output": "GGGGGGGGGGGBBBBBB" }, { "input": "30 50\nBGGBBGGGGGGGGBBGGGBBGGBBBGBBGG", "output": "GGGGGGGGGGGGGGGGGGBBBBBBBBBBBB" }, { "input": "31 33\nBBGGBBGGBGBBBBGGBGBBBGBGGBBGBBB", "output": "GGGGGGGGGGGGBBBBBBBBBBBBBBBBBBB" }, { "input": "2 2\nBG", "output": "GB" }, { "input": "8 8\nGGGBGGBB", "output": "GGGGGBBB" }, { "input": "34 34\nBGGBBBBGGBBGBGGGGGGBBGGGGGBGGBGGGB", "output": "GGGGGGGGGGGGGGGGGGGGGBBBBBBBBBBBBB" }, { "input": "34 20\nBBBBGBGGGBGGGBGBGGBBBBGGBBGGGBGBBG", "output": "GGGGGGGGGGGGGGGGGBBBBBBBBBBBBBBBBB" }, { "input": "50 50\nBBGBBBBBBBBBBBBGBBBGBBBBBBBGBBBBBBGBBBGBBGBBGBBBGG", "output": "GGGGGGGGGGBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB" }, { "input": "10 10\nGGGGGGGGGG", "output": "GGGGGGGGGG" }, { "input": "10 10\nBBBBBBBBBB", "output": "BBBBBBBBBB" }, { "input": "10 10\nBGBGBGBGBG", "output": "GGGGGBBBBB" }, { "input": "1 1\nB", "output": "B" } ]
1,694,619,009
2,147,483,647
Python 3
OK
TESTS
44
92
0
import sys n, t = map(int, input().split()) s = input().strip() for _ in range(t): i = 1 while i < n: if s[i] == 'G' and s[i - 1] == 'B': s = s[:i - 1] + 'G' + 'B' + s[i + 1:] i += 1 i += 1 print(s)
Title: Queue at the School Time Limit: None seconds Memory Limit: None megabytes Problem Description: During the break the schoolchildren, boys and girls, formed a queue of *n* people in the canteen. Initially the children stood in the order they entered the canteen. However, after a while the boys started feeling awkward for standing in front of the girls in the queue and they started letting the girls move forward each second. Let's describe the process more precisely. Let's say that the positions in the queue are sequentially numbered by integers from 1 to *n*, at that the person in the position number 1 is served first. Then, if at time *x* a boy stands on the *i*-th position and a girl stands on the (*i*<=+<=1)-th position, then at time *x*<=+<=1 the *i*-th position will have a girl and the (*i*<=+<=1)-th position will have a boy. The time is given in seconds. You've got the initial position of the children, at the initial moment of time. Determine the way the queue is going to look after *t* seconds. Input Specification: The first line contains two integers *n* and *t* (1<=≤<=*n*,<=*t*<=≤<=50), which represent the number of children in the queue and the time after which the queue will transform into the arrangement you need to find. The next line contains string *s*, which represents the schoolchildren's initial arrangement. If the *i*-th position in the queue contains a boy, then the *i*-th character of string *s* equals "B", otherwise the *i*-th character equals "G". Output Specification: Print string *a*, which describes the arrangement after *t* seconds. If the *i*-th position has a boy after the needed time, then the *i*-th character *a* must equal "B", otherwise it must equal "G". Demo Input: ['5 1\nBGGBG\n', '5 2\nBGGBG\n', '4 1\nGGGB\n'] Demo Output: ['GBGGB\n', 'GGBGB\n', 'GGGB\n'] Note: none
```python import sys n, t = map(int, input().split()) s = input().strip() for _ in range(t): i = 1 while i < n: if s[i] == 'G' and s[i - 1] == 'B': s = s[:i - 1] + 'G' + 'B' + s[i + 1:] i += 1 i += 1 print(s) ```
3
490
A
Team Olympiad
PROGRAMMING
800
[ "greedy", "implementation", "sortings" ]
null
null
The School №0 of the capital of Berland has *n* children studying in it. All the children in this school are gifted: some of them are good at programming, some are good at maths, others are good at PE (Physical Education). Hence, for each child we know value *t**i*: - *t**i*<==<=1, if the *i*-th child is good at programming, - *t**i*<==<=2, if the *i*-th child is good at maths, - *t**i*<==<=3, if the *i*-th child is good at PE Each child happens to be good at exactly one of these three subjects. The Team Scientific Decathlon Olympias requires teams of three students. The school teachers decided that the teams will be composed of three children that are good at different subjects. That is, each team must have one mathematician, one programmer and one sportsman. Of course, each child can be a member of no more than one team. What is the maximum number of teams that the school will be able to present at the Olympiad? How should the teams be formed for that?
The first line contains integer *n* (1<=≤<=*n*<=≤<=5000) — the number of children in the school. The second line contains *n* integers *t*1,<=*t*2,<=...,<=*t**n* (1<=≤<=*t**i*<=≤<=3), where *t**i* describes the skill of the *i*-th child.
In the first line output integer *w* — the largest possible number of teams. Then print *w* lines, containing three numbers in each line. Each triple represents the indexes of the children forming the team. You can print both the teams, and the numbers in the triplets in any order. The children are numbered from 1 to *n* in the order of their appearance in the input. Each child must participate in no more than one team. If there are several solutions, print any of them. If no teams can be compiled, print the only line with value *w* equal to 0.
[ "7\n1 3 1 3 2 1 2\n", "4\n2 1 1 2\n" ]
[ "2\n3 5 2\n6 7 4\n", "0\n" ]
none
500
[ { "input": "7\n1 3 1 3 2 1 2", "output": "2\n3 5 2\n6 7 4" }, { "input": "4\n2 1 1 2", "output": "0" }, { "input": "1\n2", "output": "0" }, { "input": "2\n3 1", "output": "0" }, { "input": "3\n2 1 2", "output": "0" }, { "input": "3\n1 2 3", "output": "1\n1 2 3" }, { "input": "12\n3 3 3 3 3 3 3 3 1 3 3 2", "output": "1\n9 12 2" }, { "input": "60\n3 3 1 2 2 1 3 1 1 1 3 2 2 2 3 3 1 3 2 3 2 2 1 3 3 2 3 1 2 2 2 1 3 2 1 1 3 3 1 1 1 3 1 2 1 1 3 3 3 2 3 2 3 2 2 2 1 1 1 2", "output": "20\n6 60 1\n17 44 20\n3 5 33\n36 21 42\n59 14 2\n58 26 49\n9 29 48\n23 19 24\n10 30 37\n41 54 15\n45 31 27\n57 55 38\n39 12 25\n35 34 11\n32 52 7\n8 50 18\n43 4 53\n46 56 51\n40 22 16\n28 13 47" }, { "input": "12\n3 1 1 1 1 1 1 2 1 1 1 1", "output": "1\n3 8 1" }, { "input": "22\n2 2 2 2 2 2 2 2 2 2 3 2 2 2 2 2 2 1 2 2 2 2", "output": "1\n18 2 11" }, { "input": "138\n2 3 2 2 2 2 2 2 2 2 1 2 1 2 2 2 1 2 1 2 2 1 2 2 2 2 2 2 2 2 2 2 2 1 2 3 2 2 2 1 2 3 2 2 2 3 1 3 2 3 2 3 2 2 2 2 3 2 2 2 2 2 1 2 2 3 2 2 3 2 1 2 2 2 2 2 3 1 2 2 2 2 2 3 2 2 3 2 2 2 2 2 1 1 2 3 2 2 2 2 3 2 2 2 2 2 1 2 1 2 2 2 2 2 1 2 3 2 3 2 2 2 1 2 2 2 1 2 2 2 2 1 2 2 2 2 1 3", "output": "18\n13 91 84\n34 90 48\n11 39 77\n78 129 50\n137 68 119\n132 122 138\n19 12 96\n40 7 2\n22 88 69\n107 73 46\n115 15 52\n127 106 87\n93 92 66\n71 112 117\n63 124 42\n17 70 101\n109 121 57\n123 25 36" }, { "input": "203\n2 2 1 2 1 2 2 2 1 2 2 1 1 3 1 2 1 2 1 1 2 3 1 1 2 3 3 2 2 2 1 2 1 1 1 1 1 3 1 1 2 1 1 2 2 2 1 2 2 2 1 2 3 2 1 1 2 2 1 2 1 2 2 1 1 2 2 2 1 1 2 2 1 2 1 2 2 3 2 1 2 1 1 1 1 1 1 1 1 1 1 2 2 1 1 2 2 2 2 1 1 1 1 1 1 1 2 2 2 2 2 1 1 1 2 2 2 1 2 2 1 3 2 1 1 1 2 1 1 2 1 1 2 2 2 1 1 2 2 2 1 2 1 3 2 1 2 2 2 1 1 1 2 2 2 1 2 1 1 2 2 2 2 2 1 1 2 1 2 2 1 1 1 1 1 1 2 2 3 1 1 2 3 1 1 1 1 1 1 2 2 1 1 1 2 2 3 2 1 3 1 1 1", "output": "13\n188 72 14\n137 4 197\n158 76 122\n152 142 26\n104 119 179\n40 63 38\n12 1 78\n17 30 27\n189 60 53\n166 190 144\n129 7 183\n83 41 22\n121 81 200" }, { "input": "220\n1 1 3 1 3 1 1 3 1 3 3 3 3 1 3 3 1 3 3 3 3 3 1 1 1 3 1 1 1 3 2 3 3 3 1 1 3 3 1 1 3 3 3 3 1 3 3 1 1 1 2 3 1 1 1 2 3 3 3 2 3 1 1 3 1 1 1 3 2 1 3 2 3 1 1 3 3 3 1 3 1 1 1 3 3 2 1 3 2 1 1 3 3 1 1 1 2 1 1 3 2 1 2 1 1 1 3 1 3 3 1 2 3 3 3 3 1 3 1 1 1 1 2 3 1 1 1 1 1 1 3 2 3 1 3 1 3 1 1 3 1 3 1 3 1 3 1 3 3 2 3 1 3 3 1 3 3 3 3 1 1 3 3 3 3 1 1 3 3 3 2 1 1 1 3 3 1 3 3 3 1 1 1 3 1 3 3 1 1 1 2 3 1 1 3 1 1 1 1 2 3 1 1 2 3 3 1 3 1 3 3 3 3 1 3 2 3 1 1 3", "output": "20\n198 89 20\n141 56 131\n166 204 19\n160 132 142\n111 112 195\n45 216 92\n6 31 109\n14 150 170\n199 60 18\n173 123 140\n134 69 156\n82 191 85\n126 200 80\n24 97 46\n62 86 149\n214 101 26\n79 171 78\n125 72 118\n172 103 162\n219 51 64" }, { "input": "61\n2 3 1 3 2 2 2 3 1 3 2 3 1 2 1 1 2 2 2 2 3 2 3 1 2 1 3 1 3 2 1 1 3 2 1 3 3 3 1 3 3 1 1 3 1 3 2 2 1 2 2 2 1 3 2 3 1 3 3 1 1", "output": "20\n9 55 2\n24 34 27\n3 5 37\n35 17 41\n61 11 4\n60 19 54\n15 20 59\n26 14 29\n16 22 38\n43 50 12\n49 25 36\n57 51 40\n39 6 33\n32 30 10\n31 48 8\n13 47 23\n45 1 58\n53 52 56\n42 18 21\n28 7 44" }, { "input": "5\n1 2 2 3 3", "output": "1\n1 3 4" } ]
1,659,629,025
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
5
46
0
n = int(input()) t = list(map(int,input().split(" "))) if (t.count(1)) < 2 or (t.count(2)) < 2 or (t.count(3)) < 2: print(0) exit() else: number = min(t.count(1), t.count(2), t.count(3)) f = [] s = [] third = [] for i in range(n): if t[i] == 1: f.append(i) if t[i] == 2: s.append(i) if t[i] == 3: third.append(i) print(number) j = 0 f = [i+1 for i in f] s = [i+1 for i in s] third = [i+1 for i in third] for i in range(number): print(f[j], s[j], third[j]) j += 1
Title: Team Olympiad Time Limit: None seconds Memory Limit: None megabytes Problem Description: The School №0 of the capital of Berland has *n* children studying in it. All the children in this school are gifted: some of them are good at programming, some are good at maths, others are good at PE (Physical Education). Hence, for each child we know value *t**i*: - *t**i*<==<=1, if the *i*-th child is good at programming, - *t**i*<==<=2, if the *i*-th child is good at maths, - *t**i*<==<=3, if the *i*-th child is good at PE Each child happens to be good at exactly one of these three subjects. The Team Scientific Decathlon Olympias requires teams of three students. The school teachers decided that the teams will be composed of three children that are good at different subjects. That is, each team must have one mathematician, one programmer and one sportsman. Of course, each child can be a member of no more than one team. What is the maximum number of teams that the school will be able to present at the Olympiad? How should the teams be formed for that? Input Specification: The first line contains integer *n* (1<=≤<=*n*<=≤<=5000) — the number of children in the school. The second line contains *n* integers *t*1,<=*t*2,<=...,<=*t**n* (1<=≤<=*t**i*<=≤<=3), where *t**i* describes the skill of the *i*-th child. Output Specification: In the first line output integer *w* — the largest possible number of teams. Then print *w* lines, containing three numbers in each line. Each triple represents the indexes of the children forming the team. You can print both the teams, and the numbers in the triplets in any order. The children are numbered from 1 to *n* in the order of their appearance in the input. Each child must participate in no more than one team. If there are several solutions, print any of them. If no teams can be compiled, print the only line with value *w* equal to 0. Demo Input: ['7\n1 3 1 3 2 1 2\n', '4\n2 1 1 2\n'] Demo Output: ['2\n3 5 2\n6 7 4\n', '0\n'] Note: none
```python n = int(input()) t = list(map(int,input().split(" "))) if (t.count(1)) < 2 or (t.count(2)) < 2 or (t.count(3)) < 2: print(0) exit() else: number = min(t.count(1), t.count(2), t.count(3)) f = [] s = [] third = [] for i in range(n): if t[i] == 1: f.append(i) if t[i] == 2: s.append(i) if t[i] == 3: third.append(i) print(number) j = 0 f = [i+1 for i in f] s = [i+1 for i in s] third = [i+1 for i in third] for i in range(number): print(f[j], s[j], third[j]) j += 1 ```
0
58
A
Chat room
PROGRAMMING
1,000
[ "greedy", "strings" ]
A. Chat room
1
256
Vasya has recently learned to type and log on to the Internet. He immediately entered a chat room and decided to say hello to everybody. Vasya typed the word *s*. It is considered that Vasya managed to say hello if several letters can be deleted from the typed word so that it resulted in the word "hello". For example, if Vasya types the word "ahhellllloou", it will be considered that he said hello, and if he types "hlelo", it will be considered that Vasya got misunderstood and he didn't manage to say hello. Determine whether Vasya managed to say hello by the given word *s*.
The first and only line contains the word *s*, which Vasya typed. This word consisits of small Latin letters, its length is no less that 1 and no more than 100 letters.
If Vasya managed to say hello, print "YES", otherwise print "NO".
[ "ahhellllloou\n", "hlelo\n" ]
[ "YES\n", "NO\n" ]
none
500
[ { "input": "ahhellllloou", "output": "YES" }, { "input": "hlelo", "output": "NO" }, { "input": "helhcludoo", "output": "YES" }, { "input": "hehwelloho", "output": "YES" }, { "input": "pnnepelqomhhheollvlo", "output": "YES" }, { "input": "tymbzjyqhymedasloqbq", "output": "NO" }, { "input": "yehluhlkwo", "output": "NO" }, { "input": "hatlevhhalrohairnolsvocafgueelrqmlqlleello", "output": "YES" }, { "input": "hhhtehdbllnhwmbyhvelqqyoulretpbfokflhlhreeflxeftelziclrwllrpflflbdtotvlqgoaoqldlroovbfsq", "output": "YES" }, { "input": "rzlvihhghnelqtwlexmvdjjrliqllolhyewgozkuovaiezgcilelqapuoeglnwmnlftxxiigzczlouooi", "output": "YES" }, { "input": "pfhhwctyqdlkrwhebfqfelhyebwllhemtrmeblgrynmvyhioesqklclocxmlffuormljszllpoo", "output": "YES" }, { "input": "lqllcolohwflhfhlnaow", "output": "NO" }, { "input": "heheeellollvoo", "output": "YES" }, { "input": "hellooo", "output": "YES" }, { "input": "o", "output": "NO" }, { "input": "hhqhzeclohlehljlhtesllylrolmomvuhcxsobtsckogdv", "output": "YES" }, { "input": "yoegfuzhqsihygnhpnukluutocvvwuldiighpogsifealtgkfzqbwtmgghmythcxflebrkctlldlkzlagovwlstsghbouk", "output": "YES" }, { "input": "uatqtgbvrnywfacwursctpagasnhydvmlinrcnqrry", "output": "NO" }, { "input": "tndtbldbllnrwmbyhvqaqqyoudrstpbfokfoclnraefuxtftmgzicorwisrpfnfpbdtatvwqgyalqtdtrjqvbfsq", "output": "NO" }, { "input": "rzlvirhgemelnzdawzpaoqtxmqucnahvqnwldklrmjiiyageraijfivigvozgwngiulttxxgzczptusoi", "output": "YES" }, { "input": "kgyelmchocojsnaqdsyeqgnllytbqietpdlgknwwumqkxrexgdcnwoldicwzwofpmuesjuxzrasscvyuqwspm", "output": "YES" }, { "input": "pnyvrcotjvgynbeldnxieghfltmexttuxzyac", "output": "NO" }, { "input": "dtwhbqoumejligbenxvzhjlhosqojetcqsynlzyhfaevbdpekgbtjrbhlltbceobcok", "output": "YES" }, { "input": "crrfpfftjwhhikwzeedrlwzblckkteseofjuxjrktcjfsylmlsvogvrcxbxtffujqshslemnixoeezivksouefeqlhhokwbqjz", "output": "YES" }, { "input": "jhfbndhyzdvhbvhmhmefqllujdflwdpjbehedlsqfdsqlyelwjtyloxwsvasrbqosblzbowlqjmyeilcvotdlaouxhdpoeloaovb", "output": "YES" }, { "input": "hwlghueoemiqtjhhpashjsouyegdlvoyzeunlroypoprnhlyiwiuxrghekaylndhrhllllwhbebezoglydcvykllotrlaqtvmlla", "output": "YES" }, { "input": "wshiaunnqnqxodholbipwhhjmyeblhgpeleblklpzwhdunmpqkbuzloetmwwxmeltkrcomulxauzlwmlklldjodozxryghsnwgcz", "output": "YES" }, { "input": "shvksednttggehroewuiptvvxtrzgidravtnjwuqrlnnkxbplctzkckinpkgjopjfoxdbojtcvsuvablcbkrzajrlhgobkcxeqti", "output": "YES" }, { "input": "hyyhddqhxhekehkwfhlnlsihzefwchzerevcjtokefplholrbvxlltdlafjxrfhleglrvlolojoqaolagtbeyogxlbgfolllslli", "output": "YES" }, { "input": "iaagrdhhelxpdegueiulflquvlzidoprzkehthkldaytrjwhyhprwjxlltinxvuilxohqgjqcvkkdcuoliekcnlilwgqlnlzouoo", "output": "YES" }, { "input": "wfluaeseldgxyvxpwuhkptdmlflnlhktwxiabsvkolsquymrmhzczzoybvlilhmvsuunggvgxzgyyffk", "output": "NO" }, { "input": "loee", "output": "NO" }, { "input": "izdipwylefqmjbuoznfglgcfvedeouflkeehxbasaqmiooppfsqlhprospqgxvzrcpwlfdddngoqvpwvggsnvvxhmjoslwjudjlo", "output": "NO" }, { "input": "pplynflbjlseflaegzqpdxswgunhnlglqhycrbcwdfhclmcrwekkzsoosmfblljeenwfjyifcvxihhhbyhmhlkvtskeglaovjnsi", "output": "YES" }, { "input": "xqjqmenkodmlhzyzmmvofdngktygbbxbzpluzcohohmalkoeuwfikblltaaigv", "output": "NO" }, { "input": "hello", "output": "YES" }, { "input": "oohell", "output": "NO" }, { "input": "hell", "output": "NO" }, { "input": "eloellohoelo", "output": "NO" }, { "input": "helllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllo", "output": "YES" } ]
1,539,801,813
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
0
62
0
s=input().split('+') #split help me to make my input as i want s.sort() print('+'.join(s))
Title: Chat room Time Limit: 1 seconds Memory Limit: 256 megabytes Problem Description: Vasya has recently learned to type and log on to the Internet. He immediately entered a chat room and decided to say hello to everybody. Vasya typed the word *s*. It is considered that Vasya managed to say hello if several letters can be deleted from the typed word so that it resulted in the word "hello". For example, if Vasya types the word "ahhellllloou", it will be considered that he said hello, and if he types "hlelo", it will be considered that Vasya got misunderstood and he didn't manage to say hello. Determine whether Vasya managed to say hello by the given word *s*. Input Specification: The first and only line contains the word *s*, which Vasya typed. This word consisits of small Latin letters, its length is no less that 1 and no more than 100 letters. Output Specification: If Vasya managed to say hello, print "YES", otherwise print "NO". Demo Input: ['ahhellllloou\n', 'hlelo\n'] Demo Output: ['YES\n', 'NO\n'] Note: none
```python s=input().split('+') #split help me to make my input as i want s.sort() print('+'.join(s)) ```
0
538
B
Quasi Binary
PROGRAMMING
1,400
[ "constructive algorithms", "dp", "greedy", "implementation" ]
null
null
A number is called quasibinary if its decimal representation contains only digits 0 or 1. For example, numbers 0, 1, 101, 110011 — are quasibinary and numbers 2, 12, 900 are not. You are given a positive integer *n*. Represent it as a sum of minimum number of quasibinary numbers.
The first line contains a single integer *n* (1<=≤<=*n*<=≤<=106).
In the first line print a single integer *k* — the minimum number of numbers in the representation of number *n* as a sum of quasibinary numbers. In the second line print *k* numbers — the elements of the sum. All these numbers should be quasibinary according to the definition above, their sum should equal *n*. Do not have to print the leading zeroes in the numbers. The order of numbers doesn't matter. If there are multiple possible representations, you are allowed to print any of them.
[ "9\n", "32\n" ]
[ "9\n1 1 1 1 1 1 1 1 1 \n", "3\n10 11 11 \n" ]
none
1,000
[ { "input": "9", "output": "9\n1 1 1 1 1 1 1 1 1 " }, { "input": "32", "output": "3\n10 11 11 " }, { "input": "1", "output": "1\n1 " }, { "input": "415", "output": "5\n1 101 101 101 111 " }, { "input": "10011", "output": "1\n10011 " }, { "input": "10201", "output": "2\n100 10101 " }, { "input": "314159", "output": "9\n1 1 1 1 11 1011 101011 101011 111111 " }, { "input": "999999", "output": "9\n111111 111111 111111 111111 111111 111111 111111 111111 111111 " }, { "input": "2", "output": "2\n1 1 " }, { "input": "10", "output": "1\n10 " }, { "input": "21", "output": "2\n10 11 " }, { "input": "98", "output": "9\n10 11 11 11 11 11 11 11 11 " }, { "input": "102030", "output": "3\n10 1010 101010 " }, { "input": "909090", "output": "9\n101010 101010 101010 101010 101010 101010 101010 101010 101010 " }, { "input": "909823", "output": "9\n101000 101100 101100 101100 101100 101100 101101 101111 101111 " }, { "input": "1000000", "output": "1\n1000000 " }, { "input": "111111", "output": "1\n111111 " }, { "input": "123456", "output": "6\n1 11 111 1111 11111 111111 " }, { "input": "987654", "output": "9\n100000 110000 111000 111100 111110 111111 111111 111111 111111 " }, { "input": "908172", "output": "9\n100000 101000 101010 101010 101010 101010 101010 101011 101111 " }, { "input": "8", "output": "8\n1 1 1 1 1 1 1 1 " }, { "input": "100009", "output": "9\n1 1 1 1 1 1 1 1 100001 " }, { "input": "900000", "output": "9\n100000 100000 100000 100000 100000 100000 100000 100000 100000 " }, { "input": "1435", "output": "5\n1 101 111 111 1111 " }, { "input": "1453", "output": "5\n10 110 111 111 1111 " } ]
1,584,181,096
2,147,483,647
Python 3
OK
TESTS
25
109
307,200
#### B. Quasi Binary n=int(input()) result=[] while n: r=''.join(min(i,'1') for i in str(n)) n=n-int(r) result.append(r) print(len(result)) print(*result)
Title: Quasi Binary Time Limit: None seconds Memory Limit: None megabytes Problem Description: A number is called quasibinary if its decimal representation contains only digits 0 or 1. For example, numbers 0, 1, 101, 110011 — are quasibinary and numbers 2, 12, 900 are not. You are given a positive integer *n*. Represent it as a sum of minimum number of quasibinary numbers. Input Specification: The first line contains a single integer *n* (1<=≤<=*n*<=≤<=106). Output Specification: In the first line print a single integer *k* — the minimum number of numbers in the representation of number *n* as a sum of quasibinary numbers. In the second line print *k* numbers — the elements of the sum. All these numbers should be quasibinary according to the definition above, their sum should equal *n*. Do not have to print the leading zeroes in the numbers. The order of numbers doesn't matter. If there are multiple possible representations, you are allowed to print any of them. Demo Input: ['9\n', '32\n'] Demo Output: ['9\n1 1 1 1 1 1 1 1 1 \n', '3\n10 11 11 \n'] Note: none
```python #### B. Quasi Binary n=int(input()) result=[] while n: r=''.join(min(i,'1') for i in str(n)) n=n-int(r) result.append(r) print(len(result)) print(*result) ```
3
1,006
E
Military Problem
PROGRAMMING
1,600
[ "dfs and similar", "graphs", "trees" ]
null
null
In this problem you will have to help Berland army with organizing their command delivery system. There are $n$ officers in Berland army. The first officer is the commander of the army, and he does not have any superiors. Every other officer has exactly one direct superior. If officer $a$ is the direct superior of officer $b$, then we also can say that officer $b$ is a direct subordinate of officer $a$. Officer $x$ is considered to be a subordinate (direct or indirect) of officer $y$ if one of the following conditions holds: - officer $y$ is the direct superior of officer $x$; - the direct superior of officer $x$ is a subordinate of officer $y$. For example, on the picture below the subordinates of the officer $3$ are: $5, 6, 7, 8, 9$. The structure of Berland army is organized in such a way that every officer, except for the commander, is a subordinate of the commander of the army. Formally, let's represent Berland army as a tree consisting of $n$ vertices, in which vertex $u$ corresponds to officer $u$. The parent of vertex $u$ corresponds to the direct superior of officer $u$. The root (which has index $1$) corresponds to the commander of the army. Berland War Ministry has ordered you to give answers on $q$ queries, the $i$-th query is given as $(u_i, k_i)$, where $u_i$ is some officer, and $k_i$ is a positive integer. To process the $i$-th query imagine how a command from $u_i$ spreads to the subordinates of $u_i$. Typical DFS (depth first search) algorithm is used here. Suppose the current officer is $a$ and he spreads a command. Officer $a$ chooses $b$ — one of his direct subordinates (i.e. a child in the tree) who has not received this command yet. If there are many such direct subordinates, then $a$ chooses the one having minimal index. Officer $a$ gives a command to officer $b$. Afterwards, $b$ uses exactly the same algorithm to spread the command to its subtree. After $b$ finishes spreading the command, officer $a$ chooses the next direct subordinate again (using the same strategy). When officer $a$ cannot choose any direct subordinate who still hasn't received this command, officer $a$ finishes spreading the command. Let's look at the following example: If officer $1$ spreads a command, officers receive it in the following order: $[1, 2, 3, 5 ,6, 8, 7, 9, 4]$. If officer $3$ spreads a command, officers receive it in the following order: $[3, 5, 6, 8, 7, 9]$. If officer $7$ spreads a command, officers receive it in the following order: $[7, 9]$. If officer $9$ spreads a command, officers receive it in the following order: $[9]$. To answer the $i$-th query $(u_i, k_i)$, construct a sequence which describes the order in which officers will receive the command if the $u_i$-th officer spreads it. Return the $k_i$-th element of the constructed list or -1 if there are fewer than $k_i$ elements in it. You should process queries independently. A query doesn't affect the following queries.
The first line of the input contains two integers $n$ and $q$ ($2 \le n \le 2 \cdot 10^5, 1 \le q \le 2 \cdot 10^5$) — the number of officers in Berland army and the number of queries. The second line of the input contains $n - 1$ integers $p_2, p_3, \dots, p_n$ ($1 \le p_i &lt; i$), where $p_i$ is the index of the direct superior of the officer having the index $i$. The commander has index $1$ and doesn't have any superiors. The next $q$ lines describe the queries. The $i$-th query is given as a pair ($u_i, k_i$) ($1 \le u_i, k_i \le n$), where $u_i$ is the index of the officer which starts spreading a command, and $k_i$ is the index of the required officer in the command spreading sequence.
Print $q$ numbers, where the $i$-th number is the officer at the position $k_i$ in the list which describes the order in which officers will receive the command if it starts spreading from officer $u_i$. Print "-1" if the number of officers which receive the command is less than $k_i$. You should process queries independently. They do not affect each other.
[ "9 6\n1 1 1 3 5 3 5 7\n3 1\n1 5\n3 4\n7 3\n1 8\n1 9\n" ]
[ "3\n6\n8\n-1\n9\n4\n" ]
none
0
[ { "input": "9 6\n1 1 1 3 5 3 5 7\n3 1\n1 5\n3 4\n7 3\n1 8\n1 9", "output": "3\n6\n8\n-1\n9\n4" }, { "input": "2 1\n1\n1 1", "output": "1" }, { "input": "13 12\n1 1 1 1 1 1 1 1 1 1 1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1", "output": "1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1" } ]
1,675,886,891
2,147,483,647
PyPy 3-64
OK
TESTS
31
1,964
20,480,000
n,q= map(int, input().split()) parent=[-1]+[int(x) -1 for x in input().split()] start=[0]*n end=[1]*n size=[1]*n path=[0]*n for i in range(n-1, 0, -1): size[parent[i]]+=size[i] for v in range(1, n): start[v]=end[parent[v]] end[v]=start[v]+1 end[parent[v]]+=size[v] path[start[v]]=v for j in range(q): u, k=[int(x) -1 for x in input().split()] if k >= size[u]: print ("-1") else: print(path[start[u]+k]+1)
Title: Military Problem Time Limit: None seconds Memory Limit: None megabytes Problem Description: In this problem you will have to help Berland army with organizing their command delivery system. There are $n$ officers in Berland army. The first officer is the commander of the army, and he does not have any superiors. Every other officer has exactly one direct superior. If officer $a$ is the direct superior of officer $b$, then we also can say that officer $b$ is a direct subordinate of officer $a$. Officer $x$ is considered to be a subordinate (direct or indirect) of officer $y$ if one of the following conditions holds: - officer $y$ is the direct superior of officer $x$; - the direct superior of officer $x$ is a subordinate of officer $y$. For example, on the picture below the subordinates of the officer $3$ are: $5, 6, 7, 8, 9$. The structure of Berland army is organized in such a way that every officer, except for the commander, is a subordinate of the commander of the army. Formally, let's represent Berland army as a tree consisting of $n$ vertices, in which vertex $u$ corresponds to officer $u$. The parent of vertex $u$ corresponds to the direct superior of officer $u$. The root (which has index $1$) corresponds to the commander of the army. Berland War Ministry has ordered you to give answers on $q$ queries, the $i$-th query is given as $(u_i, k_i)$, where $u_i$ is some officer, and $k_i$ is a positive integer. To process the $i$-th query imagine how a command from $u_i$ spreads to the subordinates of $u_i$. Typical DFS (depth first search) algorithm is used here. Suppose the current officer is $a$ and he spreads a command. Officer $a$ chooses $b$ — one of his direct subordinates (i.e. a child in the tree) who has not received this command yet. If there are many such direct subordinates, then $a$ chooses the one having minimal index. Officer $a$ gives a command to officer $b$. Afterwards, $b$ uses exactly the same algorithm to spread the command to its subtree. After $b$ finishes spreading the command, officer $a$ chooses the next direct subordinate again (using the same strategy). When officer $a$ cannot choose any direct subordinate who still hasn't received this command, officer $a$ finishes spreading the command. Let's look at the following example: If officer $1$ spreads a command, officers receive it in the following order: $[1, 2, 3, 5 ,6, 8, 7, 9, 4]$. If officer $3$ spreads a command, officers receive it in the following order: $[3, 5, 6, 8, 7, 9]$. If officer $7$ spreads a command, officers receive it in the following order: $[7, 9]$. If officer $9$ spreads a command, officers receive it in the following order: $[9]$. To answer the $i$-th query $(u_i, k_i)$, construct a sequence which describes the order in which officers will receive the command if the $u_i$-th officer spreads it. Return the $k_i$-th element of the constructed list or -1 if there are fewer than $k_i$ elements in it. You should process queries independently. A query doesn't affect the following queries. Input Specification: The first line of the input contains two integers $n$ and $q$ ($2 \le n \le 2 \cdot 10^5, 1 \le q \le 2 \cdot 10^5$) — the number of officers in Berland army and the number of queries. The second line of the input contains $n - 1$ integers $p_2, p_3, \dots, p_n$ ($1 \le p_i &lt; i$), where $p_i$ is the index of the direct superior of the officer having the index $i$. The commander has index $1$ and doesn't have any superiors. The next $q$ lines describe the queries. The $i$-th query is given as a pair ($u_i, k_i$) ($1 \le u_i, k_i \le n$), where $u_i$ is the index of the officer which starts spreading a command, and $k_i$ is the index of the required officer in the command spreading sequence. Output Specification: Print $q$ numbers, where the $i$-th number is the officer at the position $k_i$ in the list which describes the order in which officers will receive the command if it starts spreading from officer $u_i$. Print "-1" if the number of officers which receive the command is less than $k_i$. You should process queries independently. They do not affect each other. Demo Input: ['9 6\n1 1 1 3 5 3 5 7\n3 1\n1 5\n3 4\n7 3\n1 8\n1 9\n'] Demo Output: ['3\n6\n8\n-1\n9\n4\n'] Note: none
```python n,q= map(int, input().split()) parent=[-1]+[int(x) -1 for x in input().split()] start=[0]*n end=[1]*n size=[1]*n path=[0]*n for i in range(n-1, 0, -1): size[parent[i]]+=size[i] for v in range(1, n): start[v]=end[parent[v]] end[v]=start[v]+1 end[parent[v]]+=size[v] path[start[v]]=v for j in range(q): u, k=[int(x) -1 for x in input().split()] if k >= size[u]: print ("-1") else: print(path[start[u]+k]+1) ```
3
950
A
Left-handers, Right-handers and Ambidexters
PROGRAMMING
800
[ "implementation", "math" ]
null
null
You are at a water bowling training. There are *l* people who play with their left hand, *r* people, who play with their right hand, and *a* ambidexters, who can play with left or right hand. The coach decided to form a team of even number of players, exactly half of the players should play with their right hand, and exactly half of the players should play with their left hand. One player should use only on of his hands. Ambidexters play as well with their right hand as with their left hand. In the team, an ambidexter can play with their left hand, or with their right hand. Please find the maximum possible size of the team, where equal number of players use their left and right hands, respectively.
The only line contains three integers *l*, *r* and *a* (0<=≤<=*l*,<=*r*,<=*a*<=≤<=100) — the number of left-handers, the number of right-handers and the number of ambidexters at the training.
Print a single even integer — the maximum number of players in the team. It is possible that the team can only have zero number of players.
[ "1 4 2\n", "5 5 5\n", "0 2 0\n" ]
[ "6\n", "14\n", "0\n" ]
In the first example you can form a team of 6 players. You should take the only left-hander and two ambidexters to play with left hand, and three right-handers to play with right hand. The only person left can't be taken into the team. In the second example you can form a team of 14 people. You have to take all five left-handers, all five right-handers, two ambidexters to play with left hand and two ambidexters to play with right hand.
500
[ { "input": "1 4 2", "output": "6" }, { "input": "5 5 5", "output": "14" }, { "input": "0 2 0", "output": "0" }, { "input": "30 70 34", "output": "128" }, { "input": "89 32 24", "output": "112" }, { "input": "89 44 77", "output": "210" }, { "input": "0 0 0", "output": "0" }, { "input": "100 100 100", "output": "300" }, { "input": "1 1 1", "output": "2" }, { "input": "30 70 35", "output": "130" }, { "input": "89 44 76", "output": "208" }, { "input": "0 100 100", "output": "200" }, { "input": "100 0 100", "output": "200" }, { "input": "100 1 100", "output": "200" }, { "input": "1 100 100", "output": "200" }, { "input": "100 100 0", "output": "200" }, { "input": "100 100 1", "output": "200" }, { "input": "1 2 1", "output": "4" }, { "input": "0 0 100", "output": "100" }, { "input": "0 100 0", "output": "0" }, { "input": "100 0 0", "output": "0" }, { "input": "10 8 7", "output": "24" }, { "input": "45 47 16", "output": "108" }, { "input": "59 43 100", "output": "202" }, { "input": "34 1 30", "output": "62" }, { "input": "14 81 1", "output": "30" }, { "input": "53 96 94", "output": "242" }, { "input": "62 81 75", "output": "218" }, { "input": "21 71 97", "output": "188" }, { "input": "49 82 73", "output": "204" }, { "input": "88 19 29", "output": "96" }, { "input": "89 4 62", "output": "132" }, { "input": "58 3 65", "output": "126" }, { "input": "27 86 11", "output": "76" }, { "input": "35 19 80", "output": "134" }, { "input": "4 86 74", "output": "156" }, { "input": "32 61 89", "output": "182" }, { "input": "68 60 98", "output": "226" }, { "input": "37 89 34", "output": "142" }, { "input": "92 9 28", "output": "74" }, { "input": "79 58 98", "output": "234" }, { "input": "35 44 88", "output": "166" }, { "input": "16 24 19", "output": "58" }, { "input": "74 71 75", "output": "220" }, { "input": "83 86 99", "output": "268" }, { "input": "97 73 15", "output": "176" }, { "input": "77 76 73", "output": "226" }, { "input": "48 85 55", "output": "188" }, { "input": "1 2 2", "output": "4" }, { "input": "2 2 2", "output": "6" }, { "input": "2 1 2", "output": "4" }, { "input": "2 2 1", "output": "4" }, { "input": "3 2 1", "output": "6" }, { "input": "1 2 3", "output": "6" }, { "input": "1 3 2", "output": "6" }, { "input": "2 1 3", "output": "6" }, { "input": "2 3 1", "output": "6" }, { "input": "3 1 2", "output": "6" }, { "input": "99 99 99", "output": "296" }, { "input": "99 99 100", "output": "298" }, { "input": "99 100 99", "output": "298" }, { "input": "99 100 100", "output": "298" }, { "input": "100 99 99", "output": "298" }, { "input": "100 99 100", "output": "298" }, { "input": "100 100 99", "output": "298" }, { "input": "89 32 23", "output": "110" }, { "input": "4 5 0", "output": "8" }, { "input": "3 0 3", "output": "6" }, { "input": "0 0 2", "output": "2" }, { "input": "97 97 0", "output": "194" }, { "input": "1 4 0", "output": "2" }, { "input": "5 2 0", "output": "4" }, { "input": "0 5 10", "output": "14" }, { "input": "0 1 2", "output": "2" }, { "input": "5 2 3", "output": "10" }, { "input": "5 5 0", "output": "10" }, { "input": "0 0 10", "output": "10" }, { "input": "0 1 1", "output": "2" }, { "input": "0 0 1", "output": "0" } ]
1,682,859,780
2,147,483,647
Python 3
OK
TESTS
79
46
0
def li(): return list(map(int,input().split())) def gi(n): return [list(map(int,input().split())) for _ in range(n)] # File input # import sys # sys.stdin = open('user.txt','r') l,r,a = li() if max(l,r) - min(l,r) > a: print((min(l,r)+a) * 2) else: print((max(l,r) + (a - (max(l,r) - min(l,r))) // 2) * 2)
Title: Left-handers, Right-handers and Ambidexters Time Limit: None seconds Memory Limit: None megabytes Problem Description: You are at a water bowling training. There are *l* people who play with their left hand, *r* people, who play with their right hand, and *a* ambidexters, who can play with left or right hand. The coach decided to form a team of even number of players, exactly half of the players should play with their right hand, and exactly half of the players should play with their left hand. One player should use only on of his hands. Ambidexters play as well with their right hand as with their left hand. In the team, an ambidexter can play with their left hand, or with their right hand. Please find the maximum possible size of the team, where equal number of players use their left and right hands, respectively. Input Specification: The only line contains three integers *l*, *r* and *a* (0<=≤<=*l*,<=*r*,<=*a*<=≤<=100) — the number of left-handers, the number of right-handers and the number of ambidexters at the training. Output Specification: Print a single even integer — the maximum number of players in the team. It is possible that the team can only have zero number of players. Demo Input: ['1 4 2\n', '5 5 5\n', '0 2 0\n'] Demo Output: ['6\n', '14\n', '0\n'] Note: In the first example you can form a team of 6 players. You should take the only left-hander and two ambidexters to play with left hand, and three right-handers to play with right hand. The only person left can't be taken into the team. In the second example you can form a team of 14 people. You have to take all five left-handers, all five right-handers, two ambidexters to play with left hand and two ambidexters to play with right hand.
```python def li(): return list(map(int,input().split())) def gi(n): return [list(map(int,input().split())) for _ in range(n)] # File input # import sys # sys.stdin = open('user.txt','r') l,r,a = li() if max(l,r) - min(l,r) > a: print((min(l,r)+a) * 2) else: print((max(l,r) + (a - (max(l,r) - min(l,r))) // 2) * 2) ```
3
682
C
Alyona and the Tree
PROGRAMMING
1,600
[ "dfs and similar", "dp", "graphs", "trees" ]
null
null
Alyona decided to go on a diet and went to the forest to get some apples. There she unexpectedly found a magic rooted tree with root in the vertex 1, every vertex and every edge of which has a number written on. The girl noticed that some of the tree's vertices are sad, so she decided to play with them. Let's call vertex *v* sad if there is a vertex *u* in subtree of vertex *v* such that *dist*(*v*,<=*u*)<=&gt;<=*a**u*, where *a**u* is the number written on vertex *u*, *dist*(*v*,<=*u*) is the sum of the numbers written on the edges on the path from *v* to *u*. Leaves of a tree are vertices connected to a single vertex by a single edge, but the root of a tree is a leaf if and only if the tree consists of a single vertex — root. Thus Alyona decided to remove some of tree leaves until there will be no any sad vertex left in the tree. What is the minimum number of leaves Alyona needs to remove?
In the first line of the input integer *n* (1<=≤<=*n*<=≤<=105) is given — the number of vertices in the tree. In the second line the sequence of *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=109) is given, where *a**i* is the number written on vertex *i*. The next *n*<=-<=1 lines describe tree edges: *i**th* of them consists of two integers *p**i* and *c**i* (1<=≤<=*p**i*<=≤<=*n*, <=-<=109<=≤<=*c**i*<=≤<=109), meaning that there is an edge connecting vertices *i*<=+<=1 and *p**i* with number *c**i* written on it.
Print the only integer — the minimum number of leaves Alyona needs to remove such that there will be no any sad vertex left in the tree.
[ "9\n88 22 83 14 95 91 98 53 11\n3 24\n7 -8\n1 67\n1 64\n9 65\n5 12\n6 -80\n3 8\n" ]
[ "5\n" ]
The following image represents possible process of removing leaves from the tree:
1,500
[ { "input": "9\n88 22 83 14 95 91 98 53 11\n3 24\n7 -8\n1 67\n1 64\n9 65\n5 12\n6 -80\n3 8", "output": "5" }, { "input": "6\n53 82 15 77 71 23\n5 -77\n6 -73\n2 0\n1 26\n4 -92", "output": "0" }, { "input": "10\n99 60 68 46 51 11 96 41 48 99\n4 50\n6 -97\n3 -92\n7 1\n9 99\n2 79\n1 -15\n8 -68\n5 -84", "output": "7" }, { "input": "8\n53 41 22 22 34 95 56 24\n3 -20\n7 -56\n5 -3\n3 22\n1 37\n6 -34\n2 32", "output": "1" }, { "input": "8\n2 19 83 95 9 87 15 6\n6 16\n7 98\n5 32\n7 90\n8 37\n2 -34\n1 -83", "output": "5" }, { "input": "6\n60 89 33 64 92 75\n4 50\n1 32\n5 21\n3 77\n1 86", "output": "4" }, { "input": "4\n14 66 86 37\n3 -9\n1 93\n2 -57", "output": "3" }, { "input": "9\n59 48 48 14 51 51 86 53 58\n1 -47\n5 10\n8 -6\n9 46\n2 -69\n8 -79\n9 92\n6 12", "output": "5" }, { "input": "3\n17 26 6\n1 -41\n2 -66", "output": "0" }, { "input": "7\n63 3 67 55 14 19 96\n4 35\n1 -23\n3 -66\n2 80\n3 80\n2 -42", "output": "4" }, { "input": "5\n91 61 4 61 35\n5 75\n2 13\n2 -15\n1 90", "output": "4" }, { "input": "19\n40 99 20 54 5 31 67 73 10 46 70 68 80 74 7 58 75 25 13\n13 -28\n12 -33\n9 -62\n12 34\n15 70\n5 -22\n7 83\n2 -24\n6 -64\n17 62\n14 -28\n1 -83\n4 34\n8 -24\n11 19\n6 31\n7 -8\n16 90", "output": "11" }, { "input": "39\n98 80 74 31 81 15 23 52 54 86 56 9 95 91 29 20 97 78 62 65 17 95 12 39 77 17 60 78 76 51 36 56 74 66 43 23 17 9 13\n15 21\n34 -35\n28 80\n13 -15\n29 -34\n38 -8\n18 10\n18 19\n27 54\n7 42\n16 49\n12 90\n39 33\n20 53\n2 91\n33 59\n29 -93\n36 29\n26 50\n5 -12\n33 -6\n17 -60\n27 7\n17 85\n31 63\n26 80\n1 -99\n4 -40\n10 -39\n11 36\n21 22\n16 -15\n14 -25\n25 30\n33 97\n38 26\n8 -78\n10 -7", "output": "37" }, { "input": "19\n51 5 39 54 26 71 97 99 73 16 31 9 52 38 89 87 55 12 3\n18 -94\n19 -48\n2 -61\n10 72\n1 -82\n13 4\n19 -40\n16 -96\n6 -16\n19 -40\n13 44\n11 38\n15 -7\n6 8\n18 -32\n8 -75\n3 58\n10 -15", "output": "7" }, { "input": "39\n100 83 92 26 10 63 56 85 12 64 25 50 75 51 11 41 78 53 52 96 63 12 48 88 57 57 25 52 69 45 4 97 5 87 58 15 72 59 100\n35 -60\n33 -39\n1 65\n11 -65\n34 -63\n38 84\n4 76\n22 -9\n6 -91\n23 -65\n18 7\n2 -17\n29 -15\n19 26\n29 23\n14 -12\n30 -72\n9 14\n12 -1\n27 -21\n32 -67\n7 -3\n26 -18\n12 -45\n33 75\n14 -86\n34 -46\n24 -44\n27 -29\n22 -39\n17 -73\n36 -72\n18 -76\n27 -65\n8 65\n24 -15\n35 79\n27 61", "output": "38" }, { "input": "2\n83 33\n1 67", "output": "1" }, { "input": "6\n538779323 241071283 506741761 673531032 208769045 334127496\n1 -532301622\n5 -912729787\n6 -854756762\n4 -627791911\n2 -289935846", "output": "0" }, { "input": "10\n909382626 193846090 573881879 291637627 123338066 411896152 123287948 171497812 135534629 568762298\n9 -257478179\n4 -502075958\n2 -243790121\n2 -927464462\n8 -89981403\n1 -792322781\n10 -326468006\n7 -261940740\n4 -565652087", "output": "0" } ]
1,467,895,129
2,147,483,647
Python 3
RUNTIME_ERROR
TESTS
11
607
20,582,400
def subtree_dfs(v): size = 1 for u, c in edge[v]: size += subtree_dfs(u) subtree[v] = size return size def remove_dfs(v, path): if path < 0: path = 0 if vertex[v] < path: return subtree[v] removed = 0 for u, c in edge[v]: removed += remove_dfs(u, path + c) return removed n = int(input()) vertex = list(map(int, input().split())) edge = {} subtree = {} for i in range(n): edge[i] = [] for i in range(n - 1): p, c = map(int, input().split()) edge[p - 1] += [(i + 1, c)] subtree_dfs(0) print(remove_dfs(0, 0))
Title: Alyona and the Tree Time Limit: None seconds Memory Limit: None megabytes Problem Description: Alyona decided to go on a diet and went to the forest to get some apples. There she unexpectedly found a magic rooted tree with root in the vertex 1, every vertex and every edge of which has a number written on. The girl noticed that some of the tree's vertices are sad, so she decided to play with them. Let's call vertex *v* sad if there is a vertex *u* in subtree of vertex *v* such that *dist*(*v*,<=*u*)<=&gt;<=*a**u*, where *a**u* is the number written on vertex *u*, *dist*(*v*,<=*u*) is the sum of the numbers written on the edges on the path from *v* to *u*. Leaves of a tree are vertices connected to a single vertex by a single edge, but the root of a tree is a leaf if and only if the tree consists of a single vertex — root. Thus Alyona decided to remove some of tree leaves until there will be no any sad vertex left in the tree. What is the minimum number of leaves Alyona needs to remove? Input Specification: In the first line of the input integer *n* (1<=≤<=*n*<=≤<=105) is given — the number of vertices in the tree. In the second line the sequence of *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=109) is given, where *a**i* is the number written on vertex *i*. The next *n*<=-<=1 lines describe tree edges: *i**th* of them consists of two integers *p**i* and *c**i* (1<=≤<=*p**i*<=≤<=*n*, <=-<=109<=≤<=*c**i*<=≤<=109), meaning that there is an edge connecting vertices *i*<=+<=1 and *p**i* with number *c**i* written on it. Output Specification: Print the only integer — the minimum number of leaves Alyona needs to remove such that there will be no any sad vertex left in the tree. Demo Input: ['9\n88 22 83 14 95 91 98 53 11\n3 24\n7 -8\n1 67\n1 64\n9 65\n5 12\n6 -80\n3 8\n'] Demo Output: ['5\n'] Note: The following image represents possible process of removing leaves from the tree:
```python def subtree_dfs(v): size = 1 for u, c in edge[v]: size += subtree_dfs(u) subtree[v] = size return size def remove_dfs(v, path): if path < 0: path = 0 if vertex[v] < path: return subtree[v] removed = 0 for u, c in edge[v]: removed += remove_dfs(u, path + c) return removed n = int(input()) vertex = list(map(int, input().split())) edge = {} subtree = {} for i in range(n): edge[i] = [] for i in range(n - 1): p, c = map(int, input().split()) edge[p - 1] += [(i + 1, c)] subtree_dfs(0) print(remove_dfs(0, 0)) ```
-1
644
B
Processing Queries
PROGRAMMING
1,700
[ "*special", "constructive algorithms", "data structures", "two pointers" ]
null
null
In this problem you have to simulate the workflow of one-thread server. There are *n* queries to process, the *i*-th will be received at moment *t**i* and needs to be processed for *d**i* units of time. All *t**i* are guaranteed to be distinct. When a query appears server may react in three possible ways: 1. If server is free and query queue is empty, then server immediately starts to process this query. 1. If server is busy and there are less than *b* queries in the queue, then new query is added to the end of the queue. 1. If server is busy and there are already *b* queries pending in the queue, then new query is just rejected and will never be processed. As soon as server finished to process some query, it picks new one from the queue (if it's not empty, of course). If a new query comes at some moment *x*, and the server finishes to process another query at exactly the same moment, we consider that first query is picked from the queue and only then new query appears. For each query find the moment when the server will finish to process it or print -1 if this query will be rejected.
The first line of the input contains two integers *n* and *b* (1<=≤<=*n*,<=*b*<=≤<=200<=000) — the number of queries and the maximum possible size of the query queue. Then follow *n* lines with queries descriptions (in chronological order). Each description consists of two integers *t**i* and *d**i* (1<=≤<=*t**i*,<=*d**i*<=≤<=109), where *t**i* is the moment of time when the *i*-th query appears and *d**i* is the time server needs to process it. It is guaranteed that *t**i*<=-<=1<=&lt;<=*t**i* for all *i*<=&gt;<=1.
Print the sequence of *n* integers *e*1,<=*e*2,<=...,<=*e**n*, where *e**i* is the moment the server will finish to process the *i*-th query (queries are numbered in the order they appear in the input) or <=-<=1 if the corresponding query will be rejected.
[ "5 1\n2 9\n4 8\n10 9\n15 2\n19 1\n", "4 1\n2 8\n4 8\n10 9\n15 2\n" ]
[ "11 19 -1 21 22 \n", "10 18 27 -1 \n" ]
Consider the first sample. 1. The server will start to process first query at the moment 2 and will finish to process it at the moment 11. 1. At the moment 4 second query appears and proceeds to the queue. 1. At the moment 10 third query appears. However, the server is still busy with query 1, *b* = 1 and there is already query 2 pending in the queue, so third query is just rejected. 1. At the moment 11 server will finish to process first query and will take the second query from the queue. 1. At the moment 15 fourth query appears. As the server is currently busy it proceeds to the queue. 1. At the moment 19 two events occur simultaneously: server finishes to proceed the second query and the fifth query appears. As was said in the statement above, first server will finish to process the second query, then it will pick the fourth query from the queue and only then will the fifth query appear. As the queue is empty fifth query is proceed there. 1. Server finishes to process query number 4 at the moment 21. Query number 5 is picked from the queue. 1. Server finishes to process query number 5 at the moment 22.
1,000
[ { "input": "5 1\n2 9\n4 8\n10 9\n15 2\n19 1", "output": "11 19 -1 21 22 " }, { "input": "4 1\n2 8\n4 8\n10 9\n15 2", "output": "10 18 27 -1 " }, { "input": "1 1\n1000000000 1000000000", "output": "2000000000 " }, { "input": "4 3\n999999996 1000000000\n999999997 1000000000\n999999998 1000000000\n999999999 1000000000", "output": "1999999996 2999999996 3999999996 4999999996 " }, { "input": "5 1\n2 1\n3 6\n4 5\n6 4\n7 2", "output": "3 9 14 -1 -1 " }, { "input": "10 2\n4 14\n5 2\n6 6\n7 11\n8 6\n9 5\n10 13\n11 8\n13 2\n20 2", "output": "18 20 26 -1 -1 -1 -1 -1 -1 28 " }, { "input": "6 4\n2 4\n4 2\n5 2\n6 2\n7 2\n9 2", "output": "6 8 10 12 14 16 " }, { "input": "8 3\n1 2\n3 1\n4 3\n5 3\n6 1\n7 2\n8 8\n9 7", "output": "3 4 7 10 11 13 21 -1 " }, { "input": "10 3\n1 14\n3 2\n5 4\n6 9\n9 1\n12 22\n15 11\n18 8\n28 2\n29 4", "output": "15 17 21 30 -1 -1 41 49 51 -1 " }, { "input": "5 2\n2 7\n3 3\n7 4\n9 1\n10 2", "output": "9 12 16 17 -1 " }, { "input": "4 1\n2 1\n6 5\n9 2\n10 3", "output": "3 11 13 -1 " }, { "input": "4 1\n1 2\n2 1\n3 1\n4 3", "output": "3 4 5 8 " }, { "input": "6 3\n1 2\n2 3\n100 200\n200 300\n10000 20000\n20000 30000", "output": "3 6 300 600 30000 60000 " } ]
1,611,284,793
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
31
1,950
16,384,000
import queue query = queue.Queue() q, b = map(int, input().split()) res = [] total = 0 pos = 0 # vị trí trong mảng for i in range(q): t,d = map(int, input().split()) query.put([t,d]) while not query.empty(): [x,y] = query.get() if not res: # ptu đầu total = x + y else: pos += 1 # nếu thời gian đến < thời gian xong của ptu nằm b + 1 vị trí trc nó if pos > 1 and pos - b - 1 >= 0 and x < res[pos - b - 1]: b += 1 # + 1 vì có thêm -1 vào res.append(-1) continue if x > total: total = x + y else: total += y res.append(total) print(*res)
Title: Processing Queries Time Limit: None seconds Memory Limit: None megabytes Problem Description: In this problem you have to simulate the workflow of one-thread server. There are *n* queries to process, the *i*-th will be received at moment *t**i* and needs to be processed for *d**i* units of time. All *t**i* are guaranteed to be distinct. When a query appears server may react in three possible ways: 1. If server is free and query queue is empty, then server immediately starts to process this query. 1. If server is busy and there are less than *b* queries in the queue, then new query is added to the end of the queue. 1. If server is busy and there are already *b* queries pending in the queue, then new query is just rejected and will never be processed. As soon as server finished to process some query, it picks new one from the queue (if it's not empty, of course). If a new query comes at some moment *x*, and the server finishes to process another query at exactly the same moment, we consider that first query is picked from the queue and only then new query appears. For each query find the moment when the server will finish to process it or print -1 if this query will be rejected. Input Specification: The first line of the input contains two integers *n* and *b* (1<=≤<=*n*,<=*b*<=≤<=200<=000) — the number of queries and the maximum possible size of the query queue. Then follow *n* lines with queries descriptions (in chronological order). Each description consists of two integers *t**i* and *d**i* (1<=≤<=*t**i*,<=*d**i*<=≤<=109), where *t**i* is the moment of time when the *i*-th query appears and *d**i* is the time server needs to process it. It is guaranteed that *t**i*<=-<=1<=&lt;<=*t**i* for all *i*<=&gt;<=1. Output Specification: Print the sequence of *n* integers *e*1,<=*e*2,<=...,<=*e**n*, where *e**i* is the moment the server will finish to process the *i*-th query (queries are numbered in the order they appear in the input) or <=-<=1 if the corresponding query will be rejected. Demo Input: ['5 1\n2 9\n4 8\n10 9\n15 2\n19 1\n', '4 1\n2 8\n4 8\n10 9\n15 2\n'] Demo Output: ['11 19 -1 21 22 \n', '10 18 27 -1 \n'] Note: Consider the first sample. 1. The server will start to process first query at the moment 2 and will finish to process it at the moment 11. 1. At the moment 4 second query appears and proceeds to the queue. 1. At the moment 10 third query appears. However, the server is still busy with query 1, *b* = 1 and there is already query 2 pending in the queue, so third query is just rejected. 1. At the moment 11 server will finish to process first query and will take the second query from the queue. 1. At the moment 15 fourth query appears. As the server is currently busy it proceeds to the queue. 1. At the moment 19 two events occur simultaneously: server finishes to proceed the second query and the fifth query appears. As was said in the statement above, first server will finish to process the second query, then it will pick the fourth query from the queue and only then will the fifth query appear. As the queue is empty fifth query is proceed there. 1. Server finishes to process query number 4 at the moment 21. Query number 5 is picked from the queue. 1. Server finishes to process query number 5 at the moment 22.
```python import queue query = queue.Queue() q, b = map(int, input().split()) res = [] total = 0 pos = 0 # vị trí trong mảng for i in range(q): t,d = map(int, input().split()) query.put([t,d]) while not query.empty(): [x,y] = query.get() if not res: # ptu đầu total = x + y else: pos += 1 # nếu thời gian đến < thời gian xong của ptu nằm b + 1 vị trí trc nó if pos > 1 and pos - b - 1 >= 0 and x < res[pos - b - 1]: b += 1 # + 1 vì có thêm -1 vào res.append(-1) continue if x > total: total = x + y else: total += y res.append(total) print(*res) ```
0
864
B
Polycarp and Letters
PROGRAMMING
1,000
[ "brute force", "implementation", "strings" ]
null
null
Polycarp loves lowercase letters and dislikes uppercase ones. Once he got a string *s* consisting only of lowercase and uppercase Latin letters. Let *A* be a set of positions in the string. Let's call it pretty if following conditions are met: - letters on positions from *A* in the string are all distinct and lowercase; - there are no uppercase letters in the string which are situated between positions from *A* (i.e. there is no such *j* that *s*[*j*] is an uppercase letter, and *a*1<=&lt;<=*j*<=&lt;<=*a*2 for some *a*1 and *a*2 from *A*). Write a program that will determine the maximum number of elements in a pretty set of positions.
The first line contains a single integer *n* (1<=≤<=*n*<=≤<=200) — length of string *s*. The second line contains a string *s* consisting of lowercase and uppercase Latin letters.
Print maximum number of elements in pretty set of positions for string *s*.
[ "11\naaaaBaabAbA\n", "12\nzACaAbbaazzC\n", "3\nABC\n" ]
[ "2\n", "3\n", "0\n" ]
In the first example the desired positions might be 6 and 8 or 7 and 8. Positions 6 and 7 contain letters 'a', position 8 contains letter 'b'. The pair of positions 1 and 8 is not suitable because there is an uppercase letter 'B' between these position. In the second example desired positions can be 7, 8 and 11. There are other ways to choose pretty set consisting of three elements. In the third example the given string *s* does not contain any lowercase letters, so the answer is 0.
1,000
[ { "input": "11\naaaaBaabAbA", "output": "2" }, { "input": "12\nzACaAbbaazzC", "output": "3" }, { "input": "3\nABC", "output": "0" }, { "input": "1\na", "output": "1" }, { "input": "2\naz", "output": "2" }, { "input": "200\nXbTJZqcbpYuZQEoUrbxlPXAPCtVLrRExpQzxzqzcqsqzsiisswqitswzCtJQxOavicSdBIodideVRKHPojCNHmbnrLgwJlwOpyrJJIhrUePszxSjJGeUgTtOfewPQnPVWhZAtogRPrJLwyShNQaeNsvrJwjuuBOMPCeSckBMISQzGngfOmeyfDObncyeNsihYVtQbSEh", "output": "8" }, { "input": "2\nAZ", "output": "0" }, { "input": "28\nAabcBabcCBNMaaaaabbbbbcccccc", "output": "3" }, { "input": "200\nrsgraosldglhdoorwhkrsehjpuxrjuwgeanjgezhekprzarelduuaxdnspzjuooguuwnzkowkuhzduakdrzpnslauejhrrkalwpurpuuswdgeadlhjwzjgegwpknepazwwleulppwrlgrgedlwdzuodzropsrrkxusjnuzshdkjrxxpgzanzdrpnggdwxarpwohxdepJ", "output": "17" }, { "input": "1\nk", "output": "1" }, { "input": "1\nH", "output": "0" }, { "input": "2\nzG", "output": "1" }, { "input": "2\ngg", "output": "1" }, { "input": "2\nai", "output": "2" }, { "input": "20\npEjVrKWLIFCZjIHgggVU", "output": "1" }, { "input": "20\niFSiiigiYFSKmDnMGcgM", "output": "2" }, { "input": "20\nedxedxxxCQiIVmYEUtLi", "output": "3" }, { "input": "20\nprnchweyabjvzkoqiltm", "output": "20" }, { "input": "35\nQLDZNKFXKVSVLUVHRTDPQYMSTDXBELXBOTS", "output": "0" }, { "input": "35\nbvZWiitgxodztelnYUyljYGnCoWluXTvBLp", "output": "10" }, { "input": "35\nBTexnaeplecllxwlanarpcollawHLVMHIIF", "output": "10" }, { "input": "35\nhhwxqysolegsthsvfcqiryenbujbrrScobu", "output": "20" }, { "input": "26\npbgfqosklxjuzmdheyvawrictn", "output": "26" }, { "input": "100\nchMRWwymTDuZDZuSTvUmmuxvSscnTasyjlwwodhzcoifeahnbmcifyeobbydwparebduoLDCgHlOsPtVRbYGGQXfnkdvrWKIwCRl", "output": "20" }, { "input": "100\nhXYLXKUMBrGkjqQJTGbGWAfmztqqapdbjbhcualhypgnaieKXmhzGMnqXVlcPesskfaEVgvWQTTShRRnEtFahWDyuBzySMpugxCM", "output": "19" }, { "input": "100\nucOgELrgjMrFOgtHzqgvUgtHngKJxdMFKBjfcCppciqmGZXXoiSZibgpadshyljqrwxbomzeutvnhTLGVckZUmyiFPLlwuLBFito", "output": "23" }, { "input": "200\nWTCKAKLVGXSYFVMVJDUYERXNMVNTGWXUGRFCGMYXJQGLODYZTUIDENHYEGFKXFIEUILAMESAXAWZXVCZPJPEYUXBITHMTZOTMKWITGRSFHODKVJHPAHVVWTCTHIVAWAREQXWMPUWQSTPPJFHKGKELBTPUYDAVIUMGASPUEDIODRYXIWCORHOSLIBLOZUNJPHHMXEXOAY", "output": "0" }, { "input": "200\neLCCuYMPPwQoNlCpPOtKWJaQJmWfHeZCKiMSpILHSKjFOYGpRMzMCfMXdDuQdBGNsCNrHIVJzEFfBZcNMwNcFjOFVJvEtUQmLbFNKVHgNDyFkFVQhUTUQDgXhMjJZgFSSiHhMKuTgZQYJqAqKBpHoHddddddddddddddddXSSYNKNnRrKuOjAVKZlRLzCjExPdHaDHBT", "output": "1" }, { "input": "200\nitSYxgOLlwOoAkkkkkzzzzzzzzkzkzkzkkkkkzkzzkzUDJSKybRPBvaIDsNuWImPJvrHkKiMeYukWmtHtgZSyQsgYanZvXNbKXBlFLSUcqRnGWSriAvKxsTkDJfROqaKdzXhvJsPEDATueCraWOGEvRDWjPwXuiNpWsEnCuhDcKWOQxjBkdBqmFatWFkgKsbZuLtRGtY", "output": "2" }, { "input": "200\noggqoqqogoqoggggoggqgooqggogogooogqqgggoqgggqoqogogggogggqgooqgqggqqqoqgqgoooqgqogqoggoqqgqoqgoooqoogooqoogqoqoqqgoqgoqgggogqqqoqoggoqoqqoqggqoggooqqqoqggoggqqqqqqqqqgogqgggggooogogqgggqogqgoqoqogoooq", "output": "3" }, { "input": "200\nCtclUtUnmqFniaLqGRmMoUMeLyFfAgWxIZxdrBarcRQprSOGcdUYsmDbooSuOvBLgrYlgaIjJtFgcxJKHGkCXpYfVKmUbouuIqGstFrrwJzYQqjjqqppqqqqqpqqqjpjjpjqjXRYkfPhGAatOigFuItkKxkjCBLdiNMVGjmdWNMgOOvmaJEdGsWNoaERrINNKqKeQajv", "output": "3" }, { "input": "200\nmeZNrhqtSTSmktGQnnNOTcnyAMTKSixxKQKiagrMqRYBqgbRlsbJhvtNeHVUuMCyZLCnsIixRYrYEAkfQOxSVqXkrPqeCZQksInzRsRKBgvIqlGVPxPQnypknSXjgMjsjElcqGsaJRbegJVAKtWcHoOnzHqzhoKReqBBsOhZYLaYJhmqOMQsizdCsQfjUDHcTtHoeYwu", "output": "4" }, { "input": "200\nvFAYTHJLZaivWzSYmiuDBDUFACDSVbkImnVaXBpCgrbgmTfXKJfoglIkZxWPSeVSFPnHZDNUAqLyhjLXSuAqGLskBlDxjxGPJyGdwzlPfIekwsblIrkxzfhJeNoHywdfAGlJzqXOfQaKceSqViVFTRJEGfACnsFeSFpOYisIHJciqTMNAmgeXeublTvfWoPnddtvKIyF", "output": "6" }, { "input": "200\ngnDdkqJjYvduVYDSsswZDvoCouyaYZTfhmpSakERWLhufZtthWsfbQdTGwhKYjEcrqWBOyxBbiFhdLlIjChLOPiOpYmcrJgDtXsJfmHtLrabyGKOfHQRukEtTzwoqBHfmyVXPebfcpGQacLkGWFwerszjdHpTBXGssYXmGHlcCBgBXyGJqxbVhvDffLyCrZnxonABEXV", "output": "7" }, { "input": "200\nBmggKNRZBXPtJqlJaXLdKKQLDJvXpDuQGupiRQfDwCJCJvAlDDGpPZNOvXkrdKOFOEFBVfrsZjWyHPoKGzXmTAyPJGEmxCyCXpeAdTwbrMtWLmlmGNqxvuxmqpmtpuhrmxxtrquSLFYVlnSYgRJDYHWgHBbziBLZRwCIJNvbtsEdLLxmTbnjkoqSPAuzEeTYLlmejOUH", "output": "9" }, { "input": "200\nMkuxcDWdcnqsrlTsejehQKrTwoOBRCUAywqSnZkDLRmVBDVoOqdZHbrInQQyeRFAjiYYmHGrBbWgWstCPfLPRdNVDXBdqFJsGQfSXbufsiogybEhKDlWfPazIuhpONwGzZWaQNwVnmhTqWdewaklgjwaumXYDGwjSeEcYXjkVtLiYSWULEnTFukIlWQGWsXwWRMJGTcI", "output": "10" }, { "input": "200\nOgMBgYeuMJdjPtLybvwmGDrQEOhliaabEtwulzNEjsfnaznXUMoBbbxkLEwSQzcLrlJdjJCLGVNBxorghPxTYCoqniySJMcilpsqpBAbqdzqRUDVaYOgqGhGrxlIJkyYgkOdTUgRZwpgIkeZFXojLXpDilzirHVVadiHaMrxhzodzpdvhvrzdzxbhmhdpxqqpoDegfFQ", "output": "11" }, { "input": "200\nOLaJOtwultZLiZPSYAVGIbYvbIuZkqFZXwfsqpsavCDmBMStAuUFLBVknWDXNzmiuUYIsUMGxtoadWlPYPqvqSvpYdOiJRxFzGGnnmstniltvitnrmyrblnqyruylummmlsqtqitlbulvtuitiqimuintbimqyurviuntqnnvslynlNYMpYVKYwKVTbIUVdlNGrcFZON", "output": "12" }, { "input": "200\nGAcmlaqfjSAQLvXlkhxujXgSbxdFAwnoxDuldDvYmpUhTWJdcEQSdARLrozJzIgFVCkzPUztWIpaGfiKeqzoXinEjVuoKqyBHmtFjBWcRdBmyjviNlGAIkpikjAimmBgayfphrstfbjexjbttzfzfzaysxfyrjazfhtpghnbbeffjhxrjxpttesgzrnrfbgzzsRsCgmz", "output": "15" }, { "input": "200\nYRvIopNqSTYDhViTqCLMwEbTTIdHkoeuBmAJWhgtOgVxlcHSsavDNzMfpwTghkBvYEtCYQxicLUxdgAcaCzOOgbQYsfnaTXFlFxbeEiGwdNvxwHzkTdKtWlqzalwniDDBDipkxfflpaqkfkgfezbkxdvzemlfohwtgytzzywmwhvzUgPlPdeAVqTPAUZbogQheRXetvT", "output": "20" }, { "input": "200\nNcYVomemswLCUqVRSDKHCknlBmqeSWhVyRzQrnZaOANnTGqsRFMjpczllcEVebqpxdavzppvztxsnfmtcharzqlginndyjkawzurqkxJLXiXKNZTIIxhSQghDpjwzatEqnLMTLxwoEKpHytvWkKFDUcZjLShCiVdocxRvvJtbXHCDGpJvMwRKWLhcTFtswdLUHkbhfau", "output": "25" }, { "input": "200\nDxNZuvkTkQEqdWIkLzcKAwfqvZQiptnTazydSCTIfGjDhLMrlPZiKEsqIdDhgKPAlEvXyzNwWtYorotgkcwydpabjqnzubaksdchucxtkmjzfretdmvlxgklyvicrtftvztsbiUaQorfNIYUOdwQDRsKpxLUiLknbLbinilpPXPTTwLAnXVpMHBaAcKWgDBeOFabPtXU", "output": "26" }, { "input": "4\nabbc", "output": "3" }, { "input": "3\naaa", "output": "1" }, { "input": "3\naba", "output": "2" }, { "input": "3\nabb", "output": "2" }, { "input": "3\nbba", "output": "2" }, { "input": "3\nAaa", "output": "1" }, { "input": "3\nAba", "output": "2" }, { "input": "3\naBa", "output": "1" }, { "input": "3\naAa", "output": "1" }, { "input": "3\naAb", "output": "1" }, { "input": "3\nAaA", "output": "1" }, { "input": "5\naBacd", "output": "3" }, { "input": "5\naAabc", "output": "3" } ]
1,600,254,302
2,147,483,647
PyPy 3
WRONG_ANSWER
TESTS
0
109
0
n = int(input()) s = input() if s.isupper() or (len(set(s)) == 1): print(0) exit() cnt = 0 for i in range(1,n): k = s[i-1] if s[i].islower(): if k.islower() and s[i] != k: cnt +=1 else: cnt = cnt else: cnt = cnt continue print(cnt)
Title: Polycarp and Letters Time Limit: None seconds Memory Limit: None megabytes Problem Description: Polycarp loves lowercase letters and dislikes uppercase ones. Once he got a string *s* consisting only of lowercase and uppercase Latin letters. Let *A* be a set of positions in the string. Let's call it pretty if following conditions are met: - letters on positions from *A* in the string are all distinct and lowercase; - there are no uppercase letters in the string which are situated between positions from *A* (i.e. there is no such *j* that *s*[*j*] is an uppercase letter, and *a*1<=&lt;<=*j*<=&lt;<=*a*2 for some *a*1 and *a*2 from *A*). Write a program that will determine the maximum number of elements in a pretty set of positions. Input Specification: The first line contains a single integer *n* (1<=≤<=*n*<=≤<=200) — length of string *s*. The second line contains a string *s* consisting of lowercase and uppercase Latin letters. Output Specification: Print maximum number of elements in pretty set of positions for string *s*. Demo Input: ['11\naaaaBaabAbA\n', '12\nzACaAbbaazzC\n', '3\nABC\n'] Demo Output: ['2\n', '3\n', '0\n'] Note: In the first example the desired positions might be 6 and 8 or 7 and 8. Positions 6 and 7 contain letters 'a', position 8 contains letter 'b'. The pair of positions 1 and 8 is not suitable because there is an uppercase letter 'B' between these position. In the second example desired positions can be 7, 8 and 11. There are other ways to choose pretty set consisting of three elements. In the third example the given string *s* does not contain any lowercase letters, so the answer is 0.
```python n = int(input()) s = input() if s.isupper() or (len(set(s)) == 1): print(0) exit() cnt = 0 for i in range(1,n): k = s[i-1] if s[i].islower(): if k.islower() and s[i] != k: cnt +=1 else: cnt = cnt else: cnt = cnt continue print(cnt) ```
0
727
A
Transformation: from A to B
PROGRAMMING
1,000
[ "brute force", "dfs and similar", "math" ]
null
null
Vasily has a number *a*, which he wants to turn into a number *b*. For this purpose, he can do two types of operations: - multiply the current number by 2 (that is, replace the number *x* by 2·*x*); - append the digit 1 to the right of current number (that is, replace the number *x* by 10·*x*<=+<=1). You need to help Vasily to transform the number *a* into the number *b* using only the operations described above, or find that it is impossible. Note that in this task you are not required to minimize the number of operations. It suffices to find any way to transform *a* into *b*.
The first line contains two positive integers *a* and *b* (1<=≤<=*a*<=&lt;<=*b*<=≤<=109) — the number which Vasily has and the number he wants to have.
If there is no way to get *b* from *a*, print "NO" (without quotes). Otherwise print three lines. On the first line print "YES" (without quotes). The second line should contain single integer *k* — the length of the transformation sequence. On the third line print the sequence of transformations *x*1,<=*x*2,<=...,<=*x**k*, where: - *x*1 should be equal to *a*, - *x**k* should be equal to *b*, - *x**i* should be obtained from *x**i*<=-<=1 using any of two described operations (1<=&lt;<=*i*<=≤<=*k*). If there are multiple answers, print any of them.
[ "2 162\n", "4 42\n", "100 40021\n" ]
[ "YES\n5\n2 4 8 81 162 \n", "NO\n", "YES\n5\n100 200 2001 4002 40021 \n" ]
none
1,000
[ { "input": "2 162", "output": "YES\n5\n2 4 8 81 162 " }, { "input": "4 42", "output": "NO" }, { "input": "100 40021", "output": "YES\n5\n100 200 2001 4002 40021 " }, { "input": "1 111111111", "output": "YES\n9\n1 11 111 1111 11111 111111 1111111 11111111 111111111 " }, { "input": "1 1000000000", "output": "NO" }, { "input": "999999999 1000000000", "output": "NO" }, { "input": "1 2", "output": "YES\n2\n1 2 " }, { "input": "1 536870912", "output": "YES\n30\n1 2 4 8 16 32 64 128 256 512 1024 2048 4096 8192 16384 32768 65536 131072 262144 524288 1048576 2097152 4194304 8388608 16777216 33554432 67108864 134217728 268435456 536870912 " }, { "input": "11111 11111111", "output": "YES\n4\n11111 111111 1111111 11111111 " }, { "input": "59139 946224", "output": "YES\n5\n59139 118278 236556 473112 946224 " }, { "input": "9859 19718", "output": "YES\n2\n9859 19718 " }, { "input": "25987 51974222", "output": "YES\n5\n25987 259871 2598711 25987111 51974222 " }, { "input": "9411 188222222", "output": "YES\n6\n9411 94111 941111 9411111 94111111 188222222 " }, { "input": "25539 510782222", "output": "YES\n6\n25539 255391 2553911 25539111 255391111 510782222 " }, { "input": "76259 610072", "output": "YES\n4\n76259 152518 305036 610072 " }, { "input": "92387 184774", "output": "YES\n2\n92387 184774 " }, { "input": "8515 85151111", "output": "YES\n5\n8515 85151 851511 8515111 85151111 " }, { "input": "91939 9193911", "output": "YES\n3\n91939 919391 9193911 " }, { "input": "30518 610361", "output": "YES\n3\n30518 61036 610361 " }, { "input": "46646 373168844", "output": "YES\n7\n46646 466461 932922 9329221 93292211 186584422 373168844 " }, { "input": "30070 300701", "output": "YES\n2\n30070 300701 " }, { "input": "13494 1079528", "output": "YES\n5\n13494 134941 269882 539764 1079528 " }, { "input": "96918 775344422", "output": "YES\n7\n96918 193836 1938361 3876722 38767221 387672211 775344422 " }, { "input": "13046 260921", "output": "YES\n3\n13046 26092 260921 " }, { "input": "29174 5834811", "output": "YES\n4\n29174 58348 583481 5834811 " }, { "input": "79894 319576421", "output": "YES\n6\n79894 798941 1597882 15978821 31957642 319576421 " }, { "input": "96022 1920442", "output": "YES\n3\n96022 960221 1920442 " }, { "input": "79446 6355681", "output": "YES\n5\n79446 158892 317784 635568 6355681 " }, { "input": "5440 27853056", "output": "YES\n11\n5440 10880 108801 217602 435204 870408 1740816 3481632 6963264 13926528 27853056 " }, { "input": "250000000 705032705", "output": "NO" }, { "input": "17 35", "output": "NO" }, { "input": "1 3", "output": "NO" }, { "input": "2 11", "output": "NO" } ]
1,594,193,638
2,147,483,647
PyPy 3
OK
TESTS
33
171
24,985,600
a, b = map(int, input().split()) seq = [] def d(s): if s > b: return False if s == b: return True for i in range(2): if i==0: hit = d(2*s) if hit: seq.append(2*s) return True if i == 1: hit = d(10*s +1) if hit: seq.append(10*s + 1) return True d(a) if len(seq) > 0: print("YES") # seq += [a] seq.append(a) print(len(seq)) for i in reversed(seq): print(i, end = " ") else: print("NO")
Title: Transformation: from A to B Time Limit: None seconds Memory Limit: None megabytes Problem Description: Vasily has a number *a*, which he wants to turn into a number *b*. For this purpose, he can do two types of operations: - multiply the current number by 2 (that is, replace the number *x* by 2·*x*); - append the digit 1 to the right of current number (that is, replace the number *x* by 10·*x*<=+<=1). You need to help Vasily to transform the number *a* into the number *b* using only the operations described above, or find that it is impossible. Note that in this task you are not required to minimize the number of operations. It suffices to find any way to transform *a* into *b*. Input Specification: The first line contains two positive integers *a* and *b* (1<=≤<=*a*<=&lt;<=*b*<=≤<=109) — the number which Vasily has and the number he wants to have. Output Specification: If there is no way to get *b* from *a*, print "NO" (without quotes). Otherwise print three lines. On the first line print "YES" (without quotes). The second line should contain single integer *k* — the length of the transformation sequence. On the third line print the sequence of transformations *x*1,<=*x*2,<=...,<=*x**k*, where: - *x*1 should be equal to *a*, - *x**k* should be equal to *b*, - *x**i* should be obtained from *x**i*<=-<=1 using any of two described operations (1<=&lt;<=*i*<=≤<=*k*). If there are multiple answers, print any of them. Demo Input: ['2 162\n', '4 42\n', '100 40021\n'] Demo Output: ['YES\n5\n2 4 8 81 162 \n', 'NO\n', 'YES\n5\n100 200 2001 4002 40021 \n'] Note: none
```python a, b = map(int, input().split()) seq = [] def d(s): if s > b: return False if s == b: return True for i in range(2): if i==0: hit = d(2*s) if hit: seq.append(2*s) return True if i == 1: hit = d(10*s +1) if hit: seq.append(10*s + 1) return True d(a) if len(seq) > 0: print("YES") # seq += [a] seq.append(a) print(len(seq)) for i in reversed(seq): print(i, end = " ") else: print("NO") ```
3
409
F
000001
PROGRAMMING
1,900
[ "*special" ]
null
null
The input contains a single integer *a* (1<=≤<=*a*<=≤<=64). Output a single integer.
The input contains a single integer *a* (1<=≤<=*a*<=≤<=64).
Output a single integer.
[ "2\n", "4\n", "27\n", "42\n" ]
[ "1\n", "2\n", "5\n", "6\n" ]
none
0
[ { "input": "2", "output": "1" }, { "input": "4", "output": "2" }, { "input": "27", "output": "5" }, { "input": "42", "output": "6" }, { "input": "1", "output": "1" }, { "input": "3", "output": "1" }, { "input": "64", "output": "267" }, { "input": "5", "output": "1" }, { "input": "6", "output": "2" }, { "input": "7", "output": "1" }, { "input": "8", "output": "5" }, { "input": "9", "output": "2" }, { "input": "10", "output": "2" }, { "input": "11", "output": "1" }, { "input": "12", "output": "5" }, { "input": "13", "output": "1" }, { "input": "14", "output": "2" }, { "input": "15", "output": "1" }, { "input": "16", "output": "14" }, { "input": "17", "output": "1" }, { "input": "18", "output": "5" }, { "input": "19", "output": "1" }, { "input": "20", "output": "5" }, { "input": "21", "output": "2" }, { "input": "22", "output": "2" }, { "input": "23", "output": "1" }, { "input": "24", "output": "15" }, { "input": "25", "output": "2" }, { "input": "26", "output": "2" }, { "input": "28", "output": "4" }, { "input": "29", "output": "1" }, { "input": "30", "output": "4" }, { "input": "31", "output": "1" }, { "input": "32", "output": "51" }, { "input": "33", "output": "1" }, { "input": "34", "output": "2" }, { "input": "35", "output": "1" }, { "input": "36", "output": "14" }, { "input": "37", "output": "1" }, { "input": "38", "output": "2" }, { "input": "39", "output": "2" }, { "input": "40", "output": "14" }, { "input": "41", "output": "1" }, { "input": "43", "output": "1" }, { "input": "44", "output": "4" }, { "input": "45", "output": "2" }, { "input": "46", "output": "2" }, { "input": "47", "output": "1" }, { "input": "48", "output": "52" }, { "input": "49", "output": "2" }, { "input": "50", "output": "5" }, { "input": "51", "output": "1" }, { "input": "52", "output": "5" }, { "input": "53", "output": "1" }, { "input": "54", "output": "15" }, { "input": "55", "output": "2" }, { "input": "56", "output": "13" }, { "input": "57", "output": "2" }, { "input": "58", "output": "2" }, { "input": "59", "output": "1" }, { "input": "60", "output": "13" }, { "input": "61", "output": "1" }, { "input": "62", "output": "2" }, { "input": "63", "output": "4" } ]
1,692,211,470
2,147,483,647
PyPy 3-64
OK
TESTS
64
62
0
from sys import stdin,stdout # from os import _exit # from bisect import bisect_left,bisect # from heapq import heapify,heappop,heappush # from sys import setrecursionlimit # from collections import defaultdict,Counter # from itertools import permutations # from math import gcd,ceil,sqrt,factorial # setrecursionlimit(int(1e5)) input,print = stdin.readline,stdout.write print(str([0, 1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51, 1, 2, 1, 14, 1, 2, 2, 14, 1, 6, 1, 4, 2, 2, 1, 52, 2, 5, 1, 5, 1, 15, 2, 13, 2, 2, 1, 13, 1, 2, 4, 267, 1, 4, 1, 5, 1, 4, 1, 50, 1, 2, 3, 4, 1, 6, 1, 52, 15, 2, 1, 15, 1, 2, 1, 12, 1, 10, 1, 4, 2][int(input())])+"\n")
Title: 000001 Time Limit: None seconds Memory Limit: None megabytes Problem Description: The input contains a single integer *a* (1<=≤<=*a*<=≤<=64). Output a single integer. Input Specification: The input contains a single integer *a* (1<=≤<=*a*<=≤<=64). Output Specification: Output a single integer. Demo Input: ['2\n', '4\n', '27\n', '42\n'] Demo Output: ['1\n', '2\n', '5\n', '6\n'] Note: none
```python from sys import stdin,stdout # from os import _exit # from bisect import bisect_left,bisect # from heapq import heapify,heappop,heappush # from sys import setrecursionlimit # from collections import defaultdict,Counter # from itertools import permutations # from math import gcd,ceil,sqrt,factorial # setrecursionlimit(int(1e5)) input,print = stdin.readline,stdout.write print(str([0, 1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51, 1, 2, 1, 14, 1, 2, 2, 14, 1, 6, 1, 4, 2, 2, 1, 52, 2, 5, 1, 5, 1, 15, 2, 13, 2, 2, 1, 13, 1, 2, 4, 267, 1, 4, 1, 5, 1, 4, 1, 50, 1, 2, 3, 4, 1, 6, 1, 52, 15, 2, 1, 15, 1, 2, 1, 12, 1, 10, 1, 4, 2][int(input())])+"\n") ```
3
575
D
Tablecity
PROGRAMMING
1,700
[ "constructive algorithms", "implementation" ]
null
null
There was a big bank robbery in Tablecity. In order to catch the thief, the President called none other than Albert – Tablecity’s Chief of Police. Albert does not know where the thief is located, but he does know how he moves. Tablecity can be represented as 1000<=×<=2 grid, where every cell represents one district. Each district has its own unique name “(*X*,<=*Y*)”, where *X* and *Y* are the coordinates of the district in the grid. The thief’s movement is as Every hour the thief will leave the district (*X*,<=*Y*) he is currently hiding in, and move to one of the districts: (*X*<=-<=1,<=*Y*), (*X*<=+<=1,<=*Y*), (*X*<=-<=1,<=*Y*<=-<=1), (*X*<=-<=1,<=*Y*<=+<=1), (*X*<=+<=1,<=*Y*<=-<=1), (*X*<=+<=1,<=*Y*<=+<=1) as long as it exists in Tablecity. Below is an example of thief’s possible movements if he is located in district (7,1): Albert has enough people so that every hour he can pick any two districts in Tablecity and fully investigate them, making sure that if the thief is located in one of them, he will get caught. Albert promised the President that the thief will be caught in no more than 2015 hours and needs your help in order to achieve that.
There is no input for this problem.
The first line of output contains integer *N* – duration of police search in hours. Each of the following *N* lines contains exactly 4 integers *X**i*1, *Y**i*1, *X**i*2, *Y**i*2 separated by spaces, that represent 2 districts (*X**i*1, *Y**i*1), (*X**i*2, *Y**i*2) which got investigated during i-th hour. Output is given in chronological order (i-th line contains districts investigated during i-th hour) and should guarantee that the thief is caught in no more than 2015 hours, regardless of thief’s initial position and movement. - *N*<=≤<=2015 - 1<=≤<=*X*<=≤<=1000 - 1<=≤<=*Y*<=≤<=2
[ "В этой задаче нет примеров ввода-вывода.\nThis problem doesn't have sample input and output." ]
[ "Смотрите замечание ниже.\nSee the note below." ]
Let's consider the following output: 2 5 1 50 2 8 1 80 2 This output is not guaranteed to catch the thief and is not correct. It is given to you only to show the expected output format. There exists a combination of an initial position and a movement strategy such that the police will not catch the thief. Consider the following initial position and thief’s movement: In the first hour, the thief is located in district (1,1). Police officers will search districts (5,1) and (50,2) and will not find him. At the start of the second hour, the thief moves to district (2,2). Police officers will search districts (8,1) and (80,2) and will not find him. Since there is no further investigation by the police, the thief escaped!
0
[ { "input": "dummy", "output": "2000\n1 1 1 2\n2 1 2 2\n3 1 3 2\n4 1 4 2\n5 1 5 2\n6 1 6 2\n7 1 7 2\n8 1 8 2\n9 1 9 2\n10 1 10 2\n11 1 11 2\n12 1 12 2\n13 1 13 2\n14 1 14 2\n15 1 15 2\n16 1 16 2\n17 1 17 2\n18 1 18 2\n19 1 19 2\n20 1 20 2\n21 1 21 2\n22 1 22 2\n23 1 23 2\n24 1 24 2\n25 1 25 2\n26 1 26 2\n27 1 27 2\n28 1 28 2\n29 1 29 2\n30 1 30 2\n31 1 31 2\n32 1 32 2\n33 1 33 2\n34 1 34 2\n35 1 35 2\n36 1 36 2\n37 1 37 2\n38 1 38 2\n39 1 39 2\n40 1 40 2\n41 1 41 2\n42 1 42 2\n43 1 43 2\n44 1 44 2\n45 1 45 2\n46 1 46 2\n47 1 47 2\n48 1 4..." } ]
1,442,062,414
2,147,483,647
PyPy 3
WRONG_ANSWER
TESTS
0
124
2,560,000
print(1998); [print(i, 2, i, 1) for i in range(1, 1000)] * 2
Title: Tablecity Time Limit: None seconds Memory Limit: None megabytes Problem Description: There was a big bank robbery in Tablecity. In order to catch the thief, the President called none other than Albert – Tablecity’s Chief of Police. Albert does not know where the thief is located, but he does know how he moves. Tablecity can be represented as 1000<=×<=2 grid, where every cell represents one district. Each district has its own unique name “(*X*,<=*Y*)”, where *X* and *Y* are the coordinates of the district in the grid. The thief’s movement is as Every hour the thief will leave the district (*X*,<=*Y*) he is currently hiding in, and move to one of the districts: (*X*<=-<=1,<=*Y*), (*X*<=+<=1,<=*Y*), (*X*<=-<=1,<=*Y*<=-<=1), (*X*<=-<=1,<=*Y*<=+<=1), (*X*<=+<=1,<=*Y*<=-<=1), (*X*<=+<=1,<=*Y*<=+<=1) as long as it exists in Tablecity. Below is an example of thief’s possible movements if he is located in district (7,1): Albert has enough people so that every hour he can pick any two districts in Tablecity and fully investigate them, making sure that if the thief is located in one of them, he will get caught. Albert promised the President that the thief will be caught in no more than 2015 hours and needs your help in order to achieve that. Input Specification: There is no input for this problem. Output Specification: The first line of output contains integer *N* – duration of police search in hours. Each of the following *N* lines contains exactly 4 integers *X**i*1, *Y**i*1, *X**i*2, *Y**i*2 separated by spaces, that represent 2 districts (*X**i*1, *Y**i*1), (*X**i*2, *Y**i*2) which got investigated during i-th hour. Output is given in chronological order (i-th line contains districts investigated during i-th hour) and should guarantee that the thief is caught in no more than 2015 hours, regardless of thief’s initial position and movement. - *N*<=≤<=2015 - 1<=≤<=*X*<=≤<=1000 - 1<=≤<=*Y*<=≤<=2 Demo Input: ["В этой задаче нет примеров ввода-вывода.\nThis problem doesn't have sample input and output."] Demo Output: ['Смотрите замечание ниже.\nSee the note below.'] Note: Let's consider the following output: 2 5 1 50 2 8 1 80 2 This output is not guaranteed to catch the thief and is not correct. It is given to you only to show the expected output format. There exists a combination of an initial position and a movement strategy such that the police will not catch the thief. Consider the following initial position and thief’s movement: In the first hour, the thief is located in district (1,1). Police officers will search districts (5,1) and (50,2) and will not find him. At the start of the second hour, the thief moves to district (2,2). Police officers will search districts (8,1) and (80,2) and will not find him. Since there is no further investigation by the police, the thief escaped!
```python print(1998); [print(i, 2, i, 1) for i in range(1, 1000)] * 2 ```
0
465
A
inc ARG
PROGRAMMING
900
[ "implementation" ]
null
null
Sergey is testing a next-generation processor. Instead of bytes the processor works with memory cells consisting of *n* bits. These bits are numbered from 1 to *n*. An integer is stored in the cell in the following way: the least significant bit is stored in the first bit of the cell, the next significant bit is stored in the second bit, and so on; the most significant bit is stored in the *n*-th bit. Now Sergey wants to test the following instruction: "add 1 to the value of the cell". As a result of the instruction, the integer that is written in the cell must be increased by one; if some of the most significant bits of the resulting number do not fit into the cell, they must be discarded. Sergey wrote certain values ​​of the bits in the cell and is going to add one to its value. How many bits of the cell will change after the operation?
The first line contains a single integer *n* (1<=≤<=*n*<=≤<=100) — the number of bits in the cell. The second line contains a string consisting of *n* characters — the initial state of the cell. The first character denotes the state of the first bit of the cell. The second character denotes the second least significant bit and so on. The last character denotes the state of the most significant bit.
Print a single integer — the number of bits in the cell which change their state after we add 1 to the cell.
[ "4\n1100\n", "4\n1111\n" ]
[ "3\n", "4\n" ]
In the first sample the cell ends up with value 0010, in the second sample — with 0000.
500
[ { "input": "4\n1100", "output": "3" }, { "input": "4\n1111", "output": "4" }, { "input": "1\n0", "output": "1" }, { "input": "1\n1", "output": "1" }, { "input": "2\n00", "output": "1" }, { "input": "2\n01", "output": "1" }, { "input": "2\n10", "output": "2" }, { "input": "2\n11", "output": "2" }, { "input": "10\n0000000000", "output": "1" }, { "input": "20\n11111111110110001100", "output": "11" }, { "input": "50\n01011110100010000001010000100001001101001101101011", "output": "1" }, { "input": "60\n111111111101111111111111111111111111111111111111111111111111", "output": "11" }, { "input": "60\n111111111111111111111111111111111111111111111111111111111111", "output": "60" }, { "input": "66\n111111010010011001110011000111000100011110011001111110011111111101", "output": "7" }, { "input": "90\n000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", "output": "1" }, { "input": "91\n1011111111111111111111111111111111111111111111111111111111111111111111111111111111111111111", "output": "2" }, { "input": "92\n11111111101011111011111111111111111111111011101111111111011111111111111101111111101011111101", "output": "10" }, { "input": "100\n0001011110100011001100100010111001000001111101101001001001001011110100101101010000000110100101110010", "output": "1" }, { "input": "100\n0111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111", "output": "1" }, { "input": "100\n0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", "output": "1" }, { "input": "100\n0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", "output": "1" }, { "input": "100\n1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111", "output": "100" }, { "input": "100\n1011001110001000011111110011000100001110010110111101110110011011011000010100110001111100000010110010", "output": "2" }, { "input": "100\n1101111011001111111111110011110111101110111111111111111111111111111111011111111111110111111111111111", "output": "3" }, { "input": "100\n1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111", "output": "100" }, { "input": "100\n1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111110", "output": "100" }, { "input": "100\n1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111101", "output": "99" }, { "input": "100\n1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111100000", "output": "96" }, { "input": "100\n1111111111111111111111111111111110011000110110001010101100100100001000010010010010000100110000010101", "output": "34" } ]
1,696,219,782
2,147,483,647
PyPy 3-64
OK
TESTS
29
78
0
n = int(input()) cells = input() if cells.find('0') == -1: print(n) else: before = int(cells[::-1], 2) after = before + 1 print(str(bin(before ^ after)).count('1'))
Title: inc ARG Time Limit: None seconds Memory Limit: None megabytes Problem Description: Sergey is testing a next-generation processor. Instead of bytes the processor works with memory cells consisting of *n* bits. These bits are numbered from 1 to *n*. An integer is stored in the cell in the following way: the least significant bit is stored in the first bit of the cell, the next significant bit is stored in the second bit, and so on; the most significant bit is stored in the *n*-th bit. Now Sergey wants to test the following instruction: "add 1 to the value of the cell". As a result of the instruction, the integer that is written in the cell must be increased by one; if some of the most significant bits of the resulting number do not fit into the cell, they must be discarded. Sergey wrote certain values ​​of the bits in the cell and is going to add one to its value. How many bits of the cell will change after the operation? Input Specification: The first line contains a single integer *n* (1<=≤<=*n*<=≤<=100) — the number of bits in the cell. The second line contains a string consisting of *n* characters — the initial state of the cell. The first character denotes the state of the first bit of the cell. The second character denotes the second least significant bit and so on. The last character denotes the state of the most significant bit. Output Specification: Print a single integer — the number of bits in the cell which change their state after we add 1 to the cell. Demo Input: ['4\n1100\n', '4\n1111\n'] Demo Output: ['3\n', '4\n'] Note: In the first sample the cell ends up with value 0010, in the second sample — with 0000.
```python n = int(input()) cells = input() if cells.find('0') == -1: print(n) else: before = int(cells[::-1], 2) after = before + 1 print(str(bin(before ^ after)).count('1')) ```
3
4
A
Watermelon
PROGRAMMING
800
[ "brute force", "math" ]
A. Watermelon
1
64
One hot summer day Pete and his friend Billy decided to buy a watermelon. They chose the biggest and the ripest one, in their opinion. After that the watermelon was weighed, and the scales showed *w* kilos. They rushed home, dying of thirst, and decided to divide the berry, however they faced a hard problem. Pete and Billy are great fans of even numbers, that's why they want to divide the watermelon in such a way that each of the two parts weighs even number of kilos, at the same time it is not obligatory that the parts are equal. The boys are extremely tired and want to start their meal as soon as possible, that's why you should help them and find out, if they can divide the watermelon in the way they want. For sure, each of them should get a part of positive weight.
The first (and the only) input line contains integer number *w* (1<=≤<=*w*<=≤<=100) — the weight of the watermelon bought by the boys.
Print YES, if the boys can divide the watermelon into two parts, each of them weighing even number of kilos; and NO in the opposite case.
[ "8\n" ]
[ "YES\n" ]
For example, the boys can divide the watermelon into two parts of 2 and 6 kilos respectively (another variant — two parts of 4 and 4 kilos).
0
[ { "input": "8", "output": "YES" }, { "input": "5", "output": "NO" }, { "input": "4", "output": "YES" }, { "input": "3", "output": "NO" }, { "input": "2", "output": "NO" }, { "input": "1", "output": "NO" }, { "input": "7", "output": "NO" }, { "input": "6", "output": "YES" }, { "input": "10", "output": "YES" }, { "input": "9", "output": "NO" }, { "input": "53", "output": "NO" }, { "input": "77", "output": "NO" }, { "input": "32", "output": "YES" }, { "input": "44", "output": "YES" }, { "input": "98", "output": "YES" }, { "input": "99", "output": "NO" }, { "input": "90", "output": "YES" }, { "input": "67", "output": "NO" }, { "input": "100", "output": "YES" }, { "input": "88", "output": "YES" } ]
1,693,388,366
2,147,483,647
Python 3
OK
TESTS
20
92
0
w = int(input()) if w%2 == 0 and 100>= w >= 3: print('YES') else: print('NO')
Title: Watermelon Time Limit: 1 seconds Memory Limit: 64 megabytes Problem Description: One hot summer day Pete and his friend Billy decided to buy a watermelon. They chose the biggest and the ripest one, in their opinion. After that the watermelon was weighed, and the scales showed *w* kilos. They rushed home, dying of thirst, and decided to divide the berry, however they faced a hard problem. Pete and Billy are great fans of even numbers, that's why they want to divide the watermelon in such a way that each of the two parts weighs even number of kilos, at the same time it is not obligatory that the parts are equal. The boys are extremely tired and want to start their meal as soon as possible, that's why you should help them and find out, if they can divide the watermelon in the way they want. For sure, each of them should get a part of positive weight. Input Specification: The first (and the only) input line contains integer number *w* (1<=≤<=*w*<=≤<=100) — the weight of the watermelon bought by the boys. Output Specification: Print YES, if the boys can divide the watermelon into two parts, each of them weighing even number of kilos; and NO in the opposite case. Demo Input: ['8\n'] Demo Output: ['YES\n'] Note: For example, the boys can divide the watermelon into two parts of 2 and 6 kilos respectively (another variant — two parts of 4 and 4 kilos).
```python w = int(input()) if w%2 == 0 and 100>= w >= 3: print('YES') else: print('NO') ```
3.954
61
A
Ultra-Fast Mathematician
PROGRAMMING
800
[ "implementation" ]
A. Ultra-Fast Mathematician
2
256
Shapur was an extremely gifted student. He was great at everything including Combinatorics, Algebra, Number Theory, Geometry, Calculus, etc. He was not only smart but extraordinarily fast! He could manage to sum 1018 numbers in a single second. One day in 230 AD Shapur was trying to find out if any one can possibly do calculations faster than him. As a result he made a very great contest and asked every one to come and take part. In his contest he gave the contestants many different pairs of numbers. Each number is made from digits 0 or 1. The contestants should write a new number corresponding to the given pair of numbers. The rule is simple: The *i*-th digit of the answer is 1 if and only if the *i*-th digit of the two given numbers differ. In the other case the *i*-th digit of the answer is 0. Shapur made many numbers and first tried his own speed. He saw that he can perform these operations on numbers of length ∞ (length of a number is number of digits in it) in a glance! He always gives correct answers so he expects the contestants to give correct answers, too. He is a good fellow so he won't give anyone very big numbers and he always gives one person numbers of same length. Now you are going to take part in Shapur's contest. See if you are faster and more accurate.
There are two lines in each input. Each of them contains a single number. It is guaranteed that the numbers are made from 0 and 1 only and that their length is same. The numbers may start with 0. The length of each number doesn't exceed 100.
Write one line — the corresponding answer. Do not omit the leading 0s.
[ "1010100\n0100101\n", "000\n111\n", "1110\n1010\n", "01110\n01100\n" ]
[ "1110001\n", "111\n", "0100\n", "00010\n" ]
none
500
[ { "input": "1010100\n0100101", "output": "1110001" }, { "input": "000\n111", "output": "111" }, { "input": "1110\n1010", "output": "0100" }, { "input": "01110\n01100", "output": "00010" }, { "input": "011101\n000001", "output": "011100" }, { "input": "10\n01", "output": "11" }, { "input": "00111111\n11011101", "output": "11100010" }, { "input": "011001100\n101001010", "output": "110000110" }, { "input": "1100100001\n0110101100", "output": "1010001101" }, { "input": "00011101010\n10010100101", "output": "10001001111" }, { "input": "100000101101\n111010100011", "output": "011010001110" }, { "input": "1000001111010\n1101100110001", "output": "0101101001011" }, { "input": "01011111010111\n10001110111010", "output": "11010001101101" }, { "input": "110010000111100\n001100101011010", "output": "111110101100110" }, { "input": "0010010111110000\n0000000011010110", "output": "0010010100100110" }, { "input": "00111110111110000\n01111100001100000", "output": "01000010110010000" }, { "input": "101010101111010001\n001001111101111101", "output": "100011010010101100" }, { "input": "0110010101111100000\n0011000101000000110", "output": "0101010000111100110" }, { "input": "11110100011101010111\n00001000011011000000", "output": "11111100000110010111" }, { "input": "101010101111101101001\n111010010010000011111", "output": "010000111101101110110" }, { "input": "0000111111100011000010\n1110110110110000001010", "output": "1110001001010011001000" }, { "input": "10010010101000110111000\n00101110100110111000111", "output": "10111100001110001111111" }, { "input": "010010010010111100000111\n100100111111100011001110", "output": "110110101101011111001001" }, { "input": "0101110100100111011010010\n0101100011010111001010001", "output": "0000010111110000010000011" }, { "input": "10010010100011110111111011\n10000110101100000001000100", "output": "00010100001111110110111111" }, { "input": "000001111000000100001000000\n011100111101111001110110001", "output": "011101000101111101111110001" }, { "input": "0011110010001001011001011100\n0000101101000011101011001010", "output": "0011011111001010110010010110" }, { "input": "11111000000000010011001101111\n11101110011001010100010000000", "output": "00010110011001000111011101111" }, { "input": "011001110000110100001100101100\n001010000011110000001000101001", "output": "010011110011000100000100000101" }, { "input": "1011111010001100011010110101111\n1011001110010000000101100010101", "output": "0000110100011100011111010111010" }, { "input": "10111000100001000001010110000001\n10111000001100101011011001011000", "output": "00000000101101101010001111011001" }, { "input": "000001010000100001000000011011100\n111111111001010100100001100000111", "output": "111110101001110101100001111011011" }, { "input": "1101000000000010011011101100000110\n1110000001100010011010000011011110", "output": "0011000001100000000001101111011000" }, { "input": "01011011000010100001100100011110001\n01011010111000001010010100001110000", "output": "00000001111010101011110000010000001" }, { "input": "000011111000011001000110111100000100\n011011000110000111101011100111000111", "output": "011000111110011110101101011011000011" }, { "input": "1001000010101110001000000011111110010\n0010001011010111000011101001010110000", "output": "1011001001111001001011101010101000010" }, { "input": "00011101011001100101111111000000010101\n10010011011011001011111000000011101011", "output": "10001110000010101110000111000011111110" }, { "input": "111011100110001001101111110010111001010\n111111101101111001110010000101101000100", "output": "000100001011110000011101110111010001110" }, { "input": "1111001001101000001000000010010101001010\n0010111100111110001011000010111110111001", "output": "1101110101010110000011000000101011110011" }, { "input": "00100101111000000101011111110010100011010\n11101110001010010101001000111110101010100", "output": "11001011110010010000010111001100001001110" }, { "input": "101011001110110100101001000111010101101111\n100111100110101011010100111100111111010110", "output": "001100101000011111111101111011101010111001" }, { "input": "1111100001100101000111101001001010011100001\n1000110011000011110010001011001110001000001", "output": "0111010010100110110101100010000100010100000" }, { "input": "01100111011111010101000001101110000001110101\n10011001011111110000000101011001001101101100", "output": "11111110000000100101000100110111001100011001" }, { "input": "110010100111000100100101100000011100000011001\n011001111011100110000110111001110110100111011", "output": "101011011100100010100011011001101010100100010" }, { "input": "0001100111111011010110100100111000000111000110\n1100101011000000000001010010010111001100110001", "output": "1101001100111011010111110110101111001011110111" }, { "input": "00000101110110110001110010100001110100000100000\n10010000110011110001101000111111101010011010001", "output": "10010101000101000000011010011110011110011110001" }, { "input": "110000100101011100100011001111110011111110010001\n101011111001011100110110111101110011010110101100", "output": "011011011100000000010101110010000000101000111101" }, { "input": "0101111101011111010101011101000011101100000000111\n0000101010110110001110101011011110111001010100100", "output": "0101010111101001011011110110011101010101010100011" }, { "input": "11000100010101110011101000011111001010110111111100\n00001111000111001011111110000010101110111001000011", "output": "11001011010010111000010110011101100100001110111111" }, { "input": "101000001101111101101111111000001110110010101101010\n010011100111100001100000010001100101000000111011011", "output": "111011101010011100001111101001101011110010010110001" }, { "input": "0011111110010001010100010110111000110011001101010100\n0111000000100010101010000100101000000100101000111001", "output": "0100111110110011111110010010010000110111100101101101" }, { "input": "11101010000110000011011010000001111101000111011111100\n10110011110001010100010110010010101001010111100100100", "output": "01011001110111010111001100010011010100010000111011000" }, { "input": "011000100001000001101000010110100110011110100111111011\n111011001000001001110011001111011110111110110011011111", "output": "100011101001001000011011011001111000100000010100100100" }, { "input": "0111010110010100000110111011010110100000000111110110000\n1011100100010001101100000100111111101001110010000100110", "output": "1100110010000101101010111111101001001001110101110010110" }, { "input": "10101000100111000111010001011011011011110100110101100011\n11101111000000001100100011111000100100000110011001101110", "output": "01000111100111001011110010100011111111110010101100001101" }, { "input": "000000111001010001000000110001001011100010011101010011011\n110001101000010010000101000100001111101001100100001010010", "output": "110001010001000011000101110101000100001011111001011001001" }, { "input": "0101011100111010000111110010101101111111000000111100011100\n1011111110000010101110111001000011100000100111111111000111", "output": "1110100010111000101001001011101110011111100111000011011011" }, { "input": "11001000001100100111100111100100101011000101001111001001101\n10111110100010000011010100110100100011101001100000001110110", "output": "01110110101110100100110011010000001000101100101111000111011" }, { "input": "010111011011101000000110000110100110001110100001110110111011\n101011110011101011101101011111010100100001100111100100111011", "output": "111100101000000011101011011001110010101111000110010010000000" }, { "input": "1001011110110110000100011001010110000100011010010111010101110\n1101111100001000010111110011010101111010010100000001000010111", "output": "0100100010111110010011101010000011111110001110010110010111001" }, { "input": "10000010101111100111110101111000010100110111101101111111111010\n10110110101100101010011001011010100110111011101100011001100111", "output": "00110100000011001101101100100010110010001100000001100110011101" }, { "input": "011111010011111000001010101001101001000010100010111110010100001\n011111001011000011111001000001111001010110001010111101000010011", "output": "000000011000111011110011101000010000010100101000000011010110010" }, { "input": "1111000000110001011101000100100100001111011100001111001100011111\n1101100110000101100001100000001001011011111011010101000101001010", "output": "0010100110110100111100100100101101010100100111011010001001010101" }, { "input": "01100000101010010011001110100110110010000110010011011001100100011\n10110110010110111100100111000111000110010000000101101110000010111", "output": "11010110111100101111101001100001110100010110010110110111100110100" }, { "input": "001111111010000100001100001010011001111110011110010111110001100111\n110000101001011000100010101100100110000111100000001101001110010111", "output": "111111010011011100101110100110111111111001111110011010111111110000" }, { "input": "1011101011101101011110101101011101011000010011100101010101000100110\n0001000001001111010111100100111101100000000001110001000110000000110", "output": "1010101010100010001001001001100000111000010010010100010011000100000" }, { "input": "01000001011001010011011100010000100100110101111011011011110000001110\n01011110000110011011000000000011000111100001010000000011111001110000", "output": "00011111011111001000011100010011100011010100101011011000001001111110" }, { "input": "110101010100110101000001111110110100010010000100111110010100110011100\n111010010111111011100110101011001011001110110111110100000110110100111", "output": "001111000011001110100111010101111111011100110011001010010010000111011" }, { "input": "1001101011000001011111100110010010000011010001001111011100010100110001\n1111100111110101001111010001010000011001001001010110001111000000100101", "output": "0110001100110100010000110111000010011010011000011001010011010100010100" }, { "input": "00000111110010110001110110001010010101000111011001111111100110011110010\n00010111110100000100110101000010010001100001100011100000001100010100010", "output": "00010000000110110101000011001000000100100110111010011111101010001010000" }, { "input": "100101011100101101000011010001011001101110101110001100010001010111001110\n100001111100101011011111110000001111000111001011111110000010101110111001", "output": "000100100000000110011100100001010110101001100101110010010011111001110111" }, { "input": "1101100001000111001101001011101000111000011110000001001101101001111011010\n0101011101010100011011010110101000010010110010011110101100000110110001000", "output": "1000111100010011010110011101000000101010101100011111100001101111001010010" }, { "input": "01101101010011110101100001110101111011100010000010001101111000011110111111\n00101111001101001100111010000101110000100101101111100111101110010100011011", "output": "01000010011110111001011011110000001011000111101101101010010110001010100100" }, { "input": "101100101100011001101111110110110010100110110010100001110010110011001101011\n000001011010101011110011111101001110000111000010001101000010010000010001101", "output": "101101110110110010011100001011111100100001110000101100110000100011011100110" }, { "input": "0010001011001010001100000010010011110110011000100000000100110000101111001110\n1100110100111000110100001110111001011101001100001010100001010011100110110001", "output": "1110111111110010111000001100101010101011010100101010100101100011001001111111" }, { "input": "00101101010000000101011001101011001100010001100000101011101110000001111001000\n10010110010111000000101101000011101011001010000011011101101011010000000011111", "output": "10111011000111000101110100101000100111011011100011110110000101010001111010111" }, { "input": "111100000100100000101001100001001111001010001000001000000111010000010101101011\n001000100010100101111011111011010110101100001111011000010011011011100010010110", "output": "110100100110000101010010011010011001100110000111010000010100001011110111111101" }, { "input": "0110001101100100001111110101101000100101010010101010011001101001001101110000000\n0111011000000010010111011110010000000001000110001000011001101000000001110100111", "output": "0001010101100110011000101011111000100100010100100010000000000001001100000100111" }, { "input": "10001111111001000101001011110101111010100001011010101100111001010001010010001000\n10000111010010011110111000111010101100000011110001101111001000111010100000000001", "output": "00001000101011011011110011001111010110100010101011000011110001101011110010001001" }, { "input": "100110001110110000100101001110000011110110000110000000100011110100110110011001101\n110001110101110000000100101001101011111100100100001001000110000001111100011110110", "output": "010111111011000000100001100111101000001010100010001001100101110101001010000111011" }, { "input": "0000010100100000010110111100011111111010011101000000100000011001001101101100111010\n0100111110011101010110101011110110010111001111000110101100101110111100101000111111", "output": "0100101010111101000000010111101001101101010010000110001100110111110001000100000101" }, { "input": "11000111001010100001110000001001011010010010110000001110100101000001010101100110111\n11001100100100100001101010110100000111100011101110011010110100001001000011011011010", "output": "00001011101110000000011010111101011101110001011110010100010001001000010110111101101" }, { "input": "010110100010001000100010101001101010011010111110100001000100101000111011100010100001\n110000011111101101010011111000101010111010100001001100001001100101000000111000000000", "output": "100110111101100101110001010001000000100000011111101101001101001101111011011010100001" }, { "input": "0000011110101110010101110110110101100001011001101010101001000010000010000000101001101\n1100111111011100000110000111101110011111100111110001011001000010011111100001001100011", "output": "1100100001110010010011110001011011111110111110011011110000000000011101100001100101110" }, { "input": "10100000101101110001100010010010100101100011010010101000110011100000101010110010000000\n10001110011011010010111011011101101111000111110000111000011010010101001100000001010011", "output": "00101110110110100011011001001111001010100100100010010000101001110101100110110011010011" }, { "input": "001110000011111101101010011111000101010111010100001001100001001100101000000111000000000\n111010000000000000101001110011001000111011001100101010011001000011101001001011110000011", "output": "110100000011111101000011101100001101101100011000100011111000001111000001001100110000011" }, { "input": "1110111100111011010101011011001110001010010010110011110010011111000010011111010101100001\n1001010101011001001010100010101100000110111101011000100010101111111010111100001110010010", "output": "0111101001100010011111111001100010001100101111101011010000110000111000100011011011110011" }, { "input": "11100010001100010011001100001100010011010001101110011110100101110010101101011101000111111\n01110000000110111010110100001010000101011110100101010011000110101110101101110111011110001", "output": "10010010001010101001111000000110010110001111001011001101100011011100000000101010011001110" }, { "input": "001101011001100101101100110000111000101011001001100100000100101000100000110100010111111101\n101001111110000010111101111110001001111001111101111010000110111000100100110010010001011111", "output": "100100100111100111010001001110110001010010110100011110000010010000000100000110000110100010" }, { "input": "1010110110010101000110010010110101011101010100011001101011000110000000100011100100011000000\n0011011111100010001111101101000111001011101110100000110111100100101111010110101111011100011", "output": "1001101001110111001001111111110010010110111010111001011100100010101111110101001011000100011" }, { "input": "10010010000111010111011111110010100101100000001100011100111011100010000010010001011100001100\n00111010100010110010000100010111010001111110100100100011101000101111111111001101101100100100", "output": "10101000100101100101011011100101110100011110101000111111010011001101111101011100110000101000" }, { "input": "010101110001010101100000010111010000000111110011001101100011001000000011001111110000000010100\n010010111011100101010101111110110000000111000100001101101001001000001100101110001010000100001", "output": "000111001010110000110101101001100000000000110111000000001010000000001111100001111010000110101" }, { "input": "1100111110011001000111101001001011000110011010111111100010111111001100111111011101100111101011\n1100000011001000110100110111000001011001010111101000010010100011000001100100111101101000010110", "output": "0000111101010001110011011110001010011111001101010111110000011100001101011011100000001111111101" }, { "input": "00011000100100110111100101100100000000010011110111110010101110110011100001010111010011110100101\n00011011111011111011100101100111100101001110010111000010000111000100100100000001110101111011011", "output": "00000011011111001100000000000011100101011101100000110000101001110111000101010110100110001111110" }, { "input": "000101011001001100000111100010110101111011110101111101000110001101011010111110110011100100000001\n011000101010011111011000111000100000000011011000000001111110001000001111101010110000011100001111", "output": "011101110011010011011111011010010101111000101101111100111000000101010101010100000011111000001110" }, { "input": "1000101001011010000100100100010010011101011001110101111011101111111110010101001101010001010101001\n0110110010011100011111011111110111000000010001110100001010111110101011010011111011111110000110000", "output": "1110011011000110011011111011100101011101001000000001110001010001010101000110110110101111010011001" }, { "input": "01111010010101100111110111111011011010100001011101010000111100101101101110111011001100101011100111\n00001100110110100001111011000010001001001100000010111101000001111011100000010111010010000011000010", "output": "01110110100011000110001100111001010011101101011111101101111101010110001110101100011110101000100101" }, { "input": "111101011101111000001011001101111010110111001101110100100011111011011101001101010101011010111000110\n101111100101101101001100110011000001111010011101110111110110101110011011110011111100001001110101101", "output": "010010111000010101000111111110111011001101010000000011010101010101000110111110101001010011001101011" }, { "input": "1010000011010110011101001101110001110010000111011101110010110110111111001001110100101100010101010001\n0111101000111100101100000101111010100100001000011101010100110011100011010011010101000100101011100011", "output": "1101101011101010110001001000001011010110001111000000100110000101011100011010100001101000111110110010" }, { "input": "0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001\n1111111010111111101011111110101111111010111111101011111110101111111010111111101011111110101111111010", "output": "1111111010111111101011111110101111111010111111101011111110101111111010111111101011111110101111111011" }, { "input": "0\n0", "output": "0" }, { "input": "0\n1", "output": "1" } ]
1,592,933,269
2,147,483,647
PyPy 3
OK
TESTS
102
140
20,172,800
#!/usr/bin/python3 # n, t = input().split(" ") # a = input() # n = int(n) # t = int(t) # s = list(a) # while(t != 0): # for i in range(n-1): # if s[i] == 'B' and s[i+1] == 'G': # s[i] = 'G' # s[i + 1] = 'B' # t -= 1 # break # print("".join(s)) # t = int(input()[2:]) # s = input() # while t: # s = s.replace('BG', 'GB') # t -= 1 # print(s) # print(s) # n = input # c = p = 0 # for i in' '*int(n()): # s = n() # c += s != p # p = s # print(c) # s = input() # d = {".": "0", "-.": "1", "--": "2"} # s = s.replace("--", "2") # s = s.replace("-.", "1") # s = s.replace(".", "0") # print(s) # y = int(input()) # while(len(set(str(y))) < 4): # y += 1 # print(y) # for i in range(2): # o = "" # r = input().replace(" ", "") # for j in r: # if int(j) % 2 == 0: # o += "1" # else: # o += "0" # print(o) # s = [[1]*5 for _ in range(5)] # for i in 1, 2, 3: # for j, v in zip((1, 2, 3), map(int, input().split())): # for k, d in (-1, 0), (1, 0), (0, -1), (0, 1), (0, 0): # s[i+k][j+d] += v # for i in 1, 2, 3: # for j in 1, 2, 3: # print(s[i][j] % 2, end='') # print() # s = input() # u = l = 0 # for i in s: # if i.lower() == i: # l += 1s # else: # u += 1 # if u == l or l > u: # s = s.lower() # elif u > l: # s = s.upper() # print(s) # n=int(input()) # a=[*map(int,input().split())] # print(a) # b=a.index(max(a))+a[::-1].index(min(a)) # print(b) # print(b-(b>=n)) i = input # print(''.join('01'[a != b]for a, b in zip(i(), i()))) s = "" for a, b in zip(i(), i()): s += '01'[a != b] print(s)
Title: Ultra-Fast Mathematician Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: Shapur was an extremely gifted student. He was great at everything including Combinatorics, Algebra, Number Theory, Geometry, Calculus, etc. He was not only smart but extraordinarily fast! He could manage to sum 1018 numbers in a single second. One day in 230 AD Shapur was trying to find out if any one can possibly do calculations faster than him. As a result he made a very great contest and asked every one to come and take part. In his contest he gave the contestants many different pairs of numbers. Each number is made from digits 0 or 1. The contestants should write a new number corresponding to the given pair of numbers. The rule is simple: The *i*-th digit of the answer is 1 if and only if the *i*-th digit of the two given numbers differ. In the other case the *i*-th digit of the answer is 0. Shapur made many numbers and first tried his own speed. He saw that he can perform these operations on numbers of length ∞ (length of a number is number of digits in it) in a glance! He always gives correct answers so he expects the contestants to give correct answers, too. He is a good fellow so he won't give anyone very big numbers and he always gives one person numbers of same length. Now you are going to take part in Shapur's contest. See if you are faster and more accurate. Input Specification: There are two lines in each input. Each of them contains a single number. It is guaranteed that the numbers are made from 0 and 1 only and that their length is same. The numbers may start with 0. The length of each number doesn't exceed 100. Output Specification: Write one line — the corresponding answer. Do not omit the leading 0s. Demo Input: ['1010100\n0100101\n', '000\n111\n', '1110\n1010\n', '01110\n01100\n'] Demo Output: ['1110001\n', '111\n', '0100\n', '00010\n'] Note: none
```python #!/usr/bin/python3 # n, t = input().split(" ") # a = input() # n = int(n) # t = int(t) # s = list(a) # while(t != 0): # for i in range(n-1): # if s[i] == 'B' and s[i+1] == 'G': # s[i] = 'G' # s[i + 1] = 'B' # t -= 1 # break # print("".join(s)) # t = int(input()[2:]) # s = input() # while t: # s = s.replace('BG', 'GB') # t -= 1 # print(s) # print(s) # n = input # c = p = 0 # for i in' '*int(n()): # s = n() # c += s != p # p = s # print(c) # s = input() # d = {".": "0", "-.": "1", "--": "2"} # s = s.replace("--", "2") # s = s.replace("-.", "1") # s = s.replace(".", "0") # print(s) # y = int(input()) # while(len(set(str(y))) < 4): # y += 1 # print(y) # for i in range(2): # o = "" # r = input().replace(" ", "") # for j in r: # if int(j) % 2 == 0: # o += "1" # else: # o += "0" # print(o) # s = [[1]*5 for _ in range(5)] # for i in 1, 2, 3: # for j, v in zip((1, 2, 3), map(int, input().split())): # for k, d in (-1, 0), (1, 0), (0, -1), (0, 1), (0, 0): # s[i+k][j+d] += v # for i in 1, 2, 3: # for j in 1, 2, 3: # print(s[i][j] % 2, end='') # print() # s = input() # u = l = 0 # for i in s: # if i.lower() == i: # l += 1s # else: # u += 1 # if u == l or l > u: # s = s.lower() # elif u > l: # s = s.upper() # print(s) # n=int(input()) # a=[*map(int,input().split())] # print(a) # b=a.index(max(a))+a[::-1].index(min(a)) # print(b) # print(b-(b>=n)) i = input # print(''.join('01'[a != b]for a, b in zip(i(), i()))) s = "" for a, b in zip(i(), i()): s += '01'[a != b] print(s) ```
3.927425
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,618,432,432
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
4
122
0
for _ in range(1): ls = list(map(int, input().split())) print(ls[0]-ls[1])
Title: The number of positions Time Limit: None seconds Memory Limit: None megabytes Problem Description: Petr stands in line of *n* people, but he doesn't know exactly which position he occupies. He can say that there are no less than *a* people standing in front of him and no more than *b* people standing behind him. Find the number of different positions Petr can occupy. Input Specification: The only line contains three integers *n*, *a* and *b* (0<=≤<=*a*,<=*b*<=&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 for _ in range(1): ls = list(map(int, input().split())) print(ls[0]-ls[1]) ```
0
281
A
Word Capitalization
PROGRAMMING
800
[ "implementation", "strings" ]
null
null
Capitalization is writing a word with its first letter as a capital letter. Your task is to capitalize the given word. Note, that during capitalization all the letters except the first one remains unchanged.
A single line contains a non-empty word. This word consists of lowercase and uppercase English letters. The length of the word will not exceed 103.
Output the given word after capitalization.
[ "ApPLe\n", "konjac\n" ]
[ "ApPLe\n", "Konjac\n" ]
none
500
[ { "input": "ApPLe", "output": "ApPLe" }, { "input": "konjac", "output": "Konjac" }, { "input": "a", "output": "A" }, { "input": "A", "output": "A" }, { "input": "z", "output": "Z" }, { "input": "ABACABA", "output": "ABACABA" }, { "input": "xYaPxPxHxGePfGtQySlNrLxSjDtNnTaRaEpAhPaQpWnDzMqGgRgEwJxGiBdZnMtHxFbObCaGiCeZkUqIgBhHtNvAqAlHpMnQhNeQbMyZrCdElVwHtKrPpJjIaHuIlYwHaRkAkUpPlOhNlBtXwDsKzPyHrPiUwNlXtTaPuMwTqYtJySgFoXvLiHbQwMjSvXsQfKhVlOxGdQkWjBhEyQvBjPoFkThNeRhTuIzFjInJtEfPjOlOsJpJuLgLzFnZmKvFgFrNsOnVqFcNiMfCqTpKnVyLwNqFiTySpWeTdFnWuTwDkRjVxNyQvTrOoEiExYiFaIrLoFmJfZcDkHuWjYfCeEqCvEsZiWnJaEmFbMjDvYwEeJeGcKbVbChGsIzNlExHzHiTlHcSaKxLuZxX", "output": "XYaPxPxHxGePfGtQySlNrLxSjDtNnTaRaEpAhPaQpWnDzMqGgRgEwJxGiBdZnMtHxFbObCaGiCeZkUqIgBhHtNvAqAlHpMnQhNeQbMyZrCdElVwHtKrPpJjIaHuIlYwHaRkAkUpPlOhNlBtXwDsKzPyHrPiUwNlXtTaPuMwTqYtJySgFoXvLiHbQwMjSvXsQfKhVlOxGdQkWjBhEyQvBjPoFkThNeRhTuIzFjInJtEfPjOlOsJpJuLgLzFnZmKvFgFrNsOnVqFcNiMfCqTpKnVyLwNqFiTySpWeTdFnWuTwDkRjVxNyQvTrOoEiExYiFaIrLoFmJfZcDkHuWjYfCeEqCvEsZiWnJaEmFbMjDvYwEeJeGcKbVbChGsIzNlExHzHiTlHcSaKxLuZxX" }, { "input": "rZhIcQlXpNcPgXrOjTiOlMoTgXgIhCfMwZfWoFzGhEkQlOoMjIuShPlZfWkNnMyQfYdUhVgQuSmYoElEtZpDyHtOxXgCpWbZqSbYnPqBcNqRtPgCnJnAyIvNsAhRbNeVlMwZyRyJnFgIsCnSbOdLvUyIeOzQvRpMoMoHfNhHwKvTcHuYnYySfPmAiNwAiWdZnWlLvGfBbRbRrCrBqIgIdWkWiBsNyYkKdNxZdGaToSsDnXpRaGrKxBpQsCzBdQgZzBkGeHgGxNrIyQlSzWsTmSnZwOcHqQpNcQvJlPvKaPiQaMaYsQjUeCqQdCjPgUbDmWiJmNiXgExLqOcCtSwSePnUxIuZfIfBeWbEiVbXnUsPwWyAiXyRbZgKwOqFfCtQuKxEmVeRlAkOeXkO", "output": "RZhIcQlXpNcPgXrOjTiOlMoTgXgIhCfMwZfWoFzGhEkQlOoMjIuShPlZfWkNnMyQfYdUhVgQuSmYoElEtZpDyHtOxXgCpWbZqSbYnPqBcNqRtPgCnJnAyIvNsAhRbNeVlMwZyRyJnFgIsCnSbOdLvUyIeOzQvRpMoMoHfNhHwKvTcHuYnYySfPmAiNwAiWdZnWlLvGfBbRbRrCrBqIgIdWkWiBsNyYkKdNxZdGaToSsDnXpRaGrKxBpQsCzBdQgZzBkGeHgGxNrIyQlSzWsTmSnZwOcHqQpNcQvJlPvKaPiQaMaYsQjUeCqQdCjPgUbDmWiJmNiXgExLqOcCtSwSePnUxIuZfIfBeWbEiVbXnUsPwWyAiXyRbZgKwOqFfCtQuKxEmVeRlAkOeXkO" }, { "input": "hDgZlUmLhYbLkLcNcKeOwJwTePbOvLaRvNzQbSbLsPeHqLhUqWtUbNdQfQqFfXeJqJwWuOrFnDdZiPxIkDyVmHbHvXfIlFqSgAcSyWbOlSlRuPhWdEpEzEeLnXwCtWuVcHaUeRgCiYsIvOaIgDnFuDbRnMoCmPrZfLeFpSjQaTfHgZwZvAzDuSeNwSoWuJvLqKqAuUxFaCxFfRcEjEsJpOfCtDiVrBqNsNwPuGoRgPzRpLpYnNyQxKaNnDnYiJrCrVcHlOxPiPcDbEgKfLwBjLhKcNeMgJhJmOiJvPfOaPaEuGqWvRbErKrIpDkEoQnKwJnTlStLyNsHyOjZfKoIjXwUvRrWpSyYhRpQdLqGmErAiNcGqAqIrTeTiMuPmCrEkHdBrLyCxPtYpRqD", "output": "HDgZlUmLhYbLkLcNcKeOwJwTePbOvLaRvNzQbSbLsPeHqLhUqWtUbNdQfQqFfXeJqJwWuOrFnDdZiPxIkDyVmHbHvXfIlFqSgAcSyWbOlSlRuPhWdEpEzEeLnXwCtWuVcHaUeRgCiYsIvOaIgDnFuDbRnMoCmPrZfLeFpSjQaTfHgZwZvAzDuSeNwSoWuJvLqKqAuUxFaCxFfRcEjEsJpOfCtDiVrBqNsNwPuGoRgPzRpLpYnNyQxKaNnDnYiJrCrVcHlOxPiPcDbEgKfLwBjLhKcNeMgJhJmOiJvPfOaPaEuGqWvRbErKrIpDkEoQnKwJnTlStLyNsHyOjZfKoIjXwUvRrWpSyYhRpQdLqGmErAiNcGqAqIrTeTiMuPmCrEkHdBrLyCxPtYpRqD" }, { "input": "qUdLgGrJeGmIzIeZrCjUtBpYfRvNdXdRpGsThIsEmJjTiMqEwRxBeBaSxEuWrNvExKePjPnXhPzBpWnHiDhTvZhBuIjDnZpTcEkCvRkAcTmMuXhGgErWgFyGyToOyVwYlCuQpTfJkVdWmFyBqQhJjYtXrBbFdHzDlGsFbHmHbFgXgFhIyDhZyEqEiEwNxSeByBwLiVeSnCxIdHbGjOjJrZeVkOzGeMmQrJkVyGhDtCzOlPeAzGrBlWwEnAdUfVaIjNrRyJjCnHkUvFuKuKeKbLzSbEmUcXtVkZzXzKlOrPgQiDmCcCvIyAdBwOeUuLbRmScNcWxIkOkJuIsBxTrIqXhDzLcYdVtPgZdZfAxTmUtByGiTsJkSySjXdJvEwNmSmNoWsChPdAzJrBoW", "output": "QUdLgGrJeGmIzIeZrCjUtBpYfRvNdXdRpGsThIsEmJjTiMqEwRxBeBaSxEuWrNvExKePjPnXhPzBpWnHiDhTvZhBuIjDnZpTcEkCvRkAcTmMuXhGgErWgFyGyToOyVwYlCuQpTfJkVdWmFyBqQhJjYtXrBbFdHzDlGsFbHmHbFgXgFhIyDhZyEqEiEwNxSeByBwLiVeSnCxIdHbGjOjJrZeVkOzGeMmQrJkVyGhDtCzOlPeAzGrBlWwEnAdUfVaIjNrRyJjCnHkUvFuKuKeKbLzSbEmUcXtVkZzXzKlOrPgQiDmCcCvIyAdBwOeUuLbRmScNcWxIkOkJuIsBxTrIqXhDzLcYdVtPgZdZfAxTmUtByGiTsJkSySjXdJvEwNmSmNoWsChPdAzJrBoW" }, { "input": "kHbApGoBcLmIwUlXkVgUmWzYeLoDbGaOkWbIuXoRwMfKuOoMzAoXrBoTvYxGrMbRjDuRxAbGsTnErIiHnHoLeRnTbFiRfDdOkNlWiAcOsChLdLqFqXlDpDoDtPxXqAmSvYgPvOcCpOlWtOjYwFkGkHuCaHwZcFdOfHjBmIxTeSiHkWjXyFcCtOlSuJsZkDxUgPeZkJwMmNpErUlBcGuMlJwKkWnOzFeFiSiPsEvMmQiCsYeHlLuHoMgBjFoZkXlObDkSoQcVyReTmRsFzRhTuIvCeBqVsQdQyTyZjStGrTyDcEcAgTgMiIcVkLbZbGvWeHtXwEqWkXfTcPyHhHjYwIeVxLyVmHmMkUsGiHmNnQuMsXaFyPpVqNrBhOiWmNkBbQuHvQdOjPjKiZcL", "output": "KHbApGoBcLmIwUlXkVgUmWzYeLoDbGaOkWbIuXoRwMfKuOoMzAoXrBoTvYxGrMbRjDuRxAbGsTnErIiHnHoLeRnTbFiRfDdOkNlWiAcOsChLdLqFqXlDpDoDtPxXqAmSvYgPvOcCpOlWtOjYwFkGkHuCaHwZcFdOfHjBmIxTeSiHkWjXyFcCtOlSuJsZkDxUgPeZkJwMmNpErUlBcGuMlJwKkWnOzFeFiSiPsEvMmQiCsYeHlLuHoMgBjFoZkXlObDkSoQcVyReTmRsFzRhTuIvCeBqVsQdQyTyZjStGrTyDcEcAgTgMiIcVkLbZbGvWeHtXwEqWkXfTcPyHhHjYwIeVxLyVmHmMkUsGiHmNnQuMsXaFyPpVqNrBhOiWmNkBbQuHvQdOjPjKiZcL" }, { "input": "aHmRbLgNuWkLxLnWvUbYwTeZeYiOlLhTuOvKfLnVmCiPcMkSgVrYjZiLuRjCiXhAnVzVcTlVeJdBvPdDfFvHkTuIhCdBjEsXbVmGcLrPfNvRdFsZkSdNpYsJeIhIcNqSoLkOjUlYlDmXsOxPbQtIoUxFjGnRtBhFaJvBeEzHsAtVoQbAfYjJqReBiKeUwRqYrUjPjBoHkOkPzDwEwUgTxQxAvKzUpMhKyOhPmEhYhItQwPeKsKaKlUhGuMcTtSwFtXfJsDsFlTtOjVvVfGtBtFlQyIcBaMsPaJlPqUcUvLmReZiFbXxVtRhTzJkLkAjVqTyVuFeKlTyQgUzMsXjOxQnVfTaWmThEnEoIhZeZdStBkKeLpAhJnFoJvQyGwDiStLjEwGfZwBuWsEfC", "output": "AHmRbLgNuWkLxLnWvUbYwTeZeYiOlLhTuOvKfLnVmCiPcMkSgVrYjZiLuRjCiXhAnVzVcTlVeJdBvPdDfFvHkTuIhCdBjEsXbVmGcLrPfNvRdFsZkSdNpYsJeIhIcNqSoLkOjUlYlDmXsOxPbQtIoUxFjGnRtBhFaJvBeEzHsAtVoQbAfYjJqReBiKeUwRqYrUjPjBoHkOkPzDwEwUgTxQxAvKzUpMhKyOhPmEhYhItQwPeKsKaKlUhGuMcTtSwFtXfJsDsFlTtOjVvVfGtBtFlQyIcBaMsPaJlPqUcUvLmReZiFbXxVtRhTzJkLkAjVqTyVuFeKlTyQgUzMsXjOxQnVfTaWmThEnEoIhZeZdStBkKeLpAhJnFoJvQyGwDiStLjEwGfZwBuWsEfC" }, { "input": "sLlZkDiDmEdNaXuUuJwHqYvRtOdGfTiTpEpAoSqAbJaChOiCvHgSwZwEuPkMmXiLcKdXqSsEyViEbZpZsHeZpTuXoGcRmOiQfBfApPjDqSqElWeSeOhUyWjLyNoRuYeGfGwNqUsQoTyVvWeNgNdZfDxGwGfLsDjIdInSqDlMuNvFaHbScZkTlVwNcJpEjMaPaOtFgJjBjOcLlLmDnQrShIrJhOcUmPnZhTxNeClQsZaEaVaReLyQpLwEqJpUwYhLiRzCzKfOoFeTiXzPiNbOsZaZaLgCiNnMkBcFwGgAwPeNyTxJcCtBgXcToKlWaWcBaIvBpNxPeClQlWeQqRyEtAkJdBtSrFdDvAbUlKyLdCuTtXxFvRcKnYnWzVdYqDeCmOqPxUaFjQdTdCtN", "output": "SLlZkDiDmEdNaXuUuJwHqYvRtOdGfTiTpEpAoSqAbJaChOiCvHgSwZwEuPkMmXiLcKdXqSsEyViEbZpZsHeZpTuXoGcRmOiQfBfApPjDqSqElWeSeOhUyWjLyNoRuYeGfGwNqUsQoTyVvWeNgNdZfDxGwGfLsDjIdInSqDlMuNvFaHbScZkTlVwNcJpEjMaPaOtFgJjBjOcLlLmDnQrShIrJhOcUmPnZhTxNeClQsZaEaVaReLyQpLwEqJpUwYhLiRzCzKfOoFeTiXzPiNbOsZaZaLgCiNnMkBcFwGgAwPeNyTxJcCtBgXcToKlWaWcBaIvBpNxPeClQlWeQqRyEtAkJdBtSrFdDvAbUlKyLdCuTtXxFvRcKnYnWzVdYqDeCmOqPxUaFjQdTdCtN" }, { "input": "iRuStKvVhJdJbQwRoIuLiVdTpKaOqKfYlYwAzIpPtUwUtMeKyCaOlXmVrKwWeImYmVuXdLkRlHwFxKqZbZtTzNgOzDbGqTfZnKmUzAcIjDcEmQgYyFbEfWzRpKvCkDmAqDiIiRcLvMxWaJqCgYqXgIcLdNaZlBnXtJyKaMnEaWfXfXwTbDnAiYnWqKbAtDpYdUbZrCzWgRnHzYxFgCdDbOkAgTqBuLqMeStHcDxGnVhSgMzVeTaZoTfLjMxQfRuPcFqVlRyYdHyOdJsDoCeWrUuJyIiAqHwHyVpEeEoMaJwAoUfPtBeJqGhMaHiBjKwAlXoZpUsDhHgMxBkVbLcEvNtJbGnPsUwAvXrAkTlXwYvEnOpNeWyIkRnEnTrIyAcLkRgMyYcKrGiDaAyE", "output": "IRuStKvVhJdJbQwRoIuLiVdTpKaOqKfYlYwAzIpPtUwUtMeKyCaOlXmVrKwWeImYmVuXdLkRlHwFxKqZbZtTzNgOzDbGqTfZnKmUzAcIjDcEmQgYyFbEfWzRpKvCkDmAqDiIiRcLvMxWaJqCgYqXgIcLdNaZlBnXtJyKaMnEaWfXfXwTbDnAiYnWqKbAtDpYdUbZrCzWgRnHzYxFgCdDbOkAgTqBuLqMeStHcDxGnVhSgMzVeTaZoTfLjMxQfRuPcFqVlRyYdHyOdJsDoCeWrUuJyIiAqHwHyVpEeEoMaJwAoUfPtBeJqGhMaHiBjKwAlXoZpUsDhHgMxBkVbLcEvNtJbGnPsUwAvXrAkTlXwYvEnOpNeWyIkRnEnTrIyAcLkRgMyYcKrGiDaAyE" }, { "input": "cRtJkOxHzUbJcDdHzJtLbVmSoWuHoTkVrPqQaVmXeBrHxJbQfNrQbAaMrEhVdQnPxNyCjErKxPoEdWkVrBbDeNmEgBxYiBtWdAfHiLuSwIxJuHpSkAxPoYdNkGoLySsNhUmGoZhDzAfWhJdPlJzQkZbOnMtTkClIoCqOlIcJcMlGjUyOiEmHdYfIcPtTgQhLlLcPqQjAnQnUzHpCaQsCnYgQsBcJrQwBnWsIwFfSfGuYgTzQmShFpKqEeRlRkVfMuZbUsDoFoPrNuNwTtJqFkRiXxPvKyElDzLoUnIwAaBaOiNxMpEvPzSpGpFhMtGhGdJrFnZmNiMcUfMtBnDuUnXqDcMsNyGoLwLeNnLfRsIwRfBtXkHrFcPsLdXaAoYaDzYnZuQeVcZrElWmP", "output": "CRtJkOxHzUbJcDdHzJtLbVmSoWuHoTkVrPqQaVmXeBrHxJbQfNrQbAaMrEhVdQnPxNyCjErKxPoEdWkVrBbDeNmEgBxYiBtWdAfHiLuSwIxJuHpSkAxPoYdNkGoLySsNhUmGoZhDzAfWhJdPlJzQkZbOnMtTkClIoCqOlIcJcMlGjUyOiEmHdYfIcPtTgQhLlLcPqQjAnQnUzHpCaQsCnYgQsBcJrQwBnWsIwFfSfGuYgTzQmShFpKqEeRlRkVfMuZbUsDoFoPrNuNwTtJqFkRiXxPvKyElDzLoUnIwAaBaOiNxMpEvPzSpGpFhMtGhGdJrFnZmNiMcUfMtBnDuUnXqDcMsNyGoLwLeNnLfRsIwRfBtXkHrFcPsLdXaAoYaDzYnZuQeVcZrElWmP" }, { "input": "wVaCsGxZrBbFnTbKsCoYlAvUkIpBaYpYmJkMlPwCaFvUkDxAiJgIqWsFqZlFvTtAnGzEwXbYiBdFfFxRiDoUkLmRfAwOlKeOlKgXdUnVqLkTuXtNdQpBpXtLvZxWoBeNePyHcWmZyRiUkPlRqYiQdGeXwOhHbCqVjDcEvJmBkRwWnMqPjXpUsIyXqGjHsEsDwZiFpIbTkQaUlUeFxMwJzSaHdHnDhLaLdTuYgFuJsEcMmDvXyPjKsSeBaRwNtPuOuBtNeOhQdVgKzPzOdYtPjPfDzQzHoWcYjFbSvRgGdGsCmGnQsErToBkCwGeQaCbBpYkLhHxTbUvRnJpZtXjKrHdRiUmUbSlJyGaLnWsCrJbBnSjFaZrIzIrThCmGhQcMsTtOxCuUcRaEyPaG", "output": "WVaCsGxZrBbFnTbKsCoYlAvUkIpBaYpYmJkMlPwCaFvUkDxAiJgIqWsFqZlFvTtAnGzEwXbYiBdFfFxRiDoUkLmRfAwOlKeOlKgXdUnVqLkTuXtNdQpBpXtLvZxWoBeNePyHcWmZyRiUkPlRqYiQdGeXwOhHbCqVjDcEvJmBkRwWnMqPjXpUsIyXqGjHsEsDwZiFpIbTkQaUlUeFxMwJzSaHdHnDhLaLdTuYgFuJsEcMmDvXyPjKsSeBaRwNtPuOuBtNeOhQdVgKzPzOdYtPjPfDzQzHoWcYjFbSvRgGdGsCmGnQsErToBkCwGeQaCbBpYkLhHxTbUvRnJpZtXjKrHdRiUmUbSlJyGaLnWsCrJbBnSjFaZrIzIrThCmGhQcMsTtOxCuUcRaEyPaG" }, { "input": "kEiLxLmPjGzNoGkJdBlAfXhThYhMsHmZoZbGyCvNiUoLoZdAxUbGyQiEfXvPzZzJrPbEcMpHsMjIkRrVvDvQtHuKmXvGpQtXbPzJpFjJdUgWcPdFxLjLtXgVpEiFhImHnKkGiWnZbJqRjCyEwHsNbYfYfTyBaEuKlCtWnOqHmIgGrFmQiYrBnLiFcGuZxXlMfEuVoCxPkVrQvZoIpEhKsYtXrPxLcSfQqXsWaDgVlOnAzUvAhOhMrJfGtWcOwQfRjPmGhDyAeXrNqBvEiDfCiIvWxPjTwPlXpVsMjVjUnCkXgBuWnZaDyJpWkCfBrWnHxMhJgItHdRqNrQaEeRjAuUwRkUdRhEeGlSqVqGmOjNcUhFfXjCmWzBrGvIuZpRyWkWiLyUwFpYjNmNfV", "output": "KEiLxLmPjGzNoGkJdBlAfXhThYhMsHmZoZbGyCvNiUoLoZdAxUbGyQiEfXvPzZzJrPbEcMpHsMjIkRrVvDvQtHuKmXvGpQtXbPzJpFjJdUgWcPdFxLjLtXgVpEiFhImHnKkGiWnZbJqRjCyEwHsNbYfYfTyBaEuKlCtWnOqHmIgGrFmQiYrBnLiFcGuZxXlMfEuVoCxPkVrQvZoIpEhKsYtXrPxLcSfQqXsWaDgVlOnAzUvAhOhMrJfGtWcOwQfRjPmGhDyAeXrNqBvEiDfCiIvWxPjTwPlXpVsMjVjUnCkXgBuWnZaDyJpWkCfBrWnHxMhJgItHdRqNrQaEeRjAuUwRkUdRhEeGlSqVqGmOjNcUhFfXjCmWzBrGvIuZpRyWkWiLyUwFpYjNmNfV" }, { "input": "eIhDoLmDeReKqXsHcVgFxUqNfScAiQnFrTlCgSuTtXiYvBxKaPaGvUeYfSgHqEaWcHxKpFaSlCxGqAmNeFcIzFcZsBiVoZhUjXaDaIcKoBzYdIlEnKfScRqSkYpPtVsVhXsBwUsUfAqRoCkBxWbHgDiCkRtPvUwVgDjOzObYwNiQwXlGnAqEkHdSqLgUkOdZiWaHqQnOhUnDhIzCiQtVcJlGoRfLuVlFjWqSuMsLgLwOdZvKtWdRuRqDoBoInKqPbJdXpIqLtFlMlDaWgSiKbFpCxOnQeNeQzXeKsBzIjCyPxCmBnYuHzQoYxZgGzSgGtZiTeQmUeWlNzZeKiJbQmEjIiDhPeSyZlNdHpZnIkPdJzSeJpPiXxToKyBjJfPwNzZpWzIzGySqPxLtI", "output": "EIhDoLmDeReKqXsHcVgFxUqNfScAiQnFrTlCgSuTtXiYvBxKaPaGvUeYfSgHqEaWcHxKpFaSlCxGqAmNeFcIzFcZsBiVoZhUjXaDaIcKoBzYdIlEnKfScRqSkYpPtVsVhXsBwUsUfAqRoCkBxWbHgDiCkRtPvUwVgDjOzObYwNiQwXlGnAqEkHdSqLgUkOdZiWaHqQnOhUnDhIzCiQtVcJlGoRfLuVlFjWqSuMsLgLwOdZvKtWdRuRqDoBoInKqPbJdXpIqLtFlMlDaWgSiKbFpCxOnQeNeQzXeKsBzIjCyPxCmBnYuHzQoYxZgGzSgGtZiTeQmUeWlNzZeKiJbQmEjIiDhPeSyZlNdHpZnIkPdJzSeJpPiXxToKyBjJfPwNzZpWzIzGySqPxLtI" }, { "input": "uOoQzIeTwYeKpJtGoUdNiXbPgEwVsZkAnJcArHxIpEnEhZwQhZvAiOuLeMkVqLeDsAyKeYgFxGmRoLaRsZjAeXgNfYhBkHeDrHdPuTuYhKmDlAvYzYxCdYgYfVaYlGeVqTeSfBxQePbQrKsTaIkGzMjFrQlJuYaMxWpQkLdEcDsIiMnHnDtThRvAcKyGwBsHqKdXpJfIeTeZtYjFbMeUoXoXzGrShTwSwBpQlKeDrZdCjRqNtXoTsIzBkWbMsObTtDvYaPhUeLeHqHeMpZmTaCcIqXzAmGnPfNdDaFhOqWqDrWuFiBpRjZrQmAdViOuMbFfRyXyWfHgRkGpPnDrEqQcEmHcKpEvWlBrOtJbUaXbThJaSxCbVoGvTmHvZrHvXpCvLaYbRiHzYuQyX", "output": "UOoQzIeTwYeKpJtGoUdNiXbPgEwVsZkAnJcArHxIpEnEhZwQhZvAiOuLeMkVqLeDsAyKeYgFxGmRoLaRsZjAeXgNfYhBkHeDrHdPuTuYhKmDlAvYzYxCdYgYfVaYlGeVqTeSfBxQePbQrKsTaIkGzMjFrQlJuYaMxWpQkLdEcDsIiMnHnDtThRvAcKyGwBsHqKdXpJfIeTeZtYjFbMeUoXoXzGrShTwSwBpQlKeDrZdCjRqNtXoTsIzBkWbMsObTtDvYaPhUeLeHqHeMpZmTaCcIqXzAmGnPfNdDaFhOqWqDrWuFiBpRjZrQmAdViOuMbFfRyXyWfHgRkGpPnDrEqQcEmHcKpEvWlBrOtJbUaXbThJaSxCbVoGvTmHvZrHvXpCvLaYbRiHzYuQyX" }, { "input": "lZqBqKeGvNdSeYuWxRiVnFtYbKuJwQtUcKnVtQhAlOeUzMaAuTaEnDdPfDcNyHgEoBmYjZyFePeJrRiKyAzFnBfAuGiUyLrIeLrNhBeBdVcEeKgCcBrQzDsPwGcNnZvTsEaYmFfMeOmMdNuZbUtDoQoNcGwDqEkEjIdQaPwAxJbXeNxOgKgXoEbZiIsVkRrNpNyAkLeHkNfEpLuQvEcMbIoGaDzXbEtNsLgGfOkZaFiUsOvEjVeCaMcZqMzKeAdXxJsVeCrZaFpJtZxInQxFaSmGgSsVyGeLlFgFqTpIbAvPkIfJrVcJeBxSdEvPyVwIjHpYrLrKqLnAmCuGmPoZrSbOtGaLaTmBmSuUyAmAsRiMqOtRjJhPhAfXaJnTpLbFqPmJgFcBxImTqIiJ", "output": "LZqBqKeGvNdSeYuWxRiVnFtYbKuJwQtUcKnVtQhAlOeUzMaAuTaEnDdPfDcNyHgEoBmYjZyFePeJrRiKyAzFnBfAuGiUyLrIeLrNhBeBdVcEeKgCcBrQzDsPwGcNnZvTsEaYmFfMeOmMdNuZbUtDoQoNcGwDqEkEjIdQaPwAxJbXeNxOgKgXoEbZiIsVkRrNpNyAkLeHkNfEpLuQvEcMbIoGaDzXbEtNsLgGfOkZaFiUsOvEjVeCaMcZqMzKeAdXxJsVeCrZaFpJtZxInQxFaSmGgSsVyGeLlFgFqTpIbAvPkIfJrVcJeBxSdEvPyVwIjHpYrLrKqLnAmCuGmPoZrSbOtGaLaTmBmSuUyAmAsRiMqOtRjJhPhAfXaJnTpLbFqPmJgFcBxImTqIiJ" }, { "input": "P", "output": "P" }, { "input": "Xyzzy", "output": "Xyzzy" }, { "input": "Zzz", "output": "Zzz" }, { "input": "Zp", "output": "Zp" } ]
1,697,703,650
2,147,483,647
PyPy 3
OK
TESTS
25
184
0
s = input() ans = s[0].capitalize() + s[1::] print(ans)
Title: Word Capitalization Time Limit: None seconds Memory Limit: None megabytes Problem Description: Capitalization is writing a word with its first letter as a capital letter. Your task is to capitalize the given word. Note, that during capitalization all the letters except the first one remains unchanged. Input Specification: A single line contains a non-empty word. This word consists of lowercase and uppercase English letters. The length of the word will not exceed 103. Output Specification: Output the given word after capitalization. Demo Input: ['ApPLe\n', 'konjac\n'] Demo Output: ['ApPLe\n', 'Konjac\n'] Note: none
```python s = input() ans = s[0].capitalize() + s[1::] print(ans) ```
3
466
C
Number of Ways
PROGRAMMING
1,700
[ "binary search", "brute force", "data structures", "dp", "two pointers" ]
null
null
You've got array *a*[1],<=*a*[2],<=...,<=*a*[*n*], consisting of *n* integers. Count the number of ways to split all the elements of the array into three contiguous parts so that the sum of elements in each part is the same. More formally, you need to find the number of such pairs of indices *i*,<=*j* (2<=≤<=*i*<=≤<=*j*<=≤<=*n*<=-<=1), that .
The first line contains integer *n* (1<=≤<=*n*<=≤<=5·105), showing how many numbers are in the array. The second line contains *n* integers *a*[1], *a*[2], ..., *a*[*n*] (|*a*[*i*]|<=≤<=<=109) — the elements of array *a*.
Print a single integer — the number of ways to split the array into three parts with the same sum.
[ "5\n1 2 3 0 3\n", "4\n0 1 -1 0\n", "2\n4 1\n" ]
[ "2\n", "1\n", "0\n" ]
none
1,500
[ { "input": "5\n1 2 3 0 3", "output": "2" }, { "input": "4\n0 1 -1 0", "output": "1" }, { "input": "2\n4 1", "output": "0" }, { "input": "9\n0 0 0 0 0 0 0 0 0", "output": "28" }, { "input": "10\n2 5 -2 2 -3 -2 3 5 -5 -2", "output": "0" }, { "input": "1\n1", "output": "0" }, { "input": "3\n1 2 3", "output": "0" }, { "input": "100\n1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1", "output": "2030" }, { "input": "6\n1000000000 1000000000 1000000000 1000000000 1000000000 1000000000", "output": "1" }, { "input": "10\n1 0 0 0 1 1 1 0 1 1", "output": "2" }, { "input": "10\n-2 2 -2 0 -2 -1 1 -1 2 0", "output": "0" }, { "input": "4\n0 2 -1 2", "output": "0" }, { "input": "5\n3 3 -3 3 3", "output": "3" }, { "input": "5\n1 1 1 1 1", "output": "0" }, { "input": "8\n-1 -1 -1 -1 -1 -1 -1 -1", "output": "0" }, { "input": "2\n0 0", "output": "0" }, { "input": "4\n1 -1 0 0", "output": "1" }, { "input": "3\n6 -3 6", "output": "0" } ]
1,699,512,011
2,147,483,647
Python 3
RUNTIME_ERROR
TESTS
0
30
0
n = int(input()) for i in range(n): dish_num = int(input()) delivery_time = list(map(int, input().split())) arrival_time = list(map(int, input().split())) combine_time = sorted(zip(delivery_time, arrival_time), key=lambda x: x[0]) a = sum(arrival_time) min_time = float('inf') for j in combine_time: a -= j[1] if j[0] >= a: min_time = min(min_time, j[0]) print(min(min_time, a))
Title: Number of Ways Time Limit: None seconds Memory Limit: None megabytes Problem Description: You've got array *a*[1],<=*a*[2],<=...,<=*a*[*n*], consisting of *n* integers. Count the number of ways to split all the elements of the array into three contiguous parts so that the sum of elements in each part is the same. More formally, you need to find the number of such pairs of indices *i*,<=*j* (2<=≤<=*i*<=≤<=*j*<=≤<=*n*<=-<=1), that . Input Specification: The first line contains integer *n* (1<=≤<=*n*<=≤<=5·105), showing how many numbers are in the array. The second line contains *n* integers *a*[1], *a*[2], ..., *a*[*n*] (|*a*[*i*]|<=≤<=<=109) — the elements of array *a*. Output Specification: Print a single integer — the number of ways to split the array into three parts with the same sum. Demo Input: ['5\n1 2 3 0 3\n', '4\n0 1 -1 0\n', '2\n4 1\n'] Demo Output: ['2\n', '1\n', '0\n'] Note: none
```python n = int(input()) for i in range(n): dish_num = int(input()) delivery_time = list(map(int, input().split())) arrival_time = list(map(int, input().split())) combine_time = sorted(zip(delivery_time, arrival_time), key=lambda x: x[0]) a = sum(arrival_time) min_time = float('inf') for j in combine_time: a -= j[1] if j[0] >= a: min_time = min(min_time, j[0]) print(min(min_time, a)) ```
-1
777
D
Cloud of Hashtags
PROGRAMMING
1,800
[ "binary search", "greedy", "implementation", "strings" ]
null
null
Vasya is an administrator of a public page of organization "Mouse and keyboard" and his everyday duty is to publish news from the world of competitive programming. For each news he also creates a list of hashtags to make searching for a particular topic more comfortable. For the purpose of this problem we define hashtag as a string consisting of lowercase English letters and exactly one symbol '#' located at the beginning of the string. The length of the hashtag is defined as the number of symbols in it without the symbol '#'. The head administrator of the page told Vasya that hashtags should go in lexicographical order (take a look at the notes section for the definition). Vasya is lazy so he doesn't want to actually change the order of hashtags in already published news. Instead, he decided to delete some suffixes (consecutive characters at the end of the string) of some of the hashtags. He is allowed to delete any number of characters, even the whole string except for the symbol '#'. Vasya wants to pick such a way to delete suffixes that the total number of deleted symbols is minimum possible. If there are several optimal solutions, he is fine with any of them.
The first line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=500<=000) — the number of hashtags being edited now. Each of the next *n* lines contains exactly one hashtag of positive length. It is guaranteed that the total length of all hashtags (i.e. the total length of the string except for characters '#') won't exceed 500<=000.
Print the resulting hashtags in any of the optimal solutions.
[ "3\n#book\n#bigtown\n#big\n", "3\n#book\n#cool\n#cold\n", "4\n#car\n#cart\n#art\n#at\n", "3\n#apple\n#apple\n#fruit\n" ]
[ "#b\n#big\n#big\n", "#book\n#co\n#cold\n", "#\n#\n#art\n#at\n", "#apple\n#apple\n#fruit\n" ]
Word *a*<sub class="lower-index">1</sub>, *a*<sub class="lower-index">2</sub>, ..., *a*<sub class="lower-index">*m*</sub> of length *m* is lexicographically not greater than word *b*<sub class="lower-index">1</sub>, *b*<sub class="lower-index">2</sub>, ..., *b*<sub class="lower-index">*k*</sub> of length *k*, if one of two conditions hold: - at first position *i*, such that *a*<sub class="lower-index">*i*</sub> ≠ *b*<sub class="lower-index">*i*</sub>, the character *a*<sub class="lower-index">*i*</sub> goes earlier in the alphabet than character *b*<sub class="lower-index">*i*</sub>, i.e. *a* has smaller character than *b* in the first position where they differ; - if there is no such position *i* and *m* ≤ *k*, i.e. the first word is a prefix of the second or two words are equal. The sequence of words is said to be sorted in lexicographical order if each word (except the last one) is lexicographically not greater than the next word. For the words consisting of lowercase English letters the lexicographical order coincides with the alphabet word order in the dictionary. According to the above definition, if a hashtag consisting of one character '#' it is lexicographically not greater than any other valid hashtag. That's why in the third sample we can't keep first two hashtags unchanged and shorten the other two.
2,000
[ { "input": "3\n#book\n#bigtown\n#big", "output": "#b\n#big\n#big" }, { "input": "3\n#book\n#cool\n#cold", "output": "#book\n#co\n#cold" }, { "input": "4\n#car\n#cart\n#art\n#at", "output": "#\n#\n#art\n#at" }, { "input": "3\n#apple\n#apple\n#fruit", "output": "#apple\n#apple\n#fruit" }, { "input": "1\n#h", "output": "#h" }, { "input": "2\n#y\n#q", "output": "#\n#q" }, { "input": "3\n#sima\n#simb\n#sima", "output": "#sim\n#sim\n#sima" }, { "input": "1\n#lxqnqdnkpeayhxh", "output": "#lxqnqdnkpeayhxh" }, { "input": "6\n#abu\n#abc\n#ac\n#bk\n#bmm\n#bb", "output": "#ab\n#abc\n#ac\n#b\n#b\n#bb" }, { "input": "7\n#a\n#aab\n#abc\n#abq\n#ab\n#ac\n#z", "output": "#a\n#aab\n#ab\n#ab\n#ab\n#ac\n#z" }, { "input": "15\n#a\n#a\n#b\n#c\n#e\n#i\n#k\n#m\n#o\n#r\n#u\n#v\n#w\n#w\n#e", "output": "#\n#\n#\n#\n#\n#\n#\n#\n#\n#\n#\n#\n#\n#\n#e" }, { "input": "5\n#abcde\n#abcd\n#abc\n#ab\n#a", "output": "#a\n#a\n#a\n#a\n#a" }, { "input": "5\n#xyz\n#yzx\n#zzxy\n#zzy\n#yz", "output": "#\n#\n#\n#\n#yz" }, { "input": "15\n#a\n#b\n#c\n#c\n#f\n#h\n#i\n#j\n#l\n#l\n#q\n#q\n#u\n#z\n#z", "output": "#a\n#b\n#c\n#c\n#f\n#h\n#i\n#j\n#l\n#l\n#q\n#q\n#u\n#z\n#z" }, { "input": "6\n#jgpajxhyrlbnpcfkklkfjflexcbhza\n#jgpajxhyrlbnpcfkklkfjflexcbhz\n#jgpajxhyrlbnpcfkklkfjflexcb\n#jgpajxhyrlbnpcfkklkfjflex\n#jgpajxhyrlbnpcfkklkfjf\n#jgpajxhyrlbnpcfkk", "output": "#jgpajxhyrlbnpcfkk\n#jgpajxhyrlbnpcfkk\n#jgpajxhyrlbnpcfkk\n#jgpajxhyrlbnpcfkk\n#jgpajxhyrlbnpcfkk\n#jgpajxhyrlbnpcfkk" }, { "input": "37\n#dut\n#du\n#du\n#dxzd\n#dxz\n#dxz\n#dyyr\n#dyy\n#dyy\n#dzuo\n#dzu\n#dzu\n#wldl\n#wld\n#wl\n#wl\n#xeuu\n#xeu\n#xe\n#xe\n#ytki\n#ytk\n#yt\n#yt\n#yvbn\n#yvb\n#yvb\n#zvip\n#zvi\n#zv\n#zv\n#zzag\n#zza\n#zza\n#zznz\n#zznz\n#zzo", "output": "#du\n#du\n#du\n#dxz\n#dxz\n#dxz\n#dyy\n#dyy\n#dyy\n#dzu\n#dzu\n#dzu\n#wl\n#wl\n#wl\n#wl\n#xe\n#xe\n#xe\n#xe\n#yt\n#yt\n#yt\n#yt\n#yvb\n#yvb\n#yvb\n#zv\n#zv\n#zv\n#zv\n#zza\n#zza\n#zza\n#zznz\n#zznz\n#zzo" }, { "input": "2\n#aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaab\n#aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", "output": "#aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\n#aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" } ]
1,657,190,402
2,147,483,647
PyPy 3-64
TIME_LIMIT_EXCEEDED
TESTS
8
2,000
41,369,600
n = int(input()) ls = [input() for _ in range(n)] for x in range(n - 2, -1, -1): m = min(len(ls[x]), len(ls[x + 1])) for j in range(m): if ls[x][j] > ls[x + 1][j]: ls[x] = ls[x][:j] break elif ls[x][j] < ls[x + 1][j]: break else: ls[x] = ls[x][: m] for x in ls: print(x)
Title: Cloud of Hashtags Time Limit: None seconds Memory Limit: None megabytes Problem Description: Vasya is an administrator of a public page of organization "Mouse and keyboard" and his everyday duty is to publish news from the world of competitive programming. For each news he also creates a list of hashtags to make searching for a particular topic more comfortable. For the purpose of this problem we define hashtag as a string consisting of lowercase English letters and exactly one symbol '#' located at the beginning of the string. The length of the hashtag is defined as the number of symbols in it without the symbol '#'. The head administrator of the page told Vasya that hashtags should go in lexicographical order (take a look at the notes section for the definition). Vasya is lazy so he doesn't want to actually change the order of hashtags in already published news. Instead, he decided to delete some suffixes (consecutive characters at the end of the string) of some of the hashtags. He is allowed to delete any number of characters, even the whole string except for the symbol '#'. Vasya wants to pick such a way to delete suffixes that the total number of deleted symbols is minimum possible. If there are several optimal solutions, he is fine with any of them. Input Specification: The first line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=500<=000) — the number of hashtags being edited now. Each of the next *n* lines contains exactly one hashtag of positive length. It is guaranteed that the total length of all hashtags (i.e. the total length of the string except for characters '#') won't exceed 500<=000. Output Specification: Print the resulting hashtags in any of the optimal solutions. Demo Input: ['3\n#book\n#bigtown\n#big\n', '3\n#book\n#cool\n#cold\n', '4\n#car\n#cart\n#art\n#at\n', '3\n#apple\n#apple\n#fruit\n'] Demo Output: ['#b\n#big\n#big\n', '#book\n#co\n#cold\n', '#\n#\n#art\n#at\n', '#apple\n#apple\n#fruit\n'] Note: Word *a*<sub class="lower-index">1</sub>, *a*<sub class="lower-index">2</sub>, ..., *a*<sub class="lower-index">*m*</sub> of length *m* is lexicographically not greater than word *b*<sub class="lower-index">1</sub>, *b*<sub class="lower-index">2</sub>, ..., *b*<sub class="lower-index">*k*</sub> of length *k*, if one of two conditions hold: - at first position *i*, such that *a*<sub class="lower-index">*i*</sub> ≠ *b*<sub class="lower-index">*i*</sub>, the character *a*<sub class="lower-index">*i*</sub> goes earlier in the alphabet than character *b*<sub class="lower-index">*i*</sub>, i.e. *a* has smaller character than *b* in the first position where they differ; - if there is no such position *i* and *m* ≤ *k*, i.e. the first word is a prefix of the second or two words are equal. The sequence of words is said to be sorted in lexicographical order if each word (except the last one) is lexicographically not greater than the next word. For the words consisting of lowercase English letters the lexicographical order coincides with the alphabet word order in the dictionary. According to the above definition, if a hashtag consisting of one character '#' it is lexicographically not greater than any other valid hashtag. That's why in the third sample we can't keep first two hashtags unchanged and shorten the other two.
```python n = int(input()) ls = [input() for _ in range(n)] for x in range(n - 2, -1, -1): m = min(len(ls[x]), len(ls[x + 1])) for j in range(m): if ls[x][j] > ls[x + 1][j]: ls[x] = ls[x][:j] break elif ls[x][j] < ls[x + 1][j]: break else: ls[x] = ls[x][: m] for x in ls: print(x) ```
0
658
A
Bear and Reverse Radewoosh
PROGRAMMING
800
[ "implementation" ]
null
null
Limak and Radewoosh are going to compete against each other in the upcoming algorithmic contest. They are equally skilled but they won't solve problems in the same order. There will be *n* problems. The *i*-th problem has initial score *p**i* and it takes exactly *t**i* minutes to solve it. Problems are sorted by difficulty — it's guaranteed that *p**i*<=&lt;<=*p**i*<=+<=1 and *t**i*<=&lt;<=*t**i*<=+<=1. A constant *c* is given too, representing the speed of loosing points. Then, submitting the *i*-th problem at time *x* (*x* minutes after the start of the contest) gives *max*(0,<= *p**i*<=-<=*c*·*x*) points. Limak is going to solve problems in order 1,<=2,<=...,<=*n* (sorted increasingly by *p**i*). Radewoosh is going to solve them in order *n*,<=*n*<=-<=1,<=...,<=1 (sorted decreasingly by *p**i*). Your task is to predict the outcome — print the name of the winner (person who gets more points at the end) or a word "Tie" in case of a tie. You may assume that the duration of the competition is greater or equal than the sum of all *t**i*. That means both Limak and Radewoosh will accept all *n* problems.
The first line contains two integers *n* and *c* (1<=≤<=*n*<=≤<=50,<=1<=≤<=*c*<=≤<=1000) — the number of problems and the constant representing the speed of loosing points. The second line contains *n* integers *p*1,<=*p*2,<=...,<=*p**n* (1<=≤<=*p**i*<=≤<=1000,<=*p**i*<=&lt;<=*p**i*<=+<=1) — initial scores. The third line contains *n* integers *t*1,<=*t*2,<=...,<=*t**n* (1<=≤<=*t**i*<=≤<=1000,<=*t**i*<=&lt;<=*t**i*<=+<=1) where *t**i* denotes the number of minutes one needs to solve the *i*-th problem.
Print "Limak" (without quotes) if Limak will get more points in total. Print "Radewoosh" (without quotes) if Radewoosh will get more points in total. Print "Tie" (without quotes) if Limak and Radewoosh will get the same total number of points.
[ "3 2\n50 85 250\n10 15 25\n", "3 6\n50 85 250\n10 15 25\n", "8 1\n10 20 30 40 50 60 70 80\n8 10 58 63 71 72 75 76\n" ]
[ "Limak\n", "Radewoosh\n", "Tie\n" ]
In the first sample, there are 3 problems. Limak solves them as follows: 1. Limak spends 10 minutes on the 1-st problem and he gets 50 - *c*·10 = 50 - 2·10 = 30 points. 1. Limak spends 15 minutes on the 2-nd problem so he submits it 10 + 15 = 25 minutes after the start of the contest. For the 2-nd problem he gets 85 - 2·25 = 35 points. 1. He spends 25 minutes on the 3-rd problem so he submits it 10 + 15 + 25 = 50 minutes after the start. For this problem he gets 250 - 2·50 = 150 points. So, Limak got 30 + 35 + 150 = 215 points. Radewoosh solves problem in the reversed order: 1. Radewoosh solves 3-rd problem after 25 minutes so he gets 250 - 2·25 = 200 points. 1. He spends 15 minutes on the 2-nd problem so he submits it 25 + 15 = 40 minutes after the start. He gets 85 - 2·40 = 5 points for this problem. 1. He spends 10 minutes on the 1-st problem so he submits it 25 + 15 + 10 = 50 minutes after the start. He gets *max*(0, 50 - 2·50) = *max*(0,  - 50) = 0 points. Radewoosh got 200 + 5 + 0 = 205 points in total. Limak has 215 points so Limak wins. In the second sample, Limak will get 0 points for each problem and Radewoosh will first solve the hardest problem and he will get 250 - 6·25 = 100 points for that. Radewoosh will get 0 points for other two problems but he is the winner anyway. In the third sample, Limak will get 2 points for the 1-st problem and 2 points for the 2-nd problem. Radewoosh will get 4 points for the 8-th problem. They won't get points for other problems and thus there is a tie because 2 + 2 = 4.
500
[ { "input": "3 2\n50 85 250\n10 15 25", "output": "Limak" }, { "input": "3 6\n50 85 250\n10 15 25", "output": "Radewoosh" }, { "input": "8 1\n10 20 30 40 50 60 70 80\n8 10 58 63 71 72 75 76", "output": "Tie" }, { "input": "4 1\n3 5 6 9\n1 2 4 8", "output": "Limak" }, { "input": "4 1\n1 3 6 10\n1 5 7 8", "output": "Radewoosh" }, { "input": "4 1\n2 4 5 10\n2 3 9 10", "output": "Tie" }, { "input": "18 4\n68 97 121 132 146 277 312 395 407 431 458 461 595 634 751 855 871 994\n1 2 3 4 9 10 13 21 22 29 31 34 37 38 39 41 48 49", "output": "Radewoosh" }, { "input": "50 1\n5 14 18 73 137 187 195 197 212 226 235 251 262 278 287 304 310 322 342 379 393 420 442 444 448 472 483 485 508 515 517 523 559 585 618 627 636 646 666 682 703 707 780 853 937 951 959 989 991 992\n30 84 113 173 199 220 235 261 266 277 300 306 310 312 347 356 394 396 397 409 414 424 446 462 468 487 507 517 537 566 594 643 656 660 662 668 706 708 773 774 779 805 820 827 868 896 929 942 961 995", "output": "Tie" }, { "input": "4 1\n4 6 9 10\n2 3 4 5", "output": "Radewoosh" }, { "input": "4 1\n4 6 9 10\n3 4 5 7", "output": "Radewoosh" }, { "input": "4 1\n1 6 7 10\n2 7 8 10", "output": "Tie" }, { "input": "4 1\n4 5 7 9\n1 4 5 8", "output": "Limak" }, { "input": "50 1\n6 17 44 82 94 127 134 156 187 211 212 252 256 292 294 303 352 355 379 380 398 409 424 434 480 524 584 594 631 714 745 756 777 778 789 793 799 821 841 849 859 878 879 895 925 932 944 952 958 990\n15 16 40 42 45 71 99 100 117 120 174 181 186 204 221 268 289 332 376 394 403 409 411 444 471 487 499 539 541 551 567 589 619 623 639 669 689 722 735 776 794 822 830 840 847 907 917 927 936 988", "output": "Radewoosh" }, { "input": "50 10\n25 49 52 73 104 117 127 136 149 164 171 184 226 251 257 258 286 324 337 341 386 390 428 453 464 470 492 517 543 565 609 634 636 660 678 693 710 714 729 736 739 749 781 836 866 875 956 960 977 979\n2 4 7 10 11 22 24 26 27 28 31 35 37 38 42 44 45 46 52 53 55 56 57 59 60 61 64 66 67 68 69 71 75 76 77 78 79 81 83 85 86 87 89 90 92 93 94 98 99 100", "output": "Limak" }, { "input": "50 10\n11 15 25 71 77 83 95 108 143 150 182 183 198 203 213 223 279 280 346 348 350 355 375 376 412 413 415 432 470 545 553 562 589 595 607 633 635 637 688 719 747 767 771 799 842 883 905 924 942 944\n1 3 5 6 7 10 11 12 13 14 15 16 19 20 21 23 25 32 35 36 37 38 40 41 42 43 47 50 51 54 55 56 57 58 59 60 62 63 64 65 66 68 69 70 71 72 73 75 78 80", "output": "Radewoosh" }, { "input": "32 6\n25 77 141 148 157 159 192 196 198 244 245 255 332 392 414 457 466 524 575 603 629 700 738 782 838 841 845 847 870 945 984 985\n1 2 4 5 8 9 10 12 13 14 15 16 17 18 20 21 22 23 24 26 28 31 38 39 40 41 42 43 45 47 48 49", "output": "Radewoosh" }, { "input": "5 1\n256 275 469 671 842\n7 9 14 17 26", "output": "Limak" }, { "input": "2 1000\n1 2\n1 2", "output": "Tie" }, { "input": "3 1\n1 50 809\n2 8 800", "output": "Limak" }, { "input": "1 13\n866\n10", "output": "Tie" }, { "input": "15 1\n9 11 66 128 199 323 376 386 393 555 585 718 935 960 971\n3 11 14 19 20 21 24 26 32 38 40 42 44 47 50", "output": "Limak" }, { "input": "1 10\n546\n45", "output": "Tie" }, { "input": "50 20\n21 43 51 99 117 119 158 167 175 190 196 244 250 316 335 375 391 403 423 428 451 457 460 480 487 522 539 559 566 584 598 602 604 616 626 666 675 730 771 787 828 841 861 867 886 889 898 970 986 991\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", "output": "Limak" }, { "input": "50 21\n13 20 22 38 62 84 118 135 141 152 170 175 194 218 227 229 232 253 260 263 278 313 329 357 396 402 422 452 454 533 575 576 580 594 624 644 653 671 676 759 789 811 816 823 831 833 856 924 933 987\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", "output": "Tie" }, { "input": "1 36\n312\n42", "output": "Tie" }, { "input": "1 1000\n1\n1000", "output": "Tie" }, { "input": "1 1\n1000\n1", "output": "Tie" }, { "input": "50 35\n9 17 28 107 136 152 169 174 186 188 201 262 291 312 324 330 341 358 385 386 393 397 425 431 479 498 502 523 530 540 542 554 578 588 622 623 684 696 709 722 784 819 836 845 850 932 945 969 983 984\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", "output": "Tie" }, { "input": "50 20\n12 113 116 120 138 156 167 183 185 194 211 228 234 261 278 287 310 317 346 361 364 397 424 470 496 522 527 536 611 648 668 704 707 712 717 752 761 766 815 828 832 864 872 885 889 901 904 929 982 993\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", "output": "Limak" } ]
1,543,491,783
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
0
108
0
n, c = map(int, input().split()) p = [int(i) for i in input().split()] t = [int(i) for i in input().split()] t1 = [] t_l = 0 for i in t: t_l += i t1.append(t_l) t2 = [] t_r = 0 for i in reversed(t): t_r += i t2.append(t_r) p1 = p p2 = list(reversed(p)) limak = 0 revad = 0 j = 0 k = 0 for i in range(1,sum(t)+1): if i in t1: if p1[j]-i*c>=0: limak += p1[j]-i*c j += 1 if i in t2: if p2[k]-i*c>=0: revad += p2[k]-i*c k += 1 print(limak, revad)
Title: Bear and Reverse Radewoosh Time Limit: None seconds Memory Limit: None megabytes Problem Description: Limak and Radewoosh are going to compete against each other in the upcoming algorithmic contest. They are equally skilled but they won't solve problems in the same order. There will be *n* problems. The *i*-th problem has initial score *p**i* and it takes exactly *t**i* minutes to solve it. Problems are sorted by difficulty — it's guaranteed that *p**i*<=&lt;<=*p**i*<=+<=1 and *t**i*<=&lt;<=*t**i*<=+<=1. A constant *c* is given too, representing the speed of loosing points. Then, submitting the *i*-th problem at time *x* (*x* minutes after the start of the contest) gives *max*(0,<= *p**i*<=-<=*c*·*x*) points. Limak is going to solve problems in order 1,<=2,<=...,<=*n* (sorted increasingly by *p**i*). Radewoosh is going to solve them in order *n*,<=*n*<=-<=1,<=...,<=1 (sorted decreasingly by *p**i*). Your task is to predict the outcome — print the name of the winner (person who gets more points at the end) or a word "Tie" in case of a tie. You may assume that the duration of the competition is greater or equal than the sum of all *t**i*. That means both Limak and Radewoosh will accept all *n* problems. Input Specification: The first line contains two integers *n* and *c* (1<=≤<=*n*<=≤<=50,<=1<=≤<=*c*<=≤<=1000) — the number of problems and the constant representing the speed of loosing points. The second line contains *n* integers *p*1,<=*p*2,<=...,<=*p**n* (1<=≤<=*p**i*<=≤<=1000,<=*p**i*<=&lt;<=*p**i*<=+<=1) — initial scores. The third line contains *n* integers *t*1,<=*t*2,<=...,<=*t**n* (1<=≤<=*t**i*<=≤<=1000,<=*t**i*<=&lt;<=*t**i*<=+<=1) where *t**i* denotes the number of minutes one needs to solve the *i*-th problem. Output Specification: Print "Limak" (without quotes) if Limak will get more points in total. Print "Radewoosh" (without quotes) if Radewoosh will get more points in total. Print "Tie" (without quotes) if Limak and Radewoosh will get the same total number of points. Demo Input: ['3 2\n50 85 250\n10 15 25\n', '3 6\n50 85 250\n10 15 25\n', '8 1\n10 20 30 40 50 60 70 80\n8 10 58 63 71 72 75 76\n'] Demo Output: ['Limak\n', 'Radewoosh\n', 'Tie\n'] Note: In the first sample, there are 3 problems. Limak solves them as follows: 1. Limak spends 10 minutes on the 1-st problem and he gets 50 - *c*·10 = 50 - 2·10 = 30 points. 1. Limak spends 15 minutes on the 2-nd problem so he submits it 10 + 15 = 25 minutes after the start of the contest. For the 2-nd problem he gets 85 - 2·25 = 35 points. 1. He spends 25 minutes on the 3-rd problem so he submits it 10 + 15 + 25 = 50 minutes after the start. For this problem he gets 250 - 2·50 = 150 points. So, Limak got 30 + 35 + 150 = 215 points. Radewoosh solves problem in the reversed order: 1. Radewoosh solves 3-rd problem after 25 minutes so he gets 250 - 2·25 = 200 points. 1. He spends 15 minutes on the 2-nd problem so he submits it 25 + 15 = 40 minutes after the start. He gets 85 - 2·40 = 5 points for this problem. 1. He spends 10 minutes on the 1-st problem so he submits it 25 + 15 + 10 = 50 minutes after the start. He gets *max*(0, 50 - 2·50) = *max*(0,  - 50) = 0 points. Radewoosh got 200 + 5 + 0 = 205 points in total. Limak has 215 points so Limak wins. In the second sample, Limak will get 0 points for each problem and Radewoosh will first solve the hardest problem and he will get 250 - 6·25 = 100 points for that. Radewoosh will get 0 points for other two problems but he is the winner anyway. In the third sample, Limak will get 2 points for the 1-st problem and 2 points for the 2-nd problem. Radewoosh will get 4 points for the 8-th problem. They won't get points for other problems and thus there is a tie because 2 + 2 = 4.
```python n, c = map(int, input().split()) p = [int(i) for i in input().split()] t = [int(i) for i in input().split()] t1 = [] t_l = 0 for i in t: t_l += i t1.append(t_l) t2 = [] t_r = 0 for i in reversed(t): t_r += i t2.append(t_r) p1 = p p2 = list(reversed(p)) limak = 0 revad = 0 j = 0 k = 0 for i in range(1,sum(t)+1): if i in t1: if p1[j]-i*c>=0: limak += p1[j]-i*c j += 1 if i in t2: if p2[k]-i*c>=0: revad += p2[k]-i*c k += 1 print(limak, revad) ```
0
312
B
Archer
PROGRAMMING
1,300
[ "math", "probabilities" ]
null
null
SmallR is an archer. SmallR is taking a match of archer with Zanoes. They try to shoot in the target in turns, and SmallR shoots first. The probability of shooting the target each time is for SmallR while for Zanoes. The one who shoots in the target first should be the winner. Output the probability that SmallR will win the match.
A single line contains four integers .
Print a single real number, the probability that SmallR will win the match. The answer will be considered correct if the absolute or relative error doesn't exceed 10<=-<=6.
[ "1 2 1 2\n" ]
[ "0.666666666667" ]
none
1,000
[ { "input": "1 2 1 2", "output": "0.666666666667" }, { "input": "1 3 1 3", "output": "0.600000000000" }, { "input": "1 3 2 3", "output": "0.428571428571" }, { "input": "3 4 3 4", "output": "0.800000000000" }, { "input": "1 2 10 11", "output": "0.523809523810" }, { "input": "4 5 4 5", "output": "0.833333333333" }, { "input": "466 701 95 721", "output": "0.937693791148" }, { "input": "268 470 444 885", "output": "0.725614009325" }, { "input": "632 916 713 821", "output": "0.719292895126" }, { "input": "269 656 918 992", "output": "0.428937461623" }, { "input": "71 657 187 695", "output": "0.310488463257" }, { "input": "435 852 973 978", "output": "0.511844133157" }, { "input": "518 816 243 359", "output": "0.719734031025" }, { "input": "882 962 311 811", "output": "0.966386645447" }, { "input": "684 774 580 736", "output": "0.906051574446" }, { "input": "486 868 929 999", "output": "0.577723252958" }, { "input": "132 359 996 998", "output": "0.368154532345" }, { "input": "933 977 266 450", "output": "0.972879407907" }, { "input": "298 833 615 872", "output": "0.441270817024" }, { "input": "34 554 14 958", "output": "0.817324099167" }, { "input": "836 934 800 905", "output": "0.906105535462" }, { "input": "482 815 69 509", "output": "0.914365577772" }, { "input": "284 423 137 521", "output": "0.885974839378" }, { "input": "648 881 486 703", "output": "0.800911421248" }, { "input": "450 885 755 836", "output": "0.533901011176" }, { "input": "533 773 823 998", "output": "0.729222130525" }, { "input": "897 957 92 898", "output": "0.993193806364" }, { "input": "699 925 441 928", "output": "0.866816866175" }, { "input": "64 704 148 603", "output": "0.289486317811" }, { "input": "719 735 626 990", "output": "0.986124079764" }, { "input": "1 1000 1 1000", "output": "0.500250125063" } ]
1,577,418,860
2,147,483,647
Python 3
RUNTIME_ERROR
TESTS
0
93
0
x=map(int,input().split()) print(round(((x[0]/x[1])/(1-(c/d)**2)),2))
Title: Archer Time Limit: None seconds Memory Limit: None megabytes Problem Description: SmallR is an archer. SmallR is taking a match of archer with Zanoes. They try to shoot in the target in turns, and SmallR shoots first. The probability of shooting the target each time is for SmallR while for Zanoes. The one who shoots in the target first should be the winner. Output the probability that SmallR will win the match. Input Specification: A single line contains four integers . Output Specification: Print a single real number, the probability that SmallR will win the match. The answer will be considered correct if the absolute or relative error doesn't exceed 10<=-<=6. Demo Input: ['1 2 1 2\n'] Demo Output: ['0.666666666667'] Note: none
```python x=map(int,input().split()) print(round(((x[0]/x[1])/(1-(c/d)**2)),2)) ```
-1
979
C
Kuro and Walking Route
PROGRAMMING
1,600
[ "dfs and similar", "trees" ]
null
null
Kuro is living in a country called Uberland, consisting of $n$ towns, numbered from $1$ to $n$, and $n - 1$ bidirectional roads connecting these towns. It is possible to reach each town from any other. Each road connects two towns $a$ and $b$. Kuro loves walking and he is planning to take a walking marathon, in which he will choose a pair of towns $(u, v)$ ($u \neq v$) and walk from $u$ using the shortest path to $v$ (note that $(u, v)$ is considered to be different from $(v, u)$). Oddly, there are 2 special towns in Uberland named Flowrisa (denoted with the index $x$) and Beetopia (denoted with the index $y$). Flowrisa is a town where there are many strong-scent flowers, and Beetopia is another town where many bees live. In particular, Kuro will avoid any pair of towns $(u, v)$ if on the path from $u$ to $v$, he reaches Beetopia after he reached Flowrisa, since the bees will be attracted with the flower smell on Kuro’s body and sting him. Kuro wants to know how many pair of city $(u, v)$ he can take as his route. Since he’s not really bright, he asked you to help him with this problem.
The first line contains three integers $n$, $x$ and $y$ ($1 \leq n \leq 3 \cdot 10^5$, $1 \leq x, y \leq n$, $x \ne y$) - the number of towns, index of the town Flowrisa and index of the town Beetopia, respectively. $n - 1$ lines follow, each line contains two integers $a$ and $b$ ($1 \leq a, b \leq n$, $a \ne b$), describes a road connecting two towns $a$ and $b$. It is guaranteed that from each town, we can reach every other town in the city using the given roads. That is, the given map of towns and roads is a tree.
A single integer resembles the number of pair of towns $(u, v)$ that Kuro can use as his walking route.
[ "3 1 3\n1 2\n2 3\n", "3 1 3\n1 2\n1 3\n" ]
[ "5", "4" ]
On the first example, Kuro can choose these pairs: - $(1, 2)$: his route would be $1 \rightarrow 2$, - $(2, 3)$: his route would be $2 \rightarrow 3$, - $(3, 2)$: his route would be $3 \rightarrow 2$, - $(2, 1)$: his route would be $2 \rightarrow 1$, - $(3, 1)$: his route would be $3 \rightarrow 2 \rightarrow 1$. Kuro can't choose pair $(1, 3)$ since his walking route would be $1 \rightarrow 2 \rightarrow 3$, in which Kuro visits town $1$ (Flowrisa) and then visits town $3$ (Beetopia), which is not allowed (note that pair $(3, 1)$ is still allowed because although Kuro visited Flowrisa and Beetopia, he did not visit them in that order). On the second example, Kuro can choose the following pairs: - $(1, 2)$: his route would be $1 \rightarrow 2$, - $(2, 1)$: his route would be $2 \rightarrow 1$, - $(3, 2)$: his route would be $3 \rightarrow 1 \rightarrow 2$, - $(3, 1)$: his route would be $3 \rightarrow 1$.
1,250
[ { "input": "3 1 3\n1 2\n2 3", "output": "5" }, { "input": "3 1 3\n1 2\n1 3", "output": "4" }, { "input": "61 26 12\n33 38\n32 8\n27 59\n1 21\n61 57\n61 22\n35 18\n61 14\n39 56\n50 10\n1 42\n21 43\n61 41\n31 30\n35 9\n23 28\n39 34\n39 4\n39 25\n27 60\n45 51\n1 11\n35 26\n29 15\n23 44\n31 2\n35 27\n39 20\n1 24\n1 53\n35 58\n39 37\n61 13\n61 16\n1 12\n32 17\n1 40\n33 47\n29 52\n1 39\n35 19\n39 50\n27 6\n26 3\n26 55\n35 31\n1 61\n1 23\n27 45\n39 7\n1 35\n39 29\n27 5\n39 32\n27 48\n35 49\n29 54\n1 46\n35 36\n31 33", "output": "3657" }, { "input": "8 5 1\n5 8\n1 5\n1 3\n1 4\n5 6\n6 7\n1 2", "output": "40" }, { "input": "31 29 20\n29 23\n29 18\n22 14\n29 20\n1 21\n29 10\n28 2\n1 17\n17 15\n1 11\n29 31\n28 6\n12 29\n12 26\n1 13\n22 4\n29 25\n28 22\n17 5\n28 30\n20 27\n29 8\n12 28\n1 12\n12 24\n22 7\n12 16\n12 3\n28 9\n1 19", "output": "872" }, { "input": "8 6 4\n1 2\n1 4\n1 8\n1 3\n1 7\n2 6\n2 5", "output": "55" }, { "input": "7 7 3\n3 2\n3 5\n3 7\n1 3\n1 4\n5 6", "output": "36" }, { "input": "70 42 32\n25 50\n51 7\n39 61\n1 33\n20 5\n1 70\n1 63\n42 35\n64 16\n1 11\n39 42\n20 54\n11 14\n57 44\n1 59\n55 40\n25 3\n31 18\n38 68\n57 23\n39 57\n28 10\n39 20\n42 26\n58 6\n20 56\n57 2\n13 21\n15 69\n39 64\n1 39\n62 53\n39 13\n1 41\n22 12\n13 30\n68 67\n20 31\n51 15\n57 32\n59 34\n39 4\n31 65\n58 24\n20 55\n15 27\n25 46\n20 22\n57 49\n68 52\n39 8\n54 58\n39 28\n13 48\n15 43\n25 66\n1 29\n15 37\n31 60\n1 19\n62 38\n39 17\n64 36\n59 25\n57 45\n57 9\n11 62\n20 51\n54 47", "output": "4827" }, { "input": "13 5 13\n2 5\n5 8\n1 2\n13 7\n2 3\n1 13\n13 11\n13 4\n10 6\n10 12\n7 9\n1 10", "output": "146" }, { "input": "72 16 5\n1 20\n8 4\n23 19\n16 63\n45 65\n27 67\n58 21\n36 17\n20 52\n1 71\n8 59\n20 26\n28 16\n23 3\n45 42\n61 51\n6 31\n1 15\n1 11\n6 62\n43 60\n20 27\n20 32\n1 8\n68 25\n1 57\n20 70\n1 64\n1 13\n8 18\n8 46\n28 49\n8 39\n64 58\n28 47\n27 14\n8 10\n11 53\n1 24\n28 2\n72 30\n36 29\n1 45\n24 23\n1 72\n46 61\n45 56\n72 35\n11 50\n8 55\n8 28\n1 38\n61 41\n1 44\n61 40\n27 33\n72 69\n46 36\n43 66\n61 22\n45 5\n27 43\n46 12\n1 7\n16 68\n1 6\n1 9\n45 37\n27 34\n8 54\n20 48", "output": "5108" }, { "input": "2 1 2\n1 2", "output": "1" }, { "input": "2 1 2\n2 1", "output": "1" } ]
1,535,471,953
2,147,483,647
Python 3
TIME_LIMIT_EXCEEDED
TESTS
4
2,000
38,297,600
n,x,y=map(int,input().split(' '));x-=1;y-=1 adjli=[];parent=[]; for i in range(n): adjli.append([]);parent.append(-1); for _ in range(n-1): u,v=map(int,input().split(' ')) adjli[u-1].append(v-1); adjli[v-1].append(u-1); def dfs(): global adjli,x,y,n visi=[0 for i in range(n)] tr=[False for i in range(n)] child=[0 for i in range(n)] ce=[0 for i in range(n)] visi=[0 for i in range(n)] stack=[x];visi[x]=1 while stack: #print(stack) curr=stack[-1] if curr==y: tr[curr]=True if ce[curr]<len(adjli[curr]): if visi[adjli[curr][ce[curr]]]==0: stack.append(adjli[curr][ce[curr]]) visi[adjli[curr][ce[curr]]]=1 ce[curr]+=1 else: ce[curr]+=1 else: t1=stack[-1];del stack[-1] for i in adjli[t1]: child[t1]+=child[i] child[t1]+=1 if len(stack)>=1: tr[stack[-1]]=tr[stack[-1]]|tr[t1] #print(child,tr) final=n*(n-1) t2=0 for i in adjli[x]: if tr[i]==True: t2=i break #if t2==y: # print(final-(child[y]*child[x]),"yes") #else: print(final-child[y]*(child[x]-child[t2])) dfs()
Title: Kuro and Walking Route Time Limit: None seconds Memory Limit: None megabytes Problem Description: Kuro is living in a country called Uberland, consisting of $n$ towns, numbered from $1$ to $n$, and $n - 1$ bidirectional roads connecting these towns. It is possible to reach each town from any other. Each road connects two towns $a$ and $b$. Kuro loves walking and he is planning to take a walking marathon, in which he will choose a pair of towns $(u, v)$ ($u \neq v$) and walk from $u$ using the shortest path to $v$ (note that $(u, v)$ is considered to be different from $(v, u)$). Oddly, there are 2 special towns in Uberland named Flowrisa (denoted with the index $x$) and Beetopia (denoted with the index $y$). Flowrisa is a town where there are many strong-scent flowers, and Beetopia is another town where many bees live. In particular, Kuro will avoid any pair of towns $(u, v)$ if on the path from $u$ to $v$, he reaches Beetopia after he reached Flowrisa, since the bees will be attracted with the flower smell on Kuro’s body and sting him. Kuro wants to know how many pair of city $(u, v)$ he can take as his route. Since he’s not really bright, he asked you to help him with this problem. Input Specification: The first line contains three integers $n$, $x$ and $y$ ($1 \leq n \leq 3 \cdot 10^5$, $1 \leq x, y \leq n$, $x \ne y$) - the number of towns, index of the town Flowrisa and index of the town Beetopia, respectively. $n - 1$ lines follow, each line contains two integers $a$ and $b$ ($1 \leq a, b \leq n$, $a \ne b$), describes a road connecting two towns $a$ and $b$. It is guaranteed that from each town, we can reach every other town in the city using the given roads. That is, the given map of towns and roads is a tree. Output Specification: A single integer resembles the number of pair of towns $(u, v)$ that Kuro can use as his walking route. Demo Input: ['3 1 3\n1 2\n2 3\n', '3 1 3\n1 2\n1 3\n'] Demo Output: ['5', '4'] Note: On the first example, Kuro can choose these pairs: - $(1, 2)$: his route would be $1 \rightarrow 2$, - $(2, 3)$: his route would be $2 \rightarrow 3$, - $(3, 2)$: his route would be $3 \rightarrow 2$, - $(2, 1)$: his route would be $2 \rightarrow 1$, - $(3, 1)$: his route would be $3 \rightarrow 2 \rightarrow 1$. Kuro can't choose pair $(1, 3)$ since his walking route would be $1 \rightarrow 2 \rightarrow 3$, in which Kuro visits town $1$ (Flowrisa) and then visits town $3$ (Beetopia), which is not allowed (note that pair $(3, 1)$ is still allowed because although Kuro visited Flowrisa and Beetopia, he did not visit them in that order). On the second example, Kuro can choose the following pairs: - $(1, 2)$: his route would be $1 \rightarrow 2$, - $(2, 1)$: his route would be $2 \rightarrow 1$, - $(3, 2)$: his route would be $3 \rightarrow 1 \rightarrow 2$, - $(3, 1)$: his route would be $3 \rightarrow 1$.
```python n,x,y=map(int,input().split(' '));x-=1;y-=1 adjli=[];parent=[]; for i in range(n): adjli.append([]);parent.append(-1); for _ in range(n-1): u,v=map(int,input().split(' ')) adjli[u-1].append(v-1); adjli[v-1].append(u-1); def dfs(): global adjli,x,y,n visi=[0 for i in range(n)] tr=[False for i in range(n)] child=[0 for i in range(n)] ce=[0 for i in range(n)] visi=[0 for i in range(n)] stack=[x];visi[x]=1 while stack: #print(stack) curr=stack[-1] if curr==y: tr[curr]=True if ce[curr]<len(adjli[curr]): if visi[adjli[curr][ce[curr]]]==0: stack.append(adjli[curr][ce[curr]]) visi[adjli[curr][ce[curr]]]=1 ce[curr]+=1 else: ce[curr]+=1 else: t1=stack[-1];del stack[-1] for i in adjli[t1]: child[t1]+=child[i] child[t1]+=1 if len(stack)>=1: tr[stack[-1]]=tr[stack[-1]]|tr[t1] #print(child,tr) final=n*(n-1) t2=0 for i in adjli[x]: if tr[i]==True: t2=i break #if t2==y: # print(final-(child[y]*child[x]),"yes") #else: print(final-child[y]*(child[x]-child[t2])) dfs() ```
0
1,009
A
Game Shopping
PROGRAMMING
800
[ "implementation" ]
null
null
Maxim wants to buy some games at the local game shop. There are $n$ games in the shop, the $i$-th game costs $c_i$. Maxim has a wallet which can be represented as an array of integers. His wallet contains $m$ bills, the $j$-th bill has value $a_j$. Games in the shop are ordered from left to right, Maxim tries to buy every game in that order. When Maxim stands at the position $i$ in the shop, he takes the first bill from his wallet (if his wallet is empty then he proceeds to the next position immediately) and tries to buy the $i$-th game using this bill. After Maxim tried to buy the $n$-th game, he leaves the shop. Maxim buys the $i$-th game if and only if the value of the first bill (which he takes) from his wallet is greater or equal to the cost of the $i$-th game. If he successfully buys the $i$-th game, the first bill from his wallet disappears and the next bill becomes first. Otherwise Maxim leaves the first bill in his wallet (this bill still remains the first one) and proceeds to the next game. For example, for array $c = [2, 4, 5, 2, 4]$ and array $a = [5, 3, 4, 6]$ the following process takes place: Maxim buys the first game using the first bill (its value is $5$), the bill disappears, after that the second bill (with value $3$) becomes the first one in Maxim's wallet, then Maxim doesn't buy the second game because $c_2 &gt; a_2$, the same with the third game, then he buys the fourth game using the bill of value $a_2$ (the third bill becomes the first one in Maxim's wallet) and buys the fifth game using the bill of value $a_3$. Your task is to get the number of games Maxim will buy.
The first line of the input contains two integers $n$ and $m$ ($1 \le n, m \le 1000$) — the number of games and the number of bills in Maxim's wallet. The second line of the input contains $n$ integers $c_1, c_2, \dots, c_n$ ($1 \le c_i \le 1000$), where $c_i$ is the cost of the $i$-th game. The third line of the input contains $m$ integers $a_1, a_2, \dots, a_m$ ($1 \le a_j \le 1000$), where $a_j$ is the value of the $j$-th bill from the Maxim's wallet.
Print a single integer — the number of games Maxim will buy.
[ "5 4\n2 4 5 2 4\n5 3 4 6\n", "5 2\n20 40 50 20 40\n19 20\n", "6 4\n4 8 15 16 23 42\n1000 1000 1000 1000\n" ]
[ "3\n", "0\n", "4\n" ]
The first example is described in the problem statement. In the second example Maxim cannot buy any game because the value of the first bill in his wallet is smaller than the cost of any game in the shop. In the third example the values of the bills in Maxim's wallet are large enough to buy any game he encounter until he runs out of bills in his wallet.
0
[ { "input": "5 4\n2 4 5 2 4\n5 3 4 6", "output": "3" }, { "input": "5 2\n20 40 50 20 40\n19 20", "output": "0" }, { "input": "6 4\n4 8 15 16 23 42\n1000 1000 1000 1000", "output": "4" }, { "input": "5 1\n1 1 1 1 1\n5", "output": "1" }, { "input": "5 1\n10 1 1 1 1\n1000", "output": "1" }, { "input": "5 1\n100 100 100 100 100\n100", "output": "1" }, { "input": "2 1\n2 1\n1", "output": "1" }, { "input": "2 3\n3 1\n2 4 2", "output": "1" }, { "input": "1 5\n4\n1 4 3 3 2", "output": "0" }, { "input": "5 3\n4 2 3 1 1\n2 1 3", "output": "3" }, { "input": "3 5\n5 2 5\n1 4 1 4 2", "output": "0" }, { "input": "7 3\n9 7 10 2 1 1 1\n8 9 6", "output": "3" }, { "input": "5 3\n2 5 3 3 2\n2 5 3", "output": "3" } ]
1,592,372,457
2,147,483,647
Python 3
OK
TESTS
19
124
307,200
n,m=map(int,input().split()) l=list(map(int,input().split())) k=list(map(int,input().split())) i,j = 0,0 count=0 while i<len(l) and j<len(k): if l[i]<=k[j]: count+=1 j+=1 i+=1 else: i+=1 print(count)
Title: Game Shopping Time Limit: None seconds Memory Limit: None megabytes Problem Description: Maxim wants to buy some games at the local game shop. There are $n$ games in the shop, the $i$-th game costs $c_i$. Maxim has a wallet which can be represented as an array of integers. His wallet contains $m$ bills, the $j$-th bill has value $a_j$. Games in the shop are ordered from left to right, Maxim tries to buy every game in that order. When Maxim stands at the position $i$ in the shop, he takes the first bill from his wallet (if his wallet is empty then he proceeds to the next position immediately) and tries to buy the $i$-th game using this bill. After Maxim tried to buy the $n$-th game, he leaves the shop. Maxim buys the $i$-th game if and only if the value of the first bill (which he takes) from his wallet is greater or equal to the cost of the $i$-th game. If he successfully buys the $i$-th game, the first bill from his wallet disappears and the next bill becomes first. Otherwise Maxim leaves the first bill in his wallet (this bill still remains the first one) and proceeds to the next game. For example, for array $c = [2, 4, 5, 2, 4]$ and array $a = [5, 3, 4, 6]$ the following process takes place: Maxim buys the first game using the first bill (its value is $5$), the bill disappears, after that the second bill (with value $3$) becomes the first one in Maxim's wallet, then Maxim doesn't buy the second game because $c_2 &gt; a_2$, the same with the third game, then he buys the fourth game using the bill of value $a_2$ (the third bill becomes the first one in Maxim's wallet) and buys the fifth game using the bill of value $a_3$. Your task is to get the number of games Maxim will buy. Input Specification: The first line of the input contains two integers $n$ and $m$ ($1 \le n, m \le 1000$) — the number of games and the number of bills in Maxim's wallet. The second line of the input contains $n$ integers $c_1, c_2, \dots, c_n$ ($1 \le c_i \le 1000$), where $c_i$ is the cost of the $i$-th game. The third line of the input contains $m$ integers $a_1, a_2, \dots, a_m$ ($1 \le a_j \le 1000$), where $a_j$ is the value of the $j$-th bill from the Maxim's wallet. Output Specification: Print a single integer — the number of games Maxim will buy. Demo Input: ['5 4\n2 4 5 2 4\n5 3 4 6\n', '5 2\n20 40 50 20 40\n19 20\n', '6 4\n4 8 15 16 23 42\n1000 1000 1000 1000\n'] Demo Output: ['3\n', '0\n', '4\n'] Note: The first example is described in the problem statement. In the second example Maxim cannot buy any game because the value of the first bill in his wallet is smaller than the cost of any game in the shop. In the third example the values of the bills in Maxim's wallet are large enough to buy any game he encounter until he runs out of bills in his wallet.
```python n,m=map(int,input().split()) l=list(map(int,input().split())) k=list(map(int,input().split())) i,j = 0,0 count=0 while i<len(l) and j<len(k): if l[i]<=k[j]: count+=1 j+=1 i+=1 else: i+=1 print(count) ```
3
448
D
Multiplication Table
PROGRAMMING
1,800
[ "binary search", "brute force" ]
null
null
Bizon the Champion isn't just charming, he also is very smart. While some of us were learning the multiplication table, Bizon the Champion had fun in his own manner. Bizon the Champion painted an *n*<=×<=*m* multiplication table, where the element on the intersection of the *i*-th row and *j*-th column equals *i*·*j* (the rows and columns of the table are numbered starting from 1). Then he was asked: what number in the table is the *k*-th largest number? Bizon the Champion always answered correctly and immediately. Can you repeat his success? Consider the given multiplication table. If you write out all *n*·*m* numbers from the table in the non-decreasing order, then the *k*-th number you write out is called the *k*-th largest number.
The single line contains integers *n*, *m* and *k* (1<=≤<=*n*,<=*m*<=≤<=5·105; 1<=≤<=*k*<=≤<=*n*·*m*).
Print the *k*-th largest number in a *n*<=×<=*m* multiplication table.
[ "2 2 2\n", "2 3 4\n", "1 10 5\n" ]
[ "2\n", "3\n", "5\n" ]
A 2 × 3 multiplication table looks like this:
2,000
[ { "input": "2 2 2", "output": "2" }, { "input": "2 3 4", "output": "3" }, { "input": "1 10 5", "output": "5" }, { "input": "1 1 1", "output": "1" }, { "input": "10 1 7", "output": "7" }, { "input": "10 10 33", "output": "14" }, { "input": "500000 500000 1", "output": "1" }, { "input": "500000 500000 250000000000", "output": "250000000000" }, { "input": "3 3 1", "output": "1" }, { "input": "3 3 2", "output": "2" }, { "input": "3 3 3", "output": "2" }, { "input": "3 3 5", "output": "3" }, { "input": "3 3 8", "output": "6" }, { "input": "3 3 9", "output": "9" }, { "input": "1 500000 74747", "output": "74747" }, { "input": "500000 1 47474", "output": "47474" }, { "input": "499975 499981 12345", "output": "1634" }, { "input": "499997 499989 248758432143", "output": "225563648440" }, { "input": "5 1 2", "output": "2" }, { "input": "2 2 4", "output": "4" }, { "input": "1 2 1", "output": "1" }, { "input": "2 44 36", "output": "24" }, { "input": "2 28 49", "output": "42" }, { "input": "3 48 30", "output": "17" }, { "input": "5 385 1296", "output": "711" }, { "input": "1 454 340", "output": "340" }, { "input": "1 450 399", "output": "399" }, { "input": "1 3304 218", "output": "218" }, { "input": "3 4175 661", "output": "361" }, { "input": "4 1796 2564", "output": "1232" }, { "input": "2 33975 17369", "output": "11580" }, { "input": "4 25555 45556", "output": "21868" }, { "input": "5 17136 9220", "output": "4039" }, { "input": "3 355632 94220", "output": "51393" }, { "input": "5 353491 107977", "output": "47290" }, { "input": "4 194790 114613", "output": "55015" }, { "input": "47 5 157", "output": "87" }, { "input": "26 5 79", "output": "42" }, { "input": "40 2 3", "output": "2" }, { "input": "12 28 127", "output": "49" }, { "input": "32 12 132", "output": "50" }, { "input": "48 40 937", "output": "364" }, { "input": "45 317 6079", "output": "2160" }, { "input": "18 459 7733", "output": "5684" }, { "input": "38 127 1330", "output": "404" }, { "input": "25 1155 9981", "output": "3318" }, { "input": "41 4600 39636", "output": "10865" }, { "input": "20 2222 11312", "output": "3502" }, { "input": "32 11568 36460", "output": "8988" }, { "input": "48 33111 5809", "output": "1308" }, { "input": "27 24692 71714", "output": "18432" }, { "input": "46 356143 2399416", "output": "598032" }, { "input": "25 127045 1458997", "output": "548779" }, { "input": "41 246624 2596292", "output": "751716" }, { "input": "264 3 775", "output": "741" }, { "input": "495 3 17", "output": "10" }, { "input": "252 5 672", "output": "328" }, { "input": "314 32 3903", "output": "1345" }, { "input": "472 15 932", "output": "283" }, { "input": "302 39 4623", "output": "1589" }, { "input": "318 440 57023", "output": "19203" }, { "input": "403 363 932", "output": "175" }, { "input": "306 433 25754", "output": "6500" }, { "input": "143 1735 246128", "output": "218316" }, { "input": "447 4446 802918", "output": "268036" }, { "input": "132 3890 439379", "output": "265096" }, { "input": "366 45769 5885721", "output": "1841004" }, { "input": "123 37349 4224986", "output": "2895390" }, { "input": "427 46704 7152399", "output": "2256408" }, { "input": "357 184324 28748161", "output": "9992350" }, { "input": "187 425625 25103321", "output": "7534560" }, { "input": "345 423483 40390152", "output": "11441760" }, { "input": "4775 3 7798", "output": "4254" }, { "input": "1035 2 2055", "output": "2040" }, { "input": "3119 3 7305", "output": "5024" }, { "input": "1140 18 11371", "output": "4830" }, { "input": "4313 40 86640", "output": "33496" }, { "input": "2396 24 55229", "output": "43102" }, { "input": "2115 384 385536", "output": "140250" }, { "input": "2376 308 665957", "output": "445248" }, { "input": "4460 377 1197310", "output": "581462" }, { "input": "2315 1673 225263", "output": "40950" }, { "input": "1487 3295 736705", "output": "169290" }, { "input": "3571 3828 7070865", "output": "2696688" }, { "input": "3082 23173 68350097", "output": "51543000" }, { "input": "1165 34678 7211566", "output": "1745254" }, { "input": "1426 26259 37212278", "output": "33359110" }, { "input": "2930 491026 923941798", "output": "409544625" }, { "input": "3191 454046 718852491", "output": "267275676" }, { "input": "1274 295345 301511265", "output": "165699050" }, { "input": "10657 3 9816", "output": "5355" }, { "input": "38939 3 6757", "output": "3686" }, { "input": "37107 4 28350", "output": "13608" }, { "input": "19618 16 313726", "output": "311296" }, { "input": "27824 40 906786", "output": "518185" }, { "input": "46068 31 424079", "output": "131352" }, { "input": "40716 482 14569037", "output": "7363656" }, { "input": "48922 150 653002", "output": "135716" }, { "input": "37203 219 2355222", "output": "681502" }, { "input": "23808 3322 48603931", "output": "20824476" }, { "input": "12090 2766 12261436", "output": "3894264" }, { "input": "20296 4388 29300901", "output": "8862304" }, { "input": "29699 38801 37684232", "output": "6032628" }, { "input": "17980 28231 221639883", "output": "76707084" }, { "input": "16148 39736 239320912", "output": "76569666" }, { "input": "35531 340928 9207622511", "output": "4761654318" }, { "input": "43737 111829 865416726", "output": "208223208" }, { "input": "21980 353130 2233068545", "output": "638445948" }, { "input": "339697 4 1259155", "output": "993876" }, { "input": "404625 2 132619", "output": "88413" }, { "input": "226111 2 359116", "output": "266010" }, { "input": "318377 38 7214261", "output": "3108710" }, { "input": "139863 21 1834174", "output": "833220" }, { "input": "204791 41 8382971", "output": "8020256" }, { "input": "149281 382 51428462", "output": "33762615" }, { "input": "370768 123 15161219", "output": "4677246" }, { "input": "313975 448 85041752", "output": "36070940" }, { "input": "136614 3211 364472869", "output": "209750632" }, { "input": "201542 4833 512478332", "output": "197440230" }, { "input": "423029 1365 126620483", "output": "32780826" }, { "input": "110941 47433 2098952903", "output": "693548595" }, { "input": "175869 39014 3201917805", "output": "1148848775" }, { "input": "397356 10518 874806404", "output": "222468766" }, { "input": "118728 168631 16269281609", "output": "9092195490" }, { "input": "183656 409931 42943608085", "output": "17438143800" }, { "input": "283422 407789 73398688052", "output": "32237937640" }, { "input": "500000 500000 888888", "output": "77856" } ]
1,658,074,860
2,147,483,647
Python 3
TIME_LIMIT_EXCEEDED
TESTS
6
1,000
0
def fun(a,n,m): lt_eq_mid=0 for i in range(1,n+1): lt_eq_mid+=min(m,a//i) return lt_eq_mid n,m,k=list(map(int,input().split())) left=1 right=n*m while(left<=right): mid=(left+right)//2 lt_eq_mid=fun(mid,n,m) #print(str(mid)+" "+str(lt_eq_mid)) if(lt_eq_mid>k): prev=fun(mid-1,n,m) #print("Prev"+str(prev)+" "+str(mid)) if(prev<k): print(mid) break right=mid-1 elif(lt_eq_mid<k): left=mid+1 else: print(mid) break
Title: Multiplication Table Time Limit: None seconds Memory Limit: None megabytes Problem Description: Bizon the Champion isn't just charming, he also is very smart. While some of us were learning the multiplication table, Bizon the Champion had fun in his own manner. Bizon the Champion painted an *n*<=×<=*m* multiplication table, where the element on the intersection of the *i*-th row and *j*-th column equals *i*·*j* (the rows and columns of the table are numbered starting from 1). Then he was asked: what number in the table is the *k*-th largest number? Bizon the Champion always answered correctly and immediately. Can you repeat his success? Consider the given multiplication table. If you write out all *n*·*m* numbers from the table in the non-decreasing order, then the *k*-th number you write out is called the *k*-th largest number. Input Specification: The single line contains integers *n*, *m* and *k* (1<=≤<=*n*,<=*m*<=≤<=5·105; 1<=≤<=*k*<=≤<=*n*·*m*). Output Specification: Print the *k*-th largest number in a *n*<=×<=*m* multiplication table. Demo Input: ['2 2 2\n', '2 3 4\n', '1 10 5\n'] Demo Output: ['2\n', '3\n', '5\n'] Note: A 2 × 3 multiplication table looks like this:
```python def fun(a,n,m): lt_eq_mid=0 for i in range(1,n+1): lt_eq_mid+=min(m,a//i) return lt_eq_mid n,m,k=list(map(int,input().split())) left=1 right=n*m while(left<=right): mid=(left+right)//2 lt_eq_mid=fun(mid,n,m) #print(str(mid)+" "+str(lt_eq_mid)) if(lt_eq_mid>k): prev=fun(mid-1,n,m) #print("Prev"+str(prev)+" "+str(mid)) if(prev<k): print(mid) break right=mid-1 elif(lt_eq_mid<k): left=mid+1 else: print(mid) break ```
0
981
A
Antipalindrome
PROGRAMMING
900
[ "brute force", "implementation", "strings" ]
null
null
A string is a palindrome if it reads the same from the left to the right and from the right to the left. For example, the strings "kek", "abacaba", "r" and "papicipap" are palindromes, while the strings "abb" and "iq" are not. A substring $s[l \ldots r]$ ($1<=\leq<=l<=\leq<=r<=\leq<=|s|$) of a string $s<==<=s_{1}s_{2} \ldots s_{|s|}$ is the string $s_{l}s_{l<=+<=1} \ldots s_{r}$. Anna does not like palindromes, so she makes her friends call her Ann. She also changes all the words she reads in a similar way. Namely, each word $s$ is changed into its longest substring that is not a palindrome. If all the substrings of $s$ are palindromes, she skips the word at all. Some time ago Ann read the word $s$. What is the word she changed it into?
The first line contains a non-empty string $s$ with length at most $50$ characters, containing lowercase English letters only.
If there is such a substring in $s$ that is not a palindrome, print the maximum length of such a substring. Otherwise print $0$. Note that there can be multiple longest substrings that are not palindromes, but their length is unique.
[ "mew\n", "wuffuw\n", "qqqqqqqq\n" ]
[ "3\n", "5\n", "0\n" ]
"mew" is not a palindrome, so the longest substring of it that is not a palindrome, is the string "mew" itself. Thus, the answer for the first example is $3$. The string "uffuw" is one of the longest non-palindrome substrings (of length $5$) of the string "wuffuw", so the answer for the second example is $5$. All substrings of the string "qqqqqqqq" consist of equal characters so they are palindromes. This way, there are no non-palindrome substrings. Thus, the answer for the third example is $0$.
500
[ { "input": "mew", "output": "3" }, { "input": "wuffuw", "output": "5" }, { "input": "qqqqqqqq", "output": "0" }, { "input": "ijvji", "output": "4" }, { "input": "iiiiiii", "output": "0" }, { "input": "wobervhvvkihcuyjtmqhaaigvvgiaahqmtjyuchikvvhvrebow", "output": "49" }, { "input": "wwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwww", "output": "0" }, { "input": "wobervhvvkihcuyjtmqhaaigvahheoqleromusrartldojsjvy", "output": "50" }, { "input": "ijvxljt", "output": "7" }, { "input": "fyhcncnchyf", "output": "10" }, { "input": "ffffffffffff", "output": "0" }, { "input": "fyhcncfsepqj", "output": "12" }, { "input": "ybejrrlbcinttnicblrrjeby", "output": "23" }, { "input": "yyyyyyyyyyyyyyyyyyyyyyyyy", "output": "0" }, { "input": "ybejrrlbcintahovgjddrqatv", "output": "25" }, { "input": "oftmhcmclgyqaojljoaqyglcmchmtfo", "output": "30" }, { "input": "oooooooooooooooooooooooooooooooo", "output": "0" }, { "input": "oftmhcmclgyqaojllbotztajglsmcilv", "output": "32" }, { "input": "gxandbtgpbknxvnkjaajknvxnkbpgtbdnaxg", "output": "35" }, { "input": "gggggggggggggggggggggggggggggggggggg", "output": "0" }, { "input": "gxandbtgpbknxvnkjaygommzqitqzjfalfkk", "output": "36" }, { "input": "fcliblymyqckxvieotjooojtoeivxkcqymylbilcf", "output": "40" }, { "input": "fffffffffffffffffffffffffffffffffffffffffff", "output": "0" }, { "input": "fcliblymyqckxvieotjootiqwtyznhhvuhbaixwqnsy", "output": "43" }, { "input": "rrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr", "output": "0" }, { "input": "rajccqwqnqmshmerpvjyfepxwpxyldzpzhctqjnstxyfmlhiy", "output": "49" }, { "input": "a", "output": "0" }, { "input": "abca", "output": "4" }, { "input": "aaaaabaaaaa", "output": "10" }, { "input": "aba", "output": "2" }, { "input": "asaa", "output": "4" }, { "input": "aabaa", "output": "4" }, { "input": "aabbaa", "output": "5" }, { "input": "abcdaaa", "output": "7" }, { "input": "aaholaa", "output": "7" }, { "input": "abcdefghijka", "output": "12" }, { "input": "aaadcba", "output": "7" }, { "input": "aaaabaaaa", "output": "8" }, { "input": "abaa", "output": "4" }, { "input": "abcbaa", "output": "6" }, { "input": "ab", "output": "2" }, { "input": "l", "output": "0" }, { "input": "aaaabcaaaa", "output": "10" }, { "input": "abbaaaaaabba", "output": "11" }, { "input": "abaaa", "output": "5" }, { "input": "baa", "output": "3" }, { "input": "aaaaaaabbba", "output": "11" }, { "input": "ccbcc", "output": "4" }, { "input": "bbbaaab", "output": "7" }, { "input": "abaaaaaaaa", "output": "10" }, { "input": "abaaba", "output": "5" }, { "input": "aabsdfaaaa", "output": "10" }, { "input": "aaaba", "output": "5" }, { "input": "aaabaaa", "output": "6" }, { "input": "baaabbb", "output": "7" }, { "input": "ccbbabbcc", "output": "8" }, { "input": "cabc", "output": "4" }, { "input": "aabcd", "output": "5" }, { "input": "abcdea", "output": "6" }, { "input": "bbabb", "output": "4" }, { "input": "aaaaabababaaaaa", "output": "14" }, { "input": "bbabbb", "output": "6" }, { "input": "aababd", "output": "6" }, { "input": "abaaaa", "output": "6" }, { "input": "aaaaaaaabbba", "output": "12" }, { "input": "aabca", "output": "5" }, { "input": "aaabccbaaa", "output": "9" }, { "input": "aaaaaaaaaaaaaaaaaaaab", "output": "21" }, { "input": "babb", "output": "4" }, { "input": "abcaa", "output": "5" }, { "input": "qwqq", "output": "4" }, { "input": "aaaaaaaaaaabbbbbbbbbbbbbbbaaaaaaaaaaaaaaaaaaaaaa", "output": "48" }, { "input": "aaab", "output": "4" }, { "input": "aaaaaabaaaaa", "output": "12" }, { "input": "wwuww", "output": "4" }, { "input": "aaaaabcbaaaaa", "output": "12" }, { "input": "aaabbbaaa", "output": "8" }, { "input": "aabcbaa", "output": "6" }, { "input": "abccdefccba", "output": "11" }, { "input": "aabbcbbaa", "output": "8" }, { "input": "aaaabbaaaa", "output": "9" }, { "input": "aabcda", "output": "6" }, { "input": "abbca", "output": "5" }, { "input": "aaaaaabbaaa", "output": "11" }, { "input": "sssssspssssss", "output": "12" }, { "input": "sdnmsdcs", "output": "8" }, { "input": "aaabbbccbbbaaa", "output": "13" }, { "input": "cbdbdc", "output": "6" }, { "input": "abb", "output": "3" }, { "input": "abcdefaaaa", "output": "10" }, { "input": "abbbaaa", "output": "7" }, { "input": "v", "output": "0" }, { "input": "abccbba", "output": "7" }, { "input": "axyza", "output": "5" }, { "input": "abcdefgaaaa", "output": "11" }, { "input": "aaabcdaaa", "output": "9" }, { "input": "aaaacaaaa", "output": "8" }, { "input": "aaaaaaaaaaaaaaaaaaaabaaaaaaaaaaaaaaaaaaaaa", "output": "42" }, { "input": "abbbaa", "output": "6" }, { "input": "abcdee", "output": "6" }, { "input": "oom", "output": "3" }, { "input": "aabcaa", "output": "6" }, { "input": "abba", "output": "3" }, { "input": "aaca", "output": "4" }, { "input": "aacbca", "output": "6" }, { "input": "ababa", "output": "4" }, { "input": "abcda", "output": "5" }, { "input": "cccaaccc", "output": "7" }, { "input": "aaabcda", "output": "7" }, { "input": "aa", "output": "0" }, { "input": "aabaaaa", "output": "7" }, { "input": "abbaaaa", "output": "7" }, { "input": "aaabcbaaa", "output": "8" }, { "input": "aabba", "output": "5" }, { "input": "xyxx", "output": "4" }, { "input": "aaaaaaaaaaaabc", "output": "14" }, { "input": "bbaaaabb", "output": "7" }, { "input": "aaabaa", "output": "6" }, { "input": "sssssabsssss", "output": "12" }, { "input": "bbbaaaabbb", "output": "9" }, { "input": "abbbbaaaa", "output": "9" }, { "input": "wwufuww", "output": "6" }, { "input": "oowoo", "output": "4" }, { "input": "cccaccc", "output": "6" }, { "input": "aaa", "output": "0" }, { "input": "bbbcc", "output": "5" }, { "input": "abcdef", "output": "6" }, { "input": "abbba", "output": "4" }, { "input": "aab", "output": "3" }, { "input": "aaba", "output": "4" }, { "input": "azbyaaa", "output": "7" }, { "input": "oooooiooooo", "output": "10" }, { "input": "aabbbbbaaaaaa", "output": "13" } ]
1,638,459,564
2,147,483,647
Python 3
OK
TESTS
133
46
0
s = input() f = False d = len(s) while s != '': for i in range(len(s) // 2): if s[i] != s[len(s) - 1 -i]: f = True break if f: break else: s = s[1:] d -= 1 print(d)
Title: Antipalindrome Time Limit: None seconds Memory Limit: None megabytes Problem Description: A string is a palindrome if it reads the same from the left to the right and from the right to the left. For example, the strings "kek", "abacaba", "r" and "papicipap" are palindromes, while the strings "abb" and "iq" are not. A substring $s[l \ldots r]$ ($1<=\leq<=l<=\leq<=r<=\leq<=|s|$) of a string $s<==<=s_{1}s_{2} \ldots s_{|s|}$ is the string $s_{l}s_{l<=+<=1} \ldots s_{r}$. Anna does not like palindromes, so she makes her friends call her Ann. She also changes all the words she reads in a similar way. Namely, each word $s$ is changed into its longest substring that is not a palindrome. If all the substrings of $s$ are palindromes, she skips the word at all. Some time ago Ann read the word $s$. What is the word she changed it into? Input Specification: The first line contains a non-empty string $s$ with length at most $50$ characters, containing lowercase English letters only. Output Specification: If there is such a substring in $s$ that is not a palindrome, print the maximum length of such a substring. Otherwise print $0$. Note that there can be multiple longest substrings that are not palindromes, but their length is unique. Demo Input: ['mew\n', 'wuffuw\n', 'qqqqqqqq\n'] Demo Output: ['3\n', '5\n', '0\n'] Note: "mew" is not a palindrome, so the longest substring of it that is not a palindrome, is the string "mew" itself. Thus, the answer for the first example is $3$. The string "uffuw" is one of the longest non-palindrome substrings (of length $5$) of the string "wuffuw", so the answer for the second example is $5$. All substrings of the string "qqqqqqqq" consist of equal characters so they are palindromes. This way, there are no non-palindrome substrings. Thus, the answer for the third example is $0$.
```python s = input() f = False d = len(s) while s != '': for i in range(len(s) // 2): if s[i] != s[len(s) - 1 -i]: f = True break if f: break else: s = s[1:] d -= 1 print(d) ```
3
978
A
Remove Duplicates
PROGRAMMING
800
[ "implementation" ]
null
null
Petya has an array $a$ consisting of $n$ integers. He wants to remove duplicate (equal) elements. Petya wants to leave only the rightmost entry (occurrence) for each element of the array. The relative order of the remaining unique elements should not be changed.
The first line contains a single integer $n$ ($1 \le n \le 50$) — the number of elements in Petya's array. The following line contains a sequence $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 1\,000$) — the Petya's array.
In the first line print integer $x$ — the number of elements which will be left in Petya's array after he removed the duplicates. In the second line print $x$ integers separated with a space — Petya's array after he removed the duplicates. For each unique element only the rightmost entry should be left.
[ "6\n1 5 5 1 6 1\n", "5\n2 4 2 4 4\n", "5\n6 6 6 6 6\n" ]
[ "3\n5 6 1 \n", "2\n2 4 \n", "1\n6 \n" ]
In the first example you should remove two integers $1$, which are in the positions $1$ and $4$. Also you should remove the integer $5$, which is in the position $2$. In the second example you should remove integer $2$, which is in the position $1$, and two integers $4$, which are in the positions $2$ and $4$. In the third example you should remove four integers $6$, which are in the positions $1$, $2$, $3$ and $4$.
0
[ { "input": "6\n1 5 5 1 6 1", "output": "3\n5 6 1 " }, { "input": "5\n2 4 2 4 4", "output": "2\n2 4 " }, { "input": "5\n6 6 6 6 6", "output": "1\n6 " }, { "input": "7\n1 2 3 4 2 2 3", "output": "4\n1 4 2 3 " }, { "input": "9\n100 100 100 99 99 99 100 100 100", "output": "2\n99 100 " }, { "input": "27\n489 489 487 488 750 230 43 645 42 42 489 42 973 42 973 750 645 355 868 112 868 489 750 489 887 489 868", "output": "13\n487 488 230 43 42 973 645 355 112 750 887 489 868 " }, { "input": "40\n151 421 421 909 117 222 909 954 227 421 227 954 954 222 421 227 421 421 421 151 421 227 222 222 222 222 421 183 421 227 421 954 222 421 954 421 222 421 909 421", "output": "8\n117 151 183 227 954 222 909 421 " }, { "input": "48\n2 2 2 903 903 2 726 2 2 2 2 2 2 2 2 2 2 726 2 2 2 2 2 2 2 726 2 2 2 2 62 2 2 2 2 2 2 2 2 726 62 726 2 2 2 903 903 2", "output": "4\n62 726 903 2 " }, { "input": "1\n1", "output": "1\n1 " }, { "input": "13\n5 37 375 5 37 33 37 375 37 2 3 3 2", "output": "6\n5 33 375 37 3 2 " }, { "input": "50\n1 2 3 4 5 4 3 2 1 2 3 2 1 4 5 5 4 3 2 1 1 2 3 4 5 4 3 2 1 2 3 2 1 4 5 5 4 3 2 1 4 3 2 5 1 6 6 6 6 6", "output": "6\n4 3 2 5 1 6 " }, { "input": "47\n233 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 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": "2\n233 1 " }, { "input": "47\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", "output": "1\n1 " }, { "input": "2\n964 964", "output": "1\n964 " }, { "input": "2\n1000 1000", "output": "1\n1000 " }, { "input": "1\n1000", "output": "1\n1000 " }, { "input": "45\n991 991 996 996 992 992 999 1000 998 1000 992 999 996 999 991 991 999 993 992 999 1000 997 992 999 996 991 994 996 991 999 1000 993 999 997 999 992 991 997 991 998 998 995 998 994 993", "output": "10\n996 1000 999 992 997 991 995 998 994 993 " }, { "input": "6\n994 993 1000 998 991 994", "output": "5\n993 1000 998 991 994 " }, { "input": "48\n992 995 992 991 994 992 995 999 996 993 999 995 993 992 1000 992 997 996 991 993 992 998 998 998 999 995 992 992 993 992 992 995 996 995 997 991 997 991 999 994 994 997 1000 998 1000 992 1000 999", "output": "10\n993 996 995 991 994 997 998 992 1000 999 " }, { "input": "3\n6 6 3", "output": "2\n6 3 " }, { "input": "36\n999 1000 993 993 1000 999 996 997 998 995 995 997 999 995 1000 998 998 994 993 998 994 999 1000 995 996 994 991 991 999 996 993 999 996 998 991 997", "output": "9\n1000 995 994 993 999 996 998 991 997 " }, { "input": "49\n991 997 995 991 995 998 994 996 997 991 998 993 992 999 996 995 991 991 999 997 995 993 997 1000 997 993 993 994 999 994 992 991 1000 996 994 996 996 999 992 992 1000 991 997 993 991 994 997 991 996", "output": "10\n998 995 999 992 1000 993 994 997 991 996 " }, { "input": "2\n1000 999", "output": "2\n1000 999 " }, { "input": "28\n997 994 991 994 994 995 1000 992 995 994 994 995 991 996 991 996 991 999 999 993 994 997 995 992 991 992 998 1000", "output": "10\n996 999 993 994 997 995 991 992 998 1000 " }, { "input": "15\n991 995 995 1000 991 993 997 998 1000 994 1000 992 991 995 992", "output": "8\n993 997 998 994 1000 991 995 992 " }, { "input": "6\n1000 1 1000 2 1000 1", "output": "3\n2 1000 1 " }, { "input": "6\n1000 1 1000 2 1 1000", "output": "3\n2 1 1000 " }, { "input": "7\n1 1000 1 999 1000 1 2", "output": "4\n999 1000 1 2 " } ]
1,697,003,591
2,147,483,647
PyPy 3-64
WRONG_ANSWER
TESTS
0
46
0
#for _ in range(int(input())): q=int(input()) a=set(list(map(int,input().split()))) print(*a)
Title: Remove Duplicates Time Limit: None seconds Memory Limit: None megabytes Problem Description: Petya has an array $a$ consisting of $n$ integers. He wants to remove duplicate (equal) elements. Petya wants to leave only the rightmost entry (occurrence) for each element of the array. The relative order of the remaining unique elements should not be changed. Input Specification: The first line contains a single integer $n$ ($1 \le n \le 50$) — the number of elements in Petya's array. The following line contains a sequence $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 1\,000$) — the Petya's array. Output Specification: In the first line print integer $x$ — the number of elements which will be left in Petya's array after he removed the duplicates. In the second line print $x$ integers separated with a space — Petya's array after he removed the duplicates. For each unique element only the rightmost entry should be left. Demo Input: ['6\n1 5 5 1 6 1\n', '5\n2 4 2 4 4\n', '5\n6 6 6 6 6\n'] Demo Output: ['3\n5 6 1 \n', '2\n2 4 \n', '1\n6 \n'] Note: In the first example you should remove two integers $1$, which are in the positions $1$ and $4$. Also you should remove the integer $5$, which is in the position $2$. In the second example you should remove integer $2$, which is in the position $1$, and two integers $4$, which are in the positions $2$ and $4$. In the third example you should remove four integers $6$, which are in the positions $1$, $2$, $3$ and $4$.
```python #for _ in range(int(input())): q=int(input()) a=set(list(map(int,input().split()))) print(*a) ```
0
450
A
Jzzhu and Children
PROGRAMMING
1,000
[ "implementation" ]
null
null
There are *n* children in Jzzhu's school. Jzzhu is going to give some candies to them. Let's number all the children from 1 to *n*. The *i*-th child wants to get at least *a**i* candies. Jzzhu asks children to line up. Initially, the *i*-th child stands at the *i*-th place of the line. Then Jzzhu start distribution of the candies. He follows the algorithm: 1. Give *m* candies to the first child of the line. 1. If this child still haven't got enough candies, then the child goes to the end of the line, else the child go home. 1. Repeat the first two steps while the line is not empty. Consider all the children in the order they go home. Jzzhu wants to know, which child will be the last in this order?
The first line contains two integers *n*,<=*m* (1<=≤<=*n*<=≤<=100; 1<=≤<=*m*<=≤<=100). The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=100).
Output a single integer, representing the number of the last child.
[ "5 2\n1 3 1 4 2\n", "6 4\n1 1 2 2 3 3\n" ]
[ "4\n", "6\n" ]
Let's consider the first sample. Firstly child 1 gets 2 candies and go home. Then child 2 gets 2 candies and go to the end of the line. Currently the line looks like [3, 4, 5, 2] (indices of the children in order of the line). Then child 3 gets 2 candies and go home, and then child 4 gets 2 candies and goes to the end of the line. Currently the line looks like [5, 2, 4]. Then child 5 gets 2 candies and goes home. Then child 2 gets two candies and goes home, and finally child 4 gets 2 candies and goes home. Child 4 is the last one who goes home.
500
[ { "input": "5 2\n1 3 1 4 2", "output": "4" }, { "input": "6 4\n1 1 2 2 3 3", "output": "6" }, { "input": "7 3\n6 1 5 4 2 3 1", "output": "4" }, { "input": "10 5\n2 7 3 6 2 5 1 3 4 5", "output": "4" }, { "input": "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", "output": "100" }, { "input": "9 3\n9 5 2 3 7 1 8 4 6", "output": "7" }, { "input": "20 10\n58 4 32 10 73 7 30 39 47 6 59 21 24 66 79 79 46 13 29 58", "output": "16" }, { "input": "50 5\n89 56 3 2 40 37 56 52 83 59 43 83 43 59 29 74 22 58 53 41 53 67 78 30 57 32 58 29 95 46 45 85 60 49 41 82 8 71 52 40 45 26 6 71 84 91 4 93 40 54", "output": "48" }, { "input": "50 1\n4 3 9 7 6 8 3 7 10 9 8 8 10 2 9 3 2 4 4 10 4 6 8 10 9 9 4 2 8 9 4 4 9 5 1 5 2 4 4 9 10 2 5 10 7 2 8 6 8 1", "output": "44" }, { "input": "50 5\n3 9 10 8 3 3 4 6 8 2 9 9 3 1 2 10 6 8 7 2 7 4 2 7 5 10 2 2 2 5 10 5 6 6 8 7 10 4 3 2 10 8 6 6 8 6 4 4 1 3", "output": "46" }, { "input": "50 2\n56 69 72 15 95 92 51 1 74 87 100 29 46 54 18 81 84 72 84 83 20 63 71 27 45 74 50 89 48 8 21 15 47 3 39 73 80 84 6 99 17 25 56 3 74 64 71 39 89 78", "output": "40" }, { "input": "50 3\n31 39 64 16 86 3 1 9 25 54 98 42 20 3 49 41 73 37 55 62 33 77 64 22 33 82 26 13 10 13 7 40 48 18 46 79 94 72 19 12 11 61 16 37 10 49 14 94 48 69", "output": "11" }, { "input": "50 100\n67 67 61 68 42 29 70 77 12 61 71 27 4 73 87 52 59 38 93 90 31 27 87 47 26 57 76 6 28 72 81 68 50 84 69 79 39 93 52 6 88 12 46 13 90 68 71 38 90 95", "output": "50" }, { "input": "100 3\n4 14 20 11 19 11 14 20 5 7 6 12 11 17 5 11 7 6 2 10 13 5 12 8 5 17 20 18 7 19 11 7 7 20 20 8 10 17 17 19 20 5 15 16 19 7 11 16 4 17 2 10 1 20 20 16 19 9 9 11 5 7 12 9 9 6 20 18 13 19 8 4 8 1 2 4 10 11 15 14 1 7 17 12 13 19 12 2 3 14 15 15 5 17 14 12 17 14 16 9", "output": "86" }, { "input": "100 5\n16 8 14 16 12 11 17 19 19 2 8 9 5 6 19 9 11 18 6 9 14 16 14 18 17 17 17 5 15 20 19 7 7 10 10 5 14 20 5 19 11 16 16 19 17 9 7 12 14 10 2 11 14 5 20 8 10 11 19 2 14 14 19 17 5 10 8 8 4 2 1 10 20 12 14 11 7 6 6 15 1 5 9 15 3 17 16 17 5 14 11 9 16 15 1 11 10 6 15 7", "output": "93" }, { "input": "100 1\n58 94 18 50 17 14 96 62 83 80 75 5 9 22 25 41 3 96 74 45 66 37 2 37 13 85 68 54 77 11 85 19 25 21 52 59 90 61 72 89 82 22 10 16 3 68 61 29 55 76 28 85 65 76 27 3 14 10 56 37 86 18 35 38 56 68 23 88 33 38 52 87 55 83 94 34 100 41 83 56 91 77 32 74 97 13 67 31 57 81 53 39 5 88 46 1 79 4 49 42", "output": "77" }, { "input": "100 2\n1 51 76 62 34 93 90 43 57 59 52 78 3 48 11 60 57 48 5 54 28 81 87 23 44 77 67 61 14 73 29 53 21 89 67 41 47 9 63 37 1 71 40 85 4 14 77 40 78 75 89 74 4 70 32 65 81 95 49 90 72 41 76 55 69 83 73 84 85 93 46 6 74 90 62 37 97 7 7 37 83 30 37 88 34 16 11 59 85 19 57 63 85 20 63 97 97 65 61 48", "output": "97" }, { "input": "100 3\n30 83 14 55 61 66 34 98 90 62 89 74 45 93 33 31 75 35 82 100 63 69 48 18 99 2 36 71 14 30 70 76 96 85 97 90 49 36 6 76 37 94 70 3 63 73 75 48 39 29 13 2 46 26 9 56 1 18 54 53 85 34 2 12 1 93 75 67 77 77 14 26 33 25 55 9 57 70 75 6 87 66 18 3 41 69 73 24 49 2 20 72 39 58 91 54 74 56 66 78", "output": "20" }, { "input": "100 4\n69 92 76 3 32 50 15 38 21 22 14 3 67 41 95 12 10 62 83 52 78 1 18 58 94 35 62 71 58 75 13 73 60 34 50 97 50 70 19 96 53 10 100 26 20 39 62 59 88 26 24 83 70 68 66 8 6 38 16 93 2 91 81 89 78 74 21 8 31 56 28 53 77 5 81 5 94 42 77 75 92 15 59 36 61 18 55 45 69 68 81 51 12 42 85 74 98 31 17 41", "output": "97" }, { "input": "100 5\n2 72 10 60 6 50 72 34 97 77 35 43 80 64 40 53 46 6 90 22 29 70 26 68 52 19 72 88 83 18 55 32 99 81 11 21 39 42 41 63 60 97 30 23 55 78 89 35 24 50 99 52 27 76 24 8 20 27 51 37 17 82 69 18 46 19 26 77 52 83 76 65 43 66 84 84 13 30 66 88 84 23 37 1 17 26 11 50 73 56 54 37 40 29 35 8 1 39 50 82", "output": "51" }, { "input": "100 7\n6 73 7 54 92 33 66 65 80 47 2 53 28 59 61 16 54 89 37 48 77 40 49 59 27 52 17 22 78 80 81 80 8 93 50 7 87 57 29 16 89 55 20 7 51 54 30 98 44 96 27 70 1 1 32 61 22 92 84 98 31 89 91 90 28 56 49 25 86 49 55 16 19 1 18 8 88 47 16 18 73 86 2 96 16 91 74 49 38 98 94 25 34 85 29 27 99 31 31 58", "output": "97" }, { "input": "100 9\n36 4 45 16 19 6 10 87 44 82 71 49 70 35 83 19 40 76 45 94 44 96 10 54 82 77 86 63 11 37 21 3 15 89 80 88 89 16 72 23 25 9 51 25 10 45 96 5 6 18 51 31 42 57 41 51 42 15 89 61 45 82 16 48 61 67 19 40 9 33 90 36 78 36 79 79 16 10 83 87 9 22 84 12 23 76 36 14 2 81 56 33 56 23 57 84 76 55 35 88", "output": "47" }, { "input": "100 10\n75 81 39 64 90 58 92 28 75 9 96 78 92 83 77 68 76 71 14 46 58 60 80 25 78 11 13 63 22 82 65 68 47 6 33 63 90 50 85 43 73 94 80 48 67 11 83 17 22 15 94 80 66 99 66 4 46 35 52 1 62 39 96 57 37 47 97 49 64 12 36 63 90 16 4 75 85 82 85 56 13 4 92 45 44 93 17 35 22 46 18 44 29 7 52 4 100 98 87 51", "output": "98" }, { "input": "100 20\n21 19 61 70 54 97 98 14 61 72 25 94 24 56 55 25 12 80 76 11 35 17 80 26 11 94 52 47 84 61 10 2 74 25 10 21 2 79 55 50 30 75 10 64 44 5 60 96 52 16 74 41 20 77 20 44 8 86 74 36 49 61 99 13 54 64 19 99 50 43 12 73 48 48 83 55 72 73 63 81 30 27 95 9 97 82 24 3 89 90 33 14 47 88 22 78 12 75 58 67", "output": "94" }, { "input": "100 30\n56 79 59 23 11 23 67 82 81 80 99 79 8 58 93 36 98 81 46 39 34 67 3 50 4 68 70 71 2 21 52 30 75 23 33 21 16 100 56 43 8 27 40 8 56 24 17 40 94 10 67 49 61 36 95 87 17 41 7 94 33 19 17 50 26 11 94 54 38 46 77 9 53 35 98 42 50 20 43 6 78 6 38 24 100 45 43 16 1 50 16 46 14 91 95 88 10 1 50 19", "output": "95" }, { "input": "100 40\n86 11 97 17 38 95 11 5 13 83 67 75 50 2 46 39 84 68 22 85 70 23 64 46 59 93 39 80 35 78 93 21 83 19 64 1 49 59 99 83 44 81 70 58 15 82 83 47 55 65 91 10 2 92 4 77 37 32 12 57 78 11 42 8 59 21 96 69 61 30 44 29 12 70 91 14 10 83 11 75 14 10 19 39 8 98 5 81 66 66 79 55 36 29 22 45 19 24 55 49", "output": "88" }, { "input": "100 50\n22 39 95 69 94 53 80 73 33 90 40 60 2 4 84 50 70 38 92 12 36 74 87 70 51 36 57 5 54 6 35 81 52 17 55 100 95 81 32 76 21 1 100 1 95 1 40 91 98 59 84 19 11 51 79 19 47 86 45 15 62 2 59 77 31 68 71 92 17 33 10 33 85 57 5 2 88 97 91 99 63 20 63 54 79 93 24 62 46 27 30 87 3 64 95 88 16 50 79 1", "output": "99" }, { "input": "100 70\n61 48 89 17 97 6 93 13 64 50 66 88 24 52 46 99 6 65 93 64 82 37 57 41 47 1 84 5 97 83 79 46 16 35 40 7 64 15 44 96 37 17 30 92 51 67 26 3 14 56 27 68 66 93 36 39 51 6 40 55 79 26 71 54 8 48 18 2 71 12 55 60 29 37 31 97 26 37 25 68 67 70 3 87 100 41 5 82 65 92 24 66 76 48 89 8 40 93 31 95", "output": "100" }, { "input": "100 90\n87 32 30 15 10 52 93 63 84 1 82 41 27 51 75 32 42 94 39 53 70 13 4 22 99 35 44 38 5 23 18 100 61 80 9 12 42 93 9 77 3 7 60 95 66 78 95 42 69 8 1 88 93 66 96 20 76 63 15 36 92 52 2 72 36 57 48 63 29 20 74 88 49 47 81 61 94 74 70 93 47 3 19 52 59 41 5 40 22 3 76 97 91 37 95 88 91 99 76 15", "output": "98" }, { "input": "100 100\n79 75 7 28 6 96 38 35 57 95 41 74 24 96 32 78 81 13 63 84 24 95 3 23 66 1 60 6 96 49 41 5 14 18 31 97 66 19 49 89 49 70 51 28 20 99 18 1 28 77 24 46 69 21 40 32 31 66 28 6 66 97 9 16 70 90 91 30 34 82 93 41 65 11 39 52 1 88 63 43 80 50 60 49 28 56 18 76 24 57 74 1 28 99 36 35 79 54 18 16", "output": "100" }, { "input": "1 3\n5", "output": "1" }, { "input": "1 1\n100", "output": "1" }, { "input": "2 3\n4 2", "output": "1" }, { "input": "2 5\n99 97", "output": "2" }, { "input": "3 4\n7 5 2", "output": "2" }, { "input": "3 50\n47 86 51", "output": "3" }, { "input": "5 100\n82 100 85 1 37", "output": "5" }, { "input": "5 20\n40 39 21 5 20", "output": "3" }, { "input": "1 27\n81", "output": "1" }, { "input": "20 13\n7 8 29 83 74 28 93 85 7 8 3 9 8 70 49 50 39 41 57 1", "output": "7" }, { "input": "2 1\n100 2", "output": "1" }, { "input": "2 2\n6 4", "output": "1" }, { "input": "5 2\n6 4 4 1 1", "output": "1" }, { "input": "1 4\n3", "output": "1" }, { "input": "3 2\n1 5 3", "output": "2" }, { "input": "3 1\n3 2 2", "output": "1" }, { "input": "3 1\n2 3 2", "output": "2" }, { "input": "5 1\n5 1 1 1 1", "output": "1" }, { "input": "2 3\n7 4", "output": "1" } ]
1,669,850,114
2,147,483,647
PyPy 3-64
WRONG_ANSWER
TESTS
4
46
1,536,000
n, m = map(int, input().split()) a = list(map(int, input().split())) d = [j for j in range(1, len(a) + 1)] while len(a) > 1: if m >= a[0]: del a[0], d[0] elif m < a[0]: a[0] -= m a[0], a[-1], d[0], d[-1] = a[-1], a[0], d[-1], d[0] print(d[0])
Title: Jzzhu and Children Time Limit: None seconds Memory Limit: None megabytes Problem Description: There are *n* children in Jzzhu's school. Jzzhu is going to give some candies to them. Let's number all the children from 1 to *n*. The *i*-th child wants to get at least *a**i* candies. Jzzhu asks children to line up. Initially, the *i*-th child stands at the *i*-th place of the line. Then Jzzhu start distribution of the candies. He follows the algorithm: 1. Give *m* candies to the first child of the line. 1. If this child still haven't got enough candies, then the child goes to the end of the line, else the child go home. 1. Repeat the first two steps while the line is not empty. Consider all the children in the order they go home. Jzzhu wants to know, which child will be the last in this order? Input Specification: The first line contains two integers *n*,<=*m* (1<=≤<=*n*<=≤<=100; 1<=≤<=*m*<=≤<=100). The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=100). Output Specification: Output a single integer, representing the number of the last child. Demo Input: ['5 2\n1 3 1 4 2\n', '6 4\n1 1 2 2 3 3\n'] Demo Output: ['4\n', '6\n'] Note: Let's consider the first sample. Firstly child 1 gets 2 candies and go home. Then child 2 gets 2 candies and go to the end of the line. Currently the line looks like [3, 4, 5, 2] (indices of the children in order of the line). Then child 3 gets 2 candies and go home, and then child 4 gets 2 candies and goes to the end of the line. Currently the line looks like [5, 2, 4]. Then child 5 gets 2 candies and goes home. Then child 2 gets two candies and goes home, and finally child 4 gets 2 candies and goes home. Child 4 is the last one who goes home.
```python n, m = map(int, input().split()) a = list(map(int, input().split())) d = [j for j in range(1, len(a) + 1)] while len(a) > 1: if m >= a[0]: del a[0], d[0] elif m < a[0]: a[0] -= m a[0], a[-1], d[0], d[-1] = a[-1], a[0], d[-1], d[0] print(d[0]) ```
0
32
B
Borze
PROGRAMMING
800
[ "expression parsing", "implementation" ]
B. Borze
2
256
Ternary numeric notation is quite popular in Berland. To telegraph the ternary number the Borze alphabet is used. Digit 0 is transmitted as «.», 1 as «-.» and 2 as «--». You are to decode the Borze code, i.e. to find out the ternary number given its representation in Borze alphabet.
The first line contains a number in Borze code. The length of the string is between 1 and 200 characters. It's guaranteed that the given string is a valid Borze code of some ternary number (this number can have leading zeroes).
Output the decoded ternary number. It can have leading zeroes.
[ ".-.--\n", "--.\n", "-..-.--\n" ]
[ "012", "20", "1012" ]
none
1,000
[ { "input": ".-.--", "output": "012" }, { "input": "--.", "output": "20" }, { "input": "-..-.--", "output": "1012" }, { "input": "---..", "output": "210" }, { "input": "..--.---..", "output": "0020210" }, { "input": "-.....----.", "output": "10000220" }, { "input": ".", "output": "0" }, { "input": "-.", "output": "1" }, { "input": "--", "output": "2" }, { "input": "..", "output": "00" }, { "input": "--.", "output": "20" }, { "input": ".--.", "output": "020" }, { "input": ".-.-..", "output": "0110" }, { "input": "----.-.", "output": "2201" }, { "input": "-..--.-.", "output": "10201" }, { "input": "..--..--.", "output": "0020020" }, { "input": "-.-.---.--..-..-.-.-..-..-.--.", "output": "112120010111010120" }, { "input": "---.-.-.------..-..-..-..-.-..-.--.-.-..-.-.-----..-.-.", "output": "21112220010101011012011011221011" }, { "input": "-.-..--.-.-.-.-.-..-.-.-.---------.--.---..--...--.-----.-.-.-...--.-.-.---.------.--..-.--.-----.-...-..------", "output": "11020111110111222212021020002022111100201121222020012022110010222" }, { "input": "-.-..-.--.---..---.-..---.-...-.-.----..-.---.-.---..-.--.---.-.-------.---.--....----.-.---.---.---.----.-----..---.-.-.-.-----.--.-------.-..", "output": "110120210211021100112200121121012021122212120000220121212122022102111122120222110" }, { "input": ".-..-.-.---.-----.--.---...-.--.-.-....-..", "output": "01011212212021001201100010" }, { "input": ".------.-.---..--...-..-..-.-.-.--.--.-..-.--...-.-.---.-.-.------..--..-.---..----.-..-.--.---.-.----.-.---...-.-.-.-----.-.-.---.---.-.....-.-...-----.-...-.---.-..-.-----.--...---.-.-..-.--.-.---..", "output": "022201210200010101112020101200011211122200200121022010120211220121001112211121211000011002211001211012212000211101201210" }, { "input": ".-.--.---.-----.-.-----.-.-..-----..-..----..--.-.--.----..---.---..-.-.-----..-------.----..----.-..---...-----..-..-----...-..-.-.-----....---..---..-.-----...-.--...--.-.---.-.-.-.-.-...---..----.", "output": "01202122112211102210102200201202200212101122102221220022010210022101022100101122100021021012210012000201211111100210220" }, { "input": "..-.-.-.---.-.-.-..-.-..-.-.---.-------.---..-----.---....-.---.--.--.-.---.---------.-..---.-.-.--..---.---.-.---.-.-..-.-..-.-.-.----.--.-....--------.-.---..----.------.-.-.--.--.-----.-----.----", "output": "0011121111011011212221210221210001212020121222211021112002121121110110111220201000222201210220222011202022122122" }, { "input": "-..-------.------.-..--.-.-..--.-.-..-----..-.-.-..-..-..--.---..-----..---..-..--.-..-.-.---...-.....-------.---.-----.-...-.-...-.-.---.---.-----.--.--...-.--..-.-..-...-.-.-.-.---..---.-..-.-.-.-..", "output": "102221222010201102011022101110101020210221021010201011210010000222121221100110011212122120200012001101001111210211011110" }, { "input": ".-.----.-.--..-.-.-.-..----..-.-...--.-.---.---.-------..-.--..-......--.------.--.----.--...-.--.--..-----..-.....--.--.-.-.------..--------.----------..-.---.----.---.-..--..-.....-..------.--.", "output": "012201200111102200110020121212221012001000002022202022020001202002210100002020112220022220222220012122021102001000010222020" }, { "input": "------.-----.-....--.-.----.-.---.-.-..---.-.---.-----..-...-.-.---..-.-.-..-.-.-...-.-.-.----..--.------.----.-..-.--...-.-------...-.-..-.-.--.--.---..--..--------.--.-.-.---.-.-.-...----.--..-.--..", "output": "222022110002012201211102112122101001121011101110011122002022202201012000122210011011202021020022220201121111002202001200" }, { "input": "-.---...----...--.--...-.--.----", "output": "121002200020200012022" }, { "input": "--.--.--.---.--.-.---.-.-..-..--.-..---.-.....-..---.-----.--...-.-.-------.-.--.-.----.-..-.------.", "output": "202020212012111010201021100001021221200011222112012201012220" } ]
1,628,750,587
2,147,483,647
Python 3
OK
TESTS
30
156
6,758,400
x=input() x=x.replace('--','2',x.count('--')) x=x.replace('-.','1',x.count('-.')) x=x.replace('.','0',x.count('.')) print(x)
Title: Borze Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: Ternary numeric notation is quite popular in Berland. To telegraph the ternary number the Borze alphabet is used. Digit 0 is transmitted as «.», 1 as «-.» and 2 as «--». You are to decode the Borze code, i.e. to find out the ternary number given its representation in Borze alphabet. Input Specification: The first line contains a number in Borze code. The length of the string is between 1 and 200 characters. It's guaranteed that the given string is a valid Borze code of some ternary number (this number can have leading zeroes). Output Specification: Output the decoded ternary number. It can have leading zeroes. Demo Input: ['.-.--\n', '--.\n', '-..-.--\n'] Demo Output: ['012', '20', '1012'] Note: none
```python x=input() x=x.replace('--','2',x.count('--')) x=x.replace('-.','1',x.count('-.')) x=x.replace('.','0',x.count('.')) print(x) ```
3.948411
760
B
Frodo and pillows
PROGRAMMING
1,500
[ "binary search", "greedy" ]
null
null
*n* hobbits are planning to spend the night at Frodo's house. Frodo has *n* beds standing in a row and *m* pillows (*n*<=≤<=*m*). Each hobbit needs a bed and at least one pillow to sleep, however, everyone wants as many pillows as possible. Of course, it's not always possible to share pillows equally, but any hobbit gets hurt if he has at least two pillows less than some of his neighbors have. Frodo will sleep on the *k*-th bed in the row. What is the maximum number of pillows he can have so that every hobbit has at least one pillow, every pillow is given to some hobbit and no one is hurt?
The only line contain three integers *n*, *m* and *k* (1<=≤<=*n*<=≤<=*m*<=≤<=109, 1<=≤<=*k*<=≤<=*n*) — the number of hobbits, the number of pillows and the number of Frodo's bed.
Print single integer — the maximum number of pillows Frodo can have so that no one is hurt.
[ "4 6 2\n", "3 10 3\n", "3 6 1\n" ]
[ "2\n", "4\n", "3\n" ]
In the first example Frodo can have at most two pillows. In this case, he can give two pillows to the hobbit on the first bed, and one pillow to each of the hobbits on the third and the fourth beds. In the second example Frodo can take at most four pillows, giving three pillows to each of the others. In the third example Frodo can take three pillows, giving two pillows to the hobbit in the middle and one pillow to the hobbit on the third bed.
1,000
[ { "input": "4 6 2", "output": "2" }, { "input": "3 10 3", "output": "4" }, { "input": "3 6 1", "output": "3" }, { "input": "3 3 3", "output": "1" }, { "input": "1 1 1", "output": "1" }, { "input": "1 1000000000 1", "output": "1000000000" }, { "input": "100 1000000000 20", "output": "10000034" }, { "input": "1000 1000 994", "output": "1" }, { "input": "100000000 200000000 54345", "output": "10001" }, { "input": "1000000000 1000000000 1", "output": "1" }, { "input": "1000000000 1000000000 1000000000", "output": "1" }, { "input": "1000000000 1000000000 500000000", "output": "1" }, { "input": "1000 1000 3", "output": "1" }, { "input": "100000000 200020000 54345", "output": "10001" }, { "input": "100 108037 18", "output": "1115" }, { "input": "100000000 200020001 54345", "output": "10002" }, { "input": "200 6585 2", "output": "112" }, { "input": "30000 30593 5980", "output": "25" }, { "input": "40000 42107 10555", "output": "46" }, { "input": "50003 50921 192", "output": "31" }, { "input": "100000 113611 24910", "output": "117" }, { "input": "1000000 483447163 83104", "output": "21965" }, { "input": "10000000 10021505 600076", "output": "147" }, { "input": "100000000 102144805 2091145", "output": "1465" }, { "input": "1000000000 1000000000 481982093", "output": "1" }, { "input": "100 999973325 5", "output": "9999778" }, { "input": "200 999999109 61", "output": "5000053" }, { "input": "30000 999999384 5488", "output": "43849" }, { "input": "40000 999997662 8976", "output": "38038" }, { "input": "50003 999999649 405", "output": "44320" }, { "input": "100000 999899822 30885", "output": "31624" }, { "input": "1000000 914032367 528790", "output": "30217" }, { "input": "10000000 999617465 673112", "output": "31459" }, { "input": "100000000 993180275 362942", "output": "29887" }, { "input": "1000000000 1000000000 331431458", "output": "1" }, { "input": "100 10466 89", "output": "144" }, { "input": "200 5701 172", "output": "84" }, { "input": "30000 36932 29126", "output": "84" }, { "input": "40000 40771 22564", "output": "28" }, { "input": "50003 51705 49898", "output": "42" }, { "input": "100000 149408 74707", "output": "223" }, { "input": "1000000 194818222 998601", "output": "18389" }, { "input": "10000000 10748901 8882081", "output": "866" }, { "input": "100000000 106296029 98572386", "output": "2510" }, { "input": "1000000000 1000000000 193988157", "output": "1" }, { "input": "100 999981057 92", "output": "9999852" }, { "input": "200 999989691 199", "output": "5000046" }, { "input": "30000 999995411 24509", "output": "43846" }, { "input": "40000 999998466 30827", "output": "37930" }, { "input": "50003 999997857 48387", "output": "43163" }, { "input": "100000 999731886 98615", "output": "43371" }, { "input": "1000000 523220797 654341", "output": "22853" }, { "input": "10000000 999922591 8157724", "output": "31464" }, { "input": "100000000 999834114 93836827", "output": "29998" }, { "input": "1000000000 1000000000 912549504", "output": "1" }, { "input": "1000 97654978 234", "output": "97976" }, { "input": "1000 97654977 234", "output": "97975" }, { "input": "1000234 97653889 1", "output": "13903" }, { "input": "1000234 97653890 1", "output": "13904" }, { "input": "3450234 97656670 3000000", "output": "9707" }, { "input": "3450234 97656669 3000000", "output": "9706" }, { "input": "3 1000000000 2", "output": "333333334" }, { "input": "2 1000000000 1", "output": "500000000" }, { "input": "2 1000000000 2", "output": "500000000" }, { "input": "3 1000000000 1", "output": "333333334" }, { "input": "3 1000000000 3", "output": "333333334" }, { "input": "2 999999999 1", "output": "500000000" }, { "input": "2 999999999 2", "output": "500000000" }, { "input": "1 999999999 1", "output": "999999999" } ]
1,624,372,490
2,147,483,647
PyPy 3
OK
TESTS
69
888
1,638,400
n,m,k = list(map(int, input().split(' '))) extra = m - n maxi = 1 if n == 1: print(m) elif n == 2: if m%2 == 0: print(m//2) else: print(m//2 +1) else: for i in range(extra): stepPillows = 1 + min(k-1,i) + min(n-k,i) if extra >= stepPillows: extra -= stepPillows maxi += 1 else: break print(maxi)
Title: Frodo and pillows Time Limit: None seconds Memory Limit: None megabytes Problem Description: *n* hobbits are planning to spend the night at Frodo's house. Frodo has *n* beds standing in a row and *m* pillows (*n*<=≤<=*m*). Each hobbit needs a bed and at least one pillow to sleep, however, everyone wants as many pillows as possible. Of course, it's not always possible to share pillows equally, but any hobbit gets hurt if he has at least two pillows less than some of his neighbors have. Frodo will sleep on the *k*-th bed in the row. What is the maximum number of pillows he can have so that every hobbit has at least one pillow, every pillow is given to some hobbit and no one is hurt? Input Specification: The only line contain three integers *n*, *m* and *k* (1<=≤<=*n*<=≤<=*m*<=≤<=109, 1<=≤<=*k*<=≤<=*n*) — the number of hobbits, the number of pillows and the number of Frodo's bed. Output Specification: Print single integer — the maximum number of pillows Frodo can have so that no one is hurt. Demo Input: ['4 6 2\n', '3 10 3\n', '3 6 1\n'] Demo Output: ['2\n', '4\n', '3\n'] Note: In the first example Frodo can have at most two pillows. In this case, he can give two pillows to the hobbit on the first bed, and one pillow to each of the hobbits on the third and the fourth beds. In the second example Frodo can take at most four pillows, giving three pillows to each of the others. In the third example Frodo can take three pillows, giving two pillows to the hobbit in the middle and one pillow to the hobbit on the third bed.
```python n,m,k = list(map(int, input().split(' '))) extra = m - n maxi = 1 if n == 1: print(m) elif n == 2: if m%2 == 0: print(m//2) else: print(m//2 +1) else: for i in range(extra): stepPillows = 1 + min(k-1,i) + min(n-k,i) if extra >= stepPillows: extra -= stepPillows maxi += 1 else: break print(maxi) ```
3
60
B
Serial Time!
PROGRAMMING
1,400
[ "dfs and similar", "dsu" ]
B. Serial Time!
2
256
The Cereal Guy's friend Serial Guy likes to watch soap operas. An episode is about to start, and he hasn't washed his plate yet. But he decided to at least put in under the tap to be filled with water. The plate can be represented by a parallelepiped *k*<=×<=*n*<=×<=*m*, that is, it has *k* layers (the first layer is the upper one), each of which is a rectangle *n*<=×<=*m* with empty squares ('.') and obstacles ('#'). The water can only be present in the empty squares. The tap is positioned above the square (*x*,<=*y*) of the first layer, it is guaranteed that this square is empty. Every minute a cubical unit of water falls into the plate. Find out in how many minutes the Serial Guy should unglue himself from the soap opera and turn the water off for it not to overfill the plate. That is, you should find the moment of time when the plate is absolutely full and is going to be overfilled in the next moment. Note: the water fills all the area within reach (see sample 4). Water flows in each of the 6 directions, through faces of 1<=×<=1<=×<=1 cubes.
The first line contains three numbers *k*, *n*, *m* (1<=≤<=*k*,<=*n*,<=*m*<=≤<=10) which are the sizes of the plate. Then follow *k* rectangles consisting of *n* lines each containing *m* characters '.' or '#', which represents the "layers" of the plate in the order from the top to the bottom. The rectangles are separated by empty lines (see the samples). The last line contains *x* and *y* (1<=≤<=*x*<=≤<=*n*,<=1<=≤<=*y*<=≤<=*m*) which are the tap's coordinates. *x* is the number of the line and *y* is the number of the column. Lines of each layer are numbered from left to right by the integers from 1 to *n*, columns of each layer are numbered from top to bottom by the integers from 1 to *m*.
The answer should contain a single number, showing in how many minutes the plate will be filled.
[ "1 1 1\n\n.\n\n1 1\n", "2 1 1\n\n.\n\n#\n\n1 1\n", "2 2 2\n\n.#\n##\n\n..\n..\n\n1 1\n", "3 2 2\n\n#.\n##\n\n#.\n.#\n\n..\n..\n\n1 2\n", "3 3 3\n\n.#.\n###\n##.\n\n.##\n###\n##.\n\n...\n...\n...\n\n1 1\n" ]
[ "1\n", "1\n", "5\n", "7\n", "13\n" ]
none
1,000
[ { "input": "1 1 1\n\n.\n\n1 1", "output": "1" }, { "input": "2 1 1\n\n.\n\n#\n\n1 1", "output": "1" }, { "input": "2 2 2\n\n.#\n##\n\n..\n..\n\n1 1", "output": "5" }, { "input": "3 2 2\n\n#.\n##\n\n#.\n.#\n\n..\n..\n\n1 2", "output": "7" }, { "input": "3 3 3\n\n.#.\n###\n##.\n\n.##\n###\n##.\n\n...\n...\n...\n\n1 1", "output": "13" }, { "input": "2 2 2\n\n#.\n..\n\n.#\n#.\n\n2 1", "output": "4" }, { "input": "4 7 8\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\n3 4", "output": "224" }, { "input": "6 5 4\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\n5 1", "output": "1" }, { "input": "8 2 6\n\n#.####\n######\n\n......\n......\n\n#.####\n######\n\n......\n......\n\n#.####\n######\n\n......\n......\n\n#.####\n######\n\n......\n......\n\n1 2", "output": "52" }, { "input": "9 1 9\n\n.........\n\n#####.###\n\n.........\n\n#####.###\n\n.........\n\n#####.###\n\n.........\n\n#####.###\n\n.........\n\n1 6", "output": "49" }, { "input": "6 8 4\n\n.###\n.#..\n.#..\n####\n....\n.##.\n..#.\n...#\n\n....\n##.#\n....\n....\n##..\n#.##\n#.#.\n#..#\n\n..##\n####\n#...\n..##\n###.\n#..#\n..##\n##..\n\n.##.\n##..\n#.#.\n##..\n####\n####\n.#.#\n###.\n\n#.##\n..#.\n...#\n#.##\n##.#\n##..\n####\n###.\n\n.#.#\n#.#.\n#.##\n#.##\n....\n#.##\n..##\n.##.\n\n6 4", "output": "88" }, { "input": "8 1 8\n\n........\n\n........\n\n........\n\n........\n\n........\n\n........\n\n........\n\n........\n\n1 3", "output": "64" }, { "input": "1 8 6\n\n######\n######\n.#####\n######\n######\n######\n######\n######\n\n3 1", "output": "1" }, { "input": "6 1 9\n\n##.######\n\n.........\n\n##.######\n\n.........\n\n##.######\n\n.........\n\n1 3", "output": "30" }, { "input": "1 1 10\n\n..........\n\n1 6", "output": "10" }, { "input": "5 2 8\n\n.##..#..\n.#.....#\n\n....##..\n#..###.#\n\n#..#.#..\n.#..#...\n\n###.#..#\n#......#\n\n#..#####\n##.....#\n\n1 7", "output": "45" }, { "input": "9 2 1\n\n.\n.\n\n.\n.\n\n.\n.\n\n.\n.\n\n.\n.\n\n.\n.\n\n.\n.\n\n.\n.\n\n.\n.\n\n1 1", "output": "18" }, { "input": "5 8 2\n\n##\n##\n##\n#.\n##\n##\n##\n##\n\n##\n##\n##\n##\n##\n##\n##\n##\n\n##\n##\n##\n##\n##\n##\n##\n##\n\n##\n##\n##\n##\n##\n##\n##\n##\n\n##\n##\n##\n##\n##\n##\n##\n##\n\n4 2", "output": "1" }, { "input": "6 10 2\n\n##\n#.\n##\n##\n##\n##\n##\n##\n##\n##\n\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n\n##\n#.\n##\n##\n##\n##\n##\n##\n##\n##\n\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n\n##\n#.\n##\n##\n##\n##\n##\n##\n##\n##\n\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n\n2 2", "output": "63" }, { "input": "8 6 2\n\n..\n..\n..\n..\n..\n..\n\n##\n##\n.#\n##\n##\n##\n\n..\n..\n..\n..\n..\n..\n\n##\n##\n.#\n##\n##\n##\n\n..\n..\n..\n..\n..\n..\n\n##\n##\n.#\n##\n##\n##\n\n..\n..\n..\n..\n..\n..\n\n##\n##\n.#\n##\n##\n##\n\n3 1", "output": "52" }, { "input": "4 1 3\n\n...\n\n...\n\n...\n\n...\n\n1 1", "output": "12" }, { "input": "4 6 2\n\n##\n##\n##\n##\n.#\n##\n\n##\n##\n##\n##\n##\n##\n\n##\n##\n##\n##\n##\n##\n\n##\n##\n##\n##\n##\n##\n\n5 1", "output": "1" }, { "input": "2 9 2\n\n##\n##\n##\n##\n.#\n##\n##\n##\n##\n\n..\n..\n..\n..\n..\n..\n..\n..\n..\n\n5 1", "output": "19" }, { "input": "10 6 5\n\n.....\n.....\n.....\n.....\n.....\n.....\n\n#####\n###.#\n#####\n#####\n#####\n#####\n\n.....\n.....\n.....\n.....\n.....\n.....\n\n#####\n###.#\n#####\n#####\n#####\n#####\n\n.....\n.....\n.....\n.....\n.....\n.....\n\n#####\n###.#\n#####\n#####\n#####\n#####\n\n.....\n.....\n.....\n.....\n.....\n.....\n\n#####\n###.#\n#####\n#####\n#####\n#####\n\n.....\n.....\n.....\n.....\n.....\n.....\n\n#####\n###.#\n#####\n#####\n#####\n#####\n\n2 4", "output": "155" }, { "input": "2 3 6\n\n......\n#..#..\n##.#.#\n\n#.##..\n.....#\n##..##\n\n1 3", "output": "22" }, { "input": "8 5 6\n\n######\n######\n######\n###.##\n######\n\n######\n######\n######\n######\n######\n\n######\n######\n######\n######\n######\n\n######\n######\n######\n######\n######\n\n######\n######\n######\n######\n######\n\n######\n######\n######\n######\n######\n\n######\n######\n######\n######\n######\n\n######\n######\n######\n######\n######\n\n4 4", "output": "1" }, { "input": "1 3 10\n\n##########\n####.#####\n##########\n\n2 5", "output": "1" }, { "input": "8 3 3\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\n3 3", "output": "40" }, { "input": "5 1 4\n\n#...\n\n####\n\n#.##\n\n.###\n\n###.\n\n1 4", "output": "3" }, { "input": "9 2 2\n\n##\n..\n\n##\n##\n\n#.\n#.\n\n..\n..\n\n##\n..\n\n..\n.#\n\n#.\n#.\n\n.#\n..\n\n#.\n.#\n\n2 1", "output": "2" }, { "input": "1 6 2\n\n##\n..\n##\n.#\n##\n#.\n\n6 2", "output": "1" }, { "input": "5 9 2\n\n##\n##\n##\n#.\n.#\n.#\n..\n##\n#.\n\n##\n..\n##\n##\n#.\n#.\n.#\n#.\n#.\n\n#.\n.#\n##\n.#\n..\n##\n##\n#.\n..\n\n#.\n..\n.#\n#.\n..\n#.\n..\n..\n##\n\n.#\n##\n..\n.#\n#.\n#.\n.#\n##\n##\n\n4 2", "output": "1" }, { "input": "5 8 7\n\n.#.#...\n##.#.##\n...#..#\n#####..\n......#\n..###..\n#.#..#.\n.##..#.\n\n##.....\n.##.#..\n.##.###\n...##..\n.#.###.\n##.#..#\n##..#.#\n.##....\n\n#.#...#\n##.....\n...###.\n...##..\n..#.###\n.#.#...\n.#.#..#\n..###..\n\n#..#...\n.####..\n###.#.#\n#..#.##\n....#..\n.#.#.##\n#.#.###\n.#..###\n\n..#.#.#\n##....#\n.#.####\n#.#.##.\n.#..##.\n##..#.#\n.##.##.\n...###.\n\n4 7", "output": "132" }, { "input": "4 3 2\n\n#.\n#.\n##\n\n.#\n.#\n##\n\n..\n#.\n##\n\n#.\n..\n.#\n\n1 2", "output": "2" }, { "input": "4 10 10\n\n..........\n..........\n..........\n..........\n..........\n..........\n..........\n..........\n..........\n..........\n\n..........\n..........\n..........\n..........\n..........\n..........\n..........\n..........\n..........\n..........\n\n..........\n..........\n..........\n..........\n..........\n..........\n..........\n..........\n..........\n..........\n\n..........\n..........\n..........\n..........\n..........\n..........\n..........\n..........\n..........\n..........\n\n8 1", "output": "400" }, { "input": "4 10 10\n\n##########\n##########\n##########\n##########\n##########\n##########\n#########.\n##########\n##########\n##########\n\n##########\n##########\n##########\n##########\n##########\n##########\n##########\n##########\n##########\n##########\n\n##########\n##########\n##########\n##########\n##########\n##########\n##########\n##########\n##########\n##########\n\n##########\n##########\n##########\n##########\n##########\n##########\n##########\n##########\n##########\n##########\n\n7 10", "output": "1" }, { "input": "3 10 10\n\n#######.##\n##########\n##########\n##########\n##########\n##########\n##########\n##########\n##########\n##########\n\n..........\n..........\n..........\n..........\n..........\n..........\n..........\n..........\n..........\n..........\n\n#######.##\n##########\n##########\n##########\n##########\n##########\n##########\n##########\n##########\n##########\n\n1 8", "output": "102" }, { "input": "2 10 10\n\n#..#...#..\n###..#..##\n..#..#..#.\n#..#.#...#\n#####...#.\n#.####..#.\n###..##.##\n.###..#...\n##..##.##.\n..#.#.####\n\n..##..#.#.\n.##....#..\n..#.#.##..\n#.####....\n##..##.#..\n######...#\n..#...###.\n####.###.#\n#...##.#..\n##.#####.#\n\n6 7", "output": "57" } ]
1,384,283,307
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
0
30
307,200
a, b, c = map(int, input().split()) t = [[[0] * c for k in range(b)] for i in range(a)] for i in range(a): input() for j in range(b): for k, q in enumerate(input()): if q == '#': t[i][j][k] = 1 q = [(i, j, k) for i in range(-1, 2) for j in range(-1, 2) for k in range(-1, 2)] q.remove((0, 0, 0)) s = 0 def f(x, y, z): global s p = [(x + i, y + j, z + k) for i, j, k in q] p = [(i, j, k) for i, j, k in p if -1 < i < a and -1 < j < b and -1 < k < c and t[i][j][k] == 0] for i, j, k in p: t[i][j][k] = 2 for i, j, k in p: f(i, j, k) s += len(p) input() y, z = map(int, input().split()) f(0, y - 1, z - 1) print(s)
Title: Serial Time! Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: The Cereal Guy's friend Serial Guy likes to watch soap operas. An episode is about to start, and he hasn't washed his plate yet. But he decided to at least put in under the tap to be filled with water. The plate can be represented by a parallelepiped *k*<=×<=*n*<=×<=*m*, that is, it has *k* layers (the first layer is the upper one), each of which is a rectangle *n*<=×<=*m* with empty squares ('.') and obstacles ('#'). The water can only be present in the empty squares. The tap is positioned above the square (*x*,<=*y*) of the first layer, it is guaranteed that this square is empty. Every minute a cubical unit of water falls into the plate. Find out in how many minutes the Serial Guy should unglue himself from the soap opera and turn the water off for it not to overfill the plate. That is, you should find the moment of time when the plate is absolutely full and is going to be overfilled in the next moment. Note: the water fills all the area within reach (see sample 4). Water flows in each of the 6 directions, through faces of 1<=×<=1<=×<=1 cubes. Input Specification: The first line contains three numbers *k*, *n*, *m* (1<=≤<=*k*,<=*n*,<=*m*<=≤<=10) which are the sizes of the plate. Then follow *k* rectangles consisting of *n* lines each containing *m* characters '.' or '#', which represents the "layers" of the plate in the order from the top to the bottom. The rectangles are separated by empty lines (see the samples). The last line contains *x* and *y* (1<=≤<=*x*<=≤<=*n*,<=1<=≤<=*y*<=≤<=*m*) which are the tap's coordinates. *x* is the number of the line and *y* is the number of the column. Lines of each layer are numbered from left to right by the integers from 1 to *n*, columns of each layer are numbered from top to bottom by the integers from 1 to *m*. Output Specification: The answer should contain a single number, showing in how many minutes the plate will be filled. Demo Input: ['1 1 1\n\n.\n\n1 1\n', '2 1 1\n\n.\n\n#\n\n1 1\n', '2 2 2\n\n.#\n##\n\n..\n..\n\n1 1\n', '3 2 2\n\n#.\n##\n\n#.\n.#\n\n..\n..\n\n1 2\n', '3 3 3\n\n.#.\n###\n##.\n\n.##\n###\n##.\n\n...\n...\n...\n\n1 1\n'] Demo Output: ['1\n', '1\n', '5\n', '7\n', '13\n'] Note: none
```python a, b, c = map(int, input().split()) t = [[[0] * c for k in range(b)] for i in range(a)] for i in range(a): input() for j in range(b): for k, q in enumerate(input()): if q == '#': t[i][j][k] = 1 q = [(i, j, k) for i in range(-1, 2) for j in range(-1, 2) for k in range(-1, 2)] q.remove((0, 0, 0)) s = 0 def f(x, y, z): global s p = [(x + i, y + j, z + k) for i, j, k in q] p = [(i, j, k) for i, j, k in p if -1 < i < a and -1 < j < b and -1 < k < c and t[i][j][k] == 0] for i, j, k in p: t[i][j][k] = 2 for i, j, k in p: f(i, j, k) s += len(p) input() y, z = map(int, input().split()) f(0, y - 1, z - 1) print(s) ```
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,647,581,103
2,147,483,647
Python 3
RUNTIME_ERROR
TESTS
9
62
0
ber = list(input()) bir = list(input()) j = len(ber)-1 for i in range(j+1): if ber[i] != bir[j-i]: print('NO') exit() print('YES')
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 ber = list(input()) bir = list(input()) j = len(ber)-1 for i in range(j+1): if ber[i] != bir[j-i]: print('NO') exit() print('YES') ```
-1
25
D
Roads not only in Berland
PROGRAMMING
1,900
[ "dsu", "graphs", "trees" ]
D. Roads not only in Berland
2
256
Berland Government decided to improve relations with neighboring countries. First of all, it was decided to build new roads so that from each city of Berland and neighboring countries it became possible to reach all the others. There are *n* cities in Berland and neighboring countries in total and exactly *n*<=-<=1 two-way roads. Because of the recent financial crisis, the Berland Government is strongly pressed for money, so to build a new road it has to close some of the existing ones. Every day it is possible to close one existing road and immediately build a new one. Your task is to determine how many days would be needed to rebuild roads so that from each city it became possible to reach all the others, and to draw a plan of closure of old roads and building of new ones.
The first line contains integer *n* (2<=≤<=*n*<=≤<=1000) — amount of cities in Berland and neighboring countries. Next *n*<=-<=1 lines contain the description of roads. Each road is described by two space-separated integers *a**i*, *b**i* (1<=≤<=*a**i*,<=*b**i*<=≤<=*n*,<=*a**i*<=≠<=*b**i*) — pair of cities, which the road connects. It can't be more than one road between a pair of cities. No road connects the city with itself.
Output the answer, number *t* — what is the least amount of days needed to rebuild roads so that from each city it became possible to reach all the others. Then output *t* lines — the plan of closure of old roads and building of new ones. Each line should describe one day in the format i j u v — it means that road between cities i and j became closed and a new road between cities u and v is built. Cities are numbered from 1. If the answer is not unique, output any.
[ "2\n1 2\n", "7\n1 2\n2 3\n3 1\n4 5\n5 6\n6 7\n" ]
[ "0\n", "1\n3 1 3 7\n" ]
none
0
[ { "input": "2\n1 2", "output": "0" }, { "input": "7\n1 2\n2 3\n3 1\n4 5\n5 6\n6 7", "output": "1\n3 1 3 7" }, { "input": "3\n3 2\n1 2", "output": "0" }, { "input": "3\n3 1\n3 2", "output": "0" }, { "input": "4\n1 4\n3 1\n3 4", "output": "1\n3 4 2 4" }, { "input": "5\n4 1\n4 3\n5 3\n2 4", "output": "0" }, { "input": "6\n5 2\n5 3\n1 4\n3 1\n5 6", "output": "0" }, { "input": "10\n5 9\n8 5\n7 6\n7 9\n3 9\n2 1\n7 2\n3 6\n7 1", "output": "2\n3 6 1 4\n7 1 4 10" }, { "input": "21\n7 15\n13 1\n14 3\n4 10\n2 3\n16 18\n17 20\n16 20\n8 4\n3 12\n2 17\n13 11\n16 1\n13 2\n13 5\n8 9\n6 14\n3 17\n16 9\n13 8", "output": "3\n13 2 9 15\n3 17 15 19\n13 8 19 21" }, { "input": "39\n6 13\n15 39\n10 35\n31 28\n4 21\n12 39\n3 7\n3 13\n6 1\n5 14\n36 28\n12 15\n18 38\n30 29\n19 34\n36 16\n20 22\n8 13\n38 32\n26 39\n21 37\n1 7\n15 27\n12 26\n8 3\n6 14\n29 2\n25 23\n32 21\n5 16\n32 25\n6 8\n13 10\n23 30\n34 37\n29 33\n28 14\n36 5", "output": "7\n12 15 9 11\n1 7 11 17\n12 26 17 22\n8 3 22 24\n6 8 24 27\n28 14 27 33\n36 5 33 35" }, { "input": "60\n17 34\n46 22\n50 44\n46 33\n41 21\n31 33\n48 6\n38 19\n35 60\n2 24\n49 29\n7 53\n34 1\n19 55\n32 1\n31 42\n27 28\n4 53\n6 50\n21 34\n1 10\n12 36\n54 8\n16 13\n51 43\n45 51\n54 20\n13 53\n34 33\n49 33\n51 11\n59 34\n15 5\n59 28\n30 39\n13 30\n58 4\n34 14\n3 9\n19 34\n4 18\n26 48\n56 54\n3 43\n57 25\n3 41\n35 3\n48 44\n19 13\n54 1\n23 31\n59 47\n5 1\n46 40\n6 26\n20 25\n37 5\n17 24\n20 52", "output": "2\n48 44 36 44\n6 26 44 52" } ]
1,646,053,214
2,147,483,647
PyPy 3
WRONG_ANSWER
TESTS
7
154
102,400
from collections import defaultdict def main(): n = int(input()) edges = list() for i in range(n-1): u, v = map(int, input().split(' ')) edges.append([u, v]) def find(a): if p[a] != a: p[a] = find(p[a]) return p[a] def union(a, b): a = find(a) b = find(b) if a == b: return if sz[a] > sz[b]: p[b] = a sz[a] += sz[b] else: p[a] = b sz[b] += sz[a] p = list(range(n + 1)) sz = [1] * (n + 1) for u, v in edges: union(u, v) u, v = edges[0] res = list() for i in range(1, n + 1): if find(i) != find(u): res.append([u, v, u, i]) union(u, i) print(len(res)) for item in res: print(*item) main()
Title: Roads not only in Berland Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: Berland Government decided to improve relations with neighboring countries. First of all, it was decided to build new roads so that from each city of Berland and neighboring countries it became possible to reach all the others. There are *n* cities in Berland and neighboring countries in total and exactly *n*<=-<=1 two-way roads. Because of the recent financial crisis, the Berland Government is strongly pressed for money, so to build a new road it has to close some of the existing ones. Every day it is possible to close one existing road and immediately build a new one. Your task is to determine how many days would be needed to rebuild roads so that from each city it became possible to reach all the others, and to draw a plan of closure of old roads and building of new ones. Input Specification: The first line contains integer *n* (2<=≤<=*n*<=≤<=1000) — amount of cities in Berland and neighboring countries. Next *n*<=-<=1 lines contain the description of roads. Each road is described by two space-separated integers *a**i*, *b**i* (1<=≤<=*a**i*,<=*b**i*<=≤<=*n*,<=*a**i*<=≠<=*b**i*) — pair of cities, which the road connects. It can't be more than one road between a pair of cities. No road connects the city with itself. Output Specification: Output the answer, number *t* — what is the least amount of days needed to rebuild roads so that from each city it became possible to reach all the others. Then output *t* lines — the plan of closure of old roads and building of new ones. Each line should describe one day in the format i j u v — it means that road between cities i and j became closed and a new road between cities u and v is built. Cities are numbered from 1. If the answer is not unique, output any. Demo Input: ['2\n1 2\n', '7\n1 2\n2 3\n3 1\n4 5\n5 6\n6 7\n'] Demo Output: ['0\n', '1\n3 1 3 7\n'] Note: none
```python from collections import defaultdict def main(): n = int(input()) edges = list() for i in range(n-1): u, v = map(int, input().split(' ')) edges.append([u, v]) def find(a): if p[a] != a: p[a] = find(p[a]) return p[a] def union(a, b): a = find(a) b = find(b) if a == b: return if sz[a] > sz[b]: p[b] = a sz[a] += sz[b] else: p[a] = b sz[b] += sz[a] p = list(range(n + 1)) sz = [1] * (n + 1) for u, v in edges: union(u, v) u, v = edges[0] res = list() for i in range(1, n + 1): if find(i) != find(u): res.append([u, v, u, i]) union(u, i) print(len(res)) for item in res: print(*item) main() ```
0
745
A
Hongcow Learns the Cyclic Shift
PROGRAMMING
900
[ "implementation", "strings" ]
null
null
Hongcow is learning to spell! One day, his teacher gives him a word that he needs to learn to spell. Being a dutiful student, he immediately learns how to spell the word. Hongcow has decided to try to make new words from this one. He starts by taking the word he just learned how to spell, and moves the last character of the word to the beginning of the word. He calls this a cyclic shift. He can apply cyclic shift many times. For example, consecutively applying cyclic shift operation to the word "abracadabra" Hongcow will get words "aabracadabr", "raabracadab" and so on. Hongcow is now wondering how many distinct words he can generate by doing the cyclic shift arbitrarily many times. The initial string is also counted.
The first line of input will be a single string *s* (1<=≤<=|*s*|<=≤<=50), the word Hongcow initially learns how to spell. The string *s* consists only of lowercase English letters ('a'–'z').
Output a single integer equal to the number of distinct strings that Hongcow can obtain by applying the cyclic shift arbitrarily many times to the given string.
[ "abcd\n", "bbb\n", "yzyz\n" ]
[ "4\n", "1\n", "2\n" ]
For the first sample, the strings Hongcow can generate are "abcd", "dabc", "cdab", and "bcda". For the second sample, no matter how many times Hongcow does the cyclic shift, Hongcow can only generate "bbb". For the third sample, the two strings Hongcow can generate are "yzyz" and "zyzy".
500
[ { "input": "abcd", "output": "4" }, { "input": "bbb", "output": "1" }, { "input": "yzyz", "output": "2" }, { "input": "abcdefghijklmnopqrstuvwxyabcdefghijklmnopqrstuvwxy", "output": "25" }, { "input": "zclkjadoprqronzclkjadoprqronzclkjadoprqron", "output": "14" }, { "input": "zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz", "output": "1" }, { "input": "xyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxy", "output": "2" }, { "input": "y", "output": "1" }, { "input": "ervbfotfedpozygoumbmxeaqegouaqqzqerlykhmvxvvlcaos", "output": "49" }, { "input": "zyzzzyyzyyyzyyzyzyzyzyzzzyyyzzyzyyzzzzzyyyzzzzyzyy", "output": "50" }, { "input": "zzfyftdezzfyftdezzfyftdezzfyftdezzfyftdezzfyftde", "output": "8" }, { "input": "yehcqdlllqpuxdsaicyjjxiylahgxbygmsopjbxhtimzkashs", "output": "49" }, { "input": "yyyyzzzyzzzyzyzyzyyyyyzzyzyzyyyyyzyzyyyzyzzyyzzzz", "output": "49" }, { "input": "zkqcrhzlzsnwzkqcrhzlzsnwzkqcrhzlzsnwzkqcrhzlzsnw", "output": "12" }, { "input": "xxyxxyxxyxxyxxyxxyxxyxxyxxyxxyxxyxxyxxyxxyxxyxxy", "output": "3" }, { "input": "aaaaaaaaaaaaaaaaaaaaaaaabaaaaaaaaaaaaaaaaaaaaaaaab", "output": "25" }, { "input": "aabaaabaaabaaabaaabaaabaaabaaabaaabaaabaaabaaaba", "output": "4" }, { "input": "pqqpqqpqqpqqpqqpqqpqqpqqpqqpqqpqqppqppqppqppqppq", "output": "48" }, { "input": "zxkljaqzxkljaqzxkljaqzxkljaqzxrljaqzxkljaqzxkljaq", "output": "49" }, { "input": "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwx", "output": "50" }, { "input": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaz", "output": "50" }, { "input": "abcddcba", "output": "8" }, { "input": "aabaabaabaacaabaabaabaacaabaabaabaacaabaabaabaac", "output": "12" }, { "input": "aabaabcaabaabcdaabaabcaabaabcd", "output": "15" }, { "input": "ababaababaaababaababaaaababaababaaababaababaaaa", "output": "47" }, { "input": "ababaababaaababaababaaaababaababaaababaababaaa", "output": "23" }, { "input": "aaababaab", "output": "9" }, { "input": "aba", "output": "3" } ]
1,532,685,004
2,147,483,647
Python 3
OK
TESTS
28
124
0
s = input() ans = set() for l in range(len(s)): t = s[l:] + s[:l] ans.add(t) print(len(ans))
Title: Hongcow Learns the Cyclic Shift Time Limit: None seconds Memory Limit: None megabytes Problem Description: Hongcow is learning to spell! One day, his teacher gives him a word that he needs to learn to spell. Being a dutiful student, he immediately learns how to spell the word. Hongcow has decided to try to make new words from this one. He starts by taking the word he just learned how to spell, and moves the last character of the word to the beginning of the word. He calls this a cyclic shift. He can apply cyclic shift many times. For example, consecutively applying cyclic shift operation to the word "abracadabra" Hongcow will get words "aabracadabr", "raabracadab" and so on. Hongcow is now wondering how many distinct words he can generate by doing the cyclic shift arbitrarily many times. The initial string is also counted. Input Specification: The first line of input will be a single string *s* (1<=≤<=|*s*|<=≤<=50), the word Hongcow initially learns how to spell. The string *s* consists only of lowercase English letters ('a'–'z'). Output Specification: Output a single integer equal to the number of distinct strings that Hongcow can obtain by applying the cyclic shift arbitrarily many times to the given string. Demo Input: ['abcd\n', 'bbb\n', 'yzyz\n'] Demo Output: ['4\n', '1\n', '2\n'] Note: For the first sample, the strings Hongcow can generate are "abcd", "dabc", "cdab", and "bcda". For the second sample, no matter how many times Hongcow does the cyclic shift, Hongcow can only generate "bbb". For the third sample, the two strings Hongcow can generate are "yzyz" and "zyzy".
```python s = input() ans = set() for l in range(len(s)): t = s[l:] + s[:l] ans.add(t) print(len(ans)) ```
3
791
A
Bear and Big Brother
PROGRAMMING
800
[ "implementation" ]
null
null
Bear Limak wants to become the largest of bears, or at least to become larger than his brother Bob. Right now, Limak and Bob weigh *a* and *b* respectively. It's guaranteed that Limak's weight is smaller than or equal to his brother's weight. Limak eats a lot and his weight is tripled after every year, while Bob's weight is doubled after every year. After how many full years will Limak become strictly larger (strictly heavier) than Bob?
The only line of the input contains two integers *a* and *b* (1<=≤<=*a*<=≤<=*b*<=≤<=10) — the weight of Limak and the weight of Bob respectively.
Print one integer, denoting the integer number of years after which Limak will become strictly larger than Bob.
[ "4 7\n", "4 9\n", "1 1\n" ]
[ "2\n", "3\n", "1\n" ]
In the first sample, Limak weighs 4 and Bob weighs 7 initially. After one year their weights are 4·3 = 12 and 7·2 = 14 respectively (one weight is tripled while the other one is doubled). Limak isn't larger than Bob yet. After the second year weights are 36 and 28, so the first weight is greater than the second one. Limak became larger than Bob after two years so you should print 2. In the second sample, Limak's and Bob's weights in next years are: 12 and 18, then 36 and 36, and finally 108 and 72 (after three years). The answer is 3. Remember that Limak wants to be larger than Bob and he won't be satisfied with equal weights. In the third sample, Limak becomes larger than Bob after the first year. Their weights will be 3 and 2 then.
500
[ { "input": "4 7", "output": "2" }, { "input": "4 9", "output": "3" }, { "input": "1 1", "output": "1" }, { "input": "4 6", "output": "2" }, { "input": "1 10", "output": "6" }, { "input": "1 1", "output": "1" }, { "input": "1 2", "output": "2" }, { "input": "1 3", "output": "3" }, { "input": "1 4", "output": "4" }, { "input": "1 5", "output": "4" }, { "input": "1 6", "output": "5" }, { "input": "1 7", "output": "5" }, { "input": "1 8", "output": "6" }, { "input": "1 9", "output": "6" }, { "input": "1 10", "output": "6" }, { "input": "2 2", "output": "1" }, { "input": "2 3", "output": "2" }, { "input": "2 4", "output": "2" }, { "input": "2 5", "output": "3" }, { "input": "2 6", "output": "3" }, { "input": "2 7", "output": "4" }, { "input": "2 8", "output": "4" }, { "input": "2 9", "output": "4" }, { "input": "2 10", "output": "4" }, { "input": "3 3", "output": "1" }, { "input": "3 4", "output": "1" }, { "input": "3 5", "output": "2" }, { "input": "3 6", "output": "2" }, { "input": "3 7", "output": "3" }, { "input": "3 8", "output": "3" }, { "input": "3 9", "output": "3" }, { "input": "3 10", "output": "3" }, { "input": "4 4", "output": "1" }, { "input": "4 5", "output": "1" }, { "input": "4 6", "output": "2" }, { "input": "4 7", "output": "2" }, { "input": "4 8", "output": "2" }, { "input": "4 9", "output": "3" }, { "input": "4 10", "output": "3" }, { "input": "5 5", "output": "1" }, { "input": "5 6", "output": "1" }, { "input": "5 7", "output": "1" }, { "input": "5 8", "output": "2" }, { "input": "5 9", "output": "2" }, { "input": "5 10", "output": "2" }, { "input": "6 6", "output": "1" }, { "input": "6 7", "output": "1" }, { "input": "6 8", "output": "1" }, { "input": "6 9", "output": "2" }, { "input": "6 10", "output": "2" }, { "input": "7 7", "output": "1" }, { "input": "7 8", "output": "1" }, { "input": "7 9", "output": "1" }, { "input": "7 10", "output": "1" }, { "input": "8 8", "output": "1" }, { "input": "8 9", "output": "1" }, { "input": "8 10", "output": "1" }, { "input": "9 9", "output": "1" }, { "input": "9 10", "output": "1" }, { "input": "10 10", "output": "1" }, { "input": "10 10", "output": "1" }, { "input": "1 2", "output": "2" } ]
1,695,110,166
2,147,483,647
Python 3
OK
TESTS
62
46
0
# -*- coding: utf-8 -*- """ Created on Tue Sep 19 15:47:18 2023 @author: lenovo """ a,b=map(int,input().split()) s=0 while a<=b: a*=3 b*=2 s=s+1 print(s)
Title: Bear and Big Brother Time Limit: None seconds Memory Limit: None megabytes Problem Description: Bear Limak wants to become the largest of bears, or at least to become larger than his brother Bob. Right now, Limak and Bob weigh *a* and *b* respectively. It's guaranteed that Limak's weight is smaller than or equal to his brother's weight. Limak eats a lot and his weight is tripled after every year, while Bob's weight is doubled after every year. After how many full years will Limak become strictly larger (strictly heavier) than Bob? Input Specification: The only line of the input contains two integers *a* and *b* (1<=≤<=*a*<=≤<=*b*<=≤<=10) — the weight of Limak and the weight of Bob respectively. Output Specification: Print one integer, denoting the integer number of years after which Limak will become strictly larger than Bob. Demo Input: ['4 7\n', '4 9\n', '1 1\n'] Demo Output: ['2\n', '3\n', '1\n'] Note: In the first sample, Limak weighs 4 and Bob weighs 7 initially. After one year their weights are 4·3 = 12 and 7·2 = 14 respectively (one weight is tripled while the other one is doubled). Limak isn't larger than Bob yet. After the second year weights are 36 and 28, so the first weight is greater than the second one. Limak became larger than Bob after two years so you should print 2. In the second sample, Limak's and Bob's weights in next years are: 12 and 18, then 36 and 36, and finally 108 and 72 (after three years). The answer is 3. Remember that Limak wants to be larger than Bob and he won't be satisfied with equal weights. In the third sample, Limak becomes larger than Bob after the first year. Their weights will be 3 and 2 then.
```python # -*- coding: utf-8 -*- """ Created on Tue Sep 19 15:47:18 2023 @author: lenovo """ a,b=map(int,input().split()) s=0 while a<=b: a*=3 b*=2 s=s+1 print(s) ```
3
412
B
Network Configuration
PROGRAMMING
900
[ "greedy", "sortings" ]
null
null
The R1 company wants to hold a web search championship. There were *n* computers given for the competition, each of them is connected to the Internet. The organizers believe that the data transfer speed directly affects the result. The higher the speed of the Internet is, the faster the participant will find the necessary information. Therefore, before the competition started, each computer had its maximum possible data transfer speed measured. On the *i*-th computer it was *a**i* kilobits per second. There will be *k* participants competing in the championship, each should get a separate computer. The organizing company does not want any of the participants to have an advantage over the others, so they want to provide the same data transfer speed to each participant's computer. Also, the organizers want to create the most comfortable conditions for the participants, so the data transfer speed on the participants' computers should be as large as possible. The network settings of the R1 company has a special option that lets you to cut the initial maximum data transfer speed of any computer to any lower speed. How should the R1 company configure the network using the described option so that at least *k* of *n* computers had the same data transfer speed and the data transfer speed on these computers was as large as possible?
The first line contains two space-separated integers *n* and *k* (1<=≤<=*k*<=≤<=*n*<=≤<=100) — the number of computers and the number of participants, respectively. In the second line you have a space-separated sequence consisting of *n* integers: *a*1,<=*a*2,<=...,<=*a**n* (16<=≤<=*a**i*<=≤<=32768); number *a**i* denotes the maximum data transfer speed on the *i*-th computer.
Print a single integer — the maximum Internet speed value. It is guaranteed that the answer to the problem is always an integer.
[ "3 2\n40 20 30\n", "6 4\n100 20 40 20 50 50\n" ]
[ "30\n", "40\n" ]
In the first test case the organizers can cut the first computer's speed to 30 kilobits. Then two computers (the first and the third one) will have the same speed of 30 kilobits. They should be used as the participants' computers. This answer is optimal.
1,000
[ { "input": "3 2\n40 20 30", "output": "30" }, { "input": "6 4\n100 20 40 20 50 50", "output": "40" }, { "input": "1 1\n16", "output": "16" }, { "input": "2 1\n10000 17", "output": "10000" }, { "input": "2 2\n200 300", "output": "200" }, { "input": "3 1\n21 25 16", "output": "25" }, { "input": "3 2\n23 20 26", "output": "23" }, { "input": "3 3\n19 29 28", "output": "19" }, { "input": "100 2\n82 37 88 28 98 30 38 76 90 68 79 29 67 93 19 71 122 103 110 79 20 75 68 101 16 120 114 68 73 71 103 114 99 70 73 18 36 31 32 87 32 79 44 72 58 25 44 72 106 38 47 17 83 41 75 23 49 30 73 67 117 52 22 117 109 89 66 88 75 62 17 35 83 69 63 60 23 120 93 18 112 93 39 72 116 109 106 72 27 123 117 119 87 72 33 73 70 110 43 43", "output": "122" }, { "input": "30 13\n36 82 93 91 48 62 59 96 72 40 45 68 97 70 26 22 35 98 92 83 72 49 70 39 53 94 97 65 37 28", "output": "70" }, { "input": "50 49\n20 77 31 40 18 87 44 64 70 48 29 59 98 33 95 17 69 84 81 17 24 66 37 54 97 55 77 79 42 21 23 42 36 55 81 83 94 45 25 84 20 97 37 95 46 92 73 39 90 71", "output": "17" }, { "input": "40 40\n110 674 669 146 882 590 650 844 427 187 380 711 122 94 38 216 414 874 380 31 895 390 414 557 913 68 665 964 895 708 594 17 24 621 780 509 837 550 630 568", "output": "17" }, { "input": "40 1\n851 110 1523 1572 945 4966 4560 756 2373 4760 144 2579 4022 220 1924 1042 160 2792 2425 4483 2154 4120 319 4617 4686 2502 4797 4941 4590 4478 4705 4355 695 684 1560 684 2780 1090 4995 3113", "output": "4995" }, { "input": "70 12\n6321 2502 557 2734 16524 10133 13931 5045 3897 18993 5745 8687 12344 1724 12071 2345 3852 9312 14432 8615 7461 2439 4751 19872 12266 12997 8276 8155 9502 3047 7226 12754 9447 17349 1888 14564 18257 18099 8924 14199 738 13693 10917 15554 15773 17859 13391 13176 10567 19658 16494 3968 13977 14694 10537 4044 16402 9714 4425 13599 19660 2426 19687 2455 2382 3413 5754 113 7542 8353", "output": "16402" }, { "input": "80 60\n6159 26457 23753 27073 9877 4492 11957 10989 27151 6552 1646 7773 23924 27554 10517 8788 31160 455 12625 22009 22133 15657 14968 31871 15344 16550 27414 876 31213 10895 21508 17516 12747 59 11786 10497 30143 25548 22003 2809 11694 30395 8122 31248 23075 19013 31614 9133 27942 27346 15969 19415 10367 8424 29355 18903 3396 6327 4201 24124 24266 22586 724 1595 3972 17526 2843 20982 23655 12714 18050 15225 2658 7236 27555 13023 729 9022 17386 2585", "output": "8122" }, { "input": "100 1\n199 348 489 76 638 579 982 125 28 401 228 117 195 337 80 914 752 98 679 417 47 225 357 413 849 622 477 620 487 223 321 240 439 393 733 660 652 500 877 40 788 246 376 723 952 601 912 316 598 809 476 932 384 147 982 271 202 695 129 303 304 712 49 306 598 141 833 730 946 708 724 788 202 465 951 118 279 706 214 655 152 976 998 231 487 311 342 317 243 554 977 232 365 643 336 501 761 400 600 528", "output": "998" }, { "input": "80 50\n15160 6853 20254 11358 19535 27691 2983 31650 9219 11833 32053 31695 21511 4320 4384 24843 1454 31543 18796 13815 1546 27926 16276 14315 12542 25370 24890 29647 3584 17867 12446 15072 19852 30207 16361 7964 5343 398 10837 31114 9252 12767 15098 22562 32637 31823 8160 12658 6422 19142 12448 6765 7373 868 31712 24856 23251 29200 8159 16144 27165 4308 13652 12502 4183 7961 3032 26855 8687 12263 24319 7722 19460 30700 29806 1280 21141 25965 25550 26881", "output": "12448" }, { "input": "50 16\n16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16", "output": "16" }, { "input": "100 1\n16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16", "output": "16" }, { "input": "100 2\n16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16", "output": "16" }, { "input": "100 100\n16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16", "output": "16" }, { "input": "100 99\n16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16", "output": "16" } ]
1,698,418,610
2,147,483,647
PyPy 3-64
OK
TESTS
34
62
0
n,k=map(int,input().split()) a=[int(i) for i in input().split()] a.sort(reverse=True) print(min(a[:k]))
Title: Network Configuration Time Limit: None seconds Memory Limit: None megabytes Problem Description: The R1 company wants to hold a web search championship. There were *n* computers given for the competition, each of them is connected to the Internet. The organizers believe that the data transfer speed directly affects the result. The higher the speed of the Internet is, the faster the participant will find the necessary information. Therefore, before the competition started, each computer had its maximum possible data transfer speed measured. On the *i*-th computer it was *a**i* kilobits per second. There will be *k* participants competing in the championship, each should get a separate computer. The organizing company does not want any of the participants to have an advantage over the others, so they want to provide the same data transfer speed to each participant's computer. Also, the organizers want to create the most comfortable conditions for the participants, so the data transfer speed on the participants' computers should be as large as possible. The network settings of the R1 company has a special option that lets you to cut the initial maximum data transfer speed of any computer to any lower speed. How should the R1 company configure the network using the described option so that at least *k* of *n* computers had the same data transfer speed and the data transfer speed on these computers was as large as possible? Input Specification: The first line contains two space-separated integers *n* and *k* (1<=≤<=*k*<=≤<=*n*<=≤<=100) — the number of computers and the number of participants, respectively. In the second line you have a space-separated sequence consisting of *n* integers: *a*1,<=*a*2,<=...,<=*a**n* (16<=≤<=*a**i*<=≤<=32768); number *a**i* denotes the maximum data transfer speed on the *i*-th computer. Output Specification: Print a single integer — the maximum Internet speed value. It is guaranteed that the answer to the problem is always an integer. Demo Input: ['3 2\n40 20 30\n', '6 4\n100 20 40 20 50 50\n'] Demo Output: ['30\n', '40\n'] Note: In the first test case the organizers can cut the first computer's speed to 30 kilobits. Then two computers (the first and the third one) will have the same speed of 30 kilobits. They should be used as the participants' computers. This answer is optimal.
```python n,k=map(int,input().split()) a=[int(i) for i in input().split()] a.sort(reverse=True) print(min(a[:k])) ```
3