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
14
B
Young Photographer
PROGRAMMING
1,000
[ "implementation" ]
B. Young Photographer
2
64
Among other things, Bob is keen on photography. Especially he likes to take pictures of sportsmen. That was the reason why he placed himself in position *x*0 of a long straight racetrack and got ready to take pictures. But the problem was that not all the runners passed him. The total amount of sportsmen, training at that racetrack, equals *n*. And each of them regularly runs distances within a particular segment of the racetrack, which is the same for each sportsman. For example, the first sportsman runs from position *a*1 to position *b*1, the second — from *a*2 to *b*2 What is the minimum distance that Bob should move to have a chance to take pictures of each sportsman? Bob can take a picture of a sportsman, if he stands within the segment that this sportsman covers on the racetrack.
The first line of the input file contains integers *n* and *x*0 (1<=≤<=*n*<=≤<=100; 0<=≤<=*x*0<=≤<=1000). The following *n* lines contain pairs of integers *a**i*,<=*b**i* (0<=≤<=*a**i*,<=*b**i*<=≤<=1000; *a**i*<=≠<=*b**i*).
Output the required minimum distance in the same units as the positions on the racetrack. If there is no such a position, output -1.
[ "3 3\n0 7\n14 2\n4 6\n" ]
[ "1\n" ]
none
0
[ { "input": "3 3\n0 7\n14 2\n4 6", "output": "1" }, { "input": "1 1\n0 10", "output": "0" }, { "input": "2 2\n1 2\n3 2", "output": "0" }, { "input": "3 2\n1 2\n2 3\n3 4", "output": "-1" }, { "input": "2 4\n10 4\n1 5", "output": "0" }, { "input": "1 10\n1 9", "output": "1" }, { "input": "1 10\n123 12", "output": "2" }, { "input": "1 17\n10 17", "output": "0" }, { "input": "1 22\n22 33", "output": "0" }, { "input": "1 3\n1 2", "output": "1" }, { "input": "2 5\n0 3\n2 1", "output": "3" }, { "input": "3 3\n7 3\n6 4\n3 7", "output": "1" }, { "input": "4 9\n8 6\n11 5\n5 11\n8 3", "output": "1" }, { "input": "2 4\n1 4\n4 0", "output": "0" }, { "input": "3 7\n5 8\n7 5\n4 7", "output": "0" }, { "input": "4 7\n8 2\n5 7\n8 2\n5 8", "output": "0" }, { "input": "2 3\n4 1\n4 1", "output": "0" }, { "input": "3 8\n7 2\n3 7\n5 2", "output": "3" }, { "input": "4 0\n9 1\n8 1\n8 4\n4 5", "output": "4" }, { "input": "4 7\n2 5\n3 6\n3 5\n7 4", "output": "2" }, { "input": "10 16\n4 18\n6 19\n22 1\n23 0\n1 22\n9 22\n4 19\n0 14\n6 14\n0 16", "output": "2" }, { "input": "20 1\n35 8\n40 6\n49 5\n48 18\n46 16\n45 16\n44 10\n16 44\n8 46\n2 45\n38 3\n42 1\n13 35\n35 18\n12 33\n32 11\n31 3\n50 20\n47 6\n38 2", "output": "19" }, { "input": "30 43\n17 72\n75 26\n23 69\n83 30\n15 82\n4 67\n83 27\n33 62\n26 83\n70 26\n69 25\n16 67\n77 26\n66 33\n7 88\n70 9\n10 79\n76 9\n30 77\n77 28\n21 68\n81 14\n13 72\n88 15\n60 29\n87 28\n16 58\n6 58\n71 9\n83 18", "output": "0" }, { "input": "40 69\n29 109\n28 87\n52 106\n101 34\n32 92\n91 60\n90 47\n62 102\n33 72\n27 87\n45 78\n103 37\n94 33\n56 98\n38 79\n31 83\n105 53\n47 89\n50 83\n93 62\n96 49\n47 75\n89 47\n89 61\n93 54\n46 100\n110 41\n103 28\n101 57\n100 62\n71 37\n65 80\n86 28\n73 42\n96 44\n33 111\n98 39\n87 55\n108 65\n31 101", "output": "0" }, { "input": "50 77\n95 55\n113 33\n101 17\n109 56\n117 7\n77 12\n14 84\n57 101\n96 28\n108 22\n105 12\n17 114\n51 115\n18 112\n104 25\n50 115\n14 111\n55 113\n124 20\n101 37\n18 121\n41 90\n77 41\n117 16\n8 83\n92 45\n48 86\n16 84\n13 98\n40 107\n14 94\n23 111\n36 121\n50 100\n35 90\n103 37\n96 51\n109 15\n13 117\n117 42\n112 45\n88 36\n51 121\n127 49\n112 15\n9 95\n122 46\n126 40\n57 93\n56 88", "output": "0" }, { "input": "5 12\n2 7\n7 5\n3 10\n11 3\n2 11", "output": "5" }, { "input": "15 15\n12 37\n40 4\n38 8\n5 36\n11 31\n21 33\n9 37\n4 38\n8 33\n5 39\n7 39\n38 16\n16 41\n38 9\n5 32", "output": "6" }, { "input": "25 40\n66 26\n56 19\n64 38\n64 23\n25 49\n51 26\n67 20\n65 35\n33 66\n28 63\n27 57\n40 56\n59 26\n35 56\n39 67\n30 63\n69 22\n21 63\n67 22\n20 66\n26 65\n64 26\n44 57\n57 41\n35 50", "output": "4" }, { "input": "50 77\n24 119\n43 119\n102 22\n117 30\n127 54\n93 19\n120 9\n118 27\n98 16\n17 105\n22 127\n109 52\n115 40\n11 121\n12 120\n113 30\n13 108\n33 124\n31 116\n112 39\n37 108\n127 28\n127 39\n120 29\n19 114\n103 18\n106 16\n24 121\n93 10\n36 112\n104 40\n39 100\n36 97\n83 9\n14 114\n126 12\n85 47\n25 84\n105 29\n35 113\n102 19\n8 110\n111 28\n94 12\n11 115\n40 124\n39 85\n47 93\n94 31\n17 121", "output": "0" }, { "input": "1 21\n973 373", "output": "352" }, { "input": "2 212\n831 551\n810 753", "output": "541" }, { "input": "3 404\n690 728\n820 260\n186 402", "output": "-1" }, { "input": "4 906\n548 906\n830 457\n228 638\n464 167", "output": "-1" }, { "input": "5 97\n97 393\n840 965\n269 183\n596 49\n975 62", "output": "-1" }, { "input": "3 183\n416 335\n773 648\n434 198", "output": "-1" }, { "input": "3 868\n251 927\n862 464\n157 756", "output": "112" }, { "input": "3 242\n397 208\n951 279\n570 622", "output": "-1" }, { "input": "3 618\n543 800\n38 94\n293 179", "output": "-1" }, { "input": "3 993\n378 81\n127 911\n16 737", "output": "615" }, { "input": "5 12\n11 1\n9 6\n1 11\n3 8\n874 842", "output": "-1" }, { "input": "15 16\n11 40\n5 32\n5 31\n36 10\n34 9\n43 6\n28 6\n34 8\n43 15\n9 28\n14 34\n34 6\n7 31\n31 14\n68 478", "output": "-1" }, { "input": "25 57\n47 31\n64 21\n43 56\n47 19\n70 27\n28 61\n41 61\n39 45\n46 21\n55 35\n70 22\n22 69\n30 67\n55 42\n37 58\n50 28\n57 42\n35 48\n68 40\n38 50\n62 20\n31 52\n38 70\n64 35\n666 393", "output": "-1" }, { "input": "50 118\n83 55\n101 33\n89 17\n97 56\n105 7\n65 12\n14 72\n57 89\n84 28\n96 22\n93 12\n17 102\n51 103\n18 100\n92 25\n50 103\n14 99\n55 101\n112 20\n89 37\n18 109\n41 78\n65 41\n105 16\n8 71\n80 45\n48 74\n16 72\n13 86\n40 95\n14 82\n23 99\n36 109\n50 88\n35 78\n91 37\n84 51\n97 15\n13 105\n105 42\n100 45\n76 36\n51 109\n115 49\n100 15\n9 83\n110 46\n114 40\n57 81\n528 348", "output": "-1" }, { "input": "1 21\n0 1000", "output": "0" } ]
1,597,582,792
2,147,483,647
PyPy 3
WRONG_ANSWER
TESTS
18
280
0
n,x0=map(int,input().split()) pos=set() a,b=map(int,input().split()) a1=min(a,b) a2=max(a,b) for i in range(a1,a2+1): pos.add(i) for i in range(n-1): a,b=map(int,input().split()) a1=min(a,b) a2=max(a,b) L=[] for each in pos: if each not in range(a1,a2+1): L.append(each) for each in L: pos.remove(each) if len(pos)==0: print("-1") else: ans=x0 for each in pos: ans=min(ans,abs(x0-each)) print(ans)
Title: Young Photographer Time Limit: 2 seconds Memory Limit: 64 megabytes Problem Description: Among other things, Bob is keen on photography. Especially he likes to take pictures of sportsmen. That was the reason why he placed himself in position *x*0 of a long straight racetrack and got ready to take pictures. But the problem was that not all the runners passed him. The total amount of sportsmen, training at that racetrack, equals *n*. And each of them regularly runs distances within a particular segment of the racetrack, which is the same for each sportsman. For example, the first sportsman runs from position *a*1 to position *b*1, the second — from *a*2 to *b*2 What is the minimum distance that Bob should move to have a chance to take pictures of each sportsman? Bob can take a picture of a sportsman, if he stands within the segment that this sportsman covers on the racetrack. Input Specification: The first line of the input file contains integers *n* and *x*0 (1<=≤<=*n*<=≤<=100; 0<=≤<=*x*0<=≤<=1000). The following *n* lines contain pairs of integers *a**i*,<=*b**i* (0<=≤<=*a**i*,<=*b**i*<=≤<=1000; *a**i*<=≠<=*b**i*). Output Specification: Output the required minimum distance in the same units as the positions on the racetrack. If there is no such a position, output -1. Demo Input: ['3 3\n0 7\n14 2\n4 6\n'] Demo Output: ['1\n'] Note: none
```python n,x0=map(int,input().split()) pos=set() a,b=map(int,input().split()) a1=min(a,b) a2=max(a,b) for i in range(a1,a2+1): pos.add(i) for i in range(n-1): a,b=map(int,input().split()) a1=min(a,b) a2=max(a,b) L=[] for each in pos: if each not in range(a1,a2+1): L.append(each) for each in L: pos.remove(each) if len(pos)==0: print("-1") else: ans=x0 for each in pos: ans=min(ans,abs(x0-each)) print(ans) ```
0
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,489,643,983
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
3
46
4,608,000
##n = int(input()) ##a = list(map(int, input().split())) ##print(" ".join(map(str, res))) n = int(input()) t = list(map(int, input().split())) s = 0 res = 0 for i in range(len(t)): if t[i]-s > 15: res += 15 break else: s = t[i] res = s res = min(res, 90) print(res)
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 ##n = int(input()) ##a = list(map(int, input().split())) ##print(" ".join(map(str, res))) n = int(input()) t = list(map(int, input().split())) s = 0 res = 0 for i in range(len(t)): if t[i]-s > 15: res += 15 break else: s = t[i] res = s res = min(res, 90) print(res) ```
0
71
A
Way Too Long Words
PROGRAMMING
800
[ "strings" ]
A. Way Too Long Words
1
256
Sometimes some words like "localization" or "internationalization" are so long that writing them many times in one text is quite tiresome. Let's consider a word too long, if its length is strictly more than 10 characters. All too long words should be replaced with a special abbreviation. This abbreviation is made like this: we write down the first and the last letter of a word and between them we write the number of letters between the first and the last letters. That number is in decimal system and doesn't contain any leading zeroes. Thus, "localization" will be spelt as "l10n", and "internationalization» will be spelt as "i18n". You are suggested to automatize the process of changing the words with abbreviations. At that all too long words should be replaced by the abbreviation and the words that are not too long should not undergo any changes.
The first line contains an integer *n* (1<=≤<=*n*<=≤<=100). Each of the following *n* lines contains one word. All the words consist of lowercase Latin letters and possess the lengths of from 1 to 100 characters.
Print *n* lines. The *i*-th line should contain the result of replacing of the *i*-th word from the input data.
[ "4\nword\nlocalization\ninternationalization\npneumonoultramicroscopicsilicovolcanoconiosis\n" ]
[ "word\nl10n\ni18n\np43s\n" ]
none
500
[ { "input": "4\nword\nlocalization\ninternationalization\npneumonoultramicroscopicsilicovolcanoconiosis", "output": "word\nl10n\ni18n\np43s" }, { "input": "5\nabcdefgh\nabcdefghi\nabcdefghij\nabcdefghijk\nabcdefghijklm", "output": "abcdefgh\nabcdefghi\nabcdefghij\na9k\na11m" }, { "input": "3\nnjfngnrurunrgunrunvurn\njfvnjfdnvjdbfvsbdubruvbubvkdb\nksdnvidnviudbvibd", "output": "n20n\nj27b\nk15d" }, { "input": "1\ntcyctkktcctrcyvbyiuhihhhgyvyvyvyvjvytchjckt", "output": "t41t" }, { "input": "24\nyou\nare\nregistered\nfor\npractice\nyou\ncan\nsolve\nproblems\nunofficially\nresults\ncan\nbe\nfound\nin\nthe\ncontest\nstatus\nand\nin\nthe\nbottom\nof\nstandings", "output": "you\nare\nregistered\nfor\npractice\nyou\ncan\nsolve\nproblems\nu10y\nresults\ncan\nbe\nfound\nin\nthe\ncontest\nstatus\nand\nin\nthe\nbottom\nof\nstandings" }, { "input": "1\na", "output": "a" }, { "input": "26\na\nb\nc\nd\ne\nf\ng\nh\ni\nj\nk\nl\nm\nn\no\np\nq\nr\ns\nt\nu\nv\nw\nx\ny\nz", "output": "a\nb\nc\nd\ne\nf\ng\nh\ni\nj\nk\nl\nm\nn\no\np\nq\nr\ns\nt\nu\nv\nw\nx\ny\nz" }, { "input": "1\nabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghij", "output": "a98j" }, { "input": "10\ngyartjdxxlcl\nfzsck\nuidwu\nxbymclornemdmtj\nilppyoapitawgje\ncibzc\ndrgbeu\nhezplmsdekhhbo\nfeuzlrimbqbytdu\nkgdco", "output": "g10l\nfzsck\nuidwu\nx13j\ni13e\ncibzc\ndrgbeu\nh12o\nf13u\nkgdco" }, { "input": "20\nlkpmx\nkovxmxorlgwaomlswjxlpnbvltfv\nhykasjxqyjrmybejnmeumzha\ntuevlumpqbbhbww\nqgqsphvrmupxxc\ntrissbaf\nqfgrlinkzvzqdryckaizutd\nzzqtoaxkvwoscyx\noswytrlnhpjvvnwookx\nlpuzqgec\ngyzqfwxggtvpjhzmzmdw\nrlxjgmvdftvrmvbdwudra\nvsntnjpepnvdaxiporggmglhagv\nxlvcqkqgcrbgtgglj\nlyxwxbiszyhlsrgzeedzprbmcpduvq\nyrmqqvrkqskqukzqrwukpsifgtdc\nxpuohcsjhhuhvr\nvvlfrlxpvqejngwrbfbpmqeirxlw\nsvmasocxdvadmaxtrpakysmeaympy\nyuflqboqfdt", "output": "lkpmx\nk26v\nh22a\nt13w\nq12c\ntrissbaf\nq21d\nz13x\no17x\nlpuzqgec\ng18w\nr19a\nv25v\nx15j\nl28q\ny26c\nx12r\nv26w\ns27y\ny9t" }, { "input": "100\nm\nz\ns\nv\nd\nr\nv\ny\ny\ne\np\nt\nc\na\nn\nm\np\ng\ni\nj\nc\na\nb\nq\ne\nn\nv\no\nk\nx\nf\ni\nl\na\nq\nr\nu\nb\ns\nl\nc\nl\ne\nv\nj\nm\nx\nb\na\nq\nb\na\nf\nj\nv\nm\nq\nc\nt\nt\nn\nx\no\ny\nr\nu\nh\nm\nj\np\nj\nq\nz\ns\nj\no\ng\nc\nm\nn\no\nm\nr\no\ns\nt\nh\nr\np\nk\nb\nz\ng\no\nc\nc\nz\nz\ng\nr", "output": "m\nz\ns\nv\nd\nr\nv\ny\ny\ne\np\nt\nc\na\nn\nm\np\ng\ni\nj\nc\na\nb\nq\ne\nn\nv\no\nk\nx\nf\ni\nl\na\nq\nr\nu\nb\ns\nl\nc\nl\ne\nv\nj\nm\nx\nb\na\nq\nb\na\nf\nj\nv\nm\nq\nc\nt\nt\nn\nx\no\ny\nr\nu\nh\nm\nj\np\nj\nq\nz\ns\nj\no\ng\nc\nm\nn\no\nm\nr\no\ns\nt\nh\nr\np\nk\nb\nz\ng\no\nc\nc\nz\nz\ng\nr" } ]
1,671,899,796
2,147,483,647
Python 3
OK
TESTS
20
46
0
n = int(input()) while n>0: v = input() x = len(v[1:len(v)-1]) if len(v) > 10: op = v[0]+str(x)+v[-1] print(op) else: print(v) n -= 1
Title: Way Too Long Words Time Limit: 1 seconds Memory Limit: 256 megabytes Problem Description: Sometimes some words like "localization" or "internationalization" are so long that writing them many times in one text is quite tiresome. Let's consider a word too long, if its length is strictly more than 10 characters. All too long words should be replaced with a special abbreviation. This abbreviation is made like this: we write down the first and the last letter of a word and between them we write the number of letters between the first and the last letters. That number is in decimal system and doesn't contain any leading zeroes. Thus, "localization" will be spelt as "l10n", and "internationalization» will be spelt as "i18n". You are suggested to automatize the process of changing the words with abbreviations. At that all too long words should be replaced by the abbreviation and the words that are not too long should not undergo any changes. Input Specification: The first line contains an integer *n* (1<=≤<=*n*<=≤<=100). Each of the following *n* lines contains one word. All the words consist of lowercase Latin letters and possess the lengths of from 1 to 100 characters. Output Specification: Print *n* lines. The *i*-th line should contain the result of replacing of the *i*-th word from the input data. Demo Input: ['4\nword\nlocalization\ninternationalization\npneumonoultramicroscopicsilicovolcanoconiosis\n'] Demo Output: ['word\nl10n\ni18n\np43s\n'] Note: none
```python n = int(input()) while n>0: v = input() x = len(v[1:len(v)-1]) if len(v) > 10: op = v[0]+str(x)+v[-1] print(op) else: print(v) n -= 1 ```
3.977
27
D
Ring Road 2
PROGRAMMING
2,200
[ "2-sat", "dfs and similar", "dsu", "graphs" ]
D. Ring Road 2
2
256
It is well known that Berland has *n* cities, which form the Silver ring — cities *i* and *i*<=+<=1 (1<=≤<=*i*<=&lt;<=*n*) are connected by a road, as well as the cities *n* and 1. The goverment have decided to build *m* new roads. The list of the roads to build was prepared. Each road will connect two cities. Each road should be a curve which lies inside or outside the ring. New roads will have no common points with the ring (except the endpoints of the road). Now the designers of the constructing plan wonder if it is possible to build the roads in such a way that no two roads intersect (note that the roads may intersect at their endpoints). If it is possible to do, which roads should be inside the ring, and which should be outside?
The first line contains two integers *n* and *m* (4<=≤<=*n*<=≤<=100,<=1<=≤<=*m*<=≤<=100). Each of the following *m* lines contains two integers *a**i* and *b**i* (1<=≤<=*a**i*,<=*b**i*<=≤<=*n*,<=*a**i*<=≠<=*b**i*). No two cities will be connected by more than one road in the list. The list will not contain the roads which exist in the Silver ring.
If it is impossible to build the roads in such a way that no two roads intersect, output Impossible. Otherwise print *m* characters. *i*-th character should be i, if the road should be inside the ring, and o if the road should be outside the ring. If there are several solutions, output any of them.
[ "4 2\n1 3\n2 4\n", "6 3\n1 3\n3 5\n5 1\n" ]
[ "io\n", "ooo\n" ]
none
2,000
[ { "input": "4 1\n4 2", "output": "o" }, { "input": "4 2\n1 3\n2 4", "output": "io" }, { "input": "5 1\n3 5", "output": "o" }, { "input": "5 2\n2 4\n4 1", "output": "oo" }, { "input": "5 3\n4 2\n1 3\n5 2", "output": "oio" }, { "input": "5 4\n1 3\n3 5\n1 4\n2 4", "output": "iioo" }, { "input": "6 1\n6 2", "output": "o" }, { "input": "6 2\n3 5\n2 4", "output": "oi" }, { "input": "6 3\n5 1\n4 6\n3 1", "output": "oio" }, { "input": "6 4\n6 3\n1 3\n6 4\n5 3", "output": "oooi" }, { "input": "6 5\n5 3\n4 1\n2 6\n5 1\n5 2", "output": "ioioi" }, { "input": "6 6\n1 4\n4 6\n2 6\n2 4\n5 3\n6 3", "output": "iioioo" }, { "input": "7 1\n4 7", "output": "o" }, { "input": "7 3\n2 7\n1 5\n5 7", "output": "oio" }, { "input": "7 5\n3 7\n5 7\n6 4\n4 1\n3 1", "output": "iiooo" }, { "input": "7 8\n4 7\n3 5\n7 2\n2 4\n4 6\n1 5\n1 3\n7 5", "output": "oioooiii" }, { "input": "5 4\n2 4\n2 5\n3 1\n5 3", "output": "iioo" }, { "input": "10 4\n6 9\n10 2\n4 8\n2 9", "output": "ooio" }, { "input": "17 10\n4 11\n7 16\n8 5\n12 15\n7 4\n1 12\n11 1\n15 1\n7 14\n2 9", "output": "Impossible" }, { "input": "100 50\n79 24\n65 69\n44 6\n49 53\n26 22\n24 76\n10 2\n19 44\n44 10\n87 82\n91 87\n23 92\n69 66\n95 30\n90 24\n95 20\n76 36\n82 24\n63 80\n70 72\n34 76\n42 40\n17 100\n66 64\n85 96\n34 30\n36 69\n45 56\n36 62\n26 38\n31 28\n79 64\n78 69\n41 62\n36 40\n64 67\n21 13\n90 88\n28 30\n59 6\n59 56\n63 1\n24 91\n12 19\n100 80\n98 95\n75 78\n54 44\n81 97\n20 38", "output": "Impossible" }, { "input": "20 14\n18 3\n15 12\n8 15\n17 7\n16 14\n15 7\n18 5\n6 17\n4 18\n4 2\n20 2\n9 19\n20 7\n16 18", "output": "ooooiooooioiii" }, { "input": "10 7\n1 3\n1 4\n1 5\n1 6\n1 7\n1 8\n1 9", "output": "ooooooo" }, { "input": "6 3\n1 4\n2 5\n3 6", "output": "Impossible" }, { "input": "7 9\n4 7\n3 5\n7 2\n2 4\n4 6\n1 5\n1 3\n7 5\n2 5", "output": "Impossible" } ]
1,531,489,291
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
4
248
0
n,m = map(int,input().split(' ')) ans = [] for i in range(0,m): a,b = map(int,input().split(' ')) if a%2==0 and b%2==0: ans.append('i') else: ans.append('o') ans = ''.join(ans) print(ans)
Title: Ring Road 2 Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: It is well known that Berland has *n* cities, which form the Silver ring — cities *i* and *i*<=+<=1 (1<=≤<=*i*<=&lt;<=*n*) are connected by a road, as well as the cities *n* and 1. The goverment have decided to build *m* new roads. The list of the roads to build was prepared. Each road will connect two cities. Each road should be a curve which lies inside or outside the ring. New roads will have no common points with the ring (except the endpoints of the road). Now the designers of the constructing plan wonder if it is possible to build the roads in such a way that no two roads intersect (note that the roads may intersect at their endpoints). If it is possible to do, which roads should be inside the ring, and which should be outside? Input Specification: The first line contains two integers *n* and *m* (4<=≤<=*n*<=≤<=100,<=1<=≤<=*m*<=≤<=100). Each of the following *m* lines contains two integers *a**i* and *b**i* (1<=≤<=*a**i*,<=*b**i*<=≤<=*n*,<=*a**i*<=≠<=*b**i*). No two cities will be connected by more than one road in the list. The list will not contain the roads which exist in the Silver ring. Output Specification: If it is impossible to build the roads in such a way that no two roads intersect, output Impossible. Otherwise print *m* characters. *i*-th character should be i, if the road should be inside the ring, and o if the road should be outside the ring. If there are several solutions, output any of them. Demo Input: ['4 2\n1 3\n2 4\n', '6 3\n1 3\n3 5\n5 1\n'] Demo Output: ['io\n', 'ooo\n'] Note: none
```python n,m = map(int,input().split(' ')) ans = [] for i in range(0,m): a,b = map(int,input().split(' ')) if a%2==0 and b%2==0: ans.append('i') else: ans.append('o') ans = ''.join(ans) print(ans) ```
0
633
B
A Trivial Problem
PROGRAMMING
1,300
[ "brute force", "constructive algorithms", "math", "number theory" ]
null
null
Mr. Santa asks all the great programmers of the world to solve a trivial problem. He gives them an integer *m* and asks for the number of positive integers *n*, such that the factorial of *n* ends with exactly *m* zeroes. Are you among those great programmers who can solve this problem?
The only line of input contains an integer *m* (1<=≤<=*m*<=≤<=100<=000) — the required number of trailing zeroes in factorial.
First print *k* — the number of values of *n* such that the factorial of *n* ends with *m* zeroes. Then print these *k* integers in increasing order.
[ "1\n", "5\n" ]
[ "5\n5 6 7 8 9 ", "0" ]
The factorial of *n* is equal to the product of all integers from 1 to *n* inclusive, that is *n*! = 1·2·3·...·*n*. In the first sample, 5! = 120, 6! = 720, 7! = 5040, 8! = 40320 and 9! = 362880.
500
[ { "input": "1", "output": "5\n5 6 7 8 9 " }, { "input": "5", "output": "0" }, { "input": "2", "output": "5\n10 11 12 13 14 " }, { "input": "3", "output": "5\n15 16 17 18 19 " }, { "input": "7", "output": "5\n30 31 32 33 34 " }, { "input": "12", "output": "5\n50 51 52 53 54 " }, { "input": "15", "output": "5\n65 66 67 68 69 " }, { "input": "18", "output": "5\n75 76 77 78 79 " }, { "input": "38", "output": "5\n155 156 157 158 159 " }, { "input": "47", "output": "5\n195 196 197 198 199 " }, { "input": "58", "output": "5\n240 241 242 243 244 " }, { "input": "66", "output": "5\n270 271 272 273 274 " }, { "input": "70", "output": "5\n285 286 287 288 289 " }, { "input": "89", "output": "5\n365 366 367 368 369 " }, { "input": "417", "output": "5\n1675 1676 1677 1678 1679 " }, { "input": "815", "output": "5\n3265 3266 3267 3268 3269 " }, { "input": "394", "output": "5\n1585 1586 1587 1588 1589 " }, { "input": "798", "output": "0" }, { "input": "507", "output": "5\n2035 2036 2037 2038 2039 " }, { "input": "406", "output": "5\n1630 1631 1632 1633 1634 " }, { "input": "570", "output": "5\n2290 2291 2292 2293 2294 " }, { "input": "185", "output": "0" }, { "input": "765", "output": "0" }, { "input": "967", "output": "0" }, { "input": "112", "output": "5\n455 456 457 458 459 " }, { "input": "729", "output": "5\n2925 2926 2927 2928 2929 " }, { "input": "4604", "output": "5\n18425 18426 18427 18428 18429 " }, { "input": "8783", "output": "5\n35140 35141 35142 35143 35144 " }, { "input": "1059", "output": "0" }, { "input": "6641", "output": "5\n26575 26576 26577 26578 26579 " }, { "input": "9353", "output": "5\n37425 37426 37427 37428 37429 " }, { "input": "1811", "output": "5\n7250 7251 7252 7253 7254 " }, { "input": "2528", "output": "0" }, { "input": "8158", "output": "5\n32640 32641 32642 32643 32644 " }, { "input": "3014", "output": "5\n12070 12071 12072 12073 12074 " }, { "input": "7657", "output": "5\n30640 30641 30642 30643 30644 " }, { "input": "4934", "output": "0" }, { "input": "9282", "output": "5\n37140 37141 37142 37143 37144 " }, { "input": "2610", "output": "5\n10450 10451 10452 10453 10454 " }, { "input": "2083", "output": "5\n8345 8346 8347 8348 8349 " }, { "input": "26151", "output": "5\n104620 104621 104622 104623 104624 " }, { "input": "64656", "output": "5\n258640 258641 258642 258643 258644 " }, { "input": "46668", "output": "5\n186690 186691 186692 186693 186694 " }, { "input": "95554", "output": "5\n382235 382236 382237 382238 382239 " }, { "input": "37320", "output": "0" }, { "input": "52032", "output": "5\n208140 208141 208142 208143 208144 " }, { "input": "11024", "output": "5\n44110 44111 44112 44113 44114 " }, { "input": "63218", "output": "5\n252885 252886 252887 252888 252889 " }, { "input": "40095", "output": "5\n160390 160391 160392 160393 160394 " }, { "input": "42724", "output": "5\n170910 170911 170912 170913 170914 " }, { "input": "24381", "output": "5\n97530 97531 97532 97533 97534 " }, { "input": "73138", "output": "5\n292570 292571 292572 292573 292574 " }, { "input": "93346", "output": "5\n373400 373401 373402 373403 373404 " }, { "input": "18338", "output": "5\n73370 73371 73372 73373 73374 " }, { "input": "42662", "output": "5\n170660 170661 170662 170663 170664 " }, { "input": "81221", "output": "5\n324900 324901 324902 324903 324904 " }, { "input": "100000", "output": "5\n400005 400006 400007 400008 400009 " }, { "input": "100000", "output": "5\n400005 400006 400007 400008 400009 " }, { "input": "99998", "output": "0" }, { "input": "30", "output": "0" }, { "input": "11", "output": "0" }, { "input": "780", "output": "0" }, { "input": "97656", "output": "5\n390625 390626 390627 390628 390629 " }, { "input": "12499", "output": "5\n50000 50001 50002 50003 50004 " }, { "input": "65", "output": "5\n265 266 267 268 269 " }, { "input": "41", "output": "5\n170 171 172 173 174 " }, { "input": "31", "output": "5\n125 126 127 128 129 " }, { "input": "86577", "output": "0" } ]
1,540,894,464
2,147,483,647
Python 3
COMPILATION_ERROR
TESTS
0
0
0
a=int(input()) from math import log if (int log(a)/log(5))==log(a)/log(5): print(0) else: print("5") for i in range(5): print(i+a*5-5*(log(a)//log(5)))
Title: A Trivial Problem Time Limit: None seconds Memory Limit: None megabytes Problem Description: Mr. Santa asks all the great programmers of the world to solve a trivial problem. He gives them an integer *m* and asks for the number of positive integers *n*, such that the factorial of *n* ends with exactly *m* zeroes. Are you among those great programmers who can solve this problem? Input Specification: The only line of input contains an integer *m* (1<=≤<=*m*<=≤<=100<=000) — the required number of trailing zeroes in factorial. Output Specification: First print *k* — the number of values of *n* such that the factorial of *n* ends with *m* zeroes. Then print these *k* integers in increasing order. Demo Input: ['1\n', '5\n'] Demo Output: ['5\n5 6 7 8 9 ', '0'] Note: The factorial of *n* is equal to the product of all integers from 1 to *n* inclusive, that is *n*! = 1·2·3·...·*n*. In the first sample, 5! = 120, 6! = 720, 7! = 5040, 8! = 40320 and 9! = 362880.
```python a=int(input()) from math import log if (int log(a)/log(5))==log(a)/log(5): print(0) else: print("5") for i in range(5): print(i+a*5-5*(log(a)//log(5))) ```
-1
505
B
Mr. Kitayuta's Colorful Graph
PROGRAMMING
1,400
[ "dfs and similar", "dp", "dsu", "graphs" ]
null
null
Mr. Kitayuta has just bought an undirected graph consisting of *n* vertices and *m* edges. The vertices of the graph are numbered from 1 to *n*. Each edge, namely edge *i*, has a color *c**i*, connecting vertex *a**i* and *b**i*. Mr. Kitayuta wants you to process the following *q* queries. In the *i*-th query, he gives you two integers — *u**i* and *v**i*. Find the number of the colors that satisfy the following condition: the edges of that color connect vertex *u**i* and vertex *v**i* directly or indirectly.
The first line of the input contains space-separated two integers — *n* and *m* (2<=≤<=*n*<=≤<=100,<=1<=≤<=*m*<=≤<=100), denoting the number of the vertices and the number of the edges, respectively. The next *m* lines contain space-separated three integers — *a**i*, *b**i* (1<=≤<=*a**i*<=&lt;<=*b**i*<=≤<=*n*) and *c**i* (1<=≤<=*c**i*<=≤<=*m*). Note that there can be multiple edges between two vertices. However, there are no multiple edges of the same color between two vertices, that is, if *i*<=≠<=*j*, (*a**i*,<=*b**i*,<=*c**i*)<=≠<=(*a**j*,<=*b**j*,<=*c**j*). The next line contains a integer — *q* (1<=≤<=*q*<=≤<=100), denoting the number of the queries. Then follows *q* lines, containing space-separated two integers — *u**i* and *v**i* (1<=≤<=*u**i*,<=*v**i*<=≤<=*n*). It is guaranteed that *u**i*<=≠<=*v**i*.
For each query, print the answer in a separate line.
[ "4 5\n1 2 1\n1 2 2\n2 3 1\n2 3 3\n2 4 3\n3\n1 2\n3 4\n1 4\n", "5 7\n1 5 1\n2 5 1\n3 5 1\n4 5 1\n1 2 2\n2 3 2\n3 4 2\n5\n1 5\n5 1\n2 5\n1 5\n1 4\n" ]
[ "2\n1\n0\n", "1\n1\n1\n1\n2\n" ]
Let's consider the first sample. - Vertex 1 and vertex 2 are connected by color 1 and 2. - Vertex 3 and vertex 4 are connected by color 3. - Vertex 1 and vertex 4 are not connected by any single color.
1,000
[ { "input": "4 5\n1 2 1\n1 2 2\n2 3 1\n2 3 3\n2 4 3\n3\n1 2\n3 4\n1 4", "output": "2\n1\n0" }, { "input": "5 7\n1 5 1\n2 5 1\n3 5 1\n4 5 1\n1 2 2\n2 3 2\n3 4 2\n5\n1 5\n5 1\n2 5\n1 5\n1 4", "output": "1\n1\n1\n1\n2" }, { "input": "2 1\n1 2 1\n1\n1 2", "output": "1" }, { "input": "2 3\n1 2 3\n1 2 2\n1 2 1\n1\n1 2", "output": "3" }, { "input": "2 5\n1 2 1\n1 2 2\n1 2 3\n1 2 4\n1 2 5\n1\n1 2", "output": "5" } ]
1,618,398,962
2,147,483,647
PyPy 3
OK
TESTS
29
592
4,812,800
#code by aanchaltiwari__ def dfs(x, y, color): visited = [False for i in range(n + 1)] visited[x] = True stack = [x] while stack: node = stack.pop() for child, childcolor in g[node]: if visited[child] == False and childcolor == color: visited[child] = True stack.append(child) if visited[y] == True: return True return False n, m = map(int, input().split()) g = {i: [] for i in range(1, n + 1)} s = set() for i in range(m): u, v, c = map(int, input().split()) s.add(c) g[u].append([v, c]) g[v].append([u, c]) s = list(s) # print(g) # print(s) ans = [[0 for i in range(n+1)]for j in range(n+1)] for i in range(1, n + 1): for j in range(1, n + 1): for c in s: if i != j: if dfs(i, j, c): ans[i][j] += 1 # print(ans) q = int(input()) for i in range(q): u, v = map(int, input().split()) print(ans[u][v])
Title: Mr. Kitayuta's Colorful Graph Time Limit: None seconds Memory Limit: None megabytes Problem Description: Mr. Kitayuta has just bought an undirected graph consisting of *n* vertices and *m* edges. The vertices of the graph are numbered from 1 to *n*. Each edge, namely edge *i*, has a color *c**i*, connecting vertex *a**i* and *b**i*. Mr. Kitayuta wants you to process the following *q* queries. In the *i*-th query, he gives you two integers — *u**i* and *v**i*. Find the number of the colors that satisfy the following condition: the edges of that color connect vertex *u**i* and vertex *v**i* directly or indirectly. Input Specification: The first line of the input contains space-separated two integers — *n* and *m* (2<=≤<=*n*<=≤<=100,<=1<=≤<=*m*<=≤<=100), denoting the number of the vertices and the number of the edges, respectively. The next *m* lines contain space-separated three integers — *a**i*, *b**i* (1<=≤<=*a**i*<=&lt;<=*b**i*<=≤<=*n*) and *c**i* (1<=≤<=*c**i*<=≤<=*m*). Note that there can be multiple edges between two vertices. However, there are no multiple edges of the same color between two vertices, that is, if *i*<=≠<=*j*, (*a**i*,<=*b**i*,<=*c**i*)<=≠<=(*a**j*,<=*b**j*,<=*c**j*). The next line contains a integer — *q* (1<=≤<=*q*<=≤<=100), denoting the number of the queries. Then follows *q* lines, containing space-separated two integers — *u**i* and *v**i* (1<=≤<=*u**i*,<=*v**i*<=≤<=*n*). It is guaranteed that *u**i*<=≠<=*v**i*. Output Specification: For each query, print the answer in a separate line. Demo Input: ['4 5\n1 2 1\n1 2 2\n2 3 1\n2 3 3\n2 4 3\n3\n1 2\n3 4\n1 4\n', '5 7\n1 5 1\n2 5 1\n3 5 1\n4 5 1\n1 2 2\n2 3 2\n3 4 2\n5\n1 5\n5 1\n2 5\n1 5\n1 4\n'] Demo Output: ['2\n1\n0\n', '1\n1\n1\n1\n2\n'] Note: Let's consider the first sample. - Vertex 1 and vertex 2 are connected by color 1 and 2. - Vertex 3 and vertex 4 are connected by color 3. - Vertex 1 and vertex 4 are not connected by any single color.
```python #code by aanchaltiwari__ def dfs(x, y, color): visited = [False for i in range(n + 1)] visited[x] = True stack = [x] while stack: node = stack.pop() for child, childcolor in g[node]: if visited[child] == False and childcolor == color: visited[child] = True stack.append(child) if visited[y] == True: return True return False n, m = map(int, input().split()) g = {i: [] for i in range(1, n + 1)} s = set() for i in range(m): u, v, c = map(int, input().split()) s.add(c) g[u].append([v, c]) g[v].append([u, c]) s = list(s) # print(g) # print(s) ans = [[0 for i in range(n+1)]for j in range(n+1)] for i in range(1, n + 1): for j in range(1, n + 1): for c in s: if i != j: if dfs(i, j, c): ans[i][j] += 1 # print(ans) q = int(input()) for i in range(q): u, v = map(int, input().split()) print(ans[u][v]) ```
3
585
B
Phillip and Trains
PROGRAMMING
1,700
[ "dfs and similar", "graphs", "shortest paths" ]
null
null
The mobile application store has a new game called "Subway Roller". The protagonist of the game Philip is located in one end of the tunnel and wants to get out of the other one. The tunnel is a rectangular field consisting of three rows and *n* columns. At the beginning of the game the hero is in some cell of the leftmost column. Some number of trains rides towards the hero. Each train consists of two or more neighbouring cells in some row of the field. All trains are moving from right to left at a speed of two cells per second, and the hero runs from left to right at the speed of one cell per second. For simplicity, the game is implemented so that the hero and the trains move in turns. First, the hero moves one cell to the right, then one square up or down, or stays idle. Then all the trains move twice simultaneously one cell to the left. Thus, in one move, Philip definitely makes a move to the right and can move up or down. If at any point, Philip is in the same cell with a train, he loses. If the train reaches the left column, it continues to move as before, leaving the tunnel. Your task is to answer the question whether there is a sequence of movements of Philip, such that he would be able to get to the rightmost column.
Each test contains from one to ten sets of the input data. The first line of the test contains a single integer *t* (1<=≤<=*t*<=≤<=10 for pretests and tests or *t*<==<=1 for hacks; see the Notes section for details) — the number of sets. Then follows the description of *t* sets of the input data. The first line of the description of each set contains two integers *n*,<=*k* (2<=≤<=*n*<=≤<=100,<=1<=≤<=*k*<=≤<=26) — the number of columns on the field and the number of trains. Each of the following three lines contains the sequence of *n* character, representing the row of the field where the game is on. Philip's initial position is marked as 's', he is in the leftmost column. Each of the *k* trains is marked by some sequence of identical uppercase letters of the English alphabet, located in one line. Distinct trains are represented by distinct letters. Character '.' represents an empty cell, that is, the cell that doesn't contain either Philip or the trains.
For each set of the input data print on a single line word YES, if it is possible to win the game and word NO otherwise.
[ "2\n16 4\n...AAAAA........\ns.BBB......CCCCC\n........DDDDD...\n16 4\n...AAAAA........\ns.BBB....CCCCC..\n.......DDDDD....\n", "2\n10 4\ns.ZZ......\n.....AAABB\n.YYYYYY...\n10 4\ns.ZZ......\n....AAAABB\n.YYYYYY...\n" ]
[ "YES\nNO\n", "YES\nNO\n" ]
In the first set of the input of the first sample Philip must first go forward and go down to the third row of the field, then go only forward, then go forward and climb to the second row, go forward again and go up to the first row. After that way no train blocks Philip's path, so he can go straight to the end of the tunnel. Note that in this problem the challenges are restricted to tests that contain only one testset.
750
[]
1,453,383,136
2,147,483,647
Python 3
TIME_LIMIT_EXCEEDED
TESTS
2
1,000
0
t = int(input()) for _ in range(t): n,k = map(int,input().split()) tunnel = [input() for _ in range(3)] def dfs_walk(x,y): if y > 2 or y < 0: return False if x >= n-1: return True if (tunnel[y][x] != 's') and not ( tunnel[y][x] == tunnel[y][x+1] == '.'): return False return ( dfs_train(x+1,y-1) or dfs_train(x+1,y ) or dfs_train(x+1,y+1) ) def dfs_train(x,y): if y > 2 or y < 0: return False if x >= n-2: return True if not (tunnel[y][x] == tunnel[y][x+1] == tunnel[y][x+2] == '.'): return False return dfs_walk(x+2,y) def start_loc(): for i in range(3): if not tunnel[i].find('s'): return i f = dfs_walk(0,start_loc()) print(("NO","YES")[f])
Title: Phillip and Trains Time Limit: None seconds Memory Limit: None megabytes Problem Description: The mobile application store has a new game called "Subway Roller". The protagonist of the game Philip is located in one end of the tunnel and wants to get out of the other one. The tunnel is a rectangular field consisting of three rows and *n* columns. At the beginning of the game the hero is in some cell of the leftmost column. Some number of trains rides towards the hero. Each train consists of two or more neighbouring cells in some row of the field. All trains are moving from right to left at a speed of two cells per second, and the hero runs from left to right at the speed of one cell per second. For simplicity, the game is implemented so that the hero and the trains move in turns. First, the hero moves one cell to the right, then one square up or down, or stays idle. Then all the trains move twice simultaneously one cell to the left. Thus, in one move, Philip definitely makes a move to the right and can move up or down. If at any point, Philip is in the same cell with a train, he loses. If the train reaches the left column, it continues to move as before, leaving the tunnel. Your task is to answer the question whether there is a sequence of movements of Philip, such that he would be able to get to the rightmost column. Input Specification: Each test contains from one to ten sets of the input data. The first line of the test contains a single integer *t* (1<=≤<=*t*<=≤<=10 for pretests and tests or *t*<==<=1 for hacks; see the Notes section for details) — the number of sets. Then follows the description of *t* sets of the input data. The first line of the description of each set contains two integers *n*,<=*k* (2<=≤<=*n*<=≤<=100,<=1<=≤<=*k*<=≤<=26) — the number of columns on the field and the number of trains. Each of the following three lines contains the sequence of *n* character, representing the row of the field where the game is on. Philip's initial position is marked as 's', he is in the leftmost column. Each of the *k* trains is marked by some sequence of identical uppercase letters of the English alphabet, located in one line. Distinct trains are represented by distinct letters. Character '.' represents an empty cell, that is, the cell that doesn't contain either Philip or the trains. Output Specification: For each set of the input data print on a single line word YES, if it is possible to win the game and word NO otherwise. Demo Input: ['2\n16 4\n...AAAAA........\ns.BBB......CCCCC\n........DDDDD...\n16 4\n...AAAAA........\ns.BBB....CCCCC..\n.......DDDDD....\n', '2\n10 4\ns.ZZ......\n.....AAABB\n.YYYYYY...\n10 4\ns.ZZ......\n....AAAABB\n.YYYYYY...\n'] Demo Output: ['YES\nNO\n', 'YES\nNO\n'] Note: In the first set of the input of the first sample Philip must first go forward and go down to the third row of the field, then go only forward, then go forward and climb to the second row, go forward again and go up to the first row. After that way no train blocks Philip's path, so he can go straight to the end of the tunnel. Note that in this problem the challenges are restricted to tests that contain only one testset.
```python t = int(input()) for _ in range(t): n,k = map(int,input().split()) tunnel = [input() for _ in range(3)] def dfs_walk(x,y): if y > 2 or y < 0: return False if x >= n-1: return True if (tunnel[y][x] != 's') and not ( tunnel[y][x] == tunnel[y][x+1] == '.'): return False return ( dfs_train(x+1,y-1) or dfs_train(x+1,y ) or dfs_train(x+1,y+1) ) def dfs_train(x,y): if y > 2 or y < 0: return False if x >= n-2: return True if not (tunnel[y][x] == tunnel[y][x+1] == tunnel[y][x+2] == '.'): return False return dfs_walk(x+2,y) def start_loc(): for i in range(3): if not tunnel[i].find('s'): return i f = dfs_walk(0,start_loc()) print(("NO","YES")[f]) ```
0
131
B
Opposites Attract
PROGRAMMING
1,200
[ "implementation", "math" ]
null
null
Everybody knows that opposites attract. That is the key principle of the "Perfect Matching" dating agency. The "Perfect Matching" matchmakers have classified each registered customer by his interests and assigned to the *i*-th client number *t**i* (<=-<=10<=≤<=*t**i*<=≤<=10). Of course, one number can be assigned to any number of customers. "Perfect Matching" wants to advertise its services and publish the number of opposite couples, that is, the couples who have opposite values of *t*. Each couple consists of exactly two clients. The customer can be included in a couple an arbitrary number of times. Help the agency and write the program that will find the sought number by the given sequence *t*1,<=*t*2,<=...,<=*t**n*. For example, if *t*<==<=(1,<=<=-<=1,<=1,<=<=-<=1), then any two elements *t**i* and *t**j* form a couple if *i* and *j* have different parity. Consequently, in this case the sought number equals 4. Of course, a client can't form a couple with him/herself.
The first line of the input data contains an integer *n* (1<=≤<=*n*<=≤<=105) which represents the number of registered clients of the "Couple Matching". The second line contains a sequence of integers *t*1,<=*t*2,<=...,<=*t**n* (<=-<=10<=≤<=*t**i*<=≤<=10), *t**i* — is the parameter of the *i*-th customer that has been assigned to the customer by the result of the analysis of his interests.
Print the number of couples of customs with opposite *t*. The opposite number for *x* is number <=-<=*x* (0 is opposite to itself). Couples that only differ in the clients' order are considered the same. Note that the answer to the problem can be large enough, so you must use the 64-bit integer type for calculations. Please, do not use the %lld specificator to read or write 64-bit integers in С++. It is preferred to use cin, cout streams or the %I64d specificator.
[ "5\n-3 3 0 0 3\n", "3\n0 0 0\n" ]
[ "3\n", "3\n" ]
In the first sample the couples of opposite clients are: (1,2), (1,5) и (3,4). In the second sample any couple of clients is opposite.
1,000
[ { "input": "5\n-3 3 0 0 3", "output": "3" }, { "input": "3\n0 0 0", "output": "3" }, { "input": "1\n0", "output": "0" }, { "input": "1\n5", "output": "0" }, { "input": "2\n0 0", "output": "1" }, { "input": "2\n-3 3", "output": "1" }, { "input": "2\n1 5", "output": "0" }, { "input": "4\n1 -1 1 -1", "output": "4" }, { "input": "10\n1 -1 2 -2 3 -3 4 -4 0 0", "output": "5" }, { "input": "5\n0 0 0 0 0", "output": "10" }, { "input": "4\n4 4 4 -1", "output": "0" }, { "input": "2\n10 -10", "output": "1" }, { "input": "2\n-10 10", "output": "1" }, { "input": "3\n-1 -1 2", "output": "0" }, { "input": "2\n-1 2", "output": "0" }, { "input": "7\n0 10 -10 10 -10 10 10", "output": "8" }, { "input": "5\n-3 2 1 -1 3", "output": "2" }, { "input": "4\n-10 10 -10 10", "output": "4" }, { "input": "4\n1 -1 2 -2", "output": "2" } ]
1,694,022,162
2,147,483,647
Python 3
TIME_LIMIT_EXCEEDED
TESTS
7
2,000
5,836,800
n = int(input()) nums = input() pos = [] neg = [] zeroes = 0 for num in nums.split(" "): if int(num) > 0: pos.append(int(num)) elif int(num) < 0: neg.append(int(num)) else: zeroes += 1 # Since 0 can be matches with any other zero, this can be achieved with the combinations formula matches = zeroes * (zeroes - 1) // 2 # Now for postitive and negative numbers for a in range(len(pos)): for b in range(len(neg)): if -pos[a] == neg[b]: matches += 1 print(matches)
Title: Opposites Attract Time Limit: None seconds Memory Limit: None megabytes Problem Description: Everybody knows that opposites attract. That is the key principle of the "Perfect Matching" dating agency. The "Perfect Matching" matchmakers have classified each registered customer by his interests and assigned to the *i*-th client number *t**i* (<=-<=10<=≤<=*t**i*<=≤<=10). Of course, one number can be assigned to any number of customers. "Perfect Matching" wants to advertise its services and publish the number of opposite couples, that is, the couples who have opposite values of *t*. Each couple consists of exactly two clients. The customer can be included in a couple an arbitrary number of times. Help the agency and write the program that will find the sought number by the given sequence *t*1,<=*t*2,<=...,<=*t**n*. For example, if *t*<==<=(1,<=<=-<=1,<=1,<=<=-<=1), then any two elements *t**i* and *t**j* form a couple if *i* and *j* have different parity. Consequently, in this case the sought number equals 4. Of course, a client can't form a couple with him/herself. Input Specification: The first line of the input data contains an integer *n* (1<=≤<=*n*<=≤<=105) which represents the number of registered clients of the "Couple Matching". The second line contains a sequence of integers *t*1,<=*t*2,<=...,<=*t**n* (<=-<=10<=≤<=*t**i*<=≤<=10), *t**i* — is the parameter of the *i*-th customer that has been assigned to the customer by the result of the analysis of his interests. Output Specification: Print the number of couples of customs with opposite *t*. The opposite number for *x* is number <=-<=*x* (0 is opposite to itself). Couples that only differ in the clients' order are considered the same. Note that the answer to the problem can be large enough, so you must use the 64-bit integer type for calculations. Please, do not use the %lld specificator to read or write 64-bit integers in С++. It is preferred to use cin, cout streams or the %I64d specificator. Demo Input: ['5\n-3 3 0 0 3\n', '3\n0 0 0\n'] Demo Output: ['3\n', '3\n'] Note: In the first sample the couples of opposite clients are: (1,2), (1,5) и (3,4). In the second sample any couple of clients is opposite.
```python n = int(input()) nums = input() pos = [] neg = [] zeroes = 0 for num in nums.split(" "): if int(num) > 0: pos.append(int(num)) elif int(num) < 0: neg.append(int(num)) else: zeroes += 1 # Since 0 can be matches with any other zero, this can be achieved with the combinations formula matches = zeroes * (zeroes - 1) // 2 # Now for postitive and negative numbers for a in range(len(pos)): for b in range(len(neg)): if -pos[a] == neg[b]: matches += 1 print(matches) ```
0
797
C
Minimal string
PROGRAMMING
1,700
[ "data structures", "greedy", "strings" ]
null
null
Petya recieved a gift of a string *s* with length up to 105 characters for his birthday. He took two more empty strings *t* and *u* and decided to play a game. This game has two possible moves: - Extract the first character of *s* and append *t* with this character. - Extract the last character of *t* and append *u* with this character. Petya wants to get strings *s* and *t* empty and string *u* lexicographically minimal. You should write a program that will help Petya win the game.
First line contains non-empty string *s* (1<=≤<=|*s*|<=≤<=105), consisting of lowercase English letters.
Print resulting string *u*.
[ "cab\n", "acdb\n" ]
[ "abc\n", "abdc\n" ]
none
0
[ { "input": "cab", "output": "abc" }, { "input": "acdb", "output": "abdc" }, { "input": "a", "output": "a" }, { "input": "ab", "output": "ab" }, { "input": "ba", "output": "ab" }, { "input": "dijee", "output": "deeji" }, { "input": "bhrmc", "output": "bcmrh" }, { "input": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", "output": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" }, { "input": "bababaaababaabbbbbabbbbbbaaabbabaaaaabbbbbaaaabbbbabaabaabababbbabbabbabaaababbabbababaaaaabaaaabbba", "output": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaabbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb" }, { "input": "bccbbcccbccbacacbaccaababcbaababaaaaabcaaabcaacbabcaababaabaccacacccbacbcacbbbaacaaccccabbbbacbcbbba", "output": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaabbbcbcbbbbcccccbbbccbcbccccccbbbcbbccbcbbbbcbbccbccbccbcccbbccb" }, { "input": "eejahjfbbcdhbieiigaihidhageiechaadieecaaehcehjbddgcjgagdfgffdaaihbecebdjhjagghecdhbhdfbedhfhfafbjajg", "output": "aaaaaaaaaaaaagjjbffhfhdebfdhbhdcehggjhjdbecebhidffgfdggjcgddbjhecheceeidhceieghdihigiieibhdcbbfjhjee" }, { "input": "bnrdfnybkzepmluyrhofwnwvfmkdwolvyzrqhuhztvlwjldqmoyxzytpfmrgouymeupxrvpbesyxixnrfbxnqcwgmgjstknqtwrr", "output": "bbbbcggjknqrrwttsmwqnxfrnxixysepvrxpuemyuogrmfptyzxyomqdljwlvtzhuhqrzyvlowdkmfvwnwfohryulmpezkynfdrn" }, { "input": "bcaeaae", "output": "aaaecbe" }, { "input": "edcadcbcdd", "output": "abccdcddde" }, { "input": "a", "output": "a" }, { "input": "a", "output": "a" }, { "input": "a", "output": "a" }, { "input": "b", "output": "b" }, { "input": "b", "output": "b" }, { "input": "a", "output": "a" }, { "input": "c", "output": "c" }, { "input": "a", "output": "a" }, { "input": "b", "output": "b" }, { "input": "c", "output": "c" }, { "input": "b", "output": "b" }, { "input": "a", "output": "a" }, { "input": "e", "output": "e" }, { "input": "b", "output": "b" }, { "input": "b", "output": "b" }, { "input": "aa", "output": "aa" }, { "input": "aa", "output": "aa" }, { "input": "aa", "output": "aa" }, { "input": "aa", "output": "aa" }, { "input": "bb", "output": "bb" }, { "input": "bb", "output": "bb" }, { "input": "ba", "output": "ab" }, { "input": "ca", "output": "ac" }, { "input": "ab", "output": "ab" }, { "input": "cb", "output": "bc" }, { "input": "bb", "output": "bb" }, { "input": "aa", "output": "aa" }, { "input": "da", "output": "ad" }, { "input": "ab", "output": "ab" }, { "input": "cd", "output": "cd" }, { "input": "aaa", "output": "aaa" }, { "input": "aaa", "output": "aaa" }, { "input": "aaa", "output": "aaa" }, { "input": "aab", "output": "aab" }, { "input": "aaa", "output": "aaa" }, { "input": "baa", "output": "aab" }, { "input": "bab", "output": "abb" }, { "input": "baa", "output": "aab" }, { "input": "ccc", "output": "ccc" }, { "input": "ddd", "output": "ddd" }, { "input": "ccd", "output": "ccd" }, { "input": "bca", "output": "acb" }, { "input": "cde", "output": "cde" }, { "input": "ece", "output": "cee" }, { "input": "bdd", "output": "bdd" }, { "input": "aaaa", "output": "aaaa" }, { "input": "aaaa", "output": "aaaa" }, { "input": "aaaa", "output": "aaaa" }, { "input": "abaa", "output": "aaab" }, { "input": "abab", "output": "aabb" }, { "input": "bbbb", "output": "bbbb" }, { "input": "bbba", "output": "abbb" }, { "input": "caba", "output": "aabc" }, { "input": "ccbb", "output": "bbcc" }, { "input": "abac", "output": "aabc" }, { "input": "daba", "output": "aabd" }, { "input": "cdbb", "output": "bbdc" }, { "input": "bddd", "output": "bddd" }, { "input": "dacb", "output": "abcd" }, { "input": "abcc", "output": "abcc" }, { "input": "aaaaa", "output": "aaaaa" }, { "input": "aaaaa", "output": "aaaaa" }, { "input": "aaaaa", "output": "aaaaa" }, { "input": "baaab", "output": "aaabb" }, { "input": "aabbb", "output": "aabbb" }, { "input": "aabaa", "output": "aaaab" }, { "input": "abcba", "output": "aabcb" }, { "input": "bacbc", "output": "abbcc" }, { "input": "bacba", "output": "aabcb" }, { "input": "bdbda", "output": "adbdb" }, { "input": "accbb", "output": "abbcc" }, { "input": "dbccc", "output": "bcccd" }, { "input": "decca", "output": "acced" }, { "input": "dbbdd", "output": "bbddd" }, { "input": "accec", "output": "accce" }, { "input": "aaaaaa", "output": "aaaaaa" }, { "input": "aaaaaa", "output": "aaaaaa" }, { "input": "aaaaaa", "output": "aaaaaa" }, { "input": "bbbbab", "output": "abbbbb" }, { "input": "bbbbab", "output": "abbbbb" }, { "input": "aaaaba", "output": "aaaaab" }, { "input": "cbbbcc", "output": "bbbccc" }, { "input": "aaacac", "output": "aaaacc" }, { "input": "bacbbc", "output": "abbbcc" }, { "input": "cacacc", "output": "aacccc" }, { "input": "badbdc", "output": "abbcdd" }, { "input": "ddadad", "output": "aadddd" }, { "input": "ccdece", "output": "cccede" }, { "input": "eecade", "output": "acdeee" }, { "input": "eabdcb", "output": "abbcde" }, { "input": "aaaaaaa", "output": "aaaaaaa" }, { "input": "aaaaaaa", "output": "aaaaaaa" }, { "input": "aaaaaaa", "output": "aaaaaaa" }, { "input": "aaabbaa", "output": "aaaaabb" }, { "input": "baaabab", "output": "aaaabbb" }, { "input": "bbababa", "output": "aaabbbb" }, { "input": "bcccacc", "output": "acccbcc" }, { "input": "cbbcccc", "output": "bbccccc" }, { "input": "abacaaa", "output": "aaaaacb" }, { "input": "ccdbdac", "output": "acdbdcc" }, { "input": "bbacaba", "output": "aaabcbb" }, { "input": "abbaccc", "output": "aabbccc" }, { "input": "bdcbcab", "output": "abcbcdb" }, { "input": "dabcbce", "output": "abbccde" }, { "input": "abaaabe", "output": "aaaabbe" }, { "input": "aaaaaaaa", "output": "aaaaaaaa" }, { "input": "aaaaaaaa", "output": "aaaaaaaa" }, { "input": "aaaaaaaa", "output": "aaaaaaaa" }, { "input": "ababbbba", "output": "aaabbbbb" }, { "input": "aaaaaaba", "output": "aaaaaaab" }, { "input": "babbbaab", "output": "aaabbbbb" }, { "input": "bcaccaab", "output": "aaabcccb" }, { "input": "bbccaabc", "output": "aabccbbc" }, { "input": "cacaaaac", "output": "aaaaaccc" }, { "input": "daacbddc", "output": "aabccddd" }, { "input": "cdbdcdaa", "output": "aadcdbdc" }, { "input": "bccbdacd", "output": "acdbccbd" }, { "input": "abbeaade", "output": "aaadebbe" }, { "input": "ccabecba", "output": "aabcebcc" }, { "input": "ececaead", "output": "aadecece" }, { "input": "aaaaaaaaa", "output": "aaaaaaaaa" }, { "input": "aaaaaaaaa", "output": "aaaaaaaaa" }, { "input": "aaaaaaaaa", "output": "aaaaaaaaa" }, { "input": "aabaaabbb", "output": "aaaaabbbb" }, { "input": "abbbbbaab", "output": "aaabbbbbb" }, { "input": "bbbaababb", "output": "aaabbbbbb" }, { "input": "babcaaccb", "output": "aaabcccbb" }, { "input": "ccbcabaac", "output": "aaabcbccc" }, { "input": "caaaccccb", "output": "aaabccccc" }, { "input": "abbcdbddb", "output": "abbbbdddc" }, { "input": "dbcaacbbb", "output": "aabbbccbd" }, { "input": "cadcbddac", "output": "aacddbcdc" }, { "input": "ecebadadb", "output": "aabddbece" }, { "input": "bdbeeccdd", "output": "bbccddeed" }, { "input": "daaedecda", "output": "aaadceded" }, { "input": "aaaaaaaaaa", "output": "aaaaaaaaaa" }, { "input": "aaaaaaaaaa", "output": "aaaaaaaaaa" }, { "input": "aaaaaaaaaa", "output": "aaaaaaaaaa" }, { "input": "abaaaaabbb", "output": "aaaaaabbbb" }, { "input": "bbaaaabaaa", "output": "aaaaaaabbb" }, { "input": "bbabbaaaaa", "output": "aaaaaabbbb" }, { "input": "cbaabcaacc", "output": "aaaacbbccc" }, { "input": "aaaaccccab", "output": "aaaaabcccc" }, { "input": "bccaccaacc", "output": "aaaccccbcc" }, { "input": "dbdccdcacd", "output": "accdccdbdd" }, { "input": "caaddaaccb", "output": "aaaabccddc" }, { "input": "adbbabcbdc", "output": "aabbbbccdd" }, { "input": "cdeabdbbad", "output": "aabbdbdedc" }, { "input": "eeddcbeeec", "output": "bcceeeddee" }, { "input": "bbcebddeba", "output": "abeddbecbb" } ]
1,584,976,556
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
11
124
0
s = input() t = [] u = [] s1 = sorted(s) j = 0 for i in s: if i == s1[j]: u.append(i) j += 1 else: t.append(i) s = u + t[::-1] ans = "" for i in s: ans += i print(ans)
Title: Minimal string Time Limit: None seconds Memory Limit: None megabytes Problem Description: Petya recieved a gift of a string *s* with length up to 105 characters for his birthday. He took two more empty strings *t* and *u* and decided to play a game. This game has two possible moves: - Extract the first character of *s* and append *t* with this character. - Extract the last character of *t* and append *u* with this character. Petya wants to get strings *s* and *t* empty and string *u* lexicographically minimal. You should write a program that will help Petya win the game. Input Specification: First line contains non-empty string *s* (1<=≤<=|*s*|<=≤<=105), consisting of lowercase English letters. Output Specification: Print resulting string *u*. Demo Input: ['cab\n', 'acdb\n'] Demo Output: ['abc\n', 'abdc\n'] Note: none
```python s = input() t = [] u = [] s1 = sorted(s) j = 0 for i in s: if i == s1[j]: u.append(i) j += 1 else: t.append(i) s = u + t[::-1] ans = "" for i in s: ans += i print(ans) ```
0
977
B
Two-gram
PROGRAMMING
900
[ "implementation", "strings" ]
null
null
Two-gram is an ordered pair (i.e. string of length two) of capital Latin letters. For example, "AZ", "AA", "ZA" — three distinct two-grams. You are given a string $s$ consisting of $n$ capital Latin letters. Your task is to find any two-gram contained in the given string as a substring (i.e. two consecutive characters of the string) maximal number of times. For example, for string $s$ = "BBAABBBA" the answer is two-gram "BB", which contained in $s$ three times. In other words, find any most frequent two-gram. Note that occurrences of the two-gram can overlap with each other.
The first line of the input contains integer number $n$ ($2 \le n \le 100$) — the length of string $s$. The second line of the input contains the string $s$ consisting of $n$ capital Latin letters.
Print the only line containing exactly two capital Latin letters — any two-gram contained in the given string $s$ as a substring (i.e. two consecutive characters of the string) maximal number of times.
[ "7\nABACABA\n", "5\nZZZAA\n" ]
[ "AB\n", "ZZ\n" ]
In the first example "BA" is also valid answer. In the second example the only two-gram "ZZ" can be printed because it contained in the string "ZZZAA" two times.
0
[ { "input": "7\nABACABA", "output": "AB" }, { "input": "5\nZZZAA", "output": "ZZ" }, { "input": "26\nQWERTYUIOPASDFGHJKLZXCVBNM", "output": "AS" }, { "input": "2\nQA", "output": "QA" }, { "input": "2\nWW", "output": "WW" }, { "input": "11\nGGRRAATTZZZ", "output": "ZZ" }, { "input": "50\nNYQAHBYYOXLTRYQDMVENEMAQNBAKGLGQOLXNAIFNQTOCLNNQIA", "output": "NQ" }, { "input": "100\nURXCAIZFIBNJTPCZHBQIBCILLPXZCFGMKKZMNPLCYGAVJVIBMCZEBSJWPSCPQDYCTTKPOKIJRSKIZPDGCHVOUTMPNECYORSFZFNC", "output": "IB" }, { "input": "100\nAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA", "output": "AA" }, { "input": "10\nSQSQSQSQTG", "output": "SQ" }, { "input": "5\nAZAZA", "output": "AZ" }, { "input": "15\nMIRZOYANOVECLOX", "output": "AN" }, { "input": "9\nEGORLETOV", "output": "EG" }, { "input": "8\nPUTINVOR", "output": "IN" }, { "input": "7\nKADUROV", "output": "AD" }, { "input": "6\nAZAZAZ", "output": "AZ" }, { "input": "3\nLOL", "output": "LO" }, { "input": "3\nKEK", "output": "EK" }, { "input": "5\nFUFEL", "output": "EL" }, { "input": "9\nMIKEPIDOR", "output": "DO" }, { "input": "9\nAAAAAAAAA", "output": "AA" }, { "input": "23\nAABBBAAACCCCCAAADDDDDDD", "output": "DD" } ]
1,694,175,718
2,147,483,647
Python 3
OK
TESTS
22
31
0
n = int(input()) s = input() max_s = "" m = 0 i = 1 count = 0 while i < len(s): temp = "".join(list(s)[i-1:i+1:]) res = sum(1 for i in range(len(s)) if s.startswith(temp, i)) if res > m: max_s = temp m = res i += 1 print(max_s)
Title: Two-gram Time Limit: None seconds Memory Limit: None megabytes Problem Description: Two-gram is an ordered pair (i.e. string of length two) of capital Latin letters. For example, "AZ", "AA", "ZA" — three distinct two-grams. You are given a string $s$ consisting of $n$ capital Latin letters. Your task is to find any two-gram contained in the given string as a substring (i.e. two consecutive characters of the string) maximal number of times. For example, for string $s$ = "BBAABBBA" the answer is two-gram "BB", which contained in $s$ three times. In other words, find any most frequent two-gram. Note that occurrences of the two-gram can overlap with each other. Input Specification: The first line of the input contains integer number $n$ ($2 \le n \le 100$) — the length of string $s$. The second line of the input contains the string $s$ consisting of $n$ capital Latin letters. Output Specification: Print the only line containing exactly two capital Latin letters — any two-gram contained in the given string $s$ as a substring (i.e. two consecutive characters of the string) maximal number of times. Demo Input: ['7\nABACABA\n', '5\nZZZAA\n'] Demo Output: ['AB\n', 'ZZ\n'] Note: In the first example "BA" is also valid answer. In the second example the only two-gram "ZZ" can be printed because it contained in the string "ZZZAA" two times.
```python n = int(input()) s = input() max_s = "" m = 0 i = 1 count = 0 while i < len(s): temp = "".join(list(s)[i-1:i+1:]) res = sum(1 for i in range(len(s)) if s.startswith(temp, i)) if res > m: max_s = temp m = res i += 1 print(max_s) ```
3
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,661,481,057
2,147,483,647
Python 3
OK
TESTS
40
92
0
s=[* input()] t=[* input()] t.reverse() if s==t: print("YES") else: print("NO")
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 s=[* input()] t=[* input()] t.reverse() if s==t: print("YES") else: print("NO") ```
3.977
52
A
123-sequence
PROGRAMMING
900
[ "implementation" ]
A. 123-sequence
2
256
There is a given sequence of integers *a*1,<=*a*2,<=...,<=*a**n*, where every number is from 1 to 3 inclusively. You have to replace the minimum number of numbers in it so that all the numbers in the sequence are equal to each other.
The first line contains an integer *n* (1<=≤<=*n*<=≤<=106). The second line contains a sequence of integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=3).
Print the minimum number of replacements needed to be performed to make all the numbers in the sequence equal.
[ "9\n1 3 2 2 2 1 1 2 3\n" ]
[ "5\n" ]
In the example all the numbers equal to 1 and 3 should be replaced by 2.
500
[ { "input": "9\n1 3 2 2 2 1 1 2 3", "output": "5" }, { "input": "6\n3 3 2 2 1 3", "output": "3" }, { "input": "12\n3 1 3 1 2 1 3 2 2 1 2 1", "output": "7" }, { "input": "15\n3 2 1 1 1 1 3 2 2 3 3 1 2 3 2", "output": "10" }, { "input": "2\n2 1", "output": "1" }, { "input": "2\n3 2", "output": "1" }, { "input": "2\n3 1", "output": "1" }, { "input": "18\n2 3 2 1 2 3 2 1 2 3 3 3 1 2 3 3 3 2", "output": "10" }, { "input": "30\n2 1 3 2 3 2 2 2 2 3 2 2 3 2 1 1 3 1 3 2 1 2 3 1 1 3 3 1 3 1", "output": "19" }, { "input": "1\n1", "output": "0" }, { "input": "1\n2", "output": "0" }, { "input": "1\n3", "output": "0" } ]
1,446,581,759
2,147,483,647
Python 3
OK
TESTS
23
780
10,854,400
n = int(input()) counts = 4 * [0] for a in map(int, input().split()): counts[a] += 1 result = n - max(counts) print(result)
Title: 123-sequence Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: There is a given sequence of integers *a*1,<=*a*2,<=...,<=*a**n*, where every number is from 1 to 3 inclusively. You have to replace the minimum number of numbers in it so that all the numbers in the sequence are equal to each other. Input Specification: The first line contains an integer *n* (1<=≤<=*n*<=≤<=106). The second line contains a sequence of integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=3). Output Specification: Print the minimum number of replacements needed to be performed to make all the numbers in the sequence equal. Demo Input: ['9\n1 3 2 2 2 1 1 2 3\n'] Demo Output: ['5\n'] Note: In the example all the numbers equal to 1 and 3 should be replaced by 2.
```python n = int(input()) counts = 4 * [0] for a in map(int, input().split()): counts[a] += 1 result = n - max(counts) print(result) ```
3.784782
366
C
Dima and Salad
PROGRAMMING
1,900
[ "dp" ]
null
null
Dima, Inna and Seryozha have gathered in a room. That's right, someone's got to go. To cheer Seryozha up and inspire him to have a walk, Inna decided to cook something. Dima and Seryozha have *n* fruits in the fridge. Each fruit has two parameters: the taste and the number of calories. Inna decided to make a fruit salad, so she wants to take some fruits from the fridge for it. Inna follows a certain principle as she chooses the fruits: the total taste to the total calories ratio of the chosen fruits must equal *k*. In other words, , where *a**j* is the taste of the *j*-th chosen fruit and *b**j* is its calories. Inna hasn't chosen the fruits yet, she is thinking: what is the maximum taste of the chosen fruits if she strictly follows her principle? Help Inna solve this culinary problem — now the happiness of a young couple is in your hands! Inna loves Dima very much so she wants to make the salad from at least one fruit.
The first line of the input contains two integers *n*, *k* (1<=≤<=*n*<=≤<=100,<=1<=≤<=*k*<=≤<=10). The second line of the input contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=100) — the fruits' tastes. The third line of the input contains *n* integers *b*1,<=*b*2,<=...,<=*b**n* (1<=≤<=*b**i*<=≤<=100) — the fruits' calories. Fruit number *i* has taste *a**i* and calories *b**i*.
If there is no way Inna can choose the fruits for the salad, print in the single line number -1. Otherwise, print a single integer — the maximum possible sum of the taste values of the chosen fruits.
[ "3 2\n10 8 1\n2 7 1\n", "5 3\n4 4 4 4 4\n2 2 2 2 2\n" ]
[ "18\n", "-1\n" ]
In the first test sample we can get the total taste of the fruits equal to 18 if we choose fruit number 1 and fruit number 2, then the total calories will equal 9. The condition <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/f7429bb0084a26268b364ce919a5231a4d9e38a9.png" style="max-width: 100.0%;max-height: 100.0%;"/> fulfills, that's exactly what Inna wants. In the second test sample we cannot choose the fruits so as to follow Inna's principle.
1,500
[ { "input": "3 2\n10 8 1\n2 7 1", "output": "18" }, { "input": "5 3\n4 4 4 4 4\n2 2 2 2 2", "output": "-1" }, { "input": "1 1\n1\n1", "output": "1" }, { "input": "1 1\n1\n2", "output": "-1" }, { "input": "2 1\n75 65\n16 60", "output": "-1" }, { "input": "21 8\n50 39 28 27 58 46 95 46 50 8 28 94 61 58 57 7 1 38 9 34 12\n94 1 77 1 17 40 99 31 26 1 1 1 15 7 6 1 85 3 32 65 78", "output": "352" }, { "input": "16 2\n60 5 39 38 43 10 99 2 88 24 2 73 21 57 60 69\n59 92 96 9 1 15 4 42 23 7 100 10 90 97 13 2", "output": "528" }, { "input": "35 6\n99 26 11 66 36 8 38 7 68 23 14 5 89 14 14 95 33 83 74 21 81 98 86 17 16 25 51 44 90 17 12 23 77 15 63\n5 2 33 1 37 77 3 54 2 69 28 2 45 2 60 10 84 26 27 77 95 65 3 5 47 63 86 7 62 64 13 1 2 22 62", "output": "894" }, { "input": "55 1\n42 45 79 90 55 14 46 34 98 30 26 100 26 61 52 85 62 26 17 32 23 76 24 35 60 41 2 94 66 16 48 81 81 30 9 23 91 71 62 76 83 10 11 37 15 45 85 31 38 42 42 34 86 49 78\n43 37 78 2 48 79 7 55 47 7 75 78 100 10 11 4 83 82 26 95 70 67 9 34 10 85 32 60 28 98 81 78 52 47 91 51 98 33 26 40 82 46 60 27 75 9 35 11 65 61 28 62 11 95 72", "output": "2671" }, { "input": "21 6\n1 94 34 73 75 73 7 70 31 73 54 81 78 37 74 82 34 49 67 47 98\n79 77 84 42 28 49 81 98 64 62 83 2 40 92 1 87 86 95 69 45 41", "output": "-1" }, { "input": "37 10\n29 83 52 50 29 8 24 6 15 95 94 41 2 20 93 86 96 6 64 92 93 73 88 26 91 60 17 4 70 32 89 87 92 89 43 33 94\n81 51 73 43 13 47 6 92 79 3 71 65 1 46 48 68 2 24 17 85 84 61 13 59 21 90 83 6 87 3 3 66 65 14 32 98 21", "output": "520" }, { "input": "60 3\n97 90 34 70 30 57 18 58 87 93 32 93 14 45 24 97 99 61 75 44 11 62 76 52 29 54 24 8 21 79 10 37 54 2 38 72 65 24 30 42 70 96 71 58 91 1 35 22 43 80 55 26 90 7 17 34 49 12 44 29\n28 63 66 7 64 100 59 51 71 90 14 10 66 86 35 44 16 74 40 3 77 19 51 12 58 71 88 7 74 7 89 28 92 25 4 37 76 33 12 2 62 46 36 23 93 20 86 14 65 69 37 19 47 9 7 25 40 44 30 71", "output": "1374" }, { "input": "80 3\n84 61 7 14 79 81 16 61 38 62 16 71 14 6 56 91 91 94 85 52 80 51 97 26 46 39 87 76 69 19 57 54 34 65 49 24 35 20 68 40 92 11 35 32 70 89 83 50 18 67 48 82 65 97 100 70 89 42 40 2 91 29 78 92 11 3 59 84 35 11 90 66 30 61 74 55 83 89 98 51\n93 9 7 95 47 3 19 61 69 10 8 58 49 65 4 45 79 64 30 34 59 1 22 37 1 15 20 72 6 34 51 90 1 77 19 64 41 83 90 71 35 64 18 88 1 86 52 92 88 66 68 43 85 55 60 11 27 56 98 89 53 96 19 97 55 85 38 3 34 59 96 65 51 10 1 3 26 3 6 43", "output": "2793" }, { "input": "19 2\n68 24 95 24 94 82 37 87 68 67 59 28 68 5 70 53 80 46 61\n60 74 46 9 40 45 58 51 96 4 42 33 12 40 34 9 58 84 91", "output": "816" }, { "input": "42 5\n2 75 38 94 77 91 37 4 50 56 55 31 87 57 7 44 38 71 91 50 77 92 48 28 92 39 79 66 25 85 44 96 30 46 15 48 76 44 48 18 26 48\n90 46 64 99 17 16 43 90 21 50 91 45 20 4 58 41 97 91 85 47 64 90 27 77 14 4 56 37 1 20 15 82 1 85 29 99 16 13 60 69 8 86", "output": "710" }, { "input": "68 6\n32 34 18 21 1 37 55 5 25 1 1 2 57 54 1 1 1 24 1 1 100 1 2 1 1 19 77 53 1 67 76 81 1 38 1 45 54 88 1 29 96 80 100 1 1 1 1 34 80 1 75 76 93 1 63 67 1 92 26 94 55 1 68 76 57 88 87 4\n95 57 1 1 74 70 29 1 1 1 1 1 17 14 97 4 66 14 1 86 94 7 84 84 71 1 96 73 1 12 19 3 80 1 82 3 37 36 39 1 96 1 85 32 75 38 66 4 70 1 3 1 1 1 8 22 1 1 1 1 37 1 65 1 9 1 5 3", "output": "1830" }, { "input": "88 10\n6 64 43 1 1 1 8 15 39 1 95 2 1 80 36 40 25 2 52 24 29 26 16 45 96 99 1 91 16 97 67 1 39 91 1 41 72 67 93 84 1 12 67 53 26 1 14 39 94 92 28 75 10 16 81 97 77 22 1 1 41 90 51 49 90 74 5 61 1 45 88 1 40 7 4 59 16 33 6 4 92 1 38 20 4 53 10 80\n70 45 1 73 52 1 20 78 68 98 1 95 2 61 1 56 5 70 92 1 99 52 84 87 87 1 76 51 30 20 1 12 4 52 80 63 33 1 1 3 1 12 43 29 51 64 1 82 6 81 1 15 93 74 11 1 41 89 40 40 20 6 80 42 1 1 1 83 3 69 42 2 55 37 7 1 1 1 43 79 79 50 79 68 52 1 77 59", "output": "1750" }, { "input": "11 5\n29 26 61 52 10 50 26 68 85 93 86\n26 32 1 24 2 1 2 4 2 1 52", "output": "330" }, { "input": "27 9\n68 3 3 4 87 74 82 49 10 9 15 2 48 3 74 96 3 21 37 44 4 3 14 14 10 16 72\n1 1 59 1 1 97 1 1 40 1 20 1 9 1 70 1 89 1 1 69 40 4 7 65 1 1 2", "output": "621" }, { "input": "47 4\n35 64 42 41 61 55 66 16 18 65 50 32 26 80 39 65 78 25 3 29 6 88 3 3 17 36 23 84 60 78 62 36 47 36 90 19 6 46 18 98 35 88 94 26 37 63 88\n1 29 1 1 30 1 1 1 1 37 1 75 2 74 41 1 16 1 56 36 1 3 51 1 13 1 1 1 1 1 1 1 58 90 1 1 1 4 1 1 1 1 67 72 1 1 87", "output": "2044" }, { "input": "69 8\n2 1 41 1 72 44 75 23 1 76 5 50 92 56 1 34 1 55 66 20 77 92 94 34 76 63 90 25 29 44 68 53 9 54 87 74 2 4 19 36 1 87 36 17 23 14 89 62 52 40 44 74 72 77 69 11 50 69 3 72 3 1 70 96 90 5 25 49 1\n42 1 1 1 85 19 67 1 22 44 84 1 1 69 1 2 1 75 17 3 55 1 12 23 71 33 3 22 1 59 60 1 1 33 1 1 51 33 1 1 1 8 19 1 2 1 62 34 77 36 87 27 17 1 8 1 68 17 1 14 6 16 1 73 1 1 12 94 1", "output": "1808" } ]
1,553,985,409
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
5
93
307,200
n, k = [int(x) for x in input().split(' ')] taste = [0] + [int(x) for x in input().split(' ')] cal = [0] + [int(x) for x in input().split(' ')] taste_mat = [[0 for _ in range(n+1)] for _ in range(n+1)] cal_mat = [[0 for _ in range(n+1)] for _ in range(n+1)] best_taste = -1 for i in range(1,n+1): for j in range(1,i+1): taste_mat[i][j] = taste[i] + taste_mat[i-1][j] cal_mat[i][j] = cal[i] + cal_mat[i - 1][j] if (taste_mat[i][j] / cal_mat[i][j]) == k: best_taste = taste_mat[i][j] print(best_taste)
Title: Dima and Salad Time Limit: None seconds Memory Limit: None megabytes Problem Description: Dima, Inna and Seryozha have gathered in a room. That's right, someone's got to go. To cheer Seryozha up and inspire him to have a walk, Inna decided to cook something. Dima and Seryozha have *n* fruits in the fridge. Each fruit has two parameters: the taste and the number of calories. Inna decided to make a fruit salad, so she wants to take some fruits from the fridge for it. Inna follows a certain principle as she chooses the fruits: the total taste to the total calories ratio of the chosen fruits must equal *k*. In other words, , where *a**j* is the taste of the *j*-th chosen fruit and *b**j* is its calories. Inna hasn't chosen the fruits yet, she is thinking: what is the maximum taste of the chosen fruits if she strictly follows her principle? Help Inna solve this culinary problem — now the happiness of a young couple is in your hands! Inna loves Dima very much so she wants to make the salad from at least one fruit. Input Specification: The first line of the input contains two integers *n*, *k* (1<=≤<=*n*<=≤<=100,<=1<=≤<=*k*<=≤<=10). The second line of the input contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=100) — the fruits' tastes. The third line of the input contains *n* integers *b*1,<=*b*2,<=...,<=*b**n* (1<=≤<=*b**i*<=≤<=100) — the fruits' calories. Fruit number *i* has taste *a**i* and calories *b**i*. Output Specification: If there is no way Inna can choose the fruits for the salad, print in the single line number -1. Otherwise, print a single integer — the maximum possible sum of the taste values of the chosen fruits. Demo Input: ['3 2\n10 8 1\n2 7 1\n', '5 3\n4 4 4 4 4\n2 2 2 2 2\n'] Demo Output: ['18\n', '-1\n'] Note: In the first test sample we can get the total taste of the fruits equal to 18 if we choose fruit number 1 and fruit number 2, then the total calories will equal 9. The condition <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/f7429bb0084a26268b364ce919a5231a4d9e38a9.png" style="max-width: 100.0%;max-height: 100.0%;"/> fulfills, that's exactly what Inna wants. In the second test sample we cannot choose the fruits so as to follow Inna's principle.
```python n, k = [int(x) for x in input().split(' ')] taste = [0] + [int(x) for x in input().split(' ')] cal = [0] + [int(x) for x in input().split(' ')] taste_mat = [[0 for _ in range(n+1)] for _ in range(n+1)] cal_mat = [[0 for _ in range(n+1)] for _ in range(n+1)] best_taste = -1 for i in range(1,n+1): for j in range(1,i+1): taste_mat[i][j] = taste[i] + taste_mat[i-1][j] cal_mat[i][j] = cal[i] + cal_mat[i - 1][j] if (taste_mat[i][j] / cal_mat[i][j]) == k: best_taste = taste_mat[i][j] print(best_taste) ```
0
296
A
Yaroslav and Permutations
PROGRAMMING
1,100
[ "greedy", "math" ]
null
null
Yaroslav has an array that consists of *n* integers. In one second Yaroslav can swap two neighboring array elements. Now Yaroslav is wondering if he can obtain an array where any two neighboring elements would be distinct in a finite time. Help Yaroslav.
The first line contains integer *n* (1<=≤<=*n*<=≤<=100) — the number of elements in the array. The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=1000) — the array elements.
In the single line print "YES" (without the quotes) if Yaroslav can obtain the array he needs, and "NO" (without the quotes) otherwise.
[ "1\n1\n", "3\n1 1 2\n", "4\n7 7 7 7\n" ]
[ "YES\n", "YES\n", "NO\n" ]
In the first sample the initial array fits well. In the second sample Yaroslav can get array: 1, 2, 1. He can swap the last and the second last elements to obtain it. In the third sample Yarosav can't get the array he needs.
500
[ { "input": "1\n1", "output": "YES" }, { "input": "3\n1 1 2", "output": "YES" }, { "input": "4\n7 7 7 7", "output": "NO" }, { "input": "4\n479 170 465 146", "output": "YES" }, { "input": "5\n996 437 605 996 293", "output": "YES" }, { "input": "6\n727 539 896 668 36 896", "output": "YES" }, { "input": "7\n674 712 674 674 674 674 674", "output": "NO" }, { "input": "8\n742 742 742 742 742 289 742 742", "output": "NO" }, { "input": "9\n730 351 806 806 806 630 85 757 967", "output": "YES" }, { "input": "10\n324 539 83 440 834 640 440 440 440 440", "output": "YES" }, { "input": "7\n925 830 925 98 987 162 356", "output": "YES" }, { "input": "68\n575 32 53 351 151 942 725 967 431 108 192 8 338 458 288 754 384 946 910 210 759 222 589 423 947 507 31 414 169 901 592 763 656 411 360 625 538 549 484 596 42 603 351 292 837 375 21 597 22 349 200 669 485 282 735 54 1000 419 939 901 789 128 468 729 894 649 484 808", "output": "YES" }, { "input": "22\n618 814 515 310 617 936 452 601 250 520 557 799 304 225 9 845 610 990 703 196 486 94", "output": "YES" }, { "input": "44\n459 581 449 449 449 449 449 449 449 623 449 449 449 449 449 449 449 449 889 449 203 273 329 449 449 449 449 449 449 845 882 323 22 449 449 893 449 449 449 449 449 870 449 402", "output": "NO" }, { "input": "90\n424 3 586 183 286 89 427 618 758 833 933 170 155 722 190 977 330 369 693 426 556 435 550 442 513 146 61 719 754 140 424 280 997 688 530 550 438 867 950 194 196 298 417 287 106 489 283 456 735 115 702 317 672 787 264 314 356 186 54 913 809 833 946 314 757 322 559 647 983 482 145 197 223 130 162 536 451 174 467 45 660 293 440 254 25 155 511 746 650 187", "output": "YES" }, { "input": "14\n959 203 478 315 788 788 373 834 488 519 774 764 193 103", "output": "YES" }, { "input": "81\n544 528 528 528 528 4 506 528 32 528 528 528 528 528 528 528 528 975 528 528 528 528 528 528 528 528 528 528 528 528 528 20 528 528 528 528 528 528 528 528 852 528 528 120 528 528 61 11 528 528 528 228 528 165 883 528 488 475 628 528 528 528 528 528 528 597 528 528 528 528 528 528 528 528 528 528 528 412 528 521 925", "output": "NO" }, { "input": "89\n354 356 352 355 355 355 352 354 354 352 355 356 355 352 354 356 354 355 355 354 353 352 352 355 355 356 352 352 353 356 352 353 354 352 355 352 353 353 353 354 353 354 354 353 356 353 353 354 354 354 354 353 352 353 355 356 356 352 356 354 353 352 355 354 356 356 356 354 354 356 354 355 354 355 353 352 354 355 352 355 355 354 356 353 353 352 356 352 353", "output": "YES" }, { "input": "71\n284 284 285 285 285 284 285 284 284 285 284 285 284 284 285 284 285 285 285 285 284 284 285 285 284 284 284 285 284 285 284 285 285 284 284 284 285 284 284 285 285 285 284 284 285 284 285 285 284 285 285 284 285 284 284 284 285 285 284 285 284 285 285 285 285 284 284 285 285 284 285", "output": "NO" }, { "input": "28\n602 216 214 825 814 760 814 28 76 814 814 288 814 814 222 707 11 490 814 543 914 705 814 751 976 814 814 99", "output": "YES" }, { "input": "48\n546 547 914 263 986 945 914 914 509 871 324 914 153 571 914 914 914 528 970 566 544 914 914 914 410 914 914 589 609 222 914 889 691 844 621 68 914 36 914 39 630 749 914 258 945 914 727 26", "output": "YES" }, { "input": "56\n516 76 516 197 516 427 174 516 706 813 94 37 516 815 516 516 937 483 16 516 842 516 638 691 516 635 516 516 453 263 516 516 635 257 125 214 29 81 516 51 362 516 677 516 903 516 949 654 221 924 516 879 516 516 972 516", "output": "YES" }, { "input": "46\n314 723 314 314 314 235 314 314 314 314 270 314 59 972 314 216 816 40 314 314 314 314 314 314 314 381 314 314 314 314 314 314 314 789 314 957 114 942 314 314 29 314 314 72 314 314", "output": "NO" }, { "input": "72\n169 169 169 599 694 81 250 529 865 406 817 169 667 169 965 169 169 663 65 169 903 169 942 763 169 807 169 603 169 169 13 169 169 810 169 291 169 169 169 169 169 169 169 713 169 440 169 169 169 169 169 480 169 169 867 169 169 169 169 169 169 169 169 393 169 169 459 169 99 169 601 800", "output": "NO" }, { "input": "100\n317 316 317 316 317 316 317 316 317 316 316 317 317 316 317 316 316 316 317 316 317 317 316 317 316 316 316 316 316 316 317 316 317 317 317 317 317 317 316 316 316 317 316 317 316 317 316 317 317 316 317 316 317 317 316 317 316 317 316 317 316 316 316 317 317 317 317 317 316 317 317 316 316 316 316 317 317 316 317 316 316 316 316 316 316 317 316 316 317 317 317 317 317 317 317 317 317 316 316 317", "output": "NO" }, { "input": "100\n510 510 510 162 969 32 510 511 510 510 911 183 496 875 903 461 510 510 123 578 510 510 510 510 510 755 510 673 510 510 763 510 510 909 510 435 487 959 807 510 368 788 557 448 284 332 510 949 510 510 777 112 857 926 487 510 510 510 678 510 510 197 829 427 698 704 409 509 510 238 314 851 510 651 510 455 682 510 714 635 973 510 443 878 510 510 510 591 510 24 596 510 43 183 510 510 671 652 214 784", "output": "YES" }, { "input": "100\n476 477 474 476 476 475 473 476 474 475 473 477 476 476 474 476 474 475 476 477 473 473 473 474 474 476 473 473 476 476 475 476 473 474 473 473 477 475 475 475 476 475 477 477 477 476 475 475 475 473 476 477 475 476 477 473 474 477 473 475 476 476 474 477 476 474 473 477 473 475 477 473 476 474 477 473 475 477 473 476 476 475 476 475 474 473 477 473 475 473 477 473 473 474 475 473 477 476 477 474", "output": "YES" }, { "input": "100\n498 498 498 498 498 499 498 499 499 499 498 498 498 498 499 498 499 499 498 499 498 498 498 499 499 499 498 498 499 499 498 498 498 499 498 499 498 498 498 499 498 499 498 498 498 498 499 498 498 499 498 498 499 498 499 499 498 499 499 499 498 498 498 498 499 498 499 498 499 499 499 499 498 498 499 499 498 499 499 498 498 499 499 498 498 499 499 499 498 498 499 498 498 498 499 499 499 498 498 499", "output": "NO" }, { "input": "100\n858 53 816 816 816 816 816 816 816 181 816 816 816 816 579 879 816 948 171 816 816 150 866 816 816 816 897 816 816 816 816 816 816 706 816 539 816 816 816 816 816 816 423 487 816 615 254 816 816 816 816 83 816 816 816 816 816 816 816 816 816 816 816 136 775 999 816 816 816 644 816 816 816 816 927 816 802 816 856 816 816 816 816 816 816 816 816 816 816 700 816 816 816 816 982 477 816 891 806 816", "output": "NO" }, { "input": "100\n167 169 169 167 169 169 167 167 167 167 168 166 170 170 169 170 170 170 169 168 166 167 170 169 167 169 168 169 166 170 166 167 170 166 166 167 169 166 166 169 166 167 168 168 170 167 168 166 168 170 167 168 167 169 169 166 168 167 170 168 167 169 168 169 166 168 168 169 169 166 170 168 167 169 170 168 167 169 168 167 168 168 166 169 170 170 166 166 167 170 167 168 167 167 169 169 166 166 169 167", "output": "YES" }, { "input": "100\n1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000", "output": "NO" }, { "input": "99\n1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000", "output": "NO" }, { "input": "100\n1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 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": "YES" }, { "input": "99\n1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 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": "YES" }, { "input": "2\n1 1", "output": "NO" }, { "input": "1\n1000", "output": "YES" }, { "input": "12\n2 2 4 4 4 4 6 6 6 6 6 6", "output": "YES" } ]
1,625,586,178
2,147,483,647
Python 3
OK
TESTS
37
124
0
n=int(input()) x=list(map(int, input().split())) freq = {} for item in x: if (item in freq): freq[item] += 1 else: freq[item] = 1 p=max(freq.values()) q=sum(freq.values())-p if q>=p or p-q==1: print("YES") else: print("NO")
Title: Yaroslav and Permutations Time Limit: None seconds Memory Limit: None megabytes Problem Description: Yaroslav has an array that consists of *n* integers. In one second Yaroslav can swap two neighboring array elements. Now Yaroslav is wondering if he can obtain an array where any two neighboring elements would be distinct in a finite time. Help Yaroslav. Input Specification: The first line contains integer *n* (1<=≤<=*n*<=≤<=100) — the number of elements in the array. The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=1000) — the array elements. Output Specification: In the single line print "YES" (without the quotes) if Yaroslav can obtain the array he needs, and "NO" (without the quotes) otherwise. Demo Input: ['1\n1\n', '3\n1 1 2\n', '4\n7 7 7 7\n'] Demo Output: ['YES\n', 'YES\n', 'NO\n'] Note: In the first sample the initial array fits well. In the second sample Yaroslav can get array: 1, 2, 1. He can swap the last and the second last elements to obtain it. In the third sample Yarosav can't get the array he needs.
```python n=int(input()) x=list(map(int, input().split())) freq = {} for item in x: if (item in freq): freq[item] += 1 else: freq[item] = 1 p=max(freq.values()) q=sum(freq.values())-p if q>=p or p-q==1: print("YES") else: print("NO") ```
3
887
B
Cubes for Masha
PROGRAMMING
1,300
[ "brute force", "implementation" ]
null
null
Absent-minded Masha got set of *n* cubes for her birthday. At each of 6 faces of each cube, there is exactly one digit from 0 to 9. Masha became interested what is the largest natural *x* such she can make using her new cubes all integers from 1 to *x*. To make a number Masha can rotate her cubes and put them in a row. After that, she looks at upper faces of cubes from left to right and reads the number. The number can't contain leading zeros. It's not required to use all cubes to build a number. Pay attention: Masha can't make digit 6 from digit 9 and vice-versa using cube rotations.
In first line integer *n* is given (1<=≤<=*n*<=≤<=3) — the number of cubes, Masha got for her birthday. Each of next *n* lines contains 6 integers *a**i**j* (0<=≤<=*a**i**j*<=≤<=9) — number on *j*-th face of *i*-th cube.
Print single integer — maximum number *x* such Masha can make any integers from 1 to *x* using her cubes or 0 if Masha can't make even 1.
[ "3\n0 1 2 3 4 5\n6 7 8 9 0 1\n2 3 4 5 6 7\n", "3\n0 1 3 5 6 8\n1 2 4 5 7 8\n2 3 4 6 7 9\n" ]
[ "87", "98" ]
In the first test case, Masha can build all numbers from 1 to 87, but she can't make 88 because there are no two cubes with digit 8.
1,000
[ { "input": "3\n0 1 2 3 4 5\n6 7 8 9 0 1\n2 3 4 5 6 7", "output": "87" }, { "input": "3\n0 1 3 5 6 8\n1 2 4 5 7 8\n2 3 4 6 7 9", "output": "98" }, { "input": "3\n0 1 2 3 4 5\n0 1 2 3 4 5\n0 1 2 3 4 5", "output": "5" }, { "input": "3\n1 2 3 7 8 9\n9 8 7 1 2 3\n7 9 2 3 1 8", "output": "3" }, { "input": "1\n5 2 2 5 6 7", "output": "0" }, { "input": "1\n7 6 5 8 9 0", "output": "0" }, { "input": "1\n2 5 9 6 7 9", "output": "0" }, { "input": "1\n6 3 1 9 4 9", "output": "1" }, { "input": "1\n1 9 8 3 7 8", "output": "1" }, { "input": "2\n1 7 2 0 4 3\n5 2 3 6 1 0", "output": "7" }, { "input": "2\n6 0 1 7 2 9\n1 3 4 6 7 0", "output": "4" }, { "input": "2\n8 6 4 1 2 0\n7 8 5 3 2 1", "output": "8" }, { "input": "2\n0 8 6 2 1 3\n5 2 7 1 0 9", "output": "3" }, { "input": "2\n0 9 5 7 6 2\n8 6 2 7 1 4", "output": "2" }, { "input": "3\n5 0 7 6 2 1\n2 7 4 6 1 9\n0 2 6 1 7 5", "output": "2" }, { "input": "3\n0 6 2 9 5 4\n3 8 0 1 6 9\n6 9 0 1 5 2", "output": "6" }, { "input": "3\n5 6 2 9 3 5\n5 4 1 5 9 8\n4 4 2 0 3 5", "output": "6" }, { "input": "3\n0 1 9 1 0 8\n9 9 3 5 6 2\n9 3 9 9 7 3", "output": "3" }, { "input": "3\n2 5 7 4 2 7\n1 5 5 9 0 3\n8 2 0 1 5 1", "output": "5" }, { "input": "1\n4 6 9 8 2 7", "output": "0" }, { "input": "1\n5 3 8 0 2 6", "output": "0" }, { "input": "1\n7 9 5 0 4 6", "output": "0" }, { "input": "1\n4 0 9 6 3 1", "output": "1" }, { "input": "1\n7 9 2 5 0 4", "output": "0" }, { "input": "1\n0 7 6 3 2 4", "output": "0" }, { "input": "1\n9 8 1 6 5 7", "output": "1" }, { "input": "1\n7 3 6 9 8 1", "output": "1" }, { "input": "1\n3 9 1 7 4 5", "output": "1" }, { "input": "1\n8 6 0 9 4 2", "output": "0" }, { "input": "1\n8 2 7 4 1 0", "output": "2" }, { "input": "1\n8 3 5 4 2 9", "output": "0" }, { "input": "1\n0 8 7 1 3 2", "output": "3" }, { "input": "1\n6 2 8 5 1 3", "output": "3" }, { "input": "1\n6 0 7 5 4 8", "output": "0" }, { "input": "1\n6 2 8 4 5 1", "output": "2" }, { "input": "1\n4 3 8 9 2 3", "output": "0" }, { "input": "1\n8 1 9 2 9 7", "output": "2" }, { "input": "1\n3 7 7 6 4 2", "output": "0" }, { "input": "1\n1 4 5 7 0 5", "output": "1" }, { "input": "2\n6 6 4 7 9 0\n2 1 2 8 6 4", "output": "2" }, { "input": "2\n5 3 2 9 8 2\n0 7 4 8 1 8", "output": "5" }, { "input": "2\n5 7 4 2 1 9\n2 2 7 1 1 8", "output": "2" }, { "input": "2\n9 3 3 6 7 2\n6 2 9 1 5 9", "output": "3" }, { "input": "2\n2 0 5 7 0 8\n4 5 1 5 4 9", "output": "2" }, { "input": "2\n2 6 8 1 3 1\n2 1 3 8 6 7", "output": "3" }, { "input": "2\n4 3 8 6 0 1\n4 7 1 8 9 0", "output": "1" }, { "input": "2\n0 2 9 1 8 5\n0 7 4 3 2 5", "output": "5" }, { "input": "2\n1 7 6 9 2 5\n1 6 7 0 9 2", "output": "2" }, { "input": "2\n0 2 9 8 1 7\n6 7 4 3 2 5", "output": "9" }, { "input": "2\n3 6 8 9 5 0\n6 7 0 8 2 3", "output": "0" }, { "input": "2\n5 1 2 3 0 8\n3 6 7 4 9 2", "output": "9" }, { "input": "2\n7 8 6 1 4 5\n8 6 4 3 2 5", "output": "8" }, { "input": "2\n2 3 5 1 9 6\n1 6 8 7 3 9", "output": "3" }, { "input": "2\n1 7 8 6 0 9\n3 2 1 7 4 9", "output": "4" }, { "input": "2\n2 4 0 3 7 6\n3 2 8 7 1 5", "output": "8" }, { "input": "2\n6 5 2 7 1 3\n3 7 8 1 0 9", "output": "3" }, { "input": "2\n5 8 4 7 1 2\n0 8 6 2 4 9", "output": "2" }, { "input": "2\n8 0 6 5 1 4\n7 1 0 8 3 4", "output": "1" }, { "input": "2\n2 3 9 1 6 7\n2 5 4 3 0 6", "output": "7" }, { "input": "3\n9 4 3 0 2 6\n7 0 5 3 3 9\n1 0 7 4 6 7", "output": "7" }, { "input": "3\n3 8 5 1 5 5\n1 5 7 2 6 9\n4 3 4 8 8 9", "output": "9" }, { "input": "3\n7 7 2 5 3 2\n3 0 0 6 4 4\n1 2 1 1 9 1", "output": "7" }, { "input": "3\n8 1 6 8 6 8\n7 0 2 5 8 4\n5 2 0 3 1 9", "output": "32" }, { "input": "3\n2 7 4 0 7 1\n5 5 4 9 1 4\n2 1 7 5 1 7", "output": "2" }, { "input": "3\n4 4 5 0 6 6\n7 1 6 9 5 4\n5 0 4 0 3 9", "output": "1" }, { "input": "3\n9 4 3 3 9 3\n1 0 3 4 5 3\n2 9 6 2 4 1", "output": "6" }, { "input": "3\n3 8 3 5 5 5\n3 0 1 6 6 3\n0 4 3 7 2 4", "output": "8" }, { "input": "3\n4 1 0 8 0 2\n1 5 3 5 0 7\n7 7 2 7 2 2", "output": "5" }, { "input": "3\n8 1 8 2 7 1\n9 1 9 9 4 7\n0 0 9 0 4 0", "output": "2" }, { "input": "3\n4 6 0 3 9 2\n8 6 9 0 7 2\n6 9 3 2 5 7", "output": "0" }, { "input": "3\n5 1 2 9 6 4\n9 0 6 4 2 8\n4 6 2 8 3 7", "output": "10" }, { "input": "3\n9 3 1 8 4 6\n6 9 1 2 0 7\n8 9 1 5 0 3", "output": "21" }, { "input": "3\n7 1 3 0 2 4\n2 4 3 0 9 5\n1 9 8 0 6 5", "output": "65" }, { "input": "3\n9 4 6 2 7 0\n3 7 1 9 6 4\n6 1 0 8 7 2", "output": "4" }, { "input": "3\n2 7 3 6 4 5\n0 2 1 9 4 8\n8 6 9 5 4 0", "output": "10" }, { "input": "3\n2 6 3 7 1 0\n9 1 2 4 7 6\n1 4 8 7 6 2", "output": "4" }, { "input": "3\n5 4 8 1 6 7\n0 9 3 5 8 6\n2 4 7 8 1 3", "output": "21" }, { "input": "3\n7 2 1 3 6 9\n0 3 8 4 7 6\n1 4 5 8 7 0", "output": "21" }, { "input": "3\n8 6 0 5 4 9\n1 8 5 3 9 7\n7 4 5 1 6 8", "output": "1" }, { "input": "1\n0 1 2 3 4 5", "output": "5" }, { "input": "3\n0 1 1 2 2 3\n4 5 6 7 8 9\n3 4 5 6 7 8", "output": "9" }, { "input": "2\n0 1 2 3 4 5\n6 7 8 9 1 2", "output": "29" }, { "input": "3\n0 1 2 3 4 5\n6 7 8 9 1 2\n3 4 5 6 7 8", "output": "98" }, { "input": "3\n0 1 1 2 2 3\n4 5 6 7 8 9\n3 4 5 6 7 1", "output": "19" }, { "input": "2\n0 1 2 3 4 5\n6 7 8 9 6 6", "output": "9" }, { "input": "2\n0 1 2 3 4 5\n4 5 6 7 8 9", "output": "9" }, { "input": "2\n1 8 9 1 1 0\n2 3 4 5 6 7", "output": "9" }, { "input": "2\n0 1 2 3 4 5\n9 8 7 6 5 4", "output": "9" }, { "input": "3\n2 3 4 5 6 7\n3 4 5 6 7 8\n9 1 2 3 4 5", "output": "9" }, { "input": "3\n1 1 2 3 4 5\n6 7 8 9 0 2\n3 4 5 6 7 8", "output": "10" }, { "input": "3\n1 1 1 0 2 3\n4 5 6 7 8 9\n0 0 0 0 0 0", "output": "10" }, { "input": "3\n0 1 2 2 4 5\n6 7 8 9 0 1\n3 3 4 5 6 7", "output": "21" }, { "input": "3\n2 0 1 3 4 5\n6 7 8 9 1 1\n3 4 5 6 6 7", "output": "19" }, { "input": "3\n1 1 1 1 1 1\n0 2 3 4 5 6\n7 8 9 2 3 4", "output": "10" }, { "input": "2\n0 1 2 3 4 5\n6 6 6 7 8 9", "output": "9" }, { "input": "3\n3 4 5 6 8 9\n1 1 1 1 1 1\n1 2 4 5 7 0", "output": "19" } ]
1,530,023,593
2,147,483,647
Python 3
OK
TESTS
96
93
0
n=int(input()) d=1 e=1 f=1 g=1 h=1 k=1 if(n==1): a=list(map(str,input().split())) for i in range(1,10): j=str(i) if j not in a: print(i-1) exit(0) if(n==2): a=list(map(str,input().split())) b=list(map(str,input().split())) for i in range(1,10): j=str(i) if j not in a and j not in b: print(i-1) exit(0) for i in range(10,37): j=str(i) if j[0] in a and j[1] in b: d=0 if j[0] in b and j[1] in a: e=0 if(d==1 and e==1): print(i-1) exit(0) d=1 e=1 if(n==3): a=list(map(str,input().split())) b=list(map(str,input().split())) c=list(map(str,input().split())) for i in range(1,10): j=str(i) if j not in a and j not in b and j not in c: print(i-1) exit(0) for i in range(10,100): j=str(i) d=1 e=1 f=1 g=1 h=1 k=1 if j[0] in a and j[1] in b: d=0 if j[0] in b and j[1] in a: e=0 if j[0] in b and j[1] in c: f=0 if j[0] in c and j[1] in b: g=0 if j[0] in a and j[1] in c: h=0 if j[0] in c and j[1] in a: k=0 if(d+e+f+g+h+k==6): print(i-1) exit(0) for i in range(100,1000): j=str(i) d=1 e=1 f=1 g=1 h=1 k=1 if j[0] in a and j[1] in b and j[2] in c: d=0 if j[0] in b and j[1] in a and j[2] in c: e=0 if j[0] in b and j[1] in c and j[2] in a: f=0 if j[0] in c and j[1] in b and j[2] in a: g=0 if j[0] in a and j[1] in c and j[2] in b: h=0 if j[0] in c and j[1] in a and j[2] in b: k=0 if(d+e+f+g+h+k==6): print(i-1) exit(0)
Title: Cubes for Masha Time Limit: None seconds Memory Limit: None megabytes Problem Description: Absent-minded Masha got set of *n* cubes for her birthday. At each of 6 faces of each cube, there is exactly one digit from 0 to 9. Masha became interested what is the largest natural *x* such she can make using her new cubes all integers from 1 to *x*. To make a number Masha can rotate her cubes and put them in a row. After that, she looks at upper faces of cubes from left to right and reads the number. The number can't contain leading zeros. It's not required to use all cubes to build a number. Pay attention: Masha can't make digit 6 from digit 9 and vice-versa using cube rotations. Input Specification: In first line integer *n* is given (1<=≤<=*n*<=≤<=3) — the number of cubes, Masha got for her birthday. Each of next *n* lines contains 6 integers *a**i**j* (0<=≤<=*a**i**j*<=≤<=9) — number on *j*-th face of *i*-th cube. Output Specification: Print single integer — maximum number *x* such Masha can make any integers from 1 to *x* using her cubes or 0 if Masha can't make even 1. Demo Input: ['3\n0 1 2 3 4 5\n6 7 8 9 0 1\n2 3 4 5 6 7\n', '3\n0 1 3 5 6 8\n1 2 4 5 7 8\n2 3 4 6 7 9\n'] Demo Output: ['87', '98'] Note: In the first test case, Masha can build all numbers from 1 to 87, but she can't make 88 because there are no two cubes with digit 8.
```python n=int(input()) d=1 e=1 f=1 g=1 h=1 k=1 if(n==1): a=list(map(str,input().split())) for i in range(1,10): j=str(i) if j not in a: print(i-1) exit(0) if(n==2): a=list(map(str,input().split())) b=list(map(str,input().split())) for i in range(1,10): j=str(i) if j not in a and j not in b: print(i-1) exit(0) for i in range(10,37): j=str(i) if j[0] in a and j[1] in b: d=0 if j[0] in b and j[1] in a: e=0 if(d==1 and e==1): print(i-1) exit(0) d=1 e=1 if(n==3): a=list(map(str,input().split())) b=list(map(str,input().split())) c=list(map(str,input().split())) for i in range(1,10): j=str(i) if j not in a and j not in b and j not in c: print(i-1) exit(0) for i in range(10,100): j=str(i) d=1 e=1 f=1 g=1 h=1 k=1 if j[0] in a and j[1] in b: d=0 if j[0] in b and j[1] in a: e=0 if j[0] in b and j[1] in c: f=0 if j[0] in c and j[1] in b: g=0 if j[0] in a and j[1] in c: h=0 if j[0] in c and j[1] in a: k=0 if(d+e+f+g+h+k==6): print(i-1) exit(0) for i in range(100,1000): j=str(i) d=1 e=1 f=1 g=1 h=1 k=1 if j[0] in a and j[1] in b and j[2] in c: d=0 if j[0] in b and j[1] in a and j[2] in c: e=0 if j[0] in b and j[1] in c and j[2] in a: f=0 if j[0] in c and j[1] in b and j[2] in a: g=0 if j[0] in a and j[1] in c and j[2] in b: h=0 if j[0] in c and j[1] in a and j[2] in b: k=0 if(d+e+f+g+h+k==6): print(i-1) exit(0) ```
3
748
A
Santa Claus and a Place in a Class
PROGRAMMING
800
[ "implementation", "math" ]
null
null
Santa Claus is the first who came to the Christmas Olympiad, and he is going to be the first to take his place at a desk! In the classroom there are *n* lanes of *m* desks each, and there are two working places at each of the desks. The lanes are numbered from 1 to *n* from the left to the right, the desks in a lane are numbered from 1 to *m* starting from the blackboard. Note that the lanes go perpendicularly to the blackboard, not along it (see picture). The organizers numbered all the working places from 1 to 2*nm*. The places are numbered by lanes (i. e. all the places of the first lane go first, then all the places of the second lane, and so on), in a lane the places are numbered starting from the nearest to the blackboard (i. e. from the first desk in the lane), at each desk, the place on the left is numbered before the place on the right. Santa Clause knows that his place has number *k*. Help him to determine at which lane at which desk he should sit, and whether his place is on the left or on the right!
The only line contains three integers *n*, *m* and *k* (1<=≤<=*n*,<=*m*<=≤<=10<=000, 1<=≤<=*k*<=≤<=2*nm*) — the number of lanes, the number of desks in each lane and the number of Santa Claus' place.
Print two integers: the number of lane *r*, the number of desk *d*, and a character *s*, which stands for the side of the desk Santa Claus. The character *s* should be "L", if Santa Clause should sit on the left, and "R" if his place is on the right.
[ "4 3 9\n", "4 3 24\n", "2 4 4\n" ]
[ "2 2 L\n", "4 3 R\n", "1 2 R\n" ]
The first and the second samples are shown on the picture. The green place corresponds to Santa Claus' place in the first example, the blue place corresponds to Santa Claus' place in the second example. In the third sample there are two lanes with four desks in each, and Santa Claus has the fourth place. Thus, his place is in the first lane at the second desk on the right.
500
[ { "input": "4 3 9", "output": "2 2 L" }, { "input": "4 3 24", "output": "4 3 R" }, { "input": "2 4 4", "output": "1 2 R" }, { "input": "3 10 24", "output": "2 2 R" }, { "input": "10 3 59", "output": "10 3 L" }, { "input": "10000 10000 160845880", "output": "8043 2940 R" }, { "input": "1 1 1", "output": "1 1 L" }, { "input": "1 1 2", "output": "1 1 R" }, { "input": "1 10000 1", "output": "1 1 L" }, { "input": "1 10000 20000", "output": "1 10000 R" }, { "input": "10000 1 1", "output": "1 1 L" }, { "input": "10000 1 10000", "output": "5000 1 R" }, { "input": "10000 1 20000", "output": "10000 1 R" }, { "input": "3 2 1", "output": "1 1 L" }, { "input": "3 2 2", "output": "1 1 R" }, { "input": "3 2 3", "output": "1 2 L" }, { "input": "3 2 4", "output": "1 2 R" }, { "input": "3 2 5", "output": "2 1 L" }, { "input": "3 2 6", "output": "2 1 R" }, { "input": "3 2 7", "output": "2 2 L" }, { "input": "3 2 8", "output": "2 2 R" }, { "input": "3 2 9", "output": "3 1 L" }, { "input": "3 2 10", "output": "3 1 R" }, { "input": "3 2 11", "output": "3 2 L" }, { "input": "3 2 12", "output": "3 2 R" }, { "input": "300 2000 1068628", "output": "268 314 R" }, { "input": "300 2000 584756", "output": "147 378 R" }, { "input": "300 2000 268181", "output": "68 91 L" }, { "input": "10000 9999 186450844", "output": "9324 4745 R" }, { "input": "10000 9999 197114268", "output": "9857 6990 R" }, { "input": "10000 9999 112390396", "output": "5621 818 R" }, { "input": "10000 10000 1", "output": "1 1 L" }, { "input": "10000 10000 2", "output": "1 1 R" }, { "input": "10000 10000 100000001", "output": "5001 1 L" }, { "input": "10000 10000 199999999", "output": "10000 10000 L" }, { "input": "10000 10000 200000000", "output": "10000 10000 R" }, { "input": "1 2 1", "output": "1 1 L" }, { "input": "1 2 2", "output": "1 1 R" }, { "input": "1 2 3", "output": "1 2 L" }, { "input": "1 2 4", "output": "1 2 R" }, { "input": "2 1 1", "output": "1 1 L" }, { "input": "2 1 2", "output": "1 1 R" }, { "input": "2 1 3", "output": "2 1 L" }, { "input": "2 1 4", "output": "2 1 R" }, { "input": "4 3 7", "output": "2 1 L" }, { "input": "1 1 1", "output": "1 1 L" } ]
1,670,659,582
2,147,483,647
PyPy 3
OK
TESTS
46
93
0
n,m,k=map(int,input().split()) p=(k-1)//2 r=(p//m)+1 n=p%m+1 print(r,n, 'L' if k%2==1 else 'R')
Title: Santa Claus and a Place in a Class Time Limit: None seconds Memory Limit: None megabytes Problem Description: Santa Claus is the first who came to the Christmas Olympiad, and he is going to be the first to take his place at a desk! In the classroom there are *n* lanes of *m* desks each, and there are two working places at each of the desks. The lanes are numbered from 1 to *n* from the left to the right, the desks in a lane are numbered from 1 to *m* starting from the blackboard. Note that the lanes go perpendicularly to the blackboard, not along it (see picture). The organizers numbered all the working places from 1 to 2*nm*. The places are numbered by lanes (i. e. all the places of the first lane go first, then all the places of the second lane, and so on), in a lane the places are numbered starting from the nearest to the blackboard (i. e. from the first desk in the lane), at each desk, the place on the left is numbered before the place on the right. Santa Clause knows that his place has number *k*. Help him to determine at which lane at which desk he should sit, and whether his place is on the left or on the right! Input Specification: The only line contains three integers *n*, *m* and *k* (1<=≤<=*n*,<=*m*<=≤<=10<=000, 1<=≤<=*k*<=≤<=2*nm*) — the number of lanes, the number of desks in each lane and the number of Santa Claus' place. Output Specification: Print two integers: the number of lane *r*, the number of desk *d*, and a character *s*, which stands for the side of the desk Santa Claus. The character *s* should be "L", if Santa Clause should sit on the left, and "R" if his place is on the right. Demo Input: ['4 3 9\n', '4 3 24\n', '2 4 4\n'] Demo Output: ['2 2 L\n', '4 3 R\n', '1 2 R\n'] Note: The first and the second samples are shown on the picture. The green place corresponds to Santa Claus' place in the first example, the blue place corresponds to Santa Claus' place in the second example. In the third sample there are two lanes with four desks in each, and Santa Claus has the fourth place. Thus, his place is in the first lane at the second desk on the right.
```python n,m,k=map(int,input().split()) p=(k-1)//2 r=(p//m)+1 n=p%m+1 print(r,n, 'L' if k%2==1 else 'R') ```
3
919
D
Substring
PROGRAMMING
1,700
[ "dfs and similar", "dp", "graphs" ]
null
null
You are given a graph with $n$ nodes and $m$ directed edges. One lowercase letter is assigned to each node. We define a path's value as the number of the most frequently occurring letter. For example, if letters on a path are "abaca", then the value of that path is $3$. Your task is find a path whose value is the largest.
The first line contains two positive integers $n, m$ ($1 \leq n, m \leq 300\,000$), denoting that the graph has $n$ nodes and $m$ directed edges. The second line contains a string $s$ with only lowercase English letters. The $i$-th character is the letter assigned to the $i$-th node. Then $m$ lines follow. Each line contains two integers $x, y$ ($1 \leq x, y \leq n$), describing a directed edge from $x$ to $y$. Note that $x$ can be equal to $y$ and there can be multiple edges between $x$ and $y$. Also the graph can be not connected.
Output a single line with a single integer denoting the largest value. If the value can be arbitrarily large, output -1 instead.
[ "5 4\nabaca\n1 2\n1 3\n3 4\n4 5\n", "6 6\nxzyabc\n1 2\n3 1\n2 3\n5 4\n4 3\n6 4\n", "10 14\nxzyzyzyzqx\n1 2\n2 4\n3 5\n4 5\n2 6\n6 8\n6 5\n2 10\n3 9\n10 9\n4 6\n1 10\n2 8\n3 7\n" ]
[ "3\n", "-1\n", "4\n" ]
In the first sample, the path with largest value is $1 \to 3 \to 4 \to 5$. The value is $3$ because the letter 'a' appears $3$ times.
1,500
[ { "input": "5 4\nabaca\n1 2\n1 3\n3 4\n4 5", "output": "3" }, { "input": "6 6\nxzyabc\n1 2\n3 1\n2 3\n5 4\n4 3\n6 4", "output": "-1" }, { "input": "10 14\nxzyzyzyzqx\n1 2\n2 4\n3 5\n4 5\n2 6\n6 8\n6 5\n2 10\n3 9\n10 9\n4 6\n1 10\n2 8\n3 7", "output": "4" }, { "input": "1 1\nf\n1 1", "output": "-1" }, { "input": "10 50\nebibwbjihv\n1 10\n1 2\n5 4\n1 8\n9 7\n5 6\n1 8\n8 7\n2 6\n5 4\n1 9\n3 2\n8 3\n5 6\n5 9\n2 4\n2 7\n3 9\n1 2\n1 7\n1 10\n3 7\n1 8\n3 10\n8 6\n1 7\n10 6\n1 6\n5 8\n1 5\n2 10\n3 9\n5 8\n8 3\n3 7\n5 2\n1 10\n1 4\n5 3\n3 2\n1 2\n5 8\n10 4\n2 10\n8 2\n1 9\n1 8\n1 2\n3 4\n1 8", "output": "2" }, { "input": "13 37\ndwpzcppjmhkmz\n2 6\n3 6\n6 7\n6 7\n6 7\n6 7\n6 8\n6 8\n6 8\n6 8\n4 6\n4 6\n5 6\n4 6\n4 6\n6 9\n6 9\n6 10\n6 10\n6 10\n6 10\n4 6\n1 6\n1 6\n10 11\n6 11\n1 6\n6 12\n6 12\n6 12\n6 13\n6 13\n6 13\n6 13\n3 6\n2 6\n2 6", "output": "3" }, { "input": "5 8\ntetqw\n2 1\n4 4\n5 5\n5 2\n4 5\n1 5\n1 5\n1 1", "output": "-1" }, { "input": "5 8\nreeet\n4 3\n2 5\n4 2\n2 4\n4 2\n5 2\n3 3\n3 4", "output": "-1" } ]
1,666,975,618
2,218
PyPy 3
OK
TESTS
53
888
61,337,600
import sys, os, io input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline def topological_sort(): q, k = [], 0 cnt = [0] * (n + 1) for i in range(1, n + 1): for j in G[i]: cnt[j] += 1 for i in range(1, n + 1): if not cnt[i]: q.append(i) while len(q) ^ k: i = q[k] for j in G[i]: cnt[j] -= 1 if not cnt[j]: q.append(j) k += 1 return q def f(u, v): return u * 26 + v n, m = map(int, input().split()) s = [0] + list(input().rstrip()) G = [[] for _ in range(n + 1)] for _ in range(m): x, y = map(int, input().split()) G[x].append(y) g = topological_sort() if len(g) ^ n: ans = -1 print(ans) exit() dp = [0] * (26 * (n + 1)) for i in g: dp[f(i, s[i] - 97)] += 1 for j in range(26): dp0 = dp[f(i, j)] for k in G[i]: u = f(k, j) dp[u] = max(dp[u], dp0) ans = max(dp) print(ans)
Title: Substring Time Limit: None seconds Memory Limit: None megabytes Problem Description: You are given a graph with $n$ nodes and $m$ directed edges. One lowercase letter is assigned to each node. We define a path's value as the number of the most frequently occurring letter. For example, if letters on a path are "abaca", then the value of that path is $3$. Your task is find a path whose value is the largest. Input Specification: The first line contains two positive integers $n, m$ ($1 \leq n, m \leq 300\,000$), denoting that the graph has $n$ nodes and $m$ directed edges. The second line contains a string $s$ with only lowercase English letters. The $i$-th character is the letter assigned to the $i$-th node. Then $m$ lines follow. Each line contains two integers $x, y$ ($1 \leq x, y \leq n$), describing a directed edge from $x$ to $y$. Note that $x$ can be equal to $y$ and there can be multiple edges between $x$ and $y$. Also the graph can be not connected. Output Specification: Output a single line with a single integer denoting the largest value. If the value can be arbitrarily large, output -1 instead. Demo Input: ['5 4\nabaca\n1 2\n1 3\n3 4\n4 5\n', '6 6\nxzyabc\n1 2\n3 1\n2 3\n5 4\n4 3\n6 4\n', '10 14\nxzyzyzyzqx\n1 2\n2 4\n3 5\n4 5\n2 6\n6 8\n6 5\n2 10\n3 9\n10 9\n4 6\n1 10\n2 8\n3 7\n'] Demo Output: ['3\n', '-1\n', '4\n'] Note: In the first sample, the path with largest value is $1 \to 3 \to 4 \to 5$. The value is $3$ because the letter 'a' appears $3$ times.
```python import sys, os, io input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline def topological_sort(): q, k = [], 0 cnt = [0] * (n + 1) for i in range(1, n + 1): for j in G[i]: cnt[j] += 1 for i in range(1, n + 1): if not cnt[i]: q.append(i) while len(q) ^ k: i = q[k] for j in G[i]: cnt[j] -= 1 if not cnt[j]: q.append(j) k += 1 return q def f(u, v): return u * 26 + v n, m = map(int, input().split()) s = [0] + list(input().rstrip()) G = [[] for _ in range(n + 1)] for _ in range(m): x, y = map(int, input().split()) G[x].append(y) g = topological_sort() if len(g) ^ n: ans = -1 print(ans) exit() dp = [0] * (26 * (n + 1)) for i in g: dp[f(i, s[i] - 97)] += 1 for j in range(26): dp0 = dp[f(i, j)] for k in G[i]: u = f(k, j) dp[u] = max(dp[u], dp0) ans = max(dp) print(ans) ```
3
750
A
New Year and Hurry
PROGRAMMING
800
[ "binary search", "brute force", "implementation", "math" ]
null
null
Limak is going to participate in a contest on the last day of the 2016. The contest will start at 20:00 and will last four hours, exactly until midnight. There will be *n* problems, sorted by difficulty, i.e. problem 1 is the easiest and problem *n* is the hardest. Limak knows it will take him 5·*i* minutes to solve the *i*-th problem. Limak's friends organize a New Year's Eve party and Limak wants to be there at midnight or earlier. He needs *k* minutes to get there from his house, where he will participate in the contest first. How many problems can Limak solve if he wants to make it to the party?
The only line of the input contains two integers *n* and *k* (1<=≤<=*n*<=≤<=10, 1<=≤<=*k*<=≤<=240) — the number of the problems in the contest and the number of minutes Limak needs to get to the party from his house.
Print one integer, denoting the maximum possible number of problems Limak can solve so that he could get to the party at midnight or earlier.
[ "3 222\n", "4 190\n", "7 1\n" ]
[ "2\n", "4\n", "7\n" ]
In the first sample, there are 3 problems and Limak needs 222 minutes to get to the party. The three problems require 5, 10 and 15 minutes respectively. Limak can spend 5 + 10 = 15 minutes to solve first two problems. Then, at 20:15 he can leave his house to get to the party at 23:57 (after 222 minutes). In this scenario Limak would solve 2 problems. He doesn't have enough time to solve 3 problems so the answer is 2. In the second sample, Limak can solve all 4 problems in 5 + 10 + 15 + 20 = 50 minutes. At 20:50 he will leave the house and go to the party. He will get there exactly at midnight. In the third sample, Limak needs only 1 minute to get to the party. He has enough time to solve all 7 problems.
500
[ { "input": "3 222", "output": "2" }, { "input": "4 190", "output": "4" }, { "input": "7 1", "output": "7" }, { "input": "10 135", "output": "6" }, { "input": "10 136", "output": "5" }, { "input": "1 1", "output": "1" }, { "input": "1 240", "output": "0" }, { "input": "10 1", "output": "9" }, { "input": "10 240", "output": "0" }, { "input": "9 240", "output": "0" }, { "input": "9 1", "output": "9" }, { "input": "9 235", "output": "1" }, { "input": "9 236", "output": "0" }, { "input": "5 225", "output": "2" }, { "input": "5 226", "output": "1" }, { "input": "4 210", "output": "3" }, { "input": "4 211", "output": "2" }, { "input": "4 191", "output": "3" }, { "input": "10 165", "output": "5" }, { "input": "10 166", "output": "4" }, { "input": "8 100", "output": "7" }, { "input": "8 101", "output": "6" }, { "input": "8 60", "output": "8" }, { "input": "8 61", "output": "7" }, { "input": "10 15", "output": "9" }, { "input": "10 16", "output": "8" }, { "input": "4 100", "output": "4" }, { "input": "4 101", "output": "4" }, { "input": "7 167", "output": "4" }, { "input": "10 164", "output": "5" }, { "input": "9 170", "output": "4" }, { "input": "8 160", "output": "5" }, { "input": "1 100", "output": "1" }, { "input": "8 123", "output": "6" }, { "input": "2 99", "output": "2" }, { "input": "10 88", "output": "7" }, { "input": "1 235", "output": "1" }, { "input": "1 1", "output": "1" }, { "input": "4 240", "output": "0" }, { "input": "1 55", "output": "1" }, { "input": "1 240", "output": "0" }, { "input": "3 240", "output": "0" }, { "input": "10 240", "output": "0" }, { "input": "2 240", "output": "0" }, { "input": "10 1", "output": "9" }, { "input": "9 1", "output": "9" }, { "input": "2 236", "output": "0" }, { "input": "10 2", "output": "9" }, { "input": "3 239", "output": "0" }, { "input": "1 237", "output": "0" }, { "input": "7 8", "output": "7" }, { "input": "10 235", "output": "1" } ]
1,678,222,059
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
7
31
0
n, k =map(int,input().split()) '''1440 1200''' i=1200 d=0 if k==1: print(n) exit() while i <= 1440-k: p = 5 for j in range(1,n+1): i+=j*p d+=1 if i>1440-k: break print(d-1)
Title: New Year and Hurry Time Limit: None seconds Memory Limit: None megabytes Problem Description: Limak is going to participate in a contest on the last day of the 2016. The contest will start at 20:00 and will last four hours, exactly until midnight. There will be *n* problems, sorted by difficulty, i.e. problem 1 is the easiest and problem *n* is the hardest. Limak knows it will take him 5·*i* minutes to solve the *i*-th problem. Limak's friends organize a New Year's Eve party and Limak wants to be there at midnight or earlier. He needs *k* minutes to get there from his house, where he will participate in the contest first. How many problems can Limak solve if he wants to make it to the party? Input Specification: The only line of the input contains two integers *n* and *k* (1<=≤<=*n*<=≤<=10, 1<=≤<=*k*<=≤<=240) — the number of the problems in the contest and the number of minutes Limak needs to get to the party from his house. Output Specification: Print one integer, denoting the maximum possible number of problems Limak can solve so that he could get to the party at midnight or earlier. Demo Input: ['3 222\n', '4 190\n', '7 1\n'] Demo Output: ['2\n', '4\n', '7\n'] Note: In the first sample, there are 3 problems and Limak needs 222 minutes to get to the party. The three problems require 5, 10 and 15 minutes respectively. Limak can spend 5 + 10 = 15 minutes to solve first two problems. Then, at 20:15 he can leave his house to get to the party at 23:57 (after 222 minutes). In this scenario Limak would solve 2 problems. He doesn't have enough time to solve 3 problems so the answer is 2. In the second sample, Limak can solve all 4 problems in 5 + 10 + 15 + 20 = 50 minutes. At 20:50 he will leave the house and go to the party. He will get there exactly at midnight. In the third sample, Limak needs only 1 minute to get to the party. He has enough time to solve all 7 problems.
```python n, k =map(int,input().split()) '''1440 1200''' i=1200 d=0 if k==1: print(n) exit() while i <= 1440-k: p = 5 for j in range(1,n+1): i+=j*p d+=1 if i>1440-k: break print(d-1) ```
0
260
A
Adding Digits
PROGRAMMING
1,400
[ "implementation", "math" ]
null
null
Vasya has got two number: *a* and *b*. However, Vasya finds number *a* too short. So he decided to repeat the operation of lengthening number *a* *n* times. One operation of lengthening a number means adding exactly one digit to the number (in the decimal notation) to the right provided that the resulting number is divisible by Vasya's number *b*. If it is impossible to obtain the number which is divisible by *b*, then the lengthening operation cannot be performed. Your task is to help Vasya and print the number he can get after applying the lengthening operation to number *a* *n* times.
The first line contains three integers: *a*,<=*b*,<=*n* (1<=≤<=*a*,<=*b*,<=*n*<=≤<=105).
In a single line print the integer without leading zeros, which Vasya can get when he applies the lengthening operations to number *a* *n* times. If no such number exists, then print number -1. If there are multiple possible answers, print any of them.
[ "5 4 5\n", "12 11 1\n", "260 150 10\n" ]
[ "524848\n", "121\n", "-1\n" ]
none
500
[ { "input": "5 4 5", "output": "524848" }, { "input": "12 11 1", "output": "121" }, { "input": "260 150 10", "output": "-1" }, { "input": "78843 5684 42717", "output": "-1" }, { "input": "93248 91435 1133", "output": "-1" }, { "input": "100000 10 64479", "output": "1000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000..." }, { "input": "99999 21 73839", "output": "9999990000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000..." }, { "input": "99991 623 36438", "output": "9999150000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000..." }, { "input": "99999 334 94854", "output": "9999960000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000..." }, { "input": "99252 9827 84849", "output": "9925270000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000..." }, { "input": "99313 9833 10561", "output": "9931330000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000..." }, { "input": "94885 55815 11417", "output": "9488550000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000..." }, { "input": "99492 58525 53481", "output": "9949250000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000..." }, { "input": "99858 28531 79193", "output": "9985850000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000..." }, { "input": "99136 47208 42607", "output": "9913680000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000..." }, { "input": "63270 19953 5555", "output": "-1" }, { "input": "10240 128 100000", "output": "1024000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000..." }, { "input": "12 11 3", "output": "12100" }, { "input": "14 12 99998", "output": "1440000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000..." }, { "input": "1 11 3", "output": "1100" }, { "input": "3 40 1", "output": "-1" }, { "input": "150 100 10", "output": "1500000000000" }, { "input": "5 10 1", "output": "50" }, { "input": "1 15 10", "output": "15000000000" }, { "input": "3 13 2", "output": "390" } ]
1,695,899,645
2,147,483,647
PyPy 3-64
WRONG_ANSWER
TESTS
5
61
1,331,200
a,b,n=map(int,input().split()) o=0 while n>0 : y=(10*a)%b y=b-y if y<10 : a=(10*a)+y else : o=1 n-=1 if o==0 : print(a) else : print(-1)
Title: Adding Digits Time Limit: None seconds Memory Limit: None megabytes Problem Description: Vasya has got two number: *a* and *b*. However, Vasya finds number *a* too short. So he decided to repeat the operation of lengthening number *a* *n* times. One operation of lengthening a number means adding exactly one digit to the number (in the decimal notation) to the right provided that the resulting number is divisible by Vasya's number *b*. If it is impossible to obtain the number which is divisible by *b*, then the lengthening operation cannot be performed. Your task is to help Vasya and print the number he can get after applying the lengthening operation to number *a* *n* times. Input Specification: The first line contains three integers: *a*,<=*b*,<=*n* (1<=≤<=*a*,<=*b*,<=*n*<=≤<=105). Output Specification: In a single line print the integer without leading zeros, which Vasya can get when he applies the lengthening operations to number *a* *n* times. If no such number exists, then print number -1. If there are multiple possible answers, print any of them. Demo Input: ['5 4 5\n', '12 11 1\n', '260 150 10\n'] Demo Output: ['524848\n', '121\n', '-1\n'] Note: none
```python a,b,n=map(int,input().split()) o=0 while n>0 : y=(10*a)%b y=b-y if y<10 : a=(10*a)+y else : o=1 n-=1 if o==0 : print(a) else : print(-1) ```
0
862
D
Mahmoud and Ehab and the binary string
PROGRAMMING
2,000
[ "binary search", "divide and conquer", "interactive" ]
null
null
Mahmoud and Ehab are in the fourth stage now. Dr. Evil has a hidden binary string of length *n*. He guarantees that there is at least one '0' symbol and at least one '1' symbol in it. Now he wants Mahmoud and Ehab to find a position of any '0' symbol and any '1' symbol. In order to do this, Mahmoud and Ehab can ask Dr. Evil up to 15 questions. They tell Dr. Evil some binary string of length *n*, and Dr. Evil tells the Hamming distance between these two strings. Hamming distance between 2 binary strings of the same length is the number of positions in which they have different symbols. You can find the definition of Hamming distance in the notes section below. Help Mahmoud and Ehab find these two positions. You will get Wrong Answer verdict if - Your queries doesn't satisfy interaction protocol described below. - You ask strictly more than 15 questions and your program terminated after exceeding queries limit. Please note, that you can do up to 15 ask queries and one answer query. - Your final answer is not correct. If you exceed the maximum number of queries, You should terminate with 0, In this case you'll get Wrong Answer, If you don't terminate you may receive any verdict because you'll be reading from a closed stream .
The first line of input will contain a single integer *n* (2<=≤<=*n*<=≤<=1000) — the length of the hidden binary string.
To print the final answer, print "! pos0 pos1" (without quotes), where *pos*0 and *pos*1 are positions of some '0' and some '1' in the string (the string is 1-indexed). Don't forget to flush the output after printing the answer!
[ "3\n2\n1\n3\n2\n1\n0" ]
[ "? 000\n? 001\n? 010\n? 011\n? 100\n? 101\n! 2 1" ]
Hamming distance definition: [https://en.wikipedia.org/wiki/Hamming_distance](https://en.wikipedia.org/wiki/Hamming_distance) In the first test case the hidden binary string is 101, The first query is 000, so the Hamming distance is 2. In the second query the hidden string is still 101 and query is 001, so the Hamming distance is 1. After some queries you find that symbol at position 2 is '0' and symbol at position 1 is '1', so you print "! 2 1".
1,750
[ { "input": "101", "output": "3" }, { "input": "0011001100", "output": "4" }, { "input": "01", "output": "2" }, { "input": "0010100101101100001101110001110011000010011011001110010011101010011010100101101001111010111001000100", "output": "8" }, { "input": "0101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101", "output": "8" }, { "input": "110010011001010100101010001101110010010111001110111110011011111111000110010001010100011101101101110", "output": "8" }, { "input": "010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010", "output": "8" }, { "input": "1101111111", "output": "4" }, { "input": "100010", "output": "4" }, { "input": "101001011", "output": "5" }, { "input": "11111111111111110000000000000000", "output": "6" }, { "input": "11111111111111111000000000000000", "output": "6" }, { "input": "11111111111111100000000000000000", "output": "6" }, { "input": "1111111111111111111111111111101010101010101010101010", "output": "7" }, { "input": "001", "output": "2" }, { "input": "010", "output": "3" }, { "input": "011", "output": "3" }, { "input": "100", "output": "3" }, { "input": "110", "output": "2" }, { "input": "0001", "output": "3" }, { "input": "0010", "output": "3" }, { "input": "0011", "output": "3" }, { "input": "0100", "output": "3" }, { "input": "0101", "output": "3" }, { "input": "0110", "output": "3" }, { "input": "0111", "output": "3" }, { "input": "1000", "output": "3" }, { "input": "1001", "output": "3" }, { "input": "1010", "output": "3" }, { "input": "1011", "output": "3" }, { "input": "1100", "output": "3" }, { "input": "1101", "output": "3" }, { "input": "1110", "output": "3" }, { "input": "00001", "output": "3" }, { "input": "00010", "output": "3" }, { "input": "00011", "output": "3" }, { "input": "00100", "output": "3" }, { "input": "00101", "output": "3" }, { "input": "00110", "output": "3" }, { "input": "00111", "output": "3" }, { "input": "01000", "output": "4" }, { "input": "01001", "output": "4" }, { "input": "01010", "output": "4" }, { "input": "01011", "output": "4" }, { "input": "01100", "output": "4" }, { "input": "01101", "output": "4" }, { "input": "01110", "output": "4" }, { "input": "01111", "output": "4" }, { "input": "10000", "output": "4" }, { "input": "10001", "output": "4" }, { "input": "10010", "output": "4" }, { "input": "10011", "output": "4" }, { "input": "10100", "output": "4" }, { "input": "10101", "output": "4" }, { "input": "10110", "output": "4" }, { "input": "10111", "output": "4" }, { "input": "11000", "output": "3" }, { "input": "11001", "output": "3" }, { "input": "11010", "output": "3" }, { "input": "11011", "output": "3" }, { "input": "11100", "output": "3" }, { "input": "11101", "output": "3" }, { "input": "11110", "output": "3" }, { "input": "01111111", "output": "4" }, { "input": "0110110111101010100", "output": "6" }, { "input": "10101101000011000001100010111100101101010010010100001001100110100101000110011", "output": "8" }, { "input": "100011010001110101001101101010010100101001110000110110010011000100111101101010010010001001001100010", "output": "8" }, { "input": "101100000010000100100100000010000101100110101001010111000101100010010010110100100110100000011011100011101010011111110000010", "output": "8" }, { "input": "010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101", "output": "10" }, { "input": "00000010", "output": "4" }, { "input": "0000000000000000100", "output": "5" }, { "input": "00000000000000000000000000000000000000000000000000000000000000000000000000010", "output": "7" }, { "input": "000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000", "output": "8" }, { "input": "000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000000000000", "output": "8" }, { "input": "111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111110111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111", "output": "10" }, { "input": "10", "output": "2" } ]
1,559,229,038
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
0
93
307,200
class Game: def __init__(self, n): self.n = n self.total_zeros = self.ask([1 for _ in range(n)]) self.zero = -1 self.one = -1 def ask(self, ps): print('? ' + ''.join('1' if p else '0' for p in ps), flush=True) return int(input().strip()) def count_zeros(self, i, j): if i == 0 and j == self.n: return self.total_zeros ps = [0 if i <= s < j else 1 for s in range(self.n)] x = self.ask(ps) return (self.total_zeros - x + (j - i)) // 2 def find(self, i, j): if i >= j: return if self.zero != -1 and self.one != -1: return zeros = self.count_zeros(i, j) ones = (j - i) - zeros if zeros == 0: self.one = i elif ones == 0: self.zero = i if j - i >= 2: mid = (i + j) // 2 self.find(i, mid) self.find(mid, j) def main(): n = int(input().strip()) game = Game(n) game.find(0, n) print('! {} {}'.format(game.zero, game.one)) main()
Title: Mahmoud and Ehab and the binary string Time Limit: None seconds Memory Limit: None megabytes Problem Description: Mahmoud and Ehab are in the fourth stage now. Dr. Evil has a hidden binary string of length *n*. He guarantees that there is at least one '0' symbol and at least one '1' symbol in it. Now he wants Mahmoud and Ehab to find a position of any '0' symbol and any '1' symbol. In order to do this, Mahmoud and Ehab can ask Dr. Evil up to 15 questions. They tell Dr. Evil some binary string of length *n*, and Dr. Evil tells the Hamming distance between these two strings. Hamming distance between 2 binary strings of the same length is the number of positions in which they have different symbols. You can find the definition of Hamming distance in the notes section below. Help Mahmoud and Ehab find these two positions. You will get Wrong Answer verdict if - Your queries doesn't satisfy interaction protocol described below. - You ask strictly more than 15 questions and your program terminated after exceeding queries limit. Please note, that you can do up to 15 ask queries and one answer query. - Your final answer is not correct. If you exceed the maximum number of queries, You should terminate with 0, In this case you'll get Wrong Answer, If you don't terminate you may receive any verdict because you'll be reading from a closed stream . Input Specification: The first line of input will contain a single integer *n* (2<=≤<=*n*<=≤<=1000) — the length of the hidden binary string. Output Specification: To print the final answer, print "! pos0 pos1" (without quotes), where *pos*0 and *pos*1 are positions of some '0' and some '1' in the string (the string is 1-indexed). Don't forget to flush the output after printing the answer! Demo Input: ['3\n2\n1\n3\n2\n1\n0'] Demo Output: ['? 000\n? 001\n? 010\n? 011\n? 100\n? 101\n! 2 1'] Note: Hamming distance definition: [https://en.wikipedia.org/wiki/Hamming_distance](https://en.wikipedia.org/wiki/Hamming_distance) In the first test case the hidden binary string is 101, The first query is 000, so the Hamming distance is 2. In the second query the hidden string is still 101 and query is 001, so the Hamming distance is 1. After some queries you find that symbol at position 2 is '0' and symbol at position 1 is '1', so you print "! 2 1".
```python class Game: def __init__(self, n): self.n = n self.total_zeros = self.ask([1 for _ in range(n)]) self.zero = -1 self.one = -1 def ask(self, ps): print('? ' + ''.join('1' if p else '0' for p in ps), flush=True) return int(input().strip()) def count_zeros(self, i, j): if i == 0 and j == self.n: return self.total_zeros ps = [0 if i <= s < j else 1 for s in range(self.n)] x = self.ask(ps) return (self.total_zeros - x + (j - i)) // 2 def find(self, i, j): if i >= j: return if self.zero != -1 and self.one != -1: return zeros = self.count_zeros(i, j) ones = (j - i) - zeros if zeros == 0: self.one = i elif ones == 0: self.zero = i if j - i >= 2: mid = (i + j) // 2 self.find(i, mid) self.find(mid, j) def main(): n = int(input().strip()) game = Game(n) game.find(0, n) print('! {} {}'.format(game.zero, game.one)) main() ```
0
902
A
Visiting a Friend
PROGRAMMING
1,100
[ "greedy", "implementation" ]
null
null
Pig is visiting a friend. Pig's house is located at point 0, and his friend's house is located at point *m* on an axis. Pig can use teleports to move along the axis. To use a teleport, Pig should come to a certain point (where the teleport is located) and choose where to move: for each teleport there is the rightmost point it can move Pig to, this point is known as the limit of the teleport. Formally, a teleport located at point *x* with limit *y* can move Pig from point *x* to any point within the segment [*x*;<=*y*], including the bounds. Determine if Pig can visit the friend using teleports only, or he should use his car.
The first line contains two integers *n* and *m* (1<=≤<=*n*<=≤<=100,<=1<=≤<=*m*<=≤<=100) — the number of teleports and the location of the friend's house. The next *n* lines contain information about teleports. The *i*-th of these lines contains two integers *a**i* and *b**i* (0<=≤<=*a**i*<=≤<=*b**i*<=≤<=*m*), where *a**i* is the location of the *i*-th teleport, and *b**i* is its limit. It is guaranteed that *a**i*<=≥<=*a**i*<=-<=1 for every *i* (2<=≤<=*i*<=≤<=*n*).
Print "YES" if there is a path from Pig's house to his friend's house that uses only teleports, and "NO" otherwise. You can print each letter in arbitrary case (upper or lower).
[ "3 5\n0 2\n2 4\n3 5\n", "3 7\n0 4\n2 5\n6 7\n" ]
[ "YES\n", "NO\n" ]
The first example is shown on the picture below: Pig can use the first teleport from his house (point 0) to reach point 2, then using the second teleport go from point 2 to point 3, then using the third teleport go from point 3 to point 5, where his friend lives. The second example is shown on the picture below: You can see that there is no path from Pig's house to his friend's house that uses only teleports.
500
[ { "input": "3 5\n0 2\n2 4\n3 5", "output": "YES" }, { "input": "3 7\n0 4\n2 5\n6 7", "output": "NO" }, { "input": "1 1\n0 0", "output": "NO" }, { "input": "30 10\n0 7\n1 2\n1 2\n1 4\n1 4\n1 3\n2 2\n2 4\n2 6\n2 9\n2 2\n3 5\n3 8\n4 8\n4 5\n4 6\n5 6\n5 7\n6 6\n6 9\n6 7\n6 9\n7 7\n7 7\n8 8\n8 8\n9 9\n9 9\n10 10\n10 10", "output": "NO" }, { "input": "30 100\n0 27\n4 82\n11 81\n14 32\n33 97\n33 34\n37 97\n38 52\n45 91\n49 56\n50 97\n57 70\n59 94\n59 65\n62 76\n64 65\n65 95\n67 77\n68 100\n71 73\n80 94\n81 92\n84 85\n85 100\n88 91\n91 95\n92 98\n92 98\n99 100\n100 100", "output": "YES" }, { "input": "70 10\n0 4\n0 4\n0 8\n0 9\n0 1\n0 5\n0 7\n1 3\n1 8\n1 8\n1 6\n1 6\n1 2\n1 3\n1 2\n1 3\n2 5\n2 4\n2 3\n2 4\n2 6\n2 2\n2 5\n2 7\n3 7\n3 4\n3 7\n3 4\n3 8\n3 4\n3 9\n3 3\n3 7\n3 9\n3 3\n3 9\n4 6\n4 7\n4 5\n4 7\n5 8\n5 5\n5 9\n5 7\n5 5\n6 6\n6 9\n6 7\n6 8\n6 9\n6 8\n7 7\n7 8\n7 7\n7 8\n8 9\n8 8\n8 9\n8 8\n9 9\n9 9\n9 9\n9 9\n9 9\n9 9\n10 10\n10 10\n10 10\n10 10\n10 10", "output": "NO" }, { "input": "30 10\n0 7\n1 2\n1 2\n1 4\n1 4\n1 3\n2 2\n2 4\n2 6\n2 9\n2 2\n3 5\n3 8\n4 8\n4 5\n4 6\n5 6\n5 7\n6 6\n6 9\n6 7\n6 9\n7 7\n7 7\n8 10\n8 10\n9 9\n9 9\n10 10\n10 10", "output": "YES" }, { "input": "50 100\n0 95\n1 100\n1 38\n2 82\n5 35\n7 71\n8 53\n11 49\n15 27\n17 84\n17 75\n18 99\n18 43\n18 69\n21 89\n27 60\n27 29\n38 62\n38 77\n39 83\n40 66\n48 80\n48 100\n50 51\n50 61\n53 77\n53 63\n55 58\n56 68\n60 82\n62 95\n66 74\n67 83\n69 88\n69 81\n69 88\n69 98\n70 91\n70 76\n71 90\n72 99\n81 99\n85 87\n88 97\n88 93\n90 97\n90 97\n92 98\n98 99\n100 100", "output": "YES" }, { "input": "70 10\n0 4\n0 4\n0 8\n0 9\n0 1\n0 5\n0 7\n1 3\n1 8\n1 8\n1 10\n1 9\n1 6\n1 2\n1 3\n1 2\n2 6\n2 5\n2 4\n2 3\n2 10\n2 2\n2 6\n2 2\n3 10\n3 7\n3 7\n3 4\n3 7\n3 4\n3 8\n3 4\n3 10\n3 5\n3 3\n3 7\n4 8\n4 8\n4 9\n4 6\n5 7\n5 10\n5 7\n5 8\n5 5\n6 8\n6 9\n6 10\n6 6\n6 9\n6 7\n7 8\n7 9\n7 10\n7 10\n8 8\n8 8\n8 9\n8 10\n9 10\n9 9\n9 10\n9 10\n9 9\n9 9\n10 10\n10 10\n10 10\n10 10\n10 10", "output": "YES" }, { "input": "85 10\n0 9\n0 4\n0 2\n0 5\n0 1\n0 8\n0 7\n1 2\n1 4\n1 5\n1 9\n1 1\n1 6\n1 6\n2 5\n2 7\n2 7\n2 7\n2 7\n3 4\n3 7\n3 9\n3 5\n3 3\n4 4\n4 6\n4 5\n5 6\n5 6\n5 6\n5 6\n5 7\n5 8\n5 5\n5 7\n5 8\n5 9\n5 8\n6 8\n6 7\n6 8\n6 9\n6 9\n6 6\n6 9\n6 7\n7 7\n7 7\n7 7\n7 8\n7 7\n7 8\n7 8\n7 9\n8 8\n8 8\n8 8\n8 8\n8 8\n8 9\n8 9\n9 9\n9 9\n9 9\n9 9\n9 9\n9 9\n9 9\n9 9\n9 9\n10 10\n10 10\n10 10\n10 10\n10 10\n10 10\n10 10\n10 10\n10 10\n10 10\n10 10\n10 10\n10 10\n10 10\n10 10", "output": "NO" }, { "input": "30 40\n0 0\n4 8\n5 17\n7 32\n7 16\n8 16\n10 19\n12 22\n12 27\n13 21\n13 28\n13 36\n14 28\n14 18\n18 21\n21 26\n21 36\n22 38\n23 32\n24 30\n26 35\n29 32\n29 32\n31 34\n31 31\n33 33\n33 35\n35 40\n38 38\n40 40", "output": "NO" }, { "input": "70 100\n0 99\n1 87\n1 94\n1 4\n2 72\n3 39\n3 69\n4 78\n5 85\n7 14\n8 59\n12 69\n14 15\n14 76\n17 17\n19 53\n19 57\n19 21\n21 35\n21 83\n24 52\n24 33\n27 66\n27 97\n30 62\n30 74\n30 64\n32 63\n35 49\n37 60\n40 99\n40 71\n41 83\n42 66\n42 46\n45 83\n51 76\n53 69\n54 82\n54 96\n54 88\n55 91\n56 88\n58 62\n62 87\n64 80\n67 90\n67 69\n68 92\n72 93\n74 93\n77 79\n77 91\n78 97\n78 98\n81 85\n81 83\n81 83\n84 85\n86 88\n89 94\n89 92\n92 97\n96 99\n97 98\n97 99\n99 99\n100 100\n100 100\n100 100", "output": "NO" }, { "input": "1 10\n0 10", "output": "YES" }, { "input": "70 40\n0 34\n1 16\n3 33\n4 36\n4 22\n5 9\n5 9\n7 16\n8 26\n9 29\n9 25\n10 15\n10 22\n10 29\n10 20\n11 27\n11 26\n11 12\n12 19\n13 21\n14 31\n14 36\n15 34\n15 37\n16 21\n17 31\n18 22\n20 27\n20 32\n20 20\n20 29\n21 29\n21 34\n21 30\n22 40\n23 23\n23 28\n24 29\n25 38\n26 35\n27 37\n28 39\n28 33\n28 40\n28 33\n29 31\n29 33\n30 38\n30 36\n30 30\n30 38\n31 37\n31 35\n31 32\n31 36\n33 39\n33 40\n35 38\n36 38\n37 38\n37 40\n38 39\n38 40\n38 39\n39 39\n39 40\n40 40\n40 40\n40 40\n40 40", "output": "YES" }, { "input": "50 40\n0 9\n1 26\n1 27\n2 33\n2 5\n3 30\n4 28\n5 31\n5 27\n5 29\n7 36\n8 32\n8 13\n9 24\n10 10\n10 30\n11 26\n11 22\n11 40\n11 31\n12 26\n13 25\n14 32\n17 19\n21 29\n22 36\n24 27\n25 39\n25 27\n27 32\n27 29\n27 39\n27 29\n28 38\n30 38\n32 40\n32 38\n33 33\n33 40\n34 35\n34 34\n34 38\n34 38\n35 37\n36 39\n36 39\n37 37\n38 40\n39 39\n40 40", "output": "YES" }, { "input": "70 40\n0 34\n1 16\n3 33\n4 36\n4 22\n5 9\n5 9\n7 16\n8 26\n9 29\n9 25\n10 15\n10 22\n10 29\n10 20\n11 27\n11 26\n11 12\n12 19\n13 21\n14 31\n14 36\n15 34\n15 37\n16 21\n17 31\n18 22\n20 27\n20 32\n20 20\n20 29\n21 29\n21 34\n21 30\n22 22\n23 28\n23 39\n24 24\n25 27\n26 38\n27 39\n28 33\n28 39\n28 34\n28 33\n29 30\n29 35\n30 30\n30 38\n30 34\n30 31\n31 36\n31 31\n31 32\n31 38\n33 34\n33 34\n35 36\n36 38\n37 38\n37 39\n38 38\n38 38\n38 38\n39 39\n39 39\n40 40\n40 40\n40 40\n40 40", "output": "NO" }, { "input": "10 100\n0 34\n8 56\n17 79\n24 88\n28 79\n45 79\n48 93\n55 87\n68 93\n88 99", "output": "NO" }, { "input": "10 10\n0 2\n3 8\n3 5\n3 3\n3 9\n3 8\n5 7\n6 10\n7 10\n9 10", "output": "NO" }, { "input": "50 10\n0 2\n0 2\n0 6\n1 9\n1 3\n1 2\n1 6\n1 1\n1 1\n2 7\n2 6\n2 4\n3 9\n3 8\n3 8\n3 8\n3 6\n3 4\n3 7\n3 4\n3 6\n3 5\n4 8\n5 5\n5 7\n6 7\n6 6\n7 7\n7 7\n7 7\n7 8\n7 8\n8 8\n8 8\n8 9\n8 8\n8 9\n9 9\n9 9\n9 9\n10 10\n10 10\n10 10\n10 10\n10 10\n10 10\n10 10\n10 10\n10 10\n10 10", "output": "NO" }, { "input": "10 40\n0 21\n1 19\n4 33\n6 26\n8 39\n15 15\n20 24\n27 27\n29 39\n32 37", "output": "NO" }, { "input": "50 10\n0 2\n0 2\n0 6\n1 9\n1 3\n1 2\n1 6\n1 1\n1 1\n2 7\n2 6\n2 4\n3 9\n3 8\n3 8\n3 8\n3 6\n3 4\n3 7\n3 4\n3 6\n3 10\n4 6\n5 9\n5 5\n6 7\n6 10\n7 8\n7 7\n7 7\n7 7\n7 10\n8 8\n8 8\n8 10\n8 8\n8 8\n9 10\n9 10\n9 10\n10 10\n10 10\n10 10\n10 10\n10 10\n10 10\n10 10\n10 10\n10 10\n10 10", "output": "YES" }, { "input": "1 1\n0 1", "output": "YES" }, { "input": "30 40\n0 0\n4 8\n5 17\n7 32\n7 16\n8 16\n10 19\n12 22\n12 27\n13 21\n13 28\n13 36\n14 28\n14 18\n18 21\n21 26\n21 36\n22 38\n23 32\n24 30\n26 35\n29 32\n29 32\n31 34\n31 31\n33 33\n33 35\n35 36\n38 38\n40 40", "output": "NO" }, { "input": "30 100\n0 27\n4 82\n11 81\n14 32\n33 97\n33 34\n37 97\n38 52\n45 91\n49 56\n50 97\n57 70\n59 94\n59 65\n62 76\n64 65\n65 95\n67 77\n68 82\n71 94\n80 90\n81 88\n84 93\n85 89\n88 92\n91 97\n92 99\n92 97\n99 99\n100 100", "output": "NO" }, { "input": "10 100\n0 34\n8 56\n17 79\n24 88\n28 79\n45 79\n48 93\n55 87\n68 93\n79 100", "output": "YES" }, { "input": "10 40\n0 21\n1 19\n4 33\n6 26\n8 39\n15 15\n20 24\n27 27\n29 39\n37 40", "output": "YES" }, { "input": "85 10\n0 9\n0 4\n0 2\n0 5\n0 1\n0 8\n0 7\n1 2\n1 10\n1 2\n1 5\n1 10\n1 8\n1 1\n2 8\n2 7\n2 5\n2 5\n2 7\n3 5\n3 7\n3 5\n3 4\n3 7\n4 7\n4 8\n4 6\n5 7\n5 10\n5 5\n5 6\n5 6\n5 6\n5 6\n5 7\n5 8\n5 5\n5 7\n6 10\n6 9\n6 7\n6 10\n6 8\n6 7\n6 10\n6 10\n7 8\n7 9\n7 8\n7 8\n7 8\n7 8\n7 7\n7 7\n8 8\n8 8\n8 10\n8 9\n8 9\n8 9\n8 9\n9 9\n9 10\n9 9\n9 9\n9 9\n9 9\n9 10\n9 10\n9 9\n10 10\n10 10\n10 10\n10 10\n10 10\n10 10\n10 10\n10 10\n10 10\n10 10\n10 10\n10 10\n10 10\n10 10\n10 10", "output": "YES" }, { "input": "50 100\n0 95\n1 7\n1 69\n2 83\n5 67\n7 82\n8 31\n11 25\n15 44\n17 75\n17 27\n18 43\n18 69\n18 40\n21 66\n27 29\n27 64\n38 77\n38 90\n39 52\n40 60\n48 91\n48 98\n50 89\n50 63\n53 54\n53 95\n55 76\n56 59\n60 96\n62 86\n66 70\n67 77\n69 88\n69 98\n69 80\n69 95\n70 74\n70 77\n71 99\n72 73\n81 87\n85 99\n88 96\n88 91\n90 97\n90 99\n92 92\n98 99\n100 100", "output": "NO" }, { "input": "50 40\n0 9\n1 26\n1 27\n2 33\n2 5\n3 30\n4 28\n5 31\n5 27\n5 29\n7 36\n8 32\n8 13\n9 24\n10 10\n10 30\n11 26\n11 22\n11 35\n11 23\n12 36\n13 31\n14 31\n17 17\n21 25\n22 33\n24 26\n25 32\n25 25\n27 39\n27 29\n27 34\n27 32\n28 34\n30 36\n32 37\n32 33\n33 35\n33 33\n34 38\n34 38\n34 36\n34 36\n35 36\n36 36\n36 39\n37 37\n38 39\n39 39\n40 40", "output": "NO" }, { "input": "10 10\n0 2\n3 8\n3 5\n3 3\n3 9\n3 8\n5 7\n6 9\n7 7\n9 9", "output": "NO" }, { "input": "70 100\n0 99\n1 87\n1 94\n1 4\n2 72\n3 39\n3 69\n4 78\n5 85\n7 14\n8 59\n12 69\n14 15\n14 76\n17 17\n19 53\n19 57\n19 21\n21 35\n21 83\n24 52\n24 33\n27 66\n27 97\n30 62\n30 74\n30 64\n32 63\n35 49\n37 60\n40 99\n40 71\n41 83\n42 66\n42 46\n45 83\n51 76\n53 69\n54 82\n54 96\n54 88\n55 91\n56 88\n58 62\n62 87\n64 80\n67 90\n67 69\n68 92\n72 93\n74 93\n77 79\n77 91\n78 97\n78 98\n81 85\n81 83\n81 83\n84 85\n86 88\n89 94\n89 100\n92 97\n96 96\n97 98\n97 100\n99 100\n100 100\n100 100\n100 100", "output": "YES" }, { "input": "2 2\n0 2\n0 1", "output": "YES" }, { "input": "2 100\n0 49\n50 100", "output": "NO" }, { "input": "2 100\n0 50\n50 100", "output": "YES" }, { "input": "10 100\n0 10\n10 20\n20 30\n30 40\n40 50\n50 60\n60 70\n70 80\n80 90\n90 100", "output": "YES" }, { "input": "100 10\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 10", "output": "YES" }, { "input": "1 4\n1 4", "output": "NO" }, { "input": "3 5\n0 2\n2 5\n3 4", "output": "YES" }, { "input": "2 5\n0 5\n1 2", "output": "YES" }, { "input": "5 5\n0 2\n0 2\n3 5\n3 5\n3 5", "output": "NO" }, { "input": "4 10\n0 3\n2 10\n4 10\n5 7", "output": "YES" }, { "input": "3 8\n0 0\n1 8\n2 8", "output": "NO" }, { "input": "6 8\n0 3\n1 5\n2 3\n5 6\n6 7\n7 8", "output": "YES" } ]
1,645,947,140
2,147,483,647
Python 3
OK
TESTS
55
46
0
n,m=map(int,input().split()) p=q=0 for _ in range(n): a,b=map(int,input().split()) if b>q: if p<=a and a<=q: p=a q=b if q>=m:print("YES") else:print("NO")
Title: Visiting a Friend Time Limit: None seconds Memory Limit: None megabytes Problem Description: Pig is visiting a friend. Pig's house is located at point 0, and his friend's house is located at point *m* on an axis. Pig can use teleports to move along the axis. To use a teleport, Pig should come to a certain point (where the teleport is located) and choose where to move: for each teleport there is the rightmost point it can move Pig to, this point is known as the limit of the teleport. Formally, a teleport located at point *x* with limit *y* can move Pig from point *x* to any point within the segment [*x*;<=*y*], including the bounds. Determine if Pig can visit the friend using teleports only, or he should use his car. Input Specification: The first line contains two integers *n* and *m* (1<=≤<=*n*<=≤<=100,<=1<=≤<=*m*<=≤<=100) — the number of teleports and the location of the friend's house. The next *n* lines contain information about teleports. The *i*-th of these lines contains two integers *a**i* and *b**i* (0<=≤<=*a**i*<=≤<=*b**i*<=≤<=*m*), where *a**i* is the location of the *i*-th teleport, and *b**i* is its limit. It is guaranteed that *a**i*<=≥<=*a**i*<=-<=1 for every *i* (2<=≤<=*i*<=≤<=*n*). Output Specification: Print "YES" if there is a path from Pig's house to his friend's house that uses only teleports, and "NO" otherwise. You can print each letter in arbitrary case (upper or lower). Demo Input: ['3 5\n0 2\n2 4\n3 5\n', '3 7\n0 4\n2 5\n6 7\n'] Demo Output: ['YES\n', 'NO\n'] Note: The first example is shown on the picture below: Pig can use the first teleport from his house (point 0) to reach point 2, then using the second teleport go from point 2 to point 3, then using the third teleport go from point 3 to point 5, where his friend lives. The second example is shown on the picture below: You can see that there is no path from Pig's house to his friend's house that uses only teleports.
```python n,m=map(int,input().split()) p=q=0 for _ in range(n): a,b=map(int,input().split()) if b>q: if p<=a and a<=q: p=a q=b if q>=m:print("YES") else:print("NO") ```
3
591
B
Rebranding
PROGRAMMING
1,200
[ "implementation", "strings" ]
null
null
The name of one small but proud corporation consists of *n* lowercase English letters. The Corporation has decided to try rebranding — an active marketing strategy, that includes a set of measures to change either the brand (both for the company and the goods it produces) or its components: the name, the logo, the slogan. They decided to start with the name. For this purpose the corporation has consecutively hired *m* designers. Once a company hires the *i*-th designer, he immediately contributes to the creation of a new corporation name as follows: he takes the newest version of the name and replaces all the letters *x**i* by *y**i*, and all the letters *y**i* by *x**i*. This results in the new version. It is possible that some of these letters do no occur in the string. It may also happen that *x**i* coincides with *y**i*. The version of the name received after the work of the last designer becomes the new name of the corporation. Manager Arkady has recently got a job in this company, but is already soaked in the spirit of teamwork and is very worried about the success of the rebranding. Naturally, he can't wait to find out what is the new name the Corporation will receive. Satisfy Arkady's curiosity and tell him the final version of the name.
The first line of the input contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=200<=000) — the length of the initial name and the number of designers hired, respectively. The second line consists of *n* lowercase English letters and represents the original name of the corporation. Next *m* lines contain the descriptions of the designers' actions: the *i*-th of them contains two space-separated lowercase English letters *x**i* and *y**i*.
Print the new name of the corporation.
[ "6 1\npolice\np m\n", "11 6\nabacabadaba\na b\nb c\na d\ne g\nf a\nb b\n" ]
[ "molice\n", "cdcbcdcfcdc\n" ]
In the second sample the name of the corporation consecutively changes as follows: <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/c7648432f7138ca53234357d7e08d1d119166055.png" style="max-width: 100.0%;max-height: 100.0%;"/> <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/de89ad7bc7f27c46ec34f5e66ce0dc23bd5bc90a.png" style="max-width: 100.0%;max-height: 100.0%;"/> <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/812e653c8d7ff496e6a0f04c676423806751531e.png" style="max-width: 100.0%;max-height: 100.0%;"/> <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/19c564fcefb8dde36256240a8b877bb6a4792bfe.png" style="max-width: 100.0%;max-height: 100.0%;"/> <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/e1cafd93792430ad1a49e893e04715383bdae757.png" style="max-width: 100.0%;max-height: 100.0%;"/>
1,000
[ { "input": "6 1\npolice\np m", "output": "molice" }, { "input": "11 6\nabacabadaba\na b\nb c\na d\ne g\nf a\nb b", "output": "cdcbcdcfcdc" }, { "input": "1 1\nf\nz h", "output": "f" }, { "input": "1 1\na\na b", "output": "b" }, { "input": "10 10\nlellelleel\ne l\ne l\ne l\ne l\ne l\ne e\nl l\nl e\nl l\ne e", "output": "lellelleel" } ]
1,445,765,769
2,169
Python 3
TIME_LIMIT_EXCEEDED
PRETESTS
5
2,000
1,126,400
a = input().split() b = input() for i in range(1,int(a[1]) + 1): c = input().split() b = b.replace(c[0],'[').replace(c[1],']').replace('[',c[1]).replace(']',c[0]) print(b)
Title: Rebranding Time Limit: None seconds Memory Limit: None megabytes Problem Description: The name of one small but proud corporation consists of *n* lowercase English letters. The Corporation has decided to try rebranding — an active marketing strategy, that includes a set of measures to change either the brand (both for the company and the goods it produces) or its components: the name, the logo, the slogan. They decided to start with the name. For this purpose the corporation has consecutively hired *m* designers. Once a company hires the *i*-th designer, he immediately contributes to the creation of a new corporation name as follows: he takes the newest version of the name and replaces all the letters *x**i* by *y**i*, and all the letters *y**i* by *x**i*. This results in the new version. It is possible that some of these letters do no occur in the string. It may also happen that *x**i* coincides with *y**i*. The version of the name received after the work of the last designer becomes the new name of the corporation. Manager Arkady has recently got a job in this company, but is already soaked in the spirit of teamwork and is very worried about the success of the rebranding. Naturally, he can't wait to find out what is the new name the Corporation will receive. Satisfy Arkady's curiosity and tell him the final version of the name. Input Specification: The first line of the input contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=200<=000) — the length of the initial name and the number of designers hired, respectively. The second line consists of *n* lowercase English letters and represents the original name of the corporation. Next *m* lines contain the descriptions of the designers' actions: the *i*-th of them contains two space-separated lowercase English letters *x**i* and *y**i*. Output Specification: Print the new name of the corporation. Demo Input: ['6 1\npolice\np m\n', '11 6\nabacabadaba\na b\nb c\na d\ne g\nf a\nb b\n'] Demo Output: ['molice\n', 'cdcbcdcfcdc\n'] Note: In the second sample the name of the corporation consecutively changes as follows: <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/c7648432f7138ca53234357d7e08d1d119166055.png" style="max-width: 100.0%;max-height: 100.0%;"/> <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/de89ad7bc7f27c46ec34f5e66ce0dc23bd5bc90a.png" style="max-width: 100.0%;max-height: 100.0%;"/> <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/812e653c8d7ff496e6a0f04c676423806751531e.png" style="max-width: 100.0%;max-height: 100.0%;"/> <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/19c564fcefb8dde36256240a8b877bb6a4792bfe.png" style="max-width: 100.0%;max-height: 100.0%;"/> <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/e1cafd93792430ad1a49e893e04715383bdae757.png" style="max-width: 100.0%;max-height: 100.0%;"/>
```python a = input().split() b = input() for i in range(1,int(a[1]) + 1): c = input().split() b = b.replace(c[0],'[').replace(c[1],']').replace('[',c[1]).replace(']',c[0]) print(b) ```
0
47
B
Coins
PROGRAMMING
1,200
[ "implementation" ]
B. Coins
2
256
One day Vasya came across three Berland coins. They didn't have any numbers that's why Vasya didn't understand how their denominations differ. He supposed that if one coin is heavier than the other one, then it should be worth more. Vasya weighed all the three pairs of coins on pan balance scales and told you the results. Find out how the deminations of the coins differ or if Vasya has a mistake in the weighting results. No two coins are equal.
The input data contains the results of all the weighting, one result on each line. It is guaranteed that every coin pair was weighted exactly once. Vasya labelled the coins with letters «A», «B» and «C». Each result is a line that appears as (letter)(&gt; or &lt; sign)(letter). For example, if coin "A" proved lighter than coin "B", the result of the weighting is A&lt;B.
It the results are contradictory, print Impossible. Otherwise, print without spaces the rearrangement of letters «A», «B» and «C» which represent the coins in the increasing order of their weights.
[ "A&gt;B\nC&lt;B\nA&gt;C\n", "A&lt;B\nB&gt;C\nC&gt;A\n" ]
[ "CBA", "ACB" ]
none
1,000
[ { "input": "A>B\nC<B\nA>C", "output": "CBA" }, { "input": "A<B\nB>C\nC>A", "output": "ACB" }, { "input": "A<C\nB<A\nB>C", "output": "Impossible" }, { "input": "A<B\nA<C\nB>C", "output": "ACB" }, { "input": "B>A\nC<B\nC>A", "output": "ACB" }, { "input": "A>B\nB>C\nC<A", "output": "CBA" }, { "input": "A>C\nA>B\nB<C", "output": "BCA" }, { "input": "C<B\nB>A\nA<C", "output": "ACB" }, { "input": "C<B\nA>B\nC<A", "output": "CBA" }, { "input": "C>B\nB>A\nA<C", "output": "ABC" }, { "input": "C<B\nB<A\nC>A", "output": "Impossible" }, { "input": "B<C\nC<A\nA>B", "output": "BCA" }, { "input": "A>B\nC<B\nC<A", "output": "CBA" }, { "input": "B>A\nC>B\nA>C", "output": "Impossible" }, { "input": "B<A\nC>B\nC>A", "output": "BAC" }, { "input": "A<B\nC>B\nA<C", "output": "ABC" }, { "input": "A<B\nC<A\nB<C", "output": "Impossible" }, { "input": "A>C\nC<B\nB>A", "output": "CAB" }, { "input": "C>A\nA<B\nB>C", "output": "ACB" }, { "input": "C>A\nC<B\nB>A", "output": "ACB" }, { "input": "B>C\nB>A\nA<C", "output": "ACB" }, { "input": "C<B\nC<A\nB<A", "output": "CBA" }, { "input": "A<C\nA<B\nB>C", "output": "ACB" }, { "input": "B>A\nA>C\nB>C", "output": "CAB" }, { "input": "B<A\nA<C\nC<B", "output": "Impossible" }, { "input": "A<C\nB>C\nA>B", "output": "Impossible" }, { "input": "B>A\nC<A\nC>B", "output": "Impossible" }, { "input": "A>C\nC>B\nB<A", "output": "BCA" }, { "input": "B<C\nB<A\nA>C", "output": "BCA" }, { "input": "A>B\nC>B\nA<C", "output": "BAC" }, { "input": "C<B\nC<A\nB<A", "output": "CBA" }, { "input": "A<C\nA>B\nB>C", "output": "Impossible" }, { "input": "B>A\nB>C\nA<C", "output": "ACB" }, { "input": "B>C\nC<A\nB<A", "output": "CBA" }, { "input": "C>A\nB>A\nB>C", "output": "ACB" }, { "input": "B<A\nB>C\nA<C", "output": "Impossible" }, { "input": "B<C\nA<B\nC>A", "output": "ABC" }, { "input": "C<B\nB>A\nA>C", "output": "CAB" }, { "input": "A>B\nC>A\nB<C", "output": "BAC" }, { "input": "A>B\nB>C\nC<A", "output": "CBA" }, { "input": "B>C\nC>A\nA>B", "output": "Impossible" }, { "input": "B<A\nB>C\nC<A", "output": "CBA" }, { "input": "C>B\nB>A\nC>A", "output": "ABC" }, { "input": "A>C\nA>B\nB>C", "output": "CBA" }, { "input": "B<C\nA>B\nA<C", "output": "BAC" }, { "input": "C>A\nC<B\nB>A", "output": "ACB" }, { "input": "C>B\nA<B\nC<A", "output": "Impossible" }, { "input": "A<C\nC<B\nA>B", "output": "Impossible" }, { "input": "B>C\nA<B\nA<C", "output": "ACB" }, { "input": "C>A\nA<B\nC>B", "output": "ABC" } ]
1,623,858,696
2,147,483,647
Python 3
COMPILATION_ERROR
TESTS
0
0
0
class Employee: def __init__(self, id: int, importance: int, subordinates: List[int]): self.id = id self.importance = importance self.subordinates = subordinates class Solution: def getImportance(self, employees: List['Employee'], id: int) -> int:
Title: Coins Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: One day Vasya came across three Berland coins. They didn't have any numbers that's why Vasya didn't understand how their denominations differ. He supposed that if one coin is heavier than the other one, then it should be worth more. Vasya weighed all the three pairs of coins on pan balance scales and told you the results. Find out how the deminations of the coins differ or if Vasya has a mistake in the weighting results. No two coins are equal. Input Specification: The input data contains the results of all the weighting, one result on each line. It is guaranteed that every coin pair was weighted exactly once. Vasya labelled the coins with letters «A», «B» and «C». Each result is a line that appears as (letter)(&gt; or &lt; sign)(letter). For example, if coin "A" proved lighter than coin "B", the result of the weighting is A&lt;B. Output Specification: It the results are contradictory, print Impossible. Otherwise, print without spaces the rearrangement of letters «A», «B» and «C» which represent the coins in the increasing order of their weights. Demo Input: ['A&gt;B\nC&lt;B\nA&gt;C\n', 'A&lt;B\nB&gt;C\nC&gt;A\n'] Demo Output: ['CBA', 'ACB'] Note: none
```python class Employee: def __init__(self, id: int, importance: int, subordinates: List[int]): self.id = id self.importance = importance self.subordinates = subordinates class Solution: def getImportance(self, employees: List['Employee'], id: int) -> int: ```
-1
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,620,846,082
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
1
46
6,963,200
def main(): n=int(input()) a=[0]*n b=[0]*n tmp=list() rated=0 for i in range(n): tmp=input() a[i]=int(tmp[0]) b[i]=int(tmp[1]) if a[i]!=b[i]: rated=1 if rated==1: print("rated") else: for i in range(n): for j in range(i+1,n+1): if a[i]<a[j]: rated=-1 if rated==-1: print("unrated") else: print("maybe") if __name__=="__main__": main()
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 def main(): n=int(input()) a=[0]*n b=[0]*n tmp=list() rated=0 for i in range(n): tmp=input() a[i]=int(tmp[0]) b[i]=int(tmp[1]) if a[i]!=b[i]: rated=1 if rated==1: print("rated") else: for i in range(n): for j in range(i+1,n+1): if a[i]<a[j]: rated=-1 if rated==-1: print("unrated") else: print("maybe") if __name__=="__main__": main() ```
0
268
A
Games
PROGRAMMING
800
[ "brute force" ]
null
null
Manao works on a sports TV. He's spent much time watching the football games of some country. After a while he began to notice different patterns. For example, each team has two sets of uniforms: home uniform and guest uniform. When a team plays a game at home, the players put on the home uniform. When a team plays as a guest on somebody else's stadium, the players put on the guest uniform. The only exception to that rule is: when the home uniform color of the host team matches the guests' uniform, the host team puts on its guest uniform as well. For each team the color of the home and guest uniform is different. There are *n* teams taking part in the national championship. The championship consists of *n*·(*n*<=-<=1) games: each team invites each other team to its stadium. At this point Manao wondered: how many times during the championship is a host team going to put on the guest uniform? Note that the order of the games does not affect this number. You know the colors of the home and guest uniform for each team. For simplicity, the colors are numbered by integers in such a way that no two distinct colors have the same number. Help Manao find the answer to his question.
The first line contains an integer *n* (2<=≤<=*n*<=≤<=30). Each of the following *n* lines contains a pair of distinct space-separated integers *h**i*, *a**i* (1<=≤<=*h**i*,<=*a**i*<=≤<=100) — the colors of the *i*-th team's home and guest uniforms, respectively.
In a single line print the number of games where the host team is going to play in the guest uniform.
[ "3\n1 2\n2 4\n3 4\n", "4\n100 42\n42 100\n5 42\n100 5\n", "2\n1 2\n1 2\n" ]
[ "1\n", "5\n", "0\n" ]
In the first test case the championship consists of 6 games. The only game with the event in question is the game between teams 2 and 1 on the stadium of team 2. In the second test sample the host team will have to wear guest uniform in the games between teams: 1 and 2, 2 and 1, 2 and 3, 3 and 4, 4 and 2 (the host team is written first).
500
[ { "input": "3\n1 2\n2 4\n3 4", "output": "1" }, { "input": "4\n100 42\n42 100\n5 42\n100 5", "output": "5" }, { "input": "2\n1 2\n1 2", "output": "0" }, { "input": "7\n4 7\n52 55\n16 4\n55 4\n20 99\n3 4\n7 52", "output": "6" }, { "input": "10\n68 42\n1 35\n25 70\n59 79\n65 63\n46 6\n28 82\n92 62\n43 96\n37 28", "output": "1" }, { "input": "30\n10 39\n89 1\n78 58\n75 99\n36 13\n77 50\n6 97\n79 28\n27 52\n56 5\n93 96\n40 21\n33 74\n26 37\n53 59\n98 56\n61 65\n42 57\n9 7\n25 63\n74 34\n96 84\n95 47\n12 23\n34 21\n71 6\n27 13\n15 47\n64 14\n12 77", "output": "6" }, { "input": "30\n46 100\n87 53\n34 84\n44 66\n23 20\n50 34\n90 66\n17 39\n13 22\n94 33\n92 46\n63 78\n26 48\n44 61\n3 19\n41 84\n62 31\n65 89\n23 28\n58 57\n19 85\n26 60\n75 66\n69 67\n76 15\n64 15\n36 72\n90 89\n42 69\n45 35", "output": "4" }, { "input": "2\n46 6\n6 46", "output": "2" }, { "input": "29\n8 18\n33 75\n69 22\n97 95\n1 97\n78 10\n88 18\n13 3\n19 64\n98 12\n79 92\n41 72\n69 15\n98 31\n57 74\n15 56\n36 37\n15 66\n63 100\n16 42\n47 56\n6 4\n73 15\n30 24\n27 71\n12 19\n88 69\n85 6\n50 11", "output": "10" }, { "input": "23\n43 78\n31 28\n58 80\n66 63\n20 4\n51 95\n40 20\n50 14\n5 34\n36 39\n77 42\n64 97\n62 89\n16 56\n8 34\n58 16\n37 35\n37 66\n8 54\n50 36\n24 8\n68 48\n85 33", "output": "6" }, { "input": "13\n76 58\n32 85\n99 79\n23 58\n96 59\n72 35\n53 43\n96 55\n41 78\n75 10\n28 11\n72 7\n52 73", "output": "0" }, { "input": "18\n6 90\n70 79\n26 52\n67 81\n29 95\n41 32\n94 88\n18 58\n59 65\n51 56\n64 68\n34 2\n6 98\n95 82\n34 2\n40 98\n83 78\n29 2", "output": "1" }, { "input": "18\n6 90\n100 79\n26 100\n67 100\n29 100\n100 32\n94 88\n18 58\n59 65\n51 56\n64 68\n34 2\n6 98\n95 82\n34 2\n40 98\n83 78\n29 100", "output": "8" }, { "input": "30\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1", "output": "450" }, { "input": "30\n100 99\n58 59\n56 57\n54 55\n52 53\n50 51\n48 49\n46 47\n44 45\n42 43\n40 41\n38 39\n36 37\n34 35\n32 33\n30 31\n28 29\n26 27\n24 25\n22 23\n20 21\n18 19\n16 17\n14 15\n12 13\n10 11\n8 9\n6 7\n4 5\n2 3", "output": "0" }, { "input": "15\n9 3\n2 6\n7 6\n5 10\n9 5\n8 1\n10 5\n2 8\n4 5\n9 8\n5 3\n3 8\n9 8\n4 10\n8 5", "output": "20" }, { "input": "15\n2 1\n1 2\n1 2\n1 2\n2 1\n2 1\n2 1\n1 2\n2 1\n2 1\n2 1\n1 2\n2 1\n2 1\n1 2", "output": "108" }, { "input": "25\n2 1\n1 2\n1 2\n1 2\n2 1\n1 2\n1 2\n1 2\n2 1\n2 1\n2 1\n1 2\n1 2\n1 2\n2 1\n2 1\n2 1\n1 2\n2 1\n1 2\n2 1\n2 1\n2 1\n2 1\n1 2", "output": "312" }, { "input": "25\n91 57\n2 73\n54 57\n2 57\n23 57\n2 6\n57 54\n57 23\n91 54\n91 23\n57 23\n91 57\n54 2\n6 91\n57 54\n2 57\n57 91\n73 91\n57 23\n91 57\n2 73\n91 2\n23 6\n2 73\n23 6", "output": "96" }, { "input": "28\n31 66\n31 91\n91 31\n97 66\n31 66\n31 66\n66 91\n91 31\n97 31\n91 97\n97 31\n66 31\n66 97\n91 31\n31 66\n31 66\n66 31\n31 97\n66 97\n97 31\n31 91\n66 91\n91 66\n31 66\n91 66\n66 31\n66 31\n91 97", "output": "210" }, { "input": "29\n78 27\n50 68\n24 26\n68 43\n38 78\n26 38\n78 28\n28 26\n27 24\n23 38\n24 26\n24 43\n61 50\n38 78\n27 23\n61 26\n27 28\n43 23\n28 78\n43 27\n43 78\n27 61\n28 38\n61 78\n50 26\n43 27\n26 78\n28 50\n43 78", "output": "73" }, { "input": "29\n80 27\n69 80\n27 80\n69 80\n80 27\n80 27\n80 27\n80 69\n27 69\n80 69\n80 27\n27 69\n69 27\n80 69\n27 69\n69 80\n27 69\n80 69\n80 27\n69 27\n27 69\n27 80\n80 27\n69 80\n27 69\n80 69\n69 80\n69 80\n27 80", "output": "277" }, { "input": "30\n19 71\n7 89\n89 71\n21 7\n19 21\n7 89\n19 71\n89 8\n89 21\n19 8\n21 7\n8 89\n19 89\n7 21\n19 8\n19 7\n7 19\n8 21\n71 21\n71 89\n7 19\n7 19\n21 7\n21 19\n21 19\n71 8\n21 8\n71 19\n19 71\n8 21", "output": "154" }, { "input": "30\n44 17\n44 17\n44 17\n17 44\n44 17\n44 17\n17 44\n17 44\n17 44\n44 17\n44 17\n44 17\n44 17\n44 17\n17 44\n17 44\n17 44\n44 17\n44 17\n17 44\n44 17\n44 17\n44 17\n17 44\n17 44\n44 17\n17 44\n44 17\n44 17\n44 17", "output": "418" }, { "input": "22\n78 92\n15 92\n92 78\n78 80\n92 16\n24 80\n92 16\n16 92\n78 16\n24 78\n80 78\n92 80\n16 80\n80 78\n15 78\n92 16\n24 15\n24 80\n80 16\n16 80\n92 80\n24 80", "output": "74" }, { "input": "24\n9 83\n90 31\n83 3\n83 3\n21 31\n83 3\n32 31\n12 21\n31 21\n90 32\n32 21\n12 9\n12 31\n9 83\n83 12\n32 3\n32 83\n90 31\n9 32\n31 21\n83 90\n32 21\n21 3\n32 9", "output": "59" }, { "input": "30\n67 21\n85 39\n85 87\n21 39\n66 85\n10 95\n10 21\n87 85\n82 21\n67 21\n95 10\n21 39\n82 21\n21 66\n66 39\n95 30\n67 85\n66 82\n85 82\n21 66\n10 39\n67 10\n21 85\n10 82\n85 95\n10 85\n21 39\n85 39\n39 10\n95 67", "output": "100" }, { "input": "4\n8 7\n8 7\n7 8\n7 8", "output": "8" }, { "input": "6\n1 2\n1 2\n1 2\n1 2\n1 2\n2 1", "output": "10" }, { "input": "12\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1", "output": "72" }, { "input": "4\n1 2\n1 2\n2 1\n2 1", "output": "8" } ]
1,694,085,115
2,147,483,647
Python 3
OK
TESTS
31
92
0
num = int(input()) team1 = [] team2 = [] c = 0 for i in range(num): x = input().split() team1.append(x[0]) team2.append(x[1]) for i in team1: for e in team2: if i == e: c += 1 print(c)
Title: Games Time Limit: None seconds Memory Limit: None megabytes Problem Description: Manao works on a sports TV. He's spent much time watching the football games of some country. After a while he began to notice different patterns. For example, each team has two sets of uniforms: home uniform and guest uniform. When a team plays a game at home, the players put on the home uniform. When a team plays as a guest on somebody else's stadium, the players put on the guest uniform. The only exception to that rule is: when the home uniform color of the host team matches the guests' uniform, the host team puts on its guest uniform as well. For each team the color of the home and guest uniform is different. There are *n* teams taking part in the national championship. The championship consists of *n*·(*n*<=-<=1) games: each team invites each other team to its stadium. At this point Manao wondered: how many times during the championship is a host team going to put on the guest uniform? Note that the order of the games does not affect this number. You know the colors of the home and guest uniform for each team. For simplicity, the colors are numbered by integers in such a way that no two distinct colors have the same number. Help Manao find the answer to his question. Input Specification: The first line contains an integer *n* (2<=≤<=*n*<=≤<=30). Each of the following *n* lines contains a pair of distinct space-separated integers *h**i*, *a**i* (1<=≤<=*h**i*,<=*a**i*<=≤<=100) — the colors of the *i*-th team's home and guest uniforms, respectively. Output Specification: In a single line print the number of games where the host team is going to play in the guest uniform. Demo Input: ['3\n1 2\n2 4\n3 4\n', '4\n100 42\n42 100\n5 42\n100 5\n', '2\n1 2\n1 2\n'] Demo Output: ['1\n', '5\n', '0\n'] Note: In the first test case the championship consists of 6 games. The only game with the event in question is the game between teams 2 and 1 on the stadium of team 2. In the second test sample the host team will have to wear guest uniform in the games between teams: 1 and 2, 2 and 1, 2 and 3, 3 and 4, 4 and 2 (the host team is written first).
```python num = int(input()) team1 = [] team2 = [] c = 0 for i in range(num): x = input().split() team1.append(x[0]) team2.append(x[1]) for i in team1: for e in team2: if i == e: c += 1 print(c) ```
3
723
A
The New Year: Meeting Friends
PROGRAMMING
800
[ "implementation", "math", "sortings" ]
null
null
There are three friend living on the straight line *Ox* in Lineland. The first friend lives at the point *x*1, the second friend lives at the point *x*2, and the third friend lives at the point *x*3. They plan to celebrate the New Year together, so they need to meet at one point. What is the minimum total distance they have to travel in order to meet at some point and celebrate the New Year? It's guaranteed that the optimal answer is always integer.
The first line of the input contains three distinct integers *x*1, *x*2 and *x*3 (1<=≤<=*x*1,<=*x*2,<=*x*3<=≤<=100) — the coordinates of the houses of the first, the second and the third friends respectively.
Print one integer — the minimum total distance the friends need to travel in order to meet together.
[ "7 1 4\n", "30 20 10\n" ]
[ "6\n", "20\n" ]
In the first sample, friends should meet at the point 4. Thus, the first friend has to travel the distance of 3 (from the point 7 to the point 4), the second friend also has to travel the distance of 3 (from the point 1 to the point 4), while the third friend should not go anywhere because he lives at the point 4.
500
[ { "input": "7 1 4", "output": "6" }, { "input": "30 20 10", "output": "20" }, { "input": "1 4 100", "output": "99" }, { "input": "100 1 91", "output": "99" }, { "input": "1 45 100", "output": "99" }, { "input": "1 2 3", "output": "2" }, { "input": "71 85 88", "output": "17" }, { "input": "30 38 99", "output": "69" }, { "input": "23 82 95", "output": "72" }, { "input": "22 41 47", "output": "25" }, { "input": "9 94 77", "output": "85" }, { "input": "1 53 51", "output": "52" }, { "input": "25 97 93", "output": "72" }, { "input": "42 53 51", "output": "11" }, { "input": "81 96 94", "output": "15" }, { "input": "21 5 93", "output": "88" }, { "input": "50 13 75", "output": "62" }, { "input": "41 28 98", "output": "70" }, { "input": "69 46 82", "output": "36" }, { "input": "87 28 89", "output": "61" }, { "input": "44 45 40", "output": "5" }, { "input": "86 97 68", "output": "29" }, { "input": "43 92 30", "output": "62" }, { "input": "16 70 1", "output": "69" }, { "input": "40 46 19", "output": "27" }, { "input": "71 38 56", "output": "33" }, { "input": "82 21 80", "output": "61" }, { "input": "75 8 35", "output": "67" }, { "input": "75 24 28", "output": "51" }, { "input": "78 23 56", "output": "55" }, { "input": "85 31 10", "output": "75" }, { "input": "76 50 9", "output": "67" }, { "input": "95 37 34", "output": "61" }, { "input": "84 61 35", "output": "49" }, { "input": "87 85 37", "output": "50" }, { "input": "1 3 2", "output": "2" }, { "input": "4 2 6", "output": "4" }, { "input": "6 9 3", "output": "6" }, { "input": "12 4 8", "output": "8" }, { "input": "15 10 5", "output": "10" }, { "input": "1 50 17", "output": "49" }, { "input": "10 5 15", "output": "10" }, { "input": "8 1 9", "output": "8" }, { "input": "3 5 4", "output": "2" }, { "input": "2 1 3", "output": "2" }, { "input": "1 8 2", "output": "7" }, { "input": "1 100 2", "output": "99" }, { "input": "1 4 6", "output": "5" } ]
1,678,161,050
2,147,483,647
Python 3
OK
TESTS
48
46
0
x1,x2,x3=map(int,input().split()) x11=abs(x3-x1)+abs(x2-x1) x22=abs(x3-x2)+abs(x1-x2) x33=abs(x2-x3)+abs(x1-x3) print(min(x11,x22,x33))
Title: The New Year: Meeting Friends Time Limit: None seconds Memory Limit: None megabytes Problem Description: There are three friend living on the straight line *Ox* in Lineland. The first friend lives at the point *x*1, the second friend lives at the point *x*2, and the third friend lives at the point *x*3. They plan to celebrate the New Year together, so they need to meet at one point. What is the minimum total distance they have to travel in order to meet at some point and celebrate the New Year? It's guaranteed that the optimal answer is always integer. Input Specification: The first line of the input contains three distinct integers *x*1, *x*2 and *x*3 (1<=≤<=*x*1,<=*x*2,<=*x*3<=≤<=100) — the coordinates of the houses of the first, the second and the third friends respectively. Output Specification: Print one integer — the minimum total distance the friends need to travel in order to meet together. Demo Input: ['7 1 4\n', '30 20 10\n'] Demo Output: ['6\n', '20\n'] Note: In the first sample, friends should meet at the point 4. Thus, the first friend has to travel the distance of 3 (from the point 7 to the point 4), the second friend also has to travel the distance of 3 (from the point 1 to the point 4), while the third friend should not go anywhere because he lives at the point 4.
```python x1,x2,x3=map(int,input().split()) x11=abs(x3-x1)+abs(x2-x1) x22=abs(x3-x2)+abs(x1-x2) x33=abs(x2-x3)+abs(x1-x3) print(min(x11,x22,x33)) ```
3
908
A
New Year and Counting Cards
PROGRAMMING
800
[ "brute force", "implementation" ]
null
null
Your friend has *n* cards. You know that each card has a lowercase English letter on one side and a digit on the other. Currently, your friend has laid out the cards on a table so only one side of each card is visible. You would like to know if the following statement is true for cards that your friend owns: "If a card has a vowel on one side, then it has an even digit on the other side." More specifically, a vowel is one of 'a', 'e', 'i', 'o' or 'u', and even digit is one of '0', '2', '4', '6' or '8'. For example, if a card has 'a' on one side, and '6' on the other side, then this statement is true for it. Also, the statement is true, for example, for a card with 'b' and '4', and for a card with 'b' and '3' (since the letter is not a vowel). The statement is false, for example, for card with 'e' and '5'. You are interested if the statement is true for all cards. In particular, if no card has a vowel, the statement is true. To determine this, you can flip over some cards to reveal the other side. You would like to know what is the minimum number of cards you need to flip in the worst case in order to verify that the statement is true.
The first and only line of input will contain a string *s* (1<=≤<=|*s*|<=≤<=50), denoting the sides of the cards that you can see on the table currently. Each character of *s* is either a lowercase English letter or a digit.
Print a single integer, the minimum number of cards you must turn over to verify your claim.
[ "ee\n", "z\n", "0ay1\n" ]
[ "2\n", "0\n", "2\n" ]
In the first sample, we must turn over both cards. Note that even though both cards have the same letter, they could possibly have different numbers on the other side. In the second sample, we don't need to turn over any cards. The statement is vacuously true, since you know your friend has no cards with a vowel on them. In the third sample, we need to flip the second and fourth cards.
500
[ { "input": "ee", "output": "2" }, { "input": "z", "output": "0" }, { "input": "0ay1", "output": "2" }, { "input": "0abcdefghijklmnopqrstuvwxyz1234567896", "output": "10" }, { "input": "0a0a9e9e2i2i9o9o6u6u9z9z4x4x9b9b", "output": "18" }, { "input": "01234567890123456789012345678901234567890123456789", "output": "25" }, { "input": "qwertyuioplkjhgfdsazxcvbnmqwertyuioplkjhgfdsazxcvb", "output": "10" }, { "input": "cjw2dwmr10pku4yxohe0wglktd", "output": "4" }, { "input": "6z2tx805jie8cfybwtfqvmlveec3iak5z5u3lu62vbxyqht6", "output": "13" }, { "input": "kaq7jyialrfp4ilkni90eq8v3amcbygon7py0hb8z26fbl8ss1", "output": "13" }, { "input": "hpwn50zgbmct80k9rizjqg40nycgs0acwikjqt11nr6m61krfs", "output": "8" }, { "input": "l3rw91a4m25l8iytxyeuixsegzcbm4h41ornf3pixkrmwznrzc", "output": "14" }, { "input": "2222", "output": "0" }, { "input": "13579", "output": "5" }, { "input": "1", "output": "1" }, { "input": "0", "output": "0" }, { "input": "a", "output": "1" }, { "input": "y", "output": "0" }, { "input": "w", "output": "0" }, { "input": "oo", "output": "2" }, { "input": "oy", "output": "1" }, { "input": "yo", "output": "1" }, { "input": "yy", "output": "0" }, { "input": "a0", "output": "1" }, { "input": "a9", "output": "2" }, { "input": "y0", "output": "0" }, { "input": "y7", "output": "1" }, { "input": "0a", "output": "1" }, { "input": "3a", "output": "2" }, { "input": "06", "output": "0" }, { "input": "07", "output": "1" }, { "input": "70", "output": "1" }, { "input": "77", "output": "2" }, { "input": "13570", "output": "4" }, { "input": "0000000000011111", "output": "5" }, { "input": "1357", "output": "4" }, { "input": "uuuuuuuuuuuuuuuuuu", "output": "18" }, { "input": "gabieurat", "output": "5" } ]
1,638,135,729
2,147,483,647
Python 3
OK
TESTS
38
46
0
cards = input() vowels = set('aeiou') odds = set('13579') count = 0 for c in cards: if c in vowels or c in odds: count += 1 print(count)
Title: New Year and Counting Cards Time Limit: None seconds Memory Limit: None megabytes Problem Description: Your friend has *n* cards. You know that each card has a lowercase English letter on one side and a digit on the other. Currently, your friend has laid out the cards on a table so only one side of each card is visible. You would like to know if the following statement is true for cards that your friend owns: "If a card has a vowel on one side, then it has an even digit on the other side." More specifically, a vowel is one of 'a', 'e', 'i', 'o' or 'u', and even digit is one of '0', '2', '4', '6' or '8'. For example, if a card has 'a' on one side, and '6' on the other side, then this statement is true for it. Also, the statement is true, for example, for a card with 'b' and '4', and for a card with 'b' and '3' (since the letter is not a vowel). The statement is false, for example, for card with 'e' and '5'. You are interested if the statement is true for all cards. In particular, if no card has a vowel, the statement is true. To determine this, you can flip over some cards to reveal the other side. You would like to know what is the minimum number of cards you need to flip in the worst case in order to verify that the statement is true. Input Specification: The first and only line of input will contain a string *s* (1<=≤<=|*s*|<=≤<=50), denoting the sides of the cards that you can see on the table currently. Each character of *s* is either a lowercase English letter or a digit. Output Specification: Print a single integer, the minimum number of cards you must turn over to verify your claim. Demo Input: ['ee\n', 'z\n', '0ay1\n'] Demo Output: ['2\n', '0\n', '2\n'] Note: In the first sample, we must turn over both cards. Note that even though both cards have the same letter, they could possibly have different numbers on the other side. In the second sample, we don't need to turn over any cards. The statement is vacuously true, since you know your friend has no cards with a vowel on them. In the third sample, we need to flip the second and fourth cards.
```python cards = input() vowels = set('aeiou') odds = set('13579') count = 0 for c in cards: if c in vowels or c in odds: count += 1 print(count) ```
3
996
A
Hit the Lottery
PROGRAMMING
800
[ "dp", "greedy" ]
null
null
Allen has a LOT of money. He has $n$ dollars in the bank. For security reasons, he wants to withdraw it in cash (we will not disclose the reasons here). The denominations for dollar bills are $1$, $5$, $10$, $20$, $100$. What is the minimum number of bills Allen could receive after withdrawing his entire balance?
The first and only line of input contains a single integer $n$ ($1 \le n \le 10^9$).
Output the minimum number of bills that Allen could receive.
[ "125\n", "43\n", "1000000000\n" ]
[ "3\n", "5\n", "10000000\n" ]
In the first sample case, Allen can withdraw this with a $100$ dollar bill, a $20$ dollar bill, and a $5$ dollar bill. There is no way for Allen to receive $125$ dollars in one or two bills. In the second sample case, Allen can withdraw two $20$ dollar bills and three $1$ dollar bills. In the third sample case, Allen can withdraw $100000000$ (ten million!) $100$ dollar bills.
500
[ { "input": "125", "output": "3" }, { "input": "43", "output": "5" }, { "input": "1000000000", "output": "10000000" }, { "input": "4", "output": "4" }, { "input": "5", "output": "1" }, { "input": "1", "output": "1" }, { "input": "74", "output": "8" }, { "input": "31", "output": "3" }, { "input": "59", "output": "8" }, { "input": "79", "output": "9" }, { "input": "7", "output": "3" }, { "input": "55", "output": "4" }, { "input": "40", "output": "2" }, { "input": "719", "output": "13" }, { "input": "847", "output": "13" }, { "input": "225", "output": "4" }, { "input": "4704", "output": "51" }, { "input": "1132", "output": "15" }, { "input": "7811", "output": "80" }, { "input": "7981", "output": "84" }, { "input": "82655", "output": "830" }, { "input": "6364", "output": "70" }, { "input": "74611", "output": "748" }, { "input": "45391", "output": "459" }, { "input": "620448", "output": "6210" }, { "input": "265145", "output": "2654" }, { "input": "671704", "output": "6721" }, { "input": "365173", "output": "3658" }, { "input": "7130872", "output": "71314" }, { "input": "9628747", "output": "96292" }, { "input": "8898399", "output": "88993" }, { "input": "9497953", "output": "94985" }, { "input": "19070947", "output": "190714" }, { "input": "20185520", "output": "201856" }, { "input": "91402248", "output": "914028" }, { "input": "27035533", "output": "270360" }, { "input": "22717528", "output": "227180" }, { "input": "24403439", "output": "244041" }, { "input": "163565555", "output": "1635659" }, { "input": "152541908", "output": "1525423" }, { "input": "668439837", "output": "6684403" }, { "input": "20", "output": "1" }, { "input": "999999999", "output": "10000009" }, { "input": "10", "output": "1" }, { "input": "7", "output": "3" }, { "input": "6", "output": "2" }, { "input": "99999999", "output": "1000009" }, { "input": "1000001", "output": "10001" }, { "input": "2521", "output": "27" } ]
1,687,723,251
2,147,483,647
Python 3
OK
TESTS
49
46
0
import sys input = sys.stdin.readline ############ ---- Input Functions ---- ############ def inp(): return(int(input())) def inlt(): return(list(map(int,input().split()))) def insr(): s = input() return(list(s[:len(s) - 1])) def invr(): return(map(int,input().split())) def main(): amount = inp() bills = 0 bills += amount // 100 amount %= 100 bills += amount // 20 amount %= 20 bills += amount // 10 amount %= 10 bills += amount // 5 amount %= 5 bills += amount // 1 print(bills) main()
Title: Hit the Lottery Time Limit: None seconds Memory Limit: None megabytes Problem Description: Allen has a LOT of money. He has $n$ dollars in the bank. For security reasons, he wants to withdraw it in cash (we will not disclose the reasons here). The denominations for dollar bills are $1$, $5$, $10$, $20$, $100$. What is the minimum number of bills Allen could receive after withdrawing his entire balance? Input Specification: The first and only line of input contains a single integer $n$ ($1 \le n \le 10^9$). Output Specification: Output the minimum number of bills that Allen could receive. Demo Input: ['125\n', '43\n', '1000000000\n'] Demo Output: ['3\n', '5\n', '10000000\n'] Note: In the first sample case, Allen can withdraw this with a $100$ dollar bill, a $20$ dollar bill, and a $5$ dollar bill. There is no way for Allen to receive $125$ dollars in one or two bills. In the second sample case, Allen can withdraw two $20$ dollar bills and three $1$ dollar bills. In the third sample case, Allen can withdraw $100000000$ (ten million!) $100$ dollar bills.
```python import sys input = sys.stdin.readline ############ ---- Input Functions ---- ############ def inp(): return(int(input())) def inlt(): return(list(map(int,input().split()))) def insr(): s = input() return(list(s[:len(s) - 1])) def invr(): return(map(int,input().split())) def main(): amount = inp() bills = 0 bills += amount // 100 amount %= 100 bills += amount // 20 amount %= 20 bills += amount // 10 amount %= 10 bills += amount // 5 amount %= 5 bills += amount // 1 print(bills) main() ```
3
591
A
Wizards' Duel
PROGRAMMING
900
[ "implementation", "math" ]
null
null
Harry Potter and He-Who-Must-Not-Be-Named engaged in a fight to the death once again. This time they are located at opposite ends of the corridor of length *l*. Two opponents simultaneously charge a deadly spell in the enemy. We know that the impulse of Harry's magic spell flies at a speed of *p* meters per second, and the impulse of You-Know-Who's magic spell flies at a speed of *q* meters per second. The impulses are moving through the corridor toward each other, and at the time of the collision they turn round and fly back to those who cast them without changing their original speeds. Then, as soon as the impulse gets back to it's caster, the wizard reflects it and sends again towards the enemy, without changing the original speed of the impulse. Since Harry has perfectly mastered the basics of magic, he knows that after the second collision both impulses will disappear, and a powerful explosion will occur exactly in the place of their collision. However, the young wizard isn't good at math, so he asks you to calculate the distance from his position to the place of the second meeting of the spell impulses, provided that the opponents do not change positions during the whole fight.
The first line of the input contains a single integer *l* (1<=≤<=*l*<=≤<=1<=000) — the length of the corridor where the fight takes place. The second line contains integer *p*, the third line contains integer *q* (1<=≤<=*p*,<=*q*<=≤<=500) — the speeds of magical impulses for Harry Potter and He-Who-Must-Not-Be-Named, respectively.
Print a single real number — the distance from the end of the corridor, where Harry is located, to the place of the second meeting of the spell impulses. Your answer will be considered correct if its absolute or relative error will not exceed 10<=-<=4. Namely: let's assume that your answer equals *a*, and the answer of the jury is *b*. The checker program will consider your answer correct if .
[ "100\n50\n50\n", "199\n60\n40\n" ]
[ "50\n", "119.4\n" ]
In the first sample the speeds of the impulses are equal, so both of their meetings occur exactly in the middle of the corridor.
500
[ { "input": "100\n50\n50", "output": "50" }, { "input": "199\n60\n40", "output": "119.4" }, { "input": "1\n1\n1", "output": "0.5" }, { "input": "1\n1\n500", "output": "0.001996007984" }, { "input": "1\n500\n1", "output": "0.998003992" }, { "input": "1\n500\n500", "output": "0.5" }, { "input": "1000\n1\n1", "output": "500" }, { "input": "1000\n1\n500", "output": "1.996007984" }, { "input": "1000\n500\n1", "output": "998.003992" }, { "input": "1000\n500\n500", "output": "500" }, { "input": "101\n11\n22", "output": "33.66666667" }, { "input": "987\n1\n3", "output": "246.75" }, { "input": "258\n25\n431", "output": "14.14473684" }, { "input": "979\n39\n60", "output": "385.6666667" }, { "input": "538\n479\n416", "output": "287.9351955" }, { "input": "583\n112\n248", "output": "181.3777778" }, { "input": "978\n467\n371", "output": "545.0190931" }, { "input": "980\n322\n193", "output": "612.7378641" }, { "input": "871\n401\n17", "output": "835.576555" }, { "input": "349\n478\n378", "output": "194.885514" }, { "input": "425\n458\n118", "output": "337.9340278" }, { "input": "919\n323\n458", "output": "380.0729834" }, { "input": "188\n59\n126", "output": "59.95675676" }, { "input": "644\n428\n484", "output": "302.2280702" }, { "input": "253\n80\n276", "output": "56.85393258" }, { "input": "745\n152\n417", "output": "199.0158172" }, { "input": "600\n221\n279", "output": "265.2" }, { "input": "690\n499\n430", "output": "370.6243272" }, { "input": "105\n68\n403", "output": "15.15923567" }, { "input": "762\n462\n371", "output": "422.6218487" }, { "input": "903\n460\n362", "output": "505.3284672" }, { "input": "886\n235\n95", "output": "630.9393939" }, { "input": "655\n203\n18", "output": "601.6515837" }, { "input": "718\n29\n375", "output": "51.53960396" }, { "input": "296\n467\n377", "output": "163.7819905" }, { "input": "539\n61\n56", "output": "281.017094" }, { "input": "133\n53\n124", "output": "39.82485876" }, { "input": "998\n224\n65", "output": "773.5363322" }, { "input": "961\n173\n47", "output": "755.6954545" }, { "input": "285\n468\n62", "output": "251.6603774" }, { "input": "496\n326\n429", "output": "214.1668874" }, { "input": "627\n150\n285", "output": "216.2068966" }, { "input": "961\n443\n50", "output": "863.535497" }, { "input": "623\n422\n217", "output": "411.4334898" }, { "input": "678\n295\n29", "output": "617.3148148" } ]
1,581,093,745
2,147,483,647
Python 3
OK
TESTS
45
124
0
l=int(input()) p=int(input()) q=int(input()) t=l*p y=p+q print(t/y)
Title: Wizards' Duel Time Limit: None seconds Memory Limit: None megabytes Problem Description: Harry Potter and He-Who-Must-Not-Be-Named engaged in a fight to the death once again. This time they are located at opposite ends of the corridor of length *l*. Two opponents simultaneously charge a deadly spell in the enemy. We know that the impulse of Harry's magic spell flies at a speed of *p* meters per second, and the impulse of You-Know-Who's magic spell flies at a speed of *q* meters per second. The impulses are moving through the corridor toward each other, and at the time of the collision they turn round and fly back to those who cast them without changing their original speeds. Then, as soon as the impulse gets back to it's caster, the wizard reflects it and sends again towards the enemy, without changing the original speed of the impulse. Since Harry has perfectly mastered the basics of magic, he knows that after the second collision both impulses will disappear, and a powerful explosion will occur exactly in the place of their collision. However, the young wizard isn't good at math, so he asks you to calculate the distance from his position to the place of the second meeting of the spell impulses, provided that the opponents do not change positions during the whole fight. Input Specification: The first line of the input contains a single integer *l* (1<=≤<=*l*<=≤<=1<=000) — the length of the corridor where the fight takes place. The second line contains integer *p*, the third line contains integer *q* (1<=≤<=*p*,<=*q*<=≤<=500) — the speeds of magical impulses for Harry Potter and He-Who-Must-Not-Be-Named, respectively. Output Specification: Print a single real number — the distance from the end of the corridor, where Harry is located, to the place of the second meeting of the spell impulses. Your answer will be considered correct if its absolute or relative error will not exceed 10<=-<=4. Namely: let's assume that your answer equals *a*, and the answer of the jury is *b*. The checker program will consider your answer correct if . Demo Input: ['100\n50\n50\n', '199\n60\n40\n'] Demo Output: ['50\n', '119.4\n'] Note: In the first sample the speeds of the impulses are equal, so both of their meetings occur exactly in the middle of the corridor.
```python l=int(input()) p=int(input()) q=int(input()) t=l*p y=p+q print(t/y) ```
3
322
B
Ciel and Flowers
PROGRAMMING
1,600
[ "combinatorics", "math" ]
null
null
Fox Ciel has some flowers: *r* red flowers, *g* green flowers and *b* blue flowers. She wants to use these flowers to make several bouquets. There are 4 types of bouquets: - To make a "red bouquet", it needs 3 red flowers. - To make a "green bouquet", it needs 3 green flowers. - To make a "blue bouquet", it needs 3 blue flowers. - To make a "mixing bouquet", it needs 1 red, 1 green and 1 blue flower. Help Fox Ciel to find the maximal number of bouquets she can make.
The first line contains three integers *r*, *g* and *b* (0<=≤<=*r*,<=*g*,<=*b*<=≤<=109) — the number of red, green and blue flowers.
Print the maximal number of bouquets Fox Ciel can make.
[ "3 6 9\n", "4 4 4\n", "0 0 0\n" ]
[ "6\n", "4\n", "0\n" ]
In test case 1, we can make 1 red bouquet, 2 green bouquets and 3 blue bouquets. In test case 2, we can make 1 red, 1 green, 1 blue and 1 mixing bouquet.
1,000
[ { "input": "3 6 9", "output": "6" }, { "input": "4 4 4", "output": "4" }, { "input": "0 0 0", "output": "0" }, { "input": "0 3 6", "output": "3" }, { "input": "7 8 9", "output": "7" }, { "input": "8 8 9", "output": "8" }, { "input": "15 3 999", "output": "339" }, { "input": "32 62 92", "output": "62" }, { "input": "123456789 123456789 123456789", "output": "123456789" }, { "input": "3 5 5", "output": "4" }, { "input": "666806767 385540591 357848286", "output": "470065214" }, { "input": "80010646 727118126 817880463", "output": "541669744" }, { "input": "829651016 732259171 572879931", "output": "711596705" }, { "input": "242854896 442432924 180395753", "output": "288561190" }, { "input": "139978911 5123031 935395222", "output": "360165721" }, { "input": "553182792 10264076 395427398", "output": "319624755" }, { "input": "597790453 720437830 855459575", "output": "724562619" }, { "input": "494914467 356982656 757942689", "output": "536613270" }, { "input": "908118348 67156409 217974865", "output": "397749873" }, { "input": "952726009 629846517 972974334", "output": "851848953" }, { "input": "775140200 616574841 630329230", "output": "674014756" }, { "input": "524780569 326748594 90361407", "output": "313963523" }, { "input": "937984449 184405994 992844522", "output": "705078321" }, { "input": "835108464 525983528 452876698", "output": "604656229" }, { "input": "879716125 531124573 207876166", "output": "539572288" }, { "input": "292920005 241298326 667908343", "output": "400708891" }, { "input": "1000000000 1000000000 1000000000", "output": "1000000000" }, { "input": "1000000000 999999999 999999998", "output": "999999998" }, { "input": "999999998 999999998 999999999", "output": "999999998" }, { "input": "0 1 1", "output": "0" }, { "input": "0 1000000000 0", "output": "333333333" }, { "input": "0 1 0", "output": "0" }, { "input": "1 0 0", "output": "0" }, { "input": "0 2 2", "output": "0" }, { "input": "3 3 5", "output": "3" }, { "input": "2 2 0", "output": "0" }, { "input": "0 5 5", "output": "2" }, { "input": "2 0 11", "output": "3" }, { "input": "9 9 7", "output": "8" }, { "input": "65 30 74", "output": "56" } ]
1,681,279,850
2,147,483,647
PyPy 3-64
OK
TESTS
40
122
0
a,b,c=map(int,input().split()) p=min(a,b,c) ans=a//3+b//3+c//3 for i in range(1,min(p,3)): ans=max(ans,(i+(a-i)//3+(b-i)//3+(c-i)//3)) print(ans)
Title: Ciel and Flowers Time Limit: None seconds Memory Limit: None megabytes Problem Description: Fox Ciel has some flowers: *r* red flowers, *g* green flowers and *b* blue flowers. She wants to use these flowers to make several bouquets. There are 4 types of bouquets: - To make a "red bouquet", it needs 3 red flowers. - To make a "green bouquet", it needs 3 green flowers. - To make a "blue bouquet", it needs 3 blue flowers. - To make a "mixing bouquet", it needs 1 red, 1 green and 1 blue flower. Help Fox Ciel to find the maximal number of bouquets she can make. Input Specification: The first line contains three integers *r*, *g* and *b* (0<=≤<=*r*,<=*g*,<=*b*<=≤<=109) — the number of red, green and blue flowers. Output Specification: Print the maximal number of bouquets Fox Ciel can make. Demo Input: ['3 6 9\n', '4 4 4\n', '0 0 0\n'] Demo Output: ['6\n', '4\n', '0\n'] Note: In test case 1, we can make 1 red bouquet, 2 green bouquets and 3 blue bouquets. In test case 2, we can make 1 red, 1 green, 1 blue and 1 mixing bouquet.
```python a,b,c=map(int,input().split()) p=min(a,b,c) ans=a//3+b//3+c//3 for i in range(1,min(p,3)): ans=max(ans,(i+(a-i)//3+(b-i)//3+(c-i)//3)) print(ans) ```
3
803
A
Maximal Binary Matrix
PROGRAMMING
1,400
[ "constructive algorithms" ]
null
null
You are given matrix with *n* rows and *n* columns filled with zeroes. You should put *k* ones in it in such a way that the resulting matrix is symmetrical with respect to the main diagonal (the diagonal that goes from the top left to the bottom right corner) and is lexicographically maximal. One matrix is lexicographically greater than the other if the first different number in the first different row from the top in the first matrix is greater than the corresponding number in the second one. If there exists no such matrix then output -1.
The first line consists of two numbers *n* and *k* (1<=≤<=*n*<=≤<=100, 0<=≤<=*k*<=≤<=106).
If the answer exists then output resulting matrix. Otherwise output -1.
[ "2 1\n", "3 2\n", "2 5\n" ]
[ "1 0 \n0 0 \n", "1 0 0 \n0 1 0 \n0 0 0 \n", "-1\n" ]
none
0
[ { "input": "2 1", "output": "1 0 \n0 0 " }, { "input": "3 2", "output": "1 0 0 \n0 1 0 \n0 0 0 " }, { "input": "2 5", "output": "-1" }, { "input": "1 0", "output": "0 " }, { "input": "1 1", "output": "1 " }, { "input": "20 398", "output": "1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 \n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 \n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 \n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 \n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 \n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 \n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 \n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 \n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 \n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 \n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 \n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 \n1 1 1 1..." }, { "input": "20 401", "output": "-1" }, { "input": "100 3574", "output": "1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 \n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 \n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1..." }, { "input": "100 10000", "output": "1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 \n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 \n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1..." }, { "input": "100 10001", "output": "-1" }, { "input": "2 3", "output": "1 1 \n1 0 " }, { "input": "4 5", "output": "1 1 1 0 \n1 0 0 0 \n1 0 0 0 \n0 0 0 0 " }, { "input": "5 6", "output": "1 1 1 0 0 \n1 1 0 0 0 \n1 0 0 0 0 \n0 0 0 0 0 \n0 0 0 0 0 " }, { "input": "5 24", "output": "1 1 1 1 1 \n1 1 1 1 1 \n1 1 1 1 1 \n1 1 1 1 1 \n1 1 1 1 0 " }, { "input": "2 0", "output": "0 0 \n0 0 " }, { "input": "3 5", "output": "1 1 1 \n1 0 0 \n1 0 0 " }, { "input": "3 3", "output": "1 1 0 \n1 0 0 \n0 0 0 " }, { "input": "5 10", "output": "1 1 1 1 1 \n1 1 0 0 0 \n1 0 0 0 0 \n1 0 0 0 0 \n1 0 0 0 0 " }, { "input": "3 4", "output": "1 1 0 \n1 1 0 \n0 0 0 " }, { "input": "4 3", "output": "1 1 0 0 \n1 0 0 0 \n0 0 0 0 \n0 0 0 0 " }, { "input": "1 1000000", "output": "-1" }, { "input": "3 6", "output": "1 1 1 \n1 1 0 \n1 0 0 " }, { "input": "1 2", "output": "-1" }, { "input": "1 0", "output": "0 " }, { "input": "1 1", "output": "1 " }, { "input": "1 2", "output": "-1" }, { "input": "1 3", "output": "-1" }, { "input": "1 4", "output": "-1" }, { "input": "1 5", "output": "-1" }, { "input": "1 6", "output": "-1" }, { "input": "1 7", "output": "-1" }, { "input": "1 8", "output": "-1" }, { "input": "1 9", "output": "-1" }, { "input": "1 10", "output": "-1" }, { "input": "1 11", "output": "-1" }, { "input": "1 12", "output": "-1" }, { "input": "1 13", "output": "-1" }, { "input": "1 14", "output": "-1" }, { "input": "1 15", "output": "-1" }, { "input": "1 16", "output": "-1" }, { "input": "1 17", "output": "-1" }, { "input": "1 18", "output": "-1" }, { "input": "1 19", "output": "-1" }, { "input": "1 20", "output": "-1" }, { "input": "1 21", "output": "-1" }, { "input": "1 22", "output": "-1" }, { "input": "1 23", "output": "-1" }, { "input": "1 24", "output": "-1" }, { "input": "1 25", "output": "-1" }, { "input": "1 26", "output": "-1" }, { "input": "2 0", "output": "0 0 \n0 0 " }, { "input": "2 1", "output": "1 0 \n0 0 " }, { "input": "2 2", "output": "1 0 \n0 1 " }, { "input": "2 3", "output": "1 1 \n1 0 " }, { "input": "2 4", "output": "1 1 \n1 1 " }, { "input": "2 5", "output": "-1" }, { "input": "2 6", "output": "-1" }, { "input": "2 7", "output": "-1" }, { "input": "2 8", "output": "-1" }, { "input": "2 9", "output": "-1" }, { "input": "2 10", "output": "-1" }, { "input": "2 11", "output": "-1" }, { "input": "2 12", "output": "-1" }, { "input": "2 13", "output": "-1" }, { "input": "2 14", "output": "-1" }, { "input": "2 15", "output": "-1" }, { "input": "2 16", "output": "-1" }, { "input": "2 17", "output": "-1" }, { "input": "2 18", "output": "-1" }, { "input": "2 19", "output": "-1" }, { "input": "2 20", "output": "-1" }, { "input": "2 21", "output": "-1" }, { "input": "2 22", "output": "-1" }, { "input": "2 23", "output": "-1" }, { "input": "2 24", "output": "-1" }, { "input": "2 25", "output": "-1" }, { "input": "2 26", "output": "-1" }, { "input": "3 0", "output": "0 0 0 \n0 0 0 \n0 0 0 " }, { "input": "3 1", "output": "1 0 0 \n0 0 0 \n0 0 0 " }, { "input": "3 2", "output": "1 0 0 \n0 1 0 \n0 0 0 " }, { "input": "3 3", "output": "1 1 0 \n1 0 0 \n0 0 0 " }, { "input": "3 4", "output": "1 1 0 \n1 1 0 \n0 0 0 " }, { "input": "3 5", "output": "1 1 1 \n1 0 0 \n1 0 0 " }, { "input": "3 6", "output": "1 1 1 \n1 1 0 \n1 0 0 " }, { "input": "3 7", "output": "1 1 1 \n1 1 0 \n1 0 1 " }, { "input": "3 8", "output": "1 1 1 \n1 1 1 \n1 1 0 " }, { "input": "3 9", "output": "1 1 1 \n1 1 1 \n1 1 1 " }, { "input": "3 10", "output": "-1" }, { "input": "3 11", "output": "-1" }, { "input": "3 12", "output": "-1" }, { "input": "3 13", "output": "-1" }, { "input": "3 14", "output": "-1" }, { "input": "3 15", "output": "-1" }, { "input": "3 16", "output": "-1" }, { "input": "3 17", "output": "-1" }, { "input": "3 18", "output": "-1" }, { "input": "3 19", "output": "-1" }, { "input": "3 20", "output": "-1" }, { "input": "3 21", "output": "-1" }, { "input": "3 22", "output": "-1" }, { "input": "3 23", "output": "-1" }, { "input": "3 24", "output": "-1" }, { "input": "3 25", "output": "-1" }, { "input": "3 26", "output": "-1" }, { "input": "4 0", "output": "0 0 0 0 \n0 0 0 0 \n0 0 0 0 \n0 0 0 0 " }, { "input": "4 1", "output": "1 0 0 0 \n0 0 0 0 \n0 0 0 0 \n0 0 0 0 " }, { "input": "4 2", "output": "1 0 0 0 \n0 1 0 0 \n0 0 0 0 \n0 0 0 0 " }, { "input": "4 3", "output": "1 1 0 0 \n1 0 0 0 \n0 0 0 0 \n0 0 0 0 " }, { "input": "4 4", "output": "1 1 0 0 \n1 1 0 0 \n0 0 0 0 \n0 0 0 0 " }, { "input": "4 5", "output": "1 1 1 0 \n1 0 0 0 \n1 0 0 0 \n0 0 0 0 " }, { "input": "4 6", "output": "1 1 1 0 \n1 1 0 0 \n1 0 0 0 \n0 0 0 0 " }, { "input": "4 7", "output": "1 1 1 1 \n1 0 0 0 \n1 0 0 0 \n1 0 0 0 " }, { "input": "4 8", "output": "1 1 1 1 \n1 1 0 0 \n1 0 0 0 \n1 0 0 0 " }, { "input": "4 9", "output": "1 1 1 1 \n1 1 0 0 \n1 0 1 0 \n1 0 0 0 " }, { "input": "4 10", "output": "1 1 1 1 \n1 1 1 0 \n1 1 0 0 \n1 0 0 0 " }, { "input": "4 11", "output": "1 1 1 1 \n1 1 1 0 \n1 1 1 0 \n1 0 0 0 " }, { "input": "4 12", "output": "1 1 1 1 \n1 1 1 1 \n1 1 0 0 \n1 1 0 0 " }, { "input": "4 13", "output": "1 1 1 1 \n1 1 1 1 \n1 1 1 0 \n1 1 0 0 " }, { "input": "4 14", "output": "1 1 1 1 \n1 1 1 1 \n1 1 1 0 \n1 1 0 1 " }, { "input": "4 15", "output": "1 1 1 1 \n1 1 1 1 \n1 1 1 1 \n1 1 1 0 " }, { "input": "4 16", "output": "1 1 1 1 \n1 1 1 1 \n1 1 1 1 \n1 1 1 1 " }, { "input": "4 17", "output": "-1" }, { "input": "4 18", "output": "-1" }, { "input": "4 19", "output": "-1" }, { "input": "4 20", "output": "-1" }, { "input": "4 21", "output": "-1" }, { "input": "4 22", "output": "-1" }, { "input": "4 23", "output": "-1" }, { "input": "4 24", "output": "-1" }, { "input": "4 25", "output": "-1" }, { "input": "4 26", "output": "-1" }, { "input": "5 0", "output": "0 0 0 0 0 \n0 0 0 0 0 \n0 0 0 0 0 \n0 0 0 0 0 \n0 0 0 0 0 " }, { "input": "5 1", "output": "1 0 0 0 0 \n0 0 0 0 0 \n0 0 0 0 0 \n0 0 0 0 0 \n0 0 0 0 0 " }, { "input": "5 2", "output": "1 0 0 0 0 \n0 1 0 0 0 \n0 0 0 0 0 \n0 0 0 0 0 \n0 0 0 0 0 " }, { "input": "5 3", "output": "1 1 0 0 0 \n1 0 0 0 0 \n0 0 0 0 0 \n0 0 0 0 0 \n0 0 0 0 0 " }, { "input": "5 4", "output": "1 1 0 0 0 \n1 1 0 0 0 \n0 0 0 0 0 \n0 0 0 0 0 \n0 0 0 0 0 " }, { "input": "5 5", "output": "1 1 1 0 0 \n1 0 0 0 0 \n1 0 0 0 0 \n0 0 0 0 0 \n0 0 0 0 0 " }, { "input": "5 6", "output": "1 1 1 0 0 \n1 1 0 0 0 \n1 0 0 0 0 \n0 0 0 0 0 \n0 0 0 0 0 " }, { "input": "5 7", "output": "1 1 1 1 0 \n1 0 0 0 0 \n1 0 0 0 0 \n1 0 0 0 0 \n0 0 0 0 0 " }, { "input": "5 8", "output": "1 1 1 1 0 \n1 1 0 0 0 \n1 0 0 0 0 \n1 0 0 0 0 \n0 0 0 0 0 " }, { "input": "5 9", "output": "1 1 1 1 1 \n1 0 0 0 0 \n1 0 0 0 0 \n1 0 0 0 0 \n1 0 0 0 0 " }, { "input": "5 10", "output": "1 1 1 1 1 \n1 1 0 0 0 \n1 0 0 0 0 \n1 0 0 0 0 \n1 0 0 0 0 " }, { "input": "5 11", "output": "1 1 1 1 1 \n1 1 0 0 0 \n1 0 1 0 0 \n1 0 0 0 0 \n1 0 0 0 0 " }, { "input": "5 12", "output": "1 1 1 1 1 \n1 1 1 0 0 \n1 1 0 0 0 \n1 0 0 0 0 \n1 0 0 0 0 " }, { "input": "5 13", "output": "1 1 1 1 1 \n1 1 1 0 0 \n1 1 1 0 0 \n1 0 0 0 0 \n1 0 0 0 0 " }, { "input": "5 14", "output": "1 1 1 1 1 \n1 1 1 1 0 \n1 1 0 0 0 \n1 1 0 0 0 \n1 0 0 0 0 " }, { "input": "5 15", "output": "1 1 1 1 1 \n1 1 1 1 0 \n1 1 1 0 0 \n1 1 0 0 0 \n1 0 0 0 0 " }, { "input": "5 16", "output": "1 1 1 1 1 \n1 1 1 1 1 \n1 1 0 0 0 \n1 1 0 0 0 \n1 1 0 0 0 " }, { "input": "5 17", "output": "1 1 1 1 1 \n1 1 1 1 1 \n1 1 1 0 0 \n1 1 0 0 0 \n1 1 0 0 0 " }, { "input": "5 18", "output": "1 1 1 1 1 \n1 1 1 1 1 \n1 1 1 0 0 \n1 1 0 1 0 \n1 1 0 0 0 " }, { "input": "5 19", "output": "1 1 1 1 1 \n1 1 1 1 1 \n1 1 1 1 0 \n1 1 1 0 0 \n1 1 0 0 0 " }, { "input": "5 20", "output": "1 1 1 1 1 \n1 1 1 1 1 \n1 1 1 1 0 \n1 1 1 1 0 \n1 1 0 0 0 " }, { "input": "5 21", "output": "1 1 1 1 1 \n1 1 1 1 1 \n1 1 1 1 1 \n1 1 1 0 0 \n1 1 1 0 0 " }, { "input": "5 22", "output": "1 1 1 1 1 \n1 1 1 1 1 \n1 1 1 1 1 \n1 1 1 1 0 \n1 1 1 0 0 " }, { "input": "5 23", "output": "1 1 1 1 1 \n1 1 1 1 1 \n1 1 1 1 1 \n1 1 1 1 0 \n1 1 1 0 1 " }, { "input": "5 24", "output": "1 1 1 1 1 \n1 1 1 1 1 \n1 1 1 1 1 \n1 1 1 1 1 \n1 1 1 1 0 " }, { "input": "5 25", "output": "1 1 1 1 1 \n1 1 1 1 1 \n1 1 1 1 1 \n1 1 1 1 1 \n1 1 1 1 1 " }, { "input": "5 26", "output": "-1" }, { "input": "100 0", "output": "0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 \n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 \n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0..." }, { "input": "100 1", "output": "1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 \n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 \n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0..." }, { "input": "100 2", "output": "1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 \n0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 \n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0..." }, { "input": "100 3", "output": "1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 \n1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 \n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0..." }, { "input": "100 99", "output": "1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 \n1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 \n1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0..." }, { "input": "100 100", "output": "1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 \n1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 \n1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0..." }, { "input": "100 101", "output": "1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 \n1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 \n1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0..." }, { "input": "100 9999", "output": "1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 \n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 \n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1..." }, { "input": "100 10000", "output": "1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 \n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 \n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1..." }, { "input": "100 10001", "output": "-1" } ]
1,698,763,579
2,147,483,647
Python 3
OK
TESTS
168
93
10,956,800
n, k = map(int, input().split()) vis = [[0 for _ in range(1000)] for _ in range(1000)] flag = True if k > n * n: flag = False else: for i in range(n): for j in range(n): if vis[i][j] != 0: continue elif i == j and k != 0: vis[i][j] = 1 k -= 1 elif k >= 2: vis[i][j] = vis[j][i] = 1 k -= 2 if k: flag = False if flag: for i in range(n): for j in range(n): if j == 0: print(vis[i][j], end="") else: print(" " + str(vis[i][j]), end="") print() else: print("-1")
Title: Maximal Binary Matrix Time Limit: None seconds Memory Limit: None megabytes Problem Description: You are given matrix with *n* rows and *n* columns filled with zeroes. You should put *k* ones in it in such a way that the resulting matrix is symmetrical with respect to the main diagonal (the diagonal that goes from the top left to the bottom right corner) and is lexicographically maximal. One matrix is lexicographically greater than the other if the first different number in the first different row from the top in the first matrix is greater than the corresponding number in the second one. If there exists no such matrix then output -1. Input Specification: The first line consists of two numbers *n* and *k* (1<=≤<=*n*<=≤<=100, 0<=≤<=*k*<=≤<=106). Output Specification: If the answer exists then output resulting matrix. Otherwise output -1. Demo Input: ['2 1\n', '3 2\n', '2 5\n'] Demo Output: ['1 0 \n0 0 \n', '1 0 0 \n0 1 0 \n0 0 0 \n', '-1\n'] Note: none
```python n, k = map(int, input().split()) vis = [[0 for _ in range(1000)] for _ in range(1000)] flag = True if k > n * n: flag = False else: for i in range(n): for j in range(n): if vis[i][j] != 0: continue elif i == j and k != 0: vis[i][j] = 1 k -= 1 elif k >= 2: vis[i][j] = vis[j][i] = 1 k -= 2 if k: flag = False if flag: for i in range(n): for j in range(n): if j == 0: print(vis[i][j], end="") else: print(" " + str(vis[i][j]), end="") print() else: print("-1") ```
3
616
B
Dinner with Emma
PROGRAMMING
1,000
[ "games", "greedy" ]
null
null
Jack decides to invite Emma out for a dinner. Jack is a modest student, he doesn't want to go to an expensive restaurant. Emma is a girl with high taste, she prefers elite places. Munhattan consists of *n* streets and *m* avenues. There is exactly one restaurant on the intersection of each street and avenue. The streets are numbered with integers from 1 to *n* and the avenues are numbered with integers from 1 to *m*. The cost of dinner in the restaurant at the intersection of the *i*-th street and the *j*-th avenue is *c**ij*. Jack and Emma decide to choose the restaurant in the following way. Firstly Emma chooses the street to dinner and then Jack chooses the avenue. Emma and Jack makes their choice optimally: Emma wants to maximize the cost of the dinner, Jack wants to minimize it. Emma takes into account that Jack wants to minimize the cost of the dinner. Find the cost of the dinner for the couple in love.
The first line contains two integers *n*,<=*m* (1<=≤<=*n*,<=*m*<=≤<=100) — the number of streets and avenues in Munhattan. Each of the next *n* lines contains *m* integers *c**ij* (1<=≤<=*c**ij*<=≤<=109) — the cost of the dinner in the restaurant on the intersection of the *i*-th street and the *j*-th avenue.
Print the only integer *a* — the cost of the dinner for Jack and Emma.
[ "3 4\n4 1 3 5\n2 2 2 2\n5 4 5 1\n", "3 3\n1 2 3\n2 3 1\n3 1 2\n" ]
[ "2\n", "1\n" ]
In the first example if Emma chooses the first or the third streets Jack can choose an avenue with the cost of the dinner 1. So she chooses the second street and Jack chooses any avenue. The cost of the dinner is 2. In the second example regardless of Emma's choice Jack can choose a restaurant with the cost of the dinner 1.
0
[ { "input": "3 4\n4 1 3 5\n2 2 2 2\n5 4 5 1", "output": "2" }, { "input": "3 3\n1 2 3\n2 3 1\n3 1 2", "output": "1" }, { "input": "1 1\n1", "output": "1" }, { "input": "1 10\n74 35 82 39 1 84 29 41 70 12", "output": "1" }, { "input": "10 1\n44\n23\n65\n17\n48\n29\n49\n88\n91\n85", "output": "91" }, { "input": "10 10\n256 72 455 45 912 506 235 68 951 92\n246 305 45 212 788 621 449 876 459 899\n732 107 230 357 370 610 997 669 61 192\n131 93 481 527 983 920 825 540 435 54\n777 682 984 20 337 480 264 137 249 502\n51 467 479 228 923 752 714 436 199 973\n3 91 612 571 631 212 751 84 886 948\n252 130 583 23 194 985 234 978 709 16\n636 991 203 469 719 540 184 902 503 652\n826 680 150 284 37 987 360 183 447 51", "output": "184" }, { "input": "1 1\n1000000000", "output": "1000000000" }, { "input": "2 1\n999999999\n1000000000", "output": "1000000000" } ]
1,596,017,349
2,147,483,647
PyPy 3
RUNTIME_ERROR
TESTS
0
186
22,323,200
n,m,k=list(map(int,input().split())) if n&1: i=2 flag=False while(i*i<=m): if m%i==0 and (k<=i<m or k<=m//i<m): flag=True break i+=1 print("Timur") if flag else print("Marsel") else: print("Marsel")
Title: Dinner with Emma Time Limit: None seconds Memory Limit: None megabytes Problem Description: Jack decides to invite Emma out for a dinner. Jack is a modest student, he doesn't want to go to an expensive restaurant. Emma is a girl with high taste, she prefers elite places. Munhattan consists of *n* streets and *m* avenues. There is exactly one restaurant on the intersection of each street and avenue. The streets are numbered with integers from 1 to *n* and the avenues are numbered with integers from 1 to *m*. The cost of dinner in the restaurant at the intersection of the *i*-th street and the *j*-th avenue is *c**ij*. Jack and Emma decide to choose the restaurant in the following way. Firstly Emma chooses the street to dinner and then Jack chooses the avenue. Emma and Jack makes their choice optimally: Emma wants to maximize the cost of the dinner, Jack wants to minimize it. Emma takes into account that Jack wants to minimize the cost of the dinner. Find the cost of the dinner for the couple in love. Input Specification: The first line contains two integers *n*,<=*m* (1<=≤<=*n*,<=*m*<=≤<=100) — the number of streets and avenues in Munhattan. Each of the next *n* lines contains *m* integers *c**ij* (1<=≤<=*c**ij*<=≤<=109) — the cost of the dinner in the restaurant on the intersection of the *i*-th street and the *j*-th avenue. Output Specification: Print the only integer *a* — the cost of the dinner for Jack and Emma. Demo Input: ['3 4\n4 1 3 5\n2 2 2 2\n5 4 5 1\n', '3 3\n1 2 3\n2 3 1\n3 1 2\n'] Demo Output: ['2\n', '1\n'] Note: In the first example if Emma chooses the first or the third streets Jack can choose an avenue with the cost of the dinner 1. So she chooses the second street and Jack chooses any avenue. The cost of the dinner is 2. In the second example regardless of Emma's choice Jack can choose a restaurant with the cost of the dinner 1.
```python n,m,k=list(map(int,input().split())) if n&1: i=2 flag=False while(i*i<=m): if m%i==0 and (k<=i<m or k<=m//i<m): flag=True break i+=1 print("Timur") if flag else print("Marsel") else: print("Marsel") ```
-1
555
A
Case of Matryoshkas
PROGRAMMING
1,500
[ "implementation" ]
null
null
Andrewid the Android is a galaxy-famous detective. He is now investigating the case of vandalism at the exhibition of contemporary art. The main exhibit is a construction of *n* matryoshka dolls that can be nested one into another. The matryoshka dolls are numbered from 1 to *n*. A matryoshka with a smaller number can be nested in a matryoshka with a higher number, two matryoshkas can not be directly nested in the same doll, but there may be chain nestings, for example, 1<=→<=2<=→<=4<=→<=5. In one second, you can perform one of the two following operations: - Having a matryoshka *a* that isn't nested in any other matryoshka and a matryoshka *b*, such that *b* doesn't contain any other matryoshka and is not nested in any other matryoshka, you may put *a* in *b*; - Having a matryoshka *a* directly contained in matryoshka *b*, such that *b* is not nested in any other matryoshka, you may get *a* out of *b*. According to the modern aesthetic norms the matryoshka dolls on display were assembled in a specific configuration, i.e. as several separate chains of nested matryoshkas, but the criminal, following the mysterious plan, took out all the dolls and assembled them into a single large chain (1<=→<=2<=→<=...<=→<=*n*). In order to continue the investigation Andrewid needs to know in what minimum time it is possible to perform this action.
The first line contains integers *n* (1<=≤<=*n*<=≤<=105) and *k* (1<=≤<=*k*<=≤<=105) — the number of matryoshkas and matryoshka chains in the initial configuration. The next *k* lines contain the descriptions of the chains: the *i*-th line first contains number *m**i* (1<=≤<=*m**i*<=≤<=*n*), and then *m**i* numbers *a**i*1,<=*a**i*2,<=...,<=*a**im**i* — the numbers of matryoshkas in the chain (matryoshka *a**i*1 is nested into matryoshka *a**i*2, that is nested into matryoshka *a**i*3, and so on till the matryoshka *a**im**i* that isn't nested into any other matryoshka). It is guaranteed that *m*1<=+<=*m*2<=+<=...<=+<=*m**k*<==<=*n*, the numbers of matryoshkas in all the chains are distinct, in each chain the numbers of matryoshkas follow in the ascending order.
In the single line print the minimum number of seconds needed to assemble one large chain from the initial configuration.
[ "3 2\n2 1 2\n1 3\n", "7 3\n3 1 3 7\n2 2 5\n2 4 6\n" ]
[ "1\n", "10\n" ]
In the first sample test there are two chains: 1 → 2 and 3. In one second you can nest the first chain into the second one and get 1 → 2 → 3. In the second sample test you need to disassemble all the three chains into individual matryoshkas in 2 + 1 + 1 = 4 seconds and then assemble one big chain in 6 seconds.
250
[ { "input": "3 2\n2 1 2\n1 3", "output": "1" }, { "input": "7 3\n3 1 3 7\n2 2 5\n2 4 6", "output": "10" }, { "input": "1 1\n1 1", "output": "0" }, { "input": "3 2\n1 2\n2 1 3", "output": "3" }, { "input": "5 3\n1 4\n3 1 2 3\n1 5", "output": "2" }, { "input": "8 5\n2 1 2\n2 3 4\n1 5\n2 6 7\n1 8", "output": "8" }, { "input": "10 10\n1 5\n1 4\n1 10\n1 3\n1 7\n1 1\n1 8\n1 6\n1 9\n1 2", "output": "9" }, { "input": "20 6\n3 8 9 13\n3 4 14 20\n2 15 17\n3 2 5 11\n5 7 10 12 18 19\n4 1 3 6 16", "output": "33" }, { "input": "50 10\n6 17 21 31 42 45 49\n6 11 12 15 22 26 38\n3 9 29 36\n3 10 23 43\n5 14 19 28 46 48\n2 30 39\n6 13 20 24 33 37 47\n8 1 2 3 4 5 6 7 8\n7 16 18 25 27 34 40 44\n4 32 35 41 50", "output": "75" }, { "input": "13 8\n1 5\n2 8 10\n1 13\n4 1 2 3 11\n1 7\n2 6 12\n1 4\n1 9", "output": "13" }, { "input": "21 13\n1 18\n2 8 13\n1 21\n1 17\n2 7 9\n1 20\n1 19\n1 4\n1 16\n2 5 6\n3 12 14 15\n3 1 2 3\n2 10 11", "output": "24" }, { "input": "50 50\n1 2\n1 5\n1 28\n1 46\n1 42\n1 24\n1 3\n1 37\n1 33\n1 50\n1 23\n1 40\n1 43\n1 26\n1 49\n1 34\n1 8\n1 45\n1 15\n1 1\n1 22\n1 18\n1 27\n1 25\n1 13\n1 39\n1 38\n1 10\n1 44\n1 6\n1 17\n1 47\n1 7\n1 35\n1 20\n1 36\n1 31\n1 21\n1 32\n1 29\n1 4\n1 12\n1 19\n1 16\n1 11\n1 41\n1 9\n1 14\n1 30\n1 48", "output": "49" }, { "input": "100 3\n45 1 2 3 4 5 6 7 8 9 19 21 24 27 28 30 34 35 37 39 40 41 42 43 46 47 48 51 52 55 58 59 61 63 64 66 69 71 76 80 85 86 88 89 94 99\n26 10 11 15 18 23 29 31 33 36 38 44 49 54 56 60 62 65 75 78 82 83 84 95 96 97 98\n29 12 13 14 16 17 20 22 25 26 32 45 50 53 57 67 68 70 72 73 74 77 79 81 87 90 91 92 93 100", "output": "180" }, { "input": "100 19\n6 62 72 83 91 94 97\n3 61 84 99\n1 63\n5 46 53 56 69 78\n5 41 43 49 74 89\n5 55 57 79 85 87\n3 47 59 98\n3 64 76 82\n3 48 66 75\n2 60 88\n2 67 77\n4 40 51 73 95\n41 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 44 71 81\n4 58 65 90 93\n1 100\n5 39 45 52 80 86\n2 50 68\n1 92\n4 42 54 70 96", "output": "106" } ]
1,600,335,078
2,147,483,647
Python 3
OK
TESTS
47
312
7,372,800
n, k = map(int, input().split()) for _ in range(k): a=list(map(int, input().split()))[1:]+[0] if a[0]!=1: continue i=0 while a[i+1]==i+2: i+=1 #print(i) print(2*n-k-1-2*i)
Title: Case of Matryoshkas Time Limit: None seconds Memory Limit: None megabytes Problem Description: Andrewid the Android is a galaxy-famous detective. He is now investigating the case of vandalism at the exhibition of contemporary art. The main exhibit is a construction of *n* matryoshka dolls that can be nested one into another. The matryoshka dolls are numbered from 1 to *n*. A matryoshka with a smaller number can be nested in a matryoshka with a higher number, two matryoshkas can not be directly nested in the same doll, but there may be chain nestings, for example, 1<=→<=2<=→<=4<=→<=5. In one second, you can perform one of the two following operations: - Having a matryoshka *a* that isn't nested in any other matryoshka and a matryoshka *b*, such that *b* doesn't contain any other matryoshka and is not nested in any other matryoshka, you may put *a* in *b*; - Having a matryoshka *a* directly contained in matryoshka *b*, such that *b* is not nested in any other matryoshka, you may get *a* out of *b*. According to the modern aesthetic norms the matryoshka dolls on display were assembled in a specific configuration, i.e. as several separate chains of nested matryoshkas, but the criminal, following the mysterious plan, took out all the dolls and assembled them into a single large chain (1<=→<=2<=→<=...<=→<=*n*). In order to continue the investigation Andrewid needs to know in what minimum time it is possible to perform this action. Input Specification: The first line contains integers *n* (1<=≤<=*n*<=≤<=105) and *k* (1<=≤<=*k*<=≤<=105) — the number of matryoshkas and matryoshka chains in the initial configuration. The next *k* lines contain the descriptions of the chains: the *i*-th line first contains number *m**i* (1<=≤<=*m**i*<=≤<=*n*), and then *m**i* numbers *a**i*1,<=*a**i*2,<=...,<=*a**im**i* — the numbers of matryoshkas in the chain (matryoshka *a**i*1 is nested into matryoshka *a**i*2, that is nested into matryoshka *a**i*3, and so on till the matryoshka *a**im**i* that isn't nested into any other matryoshka). It is guaranteed that *m*1<=+<=*m*2<=+<=...<=+<=*m**k*<==<=*n*, the numbers of matryoshkas in all the chains are distinct, in each chain the numbers of matryoshkas follow in the ascending order. Output Specification: In the single line print the minimum number of seconds needed to assemble one large chain from the initial configuration. Demo Input: ['3 2\n2 1 2\n1 3\n', '7 3\n3 1 3 7\n2 2 5\n2 4 6\n'] Demo Output: ['1\n', '10\n'] Note: In the first sample test there are two chains: 1 → 2 and 3. In one second you can nest the first chain into the second one and get 1 → 2 → 3. In the second sample test you need to disassemble all the three chains into individual matryoshkas in 2 + 1 + 1 = 4 seconds and then assemble one big chain in 6 seconds.
```python n, k = map(int, input().split()) for _ in range(k): a=list(map(int, input().split()))[1:]+[0] if a[0]!=1: continue i=0 while a[i+1]==i+2: i+=1 #print(i) print(2*n-k-1-2*i) ```
3
485
B
Valuable Resources
PROGRAMMING
1,300
[ "brute force", "greedy" ]
null
null
Many computer strategy games require building cities, recruiting army, conquering tribes, collecting resources. Sometimes it leads to interesting problems. Let's suppose that your task is to build a square city. The world map uses the Cartesian coordinates. The sides of the city should be parallel to coordinate axes. The map contains mines with valuable resources, located at some points with integer coordinates. The sizes of mines are relatively small, i.e. they can be treated as points. The city should be built in such a way that all the mines are inside or on the border of the city square. Building a city takes large amount of money depending on the size of the city, so you have to build the city with the minimum area. Given the positions of the mines find the minimum possible area of the city.
The first line of the input contains number *n* — the number of mines on the map (2<=≤<=*n*<=≤<=1000). Each of the next *n* lines contains a pair of integers *x**i* and *y**i* — the coordinates of the corresponding mine (<=-<=109<=≤<=*x**i*,<=*y**i*<=≤<=109). All points are pairwise distinct.
Print the minimum area of the city that can cover all the mines with valuable resources.
[ "2\n0 0\n2 2\n", "2\n0 0\n0 3\n" ]
[ "4\n", "9\n" ]
none
500
[ { "input": "2\n0 0\n2 2", "output": "4" }, { "input": "2\n0 0\n0 3", "output": "9" }, { "input": "2\n0 1\n1 0", "output": "1" }, { "input": "3\n2 2\n1 1\n3 3", "output": "4" }, { "input": "3\n3 1\n1 3\n2 2", "output": "4" }, { "input": "3\n0 1\n1 0\n2 2", "output": "4" }, { "input": "2\n-1000000000 -1000000000\n1000000000 1000000000", "output": "4000000000000000000" }, { "input": "2\n1000000000 -1000000000\n-1000000000 1000000000", "output": "4000000000000000000" }, { "input": "5\n-851545463 -208880322\n-154983867 -781305244\n293363100 785256340\n833468900 -593065920\n-920692803 -637662144", "output": "3077083280271860209" }, { "input": "10\n-260530833 169589238\n-681955770 -35391010\n223450511 24504262\n479795061 -26191863\n-291344265 21153856\n714700263 -328447419\n-858655942 161086142\n-270884153 462537328\n-501424901 977460517\n115284904 -151626824", "output": "2475449747812002025" }, { "input": "10\n917139470 819990899\n-69828590 691215072\n-846815289 112372447\n560780737 -890423729\n243241705 284240970\n-47397355 -263709479\n759162072 709456353\n-330469400 -597545533\n436509256 728506920\n133368867 668789238", "output": "3111536391798748081" }, { "input": "10\n-200157522 -824574736\n299208799 -287211553\n-160170880 148363130\n103709327 245344406\n482860382 547328085\n895537733 -545816336\n671947380 910981768\n-43209851 585461399\n-573679087 427675821\n151452830 27262384", "output": "3012156378576702016" }, { "input": "2\n-2 -2\n-3 -3", "output": "1" }, { "input": "2\n-1000 -1000\n-1100 -1100", "output": "10000" }, { "input": "2\n-5 -5\n-4 -4", "output": "1" }, { "input": "2\n-10 0\n-9 0", "output": "1" }, { "input": "2\n-10 -10\n-20 -20", "output": "100" }, { "input": "2\n-1000000 -1000000\n-100 -100", "output": "999800010000" }, { "input": "2\n100000000 100000000\n200000000 200000000", "output": "10000000000000000" }, { "input": "2\n-10 10\n-2 3", "output": "64" }, { "input": "2\n-999999999 -999999999\n-999999991 -999999991", "output": "64" }, { "input": "2\n-1000 -1000\n-999 -999", "output": "1" }, { "input": "2\n-3 0\n-5 0", "output": "4" }, { "input": "2\n999999999 999999999\n999999991 999999991", "output": "64" }, { "input": "2\n100000012 100000012\n100000012 100000013", "output": "1" } ]
1,437,759,863
4,763
Python 3
OK
TESTS
45
62
0
# mukulchandel import sys n=int(sys.stdin.readline()) mx=-1234567890 my=-1234567890 nx=1234567890 ny=1234567890 for i in range(n): x,y=map(int,sys.stdin.readline().split()) mx=max(mx,x) my=max(my,y) nx=min(nx,x) ny=min(ny,y) print(max((mx-nx),(my-ny))**2)
Title: Valuable Resources Time Limit: None seconds Memory Limit: None megabytes Problem Description: Many computer strategy games require building cities, recruiting army, conquering tribes, collecting resources. Sometimes it leads to interesting problems. Let's suppose that your task is to build a square city. The world map uses the Cartesian coordinates. The sides of the city should be parallel to coordinate axes. The map contains mines with valuable resources, located at some points with integer coordinates. The sizes of mines are relatively small, i.e. they can be treated as points. The city should be built in such a way that all the mines are inside or on the border of the city square. Building a city takes large amount of money depending on the size of the city, so you have to build the city with the minimum area. Given the positions of the mines find the minimum possible area of the city. Input Specification: The first line of the input contains number *n* — the number of mines on the map (2<=≤<=*n*<=≤<=1000). Each of the next *n* lines contains a pair of integers *x**i* and *y**i* — the coordinates of the corresponding mine (<=-<=109<=≤<=*x**i*,<=*y**i*<=≤<=109). All points are pairwise distinct. Output Specification: Print the minimum area of the city that can cover all the mines with valuable resources. Demo Input: ['2\n0 0\n2 2\n', '2\n0 0\n0 3\n'] Demo Output: ['4\n', '9\n'] Note: none
```python # mukulchandel import sys n=int(sys.stdin.readline()) mx=-1234567890 my=-1234567890 nx=1234567890 ny=1234567890 for i in range(n): x,y=map(int,sys.stdin.readline().split()) mx=max(mx,x) my=max(my,y) nx=min(nx,x) ny=min(ny,y) print(max((mx-nx),(my-ny))**2) ```
3
0
none
none
none
0
[ "none" ]
null
null
Little Petya likes points a lot. Recently his mom has presented him *n* points lying on the line *OX*. Now Petya is wondering in how many ways he can choose three distinct points so that the distance between the two farthest of them doesn't exceed *d*. Note that the order of the points inside the group of three chosen points doesn't matter.
The first line contains two integers: *n* and *d* (1<=≤<=*n*<=≤<=105; 1<=≤<=*d*<=≤<=109). The next line contains *n* integers *x*1,<=*x*2,<=...,<=*x**n*, their absolute value doesn't exceed 109 — the *x*-coordinates of the points that Petya has got. It is guaranteed that the coordinates of the points in the input strictly increase.
Print a single integer — the number of groups of three points, where the distance between two farthest points doesn't exceed *d*. Please do not use the %lld specifier to read or write 64-bit integers in С++. It is preferred to use the cin, cout streams or the %I64d specifier.
[ "4 3\n1 2 3 4\n", "4 2\n-3 -2 -1 0\n", "5 19\n1 10 20 30 50\n" ]
[ "4\n", "2\n", "1\n" ]
In the first sample any group of three points meets our conditions. In the seconds sample only 2 groups of three points meet our conditions: {-3, -2, -1} and {-2, -1, 0}. In the third sample only one group does: {1, 10, 20}.
0
[ { "input": "4 3\n1 2 3 4", "output": "4" }, { "input": "4 2\n-3 -2 -1 0", "output": "2" }, { "input": "5 19\n1 10 20 30 50", "output": "1" }, { "input": "10 5\n31 36 43 47 48 50 56 69 71 86", "output": "2" }, { "input": "10 50\n1 4 20 27 65 79 82 83 99 100", "output": "25" }, { "input": "10 90\n24 27 40 41 61 69 73 87 95 97", "output": "120" }, { "input": "100 100\n-98 -97 -96 -93 -92 -91 -90 -87 -86 -84 -81 -80 -79 -78 -76 -75 -73 -71 -69 -67 -65 -64 -63 -62 -61 -54 -51 -50 -49 -48 -46 -45 -44 -37 -36 -33 -30 -28 -27 -16 -15 -13 -12 -10 -9 -7 -6 -5 -4 2 3 5 8 9 10 11 13 14 15 16 17 19 22 24 25 26 27 28 30 31 32 36 40 43 45 46 47 50 51 52 53 58 60 63 69 70 73 78 80 81 82 85 88 89 90 91 95 96 97 99", "output": "79351" }, { "input": "1 14751211\n847188590", "output": "0" }, { "input": "2 1000000000\n-907894512 -289906312", "output": "0" }, { "input": "2 1000000000\n-14348867 1760823", "output": "0" }, { "input": "3 1000000000\n-5 -1 1", "output": "1" } ]
1,649,607,360
2,147,483,647
Python 3
RUNTIME_ERROR
TESTS
0
30
716,800
#!/usr/bin/env python3 import math import re from typing import List, Tuple from attr import has from scipy.misc import face def main(): t = int(input()) answers: List[int] = [] for _ in range(t): n_members = int(input()) problems = [int(x) for x in input().strip().split(' ')] answers.append(solution(n_members, problems)) for a in answers: print(a % 998_244_353) def solution(n: int, problems: List[int]) -> int: first_max, first_count, second_max, second_count = find_maxs(problems) if first_count > 1: return math.factorial(n) if first_max >= n: return 0 if first_max == second_max + 1: return int(math.factorial(n) * (1 - (first_count / n))) else: return 0 def find_maxs(problems: List[int]) -> Tuple[int, int, int, int]: first_count, second_count = 0, 0 first_max = 0 second_max = 0 for val in problems: if val > first_max: second_max = first_max first_max = val second_count = first_count first_count = 1 elif val == first_max: first_count += 1 elif val == second_max: second_count += 1 return (first_max, first_count, second_max, second_count) if __name__ == '__main__': main()
Title: none Time Limit: None seconds Memory Limit: None megabytes Problem Description: Little Petya likes points a lot. Recently his mom has presented him *n* points lying on the line *OX*. Now Petya is wondering in how many ways he can choose three distinct points so that the distance between the two farthest of them doesn't exceed *d*. Note that the order of the points inside the group of three chosen points doesn't matter. Input Specification: The first line contains two integers: *n* and *d* (1<=≤<=*n*<=≤<=105; 1<=≤<=*d*<=≤<=109). The next line contains *n* integers *x*1,<=*x*2,<=...,<=*x**n*, their absolute value doesn't exceed 109 — the *x*-coordinates of the points that Petya has got. It is guaranteed that the coordinates of the points in the input strictly increase. Output Specification: Print a single integer — the number of groups of three points, where the distance between two farthest points doesn't exceed *d*. Please do not use the %lld specifier to read or write 64-bit integers in С++. It is preferred to use the cin, cout streams or the %I64d specifier. Demo Input: ['4 3\n1 2 3 4\n', '4 2\n-3 -2 -1 0\n', '5 19\n1 10 20 30 50\n'] Demo Output: ['4\n', '2\n', '1\n'] Note: In the first sample any group of three points meets our conditions. In the seconds sample only 2 groups of three points meet our conditions: {-3, -2, -1} and {-2, -1, 0}. In the third sample only one group does: {1, 10, 20}.
```python #!/usr/bin/env python3 import math import re from typing import List, Tuple from attr import has from scipy.misc import face def main(): t = int(input()) answers: List[int] = [] for _ in range(t): n_members = int(input()) problems = [int(x) for x in input().strip().split(' ')] answers.append(solution(n_members, problems)) for a in answers: print(a % 998_244_353) def solution(n: int, problems: List[int]) -> int: first_max, first_count, second_max, second_count = find_maxs(problems) if first_count > 1: return math.factorial(n) if first_max >= n: return 0 if first_max == second_max + 1: return int(math.factorial(n) * (1 - (first_count / n))) else: return 0 def find_maxs(problems: List[int]) -> Tuple[int, int, int, int]: first_count, second_count = 0, 0 first_max = 0 second_max = 0 for val in problems: if val > first_max: second_max = first_max first_max = val second_count = first_count first_count = 1 elif val == first_max: first_count += 1 elif val == second_max: second_count += 1 return (first_max, first_count, second_max, second_count) if __name__ == '__main__': main() ```
-1
492
C
Vanya and Exams
PROGRAMMING
1,400
[ "greedy", "sortings" ]
null
null
Vanya wants to pass *n* exams and get the academic scholarship. He will get the scholarship if the average grade mark for all the exams is at least *avg*. The exam grade cannot exceed *r*. Vanya has passed the exams and got grade *a**i* for the *i*-th exam. To increase the grade for the *i*-th exam by 1 point, Vanya must write *b**i* essays. He can raise the exam grade multiple times. What is the minimum number of essays that Vanya needs to write to get scholarship?
The first line contains three integers *n*, *r*, *avg* (1<=≤<=*n*<=≤<=105, 1<=≤<=*r*<=≤<=109, 1<=≤<=*avg*<=≤<=*min*(*r*,<=106)) — the number of exams, the maximum grade and the required grade point average, respectively. Each of the following *n* lines contains space-separated integers *a**i* and *b**i* (1<=≤<=*a**i*<=≤<=*r*, 1<=≤<=*b**i*<=≤<=106).
In the first line print the minimum number of essays.
[ "5 5 4\n5 2\n4 7\n3 1\n3 2\n2 5\n", "2 5 4\n5 2\n5 2\n" ]
[ "4\n", "0\n" ]
In the first sample Vanya can write 2 essays for the 3rd exam to raise his grade by 2 points and 2 essays for the 4th exam to raise his grade by 1 point. In the second sample, Vanya doesn't need to write any essays as his general point average already is above average.
1,500
[ { "input": "5 5 4\n5 2\n4 7\n3 1\n3 2\n2 5", "output": "4" }, { "input": "2 5 4\n5 2\n5 2", "output": "0" }, { "input": "6 5 5\n1 7\n2 4\n3 5\n4 6\n5 6\n4 7", "output": "63" }, { "input": "1 1000000000 1000000\n1 1000000", "output": "999999000000" }, { "input": "10 10 7\n1 10\n2 9\n3 8\n4 7\n5 6\n6 5\n7 4\n8 3\n9 2\n10 1", "output": "70" }, { "input": "3 5 2\n1 10\n1 7\n1 4", "output": "12" }, { "input": "10 10 10\n9 8\n3 9\n3 6\n10 5\n5 5\n6 10\n10 3\n6 7\n2 3\n9 8", "output": "238" }, { "input": "1 1 1\n1 1", "output": "0" }, { "input": "1 100 10\n8 27", "output": "54" }, { "input": "2 1000000000 1000000\n1000000 5\n999998 7", "output": "10" }, { "input": "10 10 6\n1 10\n2 9\n3 8\n4 7\n5 6\n6 5\n7 4\n8 3\n9 2\n10 1", "output": "16" }, { "input": "1 2 1\n2 2", "output": "0" }, { "input": "9 846678 205000\n102282 593538\n246630 24854\n545346 409737\n334264 443193\n37717 191227\n154582 913095\n97105 345066\n65504 578960\n163348 394257", "output": "2441209588" }, { "input": "2 100000 100000\n1 1000000\n1 1000000", "output": "199998000000" }, { "input": "2 1000000 1000000\n1 1000000\n1 1000000", "output": "1999998000000" } ]
1,695,171,702
2,147,483,647
PyPy 3-64
COMPILATION_ERROR
TESTS
0
0
0
#include<bits/stdc++.h> using namespace std; #define int long long int #define mod 1000000007 #define fastIO ios_base::sync_with_stdio(false);cin.tie(NULL); #define accDeci cout<<fixed;cout<<setprecision(10); bool comp(pair<int,int> data1, pair<int,int> data2) { if(data1.second!=data2.second) return(data1.second<=data2.second); else return(data1.first<data2.first); } int32_t main() { fastIO;accDeci; int n,r,avg,sum=0,essay=0;cin>>n>>r>>avg;vector<pair<int,int>> data(n); for(int i=0;i<n;i++) cin>>data[i].first>>data[i].second,sum+=data[i].first; sort(data.begin(),data.end(),comp); int idx=0; while(sum<(n*avg)) { if(data[idx].first<=r) { int k=min(n*avg-sum,(r-data[idx].first)); essay+=(k*data[idx].second); data[idx].first+=k; sum+=k; } idx++; } cout<<essay; return 0; }
Title: Vanya and Exams Time Limit: None seconds Memory Limit: None megabytes Problem Description: Vanya wants to pass *n* exams and get the academic scholarship. He will get the scholarship if the average grade mark for all the exams is at least *avg*. The exam grade cannot exceed *r*. Vanya has passed the exams and got grade *a**i* for the *i*-th exam. To increase the grade for the *i*-th exam by 1 point, Vanya must write *b**i* essays. He can raise the exam grade multiple times. What is the minimum number of essays that Vanya needs to write to get scholarship? Input Specification: The first line contains three integers *n*, *r*, *avg* (1<=≤<=*n*<=≤<=105, 1<=≤<=*r*<=≤<=109, 1<=≤<=*avg*<=≤<=*min*(*r*,<=106)) — the number of exams, the maximum grade and the required grade point average, respectively. Each of the following *n* lines contains space-separated integers *a**i* and *b**i* (1<=≤<=*a**i*<=≤<=*r*, 1<=≤<=*b**i*<=≤<=106). Output Specification: In the first line print the minimum number of essays. Demo Input: ['5 5 4\n5 2\n4 7\n3 1\n3 2\n2 5\n', '2 5 4\n5 2\n5 2\n'] Demo Output: ['4\n', '0\n'] Note: In the first sample Vanya can write 2 essays for the 3rd exam to raise his grade by 2 points and 2 essays for the 4th exam to raise his grade by 1 point. In the second sample, Vanya doesn't need to write any essays as his general point average already is above average.
```python #include<bits/stdc++.h> using namespace std; #define int long long int #define mod 1000000007 #define fastIO ios_base::sync_with_stdio(false);cin.tie(NULL); #define accDeci cout<<fixed;cout<<setprecision(10); bool comp(pair<int,int> data1, pair<int,int> data2) { if(data1.second!=data2.second) return(data1.second<=data2.second); else return(data1.first<data2.first); } int32_t main() { fastIO;accDeci; int n,r,avg,sum=0,essay=0;cin>>n>>r>>avg;vector<pair<int,int>> data(n); for(int i=0;i<n;i++) cin>>data[i].first>>data[i].second,sum+=data[i].first; sort(data.begin(),data.end(),comp); int idx=0; while(sum<(n*avg)) { if(data[idx].first<=r) { int k=min(n*avg-sum,(r-data[idx].first)); essay+=(k*data[idx].second); data[idx].first+=k; sum+=k; } idx++; } cout<<essay; return 0; } ```
-1
607
A
Chain Reaction
PROGRAMMING
1,600
[ "binary search", "dp" ]
null
null
There are *n* beacons located at distinct positions on a number line. The *i*-th beacon has position *a**i* and power level *b**i*. When the *i*-th beacon is activated, it destroys all beacons to its left (direction of decreasing coordinates) within distance *b**i* inclusive. The beacon itself is not destroyed however. Saitama will activate the beacons one at a time from right to left. If a beacon is destroyed, it cannot be activated. Saitama wants Genos to add a beacon strictly to the right of all the existing beacons, with any position and any power level, such that the least possible number of beacons are destroyed. Note that Genos's placement of the beacon means it will be the first beacon activated. Help Genos by finding the minimum number of beacons that could be destroyed.
The first line of input contains a single integer *n* (1<=≤<=*n*<=≤<=100<=000) — the initial number of beacons. The *i*-th of next *n* lines contains two integers *a**i* and *b**i* (0<=≤<=*a**i*<=≤<=1<=000<=000, 1<=≤<=*b**i*<=≤<=1<=000<=000) — the position and power level of the *i*-th beacon respectively. No two beacons will have the same position, so *a**i*<=≠<=*a**j* if *i*<=≠<=*j*.
Print a single integer — the minimum number of beacons that could be destroyed if exactly one beacon is added.
[ "4\n1 9\n3 1\n6 1\n7 4\n", "7\n1 1\n2 1\n3 1\n4 1\n5 1\n6 1\n7 1\n" ]
[ "1\n", "3\n" ]
For the first sample case, the minimum number of beacons destroyed is 1. One way to achieve this is to place a beacon at position 9 with power level 2. For the second sample case, the minimum number of beacons destroyed is 3. One way to achieve this is to place a beacon at position 1337 with power level 42.
500
[ { "input": "4\n1 9\n3 1\n6 1\n7 4", "output": "1" }, { "input": "7\n1 1\n2 1\n3 1\n4 1\n5 1\n6 1\n7 1", "output": "3" }, { "input": "1\n0 1", "output": "0" }, { "input": "1\n0 1000000", "output": "0" }, { "input": "1\n1000000 1000000", "output": "0" }, { "input": "7\n1 1\n2 1\n3 1\n4 1\n5 1\n6 6\n7 7", "output": "4" }, { "input": "5\n1 1\n3 1\n5 1\n7 10\n8 10", "output": "2" }, { "input": "11\n110 90\n100 70\n90 10\n80 10\n70 1\n60 1\n50 10\n40 1\n30 1\n10 1\n20 1", "output": "4" } ]
1,551,682,572
2,147,483,647
Python 3
RUNTIME_ERROR
TESTS
0
93
0
import numpy as np count = int(input()) array = np.zeros(10**6, dtype=np.int32) maxy = 0 for i in range(count): a, b = input().split() array[int(a)+1] = int(b) maxy = max(maxy, int(a)) maxy = maxy + 2 activation_list = [0] preceding_list = [0] # activation_list.append(int(array[0] != 0)) # preceding_list.append(int(array[0] != 0)) for i in range(1, maxy): if array[i] != 0: activation_list.append(activation_list[max(i-array[i]-1, 0)] +1) preceding_list.append(preceding_list[i-1] + 1) else: activation_list.append(activation_list[i-1]) preceding_list.append(preceding_list[i-1]) #print(list(array[:maxy])) #print(activation_list) #print(preceding_list) destroy_list = np.array(preceding_list) - np.array(activation_list) #print(list(destroy_list)) succeeding_list = preceding_list[-1] - np.array(preceding_list) #print(list(succeeding_list)) result = np.array(destroy_list) + succeeding_list #print(list(result)) print(min(result))
Title: Chain Reaction Time Limit: None seconds Memory Limit: None megabytes Problem Description: There are *n* beacons located at distinct positions on a number line. The *i*-th beacon has position *a**i* and power level *b**i*. When the *i*-th beacon is activated, it destroys all beacons to its left (direction of decreasing coordinates) within distance *b**i* inclusive. The beacon itself is not destroyed however. Saitama will activate the beacons one at a time from right to left. If a beacon is destroyed, it cannot be activated. Saitama wants Genos to add a beacon strictly to the right of all the existing beacons, with any position and any power level, such that the least possible number of beacons are destroyed. Note that Genos's placement of the beacon means it will be the first beacon activated. Help Genos by finding the minimum number of beacons that could be destroyed. Input Specification: The first line of input contains a single integer *n* (1<=≤<=*n*<=≤<=100<=000) — the initial number of beacons. The *i*-th of next *n* lines contains two integers *a**i* and *b**i* (0<=≤<=*a**i*<=≤<=1<=000<=000, 1<=≤<=*b**i*<=≤<=1<=000<=000) — the position and power level of the *i*-th beacon respectively. No two beacons will have the same position, so *a**i*<=≠<=*a**j* if *i*<=≠<=*j*. Output Specification: Print a single integer — the minimum number of beacons that could be destroyed if exactly one beacon is added. Demo Input: ['4\n1 9\n3 1\n6 1\n7 4\n', '7\n1 1\n2 1\n3 1\n4 1\n5 1\n6 1\n7 1\n'] Demo Output: ['1\n', '3\n'] Note: For the first sample case, the minimum number of beacons destroyed is 1. One way to achieve this is to place a beacon at position 9 with power level 2. For the second sample case, the minimum number of beacons destroyed is 3. One way to achieve this is to place a beacon at position 1337 with power level 42.
```python import numpy as np count = int(input()) array = np.zeros(10**6, dtype=np.int32) maxy = 0 for i in range(count): a, b = input().split() array[int(a)+1] = int(b) maxy = max(maxy, int(a)) maxy = maxy + 2 activation_list = [0] preceding_list = [0] # activation_list.append(int(array[0] != 0)) # preceding_list.append(int(array[0] != 0)) for i in range(1, maxy): if array[i] != 0: activation_list.append(activation_list[max(i-array[i]-1, 0)] +1) preceding_list.append(preceding_list[i-1] + 1) else: activation_list.append(activation_list[i-1]) preceding_list.append(preceding_list[i-1]) #print(list(array[:maxy])) #print(activation_list) #print(preceding_list) destroy_list = np.array(preceding_list) - np.array(activation_list) #print(list(destroy_list)) succeeding_list = preceding_list[-1] - np.array(preceding_list) #print(list(succeeding_list)) result = np.array(destroy_list) + succeeding_list #print(list(result)) print(min(result)) ```
-1
27
A
Next Test
PROGRAMMING
1,200
[ "implementation", "sortings" ]
A. Next Test
2
256
«Polygon» is a system which allows to create programming tasks in a simple and professional way. When you add a test to the problem, the corresponding form asks you for the test index. As in most cases it is clear which index the next test will have, the system suggests the default value of the index. It is calculated as the smallest positive integer which is not used as an index for some previously added test. You are to implement this feature. Create a program which determines the default index of the next test, given the indexes of the previously added tests.
The first line contains one integer *n* (1<=≤<=*n*<=≤<=3000) — the amount of previously added tests. The second line contains *n* distinct integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=3000) — indexes of these tests.
Output the required default value for the next test index.
[ "3\n1 7 2\n" ]
[ "3\n" ]
none
500
[ { "input": "1\n1", "output": "2" }, { "input": "2\n2 1", "output": "3" }, { "input": "3\n3 4 1", "output": "2" }, { "input": "4\n6 4 3 5", "output": "1" }, { "input": "5\n3 2 1 7 4", "output": "5" }, { "input": "6\n4 1 2 5 3 7", "output": "6" }, { "input": "7\n3 2 1 6 5 7 4", "output": "8" }, { "input": "8\n2 8 3 7 6 9 1 5", "output": "4" }, { "input": "9\n10 5 9 3 8 7 1 2 4", "output": "6" }, { "input": "10\n7 2 3 8 9 6 5 4 1 10", "output": "11" }, { "input": "1\n1", "output": "2" }, { "input": "2\n1 2", "output": "3" }, { "input": "3\n2 4 1", "output": "3" }, { "input": "4\n4 2 3 1", "output": "5" }, { "input": "5\n3 1 4 2 5", "output": "6" }, { "input": "6\n1 3 6 7 2 4", "output": "5" }, { "input": "7\n1 5 4 7 2 3 6", "output": "8" }, { "input": "8\n12 1 6 5 2 8 3 4", "output": "7" }, { "input": "9\n3 2 7 5 6 4 1 9 10", "output": "8" }, { "input": "10\n1 7 13 6 5 10 3 8 2 4", "output": "9" }, { "input": "1\n2", "output": "1" }, { "input": "1\n3", "output": "1" }, { "input": "1\n3000", "output": "1" }, { "input": "2\n2 3", "output": "1" }, { "input": "2\n3000 1", "output": "2" } ]
1,690,645,005
2,147,483,647
Python 3
OK
TESTS
30
186
204,800
n = int(input()) i = 1 x = sorted(list(map(int, input().split()))) while i in x: i+=1 print(i)
Title: Next Test Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: «Polygon» is a system which allows to create programming tasks in a simple and professional way. When you add a test to the problem, the corresponding form asks you for the test index. As in most cases it is clear which index the next test will have, the system suggests the default value of the index. It is calculated as the smallest positive integer which is not used as an index for some previously added test. You are to implement this feature. Create a program which determines the default index of the next test, given the indexes of the previously added tests. Input Specification: The first line contains one integer *n* (1<=≤<=*n*<=≤<=3000) — the amount of previously added tests. The second line contains *n* distinct integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=3000) — indexes of these tests. Output Specification: Output the required default value for the next test index. Demo Input: ['3\n1 7 2\n'] Demo Output: ['3\n'] Note: none
```python n = int(input()) i = 1 x = sorted(list(map(int, input().split()))) while i in x: i+=1 print(i) ```
3.953119
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,639,557,697
2,147,483,647
PyPy 3-64
OK
TESTS
102
109
0
first = input() second = input() answer = '' i = 0 while i < len(first): if first[i] == second[i]: answer += str('0') else: answer += str('1') i += 1 print(answer)
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 first = input() second = input() answer = '' i = 0 while i < len(first): if first[i] == second[i]: answer += str('0') else: answer += str('1') i += 1 print(answer) ```
3.97275
69
B
Bets
PROGRAMMING
1,200
[ "greedy", "implementation" ]
B. Bets
2
256
In Chelyabinsk lives a much respected businessman Nikita with a strange nickname "Boss". Once Nikita decided to go with his friend Alex to the Summer Biathlon World Cup. Nikita, as a very important person, received a token which allows to place bets on each section no more than on one competitor. To begin with friends learned the rules: in the race there are *n* sections of equal length and *m* participants. The participants numbered from 1 to *m*. About each participant the following is known: - *l**i* — the number of the starting section, - *r**i* — the number of the finishing section (*l**i*<=≤<=*r**i*),- *t**i* — the time a biathlete needs to complete an section of the path,- *c**i* — the profit in roubles. If the *i*-th sportsman wins on one of the sections, the profit will be given to the man who had placed a bet on that sportsman. The *i*-th biathlete passes the sections from *l**i* to *r**i* inclusive. The competitor runs the whole way in (*r**i*<=-<=*l**i*<=+<=1)·*t**i* time units. It takes him exactly *t**i* time units to pass each section. In case of the athlete's victory on *k* sections the man who has betted on him receives *k*·*c**i* roubles. In each section the winner is determined independently as follows: if there is at least one biathlete running this in this section, then among all of them the winner is the one who has ran this section in minimum time (spent minimum time passing this section). In case of equality of times the athlete with the smaller index number wins. If there are no participants in this section, then the winner in this section in not determined. We have to say that in the summer biathlon all the participants are moving at a constant speed. We should also add that Nikita can bet on each section and on any contestant running in this section. Help the friends find the maximum possible profit.
The first line contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=100). Then follow *m* lines, each containing 4 integers *l**i*, *r**i*, *t**i*, *c**i* (1<=≤<=*l**i*<=≤<=*r**i*<=≤<=*n*, 1<=≤<=*t**i*,<=*c**i*<=≤<=1000).
Print a single integer, the maximal profit in roubles that the friends can get. In each of *n* sections it is not allowed to place bets on more than one sportsman.
[ "4 4\n1 4 20 5\n1 3 21 10\n3 3 4 30\n3 4 4 20\n", "8 4\n1 5 24 10\n2 4 6 15\n4 6 30 50\n6 7 4 20\n" ]
[ "60", "105" ]
In the first test the optimal bet is: in the 1-2 sections on biathlete 1, in section 3 on biathlete 3, in section 4 on biathlete 4. Total: profit of 5 rubles for 1 section, the profit of 5 rubles for 2 section, profit of 30 rubles for a 3 section, profit of 20 rubles for 4 section. Total profit 60 rubles. In the second test the optimal bet is: on 1 and 5 sections on biathlete 1, in the 2-4 sections on biathlete 2, in the 6-7 sections on athlete 4. There is no winner in the 8 section. Total: profit of 10 rubles for 1 section, the profit of 15 rubles for 2,3,4 section, profit of 10 rubles for a 5 section, profit of 20 rubles for 6, 7 section. Total profit 105 rubles.
1,000
[ { "input": "4 4\n1 4 20 5\n1 3 21 10\n3 3 4 30\n3 4 4 20", "output": "60" }, { "input": "8 4\n1 5 24 10\n2 4 6 15\n4 6 30 50\n6 7 4 20", "output": "105" }, { "input": "2 2\n1 2 3 1\n2 2 3 10", "output": "2" }, { "input": "20 30\n15 17 54 46\n4 18 26 18\n18 20 49 94\n12 12 83 12\n11 13 88 47\n8 8 8 12\n18 18 94 2\n14 17 88 96\n19 19 62 97\n1 12 81 67\n10 12 78 26\n19 20 63 93\n9 20 38 32\n7 9 90 17\n9 10 19 60\n16 16 47 29\n1 6 62 29\n12 18 74 89\n5 5 97 92\n5 17 16 25\n11 19 2 76\n3 15 61 29\n5 7 73 54\n19 20 91 91\n4 17 28 61\n9 13 56 81\n10 11 82 80\n10 11 82 70\n5 10 66 38\n10 19 22 61", "output": "958" }, { "input": "20 30\n4 13 78 11\n13 19 56 41\n15 15 46 83\n4 9 74 72\n17 20 97 7\n15 20 29 48\n8 17 44 85\n4 18 26 46\n16 17 9 90\n16 16 39 89\n13 14 46 63\n14 18 67 18\n12 20 84 48\n10 20 49 32\n10 14 14 11\n6 18 80 84\n3 20 13 97\n12 20 62 42\n12 14 64 71\n5 19 38 17\n17 18 99 18\n11 15 83 22\n4 11 65 99\n8 16 89 45\n11 20 15 39\n8 13 85 26\n5 19 84 3\n10 16 26 45\n13 16 81 37\n3 5 100 42", "output": "1732" }, { "input": "20 30\n4 12 30 83\n3 3 91 46\n5 11 82 84\n20 20 29 36\n3 13 89 29\n11 14 40 80\n9 20 90 21\n14 19 23 74\n8 9 13 88\n12 18 13 95\n13 18 48 29\n8 17 13 15\n7 15 18 51\n9 20 87 51\n12 20 40 32\n4 11 34 11\n3 19 22 20\n19 19 53 5\n16 18 52 30\n5 19 52 71\n19 19 99 95\n14 18 15 28\n20 20 91 64\n15 16 55 47\n1 9 40 40\n9 17 93 82\n7 16 10 75\n1 15 100 24\n10 10 35 84\n1 2 4 7", "output": "1090" }, { "input": "20 30\n20 20 43 41\n5 13 99 35\n9 15 79 12\n4 20 75 16\n20 20 4 94\n14 14 1 1\n5 5 4 92\n14 19 52 30\n19 20 61 14\n10 12 34 89\n11 15 27 12\n14 18 64 25\n11 14 37 14\n19 19 56 20\n19 20 61 11\n13 16 48 36\n14 16 82 73\n16 17 82 26\n1 5 55 91\n10 13 24 33\n3 19 91 70\n10 15 87 53\n3 5 92 80\n10 10 13 24\n9 9 38 20\n13 20 80 38\n5 10 71 23\n6 19 43 90\n13 20 10 55\n11 14 29 62", "output": "1261" }, { "input": "20 30\n15 15 14 51\n17 20 3 20\n14 16 59 66\n14 15 48 22\n18 19 72 26\n13 14 60 72\n8 13 69 57\n4 12 3 82\n1 8 80 37\n18 19 40 33\n9 9 32 55\n13 15 67 5\n10 13 37 1\n19 19 39 11\n17 19 28 88\n8 19 88 87\n16 20 26 2\n18 18 11 46\n14 14 14 20\n15 15 78 100\n18 19 53 32\n12 13 59 66\n11 18 38 36\n5 8 14 97\n8 18 80 97\n6 19 81 17\n13 19 65 93\n8 10 77 3\n20 20 70 60\n17 17 28 35", "output": "1003" }, { "input": "20 30\n5 10 38 50\n17 18 86 42\n4 13 91 90\n20 20 45 31\n3 3 16 11\n16 16 80 66\n19 19 96 26\n15 20 7 84\n9 18 45 36\n5 19 89 6\n9 9 4 58\n9 14 97 31\n6 12 74 90\n4 5 84 2\n12 19 92 48\n16 16 92 55\n9 15 88 38\n6 14 8 66\n14 17 71 91\n20 20 58 20\n8 18 5 47\n7 19 67 43\n19 19 88 80\n9 12 35 86\n4 4 82 22\n7 8 72 82\n8 10 61 92\n20 20 77 93\n15 19 66 20\n20 20 8 10", "output": "911" }, { "input": "20 30\n1 20 49 91\n15 15 60 37\n14 14 3 79\n11 12 81 66\n8 12 71 31\n3 13 8 14\n2 10 11 35\n19 20 40 28\n12 14 6 75\n16 18 100 100\n20 20 89 74\n16 16 27 98\n18 18 21 24\n1 18 69 98\n7 13 70 57\n9 20 41 79\n17 17 75 75\n11 16 19 14\n1 15 62 59\n12 15 33 91\n3 17 10 79\n15 16 100 80\n10 16 5 5\n9 19 53 100\n9 18 65 42\n5 13 34 13\n6 13 61 47\n17 19 68 25\n5 5 42 59\n6 8 48 92", "output": "492" }, { "input": "100 1\n22 59 287 173", "output": "6574" }, { "input": "100 1\n8 31 93 267", "output": "6408" }, { "input": "100 1\n72 82 727 390", "output": "4290" }, { "input": "100 1\n14 25 343 50", "output": "600" }, { "input": "100 1\n73 75 59 176", "output": "528" }, { "input": "21 2\n19 20 253 233\n3 17 23 150", "output": "2716" }, { "input": "47 18\n14 38 376 96\n21 34 749 32\n7 20 409 146\n41 41 740 9\n14 16 526 128\n38 47 518 147\n3 26 7 16\n25 31 155 75\n32 36 164 12\n5 33 436 150\n22 41 477 52\n4 13 166 6\n38 44 664 133\n2 33 452 16\n30 40 623 48\n37 37 250 122\n25 34 506 109\n36 38 716 78", "output": "2091" }, { "input": "1 1\n1 1 1 1", "output": "1" }, { "input": "1 1\n1 1 1000 1000", "output": "1000" } ]
1,694,969,585
2,147,483,647
PyPy 3
OK
TESTS
67
186
2,560,000
n, m = map(int, input().split(' ')) M = [(10**9, 0)] * (n + 1) for _ in range(m): l, r, t, c = map(int, input().split(' ')) for i in range(l, r + 1): if M[i][0] > t: M[i] = (t, c) print(sum(c for _, c in M))
Title: Bets Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: In Chelyabinsk lives a much respected businessman Nikita with a strange nickname "Boss". Once Nikita decided to go with his friend Alex to the Summer Biathlon World Cup. Nikita, as a very important person, received a token which allows to place bets on each section no more than on one competitor. To begin with friends learned the rules: in the race there are *n* sections of equal length and *m* participants. The participants numbered from 1 to *m*. About each participant the following is known: - *l**i* — the number of the starting section, - *r**i* — the number of the finishing section (*l**i*<=≤<=*r**i*),- *t**i* — the time a biathlete needs to complete an section of the path,- *c**i* — the profit in roubles. If the *i*-th sportsman wins on one of the sections, the profit will be given to the man who had placed a bet on that sportsman. The *i*-th biathlete passes the sections from *l**i* to *r**i* inclusive. The competitor runs the whole way in (*r**i*<=-<=*l**i*<=+<=1)·*t**i* time units. It takes him exactly *t**i* time units to pass each section. In case of the athlete's victory on *k* sections the man who has betted on him receives *k*·*c**i* roubles. In each section the winner is determined independently as follows: if there is at least one biathlete running this in this section, then among all of them the winner is the one who has ran this section in minimum time (spent minimum time passing this section). In case of equality of times the athlete with the smaller index number wins. If there are no participants in this section, then the winner in this section in not determined. We have to say that in the summer biathlon all the participants are moving at a constant speed. We should also add that Nikita can bet on each section and on any contestant running in this section. Help the friends find the maximum possible profit. Input Specification: The first line contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=100). Then follow *m* lines, each containing 4 integers *l**i*, *r**i*, *t**i*, *c**i* (1<=≤<=*l**i*<=≤<=*r**i*<=≤<=*n*, 1<=≤<=*t**i*,<=*c**i*<=≤<=1000). Output Specification: Print a single integer, the maximal profit in roubles that the friends can get. In each of *n* sections it is not allowed to place bets on more than one sportsman. Demo Input: ['4 4\n1 4 20 5\n1 3 21 10\n3 3 4 30\n3 4 4 20\n', '8 4\n1 5 24 10\n2 4 6 15\n4 6 30 50\n6 7 4 20\n'] Demo Output: ['60', '105'] Note: In the first test the optimal bet is: in the 1-2 sections on biathlete 1, in section 3 on biathlete 3, in section 4 on biathlete 4. Total: profit of 5 rubles for 1 section, the profit of 5 rubles for 2 section, profit of 30 rubles for a 3 section, profit of 20 rubles for 4 section. Total profit 60 rubles. In the second test the optimal bet is: on 1 and 5 sections on biathlete 1, in the 2-4 sections on biathlete 2, in the 6-7 sections on athlete 4. There is no winner in the 8 section. Total: profit of 10 rubles for 1 section, the profit of 15 rubles for 2,3,4 section, profit of 10 rubles for a 5 section, profit of 20 rubles for 6, 7 section. Total profit 105 rubles.
```python n, m = map(int, input().split(' ')) M = [(10**9, 0)] * (n + 1) for _ in range(m): l, r, t, c = map(int, input().split(' ')) for i in range(l, r + 1): if M[i][0] > t: M[i] = (t, c) print(sum(c for _, c in M)) ```
3.948732
265
A
Colorful Stones (Simplified Edition)
PROGRAMMING
800
[ "implementation" ]
null
null
There is a sequence of colorful stones. The color of each stone is one of red, green, or blue. You are given a string *s*. The *i*-th (1-based) character of *s* represents the color of the *i*-th stone. If the character is "R", "G", or "B", the color of the corresponding stone is red, green, or blue, respectively. Initially Squirrel Liss is standing on the first stone. You perform instructions one or more times. Each instruction is one of the three types: "RED", "GREEN", or "BLUE". After an instruction *c*, if Liss is standing on a stone whose colors is *c*, Liss will move one stone forward, else she will not move. You are given a string *t*. The number of instructions is equal to the length of *t*, and the *i*-th character of *t* represents the *i*-th instruction. Calculate the final position of Liss (the number of the stone she is going to stand on in the end) after performing all the instructions, and print its 1-based position. It is guaranteed that Liss don't move out of the sequence.
The input contains two lines. The first line contains the string *s* (1<=≤<=|*s*|<=≤<=50). The second line contains the string *t* (1<=≤<=|*t*|<=≤<=50). The characters of each string will be one of "R", "G", or "B". It is guaranteed that Liss don't move out of the sequence.
Print the final 1-based position of Liss in a single line.
[ "RGB\nRRR\n", "RRRBGBRBBB\nBBBRR\n", "BRRBGBRGRBGRGRRGGBGBGBRGBRGRGGGRBRRRBRBBBGRRRGGBBB\nBBRBGGRGRGBBBRBGRBRBBBBRBRRRBGBBGBBRRBBGGRBRRBRGRB\n" ]
[ "2\n", "3\n", "15\n" ]
none
500
[ { "input": "RGB\nRRR", "output": "2" }, { "input": "RRRBGBRBBB\nBBBRR", "output": "3" }, { "input": "BRRBGBRGRBGRGRRGGBGBGBRGBRGRGGGRBRRRBRBBBGRRRGGBBB\nBBRBGGRGRGBBBRBGRBRBBBBRBRRRBGBBGBBRRBBGGRBRRBRGRB", "output": "15" }, { "input": "G\nRRBBRBRRBR", "output": "1" }, { "input": "RRRRRBRRBRRGRBGGRRRGRBBRBBBBBRGRBGBRRGBBBRBBGBRGBB\nB", "output": "1" }, { "input": "RRGGBRGRBG\nBRRGGBBGGR", "output": "7" }, { "input": "BBRRGBGGRGBRGBRBRBGR\nGGGRBGGGBRRRRGRBGBGRGRRBGRBGBG", "output": "15" }, { "input": "GBRRBGBGBBBBRRRGBGRRRGBGBBBRGR\nRRGBRRGRBBBBBBGRRBBR", "output": "8" }, { "input": "BRGRRGRGRRGBBGBBBRRBBRRBGBBGRGBBGGRGBRBGGGRRRBGGBB\nRGBBGRRBBBRRGRRBRBBRGBBGGGRGBGRRRRBRBGGBRBGGGRGBRR", "output": "16" }, { "input": "GGRGGBRRGRGBRRGGRBBGGRRGBBBGBBBGGRBGGBRBBRGBRRRBRG\nGGRGRRRRRRRRRGBBBBRGBRGRGRRGBBRGGBRBBRBGBRGRRRRGGR", "output": "18" }, { "input": "RBBRBGBBGGGBRRBGBRGRRGGRBBBBGRBGGBRRBGBBRBRGBBGGGG\nBRRGRBGRBGBRGBRBGGBBBGBBRGRBGRGRBGRBGGRRBGBRGRRBBG", "output": "23" }, { "input": "RRGGRRBRGRGBRGBRGBBRGGGBRBGBRGBRGGBRBRGBGRRBBGGRBR\nBRGRBBBGRBGRRGGRRRRRRRRGGGGGGGGBGGGGGGGRGRBBRGRGBR", "output": "14" }, { "input": "RBRBRRRRRGGR\nBBBBRRGGBGRBRGBBRGGGRGGBRRBRBRBGGG", "output": "12" }, { "input": "GGRGGGBRGRGRBBRGGGRBGRRR\nGBBBBGBGBGBBBRGGRGGBGRRGRRRGBGB", "output": "12" }, { "input": "RGRBGBRBBGBRRGGGBBGBRRBGRGBBBBBGRRRGGRBB\nBGR", "output": "2" }, { "input": "R\nB", "output": "1" }, { "input": "RRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRR\nRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRR", "output": "50" }, { "input": "RRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRR\nGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGG", "output": "1" }, { "input": "R\nGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGG", "output": "1" } ]
1,593,060,305
2,147,483,647
Python 3
OK
TESTS
19
218
6,656,000
s = input() t = input() pos = 0 for x in t : if s[pos] == x : pos += 1 print (pos + 1)
Title: Colorful Stones (Simplified Edition) Time Limit: None seconds Memory Limit: None megabytes Problem Description: There is a sequence of colorful stones. The color of each stone is one of red, green, or blue. You are given a string *s*. The *i*-th (1-based) character of *s* represents the color of the *i*-th stone. If the character is "R", "G", or "B", the color of the corresponding stone is red, green, or blue, respectively. Initially Squirrel Liss is standing on the first stone. You perform instructions one or more times. Each instruction is one of the three types: "RED", "GREEN", or "BLUE". After an instruction *c*, if Liss is standing on a stone whose colors is *c*, Liss will move one stone forward, else she will not move. You are given a string *t*. The number of instructions is equal to the length of *t*, and the *i*-th character of *t* represents the *i*-th instruction. Calculate the final position of Liss (the number of the stone she is going to stand on in the end) after performing all the instructions, and print its 1-based position. It is guaranteed that Liss don't move out of the sequence. Input Specification: The input contains two lines. The first line contains the string *s* (1<=≤<=|*s*|<=≤<=50). The second line contains the string *t* (1<=≤<=|*t*|<=≤<=50). The characters of each string will be one of "R", "G", or "B". It is guaranteed that Liss don't move out of the sequence. Output Specification: Print the final 1-based position of Liss in a single line. Demo Input: ['RGB\nRRR\n', 'RRRBGBRBBB\nBBBRR\n', 'BRRBGBRGRBGRGRRGGBGBGBRGBRGRGGGRBRRRBRBBBGRRRGGBBB\nBBRBGGRGRGBBBRBGRBRBBBBRBRRRBGBBGBBRRBBGGRBRRBRGRB\n'] Demo Output: ['2\n', '3\n', '15\n'] Note: none
```python s = input() t = input() pos = 0 for x in t : if s[pos] == x : pos += 1 print (pos + 1) ```
3
25
A
IQ test
PROGRAMMING
1,300
[ "brute force" ]
A. IQ test
2
256
Bob is preparing to pass IQ test. The most frequent task in this test is to find out which one of the given *n* numbers differs from the others. Bob observed that one number usually differs from the others in evenness. Help Bob — to check his answers, he needs a program that among the given *n* numbers finds one that is different in evenness.
The first line contains integer *n* (3<=≤<=*n*<=≤<=100) — amount of numbers in the task. The second line contains *n* space-separated natural numbers, not exceeding 100. It is guaranteed, that exactly one of these numbers differs from the others in evenness.
Output index of number that differs from the others in evenness. Numbers are numbered from 1 in the input order.
[ "5\n2 4 7 8 10\n", "4\n1 2 1 1\n" ]
[ "3\n", "2\n" ]
none
0
[ { "input": "5\n2 4 7 8 10", "output": "3" }, { "input": "4\n1 2 1 1", "output": "2" }, { "input": "3\n1 2 2", "output": "1" }, { "input": "3\n100 99 100", "output": "2" }, { "input": "3\n5 3 2", "output": "3" }, { "input": "4\n43 28 1 91", "output": "2" }, { "input": "4\n75 13 94 77", "output": "3" }, { "input": "4\n97 8 27 3", "output": "2" }, { "input": "10\n95 51 12 91 85 3 1 31 25 7", "output": "3" }, { "input": "20\n88 96 66 51 14 88 2 92 18 72 18 88 20 30 4 82 90 100 24 46", "output": "4" }, { "input": "30\n20 94 56 50 10 98 52 32 14 22 24 60 4 8 98 46 34 68 82 82 98 90 50 20 78 49 52 94 64 36", "output": "26" }, { "input": "50\n79 27 77 57 37 45 27 49 65 33 57 21 71 19 75 85 65 61 23 97 85 9 23 1 9 3 99 77 77 21 79 69 15 37 15 7 93 81 13 89 91 31 45 93 15 97 55 80 85 83", "output": "48" }, { "input": "60\n46 11 73 65 3 69 3 53 43 53 97 47 55 93 31 75 35 3 9 73 23 31 3 81 91 79 61 21 15 11 11 11 81 7 83 75 39 87 83 59 89 55 93 27 49 67 67 29 1 93 11 17 9 19 35 21 63 31 31 25", "output": "1" }, { "input": "70\n28 42 42 92 64 54 22 38 38 78 62 38 4 38 14 66 4 92 66 58 94 26 4 44 41 88 48 82 44 26 74 44 48 4 16 92 34 38 26 64 94 4 30 78 50 54 12 90 8 16 80 98 28 100 74 50 36 42 92 18 76 98 8 22 2 50 58 50 64 46", "output": "25" }, { "input": "100\n43 35 79 53 13 91 91 45 65 83 57 9 42 39 85 45 71 51 61 59 31 13 63 39 25 21 79 39 91 67 21 61 97 75 93 83 29 79 59 97 11 37 63 51 39 55 91 23 21 17 47 23 35 75 49 5 69 99 5 7 41 17 25 89 15 79 21 63 53 81 43 91 59 91 69 99 85 15 91 51 49 37 65 7 89 81 21 93 61 63 97 93 45 17 13 69 57 25 75 73", "output": "13" }, { "input": "100\n50 24 68 60 70 30 52 22 18 74 68 98 20 82 4 46 26 68 100 78 84 58 74 98 38 88 68 86 64 80 82 100 20 22 98 98 52 6 94 10 48 68 2 18 38 22 22 82 44 20 66 72 36 58 64 6 36 60 4 96 76 64 12 90 10 58 64 60 74 28 90 26 24 60 40 58 2 16 76 48 58 36 82 60 24 44 4 78 28 38 8 12 40 16 38 6 66 24 31 76", "output": "99" }, { "input": "100\n47 48 94 48 14 18 94 36 96 22 12 30 94 20 48 98 40 58 2 94 8 36 98 18 98 68 2 60 76 38 18 100 8 72 100 68 2 86 92 72 58 16 48 14 6 58 72 76 6 88 80 66 20 28 74 62 86 68 90 86 2 56 34 38 56 90 4 8 76 44 32 86 12 98 38 34 54 92 70 94 10 24 82 66 90 58 62 2 32 58 100 22 58 72 2 22 68 72 42 14", "output": "1" }, { "input": "99\n38 20 68 60 84 16 28 88 60 48 80 28 4 92 70 60 46 46 20 34 12 100 76 2 40 10 8 86 6 80 50 66 12 34 14 28 26 70 46 64 34 96 10 90 98 96 56 88 50 74 70 94 2 94 24 66 68 46 22 30 6 10 64 32 88 14 98 100 64 58 50 18 50 50 8 38 8 16 54 2 60 54 62 84 92 98 4 72 66 26 14 88 99 16 10 6 88 56 22", "output": "93" }, { "input": "99\n50 83 43 89 53 47 69 1 5 37 63 87 95 15 55 95 75 89 33 53 89 75 93 75 11 85 49 29 11 97 49 67 87 11 25 37 97 73 67 49 87 43 53 97 43 29 53 33 45 91 37 73 39 49 59 5 21 43 87 35 5 63 89 57 63 47 29 99 19 85 13 13 3 13 43 19 5 9 61 51 51 57 15 89 13 97 41 13 99 79 13 27 97 95 73 33 99 27 23", "output": "1" }, { "input": "98\n61 56 44 30 58 14 20 24 88 28 46 56 96 52 58 42 94 50 46 30 46 80 72 88 68 16 6 60 26 90 10 98 76 20 56 40 30 16 96 20 88 32 62 30 74 58 36 76 60 4 24 36 42 54 24 92 28 14 2 74 86 90 14 52 34 82 40 76 8 64 2 56 10 8 78 16 70 86 70 42 70 74 22 18 76 98 88 28 62 70 36 72 20 68 34 48 80 98", "output": "1" }, { "input": "98\n66 26 46 42 78 32 76 42 26 82 8 12 4 10 24 26 64 44 100 46 94 64 30 18 88 28 8 66 30 82 82 28 74 52 62 80 80 60 94 86 64 32 44 88 92 20 12 74 94 28 34 58 4 22 16 10 94 76 82 58 40 66 22 6 30 32 92 54 16 76 74 98 18 48 48 30 92 2 16 42 84 74 30 60 64 52 50 26 16 86 58 96 79 60 20 62 82 94", "output": "93" }, { "input": "95\n9 31 27 93 17 77 75 9 9 53 89 39 51 99 5 1 11 39 27 49 91 17 27 79 81 71 37 75 35 13 93 4 99 55 85 11 23 57 5 43 5 61 15 35 23 91 3 81 99 85 43 37 39 27 5 67 7 33 75 59 13 71 51 27 15 93 51 63 91 53 43 99 25 47 17 71 81 15 53 31 59 83 41 23 73 25 91 91 13 17 25 13 55 57 29", "output": "32" }, { "input": "100\n91 89 81 45 53 1 41 3 77 93 55 97 55 97 87 27 69 95 73 41 93 21 75 35 53 56 5 51 87 59 91 67 33 3 99 45 83 17 97 47 75 97 7 89 17 99 23 23 81 25 55 97 27 35 69 5 77 35 93 19 55 59 37 21 31 37 49 41 91 53 73 69 7 37 37 39 17 71 7 97 55 17 47 23 15 73 31 39 57 37 9 5 61 41 65 57 77 79 35 47", "output": "26" }, { "input": "99\n38 56 58 98 80 54 26 90 14 16 78 92 52 74 40 30 84 14 44 80 16 90 98 68 26 24 78 72 42 16 84 40 14 44 2 52 50 2 12 96 58 66 8 80 44 52 34 34 72 98 74 4 66 74 56 21 8 38 76 40 10 22 48 32 98 34 12 62 80 68 64 82 22 78 58 74 20 22 48 56 12 38 32 72 6 16 74 24 94 84 26 38 18 24 76 78 98 94 72", "output": "56" }, { "input": "100\n44 40 6 40 56 90 98 8 36 64 76 86 98 76 36 92 6 30 98 70 24 98 96 60 24 82 88 68 86 96 34 42 58 10 40 26 56 10 88 58 70 32 24 28 14 82 52 12 62 36 70 60 52 34 74 30 78 76 10 16 42 94 66 90 70 38 52 12 58 22 98 96 14 68 24 70 4 30 84 98 8 50 14 52 66 34 100 10 28 100 56 48 38 12 38 14 91 80 70 86", "output": "97" }, { "input": "100\n96 62 64 20 90 46 56 90 68 36 30 56 70 28 16 64 94 34 6 32 34 50 94 22 90 32 40 2 72 10 88 38 28 92 20 26 56 80 4 100 100 90 16 74 74 84 8 2 30 20 80 32 16 46 92 56 42 12 96 64 64 42 64 58 50 42 74 28 2 4 36 32 70 50 54 92 70 16 45 76 28 16 18 50 48 2 62 94 4 12 52 52 4 100 70 60 82 62 98 42", "output": "79" }, { "input": "99\n14 26 34 68 90 58 50 36 8 16 18 6 2 74 54 20 36 84 32 50 52 2 26 24 3 64 20 10 54 26 66 44 28 72 4 96 78 90 96 86 68 28 94 4 12 46 100 32 22 36 84 32 44 94 76 94 4 52 12 30 74 4 34 64 58 72 44 16 70 56 54 8 14 74 8 6 58 62 98 54 14 40 80 20 36 72 28 98 20 58 40 52 90 64 22 48 54 70 52", "output": "25" }, { "input": "95\n82 86 30 78 6 46 80 66 74 72 16 24 18 52 52 38 60 36 86 26 62 28 22 46 96 26 94 84 20 46 66 88 76 32 12 86 74 18 34 88 4 48 94 6 58 6 100 82 4 24 88 32 54 98 34 48 6 76 42 88 42 28 100 4 22 2 10 66 82 54 98 20 60 66 38 98 32 47 86 58 6 100 12 46 2 42 8 84 78 28 24 70 34 28 86", "output": "78" }, { "input": "90\n40 50 8 42 76 24 58 42 26 68 20 48 54 12 34 84 14 36 32 88 6 50 96 56 20 92 48 16 40 34 96 46 20 84 30 50 20 98 8 44 96 42 8 76 70 38 84 30 40 88 84 72 2 22 52 58 16 62 100 66 80 40 50 32 14 62 88 72 22 99 76 50 84 82 8 82 98 46 26 40 2 98 18 78 30 72 70 18 34 68", "output": "70" }, { "input": "80\n81 43 87 1 55 43 53 61 27 19 43 13 89 9 33 83 75 55 97 71 91 37 95 5 21 69 81 93 95 69 31 83 55 7 97 7 79 57 8 61 27 85 49 1 15 97 63 79 29 73 41 85 5 41 31 93 67 11 63 59 15 99 91 77 43 69 23 23 81 73 19 1 67 51 1 75 99 67 3 81", "output": "39" }, { "input": "98\n13 83 61 27 35 1 85 95 97 73 95 65 73 45 5 43 27 83 91 19 11 3 85 59 9 39 69 23 45 7 51 85 5 71 5 95 1 51 75 3 43 57 3 11 33 71 21 99 47 41 87 39 71 87 31 85 91 49 83 5 49 85 47 91 55 99 33 23 31 23 23 73 29 77 55 31 25 5 81 49 91 15 15 39 87 5 9 40 69 47 29 33 11 21 49 79 51 83", "output": "88" }, { "input": "3\n100 100 1", "output": "3" } ]
1,676,481,935
2,147,483,647
PyPy 3-64
OK
TESTS
32
122
0
n = int(input()) lst = list(map(int, input().split())) evenCount = sum(1 for x in lst[0:3] if x % 2 == 0) residuToFind = 1 if evenCount >= 2 else 0 print(1 + next(n for n, x in enumerate(lst) if x % 2 == residuToFind))
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()) lst = list(map(int, input().split())) evenCount = sum(1 for x in lst[0:3] if x % 2 == 0) residuToFind = 1 if evenCount >= 2 else 0 print(1 + next(n for n, x in enumerate(lst) if x % 2 == residuToFind)) ```
3.9695
294
A
Shaass and Oskols
PROGRAMMING
800
[ "implementation", "math" ]
null
null
Shaass has decided to hunt some birds. There are *n* horizontal electricity wires aligned parallel to each other. Wires are numbered 1 to *n* from top to bottom. On each wire there are some oskols sitting next to each other. Oskol is the name of a delicious kind of birds in Shaass's territory. Supposed there are *a**i* oskols sitting on the *i*-th wire. Sometimes Shaass shots one of the birds and the bird dies (suppose that this bird sat at the *i*-th wire). Consequently all the birds on the *i*-th wire to the left of the dead bird get scared and jump up on the wire number *i*<=-<=1, if there exists no upper wire they fly away. Also all the birds to the right of the dead bird jump down on wire number *i*<=+<=1, if there exists no such wire they fly away. Shaass has shot *m* birds. You're given the initial number of birds on each wire, tell him how many birds are sitting on each wire after the shots.
The first line of the input contains an integer *n*, (1<=≤<=*n*<=≤<=100). The next line contains a list of space-separated integers *a*1,<=*a*2,<=...,<=*a**n*, (0<=≤<=*a**i*<=≤<=100). The third line contains an integer *m*, (0<=≤<=*m*<=≤<=100). Each of the next *m* lines contains two integers *x**i* and *y**i*. The integers mean that for the *i*-th time Shaass shoot the *y**i*-th (from left) bird on the *x**i*-th wire, (1<=≤<=*x**i*<=≤<=*n*,<=1<=≤<=*y**i*). It's guaranteed there will be at least *y**i* birds on the *x**i*-th wire at that moment.
On the *i*-th line of the output print the number of birds on the *i*-th wire.
[ "5\n10 10 10 10 10\n5\n2 5\n3 13\n2 12\n1 13\n4 6\n", "3\n2 4 1\n1\n2 2\n" ]
[ "0\n12\n5\n0\n16\n", "3\n0\n3\n" ]
none
500
[ { "input": "5\n10 10 10 10 10\n5\n2 5\n3 13\n2 12\n1 13\n4 6", "output": "0\n12\n5\n0\n16" }, { "input": "3\n2 4 1\n1\n2 2", "output": "3\n0\n3" }, { "input": "5\n58 51 45 27 48\n5\n4 9\n5 15\n4 5\n5 8\n1 43", "output": "0\n66\n57\n7\n0" }, { "input": "10\n48 53 10 28 91 56 81 2 67 52\n2\n2 40\n6 51", "output": "87\n0\n23\n28\n141\n0\n86\n2\n67\n52" }, { "input": "2\n72 45\n6\n1 69\n2 41\n1 19\n2 7\n1 5\n2 1", "output": "0\n0" }, { "input": "10\n95 54 36 39 98 30 19 24 14 12\n3\n9 5\n8 15\n7 5", "output": "95\n54\n36\n39\n98\n34\n0\n28\n13\n21" }, { "input": "100\n95 15 25 18 64 62 23 59 70 84 50 26 87 35 75 86 0 22 77 60 66 41 21 9 75 50 25 3 69 14 39 68 64 46 59 99 2 0 21 76 90 12 61 42 6 91 36 39 47 41 93 81 66 57 70 36 68 89 52 1 19 93 67 22 76 20 8 81 98 18 100 73 61 93 75 80 53 72 40 20 2 86 33 59 27 16 11 26 55 44 47 55 94 58 2 55 82 22 9 95\n0", "output": "95\n15\n25\n18\n64\n62\n23\n59\n70\n84\n50\n26\n87\n35\n75\n86\n0\n22\n77\n60\n66\n41\n21\n9\n75\n50\n25\n3\n69\n14\n39\n68\n64\n46\n59\n99\n2\n0\n21\n76\n90\n12\n61\n42\n6\n91\n36\n39\n47\n41\n93\n81\n66\n57\n70\n36\n68\n89\n52\n1\n19\n93\n67\n22\n76\n20\n8\n81\n98\n18\n100\n73\n61\n93\n75\n80\n53\n72\n40\n20\n2\n86\n33\n59\n27\n16\n11\n26\n55\n44\n47\n55\n94\n58\n2\n55\n82\n22\n9\n95" }, { "input": "1\n100\n1\n1 100", "output": "0" }, { "input": "1\n100\n1\n1 1", "output": "0" }, { "input": "1\n50\n1\n1 25", "output": "0" }, { "input": "2\n50 0\n1\n1 1", "output": "0\n49" }, { "input": "1\n10\n0", "output": "10" } ]
1,595,491,221
2,147,483,647
Python 3
RUNTIME_ERROR
TESTS
0
156
6,963,200
def bird(a,b): if a!=1 and a!=m: l[a-2]+=b-1 l[a]+=l[a-1]-b l[a-1]=0 if a==1: l[a] += l[a - 1] - b l[a - 1] = 0 if a==m: l[a - 2] += b - 1 l[a - 1] = 0 for i in range(m): a,b=map(int, input().split()) bird(a,b) for i in l: print(i)
Title: Shaass and Oskols Time Limit: None seconds Memory Limit: None megabytes Problem Description: Shaass has decided to hunt some birds. There are *n* horizontal electricity wires aligned parallel to each other. Wires are numbered 1 to *n* from top to bottom. On each wire there are some oskols sitting next to each other. Oskol is the name of a delicious kind of birds in Shaass's territory. Supposed there are *a**i* oskols sitting on the *i*-th wire. Sometimes Shaass shots one of the birds and the bird dies (suppose that this bird sat at the *i*-th wire). Consequently all the birds on the *i*-th wire to the left of the dead bird get scared and jump up on the wire number *i*<=-<=1, if there exists no upper wire they fly away. Also all the birds to the right of the dead bird jump down on wire number *i*<=+<=1, if there exists no such wire they fly away. Shaass has shot *m* birds. You're given the initial number of birds on each wire, tell him how many birds are sitting on each wire after the shots. Input Specification: The first line of the input contains an integer *n*, (1<=≤<=*n*<=≤<=100). The next line contains a list of space-separated integers *a*1,<=*a*2,<=...,<=*a**n*, (0<=≤<=*a**i*<=≤<=100). The third line contains an integer *m*, (0<=≤<=*m*<=≤<=100). Each of the next *m* lines contains two integers *x**i* and *y**i*. The integers mean that for the *i*-th time Shaass shoot the *y**i*-th (from left) bird on the *x**i*-th wire, (1<=≤<=*x**i*<=≤<=*n*,<=1<=≤<=*y**i*). It's guaranteed there will be at least *y**i* birds on the *x**i*-th wire at that moment. Output Specification: On the *i*-th line of the output print the number of birds on the *i*-th wire. Demo Input: ['5\n10 10 10 10 10\n5\n2 5\n3 13\n2 12\n1 13\n4 6\n', '3\n2 4 1\n1\n2 2\n'] Demo Output: ['0\n12\n5\n0\n16\n', '3\n0\n3\n'] Note: none
```python def bird(a,b): if a!=1 and a!=m: l[a-2]+=b-1 l[a]+=l[a-1]-b l[a-1]=0 if a==1: l[a] += l[a - 1] - b l[a - 1] = 0 if a==m: l[a - 2] += b - 1 l[a - 1] = 0 for i in range(m): a,b=map(int, input().split()) bird(a,b) for i in l: print(i) ```
-1
433
A
Kitahara Haruki's Gift
PROGRAMMING
1,100
[ "brute force", "implementation" ]
null
null
Kitahara Haruki has bought *n* apples for Touma Kazusa and Ogiso Setsuna. Now he wants to divide all the apples between the friends. Each apple weights 100 grams or 200 grams. Of course Kitahara Haruki doesn't want to offend any of his friend. Therefore the total weight of the apples given to Touma Kazusa must be equal to the total weight of the apples given to Ogiso Setsuna. But unfortunately Kitahara Haruki doesn't have a knife right now, so he cannot split any apple into some parts. Please, tell him: is it possible to divide all the apples in a fair way between his friends?
The first line contains an integer *n* (1<=≤<=*n*<=≤<=100) — the number of apples. The second line contains *n* integers *w*1,<=*w*2,<=...,<=*w**n* (*w**i*<==<=100 or *w**i*<==<=200), where *w**i* is the weight of the *i*-th apple.
In a single line print "YES" (without the quotes) if it is possible to divide all the apples between his friends. Otherwise print "NO" (without the quotes).
[ "3\n100 200 100\n", "4\n100 100 100 200\n" ]
[ "YES\n", "NO\n" ]
In the first test sample Kitahara Haruki can give the first and the last apple to Ogiso Setsuna and the middle apple to Touma Kazusa.
500
[ { "input": "3\n100 200 100", "output": "YES" }, { "input": "4\n100 100 100 200", "output": "NO" }, { "input": "1\n100", "output": "NO" }, { "input": "1\n200", "output": "NO" }, { "input": "2\n100 100", "output": "YES" }, { "input": "2\n200 200", "output": "YES" }, { "input": "100\n200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200", "output": "YES" }, { "input": "100\n200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 100 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200", "output": "NO" }, { "input": "52\n200 200 100 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 100 200 200 200 200 200 200 200 200 200 200 200 200 200 200 100 200 200 200 200 100 200 100 200 200 200 100 200 200", "output": "YES" }, { "input": "2\n100 200", "output": "NO" }, { "input": "2\n200 100", "output": "NO" }, { "input": "3\n100 100 100", "output": "NO" }, { "input": "3\n200 200 200", "output": "NO" }, { "input": "3\n200 100 200", "output": "NO" }, { "input": "4\n100 100 100 100", "output": "YES" }, { "input": "4\n200 200 200 200", "output": "YES" }, { "input": "100\n200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 100 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 100 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200", "output": "YES" }, { "input": "100\n200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 100 200 100 200 100 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200", "output": "NO" }, { "input": "100\n100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100", "output": "YES" }, { "input": "100\n100 100 200 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100", "output": "NO" }, { "input": "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 200 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 200 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100", "output": "YES" }, { "input": "100\n100 100 100 100 100 100 100 100 200 100 100 200 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 200 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100", "output": "NO" }, { "input": "99\n200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200", "output": "NO" }, { "input": "99\n200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 100 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200", "output": "NO" }, { "input": "99\n200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 100 200 200 200 200 200 100 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200", "output": "YES" }, { "input": "99\n200 200 200 200 200 200 200 200 200 200 200 100 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 100 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 100 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200", "output": "NO" }, { "input": "99\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", "output": "NO" }, { "input": "99\n100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 200 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 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": "YES" }, { "input": "99\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 200 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 200 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100", "output": "NO" }, { "input": "100\n100 100 200 100 100 200 200 200 200 100 200 100 100 100 200 100 100 100 100 200 100 100 100 100 100 100 200 100 100 200 200 100 100 100 200 200 200 100 200 200 100 200 100 100 200 100 200 200 100 200 200 100 100 200 200 100 200 200 100 100 200 100 200 100 200 200 200 200 200 100 200 200 200 200 200 200 100 100 200 200 200 100 100 100 200 100 100 200 100 100 100 200 200 100 100 200 200 200 200 100", "output": "YES" }, { "input": "100\n100 100 200 200 100 200 100 100 100 100 100 100 200 100 200 200 200 100 100 200 200 200 200 200 100 200 100 200 100 100 100 200 100 100 200 100 200 100 100 100 200 200 100 100 100 200 200 200 200 200 100 200 200 100 100 100 100 200 100 100 200 100 100 100 100 200 200 200 100 200 100 200 200 200 100 100 200 200 200 200 100 200 100 200 200 100 200 100 200 200 200 200 200 200 100 100 100 200 200 100", "output": "NO" }, { "input": "100\n100 200 100 100 200 200 200 200 100 200 200 200 200 200 200 200 200 200 100 100 100 200 200 200 200 200 100 200 200 200 200 100 200 200 100 100 200 100 100 100 200 100 100 100 200 100 200 100 200 200 200 100 100 200 100 200 100 200 100 100 100 200 100 200 100 100 100 100 200 200 200 200 100 200 200 100 200 100 100 100 200 100 100 100 100 100 200 100 100 100 200 200 200 100 200 100 100 100 200 200", "output": "YES" }, { "input": "99\n100 200 200 200 100 200 100 200 200 100 100 100 100 200 100 100 200 100 200 100 100 200 100 100 200 200 100 100 100 100 200 200 200 200 200 100 100 200 200 100 100 100 100 200 200 100 100 100 100 100 200 200 200 100 100 100 200 200 200 100 200 100 100 100 100 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 100 100 200 100 200 200 200 200 100 200 100 100 100 100 100 100 100 100 100", "output": "YES" }, { "input": "99\n100 200 100 100 100 100 200 200 100 200 100 100 200 100 100 100 100 100 100 200 100 100 100 100 100 100 100 200 100 200 100 100 100 100 100 100 100 200 200 200 200 200 200 200 100 200 100 200 100 200 100 200 100 100 200 200 200 100 200 200 200 200 100 200 100 200 200 200 200 100 200 100 200 200 100 200 200 200 200 200 100 100 200 100 100 100 100 200 200 200 100 100 200 200 200 200 200 200 200", "output": "NO" }, { "input": "99\n200 100 100 100 200 200 200 100 100 100 100 100 100 100 100 100 200 200 100 200 200 100 200 100 100 200 200 200 100 200 100 200 200 100 200 100 200 200 200 100 100 200 200 200 200 100 100 100 100 200 200 200 200 100 200 200 200 100 100 100 200 200 200 100 200 100 200 100 100 100 200 100 200 200 100 200 200 200 100 100 100 200 200 200 100 200 200 200 100 100 100 200 100 200 100 100 100 200 200", "output": "YES" }, { "input": "56\n100 200 200 200 200 200 100 200 100 100 200 100 100 100 100 100 200 200 200 100 200 100 100 200 200 200 100 200 100 200 200 100 100 100 100 100 200 100 200 100 200 200 200 100 100 200 200 200 200 200 200 200 200 200 200 100", "output": "YES" }, { "input": "72\n200 100 200 200 200 100 100 200 200 100 100 100 100 200 100 200 100 100 100 100 200 100 200 100 100 200 100 100 200 100 200 100 100 200 100 200 100 100 200 200 200 200 200 100 100 200 200 200 200 100 100 100 200 200 100 100 100 100 100 200 100 100 200 100 100 200 200 100 100 200 100 200", "output": "YES" }, { "input": "32\n200 200 200 100 100 100 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 100 200 200 200 200 200 200", "output": "YES" }, { "input": "48\n200 200 200 200 200 200 100 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 100 200 100 200 200 200 200 200 200", "output": "NO" }, { "input": "60\n100 100 200 200 100 200 100 200 100 100 100 100 100 100 200 100 100 100 200 100 200 100 100 100 100 100 200 100 200 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 200 100 100 100", "output": "YES" }, { "input": "24\n200 200 100 100 200 100 200 200 100 200 200 200 200 200 100 200 200 200 200 200 200 200 200 100", "output": "YES" }, { "input": "40\n100 100 200 200 200 200 100 100 100 200 100 100 200 200 100 100 100 100 100 200 100 200 200 100 200 200 200 100 100 100 100 100 200 200 100 200 100 100 200 100", "output": "NO" }, { "input": "5\n200 200 200 200 200", "output": "NO" }, { "input": "9\n100 100 100 200 100 100 200 100 200", "output": "YES" }, { "input": "1\n200", "output": "NO" }, { "input": "7\n200 200 200 100 200 200 200", "output": "NO" }, { "input": "4\n100 100 200 200", "output": "YES" }, { "input": "6\n100 100 100 200 200 200", "output": "NO" }, { "input": "4\n200 100 100 200", "output": "YES" }, { "input": "5\n100 100 100 100 200", "output": "YES" } ]
1,629,018,863
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
3
61
6,963,200
n = int(input()) s = input().split(' ') a = [int(i) for i in s] f = 1 count_100 = a.count(100) count_200 = a.count(200) c1 = count_100%2 c2 = count_200%2 if c1==1: if count_100==1: print("NO") f = 0 elif count_100>1: if c2!=1 or count_200==1: print("NO") f = 0 elif c2 ==0: if count_100==0: if c2!=0: print("NO") f = 0 if f!=0: print("YES")
Title: Kitahara Haruki's Gift Time Limit: None seconds Memory Limit: None megabytes Problem Description: Kitahara Haruki has bought *n* apples for Touma Kazusa and Ogiso Setsuna. Now he wants to divide all the apples between the friends. Each apple weights 100 grams or 200 grams. Of course Kitahara Haruki doesn't want to offend any of his friend. Therefore the total weight of the apples given to Touma Kazusa must be equal to the total weight of the apples given to Ogiso Setsuna. But unfortunately Kitahara Haruki doesn't have a knife right now, so he cannot split any apple into some parts. Please, tell him: is it possible to divide all the apples in a fair way between his friends? Input Specification: The first line contains an integer *n* (1<=≤<=*n*<=≤<=100) — the number of apples. The second line contains *n* integers *w*1,<=*w*2,<=...,<=*w**n* (*w**i*<==<=100 or *w**i*<==<=200), where *w**i* is the weight of the *i*-th apple. Output Specification: In a single line print "YES" (without the quotes) if it is possible to divide all the apples between his friends. Otherwise print "NO" (without the quotes). Demo Input: ['3\n100 200 100\n', '4\n100 100 100 200\n'] Demo Output: ['YES\n', 'NO\n'] Note: In the first test sample Kitahara Haruki can give the first and the last apple to Ogiso Setsuna and the middle apple to Touma Kazusa.
```python n = int(input()) s = input().split(' ') a = [int(i) for i in s] f = 1 count_100 = a.count(100) count_200 = a.count(200) c1 = count_100%2 c2 = count_200%2 if c1==1: if count_100==1: print("NO") f = 0 elif count_100>1: if c2!=1 or count_200==1: print("NO") f = 0 elif c2 ==0: if count_100==0: if c2!=0: print("NO") f = 0 if f!=0: print("YES") ```
0
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,695,922,119
2,147,483,647
Python 3
OK
TESTS
42
92
0
word = input().lower() vowels = ['a','e','y','u','i','o'] result = "" for char in word: if char not in vowels: result += '.' + char print(result)
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 word = input().lower() vowels = ['a','e','y','u','i','o'] result = "" for char in word: if char not in vowels: result += '.' + char print(result) ```
3
59
A
Word
PROGRAMMING
800
[ "implementation", "strings" ]
A. Word
2
256
Vasya is very upset that many people on the Net mix uppercase and lowercase letters in one word. That's why he decided to invent an extension for his favorite browser that would change the letters' register in every word so that it either only consisted of lowercase letters or, vice versa, only of uppercase ones. At that as little as possible letters should be changed in the word. For example, the word HoUse must be replaced with house, and the word ViP — with VIP. If a word contains an equal number of uppercase and lowercase letters, you should replace all the letters with lowercase ones. For example, maTRIx should be replaced by matrix. Your task is to use the given method on one given word.
The first line contains a word *s* — it consists of uppercase and lowercase Latin letters and possesses the length from 1 to 100.
Print the corrected word *s*. If the given word *s* has strictly more uppercase letters, make the word written in the uppercase register, otherwise - in the lowercase one.
[ "HoUse\n", "ViP\n", "maTRIx\n" ]
[ "house\n", "VIP\n", "matrix\n" ]
none
500
[ { "input": "HoUse", "output": "house" }, { "input": "ViP", "output": "VIP" }, { "input": "maTRIx", "output": "matrix" }, { "input": "BNHWpnpawg", "output": "bnhwpnpawg" }, { "input": "VTYGP", "output": "VTYGP" }, { "input": "CHNenu", "output": "chnenu" }, { "input": "ERPZGrodyu", "output": "erpzgrodyu" }, { "input": "KSXBXWpebh", "output": "KSXBXWPEBH" }, { "input": "qvxpqullmcbegsdskddortcvxyqlbvxmmkhevovnezubvpvnrcajpxraeaxizgaowtfkzywvhnbgzsxbhkaipcmoumtikkiyyaiv", "output": "qvxpqullmcbegsdskddortcvxyqlbvxmmkhevovnezubvpvnrcajpxraeaxizgaowtfkzywvhnbgzsxbhkaipcmoumtikkiyyaiv" }, { "input": "Amnhaxtaopjzrkqlbroiyipitndczpunwygstmzevgyjdzyanxkdqnvgkikfabwouwkkbzuiuvgvxgpizsvqsbwepktpdrgdkmfd", "output": "amnhaxtaopjzrkqlbroiyipitndczpunwygstmzevgyjdzyanxkdqnvgkikfabwouwkkbzuiuvgvxgpizsvqsbwepktpdrgdkmfd" }, { "input": "ISAGFJFARYFBLOPQDSHWGMCNKMFTLVFUGNJEWGWNBLXUIATXEkqiettmmjgydwcpafqrppdsrrrtguinqbgmzzfqwonkpgpcwenv", "output": "isagfjfaryfblopqdshwgmcnkmftlvfugnjewgwnblxuiatxekqiettmmjgydwcpafqrppdsrrrtguinqbgmzzfqwonkpgpcwenv" }, { "input": "XHRPXZEGHSOCJPICUIXSKFUZUPYTSGJSDIYBCMNMNBPNDBXLXBzhbfnqvwcffvrdhtickyqhupmcehlsyvncqmfhautvxudqdhgg", "output": "xhrpxzeghsocjpicuixskfuzupytsgjsdiybcmnmnbpndbxlxbzhbfnqvwcffvrdhtickyqhupmcehlsyvncqmfhautvxudqdhgg" }, { "input": "RJIQZMJCIMSNDBOHBRAWIENODSALETAKGKPYUFGVEFGCBRENZGAdkcetqjljtmttlonpekcovdzebzdkzggwfsxhapmjkdbuceak", "output": "RJIQZMJCIMSNDBOHBRAWIENODSALETAKGKPYUFGVEFGCBRENZGADKCETQJLJTMTTLONPEKCOVDZEBZDKZGGWFSXHAPMJKDBUCEAK" }, { "input": "DWLWOBHNMMGTFOLFAECKBRNNGLYLYDXTGTVRLMEESZOIUATZZZXUFUZDLSJXMEVRTESSFBWLNZZCLCQWEVNNUCXYVHNGNXHCBDFw", "output": "DWLWOBHNMMGTFOLFAECKBRNNGLYLYDXTGTVRLMEESZOIUATZZZXUFUZDLSJXMEVRTESSFBWLNZZCLCQWEVNNUCXYVHNGNXHCBDFW" }, { "input": "NYCNHJWGBOCOTSPETKKHVWFGAQYNHOVJWJHCIEFOUQZXOYUIEQDZALFKTEHTVDBVJMEUBJUBCMNVPWGDPNCHQHZJRCHYRFPVIGUB", "output": "NYCNHJWGBOCOTSPETKKHVWFGAQYNHOVJWJHCIEFOUQZXOYUIEQDZALFKTEHTVDBVJMEUBJUBCMNVPWGDPNCHQHZJRCHYRFPVIGUB" }, { "input": "igxoixiecetohtgjgbqzvlaobkhstejxdklghowtvwunnnvauriohuspsdmpzckprwajyxldoyckgjivjpmbfqtszmtocovxwge", "output": "igxoixiecetohtgjgbqzvlaobkhstejxdklghowtvwunnnvauriohuspsdmpzckprwajyxldoyckgjivjpmbfqtszmtocovxwge" }, { "input": "Ykkekrsqolzryiwsmdlnbmfautxxxauoojrddvwklgnlyrfcvhorrzbmtcrvpaypqhcffdqhwziipyyskcmztjprjqvmzzqhqnw", "output": "ykkekrsqolzryiwsmdlnbmfautxxxauoojrddvwklgnlyrfcvhorrzbmtcrvpaypqhcffdqhwziipyyskcmztjprjqvmzzqhqnw" }, { "input": "YQOMLKYAORUQQUCQZCDYMIVDHGWZFFRMUVTAWCHERFPMNRYRIkgqrciokgajamehmcxgerpudvsqyonjonsxgbnefftzmygncks", "output": "yqomlkyaoruqqucqzcdymivdhgwzffrmuvtawcherfpmnryrikgqrciokgajamehmcxgerpudvsqyonjonsxgbnefftzmygncks" }, { "input": "CDOZDPBVVVHNBJVBYHEOXWFLJKRWJCAJMIFCOZWWYFKVWOGTVJcuusigdqfkumewjtdyitveeiaybwrhomrwmpdipjwiuxfnwuz", "output": "CDOZDPBVVVHNBJVBYHEOXWFLJKRWJCAJMIFCOZWWYFKVWOGTVJCUUSIGDQFKUMEWJTDYITVEEIAYBWRHOMRWMPDIPJWIUXFNWUZ" }, { "input": "WHIUVEXHVOOIJIDVJVPQUBJMEVPMPDKQWJKFBZSGSKUXMIPPMJWuckzcpxosodcjaaakvlxpbiigsiauviilylnnqlyucziihqg", "output": "WHIUVEXHVOOIJIDVJVPQUBJMEVPMPDKQWJKFBZSGSKUXMIPPMJWUCKZCPXOSODCJAAAKVLXPBIIGSIAUVIILYLNNQLYUCZIIHQG" }, { "input": "VGHUNFOXKETUYMZDJNGTAOIOANYXSGYNFOGOFFLDAWEUKYFOZXCJTCAFXZYLQZERYZLRSQXYQGAPCSUDPMEYTNCTTTMFAGVDWBO", "output": "VGHUNFOXKETUYMZDJNGTAOIOANYXSGYNFOGOFFLDAWEUKYFOZXCJTCAFXZYLQZERYZLRSQXYQGAPCSUDPMEYTNCTTTMFAGVDWBO" }, { "input": "EDUANHCQDOCJHFONTTSWBUJSTTIXBIXMAIUFSGFLXWAYIURTVAVZPYQDLAWIGCLMPHXCEFCJPFAAHXVNGQUFNHADAIUAZIDMHDd", "output": "EDUANHCQDOCJHFONTTSWBUJSTTIXBIXMAIUFSGFLXWAYIURTVAVZPYQDLAWIGCLMPHXCEFCJPFAAHXVNGQUFNHADAIUAZIDMHDD" }, { "input": "EBWOVSNLYTWWXrnovgugogtjahnmatomubebyxakas", "output": "ebwovsnlytwwxrnovgugogtjahnmatomubebyxakas" }, { "input": "AORNNDKTRLRVGDPXJKXFTPFpopuzrlqumrxssskvbm", "output": "AORNNDKTRLRVGDPXJKXFTPFPOPUZRLQUMRXSSSKVBM" }, { "input": "DBBZJCWQEVGYHEEUHJAWRHBDPsnplijbwtdibqrrheebfxqcvn", "output": "dbbzjcwqevgyheeuhjawrhbdpsnplijbwtdibqrrheebfxqcvn" }, { "input": "t", "output": "t" }, { "input": "N", "output": "N" }, { "input": "kv", "output": "kv" }, { "input": "Ur", "output": "ur" }, { "input": "CN", "output": "CN" } ]
1,674,581,130
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
2
62
0
word=input() l=0 u=0 for i in range(len(word)): if word[i].islower(): l+=1 else: u+=1 if l>u: print(word.lower()) else: print(word.upper())
Title: Word Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: Vasya is very upset that many people on the Net mix uppercase and lowercase letters in one word. That's why he decided to invent an extension for his favorite browser that would change the letters' register in every word so that it either only consisted of lowercase letters or, vice versa, only of uppercase ones. At that as little as possible letters should be changed in the word. For example, the word HoUse must be replaced with house, and the word ViP — with VIP. If a word contains an equal number of uppercase and lowercase letters, you should replace all the letters with lowercase ones. For example, maTRIx should be replaced by matrix. Your task is to use the given method on one given word. Input Specification: The first line contains a word *s* — it consists of uppercase and lowercase Latin letters and possesses the length from 1 to 100. Output Specification: Print the corrected word *s*. If the given word *s* has strictly more uppercase letters, make the word written in the uppercase register, otherwise - in the lowercase one. Demo Input: ['HoUse\n', 'ViP\n', 'maTRIx\n'] Demo Output: ['house\n', 'VIP\n', 'matrix\n'] Note: none
```python word=input() l=0 u=0 for i in range(len(word)): if word[i].islower(): l+=1 else: u+=1 if l>u: print(word.lower()) else: print(word.upper()) ```
0
792
A
New Bus Route
PROGRAMMING
1,100
[ "implementation", "sortings" ]
null
null
There are *n* cities situated along the main road of Berland. Cities are represented by their coordinates — integer numbers *a*1,<=*a*2,<=...,<=*a**n*. All coordinates are pairwise distinct. It is possible to get from one city to another only by bus. But all buses and roads are very old, so the Minister of Transport decided to build a new bus route. The Minister doesn't want to spend large amounts of money — he wants to choose two cities in such a way that the distance between them is minimal possible. The distance between two cities is equal to the absolute value of the difference between their coordinates. It is possible that there are multiple pairs of cities with minimal possible distance, so the Minister wants to know the quantity of such pairs. Your task is to write a program that will calculate the minimal possible distance between two pairs of cities and the quantity of pairs which have this distance.
The first line contains one integer number *n* (2<=≤<=*n*<=≤<=2·105). The second line contains *n* integer numbers *a*1,<=*a*2,<=...,<=*a**n* (<=-<=109<=≤<=*a**i*<=≤<=109). All numbers *a**i* are pairwise distinct.
Print two integer numbers — the minimal distance and the quantity of pairs with this distance.
[ "4\n6 -3 0 4\n", "3\n-2 0 2\n" ]
[ "2 1\n", "2 2\n" ]
In the first example the distance between the first city and the fourth city is |4 - 6| = 2, and it is the only pair with this distance.
0
[ { "input": "4\n6 -3 0 4", "output": "2 1" }, { "input": "3\n-2 0 2", "output": "2 2" }, { "input": "2\n1 2", "output": "1 1" }, { "input": "2\n1000000000 -1000000000", "output": "2000000000 1" }, { "input": "5\n-979619606 -979619602 -979619604 -979619605 -979619603", "output": "1 4" }, { "input": "5\n-799147771 -799147773 -799147764 -799147774 -799147770", "output": "1 2" }, { "input": "20\n553280626 553280623 553280627 553280624 553280625 553280618 553280620 553280629 553280637 553280631 553280628 553280636 553280635 553280632 553280634 553280622 553280633 553280621 553280630 553280619", "output": "1 19" }, { "input": "20\n105619866 106083760 106090730 105809555 106115212 105155938 105979518 106075627 106145216 105637844 105925719 105498536 105927000 106155938 106134226 106125969 106130588 105464813 106145509 106114971", "output": "241 1" }, { "input": "10\n570685866 570685854 570685858 570685850 570685856 570685864 570685860 570685852 570685862 570685868", "output": "2 9" }, { "input": "2\n1 1000000000", "output": "999999999 1" }, { "input": "6\n1 2 3 4 5 6", "output": "1 5" }, { "input": "3\n7 10 12", "output": "2 1" }, { "input": "5\n-7 -5 -4 -3 -1", "output": "1 2" }, { "input": "4\n-6 -4 -2 1", "output": "2 2" }, { "input": "4\n3 5 7 8", "output": "1 1" }, { "input": "9\n-9 -8 -7 -6 -5 -4 -3 -2 -1", "output": "1 8" }, { "input": "2\n15 13", "output": "2 1" }, { "input": "2\n14 13", "output": "1 1" }, { "input": "2\n12 13", "output": "1 1" }, { "input": "2\n-1000000000 13265920", "output": "1013265920 1" }, { "input": "2\n8 10", "output": "2 1" } ]
1,544,909,036
2,147,483,647
Python 3
OK
TESTS
45
374
15,667,200
N = int(input()) points = [int(n) for n in input().split()] points.sort() pairs = 0 min_dist = float('inf') distance = [points[i+1]-points[i] for i in range(N-1)] for i in range(N-1): if distance[i] < min_dist: min_dist=distance[i] pairs = 1 elif distance[i] == min_dist: pairs += 1 print(min_dist, pairs)
Title: New Bus Route Time Limit: None seconds Memory Limit: None megabytes Problem Description: There are *n* cities situated along the main road of Berland. Cities are represented by their coordinates — integer numbers *a*1,<=*a*2,<=...,<=*a**n*. All coordinates are pairwise distinct. It is possible to get from one city to another only by bus. But all buses and roads are very old, so the Minister of Transport decided to build a new bus route. The Minister doesn't want to spend large amounts of money — he wants to choose two cities in such a way that the distance between them is minimal possible. The distance between two cities is equal to the absolute value of the difference between their coordinates. It is possible that there are multiple pairs of cities with minimal possible distance, so the Minister wants to know the quantity of such pairs. Your task is to write a program that will calculate the minimal possible distance between two pairs of cities and the quantity of pairs which have this distance. Input Specification: The first line contains one integer number *n* (2<=≤<=*n*<=≤<=2·105). The second line contains *n* integer numbers *a*1,<=*a*2,<=...,<=*a**n* (<=-<=109<=≤<=*a**i*<=≤<=109). All numbers *a**i* are pairwise distinct. Output Specification: Print two integer numbers — the minimal distance and the quantity of pairs with this distance. Demo Input: ['4\n6 -3 0 4\n', '3\n-2 0 2\n'] Demo Output: ['2 1\n', '2 2\n'] Note: In the first example the distance between the first city and the fourth city is |4 - 6| = 2, and it is the only pair with this distance.
```python N = int(input()) points = [int(n) for n in input().split()] points.sort() pairs = 0 min_dist = float('inf') distance = [points[i+1]-points[i] for i in range(N-1)] for i in range(N-1): if distance[i] < min_dist: min_dist=distance[i] pairs = 1 elif distance[i] == min_dist: pairs += 1 print(min_dist, pairs) ```
3
305
C
Ivan and Powers of Two
PROGRAMMING
1,600
[ "greedy", "implementation" ]
null
null
Ivan has got an array of *n* non-negative integers *a*1,<=*a*2,<=...,<=*a**n*. Ivan knows that the array is sorted in the non-decreasing order. Ivan wrote out integers 2*a*1,<=2*a*2,<=...,<=2*a**n* on a piece of paper. Now he wonders, what minimum number of integers of form 2*b* (*b*<=≥<=0) need to be added to the piece of paper so that the sum of all integers written on the paper equalled 2*v*<=-<=1 for some integer *v* (*v*<=≥<=0). Help Ivan, find the required quantity of numbers.
The first line contains integer *n* (1<=≤<=*n*<=≤<=105). The second input line contains *n* space-separated integers *a*1,<=*a*2,<=...,<=*a**n* (0<=≤<=*a**i*<=≤<=2·109). It is guaranteed that *a*1<=≤<=*a*2<=≤<=...<=≤<=*a**n*.
Print a single integer — the answer to the problem.
[ "4\n0 1 1 1\n", "1\n3\n" ]
[ "0\n", "3\n" ]
In the first sample you do not need to add anything, the sum of numbers already equals 2<sup class="upper-index">3</sup> - 1 = 7. In the second sample you need to add numbers 2<sup class="upper-index">0</sup>, 2<sup class="upper-index">1</sup>, 2<sup class="upper-index">2</sup>.
1,500
[ { "input": "4\n0 1 1 1", "output": "0" }, { "input": "1\n3", "output": "3" }, { "input": "1\n0", "output": "0" }, { "input": "1\n2000000000", "output": "2000000000" }, { "input": "1\n1", "output": "1" }, { "input": "26\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 2 2", "output": "5" } ]
1,518,315,905
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
6
233
13,721,600
from sys import stdin, stdout inputIdx = 0; input = stdin.read().strip().split(); def nextToken(): global inputIdx, input; token = input[inputIdx]; inputIdx += 1; return token; def main(): global inputIdx, input; while inputIdx < len(input): n = int( nextToken() ); arr = [ int( nextToken() ) for i in range(n) ]; diff = 0; cur = -1; cnt = 0; i = 0; ans = max(arr); while i < n: ans = max( ans, cur ); if ( cur != -1 and arr[i] == cur ) or ( cur == -1 ): j = i; while j < n and arr[i] == arr[j]: j += 1; cnt += j-i; cur = arr[i]+1; i = j; if (cnt&1) == 1: diff += 1; cnt //= 2; if cnt == 0: cur = -1; ans -= diff-1; print( int(ans) ); main();
Title: Ivan and Powers of Two Time Limit: None seconds Memory Limit: None megabytes Problem Description: Ivan has got an array of *n* non-negative integers *a*1,<=*a*2,<=...,<=*a**n*. Ivan knows that the array is sorted in the non-decreasing order. Ivan wrote out integers 2*a*1,<=2*a*2,<=...,<=2*a**n* on a piece of paper. Now he wonders, what minimum number of integers of form 2*b* (*b*<=≥<=0) need to be added to the piece of paper so that the sum of all integers written on the paper equalled 2*v*<=-<=1 for some integer *v* (*v*<=≥<=0). Help Ivan, find the required quantity of numbers. Input Specification: The first line contains integer *n* (1<=≤<=*n*<=≤<=105). The second input line contains *n* space-separated integers *a*1,<=*a*2,<=...,<=*a**n* (0<=≤<=*a**i*<=≤<=2·109). It is guaranteed that *a*1<=≤<=*a*2<=≤<=...<=≤<=*a**n*. Output Specification: Print a single integer — the answer to the problem. Demo Input: ['4\n0 1 1 1\n', '1\n3\n'] Demo Output: ['0\n', '3\n'] Note: In the first sample you do not need to add anything, the sum of numbers already equals 2<sup class="upper-index">3</sup> - 1 = 7. In the second sample you need to add numbers 2<sup class="upper-index">0</sup>, 2<sup class="upper-index">1</sup>, 2<sup class="upper-index">2</sup>.
```python from sys import stdin, stdout inputIdx = 0; input = stdin.read().strip().split(); def nextToken(): global inputIdx, input; token = input[inputIdx]; inputIdx += 1; return token; def main(): global inputIdx, input; while inputIdx < len(input): n = int( nextToken() ); arr = [ int( nextToken() ) for i in range(n) ]; diff = 0; cur = -1; cnt = 0; i = 0; ans = max(arr); while i < n: ans = max( ans, cur ); if ( cur != -1 and arr[i] == cur ) or ( cur == -1 ): j = i; while j < n and arr[i] == arr[j]: j += 1; cnt += j-i; cur = arr[i]+1; i = j; if (cnt&1) == 1: diff += 1; cnt //= 2; if cnt == 0: cur = -1; ans -= diff-1; print( int(ans) ); main(); ```
0
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,694,003,593
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
1
62
0
a = 8 if a % 2 == 0: 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 a = 8 if a % 2 == 0: print("Yes") else: print("no") ```
0
666
A
Reberland Linguistics
PROGRAMMING
1,800
[ "dp", "implementation", "strings" ]
null
null
First-rate specialists graduate from Berland State Institute of Peace and Friendship. You are one of the most talented students in this university. The education is not easy because you need to have fundamental knowledge in different areas, which sometimes are not related to each other. For example, you should know linguistics very well. You learn a structure of Reberland language as foreign language. In this language words are constructed according to the following rules. First you need to choose the "root" of the word — some string which has more than 4 letters. Then several strings with the length 2 or 3 symbols are appended to this word. The only restriction — it is not allowed to append the same string twice in a row. All these strings are considered to be suffixes of the word (this time we use word "suffix" to describe a morpheme but not the few last characters of the string as you may used to). Here is one exercise that you have found in your task list. You are given the word *s*. Find all distinct strings with the length 2 or 3, which can be suffixes of this word according to the word constructing rules in Reberland language. Two strings are considered distinct if they have different length or there is a position in which corresponding characters do not match. Let's look at the example: the word *abacabaca* is given. This word can be obtained in the following ways: , where the root of the word is overlined, and suffixes are marked by "corners". Thus, the set of possible suffixes for this word is {*aca*,<=*ba*,<=*ca*}.
The only line contains a string *s* (5<=≤<=|*s*|<=≤<=104) consisting of lowercase English letters.
On the first line print integer *k* — a number of distinct possible suffixes. On the next *k* lines print suffixes. Print suffixes in lexicographical (alphabetical) order.
[ "abacabaca\n", "abaca\n" ]
[ "3\naca\nba\nca\n", "0\n" ]
The first test was analysed in the problem statement. In the second example the length of the string equals 5. The length of the root equals 5, so no string can be used as a suffix.
500
[ { "input": "abacabaca", "output": "3\naca\nba\nca" }, { "input": "abaca", "output": "0" }, { "input": "gzqgchv", "output": "1\nhv" }, { "input": "iosdwvzerqfi", "output": "9\ner\nerq\nfi\nqfi\nrq\nvz\nvze\nze\nzer" }, { "input": "oawtxikrpvfuzugjweki", "output": "25\neki\nfu\nfuz\ngj\ngjw\nik\nikr\njw\njwe\nki\nkr\nkrp\npv\npvf\nrp\nrpv\nug\nugj\nuz\nuzu\nvf\nvfu\nwe\nzu\nzug" }, { "input": "abcdexyzzzz", "output": "5\nxyz\nyz\nyzz\nzz\nzzz" }, { "input": "affviytdmexpwfqplpyrlniprbdphrcwlboacoqec", "output": "67\nac\naco\nbd\nbdp\nbo\nboa\nco\ncoq\ncw\ncwl\ndm\ndme\ndp\ndph\nec\nex\nexp\nfq\nfqp\nhr\nhrc\nip\nipr\nlb\nlbo\nln\nlni\nlp\nlpy\nme\nmex\nni\nnip\noa\noac\noq\nph\nphr\npl\nplp\npr\nprb\npw\npwf\npy\npyr\nqec\nqp\nqpl\nrb\nrbd\nrc\nrcw\nrl\nrln\ntd\ntdm\nwf\nwfq\nwl\nwlb\nxp\nxpw\nyr\nyrl\nyt\nytd" }, { "input": "lmnxtobrknqjvnzwadpccrlvisxyqbxxmghvl", "output": "59\nad\nadp\nbr\nbrk\nbx\nbxx\ncc\nccr\ncr\ncrl\ndp\ndpc\ngh\nhvl\nis\nisx\njv\njvn\nkn\nknq\nlv\nlvi\nmg\nmgh\nnq\nnqj\nnz\nnzw\nob\nobr\npc\npcc\nqb\nqbx\nqj\nqjv\nrk\nrkn\nrl\nrlv\nsx\nsxy\nvi\nvis\nvl\nvn\nvnz\nwa\nwad\nxm\nxmg\nxx\nxxm\nxy\nxyq\nyq\nyqb\nzw\nzwa" }, { "input": "tbdbdpkluawodlrwldjgplbiylrhuywkhafbkiuoppzsjxwbaqqiwagprqtoauowtaexrhbmctcxwpmplkyjnpwukzwqrqpv", "output": "170\nae\naex\naf\nafb\nag\nagp\naq\naqq\nau\nauo\naw\nawo\nba\nbaq\nbi\nbiy\nbk\nbki\nbm\nbmc\nct\nctc\ncx\ncxw\ndj\ndjg\ndl\ndlr\nex\nexr\nfb\nfbk\ngp\ngpl\ngpr\nha\nhaf\nhb\nhbm\nhu\nhuy\niu\niuo\niw\niwa\niy\niyl\njg\njgp\njn\njnp\njx\njxw\nkh\nkha\nki\nkiu\nkl\nklu\nky\nkyj\nkz\nkzw\nlb\nlbi\nld\nldj\nlk\nlky\nlr\nlrh\nlrw\nlu\nlua\nmc\nmct\nmp\nmpl\nnp\nnpw\noa\noau\nod\nodl\nop\nopp\now\nowt\npk\npkl\npl\nplb\nplk\npm\npmp\npp\nppz\npr\nprq\npv\npw\npwu\npz\npzs\nqi\nqiw\nqpv\nqq\nqqi\nqr\nqrq\nqt\nq..." }, { "input": "caqmjjtwmqxytcsawfufvlofqcqdwnyvywvbbhmpzqwqqxieptiaguwvqdrdftccsglgfezrzhstjcxdknftpyslyqdmkwdolwbusyrgyndqllgesktvgarpfkiglxgtcfepclqhgfbfmkymsszrtynlxbosmrvntsqwccdtahkpnelwiqn", "output": "323\nag\nagu\nah\nahk\nar\narp\naw\nawf\nbb\nbbh\nbf\nbfm\nbh\nbhm\nbo\nbos\nbu\nbus\ncc\nccd\nccs\ncd\ncdt\ncf\ncfe\ncl\nclq\ncq\ncqd\ncs\ncsa\ncsg\ncx\ncxd\ndf\ndft\ndk\ndkn\ndm\ndmk\ndo\ndol\ndq\ndql\ndr\ndrd\ndt\ndta\ndw\ndwn\nel\nelw\nep\nepc\nept\nes\nesk\nez\nezr\nfb\nfbf\nfe\nfep\nfez\nfk\nfki\nfm\nfmk\nfq\nfqc\nft\nftc\nftp\nfu\nfuf\nfv\nfvl\nga\ngar\nge\nges\ngf\ngfb\ngfe\ngl\nglg\nglx\ngt\ngtc\ngu\nguw\ngy\ngyn\nhg\nhgf\nhk\nhkp\nhm\nhmp\nhs\nhst\nia\niag\nie\niep\nig\nigl\niqn\njc\njcx\njt\njtw..." }, { "input": "prntaxhysjfcfmrjngdsitlguahtpnwgbaxptubgpwcfxqehrulbxfcjssgocqncscduvyvarvwxzvmjoatnqfsvsilubexmwugedtzavyamqjqtkxzuslielibjnvkpvyrbndehsqcaqzcrmomqqwskwcypgqoawxdutnxmeivnfpzwvxiyscbfnloqjhjacsfnkfmbhgzpujrqdbaemjsqphokkiplblbflvadcyykcqrdohfasstobwrobslaofbasylwiizrpozvhtwyxtzl", "output": "505\nac\nacs\nad\nadc\nae\naem\nah\naht\nam\namq\nao\naof\naq\naqz\nar\narv\nas\nass\nasy\nat\natn\nav\navy\naw\nawx\nax\naxp\nba\nbae\nbas\nbax\nbe\nbex\nbf\nbfl\nbfn\nbg\nbgp\nbh\nbhg\nbj\nbjn\nbl\nblb\nbn\nbnd\nbs\nbsl\nbw\nbwr\nbx\nbxf\nca\ncaq\ncb\ncbf\ncd\ncdu\ncf\ncfm\ncfx\ncj\ncjs\ncq\ncqn\ncqr\ncr\ncrm\ncs\ncsc\ncsf\ncy\ncyp\ncyy\ndb\ndba\ndc\ndcy\nde\ndeh\ndo\ndoh\nds\ndsi\ndt\ndtz\ndu\ndut\nduv\ned\nedt\neh\nehr\nehs\nei\neiv\nel\neli\nem\nemj\nex\nexm\nfa\nfas\nfb\nfba\nfc\nfcf\nfcj\nfl\nflv\nf..." }, { "input": "gvtgnjyfvnuhagulgmjlqzpvxsygmikofsnvkuplnkxeibnicygpvfvtebppadpdnrxjodxdhxqceaulbfxogwrigstsjudhkgwkhseuwngbppisuzvhzzxxbaggfngmevksbrntpprxvcczlalutdzhwmzbalkqmykmodacjrmwhwugyhwlrbnqxsznldmaxpndwmovcolowxhj", "output": "375\nac\nacj\nad\nadp\nag\nagg\nagu\nal\nalk\nalu\nau\naul\nax\naxp\nba\nbag\nbal\nbf\nbfx\nbn\nbni\nbnq\nbp\nbpp\nbr\nbrn\ncc\nccz\nce\ncea\ncj\ncjr\nco\ncol\ncy\ncyg\ncz\nczl\nda\ndac\ndh\ndhk\ndhx\ndm\ndma\ndn\ndnr\ndp\ndpd\ndw\ndwm\ndx\ndxd\ndz\ndzh\nea\neau\neb\nebp\nei\neib\neu\neuw\nev\nevk\nfn\nfng\nfs\nfsn\nfv\nfvn\nfvt\nfx\nfxo\ngb\ngbp\ngf\ngfn\ngg\nggf\ngm\ngme\ngmi\ngmj\ngp\ngpv\ngs\ngst\ngu\ngul\ngw\ngwk\ngwr\ngy\ngyh\nha\nhag\nhj\nhk\nhkg\nhs\nhse\nhw\nhwl\nhwm\nhwu\nhx\nhxq\nhz\nhzz\nib\nib..." }, { "input": "topqexoicgzjmssuxnswdhpwbsqwfhhziwqibjgeepcvouhjezlomobgireaxaceppoxfxvkwlvgwtjoiplihbpsdhczddwfvcbxqqmqtveaunshmobdlkmmfyajjlkhxnvfmibtbbqswrhcfwytrccgtnlztkddrevkfovunuxtzhhhnorecyfgmlqcwjfjtqegxagfiuqtpjpqlwiefofpatxuqxvikyynncsueynmigieototnbcwxavlbgeqao", "output": "462\nac\nace\nag\nagf\naj\najj\nao\nat\natx\nau\naun\nav\navl\nax\naxa\nbb\nbbq\nbc\nbcw\nbd\nbdl\nbg\nbge\nbgi\nbj\nbjg\nbp\nbps\nbq\nbqs\nbs\nbsq\nbt\nbtb\nbx\nbxq\ncb\ncbx\ncc\nccg\nce\ncep\ncf\ncfw\ncg\ncgt\ncgz\ncs\ncsu\ncv\ncvo\ncw\ncwj\ncwx\ncy\ncyf\ncz\nczd\ndd\nddr\nddw\ndh\ndhc\ndhp\ndl\ndlk\ndr\ndre\ndw\ndwf\nea\neau\neax\nec\necy\nee\neep\nef\nefo\neg\negx\neo\neot\nep\nepc\nepp\neq\nev\nevk\ney\neyn\nez\nezl\nfg\nfgm\nfh\nfhh\nfi\nfiu\nfj\nfjt\nfm\nfmi\nfo\nfof\nfov\nfp\nfpa\nfv\nfvc\nfw\nfwy\n..." }, { "input": "lcrjhbybgamwetyrppxmvvxiyufdkcotwhmptefkqxjhrknjdponulsynpkgszhbkeinpnjdonjfwzbsaweqwlsvuijauwezfydktfljxgclpxpknhygdqyiapvzudyyqomgnsrdhhxhsrdfrwnxdolkmwmw", "output": "276\nam\namw\nap\napv\nau\nauw\naw\nawe\nbg\nbga\nbk\nbke\nbs\nbsa\nby\nbyb\ncl\nclp\nco\ncot\ndf\ndfr\ndh\ndhh\ndk\ndkc\ndkt\ndo\ndol\ndon\ndp\ndpo\ndq\ndqy\ndy\ndyy\nef\nefk\nei\nein\neq\neqw\net\nety\nez\nezf\nfd\nfdk\nfk\nfkq\nfl\nflj\nfr\nfrw\nfw\nfwz\nfy\nfyd\nga\ngam\ngc\ngcl\ngd\ngdq\ngn\ngns\ngs\ngsz\nhb\nhbk\nhh\nhhx\nhm\nhmp\nhr\nhrk\nhs\nhsr\nhx\nhxh\nhy\nhyg\nia\niap\nij\nija\nin\ninp\niy\niyu\nja\njau\njd\njdo\njdp\njf\njfw\njh\njhr\njx\njxg\nkc\nkco\nke\nkei\nkg\nkgs\nkm\nkmw\nkn\nknh\nknj\n..." }, { "input": "hzobjysjhbebobkoror", "output": "20\nbe\nbeb\nbko\nbo\nbob\neb\nebo\nhb\nhbe\njh\njhb\nko\nkor\nob\nor\nror\nsj\nsjh\nys\nysj" }, { "input": "safgmgpzljarfswowdxqhuhypxcmiddyvehjtnlflzknznrukdsbatxoytzxkqngopeipbythhbhfkvlcdxwqrxumbtbgiosjnbeorkzsrfarqofsrcwsfpyheaszjpkjysrcxbzebkxzovdchhososo", "output": "274\nar\narf\narq\nas\nasz\nat\natx\nba\nbat\nbe\nbeo\nbg\nbgi\nbh\nbhf\nbk\nbkx\nbt\nbtb\nby\nbyt\nbz\nbze\ncd\ncdx\nch\nchh\ncm\ncmi\ncw\ncws\ncx\ncxb\ndc\ndch\ndd\nddy\nds\ndsb\ndx\ndxq\ndxw\ndy\ndyv\nea\neas\neb\nebk\neh\nehj\nei\neip\neo\neor\nfa\nfar\nfk\nfkv\nfl\nflz\nfp\nfpy\nfs\nfsr\nfsw\ngi\ngio\ngo\ngop\ngp\ngpz\nhb\nhbh\nhe\nhea\nhf\nhfk\nhh\nhhb\nhj\nhjt\nhos\nhu\nhuh\nhy\nhyp\nid\nidd\nio\nios\nip\nipb\nja\njar\njn\njnb\njp\njpk\njt\njtn\njy\njys\nkd\nkds\nkj\nkjy\nkn\nknz\nkq\nkqn\nkv\nkvl\n..." }, { "input": "glaoyryxrgsysy", "output": "10\ngs\ngsy\nrgs\nry\nryx\nsy\nxr\nysy\nyx\nyxr" }, { "input": "aaaaaxyxxxx", "output": "5\nxx\nxxx\nxyx\nyx\nyxx" }, { "input": "aaaaax", "output": "0" }, { "input": "aaaaaxx", "output": "1\nxx" }, { "input": "aaaaaaa", "output": "1\naa" }, { "input": "aaaaaxxx", "output": "2\nxx\nxxx" }, { "input": "aaaaayxx", "output": "2\nxx\nyxx" }, { "input": "aaaaaxyz", "output": "2\nxyz\nyz" }, { "input": "aaaaaxyxy", "output": "2\nxy\nyxy" }, { "input": "aaaxyyxyy", "output": "3\nxyy\nyx\nyy" }, { "input": "aaaaaxxxxxx", "output": "2\nxx\nxxx" }, { "input": "aaaaaxxxxx", "output": "2\nxx\nxxx" }, { "input": "aaaaaxyzxyxy", "output": "5\nxy\nyxy\nyzx\nzx\nzxy" }, { "input": "aaaaadddgggg", "output": "6\ndd\nddg\ndg\ndgg\ngg\nggg" }, { "input": "abcdeabzzzzzzzz", "output": "5\nab\nabz\nbz\nzz\nzzz" }, { "input": "bbbbbccaaaaaa", "output": "4\naa\naaa\nca\ncca" }, { "input": "xxxxxababc", "output": "5\nab\naba\nabc\nba\nbc" }, { "input": "dddddaabbbbbb", "output": "4\naab\nab\nbb\nbbb" }, { "input": "xxxxxababe", "output": "5\nab\naba\nabe\nba\nbe" }, { "input": "aaaaababaaaaaaaaaaaa", "output": "6\naa\naaa\nab\nba\nbaa\nbab" } ]
1,663,992,865
2,147,483,647
PyPy 3-64
OK
TESTS
48
77
5,324,800
''' 给定字符串,求所有“词根长度>4,从末尾开始往前、长度为2或3、相邻不重复的子串后缀”。 相当于用水壶盖从后往前圈饺子皮,每次可选尺寸为2或3的盖子,连续两个饺子皮相同时停止。 ''' P,s=print,input();stk,d,z=[(len(s),0)],set(),set() while stk: i,jr=stk.pop();r=i+jr for jl in (2,3): l=i-jl;k=(l,jl) if k not in d and l>=5 and s[l:i]!=s[i:r]: z.add(s[l:i]);d.add(k);stk+=[k] P(len(z)),P('\n'.join(sorted(z)))
Title: Reberland Linguistics Time Limit: None seconds Memory Limit: None megabytes Problem Description: First-rate specialists graduate from Berland State Institute of Peace and Friendship. You are one of the most talented students in this university. The education is not easy because you need to have fundamental knowledge in different areas, which sometimes are not related to each other. For example, you should know linguistics very well. You learn a structure of Reberland language as foreign language. In this language words are constructed according to the following rules. First you need to choose the "root" of the word — some string which has more than 4 letters. Then several strings with the length 2 or 3 symbols are appended to this word. The only restriction — it is not allowed to append the same string twice in a row. All these strings are considered to be suffixes of the word (this time we use word "suffix" to describe a morpheme but not the few last characters of the string as you may used to). Here is one exercise that you have found in your task list. You are given the word *s*. Find all distinct strings with the length 2 or 3, which can be suffixes of this word according to the word constructing rules in Reberland language. Two strings are considered distinct if they have different length or there is a position in which corresponding characters do not match. Let's look at the example: the word *abacabaca* is given. This word can be obtained in the following ways: , where the root of the word is overlined, and suffixes are marked by "corners". Thus, the set of possible suffixes for this word is {*aca*,<=*ba*,<=*ca*}. Input Specification: The only line contains a string *s* (5<=≤<=|*s*|<=≤<=104) consisting of lowercase English letters. Output Specification: On the first line print integer *k* — a number of distinct possible suffixes. On the next *k* lines print suffixes. Print suffixes in lexicographical (alphabetical) order. Demo Input: ['abacabaca\n', 'abaca\n'] Demo Output: ['3\naca\nba\nca\n', '0\n'] Note: The first test was analysed in the problem statement. In the second example the length of the string equals 5. The length of the root equals 5, so no string can be used as a suffix.
```python ''' 给定字符串,求所有“词根长度>4,从末尾开始往前、长度为2或3、相邻不重复的子串后缀”。 相当于用水壶盖从后往前圈饺子皮,每次可选尺寸为2或3的盖子,连续两个饺子皮相同时停止。 ''' P,s=print,input();stk,d,z=[(len(s),0)],set(),set() while stk: i,jr=stk.pop();r=i+jr for jl in (2,3): l=i-jl;k=(l,jl) if k not in d and l>=5 and s[l:i]!=s[i:r]: z.add(s[l:i]);d.add(k);stk+=[k] P(len(z)),P('\n'.join(sorted(z))) ```
3
59
A
Word
PROGRAMMING
800
[ "implementation", "strings" ]
A. Word
2
256
Vasya is very upset that many people on the Net mix uppercase and lowercase letters in one word. That's why he decided to invent an extension for his favorite browser that would change the letters' register in every word so that it either only consisted of lowercase letters or, vice versa, only of uppercase ones. At that as little as possible letters should be changed in the word. For example, the word HoUse must be replaced with house, and the word ViP — with VIP. If a word contains an equal number of uppercase and lowercase letters, you should replace all the letters with lowercase ones. For example, maTRIx should be replaced by matrix. Your task is to use the given method on one given word.
The first line contains a word *s* — it consists of uppercase and lowercase Latin letters and possesses the length from 1 to 100.
Print the corrected word *s*. If the given word *s* has strictly more uppercase letters, make the word written in the uppercase register, otherwise - in the lowercase one.
[ "HoUse\n", "ViP\n", "maTRIx\n" ]
[ "house\n", "VIP\n", "matrix\n" ]
none
500
[ { "input": "HoUse", "output": "house" }, { "input": "ViP", "output": "VIP" }, { "input": "maTRIx", "output": "matrix" }, { "input": "BNHWpnpawg", "output": "bnhwpnpawg" }, { "input": "VTYGP", "output": "VTYGP" }, { "input": "CHNenu", "output": "chnenu" }, { "input": "ERPZGrodyu", "output": "erpzgrodyu" }, { "input": "KSXBXWpebh", "output": "KSXBXWPEBH" }, { "input": "qvxpqullmcbegsdskddortcvxyqlbvxmmkhevovnezubvpvnrcajpxraeaxizgaowtfkzywvhnbgzsxbhkaipcmoumtikkiyyaiv", "output": "qvxpqullmcbegsdskddortcvxyqlbvxmmkhevovnezubvpvnrcajpxraeaxizgaowtfkzywvhnbgzsxbhkaipcmoumtikkiyyaiv" }, { "input": "Amnhaxtaopjzrkqlbroiyipitndczpunwygstmzevgyjdzyanxkdqnvgkikfabwouwkkbzuiuvgvxgpizsvqsbwepktpdrgdkmfd", "output": "amnhaxtaopjzrkqlbroiyipitndczpunwygstmzevgyjdzyanxkdqnvgkikfabwouwkkbzuiuvgvxgpizsvqsbwepktpdrgdkmfd" }, { "input": "ISAGFJFARYFBLOPQDSHWGMCNKMFTLVFUGNJEWGWNBLXUIATXEkqiettmmjgydwcpafqrppdsrrrtguinqbgmzzfqwonkpgpcwenv", "output": "isagfjfaryfblopqdshwgmcnkmftlvfugnjewgwnblxuiatxekqiettmmjgydwcpafqrppdsrrrtguinqbgmzzfqwonkpgpcwenv" }, { "input": "XHRPXZEGHSOCJPICUIXSKFUZUPYTSGJSDIYBCMNMNBPNDBXLXBzhbfnqvwcffvrdhtickyqhupmcehlsyvncqmfhautvxudqdhgg", "output": "xhrpxzeghsocjpicuixskfuzupytsgjsdiybcmnmnbpndbxlxbzhbfnqvwcffvrdhtickyqhupmcehlsyvncqmfhautvxudqdhgg" }, { "input": "RJIQZMJCIMSNDBOHBRAWIENODSALETAKGKPYUFGVEFGCBRENZGAdkcetqjljtmttlonpekcovdzebzdkzggwfsxhapmjkdbuceak", "output": "RJIQZMJCIMSNDBOHBRAWIENODSALETAKGKPYUFGVEFGCBRENZGADKCETQJLJTMTTLONPEKCOVDZEBZDKZGGWFSXHAPMJKDBUCEAK" }, { "input": "DWLWOBHNMMGTFOLFAECKBRNNGLYLYDXTGTVRLMEESZOIUATZZZXUFUZDLSJXMEVRTESSFBWLNZZCLCQWEVNNUCXYVHNGNXHCBDFw", "output": "DWLWOBHNMMGTFOLFAECKBRNNGLYLYDXTGTVRLMEESZOIUATZZZXUFUZDLSJXMEVRTESSFBWLNZZCLCQWEVNNUCXYVHNGNXHCBDFW" }, { "input": "NYCNHJWGBOCOTSPETKKHVWFGAQYNHOVJWJHCIEFOUQZXOYUIEQDZALFKTEHTVDBVJMEUBJUBCMNVPWGDPNCHQHZJRCHYRFPVIGUB", "output": "NYCNHJWGBOCOTSPETKKHVWFGAQYNHOVJWJHCIEFOUQZXOYUIEQDZALFKTEHTVDBVJMEUBJUBCMNVPWGDPNCHQHZJRCHYRFPVIGUB" }, { "input": "igxoixiecetohtgjgbqzvlaobkhstejxdklghowtvwunnnvauriohuspsdmpzckprwajyxldoyckgjivjpmbfqtszmtocovxwge", "output": "igxoixiecetohtgjgbqzvlaobkhstejxdklghowtvwunnnvauriohuspsdmpzckprwajyxldoyckgjivjpmbfqtszmtocovxwge" }, { "input": "Ykkekrsqolzryiwsmdlnbmfautxxxauoojrddvwklgnlyrfcvhorrzbmtcrvpaypqhcffdqhwziipyyskcmztjprjqvmzzqhqnw", "output": "ykkekrsqolzryiwsmdlnbmfautxxxauoojrddvwklgnlyrfcvhorrzbmtcrvpaypqhcffdqhwziipyyskcmztjprjqvmzzqhqnw" }, { "input": "YQOMLKYAORUQQUCQZCDYMIVDHGWZFFRMUVTAWCHERFPMNRYRIkgqrciokgajamehmcxgerpudvsqyonjonsxgbnefftzmygncks", "output": "yqomlkyaoruqqucqzcdymivdhgwzffrmuvtawcherfpmnryrikgqrciokgajamehmcxgerpudvsqyonjonsxgbnefftzmygncks" }, { "input": "CDOZDPBVVVHNBJVBYHEOXWFLJKRWJCAJMIFCOZWWYFKVWOGTVJcuusigdqfkumewjtdyitveeiaybwrhomrwmpdipjwiuxfnwuz", "output": "CDOZDPBVVVHNBJVBYHEOXWFLJKRWJCAJMIFCOZWWYFKVWOGTVJCUUSIGDQFKUMEWJTDYITVEEIAYBWRHOMRWMPDIPJWIUXFNWUZ" }, { "input": "WHIUVEXHVOOIJIDVJVPQUBJMEVPMPDKQWJKFBZSGSKUXMIPPMJWuckzcpxosodcjaaakvlxpbiigsiauviilylnnqlyucziihqg", "output": "WHIUVEXHVOOIJIDVJVPQUBJMEVPMPDKQWJKFBZSGSKUXMIPPMJWUCKZCPXOSODCJAAAKVLXPBIIGSIAUVIILYLNNQLYUCZIIHQG" }, { "input": "VGHUNFOXKETUYMZDJNGTAOIOANYXSGYNFOGOFFLDAWEUKYFOZXCJTCAFXZYLQZERYZLRSQXYQGAPCSUDPMEYTNCTTTMFAGVDWBO", "output": "VGHUNFOXKETUYMZDJNGTAOIOANYXSGYNFOGOFFLDAWEUKYFOZXCJTCAFXZYLQZERYZLRSQXYQGAPCSUDPMEYTNCTTTMFAGVDWBO" }, { "input": "EDUANHCQDOCJHFONTTSWBUJSTTIXBIXMAIUFSGFLXWAYIURTVAVZPYQDLAWIGCLMPHXCEFCJPFAAHXVNGQUFNHADAIUAZIDMHDd", "output": "EDUANHCQDOCJHFONTTSWBUJSTTIXBIXMAIUFSGFLXWAYIURTVAVZPYQDLAWIGCLMPHXCEFCJPFAAHXVNGQUFNHADAIUAZIDMHDD" }, { "input": "EBWOVSNLYTWWXrnovgugogtjahnmatomubebyxakas", "output": "ebwovsnlytwwxrnovgugogtjahnmatomubebyxakas" }, { "input": "AORNNDKTRLRVGDPXJKXFTPFpopuzrlqumrxssskvbm", "output": "AORNNDKTRLRVGDPXJKXFTPFPOPUZRLQUMRXSSSKVBM" }, { "input": "DBBZJCWQEVGYHEEUHJAWRHBDPsnplijbwtdibqrrheebfxqcvn", "output": "dbbzjcwqevgyheeuhjawrhbdpsnplijbwtdibqrrheebfxqcvn" }, { "input": "t", "output": "t" }, { "input": "N", "output": "N" }, { "input": "kv", "output": "kv" }, { "input": "Ur", "output": "ur" }, { "input": "CN", "output": "CN" } ]
1,675,090,935
2,147,483,647
Python 3
OK
TESTS
30
92
0
a = input() l_a = [i for i in a if i.islower()] if len(a) % 2 == 0: if len(a) // 2 <= len(l_a): a = a.lower() else: a = a.upper() elif len (a) % 2 != 0: if len(a) // 2 ++ 1 <= len(l_a): a = a.lower() else: a = a.upper() print(a)
Title: Word Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: Vasya is very upset that many people on the Net mix uppercase and lowercase letters in one word. That's why he decided to invent an extension for his favorite browser that would change the letters' register in every word so that it either only consisted of lowercase letters or, vice versa, only of uppercase ones. At that as little as possible letters should be changed in the word. For example, the word HoUse must be replaced with house, and the word ViP — with VIP. If a word contains an equal number of uppercase and lowercase letters, you should replace all the letters with lowercase ones. For example, maTRIx should be replaced by matrix. Your task is to use the given method on one given word. Input Specification: The first line contains a word *s* — it consists of uppercase and lowercase Latin letters and possesses the length from 1 to 100. Output Specification: Print the corrected word *s*. If the given word *s* has strictly more uppercase letters, make the word written in the uppercase register, otherwise - in the lowercase one. Demo Input: ['HoUse\n', 'ViP\n', 'maTRIx\n'] Demo Output: ['house\n', 'VIP\n', 'matrix\n'] Note: none
```python a = input() l_a = [i for i in a if i.islower()] if len(a) % 2 == 0: if len(a) // 2 <= len(l_a): a = a.lower() else: a = a.upper() elif len (a) % 2 != 0: if len(a) // 2 ++ 1 <= len(l_a): a = a.lower() else: a = a.upper() print(a) ```
3.977
151
A
Soft Drinking
PROGRAMMING
800
[ "implementation", "math" ]
null
null
This winter is so cold in Nvodsk! A group of *n* friends decided to buy *k* bottles of a soft drink called "Take-It-Light" to warm up a bit. Each bottle has *l* milliliters of the drink. Also they bought *c* limes and cut each of them into *d* slices. After that they found *p* grams of salt. To make a toast, each friend needs *nl* milliliters of the drink, a slice of lime and *np* grams of salt. The friends want to make as many toasts as they can, provided they all drink the same amount. How many toasts can each friend make?
The first and only line contains positive integers *n*, *k*, *l*, *c*, *d*, *p*, *nl*, *np*, not exceeding 1000 and no less than 1. The numbers are separated by exactly one space.
Print a single integer — the number of toasts each friend can make.
[ "3 4 5 10 8 100 3 1\n", "5 100 10 1 19 90 4 3\n", "10 1000 1000 25 23 1 50 1\n" ]
[ "2\n", "3\n", "0\n" ]
A comment to the first sample: Overall the friends have 4 * 5 = 20 milliliters of the drink, it is enough to make 20 / 3 = 6 toasts. The limes are enough for 10 * 8 = 80 toasts and the salt is enough for 100 / 1 = 100 toasts. However, there are 3 friends in the group, so the answer is *min*(6, 80, 100) / 3 = 2.
500
[ { "input": "3 4 5 10 8 100 3 1", "output": "2" }, { "input": "5 100 10 1 19 90 4 3", "output": "3" }, { "input": "10 1000 1000 25 23 1 50 1", "output": "0" }, { "input": "1 7 4 5 5 8 3 2", "output": "4" }, { "input": "2 3 3 5 5 10 1 3", "output": "1" }, { "input": "2 6 4 5 6 5 1 3", "output": "0" }, { "input": "1 7 3 5 3 6 2 1", "output": "6" }, { "input": "2 4 5 4 5 7 3 2", "output": "1" }, { "input": "2 3 6 5 7 8 2 1", "output": "4" }, { "input": "1 4 5 5 3 10 3 1", "output": "6" }, { "input": "1 4 6 7 3 5 1 3", "output": "1" }, { "input": "1 6 5 5 5 8 3 1", "output": "8" }, { "input": "1 7 5 3 3 9 2 1", "output": "9" }, { "input": "3 5 3 7 6 10 3 1", "output": "1" }, { "input": "3 6 3 5 3 6 3 1", "output": "2" }, { "input": "1 7 5 5 5 5 2 2", "output": "2" }, { "input": "2 5 3 5 6 9 2 1", "output": "3" }, { "input": "3 4 3 5 3 6 2 1", "output": "2" }, { "input": "1 5 5 4 7 6 3 1", "output": "6" }, { "input": "2 3 7 6 5 9 3 1", "output": "3" }, { "input": "2 6 5 3 3 8 1 1", "output": "4" }, { "input": "2 4 7 3 4 10 2 1", "output": "5" }, { "input": "1 1000 1000 1000 1000 1000 1 1", "output": "1000" }, { "input": "17 1000 1000 1000 1000 1000 3 7", "output": "8" }, { "input": "115 1000 1000 1000 1000 1000 17 15", "output": "0" }, { "input": "1 587 981 1 2 1 1 1", "output": "1" }, { "input": "1 1 2 1 2 2 1 1", "output": "2" } ]
1,696,082,418
2,147,483,647
PyPy 3-64
WRONG_ANSWER
TESTS
8
124
0
n, k, l, c, d, p, nl, np = [int(i) for i in input().split(" ")] ml = (k*l)/3 limes = c*d salt = p/np print(int(min(ml, limes, salt)//n))
Title: Soft Drinking Time Limit: None seconds Memory Limit: None megabytes Problem Description: This winter is so cold in Nvodsk! A group of *n* friends decided to buy *k* bottles of a soft drink called "Take-It-Light" to warm up a bit. Each bottle has *l* milliliters of the drink. Also they bought *c* limes and cut each of them into *d* slices. After that they found *p* grams of salt. To make a toast, each friend needs *nl* milliliters of the drink, a slice of lime and *np* grams of salt. The friends want to make as many toasts as they can, provided they all drink the same amount. How many toasts can each friend make? Input Specification: The first and only line contains positive integers *n*, *k*, *l*, *c*, *d*, *p*, *nl*, *np*, not exceeding 1000 and no less than 1. The numbers are separated by exactly one space. Output Specification: Print a single integer — the number of toasts each friend can make. Demo Input: ['3 4 5 10 8 100 3 1\n', '5 100 10 1 19 90 4 3\n', '10 1000 1000 25 23 1 50 1\n'] Demo Output: ['2\n', '3\n', '0\n'] Note: A comment to the first sample: Overall the friends have 4 * 5 = 20 milliliters of the drink, it is enough to make 20 / 3 = 6 toasts. The limes are enough for 10 * 8 = 80 toasts and the salt is enough for 100 / 1 = 100 toasts. However, there are 3 friends in the group, so the answer is *min*(6, 80, 100) / 3 = 2.
```python n, k, l, c, d, p, nl, np = [int(i) for i in input().split(" ")] ml = (k*l)/3 limes = c*d salt = p/np print(int(min(ml, limes, salt)//n)) ```
0
1
A
Theatre Square
PROGRAMMING
1,000
[ "math" ]
A. Theatre Square
1
256
Theatre Square in the capital city of Berland has a rectangular shape with the size *n*<=×<=*m* meters. On the occasion of the city's anniversary, a decision was taken to pave the Square with square granite flagstones. Each flagstone is of the size *a*<=×<=*a*. What is the least number of flagstones needed to pave the Square? It's allowed to cover the surface larger than the Theatre Square, but the Square has to be covered. It's not allowed to break the flagstones. The sides of flagstones should be parallel to the sides of the Square.
The input contains three positive integer numbers in the first line: *n*,<=<=*m* and *a* (1<=≤<=<=*n*,<=*m*,<=*a*<=≤<=109).
Write the needed number of flagstones.
[ "6 6 4\n" ]
[ "4\n" ]
none
0
[ { "input": "6 6 4", "output": "4" }, { "input": "1 1 1", "output": "1" }, { "input": "2 1 1", "output": "2" }, { "input": "1 2 1", "output": "2" }, { "input": "2 2 1", "output": "4" }, { "input": "2 1 2", "output": "1" }, { "input": "1 1 3", "output": "1" }, { "input": "2 3 4", "output": "1" }, { "input": "1000000000 1000000000 1", "output": "1000000000000000000" }, { "input": "12 13 4", "output": "12" }, { "input": "222 332 5", "output": "3015" }, { "input": "1000 1000 10", "output": "10000" }, { "input": "1001 1000 10", "output": "10100" }, { "input": "100 10001 1000000000", "output": "1" }, { "input": "1000000000 1000000000 1000000000", "output": "1" }, { "input": "1000000000 1000000000 999999999", "output": "4" }, { "input": "1000000000 1000000000 192", "output": "27126743055556" }, { "input": "1000000000 987654321 1", "output": "987654321000000000" }, { "input": "456784567 1000000000 51", "output": "175618850864484" }, { "input": "39916800 134217728 40320", "output": "3295710" } ]
1,686,157,516
2,147,483,647
PyPy 3-64
COMPILATION_ERROR
TESTS
0
0
0
import math n = input() l = [0]*2 count = -1 for i in range(len(n)): if (n[i] == " "): count += 1 l[count]= i x = float(n[0:l[0]]) y = float(n[l[0]+1: l[1]]) z = float(n[1]+1:len(n)) if (x * y) < (z * 2): print(l) elif (z == 1): print(int((x * y) / z)) else: if (x == y): if int(x) % int(z) == 0: print(int(ceil((x * y) / (z * z)))) else: print(int(((x + (z - (int(x))))) * (y + (z - int(y) % int(z)))) / (z * z)) else: if int(x) % int(z) == 0 and int(y) % int(z) != 0: print(int(((y + (z - int(x) % int(z)))) * x) / (z * z)) elif int(x) % int(z) != 0 and int(y) % int(z) == 0: print(int(((x + (z - (int(x) % int(z)))) * y) / (z * z))) elif int(x) % int(z) != 0 and int(y) % int(z) != 0: print(int(((x + (z - (int(x) % int(z)))) * (y + (z - (int(y) % int(z))))) / (z * z)))
Title: Theatre Square Time Limit: 1 seconds Memory Limit: 256 megabytes Problem Description: Theatre Square in the capital city of Berland has a rectangular shape with the size *n*<=×<=*m* meters. On the occasion of the city's anniversary, a decision was taken to pave the Square with square granite flagstones. Each flagstone is of the size *a*<=×<=*a*. What is the least number of flagstones needed to pave the Square? It's allowed to cover the surface larger than the Theatre Square, but the Square has to be covered. It's not allowed to break the flagstones. The sides of flagstones should be parallel to the sides of the Square. Input Specification: The input contains three positive integer numbers in the first line: *n*,<=<=*m* and *a* (1<=≤<=<=*n*,<=*m*,<=*a*<=≤<=109). Output Specification: Write the needed number of flagstones. Demo Input: ['6 6 4\n'] Demo Output: ['4\n'] Note: none
```python import math n = input() l = [0]*2 count = -1 for i in range(len(n)): if (n[i] == " "): count += 1 l[count]= i x = float(n[0:l[0]]) y = float(n[l[0]+1: l[1]]) z = float(n[1]+1:len(n)) if (x * y) < (z * 2): print(l) elif (z == 1): print(int((x * y) / z)) else: if (x == y): if int(x) % int(z) == 0: print(int(ceil((x * y) / (z * z)))) else: print(int(((x + (z - (int(x))))) * (y + (z - int(y) % int(z)))) / (z * z)) else: if int(x) % int(z) == 0 and int(y) % int(z) != 0: print(int(((y + (z - int(x) % int(z)))) * x) / (z * z)) elif int(x) % int(z) != 0 and int(y) % int(z) == 0: print(int(((x + (z - (int(x) % int(z)))) * y) / (z * z))) elif int(x) % int(z) != 0 and int(y) % int(z) != 0: print(int(((x + (z - (int(x) % int(z)))) * (y + (z - (int(y) % int(z))))) / (z * z))) ```
-1
501
A
Contest
PROGRAMMING
900
[ "implementation" ]
null
null
Misha and Vasya participated in a Codeforces contest. Unfortunately, each of them solved only one problem, though successfully submitted it at the first attempt. Misha solved the problem that costs *a* points and Vasya solved the problem that costs *b* points. Besides, Misha submitted the problem *c* minutes after the contest started and Vasya submitted the problem *d* minutes after the contest started. As you know, on Codeforces the cost of a problem reduces as a round continues. That is, if you submit a problem that costs *p* points *t* minutes after the contest started, you get points. Misha and Vasya are having an argument trying to find out who got more points. Help them to find out the truth.
The first line contains four integers *a*, *b*, *c*, *d* (250<=≤<=*a*,<=*b*<=≤<=3500, 0<=≤<=*c*,<=*d*<=≤<=180). It is guaranteed that numbers *a* and *b* are divisible by 250 (just like on any real Codeforces round).
Output on a single line: "Misha" (without the quotes), if Misha got more points than Vasya. "Vasya" (without the quotes), if Vasya got more points than Misha. "Tie" (without the quotes), if both of them got the same number of points.
[ "500 1000 20 30\n", "1000 1000 1 1\n", "1500 1000 176 177\n" ]
[ "Vasya\n", "Tie\n", "Misha\n" ]
none
500
[ { "input": "500 1000 20 30", "output": "Vasya" }, { "input": "1000 1000 1 1", "output": "Tie" }, { "input": "1500 1000 176 177", "output": "Misha" }, { "input": "1500 1000 74 177", "output": "Misha" }, { "input": "750 2500 175 178", "output": "Vasya" }, { "input": "750 1000 54 103", "output": "Tie" }, { "input": "2000 1250 176 130", "output": "Tie" }, { "input": "1250 1750 145 179", "output": "Tie" }, { "input": "2000 2000 176 179", "output": "Tie" }, { "input": "1500 1500 148 148", "output": "Tie" }, { "input": "2750 1750 134 147", "output": "Misha" }, { "input": "3250 250 175 173", "output": "Misha" }, { "input": "500 500 170 176", "output": "Misha" }, { "input": "250 1000 179 178", "output": "Vasya" }, { "input": "3250 1000 160 138", "output": "Misha" }, { "input": "3000 2000 162 118", "output": "Tie" }, { "input": "1500 1250 180 160", "output": "Tie" }, { "input": "1250 2500 100 176", "output": "Tie" }, { "input": "3500 3500 177 178", "output": "Tie" }, { "input": "3000 3250 16 34", "output": "Tie" }, { "input": "1750 3000 137 49", "output": "Vasya" }, { "input": "500 1500 179 71", "output": "Vasya" }, { "input": "1250 2000 101 180", "output": "Misha" }, { "input": "250 750 180 176", "output": "Vasya" }, { "input": "2250 2250 163 145", "output": "Vasya" }, { "input": "3000 3000 176 78", "output": "Vasya" }, { "input": "250 3500 8 178", "output": "Vasya" }, { "input": "1750 1250 179 180", "output": "Misha" }, { "input": "2750 1750 13 164", "output": "Misha" }, { "input": "1750 2250 178 53", "output": "Vasya" }, { "input": "2500 2750 73 179", "output": "Misha" }, { "input": "1000 3500 178 175", "output": "Vasya" }, { "input": "1000 500 7 162", "output": "Misha" }, { "input": "1000 250 175 48", "output": "Misha" }, { "input": "1750 500 166 177", "output": "Misha" }, { "input": "250 250 0 0", "output": "Tie" }, { "input": "250 3500 0 0", "output": "Vasya" }, { "input": "250 3500 0 180", "output": "Vasya" }, { "input": "3500 3500 180 180", "output": "Tie" }, { "input": "3500 250 0 180", "output": "Misha" } ]
1,577,636,657
2,147,483,647
PyPy 3
OK
TESTS
40
156
0
a,b,c,d=map(int,input().split()) ans,res=0,0 temp=max((3*a/10),a-(a/250)*c) res=max((3*b/10),b-(b/250)*d) if temp==res: print("Tie") elif temp<res: print("Vasya") else: print("Misha")
Title: Contest Time Limit: None seconds Memory Limit: None megabytes Problem Description: Misha and Vasya participated in a Codeforces contest. Unfortunately, each of them solved only one problem, though successfully submitted it at the first attempt. Misha solved the problem that costs *a* points and Vasya solved the problem that costs *b* points. Besides, Misha submitted the problem *c* minutes after the contest started and Vasya submitted the problem *d* minutes after the contest started. As you know, on Codeforces the cost of a problem reduces as a round continues. That is, if you submit a problem that costs *p* points *t* minutes after the contest started, you get points. Misha and Vasya are having an argument trying to find out who got more points. Help them to find out the truth. Input Specification: The first line contains four integers *a*, *b*, *c*, *d* (250<=≤<=*a*,<=*b*<=≤<=3500, 0<=≤<=*c*,<=*d*<=≤<=180). It is guaranteed that numbers *a* and *b* are divisible by 250 (just like on any real Codeforces round). Output Specification: Output on a single line: "Misha" (without the quotes), if Misha got more points than Vasya. "Vasya" (without the quotes), if Vasya got more points than Misha. "Tie" (without the quotes), if both of them got the same number of points. Demo Input: ['500 1000 20 30\n', '1000 1000 1 1\n', '1500 1000 176 177\n'] Demo Output: ['Vasya\n', 'Tie\n', 'Misha\n'] Note: none
```python a,b,c,d=map(int,input().split()) ans,res=0,0 temp=max((3*a/10),a-(a/250)*c) res=max((3*b/10),b-(b/250)*d) if temp==res: print("Tie") elif temp<res: print("Vasya") else: print("Misha") ```
3
1,005
D
Polycarp and Div 3
PROGRAMMING
1,500
[ "dp", "greedy", "number theory" ]
null
null
Polycarp likes numbers that are divisible by 3. He has a huge number $s$. Polycarp wants to cut from it the maximum number of numbers that are divisible by $3$. To do this, he makes an arbitrary number of vertical cuts between pairs of adjacent digits. As a result, after $m$ such cuts, there will be $m+1$ parts in total. Polycarp analyzes each of the obtained numbers and finds the number of those that are divisible by $3$. For example, if the original number is $s=3121$, then Polycarp can cut it into three parts with two cuts: $3|1|21$. As a result, he will get two numbers that are divisible by $3$. Polycarp can make an arbitrary number of vertical cuts, where each cut is made between a pair of adjacent digits. The resulting numbers cannot contain extra leading zeroes (that is, the number can begin with 0 if and only if this number is exactly one character '0'). For example, 007, 01 and 00099 are not valid numbers, but 90, 0 and 10001 are valid. What is the maximum number of numbers divisible by $3$ that Polycarp can obtain?
The first line of the input contains a positive integer $s$. The number of digits of the number $s$ is between $1$ and $2\cdot10^5$, inclusive. The first (leftmost) digit is not equal to 0.
Print the maximum number of numbers divisible by $3$ that Polycarp can get by making vertical cuts in the given number $s$.
[ "3121\n", "6\n", "1000000000000000000000000000000000\n", "201920181\n" ]
[ "2\n", "1\n", "33\n", "4\n" ]
In the first example, an example set of optimal cuts on the number is 3|1|21. In the second example, you do not need to make any cuts. The specified number 6 forms one number that is divisible by $3$. In the third example, cuts must be made between each pair of digits. As a result, Polycarp gets one digit 1 and $33$ digits 0. Each of the $33$ digits 0 forms a number that is divisible by $3$. In the fourth example, an example set of optimal cuts is 2|0|1|9|201|81. The numbers $0$, $9$, $201$ and $81$ are divisible by $3$.
0
[ { "input": "3121", "output": "2" }, { "input": "6", "output": "1" }, { "input": "1000000000000000000000000000000000", "output": "33" }, { "input": "201920181", "output": "4" }, { "input": "4", "output": "0" }, { "input": "10", "output": "1" }, { "input": "11", "output": "0" }, { "input": "12", "output": "1" }, { "input": "13", "output": "1" }, { "input": "31", "output": "1" }, { "input": "14139582796", "output": "6" }, { "input": "1670000", "output": "5" }, { "input": "604500", "output": "5" }, { "input": "40041", "output": "2" }, { "input": "10000170", "output": "5" } ]
1,645,795,420
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
2
31
0
import sys input = sys.stdin.readline def solve(s): num, s = s, str(s) ans = 0 curr = 0 n = len(s) for i in range(n): curr += int(s[i]) if curr % 3 == 0: curr = 0 ans += 1 print(ans) s = int(input()) solve(s)
Title: Polycarp and Div 3 Time Limit: None seconds Memory Limit: None megabytes Problem Description: Polycarp likes numbers that are divisible by 3. He has a huge number $s$. Polycarp wants to cut from it the maximum number of numbers that are divisible by $3$. To do this, he makes an arbitrary number of vertical cuts between pairs of adjacent digits. As a result, after $m$ such cuts, there will be $m+1$ parts in total. Polycarp analyzes each of the obtained numbers and finds the number of those that are divisible by $3$. For example, if the original number is $s=3121$, then Polycarp can cut it into three parts with two cuts: $3|1|21$. As a result, he will get two numbers that are divisible by $3$. Polycarp can make an arbitrary number of vertical cuts, where each cut is made between a pair of adjacent digits. The resulting numbers cannot contain extra leading zeroes (that is, the number can begin with 0 if and only if this number is exactly one character '0'). For example, 007, 01 and 00099 are not valid numbers, but 90, 0 and 10001 are valid. What is the maximum number of numbers divisible by $3$ that Polycarp can obtain? Input Specification: The first line of the input contains a positive integer $s$. The number of digits of the number $s$ is between $1$ and $2\cdot10^5$, inclusive. The first (leftmost) digit is not equal to 0. Output Specification: Print the maximum number of numbers divisible by $3$ that Polycarp can get by making vertical cuts in the given number $s$. Demo Input: ['3121\n', '6\n', '1000000000000000000000000000000000\n', '201920181\n'] Demo Output: ['2\n', '1\n', '33\n', '4\n'] Note: In the first example, an example set of optimal cuts on the number is 3|1|21. In the second example, you do not need to make any cuts. The specified number 6 forms one number that is divisible by $3$. In the third example, cuts must be made between each pair of digits. As a result, Polycarp gets one digit 1 and $33$ digits 0. Each of the $33$ digits 0 forms a number that is divisible by $3$. In the fourth example, an example set of optimal cuts is 2|0|1|9|201|81. The numbers $0$, $9$, $201$ and $81$ are divisible by $3$.
```python import sys input = sys.stdin.readline def solve(s): num, s = s, str(s) ans = 0 curr = 0 n = len(s) for i in range(n): curr += int(s[i]) if curr % 3 == 0: curr = 0 ans += 1 print(ans) s = int(input()) solve(s) ```
0
262
B
Roma and Changing Signs
PROGRAMMING
1,200
[ "greedy" ]
null
null
Roma works in a company that sells TVs. Now he has to prepare a report for the last year. Roma has got a list of the company's incomes. The list is a sequence that consists of *n* integers. The total income of the company is the sum of all integers in sequence. Roma decided to perform exactly *k* changes of signs of several numbers in the sequence. He can also change the sign of a number one, two or more times. The operation of changing a number's sign is the operation of multiplying this number by -1. Help Roma perform the changes so as to make the total income of the company (the sum of numbers in the resulting sequence) maximum. Note that Roma should perform exactly *k* changes.
The first line contains two integers *n* and *k* (1<=≤<=*n*,<=*k*<=≤<=105), showing, how many numbers are in the sequence and how many swaps are to be made. The second line contains a non-decreasing sequence, consisting of *n* integers *a**i* (|*a**i*|<=≤<=104). The numbers in the lines are separated by single spaces. Please note that the given sequence is sorted in non-decreasing order.
In the single line print the answer to the problem — the maximum total income that we can obtain after exactly *k* changes.
[ "3 2\n-1 -1 1\n", "3 1\n-1 -1 1\n" ]
[ "3\n", "1\n" ]
In the first sample we can get sequence [1, 1, 1], thus the total income equals 3. In the second test, the optimal strategy is to get sequence [-1, 1, 1], thus the total income equals 1.
1,000
[ { "input": "3 2\n-1 -1 1", "output": "3" }, { "input": "3 1\n-1 -1 1", "output": "1" }, { "input": "17 27\n257 320 676 1136 2068 2505 2639 4225 4951 5786 7677 7697 7851 8337 8429 8469 9343", "output": "81852" }, { "input": "69 28\n-9822 -9264 -9253 -9221 -9139 -9126 -9096 -8981 -8521 -8313 -8257 -8253 -7591 -7587 -7301 -7161 -7001 -6847 -6441 -6241 -5949 -5896 -5713 -5692 -5644 -5601 -5545 -5525 -5331 -5253 -5041 -5000 -4951 -4855 -4384 -4293 -4251 -4001 -3991 -3762 -3544 -3481 -3261 -2983 -2882 -2857 -2713 -2691 -2681 -2653 -2221 -2043 -2011 -1997 -1601 -1471 -1448 -1363 -1217 -1217 -1129 -961 -926 -801 -376 -327 -305 -174 -91", "output": "102443" }, { "input": "12 28\n-6652 -6621 -6471 -5559 -5326 -4551 -4401 -4326 -3294 -1175 -1069 -43", "output": "49488" }, { "input": "78 13\n-9961 -9922 -9817 -9813 -9521 -9368 -9361 -9207 -9153 -9124 -9008 -8981 -8951 -8911 -8551 -8479 -8245 -8216 -7988 -7841 -7748 -7741 -7734 -7101 -6846 -6804 -6651 -6526 -6519 -6463 -6297 -6148 -6090 -5845 -5209 -5201 -5161 -5061 -4537 -4529 -4433 -4370 -4266 -4189 -4125 -3945 -3843 -3777 -3751 -3476 -3461 -3279 -3205 -3001 -2889 -2761 -2661 -2521 -2481 -2305 -2278 -2269 -2225 -1648 -1524 -1476 -1353 -1097 -867 -785 -741 -711 -692 -440 -401 -225 -65 -41", "output": "-147832" }, { "input": "4 1\n218 3441 4901 7601", "output": "15725" }, { "input": "73 26\n-8497 -8363 -7603 -7388 -6830 -6827 -6685 -6389 -6237 -6099 -6013 -5565 -5465 -4965 -4947 -4201 -3851 -3793 -3421 -3410 -3201 -3169 -3156 -2976 -2701 -2623 -2321 -2169 -1469 -1221 -950 -926 -9 47 236 457 773 1321 1485 1545 1671 1736 2014 2137 2174 2301 2625 3181 3536 3851 4041 4685 4981 4987 5145 5163 5209 5249 6011 6337 6790 7254 7361 7407 7969 7982 8083 8251 8407 8735 9660 9855 9957", "output": "315919" }, { "input": "53 5\n-9821 -9429 -9146 -8973 -8807 -8801 -8321 -7361 -7222 -7161 -6913 -5961 -4877 -4756 -4753 -4661 -3375 -3031 -2950 -2661 -2161 -2041 -1111 -1071 -905 -697 -397 323 772 1617 1752 2736 2737 3201 3465 4029 4121 4463 4561 4637 4814 6119 6610 6641 6961 7217 7523 8045 8610 8915 9004 9265 9576", "output": "92703" }, { "input": "1 1\n0", "output": "0" }, { "input": "1 1\n10000", "output": "-10000" }, { "input": "1 2\n-1", "output": "-1" }, { "input": "2 1\n0 1", "output": "1" }, { "input": "2 2\n-1 0", "output": "1" }, { "input": "5 6\n-3 -2 -1 5 6", "output": "15" }, { "input": "3 3\n-50 -10 30", "output": "70" }, { "input": "4 4\n-100 -90 -80 1", "output": "269" }, { "input": "4 3\n-3 -2 1 2", "output": "6" }, { "input": "6 4\n-6 -3 -2 1 2 3", "output": "15" }, { "input": "5 6\n-10 -9 -8 1 2", "output": "28" }, { "input": "1 2\n1", "output": "1" }, { "input": "2 2\n-1 3", "output": "2" }, { "input": "4 7\n-3 -2 1 6", "output": "10" }, { "input": "4 3\n-7 -6 1 5", "output": "17" }, { "input": "4 4\n-5 -1 1 2", "output": "9" } ]
1,596,655,758
2,147,483,647
PyPy 3
RUNTIME_ERROR
TESTS
42
404
31,846,400
import sys def mi(s): return map(int, s.strip().split()) def lmi(s): return list(mi(s)) def main(arr, k): arr.sort() negs = [i for i in arr if i < 0] pos = [i for i in arr if i >= 0] if len(pos) == len(arr): if k % 2 == 0: return sum(arr) else: return sum(arr[1:]) - arr[0] else: # There are some negative nums. larger_negs = list(map(lambda x: -x, negs[:k])) smaller_negs = negs[k:] remaining = k - len(larger_negs) if remaining == 0 or remaining % 2 == 0: return sum(smaller_negs) + sum(larger_negs) + sum(pos) else: return sum(pos) + sum(larger_negs) - 2 * min(larger_negs[-1], pos[0]) if __name__ == "__main__": for e, line in enumerate(sys.stdin.readlines()): if e == 0: _, k = mi(line) else: colors = lmi(line) # Proof by induction that sorting is that # same as solving this problem. print(main(colors, k))
Title: Roma and Changing Signs Time Limit: None seconds Memory Limit: None megabytes Problem Description: Roma works in a company that sells TVs. Now he has to prepare a report for the last year. Roma has got a list of the company's incomes. The list is a sequence that consists of *n* integers. The total income of the company is the sum of all integers in sequence. Roma decided to perform exactly *k* changes of signs of several numbers in the sequence. He can also change the sign of a number one, two or more times. The operation of changing a number's sign is the operation of multiplying this number by -1. Help Roma perform the changes so as to make the total income of the company (the sum of numbers in the resulting sequence) maximum. Note that Roma should perform exactly *k* changes. Input Specification: The first line contains two integers *n* and *k* (1<=≤<=*n*,<=*k*<=≤<=105), showing, how many numbers are in the sequence and how many swaps are to be made. The second line contains a non-decreasing sequence, consisting of *n* integers *a**i* (|*a**i*|<=≤<=104). The numbers in the lines are separated by single spaces. Please note that the given sequence is sorted in non-decreasing order. Output Specification: In the single line print the answer to the problem — the maximum total income that we can obtain after exactly *k* changes. Demo Input: ['3 2\n-1 -1 1\n', '3 1\n-1 -1 1\n'] Demo Output: ['3\n', '1\n'] Note: In the first sample we can get sequence [1, 1, 1], thus the total income equals 3. In the second test, the optimal strategy is to get sequence [-1, 1, 1], thus the total income equals 1.
```python import sys def mi(s): return map(int, s.strip().split()) def lmi(s): return list(mi(s)) def main(arr, k): arr.sort() negs = [i for i in arr if i < 0] pos = [i for i in arr if i >= 0] if len(pos) == len(arr): if k % 2 == 0: return sum(arr) else: return sum(arr[1:]) - arr[0] else: # There are some negative nums. larger_negs = list(map(lambda x: -x, negs[:k])) smaller_negs = negs[k:] remaining = k - len(larger_negs) if remaining == 0 or remaining % 2 == 0: return sum(smaller_negs) + sum(larger_negs) + sum(pos) else: return sum(pos) + sum(larger_negs) - 2 * min(larger_negs[-1], pos[0]) if __name__ == "__main__": for e, line in enumerate(sys.stdin.readlines()): if e == 0: _, k = mi(line) else: colors = lmi(line) # Proof by induction that sorting is that # same as solving this problem. print(main(colors, k)) ```
-1
965
A
Paper Airplanes
PROGRAMMING
800
[ "math" ]
null
null
To make a paper airplane, one has to use a rectangular piece of paper. From a sheet of standard size you can make $s$ airplanes. A group of $k$ people decided to make $n$ airplanes each. They are going to buy several packs of paper, each of them containing $p$ sheets, and then distribute the sheets between the people. Each person should have enough sheets to make $n$ airplanes. How many packs should they buy?
The only line contains four integers $k$, $n$, $s$, $p$ ($1 \le k, n, s, p \le 10^4$) — the number of people, the number of airplanes each should make, the number of airplanes that can be made using one sheet and the number of sheets in one pack, respectively.
Print a single integer — the minimum number of packs they should buy.
[ "5 3 2 3\n", "5 3 100 1\n" ]
[ "4\n", "5\n" ]
In the first sample they have to buy $4$ packs of paper: there will be $12$ sheets in total, and giving $2$ sheets to each person is enough to suit everyone's needs. In the second sample they have to buy a pack for each person as they can't share sheets.
500
[ { "input": "5 3 2 3", "output": "4" }, { "input": "5 3 100 1", "output": "5" }, { "input": "10000 10000 1 1", "output": "100000000" }, { "input": "1 1 10000 10000", "output": "1" }, { "input": "300 300 21 23", "output": "196" }, { "input": "300 2 37 51", "output": "6" }, { "input": "2 400 23 57", "output": "1" }, { "input": "1 1 1 1", "output": "1" }, { "input": "10000 10000 3 2", "output": "16670000" }, { "input": "1 2 1 2", "output": "1" }, { "input": "1 1 2 2", "output": "1" }, { "input": "1 1 10 10", "output": "1" }, { "input": "5324 5439 32 13", "output": "69622" }, { "input": "9000 1 2432 1", "output": "9000" }, { "input": "230 1234 9124 23", "output": "10" }, { "input": "11 1 1 1", "output": "11" }, { "input": "6246 8489 1227 9", "output": "4858" }, { "input": "9 20 5 7", "output": "6" } ]
1,641,564,917
2,147,483,647
Python 3
OK
TESTS
18
46
0
a,b,c,d=map(int,input().split()) if b%c!=0: t=int(b/c)+1 else: t=int(b/c) if (t*a)%d!=0: print(int((t*a)/d)+1) else: print(int((t*a)/d))
Title: Paper Airplanes Time Limit: None seconds Memory Limit: None megabytes Problem Description: To make a paper airplane, one has to use a rectangular piece of paper. From a sheet of standard size you can make $s$ airplanes. A group of $k$ people decided to make $n$ airplanes each. They are going to buy several packs of paper, each of them containing $p$ sheets, and then distribute the sheets between the people. Each person should have enough sheets to make $n$ airplanes. How many packs should they buy? Input Specification: The only line contains four integers $k$, $n$, $s$, $p$ ($1 \le k, n, s, p \le 10^4$) — the number of people, the number of airplanes each should make, the number of airplanes that can be made using one sheet and the number of sheets in one pack, respectively. Output Specification: Print a single integer — the minimum number of packs they should buy. Demo Input: ['5 3 2 3\n', '5 3 100 1\n'] Demo Output: ['4\n', '5\n'] Note: In the first sample they have to buy $4$ packs of paper: there will be $12$ sheets in total, and giving $2$ sheets to each person is enough to suit everyone's needs. In the second sample they have to buy a pack for each person as they can't share sheets.
```python a,b,c,d=map(int,input().split()) if b%c!=0: t=int(b/c)+1 else: t=int(b/c) if (t*a)%d!=0: print(int((t*a)/d)+1) else: print(int((t*a)/d)) ```
3
16
A
Flag
PROGRAMMING
800
[ "implementation" ]
A. Flag
2
64
According to a new ISO standard, a flag of every country should have a chequered field *n*<=×<=*m*, each square should be of one of 10 colours, and the flag should be «striped»: each horizontal row of the flag should contain squares of the same colour, and the colours of adjacent horizontal rows should be different. Berland's government asked you to find out whether their flag meets the new ISO standard.
The first line of the input contains numbers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=100), *n* — the amount of rows, *m* — the amount of columns on the flag of Berland. Then there follows the description of the flag: each of the following *n* lines contain *m* characters. Each character is a digit between 0 and 9, and stands for the colour of the corresponding square.
Output YES, if the flag meets the new ISO standard, and NO otherwise.
[ "3 3\n000\n111\n222\n", "3 3\n000\n000\n111\n", "3 3\n000\n111\n002\n" ]
[ "YES\n", "NO\n", "NO\n" ]
none
0
[ { "input": "3 3\n000\n111\n222", "output": "YES" }, { "input": "3 3\n000\n000\n111", "output": "NO" }, { "input": "3 3\n000\n111\n002", "output": "NO" }, { "input": "10 10\n2222222222\n5555555555\n0000000000\n4444444444\n1111111111\n3333333393\n3333333333\n5555555555\n0000000000\n8888888888", "output": "NO" }, { "input": "10 13\n4442444444444\n8888888888888\n6666666666666\n0000000000000\n3333333333333\n4444444444444\n7777777777777\n8388888888888\n1111111111111\n5555555555555", "output": "NO" }, { "input": "10 8\n33333333\n44444444\n11111115\n81888888\n44444444\n11111111\n66666666\n33330333\n33333333\n33333333", "output": "NO" }, { "input": "5 5\n88888\n44444\n66666\n55555\n88888", "output": "YES" }, { "input": "20 19\n1111111111111111111\n5555555555555555555\n0000000000000000000\n3333333333333333333\n1111111111111111111\n2222222222222222222\n4444444444444444444\n5555555555555555555\n0000000000000000000\n4444444444444444444\n0000000000000000000\n5555555555555555555\n7777777777777777777\n9999999999999999999\n2222222222222222222\n4444444444444444444\n1111111111111111111\n6666666666666666666\n7777777777777777777\n2222222222222222222", "output": "YES" }, { "input": "1 100\n8888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888", "output": "YES" }, { "input": "100 1\n5\n7\n9\n4\n7\n2\n5\n1\n6\n7\n2\n7\n6\n8\n7\n4\n0\n2\n9\n8\n9\n1\n6\n4\n3\n4\n7\n1\n9\n3\n0\n8\n3\n1\n7\n5\n3\n9\n5\n1\n3\n5\n8\n1\n9\n3\n9\n0\n6\n0\n7\n6\n5\n2\n8\n3\n7\n6\n5\n1\n8\n3\n6\n9\n6\n0\n5\n8\n5\n2\n9\n1\n0\n1\n8\n3\n2\n1\n0\n3\n9\n0\n5\n1\n0\n4\n9\n3\n0\n4\n8\n4\n8\n6\n3\n0\n4\n6\n8\n4", "output": "YES" }, { "input": "1 1\n2", "output": "YES" }, { "input": "1 100\n1111111111111111111111111111111111111111111111111111111111111111111111111111181111111111111111111111", "output": "NO" }, { "input": "100 1\n3\n6\n4\n3\n0\n2\n8\n7\n3\n2\n1\n7\n1\n3\n2\n3\n6\n9\n0\n8\n5\n9\n7\n9\n2\n1\n4\n5\n1\n9\n2\n5\n1\n4\n6\n4\n9\n1\n0\n2\n1\n4\n7\n1\n4\n8\n0\n9\n2\n1\n6\n2\n8\n6\n9\n5\n8\n6\n4\n5\n9\n2\n7\n4\n1\n5\n8\n0\n9\n5\n4\n6\n5\n0\n6\n3\n6\n9\n7\n2\n0\n9\n7\n3\n2\n4\n9\n4\n7\n1\n2\n3\n1\n7\n9\n1\n9\n0\n4\n0", "output": "YES" } ]
1,642,596,366
2,147,483,647
Python 3
OK
TESTS
35
92
0
a=[*open(0)][1:] r=any(any(x!=y for x,y in zip(b,b[1:-1]))for b in a) print('YNEOS'[r|any(x[0]==y[0] for x,y in zip(a,a[1:]))::2])
Title: Flag Time Limit: 2 seconds Memory Limit: 64 megabytes Problem Description: According to a new ISO standard, a flag of every country should have a chequered field *n*<=×<=*m*, each square should be of one of 10 colours, and the flag should be «striped»: each horizontal row of the flag should contain squares of the same colour, and the colours of adjacent horizontal rows should be different. Berland's government asked you to find out whether their flag meets the new ISO standard. Input Specification: The first line of the input contains numbers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=100), *n* — the amount of rows, *m* — the amount of columns on the flag of Berland. Then there follows the description of the flag: each of the following *n* lines contain *m* characters. Each character is a digit between 0 and 9, and stands for the colour of the corresponding square. Output Specification: Output YES, if the flag meets the new ISO standard, and NO otherwise. Demo Input: ['3 3\n000\n111\n222\n', '3 3\n000\n000\n111\n', '3 3\n000\n111\n002\n'] Demo Output: ['YES\n', 'NO\n', 'NO\n'] Note: none
```python a=[*open(0)][1:] r=any(any(x!=y for x,y in zip(b,b[1:-1]))for b in a) print('YNEOS'[r|any(x[0]==y[0] for x,y in zip(a,a[1:]))::2]) ```
3.977
894
A
QAQ
PROGRAMMING
800
[ "brute force", "dp" ]
null
null
"QAQ" is a word to denote an expression of crying. Imagine "Q" as eyes with tears and "A" as a mouth. Now Diamond has given Bort a string consisting of only uppercase English letters of length *n*. There is a great number of "QAQ" in the string (Diamond is so cute!). Bort wants to know how many subsequences "QAQ" are in the string Diamond has given. Note that the letters "QAQ" don't have to be consecutive, but the order of letters should be exact.
The only line contains a string of length *n* (1<=≤<=*n*<=≤<=100). It's guaranteed that the string only contains uppercase English letters.
Print a single integer — the number of subsequences "QAQ" in the string.
[ "QAQAQYSYIOIWIN\n", "QAQQQZZYNOIWIN\n" ]
[ "4\n", "3\n" ]
In the first example there are 4 subsequences "QAQ": "QAQAQYSYIOIWIN", "QAQAQYSYIOIWIN", "QAQAQYSYIOIWIN", "QAQAQYSYIOIWIN".
500
[ { "input": "QAQAQYSYIOIWIN", "output": "4" }, { "input": "QAQQQZZYNOIWIN", "output": "3" }, { "input": "QA", "output": "0" }, { "input": "IAQVAQZLQBQVQFTQQQADAQJA", "output": "24" }, { "input": "QQAAQASGAYAAAAKAKAQIQEAQAIAAIAQQQQQ", "output": "378" }, { "input": "AMVFNFJIAVNQJWIVONQOAOOQSNQSONOASONAONQINAONAOIQONANOIQOANOQINAONOQINAONOXJCOIAQOAOQAQAQAQAQWWWAQQAQ", "output": "1077" }, { "input": "AAQQAXBQQBQQXBNQRJAQKQNAQNQVDQASAGGANQQQQTJFFQQQTQQA", "output": "568" }, { "input": "KAZXAVLPJQBQVQQQQQAPAQQGQTQVZQAAAOYA", "output": "70" }, { "input": "W", "output": "0" }, { "input": "DBA", "output": "0" }, { "input": "RQAWNACASAAKAGAAAAQ", "output": "10" }, { "input": "QJAWZAAOAAGIAAAAAOQATASQAEAAAAQFQQHPA", "output": "111" }, { "input": "QQKWQAQAAAAAAAAGAAVAQUEQQUMQMAQQQNQLAMAAAUAEAAEMAAA", "output": "411" }, { "input": "QQUMQAYAUAAGWAAAQSDAVAAQAAAASKQJJQQQQMAWAYYAAAAAAEAJAXWQQ", "output": "625" }, { "input": "QORZOYAQ", "output": "1" }, { "input": "QCQAQAGAWAQQQAQAVQAQQQQAQAQQQAQAAATQAAVAAAQQQQAAAUUQAQQNQQWQQWAQAAQQKQYAQAAQQQAAQRAQQQWBQQQQAPBAQGQA", "output": "13174" }, { "input": "QQAQQAKQFAQLQAAWAMQAZQAJQAAQQOACQQAAAYANAQAQQAQAAQQAOBQQJQAQAQAQQQAAAAABQQQAVNZAQQQQAMQQAFAAEAQAQHQT", "output": "10420" }, { "input": "AQEGQHQQKQAQQPQKAQQQAAAAQQQAQEQAAQAAQAQFSLAAQQAQOQQAVQAAAPQQAWAQAQAFQAXAQQQQTRLOQAQQJQNQXQQQQSQVDQQQ", "output": "12488" }, { "input": "QNQKQQQLASQBAVQQQQAAQQOQRJQQAQQQEQZUOANAADAAQQJAQAQARAAAQQQEQBHTQAAQAAAAQQMKQQQIAOJJQQAQAAADADQUQQQA", "output": "9114" }, { "input": "QQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQ", "output": "35937" }, { "input": "AMQQAAQAAQAAAAAAQQQBOAAANAAKQJCYQAE", "output": "254" }, { "input": "AYQBAEQGAQEOAKGIXLQJAIAKQAAAQPUAJAKAATFWQQAOQQQUFQYAQQMQHOKAAJXGFCARAQSATHAUQQAATQJJQDQRAANQQAE", "output": "2174" }, { "input": "AAQXAAQAYQAAAAGAQHVQYAGIVACADFAAQAAAAQZAAQMAKZAADQAQDAAQDAAAMQQOXYAQQQAKQBAAQQKAXQBJZDDLAAHQQ", "output": "2962" }, { "input": "AYQQYAVAMNIAUAAKBBQVACWKTQSAQZAAQAAASZJAWBCAALAARHACQAKQQAQAARPAQAAQAQAAZQUSHQAMFVFZQQQQSAQQXAA", "output": "2482" }, { "input": "LQMAQQARQAQBJQQQAGAAZQQXALQQAARQAQQQQAAQQAQQQAQQCAQQAQQAYQQQRAAZATQALYQQAAHHAAQHAAAAAAAAQQMAAQNAKQ", "output": "7768" }, { "input": "MAQQWAQOYQMAAAQAQPQZAOAAQAUAQNAAQAAAITQSAQAKAQKAQQWSQAAQQAGUCDQMQWKQUXKWQQAAQQAAQQZQDQQQAABXQUUXQOA", "output": "5422" }, { "input": "QTAAQDAQXAQQJQQQGAAAQQQQSBQZKAQQAQQQQEAQNUQBZCQLYQZQEQQAAQHQVAORKQVAQYQNASZQAARZAAGAAAAOQDCQ", "output": "3024" }, { "input": "QQWAQQGQQUZQQQLZAAQYQXQVAQFQUAQZUQZZQUKBHSHTQYLQAOQXAQQGAQQTQOAQARQADAJRAAQPQAQQUQAUAMAUVQAAAQQAWQ", "output": "4527" }, { "input": "QQAAQQAQVAQZQQQQAOEAQZPQIBQZACQQAFQQLAAQDATZQANHKYQQAQTAAFQRQAIQAJPWQAQTEIRXAEQQAYWAAAUKQQAQAQQQSQQH", "output": "6416" }, { "input": "AQQQQAQAAQQAQAQAAAAAAAAAQAQAAAAAQAQAQQQAQQQAAAQQQAAAAAAAQAAAAQQQQQQQAQQQQAQAAAQAAAAAQAQAAAAAQAQAAAA", "output": "14270" }, { "input": "AQQQQAQAAQQAQAQAAAAAAAAAQAQAAAAAQAQAQQQAQQQAAAQQQAAAAAAAQAAAAQQQQQQQAQQQQAQAAAQAAAAAQAQAAAAAQ", "output": "13136" }, { "input": "AQQQQAQAAQQAQAQAAAAAAAAAQAQAAAAAQAQAQQQAQQQAAAQQQAAAAAAAQAAAAQQQQQQQAQQQQAQAAAQAAAAAQAQAAAAAQAQAA", "output": "14270" }, { "input": "AQQQQAQAAQQAQAQAAAAAAAAAQAQAAAAAQAQAQQQAQQQAAAQQQAAAAAAAQAAAAQQQQQQQAQQQQAQAAAQAAAAAQAQAAAAAQQAA", "output": "14231" }, { "input": "QQQQQAQAAQQAQAQAAAAAAAAAQAQAAAAAQAQAQQQAQQQAAAQQQAAAAAAAQAAAAQQQQQQQAQQQQAQAAAQAAAAAQAQAAAAAQAQAA", "output": "15296" }, { "input": "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQ", "output": "0" }, { "input": "QQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA", "output": "0" }, { "input": "QQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQ", "output": "0" }, { "input": "QAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQA", "output": "20825" }, { "input": "AQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQ", "output": "20825" }, { "input": "Q", "output": "0" }, { "input": "A", "output": "0" }, { "input": "FFF", "output": "0" }, { "input": "AAAAAA", "output": "0" } ]
1,609,497,146
2,147,483,647
Python 3
OK
TESTS
43
109
0
def fun(st): count=0 for i in st: if i=='Q': count= count+1 ans=0 leftq=0 rightq=count for i in st: if i=='Q': leftq+=1 rightq-=1 if i=='A': ans+=leftq*rightq print(ans) st= input() fun(st)
Title: QAQ Time Limit: None seconds Memory Limit: None megabytes Problem Description: "QAQ" is a word to denote an expression of crying. Imagine "Q" as eyes with tears and "A" as a mouth. Now Diamond has given Bort a string consisting of only uppercase English letters of length *n*. There is a great number of "QAQ" in the string (Diamond is so cute!). Bort wants to know how many subsequences "QAQ" are in the string Diamond has given. Note that the letters "QAQ" don't have to be consecutive, but the order of letters should be exact. Input Specification: The only line contains a string of length *n* (1<=≤<=*n*<=≤<=100). It's guaranteed that the string only contains uppercase English letters. Output Specification: Print a single integer — the number of subsequences "QAQ" in the string. Demo Input: ['QAQAQYSYIOIWIN\n', 'QAQQQZZYNOIWIN\n'] Demo Output: ['4\n', '3\n'] Note: In the first example there are 4 subsequences "QAQ": "QAQAQYSYIOIWIN", "QAQAQYSYIOIWIN", "QAQAQYSYIOIWIN", "QAQAQYSYIOIWIN".
```python def fun(st): count=0 for i in st: if i=='Q': count= count+1 ans=0 leftq=0 rightq=count for i in st: if i=='Q': leftq+=1 rightq-=1 if i=='A': ans+=leftq*rightq print(ans) st= input() fun(st) ```
3
884
A
Book Reading
PROGRAMMING
800
[ "implementation" ]
null
null
Recently Luba bought a very interesting book. She knows that it will take *t* seconds to read the book. Luba wants to finish reading as fast as she can. But she has some work to do in each of *n* next days. The number of seconds that Luba has to spend working during *i*-th day is *a**i*. If some free time remains, she can spend it on reading. Help Luba to determine the minimum number of day when she finishes reading. It is guaranteed that the answer doesn't exceed *n*. Remember that there are 86400 seconds in a day.
The first line contains two integers *n* and *t* (1<=≤<=*n*<=≤<=100, 1<=≤<=*t*<=≤<=106) — the number of days and the time required to read the book. The second line contains *n* integers *a**i* (0<=≤<=*a**i*<=≤<=86400) — the time Luba has to spend on her work during *i*-th day.
Print the minimum day Luba can finish reading the book. It is guaranteed that answer doesn't exceed *n*.
[ "2 2\n86400 86398\n", "2 86400\n0 86400\n" ]
[ "2\n", "1\n" ]
none
0
[ { "input": "2 2\n86400 86398", "output": "2" }, { "input": "2 86400\n0 86400", "output": "1" }, { "input": "2 86400\n1 86399", "output": "2" }, { "input": "100 1000000\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": "12" }, { "input": "1 1\n86399", "output": "1" }, { "input": "6 1200\n86400 86400 86000 86000 86000 86400", "output": "5" }, { "input": "6 1200\n86400 86400 86000 86000 86001 86399", "output": "6" }, { "input": "4 172799\n1 1 86400 0", "output": "4" }, { "input": "4 172799\n0 86400 86399 0", "output": "4" }, { "input": "6 1\n1 1 86400 1 86399 1", "output": "1" }, { "input": "4 1\n86400 86399 86400 86400", "output": "2" }, { "input": "4 1\n86400 86400 0 86400", "output": "3" } ]
1,599,816,795
2,147,483,647
PyPy 3
OK
TESTS
16
139
0
n, t = [int(x) for x in input().split()] a = [86400 - int(x) for x in input().split()] s = 0 for i, x in enumerate(a): s += x if s >= t: print(i+1) break
Title: Book Reading Time Limit: None seconds Memory Limit: None megabytes Problem Description: Recently Luba bought a very interesting book. She knows that it will take *t* seconds to read the book. Luba wants to finish reading as fast as she can. But she has some work to do in each of *n* next days. The number of seconds that Luba has to spend working during *i*-th day is *a**i*. If some free time remains, she can spend it on reading. Help Luba to determine the minimum number of day when she finishes reading. It is guaranteed that the answer doesn't exceed *n*. Remember that there are 86400 seconds in a day. Input Specification: The first line contains two integers *n* and *t* (1<=≤<=*n*<=≤<=100, 1<=≤<=*t*<=≤<=106) — the number of days and the time required to read the book. The second line contains *n* integers *a**i* (0<=≤<=*a**i*<=≤<=86400) — the time Luba has to spend on her work during *i*-th day. Output Specification: Print the minimum day Luba can finish reading the book. It is guaranteed that answer doesn't exceed *n*. Demo Input: ['2 2\n86400 86398\n', '2 86400\n0 86400\n'] Demo Output: ['2\n', '1\n'] Note: none
```python n, t = [int(x) for x in input().split()] a = [86400 - int(x) for x in input().split()] s = 0 for i, x in enumerate(a): s += x if s >= t: print(i+1) break ```
3
746
A
Compote
PROGRAMMING
800
[ "implementation", "math" ]
null
null
Nikolay has *a* lemons, *b* apples and *c* pears. He decided to cook a compote. According to the recipe the fruits should be in the ratio 1:<=2:<=4. It means that for each lemon in the compote should be exactly 2 apples and exactly 4 pears. You can't crumble up, break up or cut these fruits into pieces. These fruits — lemons, apples and pears — should be put in the compote as whole fruits. Your task is to determine the maximum total number of lemons, apples and pears from which Nikolay can cook the compote. It is possible that Nikolay can't use any fruits, in this case print 0.
The first line contains the positive integer *a* (1<=≤<=*a*<=≤<=1000) — the number of lemons Nikolay has. The second line contains the positive integer *b* (1<=≤<=*b*<=≤<=1000) — the number of apples Nikolay has. The third line contains the positive integer *c* (1<=≤<=*c*<=≤<=1000) — the number of pears Nikolay has.
Print the maximum total number of lemons, apples and pears from which Nikolay can cook the compote.
[ "2\n5\n7\n", "4\n7\n13\n", "2\n3\n2\n" ]
[ "7\n", "21\n", "0\n" ]
In the first example Nikolay can use 1 lemon, 2 apples and 4 pears, so the answer is 1 + 2 + 4 = 7. In the second example Nikolay can use 3 lemons, 6 apples and 12 pears, so the answer is 3 + 6 + 12 = 21. In the third example Nikolay don't have enough pears to cook any compote, so the answer is 0.
500
[ { "input": "2\n5\n7", "output": "7" }, { "input": "4\n7\n13", "output": "21" }, { "input": "2\n3\n2", "output": "0" }, { "input": "1\n1\n1", "output": "0" }, { "input": "1\n2\n4", "output": "7" }, { "input": "1000\n1000\n1000", "output": "1750" }, { "input": "1\n1\n4", "output": "0" }, { "input": "1\n2\n3", "output": "0" }, { "input": "1\n1000\n1000", "output": "7" }, { "input": "1000\n1\n1000", "output": "0" }, { "input": "1000\n2\n1000", "output": "7" }, { "input": "1000\n500\n1000", "output": "1750" }, { "input": "1000\n1000\n4", "output": "7" }, { "input": "1000\n1000\n3", "output": "0" }, { "input": "4\n8\n12", "output": "21" }, { "input": "10\n20\n40", "output": "70" }, { "input": "100\n200\n399", "output": "693" }, { "input": "200\n400\n800", "output": "1400" }, { "input": "199\n400\n800", "output": "1393" }, { "input": "201\n400\n800", "output": "1400" }, { "input": "200\n399\n800", "output": "1393" }, { "input": "200\n401\n800", "output": "1400" }, { "input": "200\n400\n799", "output": "1393" }, { "input": "200\n400\n801", "output": "1400" }, { "input": "139\n252\n871", "output": "882" }, { "input": "109\n346\n811", "output": "763" }, { "input": "237\n487\n517", "output": "903" }, { "input": "161\n331\n725", "output": "1127" }, { "input": "39\n471\n665", "output": "273" }, { "input": "9\n270\n879", "output": "63" }, { "input": "137\n422\n812", "output": "959" }, { "input": "15\n313\n525", "output": "105" }, { "input": "189\n407\n966", "output": "1323" }, { "input": "18\n268\n538", "output": "126" }, { "input": "146\n421\n978", "output": "1022" }, { "input": "70\n311\n685", "output": "490" }, { "input": "244\n405\n625", "output": "1092" }, { "input": "168\n454\n832", "output": "1176" }, { "input": "46\n344\n772", "output": "322" }, { "input": "174\n438\n987", "output": "1218" }, { "input": "144\n387\n693", "output": "1008" }, { "input": "22\n481\n633", "output": "154" }, { "input": "196\n280\n848", "output": "980" }, { "input": "190\n454\n699", "output": "1218" }, { "input": "231\n464\n928", "output": "1617" }, { "input": "151\n308\n616", "output": "1057" }, { "input": "88\n182\n364", "output": "616" }, { "input": "12\n26\n52", "output": "84" }, { "input": "204\n412\n824", "output": "1428" }, { "input": "127\n256\n512", "output": "889" }, { "input": "224\n446\n896", "output": "1561" }, { "input": "146\n291\n584", "output": "1015" }, { "input": "83\n164\n332", "output": "574" }, { "input": "20\n38\n80", "output": "133" }, { "input": "198\n393\n792", "output": "1372" }, { "input": "120\n239\n480", "output": "833" }, { "input": "208\n416\n831", "output": "1449" }, { "input": "130\n260\n517", "output": "903" }, { "input": "67\n134\n267", "output": "462" }, { "input": "245\n490\n979", "output": "1708" }, { "input": "182\n364\n727", "output": "1267" }, { "input": "104\n208\n413", "output": "721" }, { "input": "10\n2\n100", "output": "7" }, { "input": "2\n100\n100", "output": "14" }, { "input": "2\n3\n8", "output": "7" }, { "input": "1\n2\n8", "output": "7" }, { "input": "1\n2\n200", "output": "7" }, { "input": "5\n4\n16", "output": "14" }, { "input": "1\n10\n10", "output": "7" }, { "input": "1\n4\n8", "output": "7" }, { "input": "100\n4\n1000", "output": "14" }, { "input": "2\n6\n12", "output": "14" }, { "input": "10\n7\n4", "output": "7" }, { "input": "2\n10\n100", "output": "14" }, { "input": "2\n3\n4", "output": "7" }, { "input": "1\n2\n999", "output": "7" }, { "input": "1\n10\n20", "output": "7" }, { "input": "100\n18\n20", "output": "35" }, { "input": "100\n1\n100", "output": "0" }, { "input": "3\n7\n80", "output": "21" }, { "input": "2\n8\n24", "output": "14" }, { "input": "1\n100\n100", "output": "7" }, { "input": "2\n1\n8", "output": "0" }, { "input": "10\n5\n23", "output": "14" } ]
1,617,797,049
2,147,483,647
Python 3
OK
TESTS
84
62
0
l = int(input()) a = int(input()) p = int(input()) total=0 while(l>0 and a>1 and p>3): total+=7 l = l - 1 a = a - 2 p = p - 4 print(total)
Title: Compote Time Limit: None seconds Memory Limit: None megabytes Problem Description: Nikolay has *a* lemons, *b* apples and *c* pears. He decided to cook a compote. According to the recipe the fruits should be in the ratio 1:<=2:<=4. It means that for each lemon in the compote should be exactly 2 apples and exactly 4 pears. You can't crumble up, break up or cut these fruits into pieces. These fruits — lemons, apples and pears — should be put in the compote as whole fruits. Your task is to determine the maximum total number of lemons, apples and pears from which Nikolay can cook the compote. It is possible that Nikolay can't use any fruits, in this case print 0. Input Specification: The first line contains the positive integer *a* (1<=≤<=*a*<=≤<=1000) — the number of lemons Nikolay has. The second line contains the positive integer *b* (1<=≤<=*b*<=≤<=1000) — the number of apples Nikolay has. The third line contains the positive integer *c* (1<=≤<=*c*<=≤<=1000) — the number of pears Nikolay has. Output Specification: Print the maximum total number of lemons, apples and pears from which Nikolay can cook the compote. Demo Input: ['2\n5\n7\n', '4\n7\n13\n', '2\n3\n2\n'] Demo Output: ['7\n', '21\n', '0\n'] Note: In the first example Nikolay can use 1 lemon, 2 apples and 4 pears, so the answer is 1 + 2 + 4 = 7. In the second example Nikolay can use 3 lemons, 6 apples and 12 pears, so the answer is 3 + 6 + 12 = 21. In the third example Nikolay don't have enough pears to cook any compote, so the answer is 0.
```python l = int(input()) a = int(input()) p = int(input()) total=0 while(l>0 and a>1 and p>3): total+=7 l = l - 1 a = a - 2 p = p - 4 print(total) ```
3
437
A
The Child and Homework
PROGRAMMING
1,300
[ "implementation" ]
null
null
Once upon a time a child got a test consisting of multiple-choice questions as homework. A multiple-choice question consists of four choices: A, B, C and D. Each choice has a description, and the child should find out the only one that is correct. Fortunately the child knows how to solve such complicated test. The child will follow the algorithm: - If there is some choice whose description at least twice shorter than all other descriptions, or at least twice longer than all other descriptions, then the child thinks the choice is great. - If there is exactly one great choice then the child chooses it. Otherwise the child chooses C (the child think it is the luckiest choice). You are given a multiple-choice questions, can you predict child's choose?
The first line starts with "A." (without quotes), then followed the description of choice A. The next three lines contains the descriptions of the other choices in the same format. They are given in order: B, C, D. Please note, that the description goes after prefix "X.", so the prefix mustn't be counted in description's length. Each description is non-empty and consists of at most 100 characters. Each character can be either uppercase English letter or lowercase English letter, or "_".
Print a single line with the child's choice: "A", "B", "C" or "D" (without quotes).
[ "A.VFleaKing_is_the_author_of_this_problem\nB.Picks_is_the_author_of_this_problem\nC.Picking_is_the_author_of_this_problem\nD.Ftiasch_is_cute\n", "A.ab\nB.abcde\nC.ab\nD.abc\n", "A.c\nB.cc\nC.c\nD.c\n" ]
[ "D\n", "C\n", "B\n" ]
In the first sample, the first choice has length 39, the second one has length 35, the third one has length 37, and the last one has length 15. The choice D (length 15) is twice shorter than all other choices', so it is great choice. There is no other great choices so the child will choose D. In the second sample, no choice is great, so the child will choose the luckiest choice C. In the third sample, the choice B (length 2) is twice longer than all other choices', so it is great choice. There is no other great choices so the child will choose B.
500
[ { "input": "A.VFleaKing_is_the_author_of_this_problem\nB.Picks_is_the_author_of_this_problem\nC.Picking_is_the_author_of_this_problem\nD.Ftiasch_is_cute", "output": "D" }, { "input": "A.ab\nB.abcde\nC.ab\nD.abc", "output": "C" }, { "input": "A.c\nB.cc\nC.c\nD.c", "output": "B" }, { "input": "A.He_nan_de_yang_guang_zhao_yao_zhe_wo_men_mei_guo_ren_lian_shang_dou_xiao_kai_yan_wahaaaaaaaaaaaaaaaa\nB.Li_bai_li_bai_fei_liu_zhi_xia_san_qian_chi_yi_si_yin_he_luo_jiu_tian_li_bai_li_bai_li_bai_li_bai_shi\nC.Peng_yu_xiang_shi_zai_tai_shen_le_jian_zhi_jiu_shi_ye_jie_du_liu_a_si_mi_da_zhen_shi_tai_shen_le_a_a\nD.Wo_huo_le_si_shi_er_nian_zhen_de_shi_cong_lai_ye_mei_you_jian_guo_zhe_me_biao_zhun_de_yi_bai_ge_zi_a", "output": "C" }, { "input": "A.a___FXIcs_gB____dxFFzst_p_P_Xp_vS__cS_C_ei_\nB.fmnmkS_SeZYx_tSys_d__Exbojv_a_YPEL_BPj__I_aYH\nC._nrPx_j\nD.o_A_UwmNbC_sZ_AXk_Y___i_SN_U_UxrBN_qo_____", "output": "C" }, { "input": "A.G_R__iT_ow_Y__Sm_al__u_____l_ltK\nB.CWRe__h__cbCF\nC._QJ_dVHCL_g_WBsMO__LC____hMNE_DoO__xea_ec\nD.___Zh_", "output": "D" }, { "input": "A.a___FXIcs_gB____dxFFzst_p_P_Xp_vS__cS_C_ei_\nB.fmnmkS_SeZYx_tSys_d__Exbojv_a_YPEL_BPj__I_aYH\nC._nrPx_j\nD.o_A_UwmNbC_sZ_AXk_Y___i_SN_U_UxrBN_qo_____", "output": "C" }, { "input": "A.G_R__iT_ow_Y__Sm_al__u_____l_ltK\nB.CWRe__h__cbCF\nC._QJ_dVHCL_g_WBsMO__LC____hMNE_DoO__xea_ec\nD.___Zh_", "output": "D" }, { "input": "A.ejQ_E_E_G_e_SDjZ__lh_f_K__Z_i_B_U__S__S_EMD_ZEU_Sq\nB.o_JpInEdsrAY_T__D_S\nC.E_Vp_s\nD.a_AU_h", "output": "A" }, { "input": "A.PN_m_P_qgOAMwDyxtbH__Yc__bPOh_wYH___n_Fv_qlZp_\nB._gLeDU__rr_vjrm__O_jl_R__DG___u_XqJjW_\nC.___sHLQzdTzT_tZ_Gs\nD.sZNcVa__M_To_bz_clFi_mH_", "output": "C" }, { "input": "A.bR___cCYJg_Wbt____cxfXfC____c_O_\nB.guM\nC.__bzsH_Of__RjG__u_w_i__PXQL_U_Ow_U_n\nD._nHIuZsu_uU_stRC_k___vD_ZOD_u_z_c_Zf__p_iF_uD_Hdg", "output": "B" }, { "input": "A.x_\nB.__RSiDT_\nC.Ci\nD.KLY_Hc_YN_xXg_DynydumheKTw_PFHo_vqXwm_DY_dA___OS_kG___", "output": "D" }, { "input": "A.yYGJ_C__NYq_\nB.ozMUZ_cKKk_zVUPR_b_g_ygv_HoM__yAxvh__iE\nC.sgHJ___MYP__AWejchRvjSD_o\nD.gkfF_GiOqW_psMT_eS", "output": "C" }, { "input": "A._LYm_nvl_E__RCFZ_IdO\nB.k__qIPO_ivvZyIG__L_\nC.D_SabLm_R___j_HS_t__\nD._adj_R_ngix____GSe_aw__SbOOl_", "output": "C" }, { "input": "A.h_WiYTD_C_h___z_Gn_Th_uNh__g___jm\nB.__HeQaudCJcYfVi__Eg_vryuQrDkb_g__oy_BwX_Mu_\nC._MChdMhQA_UKrf_LGZk_ALTo_mnry_GNNza_X_D_u____ueJb__Y_h__CNUNDfmZATck_ad_XTbG\nD.NV___OoL__GfP_CqhD__RB_____v_T_xi", "output": "C" }, { "input": "A.____JGWsfiU\nB.S_LMq__MpE_oFBs_P\nC.U_Rph_VHpUr____X_jWXbk__ElJTu_Z_wlBpKLTD\nD.p_ysvPNmbrF__", "output": "C" }, { "input": "A.ejQ_E_E_G_e_SDjZ__lh_f_K__Z_i_B_U__S__S_EMD_ZEU_Sq\nB.o_JpInEdsrAY_T__D_S\nC.E_Vp_s\nD.a_AU_h", "output": "A" }, { "input": "A.PN_m_P_qgOAMwDyxtbH__Yc__bPOh_wYH___n_Fv_qlZp_\nB._gLeDU__rr_vjrm__O_jl_R__DG___u_XqJjW_\nC.___sHLQzdTzT_tZ_Gs\nD.sZNcVa__M_To_bz_clFi_mH_", "output": "C" }, { "input": "A.bR___cCYJg_Wbt____cxfXfC____c_O_\nB.guM\nC.__bzsH_Of__RjG__u_w_i__PXQL_U_Ow_U_n\nD._nHIuZsu_uU_stRC_k___vD_ZOD_u_z_c_Zf__p_iF_uD_Hdg", "output": "B" }, { "input": "A.x_\nB.__RSiDT_\nC.Ci\nD.KLY_Hc_YN_xXg_DynydumheKTw_PFHo_vqXwm_DY_dA___OS_kG___", "output": "D" }, { "input": "A.yYGJ_C__NYq_\nB.ozMUZ_cKKk_zVUPR_b_g_ygv_HoM__yAxvh__iE\nC.sgHJ___MYP__AWejchRvjSD_o\nD.gkfF_GiOqW_psMT_eS", "output": "C" }, { "input": "A._LYm_nvl_E__RCFZ_IdO\nB.k__qIPO_ivvZyIG__L_\nC.D_SabLm_R___j_HS_t__\nD._adj_R_ngix____GSe_aw__SbOOl_", "output": "C" }, { "input": "A.h_WiYTD_C_h___z_Gn_Th_uNh__g___jm\nB.__HeQaudCJcYfVi__Eg_vryuQrDkb_g__oy_BwX_Mu_\nC._MChdMhQA_UKrf_LGZk_ALTo_mnry_GNNza_X_D_u____ueJb__Y_h__CNUNDfmZATck_ad_XTbG\nD.NV___OoL__GfP_CqhD__RB_____v_T_xi", "output": "C" }, { "input": "A.____JGWsfiU\nB.S_LMq__MpE_oFBs_P\nC.U_Rph_VHpUr____X_jWXbk__ElJTu_Z_wlBpKLTD\nD.p_ysvPNmbrF__", "output": "C" }, { "input": "A.aaaaaa\nB.aaa\nC.aaa\nD.aaa", "output": "A" }, { "input": "A.aaa\nB.aaaaaa\nC.aaaaaa\nD.aaaaaa", "output": "A" }, { "input": "A.a\nB.b\nC.c\nD.d", "output": "C" }, { "input": "A._\nB.__\nC.____\nD.________", "output": "C" }, { "input": "A.____\nB.________\nC.________\nD._______", "output": "C" }, { "input": "A.h\nB.asdf\nC.asqw\nD.qwertasdfg", "output": "C" }, { "input": "A.aa\nB.aaaaa\nC.aaaaaa\nD.aaaaaaaaaaaaa", "output": "C" }, { "input": "A.ccc\nB.ccccccc\nC.ccc\nD.c", "output": "C" }, { "input": "A.c\nB.ccc\nC.cccccccccccccccccc\nD.cccccc", "output": "C" }, { "input": "A.aa\nB.bb\nC.cc\nD.ddd", "output": "C" }, { "input": "A.QW\nB.WERT\nC.QWER\nD.QWERTYUI", "output": "C" } ]
1,605,085,176
2,147,483,647
Python 3
OK
TESTS
35
93
307,200
choice=[] for i in range(4): choice.append(len(input(' ')[2:])) Shortest=True Longest=True cc=0 ci=None for i in range(4): Shortest=True Longest=True for j in range(4): if i==j:continue if choice[i]<choice[j]*2:Longest=False if choice[i]*2>choice[j]:Shortest=False if Shortest:cc+=1;ci=chr(65+i) if Longest:cc+=1;ci=chr(65+i) if cc==1: print(ci) else: print('C')
Title: The Child and Homework Time Limit: None seconds Memory Limit: None megabytes Problem Description: Once upon a time a child got a test consisting of multiple-choice questions as homework. A multiple-choice question consists of four choices: A, B, C and D. Each choice has a description, and the child should find out the only one that is correct. Fortunately the child knows how to solve such complicated test. The child will follow the algorithm: - If there is some choice whose description at least twice shorter than all other descriptions, or at least twice longer than all other descriptions, then the child thinks the choice is great. - If there is exactly one great choice then the child chooses it. Otherwise the child chooses C (the child think it is the luckiest choice). You are given a multiple-choice questions, can you predict child's choose? Input Specification: The first line starts with "A." (without quotes), then followed the description of choice A. The next three lines contains the descriptions of the other choices in the same format. They are given in order: B, C, D. Please note, that the description goes after prefix "X.", so the prefix mustn't be counted in description's length. Each description is non-empty and consists of at most 100 characters. Each character can be either uppercase English letter or lowercase English letter, or "_". Output Specification: Print a single line with the child's choice: "A", "B", "C" or "D" (without quotes). Demo Input: ['A.VFleaKing_is_the_author_of_this_problem\nB.Picks_is_the_author_of_this_problem\nC.Picking_is_the_author_of_this_problem\nD.Ftiasch_is_cute\n', 'A.ab\nB.abcde\nC.ab\nD.abc\n', 'A.c\nB.cc\nC.c\nD.c\n'] Demo Output: ['D\n', 'C\n', 'B\n'] Note: In the first sample, the first choice has length 39, the second one has length 35, the third one has length 37, and the last one has length 15. The choice D (length 15) is twice shorter than all other choices', so it is great choice. There is no other great choices so the child will choose D. In the second sample, no choice is great, so the child will choose the luckiest choice C. In the third sample, the choice B (length 2) is twice longer than all other choices', so it is great choice. There is no other great choices so the child will choose B.
```python choice=[] for i in range(4): choice.append(len(input(' ')[2:])) Shortest=True Longest=True cc=0 ci=None for i in range(4): Shortest=True Longest=True for j in range(4): if i==j:continue if choice[i]<choice[j]*2:Longest=False if choice[i]*2>choice[j]:Shortest=False if Shortest:cc+=1;ci=chr(65+i) if Longest:cc+=1;ci=chr(65+i) if cc==1: print(ci) else: print('C') ```
3
581
A
Vasya the Hipster
PROGRAMMING
800
[ "implementation", "math" ]
null
null
One day Vasya the Hipster decided to count how many socks he had. It turned out that he had *a* red socks and *b* blue socks. According to the latest fashion, hipsters should wear the socks of different colors: a red one on the left foot, a blue one on the right foot. Every day Vasya puts on new socks in the morning and throws them away before going to bed as he doesn't want to wash them. Vasya wonders, what is the maximum number of days when he can dress fashionable and wear different socks, and after that, for how many days he can then wear the same socks until he either runs out of socks or cannot make a single pair from the socks he's got. Can you help him?
The single line of the input contains two positive integers *a* and *b* (1<=≤<=*a*,<=*b*<=≤<=100) — the number of red and blue socks that Vasya's got.
Print two space-separated integers — the maximum number of days when Vasya can wear different socks and the number of days when he can wear the same socks until he either runs out of socks or cannot make a single pair from the socks he's got. Keep in mind that at the end of the day Vasya throws away the socks that he's been wearing on that day.
[ "3 1\n", "2 3\n", "7 3\n" ]
[ "1 1\n", "2 0\n", "3 2\n" ]
In the first sample Vasya can first put on one pair of different socks, after that he has two red socks left to wear on the second day.
500
[ { "input": "3 1", "output": "1 1" }, { "input": "2 3", "output": "2 0" }, { "input": "7 3", "output": "3 2" }, { "input": "100 100", "output": "100 0" }, { "input": "4 10", "output": "4 3" }, { "input": "6 10", "output": "6 2" }, { "input": "6 11", "output": "6 2" }, { "input": "10 40", "output": "10 15" }, { "input": "11 56", "output": "11 22" }, { "input": "34 30", "output": "30 2" }, { "input": "33 33", "output": "33 0" }, { "input": "100 45", "output": "45 27" }, { "input": "100 23", "output": "23 38" }, { "input": "45 12", "output": "12 16" }, { "input": "1 1", "output": "1 0" }, { "input": "1 100", "output": "1 49" }, { "input": "100 1", "output": "1 49" }, { "input": "68 59", "output": "59 4" }, { "input": "45 99", "output": "45 27" }, { "input": "99 100", "output": "99 0" }, { "input": "100 98", "output": "98 1" }, { "input": "59 12", "output": "12 23" }, { "input": "86 4", "output": "4 41" }, { "input": "68 21", "output": "21 23" }, { "input": "100 11", "output": "11 44" }, { "input": "100 10", "output": "10 45" }, { "input": "15 45", "output": "15 15" }, { "input": "11 32", "output": "11 10" }, { "input": "34 96", "output": "34 31" }, { "input": "89 89", "output": "89 0" } ]
1,678,371,010
2,147,483,647
PyPy 3-64
OK
TESTS
30
62
0
a,b=map(int,input().split()) x=min(a,b) c=max(a,b) z=(c-x)//2 print(x,z)
Title: Vasya the Hipster Time Limit: None seconds Memory Limit: None megabytes Problem Description: One day Vasya the Hipster decided to count how many socks he had. It turned out that he had *a* red socks and *b* blue socks. According to the latest fashion, hipsters should wear the socks of different colors: a red one on the left foot, a blue one on the right foot. Every day Vasya puts on new socks in the morning and throws them away before going to bed as he doesn't want to wash them. Vasya wonders, what is the maximum number of days when he can dress fashionable and wear different socks, and after that, for how many days he can then wear the same socks until he either runs out of socks or cannot make a single pair from the socks he's got. Can you help him? Input Specification: The single line of the input contains two positive integers *a* and *b* (1<=≤<=*a*,<=*b*<=≤<=100) — the number of red and blue socks that Vasya's got. Output Specification: Print two space-separated integers — the maximum number of days when Vasya can wear different socks and the number of days when he can wear the same socks until he either runs out of socks or cannot make a single pair from the socks he's got. Keep in mind that at the end of the day Vasya throws away the socks that he's been wearing on that day. Demo Input: ['3 1\n', '2 3\n', '7 3\n'] Demo Output: ['1 1\n', '2 0\n', '3 2\n'] Note: In the first sample Vasya can first put on one pair of different socks, after that he has two red socks left to wear on the second day.
```python a,b=map(int,input().split()) x=min(a,b) c=max(a,b) z=(c-x)//2 print(x,z) ```
3
892
B
Wrath
PROGRAMMING
1,200
[ "greedy", "implementation", "two pointers" ]
null
null
Hands that shed innocent blood! There are *n* guilty people in a line, the *i*-th of them holds a claw with length *L**i*. The bell rings and every person kills some of people in front of him. All people kill others at the same time. Namely, the *i*-th person kills the *j*-th person if and only if *j*<=&lt;<=*i* and *j*<=≥<=*i*<=-<=*L**i*. You are given lengths of the claws. You need to find the total number of alive people after the bell rings.
The first line contains one integer *n* (1<=≤<=*n*<=≤<=106) — the number of guilty people. Second line contains *n* space-separated integers *L*1,<=*L*2,<=...,<=*L**n* (0<=≤<=*L**i*<=≤<=109), where *L**i* is the length of the *i*-th person's claw.
Print one integer — the total number of alive people after the bell rings.
[ "4\n0 1 0 10\n", "2\n0 0\n", "10\n1 1 3 0 0 0 2 1 0 3\n" ]
[ "1\n", "2\n", "3\n" ]
In first sample the last person kills everyone in front of him.
1,000
[ { "input": "4\n0 1 0 10", "output": "1" }, { "input": "2\n0 0", "output": "2" }, { "input": "10\n1 1 3 0 0 0 2 1 0 3", "output": "3" }, { "input": "10\n0 0 2 0 0 3 3 2 2 0", "output": "2" }, { "input": "1\n0", "output": "1" }, { "input": "5\n0 0 0 1 0", "output": "4" }, { "input": "6\n3 1 1 0 3 3", "output": "1" }, { "input": "8\n0 0 0 1 0 0 1 2", "output": "5" }, { "input": "1\n1000000000", "output": "1" }, { "input": "2\n1 3", "output": "1" }, { "input": "2\n1000000000 1000000000", "output": "1" }, { "input": "11\n1 0 0 1 1 3 2 0 0 2 3", "output": "4" }, { "input": "1\n1", "output": "1" } ]
1,608,194,300
2,147,483,647
Python 3
OK
TESTS
43
1,356
77,926,400
n=int(input()) l=[int(x) for x in input().split()] k=1; j=n-l[-1] for i in range(2, n+1): if j>n-i+1 and l[-i+1]==0: k+=1 j=min(j, n-i+1-l[-i]) print(k)
Title: Wrath Time Limit: None seconds Memory Limit: None megabytes Problem Description: Hands that shed innocent blood! There are *n* guilty people in a line, the *i*-th of them holds a claw with length *L**i*. The bell rings and every person kills some of people in front of him. All people kill others at the same time. Namely, the *i*-th person kills the *j*-th person if and only if *j*<=&lt;<=*i* and *j*<=≥<=*i*<=-<=*L**i*. You are given lengths of the claws. You need to find the total number of alive people after the bell rings. Input Specification: The first line contains one integer *n* (1<=≤<=*n*<=≤<=106) — the number of guilty people. Second line contains *n* space-separated integers *L*1,<=*L*2,<=...,<=*L**n* (0<=≤<=*L**i*<=≤<=109), where *L**i* is the length of the *i*-th person's claw. Output Specification: Print one integer — the total number of alive people after the bell rings. Demo Input: ['4\n0 1 0 10\n', '2\n0 0\n', '10\n1 1 3 0 0 0 2 1 0 3\n'] Demo Output: ['1\n', '2\n', '3\n'] Note: In first sample the last person kills everyone in front of him.
```python n=int(input()) l=[int(x) for x in input().split()] k=1; j=n-l[-1] for i in range(2, n+1): if j>n-i+1 and l[-i+1]==0: k+=1 j=min(j, n-i+1-l[-i]) print(k) ```
3
50
A
Domino piling
PROGRAMMING
800
[ "greedy", "math" ]
A. Domino piling
2
256
You are given a rectangular board of *M*<=×<=*N* squares. Also you are given an unlimited number of standard domino pieces of 2<=×<=1 squares. You are allowed to rotate the pieces. You are asked to place as many dominoes as possible on the board so as to meet the following conditions: 1. Each domino completely covers two squares. 2. No two dominoes overlap. 3. Each domino lies entirely inside the board. It is allowed to touch the edges of the board. Find the maximum number of dominoes, which can be placed under these restrictions.
In a single line you are given two integers *M* and *N* — board sizes in squares (1<=≤<=*M*<=≤<=*N*<=≤<=16).
Output one number — the maximal number of dominoes, which can be placed.
[ "2 4\n", "3 3\n" ]
[ "4\n", "4\n" ]
none
500
[ { "input": "2 4", "output": "4" }, { "input": "3 3", "output": "4" }, { "input": "1 5", "output": "2" }, { "input": "1 6", "output": "3" }, { "input": "1 15", "output": "7" }, { "input": "1 16", "output": "8" }, { "input": "2 5", "output": "5" }, { "input": "2 6", "output": "6" }, { "input": "2 7", "output": "7" }, { "input": "2 14", "output": "14" }, { "input": "2 15", "output": "15" }, { "input": "1 4", "output": "2" }, { "input": "2 16", "output": "16" }, { "input": "3 5", "output": "7" }, { "input": "3 6", "output": "9" }, { "input": "3 10", "output": "15" }, { "input": "3 14", "output": "21" }, { "input": "3 15", "output": "22" }, { "input": "3 16", "output": "24" }, { "input": "5 7", "output": "17" }, { "input": "16 16", "output": "128" }, { "input": "15 16", "output": "120" }, { "input": "2 3", "output": "3" }, { "input": "15 15", "output": "112" }, { "input": "14 16", "output": "112" }, { "input": "11 13", "output": "71" }, { "input": "5 16", "output": "40" }, { "input": "8 15", "output": "60" }, { "input": "2 2", "output": "2" }, { "input": "3 4", "output": "6" }, { "input": "4 4", "output": "8" }, { "input": "1 1", "output": "0" }, { "input": "1 2", "output": "1" }, { "input": "1 3", "output": "1" }, { "input": "14 15", "output": "105" } ]
1,683,417,466
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
0
30
0
def maximum_no_of_dominos(n,m): area = m *n return area//2
Title: Domino piling Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: You are given a rectangular board of *M*<=×<=*N* squares. Also you are given an unlimited number of standard domino pieces of 2<=×<=1 squares. You are allowed to rotate the pieces. You are asked to place as many dominoes as possible on the board so as to meet the following conditions: 1. Each domino completely covers two squares. 2. No two dominoes overlap. 3. Each domino lies entirely inside the board. It is allowed to touch the edges of the board. Find the maximum number of dominoes, which can be placed under these restrictions. Input Specification: In a single line you are given two integers *M* and *N* — board sizes in squares (1<=≤<=*M*<=≤<=*N*<=≤<=16). Output Specification: Output one number — the maximal number of dominoes, which can be placed. Demo Input: ['2 4\n', '3 3\n'] Demo Output: ['4\n', '4\n'] Note: none
```python def maximum_no_of_dominos(n,m): area = m *n return area//2 ```
0
378
A
Playing with Dice
PROGRAMMING
800
[ "brute force" ]
null
null
Two players are playing a game. First each of them writes an integer from 1 to 6, and then a dice is thrown. The player whose written number got closer to the number on the dice wins. If both payers have the same difference, it's a draw. The first player wrote number *a*, the second player wrote number *b*. How many ways to throw a dice are there, at which the first player wins, or there is a draw, or the second player wins?
The single line contains two integers *a* and *b* (1<=≤<=*a*,<=*b*<=≤<=6) — the numbers written on the paper by the first and second player, correspondingly.
Print three integers: the number of ways to throw the dice at which the first player wins, the game ends with a draw or the second player wins, correspondingly.
[ "2 5\n", "2 4\n" ]
[ "3 0 3\n", "2 1 3\n" ]
The dice is a standard cube-shaped six-sided object with each side containing a number from 1 to 6, and where all numbers on all sides are distinct. You can assume that number *a* is closer to number *x* than number *b*, if |*a* - *x*| &lt; |*b* - *x*|.
500
[ { "input": "2 5", "output": "3 0 3" }, { "input": "2 4", "output": "2 1 3" }, { "input": "5 3", "output": "2 1 3" }, { "input": "1 6", "output": "3 0 3" }, { "input": "5 1", "output": "3 1 2" }, { "input": "6 3", "output": "2 0 4" }, { "input": "2 3", "output": "2 0 4" }, { "input": "5 6", "output": "5 0 1" }, { "input": "4 4", "output": "0 6 0" }, { "input": "1 1", "output": "0 6 0" }, { "input": "6 4", "output": "1 1 4" }, { "input": "1 4", "output": "2 0 4" }, { "input": "5 5", "output": "0 6 0" }, { "input": "4 5", "output": "4 0 2" }, { "input": "4 3", "output": "3 0 3" }, { "input": "1 5", "output": "2 1 3" }, { "input": "6 5", "output": "1 0 5" }, { "input": "2 2", "output": "0 6 0" }, { "input": "1 3", "output": "1 1 4" }, { "input": "3 6", "output": "4 0 2" }, { "input": "3 1", "output": "4 1 1" }, { "input": "3 2", "output": "4 0 2" }, { "input": "3 5", "output": "3 1 2" }, { "input": "3 3", "output": "0 6 0" }, { "input": "6 2", "output": "2 1 3" }, { "input": "4 1", "output": "4 0 2" }, { "input": "5 2", "output": "3 0 3" }, { "input": "4 2", "output": "3 1 2" }, { "input": "2 1", "output": "5 0 1" }, { "input": "6 1", "output": "3 0 3" }, { "input": "4 6", "output": "4 1 1" }, { "input": "2 6", "output": "3 1 2" }, { "input": "3 4", "output": "3 0 3" }, { "input": "1 2", "output": "1 0 5" }, { "input": "6 6", "output": "0 6 0" }, { "input": "5 4", "output": "2 0 4" }, { "input": "3 3", "output": "0 6 0" }, { "input": "1 1", "output": "0 6 0" } ]
1,649,469,293
2,147,483,647
Python 3
OK
TESTS
38
46
0
a, b = [int(i) for i in input().split()] c, d, e = 0, 0, 0 for i in range(1, 7): if abs(a-i) < abs(b-i): c += 1 elif abs(a-i) == abs(b-i): d += 1 else: e += 1 print(c, d, e)
Title: Playing with Dice Time Limit: None seconds Memory Limit: None megabytes Problem Description: Two players are playing a game. First each of them writes an integer from 1 to 6, and then a dice is thrown. The player whose written number got closer to the number on the dice wins. If both payers have the same difference, it's a draw. The first player wrote number *a*, the second player wrote number *b*. How many ways to throw a dice are there, at which the first player wins, or there is a draw, or the second player wins? Input Specification: The single line contains two integers *a* and *b* (1<=≤<=*a*,<=*b*<=≤<=6) — the numbers written on the paper by the first and second player, correspondingly. Output Specification: Print three integers: the number of ways to throw the dice at which the first player wins, the game ends with a draw or the second player wins, correspondingly. Demo Input: ['2 5\n', '2 4\n'] Demo Output: ['3 0 3\n', '2 1 3\n'] Note: The dice is a standard cube-shaped six-sided object with each side containing a number from 1 to 6, and where all numbers on all sides are distinct. You can assume that number *a* is closer to number *x* than number *b*, if |*a* - *x*| &lt; |*b* - *x*|.
```python a, b = [int(i) for i in input().split()] c, d, e = 0, 0, 0 for i in range(1, 7): if abs(a-i) < abs(b-i): c += 1 elif abs(a-i) == abs(b-i): d += 1 else: e += 1 print(c, d, e) ```
3
158
A
Next Round
PROGRAMMING
800
[ "*special", "implementation" ]
null
null
"Contestant who earns a score equal to or greater than the *k*-th place finisher's score will advance to the next round, as long as the contestant earns a positive score..." — an excerpt from contest rules. A total of *n* participants took part in the contest (*n*<=≥<=*k*), and you already know their scores. Calculate how many participants will advance to the next round.
The first line of the input contains two integers *n* and *k* (1<=≤<=*k*<=≤<=*n*<=≤<=50) separated by a single space. The second line contains *n* space-separated integers *a*1,<=*a*2,<=...,<=*a**n* (0<=≤<=*a**i*<=≤<=100), where *a**i* is the score earned by the participant who got the *i*-th place. The given sequence is non-increasing (that is, for all *i* from 1 to *n*<=-<=1 the following condition is fulfilled: *a**i*<=≥<=*a**i*<=+<=1).
Output the number of participants who advance to the next round.
[ "8 5\n10 9 8 7 7 7 5 5\n", "4 2\n0 0 0 0\n" ]
[ "6\n", "0\n" ]
In the first example the participant on the 5th place earned 7 points. As the participant on the 6th place also earned 7 points, there are 6 advancers. In the second example nobody got a positive score.
500
[ { "input": "8 5\n10 9 8 7 7 7 5 5", "output": "6" }, { "input": "4 2\n0 0 0 0", "output": "0" }, { "input": "5 1\n1 1 1 1 1", "output": "5" }, { "input": "5 5\n1 1 1 1 1", "output": "5" }, { "input": "1 1\n10", "output": "1" }, { "input": "17 14\n16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0", "output": "14" }, { "input": "5 5\n3 2 1 0 0", "output": "3" }, { "input": "8 6\n10 9 8 7 7 7 5 5", "output": "6" }, { "input": "8 7\n10 9 8 7 7 7 5 5", "output": "8" }, { "input": "8 4\n10 9 8 7 7 7 5 5", "output": "6" }, { "input": "8 3\n10 9 8 7 7 7 5 5", "output": "3" }, { "input": "8 1\n10 9 8 7 7 7 5 5", "output": "1" }, { "input": "8 2\n10 9 8 7 7 7 5 5", "output": "2" }, { "input": "1 1\n100", "output": "1" }, { "input": "1 1\n0", "output": "0" }, { "input": "50 25\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", "output": "50" }, { "input": "50 25\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 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1", "output": "25" }, { "input": "50 25\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 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": "26" }, { "input": "50 25\n2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 1 1 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": "50" }, { "input": "11 5\n100 99 98 97 96 95 94 93 92 91 90", "output": "5" }, { "input": "10 4\n100 81 70 69 64 43 34 29 15 3", "output": "4" }, { "input": "11 6\n87 71 62 52 46 46 43 35 32 25 12", "output": "6" }, { "input": "17 12\n99 88 86 82 75 75 74 65 58 52 45 30 21 16 7 2 2", "output": "12" }, { "input": "20 3\n98 98 96 89 87 82 82 80 76 74 74 68 61 60 43 32 30 22 4 2", "output": "3" }, { "input": "36 12\n90 87 86 85 83 80 79 78 76 70 69 69 61 61 59 58 56 48 45 44 42 41 33 31 27 25 23 21 20 19 15 14 12 7 5 5", "output": "12" }, { "input": "49 8\n99 98 98 96 92 92 90 89 89 86 86 85 83 80 79 76 74 69 67 67 58 56 55 51 49 47 47 46 45 41 41 40 39 34 34 33 25 23 18 15 13 13 11 9 5 4 3 3 1", "output": "9" }, { "input": "49 29\n100 98 98 96 96 96 95 87 85 84 81 76 74 70 63 63 63 62 57 57 56 54 53 52 50 47 45 41 41 39 38 31 30 28 27 26 23 22 20 15 15 11 7 6 6 4 2 1 0", "output": "29" }, { "input": "49 34\n99 98 96 96 93 92 90 89 88 86 85 85 82 76 73 69 66 64 63 63 60 59 57 57 56 55 54 54 51 48 47 44 42 42 40 39 38 36 33 26 24 23 19 17 17 14 12 7 4", "output": "34" }, { "input": "50 44\n100 100 99 97 95 91 91 84 83 83 79 71 70 69 69 62 61 60 59 59 58 58 58 55 55 54 52 48 47 45 44 44 38 36 32 31 28 28 25 25 24 24 24 22 17 15 14 13 12 4", "output": "44" }, { "input": "50 13\n99 95 94 94 88 87 81 79 78 76 74 72 72 69 68 67 67 67 66 63 62 61 58 57 55 55 54 51 50 50 48 48 42 41 38 35 34 32 31 30 26 24 13 13 12 6 5 4 3 3", "output": "13" }, { "input": "50 30\n100 98 96 94 91 89 88 81 81 81 81 81 76 73 72 71 70 69 66 64 61 59 59 56 52 50 49 48 43 39 36 35 34 34 31 29 27 26 24 22 16 16 15 14 14 14 9 7 4 3", "output": "30" }, { "input": "2 1\n10 10", "output": "2" }, { "input": "2 2\n10 10", "output": "2" }, { "input": "2 2\n10 0", "output": "1" }, { "input": "2 2\n10 1", "output": "2" }, { "input": "2 1\n10 0", "output": "1" }, { "input": "2 1\n10 2", "output": "1" }, { "input": "50 13\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", "output": "0" }, { "input": "50 1\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0", "output": "0" }, { "input": "50 50\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", "output": "0" }, { "input": "10 1\n5 5 5 3 3 3 0 0 0 0", "output": "3" }, { "input": "10 2\n5 5 5 3 3 3 0 0 0 0", "output": "3" }, { "input": "10 3\n5 5 5 3 3 3 0 0 0 0", "output": "3" }, { "input": "10 4\n5 5 5 3 3 3 0 0 0 0", "output": "6" }, { "input": "10 5\n5 5 5 3 3 3 0 0 0 0", "output": "6" }, { "input": "10 6\n5 5 5 3 3 3 0 0 0 0", "output": "6" }, { "input": "10 7\n5 5 5 3 3 3 0 0 0 0", "output": "6" }, { "input": "10 8\n5 5 5 3 3 3 0 0 0 0", "output": "6" }, { "input": "10 9\n5 5 5 3 3 3 0 0 0 0", "output": "6" }, { "input": "10 10\n5 5 5 3 3 3 0 0 0 0", "output": "6" } ]
1,697,239,758
2,147,483,647
PyPy 3
WRONG_ANSWER
TESTS
1
154
0
n,k = list(map(int,input().split())) arr = list(map(int,input().split())) current_place = 1 advance = 0 last_advancer = arr[0] for p in arr: if p>0 and current_place<=k: advance+=1 last_advancer = arr[current_place] elif p<0: break elif current_place>k and current_place<len(arr): if arr[current_place] == p: advance+=1 current_place+=1 print(advance)
Title: Next Round Time Limit: None seconds Memory Limit: None megabytes Problem Description: "Contestant who earns a score equal to or greater than the *k*-th place finisher's score will advance to the next round, as long as the contestant earns a positive score..." — an excerpt from contest rules. A total of *n* participants took part in the contest (*n*<=≥<=*k*), and you already know their scores. Calculate how many participants will advance to the next round. Input Specification: The first line of the input contains two integers *n* and *k* (1<=≤<=*k*<=≤<=*n*<=≤<=50) separated by a single space. The second line contains *n* space-separated integers *a*1,<=*a*2,<=...,<=*a**n* (0<=≤<=*a**i*<=≤<=100), where *a**i* is the score earned by the participant who got the *i*-th place. The given sequence is non-increasing (that is, for all *i* from 1 to *n*<=-<=1 the following condition is fulfilled: *a**i*<=≥<=*a**i*<=+<=1). Output Specification: Output the number of participants who advance to the next round. Demo Input: ['8 5\n10 9 8 7 7 7 5 5\n', '4 2\n0 0 0 0\n'] Demo Output: ['6\n', '0\n'] Note: In the first example the participant on the 5th place earned 7 points. As the participant on the 6th place also earned 7 points, there are 6 advancers. In the second example nobody got a positive score.
```python n,k = list(map(int,input().split())) arr = list(map(int,input().split())) current_place = 1 advance = 0 last_advancer = arr[0] for p in arr: if p>0 and current_place<=k: advance+=1 last_advancer = arr[current_place] elif p<0: break elif current_place>k and current_place<len(arr): if arr[current_place] == p: advance+=1 current_place+=1 print(advance) ```
0
454
B
Little Pony and Sort by Shift
PROGRAMMING
1,200
[ "implementation" ]
null
null
One day, Twilight Sparkle is interested in how to sort a sequence of integers *a*1,<=*a*2,<=...,<=*a**n* in non-decreasing order. Being a young unicorn, the only operation she can perform is a unit shift. That is, she can move the last element of the sequence to its beginning: Help Twilight Sparkle to calculate: what is the minimum number of operations that she needs to sort the sequence?
The first line contains an integer *n* (2<=≤<=*n*<=≤<=105). The second line contains *n* integer numbers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=105).
If it's impossible to sort the sequence output -1. Otherwise output the minimum number of operations Twilight Sparkle needs to sort it.
[ "2\n2 1\n", "3\n1 3 2\n", "2\n1 2\n" ]
[ "1\n", "-1\n", "0\n" ]
none
1,000
[ { "input": "2\n2 1", "output": "1" }, { "input": "3\n1 3 2", "output": "-1" }, { "input": "2\n1 2", "output": "0" }, { "input": "6\n3 4 5 6 3 2", "output": "-1" }, { "input": "3\n1 2 1", "output": "1" }, { "input": "5\n1 1 2 1 1", "output": "2" }, { "input": "4\n5 4 5 4", "output": "-1" }, { "input": "7\n3 4 5 5 5 1 2", "output": "2" }, { "input": "5\n2 2 1 2 2", "output": "3" }, { "input": "5\n5 4 1 2 3", "output": "-1" }, { "input": "4\n6 1 2 7", "output": "-1" }, { "input": "5\n4 5 6 2 3", "output": "2" }, { "input": "2\n1 1", "output": "0" }, { "input": "4\n1 2 2 1", "output": "1" }, { "input": "9\n4 5 6 7 1 2 3 4 10", "output": "-1" }, { "input": "7\n2 3 4 1 2 3 4", "output": "-1" }, { "input": "6\n1 2 1 2 1 2", "output": "-1" }, { "input": "3\n3 2 1", "output": "-1" }, { "input": "4\n1 4 4 1", "output": "1" }, { "input": "5\n1 2 1 1 1", "output": "3" }, { "input": "5\n4 6 7 3 5", "output": "-1" }, { "input": "4\n2 3 1 4", "output": "-1" }, { "input": "5\n5 4 3 2 1", "output": "-1" }, { "input": "4\n2 4 1 4", "output": "-1" }, { "input": "6\n4 5 6 1 2 7", "output": "-1" }, { "input": "6\n1 2 3 1 1 1", "output": "3" }, { "input": "5\n1 3 3 3 1", "output": "1" }, { "input": "6\n5 6 7 5 5 5", "output": "3" }, { "input": "5\n3 4 2 1 2", "output": "-1" }, { "input": "3\n3 4 2", "output": "1" }, { "input": "6\n1 1 2 2 1 1", "output": "2" }, { "input": "4\n2 3 4 2", "output": "1" }, { "input": "5\n3 5 7 7 3", "output": "1" }, { "input": "4\n1 1 4 1", "output": "1" }, { "input": "7\n1 5 6 1 1 1 1", "output": "4" }, { "input": "5\n7 8 6 7 8", "output": "-1" }, { "input": "4\n2 4 1 3", "output": "-1" } ]
1,590,080,635
2,147,483,647
PyPy 3
WRONG_ANSWER
TESTS
4
202
10,444,800
n=int(input()) a=list(map(int,input().split())) r=min(a) f=0 for i in range(r+1,n): if a[i]<a[i-1]: f=1 break if f==1: print(-1) elif f==0 and r==a[0]: print(0) elif f==0: print(n-r)
Title: Little Pony and Sort by Shift Time Limit: None seconds Memory Limit: None megabytes Problem Description: One day, Twilight Sparkle is interested in how to sort a sequence of integers *a*1,<=*a*2,<=...,<=*a**n* in non-decreasing order. Being a young unicorn, the only operation she can perform is a unit shift. That is, she can move the last element of the sequence to its beginning: Help Twilight Sparkle to calculate: what is the minimum number of operations that she needs to sort the sequence? Input Specification: The first line contains an integer *n* (2<=≤<=*n*<=≤<=105). The second line contains *n* integer numbers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=105). Output Specification: If it's impossible to sort the sequence output -1. Otherwise output the minimum number of operations Twilight Sparkle needs to sort it. Demo Input: ['2\n2 1\n', '3\n1 3 2\n', '2\n1 2\n'] Demo Output: ['1\n', '-1\n', '0\n'] Note: none
```python n=int(input()) a=list(map(int,input().split())) r=min(a) f=0 for i in range(r+1,n): if a[i]<a[i-1]: f=1 break if f==1: print(-1) elif f==0 and r==a[0]: print(0) elif f==0: print(n-r) ```
0
0
none
none
none
0
[ "none" ]
null
null
Bear Limak examines a social network. Its main functionality is that two members can become friends (then they can talk with each other and share funny pictures). There are *n* members, numbered 1 through *n*. *m* pairs of members are friends. Of course, a member can't be a friend with themselves. Let A-B denote that members A and B are friends. Limak thinks that a network is reasonable if and only if the following condition is satisfied: For every three distinct members (X, Y, Z), if X-Y and Y-Z then also X-Z. For example: if Alan and Bob are friends, and Bob and Ciri are friends, then Alan and Ciri should be friends as well. Can you help Limak and check if the network is reasonable? Print "YES" or "NO" accordingly, without the quotes.
The first line of the input contain two integers *n* and *m* (3<=≤<=*n*<=≤<=150<=000, ) — the number of members and the number of pairs of members that are friends. The *i*-th of the next *m* lines contains two distinct integers *a**i* and *b**i* (1<=≤<=*a**i*,<=*b**i*<=≤<=*n*,<=*a**i*<=≠<=*b**i*). Members *a**i* and *b**i* are friends with each other. No pair of members will appear more than once in the input.
If the given network is reasonable, print "YES" in a single line (without the quotes). Otherwise, print "NO" in a single line (without the quotes).
[ "4 3\n1 3\n3 4\n1 4\n", "4 4\n3 1\n2 3\n3 4\n1 2\n", "10 4\n4 3\n5 10\n8 9\n1 2\n", "3 2\n1 2\n2 3\n" ]
[ "YES\n", "NO\n", "YES\n", "NO\n" ]
The drawings below show the situation in the first sample (on the left) and in the second sample (on the right). Each edge represents two members that are friends. The answer is "NO" in the second sample because members (2, 3) are friends and members (3, 4) are friends, while members (2, 4) are not.
0
[ { "input": "4 3\n1 3\n3 4\n1 4", "output": "YES" }, { "input": "4 4\n3 1\n2 3\n3 4\n1 2", "output": "NO" }, { "input": "10 4\n4 3\n5 10\n8 9\n1 2", "output": "YES" }, { "input": "3 2\n1 2\n2 3", "output": "NO" }, { "input": "3 0", "output": "YES" }, { "input": "15 42\n8 1\n3 14\n7 14\n12 3\n7 9\n6 7\n6 12\n14 12\n3 10\n10 14\n6 3\n3 13\n13 10\n7 12\n7 2\n6 10\n11 4\n9 3\n8 4\n7 3\n2 3\n2 10\n9 13\n2 14\n6 14\n13 2\n1 4\n13 6\n7 10\n13 14\n12 10\n13 7\n12 2\n9 10\n13 12\n2 6\n9 14\n6 9\n12 9\n11 1\n2 9\n11 8", "output": "YES" }, { "input": "20 80\n17 4\n10 1\n11 10\n17 7\n15 10\n14 15\n13 1\n18 13\n3 13\n12 7\n9 13\n10 12\n14 12\n18 11\n4 7\n10 13\n11 3\n19 8\n14 7\n10 17\n14 3\n7 11\n11 14\n19 5\n10 14\n15 17\n3 1\n9 10\n11 1\n4 1\n11 4\n9 1\n12 3\n13 7\n1 14\n11 12\n7 1\n9 12\n18 15\n17 3\n7 15\n4 10\n7 18\n7 9\n12 17\n14 18\n3 18\n18 17\n9 15\n14 4\n14 9\n9 18\n12 4\n7 10\n15 4\n4 18\n15 13\n1 12\n7 3\n13 11\n4 13\n5 8\n12 18\n12 15\n17 9\n11 15\n3 10\n18 10\n4 3\n15 3\n13 12\n9 4\n9 11\n14 17\n13 17\n3 9\n13 14\n1 17\n15 1\n17 11", "output": "NO" }, { "input": "99 26\n64 17\n48 70\n71 50\n3 50\n9 60\n61 64\n53 50\n25 12\n3 71\n71 53\n3 53\n65 70\n9 25\n9 12\n59 56\n39 60\n64 69\n65 94\n70 94\n25 60\n60 12\n94 48\n17 69\n61 17\n65 48\n61 69", "output": "NO" }, { "input": "3 1\n1 2", "output": "YES" }, { "input": "3 2\n3 2\n1 3", "output": "NO" }, { "input": "3 3\n2 3\n1 2\n1 3", "output": "YES" }, { "input": "4 2\n4 1\n2 1", "output": "NO" }, { "input": "4 3\n3 1\n2 1\n3 2", "output": "YES" }, { "input": "5 9\n1 2\n5 1\n3 1\n1 4\n2 4\n5 3\n5 4\n2 3\n5 2", "output": "NO" }, { "input": "10 5\n9 5\n1 2\n6 8\n6 3\n10 6", "output": "NO" }, { "input": "10 8\n10 7\n9 7\n5 7\n6 8\n3 5\n8 10\n3 4\n7 8", "output": "NO" }, { "input": "10 20\n8 2\n8 3\n1 8\n9 5\n2 4\n10 1\n10 5\n7 5\n7 8\n10 7\n6 5\n3 7\n1 9\n9 8\n7 2\n2 10\n2 1\n6 4\n9 7\n4 3", "output": "NO" }, { "input": "150000 10\n62562 50190\n48849 60549\n139470 18456\n21436 25159\n66845 120884\n99972 114453\n11631 99153\n62951 134848\n78114 146050\n136760 131762", "output": "YES" }, { "input": "150000 0", "output": "YES" }, { "input": "4 4\n1 2\n2 3\n3 4\n1 4", "output": "NO" }, { "input": "30 73\n25 2\n2 16\n20 12\n16 20\n7 18\n11 15\n13 11\n30 29\n16 12\n12 25\n2 1\n18 14\n9 8\n28 16\n2 9\n22 21\n1 25\n12 28\n14 7\n4 9\n26 7\n14 27\n12 2\n29 22\n1 9\n13 15\n3 10\n1 12\n8 20\n30 24\n25 20\n4 1\n4 12\n20 1\n8 4\n2 28\n25 16\n16 8\n20 4\n9 12\n21 30\n23 11\n19 6\n28 4\n29 21\n9 28\n30 10\n22 24\n25 8\n27 26\n25 4\n28 20\n9 25\n24 29\n20 9\n18 26\n1 28\n30 22\n23 15\n28 27\n8 2\n23 13\n12 8\n14 26\n16 4\n28 25\n8 1\n4 2\n9 16\n20 2\n18 27\n28 8\n27 7", "output": "NO" }, { "input": "5 4\n1 2\n2 5\n3 4\n4 5", "output": "NO" }, { "input": "4 4\n1 2\n2 3\n3 4\n4 1", "output": "NO" }, { "input": "6 6\n1 2\n2 4\n4 3\n1 5\n5 6\n6 3", "output": "NO" }, { "input": "3 2\n1 2\n1 3", "output": "NO" }, { "input": "6 6\n1 2\n2 3\n3 4\n4 5\n5 6\n1 6", "output": "NO" }, { "input": "4 4\n1 2\n1 3\n2 4\n3 4", "output": "NO" }, { "input": "6 9\n1 4\n1 5\n1 6\n2 4\n2 5\n2 6\n3 4\n3 5\n3 6", "output": "NO" }, { "input": "4 3\n1 2\n1 3\n3 4", "output": "NO" }, { "input": "4 3\n1 2\n1 3\n2 4", "output": "NO" }, { "input": "6 6\n1 2\n2 3\n3 4\n4 5\n5 6\n6 1", "output": "NO" }, { "input": "4 3\n1 2\n1 3\n1 4", "output": "NO" }, { "input": "150000 3\n150000 149999\n149998 149999\n149998 150000", "output": "YES" }, { "input": "10 15\n1 2\n1 3\n2 4\n2 5\n3 4\n3 5\n4 5\n1 6\n6 7\n6 8\n7 9\n7 10\n8 9\n8 10\n9 10", "output": "NO" }, { "input": "5 5\n1 2\n2 3\n3 4\n4 5\n5 1", "output": "NO" }, { "input": "5 4\n1 2\n1 3\n1 4\n1 5", "output": "NO" }, { "input": "9 9\n1 2\n2 3\n3 4\n4 5\n5 6\n6 7\n7 8\n8 9\n9 1", "output": "NO" }, { "input": "4 5\n1 2\n1 3\n1 4\n2 3\n3 4", "output": "NO" }, { "input": "4 4\n1 2\n1 3\n4 2\n4 3", "output": "NO" }, { "input": "5 5\n1 4\n5 3\n5 1\n2 3\n4 5", "output": "NO" }, { "input": "4 5\n1 2\n1 3\n2 3\n1 4\n2 4", "output": "NO" }, { "input": "4 5\n1 2\n1 3\n1 4\n2 3\n2 4", "output": "NO" }, { "input": "6 12\n1 2\n1 4\n1 5\n1 6\n2 3\n2 5\n2 6\n3 4\n3 5\n3 6\n4 5\n4 6", "output": "NO" }, { "input": "1000 4\n100 132\n100 164\n196 132\n196 164", "output": "NO" } ]
1,694,386,020
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
0
30
0
class UnionFind: def __init__(self, n): self.parent = list(range(n)) self.size = [1] * n def find(self, x): if self.parent[x] != x: self.parent[x] = self.find(self.parent[x]) return self.parent[x] def union(self, x, y): root_x = self.find(x) root_y = self.find(y) if root_x != root_y: if self.size[root_x] < self.size[root_y]: root_x, root_y = root_y, root_x self.parent[root_y] = root_x self.size[root_x] += self.size[root_y] def es_red_racional(n, relaciones): uf = UnionFind(n + 1) for a, b in relaciones: uf.union(a, b) for x in range(1, n + 1): for y in range(x + 1, n + 1): if uf.find(x) != uf.find(y): return "NO" return "YES" # Lectura de entrada n, m = map(int, input().split()) relaciones = [] for _ in range(m): a, b = map(int, input().split()) relaciones.append((a, b)) # Verificación y salida resultado = es_red_racional(n, relaciones) print(resultado)
Title: none Time Limit: None seconds Memory Limit: None megabytes Problem Description: Bear Limak examines a social network. Its main functionality is that two members can become friends (then they can talk with each other and share funny pictures). There are *n* members, numbered 1 through *n*. *m* pairs of members are friends. Of course, a member can't be a friend with themselves. Let A-B denote that members A and B are friends. Limak thinks that a network is reasonable if and only if the following condition is satisfied: For every three distinct members (X, Y, Z), if X-Y and Y-Z then also X-Z. For example: if Alan and Bob are friends, and Bob and Ciri are friends, then Alan and Ciri should be friends as well. Can you help Limak and check if the network is reasonable? Print "YES" or "NO" accordingly, without the quotes. Input Specification: The first line of the input contain two integers *n* and *m* (3<=≤<=*n*<=≤<=150<=000, ) — the number of members and the number of pairs of members that are friends. The *i*-th of the next *m* lines contains two distinct integers *a**i* and *b**i* (1<=≤<=*a**i*,<=*b**i*<=≤<=*n*,<=*a**i*<=≠<=*b**i*). Members *a**i* and *b**i* are friends with each other. No pair of members will appear more than once in the input. Output Specification: If the given network is reasonable, print "YES" in a single line (without the quotes). Otherwise, print "NO" in a single line (without the quotes). Demo Input: ['4 3\n1 3\n3 4\n1 4\n', '4 4\n3 1\n2 3\n3 4\n1 2\n', '10 4\n4 3\n5 10\n8 9\n1 2\n', '3 2\n1 2\n2 3\n'] Demo Output: ['YES\n', 'NO\n', 'YES\n', 'NO\n'] Note: The drawings below show the situation in the first sample (on the left) and in the second sample (on the right). Each edge represents two members that are friends. The answer is "NO" in the second sample because members (2, 3) are friends and members (3, 4) are friends, while members (2, 4) are not.
```python class UnionFind: def __init__(self, n): self.parent = list(range(n)) self.size = [1] * n def find(self, x): if self.parent[x] != x: self.parent[x] = self.find(self.parent[x]) return self.parent[x] def union(self, x, y): root_x = self.find(x) root_y = self.find(y) if root_x != root_y: if self.size[root_x] < self.size[root_y]: root_x, root_y = root_y, root_x self.parent[root_y] = root_x self.size[root_x] += self.size[root_y] def es_red_racional(n, relaciones): uf = UnionFind(n + 1) for a, b in relaciones: uf.union(a, b) for x in range(1, n + 1): for y in range(x + 1, n + 1): if uf.find(x) != uf.find(y): return "NO" return "YES" # Lectura de entrada n, m = map(int, input().split()) relaciones = [] for _ in range(m): a, b = map(int, input().split()) relaciones.append((a, b)) # Verificación y salida resultado = es_red_racional(n, relaciones) print(resultado) ```
0
869
B
The Eternal Immortality
PROGRAMMING
1,100
[ "math" ]
null
null
Even if the world is full of counterfeits, I still regard it as wonderful. Pile up herbs and incense, and arise again from the flames and ashes of its predecessor — as is known to many, the phoenix does it like this. The phoenix has a rather long lifespan, and reincarnates itself once every *a*! years. Here *a*! denotes the factorial of integer *a*, that is, *a*!<==<=1<=×<=2<=×<=...<=×<=*a*. Specifically, 0!<==<=1. Koyomi doesn't care much about this, but before he gets into another mess with oddities, he is interested in the number of times the phoenix will reincarnate in a timespan of *b*! years, that is, . Note that when *b*<=≥<=*a* this value is always integer. As the answer can be quite large, it would be enough for Koyomi just to know the last digit of the answer in decimal representation. And you're here to provide Koyomi with this knowledge.
The first and only line of input contains two space-separated integers *a* and *b* (0<=≤<=*a*<=≤<=*b*<=≤<=1018).
Output one line containing a single decimal digit — the last digit of the value that interests Koyomi.
[ "2 4\n", "0 10\n", "107 109\n" ]
[ "2\n", "0\n", "2\n" ]
In the first example, the last digit of <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/99c47ca8b182f097e38094d12f0c06ce0b081b76.png" style="max-width: 100.0%;max-height: 100.0%;"/> is 2; In the second example, the last digit of <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/9642ef11a23e7c5a3f3c2b1255c1b1b3533802a4.png" style="max-width: 100.0%;max-height: 100.0%;"/> is 0; In the third example, the last digit of <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/844938cef52ee264c183246d2a9df05cca94dc60.png" style="max-width: 100.0%;max-height: 100.0%;"/> is 2.
1,000
[ { "input": "2 4", "output": "2" }, { "input": "0 10", "output": "0" }, { "input": "107 109", "output": "2" }, { "input": "10 13", "output": "6" }, { "input": "998244355 998244359", "output": "4" }, { "input": "999999999000000000 1000000000000000000", "output": "0" }, { "input": "2 3", "output": "3" }, { "input": "3 15", "output": "0" }, { "input": "24 26", "output": "0" }, { "input": "14 60", "output": "0" }, { "input": "11 79", "output": "0" }, { "input": "1230 1232", "output": "2" }, { "input": "2633 2634", "output": "4" }, { "input": "535 536", "output": "6" }, { "input": "344319135 396746843", "output": "0" }, { "input": "696667767 696667767", "output": "1" }, { "input": "419530302 610096911", "output": "0" }, { "input": "238965115 821731161", "output": "0" }, { "input": "414626436 728903812", "output": "0" }, { "input": "274410639 293308324", "output": "0" }, { "input": "650636673091305697 650636673091305702", "output": "0" }, { "input": "651240548333620923 651240548333620924", "output": "4" }, { "input": "500000000000000000 1000000000000000000", "output": "0" }, { "input": "999999999999999999 1000000000000000000", "output": "0" }, { "input": "1000000000000000000 1000000000000000000", "output": "1" }, { "input": "0 4", "output": "4" }, { "input": "50000000062000007 50000000062000011", "output": "0" }, { "input": "0 0", "output": "1" }, { "input": "1 1", "output": "1" }, { "input": "0 2", "output": "2" }, { "input": "10000000000012 10000000000015", "output": "0" }, { "input": "5 5", "output": "1" }, { "input": "12 23", "output": "0" }, { "input": "0 11", "output": "0" }, { "input": "11111234567890 11111234567898", "output": "0" }, { "input": "0 3", "output": "6" }, { "input": "1 2", "output": "2" }, { "input": "999999999999999997 999999999999999999", "output": "2" }, { "input": "4 5", "output": "5" }, { "input": "0 1", "output": "1" }, { "input": "101 1002", "output": "0" }, { "input": "0 100000000000000001", "output": "0" }, { "input": "99999999999999997 99999999999999999", "output": "2" }, { "input": "14 15", "output": "5" }, { "input": "8 19", "output": "0" }, { "input": "12 22", "output": "0" }, { "input": "999999999999996 999999999999999", "output": "4" }, { "input": "1 3", "output": "6" }, { "input": "124 125", "output": "5" }, { "input": "11 32", "output": "0" }, { "input": "0 5", "output": "0" }, { "input": "0 999999", "output": "0" }, { "input": "151151151515 151151151526", "output": "0" }, { "input": "6 107", "output": "0" }, { "input": "5 16", "output": "0" }, { "input": "7 16", "output": "0" }, { "input": "6 19", "output": "0" }, { "input": "11113111111111 13111111111111", "output": "0" }, { "input": "1 1000", "output": "0" }, { "input": "24 25", "output": "5" }, { "input": "0 100000000000", "output": "0" }, { "input": "1 22", "output": "0" }, { "input": "999999999999999996 999999999999999999", "output": "4" } ]
1,615,988,976
2,147,483,647
PyPy 3
OK
TESTS
63
109
0
ans = 1 a,b=map(int,input().split()) '''b!/a! (b>=a) = (a+x)!/a! = (a+x)(a+x-1)(a+x-2)(a+x-3).....(a+x-(x-1))(a+x-x)! / a! = (a+x)(a+x-1)(a+x-2)(a+x-3).....(a+x-(x-1)) = (b)(b-1)(b-2)(b-3)(b-4)........(b-(x-1)) ''' if( (b -a) > (b % 10) ) : print(0) else : for i in range(b-a): ans*=(b-i) print(ans%10)
Title: The Eternal Immortality Time Limit: None seconds Memory Limit: None megabytes Problem Description: Even if the world is full of counterfeits, I still regard it as wonderful. Pile up herbs and incense, and arise again from the flames and ashes of its predecessor — as is known to many, the phoenix does it like this. The phoenix has a rather long lifespan, and reincarnates itself once every *a*! years. Here *a*! denotes the factorial of integer *a*, that is, *a*!<==<=1<=×<=2<=×<=...<=×<=*a*. Specifically, 0!<==<=1. Koyomi doesn't care much about this, but before he gets into another mess with oddities, he is interested in the number of times the phoenix will reincarnate in a timespan of *b*! years, that is, . Note that when *b*<=≥<=*a* this value is always integer. As the answer can be quite large, it would be enough for Koyomi just to know the last digit of the answer in decimal representation. And you're here to provide Koyomi with this knowledge. Input Specification: The first and only line of input contains two space-separated integers *a* and *b* (0<=≤<=*a*<=≤<=*b*<=≤<=1018). Output Specification: Output one line containing a single decimal digit — the last digit of the value that interests Koyomi. Demo Input: ['2 4\n', '0 10\n', '107 109\n'] Demo Output: ['2\n', '0\n', '2\n'] Note: In the first example, the last digit of <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/99c47ca8b182f097e38094d12f0c06ce0b081b76.png" style="max-width: 100.0%;max-height: 100.0%;"/> is 2; In the second example, the last digit of <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/9642ef11a23e7c5a3f3c2b1255c1b1b3533802a4.png" style="max-width: 100.0%;max-height: 100.0%;"/> is 0; In the third example, the last digit of <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/844938cef52ee264c183246d2a9df05cca94dc60.png" style="max-width: 100.0%;max-height: 100.0%;"/> is 2.
```python ans = 1 a,b=map(int,input().split()) '''b!/a! (b>=a) = (a+x)!/a! = (a+x)(a+x-1)(a+x-2)(a+x-3).....(a+x-(x-1))(a+x-x)! / a! = (a+x)(a+x-1)(a+x-2)(a+x-3).....(a+x-(x-1)) = (b)(b-1)(b-2)(b-3)(b-4)........(b-(x-1)) ''' if( (b -a) > (b % 10) ) : print(0) else : for i in range(b-a): ans*=(b-i) print(ans%10) ```
3
146
A
Lucky Ticket
PROGRAMMING
800
[ "implementation" ]
null
null
Petya loves lucky numbers very much. Everybody knows that lucky numbers are positive integers whose decimal record contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. Petya loves tickets very much. As we know, each ticket has a number that is a positive integer. Its length equals *n* (*n* is always even). Petya calls a ticket lucky if the ticket's number is a lucky number and the sum of digits in the first half (the sum of the first *n*<=/<=2 digits) equals the sum of digits in the second half (the sum of the last *n*<=/<=2 digits). Check if the given ticket is lucky.
The first line contains an even integer *n* (2<=≤<=*n*<=≤<=50) — the length of the ticket number that needs to be checked. The second line contains an integer whose length equals exactly *n* — the ticket number. The number may contain leading zeros.
On the first line print "YES" if the given ticket number is lucky. Otherwise, print "NO" (without the quotes).
[ "2\n47\n", "4\n4738\n", "4\n4774\n" ]
[ "NO\n", "NO\n", "YES\n" ]
In the first sample the sum of digits in the first half does not equal the sum of digits in the second half (4 ≠ 7). In the second sample the ticket number is not the lucky number.
500
[ { "input": "2\n47", "output": "NO" }, { "input": "4\n4738", "output": "NO" }, { "input": "4\n4774", "output": "YES" }, { "input": "4\n4570", "output": "NO" }, { "input": "6\n477477", "output": "YES" }, { "input": "6\n777777", "output": "YES" }, { "input": "20\n44444444444444444444", "output": "YES" }, { "input": "2\n44", "output": "YES" }, { "input": "10\n4745474547", "output": "NO" }, { "input": "14\n77770004444444", "output": "NO" }, { "input": "10\n4747777744", "output": "YES" }, { "input": "10\n1234567890", "output": "NO" }, { "input": "50\n44444444444444444444444444444444444444444444444444", "output": "YES" }, { "input": "50\n44444444444444444444444444444444444444444444444447", "output": "NO" }, { "input": "50\n74444444444444444444444444444444444444444444444444", "output": "NO" }, { "input": "50\n07777777777777777777777777777777777777777777777770", "output": "NO" }, { "input": "50\n77777777777777777777777777777777777777777777777777", "output": "YES" }, { "input": "50\n44747747774474747747747447777447774747447477444474", "output": "YES" }, { "input": "48\n447474444777444474747747744774447444747474774474", "output": "YES" }, { "input": "32\n74474474777444474444747774474774", "output": "YES" }, { "input": "40\n4747777444447747777447447747447474774777", "output": "YES" }, { "input": "10\n4477477444", "output": "YES" }, { "input": "18\n447747474447744747", "output": "YES" }, { "input": "26\n44747744444774744774474447", "output": "YES" }, { "input": "50\n44707747774474747747747447777447774747447477444474", "output": "NO" }, { "input": "40\n4747777444447737777447447747447474774777", "output": "NO" }, { "input": "36\n764477744747444444447747747474744444", "output": "NO" }, { "input": "22\n4477407474777477744447", "output": "NO" }, { "input": "32\n74274474777444474444747774474774", "output": "NO" }, { "input": "16\n4744447974444747", "output": "NO" }, { "input": "2\n11", "output": "NO" }, { "input": "2\n22", "output": "NO" }, { "input": "2\n33", "output": "NO" }, { "input": "2\n74", "output": "NO" }, { "input": "2\n55", "output": "NO" }, { "input": "2\n66", "output": "NO" }, { "input": "2\n77", "output": "YES" }, { "input": "2\n88", "output": "NO" }, { "input": "2\n99", "output": "NO" }, { "input": "4\n4004", "output": "NO" }, { "input": "14\n00077774444444", "output": "NO" }, { "input": "6\n004444", "output": "NO" }, { "input": "4\n0044", "output": "NO" }, { "input": "14\n77771114444444", "output": "NO" }, { "input": "14\n44444447777000", "output": "NO" }, { "input": "6\n004774", "output": "NO" } ]
1,625,115,662
2,147,483,647
PyPy 3
OK
TESTS
46
216
0
def f(n, s): for i in s: if(i not in ['4', '7']): print("NO") return s1 = s[:n//2] s2 = s[n//2:] ans1 = 0 ans2 = 0 for i in range(n//2): ans1 += int(s1[i]) ans2 += int(s2[i]) if(ans1 == ans2): print("YES") else: print("NO") n = int(input()) s = input() f(n, s)
Title: Lucky Ticket Time Limit: None seconds Memory Limit: None megabytes Problem Description: Petya loves lucky numbers very much. Everybody knows that lucky numbers are positive integers whose decimal record contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. Petya loves tickets very much. As we know, each ticket has a number that is a positive integer. Its length equals *n* (*n* is always even). Petya calls a ticket lucky if the ticket's number is a lucky number and the sum of digits in the first half (the sum of the first *n*<=/<=2 digits) equals the sum of digits in the second half (the sum of the last *n*<=/<=2 digits). Check if the given ticket is lucky. Input Specification: The first line contains an even integer *n* (2<=≤<=*n*<=≤<=50) — the length of the ticket number that needs to be checked. The second line contains an integer whose length equals exactly *n* — the ticket number. The number may contain leading zeros. Output Specification: On the first line print "YES" if the given ticket number is lucky. Otherwise, print "NO" (without the quotes). Demo Input: ['2\n47\n', '4\n4738\n', '4\n4774\n'] Demo Output: ['NO\n', 'NO\n', 'YES\n'] Note: In the first sample the sum of digits in the first half does not equal the sum of digits in the second half (4 ≠ 7). In the second sample the ticket number is not the lucky number.
```python def f(n, s): for i in s: if(i not in ['4', '7']): print("NO") return s1 = s[:n//2] s2 = s[n//2:] ans1 = 0 ans2 = 0 for i in range(n//2): ans1 += int(s1[i]) ans2 += int(s2[i]) if(ans1 == ans2): print("YES") else: print("NO") n = int(input()) s = input() f(n, s) ```
3
6
E
Exposition
PROGRAMMING
1,900
[ "binary search", "data structures", "dsu", "trees", "two pointers" ]
E. Exposition
1
64
There are several days left before the fiftieth birthday of a famous Berland's writer Berlbury. In this connection the local library decided to make an exposition of the works of this famous science-fiction writer. It was decided as well that it is necessary to include into the exposition only those books that were published during a particular time period. It is obvious that if the books differ much in size, the visitors will not like it. That was why the organizers came to the opinion, that the difference between the highest and the lowest books in the exposition should be not more than *k* millimeters. The library has *n* volumes of books by Berlbury, arranged in chronological order of their appearance. The height of each book in millimeters is know, it is *h**i*. As Berlbury is highly respected in the city, the organizers want to include into the exposition as many books as possible, and to find out what periods of his creative work they will manage to cover. You are asked to help the organizers cope with this hard task.
The first line of the input data contains two integer numbers separated by a space *n* (1<=≤<=*n*<=≤<=105) and *k* (0<=≤<=*k*<=≤<=106) — the amount of books by Berlbury in the library, and the maximum allowed height difference between the lowest and the highest books. The second line contains *n* integer numbers separated by a space. Each number *h**i* (1<=≤<=*h**i*<=≤<=106) is the height of the *i*-th book in millimeters.
In the first line of the output data print two numbers *a* and *b* (separate them by a space), where *a* is the maximum amount of books the organizers can include into the exposition, and *b* — the amount of the time periods, during which Berlbury published *a* books, and the height difference between the lowest and the highest among these books is not more than *k* milllimeters. In each of the following *b* lines print two integer numbers separated by a space — indexes of the first and the last volumes from each of the required time periods of Berlbury's creative work.
[ "3 3\n14 12 10\n", "2 0\n10 10\n", "4 5\n8 19 10 13\n" ]
[ "2 2\n1 2\n2 3\n", "2 1\n1 2\n", "2 1\n3 4\n" ]
none
0
[ { "input": "3 3\n14 12 10", "output": "2 2\n1 2\n2 3" }, { "input": "2 0\n10 10", "output": "2 1\n1 2" }, { "input": "4 5\n8 19 10 13", "output": "2 1\n3 4" }, { "input": "1 1\n1", "output": "1 1\n1 1" }, { "input": "2 10\n35 45", "output": "2 1\n1 2" }, { "input": "4 8\n89 33 54 75", "output": "1 4\n1 1\n2 2\n3 3\n4 4" }, { "input": "5 1\n9 6 8 7 5", "output": "2 1\n3 4" }, { "input": "3 3\n3 8 6", "output": "2 1\n2 3" }, { "input": "4 1000000\n100001 1 200001 300001", "output": "4 1\n1 4" }, { "input": "4 1000\n11497 9999 10730 12280", "output": "2 1\n2 3" }, { "input": "3 0\n1000000 1000000 1000000", "output": "3 1\n1 3" }, { "input": "4 50\n165 182 157 132", "output": "4 1\n1 4" }, { "input": "5 173\n350 250 200 300 400", "output": "4 1\n1 4" }, { "input": "4 0\n1 1 1 1", "output": "4 1\n1 4" }, { "input": "2 1000000\n1 1000000", "output": "2 1\n1 2" }, { "input": "7 14\n28 28 29 35 25 29 28", "output": "7 1\n1 7" }, { "input": "10 163\n7541 2535 5883 5775 2821 5962 4489 5548 2852 4595", "output": "2 1\n3 4" }, { "input": "15 793\n98580 27440 3719 73977 34819 64092 89939 75329 72884 66502 17464 73662 6666 47984 45348", "output": "1 15\n1 1\n2 2\n3 3\n4 4\n5 5\n6 6\n7 7\n8 8\n9 9\n10 10\n11 11\n12 12\n13 13\n14 14\n15 15" }, { "input": "28 543\n1921 1700 1363 2580 2693 3144 2269 908 3863 3750 2151 3039 1581 3395 1133 1804 1464 2040 2372 2475 1240 800 3521 3270 2815 1026 3625 2930", "output": "3 1\n18 20" }, { "input": "55 1000\n2612 1306 4300 1790 3173 9493 7209 7763 8563 4534 7466 1281 4483 6863 3787 7292 3957 8775 7221 4016 5743 6556 2070 2119 4795 9094 1913 2077 8786 4520 1865 2357 7871 3288 8231 5808 9383 9820 9974 3056 5343 2169 5177 6299 5805 8132 9315 6747 5226 3531 1206 4073 8290 1423 6720", "output": "3 1\n37 39" } ]
1,459,417,820
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
0
31
4,812,800
n,k=[int(i) for i in input().split()] h=[int(i) for i in input().split()] l=[] a=0 for i in range(n): l.append(h[i]) a=max(a,len(l)-1) if max(l)-min(l)>k: while max(l)-min(l)>k: l.pop(0) if i==n-1: a=max(a,len(l)) b=0 l=[] count=0 tmp=[] a1=0 for i in range(n): l.append(h[i]) a1=max(a1,len(l)-1) if max(l)-min(l)>k: while max(l)-min(l)>k: l.pop(0) count+=1 if i==n-1: a1=max(a1,len(l)) if a1==a: b+=1 tmp.append([count+1,len(l)+count]) print(a,b) for i in tmp: print(i[0],i[1])
Title: Exposition Time Limit: 1 seconds Memory Limit: 64 megabytes Problem Description: There are several days left before the fiftieth birthday of a famous Berland's writer Berlbury. In this connection the local library decided to make an exposition of the works of this famous science-fiction writer. It was decided as well that it is necessary to include into the exposition only those books that were published during a particular time period. It is obvious that if the books differ much in size, the visitors will not like it. That was why the organizers came to the opinion, that the difference between the highest and the lowest books in the exposition should be not more than *k* millimeters. The library has *n* volumes of books by Berlbury, arranged in chronological order of their appearance. The height of each book in millimeters is know, it is *h**i*. As Berlbury is highly respected in the city, the organizers want to include into the exposition as many books as possible, and to find out what periods of his creative work they will manage to cover. You are asked to help the organizers cope with this hard task. Input Specification: The first line of the input data contains two integer numbers separated by a space *n* (1<=≤<=*n*<=≤<=105) and *k* (0<=≤<=*k*<=≤<=106) — the amount of books by Berlbury in the library, and the maximum allowed height difference between the lowest and the highest books. The second line contains *n* integer numbers separated by a space. Each number *h**i* (1<=≤<=*h**i*<=≤<=106) is the height of the *i*-th book in millimeters. Output Specification: In the first line of the output data print two numbers *a* and *b* (separate them by a space), where *a* is the maximum amount of books the organizers can include into the exposition, and *b* — the amount of the time periods, during which Berlbury published *a* books, and the height difference between the lowest and the highest among these books is not more than *k* milllimeters. In each of the following *b* lines print two integer numbers separated by a space — indexes of the first and the last volumes from each of the required time periods of Berlbury's creative work. Demo Input: ['3 3\n14 12 10\n', '2 0\n10 10\n', '4 5\n8 19 10 13\n'] Demo Output: ['2 2\n1 2\n2 3\n', '2 1\n1 2\n', '2 1\n3 4\n'] Note: none
```python n,k=[int(i) for i in input().split()] h=[int(i) for i in input().split()] l=[] a=0 for i in range(n): l.append(h[i]) a=max(a,len(l)-1) if max(l)-min(l)>k: while max(l)-min(l)>k: l.pop(0) if i==n-1: a=max(a,len(l)) b=0 l=[] count=0 tmp=[] a1=0 for i in range(n): l.append(h[i]) a1=max(a1,len(l)-1) if max(l)-min(l)>k: while max(l)-min(l)>k: l.pop(0) count+=1 if i==n-1: a1=max(a1,len(l)) if a1==a: b+=1 tmp.append([count+1,len(l)+count]) print(a,b) for i in tmp: print(i[0],i[1]) ```
0
888
B
Buggy Robot
PROGRAMMING
1,000
[ "greedy" ]
null
null
Ivan has a robot which is situated on an infinite grid. Initially the robot is standing in the starting cell (0,<=0). The robot can process commands. There are four types of commands it can perform: - U — move from the cell (*x*,<=*y*) to (*x*,<=*y*<=+<=1); - D — move from (*x*,<=*y*) to (*x*,<=*y*<=-<=1); - L — move from (*x*,<=*y*) to (*x*<=-<=1,<=*y*); - R — move from (*x*,<=*y*) to (*x*<=+<=1,<=*y*). Ivan entered a sequence of *n* commands, and the robot processed it. After this sequence the robot ended up in the starting cell (0,<=0), but Ivan doubts that the sequence is such that after performing it correctly the robot ends up in the same cell. He thinks that some commands were ignored by robot. To acknowledge whether the robot is severely bugged, he needs to calculate the maximum possible number of commands that were performed correctly. Help Ivan to do the calculations!
The first line contains one number *n* — the length of sequence of commands entered by Ivan (1<=≤<=*n*<=≤<=100). The second line contains the sequence itself — a string consisting of *n* characters. Each character can be U, D, L or R.
Print the maximum possible number of commands from the sequence the robot could perform to end up in the starting cell.
[ "4\nLDUR\n", "5\nRRRUU\n", "6\nLLRRRR\n" ]
[ "4\n", "0\n", "4\n" ]
none
0
[ { "input": "4\nLDUR", "output": "4" }, { "input": "5\nRRRUU", "output": "0" }, { "input": "6\nLLRRRR", "output": "4" }, { "input": "88\nLLUUULRDRRURDDLURRLRDRLLRULRUUDDLLLLRRDDURDURRLDURRLDRRRUULDDLRRRDDRRLUULLURDURUDDDDDLDR", "output": "76" }, { "input": "89\nLDLLLDRDUDURRRRRUDULDDDLLUDLRLRLRLDLDUULRDUDLRRDLUDLURRDDRRDLDUDUUURUUUDRLUDUDLURDLDLLDDU", "output": "80" }, { "input": "90\nRRRDUULLLRDUUDDRLDLRLUDURDRDUUURUURDDRRRURLDDDUUDRLLLULURDRDRURLDRRRRUULDULDDLLLRRLRDLLLLR", "output": "84" }, { "input": "91\nRLDRLRRLLDLULULLURULLRRULUDUULLUDULDUULURUDRUDUURDULDUDDUUUDRRUUDLLRULRULURLDRDLDRURLLLRDDD", "output": "76" }, { "input": "92\nRLRDDLULRLLUURRDDDLDDDLDDUURRRULLRDULDULLLUUULDUDLRLRRDRDRDDULDRLUDRDULDRURUDUULLRDRRLLDRLRR", "output": "86" }, { "input": "93\nRLLURLULRURDDLUURLUDDRDLUURLRDLRRRDUULLRDRRLRLDURRDLLRDDLLLDDDLDRRURLLDRUDULDDRRULRRULRLDRDLR", "output": "84" }, { "input": "94\nRDULDDDLULRDRUDRUUDUUDRRRULDRRUDURUULRDUUDLULLLUDURRDRDLUDRULRRRULUURUDDDDDUDLLRDLDRLLRUUURLUL", "output": "86" }, { "input": "95\nRDLUUULLUURDDRLDLLRRRULRLRDULULRULRUDURLULDDDRLURLDRULDUDUUULLRDDURUULULLDDLDRDRLLLURLRDLLDDDDU", "output": "86" }, { "input": "96\nRDDRLRLLDDULRLRURUDLRLDUDRURLLUUDLLURDLRRUURDRRUDRURLLDLLRDURDURLRLUDURULLLRDUURULUUULRRURRDLURL", "output": "84" }, { "input": "97\nRURDDLRLLRULUDURDLRLLUUDURRLLUDLLLDUDRUULDRUUURURULRDLDRRLLUUUDLLLDDLLLLRLLDUDRRDLLUDLRURUDULRLUR", "output": "82" }, { "input": "98\nRUDURLULLDDLLRDLLRDDLLLLRLDDDDRRRDDRRURLDRLLRUUUDLUUUDDDUDRUURLURUUDUUDRULRRULLRRLRULLULDLUURLULRD", "output": "92" }, { "input": "99\nRRULLDULRRDRULLDUDRUDDDRLLUUDRDDUDURLDDRUUDRRUUURRRURDDLDUURDLRLURRDDLUDDLUDURDRUDDURLURURLRUDRURLD", "output": "86" }, { "input": "100\nUDRLRRLLRRLRRRDDLLDDDLULLDDLURUURUULUDDDRDDLLRDLLUURLRDRLRRLRLLLULDUDDUURRLRDULDRDURRRRRRULDRRDLDRRL", "output": "88" }, { "input": "1\nU", "output": "0" }, { "input": "5\nUUULD", "output": "2" }, { "input": "1\nD", "output": "0" }, { "input": "5\nURLUL", "output": "2" }, { "input": "5\nDDDRU", "output": "2" }, { "input": "2\nLR", "output": "2" }, { "input": "8\nDDRDLDUR", "output": "4" }, { "input": "6\nLLLLUD", "output": "2" }, { "input": "13\nRRRLLLLLLLLLL", "output": "6" } ]
1,630,831,003
2,147,483,647
Python 3
OK
TESTS
25
77
6,758,400
#888B (62No. Problem B) n = int(input()) seq = input() l = seq.count('L') r = seq.count('R') u = seq.count('U') d = seq.count('D') steps = (min(l,r) + min(u,d)) * 2 print(steps)
Title: Buggy Robot Time Limit: None seconds Memory Limit: None megabytes Problem Description: Ivan has a robot which is situated on an infinite grid. Initially the robot is standing in the starting cell (0,<=0). The robot can process commands. There are four types of commands it can perform: - U — move from the cell (*x*,<=*y*) to (*x*,<=*y*<=+<=1); - D — move from (*x*,<=*y*) to (*x*,<=*y*<=-<=1); - L — move from (*x*,<=*y*) to (*x*<=-<=1,<=*y*); - R — move from (*x*,<=*y*) to (*x*<=+<=1,<=*y*). Ivan entered a sequence of *n* commands, and the robot processed it. After this sequence the robot ended up in the starting cell (0,<=0), but Ivan doubts that the sequence is such that after performing it correctly the robot ends up in the same cell. He thinks that some commands were ignored by robot. To acknowledge whether the robot is severely bugged, he needs to calculate the maximum possible number of commands that were performed correctly. Help Ivan to do the calculations! Input Specification: The first line contains one number *n* — the length of sequence of commands entered by Ivan (1<=≤<=*n*<=≤<=100). The second line contains the sequence itself — a string consisting of *n* characters. Each character can be U, D, L or R. Output Specification: Print the maximum possible number of commands from the sequence the robot could perform to end up in the starting cell. Demo Input: ['4\nLDUR\n', '5\nRRRUU\n', '6\nLLRRRR\n'] Demo Output: ['4\n', '0\n', '4\n'] Note: none
```python #888B (62No. Problem B) n = int(input()) seq = input() l = seq.count('L') r = seq.count('R') u = seq.count('U') d = seq.count('D') steps = (min(l,r) + min(u,d)) * 2 print(steps) ```
3
381
A
Sereja and Dima
PROGRAMMING
800
[ "greedy", "implementation", "two pointers" ]
null
null
Sereja and Dima play a game. The rules of the game are very simple. The players have *n* cards in a row. Each card contains a number, all numbers on the cards are distinct. The players take turns, Sereja moves first. During his turn a player can take one card: either the leftmost card in a row, or the rightmost one. The game ends when there is no more cards. The player who has the maximum sum of numbers on his cards by the end of the game, wins. Sereja and Dima are being greedy. Each of them chooses the card with the larger number during his move. Inna is a friend of Sereja and Dima. She knows which strategy the guys are using, so she wants to determine the final score, given the initial state of the game. Help her.
The first line contains integer *n* (1<=≤<=*n*<=≤<=1000) — the number of cards on the table. The second line contains space-separated numbers on the cards from left to right. The numbers on the cards are distinct integers from 1 to 1000.
On a single line, print two integers. The first number is the number of Sereja's points at the end of the game, the second number is the number of Dima's points at the end of the game.
[ "4\n4 1 2 10\n", "7\n1 2 3 4 5 6 7\n" ]
[ "12 5\n", "16 12\n" ]
In the first sample Sereja will take cards with numbers 10 and 2, so Sereja's sum is 12. Dima will take cards with numbers 4 and 1, so Dima's sum is 5.
500
[ { "input": "4\n4 1 2 10", "output": "12 5" }, { "input": "7\n1 2 3 4 5 6 7", "output": "16 12" }, { "input": "42\n15 29 37 22 16 5 26 31 6 32 19 3 45 36 33 14 25 20 48 7 42 11 24 28 9 18 8 21 47 17 38 40 44 4 35 1 43 39 41 27 12 13", "output": "613 418" }, { "input": "43\n32 1 15 48 38 26 25 14 20 44 11 30 3 42 49 19 18 46 5 45 10 23 34 9 29 41 2 52 6 17 35 4 50 22 33 51 7 28 47 13 39 37 24", "output": "644 500" }, { "input": "1\n3", "output": "3 0" }, { "input": "45\n553 40 94 225 415 471 126 190 647 394 515 303 189 159 308 6 139 132 326 78 455 75 85 295 135 613 360 614 351 228 578 259 258 591 444 29 33 463 561 174 368 183 140 168 646", "output": "6848 6568" }, { "input": "44\n849 373 112 307 479 608 856 769 526 82 168 143 573 762 115 501 688 36 214 450 396 496 236 309 287 786 397 43 811 141 745 846 350 270 276 677 420 459 403 722 267 54 394 727", "output": "9562 9561" }, { "input": "35\n10 15 18 1 28 16 2 33 6 22 23 4 9 25 35 8 7 26 3 20 30 14 31 19 27 32 11 5 29 24 21 34 13 17 12", "output": "315 315" }, { "input": "17\n580 376 191 496 73 44 520 357 483 149 81 178 514 300 216 598 304", "output": "3238 2222" }, { "input": "30\n334 443 223 424 168 549 189 303 429 559 516 220 459 134 344 346 316 446 209 148 487 526 69 286 102 366 518 280 392 325", "output": "5246 4864" }, { "input": "95\n122 29 188 265 292 287 183 225 222 187 155 256 64 148 173 278 218 136 290 17 31 130 2 87 57 283 255 280 68 166 174 142 102 39 116 206 288 154 26 78 296 172 184 232 77 91 277 8 249 186 94 93 207 251 257 195 101 299 193 124 293 65 58 35 24 302 220 189 252 125 27 284 247 182 141 103 198 97 234 83 281 216 85 180 267 236 109 143 149 239 79 300 191 244 71", "output": "8147 7807" }, { "input": "1\n1", "output": "1 0" } ]
1,668,194,717
2,147,483,647
Python 3
OK
TESTS
34
46
0
a = int(input()) b = input().split() sum1 = 0 sum2 = 0 i = 0 while len(b) != 0: if int(b[0]) > int(b[-1]): sum1+=int(b[0]) b.pop(0) else: sum1 +=int(b[-1]) b.pop() if len(b) == 0: break if int(b[0]) > int(b[-1]): sum2+=int(b[0]) b.pop(0) else: sum2 +=int(b[-1]) b.pop() print(sum1,sum2)
Title: Sereja and Dima Time Limit: None seconds Memory Limit: None megabytes Problem Description: Sereja and Dima play a game. The rules of the game are very simple. The players have *n* cards in a row. Each card contains a number, all numbers on the cards are distinct. The players take turns, Sereja moves first. During his turn a player can take one card: either the leftmost card in a row, or the rightmost one. The game ends when there is no more cards. The player who has the maximum sum of numbers on his cards by the end of the game, wins. Sereja and Dima are being greedy. Each of them chooses the card with the larger number during his move. Inna is a friend of Sereja and Dima. She knows which strategy the guys are using, so she wants to determine the final score, given the initial state of the game. Help her. Input Specification: The first line contains integer *n* (1<=≤<=*n*<=≤<=1000) — the number of cards on the table. The second line contains space-separated numbers on the cards from left to right. The numbers on the cards are distinct integers from 1 to 1000. Output Specification: On a single line, print two integers. The first number is the number of Sereja's points at the end of the game, the second number is the number of Dima's points at the end of the game. Demo Input: ['4\n4 1 2 10\n', '7\n1 2 3 4 5 6 7\n'] Demo Output: ['12 5\n', '16 12\n'] Note: In the first sample Sereja will take cards with numbers 10 and 2, so Sereja's sum is 12. Dima will take cards with numbers 4 and 1, so Dima's sum is 5.
```python a = int(input()) b = input().split() sum1 = 0 sum2 = 0 i = 0 while len(b) != 0: if int(b[0]) > int(b[-1]): sum1+=int(b[0]) b.pop(0) else: sum1 +=int(b[-1]) b.pop() if len(b) == 0: break if int(b[0]) > int(b[-1]): sum2+=int(b[0]) b.pop(0) else: sum2 +=int(b[-1]) b.pop() print(sum1,sum2) ```
3
39
J
Spelling Check
PROGRAMMING
1,500
[ "hashing", "implementation", "strings" ]
J. Spelling Check
2
256
Petya has noticed that when he types using a keyboard, he often presses extra buttons and adds extra letters to the words. Of course, the spell-checking system underlines the words for him and he has to click every word and choose the right variant. Petya got fed up with correcting his mistakes himself, that’s why he decided to invent the function that will correct the words itself. Petya started from analyzing the case that happens to him most of the time, when all one needs is to delete one letter for the word to match a word from the dictionary. Thus, Petya faces one mini-task: he has a printed word and a word from the dictionary, and he should delete one letter from the first word to get the second one. And now the very non-trivial question that Petya faces is: which letter should he delete?
The input data contains two strings, consisting of lower-case Latin letters. The length of each string is from 1 to 106 symbols inclusive, the first string contains exactly 1 symbol more than the second one.
In the first line output the number of positions of the symbols in the first string, after the deleting of which the first string becomes identical to the second one. In the second line output space-separated positions of these symbols in increasing order. The positions are numbered starting from 1. If it is impossible to make the first string identical to the second string by deleting one symbol, output one number 0.
[ "abdrakadabra\nabrakadabra\n", "aa\na\n", "competition\ncodeforces\n" ]
[ "1\n3\n", "2\n1 2\n", "0\n" ]
none
0
[ { "input": "abdrakadabra\nabrakadabra", "output": "1\n3 " }, { "input": "aa\na", "output": "2\n1 2 " }, { "input": "competition\ncodeforces", "output": "0" }, { "input": "ab\na", "output": "1\n2 " }, { "input": "bb\nb", "output": "2\n1 2 " }, { "input": "aab\nab", "output": "2\n1 2 " }, { "input": "aabb\nabb", "output": "2\n1 2 " }, { "input": "babaacaacaa\nbbaacaacaa", "output": "1\n2 " }, { "input": "bccaabbcccc\nbccaabcccc", "output": "2\n6 7 " }, { "input": "ababcaabaaa\nabacaabaaa", "output": "1\n4 " }, { "input": "cccacaccacb\ncccacaccac", "output": "1\n11 " }, { "input": "aaaaaaaaaaa\naaaaaaaaaa", "output": "11\n1 2 3 4 5 6 7 8 9 10 11 " }, { "input": "lcaaxcbcjca\nccaaacccca", "output": "0" }, { "input": "babbbtaamba\nbabbbaabba", "output": "0" }, { "input": "xdfxmcnzpch\nazvotghvtk", "output": "0" }, { "input": "ki\nb", "output": "0" }, { "input": "vct\nie", "output": "0" }, { "input": "feee\nsnl", "output": "0" }, { "input": "cbxxxxzvks\ncbxxxzvks", "output": "4\n3 4 5 6 " }, { "input": "qybldcgfhdhhhhhhhhhhopqkhuczzytzluiahwbqjltgafvvoecititchjwdoljiehubngmtjckqymldhoncgtqhxnqvoagnrmur\nqybldcgfhdhhhhhhhhhopqkhuczzytzluiahwbqjltgafvvoecititchjwdoljiehubngmtjckqymldhoncgtqhxnqvoagnrmur", "output": "10\n11 12 13 14 15 16 17 18 19 20 " } ]
1,688,333,005
2,147,483,647
PyPy 3-64
OK
TESTS
40
872
10,547,200
import sys s1 = sys.stdin.readline().strip() s2 = sys.stdin.readline().strip() l = 0 while l < len(s2) and s1[l] == s2[l]: l += 1 r = len(s1) - 1 while r>=1 and s1[r] == s2[r-1]: r -= 1 r = len(s1) - r - 1 total = (l + 1) - (len(s1) - r) + 1 if total < 0: total = 0 print(total) for i in range(total): if i + 1 < total: end = ' ' else: end = '\n' print(i + len(s1) - r, end=end)
Title: Spelling Check Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: Petya has noticed that when he types using a keyboard, he often presses extra buttons and adds extra letters to the words. Of course, the spell-checking system underlines the words for him and he has to click every word and choose the right variant. Petya got fed up with correcting his mistakes himself, that’s why he decided to invent the function that will correct the words itself. Petya started from analyzing the case that happens to him most of the time, when all one needs is to delete one letter for the word to match a word from the dictionary. Thus, Petya faces one mini-task: he has a printed word and a word from the dictionary, and he should delete one letter from the first word to get the second one. And now the very non-trivial question that Petya faces is: which letter should he delete? Input Specification: The input data contains two strings, consisting of lower-case Latin letters. The length of each string is from 1 to 106 symbols inclusive, the first string contains exactly 1 symbol more than the second one. Output Specification: In the first line output the number of positions of the symbols in the first string, after the deleting of which the first string becomes identical to the second one. In the second line output space-separated positions of these symbols in increasing order. The positions are numbered starting from 1. If it is impossible to make the first string identical to the second string by deleting one symbol, output one number 0. Demo Input: ['abdrakadabra\nabrakadabra\n', 'aa\na\n', 'competition\ncodeforces\n'] Demo Output: ['1\n3\n', '2\n1 2\n', '0\n'] Note: none
```python import sys s1 = sys.stdin.readline().strip() s2 = sys.stdin.readline().strip() l = 0 while l < len(s2) and s1[l] == s2[l]: l += 1 r = len(s1) - 1 while r>=1 and s1[r] == s2[r-1]: r -= 1 r = len(s1) - r - 1 total = (l + 1) - (len(s1) - r) + 1 if total < 0: total = 0 print(total) for i in range(total): if i + 1 < total: end = ' ' else: end = '\n' print(i + len(s1) - r, end=end) ```
3.762354
519
B
A and B and Compilation Errors
PROGRAMMING
1,100
[ "data structures", "implementation", "sortings" ]
null
null
A and B are preparing themselves for programming contests. B loves to debug his code. But before he runs the solution and starts debugging, he has to first compile the code. Initially, the compiler displayed *n* compilation errors, each of them is represented as a positive integer. After some effort, B managed to fix some mistake and then another one mistake. However, despite the fact that B is sure that he corrected the two errors, he can not understand exactly what compilation errors disappeared — the compiler of the language which B uses shows errors in the new order every time! B is sure that unlike many other programming languages, compilation errors for his programming language do not depend on each other, that is, if you correct one error, the set of other error does not change. Can you help B find out exactly what two errors he corrected?
The first line of the input contains integer *n* (3<=≤<=*n*<=≤<=105) — the initial number of compilation errors. The second line contains *n* space-separated integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=109) — the errors the compiler displayed for the first time. The third line contains *n*<=-<=1 space-separated integers *b*1,<=*b*2,<=...,<=*b**n*<=-<=1 — the errors displayed at the second compilation. It is guaranteed that the sequence in the third line contains all numbers of the second string except for exactly one. The fourth line contains *n*<=-<=2 space-separated integers *с*1,<=*с*2,<=...,<=*с**n*<=-<=2 — the errors displayed at the third compilation. It is guaranteed that the sequence in the fourth line contains all numbers of the third line except for exactly one.
Print two numbers on a single line: the numbers of the compilation errors that disappeared after B made the first and the second correction, respectively.
[ "5\n1 5 8 123 7\n123 7 5 1\n5 1 7\n", "6\n1 4 3 3 5 7\n3 7 5 4 3\n4 3 7 5\n" ]
[ "8\n123\n", "1\n3\n" ]
In the first test sample B first corrects the error number 8, then the error number 123. In the second test sample B first corrects the error number 1, then the error number 3. Note that if there are multiple errors with the same number, B can correct only one of them in one step.
1,000
[ { "input": "5\n1 5 8 123 7\n123 7 5 1\n5 1 7", "output": "8\n123" }, { "input": "6\n1 4 3 3 5 7\n3 7 5 4 3\n4 3 7 5", "output": "1\n3" }, { "input": "3\n1 2 3\n3 2\n2", "output": "1\n3" }, { "input": "10\n460626451 802090732 277246428 661369649 388684428 784303821 376287098 656422756 9301599 25720377\n277246428 388684428 661369649 460626451 656422756 802090732 9301599 784303821 376287098\n376287098 802090732 388684428 9301599 656422756 784303821 460626451 277246428", "output": "25720377\n661369649" }, { "input": "3\n796067435 964699482 819602309\n964699482 796067435\n964699482", "output": "819602309\n796067435" }, { "input": "3\n374054998 726316780 902899520\n902899520 726316780\n726316780", "output": "374054998\n902899520" }, { "input": "3\n168638990 939116221 323703261\n168638990 323703261\n168638990", "output": "939116221\n323703261" }, { "input": "3\n77 77 77\n77 77\n77", "output": "77\n77" }, { "input": "3\n84 30 9\n9 84\n9", "output": "30\n84" }, { "input": "6\n5 4 3 3 5 5\n3 5 5 4 3\n3 5 4 3", "output": "5\n5" }, { "input": "4\n1 5 7 8\n1 5 7\n1 5", "output": "8\n7" } ]
1,683,992,571
2,147,483,647
Python 3
OK
TESTS
33
202
23,142,400
def cleaner(la, lb): la.sort() lb.sort() for i, v in enumerate(la): if i < len(lb) and lb[i] != v: return v return la[-1] n = int(input()) f = list(map(int, input().split())) s = list(map(int, input().split())) t = list(map(int, input().split())) print(cleaner(f, s)) print(cleaner(s, t))
Title: A and B and Compilation Errors Time Limit: None seconds Memory Limit: None megabytes Problem Description: A and B are preparing themselves for programming contests. B loves to debug his code. But before he runs the solution and starts debugging, he has to first compile the code. Initially, the compiler displayed *n* compilation errors, each of them is represented as a positive integer. After some effort, B managed to fix some mistake and then another one mistake. However, despite the fact that B is sure that he corrected the two errors, he can not understand exactly what compilation errors disappeared — the compiler of the language which B uses shows errors in the new order every time! B is sure that unlike many other programming languages, compilation errors for his programming language do not depend on each other, that is, if you correct one error, the set of other error does not change. Can you help B find out exactly what two errors he corrected? Input Specification: The first line of the input contains integer *n* (3<=≤<=*n*<=≤<=105) — the initial number of compilation errors. The second line contains *n* space-separated integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=109) — the errors the compiler displayed for the first time. The third line contains *n*<=-<=1 space-separated integers *b*1,<=*b*2,<=...,<=*b**n*<=-<=1 — the errors displayed at the second compilation. It is guaranteed that the sequence in the third line contains all numbers of the second string except for exactly one. The fourth line contains *n*<=-<=2 space-separated integers *с*1,<=*с*2,<=...,<=*с**n*<=-<=2 — the errors displayed at the third compilation. It is guaranteed that the sequence in the fourth line contains all numbers of the third line except for exactly one. Output Specification: Print two numbers on a single line: the numbers of the compilation errors that disappeared after B made the first and the second correction, respectively. Demo Input: ['5\n1 5 8 123 7\n123 7 5 1\n5 1 7\n', '6\n1 4 3 3 5 7\n3 7 5 4 3\n4 3 7 5\n'] Demo Output: ['8\n123\n', '1\n3\n'] Note: In the first test sample B first corrects the error number 8, then the error number 123. In the second test sample B first corrects the error number 1, then the error number 3. Note that if there are multiple errors with the same number, B can correct only one of them in one step.
```python def cleaner(la, lb): la.sort() lb.sort() for i, v in enumerate(la): if i < len(lb) and lb[i] != v: return v return la[-1] n = int(input()) f = list(map(int, input().split())) s = list(map(int, input().split())) t = list(map(int, input().split())) print(cleaner(f, s)) print(cleaner(s, t)) ```
3
792
A
New Bus Route
PROGRAMMING
1,100
[ "implementation", "sortings" ]
null
null
There are *n* cities situated along the main road of Berland. Cities are represented by their coordinates — integer numbers *a*1,<=*a*2,<=...,<=*a**n*. All coordinates are pairwise distinct. It is possible to get from one city to another only by bus. But all buses and roads are very old, so the Minister of Transport decided to build a new bus route. The Minister doesn't want to spend large amounts of money — he wants to choose two cities in such a way that the distance between them is minimal possible. The distance between two cities is equal to the absolute value of the difference between their coordinates. It is possible that there are multiple pairs of cities with minimal possible distance, so the Minister wants to know the quantity of such pairs. Your task is to write a program that will calculate the minimal possible distance between two pairs of cities and the quantity of pairs which have this distance.
The first line contains one integer number *n* (2<=≤<=*n*<=≤<=2·105). The second line contains *n* integer numbers *a*1,<=*a*2,<=...,<=*a**n* (<=-<=109<=≤<=*a**i*<=≤<=109). All numbers *a**i* are pairwise distinct.
Print two integer numbers — the minimal distance and the quantity of pairs with this distance.
[ "4\n6 -3 0 4\n", "3\n-2 0 2\n" ]
[ "2 1\n", "2 2\n" ]
In the first example the distance between the first city and the fourth city is |4 - 6| = 2, and it is the only pair with this distance.
0
[ { "input": "4\n6 -3 0 4", "output": "2 1" }, { "input": "3\n-2 0 2", "output": "2 2" }, { "input": "2\n1 2", "output": "1 1" }, { "input": "2\n1000000000 -1000000000", "output": "2000000000 1" }, { "input": "5\n-979619606 -979619602 -979619604 -979619605 -979619603", "output": "1 4" }, { "input": "5\n-799147771 -799147773 -799147764 -799147774 -799147770", "output": "1 2" }, { "input": "20\n553280626 553280623 553280627 553280624 553280625 553280618 553280620 553280629 553280637 553280631 553280628 553280636 553280635 553280632 553280634 553280622 553280633 553280621 553280630 553280619", "output": "1 19" }, { "input": "20\n105619866 106083760 106090730 105809555 106115212 105155938 105979518 106075627 106145216 105637844 105925719 105498536 105927000 106155938 106134226 106125969 106130588 105464813 106145509 106114971", "output": "241 1" }, { "input": "10\n570685866 570685854 570685858 570685850 570685856 570685864 570685860 570685852 570685862 570685868", "output": "2 9" }, { "input": "2\n1 1000000000", "output": "999999999 1" }, { "input": "6\n1 2 3 4 5 6", "output": "1 5" }, { "input": "3\n7 10 12", "output": "2 1" }, { "input": "5\n-7 -5 -4 -3 -1", "output": "1 2" }, { "input": "4\n-6 -4 -2 1", "output": "2 2" }, { "input": "4\n3 5 7 8", "output": "1 1" }, { "input": "9\n-9 -8 -7 -6 -5 -4 -3 -2 -1", "output": "1 8" }, { "input": "2\n15 13", "output": "2 1" }, { "input": "2\n14 13", "output": "1 1" }, { "input": "2\n12 13", "output": "1 1" }, { "input": "2\n-1000000000 13265920", "output": "1013265920 1" }, { "input": "2\n8 10", "output": "2 1" } ]
1,546,469,896
316
Python 3
OK
TESTS
45
358
17,408,000
import math import os import random import re import sys def mindist(n, list): list.sort() lista = [] for i in range(n-1): lista.append(list[i+1] - list[i]) mi = min(lista) count = lista.count(mi) return [mi, count] if __name__ == '__main__': n = int(input()) list = list(map(int, input().rstrip().split())) [mi, count] = mindist(n, list) print(str(mi) + " " + str(count))
Title: New Bus Route Time Limit: None seconds Memory Limit: None megabytes Problem Description: There are *n* cities situated along the main road of Berland. Cities are represented by their coordinates — integer numbers *a*1,<=*a*2,<=...,<=*a**n*. All coordinates are pairwise distinct. It is possible to get from one city to another only by bus. But all buses and roads are very old, so the Minister of Transport decided to build a new bus route. The Minister doesn't want to spend large amounts of money — he wants to choose two cities in such a way that the distance between them is minimal possible. The distance between two cities is equal to the absolute value of the difference between their coordinates. It is possible that there are multiple pairs of cities with minimal possible distance, so the Minister wants to know the quantity of such pairs. Your task is to write a program that will calculate the minimal possible distance between two pairs of cities and the quantity of pairs which have this distance. Input Specification: The first line contains one integer number *n* (2<=≤<=*n*<=≤<=2·105). The second line contains *n* integer numbers *a*1,<=*a*2,<=...,<=*a**n* (<=-<=109<=≤<=*a**i*<=≤<=109). All numbers *a**i* are pairwise distinct. Output Specification: Print two integer numbers — the minimal distance and the quantity of pairs with this distance. Demo Input: ['4\n6 -3 0 4\n', '3\n-2 0 2\n'] Demo Output: ['2 1\n', '2 2\n'] Note: In the first example the distance between the first city and the fourth city is |4 - 6| = 2, and it is the only pair with this distance.
```python import math import os import random import re import sys def mindist(n, list): list.sort() lista = [] for i in range(n-1): lista.append(list[i+1] - list[i]) mi = min(lista) count = lista.count(mi) return [mi, count] if __name__ == '__main__': n = int(input()) list = list(map(int, input().rstrip().split())) [mi, count] = mindist(n, list) print(str(mi) + " " + str(count)) ```
3
569
A
Music
PROGRAMMING
1,500
[ "implementation", "math" ]
null
null
Little Lesha loves listening to music via his smartphone. But the smartphone doesn't have much memory, so Lesha listens to his favorite songs in a well-known social network InTalk. Unfortunately, internet is not that fast in the city of Ekaterinozavodsk and the song takes a lot of time to download. But Lesha is quite impatient. The song's duration is *T* seconds. Lesha downloads the first *S* seconds of the song and plays it. When the playback reaches the point that has not yet been downloaded, Lesha immediately plays the song from the start (the loaded part of the song stays in his phone, and the download is continued from the same place), and it happens until the song is downloaded completely and Lesha listens to it to the end. For *q* seconds of real time the Internet allows you to download *q*<=-<=1 seconds of the track. Tell Lesha, for how many times he will start the song, including the very first start.
The single line contains three integers *T*,<=*S*,<=*q* (2<=≤<=*q*<=≤<=104, 1<=≤<=*S*<=&lt;<=*T*<=≤<=105).
Print a single integer — the number of times the song will be restarted.
[ "5 2 2\n", "5 4 7\n", "6 2 3\n" ]
[ "2\n", "1\n", "1\n" ]
In the first test, the song is played twice faster than it is downloaded, which means that during four first seconds Lesha reaches the moment that has not been downloaded, and starts the song again. After another two seconds, the song is downloaded completely, and thus, Lesha starts the song twice. In the second test, the song is almost downloaded, and Lesha will start it only once. In the third sample test the download finishes and Lesha finishes listening at the same moment. Note that song isn't restarted in this case.
500
[ { "input": "5 2 2", "output": "2" }, { "input": "5 4 7", "output": "1" }, { "input": "6 2 3", "output": "1" }, { "input": "2 1 2", "output": "1" }, { "input": "2 1 3", "output": "1" }, { "input": "2 1 10000", "output": "1" }, { "input": "12326 6163 2", "output": "1" }, { "input": "10000 2500 4", "output": "1" }, { "input": "100000 99999 4", "output": "1" }, { "input": "12351 1223 6", "output": "2" }, { "input": "100000 1 10000", "output": "2" }, { "input": "10028 13 10000", "output": "1" }, { "input": "100000 99999 2", "output": "1" }, { "input": "100000 99999 3", "output": "1" }, { "input": "100000 1 2", "output": "17" }, { "input": "100000 1 3", "output": "11" }, { "input": "100000 1 4", "output": "9" }, { "input": "100000 1 5", "output": "8" }, { "input": "100000 3125 2", "output": "5" }, { "input": "12628 1804 7", "output": "1" }, { "input": "100000 45 13", "output": "4" }, { "input": "100000 500 3", "output": "5" }, { "input": "356 2 3", "output": "5" }, { "input": "50 2 2", "output": "5" }, { "input": "65465 12 3", "output": "8" }, { "input": "10033 3 8", "output": "4" }, { "input": "100000 3 2", "output": "16" }, { "input": "64 1 8", "output": "2" }, { "input": "10000 9 2", "output": "11" }, { "input": "25 2 2", "output": "4" }, { "input": "129 2 2", "output": "7" }, { "input": "6562 1 3", "output": "9" }, { "input": "100000 1 10", "output": "5" } ]
1,439,234,488
2,147,483,647
Python 3
COMPILATION_ERROR
TESTS
0
0
0
#include <stdio.h> int main(void){ long T, S, q; scanf("%ld %ld %ld", &T, &S, &q); long count = 0; long downloaded = S; while (downloaded < T){ downloaded = q * downloaded; /* v1 = 1sec/s, v2 = (q-1)/q sec/s, \Delta v = v1 - v2 = * 1 - q/q + 1/q = 1/q * Thus, the playback progress bar is aproaching the download * progress bar at 1/q sec/s. It will advance by 1 sec in q real * seconds and reach the download progress bar in downloaded * q * real seconds. This is also the amount of downloaded song when * the playback stops. */ count++; } printf("%ld\n", count); return 0; }
Title: Music Time Limit: None seconds Memory Limit: None megabytes Problem Description: Little Lesha loves listening to music via his smartphone. But the smartphone doesn't have much memory, so Lesha listens to his favorite songs in a well-known social network InTalk. Unfortunately, internet is not that fast in the city of Ekaterinozavodsk and the song takes a lot of time to download. But Lesha is quite impatient. The song's duration is *T* seconds. Lesha downloads the first *S* seconds of the song and plays it. When the playback reaches the point that has not yet been downloaded, Lesha immediately plays the song from the start (the loaded part of the song stays in his phone, and the download is continued from the same place), and it happens until the song is downloaded completely and Lesha listens to it to the end. For *q* seconds of real time the Internet allows you to download *q*<=-<=1 seconds of the track. Tell Lesha, for how many times he will start the song, including the very first start. Input Specification: The single line contains three integers *T*,<=*S*,<=*q* (2<=≤<=*q*<=≤<=104, 1<=≤<=*S*<=&lt;<=*T*<=≤<=105). Output Specification: Print a single integer — the number of times the song will be restarted. Demo Input: ['5 2 2\n', '5 4 7\n', '6 2 3\n'] Demo Output: ['2\n', '1\n', '1\n'] Note: In the first test, the song is played twice faster than it is downloaded, which means that during four first seconds Lesha reaches the moment that has not been downloaded, and starts the song again. After another two seconds, the song is downloaded completely, and thus, Lesha starts the song twice. In the second test, the song is almost downloaded, and Lesha will start it only once. In the third sample test the download finishes and Lesha finishes listening at the same moment. Note that song isn't restarted in this case.
```python #include <stdio.h> int main(void){ long T, S, q; scanf("%ld %ld %ld", &T, &S, &q); long count = 0; long downloaded = S; while (downloaded < T){ downloaded = q * downloaded; /* v1 = 1sec/s, v2 = (q-1)/q sec/s, \Delta v = v1 - v2 = * 1 - q/q + 1/q = 1/q * Thus, the playback progress bar is aproaching the download * progress bar at 1/q sec/s. It will advance by 1 sec in q real * seconds and reach the download progress bar in downloaded * q * real seconds. This is also the amount of downloaded song when * the playback stops. */ count++; } printf("%ld\n", count); return 0; } ```
-1
667
A
Pouring Rain
PROGRAMMING
1,100
[ "geometry", "math" ]
null
null
A lot of people in Berland hates rain, but you do not. Rain pacifies, puts your thoughts in order. By these years you have developed a good tradition — when it rains, you go on the street and stay silent for a moment, contemplate all around you, enjoy freshness, think about big deeds you have to do. Today everything had changed quietly. You went on the street with a cup contained water, your favorite drink. In a moment when you were drinking a water you noticed that the process became quite long: the cup still contained water because of rain. You decided to make a formal model of what was happening and to find if it was possible to drink all water in that situation. Thus, your cup is a cylinder with diameter equals *d* centimeters. Initial level of water in cup equals *h* centimeters from the bottom. You drink a water with a speed equals *v* milliliters per second. But rain goes with such speed that if you do not drink a water from the cup, the level of water increases on *e* centimeters per second. The process of drinking water from the cup and the addition of rain to the cup goes evenly and continuously. Find the time needed to make the cup empty or find that it will never happen. It is guaranteed that if it is possible to drink all water, it will happen not later than after 104 seconds. Note one milliliter equals to one cubic centimeter.
The only line of the input contains four integer numbers *d*,<=*h*,<=*v*,<=*e* (1<=≤<=*d*,<=*h*,<=*v*,<=*e*<=≤<=104), where: - *d* — the diameter of your cylindrical cup, - *h* — the initial level of water in the cup, - *v* — the speed of drinking process from the cup in milliliters per second, - *e* — the growth of water because of rain if you do not drink from the cup.
If it is impossible to make the cup empty, print "NO" (without quotes). Otherwise print "YES" (without quotes) in the first line. In the second line print a real number — time in seconds needed the cup will be empty. The answer will be considered correct if its relative or absolute error doesn't exceed 10<=-<=4. It is guaranteed that if the answer exists, it doesn't exceed 104.
[ "1 2 3 100\n", "1 1 1 1\n" ]
[ "NO\n", "YES\n3.659792366325\n" ]
In the first example the water fills the cup faster than you can drink from it. In the second example area of the cup's bottom equals to <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/419dc74dcd7bc392019c9fe748fe1fdb08ab521a.png" style="max-width: 100.0%;max-height: 100.0%;"/>, thus we can conclude that you decrease the level of water by <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/e8edb237e1f805fe83c2f47e48d3a9d03f2ee304.png" style="max-width: 100.0%;max-height: 100.0%;"/> centimeters per second. At the same time water level increases by 1 centimeter per second due to rain. Thus, cup will be empty in <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/9dae615d7e2c5c7c03cb478848fb06aba1a8942e.png" style="max-width: 100.0%;max-height: 100.0%;"/> seconds.
500
[ { "input": "1 2 3 100", "output": "NO" }, { "input": "1 1 1 1", "output": "YES\n3.659792366325" }, { "input": "48 7946 7992 72", "output": "NO" }, { "input": "72 6791 8546 46", "output": "NO" }, { "input": "100 5635 9099 23", "output": "NO" }, { "input": "20 287 3845 5", "output": "YES\n39.646277165210" }, { "input": "48 6428 9807 83", "output": "NO" }, { "input": "72 5272 4552 64", "output": "NO" }, { "input": "100 4117 5106 34", "output": "NO" }, { "input": "20 2961 9852 15", "output": "YES\n180.991437129723" }, { "input": "48 1805 3109 93", "output": "NO" }, { "input": "72 8534 7042 65", "output": "NO" }, { "input": "1 47 80 68", "output": "YES\n1.388102806810" }, { "input": "4 495 8813 1", "output": "YES\n0.706823517575" }, { "input": "5 2797 5925 9", "output": "YES\n9.553973511669" }, { "input": "1 8324 4362 23", "output": "YES\n1.505007106354" }, { "input": "6 1976 8455 3", "output": "YES\n6.674898722265" }, { "input": "7 2644 8080 5", "output": "YES\n12.900417790197" }, { "input": "3 4183 5491 98", "output": "YES\n6.162185601824" }, { "input": "2 8591 320 101", "output": "YES\n9999.259991757254" }, { "input": "10000 10000 10000 10000", "output": "NO" }, { "input": "2 5000 12 3", "output": "YES\n6099.653943875812" }, { "input": "10 1000 100 1", "output": "YES\n3659.792366325487" } ]
1,461,948,520
820
Python 3
OK
TESTS
23
62
5,120,000
import math def first(): inp = input().split(" ") d = float(inp[0]) h = float(inp[1]) v = float(inp[2]) e = float(inp[3]) h_y = v/(math.pi*(d/2)**2) if(h_y > e): print("YES") print(h/(h_y - e)) else: print("NO") first()
Title: Pouring Rain Time Limit: None seconds Memory Limit: None megabytes Problem Description: A lot of people in Berland hates rain, but you do not. Rain pacifies, puts your thoughts in order. By these years you have developed a good tradition — when it rains, you go on the street and stay silent for a moment, contemplate all around you, enjoy freshness, think about big deeds you have to do. Today everything had changed quietly. You went on the street with a cup contained water, your favorite drink. In a moment when you were drinking a water you noticed that the process became quite long: the cup still contained water because of rain. You decided to make a formal model of what was happening and to find if it was possible to drink all water in that situation. Thus, your cup is a cylinder with diameter equals *d* centimeters. Initial level of water in cup equals *h* centimeters from the bottom. You drink a water with a speed equals *v* milliliters per second. But rain goes with such speed that if you do not drink a water from the cup, the level of water increases on *e* centimeters per second. The process of drinking water from the cup and the addition of rain to the cup goes evenly and continuously. Find the time needed to make the cup empty or find that it will never happen. It is guaranteed that if it is possible to drink all water, it will happen not later than after 104 seconds. Note one milliliter equals to one cubic centimeter. Input Specification: The only line of the input contains four integer numbers *d*,<=*h*,<=*v*,<=*e* (1<=≤<=*d*,<=*h*,<=*v*,<=*e*<=≤<=104), where: - *d* — the diameter of your cylindrical cup, - *h* — the initial level of water in the cup, - *v* — the speed of drinking process from the cup in milliliters per second, - *e* — the growth of water because of rain if you do not drink from the cup. Output Specification: If it is impossible to make the cup empty, print "NO" (without quotes). Otherwise print "YES" (without quotes) in the first line. In the second line print a real number — time in seconds needed the cup will be empty. The answer will be considered correct if its relative or absolute error doesn't exceed 10<=-<=4. It is guaranteed that if the answer exists, it doesn't exceed 104. Demo Input: ['1 2 3 100\n', '1 1 1 1\n'] Demo Output: ['NO\n', 'YES\n3.659792366325\n'] Note: In the first example the water fills the cup faster than you can drink from it. In the second example area of the cup's bottom equals to <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/419dc74dcd7bc392019c9fe748fe1fdb08ab521a.png" style="max-width: 100.0%;max-height: 100.0%;"/>, thus we can conclude that you decrease the level of water by <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/e8edb237e1f805fe83c2f47e48d3a9d03f2ee304.png" style="max-width: 100.0%;max-height: 100.0%;"/> centimeters per second. At the same time water level increases by 1 centimeter per second due to rain. Thus, cup will be empty in <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/9dae615d7e2c5c7c03cb478848fb06aba1a8942e.png" style="max-width: 100.0%;max-height: 100.0%;"/> seconds.
```python import math def first(): inp = input().split(" ") d = float(inp[0]) h = float(inp[1]) v = float(inp[2]) e = float(inp[3]) h_y = v/(math.pi*(d/2)**2) if(h_y > e): print("YES") print(h/(h_y - e)) else: print("NO") first() ```
3
567
A
Lineland Mail
PROGRAMMING
900
[ "greedy", "implementation" ]
null
null
All cities of Lineland are located on the *Ox* coordinate axis. Thus, each city is associated with its position *x**i* — a coordinate on the *Ox* axis. No two cities are located at a single point. Lineland residents love to send letters to each other. A person may send a letter only if the recipient lives in another city (because if they live in the same city, then it is easier to drop in). Strange but true, the cost of sending the letter is exactly equal to the distance between the sender's city and the recipient's city. For each city calculate two values ​​*min**i* and *max**i*, where *min**i* is the minimum cost of sending a letter from the *i*-th city to some other city, and *max**i* is the the maximum cost of sending a letter from the *i*-th city to some other city
The first line of the input contains integer *n* (2<=≤<=*n*<=≤<=105) — the number of cities in Lineland. The second line contains the sequence of *n* distinct integers *x*1,<=*x*2,<=...,<=*x**n* (<=-<=109<=≤<=*x**i*<=≤<=109), where *x**i* is the *x*-coordinate of the *i*-th city. All the *x**i*'s are distinct and follow in ascending order.
Print *n* lines, the *i*-th line must contain two integers *min**i*,<=*max**i*, separated by a space, where *min**i* is the minimum cost of sending a letter from the *i*-th city, and *max**i* is the maximum cost of sending a letter from the *i*-th city.
[ "4\n-5 -2 2 7\n", "2\n-1 1\n" ]
[ "3 12\n3 9\n4 7\n5 12\n", "2 2\n2 2\n" ]
none
500
[ { "input": "4\n-5 -2 2 7", "output": "3 12\n3 9\n4 7\n5 12" }, { "input": "2\n-1 1", "output": "2 2\n2 2" }, { "input": "3\n-1 0 1", "output": "1 2\n1 1\n1 2" }, { "input": "4\n-1 0 1 3", "output": "1 4\n1 3\n1 2\n2 4" }, { "input": "3\n-1000000000 0 1000000000", "output": "1000000000 2000000000\n1000000000 1000000000\n1000000000 2000000000" }, { "input": "2\n-1000000000 1000000000", "output": "2000000000 2000000000\n2000000000 2000000000" }, { "input": "10\n1 10 12 15 59 68 130 912 1239 9123", "output": "9 9122\n2 9113\n2 9111\n3 9108\n9 9064\n9 9055\n62 8993\n327 8211\n327 7884\n7884 9122" }, { "input": "5\n-2 -1 0 1 2", "output": "1 4\n1 3\n1 2\n1 3\n1 4" }, { "input": "5\n-2 -1 0 1 3", "output": "1 5\n1 4\n1 3\n1 3\n2 5" }, { "input": "3\n-10000 1 10000", "output": "10001 20000\n9999 10001\n9999 20000" }, { "input": "5\n-1000000000 -999999999 -999999998 -999999997 -999999996", "output": "1 4\n1 3\n1 2\n1 3\n1 4" }, { "input": "10\n-857422304 -529223472 82412729 145077145 188538640 265299215 527377039 588634631 592896147 702473706", "output": "328198832 1559896010\n328198832 1231697178\n62664416 939835033\n43461495 1002499449\n43461495 1045960944\n76760575 1122721519\n61257592 1384799343\n4261516 1446056935\n4261516 1450318451\n109577559 1559896010" }, { "input": "10\n-876779400 -829849659 -781819137 -570920213 18428128 25280705 121178189 219147240 528386329 923854124", "output": "46929741 1800633524\n46929741 1753703783\n48030522 1705673261\n210898924 1494774337\n6852577 905425996\n6852577 902060105\n95897484 997957589\n97969051 1095926640\n309239089 1405165729\n395467795 1800633524" }, { "input": "30\n-15 1 21 25 30 40 59 60 77 81 97 100 103 123 139 141 157 158 173 183 200 215 226 231 244 256 267 279 289 292", "output": "16 307\n16 291\n4 271\n4 267\n5 262\n10 252\n1 233\n1 232\n4 215\n4 211\n3 195\n3 192\n3 189\n16 169\n2 154\n2 156\n1 172\n1 173\n10 188\n10 198\n15 215\n11 230\n5 241\n5 246\n12 259\n11 271\n11 282\n10 294\n3 304\n3 307" }, { "input": "10\n-1000000000 -999999999 -999999997 -999999996 -999999995 -999999994 -999999992 -999999990 -999999988 -999999986", "output": "1 14\n1 13\n1 11\n1 10\n1 9\n1 8\n2 8\n2 10\n2 12\n2 14" }, { "input": "50\n-50000 -49459 -48875 -48456 -48411 -48096 -47901 -47500 -47150 -46808 -46687 -46679 -46337 -45747 -45604 -45194 -44752 -44242 -44231 -44122 -43636 -43274 -42916 -42881 -42386 -42095 -41830 -41618 -41145 -40897 -40534 -40007 -39761 -39389 -39104 -38909 -38630 -38561 -38364 -38255 -38214 -38084 -37959 -37607 -37202 -36890 -36681 -36136 -36123 -35886", "output": "541 14114\n541 13573\n419 12989\n45 12570\n45 12525\n195 12210\n195 12015\n350 11614\n342 11264\n121 10922\n8 10801\n8 10793\n342 10451\n143 9861\n143 9718\n410 9308\n442 8866\n11 8356\n11 8345\n109 8236\n362 7750\n358 7388\n35 7084\n35 7119\n291 7614\n265 7905\n212 8170\n212 8382\n248 8855\n248 9103\n363 9466\n246 9993\n246 10239\n285 10611\n195 10896\n195 11091\n69 11370\n69 11439\n109 11636\n41 11745\n41 11786\n125 11916\n125 12041\n352 12393\n312 12798\n209 13110\n209 13319\n13 13864\n13 13877\n237 141..." }, { "input": "3\n-1000000000 999999999 1000000000", "output": "1999999999 2000000000\n1 1999999999\n1 2000000000" } ]
1,617,222,258
2,147,483,647
PyPy 3
WRONG_ANSWER
TESTS
4
92
0
n=int(input()) a=list(map(int,input().split())) d=abs for i in range(n): g=g1=999999999 if n-i-1>0: g=a[i+1] if i>0: g1=a[i-1] print(min(d(a[i]-g),d(a[i]-g1)),max(d(a[i]-a[0]),d(a[i]-a[n-1])))
Title: Lineland Mail Time Limit: None seconds Memory Limit: None megabytes Problem Description: All cities of Lineland are located on the *Ox* coordinate axis. Thus, each city is associated with its position *x**i* — a coordinate on the *Ox* axis. No two cities are located at a single point. Lineland residents love to send letters to each other. A person may send a letter only if the recipient lives in another city (because if they live in the same city, then it is easier to drop in). Strange but true, the cost of sending the letter is exactly equal to the distance between the sender's city and the recipient's city. For each city calculate two values ​​*min**i* and *max**i*, where *min**i* is the minimum cost of sending a letter from the *i*-th city to some other city, and *max**i* is the the maximum cost of sending a letter from the *i*-th city to some other city Input Specification: The first line of the input contains integer *n* (2<=≤<=*n*<=≤<=105) — the number of cities in Lineland. The second line contains the sequence of *n* distinct integers *x*1,<=*x*2,<=...,<=*x**n* (<=-<=109<=≤<=*x**i*<=≤<=109), where *x**i* is the *x*-coordinate of the *i*-th city. All the *x**i*'s are distinct and follow in ascending order. Output Specification: Print *n* lines, the *i*-th line must contain two integers *min**i*,<=*max**i*, separated by a space, where *min**i* is the minimum cost of sending a letter from the *i*-th city, and *max**i* is the maximum cost of sending a letter from the *i*-th city. Demo Input: ['4\n-5 -2 2 7\n', '2\n-1 1\n'] Demo Output: ['3 12\n3 9\n4 7\n5 12\n', '2 2\n2 2\n'] Note: none
```python n=int(input()) a=list(map(int,input().split())) d=abs for i in range(n): g=g1=999999999 if n-i-1>0: g=a[i+1] if i>0: g1=a[i-1] print(min(d(a[i]-g),d(a[i]-g1)),max(d(a[i]-a[0]),d(a[i]-a[n-1]))) ```
0
166
A
Rank List
PROGRAMMING
1,100
[ "binary search", "implementation", "sortings" ]
null
null
Another programming contest is over. You got hold of the contest's final results table. The table has the following data. For each team we are shown two numbers: the number of problems and the total penalty time. However, for no team we are shown its final place. You know the rules of comparing the results of two given teams very well. Let's say that team *a* solved *p**a* problems with total penalty time *t**a* and team *b* solved *p**b* problems with total penalty time *t**b*. Team *a* gets a higher place than team *b* in the end, if it either solved more problems on the contest, or solved the same number of problems but in less total time. In other words, team *a* gets a higher place than team *b* in the final results' table if either *p**a*<=&gt;<=*p**b*, or *p**a*<==<=*p**b* and *t**a*<=&lt;<=*t**b*. It is considered that the teams that solve the same number of problems with the same penalty time share all corresponding places. More formally, let's say there is a group of *x* teams that solved the same number of problems with the same penalty time. Let's also say that *y* teams performed better than the teams from this group. In this case all teams from the group share places *y*<=+<=1, *y*<=+<=2, ..., *y*<=+<=*x*. The teams that performed worse than the teams from this group, get their places in the results table starting from the *y*<=+<=*x*<=+<=1-th place. Your task is to count what number of teams from the given list shared the *k*-th place.
The first line contains two integers *n* and *k* (1<=≤<=*k*<=≤<=*n*<=≤<=50). Then *n* lines contain the description of the teams: the *i*-th line contains two integers *p**i* and *t**i* (1<=≤<=*p**i*,<=*t**i*<=≤<=50) — the number of solved problems and the total penalty time of the *i*-th team, correspondingly. All numbers in the lines are separated by spaces.
In the only line print the sought number of teams that got the *k*-th place in the final results' table.
[ "7 2\n4 10\n4 10\n4 10\n3 20\n2 1\n2 1\n1 10\n", "5 4\n3 1\n3 1\n5 3\n3 1\n3 1\n" ]
[ "3\n", "4\n" ]
The final results' table for the first sample is: - 1-3 places — 4 solved problems, the penalty time equals 10 - 4 place — 3 solved problems, the penalty time equals 20 - 5-6 places — 2 solved problems, the penalty time equals 1 - 7 place — 1 solved problem, the penalty time equals 10 The table shows that the second place is shared by the teams that solved 4 problems with penalty time 10. There are 3 such teams. The final table for the second sample is: - 1 place — 5 solved problems, the penalty time equals 3 - 2-5 places — 3 solved problems, the penalty time equals 1 The table shows that the fourth place is shared by the teams that solved 3 problems with penalty time 1. There are 4 such teams.
500
[ { "input": "7 2\n4 10\n4 10\n4 10\n3 20\n2 1\n2 1\n1 10", "output": "3" }, { "input": "5 4\n3 1\n3 1\n5 3\n3 1\n3 1", "output": "4" }, { "input": "5 1\n2 2\n1 1\n1 1\n1 1\n2 2", "output": "2" }, { "input": "6 3\n2 2\n3 1\n2 2\n4 5\n2 2\n4 5", "output": "1" }, { "input": "5 5\n3 1\n10 2\n2 2\n1 10\n10 2", "output": "1" }, { "input": "3 2\n3 3\n3 3\n3 3", "output": "3" }, { "input": "4 3\n10 3\n6 10\n5 2\n5 2", "output": "2" }, { "input": "5 3\n10 10\n10 10\n1 1\n10 10\n4 3", "output": "3" }, { "input": "3 1\n2 1\n1 1\n1 2", "output": "1" }, { "input": "1 1\n28 28", "output": "1" }, { "input": "2 2\n1 2\n1 2", "output": "2" }, { "input": "5 3\n2 3\n4 2\n5 3\n2 4\n3 5", "output": "1" }, { "input": "50 22\n4 9\n8 1\n3 7\n1 2\n3 8\n9 8\n8 5\n2 10\n5 8\n1 3\n1 8\n2 3\n7 9\n10 2\n9 9\n7 3\n8 6\n10 6\n5 4\n8 1\n1 5\n6 8\n9 5\n9 5\n3 2\n3 3\n3 8\n7 5\n4 5\n8 10\n8 2\n3 5\n3 2\n1 1\n7 2\n2 7\n6 8\n10 4\n7 5\n1 7\n6 5\n3 1\n4 9\n2 3\n3 6\n5 8\n4 10\n10 7\n7 10\n9 8", "output": "1" }, { "input": "50 6\n11 20\n18 13\n1 13\n3 11\n4 17\n15 10\n15 8\n9 16\n11 17\n16 3\n3 20\n14 13\n12 15\n9 10\n14 2\n12 12\n13 17\n6 10\n20 9\n2 8\n13 7\n7 20\n15 3\n1 20\n2 13\n2 5\n14 7\n10 13\n15 12\n15 5\n17 6\n9 11\n18 5\n10 1\n15 14\n3 16\n6 12\n4 1\n14 9\n7 14\n8 17\n17 13\n4 6\n19 16\n5 6\n3 15\n4 19\n15 20\n2 10\n20 10", "output": "1" }, { "input": "50 12\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1", "output": "50" }, { "input": "50 28\n2 2\n1 1\n2 1\n1 2\n1 1\n1 1\n1 1\n2 2\n2 2\n2 2\n2 1\n2 2\n2 1\n2 1\n1 2\n1 2\n1 2\n1 1\n2 2\n1 2\n2 2\n2 2\n2 1\n1 1\n1 2\n1 2\n1 1\n1 1\n1 1\n2 2\n2 1\n2 1\n2 2\n1 2\n1 2\n1 2\n1 1\n2 2\n1 2\n1 1\n2 2\n2 2\n1 1\n2 1\n2 1\n1 1\n2 2\n2 2\n2 2\n2 2", "output": "13" }, { "input": "50 40\n2 3\n3 1\n2 1\n2 1\n2 1\n3 1\n1 1\n1 2\n2 3\n1 3\n1 3\n2 1\n3 1\n1 1\n3 1\n3 1\n2 2\n1 1\n3 3\n3 1\n3 2\n2 3\n3 3\n3 1\n1 3\n2 3\n2 1\n3 2\n3 3\n3 1\n2 1\n2 2\n1 3\n3 3\n1 1\n3 2\n1 2\n2 3\n2 1\n2 2\n3 2\n1 3\n3 1\n1 1\n3 3\n2 3\n2 1\n2 3\n2 3\n1 2", "output": "5" }, { "input": "50 16\n2 1\n3 2\n5 2\n2 2\n3 4\n4 4\n3 3\n4 1\n2 3\n1 5\n4 1\n2 2\n1 5\n3 2\n2 1\n5 4\n5 2\n5 4\n1 1\n3 5\n2 1\n4 5\n5 1\n5 5\n5 4\n2 4\n1 2\n5 5\n4 4\n1 5\n4 2\n5 1\n2 4\n2 5\n2 2\n3 4\n3 1\n1 1\n5 5\n2 2\n3 4\n2 4\n5 2\n4 1\n3 1\n1 1\n4 1\n4 4\n1 4\n1 3", "output": "1" }, { "input": "50 32\n6 6\n4 2\n5 5\n1 1\n2 4\n6 5\n2 3\n6 5\n2 3\n6 3\n1 4\n1 6\n3 3\n2 4\n3 2\n6 2\n4 1\n3 3\n3 1\n5 5\n1 2\n2 1\n5 4\n3 1\n4 4\n5 6\n4 1\n2 5\n3 1\n4 6\n2 3\n1 1\n6 5\n2 6\n3 3\n2 6\n2 3\n2 6\n3 4\n2 6\n4 5\n5 4\n1 6\n3 2\n5 1\n4 1\n4 6\n4 2\n1 2\n5 2", "output": "1" }, { "input": "50 48\n5 1\n6 4\n3 2\n2 1\n4 7\n3 6\n7 1\n7 5\n6 5\n5 6\n4 7\n5 7\n5 7\n5 5\n7 3\n3 5\n4 3\n5 4\n6 2\n1 6\n6 3\n6 5\n5 2\n4 2\n3 1\n1 1\n5 6\n1 3\n6 5\n3 7\n1 5\n7 5\n6 5\n3 6\n2 7\n5 3\n5 3\n4 7\n5 2\n6 5\n5 7\n7 1\n2 3\n5 5\n2 6\n4 1\n6 2\n6 5\n3 3\n1 6", "output": "1" }, { "input": "50 8\n5 3\n7 3\n4 3\n7 4\n2 2\n4 4\n5 4\n1 1\n7 7\n4 8\n1 1\n6 3\n1 5\n7 3\n6 5\n4 5\n8 6\n3 6\n2 1\n3 2\n2 5\n7 6\n5 8\n1 3\n5 5\n8 4\n4 5\n4 4\n8 8\n7 2\n7 2\n3 6\n2 8\n8 3\n3 2\n4 5\n8 1\n3 2\n8 7\n6 3\n2 3\n5 1\n3 4\n7 2\n6 3\n7 3\n3 3\n6 4\n2 2\n5 1", "output": "3" }, { "input": "20 16\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1", "output": "20" }, { "input": "20 20\n1 2\n2 2\n1 1\n2 1\n2 2\n1 1\n1 1\n2 1\n1 1\n1 2\n2 2\n1 2\n1 2\n2 2\n2 2\n1 2\n2 1\n2 1\n1 2\n2 2", "output": "6" }, { "input": "30 16\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1", "output": "30" }, { "input": "30 22\n2 1\n1 2\n2 1\n2 2\n2 1\n1 2\n2 2\n1 2\n2 2\n1 2\n2 2\n1 2\n1 2\n2 1\n1 2\n2 2\n2 2\n1 2\n2 1\n1 1\n1 2\n1 2\n1 1\n1 2\n1 2\n2 2\n1 2\n2 2\n2 1\n1 1", "output": "13" }, { "input": "30 22\n1 1\n1 3\n2 3\n3 1\n2 3\n3 1\n1 2\n3 3\n2 1\n2 1\n2 2\n3 1\n3 2\n2 3\n3 1\n1 3\n2 3\n3 1\n1 2\n1 2\n2 3\n2 1\n3 3\n3 2\n1 3\n3 3\n3 3\n3 3\n3 3\n3 1", "output": "5" }, { "input": "50 16\n2 1\n3 2\n5 2\n2 2\n3 4\n4 4\n3 3\n4 1\n2 3\n1 5\n4 1\n2 2\n1 5\n3 2\n2 1\n5 4\n5 2\n5 4\n1 1\n3 5\n2 1\n4 5\n5 1\n5 5\n5 4\n2 4\n1 2\n5 5\n4 4\n1 5\n4 2\n5 1\n2 4\n2 5\n2 2\n3 4\n3 1\n1 1\n5 5\n2 2\n3 4\n2 4\n5 2\n4 1\n3 1\n1 1\n4 1\n4 4\n1 4\n1 3", "output": "1" }, { "input": "50 22\n4 9\n8 1\n3 7\n1 2\n3 8\n9 8\n8 5\n2 10\n5 8\n1 3\n1 8\n2 3\n7 9\n10 2\n9 9\n7 3\n8 6\n10 6\n5 4\n8 1\n1 5\n6 8\n9 5\n9 5\n3 2\n3 3\n3 8\n7 5\n4 5\n8 10\n8 2\n3 5\n3 2\n1 1\n7 2\n2 7\n6 8\n10 4\n7 5\n1 7\n6 5\n3 1\n4 9\n2 3\n3 6\n5 8\n4 10\n10 7\n7 10\n9 8", "output": "1" }, { "input": "50 22\n29 15\n18 10\n6 23\n38 28\n34 40\n40 1\n16 26\n22 33\n14 30\n26 7\n15 16\n22 40\n14 15\n6 28\n32 27\n33 3\n38 22\n40 17\n16 27\n21 27\n34 26\n5 15\n34 9\n38 23\n7 36\n17 6\n19 37\n40 1\n10 28\n9 14\n8 31\n40 8\n14 2\n24 16\n38 33\n3 37\n2 9\n21 21\n40 26\n28 33\n24 31\n10 12\n27 27\n17 4\n38 5\n21 31\n5 12\n29 7\n39 12\n26 14", "output": "1" }, { "input": "50 14\n4 20\n37 50\n46 19\n20 25\n47 10\n6 34\n12 41\n47 9\n22 28\n41 34\n47 40\n12 42\n9 4\n15 15\n27 8\n38 9\n4 17\n8 13\n47 7\n9 38\n30 48\n50 7\n41 34\n23 11\n16 37\n2 32\n18 46\n37 48\n47 41\n13 9\n24 50\n46 14\n33 49\n9 50\n35 30\n49 44\n42 49\n39 15\n33 42\n3 18\n44 15\n44 28\n9 17\n16 4\n10 36\n4 22\n47 17\n24 12\n2 31\n6 30", "output": "2" }, { "input": "2 1\n50 50\n50 50", "output": "2" }, { "input": "2 2\n50 50\n50 50", "output": "2" }, { "input": "2 1\n50 50\n50 49", "output": "1" }, { "input": "2 2\n50 50\n50 49", "output": "1" }, { "input": "50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50", "output": "50" }, { "input": "50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n49 50", "output": "1" }, { "input": "50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 49", "output": "49" }, { "input": "10 1\n3 1\n3 2\n3 2\n2 3\n2 3\n2 3\n2 4\n2 4\n2 4\n2 4", "output": "1" }, { "input": "4 3\n1 1\n1 2\n2 1\n2 2", "output": "1" }, { "input": "4 2\n1 2\n1 3\n1 5\n1 2", "output": "2" }, { "input": "6 1\n4 3\n4 2\n5 1\n5 2\n5 3\n5 3", "output": "1" }, { "input": "5 3\n2 1\n1 3\n1 2\n1 1\n1 1", "output": "2" }, { "input": "3 1\n1 1\n1 2\n1 3", "output": "1" }, { "input": "10 10\n3 1\n3 2\n3 2\n2 3\n2 3\n2 3\n2 4\n2 4\n2 4\n2 4", "output": "4" }, { "input": "5 1\n5 5\n5 6\n5 7\n5 8\n5 5", "output": "2" }, { "input": "4 1\n1 1\n1 1\n1 2\n1 3", "output": "2" } ]
1,669,656,116
2,147,483,647
PyPy 3-64
WRONG_ANSWER
TESTS
2
92
0
n,k=map(int,input().split()) data=[] for _ in range(n): data.append(list(map(int,input().split()))) data.sort(key= lambda x: x[1],reverse=True) ans=[] for i in range(n-1): if data[i]==data[i+1]: continue else: ans.append(i) if k>len(ans): print(abs(len(ans)-n)) else: print(ans[k-1])
Title: Rank List Time Limit: None seconds Memory Limit: None megabytes Problem Description: Another programming contest is over. You got hold of the contest's final results table. The table has the following data. For each team we are shown two numbers: the number of problems and the total penalty time. However, for no team we are shown its final place. You know the rules of comparing the results of two given teams very well. Let's say that team *a* solved *p**a* problems with total penalty time *t**a* and team *b* solved *p**b* problems with total penalty time *t**b*. Team *a* gets a higher place than team *b* in the end, if it either solved more problems on the contest, or solved the same number of problems but in less total time. In other words, team *a* gets a higher place than team *b* in the final results' table if either *p**a*<=&gt;<=*p**b*, or *p**a*<==<=*p**b* and *t**a*<=&lt;<=*t**b*. It is considered that the teams that solve the same number of problems with the same penalty time share all corresponding places. More formally, let's say there is a group of *x* teams that solved the same number of problems with the same penalty time. Let's also say that *y* teams performed better than the teams from this group. In this case all teams from the group share places *y*<=+<=1, *y*<=+<=2, ..., *y*<=+<=*x*. The teams that performed worse than the teams from this group, get their places in the results table starting from the *y*<=+<=*x*<=+<=1-th place. Your task is to count what number of teams from the given list shared the *k*-th place. Input Specification: The first line contains two integers *n* and *k* (1<=≤<=*k*<=≤<=*n*<=≤<=50). Then *n* lines contain the description of the teams: the *i*-th line contains two integers *p**i* and *t**i* (1<=≤<=*p**i*,<=*t**i*<=≤<=50) — the number of solved problems and the total penalty time of the *i*-th team, correspondingly. All numbers in the lines are separated by spaces. Output Specification: In the only line print the sought number of teams that got the *k*-th place in the final results' table. Demo Input: ['7 2\n4 10\n4 10\n4 10\n3 20\n2 1\n2 1\n1 10\n', '5 4\n3 1\n3 1\n5 3\n3 1\n3 1\n'] Demo Output: ['3\n', '4\n'] Note: The final results' table for the first sample is: - 1-3 places — 4 solved problems, the penalty time equals 10 - 4 place — 3 solved problems, the penalty time equals 20 - 5-6 places — 2 solved problems, the penalty time equals 1 - 7 place — 1 solved problem, the penalty time equals 10 The table shows that the second place is shared by the teams that solved 4 problems with penalty time 10. There are 3 such teams. The final table for the second sample is: - 1 place — 5 solved problems, the penalty time equals 3 - 2-5 places — 3 solved problems, the penalty time equals 1 The table shows that the fourth place is shared by the teams that solved 3 problems with penalty time 1. There are 4 such teams.
```python n,k=map(int,input().split()) data=[] for _ in range(n): data.append(list(map(int,input().split()))) data.sort(key= lambda x: x[1],reverse=True) ans=[] for i in range(n-1): if data[i]==data[i+1]: continue else: ans.append(i) if k>len(ans): print(abs(len(ans)-n)) else: print(ans[k-1]) ```
0
5
A
Chat Servers Outgoing Traffic
PROGRAMMING
1,000
[ "implementation" ]
A. Chat Server's Outgoing Traffic
1
64
Polycarp is working on a new project called "Polychat". Following modern tendencies in IT, he decided, that this project should contain chat as well. To achieve this goal, Polycarp has spent several hours in front of his laptop and implemented a chat server that can process three types of commands: - Include a person to the chat ('Add' command). - Remove a person from the chat ('Remove' command). - Send a message from a person to all people, who are currently in the chat, including the one, who sends the message ('Send' command). Now Polycarp wants to find out the amount of outgoing traffic that the server will produce while processing a particular set of commands. Polycarp knows that chat server sends no traffic for 'Add' and 'Remove' commands. When 'Send' command is processed, server sends *l* bytes to each participant of the chat, where *l* is the length of the message. As Polycarp has no time, he is asking for your help in solving this problem.
Input file will contain not more than 100 commands, each in its own line. No line will exceed 100 characters. Formats of the commands will be the following: - +&lt;name&gt; for 'Add' command. - -&lt;name&gt; for 'Remove' command. - &lt;sender_name&gt;:&lt;message_text&gt; for 'Send' command. &lt;name&gt; and &lt;sender_name&gt; is a non-empty sequence of Latin letters and digits. &lt;message_text&gt; can contain letters, digits and spaces, but can't start or end with a space. &lt;message_text&gt; can be an empty line. It is guaranteed, that input data are correct, i.e. there will be no 'Add' command if person with such a name is already in the chat, there will be no 'Remove' command if there is no person with such a name in the chat etc. All names are case-sensitive.
Print a single number — answer to the problem.
[ "+Mike\nMike:hello\n+Kate\n+Dmitry\n-Dmitry\nKate:hi\n-Kate\n", "+Mike\n-Mike\n+Mike\nMike:Hi I am here\n-Mike\n+Kate\n-Kate\n" ]
[ "9\n", "14\n" ]
none
0
[ { "input": "+Mike\nMike:hello\n+Kate\n+Dmitry\n-Dmitry\nKate:hi\n-Kate", "output": "9" }, { "input": "+Mike\n-Mike\n+Mike\nMike:Hi I am here\n-Mike\n+Kate\n-Kate", "output": "14" }, { "input": "+Dmitry\n+Mike\nDmitry:All letters will be used\nDmitry:qwertyuiopasdfghjklzxcvbnm QWERTYUIOPASDFGHJKLZXCVBNM\nDmitry:And digits too\nDmitry:1234567890 0987654321\n-Dmitry", "output": "224" }, { "input": "+Dmitry\n+Mike\n+Kate\nDmitry:", "output": "0" }, { "input": "+Dmitry\nDmitry:No phrases with spaces at the beginning and at the end\n+Mike\nDmitry:spaces spaces\n-Dmitry", "output": "86" }, { "input": "+XqD\n+aT537\nXqD:x6ZPjMR1DDKG2\nXqD:lLCriywPnB\n-XqD", "output": "46" }, { "input": "+8UjgAJ\n8UjgAJ:02hR7UBc1tqqfL\n-8UjgAJ\n+zdi\n-zdi", "output": "14" }, { "input": "+6JPKkgXDrA\n+j6JHjv70An\n+QGtsceK0zJ\n6JPKkgXDrA:o4\n+CSmwi9zDra\nQGtsceK0zJ:Zl\nQGtsceK0zJ:0\nj6JHjv70An:7\nj6JHjv70An:B\nQGtsceK0zJ:OO", "output": "34" }, { "input": "+1aLNq9S7uLV\n-1aLNq9S7uLV\n+O9ykq3xDJv\n-O9ykq3xDJv\n+54Yq1xJq14F\n+0zJ5Vo0RDZ\n-54Yq1xJq14F\n-0zJ5Vo0RDZ\n+lxlH7sdolyL\n-lxlH7sdolyL", "output": "0" }, { "input": "+qlHEc2AuYy\nqlHEc2AuYy:YYRwD0 edNZgpE nGfOguRWnMYpTpGUVM aXDKGXo1Gv1tHL9\nqlHEc2AuYy:yvh3GsPcImqrvoUcBNQcP6ezwpU0 xAVltaKZp94VKiNao\nqlHEc2AuYy:zuCO6Opey L eu7lTwysaSk00zjpv zrDfbt8l hpHfu\n+pErDMxgVgh\nqlHEc2AuYy:I1FLis mmQbZtd8Ui7y 1vcax6yZBMhVRdD6Ahlq7MNCw\nqlHEc2AuYy:lz MFUNJZhlqBYckHUDlNhLiEkmecRh1o0t7alXBvCRVEFVx\npErDMxgVgh:jCyMbu1dkuEj5TzbBOjyUhpfC50cL8R900Je3R KxRgAI dT\nqlHEc2AuYy:62b47eabo2hf vSUD7KioN ZHki6WB6gh3u GKv5rgwyfF\npErDMxgVgh:zD5 9 ympl4wR gy7a7eAGAn5xVdGP9FbL6hRCZAR6O4pT6zb", "output": "615" }, { "input": "+adabacaba0", "output": "0" }, { "input": "+acabadab\n+caba0aba", "output": "0" }, { "input": "+dabaca\n-dabaca\n+aba0ab", "output": "0" }, { "input": "+cab\n+abac\n-abac\n+baca", "output": "0" }, { "input": "+cabadabac\n-cabadabac\n+abacaba1ab\n-abacaba1ab\n+ba0abaca", "output": "0" }, { "input": "+adabacaba\n-adabacaba\n+aca\naca:caba\n-aca\n+bacaba\n-bacaba\n+aba\n-aba\n+bad", "output": "4" }, { "input": "+acabadab\n-acabadab\n+aba0abacab\n+baca\n+abacaba0ab\n-baca\n-abacaba0ab\n-aba0abacab\n+cab\n-cab\n+abacabada\n-abacabada\n+badabaca\n-badabaca\n+badaba", "output": "0" }, { "input": "+badabac\nbadabac:abacabad\n-badabac\n+0ab\n-0ab\n+dabacab\n-dabacab\n+a0ab\n-a0ab\n+0abaca\n-0abaca\n+dabac\n-dabac\n+abaca\n-abaca\n+bacabada\n-bacabada\n+aca\n-aca\n+abadabaca\n-abadabaca\n+acaba\n-acaba\n+abacabadab\n-abacabadab", "output": "8" } ]
1,618,703,636
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
0
124
0
import sys a = 0 b = 0 for m in sys.stdin: if m[0] == '+': a = a + 1 elif m[0] == '-': a = a - 1 else: b = b + (a*(len(m) - m.find(':'))) print(b)
Title: Chat Servers Outgoing Traffic Time Limit: 1 seconds Memory Limit: 64 megabytes Problem Description: Polycarp is working on a new project called "Polychat". Following modern tendencies in IT, he decided, that this project should contain chat as well. To achieve this goal, Polycarp has spent several hours in front of his laptop and implemented a chat server that can process three types of commands: - Include a person to the chat ('Add' command). - Remove a person from the chat ('Remove' command). - Send a message from a person to all people, who are currently in the chat, including the one, who sends the message ('Send' command). Now Polycarp wants to find out the amount of outgoing traffic that the server will produce while processing a particular set of commands. Polycarp knows that chat server sends no traffic for 'Add' and 'Remove' commands. When 'Send' command is processed, server sends *l* bytes to each participant of the chat, where *l* is the length of the message. As Polycarp has no time, he is asking for your help in solving this problem. Input Specification: Input file will contain not more than 100 commands, each in its own line. No line will exceed 100 characters. Formats of the commands will be the following: - +&lt;name&gt; for 'Add' command. - -&lt;name&gt; for 'Remove' command. - &lt;sender_name&gt;:&lt;message_text&gt; for 'Send' command. &lt;name&gt; and &lt;sender_name&gt; is a non-empty sequence of Latin letters and digits. &lt;message_text&gt; can contain letters, digits and spaces, but can't start or end with a space. &lt;message_text&gt; can be an empty line. It is guaranteed, that input data are correct, i.e. there will be no 'Add' command if person with such a name is already in the chat, there will be no 'Remove' command if there is no person with such a name in the chat etc. All names are case-sensitive. Output Specification: Print a single number — answer to the problem. Demo Input: ['+Mike\nMike:hello\n+Kate\n+Dmitry\n-Dmitry\nKate:hi\n-Kate\n', '+Mike\n-Mike\n+Mike\nMike:Hi I am here\n-Mike\n+Kate\n-Kate\n'] Demo Output: ['9\n', '14\n'] Note: none
```python import sys a = 0 b = 0 for m in sys.stdin: if m[0] == '+': a = a + 1 elif m[0] == '-': a = a - 1 else: b = b + (a*(len(m) - m.find(':'))) print(b) ```
0
25
A
IQ test
PROGRAMMING
1,300
[ "brute force" ]
A. IQ test
2
256
Bob is preparing to pass IQ test. The most frequent task in this test is to find out which one of the given *n* numbers differs from the others. Bob observed that one number usually differs from the others in evenness. Help Bob — to check his answers, he needs a program that among the given *n* numbers finds one that is different in evenness.
The first line contains integer *n* (3<=≤<=*n*<=≤<=100) — amount of numbers in the task. The second line contains *n* space-separated natural numbers, not exceeding 100. It is guaranteed, that exactly one of these numbers differs from the others in evenness.
Output index of number that differs from the others in evenness. Numbers are numbered from 1 in the input order.
[ "5\n2 4 7 8 10\n", "4\n1 2 1 1\n" ]
[ "3\n", "2\n" ]
none
0
[ { "input": "5\n2 4 7 8 10", "output": "3" }, { "input": "4\n1 2 1 1", "output": "2" }, { "input": "3\n1 2 2", "output": "1" }, { "input": "3\n100 99 100", "output": "2" }, { "input": "3\n5 3 2", "output": "3" }, { "input": "4\n43 28 1 91", "output": "2" }, { "input": "4\n75 13 94 77", "output": "3" }, { "input": "4\n97 8 27 3", "output": "2" }, { "input": "10\n95 51 12 91 85 3 1 31 25 7", "output": "3" }, { "input": "20\n88 96 66 51 14 88 2 92 18 72 18 88 20 30 4 82 90 100 24 46", "output": "4" }, { "input": "30\n20 94 56 50 10 98 52 32 14 22 24 60 4 8 98 46 34 68 82 82 98 90 50 20 78 49 52 94 64 36", "output": "26" }, { "input": "50\n79 27 77 57 37 45 27 49 65 33 57 21 71 19 75 85 65 61 23 97 85 9 23 1 9 3 99 77 77 21 79 69 15 37 15 7 93 81 13 89 91 31 45 93 15 97 55 80 85 83", "output": "48" }, { "input": "60\n46 11 73 65 3 69 3 53 43 53 97 47 55 93 31 75 35 3 9 73 23 31 3 81 91 79 61 21 15 11 11 11 81 7 83 75 39 87 83 59 89 55 93 27 49 67 67 29 1 93 11 17 9 19 35 21 63 31 31 25", "output": "1" }, { "input": "70\n28 42 42 92 64 54 22 38 38 78 62 38 4 38 14 66 4 92 66 58 94 26 4 44 41 88 48 82 44 26 74 44 48 4 16 92 34 38 26 64 94 4 30 78 50 54 12 90 8 16 80 98 28 100 74 50 36 42 92 18 76 98 8 22 2 50 58 50 64 46", "output": "25" }, { "input": "100\n43 35 79 53 13 91 91 45 65 83 57 9 42 39 85 45 71 51 61 59 31 13 63 39 25 21 79 39 91 67 21 61 97 75 93 83 29 79 59 97 11 37 63 51 39 55 91 23 21 17 47 23 35 75 49 5 69 99 5 7 41 17 25 89 15 79 21 63 53 81 43 91 59 91 69 99 85 15 91 51 49 37 65 7 89 81 21 93 61 63 97 93 45 17 13 69 57 25 75 73", "output": "13" }, { "input": "100\n50 24 68 60 70 30 52 22 18 74 68 98 20 82 4 46 26 68 100 78 84 58 74 98 38 88 68 86 64 80 82 100 20 22 98 98 52 6 94 10 48 68 2 18 38 22 22 82 44 20 66 72 36 58 64 6 36 60 4 96 76 64 12 90 10 58 64 60 74 28 90 26 24 60 40 58 2 16 76 48 58 36 82 60 24 44 4 78 28 38 8 12 40 16 38 6 66 24 31 76", "output": "99" }, { "input": "100\n47 48 94 48 14 18 94 36 96 22 12 30 94 20 48 98 40 58 2 94 8 36 98 18 98 68 2 60 76 38 18 100 8 72 100 68 2 86 92 72 58 16 48 14 6 58 72 76 6 88 80 66 20 28 74 62 86 68 90 86 2 56 34 38 56 90 4 8 76 44 32 86 12 98 38 34 54 92 70 94 10 24 82 66 90 58 62 2 32 58 100 22 58 72 2 22 68 72 42 14", "output": "1" }, { "input": "99\n38 20 68 60 84 16 28 88 60 48 80 28 4 92 70 60 46 46 20 34 12 100 76 2 40 10 8 86 6 80 50 66 12 34 14 28 26 70 46 64 34 96 10 90 98 96 56 88 50 74 70 94 2 94 24 66 68 46 22 30 6 10 64 32 88 14 98 100 64 58 50 18 50 50 8 38 8 16 54 2 60 54 62 84 92 98 4 72 66 26 14 88 99 16 10 6 88 56 22", "output": "93" }, { "input": "99\n50 83 43 89 53 47 69 1 5 37 63 87 95 15 55 95 75 89 33 53 89 75 93 75 11 85 49 29 11 97 49 67 87 11 25 37 97 73 67 49 87 43 53 97 43 29 53 33 45 91 37 73 39 49 59 5 21 43 87 35 5 63 89 57 63 47 29 99 19 85 13 13 3 13 43 19 5 9 61 51 51 57 15 89 13 97 41 13 99 79 13 27 97 95 73 33 99 27 23", "output": "1" }, { "input": "98\n61 56 44 30 58 14 20 24 88 28 46 56 96 52 58 42 94 50 46 30 46 80 72 88 68 16 6 60 26 90 10 98 76 20 56 40 30 16 96 20 88 32 62 30 74 58 36 76 60 4 24 36 42 54 24 92 28 14 2 74 86 90 14 52 34 82 40 76 8 64 2 56 10 8 78 16 70 86 70 42 70 74 22 18 76 98 88 28 62 70 36 72 20 68 34 48 80 98", "output": "1" }, { "input": "98\n66 26 46 42 78 32 76 42 26 82 8 12 4 10 24 26 64 44 100 46 94 64 30 18 88 28 8 66 30 82 82 28 74 52 62 80 80 60 94 86 64 32 44 88 92 20 12 74 94 28 34 58 4 22 16 10 94 76 82 58 40 66 22 6 30 32 92 54 16 76 74 98 18 48 48 30 92 2 16 42 84 74 30 60 64 52 50 26 16 86 58 96 79 60 20 62 82 94", "output": "93" }, { "input": "95\n9 31 27 93 17 77 75 9 9 53 89 39 51 99 5 1 11 39 27 49 91 17 27 79 81 71 37 75 35 13 93 4 99 55 85 11 23 57 5 43 5 61 15 35 23 91 3 81 99 85 43 37 39 27 5 67 7 33 75 59 13 71 51 27 15 93 51 63 91 53 43 99 25 47 17 71 81 15 53 31 59 83 41 23 73 25 91 91 13 17 25 13 55 57 29", "output": "32" }, { "input": "100\n91 89 81 45 53 1 41 3 77 93 55 97 55 97 87 27 69 95 73 41 93 21 75 35 53 56 5 51 87 59 91 67 33 3 99 45 83 17 97 47 75 97 7 89 17 99 23 23 81 25 55 97 27 35 69 5 77 35 93 19 55 59 37 21 31 37 49 41 91 53 73 69 7 37 37 39 17 71 7 97 55 17 47 23 15 73 31 39 57 37 9 5 61 41 65 57 77 79 35 47", "output": "26" }, { "input": "99\n38 56 58 98 80 54 26 90 14 16 78 92 52 74 40 30 84 14 44 80 16 90 98 68 26 24 78 72 42 16 84 40 14 44 2 52 50 2 12 96 58 66 8 80 44 52 34 34 72 98 74 4 66 74 56 21 8 38 76 40 10 22 48 32 98 34 12 62 80 68 64 82 22 78 58 74 20 22 48 56 12 38 32 72 6 16 74 24 94 84 26 38 18 24 76 78 98 94 72", "output": "56" }, { "input": "100\n44 40 6 40 56 90 98 8 36 64 76 86 98 76 36 92 6 30 98 70 24 98 96 60 24 82 88 68 86 96 34 42 58 10 40 26 56 10 88 58 70 32 24 28 14 82 52 12 62 36 70 60 52 34 74 30 78 76 10 16 42 94 66 90 70 38 52 12 58 22 98 96 14 68 24 70 4 30 84 98 8 50 14 52 66 34 100 10 28 100 56 48 38 12 38 14 91 80 70 86", "output": "97" }, { "input": "100\n96 62 64 20 90 46 56 90 68 36 30 56 70 28 16 64 94 34 6 32 34 50 94 22 90 32 40 2 72 10 88 38 28 92 20 26 56 80 4 100 100 90 16 74 74 84 8 2 30 20 80 32 16 46 92 56 42 12 96 64 64 42 64 58 50 42 74 28 2 4 36 32 70 50 54 92 70 16 45 76 28 16 18 50 48 2 62 94 4 12 52 52 4 100 70 60 82 62 98 42", "output": "79" }, { "input": "99\n14 26 34 68 90 58 50 36 8 16 18 6 2 74 54 20 36 84 32 50 52 2 26 24 3 64 20 10 54 26 66 44 28 72 4 96 78 90 96 86 68 28 94 4 12 46 100 32 22 36 84 32 44 94 76 94 4 52 12 30 74 4 34 64 58 72 44 16 70 56 54 8 14 74 8 6 58 62 98 54 14 40 80 20 36 72 28 98 20 58 40 52 90 64 22 48 54 70 52", "output": "25" }, { "input": "95\n82 86 30 78 6 46 80 66 74 72 16 24 18 52 52 38 60 36 86 26 62 28 22 46 96 26 94 84 20 46 66 88 76 32 12 86 74 18 34 88 4 48 94 6 58 6 100 82 4 24 88 32 54 98 34 48 6 76 42 88 42 28 100 4 22 2 10 66 82 54 98 20 60 66 38 98 32 47 86 58 6 100 12 46 2 42 8 84 78 28 24 70 34 28 86", "output": "78" }, { "input": "90\n40 50 8 42 76 24 58 42 26 68 20 48 54 12 34 84 14 36 32 88 6 50 96 56 20 92 48 16 40 34 96 46 20 84 30 50 20 98 8 44 96 42 8 76 70 38 84 30 40 88 84 72 2 22 52 58 16 62 100 66 80 40 50 32 14 62 88 72 22 99 76 50 84 82 8 82 98 46 26 40 2 98 18 78 30 72 70 18 34 68", "output": "70" }, { "input": "80\n81 43 87 1 55 43 53 61 27 19 43 13 89 9 33 83 75 55 97 71 91 37 95 5 21 69 81 93 95 69 31 83 55 7 97 7 79 57 8 61 27 85 49 1 15 97 63 79 29 73 41 85 5 41 31 93 67 11 63 59 15 99 91 77 43 69 23 23 81 73 19 1 67 51 1 75 99 67 3 81", "output": "39" }, { "input": "98\n13 83 61 27 35 1 85 95 97 73 95 65 73 45 5 43 27 83 91 19 11 3 85 59 9 39 69 23 45 7 51 85 5 71 5 95 1 51 75 3 43 57 3 11 33 71 21 99 47 41 87 39 71 87 31 85 91 49 83 5 49 85 47 91 55 99 33 23 31 23 23 73 29 77 55 31 25 5 81 49 91 15 15 39 87 5 9 40 69 47 29 33 11 21 49 79 51 83", "output": "88" }, { "input": "3\n100 100 1", "output": "3" } ]
1,556,008,932
2,147,483,647
Python 3
RUNTIME_ERROR
TESTS
0
154
0
n = sys.stdin.readline().rstrip() l = sys.stdin.readline().rstrip() l = [int(x) for x in l.split(' ')] list_check = [] for i, each in enumerate(l): list_check.append(each%2) if list_check.count(0) ==1 : print(list_check.index(0)+1) else: print(list_check.index(1)+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 = sys.stdin.readline().rstrip() l = sys.stdin.readline().rstrip() l = [int(x) for x in l.split(' ')] list_check = [] for i, each in enumerate(l): list_check.append(each%2) if list_check.count(0) ==1 : print(list_check.index(0)+1) else: print(list_check.index(1)+1) ```
-1
805
B
3-palindrome
PROGRAMMING
1,000
[ "constructive algorithms" ]
null
null
In the beginning of the new year Keivan decided to reverse his name. He doesn't like palindromes, so he changed Naviek to Navick. He is too selfish, so for a given *n* he wants to obtain a string of *n* characters, each of which is either 'a', 'b' or 'c', with no palindromes of length 3 appearing in the string as a substring. For example, the strings "abc" and "abca" suit him, while the string "aba" doesn't. He also want the number of letters 'c' in his string to be as little as possible.
The first line contains single integer *n* (1<=≤<=*n*<=≤<=2·105) — the length of the string.
Print the string that satisfies all the constraints. If there are multiple answers, print any of them.
[ "2\n", "3\n" ]
[ "aa\n", "bba\n" ]
A palindrome is a sequence of characters which reads the same backward and forward.
1,000
[ { "input": "2", "output": "aa" }, { "input": "3", "output": "aab" }, { "input": "38", "output": "aabbaabbaabbaabbaabbaabbaabbaabbaabbaa" }, { "input": "47", "output": "aabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaab" }, { "input": "59", "output": "aabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaab" }, { "input": "67", "output": "aabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaab" }, { "input": "77", "output": "aabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabba" }, { "input": "89", "output": "aabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabba" }, { "input": "98", "output": "aabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaa" }, { "input": "109", "output": "aabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabba" }, { "input": "117", "output": "aabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabba" }, { "input": "1", "output": "a" }, { "input": "200000", "output": "aabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaab..." }, { "input": "100000", "output": "aabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaab..." }, { "input": "143670", "output": "aabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaab..." }, { "input": "104217", "output": "aabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaab..." }, { "input": "17879", "output": "aabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaab..." }, { "input": "131809", "output": "aabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaab..." }, { "input": "140873", "output": "aabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaab..." }, { "input": "77859", "output": "aabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaab..." }, { "input": "153022", "output": "aabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaab..." }, { "input": "179227", "output": "aabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaab..." }, { "input": "182801", "output": "aabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaab..." }, { "input": "5188", "output": "aabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaab..." }, { "input": "86539", "output": "aabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaab..." }, { "input": "12802", "output": "aabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaab..." }, { "input": "120289", "output": "aabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaab..." }, { "input": "132866", "output": "aabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaab..." }, { "input": "133377", "output": "aabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaab..." }, { "input": "31775", "output": "aabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaab..." }, { "input": "160397", "output": "aabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaab..." }, { "input": "161415", "output": "aabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaab..." }, { "input": "163623", "output": "aabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaab..." }, { "input": "22942", "output": "aabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaab..." }, { "input": "134767", "output": "aabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaab..." }, { "input": "52257", "output": "aabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaab..." }, { "input": "64905", "output": "aabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaab..." }, { "input": "183758", "output": "aabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaab..." }, { "input": "60131", "output": "aabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaab..." }, { "input": "146883", "output": "aabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaab..." }, { "input": "6", "output": "aabbaa" }, { "input": "4", "output": "aabb" } ]
1,688,891,445
2,147,483,647
PyPy 3-64
WRONG_ANSWER
TESTS
2
46
0
n=int(input()) q=n//5 r=n%5 s="aabbc" print(s*q+s[:r])
Title: 3-palindrome Time Limit: None seconds Memory Limit: None megabytes Problem Description: In the beginning of the new year Keivan decided to reverse his name. He doesn't like palindromes, so he changed Naviek to Navick. He is too selfish, so for a given *n* he wants to obtain a string of *n* characters, each of which is either 'a', 'b' or 'c', with no palindromes of length 3 appearing in the string as a substring. For example, the strings "abc" and "abca" suit him, while the string "aba" doesn't. He also want the number of letters 'c' in his string to be as little as possible. Input Specification: The first line contains single integer *n* (1<=≤<=*n*<=≤<=2·105) — the length of the string. Output Specification: Print the string that satisfies all the constraints. If there are multiple answers, print any of them. Demo Input: ['2\n', '3\n'] Demo Output: ['aa\n', 'bba\n'] Note: A palindrome is a sequence of characters which reads the same backward and forward.
```python n=int(input()) q=n//5 r=n%5 s="aabbc" print(s*q+s[:r]) ```
0
591
A
Wizards' Duel
PROGRAMMING
900
[ "implementation", "math" ]
null
null
Harry Potter and He-Who-Must-Not-Be-Named engaged in a fight to the death once again. This time they are located at opposite ends of the corridor of length *l*. Two opponents simultaneously charge a deadly spell in the enemy. We know that the impulse of Harry's magic spell flies at a speed of *p* meters per second, and the impulse of You-Know-Who's magic spell flies at a speed of *q* meters per second. The impulses are moving through the corridor toward each other, and at the time of the collision they turn round and fly back to those who cast them without changing their original speeds. Then, as soon as the impulse gets back to it's caster, the wizard reflects it and sends again towards the enemy, without changing the original speed of the impulse. Since Harry has perfectly mastered the basics of magic, he knows that after the second collision both impulses will disappear, and a powerful explosion will occur exactly in the place of their collision. However, the young wizard isn't good at math, so he asks you to calculate the distance from his position to the place of the second meeting of the spell impulses, provided that the opponents do not change positions during the whole fight.
The first line of the input contains a single integer *l* (1<=≤<=*l*<=≤<=1<=000) — the length of the corridor where the fight takes place. The second line contains integer *p*, the third line contains integer *q* (1<=≤<=*p*,<=*q*<=≤<=500) — the speeds of magical impulses for Harry Potter and He-Who-Must-Not-Be-Named, respectively.
Print a single real number — the distance from the end of the corridor, where Harry is located, to the place of the second meeting of the spell impulses. Your answer will be considered correct if its absolute or relative error will not exceed 10<=-<=4. Namely: let's assume that your answer equals *a*, and the answer of the jury is *b*. The checker program will consider your answer correct if .
[ "100\n50\n50\n", "199\n60\n40\n" ]
[ "50\n", "119.4\n" ]
In the first sample the speeds of the impulses are equal, so both of their meetings occur exactly in the middle of the corridor.
500
[ { "input": "100\n50\n50", "output": "50" }, { "input": "199\n60\n40", "output": "119.4" }, { "input": "1\n1\n1", "output": "0.5" }, { "input": "1\n1\n500", "output": "0.001996007984" }, { "input": "1\n500\n1", "output": "0.998003992" }, { "input": "1\n500\n500", "output": "0.5" }, { "input": "1000\n1\n1", "output": "500" }, { "input": "1000\n1\n500", "output": "1.996007984" }, { "input": "1000\n500\n1", "output": "998.003992" }, { "input": "1000\n500\n500", "output": "500" }, { "input": "101\n11\n22", "output": "33.66666667" }, { "input": "987\n1\n3", "output": "246.75" }, { "input": "258\n25\n431", "output": "14.14473684" }, { "input": "979\n39\n60", "output": "385.6666667" }, { "input": "538\n479\n416", "output": "287.9351955" }, { "input": "583\n112\n248", "output": "181.3777778" }, { "input": "978\n467\n371", "output": "545.0190931" }, { "input": "980\n322\n193", "output": "612.7378641" }, { "input": "871\n401\n17", "output": "835.576555" }, { "input": "349\n478\n378", "output": "194.885514" }, { "input": "425\n458\n118", "output": "337.9340278" }, { "input": "919\n323\n458", "output": "380.0729834" }, { "input": "188\n59\n126", "output": "59.95675676" }, { "input": "644\n428\n484", "output": "302.2280702" }, { "input": "253\n80\n276", "output": "56.85393258" }, { "input": "745\n152\n417", "output": "199.0158172" }, { "input": "600\n221\n279", "output": "265.2" }, { "input": "690\n499\n430", "output": "370.6243272" }, { "input": "105\n68\n403", "output": "15.15923567" }, { "input": "762\n462\n371", "output": "422.6218487" }, { "input": "903\n460\n362", "output": "505.3284672" }, { "input": "886\n235\n95", "output": "630.9393939" }, { "input": "655\n203\n18", "output": "601.6515837" }, { "input": "718\n29\n375", "output": "51.53960396" }, { "input": "296\n467\n377", "output": "163.7819905" }, { "input": "539\n61\n56", "output": "281.017094" }, { "input": "133\n53\n124", "output": "39.82485876" }, { "input": "998\n224\n65", "output": "773.5363322" }, { "input": "961\n173\n47", "output": "755.6954545" }, { "input": "285\n468\n62", "output": "251.6603774" }, { "input": "496\n326\n429", "output": "214.1668874" }, { "input": "627\n150\n285", "output": "216.2068966" }, { "input": "961\n443\n50", "output": "863.535497" }, { "input": "623\n422\n217", "output": "411.4334898" }, { "input": "678\n295\n29", "output": "617.3148148" } ]
1,589,189,178
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
3
93
6,656,000
cd=int(input()) p=int(input()) q=int(input()) if(p==q): print(cd/2) elif(p>q): z=(p*cd)/100 print(z) elif(p<q): z=(q*cd)/100 print(z)
Title: Wizards' Duel Time Limit: None seconds Memory Limit: None megabytes Problem Description: Harry Potter and He-Who-Must-Not-Be-Named engaged in a fight to the death once again. This time they are located at opposite ends of the corridor of length *l*. Two opponents simultaneously charge a deadly spell in the enemy. We know that the impulse of Harry's magic spell flies at a speed of *p* meters per second, and the impulse of You-Know-Who's magic spell flies at a speed of *q* meters per second. The impulses are moving through the corridor toward each other, and at the time of the collision they turn round and fly back to those who cast them without changing their original speeds. Then, as soon as the impulse gets back to it's caster, the wizard reflects it and sends again towards the enemy, without changing the original speed of the impulse. Since Harry has perfectly mastered the basics of magic, he knows that after the second collision both impulses will disappear, and a powerful explosion will occur exactly in the place of their collision. However, the young wizard isn't good at math, so he asks you to calculate the distance from his position to the place of the second meeting of the spell impulses, provided that the opponents do not change positions during the whole fight. Input Specification: The first line of the input contains a single integer *l* (1<=≤<=*l*<=≤<=1<=000) — the length of the corridor where the fight takes place. The second line contains integer *p*, the third line contains integer *q* (1<=≤<=*p*,<=*q*<=≤<=500) — the speeds of magical impulses for Harry Potter and He-Who-Must-Not-Be-Named, respectively. Output Specification: Print a single real number — the distance from the end of the corridor, where Harry is located, to the place of the second meeting of the spell impulses. Your answer will be considered correct if its absolute or relative error will not exceed 10<=-<=4. Namely: let's assume that your answer equals *a*, and the answer of the jury is *b*. The checker program will consider your answer correct if . Demo Input: ['100\n50\n50\n', '199\n60\n40\n'] Demo Output: ['50\n', '119.4\n'] Note: In the first sample the speeds of the impulses are equal, so both of their meetings occur exactly in the middle of the corridor.
```python cd=int(input()) p=int(input()) q=int(input()) if(p==q): print(cd/2) elif(p>q): z=(p*cd)/100 print(z) elif(p<q): z=(q*cd)/100 print(z) ```
0
712
A
Memory and Crow
PROGRAMMING
800
[ "implementation", "math" ]
null
null
There are *n* integers *b*1,<=*b*2,<=...,<=*b**n* written in a row. For all *i* from 1 to *n*, values *a**i* are defined by the crows performing the following procedure: - The crow sets *a**i* initially 0. - The crow then adds *b**i* to *a**i*, subtracts *b**i*<=+<=1, adds the *b**i*<=+<=2 number, and so on until the *n*'th number. Thus, *a**i*<==<=*b**i*<=-<=*b**i*<=+<=1<=+<=*b**i*<=+<=2<=-<=*b**i*<=+<=3.... Memory gives you the values *a*1,<=*a*2,<=...,<=*a**n*, and he now wants you to find the initial numbers *b*1,<=*b*2,<=...,<=*b**n* written in the row? Can you do it?
The first line of the input contains a single integer *n* (2<=≤<=*n*<=≤<=100<=000) — the number of integers written in the row. The next line contains *n*, the *i*'th of which is *a**i* (<=-<=109<=≤<=*a**i*<=≤<=109) — the value of the *i*'th number.
Print *n* integers corresponding to the sequence *b*1,<=*b*2,<=...,<=*b**n*. It's guaranteed that the answer is unique and fits in 32-bit integer type.
[ "5\n6 -4 8 -2 3\n", "5\n3 -2 -1 5 6\n" ]
[ "2 4 6 1 3 \n", "1 -3 4 11 6 \n" ]
In the first sample test, the crows report the numbers 6, - 4, 8, - 2, and 3 when he starts at indices 1, 2, 3, 4 and 5 respectively. It is easy to check that the sequence 2 4 6 1 3 satisfies the reports. For example, 6 = 2 - 4 + 6 - 1 + 3, and  - 4 = 4 - 6 + 1 - 3. In the second sample test, the sequence 1,  - 3, 4, 11, 6 satisfies the reports. For example, 5 = 11 - 6 and 6 = 6.
500
[ { "input": "5\n6 -4 8 -2 3", "output": "2 4 6 1 3 " }, { "input": "5\n3 -2 -1 5 6", "output": "1 -3 4 11 6 " }, { "input": "10\n13 -2 532 -63 -23 -63 -64 -23 12 10", "output": "11 530 469 -86 -86 -127 -87 -11 22 10 " }, { "input": "10\n0 0 0 0 0 0 0 0 0 0", "output": "0 0 0 0 0 0 0 0 0 0 " }, { "input": "10\n1 -1 1 -1 1 -1 1 -1 1 -1", "output": "0 0 0 0 0 0 0 0 0 -1 " }, { "input": "10\n-1000000000 1000000000 -1000000000 1000000000 -1000000000 1000000000 -1000000000 1000000000 -1000000000 1000000000", "output": "0 0 0 0 0 0 0 0 0 1000000000 " }, { "input": "10\n124 532 -642 6482 -124 952 -235 7594 34 -12", "output": "656 -110 5840 6358 828 717 7359 7628 22 -12 " }, { "input": "10\n1294 35852 32749 537295 12048 53729 29357 58320 64739 1240", "output": "37146 68601 570044 549343 65777 83086 87677 123059 65979 1240 " } ]
1,617,599,746
2,147,483,647
Python 3
OK
TESTS
49
233
8,192,000
n=int(input()) numbers=list(map(int,input().split())) iN=list() for i in range(n-1): iN.append(numbers[i]+numbers[i+1]) iN.append(numbers[n-1]) print(*iN)
Title: Memory and Crow Time Limit: None seconds Memory Limit: None megabytes Problem Description: There are *n* integers *b*1,<=*b*2,<=...,<=*b**n* written in a row. For all *i* from 1 to *n*, values *a**i* are defined by the crows performing the following procedure: - The crow sets *a**i* initially 0. - The crow then adds *b**i* to *a**i*, subtracts *b**i*<=+<=1, adds the *b**i*<=+<=2 number, and so on until the *n*'th number. Thus, *a**i*<==<=*b**i*<=-<=*b**i*<=+<=1<=+<=*b**i*<=+<=2<=-<=*b**i*<=+<=3.... Memory gives you the values *a*1,<=*a*2,<=...,<=*a**n*, and he now wants you to find the initial numbers *b*1,<=*b*2,<=...,<=*b**n* written in the row? Can you do it? Input Specification: The first line of the input contains a single integer *n* (2<=≤<=*n*<=≤<=100<=000) — the number of integers written in the row. The next line contains *n*, the *i*'th of which is *a**i* (<=-<=109<=≤<=*a**i*<=≤<=109) — the value of the *i*'th number. Output Specification: Print *n* integers corresponding to the sequence *b*1,<=*b*2,<=...,<=*b**n*. It's guaranteed that the answer is unique and fits in 32-bit integer type. Demo Input: ['5\n6 -4 8 -2 3\n', '5\n3 -2 -1 5 6\n'] Demo Output: ['2 4 6 1 3 \n', '1 -3 4 11 6 \n'] Note: In the first sample test, the crows report the numbers 6, - 4, 8, - 2, and 3 when he starts at indices 1, 2, 3, 4 and 5 respectively. It is easy to check that the sequence 2 4 6 1 3 satisfies the reports. For example, 6 = 2 - 4 + 6 - 1 + 3, and  - 4 = 4 - 6 + 1 - 3. In the second sample test, the sequence 1,  - 3, 4, 11, 6 satisfies the reports. For example, 5 = 11 - 6 and 6 = 6.
```python n=int(input()) numbers=list(map(int,input().split())) iN=list() for i in range(n-1): iN.append(numbers[i]+numbers[i+1]) iN.append(numbers[n-1]) print(*iN) ```
3
677
A
Vanya and Fence
PROGRAMMING
800
[ "implementation" ]
null
null
Vanya and his friends are walking along the fence of height *h* and they do not want the guard to notice them. In order to achieve this the height of each of the friends should not exceed *h*. If the height of some person is greater than *h* he can bend down and then he surely won't be noticed by the guard. The height of the *i*-th person is equal to *a**i*. Consider the width of the person walking as usual to be equal to 1, while the width of the bent person is equal to 2. Friends want to talk to each other while walking, so they would like to walk in a single row. What is the minimum width of the road, such that friends can walk in a row and remain unattended by the guard?
The first line of the input contains two integers *n* and *h* (1<=≤<=*n*<=≤<=1000, 1<=≤<=*h*<=≤<=1000) — the number of friends and the height of the fence, respectively. The second line contains *n* integers *a**i* (1<=≤<=*a**i*<=≤<=2*h*), the *i*-th of them is equal to the height of the *i*-th person.
Print a single integer — the minimum possible valid width of the road.
[ "3 7\n4 5 14\n", "6 1\n1 1 1 1 1 1\n", "6 5\n7 6 8 9 10 5\n" ]
[ "4\n", "6\n", "11\n" ]
In the first sample, only person number 3 must bend down, so the required width is equal to 1 + 1 + 2 = 4. In the second sample, all friends are short enough and no one has to bend, so the width 1 + 1 + 1 + 1 + 1 + 1 = 6 is enough. In the third sample, all the persons have to bend, except the last one. The required minimum width of the road is equal to 2 + 2 + 2 + 2 + 2 + 1 = 11.
500
[ { "input": "3 7\n4 5 14", "output": "4" }, { "input": "6 1\n1 1 1 1 1 1", "output": "6" }, { "input": "6 5\n7 6 8 9 10 5", "output": "11" }, { "input": "10 420\n214 614 297 675 82 740 174 23 255 15", "output": "13" }, { "input": "10 561\n657 23 1096 487 785 66 481 554 1000 821", "output": "15" }, { "input": "100 342\n478 143 359 336 162 333 385 515 117 496 310 538 469 539 258 676 466 677 1 296 150 560 26 213 627 221 255 126 617 174 279 178 24 435 70 145 619 46 669 566 300 67 576 251 58 176 441 564 569 194 24 669 73 262 457 259 619 78 400 579 222 626 269 47 80 315 160 194 455 186 315 424 197 246 683 220 68 682 83 233 290 664 273 598 362 305 674 614 321 575 362 120 14 534 62 436 294 351 485 396", "output": "144" }, { "input": "100 290\n244 49 276 77 449 261 468 458 201 424 9 131 300 88 432 394 104 77 13 289 435 259 111 453 168 394 156 412 351 576 178 530 81 271 228 564 125 328 42 372 205 61 180 471 33 360 567 331 222 318 241 117 529 169 188 484 202 202 299 268 246 343 44 364 333 494 59 236 84 485 50 8 428 8 571 227 205 310 210 9 324 472 368 490 114 84 296 305 411 351 569 393 283 120 510 171 232 151 134 366", "output": "145" }, { "input": "1 1\n1", "output": "1" }, { "input": "1 1\n2", "output": "2" }, { "input": "46 71\n30 26 56 138 123 77 60 122 73 45 79 10 130 3 14 1 38 46 128 50 82 16 32 68 28 98 62 106 2 49 131 11 114 39 139 70 40 50 45 137 33 30 35 136 135 19", "output": "63" }, { "input": "20 723\n212 602 293 591 754 91 1135 640 80 495 845 928 1399 498 926 1431 1226 869 814 1386", "output": "31" }, { "input": "48 864\n843 1020 751 1694 18 1429 1395 1174 272 1158 1628 1233 1710 441 765 561 778 748 1501 1200 563 1263 1398 1687 1518 1640 1591 839 500 466 1603 1587 1201 1209 432 868 1159 639 649 628 9 91 1036 147 896 1557 941 518", "output": "75" }, { "input": "26 708\n549 241 821 734 945 1161 566 1268 216 30 1142 730 529 1014 255 168 796 1148 89 113 1328 286 743 871 1259 1397", "output": "41" }, { "input": "75 940\n1620 1745 1599 441 64 1466 1496 1239 1716 1475 778 106 1136 1212 1261 444 781 257 1071 747 626 232 609 1544 682 1326 469 1361 1460 1450 1207 1319 922 625 1737 1057 1698 592 692 80 1016 541 1254 201 682 1007 847 206 1066 809 259 109 240 1611 219 1455 1326 1377 1827 786 42 1002 1382 1592 543 1866 1198 334 1524 1760 340 1566 955 257 1118", "output": "116" } ]
1,693,661,840
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
0
30
0
n, t = map(int, input().split()) ppl = input() for _ in range(t): ppl = ppl.replace("BG", "GB") print(ppl)
Title: Vanya and Fence Time Limit: None seconds Memory Limit: None megabytes Problem Description: Vanya and his friends are walking along the fence of height *h* and they do not want the guard to notice them. In order to achieve this the height of each of the friends should not exceed *h*. If the height of some person is greater than *h* he can bend down and then he surely won't be noticed by the guard. The height of the *i*-th person is equal to *a**i*. Consider the width of the person walking as usual to be equal to 1, while the width of the bent person is equal to 2. Friends want to talk to each other while walking, so they would like to walk in a single row. What is the minimum width of the road, such that friends can walk in a row and remain unattended by the guard? Input Specification: The first line of the input contains two integers *n* and *h* (1<=≤<=*n*<=≤<=1000, 1<=≤<=*h*<=≤<=1000) — the number of friends and the height of the fence, respectively. The second line contains *n* integers *a**i* (1<=≤<=*a**i*<=≤<=2*h*), the *i*-th of them is equal to the height of the *i*-th person. Output Specification: Print a single integer — the minimum possible valid width of the road. Demo Input: ['3 7\n4 5 14\n', '6 1\n1 1 1 1 1 1\n', '6 5\n7 6 8 9 10 5\n'] Demo Output: ['4\n', '6\n', '11\n'] Note: In the first sample, only person number 3 must bend down, so the required width is equal to 1 + 1 + 2 = 4. In the second sample, all friends are short enough and no one has to bend, so the width 1 + 1 + 1 + 1 + 1 + 1 = 6 is enough. In the third sample, all the persons have to bend, except the last one. The required minimum width of the road is equal to 2 + 2 + 2 + 2 + 2 + 1 = 11.
```python n, t = map(int, input().split()) ppl = input() for _ in range(t): ppl = ppl.replace("BG", "GB") print(ppl) ```
0
381
A
Sereja and Dima
PROGRAMMING
800
[ "greedy", "implementation", "two pointers" ]
null
null
Sereja and Dima play a game. The rules of the game are very simple. The players have *n* cards in a row. Each card contains a number, all numbers on the cards are distinct. The players take turns, Sereja moves first. During his turn a player can take one card: either the leftmost card in a row, or the rightmost one. The game ends when there is no more cards. The player who has the maximum sum of numbers on his cards by the end of the game, wins. Sereja and Dima are being greedy. Each of them chooses the card with the larger number during his move. Inna is a friend of Sereja and Dima. She knows which strategy the guys are using, so she wants to determine the final score, given the initial state of the game. Help her.
The first line contains integer *n* (1<=≤<=*n*<=≤<=1000) — the number of cards on the table. The second line contains space-separated numbers on the cards from left to right. The numbers on the cards are distinct integers from 1 to 1000.
On a single line, print two integers. The first number is the number of Sereja's points at the end of the game, the second number is the number of Dima's points at the end of the game.
[ "4\n4 1 2 10\n", "7\n1 2 3 4 5 6 7\n" ]
[ "12 5\n", "16 12\n" ]
In the first sample Sereja will take cards with numbers 10 and 2, so Sereja's sum is 12. Dima will take cards with numbers 4 and 1, so Dima's sum is 5.
500
[ { "input": "4\n4 1 2 10", "output": "12 5" }, { "input": "7\n1 2 3 4 5 6 7", "output": "16 12" }, { "input": "42\n15 29 37 22 16 5 26 31 6 32 19 3 45 36 33 14 25 20 48 7 42 11 24 28 9 18 8 21 47 17 38 40 44 4 35 1 43 39 41 27 12 13", "output": "613 418" }, { "input": "43\n32 1 15 48 38 26 25 14 20 44 11 30 3 42 49 19 18 46 5 45 10 23 34 9 29 41 2 52 6 17 35 4 50 22 33 51 7 28 47 13 39 37 24", "output": "644 500" }, { "input": "1\n3", "output": "3 0" }, { "input": "45\n553 40 94 225 415 471 126 190 647 394 515 303 189 159 308 6 139 132 326 78 455 75 85 295 135 613 360 614 351 228 578 259 258 591 444 29 33 463 561 174 368 183 140 168 646", "output": "6848 6568" }, { "input": "44\n849 373 112 307 479 608 856 769 526 82 168 143 573 762 115 501 688 36 214 450 396 496 236 309 287 786 397 43 811 141 745 846 350 270 276 677 420 459 403 722 267 54 394 727", "output": "9562 9561" }, { "input": "35\n10 15 18 1 28 16 2 33 6 22 23 4 9 25 35 8 7 26 3 20 30 14 31 19 27 32 11 5 29 24 21 34 13 17 12", "output": "315 315" }, { "input": "17\n580 376 191 496 73 44 520 357 483 149 81 178 514 300 216 598 304", "output": "3238 2222" }, { "input": "30\n334 443 223 424 168 549 189 303 429 559 516 220 459 134 344 346 316 446 209 148 487 526 69 286 102 366 518 280 392 325", "output": "5246 4864" }, { "input": "95\n122 29 188 265 292 287 183 225 222 187 155 256 64 148 173 278 218 136 290 17 31 130 2 87 57 283 255 280 68 166 174 142 102 39 116 206 288 154 26 78 296 172 184 232 77 91 277 8 249 186 94 93 207 251 257 195 101 299 193 124 293 65 58 35 24 302 220 189 252 125 27 284 247 182 141 103 198 97 234 83 281 216 85 180 267 236 109 143 149 239 79 300 191 244 71", "output": "8147 7807" }, { "input": "1\n1", "output": "1 0" } ]
1,670,480,355
2,147,483,647
Python 3
OK
TESTS
34
46
0
n=int(input()) a=list(map(int,input().split())) k=0 s=0 d=0 while len(a)>0: a1=a[0] a2=a[len(a)-1] if a1>a2: a.pop(0) c=a1 else: a.pop(len(a)-1) c=a2 if k == 0: k=1 s+=c else: k=0 d+=c print(s,d)
Title: Sereja and Dima Time Limit: None seconds Memory Limit: None megabytes Problem Description: Sereja and Dima play a game. The rules of the game are very simple. The players have *n* cards in a row. Each card contains a number, all numbers on the cards are distinct. The players take turns, Sereja moves first. During his turn a player can take one card: either the leftmost card in a row, or the rightmost one. The game ends when there is no more cards. The player who has the maximum sum of numbers on his cards by the end of the game, wins. Sereja and Dima are being greedy. Each of them chooses the card with the larger number during his move. Inna is a friend of Sereja and Dima. She knows which strategy the guys are using, so she wants to determine the final score, given the initial state of the game. Help her. Input Specification: The first line contains integer *n* (1<=≤<=*n*<=≤<=1000) — the number of cards on the table. The second line contains space-separated numbers on the cards from left to right. The numbers on the cards are distinct integers from 1 to 1000. Output Specification: On a single line, print two integers. The first number is the number of Sereja's points at the end of the game, the second number is the number of Dima's points at the end of the game. Demo Input: ['4\n4 1 2 10\n', '7\n1 2 3 4 5 6 7\n'] Demo Output: ['12 5\n', '16 12\n'] Note: In the first sample Sereja will take cards with numbers 10 and 2, so Sereja's sum is 12. Dima will take cards with numbers 4 and 1, so Dima's sum is 5.
```python n=int(input()) a=list(map(int,input().split())) k=0 s=0 d=0 while len(a)>0: a1=a[0] a2=a[len(a)-1] if a1>a2: a.pop(0) c=a1 else: a.pop(len(a)-1) c=a2 if k == 0: k=1 s+=c else: k=0 d+=c print(s,d) ```
3
368
B
Sereja and Suffixes
PROGRAMMING
1,100
[ "data structures", "dp" ]
null
null
Sereja has an array *a*, consisting of *n* integers *a*1, *a*2, ..., *a**n*. The boy cannot sit and do nothing, he decided to study an array. Sereja took a piece of paper and wrote out *m* integers *l*1,<=*l*2,<=...,<=*l**m* (1<=≤<=*l**i*<=≤<=*n*). For each number *l**i* he wants to know how many distinct numbers are staying on the positions *l**i*, *l**i*<=+<=1, ..., *n*. Formally, he want to find the number of distinct numbers among *a**l**i*,<=*a**l**i*<=+<=1,<=...,<=*a**n*.? Sereja wrote out the necessary array elements but the array was so large and the boy was so pressed for time. Help him, find the answer for the described question for each *l**i*.
The first line contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=105). The second line contains *n* integers *a*1, *a*2, ..., *a**n* (1<=≤<=*a**i*<=≤<=105) — the array elements. Next *m* lines contain integers *l*1,<=*l*2,<=...,<=*l**m*. The *i*-th line contains integer *l**i* (1<=≤<=*l**i*<=≤<=*n*).
Print *m* lines — on the *i*-th line print the answer to the number *l**i*.
[ "10 10\n1 2 3 4 1 2 3 4 100000 99999\n1\n2\n3\n4\n5\n6\n7\n8\n9\n10\n" ]
[ "6\n6\n6\n6\n6\n5\n4\n3\n2\n1\n" ]
none
1,000
[ { "input": "10 10\n1 2 3 4 1 2 3 4 100000 99999\n1\n2\n3\n4\n5\n6\n7\n8\n9\n10", "output": "6\n6\n6\n6\n6\n5\n4\n3\n2\n1" }, { "input": "8 3\n8 6 4 3 4 2 4 8\n6\n4\n2", "output": "3\n4\n5" }, { "input": "7 10\n1 3 8 6 2 2 7\n4\n2\n6\n3\n4\n4\n6\n2\n7\n4", "output": "3\n5\n2\n4\n3\n3\n2\n5\n1\n3" }, { "input": "10 2\n2 6 5 7 2 2 3 2 4 8\n1\n2", "output": "7\n7" }, { "input": "7 1\n68346 10956 76708 23018 84063 34833 80407\n1", "output": "7" }, { "input": "2 2\n8 4\n1\n1", "output": "2\n2" }, { "input": "1 5\n5\n1\n1\n1\n1\n1", "output": "1\n1\n1\n1\n1" }, { "input": "4 7\n3 1 4 2\n4\n1\n2\n3\n2\n4\n4", "output": "1\n4\n3\n2\n3\n1\n1" }, { "input": "4 3\n9 1 7 1\n1\n4\n2", "output": "3\n1\n2" }, { "input": "8 3\n9280 6676 2720 6172 8329 10413 3975 1394\n5\n6\n7", "output": "4\n3\n2" }, { "input": "1 1\n1\n1", "output": "1" } ]
1,698,423,130
2,147,483,647
Python 3
TIME_LIMIT_EXCEEDED
TESTS
10
1,000
10,752,000
# -*- coding: utf-8 -*- """ Created on Sat Oct 28 00:04:15 2023 @author: 苏柔德 2300011012 """ n,m=map(int, input().split()) a=list(map(int, input().split())) for _ in range(m): i=int(input()) print(len(set(a[i-1:])))
Title: Sereja and Suffixes Time Limit: None seconds Memory Limit: None megabytes Problem Description: Sereja has an array *a*, consisting of *n* integers *a*1, *a*2, ..., *a**n*. The boy cannot sit and do nothing, he decided to study an array. Sereja took a piece of paper and wrote out *m* integers *l*1,<=*l*2,<=...,<=*l**m* (1<=≤<=*l**i*<=≤<=*n*). For each number *l**i* he wants to know how many distinct numbers are staying on the positions *l**i*, *l**i*<=+<=1, ..., *n*. Formally, he want to find the number of distinct numbers among *a**l**i*,<=*a**l**i*<=+<=1,<=...,<=*a**n*.? Sereja wrote out the necessary array elements but the array was so large and the boy was so pressed for time. Help him, find the answer for the described question for each *l**i*. Input Specification: The first line contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=105). The second line contains *n* integers *a*1, *a*2, ..., *a**n* (1<=≤<=*a**i*<=≤<=105) — the array elements. Next *m* lines contain integers *l*1,<=*l*2,<=...,<=*l**m*. The *i*-th line contains integer *l**i* (1<=≤<=*l**i*<=≤<=*n*). Output Specification: Print *m* lines — on the *i*-th line print the answer to the number *l**i*. Demo Input: ['10 10\n1 2 3 4 1 2 3 4 100000 99999\n1\n2\n3\n4\n5\n6\n7\n8\n9\n10\n'] Demo Output: ['6\n6\n6\n6\n6\n5\n4\n3\n2\n1\n'] Note: none
```python # -*- coding: utf-8 -*- """ Created on Sat Oct 28 00:04:15 2023 @author: 苏柔德 2300011012 """ n,m=map(int, input().split()) a=list(map(int, input().split())) for _ in range(m): i=int(input()) print(len(set(a[i-1:]))) ```
0
82
A
Double Cola
PROGRAMMING
1,100
[ "implementation", "math" ]
A. Double Cola
1
256
Sheldon, Leonard, Penny, Rajesh and Howard are in the queue for a "Double Cola" drink vending machine; there are no other people in the queue. The first one in the queue (Sheldon) buys a can, drinks it and doubles! The resulting two Sheldons go to the end of the queue. Then the next in the queue (Leonard) buys a can, drinks it and gets to the end of the queue as two Leonards, and so on. This process continues ad infinitum. For example, Penny drinks the third can of cola and the queue will look like this: Rajesh, Howard, Sheldon, Sheldon, Leonard, Leonard, Penny, Penny. Write a program that will print the name of a man who will drink the *n*-th can. Note that in the very beginning the queue looks like that: Sheldon, Leonard, Penny, Rajesh, Howard. The first person is Sheldon.
The input data consist of a single integer *n* (1<=≤<=*n*<=≤<=109). It is guaranteed that the pretests check the spelling of all the five names, that is, that they contain all the five possible answers.
Print the single line — the name of the person who drinks the *n*-th can of cola. The cans are numbered starting from 1. Please note that you should spell the names like this: "Sheldon", "Leonard", "Penny", "Rajesh", "Howard" (without the quotes). In that order precisely the friends are in the queue initially.
[ "1\n", "6\n", "1802\n" ]
[ "Sheldon\n", "Sheldon\n", "Penny\n" ]
none
500
[ { "input": "1", "output": "Sheldon" }, { "input": "6", "output": "Sheldon" }, { "input": "1802", "output": "Penny" }, { "input": "1", "output": "Sheldon" }, { "input": "2", "output": "Leonard" }, { "input": "3", "output": "Penny" }, { "input": "4", "output": "Rajesh" }, { "input": "5", "output": "Howard" }, { "input": "10", "output": "Penny" }, { "input": "534", "output": "Rajesh" }, { "input": "5033", "output": "Howard" }, { "input": "10010", "output": "Howard" }, { "input": "500000000", "output": "Penny" }, { "input": "63", "output": "Rajesh" }, { "input": "841", "output": "Leonard" }, { "input": "3667", "output": "Penny" }, { "input": "38614", "output": "Howard" }, { "input": "282798", "output": "Rajesh" }, { "input": "9266286", "output": "Rajesh" }, { "input": "27385966", "output": "Leonard" }, { "input": "121580142", "output": "Penny" }, { "input": "5", "output": "Howard" }, { "input": "300", "output": "Howard" }, { "input": "1745", "output": "Leonard" }, { "input": "8302", "output": "Rajesh" }, { "input": "184518", "output": "Sheldon" }, { "input": "1154414", "output": "Rajesh" }, { "input": "28643950", "output": "Leonard" }, { "input": "159222638", "output": "Howard" }, { "input": "24", "output": "Penny" }, { "input": "505", "output": "Penny" }, { "input": "4425", "output": "Rajesh" }, { "input": "12079", "output": "Sheldon" }, { "input": "469726", "output": "Penny" }, { "input": "3961838", "output": "Penny" }, { "input": "57710446", "output": "Leonard" }, { "input": "80719470", "output": "Howard" }, { "input": "1000000000", "output": "Penny" }, { "input": "999999999", "output": "Penny" }, { "input": "999999998", "output": "Penny" }, { "input": "5", "output": "Howard" } ]
1,680,639,018
2,147,483,647
Python 3
TIME_LIMIT_EXCEEDED
TESTS
12
1,000
1,638,400
n = int(input()) queue = ["Sheldon", "Leonard", "Penny", "Rajesh", "Howard"] for i in range(n): a = queue.pop(0) if i == n - 1: print(a) queue.append(a) queue.append(a)
Title: Double Cola Time Limit: 1 seconds Memory Limit: 256 megabytes Problem Description: Sheldon, Leonard, Penny, Rajesh and Howard are in the queue for a "Double Cola" drink vending machine; there are no other people in the queue. The first one in the queue (Sheldon) buys a can, drinks it and doubles! The resulting two Sheldons go to the end of the queue. Then the next in the queue (Leonard) buys a can, drinks it and gets to the end of the queue as two Leonards, and so on. This process continues ad infinitum. For example, Penny drinks the third can of cola and the queue will look like this: Rajesh, Howard, Sheldon, Sheldon, Leonard, Leonard, Penny, Penny. Write a program that will print the name of a man who will drink the *n*-th can. Note that in the very beginning the queue looks like that: Sheldon, Leonard, Penny, Rajesh, Howard. The first person is Sheldon. Input Specification: The input data consist of a single integer *n* (1<=≤<=*n*<=≤<=109). It is guaranteed that the pretests check the spelling of all the five names, that is, that they contain all the five possible answers. Output Specification: Print the single line — the name of the person who drinks the *n*-th can of cola. The cans are numbered starting from 1. Please note that you should spell the names like this: "Sheldon", "Leonard", "Penny", "Rajesh", "Howard" (without the quotes). In that order precisely the friends are in the queue initially. Demo Input: ['1\n', '6\n', '1802\n'] Demo Output: ['Sheldon\n', 'Sheldon\n', 'Penny\n'] Note: none
```python n = int(input()) queue = ["Sheldon", "Leonard", "Penny", "Rajesh", "Howard"] for i in range(n): a = queue.pop(0) if i == n - 1: print(a) queue.append(a) queue.append(a) ```
0
393
A
Nineteen
PROGRAMMING
0
[]
null
null
Alice likes word "nineteen" very much. She has a string *s* and wants the string to contain as many such words as possible. For that reason she can rearrange the letters of the string. For example, if she has string "xiineteenppnnnewtnee", she can get string "xnineteenppnineteenw", containing (the occurrences marked) two such words. More formally, word "nineteen" occurs in the string the number of times you can read it starting from some letter of the string. Of course, you shouldn't skip letters. Help her to find the maximum number of "nineteen"s that she can get in her string.
The first line contains a non-empty string *s*, consisting only of lowercase English letters. The length of string *s* doesn't exceed 100.
Print a single integer — the maximum number of "nineteen"s that she can get in her string.
[ "nniinneetteeeenn\n", "nneteenabcnneteenabcnneteenabcnneteenabcnneteenabcii\n", "nineteenineteen\n" ]
[ "2", "2", "2" ]
none
500
[ { "input": "nniinneetteeeenn", "output": "2" }, { "input": "nneteenabcnneteenabcnneteenabcnneteenabcnneteenabcii", "output": "2" }, { "input": "nineteenineteen", "output": "2" }, { "input": "nssemsnnsitjtihtthij", "output": "0" }, { "input": "eehihnttehtherjsihihnrhimihrjinjiehmtjimnrss", "output": "1" }, { "input": "rrrteiehtesisntnjirtitijnjjjthrsmhtneirjimniemmnrhirssjnhetmnmjejjnjjritjttnnrhnjs", "output": "2" }, { "input": "mmrehtretseihsrjmtsenemniehssnisijmsnntesismmtmthnsieijjjnsnhisi", "output": "2" }, { "input": "hshretttnntmmiertrrnjihnrmshnthirnnirrheinnnrjiirshthsrsijtrrtrmnjrrjnresnintnmtrhsnjrinsseimn", "output": "1" }, { "input": "snmmensntritetnmmmerhhrmhnehehtesmhthseemjhmnrti", "output": "2" }, { "input": "rmeetriiitijmrenmeiijt", "output": "0" }, { "input": "ihimeitimrmhriemsjhrtjtijtesmhemnmmrsetmjttthtjhnnmirtimne", "output": "1" }, { "input": "rhtsnmnesieernhstjnmmirthhieejsjttsiierhihhrrijhrrnejsjer", "output": "2" }, { "input": "emmtjsjhretehmiiiestmtmnmissjrstnsnjmhimjmststsitemtttjrnhsrmsenjtjim", "output": "2" }, { "input": "nmehhjrhirniitshjtrrtitsjsntjhrstjehhhrrerhemehjeermhmhjejjesnhsiirheijjrnrjmminneeehtm", "output": "3" }, { "input": "hsntijjetmehejtsitnthietssmeenjrhhetsnjrsethisjrtrhrierjtmimeenjnhnijeesjttrmn", "output": "3" }, { "input": "jnirirhmirmhisemittnnsmsttesjhmjnsjsmntisheneiinsrjsjirnrmnjmjhmistntersimrjni", "output": "1" }, { "input": "neithjhhhtmejjnmieishethmtetthrienrhjmjenrmtejerernmthmsnrthhtrimmtmshm", "output": "2" }, { "input": "sithnrsnemhijsnjitmijjhejjrinejhjinhtisttteermrjjrtsirmessejireihjnnhhemiirmhhjeet", "output": "3" }, { "input": "jrjshtjstteh", "output": "0" }, { "input": "jsihrimrjnnmhttmrtrenetimemjnshnimeiitmnmjishjjneisesrjemeshjsijithtn", "output": "2" }, { "input": "hhtjnnmsemermhhtsstejehsssmnesereehnnsnnremjmmieethmirjjhn", "output": "2" }, { "input": "tmnersmrtsehhntsietttrehrhneiireijnijjejmjhei", "output": "1" }, { "input": "mtstiresrtmesritnjriirehtermtrtseirtjrhsejhhmnsineinsjsin", "output": "2" }, { "input": "ssitrhtmmhtnmtreijteinimjemsiiirhrttinsnneshintjnin", "output": "1" }, { "input": "rnsrsmretjiitrjthhritniijhjmm", "output": "0" }, { "input": "hntrteieimrimteemenserntrejhhmijmtjjhnsrsrmrnsjseihnjmehtthnnithirnhj", "output": "3" }, { "input": "nmmtsmjrntrhhtmimeresnrinstjnhiinjtnjjjnthsintmtrhijnrnmtjihtinmni", "output": "0" }, { "input": "eihstiirnmteejeehimttrijittjsntjejmessstsemmtristjrhenithrrsssihnthheehhrnmimssjmejjreimjiemrmiis", "output": "2" }, { "input": "srthnimimnemtnmhsjmmmjmmrsrisehjseinemienntetmitjtnnneseimhnrmiinsismhinjjnreehseh", "output": "3" }, { "input": "etrsmrjehntjjimjnmsresjnrthjhehhtreiijjminnheeiinseenmmethiemmistsei", "output": "3" }, { "input": "msjeshtthsieshejsjhsnhejsihisijsertenrshhrthjhiirijjneinjrtrmrs", "output": "1" }, { "input": "mehsmstmeejrhhsjihntjmrjrihssmtnensttmirtieehimj", "output": "1" }, { "input": "mmmsermimjmrhrhejhrrejermsneheihhjemnehrhihesnjsehthjsmmjeiejmmnhinsemjrntrhrhsmjtttsrhjjmejj", "output": "2" }, { "input": "rhsmrmesijmmsnsmmhertnrhsetmisshriirhetmjihsmiinimtrnitrseii", "output": "1" }, { "input": "iihienhirmnihh", "output": "0" }, { "input": "ismtthhshjmhisssnmnhe", "output": "0" }, { "input": "rhsmnrmhejshinnjrtmtsssijimimethnm", "output": "0" }, { "input": "eehnshtiriejhiirntminrirnjihmrnittnmmnjejjhjtennremrnssnejtntrtsiejjijisermj", "output": "3" }, { "input": "rnhmeesnhttrjintnhnrhristjrthhrmehrhjmjhjehmstrijemjmmistes", "output": "2" }, { "input": "ssrmjmjeeetrnimemrhimes", "output": "0" }, { "input": "n", "output": "0" }, { "input": "ni", "output": "0" }, { "input": "nine", "output": "0" }, { "input": "nineteenineteenineteenineteenineteenineteenineteenineteenineteenineteenineteenineteenineteen", "output": "13" }, { "input": "ninetee", "output": "0" }, { "input": "mzbmweyydiadtlcouegmdbyfwurpwbpuvhifnuapwynd", "output": "0" }, { "input": "zenudggmyopddhszhrbmftgzmjorabhgojdtfnzxjkayjlkgczsyshczutkdch", "output": "0" }, { "input": "rtzxovxqfapkdmelxiyjroohufhbakpmmvaxq", "output": "0" }, { "input": "zninetneeineteeniwnteeennieteenineteenineteenineteenineteenineteenineteenineteenineteeninetzeenz", "output": "13" }, { "input": "nnnnnnniiiiiiiiiiiitttttttttteeeeeeeeeeeeeeeeee", "output": "3" }, { "input": "ttttiiiieeeeeeeeeeeennnnnnnnn", "output": "4" }, { "input": "ttttttttteeeeeeeeeeeeeeeeeeeeeiiiiiiiiiiiinnnnnnn", "output": "3" }, { "input": "nnnnnnnnnneeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeiiiiiiiiiiiiiiiiiiiitttttttttttttttttttt", "output": "4" }, { "input": "eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeiiiiiiiiiiiiiiiiittttttttttttttttnnnnnnn", "output": "3" }, { "input": "nineeen", "output": "0" }, { "input": "nineteeeeeeeeeeeeeeeeettttttttttttttttttiiiiiiiiiiiiiiiiii", "output": "0" }, { "input": "nineteenieteenieteenieteenieteenieteenieteen", "output": "4" }, { "input": "nineteenineteenineteenineteenineteen", "output": "5" } ]
1,668,829,292
2,147,483,647
Python 3
RUNTIME_ERROR
TESTS
18
46
0
s = input() dt={} for i in s: if i in dt.keys(): dt[i]+=1 else: dt[i]=1 ans = min({(dt['n']-1)//2, dt['e']//3, dt['i'], dt['t']}) print(ans)
Title: Nineteen Time Limit: None seconds Memory Limit: None megabytes Problem Description: Alice likes word "nineteen" very much. She has a string *s* and wants the string to contain as many such words as possible. For that reason she can rearrange the letters of the string. For example, if she has string "xiineteenppnnnewtnee", she can get string "xnineteenppnineteenw", containing (the occurrences marked) two such words. More formally, word "nineteen" occurs in the string the number of times you can read it starting from some letter of the string. Of course, you shouldn't skip letters. Help her to find the maximum number of "nineteen"s that she can get in her string. Input Specification: The first line contains a non-empty string *s*, consisting only of lowercase English letters. The length of string *s* doesn't exceed 100. Output Specification: Print a single integer — the maximum number of "nineteen"s that she can get in her string. Demo Input: ['nniinneetteeeenn\n', 'nneteenabcnneteenabcnneteenabcnneteenabcnneteenabcii\n', 'nineteenineteen\n'] Demo Output: ['2', '2', '2'] Note: none
```python s = input() dt={} for i in s: if i in dt.keys(): dt[i]+=1 else: dt[i]=1 ans = min({(dt['n']-1)//2, dt['e']//3, dt['i'], dt['t']}) print(ans) ```
-1
599
A
Patrick and Shopping
PROGRAMMING
800
[ "implementation" ]
null
null
Today Patrick waits for a visit from his friend Spongebob. To prepare for the visit, Patrick needs to buy some goodies in two stores located near his house. There is a *d*1 meter long road between his house and the first shop and a *d*2 meter long road between his house and the second shop. Also, there is a road of length *d*3 directly connecting these two shops to each other. Help Patrick calculate the minimum distance that he needs to walk in order to go to both shops and return to his house. Patrick always starts at his house. He should visit both shops moving only along the three existing roads and return back to his house. He doesn't mind visiting the same shop or passing the same road multiple times. The only goal is to minimize the total distance traveled.
The first line of the input contains three integers *d*1, *d*2, *d*3 (1<=≤<=*d*1,<=*d*2,<=*d*3<=≤<=108) — the lengths of the paths. - *d*1 is the length of the path connecting Patrick's house and the first shop; - *d*2 is the length of the path connecting Patrick's house and the second shop; - *d*3 is the length of the path connecting both shops.
Print the minimum distance that Patrick will have to walk in order to visit both shops and return to his house.
[ "10 20 30\n", "1 1 5\n" ]
[ "60\n", "4\n" ]
The first sample is shown on the picture in the problem statement. One of the optimal routes is: house <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> first shop <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> second shop <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> house. In the second sample one of the optimal routes is: house <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> first shop <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> house <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> second shop <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> house.
500
[ { "input": "10 20 30", "output": "60" }, { "input": "1 1 5", "output": "4" }, { "input": "100 33 34", "output": "134" }, { "input": "777 777 777", "output": "2331" }, { "input": "2 2 8", "output": "8" }, { "input": "12 34 56", "output": "92" }, { "input": "789 101112 131415", "output": "203802" }, { "input": "27485716 99999999 35182", "output": "55041796" }, { "input": "1 293548 5", "output": "12" }, { "input": "12059 259855 5874875", "output": "543828" }, { "input": "46981 105809 585858", "output": "305580" }, { "input": "9889 1221 2442", "output": "7326" }, { "input": "100500 200600 300700", "output": "601800" }, { "input": "318476 318476 318476", "output": "955428" }, { "input": "23985 3353 75633", "output": "54676" }, { "input": "120 1298 2222", "output": "2836" }, { "input": "98437 23487 666672", "output": "243848" }, { "input": "100000000 100000000 100000000", "output": "300000000" }, { "input": "2 5 2", "output": "8" }, { "input": "1 1000 1", "output": "4" }, { "input": "1 100000000 1", "output": "4" } ]
1,669,491,932
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
2
31
0
md1,md2,mm = map(int,input().split()) if (md1 + md2)*2 <= 2*mm: print((md1+md2)*2) else: print(mm*2)
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 md1,md2,mm = map(int,input().split()) if (md1 + md2)*2 <= 2*mm: print((md1+md2)*2) else: print(mm*2) ```
0
13
A
Numbers
PROGRAMMING
1,000
[ "implementation", "math" ]
A. Numbers
1
64
Little Petya likes numbers a lot. He found that number 123 in base 16 consists of two digits: the first is 7 and the second is 11. So the sum of digits of 123 in base 16 is equal to 18. Now he wonders what is an average value of sum of digits of the number *A* written in all bases from 2 to *A*<=-<=1. Note that all computations should be done in base 10. You should find the result as an irreducible fraction, written in base 10.
Input contains one integer number *A* (3<=≤<=*A*<=≤<=1000).
Output should contain required average value in format «X/Y», where X is the numerator and Y is the denominator.
[ "5\n", "3\n" ]
[ "7/3\n", "2/1\n" ]
In the first sample number 5 written in all bases from 2 to 4 looks so: 101, 12, 11. Sums of digits are 2, 3 and 2, respectively.
0
[ { "input": "5", "output": "7/3" }, { "input": "3", "output": "2/1" }, { "input": "1000", "output": "90132/499" }, { "input": "927", "output": "155449/925" }, { "input": "260", "output": "6265/129" }, { "input": "131", "output": "3370/129" }, { "input": "386", "output": "857/12" }, { "input": "277", "output": "2864/55" }, { "input": "766", "output": "53217/382" }, { "input": "28", "output": "85/13" }, { "input": "406", "output": "7560/101" }, { "input": "757", "output": "103847/755" }, { "input": "6", "output": "9/4" }, { "input": "239", "output": "10885/237" }, { "input": "322", "output": "2399/40" }, { "input": "98", "output": "317/16" }, { "input": "208", "output": "4063/103" }, { "input": "786", "output": "55777/392" }, { "input": "879", "output": "140290/877" }, { "input": "702", "output": "89217/700" }, { "input": "948", "output": "7369/43" }, { "input": "537", "output": "52753/535" }, { "input": "984", "output": "174589/982" }, { "input": "934", "output": "157951/932" }, { "input": "726", "output": "95491/724" }, { "input": "127", "output": "3154/125" }, { "input": "504", "output": "23086/251" }, { "input": "125", "output": "3080/123" }, { "input": "604", "output": "33178/301" }, { "input": "115", "output": "2600/113" }, { "input": "27", "output": "167/25" }, { "input": "687", "output": "85854/685" }, { "input": "880", "output": "69915/439" }, { "input": "173", "output": "640/19" }, { "input": "264", "output": "6438/131" }, { "input": "785", "output": "111560/783" }, { "input": "399", "output": "29399/397" }, { "input": "514", "output": "6031/64" }, { "input": "381", "output": "26717/379" }, { "input": "592", "output": "63769/590" }, { "input": "417", "output": "32002/415" }, { "input": "588", "output": "62723/586" }, { "input": "852", "output": "131069/850" }, { "input": "959", "output": "5059/29" }, { "input": "841", "output": "127737/839" }, { "input": "733", "output": "97598/731" }, { "input": "692", "output": "87017/690" }, { "input": "69", "output": "983/67" }, { "input": "223", "output": "556/13" }, { "input": "93", "output": "246/13" }, { "input": "643", "output": "75503/641" }, { "input": "119", "output": "2833/117" }, { "input": "498", "output": "1459/16" }, { "input": "155", "output": "4637/153" }, { "input": "305", "output": "17350/303" }, { "input": "454", "output": "37893/452" }, { "input": "88", "output": "1529/86" }, { "input": "850", "output": "32645/212" }, { "input": "474", "output": "20581/236" }, { "input": "309", "output": "17731/307" }, { "input": "762", "output": "105083/760" }, { "input": "591", "output": "63761/589" }, { "input": "457", "output": "38317/455" }, { "input": "141", "output": "3832/139" }, { "input": "385", "output": "27232/383" }, { "input": "387", "output": "27628/385" }, { "input": "469", "output": "40306/467" }, { "input": "624", "output": "35285/311" }, { "input": "330", "output": "487/8" }, { "input": "31", "output": "222/29" }, { "input": "975", "output": "171679/973" }, { "input": "584", "output": "62183/582" }, { "input": "668", "output": "81127/666" }, { "input": "331", "output": "20297/329" }, { "input": "189", "output": "6789/187" }, { "input": "251", "output": "11939/249" }, { "input": "876", "output": "69196/437" }, { "input": "615", "output": "68987/613" }, { "input": "451", "output": "37258/449" }, { "input": "499", "output": "45727/497" }, { "input": "699", "output": "89117/697" }, { "input": "619", "output": "70019/617" }, { "input": "413", "output": "10515/137" }, { "input": "197", "output": "7399/195" }, { "input": "794", "output": "14281/99" }, { "input": "659", "output": "79403/657" }, { "input": "653", "output": "77695/651" }, { "input": "23", "output": "45/7" }, { "input": "430", "output": "16985/214" }, { "input": "249", "output": "11659/247" }, { "input": "837", "output": "126869/835" }, { "input": "258", "output": "12373/256" }, { "input": "995", "output": "59665/331" }, { "input": "102", "output": "504/25" }, { "input": "989", "output": "177124/987" }, { "input": "376", "output": "13008/187" }, { "input": "657", "output": "15715/131" }, { "input": "746", "output": "50509/372" }, { "input": "602", "output": "13177/120" } ]
1,648,184,545
2,147,483,647
PyPy 3-64
COMPILATION_ERROR
TESTS
0
0
0
n = int(input()) k = 2 c = 0 s = 0 while k<n: e = n while e>0: s+=e%k e=e//k c+=1 k+=1 print(s,'/',c,sep='')
Title: Numbers Time Limit: 1 seconds Memory Limit: 64 megabytes Problem Description: Little Petya likes numbers a lot. He found that number 123 in base 16 consists of two digits: the first is 7 and the second is 11. So the sum of digits of 123 in base 16 is equal to 18. Now he wonders what is an average value of sum of digits of the number *A* written in all bases from 2 to *A*<=-<=1. Note that all computations should be done in base 10. You should find the result as an irreducible fraction, written in base 10. Input Specification: Input contains one integer number *A* (3<=≤<=*A*<=≤<=1000). Output Specification: Output should contain required average value in format «X/Y», where X is the numerator and Y is the denominator. Demo Input: ['5\n', '3\n'] Demo Output: ['7/3\n', '2/1\n'] Note: In the first sample number 5 written in all bases from 2 to 4 looks so: 101, 12, 11. Sums of digits are 2, 3 and 2, respectively.
```python n = int(input()) k = 2 c = 0 s = 0 while k<n: e = n while e>0: s+=e%k e=e//k c+=1 k+=1 print(s,'/',c,sep='') ```
-1
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,605,449,145
2,147,483,647
Python 3
RUNTIME_ERROR
TESTS
2
108
307,200
import math a, b = map(int, input().split()) k2=0 k3=0 k5=0 if(a==b): print(0) else: k = math.gcd(a,b) ak = a / k bk = b / k while(ak%2==0): k2+=1 ak/=2 while(ak%3==0): k3+=1 ak/=3 while(ak%5==0): k5+=1 ak/=3 while(bk%2==0): k2+=1 bk/=2 while(ak%3==0): k3+=1 bk/=3 while(ak%5==0): k5+=1 bk/=3 ans = k2+k3+k5 if(bk!=ak): print(-1) else: print(ans)
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 import math a, b = map(int, input().split()) k2=0 k3=0 k5=0 if(a==b): print(0) else: k = math.gcd(a,b) ak = a / k bk = b / k while(ak%2==0): k2+=1 ak/=2 while(ak%3==0): k3+=1 ak/=3 while(ak%5==0): k5+=1 ak/=3 while(bk%2==0): k2+=1 bk/=2 while(ak%3==0): k3+=1 bk/=3 while(ak%5==0): k5+=1 bk/=3 ans = k2+k3+k5 if(bk!=ak): print(-1) else: print(ans) ```
-1
784
G
BF Calculator
PROGRAMMING
2,000
[ "*special" ]
null
null
In this problem you will write a simple generator of Brainfuck ([https://en.wikipedia.org/wiki/Brainfuck](https://en.wikipedia.org/wiki/Brainfuck)) calculators. You are given an arithmetic expression consisting of integers from 0 to 255 and addition/subtraction signs between them. Output a Brainfuck program which, when executed, will print the result of evaluating this expression. We use a fairly standard Brainfuck interpreter for checking the programs: - 30000 memory cells.- memory cells store integers from 0 to 255 with unsigned 8-bit wraparound.- console input (, command) is not supported, but it's not needed for this problem.
The only line of input data contains the arithmetic expression. The expression will contain between 2 and 10 operands, separated with arithmetic signs plus and/or minus. Each operand will be an integer between 0 and 255, inclusive. The calculations result is guaranteed to be an integer between 0 and 255, inclusive (results of intermediary calculations might be outside of these boundaries).
Output a Brainfuck program which, when executed, will print the result of evaluating this expression. The program must be at most 5000000 characters long (including the non-command characters), and its execution must be complete in at most 50000000 steps.
[ "2+3\n", "9-7\n" ]
[ "++&gt;\n+++&gt;\n&lt;[&lt;+&gt;-]&lt;\n++++++++++++++++++++++++++++++++++++++++++++++++.\n", "+++++++++&gt;\n+++++++&gt;\n&lt;[&lt;-&gt;-]&lt;\n++++++++++++++++++++++++++++++++++++++++++++++++.\n" ]
You can download the source code of the Brainfuck interpreter by the link [http://assets.codeforces.com/rounds/784/bf.cpp](//assets.codeforces.com/rounds/784/bf.cpp). We use this code to interpret outputs.
0
[ { "input": "2+3", "output": "+++++++++++++++++++++++++++++++++++++++++++++++++++++.>" }, { "input": "9-7", "output": "++++++++++++++++++++++++++++++++++++++++++++++++++.>" }, { "input": "1+1+1", "output": "+++++++++++++++++++++++++++++++++++++++++++++++++++.>" }, { "input": "1+11+111", "output": "+++++++++++++++++++++++++++++++++++++++++++++++++.>\n++++++++++++++++++++++++++++++++++++++++++++++++++.>\n+++++++++++++++++++++++++++++++++++++++++++++++++++.>" }, { "input": "111-11-1", "output": "+++++++++++++++++++++++++++++++++++++++++++++++++++++++++.>\n+++++++++++++++++++++++++++++++++++++++++++++++++++++++++.>" }, { "input": "1+1-1+1-1+1-1+1-1+1", "output": "++++++++++++++++++++++++++++++++++++++++++++++++++.>" }, { "input": "9+1", "output": "+++++++++++++++++++++++++++++++++++++++++++++++++.>\n++++++++++++++++++++++++++++++++++++++++++++++++.>" }, { "input": "10-1", "output": "+++++++++++++++++++++++++++++++++++++++++++++++++++++++++.>" }, { "input": "31+49+49+71-51-61+59-111+51", "output": "++++++++++++++++++++++++++++++++++++++++++++++++++++++++.>\n+++++++++++++++++++++++++++++++++++++++++++++++++++++++.>" }, { "input": "255+255+255+255+255-255-255-255-255-255", "output": "++++++++++++++++++++++++++++++++++++++++++++++++.>" }, { "input": "100+100+10+10+10+10+10+5", "output": "++++++++++++++++++++++++++++++++++++++++++++++++++.>\n+++++++++++++++++++++++++++++++++++++++++++++++++++++.>\n+++++++++++++++++++++++++++++++++++++++++++++++++++++.>" }, { "input": "255-255+255-255+255-255+255-255+255", "output": "++++++++++++++++++++++++++++++++++++++++++++++++++.>\n+++++++++++++++++++++++++++++++++++++++++++++++++++++.>\n+++++++++++++++++++++++++++++++++++++++++++++++++++++.>" }, { "input": "0-255-255-255-255+255+255+255+255+255", "output": "++++++++++++++++++++++++++++++++++++++++++++++++++.>\n+++++++++++++++++++++++++++++++++++++++++++++++++++++.>\n+++++++++++++++++++++++++++++++++++++++++++++++++++++.>" }, { "input": "34+45+29-49+52-111-4+4+2+9", "output": "+++++++++++++++++++++++++++++++++++++++++++++++++.>\n+++++++++++++++++++++++++++++++++++++++++++++++++.>" }, { "input": "0+0+0+0+0+0+0+0+0+0", "output": "++++++++++++++++++++++++++++++++++++++++++++++++.>" }, { "input": "193+235+47+150+222-3-90-248-187-100", "output": "++++++++++++++++++++++++++++++++++++++++++++++++++.>\n+++++++++++++++++++++++++++++++++++++++++++++++++.>\n+++++++++++++++++++++++++++++++++++++++++++++++++++++++++.>" }, { "input": "66-165-34+209+76", "output": "+++++++++++++++++++++++++++++++++++++++++++++++++.>\n+++++++++++++++++++++++++++++++++++++++++++++++++++++.>\n++++++++++++++++++++++++++++++++++++++++++++++++++.>" }, { "input": "36+90+6+102", "output": "++++++++++++++++++++++++++++++++++++++++++++++++++.>\n+++++++++++++++++++++++++++++++++++++++++++++++++++.>\n++++++++++++++++++++++++++++++++++++++++++++++++++++.>" }, { "input": "255-12-34-56-69-78", "output": "++++++++++++++++++++++++++++++++++++++++++++++++++++++.>" }, { "input": "243-173+90-56+78-53+53-21", "output": "+++++++++++++++++++++++++++++++++++++++++++++++++.>\n++++++++++++++++++++++++++++++++++++++++++++++++++++++.>\n+++++++++++++++++++++++++++++++++++++++++++++++++.>" } ]
1,498,196,157
5,336
Python 3
OK
TESTS
20
46
5,529,600
k=eval(input()) o="" for i in str(k): a=ord(i) o+="+"*a+".[-]" print(o)
Title: BF Calculator Time Limit: None seconds Memory Limit: None megabytes Problem Description: In this problem you will write a simple generator of Brainfuck ([https://en.wikipedia.org/wiki/Brainfuck](https://en.wikipedia.org/wiki/Brainfuck)) calculators. You are given an arithmetic expression consisting of integers from 0 to 255 and addition/subtraction signs between them. Output a Brainfuck program which, when executed, will print the result of evaluating this expression. We use a fairly standard Brainfuck interpreter for checking the programs: - 30000 memory cells.- memory cells store integers from 0 to 255 with unsigned 8-bit wraparound.- console input (, command) is not supported, but it's not needed for this problem. Input Specification: The only line of input data contains the arithmetic expression. The expression will contain between 2 and 10 operands, separated with arithmetic signs plus and/or minus. Each operand will be an integer between 0 and 255, inclusive. The calculations result is guaranteed to be an integer between 0 and 255, inclusive (results of intermediary calculations might be outside of these boundaries). Output Specification: Output a Brainfuck program which, when executed, will print the result of evaluating this expression. The program must be at most 5000000 characters long (including the non-command characters), and its execution must be complete in at most 50000000 steps. Demo Input: ['2+3\n', '9-7\n'] Demo Output: ['++&gt;\n+++&gt;\n&lt;[&lt;+&gt;-]&lt;\n++++++++++++++++++++++++++++++++++++++++++++++++.\n', '+++++++++&gt;\n+++++++&gt;\n&lt;[&lt;-&gt;-]&lt;\n++++++++++++++++++++++++++++++++++++++++++++++++.\n'] Note: You can download the source code of the Brainfuck interpreter by the link [http://assets.codeforces.com/rounds/784/bf.cpp](//assets.codeforces.com/rounds/784/bf.cpp). We use this code to interpret outputs.
```python k=eval(input()) o="" for i in str(k): a=ord(i) o+="+"*a+".[-]" print(o) ```
3
126
B
Password
PROGRAMMING
1,700
[ "binary search", "dp", "hashing", "string suffix structures", "strings" ]
null
null
Asterix, Obelix and their temporary buddies Suffix and Prefix has finally found the Harmony temple. However, its doors were firmly locked and even Obelix had no luck opening them. A little later they found a string *s*, carved on a rock below the temple's gates. Asterix supposed that that's the password that opens the temple and read the string aloud. However, nothing happened. Then Asterix supposed that a password is some substring *t* of the string *s*. Prefix supposed that the substring *t* is the beginning of the string *s*; Suffix supposed that the substring *t* should be the end of the string *s*; and Obelix supposed that *t* should be located somewhere inside the string *s*, that is, *t* is neither its beginning, nor its end. Asterix chose the substring *t* so as to please all his companions. Besides, from all acceptable variants Asterix chose the longest one (as Asterix loves long strings). When Asterix read the substring *t* aloud, the temple doors opened. You know the string *s*. Find the substring *t* or determine that such substring does not exist and all that's been written above is just a nice legend.
You are given the string *s* whose length can vary from 1 to 106 (inclusive), consisting of small Latin letters.
Print the string *t*. If a suitable *t* string does not exist, then print "Just a legend" without the quotes.
[ "fixprefixsuffix\n", "abcdabc\n" ]
[ "fix", "Just a legend" ]
none
1,000
[ { "input": "fixprefixsuffix", "output": "fix" }, { "input": "abcdabc", "output": "Just a legend" }, { "input": "qwertyqwertyqwerty", "output": "qwerty" }, { "input": "papapapap", "output": "papap" }, { "input": "aaaaaaaaaa", "output": "aaaaaaaa" }, { "input": "ghbdtn", "output": "Just a legend" }, { "input": "a", "output": "Just a legend" }, { "input": "aa", "output": "Just a legend" }, { "input": "ab", "output": "Just a legend" }, { "input": "aaa", "output": "a" }, { "input": "aba", "output": "Just a legend" }, { "input": "aab", "output": "Just a legend" }, { "input": "abb", "output": "Just a legend" }, { "input": "abc", "output": "Just a legend" }, { "input": "aaabaabaaaaab", "output": "Just a legend" }, { "input": "aabaaabaaaaab", "output": "aab" }, { "input": "aaabaaaabab", "output": "Just a legend" }, { "input": "abcabcabcabcabc", "output": "abcabcabc" }, { "input": "aaaaabaaaa", "output": "aaaa" }, { "input": "aaaabaaaaaaa", "output": "aaaa" }, { "input": "ghghghgxghghghg", "output": "ghghg" }, { "input": "kincenvizh", "output": "Just a legend" }, { "input": "amcksgurlgqzqizdauqminfzshiweejkevbazyzylrrghumnvqeqqdedyopgtvxakqwpvxntxgrkrcxabhrgoxngrwrxrvcguuyw", "output": "Just a legend" }, { "input": "kwuaizneqxfflhmyruotjlkqksinoanvkyvqptkkntnpjdyzicceelgooajdgpkneuhyvhdtmasiglplajxolxovlhkwuaizneqx", "output": "Just a legend" }, { "input": "nfbdzgdlbjhrlvfryyjbvtsmzacxglcvukmyexdgpuiwvqbnfbdzgdlbjhrlvfryyjbtuomcwbwvlhefnfbdzgdlbjhrlvfryyjb", "output": "nfbdzgdlbjhrlvfryyjb" }, { "input": "btbdpnzdenxueteteytvkwnegodyhmdwhmrmbftrifytzudumzlacwytsuzefqfpjesdblxhpcsidgksisjdmhyxmmugrjmtfcgxmcgpmvbxbyszdugvmoyjeeqsywcvuqskcjotyhvdijyslgfvyujxthngnonasgnbzzygyikheelirdfsvuicbiazfdeqecbtbdpnzdenxueteteytvkwnegodyhmdwhmrmbftrifytzudumzlacwytsuzefqfpjesdblxhpcsidgksisjdmhyxmmugrjmtfcgxmcgpccdtdteohtjjuicfjfcbzpynlqhecyqqrjpmexgfqywnfmusldgzvgnzdmuuujtkdfnlytzgstquwqpuccxbtbdpnzdenxueteteytvkwnegodyhmdwhmrmbftrifytzudumzlacwytsuzefqfpjesdblxhpcsidgksisjdmhyxmmugrjmtfcgxmcgp", "output": "btbdpnzdenxueteteytvkwnegodyhmdwhmrmbftrifytzudumzlacwytsuzefqfpjesdblxhpcsidgksisjdmhyxmmugrjmtfcgxmcgp" }, { "input": "abcazabca", "output": "a" } ]
1,661,788,266
2,147,483,647
PyPy 3-64
WRONG_ANSWER
TESTS
2
92
0
s = input() s = list(s) suffix = [] prefix = [] obelix = [] length = len(s)-1 first = s[0] last = s[length] suffixF = 0 def toStr(s1): temp = '' for ele in s1: temp += str(ele) return temp for i in range(length//2): if s[i] == last: prefix.append(s[i]) break prefix.append(s[i]) j = len(s)-1 for i in range(length//2): if s[j] == first: suffixF = j suffix.append(s[j]) break suffix.append(s[j]) j -= 1 for i in range(length): if len(prefix) < i < suffixF and s[i] == first: for m in range(i, i+len(prefix)): obelix.append(s[m]) break suffix = suffix[::-1] suffix = toStr(suffix) prefix = toStr(prefix) obelix = toStr(obelix) if suffix == obelix and obelix == prefix and suffix == prefix: print(suffix) else: print('Just a legend')
Title: Password Time Limit: None seconds Memory Limit: None megabytes Problem Description: Asterix, Obelix and their temporary buddies Suffix and Prefix has finally found the Harmony temple. However, its doors were firmly locked and even Obelix had no luck opening them. A little later they found a string *s*, carved on a rock below the temple's gates. Asterix supposed that that's the password that opens the temple and read the string aloud. However, nothing happened. Then Asterix supposed that a password is some substring *t* of the string *s*. Prefix supposed that the substring *t* is the beginning of the string *s*; Suffix supposed that the substring *t* should be the end of the string *s*; and Obelix supposed that *t* should be located somewhere inside the string *s*, that is, *t* is neither its beginning, nor its end. Asterix chose the substring *t* so as to please all his companions. Besides, from all acceptable variants Asterix chose the longest one (as Asterix loves long strings). When Asterix read the substring *t* aloud, the temple doors opened. You know the string *s*. Find the substring *t* or determine that such substring does not exist and all that's been written above is just a nice legend. Input Specification: You are given the string *s* whose length can vary from 1 to 106 (inclusive), consisting of small Latin letters. Output Specification: Print the string *t*. If a suitable *t* string does not exist, then print "Just a legend" without the quotes. Demo Input: ['fixprefixsuffix\n', 'abcdabc\n'] Demo Output: ['fix', 'Just a legend'] Note: none
```python s = input() s = list(s) suffix = [] prefix = [] obelix = [] length = len(s)-1 first = s[0] last = s[length] suffixF = 0 def toStr(s1): temp = '' for ele in s1: temp += str(ele) return temp for i in range(length//2): if s[i] == last: prefix.append(s[i]) break prefix.append(s[i]) j = len(s)-1 for i in range(length//2): if s[j] == first: suffixF = j suffix.append(s[j]) break suffix.append(s[j]) j -= 1 for i in range(length): if len(prefix) < i < suffixF and s[i] == first: for m in range(i, i+len(prefix)): obelix.append(s[m]) break suffix = suffix[::-1] suffix = toStr(suffix) prefix = toStr(prefix) obelix = toStr(obelix) if suffix == obelix and obelix == prefix and suffix == prefix: print(suffix) else: print('Just a legend') ```
0
114
A
Cifera
PROGRAMMING
1,000
[ "math" ]
null
null
When Petya went to school, he got interested in large numbers and what they were called in ancient times. For instance, he learned that the Russian word "tma" (which now means "too much to be counted") used to stand for a thousand and "tma tmyschaya" (which literally means "the tma of tmas") used to stand for a million. Petya wanted to modernize the words we use for numbers and invented a word petricium that represents number *k*. Moreover, petricium la petricium stands for number *k*2, petricium la petricium la petricium stands for *k*3 and so on. All numbers of this form are called petriciumus cifera, and the number's importance is the number of articles la in its title. Petya's invention brought on a challenge that needed to be solved quickly: does some number *l* belong to the set petriciumus cifera? As Petya is a very busy schoolboy he needs to automate the process, he asked you to solve it.
The first input line contains integer number *k*, the second line contains integer number *l* (2<=≤<=*k*,<=*l*<=≤<=231<=-<=1).
You should print in the first line of the output "YES", if the number belongs to the set petriciumus cifera and otherwise print "NO". If the number belongs to the set, then print on the seconds line the only number — the importance of number *l*.
[ "5\n25\n", "3\n8\n" ]
[ "YES\n1\n", "NO\n" ]
none
500
[ { "input": "5\n25", "output": "YES\n1" }, { "input": "3\n8", "output": "NO" }, { "input": "123\n123", "output": "YES\n0" }, { "input": "99\n970300", "output": "NO" }, { "input": "1000\n6666666", "output": "NO" }, { "input": "59\n3571", "output": "NO" }, { "input": "256\n16777217", "output": "NO" }, { "input": "4638\n21511044", "output": "YES\n1" }, { "input": "24\n191102976", "output": "YES\n5" }, { "input": "52010\n557556453", "output": "NO" }, { "input": "61703211\n1750753082", "output": "NO" }, { "input": "137\n2571353", "output": "YES\n2" }, { "input": "8758\n1746157336", "output": "NO" }, { "input": "2\n64", "output": "YES\n5" }, { "input": "96\n884736", "output": "YES\n2" }, { "input": "1094841453\n1656354409", "output": "NO" }, { "input": "1154413\n1229512809", "output": "NO" }, { "input": "2442144\n505226241", "output": "NO" }, { "input": "11548057\n1033418098", "output": "NO" }, { "input": "581\n196122941", "output": "YES\n2" }, { "input": "146\n1913781536", "output": "NO" }, { "input": "945916\n1403881488", "output": "NO" }, { "input": "68269\n365689065", "output": "NO" }, { "input": "30\n900", "output": "YES\n1" }, { "input": "6\n1296", "output": "YES\n3" }, { "input": "1470193122\n1420950405", "output": "NO" }, { "input": "90750\n1793111557", "output": "NO" }, { "input": "1950054\n1664545956", "output": "NO" }, { "input": "6767692\n123762320", "output": "NO" }, { "input": "1437134\n1622348229", "output": "NO" }, { "input": "444103\n1806462642", "output": "NO" }, { "input": "2592\n6718464", "output": "YES\n1" }, { "input": "50141\n366636234", "output": "NO" }, { "input": "835\n582182875", "output": "YES\n2" }, { "input": "156604\n902492689", "output": "NO" }, { "input": "27385965\n1742270058", "output": "NO" }, { "input": "3\n9", "output": "YES\n1" }, { "input": "35\n1838265625", "output": "YES\n5" }, { "input": "8\n4096", "output": "YES\n3" }, { "input": "85955\n945811082", "output": "NO" }, { "input": "54958832\n956670209", "output": "NO" }, { "input": "1475381\n1348159738", "output": "NO" }, { "input": "7313241\n413670642", "output": "NO" }, { "input": "582470\n2116368165", "output": "NO" }, { "input": "26859739\n595086170", "output": "NO" }, { "input": "249766393\n1582130", "output": "NO" }, { "input": "11734\n137686756", "output": "YES\n1" }, { "input": "925093\n1098566745", "output": "NO" }, { "input": "40\n1600", "output": "YES\n1" }, { "input": "2147483647\n2147483647", "output": "YES\n0" }, { "input": "2147483646\n2147483647", "output": "NO" }, { "input": "2147483647\n2147483646", "output": "NO" }, { "input": "2\n2147483647", "output": "NO" }, { "input": "2\n1073741825", "output": "NO" }, { "input": "2\n1073741824", "output": "YES\n29" }, { "input": "10000\n10", "output": "NO" }, { "input": "10\n10000", "output": "YES\n3" }, { "input": "10\n2000000000", "output": "NO" }, { "input": "10\n1000000000", "output": "YES\n8" }, { "input": "5\n1808548329", "output": "NO" }, { "input": "2\n2147483646", "output": "NO" }, { "input": "25\n125", "output": "NO" }, { "input": "6\n18", "output": "NO" }, { "input": "5\n30", "output": "NO" } ]
1,539,665,306
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
8
216
0
e = 0 def r(small, big): global e if big / small >= small: e += 1 return r(big / small, small) else: print("YES\n%d"%e) if big == small else print("NO") r(int(input()), int(input()))
Title: Cifera Time Limit: None seconds Memory Limit: None megabytes Problem Description: When Petya went to school, he got interested in large numbers and what they were called in ancient times. For instance, he learned that the Russian word "tma" (which now means "too much to be counted") used to stand for a thousand and "tma tmyschaya" (which literally means "the tma of tmas") used to stand for a million. Petya wanted to modernize the words we use for numbers and invented a word petricium that represents number *k*. Moreover, petricium la petricium stands for number *k*2, petricium la petricium la petricium stands for *k*3 and so on. All numbers of this form are called petriciumus cifera, and the number's importance is the number of articles la in its title. Petya's invention brought on a challenge that needed to be solved quickly: does some number *l* belong to the set petriciumus cifera? As Petya is a very busy schoolboy he needs to automate the process, he asked you to solve it. Input Specification: The first input line contains integer number *k*, the second line contains integer number *l* (2<=≤<=*k*,<=*l*<=≤<=231<=-<=1). Output Specification: You should print in the first line of the output "YES", if the number belongs to the set petriciumus cifera and otherwise print "NO". If the number belongs to the set, then print on the seconds line the only number — the importance of number *l*. Demo Input: ['5\n25\n', '3\n8\n'] Demo Output: ['YES\n1\n', 'NO\n'] Note: none
```python e = 0 def r(small, big): global e if big / small >= small: e += 1 return r(big / small, small) else: print("YES\n%d"%e) if big == small else print("NO") r(int(input()), int(input())) ```
0
432
A
Choosing Teams
PROGRAMMING
800
[ "greedy", "implementation", "sortings" ]
null
null
The Saratov State University Olympiad Programmers Training Center (SSU OPTC) has *n* students. For each student you know the number of times he/she has participated in the ACM ICPC world programming championship. According to the ACM ICPC rules, each person can participate in the world championship at most 5 times. The head of the SSU OPTC is recently gathering teams to participate in the world championship. Each team must consist of exactly three people, at that, any person cannot be a member of two or more teams. What maximum number of teams can the head make if he wants each team to participate in the world championship with the same members at least *k* times?
The first line contains two integers, *n* and *k* (1<=≤<=*n*<=≤<=2000; 1<=≤<=*k*<=≤<=5). The next line contains *n* integers: *y*1,<=*y*2,<=...,<=*y**n* (0<=≤<=*y**i*<=≤<=5), where *y**i* shows the number of times the *i*-th person participated in the ACM ICPC world championship.
Print a single number — the answer to the problem.
[ "5 2\n0 4 5 1 0\n", "6 4\n0 1 2 3 4 5\n", "6 5\n0 0 0 0 0 0\n" ]
[ "1\n", "0\n", "2\n" ]
In the first sample only one team could be made: the first, the fourth and the fifth participants. In the second sample no teams could be created. In the third sample two teams could be created. Any partition into two teams fits.
500
[ { "input": "5 2\n0 4 5 1 0", "output": "1" }, { "input": "6 4\n0 1 2 3 4 5", "output": "0" }, { "input": "6 5\n0 0 0 0 0 0", "output": "2" }, { "input": "3 4\n0 1 0", "output": "1" }, { "input": "3 4\n0 2 0", "output": "0" }, { "input": "6 5\n0 0 0 0 0 0", "output": "2" }, { "input": "12 2\n0 1 2 3 4 0 1 2 3 4 0 1", "output": "3" }, { "input": "15 2\n0 1 2 3 4 0 1 2 3 4 0 1 2 3 4", "output": "4" }, { "input": "13 1\n5 0 5 0 1 5 0 4 1 1 1 4 1", "output": "3" }, { "input": "20 1\n5 0 4 2 2 3 2 1 2 4 1 3 5 5 5 4 4 1 3 0", "output": "5" }, { "input": "20 2\n1 4 5 1 3 4 0 5 0 3 3 0 4 0 0 1 4 2 0 4", "output": "4" }, { "input": "20 2\n1 4 5 1 3 4 0 5 0 3 3 0 4 0 0 1 4 2 0 4", "output": "4" }, { "input": "20 2\n1 4 5 1 3 4 0 5 0 3 3 0 4 0 0 1 4 2 0 4", "output": "4" }, { "input": "20 2\n1 4 5 1 3 4 0 5 0 3 3 0 4 0 0 1 4 2 0 4", "output": "4" }, { "input": "6 3\n4 4 4 4 4 4", "output": "0" }, { "input": "1 4\n1", "output": "0" }, { "input": "1 1\n0", "output": "0" }, { "input": "2 3\n0 0", "output": "0" } ]
1,664,024,432
2,147,483,647
Python 3
OK
TESTS
35
46
0
a = input().split() N = int(a[0]) K = int(a[1]) list = [] kord = input().split() for i in range(N): if int(kord[i]) + K > 5: continue else: list.append(kord[i]) arv = len(list)/3 print(int(arv))
Title: Choosing Teams Time Limit: None seconds Memory Limit: None megabytes Problem Description: The Saratov State University Olympiad Programmers Training Center (SSU OPTC) has *n* students. For each student you know the number of times he/she has participated in the ACM ICPC world programming championship. According to the ACM ICPC rules, each person can participate in the world championship at most 5 times. The head of the SSU OPTC is recently gathering teams to participate in the world championship. Each team must consist of exactly three people, at that, any person cannot be a member of two or more teams. What maximum number of teams can the head make if he wants each team to participate in the world championship with the same members at least *k* times? Input Specification: The first line contains two integers, *n* and *k* (1<=≤<=*n*<=≤<=2000; 1<=≤<=*k*<=≤<=5). The next line contains *n* integers: *y*1,<=*y*2,<=...,<=*y**n* (0<=≤<=*y**i*<=≤<=5), where *y**i* shows the number of times the *i*-th person participated in the ACM ICPC world championship. Output Specification: Print a single number — the answer to the problem. Demo Input: ['5 2\n0 4 5 1 0\n', '6 4\n0 1 2 3 4 5\n', '6 5\n0 0 0 0 0 0\n'] Demo Output: ['1\n', '0\n', '2\n'] Note: In the first sample only one team could be made: the first, the fourth and the fifth participants. In the second sample no teams could be created. In the third sample two teams could be created. Any partition into two teams fits.
```python a = input().split() N = int(a[0]) K = int(a[1]) list = [] kord = input().split() for i in range(N): if int(kord[i]) + K > 5: continue else: list.append(kord[i]) arv = len(list)/3 print(int(arv)) ```
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,636,818,571
2,147,483,647
Python 3
OK
TESTS
21
46
4,300,800
t = list(map(int,input().split(" "))) print(min(sum(t),2*(t[1]+t[0]),2*(t[1]+t[2]),2*(t[0]+t[2])))
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 t = list(map(int,input().split(" "))) print(min(sum(t),2*(t[1]+t[0]),2*(t[1]+t[2]),2*(t[0]+t[2]))) ```
3
78
B
Easter Eggs
PROGRAMMING
1,200
[ "constructive algorithms", "implementation" ]
B. Easter Eggs
2
256
The Easter Rabbit laid *n* eggs in a circle and is about to paint them. Each egg should be painted one color out of 7: red, orange, yellow, green, blue, indigo or violet. Also, the following conditions should be satisfied: - Each of the seven colors should be used to paint at least one egg. - Any four eggs lying sequentially should be painted different colors. Help the Easter Rabbit paint the eggs in the required manner. We know that it is always possible.
The only line contains an integer *n* — the amount of eggs (7<=≤<=*n*<=≤<=100).
Print one line consisting of *n* characters. The *i*-th character should describe the color of the *i*-th egg in the order they lie in the circle. The colors should be represented as follows: "R" stands for red, "O" stands for orange, "Y" stands for yellow, "G" stands for green, "B" stands for blue, "I" stands for indigo, "V" stands for violet. If there are several answers, print any of them.
[ "8\n", "13\n" ]
[ "ROYGRBIV\n", "ROYGBIVGBIVYG\n" ]
The way the eggs will be painted in the first sample is shown on the picture:
1,000
[ { "input": "8", "output": "ROYGBIVG" }, { "input": "13", "output": "ROYGBIVOYGBIV" }, { "input": "7", "output": "ROYGBIV" }, { "input": "10", "output": "ROYGBIVYGB" }, { "input": "14", "output": "ROYGBIVROYGBIV" }, { "input": "50", "output": "ROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVG" }, { "input": "9", "output": "ROYGBIVGB" }, { "input": "11", "output": "ROYGBIVYGBI" }, { "input": "12", "output": "ROYGBIVOYGBI" }, { "input": "15", "output": "ROYGBIVROYGBIVG" }, { "input": "16", "output": "ROYGBIVROYGBIVGB" }, { "input": "17", "output": "ROYGBIVROYGBIVYGB" }, { "input": "18", "output": "ROYGBIVROYGBIVYGBI" }, { "input": "19", "output": "ROYGBIVROYGBIVOYGBI" }, { "input": "20", "output": "ROYGBIVROYGBIVOYGBIV" }, { "input": "21", "output": "ROYGBIVROYGBIVROYGBIV" }, { "input": "22", "output": "ROYGBIVROYGBIVROYGBIVG" }, { "input": "23", "output": "ROYGBIVROYGBIVROYGBIVGB" }, { "input": "24", "output": "ROYGBIVROYGBIVROYGBIVYGB" }, { "input": "25", "output": "ROYGBIVROYGBIVROYGBIVYGBI" }, { "input": "28", "output": "ROYGBIVROYGBIVROYGBIVROYGBIV" }, { "input": "29", "output": "ROYGBIVROYGBIVROYGBIVROYGBIVG" }, { "input": "34", "output": "ROYGBIVROYGBIVROYGBIVROYGBIVOYGBIV" }, { "input": "43", "output": "ROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVG" }, { "input": "61", "output": "ROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVOYGBI" }, { "input": "79", "output": "ROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVGB" }, { "input": "81", "output": "ROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVYGBI" }, { "input": "92", "output": "ROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVG" }, { "input": "95", "output": "ROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVYGBI" }, { "input": "96", "output": "ROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVOYGBI" }, { "input": "97", "output": "ROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVOYGBIV" }, { "input": "98", "output": "ROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIV" }, { "input": "99", "output": "ROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVG" }, { "input": "100", "output": "ROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVGB" } ]
1,687,535,206
2,147,483,647
PyPy 3-64
OK
TESTS
34
124
0
n = int(input()) l = ["R","O","Y","G","B","I","V"] s = "" p = 0 while len(s) < n: if p == 7: diff = n - len(s) if diff > 3: p = 0 else: p = 3 s += l[p] p += 1 print(s)
Title: Easter Eggs Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: The Easter Rabbit laid *n* eggs in a circle and is about to paint them. Each egg should be painted one color out of 7: red, orange, yellow, green, blue, indigo or violet. Also, the following conditions should be satisfied: - Each of the seven colors should be used to paint at least one egg. - Any four eggs lying sequentially should be painted different colors. Help the Easter Rabbit paint the eggs in the required manner. We know that it is always possible. Input Specification: The only line contains an integer *n* — the amount of eggs (7<=≤<=*n*<=≤<=100). Output Specification: Print one line consisting of *n* characters. The *i*-th character should describe the color of the *i*-th egg in the order they lie in the circle. The colors should be represented as follows: "R" stands for red, "O" stands for orange, "Y" stands for yellow, "G" stands for green, "B" stands for blue, "I" stands for indigo, "V" stands for violet. If there are several answers, print any of them. Demo Input: ['8\n', '13\n'] Demo Output: ['ROYGRBIV\n', 'ROYGBIVGBIVYG\n'] Note: The way the eggs will be painted in the first sample is shown on the picture:
```python n = int(input()) l = ["R","O","Y","G","B","I","V"] s = "" p = 0 while len(s) < n: if p == 7: diff = n - len(s) if diff > 3: p = 0 else: p = 3 s += l[p] p += 1 print(s) ```
3.969